-
Notifications
You must be signed in to change notification settings - Fork 421
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add Browser ES module build * ES module browser fix * Rename build * Remove prepare script * fix browser tests for ESM build * update package lock * Package lock update * Fix browser test
- Loading branch information
1 parent
f6e3bf7
commit 86ea360
Showing
13 changed files
with
37,080 additions
and
3,432 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
}, | ||
"devDependencies": { | ||
"puppeteer": "20.2.0", | ||
"ffjavascript": "^0.2.62", | ||
"st": "3.0.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/browser.esm.js"); | ||
await testBrowserBuilds(esmBuild); | ||
shutdown(); | ||
</script> | ||
</body> | ||
</body> | ||
</html> | ||
|
||
<head> </head> | ||
|
||
<body></body> |
Oops, something went wrong.