@nihilium/client-sdk 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1551 @@
1
+ import { Z as tt, j as O, V as R, X as et, b as I, q as vt, W as x, z, c as nt, e as Ut, B as St } from "./index-78RSe_cY.js";
2
+ /**
3
+ * @module @zk-kit/utils
4
+ * @version 1.2.1
5
+ * @file Essential zero-knowledge utility library for JavaScript developers.
6
+ * @copyright Ethereum Foundation 2024
7
+ * @license MIT
8
+ * @see [Github]{@link https://github.com/privacy-scaling-explorations/zk-kit/tree/main/packages/utils}
9
+ */
10
+ function Et(t) {
11
+ return I.Buffer.isBuffer(t);
12
+ }
13
+ function xt(t, e) {
14
+ if (!Et(t))
15
+ throw new TypeError(`Parameter '${e}' is not a Buffer instance`);
16
+ }
17
+ function Kt(t) {
18
+ if (t <= 0)
19
+ throw Error(`size ${t} is too small, need at least 1`);
20
+ return crypto.getRandomValues(new Uint8Array(t));
21
+ }
22
+ var Pt = /* @__PURE__ */ Object.freeze({
23
+ __proto__: null,
24
+ getRandomValues: Kt
25
+ });
26
+ /**
27
+ * @module @zk-kit/utils
28
+ * @version 1.2.1
29
+ * @file Essential zero-knowledge utility library for JavaScript developers.
30
+ * @copyright Ethereum Foundation 2024
31
+ * @license MIT
32
+ * @see [Github]{@link https://github.com/privacy-scaling-explorations/zk-kit/tree/main/packages/utils}
33
+ */
34
+ const Ot = [
35
+ "number",
36
+ "string",
37
+ "function",
38
+ "Array",
39
+ "Uint8Array",
40
+ "Buffer",
41
+ "object",
42
+ "bigint",
43
+ "stringified-bigint",
44
+ "hexadecimal",
45
+ "bignumber",
46
+ "bignumberish"
47
+ ];
48
+ function gt(t) {
49
+ return typeof t == "number";
50
+ }
51
+ function X(t) {
52
+ return typeof t == "string";
53
+ }
54
+ function Rt(t) {
55
+ return typeof t == "function";
56
+ }
57
+ function G(t) {
58
+ return typeof t == "object";
59
+ }
60
+ function dt(t) {
61
+ return G(t) && Array.isArray(t);
62
+ }
63
+ function N(t) {
64
+ return t instanceof Uint8Array;
65
+ }
66
+ function Q(t) {
67
+ return I.Buffer.isBuffer(t);
68
+ }
69
+ function H(t) {
70
+ return typeof t == "bigint";
71
+ }
72
+ function Y(t) {
73
+ if (!X(t))
74
+ return !1;
75
+ try {
76
+ return BigInt(t), !0;
77
+ } catch {
78
+ return !1;
79
+ }
80
+ }
81
+ function pt(t, e = !0) {
82
+ return X(t) ? e ? /^(0x|0X)[0-9a-fA-F]+$/.test(t) : /^[0-9a-fA-F]+$/.test(t) : !1;
83
+ }
84
+ function j(t) {
85
+ return H(t) || Y(t);
86
+ }
87
+ function J(t) {
88
+ return gt(t) || H(t) || Y(t) || pt(t) || Q(t) || N(t);
89
+ }
90
+ function zt(t, e) {
91
+ switch (e) {
92
+ case "number":
93
+ return gt(t);
94
+ case "string":
95
+ return X(t);
96
+ case "function":
97
+ return Rt(t);
98
+ case "Array":
99
+ return dt(t);
100
+ case "Uint8Array":
101
+ return N(t);
102
+ case "Buffer":
103
+ return Q(t);
104
+ case "object":
105
+ return G(t);
106
+ case "bigint":
107
+ return H(t);
108
+ case "stringified-bigint":
109
+ return Y(t);
110
+ case "hexadecimal":
111
+ return pt(t);
112
+ case "bignumber":
113
+ return j(t);
114
+ case "bignumberish":
115
+ return J(t);
116
+ default:
117
+ return !1;
118
+ }
119
+ }
120
+ function $t(t) {
121
+ return Ot.includes(t);
122
+ }
123
+ /**
124
+ * @module @zk-kit/utils
125
+ * @version 1.2.1
126
+ * @file Essential zero-knowledge utility library for JavaScript developers.
127
+ * @copyright Ethereum Foundation 2024
128
+ * @license MIT
129
+ * @see [Github]{@link https://github.com/privacy-scaling-explorations/zk-kit/tree/main/packages/utils}
130
+ */
131
+ function jt(t, e) {
132
+ if (!H(t))
133
+ throw new TypeError(`Parameter '${e}' is not a bigint, received type: ${typeof t}`);
134
+ }
135
+ function wt(t, e) {
136
+ if (!J(t))
137
+ throw new TypeError(`Parameter '${e}' is not a bignumber-ish`);
138
+ }
139
+ function F(t, e, r) {
140
+ for (const n of r)
141
+ if (!$t(n))
142
+ throw new Error(`Type '${n}' is not supported`);
143
+ for (const n of r)
144
+ if (zt(t, n))
145
+ return;
146
+ throw new TypeError(`Parameter '${e}' is none of the following types: ${r.join(", ")}`);
147
+ }
148
+ /**
149
+ * @module @zk-kit/utils
150
+ * @version 1.2.1
151
+ * @file Essential zero-knowledge utility library for JavaScript developers.
152
+ * @copyright Ethereum Foundation 2024
153
+ * @license MIT
154
+ * @see [Github]{@link https://github.com/privacy-scaling-explorations/zk-kit/tree/main/packages/utils}
155
+ */
156
+ function Ht(t) {
157
+ jt(t, "value");
158
+ let e = t.toString(16);
159
+ return e.length % 2 !== 0 && (e = `0${e}`), e;
160
+ }
161
+ function Ft(t) {
162
+ return F(t, "value", ["Buffer", "Uint8Array"]), BigInt(`0x${I.Buffer.from(t).toString("hex")}`);
163
+ }
164
+ function K(t) {
165
+ return F(t, "value", ["Buffer", "Uint8Array"]), BigInt(`0x${I.Buffer.from(t).reverse().toString("hex")}`);
166
+ }
167
+ function yt(t) {
168
+ return Ft(t);
169
+ }
170
+ function T(t, e) {
171
+ const r = Ht(t), n = Math.ceil(r.length / 2);
172
+ if (e < n)
173
+ throw Error(`Size ${e} is too small, need at least ${n} bytes`);
174
+ const g = I.Buffer.alloc(e, 0);
175
+ return I.Buffer.from(r, "hex").reverse().copy(g, 0), g;
176
+ }
177
+ function kt(t) {
178
+ return wt(t, "value"), Q(t) || N(t) ? yt(t) : BigInt(t);
179
+ }
180
+ /**
181
+ * @module @zk-kit/utils
182
+ * @version 1.2.1
183
+ * @file Essential zero-knowledge utility library for JavaScript developers.
184
+ * @copyright Ethereum Foundation 2024
185
+ * @license MIT
186
+ * @see [Github]{@link https://github.com/privacy-scaling-explorations/zk-kit/tree/main/packages/utils}
187
+ */
188
+ function Tt(t) {
189
+ return !t;
190
+ }
191
+ function rt(t, e) {
192
+ return t >> e;
193
+ }
194
+ function qt(t, e) {
195
+ return t * e;
196
+ }
197
+ function Dt(t) {
198
+ const e = [];
199
+ let r = t;
200
+ for (; r; )
201
+ r & BigInt(1) ? e.push(1) : e.push(0), r >>= BigInt(1);
202
+ return e;
203
+ }
204
+ /**
205
+ * @module @zk-kit/utils
206
+ * @version 1.2.1
207
+ * @file Essential zero-knowledge utility library for JavaScript developers.
208
+ * @copyright Ethereum Foundation 2024
209
+ * @license MIT
210
+ * @see [Github]{@link https://github.com/privacy-scaling-explorations/zk-kit/tree/main/packages/utils}
211
+ */
212
+ class Mt {
213
+ constructor(e) {
214
+ this.one = 1n, this.zero = 0n, this._order = e, this._half = e >> this.one, this._negone = this._order - this.one;
215
+ }
216
+ /**
217
+ * Ensures a given result falls within the field by applying modular reduction.
218
+ * This method also handles negative inputs, correctly mapping them into the field.
219
+ * @param res The result to be normalized to the field.
220
+ * @returns The equivalent value within the field.
221
+ */
222
+ e(e) {
223
+ return e %= this._order, e < 0 ? e + this._order : e;
224
+ }
225
+ /**
226
+ * Performs modular multiplication of two bigint values within the field.
227
+ * @param a The first value.
228
+ * @param b The second value.
229
+ * @returns The product of 'a' and 'b' modulo the field's order.
230
+ */
231
+ mul(e, r) {
232
+ return e * r % this._order;
233
+ }
234
+ /**
235
+ * Subtracts one bigint from another under modulus.
236
+ * It ensures the result is within the field if and only if the input values are within the field.
237
+ * @param a The value from which to subtract.
238
+ * @param b The value to be subtracted.
239
+ * @returns The difference of 'a' and 'b' modulo the field's order.
240
+ */
241
+ sub(e, r) {
242
+ return e >= r ? e - r : this._order - r + e;
243
+ }
244
+ /**
245
+ * Adds two bigint values together under modulus.
246
+ * It ensures the result is within the field if and only if the input values are within the field.
247
+ * @param a The first value.
248
+ * @param b The second value.
249
+ * @returns The sum of 'a' and 'b' modulo the field's order.
250
+ */
251
+ add(e, r) {
252
+ const n = e + r;
253
+ return n >= this._order ? n - this._order : n;
254
+ }
255
+ /**
256
+ * Computes the multiplicative inverse of a given value within the field.
257
+ * This method uses the Extended Euclidean Algorithm to find the inverse,
258
+ * ensuring the result is always a positive value less than the field's order.
259
+ * If the input value is zero, which has no inverse, an error is thrown.
260
+ * @param a The value for which to compute the inverse.
261
+ * @returns The multiplicative inverse of 'a' modulo the field's order.
262
+ * @throws if 'a' is zero.
263
+ */
264
+ inv(e) {
265
+ if (e === this.zero)
266
+ throw new Error("Zero has no inverse");
267
+ let r = this.zero, n = this._order, g = this.one, h = e % this._order;
268
+ for (; h; ) {
269
+ const f = n / h;
270
+ [r, g] = [g, r - f * g], [n, h] = [h, n - f * h];
271
+ }
272
+ return r < this.zero && (r += this._order), r;
273
+ }
274
+ /**
275
+ * Divides one bigint by another within the field by multiplying the first value
276
+ * by the multiplicative inverse of the second.
277
+ * @param a The dividend.
278
+ * @param b The divisor.
279
+ * @returns The result of the division of 'a' by 'b' modulo the field's order.
280
+ */
281
+ div(e, r) {
282
+ return this.mul(e, this.inv(r));
283
+ }
284
+ /**
285
+ * Checks if two bigint values are equal within the context of the field.
286
+ * It ensures the result is within the field if and only if the input values are within the field.
287
+ * @param a The first value to compare.
288
+ * @param b The second value to compare.
289
+ * @returns True if 'a' equals 'b', false otherwise.
290
+ */
291
+ eq(e, r) {
292
+ return e === r;
293
+ }
294
+ /**
295
+ * Squares a bigint value within the field.
296
+ * This is a specific case of multiplication where the value is multiplied by itself,
297
+ * optimized for performance where applicable.
298
+ * It ensures the result is within the field if and only if the input values are within the field.
299
+ * @param a The value to square.
300
+ * @returns The square of 'a' modulo the field's order.
301
+ */
302
+ square(e) {
303
+ return e * e % this._order;
304
+ }
305
+ /**
306
+ * Compares two bigint values to determine if the first is less than the second,
307
+ * taking into account the field's order for modular comparison.
308
+ * It ensures the result is within the field if and only if the input values are within the field.
309
+ * @param a The first value to compare.
310
+ * @param b The second value to compare.
311
+ * @returns True if 'a' is less than 'b', false otherwise.
312
+ */
313
+ lt(e, r) {
314
+ const n = e > this._half ? e - this._order : e, g = r > this._half ? r - this._order : r;
315
+ return n < g;
316
+ }
317
+ /**
318
+ * Compares two bigint values to determine if the first is greater than or equal to the second,
319
+ * considering the field's modular context.
320
+ * It ensures the result is within the field if and only if the input values are within the field.
321
+ * @param a The first value to compare.
322
+ * @param b The second value to compare.
323
+ * @returns True if 'a' is greater than or equal to 'b', false otherwise.
324
+ */
325
+ geq(e, r) {
326
+ const n = e > this._half ? e - this._order : e, g = r > this._half ? r - this._order : r;
327
+ return n >= g;
328
+ }
329
+ /**
330
+ * Computes the negation of a bigint value within the field.
331
+ * The result is the modular additive inverse that, when added to the original value,
332
+ * yields zero in the field's modulus.
333
+ * It ensures the result is within the field if and only if the input values are within the field.
334
+ * @param a The value to negate.
335
+ * @returns The negation of 'a' modulo the field's order.
336
+ */
337
+ neg(e) {
338
+ return e && this._order - e;
339
+ }
340
+ /**
341
+ * Checks if a bigint value is zero within the context of the field.
342
+ * @param a The value to check.
343
+ * @returns True if 'a' is zero, false otherwise.
344
+ */
345
+ isZero(e) {
346
+ return e === this.zero;
347
+ }
348
+ /**
349
+ * Raises a base to an exponent within the field, efficiently computing
350
+ * scalar exponentiation using the square-and-multiply algorithm.
351
+ * Supports both positive and negative exponents through the use of the `inv` method for negatives.
352
+ * @param base The base to be exponentiated.
353
+ * @param e The exponent.
354
+ * @returns The result of raising 'base' to the power 'e' modulo the field's order.
355
+ */
356
+ pow(e, r) {
357
+ if (Tt(r))
358
+ return this.one;
359
+ r < 0n && (e = this.inv(e), r = -r);
360
+ const n = Dt(r);
361
+ if (n.length === 0)
362
+ return this.one;
363
+ let g = e;
364
+ for (let h = n.length - 2; h >= 0; h -= 1)
365
+ g = this.square(g), n[h] && (g = this.mul(g, e));
366
+ return g;
367
+ }
368
+ }
369
+ var it = vt(), q, ot;
370
+ function _t() {
371
+ if (ot) return q;
372
+ ot = 1;
373
+ const t = "Input must be an string, Buffer or Uint8Array";
374
+ function e(f) {
375
+ let a;
376
+ if (f instanceof Uint8Array)
377
+ a = f;
378
+ else if (typeof f == "string")
379
+ a = new TextEncoder().encode(f);
380
+ else
381
+ throw new Error(t);
382
+ return a;
383
+ }
384
+ function r(f) {
385
+ return Array.prototype.map.call(f, function(a) {
386
+ return (a < 16 ? "0" : "") + a.toString(16);
387
+ }).join("");
388
+ }
389
+ function n(f) {
390
+ return (4294967296 + f).toString(16).substring(1);
391
+ }
392
+ function g(f, a, u) {
393
+ let k = `
394
+ ` + f + " = ";
395
+ for (let b = 0; b < a.length; b += 2) {
396
+ if (u === 32)
397
+ k += n(a[b]).toUpperCase(), k += " ", k += n(a[b + 1]).toUpperCase();
398
+ else if (u === 64)
399
+ k += n(a[b + 1]).toUpperCase(), k += n(a[b]).toUpperCase();
400
+ else throw new Error("Invalid size " + u);
401
+ b % 6 === 4 ? k += `
402
+ ` + new Array(f.length + 4).join(" ") : b < a.length - 2 && (k += " ");
403
+ }
404
+ console.log(k);
405
+ }
406
+ function h(f, a, u) {
407
+ let k = (/* @__PURE__ */ new Date()).getTime();
408
+ const b = new Uint8Array(a);
409
+ for (let y = 0; y < a; y++)
410
+ b[y] = y % 256;
411
+ const l = (/* @__PURE__ */ new Date()).getTime();
412
+ console.log("Generated random input in " + (l - k) + "ms"), k = l;
413
+ for (let y = 0; y < u; y++) {
414
+ const B = f(b), c = (/* @__PURE__ */ new Date()).getTime(), p = c - k;
415
+ k = c, console.log("Hashed in " + p + "ms: " + B.substring(0, 20) + "..."), console.log(
416
+ Math.round(a / (1 << 20) / (p / 1e3) * 100) / 100 + " MB PER SECOND"
417
+ );
418
+ }
419
+ }
420
+ return q = {
421
+ normalizeInput: e,
422
+ toHex: r,
423
+ debugPrint: g,
424
+ testSpeed: h
425
+ }, q;
426
+ }
427
+ var D, st;
428
+ function Ct() {
429
+ if (st) return D;
430
+ st = 1;
431
+ const t = _t();
432
+ function e(i, d, o) {
433
+ const w = i[d] + i[o];
434
+ let _ = i[d + 1] + i[o + 1];
435
+ w >= 4294967296 && _++, i[d] = w, i[d + 1] = _;
436
+ }
437
+ function r(i, d, o, w) {
438
+ let _ = i[d] + o;
439
+ o < 0 && (_ += 4294967296);
440
+ let m = i[d + 1] + w;
441
+ _ >= 4294967296 && m++, i[d] = _, i[d + 1] = m;
442
+ }
443
+ function n(i, d) {
444
+ return i[d] ^ i[d + 1] << 8 ^ i[d + 2] << 16 ^ i[d + 3] << 24;
445
+ }
446
+ function g(i, d, o, w, _, m) {
447
+ const Bt = k[_], mt = k[_ + 1], It = k[m], At = k[m + 1];
448
+ e(u, i, d), r(u, i, Bt, mt);
449
+ let A = u[w] ^ u[i], v = u[w + 1] ^ u[i + 1];
450
+ u[w] = v, u[w + 1] = A, e(u, o, w), A = u[d] ^ u[o], v = u[d + 1] ^ u[o + 1], u[d] = A >>> 24 ^ v << 8, u[d + 1] = v >>> 24 ^ A << 8, e(u, i, d), r(u, i, It, At), A = u[w] ^ u[i], v = u[w + 1] ^ u[i + 1], u[w] = A >>> 16 ^ v << 16, u[w + 1] = v >>> 16 ^ A << 16, e(u, o, w), A = u[d] ^ u[o], v = u[d + 1] ^ u[o + 1], u[d] = v >>> 31 ^ A << 1, u[d + 1] = A >>> 31 ^ v << 1;
451
+ }
452
+ const h = new Uint32Array([
453
+ 4089235720,
454
+ 1779033703,
455
+ 2227873595,
456
+ 3144134277,
457
+ 4271175723,
458
+ 1013904242,
459
+ 1595750129,
460
+ 2773480762,
461
+ 2917565137,
462
+ 1359893119,
463
+ 725511199,
464
+ 2600822924,
465
+ 4215389547,
466
+ 528734635,
467
+ 327033209,
468
+ 1541459225
469
+ ]), f = [
470
+ 0,
471
+ 1,
472
+ 2,
473
+ 3,
474
+ 4,
475
+ 5,
476
+ 6,
477
+ 7,
478
+ 8,
479
+ 9,
480
+ 10,
481
+ 11,
482
+ 12,
483
+ 13,
484
+ 14,
485
+ 15,
486
+ 14,
487
+ 10,
488
+ 4,
489
+ 8,
490
+ 9,
491
+ 15,
492
+ 13,
493
+ 6,
494
+ 1,
495
+ 12,
496
+ 0,
497
+ 2,
498
+ 11,
499
+ 7,
500
+ 5,
501
+ 3,
502
+ 11,
503
+ 8,
504
+ 12,
505
+ 0,
506
+ 5,
507
+ 2,
508
+ 15,
509
+ 13,
510
+ 10,
511
+ 14,
512
+ 3,
513
+ 6,
514
+ 7,
515
+ 1,
516
+ 9,
517
+ 4,
518
+ 7,
519
+ 9,
520
+ 3,
521
+ 1,
522
+ 13,
523
+ 12,
524
+ 11,
525
+ 14,
526
+ 2,
527
+ 6,
528
+ 5,
529
+ 10,
530
+ 4,
531
+ 0,
532
+ 15,
533
+ 8,
534
+ 9,
535
+ 0,
536
+ 5,
537
+ 7,
538
+ 2,
539
+ 4,
540
+ 10,
541
+ 15,
542
+ 14,
543
+ 1,
544
+ 11,
545
+ 12,
546
+ 6,
547
+ 8,
548
+ 3,
549
+ 13,
550
+ 2,
551
+ 12,
552
+ 6,
553
+ 10,
554
+ 0,
555
+ 11,
556
+ 8,
557
+ 3,
558
+ 4,
559
+ 13,
560
+ 7,
561
+ 5,
562
+ 15,
563
+ 14,
564
+ 1,
565
+ 9,
566
+ 12,
567
+ 5,
568
+ 1,
569
+ 15,
570
+ 14,
571
+ 13,
572
+ 4,
573
+ 10,
574
+ 0,
575
+ 7,
576
+ 6,
577
+ 3,
578
+ 9,
579
+ 2,
580
+ 8,
581
+ 11,
582
+ 13,
583
+ 11,
584
+ 7,
585
+ 14,
586
+ 12,
587
+ 1,
588
+ 3,
589
+ 9,
590
+ 5,
591
+ 0,
592
+ 15,
593
+ 4,
594
+ 8,
595
+ 6,
596
+ 2,
597
+ 10,
598
+ 6,
599
+ 15,
600
+ 14,
601
+ 9,
602
+ 11,
603
+ 3,
604
+ 0,
605
+ 8,
606
+ 12,
607
+ 2,
608
+ 13,
609
+ 7,
610
+ 1,
611
+ 4,
612
+ 10,
613
+ 5,
614
+ 10,
615
+ 2,
616
+ 8,
617
+ 4,
618
+ 7,
619
+ 6,
620
+ 1,
621
+ 5,
622
+ 15,
623
+ 11,
624
+ 9,
625
+ 14,
626
+ 3,
627
+ 12,
628
+ 13,
629
+ 0,
630
+ 0,
631
+ 1,
632
+ 2,
633
+ 3,
634
+ 4,
635
+ 5,
636
+ 6,
637
+ 7,
638
+ 8,
639
+ 9,
640
+ 10,
641
+ 11,
642
+ 12,
643
+ 13,
644
+ 14,
645
+ 15,
646
+ 14,
647
+ 10,
648
+ 4,
649
+ 8,
650
+ 9,
651
+ 15,
652
+ 13,
653
+ 6,
654
+ 1,
655
+ 12,
656
+ 0,
657
+ 2,
658
+ 11,
659
+ 7,
660
+ 5,
661
+ 3
662
+ ], a = new Uint8Array(
663
+ f.map(function(i) {
664
+ return i * 2;
665
+ })
666
+ ), u = new Uint32Array(32), k = new Uint32Array(32);
667
+ function b(i, d) {
668
+ let o = 0;
669
+ for (o = 0; o < 16; o++)
670
+ u[o] = i.h[o], u[o + 16] = h[o];
671
+ for (u[24] = u[24] ^ i.t, u[25] = u[25] ^ i.t / 4294967296, d && (u[28] = ~u[28], u[29] = ~u[29]), o = 0; o < 32; o++)
672
+ k[o] = n(i.b, 4 * o);
673
+ for (o = 0; o < 12; o++)
674
+ g(0, 8, 16, 24, a[o * 16 + 0], a[o * 16 + 1]), g(2, 10, 18, 26, a[o * 16 + 2], a[o * 16 + 3]), g(4, 12, 20, 28, a[o * 16 + 4], a[o * 16 + 5]), g(6, 14, 22, 30, a[o * 16 + 6], a[o * 16 + 7]), g(0, 10, 20, 30, a[o * 16 + 8], a[o * 16 + 9]), g(2, 12, 22, 24, a[o * 16 + 10], a[o * 16 + 11]), g(4, 14, 16, 26, a[o * 16 + 12], a[o * 16 + 13]), g(6, 8, 18, 28, a[o * 16 + 14], a[o * 16 + 15]);
675
+ for (o = 0; o < 16; o++)
676
+ i.h[o] = i.h[o] ^ u[o] ^ u[o + 16];
677
+ }
678
+ const l = new Uint8Array([
679
+ 0,
680
+ 0,
681
+ 0,
682
+ 0,
683
+ // 0: outlen, keylen, fanout, depth
684
+ 0,
685
+ 0,
686
+ 0,
687
+ 0,
688
+ // 4: leaf length, sequential mode
689
+ 0,
690
+ 0,
691
+ 0,
692
+ 0,
693
+ // 8: node offset
694
+ 0,
695
+ 0,
696
+ 0,
697
+ 0,
698
+ // 12: node offset
699
+ 0,
700
+ 0,
701
+ 0,
702
+ 0,
703
+ // 16: node depth, inner length, rfu
704
+ 0,
705
+ 0,
706
+ 0,
707
+ 0,
708
+ // 20: rfu
709
+ 0,
710
+ 0,
711
+ 0,
712
+ 0,
713
+ // 24: rfu
714
+ 0,
715
+ 0,
716
+ 0,
717
+ 0,
718
+ // 28: rfu
719
+ 0,
720
+ 0,
721
+ 0,
722
+ 0,
723
+ // 32: salt
724
+ 0,
725
+ 0,
726
+ 0,
727
+ 0,
728
+ // 36: salt
729
+ 0,
730
+ 0,
731
+ 0,
732
+ 0,
733
+ // 40: salt
734
+ 0,
735
+ 0,
736
+ 0,
737
+ 0,
738
+ // 44: salt
739
+ 0,
740
+ 0,
741
+ 0,
742
+ 0,
743
+ // 48: personal
744
+ 0,
745
+ 0,
746
+ 0,
747
+ 0,
748
+ // 52: personal
749
+ 0,
750
+ 0,
751
+ 0,
752
+ 0,
753
+ // 56: personal
754
+ 0,
755
+ 0,
756
+ 0,
757
+ 0
758
+ // 60: personal
759
+ ]);
760
+ function y(i, d, o, w) {
761
+ if (i === 0 || i > 64)
762
+ throw new Error("Illegal output length, expected 0 < length <= 64");
763
+ if (d && d.length > 64)
764
+ throw new Error("Illegal key, expected Uint8Array with 0 < length <= 64");
765
+ if (o && o.length !== 16)
766
+ throw new Error("Illegal salt, expected Uint8Array with length is 16");
767
+ if (w && w.length !== 16)
768
+ throw new Error("Illegal personal, expected Uint8Array with length is 16");
769
+ const _ = {
770
+ b: new Uint8Array(128),
771
+ h: new Uint32Array(16),
772
+ t: 0,
773
+ // input count
774
+ c: 0,
775
+ // pointer within buffer
776
+ outlen: i
777
+ // output length in bytes
778
+ };
779
+ l.fill(0), l[0] = i, d && (l[1] = d.length), l[2] = 1, l[3] = 1, o && l.set(o, 32), w && l.set(w, 48);
780
+ for (let m = 0; m < 16; m++)
781
+ _.h[m] = h[m] ^ n(l, m * 4);
782
+ return d && (B(_, d), _.c = 128), _;
783
+ }
784
+ function B(i, d) {
785
+ for (let o = 0; o < d.length; o++)
786
+ i.c === 128 && (i.t += i.c, b(i, !1), i.c = 0), i.b[i.c++] = d[o];
787
+ }
788
+ function c(i) {
789
+ for (i.t += i.c; i.c < 128; )
790
+ i.b[i.c++] = 0;
791
+ b(i, !0);
792
+ const d = new Uint8Array(i.outlen);
793
+ for (let o = 0; o < i.outlen; o++)
794
+ d[o] = i.h[o >> 2] >> 8 * (o & 3);
795
+ return d;
796
+ }
797
+ function p(i, d, o, w, _) {
798
+ o = o || 64, i = t.normalizeInput(i), w && (w = t.normalizeInput(w)), _ && (_ = t.normalizeInput(_));
799
+ const m = y(o, d, w, _);
800
+ return B(m, i), c(m);
801
+ }
802
+ function s(i, d, o, w, _) {
803
+ const m = p(i, d, o, w, _);
804
+ return t.toHex(m);
805
+ }
806
+ return D = {
807
+ blake2b: p,
808
+ blake2bHex: s,
809
+ blake2bInit: y,
810
+ blake2bUpdate: B,
811
+ blake2bFinal: c
812
+ }, D;
813
+ }
814
+ var M, ut;
815
+ function Lt() {
816
+ if (ut) return M;
817
+ ut = 1;
818
+ const t = _t();
819
+ function e(c, p) {
820
+ return c[p] ^ c[p + 1] << 8 ^ c[p + 2] << 16 ^ c[p + 3] << 24;
821
+ }
822
+ function r(c, p, s, i, d, o) {
823
+ f[c] = f[c] + f[p] + d, f[i] = n(f[i] ^ f[c], 16), f[s] = f[s] + f[i], f[p] = n(f[p] ^ f[s], 12), f[c] = f[c] + f[p] + o, f[i] = n(f[i] ^ f[c], 8), f[s] = f[s] + f[i], f[p] = n(f[p] ^ f[s], 7);
824
+ }
825
+ function n(c, p) {
826
+ return c >>> p ^ c << 32 - p;
827
+ }
828
+ const g = new Uint32Array([
829
+ 1779033703,
830
+ 3144134277,
831
+ 1013904242,
832
+ 2773480762,
833
+ 1359893119,
834
+ 2600822924,
835
+ 528734635,
836
+ 1541459225
837
+ ]), h = new Uint8Array([
838
+ 0,
839
+ 1,
840
+ 2,
841
+ 3,
842
+ 4,
843
+ 5,
844
+ 6,
845
+ 7,
846
+ 8,
847
+ 9,
848
+ 10,
849
+ 11,
850
+ 12,
851
+ 13,
852
+ 14,
853
+ 15,
854
+ 14,
855
+ 10,
856
+ 4,
857
+ 8,
858
+ 9,
859
+ 15,
860
+ 13,
861
+ 6,
862
+ 1,
863
+ 12,
864
+ 0,
865
+ 2,
866
+ 11,
867
+ 7,
868
+ 5,
869
+ 3,
870
+ 11,
871
+ 8,
872
+ 12,
873
+ 0,
874
+ 5,
875
+ 2,
876
+ 15,
877
+ 13,
878
+ 10,
879
+ 14,
880
+ 3,
881
+ 6,
882
+ 7,
883
+ 1,
884
+ 9,
885
+ 4,
886
+ 7,
887
+ 9,
888
+ 3,
889
+ 1,
890
+ 13,
891
+ 12,
892
+ 11,
893
+ 14,
894
+ 2,
895
+ 6,
896
+ 5,
897
+ 10,
898
+ 4,
899
+ 0,
900
+ 15,
901
+ 8,
902
+ 9,
903
+ 0,
904
+ 5,
905
+ 7,
906
+ 2,
907
+ 4,
908
+ 10,
909
+ 15,
910
+ 14,
911
+ 1,
912
+ 11,
913
+ 12,
914
+ 6,
915
+ 8,
916
+ 3,
917
+ 13,
918
+ 2,
919
+ 12,
920
+ 6,
921
+ 10,
922
+ 0,
923
+ 11,
924
+ 8,
925
+ 3,
926
+ 4,
927
+ 13,
928
+ 7,
929
+ 5,
930
+ 15,
931
+ 14,
932
+ 1,
933
+ 9,
934
+ 12,
935
+ 5,
936
+ 1,
937
+ 15,
938
+ 14,
939
+ 13,
940
+ 4,
941
+ 10,
942
+ 0,
943
+ 7,
944
+ 6,
945
+ 3,
946
+ 9,
947
+ 2,
948
+ 8,
949
+ 11,
950
+ 13,
951
+ 11,
952
+ 7,
953
+ 14,
954
+ 12,
955
+ 1,
956
+ 3,
957
+ 9,
958
+ 5,
959
+ 0,
960
+ 15,
961
+ 4,
962
+ 8,
963
+ 6,
964
+ 2,
965
+ 10,
966
+ 6,
967
+ 15,
968
+ 14,
969
+ 9,
970
+ 11,
971
+ 3,
972
+ 0,
973
+ 8,
974
+ 12,
975
+ 2,
976
+ 13,
977
+ 7,
978
+ 1,
979
+ 4,
980
+ 10,
981
+ 5,
982
+ 10,
983
+ 2,
984
+ 8,
985
+ 4,
986
+ 7,
987
+ 6,
988
+ 1,
989
+ 5,
990
+ 15,
991
+ 11,
992
+ 9,
993
+ 14,
994
+ 3,
995
+ 12,
996
+ 13,
997
+ 0
998
+ ]), f = new Uint32Array(16), a = new Uint32Array(16);
999
+ function u(c, p) {
1000
+ let s = 0;
1001
+ for (s = 0; s < 8; s++)
1002
+ f[s] = c.h[s], f[s + 8] = g[s];
1003
+ for (f[12] ^= c.t, f[13] ^= c.t / 4294967296, p && (f[14] = ~f[14]), s = 0; s < 16; s++)
1004
+ a[s] = e(c.b, 4 * s);
1005
+ for (s = 0; s < 10; s++)
1006
+ r(0, 4, 8, 12, a[h[s * 16 + 0]], a[h[s * 16 + 1]]), r(1, 5, 9, 13, a[h[s * 16 + 2]], a[h[s * 16 + 3]]), r(2, 6, 10, 14, a[h[s * 16 + 4]], a[h[s * 16 + 5]]), r(3, 7, 11, 15, a[h[s * 16 + 6]], a[h[s * 16 + 7]]), r(0, 5, 10, 15, a[h[s * 16 + 8]], a[h[s * 16 + 9]]), r(1, 6, 11, 12, a[h[s * 16 + 10]], a[h[s * 16 + 11]]), r(2, 7, 8, 13, a[h[s * 16 + 12]], a[h[s * 16 + 13]]), r(3, 4, 9, 14, a[h[s * 16 + 14]], a[h[s * 16 + 15]]);
1007
+ for (s = 0; s < 8; s++)
1008
+ c.h[s] ^= f[s] ^ f[s + 8];
1009
+ }
1010
+ function k(c, p) {
1011
+ if (!(c > 0 && c <= 32))
1012
+ throw new Error("Incorrect output length, should be in [1, 32]");
1013
+ const s = p ? p.length : 0;
1014
+ if (p && !(s > 0 && s <= 32))
1015
+ throw new Error("Incorrect key length, should be in [1, 32]");
1016
+ const i = {
1017
+ h: new Uint32Array(g),
1018
+ // hash state
1019
+ b: new Uint8Array(64),
1020
+ // input block
1021
+ c: 0,
1022
+ // pointer within block
1023
+ t: 0,
1024
+ // input count
1025
+ outlen: c
1026
+ // output length in bytes
1027
+ };
1028
+ return i.h[0] ^= 16842752 ^ s << 8 ^ c, s > 0 && (b(i, p), i.c = 64), i;
1029
+ }
1030
+ function b(c, p) {
1031
+ for (let s = 0; s < p.length; s++)
1032
+ c.c === 64 && (c.t += c.c, u(c, !1), c.c = 0), c.b[c.c++] = p[s];
1033
+ }
1034
+ function l(c) {
1035
+ for (c.t += c.c; c.c < 64; )
1036
+ c.b[c.c++] = 0;
1037
+ u(c, !0);
1038
+ const p = new Uint8Array(c.outlen);
1039
+ for (let s = 0; s < c.outlen; s++)
1040
+ p[s] = c.h[s >> 2] >> 8 * (s & 3) & 255;
1041
+ return p;
1042
+ }
1043
+ function y(c, p, s) {
1044
+ s = s || 32, c = t.normalizeInput(c);
1045
+ const i = k(s, p);
1046
+ return b(i, c), l(i);
1047
+ }
1048
+ function B(c, p, s) {
1049
+ const i = y(c, p, s);
1050
+ return t.toHex(i);
1051
+ }
1052
+ return M = {
1053
+ blake2s: y,
1054
+ blake2sHex: B,
1055
+ blake2sInit: k,
1056
+ blake2sUpdate: b,
1057
+ blake2sFinal: l
1058
+ }, M;
1059
+ }
1060
+ var C, at;
1061
+ function Vt() {
1062
+ if (at) return C;
1063
+ at = 1;
1064
+ const t = Ct(), e = Lt();
1065
+ return C = {
1066
+ blake2b: t.blake2b,
1067
+ blake2bHex: t.blake2bHex,
1068
+ blake2bInit: t.blake2bInit,
1069
+ blake2bUpdate: t.blake2bUpdate,
1070
+ blake2bFinal: t.blake2bFinal,
1071
+ blake2s: e.blake2s,
1072
+ blake2sHex: e.blake2sHex,
1073
+ blake2sInit: e.blake2sInit,
1074
+ blake2sUpdate: e.blake2sUpdate,
1075
+ blake2sFinal: e.blake2sFinal
1076
+ }, C;
1077
+ }
1078
+ var L = Vt();
1079
+ /**
1080
+ * @module @zk-kit/eddsa-poseidon
1081
+ * @version 1.1.0
1082
+ * @file A JavaScript EdDSA library for secure signing and verification using Poseidon the Baby Jubjub elliptic curve.
1083
+ * @copyright Ethereum Foundation 2024
1084
+ * @license MIT
1085
+ * @see [Github]{@link https://github.com/privacy-scaling-explorations/zk-kit/tree/main/packages/eddsa-poseidon}
1086
+ */
1087
+ const Zt = I.Buffer.from([1]), Wt = I.Buffer.from([129]), U = [
1088
+ [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
1089
+ [14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3],
1090
+ [11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4],
1091
+ [7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8],
1092
+ [9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13],
1093
+ [2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9],
1094
+ [12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11],
1095
+ [13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10],
1096
+ [6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5],
1097
+ [10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13, 0],
1098
+ [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
1099
+ [14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3],
1100
+ [11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4],
1101
+ [7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8],
1102
+ [9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13],
1103
+ [2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9]
1104
+ ], E = [
1105
+ 608135816,
1106
+ 2242054355,
1107
+ 320440878,
1108
+ 57701188,
1109
+ 2752067618,
1110
+ 698298832,
1111
+ 137296536,
1112
+ 3964562569,
1113
+ 1160258022,
1114
+ 953160567,
1115
+ 3193202383,
1116
+ 887688300,
1117
+ 3232508343,
1118
+ 3380367581,
1119
+ 1065670069,
1120
+ 3041331479,
1121
+ 2450970073,
1122
+ 2306472731,
1123
+ 3509652390,
1124
+ 2564797868,
1125
+ 805139163,
1126
+ 3491422135,
1127
+ 3101798381,
1128
+ 1780907670,
1129
+ 3128725573,
1130
+ 4046225305,
1131
+ 614570311,
1132
+ 3012652279,
1133
+ 134345442,
1134
+ 2240740374,
1135
+ 1667834072,
1136
+ 1901547113
1137
+ ], V = I.Buffer.from([
1138
+ 128,
1139
+ 0,
1140
+ 0,
1141
+ 0,
1142
+ 0,
1143
+ 0,
1144
+ 0,
1145
+ 0,
1146
+ 0,
1147
+ 0,
1148
+ 0,
1149
+ 0,
1150
+ 0,
1151
+ 0,
1152
+ 0,
1153
+ 0,
1154
+ 0,
1155
+ 0,
1156
+ 0,
1157
+ 0,
1158
+ 0,
1159
+ 0,
1160
+ 0,
1161
+ 0,
1162
+ 0,
1163
+ 0,
1164
+ 0,
1165
+ 0,
1166
+ 0,
1167
+ 0,
1168
+ 0,
1169
+ 0,
1170
+ 0,
1171
+ 0,
1172
+ 0,
1173
+ 0,
1174
+ 0,
1175
+ 0,
1176
+ 0,
1177
+ 0,
1178
+ 0,
1179
+ 0,
1180
+ 0,
1181
+ 0,
1182
+ 0,
1183
+ 0,
1184
+ 0,
1185
+ 0,
1186
+ 0,
1187
+ 0,
1188
+ 0,
1189
+ 0,
1190
+ 0,
1191
+ 0,
1192
+ 0,
1193
+ 0,
1194
+ 0,
1195
+ 0,
1196
+ 0,
1197
+ 0,
1198
+ 0,
1199
+ 0,
1200
+ 0,
1201
+ 0,
1202
+ 0,
1203
+ 0,
1204
+ 0,
1205
+ 0,
1206
+ 0,
1207
+ 0,
1208
+ 0,
1209
+ 0,
1210
+ 0,
1211
+ 0,
1212
+ 0,
1213
+ 0,
1214
+ 0,
1215
+ 0,
1216
+ 0,
1217
+ 0,
1218
+ 0,
1219
+ 0,
1220
+ 0,
1221
+ 0,
1222
+ 0,
1223
+ 0,
1224
+ 0,
1225
+ 0,
1226
+ 0,
1227
+ 0,
1228
+ 0,
1229
+ 0,
1230
+ 0,
1231
+ 0,
1232
+ 0,
1233
+ 0,
1234
+ 0,
1235
+ 0,
1236
+ 0,
1237
+ 0,
1238
+ 0,
1239
+ 0,
1240
+ 0,
1241
+ 0,
1242
+ 0,
1243
+ 0,
1244
+ 0,
1245
+ 0,
1246
+ 0,
1247
+ 0,
1248
+ 0,
1249
+ 0,
1250
+ 0,
1251
+ 0,
1252
+ 0,
1253
+ 0,
1254
+ 0,
1255
+ 0,
1256
+ 0,
1257
+ 0,
1258
+ 0,
1259
+ 0,
1260
+ 0,
1261
+ 0,
1262
+ 0,
1263
+ 0,
1264
+ 0,
1265
+ 0,
1266
+ 0
1267
+ ]);
1268
+ function $(t, e, r, n) {
1269
+ let g = t[e * 2] ^ t[r * 2], h = t[e * 2 + 1] ^ t[r * 2 + 1];
1270
+ n >= 32 && (h ^= g, g ^= h, h ^= g, n -= 32), n === 0 ? (t[e * 2] = g >>> 0, t[e * 2 + 1] = h >>> 0) : (t[e * 2] = (g >>> n | h << 32 - n) >>> 0, t[e * 2 + 1] = (h >>> n | g << 32 - n) >>> 0);
1271
+ }
1272
+ function S(t, e, r, n, g, h, f, a) {
1273
+ let u;
1274
+ u = t[n * 2 + 1] + ((e[U[r][a] * 2 + 1] ^ E[U[r][a + 1] * 2 + 1]) >>> 0) + t[g * 2 + 1], t[n * 2] = t[n * 2] + ((e[U[r][a] * 2] ^ E[U[r][a + 1] * 2]) >>> 0) + t[g * 2] + ~~(u / 4294967296) >>> 0, t[n * 2 + 1] = u >>> 0, $(t, f, n, 32), u = t[h * 2 + 1] + t[f * 2 + 1], t[h * 2] = t[h * 2] + t[f * 2] + ~~(u / 4294967296) >>> 0, t[h * 2 + 1] = u >>> 0, $(t, g, h, 25), u = t[n * 2 + 1] + ((e[U[r][a + 1] * 2 + 1] ^ E[U[r][a] * 2 + 1]) >>> 0) + t[g * 2 + 1], t[n * 2] = t[n * 2] + ((e[U[r][a + 1] * 2] ^ E[U[r][a] * 2]) >>> 0) + t[g * 2] + ~~(u / 4294967296) >>> 0, t[n * 2 + 1] = u >>> 0, $(t, f, n, 16), u = t[h * 2 + 1] + t[f * 2 + 1], t[h * 2] = t[h * 2] + t[f * 2] + ~~(u / 4294967296) >>> 0, t[h * 2 + 1] = u >>> 0, $(t, g, h, 11);
1275
+ }
1276
+ function ct(t) {
1277
+ for (let e = 0; e < t.length && !(t[e] < 4294967296); e += 1)
1278
+ t[e] -= 4294967296, t[e + 1] += 1;
1279
+ }
1280
+ class Xt {
1281
+ /**
1282
+ * Initializes a new Blake-512 hash instance with the default parameters.
1283
+ */
1284
+ constructor() {
1285
+ this._h = [
1286
+ 1779033703,
1287
+ 4089235720,
1288
+ 3144134277,
1289
+ 2227873595,
1290
+ 1013904242,
1291
+ 4271175723,
1292
+ 2773480762,
1293
+ 1595750129,
1294
+ 1359893119,
1295
+ 2917565137,
1296
+ 2600822924,
1297
+ 725511199,
1298
+ 528734635,
1299
+ 4215389547,
1300
+ 1541459225,
1301
+ 327033209
1302
+ ], this._s = [0, 0, 0, 0, 0, 0, 0, 0], this._block = I.Buffer.alloc(128), this._blockOffset = 0, this._length = [0, 0, 0, 0], this._nullt = !1, this._zo = Zt, this._oo = Wt;
1303
+ }
1304
+ /**
1305
+ * The core compression function for Blake-512. It transforms the internal
1306
+ * state based on the input block and the current hash parameters.
1307
+ */
1308
+ _compress() {
1309
+ const e = new Array(32), r = new Array(32);
1310
+ let n;
1311
+ for (n = 0; n < 32; n += 1)
1312
+ r[n] = this._block.readUInt32BE(n * 4);
1313
+ for (n = 0; n < 16; n += 1)
1314
+ e[n] = this._h[n] >>> 0;
1315
+ for (n = 16; n < 24; n += 1)
1316
+ e[n] = (this._s[n - 16] ^ E[n - 16]) >>> 0;
1317
+ for (n = 24; n < 32; n += 1)
1318
+ e[n] = E[n - 16];
1319
+ for (this._nullt || (e[24] = (e[24] ^ this._length[1]) >>> 0, e[25] = (e[25] ^ this._length[0]) >>> 0, e[26] = (e[26] ^ this._length[1]) >>> 0, e[27] = (e[27] ^ this._length[0]) >>> 0, e[28] = (e[28] ^ this._length[3]) >>> 0, e[29] = (e[29] ^ this._length[2]) >>> 0, e[30] = (e[30] ^ this._length[3]) >>> 0, e[31] = (e[31] ^ this._length[2]) >>> 0), n = 0; n < 16; n += 1)
1320
+ S(e, r, n, 0, 4, 8, 12, 0), S(e, r, n, 1, 5, 9, 13, 2), S(e, r, n, 2, 6, 10, 14, 4), S(e, r, n, 3, 7, 11, 15, 6), S(e, r, n, 0, 5, 10, 15, 8), S(e, r, n, 1, 6, 11, 12, 10), S(e, r, n, 2, 7, 8, 13, 12), S(e, r, n, 3, 4, 9, 14, 14);
1321
+ for (n = 0; n < 16; n += 1)
1322
+ this._h[n % 8 * 2] = (this._h[n % 8 * 2] ^ e[n * 2]) >>> 0, this._h[n % 8 * 2 + 1] = (this._h[n % 8 * 2 + 1] ^ e[n * 2 + 1]) >>> 0;
1323
+ for (n = 0; n < 8; n += 1)
1324
+ this._h[n * 2] = (this._h[n * 2] ^ this._s[n % 4 * 2]) >>> 0, this._h[n * 2 + 1] = (this._h[n * 2 + 1] ^ this._s[n % 4 * 2 + 1]) >>> 0;
1325
+ }
1326
+ /**
1327
+ * Adds padding to the message as per the Blake-512 specification, ensuring
1328
+ * the message length is a multiple of the block size.
1329
+ */
1330
+ _padding() {
1331
+ const e = this._length.slice();
1332
+ e[0] += this._blockOffset * 8, ct(e);
1333
+ const r = I.Buffer.alloc(16);
1334
+ for (let n = 0; n < 4; n += 1)
1335
+ r.writeUInt32BE(e[3 - n], n * 4);
1336
+ this._blockOffset === 111 ? (this._length[0] -= 8, this.update(this._oo)) : (this._blockOffset < 111 ? (this._blockOffset === 0 && (this._nullt = !0), this._length[0] -= (111 - this._blockOffset) * 8, this.update(V.subarray(0, 111 - this._blockOffset))) : (this._length[0] -= (128 - this._blockOffset) * 8, this.update(V.subarray(0, 128 - this._blockOffset)), this._length[0] -= 111 * 8, this.update(V.subarray(1, 112)), this._nullt = !0), this.update(this._zo), this._length[0] -= 8), this._length[0] -= 128, this.update(r);
1337
+ }
1338
+ /**
1339
+ * Completes the hash computation and returns the final hash value.
1340
+ * This method applies the necessary padding, performs the final compression,
1341
+ * and returns the hash output.
1342
+ * @returns The Blake-512 hash of the input data.
1343
+ */
1344
+ digest() {
1345
+ this._padding();
1346
+ const e = I.Buffer.alloc(64);
1347
+ for (let r = 0; r < 16; r += 1)
1348
+ e.writeUInt32BE(this._h[r], r * 4);
1349
+ return e;
1350
+ }
1351
+ /**
1352
+ * Updates the hash with new data. This method can be called multiple
1353
+ * times to incrementally add data to the hash computation.
1354
+ * @param data The data to add to the hash.
1355
+ * @returns This instance, to allow method chaining.
1356
+ */
1357
+ update(e) {
1358
+ const r = this._block;
1359
+ let n = 0;
1360
+ for (; this._blockOffset + e.length - n >= r.length; ) {
1361
+ for (let g = this._blockOffset; g < r.length; )
1362
+ r[g++] = e[n++];
1363
+ this._length[0] += r.length * 8, ct(this._length), this._compress(), this._blockOffset = 0;
1364
+ }
1365
+ for (; n < e.length; )
1366
+ r[this._blockOffset++] = e[n++];
1367
+ return this;
1368
+ }
1369
+ }
1370
+ class Gt {
1371
+ /**
1372
+ * Constructor of the Blake2b engine
1373
+ * @param outlen The fixed output length of the generated hash
1374
+ * @param key Optional key parameter if keyed hashes are required
1375
+ * @returns This instance, to allow method chaining.
1376
+ */
1377
+ constructor(e = 64, r) {
1378
+ if (this.key = null, this.outlen = 64, r && (this.key = r), e <= 0 || e > 64)
1379
+ throw new Error("Illegal output length, expected 0 < length <= 64");
1380
+ this.outlen = e, this.context = L.blake2bInit(this.outlen, r);
1381
+ }
1382
+ /**
1383
+ * Updates the hash with new data. This method can be called multiple
1384
+ * times to incrementally add data to the hash computation.
1385
+ * @param input The data to add to the hash.
1386
+ * @returns The instance, to allow method chaining.
1387
+ */
1388
+ update(e) {
1389
+ return L.blake2bUpdate(this.context, e), this;
1390
+ }
1391
+ /**
1392
+ * Completes the hash computation and returns the final hash value.
1393
+ * This method applies the necessary padding, performs the final compression,
1394
+ * and returns the output.
1395
+ * @returns The Blake2b hash of the input data.
1396
+ */
1397
+ digest() {
1398
+ return St.from(L.blake2bFinal(this.context));
1399
+ }
1400
+ }
1401
+ function ft(t) {
1402
+ return t[0] &= 248, t[31] &= 127, t[31] |= 64, t;
1403
+ }
1404
+ function W(t) {
1405
+ return dt(t) && t.length === 2 && j(t[0]) && j(t[1]);
1406
+ }
1407
+ function lt(t) {
1408
+ return G(t) && Object.prototype.hasOwnProperty.call(t, "R8") && Object.prototype.hasOwnProperty.call(t, "S") && W(t.R8) && j(t.S);
1409
+ }
1410
+ function ht(t) {
1411
+ return F(t, "privateKey", ["Buffer", "Uint8Array", "string"]), I.Buffer.from(t);
1412
+ }
1413
+ function bt(t) {
1414
+ return F(t, "message", ["bignumberish", "string"]), J(t) ? kt(t) : yt(I.Buffer.from(t));
1415
+ }
1416
+ function Z(t, e) {
1417
+ let r;
1418
+ switch (e) {
1419
+ case P.BLAKE1: {
1420
+ r = new Xt();
1421
+ break;
1422
+ }
1423
+ case P.BLAKE2b: {
1424
+ r = new Gt();
1425
+ break;
1426
+ }
1427
+ default:
1428
+ throw new Error("Unsupported algorithm. Cannot hash input.");
1429
+ }
1430
+ return r.update(I.Buffer.from(t)), r.digest();
1431
+ }
1432
+ var P;
1433
+ (function(t) {
1434
+ t.BLAKE1 = "blake-1", t.BLAKE2b = "blake-2b";
1435
+ })(P || (P = {}));
1436
+ const Nt = (t) => {
1437
+ const e = (b) => {
1438
+ b = ht(b);
1439
+ let l = Z(b, t);
1440
+ return l = l.slice(0, 32), l = ft(l), rt(K(l), BigInt(3)) % R;
1441
+ };
1442
+ function r(b) {
1443
+ const l = e(b);
1444
+ return x(z, l);
1445
+ }
1446
+ function n(b, l) {
1447
+ b = ht(b), l = bt(l);
1448
+ const y = Z(b, t), B = ft(y.slice(0, 32)), c = K(B), p = x(z, rt(c, BigInt(3))), s = T(l, 32), i = Z(I.Buffer.concat([y.slice(32, 64), s]), t), d = new Mt(R), o = d.e(K(i)), w = x(z, o), _ = it.poseidon5([w[0], w[1], p[0], p[1], l]), m = d.add(o, d.mul(_, c));
1449
+ return { R8: w, S: m };
1450
+ }
1451
+ function g(b, l, y) {
1452
+ if (!W(y) || !lt(l) || !O(l.R8) || !O(y) || BigInt(l.S) >= R)
1453
+ return !1;
1454
+ b = bt(b);
1455
+ const B = {
1456
+ R8: [BigInt(l.R8[0]), BigInt(l.R8[1])],
1457
+ S: BigInt(l.S)
1458
+ }, c = [BigInt(y[0]), BigInt(y[1])], p = it.poseidon5([l.R8[0], l.R8[1], y[0], y[1], b]), s = x(z, BigInt(l.S));
1459
+ let i = x(c, qt(p, BigInt(8)));
1460
+ return i = Ut(B.R8, i), nt.eq(s[0], i[0]) && nt.eq(s[1], i[1]);
1461
+ }
1462
+ function h(b) {
1463
+ if (!W(b) || !O(b))
1464
+ throw new Error("Invalid public key");
1465
+ const l = [BigInt(b[0]), BigInt(b[1])];
1466
+ return et(l);
1467
+ }
1468
+ function f(b) {
1469
+ wt(b, "publicKey");
1470
+ const l = tt(kt(b));
1471
+ if (l === null)
1472
+ throw new Error("Invalid public key");
1473
+ return l;
1474
+ }
1475
+ function a(b) {
1476
+ if (!lt(b) || !O(b.R8) || BigInt(b.S) >= R)
1477
+ throw new Error("Invalid signature");
1478
+ const l = {
1479
+ R8: b.R8.map((c) => BigInt(c)),
1480
+ S: BigInt(b.S)
1481
+ }, y = et(l.R8), B = I.Buffer.alloc(64);
1482
+ return B.set(T(y, 32), 0), B.set(T(l.S, 32), 32), B;
1483
+ }
1484
+ function u(b) {
1485
+ if (xt(b, "packedSignature"), b.length !== 64)
1486
+ throw new Error("Packed signature must be 64 bytes");
1487
+ const l = b.subarray(0, 32), y = b.subarray(32, 64), B = tt(K(l));
1488
+ if (B === null)
1489
+ throw new Error(`Invalid packed signature point ${y.toString("hex")}.`);
1490
+ return {
1491
+ R8: B,
1492
+ S: K(y)
1493
+ };
1494
+ }
1495
+ class k {
1496
+ /**
1497
+ * Initializes a new instance, deriving necessary cryptographic parameters from the provided private key.
1498
+ * If the private key is not passed as a parameter, a random 32-byte hexadecimal key is generated.
1499
+ *
1500
+ * The private key must be an instance of Buffer, Uint8Array or a string. The input will be used to
1501
+ * generate entropy and there is no limit in size.
1502
+ * The string is used as a set of raw bytes (in UTF-8) and is typically used to pass passwords or secret messages.
1503
+ * If you want to pass a bigint, a number or a hexadecimal, be sure to convert them to one of the supported types first.
1504
+ * The 'conversions' module in @zk-kit/utils provides a set of functions that may be useful in case you need to convert types.
1505
+ *
1506
+ * @param privateKey The private key used for signing and public key derivation.
1507
+ */
1508
+ constructor(l = Pt.getRandomValues(32)) {
1509
+ this.privateKey = l, this.secretScalar = e(l), this.publicKey = r(l), this.packedPublicKey = h(this.publicKey);
1510
+ }
1511
+ /**
1512
+ * Signs a given message using the private key and returns the signature.
1513
+ * @param message The message to be signed.
1514
+ * @returns The signature of the message.
1515
+ */
1516
+ signMessage(l) {
1517
+ return n(this.privateKey, l);
1518
+ }
1519
+ /**
1520
+ * Verifies a signature against a message and the public key stored in this instance.
1521
+ * @param message The message whose signature is to be verified.
1522
+ * @param signature The signature to be verified.
1523
+ * @returns True if the signature is valid for the message and public key, false otherwise.
1524
+ */
1525
+ verifySignature(l, y) {
1526
+ return g(l, y, this.publicKey);
1527
+ }
1528
+ }
1529
+ return {
1530
+ deriveSecretScalar: e,
1531
+ derivePublicKey: r,
1532
+ signMessage: n,
1533
+ verifySignature: g,
1534
+ packPublicKey: h,
1535
+ unpackPublicKey: f,
1536
+ packSignature: a,
1537
+ unpackSignature: u,
1538
+ EdDSAPoseidon: k
1539
+ };
1540
+ }, { EdDSAPoseidon: Yt, derivePublicKey: Jt, deriveSecretScalar: te, packPublicKey: ee, packSignature: ne, signMessage: re, unpackPublicKey: ie, unpackSignature: oe, verifySignature: se } = Nt(P.BLAKE1);
1541
+ export {
1542
+ Yt as EdDSAPoseidon,
1543
+ Jt as derivePublicKey,
1544
+ te as deriveSecretScalar,
1545
+ ee as packPublicKey,
1546
+ ne as packSignature,
1547
+ re as signMessage,
1548
+ ie as unpackPublicKey,
1549
+ oe as unpackSignature,
1550
+ se as verifySignature
1551
+ };