// This file is a bit of a mess because of different bigInt formats in websnark and snarkjs // It will be rewritten during browser integration const fs = require('fs'); const circom = require("circom"); 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 mimcsponge = circomlib.mimcsponge; const bigInt = snarkjs.bigInt; const buildGroth16 = require('websnark/src/groth16'); const stringifyBigInts = require("websnark/tools/stringifybigint").stringifyBigInts; const unstringifyBigInts = require("websnark/tools/stringifybigint").unstringifyBigInts; const stringifyBigInts2 = require("snarkjs/src/stringifybigint").stringifyBigInts; const unstringifyBigInts2 = require("snarkjs/src/stringifybigint").unstringifyBigInts; const rbigint = (nbytes) => snarkjs.bigInt.leBuff2int(crypto.randomBytes(nbytes)); function unhexBigInts(o) { if ((typeof(o) == "string") && (/^0x[0-9a-fA-F]+$/.test(o))) { return bigInt(o); } else if (Array.isArray(o)) { return o.map(unhexBigInts); } else if (typeof o == "object") { const res = {}; for (let k in o) { res[k] = unhexBigInts(o[k]); } return res; } else { return o; } } function pedersenHash(data) { return babyjub.unpackPoint(pedersen.hash(data))[0]; } function mimcHash(left, right) { return mimcsponge.multiHash([bigInt(left), bigInt(right)]).toString(); } function p256(o) { if ((typeof(o) == "bigint") || (o instanceof bigInt)) { let nstr = o.toString(16); while (nstr.length < 64) nstr = "0"+nstr; nstr = "0x"+nstr; return nstr; } else if (Array.isArray(o)) { return o.map(p256); } else if (typeof o == "object") { const res = {}; for (let k in o) { if (k === "value") { return p256(o[k]); } res[k] = p256(o[k]); } return res; } else { return o; } } function convertWitness(witness) { witness = unstringifyBigInts(witness); const buffLen = witness.length * 32; const buff = new ArrayBuffer(buffLen); const h = { dataView: new DataView(buff), offset: 0 }; for (let i=0; i