@prosopo/procaptcha-bundle 3.0.12 → 3.0.13

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.
Files changed (20) hide show
  1. package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/tests/util/renderLogic.test.js +2 -2
  2. package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/tests/util/renderLogic.test.js.map +1 -1
  3. package/CHANGELOG.md +27 -0
  4. package/dist/bundle/{ProcaptchaWidget-48FxVPQd.js → ProcaptchaWidget-BIt2pcrz.js} +5 -5
  5. package/dist/bundle/{ProcaptchaWidget-B2BzhXLv.js → ProcaptchaWidget-CXxnCzl2.js} +7 -7
  6. package/dist/bundle/{captchaComponentProvider-B7Vxx339.js → captchaComponentProvider-BGEAkC9Y.js} +7 -7
  7. package/dist/bundle/{captchaRenderer-DdOlOCKw.js → captchaRenderer-CqnUYyKY.js} +3 -3
  8. package/dist/bundle/{commonChunk-HCVkoCqn.js → commonChunk-BKceWhtS.js} +1 -1
  9. package/dist/bundle/{emotion-element-5486c51c.browser.esm-D7qvHZDV.js → emotion-element-5486c51c.browser.esm-CimrRZxS.js} +1 -1
  10. package/dist/bundle/{index-DyYmvHVN.js → index-KHTbPva_.js} +1 -1
  11. package/dist/bundle/{index-C00_J7av.js → index-hrOz2CPm.js} +2 -2
  12. package/dist/bundle/nobleChunk-CQ4ENyKh.js +3769 -0
  13. package/dist/bundle/procaptcha.bundle.js +2 -2
  14. package/dist/bundle/{utilChunk-sqstc6C5.js → utilChunk-DPr6oTOj.js} +22 -22
  15. package/dist/bundle/{utilCryptoChunk-qm-BM2eT.js → utilCryptoChunk-BKe3CKqn.js} +273 -273
  16. package/dist/bundle/{web2Chunk-DCsWA5PR.js → web2Chunk-Cqw91v-J.js} +404 -394
  17. package/dist/bundle/{web3Chunk-B8txCqUJ.js → web3Chunk-BcwDKvjL.js} +4 -4
  18. package/package.json +19 -19
  19. package/stats.html +1 -1
  20. package/dist/bundle/nobleChunk-Qozzkbsq.js +0 -3648
