|
@ -8,7 +8,7 @@ This library uses the compiled circuits generated by the jaz compiler. |
|
|
|
|
|
|
|
|
## Install. |
|
|
## Install. |
|
|
|
|
|
|
|
|
``` |
|
|
|
|
|
|
|
|
```sh |
|
|
npm install zksnark |
|
|
npm install zksnark |
|
|
``` |
|
|
``` |
|
|
|
|
|
|
|
@ -16,13 +16,13 @@ npm install zksnark |
|
|
|
|
|
|
|
|
### Import. |
|
|
### Import. |
|
|
|
|
|
|
|
|
``` |
|
|
|
|
|
|
|
|
```js |
|
|
const zkSnark = require("zksnark"); |
|
|
const zkSnark = require("zksnark"); |
|
|
``` |
|
|
``` |
|
|
|
|
|
|
|
|
### Load a circuit. |
|
|
### Load a circuit. |
|
|
|
|
|
|
|
|
``` |
|
|
|
|
|
|
|
|
```js |
|
|
// "myCircuit.cir" is the output of the jaz compiler |
|
|
// "myCircuit.cir" is the output of the jaz compiler |
|
|
|
|
|
|
|
|
const circuitDef = JSON.parse(fs.readFileSync("myCircuit.cir", "utf8")); |
|
|
const circuitDef = JSON.parse(fs.readFileSync("myCircuit.cir", "utf8")); |
|
@ -31,7 +31,7 @@ const circuit = new zkSnark.Circuit(circuitDef); |
|
|
|
|
|
|
|
|
### Inspect the circuit. |
|
|
### Inspect the circuit. |
|
|
|
|
|
|
|
|
``` |
|
|
|
|
|
|
|
|
```js |
|
|
// `signalId` can always be a number or an alias string |
|
|
// `signalId` can always be a number or an alias string |
|
|
|
|
|
|
|
|
circuit.nConstraints; // number of constraints |
|
|
circuit.nConstraints; // number of constraints |
|
@ -77,7 +77,7 @@ const circuit = new zkSnark.Circuit(circuitDef); |
|
|
|
|
|
|
|
|
### Trusted setup. |
|
|
### Trusted setup. |
|
|
|
|
|
|
|
|
``` |
|
|
|
|
|
|
|
|
```js |
|
|
const setup = zkSnark.setup(circuit); |
|
|
const setup = zkSnark.setup(circuit); |
|
|
fs.writeFileSink("myCircuit.vk_proof", JSON.stringify(setup.vk_proof), "utf8"); |
|
|
fs.writeFileSink("myCircuit.vk_proof", JSON.stringify(setup.vk_proof), "utf8"); |
|
|
fs.writeFileSink("myCircuit.vk_verifier", JSON.stringify(setup.vk_verifier), "utf8"); |
|
|
fs.writeFileSink("myCircuit.vk_verifier", JSON.stringify(setup.vk_verifier), "utf8"); |
|
@ -86,7 +86,7 @@ setup.toxic // Must be discarded. |
|
|
|
|
|
|
|
|
### Generate proof. |
|
|
### Generate proof. |
|
|
|
|
|
|
|
|
``` |
|
|
|
|
|
|
|
|
```js |
|
|
const circuitDef = JSON.parse(fs.readFileSync("myCircuit.cir", "utf8")); |
|
|
const circuitDef = JSON.parse(fs.readFileSync("myCircuit.cir", "utf8")); |
|
|
const circuit = new zkSnark.Circuit(circuitDef); |
|
|
const circuit = new zkSnark.Circuit(circuitDef); |
|
|
const input = { |
|
|
const input = { |
|
@ -101,7 +101,7 @@ const {proof, publicSignals} = zkSnark.genProof(vk_proof, witness); |
|
|
|
|
|
|
|
|
### Verifier. |
|
|
### Verifier. |
|
|
|
|
|
|
|
|
``` |
|
|
|
|
|
|
|
|
```js |
|
|
const vk_verifier = JSON.parse(fs.readFileSync("myCircuit.vk_verifier", "utf8")); |
|
|
const vk_verifier = JSON.parse(fs.readFileSync("myCircuit.vk_verifier", "utf8")); |
|
|
|
|
|
|
|
|
if (zkSnark.isValid(vk_verifier, proof, publicSignals)) { |
|
|
if (zkSnark.isValid(vk_verifier, proof, publicSignals)) { |
|
|