UNPKG

hollowdb-prover

Version:

Zero-knowledge proof generator utiity for HollowDB

58 lines (50 loc) 2.75 kB
var $kVTRK$crypto = require("crypto"); var $kVTRK$poseidonliteposeidon1 = require("poseidon-lite/poseidon1"); var $kVTRK$snarkjs = require("snarkjs"); function $parcel$export(e, n, v, s) { Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true}); } $parcel$export(module.exports, "Prover", () => $122091b78650b7d0$export$4d1acfc984b63c8f); $parcel$export(module.exports, "hashToGroup", () => $122091b78650b7d0$export$a9a26ae1d12155c4); $parcel$export(module.exports, "computeKey", () => $122091b78650b7d0$export$fb80376c49a099f2); const $122091b78650b7d0$var$bn254Prime = BigInt("21888242871839275222246405745257275088548364400416034343698204186575808495617"); const $122091b78650b7d0$var$TooLargeError = new Error("Preimage is larger than the order of scalar field of BN254."); class $122091b78650b7d0$export$4d1acfc984b63c8f { /** Generate a zero-knowledge proof. * * Calls {@link hashToGroup} on inputs, and then generates * a proof with {@link proveHashed}. */ async prove(preimage, curValue, nextValue) { return await this.proveHashed(preimage, $122091b78650b7d0$export$a9a26ae1d12155c4(curValue), $122091b78650b7d0$export$a9a26ae1d12155c4(nextValue)); } /** Generate a zero-knowledge proof. * * Value inputs are expected to be results of {@link hashToGroup}. The * incentive of using this function instead of {@link prove} is that the * hash may be stored somewhere, and there is no need to hash the entire value * again at a later time instead of using the existing hash. */ async proveHashed(preimage, curValueHash, nextValueHash) { if (preimage >= $122091b78650b7d0$var$bn254Prime) throw $122091b78650b7d0$var$TooLargeError; return await (this.protocol === "groth16" ? (0, $kVTRK$snarkjs.groth16) : (0, $kVTRK$snarkjs.plonk)).fullProve({ preimage: preimage, curValueHash: curValueHash, nextValueHash: nextValueHash }, this.wasmPath, this.proverKeyPath); } constructor(wasmPath, proverKeyPath, protocol = "groth16"){ this.wasmPath = wasmPath; this.proverKeyPath = proverKeyPath; this.protocol = protocol; } } function $122091b78650b7d0$export$a9a26ae1d12155c4(value) { if (value) return BigInt("0x" + (0, $kVTRK$crypto.createHash)("ripemd160").update(Buffer.from(JSON.stringify(value))).digest("hex")); else return BigInt(0); } function $122091b78650b7d0$export$fb80376c49a099f2(preimage) { if (preimage >= $122091b78650b7d0$var$bn254Prime) throw $122091b78650b7d0$var$TooLargeError; return "0x" + (0, $kVTRK$poseidonliteposeidon1.poseidon1)([ preimage ]).toString(16); } //# sourceMappingURL=index.cjs.map