How to use the snarkjs.bigInt.leInt2Buff function in snarkjs

To help you get started, we’ve selected a few snarkjs 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 barryWhiteHat / maci / app / utils / crypto.js View on Github external
const sign = (prv: BigInt, _msg: BigInt): { R8: BigInt, S: BigInt } => {
  // Doing this as bigInt2Buffer requires a custom
  // methods 'greater' than isn't in the standard bigint
  // object (its a snarkjs custom bigint obj method)
  const msg = bigInt(_msg)

  const h1 = bigInt2Buffer(hash(prv))
  const sBuff = eddsa.pruneBuffer(h1.slice(0, 32))
  const s = bigInt.leBuff2int(sBuff)
  const A = babyJub.mulPointEscalar(babyJub.Base8, s.shr(3))

  const msgBuff = bigInt.leInt2Buff(

  const rBuff = bigInt2Buffer(hash(
      [h1.slice(32, 64), msgBuff]
  let r = bigInt.leBuff2int(rBuff)
  r = r.mod(babyJub.subOrder)
  const R8 = babyJub.mulPointEscalar(babyJub.Base8, r)
  const hm = multiHash([R8[0], R8[1], A[0], A[1], msg])
  const S = r.add(hm.mul(s)).mod(babyJub.subOrder)
  return {
    R8: R8,