@nihilium/client-sdk 0.1.1 → 0.2.0

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