# websnark
A fast zkSnark proof generator written in native Web Assembly.
websnark is used to generate zkSnark Proofs from the browser.
This module generates highly optimized Web Assembly modules for the low level
cryptographic primitives.
It also makes use of the Web Workers feature to parallelize the generation
of the zero knoledge proofs.
The result is a fast library with times close to libsnarks but fully compatible for
browsers.
## Usage
You just need to import the websnark.js found in the build directory.
```html
```
This library has a single javascript function:
genZKSnarkProof(witness, provingKey, cb)
cb is the callback. If cb is undefined, then the function will return a promise.
witness is a binary buffer with all the signals in binnary format. The buffer is packt in 32bytes Little Endian Encoded Field Elements.
You can use the tool to build the binary file from the witness.json file generated by [snarkjs](https://github.com/iden3/snarkjs).
### IMPORTANT: Please be sure you run your setup with `--protocol groth` websnark only generates groth16 proofs!
```
node ../tools/buildwitness.js -i witness.json -o witness.bin
```
provingKey is the binary buffer with the binary representation of the proving key.
Check the tool tools/buildpkey.js to convert a proving_key.json file generated
in [snarkjs](https://github.com/iden3/snarkjs) to a proving_key.bin file that can
be used directly with this library.
```
node ../tools/buildpkey.js -i proving_key.json -o proving_key.bin
```
The result is a JSON object with pi_a, pi_b and pi_c points.
You can use the stringified version of this JSON as a proof.json in [snarkjs](https://github.com/iden3/snarkjs)
Here is a simple example of a web page that loads a key and a witness and generates the proof when the button is pressed.
```html