@@ -0,0 +1,3769 @@
1
+ const Yt = typeof globalThis == "object" && "crypto" in globalThis ? globalThis.crypto : void 0;
2
+ function pe(t) {
3
+ return t instanceof Uint8Array || ArrayBuffer.isView(t) && t.constructor.name === "Uint8Array";
4
+ }
5
+ function et(t) {
6
+ if (!Number.isSafeInteger(t) || t < 0)
7
+ throw new Error("positive integer expected, got " + t);
8
+ }
9
+ function W(t, ...e) {
10
+ if (!pe(t))
11
+ throw new Error("Uint8Array expected");
12
+ if (e.length > 0 && !e.includes(t.length))
13
+ throw new Error("Uint8Array expected of length " + e + ", got length=" + t.length);
14
+ }
15
+ function Cn(t) {
16
+ if (typeof t != "function" || typeof t.create != "function")
17
+ throw new Error("Hash should be wrapped by utils.createHasher");
18
+ et(t.outputLen), et(t.blockLen);
19
+ }
20
+ function Kt(t, e = !0) {
21
+ if (t.destroyed)
22
+ throw new Error("Hash instance has been destroyed");
23
+ if (e && t.finished)
24
+ throw new Error("Hash#digest() has already been called");
25
+ }
26
+ function zn(t, e) {
27
+ W(t);
28
+ const n = e.outputLen;
29
+ if (t.length < n)
30
+ throw new Error("digestInto() expects output buffer of length at least " + n);
31
+ }
32
+ function Mt(t) {
33
+ return new Uint32Array(t.buffer, t.byteOffset, Math.floor(t.byteLength / 4));
34
+ }
35
+ function ft(...t) {
36
+ for (let e = 0; e < t.length; e++)
37
+ t[e].fill(0);
38
+ }
39
+ function be(t) {
40
+ return new DataView(t.buffer, t.byteOffset, t.byteLength);
41
+ }
42
+ function wt(t, e) {
43
+ return t << 32 - e | t >>> e;
44
+ }
45
+ function D(t, e) {
46
+ return t << e | t >>> 32 - e >>> 0;
47
+ }
48
+ const jn = new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68;
49
+ function Vn(t) {
50
+ return t << 24 & 4278190080 | t << 8 & 16711680 | t >>> 8 & 65280 | t >>> 24 & 255;
51
+ }
52
+ const xt = jn ? (t) => t : (t) => Vn(t);
53
+ function Nr(t) {
54
+ for (let e = 0; e < t.length; e++)
55
+ t[e] = Vn(t[e]);
56
+ return t;
57
+ }
58
+ const qt = jn ? (t) => t : Nr, Yn = /* @ts-ignore */ typeof Uint8Array.from([]).toHex == "function" && typeof Uint8Array.fromHex == "function", $r = /* @__PURE__ */ Array.from({ length: 256 }, (t, e) => e.toString(16).padStart(2, "0"));
59
+ function ht(t) {
60
+ if (W(t), Yn)
61
+ return t.toHex();
62
+ let e = "";
63
+ for (let n = 0; n < t.length; n++)
64
+ e += $r[t[n]];
65
+ return e;
66
+ }
67
+ const gt = { _0: 48, _9: 57, A: 65, F: 70, a: 97, f: 102 };
68
+ function hn(t) {
69
+ if (t >= gt._0 && t <= gt._9)
70
+ return t - gt._0;
71
+ if (t >= gt.A && t <= gt.F)
72
+ return t - (gt.A - 10);
73
+ if (t >= gt.a && t <= gt.f)
74
+ return t - (gt.a - 10);
75
+ }
76
+ function ae(t) {
77
+ if (typeof t != "string")
78
+ throw new Error("hex string expected, got " + typeof t);
79
+ if (Yn)
80
+ return Uint8Array.fromHex(t);
81
+ const e = t.length, n = e / 2;
82
+ if (e % 2)
83
+ throw new Error("hex string expected, got unpadded hex of length " + e);
84
+ const r = new Uint8Array(n);
85
+ for (let i = 0, s = 0; i < n; i++, s += 2) {
86
+ const c = hn(t.charCodeAt(s)), o = hn(t.charCodeAt(s + 1));
87
+ if (c === void 0 || o === void 0) {
88
+ const f = t[s] + t[s + 1];
89
+ throw new Error('hex string expected, got non-hex character "' + f + '" at index ' + s);
90
+ }
91
+ r[i] = c * 16 + o;
92
+ }
93
+ return r;
94
+ }
95
+ function We(t) {
96
+ if (typeof t != "string")
97
+ throw new Error("string expected");
98
+ return new Uint8Array(new TextEncoder().encode(t));
99
+ }
100
+ function Ht(t) {
101
+ return typeof t == "string" && (t = We(t)), W(t), t;
102
+ }
103
+ function wn(t) {
104
+ return typeof t == "string" && (t = We(t)), W(t), t;
105
+ }
106
+ function ut(...t) {
107
+ let e = 0;
108
+ for (let r = 0; r < t.length; r++) {
109
+ const i = t[r];
110
+ W(i), e += i.length;
111
+ }
112
+ const n = new Uint8Array(e);
113
+ for (let r = 0, i = 0; r < t.length; r++) {
114
+ const s = t[r];
115
+ n.set(s, i), i += s.length;
116
+ }
117
+ return n;
118
+ }
119
+ function Gn(t, e) {
120
+ if (e !== void 0 && {}.toString.call(e) !== "[object Object]")
121
+ throw new Error("options should be object or undefined");
122
+ return Object.assign(t, e);
123
+ }
124
+ class Qe {
125
+ }
126
+ function Xn(t) {
127
+ const e = (r) => t().update(Ht(r)).digest(), n = t();
128
+ return e.outputLen = n.outputLen, e.blockLen = n.blockLen, e.create = () => t(), e;
129
+ }
130
+ function Hr(t) {
131
+ const e = (r, i) => t(i).update(Ht(r)).digest(), n = t({});
132
+ return e.outputLen = n.outputLen, e.blockLen = n.blockLen, e.create = (r) => t(r), e;
133
+ }
134
+ function Je(t = 32) {
135
+ if (Yt && typeof Yt.getRandomValues == "function")
136
+ return Yt.getRandomValues(new Uint8Array(t));
137
+ if (Yt && typeof Yt.randomBytes == "function")
138
+ return Uint8Array.from(Yt.randomBytes(t));
139
+ throw new Error("crypto.getRandomValues must be defined");
140
+ }
141
+ const kr = /* @__PURE__ */ Uint8Array.from([
142
+ 0,
143
+ 1,
144
+ 2,
145
+ 3,
146
+ 4,
147
+ 5,
148
+ 6,
149
+ 7,
150
+ 8,
151
+ 9,
152
+ 10,
153
+ 11,
154
+ 12,
155
+ 13,
156
+ 14,
157
+ 15,
158
+ 14,
159
+ 10,
160
+ 4,
161
+ 8,
162
+ 9,
163
+ 15,
164
+ 13,
165
+ 6,
166
+ 1,
167
+ 12,
168
+ 0,
169
+ 2,
170
+ 11,
171
+ 7,
172
+ 5,
173
+ 3,
174
+ 11,
175
+ 8,
176
+ 12,
177
+ 0,
178
+ 5,
179
+ 2,
180
+ 15,
181
+ 13,
182
+ 10,
183
+ 14,
184
+ 3,
185
+ 6,
186
+ 7,
187
+ 1,
188
+ 9,
189
+ 4,
190
+ 7,
191
+ 9,
192
+ 3,
193
+ 1,
194
+ 13,
195
+ 12,
196
+ 11,
197
+ 14,
198
+ 2,
199
+ 6,
200
+ 5,
201
+ 10,
202
+ 4,
203
+ 0,
204
+ 15,
205
+ 8,
206
+ 9,
207
+ 0,
208
+ 5,
209
+ 7,
210
+ 2,
211
+ 4,
212
+ 10,
213
+ 15,
214
+ 14,
215
+ 1,
216
+ 11,
217
+ 12,
218
+ 6,
219
+ 8,
220
+ 3,
221
+ 13,
222
+ 2,
223
+ 12,
224
+ 6,
225
+ 10,
226
+ 0,
227
+ 11,
228
+ 8,
229
+ 3,
230
+ 4,
231
+ 13,
232
+ 7,
233
+ 5,
234
+ 15,
235
+ 14,
236
+ 1,
237
+ 9,
238
+ 12,
239
+ 5,
240
+ 1,
241
+ 15,
242
+ 14,
243
+ 13,
244
+ 4,
245
+ 10,
246
+ 0,
247
+ 7,
248
+ 6,
249
+ 3,
250
+ 9,
251
+ 2,
252
+ 8,
253
+ 11,
254
+ 13,
255
+ 11,
256
+ 7,
257
+ 14,
258
+ 12,
259
+ 1,
260
+ 3,
261
+ 9,
262
+ 5,
263
+ 0,
264
+ 15,
265
+ 4,
266
+ 8,
267
+ 6,
268
+ 2,
269
+ 10,
270
+ 6,
271
+ 15,
272
+ 14,
273
+ 9,
274
+ 11,
275
+ 3,
276
+ 0,
277
+ 8,
278
+ 12,
279
+ 2,
280
+ 13,
281
+ 7,
282
+ 1,
283
+ 4,
284
+ 10,
285
+ 5,
286
+ 10,
287
+ 2,
288
+ 8,
289
+ 4,
290
+ 7,
291
+ 6,
292
+ 1,
293
+ 5,
294
+ 15,
295
+ 11,
296
+ 9,
297
+ 14,
298
+ 3,
299
+ 12,
300
+ 13,
301
+ 0,
302
+ 0,
303
+ 1,
304
+ 2,
305
+ 3,
306
+ 4,
307
+ 5,
308
+ 6,
309
+ 7,
310
+ 8,
311
+ 9,
312
+ 10,
313
+ 11,
314
+ 12,
315
+ 13,
316
+ 14,
317
+ 15,
318
+ 14,
319
+ 10,
320
+ 4,
321
+ 8,
322
+ 9,
323
+ 15,
324
+ 13,
325
+ 6,
326
+ 1,
327
+ 12,
328
+ 0,
329
+ 2,
330
+ 11,
331
+ 7,
332
+ 5,
333
+ 3,
334
+ // Blake1, unused in others
335
+ 11,
336
+ 8,
337
+ 12,
338
+ 0,
339
+ 5,
340
+ 2,
341
+ 15,
342
+ 13,
343
+ 10,
344
+ 14,
345
+ 3,
346
+ 6,
347
+ 7,
348
+ 1,
349
+ 9,
350
+ 4,
351
+ 7,
352
+ 9,
353
+ 3,
354
+ 1,
355
+ 13,
356
+ 12,
357
+ 11,
358
+ 14,
359
+ 2,
360
+ 6,
361
+ 5,
362
+ 10,
363
+ 4,
364
+ 0,
365
+ 15,
366
+ 8,
367
+ 9,
368
+ 0,
369
+ 5,
370
+ 7,
371
+ 2,
372
+ 4,
373
+ 10,
374
+ 15,
375
+ 14,
376
+ 1,
377
+ 11,
378
+ 12,
379
+ 6,
380
+ 8,
381
+ 3,
382
+ 13,
383
+ 2,
384
+ 12,
385
+ 6,
386
+ 10,
387
+ 0,
388
+ 11,
389
+ 8,
390
+ 3,
391
+ 4,
392
+ 13,
393
+ 7,
394
+ 5,
395
+ 15,
396
+ 14,
397
+ 1,
398
+ 9
399
+ ]);
400
+ function Tr(t, e, n, r) {
401
+ if (typeof t.setBigUint64 == "function")
402
+ return t.setBigUint64(e, n, r);
403
+ const i = BigInt(32), s = BigInt(4294967295), c = Number(n >> i & s), o = Number(n & s), f = r ? 4 : 0, u = r ? 0 : 4;
404
+ t.setUint32(e + f, c, r), t.setUint32(e + u, o, r);
405
+ }
406
+ function Ur(t, e, n) {
407
+ return t & e ^ ~t & n;
408
+ }
409
+ function Zr(t, e, n) {
410
+ return t & e ^ t & n ^ e & n;
411
+ }
412
+ class Kn extends Qe {
413
+ constructor(e, n, r, i) {
414
+ super(), this.finished = !1, this.length = 0, this.pos = 0, this.destroyed = !1, this.blockLen = e, this.outputLen = n, this.padOffset = r, this.isLE = i, this.buffer = new Uint8Array(e), this.view = be(this.buffer);
415
+ }
416
+ update(e) {
417
+ Kt(this), e = Ht(e), W(e);
418
+ const { view: n, buffer: r, blockLen: i } = this, s = e.length;
419
+ for (let c = 0; c < s; ) {
420
+ const o = Math.min(i - this.pos, s - c);
421
+ if (o === i) {
422
+ const f = be(e);
423
+ for (; i <= s - c; c += i)
424
+ this.process(f, c);
425
+ continue;
426
+ }
427
+ r.set(e.subarray(c, c + o), this.pos), this.pos += o, c += o, this.pos === i && (this.process(n, 0), this.pos = 0);
428
+ }
429
+ return this.length += e.length, this.roundClean(), this;
430
+ }
431
+ digestInto(e) {
432
+ Kt(this), zn(e, this), this.finished = !0;
433
+ const { buffer: n, view: r, blockLen: i, isLE: s } = this;
434
+ let { pos: c } = this;
435
+ n[c++] = 128, ft(this.buffer.subarray(c)), this.padOffset > i - c && (this.process(r, 0), c = 0);
436
+ for (let w = c; w < i; w++)
437
+ n[w] = 0;
438
+ Tr(r, i - 8, BigInt(this.length * 8), s), this.process(r, 0);
439
+ const o = be(e), f = this.outputLen;
440
+ if (f % 4)
441
+ throw new Error("_sha2: outputLen should be aligned to 32bit");
442
+ const u = f / 4, a = this.get();
443
+ if (u > a.length)
444
+ throw new Error("_sha2: outputLen bigger than state");
445
+ for (let w = 0; w < u; w++)
446
+ o.setUint32(4 * w, a[w], s);
447
+ }
448
+ digest() {
449
+ const { buffer: e, outputLen: n } = this;
450
+ this.digestInto(e);
451
+ const r = e.slice(0, n);
452
+ return this.destroy(), r;
453
+ }
454
+ _cloneInto(e) {
455
+ e || (e = new this.constructor()), e.set(...this.get());
456
+ const { blockLen: n, buffer: r, length: i, finished: s, destroyed: c, pos: o } = this;
457
+ return e.destroyed = c, e.finished = s, e.length = i, e.pos = o, i % n && e.buffer.set(r), e;
458
+ }
459
+ clone() {
460
+ return this._cloneInto();
461
+ }
462
+ }
463
+ const _t = /* @__PURE__ */ Uint32Array.from([
464
+ 1779033703,
465
+ 3144134277,
466
+ 1013904242,
467
+ 2773480762,
468
+ 1359893119,
469
+ 2600822924,
470
+ 528734635,
471
+ 1541459225
472
+ ]);
473
+ const F = /* @__PURE__ */ Uint32Array.from([
474
+ 1779033703,
475
+ 4089235720,
476
+ 3144134277,
477
+ 2227873595,
478
+ 1013904242,
479
+ 4271175723,
480
+ 2773480762,
481
+ 1595750129,
482
+ 1359893119,
483
+ 2917565137,
484
+ 2600822924,
485
+ 725511199,
486
+ 528734635,
487
+ 4215389547,
488
+ 1541459225,
489
+ 327033209
490
+ ]), de = /* @__PURE__ */ BigInt(2 ** 32 - 1), mn = /* @__PURE__ */ BigInt(32);
491
+ function Pn(t, e = !1) {
492
+ return e ? { h: Number(t & de), l: Number(t >> mn & de) } : { h: Number(t >> mn & de) | 0, l: Number(t & de) | 0 };
493
+ }
494
+ function Wn(t, e = !1) {
495
+ const n = t.length;
496
+ let r = new Uint32Array(n), i = new Uint32Array(n);
497
+ for (let s = 0; s < n; s++) {
498
+ const { h: c, l: o } = Pn(t[s], e);
499
+ [r[s], i[s]] = [c, o];
500
+ }
501
+ return [r, i];
502
+ }
503
+ const bn = (t, e, n) => t >>> n, yn = (t, e, n) => t << 32 - n | e >>> n, Rt = (t, e, n) => t >>> n | e << 32 - n, Lt = (t, e, n) => t << 32 - n | e >>> n, ee = (t, e, n) => t << 64 - n | e >>> n - 32, ne = (t, e, n) => t >>> n - 32 | e << 64 - n, Dr = (t, e) => e, Mr = (t, e) => t, Cr = (t, e, n) => t << n | e >>> 32 - n, zr = (t, e, n) => e << n | t >>> 32 - n, jr = (t, e, n) => e << n - 32 | t >>> 64 - n, Vr = (t, e, n) => t << n - 32 | e >>> 64 - n;
504
+ function at(t, e, n, r) {
505
+ const i = (e >>> 0) + (r >>> 0);
506
+ return { h: t + n + (i / 2 ** 32 | 0) | 0, l: i | 0 };
507
+ }
508
+ const Fe = (t, e, n) => (t >>> 0) + (e >>> 0) + (n >>> 0), tn = (t, e, n, r) => e + n + r + (t / 2 ** 32 | 0) | 0, Yr = (t, e, n, r) => (t >>> 0) + (e >>> 0) + (n >>> 0) + (r >>> 0), Gr = (t, e, n, r, i) => e + n + r + i + (t / 2 ** 32 | 0) | 0, Xr = (t, e, n, r, i) => (t >>> 0) + (e >>> 0) + (n >>> 0) + (r >>> 0) + (i >>> 0), Kr = (t, e, n, r, i, s) => e + n + r + i + s + (t / 2 ** 32 | 0) | 0, G = /* @__PURE__ */ Uint32Array.from([
509
+ 4089235720,
510
+ 1779033703,
511
+ 2227873595,
512
+ 3144134277,
513
+ 4271175723,
514
+ 1013904242,
515
+ 1595750129,
516
+ 2773480762,
517
+ 2917565137,
518
+ 1359893119,
519
+ 725511199,
520
+ 2600822924,
521
+ 4215389547,
522
+ 528734635,
523
+ 327033209,
524
+ 1541459225
525
+ ]), $ = /* @__PURE__ */ new Uint32Array(32);
526
+ function vt(t, e, n, r, i, s) {
527
+ const c = i[s], o = i[s + 1];
528
+ let f = $[2 * t], u = $[2 * t + 1], a = $[2 * e], w = $[2 * e + 1], l = $[2 * n], d = $[2 * n + 1], p = $[2 * r], b = $[2 * r + 1], h = Fe(f, a, c);
529
+ u = tn(h, u, w, o), f = h | 0, { Dh: b, Dl: p } = { Dh: b ^ u, Dl: p ^ f }, { Dh: b, Dl: p } = { Dh: Dr(b, p), Dl: Mr(b) }, { h: d, l } = at(d, l, b, p), { Bh: w, Bl: a } = { Bh: w ^ d, Bl: a ^ l }, { Bh: w, Bl: a } = { Bh: Rt(w, a, 24), Bl: Lt(w, a, 24) }, $[2 * t] = f, $[2 * t + 1] = u, $[2 * e] = a, $[2 * e + 1] = w, $[2 * n] = l, $[2 * n + 1] = d, $[2 * r] = p, $[2 * r + 1] = b;
530
+ }
531
+ function St(t, e, n, r, i, s) {
532
+ const c = i[s], o = i[s + 1];
533
+ let f = $[2 * t], u = $[2 * t + 1], a = $[2 * e], w = $[2 * e + 1], l = $[2 * n], d = $[2 * n + 1], p = $[2 * r], b = $[2 * r + 1], h = Fe(f, a, c);
534
+ u = tn(h, u, w, o), f = h | 0, { Dh: b, Dl: p } = { Dh: b ^ u, Dl: p ^ f }, { Dh: b, Dl: p } = { Dh: Rt(b, p, 16), Dl: Lt(b, p, 16) }, { h: d, l } = at(d, l, b, p), { Bh: w, Bl: a } = { Bh: w ^ d, Bl: a ^ l }, { Bh: w, Bl: a } = { Bh: ee(w, a, 63), Bl: ne(w, a, 63) }, $[2 * t] = f, $[2 * t + 1] = u, $[2 * e] = a, $[2 * e + 1] = w, $[2 * n] = l, $[2 * n + 1] = d, $[2 * r] = p, $[2 * r + 1] = b;
535
+ }
536
+ function Pr(t, e = {}, n, r, i) {
537
+ if (et(n), t < 0 || t > n)
538
+ throw new Error("outputLen bigger than keyLen");
539
+ const { key: s, salt: c, personalization: o } = e;
540
+ if (s !== void 0 && (s.length < 1 || s.length > n))
541
+ throw new Error("key length must be undefined or 1.." + n);
542
+ if (c !== void 0 && c.length !== r)
543
+ throw new Error("salt must be undefined or " + r);
544
+ if (o !== void 0 && o.length !== i)
545
+ throw new Error("personalization must be undefined or " + i);
546
+ }
547
+ class Wr extends Qe {
548
+ constructor(e, n) {
549
+ super(), this.finished = !1, this.destroyed = !1, this.length = 0, this.pos = 0, et(e), et(n), this.blockLen = e, this.outputLen = n, this.buffer = new Uint8Array(e), this.buffer32 = Mt(this.buffer);
550
+ }
551
+ update(e) {
552
+ Kt(this), e = Ht(e), W(e);
553
+ const { blockLen: n, buffer: r, buffer32: i } = this, s = e.length, c = e.byteOffset, o = e.buffer;
554
+ for (let f = 0; f < s; ) {
555
+ this.pos === n && (qt(i), this.compress(i, 0, !1), qt(i), this.pos = 0);
556
+ const u = Math.min(n - this.pos, s - f), a = c + f;
557
+ if (u === n && !(a % 4) && f + u < s) {
558
+ const w = new Uint32Array(o, a, Math.floor((s - f) / 4));
559
+ qt(w);
560
+ for (let l = 0; f + n < s; l += i.length, f += n)
561
+ this.length += n, this.compress(w, l, !1);
562
+ qt(w);
563
+ continue;
564
+ }
565
+ r.set(e.subarray(f, f + u), this.pos), this.pos += u, this.length += u, f += u;
566
+ }
567
+ return this;
568
+ }
569
+ digestInto(e) {
570
+ Kt(this), zn(e, this);
571
+ const { pos: n, buffer32: r } = this;
572
+ this.finished = !0, ft(this.buffer.subarray(n)), qt(r), this.compress(r, 0, !0), qt(r);
573
+ const i = Mt(e);
574
+ this.get().forEach((s, c) => i[c] = xt(s));
575
+ }
576
+ digest() {
577
+ const { buffer: e, outputLen: n } = this;
578
+ this.digestInto(e);
579
+ const r = e.slice(0, n);
580
+ return this.destroy(), r;
581
+ }
582
+ _cloneInto(e) {
583
+ const { buffer: n, length: r, finished: i, destroyed: s, outputLen: c, pos: o } = this;
584
+ return e || (e = new this.constructor({ dkLen: c })), e.set(...this.get()), e.buffer.set(n), e.destroyed = s, e.finished = i, e.length = r, e.pos = o, e.outputLen = c, e;
585
+ }
586
+ clone() {
587
+ return this._cloneInto();
588
+ }
589
+ }
590
+ class Qr extends Wr {
591
+ constructor(e = {}) {
592
+ const n = e.dkLen === void 0 ? 64 : e.dkLen;
593
+ super(128, n), this.v0l = G[0] | 0, this.v0h = G[1] | 0, this.v1l = G[2] | 0, this.v1h = G[3] | 0, this.v2l = G[4] | 0, this.v2h = G[5] | 0, this.v3l = G[6] | 0, this.v3h = G[7] | 0, this.v4l = G[8] | 0, this.v4h = G[9] | 0, this.v5l = G[10] | 0, this.v5h = G[11] | 0, this.v6l = G[12] | 0, this.v6h = G[13] | 0, this.v7l = G[14] | 0, this.v7h = G[15] | 0, Pr(n, e, 64, 16, 16);
594
+ let { key: r, personalization: i, salt: s } = e, c = 0;
595
+ if (r !== void 0 && (r = Ht(r), c = r.length), this.v0l ^= this.outputLen | c << 8 | 65536 | 1 << 24, s !== void 0) {
596
+ s = Ht(s);
597
+ const o = Mt(s);
598
+ this.v4l ^= xt(o[0]), this.v4h ^= xt(o[1]), this.v5l ^= xt(o[2]), this.v5h ^= xt(o[3]);
599
+ }
600
+ if (i !== void 0) {
601
+ i = Ht(i);
602
+ const o = Mt(i);
603
+ this.v6l ^= xt(o[0]), this.v6h ^= xt(o[1]), this.v7l ^= xt(o[2]), this.v7h ^= xt(o[3]);
604
+ }
605
+ if (r !== void 0) {
606
+ const o = new Uint8Array(this.blockLen);
607
+ o.set(r), this.update(o);
608
+ }
609
+ }
610
+ // prettier-ignore
611
+ get() {
612
+ let { v0l: e, v0h: n, v1l: r, v1h: i, v2l: s, v2h: c, v3l: o, v3h: f, v4l: u, v4h: a, v5l: w, v5h: l, v6l: d, v6h: p, v7l: b, v7h: h } = this;
613
+ return [e, n, r, i, s, c, o, f, u, a, w, l, d, p, b, h];
614
+ }
615
+ // prettier-ignore
616
+ set(e, n, r, i, s, c, o, f, u, a, w, l, d, p, b, h) {
617
+ this.v0l = e | 0, this.v0h = n | 0, this.v1l = r | 0, this.v1h = i | 0, this.v2l = s | 0, this.v2h = c | 0, this.v3l = o | 0, this.v3h = f | 0, this.v4l = u | 0, this.v4h = a | 0, this.v5l = w | 0, this.v5h = l | 0, this.v6l = d | 0, this.v6h = p | 0, this.v7l = b | 0, this.v7h = h | 0;
618
+ }
619
+ compress(e, n, r) {
620
+ this.get().forEach((f, u) => $[u] = f), $.set(G, 16);
621
+ let { h: i, l: s } = Pn(BigInt(this.length));
622
+ $[24] = G[8] ^ s, $[25] = G[9] ^ i, r && ($[28] = ~$[28], $[29] = ~$[29]);
623
+ let c = 0;
624
+ const o = kr;
625
+ for (let f = 0; f < 12; f++)
626
+ vt(0, 4, 8, 12, e, n + 2 * o[c++]), St(0, 4, 8, 12, e, n + 2 * o[c++]), vt(1, 5, 9, 13, e, n + 2 * o[c++]), St(1, 5, 9, 13, e, n + 2 * o[c++]), vt(2, 6, 10, 14, e, n + 2 * o[c++]), St(2, 6, 10, 14, e, n + 2 * o[c++]), vt(3, 7, 11, 15, e, n + 2 * o[c++]), St(3, 7, 11, 15, e, n + 2 * o[c++]), vt(0, 5, 10, 15, e, n + 2 * o[c++]), St(0, 5, 10, 15, e, n + 2 * o[c++]), vt(1, 6, 11, 12, e, n + 2 * o[c++]), St(1, 6, 11, 12, e, n + 2 * o[c++]), vt(2, 7, 8, 13, e, n + 2 * o[c++]), St(2, 7, 8, 13, e, n + 2 * o[c++]), vt(3, 4, 9, 14, e, n + 2 * o[c++]), St(3, 4, 9, 14, e, n + 2 * o[c++]);
627
+ this.v0l ^= $[0] ^ $[16], this.v0h ^= $[1] ^ $[17], this.v1l ^= $[2] ^ $[18], this.v1h ^= $[3] ^ $[19], this.v2l ^= $[4] ^ $[20], this.v2h ^= $[5] ^ $[21], this.v3l ^= $[6] ^ $[22], this.v3h ^= $[7] ^ $[23], this.v4l ^= $[8] ^ $[24], this.v4h ^= $[9] ^ $[25], this.v5l ^= $[10] ^ $[26], this.v5h ^= $[11] ^ $[27], this.v6l ^= $[12] ^ $[28], this.v6h ^= $[13] ^ $[29], this.v7l ^= $[14] ^ $[30], this.v7h ^= $[15] ^ $[31], ft($);
628
+ }
629
+ destroy() {
630
+ this.destroyed = !0, ft(this.buffer32), this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
631
+ }
632
+ }
633
+ const Jr = /* @__PURE__ */ Hr((t) => new Qr(t));
634
+ const Ks = Jr;
635
+ class Qn extends Qe {
636
+ constructor(e, n) {
637
+ super(), this.finished = !1, this.destroyed = !1, Cn(e);
638
+ const r = Ht(n);
639
+ if (this.iHash = e.create(), typeof this.iHash.update != "function")
640
+ throw new Error("Expected instance of class which extends utils.Hash");
641
+ this.blockLen = this.iHash.blockLen, this.outputLen = this.iHash.outputLen;
642
+ const i = this.blockLen, s = new Uint8Array(i);
643
+ s.set(r.length > i ? e.create().update(r).digest() : r);
644
+ for (let c = 0; c < s.length; c++)
645
+ s[c] ^= 54;
646
+ this.iHash.update(s), this.oHash = e.create();
647
+ for (let c = 0; c < s.length; c++)
648
+ s[c] ^= 106;
649
+ this.oHash.update(s), ft(s);
650
+ }
651
+ update(e) {
652
+ return Kt(this), this.iHash.update(e), this;
653
+ }
654
+ digestInto(e) {
655
+ Kt(this), W(e, this.outputLen), this.finished = !0, this.iHash.digestInto(e), this.oHash.update(e), this.oHash.digestInto(e), this.destroy();
656
+ }
657
+ digest() {
658
+ const e = new Uint8Array(this.oHash.outputLen);
659
+ return this.digestInto(e), e;
660
+ }
661
+ _cloneInto(e) {
662
+ e || (e = Object.create(Object.getPrototypeOf(this), {}));
663
+ const { oHash: n, iHash: r, finished: i, destroyed: s, blockLen: c, outputLen: o } = this;
664
+ return e = e, e.finished = i, e.destroyed = s, e.blockLen = c, e.outputLen = o, e.oHash = n._cloneInto(e.oHash), e.iHash = r._cloneInto(e.iHash), e;
665
+ }
666
+ clone() {
667
+ return this._cloneInto();
668
+ }
669
+ destroy() {
670
+ this.destroyed = !0, this.oHash.destroy(), this.iHash.destroy();
671
+ }
672
+ }
673
+ const en = (t, e, n) => new Qn(t, e).update(n).digest();
674
+ en.create = (t, e) => new Qn(t, e);
675
+ function Fr(t, e, n, r) {
676
+ Cn(t);
677
+ const i = Gn({ dkLen: 32, asyncTick: 10 }, r), { c: s, dkLen: c, asyncTick: o } = i;
678
+ if (et(s), et(c), et(o), s < 1)
679
+ throw new Error("iterations (c) should be >= 1");
680
+ const f = wn(e), u = wn(n), a = new Uint8Array(c), w = en.create(t, f), l = w._cloneInto().update(u);
681
+ return { c: s, dkLen: c, asyncTick: o, DK: a, PRF: w, PRFSalt: l };
682
+ }
683
+ function to(t, e, n, r, i) {
684
+ return t.destroy(), e.destroy(), r && r.destroy(), ft(i), n;
685
+ }
686
+ function Jn(t, e, n, r) {
687
+ const { c: i, dkLen: s, DK: c, PRF: o, PRFSalt: f } = Fr(t, e, n, r);
688
+ let u;
689
+ const a = new Uint8Array(4), w = be(a), l = new Uint8Array(o.outputLen);
690
+ for (let d = 1, p = 0; p < s; d++, p += o.outputLen) {
691
+ const b = c.subarray(p, p + o.outputLen);
692
+ w.setInt32(0, d, !1), (u = f._cloneInto(u)).update(a).digestInto(l), b.set(l.subarray(0, b.length));
693
+ for (let h = 1; h < i; h++) {
694
+ o._cloneInto(u).update(l).digestInto(l);
695
+ for (let x = 0; x < b.length; x++)
696
+ b[x] ^= l[x];
697
+ }
698
+ }
699
+ return to(o, f, c, u, l);
700
+ }
701
+ const eo = /* @__PURE__ */ Uint32Array.from([
702
+ 1116352408,
703
+ 1899447441,
704
+ 3049323471,
705
+ 3921009573,
706
+ 961987163,
707
+ 1508970993,
708
+ 2453635748,
709
+ 2870763221,
710
+ 3624381080,
711
+ 310598401,
712
+ 607225278,
713
+ 1426881987,
714
+ 1925078388,
715
+ 2162078206,
716
+ 2614888103,
717
+ 3248222580,
718
+ 3835390401,
719
+ 4022224774,
720
+ 264347078,
721
+ 604807628,
722
+ 770255983,
723
+ 1249150122,
724
+ 1555081692,
725
+ 1996064986,
726
+ 2554220882,
727
+ 2821834349,
728
+ 2952996808,
729
+ 3210313671,
730
+ 3336571891,
731
+ 3584528711,
732
+ 113926993,
733
+ 338241895,
734
+ 666307205,
735
+ 773529912,
736
+ 1294757372,
737
+ 1396182291,
738
+ 1695183700,
739
+ 1986661051,
740
+ 2177026350,
741
+ 2456956037,
742
+ 2730485921,
743
+ 2820302411,
744
+ 3259730800,
745
+ 3345764771,
746
+ 3516065817,
747
+ 3600352804,
748
+ 4094571909,
749
+ 275423344,
750
+ 430227734,
751
+ 506948616,
752
+ 659060556,
753
+ 883997877,
754
+ 958139571,
755
+ 1322822218,
756
+ 1537002063,
757
+ 1747873779,
758
+ 1955562222,
759
+ 2024104815,
760
+ 2227730452,
761
+ 2361852424,
762
+ 2428436474,
763
+ 2756734187,
764
+ 3204031479,
765
+ 3329325298
766
+ ]), At = /* @__PURE__ */ new Uint32Array(64);
767
+ class no extends Kn {
768
+ constructor(e = 32) {
769
+ super(64, e, 8, !1), this.A = _t[0] | 0, this.B = _t[1] | 0, this.C = _t[2] | 0, this.D = _t[3] | 0, this.E = _t[4] | 0, this.F = _t[5] | 0, this.G = _t[6] | 0, this.H = _t[7] | 0;
770
+ }
771
+ get() {
772
+ const { A: e, B: n, C: r, D: i, E: s, F: c, G: o, H: f } = this;
773
+ return [e, n, r, i, s, c, o, f];
774
+ }
775
+ // prettier-ignore
776
+ set(e, n, r, i, s, c, o, f) {
777
+ this.A = e | 0, this.B = n | 0, this.C = r | 0, this.D = i | 0, this.E = s | 0, this.F = c | 0, this.G = o | 0, this.H = f | 0;
778
+ }
779
+ process(e, n) {
780
+ for (let w = 0; w < 16; w++, n += 4)
781
+ At[w] = e.getUint32(n, !1);
782
+ for (let w = 16; w < 64; w++) {
783
+ const l = At[w - 15], d = At[w - 2], p = wt(l, 7) ^ wt(l, 18) ^ l >>> 3, b = wt(d, 17) ^ wt(d, 19) ^ d >>> 10;
784
+ At[w] = b + At[w - 7] + p + At[w - 16] | 0;
785
+ }
786
+ let { A: r, B: i, C: s, D: c, E: o, F: f, G: u, H: a } = this;
787
+ for (let w = 0; w < 64; w++) {
788
+ const l = wt(o, 6) ^ wt(o, 11) ^ wt(o, 25), d = a + l + Ur(o, f, u) + eo[w] + At[w] | 0, b = (wt(r, 2) ^ wt(r, 13) ^ wt(r, 22)) + Zr(r, i, s) | 0;
789
+ a = u, u = f, f = o, o = c + d | 0, c = s, s = i, i = r, r = d + b | 0;
790
+ }
791
+ r = r + this.A | 0, i = i + this.B | 0, s = s + this.C | 0, c = c + this.D | 0, o = o + this.E | 0, f = f + this.F | 0, u = u + this.G | 0, a = a + this.H | 0, this.set(r, i, s, c, o, f, u, a);
792
+ }
793
+ roundClean() {
794
+ ft(At);
795
+ }
796
+ destroy() {
797
+ this.set(0, 0, 0, 0, 0, 0, 0, 0), ft(this.buffer);
798
+ }
799
+ }
800
+ const Fn = Wn([
801
+ "0x428a2f98d728ae22",
802
+ "0x7137449123ef65cd",
803
+ "0xb5c0fbcfec4d3b2f",
804
+ "0xe9b5dba58189dbbc",
805
+ "0x3956c25bf348b538",
806
+ "0x59f111f1b605d019",
807
+ "0x923f82a4af194f9b",
808
+ "0xab1c5ed5da6d8118",
809
+ "0xd807aa98a3030242",
810
+ "0x12835b0145706fbe",
811
+ "0x243185be4ee4b28c",
812
+ "0x550c7dc3d5ffb4e2",
813
+ "0x72be5d74f27b896f",
814
+ "0x80deb1fe3b1696b1",
815
+ "0x9bdc06a725c71235",
816
+ "0xc19bf174cf692694",
817
+ "0xe49b69c19ef14ad2",
818
+ "0xefbe4786384f25e3",
819
+ "0x0fc19dc68b8cd5b5",
820
+ "0x240ca1cc77ac9c65",
821
+ "0x2de92c6f592b0275",
822
+ "0x4a7484aa6ea6e483",
823
+ "0x5cb0a9dcbd41fbd4",
824
+ "0x76f988da831153b5",
825
+ "0x983e5152ee66dfab",
826
+ "0xa831c66d2db43210",
827
+ "0xb00327c898fb213f",
828
+ "0xbf597fc7beef0ee4",
829
+ "0xc6e00bf33da88fc2",
830
+ "0xd5a79147930aa725",
831
+ "0x06ca6351e003826f",
832
+ "0x142929670a0e6e70",
833
+ "0x27b70a8546d22ffc",
834
+ "0x2e1b21385c26c926",
835
+ "0x4d2c6dfc5ac42aed",
836
+ "0x53380d139d95b3df",
837
+ "0x650a73548baf63de",
838
+ "0x766a0abb3c77b2a8",
839
+ "0x81c2c92e47edaee6",
840
+ "0x92722c851482353b",
841
+ "0xa2bfe8a14cf10364",
842
+ "0xa81a664bbc423001",
843
+ "0xc24b8b70d0f89791",
844
+ "0xc76c51a30654be30",
845
+ "0xd192e819d6ef5218",
846
+ "0xd69906245565a910",
847
+ "0xf40e35855771202a",
848
+ "0x106aa07032bbd1b8",
849
+ "0x19a4c116b8d2d0c8",
850
+ "0x1e376c085141ab53",
851
+ "0x2748774cdf8eeb99",
852
+ "0x34b0bcb5e19b48a8",
853
+ "0x391c0cb3c5c95a63",
854
+ "0x4ed8aa4ae3418acb",
855
+ "0x5b9cca4f7763e373",
856
+ "0x682e6ff3d6b2b8a3",
857
+ "0x748f82ee5defb2fc",
858
+ "0x78a5636f43172f60",
859
+ "0x84c87814a1f0ab72",
860
+ "0x8cc702081a6439ec",
861
+ "0x90befffa23631e28",
862
+ "0xa4506cebde82bde9",
863
+ "0xbef9a3f7b2c67915",
864
+ "0xc67178f2e372532b",
865
+ "0xca273eceea26619c",
866
+ "0xd186b8c721c0c207",
867
+ "0xeada7dd6cde0eb1e",
868
+ "0xf57d4f7fee6ed178",
869
+ "0x06f067aa72176fba",
870
+ "0x0a637dc5a2c898a6",
871
+ "0x113f9804bef90dae",
872
+ "0x1b710b35131c471b",
873
+ "0x28db77f523047d84",
874
+ "0x32caab7b40c72493",
875
+ "0x3c9ebe0a15c9bebc",
876
+ "0x431d67c49c100d4c",
877
+ "0x4cc5d4becb3e42b6",
878
+ "0x597f299cfc657e2a",
879
+ "0x5fcb6fab3ad6faec",
880
+ "0x6c44198c4a475817"
881
+ ].map((t) => BigInt(t))), ro = Fn[0], oo = Fn[1], It = /* @__PURE__ */ new Uint32Array(80), Ot = /* @__PURE__ */ new Uint32Array(80);
882
+ class so extends Kn {
883
+ constructor(e = 64) {
884
+ super(128, e, 16, !1), this.Ah = F[0] | 0, this.Al = F[1] | 0, this.Bh = F[2] | 0, this.Bl = F[3] | 0, this.Ch = F[4] | 0, this.Cl = F[5] | 0, this.Dh = F[6] | 0, this.Dl = F[7] | 0, this.Eh = F[8] | 0, this.El = F[9] | 0, this.Fh = F[10] | 0, this.Fl = F[11] | 0, this.Gh = F[12] | 0, this.Gl = F[13] | 0, this.Hh = F[14] | 0, this.Hl = F[15] | 0;
885
+ }
886
+ // prettier-ignore
887
+ get() {
888
+ const { Ah: e, Al: n, Bh: r, Bl: i, Ch: s, Cl: c, Dh: o, Dl: f, Eh: u, El: a, Fh: w, Fl: l, Gh: d, Gl: p, Hh: b, Hl: h } = this;
889
+ return [e, n, r, i, s, c, o, f, u, a, w, l, d, p, b, h];
890
+ }
891
+ // prettier-ignore
892
+ set(e, n, r, i, s, c, o, f, u, a, w, l, d, p, b, h) {
893
+ this.Ah = e | 0, this.Al = n | 0, this.Bh = r | 0, this.Bl = i | 0, this.Ch = s | 0, this.Cl = c | 0, this.Dh = o | 0, this.Dl = f | 0, this.Eh = u | 0, this.El = a | 0, this.Fh = w | 0, this.Fl = l | 0, this.Gh = d | 0, this.Gl = p | 0, this.Hh = b | 0, this.Hl = h | 0;
894
+ }
895
+ process(e, n) {
896
+ for (let A = 0; A < 16; A++, n += 4)
897
+ It[A] = e.getUint32(n), Ot[A] = e.getUint32(n += 4);
898
+ for (let A = 16; A < 80; A++) {
899
+ const L = It[A - 15] | 0, B = Ot[A - 15] | 0, R = Rt(L, B, 1) ^ Rt(L, B, 8) ^ bn(L, B, 7), N = Lt(L, B, 1) ^ Lt(L, B, 8) ^ yn(L, B, 7), q = It[A - 2] | 0, g = Ot[A - 2] | 0, _ = Rt(q, g, 19) ^ ee(q, g, 61) ^ bn(q, g, 6), m = Lt(q, g, 19) ^ ne(q, g, 61) ^ yn(q, g, 6), y = Yr(N, m, Ot[A - 7], Ot[A - 16]), E = Gr(y, R, _, It[A - 7], It[A - 16]);
900
+ It[A] = E | 0, Ot[A] = y | 0;
901
+ }
902
+ let { Ah: r, Al: i, Bh: s, Bl: c, Ch: o, Cl: f, Dh: u, Dl: a, Eh: w, El: l, Fh: d, Fl: p, Gh: b, Gl: h, Hh: x, Hl: v } = this;
903
+ for (let A = 0; A < 80; A++) {
904
+ const L = Rt(w, l, 14) ^ Rt(w, l, 18) ^ ee(w, l, 41), B = Lt(w, l, 14) ^ Lt(w, l, 18) ^ ne(w, l, 41), R = w & d ^ ~w & b, N = l & p ^ ~l & h, q = Xr(v, B, N, oo[A], Ot[A]), g = Kr(q, x, L, R, ro[A], It[A]), _ = q | 0, m = Rt(r, i, 28) ^ ee(r, i, 34) ^ ee(r, i, 39), y = Lt(r, i, 28) ^ ne(r, i, 34) ^ ne(r, i, 39), E = r & s ^ r & o ^ s & o, S = i & c ^ i & f ^ c & f;
905
+ x = b | 0, v = h | 0, b = d | 0, h = p | 0, d = w | 0, p = l | 0, { h: w, l } = at(u | 0, a | 0, g | 0, _ | 0), u = o | 0, a = f | 0, o = s | 0, f = c | 0, s = r | 0, c = i | 0;
906
+ const I = Fe(_, y, S);
907
+ r = tn(I, g, m, E), i = I | 0;
908
+ }
909
+ ({ h: r, l: i } = at(this.Ah | 0, this.Al | 0, r | 0, i | 0)), { h: s, l: c } = at(this.Bh | 0, this.Bl | 0, s | 0, c | 0), { h: o, l: f } = at(this.Ch | 0, this.Cl | 0, o | 0, f | 0), { h: u, l: a } = at(this.Dh | 0, this.Dl | 0, u | 0, a | 0), { h: w, l } = at(this.Eh | 0, this.El | 0, w | 0, l | 0), { h: d, l: p } = at(this.Fh | 0, this.Fl | 0, d | 0, p | 0), { h: b, l: h } = at(this.Gh | 0, this.Gl | 0, b | 0, h | 0), { h: x, l: v } = at(this.Hh | 0, this.Hl | 0, x | 0, v | 0), this.set(r, i, s, c, o, f, u, a, w, l, d, p, b, h, x, v);
910
+ }
911
+ roundClean() {
912
+ ft(It, Ot);
913
+ }
914
+ destroy() {
915
+ ft(this.buffer), this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
916
+ }
917
+ }
918
+ const Ee = /* @__PURE__ */ Xn(() => new no()), nn = /* @__PURE__ */ Xn(() => new so());
919
+ function gn(t, e, n, r, i, s) {
920
+ let c = t[e++] ^ n[r++], o = t[e++] ^ n[r++], f = t[e++] ^ n[r++], u = t[e++] ^ n[r++], a = t[e++] ^ n[r++], w = t[e++] ^ n[r++], l = t[e++] ^ n[r++], d = t[e++] ^ n[r++], p = t[e++] ^ n[r++], b = t[e++] ^ n[r++], h = t[e++] ^ n[r++], x = t[e++] ^ n[r++], v = t[e++] ^ n[r++], A = t[e++] ^ n[r++], L = t[e++] ^ n[r++], B = t[e++] ^ n[r++], R = c, N = o, q = f, g = u, _ = a, m = w, y = l, E = d, S = p, I = b, O = h, H = x, k = v, Z = A, U = L, T = B;
921
+ for (let M = 0; M < 8; M += 2)
922
+ _ ^= D(R + k | 0, 7), S ^= D(_ + R | 0, 9), k ^= D(S + _ | 0, 13), R ^= D(k + S | 0, 18), I ^= D(m + N | 0, 7), Z ^= D(I + m | 0, 9), N ^= D(Z + I | 0, 13), m ^= D(N + Z | 0, 18), U ^= D(O + y | 0, 7), q ^= D(U + O | 0, 9), y ^= D(q + U | 0, 13), O ^= D(y + q | 0, 18), g ^= D(T + H | 0, 7), E ^= D(g + T | 0, 9), H ^= D(E + g | 0, 13), T ^= D(H + E | 0, 18), N ^= D(R + g | 0, 7), q ^= D(N + R | 0, 9), g ^= D(q + N | 0, 13), R ^= D(g + q | 0, 18), y ^= D(m + _ | 0, 7), E ^= D(y + m | 0, 9), _ ^= D(E + y | 0, 13), m ^= D(_ + E | 0, 18), H ^= D(O + I | 0, 7), S ^= D(H + O | 0, 9), I ^= D(S + H | 0, 13), O ^= D(I + S | 0, 18), k ^= D(T + U | 0, 7), Z ^= D(k + T | 0, 9), U ^= D(Z + k | 0, 13), T ^= D(U + Z | 0, 18);
923
+ i[s++] = c + R | 0, i[s++] = o + N | 0, i[s++] = f + q | 0, i[s++] = u + g | 0, i[s++] = a + _ | 0, i[s++] = w + m | 0, i[s++] = l + y | 0, i[s++] = d + E | 0, i[s++] = p + S | 0, i[s++] = b + I | 0, i[s++] = h + O | 0, i[s++] = x + H | 0, i[s++] = v + k | 0, i[s++] = A + Z | 0, i[s++] = L + U | 0, i[s++] = B + T | 0;
924
+ }
925
+ function Ae(t, e, n, r, i) {
926
+ let s = r + 0, c = r + 16 * i;
927
+ for (let o = 0; o < 16; o++)
928
+ n[c + o] = t[e + (2 * i - 1) * 16 + o];
929
+ for (let o = 0; o < i; o++, s += 16, e += 16)
930
+ gn(n, c, t, e, n, s), o > 0 && (c += 16), gn(n, s, t, e += 16, n, c);
931
+ }
932
+ function io(t, e, n) {
933
+ const r = Gn({
934
+ dkLen: 32,
935
+ asyncTick: 10,
936
+ maxmem: 1073742848
937
+ }, n), { N: i, r: s, p: c, dkLen: o, asyncTick: f, maxmem: u, onProgress: a } = r;
938
+ if (et(i), et(s), et(c), et(o), et(f), et(u), a !== void 0 && typeof a != "function")
939
+ throw new Error("progressCb should be function");
940
+ const w = 128 * s, l = w / 4, d = Math.pow(2, 32);
941
+ if (i <= 1 || (i & i - 1) !== 0 || i > d)
942
+ throw new Error("Scrypt: N must be larger than 1, a power of 2, and less than 2^32");
943
+ if (c < 0 || c > (d - 1) * 32 / w)
944
+ throw new Error("Scrypt: p must be a positive integer less than or equal to ((2^32 - 1) * 32) / (128 * r)");
945
+ if (o < 0 || o > (d - 1) * 32)
946
+ throw new Error("Scrypt: dkLen should be positive integer less than or equal to (2^32 - 1) * 32");
947
+ if (w * (i + c) > u)
948
+ throw new Error("Scrypt: memused is bigger than maxMem. Expected 128 * r * (N + p) > maxmem of " + u);
949
+ const b = Jn(Ee, t, e, { c: 1, dkLen: w * c }), h = Mt(b), x = Mt(new Uint8Array(w * i)), v = Mt(new Uint8Array(w));
950
+ let A = () => {
951
+ };
952
+ if (a) {
953
+ const L = 2 * i * c, B = Math.max(Math.floor(L / 1e4), 1);
954
+ let R = 0;
955
+ A = () => {
956
+ R++, a && (!(R % B) || R === L) && a(R / L);
957
+ };
958
+ }
959
+ return { N: i, r: s, p: c, dkLen: o, blockSize32: l, V: x, B32: h, B: b, tmp: v, blockMixCb: A, asyncTick: f };
960
+ }
961
+ function co(t, e, n, r, i) {
962
+ const s = Jn(Ee, t, n, { c: 1, dkLen: e });
963
+ return ft(n, r, i), s;
964
+ }
965
+ function Ps(t, e, n) {
966
+ const { N: r, r: i, p: s, dkLen: c, blockSize32: o, V: f, B32: u, B: a, tmp: w, blockMixCb: l } = io(t, e, n);
967
+ qt(u);
968
+ for (let d = 0; d < s; d++) {
969
+ const p = o * d;
970
+ for (let b = 0; b < o; b++)
971
+ f[b] = u[p + b];
972
+ for (let b = 0, h = 0; b < r - 1; b++)
973
+ Ae(f, h, f, h += o, i), l();
974
+ Ae(f, (r - 1) * o, u, p, i), l();
975
+ for (let b = 0; b < r; b++) {
976
+ const h = u[p + o - 16] % r;
977
+ for (let x = 0; x < o; x++)
978
+ w[x] = u[p + x] ^ f[h * o + x];
979
+ Ae(w, 0, u, p, i), l();
980
+ }
981
+ }
982
+ return qt(u), co(t, c, a, f, w);
983
+ }
984
+ const rn = /* @__PURE__ */ BigInt(0), De = /* @__PURE__ */ BigInt(1);
985
+ function Me(t, e) {
986
+ if (typeof e != "boolean")
987
+ throw new Error(t + " boolean expected, got " + e);
988
+ }
989
+ function tr(t) {
990
+ if (typeof t != "string")
991
+ throw new Error("hex string expected, got " + typeof t);
992
+ return t === "" ? rn : BigInt("0x" + t);
993
+ }
994
+ function fo(t) {
995
+ return tr(ht(t));
996
+ }
997
+ function ce(t) {
998
+ return W(t), tr(ht(Uint8Array.from(t).reverse()));
999
+ }
1000
+ function er(t, e) {
1001
+ return ae(t.toString(16).padStart(e * 2, "0"));
1002
+ }
1003
+ function fe(t, e) {
1004
+ return er(t, e).reverse();
1005
+ }
1006
+ function lt(t, e, n) {
1007
+ let r;
1008
+ if (typeof e == "string")
1009
+ try {
1010
+ r = ae(e);
1011
+ } catch (s) {
1012
+ throw new Error(t + " must be hex string or Uint8Array, cause: " + s);
1013
+ }
1014
+ else if (pe(e))
1015
+ r = Uint8Array.from(e);
1016
+ else
1017
+ throw new Error(t + " must be hex string or Uint8Array");
1018
+ const i = r.length;
1019
+ if (typeof n == "number" && i !== n)
1020
+ throw new Error(t + " of length " + n + " expected, got " + i);
1021
+ return r;
1022
+ }
1023
+ function ao(t, e) {
1024
+ if (t.length !== e.length)
1025
+ return !1;
1026
+ let n = 0;
1027
+ for (let r = 0; r < t.length; r++)
1028
+ n |= t[r] ^ e[r];
1029
+ return n === 0;
1030
+ }
1031
+ const Ie = (t) => typeof t == "bigint" && rn <= t;
1032
+ function lo(t, e, n) {
1033
+ return Ie(t) && Ie(e) && Ie(n) && e <= t && t < n;
1034
+ }
1035
+ function re(t, e, n, r) {
1036
+ if (!lo(e, n, r))
1037
+ throw new Error("expected valid " + t + ": " + n + " <= n < " + r + ", got " + e);
1038
+ }
1039
+ function uo(t) {
1040
+ let e;
1041
+ for (e = 0; t > rn; t >>= De, e += 1)
1042
+ ;
1043
+ return e;
1044
+ }
1045
+ const on = (t) => (De << BigInt(t)) - De;
1046
+ function sn(t, e, n = {}) {
1047
+ if (!t || typeof t != "object")
1048
+ throw new Error("expected valid options object");
1049
+ function r(i, s, c) {
1050
+ const o = t[i];
1051
+ if (c && o === void 0)
1052
+ return;
1053
+ const f = typeof o;
1054
+ if (f !== s || o === null)
1055
+ throw new Error(`param "${i}" is invalid: expected ${s}, got ${f}`);
1056
+ }
1057
+ Object.entries(e).forEach(([i, s]) => r(i, s, !1)), Object.entries(n).forEach(([i, s]) => r(i, s, !0));
1058
+ }
1059
+ function xn(t) {
1060
+ const e = /* @__PURE__ */ new WeakMap();
1061
+ return (n, ...r) => {
1062
+ const i = e.get(n);
1063
+ if (i !== void 0)
1064
+ return i;
1065
+ const s = t(n, ...r);
1066
+ return e.set(n, s), s;
1067
+ };
1068
+ }
1069
+ const st = BigInt(0), ot = BigInt(1), Ut = /* @__PURE__ */ BigInt(2), nr = /* @__PURE__ */ BigInt(3), rr = /* @__PURE__ */ BigInt(4), or = /* @__PURE__ */ BigInt(5), ho = /* @__PURE__ */ BigInt(7), sr = /* @__PURE__ */ BigInt(8), wo = /* @__PURE__ */ BigInt(9), ir = /* @__PURE__ */ BigInt(16);
1070
+ function P(t, e) {
1071
+ const n = t % e;
1072
+ return n >= st ? n : e + n;
1073
+ }
1074
+ function mt(t, e, n) {
1075
+ let r = t;
1076
+ for (; e-- > st; )
1077
+ r *= r, r %= n;
1078
+ return r;
1079
+ }
1080
+ function pn(t, e) {
1081
+ if (t === st)
1082
+ throw new Error("invert: expected non-zero number");
1083
+ if (e <= st)
1084
+ throw new Error("invert: expected positive modulus, got " + e);
1085
+ let n = P(t, e), r = e, i = st, s = ot;
1086
+ for (; n !== st; ) {
1087
+ const o = r / n, f = r % n, u = i - s * o;
1088
+ r = n, n = f, i = s, s = u;
1089
+ }
1090
+ if (r !== ot)
1091
+ throw new Error("invert: does not exist");
1092
+ return P(i, e);
1093
+ }
1094
+ function cn(t, e, n) {
1095
+ if (!t.eql(t.sqr(e), n))
1096
+ throw new Error("Cannot find square root");
1097
+ }
1098
+ function cr(t, e) {
1099
+ const n = (t.ORDER + ot) / rr, r = t.pow(e, n);
1100
+ return cn(t, r, e), r;
1101
+ }
1102
+ function mo(t, e) {
1103
+ const n = (t.ORDER - or) / sr, r = t.mul(e, Ut), i = t.pow(r, n), s = t.mul(e, i), c = t.mul(t.mul(s, Ut), i), o = t.mul(s, t.sub(c, t.ONE));
1104
+ return cn(t, o, e), o;
1105
+ }
1106
+ function bo(t) {
1107
+ const e = Jt(t), n = fr(t), r = n(e, e.neg(e.ONE)), i = n(e, r), s = n(e, e.neg(r)), c = (t + ho) / ir;
1108
+ return (o, f) => {
1109
+ let u = o.pow(f, c), a = o.mul(u, r);
1110
+ const w = o.mul(u, i), l = o.mul(u, s), d = o.eql(o.sqr(a), f), p = o.eql(o.sqr(w), f);
1111
+ u = o.cmov(u, a, d), a = o.cmov(l, w, p);
1112
+ const b = o.eql(o.sqr(a), f), h = o.cmov(u, a, b);
1113
+ return cn(o, h, f), h;
1114
+ };
1115
+ }
1116
+ function fr(t) {
1117
+ if (t < nr)
1118
+ throw new Error("sqrt is not defined for small field");
1119
+ let e = t - ot, n = 0;
1120
+ for (; e % Ut === st; )
1121
+ e /= Ut, n++;
1122
+ let r = Ut;
1123
+ const i = Jt(t);
1124
+ for (; En(i, r) === 1; )
1125
+ if (r++ > 1e3)
1126
+ throw new Error("Cannot find square root: probably non-prime P");
1127
+ if (n === 1)
1128
+ return cr;
1129
+ let s = i.pow(r, e);
1130
+ const c = (e + ot) / Ut;
1131
+ return function(f, u) {
1132
+ if (f.is0(u))
1133
+ return u;
1134
+ if (En(f, u) !== 1)
1135
+ throw new Error("Cannot find square root");
1136
+ let a = n, w = f.mul(f.ONE, s), l = f.pow(u, e), d = f.pow(u, c);
1137
+ for (; !f.eql(l, f.ONE); ) {
1138
+ if (f.is0(l))
1139
+ return f.ZERO;
1140
+ let p = 1, b = f.sqr(l);
1141
+ for (; !f.eql(b, f.ONE); )
1142
+ if (p++, b = f.sqr(b), p === a)
1143
+ throw new Error("Cannot find square root");
1144
+ const h = ot << BigInt(a - p - 1), x = f.pow(w, h);
1145
+ a = p, w = f.sqr(x), l = f.mul(l, w), d = f.mul(d, x);
1146
+ }
1147
+ return d;
1148
+ };
1149
+ }
1150
+ function yo(t) {
1151
+ return t % rr === nr ? cr : t % sr === or ? mo : t % ir === wo ? bo(t) : fr(t);
1152
+ }
1153
+ const Nt = (t, e) => (P(t, e) & ot) === ot, go = [
1154
+ "create",
1155
+ "isValid",
1156
+ "is0",
1157
+ "neg",
1158
+ "inv",
1159
+ "sqrt",
1160
+ "sqr",
1161
+ "eql",
1162
+ "add",
1163
+ "sub",
1164
+ "mul",
1165
+ "pow",
1166
+ "div",
1167
+ "addN",
1168
+ "subN",
1169
+ "mulN",
1170
+ "sqrN"
1171
+ ];
1172
+ function xo(t) {
1173
+ const e = {
1174
+ ORDER: "bigint",
1175
+ MASK: "bigint",
1176
+ BYTES: "number",
1177
+ BITS: "number"
1178
+ }, n = go.reduce((r, i) => (r[i] = "function", r), e);
1179
+ return sn(t, n), t;
1180
+ }
1181
+ function po(t, e, n) {
1182
+ if (n < st)
1183
+ throw new Error("invalid exponent, negatives unsupported");
1184
+ if (n === st)
1185
+ return t.ONE;
1186
+ if (n === ot)
1187
+ return e;
1188
+ let r = t.ONE, i = e;
1189
+ for (; n > st; )
1190
+ n & ot && (r = t.mul(r, i)), i = t.sqr(i), n >>= ot;
1191
+ return r;
1192
+ }
1193
+ function ar(t, e, n = !1) {
1194
+ const r = new Array(e.length).fill(n ? t.ZERO : void 0), i = e.reduce((c, o, f) => t.is0(o) ? c : (r[f] = c, t.mul(c, o)), t.ONE), s = t.inv(i);
1195
+ return e.reduceRight((c, o, f) => t.is0(o) ? c : (r[f] = t.mul(c, r[f]), t.mul(c, o)), s), r;
1196
+ }
1197
+ function En(t, e) {
1198
+ const n = (t.ORDER - ot) / Ut, r = t.pow(e, n), i = t.eql(r, t.ONE), s = t.eql(r, t.ZERO), c = t.eql(r, t.neg(t.ONE));
1199
+ if (!i && !s && !c)
1200
+ throw new Error("invalid Legendre symbol result");
1201
+ return i ? 1 : s ? 0 : -1;
1202
+ }
1203
+ function Eo(t, e) {
1204
+ e !== void 0 && et(e);
1205
+ const n = e !== void 0 ? e : t.toString(2).length, r = Math.ceil(n / 8);
1206
+ return { nBitLength: n, nByteLength: r };
1207
+ }
1208
+ function Jt(t, e, n = !1, r = {}) {
1209
+ if (t <= st)
1210
+ throw new Error("invalid field: expected ORDER > 0, got " + t);
1211
+ let i, s, c = !1, o;
1212
+ if (typeof e == "object" && e != null) {
1213
+ if (r.sqrt || n)
1214
+ throw new Error("cannot specify opts in two arguments");
1215
+ const l = e;
1216
+ l.BITS && (i = l.BITS), l.sqrt && (s = l.sqrt), typeof l.isLE == "boolean" && (n = l.isLE), typeof l.modOnDecode == "boolean" && (c = l.modOnDecode), o = l.allowedLengths;
1217
+ } else
1218
+ typeof e == "number" && (i = e), r.sqrt && (s = r.sqrt);
1219
+ const { nBitLength: f, nByteLength: u } = Eo(t, i);
1220
+ if (u > 2048)
1221
+ throw new Error("invalid field: expected ORDER of <= 2048 bytes");
1222
+ let a;
1223
+ const w = Object.freeze({
1224
+ ORDER: t,
1225
+ isLE: n,
1226
+ BITS: f,
1227
+ BYTES: u,
1228
+ MASK: on(f),
1229
+ ZERO: st,
1230
+ ONE: ot,
1231
+ allowedLengths: o,
1232
+ create: (l) => P(l, t),
1233
+ isValid: (l) => {
1234
+ if (typeof l != "bigint")
1235
+ throw new Error("invalid field element: expected bigint, got " + typeof l);
1236
+ return st <= l && l < t;
1237
+ },
1238
+ is0: (l) => l === st,
1239
+ // is valid and invertible
1240
+ isValidNot0: (l) => !w.is0(l) && w.isValid(l),
1241
+ isOdd: (l) => (l & ot) === ot,
1242
+ neg: (l) => P(-l, t),
1243
+ eql: (l, d) => l === d,
1244
+ sqr: (l) => P(l * l, t),
1245
+ add: (l, d) => P(l + d, t),
1246
+ sub: (l, d) => P(l - d, t),
1247
+ mul: (l, d) => P(l * d, t),
1248
+ pow: (l, d) => po(w, l, d),
1249
+ div: (l, d) => P(l * pn(d, t), t),
1250
+ // Same as above, but doesn't normalize
1251
+ sqrN: (l) => l * l,
1252
+ addN: (l, d) => l + d,
1253
+ subN: (l, d) => l - d,
1254
+ mulN: (l, d) => l * d,
1255
+ inv: (l) => pn(l, t),
1256
+ sqrt: s || ((l) => (a || (a = yo(t)), a(w, l))),
1257
+ toBytes: (l) => n ? fe(l, u) : er(l, u),
1258
+ fromBytes: (l, d = !0) => {
1259
+ if (o) {
1260
+ if (!o.includes(l.length) || l.length > u)
1261
+ throw new Error("Field.fromBytes: expected " + o + " bytes, got " + l.length);
1262
+ const b = new Uint8Array(u);
1263
+ b.set(l, n ? 0 : b.length - l.length), l = b;
1264
+ }
1265
+ if (l.length !== u)
1266
+ throw new Error("Field.fromBytes: expected " + u + " bytes, got " + l.length);
1267
+ let p = n ? ce(l) : fo(l);
1268
+ if (c && (p = P(p, t)), !d && !w.isValid(p))
1269
+ throw new Error("invalid field element: outside of range 0..ORDER");
1270
+ return p;
1271
+ },
1272
+ // TODO: we don't need it here, move out to separate fn
1273
+ invertBatch: (l) => ar(w, l),
1274
+ // We can't move this out because Fp6, Fp12 implement it
1275
+ // and it's unclear what to return in there.
1276
+ cmov: (l, d, p) => p ? d : l
1277
+ });
1278
+ return Object.freeze(w);
1279
+ }
1280
+ const ye = BigInt(0), Ce = BigInt(1);
1281
+ function Bn(t, e) {
1282
+ const n = e.negate();
1283
+ return t ? n : e;
1284
+ }
1285
+ function he(t, e) {
1286
+ const n = ar(t.Fp, e.map((r) => r.Z));
1287
+ return e.map((r, i) => t.fromAffine(r.toAffine(n[i])));
1288
+ }
1289
+ function lr(t, e) {
1290
+ if (!Number.isSafeInteger(t) || t <= 0 || t > e)
1291
+ throw new Error("invalid window size, expected [1.." + e + "], got W=" + t);
1292
+ }
1293
+ function Oe(t, e) {
1294
+ lr(t, e);
1295
+ const n = Math.ceil(e / t) + 1, r = 2 ** (t - 1), i = 2 ** t, s = on(t), c = BigInt(t);
1296
+ return { windows: n, windowSize: r, mask: s, maxNumber: i, shiftBy: c };
1297
+ }
1298
+ function _n(t, e, n) {
1299
+ const { windowSize: r, mask: i, maxNumber: s, shiftBy: c } = n;
1300
+ let o = Number(t & i), f = t >> c;
1301
+ o > r && (o -= s, f += Ce);
1302
+ const u = e * r, a = u + Math.abs(o) - 1, w = o === 0, l = o < 0, d = e % 2 !== 0;
1303
+ return { nextN: f, offset: a, isZero: w, isNeg: l, isNegF: d, offsetF: u };
1304
+ }
1305
+ function Bo(t, e) {
1306
+ if (!Array.isArray(t))
1307
+ throw new Error("array expected");
1308
+ t.forEach((n, r) => {
1309
+ if (!(n instanceof e))
1310
+ throw new Error("invalid point at index " + r);
1311
+ });
1312
+ }
1313
+ function _o(t, e) {
1314
+ if (!Array.isArray(t))
1315
+ throw new Error("array of scalars expected");
1316
+ t.forEach((n, r) => {
1317
+ if (!e.isValid(n))
1318
+ throw new Error("invalid scalar at index " + r);
1319
+ });
1320
+ }
1321
+ const qe = /* @__PURE__ */ new WeakMap(), ur = /* @__PURE__ */ new WeakMap();
1322
+ function Re(t) {
1323
+ return ur.get(t) || 1;
1324
+ }
1325
+ function vn(t) {
1326
+ if (t !== ye)
1327
+ throw new Error("invalid wNAF");
1328
+ }
1329
+ let vo = class {
1330
+ // Parametrized with a given Point class (not individual point)
1331
+ constructor(e, n) {
1332
+ this.BASE = e.BASE, this.ZERO = e.ZERO, this.Fn = e.Fn, this.bits = n;
1333
+ }
1334
+ // non-const time multiplication ladder
1335
+ _unsafeLadder(e, n, r = this.ZERO) {
1336
+ let i = e;
1337
+ for (; n > ye; )
1338
+ n & Ce && (r = r.add(i)), i = i.double(), n >>= Ce;
1339
+ return r;
1340
+ }
1341
+ /**
1342
+ * Creates a wNAF precomputation window. Used for caching.
1343
+ * Default window size is set by `utils.precompute()` and is equal to 8.
1344
+ * Number of precomputed points depends on the curve size:
1345
+ * 2^(𝑊−1) * (Math.ceil(𝑛 / 𝑊) + 1), where:
1346
+ * - 𝑊 is the window size
1347
+ * - 𝑛 is the bitlength of the curve order.
1348
+ * For a 256-bit curve and window size 8, the number of precomputed points is 128 * 33 = 4224.
1349
+ * @param point Point instance
1350
+ * @param W window size
1351
+ * @returns precomputed point tables flattened to a single array
1352
+ */
1353
+ precomputeWindow(e, n) {
1354
+ const { windows: r, windowSize: i } = Oe(n, this.bits), s = [];
1355
+ let c = e, o = c;
1356
+ for (let f = 0; f < r; f++) {
1357
+ o = c, s.push(o);
1358
+ for (let u = 1; u < i; u++)
1359
+ o = o.add(c), s.push(o);
1360
+ c = o.double();
1361
+ }
1362
+ return s;
1363
+ }
1364
+ /**
1365
+ * Implements ec multiplication using precomputed tables and w-ary non-adjacent form.
1366
+ * More compact implementation:
1367
+ * https://github.com/paulmillr/noble-secp256k1/blob/47cb1669b6e506ad66b35fe7d76132ae97465da2/index.ts#L502-L541
1368
+ * @returns real and fake (for const-time) points
1369
+ */
1370
+ wNAF(e, n, r) {
1371
+ if (!this.Fn.isValid(r))
1372
+ throw new Error("invalid scalar");
1373
+ let i = this.ZERO, s = this.BASE;
1374
+ const c = Oe(e, this.bits);
1375
+ for (let o = 0; o < c.windows; o++) {
1376
+ const { nextN: f, offset: u, isZero: a, isNeg: w, isNegF: l, offsetF: d } = _n(r, o, c);
1377
+ r = f, a ? s = s.add(Bn(l, n[d])) : i = i.add(Bn(w, n[u]));
1378
+ }
1379
+ return vn(r), { p: i, f: s };
1380
+ }
1381
+ /**
1382
+ * Implements ec unsafe (non const-time) multiplication using precomputed tables and w-ary non-adjacent form.
1383
+ * @param acc accumulator point to add result of multiplication
1384
+ * @returns point
1385
+ */
1386
+ wNAFUnsafe(e, n, r, i = this.ZERO) {
1387
+ const s = Oe(e, this.bits);
1388
+ for (let c = 0; c < s.windows && r !== ye; c++) {
1389
+ const { nextN: o, offset: f, isZero: u, isNeg: a } = _n(r, c, s);
1390
+ if (r = o, !u) {
1391
+ const w = n[f];
1392
+ i = i.add(a ? w.negate() : w);
1393
+ }
1394
+ }
1395
+ return vn(r), i;
1396
+ }
1397
+ getPrecomputes(e, n, r) {
1398
+ let i = qe.get(n);
1399
+ return i || (i = this.precomputeWindow(n, e), e !== 1 && (typeof r == "function" && (i = r(i)), qe.set(n, i))), i;
1400
+ }
1401
+ cached(e, n, r) {
1402
+ const i = Re(e);
1403
+ return this.wNAF(i, this.getPrecomputes(i, e, r), n);
1404
+ }
1405
+ unsafe(e, n, r, i) {
1406
+ const s = Re(e);
1407
+ return s === 1 ? this._unsafeLadder(e, n, i) : this.wNAFUnsafe(s, this.getPrecomputes(s, e, r), n, i);
1408
+ }
1409
+ // We calculate precomputes for elliptic curve point multiplication
1410
+ // using windowed method. This specifies window size and
1411
+ // stores precomputed values. Usually only base point would be precomputed.
1412
+ createCache(e, n) {
1413
+ lr(n, this.bits), ur.set(e, n), qe.delete(e);
1414
+ }
1415
+ hasCache(e) {
1416
+ return Re(e) !== 1;
1417
+ }
1418
+ };
1419
+ function dr(t, e, n, r) {
1420
+ Bo(n, t), _o(r, e);
1421
+ const i = n.length, s = r.length;
1422
+ if (i !== s)
1423
+ throw new Error("arrays of points and scalars must have equal length");
1424
+ const c = t.ZERO, o = uo(BigInt(i));
1425
+ let f = 1;
1426
+ o > 12 ? f = o - 3 : o > 4 ? f = o - 2 : o > 0 && (f = 2);
1427
+ const u = on(f), a = new Array(Number(u) + 1).fill(c), w = Math.floor((e.BITS - 1) / f) * f;
1428
+ let l = c;
1429
+ for (let d = w; d >= 0; d -= f) {
1430
+ a.fill(c);
1431
+ for (let b = 0; b < s; b++) {
1432
+ const h = r[b], x = Number(h >> BigInt(d) & u);
1433
+ a[x] = a[x].add(n[b]);
1434
+ }
1435
+ let p = c;
1436
+ for (let b = a.length - 1, h = c; b > 0; b--)
1437
+ h = h.add(a[b]), p = p.add(h);
1438
+ if (l = l.add(p), d !== 0)
1439
+ for (let b = 0; b < f; b++)
1440
+ l = l.double();
1441
+ }
1442
+ return l;
1443
+ }
1444
+ function Sn(t, e) {
1445
+ if (e) {
1446
+ if (e.ORDER !== t)
1447
+ throw new Error("Field.ORDER must match order: Fp == p, Fn == n");
1448
+ return xo(e), e;
1449
+ } else
1450
+ return Jt(t);
1451
+ }
1452
+ function So(t, e, n = {}) {
1453
+ if (!e || typeof e != "object")
1454
+ throw new Error(`expected valid ${t} CURVE object`);
1455
+ for (const o of ["p", "n", "h"]) {
1456
+ const f = e[o];
1457
+ if (!(typeof f == "bigint" && f > ye))
1458
+ throw new Error(`CURVE.${o} must be positive bigint`);
1459
+ }
1460
+ const r = Sn(e.p, n.Fp), i = Sn(e.n, n.Fn), c = ["Gx", "Gy", "a", "d"];
1461
+ for (const o of c)
1462
+ if (!r.isValid(e[o]))
1463
+ throw new Error(`CURVE.${o} must be valid field element of CURVE.Fp`);
1464
+ return { Fp: r, Fn: i };
1465
+ }
1466
+ const bt = BigInt(0), X = BigInt(1), Le = BigInt(2), Ao = BigInt(8);
1467
+ function Io(t, e, n, r) {
1468
+ const i = t.sqr(n), s = t.sqr(r), c = t.add(t.mul(e.a, i), s), o = t.add(t.ONE, t.mul(e.d, t.mul(i, s)));
1469
+ return t.eql(c, o);
1470
+ }
1471
+ function Oo(t, e = {}) {
1472
+ const { Fp: n, Fn: r } = So("edwards", t, e), { h: i, n: s } = t;
1473
+ sn(e, {}, { uvRatio: "function" });
1474
+ const c = Le << BigInt(r.BYTES * 8) - X, o = (b) => n.create(b), f = e.uvRatio || ((b, h) => {
1475
+ try {
1476
+ return { isValid: !0, value: n.sqrt(n.div(b, h)) };
1477
+ } catch {
1478
+ return { isValid: !1, value: bt };
1479
+ }
1480
+ });
1481
+ if (!Io(n, t, t.Gx, t.Gy))
1482
+ throw new Error("bad curve params: generator point");
1483
+ function u(b, h, x = !1) {
1484
+ const v = x ? X : bt;
1485
+ return re("coordinate " + b, h, v, c), h;
1486
+ }
1487
+ function a(b) {
1488
+ if (!(b instanceof d))
1489
+ throw new Error("ExtendedPoint expected");
1490
+ }
1491
+ const w = xn((b, h) => {
1492
+ const { X: x, Y: v, Z: A } = b, L = b.is0();
1493
+ h == null && (h = L ? Ao : n.inv(A));
1494
+ const B = o(x * h), R = o(v * h), N = n.mul(A, h);
1495
+ if (L)
1496
+ return { x: bt, y: X };
1497
+ if (N !== X)
1498
+ throw new Error("invZ was invalid");
1499
+ return { x: B, y: R };
1500
+ }), l = xn((b) => {
1501
+ const { a: h, d: x } = t;
1502
+ if (b.is0())
1503
+ throw new Error("bad point: ZERO");
1504
+ const { X: v, Y: A, Z: L, T: B } = b, R = o(v * v), N = o(A * A), q = o(L * L), g = o(q * q), _ = o(R * h), m = o(q * o(_ + N)), y = o(g + o(x * o(R * N)));
1505
+ if (m !== y)
1506
+ throw new Error("bad point: equation left != right (1)");
1507
+ const E = o(v * A), S = o(L * B);
1508
+ if (E !== S)
1509
+ throw new Error("bad point: equation left != right (2)");
1510
+ return !0;
1511
+ });
1512
+ class d {
1513
+ constructor(h, x, v, A) {
1514
+ this.X = u("x", h), this.Y = u("y", x), this.Z = u("z", v, !0), this.T = u("t", A), Object.freeze(this);
1515
+ }
1516
+ get x() {
1517
+ return this.toAffine().x;
1518
+ }
1519
+ get y() {
1520
+ return this.toAffine().y;
1521
+ }
1522
+ // TODO: remove
1523
+ get ex() {
1524
+ return this.X;
1525
+ }
1526
+ get ey() {
1527
+ return this.Y;
1528
+ }
1529
+ get ez() {
1530
+ return this.Z;
1531
+ }
1532
+ get et() {
1533
+ return this.T;
1534
+ }
1535
+ static normalizeZ(h) {
1536
+ return he(d, h);
1537
+ }
1538
+ static msm(h, x) {
1539
+ return dr(d, r, h, x);
1540
+ }
1541
+ _setWindowSize(h) {
1542
+ this.precompute(h);
1543
+ }
1544
+ static fromAffine(h) {
1545
+ if (h instanceof d)
1546
+ throw new Error("extended point not allowed");
1547
+ const { x, y: v } = h || {};
1548
+ return u("x", x), u("y", v), new d(x, v, X, o(x * v));
1549
+ }
1550
+ precompute(h = 8, x = !0) {
1551
+ return p.createCache(this, h), x || this.multiply(Le), this;
1552
+ }
1553
+ // Useful in fromAffine() - not for fromBytes(), which always created valid points.
1554
+ assertValidity() {
1555
+ l(this);
1556
+ }
1557
+ // Compare one point to another.
1558
+ equals(h) {
1559
+ a(h);
1560
+ const { X: x, Y: v, Z: A } = this, { X: L, Y: B, Z: R } = h, N = o(x * R), q = o(L * A), g = o(v * R), _ = o(B * A);
1561
+ return N === q && g === _;
1562
+ }
1563
+ is0() {
1564
+ return this.equals(d.ZERO);
1565
+ }
1566
+ negate() {
1567
+ return new d(o(-this.X), this.Y, this.Z, o(-this.T));
1568
+ }
1569
+ // Fast algo for doubling Extended Point.
1570
+ // https://hyperelliptic.org/EFD/g1p/auto-twisted-extended.html#doubling-dbl-2008-hwcd
1571
+ // Cost: 4M + 4S + 1*a + 6add + 1*2.
1572
+ double() {
1573
+ const { a: h } = t, { X: x, Y: v, Z: A } = this, L = o(x * x), B = o(v * v), R = o(Le * o(A * A)), N = o(h * L), q = x + v, g = o(o(q * q) - L - B), _ = N + B, m = _ - R, y = N - B, E = o(g * m), S = o(_ * y), I = o(g * y), O = o(m * _);
1574
+ return new d(E, S, O, I);
1575
+ }
1576
+ // Fast algo for adding 2 Extended Points.
1577
+ // https://hyperelliptic.org/EFD/g1p/auto-twisted-extended.html#addition-add-2008-hwcd
1578
+ // Cost: 9M + 1*a + 1*d + 7add.
1579
+ add(h) {
1580
+ a(h);
1581
+ const { a: x, d: v } = t, { X: A, Y: L, Z: B, T: R } = this, { X: N, Y: q, Z: g, T: _ } = h, m = o(A * N), y = o(L * q), E = o(R * v * _), S = o(B * g), I = o((A + L) * (N + q) - m - y), O = S - E, H = S + E, k = o(y - x * m), Z = o(I * O), U = o(H * k), T = o(I * k), M = o(O * H);
1582
+ return new d(Z, U, M, T);
1583
+ }
1584
+ subtract(h) {
1585
+ return this.add(h.negate());
1586
+ }
1587
+ // Constant-time multiplication.
1588
+ multiply(h) {
1589
+ const x = h;
1590
+ re("scalar", x, X, s);
1591
+ const { p: v, f: A } = p.cached(this, x, (L) => he(d, L));
1592
+ return he(d, [v, A])[0];
1593
+ }
1594
+ // Non-constant-time multiplication. Uses double-and-add algorithm.
1595
+ // It's faster, but should only be used when you don't care about
1596
+ // an exposed private key e.g. sig verification.
1597
+ // Does NOT allow scalars higher than CURVE.n.
1598
+ // Accepts optional accumulator to merge with multiply (important for sparse scalars)
1599
+ multiplyUnsafe(h, x = d.ZERO) {
1600
+ const v = h;
1601
+ return re("scalar", v, bt, s), v === bt ? d.ZERO : this.is0() || v === X ? this : p.unsafe(this, v, (A) => he(d, A), x);
1602
+ }
1603
+ // Checks if point is of small order.
1604
+ // If you add something to small order point, you will have "dirty"
1605
+ // point with torsion component.
1606
+ // Multiplies point by cofactor and checks if the result is 0.
1607
+ isSmallOrder() {
1608
+ return this.multiplyUnsafe(i).is0();
1609
+ }
1610
+ // Multiplies point by curve order and checks if the result is 0.
1611
+ // Returns `false` is the point is dirty.
1612
+ isTorsionFree() {
1613
+ return p.unsafe(this, s).is0();
1614
+ }
1615
+ // Converts Extended point to default (x, y) coordinates.
1616
+ // Can accept precomputed Z^-1 - for example, from invertBatch.
1617
+ toAffine(h) {
1618
+ return w(this, h);
1619
+ }
1620
+ clearCofactor() {
1621
+ return i === X ? this : this.multiplyUnsafe(i);
1622
+ }
1623
+ static fromBytes(h, x = !1) {
1624
+ return W(h), d.fromHex(h, x);
1625
+ }
1626
+ // Converts hash string or Uint8Array to Point.
1627
+ // Uses algo from RFC8032 5.1.3.
1628
+ static fromHex(h, x = !1) {
1629
+ const { d: v, a: A } = t, L = n.BYTES;
1630
+ h = lt("pointHex", h, L), Me("zip215", x);
1631
+ const B = h.slice(), R = h[L - 1];
1632
+ B[L - 1] = R & -129;
1633
+ const N = ce(B), q = x ? c : n.ORDER;
1634
+ re("pointHex.y", N, bt, q);
1635
+ const g = o(N * N), _ = o(g - X), m = o(v * g - A);
1636
+ let { isValid: y, value: E } = f(_, m);
1637
+ if (!y)
1638
+ throw new Error("Point.fromHex: invalid y coordinate");
1639
+ const S = (E & X) === X, I = (R & 128) !== 0;
1640
+ if (!x && E === bt && I)
1641
+ throw new Error("Point.fromHex: x=0 and x_0=1");
1642
+ return I !== S && (E = o(-E)), d.fromAffine({ x: E, y: N });
1643
+ }
1644
+ toBytes() {
1645
+ const { x: h, y: x } = this.toAffine(), v = fe(x, n.BYTES);
1646
+ return v[v.length - 1] |= h & X ? 128 : 0, v;
1647
+ }
1648
+ /** @deprecated use `toBytes` */
1649
+ toRawBytes() {
1650
+ return this.toBytes();
1651
+ }
1652
+ toHex() {
1653
+ return ht(this.toBytes());
1654
+ }
1655
+ toString() {
1656
+ return `<Point ${this.is0() ? "ZERO" : this.toHex()}>`;
1657
+ }
1658
+ }
1659
+ d.BASE = new d(t.Gx, t.Gy, X, o(t.Gx * t.Gy)), d.ZERO = new d(bt, X, X, bt), d.Fp = n, d.Fn = r;
1660
+ const p = new vo(d, r.BYTES * 8);
1661
+ return d;
1662
+ }
1663
+ class qo {
1664
+ constructor(e) {
1665
+ this.ep = e;
1666
+ }
1667
+ // Static methods that must be implemented by subclasses
1668
+ static fromBytes(e) {
1669
+ throw new Error("fromBytes must be implemented by subclass");
1670
+ }
1671
+ static fromHex(e) {
1672
+ throw new Error("fromHex must be implemented by subclass");
1673
+ }
1674
+ get x() {
1675
+ return this.toAffine().x;
1676
+ }
1677
+ get y() {
1678
+ return this.toAffine().y;
1679
+ }
1680
+ // Common implementations
1681
+ clearCofactor() {
1682
+ return this;
1683
+ }
1684
+ assertValidity() {
1685
+ this.ep.assertValidity();
1686
+ }
1687
+ toAffine(e) {
1688
+ return this.ep.toAffine(e);
1689
+ }
1690
+ /** @deprecated use `toBytes` */
1691
+ toRawBytes() {
1692
+ return this.toBytes();
1693
+ }
1694
+ toHex() {
1695
+ return ht(this.toBytes());
1696
+ }
1697
+ toString() {
1698
+ return this.toHex();
1699
+ }
1700
+ isTorsionFree() {
1701
+ return !0;
1702
+ }
1703
+ isSmallOrder() {
1704
+ return !1;
1705
+ }
1706
+ add(e) {
1707
+ return this.assertSame(e), this.init(this.ep.add(e.ep));
1708
+ }
1709
+ subtract(e) {
1710
+ return this.assertSame(e), this.init(this.ep.subtract(e.ep));
1711
+ }
1712
+ multiply(e) {
1713
+ return this.init(this.ep.multiply(e));
1714
+ }
1715
+ multiplyUnsafe(e) {
1716
+ return this.init(this.ep.multiplyUnsafe(e));
1717
+ }
1718
+ double() {
1719
+ return this.init(this.ep.double());
1720
+ }
1721
+ negate() {
1722
+ return this.init(this.ep.negate());
1723
+ }
1724
+ precompute(e, n) {
1725
+ return this.init(this.ep.precompute(e, n));
1726
+ }
1727
+ }
1728
+ function Ro(t, e, n) {
1729
+ if (typeof e != "function")
1730
+ throw new Error('"hash" function param is required');
1731
+ sn(n, {}, {
1732
+ adjustScalarBytes: "function",
1733
+ randomBytes: "function",
1734
+ domain: "function",
1735
+ prehash: "function",
1736
+ mapToCurve: "function"
1737
+ });
1738
+ const { prehash: r } = n, { BASE: i, Fp: s, Fn: c } = t, o = c.ORDER, f = n.randomBytes || Je, u = n.adjustScalarBytes || ((m) => m), a = n.domain || ((m, y, E) => {
1739
+ if (Me("phflag", E), y.length || E)
1740
+ throw new Error("Contexts/pre-hash are not supported");
1741
+ return m;
1742
+ });
1743
+ function w(m) {
1744
+ return c.create(m);
1745
+ }
1746
+ function l(m) {
1747
+ return w(ce(m));
1748
+ }
1749
+ function d(m) {
1750
+ const y = s.BYTES;
1751
+ m = lt("private key", m, y);
1752
+ const E = lt("hashed private key", e(m), 2 * y), S = u(E.slice(0, y)), I = E.slice(y, 2 * y), O = l(S);
1753
+ return { head: S, prefix: I, scalar: O };
1754
+ }
1755
+ function p(m) {
1756
+ const { head: y, prefix: E, scalar: S } = d(m), I = i.multiply(S), O = I.toBytes();
1757
+ return { head: y, prefix: E, scalar: S, point: I, pointBytes: O };
1758
+ }
1759
+ function b(m) {
1760
+ return p(m).pointBytes;
1761
+ }
1762
+ function h(m = Uint8Array.of(), ...y) {
1763
+ const E = ut(...y);
1764
+ return l(e(a(E, lt("context", m), !!r)));
1765
+ }
1766
+ function x(m, y, E = {}) {
1767
+ m = lt("message", m), r && (m = r(m));
1768
+ const { prefix: S, scalar: I, pointBytes: O } = p(y), H = h(E.context, S, m), k = i.multiply(H).toBytes(), Z = h(E.context, k, O, m), U = w(H + Z * I);
1769
+ re("signature.s", U, bt, o);
1770
+ const T = s.BYTES, M = ut(k, fe(U, T));
1771
+ return lt("result", M, T * 2);
1772
+ }
1773
+ const v = { zip215: !0 };
1774
+ function A(m, y, E, S = v) {
1775
+ const { context: I, zip215: O } = S, H = s.BYTES;
1776
+ m = lt("signature", m, 2 * H), y = lt("message", y), E = lt("publicKey", E, H), O !== void 0 && Me("zip215", O), r && (y = r(y));
1777
+ const k = ce(m.slice(H, 2 * H));
1778
+ let Z, U, T;
1779
+ try {
1780
+ Z = t.fromHex(E, O), U = t.fromHex(m.slice(0, H), O), T = i.multiplyUnsafe(k);
1781
+ } catch {
1782
+ return !1;
1783
+ }
1784
+ if (!O && Z.isSmallOrder())
1785
+ return !1;
1786
+ const M = h(I, U.toBytes(), Z.toBytes(), y);
1787
+ return U.add(Z.multiplyUnsafe(M)).subtract(T).clearCofactor().is0();
1788
+ }
1789
+ i.precompute(8);
1790
+ const L = s.BYTES, B = {
1791
+ secret: L,
1792
+ public: L,
1793
+ signature: 2 * L,
1794
+ seed: L
1795
+ };
1796
+ function R(m = f(B.seed)) {
1797
+ return m;
1798
+ }
1799
+ const N = {
1800
+ getExtendedPublicKey: p,
1801
+ /** ed25519 priv keys are uniform 32b. No need to check for modulo bias, like in secp256k1. */
1802
+ randomSecretKey: R,
1803
+ isValidSecretKey: g,
1804
+ isValidPublicKey: _,
1805
+ randomPrivateKey: R,
1806
+ /**
1807
+ * Converts ed public key to x public key. Uses formula:
1808
+ * - ed25519:
1809
+ * - `(u, v) = ((1+y)/(1-y), sqrt(-486664)*u/x)`
1810
+ * - `(x, y) = (sqrt(-486664)*u/v, (u-1)/(u+1))`
1811
+ * - ed448:
1812
+ * - `(u, v) = ((y-1)/(y+1), sqrt(156324)*u/x)`
1813
+ * - `(x, y) = (sqrt(156324)*u/v, (1+u)/(1-u))`
1814
+ *
1815
+ * There is NO `fromMontgomery`:
1816
+ * - There are 2 valid ed25519 points for every x25519, with flipped coordinate
1817
+ * - Sometimes there are 0 valid ed25519 points, because x25519 *additionally*
1818
+ * accepts inputs on the quadratic twist, which can't be moved to ed25519
1819
+ */
1820
+ toMontgomery(m) {
1821
+ const { y } = t.fromBytes(m), E = L === 32;
1822
+ if (!E && L !== 57)
1823
+ throw new Error("only defined for 25519 and 448");
1824
+ const S = E ? s.div(X + y, X - y) : s.div(y - X, y + X);
1825
+ return s.toBytes(S);
1826
+ },
1827
+ toMontgomeryPriv(m) {
1828
+ W(m, L);
1829
+ const y = e(m.subarray(0, L));
1830
+ return u(y).subarray(0, L);
1831
+ },
1832
+ /**
1833
+ * We're doing scalar multiplication (used in getPublicKey etc) with precomputed BASE_POINT
1834
+ * values. This slows down first getPublicKey() by milliseconds (see Speed section),
1835
+ * but allows to speed-up subsequent getPublicKey() calls up to 20x.
1836
+ * @param windowSize 2, 4, 8, 16
1837
+ */
1838
+ precompute(m = 8, y = t.BASE) {
1839
+ return y.precompute(m, !1);
1840
+ }
1841
+ };
1842
+ function q(m) {
1843
+ const y = N.randomSecretKey(m);
1844
+ return { secretKey: y, publicKey: b(y) };
1845
+ }
1846
+ function g(m) {
1847
+ try {
1848
+ return !!c.fromBytes(m, !1);
1849
+ } catch {
1850
+ return !1;
1851
+ }
1852
+ }
1853
+ function _(m, y) {
1854
+ try {
1855
+ return !!t.fromBytes(m, y);
1856
+ } catch {
1857
+ return !1;
1858
+ }
1859
+ }
1860
+ return Object.freeze({
1861
+ keygen: q,
1862
+ getPublicKey: b,
1863
+ sign: x,
1864
+ verify: A,
1865
+ utils: N,
1866
+ Point: t,
1867
+ info: { type: "edwards", lengths: B }
1868
+ });
1869
+ }
1870
+ function Lo(t) {
1871
+ const e = {
1872
+ a: t.a,
1873
+ d: t.d,
1874
+ p: t.Fp.ORDER,
1875
+ n: t.n,
1876
+ h: t.h,
1877
+ Gx: t.Gx,
1878
+ Gy: t.Gy
1879
+ }, n = t.Fp, r = Jt(e.n, t.nBitLength, !0), i = { Fp: n, Fn: r, uvRatio: t.uvRatio }, s = {
1880
+ randomBytes: t.randomBytes,
1881
+ adjustScalarBytes: t.adjustScalarBytes,
1882
+ domain: t.domain,
1883
+ prehash: t.prehash,
1884
+ mapToCurve: t.mapToCurve
1885
+ };
1886
+ return { CURVE: e, curveOpts: i, hash: t.hash, eddsaOpts: s };
1887
+ }
1888
+ function No(t, e) {
1889
+ return Object.assign({}, e, { ExtendedPoint: e.Point, CURVE: t });
1890
+ }
1891
+ function $o(t) {
1892
+ const { CURVE: e, curveOpts: n, hash: r, eddsaOpts: i } = Lo(t), s = Oo(e, n), c = Ro(s, r, i);
1893
+ return No(t, c);
1894
+ }
1895
+ const Qs = We("HashToScalar-");
1896
+ const Js = BigInt(0), Fs = BigInt(1), ti = BigInt(2);
1897
+ const Ho = BigInt(0), Et = BigInt(1), An = BigInt(2), ei = BigInt(3), ko = BigInt(5), To = BigInt(8), le = {
1898
+ p: BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),
1899
+ n: BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),
1900
+ h: To,
1901
+ a: BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),
1902
+ d: BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),
1903
+ Gx: BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),
1904
+ Gy: BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")
1905
+ };
1906
+ function Uo(t) {
1907
+ const e = BigInt(10), n = BigInt(20), r = BigInt(40), i = BigInt(80), s = le.p, o = t * t % s * t % s, f = mt(o, An, s) * o % s, u = mt(f, Et, s) * t % s, a = mt(u, ko, s) * u % s, w = mt(a, e, s) * a % s, l = mt(w, n, s) * w % s, d = mt(l, r, s) * l % s, p = mt(d, i, s) * d % s, b = mt(p, i, s) * d % s, h = mt(b, e, s) * a % s;
1908
+ return { pow_p_5_8: mt(h, An, s) * t % s, b2: o };
1909
+ }
1910
+ function Zo(t) {
1911
+ return t[0] &= 248, t[31] &= 127, t[31] |= 64, t;
1912
+ }
1913
+ const ze = /* @__PURE__ */ BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");
1914
+ function fn(t, e) {
1915
+ const n = le.p, r = P(e * e * e, n), i = P(r * r * e, n), s = Uo(t * i).pow_p_5_8;
1916
+ let c = P(t * r * s, n);
1917
+ const o = P(e * c * c, n), f = c, u = P(c * ze, n), a = o === t, w = o === P(-t, n), l = o === P(-t * ze, n);
1918
+ return a && (c = f), (w || l) && (c = u), Nt(c, n) && (c = P(-c, n)), { isValid: a || w, value: c };
1919
+ }
1920
+ const Tt = Jt(le.p, { isLE: !0 }), Do = Jt(le.n, { isLE: !0 }), Mo = {
1921
+ ...le,
1922
+ Fp: Tt,
1923
+ hash: nn,
1924
+ adjustScalarBytes: Zo,
1925
+ // dom2
1926
+ // Ratio of u to v. Allows us to combine inversion and square root. Uses algo from RFC8032 5.1.3.
1927
+ // Constant-time, u/√v
1928
+ uvRatio: fn
1929
+ }, dt = $o(Mo);
1930
+ const je = ze, Co = /* @__PURE__ */ BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"), zo = /* @__PURE__ */ BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"), jo = /* @__PURE__ */ BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"), Vo = /* @__PURE__ */ BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"), In = (t) => fn(Et, t), Yo = /* @__PURE__ */ BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"), Ve = (t) => dt.CURVE.Fp.create(ce(t) & Yo);
1931
+ function On(t) {
1932
+ const { d: e } = dt.CURVE, n = dt.CURVE.Fp.ORDER, r = dt.CURVE.Fp.create, i = r(je * t * t), s = r((i + Et) * jo);
1933
+ let c = BigInt(-1);
1934
+ const o = r((c - e * i) * r(i + e));
1935
+ let { isValid: f, value: u } = fn(s, o), a = r(u * t);
1936
+ Nt(a, n) || (a = r(-a)), f || (u = a), f || (c = i);
1937
+ const w = r(c * (i - Et) * Vo - o), l = u * u, d = r((u + u) * o), p = r(w * Co), b = r(Et - l), h = r(Et + l);
1938
+ return new dt.Point(r(d * h), r(b * p), r(p * h), r(d * b));
1939
+ }
1940
+ function Go(t) {
1941
+ W(t, 64);
1942
+ const e = Ve(t.subarray(0, 32)), n = On(e), r = Ve(t.subarray(32, 64)), i = On(r);
1943
+ return new tt(n.add(i));
1944
+ }
1945
+ class tt extends qo {
1946
+ constructor(e) {
1947
+ super(e);
1948
+ }
1949
+ static fromAffine(e) {
1950
+ return new tt(dt.Point.fromAffine(e));
1951
+ }
1952
+ assertSame(e) {
1953
+ if (!(e instanceof tt))
1954
+ throw new Error("RistrettoPoint expected");
1955
+ }
1956
+ init(e) {
1957
+ return new tt(e);
1958
+ }
1959
+ /** @deprecated use `import { ristretto255_hasher } from '@noble/curves/ed25519.js';` */
1960
+ static hashToCurve(e) {
1961
+ return Go(lt("ristrettoHash", e, 64));
1962
+ }
1963
+ static fromBytes(e) {
1964
+ W(e, 32);
1965
+ const { a: n, d: r } = dt.CURVE, i = Tt.ORDER, s = Tt.create, c = Ve(e);
1966
+ if (!ao(fe(c, 32), e) || Nt(c, i))
1967
+ throw new Error("invalid ristretto255 encoding 1");
1968
+ const o = s(c * c), f = s(Et + n * o), u = s(Et - n * o), a = s(f * f), w = s(u * u), l = s(n * r * a - w), { isValid: d, value: p } = In(s(l * w)), b = s(p * u), h = s(p * b * l);
1969
+ let x = s((c + c) * b);
1970
+ Nt(x, i) && (x = s(-x));
1971
+ const v = s(f * h), A = s(x * v);
1972
+ if (!d || Nt(A, i) || v === Ho)
1973
+ throw new Error("invalid ristretto255 encoding 2");
1974
+ return new tt(new dt.Point(x, v, Et, A));
1975
+ }
1976
+ /**
1977
+ * Converts ristretto-encoded string to ristretto point.
1978
+ * Described in [RFC9496](https://www.rfc-editor.org/rfc/rfc9496#name-decode).
1979
+ * @param hex Ristretto-encoded 32 bytes. Not every 32-byte string is valid ristretto encoding
1980
+ */
1981
+ static fromHex(e) {
1982
+ return tt.fromBytes(lt("ristrettoHex", e, 32));
1983
+ }
1984
+ static msm(e, n) {
1985
+ return dr(tt, dt.Point.Fn, e, n);
1986
+ }
1987
+ /**
1988
+ * Encodes ristretto point to Uint8Array.
1989
+ * Described in [RFC9496](https://www.rfc-editor.org/rfc/rfc9496#name-encode).
1990
+ */
1991
+ toBytes() {
1992
+ let { X: e, Y: n, Z: r, T: i } = this.ep;
1993
+ const s = Tt.ORDER, c = Tt.create, o = c(c(r + n) * c(r - n)), f = c(e * n), u = c(f * f), { value: a } = In(c(o * u)), w = c(a * o), l = c(a * f), d = c(w * l * i);
1994
+ let p;
1995
+ if (Nt(i * d, s)) {
1996
+ let h = c(n * je), x = c(e * je);
1997
+ e = h, n = x, p = c(w * zo);
1998
+ } else
1999
+ p = l;
2000
+ Nt(e * d, s) && (n = c(-n));
2001
+ let b = c((r - n) * p);
2002
+ return Nt(b, s) && (b = c(-b)), fe(b, 32);
2003
+ }
2004
+ /**
2005
+ * Compares two Ristretto points.
2006
+ * Described in [RFC9496](https://www.rfc-editor.org/rfc/rfc9496#name-equals).
2007
+ */
2008
+ equals(e) {
2009
+ this.assertSame(e);
2010
+ const { X: n, Y: r } = this.ep, { X: i, Y: s } = e.ep, c = Tt.create, o = c(n * s) === c(r * i), f = c(r * s) === c(n * i);
2011
+ return o || f;
2012
+ }
2013
+ is0() {
2014
+ return this.equals(tt.ZERO);
2015
+ }
2016
+ }
2017
+ tt.BASE = new tt(dt.Point.BASE);
2018
+ tt.ZERO = new tt(dt.Point.ZERO);
2019
+ tt.Fp = Tt;
2020
+ tt.Fn = Do;
2021
+ const ni = tt, Xo = BigInt(0), te = BigInt(1), Ko = BigInt(2), Po = BigInt(7), Wo = BigInt(256), Qo = BigInt(113), hr = [], wr = [], mr = [];
2022
+ for (let t = 0, e = te, n = 1, r = 0; t < 24; t++) {
2023
+ [n, r] = [r, (2 * n + 3 * r) % 5], hr.push(2 * (5 * r + n)), wr.push((t + 1) * (t + 2) / 2 % 64);
2024
+ let i = Xo;
2025
+ for (let s = 0; s < 7; s++)
2026
+ e = (e << te ^ (e >> Po) * Qo) % Wo, e & Ko && (i ^= te << (te << /* @__PURE__ */ BigInt(s)) - te);
2027
+ mr.push(i);
2028
+ }
2029
+ const br = Wn(mr, !0), Jo = br[0], Fo = br[1], qn = (t, e, n) => n > 32 ? jr(t, e, n) : Cr(t, e, n), Rn = (t, e, n) => n > 32 ? Vr(t, e, n) : zr(t, e, n);
2030
+ function ri(t, e = 24) {
2031
+ const n = new Uint32Array(10);
2032
+ for (let r = 24 - e; r < 24; r++) {
2033
+ for (let c = 0; c < 10; c++)
2034
+ n[c] = t[c] ^ t[c + 10] ^ t[c + 20] ^ t[c + 30] ^ t[c + 40];
2035
+ for (let c = 0; c < 10; c += 2) {
2036
+ const o = (c + 8) % 10, f = (c + 2) % 10, u = n[f], a = n[f + 1], w = qn(u, a, 1) ^ n[o], l = Rn(u, a, 1) ^ n[o + 1];
2037
+ for (let d = 0; d < 50; d += 10)
2038
+ t[c + d] ^= w, t[c + d + 1] ^= l;
2039
+ }
2040
+ let i = t[2], s = t[3];
2041
+ for (let c = 0; c < 24; c++) {
2042
+ const o = wr[c], f = qn(i, s, o), u = Rn(i, s, o), a = hr[c];
2043
+ i = t[a], s = t[a + 1], t[a] = f, t[a + 1] = u;
2044
+ }
2045
+ for (let c = 0; c < 50; c += 10) {
2046
+ for (let o = 0; o < 10; o++)
2047
+ n[o] = t[c + o];
2048
+ for (let o = 0; o < 10; o++)
2049
+ t[c + o] ^= ~n[(o + 2) % 10] & n[(o + 4) % 10];
2050
+ }
2051
+ t[0] ^= Jo[r], t[1] ^= Fo[r];
2052
+ }
2053
+ ft(n);
2054
+ }
2055
+ const oi = nn, si = Ee;
2056
+ const an = /* @__PURE__ */ BigInt(0), Ye = /* @__PURE__ */ BigInt(1);
2057
+ function Ct(t, e) {
2058
+ if (typeof e != "boolean")
2059
+ throw new Error(t + " boolean expected, got " + e);
2060
+ }
2061
+ function we(t) {
2062
+ const e = t.toString(16);
2063
+ return e.length & 1 ? "0" + e : e;
2064
+ }
2065
+ function yr(t) {
2066
+ if (typeof t != "string")
2067
+ throw new Error("hex string expected, got " + typeof t);
2068
+ return t === "" ? an : BigInt("0x" + t);
2069
+ }
2070
+ function Be(t) {
2071
+ return yr(ht(t));
2072
+ }
2073
+ function Pt(t) {
2074
+ return W(t), yr(ht(Uint8Array.from(t).reverse()));
2075
+ }
2076
+ function ln(t, e) {
2077
+ return ae(t.toString(16).padStart(e * 2, "0"));
2078
+ }
2079
+ function Wt(t, e) {
2080
+ return ln(t, e).reverse();
2081
+ }
2082
+ function z(t, e, n) {
2083
+ let r;
2084
+ if (typeof e == "string")
2085
+ try {
2086
+ r = ae(e);
2087
+ } catch (s) {
2088
+ throw new Error(t + " must be hex string or Uint8Array, cause: " + s);
2089
+ }
2090
+ else if (pe(e))
2091
+ r = Uint8Array.from(e);
2092
+ else
2093
+ throw new Error(t + " must be hex string or Uint8Array");
2094
+ const i = r.length;
2095
+ if (typeof n == "number" && i !== n)
2096
+ throw new Error(t + " of length " + n + " expected, got " + i);
2097
+ return r;
2098
+ }
2099
+ function ts(t, e) {
2100
+ if (t.length !== e.length)
2101
+ return !1;
2102
+ let n = 0;
2103
+ for (let r = 0; r < t.length; r++)
2104
+ n |= t[r] ^ e[r];
2105
+ return n === 0;
2106
+ }
2107
+ const Ne = (t) => typeof t == "bigint" && an <= t;
2108
+ function es(t, e, n) {
2109
+ return Ne(t) && Ne(e) && Ne(n) && e <= t && t < n;
2110
+ }
2111
+ function Xt(t, e, n, r) {
2112
+ if (!es(e, n, r))
2113
+ throw new Error("expected valid " + t + ": " + n + " <= n < " + r + ", got " + e);
2114
+ }
2115
+ function ns(t) {
2116
+ let e;
2117
+ for (e = 0; t > an; t >>= Ye, e += 1)
2118
+ ;
2119
+ return e;
2120
+ }
2121
+ const _e = (t) => (Ye << BigInt(t)) - Ye;
2122
+ function rs(t, e, n) {
2123
+ if (typeof t != "number" || t < 2)
2124
+ throw new Error("hashLen must be a number");
2125
+ if (typeof e != "number" || e < 2)
2126
+ throw new Error("qByteLen must be a number");
2127
+ if (typeof n != "function")
2128
+ throw new Error("hmacFn must be a function");
2129
+ const r = (d) => new Uint8Array(d), i = (d) => Uint8Array.of(d);
2130
+ let s = r(t), c = r(t), o = 0;
2131
+ const f = () => {
2132
+ s.fill(1), c.fill(0), o = 0;
2133
+ }, u = (...d) => n(c, s, ...d), a = (d = r(0)) => {
2134
+ c = u(i(0), d), s = u(), d.length !== 0 && (c = u(i(1), d), s = u());
2135
+ }, w = () => {
2136
+ if (o++ >= 1e3)
2137
+ throw new Error("drbg: tried 1000 values");
2138
+ let d = 0;
2139
+ const p = [];
2140
+ for (; d < e; ) {
2141
+ s = u();
2142
+ const b = s.slice();
2143
+ p.push(b), d += s.length;
2144
+ }
2145
+ return ut(...p);
2146
+ };
2147
+ return (d, p) => {
2148
+ f(), a(d);
2149
+ let b;
2150
+ for (; !(b = p(w())); )
2151
+ a();
2152
+ return f(), b;
2153
+ };
2154
+ }
2155
+ function ue(t, e, n = {}) {
2156
+ if (!t || typeof t != "object")
2157
+ throw new Error("expected valid options object");
2158
+ function r(i, s, c) {
2159
+ const o = t[i];
2160
+ if (c && o === void 0)
2161
+ return;
2162
+ const f = typeof o;
2163
+ if (f !== s || o === null)
2164
+ throw new Error(`param "${i}" is invalid: expected ${s}, got ${f}`);
2165
+ }
2166
+ Object.entries(e).forEach(([i, s]) => r(i, s, !1)), Object.entries(n).forEach(([i, s]) => r(i, s, !0));
2167
+ }
2168
+ function ge(t) {
2169
+ const e = /* @__PURE__ */ new WeakMap();
2170
+ return (n, ...r) => {
2171
+ const i = e.get(n);
2172
+ if (i !== void 0)
2173
+ return i;
2174
+ const s = t(n, ...r);
2175
+ return e.set(n, s), s;
2176
+ };
2177
+ }
2178
+ const it = BigInt(0), J = BigInt(1), Zt = /* @__PURE__ */ BigInt(2), os = /* @__PURE__ */ BigInt(3), gr = /* @__PURE__ */ BigInt(4), xr = /* @__PURE__ */ BigInt(5), pr = /* @__PURE__ */ BigInt(8);
2179
+ function V(t, e) {
2180
+ const n = t % e;
2181
+ return n >= it ? n : e + n;
2182
+ }
2183
+ function j(t, e, n) {
2184
+ let r = t;
2185
+ for (; e-- > it; )
2186
+ r *= r, r %= n;
2187
+ return r;
2188
+ }
2189
+ function Ln(t, e) {
2190
+ if (t === it)
2191
+ throw new Error("invert: expected non-zero number");
2192
+ if (e <= it)
2193
+ throw new Error("invert: expected positive modulus, got " + e);
2194
+ let n = V(t, e), r = e, i = it, s = J;
2195
+ for (; n !== it; ) {
2196
+ const o = r / n, f = r % n, u = i - s * o;
2197
+ r = n, n = f, i = s, s = u;
2198
+ }
2199
+ if (r !== J)
2200
+ throw new Error("invert: does not exist");
2201
+ return V(i, e);
2202
+ }
2203
+ function Er(t, e) {
2204
+ const n = (t.ORDER + J) / gr, r = t.pow(e, n);
2205
+ if (!t.eql(t.sqr(r), e))
2206
+ throw new Error("Cannot find square root");
2207
+ return r;
2208
+ }
2209
+ function ss(t, e) {
2210
+ const n = (t.ORDER - xr) / pr, r = t.mul(e, Zt), i = t.pow(r, n), s = t.mul(e, i), c = t.mul(t.mul(s, Zt), i), o = t.mul(s, t.sub(c, t.ONE));
2211
+ if (!t.eql(t.sqr(o), e))
2212
+ throw new Error("Cannot find square root");
2213
+ return o;
2214
+ }
2215
+ function is(t) {
2216
+ if (t < BigInt(3))
2217
+ throw new Error("sqrt is not defined for small field");
2218
+ let e = t - J, n = 0;
2219
+ for (; e % Zt === it; )
2220
+ e /= Zt, n++;
2221
+ let r = Zt;
2222
+ const i = zt(t);
2223
+ for (; Nn(i, r) === 1; )
2224
+ if (r++ > 1e3)
2225
+ throw new Error("Cannot find square root: probably non-prime P");
2226
+ if (n === 1)
2227
+ return Er;
2228
+ let s = i.pow(r, e);
2229
+ const c = (e + J) / Zt;
2230
+ return function(f, u) {
2231
+ if (f.is0(u))
2232
+ return u;
2233
+ if (Nn(f, u) !== 1)
2234
+ throw new Error("Cannot find square root");
2235
+ let a = n, w = f.mul(f.ONE, s), l = f.pow(u, e), d = f.pow(u, c);
2236
+ for (; !f.eql(l, f.ONE); ) {
2237
+ if (f.is0(l))
2238
+ return f.ZERO;
2239
+ let p = 1, b = f.sqr(l);
2240
+ for (; !f.eql(b, f.ONE); )
2241
+ if (p++, b = f.sqr(b), p === a)
2242
+ throw new Error("Cannot find square root");
2243
+ const h = J << BigInt(a - p - 1), x = f.pow(w, h);
2244
+ a = p, w = f.sqr(x), l = f.mul(l, w), d = f.mul(d, x);
2245
+ }
2246
+ return d;
2247
+ };
2248
+ }
2249
+ function cs(t) {
2250
+ return t % gr === os ? Er : t % pr === xr ? ss : is(t);
2251
+ }
2252
+ const $t = (t, e) => (V(t, e) & J) === J, fs = [
2253
+ "create",
2254
+ "isValid",
2255
+ "is0",
2256
+ "neg",
2257
+ "inv",
2258
+ "sqrt",
2259
+ "sqr",
2260
+ "eql",
2261
+ "add",
2262
+ "sub",
2263
+ "mul",
2264
+ "pow",
2265
+ "div",
2266
+ "addN",
2267
+ "subN",
2268
+ "mulN",
2269
+ "sqrN"
2270
+ ];
2271
+ function as(t) {
2272
+ const e = {
2273
+ ORDER: "bigint",
2274
+ MASK: "bigint",
2275
+ BYTES: "number",
2276
+ BITS: "number"
2277
+ }, n = fs.reduce((r, i) => (r[i] = "function", r), e);
2278
+ return ue(t, n), t;
2279
+ }
2280
+ function ls(t, e, n) {
2281
+ if (n < it)
2282
+ throw new Error("invalid exponent, negatives unsupported");
2283
+ if (n === it)
2284
+ return t.ONE;
2285
+ if (n === J)
2286
+ return e;
2287
+ let r = t.ONE, i = e;
2288
+ for (; n > it; )
2289
+ n & J && (r = t.mul(r, i)), i = t.sqr(i), n >>= J;
2290
+ return r;
2291
+ }
2292
+ function Br(t, e, n = !1) {
2293
+ const r = new Array(e.length).fill(n ? t.ZERO : void 0), i = e.reduce((c, o, f) => t.is0(o) ? c : (r[f] = c, t.mul(c, o)), t.ONE), s = t.inv(i);
2294
+ return e.reduceRight((c, o, f) => t.is0(o) ? c : (r[f] = t.mul(c, r[f]), t.mul(c, o)), s), r;
2295
+ }
2296
+ function Nn(t, e) {
2297
+ const n = (t.ORDER - J) / Zt, r = t.pow(e, n), i = t.eql(r, t.ONE), s = t.eql(r, t.ZERO), c = t.eql(r, t.neg(t.ONE));
2298
+ if (!i && !s && !c)
2299
+ throw new Error("invalid Legendre symbol result");
2300
+ return i ? 1 : s ? 0 : -1;
2301
+ }
2302
+ function us(t, e) {
2303
+ e !== void 0 && et(e);
2304
+ const n = e !== void 0 ? e : t.toString(2).length, r = Math.ceil(n / 8);
2305
+ return { nBitLength: n, nByteLength: r };
2306
+ }
2307
+ function zt(t, e, n = !1, r = {}) {
2308
+ if (t <= it)
2309
+ throw new Error("invalid field: expected ORDER > 0, got " + t);
2310
+ let i, s;
2311
+ if (typeof e == "object" && e != null) {
2312
+ if (r.sqrt || n)
2313
+ throw new Error("cannot specify opts in two arguments");
2314
+ const a = e;
2315
+ a.BITS && (i = a.BITS), a.sqrt && (s = a.sqrt), typeof a.isLE == "boolean" && (n = a.isLE);
2316
+ } else
2317
+ typeof e == "number" && (i = e), r.sqrt && (s = r.sqrt);
2318
+ const { nBitLength: c, nByteLength: o } = us(t, i);
2319
+ if (o > 2048)
2320
+ throw new Error("invalid field: expected ORDER of <= 2048 bytes");
2321
+ let f;
2322
+ const u = Object.freeze({
2323
+ ORDER: t,
2324
+ isLE: n,
2325
+ BITS: c,
2326
+ BYTES: o,
2327
+ MASK: _e(c),
2328
+ ZERO: it,
2329
+ ONE: J,
2330
+ create: (a) => V(a, t),
2331
+ isValid: (a) => {
2332
+ if (typeof a != "bigint")
2333
+ throw new Error("invalid field element: expected bigint, got " + typeof a);
2334
+ return it <= a && a < t;
2335
+ },
2336
+ is0: (a) => a === it,
2337
+ // is valid and invertible
2338
+ isValidNot0: (a) => !u.is0(a) && u.isValid(a),
2339
+ isOdd: (a) => (a & J) === J,
2340
+ neg: (a) => V(-a, t),
2341
+ eql: (a, w) => a === w,
2342
+ sqr: (a) => V(a * a, t),
2343
+ add: (a, w) => V(a + w, t),
2344
+ sub: (a, w) => V(a - w, t),
2345
+ mul: (a, w) => V(a * w, t),
2346
+ pow: (a, w) => ls(u, a, w),
2347
+ div: (a, w) => V(a * Ln(w, t), t),
2348
+ // Same as above, but doesn't normalize
2349
+ sqrN: (a) => a * a,
2350
+ addN: (a, w) => a + w,
2351
+ subN: (a, w) => a - w,
2352
+ mulN: (a, w) => a * w,
2353
+ inv: (a) => Ln(a, t),
2354
+ sqrt: s || ((a) => (f || (f = cs(t)), f(u, a))),
2355
+ toBytes: (a) => n ? Wt(a, o) : ln(a, o),
2356
+ fromBytes: (a) => {
2357
+ if (a.length !== o)
2358
+ throw new Error("Field.fromBytes: expected " + o + " bytes, got " + a.length);
2359
+ return n ? Pt(a) : Be(a);
2360
+ },
2361
+ // TODO: we don't need it here, move out to separate fn
2362
+ invertBatch: (a) => Br(u, a),
2363
+ // We can't move this out because Fp6, Fp12 implement it
2364
+ // and it's unclear what to return in there.
2365
+ cmov: (a, w, l) => l ? w : a
2366
+ });
2367
+ return Object.freeze(u);
2368
+ }
2369
+ function _r(t) {
2370
+ if (typeof t != "bigint")
2371
+ throw new Error("field order must be bigint");
2372
+ const e = t.toString(2).length;
2373
+ return Math.ceil(e / 8);
2374
+ }
2375
+ function vr(t) {
2376
+ const e = _r(t);
2377
+ return e + Math.ceil(e / 2);
2378
+ }
2379
+ function ds(t, e, n = !1) {
2380
+ const r = t.length, i = _r(e), s = vr(e);
2381
+ if (r < 16 || r < s || r > 1024)
2382
+ throw new Error("expected " + s + "-1024 bytes of input, got " + r);
2383
+ const c = n ? Pt(t) : Be(t), o = V(c, e - J) + J;
2384
+ return n ? Wt(o, i) : ln(o, i);
2385
+ }
2386
+ const Qt = BigInt(0), Dt = BigInt(1);
2387
+ function oe(t, e) {
2388
+ const n = e.negate();
2389
+ return t ? n : e;
2390
+ }
2391
+ function Sr(t, e, n) {
2392
+ const r = e === "pz" ? (c) => c.pz : (c) => c.ez, i = Br(t.Fp, n.map(r));
2393
+ return n.map((c, o) => c.toAffine(i[o])).map(t.fromAffine);
2394
+ }
2395
+ function Ar(t, e) {
2396
+ if (!Number.isSafeInteger(t) || t <= 0 || t > e)
2397
+ throw new Error("invalid window size, expected [1.." + e + "], got W=" + t);
2398
+ }
2399
+ function $e(t, e) {
2400
+ Ar(t, e);
2401
+ const n = Math.ceil(e / t) + 1, r = 2 ** (t - 1), i = 2 ** t, s = _e(t), c = BigInt(t);
2402
+ return { windows: n, windowSize: r, mask: s, maxNumber: i, shiftBy: c };
2403
+ }
2404
+ function $n(t, e, n) {
2405
+ const { windowSize: r, mask: i, maxNumber: s, shiftBy: c } = n;
2406
+ let o = Number(t & i), f = t >> c;
2407
+ o > r && (o -= s, f += Dt);
2408
+ const u = e * r, a = u + Math.abs(o) - 1, w = o === 0, l = o < 0, d = e % 2 !== 0;
2409
+ return { nextN: f, offset: a, isZero: w, isNeg: l, isNegF: d, offsetF: u };
2410
+ }
2411
+ function hs(t, e) {
2412
+ if (!Array.isArray(t))
2413
+ throw new Error("array expected");
2414
+ t.forEach((n, r) => {
2415
+ if (!(n instanceof e))
2416
+ throw new Error("invalid point at index " + r);
2417
+ });
2418
+ }
2419
+ function ws(t, e) {
2420
+ if (!Array.isArray(t))
2421
+ throw new Error("array of scalars expected");
2422
+ t.forEach((n, r) => {
2423
+ if (!e.isValid(n))
2424
+ throw new Error("invalid scalar at index " + r);
2425
+ });
2426
+ }
2427
+ const He = /* @__PURE__ */ new WeakMap(), Ir = /* @__PURE__ */ new WeakMap();
2428
+ function ke(t) {
2429
+ return Ir.get(t) || 1;
2430
+ }
2431
+ function Hn(t) {
2432
+ if (t !== Qt)
2433
+ throw new Error("invalid wNAF");
2434
+ }
2435
+ function Or(t, e) {
2436
+ return {
2437
+ constTimeNegate: oe,
2438
+ hasPrecomputes(n) {
2439
+ return ke(n) !== 1;
2440
+ },
2441
+ // non-const time multiplication ladder
2442
+ unsafeLadder(n, r, i = t.ZERO) {
2443
+ let s = n;
2444
+ for (; r > Qt; )
2445
+ r & Dt && (i = i.add(s)), s = s.double(), r >>= Dt;
2446
+ return i;
2447
+ },
2448
+ /**
2449
+ * Creates a wNAF precomputation window. Used for caching.
2450
+ * Default window size is set by `utils.precompute()` and is equal to 8.
2451
+ * Number of precomputed points depends on the curve size:
2452
+ * 2^(𝑊−1) * (Math.ceil(𝑛 / 𝑊) + 1), where:
2453
+ * - 𝑊 is the window size
2454
+ * - 𝑛 is the bitlength of the curve order.
2455
+ * For a 256-bit curve and window size 8, the number of precomputed points is 128 * 33 = 4224.
2456
+ * @param elm Point instance
2457
+ * @param W window size
2458
+ * @returns precomputed point tables flattened to a single array
2459
+ */
2460
+ precomputeWindow(n, r) {
2461
+ const { windows: i, windowSize: s } = $e(r, e), c = [];
2462
+ let o = n, f = o;
2463
+ for (let u = 0; u < i; u++) {
2464
+ f = o, c.push(f);
2465
+ for (let a = 1; a < s; a++)
2466
+ f = f.add(o), c.push(f);
2467
+ o = f.double();
2468
+ }
2469
+ return c;
2470
+ },
2471
+ /**
2472
+ * Implements ec multiplication using precomputed tables and w-ary non-adjacent form.
2473
+ * @param W window size
2474
+ * @param precomputes precomputed tables
2475
+ * @param n scalar (we don't check here, but should be less than curve order)
2476
+ * @returns real and fake (for const-time) points
2477
+ */
2478
+ wNAF(n, r, i) {
2479
+ let s = t.ZERO, c = t.BASE;
2480
+ const o = $e(n, e);
2481
+ for (let f = 0; f < o.windows; f++) {
2482
+ const { nextN: u, offset: a, isZero: w, isNeg: l, isNegF: d, offsetF: p } = $n(i, f, o);
2483
+ i = u, w ? c = c.add(oe(d, r[p])) : s = s.add(oe(l, r[a]));
2484
+ }
2485
+ return Hn(i), { p: s, f: c };
2486
+ },
2487
+ /**
2488
+ * Implements ec unsafe (non const-time) multiplication using precomputed tables and w-ary non-adjacent form.
2489
+ * @param W window size
2490
+ * @param precomputes precomputed tables
2491
+ * @param n scalar (we don't check here, but should be less than curve order)
2492
+ * @param acc accumulator point to add result of multiplication
2493
+ * @returns point
2494
+ */
2495
+ wNAFUnsafe(n, r, i, s = t.ZERO) {
2496
+ const c = $e(n, e);
2497
+ for (let o = 0; o < c.windows && i !== Qt; o++) {
2498
+ const { nextN: f, offset: u, isZero: a, isNeg: w } = $n(i, o, c);
2499
+ if (i = f, !a) {
2500
+ const l = r[u];
2501
+ s = s.add(w ? l.negate() : l);
2502
+ }
2503
+ }
2504
+ return Hn(i), s;
2505
+ },
2506
+ getPrecomputes(n, r, i) {
2507
+ let s = He.get(r);
2508
+ return s || (s = this.precomputeWindow(r, n), n !== 1 && (typeof i == "function" && (s = i(s)), He.set(r, s))), s;
2509
+ },
2510
+ wNAFCached(n, r, i) {
2511
+ const s = ke(n);
2512
+ return this.wNAF(s, this.getPrecomputes(s, n, i), r);
2513
+ },
2514
+ wNAFCachedUnsafe(n, r, i, s) {
2515
+ const c = ke(n);
2516
+ return c === 1 ? this.unsafeLadder(n, r, s) : this.wNAFUnsafe(c, this.getPrecomputes(c, n, i), r, s);
2517
+ },
2518
+ // We calculate precomputes for elliptic curve point multiplication
2519
+ // using windowed method. This specifies window size and
2520
+ // stores precomputed values. Usually only base point would be precomputed.
2521
+ setWindowSize(n, r) {
2522
+ Ar(r, e), Ir.set(n, r), He.delete(n);
2523
+ }
2524
+ };
2525
+ }
2526
+ function ms(t, e, n, r) {
2527
+ let i = e, s = t.ZERO, c = t.ZERO;
2528
+ for (; n > Qt || r > Qt; )
2529
+ n & Dt && (s = s.add(i)), r & Dt && (c = c.add(i)), i = i.double(), n >>= Dt, r >>= Dt;
2530
+ return { p1: s, p2: c };
2531
+ }
2532
+ function un(t, e, n, r) {
2533
+ hs(n, t), ws(r, e);
2534
+ const i = n.length, s = r.length;
2535
+ if (i !== s)
2536
+ throw new Error("arrays of points and scalars must have equal length");
2537
+ const c = t.ZERO, o = ns(BigInt(i));
2538
+ let f = 1;
2539
+ o > 12 ? f = o - 3 : o > 4 ? f = o - 2 : o > 0 && (f = 2);
2540
+ const u = _e(f), a = new Array(Number(u) + 1).fill(c), w = Math.floor((e.BITS - 1) / f) * f;
2541
+ let l = c;
2542
+ for (let d = w; d >= 0; d -= f) {
2543
+ a.fill(c);
2544
+ for (let b = 0; b < s; b++) {
2545
+ const h = r[b], x = Number(h >> BigInt(d) & u);
2546
+ a[x] = a[x].add(n[b]);
2547
+ }
2548
+ let p = c;
2549
+ for (let b = a.length - 1, h = c; b > 0; b--)
2550
+ h = h.add(a[b]), p = p.add(h);
2551
+ if (l = l.add(p), d !== 0)
2552
+ for (let b = 0; b < f; b++)
2553
+ l = l.double();
2554
+ }
2555
+ return l;
2556
+ }
2557
+ function kn(t, e) {
2558
+ if (e) {
2559
+ if (e.ORDER !== t)
2560
+ throw new Error("Field.ORDER must match order: Fp == p, Fn == n");
2561
+ return as(e), e;
2562
+ } else
2563
+ return zt(t);
2564
+ }
2565
+ function qr(t, e, n = {}) {
2566
+ if (!e || typeof e != "object")
2567
+ throw new Error(`expected valid ${t} CURVE object`);
2568
+ for (const o of ["p", "n", "h"]) {
2569
+ const f = e[o];
2570
+ if (!(typeof f == "bigint" && f > Qt))
2571
+ throw new Error(`CURVE.${o} must be positive bigint`);
2572
+ }
2573
+ const r = kn(e.p, n.Fp), i = kn(e.n, n.Fn), c = ["Gx", "Gy", "a", t === "weierstrass" ? "b" : "d"];
2574
+ for (const o of c)
2575
+ if (!r.isValid(e[o]))
2576
+ throw new Error(`CURVE.${o} must be valid field element of CURVE.Fp`);
2577
+ return { Fp: r, Fn: i };
2578
+ }
2579
+ function Tn(t) {
2580
+ t.lowS !== void 0 && Ct("lowS", t.lowS), t.prehash !== void 0 && Ct("prehash", t.prehash);
2581
+ }
2582
+ class bs extends Error {
2583
+ constructor(e = "") {
2584
+ super(e);
2585
+ }
2586
+ }
2587
+ const pt = {
2588
+ // asn.1 DER encoding utils
2589
+ Err: bs,
2590
+ // Basic building block is TLV (Tag-Length-Value)
2591
+ _tlv: {
2592
+ encode: (t, e) => {
2593
+ const { Err: n } = pt;
2594
+ if (t < 0 || t > 256)
2595
+ throw new n("tlv.encode: wrong tag");
2596
+ if (e.length & 1)
2597
+ throw new n("tlv.encode: unpadded data");
2598
+ const r = e.length / 2, i = we(r);
2599
+ if (i.length / 2 & 128)
2600
+ throw new n("tlv.encode: long form length too big");
2601
+ const s = r > 127 ? we(i.length / 2 | 128) : "";
2602
+ return we(t) + s + i + e;
2603
+ },
2604
+ // v - value, l - left bytes (unparsed)
2605
+ decode(t, e) {
2606
+ const { Err: n } = pt;
2607
+ let r = 0;
2608
+ if (t < 0 || t > 256)
2609
+ throw new n("tlv.encode: wrong tag");
2610
+ if (e.length < 2 || e[r++] !== t)
2611
+ throw new n("tlv.decode: wrong tlv");
2612
+ const i = e[r++], s = !!(i & 128);
2613
+ let c = 0;
2614
+ if (!s)
2615
+ c = i;
2616
+ else {
2617
+ const f = i & 127;
2618
+ if (!f)
2619
+ throw new n("tlv.decode(long): indefinite length not supported");
2620
+ if (f > 4)
2621
+ throw new n("tlv.decode(long): byte length is too big");
2622
+ const u = e.subarray(r, r + f);
2623
+ if (u.length !== f)
2624
+ throw new n("tlv.decode: length bytes not complete");
2625
+ if (u[0] === 0)
2626
+ throw new n("tlv.decode(long): zero leftmost byte");
2627
+ for (const a of u)
2628
+ c = c << 8 | a;
2629
+ if (r += f, c < 128)
2630
+ throw new n("tlv.decode(long): not minimal encoding");
2631
+ }
2632
+ const o = e.subarray(r, r + c);
2633
+ if (o.length !== c)
2634
+ throw new n("tlv.decode: wrong value length");
2635
+ return { v: o, l: e.subarray(r + c) };
2636
+ }
2637
+ },
2638
+ // https://crypto.stackexchange.com/a/57734 Leftmost bit of first byte is 'negative' flag,
2639
+ // since we always use positive integers here. It must always be empty:
2640
+ // - add zero byte if exists
2641
+ // - if next byte doesn't have a flag, leading zero is not allowed (minimal encoding)
2642
+ _int: {
2643
+ encode(t) {
2644
+ const { Err: e } = pt;
2645
+ if (t < se)
2646
+ throw new e("integer: negative integers are not allowed");
2647
+ let n = we(t);
2648
+ if (Number.parseInt(n[0], 16) & 8 && (n = "00" + n), n.length & 1)
2649
+ throw new e("unexpected DER parsing assertion: unpadded hex");
2650
+ return n;
2651
+ },
2652
+ decode(t) {
2653
+ const { Err: e } = pt;
2654
+ if (t[0] & 128)
2655
+ throw new e("invalid signature integer: negative");
2656
+ if (t[0] === 0 && !(t[1] & 128))
2657
+ throw new e("invalid signature integer: unnecessary leading zero");
2658
+ return Be(t);
2659
+ }
2660
+ },
2661
+ toSig(t) {
2662
+ const { Err: e, _int: n, _tlv: r } = pt, i = z("signature", t), { v: s, l: c } = r.decode(48, i);
2663
+ if (c.length)
2664
+ throw new e("invalid signature: left bytes after parsing");
2665
+ const { v: o, l: f } = r.decode(2, s), { v: u, l: a } = r.decode(2, f);
2666
+ if (a.length)
2667
+ throw new e("invalid signature: left bytes after parsing");
2668
+ return { r: n.decode(o), s: n.decode(u) };
2669
+ },
2670
+ hexFromSig(t) {
2671
+ const { _tlv: e, _int: n } = pt, r = e.encode(2, n.encode(t.r)), i = e.encode(2, n.encode(t.s)), s = r + i;
2672
+ return e.encode(48, s);
2673
+ }
2674
+ }, se = BigInt(0), ie = BigInt(1), ys = BigInt(2), me = BigInt(3), gs = BigInt(4);
2675
+ function xs(t, e, n) {
2676
+ function r(i) {
2677
+ const s = t.sqr(i), c = t.mul(s, i);
2678
+ return t.add(t.add(c, t.mul(i, e)), n);
2679
+ }
2680
+ return r;
2681
+ }
2682
+ function Rr(t, e, n) {
2683
+ const { BYTES: r } = t;
2684
+ function i(s) {
2685
+ let c;
2686
+ if (typeof s == "bigint")
2687
+ c = s;
2688
+ else {
2689
+ let o = z("private key", s);
2690
+ if (e) {
2691
+ if (!e.includes(o.length * 2))
2692
+ throw new Error("invalid private key");
2693
+ const f = new Uint8Array(r);
2694
+ f.set(o, f.length - o.length), o = f;
2695
+ }
2696
+ try {
2697
+ c = t.fromBytes(o);
2698
+ } catch {
2699
+ throw new Error(`invalid private key: expected ui8a of size ${r}, got ${typeof s}`);
2700
+ }
2701
+ }
2702
+ if (n && (c = t.create(c)), !t.isValidNot0(c))
2703
+ throw new Error("invalid private key: out of range [1..N-1]");
2704
+ return c;
2705
+ }
2706
+ return i;
2707
+ }
2708
+ function ps(t, e = {}) {
2709
+ const { Fp: n, Fn: r } = qr("weierstrass", t, e), { h: i, n: s } = t;
2710
+ ue(e, {}, {
2711
+ allowInfinityPoint: "boolean",
2712
+ clearCofactor: "function",
2713
+ isTorsionFree: "function",
2714
+ fromBytes: "function",
2715
+ toBytes: "function",
2716
+ endo: "object",
2717
+ wrapPrivateKey: "boolean"
2718
+ });
2719
+ const { endo: c } = e;
2720
+ if (c && (!n.is0(t.a) || typeof c.beta != "bigint" || typeof c.splitScalar != "function"))
2721
+ throw new Error('invalid endo: expected "beta": bigint and "splitScalar": function');
2722
+ function o() {
2723
+ if (!n.isOdd)
2724
+ throw new Error("compression is not supported: Field does not have .isOdd()");
2725
+ }
2726
+ function f(q, g, _) {
2727
+ const { x: m, y } = g.toAffine(), E = n.toBytes(m);
2728
+ if (Ct("isCompressed", _), _) {
2729
+ o();
2730
+ const S = !n.isOdd(y);
2731
+ return ut(Lr(S), E);
2732
+ } else
2733
+ return ut(Uint8Array.of(4), E, n.toBytes(y));
2734
+ }
2735
+ function u(q) {
2736
+ W(q);
2737
+ const g = n.BYTES, _ = g + 1, m = 2 * g + 1, y = q.length, E = q[0], S = q.subarray(1);
2738
+ if (y === _ && (E === 2 || E === 3)) {
2739
+ const I = n.fromBytes(S);
2740
+ if (!n.isValid(I))
2741
+ throw new Error("bad point: is not on curve, wrong x");
2742
+ const O = l(I);
2743
+ let H;
2744
+ try {
2745
+ H = n.sqrt(O);
2746
+ } catch (U) {
2747
+ const T = U instanceof Error ? ": " + U.message : "";
2748
+ throw new Error("bad point: is not on curve, sqrt error" + T);
2749
+ }
2750
+ o();
2751
+ const k = n.isOdd(H);
2752
+ return (E & 1) === 1 !== k && (H = n.neg(H)), { x: I, y: H };
2753
+ } else if (y === m && E === 4) {
2754
+ const I = n.fromBytes(S.subarray(g * 0, g * 1)), O = n.fromBytes(S.subarray(g * 1, g * 2));
2755
+ if (!d(I, O))
2756
+ throw new Error("bad point: is not on curve");
2757
+ return { x: I, y: O };
2758
+ } else
2759
+ throw new Error(`bad point: got length ${y}, expected compressed=${_} or uncompressed=${m}`);
2760
+ }
2761
+ const a = e.toBytes || f, w = e.fromBytes || u, l = xs(n, t.a, t.b);
2762
+ function d(q, g) {
2763
+ const _ = n.sqr(g), m = l(q);
2764
+ return n.eql(_, m);
2765
+ }
2766
+ if (!d(t.Gx, t.Gy))
2767
+ throw new Error("bad curve params: generator point");
2768
+ const p = n.mul(n.pow(t.a, me), gs), b = n.mul(n.sqr(t.b), BigInt(27));
2769
+ if (n.is0(n.add(p, b)))
2770
+ throw new Error("bad curve params: a or b");
2771
+ function h(q, g, _ = !1) {
2772
+ if (!n.isValid(g) || _ && n.is0(g))
2773
+ throw new Error(`bad point coordinate ${q}`);
2774
+ return g;
2775
+ }
2776
+ function x(q) {
2777
+ if (!(q instanceof B))
2778
+ throw new Error("ProjectivePoint expected");
2779
+ }
2780
+ const v = ge((q, g) => {
2781
+ const { px: _, py: m, pz: y } = q;
2782
+ if (n.eql(y, n.ONE))
2783
+ return { x: _, y: m };
2784
+ const E = q.is0();
2785
+ g == null && (g = E ? n.ONE : n.inv(y));
2786
+ const S = n.mul(_, g), I = n.mul(m, g), O = n.mul(y, g);
2787
+ if (E)
2788
+ return { x: n.ZERO, y: n.ZERO };
2789
+ if (!n.eql(O, n.ONE))
2790
+ throw new Error("invZ was invalid");
2791
+ return { x: S, y: I };
2792
+ }), A = ge((q) => {
2793
+ if (q.is0()) {
2794
+ if (e.allowInfinityPoint && !n.is0(q.py))
2795
+ return;
2796
+ throw new Error("bad point: ZERO");
2797
+ }
2798
+ const { x: g, y: _ } = q.toAffine();
2799
+ if (!n.isValid(g) || !n.isValid(_))
2800
+ throw new Error("bad point: x or y not field elements");
2801
+ if (!d(g, _))
2802
+ throw new Error("bad point: equation left != right");
2803
+ if (!q.isTorsionFree())
2804
+ throw new Error("bad point: not in prime-order subgroup");
2805
+ return !0;
2806
+ });
2807
+ function L(q, g, _, m, y) {
2808
+ return _ = new B(n.mul(_.px, q), _.py, _.pz), g = oe(m, g), _ = oe(y, _), g.add(_);
2809
+ }
2810
+ class B {
2811
+ /** Does NOT validate if the point is valid. Use `.assertValidity()`. */
2812
+ constructor(g, _, m) {
2813
+ this.px = h("x", g), this.py = h("y", _, !0), this.pz = h("z", m), Object.freeze(this);
2814
+ }
2815
+ /** Does NOT validate if the point is valid. Use `.assertValidity()`. */
2816
+ static fromAffine(g) {
2817
+ const { x: _, y: m } = g || {};
2818
+ if (!g || !n.isValid(_) || !n.isValid(m))
2819
+ throw new Error("invalid affine point");
2820
+ if (g instanceof B)
2821
+ throw new Error("projective point not allowed");
2822
+ return n.is0(_) && n.is0(m) ? B.ZERO : new B(_, m, n.ONE);
2823
+ }
2824
+ get x() {
2825
+ return this.toAffine().x;
2826
+ }
2827
+ get y() {
2828
+ return this.toAffine().y;
2829
+ }
2830
+ static normalizeZ(g) {
2831
+ return Sr(B, "pz", g);
2832
+ }
2833
+ static fromBytes(g) {
2834
+ return W(g), B.fromHex(g);
2835
+ }
2836
+ /** Converts hash string or Uint8Array to Point. */
2837
+ static fromHex(g) {
2838
+ const _ = B.fromAffine(w(z("pointHex", g)));
2839
+ return _.assertValidity(), _;
2840
+ }
2841
+ /** Multiplies generator point by privateKey. */
2842
+ static fromPrivateKey(g) {
2843
+ const _ = Rr(r, e.allowedPrivateKeyLengths, e.wrapPrivateKey);
2844
+ return B.BASE.multiply(_(g));
2845
+ }
2846
+ /** Multiscalar Multiplication */
2847
+ static msm(g, _) {
2848
+ return un(B, r, g, _);
2849
+ }
2850
+ /**
2851
+ *
2852
+ * @param windowSize
2853
+ * @param isLazy true will defer table computation until the first multiplication
2854
+ * @returns
2855
+ */
2856
+ precompute(g = 8, _ = !0) {
2857
+ return N.setWindowSize(this, g), _ || this.multiply(me), this;
2858
+ }
2859
+ /** "Private method", don't use it directly */
2860
+ _setWindowSize(g) {
2861
+ this.precompute(g);
2862
+ }
2863
+ // TODO: return `this`
2864
+ /** A point on curve is valid if it conforms to equation. */
2865
+ assertValidity() {
2866
+ A(this);
2867
+ }
2868
+ hasEvenY() {
2869
+ const { y: g } = this.toAffine();
2870
+ if (!n.isOdd)
2871
+ throw new Error("Field doesn't support isOdd");
2872
+ return !n.isOdd(g);
2873
+ }
2874
+ /** Compare one point to another. */
2875
+ equals(g) {
2876
+ x(g);
2877
+ const { px: _, py: m, pz: y } = this, { px: E, py: S, pz: I } = g, O = n.eql(n.mul(_, I), n.mul(E, y)), H = n.eql(n.mul(m, I), n.mul(S, y));
2878
+ return O && H;
2879
+ }
2880
+ /** Flips point to one corresponding to (x, -y) in Affine coordinates. */
2881
+ negate() {
2882
+ return new B(this.px, n.neg(this.py), this.pz);
2883
+ }
2884
+ // Renes-Costello-Batina exception-free doubling formula.
2885
+ // There is 30% faster Jacobian formula, but it is not complete.
2886
+ // https://eprint.iacr.org/2015/1060, algorithm 3
2887
+ // Cost: 8M + 3S + 3*a + 2*b3 + 15add.
2888
+ double() {
2889
+ const { a: g, b: _ } = t, m = n.mul(_, me), { px: y, py: E, pz: S } = this;
2890
+ let I = n.ZERO, O = n.ZERO, H = n.ZERO, k = n.mul(y, y), Z = n.mul(E, E), U = n.mul(S, S), T = n.mul(y, E);
2891
+ return T = n.add(T, T), H = n.mul(y, S), H = n.add(H, H), I = n.mul(g, H), O = n.mul(m, U), O = n.add(I, O), I = n.sub(Z, O), O = n.add(Z, O), O = n.mul(I, O), I = n.mul(T, I), H = n.mul(m, H), U = n.mul(g, U), T = n.sub(k, U), T = n.mul(g, T), T = n.add(T, H), H = n.add(k, k), k = n.add(H, k), k = n.add(k, U), k = n.mul(k, T), O = n.add(O, k), U = n.mul(E, S), U = n.add(U, U), k = n.mul(U, T), I = n.sub(I, k), H = n.mul(U, Z), H = n.add(H, H), H = n.add(H, H), new B(I, O, H);
2892
+ }
2893
+ // Renes-Costello-Batina exception-free addition formula.
2894
+ // There is 30% faster Jacobian formula, but it is not complete.
2895
+ // https://eprint.iacr.org/2015/1060, algorithm 1
2896
+ // Cost: 12M + 0S + 3*a + 3*b3 + 23add.
2897
+ add(g) {
2898
+ x(g);
2899
+ const { px: _, py: m, pz: y } = this, { px: E, py: S, pz: I } = g;
2900
+ let O = n.ZERO, H = n.ZERO, k = n.ZERO;
2901
+ const Z = t.a, U = n.mul(t.b, me);
2902
+ let T = n.mul(_, E), M = n.mul(m, S), Y = n.mul(y, I), Q = n.add(_, m), C = n.add(E, S);
2903
+ Q = n.mul(Q, C), C = n.add(T, M), Q = n.sub(Q, C), C = n.add(_, y);
2904
+ let nt = n.add(E, I);
2905
+ return C = n.mul(C, nt), nt = n.add(T, Y), C = n.sub(C, nt), nt = n.add(m, y), O = n.add(S, I), nt = n.mul(nt, O), O = n.add(M, Y), nt = n.sub(nt, O), k = n.mul(Z, C), O = n.mul(U, Y), k = n.add(O, k), O = n.sub(M, k), k = n.add(M, k), H = n.mul(O, k), M = n.add(T, T), M = n.add(M, T), Y = n.mul(Z, Y), C = n.mul(U, C), M = n.add(M, Y), Y = n.sub(T, Y), Y = n.mul(Z, Y), C = n.add(C, Y), T = n.mul(M, C), H = n.add(H, T), T = n.mul(nt, C), O = n.mul(Q, O), O = n.sub(O, T), T = n.mul(Q, M), k = n.mul(nt, k), k = n.add(k, T), new B(O, H, k);
2906
+ }
2907
+ subtract(g) {
2908
+ return this.add(g.negate());
2909
+ }
2910
+ is0() {
2911
+ return this.equals(B.ZERO);
2912
+ }
2913
+ /**
2914
+ * Constant time multiplication.
2915
+ * Uses wNAF method. Windowed method may be 10% faster,
2916
+ * but takes 2x longer to generate and consumes 2x memory.
2917
+ * Uses precomputes when available.
2918
+ * Uses endomorphism for Koblitz curves.
2919
+ * @param scalar by which the point would be multiplied
2920
+ * @returns New point
2921
+ */
2922
+ multiply(g) {
2923
+ const { endo: _ } = e;
2924
+ if (!r.isValidNot0(g))
2925
+ throw new Error("invalid scalar: out of range");
2926
+ let m, y;
2927
+ const E = (S) => N.wNAFCached(this, S, B.normalizeZ);
2928
+ if (_) {
2929
+ const { k1neg: S, k1: I, k2neg: O, k2: H } = _.splitScalar(g), { p: k, f: Z } = E(I), { p: U, f: T } = E(H);
2930
+ y = Z.add(T), m = L(_.beta, k, U, S, O);
2931
+ } else {
2932
+ const { p: S, f: I } = E(g);
2933
+ m = S, y = I;
2934
+ }
2935
+ return B.normalizeZ([m, y])[0];
2936
+ }
2937
+ /**
2938
+ * Non-constant-time multiplication. Uses double-and-add algorithm.
2939
+ * It's faster, but should only be used when you don't care about
2940
+ * an exposed private key e.g. sig verification, which works over *public* keys.
2941
+ */
2942
+ multiplyUnsafe(g) {
2943
+ const { endo: _ } = e, m = this;
2944
+ if (!r.isValid(g))
2945
+ throw new Error("invalid scalar: out of range");
2946
+ if (g === se || m.is0())
2947
+ return B.ZERO;
2948
+ if (g === ie)
2949
+ return m;
2950
+ if (N.hasPrecomputes(this))
2951
+ return this.multiply(g);
2952
+ if (_) {
2953
+ const { k1neg: y, k1: E, k2neg: S, k2: I } = _.splitScalar(g), { p1: O, p2: H } = ms(B, m, E, I);
2954
+ return L(_.beta, O, H, y, S);
2955
+ } else
2956
+ return N.wNAFCachedUnsafe(m, g);
2957
+ }
2958
+ multiplyAndAddUnsafe(g, _, m) {
2959
+ const y = this.multiplyUnsafe(_).add(g.multiplyUnsafe(m));
2960
+ return y.is0() ? void 0 : y;
2961
+ }
2962
+ /**
2963
+ * Converts Projective point to affine (x, y) coordinates.
2964
+ * @param invertedZ Z^-1 (inverted zero) - optional, precomputation is useful for invertBatch
2965
+ */
2966
+ toAffine(g) {
2967
+ return v(this, g);
2968
+ }
2969
+ /**
2970
+ * Checks whether Point is free of torsion elements (is in prime subgroup).
2971
+ * Always torsion-free for cofactor=1 curves.
2972
+ */
2973
+ isTorsionFree() {
2974
+ const { isTorsionFree: g } = e;
2975
+ return i === ie ? !0 : g ? g(B, this) : N.wNAFCachedUnsafe(this, s).is0();
2976
+ }
2977
+ clearCofactor() {
2978
+ const { clearCofactor: g } = e;
2979
+ return i === ie ? this : g ? g(B, this) : this.multiplyUnsafe(i);
2980
+ }
2981
+ toBytes(g = !0) {
2982
+ return Ct("isCompressed", g), this.assertValidity(), a(B, this, g);
2983
+ }
2984
+ /** @deprecated use `toBytes` */
2985
+ toRawBytes(g = !0) {
2986
+ return this.toBytes(g);
2987
+ }
2988
+ toHex(g = !0) {
2989
+ return ht(this.toBytes(g));
2990
+ }
2991
+ toString() {
2992
+ return `<Point ${this.is0() ? "ZERO" : this.toHex()}>`;
2993
+ }
2994
+ }
2995
+ B.BASE = new B(t.Gx, t.Gy, n.ONE), B.ZERO = new B(n.ZERO, n.ONE, n.ZERO), B.Fp = n, B.Fn = r;
2996
+ const R = r.BITS, N = Or(B, e.endo ? Math.ceil(R / 2) : R);
2997
+ return B;
2998
+ }
2999
+ function Lr(t) {
3000
+ return Uint8Array.of(t ? 2 : 3);
3001
+ }
3002
+ function Es(t, e, n = {}) {
3003
+ ue(e, { hash: "function" }, {
3004
+ hmac: "function",
3005
+ lowS: "boolean",
3006
+ randomBytes: "function",
3007
+ bits2int: "function",
3008
+ bits2int_modN: "function"
3009
+ });
3010
+ const r = e.randomBytes || Je, i = e.hmac || ((m, ...y) => en(e.hash, m, ut(...y))), { Fp: s, Fn: c } = t, { ORDER: o, BITS: f } = c;
3011
+ function u(m) {
3012
+ const y = o >> ie;
3013
+ return m > y;
3014
+ }
3015
+ function a(m) {
3016
+ return u(m) ? c.neg(m) : m;
3017
+ }
3018
+ function w(m, y) {
3019
+ if (!c.isValidNot0(y))
3020
+ throw new Error(`invalid signature ${m}: out of range 1..CURVE.n`);
3021
+ }
3022
+ class l {
3023
+ constructor(y, E, S) {
3024
+ w("r", y), w("s", E), this.r = y, this.s = E, S != null && (this.recovery = S), Object.freeze(this);
3025
+ }
3026
+ // pair (bytes of r, bytes of s)
3027
+ static fromCompact(y) {
3028
+ const E = c.BYTES, S = z("compactSignature", y, E * 2);
3029
+ return new l(c.fromBytes(S.subarray(0, E)), c.fromBytes(S.subarray(E, E * 2)));
3030
+ }
3031
+ // DER encoded ECDSA signature
3032
+ // https://bitcoin.stackexchange.com/questions/57644/what-are-the-parts-of-a-bitcoin-transaction-input-script
3033
+ static fromDER(y) {
3034
+ const { r: E, s: S } = pt.toSig(z("DER", y));
3035
+ return new l(E, S);
3036
+ }
3037
+ /**
3038
+ * @todo remove
3039
+ * @deprecated
3040
+ */
3041
+ assertValidity() {
3042
+ }
3043
+ addRecoveryBit(y) {
3044
+ return new l(this.r, this.s, y);
3045
+ }
3046
+ // ProjPointType<bigint>
3047
+ recoverPublicKey(y) {
3048
+ const E = s.ORDER, { r: S, s: I, recovery: O } = this;
3049
+ if (O == null || ![0, 1, 2, 3].includes(O))
3050
+ throw new Error("recovery id invalid");
3051
+ if (o * ys < E && O > 1)
3052
+ throw new Error("recovery id is ambiguous for h>1 curve");
3053
+ const k = O === 2 || O === 3 ? S + o : S;
3054
+ if (!s.isValid(k))
3055
+ throw new Error("recovery id 2 or 3 invalid");
3056
+ const Z = s.toBytes(k), U = t.fromHex(ut(Lr((O & 1) === 0), Z)), T = c.inv(k), M = A(z("msgHash", y)), Y = c.create(-M * T), Q = c.create(I * T), C = t.BASE.multiplyUnsafe(Y).add(U.multiplyUnsafe(Q));
3057
+ if (C.is0())
3058
+ throw new Error("point at infinify");
3059
+ return C.assertValidity(), C;
3060
+ }
3061
+ // Signatures should be low-s, to prevent malleability.
3062
+ hasHighS() {
3063
+ return u(this.s);
3064
+ }
3065
+ normalizeS() {
3066
+ return this.hasHighS() ? new l(this.r, c.neg(this.s), this.recovery) : this;
3067
+ }
3068
+ toBytes(y) {
3069
+ if (y === "compact")
3070
+ return ut(c.toBytes(this.r), c.toBytes(this.s));
3071
+ if (y === "der")
3072
+ return ae(pt.hexFromSig(this));
3073
+ throw new Error("invalid format");
3074
+ }
3075
+ // DER-encoded
3076
+ toDERRawBytes() {
3077
+ return this.toBytes("der");
3078
+ }
3079
+ toDERHex() {
3080
+ return ht(this.toBytes("der"));
3081
+ }
3082
+ // padded bytes of r, then padded bytes of s
3083
+ toCompactRawBytes() {
3084
+ return this.toBytes("compact");
3085
+ }
3086
+ toCompactHex() {
3087
+ return ht(this.toBytes("compact"));
3088
+ }
3089
+ }
3090
+ const d = Rr(c, n.allowedPrivateKeyLengths, n.wrapPrivateKey), p = {
3091
+ isValidPrivateKey(m) {
3092
+ try {
3093
+ return d(m), !0;
3094
+ } catch {
3095
+ return !1;
3096
+ }
3097
+ },
3098
+ normPrivateKeyToScalar: d,
3099
+ /**
3100
+ * Produces cryptographically secure private key from random of size
3101
+ * (groupLen + ceil(groupLen / 2)) with modulo bias being negligible.
3102
+ */
3103
+ randomPrivateKey: () => {
3104
+ const m = o;
3105
+ return ds(r(vr(m)), m);
3106
+ },
3107
+ precompute(m = 8, y = t.BASE) {
3108
+ return y.precompute(m, !1);
3109
+ }
3110
+ };
3111
+ function b(m, y = !0) {
3112
+ return t.fromPrivateKey(m).toBytes(y);
3113
+ }
3114
+ function h(m) {
3115
+ if (typeof m == "bigint")
3116
+ return !1;
3117
+ if (m instanceof t)
3118
+ return !0;
3119
+ const E = z("key", m).length, S = s.BYTES, I = S + 1, O = 2 * S + 1;
3120
+ if (!(n.allowedPrivateKeyLengths || c.BYTES === I))
3121
+ return E === I || E === O;
3122
+ }
3123
+ function x(m, y, E = !0) {
3124
+ if (h(m) === !0)
3125
+ throw new Error("first arg must be private key");
3126
+ if (h(y) === !1)
3127
+ throw new Error("second arg must be public key");
3128
+ return t.fromHex(y).multiply(d(m)).toBytes(E);
3129
+ }
3130
+ const v = e.bits2int || function(m) {
3131
+ if (m.length > 8192)
3132
+ throw new Error("input is too large");
3133
+ const y = Be(m), E = m.length * 8 - f;
3134
+ return E > 0 ? y >> BigInt(E) : y;
3135
+ }, A = e.bits2int_modN || function(m) {
3136
+ return c.create(v(m));
3137
+ }, L = _e(f);
3138
+ function B(m) {
3139
+ return Xt("num < 2^" + f, m, se, L), c.toBytes(m);
3140
+ }
3141
+ function R(m, y, E = N) {
3142
+ if (["recovered", "canonical"].some((Q) => Q in E))
3143
+ throw new Error("sign() legacy options not supported");
3144
+ const { hash: S } = e;
3145
+ let { lowS: I, prehash: O, extraEntropy: H } = E;
3146
+ I == null && (I = !0), m = z("msgHash", m), Tn(E), O && (m = z("prehashed msgHash", S(m)));
3147
+ const k = A(m), Z = d(y), U = [B(Z), B(k)];
3148
+ if (H != null && H !== !1) {
3149
+ const Q = H === !0 ? r(s.BYTES) : H;
3150
+ U.push(z("extraEntropy", Q));
3151
+ }
3152
+ const T = ut(...U), M = k;
3153
+ function Y(Q) {
3154
+ const C = v(Q);
3155
+ if (!c.isValidNot0(C))
3156
+ return;
3157
+ const nt = c.inv(C), Ft = t.BASE.multiply(C).toAffine(), jt = c.create(Ft.x);
3158
+ if (jt === se)
3159
+ return;
3160
+ const kt = c.create(nt * c.create(M + jt * Z));
3161
+ if (kt === se)
3162
+ return;
3163
+ let Se = (Ft.x === jt ? 0 : 2) | Number(Ft.y & ie), Vt = kt;
3164
+ return I && u(kt) && (Vt = a(kt), Se ^= 1), new l(jt, Vt, Se);
3165
+ }
3166
+ return { seed: T, k2sig: Y };
3167
+ }
3168
+ const N = { lowS: e.lowS, prehash: !1 }, q = { lowS: e.lowS, prehash: !1 };
3169
+ function g(m, y, E = N) {
3170
+ const { seed: S, k2sig: I } = R(m, y, E);
3171
+ return rs(e.hash.outputLen, c.BYTES, i)(S, I);
3172
+ }
3173
+ t.BASE.precompute(8);
3174
+ function _(m, y, E, S = q) {
3175
+ const I = m;
3176
+ y = z("msgHash", y), E = z("publicKey", E), Tn(S);
3177
+ const { lowS: O, prehash: H, format: k } = S;
3178
+ if ("strict" in S)
3179
+ throw new Error("options.strict was renamed to lowS");
3180
+ if (k !== void 0 && !["compact", "der", "js"].includes(k))
3181
+ throw new Error('format must be "compact", "der" or "js"');
3182
+ const Z = typeof I == "string" || pe(I), U = !Z && !k && typeof I == "object" && I !== null && typeof I.r == "bigint" && typeof I.s == "bigint";
3183
+ if (!Z && !U)
3184
+ throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");
3185
+ let T, M;
3186
+ try {
3187
+ if (U)
3188
+ if (k === void 0 || k === "js")
3189
+ T = new l(I.r, I.s);
3190
+ else
3191
+ throw new Error("invalid format");
3192
+ if (Z) {
3193
+ try {
3194
+ k !== "compact" && (T = l.fromDER(I));
3195
+ } catch (Vt) {
3196
+ if (!(Vt instanceof pt.Err))
3197
+ throw Vt;
3198
+ }
3199
+ !T && k !== "der" && (T = l.fromCompact(I));
3200
+ }
3201
+ M = t.fromHex(E);
3202
+ } catch {
3203
+ return !1;
3204
+ }
3205
+ if (!T || O && T.hasHighS())
3206
+ return !1;
3207
+ H && (y = e.hash(y));
3208
+ const { r: Y, s: Q } = T, C = A(y), nt = c.inv(Q), Ft = c.create(C * nt), jt = c.create(Y * nt), kt = t.BASE.multiplyUnsafe(Ft).add(M.multiplyUnsafe(jt));
3209
+ return kt.is0() ? !1 : c.create(kt.x) === Y;
3210
+ }
3211
+ return Object.freeze({
3212
+ getPublicKey: b,
3213
+ getSharedSecret: x,
3214
+ sign: g,
3215
+ verify: _,
3216
+ utils: p,
3217
+ Point: t,
3218
+ Signature: l
3219
+ });
3220
+ }
3221
+ function Bs(t) {
3222
+ const e = {
3223
+ a: t.a,
3224
+ b: t.b,
3225
+ p: t.Fp.ORDER,
3226
+ n: t.n,
3227
+ h: t.h,
3228
+ Gx: t.Gx,
3229
+ Gy: t.Gy
3230
+ }, n = t.Fp, r = zt(e.n, t.nBitLength), i = {
3231
+ Fp: n,
3232
+ Fn: r,
3233
+ allowedPrivateKeyLengths: t.allowedPrivateKeyLengths,
3234
+ allowInfinityPoint: t.allowInfinityPoint,
3235
+ endo: t.endo,
3236
+ wrapPrivateKey: t.wrapPrivateKey,
3237
+ isTorsionFree: t.isTorsionFree,
3238
+ clearCofactor: t.clearCofactor,
3239
+ fromBytes: t.fromBytes,
3240
+ toBytes: t.toBytes
3241
+ };
3242
+ return { CURVE: e, curveOpts: i };
3243
+ }
3244
+ function _s(t) {
3245
+ const { CURVE: e, curveOpts: n } = Bs(t), r = {
3246
+ hash: t.hash,
3247
+ hmac: t.hmac,
3248
+ randomBytes: t.randomBytes,
3249
+ lowS: t.lowS,
3250
+ bits2int: t.bits2int,
3251
+ bits2int_modN: t.bits2int_modN
3252
+ };
3253
+ return { CURVE: e, curveOpts: n, ecdsaOpts: r };
3254
+ }
3255
+ function vs(t, e) {
3256
+ return Object.assign({}, e, {
3257
+ ProjectivePoint: e.Point,
3258
+ CURVE: t
3259
+ });
3260
+ }
3261
+ function Ss(t) {
3262
+ const { CURVE: e, curveOpts: n, ecdsaOpts: r } = _s(t), i = ps(e, n), s = Es(i, r, n);
3263
+ return vs(t, s);
3264
+ }
3265
+ function As(t, e) {
3266
+ const n = (r) => Ss({ ...t, hash: r });
3267
+ return { ...n(e), create: n };
3268
+ }
3269
+ const xe = {
3270
+ p: BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),
3271
+ n: BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),
3272
+ h: BigInt(1),
3273
+ a: BigInt(0),
3274
+ b: BigInt(7),
3275
+ Gx: BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),
3276
+ Gy: BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")
3277
+ };
3278
+ BigInt(0);
3279
+ const Is = BigInt(1), Ge = BigInt(2), Un = (t, e) => (t + e / Ge) / e;
3280
+ function Os(t) {
3281
+ const e = xe.p, n = BigInt(3), r = BigInt(6), i = BigInt(11), s = BigInt(22), c = BigInt(23), o = BigInt(44), f = BigInt(88), u = t * t * t % e, a = u * u * t % e, w = j(a, n, e) * a % e, l = j(w, n, e) * a % e, d = j(l, Ge, e) * u % e, p = j(d, i, e) * d % e, b = j(p, s, e) * p % e, h = j(b, o, e) * b % e, x = j(h, f, e) * h % e, v = j(x, o, e) * b % e, A = j(v, n, e) * a % e, L = j(A, c, e) * p % e, B = j(L, r, e) * u % e, R = j(B, Ge, e);
3282
+ if (!Xe.eql(Xe.sqr(R), t))
3283
+ throw new Error("Cannot find square root");
3284
+ return R;
3285
+ }
3286
+ const Xe = zt(xe.p, void 0, void 0, { sqrt: Os }), ii = As({
3287
+ ...xe,
3288
+ Fp: Xe,
3289
+ lowS: !0,
3290
+ // Allow only low-S signatures by default in sign() and verify()
3291
+ endo: {
3292
+ // Endomorphism, see above
3293
+ beta: BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),
3294
+ splitScalar: (t) => {
3295
+ const e = xe.n, n = BigInt("0x3086d221a7d46bcde86c90e49284eb15"), r = -Is * BigInt("0xe4437ed6010e88286f547fa90abfe4c3"), i = BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"), s = n, c = BigInt("0x100000000000000000000000000000000"), o = Un(s * t, e), f = Un(-r * t, e);
3296
+ let u = V(t - o * n - f * i, e), a = V(-o * r - f * s, e);
3297
+ const w = u > c, l = a > c;
3298
+ if (w && (u = e - u), l && (a = e - a), u > c || a > c)
3299
+ throw new Error("splitScalar: Endomorphism failed, k=" + t);
3300
+ return { k1neg: w, k1: u, k2neg: l, k2: a };
3301
+ }
3302
+ }
3303
+ }, Ee);
3304
+ const yt = BigInt(0), rt = BigInt(1), Te = BigInt(2), qs = BigInt(8), Rs = { zip215: !0 };
3305
+ function Ls(t, e, n, r) {
3306
+ const i = t.sqr(n), s = t.sqr(r), c = t.add(t.mul(e.a, i), s), o = t.add(t.ONE, t.mul(e.d, t.mul(i, s)));
3307
+ return t.eql(c, o);
3308
+ }
3309
+ function Ns(t, e = {}) {
3310
+ const { Fp: n, Fn: r } = qr("edwards", t, e), { h: i, n: s } = t;
3311
+ ue(e, {}, { uvRatio: "function" });
3312
+ const c = Te << BigInt(r.BYTES * 8) - rt, o = (b) => n.create(b), f = e.uvRatio || ((b, h) => {
3313
+ try {
3314
+ return { isValid: !0, value: n.sqrt(n.div(b, h)) };
3315
+ } catch {
3316
+ return { isValid: !1, value: yt };
3317
+ }
3318
+ });
3319
+ if (!Ls(n, t, t.Gx, t.Gy))
3320
+ throw new Error("bad curve params: generator point");
3321
+ function u(b, h, x = !1) {
3322
+ const v = x ? rt : yt;
3323
+ return Xt("coordinate " + b, h, v, c), h;
3324
+ }
3325
+ function a(b) {
3326
+ if (!(b instanceof d))
3327
+ throw new Error("ExtendedPoint expected");
3328
+ }
3329
+ const w = ge((b, h) => {
3330
+ const { ex: x, ey: v, ez: A } = b, L = b.is0();
3331
+ h == null && (h = L ? qs : n.inv(A));
3332
+ const B = o(x * h), R = o(v * h), N = o(A * h);
3333
+ if (L)
3334
+ return { x: yt, y: rt };
3335
+ if (N !== rt)
3336
+ throw new Error("invZ was invalid");
3337
+ return { x: B, y: R };
3338
+ }), l = ge((b) => {
3339
+ const { a: h, d: x } = t;
3340
+ if (b.is0())
3341
+ throw new Error("bad point: ZERO");
3342
+ const { ex: v, ey: A, ez: L, et: B } = b, R = o(v * v), N = o(A * A), q = o(L * L), g = o(q * q), _ = o(R * h), m = o(q * o(_ + N)), y = o(g + o(x * o(R * N)));
3343
+ if (m !== y)
3344
+ throw new Error("bad point: equation left != right (1)");
3345
+ const E = o(v * A), S = o(L * B);
3346
+ if (E !== S)
3347
+ throw new Error("bad point: equation left != right (2)");
3348
+ return !0;
3349
+ });
3350
+ class d {
3351
+ constructor(h, x, v, A) {
3352
+ this.ex = u("x", h), this.ey = u("y", x), this.ez = u("z", v, !0), this.et = u("t", A), Object.freeze(this);
3353
+ }
3354
+ get x() {
3355
+ return this.toAffine().x;
3356
+ }
3357
+ get y() {
3358
+ return this.toAffine().y;
3359
+ }
3360
+ static fromAffine(h) {
3361
+ if (h instanceof d)
3362
+ throw new Error("extended point not allowed");
3363
+ const { x, y: v } = h || {};
3364
+ return u("x", x), u("y", v), new d(x, v, rt, o(x * v));
3365
+ }
3366
+ static normalizeZ(h) {
3367
+ return Sr(d, "ez", h);
3368
+ }
3369
+ // Multiscalar Multiplication
3370
+ static msm(h, x) {
3371
+ return un(d, r, h, x);
3372
+ }
3373
+ // "Private method", don't use it directly
3374
+ _setWindowSize(h) {
3375
+ this.precompute(h);
3376
+ }
3377
+ precompute(h = 8, x = !0) {
3378
+ return p.setWindowSize(this, h), x || this.multiply(Te), this;
3379
+ }
3380
+ // Not required for fromHex(), which always creates valid points.
3381
+ // Could be useful for fromAffine().
3382
+ assertValidity() {
3383
+ l(this);
3384
+ }
3385
+ // Compare one point to another.
3386
+ equals(h) {
3387
+ a(h);
3388
+ const { ex: x, ey: v, ez: A } = this, { ex: L, ey: B, ez: R } = h, N = o(x * R), q = o(L * A), g = o(v * R), _ = o(B * A);
3389
+ return N === q && g === _;
3390
+ }
3391
+ is0() {
3392
+ return this.equals(d.ZERO);
3393
+ }
3394
+ negate() {
3395
+ return new d(o(-this.ex), this.ey, this.ez, o(-this.et));
3396
+ }
3397
+ // Fast algo for doubling Extended Point.
3398
+ // https://hyperelliptic.org/EFD/g1p/auto-twisted-extended.html#doubling-dbl-2008-hwcd
3399
+ // Cost: 4M + 4S + 1*a + 6add + 1*2.
3400
+ double() {
3401
+ const { a: h } = t, { ex: x, ey: v, ez: A } = this, L = o(x * x), B = o(v * v), R = o(Te * o(A * A)), N = o(h * L), q = x + v, g = o(o(q * q) - L - B), _ = N + B, m = _ - R, y = N - B, E = o(g * m), S = o(_ * y), I = o(g * y), O = o(m * _);
3402
+ return new d(E, S, O, I);
3403
+ }
3404
+ // Fast algo for adding 2 Extended Points.
3405
+ // https://hyperelliptic.org/EFD/g1p/auto-twisted-extended.html#addition-add-2008-hwcd
3406
+ // Cost: 9M + 1*a + 1*d + 7add.
3407
+ add(h) {
3408
+ a(h);
3409
+ const { a: x, d: v } = t, { ex: A, ey: L, ez: B, et: R } = this, { ex: N, ey: q, ez: g, et: _ } = h, m = o(A * N), y = o(L * q), E = o(R * v * _), S = o(B * g), I = o((A + L) * (N + q) - m - y), O = S - E, H = S + E, k = o(y - x * m), Z = o(I * O), U = o(H * k), T = o(I * k), M = o(O * H);
3410
+ return new d(Z, U, M, T);
3411
+ }
3412
+ subtract(h) {
3413
+ return this.add(h.negate());
3414
+ }
3415
+ // Constant-time multiplication.
3416
+ multiply(h) {
3417
+ const x = h;
3418
+ Xt("scalar", x, rt, s);
3419
+ const { p: v, f: A } = p.wNAFCached(this, x, d.normalizeZ);
3420
+ return d.normalizeZ([v, A])[0];
3421
+ }
3422
+ // Non-constant-time multiplication. Uses double-and-add algorithm.
3423
+ // It's faster, but should only be used when you don't care about
3424
+ // an exposed private key e.g. sig verification.
3425
+ // Does NOT allow scalars higher than CURVE.n.
3426
+ // Accepts optional accumulator to merge with multiply (important for sparse scalars)
3427
+ multiplyUnsafe(h, x = d.ZERO) {
3428
+ const v = h;
3429
+ return Xt("scalar", v, yt, s), v === yt ? d.ZERO : this.is0() || v === rt ? this : p.wNAFCachedUnsafe(this, v, d.normalizeZ, x);
3430
+ }
3431
+ // Checks if point is of small order.
3432
+ // If you add something to small order point, you will have "dirty"
3433
+ // point with torsion component.
3434
+ // Multiplies point by cofactor and checks if the result is 0.
3435
+ isSmallOrder() {
3436
+ return this.multiplyUnsafe(i).is0();
3437
+ }
3438
+ // Multiplies point by curve order and checks if the result is 0.
3439
+ // Returns `false` is the point is dirty.
3440
+ isTorsionFree() {
3441
+ return p.wNAFCachedUnsafe(this, s).is0();
3442
+ }
3443
+ // Converts Extended point to default (x, y) coordinates.
3444
+ // Can accept precomputed Z^-1 - for example, from invertBatch.
3445
+ toAffine(h) {
3446
+ return w(this, h);
3447
+ }
3448
+ clearCofactor() {
3449
+ return i === rt ? this : this.multiplyUnsafe(i);
3450
+ }
3451
+ static fromBytes(h, x = !1) {
3452
+ return W(h), this.fromHex(h, x);
3453
+ }
3454
+ // Converts hash string or Uint8Array to Point.
3455
+ // Uses algo from RFC8032 5.1.3.
3456
+ static fromHex(h, x = !1) {
3457
+ const { d: v, a: A } = t, L = n.BYTES;
3458
+ h = z("pointHex", h, L), Ct("zip215", x);
3459
+ const B = h.slice(), R = h[L - 1];
3460
+ B[L - 1] = R & -129;
3461
+ const N = Pt(B), q = x ? c : n.ORDER;
3462
+ Xt("pointHex.y", N, yt, q);
3463
+ const g = o(N * N), _ = o(g - rt), m = o(v * g - A);
3464
+ let { isValid: y, value: E } = f(_, m);
3465
+ if (!y)
3466
+ throw new Error("Point.fromHex: invalid y coordinate");
3467
+ const S = (E & rt) === rt, I = (R & 128) !== 0;
3468
+ if (!x && E === yt && I)
3469
+ throw new Error("Point.fromHex: x=0 and x_0=1");
3470
+ return I !== S && (E = o(-E)), d.fromAffine({ x: E, y: N });
3471
+ }
3472
+ static fromPrivateScalar(h) {
3473
+ return d.BASE.multiply(h);
3474
+ }
3475
+ toBytes() {
3476
+ const { x: h, y: x } = this.toAffine(), v = Wt(x, n.BYTES);
3477
+ return v[v.length - 1] |= h & rt ? 128 : 0, v;
3478
+ }
3479
+ /** @deprecated use `toBytes` */
3480
+ toRawBytes() {
3481
+ return this.toBytes();
3482
+ }
3483
+ toHex() {
3484
+ return ht(this.toBytes());
3485
+ }
3486
+ toString() {
3487
+ return `<Point ${this.is0() ? "ZERO" : this.toHex()}>`;
3488
+ }
3489
+ }
3490
+ d.BASE = new d(t.Gx, t.Gy, rt, o(t.Gx * t.Gy)), d.ZERO = new d(yt, rt, rt, yt), d.Fp = n, d.Fn = r;
3491
+ const p = Or(d, r.BYTES * 8);
3492
+ return d;
3493
+ }
3494
+ function $s(t, e) {
3495
+ ue(e, {
3496
+ hash: "function"
3497
+ }, {
3498
+ adjustScalarBytes: "function",
3499
+ randomBytes: "function",
3500
+ domain: "function",
3501
+ prehash: "function",
3502
+ mapToCurve: "function"
3503
+ });
3504
+ const { prehash: n, hash: r } = e, { BASE: i, Fp: s, Fn: c } = t, o = c.ORDER, f = e.randomBytes || Je, u = e.adjustScalarBytes || ((B) => B), a = e.domain || ((B, R, N) => {
3505
+ if (Ct("phflag", N), R.length || N)
3506
+ throw new Error("Contexts/pre-hash are not supported");
3507
+ return B;
3508
+ });
3509
+ function w(B) {
3510
+ return c.create(B);
3511
+ }
3512
+ function l(B) {
3513
+ return w(Pt(B));
3514
+ }
3515
+ function d(B) {
3516
+ const R = s.BYTES;
3517
+ B = z("private key", B, R);
3518
+ const N = z("hashed private key", r(B), 2 * R), q = u(N.slice(0, R)), g = N.slice(R, 2 * R), _ = l(q);
3519
+ return { head: q, prefix: g, scalar: _ };
3520
+ }
3521
+ function p(B) {
3522
+ const { head: R, prefix: N, scalar: q } = d(B), g = i.multiply(q), _ = g.toBytes();
3523
+ return { head: R, prefix: N, scalar: q, point: g, pointBytes: _ };
3524
+ }
3525
+ function b(B) {
3526
+ return p(B).pointBytes;
3527
+ }
3528
+ function h(B = Uint8Array.of(), ...R) {
3529
+ const N = ut(...R);
3530
+ return l(r(a(N, z("context", B), !!n)));
3531
+ }
3532
+ function x(B, R, N = {}) {
3533
+ B = z("message", B), n && (B = n(B));
3534
+ const { prefix: q, scalar: g, pointBytes: _ } = p(R), m = h(N.context, q, B), y = i.multiply(m).toBytes(), E = h(N.context, y, _, B), S = w(m + E * g);
3535
+ Xt("signature.s", S, yt, o);
3536
+ const I = s.BYTES, O = ut(y, Wt(S, I));
3537
+ return z("result", O, I * 2);
3538
+ }
3539
+ const v = Rs;
3540
+ function A(B, R, N, q = v) {
3541
+ const { context: g, zip215: _ } = q, m = s.BYTES;
3542
+ B = z("signature", B, 2 * m), R = z("message", R), N = z("publicKey", N, m), _ !== void 0 && Ct("zip215", _), n && (R = n(R));
3543
+ const y = Pt(B.slice(m, 2 * m));
3544
+ let E, S, I;
3545
+ try {
3546
+ E = t.fromHex(N, _), S = t.fromHex(B.slice(0, m), _), I = i.multiplyUnsafe(y);
3547
+ } catch {
3548
+ return !1;
3549
+ }
3550
+ if (!_ && E.isSmallOrder())
3551
+ return !1;
3552
+ const O = h(g, S.toBytes(), E.toBytes(), R);
3553
+ return S.add(E.multiplyUnsafe(O)).subtract(I).clearCofactor().is0();
3554
+ }
3555
+ return i.precompute(8), { getPublicKey: b, sign: x, verify: A, utils: {
3556
+ getExtendedPublicKey: p,
3557
+ /** ed25519 priv keys are uniform 32b. No need to check for modulo bias, like in secp256k1. */
3558
+ randomPrivateKey: () => f(s.BYTES),
3559
+ /**
3560
+ * We're doing scalar multiplication (used in getPublicKey etc) with precomputed BASE_POINT
3561
+ * values. This slows down first getPublicKey() by milliseconds (see Speed section),
3562
+ * but allows to speed-up subsequent getPublicKey() calls up to 20x.
3563
+ * @param windowSize 2, 4, 8, 16
3564
+ */
3565
+ precompute(B = 8, R = t.BASE) {
3566
+ return R.precompute(B, !1);
3567
+ }
3568
+ }, Point: t };
3569
+ }
3570
+ function Hs(t) {
3571
+ const e = {
3572
+ a: t.a,
3573
+ d: t.d,
3574
+ p: t.Fp.ORDER,
3575
+ n: t.n,
3576
+ h: t.h,
3577
+ Gx: t.Gx,
3578
+ Gy: t.Gy
3579
+ }, n = t.Fp, r = zt(e.n, t.nBitLength, !0), i = { Fp: n, Fn: r, uvRatio: t.uvRatio }, s = {
3580
+ hash: t.hash,
3581
+ randomBytes: t.randomBytes,
3582
+ adjustScalarBytes: t.adjustScalarBytes,
3583
+ domain: t.domain,
3584
+ prehash: t.prehash,
3585
+ mapToCurve: t.mapToCurve
3586
+ };
3587
+ return { CURVE: e, curveOpts: i, eddsaOpts: s };
3588
+ }
3589
+ function ks(t, e) {
3590
+ return Object.assign({}, e, { ExtendedPoint: e.Point, CURVE: t });
3591
+ }
3592
+ function Ts(t) {
3593
+ const { CURVE: e, curveOpts: n, eddsaOpts: r } = Hs(t), i = Ns(e, n), s = $s(i, r);
3594
+ return ks(t, s);
3595
+ }
3596
+ const ci = BigInt(0), fi = BigInt(1), ai = BigInt(2);
3597
+ const Us = BigInt(0), Bt = BigInt(1), Zn = BigInt(2), li = BigInt(3), Zs = BigInt(5), Ds = BigInt(8), ve = {
3598
+ p: BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),
3599
+ n: BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),
3600
+ h: Ds,
3601
+ a: BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),
3602
+ d: BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),
3603
+ Gx: BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),
3604
+ Gy: BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")
3605
+ };
3606
+ function Ms(t) {
3607
+ const e = BigInt(10), n = BigInt(20), r = BigInt(40), i = BigInt(80), s = ve.p, o = t * t % s * t % s, f = j(o, Zn, s) * o % s, u = j(f, Bt, s) * t % s, a = j(u, Zs, s) * u % s, w = j(a, e, s) * a % s, l = j(w, n, s) * w % s, d = j(l, r, s) * l % s, p = j(d, i, s) * d % s, b = j(p, i, s) * d % s, h = j(b, e, s) * a % s;
3608
+ return { pow_p_5_8: j(h, Zn, s) * t % s, b2: o };
3609
+ }
3610
+ function Cs(t) {
3611
+ return t[0] &= 248, t[31] &= 127, t[31] |= 64, t;
3612
+ }
3613
+ const Ke = /* @__PURE__ */ BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");
3614
+ function dn(t, e) {
3615
+ const n = ve.p, r = V(e * e * e, n), i = V(r * r * e, n), s = Ms(t * i).pow_p_5_8;
3616
+ let c = V(t * r * s, n);
3617
+ const o = V(e * c * c, n), f = c, u = V(c * Ke, n), a = o === t, w = o === V(-t, n), l = o === V(-t * Ke, n);
3618
+ return a && (c = f), (w || l) && (c = u), $t(c, n) && (c = V(-c, n)), { isValid: a || w, value: c };
3619
+ }
3620
+ const Gt = zt(ve.p, void 0, !0), zs = {
3621
+ ...ve,
3622
+ Fp: Gt,
3623
+ hash: nn,
3624
+ adjustScalarBytes: Cs,
3625
+ // dom2
3626
+ // Ratio of u to v. Allows us to combine inversion and square root. Uses algo from RFC8032 5.1.3.
3627
+ // Constant-time, u/√v
3628
+ uvRatio: dn
3629
+ }, ct = Ts(zs);
3630
+ function Ue(t) {
3631
+ if (!(t instanceof K))
3632
+ throw new Error("RistrettoPoint expected");
3633
+ }
3634
+ const Pe = Ke, js = /* @__PURE__ */ BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"), Vs = /* @__PURE__ */ BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"), Ys = /* @__PURE__ */ BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"), Gs = /* @__PURE__ */ BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"), Dn = (t) => dn(Bt, t), Xs = /* @__PURE__ */ BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"), Ze = (t) => ct.CURVE.Fp.create(Pt(t) & Xs);
3635
+ function Mn(t) {
3636
+ const { d: e } = ct.CURVE, n = ct.CURVE.Fp.ORDER, r = ct.CURVE.Fp.create, i = r(Pe * t * t), s = r((i + Bt) * Ys);
3637
+ let c = BigInt(-1);
3638
+ const o = r((c - e * i) * r(i + e));
3639
+ let { isValid: f, value: u } = dn(s, o), a = r(u * t);
3640
+ $t(a, n) || (a = r(-a)), f || (u = a), f || (c = i);
3641
+ const w = r(c * (i - Bt) * Gs - o), l = u * u, d = r((u + u) * o), p = r(w * js), b = r(Bt - l), h = r(Bt + l);
3642
+ return new ct.Point(r(d * h), r(b * p), r(p * h), r(d * b));
3643
+ }
3644
+ class K {
3645
+ // Private property to discourage combining ExtendedPoint + RistrettoPoint
3646
+ // Always use Ristretto encoding/decoding instead.
3647
+ constructor(e) {
3648
+ this.ep = e;
3649
+ }
3650
+ static fromAffine(e) {
3651
+ return new K(ct.Point.fromAffine(e));
3652
+ }
3653
+ /**
3654
+ * Takes uniform output of 64-byte hash function like sha512 and converts it to `RistrettoPoint`.
3655
+ * The hash-to-group operation applies Elligator twice and adds the results.
3656
+ * **Note:** this is one-way map, there is no conversion from point to hash.
3657
+ * Described in [RFC9380](https://www.rfc-editor.org/rfc/rfc9380#appendix-B) and on
3658
+ * the [website](https://ristretto.group/formulas/elligator.html).
3659
+ * @param hex 64-byte output of a hash function
3660
+ */
3661
+ static hashToCurve(e) {
3662
+ e = z("ristrettoHash", e, 64);
3663
+ const n = Ze(e.slice(0, 32)), r = Mn(n), i = Ze(e.slice(32, 64)), s = Mn(i);
3664
+ return new K(r.add(s));
3665
+ }
3666
+ static fromBytes(e) {
3667
+ return W(e), this.fromHex(e);
3668
+ }
3669
+ /**
3670
+ * Converts ristretto-encoded string to ristretto point.
3671
+ * Described in [RFC9496](https://www.rfc-editor.org/rfc/rfc9496#name-decode).
3672
+ * @param hex Ristretto-encoded 32 bytes. Not every 32-byte string is valid ristretto encoding
3673
+ */
3674
+ static fromHex(e) {
3675
+ e = z("ristrettoHex", e, 32);
3676
+ const { a: n, d: r } = ct.CURVE, i = Gt.ORDER, s = Gt.create, c = "RistrettoPoint.fromHex: the hex is not valid encoding of RistrettoPoint", o = Ze(e);
3677
+ if (!ts(Wt(o, 32), e) || $t(o, i))
3678
+ throw new Error(c);
3679
+ const f = s(o * o), u = s(Bt + n * f), a = s(Bt - n * f), w = s(u * u), l = s(a * a), d = s(n * r * w - l), { isValid: p, value: b } = Dn(s(d * l)), h = s(b * a), x = s(b * h * d);
3680
+ let v = s((o + o) * h);
3681
+ $t(v, i) && (v = s(-v));
3682
+ const A = s(u * x), L = s(v * A);
3683
+ if (!p || $t(L, i) || A === Us)
3684
+ throw new Error(c);
3685
+ return new K(new ct.Point(v, A, Bt, L));
3686
+ }
3687
+ static msm(e, n) {
3688
+ const r = zt(ct.CURVE.n, ct.CURVE.nBitLength);
3689
+ return un(K, r, e, n);
3690
+ }
3691
+ /**
3692
+ * Encodes ristretto point to Uint8Array.
3693
+ * Described in [RFC9496](https://www.rfc-editor.org/rfc/rfc9496#name-encode).
3694
+ */
3695
+ toBytes() {
3696
+ let { ex: e, ey: n, ez: r, et: i } = this.ep;
3697
+ const s = Gt.ORDER, c = Gt.create, o = c(c(r + n) * c(r - n)), f = c(e * n), u = c(f * f), { value: a } = Dn(c(o * u)), w = c(a * o), l = c(a * f), d = c(w * l * i);
3698
+ let p;
3699
+ if ($t(i * d, s)) {
3700
+ let h = c(n * Pe), x = c(e * Pe);
3701
+ e = h, n = x, p = c(w * Vs);
3702
+ } else
3703
+ p = l;
3704
+ $t(e * d, s) && (n = c(-n));
3705
+ let b = c((r - n) * p);
3706
+ return $t(b, s) && (b = c(-b)), Wt(b, 32);
3707
+ }
3708
+ /** @deprecated use `toBytes` */
3709
+ toRawBytes() {
3710
+ return this.toBytes();
3711
+ }
3712
+ toHex() {
3713
+ return ht(this.toBytes());
3714
+ }
3715
+ toString() {
3716
+ return this.toHex();
3717
+ }
3718
+ /**
3719
+ * Compares two Ristretto points.
3720
+ * Described in [RFC9496](https://www.rfc-editor.org/rfc/rfc9496#name-equals).
3721
+ */
3722
+ equals(e) {
3723
+ Ue(e);
3724
+ const { ex: n, ey: r } = this.ep, { ex: i, ey: s } = e.ep, c = Gt.create, o = c(n * s) === c(r * i), f = c(r * s) === c(n * i);
3725
+ return o || f;
3726
+ }
3727
+ add(e) {
3728
+ return Ue(e), new K(this.ep.add(e.ep));
3729
+ }
3730
+ subtract(e) {
3731
+ return Ue(e), new K(this.ep.subtract(e.ep));
3732
+ }
3733
+ multiply(e) {
3734
+ return new K(this.ep.multiply(e));
3735
+ }
3736
+ multiplyUnsafe(e) {
3737
+ return new K(this.ep.multiplyUnsafe(e));
3738
+ }
3739
+ double() {
3740
+ return new K(this.ep.double());
3741
+ }
3742
+ negate() {
3743
+ return new K(this.ep.negate());
3744
+ }
3745
+ }
3746
+ const ui = (K.BASE || (K.BASE = new K(ct.Point.BASE)), K.ZERO || (K.ZERO = new K(ct.Point.ZERO)), K);
3747
+ export {
3748
+ ni as R,
3749
+ oi as a,
3750
+ Ks as b,
3751
+ ut as c,
3752
+ ce as d,
3753
+ re as e,
3754
+ dt as f,
3755
+ Mt as g,
3756
+ on as h,
3757
+ pe as i,
3758
+ si as j,
3759
+ ri as k,
3760
+ ii as l,
3761
+ P as m,
3762
+ fe as n,
3763
+ Pt as o,
3764
+ Jn as p,
3765
+ ui as q,
3766
+ Je as r,
3767
+ Ps as s,
3768
+ We as u
3769
+ };