zkjson 0.1.15 → 0.1.17
Sign up to get free protection for your applications and to get access to all the features.
- package/contracts/ZKQuery.sol +8 -0
- package/doc.js +13 -3
- package/encoder.js +5 -1
- package/package.json +1 -1
package/contracts/ZKQuery.sol
CHANGED
@@ -203,6 +203,13 @@ contract ZKQuery {
|
|
203
203
|
return true;
|
204
204
|
}
|
205
205
|
|
206
|
+
function _qCond (uint[] memory value, uint[] memory cond) internal pure returns (bool) {
|
207
|
+
uint[] memory _cond = toArr(cond);
|
208
|
+
require(value.length == _cond.length, "wrong query");
|
209
|
+
for(uint i = 0; i < value.length; i++) require(_cond[i] == value[i], "wrong query");
|
210
|
+
return true;
|
211
|
+
}
|
212
|
+
|
206
213
|
function getInt (uint[] memory path, uint[] memory raw) internal pure returns (int) {
|
207
214
|
uint[] memory value = getVal(path, raw);
|
208
215
|
return _qInt(value);
|
@@ -222,6 +229,7 @@ contract ZKQuery {
|
|
222
229
|
uint[] memory value = getVal(path, raw);
|
223
230
|
_qNull(value);
|
224
231
|
}
|
232
|
+
|
225
233
|
function verify(uint[] memory zkp, bytes4 selector, address addr) internal view returns (bool) {
|
226
234
|
uint size;
|
227
235
|
assembly {
|
package/doc.js
CHANGED
@@ -1,6 +1,14 @@
|
|
1
1
|
const snarkjs = require("snarkjs")
|
2
2
|
const { resolve } = require("path")
|
3
|
-
const {
|
3
|
+
const { isNil } = require("ramda")
|
4
|
+
const {
|
5
|
+
encodeQuery,
|
6
|
+
pad,
|
7
|
+
toSignal,
|
8
|
+
encode,
|
9
|
+
encodePath,
|
10
|
+
encodeVal,
|
11
|
+
} = require("./encoder")
|
4
12
|
|
5
13
|
module.exports = class Doc {
|
6
14
|
constructor({ size_val = 5, size_path = 5, size_json = 256, wasm, zkey }) {
|
@@ -10,11 +18,13 @@ module.exports = class Doc {
|
|
10
18
|
this.wasm = wasm
|
11
19
|
this.zkey = zkey
|
12
20
|
}
|
13
|
-
async getInputs({ json, path }) {
|
21
|
+
async getInputs({ query, json, path }) {
|
14
22
|
return {
|
15
23
|
json: pad(toSignal(encode(json)), this.size_json),
|
16
24
|
path: pad(toSignal(encodePath(path)), this.size_path),
|
17
|
-
val:
|
25
|
+
val: isNil(query)
|
26
|
+
? pad(toSignal(encodeVal(this.getVal(json, path))), this.size_val)
|
27
|
+
: pad(toSignal(encodeQuery(query)), this.size_val),
|
18
28
|
}
|
19
29
|
}
|
20
30
|
_getVal(j, p) {
|
package/encoder.js
CHANGED
@@ -8,6 +8,10 @@ const ops = {
|
|
8
8
|
$lte: 15,
|
9
9
|
$in: 16,
|
10
10
|
$nin: 17,
|
11
|
+
$contains: 18,
|
12
|
+
$contains_any: 19,
|
13
|
+
$contains_all: 20,
|
14
|
+
$contains_none: 21,
|
11
15
|
}
|
12
16
|
const opMap = {}
|
13
17
|
for (let k in ops) opMap[ops[k]] = k
|
@@ -473,7 +477,7 @@ function encodeQuery(v) {
|
|
473
477
|
if (!Array.isArray(v)) throw Error("query must be an array")
|
474
478
|
const op = v[0]
|
475
479
|
if (isNil(ops[op])) throw Error(`query not supported: ${op}`)
|
476
|
-
return [ops[op], ...encodeVal(v
|
480
|
+
return [ops[op], ...encodeVal(v[1])]
|
477
481
|
}
|
478
482
|
|
479
483
|
function decodeQuery(v) {
|