How to use the mcl-wasm.pairing function in mcl-wasm

To help you get started, we’ve selected a few mcl-wasm examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ChainSafe / lodestar / old / index.js View on Github external
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))
}
github ChainSafe / lodestar / old / index.js View on Github external
function toG2AndPairing (pubkey, messageHash, domain) {
  return mcl.pairing(pubkey, hashToG2(messageHash, domain))
}
github ChainSafe / lodestar / old / index.js View on Github external
function verify (pubkey, messageHash, signature, domain) {
  const pubkeyG1 = mclPubkey(pubkey)
  const signatureG2 = mclSignature(signature)
	return toG2AndPairing(pubkeyG1, messageHash, domain).isEqual(mcl.pairing(g1(), signatureG2))
}

mcl-wasm

mcl ; A portable and fast pairing-based cryptography library for Node.js by WebAssembly

BSD-3-Clause
Latest version published 2 months ago

Package Health Score

75 / 100
Full package analysis