backpack-viewer 0.7.0 → 0.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,4827 @@
1
+ var es = Object.defineProperty;
2
+ var ts = (t, e, n) => e in t ? es(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n;
3
+ var g = (t, e, n) => ts(t, typeof e != "symbol" ? e + "" : e, n);
4
+ function ns(t) {
5
+ return t instanceof Uint8Array || ArrayBuffer.isView(t) && t.constructor.name === "Uint8Array" && "BYTES_PER_ELEMENT" in t && t.BYTES_PER_ELEMENT === 1;
6
+ }
7
+ function de(t, e = "") {
8
+ if (typeof t != "number") {
9
+ const n = e && `"${e}" `;
10
+ throw new TypeError(`${n}expected number, got ${typeof t}`);
11
+ }
12
+ if (!Number.isSafeInteger(t) || t < 0) {
13
+ const n = e && `"${e}" `;
14
+ throw new RangeError(`${n}expected integer >= 0, got ${t}`);
15
+ }
16
+ }
17
+ function nt(t, e, n = "") {
18
+ const r = ns(t), o = t == null ? void 0 : t.length;
19
+ if (!r || e !== void 0) {
20
+ const i = n && `"${n}" `, c = "", f = r ? `length=${o}` : `type=${typeof t}`, u = i + "expected Uint8Array" + c + ", got " + f;
21
+ throw r ? new RangeError(u) : new TypeError(u);
22
+ }
23
+ return t;
24
+ }
25
+ function Zt(t) {
26
+ if (typeof t != "function" || typeof t.create != "function")
27
+ throw new TypeError("Hash must wrapped by utils.createHasher");
28
+ if (de(t.outputLen), de(t.blockLen), t.outputLen < 1)
29
+ throw new Error('"outputLen" must be >= 1');
30
+ if (t.blockLen < 1)
31
+ throw new Error('"blockLen" must be >= 1');
32
+ }
33
+ function Nt(t, e = !0) {
34
+ if (t.destroyed)
35
+ throw new Error("Hash instance has been destroyed");
36
+ if (e && t.finished)
37
+ throw new Error("Hash#digest() has already been called");
38
+ }
39
+ function Fr(t, e) {
40
+ nt(t, void 0, "digestInto() output");
41
+ const n = e.outputLen;
42
+ if (t.length < n)
43
+ throw new RangeError('"digestInto() output" expected to be of length >=' + n);
44
+ }
45
+ function sn(t) {
46
+ return new Uint32Array(t.buffer, t.byteOffset, Math.floor(t.byteLength / 4));
47
+ }
48
+ function De(...t) {
49
+ for (let e = 0; e < t.length; e++)
50
+ t[e].fill(0);
51
+ }
52
+ function Tt(t) {
53
+ return new DataView(t.buffer, t.byteOffset, t.byteLength);
54
+ }
55
+ function he(t, e) {
56
+ return t << 32 - e | t >>> e;
57
+ }
58
+ function j(t, e) {
59
+ return t << e | t >>> 32 - e >>> 0;
60
+ }
61
+ const rs = new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68;
62
+ function os(t) {
63
+ return t << 24 & 4278190080 | t << 8 & 16711680 | t >>> 8 & 65280 | t >>> 24 & 255;
64
+ }
65
+ function ss(t) {
66
+ for (let e = 0; e < t.length; e++)
67
+ t[e] = os(t[e]);
68
+ return t;
69
+ }
70
+ const sr = rs ? (t) => t : ss;
71
+ function is(t) {
72
+ if (typeof t != "string")
73
+ throw new TypeError("string expected");
74
+ return new Uint8Array(new TextEncoder().encode(t));
75
+ }
76
+ function ir(t, e = "") {
77
+ return typeof t == "string" ? is(t) : nt(t, void 0, e);
78
+ }
79
+ function Pr(t, e) {
80
+ if (e !== void 0 && {}.toString.call(e) !== "[object Object]")
81
+ throw new TypeError("options must be object or undefined");
82
+ return Object.assign(t, e);
83
+ }
84
+ function cs(t, e = {}) {
85
+ const n = (o, s) => t(s).update(o).digest(), r = t(void 0);
86
+ return n.outputLen = r.outputLen, n.blockLen = r.blockLen, n.canXOF = r.canXOF, n.create = (o) => t(o), Object.assign(n, e), Object.freeze(n);
87
+ }
88
+ function me(t = 32) {
89
+ de(t, "bytesLength");
90
+ const e = typeof globalThis == "object" ? globalThis.crypto : null;
91
+ if (typeof (e == null ? void 0 : e.getRandomValues) != "function")
92
+ throw new Error("crypto.getRandomValues must be defined");
93
+ if (t > 65536)
94
+ throw new RangeError(`"bytesLength" expected <= 65536, got ${t}`);
95
+ return e.getRandomValues(new Uint8Array(t));
96
+ }
97
+ const fs = (t) => ({
98
+ // Current NIST hashAlgs suffixes used here fit in one DER subidentifier octet.
99
+ // Larger suffix values would need base-128 OID encoding and a different length byte.
100
+ oid: Uint8Array.from([6, 9, 96, 134, 72, 1, 101, 3, 4, 2, t])
101
+ });
102
+ let cr = class {
103
+ constructor(e, n) {
104
+ g(this, "oHash");
105
+ g(this, "iHash");
106
+ g(this, "blockLen");
107
+ g(this, "outputLen");
108
+ g(this, "canXOF", !1);
109
+ g(this, "finished", !1);
110
+ g(this, "destroyed", !1);
111
+ if (Zt(e), nt(n, void 0, "key"), this.iHash = e.create(), typeof this.iHash.update != "function")
112
+ throw new Error("Expected instance of class which extends utils.Hash");
113
+ this.blockLen = this.iHash.blockLen, this.outputLen = this.iHash.outputLen;
114
+ const r = this.blockLen, o = new Uint8Array(r);
115
+ o.set(n.length > r ? e.create().update(n).digest() : n);
116
+ for (let s = 0; s < o.length; s++)
117
+ o[s] ^= 54;
118
+ this.iHash.update(o), this.oHash = e.create();
119
+ for (let s = 0; s < o.length; s++)
120
+ o[s] ^= 106;
121
+ this.oHash.update(o), De(o);
122
+ }
123
+ update(e) {
124
+ return Nt(this), this.iHash.update(e), this;
125
+ }
126
+ digestInto(e) {
127
+ Nt(this), Fr(e, this), this.finished = !0;
128
+ const n = e.subarray(0, this.outputLen);
129
+ this.iHash.digestInto(n), this.oHash.update(n), this.oHash.digestInto(n), this.destroy();
130
+ }
131
+ digest() {
132
+ const e = new Uint8Array(this.oHash.outputLen);
133
+ return this.digestInto(e), e;
134
+ }
135
+ _cloneInto(e) {
136
+ e || (e = Object.create(Object.getPrototypeOf(this), {}));
137
+ const { oHash: n, iHash: r, finished: o, destroyed: s, blockLen: i, outputLen: c } = this;
138
+ return e = e, e.finished = o, e.destroyed = s, e.blockLen = i, e.outputLen = c, e.oHash = n._cloneInto(e.oHash), e.iHash = r._cloneInto(e.iHash), e;
139
+ }
140
+ clone() {
141
+ return this._cloneInto();
142
+ }
143
+ destroy() {
144
+ this.destroyed = !0, this.oHash.destroy(), this.iHash.destroy();
145
+ }
146
+ };
147
+ const Et = /* @__PURE__ */ (() => {
148
+ const t = ((e, n, r) => new cr(e, n).update(r).digest());
149
+ return t.create = (e, n) => new cr(e, n), t;
150
+ })();
151
+ function mt(t, e, n) {
152
+ return Zt(t), n === void 0 && (n = new Uint8Array(t.outputLen)), Et(t, n, e);
153
+ }
154
+ const cn = /* @__PURE__ */ Uint8Array.of(0), fr = /* @__PURE__ */ Uint8Array.of();
155
+ function Dr(t, e, n, r = 32) {
156
+ Zt(t), de(r, "length"), nt(e, void 0, "prk");
157
+ const o = t.outputLen;
158
+ if (e.length < o)
159
+ throw new Error('"prk" must be at least HashLen octets');
160
+ if (r > 255 * o)
161
+ throw new Error("Length must be <= 255*HashLen");
162
+ const s = Math.ceil(r / o);
163
+ n === void 0 ? n = fr : nt(n, void 0, "info");
164
+ const i = new Uint8Array(s * o), c = Et.create(t, e), f = c._cloneInto(), u = new Uint8Array(c.outputLen);
165
+ for (let d = 0; d < s; d++)
166
+ cn[0] = d + 1, f.update(d === 0 ? fr : u).update(n).update(cn).digestInto(u), i.set(u, o * d), c._cloneInto(f);
167
+ return c.destroy(), f.destroy(), De(u, cn), i.slice(0, r);
168
+ }
169
+ const rt = (t, e, n, r, o) => Dr(t, mt(t, e, n), r, o);
170
+ function as(t, e, n) {
171
+ return t & e ^ ~t & n;
172
+ }
173
+ function us(t, e, n) {
174
+ return t & e ^ t & n ^ e & n;
175
+ }
176
+ let ds = class {
177
+ constructor(e, n, r, o) {
178
+ g(this, "blockLen");
179
+ g(this, "outputLen");
180
+ g(this, "canXOF", !1);
181
+ g(this, "padOffset");
182
+ g(this, "isLE");
183
+ // For partial updates less than block size
184
+ g(this, "buffer");
185
+ g(this, "view");
186
+ g(this, "finished", !1);
187
+ g(this, "length", 0);
188
+ g(this, "pos", 0);
189
+ g(this, "destroyed", !1);
190
+ this.blockLen = e, this.outputLen = n, this.padOffset = r, this.isLE = o, this.buffer = new Uint8Array(e), this.view = Tt(this.buffer);
191
+ }
192
+ update(e) {
193
+ Nt(this), nt(e);
194
+ const { view: n, buffer: r, blockLen: o } = this, s = e.length;
195
+ for (let i = 0; i < s; ) {
196
+ const c = Math.min(o - this.pos, s - i);
197
+ if (c === o) {
198
+ const f = Tt(e);
199
+ for (; o <= s - i; i += o)
200
+ this.process(f, i);
201
+ continue;
202
+ }
203
+ r.set(e.subarray(i, i + c), this.pos), this.pos += c, i += c, this.pos === o && (this.process(n, 0), this.pos = 0);
204
+ }
205
+ return this.length += e.length, this.roundClean(), this;
206
+ }
207
+ digestInto(e) {
208
+ Nt(this), Fr(e, this), this.finished = !0;
209
+ const { buffer: n, view: r, blockLen: o, isLE: s } = this;
210
+ let { pos: i } = this;
211
+ n[i++] = 128, De(this.buffer.subarray(i)), this.padOffset > o - i && (this.process(r, 0), i = 0);
212
+ for (let a = i; a < o; a++)
213
+ n[a] = 0;
214
+ r.setBigUint64(o - 8, BigInt(this.length * 8), s), this.process(r, 0);
215
+ const c = Tt(e), f = this.outputLen;
216
+ if (f % 4)
217
+ throw new Error("_sha2: outputLen must be aligned to 32bit");
218
+ const u = f / 4, d = this.get();
219
+ if (u > d.length)
220
+ throw new Error("_sha2: outputLen bigger than state");
221
+ for (let a = 0; a < u; a++)
222
+ c.setUint32(4 * a, d[a], s);
223
+ }
224
+ digest() {
225
+ const { buffer: e, outputLen: n } = this;
226
+ this.digestInto(e);
227
+ const r = e.slice(0, n);
228
+ return this.destroy(), r;
229
+ }
230
+ _cloneInto(e) {
231
+ e || (e = new this.constructor()), e.set(...this.get());
232
+ const { blockLen: n, buffer: r, length: o, finished: s, destroyed: i, pos: c } = this;
233
+ return e.destroyed = i, e.finished = s, e.length = o, e.pos = c, o % n && e.buffer.set(r), e;
234
+ }
235
+ clone() {
236
+ return this._cloneInto();
237
+ }
238
+ };
239
+ const Ae = /* @__PURE__ */ Uint32Array.from([
240
+ 1779033703,
241
+ 3144134277,
242
+ 1013904242,
243
+ 2773480762,
244
+ 1359893119,
245
+ 2600822924,
246
+ 528734635,
247
+ 1541459225
248
+ ]), ls = /* @__PURE__ */ Uint32Array.from([
249
+ 1116352408,
250
+ 1899447441,
251
+ 3049323471,
252
+ 3921009573,
253
+ 961987163,
254
+ 1508970993,
255
+ 2453635748,
256
+ 2870763221,
257
+ 3624381080,
258
+ 310598401,
259
+ 607225278,
260
+ 1426881987,
261
+ 1925078388,
262
+ 2162078206,
263
+ 2614888103,
264
+ 3248222580,
265
+ 3835390401,
266
+ 4022224774,
267
+ 264347078,
268
+ 604807628,
269
+ 770255983,
270
+ 1249150122,
271
+ 1555081692,
272
+ 1996064986,
273
+ 2554220882,
274
+ 2821834349,
275
+ 2952996808,
276
+ 3210313671,
277
+ 3336571891,
278
+ 3584528711,
279
+ 113926993,
280
+ 338241895,
281
+ 666307205,
282
+ 773529912,
283
+ 1294757372,
284
+ 1396182291,
285
+ 1695183700,
286
+ 1986661051,
287
+ 2177026350,
288
+ 2456956037,
289
+ 2730485921,
290
+ 2820302411,
291
+ 3259730800,
292
+ 3345764771,
293
+ 3516065817,
294
+ 3600352804,
295
+ 4094571909,
296
+ 275423344,
297
+ 430227734,
298
+ 506948616,
299
+ 659060556,
300
+ 883997877,
301
+ 958139571,
302
+ 1322822218,
303
+ 1537002063,
304
+ 1747873779,
305
+ 1955562222,
306
+ 2024104815,
307
+ 2227730452,
308
+ 2361852424,
309
+ 2428436474,
310
+ 2756734187,
311
+ 3204031479,
312
+ 3329325298
313
+ ]), Be = /* @__PURE__ */ new Uint32Array(64);
314
+ let hs = class extends ds {
315
+ constructor(e) {
316
+ super(64, e, 8, !1);
317
+ }
318
+ get() {
319
+ const { A: e, B: n, C: r, D: o, E: s, F: i, G: c, H: f } = this;
320
+ return [e, n, r, o, s, i, c, f];
321
+ }
322
+ // prettier-ignore
323
+ set(e, n, r, o, s, i, c, f) {
324
+ this.A = e | 0, this.B = n | 0, this.C = r | 0, this.D = o | 0, this.E = s | 0, this.F = i | 0, this.G = c | 0, this.H = f | 0;
325
+ }
326
+ process(e, n) {
327
+ for (let a = 0; a < 16; a++, n += 4)
328
+ Be[a] = e.getUint32(n, !1);
329
+ for (let a = 16; a < 64; a++) {
330
+ const y = Be[a - 15], l = Be[a - 2], b = he(y, 7) ^ he(y, 18) ^ y >>> 3, E = he(l, 17) ^ he(l, 19) ^ l >>> 10;
331
+ Be[a] = E + Be[a - 7] + b + Be[a - 16] | 0;
332
+ }
333
+ let { A: r, B: o, C: s, D: i, E: c, F: f, G: u, H: d } = this;
334
+ for (let a = 0; a < 64; a++) {
335
+ const y = he(c, 6) ^ he(c, 11) ^ he(c, 25), l = d + y + as(c, f, u) + ls[a] + Be[a] | 0, E = (he(r, 2) ^ he(r, 13) ^ he(r, 22)) + us(r, o, s) | 0;
336
+ d = u, u = f, f = c, c = i + l | 0, i = s, s = o, o = r, r = l + E | 0;
337
+ }
338
+ r = r + this.A | 0, o = o + this.B | 0, s = s + this.C | 0, i = i + this.D | 0, c = c + this.E | 0, f = f + this.F | 0, u = u + this.G | 0, d = d + this.H | 0, this.set(r, o, s, i, c, f, u, d);
339
+ }
340
+ roundClean() {
341
+ De(Be);
342
+ }
343
+ destroy() {
344
+ this.destroyed = !0, this.set(0, 0, 0, 0, 0, 0, 0, 0), De(this.buffer);
345
+ }
346
+ }, ys = class extends hs {
347
+ constructor() {
348
+ super(32);
349
+ // We cannot use array here since array allows indexing by variable
350
+ // which means optimizer/compiler cannot use registers.
351
+ g(this, "A", Ae[0] | 0);
352
+ g(this, "B", Ae[1] | 0);
353
+ g(this, "C", Ae[2] | 0);
354
+ g(this, "D", Ae[3] | 0);
355
+ g(this, "E", Ae[4] | 0);
356
+ g(this, "F", Ae[5] | 0);
357
+ g(this, "G", Ae[6] | 0);
358
+ g(this, "H", Ae[7] | 0);
359
+ }
360
+ };
361
+ const ee = /* @__PURE__ */ cs(
362
+ () => new ys(),
363
+ /* @__PURE__ */ fs(1)
364
+ );
365
+ /*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) */
366
+ function Rn(t) {
367
+ return t instanceof Uint8Array || ArrayBuffer.isView(t) && t.constructor.name === "Uint8Array";
368
+ }
369
+ function ps(t) {
370
+ if (!Rn(t))
371
+ throw new Error("Uint8Array expected");
372
+ }
373
+ function jr(t, e) {
374
+ return Array.isArray(e) ? e.length === 0 ? !0 : t ? e.every((n) => typeof n == "string") : e.every((n) => Number.isSafeInteger(n)) : !1;
375
+ }
376
+ function gs(t) {
377
+ if (typeof t != "function")
378
+ throw new Error("function expected");
379
+ return !0;
380
+ }
381
+ function je(t, e) {
382
+ if (typeof e != "string")
383
+ throw new Error(`${t}: string expected`);
384
+ return !0;
385
+ }
386
+ function Tn(t) {
387
+ if (!Number.isSafeInteger(t))
388
+ throw new Error(`invalid integer: ${t}`);
389
+ }
390
+ function wn(t) {
391
+ if (!Array.isArray(t))
392
+ throw new Error("array expected");
393
+ }
394
+ function Mt(t, e) {
395
+ if (!jr(!0, e))
396
+ throw new Error(`${t}: array of strings expected`);
397
+ }
398
+ function qr(t, e) {
399
+ if (!jr(!1, e))
400
+ throw new Error(`${t}: array of numbers expected`);
401
+ }
402
+ // @__NO_SIDE_EFFECTS__
403
+ function Cn(...t) {
404
+ const e = (s) => s, n = (s, i) => (c) => s(i(c)), r = t.map((s) => s.encode).reduceRight(n, e), o = t.map((s) => s.decode).reduce(n, e);
405
+ return { encode: r, decode: o };
406
+ }
407
+ // @__NO_SIDE_EFFECTS__
408
+ function On(t) {
409
+ const e = typeof t == "string" ? t.split("") : t, n = e.length;
410
+ Mt("alphabet", e);
411
+ const r = new Map(e.map((o, s) => [o, s]));
412
+ return {
413
+ encode: (o) => (wn(o), o.map((s) => {
414
+ if (!Number.isSafeInteger(s) || s < 0 || s >= n)
415
+ throw new Error(`alphabet.encode: digit index outside alphabet "${s}". Allowed: ${t}`);
416
+ return e[s];
417
+ })),
418
+ decode: (o) => (wn(o), o.map((s) => {
419
+ je("alphabet.decode", s);
420
+ const i = r.get(s);
421
+ if (i === void 0)
422
+ throw new Error(`Unknown letter: "${s}". Allowed: ${t}`);
423
+ return i;
424
+ }))
425
+ };
426
+ }
427
+ // @__NO_SIDE_EFFECTS__
428
+ function $n(t = "") {
429
+ return je("join", t), {
430
+ encode: (e) => (Mt("join.decode", e), e.join(t)),
431
+ decode: (e) => (je("join.decode", e), e.split(t))
432
+ };
433
+ }
434
+ // @__NO_SIDE_EFFECTS__
435
+ function bs(t, e = "=") {
436
+ return Tn(t), je("padding", e), {
437
+ encode(n) {
438
+ for (Mt("padding.encode", n); n.length * t % 8; )
439
+ n.push(e);
440
+ return n;
441
+ },
442
+ decode(n) {
443
+ Mt("padding.decode", n);
444
+ let r = n.length;
445
+ if (r * t % 8)
446
+ throw new Error("padding: invalid, string should have whole number of bytes");
447
+ for (; r > 0 && n[r - 1] === e; r--)
448
+ if ((r - 1) * t % 8 === 0)
449
+ throw new Error("padding: invalid, string has too much padding");
450
+ return n.slice(0, r);
451
+ }
452
+ };
453
+ }
454
+ const zr = (t, e) => e === 0 ? t : zr(e, t % e), Ft = /* @__NO_SIDE_EFFECTS__ */ (t, e) => t + (e - zr(t, e)), Ct = /* @__PURE__ */ (() => {
455
+ let t = [];
456
+ for (let e = 0; e < 40; e++)
457
+ t.push(2 ** e);
458
+ return t;
459
+ })();
460
+ function xn(t, e, n, r) {
461
+ if (wn(t), e <= 0 || e > 32)
462
+ throw new Error(`convertRadix2: wrong from=${e}`);
463
+ if (n <= 0 || n > 32)
464
+ throw new Error(`convertRadix2: wrong to=${n}`);
465
+ if (/* @__PURE__ */ Ft(e, n) > 32)
466
+ throw new Error(`convertRadix2: carry overflow from=${e} to=${n} carryBits=${/* @__PURE__ */ Ft(e, n)}`);
467
+ let o = 0, s = 0;
468
+ const i = Ct[e], c = Ct[n] - 1, f = [];
469
+ for (const u of t) {
470
+ if (Tn(u), u >= i)
471
+ throw new Error(`convertRadix2: invalid data word=${u} from=${e}`);
472
+ if (o = o << e | u, s + e > 32)
473
+ throw new Error(`convertRadix2: carry overflow pos=${s} from=${e}`);
474
+ for (s += e; s >= n; s -= n)
475
+ f.push((o >> s - n & c) >>> 0);
476
+ const d = Ct[s];
477
+ if (d === void 0)
478
+ throw new Error("invalid carry");
479
+ o &= d - 1;
480
+ }
481
+ if (o = o << n - s & c, !r && s >= e)
482
+ throw new Error("Excess padding");
483
+ if (!r && o > 0)
484
+ throw new Error(`Non-zero padding: ${o}`);
485
+ return r && s > 0 && f.push(o >>> 0), f;
486
+ }
487
+ // @__NO_SIDE_EFFECTS__
488
+ function Nn(t, e = !1) {
489
+ if (Tn(t), t <= 0 || t > 32)
490
+ throw new Error("radix2: bits should be in (0..32]");
491
+ if (/* @__PURE__ */ Ft(8, t) > 32 || /* @__PURE__ */ Ft(t, 8) > 32)
492
+ throw new Error("radix2: carry overflow");
493
+ return {
494
+ encode: (n) => {
495
+ if (!Rn(n))
496
+ throw new Error("radix2.encode input should be Uint8Array");
497
+ return xn(Array.from(n), 8, t, !e);
498
+ },
499
+ decode: (n) => (qr("radix2.decode", n), Uint8Array.from(xn(n, t, 8, e)))
500
+ };
501
+ }
502
+ function ar(t) {
503
+ return gs(t), function(...e) {
504
+ try {
505
+ return t.apply(null, e);
506
+ } catch {
507
+ }
508
+ };
509
+ }
510
+ const ws = typeof Uint8Array.from([]).toBase64 == "function" && typeof Uint8Array.fromBase64 == "function", xs = (t, e) => {
511
+ je("base64", t);
512
+ const n = /^[A-Za-z0-9=+/]+$/, r = "base64";
513
+ if (t.length > 0 && !n.test(t))
514
+ throw new Error("invalid base64");
515
+ return Uint8Array.fromBase64(t, { alphabet: r, lastChunkHandling: "strict" });
516
+ }, Vr = ws ? {
517
+ encode(t) {
518
+ return ps(t), t.toBase64();
519
+ },
520
+ decode(t) {
521
+ return xs(t);
522
+ }
523
+ } : /* @__PURE__ */ Cn(/* @__PURE__ */ Nn(6), /* @__PURE__ */ On("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"), /* @__PURE__ */ bs(6), /* @__PURE__ */ $n("")), se = /* @__PURE__ */ Cn(/* @__PURE__ */ Nn(6), /* @__PURE__ */ On("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"), /* @__PURE__ */ $n("")), En = /* @__PURE__ */ Cn(/* @__PURE__ */ On("qpzry9x8gf2tvdw0s3jn54khce6mua7l"), /* @__PURE__ */ $n("")), ur = [996825010, 642813549, 513874426, 1027748829, 705979059];
524
+ function ft(t) {
525
+ const e = t >> 25;
526
+ let n = (t & 33554431) << 5;
527
+ for (let r = 0; r < ur.length; r++)
528
+ (e >> r & 1) === 1 && (n ^= ur[r]);
529
+ return n;
530
+ }
531
+ function dr(t, e, n = 1) {
532
+ const r = t.length;
533
+ let o = 1;
534
+ for (let s = 0; s < r; s++) {
535
+ const i = t.charCodeAt(s);
536
+ if (i < 33 || i > 126)
537
+ throw new Error(`Invalid prefix (${t})`);
538
+ o = ft(o) ^ i >> 5;
539
+ }
540
+ o = ft(o);
541
+ for (let s = 0; s < r; s++)
542
+ o = ft(o) ^ t.charCodeAt(s) & 31;
543
+ for (let s of e)
544
+ o = ft(o) ^ s;
545
+ for (let s = 0; s < 6; s++)
546
+ o = ft(o);
547
+ return o ^= n, En.encode(xn([o % Ct[30]], 30, 5, !1));
548
+ }
549
+ // @__NO_SIDE_EFFECTS__
550
+ function Es(t) {
551
+ const e = t === "bech32" ? 1 : 734539939, n = /* @__PURE__ */ Nn(5), r = n.decode, o = n.encode, s = ar(r);
552
+ function i(a, y, l = 90) {
553
+ je("bech32.encode prefix", a), Rn(y) && (y = Array.from(y)), qr("bech32.encode", y);
554
+ const b = a.length;
555
+ if (b === 0)
556
+ throw new TypeError(`Invalid prefix length ${b}`);
557
+ const E = b + 7 + y.length;
558
+ if (l !== !1 && E > l)
559
+ throw new TypeError(`Length ${E} exceeds limit ${l}`);
560
+ const x = a.toLowerCase(), w = dr(x, y, e);
561
+ return `${x}1${En.encode(y)}${w}`;
562
+ }
563
+ function c(a, y = 90) {
564
+ je("bech32.decode input", a);
565
+ const l = a.length;
566
+ if (l < 8 || y !== !1 && l > y)
567
+ throw new TypeError(`invalid string length: ${l} (${a}). Expected (8..${y})`);
568
+ const b = a.toLowerCase();
569
+ if (a !== b && a !== a.toUpperCase())
570
+ throw new Error("String must be lowercase or uppercase");
571
+ const E = b.lastIndexOf("1");
572
+ if (E === 0 || E === -1)
573
+ throw new Error('Letter "1" must be present between prefix and data only');
574
+ const x = b.slice(0, E), w = b.slice(E + 1);
575
+ if (w.length < 6)
576
+ throw new Error("Data must be at least 6 characters long");
577
+ const H = En.decode(w).slice(0, -6), k = dr(x, H, e);
578
+ if (!w.endsWith(k))
579
+ throw new Error(`Invalid checksum in ${a}: expected "${k}"`);
580
+ return { prefix: x, words: H };
581
+ }
582
+ const f = ar(c);
583
+ function u(a) {
584
+ const { prefix: y, words: l } = c(a, !1);
585
+ return { prefix: y, words: l, bytes: r(l) };
586
+ }
587
+ function d(a, y) {
588
+ return i(a, o(y));
589
+ }
590
+ return {
591
+ encode: i,
592
+ decode: c,
593
+ encodeFromBytes: d,
594
+ decodeToBytes: u,
595
+ decodeUnsafe: f,
596
+ fromWords: r,
597
+ fromWordsUnsafe: s,
598
+ toWords: o
599
+ };
600
+ }
601
+ const re = /* @__PURE__ */ Es("bech32");
602
+ function ms(t, e, n, r) {
603
+ Zt(t);
604
+ const o = Pr({ dkLen: 32, asyncTick: 10 }, r), { c: s, dkLen: i, asyncTick: c } = o;
605
+ if (de(s, "c"), de(i, "dkLen"), de(c, "asyncTick"), s < 1)
606
+ throw new Error("iterations (c) must be >= 1");
607
+ if (i < 1)
608
+ throw new Error('"dkLen" must be >= 1');
609
+ if (i > (2 ** 32 - 1) * t.outputLen)
610
+ throw new Error("derived key too long");
611
+ const f = ir(e, "password"), u = ir(n, "salt"), d = new Uint8Array(i), a = Et.create(t, f), y = a._cloneInto().update(u);
612
+ return { c: s, dkLen: i, asyncTick: c, DK: d, PRF: a, PRFSalt: y };
613
+ }
614
+ function As(t, e, n, r, o) {
615
+ return t.destroy(), e.destroy(), r && r.destroy(), De(o), n;
616
+ }
617
+ function Gr(t, e, n, r) {
618
+ const { c: o, dkLen: s, DK: i, PRF: c, PRFSalt: f } = ms(t, e, n, r);
619
+ let u;
620
+ const d = new Uint8Array(4), a = Tt(d), y = new Uint8Array(c.outputLen);
621
+ for (let l = 1, b = 0; b < s; l++, b += c.outputLen) {
622
+ const E = i.subarray(b, b + c.outputLen);
623
+ a.setInt32(0, l, !1), (u = f._cloneInto(u)).update(d).digestInto(y), E.set(y.subarray(0, E.length));
624
+ for (let x = 1; x < o; x++) {
625
+ c._cloneInto(u).update(y).digestInto(y);
626
+ for (let w = 0; w < E.length; w++)
627
+ E[w] ^= y[w];
628
+ }
629
+ }
630
+ return As(c, f, i, u, y);
631
+ }
632
+ function lr(t, e, n, r, o, s) {
633
+ let i = t[e++] ^ n[r++], c = t[e++] ^ n[r++], f = t[e++] ^ n[r++], u = t[e++] ^ n[r++], d = t[e++] ^ n[r++], a = t[e++] ^ n[r++], y = t[e++] ^ n[r++], l = t[e++] ^ n[r++], b = t[e++] ^ n[r++], E = t[e++] ^ n[r++], x = t[e++] ^ n[r++], w = t[e++] ^ n[r++], H = t[e++] ^ n[r++], k = t[e++] ^ n[r++], O = t[e++] ^ n[r++], $ = t[e++] ^ n[r++], R = i, N = c, T = f, S = u, M = d, C = a, K = y, v = l, h = b, p = E, A = x, L = w, U = H, m = k, I = O, B = $;
634
+ for (let _ = 0; _ < 8; _ += 2)
635
+ M ^= j(R + U | 0, 7), h ^= j(M + R | 0, 9), U ^= j(h + M | 0, 13), R ^= j(U + h | 0, 18), p ^= j(C + N | 0, 7), m ^= j(p + C | 0, 9), N ^= j(m + p | 0, 13), C ^= j(N + m | 0, 18), I ^= j(A + K | 0, 7), T ^= j(I + A | 0, 9), K ^= j(T + I | 0, 13), A ^= j(K + T | 0, 18), S ^= j(B + L | 0, 7), v ^= j(S + B | 0, 9), L ^= j(v + S | 0, 13), B ^= j(L + v | 0, 18), N ^= j(R + S | 0, 7), T ^= j(N + R | 0, 9), S ^= j(T + N | 0, 13), R ^= j(S + T | 0, 18), K ^= j(C + M | 0, 7), v ^= j(K + C | 0, 9), M ^= j(v + K | 0, 13), C ^= j(M + v | 0, 18), L ^= j(A + p | 0, 7), h ^= j(L + A | 0, 9), p ^= j(h + L | 0, 13), A ^= j(p + h | 0, 18), U ^= j(B + I | 0, 7), m ^= j(U + B | 0, 9), I ^= j(m + U | 0, 13), B ^= j(I + m | 0, 18);
636
+ o[s++] = i + R | 0, o[s++] = c + N | 0, o[s++] = f + T | 0, o[s++] = u + S | 0, o[s++] = d + M | 0, o[s++] = a + C | 0, o[s++] = y + K | 0, o[s++] = l + v | 0, o[s++] = b + h | 0, o[s++] = E + p | 0, o[s++] = x + A | 0, o[s++] = w + L | 0, o[s++] = H + U | 0, o[s++] = k + m | 0, o[s++] = O + I | 0, o[s++] = $ + B | 0;
637
+ }
638
+ function fn(t, e, n, r, o) {
639
+ let s = r + 0, i = r + 16 * o;
640
+ for (let c = 0; c < 16; c++)
641
+ n[i + c] = t[e + (2 * o - 1) * 16 + c];
642
+ for (let c = 0; c < o; c++, s += 16, e += 16)
643
+ lr(n, i, t, e, n, s), c > 0 && (i += 16), lr(n, s, t, e += 16, n, i);
644
+ }
645
+ function Bs(t, e, n) {
646
+ const r = Pr({
647
+ dkLen: 32,
648
+ asyncTick: 10,
649
+ maxmem: 1073742848
650
+ }, n), { N: o, r: s, p: i, dkLen: c, asyncTick: f, maxmem: u, onProgress: d } = r;
651
+ if (de(o, "N"), de(s, "r"), de(i, "p"), de(c, "dkLen"), de(f, "asyncTick"), de(u, "maxmem"), d !== void 0 && typeof d != "function")
652
+ throw new Error("progressCb must be a function");
653
+ const a = 128 * s, y = a / 4, l = Math.pow(2, 32);
654
+ if (o <= 1 || (o & o - 1) !== 0 || o > l)
655
+ throw new Error('"N" expected a power of 2, and 2^1 <= N <= 2^32');
656
+ if (i < 1 || i > (l - 1) * 32 / a)
657
+ throw new Error('"p" expected integer 1..((2^32 - 1) * 32) / (128 * r)');
658
+ if (c < 1 || c > (l - 1) * 32)
659
+ throw new Error('"dkLen" expected integer 1..(2^32 - 1) * 32');
660
+ const b = a * (o + i + 1);
661
+ if (b > u)
662
+ throw new Error('"maxmem" limit was hit: memUsed(128*r*(N+p+1))=' + b + ", maxmem=" + u);
663
+ const E = Gr(ee, t, e, { c: 1, dkLen: a * i }), x = sn(E), w = sn(new Uint8Array(a * o)), H = sn(new Uint8Array(a));
664
+ let k = () => {
665
+ };
666
+ if (d) {
667
+ const O = 2 * o * i, $ = Math.max(Math.floor(O / 1e4), 1);
668
+ let R = 0;
669
+ k = () => {
670
+ R++, d && (!(R % $) || R === O) && d(R / O);
671
+ };
672
+ }
673
+ return { N: o, r: s, p: i, dkLen: c, blockSize32: y, V: w, B32: x, B: E, tmp: H, blockMixCb: k, asyncTick: f };
674
+ }
675
+ function Ls(t, e, n, r, o) {
676
+ const s = Gr(ee, t, n, { c: 1, dkLen: e });
677
+ return De(n, r, o), s;
678
+ }
679
+ function Yr(t, e, n) {
680
+ const { N: r, r: o, p: s, dkLen: i, blockSize32: c, V: f, B32: u, B: d, tmp: a, blockMixCb: y } = Bs(t, e, n);
681
+ sr(u);
682
+ for (let l = 0; l < s; l++) {
683
+ const b = c * l;
684
+ for (let E = 0; E < c; E++)
685
+ f[E] = u[b + E];
686
+ for (let E = 0, x = 0; E < r - 1; E++)
687
+ fn(f, x, f, x += c, o), y();
688
+ fn(f, (r - 1) * c, u, b, o), y();
689
+ for (let E = 0; E < r; E++) {
690
+ const x = (u[b + c - 16] & r - 1) >>> 0;
691
+ for (let w = 0; w < c; w++)
692
+ a[w] = u[b + w] ^ f[x * c + w];
693
+ fn(a, 0, u, b, o), y();
694
+ }
695
+ }
696
+ return sr(u), Ls(t, i, d, f, a);
697
+ }
698
+ /*! noble-ciphers - MIT License (c) 2023 Paul Miller (paulmillr.com) */
699
+ function Ss(t) {
700
+ return t instanceof Uint8Array || ArrayBuffer.isView(t) && t.constructor.name === "Uint8Array" && "BYTES_PER_ELEMENT" in t && t.BYTES_PER_ELEMENT === 1;
701
+ }
702
+ function mn(t) {
703
+ if (typeof t != "boolean")
704
+ throw new TypeError(`boolean expected, not ${t}`);
705
+ }
706
+ function yt(t) {
707
+ if (typeof t != "number")
708
+ throw new TypeError("number expected, got " + typeof t);
709
+ if (!Number.isSafeInteger(t) || t < 0)
710
+ throw new RangeError("positive integer expected, got " + t);
711
+ }
712
+ function ne(t, e, n = "") {
713
+ const r = Ss(t), o = t == null ? void 0 : t.length, s = e !== void 0;
714
+ if (!r || s && o !== e) {
715
+ const i = n && `"${n}" `, c = s ? ` of length ${e}` : "", f = r ? `length=${o}` : `type=${typeof t}`, u = i + "expected Uint8Array" + c + ", got " + f;
716
+ throw r ? new RangeError(u) : new TypeError(u);
717
+ }
718
+ return t;
719
+ }
720
+ function hr(t, e = !0) {
721
+ if (t.destroyed)
722
+ throw new Error("Hash instance has been destroyed");
723
+ if (e && t.finished)
724
+ throw new Error("Hash#digest() has already been called");
725
+ }
726
+ function Hs(t, e, n = !1) {
727
+ ne(t, void 0, "output");
728
+ const r = e.outputLen;
729
+ if (t.length < r)
730
+ throw new RangeError("digestInto() expects output buffer of length at least " + r);
731
+ if (n && !bt(t))
732
+ throw new Error("invalid output, must be aligned");
733
+ }
734
+ function xe(t) {
735
+ return new Uint32Array(t.buffer, t.byteOffset, Math.floor(t.byteLength / 4));
736
+ }
737
+ function Ke(...t) {
738
+ for (let e = 0; e < t.length; e++)
739
+ t[e].fill(0);
740
+ }
741
+ function Us(t) {
742
+ return new DataView(t.buffer, t.byteOffset, t.byteLength);
743
+ }
744
+ const Je = new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68, Is = (t) => t << 24 & 4278190080 | t << 8 & 16711680 | t >>> 8 & 65280 | t >>> 24 & 255, ks = (t) => {
745
+ for (let e = 0; e < t.length; e++)
746
+ t[e] = Is(t[e]);
747
+ return t;
748
+ }, Ne = Je ? (t) => t : ks;
749
+ function _s(t, e) {
750
+ if (e == null || typeof e != "object")
751
+ throw new Error("options must be defined");
752
+ return Object.assign(t, e);
753
+ }
754
+ function Ks(t, e) {
755
+ if (t.length !== e.length)
756
+ return !1;
757
+ let n = 0;
758
+ for (let r = 0; r < t.length; r++)
759
+ n |= t[r] ^ e[r];
760
+ return n === 0;
761
+ }
762
+ function vs(t, e, n) {
763
+ const r = e, o = (() => []), s = (c, f) => r(f, ...o(c)).update(c).digest(), i = r(new Uint8Array(t), ...o(new Uint8Array(0)));
764
+ return s.outputLen = i.outputLen, s.blockLen = i.blockLen, s.create = (c, ...f) => r(c, ...f), s;
765
+ }
766
+ const Rs = /* @__NO_SIDE_EFFECTS__ */ (t, e) => {
767
+ function n(r, ...o) {
768
+ if (ne(r, void 0, "key"), t.nonceLength !== void 0) {
769
+ const d = o[0];
770
+ ne(d, t.varSizeNonce ? void 0 : t.nonceLength, "nonce");
771
+ }
772
+ const s = t.tagLength;
773
+ s && o[1] !== void 0 && ne(o[1], void 0, "AAD");
774
+ const i = e(r, ...o), c = (d, a) => {
775
+ if (a !== void 0) {
776
+ if (d !== 2)
777
+ throw new Error("cipher output not supported");
778
+ ne(a, void 0, "output");
779
+ }
780
+ };
781
+ let f = !1;
782
+ return {
783
+ encrypt(d, a) {
784
+ if (f)
785
+ throw new Error("cannot encrypt() twice with same key + nonce");
786
+ return f = !0, ne(d), c(i.encrypt.length, a), i.encrypt(d, a);
787
+ },
788
+ decrypt(d, a) {
789
+ if (ne(d), s && d.length < s)
790
+ throw new Error('"ciphertext" expected length bigger than tagLength=' + s);
791
+ return c(i.decrypt.length, a), i.decrypt(d, a);
792
+ }
793
+ };
794
+ }
795
+ return Object.assign(n, t), n;
796
+ };
797
+ function An(t, e, n = !0) {
798
+ if (e === void 0)
799
+ return new Uint8Array(t);
800
+ if (ne(e, void 0, "output"), e.length !== t)
801
+ throw new Error('"output" expected Uint8Array of length ' + t + ", got: " + e.length);
802
+ if (n && !bt(e))
803
+ throw new Error("invalid output, must be aligned");
804
+ return e;
805
+ }
806
+ function Ts(t, e, n) {
807
+ yt(t), yt(e), mn(n);
808
+ const r = new Uint8Array(16), o = Us(r);
809
+ return o.setBigUint64(0, BigInt(e), n), o.setBigUint64(8, BigInt(t), n), r;
810
+ }
811
+ function bt(t) {
812
+ return t.byteOffset % 4 === 0;
813
+ }
814
+ function Pt(t) {
815
+ return Uint8Array.from(ne(t));
816
+ }
817
+ const Zr = (t) => Uint8Array.from(t.split(""), (e) => e.charCodeAt(0)), Cs = Ne(xe(Zr("expand 16-byte k"))), Os = Ne(xe(Zr("expand 32-byte k")));
818
+ function q(t, e) {
819
+ return t << e | t >>> 32 - e;
820
+ }
821
+ const at = 64, $s = 16, Bn = 2 ** 32 - 1, yr = /* @__PURE__ */ Uint32Array.of();
822
+ function Ns(t, e, n, r, o, s, i, c) {
823
+ const f = o.length, u = new Uint8Array(at), d = xe(u), a = Je && bt(o) && bt(s), y = a ? xe(o) : yr, l = a ? xe(s) : yr;
824
+ if (!Je) {
825
+ for (let b = 0; b < f; i++) {
826
+ if (t(e, n, r, d, i, c), Ne(d), i >= Bn)
827
+ throw new Error("arx: counter overflow");
828
+ const E = Math.min(at, f - b);
829
+ for (let x = 0, w; x < E; x++)
830
+ w = b + x, s[w] = o[w] ^ u[x];
831
+ b += E;
832
+ }
833
+ return;
834
+ }
835
+ for (let b = 0; b < f; i++) {
836
+ if (t(e, n, r, d, i, c), i >= Bn)
837
+ throw new Error("arx: counter overflow");
838
+ const E = Math.min(at, f - b);
839
+ if (a && E === at) {
840
+ const x = b / 4;
841
+ if (b % 4 !== 0)
842
+ throw new Error("arx: invalid block position");
843
+ for (let w = 0, H; w < $s; w++)
844
+ H = x + w, l[H] = y[H] ^ d[w];
845
+ b += at;
846
+ continue;
847
+ }
848
+ for (let x = 0, w; x < E; x++)
849
+ w = b + x, s[w] = o[w] ^ u[x];
850
+ b += E;
851
+ }
852
+ }
853
+ function Ms(t, e) {
854
+ const { allowShortKeys: n, extendNonceFn: r, counterLength: o, counterRight: s, rounds: i } = _s({ allowShortKeys: !1, counterLength: 8, counterRight: !1, rounds: 20 }, e);
855
+ if (typeof t != "function")
856
+ throw new Error("core must be a function");
857
+ return yt(o), yt(i), mn(s), mn(n), (c, f, u, d, a = 0) => {
858
+ ne(c, void 0, "key"), ne(f, void 0, "nonce"), ne(u, void 0, "data");
859
+ const y = u.length;
860
+ if (d = An(y, d, !1), yt(a), a < 0 || a >= Bn)
861
+ throw new Error("arx: counter overflow");
862
+ const l = [];
863
+ let b = c.length, E, x;
864
+ if (b === 32)
865
+ l.push(E = Pt(c)), x = Os;
866
+ else if (b === 16 && n)
867
+ E = new Uint8Array(32), E.set(c), E.set(c, 16), x = Cs, l.push(E);
868
+ else
869
+ throw ne(c, 32, "arx key"), new Error("invalid key size");
870
+ (!Je || !bt(f)) && l.push(f = Pt(f));
871
+ let w = xe(E);
872
+ if (r) {
873
+ if (f.length !== 24)
874
+ throw new Error("arx: extended nonce must be 24 bytes");
875
+ const O = f.subarray(0, 16);
876
+ if (Je)
877
+ r(x, w, xe(O), w);
878
+ else {
879
+ const $ = Ne(Uint32Array.from(x));
880
+ r($, w, xe(O), w), Ke($), Ne(w);
881
+ }
882
+ f = f.subarray(16);
883
+ } else Je || Ne(w);
884
+ const H = 16 - o;
885
+ if (H !== f.length)
886
+ throw new Error(`arx: nonce must be ${H} or 16 bytes`);
887
+ if (H !== 12) {
888
+ const O = new Uint8Array(12);
889
+ O.set(f, s ? 0 : 12 - f.length), f = O, l.push(f);
890
+ }
891
+ const k = Ne(xe(f));
892
+ try {
893
+ return Ns(t, x, w, k, u, d, a, i), d;
894
+ } finally {
895
+ Ke(...l);
896
+ }
897
+ };
898
+ }
899
+ function J(t, e) {
900
+ return t[e++] & 255 | (t[e++] & 255) << 8;
901
+ }
902
+ class Fs {
903
+ // Can be speed-up using BigUint64Array, at the cost of complexity
904
+ constructor(e) {
905
+ g(this, "blockLen", 16);
906
+ g(this, "outputLen", 16);
907
+ g(this, "buffer", new Uint8Array(16));
908
+ g(this, "r", new Uint16Array(10));
909
+ // Allocating 1 array with .subarray() here is slower than 3
910
+ g(this, "h", new Uint16Array(10));
911
+ g(this, "pad", new Uint16Array(8));
912
+ g(this, "pos", 0);
913
+ g(this, "finished", !1);
914
+ g(this, "destroyed", !1);
915
+ e = Pt(ne(e, 32, "key"));
916
+ const n = J(e, 0), r = J(e, 2), o = J(e, 4), s = J(e, 6), i = J(e, 8), c = J(e, 10), f = J(e, 12), u = J(e, 14);
917
+ this.r[0] = n & 8191, this.r[1] = (n >>> 13 | r << 3) & 8191, this.r[2] = (r >>> 10 | o << 6) & 7939, this.r[3] = (o >>> 7 | s << 9) & 8191, this.r[4] = (s >>> 4 | i << 12) & 255, this.r[5] = i >>> 1 & 8190, this.r[6] = (i >>> 14 | c << 2) & 8191, this.r[7] = (c >>> 11 | f << 5) & 8065, this.r[8] = (f >>> 8 | u << 8) & 8191, this.r[9] = u >>> 5 & 127;
918
+ for (let d = 0; d < 8; d++)
919
+ this.pad[d] = J(e, 16 + 2 * d);
920
+ }
921
+ process(e, n, r = !1) {
922
+ const o = r ? 0 : 2048, { h: s, r: i } = this, c = i[0], f = i[1], u = i[2], d = i[3], a = i[4], y = i[5], l = i[6], b = i[7], E = i[8], x = i[9], w = J(e, n + 0), H = J(e, n + 2), k = J(e, n + 4), O = J(e, n + 6), $ = J(e, n + 8), R = J(e, n + 10), N = J(e, n + 12), T = J(e, n + 14);
923
+ let S = s[0] + (w & 8191), M = s[1] + ((w >>> 13 | H << 3) & 8191), C = s[2] + ((H >>> 10 | k << 6) & 8191), K = s[3] + ((k >>> 7 | O << 9) & 8191), v = s[4] + ((O >>> 4 | $ << 12) & 8191), h = s[5] + ($ >>> 1 & 8191), p = s[6] + (($ >>> 14 | R << 2) & 8191), A = s[7] + ((R >>> 11 | N << 5) & 8191), L = s[8] + ((N >>> 8 | T << 8) & 8191), U = s[9] + (T >>> 5 | o), m = 0, I = m + S * c + M * (5 * x) + C * (5 * E) + K * (5 * b) + v * (5 * l);
924
+ m = I >>> 13, I &= 8191, I += h * (5 * y) + p * (5 * a) + A * (5 * d) + L * (5 * u) + U * (5 * f), m += I >>> 13, I &= 8191;
925
+ let B = m + S * f + M * c + C * (5 * x) + K * (5 * E) + v * (5 * b);
926
+ m = B >>> 13, B &= 8191, B += h * (5 * l) + p * (5 * y) + A * (5 * a) + L * (5 * d) + U * (5 * u), m += B >>> 13, B &= 8191;
927
+ let _ = m + S * u + M * f + C * c + K * (5 * x) + v * (5 * E);
928
+ m = _ >>> 13, _ &= 8191, _ += h * (5 * b) + p * (5 * l) + A * (5 * y) + L * (5 * a) + U * (5 * d), m += _ >>> 13, _ &= 8191;
929
+ let P = m + S * d + M * u + C * f + K * c + v * (5 * x);
930
+ m = P >>> 13, P &= 8191, P += h * (5 * E) + p * (5 * b) + A * (5 * l) + L * (5 * y) + U * (5 * a), m += P >>> 13, P &= 8191;
931
+ let z = m + S * a + M * d + C * u + K * f + v * c;
932
+ m = z >>> 13, z &= 8191, z += h * (5 * x) + p * (5 * E) + A * (5 * b) + L * (5 * l) + U * (5 * y), m += z >>> 13, z &= 8191;
933
+ let D = m + S * y + M * a + C * d + K * u + v * f;
934
+ m = D >>> 13, D &= 8191, D += h * c + p * (5 * x) + A * (5 * E) + L * (5 * b) + U * (5 * l), m += D >>> 13, D &= 8191;
935
+ let F = m + S * l + M * y + C * a + K * d + v * u;
936
+ m = F >>> 13, F &= 8191, F += h * f + p * c + A * (5 * x) + L * (5 * E) + U * (5 * b), m += F >>> 13, F &= 8191;
937
+ let V = m + S * b + M * l + C * y + K * a + v * d;
938
+ m = V >>> 13, V &= 8191, V += h * u + p * f + A * c + L * (5 * x) + U * (5 * E), m += V >>> 13, V &= 8191;
939
+ let G = m + S * E + M * b + C * l + K * y + v * a;
940
+ m = G >>> 13, G &= 8191, G += h * d + p * u + A * f + L * c + U * (5 * x), m += G >>> 13, G &= 8191;
941
+ let X = m + S * x + M * E + C * b + K * l + v * y;
942
+ m = X >>> 13, X &= 8191, X += h * a + p * d + A * u + L * f + U * c, m += X >>> 13, X &= 8191, m = (m << 2) + m | 0, m = m + I | 0, I = m & 8191, m = m >>> 13, B += m, s[0] = I, s[1] = B, s[2] = _, s[3] = P, s[4] = z, s[5] = D, s[6] = F, s[7] = V, s[8] = G, s[9] = X;
943
+ }
944
+ finalize() {
945
+ const { h: e, pad: n } = this, r = new Uint16Array(10);
946
+ let o = e[1] >>> 13;
947
+ e[1] &= 8191;
948
+ for (let c = 2; c < 10; c++)
949
+ e[c] += o, o = e[c] >>> 13, e[c] &= 8191;
950
+ e[0] += o * 5, o = e[0] >>> 13, e[0] &= 8191, e[1] += o, o = e[1] >>> 13, e[1] &= 8191, e[2] += o, r[0] = e[0] + 5, o = r[0] >>> 13, r[0] &= 8191;
951
+ for (let c = 1; c < 10; c++)
952
+ r[c] = e[c] + o, o = r[c] >>> 13, r[c] &= 8191;
953
+ r[9] -= 8192;
954
+ let s = (o ^ 1) - 1;
955
+ for (let c = 0; c < 10; c++)
956
+ r[c] &= s;
957
+ s = ~s;
958
+ for (let c = 0; c < 10; c++)
959
+ e[c] = e[c] & s | r[c];
960
+ e[0] = (e[0] | e[1] << 13) & 65535, e[1] = (e[1] >>> 3 | e[2] << 10) & 65535, e[2] = (e[2] >>> 6 | e[3] << 7) & 65535, e[3] = (e[3] >>> 9 | e[4] << 4) & 65535, e[4] = (e[4] >>> 12 | e[5] << 1 | e[6] << 14) & 65535, e[5] = (e[6] >>> 2 | e[7] << 11) & 65535, e[6] = (e[7] >>> 5 | e[8] << 8) & 65535, e[7] = (e[8] >>> 8 | e[9] << 5) & 65535;
961
+ let i = e[0] + n[0];
962
+ e[0] = i & 65535;
963
+ for (let c = 1; c < 8; c++)
964
+ i = (e[c] + n[c] | 0) + (i >>> 16) | 0, e[c] = i & 65535;
965
+ Ke(r);
966
+ }
967
+ update(e) {
968
+ hr(this), ne(e), e = Pt(e);
969
+ const { buffer: n, blockLen: r } = this, o = e.length;
970
+ for (let s = 0; s < o; ) {
971
+ const i = Math.min(r - this.pos, o - s);
972
+ if (i === r) {
973
+ for (; r <= o - s; s += r)
974
+ this.process(e, s);
975
+ continue;
976
+ }
977
+ n.set(e.subarray(s, s + i), this.pos), this.pos += i, s += i, this.pos === r && (this.process(n, 0, !1), this.pos = 0);
978
+ }
979
+ return this;
980
+ }
981
+ destroy() {
982
+ this.destroyed = !0, Ke(this.h, this.r, this.buffer, this.pad);
983
+ }
984
+ digestInto(e) {
985
+ hr(this), Hs(e, this), this.finished = !0;
986
+ const { buffer: n, h: r } = this;
987
+ let { pos: o } = this;
988
+ if (o) {
989
+ for (n[o++] = 1; o < 16; o++)
990
+ n[o] = 0;
991
+ this.process(n, 0, !0);
992
+ }
993
+ this.finalize();
994
+ let s = 0;
995
+ for (let i = 0; i < 8; i++)
996
+ e[s++] = r[i] >>> 0, e[s++] = r[i] >>> 8;
997
+ }
998
+ digest() {
999
+ const { buffer: e, outputLen: n } = this;
1000
+ this.digestInto(e);
1001
+ const r = e.slice(0, n);
1002
+ return this.destroy(), r;
1003
+ }
1004
+ }
1005
+ const Ps = /* @__PURE__ */ vs(32, (t) => new Fs(t));
1006
+ function Ds(t, e, n, r, o, s = 20) {
1007
+ let i = t[0], c = t[1], f = t[2], u = t[3], d = e[0], a = e[1], y = e[2], l = e[3], b = e[4], E = e[5], x = e[6], w = e[7], H = o, k = n[0], O = n[1], $ = n[2], R = i, N = c, T = f, S = u, M = d, C = a, K = y, v = l, h = b, p = E, A = x, L = w, U = H, m = k, I = O, B = $;
1008
+ for (let P = 0; P < s; P += 2)
1009
+ R = R + M | 0, U = q(U ^ R, 16), h = h + U | 0, M = q(M ^ h, 12), R = R + M | 0, U = q(U ^ R, 8), h = h + U | 0, M = q(M ^ h, 7), N = N + C | 0, m = q(m ^ N, 16), p = p + m | 0, C = q(C ^ p, 12), N = N + C | 0, m = q(m ^ N, 8), p = p + m | 0, C = q(C ^ p, 7), T = T + K | 0, I = q(I ^ T, 16), A = A + I | 0, K = q(K ^ A, 12), T = T + K | 0, I = q(I ^ T, 8), A = A + I | 0, K = q(K ^ A, 7), S = S + v | 0, B = q(B ^ S, 16), L = L + B | 0, v = q(v ^ L, 12), S = S + v | 0, B = q(B ^ S, 8), L = L + B | 0, v = q(v ^ L, 7), R = R + C | 0, B = q(B ^ R, 16), A = A + B | 0, C = q(C ^ A, 12), R = R + C | 0, B = q(B ^ R, 8), A = A + B | 0, C = q(C ^ A, 7), N = N + K | 0, U = q(U ^ N, 16), L = L + U | 0, K = q(K ^ L, 12), N = N + K | 0, U = q(U ^ N, 8), L = L + U | 0, K = q(K ^ L, 7), T = T + v | 0, m = q(m ^ T, 16), h = h + m | 0, v = q(v ^ h, 12), T = T + v | 0, m = q(m ^ T, 8), h = h + m | 0, v = q(v ^ h, 7), S = S + M | 0, I = q(I ^ S, 16), p = p + I | 0, M = q(M ^ p, 12), S = S + M | 0, I = q(I ^ S, 8), p = p + I | 0, M = q(M ^ p, 7);
1010
+ let _ = 0;
1011
+ r[_++] = i + R | 0, r[_++] = c + N | 0, r[_++] = f + T | 0, r[_++] = u + S | 0, r[_++] = d + M | 0, r[_++] = a + C | 0, r[_++] = y + K | 0, r[_++] = l + v | 0, r[_++] = b + h | 0, r[_++] = E + p | 0, r[_++] = x + A | 0, r[_++] = w + L | 0, r[_++] = H + U | 0, r[_++] = k + m | 0, r[_++] = O + I | 0, r[_++] = $ + B | 0;
1012
+ }
1013
+ const js = /* @__PURE__ */ Ms(Ds, {
1014
+ counterRight: !1,
1015
+ counterLength: 4,
1016
+ allowShortKeys: !1
1017
+ }), qs = /* @__PURE__ */ new Uint8Array(16), pr = (t, e) => {
1018
+ t.update(e);
1019
+ const n = e.length % 16;
1020
+ n && t.update(qs.subarray(n));
1021
+ }, zs = /* @__PURE__ */ new Uint8Array(32);
1022
+ function gr(t, e, n, r, o) {
1023
+ o !== void 0 && ne(o, void 0, "AAD");
1024
+ const s = t(e, n, zs), i = Ts(r.length, o ? o.length : 0, !0), c = Ps.create(s);
1025
+ o && pr(c, o), pr(c, r), c.update(i);
1026
+ const f = c.digest();
1027
+ return Ke(s, i), f;
1028
+ }
1029
+ const Vs = (t) => (e, n, r) => ({
1030
+ encrypt(s, i) {
1031
+ const c = s.length;
1032
+ i = An(c + 16, i, !1), i.set(s);
1033
+ const f = i.subarray(0, -16);
1034
+ t(e, n, f, f, 1);
1035
+ const u = gr(t, e, n, f, r);
1036
+ return i.set(u, c), Ke(u), i;
1037
+ },
1038
+ decrypt(s, i) {
1039
+ i = An(s.length - 16, i, !1);
1040
+ const c = s.subarray(0, -16), f = s.subarray(-16), u = gr(t, e, n, c, r);
1041
+ if (!Ks(f, u))
1042
+ throw Ke(u), new Error("invalid tag");
1043
+ return i.set(s.subarray(0, -16)), t(e, n, i, i, 1), Ke(u), i;
1044
+ }
1045
+ }), ge = /* @__PURE__ */ Rs(
1046
+ { blockSize: 64, nonceLength: 12, tagLength: 16 },
1047
+ /* @__PURE__ */ Vs(js)
1048
+ );
1049
+ /*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
1050
+ function Mn(t) {
1051
+ return t instanceof Uint8Array || ArrayBuffer.isView(t) && t.constructor.name === "Uint8Array";
1052
+ }
1053
+ function qe(t, e = "") {
1054
+ if (!Number.isSafeInteger(t) || t < 0) {
1055
+ const n = e && `"${e}" `;
1056
+ throw new Error(`${n}expected integer >= 0, got ${t}`);
1057
+ }
1058
+ }
1059
+ function Z(t, e, n = "") {
1060
+ const r = Mn(t), o = t == null ? void 0 : t.length, s = e !== void 0;
1061
+ if (!r || s && o !== e) {
1062
+ const i = n && `"${n}" `, c = s ? ` of length ${e}` : "", f = r ? `length=${o}` : `type=${typeof t}`;
1063
+ throw new Error(i + "expected Uint8Array" + c + ", got " + f);
1064
+ }
1065
+ return t;
1066
+ }
1067
+ function Xr(t) {
1068
+ if (typeof t != "function" || typeof t.create != "function")
1069
+ throw new Error("Hash must wrapped by utils.createHasher");
1070
+ qe(t.outputLen), qe(t.blockLen);
1071
+ }
1072
+ function Dt(t, e = !0) {
1073
+ if (t.destroyed)
1074
+ throw new Error("Hash instance has been destroyed");
1075
+ if (e && t.finished)
1076
+ throw new Error("Hash#digest() has already been called");
1077
+ }
1078
+ function Gs(t, e) {
1079
+ Z(t, void 0, "digestInto() output");
1080
+ const n = e.outputLen;
1081
+ if (t.length < n)
1082
+ throw new Error('"digestInto() output" expected to be of length >=' + n);
1083
+ }
1084
+ function ot(...t) {
1085
+ for (let e = 0; e < t.length; e++)
1086
+ t[e].fill(0);
1087
+ }
1088
+ function an(t) {
1089
+ return new DataView(t.buffer, t.byteOffset, t.byteLength);
1090
+ }
1091
+ function ye(t, e) {
1092
+ return t << 32 - e | t >>> e;
1093
+ }
1094
+ const Wr = /* @ts-ignore */ typeof Uint8Array.from([]).toHex == "function" && typeof Uint8Array.fromHex == "function", Ys = /* @__PURE__ */ Array.from({ length: 256 }, (t, e) => e.toString(16).padStart(2, "0"));
1095
+ function Xt(t) {
1096
+ if (Z(t), Wr)
1097
+ return t.toHex();
1098
+ let e = "";
1099
+ for (let n = 0; n < t.length; n++)
1100
+ e += Ys[t[n]];
1101
+ return e;
1102
+ }
1103
+ const be = { _0: 48, _9: 57, A: 65, F: 70, a: 97, f: 102 };
1104
+ function br(t) {
1105
+ if (t >= be._0 && t <= be._9)
1106
+ return t - be._0;
1107
+ if (t >= be.A && t <= be.F)
1108
+ return t - (be.A - 10);
1109
+ if (t >= be.a && t <= be.f)
1110
+ return t - (be.a - 10);
1111
+ }
1112
+ function jt(t) {
1113
+ if (typeof t != "string")
1114
+ throw new Error("hex string expected, got " + typeof t);
1115
+ if (Wr)
1116
+ return Uint8Array.fromHex(t);
1117
+ const e = t.length, n = e / 2;
1118
+ if (e % 2)
1119
+ throw new Error("hex string expected, got unpadded hex of length " + e);
1120
+ const r = new Uint8Array(n);
1121
+ for (let o = 0, s = 0; o < n; o++, s += 2) {
1122
+ const i = br(t.charCodeAt(s)), c = br(t.charCodeAt(s + 1));
1123
+ if (i === void 0 || c === void 0) {
1124
+ const f = t[s] + t[s + 1];
1125
+ throw new Error('hex string expected, got non-hex character "' + f + '" at index ' + s);
1126
+ }
1127
+ r[o] = i * 16 + c;
1128
+ }
1129
+ return r;
1130
+ }
1131
+ function ie(...t) {
1132
+ let e = 0;
1133
+ for (let r = 0; r < t.length; r++) {
1134
+ const o = t[r];
1135
+ Z(o), e += o.length;
1136
+ }
1137
+ const n = new Uint8Array(e);
1138
+ for (let r = 0, o = 0; r < t.length; r++) {
1139
+ const s = t[r];
1140
+ n.set(s, o), o += s.length;
1141
+ }
1142
+ return n;
1143
+ }
1144
+ function Qr(t, e = {}) {
1145
+ const n = (o, s) => t(s).update(o).digest(), r = t(void 0);
1146
+ return n.outputLen = r.outputLen, n.blockLen = r.blockLen, n.create = (o) => t(o), Object.assign(n, e), Object.freeze(n);
1147
+ }
1148
+ function Fn(t = 32) {
1149
+ const e = typeof globalThis == "object" ? globalThis.crypto : null;
1150
+ if (typeof (e == null ? void 0 : e.getRandomValues) != "function")
1151
+ throw new Error("crypto.getRandomValues must be defined");
1152
+ return e.getRandomValues(new Uint8Array(t));
1153
+ }
1154
+ const Jr = (t) => ({
1155
+ oid: Uint8Array.from([6, 9, 96, 134, 72, 1, 101, 3, 4, 2, t])
1156
+ });
1157
+ /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
1158
+ const Pn = /* @__PURE__ */ BigInt(0), Ln = /* @__PURE__ */ BigInt(1);
1159
+ function qt(t, e = "") {
1160
+ if (typeof t != "boolean") {
1161
+ const n = e && `"${e}" `;
1162
+ throw new Error(n + "expected boolean, got type=" + typeof t);
1163
+ }
1164
+ return t;
1165
+ }
1166
+ function eo(t) {
1167
+ if (typeof t == "bigint") {
1168
+ if (!Ot(t))
1169
+ throw new Error("positive bigint expected, got " + t);
1170
+ } else
1171
+ qe(t);
1172
+ return t;
1173
+ }
1174
+ function Ht(t) {
1175
+ const e = eo(t).toString(16);
1176
+ return e.length & 1 ? "0" + e : e;
1177
+ }
1178
+ function to(t) {
1179
+ if (typeof t != "string")
1180
+ throw new Error("hex string expected, got " + typeof t);
1181
+ return t === "" ? Pn : BigInt("0x" + t);
1182
+ }
1183
+ function At(t) {
1184
+ return to(Xt(t));
1185
+ }
1186
+ function wt(t) {
1187
+ return to(Xt(Sn(Z(t)).reverse()));
1188
+ }
1189
+ function Wt(t, e) {
1190
+ qe(e), t = eo(t);
1191
+ const n = jt(t.toString(16).padStart(e * 2, "0"));
1192
+ if (n.length !== e)
1193
+ throw new Error("number too large");
1194
+ return n;
1195
+ }
1196
+ function Dn(t, e) {
1197
+ return Wt(t, e).reverse();
1198
+ }
1199
+ function Sn(t) {
1200
+ return Uint8Array.from(t);
1201
+ }
1202
+ function Me(t) {
1203
+ return Uint8Array.from(t, (e, n) => {
1204
+ const r = e.charCodeAt(0);
1205
+ if (e.length !== 1 || r > 127)
1206
+ throw new Error(`string contains non-ASCII character "${t[n]}" with code ${r} at position ${n}`);
1207
+ return r;
1208
+ });
1209
+ }
1210
+ const Ot = (t) => typeof t == "bigint" && Pn <= t;
1211
+ function Zs(t, e, n) {
1212
+ return Ot(t) && Ot(e) && Ot(n) && e <= t && t < n;
1213
+ }
1214
+ function Hn(t, e, n, r) {
1215
+ if (!Zs(e, n, r))
1216
+ throw new Error("expected valid " + t + ": " + n + " <= n < " + r + ", got " + e);
1217
+ }
1218
+ function Xs(t) {
1219
+ let e;
1220
+ for (e = 0; t > Pn; t >>= Ln, e += 1)
1221
+ ;
1222
+ return e;
1223
+ }
1224
+ const jn = (t) => (Ln << BigInt(t)) - Ln;
1225
+ function Ws(t, e, n) {
1226
+ if (qe(t, "hashLen"), qe(e, "qByteLen"), typeof n != "function")
1227
+ throw new Error("hmacFn must be a function");
1228
+ const r = (x) => new Uint8Array(x), o = Uint8Array.of(), s = Uint8Array.of(0), i = Uint8Array.of(1), c = 1e3;
1229
+ let f = r(t), u = r(t), d = 0;
1230
+ const a = () => {
1231
+ f.fill(1), u.fill(0), d = 0;
1232
+ }, y = (...x) => n(u, ie(f, ...x)), l = (x = o) => {
1233
+ u = y(s, x), f = y(), x.length !== 0 && (u = y(i, x), f = y());
1234
+ }, b = () => {
1235
+ if (d++ >= c)
1236
+ throw new Error("drbg: tried max amount of iterations");
1237
+ let x = 0;
1238
+ const w = [];
1239
+ for (; x < e; ) {
1240
+ f = y();
1241
+ const H = f.slice();
1242
+ w.push(H), x += f.length;
1243
+ }
1244
+ return ie(...w);
1245
+ };
1246
+ return (x, w) => {
1247
+ a(), l(x);
1248
+ let H;
1249
+ for (; !(H = w(b())); )
1250
+ l();
1251
+ return a(), H;
1252
+ };
1253
+ }
1254
+ function Qt(t, e = {}, n = {}) {
1255
+ if (!t || typeof t != "object")
1256
+ throw new Error("expected valid options object");
1257
+ function r(s, i, c) {
1258
+ const f = t[s];
1259
+ if (c && f === void 0)
1260
+ return;
1261
+ const u = typeof f;
1262
+ if (u !== i || f === null)
1263
+ throw new Error(`param "${s}" is invalid: expected ${i}, got ${u}`);
1264
+ }
1265
+ const o = (s, i) => Object.entries(s).forEach(([c, f]) => r(c, f, i));
1266
+ o(e, !1), o(n, !0);
1267
+ }
1268
+ function wr(t) {
1269
+ const e = /* @__PURE__ */ new WeakMap();
1270
+ return (n, ...r) => {
1271
+ const o = e.get(n);
1272
+ if (o !== void 0)
1273
+ return o;
1274
+ const s = t(n, ...r);
1275
+ return e.set(n, s), s;
1276
+ };
1277
+ }
1278
+ /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
1279
+ const ae = /* @__PURE__ */ BigInt(0), fe = /* @__PURE__ */ BigInt(1), Fe = /* @__PURE__ */ BigInt(2), no = /* @__PURE__ */ BigInt(3), ro = /* @__PURE__ */ BigInt(4), oo = /* @__PURE__ */ BigInt(5), Qs = /* @__PURE__ */ BigInt(7), so = /* @__PURE__ */ BigInt(8), Js = /* @__PURE__ */ BigInt(9), io = /* @__PURE__ */ BigInt(16);
1280
+ function ue(t, e) {
1281
+ const n = t % e;
1282
+ return n >= ae ? n : e + n;
1283
+ }
1284
+ function le(t, e, n) {
1285
+ let r = t;
1286
+ for (; e-- > ae; )
1287
+ r *= r, r %= n;
1288
+ return r;
1289
+ }
1290
+ function xr(t, e) {
1291
+ if (t === ae)
1292
+ throw new Error("invert: expected non-zero number");
1293
+ if (e <= ae)
1294
+ throw new Error("invert: expected positive modulus, got " + e);
1295
+ let n = ue(t, e), r = e, o = ae, s = fe;
1296
+ for (; n !== ae; ) {
1297
+ const c = r / n, f = r % n, u = o - s * c;
1298
+ r = n, n = f, o = s, s = u;
1299
+ }
1300
+ if (r !== fe)
1301
+ throw new Error("invert: does not exist");
1302
+ return ue(o, e);
1303
+ }
1304
+ function qn(t, e, n) {
1305
+ if (!t.eql(t.sqr(e), n))
1306
+ throw new Error("Cannot find square root");
1307
+ }
1308
+ function co(t, e) {
1309
+ const n = (t.ORDER + fe) / ro, r = t.pow(e, n);
1310
+ return qn(t, r, e), r;
1311
+ }
1312
+ function ei(t, e) {
1313
+ const n = (t.ORDER - oo) / so, r = t.mul(e, Fe), o = t.pow(r, n), s = t.mul(e, o), i = t.mul(t.mul(s, Fe), o), c = t.mul(s, t.sub(i, t.ONE));
1314
+ return qn(t, c, e), c;
1315
+ }
1316
+ function ti(t) {
1317
+ const e = zn(t), n = fo(t), r = n(e, e.neg(e.ONE)), o = n(e, r), s = n(e, e.neg(r)), i = (t + Qs) / io;
1318
+ return (c, f) => {
1319
+ let u = c.pow(f, i), d = c.mul(u, r);
1320
+ const a = c.mul(u, o), y = c.mul(u, s), l = c.eql(c.sqr(d), f), b = c.eql(c.sqr(a), f);
1321
+ u = c.cmov(u, d, l), d = c.cmov(y, a, b);
1322
+ const E = c.eql(c.sqr(d), f), x = c.cmov(u, d, E);
1323
+ return qn(c, x, f), x;
1324
+ };
1325
+ }
1326
+ function fo(t) {
1327
+ if (t < no)
1328
+ throw new Error("sqrt is not defined for small field");
1329
+ let e = t - fe, n = 0;
1330
+ for (; e % Fe === ae; )
1331
+ e /= Fe, n++;
1332
+ let r = Fe;
1333
+ const o = zn(t);
1334
+ for (; Er(o, r) === 1; )
1335
+ if (r++ > 1e3)
1336
+ throw new Error("Cannot find square root: probably non-prime P");
1337
+ if (n === 1)
1338
+ return co;
1339
+ let s = o.pow(r, e);
1340
+ const i = (e + fe) / Fe;
1341
+ return function(f, u) {
1342
+ if (f.is0(u))
1343
+ return u;
1344
+ if (Er(f, u) !== 1)
1345
+ throw new Error("Cannot find square root");
1346
+ let d = n, a = f.mul(f.ONE, s), y = f.pow(u, e), l = f.pow(u, i);
1347
+ for (; !f.eql(y, f.ONE); ) {
1348
+ if (f.is0(y))
1349
+ return f.ZERO;
1350
+ let b = 1, E = f.sqr(y);
1351
+ for (; !f.eql(E, f.ONE); )
1352
+ if (b++, E = f.sqr(E), b === d)
1353
+ throw new Error("Cannot find square root");
1354
+ const x = fe << BigInt(d - b - 1), w = f.pow(a, x);
1355
+ d = b, a = f.sqr(w), y = f.mul(y, a), l = f.mul(l, w);
1356
+ }
1357
+ return l;
1358
+ };
1359
+ }
1360
+ function ni(t) {
1361
+ return t % ro === no ? co : t % so === oo ? ei : t % io === Js ? ti(t) : fo(t);
1362
+ }
1363
+ const ri = [
1364
+ "create",
1365
+ "isValid",
1366
+ "is0",
1367
+ "neg",
1368
+ "inv",
1369
+ "sqrt",
1370
+ "sqr",
1371
+ "eql",
1372
+ "add",
1373
+ "sub",
1374
+ "mul",
1375
+ "pow",
1376
+ "div",
1377
+ "addN",
1378
+ "subN",
1379
+ "mulN",
1380
+ "sqrN"
1381
+ ];
1382
+ function oi(t) {
1383
+ const e = {
1384
+ ORDER: "bigint",
1385
+ BYTES: "number",
1386
+ BITS: "number"
1387
+ }, n = ri.reduce((r, o) => (r[o] = "function", r), e);
1388
+ return Qt(t, n), t;
1389
+ }
1390
+ function si(t, e, n) {
1391
+ if (n < ae)
1392
+ throw new Error("invalid exponent, negatives unsupported");
1393
+ if (n === ae)
1394
+ return t.ONE;
1395
+ if (n === fe)
1396
+ return e;
1397
+ let r = t.ONE, o = e;
1398
+ for (; n > ae; )
1399
+ n & fe && (r = t.mul(r, o)), o = t.sqr(o), n >>= fe;
1400
+ return r;
1401
+ }
1402
+ function ao(t, e, n = !1) {
1403
+ const r = new Array(e.length).fill(n ? t.ZERO : void 0), o = e.reduce((i, c, f) => t.is0(c) ? i : (r[f] = i, t.mul(i, c)), t.ONE), s = t.inv(o);
1404
+ return e.reduceRight((i, c, f) => t.is0(c) ? i : (r[f] = t.mul(i, r[f]), t.mul(i, c)), s), r;
1405
+ }
1406
+ function Er(t, e) {
1407
+ const n = (t.ORDER - fe) / Fe, r = t.pow(e, n), o = t.eql(r, t.ONE), s = t.eql(r, t.ZERO), i = t.eql(r, t.neg(t.ONE));
1408
+ if (!o && !s && !i)
1409
+ throw new Error("invalid Legendre symbol result");
1410
+ return o ? 1 : s ? 0 : -1;
1411
+ }
1412
+ function ii(t, e) {
1413
+ e !== void 0 && qe(e);
1414
+ const n = e !== void 0 ? e : t.toString(2).length, r = Math.ceil(n / 8);
1415
+ return { nBitLength: n, nByteLength: r };
1416
+ }
1417
+ class ci {
1418
+ constructor(e, n = {}) {
1419
+ g(this, "ORDER");
1420
+ g(this, "BITS");
1421
+ g(this, "BYTES");
1422
+ g(this, "isLE");
1423
+ g(this, "ZERO", ae);
1424
+ g(this, "ONE", fe);
1425
+ g(this, "_lengths");
1426
+ g(this, "_sqrt");
1427
+ // cached sqrt
1428
+ g(this, "_mod");
1429
+ var i;
1430
+ if (e <= ae)
1431
+ throw new Error("invalid field: expected ORDER > 0, got " + e);
1432
+ let r;
1433
+ this.isLE = !1, n != null && typeof n == "object" && (typeof n.BITS == "number" && (r = n.BITS), typeof n.sqrt == "function" && (this.sqrt = n.sqrt), typeof n.isLE == "boolean" && (this.isLE = n.isLE), n.allowedLengths && (this._lengths = (i = n.allowedLengths) == null ? void 0 : i.slice()), typeof n.modFromBytes == "boolean" && (this._mod = n.modFromBytes));
1434
+ const { nBitLength: o, nByteLength: s } = ii(e, r);
1435
+ if (s > 2048)
1436
+ throw new Error("invalid field: expected ORDER of <= 2048 bytes");
1437
+ this.ORDER = e, this.BITS = o, this.BYTES = s, this._sqrt = void 0, Object.preventExtensions(this);
1438
+ }
1439
+ create(e) {
1440
+ return ue(e, this.ORDER);
1441
+ }
1442
+ isValid(e) {
1443
+ if (typeof e != "bigint")
1444
+ throw new Error("invalid field element: expected bigint, got " + typeof e);
1445
+ return ae <= e && e < this.ORDER;
1446
+ }
1447
+ is0(e) {
1448
+ return e === ae;
1449
+ }
1450
+ // is valid and invertible
1451
+ isValidNot0(e) {
1452
+ return !this.is0(e) && this.isValid(e);
1453
+ }
1454
+ isOdd(e) {
1455
+ return (e & fe) === fe;
1456
+ }
1457
+ neg(e) {
1458
+ return ue(-e, this.ORDER);
1459
+ }
1460
+ eql(e, n) {
1461
+ return e === n;
1462
+ }
1463
+ sqr(e) {
1464
+ return ue(e * e, this.ORDER);
1465
+ }
1466
+ add(e, n) {
1467
+ return ue(e + n, this.ORDER);
1468
+ }
1469
+ sub(e, n) {
1470
+ return ue(e - n, this.ORDER);
1471
+ }
1472
+ mul(e, n) {
1473
+ return ue(e * n, this.ORDER);
1474
+ }
1475
+ pow(e, n) {
1476
+ return si(this, e, n);
1477
+ }
1478
+ div(e, n) {
1479
+ return ue(e * xr(n, this.ORDER), this.ORDER);
1480
+ }
1481
+ // Same as above, but doesn't normalize
1482
+ sqrN(e) {
1483
+ return e * e;
1484
+ }
1485
+ addN(e, n) {
1486
+ return e + n;
1487
+ }
1488
+ subN(e, n) {
1489
+ return e - n;
1490
+ }
1491
+ mulN(e, n) {
1492
+ return e * n;
1493
+ }
1494
+ inv(e) {
1495
+ return xr(e, this.ORDER);
1496
+ }
1497
+ sqrt(e) {
1498
+ return this._sqrt || (this._sqrt = ni(this.ORDER)), this._sqrt(this, e);
1499
+ }
1500
+ toBytes(e) {
1501
+ return this.isLE ? Dn(e, this.BYTES) : Wt(e, this.BYTES);
1502
+ }
1503
+ fromBytes(e, n = !1) {
1504
+ Z(e);
1505
+ const { _lengths: r, BYTES: o, isLE: s, ORDER: i, _mod: c } = this;
1506
+ if (r) {
1507
+ if (!r.includes(e.length) || e.length > o)
1508
+ throw new Error("Field.fromBytes: expected " + r + " bytes, got " + e.length);
1509
+ const u = new Uint8Array(o);
1510
+ u.set(e, s ? 0 : u.length - e.length), e = u;
1511
+ }
1512
+ if (e.length !== o)
1513
+ throw new Error("Field.fromBytes: expected " + o + " bytes, got " + e.length);
1514
+ let f = s ? wt(e) : At(e);
1515
+ if (c && (f = ue(f, i)), !n && !this.isValid(f))
1516
+ throw new Error("invalid field element: outside of range 0..ORDER");
1517
+ return f;
1518
+ }
1519
+ // TODO: we don't need it here, move out to separate fn
1520
+ invertBatch(e) {
1521
+ return ao(this, e);
1522
+ }
1523
+ // We can't move this out because Fp6, Fp12 implement it
1524
+ // and it's unclear what to return in there.
1525
+ cmov(e, n, r) {
1526
+ return r ? n : e;
1527
+ }
1528
+ }
1529
+ function zn(t, e = {}) {
1530
+ return new ci(t, e);
1531
+ }
1532
+ function uo(t) {
1533
+ if (typeof t != "bigint")
1534
+ throw new Error("field order must be bigint");
1535
+ const e = t.toString(2).length;
1536
+ return Math.ceil(e / 8);
1537
+ }
1538
+ function lo(t) {
1539
+ const e = uo(t);
1540
+ return e + Math.ceil(e / 2);
1541
+ }
1542
+ function fi(t, e, n = !1) {
1543
+ Z(t);
1544
+ const r = t.length, o = uo(e), s = lo(e);
1545
+ if (r < 16 || r < s || r > 1024)
1546
+ throw new Error("expected " + s + "-1024 bytes of input, got " + r);
1547
+ const i = n ? wt(t) : At(t), c = ue(i, e - fe) + fe;
1548
+ return n ? Dn(c, o) : Wt(c, o);
1549
+ }
1550
+ /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
1551
+ const st = /* @__PURE__ */ BigInt(0), Pe = /* @__PURE__ */ BigInt(1);
1552
+ function zt(t, e) {
1553
+ const n = e.negate();
1554
+ return t ? n : e;
1555
+ }
1556
+ function mr(t, e) {
1557
+ const n = ao(t.Fp, e.map((r) => r.Z));
1558
+ return e.map((r, o) => t.fromAffine(r.toAffine(n[o])));
1559
+ }
1560
+ function ho(t, e) {
1561
+ if (!Number.isSafeInteger(t) || t <= 0 || t > e)
1562
+ throw new Error("invalid window size, expected [1.." + e + "], got W=" + t);
1563
+ }
1564
+ function un(t, e) {
1565
+ ho(t, e);
1566
+ const n = Math.ceil(e / t) + 1, r = 2 ** (t - 1), o = 2 ** t, s = jn(t), i = BigInt(t);
1567
+ return { windows: n, windowSize: r, mask: s, maxNumber: o, shiftBy: i };
1568
+ }
1569
+ function Ar(t, e, n) {
1570
+ const { windowSize: r, mask: o, maxNumber: s, shiftBy: i } = n;
1571
+ let c = Number(t & o), f = t >> i;
1572
+ c > r && (c -= s, f += Pe);
1573
+ const u = e * r, d = u + Math.abs(c) - 1, a = c === 0, y = c < 0, l = e % 2 !== 0;
1574
+ return { nextN: f, offset: d, isZero: a, isNeg: y, isNegF: l, offsetF: u };
1575
+ }
1576
+ const dn = /* @__PURE__ */ new WeakMap(), yo = /* @__PURE__ */ new WeakMap();
1577
+ function ln(t) {
1578
+ return yo.get(t) || 1;
1579
+ }
1580
+ function Br(t) {
1581
+ if (t !== st)
1582
+ throw new Error("invalid wNAF");
1583
+ }
1584
+ class ai {
1585
+ // Parametrized with a given Point class (not individual point)
1586
+ constructor(e, n) {
1587
+ g(this, "BASE");
1588
+ g(this, "ZERO");
1589
+ g(this, "Fn");
1590
+ g(this, "bits");
1591
+ this.BASE = e.BASE, this.ZERO = e.ZERO, this.Fn = e.Fn, this.bits = n;
1592
+ }
1593
+ // non-const time multiplication ladder
1594
+ _unsafeLadder(e, n, r = this.ZERO) {
1595
+ let o = e;
1596
+ for (; n > st; )
1597
+ n & Pe && (r = r.add(o)), o = o.double(), n >>= Pe;
1598
+ return r;
1599
+ }
1600
+ /**
1601
+ * Creates a wNAF precomputation window. Used for caching.
1602
+ * Default window size is set by `utils.precompute()` and is equal to 8.
1603
+ * Number of precomputed points depends on the curve size:
1604
+ * 2^(𝑊−1) * (Math.ceil(𝑛 / 𝑊) + 1), where:
1605
+ * - 𝑊 is the window size
1606
+ * - 𝑛 is the bitlength of the curve order.
1607
+ * For a 256-bit curve and window size 8, the number of precomputed points is 128 * 33 = 4224.
1608
+ * @param point Point instance
1609
+ * @param W window size
1610
+ * @returns precomputed point tables flattened to a single array
1611
+ */
1612
+ precomputeWindow(e, n) {
1613
+ const { windows: r, windowSize: o } = un(n, this.bits), s = [];
1614
+ let i = e, c = i;
1615
+ for (let f = 0; f < r; f++) {
1616
+ c = i, s.push(c);
1617
+ for (let u = 1; u < o; u++)
1618
+ c = c.add(i), s.push(c);
1619
+ i = c.double();
1620
+ }
1621
+ return s;
1622
+ }
1623
+ /**
1624
+ * Implements ec multiplication using precomputed tables and w-ary non-adjacent form.
1625
+ * More compact implementation:
1626
+ * https://github.com/paulmillr/noble-secp256k1/blob/47cb1669b6e506ad66b35fe7d76132ae97465da2/index.ts#L502-L541
1627
+ * @returns real and fake (for const-time) points
1628
+ */
1629
+ wNAF(e, n, r) {
1630
+ if (!this.Fn.isValid(r))
1631
+ throw new Error("invalid scalar");
1632
+ let o = this.ZERO, s = this.BASE;
1633
+ const i = un(e, this.bits);
1634
+ for (let c = 0; c < i.windows; c++) {
1635
+ const { nextN: f, offset: u, isZero: d, isNeg: a, isNegF: y, offsetF: l } = Ar(r, c, i);
1636
+ r = f, d ? s = s.add(zt(y, n[l])) : o = o.add(zt(a, n[u]));
1637
+ }
1638
+ return Br(r), { p: o, f: s };
1639
+ }
1640
+ /**
1641
+ * Implements ec unsafe (non const-time) multiplication using precomputed tables and w-ary non-adjacent form.
1642
+ * @param acc accumulator point to add result of multiplication
1643
+ * @returns point
1644
+ */
1645
+ wNAFUnsafe(e, n, r, o = this.ZERO) {
1646
+ const s = un(e, this.bits);
1647
+ for (let i = 0; i < s.windows && r !== st; i++) {
1648
+ const { nextN: c, offset: f, isZero: u, isNeg: d } = Ar(r, i, s);
1649
+ if (r = c, !u) {
1650
+ const a = n[f];
1651
+ o = o.add(d ? a.negate() : a);
1652
+ }
1653
+ }
1654
+ return Br(r), o;
1655
+ }
1656
+ getPrecomputes(e, n, r) {
1657
+ let o = dn.get(n);
1658
+ return o || (o = this.precomputeWindow(n, e), e !== 1 && (typeof r == "function" && (o = r(o)), dn.set(n, o))), o;
1659
+ }
1660
+ cached(e, n, r) {
1661
+ const o = ln(e);
1662
+ return this.wNAF(o, this.getPrecomputes(o, e, r), n);
1663
+ }
1664
+ unsafe(e, n, r, o) {
1665
+ const s = ln(e);
1666
+ return s === 1 ? this._unsafeLadder(e, n, o) : this.wNAFUnsafe(s, this.getPrecomputes(s, e, r), n, o);
1667
+ }
1668
+ // We calculate precomputes for elliptic curve point multiplication
1669
+ // using windowed method. This specifies window size and
1670
+ // stores precomputed values. Usually only base point would be precomputed.
1671
+ createCache(e, n) {
1672
+ ho(n, this.bits), yo.set(e, n), dn.delete(e);
1673
+ }
1674
+ hasCache(e) {
1675
+ return ln(e) !== 1;
1676
+ }
1677
+ }
1678
+ function ui(t, e, n, r) {
1679
+ let o = e, s = t.ZERO, i = t.ZERO;
1680
+ for (; n > st || r > st; )
1681
+ n & Pe && (s = s.add(o)), r & Pe && (i = i.add(o)), o = o.double(), n >>= Pe, r >>= Pe;
1682
+ return { p1: s, p2: i };
1683
+ }
1684
+ function Lr(t, e, n) {
1685
+ if (e) {
1686
+ if (e.ORDER !== t)
1687
+ throw new Error("Field.ORDER must match order: Fp == p, Fn == n");
1688
+ return oi(e), e;
1689
+ } else
1690
+ return zn(t, { isLE: n });
1691
+ }
1692
+ function di(t, e, n = {}, r) {
1693
+ if (r === void 0 && (r = t === "edwards"), !e || typeof e != "object")
1694
+ throw new Error(`expected valid ${t} CURVE object`);
1695
+ for (const f of ["p", "n", "h"]) {
1696
+ const u = e[f];
1697
+ if (!(typeof u == "bigint" && u > st))
1698
+ throw new Error(`CURVE.${f} must be positive bigint`);
1699
+ }
1700
+ const o = Lr(e.p, n.Fp, r), s = Lr(e.n, n.Fn, r), c = ["Gx", "Gy", "a", "b"];
1701
+ for (const f of c)
1702
+ if (!o.isValid(e[f]))
1703
+ throw new Error(`CURVE.${f} must be valid field element of CURVE.Fp`);
1704
+ return e = Object.freeze(Object.assign({}, e)), { CURVE: e, Fp: o, Fn: s };
1705
+ }
1706
+ function po(t, e) {
1707
+ return function(r) {
1708
+ const o = t(r);
1709
+ return { secretKey: o, publicKey: e(o) };
1710
+ };
1711
+ }
1712
+ /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
1713
+ const ut = BigInt(0), Xe = BigInt(1), Ut = BigInt(2);
1714
+ function li(t) {
1715
+ return Qt(t, {
1716
+ adjustScalarBytes: "function",
1717
+ powPminus2: "function"
1718
+ }), Object.freeze({ ...t });
1719
+ }
1720
+ function hi(t) {
1721
+ const e = li(t), { P: n, type: r, adjustScalarBytes: o, powPminus2: s, randomBytes: i } = e, c = r === "x25519";
1722
+ if (!c && r !== "x448")
1723
+ throw new Error("invalid type");
1724
+ const f = i || Fn, u = c ? 255 : 448, d = c ? 32 : 56, a = BigInt(c ? 9 : 5), y = BigInt(c ? 121665 : 39081), l = c ? Ut ** BigInt(254) : Ut ** BigInt(447), b = c ? BigInt(8) * Ut ** BigInt(251) - Xe : BigInt(4) * Ut ** BigInt(445) - Xe, E = l + b + Xe, x = (h) => ue(h, n), w = H(a);
1725
+ function H(h) {
1726
+ return Dn(x(h), d);
1727
+ }
1728
+ function k(h) {
1729
+ const p = Sn(Z(h, d, "uCoordinate"));
1730
+ return c && (p[31] &= 127), x(wt(p));
1731
+ }
1732
+ function O(h) {
1733
+ return wt(o(Sn(Z(h, d, "scalar"))));
1734
+ }
1735
+ function $(h, p) {
1736
+ const A = M(k(p), O(h));
1737
+ if (A === ut)
1738
+ throw new Error("invalid private or public key received");
1739
+ return H(A);
1740
+ }
1741
+ function R(h) {
1742
+ return $(h, w);
1743
+ }
1744
+ const N = R, T = $;
1745
+ function S(h, p, A) {
1746
+ const L = x(h * (p - A));
1747
+ return p = x(p - L), A = x(A + L), { x_2: p, x_3: A };
1748
+ }
1749
+ function M(h, p) {
1750
+ Hn("u", h, ut, n), Hn("scalar", p, l, E);
1751
+ const A = p, L = h;
1752
+ let U = Xe, m = ut, I = h, B = Xe, _ = ut;
1753
+ for (let z = BigInt(u - 1); z >= ut; z--) {
1754
+ const D = A >> z & Xe;
1755
+ _ ^= D, { x_2: U, x_3: I } = S(_, U, I), { x_2: m, x_3: B } = S(_, m, B), _ = D;
1756
+ const F = U + m, V = x(F * F), G = U - m, X = x(G * G), Y = V - X, Q = I + B, St = I - B, ct = x(St * F), nr = x(Q * G), rr = ct + nr, or = ct - nr;
1757
+ I = x(rr * rr), B = x(L * x(or * or)), U = x(V * X), m = x(Y * (V + x(y * Y)));
1758
+ }
1759
+ ({ x_2: U, x_3: I } = S(_, U, I)), { x_2: m, x_3: B } = S(_, m, B);
1760
+ const P = s(m);
1761
+ return x(U * P);
1762
+ }
1763
+ const C = {
1764
+ secretKey: d,
1765
+ publicKey: d,
1766
+ seed: d
1767
+ }, K = (h = f(d)) => (Z(h, C.seed, "seed"), h), v = { randomSecretKey: K };
1768
+ return Object.freeze({
1769
+ keygen: po(K, N),
1770
+ getSharedSecret: T,
1771
+ getPublicKey: N,
1772
+ scalarMult: $,
1773
+ scalarMultBase: R,
1774
+ utils: v,
1775
+ GuBytes: w.slice(),
1776
+ lengths: C
1777
+ });
1778
+ }
1779
+ let go = class {
1780
+ constructor(e, n) {
1781
+ g(this, "oHash");
1782
+ g(this, "iHash");
1783
+ g(this, "blockLen");
1784
+ g(this, "outputLen");
1785
+ g(this, "finished", !1);
1786
+ g(this, "destroyed", !1);
1787
+ if (Xr(e), Z(n, void 0, "key"), this.iHash = e.create(), typeof this.iHash.update != "function")
1788
+ throw new Error("Expected instance of class which extends utils.Hash");
1789
+ this.blockLen = this.iHash.blockLen, this.outputLen = this.iHash.outputLen;
1790
+ const r = this.blockLen, o = new Uint8Array(r);
1791
+ o.set(n.length > r ? e.create().update(n).digest() : n);
1792
+ for (let s = 0; s < o.length; s++)
1793
+ o[s] ^= 54;
1794
+ this.iHash.update(o), this.oHash = e.create();
1795
+ for (let s = 0; s < o.length; s++)
1796
+ o[s] ^= 106;
1797
+ this.oHash.update(o), ot(o);
1798
+ }
1799
+ update(e) {
1800
+ return Dt(this), this.iHash.update(e), this;
1801
+ }
1802
+ digestInto(e) {
1803
+ Dt(this), Z(e, this.outputLen, "output"), this.finished = !0, this.iHash.digestInto(e), this.oHash.update(e), this.oHash.digestInto(e), this.destroy();
1804
+ }
1805
+ digest() {
1806
+ const e = new Uint8Array(this.oHash.outputLen);
1807
+ return this.digestInto(e), e;
1808
+ }
1809
+ _cloneInto(e) {
1810
+ e || (e = Object.create(Object.getPrototypeOf(this), {}));
1811
+ const { oHash: n, iHash: r, finished: o, destroyed: s, blockLen: i, outputLen: c } = this;
1812
+ return e = e, e.finished = o, e.destroyed = s, e.blockLen = i, e.outputLen = c, e.oHash = n._cloneInto(e.oHash), e.iHash = r._cloneInto(e.iHash), e;
1813
+ }
1814
+ clone() {
1815
+ return this._cloneInto();
1816
+ }
1817
+ destroy() {
1818
+ this.destroyed = !0, this.oHash.destroy(), this.iHash.destroy();
1819
+ }
1820
+ };
1821
+ const bo = (t, e, n) => new go(t, e).update(n).digest();
1822
+ bo.create = (t, e) => new go(t, e);
1823
+ /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
1824
+ const Sr = (t, e) => (t + (t >= 0 ? e : -e) / wo) / e;
1825
+ function yi(t, e, n) {
1826
+ const [[r, o], [s, i]] = e, c = Sr(i * t, n), f = Sr(-o * t, n);
1827
+ let u = t - c * r - f * s, d = -c * o - f * i;
1828
+ const a = u < Ee, y = d < Ee;
1829
+ a && (u = -u), y && (d = -d);
1830
+ const l = jn(Math.ceil(Xs(n) / 2)) + et;
1831
+ if (u < Ee || u >= l || d < Ee || d >= l)
1832
+ throw new Error("splitScalar (endomorphism): failed, k=" + t);
1833
+ return { k1neg: a, k1: u, k2neg: y, k2: d };
1834
+ }
1835
+ function Un(t) {
1836
+ if (!["compact", "recovered", "der"].includes(t))
1837
+ throw new Error('Signature format must be "compact", "recovered", or "der"');
1838
+ return t;
1839
+ }
1840
+ function hn(t, e) {
1841
+ const n = {};
1842
+ for (let r of Object.keys(e))
1843
+ n[r] = t[r] === void 0 ? e[r] : t[r];
1844
+ return qt(n.lowS, "lowS"), qt(n.prehash, "prehash"), n.format !== void 0 && Un(n.format), n;
1845
+ }
1846
+ class pi extends Error {
1847
+ constructor(e = "") {
1848
+ super(e);
1849
+ }
1850
+ }
1851
+ const _e = {
1852
+ // asn.1 DER encoding utils
1853
+ Err: pi,
1854
+ // Basic building block is TLV (Tag-Length-Value)
1855
+ _tlv: {
1856
+ encode: (t, e) => {
1857
+ const { Err: n } = _e;
1858
+ if (t < 0 || t > 256)
1859
+ throw new n("tlv.encode: wrong tag");
1860
+ if (e.length & 1)
1861
+ throw new n("tlv.encode: unpadded data");
1862
+ const r = e.length / 2, o = Ht(r);
1863
+ if (o.length / 2 & 128)
1864
+ throw new n("tlv.encode: long form length too big");
1865
+ const s = r > 127 ? Ht(o.length / 2 | 128) : "";
1866
+ return Ht(t) + s + o + e;
1867
+ },
1868
+ // v - value, l - left bytes (unparsed)
1869
+ decode(t, e) {
1870
+ const { Err: n } = _e;
1871
+ let r = 0;
1872
+ if (t < 0 || t > 256)
1873
+ throw new n("tlv.encode: wrong tag");
1874
+ if (e.length < 2 || e[r++] !== t)
1875
+ throw new n("tlv.decode: wrong tlv");
1876
+ const o = e[r++], s = !!(o & 128);
1877
+ let i = 0;
1878
+ if (!s)
1879
+ i = o;
1880
+ else {
1881
+ const f = o & 127;
1882
+ if (!f)
1883
+ throw new n("tlv.decode(long): indefinite length not supported");
1884
+ if (f > 4)
1885
+ throw new n("tlv.decode(long): byte length is too big");
1886
+ const u = e.subarray(r, r + f);
1887
+ if (u.length !== f)
1888
+ throw new n("tlv.decode: length bytes not complete");
1889
+ if (u[0] === 0)
1890
+ throw new n("tlv.decode(long): zero leftmost byte");
1891
+ for (const d of u)
1892
+ i = i << 8 | d;
1893
+ if (r += f, i < 128)
1894
+ throw new n("tlv.decode(long): not minimal encoding");
1895
+ }
1896
+ const c = e.subarray(r, r + i);
1897
+ if (c.length !== i)
1898
+ throw new n("tlv.decode: wrong value length");
1899
+ return { v: c, l: e.subarray(r + i) };
1900
+ }
1901
+ },
1902
+ // https://crypto.stackexchange.com/a/57734 Leftmost bit of first byte is 'negative' flag,
1903
+ // since we always use positive integers here. It must always be empty:
1904
+ // - add zero byte if exists
1905
+ // - if next byte doesn't have a flag, leading zero is not allowed (minimal encoding)
1906
+ _int: {
1907
+ encode(t) {
1908
+ const { Err: e } = _e;
1909
+ if (t < Ee)
1910
+ throw new e("integer: negative integers are not allowed");
1911
+ let n = Ht(t);
1912
+ if (Number.parseInt(n[0], 16) & 8 && (n = "00" + n), n.length & 1)
1913
+ throw new e("unexpected DER parsing assertion: unpadded hex");
1914
+ return n;
1915
+ },
1916
+ decode(t) {
1917
+ const { Err: e } = _e;
1918
+ if (t[0] & 128)
1919
+ throw new e("invalid signature integer: negative");
1920
+ if (t[0] === 0 && !(t[1] & 128))
1921
+ throw new e("invalid signature integer: unnecessary leading zero");
1922
+ return At(t);
1923
+ }
1924
+ },
1925
+ toSig(t) {
1926
+ const { Err: e, _int: n, _tlv: r } = _e, o = Z(t, void 0, "signature"), { v: s, l: i } = r.decode(48, o);
1927
+ if (i.length)
1928
+ throw new e("invalid signature: left bytes after parsing");
1929
+ const { v: c, l: f } = r.decode(2, s), { v: u, l: d } = r.decode(2, f);
1930
+ if (d.length)
1931
+ throw new e("invalid signature: left bytes after parsing");
1932
+ return { r: n.decode(c), s: n.decode(u) };
1933
+ },
1934
+ hexFromSig(t) {
1935
+ const { _tlv: e, _int: n } = _e, r = e.encode(2, n.encode(t.r)), o = e.encode(2, n.encode(t.s)), s = r + o;
1936
+ return e.encode(48, s);
1937
+ }
1938
+ }, Ee = BigInt(0), et = BigInt(1), wo = BigInt(2), It = BigInt(3), gi = BigInt(4);
1939
+ function xo(t, e = {}) {
1940
+ const n = di("weierstrass", t, e), { Fp: r, Fn: o } = n;
1941
+ let s = n.CURVE;
1942
+ const { h: i, n: c } = s;
1943
+ Qt(e, {}, {
1944
+ allowInfinityPoint: "boolean",
1945
+ clearCofactor: "function",
1946
+ isTorsionFree: "function",
1947
+ fromBytes: "function",
1948
+ toBytes: "function",
1949
+ endo: "object"
1950
+ });
1951
+ const { endo: f } = e;
1952
+ if (f && (!r.is0(s.a) || typeof f.beta != "bigint" || !Array.isArray(f.basises)))
1953
+ throw new Error('invalid endo: expected "beta": bigint and "basises": array');
1954
+ const u = mo(r, o);
1955
+ function d() {
1956
+ if (!r.isOdd)
1957
+ throw new Error("compression is not supported: Field does not have .isOdd()");
1958
+ }
1959
+ function a(v, h, p) {
1960
+ const { x: A, y: L } = h.toAffine(), U = r.toBytes(A);
1961
+ if (qt(p, "isCompressed"), p) {
1962
+ d();
1963
+ const m = !r.isOdd(L);
1964
+ return ie(Eo(m), U);
1965
+ } else
1966
+ return ie(Uint8Array.of(4), U, r.toBytes(L));
1967
+ }
1968
+ function y(v) {
1969
+ Z(v, void 0, "Point");
1970
+ const { publicKey: h, publicKeyUncompressed: p } = u, A = v.length, L = v[0], U = v.subarray(1);
1971
+ if (A === h && (L === 2 || L === 3)) {
1972
+ const m = r.fromBytes(U);
1973
+ if (!r.isValid(m))
1974
+ throw new Error("bad point: is not on curve, wrong x");
1975
+ const I = E(m);
1976
+ let B;
1977
+ try {
1978
+ B = r.sqrt(I);
1979
+ } catch (z) {
1980
+ const D = z instanceof Error ? ": " + z.message : "";
1981
+ throw new Error("bad point: is not on curve, sqrt error" + D);
1982
+ }
1983
+ d();
1984
+ const _ = r.isOdd(B);
1985
+ return (L & 1) === 1 !== _ && (B = r.neg(B)), { x: m, y: B };
1986
+ } else if (A === p && L === 4) {
1987
+ const m = r.BYTES, I = r.fromBytes(U.subarray(0, m)), B = r.fromBytes(U.subarray(m, m * 2));
1988
+ if (!x(I, B))
1989
+ throw new Error("bad point: is not on curve");
1990
+ return { x: I, y: B };
1991
+ } else
1992
+ throw new Error(`bad point: got length ${A}, expected compressed=${h} or uncompressed=${p}`);
1993
+ }
1994
+ const l = e.toBytes || a, b = e.fromBytes || y;
1995
+ function E(v) {
1996
+ const h = r.sqr(v), p = r.mul(h, v);
1997
+ return r.add(r.add(p, r.mul(v, s.a)), s.b);
1998
+ }
1999
+ function x(v, h) {
2000
+ const p = r.sqr(h), A = E(v);
2001
+ return r.eql(p, A);
2002
+ }
2003
+ if (!x(s.Gx, s.Gy))
2004
+ throw new Error("bad curve params: generator point");
2005
+ const w = r.mul(r.pow(s.a, It), gi), H = r.mul(r.sqr(s.b), BigInt(27));
2006
+ if (r.is0(r.add(w, H)))
2007
+ throw new Error("bad curve params: a or b");
2008
+ function k(v, h, p = !1) {
2009
+ if (!r.isValid(h) || p && r.is0(h))
2010
+ throw new Error(`bad point coordinate ${v}`);
2011
+ return h;
2012
+ }
2013
+ function O(v) {
2014
+ if (!(v instanceof S))
2015
+ throw new Error("Weierstrass Point expected");
2016
+ }
2017
+ function $(v) {
2018
+ if (!f || !f.basises)
2019
+ throw new Error("no endo");
2020
+ return yi(v, f.basises, o.ORDER);
2021
+ }
2022
+ const R = wr((v, h) => {
2023
+ const { X: p, Y: A, Z: L } = v;
2024
+ if (r.eql(L, r.ONE))
2025
+ return { x: p, y: A };
2026
+ const U = v.is0();
2027
+ h == null && (h = U ? r.ONE : r.inv(L));
2028
+ const m = r.mul(p, h), I = r.mul(A, h), B = r.mul(L, h);
2029
+ if (U)
2030
+ return { x: r.ZERO, y: r.ZERO };
2031
+ if (!r.eql(B, r.ONE))
2032
+ throw new Error("invZ was invalid");
2033
+ return { x: m, y: I };
2034
+ }), N = wr((v) => {
2035
+ if (v.is0()) {
2036
+ if (e.allowInfinityPoint && !r.is0(v.Y))
2037
+ return;
2038
+ throw new Error("bad point: ZERO");
2039
+ }
2040
+ const { x: h, y: p } = v.toAffine();
2041
+ if (!r.isValid(h) || !r.isValid(p))
2042
+ throw new Error("bad point: x or y not field elements");
2043
+ if (!x(h, p))
2044
+ throw new Error("bad point: equation left != right");
2045
+ if (!v.isTorsionFree())
2046
+ throw new Error("bad point: not in prime-order subgroup");
2047
+ return !0;
2048
+ });
2049
+ function T(v, h, p, A, L) {
2050
+ return p = new S(r.mul(p.X, v), p.Y, p.Z), h = zt(A, h), p = zt(L, p), h.add(p);
2051
+ }
2052
+ const K = class K {
2053
+ /** Does NOT validate if the point is valid. Use `.assertValidity()`. */
2054
+ constructor(h, p, A) {
2055
+ g(this, "X");
2056
+ g(this, "Y");
2057
+ g(this, "Z");
2058
+ this.X = k("x", h), this.Y = k("y", p, !0), this.Z = k("z", A), Object.freeze(this);
2059
+ }
2060
+ static CURVE() {
2061
+ return s;
2062
+ }
2063
+ /** Does NOT validate if the point is valid. Use `.assertValidity()`. */
2064
+ static fromAffine(h) {
2065
+ const { x: p, y: A } = h || {};
2066
+ if (!h || !r.isValid(p) || !r.isValid(A))
2067
+ throw new Error("invalid affine point");
2068
+ if (h instanceof K)
2069
+ throw new Error("projective point not allowed");
2070
+ return r.is0(p) && r.is0(A) ? K.ZERO : new K(p, A, r.ONE);
2071
+ }
2072
+ static fromBytes(h) {
2073
+ const p = K.fromAffine(b(Z(h, void 0, "point")));
2074
+ return p.assertValidity(), p;
2075
+ }
2076
+ static fromHex(h) {
2077
+ return K.fromBytes(jt(h));
2078
+ }
2079
+ get x() {
2080
+ return this.toAffine().x;
2081
+ }
2082
+ get y() {
2083
+ return this.toAffine().y;
2084
+ }
2085
+ /**
2086
+ *
2087
+ * @param windowSize
2088
+ * @param isLazy true will defer table computation until the first multiplication
2089
+ * @returns
2090
+ */
2091
+ precompute(h = 8, p = !0) {
2092
+ return C.createCache(this, h), p || this.multiply(It), this;
2093
+ }
2094
+ // TODO: return `this`
2095
+ /** A point on curve is valid if it conforms to equation. */
2096
+ assertValidity() {
2097
+ N(this);
2098
+ }
2099
+ hasEvenY() {
2100
+ const { y: h } = this.toAffine();
2101
+ if (!r.isOdd)
2102
+ throw new Error("Field doesn't support isOdd");
2103
+ return !r.isOdd(h);
2104
+ }
2105
+ /** Compare one point to another. */
2106
+ equals(h) {
2107
+ O(h);
2108
+ const { X: p, Y: A, Z: L } = this, { X: U, Y: m, Z: I } = h, B = r.eql(r.mul(p, I), r.mul(U, L)), _ = r.eql(r.mul(A, I), r.mul(m, L));
2109
+ return B && _;
2110
+ }
2111
+ /** Flips point to one corresponding to (x, -y) in Affine coordinates. */
2112
+ negate() {
2113
+ return new K(this.X, r.neg(this.Y), this.Z);
2114
+ }
2115
+ // Renes-Costello-Batina exception-free doubling formula.
2116
+ // There is 30% faster Jacobian formula, but it is not complete.
2117
+ // https://eprint.iacr.org/2015/1060, algorithm 3
2118
+ // Cost: 8M + 3S + 3*a + 2*b3 + 15add.
2119
+ double() {
2120
+ const { a: h, b: p } = s, A = r.mul(p, It), { X: L, Y: U, Z: m } = this;
2121
+ let I = r.ZERO, B = r.ZERO, _ = r.ZERO, P = r.mul(L, L), z = r.mul(U, U), D = r.mul(m, m), F = r.mul(L, U);
2122
+ return F = r.add(F, F), _ = r.mul(L, m), _ = r.add(_, _), I = r.mul(h, _), B = r.mul(A, D), B = r.add(I, B), I = r.sub(z, B), B = r.add(z, B), B = r.mul(I, B), I = r.mul(F, I), _ = r.mul(A, _), D = r.mul(h, D), F = r.sub(P, D), F = r.mul(h, F), F = r.add(F, _), _ = r.add(P, P), P = r.add(_, P), P = r.add(P, D), P = r.mul(P, F), B = r.add(B, P), D = r.mul(U, m), D = r.add(D, D), P = r.mul(D, F), I = r.sub(I, P), _ = r.mul(D, z), _ = r.add(_, _), _ = r.add(_, _), new K(I, B, _);
2123
+ }
2124
+ // Renes-Costello-Batina exception-free addition formula.
2125
+ // There is 30% faster Jacobian formula, but it is not complete.
2126
+ // https://eprint.iacr.org/2015/1060, algorithm 1
2127
+ // Cost: 12M + 0S + 3*a + 3*b3 + 23add.
2128
+ add(h) {
2129
+ O(h);
2130
+ const { X: p, Y: A, Z: L } = this, { X: U, Y: m, Z: I } = h;
2131
+ let B = r.ZERO, _ = r.ZERO, P = r.ZERO;
2132
+ const z = s.a, D = r.mul(s.b, It);
2133
+ let F = r.mul(p, U), V = r.mul(A, m), G = r.mul(L, I), X = r.add(p, A), Y = r.add(U, m);
2134
+ X = r.mul(X, Y), Y = r.add(F, V), X = r.sub(X, Y), Y = r.add(p, L);
2135
+ let Q = r.add(U, I);
2136
+ return Y = r.mul(Y, Q), Q = r.add(F, G), Y = r.sub(Y, Q), Q = r.add(A, L), B = r.add(m, I), Q = r.mul(Q, B), B = r.add(V, G), Q = r.sub(Q, B), P = r.mul(z, Y), B = r.mul(D, G), P = r.add(B, P), B = r.sub(V, P), P = r.add(V, P), _ = r.mul(B, P), V = r.add(F, F), V = r.add(V, F), G = r.mul(z, G), Y = r.mul(D, Y), V = r.add(V, G), G = r.sub(F, G), G = r.mul(z, G), Y = r.add(Y, G), F = r.mul(V, Y), _ = r.add(_, F), F = r.mul(Q, Y), B = r.mul(X, B), B = r.sub(B, F), F = r.mul(X, V), P = r.mul(Q, P), P = r.add(P, F), new K(B, _, P);
2137
+ }
2138
+ subtract(h) {
2139
+ return this.add(h.negate());
2140
+ }
2141
+ is0() {
2142
+ return this.equals(K.ZERO);
2143
+ }
2144
+ /**
2145
+ * Constant time multiplication.
2146
+ * Uses wNAF method. Windowed method may be 10% faster,
2147
+ * but takes 2x longer to generate and consumes 2x memory.
2148
+ * Uses precomputes when available.
2149
+ * Uses endomorphism for Koblitz curves.
2150
+ * @param scalar by which the point would be multiplied
2151
+ * @returns New point
2152
+ */
2153
+ multiply(h) {
2154
+ const { endo: p } = e;
2155
+ if (!o.isValidNot0(h))
2156
+ throw new Error("invalid scalar: out of range");
2157
+ let A, L;
2158
+ const U = (m) => C.cached(this, m, (I) => mr(K, I));
2159
+ if (p) {
2160
+ const { k1neg: m, k1: I, k2neg: B, k2: _ } = $(h), { p: P, f: z } = U(I), { p: D, f: F } = U(_);
2161
+ L = z.add(F), A = T(p.beta, P, D, m, B);
2162
+ } else {
2163
+ const { p: m, f: I } = U(h);
2164
+ A = m, L = I;
2165
+ }
2166
+ return mr(K, [A, L])[0];
2167
+ }
2168
+ /**
2169
+ * Non-constant-time multiplication. Uses double-and-add algorithm.
2170
+ * It's faster, but should only be used when you don't care about
2171
+ * an exposed secret key e.g. sig verification, which works over *public* keys.
2172
+ */
2173
+ multiplyUnsafe(h) {
2174
+ const { endo: p } = e, A = this;
2175
+ if (!o.isValid(h))
2176
+ throw new Error("invalid scalar: out of range");
2177
+ if (h === Ee || A.is0())
2178
+ return K.ZERO;
2179
+ if (h === et)
2180
+ return A;
2181
+ if (C.hasCache(this))
2182
+ return this.multiply(h);
2183
+ if (p) {
2184
+ const { k1neg: L, k1: U, k2neg: m, k2: I } = $(h), { p1: B, p2: _ } = ui(K, A, U, I);
2185
+ return T(p.beta, B, _, L, m);
2186
+ } else
2187
+ return C.unsafe(A, h);
2188
+ }
2189
+ /**
2190
+ * Converts Projective point to affine (x, y) coordinates.
2191
+ * @param invertedZ Z^-1 (inverted zero) - optional, precomputation is useful for invertBatch
2192
+ */
2193
+ toAffine(h) {
2194
+ return R(this, h);
2195
+ }
2196
+ /**
2197
+ * Checks whether Point is free of torsion elements (is in prime subgroup).
2198
+ * Always torsion-free for cofactor=1 curves.
2199
+ */
2200
+ isTorsionFree() {
2201
+ const { isTorsionFree: h } = e;
2202
+ return i === et ? !0 : h ? h(K, this) : C.unsafe(this, c).is0();
2203
+ }
2204
+ clearCofactor() {
2205
+ const { clearCofactor: h } = e;
2206
+ return i === et ? this : h ? h(K, this) : this.multiplyUnsafe(i);
2207
+ }
2208
+ isSmallOrder() {
2209
+ return this.multiplyUnsafe(i).is0();
2210
+ }
2211
+ toBytes(h = !0) {
2212
+ return qt(h, "isCompressed"), this.assertValidity(), l(K, this, h);
2213
+ }
2214
+ toHex(h = !0) {
2215
+ return Xt(this.toBytes(h));
2216
+ }
2217
+ toString() {
2218
+ return `<Point ${this.is0() ? "ZERO" : this.toHex()}>`;
2219
+ }
2220
+ };
2221
+ // base / generator point
2222
+ g(K, "BASE", new K(s.Gx, s.Gy, r.ONE)), // zero / infinity / identity point
2223
+ g(K, "ZERO", new K(r.ZERO, r.ONE, r.ZERO)), // 0, 1, 0
2224
+ // math field
2225
+ g(K, "Fp", r), // scalar field
2226
+ g(K, "Fn", o);
2227
+ let S = K;
2228
+ const M = o.BITS, C = new ai(S, e.endo ? Math.ceil(M / 2) : M);
2229
+ return S.BASE.precompute(8), S;
2230
+ }
2231
+ function Eo(t) {
2232
+ return Uint8Array.of(t ? 2 : 3);
2233
+ }
2234
+ function mo(t, e) {
2235
+ return {
2236
+ secretKey: e.BYTES,
2237
+ publicKey: 1 + t.BYTES,
2238
+ publicKeyUncompressed: 1 + 2 * t.BYTES,
2239
+ publicKeyHasPrefix: !0,
2240
+ signature: 2 * e.BYTES
2241
+ };
2242
+ }
2243
+ function bi(t, e = {}) {
2244
+ const { Fn: n } = t, r = e.randomBytes || Fn, o = Object.assign(mo(t.Fp, n), { seed: lo(n.ORDER) });
2245
+ function s(l) {
2246
+ try {
2247
+ const b = n.fromBytes(l);
2248
+ return n.isValidNot0(b);
2249
+ } catch {
2250
+ return !1;
2251
+ }
2252
+ }
2253
+ function i(l, b) {
2254
+ const { publicKey: E, publicKeyUncompressed: x } = o;
2255
+ try {
2256
+ const w = l.length;
2257
+ return b === !0 && w !== E || b === !1 && w !== x ? !1 : !!t.fromBytes(l);
2258
+ } catch {
2259
+ return !1;
2260
+ }
2261
+ }
2262
+ function c(l = r(o.seed)) {
2263
+ return fi(Z(l, o.seed, "seed"), n.ORDER);
2264
+ }
2265
+ function f(l, b = !0) {
2266
+ return t.BASE.multiply(n.fromBytes(l)).toBytes(b);
2267
+ }
2268
+ function u(l) {
2269
+ const { secretKey: b, publicKey: E, publicKeyUncompressed: x } = o;
2270
+ if (!Mn(l) || "_lengths" in n && n._lengths || b === E)
2271
+ return;
2272
+ const w = Z(l, void 0, "key").length;
2273
+ return w === E || w === x;
2274
+ }
2275
+ function d(l, b, E = !0) {
2276
+ if (u(l) === !0)
2277
+ throw new Error("first arg must be private key");
2278
+ if (u(b) === !1)
2279
+ throw new Error("second arg must be public key");
2280
+ const x = n.fromBytes(l);
2281
+ return t.fromBytes(b).multiply(x).toBytes(E);
2282
+ }
2283
+ const a = {
2284
+ isValidSecretKey: s,
2285
+ isValidPublicKey: i,
2286
+ randomSecretKey: c
2287
+ }, y = po(c, f);
2288
+ return Object.freeze({ getPublicKey: f, getSharedSecret: d, keygen: y, Point: t, utils: a, lengths: o });
2289
+ }
2290
+ function Ao(t, e, n = {}) {
2291
+ Xr(e), Qt(n, {}, {
2292
+ hmac: "function",
2293
+ lowS: "boolean",
2294
+ randomBytes: "function",
2295
+ bits2int: "function",
2296
+ bits2int_modN: "function"
2297
+ }), n = Object.assign({}, n);
2298
+ const r = n.randomBytes || Fn, o = n.hmac || ((h, p) => bo(e, h, p)), { Fp: s, Fn: i } = t, { ORDER: c, BITS: f } = i, { keygen: u, getPublicKey: d, getSharedSecret: a, utils: y, lengths: l } = bi(t, n), b = {
2299
+ prehash: !0,
2300
+ lowS: typeof n.lowS == "boolean" ? n.lowS : !0,
2301
+ format: "compact",
2302
+ extraEntropy: !1
2303
+ }, E = c * wo < s.ORDER;
2304
+ function x(h) {
2305
+ const p = c >> et;
2306
+ return h > p;
2307
+ }
2308
+ function w(h, p) {
2309
+ if (!i.isValidNot0(p))
2310
+ throw new Error(`invalid signature ${h}: out of range 1..Point.Fn.ORDER`);
2311
+ return p;
2312
+ }
2313
+ function H() {
2314
+ if (E)
2315
+ throw new Error('"recovered" sig type is not supported for cofactor >2 curves');
2316
+ }
2317
+ function k(h, p) {
2318
+ Un(p);
2319
+ const A = l.signature, L = p === "compact" ? A : p === "recovered" ? A + 1 : void 0;
2320
+ return Z(h, L);
2321
+ }
2322
+ class O {
2323
+ constructor(p, A, L) {
2324
+ g(this, "r");
2325
+ g(this, "s");
2326
+ g(this, "recovery");
2327
+ if (this.r = w("r", p), this.s = w("s", A), L != null) {
2328
+ if (H(), ![0, 1, 2, 3].includes(L))
2329
+ throw new Error("invalid recovery id");
2330
+ this.recovery = L;
2331
+ }
2332
+ Object.freeze(this);
2333
+ }
2334
+ static fromBytes(p, A = b.format) {
2335
+ k(p, A);
2336
+ let L;
2337
+ if (A === "der") {
2338
+ const { r: B, s: _ } = _e.toSig(Z(p));
2339
+ return new O(B, _);
2340
+ }
2341
+ A === "recovered" && (L = p[0], A = "compact", p = p.subarray(1));
2342
+ const U = l.signature / 2, m = p.subarray(0, U), I = p.subarray(U, U * 2);
2343
+ return new O(i.fromBytes(m), i.fromBytes(I), L);
2344
+ }
2345
+ static fromHex(p, A) {
2346
+ return this.fromBytes(jt(p), A);
2347
+ }
2348
+ assertRecovery() {
2349
+ const { recovery: p } = this;
2350
+ if (p == null)
2351
+ throw new Error("invalid recovery id: must be present");
2352
+ return p;
2353
+ }
2354
+ addRecoveryBit(p) {
2355
+ return new O(this.r, this.s, p);
2356
+ }
2357
+ recoverPublicKey(p) {
2358
+ const { r: A, s: L } = this, U = this.assertRecovery(), m = U === 2 || U === 3 ? A + c : A;
2359
+ if (!s.isValid(m))
2360
+ throw new Error("invalid recovery id: sig.r+curve.n != R.x");
2361
+ const I = s.toBytes(m), B = t.fromBytes(ie(Eo((U & 1) === 0), I)), _ = i.inv(m), P = R(Z(p, void 0, "msgHash")), z = i.create(-P * _), D = i.create(L * _), F = t.BASE.multiplyUnsafe(z).add(B.multiplyUnsafe(D));
2362
+ if (F.is0())
2363
+ throw new Error("invalid recovery: point at infinify");
2364
+ return F.assertValidity(), F;
2365
+ }
2366
+ // Signatures should be low-s, to prevent malleability.
2367
+ hasHighS() {
2368
+ return x(this.s);
2369
+ }
2370
+ toBytes(p = b.format) {
2371
+ if (Un(p), p === "der")
2372
+ return jt(_e.hexFromSig(this));
2373
+ const { r: A, s: L } = this, U = i.toBytes(A), m = i.toBytes(L);
2374
+ return p === "recovered" ? (H(), ie(Uint8Array.of(this.assertRecovery()), U, m)) : ie(U, m);
2375
+ }
2376
+ toHex(p) {
2377
+ return Xt(this.toBytes(p));
2378
+ }
2379
+ }
2380
+ const $ = n.bits2int || function(p) {
2381
+ if (p.length > 8192)
2382
+ throw new Error("input is too large");
2383
+ const A = At(p), L = p.length * 8 - f;
2384
+ return L > 0 ? A >> BigInt(L) : A;
2385
+ }, R = n.bits2int_modN || function(p) {
2386
+ return i.create($(p));
2387
+ }, N = jn(f);
2388
+ function T(h) {
2389
+ return Hn("num < 2^" + f, h, Ee, N), i.toBytes(h);
2390
+ }
2391
+ function S(h, p) {
2392
+ return Z(h, void 0, "message"), p ? Z(e(h), void 0, "prehashed message") : h;
2393
+ }
2394
+ function M(h, p, A) {
2395
+ const { lowS: L, prehash: U, extraEntropy: m } = hn(A, b);
2396
+ h = S(h, U);
2397
+ const I = R(h), B = i.fromBytes(p);
2398
+ if (!i.isValidNot0(B))
2399
+ throw new Error("invalid private key");
2400
+ const _ = [T(B), T(I)];
2401
+ if (m != null && m !== !1) {
2402
+ const F = m === !0 ? r(l.secretKey) : m;
2403
+ _.push(Z(F, void 0, "extraEntropy"));
2404
+ }
2405
+ const P = ie(..._), z = I;
2406
+ function D(F) {
2407
+ const V = $(F);
2408
+ if (!i.isValidNot0(V))
2409
+ return;
2410
+ const G = i.inv(V), X = t.BASE.multiply(V).toAffine(), Y = i.create(X.x);
2411
+ if (Y === Ee)
2412
+ return;
2413
+ const Q = i.create(G * i.create(z + Y * B));
2414
+ if (Q === Ee)
2415
+ return;
2416
+ let St = (X.x === Y ? 0 : 2) | Number(X.y & et), ct = Q;
2417
+ return L && x(Q) && (ct = i.neg(Q), St ^= 1), new O(Y, ct, E ? void 0 : St);
2418
+ }
2419
+ return { seed: P, k2sig: D };
2420
+ }
2421
+ function C(h, p, A = {}) {
2422
+ const { seed: L, k2sig: U } = M(h, p, A);
2423
+ return Ws(e.outputLen, i.BYTES, o)(L, U).toBytes(A.format);
2424
+ }
2425
+ function K(h, p, A, L = {}) {
2426
+ const { lowS: U, prehash: m, format: I } = hn(L, b);
2427
+ if (A = Z(A, void 0, "publicKey"), p = S(p, m), !Mn(h)) {
2428
+ const B = h instanceof O ? ", use sig.toBytes()" : "";
2429
+ throw new Error("verify expects Uint8Array signature" + B);
2430
+ }
2431
+ k(h, I);
2432
+ try {
2433
+ const B = O.fromBytes(h, I), _ = t.fromBytes(A);
2434
+ if (U && B.hasHighS())
2435
+ return !1;
2436
+ const { r: P, s: z } = B, D = R(p), F = i.inv(z), V = i.create(D * F), G = i.create(P * F), X = t.BASE.multiplyUnsafe(V).add(_.multiplyUnsafe(G));
2437
+ return X.is0() ? !1 : i.create(X.x) === P;
2438
+ } catch {
2439
+ return !1;
2440
+ }
2441
+ }
2442
+ function v(h, p, A = {}) {
2443
+ const { prehash: L } = hn(A, b);
2444
+ return p = S(p, L), O.fromBytes(h, "recovered").recoverPublicKey(p).toBytes();
2445
+ }
2446
+ return Object.freeze({
2447
+ keygen: u,
2448
+ getPublicKey: d,
2449
+ getSharedSecret: a,
2450
+ utils: y,
2451
+ lengths: l,
2452
+ Point: t,
2453
+ sign: C,
2454
+ verify: K,
2455
+ recoverPublicKey: v,
2456
+ Signature: O,
2457
+ hash: e
2458
+ });
2459
+ }
2460
+ function wi(t, e, n) {
2461
+ return t & e ^ ~t & n;
2462
+ }
2463
+ function xi(t, e, n) {
2464
+ return t & e ^ t & n ^ e & n;
2465
+ }
2466
+ let Bo = class {
2467
+ constructor(e, n, r, o) {
2468
+ g(this, "blockLen");
2469
+ g(this, "outputLen");
2470
+ g(this, "padOffset");
2471
+ g(this, "isLE");
2472
+ // For partial updates less than block size
2473
+ g(this, "buffer");
2474
+ g(this, "view");
2475
+ g(this, "finished", !1);
2476
+ g(this, "length", 0);
2477
+ g(this, "pos", 0);
2478
+ g(this, "destroyed", !1);
2479
+ this.blockLen = e, this.outputLen = n, this.padOffset = r, this.isLE = o, this.buffer = new Uint8Array(e), this.view = an(this.buffer);
2480
+ }
2481
+ update(e) {
2482
+ Dt(this), Z(e);
2483
+ const { view: n, buffer: r, blockLen: o } = this, s = e.length;
2484
+ for (let i = 0; i < s; ) {
2485
+ const c = Math.min(o - this.pos, s - i);
2486
+ if (c === o) {
2487
+ const f = an(e);
2488
+ for (; o <= s - i; i += o)
2489
+ this.process(f, i);
2490
+ continue;
2491
+ }
2492
+ r.set(e.subarray(i, i + c), this.pos), this.pos += c, i += c, this.pos === o && (this.process(n, 0), this.pos = 0);
2493
+ }
2494
+ return this.length += e.length, this.roundClean(), this;
2495
+ }
2496
+ digestInto(e) {
2497
+ Dt(this), Gs(e, this), this.finished = !0;
2498
+ const { buffer: n, view: r, blockLen: o, isLE: s } = this;
2499
+ let { pos: i } = this;
2500
+ n[i++] = 128, ot(this.buffer.subarray(i)), this.padOffset > o - i && (this.process(r, 0), i = 0);
2501
+ for (let a = i; a < o; a++)
2502
+ n[a] = 0;
2503
+ r.setBigUint64(o - 8, BigInt(this.length * 8), s), this.process(r, 0);
2504
+ const c = an(e), f = this.outputLen;
2505
+ if (f % 4)
2506
+ throw new Error("_sha2: outputLen must be aligned to 32bit");
2507
+ const u = f / 4, d = this.get();
2508
+ if (u > d.length)
2509
+ throw new Error("_sha2: outputLen bigger than state");
2510
+ for (let a = 0; a < u; a++)
2511
+ c.setUint32(4 * a, d[a], s);
2512
+ }
2513
+ digest() {
2514
+ const { buffer: e, outputLen: n } = this;
2515
+ this.digestInto(e);
2516
+ const r = e.slice(0, n);
2517
+ return this.destroy(), r;
2518
+ }
2519
+ _cloneInto(e) {
2520
+ e || (e = new this.constructor()), e.set(...this.get());
2521
+ const { blockLen: n, buffer: r, length: o, finished: s, destroyed: i, pos: c } = this;
2522
+ return e.destroyed = i, e.finished = s, e.length = o, e.pos = c, o % n && e.buffer.set(r), e;
2523
+ }
2524
+ clone() {
2525
+ return this._cloneInto();
2526
+ }
2527
+ };
2528
+ const Le = /* @__PURE__ */ Uint32Array.from([
2529
+ 1779033703,
2530
+ 3144134277,
2531
+ 1013904242,
2532
+ 2773480762,
2533
+ 1359893119,
2534
+ 2600822924,
2535
+ 528734635,
2536
+ 1541459225
2537
+ ]), te = /* @__PURE__ */ Uint32Array.from([
2538
+ 3418070365,
2539
+ 3238371032,
2540
+ 1654270250,
2541
+ 914150663,
2542
+ 2438529370,
2543
+ 812702999,
2544
+ 355462360,
2545
+ 4144912697,
2546
+ 1731405415,
2547
+ 4290775857,
2548
+ 2394180231,
2549
+ 1750603025,
2550
+ 3675008525,
2551
+ 1694076839,
2552
+ 1203062813,
2553
+ 3204075428
2554
+ ]), kt = /* @__PURE__ */ BigInt(2 ** 32 - 1), Hr = /* @__PURE__ */ BigInt(32);
2555
+ function Ei(t, e = !1) {
2556
+ return e ? { h: Number(t & kt), l: Number(t >> Hr & kt) } : { h: Number(t >> Hr & kt) | 0, l: Number(t & kt) | 0 };
2557
+ }
2558
+ function mi(t, e = !1) {
2559
+ const n = t.length;
2560
+ let r = new Uint32Array(n), o = new Uint32Array(n);
2561
+ for (let s = 0; s < n; s++) {
2562
+ const { h: i, l: c } = Ei(t[s], e);
2563
+ [r[s], o[s]] = [i, c];
2564
+ }
2565
+ return [r, o];
2566
+ }
2567
+ const Ur = (t, e, n) => t >>> n, Ir = (t, e, n) => t << 32 - n | e >>> n, We = (t, e, n) => t >>> n | e << 32 - n, Qe = (t, e, n) => t << 32 - n | e >>> n, _t = (t, e, n) => t << 64 - n | e >>> n - 32, Kt = (t, e, n) => t >>> n - 32 | e << 64 - n;
2568
+ function we(t, e, n, r) {
2569
+ const o = (e >>> 0) + (r >>> 0);
2570
+ return { h: t + n + (o / 2 ** 32 | 0) | 0, l: o | 0 };
2571
+ }
2572
+ const Ai = (t, e, n) => (t >>> 0) + (e >>> 0) + (n >>> 0), Bi = (t, e, n, r) => e + n + r + (t / 2 ** 32 | 0) | 0, Li = (t, e, n, r) => (t >>> 0) + (e >>> 0) + (n >>> 0) + (r >>> 0), Si = (t, e, n, r, o) => e + n + r + o + (t / 2 ** 32 | 0) | 0, Hi = (t, e, n, r, o) => (t >>> 0) + (e >>> 0) + (n >>> 0) + (r >>> 0) + (o >>> 0), Ui = (t, e, n, r, o, s) => e + n + r + o + s + (t / 2 ** 32 | 0) | 0, Ii = /* @__PURE__ */ Uint32Array.from([
2573
+ 1116352408,
2574
+ 1899447441,
2575
+ 3049323471,
2576
+ 3921009573,
2577
+ 961987163,
2578
+ 1508970993,
2579
+ 2453635748,
2580
+ 2870763221,
2581
+ 3624381080,
2582
+ 310598401,
2583
+ 607225278,
2584
+ 1426881987,
2585
+ 1925078388,
2586
+ 2162078206,
2587
+ 2614888103,
2588
+ 3248222580,
2589
+ 3835390401,
2590
+ 4022224774,
2591
+ 264347078,
2592
+ 604807628,
2593
+ 770255983,
2594
+ 1249150122,
2595
+ 1555081692,
2596
+ 1996064986,
2597
+ 2554220882,
2598
+ 2821834349,
2599
+ 2952996808,
2600
+ 3210313671,
2601
+ 3336571891,
2602
+ 3584528711,
2603
+ 113926993,
2604
+ 338241895,
2605
+ 666307205,
2606
+ 773529912,
2607
+ 1294757372,
2608
+ 1396182291,
2609
+ 1695183700,
2610
+ 1986661051,
2611
+ 2177026350,
2612
+ 2456956037,
2613
+ 2730485921,
2614
+ 2820302411,
2615
+ 3259730800,
2616
+ 3345764771,
2617
+ 3516065817,
2618
+ 3600352804,
2619
+ 4094571909,
2620
+ 275423344,
2621
+ 430227734,
2622
+ 506948616,
2623
+ 659060556,
2624
+ 883997877,
2625
+ 958139571,
2626
+ 1322822218,
2627
+ 1537002063,
2628
+ 1747873779,
2629
+ 1955562222,
2630
+ 2024104815,
2631
+ 2227730452,
2632
+ 2361852424,
2633
+ 2428436474,
2634
+ 2756734187,
2635
+ 3204031479,
2636
+ 3329325298
2637
+ ]), Se = /* @__PURE__ */ new Uint32Array(64);
2638
+ let ki = class extends Bo {
2639
+ constructor(e) {
2640
+ super(64, e, 8, !1);
2641
+ }
2642
+ get() {
2643
+ const { A: e, B: n, C: r, D: o, E: s, F: i, G: c, H: f } = this;
2644
+ return [e, n, r, o, s, i, c, f];
2645
+ }
2646
+ // prettier-ignore
2647
+ set(e, n, r, o, s, i, c, f) {
2648
+ this.A = e | 0, this.B = n | 0, this.C = r | 0, this.D = o | 0, this.E = s | 0, this.F = i | 0, this.G = c | 0, this.H = f | 0;
2649
+ }
2650
+ process(e, n) {
2651
+ for (let a = 0; a < 16; a++, n += 4)
2652
+ Se[a] = e.getUint32(n, !1);
2653
+ for (let a = 16; a < 64; a++) {
2654
+ const y = Se[a - 15], l = Se[a - 2], b = ye(y, 7) ^ ye(y, 18) ^ y >>> 3, E = ye(l, 17) ^ ye(l, 19) ^ l >>> 10;
2655
+ Se[a] = E + Se[a - 7] + b + Se[a - 16] | 0;
2656
+ }
2657
+ let { A: r, B: o, C: s, D: i, E: c, F: f, G: u, H: d } = this;
2658
+ for (let a = 0; a < 64; a++) {
2659
+ const y = ye(c, 6) ^ ye(c, 11) ^ ye(c, 25), l = d + y + wi(c, f, u) + Ii[a] + Se[a] | 0, E = (ye(r, 2) ^ ye(r, 13) ^ ye(r, 22)) + xi(r, o, s) | 0;
2660
+ d = u, u = f, f = c, c = i + l | 0, i = s, s = o, o = r, r = l + E | 0;
2661
+ }
2662
+ r = r + this.A | 0, o = o + this.B | 0, s = s + this.C | 0, i = i + this.D | 0, c = c + this.E | 0, f = f + this.F | 0, u = u + this.G | 0, d = d + this.H | 0, this.set(r, o, s, i, c, f, u, d);
2663
+ }
2664
+ roundClean() {
2665
+ ot(Se);
2666
+ }
2667
+ destroy() {
2668
+ this.set(0, 0, 0, 0, 0, 0, 0, 0), ot(this.buffer);
2669
+ }
2670
+ }, _i = class extends ki {
2671
+ constructor() {
2672
+ super(32);
2673
+ // We cannot use array here since array allows indexing by variable
2674
+ // which means optimizer/compiler cannot use registers.
2675
+ g(this, "A", Le[0] | 0);
2676
+ g(this, "B", Le[1] | 0);
2677
+ g(this, "C", Le[2] | 0);
2678
+ g(this, "D", Le[3] | 0);
2679
+ g(this, "E", Le[4] | 0);
2680
+ g(this, "F", Le[5] | 0);
2681
+ g(this, "G", Le[6] | 0);
2682
+ g(this, "H", Le[7] | 0);
2683
+ }
2684
+ };
2685
+ const Lo = mi([
2686
+ "0x428a2f98d728ae22",
2687
+ "0x7137449123ef65cd",
2688
+ "0xb5c0fbcfec4d3b2f",
2689
+ "0xe9b5dba58189dbbc",
2690
+ "0x3956c25bf348b538",
2691
+ "0x59f111f1b605d019",
2692
+ "0x923f82a4af194f9b",
2693
+ "0xab1c5ed5da6d8118",
2694
+ "0xd807aa98a3030242",
2695
+ "0x12835b0145706fbe",
2696
+ "0x243185be4ee4b28c",
2697
+ "0x550c7dc3d5ffb4e2",
2698
+ "0x72be5d74f27b896f",
2699
+ "0x80deb1fe3b1696b1",
2700
+ "0x9bdc06a725c71235",
2701
+ "0xc19bf174cf692694",
2702
+ "0xe49b69c19ef14ad2",
2703
+ "0xefbe4786384f25e3",
2704
+ "0x0fc19dc68b8cd5b5",
2705
+ "0x240ca1cc77ac9c65",
2706
+ "0x2de92c6f592b0275",
2707
+ "0x4a7484aa6ea6e483",
2708
+ "0x5cb0a9dcbd41fbd4",
2709
+ "0x76f988da831153b5",
2710
+ "0x983e5152ee66dfab",
2711
+ "0xa831c66d2db43210",
2712
+ "0xb00327c898fb213f",
2713
+ "0xbf597fc7beef0ee4",
2714
+ "0xc6e00bf33da88fc2",
2715
+ "0xd5a79147930aa725",
2716
+ "0x06ca6351e003826f",
2717
+ "0x142929670a0e6e70",
2718
+ "0x27b70a8546d22ffc",
2719
+ "0x2e1b21385c26c926",
2720
+ "0x4d2c6dfc5ac42aed",
2721
+ "0x53380d139d95b3df",
2722
+ "0x650a73548baf63de",
2723
+ "0x766a0abb3c77b2a8",
2724
+ "0x81c2c92e47edaee6",
2725
+ "0x92722c851482353b",
2726
+ "0xa2bfe8a14cf10364",
2727
+ "0xa81a664bbc423001",
2728
+ "0xc24b8b70d0f89791",
2729
+ "0xc76c51a30654be30",
2730
+ "0xd192e819d6ef5218",
2731
+ "0xd69906245565a910",
2732
+ "0xf40e35855771202a",
2733
+ "0x106aa07032bbd1b8",
2734
+ "0x19a4c116b8d2d0c8",
2735
+ "0x1e376c085141ab53",
2736
+ "0x2748774cdf8eeb99",
2737
+ "0x34b0bcb5e19b48a8",
2738
+ "0x391c0cb3c5c95a63",
2739
+ "0x4ed8aa4ae3418acb",
2740
+ "0x5b9cca4f7763e373",
2741
+ "0x682e6ff3d6b2b8a3",
2742
+ "0x748f82ee5defb2fc",
2743
+ "0x78a5636f43172f60",
2744
+ "0x84c87814a1f0ab72",
2745
+ "0x8cc702081a6439ec",
2746
+ "0x90befffa23631e28",
2747
+ "0xa4506cebde82bde9",
2748
+ "0xbef9a3f7b2c67915",
2749
+ "0xc67178f2e372532b",
2750
+ "0xca273eceea26619c",
2751
+ "0xd186b8c721c0c207",
2752
+ "0xeada7dd6cde0eb1e",
2753
+ "0xf57d4f7fee6ed178",
2754
+ "0x06f067aa72176fba",
2755
+ "0x0a637dc5a2c898a6",
2756
+ "0x113f9804bef90dae",
2757
+ "0x1b710b35131c471b",
2758
+ "0x28db77f523047d84",
2759
+ "0x32caab7b40c72493",
2760
+ "0x3c9ebe0a15c9bebc",
2761
+ "0x431d67c49c100d4c",
2762
+ "0x4cc5d4becb3e42b6",
2763
+ "0x597f299cfc657e2a",
2764
+ "0x5fcb6fab3ad6faec",
2765
+ "0x6c44198c4a475817"
2766
+ ].map((t) => BigInt(t))), Ki = Lo[0], vi = Lo[1], He = /* @__PURE__ */ new Uint32Array(80), Ue = /* @__PURE__ */ new Uint32Array(80);
2767
+ class Ri extends Bo {
2768
+ constructor(e) {
2769
+ super(128, e, 16, !1);
2770
+ }
2771
+ // prettier-ignore
2772
+ get() {
2773
+ const { Ah: e, Al: n, Bh: r, Bl: o, Ch: s, Cl: i, Dh: c, Dl: f, Eh: u, El: d, Fh: a, Fl: y, Gh: l, Gl: b, Hh: E, Hl: x } = this;
2774
+ return [e, n, r, o, s, i, c, f, u, d, a, y, l, b, E, x];
2775
+ }
2776
+ // prettier-ignore
2777
+ set(e, n, r, o, s, i, c, f, u, d, a, y, l, b, E, x) {
2778
+ this.Ah = e | 0, this.Al = n | 0, this.Bh = r | 0, this.Bl = o | 0, this.Ch = s | 0, this.Cl = i | 0, this.Dh = c | 0, this.Dl = f | 0, this.Eh = u | 0, this.El = d | 0, this.Fh = a | 0, this.Fl = y | 0, this.Gh = l | 0, this.Gl = b | 0, this.Hh = E | 0, this.Hl = x | 0;
2779
+ }
2780
+ process(e, n) {
2781
+ for (let k = 0; k < 16; k++, n += 4)
2782
+ He[k] = e.getUint32(n), Ue[k] = e.getUint32(n += 4);
2783
+ for (let k = 16; k < 80; k++) {
2784
+ const O = He[k - 15] | 0, $ = Ue[k - 15] | 0, R = We(O, $, 1) ^ We(O, $, 8) ^ Ur(O, $, 7), N = Qe(O, $, 1) ^ Qe(O, $, 8) ^ Ir(O, $, 7), T = He[k - 2] | 0, S = Ue[k - 2] | 0, M = We(T, S, 19) ^ _t(T, S, 61) ^ Ur(T, S, 6), C = Qe(T, S, 19) ^ Kt(T, S, 61) ^ Ir(T, S, 6), K = Li(N, C, Ue[k - 7], Ue[k - 16]), v = Si(K, R, M, He[k - 7], He[k - 16]);
2785
+ He[k] = v | 0, Ue[k] = K | 0;
2786
+ }
2787
+ let { Ah: r, Al: o, Bh: s, Bl: i, Ch: c, Cl: f, Dh: u, Dl: d, Eh: a, El: y, Fh: l, Fl: b, Gh: E, Gl: x, Hh: w, Hl: H } = this;
2788
+ for (let k = 0; k < 80; k++) {
2789
+ const O = We(a, y, 14) ^ We(a, y, 18) ^ _t(a, y, 41), $ = Qe(a, y, 14) ^ Qe(a, y, 18) ^ Kt(a, y, 41), R = a & l ^ ~a & E, N = y & b ^ ~y & x, T = Hi(H, $, N, vi[k], Ue[k]), S = Ui(T, w, O, R, Ki[k], He[k]), M = T | 0, C = We(r, o, 28) ^ _t(r, o, 34) ^ _t(r, o, 39), K = Qe(r, o, 28) ^ Kt(r, o, 34) ^ Kt(r, o, 39), v = r & s ^ r & c ^ s & c, h = o & i ^ o & f ^ i & f;
2790
+ w = E | 0, H = x | 0, E = l | 0, x = b | 0, l = a | 0, b = y | 0, { h: a, l: y } = we(u | 0, d | 0, S | 0, M | 0), u = c | 0, d = f | 0, c = s | 0, f = i | 0, s = r | 0, i = o | 0;
2791
+ const p = Ai(M, K, h);
2792
+ r = Bi(p, S, C, v), o = p | 0;
2793
+ }
2794
+ ({ h: r, l: o } = we(this.Ah | 0, this.Al | 0, r | 0, o | 0)), { h: s, l: i } = we(this.Bh | 0, this.Bl | 0, s | 0, i | 0), { h: c, l: f } = we(this.Ch | 0, this.Cl | 0, c | 0, f | 0), { h: u, l: d } = we(this.Dh | 0, this.Dl | 0, u | 0, d | 0), { h: a, l: y } = we(this.Eh | 0, this.El | 0, a | 0, y | 0), { h: l, l: b } = we(this.Fh | 0, this.Fl | 0, l | 0, b | 0), { h: E, l: x } = we(this.Gh | 0, this.Gl | 0, E | 0, x | 0), { h: w, l: H } = we(this.Hh | 0, this.Hl | 0, w | 0, H | 0), this.set(r, o, s, i, c, f, u, d, a, y, l, b, E, x, w, H);
2795
+ }
2796
+ roundClean() {
2797
+ ot(He, Ue);
2798
+ }
2799
+ destroy() {
2800
+ ot(this.buffer), this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
2801
+ }
2802
+ }
2803
+ class Ti extends Ri {
2804
+ constructor() {
2805
+ super(48);
2806
+ g(this, "Ah", te[0] | 0);
2807
+ g(this, "Al", te[1] | 0);
2808
+ g(this, "Bh", te[2] | 0);
2809
+ g(this, "Bl", te[3] | 0);
2810
+ g(this, "Ch", te[4] | 0);
2811
+ g(this, "Cl", te[5] | 0);
2812
+ g(this, "Dh", te[6] | 0);
2813
+ g(this, "Dl", te[7] | 0);
2814
+ g(this, "Eh", te[8] | 0);
2815
+ g(this, "El", te[9] | 0);
2816
+ g(this, "Fh", te[10] | 0);
2817
+ g(this, "Fl", te[11] | 0);
2818
+ g(this, "Gh", te[12] | 0);
2819
+ g(this, "Gl", te[13] | 0);
2820
+ g(this, "Hh", te[14] | 0);
2821
+ g(this, "Hl", te[15] | 0);
2822
+ }
2823
+ }
2824
+ const Ci = /* @__PURE__ */ Qr(
2825
+ () => new _i(),
2826
+ /* @__PURE__ */ Jr(1)
2827
+ ), Oi = /* @__PURE__ */ Qr(
2828
+ () => new Ti(),
2829
+ /* @__PURE__ */ Jr(2)
2830
+ );
2831
+ /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
2832
+ const $i = BigInt(1), kr = BigInt(2), Ni = /* @__PURE__ */ BigInt(3), Mi = BigInt(5);
2833
+ BigInt(8);
2834
+ const So = BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed");
2835
+ function Fi(t) {
2836
+ const e = BigInt(10), n = BigInt(20), r = BigInt(40), o = BigInt(80), s = So, c = t * t % s * t % s, f = le(c, kr, s) * c % s, u = le(f, $i, s) * t % s, d = le(u, Mi, s) * u % s, a = le(d, e, s) * d % s, y = le(a, n, s) * a % s, l = le(y, r, s) * y % s, b = le(l, o, s) * l % s, E = le(b, o, s) * l % s, x = le(E, e, s) * d % s;
2837
+ return { pow_p_5_8: le(x, kr, s) * t % s, b2: c };
2838
+ }
2839
+ function Pi(t) {
2840
+ return t[0] &= 248, t[31] &= 127, t[31] |= 64, t;
2841
+ }
2842
+ const Vt = /* @__PURE__ */ (() => {
2843
+ const t = So;
2844
+ return hi({
2845
+ P: t,
2846
+ type: "x25519",
2847
+ powPminus2: (e) => {
2848
+ const { pow_p_5_8: n, b2: r } = Fi(e);
2849
+ return ue(le(n, Ni, t) * r, t);
2850
+ },
2851
+ adjustScalarBytes: Pi
2852
+ });
2853
+ })();
2854
+ /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
2855
+ const Di = {
2856
+ p: BigInt("0xffffffff00000001000000000000000000000000ffffffffffffffffffffffff"),
2857
+ n: BigInt("0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551"),
2858
+ h: BigInt(1),
2859
+ a: BigInt("0xffffffff00000001000000000000000000000000fffffffffffffffffffffffc"),
2860
+ b: BigInt("0x5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b"),
2861
+ Gx: BigInt("0x6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296"),
2862
+ Gy: BigInt("0x4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5")
2863
+ }, ji = {
2864
+ p: BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffff0000000000000000ffffffff"),
2865
+ n: BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffc7634d81f4372ddf581a0db248b0a77aecec196accc52973"),
2866
+ h: BigInt(1),
2867
+ a: BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffff0000000000000000fffffffc"),
2868
+ b: BigInt("0xb3312fa7e23ee7e4988e056be3f82d19181d9c6efe8141120314088f5013875ac656398d8a2ed19d2a85c8edd3ec2aef"),
2869
+ Gx: BigInt("0xaa87ca22be8b05378eb1c71ef320ad746e1d3b628ba79b9859f741e082542a385502f25dbf55296c3a545e3872760ab7"),
2870
+ Gy: BigInt("0x3617de4a96262c6f5d9e98bf9292dc29f8f41dbd289a147ce9da3113b5f0b8c00a60b1ce1d7e819d7a431d7c90ea0e5f")
2871
+ }, qi = /* @__PURE__ */ xo(Di), Oe = /* @__PURE__ */ Ao(qi, Ci), zi = /* @__PURE__ */ xo(ji), Vi = /* @__PURE__ */ Ao(zi, Oi);
2872
+ /*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
2873
+ function Gi(t) {
2874
+ return t instanceof Uint8Array || ArrayBuffer.isView(t) && t.constructor.name === "Uint8Array";
2875
+ }
2876
+ function ze(t, e = "") {
2877
+ if (!Number.isSafeInteger(t) || t < 0) {
2878
+ const n = e && `"${e}" `;
2879
+ throw new Error(`${n}expected integer >= 0, got ${t}`);
2880
+ }
2881
+ }
2882
+ function W(t, e, n = "") {
2883
+ const r = Gi(t), o = t == null ? void 0 : t.length, s = e !== void 0;
2884
+ if (!r || s && o !== e) {
2885
+ const i = n && `"${n}" `, c = s ? ` of length ${e}` : "", f = r ? `length=${o}` : `type=${typeof t}`;
2886
+ throw new Error(i + "expected Uint8Array" + c + ", got " + f);
2887
+ }
2888
+ return t;
2889
+ }
2890
+ function Ve(t) {
2891
+ if (typeof t != "function" || typeof t.create != "function")
2892
+ throw new Error("Hash must wrapped by utils.createHasher");
2893
+ ze(t.outputLen), ze(t.blockLen);
2894
+ }
2895
+ function it(t, e = !0) {
2896
+ if (t.destroyed)
2897
+ throw new Error("Hash instance has been destroyed");
2898
+ if (e && t.finished)
2899
+ throw new Error("Hash#digest() has already been called");
2900
+ }
2901
+ function Ho(t, e) {
2902
+ W(t, void 0, "digestInto() output");
2903
+ const n = e.outputLen;
2904
+ if (t.length < n)
2905
+ throw new Error('"digestInto() output" expected to be of length >=' + n);
2906
+ }
2907
+ function Uo(t) {
2908
+ return new Uint32Array(t.buffer, t.byteOffset, Math.floor(t.byteLength / 4));
2909
+ }
2910
+ function Ge(...t) {
2911
+ for (let e = 0; e < t.length; e++)
2912
+ t[e].fill(0);
2913
+ }
2914
+ function yn(t) {
2915
+ return new DataView(t.buffer, t.byteOffset, t.byteLength);
2916
+ }
2917
+ function pe(t, e) {
2918
+ return t << 32 - e | t >>> e;
2919
+ }
2920
+ const Yi = new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68;
2921
+ function Zi(t) {
2922
+ return t << 24 & 4278190080 | t << 8 & 16711680 | t >>> 8 & 65280 | t >>> 24 & 255;
2923
+ }
2924
+ function Xi(t) {
2925
+ for (let e = 0; e < t.length; e++)
2926
+ t[e] = Zi(t[e]);
2927
+ return t;
2928
+ }
2929
+ const _r = Yi ? (t) => t : Xi;
2930
+ function Vn(t, e = {}) {
2931
+ const n = (o, s) => t(s).update(o).digest(), r = t(void 0);
2932
+ return n.outputLen = r.outputLen, n.blockLen = r.blockLen, n.create = (o) => t(o), Object.assign(n, e), Object.freeze(n);
2933
+ }
2934
+ function Wi(t = 32) {
2935
+ const e = typeof globalThis == "object" ? globalThis.crypto : null;
2936
+ if (typeof (e == null ? void 0 : e.getRandomValues) != "function")
2937
+ throw new Error("crypto.getRandomValues must be defined");
2938
+ return e.getRandomValues(new Uint8Array(t));
2939
+ }
2940
+ const Bt = (t) => ({
2941
+ oid: Uint8Array.from([6, 9, 96, 134, 72, 1, 101, 3, 4, 2, t])
2942
+ });
2943
+ class Io {
2944
+ constructor(e, n) {
2945
+ g(this, "oHash");
2946
+ g(this, "iHash");
2947
+ g(this, "blockLen");
2948
+ g(this, "outputLen");
2949
+ g(this, "finished", !1);
2950
+ g(this, "destroyed", !1);
2951
+ if (Ve(e), W(n, void 0, "key"), this.iHash = e.create(), typeof this.iHash.update != "function")
2952
+ throw new Error("Expected instance of class which extends utils.Hash");
2953
+ this.blockLen = this.iHash.blockLen, this.outputLen = this.iHash.outputLen;
2954
+ const r = this.blockLen, o = new Uint8Array(r);
2955
+ o.set(n.length > r ? e.create().update(n).digest() : n);
2956
+ for (let s = 0; s < o.length; s++)
2957
+ o[s] ^= 54;
2958
+ this.iHash.update(o), this.oHash = e.create();
2959
+ for (let s = 0; s < o.length; s++)
2960
+ o[s] ^= 106;
2961
+ this.oHash.update(o), Ge(o);
2962
+ }
2963
+ update(e) {
2964
+ return it(this), this.iHash.update(e), this;
2965
+ }
2966
+ digestInto(e) {
2967
+ it(this), W(e, this.outputLen, "output"), this.finished = !0, this.iHash.digestInto(e), this.oHash.update(e), this.oHash.digestInto(e), this.destroy();
2968
+ }
2969
+ digest() {
2970
+ const e = new Uint8Array(this.oHash.outputLen);
2971
+ return this.digestInto(e), e;
2972
+ }
2973
+ _cloneInto(e) {
2974
+ e || (e = Object.create(Object.getPrototypeOf(this), {}));
2975
+ const { oHash: n, iHash: r, finished: o, destroyed: s, blockLen: i, outputLen: c } = this;
2976
+ return e = e, e.finished = o, e.destroyed = s, e.blockLen = i, e.outputLen = c, e.oHash = n._cloneInto(e.oHash), e.iHash = r._cloneInto(e.iHash), e;
2977
+ }
2978
+ clone() {
2979
+ return this._cloneInto();
2980
+ }
2981
+ destroy() {
2982
+ this.destroyed = !0, this.oHash.destroy(), this.iHash.destroy();
2983
+ }
2984
+ }
2985
+ const Gn = (t, e, n) => new Io(t, e).update(n).digest();
2986
+ Gn.create = (t, e) => new Io(t, e);
2987
+ function Qi(t, e, n) {
2988
+ return Ve(t), n === void 0 && (n = new Uint8Array(t.outputLen)), Gn(t, n, e);
2989
+ }
2990
+ const pn = /* @__PURE__ */ Uint8Array.of(0), Kr = /* @__PURE__ */ Uint8Array.of();
2991
+ function Ji(t, e, n, r = 32) {
2992
+ Ve(t), ze(r, "length");
2993
+ const o = t.outputLen;
2994
+ if (r > 255 * o)
2995
+ throw new Error("Length must be <= 255*HashLen");
2996
+ const s = Math.ceil(r / o);
2997
+ n === void 0 ? n = Kr : W(n, void 0, "info");
2998
+ const i = new Uint8Array(s * o), c = Gn.create(t, e), f = c._cloneInto(), u = new Uint8Array(c.outputLen);
2999
+ for (let d = 0; d < s; d++)
3000
+ pn[0] = d + 1, f.update(d === 0 ? Kr : u).update(n).update(pn).digestInto(u), i.set(u, o * d), c._cloneInto(f);
3001
+ return c.destroy(), f.destroy(), Ge(u, pn), i.slice(0, r);
3002
+ }
3003
+ function ec(t, e, n) {
3004
+ return t & e ^ ~t & n;
3005
+ }
3006
+ function tc(t, e, n) {
3007
+ return t & e ^ t & n ^ e & n;
3008
+ }
3009
+ class nc {
3010
+ constructor(e, n, r, o) {
3011
+ g(this, "blockLen");
3012
+ g(this, "outputLen");
3013
+ g(this, "padOffset");
3014
+ g(this, "isLE");
3015
+ // For partial updates less than block size
3016
+ g(this, "buffer");
3017
+ g(this, "view");
3018
+ g(this, "finished", !1);
3019
+ g(this, "length", 0);
3020
+ g(this, "pos", 0);
3021
+ g(this, "destroyed", !1);
3022
+ this.blockLen = e, this.outputLen = n, this.padOffset = r, this.isLE = o, this.buffer = new Uint8Array(e), this.view = yn(this.buffer);
3023
+ }
3024
+ update(e) {
3025
+ it(this), W(e);
3026
+ const { view: n, buffer: r, blockLen: o } = this, s = e.length;
3027
+ for (let i = 0; i < s; ) {
3028
+ const c = Math.min(o - this.pos, s - i);
3029
+ if (c === o) {
3030
+ const f = yn(e);
3031
+ for (; o <= s - i; i += o)
3032
+ this.process(f, i);
3033
+ continue;
3034
+ }
3035
+ r.set(e.subarray(i, i + c), this.pos), this.pos += c, i += c, this.pos === o && (this.process(n, 0), this.pos = 0);
3036
+ }
3037
+ return this.length += e.length, this.roundClean(), this;
3038
+ }
3039
+ digestInto(e) {
3040
+ it(this), Ho(e, this), this.finished = !0;
3041
+ const { buffer: n, view: r, blockLen: o, isLE: s } = this;
3042
+ let { pos: i } = this;
3043
+ n[i++] = 128, Ge(this.buffer.subarray(i)), this.padOffset > o - i && (this.process(r, 0), i = 0);
3044
+ for (let a = i; a < o; a++)
3045
+ n[a] = 0;
3046
+ r.setBigUint64(o - 8, BigInt(this.length * 8), s), this.process(r, 0);
3047
+ const c = yn(e), f = this.outputLen;
3048
+ if (f % 4)
3049
+ throw new Error("_sha2: outputLen must be aligned to 32bit");
3050
+ const u = f / 4, d = this.get();
3051
+ if (u > d.length)
3052
+ throw new Error("_sha2: outputLen bigger than state");
3053
+ for (let a = 0; a < u; a++)
3054
+ c.setUint32(4 * a, d[a], s);
3055
+ }
3056
+ digest() {
3057
+ const { buffer: e, outputLen: n } = this;
3058
+ this.digestInto(e);
3059
+ const r = e.slice(0, n);
3060
+ return this.destroy(), r;
3061
+ }
3062
+ _cloneInto(e) {
3063
+ e || (e = new this.constructor()), e.set(...this.get());
3064
+ const { blockLen: n, buffer: r, length: o, finished: s, destroyed: i, pos: c } = this;
3065
+ return e.destroyed = i, e.finished = s, e.length = o, e.pos = c, o % n && e.buffer.set(r), e;
3066
+ }
3067
+ clone() {
3068
+ return this._cloneInto();
3069
+ }
3070
+ }
3071
+ const Ie = /* @__PURE__ */ Uint32Array.from([
3072
+ 1779033703,
3073
+ 3144134277,
3074
+ 1013904242,
3075
+ 2773480762,
3076
+ 1359893119,
3077
+ 2600822924,
3078
+ 528734635,
3079
+ 1541459225
3080
+ ]), vt = /* @__PURE__ */ BigInt(2 ** 32 - 1), vr = /* @__PURE__ */ BigInt(32);
3081
+ function rc(t, e = !1) {
3082
+ return e ? { h: Number(t & vt), l: Number(t >> vr & vt) } : { h: Number(t >> vr & vt) | 0, l: Number(t & vt) | 0 };
3083
+ }
3084
+ function oc(t, e = !1) {
3085
+ const n = t.length;
3086
+ let r = new Uint32Array(n), o = new Uint32Array(n);
3087
+ for (let s = 0; s < n; s++) {
3088
+ const { h: i, l: c } = rc(t[s], e);
3089
+ [r[s], o[s]] = [i, c];
3090
+ }
3091
+ return [r, o];
3092
+ }
3093
+ const sc = (t, e, n) => t << n | e >>> 32 - n, ic = (t, e, n) => e << n | t >>> 32 - n, cc = (t, e, n) => e << n - 32 | t >>> 64 - n, fc = (t, e, n) => t << n - 32 | e >>> 64 - n, ac = /* @__PURE__ */ Uint32Array.from([
3094
+ 1116352408,
3095
+ 1899447441,
3096
+ 3049323471,
3097
+ 3921009573,
3098
+ 961987163,
3099
+ 1508970993,
3100
+ 2453635748,
3101
+ 2870763221,
3102
+ 3624381080,
3103
+ 310598401,
3104
+ 607225278,
3105
+ 1426881987,
3106
+ 1925078388,
3107
+ 2162078206,
3108
+ 2614888103,
3109
+ 3248222580,
3110
+ 3835390401,
3111
+ 4022224774,
3112
+ 264347078,
3113
+ 604807628,
3114
+ 770255983,
3115
+ 1249150122,
3116
+ 1555081692,
3117
+ 1996064986,
3118
+ 2554220882,
3119
+ 2821834349,
3120
+ 2952996808,
3121
+ 3210313671,
3122
+ 3336571891,
3123
+ 3584528711,
3124
+ 113926993,
3125
+ 338241895,
3126
+ 666307205,
3127
+ 773529912,
3128
+ 1294757372,
3129
+ 1396182291,
3130
+ 1695183700,
3131
+ 1986661051,
3132
+ 2177026350,
3133
+ 2456956037,
3134
+ 2730485921,
3135
+ 2820302411,
3136
+ 3259730800,
3137
+ 3345764771,
3138
+ 3516065817,
3139
+ 3600352804,
3140
+ 4094571909,
3141
+ 275423344,
3142
+ 430227734,
3143
+ 506948616,
3144
+ 659060556,
3145
+ 883997877,
3146
+ 958139571,
3147
+ 1322822218,
3148
+ 1537002063,
3149
+ 1747873779,
3150
+ 1955562222,
3151
+ 2024104815,
3152
+ 2227730452,
3153
+ 2361852424,
3154
+ 2428436474,
3155
+ 2756734187,
3156
+ 3204031479,
3157
+ 3329325298
3158
+ ]), ke = /* @__PURE__ */ new Uint32Array(64);
3159
+ class uc extends nc {
3160
+ constructor(e) {
3161
+ super(64, e, 8, !1);
3162
+ }
3163
+ get() {
3164
+ const { A: e, B: n, C: r, D: o, E: s, F: i, G: c, H: f } = this;
3165
+ return [e, n, r, o, s, i, c, f];
3166
+ }
3167
+ // prettier-ignore
3168
+ set(e, n, r, o, s, i, c, f) {
3169
+ this.A = e | 0, this.B = n | 0, this.C = r | 0, this.D = o | 0, this.E = s | 0, this.F = i | 0, this.G = c | 0, this.H = f | 0;
3170
+ }
3171
+ process(e, n) {
3172
+ for (let a = 0; a < 16; a++, n += 4)
3173
+ ke[a] = e.getUint32(n, !1);
3174
+ for (let a = 16; a < 64; a++) {
3175
+ const y = ke[a - 15], l = ke[a - 2], b = pe(y, 7) ^ pe(y, 18) ^ y >>> 3, E = pe(l, 17) ^ pe(l, 19) ^ l >>> 10;
3176
+ ke[a] = E + ke[a - 7] + b + ke[a - 16] | 0;
3177
+ }
3178
+ let { A: r, B: o, C: s, D: i, E: c, F: f, G: u, H: d } = this;
3179
+ for (let a = 0; a < 64; a++) {
3180
+ const y = pe(c, 6) ^ pe(c, 11) ^ pe(c, 25), l = d + y + ec(c, f, u) + ac[a] + ke[a] | 0, E = (pe(r, 2) ^ pe(r, 13) ^ pe(r, 22)) + tc(r, o, s) | 0;
3181
+ d = u, u = f, f = c, c = i + l | 0, i = s, s = o, o = r, r = l + E | 0;
3182
+ }
3183
+ r = r + this.A | 0, o = o + this.B | 0, s = s + this.C | 0, i = i + this.D | 0, c = c + this.E | 0, f = f + this.F | 0, u = u + this.G | 0, d = d + this.H | 0, this.set(r, o, s, i, c, f, u, d);
3184
+ }
3185
+ roundClean() {
3186
+ Ge(ke);
3187
+ }
3188
+ destroy() {
3189
+ this.set(0, 0, 0, 0, 0, 0, 0, 0), Ge(this.buffer);
3190
+ }
3191
+ }
3192
+ class dc extends uc {
3193
+ constructor() {
3194
+ super(32);
3195
+ // We cannot use array here since array allows indexing by variable
3196
+ // which means optimizer/compiler cannot use registers.
3197
+ g(this, "A", Ie[0] | 0);
3198
+ g(this, "B", Ie[1] | 0);
3199
+ g(this, "C", Ie[2] | 0);
3200
+ g(this, "D", Ie[3] | 0);
3201
+ g(this, "E", Ie[4] | 0);
3202
+ g(this, "F", Ie[5] | 0);
3203
+ g(this, "G", Ie[6] | 0);
3204
+ g(this, "H", Ie[7] | 0);
3205
+ }
3206
+ }
3207
+ const lc = /* @__PURE__ */ Vn(
3208
+ () => new dc(),
3209
+ /* @__PURE__ */ Bt(1)
3210
+ ), hc = BigInt(0), dt = BigInt(1), yc = BigInt(2), pc = BigInt(7), gc = BigInt(256), bc = BigInt(113), ko = [], _o = [], Ko = [];
3211
+ for (let t = 0, e = dt, n = 1, r = 0; t < 24; t++) {
3212
+ [n, r] = [r, (2 * n + 3 * r) % 5], ko.push(2 * (5 * r + n)), _o.push((t + 1) * (t + 2) / 2 % 64);
3213
+ let o = hc;
3214
+ for (let s = 0; s < 7; s++)
3215
+ e = (e << dt ^ (e >> pc) * bc) % gc, e & yc && (o ^= dt << (dt << BigInt(s)) - dt);
3216
+ Ko.push(o);
3217
+ }
3218
+ const vo = oc(Ko, !0), wc = vo[0], xc = vo[1], Rr = (t, e, n) => n > 32 ? cc(t, e, n) : sc(t, e, n), Tr = (t, e, n) => n > 32 ? fc(t, e, n) : ic(t, e, n);
3219
+ function Ec(t, e = 24) {
3220
+ const n = new Uint32Array(10);
3221
+ for (let r = 24 - e; r < 24; r++) {
3222
+ for (let i = 0; i < 10; i++)
3223
+ n[i] = t[i] ^ t[i + 10] ^ t[i + 20] ^ t[i + 30] ^ t[i + 40];
3224
+ for (let i = 0; i < 10; i += 2) {
3225
+ const c = (i + 8) % 10, f = (i + 2) % 10, u = n[f], d = n[f + 1], a = Rr(u, d, 1) ^ n[c], y = Tr(u, d, 1) ^ n[c + 1];
3226
+ for (let l = 0; l < 50; l += 10)
3227
+ t[i + l] ^= a, t[i + l + 1] ^= y;
3228
+ }
3229
+ let o = t[2], s = t[3];
3230
+ for (let i = 0; i < 24; i++) {
3231
+ const c = _o[i], f = Rr(o, s, c), u = Tr(o, s, c), d = ko[i];
3232
+ o = t[d], s = t[d + 1], t[d] = f, t[d + 1] = u;
3233
+ }
3234
+ for (let i = 0; i < 50; i += 10) {
3235
+ for (let c = 0; c < 10; c++)
3236
+ n[c] = t[i + c];
3237
+ for (let c = 0; c < 10; c++)
3238
+ t[i + c] ^= ~n[(c + 2) % 10] & n[(c + 4) % 10];
3239
+ }
3240
+ t[0] ^= wc[r], t[1] ^= xc[r];
3241
+ }
3242
+ Ge(n);
3243
+ }
3244
+ class Jt {
3245
+ // NOTE: we accept arguments in bytes instead of bits here.
3246
+ constructor(e, n, r, o = !1, s = 24) {
3247
+ g(this, "state");
3248
+ g(this, "pos", 0);
3249
+ g(this, "posOut", 0);
3250
+ g(this, "finished", !1);
3251
+ g(this, "state32");
3252
+ g(this, "destroyed", !1);
3253
+ g(this, "blockLen");
3254
+ g(this, "suffix");
3255
+ g(this, "outputLen");
3256
+ g(this, "enableXOF", !1);
3257
+ g(this, "rounds");
3258
+ if (this.blockLen = e, this.suffix = n, this.outputLen = r, this.enableXOF = o, this.rounds = s, ze(r, "outputLen"), !(0 < e && e < 200))
3259
+ throw new Error("only keccak-f1600 function is supported");
3260
+ this.state = new Uint8Array(200), this.state32 = Uo(this.state);
3261
+ }
3262
+ clone() {
3263
+ return this._cloneInto();
3264
+ }
3265
+ keccak() {
3266
+ _r(this.state32), Ec(this.state32, this.rounds), _r(this.state32), this.posOut = 0, this.pos = 0;
3267
+ }
3268
+ update(e) {
3269
+ it(this), W(e);
3270
+ const { blockLen: n, state: r } = this, o = e.length;
3271
+ for (let s = 0; s < o; ) {
3272
+ const i = Math.min(n - this.pos, o - s);
3273
+ for (let c = 0; c < i; c++)
3274
+ r[this.pos++] ^= e[s++];
3275
+ this.pos === n && this.keccak();
3276
+ }
3277
+ return this;
3278
+ }
3279
+ finish() {
3280
+ if (this.finished)
3281
+ return;
3282
+ this.finished = !0;
3283
+ const { state: e, suffix: n, pos: r, blockLen: o } = this;
3284
+ e[r] ^= n, (n & 128) !== 0 && r === o - 1 && this.keccak(), e[o - 1] ^= 128, this.keccak();
3285
+ }
3286
+ writeInto(e) {
3287
+ it(this, !1), W(e), this.finish();
3288
+ const n = this.state, { blockLen: r } = this;
3289
+ for (let o = 0, s = e.length; o < s; ) {
3290
+ this.posOut >= r && this.keccak();
3291
+ const i = Math.min(r - this.posOut, s - o);
3292
+ e.set(n.subarray(this.posOut, this.posOut + i), o), this.posOut += i, o += i;
3293
+ }
3294
+ return e;
3295
+ }
3296
+ xofInto(e) {
3297
+ if (!this.enableXOF)
3298
+ throw new Error("XOF is not possible for this instance");
3299
+ return this.writeInto(e);
3300
+ }
3301
+ xof(e) {
3302
+ return ze(e), this.xofInto(new Uint8Array(e));
3303
+ }
3304
+ digestInto(e) {
3305
+ if (Ho(e, this), this.finished)
3306
+ throw new Error("digest() was already called");
3307
+ return this.writeInto(e), this.destroy(), e;
3308
+ }
3309
+ digest() {
3310
+ return this.digestInto(new Uint8Array(this.outputLen));
3311
+ }
3312
+ destroy() {
3313
+ this.destroyed = !0, Ge(this.state);
3314
+ }
3315
+ _cloneInto(e) {
3316
+ const { blockLen: n, suffix: r, outputLen: o, rounds: s, enableXOF: i } = this;
3317
+ return e || (e = new Jt(n, r, o, i, s)), e.state32.set(this.state32), e.pos = this.pos, e.posOut = this.posOut, e.finished = this.finished, e.rounds = s, e.suffix = r, e.outputLen = o, e.enableXOF = i, e.destroyed = this.destroyed, e;
3318
+ }
3319
+ }
3320
+ const Ro = (t, e, n, r = {}) => Vn(() => new Jt(e, t, n), r), Lt = /* @__PURE__ */ Ro(
3321
+ 6,
3322
+ 136,
3323
+ 32,
3324
+ /* @__PURE__ */ Bt(8)
3325
+ ), mc = /* @__PURE__ */ Ro(
3326
+ 6,
3327
+ 72,
3328
+ 64,
3329
+ /* @__PURE__ */ Bt(10)
3330
+ ), To = (t, e, n, r = {}) => Vn((o = {}) => new Jt(e, t, o.dkLen === void 0 ? n : o.dkLen, !0), r), Ac = /* @__PURE__ */ To(31, 168, 16, /* @__PURE__ */ Bt(11)), Ye = /* @__PURE__ */ To(31, 136, 32, /* @__PURE__ */ Bt(12));
3331
+ function Yn(t) {
3332
+ if (!Number.isSafeInteger(t) || t < 0 || t > 4294967295)
3333
+ throw new Error("wrong u32 integer:" + t);
3334
+ return t;
3335
+ }
3336
+ function Co(t) {
3337
+ return Yn(t), (t & t - 1) === 0 && t !== 0;
3338
+ }
3339
+ function Oo(t, e) {
3340
+ Yn(t);
3341
+ let n = 0;
3342
+ for (let r = 0; r < e; r++, t >>>= 1)
3343
+ n = n << 1 | t & 1;
3344
+ return n;
3345
+ }
3346
+ function $o(t) {
3347
+ return Yn(t), 31 - Math.clz32(t);
3348
+ }
3349
+ function Cr(t) {
3350
+ const e = t.length;
3351
+ if (e < 2 || !Co(e))
3352
+ throw new Error("n must be a power of 2 and greater than 1. Got " + e);
3353
+ const n = $o(e);
3354
+ for (let r = 0; r < e; r++) {
3355
+ const o = Oo(r, n);
3356
+ if (r < o) {
3357
+ const s = t[r];
3358
+ t[r] = t[o], t[o] = s;
3359
+ }
3360
+ }
3361
+ return t;
3362
+ }
3363
+ const Or = (t, e) => {
3364
+ const { N: n, roots: r, dit: o, invertButterflies: s = !1, skipStages: i = 0, brp: c = !0 } = e, f = $o(n);
3365
+ if (!Co(n))
3366
+ throw new Error("FFT: Polynomial size should be power of two");
3367
+ const u = o !== s;
3368
+ return (d) => {
3369
+ if (d.length !== n)
3370
+ throw new Error("FFT: wrong Polynomial length");
3371
+ o && c && Cr(d);
3372
+ for (let a = 0, y = 1; a < f - i; a++) {
3373
+ const l = o ? a + 1 + i : f - a, b = 1 << l, E = b >> 1, x = n >> l;
3374
+ for (let w = 0; w < n; w += b)
3375
+ for (let H = 0, k = y++; H < E; H++) {
3376
+ const O = s ? o ? n - k : k : H * x, $ = w + H, R = w + H + E, N = r[O], T = d[R], S = d[$];
3377
+ if (u) {
3378
+ const M = t.mul(T, N);
3379
+ d[$] = t.add(S, M), d[R] = t.sub(S, M);
3380
+ } else s ? (d[$] = t.add(T, S), d[R] = t.mul(t.sub(T, S), N)) : (d[$] = t.add(S, T), d[R] = t.mul(t.sub(S, T), N));
3381
+ }
3382
+ }
3383
+ return !o && c && Cr(d), d;
3384
+ };
3385
+ };
3386
+ /*! noble-post-quantum - MIT License (c) 2024 Paul Miller (paulmillr.com) */
3387
+ const Re = Wi;
3388
+ function gn(t, e) {
3389
+ if (t.length !== e.length)
3390
+ return !1;
3391
+ let n = 0;
3392
+ for (let r = 0; r < t.length; r++)
3393
+ n |= t[r] ^ e[r];
3394
+ return n === 0;
3395
+ }
3396
+ function Bc(t) {
3397
+ return Uint8Array.from(t);
3398
+ }
3399
+ function pt(t, ...e) {
3400
+ const n = (o) => typeof o == "number" ? o : o.bytesLen, r = e.reduce((o, s) => o + n(s), 0);
3401
+ return {
3402
+ bytesLen: r,
3403
+ encode: (o) => {
3404
+ const s = new Uint8Array(r);
3405
+ for (let i = 0, c = 0; i < e.length; i++) {
3406
+ const f = e[i], u = n(f), d = typeof f == "number" ? o[i] : f.encode(o[i]);
3407
+ W(d, u, t), s.set(d, c), typeof f != "number" && d.fill(0), c += u;
3408
+ }
3409
+ return s;
3410
+ },
3411
+ decode: (o) => {
3412
+ W(o, r, t);
3413
+ const s = [];
3414
+ for (const i of e) {
3415
+ const c = n(i), f = o.subarray(0, c);
3416
+ s.push(typeof i == "number" ? f : i.decode(f)), o = o.subarray(c);
3417
+ }
3418
+ return s;
3419
+ }
3420
+ };
3421
+ }
3422
+ function bn(t, e) {
3423
+ const n = e * t.bytesLen;
3424
+ return {
3425
+ bytesLen: n,
3426
+ encode: (r) => {
3427
+ if (r.length !== e)
3428
+ throw new Error(`vecCoder.encode: wrong length=${r.length}. Expected: ${e}`);
3429
+ const o = new Uint8Array(n);
3430
+ for (let s = 0, i = 0; s < r.length; s++) {
3431
+ const c = t.encode(r[s]);
3432
+ o.set(c, i), c.fill(0), i += c.length;
3433
+ }
3434
+ return o;
3435
+ },
3436
+ decode: (r) => {
3437
+ W(r, n);
3438
+ const o = [];
3439
+ for (let s = 0; s < r.length; s += t.bytesLen)
3440
+ o.push(t.decode(r.subarray(s, s + t.bytesLen)));
3441
+ return o;
3442
+ }
3443
+ };
3444
+ }
3445
+ function oe(...t) {
3446
+ for (const e of t)
3447
+ if (Array.isArray(e))
3448
+ for (const n of e)
3449
+ n.fill(0);
3450
+ else
3451
+ e.fill(0);
3452
+ }
3453
+ function $r(t) {
3454
+ return (1 << t) - 1;
3455
+ }
3456
+ /*! noble-post-quantum - MIT License (c) 2024 Paul Miller (paulmillr.com) */
3457
+ const Lc = (t) => {
3458
+ const { newPoly: e, N: n, Q: r, F: o, ROOT_OF_UNITY: s, brvBits: i } = t, c = (w, H = r) => {
3459
+ const k = w % H | 0;
3460
+ return (k >= 0 ? k | 0 : H + k | 0) | 0;
3461
+ }, f = (w, H = r) => {
3462
+ const k = c(w, H) | 0;
3463
+ return (k > H >> 1 ? k - H | 0 : k) | 0;
3464
+ };
3465
+ function u() {
3466
+ const w = e(n);
3467
+ for (let H = 0; H < n; H++) {
3468
+ const k = Oo(H, i), O = BigInt(s) ** BigInt(k) % BigInt(r);
3469
+ w[H] = Number(O) | 0;
3470
+ }
3471
+ return w;
3472
+ }
3473
+ const d = u(), a = {
3474
+ add: (w, H) => c((w | 0) + (H | 0)) | 0,
3475
+ sub: (w, H) => c((w | 0) - (H | 0)) | 0,
3476
+ mul: (w, H) => c((w | 0) * (H | 0)) | 0,
3477
+ inv: (w) => {
3478
+ throw new Error("not implemented");
3479
+ }
3480
+ }, y = {
3481
+ N: n,
3482
+ roots: d,
3483
+ invertButterflies: !0,
3484
+ skipStages: 1,
3485
+ brp: !1
3486
+ }, l = Or(a, { dit: !1, ...y }), b = Or(a, { dit: !0, ...y });
3487
+ return { mod: c, smod: f, nttZetas: d, NTT: {
3488
+ encode: (w) => l(w),
3489
+ decode: (w) => {
3490
+ b(w);
3491
+ for (let H = 0; H < w.length; H++)
3492
+ w[H] = c(o * w[H]);
3493
+ return w;
3494
+ }
3495
+ }, bitsCoder: (w, H) => {
3496
+ const k = $r(w), O = w * (n / 8);
3497
+ return {
3498
+ bytesLen: O,
3499
+ encode: ($) => {
3500
+ const R = new Uint8Array(O);
3501
+ for (let N = 0, T = 0, S = 0, M = 0; N < $.length; N++)
3502
+ for (T |= (H.encode($[N]) & k) << S, S += w; S >= 8; S -= 8, T >>= 8)
3503
+ R[M++] = T & $r(S);
3504
+ return R;
3505
+ },
3506
+ decode: ($) => {
3507
+ const R = e(n);
3508
+ for (let N = 0, T = 0, S = 0, M = 0; N < $.length; N++)
3509
+ for (T |= $[N] << S, S += 8; S >= w; S -= w, T >>= w)
3510
+ R[M++] = H.decode(T & k);
3511
+ return R;
3512
+ }
3513
+ };
3514
+ } };
3515
+ }, Sc = (t) => (e, n) => {
3516
+ n || (n = t.blockLen);
3517
+ const r = new Uint8Array(e.length + 2);
3518
+ r.set(e);
3519
+ const o = e.length, s = new Uint8Array(n);
3520
+ let i = t.create({}), c = 0, f = 0;
3521
+ return {
3522
+ stats: () => ({ calls: c, xofs: f }),
3523
+ get: (u, d) => (r[o + 0] = u, r[o + 1] = d, i.destroy(), i = t.create({}).update(r), c++, () => (f++, i.xofInto(s))),
3524
+ clean: () => {
3525
+ i.destroy(), oe(s, r);
3526
+ }
3527
+ };
3528
+ }, Hc = /* @__PURE__ */ Sc(Ac);
3529
+ /*! noble-post-quantum - MIT License (c) 2024 Paul Miller (paulmillr.com) */
3530
+ const ce = 256, ve = 3329, Uc = 3303, Ic = 17, { mod: xt, nttZetas: kc, NTT: Te, bitsCoder: _c } = Lc({
3531
+ N: ce,
3532
+ Q: ve,
3533
+ F: Uc,
3534
+ ROOT_OF_UNITY: Ic,
3535
+ newPoly: (t) => new Uint16Array(t),
3536
+ brvBits: 7
3537
+ }), No = {
3538
+ 768: { N: ce, Q: ve, K: 3, ETA1: 2, ETA2: 2, du: 10, dv: 4, RBGstrength: 192 },
3539
+ 1024: { N: ce, Q: ve, K: 4, ETA1: 2, ETA2: 2, du: 11, dv: 5, RBGstrength: 256 }
3540
+ }, Kc = (t) => {
3541
+ if (t >= 12)
3542
+ return { encode: (n) => n, decode: (n) => n };
3543
+ const e = 2 ** (t - 1);
3544
+ return {
3545
+ // const compress = (i: number) => round((2 ** d / Q) * i) % 2 ** d;
3546
+ encode: (n) => ((n << t) + ve / 2) / ve,
3547
+ // const decompress = (i: number) => round((Q / 2 ** d) * i);
3548
+ decode: (n) => n * ve + e >>> t
3549
+ };
3550
+ }, lt = (t) => _c(t, Kc(t));
3551
+ function Ce(t, e) {
3552
+ for (let n = 0; n < ce; n++)
3553
+ t[n] = xt(t[n] + e[n]);
3554
+ }
3555
+ function vc(t, e) {
3556
+ for (let n = 0; n < ce; n++)
3557
+ t[n] = xt(t[n] - e[n]);
3558
+ }
3559
+ function Rc(t, e, n, r, o) {
3560
+ const s = xt(e * r * o + t * n), i = xt(t * r + e * n);
3561
+ return { c0: s, c1: i };
3562
+ }
3563
+ function Rt(t, e) {
3564
+ for (let n = 0; n < ce / 2; n++) {
3565
+ let r = kc[64 + (n >> 1)];
3566
+ n & 1 && (r = -r);
3567
+ const { c0: o, c1: s } = Rc(t[2 * n + 0], t[2 * n + 1], e[2 * n + 0], e[2 * n + 1], r);
3568
+ t[2 * n + 0] = o, t[2 * n + 1] = s;
3569
+ }
3570
+ return t;
3571
+ }
3572
+ function Nr(t) {
3573
+ const e = new Uint16Array(ce);
3574
+ for (let n = 0; n < ce; ) {
3575
+ const r = t();
3576
+ if (r.length % 3)
3577
+ throw new Error("SampleNTT: unaligned block");
3578
+ for (let o = 0; n < ce && o + 3 <= r.length; o += 3) {
3579
+ const s = (r[o + 0] >> 0 | r[o + 1] << 8) & 4095, i = (r[o + 1] >> 4 | r[o + 2] << 4) & 4095;
3580
+ s < ve && (e[n++] = s), n < ce && i < ve && (e[n++] = i);
3581
+ }
3582
+ }
3583
+ return e;
3584
+ }
3585
+ function ht(t, e, n, r) {
3586
+ const o = t(r * ce / 4, e, n), s = new Uint16Array(ce), i = Uo(o);
3587
+ let c = 0;
3588
+ for (let f = 0, u = 0, d = 0, a = 0; f < i.length; f++) {
3589
+ let y = i[f];
3590
+ for (let l = 0; l < 32; l++)
3591
+ d += y & 1, y >>= 1, c += 1, c === r ? (a = d, d = 0) : c === 2 * r && (s[u++] = xt(a - d), d = 0, c = 0);
3592
+ }
3593
+ if (c)
3594
+ throw new Error(`sampleCBD: leftover bits: ${c}`);
3595
+ return s;
3596
+ }
3597
+ const Tc = (t) => {
3598
+ const { K: e, PRF: n, XOF: r, HASH512: o, ETA1: s, ETA2: i, du: c, dv: f } = t, u = lt(1), d = lt(f), a = lt(c), y = pt("publicKey", bn(lt(12), e), 32), l = bn(lt(12), e), b = pt("ciphertext", bn(a, e), d), E = pt("seed", 32, 32);
3599
+ return {
3600
+ secretCoder: l,
3601
+ lengths: {
3602
+ secretKey: l.bytesLen,
3603
+ publicKey: y.bytesLen,
3604
+ cipherText: b.bytesLen
3605
+ },
3606
+ keygen: (x) => {
3607
+ W(x, 32, "seed");
3608
+ const w = new Uint8Array(33);
3609
+ w.set(x), w[32] = e;
3610
+ const H = o(w), [k, O] = E.decode(H), $ = [], R = [];
3611
+ for (let S = 0; S < e; S++)
3612
+ $.push(Te.encode(ht(n, O, S, s)));
3613
+ const N = r(k);
3614
+ for (let S = 0; S < e; S++) {
3615
+ const M = Te.encode(ht(n, O, e + S, s));
3616
+ for (let C = 0; C < e; C++) {
3617
+ const K = Nr(N.get(C, S));
3618
+ Ce(M, Rt(K, $[C]));
3619
+ }
3620
+ R.push(M);
3621
+ }
3622
+ N.clean();
3623
+ const T = {
3624
+ publicKey: y.encode([R, k]),
3625
+ secretKey: l.encode($)
3626
+ };
3627
+ return oe(k, O, $, R, w, H), T;
3628
+ },
3629
+ encrypt: (x, w, H) => {
3630
+ const [k, O] = y.decode(x), $ = [];
3631
+ for (let C = 0; C < e; C++)
3632
+ $.push(Te.encode(ht(n, H, C, s)));
3633
+ const R = r(O), N = new Uint16Array(ce), T = [];
3634
+ for (let C = 0; C < e; C++) {
3635
+ const K = ht(n, H, e + C, i), v = new Uint16Array(ce);
3636
+ for (let h = 0; h < e; h++) {
3637
+ const p = Nr(R.get(C, h));
3638
+ Ce(v, Rt(p, $[h]));
3639
+ }
3640
+ Ce(K, Te.decode(v)), T.push(K), Ce(N, Rt(k[C], $[C])), oe(v);
3641
+ }
3642
+ R.clean();
3643
+ const S = ht(n, H, 2 * e, i);
3644
+ Ce(S, Te.decode(N));
3645
+ const M = u.decode(w);
3646
+ return Ce(M, S), oe(k, $, N, S), b.encode([T, M]);
3647
+ },
3648
+ decrypt: (x, w) => {
3649
+ const [H, k] = b.decode(x), O = l.decode(w), $ = new Uint16Array(ce);
3650
+ for (let R = 0; R < e; R++)
3651
+ Ce($, Rt(O[R], Te.encode(H[R])));
3652
+ return vc(k, Te.decode($)), oe($, O, H), u.encode(k);
3653
+ }
3654
+ };
3655
+ };
3656
+ function Mo(t) {
3657
+ const e = Tc(t), { HASH256: n, HASH512: r, KDF: o } = t, { secretCoder: s, lengths: i } = e, c = pt("secretKey", i.secretKey, i.publicKey, 32, 32), f = 32, u = 64;
3658
+ return {
3659
+ info: { type: "ml-kem" },
3660
+ lengths: {
3661
+ ...i,
3662
+ seed: 64,
3663
+ msg: f,
3664
+ msgRand: f,
3665
+ secretKey: c.bytesLen
3666
+ },
3667
+ keygen: (d = Re(u)) => {
3668
+ W(d, u, "seed");
3669
+ const { publicKey: a, secretKey: y } = e.keygen(d.subarray(0, 32)), l = n(a), b = c.encode([y, a, l, d.subarray(32)]);
3670
+ return oe(y, l), { publicKey: a, secretKey: b };
3671
+ },
3672
+ getPublicKey: (d) => {
3673
+ const [a, y, l, b] = c.decode(d);
3674
+ return Uint8Array.from(y);
3675
+ },
3676
+ encapsulate: (d, a = Re(f)) => {
3677
+ W(d, i.publicKey, "publicKey"), W(a, f, "message");
3678
+ const y = d.subarray(0, 384 * t.K), l = s.encode(s.decode(Bc(y)));
3679
+ if (!gn(l, y))
3680
+ throw oe(l), new Error("ML-KEM.encapsulate: wrong publicKey modulus");
3681
+ oe(l);
3682
+ const b = r.create().update(a).update(n(d)).digest(), E = e.encrypt(d, a, b.subarray(32, 64));
3683
+ return oe(b.subarray(32)), { cipherText: E, sharedSecret: b.subarray(0, 32) };
3684
+ },
3685
+ decapsulate: (d, a) => {
3686
+ W(a, c.bytesLen, "secretKey"), W(d, i.cipherText, "cipherText");
3687
+ const y = c.bytesLen - 96, l = y + 32, b = n(a.subarray(y / 2, l));
3688
+ if (!gn(b, a.subarray(l, l + 32)))
3689
+ throw new Error("invalid secretKey: hash check failed");
3690
+ const [E, x, w, H] = c.decode(a), k = e.decrypt(d, E), O = r.create().update(k).update(w).digest(), $ = O.subarray(0, 32), R = e.encrypt(x, k, O.subarray(32, 64)), N = gn(d, R), T = o.create({ dkLen: 32 }).update(H).update(d).digest();
3691
+ return oe(k, R, N ? T : $), N ? $ : T;
3692
+ }
3693
+ };
3694
+ }
3695
+ function Cc(t, e, n) {
3696
+ return Ye.create({ dkLen: t }).update(e).update(new Uint8Array([n])).digest();
3697
+ }
3698
+ const Fo = {
3699
+ HASH256: Lt,
3700
+ HASH512: mc,
3701
+ KDF: Ye,
3702
+ XOF: Hc,
3703
+ PRF: Cc
3704
+ }, en = /* @__PURE__ */ Mo({
3705
+ ...Fo,
3706
+ ...No[768]
3707
+ }), Oc = /* @__PURE__ */ Mo({
3708
+ ...Fo,
3709
+ ...No[1024]
3710
+ });
3711
+ /*! noble-post-quantum - MIT License (c) 2024 Paul Miller (paulmillr.com) */
3712
+ function $c(t, e = !1) {
3713
+ const n = t.lengths;
3714
+ let r = t.keygen;
3715
+ if (e) {
3716
+ const s = t.Point.Fn;
3717
+ if (!s)
3718
+ throw new Error("No Point.Fn");
3719
+ r = (i = Re(n.seed)) => {
3720
+ W(i, n.seed, "seed");
3721
+ const c = s.isLE ? wt(i) : At(i), f = s.toBytes(s.create(c));
3722
+ return { secretKey: f, publicKey: t.getPublicKey(f) };
3723
+ };
3724
+ }
3725
+ return {
3726
+ lengths: { secretKey: n.secretKey, publicKey: n.publicKey, seed: n.seed },
3727
+ keygen: r,
3728
+ getPublicKey: (o) => t.getPublicKey(o)
3729
+ };
3730
+ }
3731
+ function Zn(t, e = !1) {
3732
+ const n = $c(t, e);
3733
+ if (!t.getSharedSecret)
3734
+ throw new Error("wrong curve");
3735
+ return {
3736
+ lengths: { ...n.lengths, msg: n.lengths.seed, cipherText: n.lengths.publicKey },
3737
+ keygen: n.keygen,
3738
+ getPublicKey: n.getPublicKey,
3739
+ encapsulate(r, o = Re(t.lengths.seed)) {
3740
+ const s = this.keygen(o).secretKey, i = this.decapsulate(r, s), c = t.getPublicKey(s);
3741
+ return oe(s), { sharedSecret: i, cipherText: c };
3742
+ },
3743
+ decapsulate(r, o) {
3744
+ const s = t.getSharedSecret(o, r);
3745
+ return t.lengths.publicKeyHasPrefix ? s.subarray(1) : s;
3746
+ }
3747
+ };
3748
+ }
3749
+ function gt(t, e) {
3750
+ return pt(e, ...t.map((n) => {
3751
+ if (typeof n.lengths[e] != "number")
3752
+ throw new Error("wrong length: " + e);
3753
+ return n.lengths[e];
3754
+ }));
3755
+ }
3756
+ function Xn(t) {
3757
+ return (e, n) => t(e, { dkLen: n });
3758
+ }
3759
+ function Nc(t, e, ...n) {
3760
+ const r = gt(n, "seed"), o = gt(n, "publicKey");
3761
+ ze(t);
3762
+ function s(i) {
3763
+ W(i, t);
3764
+ const c = r.decode(e(i, r.bytesLen)), f = n.map((a, y) => a.keygen(c[y])), u = f.map((a) => a.secretKey), d = f.map((a) => a.publicKey);
3765
+ return { secretKey: u, publicKey: d };
3766
+ }
3767
+ return {
3768
+ info: { lengths: { seed: t, publicKey: o.bytesLen, secretKey: t } },
3769
+ getPublicKey(i) {
3770
+ return this.keygen(i).publicKey;
3771
+ },
3772
+ keygen(i = Re(t)) {
3773
+ const { publicKey: c, secretKey: f } = s(i), u = o.encode(c);
3774
+ return oe(c), oe(f), { secretKey: i, publicKey: u };
3775
+ },
3776
+ expandDecapsulationKey: s,
3777
+ realSeedLen: t
3778
+ };
3779
+ }
3780
+ function tn(t, e, n, r, ...o) {
3781
+ const s = Nc(t, n, ...o), i = gt(o, "cipherText"), c = gt(o, "publicKey"), f = gt(o, "msg");
3782
+ return ze(e), {
3783
+ lengths: {
3784
+ ...s.info.lengths,
3785
+ msg: e,
3786
+ msgRand: f.bytesLen,
3787
+ cipherText: i.bytesLen
3788
+ },
3789
+ getPublicKey: s.getPublicKey,
3790
+ keygen: s.keygen,
3791
+ encapsulate(u, d = Re(f.bytesLen)) {
3792
+ const a = c.decode(u), y = f.decode(d), l = o.map((w, H) => w.encapsulate(a[H], y[H])), b = l.map((w) => w.sharedSecret), E = l.map((w) => w.cipherText), x = {
3793
+ sharedSecret: r(a, E, b),
3794
+ cipherText: i.encode(E)
3795
+ };
3796
+ return oe(b, E), x;
3797
+ },
3798
+ decapsulate(u, d) {
3799
+ const a = i.decode(u), { publicKey: y, secretKey: l } = s.expandDecapsulationKey(d), b = o.map((E, x) => E.decapsulate(a[x], l[x]));
3800
+ return r(y, a, b);
3801
+ }
3802
+ };
3803
+ }
3804
+ function Po(t, e, n, r, o) {
3805
+ return Ve(r), Ve(o), tn(32, 32, Xn(r), (s, i, c) => o(ie(c[0], c[1], i[1], s[1], Me(t))), e, n);
3806
+ }
3807
+ Po("QSF-KEM(ML-KEM-768,P-256)-XOF(SHAKE256)-KDF(SHA3-256)", en, Zn(Oe, !0), Ye, Lt);
3808
+ Po("QSF-KEM(ML-KEM-1024,P-384)-XOF(SHAKE256)-KDF(SHA3-256)", Oc, Zn(Vi, !0), Ye, Lt);
3809
+ function Mc(t, e, n, r, o) {
3810
+ return Ve(r), Ve(o), tn(32, 32, Xn(r), (s, i, c) => {
3811
+ const f = ie(c[0], c[1], i[0], s[0], i[1], s[1], Me(t)), u = 32, d = ie(Me("hybrid_prk"), f), a = Qi(o, d), y = ie(Wt(u, 2), Me("shared_secret"), Me("")), l = Ji(o, a, y, u);
3812
+ return oe(a, y, d, f), l;
3813
+ }, e, n);
3814
+ }
3815
+ const Do = Zn(Vt);
3816
+ Mc("KitchenSink-KEM(ML-KEM-768,X25519)-XOF(SHAKE256)-KDF(HKDF-SHA-256)", en, Do, Ye, lc);
3817
+ const Fc = tn(
3818
+ 32,
3819
+ 32,
3820
+ Xn(Ye),
3821
+ // Awesome label, so much escaping hell in a single line.
3822
+ (t, e, n) => Lt(ie(n[0], n[1], e[1], t[1], Me("\\.//^\\"))),
3823
+ en,
3824
+ Do
3825
+ );
3826
+ function Pc(t, e, n, r) {
3827
+ const o = t.Point.Fn;
3828
+ if (!o)
3829
+ throw new Error("no Point.Fn");
3830
+ function s(i) {
3831
+ let c;
3832
+ for (let d = 0, a = e; ; d = a, a += e) {
3833
+ if (a > i.length)
3834
+ throw new Error("rejection sampling failed");
3835
+ if (c = o.fromBytes(i.subarray(d, a), !0), o.isValidNot0(c))
3836
+ break;
3837
+ }
3838
+ const f = o.toBytes(o.create(c)), u = t.getPublicKey(f, !1);
3839
+ return { secretKey: f, publicKey: u };
3840
+ }
3841
+ return {
3842
+ lengths: {
3843
+ secretKey: e,
3844
+ publicKey: n,
3845
+ seed: r,
3846
+ msg: r,
3847
+ cipherText: n
3848
+ },
3849
+ keygen(i = Re(r)) {
3850
+ return W(i, r, "seed"), s(i);
3851
+ },
3852
+ getPublicKey(i) {
3853
+ return t.getPublicKey(i, !1);
3854
+ },
3855
+ encapsulate(i, c = Re(r)) {
3856
+ W(c, r, "rand");
3857
+ const { secretKey: f } = s(c), u = this.decapsulate(i, f), d = t.getPublicKey(f, !1);
3858
+ return oe(f), { sharedSecret: u, cipherText: d };
3859
+ },
3860
+ decapsulate(i, c) {
3861
+ return t.getSharedSecret(c, i).subarray(1);
3862
+ }
3863
+ };
3864
+ }
3865
+ function Dc(t, e, n, r) {
3866
+ const { secretKey: o, publicKeyUncompressed: s } = n.lengths;
3867
+ if (!o || !s)
3868
+ throw new Error("wrong curve");
3869
+ const i = Pc(n, o, s, r), c = 64, f = c + r;
3870
+ return tn(32, 32, (u) => {
3871
+ W(u, 32);
3872
+ const d = Ye(u, { dkLen: f }), a = d.subarray(0, c), y = d.subarray(c, f);
3873
+ return ie(a, y);
3874
+ }, (u, d, a) => Lt(ie(a[0], a[1], d[1], u[1], Me(t))), e, i);
3875
+ }
3876
+ const jc = Dc("MLKEM768-P256", en, Oe, 128), Wn = Fc, qc = jc, jo = !1;
3877
+ async function qo(t, e) {
3878
+ try {
3879
+ return await t();
3880
+ } catch (n) {
3881
+ if (n instanceof ReferenceError || n instanceof DOMException && n.name === "NotSupportedError")
3882
+ return await e();
3883
+ throw n;
3884
+ }
3885
+ }
3886
+ async function Qn(t, e) {
3887
+ return await qo(async () => {
3888
+ const n = In(t) ? t : await Vc(t), r = await crypto.subtle.importKey("raw", e, { name: "X25519" }, jo, []);
3889
+ return new Uint8Array(await crypto.subtle.deriveBits({ name: "X25519", public: r }, n, 256));
3890
+ }, () => {
3891
+ if (In(t))
3892
+ throw new Error("CryptoKey provided but X25519 WebCrypto is not supported");
3893
+ return Vt.scalarMult(t, e);
3894
+ });
3895
+ }
3896
+ async function Gt(t) {
3897
+ return await qo(async () => Qn(t, Vt.GuBytes), () => {
3898
+ if (In(t))
3899
+ throw new Error("CryptoKey provided but X25519 WebCrypto is not supported");
3900
+ return Vt.scalarMultBase(t);
3901
+ });
3902
+ }
3903
+ const zc = /* @__PURE__ */ new Uint8Array([
3904
+ 48,
3905
+ 46,
3906
+ 2,
3907
+ 1,
3908
+ 0,
3909
+ 48,
3910
+ 5,
3911
+ 6,
3912
+ 3,
3913
+ 43,
3914
+ 101,
3915
+ 110,
3916
+ 4,
3917
+ 34,
3918
+ 4,
3919
+ 32
3920
+ ]);
3921
+ async function Vc(t) {
3922
+ if (t.length !== 32)
3923
+ throw new Error("X25519 private key must be 32 bytes");
3924
+ const e = new Uint8Array([...zc, ...t]);
3925
+ return crypto.subtle.importKey("pkcs8", e, { name: "X25519" }, jo, ["deriveBits"]);
3926
+ }
3927
+ function In(t) {
3928
+ return typeof CryptoKey < "u" && t instanceof CryptoKey;
3929
+ }
3930
+ class Gc {
3931
+ constructor(e) {
3932
+ g(this, "s");
3933
+ g(this, "transcript", []);
3934
+ g(this, "buf", new Uint8Array(0));
3935
+ this.s = e.getReader();
3936
+ }
3937
+ async readLine() {
3938
+ const e = [];
3939
+ for (; ; ) {
3940
+ const n = this.buf.indexOf(10);
3941
+ if (n >= 0)
3942
+ return e.push(this.buf.subarray(0, n)), this.transcript.push(this.buf.subarray(0, n + 1)), this.buf = this.buf.subarray(n + 1), Yc(tt(e));
3943
+ this.buf.length > 0 && (e.push(this.buf), this.transcript.push(this.buf));
3944
+ const r = await this.s.read();
3945
+ if (r.done)
3946
+ return this.buf = tt(e), null;
3947
+ this.buf = r.value;
3948
+ }
3949
+ }
3950
+ close() {
3951
+ return this.s.releaseLock(), { rest: this.buf, transcript: tt(this.transcript) };
3952
+ }
3953
+ }
3954
+ function Yc(t) {
3955
+ return t.forEach((e) => {
3956
+ if (e < 32 || e > 126)
3957
+ throw Error("invalid non-ASCII byte in header");
3958
+ }), new TextDecoder().decode(t);
3959
+ }
3960
+ function tt(t) {
3961
+ const e = t.reduce(((o, s) => o + s.length), 0), n = new Uint8Array(e);
3962
+ let r = 0;
3963
+ for (const o of t)
3964
+ n.set(o, r), r += o.length;
3965
+ return n;
3966
+ }
3967
+ function Yt(t, ...e) {
3968
+ return t.pipeThrough(new TransformStream({
3969
+ start(n) {
3970
+ for (const r of e)
3971
+ n.enqueue(r);
3972
+ }
3973
+ }));
3974
+ }
3975
+ function kn(t) {
3976
+ return new ReadableStream({
3977
+ start(e) {
3978
+ e.enqueue(t), e.close();
3979
+ }
3980
+ });
3981
+ }
3982
+ async function zo(t) {
3983
+ if (!(t instanceof ReadableStream))
3984
+ throw new Error("readAll expects a ReadableStream<Uint8Array>");
3985
+ return new Uint8Array(await new Response(t).arrayBuffer());
3986
+ }
3987
+ async function Zc(t) {
3988
+ if (!(t instanceof ReadableStream))
3989
+ throw new Error("readAllString expects a ReadableStream<Uint8Array>");
3990
+ return await new Response(t).text();
3991
+ }
3992
+ async function Xc(t, e) {
3993
+ const n = t.getReader(), r = [];
3994
+ let o = 0;
3995
+ for (; o < e; ) {
3996
+ const { done: f, value: u } = await n.read();
3997
+ if (f)
3998
+ throw Error("stream ended before reading " + e.toString() + " bytes");
3999
+ r.push(u), o += u.length;
4000
+ }
4001
+ n.releaseLock();
4002
+ const s = tt(r), i = s.subarray(0, e), c = Yt(t, s.subarray(e));
4003
+ return { data: i, rest: c };
4004
+ }
4005
+ class Ze {
4006
+ constructor(e, n) {
4007
+ /**
4008
+ * All space-separated arguments on the first line of the stanza.
4009
+ * Each argument is a string that does not contain spaces.
4010
+ * The first argument is often a recipient type, which should look like
4011
+ * `example.com/...` to avoid collisions.
4012
+ */
4013
+ g(this, "args");
4014
+ /**
4015
+ * The raw body of the stanza. This is automatically base64-encoded and
4016
+ * split into lines of 48 characters each.
4017
+ */
4018
+ g(this, "body");
4019
+ this.args = e, this.body = n;
4020
+ }
4021
+ }
4022
+ async function Wc(t) {
4023
+ const e = await t.readLine();
4024
+ if (e === null)
4025
+ throw Error("invalid stanza");
4026
+ const n = e.split(" ");
4027
+ if (n.length < 2 || n.shift() !== "->")
4028
+ return { next: e };
4029
+ for (const s of n)
4030
+ if (s.length === 0)
4031
+ throw Error("invalid stanza");
4032
+ const r = [];
4033
+ for (; ; ) {
4034
+ const s = await t.readLine();
4035
+ if (s === null)
4036
+ throw Error("invalid stanza");
4037
+ const i = se.decode(s);
4038
+ if (i.length > 48)
4039
+ throw Error("invalid stanza");
4040
+ if (r.push(i), i.length < 48)
4041
+ break;
4042
+ }
4043
+ const o = tt(r);
4044
+ return { s: new Ze(n, o) };
4045
+ }
4046
+ async function Qc(t) {
4047
+ const e = new Gc(t), n = await e.readLine();
4048
+ if (n !== "age-encryption.org/v1")
4049
+ throw Error("invalid version " + (n ?? "line"));
4050
+ const r = [];
4051
+ for (; ; ) {
4052
+ const { s: o, next: s } = await Wc(e);
4053
+ if (o !== void 0) {
4054
+ r.push(o);
4055
+ continue;
4056
+ }
4057
+ if (!s.startsWith("--- "))
4058
+ throw Error("invalid header");
4059
+ const i = se.decode(s.slice(4)), { rest: c, transcript: f } = e.close(), u = f.slice(0, f.length - 1 - s.length + 3);
4060
+ return { stanzas: r, headerNoMAC: u, MAC: i, headerSize: f.length, rest: Yt(t, c) };
4061
+ }
4062
+ }
4063
+ function Vo(t) {
4064
+ const e = [];
4065
+ e.push(`age-encryption.org/v1
4066
+ `);
4067
+ for (const n of t) {
4068
+ e.push("-> " + n.args.join(" ") + `
4069
+ `);
4070
+ for (let r = 0; r < n.body.length; r += 48) {
4071
+ let o = r + 48;
4072
+ o > n.body.length && (o = n.body.length), e.push(se.encode(n.body.subarray(r, o)) + `
4073
+ `);
4074
+ }
4075
+ n.body.length % 48 === 0 && e.push(`
4076
+ `);
4077
+ }
4078
+ return e.push("---"), new TextEncoder().encode(e.join(""));
4079
+ }
4080
+ function Jc(t, e) {
4081
+ return tt([
4082
+ Vo(t),
4083
+ new TextEncoder().encode(" " + se.encode(e) + `
4084
+ `)
4085
+ ]);
4086
+ }
4087
+ function Df() {
4088
+ return ef();
4089
+ }
4090
+ function ef() {
4091
+ const t = me(32), e = re.encodeFromBytes("AGE-SECRET-KEY-", t).toUpperCase();
4092
+ return Promise.resolve(e);
4093
+ }
4094
+ function jf() {
4095
+ const t = me(32), e = re.encodeFromBytes("AGE-SECRET-KEY-PQ-", t).toUpperCase();
4096
+ return Promise.resolve(e);
4097
+ }
4098
+ async function qf(t) {
4099
+ let e;
4100
+ if (Yo(t))
4101
+ e = t;
4102
+ else if (t.startsWith("AGE-SECRET-KEY-PQ-1")) {
4103
+ const r = re.decodeToBytes(t);
4104
+ if (r.prefix.toUpperCase() !== "AGE-SECRET-KEY-PQ-" || r.bytes.length !== 32)
4105
+ throw Error("invalid identity");
4106
+ const o = Wn.getPublicKey(r.bytes);
4107
+ return re.encode("age1pq", re.toWords(o), !1);
4108
+ } else {
4109
+ const r = re.decodeToBytes(t);
4110
+ if (!t.startsWith("AGE-SECRET-KEY-1") || r.prefix.toUpperCase() !== "AGE-SECRET-KEY-" || r.bytes.length !== 32)
4111
+ throw Error("invalid identity");
4112
+ e = r.bytes;
4113
+ }
4114
+ const n = await Gt(e);
4115
+ return re.encodeFromBytes("age", n);
4116
+ }
4117
+ class tf {
4118
+ constructor(e) {
4119
+ g(this, "recipient");
4120
+ const n = re.decodeToBytes(e);
4121
+ if (!e.startsWith("age1pq1") || n.prefix.toLowerCase() !== "age1pq" || n.bytes.length !== 1216)
4122
+ throw Error("invalid recipient");
4123
+ this.recipient = n.bytes;
4124
+ }
4125
+ wrapFileKey(e) {
4126
+ const { cipherText: n, sharedSecret: r } = Wn.encapsulate(this.recipient), o = new TextEncoder().encode("age-encryption.org/mlkem768x25519"), { key: s, nonce: i } = nn(Go, r, o), c = ge(s, i).encrypt(e);
4127
+ return [new Ze(["mlkem768x25519", se.encode(n)], c)];
4128
+ }
4129
+ }
4130
+ class nf {
4131
+ constructor(e) {
4132
+ g(this, "identity");
4133
+ const n = re.decodeToBytes(e);
4134
+ if (!e.startsWith("AGE-SECRET-KEY-PQ-1") || n.prefix.toUpperCase() !== "AGE-SECRET-KEY-PQ-" || n.bytes.length !== 32)
4135
+ throw Error("invalid identity");
4136
+ this.identity = n.bytes;
4137
+ }
4138
+ unwrapFileKey(e) {
4139
+ for (const n of e) {
4140
+ if (n.args.length < 1 || n.args[0] !== "mlkem768x25519")
4141
+ continue;
4142
+ if (n.args.length !== 2)
4143
+ throw Error("invalid mlkem768x25519 stanza");
4144
+ const r = se.decode(n.args[1]);
4145
+ if (r.length !== 1120 || n.body.length !== 32)
4146
+ throw Error("invalid mlkem768x25519 stanza");
4147
+ const o = Wn.decapsulate(r, this.identity), s = new TextEncoder().encode("age-encryption.org/mlkem768x25519"), { key: i, nonce: c } = nn(Go, o, s);
4148
+ try {
4149
+ return ge(i, c).decrypt(n.body);
4150
+ } catch {
4151
+ continue;
4152
+ }
4153
+ }
4154
+ return null;
4155
+ }
4156
+ }
4157
+ const Go = 25722, rf = 80, _n = 16;
4158
+ function nn(t, e, n) {
4159
+ const r = of(t), o = $t(r, void 0, "psk_id_hash", new Uint8Array(0)), s = $t(r, void 0, "info_hash", n), i = new Uint8Array(1 + o.length + s.length);
4160
+ i[0] = 0, i.set(o, 1), i.set(s, 1 + o.length);
4161
+ const c = $t(r, e, "secret", new Uint8Array(0)), f = Kn(r, c, "key", i, 32), u = Kn(r, c, "base_nonce", i, 12);
4162
+ return { key: f, nonce: u };
4163
+ }
4164
+ function of(t) {
4165
+ const e = new Uint8Array(10);
4166
+ return e.set(new TextEncoder().encode("HPKE"), 0), e[4] = t >> 8 & 255, e[5] = t & 255, e[6] = 0, e[7] = 1, e[8] = 0, e[9] = 3, e;
4167
+ }
4168
+ function $t(t, e, n, r) {
4169
+ const o = new Uint8Array(7 + t.length + n.length + r.length);
4170
+ let s = 0;
4171
+ return o.set(new TextEncoder().encode("HPKE-v1"), s), s += 7, o.set(t, s), s += t.length, o.set(new TextEncoder().encode(n), s), s += n.length, o.set(r, s), mt(ee, o, e);
4172
+ }
4173
+ function Kn(t, e, n, r, o) {
4174
+ const s = new Uint8Array(9 + t.length + n.length + r.length);
4175
+ let i = 0;
4176
+ return s[i] = o >> 8 & 255, s[i + 1] = o & 255, i += 2, s.set(new TextEncoder().encode("HPKE-v1"), i), i += 7, s.set(t, i), i += t.length, s.set(new TextEncoder().encode(n), i), i += n.length, s.set(r, i), Dr(ee, e, s, o);
4177
+ }
4178
+ function sf(t) {
4179
+ t.length !== Oe.lengths.publicKeyUncompressed && (t = Oe.Point.fromBytes(t).toBytes(!1));
4180
+ const e = Oe.utils.randomSecretKey(), n = Oe.getPublicKey(e, !1), r = Oe.getSharedSecret(e, t, !0).subarray(1), o = new Uint8Array(n.length + t.length);
4181
+ o.set(n, 0), o.set(t, n.length);
4182
+ const s = new Uint8Array(5);
4183
+ s.set(new TextEncoder().encode("KEM"), 0), s[3] = _n >> 8, s[4] = _n & 255;
4184
+ const i = $t(s, void 0, "eae_prk", r), c = Kn(s, i, "shared_secret", o, 32);
4185
+ return { encapsulatedKey: n, sharedSecret: c };
4186
+ }
4187
+ class cf {
4188
+ constructor(e) {
4189
+ g(this, "recipient");
4190
+ const n = re.decodeToBytes(e);
4191
+ if (!e.startsWith("age1tag1") || n.prefix.toLowerCase() !== "age1tag" || n.bytes.length !== 33)
4192
+ throw Error("invalid recipient");
4193
+ this.recipient = n.bytes;
4194
+ }
4195
+ wrapFileKey(e) {
4196
+ const { encapsulatedKey: n, sharedSecret: r } = sf(this.recipient), o = new TextEncoder().encode("age-encryption.org/p256tag"), s = (() => {
4197
+ const u = ee(this.recipient).subarray(0, 4), d = new Uint8Array(n.length + u.length);
4198
+ return d.set(n, 0), d.set(u, n.length), mt(ee, d, o).subarray(0, 4);
4199
+ })(), { key: i, nonce: c } = nn(_n, r, o), f = ge(i, c).encrypt(e);
4200
+ return [new Ze(["p256tag", se.encode(s), se.encode(n)], f)];
4201
+ }
4202
+ }
4203
+ class ff {
4204
+ constructor(e) {
4205
+ g(this, "recipient");
4206
+ const n = re.decodeToBytes(e);
4207
+ if (!e.startsWith("age1tagpq1") || n.prefix.toLowerCase() !== "age1tagpq" || n.bytes.length !== 1249)
4208
+ throw Error("invalid recipient");
4209
+ this.recipient = n.bytes;
4210
+ }
4211
+ wrapFileKey(e) {
4212
+ const { cipherText: n, sharedSecret: r } = qc.encapsulate(this.recipient), o = new TextEncoder().encode("age-encryption.org/mlkem768p256tag"), s = (() => {
4213
+ const u = ee(this.recipient.subarray(1184)).subarray(0, 4), d = new Uint8Array(n.length + u.length);
4214
+ return d.set(n, 0), d.set(u, n.length), mt(ee, d, o).subarray(0, 4);
4215
+ })(), { key: i, nonce: c } = nn(rf, r, o), f = ge(i, c).encrypt(e);
4216
+ return [new Ze(["mlkem768p256tag", se.encode(s), se.encode(n)], f)];
4217
+ }
4218
+ }
4219
+ class af {
4220
+ constructor(e) {
4221
+ g(this, "recipient");
4222
+ const n = re.decodeToBytes(e);
4223
+ if (!e.startsWith("age1") || n.prefix.toLowerCase() !== "age" || n.bytes.length !== 32)
4224
+ throw Error("invalid recipient");
4225
+ this.recipient = n.bytes;
4226
+ }
4227
+ async wrapFileKey(e) {
4228
+ const n = me(32), r = await Gt(n), o = await Qn(n, this.recipient), s = new Uint8Array(r.length + this.recipient.length);
4229
+ s.set(r), s.set(this.recipient, r.length);
4230
+ const i = new TextEncoder().encode("age-encryption.org/v1/X25519"), c = rt(ee, o, s, i, 32);
4231
+ return [new Ze(["X25519", se.encode(r)], Jn(e, c))];
4232
+ }
4233
+ }
4234
+ class Mr {
4235
+ constructor(e) {
4236
+ g(this, "identity");
4237
+ g(this, "recipient");
4238
+ if (Yo(e)) {
4239
+ this.identity = e, this.recipient = Gt(e);
4240
+ return;
4241
+ }
4242
+ const n = re.decodeToBytes(e);
4243
+ if (!e.startsWith("AGE-SECRET-KEY-1") || n.prefix.toUpperCase() !== "AGE-SECRET-KEY-" || n.bytes.length !== 32)
4244
+ throw Error("invalid identity");
4245
+ this.identity = n.bytes, this.recipient = Gt(n.bytes);
4246
+ }
4247
+ async unwrapFileKey(e) {
4248
+ for (const n of e) {
4249
+ if (n.args.length < 1 || n.args[0] !== "X25519")
4250
+ continue;
4251
+ if (n.args.length !== 2)
4252
+ throw Error("invalid X25519 stanza");
4253
+ const r = se.decode(n.args[1]);
4254
+ if (r.length !== 32)
4255
+ throw Error("invalid X25519 stanza");
4256
+ const o = await Qn(this.identity, r), s = await this.recipient, i = new Uint8Array(r.length + s.length);
4257
+ i.set(r), i.set(s, r.length);
4258
+ const c = new TextEncoder().encode("age-encryption.org/v1/X25519"), f = rt(ee, o, i, c, 32), u = er(n.body, f);
4259
+ if (u !== null)
4260
+ return u;
4261
+ }
4262
+ return null;
4263
+ }
4264
+ }
4265
+ class uf {
4266
+ constructor(e, n) {
4267
+ g(this, "passphrase");
4268
+ g(this, "logN");
4269
+ this.passphrase = e, this.logN = n;
4270
+ }
4271
+ wrapFileKey(e) {
4272
+ const n = me(16), r = "age-encryption.org/v1/scrypt", o = new Uint8Array(r.length + 16);
4273
+ o.set(new TextEncoder().encode(r)), o.set(n, r.length);
4274
+ const s = Yr(this.passphrase, o, { N: 2 ** this.logN, r: 8, p: 1, dkLen: 32 });
4275
+ return [new Ze(["scrypt", se.encode(n), this.logN.toString()], Jn(e, s))];
4276
+ }
4277
+ }
4278
+ class df {
4279
+ constructor(e) {
4280
+ g(this, "passphrase");
4281
+ this.passphrase = e;
4282
+ }
4283
+ unwrapFileKey(e) {
4284
+ for (const n of e) {
4285
+ if (n.args.length < 1 || n.args[0] !== "scrypt")
4286
+ continue;
4287
+ if (e.length !== 1)
4288
+ throw Error("scrypt recipient is not the only one in the header");
4289
+ if (n.args.length !== 3 || !/^[1-9][0-9]*$/.test(n.args[2]))
4290
+ throw Error("invalid scrypt stanza");
4291
+ const r = se.decode(n.args[1]);
4292
+ if (r.length !== 16)
4293
+ throw Error("invalid scrypt stanza");
4294
+ const o = Number(n.args[2]);
4295
+ if (o > 20)
4296
+ throw Error("scrypt work factor is too high");
4297
+ const s = "age-encryption.org/v1/scrypt", i = new Uint8Array(s.length + 16);
4298
+ i.set(new TextEncoder().encode(s)), i.set(r, s.length);
4299
+ const c = Yr(this.passphrase, i, { N: 2 ** o, r: 8, p: 1, dkLen: 32 }), f = er(n.body, c);
4300
+ if (f !== null)
4301
+ return f;
4302
+ }
4303
+ return null;
4304
+ }
4305
+ }
4306
+ function Jn(t, e) {
4307
+ const n = new Uint8Array(12);
4308
+ return ge(e, n).encrypt(t);
4309
+ }
4310
+ function er(t, e) {
4311
+ if (t.length !== 32)
4312
+ throw Error("invalid stanza");
4313
+ const n = new Uint8Array(12);
4314
+ try {
4315
+ return ge(e, n).decrypt(t);
4316
+ } catch {
4317
+ return null;
4318
+ }
4319
+ }
4320
+ function Yo(t) {
4321
+ return typeof CryptoKey < "u" && t instanceof CryptoKey;
4322
+ }
4323
+ const $e = 16, tr = 64 * 1024, vn = tr + $e;
4324
+ function lf(t) {
4325
+ const e = new Uint8Array(12), n = () => {
4326
+ for (let i = e.length - 2; i >= 0 && (e[i]++, e[i] === 0); i--)
4327
+ ;
4328
+ };
4329
+ let r = !0;
4330
+ const o = new Uint8Array(vn);
4331
+ let s = 0;
4332
+ return new TransformStream({
4333
+ transform(i, c) {
4334
+ for (; i.length > 0; ) {
4335
+ if (s === o.length) {
4336
+ const u = ge(t, e).decrypt(o);
4337
+ c.enqueue(u), n(), s = 0, r = !1;
4338
+ }
4339
+ const f = Math.min(o.length - s, i.length);
4340
+ o.set(i.subarray(0, f), s), s += f, i = i.subarray(f);
4341
+ }
4342
+ },
4343
+ flush(i) {
4344
+ e[11] = 1;
4345
+ const c = ge(t, e).decrypt(o.subarray(0, s));
4346
+ if (!r && c.length === 0)
4347
+ throw new Error("final chunk is empty");
4348
+ i.enqueue(c);
4349
+ }
4350
+ });
4351
+ }
4352
+ function hf(t) {
4353
+ if (t < $e)
4354
+ throw Error("ciphertext is too small");
4355
+ if (t === $e)
4356
+ return 0;
4357
+ const e = Math.floor(t / vn), n = t % vn;
4358
+ if (0 < n && n <= $e)
4359
+ throw Error("ciphertext size is invalid");
4360
+ let r = t;
4361
+ return r -= e * $e, r -= n > 0 ? $e : 0, r;
4362
+ }
4363
+ function yf(t) {
4364
+ const e = new Uint8Array(12), n = () => {
4365
+ for (let s = e.length - 2; s >= 0 && (e[s]++, e[s] === 0); s--)
4366
+ ;
4367
+ }, r = new Uint8Array(tr);
4368
+ let o = 0;
4369
+ return new TransformStream({
4370
+ transform(s, i) {
4371
+ for (; s.length > 0; ) {
4372
+ if (o === r.length) {
4373
+ const f = ge(t, e).encrypt(r);
4374
+ i.enqueue(f), n(), o = 0;
4375
+ }
4376
+ const c = Math.min(r.length - o, s.length);
4377
+ r.set(s.subarray(0, c), o), o += c, s = s.subarray(c);
4378
+ }
4379
+ },
4380
+ flush(s) {
4381
+ e[11] = 1;
4382
+ const i = ge(t, e).encrypt(r.subarray(0, o));
4383
+ s.enqueue(i);
4384
+ }
4385
+ });
4386
+ }
4387
+ function pf(t) {
4388
+ const e = Math.max(1, Math.ceil(t / tr));
4389
+ return t + $e * e;
4390
+ }
4391
+ function gf(t) {
4392
+ const e = [];
4393
+ e.push(`-----BEGIN AGE ENCRYPTED FILE-----
4394
+ `);
4395
+ for (let n = 0; n < t.length; n += 48) {
4396
+ let r = n + 48;
4397
+ r > t.length && (r = t.length), e.push(Vr.encode(t.subarray(n, r)) + `
4398
+ `);
4399
+ }
4400
+ return e.push(`-----END AGE ENCRYPTED FILE-----
4401
+ `), e.join("");
4402
+ }
4403
+ function bf(t) {
4404
+ const e = t.trim().replaceAll(`\r
4405
+ `, `
4406
+ `).split(`
4407
+ `);
4408
+ if (e.shift() !== "-----BEGIN AGE ENCRYPTED FILE-----")
4409
+ throw Error("invalid header");
4410
+ if (e.pop() !== "-----END AGE ENCRYPTED FILE-----")
4411
+ throw Error("invalid footer");
4412
+ function n(r, o) {
4413
+ return r === e.length - 1 ? o.length > 0 && o.length <= 64 && o.length % 4 === 0 : o.length === 64;
4414
+ }
4415
+ if (!e.every((r, o) => n(o, r)))
4416
+ throw Error("invalid line length");
4417
+ if (!e.every((r) => /^[A-Za-z0-9+/=]+$/.test(r)))
4418
+ throw Error("invalid base64");
4419
+ return Vr.decode(e.join(""));
4420
+ }
4421
+ const zf = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
4422
+ __proto__: null,
4423
+ decode: bf,
4424
+ encode: gf
4425
+ }, Symbol.toStringTag, { value: "Module" }));
4426
+ function rn(t) {
4427
+ if (t.length === 0)
4428
+ throw Error("cbor: unexpected EOF");
4429
+ const e = t[0] >> 5, n = t[0] & 31;
4430
+ if (n <= 23)
4431
+ return [e, n, t.subarray(1)];
4432
+ if (n === 24) {
4433
+ if (t.length < 2)
4434
+ throw Error("cbor: unexpected EOF");
4435
+ return [e, t[1], t.subarray(2)];
4436
+ }
4437
+ if (n === 25) {
4438
+ if (t.length < 3)
4439
+ throw Error("cbor: unexpected EOF");
4440
+ return [e, t[1] << 8 | t[2], t.subarray(3)];
4441
+ }
4442
+ throw Error("cbor: unsupported argument encoding");
4443
+ }
4444
+ function wf(t) {
4445
+ const [e, n, r] = rn(t);
4446
+ if (e !== 0)
4447
+ throw Error("cbor: expected unsigned integer");
4448
+ return [n, r];
4449
+ }
4450
+ function xf(t) {
4451
+ const [e, n, r] = rn(t);
4452
+ if (e !== 2)
4453
+ throw Error("cbor: expected byte string");
4454
+ if (n > r.length)
4455
+ throw Error("cbor: unexpected EOF");
4456
+ return [r.subarray(0, n), r.subarray(n)];
4457
+ }
4458
+ function Zo(t) {
4459
+ const [e, n, r] = rn(t);
4460
+ if (e !== 3)
4461
+ throw Error("cbor: expected text string");
4462
+ if (n > r.length)
4463
+ throw Error("cbor: unexpected EOF");
4464
+ return [new TextDecoder("utf-8", { fatal: !0, ignoreBOM: !0 }).decode(r.subarray(0, n)), r.subarray(n)];
4465
+ }
4466
+ function Ef(t) {
4467
+ const [e, n, r] = rn(t);
4468
+ if (e !== 4)
4469
+ throw Error("cbor: expected array");
4470
+ let o = r;
4471
+ const s = [];
4472
+ for (let i = 0; i < n; i++) {
4473
+ let c;
4474
+ [c, o] = Zo(o), s.push(c);
4475
+ }
4476
+ return [s, o];
4477
+ }
4478
+ function mf(t) {
4479
+ return new Uint8Array([t]);
4480
+ }
4481
+ function Af(t) {
4482
+ if (t.length <= 23)
4483
+ return new Uint8Array([64 | t.length, ...t]);
4484
+ if (t.length <= 255)
4485
+ return new Uint8Array([88, t.length, ...t]);
4486
+ if (t.length <= 65535)
4487
+ return new Uint8Array([89, t.length >> 8, t.length & 255, ...t]);
4488
+ throw Error("cbor: byte string too long");
4489
+ }
4490
+ function Xo(t) {
4491
+ const e = new TextEncoder().encode(t);
4492
+ if (e.length <= 23)
4493
+ return new Uint8Array([96 | e.length, ...e]);
4494
+ if (e.length <= 255)
4495
+ return new Uint8Array([120, e.length, ...e]);
4496
+ if (e.length <= 65535)
4497
+ return new Uint8Array([121, e.length >> 8, e.length & 255, ...e]);
4498
+ throw Error("cbor: text string too long");
4499
+ }
4500
+ function Bf(t) {
4501
+ const e = t.flatMap((n) => [...Xo(n)]);
4502
+ if (t.length <= 23)
4503
+ return new Uint8Array([128 | t.length, ...e]);
4504
+ if (t.length <= 255)
4505
+ return new Uint8Array([152, t.length, ...e]);
4506
+ if (t.length <= 65535)
4507
+ return new Uint8Array([153, t.length >> 8, t.length & 255, ...e]);
4508
+ throw Error("cbor: array too long");
4509
+ }
4510
+ const Lf = [
4511
+ { type: "public-key", alg: -8 },
4512
+ // Ed25519
4513
+ { type: "public-key", alg: -7 },
4514
+ // ECDSA with P-256 and SHA-256
4515
+ { type: "public-key", alg: -257 }
4516
+ // RSA PKCS#1 v1.5 with SHA-256
4517
+ ];
4518
+ async function Sf(t) {
4519
+ var r;
4520
+ const e = await navigator.credentials.create({
4521
+ publicKey: {
4522
+ rp: { name: "", id: t.rpId },
4523
+ user: {
4524
+ name: t.keyName,
4525
+ id: me(8),
4526
+ // avoid overwriting existing keys
4527
+ displayName: ""
4528
+ },
4529
+ pubKeyCredParams: Lf,
4530
+ authenticatorSelection: {
4531
+ requireResidentKey: t.type !== "security-key",
4532
+ residentKey: t.type !== "security-key" ? "required" : "discouraged",
4533
+ userVerification: "required"
4534
+ // prf requires UV
4535
+ },
4536
+ hints: t.type === "security-key" ? ["security-key"] : [],
4537
+ extensions: { prf: {} },
4538
+ challenge: new Uint8Array([0]).buffer
4539
+ // unused without attestation
4540
+ }
4541
+ });
4542
+ if (!((r = e.getClientExtensionResults().prf) != null && r.enabled))
4543
+ throw Error("PRF extension not available (need macOS 15+, Chrome 132+)");
4544
+ const n = t.rpId ?? new URL(window.origin).hostname;
4545
+ return Hf(e, n);
4546
+ }
4547
+ const Wo = "AGE-PLUGIN-FIDO2PRF-";
4548
+ function Hf(t, e) {
4549
+ const n = t.response, r = mf(1), o = Af(new Uint8Array(t.rawId)), s = Xo(e), i = Bf(n.getTransports()), c = new Uint8Array([...r, ...o, ...s, ...i]);
4550
+ return re.encode(Wo, re.toWords(c), !1).toUpperCase();
4551
+ }
4552
+ function Uf(t) {
4553
+ const e = re.decodeToBytes(t);
4554
+ if (!t.startsWith(Wo + "1"))
4555
+ throw Error("invalid identity");
4556
+ const [n, r] = wf(e.bytes);
4557
+ if (n !== 1)
4558
+ throw Error("unsupported identity version");
4559
+ const [o, s] = xf(r), [i, c] = Zo(s), [f] = Ef(c);
4560
+ return [o, i, f];
4561
+ }
4562
+ const on = "age-encryption.org/fido2prf";
4563
+ class Qo {
4564
+ constructor(e) {
4565
+ g(this, "credId");
4566
+ g(this, "transports");
4567
+ g(this, "rpId");
4568
+ if (e != null && e.identity) {
4569
+ const [n, r, o] = Uf(e.identity);
4570
+ this.credId = n, this.transports = o, this.rpId = r;
4571
+ } else
4572
+ this.rpId = e == null ? void 0 : e.rpId;
4573
+ }
4574
+ async getCredential(e) {
4575
+ var o;
4576
+ const r = (o = (await navigator.credentials.get({
4577
+ publicKey: {
4578
+ allowCredentials: this.credId ? [{
4579
+ id: this.credId,
4580
+ transports: this.transports,
4581
+ type: "public-key"
4582
+ }] : [],
4583
+ challenge: me(16),
4584
+ extensions: { prf: { eval: _f(e) } },
4585
+ userVerification: "required",
4586
+ // prf requires UV
4587
+ rpId: this.rpId
4588
+ }
4589
+ })).getClientExtensionResults().prf) == null ? void 0 : o.results;
4590
+ if (r === void 0)
4591
+ throw Error("PRF extension not available (need macOS 15+, Chrome 132+)");
4592
+ return r;
4593
+ }
4594
+ }
4595
+ class If extends Qo {
4596
+ /**
4597
+ * Implements {@link Recipient.wrapFileKey}.
4598
+ */
4599
+ async wrapFileKey(e) {
4600
+ const n = me(16), r = await this.getCredential(n), o = Jo(r);
4601
+ return [new Ze([on, se.encode(n)], Jn(e, o))];
4602
+ }
4603
+ }
4604
+ class kf extends Qo {
4605
+ /**
4606
+ * Implements {@link Identity.unwrapFileKey}.
4607
+ */
4608
+ async unwrapFileKey(e) {
4609
+ for (const n of e) {
4610
+ if (n.args.length < 1 || n.args[0] !== on)
4611
+ continue;
4612
+ if (n.args.length !== 2)
4613
+ throw Error("invalid prf stanza");
4614
+ const r = se.decode(n.args[1]);
4615
+ if (r.length !== 16)
4616
+ throw Error("invalid prf stanza");
4617
+ const o = await this.getCredential(r), s = Jo(o), i = er(n.body, s);
4618
+ if (i !== null)
4619
+ return i;
4620
+ }
4621
+ return null;
4622
+ }
4623
+ }
4624
+ function _f(t) {
4625
+ const e = new TextEncoder().encode(on), n = new Uint8Array(e.length + t.length + 1);
4626
+ n.set(e, 0), n[e.length] = 1, n.set(t, e.length + 1);
4627
+ const r = new Uint8Array(e.length + t.length + 1);
4628
+ return r.set(e, 0), r[e.length] = 2, r.set(t, e.length + 1), { first: n, second: r };
4629
+ }
4630
+ function Jo(t) {
4631
+ if (t.second === void 0)
4632
+ throw Error("Missing second PRF result");
4633
+ const e = new Uint8Array(t.first.byteLength + t.second.byteLength);
4634
+ return e.set(new Uint8Array(t.first), 0), e.set(new Uint8Array(t.second), t.first.byteLength), mt(ee, e, new TextEncoder().encode(on));
4635
+ }
4636
+ const Vf = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
4637
+ __proto__: null,
4638
+ WebAuthnIdentity: kf,
4639
+ WebAuthnRecipient: If,
4640
+ createCredential: Sf
4641
+ }, Symbol.toStringTag, { value: "Module" }));
4642
+ class Gf {
4643
+ constructor() {
4644
+ g(this, "passphrase", null);
4645
+ g(this, "scryptWorkFactor", 18);
4646
+ g(this, "recipients", []);
4647
+ }
4648
+ /**
4649
+ * Set the passphrase to encrypt the file(s) with. This method can only be
4650
+ * called once, and can't be called if {@link Encrypter.addRecipient} has
4651
+ * been called.
4652
+ *
4653
+ * The passphrase is passed through the scrypt key derivation function, but
4654
+ * it needs to have enough entropy to resist offline brute-force attacks.
4655
+ * You should use at least 8-10 random alphanumeric characters, or 4-5
4656
+ * random words from a list of at least 2000 words.
4657
+ *
4658
+ * @param s - The passphrase to encrypt the file with.
4659
+ */
4660
+ setPassphrase(e) {
4661
+ if (this.passphrase !== null)
4662
+ throw new Error("can encrypt to at most one passphrase");
4663
+ if (this.recipients.length !== 0)
4664
+ throw new Error("can't encrypt to both recipients and passphrases");
4665
+ this.passphrase = e;
4666
+ }
4667
+ /**
4668
+ * Set the scrypt work factor to use when encrypting the file(s) with a
4669
+ * passphrase. The default is 18. Using a lower value will require stronger
4670
+ * passphrases to resist offline brute-force attacks.
4671
+ *
4672
+ * @param logN - The base-2 logarithm of the scrypt work factor.
4673
+ */
4674
+ setScryptWorkFactor(e) {
4675
+ this.scryptWorkFactor = e;
4676
+ }
4677
+ /**
4678
+ * Add a recipient to encrypt the file(s) for. This method can be called
4679
+ * multiple times to encrypt the file(s) for multiple recipients.
4680
+ *
4681
+ * This version supports native X25519 recipients (`age1...`), hybrid
4682
+ * post-quantum recipients (`age1pq1...`), tag recipients (`age1tag1...`),
4683
+ * and hybrid tag recipients (`age1tagpq1...`).
4684
+ *
4685
+ * @param s - The recipient to encrypt the file for. Either a string
4686
+ * beginning with `age1...` or an object implementing the {@link Recipient}
4687
+ * interface.
4688
+ */
4689
+ addRecipient(e) {
4690
+ if (this.passphrase !== null)
4691
+ throw new Error("can't encrypt to both recipients and passphrases");
4692
+ if (typeof e == "string")
4693
+ if (e.startsWith("age1pq1"))
4694
+ this.recipients.push(new tf(e));
4695
+ else if (e.startsWith("age1tag1"))
4696
+ this.recipients.push(new cf(e));
4697
+ else if (e.startsWith("age1tagpq1"))
4698
+ this.recipients.push(new ff(e));
4699
+ else if (e.startsWith("age1"))
4700
+ this.recipients.push(new af(e));
4701
+ else
4702
+ throw new Error("unrecognized recipient type");
4703
+ else
4704
+ this.recipients.push(e);
4705
+ }
4706
+ async encrypt(e) {
4707
+ const n = me(16), r = [];
4708
+ let o = this.recipients;
4709
+ this.passphrase !== null && (o = [new uf(this.passphrase, this.scryptWorkFactor)]);
4710
+ for (const l of o)
4711
+ r.push(...await l.wrapFileKey(n));
4712
+ const s = new TextEncoder().encode("header"), i = rt(ee, n, void 0, s, 32), c = Et(ee, i, Vo(r)), f = Jc(r, c), u = me(16), d = new TextEncoder().encode("payload"), a = rt(ee, n, u, d, 32), y = yf(a);
4713
+ return e instanceof ReadableStream ? Object.assign(Yt(e.pipeThrough(y), f, u), {
4714
+ size: (l) => pf(l) + f.length + u.length
4715
+ }) : (typeof e == "string" && (e = new TextEncoder().encode(e)), await zo(Yt(kn(e).pipeThrough(y), f, u)));
4716
+ }
4717
+ }
4718
+ class Yf {
4719
+ constructor() {
4720
+ g(this, "identities", []);
4721
+ }
4722
+ /**
4723
+ * Add a passphrase to decrypt password-encrypted file(s) with. This method
4724
+ * can be called multiple times to try multiple passphrases.
4725
+ *
4726
+ * @param s - The passphrase to decrypt the file with.
4727
+ */
4728
+ addPassphrase(e) {
4729
+ this.identities.push(new df(e));
4730
+ }
4731
+ /**
4732
+ * Add an identity to decrypt file(s) with. This method can be called
4733
+ * multiple times to try multiple identities.
4734
+ *
4735
+ * @param s - The identity to decrypt the file with. Either a string
4736
+ * beginning with `AGE-SECRET-KEY-PQ-1...` or `AGE-SECRET-KEY-1...`, an
4737
+ * X25519 private
4738
+ * {@link https://developer.mozilla.org/en-US/docs/Web/API/CryptoKey | CryptoKey}
4739
+ * object, or an object implementing the {@link Identity} interface.
4740
+ *
4741
+ * A CryptoKey object must have
4742
+ * {@link https://developer.mozilla.org/en-US/docs/Web/API/CryptoKey/type | type}
4743
+ * `private`,
4744
+ * {@link https://developer.mozilla.org/en-US/docs/Web/API/CryptoKey/algorithm | algorithm}
4745
+ * `{name: 'X25519'}`, and
4746
+ * {@link https://developer.mozilla.org/en-US/docs/Web/API/CryptoKey/usages | usages}
4747
+ * `["deriveBits"]`. For example:
4748
+ * ```js
4749
+ * const keyPair = await crypto.subtle.generateKey({ name: "X25519" }, false, ["deriveBits"])
4750
+ * decrypter.addIdentity(key.privateKey)
4751
+ * ```
4752
+ */
4753
+ addIdentity(e) {
4754
+ if (vf(e))
4755
+ this.identities.push(new Mr(e));
4756
+ else if (typeof e == "string")
4757
+ if (e.startsWith("AGE-SECRET-KEY-1"))
4758
+ this.identities.push(new Mr(e));
4759
+ else if (e.startsWith("AGE-SECRET-KEY-PQ-1"))
4760
+ this.identities.push(new nf(e));
4761
+ else
4762
+ throw new Error("unrecognized identity type");
4763
+ else
4764
+ this.identities.push(e);
4765
+ }
4766
+ async decrypt(e, n) {
4767
+ const r = e instanceof ReadableStream ? e : kn(e), { fileKey: o, headerSize: s, rest: i } = await this.decryptHeaderInternal(r), { data: c, rest: f } = await Xc(i, 16), u = new TextEncoder().encode("payload"), d = rt(ee, o, c, u, 32), a = lf(d), y = f.pipeThrough(a), l = Object.assign(y, {
4768
+ size: (b) => hf(b - s - c.length)
4769
+ });
4770
+ return e instanceof ReadableStream ? l : n === "text" ? await Zc(y) : await zo(y);
4771
+ }
4772
+ /**
4773
+ * Decrypt the file key from a detached header. This is a low-level
4774
+ * function that can be used to implement delegated decryption logic.
4775
+ * Most users won't need this.
4776
+ *
4777
+ * It is the caller's responsibility to keep track of what file the
4778
+ * returned file key decrypts, and to ensure the file key is not used
4779
+ * for any other purpose.
4780
+ *
4781
+ * @param header - The file's textual header, including the MAC.
4782
+ *
4783
+ * @returns The file key used to encrypt the file.
4784
+ */
4785
+ async decryptHeader(e) {
4786
+ return (await this.decryptHeaderInternal(kn(e))).fileKey;
4787
+ }
4788
+ async decryptHeaderInternal(e) {
4789
+ const n = await Qc(e), r = await this.unwrapFileKey(n.stanzas);
4790
+ if (r === null)
4791
+ throw Error("no identity matched any of the file's recipients");
4792
+ const o = new TextEncoder().encode("header"), s = rt(ee, r, void 0, o, 32), i = Et(ee, s, n.headerNoMAC);
4793
+ if (!Kf(n.MAC, i))
4794
+ throw Error("invalid header HMAC");
4795
+ return { fileKey: r, headerSize: n.headerSize, rest: n.rest };
4796
+ }
4797
+ async unwrapFileKey(e) {
4798
+ for (const n of this.identities) {
4799
+ const r = await n.unwrapFileKey(e);
4800
+ if (r !== null)
4801
+ return r;
4802
+ }
4803
+ return null;
4804
+ }
4805
+ }
4806
+ function Kf(t, e) {
4807
+ if (t.length !== e.length)
4808
+ return !1;
4809
+ let n = 0;
4810
+ for (let r = 0; r < t.length; r++)
4811
+ n |= t[r] ^ e[r];
4812
+ return n === 0;
4813
+ }
4814
+ function vf(t) {
4815
+ return typeof CryptoKey < "u" && t instanceof CryptoKey;
4816
+ }
4817
+ export {
4818
+ Yf as Decrypter,
4819
+ Gf as Encrypter,
4820
+ Ze as Stanza,
4821
+ zf as armor,
4822
+ jf as generateHybridIdentity,
4823
+ Df as generateIdentity,
4824
+ ef as generateX25519Identity,
4825
+ qf as identityToRecipient,
4826
+ Vf as webauthn
4827
+ };