hollowdb-prover
Version:
Zero-knowledge proof generator utiity for HollowDB
52 lines (45 loc) • 2.52 kB
JavaScript
import {createHash as $iNA3B$createHash} from "crypto";
import {poseidon1 as $iNA3B$poseidon1} from "poseidon-lite/poseidon1";
import {groth16 as $iNA3B$groth16, plonk as $iNA3B$plonk} from "snarkjs";
const $9f098070e0814ba4$var$bn254Prime = BigInt("21888242871839275222246405745257275088548364400416034343698204186575808495617");
const $9f098070e0814ba4$var$TooLargeError = new Error("Preimage is larger than the order of scalar field of BN254.");
class $9f098070e0814ba4$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, $9f098070e0814ba4$export$a9a26ae1d12155c4(curValue), $9f098070e0814ba4$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 >= $9f098070e0814ba4$var$bn254Prime) throw $9f098070e0814ba4$var$TooLargeError;
return await (this.protocol === "groth16" ? (0, $iNA3B$groth16) : (0, $iNA3B$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 $9f098070e0814ba4$export$a9a26ae1d12155c4(value) {
if (value) return BigInt("0x" + (0, $iNA3B$createHash)("ripemd160").update(Buffer.from(JSON.stringify(value))).digest("hex"));
else return BigInt(0);
}
function $9f098070e0814ba4$export$fb80376c49a099f2(preimage) {
if (preimage >= $9f098070e0814ba4$var$bn254Prime) throw $9f098070e0814ba4$var$TooLargeError;
return "0x" + (0, $iNA3B$poseidon1)([
preimage
]).toString(16);
}
export {$9f098070e0814ba4$export$4d1acfc984b63c8f as Prover, $9f098070e0814ba4$export$a9a26ae1d12155c4 as hashToGroup, $9f098070e0814ba4$export$fb80376c49a099f2 as computeKey};
//# sourceMappingURL=index.mjs.map