How to use the circomlib.babyJub.Base8 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
// @flow

const { babyJub, eddsa } = require('circomlib');
const crypto = require('crypto');
const { bigInt } = require('snarkjs');
const createBlakeHash = require('blake-hash');

const utils = require('../utils');


const baseBabyJub = babyJub.Base8;

/**
 * Get compressed point given a public key compsed by coordinate X and Y
 * @param {Buffer} pubKeyX - Coordinate X of public key
 * @param {Buffer} pubKeyY - Coordinate Y of public key
 * @returns {Buffer} - Public key compressed
 */
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 barryWhiteHat / maci / boilerplate / crypto / ts / index.ts View on Github external
const genPubKey = (privKey: PrivKey): PubKey => {
    // Check whether privKey is a field element
    assert(privKey < SNARK_FIELD_SIZE)

    // TODO: check whether privKey is valid (i.e. that the prune buffer step
    // worked)

    const pubKey = babyJub.mulPointEscalar(
        babyJub.Base8,
        formatPrivKeyForBabyJub(privKey),
    )

    // TODO: assert that pubKey is valid
    // TODO: figure out how to check if pubKey is valid

    return pubKey
}
github barryWhiteHat / maci / boilerplate / crypto / ts / index.ts View on Github external
plaintext,
        32
    )

    const rBuff = bigInt2Buffer(
        mimcspongeHashOne(
            buffer2BigInt(Buffer.concat(
                [h1.slice(32, 64), msgBuff]
            ))
        )
    )

    let r = snarkjs.bigInt.leBuff2int(rBuff)
    r = r.mod(babyJub.subOrder)

    const R8 = babyJub.mulPointEscalar(babyJub.Base8, r)
    const hm = mimcsponge.multiHash([R8[0], R8[1], A[0], A[1], plaintext], 0, 1)
    const S = r.add(hm.mul(s)).mod(babyJub.subOrder)

    const signature: Signature = { R8, S }

    return signature
}
github barryWhiteHat / maci / app / utils / crypto.js View on Github external
const privateToPublicKey = (sk: BigInt): [BigInt, BigInt] => {
  const s = babyJubJubPrivateKey(sk)

  return babyJub.mulPointEscalar(
    babyJub.Base8,
    s
  )
}
github barryWhiteHat / maci / app / utils / crypto.js View on Github external
const s = bigInt.leBuff2int(sBuff)
  const A = babyJub.mulPointEscalar(babyJub.Base8, s.shr(3))

  const msgBuff = bigInt.leInt2Buff(
    msg,
    32
  )

  const rBuff = bigInt2Buffer(hash(
    buffer2BigInt(Buffer.concat(
      [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,
    S: S
  }
}