zkjson 0.6.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +537 -0
- package/assets/collection.png +0 -0
- package/assets/db.png +0 -0
- package/assets/encode.png +0 -0
- package/assets/query.png +0 -0
- package/assets/rollup.png +0 -0
- package/assets/structure.png +0 -0
- package/assets/weavedb.png +0 -0
- package/assets/zkjson.png +0 -0
- package/benchmark/components/ui/avatar.jsx +49 -0
- package/benchmark/components/ui/checkbox.jsx +17 -0
- package/benchmark/components/ui/close-button.jsx +20 -0
- package/benchmark/components/ui/color-mode.jsx +89 -0
- package/benchmark/components/ui/dialog.jsx +54 -0
- package/benchmark/components/ui/drawer.jsx +44 -0
- package/benchmark/components/ui/field.jsx +22 -0
- package/benchmark/components/ui/input-group.jsx +39 -0
- package/benchmark/components/ui/popover.jsx +49 -0
- package/benchmark/components/ui/provider.jsx +12 -0
- package/benchmark/components/ui/radio.jsx +17 -0
- package/benchmark/components/ui/slider.jsx +107 -0
- package/benchmark/components/ui/tooltip.jsx +35 -0
- package/benchmark/jsconfig.json +7 -0
- package/benchmark/lib/cbor.js +387 -0
- package/benchmark/lib/msgpack.js +651 -0
- package/benchmark/next.config.mjs +6 -0
- package/benchmark/package.json +22 -0
- package/benchmark/pages/_app.js +9 -0
- package/benchmark/pages/_document.js +13 -0
- package/benchmark/pages/api/hello.js +5 -0
- package/benchmark/pages/index.js +438 -0
- package/benchmark/public/favicon.ico +0 -0
- package/benchmark/public/file.svg +1 -0
- package/benchmark/public/globe.svg +1 -0
- package/benchmark/public/next.svg +1 -0
- package/benchmark/public/vercel.svg +1 -0
- package/benchmark/public/window.svg +1 -0
- package/benchmark/yarn.lock +2448 -0
- package/circom/collection/collection.circom +32 -0
- package/circom/collection/compile.sh +10 -0
- package/circom/collection/gen.js +34 -0
- package/circom/collection/generateInput.js +10 -0
- package/circom/collection/index.circom +4 -0
- package/circom/collection/test.js +21 -0
- package/circom/collection/verifier.sol +247 -0
- package/circom/db/compile.sh +10 -0
- package/circom/db/db.circom +39 -0
- package/circom/db/gen.js +30 -0
- package/circom/db/generateInput.js +10 -0
- package/circom/db/index.circom +4 -0
- package/circom/db/test.js +21 -0
- package/circom/db/verifier.sol +261 -0
- package/circom/ipfs/calculate_total.circom +17 -0
- package/circom/ipfs/compile.sh +10 -0
- package/circom/ipfs/gen.js +18 -0
- package/circom/ipfs/generateInput.js +10 -0
- package/circom/ipfs/index.circom +4 -0
- package/circom/ipfs/ipfs.circom +62 -0
- package/circom/ipfs/parse.circom +289 -0
- package/circom/ipfs/sha256.circom +99 -0
- package/circom/ipfs/test.js +167 -0
- package/circom/ipfs/verifier.sol +261 -0
- package/circom/json/compile.sh +10 -0
- package/circom/json/gen.js +22 -0
- package/circom/json/gen2.js +21 -0
- package/circom/json/generateInput.js +20 -0
- package/circom/json/index.circom +4 -0
- package/circom/json/json.circom +81 -0
- package/circom/json/test.js +100 -0
- package/circom/json/verifier.sol +247 -0
- package/circom/query/compile.sh +10 -0
- package/circom/query/gen.js +28 -0
- package/circom/query/generateInput.js +11 -0
- package/circom/query/index.circom +4 -0
- package/circom/query/query.circom +58 -0
- package/circom/query/test.js +20 -0
- package/circom/query/verifier.sol +177 -0
- package/circom/rollup/compile.sh +10 -0
- package/circom/rollup/gen.js +36 -0
- package/circom/rollup/generateInput.js +11 -0
- package/circom/rollup/index.circom +4 -0
- package/circom/rollup/rollup.circom +43 -0
- package/circom/rollup/test.js +35 -0
- package/circom/rollup/verifier.sol +240 -0
- package/circom/scripts/ceremony.js +39 -0
- package/circom/scripts/ceremony.sh +6 -0
- package/circom/scripts/compile.js +113 -0
- package/circom/scripts/compile.sh +16 -0
- package/circom/utils/uint.circom +512 -0
- package/circom/utils/utils.circom +628 -0
- package/demos/arweave/jsconfig.json +7 -0
- package/demos/arweave/lib/ZKArweave.json +617 -0
- package/demos/arweave/lib/encoder.js +375 -0
- package/demos/arweave/next.config.js +6 -0
- package/demos/arweave/package.json +26 -0
- package/demos/arweave/pages/_app.js +9 -0
- package/demos/arweave/pages/_document.js +19 -0
- package/demos/arweave/pages/api/arweave.js +31 -0
- package/demos/arweave/pages/api/hello.js +5 -0
- package/demos/arweave/pages/index.js +869 -0
- package/demos/arweave/public/circuit.wasm +0 -0
- package/demos/arweave/public/circuit_final.zkey +0 -0
- package/demos/arweave/public/verification_key.json +149 -0
- package/demos/arweave/vercel.json +7 -0
- package/demos/arweave/yarn.lock +2510 -0
- package/demos/simple/jsconfig.json +7 -0
- package/demos/simple/lib/encoder.js +375 -0
- package/demos/simple/next.config.js +6 -0
- package/demos/simple/package.json +24 -0
- package/demos/simple/pages/_app.js +9 -0
- package/demos/simple/pages/_document.js +13 -0
- package/demos/simple/pages/api/hello.js +5 -0
- package/demos/simple/pages/index.js +342 -0
- package/demos/simple/public/circuit.wasm +0 -0
- package/demos/simple/public/circuit_final.zkey +0 -0
- package/demos/simple/public/verification_key.json +149 -0
- package/demos/simple/yarn.lock +2519 -0
- package/docs/README.md +17 -0
- package/docs/simple-zkjson.md +210 -0
- package/docs/solidity-contracts.md +216 -0
- package/docs/zk-circuits.md +125 -0
- package/docs/zkdb-rollup.md +218 -0
- package/docs/zkjson-sdk.md +254 -0
- package/docs/zkjson-v1_5.md +365 -0
- package/package.json +16 -7
- package/{contracts → sdk/contracts}/NORollup.sol +0 -2
- package/sdk/package.json +15 -0
- package/sdk/yarn.lock +881 -0
- package/solidity/README.md +13 -0
- package/solidity/arguments.js +4 -0
- package/solidity/contracts/NORollup.sol +13 -0
- package/solidity/contracts/OPRollup.sol +14 -0
- package/solidity/contracts/ZKIPFS.sol +95 -0
- package/solidity/contracts/ZKJson.sol +21 -0
- package/solidity/contracts/ZKQuery.sol +286 -0
- package/solidity/contracts/ZKRollup.sol +35 -0
- package/solidity/contracts/apps/NORU.sol +66 -0
- package/solidity/contracts/apps/SimpleJSON.sol +64 -0
- package/solidity/contracts/apps/SimpleOPRU.sol +67 -0
- package/solidity/contracts/apps/SimpleRU.sol +67 -0
- package/solidity/contracts/apps/Token.sol +12 -0
- package/solidity/contracts/apps/ZKArweave.sol +89 -0
- package/solidity/contracts/apps/ZKBridge.sol +74 -0
- package/solidity/contracts/apps/ZKNFT.sol +63 -0
- package/solidity/contracts/verifiers/verifier_db.sol +275 -0
- package/solidity/contracts/verifiers/verifier_ipfs.sol +464 -0
- package/solidity/contracts/verifiers/verifier_json.sol +261 -0
- package/solidity/contracts/verifiers/verifier_rollup.sol +240 -0
- package/solidity/package.json +27 -0
- package/solidity/scripts/deploy.js +33 -0
- package/solidity/test/NORU.js +66 -0
- package/solidity/test/ZKArweave.js +97 -0
- package/solidity/test/arweave.js +55 -0
- package/solidity/test/bridge.js +71 -0
- package/solidity/test/simple.js +76 -0
- package/solidity/test/simpleOPRU.js +98 -0
- package/solidity/test/simpleRU.js +94 -0
- package/solidity/test/zknft.js +98 -0
- package/solidity/yarn.lock +4152 -0
- package/test/test.js +304 -0
- /package/{circomlibjs.js → sdk/circomlibjs.js} +0 -0
- /package/{collection.js → sdk/collection.js} +0 -0
- /package/{contracts → sdk/contracts}/OPRollup.sol +0 -0
- /package/{contracts → sdk/contracts}/ZKIPFS.sol +0 -0
- /package/{contracts → sdk/contracts}/ZKJson.sol +0 -0
- /package/{contracts → sdk/contracts}/ZKQuery.sol +0 -0
- /package/{contracts → sdk/contracts}/ZKRollup.sol +0 -0
- /package/{contracts → sdk/contracts}/apps/SimpleJSON.sol +0 -0
- /package/{contracts → sdk/contracts}/apps/SimpleOPRU.sol +0 -0
- /package/{contracts → sdk/contracts}/apps/SimpleRU.sol +0 -0
- /package/{contracts → sdk/contracts}/apps/Token.sol +0 -0
- /package/{contracts → sdk/contracts}/apps/ZKArweave.sol +0 -0
- /package/{contracts → sdk/contracts}/apps/ZKBridge.sol +0 -0
- /package/{contracts → sdk/contracts}/apps/ZKNFT.sol +0 -0
- /package/{contracts → sdk/contracts}/verifiers/verifier_db.sol +0 -0
- /package/{contracts → sdk/contracts}/verifiers/verifier_ipfs.sol +0 -0
- /package/{contracts → sdk/contracts}/verifiers/verifier_json.sol +0 -0
- /package/{contracts → sdk/contracts}/verifiers/verifier_rollup.sol +0 -0
- /package/{db.js → sdk/db.js} +0 -0
- /package/{doc.js → sdk/doc.js} +0 -0
- /package/{encoder-v1_5.js → sdk/encoder-v1_5.js} +0 -0
- /package/{encoder.js → sdk/encoder.js} +0 -0
- /package/{index.js → sdk/index.js} +0 -0
- /package/{json.js → sdk/json.js} +0 -0
- /package/{nft.js → sdk/nft.js} +0 -0
- /package/{parse.js → sdk/parse.js} +0 -0
- /package/{uint.js → sdk/uint.js} +0 -0
@@ -0,0 +1,375 @@
|
|
1
|
+
const base64Map = {
|
2
|
+
A: "00",
|
3
|
+
B: "01",
|
4
|
+
C: "02",
|
5
|
+
D: "03",
|
6
|
+
E: "04",
|
7
|
+
F: "05",
|
8
|
+
G: "06",
|
9
|
+
H: "07",
|
10
|
+
I: "08",
|
11
|
+
J: "09",
|
12
|
+
K: "10",
|
13
|
+
L: "11",
|
14
|
+
M: "12",
|
15
|
+
N: "13",
|
16
|
+
O: "14",
|
17
|
+
P: "15",
|
18
|
+
Q: "16",
|
19
|
+
R: "17",
|
20
|
+
S: "18",
|
21
|
+
T: "19",
|
22
|
+
U: "20",
|
23
|
+
V: "21",
|
24
|
+
W: "22",
|
25
|
+
X: "23",
|
26
|
+
Y: "24",
|
27
|
+
Z: "25",
|
28
|
+
a: "26",
|
29
|
+
b: "27",
|
30
|
+
c: "28",
|
31
|
+
d: "29",
|
32
|
+
e: "30",
|
33
|
+
f: "31",
|
34
|
+
g: "32",
|
35
|
+
h: "33",
|
36
|
+
i: "34",
|
37
|
+
j: "35",
|
38
|
+
k: "36",
|
39
|
+
l: "37",
|
40
|
+
m: "38",
|
41
|
+
n: "39",
|
42
|
+
o: "40",
|
43
|
+
p: "41",
|
44
|
+
q: "42",
|
45
|
+
r: "43",
|
46
|
+
s: "44",
|
47
|
+
t: "45",
|
48
|
+
u: "46",
|
49
|
+
v: "47",
|
50
|
+
w: "48",
|
51
|
+
x: "49",
|
52
|
+
y: "50",
|
53
|
+
z: "51",
|
54
|
+
0: "52",
|
55
|
+
1: "53",
|
56
|
+
2: "54",
|
57
|
+
3: "55",
|
58
|
+
4: "56",
|
59
|
+
5: "57",
|
60
|
+
6: "58",
|
61
|
+
7: "59",
|
62
|
+
8: "60",
|
63
|
+
9: "61",
|
64
|
+
"-": "62",
|
65
|
+
_: "63",
|
66
|
+
}
|
67
|
+
|
68
|
+
function pad(arr, max = 0) {
|
69
|
+
arr = arr.map(n => n.toString())
|
70
|
+
for (let i = arr.length; i < max; i++) {
|
71
|
+
arr.push("0")
|
72
|
+
}
|
73
|
+
return arr
|
74
|
+
}
|
75
|
+
|
76
|
+
function encodePath(path) {
|
77
|
+
const parts = []
|
78
|
+
let str = ""
|
79
|
+
let num = 0
|
80
|
+
for (const s of path) {
|
81
|
+
if (num === 2 && !(s === "." || s === "[")) throw Error()
|
82
|
+
if (s === ".") {
|
83
|
+
if (num === 2) {
|
84
|
+
num = 0
|
85
|
+
} else {
|
86
|
+
parts.push(str)
|
87
|
+
str = ""
|
88
|
+
}
|
89
|
+
} else if (s === "[") {
|
90
|
+
if (num !== 2) {
|
91
|
+
if (str !== "" || parts.length > 0) parts.push(str)
|
92
|
+
str = ""
|
93
|
+
}
|
94
|
+
num = 1
|
95
|
+
} else if (s === "]") {
|
96
|
+
if (num !== 1) throw Error()
|
97
|
+
num = 2
|
98
|
+
if (str === "" || Number.isNaN(+str)) throw Error()
|
99
|
+
parts.push(+str)
|
100
|
+
str = ""
|
101
|
+
} else {
|
102
|
+
str += s
|
103
|
+
}
|
104
|
+
}
|
105
|
+
if (str !== "") parts.push(str)
|
106
|
+
if (parts.length === 0) parts.push("")
|
107
|
+
let encoded = [parts.length]
|
108
|
+
for (const p of parts) {
|
109
|
+
if (typeof p === "number") {
|
110
|
+
encoded = encoded.concat([0, 0, p])
|
111
|
+
} else {
|
112
|
+
let plen = [p.length]
|
113
|
+
if (p.length === 0) plen.push(1)
|
114
|
+
encoded = encoded.concat([
|
115
|
+
...plen,
|
116
|
+
...p.split("").map(c => c.charCodeAt(0)),
|
117
|
+
])
|
118
|
+
}
|
119
|
+
}
|
120
|
+
return encoded
|
121
|
+
}
|
122
|
+
|
123
|
+
function decodePath(path) {
|
124
|
+
let str = ""
|
125
|
+
let p = []
|
126
|
+
let len = path.shift()
|
127
|
+
while (path.length > 0) {
|
128
|
+
const type = path.shift()
|
129
|
+
let val = null
|
130
|
+
if (type === 0) {
|
131
|
+
const type2 = path.shift()
|
132
|
+
if (type2 === 0) {
|
133
|
+
val = [type2, path.shift()]
|
134
|
+
} else {
|
135
|
+
val = [type2]
|
136
|
+
}
|
137
|
+
} else {
|
138
|
+
val = []
|
139
|
+
for (let i = 0; i < type; i++) {
|
140
|
+
val.push(path.shift())
|
141
|
+
}
|
142
|
+
}
|
143
|
+
p.push([type, ...val])
|
144
|
+
}
|
145
|
+
let i = 0
|
146
|
+
for (let s of p) {
|
147
|
+
if (s[0] === 0 && s[1] === 0) {
|
148
|
+
str += `[${s[2]}]`
|
149
|
+
} else if (s[0] === 0 && s[1] === 1) {
|
150
|
+
if (str !== "") str += "."
|
151
|
+
} else {
|
152
|
+
str += `${i === 0 ? "" : "."}${s
|
153
|
+
.slice(1)
|
154
|
+
.map(c => String.fromCharCode(c))
|
155
|
+
.join("")}`
|
156
|
+
}
|
157
|
+
i++
|
158
|
+
}
|
159
|
+
return str
|
160
|
+
}
|
161
|
+
|
162
|
+
function flattenPath(path) {
|
163
|
+
let p = [path.length]
|
164
|
+
for (const v of path) {
|
165
|
+
p = p.concat(v)
|
166
|
+
}
|
167
|
+
return p
|
168
|
+
}
|
169
|
+
|
170
|
+
function _encode(v, path = []) {
|
171
|
+
let vals = []
|
172
|
+
if (typeof v === "number") {
|
173
|
+
vals.push([path, encodeVal(v)])
|
174
|
+
} else if (typeof v === "boolean") {
|
175
|
+
vals.push([path, encodeVal(v)])
|
176
|
+
} else if (v === null) {
|
177
|
+
vals.push([path, encodeVal(v)])
|
178
|
+
} else if (typeof v === "string") {
|
179
|
+
vals.push([path, encodeVal(v)])
|
180
|
+
} else if (Array.isArray(v)) {
|
181
|
+
let i = 0
|
182
|
+
for (const v2 of v) {
|
183
|
+
for (const v3 of _encode(v2, [...path, [0, 0, i]])) vals.push(v3)
|
184
|
+
i++
|
185
|
+
}
|
186
|
+
} else if (typeof v === "object") {
|
187
|
+
for (const k in v) {
|
188
|
+
const key = k.split("").map(c => c.charCodeAt(0))
|
189
|
+
for (let v4 of _encode(v[k], [
|
190
|
+
...path,
|
191
|
+
[key.length, ...(key.length === 0 ? [1] : key)],
|
192
|
+
])) {
|
193
|
+
vals.push(v4)
|
194
|
+
}
|
195
|
+
}
|
196
|
+
}
|
197
|
+
return vals
|
198
|
+
}
|
199
|
+
|
200
|
+
function encode(json) {
|
201
|
+
let flattened = _encode(json)
|
202
|
+
flattened.sort((a, b) => {
|
203
|
+
const isUndefined = v => typeof v === "undefined"
|
204
|
+
const max = Math.max(a[0].length, b[0].length)
|
205
|
+
if (max > 0) {
|
206
|
+
for (let i = 0; i < max; i++) {
|
207
|
+
const exA = !isUndefined(a[0][i])
|
208
|
+
const exB = !isUndefined(b[0][i])
|
209
|
+
if (exA && !exB) return 1
|
210
|
+
if (!exA && exB) return -1
|
211
|
+
const max2 = Math.max(a[0][i].length, b[0][i].length)
|
212
|
+
if (max2 > 0) {
|
213
|
+
for (let i2 = 0; i2 < max2; i2++) {
|
214
|
+
const vA = a[0][i][i2]
|
215
|
+
const vB = b[0][i][i2]
|
216
|
+
const exA = !isUndefined(vA)
|
217
|
+
const exB = !isUndefined(vB)
|
218
|
+
if (exA && !exB) return 1
|
219
|
+
if (!exA && exB) return -1
|
220
|
+
if (vA > vB) return 1
|
221
|
+
if (vA < vB) return -1
|
222
|
+
}
|
223
|
+
}
|
224
|
+
}
|
225
|
+
}
|
226
|
+
return 0
|
227
|
+
})
|
228
|
+
return flattened.reduce(
|
229
|
+
(arr, v) => arr.concat([...flattenPath(v[0]), ...v[1]]),
|
230
|
+
[]
|
231
|
+
)
|
232
|
+
}
|
233
|
+
|
234
|
+
function _decode(arr, obj) {
|
235
|
+
let vals = []
|
236
|
+
while (arr.length > 0) {
|
237
|
+
let plen = arr.shift()
|
238
|
+
let keys = []
|
239
|
+
let val = null
|
240
|
+
while (plen > 0) {
|
241
|
+
const plen2 = arr.shift()
|
242
|
+
if (plen2 === 0) {
|
243
|
+
const plen3 = arr.shift()
|
244
|
+
if (plen3 === 1) {
|
245
|
+
keys.push([plen2, plen3])
|
246
|
+
} else {
|
247
|
+
keys.push([plen2, plen3, arr.shift()])
|
248
|
+
}
|
249
|
+
} else if (plen2 !== 0) {
|
250
|
+
const plen3 = plen2
|
251
|
+
const key = []
|
252
|
+
for (let i2 = 0; i2 < plen3; i2++) key.push(arr.shift())
|
253
|
+
keys.push([plen2, ...key])
|
254
|
+
}
|
255
|
+
plen--
|
256
|
+
}
|
257
|
+
const type = arr.shift()
|
258
|
+
val = [type]
|
259
|
+
if (type === 2) {
|
260
|
+
val.push(arr.shift())
|
261
|
+
val.push(arr.shift())
|
262
|
+
} else if (type === 1) {
|
263
|
+
val.push(arr.shift())
|
264
|
+
} else if (type === 3) {
|
265
|
+
const strlen = arr.shift()
|
266
|
+
val.push(strlen)
|
267
|
+
for (let i2 = 0; i2 < strlen; i2++) val.push(arr.shift())
|
268
|
+
}
|
269
|
+
vals.push([keys, val])
|
270
|
+
}
|
271
|
+
return vals
|
272
|
+
}
|
273
|
+
|
274
|
+
function encodeVal(v) {
|
275
|
+
let vals = []
|
276
|
+
if (typeof v === "number") {
|
277
|
+
vals = v < 0 ? [2, 0, -v] : [2, 1, v]
|
278
|
+
} else if (typeof v === "boolean") {
|
279
|
+
vals = [1, v ? 1 : 0]
|
280
|
+
} else if (v === null) {
|
281
|
+
vals = [0]
|
282
|
+
} else if (typeof v === "string") {
|
283
|
+
vals = [3, v.length, ...v.split("").map(c => c.charCodeAt(0))]
|
284
|
+
}
|
285
|
+
return vals
|
286
|
+
}
|
287
|
+
|
288
|
+
function decodeVal(arr) {
|
289
|
+
const type = arr[0]
|
290
|
+
const _val = arr[1]
|
291
|
+
let val = null
|
292
|
+
if (type === 0) {
|
293
|
+
val = null
|
294
|
+
} else if (type === 1) {
|
295
|
+
val = arr[1] ? true : false
|
296
|
+
} else if (type === 2) {
|
297
|
+
val = (arr[1] === 0 ? -1 : 1) * arr[2]
|
298
|
+
} else if (type === 3) {
|
299
|
+
val = arr
|
300
|
+
.slice(2)
|
301
|
+
.map(c => String.fromCharCode(c))
|
302
|
+
.join("")
|
303
|
+
}
|
304
|
+
return val
|
305
|
+
}
|
306
|
+
|
307
|
+
function decode(arr) {
|
308
|
+
const decoded = _decode(arr)
|
309
|
+
let json =
|
310
|
+
decoded[0]?.[0]?.[0]?.[0] === 0 && decoded[0]?.[0]?.[0]?.[1] === 0 ? [] : {}
|
311
|
+
for (const v of decoded) {
|
312
|
+
const keys = v[0].map(v2 => {
|
313
|
+
if (v2[0] === 0) {
|
314
|
+
if (v2[1] === 1) return ""
|
315
|
+
return v2[2]
|
316
|
+
} else {
|
317
|
+
return v2
|
318
|
+
.slice(1)
|
319
|
+
.map(c => String.fromCharCode(c))
|
320
|
+
.join("")
|
321
|
+
}
|
322
|
+
})
|
323
|
+
if (keys.length === 0) {
|
324
|
+
json = decodeVal(v[1])
|
325
|
+
} else {
|
326
|
+
let obj = json
|
327
|
+
let i = 0
|
328
|
+
for (const k of keys) {
|
329
|
+
if (typeof k === "number") {
|
330
|
+
if (typeof keys[i + 1] === "undefined") {
|
331
|
+
obj[k] = decodeVal(v[1])
|
332
|
+
} else {
|
333
|
+
if (typeof obj[k] === "undefined") {
|
334
|
+
if (typeof keys[i + 1] === "string") {
|
335
|
+
obj[k] = {}
|
336
|
+
} else {
|
337
|
+
obj[k] = []
|
338
|
+
}
|
339
|
+
}
|
340
|
+
}
|
341
|
+
} else {
|
342
|
+
if (typeof obj[k] === "undefined") {
|
343
|
+
if (typeof keys[i + 1] === "undefined") {
|
344
|
+
obj[k] = decodeVal(v[1])
|
345
|
+
} else if (typeof keys[i + 1] === "string") {
|
346
|
+
obj[k] = {}
|
347
|
+
} else {
|
348
|
+
obj[k] = []
|
349
|
+
}
|
350
|
+
}
|
351
|
+
}
|
352
|
+
obj = obj[k]
|
353
|
+
i++
|
354
|
+
}
|
355
|
+
}
|
356
|
+
}
|
357
|
+
return json
|
358
|
+
}
|
359
|
+
|
360
|
+
const str2id = str => {
|
361
|
+
return str.map(s => base64Map(s)).join("")
|
362
|
+
}
|
363
|
+
|
364
|
+
module.exports = {
|
365
|
+
encode,
|
366
|
+
decode,
|
367
|
+
encodePath,
|
368
|
+
decodePath,
|
369
|
+
encodeVal,
|
370
|
+
decodeVal,
|
371
|
+
pad,
|
372
|
+
_encode,
|
373
|
+
flattenPath,
|
374
|
+
str2id,
|
375
|
+
}
|
@@ -0,0 +1,26 @@
|
|
1
|
+
{
|
2
|
+
"name": "demo",
|
3
|
+
"version": "0.1.0",
|
4
|
+
"private": true,
|
5
|
+
"scripts": {
|
6
|
+
"dev": "next dev",
|
7
|
+
"build": "next build",
|
8
|
+
"start": "next start",
|
9
|
+
"lint": "next lint"
|
10
|
+
},
|
11
|
+
"dependencies": {
|
12
|
+
"@chakra-ui/next-js": "^2.2.0",
|
13
|
+
"@chakra-ui/react": "^2.8.2",
|
14
|
+
"@emotion/react": "^11.11.3",
|
15
|
+
"@emotion/styled": "^11.11.0",
|
16
|
+
"ethers": "5",
|
17
|
+
"framer-motion": "^10.17.4",
|
18
|
+
"next": "14.0.4",
|
19
|
+
"ramda": "^0.29.1",
|
20
|
+
"react": "18.2.0",
|
21
|
+
"react-copy-to-clipboard": "^5.1.0",
|
22
|
+
"react-dom": "18.2.0",
|
23
|
+
"snarkjs": "^0.7.2",
|
24
|
+
"zkjson": "^0.1.6"
|
25
|
+
}
|
26
|
+
}
|
@@ -0,0 +1,19 @@
|
|
1
|
+
import { Html, Head, Main, NextScript } from "next/document"
|
2
|
+
|
3
|
+
export default function Document() {
|
4
|
+
return (
|
5
|
+
<Html lang="en">
|
6
|
+
<Head>
|
7
|
+
<link
|
8
|
+
key="fontawesome"
|
9
|
+
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.14.0/css/all.min.css"
|
10
|
+
rel="stylesheet"
|
11
|
+
/>
|
12
|
+
</Head>
|
13
|
+
<body>
|
14
|
+
<Main />
|
15
|
+
<NextScript />
|
16
|
+
</body>
|
17
|
+
</Html>
|
18
|
+
)
|
19
|
+
}
|
@@ -0,0 +1,31 @@
|
|
1
|
+
const { toSignal, pad, encode } = require("zkjson")
|
2
|
+
const { newMemEmptyTrie, buildPoseidon } = require("zkjson/circomlibjs")
|
3
|
+
const { splitEvery } = require("ramda")
|
4
|
+
const { Contract, Wallet, providers, utils } = require("ethers")
|
5
|
+
const abi = require("../../lib/ZKArweave.json").abi
|
6
|
+
const contractAddr = process.env.NEXT_PUBLIC_CONTRACT_ADDR
|
7
|
+
|
8
|
+
export default async function handler(req, res) {
|
9
|
+
const provider = new providers.JsonRpcProvider(process.env.EVM_RPC)
|
10
|
+
const zkar = await new Contract(contractAddr, abi, provider)
|
11
|
+
const txid = req.body.txid
|
12
|
+
const _json = await fetch(`https://arweave.net/${txid}`).then(v => v.json())
|
13
|
+
const _value = pad(toSignal(encode(_json)), 256)
|
14
|
+
const tree = await newMemEmptyTrie()
|
15
|
+
const poseidon = await buildPoseidon()
|
16
|
+
let _hash_value = _value
|
17
|
+
if (_value.length === 256) {
|
18
|
+
_hash_value = []
|
19
|
+
for (let v of splitEvery(16, _value)) {
|
20
|
+
const poseidon = await buildPoseidon()
|
21
|
+
const value = poseidon(v)
|
22
|
+
_hash_value.push(value)
|
23
|
+
}
|
24
|
+
}
|
25
|
+
const value = poseidon(_hash_value)
|
26
|
+
const _hash = tree.F.toObject(value).toString()
|
27
|
+
const hash = await zkar.getMessageHash(txid, _hash)
|
28
|
+
const pkp = Wallet.createRandom()
|
29
|
+
const signature = await pkp.signMessage(utils.arrayify(hash))
|
30
|
+
res.json({ hash: _hash, signature })
|
31
|
+
}
|