@0xbow/privacy-pools-core-sdk 0.1.5
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 +73 -0
- package/dist/esm/ccip-nJye9Itm.js +166 -0
- package/dist/esm/ccip-nJye9Itm.js.map +1 -0
- package/dist/esm/index-DAWUECi8.js +84043 -0
- package/dist/esm/index-DAWUECi8.js.map +1 -0
- package/dist/esm/index.mjs +4 -0
- package/dist/esm/index.mjs.map +1 -0
- package/dist/index.d.mts +666 -0
- package/dist/node/artifacts/commitment.vkey +114 -0
- package/dist/node/artifacts/commitment.wasm +0 -0
- package/dist/node/artifacts/commitment.zkey +0 -0
- package/dist/node/artifacts/merkleTree.vkey +269 -0
- package/dist/node/artifacts/merkleTree.wasm +0 -0
- package/dist/node/artifacts/merkleTree.zkey +0 -0
- package/dist/node/artifacts/withdraw.vkey +129 -0
- package/dist/node/artifacts/withdraw.wasm +0 -0
- package/dist/node/artifacts/withdraw.zkey +0 -0
- package/dist/node/ccip-lPhPeJab.js +183 -0
- package/dist/node/ccip-lPhPeJab.js.map +1 -0
- package/dist/node/index-BiU5Ef8Z.js +90625 -0
- package/dist/node/index-BiU5Ef8Z.js.map +1 -0
- package/dist/node/index.mjs +21 -0
- package/dist/node/index.mjs.map +1 -0
- package/dist/types/abi/ERC20.d.ts +38 -0
- package/dist/types/abi/IEntrypoint.d.ts +794 -0
- package/dist/types/abi/IPrivacyPool.d.ts +51 -0
- package/dist/types/ccip-BZzz1Y5w.js +182 -0
- package/dist/types/circuits/circuits.impl.d.ts +108 -0
- package/dist/types/circuits/circuits.interface.d.ts +127 -0
- package/dist/types/circuits/index.d.ts +2 -0
- package/dist/types/constants.d.ts +2 -0
- package/dist/types/core/bruteForce.service.d.ts +61 -0
- package/dist/types/core/commitment.service.d.ts +30 -0
- package/dist/types/core/contracts.service.d.ts +106 -0
- package/dist/types/core/sdk.d.ts +44 -0
- package/dist/types/core/withdrawal.service.d.ts +32 -0
- package/dist/types/crypto.d.ts +45 -0
- package/dist/types/dirname.helper.d.ts +2 -0
- package/dist/types/errors/base.error.d.ts +52 -0
- package/dist/types/exceptions/circuitInitialization.exception.d.ts +3 -0
- package/dist/types/exceptions/fetchArtifacts.exception.d.ts +3 -0
- package/dist/types/exceptions/index.d.ts +4 -0
- package/dist/types/exceptions/invalidRpcUrl.exception.d.ts +3 -0
- package/dist/types/exceptions/privacyPool.exception.d.ts +13 -0
- package/dist/types/external.d.ts +7 -0
- package/dist/types/filename.helper.d.ts +2 -0
- package/dist/types/index-D-_1h8-n.js +90638 -0
- package/dist/types/index.d.ts +10 -0
- package/dist/types/index.js +20 -0
- package/dist/types/interfaces/blockchainProvider.interface.d.ts +12 -0
- package/dist/types/interfaces/circuits.interface.d.ts +30 -0
- package/dist/types/interfaces/contracts.interface.d.ts +28 -0
- package/dist/types/interfaces/index.d.ts +1 -0
- package/dist/types/internal.d.ts +6 -0
- package/dist/types/providers/blockchainProvider.d.ts +8 -0
- package/dist/types/providers/index.d.ts +1 -0
- package/dist/types/types/commitment.d.ts +48 -0
- package/dist/types/types/index.d.ts +2 -0
- package/dist/types/types/withdrawal.d.ts +30 -0
- package/package.json +81 -0
- package/src/abi/ERC20.ts +222 -0
- package/src/abi/IEntrypoint.ts +627 -0
- package/src/abi/IPrivacyPool.ts +386 -0
- package/src/circuits/circuits.impl.ts +213 -0
- package/src/circuits/circuits.interface.ts +162 -0
- package/src/circuits/index.ts +2 -0
- package/src/constants.ts +3 -0
- package/src/core/bruteForce.service.ts +120 -0
- package/src/core/commitment.service.ts +84 -0
- package/src/core/contracts.service.ts +407 -0
- package/src/core/sdk.ts +91 -0
- package/src/core/withdrawal.service.ts +110 -0
- package/src/crypto.ts +156 -0
- package/src/dirname.helper.ts +4 -0
- package/src/errors/base.error.ts +120 -0
- package/src/exceptions/circuitInitialization.exception.ts +6 -0
- package/src/exceptions/fetchArtifacts.exception.ts +7 -0
- package/src/exceptions/index.ts +4 -0
- package/src/exceptions/invalidRpcUrl.exception.ts +6 -0
- package/src/exceptions/privacyPool.exception.ts +19 -0
- package/src/external.ts +13 -0
- package/src/filename.helper.ts +4 -0
- package/src/index.ts +18 -0
- package/src/interfaces/blockchainProvider.interface.ts +13 -0
- package/src/interfaces/circuits.interface.ts +34 -0
- package/src/interfaces/contracts.interface.ts +58 -0
- package/src/interfaces/index.ts +1 -0
- package/src/internal.ts +6 -0
- package/src/providers/blockchainProvider.ts +26 -0
- package/src/providers/index.ts +1 -0
- package/src/types/commitment.ts +50 -0
- package/src/types/index.ts +2 -0
- package/src/types/withdrawal.ts +33 -0
|
@@ -0,0 +1,386 @@
|
|
|
1
|
+
export const IPrivacyPoolABI = [
|
|
2
|
+
{
|
|
3
|
+
type: "function",
|
|
4
|
+
name: "ASSET",
|
|
5
|
+
inputs: [],
|
|
6
|
+
outputs: [{ name: "", type: "address", internalType: "address" }],
|
|
7
|
+
stateMutability: "view",
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
type: "function",
|
|
11
|
+
name: "ENTRYPOINT",
|
|
12
|
+
inputs: [],
|
|
13
|
+
outputs: [
|
|
14
|
+
{
|
|
15
|
+
name: "",
|
|
16
|
+
type: "address",
|
|
17
|
+
internalType: "contract IEntrypoint",
|
|
18
|
+
},
|
|
19
|
+
],
|
|
20
|
+
stateMutability: "view",
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
type: "function",
|
|
24
|
+
name: "MAX_TREE_DEPTH",
|
|
25
|
+
inputs: [],
|
|
26
|
+
outputs: [{ name: "", type: "uint32", internalType: "uint32" }],
|
|
27
|
+
stateMutability: "view",
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
type: "function",
|
|
31
|
+
name: "RAGEQUIT_VERIFIER",
|
|
32
|
+
inputs: [],
|
|
33
|
+
outputs: [
|
|
34
|
+
{ name: "", type: "address", internalType: "contract IVerifier" },
|
|
35
|
+
],
|
|
36
|
+
stateMutability: "view",
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
type: "function",
|
|
40
|
+
name: "ROOT_HISTORY_SIZE",
|
|
41
|
+
inputs: [],
|
|
42
|
+
outputs: [{ name: "", type: "uint32", internalType: "uint32" }],
|
|
43
|
+
stateMutability: "view",
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
type: "function",
|
|
47
|
+
name: "SCOPE",
|
|
48
|
+
inputs: [],
|
|
49
|
+
outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
|
|
50
|
+
stateMutability: "view",
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
type: "function",
|
|
54
|
+
name: "WITHDRAWAL_VERIFIER",
|
|
55
|
+
inputs: [],
|
|
56
|
+
outputs: [
|
|
57
|
+
{ name: "", type: "address", internalType: "contract IVerifier" },
|
|
58
|
+
],
|
|
59
|
+
stateMutability: "view",
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
type: "function",
|
|
63
|
+
name: "currentRoot",
|
|
64
|
+
inputs: [],
|
|
65
|
+
outputs: [{ name: "_root", type: "uint256", internalType: "uint256" }],
|
|
66
|
+
stateMutability: "view",
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
type: "function",
|
|
70
|
+
name: "currentRootIndex",
|
|
71
|
+
inputs: [],
|
|
72
|
+
outputs: [{ name: "", type: "uint32", internalType: "uint32" }],
|
|
73
|
+
stateMutability: "view",
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
type: "function",
|
|
77
|
+
name: "currentTreeDepth",
|
|
78
|
+
inputs: [],
|
|
79
|
+
outputs: [{ name: "_depth", type: "uint256", internalType: "uint256" }],
|
|
80
|
+
stateMutability: "view",
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
type: "function",
|
|
84
|
+
name: "currentTreeSize",
|
|
85
|
+
inputs: [],
|
|
86
|
+
outputs: [{ name: "_size", type: "uint256", internalType: "uint256" }],
|
|
87
|
+
stateMutability: "view",
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
type: "function",
|
|
91
|
+
name: "dead",
|
|
92
|
+
inputs: [],
|
|
93
|
+
outputs: [{ name: "", type: "bool", internalType: "bool" }],
|
|
94
|
+
stateMutability: "view",
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
type: "function",
|
|
98
|
+
name: "deposit",
|
|
99
|
+
inputs: [
|
|
100
|
+
{ name: "_depositor", type: "address", internalType: "address" },
|
|
101
|
+
{ name: "_value", type: "uint256", internalType: "uint256" },
|
|
102
|
+
{
|
|
103
|
+
name: "_precommitmentHash",
|
|
104
|
+
type: "uint256",
|
|
105
|
+
internalType: "uint256",
|
|
106
|
+
},
|
|
107
|
+
],
|
|
108
|
+
outputs: [
|
|
109
|
+
{ name: "_commitment", type: "uint256", internalType: "uint256" },
|
|
110
|
+
],
|
|
111
|
+
stateMutability: "payable",
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
type: "function",
|
|
115
|
+
name: "depositors",
|
|
116
|
+
inputs: [{ name: "_label", type: "uint256", internalType: "uint256" }],
|
|
117
|
+
outputs: [
|
|
118
|
+
{ name: "_depositooor", type: "address", internalType: "address" },
|
|
119
|
+
],
|
|
120
|
+
stateMutability: "view",
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
type: "function",
|
|
124
|
+
name: "nonce",
|
|
125
|
+
inputs: [],
|
|
126
|
+
outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
|
|
127
|
+
stateMutability: "view",
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
type: "function",
|
|
131
|
+
name: "nullifierHashes",
|
|
132
|
+
inputs: [
|
|
133
|
+
{
|
|
134
|
+
name: "_nullifierHash",
|
|
135
|
+
type: "uint256",
|
|
136
|
+
internalType: "uint256",
|
|
137
|
+
},
|
|
138
|
+
],
|
|
139
|
+
outputs: [{ name: "_spent", type: "bool", internalType: "bool" }],
|
|
140
|
+
stateMutability: "view",
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
type: "function",
|
|
144
|
+
name: "ragequit",
|
|
145
|
+
inputs: [
|
|
146
|
+
{
|
|
147
|
+
name: "_proof",
|
|
148
|
+
type: "tuple",
|
|
149
|
+
internalType: "struct ProofLib.RagequitProof",
|
|
150
|
+
components: [
|
|
151
|
+
{
|
|
152
|
+
name: "pA",
|
|
153
|
+
type: "uint256[2]",
|
|
154
|
+
internalType: "uint256[2]",
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
name: "pB",
|
|
158
|
+
type: "uint256[2][2]",
|
|
159
|
+
internalType: "uint256[2][2]",
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
name: "pC",
|
|
163
|
+
type: "uint256[2]",
|
|
164
|
+
internalType: "uint256[2]",
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
name: "pubSignals",
|
|
168
|
+
type: "uint256[5]",
|
|
169
|
+
internalType: "uint256[5]",
|
|
170
|
+
},
|
|
171
|
+
],
|
|
172
|
+
},
|
|
173
|
+
],
|
|
174
|
+
outputs: [],
|
|
175
|
+
stateMutability: "nonpayable",
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
type: "function",
|
|
179
|
+
name: "roots",
|
|
180
|
+
inputs: [{ name: "_index", type: "uint256", internalType: "uint256" }],
|
|
181
|
+
outputs: [{ name: "_root", type: "uint256", internalType: "uint256" }],
|
|
182
|
+
stateMutability: "view",
|
|
183
|
+
},
|
|
184
|
+
{
|
|
185
|
+
type: "function",
|
|
186
|
+
name: "windDown",
|
|
187
|
+
inputs: [],
|
|
188
|
+
outputs: [],
|
|
189
|
+
stateMutability: "nonpayable",
|
|
190
|
+
},
|
|
191
|
+
{
|
|
192
|
+
type: "function",
|
|
193
|
+
name: "withdraw",
|
|
194
|
+
inputs: [
|
|
195
|
+
{
|
|
196
|
+
name: "_withdrawal",
|
|
197
|
+
type: "tuple",
|
|
198
|
+
internalType: "struct IPrivacyPool.Withdrawal",
|
|
199
|
+
components: [
|
|
200
|
+
{
|
|
201
|
+
name: "processooor",
|
|
202
|
+
type: "address",
|
|
203
|
+
internalType: "address",
|
|
204
|
+
},
|
|
205
|
+
{ name: "data", type: "bytes", internalType: "bytes" },
|
|
206
|
+
],
|
|
207
|
+
},
|
|
208
|
+
{
|
|
209
|
+
name: "_proof",
|
|
210
|
+
type: "tuple",
|
|
211
|
+
internalType: "struct ProofLib.WithdrawProof",
|
|
212
|
+
components: [
|
|
213
|
+
{
|
|
214
|
+
name: "pA",
|
|
215
|
+
type: "uint256[2]",
|
|
216
|
+
internalType: "uint256[2]",
|
|
217
|
+
},
|
|
218
|
+
{
|
|
219
|
+
name: "pB",
|
|
220
|
+
type: "uint256[2][2]",
|
|
221
|
+
internalType: "uint256[2][2]",
|
|
222
|
+
},
|
|
223
|
+
{
|
|
224
|
+
name: "pC",
|
|
225
|
+
type: "uint256[2]",
|
|
226
|
+
internalType: "uint256[2]",
|
|
227
|
+
},
|
|
228
|
+
{
|
|
229
|
+
name: "pubSignals",
|
|
230
|
+
type: "uint256[8]",
|
|
231
|
+
internalType: "uint256[8]",
|
|
232
|
+
},
|
|
233
|
+
],
|
|
234
|
+
},
|
|
235
|
+
],
|
|
236
|
+
outputs: [],
|
|
237
|
+
stateMutability: "nonpayable",
|
|
238
|
+
},
|
|
239
|
+
{
|
|
240
|
+
type: "event",
|
|
241
|
+
name: "Deposited",
|
|
242
|
+
inputs: [
|
|
243
|
+
{
|
|
244
|
+
name: "_depositor",
|
|
245
|
+
type: "address",
|
|
246
|
+
indexed: true,
|
|
247
|
+
internalType: "address",
|
|
248
|
+
},
|
|
249
|
+
{
|
|
250
|
+
name: "_commitment",
|
|
251
|
+
type: "uint256",
|
|
252
|
+
indexed: false,
|
|
253
|
+
internalType: "uint256",
|
|
254
|
+
},
|
|
255
|
+
{
|
|
256
|
+
name: "_label",
|
|
257
|
+
type: "uint256",
|
|
258
|
+
indexed: false,
|
|
259
|
+
internalType: "uint256",
|
|
260
|
+
},
|
|
261
|
+
{
|
|
262
|
+
name: "_value",
|
|
263
|
+
type: "uint256",
|
|
264
|
+
indexed: false,
|
|
265
|
+
internalType: "uint256",
|
|
266
|
+
},
|
|
267
|
+
{
|
|
268
|
+
name: "_merkleRoot",
|
|
269
|
+
type: "uint256",
|
|
270
|
+
indexed: false,
|
|
271
|
+
internalType: "uint256",
|
|
272
|
+
},
|
|
273
|
+
],
|
|
274
|
+
anonymous: false,
|
|
275
|
+
},
|
|
276
|
+
{
|
|
277
|
+
type: "event",
|
|
278
|
+
name: "LeafInserted",
|
|
279
|
+
inputs: [
|
|
280
|
+
{
|
|
281
|
+
name: "_index",
|
|
282
|
+
type: "uint256",
|
|
283
|
+
indexed: false,
|
|
284
|
+
internalType: "uint256",
|
|
285
|
+
},
|
|
286
|
+
{
|
|
287
|
+
name: "_leaf",
|
|
288
|
+
type: "uint256",
|
|
289
|
+
indexed: false,
|
|
290
|
+
internalType: "uint256",
|
|
291
|
+
},
|
|
292
|
+
{
|
|
293
|
+
name: "_root",
|
|
294
|
+
type: "uint256",
|
|
295
|
+
indexed: false,
|
|
296
|
+
internalType: "uint256",
|
|
297
|
+
},
|
|
298
|
+
],
|
|
299
|
+
anonymous: false,
|
|
300
|
+
},
|
|
301
|
+
{ type: "event", name: "PoolDied", inputs: [], anonymous: false },
|
|
302
|
+
{
|
|
303
|
+
type: "event",
|
|
304
|
+
name: "Ragequit",
|
|
305
|
+
inputs: [
|
|
306
|
+
{
|
|
307
|
+
name: "_ragequitter",
|
|
308
|
+
type: "address",
|
|
309
|
+
indexed: true,
|
|
310
|
+
internalType: "address",
|
|
311
|
+
},
|
|
312
|
+
{
|
|
313
|
+
name: "_commitment",
|
|
314
|
+
type: "uint256",
|
|
315
|
+
indexed: false,
|
|
316
|
+
internalType: "uint256",
|
|
317
|
+
},
|
|
318
|
+
{
|
|
319
|
+
name: "_label",
|
|
320
|
+
type: "uint256",
|
|
321
|
+
indexed: false,
|
|
322
|
+
internalType: "uint256",
|
|
323
|
+
},
|
|
324
|
+
{
|
|
325
|
+
name: "_value",
|
|
326
|
+
type: "uint256",
|
|
327
|
+
indexed: false,
|
|
328
|
+
internalType: "uint256",
|
|
329
|
+
},
|
|
330
|
+
],
|
|
331
|
+
anonymous: false,
|
|
332
|
+
},
|
|
333
|
+
{
|
|
334
|
+
type: "event",
|
|
335
|
+
name: "Withdrawn",
|
|
336
|
+
inputs: [
|
|
337
|
+
{
|
|
338
|
+
name: "_processooor",
|
|
339
|
+
type: "address",
|
|
340
|
+
indexed: true,
|
|
341
|
+
internalType: "address",
|
|
342
|
+
},
|
|
343
|
+
{
|
|
344
|
+
name: "_value",
|
|
345
|
+
type: "uint256",
|
|
346
|
+
indexed: false,
|
|
347
|
+
internalType: "uint256",
|
|
348
|
+
},
|
|
349
|
+
{
|
|
350
|
+
name: "_spentNullifier",
|
|
351
|
+
type: "uint256",
|
|
352
|
+
indexed: false,
|
|
353
|
+
internalType: "uint256",
|
|
354
|
+
},
|
|
355
|
+
{
|
|
356
|
+
name: "_newCommitment",
|
|
357
|
+
type: "uint256",
|
|
358
|
+
indexed: false,
|
|
359
|
+
internalType: "uint256",
|
|
360
|
+
},
|
|
361
|
+
],
|
|
362
|
+
anonymous: false,
|
|
363
|
+
},
|
|
364
|
+
{ type: "error", name: "ContextMismatch", inputs: [] },
|
|
365
|
+
{ type: "error", name: "IncorrectASPRoot", inputs: [] },
|
|
366
|
+
{ type: "error", name: "InvalidCommitment", inputs: [] },
|
|
367
|
+
{ type: "error", name: "InvalidProcessooor", inputs: [] },
|
|
368
|
+
{ type: "error", name: "InvalidProof", inputs: [] },
|
|
369
|
+
{ type: "error", name: "InvalidTreeDepth", inputs: [] },
|
|
370
|
+
{ type: "error", name: "LeafAlreadyExists", inputs: [] },
|
|
371
|
+
{ type: "error", name: "LeafCannotBeZero", inputs: [] },
|
|
372
|
+
{
|
|
373
|
+
type: "error",
|
|
374
|
+
name: "LeafGreaterThanSnarkScalarField",
|
|
375
|
+
inputs: [],
|
|
376
|
+
},
|
|
377
|
+
{ type: "error", name: "MaxTreeDepthReached", inputs: [] },
|
|
378
|
+
{ type: "error", name: "NotYetRagequitteable", inputs: [] },
|
|
379
|
+
{ type: "error", name: "NullifierAlreadySpent", inputs: [] },
|
|
380
|
+
{ type: "error", name: "OnlyEntrypoint", inputs: [] },
|
|
381
|
+
{ type: "error", name: "OnlyOriginalDepositor", inputs: [] },
|
|
382
|
+
{ type: "error", name: "PoolIsDead", inputs: [] },
|
|
383
|
+
{ type: "error", name: "ScopeMismatch", inputs: [] },
|
|
384
|
+
{ type: "error", name: "UnknownStateRoot", inputs: [] },
|
|
385
|
+
{ type: "error", name: "ZeroAddress", inputs: [] },
|
|
386
|
+
];
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import { CircuitInitialization, FetchArtifact } from "../internal.js";
|
|
2
|
+
import {
|
|
3
|
+
Binaries,
|
|
4
|
+
CircuitArtifacts,
|
|
5
|
+
CircuitName,
|
|
6
|
+
CircuitNameString,
|
|
7
|
+
CircuitsInterface,
|
|
8
|
+
circuitToAsset,
|
|
9
|
+
Version,
|
|
10
|
+
VersionString,
|
|
11
|
+
} from "./circuits.interface.js";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Class representing circuit management and artifact handling.
|
|
15
|
+
* Implements the CircuitsInterface.
|
|
16
|
+
*/
|
|
17
|
+
export class Circuits implements CircuitsInterface {
|
|
18
|
+
/**
|
|
19
|
+
* Indicates whether the circuits have been initialized.
|
|
20
|
+
* @type {boolean}
|
|
21
|
+
* @protected
|
|
22
|
+
*/
|
|
23
|
+
protected initialized: boolean = false;
|
|
24
|
+
/**
|
|
25
|
+
* The version of the circuit artifacts being used.
|
|
26
|
+
* @type {VersionString}
|
|
27
|
+
* @protected
|
|
28
|
+
*/
|
|
29
|
+
protected version: VersionString = Version.Latest;
|
|
30
|
+
/**
|
|
31
|
+
* The binaries containing circuit artifacts such as wasm, vkey, and zkey files.
|
|
32
|
+
* @type {Binaries}
|
|
33
|
+
* @protected
|
|
34
|
+
*/
|
|
35
|
+
protected binaries!: Binaries;
|
|
36
|
+
/**
|
|
37
|
+
* The base URL for fetching circuit artifacts.
|
|
38
|
+
* @type {string}
|
|
39
|
+
* @protected
|
|
40
|
+
*/
|
|
41
|
+
protected baseUrl: string = import.meta.url;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Determines whether the environment is a browser.
|
|
45
|
+
* @returns {boolean} True if running in a browser environment, false otherwise.
|
|
46
|
+
* @protected
|
|
47
|
+
*/
|
|
48
|
+
_browser(): boolean {
|
|
49
|
+
return typeof window !== "undefined";
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Initializes the circuit manager with binaries and a version.
|
|
54
|
+
* @param {Binaries} binaries - The binaries containing circuit artifacts.
|
|
55
|
+
* @param {VersionString} version - The version of the circuit artifacts.
|
|
56
|
+
* @protected
|
|
57
|
+
*/
|
|
58
|
+
protected _initialize(binaries: Binaries, version: VersionString) {
|
|
59
|
+
this.binaries = binaries;
|
|
60
|
+
this.version = version;
|
|
61
|
+
this.initialized = true;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Handles initialization of circuit artifacts, fetching them if necessary.
|
|
66
|
+
* @param {VersionString} [version=Version.latest] - The version of the circuit artifacts.
|
|
67
|
+
* @throws {CircuitInitialization} If an error occurs during initialization.
|
|
68
|
+
* @protected
|
|
69
|
+
* @async
|
|
70
|
+
*/
|
|
71
|
+
protected async _handleInitialization(
|
|
72
|
+
version: VersionString = Version.Latest,
|
|
73
|
+
) {
|
|
74
|
+
if (!this.initialized || this.binaries === undefined) {
|
|
75
|
+
try {
|
|
76
|
+
await this.initArtifacts(version);
|
|
77
|
+
} catch (e) {
|
|
78
|
+
if (e instanceof FetchArtifact) {
|
|
79
|
+
throw new CircuitInitialization(`${e.name}: ${e.message}`);
|
|
80
|
+
} else {
|
|
81
|
+
console.error(e);
|
|
82
|
+
throw new CircuitInitialization(`UnknownError: ${e}`);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Fetches a versioned artifact from a given path.
|
|
90
|
+
* @param {string} artifactPath - The path to the artifact.
|
|
91
|
+
* @param {VersionString} version - The version of the artifact.
|
|
92
|
+
* @returns {Promise<Uint8Array>} A promise that resolves to the artifact as a Uint8Array.
|
|
93
|
+
* @throws {FetchArtifact} If the artifact cannot be fetched.
|
|
94
|
+
* @protected
|
|
95
|
+
* @async
|
|
96
|
+
*/
|
|
97
|
+
async _fetchVersionedArtifact(artifactPath: string): Promise<Uint8Array> {
|
|
98
|
+
const artifactUrl = new URL(artifactPath, this.baseUrl);
|
|
99
|
+
if (this._browser()) {
|
|
100
|
+
const res = await fetch(artifactUrl);
|
|
101
|
+
if (res.status !== 200) {
|
|
102
|
+
throw new FetchArtifact(artifactUrl);
|
|
103
|
+
}
|
|
104
|
+
const aBuf = await res.arrayBuffer();
|
|
105
|
+
return new Uint8Array(aBuf);
|
|
106
|
+
} else {
|
|
107
|
+
try {
|
|
108
|
+
const fs = (await import("node:fs/promises")).default;
|
|
109
|
+
const buf = await fs.readFile(artifactUrl);
|
|
110
|
+
return new Uint8Array(buf);
|
|
111
|
+
} catch (error) {
|
|
112
|
+
console.error(error);
|
|
113
|
+
throw new FetchArtifact(artifactUrl);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Downloads and returns the circuit artifacts for a specific circuit.
|
|
120
|
+
* @param {CircuitNameString} circuitName - The name of the circuit.
|
|
121
|
+
* @returns {Promise<CircuitArtifacts>} A promise that resolves to the circuit artifacts.
|
|
122
|
+
* @protected
|
|
123
|
+
* @async
|
|
124
|
+
*/
|
|
125
|
+
async _downloadCircuitArtifacts(
|
|
126
|
+
circuitName: CircuitNameString,
|
|
127
|
+
): Promise<CircuitArtifacts> {
|
|
128
|
+
const assetName = circuitToAsset[circuitName];
|
|
129
|
+
|
|
130
|
+
const [wasm, vkey, zkey] = await Promise.all([
|
|
131
|
+
this._fetchVersionedArtifact(["artifacts", assetName.wasm].join("/")),
|
|
132
|
+
this._fetchVersionedArtifact(["artifacts", assetName.vkey].join("/")),
|
|
133
|
+
this._fetchVersionedArtifact(["artifacts", assetName.zkey].join("/")),
|
|
134
|
+
]);
|
|
135
|
+
return { wasm, vkey, zkey };
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Downloads all circuit artifacts for the specified version.
|
|
140
|
+
* @param {VersionString} version - The version of the artifacts.
|
|
141
|
+
* @returns {Promise<Binaries>} A promise that resolves to the binaries containing all circuit artifacts.
|
|
142
|
+
* @async
|
|
143
|
+
*/
|
|
144
|
+
// prettier-ignore
|
|
145
|
+
async downloadArtifacts(version: VersionString): Promise<Binaries> { // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
146
|
+
const [commitment, merkleTree, withdraw] = await Promise.all([
|
|
147
|
+
this._downloadCircuitArtifacts(CircuitName.Commitment),
|
|
148
|
+
this._downloadCircuitArtifacts(CircuitName.MerkleTree),
|
|
149
|
+
this._downloadCircuitArtifacts(CircuitName.Withdraw),
|
|
150
|
+
]);
|
|
151
|
+
return {
|
|
152
|
+
commitment,
|
|
153
|
+
merkleTree,
|
|
154
|
+
withdraw,
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Initializes the circuit artifacts for the specified version.
|
|
160
|
+
* @param {VersionString} version - The version of the artifacts.
|
|
161
|
+
* @returns {Promise<void>} A promise that resolves when initialization is complete.
|
|
162
|
+
* @async
|
|
163
|
+
*/
|
|
164
|
+
async initArtifacts(version: VersionString): Promise<void> {
|
|
165
|
+
const binaries = await this.downloadArtifacts(version);
|
|
166
|
+
this._initialize(binaries, version);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Retrieves the verification key for a specified circuit.
|
|
171
|
+
* @param {CircuitNameString} circuitName - The name of the circuit.
|
|
172
|
+
* @param {VersionString} [version=Version.latest] - The version of the artifacts.
|
|
173
|
+
* @returns {Promise<Uint8Array>} A promise that resolves to the verification key.
|
|
174
|
+
* @async
|
|
175
|
+
*/
|
|
176
|
+
async getVerificationKey(
|
|
177
|
+
circuitName: CircuitNameString,
|
|
178
|
+
version: VersionString = Version.Latest,
|
|
179
|
+
): Promise<Uint8Array> {
|
|
180
|
+
await this._handleInitialization(version);
|
|
181
|
+
return this.binaries[circuitName]?.vkey;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Retrieves the proving key for a specified circuit.
|
|
186
|
+
* @param {CircuitNameString} circuitName - The name of the circuit.
|
|
187
|
+
* @param {VersionString} [version=Version.latest] - The version of the artifacts.
|
|
188
|
+
* @returns {Promise<Uint8Array>} A promise that resolves to the proving key.
|
|
189
|
+
* @async
|
|
190
|
+
*/
|
|
191
|
+
async getProvingKey(
|
|
192
|
+
circuitName: CircuitNameString,
|
|
193
|
+
version: VersionString = Version.Latest,
|
|
194
|
+
): Promise<Uint8Array> {
|
|
195
|
+
await this._handleInitialization(version);
|
|
196
|
+
return this.binaries[circuitName]?.zkey;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Retrieves the wasm file for a specified circuit.
|
|
201
|
+
* @param {CircuitNameString} circuitName - The name of the circuit.
|
|
202
|
+
* @param {VersionString} [version=Version.latest] - The version of the artifacts.
|
|
203
|
+
* @returns {Promise<Uint8Array>} A promise that resolves to the wasm file.
|
|
204
|
+
* @async
|
|
205
|
+
*/
|
|
206
|
+
async getWasm(
|
|
207
|
+
circuitName: CircuitNameString,
|
|
208
|
+
version: VersionString = Version.Latest,
|
|
209
|
+
): Promise<Uint8Array> {
|
|
210
|
+
await this._handleInitialization(version);
|
|
211
|
+
return this.binaries[circuitName]?.wasm;
|
|
212
|
+
}
|
|
213
|
+
}
|