websnark/main.js
main.jsRaw
1/*
2 Copyright 2019 0KIMS association.
3
4 This file is part of websnark (Web Assembly zkSnark Prover).
5
6 websnark is a free software: you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 websnark is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
14 License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with websnark. If not, see <https://www.gnu.org/licenses/>.
18*/
19
20/* globals window */
21
22const buildGroth16 = require("./src/groth16.js");
23
24buildGroth16().then( (groth16) => {
25 window.groth16 = groth16;
26 window.genZKSnarkProof = function(witness, provingKey, cb) {
27
28 const p = groth16.proof(witness, provingKey);
29
30 if (cb) {
31 p.then( (proof) => {
32 cb(null, proof);
33 }, (err) => {
34 cb(err);
35 });
36 } else {
37 return p;
38 }
39 };
40});
41
42