How to use the circomlib.eddsa.pruneBuffer function in circomlib

To help you get started, we’ve selected a few circomlib 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 babyJubJubPrivateKey = (priv: BigInt): BigInt => {
  // Formats private key to be babyJubJub compatiable

  // https://tools.ietf.org/html/rfc8032
  // Because of the "buff[0] & 0xF8" part which makes sure you have a point with order that 8 divides
  // (^ pruneBuffer)
  // Every point in babyjubjub is of the form: aP + bH, where H has order 8 and P has a big large prime order
  // Guaranteeing that any low order points in babyjubjub get deleted
  // ^From Kobi
  const sBuff = eddsa.pruneBuffer(
    bigInt2Buffer(hash(priv))
      .slice(0, 32)
  )

  return bigInt.leBuff2int(sBuff).shr(3)
}
github barryWhiteHat / maci / boilerplate / crypto / ts / index.ts View on Github external
const formatPrivKeyForBabyJub = (privKey: PrivKey) => {

    // TODO: clarify this explanation
    // https://tools.ietf.org/html/rfc8032
    // Because of the "buff[0] & 0xF8" part which makes sure you have a point
    // with order that 8 divides (^ pruneBuffer)
    // Every point in babyjubjub is of the form: aP + bH, where H has order 8
    // and P has a big large prime order
    // Guaranteeing that any low order points in babyjubjub get deleted
    const sBuff = eddsa.pruneBuffer(
        bigInt2Buffer(
            mimcspongeHashOne(privKey)
        ).slice(0, 32)
    )

    return snarkjs.bigInt.leBuff2int(sBuff).shr(3)
}
github iden3 / iden3js / src / crypto / babyjub-utils.js View on Github external
function privToScalar(privKey: Buffer): bigInt {
  const h1 = createBlakeHash('blake512').update(privKey).digest();
  const sBuff = eddsa.pruneBuffer(h1.slice(0, 32));
  const scalar = (bigInt.leBuff2int(sBuff)).shr(3);
  if (scalar >= babyJub.p) {
    throw new Error('scalar generated larger than subgroup');
  }
  return scalar;
}
github iden3 / iden3js / src / crypto / eddsa-babyjub.js View on Github external
toPrivScalar(): bigInt {
    const h1 = createBlakeHash('blake512').update(this.sk).digest();
    const sBuff = eddsa.pruneBuffer(h1.slice(0, 32));
    return (bigInt.leBuff2int(sBuff)).shr(3);
  }