20 lines
857 B
JavaScript
Raw Normal View History

2019-07-12 19:34:25 +03:00
const snarkjs = require("snarkjs");
const groth = snarkjs["groth"];
const crypto = require("crypto");
const circomlib = require('circomlib');
const pedersen = circomlib.pedersenHash;
const babyjub = circomlib.babyJub;
2019-07-15 19:23:03 +03:00
const websnarkUtils = require('websnark/src/utils');
2019-07-12 23:52:10 +03:00
const unstringifyBigInts2 = require("snarkjs/src/stringifybigint").unstringifyBigInts;
2019-07-12 19:34:25 +03:00
const rbigint = (nbytes) => snarkjs.bigInt.leBuff2int(crypto.randomBytes(nbytes));
2019-07-15 19:23:03 +03:00
const pedersenHash = (data) => babyjub.unpackPoint(pedersen.hash(data))[0];
2019-07-12 19:34:25 +03:00
2019-07-16 18:38:55 +03:00
function snarkVerify(proof) {
2019-07-15 19:23:03 +03:00
proof = unstringifyBigInts2(websnarkUtils.fromSolidityInput(proof));
2019-07-12 23:52:10 +03:00
const verification_key = unstringifyBigInts2(require('../build/circuits/withdraw_verification_key.json'));
2019-07-15 19:23:03 +03:00
return groth.isValid(verification_key, proof, proof.publicSignals);
2019-07-12 19:34:25 +03:00
}
2019-07-15 13:15:41 -07:00
module.exports = {rbigint, pedersenHash, snarkVerify};