Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
withdrawalAmount = new Big(amountRequested);
} catch (e) {
console.log(`Bad data fed to new Big() in Adapter::receiveWithdrawalRequest()\n${JSON.stringify(e)}`);
console.log(`Withdrawal request amount is ${amountRequested}`);
this.getLogger().CommandEvents.onWithdrawalInvalidAmountProvided(withdrawalRequest)
return this.onWithdrawalInvalidAmountProvided(withdrawalRequest);
}
const fixedAmount = withdrawalAmount.toFixed(7);
if(typeof address === 'undefined' || address === null) {
this.getLogger().CommandEvents.onWithdrawalNoAddressProvided(withdrawalRequest)
return this.onWithdrawalNoAddressProvided(withdrawalRequest);
}
if (!StellarSdk.StrKey.isValidEd25519PublicKey(address)) {
this.getLogger().CommandEvents.onWithdrawalBadlyFormedAddress(withdrawalRequest, address)
return this.onWithdrawalInvalidAddress(withdrawalRequest);
}
// Fetch the account
const target = await withdrawalRequest.getSourceAccount();
// TODO: Rather than having this fetch occur here, I think it might make more sense to move this to the Command constructor
if (!target.canPay(withdrawalAmount)) {
this.getLogger().CommandEvents.onWithdrawalInsufficientBalance(withdrawalRequest, target.balance)
return this.onWithdrawalFailedWithInsufficientBalance(withdrawalRequest, target.balance);
}
// Withdraw
try {
// txHash is the hash from the stellar blockchain, not our internal hash
const txHash = await target.withdraw(this.config.stellar, address, withdrawalAmount, hash);
beforeSave: function () {
const now = new Date()
// If our walletAddress is set, we need to make sure it's a valid wallet address before saving
if(typeof this.walletAddress !== 'undefined' && this.walletAddress !== null) {
if(!StellarSdk.StrKey.isValidEd25519PublicKey(this.walletAddress)) {
this.walletAddress = null
return Promise.reject(new Error('BAD_PUBLIC_WALLET_ADDRESS'))
}
}
if(!this.hasAcceptedTerms) {
this.hasAcceptedTerms = false
}
if (!this.createdAt) {
this.createdAt = now.toISOString()
}
if (!this.balance) {
this.balance = '0.0000000'
}
this.updatedAt = now.toISOString()
it('should generate a keypair from seed', function() {
const seed = crypto.randomBytes(32);
const keyPair = basecoin.generateKeyPair(seed);
keyPair.should.have.property('pub');
keyPair.should.have.property('prv');
const address = keyPair.pub;
basecoin.isValidAddress(address).should.equal(true);
basecoin.isValidPub(keyPair.pub).should.equal(true);
basecoin.isValidPrv(keyPair.prv).should.equal(true);
const secret = keyPair.prv;
stellar.StrKey.encodeEd25519SecretSeed(seed).should.equal(secret);
});
const isStellarSecretSeed = addr =>
stellarSdk.StrKey.isValidEd25519SecretSeed(addr)
const isStellarFederatedAddress = addr => /^[^*,]*\*[a-z0-9-.]*$/i.test(addr)
ngModel.$validators.validSeed = function (modelValue) {
return StellarSdk.StrKey.isValidEd25519SecretSeed(modelValue);
};
}
const createKeypair = () => {
const wallet = sdk.createWalletAddress();
const publicKey = wallet.publicKey();
const privateKey = StellarSdk.StrKey.encodeEd25519SecretSeed(wallet._secretSeed);
return ({publicKey, privateKey});
};
else if (data.stellar.payment) {
handlePayment(data.stellar.payment);
}
else if (data.stellar.challenge) {
handleChallenge(data.stellar.challenge);
}
}
catch (err) {
if (qrData.startsWith('centaurus:backup003')) {
handleCentaurusImport(qrData);
}
else if (StellarSdk.StrKey.isValidEd25519PublicKey(qrData)) {
const contact = {
id: qrData
};
handleContact(contact);
}
}
}
const validateContact = (c) => {
if(c.address) {
if(!StellarSdk.StrKey.isValidEd25519PublicKey(c.address)) throw new Error('Not a valid address.');
}
if(c.federation) {
if(typeof c.federation !== 'string') throw new Error('Invalid federation.');
}
if(!c.address && !c.federation) throw new Error('Either address or federation required, or both.');
if(typeof c.name !== 'string') throw new Error('Invalid name.');
if(c.name.length > 100) throw new Error(`Too long name, max 100 characters. Got ${c.name.length}.`);
if(typeof c.details !== 'string') throw new Error('Invalid details.');
if(c.details.length > 10000) throw new Error(`Too long details, max 10000 characters. Got ${c.name.length}.`);
if(!moment(c.created, 'YYYY-MM-DDTHH:mm:ssZZ', true).isValid()) throw new Error('Invalid created time.')
if(!moment(c.updated, 'YYYY-MM-DDTHH:mm:ssZZ', true).isValid()) throw new Error('Invalid created time.')
switch(c.defaultMemoType) {
case(StellarSdk.MemoNone):
case(StellarSdk.MemoId):
normalizeAddress({ address, memoId }: AddressDetails): string {
if (!stellar.StrKey.isValidEd25519PublicKey(address)) {
throw new Error(`invalid address details: ${address}`);
}
if (memoId && this.isValidMemoId(memoId)) {
return `${address}?memoId=${memoId}`;
}
return address;
}