Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Browser ES module build #434

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 56 additions & 17 deletions browser_tests/test/groth16.html
Original file line number Diff line number Diff line change
@@ -1,40 +1,79 @@
<head>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<script src="/build/snarkjs.js"></script>
</head>

<body>
<script type="importmap">
{
"imports": {
"ffjavascript": "../../node_modules/ffjavascript/build/browser.esm.js"
}
}
</script>
</head>
<body>
<script type="module">
const ptau_final = "https://hermez.s3-eu-west-1.amazonaws.com/powersOfTau28_hez_final_10.ptau";
async function testBrowserBuilds(build) {
const ptau_final =
"https://hermez.s3-eu-west-1.amazonaws.com/powersOfTau28_hez_final_10.ptau";
const r1cs = "/test/circuit/circuit.r1cs";
const wasm = "/test/circuit/circuit.wasm";
const zkey_0 = { type: "mem" };
const zkey_1 = { type: "mem" };
const zkey_final = { type: "mem" };
const wtns = { type: "mem" };

await snarkjs.zKey.newZKey(r1cs, ptau_final, zkey_0);
await build.zKey.newZKey(r1cs, ptau_final, zkey_0);

await snarkjs.zKey.contribute(zkey_0, zkey_1, "p2_C1", "pa_Entropy1");
await build.zKey.contribute(zkey_0, zkey_1, "p2_C1", "pa_Entropy1");

await snarkjs.zKey.beacon(zkey_1, zkey_final, "B3", "0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20", 10);
await build.zKey.beacon(
zkey_1,
zkey_final,
"B3",
"0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20",
10
);

const verifyFromR1csResult = await snarkjs.zKey.verifyFromR1cs(r1cs, ptau_final, zkey_final);
const verifyFromR1csResult = await build.zKey.verifyFromR1cs(
r1cs,
ptau_final,
zkey_final
);
console.assert(verifyFromR1csResult);

const verifyFromInit = await snarkjs.zKey.verifyFromInit(zkey_0, ptau_final, zkey_final);
const verifyFromInit = await build.zKey.verifyFromInit(
zkey_0,
ptau_final,
zkey_final
);
console.assert(verifyFromInit);

const vKey = await snarkjs.zKey.exportVerificationKey(zkey_final);
const vKey = await build.zKey.exportVerificationKey(zkey_final);

await snarkjs.wtns.calculate({ a: 11, b: 2 }, wasm, wtns);
await build.wtns.calculate({ a: 11, b: 2 }, wasm, wtns);

await snarkjs.wtns.check(r1cs, wtns);
await build.wtns.check(r1cs, wtns);

const { proof, publicSignals } = await snarkjs.groth16.prove(zkey_final, wtns);
const { proof, publicSignals } = await build.groth16.prove(
zkey_final,
wtns
);

const verified = await snarkjs.groth16.verify(vKey, publicSignals, proof);
const verified = await build.groth16.verify(vKey, publicSignals, proof);
console.assert(verified);
}

shutdown();
await testBrowserBuilds(snarkjs);
const esmBuild = await import("/build/esm.js");
await testBrowserBuilds(esmBuild);
shutdown();
</script>
</body>
</body>
</html>

<head> </head>

<body></body>
Loading
Loading