Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
delegateList: string[],
): ReadonlyArray => {
// tslint:disable-next-line no-let
let hashedRound = hash(round, 'utf8');
const list = [...delegateList];
const numberOfDelegates = delegateList.length;
// tslint:disable-next-line
for (let i = 0; i < numberOfDelegates; i++) {
// tslint:disable-next-line
for (let j = 0; j < 4 && i < numberOfDelegates; i++, j++) {
const newIndex = hashedRound[j] % numberOfDelegates;
const temp = list[newIndex];
list[newIndex] = list[i];
list[i] = temp;
}
hashedRound = hash(hashedRound, 'utf8');
}
return list;
};
export const generateDelegateList = (
round: string,
delegateList: string[],
): ReadonlyArray => {
// tslint:disable-next-line no-let
let hashedRound = hash(round, 'utf8');
const list = [...delegateList];
const numberOfDelegates = delegateList.length;
// tslint:disable-next-line
for (let i = 0; i < numberOfDelegates; i++) {
// tslint:disable-next-line
for (let j = 0; j < 4 && i < numberOfDelegates; i++, j++) {
const newIndex = hashedRound[j] % numberOfDelegates;
const temp = list[newIndex];
list[newIndex] = list[i];
list[i] = temp;
}
hashedRound = hash(hashedRound, 'utf8');
}
return list;
};
signature: string,
transaction: TransactionJSON,
isSecondSignature: boolean = false,
): VerifyReturn => {
const {
signature: removedSignature,
signSignature,
...strippedTransaction
} = transaction;
// If transaction includes asset data, include those bytes
const transactionBytes =
transaction.asset && Object.keys(transaction.asset).length
? getTransactionBytes(strippedTransaction as TransactionJSON)
: getBytes(transaction, !isSecondSignature);
const transactionHash = cryptography.hash(transactionBytes);
const verified = cryptography.verifyData(
transactionHash,
signature,
publicKey,
);
return {
verified,
error: !verified
? new TransactionError(
`Failed to verify signature ${signature}`,
transaction.id,
'.signature',
)
: undefined,
_verifySignature(targetChain, publicKey, transaction, signatureToVerify) {
let isValidMemberSignature = this.multisigWalletInfo[targetChain].members[publicKey];
if (!isValidMemberSignature) {
return false;
}
let {signature, signSignature, ...transactionToHash} = transaction;
let txnHash = liskCryptography.hash(liskTransactions.utils.getTransactionBytes(transactionToHash));
return liskCryptography.verifyData(txnHash, signatureToVerify, publicKey);
}
export const getTransactionHash = (transaction: TransactionJSON): Buffer => {
const bytes = getTransactionBytes(transaction);
return cryptography.hash(bytes);
};
const verifySignature = block => {
const signatureLength = 64;
const data = getBytes(block);
const dataWithoutSignature = Buffer.alloc(data.length - signatureLength);
for (let i = 0; i < dataWithoutSignature.length; i++) {
dataWithoutSignature[i] = data[i];
}
const hashedBlock = hash(dataWithoutSignature);
return verifyData(
hashedBlock,
block.blockSignature,
block.generatorPublicKey
);
};
export const getTransactionHash = (transaction: BaseTransaction): Buffer => {
const bytes = getTransactionBytes(transaction);
return cryptography.hash(bytes);
};
export const validateSignature = (
publicKey: string,
signature: string,
transactionBytes: Buffer,
id?: string,
): IsValidResponseWithError => {
const transactionHash = cryptography.hash(transactionBytes);
const valid = cryptography.verifyData(transactionHash, signature, publicKey);
return {
valid,
error: !valid
? new TransactionError(
`Failed to validate signature ${signature}`,
id,
'.signature',
)
: undefined,
};
};