zkjson 0.1.7 → 0.1.9
Sign up to get free protection for your applications and to get access to all the features.
- package/contracts/ZKQuery.sol +1 -1
- package/doc.js +41 -3
- package/package.json +1 -1
package/contracts/ZKQuery.sol
CHANGED
@@ -271,7 +271,7 @@ contract ZKQuery {
|
|
271
271
|
}
|
272
272
|
|
273
273
|
function _qFloat (uint[] memory value) internal pure returns (uint[3] memory) {
|
274
|
-
require(value[0] == 2 && value[2]
|
274
|
+
require(value[0] == 2 && value[2] != 0, "not float");
|
275
275
|
uint[3] memory float;
|
276
276
|
float[0] = value[1];
|
277
277
|
float[1] = value[2];
|
package/doc.js
CHANGED
@@ -1,16 +1,54 @@
|
|
1
|
+
const snarkjs = require("snarkjs")
|
2
|
+
const { resolve } = require("path")
|
1
3
|
const { pad, toSignal, encode, encodePath, encodeVal } = require("./encoder")
|
2
4
|
|
3
5
|
module.exports = class Doc {
|
4
|
-
constructor({ size_val = 5, size_path = 5, size_json = 256 }) {
|
6
|
+
constructor({ size_val = 5, size_path = 5, size_json = 256, wasm, zkey }) {
|
5
7
|
this.size_val = size_val
|
6
8
|
this.size_path = size_path
|
7
9
|
this.size_json = size_json
|
10
|
+
this.wasm = wasm
|
11
|
+
this.zkey = zkey
|
8
12
|
}
|
9
|
-
async getInputs({ json, path
|
13
|
+
async getInputs({ json, path }) {
|
10
14
|
return {
|
11
15
|
json: pad(toSignal(encode(json)), this.size_json),
|
12
16
|
path: pad(toSignal(encodePath(path)), this.size_path),
|
13
|
-
val: pad(toSignal(encodeVal(
|
17
|
+
val: pad(toSignal(encodeVal(this.getVal(json, path))), this.size_val),
|
14
18
|
}
|
15
19
|
}
|
20
|
+
_getVal(j, p) {
|
21
|
+
if (p.length === 0) {
|
22
|
+
return j
|
23
|
+
} else {
|
24
|
+
const sp = p[0].split("[")
|
25
|
+
for (let v of sp) {
|
26
|
+
if (/]$/.test(v)) {
|
27
|
+
j = j[v.replace(/]$/, "") * 1]
|
28
|
+
} else {
|
29
|
+
j = j[v]
|
30
|
+
}
|
31
|
+
}
|
32
|
+
return this._getVal(j, p.slice(1))
|
33
|
+
}
|
34
|
+
}
|
35
|
+
getVal(j, p) {
|
36
|
+
if (p === "") return j
|
37
|
+
return this._getVal(j, p.split("."))
|
38
|
+
}
|
39
|
+
async genProof(json, path) {
|
40
|
+
const inputs = await this.getInputs(json, path)
|
41
|
+
const { proof, publicSignals } = await snarkjs.groth16.fullProve(
|
42
|
+
inputs,
|
43
|
+
this.wasm,
|
44
|
+
this.zkey
|
45
|
+
)
|
46
|
+
return [
|
47
|
+
...proof.pi_a.slice(0, 2),
|
48
|
+
...proof.pi_b[0].slice(0, 2).reverse(),
|
49
|
+
...proof.pi_b[1].slice(0, 2).reverse(),
|
50
|
+
...proof.pi_c.slice(0, 2),
|
51
|
+
...publicSignals,
|
52
|
+
]
|
53
|
+
}
|
16
54
|
}
|