Skip to content

improve example html. Add protocol field to proof output #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -47,7 +47,7 @@ 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.
The result is a JSON object with pi_a, pi_b, pi_c points and protocol groth field.

You can use the stringified version of this JSON as a proof.json in [snarkjs](https://github.com/iden3/snarkjs)

@@ -62,20 +62,24 @@ Here is a simple example of a web page that loads a key and a witness and genera
<script>

var witness;
var proving_key;
var provingKey;

function onLoad() {

document.getElementById("calcProof").disabled = true;
fetch("proving_key.bin").then( (response) => {
return response.arrayBuffer();
}).then( (b) => {
provingKey = b;
});

fetch("witness.bin").then( (response) => {
return response.arrayBuffer();
}).then( (b) => {
witness = b;
console.log("proving key loaded");
}).then( () =>{
fetch("witness.bin").then( (response) => {
return response.arrayBuffer();
}).then( (b) => {
witness = b;
}).then ( () => {
console.log("witness loaded");
document.getElementById("calcProof").disabled = false;
});
});
}

@@ -96,7 +100,7 @@ function calcProof() {
<body onLoad="onLoad()">
<h1>iden3</h1>
<h2>Zero knowledge proof generator</h2>
<button onClick="calcProof()">Test</button>
<button id="calcProof" onClick="calcProof()">Test</button>
<div id="time"></div>
<pre id="proof"></pre>

9 changes: 6 additions & 3 deletions build/websnark.js
Original file line number Diff line number Diff line change
@@ -1572,6 +1572,10 @@ function thread(self) {
while (i32[0] & 3) i32[0]++; // Return always aligned pointers
const res = i32[0];
i32[0] += length;
while (i32[0] > memory.buffer.byteLength) {
memory.grow(100);
}
i32 = new Uint32Array(memory.buffer);
return res;
}

@@ -2099,6 +2103,7 @@ class Groth16 {
pi_a: this.bin2g1(this.getBin(pi_a, 96)),
pi_b: this.bin2g2(this.getBin(pi_b, 192)),
pi_c: this.bin2g1(this.getBin(pi_c, 96)),
protocol: 'groth',
};

}
@@ -3378,7 +3383,6 @@ function fromByteArray (uint8) {
}

},{}],10:[function(require,module,exports){
(function (Buffer){
/*!
* The buffer module from node.js, for the browser.
*
@@ -5157,8 +5161,7 @@ function numberIsNaN (obj) {
return obj !== obj // eslint-disable-line no-self-compare
}

}).call(this,require("buffer").Buffer)
},{"base64-js":9,"buffer":10,"ieee754":11}],11:[function(require,module,exports){
},{"base64-js":9,"ieee754":11}],11:[function(require,module,exports){
exports.read = function (buffer, offset, isLE, mLen, nBytes) {
var e, m
var eLen = (nBytes * 8) - mLen - 1
20 changes: 12 additions & 8 deletions example/index.html
Original file line number Diff line number Diff line change
@@ -8,17 +8,21 @@
var provingKey;

function onLoad() {

document.getElementById("calcProof").disabled = true;
fetch("proving_key.bin").then( (response) => {
return response.arrayBuffer();
}).then( (b) => {
provingKey = b;
});

fetch("witness.bin").then( (response) => {
return response.arrayBuffer();
}).then( (b) => {
witness = b;
console.log("proving key loaded");
}).then( () =>{
fetch("witness.bin").then( (response) => {
return response.arrayBuffer();
}).then( (b) => {
witness = b;
}).then ( () => {
console.log("witness loaded");
document.getElementById("calcProof").disabled = false;
});
});
}

@@ -75,7 +79,7 @@
<body onLoad="onLoad()">
<h1>iden3</h1>
<h2>Zero knowledge proof generator</h2>
<button onClick="calcProof()">Test</button>
<button id="calcProof" onClick="calcProof()">Test</button>
<div id="time"></div>
<pre id="proof"></pre>

9 changes: 6 additions & 3 deletions example/websnark.js
Original file line number Diff line number Diff line change
@@ -1572,6 +1572,10 @@ function thread(self) {
while (i32[0] & 3) i32[0]++; // Return always aligned pointers
const res = i32[0];
i32[0] += length;
while (i32[0] > memory.buffer.byteLength) {
memory.grow(100);
}
i32 = new Uint32Array(memory.buffer);
return res;
}

@@ -2099,6 +2103,7 @@ class Groth16 {
pi_a: this.bin2g1(this.getBin(pi_a, 96)),
pi_b: this.bin2g2(this.getBin(pi_b, 192)),
pi_c: this.bin2g1(this.getBin(pi_c, 96)),
protocol: 'groth',
};

}
@@ -3378,7 +3383,6 @@ function fromByteArray (uint8) {
}

},{}],10:[function(require,module,exports){
(function (Buffer){
/*!
* The buffer module from node.js, for the browser.
*
@@ -5157,8 +5161,7 @@ function numberIsNaN (obj) {
return obj !== obj // eslint-disable-line no-self-compare
}

}).call(this,require("buffer").Buffer)
},{"base64-js":9,"buffer":10,"ieee754":11}],11:[function(require,module,exports){
},{"base64-js":9,"ieee754":11}],11:[function(require,module,exports){
exports.read = function (buffer, offset, isLE, mLen, nBytes) {
var e, m
var eLen = (nBytes * 8) - mLen - 1
1 change: 1 addition & 0 deletions src/groth16.js
Original file line number Diff line number Diff line change
@@ -599,6 +599,7 @@ class Groth16 {
pi_a: this.bin2g1(this.getBin(pi_a, 96)),
pi_b: this.bin2g2(this.getBin(pi_b, 192)),
pi_c: this.bin2g1(this.getBin(pi_c, 96)),
protocol: 'groth',
};

}