@zkclaw/sdk 2.0.0 → 2.0.3

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.
@@ -0,0 +1,3378 @@
1
+ import {
2
+ __commonJS,
3
+ __require,
4
+ __toESM
5
+ } from "./chunk-XGB3TDIC.mjs";
6
+
7
+ // ../../node_modules/ms/index.js
8
+ var require_ms = __commonJS({
9
+ "../../node_modules/ms/index.js"(exports, module) {
10
+ "use strict";
11
+ var s = 1e3;
12
+ var m = s * 60;
13
+ var h = m * 60;
14
+ var d = h * 24;
15
+ var w = d * 7;
16
+ var y = d * 365.25;
17
+ module.exports = function(val, options) {
18
+ options = options || {};
19
+ var type = typeof val;
20
+ if (type === "string" && val.length > 0) {
21
+ return parse(val);
22
+ } else if (type === "number" && isFinite(val)) {
23
+ return options.long ? fmtLong(val) : fmtShort(val);
24
+ }
25
+ throw new Error(
26
+ "val is not a non-empty string or a valid number. val=" + JSON.stringify(val)
27
+ );
28
+ };
29
+ function parse(str) {
30
+ str = String(str);
31
+ if (str.length > 100) {
32
+ return;
33
+ }
34
+ var match = /^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(
35
+ str
36
+ );
37
+ if (!match) {
38
+ return;
39
+ }
40
+ var n = parseFloat(match[1]);
41
+ var type = (match[2] || "ms").toLowerCase();
42
+ switch (type) {
43
+ case "years":
44
+ case "year":
45
+ case "yrs":
46
+ case "yr":
47
+ case "y":
48
+ return n * y;
49
+ case "weeks":
50
+ case "week":
51
+ case "w":
52
+ return n * w;
53
+ case "days":
54
+ case "day":
55
+ case "d":
56
+ return n * d;
57
+ case "hours":
58
+ case "hour":
59
+ case "hrs":
60
+ case "hr":
61
+ case "h":
62
+ return n * h;
63
+ case "minutes":
64
+ case "minute":
65
+ case "mins":
66
+ case "min":
67
+ case "m":
68
+ return n * m;
69
+ case "seconds":
70
+ case "second":
71
+ case "secs":
72
+ case "sec":
73
+ case "s":
74
+ return n * s;
75
+ case "milliseconds":
76
+ case "millisecond":
77
+ case "msecs":
78
+ case "msec":
79
+ case "ms":
80
+ return n;
81
+ default:
82
+ return void 0;
83
+ }
84
+ }
85
+ function fmtShort(ms) {
86
+ var msAbs = Math.abs(ms);
87
+ if (msAbs >= d) {
88
+ return Math.round(ms / d) + "d";
89
+ }
90
+ if (msAbs >= h) {
91
+ return Math.round(ms / h) + "h";
92
+ }
93
+ if (msAbs >= m) {
94
+ return Math.round(ms / m) + "m";
95
+ }
96
+ if (msAbs >= s) {
97
+ return Math.round(ms / s) + "s";
98
+ }
99
+ return ms + "ms";
100
+ }
101
+ function fmtLong(ms) {
102
+ var msAbs = Math.abs(ms);
103
+ if (msAbs >= d) {
104
+ return plural(ms, msAbs, d, "day");
105
+ }
106
+ if (msAbs >= h) {
107
+ return plural(ms, msAbs, h, "hour");
108
+ }
109
+ if (msAbs >= m) {
110
+ return plural(ms, msAbs, m, "minute");
111
+ }
112
+ if (msAbs >= s) {
113
+ return plural(ms, msAbs, s, "second");
114
+ }
115
+ return ms + " ms";
116
+ }
117
+ function plural(ms, msAbs, n, name) {
118
+ var isPlural = msAbs >= n * 1.5;
119
+ return Math.round(ms / n) + " " + name + (isPlural ? "s" : "");
120
+ }
121
+ }
122
+ });
123
+
124
+ // ../../node_modules/debug/src/common.js
125
+ var require_common = __commonJS({
126
+ "../../node_modules/debug/src/common.js"(exports, module) {
127
+ "use strict";
128
+ function setup(env) {
129
+ createDebug6.debug = createDebug6;
130
+ createDebug6.default = createDebug6;
131
+ createDebug6.coerce = coerce;
132
+ createDebug6.disable = disable;
133
+ createDebug6.enable = enable;
134
+ createDebug6.enabled = enabled;
135
+ createDebug6.humanize = require_ms();
136
+ createDebug6.destroy = destroy;
137
+ Object.keys(env).forEach((key) => {
138
+ createDebug6[key] = env[key];
139
+ });
140
+ createDebug6.names = [];
141
+ createDebug6.skips = [];
142
+ createDebug6.formatters = {};
143
+ function selectColor(namespace) {
144
+ let hash = 0;
145
+ for (let i = 0; i < namespace.length; i++) {
146
+ hash = (hash << 5) - hash + namespace.charCodeAt(i);
147
+ hash |= 0;
148
+ }
149
+ return createDebug6.colors[Math.abs(hash) % createDebug6.colors.length];
150
+ }
151
+ createDebug6.selectColor = selectColor;
152
+ function createDebug6(namespace) {
153
+ let prevTime;
154
+ let enableOverride = null;
155
+ let namespacesCache;
156
+ let enabledCache;
157
+ function debug6(...args) {
158
+ if (!debug6.enabled) {
159
+ return;
160
+ }
161
+ const self = debug6;
162
+ const curr = Number(/* @__PURE__ */ new Date());
163
+ const ms = curr - (prevTime || curr);
164
+ self.diff = ms;
165
+ self.prev = prevTime;
166
+ self.curr = curr;
167
+ prevTime = curr;
168
+ args[0] = createDebug6.coerce(args[0]);
169
+ if (typeof args[0] !== "string") {
170
+ args.unshift("%O");
171
+ }
172
+ let index = 0;
173
+ args[0] = args[0].replace(/%([a-zA-Z%])/g, (match, format) => {
174
+ if (match === "%%") {
175
+ return "%";
176
+ }
177
+ index++;
178
+ const formatter = createDebug6.formatters[format];
179
+ if (typeof formatter === "function") {
180
+ const val = args[index];
181
+ match = formatter.call(self, val);
182
+ args.splice(index, 1);
183
+ index--;
184
+ }
185
+ return match;
186
+ });
187
+ createDebug6.formatArgs.call(self, args);
188
+ const logFn = self.log || createDebug6.log;
189
+ logFn.apply(self, args);
190
+ }
191
+ debug6.namespace = namespace;
192
+ debug6.useColors = createDebug6.useColors();
193
+ debug6.color = createDebug6.selectColor(namespace);
194
+ debug6.extend = extend;
195
+ debug6.destroy = createDebug6.destroy;
196
+ Object.defineProperty(debug6, "enabled", {
197
+ enumerable: true,
198
+ configurable: false,
199
+ get: () => {
200
+ if (enableOverride !== null) {
201
+ return enableOverride;
202
+ }
203
+ if (namespacesCache !== createDebug6.namespaces) {
204
+ namespacesCache = createDebug6.namespaces;
205
+ enabledCache = createDebug6.enabled(namespace);
206
+ }
207
+ return enabledCache;
208
+ },
209
+ set: (v) => {
210
+ enableOverride = v;
211
+ }
212
+ });
213
+ if (typeof createDebug6.init === "function") {
214
+ createDebug6.init(debug6);
215
+ }
216
+ return debug6;
217
+ }
218
+ function extend(namespace, delimiter) {
219
+ const newDebug = createDebug6(this.namespace + (typeof delimiter === "undefined" ? ":" : delimiter) + namespace);
220
+ newDebug.log = this.log;
221
+ return newDebug;
222
+ }
223
+ function enable(namespaces) {
224
+ createDebug6.save(namespaces);
225
+ createDebug6.namespaces = namespaces;
226
+ createDebug6.names = [];
227
+ createDebug6.skips = [];
228
+ const split = (typeof namespaces === "string" ? namespaces : "").trim().replace(/\s+/g, ",").split(",").filter(Boolean);
229
+ for (const ns of split) {
230
+ if (ns[0] === "-") {
231
+ createDebug6.skips.push(ns.slice(1));
232
+ } else {
233
+ createDebug6.names.push(ns);
234
+ }
235
+ }
236
+ }
237
+ function matchesTemplate(search, template) {
238
+ let searchIndex = 0;
239
+ let templateIndex = 0;
240
+ let starIndex = -1;
241
+ let matchIndex = 0;
242
+ while (searchIndex < search.length) {
243
+ if (templateIndex < template.length && (template[templateIndex] === search[searchIndex] || template[templateIndex] === "*")) {
244
+ if (template[templateIndex] === "*") {
245
+ starIndex = templateIndex;
246
+ matchIndex = searchIndex;
247
+ templateIndex++;
248
+ } else {
249
+ searchIndex++;
250
+ templateIndex++;
251
+ }
252
+ } else if (starIndex !== -1) {
253
+ templateIndex = starIndex + 1;
254
+ matchIndex++;
255
+ searchIndex = matchIndex;
256
+ } else {
257
+ return false;
258
+ }
259
+ }
260
+ while (templateIndex < template.length && template[templateIndex] === "*") {
261
+ templateIndex++;
262
+ }
263
+ return templateIndex === template.length;
264
+ }
265
+ function disable() {
266
+ const namespaces = [
267
+ ...createDebug6.names,
268
+ ...createDebug6.skips.map((namespace) => "-" + namespace)
269
+ ].join(",");
270
+ createDebug6.enable("");
271
+ return namespaces;
272
+ }
273
+ function enabled(name) {
274
+ for (const skip of createDebug6.skips) {
275
+ if (matchesTemplate(name, skip)) {
276
+ return false;
277
+ }
278
+ }
279
+ for (const ns of createDebug6.names) {
280
+ if (matchesTemplate(name, ns)) {
281
+ return true;
282
+ }
283
+ }
284
+ return false;
285
+ }
286
+ function coerce(val) {
287
+ if (val instanceof Error) {
288
+ return val.stack || val.message;
289
+ }
290
+ return val;
291
+ }
292
+ function destroy() {
293
+ console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.");
294
+ }
295
+ createDebug6.enable(createDebug6.load());
296
+ return createDebug6;
297
+ }
298
+ module.exports = setup;
299
+ }
300
+ });
301
+
302
+ // ../../node_modules/debug/src/browser.js
303
+ var require_browser = __commonJS({
304
+ "../../node_modules/debug/src/browser.js"(exports, module) {
305
+ "use strict";
306
+ exports.formatArgs = formatArgs;
307
+ exports.save = save;
308
+ exports.load = load;
309
+ exports.useColors = useColors;
310
+ exports.storage = localstorage();
311
+ exports.destroy = /* @__PURE__ */ (() => {
312
+ let warned = false;
313
+ return () => {
314
+ if (!warned) {
315
+ warned = true;
316
+ console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.");
317
+ }
318
+ };
319
+ })();
320
+ exports.colors = [
321
+ "#0000CC",
322
+ "#0000FF",
323
+ "#0033CC",
324
+ "#0033FF",
325
+ "#0066CC",
326
+ "#0066FF",
327
+ "#0099CC",
328
+ "#0099FF",
329
+ "#00CC00",
330
+ "#00CC33",
331
+ "#00CC66",
332
+ "#00CC99",
333
+ "#00CCCC",
334
+ "#00CCFF",
335
+ "#3300CC",
336
+ "#3300FF",
337
+ "#3333CC",
338
+ "#3333FF",
339
+ "#3366CC",
340
+ "#3366FF",
341
+ "#3399CC",
342
+ "#3399FF",
343
+ "#33CC00",
344
+ "#33CC33",
345
+ "#33CC66",
346
+ "#33CC99",
347
+ "#33CCCC",
348
+ "#33CCFF",
349
+ "#6600CC",
350
+ "#6600FF",
351
+ "#6633CC",
352
+ "#6633FF",
353
+ "#66CC00",
354
+ "#66CC33",
355
+ "#9900CC",
356
+ "#9900FF",
357
+ "#9933CC",
358
+ "#9933FF",
359
+ "#99CC00",
360
+ "#99CC33",
361
+ "#CC0000",
362
+ "#CC0033",
363
+ "#CC0066",
364
+ "#CC0099",
365
+ "#CC00CC",
366
+ "#CC00FF",
367
+ "#CC3300",
368
+ "#CC3333",
369
+ "#CC3366",
370
+ "#CC3399",
371
+ "#CC33CC",
372
+ "#CC33FF",
373
+ "#CC6600",
374
+ "#CC6633",
375
+ "#CC9900",
376
+ "#CC9933",
377
+ "#CCCC00",
378
+ "#CCCC33",
379
+ "#FF0000",
380
+ "#FF0033",
381
+ "#FF0066",
382
+ "#FF0099",
383
+ "#FF00CC",
384
+ "#FF00FF",
385
+ "#FF3300",
386
+ "#FF3333",
387
+ "#FF3366",
388
+ "#FF3399",
389
+ "#FF33CC",
390
+ "#FF33FF",
391
+ "#FF6600",
392
+ "#FF6633",
393
+ "#FF9900",
394
+ "#FF9933",
395
+ "#FFCC00",
396
+ "#FFCC33"
397
+ ];
398
+ function useColors() {
399
+ if (typeof window !== "undefined" && window.process && (window.process.type === "renderer" || window.process.__nwjs)) {
400
+ return true;
401
+ }
402
+ if (typeof navigator !== "undefined" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) {
403
+ return false;
404
+ }
405
+ let m;
406
+ return typeof document !== "undefined" && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance || // Is firebug? http://stackoverflow.com/a/398120/376773
407
+ typeof window !== "undefined" && window.console && (window.console.firebug || window.console.exception && window.console.table) || // Is firefox >= v31?
408
+ // https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
409
+ typeof navigator !== "undefined" && navigator.userAgent && (m = navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)) && parseInt(m[1], 10) >= 31 || // Double check webkit in userAgent just in case we are in a worker
410
+ typeof navigator !== "undefined" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/);
411
+ }
412
+ function formatArgs(args) {
413
+ args[0] = (this.useColors ? "%c" : "") + this.namespace + (this.useColors ? " %c" : " ") + args[0] + (this.useColors ? "%c " : " ") + "+" + module.exports.humanize(this.diff);
414
+ if (!this.useColors) {
415
+ return;
416
+ }
417
+ const c = "color: " + this.color;
418
+ args.splice(1, 0, c, "color: inherit");
419
+ let index = 0;
420
+ let lastC = 0;
421
+ args[0].replace(/%[a-zA-Z%]/g, (match) => {
422
+ if (match === "%%") {
423
+ return;
424
+ }
425
+ index++;
426
+ if (match === "%c") {
427
+ lastC = index;
428
+ }
429
+ });
430
+ args.splice(lastC, 0, c);
431
+ }
432
+ exports.log = console.debug || console.log || (() => {
433
+ });
434
+ function save(namespaces) {
435
+ try {
436
+ if (namespaces) {
437
+ exports.storage.setItem("debug", namespaces);
438
+ } else {
439
+ exports.storage.removeItem("debug");
440
+ }
441
+ } catch (error) {
442
+ }
443
+ }
444
+ function load() {
445
+ let r;
446
+ try {
447
+ r = exports.storage.getItem("debug") || exports.storage.getItem("DEBUG");
448
+ } catch (error) {
449
+ }
450
+ if (!r && typeof process !== "undefined" && "env" in process) {
451
+ r = process.env.DEBUG;
452
+ }
453
+ return r;
454
+ }
455
+ function localstorage() {
456
+ try {
457
+ return localStorage;
458
+ } catch (error) {
459
+ }
460
+ }
461
+ module.exports = require_common()(exports);
462
+ var { formatters } = module.exports;
463
+ formatters.j = function(v) {
464
+ try {
465
+ return JSON.stringify(v);
466
+ } catch (error) {
467
+ return "[UnexpectedJSONParseError]: " + error.message;
468
+ }
469
+ };
470
+ }
471
+ });
472
+
473
+ // ../../node_modules/has-flag/index.js
474
+ var require_has_flag = __commonJS({
475
+ "../../node_modules/has-flag/index.js"(exports, module) {
476
+ "use strict";
477
+ module.exports = (flag, argv = process.argv) => {
478
+ const prefix = flag.startsWith("-") ? "" : flag.length === 1 ? "-" : "--";
479
+ const position = argv.indexOf(prefix + flag);
480
+ const terminatorPosition = argv.indexOf("--");
481
+ return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition);
482
+ };
483
+ }
484
+ });
485
+
486
+ // ../../node_modules/supports-color/index.js
487
+ var require_supports_color = __commonJS({
488
+ "../../node_modules/supports-color/index.js"(exports, module) {
489
+ "use strict";
490
+ var os2 = __require("os");
491
+ var tty = __require("tty");
492
+ var hasFlag = require_has_flag();
493
+ var { env } = process;
494
+ var forceColor;
495
+ if (hasFlag("no-color") || hasFlag("no-colors") || hasFlag("color=false") || hasFlag("color=never")) {
496
+ forceColor = 0;
497
+ } else if (hasFlag("color") || hasFlag("colors") || hasFlag("color=true") || hasFlag("color=always")) {
498
+ forceColor = 1;
499
+ }
500
+ if ("FORCE_COLOR" in env) {
501
+ if (env.FORCE_COLOR === "true") {
502
+ forceColor = 1;
503
+ } else if (env.FORCE_COLOR === "false") {
504
+ forceColor = 0;
505
+ } else {
506
+ forceColor = env.FORCE_COLOR.length === 0 ? 1 : Math.min(parseInt(env.FORCE_COLOR, 10), 3);
507
+ }
508
+ }
509
+ function translateLevel(level) {
510
+ if (level === 0) {
511
+ return false;
512
+ }
513
+ return {
514
+ level,
515
+ hasBasic: true,
516
+ has256: level >= 2,
517
+ has16m: level >= 3
518
+ };
519
+ }
520
+ function supportsColor(haveStream, streamIsTTY) {
521
+ if (forceColor === 0) {
522
+ return 0;
523
+ }
524
+ if (hasFlag("color=16m") || hasFlag("color=full") || hasFlag("color=truecolor")) {
525
+ return 3;
526
+ }
527
+ if (hasFlag("color=256")) {
528
+ return 2;
529
+ }
530
+ if (haveStream && !streamIsTTY && forceColor === void 0) {
531
+ return 0;
532
+ }
533
+ const min = forceColor || 0;
534
+ if (env.TERM === "dumb") {
535
+ return min;
536
+ }
537
+ if (process.platform === "win32") {
538
+ const osRelease = os2.release().split(".");
539
+ if (Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) {
540
+ return Number(osRelease[2]) >= 14931 ? 3 : 2;
541
+ }
542
+ return 1;
543
+ }
544
+ if ("CI" in env) {
545
+ if (["TRAVIS", "CIRCLECI", "APPVEYOR", "GITLAB_CI", "GITHUB_ACTIONS", "BUILDKITE"].some((sign) => sign in env) || env.CI_NAME === "codeship") {
546
+ return 1;
547
+ }
548
+ return min;
549
+ }
550
+ if ("TEAMCITY_VERSION" in env) {
551
+ return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
552
+ }
553
+ if (env.COLORTERM === "truecolor") {
554
+ return 3;
555
+ }
556
+ if ("TERM_PROGRAM" in env) {
557
+ const version = parseInt((env.TERM_PROGRAM_VERSION || "").split(".")[0], 10);
558
+ switch (env.TERM_PROGRAM) {
559
+ case "iTerm.app":
560
+ return version >= 3 ? 3 : 2;
561
+ case "Apple_Terminal":
562
+ return 2;
563
+ }
564
+ }
565
+ if (/-256(color)?$/i.test(env.TERM)) {
566
+ return 2;
567
+ }
568
+ if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
569
+ return 1;
570
+ }
571
+ if ("COLORTERM" in env) {
572
+ return 1;
573
+ }
574
+ return min;
575
+ }
576
+ function getSupportLevel(stream) {
577
+ const level = supportsColor(stream, stream && stream.isTTY);
578
+ return translateLevel(level);
579
+ }
580
+ module.exports = {
581
+ supportsColor: getSupportLevel,
582
+ stdout: translateLevel(supportsColor(true, tty.isatty(1))),
583
+ stderr: translateLevel(supportsColor(true, tty.isatty(2)))
584
+ };
585
+ }
586
+ });
587
+
588
+ // ../../node_modules/debug/src/node.js
589
+ var require_node = __commonJS({
590
+ "../../node_modules/debug/src/node.js"(exports, module) {
591
+ "use strict";
592
+ var tty = __require("tty");
593
+ var util = __require("util");
594
+ exports.init = init;
595
+ exports.log = log;
596
+ exports.formatArgs = formatArgs;
597
+ exports.save = save;
598
+ exports.load = load;
599
+ exports.useColors = useColors;
600
+ exports.destroy = util.deprecate(
601
+ () => {
602
+ },
603
+ "Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."
604
+ );
605
+ exports.colors = [6, 2, 3, 4, 5, 1];
606
+ try {
607
+ const supportsColor = require_supports_color();
608
+ if (supportsColor && (supportsColor.stderr || supportsColor).level >= 2) {
609
+ exports.colors = [
610
+ 20,
611
+ 21,
612
+ 26,
613
+ 27,
614
+ 32,
615
+ 33,
616
+ 38,
617
+ 39,
618
+ 40,
619
+ 41,
620
+ 42,
621
+ 43,
622
+ 44,
623
+ 45,
624
+ 56,
625
+ 57,
626
+ 62,
627
+ 63,
628
+ 68,
629
+ 69,
630
+ 74,
631
+ 75,
632
+ 76,
633
+ 77,
634
+ 78,
635
+ 79,
636
+ 80,
637
+ 81,
638
+ 92,
639
+ 93,
640
+ 98,
641
+ 99,
642
+ 112,
643
+ 113,
644
+ 128,
645
+ 129,
646
+ 134,
647
+ 135,
648
+ 148,
649
+ 149,
650
+ 160,
651
+ 161,
652
+ 162,
653
+ 163,
654
+ 164,
655
+ 165,
656
+ 166,
657
+ 167,
658
+ 168,
659
+ 169,
660
+ 170,
661
+ 171,
662
+ 172,
663
+ 173,
664
+ 178,
665
+ 179,
666
+ 184,
667
+ 185,
668
+ 196,
669
+ 197,
670
+ 198,
671
+ 199,
672
+ 200,
673
+ 201,
674
+ 202,
675
+ 203,
676
+ 204,
677
+ 205,
678
+ 206,
679
+ 207,
680
+ 208,
681
+ 209,
682
+ 214,
683
+ 215,
684
+ 220,
685
+ 221
686
+ ];
687
+ }
688
+ } catch (error) {
689
+ }
690
+ exports.inspectOpts = Object.keys(process.env).filter((key) => {
691
+ return /^debug_/i.test(key);
692
+ }).reduce((obj, key) => {
693
+ const prop = key.substring(6).toLowerCase().replace(/_([a-z])/g, (_, k) => {
694
+ return k.toUpperCase();
695
+ });
696
+ let val = process.env[key];
697
+ if (/^(yes|on|true|enabled)$/i.test(val)) {
698
+ val = true;
699
+ } else if (/^(no|off|false|disabled)$/i.test(val)) {
700
+ val = false;
701
+ } else if (val === "null") {
702
+ val = null;
703
+ } else {
704
+ val = Number(val);
705
+ }
706
+ obj[prop] = val;
707
+ return obj;
708
+ }, {});
709
+ function useColors() {
710
+ return "colors" in exports.inspectOpts ? Boolean(exports.inspectOpts.colors) : tty.isatty(process.stderr.fd);
711
+ }
712
+ function formatArgs(args) {
713
+ const { namespace: name, useColors: useColors2 } = this;
714
+ if (useColors2) {
715
+ const c = this.color;
716
+ const colorCode = "\x1B[3" + (c < 8 ? c : "8;5;" + c);
717
+ const prefix = ` ${colorCode};1m${name} \x1B[0m`;
718
+ args[0] = prefix + args[0].split("\n").join("\n" + prefix);
719
+ args.push(colorCode + "m+" + module.exports.humanize(this.diff) + "\x1B[0m");
720
+ } else {
721
+ args[0] = getDate() + name + " " + args[0];
722
+ }
723
+ }
724
+ function getDate() {
725
+ if (exports.inspectOpts.hideDate) {
726
+ return "";
727
+ }
728
+ return (/* @__PURE__ */ new Date()).toISOString() + " ";
729
+ }
730
+ function log(...args) {
731
+ return process.stderr.write(util.formatWithOptions(exports.inspectOpts, ...args) + "\n");
732
+ }
733
+ function save(namespaces) {
734
+ if (namespaces) {
735
+ process.env.DEBUG = namespaces;
736
+ } else {
737
+ delete process.env.DEBUG;
738
+ }
739
+ }
740
+ function load() {
741
+ return process.env.DEBUG;
742
+ }
743
+ function init(debug6) {
744
+ debug6.inspectOpts = {};
745
+ const keys = Object.keys(exports.inspectOpts);
746
+ for (let i = 0; i < keys.length; i++) {
747
+ debug6.inspectOpts[keys[i]] = exports.inspectOpts[keys[i]];
748
+ }
749
+ }
750
+ module.exports = require_common()(exports);
751
+ var { formatters } = module.exports;
752
+ formatters.o = function(v) {
753
+ this.inspectOpts.colors = this.useColors;
754
+ return util.inspect(v, this.inspectOpts).split("\n").map((str) => str.trim()).join(" ");
755
+ };
756
+ formatters.O = function(v) {
757
+ this.inspectOpts.colors = this.useColors;
758
+ return util.inspect(v, this.inspectOpts);
759
+ };
760
+ }
761
+ });
762
+
763
+ // ../../node_modules/debug/src/index.js
764
+ var require_src = __commonJS({
765
+ "../../node_modules/debug/src/index.js"(exports, module) {
766
+ "use strict";
767
+ if (typeof process === "undefined" || process.type === "renderer" || process.browser === true || process.__nwjs) {
768
+ module.exports = require_browser();
769
+ } else {
770
+ module.exports = require_node();
771
+ }
772
+ }
773
+ });
774
+
775
+ // ../../node_modules/@aztec/bb.js/dest/node/crs/net_crs.js
776
+ var NetCrs = class {
777
+ constructor(numPoints) {
778
+ this.numPoints = numPoints;
779
+ }
780
+ /**
781
+ * Download the data.
782
+ */
783
+ async init() {
784
+ await this.downloadG1Data();
785
+ await this.downloadG2Data();
786
+ }
787
+ async downloadG1Data() {
788
+ if (this.numPoints === 0) {
789
+ return this.data = new Uint8Array([]);
790
+ }
791
+ const g1End = this.numPoints * 64 - 1;
792
+ const response = await fetch("https://aztec-ignition.s3.amazonaws.com/MAIN%20IGNITION/flat/g1.dat", {
793
+ headers: {
794
+ Range: `bytes=0-${g1End}`
795
+ },
796
+ cache: "force-cache"
797
+ });
798
+ return this.data = new Uint8Array(await response.arrayBuffer());
799
+ }
800
+ /**
801
+ * Download the G2 points data.
802
+ */
803
+ async downloadG2Data() {
804
+ const response2 = await fetch("https://aztec-ignition.s3.amazonaws.com/MAIN%20IGNITION/flat/g2.dat", {
805
+ cache: "force-cache"
806
+ });
807
+ return this.g2Data = new Uint8Array(await response2.arrayBuffer());
808
+ }
809
+ /**
810
+ * G1 points data for prover key.
811
+ * @returns The points data.
812
+ */
813
+ getG1Data() {
814
+ return this.data;
815
+ }
816
+ /**
817
+ * G2 points data for verification key.
818
+ * @returns The points data.
819
+ */
820
+ getG2Data() {
821
+ return this.g2Data;
822
+ }
823
+ };
824
+
825
+ // ../../node_modules/@aztec/bb.js/dest/node/crs/node/ignition_files_crs.js
826
+ import { dirname } from "path";
827
+ import { fileURLToPath } from "url";
828
+ function getCurrentDir() {
829
+ if (typeof __dirname !== "undefined") {
830
+ return __dirname;
831
+ } else {
832
+ return dirname(fileURLToPath(import.meta.url));
833
+ }
834
+ }
835
+ var SRS_DEV_PATH = getCurrentDir() + "/../../../../../cpp/srs_db/ignition/monomial";
836
+ var GRUMPKIN_SRS_DEV_PATH = getCurrentDir() + "/../../../../../cpp/srs_db/grumpkin/monomial";
837
+
838
+ // ../../node_modules/@aztec/bb.js/dest/node/crs/node/index.js
839
+ var import_debug = __toESM(require_src(), 1);
840
+ import { mkdirSync, readFileSync, writeFileSync } from "fs";
841
+ import { readFile, stat } from "fs/promises";
842
+ import { homedir } from "os";
843
+ var debug = (0, import_debug.default)("bb.js:crs");
844
+ var Crs = class _Crs {
845
+ constructor(numPoints, path) {
846
+ this.numPoints = numPoints;
847
+ this.path = path;
848
+ }
849
+ static async new(numPoints, crsPath = homedir() + "/.bb-crs") {
850
+ const crs = new _Crs(numPoints, crsPath);
851
+ await crs.init();
852
+ return crs;
853
+ }
854
+ async init() {
855
+ mkdirSync(this.path, { recursive: true });
856
+ const g1FileSize = await stat(this.path + "/bn254_g1.dat").then((stats) => stats.size).catch(() => 0);
857
+ const g2FileSize = await stat(this.path + "/bn254_g2.dat").then((stats) => stats.size).catch(() => 0);
858
+ if (g1FileSize >= this.numPoints * 64 && g1FileSize % 64 == 0 && g2FileSize == 128) {
859
+ debug(`using cached crs of size: ${g1FileSize / 64}`);
860
+ return;
861
+ }
862
+ debug(`downloading crs of size: ${this.numPoints}`);
863
+ const crs = new NetCrs(this.numPoints);
864
+ await crs.init();
865
+ writeFileSync(this.path + "/bn254_g1.dat", crs.getG1Data());
866
+ writeFileSync(this.path + "/bn254_g2.dat", crs.getG2Data());
867
+ }
868
+ /**
869
+ * G1 points data for prover key.
870
+ * @returns The points data.
871
+ */
872
+ getG1Data() {
873
+ return readFileSync(this.path + "/bn254_g1.dat");
874
+ }
875
+ /**
876
+ * G2 points data for verification key.
877
+ * @returns The points data.
878
+ */
879
+ getG2Data() {
880
+ return readFileSync(this.path + "/bn254_g2.dat");
881
+ }
882
+ };
883
+
884
+ // ../../node_modules/comlink/dist/esm/comlink.mjs
885
+ var proxyMarker = /* @__PURE__ */ Symbol("Comlink.proxy");
886
+ var createEndpoint = /* @__PURE__ */ Symbol("Comlink.endpoint");
887
+ var releaseProxy = /* @__PURE__ */ Symbol("Comlink.releaseProxy");
888
+ var finalizer = /* @__PURE__ */ Symbol("Comlink.finalizer");
889
+ var throwMarker = /* @__PURE__ */ Symbol("Comlink.thrown");
890
+ var isObject = (val) => typeof val === "object" && val !== null || typeof val === "function";
891
+ var proxyTransferHandler = {
892
+ canHandle: (val) => isObject(val) && val[proxyMarker],
893
+ serialize(obj) {
894
+ const { port1, port2 } = new MessageChannel();
895
+ expose(obj, port1);
896
+ return [port2, [port2]];
897
+ },
898
+ deserialize(port) {
899
+ port.start();
900
+ return wrap(port);
901
+ }
902
+ };
903
+ var throwTransferHandler = {
904
+ canHandle: (value) => isObject(value) && throwMarker in value,
905
+ serialize({ value }) {
906
+ let serialized;
907
+ if (value instanceof Error) {
908
+ serialized = {
909
+ isError: true,
910
+ value: {
911
+ message: value.message,
912
+ name: value.name,
913
+ stack: value.stack
914
+ }
915
+ };
916
+ } else {
917
+ serialized = { isError: false, value };
918
+ }
919
+ return [serialized, []];
920
+ },
921
+ deserialize(serialized) {
922
+ if (serialized.isError) {
923
+ throw Object.assign(new Error(serialized.value.message), serialized.value);
924
+ }
925
+ throw serialized.value;
926
+ }
927
+ };
928
+ var transferHandlers = /* @__PURE__ */ new Map([
929
+ ["proxy", proxyTransferHandler],
930
+ ["throw", throwTransferHandler]
931
+ ]);
932
+ function isAllowedOrigin(allowedOrigins, origin) {
933
+ for (const allowedOrigin of allowedOrigins) {
934
+ if (origin === allowedOrigin || allowedOrigin === "*") {
935
+ return true;
936
+ }
937
+ if (allowedOrigin instanceof RegExp && allowedOrigin.test(origin)) {
938
+ return true;
939
+ }
940
+ }
941
+ return false;
942
+ }
943
+ function expose(obj, ep = globalThis, allowedOrigins = ["*"]) {
944
+ ep.addEventListener("message", function callback(ev) {
945
+ if (!ev || !ev.data) {
946
+ return;
947
+ }
948
+ if (!isAllowedOrigin(allowedOrigins, ev.origin)) {
949
+ console.warn(`Invalid origin '${ev.origin}' for comlink proxy`);
950
+ return;
951
+ }
952
+ const { id, type, path } = Object.assign({ path: [] }, ev.data);
953
+ const argumentList = (ev.data.argumentList || []).map(fromWireValue);
954
+ let returnValue;
955
+ try {
956
+ const parent = path.slice(0, -1).reduce((obj2, prop) => obj2[prop], obj);
957
+ const rawValue = path.reduce((obj2, prop) => obj2[prop], obj);
958
+ switch (type) {
959
+ case "GET":
960
+ {
961
+ returnValue = rawValue;
962
+ }
963
+ break;
964
+ case "SET":
965
+ {
966
+ parent[path.slice(-1)[0]] = fromWireValue(ev.data.value);
967
+ returnValue = true;
968
+ }
969
+ break;
970
+ case "APPLY":
971
+ {
972
+ returnValue = rawValue.apply(parent, argumentList);
973
+ }
974
+ break;
975
+ case "CONSTRUCT":
976
+ {
977
+ const value = new rawValue(...argumentList);
978
+ returnValue = proxy(value);
979
+ }
980
+ break;
981
+ case "ENDPOINT":
982
+ {
983
+ const { port1, port2 } = new MessageChannel();
984
+ expose(obj, port2);
985
+ returnValue = transfer(port1, [port1]);
986
+ }
987
+ break;
988
+ case "RELEASE":
989
+ {
990
+ returnValue = void 0;
991
+ }
992
+ break;
993
+ default:
994
+ return;
995
+ }
996
+ } catch (value) {
997
+ returnValue = { value, [throwMarker]: 0 };
998
+ }
999
+ Promise.resolve(returnValue).catch((value) => {
1000
+ return { value, [throwMarker]: 0 };
1001
+ }).then((returnValue2) => {
1002
+ const [wireValue, transferables] = toWireValue(returnValue2);
1003
+ ep.postMessage(Object.assign(Object.assign({}, wireValue), { id }), transferables);
1004
+ if (type === "RELEASE") {
1005
+ ep.removeEventListener("message", callback);
1006
+ closeEndPoint(ep);
1007
+ if (finalizer in obj && typeof obj[finalizer] === "function") {
1008
+ obj[finalizer]();
1009
+ }
1010
+ }
1011
+ }).catch((error) => {
1012
+ const [wireValue, transferables] = toWireValue({
1013
+ value: new TypeError("Unserializable return value"),
1014
+ [throwMarker]: 0
1015
+ });
1016
+ ep.postMessage(Object.assign(Object.assign({}, wireValue), { id }), transferables);
1017
+ });
1018
+ });
1019
+ if (ep.start) {
1020
+ ep.start();
1021
+ }
1022
+ }
1023
+ function isMessagePort(endpoint) {
1024
+ return endpoint.constructor.name === "MessagePort";
1025
+ }
1026
+ function closeEndPoint(endpoint) {
1027
+ if (isMessagePort(endpoint))
1028
+ endpoint.close();
1029
+ }
1030
+ function wrap(ep, target) {
1031
+ const pendingListeners = /* @__PURE__ */ new Map();
1032
+ ep.addEventListener("message", function handleMessage(ev) {
1033
+ const { data } = ev;
1034
+ if (!data || !data.id) {
1035
+ return;
1036
+ }
1037
+ const resolver = pendingListeners.get(data.id);
1038
+ if (!resolver) {
1039
+ return;
1040
+ }
1041
+ try {
1042
+ resolver(data);
1043
+ } finally {
1044
+ pendingListeners.delete(data.id);
1045
+ }
1046
+ });
1047
+ return createProxy(ep, pendingListeners, [], target);
1048
+ }
1049
+ function throwIfProxyReleased(isReleased) {
1050
+ if (isReleased) {
1051
+ throw new Error("Proxy has been released and is not useable");
1052
+ }
1053
+ }
1054
+ function releaseEndpoint(ep) {
1055
+ return requestResponseMessage(ep, /* @__PURE__ */ new Map(), {
1056
+ type: "RELEASE"
1057
+ }).then(() => {
1058
+ closeEndPoint(ep);
1059
+ });
1060
+ }
1061
+ var proxyCounter = /* @__PURE__ */ new WeakMap();
1062
+ var proxyFinalizers = "FinalizationRegistry" in globalThis && new FinalizationRegistry((ep) => {
1063
+ const newCount = (proxyCounter.get(ep) || 0) - 1;
1064
+ proxyCounter.set(ep, newCount);
1065
+ if (newCount === 0) {
1066
+ releaseEndpoint(ep);
1067
+ }
1068
+ });
1069
+ function registerProxy(proxy2, ep) {
1070
+ const newCount = (proxyCounter.get(ep) || 0) + 1;
1071
+ proxyCounter.set(ep, newCount);
1072
+ if (proxyFinalizers) {
1073
+ proxyFinalizers.register(proxy2, ep, proxy2);
1074
+ }
1075
+ }
1076
+ function unregisterProxy(proxy2) {
1077
+ if (proxyFinalizers) {
1078
+ proxyFinalizers.unregister(proxy2);
1079
+ }
1080
+ }
1081
+ function createProxy(ep, pendingListeners, path = [], target = function() {
1082
+ }) {
1083
+ let isProxyReleased = false;
1084
+ const proxy2 = new Proxy(target, {
1085
+ get(_target, prop) {
1086
+ throwIfProxyReleased(isProxyReleased);
1087
+ if (prop === releaseProxy) {
1088
+ return () => {
1089
+ unregisterProxy(proxy2);
1090
+ releaseEndpoint(ep);
1091
+ pendingListeners.clear();
1092
+ isProxyReleased = true;
1093
+ };
1094
+ }
1095
+ if (prop === "then") {
1096
+ if (path.length === 0) {
1097
+ return { then: () => proxy2 };
1098
+ }
1099
+ const r = requestResponseMessage(ep, pendingListeners, {
1100
+ type: "GET",
1101
+ path: path.map((p) => p.toString())
1102
+ }).then(fromWireValue);
1103
+ return r.then.bind(r);
1104
+ }
1105
+ return createProxy(ep, pendingListeners, [...path, prop]);
1106
+ },
1107
+ set(_target, prop, rawValue) {
1108
+ throwIfProxyReleased(isProxyReleased);
1109
+ const [value, transferables] = toWireValue(rawValue);
1110
+ return requestResponseMessage(ep, pendingListeners, {
1111
+ type: "SET",
1112
+ path: [...path, prop].map((p) => p.toString()),
1113
+ value
1114
+ }, transferables).then(fromWireValue);
1115
+ },
1116
+ apply(_target, _thisArg, rawArgumentList) {
1117
+ throwIfProxyReleased(isProxyReleased);
1118
+ const last = path[path.length - 1];
1119
+ if (last === createEndpoint) {
1120
+ return requestResponseMessage(ep, pendingListeners, {
1121
+ type: "ENDPOINT"
1122
+ }).then(fromWireValue);
1123
+ }
1124
+ if (last === "bind") {
1125
+ return createProxy(ep, pendingListeners, path.slice(0, -1));
1126
+ }
1127
+ const [argumentList, transferables] = processArguments(rawArgumentList);
1128
+ return requestResponseMessage(ep, pendingListeners, {
1129
+ type: "APPLY",
1130
+ path: path.map((p) => p.toString()),
1131
+ argumentList
1132
+ }, transferables).then(fromWireValue);
1133
+ },
1134
+ construct(_target, rawArgumentList) {
1135
+ throwIfProxyReleased(isProxyReleased);
1136
+ const [argumentList, transferables] = processArguments(rawArgumentList);
1137
+ return requestResponseMessage(ep, pendingListeners, {
1138
+ type: "CONSTRUCT",
1139
+ path: path.map((p) => p.toString()),
1140
+ argumentList
1141
+ }, transferables).then(fromWireValue);
1142
+ }
1143
+ });
1144
+ registerProxy(proxy2, ep);
1145
+ return proxy2;
1146
+ }
1147
+ function myFlat(arr) {
1148
+ return Array.prototype.concat.apply([], arr);
1149
+ }
1150
+ function processArguments(argumentList) {
1151
+ const processed = argumentList.map(toWireValue);
1152
+ return [processed.map((v) => v[0]), myFlat(processed.map((v) => v[1]))];
1153
+ }
1154
+ var transferCache = /* @__PURE__ */ new WeakMap();
1155
+ function transfer(obj, transfers) {
1156
+ transferCache.set(obj, transfers);
1157
+ return obj;
1158
+ }
1159
+ function proxy(obj) {
1160
+ return Object.assign(obj, { [proxyMarker]: true });
1161
+ }
1162
+ function toWireValue(value) {
1163
+ for (const [name, handler] of transferHandlers) {
1164
+ if (handler.canHandle(value)) {
1165
+ const [serializedValue, transferables] = handler.serialize(value);
1166
+ return [
1167
+ {
1168
+ type: "HANDLER",
1169
+ name,
1170
+ value: serializedValue
1171
+ },
1172
+ transferables
1173
+ ];
1174
+ }
1175
+ }
1176
+ return [
1177
+ {
1178
+ type: "RAW",
1179
+ value
1180
+ },
1181
+ transferCache.get(value) || []
1182
+ ];
1183
+ }
1184
+ function fromWireValue(value) {
1185
+ switch (value.type) {
1186
+ case "HANDLER":
1187
+ return transferHandlers.get(value.name).deserialize(value.value);
1188
+ case "RAW":
1189
+ return value.value;
1190
+ }
1191
+ }
1192
+ function requestResponseMessage(ep, pendingListeners, msg, transfers) {
1193
+ return new Promise((resolve) => {
1194
+ const id = generateUUID();
1195
+ pendingListeners.set(id, resolve);
1196
+ if (ep.start) {
1197
+ ep.start();
1198
+ }
1199
+ ep.postMessage(Object.assign({ id }, msg), transfers);
1200
+ });
1201
+ }
1202
+ function generateUUID() {
1203
+ return new Array(4).fill(0).map(() => Math.floor(Math.random() * Number.MAX_SAFE_INTEGER).toString(16)).join("-");
1204
+ }
1205
+
1206
+ // ../../node_modules/@aztec/bb.js/dest/node/serialize/buffer_reader.js
1207
+ var BufferReader = class _BufferReader {
1208
+ constructor(buffer, offset = 0) {
1209
+ this.buffer = buffer;
1210
+ this.index = offset;
1211
+ }
1212
+ static asReader(bufferOrReader) {
1213
+ return bufferOrReader instanceof _BufferReader ? bufferOrReader : new _BufferReader(bufferOrReader);
1214
+ }
1215
+ readNumber() {
1216
+ const dataView = new DataView(this.buffer.buffer, this.buffer.byteOffset + this.index, 4);
1217
+ this.index += 4;
1218
+ return dataView.getUint32(0, false);
1219
+ }
1220
+ readBoolean() {
1221
+ this.index += 1;
1222
+ return Boolean(this.buffer.at(this.index - 1));
1223
+ }
1224
+ readBytes(n) {
1225
+ this.index += n;
1226
+ return this.buffer.slice(this.index - n, this.index);
1227
+ }
1228
+ readNumberVector() {
1229
+ return this.readVector({
1230
+ fromBuffer: (reader) => reader.readNumber()
1231
+ });
1232
+ }
1233
+ readVector(itemDeserializer) {
1234
+ const size = this.readNumber();
1235
+ const result = new Array(size);
1236
+ for (let i = 0; i < size; i++) {
1237
+ result[i] = itemDeserializer.fromBuffer(this);
1238
+ }
1239
+ return result;
1240
+ }
1241
+ readArray(size, itemDeserializer) {
1242
+ const result = new Array(size);
1243
+ for (let i = 0; i < size; i++) {
1244
+ result[i] = itemDeserializer.fromBuffer(this);
1245
+ }
1246
+ return result;
1247
+ }
1248
+ readObject(deserializer) {
1249
+ return deserializer.fromBuffer(this);
1250
+ }
1251
+ peekBytes(n) {
1252
+ return this.buffer.subarray(this.index, n ? this.index + n : void 0);
1253
+ }
1254
+ readString() {
1255
+ return new TextDecoder().decode(this.readBuffer());
1256
+ }
1257
+ readBuffer() {
1258
+ const size = this.readNumber();
1259
+ return this.readBytes(size);
1260
+ }
1261
+ readMap(deserializer) {
1262
+ const numEntries = this.readNumber();
1263
+ const map = {};
1264
+ for (let i = 0; i < numEntries; i++) {
1265
+ const key = this.readString();
1266
+ const value = this.readObject(deserializer);
1267
+ map[key] = value;
1268
+ }
1269
+ return map;
1270
+ }
1271
+ };
1272
+
1273
+ // ../../node_modules/@aztec/bb.js/dest/node/serialize/output_type.js
1274
+ function BoolDeserializer() {
1275
+ return {
1276
+ SIZE_IN_BYTES: 1,
1277
+ fromBuffer: (buf) => {
1278
+ const reader = BufferReader.asReader(buf);
1279
+ return reader.readBoolean();
1280
+ }
1281
+ };
1282
+ }
1283
+ function NumberDeserializer() {
1284
+ return {
1285
+ SIZE_IN_BYTES: 4,
1286
+ fromBuffer: (buf) => {
1287
+ const reader = BufferReader.asReader(buf);
1288
+ return reader.readNumber();
1289
+ }
1290
+ };
1291
+ }
1292
+ function VectorDeserializer(t) {
1293
+ return {
1294
+ fromBuffer: (buf) => {
1295
+ const reader = BufferReader.asReader(buf);
1296
+ return reader.readVector(t);
1297
+ }
1298
+ };
1299
+ }
1300
+ function BufferDeserializer() {
1301
+ return {
1302
+ fromBuffer: (buf) => {
1303
+ const reader = BufferReader.asReader(buf);
1304
+ return reader.readBuffer();
1305
+ }
1306
+ };
1307
+ }
1308
+ function StringDeserializer() {
1309
+ return {
1310
+ fromBuffer: (buf) => {
1311
+ const reader = BufferReader.asReader(buf);
1312
+ return reader.readString();
1313
+ }
1314
+ };
1315
+ }
1316
+
1317
+ // ../../node_modules/@aztec/bb.js/dest/node/types/raw_buffer.js
1318
+ var RawBuffer = class extends Uint8Array {
1319
+ };
1320
+
1321
+ // ../../node_modules/@aztec/bb.js/dest/node/serialize/serialize.js
1322
+ function boolToBuffer(b) {
1323
+ const buf = new Uint8Array(1);
1324
+ buf[0] = b ? 1 : 0;
1325
+ return buf;
1326
+ }
1327
+ function numToUInt32BE(n, bufferSize = 4) {
1328
+ const buf = new Uint8Array(bufferSize);
1329
+ new DataView(buf.buffer).setUint32(buf.byteLength - 4, n, false);
1330
+ return buf;
1331
+ }
1332
+ function numToInt32BE(n, bufferSize = 4) {
1333
+ const buf = new Uint8Array(bufferSize);
1334
+ new DataView(buf.buffer).setInt32(buf.byteLength - 4, n, false);
1335
+ return buf;
1336
+ }
1337
+ function concatenateUint8Arrays(arrayOfUint8Arrays) {
1338
+ const totalLength = arrayOfUint8Arrays.reduce((prev, curr) => prev + curr.length, 0);
1339
+ const result = new Uint8Array(totalLength);
1340
+ let length = 0;
1341
+ for (const array of arrayOfUint8Arrays) {
1342
+ result.set(array, length);
1343
+ length += array.length;
1344
+ }
1345
+ return result;
1346
+ }
1347
+ function uint8ArrayToHexString(uint8Array) {
1348
+ return uint8Array.reduce((accumulator, byte) => accumulator + byte.toString(16).padStart(2, "0"), "");
1349
+ }
1350
+ function serializeBufferToVector(buf) {
1351
+ return concatenateUint8Arrays([numToInt32BE(buf.length), buf]);
1352
+ }
1353
+ function serializeBigInt(n, width = 32) {
1354
+ const buf = new Uint8Array(width);
1355
+ for (let i = 0; i < width; i++) {
1356
+ buf[width - i - 1] = Number(n >> BigInt(i * 8) & 0xffn);
1357
+ }
1358
+ return buf;
1359
+ }
1360
+ function serializeBufferArrayToVector(arr) {
1361
+ return concatenateUint8Arrays([numToUInt32BE(arr.length), ...arr.flat()]);
1362
+ }
1363
+ function serializeBufferable(obj) {
1364
+ if (Array.isArray(obj)) {
1365
+ return serializeBufferArrayToVector(obj.map(serializeBufferable));
1366
+ } else if (obj instanceof RawBuffer) {
1367
+ return obj;
1368
+ } else if (obj instanceof Uint8Array) {
1369
+ return serializeBufferToVector(obj);
1370
+ } else if (typeof obj === "boolean") {
1371
+ return boolToBuffer(obj);
1372
+ } else if (typeof obj === "number") {
1373
+ return numToUInt32BE(obj);
1374
+ } else if (typeof obj === "bigint") {
1375
+ return serializeBigInt(obj);
1376
+ } else if (typeof obj === "string") {
1377
+ return serializeBufferToVector(new TextEncoder().encode(obj));
1378
+ } else {
1379
+ return obj.toBuffer();
1380
+ }
1381
+ }
1382
+
1383
+ // ../../node_modules/@aztec/bb.js/dest/node/types/ptr.js
1384
+ var Ptr = class {
1385
+ constructor(value) {
1386
+ this.value = value;
1387
+ }
1388
+ static fromBuffer(buffer) {
1389
+ const reader = BufferReader.asReader(buffer);
1390
+ return new this(reader.readBytes(this.SIZE_IN_BYTES));
1391
+ }
1392
+ toBuffer() {
1393
+ return this.value;
1394
+ }
1395
+ };
1396
+ Ptr.SIZE_IN_BYTES = 4;
1397
+
1398
+ // ../../node_modules/@aztec/bb.js/dest/node/random/node/index.js
1399
+ import { randomBytes as cryptoRandomBytes } from "crypto";
1400
+ function randomBytes(len) {
1401
+ return new Uint8Array(cryptoRandomBytes(len));
1402
+ }
1403
+
1404
+ // ../../node_modules/@aztec/bb.js/dest/node/bigint-array/index.js
1405
+ function toBigIntBE(bytes) {
1406
+ bytes = new Uint8Array(bytes);
1407
+ let bigint = BigInt(0);
1408
+ const view = new DataView(bytes.buffer);
1409
+ for (let i = 0; i < bytes.byteLength; i++) {
1410
+ bigint = (bigint << BigInt(8)) + BigInt(view.getUint8(i));
1411
+ }
1412
+ return bigint;
1413
+ }
1414
+ function toBufferBE(value, byteLength = 32) {
1415
+ const bytes = new Uint8Array(byteLength);
1416
+ const view = new DataView(bytes.buffer);
1417
+ for (let i = 0; i < byteLength; i++) {
1418
+ view.setUint8(byteLength - i - 1, Number(value & BigInt(255)));
1419
+ value >>= BigInt(8);
1420
+ }
1421
+ return bytes;
1422
+ }
1423
+
1424
+ // ../../node_modules/@aztec/bb.js/dest/node/types/fields.js
1425
+ var _a;
1426
+ var _b;
1427
+ var Fr = class {
1428
+ constructor(value) {
1429
+ const valueBigInt = typeof value === "bigint" ? value : toBigIntBE(value);
1430
+ if (valueBigInt > _a.MAX_VALUE) {
1431
+ throw new Error(`Value 0x${valueBigInt.toString(16)} is greater or equal to field modulus.`);
1432
+ }
1433
+ this.value = typeof value === "bigint" ? toBufferBE(value) : value;
1434
+ }
1435
+ static random() {
1436
+ const r = toBigIntBE(randomBytes(64)) % _a.MODULUS;
1437
+ return new this(r);
1438
+ }
1439
+ static fromBuffer(buffer) {
1440
+ const reader = BufferReader.asReader(buffer);
1441
+ return new this(reader.readBytes(this.SIZE_IN_BYTES));
1442
+ }
1443
+ static fromBufferReduce(buffer) {
1444
+ const reader = BufferReader.asReader(buffer);
1445
+ return new this(toBigIntBE(reader.readBytes(this.SIZE_IN_BYTES)) % _a.MODULUS);
1446
+ }
1447
+ static fromString(str) {
1448
+ return this.fromBuffer(Buffer.from(str.replace(/^0x/i, ""), "hex"));
1449
+ }
1450
+ toBuffer() {
1451
+ return this.value;
1452
+ }
1453
+ toString() {
1454
+ return "0x" + uint8ArrayToHexString(this.toBuffer());
1455
+ }
1456
+ equals(rhs) {
1457
+ return this.value.every((v, i) => v === rhs.value[i]);
1458
+ }
1459
+ isZero() {
1460
+ return this.value.every((v) => v === 0);
1461
+ }
1462
+ };
1463
+ _a = Fr;
1464
+ Fr.ZERO = new _a(0n);
1465
+ Fr.MODULUS = 0x30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f0000001n;
1466
+ Fr.MAX_VALUE = _a.MODULUS - 1n;
1467
+ Fr.SIZE_IN_BYTES = 32;
1468
+ var Fq = class {
1469
+ constructor(value) {
1470
+ this.value = value;
1471
+ if (value > _b.MAX_VALUE) {
1472
+ throw new Error(`Fq out of range ${value}.`);
1473
+ }
1474
+ }
1475
+ static random() {
1476
+ const r = toBigIntBE(randomBytes(64)) % _b.MODULUS;
1477
+ return new this(r);
1478
+ }
1479
+ static fromBuffer(buffer) {
1480
+ const reader = BufferReader.asReader(buffer);
1481
+ return new this(toBigIntBE(reader.readBytes(this.SIZE_IN_BYTES)));
1482
+ }
1483
+ static fromBufferReduce(buffer) {
1484
+ const reader = BufferReader.asReader(buffer);
1485
+ return new this(toBigIntBE(reader.readBytes(this.SIZE_IN_BYTES)) % Fr.MODULUS);
1486
+ }
1487
+ static fromString(str) {
1488
+ return this.fromBuffer(Buffer.from(str.replace(/^0x/i, ""), "hex"));
1489
+ }
1490
+ toBuffer() {
1491
+ return toBufferBE(this.value, _b.SIZE_IN_BYTES);
1492
+ }
1493
+ toString() {
1494
+ return "0x" + this.value.toString(16);
1495
+ }
1496
+ equals(rhs) {
1497
+ return this.value === rhs.value;
1498
+ }
1499
+ isZero() {
1500
+ return this.value === 0n;
1501
+ }
1502
+ };
1503
+ _b = Fq;
1504
+ Fq.MODULUS = 0x30644e72e131a029b85045b68181585d97816a916871ca8d3c208c16d87cfd47n;
1505
+ Fq.MAX_VALUE = _b.MODULUS - 1n;
1506
+ Fq.SIZE_IN_BYTES = 32;
1507
+
1508
+ // ../../node_modules/@aztec/bb.js/dest/node/types/point.js
1509
+ var Point = class _Point {
1510
+ constructor(x, y) {
1511
+ this.x = x;
1512
+ this.y = y;
1513
+ }
1514
+ static random() {
1515
+ return new _Point(Fr.random(), Fr.random());
1516
+ }
1517
+ static fromBuffer(buffer) {
1518
+ const reader = BufferReader.asReader(buffer);
1519
+ return new this(Fr.fromBuffer(reader), Fr.fromBuffer(reader));
1520
+ }
1521
+ static fromString(address) {
1522
+ return _Point.fromBuffer(Buffer.from(address.replace(/^0x/i, ""), "hex"));
1523
+ }
1524
+ toBuffer() {
1525
+ return Buffer.concat([this.x.toBuffer(), this.y.toBuffer()]);
1526
+ }
1527
+ toString() {
1528
+ return "0x" + this.toBuffer().toString("hex");
1529
+ }
1530
+ equals(rhs) {
1531
+ return this.x.equals(rhs.x) && this.y.equals(rhs.y);
1532
+ }
1533
+ };
1534
+ Point.SIZE_IN_BYTES = 64;
1535
+ Point.EMPTY = new Point(Fr.ZERO, Fr.ZERO);
1536
+
1537
+ // ../../node_modules/@aztec/bb.js/dest/node/types/fixed_size_buffer.js
1538
+ var Buffer32 = class _Buffer32 {
1539
+ constructor(buffer) {
1540
+ this.buffer = buffer;
1541
+ }
1542
+ static fromBuffer(buffer) {
1543
+ const reader = BufferReader.asReader(buffer);
1544
+ return new _Buffer32(reader.readBytes(this.SIZE_IN_BYTES));
1545
+ }
1546
+ static random() {
1547
+ return new _Buffer32(randomBytes(this.SIZE_IN_BYTES));
1548
+ }
1549
+ toBuffer() {
1550
+ return this.buffer;
1551
+ }
1552
+ };
1553
+ Buffer32.SIZE_IN_BYTES = 32;
1554
+ var Buffer64 = class _Buffer64 {
1555
+ constructor(buffer) {
1556
+ this.buffer = buffer;
1557
+ }
1558
+ static fromBuffer(buffer) {
1559
+ const reader = BufferReader.asReader(buffer);
1560
+ return new _Buffer64(reader.readBytes(this.SIZE_IN_BYTES));
1561
+ }
1562
+ static random() {
1563
+ return new _Buffer64(randomBytes(this.SIZE_IN_BYTES));
1564
+ }
1565
+ toBuffer() {
1566
+ return this.buffer;
1567
+ }
1568
+ };
1569
+ Buffer64.SIZE_IN_BYTES = 64;
1570
+ var Buffer128 = class _Buffer128 {
1571
+ constructor(buffer) {
1572
+ this.buffer = buffer;
1573
+ }
1574
+ static fromBuffer(buffer) {
1575
+ const reader = BufferReader.asReader(buffer);
1576
+ return new _Buffer128(reader.readBytes(this.SIZE_IN_BYTES));
1577
+ }
1578
+ static random() {
1579
+ return new _Buffer128(randomBytes(this.SIZE_IN_BYTES));
1580
+ }
1581
+ toBuffer() {
1582
+ return this.buffer;
1583
+ }
1584
+ };
1585
+ Buffer128.SIZE_IN_BYTES = 128;
1586
+
1587
+ // ../../node_modules/@aztec/bb.js/dest/node/barretenberg_api/index.js
1588
+ var BarretenbergApi = class {
1589
+ constructor(wasm) {
1590
+ this.wasm = wasm;
1591
+ }
1592
+ async pedersenCommit(inputsBuffer, ctxIndex) {
1593
+ const inArgs = [inputsBuffer, ctxIndex].map(serializeBufferable);
1594
+ const outTypes = [Point];
1595
+ const result = await this.wasm.callWasmExport("pedersen_commit", inArgs, outTypes.map((t) => t.SIZE_IN_BYTES));
1596
+ const out = result.map((r, i) => outTypes[i].fromBuffer(r));
1597
+ return out[0];
1598
+ }
1599
+ async pedersenHash(inputsBuffer, hashIndex) {
1600
+ const inArgs = [inputsBuffer, hashIndex].map(serializeBufferable);
1601
+ const outTypes = [Fr];
1602
+ const result = await this.wasm.callWasmExport("pedersen_hash", inArgs, outTypes.map((t) => t.SIZE_IN_BYTES));
1603
+ const out = result.map((r, i) => outTypes[i].fromBuffer(r));
1604
+ return out[0];
1605
+ }
1606
+ async pedersenHashes(inputsBuffer, hashIndex) {
1607
+ const inArgs = [inputsBuffer, hashIndex].map(serializeBufferable);
1608
+ const outTypes = [Fr];
1609
+ const result = await this.wasm.callWasmExport("pedersen_hashes", inArgs, outTypes.map((t) => t.SIZE_IN_BYTES));
1610
+ const out = result.map((r, i) => outTypes[i].fromBuffer(r));
1611
+ return out[0];
1612
+ }
1613
+ async pedersenHashBuffer(inputBuffer, hashIndex) {
1614
+ const inArgs = [inputBuffer, hashIndex].map(serializeBufferable);
1615
+ const outTypes = [Fr];
1616
+ const result = await this.wasm.callWasmExport("pedersen_hash_buffer", inArgs, outTypes.map((t) => t.SIZE_IN_BYTES));
1617
+ const out = result.map((r, i) => outTypes[i].fromBuffer(r));
1618
+ return out[0];
1619
+ }
1620
+ async poseidon2Hash(inputsBuffer) {
1621
+ const inArgs = [inputsBuffer].map(serializeBufferable);
1622
+ const outTypes = [Fr];
1623
+ const result = await this.wasm.callWasmExport("poseidon2_hash", inArgs, outTypes.map((t) => t.SIZE_IN_BYTES));
1624
+ const out = result.map((r, i) => outTypes[i].fromBuffer(r));
1625
+ return out[0];
1626
+ }
1627
+ async poseidon2Hashes(inputsBuffer) {
1628
+ const inArgs = [inputsBuffer].map(serializeBufferable);
1629
+ const outTypes = [Fr];
1630
+ const result = await this.wasm.callWasmExport("poseidon2_hashes", inArgs, outTypes.map((t) => t.SIZE_IN_BYTES));
1631
+ const out = result.map((r, i) => outTypes[i].fromBuffer(r));
1632
+ return out[0];
1633
+ }
1634
+ async poseidon2Permutation(inputsBuffer) {
1635
+ const inArgs = [inputsBuffer].map(serializeBufferable);
1636
+ const outTypes = [VectorDeserializer(Fr)];
1637
+ const result = await this.wasm.callWasmExport("poseidon2_permutation", inArgs, outTypes.map((t) => t.SIZE_IN_BYTES));
1638
+ const out = result.map((r, i) => outTypes[i].fromBuffer(r));
1639
+ return out[0];
1640
+ }
1641
+ async blake2s(data) {
1642
+ const inArgs = [data].map(serializeBufferable);
1643
+ const outTypes = [Buffer32];
1644
+ const result = await this.wasm.callWasmExport("blake2s", inArgs, outTypes.map((t) => t.SIZE_IN_BYTES));
1645
+ const out = result.map((r, i) => outTypes[i].fromBuffer(r));
1646
+ return out[0];
1647
+ }
1648
+ async blake2sToField(data) {
1649
+ const inArgs = [data].map(serializeBufferable);
1650
+ const outTypes = [Fr];
1651
+ const result = await this.wasm.callWasmExport("blake2s_to_field_", inArgs, outTypes.map((t) => t.SIZE_IN_BYTES));
1652
+ const out = result.map((r, i) => outTypes[i].fromBuffer(r));
1653
+ return out[0];
1654
+ }
1655
+ async schnorrComputePublicKey(privateKey) {
1656
+ const inArgs = [privateKey].map(serializeBufferable);
1657
+ const outTypes = [Point];
1658
+ const result = await this.wasm.callWasmExport("schnorr_compute_public_key", inArgs, outTypes.map((t) => t.SIZE_IN_BYTES));
1659
+ const out = result.map((r, i) => outTypes[i].fromBuffer(r));
1660
+ return out[0];
1661
+ }
1662
+ async schnorrNegatePublicKey(publicKeyBuffer) {
1663
+ const inArgs = [publicKeyBuffer].map(serializeBufferable);
1664
+ const outTypes = [Point];
1665
+ const result = await this.wasm.callWasmExport("schnorr_negate_public_key", inArgs, outTypes.map((t) => t.SIZE_IN_BYTES));
1666
+ const out = result.map((r, i) => outTypes[i].fromBuffer(r));
1667
+ return out[0];
1668
+ }
1669
+ async schnorrConstructSignature(message, privateKey) {
1670
+ const inArgs = [message, privateKey].map(serializeBufferable);
1671
+ const outTypes = [Buffer32, Buffer32];
1672
+ const result = await this.wasm.callWasmExport("schnorr_construct_signature", inArgs, outTypes.map((t) => t.SIZE_IN_BYTES));
1673
+ const out = result.map((r, i) => outTypes[i].fromBuffer(r));
1674
+ return out;
1675
+ }
1676
+ async schnorrVerifySignature(message, pubKey, sigS, sigE) {
1677
+ const inArgs = [message, pubKey, sigS, sigE].map(serializeBufferable);
1678
+ const outTypes = [BoolDeserializer()];
1679
+ const result = await this.wasm.callWasmExport("schnorr_verify_signature", inArgs, outTypes.map((t) => t.SIZE_IN_BYTES));
1680
+ const out = result.map((r, i) => outTypes[i].fromBuffer(r));
1681
+ return out[0];
1682
+ }
1683
+ async schnorrMultisigCreateMultisigPublicKey(privateKey) {
1684
+ const inArgs = [privateKey].map(serializeBufferable);
1685
+ const outTypes = [Buffer128];
1686
+ const result = await this.wasm.callWasmExport("schnorr_multisig_create_multisig_public_key", inArgs, outTypes.map((t) => t.SIZE_IN_BYTES));
1687
+ const out = result.map((r, i) => outTypes[i].fromBuffer(r));
1688
+ return out[0];
1689
+ }
1690
+ async schnorrMultisigValidateAndCombineSignerPubkeys(signerPubkeyBuf) {
1691
+ const inArgs = [signerPubkeyBuf].map(serializeBufferable);
1692
+ const outTypes = [Point, BoolDeserializer()];
1693
+ const result = await this.wasm.callWasmExport("schnorr_multisig_validate_and_combine_signer_pubkeys", inArgs, outTypes.map((t) => t.SIZE_IN_BYTES));
1694
+ const out = result.map((r, i) => outTypes[i].fromBuffer(r));
1695
+ return out;
1696
+ }
1697
+ async schnorrMultisigConstructSignatureRound1() {
1698
+ const inArgs = [].map(serializeBufferable);
1699
+ const outTypes = [Buffer128, Buffer128];
1700
+ const result = await this.wasm.callWasmExport("schnorr_multisig_construct_signature_round_1", inArgs, outTypes.map((t) => t.SIZE_IN_BYTES));
1701
+ const out = result.map((r, i) => outTypes[i].fromBuffer(r));
1702
+ return out;
1703
+ }
1704
+ async schnorrMultisigConstructSignatureRound2(message, privateKey, signerRoundOnePrivateBuf, signerPubkeysBuf, roundOnePublicBuf) {
1705
+ const inArgs = [message, privateKey, signerRoundOnePrivateBuf, signerPubkeysBuf, roundOnePublicBuf].map(serializeBufferable);
1706
+ const outTypes = [Fq, BoolDeserializer()];
1707
+ const result = await this.wasm.callWasmExport("schnorr_multisig_construct_signature_round_2", inArgs, outTypes.map((t) => t.SIZE_IN_BYTES));
1708
+ const out = result.map((r, i) => outTypes[i].fromBuffer(r));
1709
+ return out;
1710
+ }
1711
+ async schnorrMultisigCombineSignatures(message, signerPubkeysBuf, roundOneBuf, roundTwoBuf) {
1712
+ const inArgs = [message, signerPubkeysBuf, roundOneBuf, roundTwoBuf].map(serializeBufferable);
1713
+ const outTypes = [Buffer32, Buffer32, BoolDeserializer()];
1714
+ const result = await this.wasm.callWasmExport("schnorr_multisig_combine_signatures", inArgs, outTypes.map((t) => t.SIZE_IN_BYTES));
1715
+ const out = result.map((r, i) => outTypes[i].fromBuffer(r));
1716
+ return out;
1717
+ }
1718
+ async aesEncryptBufferCbc(input, iv, key, length) {
1719
+ const inArgs = [input, iv, key, length].map(serializeBufferable);
1720
+ const outTypes = [BufferDeserializer()];
1721
+ const result = await this.wasm.callWasmExport("aes_encrypt_buffer_cbc", inArgs, outTypes.map((t) => t.SIZE_IN_BYTES));
1722
+ const out = result.map((r, i) => outTypes[i].fromBuffer(r));
1723
+ return out[0];
1724
+ }
1725
+ async aesDecryptBufferCbc(input, iv, key, length) {
1726
+ const inArgs = [input, iv, key, length].map(serializeBufferable);
1727
+ const outTypes = [BufferDeserializer()];
1728
+ const result = await this.wasm.callWasmExport("aes_decrypt_buffer_cbc", inArgs, outTypes.map((t) => t.SIZE_IN_BYTES));
1729
+ const out = result.map((r, i) => outTypes[i].fromBuffer(r));
1730
+ return out[0];
1731
+ }
1732
+ async srsInitSrs(pointsBuf, numPoints, g2PointBuf) {
1733
+ const inArgs = [pointsBuf, numPoints, g2PointBuf].map(serializeBufferable);
1734
+ const outTypes = [];
1735
+ const result = await this.wasm.callWasmExport("srs_init_srs", inArgs, outTypes.map((t) => t.SIZE_IN_BYTES));
1736
+ const out = result.map((r, i) => outTypes[i].fromBuffer(r));
1737
+ return;
1738
+ }
1739
+ async srsInitGrumpkinSrs(pointsBuf, numPoints) {
1740
+ const inArgs = [pointsBuf, numPoints].map(serializeBufferable);
1741
+ const outTypes = [];
1742
+ const result = await this.wasm.callWasmExport("srs_init_grumpkin_srs", inArgs, outTypes.map((t) => t.SIZE_IN_BYTES));
1743
+ const out = result.map((r, i) => outTypes[i].fromBuffer(r));
1744
+ return;
1745
+ }
1746
+ async examplesSimpleCreateAndVerifyProof() {
1747
+ const inArgs = [].map(serializeBufferable);
1748
+ const outTypes = [BoolDeserializer()];
1749
+ const result = await this.wasm.callWasmExport("examples_simple_create_and_verify_proof", inArgs, outTypes.map((t) => t.SIZE_IN_BYTES));
1750
+ const out = result.map((r, i) => outTypes[i].fromBuffer(r));
1751
+ return out[0];
1752
+ }
1753
+ async testThreads(threads, iterations) {
1754
+ const inArgs = [threads, iterations].map(serializeBufferable);
1755
+ const outTypes = [NumberDeserializer()];
1756
+ const result = await this.wasm.callWasmExport("test_threads", inArgs, outTypes.map((t) => t.SIZE_IN_BYTES));
1757
+ const out = result.map((r, i) => outTypes[i].fromBuffer(r));
1758
+ return out[0];
1759
+ }
1760
+ async commonInitSlabAllocator(circuitSize) {
1761
+ const inArgs = [circuitSize].map(serializeBufferable);
1762
+ const outTypes = [];
1763
+ const result = await this.wasm.callWasmExport("common_init_slab_allocator", inArgs, outTypes.map((t) => t.SIZE_IN_BYTES));
1764
+ const out = result.map((r, i) => outTypes[i].fromBuffer(r));
1765
+ return;
1766
+ }
1767
+ async acirGetCircuitSizes(constraintSystemBuf, honkRecursion) {
1768
+ const inArgs = [constraintSystemBuf, honkRecursion].map(serializeBufferable);
1769
+ const outTypes = [NumberDeserializer(), NumberDeserializer()];
1770
+ const result = await this.wasm.callWasmExport("acir_get_circuit_sizes", inArgs, outTypes.map((t) => t.SIZE_IN_BYTES));
1771
+ const out = result.map((r, i) => outTypes[i].fromBuffer(r));
1772
+ return out;
1773
+ }
1774
+ async acirNewAcirComposer(sizeHint) {
1775
+ const inArgs = [sizeHint].map(serializeBufferable);
1776
+ const outTypes = [Ptr];
1777
+ const result = await this.wasm.callWasmExport("acir_new_acir_composer", inArgs, outTypes.map((t) => t.SIZE_IN_BYTES));
1778
+ const out = result.map((r, i) => outTypes[i].fromBuffer(r));
1779
+ return out[0];
1780
+ }
1781
+ async acirDeleteAcirComposer(acirComposerPtr) {
1782
+ const inArgs = [acirComposerPtr].map(serializeBufferable);
1783
+ const outTypes = [];
1784
+ const result = await this.wasm.callWasmExport("acir_delete_acir_composer", inArgs, outTypes.map((t) => t.SIZE_IN_BYTES));
1785
+ const out = result.map((r, i) => outTypes[i].fromBuffer(r));
1786
+ return;
1787
+ }
1788
+ async acirInitProvingKey(acirComposerPtr, constraintSystemBuf) {
1789
+ const inArgs = [acirComposerPtr, constraintSystemBuf].map(serializeBufferable);
1790
+ const outTypes = [];
1791
+ const result = await this.wasm.callWasmExport("acir_init_proving_key", inArgs, outTypes.map((t) => t.SIZE_IN_BYTES));
1792
+ const out = result.map((r, i) => outTypes[i].fromBuffer(r));
1793
+ return;
1794
+ }
1795
+ async acirCreateProof(acirComposerPtr, constraintSystemBuf, witnessBuf) {
1796
+ const inArgs = [acirComposerPtr, constraintSystemBuf, witnessBuf].map(serializeBufferable);
1797
+ const outTypes = [BufferDeserializer()];
1798
+ const result = await this.wasm.callWasmExport("acir_create_proof", inArgs, outTypes.map((t) => t.SIZE_IN_BYTES));
1799
+ const out = result.map((r, i) => outTypes[i].fromBuffer(r));
1800
+ return out[0];
1801
+ }
1802
+ async acirProveAndVerifyUltraHonk(constraintSystemBuf, witnessBuf) {
1803
+ const inArgs = [constraintSystemBuf, witnessBuf].map(serializeBufferable);
1804
+ const outTypes = [BoolDeserializer()];
1805
+ const result = await this.wasm.callWasmExport("acir_prove_and_verify_ultra_honk", inArgs, outTypes.map((t) => t.SIZE_IN_BYTES));
1806
+ const out = result.map((r, i) => outTypes[i].fromBuffer(r));
1807
+ return out[0];
1808
+ }
1809
+ async acirProveAndVerifyMegaHonk(constraintSystemBuf, witnessBuf) {
1810
+ const inArgs = [constraintSystemBuf, witnessBuf].map(serializeBufferable);
1811
+ const outTypes = [BoolDeserializer()];
1812
+ const result = await this.wasm.callWasmExport("acir_prove_and_verify_mega_honk", inArgs, outTypes.map((t) => t.SIZE_IN_BYTES));
1813
+ const out = result.map((r, i) => outTypes[i].fromBuffer(r));
1814
+ return out[0];
1815
+ }
1816
+ async acirFoldAndVerifyProgramStack(constraintSystemBuf, witnessBuf) {
1817
+ const inArgs = [constraintSystemBuf, witnessBuf].map(serializeBufferable);
1818
+ const outTypes = [BoolDeserializer()];
1819
+ const result = await this.wasm.callWasmExport("acir_fold_and_verify_program_stack", inArgs, outTypes.map((t) => t.SIZE_IN_BYTES));
1820
+ const out = result.map((r, i) => outTypes[i].fromBuffer(r));
1821
+ return out[0];
1822
+ }
1823
+ async acirLoadVerificationKey(acirComposerPtr, vkBuf) {
1824
+ const inArgs = [acirComposerPtr, vkBuf].map(serializeBufferable);
1825
+ const outTypes = [];
1826
+ const result = await this.wasm.callWasmExport("acir_load_verification_key", inArgs, outTypes.map((t) => t.SIZE_IN_BYTES));
1827
+ const out = result.map((r, i) => outTypes[i].fromBuffer(r));
1828
+ return;
1829
+ }
1830
+ async acirInitVerificationKey(acirComposerPtr) {
1831
+ const inArgs = [acirComposerPtr].map(serializeBufferable);
1832
+ const outTypes = [];
1833
+ const result = await this.wasm.callWasmExport("acir_init_verification_key", inArgs, outTypes.map((t) => t.SIZE_IN_BYTES));
1834
+ const out = result.map((r, i) => outTypes[i].fromBuffer(r));
1835
+ return;
1836
+ }
1837
+ async acirGetVerificationKey(acirComposerPtr) {
1838
+ const inArgs = [acirComposerPtr].map(serializeBufferable);
1839
+ const outTypes = [BufferDeserializer()];
1840
+ const result = await this.wasm.callWasmExport("acir_get_verification_key", inArgs, outTypes.map((t) => t.SIZE_IN_BYTES));
1841
+ const out = result.map((r, i) => outTypes[i].fromBuffer(r));
1842
+ return out[0];
1843
+ }
1844
+ async acirGetProvingKey(acirComposerPtr, acirVec) {
1845
+ const inArgs = [acirComposerPtr, acirVec].map(serializeBufferable);
1846
+ const outTypes = [BufferDeserializer()];
1847
+ const result = await this.wasm.callWasmExport("acir_get_proving_key", inArgs, outTypes.map((t) => t.SIZE_IN_BYTES));
1848
+ const out = result.map((r, i) => outTypes[i].fromBuffer(r));
1849
+ return out[0];
1850
+ }
1851
+ async acirVerifyProof(acirComposerPtr, proofBuf) {
1852
+ const inArgs = [acirComposerPtr, proofBuf].map(serializeBufferable);
1853
+ const outTypes = [BoolDeserializer()];
1854
+ const result = await this.wasm.callWasmExport("acir_verify_proof", inArgs, outTypes.map((t) => t.SIZE_IN_BYTES));
1855
+ const out = result.map((r, i) => outTypes[i].fromBuffer(r));
1856
+ return out[0];
1857
+ }
1858
+ async acirGetSolidityVerifier(acirComposerPtr) {
1859
+ const inArgs = [acirComposerPtr].map(serializeBufferable);
1860
+ const outTypes = [StringDeserializer()];
1861
+ const result = await this.wasm.callWasmExport("acir_get_solidity_verifier", inArgs, outTypes.map((t) => t.SIZE_IN_BYTES));
1862
+ const out = result.map((r, i) => outTypes[i].fromBuffer(r));
1863
+ return out[0];
1864
+ }
1865
+ async acirSerializeProofIntoFields(acirComposerPtr, proofBuf, numInnerPublicInputs) {
1866
+ const inArgs = [acirComposerPtr, proofBuf, numInnerPublicInputs].map(serializeBufferable);
1867
+ const outTypes = [VectorDeserializer(Fr)];
1868
+ const result = await this.wasm.callWasmExport("acir_serialize_proof_into_fields", inArgs, outTypes.map((t) => t.SIZE_IN_BYTES));
1869
+ const out = result.map((r, i) => outTypes[i].fromBuffer(r));
1870
+ return out[0];
1871
+ }
1872
+ async acirSerializeVerificationKeyIntoFields(acirComposerPtr) {
1873
+ const inArgs = [acirComposerPtr].map(serializeBufferable);
1874
+ const outTypes = [VectorDeserializer(Fr), Fr];
1875
+ const result = await this.wasm.callWasmExport("acir_serialize_verification_key_into_fields", inArgs, outTypes.map((t) => t.SIZE_IN_BYTES));
1876
+ const out = result.map((r, i) => outTypes[i].fromBuffer(r));
1877
+ return out;
1878
+ }
1879
+ async acirProveUltraHonk(acirVec, witnessVec) {
1880
+ const inArgs = [acirVec, witnessVec].map(serializeBufferable);
1881
+ const outTypes = [BufferDeserializer()];
1882
+ const result = await this.wasm.callWasmExport("acir_prove_ultra_honk", inArgs, outTypes.map((t) => t.SIZE_IN_BYTES));
1883
+ const out = result.map((r, i) => outTypes[i].fromBuffer(r));
1884
+ return out[0];
1885
+ }
1886
+ async acirVerifyUltraHonk(proofBuf, vkBuf) {
1887
+ const inArgs = [proofBuf, vkBuf].map(serializeBufferable);
1888
+ const outTypes = [BoolDeserializer()];
1889
+ const result = await this.wasm.callWasmExport("acir_verify_ultra_honk", inArgs, outTypes.map((t) => t.SIZE_IN_BYTES));
1890
+ const out = result.map((r, i) => outTypes[i].fromBuffer(r));
1891
+ return out[0];
1892
+ }
1893
+ async acirWriteVkUltraHonk(acirVec) {
1894
+ const inArgs = [acirVec].map(serializeBufferable);
1895
+ const outTypes = [BufferDeserializer()];
1896
+ const result = await this.wasm.callWasmExport("acir_write_vk_ultra_honk", inArgs, outTypes.map((t) => t.SIZE_IN_BYTES));
1897
+ const out = result.map((r, i) => outTypes[i].fromBuffer(r));
1898
+ return out[0];
1899
+ }
1900
+ async acirProofAsFieldsUltraHonk(proofBuf) {
1901
+ const inArgs = [proofBuf].map(serializeBufferable);
1902
+ const outTypes = [VectorDeserializer(Fr)];
1903
+ const result = await this.wasm.callWasmExport("acir_proof_as_fields_ultra_honk", inArgs, outTypes.map((t) => t.SIZE_IN_BYTES));
1904
+ const out = result.map((r, i) => outTypes[i].fromBuffer(r));
1905
+ return out[0];
1906
+ }
1907
+ async acirVkAsFieldsUltraHonk(vkBuf) {
1908
+ const inArgs = [vkBuf].map(serializeBufferable);
1909
+ const outTypes = [VectorDeserializer(Fr)];
1910
+ const result = await this.wasm.callWasmExport("acir_vk_as_fields_ultra_honk", inArgs, outTypes.map((t) => t.SIZE_IN_BYTES));
1911
+ const out = result.map((r, i) => outTypes[i].fromBuffer(r));
1912
+ return out[0];
1913
+ }
1914
+ };
1915
+ var BarretenbergApiSync = class {
1916
+ constructor(wasm) {
1917
+ this.wasm = wasm;
1918
+ }
1919
+ pedersenCommit(inputsBuffer, ctxIndex) {
1920
+ const inArgs = [inputsBuffer, ctxIndex].map(serializeBufferable);
1921
+ const outTypes = [Point];
1922
+ const result = this.wasm.callWasmExport("pedersen_commit", inArgs, outTypes.map((t) => t.SIZE_IN_BYTES));
1923
+ const out = result.map((r, i) => outTypes[i].fromBuffer(r));
1924
+ return out[0];
1925
+ }
1926
+ pedersenHash(inputsBuffer, hashIndex) {
1927
+ const inArgs = [inputsBuffer, hashIndex].map(serializeBufferable);
1928
+ const outTypes = [Fr];
1929
+ const result = this.wasm.callWasmExport("pedersen_hash", inArgs, outTypes.map((t) => t.SIZE_IN_BYTES));
1930
+ const out = result.map((r, i) => outTypes[i].fromBuffer(r));
1931
+ return out[0];
1932
+ }
1933
+ pedersenHashes(inputsBuffer, hashIndex) {
1934
+ const inArgs = [inputsBuffer, hashIndex].map(serializeBufferable);
1935
+ const outTypes = [Fr];
1936
+ const result = this.wasm.callWasmExport("pedersen_hashes", inArgs, outTypes.map((t) => t.SIZE_IN_BYTES));
1937
+ const out = result.map((r, i) => outTypes[i].fromBuffer(r));
1938
+ return out[0];
1939
+ }
1940
+ pedersenHashBuffer(inputBuffer, hashIndex) {
1941
+ const inArgs = [inputBuffer, hashIndex].map(serializeBufferable);
1942
+ const outTypes = [Fr];
1943
+ const result = this.wasm.callWasmExport("pedersen_hash_buffer", inArgs, outTypes.map((t) => t.SIZE_IN_BYTES));
1944
+ const out = result.map((r, i) => outTypes[i].fromBuffer(r));
1945
+ return out[0];
1946
+ }
1947
+ poseidon2Hash(inputsBuffer) {
1948
+ const inArgs = [inputsBuffer].map(serializeBufferable);
1949
+ const outTypes = [Fr];
1950
+ const result = this.wasm.callWasmExport("poseidon2_hash", inArgs, outTypes.map((t) => t.SIZE_IN_BYTES));
1951
+ const out = result.map((r, i) => outTypes[i].fromBuffer(r));
1952
+ return out[0];
1953
+ }
1954
+ poseidon2Hashes(inputsBuffer) {
1955
+ const inArgs = [inputsBuffer].map(serializeBufferable);
1956
+ const outTypes = [Fr];
1957
+ const result = this.wasm.callWasmExport("poseidon2_hashes", inArgs, outTypes.map((t) => t.SIZE_IN_BYTES));
1958
+ const out = result.map((r, i) => outTypes[i].fromBuffer(r));
1959
+ return out[0];
1960
+ }
1961
+ poseidon2Permutation(inputsBuffer) {
1962
+ const inArgs = [inputsBuffer].map(serializeBufferable);
1963
+ const outTypes = [VectorDeserializer(Fr)];
1964
+ const result = this.wasm.callWasmExport("poseidon2_permutation", inArgs, outTypes.map((t) => t.SIZE_IN_BYTES));
1965
+ const out = result.map((r, i) => outTypes[i].fromBuffer(r));
1966
+ return out[0];
1967
+ }
1968
+ blake2s(data) {
1969
+ const inArgs = [data].map(serializeBufferable);
1970
+ const outTypes = [Buffer32];
1971
+ const result = this.wasm.callWasmExport("blake2s", inArgs, outTypes.map((t) => t.SIZE_IN_BYTES));
1972
+ const out = result.map((r, i) => outTypes[i].fromBuffer(r));
1973
+ return out[0];
1974
+ }
1975
+ blake2sToField(data) {
1976
+ const inArgs = [data].map(serializeBufferable);
1977
+ const outTypes = [Fr];
1978
+ const result = this.wasm.callWasmExport("blake2s_to_field_", inArgs, outTypes.map((t) => t.SIZE_IN_BYTES));
1979
+ const out = result.map((r, i) => outTypes[i].fromBuffer(r));
1980
+ return out[0];
1981
+ }
1982
+ schnorrComputePublicKey(privateKey) {
1983
+ const inArgs = [privateKey].map(serializeBufferable);
1984
+ const outTypes = [Point];
1985
+ const result = this.wasm.callWasmExport("schnorr_compute_public_key", inArgs, outTypes.map((t) => t.SIZE_IN_BYTES));
1986
+ const out = result.map((r, i) => outTypes[i].fromBuffer(r));
1987
+ return out[0];
1988
+ }
1989
+ schnorrNegatePublicKey(publicKeyBuffer) {
1990
+ const inArgs = [publicKeyBuffer].map(serializeBufferable);
1991
+ const outTypes = [Point];
1992
+ const result = this.wasm.callWasmExport("schnorr_negate_public_key", inArgs, outTypes.map((t) => t.SIZE_IN_BYTES));
1993
+ const out = result.map((r, i) => outTypes[i].fromBuffer(r));
1994
+ return out[0];
1995
+ }
1996
+ schnorrConstructSignature(message, privateKey) {
1997
+ const inArgs = [message, privateKey].map(serializeBufferable);
1998
+ const outTypes = [Buffer32, Buffer32];
1999
+ const result = this.wasm.callWasmExport("schnorr_construct_signature", inArgs, outTypes.map((t) => t.SIZE_IN_BYTES));
2000
+ const out = result.map((r, i) => outTypes[i].fromBuffer(r));
2001
+ return out;
2002
+ }
2003
+ schnorrVerifySignature(message, pubKey, sigS, sigE) {
2004
+ const inArgs = [message, pubKey, sigS, sigE].map(serializeBufferable);
2005
+ const outTypes = [BoolDeserializer()];
2006
+ const result = this.wasm.callWasmExport("schnorr_verify_signature", inArgs, outTypes.map((t) => t.SIZE_IN_BYTES));
2007
+ const out = result.map((r, i) => outTypes[i].fromBuffer(r));
2008
+ return out[0];
2009
+ }
2010
+ schnorrMultisigCreateMultisigPublicKey(privateKey) {
2011
+ const inArgs = [privateKey].map(serializeBufferable);
2012
+ const outTypes = [Buffer128];
2013
+ const result = this.wasm.callWasmExport("schnorr_multisig_create_multisig_public_key", inArgs, outTypes.map((t) => t.SIZE_IN_BYTES));
2014
+ const out = result.map((r, i) => outTypes[i].fromBuffer(r));
2015
+ return out[0];
2016
+ }
2017
+ schnorrMultisigValidateAndCombineSignerPubkeys(signerPubkeyBuf) {
2018
+ const inArgs = [signerPubkeyBuf].map(serializeBufferable);
2019
+ const outTypes = [Point, BoolDeserializer()];
2020
+ const result = this.wasm.callWasmExport("schnorr_multisig_validate_and_combine_signer_pubkeys", inArgs, outTypes.map((t) => t.SIZE_IN_BYTES));
2021
+ const out = result.map((r, i) => outTypes[i].fromBuffer(r));
2022
+ return out;
2023
+ }
2024
+ schnorrMultisigConstructSignatureRound1() {
2025
+ const inArgs = [].map(serializeBufferable);
2026
+ const outTypes = [Buffer128, Buffer128];
2027
+ const result = this.wasm.callWasmExport("schnorr_multisig_construct_signature_round_1", inArgs, outTypes.map((t) => t.SIZE_IN_BYTES));
2028
+ const out = result.map((r, i) => outTypes[i].fromBuffer(r));
2029
+ return out;
2030
+ }
2031
+ schnorrMultisigConstructSignatureRound2(message, privateKey, signerRoundOnePrivateBuf, signerPubkeysBuf, roundOnePublicBuf) {
2032
+ const inArgs = [message, privateKey, signerRoundOnePrivateBuf, signerPubkeysBuf, roundOnePublicBuf].map(serializeBufferable);
2033
+ const outTypes = [Fq, BoolDeserializer()];
2034
+ const result = this.wasm.callWasmExport("schnorr_multisig_construct_signature_round_2", inArgs, outTypes.map((t) => t.SIZE_IN_BYTES));
2035
+ const out = result.map((r, i) => outTypes[i].fromBuffer(r));
2036
+ return out;
2037
+ }
2038
+ schnorrMultisigCombineSignatures(message, signerPubkeysBuf, roundOneBuf, roundTwoBuf) {
2039
+ const inArgs = [message, signerPubkeysBuf, roundOneBuf, roundTwoBuf].map(serializeBufferable);
2040
+ const outTypes = [Buffer32, Buffer32, BoolDeserializer()];
2041
+ const result = this.wasm.callWasmExport("schnorr_multisig_combine_signatures", inArgs, outTypes.map((t) => t.SIZE_IN_BYTES));
2042
+ const out = result.map((r, i) => outTypes[i].fromBuffer(r));
2043
+ return out;
2044
+ }
2045
+ aesEncryptBufferCbc(input, iv, key, length) {
2046
+ const inArgs = [input, iv, key, length].map(serializeBufferable);
2047
+ const outTypes = [BufferDeserializer()];
2048
+ const result = this.wasm.callWasmExport("aes_encrypt_buffer_cbc", inArgs, outTypes.map((t) => t.SIZE_IN_BYTES));
2049
+ const out = result.map((r, i) => outTypes[i].fromBuffer(r));
2050
+ return out[0];
2051
+ }
2052
+ aesDecryptBufferCbc(input, iv, key, length) {
2053
+ const inArgs = [input, iv, key, length].map(serializeBufferable);
2054
+ const outTypes = [BufferDeserializer()];
2055
+ const result = this.wasm.callWasmExport("aes_decrypt_buffer_cbc", inArgs, outTypes.map((t) => t.SIZE_IN_BYTES));
2056
+ const out = result.map((r, i) => outTypes[i].fromBuffer(r));
2057
+ return out[0];
2058
+ }
2059
+ srsInitSrs(pointsBuf, numPoints, g2PointBuf) {
2060
+ const inArgs = [pointsBuf, numPoints, g2PointBuf].map(serializeBufferable);
2061
+ const outTypes = [];
2062
+ const result = this.wasm.callWasmExport("srs_init_srs", inArgs, outTypes.map((t) => t.SIZE_IN_BYTES));
2063
+ const out = result.map((r, i) => outTypes[i].fromBuffer(r));
2064
+ return;
2065
+ }
2066
+ srsInitGrumpkinSrs(pointsBuf, numPoints) {
2067
+ const inArgs = [pointsBuf, numPoints].map(serializeBufferable);
2068
+ const outTypes = [];
2069
+ const result = this.wasm.callWasmExport("srs_init_grumpkin_srs", inArgs, outTypes.map((t) => t.SIZE_IN_BYTES));
2070
+ const out = result.map((r, i) => outTypes[i].fromBuffer(r));
2071
+ return;
2072
+ }
2073
+ examplesSimpleCreateAndVerifyProof() {
2074
+ const inArgs = [].map(serializeBufferable);
2075
+ const outTypes = [BoolDeserializer()];
2076
+ const result = this.wasm.callWasmExport("examples_simple_create_and_verify_proof", inArgs, outTypes.map((t) => t.SIZE_IN_BYTES));
2077
+ const out = result.map((r, i) => outTypes[i].fromBuffer(r));
2078
+ return out[0];
2079
+ }
2080
+ testThreads(threads, iterations) {
2081
+ const inArgs = [threads, iterations].map(serializeBufferable);
2082
+ const outTypes = [NumberDeserializer()];
2083
+ const result = this.wasm.callWasmExport("test_threads", inArgs, outTypes.map((t) => t.SIZE_IN_BYTES));
2084
+ const out = result.map((r, i) => outTypes[i].fromBuffer(r));
2085
+ return out[0];
2086
+ }
2087
+ commonInitSlabAllocator(circuitSize) {
2088
+ const inArgs = [circuitSize].map(serializeBufferable);
2089
+ const outTypes = [];
2090
+ const result = this.wasm.callWasmExport("common_init_slab_allocator", inArgs, outTypes.map((t) => t.SIZE_IN_BYTES));
2091
+ const out = result.map((r, i) => outTypes[i].fromBuffer(r));
2092
+ return;
2093
+ }
2094
+ acirGetCircuitSizes(constraintSystemBuf, honkRecursion) {
2095
+ const inArgs = [constraintSystemBuf, honkRecursion].map(serializeBufferable);
2096
+ const outTypes = [NumberDeserializer(), NumberDeserializer()];
2097
+ const result = this.wasm.callWasmExport("acir_get_circuit_sizes", inArgs, outTypes.map((t) => t.SIZE_IN_BYTES));
2098
+ const out = result.map((r, i) => outTypes[i].fromBuffer(r));
2099
+ return out;
2100
+ }
2101
+ acirNewAcirComposer(sizeHint) {
2102
+ const inArgs = [sizeHint].map(serializeBufferable);
2103
+ const outTypes = [Ptr];
2104
+ const result = this.wasm.callWasmExport("acir_new_acir_composer", inArgs, outTypes.map((t) => t.SIZE_IN_BYTES));
2105
+ const out = result.map((r, i) => outTypes[i].fromBuffer(r));
2106
+ return out[0];
2107
+ }
2108
+ acirDeleteAcirComposer(acirComposerPtr) {
2109
+ const inArgs = [acirComposerPtr].map(serializeBufferable);
2110
+ const outTypes = [];
2111
+ const result = this.wasm.callWasmExport("acir_delete_acir_composer", inArgs, outTypes.map((t) => t.SIZE_IN_BYTES));
2112
+ const out = result.map((r, i) => outTypes[i].fromBuffer(r));
2113
+ return;
2114
+ }
2115
+ acirInitProvingKey(acirComposerPtr, constraintSystemBuf) {
2116
+ const inArgs = [acirComposerPtr, constraintSystemBuf].map(serializeBufferable);
2117
+ const outTypes = [];
2118
+ const result = this.wasm.callWasmExport("acir_init_proving_key", inArgs, outTypes.map((t) => t.SIZE_IN_BYTES));
2119
+ const out = result.map((r, i) => outTypes[i].fromBuffer(r));
2120
+ return;
2121
+ }
2122
+ acirCreateProof(acirComposerPtr, constraintSystemBuf, witnessBuf) {
2123
+ const inArgs = [acirComposerPtr, constraintSystemBuf, witnessBuf].map(serializeBufferable);
2124
+ const outTypes = [BufferDeserializer()];
2125
+ const result = this.wasm.callWasmExport("acir_create_proof", inArgs, outTypes.map((t) => t.SIZE_IN_BYTES));
2126
+ const out = result.map((r, i) => outTypes[i].fromBuffer(r));
2127
+ return out[0];
2128
+ }
2129
+ acirProveAndVerifyUltraHonk(constraintSystemBuf, witnessBuf) {
2130
+ const inArgs = [constraintSystemBuf, witnessBuf].map(serializeBufferable);
2131
+ const outTypes = [BoolDeserializer()];
2132
+ const result = this.wasm.callWasmExport("acir_prove_and_verify_ultra_honk", inArgs, outTypes.map((t) => t.SIZE_IN_BYTES));
2133
+ const out = result.map((r, i) => outTypes[i].fromBuffer(r));
2134
+ return out[0];
2135
+ }
2136
+ acirProveAndVerifyMegaHonk(constraintSystemBuf, witnessBuf) {
2137
+ const inArgs = [constraintSystemBuf, witnessBuf].map(serializeBufferable);
2138
+ const outTypes = [BoolDeserializer()];
2139
+ const result = this.wasm.callWasmExport("acir_prove_and_verify_mega_honk", inArgs, outTypes.map((t) => t.SIZE_IN_BYTES));
2140
+ const out = result.map((r, i) => outTypes[i].fromBuffer(r));
2141
+ return out[0];
2142
+ }
2143
+ acirFoldAndVerifyProgramStack(constraintSystemBuf, witnessBuf) {
2144
+ const inArgs = [constraintSystemBuf, witnessBuf].map(serializeBufferable);
2145
+ const outTypes = [BoolDeserializer()];
2146
+ const result = this.wasm.callWasmExport("acir_fold_and_verify_program_stack", inArgs, outTypes.map((t) => t.SIZE_IN_BYTES));
2147
+ const out = result.map((r, i) => outTypes[i].fromBuffer(r));
2148
+ return out[0];
2149
+ }
2150
+ acirLoadVerificationKey(acirComposerPtr, vkBuf) {
2151
+ const inArgs = [acirComposerPtr, vkBuf].map(serializeBufferable);
2152
+ const outTypes = [];
2153
+ const result = this.wasm.callWasmExport("acir_load_verification_key", inArgs, outTypes.map((t) => t.SIZE_IN_BYTES));
2154
+ const out = result.map((r, i) => outTypes[i].fromBuffer(r));
2155
+ return;
2156
+ }
2157
+ acirInitVerificationKey(acirComposerPtr) {
2158
+ const inArgs = [acirComposerPtr].map(serializeBufferable);
2159
+ const outTypes = [];
2160
+ const result = this.wasm.callWasmExport("acir_init_verification_key", inArgs, outTypes.map((t) => t.SIZE_IN_BYTES));
2161
+ const out = result.map((r, i) => outTypes[i].fromBuffer(r));
2162
+ return;
2163
+ }
2164
+ acirGetVerificationKey(acirComposerPtr) {
2165
+ const inArgs = [acirComposerPtr].map(serializeBufferable);
2166
+ const outTypes = [BufferDeserializer()];
2167
+ const result = this.wasm.callWasmExport("acir_get_verification_key", inArgs, outTypes.map((t) => t.SIZE_IN_BYTES));
2168
+ const out = result.map((r, i) => outTypes[i].fromBuffer(r));
2169
+ return out[0];
2170
+ }
2171
+ acirGetProvingKey(acirComposerPtr, acirVec) {
2172
+ const inArgs = [acirComposerPtr, acirVec].map(serializeBufferable);
2173
+ const outTypes = [BufferDeserializer()];
2174
+ const result = this.wasm.callWasmExport("acir_get_proving_key", inArgs, outTypes.map((t) => t.SIZE_IN_BYTES));
2175
+ const out = result.map((r, i) => outTypes[i].fromBuffer(r));
2176
+ return out[0];
2177
+ }
2178
+ acirVerifyProof(acirComposerPtr, proofBuf) {
2179
+ const inArgs = [acirComposerPtr, proofBuf].map(serializeBufferable);
2180
+ const outTypes = [BoolDeserializer()];
2181
+ const result = this.wasm.callWasmExport("acir_verify_proof", inArgs, outTypes.map((t) => t.SIZE_IN_BYTES));
2182
+ const out = result.map((r, i) => outTypes[i].fromBuffer(r));
2183
+ return out[0];
2184
+ }
2185
+ acirGetSolidityVerifier(acirComposerPtr) {
2186
+ const inArgs = [acirComposerPtr].map(serializeBufferable);
2187
+ const outTypes = [StringDeserializer()];
2188
+ const result = this.wasm.callWasmExport("acir_get_solidity_verifier", inArgs, outTypes.map((t) => t.SIZE_IN_BYTES));
2189
+ const out = result.map((r, i) => outTypes[i].fromBuffer(r));
2190
+ return out[0];
2191
+ }
2192
+ acirSerializeProofIntoFields(acirComposerPtr, proofBuf, numInnerPublicInputs) {
2193
+ const inArgs = [acirComposerPtr, proofBuf, numInnerPublicInputs].map(serializeBufferable);
2194
+ const outTypes = [VectorDeserializer(Fr)];
2195
+ const result = this.wasm.callWasmExport("acir_serialize_proof_into_fields", inArgs, outTypes.map((t) => t.SIZE_IN_BYTES));
2196
+ const out = result.map((r, i) => outTypes[i].fromBuffer(r));
2197
+ return out[0];
2198
+ }
2199
+ acirSerializeVerificationKeyIntoFields(acirComposerPtr) {
2200
+ const inArgs = [acirComposerPtr].map(serializeBufferable);
2201
+ const outTypes = [VectorDeserializer(Fr), Fr];
2202
+ const result = this.wasm.callWasmExport("acir_serialize_verification_key_into_fields", inArgs, outTypes.map((t) => t.SIZE_IN_BYTES));
2203
+ const out = result.map((r, i) => outTypes[i].fromBuffer(r));
2204
+ return out;
2205
+ }
2206
+ acirProveUltraHonk(acirVec, witnessVec) {
2207
+ const inArgs = [acirVec, witnessVec].map(serializeBufferable);
2208
+ const outTypes = [BufferDeserializer()];
2209
+ const result = this.wasm.callWasmExport("acir_prove_ultra_honk", inArgs, outTypes.map((t) => t.SIZE_IN_BYTES));
2210
+ const out = result.map((r, i) => outTypes[i].fromBuffer(r));
2211
+ return out[0];
2212
+ }
2213
+ acirVerifyUltraHonk(proofBuf, vkBuf) {
2214
+ const inArgs = [proofBuf, vkBuf].map(serializeBufferable);
2215
+ const outTypes = [BoolDeserializer()];
2216
+ const result = this.wasm.callWasmExport("acir_verify_ultra_honk", inArgs, outTypes.map((t) => t.SIZE_IN_BYTES));
2217
+ const out = result.map((r, i) => outTypes[i].fromBuffer(r));
2218
+ return out[0];
2219
+ }
2220
+ acirWriteVkUltraHonk(acirVec) {
2221
+ const inArgs = [acirVec].map(serializeBufferable);
2222
+ const outTypes = [BufferDeserializer()];
2223
+ const result = this.wasm.callWasmExport("acir_write_vk_ultra_honk", inArgs, outTypes.map((t) => t.SIZE_IN_BYTES));
2224
+ const out = result.map((r, i) => outTypes[i].fromBuffer(r));
2225
+ return out[0];
2226
+ }
2227
+ acirProofAsFieldsUltraHonk(proofBuf) {
2228
+ const inArgs = [proofBuf].map(serializeBufferable);
2229
+ const outTypes = [VectorDeserializer(Fr)];
2230
+ const result = this.wasm.callWasmExport("acir_proof_as_fields_ultra_honk", inArgs, outTypes.map((t) => t.SIZE_IN_BYTES));
2231
+ const out = result.map((r, i) => outTypes[i].fromBuffer(r));
2232
+ return out[0];
2233
+ }
2234
+ acirVkAsFieldsUltraHonk(vkBuf) {
2235
+ const inArgs = [vkBuf].map(serializeBufferable);
2236
+ const outTypes = [VectorDeserializer(Fr)];
2237
+ const result = this.wasm.callWasmExport("acir_vk_as_fields_ultra_honk", inArgs, outTypes.map((t) => t.SIZE_IN_BYTES));
2238
+ const out = result.map((r, i) => outTypes[i].fromBuffer(r));
2239
+ return out[0];
2240
+ }
2241
+ };
2242
+
2243
+ // ../../node_modules/@aztec/bb.js/dest/node/barretenberg_wasm/barretenberg_wasm_main/factory/node/index.js
2244
+ import { Worker } from "worker_threads";
2245
+ import { dirname as dirname2 } from "path";
2246
+ import { fileURLToPath as fileURLToPath2 } from "url";
2247
+ function getCurrentDir2() {
2248
+ if (typeof __dirname !== "undefined") {
2249
+ return __dirname;
2250
+ } else {
2251
+ return dirname2(fileURLToPath2(import.meta.url));
2252
+ }
2253
+ }
2254
+ function createMainWorker() {
2255
+ const __dirname2 = getCurrentDir2();
2256
+ return new Worker(__dirname2 + `/main.worker.js`);
2257
+ }
2258
+
2259
+ // ../../node_modules/@aztec/bb.js/dest/node/barretenberg_wasm/barretenberg_wasm_main/index.js
2260
+ var import_debug3 = __toESM(require_src(), 1);
2261
+
2262
+ // ../../node_modules/@aztec/bb.js/dest/node/barretenberg_wasm/helpers/node/index.js
2263
+ import os from "os";
2264
+
2265
+ // ../../node_modules/@aztec/bb.js/dest/node/barretenberg_wasm/helpers/node/node_endpoint.js
2266
+ function nodeEndpoint(nep) {
2267
+ const listeners = /* @__PURE__ */ new WeakMap();
2268
+ return {
2269
+ postMessage: nep.postMessage.bind(nep),
2270
+ addEventListener: (_, eh) => {
2271
+ const l = (data) => {
2272
+ if ("handleEvent" in eh) {
2273
+ eh.handleEvent({ data });
2274
+ } else {
2275
+ eh({ data });
2276
+ }
2277
+ };
2278
+ nep.on("message", l);
2279
+ listeners.set(eh, l);
2280
+ },
2281
+ removeEventListener: (_, eh) => {
2282
+ const l = listeners.get(eh);
2283
+ if (!l) {
2284
+ return;
2285
+ }
2286
+ nep.off("message", l);
2287
+ listeners.delete(eh);
2288
+ },
2289
+ start: nep.start && nep.start.bind(nep)
2290
+ };
2291
+ }
2292
+
2293
+ // ../../node_modules/@aztec/bb.js/dest/node/barretenberg_wasm/helpers/node/index.js
2294
+ function getSharedMemoryAvailable() {
2295
+ return true;
2296
+ }
2297
+ function getRemoteBarretenbergWasm(worker) {
2298
+ return wrap(nodeEndpoint(worker));
2299
+ }
2300
+ function getNumCpu() {
2301
+ return +process.env.HARDWARE_CONCURRENCY || os.cpus().length;
2302
+ }
2303
+ function killSelf() {
2304
+ process.kill(process.pid);
2305
+ throw new Error();
2306
+ }
2307
+
2308
+ // ../../node_modules/@aztec/bb.js/dest/node/barretenberg_wasm/barretenberg_wasm_thread/factory/node/index.js
2309
+ import { Worker as Worker2 } from "worker_threads";
2310
+ import { dirname as dirname3 } from "path";
2311
+ import { fileURLToPath as fileURLToPath3 } from "url";
2312
+ function getCurrentDir3() {
2313
+ if (typeof __dirname !== "undefined") {
2314
+ return __dirname;
2315
+ } else {
2316
+ return dirname3(fileURLToPath3(import.meta.url));
2317
+ }
2318
+ }
2319
+ function createThreadWorker() {
2320
+ const __dirname2 = getCurrentDir3();
2321
+ return new Worker2(__dirname2 + `/thread.worker.js`);
2322
+ }
2323
+
2324
+ // ../../node_modules/@aztec/bb.js/dest/node/barretenberg_wasm/barretenberg_wasm_base/index.js
2325
+ var import_debug2 = __toESM(require_src(), 1);
2326
+ var debug2 = (0, import_debug2.default)("bb.js:wasm");
2327
+ var BarretenbergWasmBase = class {
2328
+ constructor() {
2329
+ this.memStore = {};
2330
+ this.logger = debug2;
2331
+ }
2332
+ getImportObj(memory) {
2333
+ const importObj = {
2334
+ // We need to implement a part of the wasi api:
2335
+ // https://github.com/WebAssembly/WASI/blob/main/phases/snapshot/docs.md
2336
+ // We literally only need to support random_get, everything else is noop implementated in barretenberg.wasm.
2337
+ wasi_snapshot_preview1: {
2338
+ random_get: (out, length) => {
2339
+ out = out >>> 0;
2340
+ const randomData = randomBytes(length);
2341
+ const mem = this.getMemory();
2342
+ mem.set(randomData, out);
2343
+ },
2344
+ clock_time_get: (a1, a2, out) => {
2345
+ out = out >>> 0;
2346
+ const ts = BigInt((/* @__PURE__ */ new Date()).getTime()) * 1000000n;
2347
+ const view = new DataView(this.getMemory().buffer);
2348
+ view.setBigUint64(out, ts, true);
2349
+ },
2350
+ proc_exit: () => {
2351
+ this.logger('PANIC: proc_exit was called. This is maybe caused by "joining" with unstable wasi pthreads.');
2352
+ this.logger(new Error().stack);
2353
+ killSelf();
2354
+ }
2355
+ },
2356
+ // These are functions implementations for imports we've defined are needed.
2357
+ // The native C++ build defines these in a module called "env". We must implement TypeScript versions here.
2358
+ env: {
2359
+ /**
2360
+ * The 'info' call we use for logging in C++, calls this under the hood.
2361
+ * The native code will just print to std:err (to avoid std::cout which is used for IPC).
2362
+ * Here we just emit the log line for the client to decide what to do with.
2363
+ */
2364
+ logstr: (addr) => {
2365
+ const str = this.stringFromAddress(addr);
2366
+ const m = this.getMemory();
2367
+ const str2 = `${str} (mem: ${(m.length / (1024 * 1024)).toFixed(2)}MiB)`;
2368
+ this.logger(str2);
2369
+ if (str2.startsWith("WARNING:")) {
2370
+ this.logger(new Error().stack);
2371
+ }
2372
+ },
2373
+ get_data: (keyAddr, outBufAddr) => {
2374
+ const key = this.stringFromAddress(keyAddr);
2375
+ outBufAddr = outBufAddr >>> 0;
2376
+ const data = this.memStore[key];
2377
+ if (!data) {
2378
+ this.logger(`get_data miss ${key}`);
2379
+ return;
2380
+ }
2381
+ this.writeMemory(outBufAddr, data);
2382
+ },
2383
+ set_data: (keyAddr, dataAddr, dataLength) => {
2384
+ const key = this.stringFromAddress(keyAddr);
2385
+ dataAddr = dataAddr >>> 0;
2386
+ this.memStore[key] = this.getMemorySlice(dataAddr, dataAddr + dataLength);
2387
+ },
2388
+ memory
2389
+ }
2390
+ };
2391
+ return importObj;
2392
+ }
2393
+ exports() {
2394
+ return this.instance.exports;
2395
+ }
2396
+ /**
2397
+ * When returning values from the WASM, use >>> operator to convert signed representation to unsigned representation.
2398
+ */
2399
+ call(name, ...args) {
2400
+ if (!this.exports()[name]) {
2401
+ throw new Error(`WASM function ${name} not found.`);
2402
+ }
2403
+ try {
2404
+ return this.exports()[name](...args) >>> 0;
2405
+ } catch (err2) {
2406
+ const message = `WASM function ${name} aborted, error: ${err2}`;
2407
+ this.logger(message);
2408
+ this.logger(err2.stack);
2409
+ throw err2;
2410
+ }
2411
+ }
2412
+ memSize() {
2413
+ return this.getMemory().length;
2414
+ }
2415
+ /**
2416
+ * Returns a copy of the data, not a view.
2417
+ */
2418
+ getMemorySlice(start, end) {
2419
+ return this.getMemory().subarray(start, end).slice();
2420
+ }
2421
+ writeMemory(offset, arr) {
2422
+ const mem = this.getMemory();
2423
+ mem.set(arr, offset);
2424
+ }
2425
+ // PRIVATE METHODS
2426
+ getMemory() {
2427
+ return new Uint8Array(this.memory.buffer);
2428
+ }
2429
+ stringFromAddress(addr) {
2430
+ addr = addr >>> 0;
2431
+ const m = this.getMemory();
2432
+ let i = addr;
2433
+ for (; m[i] !== 0; ++i)
2434
+ ;
2435
+ const textDecoder = new TextDecoder("ascii");
2436
+ return textDecoder.decode(m.slice(addr, i));
2437
+ }
2438
+ };
2439
+
2440
+ // ../../node_modules/@aztec/bb.js/dest/node/barretenberg_wasm/barretenberg_wasm_main/heap_allocator.js
2441
+ var HeapAllocator = class {
2442
+ constructor(wasm) {
2443
+ this.wasm = wasm;
2444
+ this.allocs = [];
2445
+ this.inScratchRemaining = 1024;
2446
+ this.outScratchRemaining = 1024;
2447
+ }
2448
+ copyToMemory(buffers) {
2449
+ return buffers.map((buf) => {
2450
+ if (buf.length <= this.inScratchRemaining) {
2451
+ const ptr = this.inScratchRemaining -= buf.length;
2452
+ this.wasm.writeMemory(ptr, buf);
2453
+ return ptr;
2454
+ } else {
2455
+ const ptr = this.wasm.call("bbmalloc", buf.length);
2456
+ this.wasm.writeMemory(ptr, buf);
2457
+ this.allocs.push(ptr);
2458
+ return ptr;
2459
+ }
2460
+ });
2461
+ }
2462
+ getOutputPtrs(outLens) {
2463
+ return outLens.map((len) => {
2464
+ const size = len || 4;
2465
+ if (size <= this.outScratchRemaining) {
2466
+ return this.outScratchRemaining -= size;
2467
+ } else {
2468
+ const ptr = this.wasm.call("bbmalloc", size);
2469
+ this.allocs.push(ptr);
2470
+ return ptr;
2471
+ }
2472
+ });
2473
+ }
2474
+ addOutputPtr(ptr) {
2475
+ if (ptr >= 1024) {
2476
+ this.allocs.push(ptr);
2477
+ }
2478
+ }
2479
+ freeAll() {
2480
+ for (const ptr of this.allocs) {
2481
+ this.wasm.call("bbfree", ptr);
2482
+ }
2483
+ }
2484
+ };
2485
+
2486
+ // ../../node_modules/@aztec/bb.js/dest/node/barretenberg_wasm/barretenberg_wasm_main/index.js
2487
+ var debug3 = (0, import_debug3.default)("bb.js:wasm");
2488
+ var BarretenbergWasmMain = class _BarretenbergWasmMain extends BarretenbergWasmBase {
2489
+ constructor() {
2490
+ super(...arguments);
2491
+ this.workers = [];
2492
+ this.remoteWasms = [];
2493
+ this.nextWorker = 0;
2494
+ this.nextThreadId = 1;
2495
+ }
2496
+ getNumThreads() {
2497
+ return this.workers.length + 1;
2498
+ }
2499
+ /**
2500
+ * Init as main thread. Spawn child threads.
2501
+ */
2502
+ async init(module, threads = Math.min(getNumCpu(), _BarretenbergWasmMain.MAX_THREADS), logger = debug3, initial = 30, maximum = 2 ** 16) {
2503
+ this.logger = logger;
2504
+ const initialMb = initial * 2 ** 16 / (1024 * 1024);
2505
+ const maxMb = maximum * 2 ** 16 / (1024 * 1024);
2506
+ const shared = getSharedMemoryAvailable();
2507
+ this.logger(`initial mem: ${initial} pages, ${initialMb}MiB. max mem: ${maximum} pages, ${maxMb}MiB. threads: ${threads}, shared: ${shared}`);
2508
+ this.memory = new WebAssembly.Memory({ initial, maximum, shared });
2509
+ const instance = await WebAssembly.instantiate(module, this.getImportObj(this.memory));
2510
+ this.instance = instance;
2511
+ this.call("_initialize");
2512
+ if (threads > 1) {
2513
+ this.logger(`creating ${threads} worker threads...`);
2514
+ this.workers = await Promise.all(Array.from({ length: threads - 1 }).map(createThreadWorker));
2515
+ this.remoteWasms = await Promise.all(this.workers.map(getRemoteBarretenbergWasm));
2516
+ await Promise.all(this.remoteWasms.map((w) => w.initThread(module, this.memory)));
2517
+ }
2518
+ this.logger("init complete.");
2519
+ }
2520
+ /**
2521
+ * Called on main thread. Signals child threads to gracefully exit.
2522
+ */
2523
+ async destroy() {
2524
+ await Promise.all(this.workers.map((w) => w.terminate()));
2525
+ }
2526
+ getImportObj(memory) {
2527
+ const baseImports = super.getImportObj(memory);
2528
+ return {
2529
+ ...baseImports,
2530
+ wasi: {
2531
+ "thread-spawn": (arg) => {
2532
+ arg = arg >>> 0;
2533
+ const id = this.nextThreadId++;
2534
+ const worker = this.nextWorker++ % this.remoteWasms.length;
2535
+ this.remoteWasms[worker].call("wasi_thread_start", id, arg).catch(this.logger);
2536
+ return id;
2537
+ }
2538
+ },
2539
+ env: {
2540
+ ...baseImports.env,
2541
+ env_hardware_concurrency: () => {
2542
+ return this.remoteWasms.length + 1;
2543
+ }
2544
+ }
2545
+ };
2546
+ }
2547
+ callWasmExport(funcName, inArgs, outLens) {
2548
+ const alloc = new HeapAllocator(this);
2549
+ const inPtrs = alloc.copyToMemory(inArgs);
2550
+ const outPtrs = alloc.getOutputPtrs(outLens);
2551
+ this.call(funcName, ...inPtrs, ...outPtrs);
2552
+ const outArgs = this.getOutputArgs(outLens, outPtrs, alloc);
2553
+ alloc.freeAll();
2554
+ return outArgs;
2555
+ }
2556
+ getOutputArgs(outLens, outPtrs, alloc) {
2557
+ return outLens.map((len, i) => {
2558
+ if (len) {
2559
+ return this.getMemorySlice(outPtrs[i], outPtrs[i] + len);
2560
+ }
2561
+ const slice = this.getMemorySlice(outPtrs[i], outPtrs[i] + 4);
2562
+ const ptr = new DataView(slice.buffer, slice.byteOffset, slice.byteLength).getUint32(0, true);
2563
+ alloc.addOutputPtr(ptr);
2564
+ const lslice = this.getMemorySlice(ptr, ptr + 4);
2565
+ const length = new DataView(lslice.buffer, lslice.byteOffset, lslice.byteLength).getUint32(0, false);
2566
+ return this.getMemorySlice(ptr + 4, ptr + 4 + length);
2567
+ });
2568
+ }
2569
+ };
2570
+ BarretenbergWasmMain.MAX_THREADS = 32;
2571
+
2572
+ // ../../node_modules/@aztec/bb.js/dest/node/barretenberg_wasm/index.js
2573
+ var import_debug4 = __toESM(require_src(), 1);
2574
+
2575
+ // ../../node_modules/@aztec/bb.js/dest/node/barretenberg_wasm/fetch_code/node/index.js
2576
+ import { readFile as readFile2 } from "fs/promises";
2577
+ import { dirname as dirname4 } from "path";
2578
+ import { fileURLToPath as fileURLToPath4 } from "url";
2579
+ function getCurrentDir4() {
2580
+ if (typeof __dirname !== "undefined") {
2581
+ return __dirname;
2582
+ } else {
2583
+ return dirname4(fileURLToPath4(import.meta.url));
2584
+ }
2585
+ }
2586
+ async function fetchCode(multithreaded) {
2587
+ const path = getCurrentDir4() + "/../../barretenberg-threads.wasm";
2588
+ return await readFile2(path);
2589
+ }
2590
+
2591
+ // ../../node_modules/@aztec/bb.js/dest/node/barretenberg_wasm/index.js
2592
+ var debug4 = (0, import_debug4.default)("bb.js:wasm");
2593
+ async function fetchModuleAndThreads(desiredThreads = 32) {
2594
+ const shared = getSharedMemoryAvailable();
2595
+ const availableThreads = shared ? await getAvailableThreads() : 1;
2596
+ const limitedThreads = Math.min(desiredThreads, availableThreads, 32);
2597
+ const code = await fetchCode(shared);
2598
+ const module = await WebAssembly.compile(code);
2599
+ return { module, threads: limitedThreads };
2600
+ }
2601
+ async function getAvailableThreads() {
2602
+ if (typeof navigator !== "undefined" && navigator.hardwareConcurrency) {
2603
+ return navigator.hardwareConcurrency;
2604
+ } else {
2605
+ try {
2606
+ const os2 = await import("os");
2607
+ return os2.cpus().length;
2608
+ } catch (e) {
2609
+ debug4(`Could not detect environment. Falling back to one thread.: {e}`);
2610
+ return 1;
2611
+ }
2612
+ }
2613
+ }
2614
+
2615
+ // ../../node_modules/@aztec/bb.js/dest/node/barretenberg/index.js
2616
+ var import_debug5 = __toESM(require_src(), 1);
2617
+
2618
+ // ../../node_modules/@aztec/bb.js/dest/node/proof/index.js
2619
+ var serializedBufferSize = 4;
2620
+ var fieldByteSize = 32;
2621
+ var publicInputOffset = 3;
2622
+ var publicInputsOffsetBytes = publicInputOffset * fieldByteSize;
2623
+ function splitHonkProof(proofWithPublicInputs) {
2624
+ const proofAsStrings = deflattenFields(proofWithPublicInputs.slice(4));
2625
+ const numPublicInputs = Number(proofAsStrings[1]);
2626
+ const publicInputsOffset = publicInputsOffsetBytes + serializedBufferSize;
2627
+ const proofStart = proofWithPublicInputs.slice(0, publicInputsOffset);
2628
+ const publicInputsSplitIndex = numPublicInputs * fieldByteSize;
2629
+ const proofEnd = proofWithPublicInputs.slice(publicInputsOffset + publicInputsSplitIndex);
2630
+ const proof = new Uint8Array([...proofStart, ...proofEnd]);
2631
+ const publicInputs = proofWithPublicInputs.slice(publicInputsOffset, publicInputsOffset + publicInputsSplitIndex);
2632
+ return {
2633
+ proof,
2634
+ publicInputs
2635
+ };
2636
+ }
2637
+ function reconstructHonkProof(publicInputs, proof) {
2638
+ const proofStart = proof.slice(0, publicInputsOffsetBytes + serializedBufferSize);
2639
+ const proofEnd = proof.slice(publicInputsOffsetBytes + serializedBufferSize);
2640
+ const proofWithPublicInputs = Uint8Array.from([...proofStart, ...publicInputs, ...proofEnd]);
2641
+ return proofWithPublicInputs;
2642
+ }
2643
+ function reconstructUltraPlonkProof(proofData) {
2644
+ const publicInputsConcatenated = flattenFieldsAsArray(proofData.publicInputs);
2645
+ const proofWithPublicInputs = Uint8Array.from([...publicInputsConcatenated, ...proofData.proof]);
2646
+ return proofWithPublicInputs;
2647
+ }
2648
+ function deflattenFields(flattenedFields) {
2649
+ const publicInputSize = 32;
2650
+ const chunkedFlattenedPublicInputs = [];
2651
+ for (let i = 0; i < flattenedFields.length; i += publicInputSize) {
2652
+ const publicInput = flattenedFields.slice(i, i + publicInputSize);
2653
+ chunkedFlattenedPublicInputs.push(publicInput);
2654
+ }
2655
+ return chunkedFlattenedPublicInputs.map(uint8ArrayToHex);
2656
+ }
2657
+ function flattenFieldsAsArray(fields) {
2658
+ const flattenedPublicInputs = fields.map(hexToUint8Array);
2659
+ return flattenUint8Arrays(flattenedPublicInputs);
2660
+ }
2661
+ function flattenUint8Arrays(arrays) {
2662
+ const totalLength = arrays.reduce((acc, val) => acc + val.length, 0);
2663
+ const result = new Uint8Array(totalLength);
2664
+ let offset = 0;
2665
+ for (const arr of arrays) {
2666
+ result.set(arr, offset);
2667
+ offset += arr.length;
2668
+ }
2669
+ return result;
2670
+ }
2671
+ function uint8ArrayToHex(buffer) {
2672
+ const hex = [];
2673
+ buffer.forEach(function(i) {
2674
+ let h = i.toString(16);
2675
+ if (h.length % 2) {
2676
+ h = "0" + h;
2677
+ }
2678
+ hex.push(h);
2679
+ });
2680
+ return "0x" + hex.join("");
2681
+ }
2682
+ function hexToUint8Array(hex) {
2683
+ const sanitisedHex = BigInt(hex).toString(16).padStart(64, "0");
2684
+ const len = sanitisedHex.length / 2;
2685
+ const u82 = new Uint8Array(len);
2686
+ let i = 0;
2687
+ let j = 0;
2688
+ while (i < len) {
2689
+ u82[i] = parseInt(sanitisedHex.slice(j, j + 2), 16);
2690
+ i += 1;
2691
+ j += 2;
2692
+ }
2693
+ return u82;
2694
+ }
2695
+
2696
+ // ../../node_modules/@aztec/bb.js/dest/node/barretenberg/verifier.js
2697
+ var BarretenbergVerifier = class {
2698
+ constructor(options = { threads: 1 }) {
2699
+ this.options = options;
2700
+ }
2701
+ /** @ignore */
2702
+ async instantiate() {
2703
+ if (!this.api) {
2704
+ const api = await Barretenberg.new(this.options);
2705
+ await api.initSRSForCircuitSize(0);
2706
+ this.acirComposer = await api.acirNewAcirComposer(0);
2707
+ this.api = api;
2708
+ }
2709
+ }
2710
+ /** @description Verifies a proof */
2711
+ async verifyUltraPlonkProof(proofData, verificationKey) {
2712
+ await this.instantiate();
2713
+ await this.api.acirLoadVerificationKey(this.acirComposer, new RawBuffer(verificationKey));
2714
+ const proof = reconstructUltraPlonkProof(proofData);
2715
+ return await this.api.acirVerifyProof(this.acirComposer, proof);
2716
+ }
2717
+ /** @description Verifies a proof */
2718
+ async verifyUltraHonkProof(proofData, verificationKey) {
2719
+ await this.instantiate();
2720
+ const proof = reconstructHonkProof(flattenFieldsAsArray(proofData.publicInputs), proofData.proof);
2721
+ return await this.api.acirVerifyUltraHonk(proof, new RawBuffer(verificationKey));
2722
+ }
2723
+ async destroy() {
2724
+ if (!this.api) {
2725
+ return;
2726
+ }
2727
+ await this.api.destroy();
2728
+ }
2729
+ };
2730
+
2731
+ // ../../node_modules/fflate/esm/index.mjs
2732
+ import { createRequire } from "module";
2733
+ var require2 = createRequire("/");
2734
+ var Worker3;
2735
+ try {
2736
+ Worker3 = require2("worker_threads").Worker;
2737
+ } catch (e) {
2738
+ }
2739
+ var u8 = Uint8Array;
2740
+ var u16 = Uint16Array;
2741
+ var i32 = Int32Array;
2742
+ var fleb = new u8([
2743
+ 0,
2744
+ 0,
2745
+ 0,
2746
+ 0,
2747
+ 0,
2748
+ 0,
2749
+ 0,
2750
+ 0,
2751
+ 1,
2752
+ 1,
2753
+ 1,
2754
+ 1,
2755
+ 2,
2756
+ 2,
2757
+ 2,
2758
+ 2,
2759
+ 3,
2760
+ 3,
2761
+ 3,
2762
+ 3,
2763
+ 4,
2764
+ 4,
2765
+ 4,
2766
+ 4,
2767
+ 5,
2768
+ 5,
2769
+ 5,
2770
+ 5,
2771
+ 0,
2772
+ /* unused */
2773
+ 0,
2774
+ 0,
2775
+ /* impossible */
2776
+ 0
2777
+ ]);
2778
+ var fdeb = new u8([
2779
+ 0,
2780
+ 0,
2781
+ 0,
2782
+ 0,
2783
+ 1,
2784
+ 1,
2785
+ 2,
2786
+ 2,
2787
+ 3,
2788
+ 3,
2789
+ 4,
2790
+ 4,
2791
+ 5,
2792
+ 5,
2793
+ 6,
2794
+ 6,
2795
+ 7,
2796
+ 7,
2797
+ 8,
2798
+ 8,
2799
+ 9,
2800
+ 9,
2801
+ 10,
2802
+ 10,
2803
+ 11,
2804
+ 11,
2805
+ 12,
2806
+ 12,
2807
+ 13,
2808
+ 13,
2809
+ /* unused */
2810
+ 0,
2811
+ 0
2812
+ ]);
2813
+ var clim = new u8([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]);
2814
+ var freb = function(eb, start) {
2815
+ var b = new u16(31);
2816
+ for (var i = 0; i < 31; ++i) {
2817
+ b[i] = start += 1 << eb[i - 1];
2818
+ }
2819
+ var r = new i32(b[30]);
2820
+ for (var i = 1; i < 30; ++i) {
2821
+ for (var j = b[i]; j < b[i + 1]; ++j) {
2822
+ r[j] = j - b[i] << 5 | i;
2823
+ }
2824
+ }
2825
+ return { b, r };
2826
+ };
2827
+ var _a2 = freb(fleb, 2);
2828
+ var fl = _a2.b;
2829
+ var revfl = _a2.r;
2830
+ fl[28] = 258, revfl[258] = 28;
2831
+ var _b2 = freb(fdeb, 0);
2832
+ var fd = _b2.b;
2833
+ var revfd = _b2.r;
2834
+ var rev = new u16(32768);
2835
+ for (i = 0; i < 32768; ++i) {
2836
+ x = (i & 43690) >> 1 | (i & 21845) << 1;
2837
+ x = (x & 52428) >> 2 | (x & 13107) << 2;
2838
+ x = (x & 61680) >> 4 | (x & 3855) << 4;
2839
+ rev[i] = ((x & 65280) >> 8 | (x & 255) << 8) >> 1;
2840
+ }
2841
+ var x;
2842
+ var i;
2843
+ var hMap = (function(cd, mb, r) {
2844
+ var s = cd.length;
2845
+ var i = 0;
2846
+ var l = new u16(mb);
2847
+ for (; i < s; ++i) {
2848
+ if (cd[i])
2849
+ ++l[cd[i] - 1];
2850
+ }
2851
+ var le = new u16(mb);
2852
+ for (i = 1; i < mb; ++i) {
2853
+ le[i] = le[i - 1] + l[i - 1] << 1;
2854
+ }
2855
+ var co;
2856
+ if (r) {
2857
+ co = new u16(1 << mb);
2858
+ var rvb = 15 - mb;
2859
+ for (i = 0; i < s; ++i) {
2860
+ if (cd[i]) {
2861
+ var sv = i << 4 | cd[i];
2862
+ var r_1 = mb - cd[i];
2863
+ var v = le[cd[i] - 1]++ << r_1;
2864
+ for (var m = v | (1 << r_1) - 1; v <= m; ++v) {
2865
+ co[rev[v] >> rvb] = sv;
2866
+ }
2867
+ }
2868
+ }
2869
+ } else {
2870
+ co = new u16(s);
2871
+ for (i = 0; i < s; ++i) {
2872
+ if (cd[i]) {
2873
+ co[i] = rev[le[cd[i] - 1]++] >> 15 - cd[i];
2874
+ }
2875
+ }
2876
+ }
2877
+ return co;
2878
+ });
2879
+ var flt = new u8(288);
2880
+ for (i = 0; i < 144; ++i)
2881
+ flt[i] = 8;
2882
+ var i;
2883
+ for (i = 144; i < 256; ++i)
2884
+ flt[i] = 9;
2885
+ var i;
2886
+ for (i = 256; i < 280; ++i)
2887
+ flt[i] = 7;
2888
+ var i;
2889
+ for (i = 280; i < 288; ++i)
2890
+ flt[i] = 8;
2891
+ var i;
2892
+ var fdt = new u8(32);
2893
+ for (i = 0; i < 32; ++i)
2894
+ fdt[i] = 5;
2895
+ var i;
2896
+ var flrm = /* @__PURE__ */ hMap(flt, 9, 1);
2897
+ var fdrm = /* @__PURE__ */ hMap(fdt, 5, 1);
2898
+ var max = function(a) {
2899
+ var m = a[0];
2900
+ for (var i = 1; i < a.length; ++i) {
2901
+ if (a[i] > m)
2902
+ m = a[i];
2903
+ }
2904
+ return m;
2905
+ };
2906
+ var bits = function(d, p, m) {
2907
+ var o = p / 8 | 0;
2908
+ return (d[o] | d[o + 1] << 8) >> (p & 7) & m;
2909
+ };
2910
+ var bits16 = function(d, p) {
2911
+ var o = p / 8 | 0;
2912
+ return (d[o] | d[o + 1] << 8 | d[o + 2] << 16) >> (p & 7);
2913
+ };
2914
+ var shft = function(p) {
2915
+ return (p + 7) / 8 | 0;
2916
+ };
2917
+ var slc = function(v, s, e) {
2918
+ if (s == null || s < 0)
2919
+ s = 0;
2920
+ if (e == null || e > v.length)
2921
+ e = v.length;
2922
+ return new u8(v.subarray(s, e));
2923
+ };
2924
+ var ec = [
2925
+ "unexpected EOF",
2926
+ "invalid block type",
2927
+ "invalid length/literal",
2928
+ "invalid distance",
2929
+ "stream finished",
2930
+ "no stream handler",
2931
+ ,
2932
+ "no callback",
2933
+ "invalid UTF-8 data",
2934
+ "extra field too long",
2935
+ "date not in range 1980-2099",
2936
+ "filename too long",
2937
+ "stream finishing",
2938
+ "invalid zip data"
2939
+ // determined by unknown compression method
2940
+ ];
2941
+ var err = function(ind, msg, nt) {
2942
+ var e = new Error(msg || ec[ind]);
2943
+ e.code = ind;
2944
+ if (Error.captureStackTrace)
2945
+ Error.captureStackTrace(e, err);
2946
+ if (!nt)
2947
+ throw e;
2948
+ return e;
2949
+ };
2950
+ var inflt = function(dat, st, buf, dict) {
2951
+ var sl = dat.length, dl = dict ? dict.length : 0;
2952
+ if (!sl || st.f && !st.l)
2953
+ return buf || new u8(0);
2954
+ var noBuf = !buf;
2955
+ var resize = noBuf || st.i != 2;
2956
+ var noSt = st.i;
2957
+ if (noBuf)
2958
+ buf = new u8(sl * 3);
2959
+ var cbuf = function(l2) {
2960
+ var bl = buf.length;
2961
+ if (l2 > bl) {
2962
+ var nbuf = new u8(Math.max(bl * 2, l2));
2963
+ nbuf.set(buf);
2964
+ buf = nbuf;
2965
+ }
2966
+ };
2967
+ var final = st.f || 0, pos = st.p || 0, bt = st.b || 0, lm = st.l, dm = st.d, lbt = st.m, dbt = st.n;
2968
+ var tbts = sl * 8;
2969
+ do {
2970
+ if (!lm) {
2971
+ final = bits(dat, pos, 1);
2972
+ var type = bits(dat, pos + 1, 3);
2973
+ pos += 3;
2974
+ if (!type) {
2975
+ var s = shft(pos) + 4, l = dat[s - 4] | dat[s - 3] << 8, t = s + l;
2976
+ if (t > sl) {
2977
+ if (noSt)
2978
+ err(0);
2979
+ break;
2980
+ }
2981
+ if (resize)
2982
+ cbuf(bt + l);
2983
+ buf.set(dat.subarray(s, t), bt);
2984
+ st.b = bt += l, st.p = pos = t * 8, st.f = final;
2985
+ continue;
2986
+ } else if (type == 1)
2987
+ lm = flrm, dm = fdrm, lbt = 9, dbt = 5;
2988
+ else if (type == 2) {
2989
+ var hLit = bits(dat, pos, 31) + 257, hcLen = bits(dat, pos + 10, 15) + 4;
2990
+ var tl = hLit + bits(dat, pos + 5, 31) + 1;
2991
+ pos += 14;
2992
+ var ldt = new u8(tl);
2993
+ var clt = new u8(19);
2994
+ for (var i = 0; i < hcLen; ++i) {
2995
+ clt[clim[i]] = bits(dat, pos + i * 3, 7);
2996
+ }
2997
+ pos += hcLen * 3;
2998
+ var clb = max(clt), clbmsk = (1 << clb) - 1;
2999
+ var clm = hMap(clt, clb, 1);
3000
+ for (var i = 0; i < tl; ) {
3001
+ var r = clm[bits(dat, pos, clbmsk)];
3002
+ pos += r & 15;
3003
+ var s = r >> 4;
3004
+ if (s < 16) {
3005
+ ldt[i++] = s;
3006
+ } else {
3007
+ var c = 0, n = 0;
3008
+ if (s == 16)
3009
+ n = 3 + bits(dat, pos, 3), pos += 2, c = ldt[i - 1];
3010
+ else if (s == 17)
3011
+ n = 3 + bits(dat, pos, 7), pos += 3;
3012
+ else if (s == 18)
3013
+ n = 11 + bits(dat, pos, 127), pos += 7;
3014
+ while (n--)
3015
+ ldt[i++] = c;
3016
+ }
3017
+ }
3018
+ var lt = ldt.subarray(0, hLit), dt = ldt.subarray(hLit);
3019
+ lbt = max(lt);
3020
+ dbt = max(dt);
3021
+ lm = hMap(lt, lbt, 1);
3022
+ dm = hMap(dt, dbt, 1);
3023
+ } else
3024
+ err(1);
3025
+ if (pos > tbts) {
3026
+ if (noSt)
3027
+ err(0);
3028
+ break;
3029
+ }
3030
+ }
3031
+ if (resize)
3032
+ cbuf(bt + 131072);
3033
+ var lms = (1 << lbt) - 1, dms = (1 << dbt) - 1;
3034
+ var lpos = pos;
3035
+ for (; ; lpos = pos) {
3036
+ var c = lm[bits16(dat, pos) & lms], sym = c >> 4;
3037
+ pos += c & 15;
3038
+ if (pos > tbts) {
3039
+ if (noSt)
3040
+ err(0);
3041
+ break;
3042
+ }
3043
+ if (!c)
3044
+ err(2);
3045
+ if (sym < 256)
3046
+ buf[bt++] = sym;
3047
+ else if (sym == 256) {
3048
+ lpos = pos, lm = null;
3049
+ break;
3050
+ } else {
3051
+ var add = sym - 254;
3052
+ if (sym > 264) {
3053
+ var i = sym - 257, b = fleb[i];
3054
+ add = bits(dat, pos, (1 << b) - 1) + fl[i];
3055
+ pos += b;
3056
+ }
3057
+ var d = dm[bits16(dat, pos) & dms], dsym = d >> 4;
3058
+ if (!d)
3059
+ err(3);
3060
+ pos += d & 15;
3061
+ var dt = fd[dsym];
3062
+ if (dsym > 3) {
3063
+ var b = fdeb[dsym];
3064
+ dt += bits16(dat, pos) & (1 << b) - 1, pos += b;
3065
+ }
3066
+ if (pos > tbts) {
3067
+ if (noSt)
3068
+ err(0);
3069
+ break;
3070
+ }
3071
+ if (resize)
3072
+ cbuf(bt + 131072);
3073
+ var end = bt + add;
3074
+ if (bt < dt) {
3075
+ var shift = dl - dt, dend = Math.min(dt, end);
3076
+ if (shift + bt < 0)
3077
+ err(3);
3078
+ for (; bt < dend; ++bt)
3079
+ buf[bt] = dict[shift + bt];
3080
+ }
3081
+ for (; bt < end; ++bt)
3082
+ buf[bt] = buf[bt - dt];
3083
+ }
3084
+ }
3085
+ st.l = lm, st.p = lpos, st.b = bt, st.f = final;
3086
+ if (lm)
3087
+ final = 1, st.m = lbt, st.d = dm, st.n = dbt;
3088
+ } while (!final);
3089
+ return bt != buf.length && noBuf ? slc(buf, 0, bt) : buf.subarray(0, bt);
3090
+ };
3091
+ var et = /* @__PURE__ */ new u8(0);
3092
+ var gzs = function(d) {
3093
+ if (d[0] != 31 || d[1] != 139 || d[2] != 8)
3094
+ err(6, "invalid gzip data");
3095
+ var flg = d[3];
3096
+ var st = 10;
3097
+ if (flg & 4)
3098
+ st += (d[10] | d[11] << 8) + 2;
3099
+ for (var zs = (flg >> 3 & 1) + (flg >> 4 & 1); zs > 0; zs -= !d[st++])
3100
+ ;
3101
+ return st + (flg & 2);
3102
+ };
3103
+ var gzl = function(d) {
3104
+ var l = d.length;
3105
+ return (d[l - 4] | d[l - 3] << 8 | d[l - 2] << 16 | d[l - 1] << 24) >>> 0;
3106
+ };
3107
+ var zls = function(d, dict) {
3108
+ if ((d[0] & 15) != 8 || d[0] >> 4 > 7 || (d[0] << 8 | d[1]) % 31)
3109
+ err(6, "invalid zlib data");
3110
+ if ((d[1] >> 5 & 1) == +!dict)
3111
+ err(6, "invalid zlib data: " + (d[1] & 32 ? "need" : "unexpected") + " dictionary");
3112
+ return (d[1] >> 3 & 4) + 2;
3113
+ };
3114
+ function inflateSync(data, opts) {
3115
+ return inflt(data, { i: 2 }, opts && opts.out, opts && opts.dictionary);
3116
+ }
3117
+ function gunzipSync(data, opts) {
3118
+ var st = gzs(data);
3119
+ if (st + 8 > data.length)
3120
+ err(6, "invalid gzip data");
3121
+ return inflt(data.subarray(st, -8), { i: 2 }, opts && opts.out || new u8(gzl(data)), opts && opts.dictionary);
3122
+ }
3123
+ function unzlibSync(data, opts) {
3124
+ return inflt(data.subarray(zls(data, opts && opts.dictionary), -4), { i: 2 }, opts && opts.out, opts && opts.dictionary);
3125
+ }
3126
+ function decompressSync(data, opts) {
3127
+ return data[0] == 31 && data[1] == 139 && data[2] == 8 ? gunzipSync(data, opts) : (data[0] & 15) != 8 || data[0] >> 4 > 7 || (data[0] << 8 | data[1]) % 31 ? inflateSync(data, opts) : unzlibSync(data, opts);
3128
+ }
3129
+ var td = typeof TextDecoder != "undefined" && /* @__PURE__ */ new TextDecoder();
3130
+ var tds = 0;
3131
+ try {
3132
+ td.decode(et, { stream: true });
3133
+ tds = 1;
3134
+ } catch (e) {
3135
+ }
3136
+
3137
+ // ../../node_modules/@aztec/bb.js/dest/node/barretenberg/backend.js
3138
+ var UltraPlonkBackend = class {
3139
+ constructor(acirBytecode, options = { threads: 1 }) {
3140
+ this.options = options;
3141
+ this.acirUncompressedBytecode = acirToUint8Array(acirBytecode);
3142
+ }
3143
+ /** @ignore */
3144
+ async instantiate() {
3145
+ if (!this.api) {
3146
+ const api = await Barretenberg.new(this.options);
3147
+ const honkRecursion = false;
3148
+ const [_total, subgroupSize] = await api.acirGetCircuitSizes(this.acirUncompressedBytecode, honkRecursion);
3149
+ await api.initSRSForCircuitSize(subgroupSize);
3150
+ this.acirComposer = await api.acirNewAcirComposer(subgroupSize);
3151
+ await api.acirInitProvingKey(this.acirComposer, this.acirUncompressedBytecode);
3152
+ this.api = api;
3153
+ }
3154
+ }
3155
+ /** @description Generates a proof */
3156
+ async generateProof(compressedWitness) {
3157
+ await this.instantiate();
3158
+ const proofWithPublicInputs = await this.api.acirCreateProof(this.acirComposer, this.acirUncompressedBytecode, decompressSync(compressedWitness));
3159
+ const numBytesInProofWithoutPublicInputs = 2144;
3160
+ const splitIndex = proofWithPublicInputs.length - numBytesInProofWithoutPublicInputs;
3161
+ const publicInputsConcatenated = proofWithPublicInputs.slice(0, splitIndex);
3162
+ const proof = proofWithPublicInputs.slice(splitIndex);
3163
+ const publicInputs = deflattenFields(publicInputsConcatenated);
3164
+ return { proof, publicInputs };
3165
+ }
3166
+ /**
3167
+ * Generates artifacts that will be passed to a circuit that will verify this proof.
3168
+ *
3169
+ * Instead of passing the proof and verification key as a byte array, we pass them
3170
+ * as fields which makes it cheaper to verify in a circuit.
3171
+ *
3172
+ * The proof that is passed here will have been created using a circuit
3173
+ * that has the #[recursive] attribute on its `main` method.
3174
+ *
3175
+ * The number of public inputs denotes how many public inputs are in the inner proof.
3176
+ *
3177
+ * @example
3178
+ * ```typescript
3179
+ * const artifacts = await backend.generateRecursiveProofArtifacts(proof, numOfPublicInputs);
3180
+ * ```
3181
+ */
3182
+ async generateRecursiveProofArtifacts(proofData, numOfPublicInputs = 0) {
3183
+ await this.instantiate();
3184
+ const proof = reconstructUltraPlonkProof(proofData);
3185
+ const proofAsFields = (await this.api.acirSerializeProofIntoFields(this.acirComposer, proof, numOfPublicInputs)).slice(numOfPublicInputs);
3186
+ await this.api.acirInitVerificationKey(this.acirComposer);
3187
+ const vk = await this.api.acirSerializeVerificationKeyIntoFields(this.acirComposer);
3188
+ return {
3189
+ proofAsFields: proofAsFields.map((p) => p.toString()),
3190
+ vkAsFields: vk[0].map((vk2) => vk2.toString()),
3191
+ vkHash: vk[1].toString()
3192
+ };
3193
+ }
3194
+ /** @description Verifies a proof */
3195
+ async verifyProof(proofData) {
3196
+ await this.instantiate();
3197
+ await this.api.acirInitVerificationKey(this.acirComposer);
3198
+ const proof = reconstructUltraPlonkProof(proofData);
3199
+ return await this.api.acirVerifyProof(this.acirComposer, proof);
3200
+ }
3201
+ async getVerificationKey() {
3202
+ await this.instantiate();
3203
+ await this.api.acirInitVerificationKey(this.acirComposer);
3204
+ return await this.api.acirGetVerificationKey(this.acirComposer);
3205
+ }
3206
+ async destroy() {
3207
+ if (!this.api) {
3208
+ return;
3209
+ }
3210
+ await this.api.destroy();
3211
+ }
3212
+ };
3213
+ var serializedBufferSize2 = 4;
3214
+ var fieldByteSize2 = 32;
3215
+ var publicInputOffset2 = 3;
3216
+ var publicInputsOffsetBytes2 = publicInputOffset2 * fieldByteSize2;
3217
+ var UltraHonkBackend = class {
3218
+ constructor(acirBytecode, options = { threads: 1 }) {
3219
+ this.options = options;
3220
+ this.acirUncompressedBytecode = acirToUint8Array(acirBytecode);
3221
+ }
3222
+ /** @ignore */
3223
+ async instantiate() {
3224
+ if (!this.api) {
3225
+ const api = await Barretenberg.new(this.options);
3226
+ const honkRecursion = true;
3227
+ await api.acirInitSRS(this.acirUncompressedBytecode, honkRecursion);
3228
+ this.api = api;
3229
+ }
3230
+ }
3231
+ async generateProof(compressedWitness) {
3232
+ await this.instantiate();
3233
+ const proofWithPublicInputs = await this.api.acirProveUltraHonk(this.acirUncompressedBytecode, decompressSync(compressedWitness));
3234
+ const proofAsStrings = deflattenFields(proofWithPublicInputs.slice(4));
3235
+ const numPublicInputs = Number(proofAsStrings[1]);
3236
+ const publicInputsOffset = publicInputsOffsetBytes2 + serializedBufferSize2;
3237
+ const proofStart = proofWithPublicInputs.slice(0, publicInputsOffset);
3238
+ const publicInputsSplitIndex = numPublicInputs * fieldByteSize2;
3239
+ const proofEnd = proofWithPublicInputs.slice(publicInputsOffset + publicInputsSplitIndex);
3240
+ const proof = new Uint8Array([...proofStart, ...proofEnd]);
3241
+ const publicInputsConcatenated = proofWithPublicInputs.slice(publicInputsOffset, publicInputsOffset + publicInputsSplitIndex);
3242
+ const publicInputs = deflattenFields(publicInputsConcatenated);
3243
+ return { proof, publicInputs };
3244
+ }
3245
+ async verifyProof(proofData) {
3246
+ await this.instantiate();
3247
+ const proof = reconstructHonkProof(flattenFieldsAsArray(proofData.publicInputs), proofData.proof);
3248
+ const vkBuf = await this.api.acirWriteVkUltraHonk(this.acirUncompressedBytecode);
3249
+ return await this.api.acirVerifyUltraHonk(proof, new RawBuffer(vkBuf));
3250
+ }
3251
+ async getVerificationKey() {
3252
+ await this.instantiate();
3253
+ return await this.api.acirWriteVkUltraHonk(this.acirUncompressedBytecode);
3254
+ }
3255
+ // TODO(https://github.com/noir-lang/noir/issues/5661): Update this to handle Honk recursive aggregation in the browser once it is ready in the backend itself
3256
+ async generateRecursiveProofArtifacts(_proof, _numOfPublicInputs) {
3257
+ await this.instantiate();
3258
+ const vkBuf = await this.api.acirWriteVkUltraHonk(this.acirUncompressedBytecode);
3259
+ const vk = await this.api.acirVkAsFieldsUltraHonk(vkBuf);
3260
+ return {
3261
+ // TODO(https://github.com/noir-lang/noir/issues/5661)
3262
+ proofAsFields: [],
3263
+ vkAsFields: vk.map((vk2) => vk2.toString()),
3264
+ // We use an empty string for the vk hash here as it is unneeded as part of the recursive artifacts
3265
+ // The user can be expected to hash the vk inside their circuit to check whether the vk is the circuit
3266
+ // they expect
3267
+ vkHash: ""
3268
+ };
3269
+ }
3270
+ async destroy() {
3271
+ if (!this.api) {
3272
+ return;
3273
+ }
3274
+ await this.api.destroy();
3275
+ }
3276
+ };
3277
+ function acirToUint8Array(base64EncodedBytecode) {
3278
+ const compressedByteCode = base64Decode(base64EncodedBytecode);
3279
+ return decompressSync(compressedByteCode);
3280
+ }
3281
+ function base64Decode(input) {
3282
+ if (typeof Buffer !== "undefined") {
3283
+ const b = Buffer.from(input, "base64");
3284
+ return new Uint8Array(b.buffer, b.byteOffset, b.byteLength);
3285
+ } else if (typeof atob === "function") {
3286
+ return Uint8Array.from(atob(input), (c) => c.charCodeAt(0));
3287
+ } else {
3288
+ throw new Error("No implementation found for base64 decoding.");
3289
+ }
3290
+ }
3291
+
3292
+ // ../../node_modules/@aztec/bb.js/dest/node/barretenberg/index.js
3293
+ var debug5 = (0, import_debug5.default)("bb.js:wasm");
3294
+ var Barretenberg = class _Barretenberg extends BarretenbergApi {
3295
+ constructor(worker, wasm, options) {
3296
+ super(wasm);
3297
+ this.worker = worker;
3298
+ this.options = options;
3299
+ }
3300
+ /**
3301
+ * Constructs an instance of Barretenberg.
3302
+ * Launches it within a worker. This is necessary as it blocks waiting on child threads to complete,
3303
+ * and blocking the main thread in the browser is not allowed.
3304
+ * It threads > 1 (defaults to hardware availability), child threads will be created on their own workers.
3305
+ */
3306
+ static async new(options = {}) {
3307
+ const worker = createMainWorker();
3308
+ const wasm = getRemoteBarretenbergWasm(worker);
3309
+ const { module, threads } = await fetchModuleAndThreads(options.threads);
3310
+ await wasm.init(module, threads, proxy(debug5), options.memory?.initial, options.memory?.maximum);
3311
+ return new _Barretenberg(worker, wasm, options);
3312
+ }
3313
+ async getNumThreads() {
3314
+ return await this.wasm.getNumThreads();
3315
+ }
3316
+ async initSRSForCircuitSize(circuitSize) {
3317
+ const crs = await Crs.new(circuitSize + 1, this.options.crsPath);
3318
+ await this.srsInitSrs(new RawBuffer(crs.getG1Data()), crs.numPoints, new RawBuffer(crs.getG2Data()));
3319
+ }
3320
+ async acirInitSRS(bytecode, honkRecursion) {
3321
+ const [_total, subgroupSize] = await this.acirGetCircuitSizes(bytecode, honkRecursion);
3322
+ return this.initSRSForCircuitSize(subgroupSize);
3323
+ }
3324
+ async destroy() {
3325
+ await this.wasm.destroy();
3326
+ await this.worker.terminate();
3327
+ }
3328
+ };
3329
+ var barretenbergSyncSingleton;
3330
+ var barretenbergSyncSingletonPromise;
3331
+ var BarretenbergSync = class _BarretenbergSync extends BarretenbergApiSync {
3332
+ constructor(wasm) {
3333
+ super(wasm);
3334
+ }
3335
+ static async new() {
3336
+ const wasm = new BarretenbergWasmMain();
3337
+ const { module, threads } = await fetchModuleAndThreads(1);
3338
+ await wasm.init(module, threads);
3339
+ return new _BarretenbergSync(wasm);
3340
+ }
3341
+ static initSingleton() {
3342
+ if (!barretenbergSyncSingletonPromise) {
3343
+ barretenbergSyncSingletonPromise = _BarretenbergSync.new().then((s) => barretenbergSyncSingleton = s);
3344
+ }
3345
+ return barretenbergSyncSingletonPromise;
3346
+ }
3347
+ static getSingleton() {
3348
+ if (!barretenbergSyncSingleton) {
3349
+ throw new Error("First call BarretenbergSync.initSingleton() on @aztec/bb.js module.");
3350
+ }
3351
+ return barretenbergSyncSingleton;
3352
+ }
3353
+ getWasm() {
3354
+ return this.wasm;
3355
+ }
3356
+ };
3357
+ await BarretenbergSync.initSingleton();
3358
+ export {
3359
+ Barretenberg,
3360
+ BarretenbergSync,
3361
+ BarretenbergVerifier,
3362
+ Crs,
3363
+ Fr,
3364
+ RawBuffer,
3365
+ UltraHonkBackend,
3366
+ UltraPlonkBackend,
3367
+ reconstructHonkProof,
3368
+ splitHonkProof
3369
+ };
3370
+ /*! Bundled license information:
3371
+
3372
+ comlink/dist/esm/comlink.mjs:
3373
+ (**
3374
+ * @license
3375
+ * Copyright 2019 Google LLC
3376
+ * SPDX-License-Identifier: Apache-2.0
3377
+ *)
3378
+ */