Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const block = {
id: raw.b_id,
version: parseInt(raw.b_version),
timestamp: parseInt(raw.b_timestamp),
height: parseInt(raw.b_height),
maxHeightPreviouslyForged: parseInt(raw.b_maxHeightPreviouslyForged),
prevotedConfirmedUptoHeight: parseInt(raw.b_prevotedConfirmedUptoHeight),
previousBlock: raw.b_previousBlock,
numberOfTransactions: parseInt(raw.b_numberOfTransactions),
totalAmount: new BigNum(raw.b_totalAmount),
totalFee: new BigNum(raw.b_totalFee),
reward: new BigNum(raw.b_reward),
payloadLength: parseInt(raw.b_payloadLength),
payloadHash: raw.b_payloadHash,
generatorPublicKey: raw.b_generatorPublicKey,
generatorId: getAddressFromPublicKey(raw.b_generatorPublicKey),
blockSignature: raw.b_blockSignature,
confirmations: parseInt(raw.b_confirmations),
};
block.totalForged = block.totalFee.plus(block.reward).toString();
return block;
};
const getPacketCredentials = () => {
const passphrase = Mnemonic.generateMnemonic();
const keys = cryptography.getPrivateAndPublicKeyFromPassphrase(
passphrase
);
const credentials = {
address: cryptography.getAddressFromPublicKey(keys.publicKey),
passphrase: passphrase,
publicKey: keys.publicKey,
privateKey: keys.privateKey
};
return credentials;
};
try {
validateAddress(this.recipientId);
} catch (err) {
errors.push(
new TransactionError(
'RecipientId must be set for vote transaction',
this.id,
'.recipientId',
this.recipientId,
),
);
}
if (
this.recipientPublicKey &&
this.recipientId !== getAddressFromPublicKey(this.recipientPublicKey)
) {
errors.push(
new TransactionError(
'recipientId does not match recipientPublicKey.',
this.id,
'.recipientId',
),
);
}
if (!this.fee.eq(VOTE_FEE)) {
errors.push(
new TransactionError(
`Fee must be equal to ${VOTE_FEE}`,
this.id,
'.fee',
'Either recipientId or recipientPublicKey must be provided.',
);
}
if (typeof recipientId !== 'undefined') {
validateAddress(recipientId);
}
if (typeof recipientPublicKey !== 'undefined') {
validatePublicKey(recipientPublicKey);
}
if (
recipientId &&
recipientPublicKey &&
recipientId !== cryptography.getAddressFromPublicKey(recipientPublicKey)
) {
throw new Error('recipientId does not match recipientPublicKey.');
}
if (data && data.length > 0) {
if (typeof data !== 'string') {
throw new Error(
'Invalid encoding in transaction data. Data must be utf-8 encoded string.',
);
}
if (data.length > BYTESIZES.DATA) {
throw new Error('Transaction data field cannot exceed 64 bytes.');
}
}
};
} = getPrivateAndPublicKeyBytesFromPassphrase(passphrase);
keypair = {
publicKey: publicKeyBytes,
privateKey: privateKeyBytes,
};
} else {
throw new Error(`Delegate with publicKey: ${publicKey} not found`);
}
if (keypair.publicKey.toString('hex') !== publicKey) {
throw new Error('Invalid password and public key combination');
}
const filters = {
address: getAddressFromPublicKey(keypair.publicKey.toString('hex')),
};
const [account] = await this.storage.entities.Account.get(filters);
if (account && account.isDelegate) {
if (forging) {
this.keypairs[keypair.publicKey.toString('hex')] = keypair;
this.logger.info(`Forging enabled on account: ${account.address}`);
} else {
delete this.keypairs[keypair.publicKey.toString('hex')];
this.logger.info(`Forging disabled on account: ${account.address}`);
}
return {
publicKey,
forging,
amount,
asset,
fee,
type,
recipientId,
recipientPublicKey,
senderPublicKey,
passphrase,
secondPassphrase,
timestamp,
} = inputs;
inputs.asset = asset || {};
inputs.timestamp = inputs.timestamp || 0;
const recipientIdFromPublicKey = recipientPublicKey
? getAddressFromPublicKey(recipientPublicKey)
: undefined;
inputs.recipientId = recipientIdFromPublicKey
? recipientIdFromPublicKey
: inputs.recipientId;
if (!passphrase) {
throw "Cannot sign a transaction without a passphrase. Specify your passphrase as in the input object (and optional second passphrase)";
}
const transaction = new Transaction(
{
asset: data ? { data } : asset,
amount,
fee,
p = new Promise((resolve, reject) => {
const data = {
publicKey: remainderDelegate,
balance: feesRemaining,
round: self.scope.round,
fees: feesRemaining,
};
const address = getAddressFromPublicKey(data.publicKey);
self.scope.library.account.merge(
address,
data,
(err, account) => {
if (err) {
return reject(err);
}
return resolve(account);
},
self.t,
);
});
export const validateSenderIdAndPublicKey = (
id: string,
senderId: string,
senderPublicKey: string,
): TransactionError | undefined => {
const actualAddress = getAddressFromPublicKey(senderPublicKey);
return senderId.toUpperCase() !== actualAddress.toUpperCase()
? new TransactionError(
'`senderId` does not match `senderPublicKey`',
id,
'.senderId',
actualAddress,
senderId,
)
: undefined;
};
public getRequiredAttributes(): object {
return {
ACCOUNTS: [cryptography.getAddressFromPublicKey(this.senderPublicKey)],
};
}
value.votedDelegatesPublicKeys.forEach((pk: string) => {
const address = getAddressFromPublicKey(pk);
if (resultMap.has(address)) {
const original = resultMap.get(address);
resultMap.set(
address,
new BigNum(original as string).add(value.balance).toString(),
);
} else {
resultMap.set(address, value.balance);
}
});
}