zerc20-client-sdk 0.1.14 → 0.1.15

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.
@@ -1,49 +1,2273 @@
1
- import { primeBatchTeleportArtifacts, primeSingleTeleportArtifacts } from "../wasm/artifacts.js";
2
- import { WasmRuntime } from "../wasm/index.js";
3
- import { ProofService } from "./proofService.js";
4
- const wasm = new WasmRuntime();
5
- const proofs = new ProofService(wasm);
6
- const ctx = self;
7
- ctx.addEventListener("message", async (event) => {
8
- const message = event.data;
9
- if (!message) {
10
- return;
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropNames = Object.getOwnPropertyNames;
3
+ var __esm = (fn, res) => function __init() {
4
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
5
+ };
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+
11
+ // dist/assets/wasm/web/zerc20_wasm.js
12
+ var zerc20_wasm_exports = {};
13
+ __export(zerc20_wasm_exports, {
14
+ SingleWithdrawWasm: () => SingleWithdrawWasm,
15
+ WithdrawNovaWasm: () => WithdrawNovaWasm,
16
+ aggregation_merkle_proof: () => aggregation_merkle_proof,
17
+ aggregation_root: () => aggregation_root,
18
+ build_full_burn_address: () => build_full_burn_address,
19
+ decode_full_burn_address: () => decode_full_burn_address,
20
+ default: () => zerc20_wasm_default,
21
+ derive_invoice_batch: () => derive_invoice_batch,
22
+ derive_invoice_single: () => derive_invoice_single,
23
+ derive_payment_advice: () => derive_payment_advice,
24
+ fetch_aggregation_tree_state: () => fetch_aggregation_tree_state,
25
+ fetch_local_teleport_merkle_proofs: () => fetch_local_teleport_merkle_proofs,
26
+ fetch_transfer_events: () => fetch_transfer_events,
27
+ general_recipient_fr: () => general_recipient_fr,
28
+ generate_global_teleport_merkle_proofs: () => generate_global_teleport_merkle_proofs,
29
+ initSync: () => initSync,
30
+ seed_message: () => seed_message,
31
+ separate_events_by_eligibility: () => separate_events_by_eligibility
32
+ });
33
+ function getUint8ArrayMemory0() {
34
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
35
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
36
+ }
37
+ return cachedUint8ArrayMemory0;
38
+ }
39
+ function decodeText(ptr, len) {
40
+ numBytesDecoded += len;
41
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
42
+ cachedTextDecoder = new TextDecoder("utf-8", { ignoreBOM: true, fatal: true });
43
+ cachedTextDecoder.decode();
44
+ numBytesDecoded = len;
45
+ }
46
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
47
+ }
48
+ function getStringFromWasm0(ptr, len) {
49
+ ptr = ptr >>> 0;
50
+ return decodeText(ptr, len);
51
+ }
52
+ function passStringToWasm0(arg, malloc, realloc) {
53
+ if (realloc === void 0) {
54
+ const buf = cachedTextEncoder.encode(arg);
55
+ const ptr2 = malloc(buf.length, 1) >>> 0;
56
+ getUint8ArrayMemory0().subarray(ptr2, ptr2 + buf.length).set(buf);
57
+ WASM_VECTOR_LEN = buf.length;
58
+ return ptr2;
59
+ }
60
+ let len = arg.length;
61
+ let ptr = malloc(len, 1) >>> 0;
62
+ const mem = getUint8ArrayMemory0();
63
+ let offset = 0;
64
+ for (; offset < len; offset++) {
65
+ const code = arg.charCodeAt(offset);
66
+ if (code > 127) break;
67
+ mem[ptr + offset] = code;
68
+ }
69
+ if (offset !== len) {
70
+ if (offset !== 0) {
71
+ arg = arg.slice(offset);
72
+ }
73
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
74
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
75
+ const ret = cachedTextEncoder.encodeInto(arg, view);
76
+ offset += ret.written;
77
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
78
+ }
79
+ WASM_VECTOR_LEN = offset;
80
+ return ptr;
81
+ }
82
+ function getDataViewMemory0() {
83
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || cachedDataViewMemory0.buffer.detached === void 0 && cachedDataViewMemory0.buffer !== wasm.memory.buffer) {
84
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
85
+ }
86
+ return cachedDataViewMemory0;
87
+ }
88
+ function addToExternrefTable0(obj) {
89
+ const idx = wasm.__externref_table_alloc();
90
+ wasm.__wbindgen_export_4.set(idx, obj);
91
+ return idx;
92
+ }
93
+ function handleError(f, args) {
94
+ try {
95
+ return f.apply(this, args);
96
+ } catch (e) {
97
+ const idx = addToExternrefTable0(e);
98
+ wasm.__wbindgen_exn_store(idx);
99
+ }
100
+ }
101
+ function getArrayU8FromWasm0(ptr, len) {
102
+ ptr = ptr >>> 0;
103
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
104
+ }
105
+ function isLikeNone(x) {
106
+ return x === void 0 || x === null;
107
+ }
108
+ function debugString(val) {
109
+ const type = typeof val;
110
+ if (type == "number" || type == "boolean" || val == null) {
111
+ return `${val}`;
112
+ }
113
+ if (type == "string") {
114
+ return `"${val}"`;
115
+ }
116
+ if (type == "symbol") {
117
+ const description = val.description;
118
+ if (description == null) {
119
+ return "Symbol";
120
+ } else {
121
+ return `Symbol(${description})`;
122
+ }
123
+ }
124
+ if (type == "function") {
125
+ const name = val.name;
126
+ if (typeof name == "string" && name.length > 0) {
127
+ return `Function(${name})`;
128
+ } else {
129
+ return "Function";
11
130
  }
131
+ }
132
+ if (Array.isArray(val)) {
133
+ const length = val.length;
134
+ let debug = "[";
135
+ if (length > 0) {
136
+ debug += debugString(val[0]);
137
+ }
138
+ for (let i = 1; i < length; i++) {
139
+ debug += ", " + debugString(val[i]);
140
+ }
141
+ debug += "]";
142
+ return debug;
143
+ }
144
+ const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
145
+ let className;
146
+ if (builtInMatches && builtInMatches.length > 1) {
147
+ className = builtInMatches[1];
148
+ } else {
149
+ return toString.call(val);
150
+ }
151
+ if (className == "Object") {
152
+ try {
153
+ return "Object(" + JSON.stringify(val) + ")";
154
+ } catch (_) {
155
+ return "Object";
156
+ }
157
+ }
158
+ if (val instanceof Error) {
159
+ return `${val.name}: ${val.message}
160
+ ${val.stack}`;
161
+ }
162
+ return className;
163
+ }
164
+ function makeMutClosure(arg0, arg1, dtor, f) {
165
+ const state = { a: arg0, b: arg1, cnt: 1, dtor };
166
+ const real = (...args) => {
167
+ state.cnt++;
168
+ const a = state.a;
169
+ state.a = 0;
12
170
  try {
13
- if (message.type === "singleTeleport") {
14
- primeSingleTeleportArtifacts(message.payload.artifacts);
15
- const result = await proofs.createSingleTeleportProof(message.payload.params);
16
- const response = {
17
- id: message.id,
18
- type: "result",
19
- result,
20
- };
21
- ctx.postMessage(response);
22
- return;
171
+ return f(a, state.b, ...args);
172
+ } finally {
173
+ if (--state.cnt === 0) {
174
+ wasm.__wbindgen_export_6.get(state.dtor)(a, state.b);
175
+ CLOSURE_DTORS.unregister(state);
176
+ } else {
177
+ state.a = a;
178
+ }
179
+ }
180
+ };
181
+ real.original = state;
182
+ CLOSURE_DTORS.register(real, state, state);
183
+ return real;
184
+ }
185
+ function takeFromExternrefTable0(idx) {
186
+ const value = wasm.__wbindgen_export_4.get(idx);
187
+ wasm.__externref_table_dealloc(idx);
188
+ return value;
189
+ }
190
+ function aggregation_root(snapshot_hex) {
191
+ let deferred2_0;
192
+ let deferred2_1;
193
+ try {
194
+ const ret = wasm.aggregation_root(snapshot_hex);
195
+ var ptr1 = ret[0];
196
+ var len1 = ret[1];
197
+ if (ret[3]) {
198
+ ptr1 = 0;
199
+ len1 = 0;
200
+ throw takeFromExternrefTable0(ret[2]);
201
+ }
202
+ deferred2_0 = ptr1;
203
+ deferred2_1 = len1;
204
+ return getStringFromWasm0(ptr1, len1);
205
+ } finally {
206
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
207
+ }
208
+ }
209
+ function aggregation_merkle_proof(snapshot_hex, index) {
210
+ const ret = wasm.aggregation_merkle_proof(snapshot_hex, index);
211
+ if (ret[2]) {
212
+ throw takeFromExternrefTable0(ret[1]);
213
+ }
214
+ return takeFromExternrefTable0(ret[0]);
215
+ }
216
+ function derive_invoice_batch(seed_hex, invoice_id_hex, sub_id, recipient_chain_id, recipient_address_hex) {
217
+ const ptr0 = passStringToWasm0(seed_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
218
+ const len0 = WASM_VECTOR_LEN;
219
+ const ptr1 = passStringToWasm0(invoice_id_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
220
+ const len1 = WASM_VECTOR_LEN;
221
+ const ptr2 = passStringToWasm0(recipient_address_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
222
+ const len2 = WASM_VECTOR_LEN;
223
+ const ret = wasm.derive_invoice_batch(ptr0, len0, ptr1, len1, sub_id, recipient_chain_id, ptr2, len2);
224
+ if (ret[2]) {
225
+ throw takeFromExternrefTable0(ret[1]);
226
+ }
227
+ return takeFromExternrefTable0(ret[0]);
228
+ }
229
+ function derive_invoice_single(seed_hex, invoice_id_hex, recipient_chain_id, recipient_address_hex) {
230
+ const ptr0 = passStringToWasm0(seed_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
231
+ const len0 = WASM_VECTOR_LEN;
232
+ const ptr1 = passStringToWasm0(invoice_id_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
233
+ const len1 = WASM_VECTOR_LEN;
234
+ const ptr2 = passStringToWasm0(recipient_address_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
235
+ const len2 = WASM_VECTOR_LEN;
236
+ const ret = wasm.derive_invoice_single(ptr0, len0, ptr1, len1, recipient_chain_id, ptr2, len2);
237
+ if (ret[2]) {
238
+ throw takeFromExternrefTable0(ret[1]);
239
+ }
240
+ return takeFromExternrefTable0(ret[0]);
241
+ }
242
+ function general_recipient_fr(chain_id, recipient_address_hex, tweak_hex) {
243
+ let deferred4_0;
244
+ let deferred4_1;
245
+ try {
246
+ const ptr0 = passStringToWasm0(recipient_address_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
247
+ const len0 = WASM_VECTOR_LEN;
248
+ const ptr1 = passStringToWasm0(tweak_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
249
+ const len1 = WASM_VECTOR_LEN;
250
+ const ret = wasm.general_recipient_fr(chain_id, ptr0, len0, ptr1, len1);
251
+ var ptr3 = ret[0];
252
+ var len3 = ret[1];
253
+ if (ret[3]) {
254
+ ptr3 = 0;
255
+ len3 = 0;
256
+ throw takeFromExternrefTable0(ret[2]);
257
+ }
258
+ deferred4_0 = ptr3;
259
+ deferred4_1 = len3;
260
+ return getStringFromWasm0(ptr3, len3);
261
+ } finally {
262
+ wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
263
+ }
264
+ }
265
+ function seed_message() {
266
+ let deferred1_0;
267
+ let deferred1_1;
268
+ try {
269
+ const ret = wasm.seed_message();
270
+ deferred1_0 = ret[0];
271
+ deferred1_1 = ret[1];
272
+ return getStringFromWasm0(ret[0], ret[1]);
273
+ } finally {
274
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
275
+ }
276
+ }
277
+ function build_full_burn_address(recipient_chain_id, recipient_address_hex, secret_hex, tweak_hex) {
278
+ const ptr0 = passStringToWasm0(recipient_address_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
279
+ const len0 = WASM_VECTOR_LEN;
280
+ const ptr1 = passStringToWasm0(secret_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
281
+ const len1 = WASM_VECTOR_LEN;
282
+ const ptr2 = passStringToWasm0(tweak_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
283
+ const len2 = WASM_VECTOR_LEN;
284
+ const ret = wasm.build_full_burn_address(recipient_chain_id, ptr0, len0, ptr1, len1, ptr2, len2);
285
+ if (ret[2]) {
286
+ throw takeFromExternrefTable0(ret[1]);
287
+ }
288
+ return takeFromExternrefTable0(ret[0]);
289
+ }
290
+ function derive_payment_advice(seed_hex, payment_advice_id_hex, recipient_chain_id, recipient_address_hex) {
291
+ const ptr0 = passStringToWasm0(seed_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
292
+ const len0 = WASM_VECTOR_LEN;
293
+ const ptr1 = passStringToWasm0(payment_advice_id_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
294
+ const len1 = WASM_VECTOR_LEN;
295
+ const ptr2 = passStringToWasm0(recipient_address_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
296
+ const len2 = WASM_VECTOR_LEN;
297
+ const ret = wasm.derive_payment_advice(ptr0, len0, ptr1, len1, recipient_chain_id, ptr2, len2);
298
+ if (ret[2]) {
299
+ throw takeFromExternrefTable0(ret[1]);
300
+ }
301
+ return takeFromExternrefTable0(ret[0]);
302
+ }
303
+ function decode_full_burn_address(full_burn_address_hex) {
304
+ const ptr0 = passStringToWasm0(full_burn_address_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
305
+ const len0 = WASM_VECTOR_LEN;
306
+ const ret = wasm.decode_full_burn_address(ptr0, len0);
307
+ if (ret[2]) {
308
+ throw takeFromExternrefTable0(ret[1]);
309
+ }
310
+ return takeFromExternrefTable0(ret[0]);
311
+ }
312
+ function separate_events_by_eligibility(params) {
313
+ const ret = wasm.separate_events_by_eligibility(params);
314
+ if (ret[2]) {
315
+ throw takeFromExternrefTable0(ret[1]);
316
+ }
317
+ return takeFromExternrefTable0(ret[0]);
318
+ }
319
+ function generate_global_teleport_merkle_proofs(params) {
320
+ const ret = wasm.generate_global_teleport_merkle_proofs(params);
321
+ if (ret[2]) {
322
+ throw takeFromExternrefTable0(ret[1]);
323
+ }
324
+ return takeFromExternrefTable0(ret[0]);
325
+ }
326
+ function fetch_transfer_events(params) {
327
+ const ret = wasm.fetch_transfer_events(params);
328
+ return ret;
329
+ }
330
+ function fetch_local_teleport_merkle_proofs(params) {
331
+ const ret = wasm.fetch_local_teleport_merkle_proofs(params);
332
+ return ret;
333
+ }
334
+ function fetch_aggregation_tree_state(params) {
335
+ const ret = wasm.fetch_aggregation_tree_state(params);
336
+ return ret;
337
+ }
338
+ function passArray8ToWasm0(arg, malloc) {
339
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
340
+ getUint8ArrayMemory0().set(arg, ptr / 1);
341
+ WASM_VECTOR_LEN = arg.length;
342
+ return ptr;
343
+ }
344
+ function __wbg_adapter_6(arg0, arg1, arg2) {
345
+ wasm.closure1250_externref_shim(arg0, arg1, arg2);
346
+ }
347
+ function __wbg_adapter_11(arg0, arg1) {
348
+ wasm.wasm_bindgen__convert__closures_____invoke__h258073e353b316af(arg0, arg1);
349
+ }
350
+ function __wbg_adapter_14(arg0, arg1) {
351
+ wasm.wasm_bindgen__convert__closures_____invoke__ha5dd837bc6b9ee0b(arg0, arg1);
352
+ }
353
+ function __wbg_adapter_151(arg0, arg1, arg2, arg3) {
354
+ wasm.closure1441_externref_shim(arg0, arg1, arg2, arg3);
355
+ }
356
+ async function __wbg_load(module2, imports) {
357
+ if (typeof Response === "function" && module2 instanceof Response) {
358
+ if (typeof WebAssembly.instantiateStreaming === "function") {
359
+ try {
360
+ return await WebAssembly.instantiateStreaming(module2, imports);
361
+ } catch (e) {
362
+ const validResponse = module2.ok && EXPECTED_RESPONSE_TYPES.has(module2.type);
363
+ if (validResponse && module2.headers.get("Content-Type") !== "application/wasm") {
364
+ console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
365
+ } else {
366
+ throw e;
23
367
  }
24
- if (message.type === "nova") {
25
- primeBatchTeleportArtifacts(message.payload.artifacts);
26
- const result = await proofs.runNovaProver(message.payload.params);
27
- const response = {
28
- id: message.id,
29
- type: "result",
30
- result,
31
- };
32
- ctx.postMessage(response);
33
- return;
368
+ }
369
+ }
370
+ const bytes = await module2.arrayBuffer();
371
+ return await WebAssembly.instantiate(bytes, imports);
372
+ } else {
373
+ const instance = await WebAssembly.instantiate(module2, imports);
374
+ if (instance instanceof WebAssembly.Instance) {
375
+ return { instance, module: module2 };
376
+ } else {
377
+ return instance;
378
+ }
379
+ }
380
+ }
381
+ function __wbg_get_imports() {
382
+ const imports = {};
383
+ imports.wbg = {};
384
+ imports.wbg.__wbg_Error_e17e777aac105295 = function(arg0, arg1) {
385
+ const ret = Error(getStringFromWasm0(arg0, arg1));
386
+ return ret;
387
+ };
388
+ imports.wbg.__wbg_Number_998bea33bd87c3e0 = function(arg0) {
389
+ const ret = Number(arg0);
390
+ return ret;
391
+ };
392
+ imports.wbg.__wbg_String_8f0eb39a4a4c2f66 = function(arg0, arg1) {
393
+ const ret = String(arg1);
394
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
395
+ const len1 = WASM_VECTOR_LEN;
396
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
397
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
398
+ };
399
+ imports.wbg.__wbg_abort_67e1b49bf6614565 = function(arg0) {
400
+ arg0.abort();
401
+ };
402
+ imports.wbg.__wbg_abort_d830bf2e9aa6ec5b = function(arg0, arg1) {
403
+ arg0.abort(arg1);
404
+ };
405
+ imports.wbg.__wbg_append_72a3c0addd2bce38 = function() {
406
+ return handleError(function(arg0, arg1, arg2, arg3, arg4) {
407
+ arg0.append(getStringFromWasm0(arg1, arg2), getStringFromWasm0(arg3, arg4));
408
+ }, arguments);
409
+ };
410
+ imports.wbg.__wbg_arrayBuffer_9c99b8e2809e8cbb = function() {
411
+ return handleError(function(arg0) {
412
+ const ret = arg0.arrayBuffer();
413
+ return ret;
414
+ }, arguments);
415
+ };
416
+ imports.wbg.__wbg_call_13410aac570ffff7 = function() {
417
+ return handleError(function(arg0, arg1) {
418
+ const ret = arg0.call(arg1);
419
+ return ret;
420
+ }, arguments);
421
+ };
422
+ imports.wbg.__wbg_call_a5400b25a865cfd8 = function() {
423
+ return handleError(function(arg0, arg1, arg2) {
424
+ const ret = arg0.call(arg1, arg2);
425
+ return ret;
426
+ }, arguments);
427
+ };
428
+ imports.wbg.__wbg_clearTimeout_7a42b49784aea641 = function(arg0) {
429
+ const ret = clearTimeout(arg0);
430
+ return ret;
431
+ };
432
+ imports.wbg.__wbg_crypto_574e78ad8b13b65f = function(arg0) {
433
+ const ret = arg0.crypto;
434
+ return ret;
435
+ };
436
+ imports.wbg.__wbg_done_75ed0ee6dd243d9d = function(arg0) {
437
+ const ret = arg0.done;
438
+ return ret;
439
+ };
440
+ imports.wbg.__wbg_entries_2be2f15bd5554996 = function(arg0) {
441
+ const ret = Object.entries(arg0);
442
+ return ret;
443
+ };
444
+ imports.wbg.__wbg_error_7534b8e9a36f1ab4 = function(arg0, arg1) {
445
+ let deferred0_0;
446
+ let deferred0_1;
447
+ try {
448
+ deferred0_0 = arg0;
449
+ deferred0_1 = arg1;
450
+ console.error(getStringFromWasm0(arg0, arg1));
451
+ } finally {
452
+ wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
453
+ }
454
+ };
455
+ imports.wbg.__wbg_fetch_74a3e84ebd2c9a0e = function(arg0) {
456
+ const ret = fetch(arg0);
457
+ return ret;
458
+ };
459
+ imports.wbg.__wbg_fetch_87aed7f306ec6d63 = function(arg0, arg1) {
460
+ const ret = arg0.fetch(arg1);
461
+ return ret;
462
+ };
463
+ imports.wbg.__wbg_getRandomValues_b8f5dbd5f3995a9e = function() {
464
+ return handleError(function(arg0, arg1) {
465
+ arg0.getRandomValues(arg1);
466
+ }, arguments);
467
+ };
468
+ imports.wbg.__wbg_get_0da715ceaecea5c8 = function(arg0, arg1) {
469
+ const ret = arg0[arg1 >>> 0];
470
+ return ret;
471
+ };
472
+ imports.wbg.__wbg_get_458e874b43b18b25 = function() {
473
+ return handleError(function(arg0, arg1) {
474
+ const ret = Reflect.get(arg0, arg1);
475
+ return ret;
476
+ }, arguments);
477
+ };
478
+ imports.wbg.__wbg_getwithrefkey_1dc361bd10053bfe = function(arg0, arg1) {
479
+ const ret = arg0[arg1];
480
+ return ret;
481
+ };
482
+ imports.wbg.__wbg_has_b89e451f638123e3 = function() {
483
+ return handleError(function(arg0, arg1) {
484
+ const ret = Reflect.has(arg0, arg1);
485
+ return ret;
486
+ }, arguments);
487
+ };
488
+ imports.wbg.__wbg_headers_29fec3c72865cd75 = function(arg0) {
489
+ const ret = arg0.headers;
490
+ return ret;
491
+ };
492
+ imports.wbg.__wbg_instanceof_ArrayBuffer_67f3012529f6a2dd = function(arg0) {
493
+ let result;
494
+ try {
495
+ result = arg0 instanceof ArrayBuffer;
496
+ } catch (_) {
497
+ result = false;
498
+ }
499
+ const ret = result;
500
+ return ret;
501
+ };
502
+ imports.wbg.__wbg_instanceof_Map_ebb01a5b6b5ffd0b = function(arg0) {
503
+ let result;
504
+ try {
505
+ result = arg0 instanceof Map;
506
+ } catch (_) {
507
+ result = false;
508
+ }
509
+ const ret = result;
510
+ return ret;
511
+ };
512
+ imports.wbg.__wbg_instanceof_Response_50fde2cd696850bf = function(arg0) {
513
+ let result;
514
+ try {
515
+ result = arg0 instanceof Response;
516
+ } catch (_) {
517
+ result = false;
518
+ }
519
+ const ret = result;
520
+ return ret;
521
+ };
522
+ imports.wbg.__wbg_instanceof_Uint8Array_9a8378d955933db7 = function(arg0) {
523
+ let result;
524
+ try {
525
+ result = arg0 instanceof Uint8Array;
526
+ } catch (_) {
527
+ result = false;
528
+ }
529
+ const ret = result;
530
+ return ret;
531
+ };
532
+ imports.wbg.__wbg_isArray_030cce220591fb41 = function(arg0) {
533
+ const ret = Array.isArray(arg0);
534
+ return ret;
535
+ };
536
+ imports.wbg.__wbg_isSafeInteger_1c0d1af5542e102a = function(arg0) {
537
+ const ret = Number.isSafeInteger(arg0);
538
+ return ret;
539
+ };
540
+ imports.wbg.__wbg_iterator_f370b34483c71a1c = function() {
541
+ const ret = Symbol.iterator;
542
+ return ret;
543
+ };
544
+ imports.wbg.__wbg_length_186546c51cd61acd = function(arg0) {
545
+ const ret = arg0.length;
546
+ return ret;
547
+ };
548
+ imports.wbg.__wbg_length_6bb7e81f9d7713e4 = function(arg0) {
549
+ const ret = arg0.length;
550
+ return ret;
551
+ };
552
+ imports.wbg.__wbg_log_6c7b5f4f00b8ce3f = function(arg0) {
553
+ console.log(arg0);
554
+ };
555
+ imports.wbg.__wbg_msCrypto_a61aeb35a24c1329 = function(arg0) {
556
+ const ret = arg0.msCrypto;
557
+ return ret;
558
+ };
559
+ imports.wbg.__wbg_new_19c25a3f2fa63a02 = function() {
560
+ const ret = new Object();
561
+ return ret;
562
+ };
563
+ imports.wbg.__wbg_new_1f3a344cf3123716 = function() {
564
+ const ret = new Array();
565
+ return ret;
566
+ };
567
+ imports.wbg.__wbg_new_2e3c58a15f39f5f9 = function(arg0, arg1) {
568
+ try {
569
+ var state0 = { a: arg0, b: arg1 };
570
+ var cb0 = (arg02, arg12) => {
571
+ const a = state0.a;
572
+ state0.a = 0;
573
+ try {
574
+ return __wbg_adapter_151(a, state0.b, arg02, arg12);
575
+ } finally {
576
+ state0.a = a;
34
577
  }
35
- throw new Error(`Unknown ZKP worker job type ${message.type}`);
36
- }
37
- catch (error) {
38
- const response = {
39
- id: message.id,
40
- type: "error",
41
- error: {
42
- message: error instanceof Error ? error.message : String(error),
43
- stack: error instanceof Error ? error.stack : undefined,
44
- },
578
+ };
579
+ const ret = new Promise(cb0);
580
+ return ret;
581
+ } finally {
582
+ state0.a = state0.b = 0;
583
+ }
584
+ };
585
+ imports.wbg.__wbg_new_638ebfaedbf32a5e = function(arg0) {
586
+ const ret = new Uint8Array(arg0);
587
+ return ret;
588
+ };
589
+ imports.wbg.__wbg_new_66b9434b4e59b63e = function() {
590
+ return handleError(function() {
591
+ const ret = new AbortController();
592
+ return ret;
593
+ }, arguments);
594
+ };
595
+ imports.wbg.__wbg_new_8a6f238a6ece86ea = function() {
596
+ const ret = new Error();
597
+ return ret;
598
+ };
599
+ imports.wbg.__wbg_new_f6e53210afea8e45 = function() {
600
+ return handleError(function() {
601
+ const ret = new Headers();
602
+ return ret;
603
+ }, arguments);
604
+ };
605
+ imports.wbg.__wbg_newfromslice_074c56947bd43469 = function(arg0, arg1) {
606
+ const ret = new Uint8Array(getArrayU8FromWasm0(arg0, arg1));
607
+ return ret;
608
+ };
609
+ imports.wbg.__wbg_newnoargs_254190557c45b4ec = function(arg0, arg1) {
610
+ const ret = new Function(getStringFromWasm0(arg0, arg1));
611
+ return ret;
612
+ };
613
+ imports.wbg.__wbg_newwithlength_a167dcc7aaa3ba77 = function(arg0) {
614
+ const ret = new Uint8Array(arg0 >>> 0);
615
+ return ret;
616
+ };
617
+ imports.wbg.__wbg_newwithstrandinit_b5d168a29a3fd85f = function() {
618
+ return handleError(function(arg0, arg1, arg2) {
619
+ const ret = new Request(getStringFromWasm0(arg0, arg1), arg2);
620
+ return ret;
621
+ }, arguments);
622
+ };
623
+ imports.wbg.__wbg_next_5b3530e612fde77d = function(arg0) {
624
+ const ret = arg0.next;
625
+ return ret;
626
+ };
627
+ imports.wbg.__wbg_next_692e82279131b03c = function() {
628
+ return handleError(function(arg0) {
629
+ const ret = arg0.next();
630
+ return ret;
631
+ }, arguments);
632
+ };
633
+ imports.wbg.__wbg_node_905d3e251edff8a2 = function(arg0) {
634
+ const ret = arg0.node;
635
+ return ret;
636
+ };
637
+ imports.wbg.__wbg_now_0dc4920a47cf7280 = function(arg0) {
638
+ const ret = arg0.now();
639
+ return ret;
640
+ };
641
+ imports.wbg.__wbg_now_2c95c9de01293173 = function(arg0) {
642
+ const ret = arg0.now();
643
+ return ret;
644
+ };
645
+ imports.wbg.__wbg_performance_6adc3b899e448a23 = function(arg0) {
646
+ const ret = arg0.performance;
647
+ return ret;
648
+ };
649
+ imports.wbg.__wbg_performance_7a3ffd0b17f663ad = function(arg0) {
650
+ const ret = arg0.performance;
651
+ return ret;
652
+ };
653
+ imports.wbg.__wbg_process_dc0fbacc7c1c06f7 = function(arg0) {
654
+ const ret = arg0.process;
655
+ return ret;
656
+ };
657
+ imports.wbg.__wbg_prototypesetcall_3d4a26c1ed734349 = function(arg0, arg1, arg2) {
658
+ Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), arg2);
659
+ };
660
+ imports.wbg.__wbg_queueMicrotask_25d0739ac89e8c88 = function(arg0) {
661
+ queueMicrotask(arg0);
662
+ };
663
+ imports.wbg.__wbg_queueMicrotask_4488407636f5bf24 = function(arg0) {
664
+ const ret = arg0.queueMicrotask;
665
+ return ret;
666
+ };
667
+ imports.wbg.__wbg_randomFillSync_ac0988aba3254290 = function() {
668
+ return handleError(function(arg0, arg1) {
669
+ arg0.randomFillSync(arg1);
670
+ }, arguments);
671
+ };
672
+ imports.wbg.__wbg_require_60cc747a6bc5215a = function() {
673
+ return handleError(function() {
674
+ const ret = module.require;
675
+ return ret;
676
+ }, arguments);
677
+ };
678
+ imports.wbg.__wbg_resolve_4055c623acdd6a1b = function(arg0) {
679
+ const ret = Promise.resolve(arg0);
680
+ return ret;
681
+ };
682
+ imports.wbg.__wbg_setTimeout_63008613644b07af = function() {
683
+ return handleError(function(arg0, arg1, arg2) {
684
+ const ret = arg0.setTimeout(arg1, arg2);
685
+ return ret;
686
+ }, arguments);
687
+ };
688
+ imports.wbg.__wbg_setTimeout_7bb3429662ab1e70 = function(arg0, arg1) {
689
+ const ret = setTimeout(arg0, arg1);
690
+ return ret;
691
+ };
692
+ imports.wbg.__wbg_set_3f1d0b984ed272ed = function(arg0, arg1, arg2) {
693
+ arg0[arg1] = arg2;
694
+ };
695
+ imports.wbg.__wbg_set_90f6c0f7bd8c0415 = function(arg0, arg1, arg2) {
696
+ arg0[arg1 >>> 0] = arg2;
697
+ };
698
+ imports.wbg.__wbg_setbody_c8460bdf44147df8 = function(arg0, arg1) {
699
+ arg0.body = arg1;
700
+ };
701
+ imports.wbg.__wbg_setcache_90ca4ad8a8ad40d3 = function(arg0, arg1) {
702
+ arg0.cache = __wbindgen_enum_RequestCache[arg1];
703
+ };
704
+ imports.wbg.__wbg_setcredentials_9cd60d632c9d5dfc = function(arg0, arg1) {
705
+ arg0.credentials = __wbindgen_enum_RequestCredentials[arg1];
706
+ };
707
+ imports.wbg.__wbg_setheaders_0052283e2f3503d1 = function(arg0, arg1) {
708
+ arg0.headers = arg1;
709
+ };
710
+ imports.wbg.__wbg_setmethod_9b504d5b855b329c = function(arg0, arg1, arg2) {
711
+ arg0.method = getStringFromWasm0(arg1, arg2);
712
+ };
713
+ imports.wbg.__wbg_setmode_a23e1a2ad8b512f8 = function(arg0, arg1) {
714
+ arg0.mode = __wbindgen_enum_RequestMode[arg1];
715
+ };
716
+ imports.wbg.__wbg_setsignal_8c45ad1247a74809 = function(arg0, arg1) {
717
+ arg0.signal = arg1;
718
+ };
719
+ imports.wbg.__wbg_signal_da4d466ce86118b5 = function(arg0) {
720
+ const ret = arg0.signal;
721
+ return ret;
722
+ };
723
+ imports.wbg.__wbg_stack_0ed75d68575b0f3c = function(arg0, arg1) {
724
+ const ret = arg1.stack;
725
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
726
+ const len1 = WASM_VECTOR_LEN;
727
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
728
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
729
+ };
730
+ imports.wbg.__wbg_static_accessor_GLOBAL_8921f820c2ce3f12 = function() {
731
+ const ret = typeof global === "undefined" ? null : global;
732
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
733
+ };
734
+ imports.wbg.__wbg_static_accessor_GLOBAL_THIS_f0a4409105898184 = function() {
735
+ const ret = typeof globalThis === "undefined" ? null : globalThis;
736
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
737
+ };
738
+ imports.wbg.__wbg_static_accessor_SELF_995b214ae681ff99 = function() {
739
+ const ret = typeof self === "undefined" ? null : self;
740
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
741
+ };
742
+ imports.wbg.__wbg_static_accessor_WINDOW_cde3890479c675ea = function() {
743
+ const ret = typeof window === "undefined" ? null : window;
744
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
745
+ };
746
+ imports.wbg.__wbg_status_3fea3036088621d6 = function(arg0) {
747
+ const ret = arg0.status;
748
+ return ret;
749
+ };
750
+ imports.wbg.__wbg_stringify_b98c93d0a190446a = function() {
751
+ return handleError(function(arg0) {
752
+ const ret = JSON.stringify(arg0);
753
+ return ret;
754
+ }, arguments);
755
+ };
756
+ imports.wbg.__wbg_subarray_70fd07feefe14294 = function(arg0, arg1, arg2) {
757
+ const ret = arg0.subarray(arg1 >>> 0, arg2 >>> 0);
758
+ return ret;
759
+ };
760
+ imports.wbg.__wbg_then_b33a773d723afa3e = function(arg0, arg1, arg2) {
761
+ const ret = arg0.then(arg1, arg2);
762
+ return ret;
763
+ };
764
+ imports.wbg.__wbg_then_e22500defe16819f = function(arg0, arg1) {
765
+ const ret = arg0.then(arg1);
766
+ return ret;
767
+ };
768
+ imports.wbg.__wbg_url_e5720dfacf77b05e = function(arg0, arg1) {
769
+ const ret = arg1.url;
770
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
771
+ const len1 = WASM_VECTOR_LEN;
772
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
773
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
774
+ };
775
+ imports.wbg.__wbg_value_dd9372230531eade = function(arg0) {
776
+ const ret = arg0.value;
777
+ return ret;
778
+ };
779
+ imports.wbg.__wbg_versions_c01dfd4722a88165 = function(arg0) {
780
+ const ret = arg0.versions;
781
+ return ret;
782
+ };
783
+ imports.wbg.__wbg_wbindgenbigintgetasi64_ac743ece6ab9bba1 = function(arg0, arg1) {
784
+ const v = arg1;
785
+ const ret = typeof v === "bigint" ? v : void 0;
786
+ getDataViewMemory0().setBigInt64(arg0 + 8 * 1, isLikeNone(ret) ? BigInt(0) : ret, true);
787
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
788
+ };
789
+ imports.wbg.__wbg_wbindgenbooleanget_3fe6f642c7d97746 = function(arg0) {
790
+ const v = arg0;
791
+ const ret = typeof v === "boolean" ? v : void 0;
792
+ return isLikeNone(ret) ? 16777215 : ret ? 1 : 0;
793
+ };
794
+ imports.wbg.__wbg_wbindgencbdrop_eb10308566512b88 = function(arg0) {
795
+ const obj = arg0.original;
796
+ if (obj.cnt-- == 1) {
797
+ obj.a = 0;
798
+ return true;
799
+ }
800
+ const ret = false;
801
+ return ret;
802
+ };
803
+ imports.wbg.__wbg_wbindgendebugstring_99ef257a3ddda34d = function(arg0, arg1) {
804
+ const ret = debugString(arg1);
805
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
806
+ const len1 = WASM_VECTOR_LEN;
807
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
808
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
809
+ };
810
+ imports.wbg.__wbg_wbindgenin_d7a1ee10933d2d55 = function(arg0, arg1) {
811
+ const ret = arg0 in arg1;
812
+ return ret;
813
+ };
814
+ imports.wbg.__wbg_wbindgenisbigint_ecb90cc08a5a9154 = function(arg0) {
815
+ const ret = typeof arg0 === "bigint";
816
+ return ret;
817
+ };
818
+ imports.wbg.__wbg_wbindgenisfunction_8cee7dce3725ae74 = function(arg0) {
819
+ const ret = typeof arg0 === "function";
820
+ return ret;
821
+ };
822
+ imports.wbg.__wbg_wbindgenisobject_307a53c6bd97fbf8 = function(arg0) {
823
+ const val = arg0;
824
+ const ret = typeof val === "object" && val !== null;
825
+ return ret;
826
+ };
827
+ imports.wbg.__wbg_wbindgenisstring_d4fa939789f003b0 = function(arg0) {
828
+ const ret = typeof arg0 === "string";
829
+ return ret;
830
+ };
831
+ imports.wbg.__wbg_wbindgenisundefined_c4b71d073b92f3c5 = function(arg0) {
832
+ const ret = arg0 === void 0;
833
+ return ret;
834
+ };
835
+ imports.wbg.__wbg_wbindgenjsvaleq_e6f2ad59ccae1b58 = function(arg0, arg1) {
836
+ const ret = arg0 === arg1;
837
+ return ret;
838
+ };
839
+ imports.wbg.__wbg_wbindgenjsvallooseeq_9bec8c9be826bed1 = function(arg0, arg1) {
840
+ const ret = arg0 == arg1;
841
+ return ret;
842
+ };
843
+ imports.wbg.__wbg_wbindgennumberget_f74b4c7525ac05cb = function(arg0, arg1) {
844
+ const obj = arg1;
845
+ const ret = typeof obj === "number" ? obj : void 0;
846
+ getDataViewMemory0().setFloat64(arg0 + 8 * 1, isLikeNone(ret) ? 0 : ret, true);
847
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
848
+ };
849
+ imports.wbg.__wbg_wbindgenstringget_0f16a6ddddef376f = function(arg0, arg1) {
850
+ const obj = arg1;
851
+ const ret = typeof obj === "string" ? obj : void 0;
852
+ var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
853
+ var len1 = WASM_VECTOR_LEN;
854
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
855
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
856
+ };
857
+ imports.wbg.__wbg_wbindgenthrow_451ec1a8469d7eb6 = function(arg0, arg1) {
858
+ throw new Error(getStringFromWasm0(arg0, arg1));
859
+ };
860
+ imports.wbg.__wbindgen_cast_0b55bcbfa1eb963a = function(arg0, arg1) {
861
+ const ret = makeMutClosure(arg0, arg1, 1208, __wbg_adapter_14);
862
+ return ret;
863
+ };
864
+ imports.wbg.__wbindgen_cast_2241b6af4c4b2941 = function(arg0, arg1) {
865
+ const ret = getStringFromWasm0(arg0, arg1);
866
+ return ret;
867
+ };
868
+ imports.wbg.__wbindgen_cast_3a2781a2dff3ac5f = function(arg0, arg1) {
869
+ const ret = makeMutClosure(arg0, arg1, 1249, __wbg_adapter_6);
870
+ return ret;
871
+ };
872
+ imports.wbg.__wbindgen_cast_4625c577ab2ec9ee = function(arg0) {
873
+ const ret = BigInt.asUintN(64, arg0);
874
+ return ret;
875
+ };
876
+ imports.wbg.__wbindgen_cast_4dfcf3514842f679 = function(arg0, arg1) {
877
+ const ret = makeMutClosure(arg0, arg1, 1205, __wbg_adapter_11);
878
+ return ret;
879
+ };
880
+ imports.wbg.__wbindgen_cast_9ae0607507abb057 = function(arg0) {
881
+ const ret = arg0;
882
+ return ret;
883
+ };
884
+ imports.wbg.__wbindgen_cast_cb9088102bce6b30 = function(arg0, arg1) {
885
+ const ret = getArrayU8FromWasm0(arg0, arg1);
886
+ return ret;
887
+ };
888
+ imports.wbg.__wbindgen_cast_d6cd19b81560fd6e = function(arg0) {
889
+ const ret = arg0;
890
+ return ret;
891
+ };
892
+ imports.wbg.__wbindgen_init_externref_table = function() {
893
+ const table = wasm.__wbindgen_export_4;
894
+ const offset = table.grow(4);
895
+ table.set(0, void 0);
896
+ table.set(offset + 0, void 0);
897
+ table.set(offset + 1, null);
898
+ table.set(offset + 2, true);
899
+ table.set(offset + 3, false);
900
+ ;
901
+ };
902
+ return imports;
903
+ }
904
+ function __wbg_init_memory(imports, memory) {
905
+ }
906
+ function __wbg_finalize_init(instance, module2) {
907
+ wasm = instance.exports;
908
+ __wbg_init.__wbindgen_wasm_module = module2;
909
+ cachedDataViewMemory0 = null;
910
+ cachedUint8ArrayMemory0 = null;
911
+ wasm.__wbindgen_start();
912
+ return wasm;
913
+ }
914
+ function initSync(module2) {
915
+ if (wasm !== void 0) return wasm;
916
+ if (typeof module2 !== "undefined") {
917
+ if (Object.getPrototypeOf(module2) === Object.prototype) {
918
+ ({ module: module2 } = module2);
919
+ } else {
920
+ console.warn("using deprecated parameters for `initSync()`; pass a single object instead");
921
+ }
922
+ }
923
+ const imports = __wbg_get_imports();
924
+ __wbg_init_memory(imports);
925
+ if (!(module2 instanceof WebAssembly.Module)) {
926
+ module2 = new WebAssembly.Module(module2);
927
+ }
928
+ const instance = new WebAssembly.Instance(module2, imports);
929
+ return __wbg_finalize_init(instance, module2);
930
+ }
931
+ async function __wbg_init(module_or_path) {
932
+ if (wasm !== void 0) return wasm;
933
+ if (typeof module_or_path !== "undefined") {
934
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
935
+ ({ module_or_path } = module_or_path);
936
+ } else {
937
+ console.warn("using deprecated parameters for the initialization function; pass a single object instead");
938
+ }
939
+ }
940
+ if (typeof module_or_path === "undefined") {
941
+ module_or_path = new URL("zerc20_wasm_bg.wasm", import.meta.url);
942
+ }
943
+ const imports = __wbg_get_imports();
944
+ if (typeof module_or_path === "string" || typeof Request === "function" && module_or_path instanceof Request || typeof URL === "function" && module_or_path instanceof URL) {
945
+ module_or_path = fetch(module_or_path);
946
+ }
947
+ __wbg_init_memory(imports);
948
+ const { instance, module: module2 } = await __wbg_load(await module_or_path, imports);
949
+ return __wbg_finalize_init(instance, module2);
950
+ }
951
+ var wasm, cachedUint8ArrayMemory0, cachedTextDecoder, MAX_SAFARI_DECODE_BYTES, numBytesDecoded, WASM_VECTOR_LEN, cachedTextEncoder, cachedDataViewMemory0, CLOSURE_DTORS, __wbindgen_enum_RequestCache, __wbindgen_enum_RequestCredentials, __wbindgen_enum_RequestMode, SingleWithdrawWasmFinalization, SingleWithdrawWasm, WithdrawNovaWasmFinalization, WithdrawNovaWasm, EXPECTED_RESPONSE_TYPES, zerc20_wasm_default;
952
+ var init_zerc20_wasm = __esm({
953
+ "dist/assets/wasm/web/zerc20_wasm.js"() {
954
+ "use strict";
955
+ cachedUint8ArrayMemory0 = null;
956
+ cachedTextDecoder = new TextDecoder("utf-8", { ignoreBOM: true, fatal: true });
957
+ cachedTextDecoder.decode();
958
+ MAX_SAFARI_DECODE_BYTES = 2146435072;
959
+ numBytesDecoded = 0;
960
+ WASM_VECTOR_LEN = 0;
961
+ cachedTextEncoder = new TextEncoder();
962
+ if (!("encodeInto" in cachedTextEncoder)) {
963
+ cachedTextEncoder.encodeInto = function(arg, view) {
964
+ const buf = cachedTextEncoder.encode(arg);
965
+ view.set(buf);
966
+ return {
967
+ read: arg.length,
968
+ written: buf.length
45
969
  };
46
- ctx.postMessage(response);
970
+ };
971
+ }
972
+ cachedDataViewMemory0 = null;
973
+ CLOSURE_DTORS = typeof FinalizationRegistry === "undefined" ? { register: () => {
974
+ }, unregister: () => {
975
+ } } : new FinalizationRegistry(
976
+ (state) => {
977
+ wasm.__wbindgen_export_6.get(state.dtor)(state.a, state.b);
978
+ }
979
+ );
980
+ __wbindgen_enum_RequestCache = ["default", "no-store", "reload", "no-cache", "force-cache", "only-if-cached"];
981
+ __wbindgen_enum_RequestCredentials = ["omit", "same-origin", "include"];
982
+ __wbindgen_enum_RequestMode = ["same-origin", "no-cors", "cors", "navigate"];
983
+ SingleWithdrawWasmFinalization = typeof FinalizationRegistry === "undefined" ? { register: () => {
984
+ }, unregister: () => {
985
+ } } : new FinalizationRegistry((ptr) => wasm.__wbg_singlewithdrawwasm_free(ptr >>> 0, 1));
986
+ SingleWithdrawWasm = class {
987
+ __destroy_into_raw() {
988
+ const ptr = this.__wbg_ptr;
989
+ this.__wbg_ptr = 0;
990
+ SingleWithdrawWasmFinalization.unregister(this);
991
+ return ptr;
992
+ }
993
+ free() {
994
+ const ptr = this.__destroy_into_raw();
995
+ wasm.__wbg_singlewithdrawwasm_free(ptr, 0);
996
+ }
997
+ /**
998
+ * @param {Uint8Array} local_pk_bytes
999
+ * @param {Uint8Array} local_vk_bytes
1000
+ * @param {Uint8Array} global_pk_bytes
1001
+ * @param {Uint8Array} global_vk_bytes
1002
+ */
1003
+ constructor(local_pk_bytes, local_vk_bytes, global_pk_bytes, global_vk_bytes) {
1004
+ const ptr0 = passArray8ToWasm0(local_pk_bytes, wasm.__wbindgen_malloc);
1005
+ const len0 = WASM_VECTOR_LEN;
1006
+ const ptr1 = passArray8ToWasm0(local_vk_bytes, wasm.__wbindgen_malloc);
1007
+ const len1 = WASM_VECTOR_LEN;
1008
+ const ptr2 = passArray8ToWasm0(global_pk_bytes, wasm.__wbindgen_malloc);
1009
+ const len2 = WASM_VECTOR_LEN;
1010
+ const ptr3 = passArray8ToWasm0(global_vk_bytes, wasm.__wbindgen_malloc);
1011
+ const len3 = WASM_VECTOR_LEN;
1012
+ const ret = wasm.singlewithdrawwasm_new(ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3);
1013
+ if (ret[2]) {
1014
+ throw takeFromExternrefTable0(ret[1]);
1015
+ }
1016
+ this.__wbg_ptr = ret[0] >>> 0;
1017
+ SingleWithdrawWasmFinalization.register(this, this.__wbg_ptr, this);
1018
+ return this;
1019
+ }
1020
+ /**
1021
+ * @param {any} witness
1022
+ * @returns {any}
1023
+ */
1024
+ prove(witness) {
1025
+ const ret = wasm.singlewithdrawwasm_prove(this.__wbg_ptr, witness);
1026
+ if (ret[2]) {
1027
+ throw takeFromExternrefTable0(ret[1]);
1028
+ }
1029
+ return takeFromExternrefTable0(ret[0]);
1030
+ }
1031
+ };
1032
+ if (Symbol.dispose) SingleWithdrawWasm.prototype[Symbol.dispose] = SingleWithdrawWasm.prototype.free;
1033
+ WithdrawNovaWasmFinalization = typeof FinalizationRegistry === "undefined" ? { register: () => {
1034
+ }, unregister: () => {
1035
+ } } : new FinalizationRegistry((ptr) => wasm.__wbg_withdrawnovawasm_free(ptr >>> 0, 1));
1036
+ WithdrawNovaWasm = class {
1037
+ __destroy_into_raw() {
1038
+ const ptr = this.__wbg_ptr;
1039
+ this.__wbg_ptr = 0;
1040
+ WithdrawNovaWasmFinalization.unregister(this);
1041
+ return ptr;
1042
+ }
1043
+ free() {
1044
+ const ptr = this.__destroy_into_raw();
1045
+ wasm.__wbg_withdrawnovawasm_free(ptr, 0);
1046
+ }
1047
+ /**
1048
+ * @param {Uint8Array} local_pp_bytes
1049
+ * @param {Uint8Array} local_vp_bytes
1050
+ * @param {Uint8Array} global_pp_bytes
1051
+ * @param {Uint8Array} global_vp_bytes
1052
+ */
1053
+ constructor(local_pp_bytes, local_vp_bytes, global_pp_bytes, global_vp_bytes) {
1054
+ const ptr0 = passArray8ToWasm0(local_pp_bytes, wasm.__wbindgen_malloc);
1055
+ const len0 = WASM_VECTOR_LEN;
1056
+ const ptr1 = passArray8ToWasm0(local_vp_bytes, wasm.__wbindgen_malloc);
1057
+ const len1 = WASM_VECTOR_LEN;
1058
+ const ptr2 = passArray8ToWasm0(global_pp_bytes, wasm.__wbindgen_malloc);
1059
+ const len2 = WASM_VECTOR_LEN;
1060
+ const ptr3 = passArray8ToWasm0(global_vp_bytes, wasm.__wbindgen_malloc);
1061
+ const len3 = WASM_VECTOR_LEN;
1062
+ const ret = wasm.withdrawnovawasm_new(ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3);
1063
+ if (ret[2]) {
1064
+ throw takeFromExternrefTable0(ret[1]);
1065
+ }
1066
+ this.__wbg_ptr = ret[0] >>> 0;
1067
+ WithdrawNovaWasmFinalization.register(this, this.__wbg_ptr, this);
1068
+ return this;
1069
+ }
1070
+ /**
1071
+ * @param {any} z0
1072
+ * @param {any} steps
1073
+ * @returns {any}
1074
+ */
1075
+ prove(z0, steps) {
1076
+ const ret = wasm.withdrawnovawasm_prove(this.__wbg_ptr, z0, steps);
1077
+ if (ret[2]) {
1078
+ throw takeFromExternrefTable0(ret[1]);
1079
+ }
1080
+ return takeFromExternrefTable0(ret[0]);
1081
+ }
1082
+ };
1083
+ if (Symbol.dispose) WithdrawNovaWasm.prototype[Symbol.dispose] = WithdrawNovaWasm.prototype.free;
1084
+ EXPECTED_RESPONSE_TYPES = /* @__PURE__ */ new Set(["basic", "cors", "default"]);
1085
+ zerc20_wasm_default = __wbg_init;
1086
+ }
1087
+ });
1088
+
1089
+ // dist/wasm/artifacts.js
1090
+ var TeleportArtifactsManager = class {
1091
+ loader;
1092
+ allPromise;
1093
+ singlePromise;
1094
+ batchPromise;
1095
+ /**
1096
+ * Configures the loader function for loading artifacts.
1097
+ * Clears any existing cache when reconfigured.
1098
+ */
1099
+ configure(loader) {
1100
+ this.loader = loader;
1101
+ this.clearCache();
1102
+ }
1103
+ /**
1104
+ * Clears all cached artifacts.
1105
+ */
1106
+ clearCache() {
1107
+ this.allPromise = void 0;
1108
+ this.singlePromise = void 0;
1109
+ this.batchPromise = void 0;
1110
+ }
1111
+ /**
1112
+ * Resets the manager to its initial state.
1113
+ * Useful for testing to ensure clean state between tests.
1114
+ */
1115
+ reset() {
1116
+ this.loader = void 0;
1117
+ this.clearCache();
1118
+ }
1119
+ /**
1120
+ * Returns true if a loader has been configured.
1121
+ */
1122
+ isConfigured() {
1123
+ return this.loader !== void 0;
1124
+ }
1125
+ /**
1126
+ * Primes all artifact caches.
1127
+ */
1128
+ primeAll(artifacts) {
1129
+ this.allPromise = Promise.resolve(artifacts);
1130
+ this.singlePromise = Promise.resolve(artifacts.single);
1131
+ this.batchPromise = Promise.resolve(artifacts.batch);
1132
+ }
1133
+ /**
1134
+ * Primes the single artifacts cache.
1135
+ */
1136
+ primeSingle(artifacts) {
1137
+ this.singlePromise = Promise.resolve(artifacts);
1138
+ }
1139
+ /**
1140
+ * Primes the batch artifacts cache.
1141
+ */
1142
+ primeBatch(artifacts) {
1143
+ this.batchPromise = Promise.resolve(artifacts);
1144
+ }
1145
+ /**
1146
+ * Loads all teleport artifacts.
1147
+ * @param _options Reserved for future use (e.g., custom fetchImpl). Kept for API consistency.
1148
+ * @throws Error if loader is not configured.
1149
+ * @remarks Use this to pre-warm caches at app startup.
1150
+ */
1151
+ async loadAll(_options = {}) {
1152
+ const artifacts = await this.resolveAll();
1153
+ if (!this.singlePromise) {
1154
+ this.singlePromise = Promise.resolve(artifacts.single);
1155
+ }
1156
+ if (!this.batchPromise) {
1157
+ this.batchPromise = Promise.resolve(artifacts.batch);
1158
+ }
1159
+ return artifacts;
1160
+ }
1161
+ /**
1162
+ * Loads single teleport artifacts.
1163
+ * @throws Error if loader is not configured.
1164
+ * @remarks This caches the resolved artifacts.
1165
+ */
1166
+ async loadSingle(options = {}) {
1167
+ if (this.singlePromise) {
1168
+ return this.singlePromise;
1169
+ }
1170
+ const promise = this.loadAll(options).then((artifacts) => artifacts.single);
1171
+ this.singlePromise = promise;
1172
+ return promise;
1173
+ }
1174
+ /**
1175
+ * Loads batch teleport artifacts.
1176
+ * @throws Error if loader is not configured.
1177
+ * @remarks This caches the resolved artifacts.
1178
+ */
1179
+ async loadBatch(options = {}) {
1180
+ if (this.batchPromise) {
1181
+ return this.batchPromise;
1182
+ }
1183
+ const promise = this.loadAll(options).then((artifacts) => artifacts.batch);
1184
+ this.batchPromise = promise;
1185
+ return promise;
1186
+ }
1187
+ requireLoader() {
1188
+ if (!this.loader) {
1189
+ throw new Error("Teleport artifact loader is not configured. Call configureTeleportArtifactsLoader() first.");
1190
+ }
1191
+ return this.loader;
1192
+ }
1193
+ async resolveAll() {
1194
+ if (!this.allPromise) {
1195
+ const loader = this.requireLoader();
1196
+ this.allPromise = Promise.resolve().then(() => loader());
1197
+ }
1198
+ return this.allPromise;
1199
+ }
1200
+ };
1201
+ var defaultManager = new TeleportArtifactsManager();
1202
+ function primeSingleTeleportArtifacts(artifacts) {
1203
+ defaultManager.primeSingle(artifacts);
1204
+ }
1205
+ function primeBatchTeleportArtifacts(artifacts) {
1206
+ defaultManager.primeBatch(artifacts);
1207
+ }
1208
+ async function loadSingleTeleportArtifacts(options = {}) {
1209
+ return defaultManager.loadSingle(options);
1210
+ }
1211
+ async function loadBatchTeleportArtifacts(options = {}) {
1212
+ return defaultManager.loadBatch(options);
1213
+ }
1214
+
1215
+ // dist/utils/hex.js
1216
+ import { bytesToHex as viemBytesToHex, hexToBytes as viemHexToBytes } from "viem";
1217
+ function ensureEvenHex(hex) {
1218
+ if (hex.length === 0) {
1219
+ return "00";
1220
+ }
1221
+ return hex.length % 2 === 0 ? hex : `0${hex}`;
1222
+ }
1223
+ function bytesToHex(bytes) {
1224
+ return viemBytesToHex(bytes);
1225
+ }
1226
+ function normalizeHex(value) {
1227
+ if (typeof value === "string") {
1228
+ const trimmed = value.trim();
1229
+ if (trimmed.length === 0) {
1230
+ throw new Error("normalizeHex: empty string provided");
1231
+ }
1232
+ const lower = trimmed.startsWith("0X") ? `0x${trimmed.slice(2)}` : trimmed;
1233
+ if (lower.startsWith("0x")) {
1234
+ return `0x${ensureEvenHex(lower.slice(2).toLowerCase())}`;
1235
+ }
1236
+ return `0x${ensureEvenHex(lower.toLowerCase())}`;
1237
+ }
1238
+ if (typeof value === "bigint") {
1239
+ return normalizeHex(value.toString(16));
1240
+ }
1241
+ if (typeof value === "number") {
1242
+ if (!Number.isInteger(value)) {
1243
+ throw new Error(`normalizeHex: expected integer number, received ${value}`);
1244
+ }
1245
+ return normalizeHex(value.toString(16));
1246
+ }
1247
+ if (value instanceof Uint8Array) {
1248
+ return bytesToHex(value);
1249
+ }
1250
+ if (value && typeof value === "object") {
1251
+ if (typeof value.toHexString === "function") {
1252
+ return normalizeHex(value.toHexString());
1253
+ }
1254
+ if (typeof value._hex === "string") {
1255
+ return normalizeHex(value._hex);
1256
+ }
1257
+ }
1258
+ throw new Error("normalizeHex: unsupported value type");
1259
+ }
1260
+ function hexToBytes(value) {
1261
+ const normalized = normalizeHex(value);
1262
+ if (normalized === "0x") {
1263
+ return new Uint8Array();
1264
+ }
1265
+ return viemHexToBytes(normalized);
1266
+ }
1267
+ function toBigInt(value) {
1268
+ if (typeof value === "bigint") {
1269
+ return value;
1270
+ }
1271
+ if (typeof value === "number") {
1272
+ if (!Number.isInteger(value)) {
1273
+ throw new Error(`toBigInt: expected integer number, received ${value}`);
1274
+ }
1275
+ return BigInt(value);
1276
+ }
1277
+ if (typeof value === "string") {
1278
+ const trimmed = value.trim();
1279
+ if (trimmed.length === 0) {
1280
+ throw new Error("toBigInt: empty string provided");
1281
+ }
1282
+ if (trimmed.startsWith("0x") || trimmed.startsWith("0X")) {
1283
+ return BigInt(trimmed);
1284
+ }
1285
+ return BigInt(trimmed);
1286
+ }
1287
+ throw new Error("toBigInt: unsupported value type");
1288
+ }
1289
+
1290
+ // dist/wasm/loader.js
1291
+ var DEFAULT_WASM_FILENAME = "assets/wasm/web/zerc20_wasm_bg.wasm";
1292
+ var BUNDLED_WASM_URL = new URL("../assets/wasm/web/zerc20_wasm_bg.wasm", import.meta.url).toString();
1293
+ function isNodeRuntime() {
1294
+ return typeof process !== "undefined" && typeof process.versions?.node === "string";
1295
+ }
1296
+ var WasmBindingsLoader = class {
1297
+ cache;
1298
+ promise;
1299
+ resolver;
1300
+ constructor(options = {}) {
1301
+ this.resolver = options.resolver ?? (() => resolveBindings());
1302
+ }
1303
+ /**
1304
+ * Gets or loads the WASM bindings with caching.
1305
+ * Returns cached bindings if available, otherwise loads them.
1306
+ */
1307
+ async getOrLoad() {
1308
+ if (this.cache) {
1309
+ return this.cache;
1310
+ }
1311
+ if (!this.promise) {
1312
+ this.promise = this.resolver();
1313
+ }
1314
+ this.cache = await this.promise;
1315
+ return this.cache;
1316
+ }
1317
+ /**
1318
+ * Returns true if bindings are already cached.
1319
+ */
1320
+ isCached() {
1321
+ return this.cache !== void 0;
1322
+ }
1323
+ /**
1324
+ * Resets the loader to its initial state.
1325
+ * Useful for testing to ensure clean state between tests.
1326
+ */
1327
+ reset() {
1328
+ this.cache = void 0;
1329
+ this.promise = void 0;
1330
+ }
1331
+ /**
1332
+ * Primes the cache with pre-loaded bindings.
1333
+ * Useful for testing or when bindings are loaded externally.
1334
+ */
1335
+ prime(bindings) {
1336
+ this.cache = bindings;
1337
+ this.promise = Promise.resolve(bindings);
1338
+ }
1339
+ };
1340
+ async function resolveBindings() {
1341
+ if (isNodeRuntime()) {
1342
+ return loadNodeBindings();
1343
+ }
1344
+ return Promise.resolve().then(() => (init_zerc20_wasm(), zerc20_wasm_exports));
1345
+ }
1346
+ async function loadNodeBindings() {
1347
+ const { createRequire } = await loadNodeModule();
1348
+ const require2 = createRequire(import.meta.url);
1349
+ return require2("../assets/wasm/node/zerc20_wasm.js");
1350
+ }
1351
+ async function loadNodeModule() {
1352
+ const specifiers = ["node:module", "module"];
1353
+ let lastError;
1354
+ for (const specifier of specifiers) {
1355
+ try {
1356
+ const mod = await import(specifier);
1357
+ return mod;
1358
+ } catch (error) {
1359
+ lastError = error;
1360
+ }
1361
+ }
1362
+ throw lastError ?? new Error("failed to load node:module for wasm bindings");
1363
+ }
1364
+ function requiresExplicitInit(bindings) {
1365
+ return typeof bindings.default === "function";
1366
+ }
1367
+ var defaultLoader = new WasmBindingsLoader();
1368
+ async function getOrLoadBindings() {
1369
+ return defaultLoader.getOrLoad();
1370
+ }
1371
+
1372
+ // dist/wasm/serialization.js
1373
+ function asSecretAndTweak(value) {
1374
+ const candidate = value;
1375
+ if (!candidate || typeof candidate.secret !== "string" || typeof candidate.tweak !== "string") {
1376
+ throw new Error("unexpected secret/tweak payload from wasm");
1377
+ }
1378
+ return {
1379
+ secret: normalizeHex(candidate.secret),
1380
+ tweak: normalizeHex(candidate.tweak)
1381
+ };
1382
+ }
1383
+ function asBurnArtifacts(value) {
1384
+ const raw = value;
1385
+ if (!raw || typeof raw.burnAddress !== "string" || typeof raw.secret !== "string") {
1386
+ throw new Error("unexpected burn artifacts payload from wasm");
1387
+ }
1388
+ const recipient = raw.generalRecipient;
1389
+ if (!recipient || typeof recipient.address !== "string") {
1390
+ throw new Error("missing general recipient payload from wasm");
1391
+ }
1392
+ const tweakSource = raw.tweak ?? recipient.tweak;
1393
+ if (typeof tweakSource !== "string") {
1394
+ throw new Error("missing burn tweak payload from wasm");
1395
+ }
1396
+ return {
1397
+ burnAddress: normalizeHex(raw.burnAddress),
1398
+ fullBurnAddress: normalizeHex(raw.fullBurnAddress),
1399
+ secret: normalizeHex(raw.secret),
1400
+ tweak: normalizeHex(tweakSource),
1401
+ generalRecipient: {
1402
+ chainId: toBigInt(recipient.chainId ?? 0),
1403
+ address: normalizeHex(recipient.address),
1404
+ tweak: normalizeHex(recipient.tweak),
1405
+ fr: normalizeHex(recipient.fr),
1406
+ u256: normalizeHex(recipient.u256)
1407
+ }
1408
+ };
1409
+ }
1410
+ function copyRpcUrls(urls, label) {
1411
+ if (!Array.isArray(urls) || urls.length === 0) {
1412
+ throw new Error(`${label} must provide at least one RPC URL`);
1413
+ }
1414
+ return urls.map((url, idx) => {
1415
+ if (typeof url !== "string" || url.trim().length === 0) {
1416
+ throw new Error(`${label} RPC URL at index ${idx} must be a non-empty string`);
1417
+ }
1418
+ return url.trim();
1419
+ });
1420
+ }
1421
+ function serializeHubEntry(entry) {
1422
+ return {
1423
+ hub_address: normalizeHex(entry.hubAddress),
1424
+ chain_id: entry.chainId,
1425
+ rpc_urls: copyRpcUrls(entry.rpcUrls, "hub.rpcUrls")
1426
+ };
1427
+ }
1428
+ function serializeTokenEntry(entry) {
1429
+ return {
1430
+ label: entry.label,
1431
+ token_address: normalizeHex(entry.tokenAddress),
1432
+ verifier_address: normalizeHex(entry.verifierAddress),
1433
+ minter_address: entry.minterAddress ? normalizeHex(entry.minterAddress) : void 0,
1434
+ chain_id: entry.chainId,
1435
+ deployed_block_number: entry.deployedBlockNumber,
1436
+ rpc_urls: copyRpcUrls(entry.rpcUrls, `${entry.label}.rpcUrls`),
1437
+ legacy_tx: entry.legacyTx ?? false
1438
+ };
1439
+ }
1440
+ function serializeAggregationTreeState(state) {
1441
+ return {
1442
+ latestAggSeq: state.latestAggSeq,
1443
+ aggregationRoot: normalizeHex(state.aggregationRoot),
1444
+ snapshot: state.snapshot.map((value) => normalizeHex(value)),
1445
+ transferTreeIndices: state.transferTreeIndices.map((value) => value),
1446
+ chainIds: state.chainIds.map((value) => value)
1447
+ };
1448
+ }
1449
+ function serializeIndexedEvent(event) {
1450
+ return {
1451
+ event_index: event.eventIndex,
1452
+ from: normalizeHex(event.from),
1453
+ to: normalizeHex(event.to),
1454
+ value: normalizeHex(event.value),
1455
+ eth_block_number: event.ethBlockNumber
1456
+ };
1457
+ }
1458
+ function serializeChainEvents(entry) {
1459
+ return {
1460
+ chainId: entry.chainId,
1461
+ events: entry.events.map(serializeIndexedEvent)
1462
+ };
1463
+ }
1464
+ function serializeLocalTeleportProof(proof) {
1465
+ return {
1466
+ treeIndex: proof.treeIndex,
1467
+ event: serializeIndexedEvent(proof.event),
1468
+ siblings: proof.siblings.map((value) => normalizeHex(value))
1469
+ };
1470
+ }
1471
+ function serializeChainLocalTeleportProofs(entry) {
1472
+ return {
1473
+ chainId: entry.chainId,
1474
+ proofs: entry.proofs.map(serializeLocalTeleportProof)
1475
+ };
1476
+ }
1477
+ function deserializeAggregationTreeState(raw) {
1478
+ return {
1479
+ latestAggSeq: toBigInt(raw.latestAggSeq),
1480
+ aggregationRoot: normalizeHex(raw.aggregationRoot),
1481
+ snapshot: raw.snapshot.map((value) => normalizeHex(value)),
1482
+ transferTreeIndices: raw.transferTreeIndices.map((value) => toBigInt(value)),
1483
+ chainIds: raw.chainIds.map((value) => toBigInt(value))
1484
+ };
1485
+ }
1486
+ function deserializeIndexedEvent(raw) {
1487
+ return {
1488
+ eventIndex: toBigInt(raw.event_index),
1489
+ from: normalizeHex(raw.from),
1490
+ to: normalizeHex(raw.to),
1491
+ value: toBigInt(raw.value),
1492
+ ethBlockNumber: toBigInt(raw.eth_block_number)
1493
+ };
1494
+ }
1495
+ function deserializeChainEvents(raw) {
1496
+ return {
1497
+ chainId: toBigInt(raw.chainId),
1498
+ events: raw.events.map(deserializeIndexedEvent)
1499
+ };
1500
+ }
1501
+ function deserializeEventsWithEligibility(raw) {
1502
+ return {
1503
+ eligible: raw.eligible.map(deserializeIndexedEvent),
1504
+ ineligible: raw.ineligible.map(deserializeIndexedEvent)
1505
+ };
1506
+ }
1507
+ function deserializeSeparatedChainEvents(raw) {
1508
+ return {
1509
+ chainId: toBigInt(raw.chainId),
1510
+ events: deserializeEventsWithEligibility(raw.events)
1511
+ };
1512
+ }
1513
+ function deserializeLocalTeleportProof(raw) {
1514
+ return {
1515
+ treeIndex: toBigInt(raw.treeIndex),
1516
+ event: deserializeIndexedEvent(raw.event),
1517
+ siblings: raw.siblings.map((value) => normalizeHex(value))
1518
+ };
1519
+ }
1520
+ function deserializeGlobalTeleportProof(raw) {
1521
+ return {
1522
+ event: deserializeIndexedEvent(raw.event),
1523
+ siblings: raw.siblings.map((value) => normalizeHex(value)),
1524
+ leafIndex: toBigInt(raw.leafIndex)
1525
+ };
1526
+ }
1527
+
1528
+ // dist/constants.js
1529
+ var AGGREGATION_TREE_HEIGHT = 6;
1530
+ var TRANSFER_TREE_HEIGHT = 40;
1531
+ var GLOBAL_TRANSFER_TREE_HEIGHT = TRANSFER_TREE_HEIGHT + AGGREGATION_TREE_HEIGHT;
1532
+ var NUM_BATCH_INVOICES = 10;
1533
+ var DEFAULT_DECIDER_TIMEOUT_MS = 5 * 60 * 1e3;
1534
+
1535
+ // dist/wasm/helpers.js
1536
+ function normalizeOverride(url) {
1537
+ if (!url) {
1538
+ return void 0;
1539
+ }
1540
+ const trimmed = url.trim();
1541
+ return trimmed.length > 0 ? trimmed : void 0;
1542
+ }
1543
+ function ensureTrailingSlash(value) {
1544
+ return value.endsWith("/") ? value : `${value}/`;
1545
+ }
1546
+ function logWasmFallbackWarning(url, error) {
1547
+ if (typeof console === "undefined" || typeof console.warn !== "function") {
1548
+ return;
1549
+ }
1550
+ console.warn(`zerc20 wasm failed to load from '${url}'. Falling back to the next candidate.`, error);
1551
+ }
1552
+ function formatError(error) {
1553
+ if (!error) {
1554
+ return "unknown error";
1555
+ }
1556
+ if (error instanceof Error) {
1557
+ return error.message;
1558
+ }
1559
+ return String(error);
1560
+ }
1561
+ function assertValidInvoiceSubId(subId) {
1562
+ if (!Number.isFinite(subId) || !Number.isInteger(subId)) {
1563
+ throw new Error("subId must be a finite integer");
1564
+ }
1565
+ if (subId < 0 || subId >= NUM_BATCH_INVOICES) {
1566
+ throw new Error(`subId must be between 0 and ${NUM_BATCH_INVOICES - 1}`);
1567
+ }
1568
+ }
1569
+ function toSafeNumber(value, label) {
1570
+ if (typeof value === "number") {
1571
+ if (!Number.isFinite(value) || !Number.isInteger(value)) {
1572
+ throw new Error(`${label} must be a finite integer`);
1573
+ }
1574
+ if (value < 0) {
1575
+ throw new Error(`${label} must be non-negative`);
1576
+ }
1577
+ return value;
1578
+ }
1579
+ if (value < 0n) {
1580
+ throw new Error(`${label} must be non-negative`);
1581
+ }
1582
+ const asNumber = Number(value);
1583
+ if (!Number.isFinite(asNumber) || BigInt(asNumber) !== value) {
1584
+ throw new Error(`${label} exceeds JavaScript safe integer range`);
1585
+ }
1586
+ return asNumber;
1587
+ }
1588
+
1589
+ // dist/wasm/runtime.js
1590
+ var WasmRuntime = class {
1591
+ locator;
1592
+ overrideUrl;
1593
+ initPromise;
1594
+ wasmBindings;
1595
+ /**
1596
+ * Create a new WASM runtime instance.
1597
+ * @remarks
1598
+ * - In Node.js, the WASM bindings are loaded from the bundled node build.
1599
+ * - In browsers, the runtime lazily initializes on first use; call {@link ready} to pre-initialize.
1600
+ */
1601
+ constructor(options = {}) {
1602
+ this.locator = { ...options };
1603
+ this.overrideUrl = normalizeOverride(options.url);
1604
+ }
1605
+ /**
1606
+ * Replace the locator options used to resolve the WASM binary.
1607
+ * @remarks This resets any in-flight initialization so a subsequent call will re-initialize.
1608
+ */
1609
+ configure(options) {
1610
+ this.locator = { ...options };
1611
+ this.overrideUrl = normalizeOverride(options.url);
1612
+ this.initPromise = void 0;
1613
+ }
1614
+ /**
1615
+ * Override the resolved WASM URL.
1616
+ * @remarks This takes precedence over `baseUrl`/`wasmFilename` resolution.
1617
+ */
1618
+ setOverrideUrl(url) {
1619
+ this.overrideUrl = normalizeOverride(url);
1620
+ this.initPromise = void 0;
1621
+ }
1622
+ /**
1623
+ * Ensure the WASM runtime is initialized and ready to use.
1624
+ * @remarks
1625
+ * This is optional in Node.js (bindings are available immediately), but recommended in browsers
1626
+ * to surface initialization errors early.
1627
+ */
1628
+ async ready() {
1629
+ await this.ensureReady();
1630
+ }
1631
+ async getSeedMessage() {
1632
+ const wasm3 = await this.readyBindings();
1633
+ return wasm3.seed_message();
1634
+ }
1635
+ async derivePaymentAdvice(seedHex, paymentAdviceIdHex, recipientChainId, recipientAddress) {
1636
+ const wasm3 = await this.readyBindings();
1637
+ return asSecretAndTweak(wasm3.derive_payment_advice(normalizeHex(seedHex), normalizeHex(paymentAdviceIdHex), toBigInt(recipientChainId), normalizeHex(recipientAddress)));
1638
+ }
1639
+ async deriveInvoiceSingle(seedHex, invoiceIdHex, recipientChainId, recipientAddress) {
1640
+ const wasm3 = await this.readyBindings();
1641
+ return asSecretAndTweak(wasm3.derive_invoice_single(normalizeHex(seedHex), normalizeHex(invoiceIdHex), toBigInt(recipientChainId), normalizeHex(recipientAddress)));
1642
+ }
1643
+ async deriveInvoiceBatch(seedHex, invoiceIdHex, subId, recipientChainId, recipientAddress) {
1644
+ assertValidInvoiceSubId(subId);
1645
+ const wasm3 = await this.readyBindings();
1646
+ return asSecretAndTweak(wasm3.derive_invoice_batch(normalizeHex(seedHex), normalizeHex(invoiceIdHex), subId, toBigInt(recipientChainId), normalizeHex(recipientAddress)));
1647
+ }
1648
+ async buildFullBurnAddress(recipientChainId, recipientAddress, secretHex, tweakHex) {
1649
+ const wasm3 = await this.readyBindings();
1650
+ const result = wasm3.build_full_burn_address(toBigInt(recipientChainId), normalizeHex(recipientAddress), normalizeHex(secretHex), normalizeHex(tweakHex));
1651
+ return asBurnArtifacts(result);
1652
+ }
1653
+ async decodeFullBurnAddress(payloadHex) {
1654
+ const wasm3 = await this.readyBindings();
1655
+ return asBurnArtifacts(wasm3.decode_full_burn_address(normalizeHex(payloadHex)));
1656
+ }
1657
+ async generalRecipientFr(chainId, recipientAddress, tweakHex) {
1658
+ const wasm3 = await this.readyBindings();
1659
+ return normalizeHex(wasm3.general_recipient_fr(toBigInt(chainId), normalizeHex(recipientAddress), normalizeHex(tweakHex)));
1660
+ }
1661
+ async aggregationRoot(snapshot) {
1662
+ const wasm3 = await this.readyBindings();
1663
+ return normalizeHex(wasm3.aggregation_root(snapshot.slice()));
1664
+ }
1665
+ async aggregationMerkleProof(snapshot, index) {
1666
+ const wasm3 = await this.readyBindings();
1667
+ const siblings = wasm3.aggregation_merkle_proof(snapshot.slice(), index);
1668
+ return siblings.map((value) => normalizeHex(value));
1669
+ }
1670
+ async fetchAggregationTreeState(params) {
1671
+ const payload = {
1672
+ hub: serializeHubEntry(params.hub),
1673
+ token: serializeTokenEntry(params.token)
1674
+ };
1675
+ if (params.eventBlockSpan !== void 0) {
1676
+ payload.eventBlockSpan = toSafeNumber(params.eventBlockSpan, "eventBlockSpan");
1677
+ }
1678
+ const wasm3 = await this.readyBindings();
1679
+ const rawState = await wasm3.fetch_aggregation_tree_state(payload);
1680
+ return deserializeAggregationTreeState(rawState);
1681
+ }
1682
+ async fetchTransferEvents(params) {
1683
+ const payload = {
1684
+ indexerUrl: params.indexerUrl,
1685
+ indexerFetchLimit: params.indexerFetchLimit,
1686
+ tokens: params.tokens.map(serializeTokenEntry),
1687
+ burnAddresses: params.burnAddresses.map((address) => normalizeHex(address))
1688
+ };
1689
+ const wasm3 = await this.readyBindings();
1690
+ const rawEvents = await wasm3.fetch_transfer_events(payload);
1691
+ return rawEvents.map((entry) => deserializeChainEvents(entry));
1692
+ }
1693
+ async separateEventsByEligibility(params) {
1694
+ const payload = {
1695
+ aggregationState: serializeAggregationTreeState(params.aggregationState),
1696
+ events: params.events.map(serializeChainEvents)
1697
+ };
1698
+ const wasm3 = await this.readyBindings();
1699
+ const rawSeparated = wasm3.separate_events_by_eligibility(payload);
1700
+ return rawSeparated.map((entry) => deserializeSeparatedChainEvents(entry));
1701
+ }
1702
+ async fetchLocalTeleportMerkleProofs(params) {
1703
+ const payload = {
1704
+ indexerUrl: params.indexerUrl,
1705
+ token: serializeTokenEntry(params.token),
1706
+ treeIndex: toBigInt(params.treeIndex),
1707
+ events: params.events.map(serializeIndexedEvent)
1708
+ };
1709
+ const wasm3 = await this.readyBindings();
1710
+ const rawProofs = await wasm3.fetch_local_teleport_merkle_proofs(payload);
1711
+ return rawProofs.map((proof) => deserializeLocalTeleportProof(proof));
1712
+ }
1713
+ async generateGlobalTeleportMerkleProofs(params) {
1714
+ const payload = {
1715
+ aggregationState: serializeAggregationTreeState(params.aggregationState),
1716
+ proofs: params.chains.map(serializeChainLocalTeleportProofs)
1717
+ };
1718
+ const wasm3 = await this.readyBindings();
1719
+ const rawProofs = wasm3.generate_global_teleport_merkle_proofs(payload);
1720
+ return rawProofs.map((proof) => deserializeGlobalTeleportProof(proof));
1721
+ }
1722
+ async createSingleWithdrawProgram(localPk, localVk, globalPk, globalVk) {
1723
+ const wasm3 = await this.readyBindings();
1724
+ return new wasm3.SingleWithdrawWasm(localPk, localVk, globalPk, globalVk);
1725
+ }
1726
+ async createWithdrawNovaProgram(localPp, localVp, globalPp, globalVp) {
1727
+ const wasm3 = await this.readyBindings();
1728
+ return new wasm3.WithdrawNovaWasm(localPp, localVp, globalPp, globalVp);
1729
+ }
1730
+ async ensureReady() {
1731
+ if (!this.initPromise) {
1732
+ this.initPromise = this.initialize();
1733
+ }
1734
+ await this.initPromise;
1735
+ }
1736
+ async readyBindings() {
1737
+ await this.ensureReady();
1738
+ return this.getBindings();
1739
+ }
1740
+ getBindings() {
1741
+ if (!this.wasmBindings) {
1742
+ throw new Error("zerc20 wasm bindings are not initialized");
1743
+ }
1744
+ return this.wasmBindings;
1745
+ }
1746
+ async initialize() {
1747
+ const bindings = await getOrLoadBindings();
1748
+ if (!requiresExplicitInit(bindings)) {
1749
+ this.wasmBindings = bindings;
1750
+ return;
1751
+ }
1752
+ const candidates = this.resolveCandidateUrls();
1753
+ let lastError;
1754
+ for (let idx = 0; idx < candidates.length; idx++) {
1755
+ const candidate = candidates[idx];
1756
+ try {
1757
+ await bindings.default({ module_or_path: candidate });
1758
+ this.wasmBindings = bindings;
1759
+ return;
1760
+ } catch (error) {
1761
+ lastError = error;
1762
+ if (idx < candidates.length - 1) {
1763
+ logWasmFallbackWarning(candidate, error);
1764
+ }
1765
+ }
1766
+ }
1767
+ throw new Error(`failed to initialize zerc20 wasm: ${formatError(lastError)}`);
1768
+ }
1769
+ resolveCandidateUrls() {
1770
+ const urls = [];
1771
+ if (this.overrideUrl) {
1772
+ urls.push(this.overrideUrl);
1773
+ }
1774
+ const configured = this.resolveConfiguredUrl();
1775
+ if (configured && configured !== this.overrideUrl) {
1776
+ urls.push(configured);
1777
+ }
1778
+ if (!urls.includes(BUNDLED_WASM_URL)) {
1779
+ urls.push(BUNDLED_WASM_URL);
1780
+ }
1781
+ return urls;
1782
+ }
1783
+ resolveConfiguredUrl() {
1784
+ const baseUrl = this.locator.baseUrl;
1785
+ if (!baseUrl) {
1786
+ return void 0;
1787
+ }
1788
+ const wasmFilename = this.locator.wasmFilename ?? DEFAULT_WASM_FILENAME;
1789
+ if (/^https?:\/\//i.test(baseUrl)) {
1790
+ return new URL(wasmFilename, ensureTrailingSlash(baseUrl)).toString();
1791
+ }
1792
+ const globalRef = this.locator.globalObject ?? (typeof globalThis !== "undefined" ? globalThis : void 0);
1793
+ const origin = globalRef?.location?.origin;
1794
+ if (!origin) {
1795
+ throw new Error("WasmRuntime requires a global location.origin when baseUrl is relative");
1796
+ }
1797
+ const prefix = baseUrl.startsWith("/") ? `${origin}${baseUrl}` : `${origin}/${baseUrl}`;
1798
+ return new URL(wasmFilename, ensureTrailingSlash(prefix)).toString();
1799
+ }
1800
+ };
1801
+
1802
+ // dist/utils/merkle.js
1803
+ import * as poseidonLite from "poseidon-lite";
1804
+ var BN254_FIELD_MODULUS = BigInt("0x30644e72e131a029b85045b68181585d97816a916871ca8d3c208c16d87cfd47");
1805
+ function resolvePoseidon(mod, functionName) {
1806
+ const defaultExport = mod.default;
1807
+ const nestedDefault = typeof defaultExport === "object" && defaultExport !== null ? defaultExport : void 0;
1808
+ const candidates = [
1809
+ mod[functionName],
1810
+ nestedDefault ? nestedDefault[functionName] : void 0,
1811
+ defaultExport
1812
+ ];
1813
+ for (const candidate of candidates) {
1814
+ if (typeof candidate === "function") {
1815
+ return candidate;
1816
+ }
1817
+ }
1818
+ throw new Error(`poseidon-lite did not expose a usable ${functionName} implementation`);
1819
+ }
1820
+ var poseidonHash2 = resolvePoseidon(poseidonLite, "poseidon2");
1821
+ var poseidonHash3 = resolvePoseidon(poseidonLite, "poseidon3");
1822
+ function ensureFieldElement(value, label) {
1823
+ if (value < 0n) {
1824
+ throw new Error(`${label} must be non-negative`);
1825
+ }
1826
+ if (value >= BN254_FIELD_MODULUS) {
1827
+ throw new Error(`${label} exceeds the BN254 field modulus`);
1828
+ }
1829
+ return value;
1830
+ }
1831
+ function hexToField(value, label) {
1832
+ const normalized = normalizeHex(value);
1833
+ return ensureFieldElement(BigInt(normalized), label);
1834
+ }
1835
+ function intoField(value, label) {
1836
+ const bigIntValue = typeof value === "bigint" ? value : toBigInt(value);
1837
+ return ensureFieldElement(bigIntValue, label);
1838
+ }
1839
+ function hashPair(left, right) {
1840
+ const result = poseidonHash2([left, right]);
1841
+ if (typeof result !== "bigint") {
1842
+ throw new Error("poseidon-lite returned a non-bigint result");
1843
+ }
1844
+ return ensureFieldElement(result, "poseidon result");
1845
+ }
1846
+ function hashTriple(left, middle, right) {
1847
+ const result = poseidonHash3([left, middle, right]);
1848
+ if (typeof result !== "bigint") {
1849
+ throw new Error("poseidon-lite returned a non-bigint result");
1850
+ }
1851
+ return ensureFieldElement(result, "poseidon result");
1852
+ }
1853
+ function computeLeafHash(fromAddressHex, toAddressHex, value) {
1854
+ const fromField = hexToField(fromAddressHex, "leaf from address");
1855
+ const toField = hexToField(toAddressHex, "leaf to address");
1856
+ const valueField = intoField(value, "leaf value");
1857
+ return hashTriple(fromField, toField, valueField);
1858
+ }
1859
+ function computeMerkleRootFromSiblings(params) {
1860
+ let state = ensureFieldElement(params.leaf, "leaf");
1861
+ let index = toBigInt(params.leafIndex);
1862
+ if (index < 0n) {
1863
+ throw new Error("leafIndex must be non-negative");
1864
+ }
1865
+ params.siblings.forEach((siblingHex, level) => {
1866
+ const sibling = hexToField(siblingHex, `siblings[${level}]`);
1867
+ if ((index & 1n) === 1n) {
1868
+ state = hashPair(sibling, state);
1869
+ } else {
1870
+ state = hashPair(state, sibling);
1871
+ }
1872
+ index >>= 1n;
1873
+ });
1874
+ return state;
1875
+ }
1876
+ function verifyGlobalTeleportProofs(args) {
1877
+ const { aggregationRoot, events, proofs: proofs2 } = args;
1878
+ if (events.length !== proofs2.length) {
1879
+ throw new Error("events length must match proofs length for global teleport verification");
1880
+ }
1881
+ if (events.length === 0) {
1882
+ return;
1883
+ }
1884
+ const expectedRoot = hexToField(aggregationRoot, "aggregationRoot");
1885
+ for (let idx = 0; idx < proofs2.length; idx++) {
1886
+ const proof = proofs2[idx];
1887
+ const event = events[idx];
1888
+ const leaf = computeLeafHash(event.from, event.to, event.value);
1889
+ const derivedRoot = computeMerkleRootFromSiblings({
1890
+ leaf,
1891
+ siblings: proof.siblings,
1892
+ leafIndex: proof.leafIndex
1893
+ });
1894
+ if (derivedRoot !== expectedRoot) {
1895
+ const leafLabel = `leafIndex ${proof.leafIndex.toString()} (eventIndex ${event.eventIndex.toString()})`;
1896
+ throw new Error(`merkle proof mismatch for ${leafLabel}`);
1897
+ }
1898
+ }
1899
+ }
1900
+
1901
+ // dist/zkp/proofUtils.js
1902
+ function toFixedHex(value, bytes = 32) {
1903
+ if (value < 0n) {
1904
+ throw new Error("toFixedHex: negative values are not supported");
1905
+ }
1906
+ const hex = value.toString(16).padStart(bytes * 2, "0");
1907
+ return `0x${hex}`;
1908
+ }
1909
+ function toFieldHex(value) {
1910
+ return toFixedHex(value, 32);
1911
+ }
1912
+ function toLeafIndexString(index) {
1913
+ return index.toString(10);
1914
+ }
1915
+ function zeroPadField(value, label) {
1916
+ const normalized = normalizeHex(value);
1917
+ const body = normalized.slice(2);
1918
+ if (!/^[0-9a-f]*$/i.test(body)) {
1919
+ throw new Error(`${label} contains non-hex characters: ${normalized}`);
1920
+ }
1921
+ if (body.length % 2 !== 0) {
1922
+ throw new Error(`${label} must have an even number of hex digits: ${normalized}`);
1923
+ }
1924
+ if (body.length > 64) {
1925
+ throw new Error(`${label} must fit within 32 bytes: ${normalized}`);
1926
+ }
1927
+ return `0x${body.padStart(64, "0")}`;
1928
+ }
1929
+ function formatFieldElement(value, label) {
1930
+ return zeroPadField(value, label);
1931
+ }
1932
+ function randomDummySteps() {
1933
+ const MIN_DUMMY_STEPS = 1;
1934
+ const MAX_DUMMY_STEPS = 3;
1935
+ const buffer = new Uint32Array(1);
1936
+ if (typeof crypto !== "undefined" && typeof crypto.getRandomValues === "function") {
1937
+ crypto.getRandomValues(buffer);
1938
+ const range = MAX_DUMMY_STEPS - MIN_DUMMY_STEPS + 1;
1939
+ return MIN_DUMMY_STEPS + buffer[0] % range;
1940
+ }
1941
+ return MIN_DUMMY_STEPS;
1942
+ }
1943
+ function appendDummySteps(steps) {
1944
+ const dummySteps = randomDummySteps();
1945
+ const maxLeaves = 1n << BigInt(GLOBAL_TRANSFER_TREE_HEIGHT);
1946
+ const offset = maxLeaves - 1n - BigInt(dummySteps);
1947
+ for (let i = 0; i < dummySteps; i += 1) {
1948
+ const leafIndex = offset + BigInt(i);
1949
+ steps.push({
1950
+ isDummy: true,
1951
+ from: formatFieldElement("0x0", `dummySteps[${i}].from`),
1952
+ value: formatFieldElement("0x0", `dummySteps[${i}].value`),
1953
+ secret: formatFieldElement("0x0", `dummySteps[${i}].secret`),
1954
+ leafIndex: toLeafIndexString(leafIndex),
1955
+ siblings: Array(GLOBAL_TRANSFER_TREE_HEIGHT).fill(null).map((_, siblingIdx) => formatFieldElement("0x0", `dummySteps[${i}].siblings[${siblingIdx}]`))
1956
+ });
1957
+ }
1958
+ }
1959
+ function sortProofsByLeafIndex(events, proofs2) {
1960
+ const proofEventPairs = events.map((event, idx) => ({
1961
+ event,
1962
+ proof: proofs2[idx]
1963
+ }));
1964
+ proofEventPairs.sort((a, b) => {
1965
+ if (a.proof.leafIndex < b.proof.leafIndex) {
1966
+ return -1;
1967
+ }
1968
+ if (a.proof.leafIndex > b.proof.leafIndex) {
1969
+ return 1;
1970
+ }
1971
+ return 0;
1972
+ });
1973
+ return {
1974
+ events: proofEventPairs.map((pair) => pair.event),
1975
+ proofs: proofEventPairs.map((pair) => pair.proof)
1976
+ };
1977
+ }
1978
+
1979
+ // dist/zkp/workerClient.js
1980
+ function hasWorkerSupport() {
1981
+ return typeof Worker !== "undefined";
1982
+ }
1983
+ var ZkpWorkerClient = class {
1984
+ worker = null;
1985
+ failed = false;
1986
+ nextJobId = 0;
1987
+ pendingJobs = /* @__PURE__ */ new Map();
1988
+ createWorkerFn;
1989
+ constructor(options = {}) {
1990
+ this.createWorkerFn = options.createWorker;
1991
+ }
1992
+ /**
1993
+ * Returns true if this client can run jobs (Worker API available and not failed).
1994
+ */
1995
+ canUse() {
1996
+ return hasWorkerSupport() && !this.failed;
1997
+ }
1998
+ /**
1999
+ * Runs a ZKP proof job in the worker.
2000
+ *
2001
+ * **Important:** Always await or catch the returned promise.
2002
+ * Calling `disable()` or `reset()` will reject pending jobs,
2003
+ * which can cause unhandled rejections if not properly awaited.
2004
+ *
2005
+ * @throws Error if worker is not available or has failed.
2006
+ */
2007
+ async runJob(type, payload) {
2008
+ const instance = this.ensureWorker();
2009
+ const jobId = this.nextJobId++;
2010
+ const message = { id: jobId, type, payload };
2011
+ const promise = new Promise((resolve, reject) => {
2012
+ this.pendingJobs.set(jobId, {
2013
+ resolve: (value) => resolve(value),
2014
+ reject
2015
+ });
2016
+ });
2017
+ instance.postMessage(message);
2018
+ return promise;
2019
+ }
2020
+ /**
2021
+ * Disables the worker and rejects all pending jobs.
2022
+ */
2023
+ disable(error) {
2024
+ this.failed = true;
2025
+ if (this.worker) {
2026
+ this.worker.terminate();
2027
+ this.worker = null;
2028
+ }
2029
+ this.pendingJobs.forEach((pending) => pending.reject(error ?? new Error("ZKP worker disabled")));
2030
+ this.pendingJobs.clear();
2031
+ }
2032
+ /**
2033
+ * Resets the client to its initial state. Useful for testing.
2034
+ */
2035
+ reset() {
2036
+ if (this.worker) {
2037
+ this.worker.terminate();
2038
+ this.worker = null;
2039
+ }
2040
+ this.failed = false;
2041
+ this.nextJobId = 0;
2042
+ this.pendingJobs.clear();
2043
+ }
2044
+ ensureWorker() {
2045
+ if (this.failed) {
2046
+ throw new Error("ZKP worker previously failed and has been disabled");
2047
+ }
2048
+ if (!hasWorkerSupport()) {
2049
+ throw new Error("Web Worker API is not available in this environment");
2050
+ }
2051
+ if (!this.worker) {
2052
+ const instance = this.createWorkerFn ? this.createWorkerFn() : new Worker(new URL("./worker.js", import.meta.url), { type: "module" });
2053
+ instance.addEventListener("message", (event) => this.handleMessage(event));
2054
+ instance.addEventListener("error", (event) => this.handleError(event));
2055
+ this.worker = instance;
2056
+ }
2057
+ return this.worker;
2058
+ }
2059
+ handleMessage(event) {
2060
+ const message = event.data;
2061
+ if (!message || typeof message !== "object") {
2062
+ return;
2063
+ }
2064
+ const pending = this.pendingJobs.get(message.id);
2065
+ if (!pending) {
2066
+ return;
2067
+ }
2068
+ this.pendingJobs.delete(message.id);
2069
+ if (message.type === "result") {
2070
+ pending.resolve(message.result);
2071
+ } else if (message.type === "error") {
2072
+ const error = new Error(message.error?.message ?? "ZKP worker failure");
2073
+ error.stack = message.error?.stack;
2074
+ pending.reject(error);
2075
+ } else {
2076
+ pending.reject(new Error(`ZKP worker returned unexpected message type ${message.type}`));
2077
+ }
2078
+ }
2079
+ handleError(event) {
2080
+ this.pendingJobs.forEach((pending) => pending.reject(event.error ?? new Error("ZKP worker error")));
2081
+ this.pendingJobs.clear();
2082
+ this.failed = true;
2083
+ if (this.worker) {
2084
+ this.worker.terminate();
2085
+ this.worker = null;
2086
+ }
2087
+ }
2088
+ };
2089
+ var defaultClient = new ZkpWorkerClient();
2090
+ function canUseZkpWorker() {
2091
+ return defaultClient.canUse();
2092
+ }
2093
+ async function runZkpWorkerJob(type, payload) {
2094
+ return defaultClient.runJob(type, payload);
2095
+ }
2096
+ function disableZkpWorker(error) {
2097
+ defaultClient.disable(error);
2098
+ }
2099
+
2100
+ // dist/zkp/proofService.js
2101
+ var ProofService = class {
2102
+ wasm;
2103
+ /**
2104
+ * Create a proof service bound to a {@link WasmRuntime}.
2105
+ */
2106
+ constructor(wasm3) {
2107
+ this.wasm = wasm3;
2108
+ }
2109
+ /**
2110
+ * Create a single teleport (Groth16) proof for an eligible event.
2111
+ * @remarks
2112
+ * - Verifies global teleport proofs before proving.
2113
+ * - Uses a worker when available; falls back to main thread if the worker fails.
2114
+ * @throws If proof verification fails or the prover fails.
2115
+ */
2116
+ async createSingleTeleportProof(params) {
2117
+ const wasmArtifacts = await loadSingleTeleportArtifacts();
2118
+ if (this.shouldUseWorker()) {
2119
+ try {
2120
+ return await runZkpWorkerJob("singleTeleport", {
2121
+ params,
2122
+ artifacts: wasmArtifacts
2123
+ });
2124
+ } catch (error) {
2125
+ console.warn("[zerc20] Worker single proof failed; falling back to main thread.", error);
2126
+ disableZkpWorker(error);
2127
+ }
2128
+ }
2129
+ return this.computeSingleTeleportProof(params, wasmArtifacts);
2130
+ }
2131
+ /**
2132
+ * Run the Nova batch prover to produce an IVC proof for multiple events.
2133
+ * @remarks
2134
+ * - Requires `events.length === proofs.length` and that each event/proof pair correspond by index.
2135
+ * - Uses a worker when available; falls back to main thread if the worker fails.
2136
+ * @throws If inputs are invalid, proof verification fails, or the prover fails.
2137
+ */
2138
+ async runNovaProver(params) {
2139
+ const wasmArtifacts = await loadBatchTeleportArtifacts();
2140
+ if (this.shouldUseWorker()) {
2141
+ try {
2142
+ return await runZkpWorkerJob("nova", {
2143
+ params,
2144
+ artifacts: wasmArtifacts
2145
+ });
2146
+ } catch (error) {
2147
+ console.warn("[zerc20] Worker nova prover failed; falling back to main thread.", error);
2148
+ disableZkpWorker(error);
2149
+ }
2150
+ }
2151
+ return this.computeNovaProof(params, wasmArtifacts);
2152
+ }
2153
+ shouldUseWorker() {
2154
+ return canUseZkpWorker();
2155
+ }
2156
+ async computeSingleTeleportProof(params, wasmArtifacts) {
2157
+ verifyGlobalTeleportProofs({
2158
+ aggregationRoot: params.aggregationState.aggregationRoot,
2159
+ events: [params.event],
2160
+ proofs: [params.proof]
2161
+ });
2162
+ const wasm3 = await this.wasm.createSingleWithdrawProgram(wasmArtifacts.localPk, wasmArtifacts.localVk, wasmArtifacts.globalPk, wasmArtifacts.globalVk);
2163
+ const zeroField = formatFieldElement("0x0", "delta");
2164
+ const witness = {
2165
+ merkleRoot: formatFieldElement(params.aggregationState.aggregationRoot, "merkleRoot"),
2166
+ recipient: formatFieldElement(params.recipientFr, "recipient"),
2167
+ withdrawValue: formatFieldElement(toFieldHex(params.event.value), "withdrawValue"),
2168
+ from: formatFieldElement(params.event.from, "from"),
2169
+ value: formatFieldElement(toFieldHex(params.event.value), "value"),
2170
+ delta: zeroField,
2171
+ secret: formatFieldElement(params.secretHex, "secret"),
2172
+ leafIndex: toLeafIndexString(params.proof.leafIndex),
2173
+ siblings: params.proof.siblings.map((sibling, idx) => formatFieldElement(sibling, `proof.siblings[${idx}]`))
2174
+ };
2175
+ try {
2176
+ const result = await wasm3.prove(witness);
2177
+ return {
2178
+ proofCalldata: normalizeHex(result.proofCalldata),
2179
+ publicInputs: result.publicInputs.map((input) => normalizeHex(input)),
2180
+ treeDepth: result.treeDepth
2181
+ };
2182
+ } catch (error) {
2183
+ console.error("[zerc20] createSingleTeleportProof failed", witness, error);
2184
+ throw new Error(error instanceof Error ? `single teleport proof failed: ${error.message}` : `single teleport proof failed: ${String(error)}`);
2185
+ }
2186
+ }
2187
+ async computeNovaProof(params, wasmArtifacts) {
2188
+ if (params.proofs.length !== params.events.length) {
2189
+ throw new Error("events length must match proofs length for batch teleport");
2190
+ }
2191
+ const { events: sortedEvents, proofs: sortedProofs } = sortProofsByLeafIndex(params.events, params.proofs);
2192
+ verifyGlobalTeleportProofs({
2193
+ aggregationRoot: params.aggregationState.aggregationRoot,
2194
+ events: sortedEvents,
2195
+ proofs: sortedProofs
2196
+ });
2197
+ const wasm3 = await this.wasm.createWithdrawNovaProgram(wasmArtifacts.localPp, wasmArtifacts.localVp, wasmArtifacts.globalPp, wasmArtifacts.globalVp);
2198
+ const z0 = [
2199
+ formatFieldElement(params.aggregationState.aggregationRoot, "z0[0]"),
2200
+ formatFieldElement(params.recipientFr, "z0[1]"),
2201
+ formatFieldElement("0x0", "z0[2]"),
2202
+ formatFieldElement("0x0", "z0[3]")
2203
+ ];
2204
+ const steps = sortedEvents.map((event, idx) => ({
2205
+ isDummy: false,
2206
+ from: formatFieldElement(event.from, `events[${idx}].from`),
2207
+ value: formatFieldElement(toFieldHex(event.value), `events[${idx}].value`),
2208
+ secret: formatFieldElement(params.secretHex, `events[${idx}].secret`),
2209
+ leafIndex: toLeafIndexString(sortedProofs[idx].leafIndex),
2210
+ siblings: sortedProofs[idx].siblings.map((sibling, siblingIdx) => formatFieldElement(sibling, `proofs[${idx}].siblings[${siblingIdx}]`))
2211
+ }));
2212
+ appendDummySteps(steps);
2213
+ try {
2214
+ const proofResult = await wasm3.prove(z0, steps);
2215
+ const ivcProofBytes = hexToBytes(proofResult.ivcProof);
2216
+ return {
2217
+ ivcProof: ivcProofBytes,
2218
+ finalState: proofResult.finalState.map((value) => normalizeHex(value)),
2219
+ steps: proofResult.steps
2220
+ };
2221
+ } catch (error) {
2222
+ console.error("[zerc20] runNovaProver failed", { z0 }, { steps }, error);
2223
+ throw new Error(error instanceof Error ? `batch teleport proof failed: ${error.message}` : `batch teleport proof failed: ${String(error)}`);
2224
+ }
2225
+ }
2226
+ };
2227
+
2228
+ // dist/zkp/worker.js
2229
+ disableZkpWorker(new Error("Workers are not used inside a worker context"));
2230
+ var wasm2 = new WasmRuntime();
2231
+ var proofs = new ProofService(wasm2);
2232
+ var ctx = self;
2233
+ ctx.addEventListener("message", async (event) => {
2234
+ const message = event.data;
2235
+ if (!message) {
2236
+ return;
2237
+ }
2238
+ try {
2239
+ if (message.type === "singleTeleport") {
2240
+ primeSingleTeleportArtifacts(message.payload.artifacts);
2241
+ const result = await proofs.createSingleTeleportProof(message.payload.params);
2242
+ const response = {
2243
+ id: message.id,
2244
+ type: "result",
2245
+ result
2246
+ };
2247
+ ctx.postMessage(response);
2248
+ return;
2249
+ }
2250
+ if (message.type === "nova") {
2251
+ primeBatchTeleportArtifacts(message.payload.artifacts);
2252
+ const result = await proofs.runNovaProver(message.payload.params);
2253
+ const response = {
2254
+ id: message.id,
2255
+ type: "result",
2256
+ result
2257
+ };
2258
+ ctx.postMessage(response);
2259
+ return;
47
2260
  }
2261
+ throw new Error(`Unknown ZKP worker job type ${message.type}`);
2262
+ } catch (error) {
2263
+ const response = {
2264
+ id: message.id,
2265
+ type: "error",
2266
+ error: {
2267
+ message: error instanceof Error ? error.message : String(error),
2268
+ stack: error instanceof Error ? error.stack : void 0
2269
+ }
2270
+ };
2271
+ ctx.postMessage(response);
2272
+ }
48
2273
  });
49
- //# sourceMappingURL=worker.js.map