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);
};
Transaction.prototype.sign = (keyPair, trs) => {
const sig = Buffer.alloc(sodium.crypto_sign_BYTES);
sodium.crypto_sign_detached(sig, self.getHash(trs), keyPair.privateKey);
return sig.toString('hex');
};
ed.sign = function (hash, keyPair) {
const sig = Buffer.alloc(sodium.crypto_sign_BYTES);
sodium.crypto_sign_detached(sig, hash, keyPair.privateKey);
return sig;
};
private sign(block, keyPair): Response {
const blockHash = this.getHash(block);
if (!blockHash.success) {
return new Response({ errors: [...blockHash.errors, 'sign'] });
}
const sig = Buffer.alloc(sodium.crypto_sign_BYTES);
sodium.crypto_sign_detached(sig, blockHash.data, keyPair.privateKey);
return new Response({ data: sig.toString('hex') });
}
Transaction.prototype.sign = function (keyPair, trs) {
const sig = Buffer.alloc(sodium.crypto_sign_BYTES);
sodium.crypto_sign_detached(sig, this.getHash(trs), keyPair.privateKey);
return sig.toString('hex');
};
Block.prototype.sign = function (block, keyPair) {
const blockHash = this.getHash(block);
const sig = Buffer.alloc(sodium.crypto_sign_BYTES);
sodium.crypto_sign_detached(sig, blockHash, keyPair.privateKey);
return sig.toString('hex');
};