How to use the circomlib.babyJub.p 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 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 / babyjub-utils.js View on Github external
function compressPoint(pubKeyX: Buffer, pubKeyY: Buffer): Buffer {
  const pubKeyXBigInt = utils.bufferToBigIntBE(pubKeyX);
  if (pubKeyXBigInt.greater(babyJub.p.shr(1))) {
    pubKeyY[0] |= 0x80;
  }
  return pubKeyY;
}
github iden3 / iden3js / src / claim / entry.js View on Github external
function checkElemFitsClaim(elem: Buffer) {
  if (elem.length !== 32) {
    throw new Error('Element is not 32 bytes length');
  }
  const elemBigInt = utils.bufferToBigIntBE(elem);
  if (elemBigInt.greater(babyJub.p)) {
    throw new Error('Element does not fit on claim element size');
  }
}