Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
numberOfSignatures: 3,
},
signatures: [],
};
sortKeysDescending(tx.asset.mandatoryKeys);
sortKeysDescending(tx.asset.optionalKeys);
let txBuffer = serializeBasicProperties(tx);
createMembersSignatures(tx, txBuffer);
txBuffer = serializeMemberSignatures(tx, txBuffer);
// Sender signs whole transaction
const signature = signData(
hash(Buffer.concat([hexToBuffer(networkIdentifier), txBuffer])),
accounts[0].passphrase,
);
const signedRegistrationTx = { ...tx, signature };
const id = getId(Buffer.concat([txBuffer, Buffer.from(signature, 'hex')]));
signedRegistrationTx.id = id;
return {
input: {
account: accounts[1],
networkIdentifier,
coSigners: [accounts[2], accounts[3], accounts[4], accounts[5]],
transaction: tx,
},
const createSignatureObject = (txBuffer, account) => ({
// publicKey: account.publicKey,
signature: signData(
hash(Buffer.concat([hexToBuffer(networkIdentifier), txBuffer])),
account.passphrase,
),
});
const validStatus = tx.validate();
if (validStatus.errors.length > 0) {
throw new Error('Invalid transaction.');
}
const { publicKey } = cryptography.getPrivateAndPublicKeyFromPassphrase(
passphrase,
);
// tslint:disable-next-line no-any
(tx as any)._signature = undefined;
// tslint:disable-next-line no-any
(tx as any)._signSignature = undefined;
const multiSignature = cryptography.signData(
cryptography.hash(tx.getBytes()),
passphrase,
);
return {
transactionId: tx.id,
publicKey,
signature: multiSignature,
};
};
let txn = {
type: 0,
amount: transactionData.amount.toString(),
recipientId: transactionData.recipientId,
fee: liskTransactions.constants.TRANSFER_FEE.toString(),
asset: {},
timestamp: transactionData.timestamp,
senderPublicKey: liskCryptography.getAddressAndPublicKeyFromPassphrase(chainOptions.sharedPassphrase).publicKey
};
if (message != null) {
txn.asset.data = message;
}
let preparedTxn = liskTransactions.utils.prepareTransaction(txn, chainOptions.sharedPassphrase);
let {signature, signSignature, ...transactionToHash} = preparedTxn;
let txnHash = liskCryptography.hash(liskTransactions.utils.getTransactionBytes(transactionToHash));
let multisigTxnSignature = liskCryptography.signData(txnHash, chainOptions.passphrase);
let publicKey = liskCryptography.getAddressAndPublicKeyFromPassphrase(chainOptions.passphrase).publicKey;
preparedTxn.signatures = [multisigTxnSignature];
let processedSignatureSet = new Set();
processedSignatureSet.add(multisigTxnSignature);
// If the pendingTransfers map already has a transaction with the specified id, delete the existing entry so
// that when it is re-inserted, it will be added at the end of the queue.
// To perform expiry using an iterator, it's essential that the insertion order is maintained.
if (this.pendingTransfers.has(preparedTxn.id)) {
this.pendingTransfers.delete(preparedTxn.id);
}
this.pendingTransfers.set(preparedTxn.id, {
transaction: preparedTxn,
targetChain,
processedSignatureSet,
transactionTimestamp.writeIntBE(tx.timestamp, 0, 4);
const txBuffer = Buffer.concat([
Buffer.alloc(1, tx.type),
transactionTimestamp,
hexToBuffer(tx.senderPublicKey),
intToBuffer(tx.asset.amount, 8, 'big'),
intToBuffer(tx.asset.recipientId.slice(0, -1), 8),
Buffer.from(tx.asset.data, 'utf8'),
]);
const signature = signData(
hash(Buffer.concat([hexToBuffer(networkIdentifier), txBuffer])),
accounts[0].passphrase,
);
const signSignature = signData(
hash(
Buffer.concat([
hexToBuffer(networkIdentifier),
txBuffer,
Buffer.from(signature, 'hex'),
]),
),
accounts[1].passphrase,
);
const id = getId(
Buffer.concat([
txBuffer,
Buffer.from(signature, 'hex'),
Buffer.from(signSignature, 'hex'),
]),
`+${accounts[2].publicKey}`,
`-${accounts[3].publicKey}`,
],
},
};
const transactionTimestamp = Buffer.alloc(4);
transactionTimestamp.writeIntBE(tx.timestamp, 0, 4);
const txBuffer = Buffer.concat([
Buffer.alloc(1, tx.type),
transactionTimestamp,
hexToBuffer(tx.senderPublicKey),
Buffer.from(tx.asset.votes.join(''), 'utf8'),
]);
const signature = signData(
hash(Buffer.concat([hexToBuffer(networkIdentifier), txBuffer])),
accounts[0].passphrase,
);
const id = getId(Buffer.concat([txBuffer, Buffer.from(signature, 'hex')]));
const signedTransaction = {
...tx,
signature,
id,
};
return {
input: {
account: accounts[0],
networkIdentifier,
transactionTimestamp,
hexToBuffer(tx.senderPublicKey),
Buffer.alloc(1, tx.asset.min),
Buffer.alloc(1, tx.asset.lifetime),
Buffer.from(tx.asset.keysgroup.join(''), 'utf8'),
]);
const signature = signData(
hash(Buffer.concat([hexToBuffer(networkIdentifier), txBuffer])),
accounts[0].passphrase,
);
const id = getId(Buffer.concat([txBuffer, Buffer.from(signature, 'hex')]));
const signatures = [
signData(
hash(Buffer.concat([hexToBuffer(networkIdentifier), txBuffer])),
accounts[1].passphrase,
),
signData(
hash(Buffer.concat([hexToBuffer(networkIdentifier), txBuffer])),
accounts[2].passphrase,
),
signData(
hash(Buffer.concat([hexToBuffer(networkIdentifier), txBuffer])),
accounts[3].passphrase,
),
];
const signedTransaction = {
...tx,
signature,
public sign(passphrase: string): void {
this._signature = undefined;
this._signSignature = undefined;
const networkIdentifierBytes = hexToBuffer(this._networkIdentifier);
const transactionWithNetworkIdentifierBytes = Buffer.concat([
networkIdentifierBytes,
this.getBytes(),
]);
this._signature = signData(
hash(transactionWithNetworkIdentifierBytes),
passphrase,
);
this._id = getId(this.getBytes());
}
}