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.genZKSnarkProof = function(witness, provingKey, cb) {
26
27 const p = groth16.proof(witness, provingKey);
28
29 if (cb) {
30 p.then( (proof) => {
31 cb(null, proof);
32 }, (err) => {
33 cb(err);
34 });
35 } else {
36 return p;
37 }
38 };
39});
40
41