Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
Transaction.prototype.verifyBytes = (bytes, publicKey, signature) => {
const hash = crypto.createHash('sha256').update(bytes).digest();
const signatureBuffer = Buffer.from(signature, 'hex');
const publicKeyBuffer = Buffer.from(publicKey, 'hex');
return sodium.crypto_sign_verify_detached(signatureBuffer, hash, publicKeyBuffer);
};
private verifySignature(block: Block, result: IVerifyResult): IVerifyResult {
let valid: boolean = false;
const hash = crypto.createHash('sha256').update(this.getBytes(block)).digest();
const blockSignatureBuffer = Buffer.from(block.signature, 'hex');
const generatorPublicKeyBuffer = Buffer.from(block.generatorPublicKey, 'hex');
try {
valid = sodium.crypto_sign_verify_detached(blockSignatureBuffer, hash, generatorPublicKeyBuffer);
} catch (e) {
if (config.constants.VERIFY_BLOCK_SIGNATURE) {
result.errors.push(e.toString());
} else {
logger.error(e.toString());
}
}
if (!valid) {
if (config.constants.VERIFY_BLOCK_SIGNATURE) {
result.errors.push('Failed to verify block signature');
} else {
logger.error(`Failed to verify block signature`);
}
}
return result;
Transaction.prototype.verifyBytes = function (bytes, publicKey, signature) {
const hash = crypto.createHash('sha256').update(bytes).digest();
const signatureBuffer = Buffer.from(signature, 'hex');
const publicKeyBuffer = Buffer.from(publicKey, 'hex');
return sodium.crypto_sign_verify_detached(signatureBuffer, hash, publicKeyBuffer);
};
Block.prototype.verifySignature = function (block) {
const hash = crypto.createHash('sha256').update(this.getBytes(block)).digest();
const blockSignatureBuffer = Buffer.from(block.blockSignature, 'hex');
const generatorPublicKeyBuffer = Buffer.from(block.generatorPublicKey, 'hex');
return sodium.crypto_sign_verify_detached(blockSignatureBuffer, hash, generatorPublicKeyBuffer);
};
ed.verify = function (hash, signatureBuffer, publicKeyBuffer) {
return sodium.crypto_sign_verify_detached(signatureBuffer, hash, publicKeyBuffer);
};