Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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,
};
};
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
);
};
_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 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,
};
};
const validateSignature = (block, blockBytes) => {
const signatureLength = 64;
const dataWithoutSignature = blockBytes.slice(
0,
blockBytes.length - signatureLength,
);
const hashedBlock = hash(dataWithoutSignature);
const verified = verifyData(
hashedBlock,
block.blockSignature,
block.generatorPublicKey,
);
if (!verified) {
throw new Error('Invalid block signature');
}
};
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
);
};
(
collectedSignatures: ReadonlyArray,
signature: string,
): ReadonlyArray => {
if (
cryptography.verifyData(transactionHash, signature, publicKey)
) {
checkedPublicKeys = [publicKey, ...checkedPublicKeys];
validatedSignaturesCount++;
return collectedSignatures;
}
return [signature, ...collectedSignatures];
},
[],
);
const secondPublicKey = secondPublicKeySource
? await processSecondPublicKey(secondPublicKeySource)
: undefined;
if (!secondPublicKey) {
const { errors } = txInstance.validate();
this.print({
verified: errors.length === 0,
});
return;
}
const verified = cryptography.verifyData(
txInstance.getBytes(),
signSignature,
secondPublicKey,
);
this.print({ verified });
}
}
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
);
};