Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function verifyMultiple (pubkeys, messageHashes, signature, domain) {
assert.equal(pubkeys.length, messageHashes.length,
'number of pubkeys must equal number of message hashes')
const pubkeyG1s = pubkeys.map((pub) => mclPubkey(pub))
const signatureG2 = mclSignature(signature)
const ePH = Array.from({length: pubkeys.length}, (_, i) => i)
// create a pairing for each pubkey, messageHash pair
.map((i) => toG2AndPairing(pubkeyG1s[i], messageHashes[i], domain))
// accumulate into a single mcl.GT
.reduce((acc, val) => mcl.mul(acc, val))
return ePH.isEqual(mcl.pairing(g1(), signatureG2))
}
function toG2AndPairing (pubkey, messageHash, domain) {
return mcl.pairing(pubkey, hashToG2(messageHash, domain))
}
function verify (pubkey, messageHash, signature, domain) {
const pubkeyG1 = mclPubkey(pubkey)
const signatureG2 = mclSignature(signature)
return toG2AndPairing(pubkeyG1, messageHash, domain).isEqual(mcl.pairing(g1(), signatureG2))
}