How to use the circomlib.pedersenHash 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 kobigurk / semaphore / semaphorejs / src / client / semaphore.js View on Github external
function pedersenHash(ints) {
  const p = circomlib.babyJub.unpackPoint(circomlib.pedersenHash.hash(Buffer.concat(
             ints.map(x => x.leInt2Buff(32))
  )));
  return bigInt(p[0]);
}
github tornadocash / tornado-core / cli.js View on Github external
const pedersenHash = (data) => circomlib.babyJub.unpackPoint(circomlib.pedersenHash.hash(data))[0]
github tornadocash / tornado-core / scripts / utils.js View on Github external
const snarkjs = require('snarkjs')
const groth = snarkjs['groth']
const crypto = require('crypto')
const circomlib = require('circomlib')
const pedersen = circomlib.pedersenHash
const babyjub = circomlib.babyJub
const websnarkUtils = require('websnark/src/utils')
const unstringifyBigInts2 = require('snarkjs/src/stringifybigint').unstringifyBigInts

const rbigint = (nbytes) => snarkjs.bigInt.leBuff2int(crypto.randomBytes(nbytes))
const pedersenHash = (data) => babyjub.unpackPoint(pedersen.hash(data))[0]

function snarkVerify(proof) {
  proof = unstringifyBigInts2(websnarkUtils.fromSolidityInput(proof))
  const verification_key = unstringifyBigInts2(require('../build/circuits/withdraw_verification_key.json'))
  return groth.isValid(verification_key, proof, proof.publicSignals)
}

module.exports = { rbigint, pedersenHash, snarkVerify }