Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (precommit == null) continue
if (!precommit.block_id.hash) continue
let validator = validatorsByAddress[precommit.validator_address]
// skip if this validator isn't in the set
// (we allow precommits from validators not in the set,
// because we sometimes check the commit against older
// validator sets)
if (!validator) continue
let signature = Buffer.from(precommit.signature, 'base64')
let signBytes = getVoteSignBytes(header.chain_id, precommit)
let pubKey = Buffer.from(validator.pub_key.value, 'base64')
if (!ed25519.verify(signature, signBytes, pubKey)) {
throw Error('Invalid precommit signature')
}
// count this validator's voting power
committedVotingPower += safeParseInt(validator.voting_power)
}
// sum all validators' voting power
let totalVotingPower = validators.reduce(
(sum, v) => sum + safeParseInt(v.voting_power), 0)
// JS numbers have no loss of precision up to 2^53, but we
// error at over 2^52 since we have to do arithmetic. apps
// should be able to keep voting power lower than this anyway
if (totalVotingPower > 2 ** 52) {
throw Error('Total voting power must be less than 2^52')
}
onSpend ({ pubkey, signature }, { sigHash }) {
// verify signature
if (!ed25519.verify(signature, sigHash, pubkey)) {
throw Error('Invalid signature')
}
}
}
export function verify (opt: { publicKey: string, message: string, signature: string }) {
const valid = supercop.verify(
new Buffer(opt.signature, "base64"),
new Buffer(opt.message),
new Buffer(opt.publicKey, "base64")
);
return valid;
}