How to use mcl-wasm - 10 common examples

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
async function init () {
  await mcl.init(mcl.BLS12_381)
}
github ChainSafe / lodestar / old / index.js View on Github external
function hashToG2 (messageHash, domain) {
  assert.equal(messageHash.length, 32, 'messageHash must be 32 bytes long')
  assert.equal(domain.length, 8, 'domain must be 8 bytes long')
	const xReal = keccak256(Buffer.concat([
    messageHash,
    domain,
    Buffer.from([1]),
  ]))
  const xRealFp = new mcl.Fp()
  xRealFp.setLittleEndian(xReal)
	const xImag = keccak256(Buffer.concat([
    messageHash,
    domain,
    Buffer.from([2]),
  ]))
  const xImagFp = new mcl.Fp()
  xImagFp.setLittleEndian(xImag)
  const xCoordinate = new mcl.Fp2()
  xCoordinate.set_a(xRealFp)
  xCoordinate.set_b(xImagFp)
  return xCoordinate.mapToG2()
}
github ChainSafe / lodestar / old / index.js View on Github external
function hashToG2 (messageHash, domain) {
  assert.equal(messageHash.length, 32, 'messageHash must be 32 bytes long')
  assert.equal(domain.length, 8, 'domain must be 8 bytes long')
	const xReal = keccak256(Buffer.concat([
    messageHash,
    domain,
    Buffer.from([1]),
  ]))
  const xRealFp = new mcl.Fp()
  xRealFp.setLittleEndian(xReal)
	const xImag = keccak256(Buffer.concat([
    messageHash,
    domain,
    Buffer.from([2]),
  ]))
  const xImagFp = new mcl.Fp()
  xImagFp.setLittleEndian(xImag)
  const xCoordinate = new mcl.Fp2()
  xCoordinate.set_a(xRealFp)
  xCoordinate.set_b(xImagFp)
  return xCoordinate.mapToG2()
}
github ChainSafe / lodestar / old / index.js View on Github external
assert.equal(domain.length, 8, 'domain must be 8 bytes long')
	const xReal = keccak256(Buffer.concat([
    messageHash,
    domain,
    Buffer.from([1]),
  ]))
  const xRealFp = new mcl.Fp()
  xRealFp.setLittleEndian(xReal)
	const xImag = keccak256(Buffer.concat([
    messageHash,
    domain,
    Buffer.from([2]),
  ]))
  const xImagFp = new mcl.Fp()
  xImagFp.setLittleEndian(xImag)
  const xCoordinate = new mcl.Fp2()
  xCoordinate.set_a(xRealFp)
  xCoordinate.set_b(xImagFp)
  return xCoordinate.mapToG2()
}
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))
}
github ChainSafe / lodestar / old / index.js View on Github external
function g1() {
	const g = new mcl.G1()
	g.setStr('1 3685416753713387016781088315183077757961620795782546409894578378688607592378376318836054947676345821548104185464507 1339506544944476473020471379941921221584933875938349620426543736416511423956333506472724655353366534992391756441569')
	return g
}
github ChainSafe / lodestar / old / index.js View on Github external
    .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 genPublic (secretKey) {
  const s = mclSecretKey(secretKey)
  const q = g1()
  const key = toBuffer(mcl.mul(q, s));
  key[0] |= 0xa0;
  return key
}

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

77 / 100
Full package analysis