@nsite/stealthis 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,4999 @@
1
+ const pr = (
2
+ /*css*/
3
+ `
4
+ :host {
5
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
6
+ }
7
+
8
+ .nd-trigger {
9
+ padding: 10px 18px;
10
+ background: #9b59b6;
11
+ color: #fff;
12
+ border: none;
13
+ border-radius: 8px;
14
+ font-size: 14px;
15
+ font-weight: 600;
16
+ cursor: pointer;
17
+ transition: background 0.2s;
18
+ }
19
+ .nd-trigger:hover { background: #8e44ad; }
20
+ .nd-trigger:disabled { opacity: 0.6; cursor: default; }
21
+ :host(.nd-fixed) .nd-trigger {
22
+ position: fixed;
23
+ bottom: 20px;
24
+ right: 20px;
25
+ z-index: 99999;
26
+ box-shadow: 0 2px 12px rgba(0,0,0,0.3);
27
+ }
28
+
29
+ .nd-overlay {
30
+ position: fixed;
31
+ inset: 0;
32
+ background: rgba(0,0,0,0.6);
33
+ display: flex;
34
+ align-items: center;
35
+ justify-content: center;
36
+ z-index: 100000;
37
+ backdrop-filter: blur(4px);
38
+ }
39
+
40
+ .nd-modal {
41
+ background: #1a1a2e;
42
+ border: 1px solid #0f3460;
43
+ border-radius: 12px;
44
+ padding: 24px;
45
+ width: 90%;
46
+ max-width: 420px;
47
+ color: #e0e0e0;
48
+ max-height: 90vh;
49
+ overflow-y: auto;
50
+ }
51
+
52
+ .nd-header {
53
+ display: flex;
54
+ justify-content: space-between;
55
+ align-items: center;
56
+ margin-bottom: 16px;
57
+ }
58
+ .nd-title {
59
+ margin: 0;
60
+ font-size: 18px;
61
+ font-weight: 700;
62
+ }
63
+ .nd-close {
64
+ background: none;
65
+ border: none;
66
+ color: #888;
67
+ font-size: 22px;
68
+ cursor: pointer;
69
+ padding: 0 0 0 8px;
70
+ line-height: 1;
71
+ }
72
+ .nd-close:hover { color: #e0e0e0; }
73
+
74
+ /* Auth section */
75
+ .nd-auth-option {
76
+ margin-bottom: 16px;
77
+ }
78
+ .nd-auth-option:last-child {
79
+ margin-bottom: 0;
80
+ }
81
+
82
+ .nd-divider {
83
+ display: flex;
84
+ align-items: center;
85
+ gap: 12px;
86
+ margin: 16px 0;
87
+ font-size: 12px;
88
+ color: #555;
89
+ text-transform: uppercase;
90
+ letter-spacing: 0.05em;
91
+ }
92
+ .nd-divider::before, .nd-divider::after {
93
+ content: '';
94
+ flex: 1;
95
+ height: 1px;
96
+ background: #0f3460;
97
+ }
98
+
99
+ .nd-btn-ext {
100
+ width: 100%;
101
+ padding: 12px;
102
+ background: #9b59b6;
103
+ color: #fff;
104
+ border: none;
105
+ border-radius: 8px;
106
+ font-size: 14px;
107
+ font-weight: 600;
108
+ cursor: pointer;
109
+ transition: background 0.2s;
110
+ }
111
+ .nd-btn-ext:hover { background: #8e44ad; }
112
+
113
+ .nd-bunker-row {
114
+ display: flex;
115
+ gap: 8px;
116
+ }
117
+ .nd-bunker-row input {
118
+ flex: 1;
119
+ padding: 8px 12px;
120
+ background: #16213e;
121
+ border: 1px solid #0f3460;
122
+ border-radius: 6px;
123
+ color: #e0e0e0;
124
+ font-size: 13px;
125
+ font-family: inherit;
126
+ box-sizing: border-box;
127
+ min-width: 0;
128
+ }
129
+ .nd-bunker-row input:focus {
130
+ outline: none;
131
+ border-color: #9b59b6;
132
+ }
133
+ .nd-bunker-row button {
134
+ padding: 8px 14px;
135
+ background: #16213e;
136
+ border: 1px solid #0f3460;
137
+ border-radius: 6px;
138
+ color: #e0e0e0;
139
+ font-size: 13px;
140
+ font-weight: 600;
141
+ cursor: pointer;
142
+ white-space: nowrap;
143
+ }
144
+ .nd-bunker-row button:hover { background: #0f3460; }
145
+
146
+ .nd-qr-wrap {
147
+ display: flex;
148
+ flex-direction: column;
149
+ align-items: center;
150
+ gap: 10px;
151
+ }
152
+ .nd-qr-label {
153
+ font-size: 12px;
154
+ color: #888;
155
+ }
156
+ .nd-qr-code {
157
+ background: #fff;
158
+ border-radius: 8px;
159
+ padding: 12px;
160
+ display: inline-flex;
161
+ }
162
+ .nd-qr-code svg {
163
+ display: block;
164
+ width: 200px;
165
+ height: 200px;
166
+ }
167
+ .nd-relay-row {
168
+ display: flex;
169
+ gap: 0;
170
+ width: 100%;
171
+ max-width: 300px;
172
+ }
173
+ .nd-relay-row label {
174
+ padding: 6px 10px;
175
+ background: #0f3460;
176
+ border: 1px solid #0f3460;
177
+ border-right: none;
178
+ border-radius: 4px 0 0 4px;
179
+ color: #888;
180
+ font-size: 11px;
181
+ white-space: nowrap;
182
+ display: flex;
183
+ align-items: center;
184
+ }
185
+ .nd-relay-row input {
186
+ flex: 1;
187
+ padding: 6px 8px;
188
+ background: #16213e;
189
+ border: 1px solid #0f3460;
190
+ border-radius: 0 4px 4px 0;
191
+ color: #e0e0e0;
192
+ font-size: 11px;
193
+ font-family: monospace;
194
+ min-width: 0;
195
+ box-sizing: border-box;
196
+ }
197
+ .nd-relay-row input:focus {
198
+ outline: none;
199
+ border-color: #9b59b6;
200
+ }
201
+ .nd-qr-uri {
202
+ display: flex;
203
+ gap: 6px;
204
+ width: 100%;
205
+ max-width: 300px;
206
+ }
207
+ .nd-qr-uri input {
208
+ flex: 1;
209
+ padding: 6px 8px;
210
+ background: #16213e;
211
+ border: 1px solid #0f3460;
212
+ border-radius: 4px;
213
+ color: #888;
214
+ font-size: 11px;
215
+ font-family: monospace;
216
+ min-width: 0;
217
+ box-sizing: border-box;
218
+ }
219
+ .nd-qr-uri button {
220
+ padding: 6px 10px;
221
+ background: #16213e;
222
+ border: 1px solid #0f3460;
223
+ border-radius: 4px;
224
+ color: #e0e0e0;
225
+ font-size: 11px;
226
+ cursor: pointer;
227
+ white-space: nowrap;
228
+ }
229
+ .nd-qr-uri button:hover { background: #0f3460; }
230
+
231
+ /* Toggle */
232
+ .nd-toggle {
233
+ display: flex;
234
+ margin-bottom: 16px;
235
+ background: #16213e;
236
+ border-radius: 6px;
237
+ padding: 3px;
238
+ }
239
+ .nd-toggle-btn {
240
+ flex: 1;
241
+ padding: 8px;
242
+ background: transparent;
243
+ border: none;
244
+ border-radius: 4px;
245
+ color: #888;
246
+ font-size: 13px;
247
+ font-weight: 600;
248
+ cursor: pointer;
249
+ transition: all 0.2s;
250
+ }
251
+ .nd-toggle-btn.active {
252
+ background: #9b59b6;
253
+ color: #fff;
254
+ }
255
+
256
+ /* Warning */
257
+ .nd-warn {
258
+ background: rgba(231, 76, 60, 0.1);
259
+ border: 1px solid rgba(231, 76, 60, 0.3);
260
+ border-radius: 6px;
261
+ padding: 12px;
262
+ font-size: 13px;
263
+ color: #e74c3c;
264
+ line-height: 1.5;
265
+ }
266
+ .nd-btn-warn {
267
+ background: #e74c3c;
268
+ color: #fff;
269
+ }
270
+ .nd-btn-warn:hover { background: #c0392b; }
271
+
272
+ .nd-root-hint {
273
+ font-size: 13px;
274
+ color: #888;
275
+ margin-bottom: 12px;
276
+ word-break: break-all;
277
+ }
278
+ .nd-root-hint strong {
279
+ color: #e0e0e0;
280
+ }
281
+
282
+ /* Form fields */
283
+ .nd-field {
284
+ margin-bottom: 12px;
285
+ }
286
+ .nd-field label {
287
+ display: block;
288
+ font-size: 11px;
289
+ color: #888;
290
+ margin-bottom: 4px;
291
+ text-transform: uppercase;
292
+ letter-spacing: 0.05em;
293
+ }
294
+ .nd-field input, .nd-field textarea {
295
+ width: 100%;
296
+ padding: 8px 12px;
297
+ background: #16213e;
298
+ border: 1px solid #0f3460;
299
+ border-radius: 6px;
300
+ color: #e0e0e0;
301
+ font-size: 14px;
302
+ font-family: inherit;
303
+ box-sizing: border-box;
304
+ }
305
+ .nd-field input:focus, .nd-field textarea:focus {
306
+ outline: none;
307
+ border-color: #9b59b6;
308
+ }
309
+ .nd-field textarea {
310
+ resize: vertical;
311
+ min-height: 60px;
312
+ }
313
+ .nd-hint {
314
+ font-size: 11px;
315
+ color: #888;
316
+ margin-top: 3px;
317
+ }
318
+ .nd-field-error {
319
+ font-size: 11px;
320
+ color: #e74c3c;
321
+ margin-top: 3px;
322
+ }
323
+
324
+ /* Actions */
325
+ .nd-actions {
326
+ display: flex;
327
+ gap: 8px;
328
+ margin-top: 16px;
329
+ }
330
+ .nd-btn {
331
+ flex: 1;
332
+ padding: 10px;
333
+ border: none;
334
+ border-radius: 6px;
335
+ font-size: 14px;
336
+ font-weight: 600;
337
+ cursor: pointer;
338
+ transition: background 0.2s;
339
+ }
340
+ .nd-btn-primary {
341
+ background: #9b59b6;
342
+ color: #fff;
343
+ }
344
+ .nd-btn-primary:hover { background: #8e44ad; }
345
+ .nd-btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
346
+ .nd-btn-secondary {
347
+ background: #16213e;
348
+ color: #e0e0e0;
349
+ border: 1px solid #0f3460;
350
+ }
351
+ .nd-btn-secondary:hover { background: #0f3460; }
352
+
353
+ /* Status */
354
+ .nd-status {
355
+ margin-top: 12px;
356
+ font-size: 13px;
357
+ color: #888;
358
+ }
359
+ .nd-status-ok { color: #2ecc71; }
360
+ .nd-status-err { color: #e74c3c; }
361
+
362
+ .nd-link {
363
+ display: block;
364
+ margin-top: 12px;
365
+ padding: 10px;
366
+ background: #16213e;
367
+ border: 1px solid #0f3460;
368
+ border-radius: 6px;
369
+ color: #9b59b6;
370
+ text-decoration: none;
371
+ text-align: center;
372
+ font-size: 13px;
373
+ word-break: break-all;
374
+ }
375
+ .nd-link:hover { background: #0f3460; }
376
+
377
+ .nd-msg {
378
+ text-align: center;
379
+ padding: 20px 0;
380
+ font-size: 14px;
381
+ color: #888;
382
+ }
383
+
384
+ /* Paper trail */
385
+ .nd-trail {
386
+ margin-top: 8px;
387
+ text-align: center;
388
+ }
389
+ .nd-trail-toggle {
390
+ background: none;
391
+ border: none;
392
+ color: #888;
393
+ font-size: 12px;
394
+ cursor: pointer;
395
+ padding: 4px 8px;
396
+ transition: color 0.2s;
397
+ }
398
+ .nd-trail-toggle:hover { color: #e0e0e0; }
399
+ .nd-trail-list {
400
+ margin-top: 6px;
401
+ text-align: left;
402
+ font-size: 12px;
403
+ color: #888;
404
+ max-height: 200px;
405
+ overflow-y: auto;
406
+ }
407
+ .nd-trail-item {
408
+ padding: 3px 0;
409
+ font-family: monospace;
410
+ font-size: 11px;
411
+ display: flex;
412
+ gap: 6px;
413
+ }
414
+ .nd-trail-idx {
415
+ color: #555;
416
+ min-width: 24px;
417
+ text-align: right;
418
+ }
419
+ .nd-trail-pk {
420
+ color: #9b59b6;
421
+ }
422
+ .nd-trail-gap {
423
+ padding: 3px 0;
424
+ color: #555;
425
+ font-style: italic;
426
+ }
427
+
428
+ @keyframes nd-spin {
429
+ to { transform: rotate(360deg); }
430
+ }
431
+ .nd-spinner {
432
+ display: inline-block;
433
+ width: 18px;
434
+ height: 18px;
435
+ border: 2px solid #555;
436
+ border-top-color: #9b59b6;
437
+ border-radius: 50%;
438
+ animation: nd-spin 0.8s linear infinite;
439
+ vertical-align: middle;
440
+ margin-right: 8px;
441
+ }
442
+ `
443
+ );
444
+ function _t(t) {
445
+ return t instanceof Uint8Array || ArrayBuffer.isView(t) && t.constructor.name === "Uint8Array";
446
+ }
447
+ function me(t, e = "") {
448
+ if (!Number.isSafeInteger(t) || t < 0) {
449
+ const r = e && `"${e}" `;
450
+ throw new Error(`${r}expected integer >= 0, got ${t}`);
451
+ }
452
+ }
453
+ function G(t, e, r = "") {
454
+ const n = _t(t), i = t?.length, s = e !== void 0;
455
+ if (!n || s && i !== e) {
456
+ const o = r && `"${r}" `, a = s ? ` of length ${e}` : "", u = n ? `length=${i}` : `type=${typeof t}`;
457
+ throw new Error(o + "expected Uint8Array" + a + ", got " + u);
458
+ }
459
+ return t;
460
+ }
461
+ function tt(t) {
462
+ if (typeof t != "function" || typeof t.create != "function")
463
+ throw new Error("Hash must wrapped by utils.createHasher");
464
+ me(t.outputLen), me(t.blockLen);
465
+ }
466
+ function ze(t, e = !0) {
467
+ if (t.destroyed)
468
+ throw new Error("Hash instance has been destroyed");
469
+ if (e && t.finished)
470
+ throw new Error("Hash#digest() has already been called");
471
+ }
472
+ function br(t, e) {
473
+ G(t, void 0, "digestInto() output");
474
+ const r = e.outputLen;
475
+ if (t.length < r)
476
+ throw new Error('"digestInto() output" expected to be of length >=' + r);
477
+ }
478
+ function Ne(...t) {
479
+ for (let e = 0; e < t.length; e++)
480
+ t[e].fill(0);
481
+ }
482
+ function at(t) {
483
+ return new DataView(t.buffer, t.byteOffset, t.byteLength);
484
+ }
485
+ function de(t, e) {
486
+ return t << 32 - e | t >>> e;
487
+ }
488
+ const yn = /* @ts-ignore */ typeof Uint8Array.from([]).toHex == "function" && typeof Uint8Array.fromHex == "function", yr = /* @__PURE__ */ Array.from({ length: 256 }, (t, e) => e.toString(16).padStart(2, "0"));
489
+ function le(t) {
490
+ if (G(t), yn)
491
+ return t.toHex();
492
+ let e = "";
493
+ for (let r = 0; r < t.length; r++)
494
+ e += yr[t[r]];
495
+ return e;
496
+ }
497
+ const ge = { _0: 48, _9: 57, A: 65, F: 70, a: 97, f: 102 };
498
+ function Ft(t) {
499
+ if (t >= ge._0 && t <= ge._9)
500
+ return t - ge._0;
501
+ if (t >= ge.A && t <= ge.F)
502
+ return t - (ge.A - 10);
503
+ if (t >= ge.a && t <= ge.f)
504
+ return t - (ge.a - 10);
505
+ }
506
+ function ie(t) {
507
+ if (typeof t != "string")
508
+ throw new Error("hex string expected, got " + typeof t);
509
+ if (yn)
510
+ return Uint8Array.fromHex(t);
511
+ const e = t.length, r = e / 2;
512
+ if (e % 2)
513
+ throw new Error("hex string expected, got unpadded hex of length " + e);
514
+ const n = new Uint8Array(r);
515
+ for (let i = 0, s = 0; i < r; i++, s += 2) {
516
+ const o = Ft(t.charCodeAt(s)), a = Ft(t.charCodeAt(s + 1));
517
+ if (o === void 0 || a === void 0) {
518
+ const u = t[s] + t[s + 1];
519
+ throw new Error('hex string expected, got non-hex character "' + u + '" at index ' + s);
520
+ }
521
+ n[i] = o * 16 + a;
522
+ }
523
+ return n;
524
+ }
525
+ function oe(...t) {
526
+ let e = 0;
527
+ for (let n = 0; n < t.length; n++) {
528
+ const i = t[n];
529
+ G(i), e += i.length;
530
+ }
531
+ const r = new Uint8Array(e);
532
+ for (let n = 0, i = 0; n < t.length; n++) {
533
+ const s = t[n];
534
+ r.set(s, i), i += s.length;
535
+ }
536
+ return r;
537
+ }
538
+ function wr(t, e = {}) {
539
+ const r = (i, s) => t(s).update(i).digest(), n = t(void 0);
540
+ return r.outputLen = n.outputLen, r.blockLen = n.blockLen, r.create = (i) => t(i), Object.assign(r, e), Object.freeze(r);
541
+ }
542
+ function $e(t = 32) {
543
+ const e = typeof globalThis == "object" ? globalThis.crypto : null;
544
+ if (typeof e?.getRandomValues != "function")
545
+ throw new Error("crypto.getRandomValues must be defined");
546
+ return e.getRandomValues(new Uint8Array(t));
547
+ }
548
+ const vr = (t) => ({
549
+ oid: Uint8Array.from([6, 9, 96, 134, 72, 1, 101, 3, 4, 2, t])
550
+ });
551
+ function Tt(t) {
552
+ return t instanceof Uint8Array || ArrayBuffer.isView(t) && t.constructor.name === "Uint8Array";
553
+ }
554
+ function mr(t) {
555
+ if (!Tt(t))
556
+ throw new Error("Uint8Array expected");
557
+ }
558
+ function wn(t, e) {
559
+ return Array.isArray(e) ? e.length === 0 ? !0 : t ? e.every((r) => typeof r == "string") : e.every((r) => Number.isSafeInteger(r)) : !1;
560
+ }
561
+ function xr(t) {
562
+ if (typeof t != "function")
563
+ throw new Error("function expected");
564
+ return !0;
565
+ }
566
+ function Se(t, e) {
567
+ if (typeof e != "string")
568
+ throw new Error(`${t}: string expected`);
569
+ return !0;
570
+ }
571
+ function Ct(t) {
572
+ if (!Number.isSafeInteger(t))
573
+ throw new Error(`invalid integer: ${t}`);
574
+ }
575
+ function vt(t) {
576
+ if (!Array.isArray(t))
577
+ throw new Error("array expected");
578
+ }
579
+ function We(t, e) {
580
+ if (!wn(!0, e))
581
+ throw new Error(`${t}: array of strings expected`);
582
+ }
583
+ function vn(t, e) {
584
+ if (!wn(!1, e))
585
+ throw new Error(`${t}: array of numbers expected`);
586
+ }
587
+ // @__NO_SIDE_EFFECTS__
588
+ function mn(...t) {
589
+ const e = (s) => s, r = (s, o) => (a) => s(o(a)), n = t.map((s) => s.encode).reduceRight(r, e), i = t.map((s) => s.decode).reduce(r, e);
590
+ return { encode: n, decode: i };
591
+ }
592
+ // @__NO_SIDE_EFFECTS__
593
+ function xn(t) {
594
+ const e = typeof t == "string" ? t.split("") : t, r = e.length;
595
+ We("alphabet", e);
596
+ const n = new Map(e.map((i, s) => [i, s]));
597
+ return {
598
+ encode: (i) => (vt(i), i.map((s) => {
599
+ if (!Number.isSafeInteger(s) || s < 0 || s >= r)
600
+ throw new Error(`alphabet.encode: digit index outside alphabet "${s}". Allowed: ${t}`);
601
+ return e[s];
602
+ })),
603
+ decode: (i) => (vt(i), i.map((s) => {
604
+ Se("alphabet.decode", s);
605
+ const o = n.get(s);
606
+ if (o === void 0)
607
+ throw new Error(`Unknown letter: "${s}". Allowed: ${t}`);
608
+ return o;
609
+ }))
610
+ };
611
+ }
612
+ // @__NO_SIDE_EFFECTS__
613
+ function En(t = "") {
614
+ return Se("join", t), {
615
+ encode: (e) => (We("join.decode", e), e.join(t)),
616
+ decode: (e) => (Se("join.decode", e), e.split(t))
617
+ };
618
+ }
619
+ // @__NO_SIDE_EFFECTS__
620
+ function Er(t, e = "=") {
621
+ return Ct(t), Se("padding", e), {
622
+ encode(r) {
623
+ for (We("padding.encode", r); r.length * t % 8; )
624
+ r.push(e);
625
+ return r;
626
+ },
627
+ decode(r) {
628
+ We("padding.decode", r);
629
+ let n = r.length;
630
+ if (n * t % 8)
631
+ throw new Error("padding: invalid, string should have whole number of bytes");
632
+ for (; n > 0 && r[n - 1] === e; n--)
633
+ if ((n - 1) * t % 8 === 0)
634
+ throw new Error("padding: invalid, string has too much padding");
635
+ return r.slice(0, n);
636
+ }
637
+ };
638
+ }
639
+ const kn = (t, e) => e === 0 ? t : kn(e, t % e), Ye = /* @__NO_SIDE_EFFECTS__ */ (t, e) => t + (e - kn(t, e)), Ve = /* @__PURE__ */ (() => {
640
+ let t = [];
641
+ for (let e = 0; e < 40; e++)
642
+ t.push(2 ** e);
643
+ return t;
644
+ })();
645
+ function mt(t, e, r, n) {
646
+ if (vt(t), e <= 0 || e > 32)
647
+ throw new Error(`convertRadix2: wrong from=${e}`);
648
+ if (r <= 0 || r > 32)
649
+ throw new Error(`convertRadix2: wrong to=${r}`);
650
+ if (/* @__PURE__ */ Ye(e, r) > 32)
651
+ throw new Error(`convertRadix2: carry overflow from=${e} to=${r} carryBits=${/* @__PURE__ */ Ye(e, r)}`);
652
+ let i = 0, s = 0;
653
+ const o = Ve[e], a = Ve[r] - 1, u = [];
654
+ for (const w of t) {
655
+ if (Ct(w), w >= o)
656
+ throw new Error(`convertRadix2: invalid data word=${w} from=${e}`);
657
+ if (i = i << e | w, s + e > 32)
658
+ throw new Error(`convertRadix2: carry overflow pos=${s} from=${e}`);
659
+ for (s += e; s >= r; s -= r)
660
+ u.push((i >> s - r & a) >>> 0);
661
+ const T = Ve[s];
662
+ if (T === void 0)
663
+ throw new Error("invalid carry");
664
+ i &= T - 1;
665
+ }
666
+ if (i = i << r - s & a, !n && s >= e)
667
+ throw new Error("Excess padding");
668
+ if (!n && i > 0)
669
+ throw new Error(`Non-zero padding: ${i}`);
670
+ return n && s > 0 && u.push(i >>> 0), u;
671
+ }
672
+ // @__NO_SIDE_EFFECTS__
673
+ function An(t, e = !1) {
674
+ if (Ct(t), t <= 0 || t > 32)
675
+ throw new Error("radix2: bits should be in (0..32]");
676
+ if (/* @__PURE__ */ Ye(8, t) > 32 || /* @__PURE__ */ Ye(t, 8) > 32)
677
+ throw new Error("radix2: carry overflow");
678
+ return {
679
+ encode: (r) => {
680
+ if (!Tt(r))
681
+ throw new Error("radix2.encode input should be Uint8Array");
682
+ return mt(Array.from(r), 8, t, !e);
683
+ },
684
+ decode: (r) => (vn("radix2.decode", r), Uint8Array.from(mt(r, t, 8, e)))
685
+ };
686
+ }
687
+ function Vt(t) {
688
+ return xr(t), function(...e) {
689
+ try {
690
+ return t.apply(null, e);
691
+ } catch {
692
+ }
693
+ };
694
+ }
695
+ const kr = typeof Uint8Array.from([]).toBase64 == "function" && typeof Uint8Array.fromBase64 == "function", Ar = (t, e) => {
696
+ Se("base64", t);
697
+ const r = /^[A-Za-z0-9=+/]+$/, n = "base64";
698
+ if (t.length > 0 && !r.test(t))
699
+ throw new Error("invalid base64");
700
+ return Uint8Array.fromBase64(t, { alphabet: n, lastChunkHandling: "strict" });
701
+ }, Sn = kr ? {
702
+ encode(t) {
703
+ return mr(t), t.toBase64();
704
+ },
705
+ decode(t) {
706
+ return Ar(t);
707
+ }
708
+ } : /* @__PURE__ */ mn(/* @__PURE__ */ An(6), /* @__PURE__ */ xn("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"), /* @__PURE__ */ Er(6), /* @__PURE__ */ En("")), xt = /* @__PURE__ */ mn(/* @__PURE__ */ xn("qpzry9x8gf2tvdw0s3jn54khce6mua7l"), /* @__PURE__ */ En("")), Zt = [996825010, 642813549, 513874426, 1027748829, 705979059];
709
+ function Ce(t) {
710
+ const e = t >> 25;
711
+ let r = (t & 33554431) << 5;
712
+ for (let n = 0; n < Zt.length; n++)
713
+ (e >> n & 1) === 1 && (r ^= Zt[n]);
714
+ return r;
715
+ }
716
+ function jt(t, e, r = 1) {
717
+ const n = t.length;
718
+ let i = 1;
719
+ for (let s = 0; s < n; s++) {
720
+ const o = t.charCodeAt(s);
721
+ if (o < 33 || o > 126)
722
+ throw new Error(`Invalid prefix (${t})`);
723
+ i = Ce(i) ^ o >> 5;
724
+ }
725
+ i = Ce(i);
726
+ for (let s = 0; s < n; s++)
727
+ i = Ce(i) ^ t.charCodeAt(s) & 31;
728
+ for (let s of e)
729
+ i = Ce(i) ^ s;
730
+ for (let s = 0; s < 6; s++)
731
+ i = Ce(i);
732
+ return i ^= r, xt.encode(mt([i % Ve[30]], 30, 5, !1));
733
+ }
734
+ // @__NO_SIDE_EFFECTS__
735
+ function Sr(t) {
736
+ const e = t === "bech32" ? 1 : 734539939, r = /* @__PURE__ */ An(5), n = r.decode, i = r.encode, s = Vt(n);
737
+ function o(R, _, k = 90) {
738
+ Se("bech32.encode prefix", R), Tt(_) && (_ = Array.from(_)), vn("bech32.encode", _);
739
+ const P = R.length;
740
+ if (P === 0)
741
+ throw new TypeError(`Invalid prefix length ${P}`);
742
+ const q = P + 7 + _.length;
743
+ if (k !== !1 && q > k)
744
+ throw new TypeError(`Length ${q} exceeds limit ${k}`);
745
+ const U = R.toLowerCase(), H = jt(U, _, e);
746
+ return `${U}1${xt.encode(_)}${H}`;
747
+ }
748
+ function a(R, _ = 90) {
749
+ Se("bech32.decode input", R);
750
+ const k = R.length;
751
+ if (k < 8 || _ !== !1 && k > _)
752
+ throw new TypeError(`invalid string length: ${k} (${R}). Expected (8..${_})`);
753
+ const P = R.toLowerCase();
754
+ if (R !== P && R !== R.toUpperCase())
755
+ throw new Error("String must be lowercase or uppercase");
756
+ const q = P.lastIndexOf("1");
757
+ if (q === 0 || q === -1)
758
+ throw new Error('Letter "1" must be present between prefix and data only');
759
+ const U = P.slice(0, q), H = P.slice(q + 1);
760
+ if (H.length < 6)
761
+ throw new Error("Data must be at least 6 characters long");
762
+ const W = xt.decode(H).slice(0, -6), ne = jt(U, W, e);
763
+ if (!H.endsWith(ne))
764
+ throw new Error(`Invalid checksum in ${R}: expected "${ne}"`);
765
+ return { prefix: U, words: W };
766
+ }
767
+ const u = Vt(a);
768
+ function w(R) {
769
+ const { prefix: _, words: k } = a(R, !1);
770
+ return { prefix: _, words: k, bytes: n(k) };
771
+ }
772
+ function T(R, _) {
773
+ return o(R, i(_));
774
+ }
775
+ return {
776
+ encode: o,
777
+ decode: a,
778
+ encodeFromBytes: T,
779
+ decodeToBytes: w,
780
+ decodeUnsafe: u,
781
+ fromWords: n,
782
+ fromWordsUnsafe: s,
783
+ toWords: i
784
+ };
785
+ }
786
+ const zt = /* @__PURE__ */ Sr("bech32");
787
+ new TextDecoder("utf-8");
788
+ new TextEncoder();
789
+ var Br = 5e3;
790
+ function Bn(t) {
791
+ return _r("npub", ie(t));
792
+ }
793
+ function Rr(t, e) {
794
+ let r = zt.toWords(e);
795
+ return zt.encode(t, r, Br);
796
+ }
797
+ function _r(t, e) {
798
+ return Rr(t, e);
799
+ }
800
+ const Ie = ["wss://purplepag.es", "wss://relay.damus.io", "wss://nos.lol"], Ze = 50, Tr = /^[a-z0-9-]{1,13}$/, Cr = /^[0-9a-z]{50}[a-z0-9-]{1,13}$/;
801
+ function Lr(t) {
802
+ return BigInt("0x" + t).toString(36).padStart(Ze, "0");
803
+ }
804
+ function Or(t) {
805
+ let e = 0n;
806
+ for (const r of t) e = e * 36n + BigInt(parseInt(r, 36));
807
+ return e.toString(16).padStart(64, "0");
808
+ }
809
+ function Ir(t) {
810
+ if (!t.startsWith("npub1")) return null;
811
+ const e = "qpzry9x8gf2tvdw0s3jn54khce6mua7l", r = [];
812
+ for (const a of t.slice(5)) {
813
+ const u = e.indexOf(a);
814
+ if (u === -1) return null;
815
+ r.push(u);
816
+ }
817
+ const n = r.slice(0, -6);
818
+ let i = 0, s = 0;
819
+ const o = [];
820
+ for (const a of n)
821
+ for (i = i << 5 | a, s += 5; s >= 8; )
822
+ s -= 8, o.push(i >> s & 255);
823
+ return o.length !== 32 ? null : o.map((a) => a.toString(16).padStart(2, "0")).join("");
824
+ }
825
+ function Pr() {
826
+ const t = window.location.hostname.split(".");
827
+ for (let r = 0; r < t.length; r++)
828
+ if (t[r].startsWith("npub1") && t[r].length >= 63) {
829
+ const n = Ir(t[r]);
830
+ if (n) return { pubkey: n, baseDomain: t.slice(r + 1).join(".") };
831
+ }
832
+ const e = t[0];
833
+ if (e && e.length > Ze && e.length <= 63 && Cr.test(e) && !e.endsWith("-"))
834
+ try {
835
+ return { pubkey: Or(e.slice(0, Ze)), identifier: e.slice(Ze), baseDomain: t.slice(1).join(".") };
836
+ } catch {
837
+ }
838
+ return null;
839
+ }
840
+ function Mr(t) {
841
+ return Tr.test(t) && !t.endsWith("-");
842
+ }
843
+ function Rn(t, e, r, n = 5e3) {
844
+ return new Promise((i) => {
845
+ try {
846
+ const s = new WebSocket(t), o = setTimeout(() => {
847
+ try {
848
+ s.close();
849
+ } catch {
850
+ }
851
+ i();
852
+ }, n), a = () => {
853
+ clearTimeout(o);
854
+ try {
855
+ s.close();
856
+ } catch {
857
+ }
858
+ i();
859
+ };
860
+ s.onopen = () => s.send(JSON.stringify(e)), s.onmessage = (u) => {
861
+ try {
862
+ r(JSON.parse(u.data)) && a();
863
+ } catch {
864
+ }
865
+ }, s.onerror = () => a();
866
+ } catch {
867
+ i();
868
+ }
869
+ });
870
+ }
871
+ async function Pe(t, e) {
872
+ const r = /* @__PURE__ */ new Map(), n = Math.random().toString(36).slice(2, 8);
873
+ return await Promise.allSettled(
874
+ t.map(
875
+ (i) => Rn(i, ["REQ", n, e], (s) => (s[0] === "EVENT" && s[1] === n && r.set(s[2].id, s[2]), s[0] === "EOSE" && s[1] === n))
876
+ )
877
+ ), [...r.values()];
878
+ }
879
+ async function Nr(t, e) {
880
+ let r = !1;
881
+ return await Rn(t, ["EVENT", e], (n) => n[0] === "OK" ? (r = n[2] === !0, !0) : !1), r;
882
+ }
883
+ async function $r(t, e) {
884
+ return (await Promise.allSettled(t.map((n) => Nr(n, e)))).filter((n) => n.status === "fulfilled" && n.value).length;
885
+ }
886
+ function _n(t) {
887
+ const e = /* @__PURE__ */ new Set();
888
+ for (const r of t)
889
+ for (const n of r.tags)
890
+ n[0] === "r" && n[1]?.startsWith("wss://") && (!n[2] || n[2] === "write") && e.add(n[1].trim());
891
+ return [...e];
892
+ }
893
+ async function Wt(t) {
894
+ const e = t.identifier ? { kinds: [35128], authors: [t.pubkey], "#d": [t.identifier] } : { kinds: [15128], authors: [t.pubkey], limit: 1 }, [r, n] = await Promise.all([
895
+ Pe(Ie, e),
896
+ Pe(Ie, { kinds: [10002], authors: [t.pubkey], limit: 5 })
897
+ ]);
898
+ if (r.length > 0)
899
+ return r.sort((o, a) => a.created_at - o.created_at)[0];
900
+ const i = _n(n).filter(
901
+ (o) => !Ie.includes(o)
902
+ );
903
+ return i.length === 0 ? null : (await Pe(i, e)).sort((o, a) => a.created_at - o.created_at)[0] ?? null;
904
+ }
905
+ async function Yt(t) {
906
+ const e = await Pe(Ie, {
907
+ kinds: [10002],
908
+ authors: [t],
909
+ limit: 5
910
+ }), r = _n(e);
911
+ return r.length > 0 ? r : Ie.filter((n) => n !== "wss://purplepag.es");
912
+ }
913
+ async function Jt(t, e, r) {
914
+ return (await Pe(t, r ? { kinds: [35128], authors: [e], "#d": [r], limit: 1 } : { kinds: [15128], authors: [e], limit: 1 })).length > 0;
915
+ }
916
+ const Gt = 9;
917
+ function Dr(t) {
918
+ return t.tags.filter((e) => e[0] === "thief" && e[1] && e[2]).map((e) => ({ index: parseInt(e[1], 10), pubkey: e[2], relays: e.slice(3) })).sort((e, r) => e.index - r.index);
919
+ }
920
+ function qr(t, e) {
921
+ const r = [];
922
+ e.slug && r.push(["d", e.slug]);
923
+ for (const a of t.tags)
924
+ (a[0] === "path" || a[0] === "server") && r.push([...a]);
925
+ const n = t.tags.filter((a) => a[0] === "thief" && a[1] && a[2]).map((a) => [...a]).sort((a, u) => parseInt(a[1], 10) - parseInt(u[1], 10)), i = n.length > 0 ? Math.max(...n.map((a) => parseInt(a[1], 10))) : -1, s = ["thief", String(i + 1), e.deployerPubkey, ...e.deployerRelays], o = [...n, s];
926
+ if (o.length > Gt) {
927
+ const a = o[0], u = o.slice(o.length - (Gt - 1));
928
+ r.push(a, ...u);
929
+ } else
930
+ for (const a of o) r.push(a);
931
+ return e.title && r.push(["title", e.title]), e.description && r.push(["description", e.description]), {
932
+ kind: e.slug ? 35128 : 15128,
933
+ created_at: Math.floor(Date.now() / 1e3),
934
+ tags: r,
935
+ content: ""
936
+ };
937
+ }
938
+ function Ur(t, e, r) {
939
+ return r ? `https://${Lr(e)}${r}.${t}` : `https://${Bn(e)}.${t}`;
940
+ }
941
+ function Hr(t) {
942
+ return t && t.__esModule && Object.prototype.hasOwnProperty.call(t, "default") ? t.default : t;
943
+ }
944
+ var ct = { exports: {} }, Xt;
945
+ function Kr() {
946
+ return Xt || (Xt = 1, (function(t, e) {
947
+ var r = (function() {
948
+ var n = function(M, L) {
949
+ var x = 236, B = 17, g = M, E = s[L], h = null, c = 0, d = null, f = [], l = {}, v = function(y, b) {
950
+ c = g * 4 + 17, h = (function(p) {
951
+ for (var m = new Array(p), S = 0; S < p; S += 1) {
952
+ m[S] = new Array(p);
953
+ for (var N = 0; N < p; N += 1)
954
+ m[S][N] = null;
955
+ }
956
+ return m;
957
+ })(c), A(0, 0), A(c - 7, 0), A(0, c - 7), O(), I(), D(y, b), g >= 7 && $(y), d == null && (d = Z(g, E, f)), j(d, b);
958
+ }, A = function(y, b) {
959
+ for (var p = -1; p <= 7; p += 1)
960
+ if (!(y + p <= -1 || c <= y + p))
961
+ for (var m = -1; m <= 7; m += 1)
962
+ b + m <= -1 || c <= b + m || (0 <= p && p <= 6 && (m == 0 || m == 6) || 0 <= m && m <= 6 && (p == 0 || p == 6) || 2 <= p && p <= 4 && 2 <= m && m <= 4 ? h[y + p][b + m] = !0 : h[y + p][b + m] = !1);
963
+ }, C = function() {
964
+ for (var y = 0, b = 0, p = 0; p < 8; p += 1) {
965
+ v(!0, p);
966
+ var m = a.getLostPoint(l);
967
+ (p == 0 || y > m) && (y = m, b = p);
968
+ }
969
+ return b;
970
+ }, I = function() {
971
+ for (var y = 8; y < c - 8; y += 1)
972
+ h[y][6] == null && (h[y][6] = y % 2 == 0);
973
+ for (var b = 8; b < c - 8; b += 1)
974
+ h[6][b] == null && (h[6][b] = b % 2 == 0);
975
+ }, O = function() {
976
+ for (var y = a.getPatternPosition(g), b = 0; b < y.length; b += 1)
977
+ for (var p = 0; p < y.length; p += 1) {
978
+ var m = y[b], S = y[p];
979
+ if (h[m][S] == null)
980
+ for (var N = -2; N <= 2; N += 1)
981
+ for (var F = -2; F <= 2; F += 1)
982
+ N == -2 || N == 2 || F == -2 || F == 2 || N == 0 && F == 0 ? h[m + N][S + F] = !0 : h[m + N][S + F] = !1;
983
+ }
984
+ }, $ = function(y) {
985
+ for (var b = a.getBCHTypeNumber(g), p = 0; p < 18; p += 1) {
986
+ var m = !y && (b >> p & 1) == 1;
987
+ h[Math.floor(p / 3)][p % 3 + c - 8 - 3] = m;
988
+ }
989
+ for (var p = 0; p < 18; p += 1) {
990
+ var m = !y && (b >> p & 1) == 1;
991
+ h[p % 3 + c - 8 - 3][Math.floor(p / 3)] = m;
992
+ }
993
+ }, D = function(y, b) {
994
+ for (var p = E << 3 | b, m = a.getBCHTypeInfo(p), S = 0; S < 15; S += 1) {
995
+ var N = !y && (m >> S & 1) == 1;
996
+ S < 6 ? h[S][8] = N : S < 8 ? h[S + 1][8] = N : h[c - 15 + S][8] = N;
997
+ }
998
+ for (var S = 0; S < 15; S += 1) {
999
+ var N = !y && (m >> S & 1) == 1;
1000
+ S < 8 ? h[8][c - S - 1] = N : S < 9 ? h[8][15 - S - 1 + 1] = N : h[8][15 - S - 1] = N;
1001
+ }
1002
+ h[c - 8][8] = !y;
1003
+ }, j = function(y, b) {
1004
+ for (var p = -1, m = c - 1, S = 7, N = 0, F = a.getMaskFunction(b), K = c - 1; K > 0; K -= 2)
1005
+ for (K == 6 && (K -= 1); ; ) {
1006
+ for (var X = 0; X < 2; X += 1)
1007
+ if (h[m][K - X] == null) {
1008
+ var te = !1;
1009
+ N < y.length && (te = (y[N] >>> S & 1) == 1);
1010
+ var V = F(m, K - X);
1011
+ V && (te = !te), h[m][K - X] = te, S -= 1, S == -1 && (N += 1, S = 7);
1012
+ }
1013
+ if (m += p, m < 0 || c <= m) {
1014
+ m -= p, p = -p;
1015
+ break;
1016
+ }
1017
+ }
1018
+ }, Y = function(y, b) {
1019
+ for (var p = 0, m = 0, S = 0, N = new Array(b.length), F = new Array(b.length), K = 0; K < b.length; K += 1) {
1020
+ var X = b[K].dataCount, te = b[K].totalCount - X;
1021
+ m = Math.max(m, X), S = Math.max(S, te), N[K] = new Array(X);
1022
+ for (var V = 0; V < N[K].length; V += 1)
1023
+ N[K][V] = 255 & y.getBuffer()[V + p];
1024
+ p += X;
1025
+ var ae = a.getErrorCorrectPolynomial(te), ce = w(N[K], ae.getLength() - 1), Ut = ce.mod(ae);
1026
+ F[K] = new Array(ae.getLength() - 1);
1027
+ for (var V = 0; V < F[K].length; V += 1) {
1028
+ var Ht = V + Ut.getLength() - F[K].length;
1029
+ F[K][V] = Ht >= 0 ? Ut.getAt(Ht) : 0;
1030
+ }
1031
+ }
1032
+ for (var Kt = 0, V = 0; V < b.length; V += 1)
1033
+ Kt += b[V].totalCount;
1034
+ for (var ot = new Array(Kt), Ue = 0, V = 0; V < m; V += 1)
1035
+ for (var K = 0; K < b.length; K += 1)
1036
+ V < N[K].length && (ot[Ue] = N[K][V], Ue += 1);
1037
+ for (var V = 0; V < S; V += 1)
1038
+ for (var K = 0; K < b.length; K += 1)
1039
+ V < F[K].length && (ot[Ue] = F[K][V], Ue += 1);
1040
+ return ot;
1041
+ }, Z = function(y, b, p) {
1042
+ for (var m = T.getRSBlocks(y, b), S = R(), N = 0; N < p.length; N += 1) {
1043
+ var F = p[N];
1044
+ S.put(F.getMode(), 4), S.put(F.getLength(), a.getLengthInBits(F.getMode(), y)), F.write(S);
1045
+ }
1046
+ for (var K = 0, N = 0; N < m.length; N += 1)
1047
+ K += m[N].dataCount;
1048
+ if (S.getLengthInBits() > K * 8)
1049
+ throw "code length overflow. (" + S.getLengthInBits() + ">" + K * 8 + ")";
1050
+ for (S.getLengthInBits() + 4 <= K * 8 && S.put(0, 4); S.getLengthInBits() % 8 != 0; )
1051
+ S.putBit(!1);
1052
+ for (; !(S.getLengthInBits() >= K * 8 || (S.put(x, 8), S.getLengthInBits() >= K * 8)); )
1053
+ S.put(B, 8);
1054
+ return Y(S, m);
1055
+ };
1056
+ l.addData = function(y, b) {
1057
+ b = b || "Byte";
1058
+ var p = null;
1059
+ switch (b) {
1060
+ case "Numeric":
1061
+ p = _(y);
1062
+ break;
1063
+ case "Alphanumeric":
1064
+ p = k(y);
1065
+ break;
1066
+ case "Byte":
1067
+ p = P(y);
1068
+ break;
1069
+ case "Kanji":
1070
+ p = q(y);
1071
+ break;
1072
+ default:
1073
+ throw "mode:" + b;
1074
+ }
1075
+ f.push(p), d = null;
1076
+ }, l.isDark = function(y, b) {
1077
+ if (y < 0 || c <= y || b < 0 || c <= b)
1078
+ throw y + "," + b;
1079
+ return h[y][b];
1080
+ }, l.getModuleCount = function() {
1081
+ return c;
1082
+ }, l.make = function() {
1083
+ if (g < 1) {
1084
+ for (var y = 1; y < 40; y++) {
1085
+ for (var b = T.getRSBlocks(y, E), p = R(), m = 0; m < f.length; m++) {
1086
+ var S = f[m];
1087
+ p.put(S.getMode(), 4), p.put(S.getLength(), a.getLengthInBits(S.getMode(), y)), S.write(p);
1088
+ }
1089
+ for (var N = 0, m = 0; m < b.length; m++)
1090
+ N += b[m].dataCount;
1091
+ if (p.getLengthInBits() <= N * 8)
1092
+ break;
1093
+ }
1094
+ g = y;
1095
+ }
1096
+ v(!1, C());
1097
+ }, l.createTableTag = function(y, b) {
1098
+ y = y || 2, b = typeof b > "u" ? y * 4 : b;
1099
+ var p = "";
1100
+ p += '<table style="', p += " border-width: 0px; border-style: none;", p += " border-collapse: collapse;", p += " padding: 0px; margin: " + b + "px;", p += '">', p += "<tbody>";
1101
+ for (var m = 0; m < l.getModuleCount(); m += 1) {
1102
+ p += "<tr>";
1103
+ for (var S = 0; S < l.getModuleCount(); S += 1)
1104
+ p += '<td style="', p += " border-width: 0px; border-style: none;", p += " border-collapse: collapse;", p += " padding: 0px; margin: 0px;", p += " width: " + y + "px;", p += " height: " + y + "px;", p += " background-color: ", p += l.isDark(m, S) ? "#000000" : "#ffffff", p += ";", p += '"/>';
1105
+ p += "</tr>";
1106
+ }
1107
+ return p += "</tbody>", p += "</table>", p;
1108
+ }, l.createSvgTag = function(y, b, p, m) {
1109
+ var S = {};
1110
+ typeof arguments[0] == "object" && (S = arguments[0], y = S.cellSize, b = S.margin, p = S.alt, m = S.title), y = y || 2, b = typeof b > "u" ? y * 4 : b, p = typeof p == "string" ? { text: p } : p || {}, p.text = p.text || null, p.id = p.text ? p.id || "qrcode-description" : null, m = typeof m == "string" ? { text: m } : m || {}, m.text = m.text || null, m.id = m.text ? m.id || "qrcode-title" : null;
1111
+ var N = l.getModuleCount() * y + b * 2, F, K, X, te, V = "", ae;
1112
+ for (ae = "l" + y + ",0 0," + y + " -" + y + ",0 0,-" + y + "z ", V += '<svg version="1.1" xmlns="http://www.w3.org/2000/svg"', V += S.scalable ? "" : ' width="' + N + 'px" height="' + N + 'px"', V += ' viewBox="0 0 ' + N + " " + N + '" ', V += ' preserveAspectRatio="xMinYMin meet"', V += m.text || p.text ? ' role="img" aria-labelledby="' + J([m.id, p.id].join(" ").trim()) + '"' : "", V += ">", V += m.text ? '<title id="' + J(m.id) + '">' + J(m.text) + "</title>" : "", V += p.text ? '<description id="' + J(p.id) + '">' + J(p.text) + "</description>" : "", V += '<rect width="100%" height="100%" fill="white" cx="0" cy="0"/>', V += '<path d="', X = 0; X < l.getModuleCount(); X += 1)
1113
+ for (te = X * y + b, F = 0; F < l.getModuleCount(); F += 1)
1114
+ l.isDark(X, F) && (K = F * y + b, V += "M" + K + "," + te + ae);
1115
+ return V += '" stroke="transparent" fill="black"/>', V += "</svg>", V;
1116
+ }, l.createDataURL = function(y, b) {
1117
+ y = y || 2, b = typeof b > "u" ? y * 4 : b;
1118
+ var p = l.getModuleCount() * y + b * 2, m = b, S = p - b;
1119
+ return Q(p, p, function(N, F) {
1120
+ if (m <= N && N < S && m <= F && F < S) {
1121
+ var K = Math.floor((N - m) / y), X = Math.floor((F - m) / y);
1122
+ return l.isDark(X, K) ? 0 : 1;
1123
+ } else
1124
+ return 1;
1125
+ });
1126
+ }, l.createImgTag = function(y, b, p) {
1127
+ y = y || 2, b = typeof b > "u" ? y * 4 : b;
1128
+ var m = l.getModuleCount() * y + b * 2, S = "";
1129
+ return S += "<img", S += ' src="', S += l.createDataURL(y, b), S += '"', S += ' width="', S += m, S += '"', S += ' height="', S += m, S += '"', p && (S += ' alt="', S += J(p), S += '"'), S += "/>", S;
1130
+ };
1131
+ var J = function(y) {
1132
+ for (var b = "", p = 0; p < y.length; p += 1) {
1133
+ var m = y.charAt(p);
1134
+ switch (m) {
1135
+ case "<":
1136
+ b += "&lt;";
1137
+ break;
1138
+ case ">":
1139
+ b += "&gt;";
1140
+ break;
1141
+ case "&":
1142
+ b += "&amp;";
1143
+ break;
1144
+ case '"':
1145
+ b += "&quot;";
1146
+ break;
1147
+ default:
1148
+ b += m;
1149
+ break;
1150
+ }
1151
+ }
1152
+ return b;
1153
+ }, ee = function(y) {
1154
+ var b = 1;
1155
+ y = typeof y > "u" ? b * 2 : y;
1156
+ var p = l.getModuleCount() * b + y * 2, m = y, S = p - y, N, F, K, X, te, V = {
1157
+ "██": "█",
1158
+ "█ ": "▀",
1159
+ " █": "▄",
1160
+ " ": " "
1161
+ }, ae = {
1162
+ "██": "▀",
1163
+ "█ ": "▀",
1164
+ " █": " ",
1165
+ " ": " "
1166
+ }, ce = "";
1167
+ for (N = 0; N < p; N += 2) {
1168
+ for (K = Math.floor((N - m) / b), X = Math.floor((N + 1 - m) / b), F = 0; F < p; F += 1)
1169
+ te = "█", m <= F && F < S && m <= N && N < S && l.isDark(K, Math.floor((F - m) / b)) && (te = " "), m <= F && F < S && m <= N + 1 && N + 1 < S && l.isDark(X, Math.floor((F - m) / b)) ? te += " " : te += "█", ce += y < 1 && N + 1 >= S ? ae[te] : V[te];
1170
+ ce += `
1171
+ `;
1172
+ }
1173
+ return p % 2 && y > 0 ? ce.substring(0, ce.length - p - 1) + Array(p + 1).join("▀") : ce.substring(0, ce.length - 1);
1174
+ };
1175
+ return l.createASCII = function(y, b) {
1176
+ if (y = y || 1, y < 2)
1177
+ return ee(b);
1178
+ y -= 1, b = typeof b > "u" ? y * 2 : b;
1179
+ var p = l.getModuleCount() * y + b * 2, m = b, S = p - b, N, F, K, X, te = Array(y + 1).join("██"), V = Array(y + 1).join(" "), ae = "", ce = "";
1180
+ for (N = 0; N < p; N += 1) {
1181
+ for (K = Math.floor((N - m) / y), ce = "", F = 0; F < p; F += 1)
1182
+ X = 1, m <= F && F < S && m <= N && N < S && l.isDark(K, Math.floor((F - m) / y)) && (X = 0), ce += X ? te : V;
1183
+ for (K = 0; K < y; K += 1)
1184
+ ae += ce + `
1185
+ `;
1186
+ }
1187
+ return ae.substring(0, ae.length - 1);
1188
+ }, l.renderTo2dContext = function(y, b) {
1189
+ b = b || 2;
1190
+ for (var p = l.getModuleCount(), m = 0; m < p; m++)
1191
+ for (var S = 0; S < p; S++)
1192
+ y.fillStyle = l.isDark(m, S) ? "black" : "white", y.fillRect(m * b, S * b, b, b);
1193
+ }, l;
1194
+ };
1195
+ n.stringToBytesFuncs = {
1196
+ default: function(M) {
1197
+ for (var L = [], x = 0; x < M.length; x += 1) {
1198
+ var B = M.charCodeAt(x);
1199
+ L.push(B & 255);
1200
+ }
1201
+ return L;
1202
+ }
1203
+ }, n.stringToBytes = n.stringToBytesFuncs.default, n.createStringToBytes = function(M, L) {
1204
+ var x = (function() {
1205
+ for (var g = W(M), E = function() {
1206
+ var I = g.read();
1207
+ if (I == -1) throw "eof";
1208
+ return I;
1209
+ }, h = 0, c = {}; ; ) {
1210
+ var d = g.read();
1211
+ if (d == -1) break;
1212
+ var f = E(), l = E(), v = E(), A = String.fromCharCode(d << 8 | f), C = l << 8 | v;
1213
+ c[A] = C, h += 1;
1214
+ }
1215
+ if (h != L)
1216
+ throw h + " != " + L;
1217
+ return c;
1218
+ })(), B = 63;
1219
+ return function(g) {
1220
+ for (var E = [], h = 0; h < g.length; h += 1) {
1221
+ var c = g.charCodeAt(h);
1222
+ if (c < 128)
1223
+ E.push(c);
1224
+ else {
1225
+ var d = x[g.charAt(h)];
1226
+ typeof d == "number" ? (d & 255) == d ? E.push(d) : (E.push(d >>> 8), E.push(d & 255)) : E.push(B);
1227
+ }
1228
+ }
1229
+ return E;
1230
+ };
1231
+ };
1232
+ var i = {
1233
+ MODE_NUMBER: 1,
1234
+ MODE_ALPHA_NUM: 2,
1235
+ MODE_8BIT_BYTE: 4,
1236
+ MODE_KANJI: 8
1237
+ }, s = {
1238
+ L: 1,
1239
+ M: 0,
1240
+ Q: 3,
1241
+ H: 2
1242
+ }, o = {
1243
+ PATTERN000: 0,
1244
+ PATTERN001: 1,
1245
+ PATTERN010: 2,
1246
+ PATTERN011: 3,
1247
+ PATTERN100: 4,
1248
+ PATTERN101: 5,
1249
+ PATTERN110: 6,
1250
+ PATTERN111: 7
1251
+ }, a = (function() {
1252
+ var M = [
1253
+ [],
1254
+ [6, 18],
1255
+ [6, 22],
1256
+ [6, 26],
1257
+ [6, 30],
1258
+ [6, 34],
1259
+ [6, 22, 38],
1260
+ [6, 24, 42],
1261
+ [6, 26, 46],
1262
+ [6, 28, 50],
1263
+ [6, 30, 54],
1264
+ [6, 32, 58],
1265
+ [6, 34, 62],
1266
+ [6, 26, 46, 66],
1267
+ [6, 26, 48, 70],
1268
+ [6, 26, 50, 74],
1269
+ [6, 30, 54, 78],
1270
+ [6, 30, 56, 82],
1271
+ [6, 30, 58, 86],
1272
+ [6, 34, 62, 90],
1273
+ [6, 28, 50, 72, 94],
1274
+ [6, 26, 50, 74, 98],
1275
+ [6, 30, 54, 78, 102],
1276
+ [6, 28, 54, 80, 106],
1277
+ [6, 32, 58, 84, 110],
1278
+ [6, 30, 58, 86, 114],
1279
+ [6, 34, 62, 90, 118],
1280
+ [6, 26, 50, 74, 98, 122],
1281
+ [6, 30, 54, 78, 102, 126],
1282
+ [6, 26, 52, 78, 104, 130],
1283
+ [6, 30, 56, 82, 108, 134],
1284
+ [6, 34, 60, 86, 112, 138],
1285
+ [6, 30, 58, 86, 114, 142],
1286
+ [6, 34, 62, 90, 118, 146],
1287
+ [6, 30, 54, 78, 102, 126, 150],
1288
+ [6, 24, 50, 76, 102, 128, 154],
1289
+ [6, 28, 54, 80, 106, 132, 158],
1290
+ [6, 32, 58, 84, 110, 136, 162],
1291
+ [6, 26, 54, 82, 110, 138, 166],
1292
+ [6, 30, 58, 86, 114, 142, 170]
1293
+ ], L = 1335, x = 7973, B = 21522, g = {}, E = function(h) {
1294
+ for (var c = 0; h != 0; )
1295
+ c += 1, h >>>= 1;
1296
+ return c;
1297
+ };
1298
+ return g.getBCHTypeInfo = function(h) {
1299
+ for (var c = h << 10; E(c) - E(L) >= 0; )
1300
+ c ^= L << E(c) - E(L);
1301
+ return (h << 10 | c) ^ B;
1302
+ }, g.getBCHTypeNumber = function(h) {
1303
+ for (var c = h << 12; E(c) - E(x) >= 0; )
1304
+ c ^= x << E(c) - E(x);
1305
+ return h << 12 | c;
1306
+ }, g.getPatternPosition = function(h) {
1307
+ return M[h - 1];
1308
+ }, g.getMaskFunction = function(h) {
1309
+ switch (h) {
1310
+ case o.PATTERN000:
1311
+ return function(c, d) {
1312
+ return (c + d) % 2 == 0;
1313
+ };
1314
+ case o.PATTERN001:
1315
+ return function(c, d) {
1316
+ return c % 2 == 0;
1317
+ };
1318
+ case o.PATTERN010:
1319
+ return function(c, d) {
1320
+ return d % 3 == 0;
1321
+ };
1322
+ case o.PATTERN011:
1323
+ return function(c, d) {
1324
+ return (c + d) % 3 == 0;
1325
+ };
1326
+ case o.PATTERN100:
1327
+ return function(c, d) {
1328
+ return (Math.floor(c / 2) + Math.floor(d / 3)) % 2 == 0;
1329
+ };
1330
+ case o.PATTERN101:
1331
+ return function(c, d) {
1332
+ return c * d % 2 + c * d % 3 == 0;
1333
+ };
1334
+ case o.PATTERN110:
1335
+ return function(c, d) {
1336
+ return (c * d % 2 + c * d % 3) % 2 == 0;
1337
+ };
1338
+ case o.PATTERN111:
1339
+ return function(c, d) {
1340
+ return (c * d % 3 + (c + d) % 2) % 2 == 0;
1341
+ };
1342
+ default:
1343
+ throw "bad maskPattern:" + h;
1344
+ }
1345
+ }, g.getErrorCorrectPolynomial = function(h) {
1346
+ for (var c = w([1], 0), d = 0; d < h; d += 1)
1347
+ c = c.multiply(w([1, u.gexp(d)], 0));
1348
+ return c;
1349
+ }, g.getLengthInBits = function(h, c) {
1350
+ if (1 <= c && c < 10)
1351
+ switch (h) {
1352
+ case i.MODE_NUMBER:
1353
+ return 10;
1354
+ case i.MODE_ALPHA_NUM:
1355
+ return 9;
1356
+ case i.MODE_8BIT_BYTE:
1357
+ return 8;
1358
+ case i.MODE_KANJI:
1359
+ return 8;
1360
+ default:
1361
+ throw "mode:" + h;
1362
+ }
1363
+ else if (c < 27)
1364
+ switch (h) {
1365
+ case i.MODE_NUMBER:
1366
+ return 12;
1367
+ case i.MODE_ALPHA_NUM:
1368
+ return 11;
1369
+ case i.MODE_8BIT_BYTE:
1370
+ return 16;
1371
+ case i.MODE_KANJI:
1372
+ return 10;
1373
+ default:
1374
+ throw "mode:" + h;
1375
+ }
1376
+ else if (c < 41)
1377
+ switch (h) {
1378
+ case i.MODE_NUMBER:
1379
+ return 14;
1380
+ case i.MODE_ALPHA_NUM:
1381
+ return 13;
1382
+ case i.MODE_8BIT_BYTE:
1383
+ return 16;
1384
+ case i.MODE_KANJI:
1385
+ return 12;
1386
+ default:
1387
+ throw "mode:" + h;
1388
+ }
1389
+ else
1390
+ throw "type:" + c;
1391
+ }, g.getLostPoint = function(h) {
1392
+ for (var c = h.getModuleCount(), d = 0, f = 0; f < c; f += 1)
1393
+ for (var l = 0; l < c; l += 1) {
1394
+ for (var v = 0, A = h.isDark(f, l), C = -1; C <= 1; C += 1)
1395
+ if (!(f + C < 0 || c <= f + C))
1396
+ for (var I = -1; I <= 1; I += 1)
1397
+ l + I < 0 || c <= l + I || C == 0 && I == 0 || A == h.isDark(f + C, l + I) && (v += 1);
1398
+ v > 5 && (d += 3 + v - 5);
1399
+ }
1400
+ for (var f = 0; f < c - 1; f += 1)
1401
+ for (var l = 0; l < c - 1; l += 1) {
1402
+ var O = 0;
1403
+ h.isDark(f, l) && (O += 1), h.isDark(f + 1, l) && (O += 1), h.isDark(f, l + 1) && (O += 1), h.isDark(f + 1, l + 1) && (O += 1), (O == 0 || O == 4) && (d += 3);
1404
+ }
1405
+ for (var f = 0; f < c; f += 1)
1406
+ for (var l = 0; l < c - 6; l += 1)
1407
+ h.isDark(f, l) && !h.isDark(f, l + 1) && h.isDark(f, l + 2) && h.isDark(f, l + 3) && h.isDark(f, l + 4) && !h.isDark(f, l + 5) && h.isDark(f, l + 6) && (d += 40);
1408
+ for (var l = 0; l < c; l += 1)
1409
+ for (var f = 0; f < c - 6; f += 1)
1410
+ h.isDark(f, l) && !h.isDark(f + 1, l) && h.isDark(f + 2, l) && h.isDark(f + 3, l) && h.isDark(f + 4, l) && !h.isDark(f + 5, l) && h.isDark(f + 6, l) && (d += 40);
1411
+ for (var $ = 0, l = 0; l < c; l += 1)
1412
+ for (var f = 0; f < c; f += 1)
1413
+ h.isDark(f, l) && ($ += 1);
1414
+ var D = Math.abs(100 * $ / c / c - 50) / 5;
1415
+ return d += D * 10, d;
1416
+ }, g;
1417
+ })(), u = (function() {
1418
+ for (var M = new Array(256), L = new Array(256), x = 0; x < 8; x += 1)
1419
+ M[x] = 1 << x;
1420
+ for (var x = 8; x < 256; x += 1)
1421
+ M[x] = M[x - 4] ^ M[x - 5] ^ M[x - 6] ^ M[x - 8];
1422
+ for (var x = 0; x < 255; x += 1)
1423
+ L[M[x]] = x;
1424
+ var B = {};
1425
+ return B.glog = function(g) {
1426
+ if (g < 1)
1427
+ throw "glog(" + g + ")";
1428
+ return L[g];
1429
+ }, B.gexp = function(g) {
1430
+ for (; g < 0; )
1431
+ g += 255;
1432
+ for (; g >= 256; )
1433
+ g -= 255;
1434
+ return M[g];
1435
+ }, B;
1436
+ })();
1437
+ function w(M, L) {
1438
+ if (typeof M.length > "u")
1439
+ throw M.length + "/" + L;
1440
+ var x = (function() {
1441
+ for (var g = 0; g < M.length && M[g] == 0; )
1442
+ g += 1;
1443
+ for (var E = new Array(M.length - g + L), h = 0; h < M.length - g; h += 1)
1444
+ E[h] = M[h + g];
1445
+ return E;
1446
+ })(), B = {};
1447
+ return B.getAt = function(g) {
1448
+ return x[g];
1449
+ }, B.getLength = function() {
1450
+ return x.length;
1451
+ }, B.multiply = function(g) {
1452
+ for (var E = new Array(B.getLength() + g.getLength() - 1), h = 0; h < B.getLength(); h += 1)
1453
+ for (var c = 0; c < g.getLength(); c += 1)
1454
+ E[h + c] ^= u.gexp(u.glog(B.getAt(h)) + u.glog(g.getAt(c)));
1455
+ return w(E, 0);
1456
+ }, B.mod = function(g) {
1457
+ if (B.getLength() - g.getLength() < 0)
1458
+ return B;
1459
+ for (var E = u.glog(B.getAt(0)) - u.glog(g.getAt(0)), h = new Array(B.getLength()), c = 0; c < B.getLength(); c += 1)
1460
+ h[c] = B.getAt(c);
1461
+ for (var c = 0; c < g.getLength(); c += 1)
1462
+ h[c] ^= u.gexp(u.glog(g.getAt(c)) + E);
1463
+ return w(h, 0).mod(g);
1464
+ }, B;
1465
+ }
1466
+ var T = (function() {
1467
+ var M = [
1468
+ // L
1469
+ // M
1470
+ // Q
1471
+ // H
1472
+ // 1
1473
+ [1, 26, 19],
1474
+ [1, 26, 16],
1475
+ [1, 26, 13],
1476
+ [1, 26, 9],
1477
+ // 2
1478
+ [1, 44, 34],
1479
+ [1, 44, 28],
1480
+ [1, 44, 22],
1481
+ [1, 44, 16],
1482
+ // 3
1483
+ [1, 70, 55],
1484
+ [1, 70, 44],
1485
+ [2, 35, 17],
1486
+ [2, 35, 13],
1487
+ // 4
1488
+ [1, 100, 80],
1489
+ [2, 50, 32],
1490
+ [2, 50, 24],
1491
+ [4, 25, 9],
1492
+ // 5
1493
+ [1, 134, 108],
1494
+ [2, 67, 43],
1495
+ [2, 33, 15, 2, 34, 16],
1496
+ [2, 33, 11, 2, 34, 12],
1497
+ // 6
1498
+ [2, 86, 68],
1499
+ [4, 43, 27],
1500
+ [4, 43, 19],
1501
+ [4, 43, 15],
1502
+ // 7
1503
+ [2, 98, 78],
1504
+ [4, 49, 31],
1505
+ [2, 32, 14, 4, 33, 15],
1506
+ [4, 39, 13, 1, 40, 14],
1507
+ // 8
1508
+ [2, 121, 97],
1509
+ [2, 60, 38, 2, 61, 39],
1510
+ [4, 40, 18, 2, 41, 19],
1511
+ [4, 40, 14, 2, 41, 15],
1512
+ // 9
1513
+ [2, 146, 116],
1514
+ [3, 58, 36, 2, 59, 37],
1515
+ [4, 36, 16, 4, 37, 17],
1516
+ [4, 36, 12, 4, 37, 13],
1517
+ // 10
1518
+ [2, 86, 68, 2, 87, 69],
1519
+ [4, 69, 43, 1, 70, 44],
1520
+ [6, 43, 19, 2, 44, 20],
1521
+ [6, 43, 15, 2, 44, 16],
1522
+ // 11
1523
+ [4, 101, 81],
1524
+ [1, 80, 50, 4, 81, 51],
1525
+ [4, 50, 22, 4, 51, 23],
1526
+ [3, 36, 12, 8, 37, 13],
1527
+ // 12
1528
+ [2, 116, 92, 2, 117, 93],
1529
+ [6, 58, 36, 2, 59, 37],
1530
+ [4, 46, 20, 6, 47, 21],
1531
+ [7, 42, 14, 4, 43, 15],
1532
+ // 13
1533
+ [4, 133, 107],
1534
+ [8, 59, 37, 1, 60, 38],
1535
+ [8, 44, 20, 4, 45, 21],
1536
+ [12, 33, 11, 4, 34, 12],
1537
+ // 14
1538
+ [3, 145, 115, 1, 146, 116],
1539
+ [4, 64, 40, 5, 65, 41],
1540
+ [11, 36, 16, 5, 37, 17],
1541
+ [11, 36, 12, 5, 37, 13],
1542
+ // 15
1543
+ [5, 109, 87, 1, 110, 88],
1544
+ [5, 65, 41, 5, 66, 42],
1545
+ [5, 54, 24, 7, 55, 25],
1546
+ [11, 36, 12, 7, 37, 13],
1547
+ // 16
1548
+ [5, 122, 98, 1, 123, 99],
1549
+ [7, 73, 45, 3, 74, 46],
1550
+ [15, 43, 19, 2, 44, 20],
1551
+ [3, 45, 15, 13, 46, 16],
1552
+ // 17
1553
+ [1, 135, 107, 5, 136, 108],
1554
+ [10, 74, 46, 1, 75, 47],
1555
+ [1, 50, 22, 15, 51, 23],
1556
+ [2, 42, 14, 17, 43, 15],
1557
+ // 18
1558
+ [5, 150, 120, 1, 151, 121],
1559
+ [9, 69, 43, 4, 70, 44],
1560
+ [17, 50, 22, 1, 51, 23],
1561
+ [2, 42, 14, 19, 43, 15],
1562
+ // 19
1563
+ [3, 141, 113, 4, 142, 114],
1564
+ [3, 70, 44, 11, 71, 45],
1565
+ [17, 47, 21, 4, 48, 22],
1566
+ [9, 39, 13, 16, 40, 14],
1567
+ // 20
1568
+ [3, 135, 107, 5, 136, 108],
1569
+ [3, 67, 41, 13, 68, 42],
1570
+ [15, 54, 24, 5, 55, 25],
1571
+ [15, 43, 15, 10, 44, 16],
1572
+ // 21
1573
+ [4, 144, 116, 4, 145, 117],
1574
+ [17, 68, 42],
1575
+ [17, 50, 22, 6, 51, 23],
1576
+ [19, 46, 16, 6, 47, 17],
1577
+ // 22
1578
+ [2, 139, 111, 7, 140, 112],
1579
+ [17, 74, 46],
1580
+ [7, 54, 24, 16, 55, 25],
1581
+ [34, 37, 13],
1582
+ // 23
1583
+ [4, 151, 121, 5, 152, 122],
1584
+ [4, 75, 47, 14, 76, 48],
1585
+ [11, 54, 24, 14, 55, 25],
1586
+ [16, 45, 15, 14, 46, 16],
1587
+ // 24
1588
+ [6, 147, 117, 4, 148, 118],
1589
+ [6, 73, 45, 14, 74, 46],
1590
+ [11, 54, 24, 16, 55, 25],
1591
+ [30, 46, 16, 2, 47, 17],
1592
+ // 25
1593
+ [8, 132, 106, 4, 133, 107],
1594
+ [8, 75, 47, 13, 76, 48],
1595
+ [7, 54, 24, 22, 55, 25],
1596
+ [22, 45, 15, 13, 46, 16],
1597
+ // 26
1598
+ [10, 142, 114, 2, 143, 115],
1599
+ [19, 74, 46, 4, 75, 47],
1600
+ [28, 50, 22, 6, 51, 23],
1601
+ [33, 46, 16, 4, 47, 17],
1602
+ // 27
1603
+ [8, 152, 122, 4, 153, 123],
1604
+ [22, 73, 45, 3, 74, 46],
1605
+ [8, 53, 23, 26, 54, 24],
1606
+ [12, 45, 15, 28, 46, 16],
1607
+ // 28
1608
+ [3, 147, 117, 10, 148, 118],
1609
+ [3, 73, 45, 23, 74, 46],
1610
+ [4, 54, 24, 31, 55, 25],
1611
+ [11, 45, 15, 31, 46, 16],
1612
+ // 29
1613
+ [7, 146, 116, 7, 147, 117],
1614
+ [21, 73, 45, 7, 74, 46],
1615
+ [1, 53, 23, 37, 54, 24],
1616
+ [19, 45, 15, 26, 46, 16],
1617
+ // 30
1618
+ [5, 145, 115, 10, 146, 116],
1619
+ [19, 75, 47, 10, 76, 48],
1620
+ [15, 54, 24, 25, 55, 25],
1621
+ [23, 45, 15, 25, 46, 16],
1622
+ // 31
1623
+ [13, 145, 115, 3, 146, 116],
1624
+ [2, 74, 46, 29, 75, 47],
1625
+ [42, 54, 24, 1, 55, 25],
1626
+ [23, 45, 15, 28, 46, 16],
1627
+ // 32
1628
+ [17, 145, 115],
1629
+ [10, 74, 46, 23, 75, 47],
1630
+ [10, 54, 24, 35, 55, 25],
1631
+ [19, 45, 15, 35, 46, 16],
1632
+ // 33
1633
+ [17, 145, 115, 1, 146, 116],
1634
+ [14, 74, 46, 21, 75, 47],
1635
+ [29, 54, 24, 19, 55, 25],
1636
+ [11, 45, 15, 46, 46, 16],
1637
+ // 34
1638
+ [13, 145, 115, 6, 146, 116],
1639
+ [14, 74, 46, 23, 75, 47],
1640
+ [44, 54, 24, 7, 55, 25],
1641
+ [59, 46, 16, 1, 47, 17],
1642
+ // 35
1643
+ [12, 151, 121, 7, 152, 122],
1644
+ [12, 75, 47, 26, 76, 48],
1645
+ [39, 54, 24, 14, 55, 25],
1646
+ [22, 45, 15, 41, 46, 16],
1647
+ // 36
1648
+ [6, 151, 121, 14, 152, 122],
1649
+ [6, 75, 47, 34, 76, 48],
1650
+ [46, 54, 24, 10, 55, 25],
1651
+ [2, 45, 15, 64, 46, 16],
1652
+ // 37
1653
+ [17, 152, 122, 4, 153, 123],
1654
+ [29, 74, 46, 14, 75, 47],
1655
+ [49, 54, 24, 10, 55, 25],
1656
+ [24, 45, 15, 46, 46, 16],
1657
+ // 38
1658
+ [4, 152, 122, 18, 153, 123],
1659
+ [13, 74, 46, 32, 75, 47],
1660
+ [48, 54, 24, 14, 55, 25],
1661
+ [42, 45, 15, 32, 46, 16],
1662
+ // 39
1663
+ [20, 147, 117, 4, 148, 118],
1664
+ [40, 75, 47, 7, 76, 48],
1665
+ [43, 54, 24, 22, 55, 25],
1666
+ [10, 45, 15, 67, 46, 16],
1667
+ // 40
1668
+ [19, 148, 118, 6, 149, 119],
1669
+ [18, 75, 47, 31, 76, 48],
1670
+ [34, 54, 24, 34, 55, 25],
1671
+ [20, 45, 15, 61, 46, 16]
1672
+ ], L = function(g, E) {
1673
+ var h = {};
1674
+ return h.totalCount = g, h.dataCount = E, h;
1675
+ }, x = {}, B = function(g, E) {
1676
+ switch (E) {
1677
+ case s.L:
1678
+ return M[(g - 1) * 4 + 0];
1679
+ case s.M:
1680
+ return M[(g - 1) * 4 + 1];
1681
+ case s.Q:
1682
+ return M[(g - 1) * 4 + 2];
1683
+ case s.H:
1684
+ return M[(g - 1) * 4 + 3];
1685
+ default:
1686
+ return;
1687
+ }
1688
+ };
1689
+ return x.getRSBlocks = function(g, E) {
1690
+ var h = B(g, E);
1691
+ if (typeof h > "u")
1692
+ throw "bad rs block @ typeNumber:" + g + "/errorCorrectionLevel:" + E;
1693
+ for (var c = h.length / 3, d = [], f = 0; f < c; f += 1)
1694
+ for (var l = h[f * 3 + 0], v = h[f * 3 + 1], A = h[f * 3 + 2], C = 0; C < l; C += 1)
1695
+ d.push(L(v, A));
1696
+ return d;
1697
+ }, x;
1698
+ })(), R = function() {
1699
+ var M = [], L = 0, x = {};
1700
+ return x.getBuffer = function() {
1701
+ return M;
1702
+ }, x.getAt = function(B) {
1703
+ var g = Math.floor(B / 8);
1704
+ return (M[g] >>> 7 - B % 8 & 1) == 1;
1705
+ }, x.put = function(B, g) {
1706
+ for (var E = 0; E < g; E += 1)
1707
+ x.putBit((B >>> g - E - 1 & 1) == 1);
1708
+ }, x.getLengthInBits = function() {
1709
+ return L;
1710
+ }, x.putBit = function(B) {
1711
+ var g = Math.floor(L / 8);
1712
+ M.length <= g && M.push(0), B && (M[g] |= 128 >>> L % 8), L += 1;
1713
+ }, x;
1714
+ }, _ = function(M) {
1715
+ var L = i.MODE_NUMBER, x = M, B = {};
1716
+ B.getMode = function() {
1717
+ return L;
1718
+ }, B.getLength = function(h) {
1719
+ return x.length;
1720
+ }, B.write = function(h) {
1721
+ for (var c = x, d = 0; d + 2 < c.length; )
1722
+ h.put(g(c.substring(d, d + 3)), 10), d += 3;
1723
+ d < c.length && (c.length - d == 1 ? h.put(g(c.substring(d, d + 1)), 4) : c.length - d == 2 && h.put(g(c.substring(d, d + 2)), 7));
1724
+ };
1725
+ var g = function(h) {
1726
+ for (var c = 0, d = 0; d < h.length; d += 1)
1727
+ c = c * 10 + E(h.charAt(d));
1728
+ return c;
1729
+ }, E = function(h) {
1730
+ if ("0" <= h && h <= "9")
1731
+ return h.charCodeAt(0) - 48;
1732
+ throw "illegal char :" + h;
1733
+ };
1734
+ return B;
1735
+ }, k = function(M) {
1736
+ var L = i.MODE_ALPHA_NUM, x = M, B = {};
1737
+ B.getMode = function() {
1738
+ return L;
1739
+ }, B.getLength = function(E) {
1740
+ return x.length;
1741
+ }, B.write = function(E) {
1742
+ for (var h = x, c = 0; c + 1 < h.length; )
1743
+ E.put(
1744
+ g(h.charAt(c)) * 45 + g(h.charAt(c + 1)),
1745
+ 11
1746
+ ), c += 2;
1747
+ c < h.length && E.put(g(h.charAt(c)), 6);
1748
+ };
1749
+ var g = function(E) {
1750
+ if ("0" <= E && E <= "9")
1751
+ return E.charCodeAt(0) - 48;
1752
+ if ("A" <= E && E <= "Z")
1753
+ return E.charCodeAt(0) - 65 + 10;
1754
+ switch (E) {
1755
+ case " ":
1756
+ return 36;
1757
+ case "$":
1758
+ return 37;
1759
+ case "%":
1760
+ return 38;
1761
+ case "*":
1762
+ return 39;
1763
+ case "+":
1764
+ return 40;
1765
+ case "-":
1766
+ return 41;
1767
+ case ".":
1768
+ return 42;
1769
+ case "/":
1770
+ return 43;
1771
+ case ":":
1772
+ return 44;
1773
+ default:
1774
+ throw "illegal char :" + E;
1775
+ }
1776
+ };
1777
+ return B;
1778
+ }, P = function(M) {
1779
+ var L = i.MODE_8BIT_BYTE, x = n.stringToBytes(M), B = {};
1780
+ return B.getMode = function() {
1781
+ return L;
1782
+ }, B.getLength = function(g) {
1783
+ return x.length;
1784
+ }, B.write = function(g) {
1785
+ for (var E = 0; E < x.length; E += 1)
1786
+ g.put(x[E], 8);
1787
+ }, B;
1788
+ }, q = function(M) {
1789
+ var L = i.MODE_KANJI, x = n.stringToBytesFuncs.SJIS;
1790
+ if (!x)
1791
+ throw "sjis not supported.";
1792
+ (function(E, h) {
1793
+ var c = x(E);
1794
+ if (c.length != 2 || (c[0] << 8 | c[1]) != h)
1795
+ throw "sjis not supported.";
1796
+ })("友", 38726);
1797
+ var B = x(M), g = {};
1798
+ return g.getMode = function() {
1799
+ return L;
1800
+ }, g.getLength = function(E) {
1801
+ return ~~(B.length / 2);
1802
+ }, g.write = function(E) {
1803
+ for (var h = B, c = 0; c + 1 < h.length; ) {
1804
+ var d = (255 & h[c]) << 8 | 255 & h[c + 1];
1805
+ if (33088 <= d && d <= 40956)
1806
+ d -= 33088;
1807
+ else if (57408 <= d && d <= 60351)
1808
+ d -= 49472;
1809
+ else
1810
+ throw "illegal char at " + (c + 1) + "/" + d;
1811
+ d = (d >>> 8 & 255) * 192 + (d & 255), E.put(d, 13), c += 2;
1812
+ }
1813
+ if (c < h.length)
1814
+ throw "illegal char at " + (c + 1);
1815
+ }, g;
1816
+ }, U = function() {
1817
+ var M = [], L = {};
1818
+ return L.writeByte = function(x) {
1819
+ M.push(x & 255);
1820
+ }, L.writeShort = function(x) {
1821
+ L.writeByte(x), L.writeByte(x >>> 8);
1822
+ }, L.writeBytes = function(x, B, g) {
1823
+ B = B || 0, g = g || x.length;
1824
+ for (var E = 0; E < g; E += 1)
1825
+ L.writeByte(x[E + B]);
1826
+ }, L.writeString = function(x) {
1827
+ for (var B = 0; B < x.length; B += 1)
1828
+ L.writeByte(x.charCodeAt(B));
1829
+ }, L.toByteArray = function() {
1830
+ return M;
1831
+ }, L.toString = function() {
1832
+ var x = "";
1833
+ x += "[";
1834
+ for (var B = 0; B < M.length; B += 1)
1835
+ B > 0 && (x += ","), x += M[B];
1836
+ return x += "]", x;
1837
+ }, L;
1838
+ }, H = function() {
1839
+ var M = 0, L = 0, x = 0, B = "", g = {}, E = function(c) {
1840
+ B += String.fromCharCode(h(c & 63));
1841
+ }, h = function(c) {
1842
+ if (!(c < 0)) {
1843
+ if (c < 26)
1844
+ return 65 + c;
1845
+ if (c < 52)
1846
+ return 97 + (c - 26);
1847
+ if (c < 62)
1848
+ return 48 + (c - 52);
1849
+ if (c == 62)
1850
+ return 43;
1851
+ if (c == 63)
1852
+ return 47;
1853
+ }
1854
+ throw "n:" + c;
1855
+ };
1856
+ return g.writeByte = function(c) {
1857
+ for (M = M << 8 | c & 255, L += 8, x += 1; L >= 6; )
1858
+ E(M >>> L - 6), L -= 6;
1859
+ }, g.flush = function() {
1860
+ if (L > 0 && (E(M << 6 - L), M = 0, L = 0), x % 3 != 0)
1861
+ for (var c = 3 - x % 3, d = 0; d < c; d += 1)
1862
+ B += "=";
1863
+ }, g.toString = function() {
1864
+ return B;
1865
+ }, g;
1866
+ }, W = function(M) {
1867
+ var L = M, x = 0, B = 0, g = 0, E = {};
1868
+ E.read = function() {
1869
+ for (; g < 8; ) {
1870
+ if (x >= L.length) {
1871
+ if (g == 0)
1872
+ return -1;
1873
+ throw "unexpected end of file./" + g;
1874
+ }
1875
+ var c = L.charAt(x);
1876
+ if (x += 1, c == "=")
1877
+ return g = 0, -1;
1878
+ if (c.match(/^\s$/))
1879
+ continue;
1880
+ B = B << 6 | h(c.charCodeAt(0)), g += 6;
1881
+ }
1882
+ var d = B >>> g - 8 & 255;
1883
+ return g -= 8, d;
1884
+ };
1885
+ var h = function(c) {
1886
+ if (65 <= c && c <= 90)
1887
+ return c - 65;
1888
+ if (97 <= c && c <= 122)
1889
+ return c - 97 + 26;
1890
+ if (48 <= c && c <= 57)
1891
+ return c - 48 + 52;
1892
+ if (c == 43)
1893
+ return 62;
1894
+ if (c == 47)
1895
+ return 63;
1896
+ throw "c:" + c;
1897
+ };
1898
+ return E;
1899
+ }, ne = function(M, L) {
1900
+ var x = M, B = L, g = new Array(M * L), E = {};
1901
+ E.setPixel = function(f, l, v) {
1902
+ g[l * x + f] = v;
1903
+ }, E.write = function(f) {
1904
+ f.writeString("GIF87a"), f.writeShort(x), f.writeShort(B), f.writeByte(128), f.writeByte(0), f.writeByte(0), f.writeByte(0), f.writeByte(0), f.writeByte(0), f.writeByte(255), f.writeByte(255), f.writeByte(255), f.writeString(","), f.writeShort(0), f.writeShort(0), f.writeShort(x), f.writeShort(B), f.writeByte(0);
1905
+ var l = 2, v = c(l);
1906
+ f.writeByte(l);
1907
+ for (var A = 0; v.length - A > 255; )
1908
+ f.writeByte(255), f.writeBytes(v, A, 255), A += 255;
1909
+ f.writeByte(v.length - A), f.writeBytes(v, A, v.length - A), f.writeByte(0), f.writeString(";");
1910
+ };
1911
+ var h = function(f) {
1912
+ var l = f, v = 0, A = 0, C = {};
1913
+ return C.write = function(I, O) {
1914
+ if (I >>> O)
1915
+ throw "length over";
1916
+ for (; v + O >= 8; )
1917
+ l.writeByte(255 & (I << v | A)), O -= 8 - v, I >>>= 8 - v, A = 0, v = 0;
1918
+ A = I << v | A, v = v + O;
1919
+ }, C.flush = function() {
1920
+ v > 0 && l.writeByte(A);
1921
+ }, C;
1922
+ }, c = function(f) {
1923
+ for (var l = 1 << f, v = (1 << f) + 1, A = f + 1, C = d(), I = 0; I < l; I += 1)
1924
+ C.add(String.fromCharCode(I));
1925
+ C.add(String.fromCharCode(l)), C.add(String.fromCharCode(v));
1926
+ var O = U(), $ = h(O);
1927
+ $.write(l, A);
1928
+ var D = 0, j = String.fromCharCode(g[D]);
1929
+ for (D += 1; D < g.length; ) {
1930
+ var Y = String.fromCharCode(g[D]);
1931
+ D += 1, C.contains(j + Y) ? j = j + Y : ($.write(C.indexOf(j), A), C.size() < 4095 && (C.size() == 1 << A && (A += 1), C.add(j + Y)), j = Y);
1932
+ }
1933
+ return $.write(C.indexOf(j), A), $.write(v, A), $.flush(), O.toByteArray();
1934
+ }, d = function() {
1935
+ var f = {}, l = 0, v = {};
1936
+ return v.add = function(A) {
1937
+ if (v.contains(A))
1938
+ throw "dup key:" + A;
1939
+ f[A] = l, l += 1;
1940
+ }, v.size = function() {
1941
+ return l;
1942
+ }, v.indexOf = function(A) {
1943
+ return f[A];
1944
+ }, v.contains = function(A) {
1945
+ return typeof f[A] < "u";
1946
+ }, v;
1947
+ };
1948
+ return E;
1949
+ }, Q = function(M, L, x) {
1950
+ for (var B = ne(M, L), g = 0; g < L; g += 1)
1951
+ for (var E = 0; E < M; E += 1)
1952
+ B.setPixel(E, g, x(E, g));
1953
+ var h = U();
1954
+ B.write(h);
1955
+ for (var c = H(), d = h.toByteArray(), f = 0; f < d.length; f += 1)
1956
+ c.writeByte(d[f]);
1957
+ return c.flush(), "data:image/gif;base64," + c;
1958
+ };
1959
+ return n;
1960
+ })();
1961
+ (function() {
1962
+ r.stringToBytesFuncs["UTF-8"] = function(n) {
1963
+ function i(s) {
1964
+ for (var o = [], a = 0; a < s.length; a++) {
1965
+ var u = s.charCodeAt(a);
1966
+ u < 128 ? o.push(u) : u < 2048 ? o.push(
1967
+ 192 | u >> 6,
1968
+ 128 | u & 63
1969
+ ) : u < 55296 || u >= 57344 ? o.push(
1970
+ 224 | u >> 12,
1971
+ 128 | u >> 6 & 63,
1972
+ 128 | u & 63
1973
+ ) : (a++, u = 65536 + ((u & 1023) << 10 | s.charCodeAt(a) & 1023), o.push(
1974
+ 240 | u >> 18,
1975
+ 128 | u >> 12 & 63,
1976
+ 128 | u >> 6 & 63,
1977
+ 128 | u & 63
1978
+ ));
1979
+ }
1980
+ return o;
1981
+ }
1982
+ return i(n);
1983
+ };
1984
+ })(), (function(n) {
1985
+ t.exports = n();
1986
+ })(function() {
1987
+ return r;
1988
+ });
1989
+ })(ct)), ct.exports;
1990
+ }
1991
+ var Fr = Kr();
1992
+ const Vr = /* @__PURE__ */ Hr(Fr);
1993
+ function Zr(t) {
1994
+ const e = Vr(0, "L");
1995
+ return e.addData(t), e.make(), e.createSvgTag({ cellSize: 3, margin: 2, scalable: !0 });
1996
+ }
1997
+ function jr(t, e, r) {
1998
+ return t & e ^ ~t & r;
1999
+ }
2000
+ function zr(t, e, r) {
2001
+ return t & e ^ t & r ^ e & r;
2002
+ }
2003
+ class Wr {
2004
+ blockLen;
2005
+ outputLen;
2006
+ padOffset;
2007
+ isLE;
2008
+ // For partial updates less than block size
2009
+ buffer;
2010
+ view;
2011
+ finished = !1;
2012
+ length = 0;
2013
+ pos = 0;
2014
+ destroyed = !1;
2015
+ constructor(e, r, n, i) {
2016
+ this.blockLen = e, this.outputLen = r, this.padOffset = n, this.isLE = i, this.buffer = new Uint8Array(e), this.view = at(this.buffer);
2017
+ }
2018
+ update(e) {
2019
+ ze(this), G(e);
2020
+ const { view: r, buffer: n, blockLen: i } = this, s = e.length;
2021
+ for (let o = 0; o < s; ) {
2022
+ const a = Math.min(i - this.pos, s - o);
2023
+ if (a === i) {
2024
+ const u = at(e);
2025
+ for (; i <= s - o; o += i)
2026
+ this.process(u, o);
2027
+ continue;
2028
+ }
2029
+ n.set(e.subarray(o, o + a), this.pos), this.pos += a, o += a, this.pos === i && (this.process(r, 0), this.pos = 0);
2030
+ }
2031
+ return this.length += e.length, this.roundClean(), this;
2032
+ }
2033
+ digestInto(e) {
2034
+ ze(this), br(e, this), this.finished = !0;
2035
+ const { buffer: r, view: n, blockLen: i, isLE: s } = this;
2036
+ let { pos: o } = this;
2037
+ r[o++] = 128, Ne(this.buffer.subarray(o)), this.padOffset > i - o && (this.process(n, 0), o = 0);
2038
+ for (let R = o; R < i; R++)
2039
+ r[R] = 0;
2040
+ n.setBigUint64(i - 8, BigInt(this.length * 8), s), this.process(n, 0);
2041
+ const a = at(e), u = this.outputLen;
2042
+ if (u % 4)
2043
+ throw new Error("_sha2: outputLen must be aligned to 32bit");
2044
+ const w = u / 4, T = this.get();
2045
+ if (w > T.length)
2046
+ throw new Error("_sha2: outputLen bigger than state");
2047
+ for (let R = 0; R < w; R++)
2048
+ a.setUint32(4 * R, T[R], s);
2049
+ }
2050
+ digest() {
2051
+ const { buffer: e, outputLen: r } = this;
2052
+ this.digestInto(e);
2053
+ const n = e.slice(0, r);
2054
+ return this.destroy(), n;
2055
+ }
2056
+ _cloneInto(e) {
2057
+ e ||= new this.constructor(), e.set(...this.get());
2058
+ const { blockLen: r, buffer: n, length: i, finished: s, destroyed: o, pos: a } = this;
2059
+ return e.destroyed = o, e.finished = s, e.length = i, e.pos = a, i % r && e.buffer.set(n), e;
2060
+ }
2061
+ clone() {
2062
+ return this._cloneInto();
2063
+ }
2064
+ }
2065
+ const be = /* @__PURE__ */ Uint32Array.from([
2066
+ 1779033703,
2067
+ 3144134277,
2068
+ 1013904242,
2069
+ 2773480762,
2070
+ 1359893119,
2071
+ 2600822924,
2072
+ 528734635,
2073
+ 1541459225
2074
+ ]), Yr = /* @__PURE__ */ Uint32Array.from([
2075
+ 1116352408,
2076
+ 1899447441,
2077
+ 3049323471,
2078
+ 3921009573,
2079
+ 961987163,
2080
+ 1508970993,
2081
+ 2453635748,
2082
+ 2870763221,
2083
+ 3624381080,
2084
+ 310598401,
2085
+ 607225278,
2086
+ 1426881987,
2087
+ 1925078388,
2088
+ 2162078206,
2089
+ 2614888103,
2090
+ 3248222580,
2091
+ 3835390401,
2092
+ 4022224774,
2093
+ 264347078,
2094
+ 604807628,
2095
+ 770255983,
2096
+ 1249150122,
2097
+ 1555081692,
2098
+ 1996064986,
2099
+ 2554220882,
2100
+ 2821834349,
2101
+ 2952996808,
2102
+ 3210313671,
2103
+ 3336571891,
2104
+ 3584528711,
2105
+ 113926993,
2106
+ 338241895,
2107
+ 666307205,
2108
+ 773529912,
2109
+ 1294757372,
2110
+ 1396182291,
2111
+ 1695183700,
2112
+ 1986661051,
2113
+ 2177026350,
2114
+ 2456956037,
2115
+ 2730485921,
2116
+ 2820302411,
2117
+ 3259730800,
2118
+ 3345764771,
2119
+ 3516065817,
2120
+ 3600352804,
2121
+ 4094571909,
2122
+ 275423344,
2123
+ 430227734,
2124
+ 506948616,
2125
+ 659060556,
2126
+ 883997877,
2127
+ 958139571,
2128
+ 1322822218,
2129
+ 1537002063,
2130
+ 1747873779,
2131
+ 1955562222,
2132
+ 2024104815,
2133
+ 2227730452,
2134
+ 2361852424,
2135
+ 2428436474,
2136
+ 2756734187,
2137
+ 3204031479,
2138
+ 3329325298
2139
+ ]), ye = /* @__PURE__ */ new Uint32Array(64);
2140
+ class Jr extends Wr {
2141
+ constructor(e) {
2142
+ super(64, e, 8, !1);
2143
+ }
2144
+ get() {
2145
+ const { A: e, B: r, C: n, D: i, E: s, F: o, G: a, H: u } = this;
2146
+ return [e, r, n, i, s, o, a, u];
2147
+ }
2148
+ // prettier-ignore
2149
+ set(e, r, n, i, s, o, a, u) {
2150
+ this.A = e | 0, this.B = r | 0, this.C = n | 0, this.D = i | 0, this.E = s | 0, this.F = o | 0, this.G = a | 0, this.H = u | 0;
2151
+ }
2152
+ process(e, r) {
2153
+ for (let R = 0; R < 16; R++, r += 4)
2154
+ ye[R] = e.getUint32(r, !1);
2155
+ for (let R = 16; R < 64; R++) {
2156
+ const _ = ye[R - 15], k = ye[R - 2], P = de(_, 7) ^ de(_, 18) ^ _ >>> 3, q = de(k, 17) ^ de(k, 19) ^ k >>> 10;
2157
+ ye[R] = q + ye[R - 7] + P + ye[R - 16] | 0;
2158
+ }
2159
+ let { A: n, B: i, C: s, D: o, E: a, F: u, G: w, H: T } = this;
2160
+ for (let R = 0; R < 64; R++) {
2161
+ const _ = de(a, 6) ^ de(a, 11) ^ de(a, 25), k = T + _ + jr(a, u, w) + Yr[R] + ye[R] | 0, q = (de(n, 2) ^ de(n, 13) ^ de(n, 22)) + zr(n, i, s) | 0;
2162
+ T = w, w = u, u = a, a = o + k | 0, o = s, s = i, i = n, n = k + q | 0;
2163
+ }
2164
+ n = n + this.A | 0, i = i + this.B | 0, s = s + this.C | 0, o = o + this.D | 0, a = a + this.E | 0, u = u + this.F | 0, w = w + this.G | 0, T = T + this.H | 0, this.set(n, i, s, o, a, u, w, T);
2165
+ }
2166
+ roundClean() {
2167
+ Ne(ye);
2168
+ }
2169
+ destroy() {
2170
+ this.set(0, 0, 0, 0, 0, 0, 0, 0), Ne(this.buffer);
2171
+ }
2172
+ }
2173
+ class Gr extends Jr {
2174
+ // We cannot use array here since array allows indexing by variable
2175
+ // which means optimizer/compiler cannot use registers.
2176
+ A = be[0] | 0;
2177
+ B = be[1] | 0;
2178
+ C = be[2] | 0;
2179
+ D = be[3] | 0;
2180
+ E = be[4] | 0;
2181
+ F = be[5] | 0;
2182
+ G = be[6] | 0;
2183
+ H = be[7] | 0;
2184
+ constructor() {
2185
+ super(32);
2186
+ }
2187
+ }
2188
+ const xe = /* @__PURE__ */ wr(
2189
+ () => new Gr(),
2190
+ /* @__PURE__ */ vr(1)
2191
+ );
2192
+ const Lt = /* @__PURE__ */ BigInt(0), Et = /* @__PURE__ */ BigInt(1);
2193
+ function Je(t, e = "") {
2194
+ if (typeof t != "boolean") {
2195
+ const r = e && `"${e}" `;
2196
+ throw new Error(r + "expected boolean, got type=" + typeof t);
2197
+ }
2198
+ return t;
2199
+ }
2200
+ function Tn(t) {
2201
+ if (typeof t == "bigint") {
2202
+ if (!je(t))
2203
+ throw new Error("positive bigint expected, got " + t);
2204
+ } else
2205
+ me(t);
2206
+ return t;
2207
+ }
2208
+ function He(t) {
2209
+ const e = Tn(t).toString(16);
2210
+ return e.length & 1 ? "0" + e : e;
2211
+ }
2212
+ function Cn(t) {
2213
+ if (typeof t != "string")
2214
+ throw new Error("hex string expected, got " + typeof t);
2215
+ return t === "" ? Lt : BigInt("0x" + t);
2216
+ }
2217
+ function De(t) {
2218
+ return Cn(le(t));
2219
+ }
2220
+ function Ln(t) {
2221
+ return Cn(le(Xr(G(t)).reverse()));
2222
+ }
2223
+ function Ot(t, e) {
2224
+ me(e), t = Tn(t);
2225
+ const r = ie(t.toString(16).padStart(e * 2, "0"));
2226
+ if (r.length !== e)
2227
+ throw new Error("number too large");
2228
+ return r;
2229
+ }
2230
+ function On(t, e) {
2231
+ return Ot(t, e).reverse();
2232
+ }
2233
+ function Xr(t) {
2234
+ return Uint8Array.from(t);
2235
+ }
2236
+ function Qr(t) {
2237
+ return Uint8Array.from(t, (e, r) => {
2238
+ const n = e.charCodeAt(0);
2239
+ if (e.length !== 1 || n > 127)
2240
+ throw new Error(`string contains non-ASCII character "${t[r]}" with code ${n} at position ${r}`);
2241
+ return n;
2242
+ });
2243
+ }
2244
+ const je = (t) => typeof t == "bigint" && Lt <= t;
2245
+ function ei(t, e, r) {
2246
+ return je(t) && je(e) && je(r) && e <= t && t < r;
2247
+ }
2248
+ function ti(t, e, r, n) {
2249
+ if (!ei(e, r, n))
2250
+ throw new Error("expected valid " + t + ": " + r + " <= n < " + n + ", got " + e);
2251
+ }
2252
+ function ni(t) {
2253
+ let e;
2254
+ for (e = 0; t > Lt; t >>= Et, e += 1)
2255
+ ;
2256
+ return e;
2257
+ }
2258
+ const It = (t) => (Et << BigInt(t)) - Et;
2259
+ function ri(t, e, r) {
2260
+ if (me(t, "hashLen"), me(e, "qByteLen"), typeof r != "function")
2261
+ throw new Error("hmacFn must be a function");
2262
+ const n = (U) => new Uint8Array(U), i = Uint8Array.of(), s = Uint8Array.of(0), o = Uint8Array.of(1), a = 1e3;
2263
+ let u = n(t), w = n(t), T = 0;
2264
+ const R = () => {
2265
+ u.fill(1), w.fill(0), T = 0;
2266
+ }, _ = (...U) => r(w, oe(u, ...U)), k = (U = i) => {
2267
+ w = _(s, U), u = _(), U.length !== 0 && (w = _(o, U), u = _());
2268
+ }, P = () => {
2269
+ if (T++ >= a)
2270
+ throw new Error("drbg: tried max amount of iterations");
2271
+ let U = 0;
2272
+ const H = [];
2273
+ for (; U < e; ) {
2274
+ u = _();
2275
+ const W = u.slice();
2276
+ H.push(W), U += u.length;
2277
+ }
2278
+ return oe(...H);
2279
+ };
2280
+ return (U, H) => {
2281
+ R(), k(U);
2282
+ let W;
2283
+ for (; !(W = H(P())); )
2284
+ k();
2285
+ return R(), W;
2286
+ };
2287
+ }
2288
+ function Pt(t, e = {}, r = {}) {
2289
+ if (!t || typeof t != "object")
2290
+ throw new Error("expected valid options object");
2291
+ function n(s, o, a) {
2292
+ const u = t[s];
2293
+ if (a && u === void 0)
2294
+ return;
2295
+ const w = typeof u;
2296
+ if (w !== o || u === null)
2297
+ throw new Error(`param "${s}" is invalid: expected ${o}, got ${w}`);
2298
+ }
2299
+ const i = (s, o) => Object.entries(s).forEach(([a, u]) => n(a, u, o));
2300
+ i(e, !1), i(r, !0);
2301
+ }
2302
+ function Qt(t) {
2303
+ const e = /* @__PURE__ */ new WeakMap();
2304
+ return (r, ...n) => {
2305
+ const i = e.get(r);
2306
+ if (i !== void 0)
2307
+ return i;
2308
+ const s = t(r, ...n);
2309
+ return e.set(r, s), s;
2310
+ };
2311
+ }
2312
+ const se = /* @__PURE__ */ BigInt(0), re = /* @__PURE__ */ BigInt(1), ke = /* @__PURE__ */ BigInt(2), In = /* @__PURE__ */ BigInt(3), Pn = /* @__PURE__ */ BigInt(4), Mn = /* @__PURE__ */ BigInt(5), ii = /* @__PURE__ */ BigInt(7), Nn = /* @__PURE__ */ BigInt(8), si = /* @__PURE__ */ BigInt(9), $n = /* @__PURE__ */ BigInt(16);
2313
+ function fe(t, e) {
2314
+ const r = t % e;
2315
+ return r >= se ? r : e + r;
2316
+ }
2317
+ function ue(t, e, r) {
2318
+ let n = t;
2319
+ for (; e-- > se; )
2320
+ n *= n, n %= r;
2321
+ return n;
2322
+ }
2323
+ function en(t, e) {
2324
+ if (t === se)
2325
+ throw new Error("invert: expected non-zero number");
2326
+ if (e <= se)
2327
+ throw new Error("invert: expected positive modulus, got " + e);
2328
+ let r = fe(t, e), n = e, i = se, s = re;
2329
+ for (; r !== se; ) {
2330
+ const a = n / r, u = n % r, w = i - s * a;
2331
+ n = r, r = u, i = s, s = w;
2332
+ }
2333
+ if (n !== re)
2334
+ throw new Error("invert: does not exist");
2335
+ return fe(i, e);
2336
+ }
2337
+ function Mt(t, e, r) {
2338
+ if (!t.eql(t.sqr(e), r))
2339
+ throw new Error("Cannot find square root");
2340
+ }
2341
+ function Dn(t, e) {
2342
+ const r = (t.ORDER + re) / Pn, n = t.pow(e, r);
2343
+ return Mt(t, n, e), n;
2344
+ }
2345
+ function oi(t, e) {
2346
+ const r = (t.ORDER - Mn) / Nn, n = t.mul(e, ke), i = t.pow(n, r), s = t.mul(e, i), o = t.mul(t.mul(s, ke), i), a = t.mul(s, t.sub(o, t.ONE));
2347
+ return Mt(t, a, e), a;
2348
+ }
2349
+ function ai(t) {
2350
+ const e = nt(t), r = qn(t), n = r(e, e.neg(e.ONE)), i = r(e, n), s = r(e, e.neg(n)), o = (t + ii) / $n;
2351
+ return (a, u) => {
2352
+ let w = a.pow(u, o), T = a.mul(w, n);
2353
+ const R = a.mul(w, i), _ = a.mul(w, s), k = a.eql(a.sqr(T), u), P = a.eql(a.sqr(R), u);
2354
+ w = a.cmov(w, T, k), T = a.cmov(_, R, P);
2355
+ const q = a.eql(a.sqr(T), u), U = a.cmov(w, T, q);
2356
+ return Mt(a, U, u), U;
2357
+ };
2358
+ }
2359
+ function qn(t) {
2360
+ if (t < In)
2361
+ throw new Error("sqrt is not defined for small field");
2362
+ let e = t - re, r = 0;
2363
+ for (; e % ke === se; )
2364
+ e /= ke, r++;
2365
+ let n = ke;
2366
+ const i = nt(t);
2367
+ for (; tn(i, n) === 1; )
2368
+ if (n++ > 1e3)
2369
+ throw new Error("Cannot find square root: probably non-prime P");
2370
+ if (r === 1)
2371
+ return Dn;
2372
+ let s = i.pow(n, e);
2373
+ const o = (e + re) / ke;
2374
+ return function(u, w) {
2375
+ if (u.is0(w))
2376
+ return w;
2377
+ if (tn(u, w) !== 1)
2378
+ throw new Error("Cannot find square root");
2379
+ let T = r, R = u.mul(u.ONE, s), _ = u.pow(w, e), k = u.pow(w, o);
2380
+ for (; !u.eql(_, u.ONE); ) {
2381
+ if (u.is0(_))
2382
+ return u.ZERO;
2383
+ let P = 1, q = u.sqr(_);
2384
+ for (; !u.eql(q, u.ONE); )
2385
+ if (P++, q = u.sqr(q), P === T)
2386
+ throw new Error("Cannot find square root");
2387
+ const U = re << BigInt(T - P - 1), H = u.pow(R, U);
2388
+ T = P, R = u.sqr(H), _ = u.mul(_, R), k = u.mul(k, H);
2389
+ }
2390
+ return k;
2391
+ };
2392
+ }
2393
+ function ci(t) {
2394
+ return t % Pn === In ? Dn : t % Nn === Mn ? oi : t % $n === si ? ai(t) : qn(t);
2395
+ }
2396
+ const ui = [
2397
+ "create",
2398
+ "isValid",
2399
+ "is0",
2400
+ "neg",
2401
+ "inv",
2402
+ "sqrt",
2403
+ "sqr",
2404
+ "eql",
2405
+ "add",
2406
+ "sub",
2407
+ "mul",
2408
+ "pow",
2409
+ "div",
2410
+ "addN",
2411
+ "subN",
2412
+ "mulN",
2413
+ "sqrN"
2414
+ ];
2415
+ function li(t) {
2416
+ const e = {
2417
+ ORDER: "bigint",
2418
+ BYTES: "number",
2419
+ BITS: "number"
2420
+ }, r = ui.reduce((n, i) => (n[i] = "function", n), e);
2421
+ return Pt(t, r), t;
2422
+ }
2423
+ function fi(t, e, r) {
2424
+ if (r < se)
2425
+ throw new Error("invalid exponent, negatives unsupported");
2426
+ if (r === se)
2427
+ return t.ONE;
2428
+ if (r === re)
2429
+ return e;
2430
+ let n = t.ONE, i = e;
2431
+ for (; r > se; )
2432
+ r & re && (n = t.mul(n, i)), i = t.sqr(i), r >>= re;
2433
+ return n;
2434
+ }
2435
+ function Un(t, e, r = !1) {
2436
+ const n = new Array(e.length).fill(r ? t.ZERO : void 0), i = e.reduce((o, a, u) => t.is0(a) ? o : (n[u] = o, t.mul(o, a)), t.ONE), s = t.inv(i);
2437
+ return e.reduceRight((o, a, u) => t.is0(a) ? o : (n[u] = t.mul(o, n[u]), t.mul(o, a)), s), n;
2438
+ }
2439
+ function tn(t, e) {
2440
+ const r = (t.ORDER - re) / ke, n = t.pow(e, r), i = t.eql(n, t.ONE), s = t.eql(n, t.ZERO), o = t.eql(n, t.neg(t.ONE));
2441
+ if (!i && !s && !o)
2442
+ throw new Error("invalid Legendre symbol result");
2443
+ return i ? 1 : s ? 0 : -1;
2444
+ }
2445
+ function di(t, e) {
2446
+ e !== void 0 && me(e);
2447
+ const r = e !== void 0 ? e : t.toString(2).length, n = Math.ceil(r / 8);
2448
+ return { nBitLength: r, nByteLength: n };
2449
+ }
2450
+ class hi {
2451
+ ORDER;
2452
+ BITS;
2453
+ BYTES;
2454
+ isLE;
2455
+ ZERO = se;
2456
+ ONE = re;
2457
+ _lengths;
2458
+ _sqrt;
2459
+ // cached sqrt
2460
+ _mod;
2461
+ constructor(e, r = {}) {
2462
+ if (e <= se)
2463
+ throw new Error("invalid field: expected ORDER > 0, got " + e);
2464
+ let n;
2465
+ this.isLE = !1, r != null && typeof r == "object" && (typeof r.BITS == "number" && (n = r.BITS), typeof r.sqrt == "function" && (this.sqrt = r.sqrt), typeof r.isLE == "boolean" && (this.isLE = r.isLE), r.allowedLengths && (this._lengths = r.allowedLengths?.slice()), typeof r.modFromBytes == "boolean" && (this._mod = r.modFromBytes));
2466
+ const { nBitLength: i, nByteLength: s } = di(e, n);
2467
+ if (s > 2048)
2468
+ throw new Error("invalid field: expected ORDER of <= 2048 bytes");
2469
+ this.ORDER = e, this.BITS = i, this.BYTES = s, this._sqrt = void 0, Object.preventExtensions(this);
2470
+ }
2471
+ create(e) {
2472
+ return fe(e, this.ORDER);
2473
+ }
2474
+ isValid(e) {
2475
+ if (typeof e != "bigint")
2476
+ throw new Error("invalid field element: expected bigint, got " + typeof e);
2477
+ return se <= e && e < this.ORDER;
2478
+ }
2479
+ is0(e) {
2480
+ return e === se;
2481
+ }
2482
+ // is valid and invertible
2483
+ isValidNot0(e) {
2484
+ return !this.is0(e) && this.isValid(e);
2485
+ }
2486
+ isOdd(e) {
2487
+ return (e & re) === re;
2488
+ }
2489
+ neg(e) {
2490
+ return fe(-e, this.ORDER);
2491
+ }
2492
+ eql(e, r) {
2493
+ return e === r;
2494
+ }
2495
+ sqr(e) {
2496
+ return fe(e * e, this.ORDER);
2497
+ }
2498
+ add(e, r) {
2499
+ return fe(e + r, this.ORDER);
2500
+ }
2501
+ sub(e, r) {
2502
+ return fe(e - r, this.ORDER);
2503
+ }
2504
+ mul(e, r) {
2505
+ return fe(e * r, this.ORDER);
2506
+ }
2507
+ pow(e, r) {
2508
+ return fi(this, e, r);
2509
+ }
2510
+ div(e, r) {
2511
+ return fe(e * en(r, this.ORDER), this.ORDER);
2512
+ }
2513
+ // Same as above, but doesn't normalize
2514
+ sqrN(e) {
2515
+ return e * e;
2516
+ }
2517
+ addN(e, r) {
2518
+ return e + r;
2519
+ }
2520
+ subN(e, r) {
2521
+ return e - r;
2522
+ }
2523
+ mulN(e, r) {
2524
+ return e * r;
2525
+ }
2526
+ inv(e) {
2527
+ return en(e, this.ORDER);
2528
+ }
2529
+ sqrt(e) {
2530
+ return this._sqrt || (this._sqrt = ci(this.ORDER)), this._sqrt(this, e);
2531
+ }
2532
+ toBytes(e) {
2533
+ return this.isLE ? On(e, this.BYTES) : Ot(e, this.BYTES);
2534
+ }
2535
+ fromBytes(e, r = !1) {
2536
+ G(e);
2537
+ const { _lengths: n, BYTES: i, isLE: s, ORDER: o, _mod: a } = this;
2538
+ if (n) {
2539
+ if (!n.includes(e.length) || e.length > i)
2540
+ throw new Error("Field.fromBytes: expected " + n + " bytes, got " + e.length);
2541
+ const w = new Uint8Array(i);
2542
+ w.set(e, s ? 0 : w.length - e.length), e = w;
2543
+ }
2544
+ if (e.length !== i)
2545
+ throw new Error("Field.fromBytes: expected " + i + " bytes, got " + e.length);
2546
+ let u = s ? Ln(e) : De(e);
2547
+ if (a && (u = fe(u, o)), !r && !this.isValid(u))
2548
+ throw new Error("invalid field element: outside of range 0..ORDER");
2549
+ return u;
2550
+ }
2551
+ // TODO: we don't need it here, move out to separate fn
2552
+ invertBatch(e) {
2553
+ return Un(this, e);
2554
+ }
2555
+ // We can't move this out because Fp6, Fp12 implement it
2556
+ // and it's unclear what to return in there.
2557
+ cmov(e, r, n) {
2558
+ return n ? r : e;
2559
+ }
2560
+ }
2561
+ function nt(t, e = {}) {
2562
+ return new hi(t, e);
2563
+ }
2564
+ function Hn(t) {
2565
+ if (typeof t != "bigint")
2566
+ throw new Error("field order must be bigint");
2567
+ const e = t.toString(2).length;
2568
+ return Math.ceil(e / 8);
2569
+ }
2570
+ function Kn(t) {
2571
+ const e = Hn(t);
2572
+ return e + Math.ceil(e / 2);
2573
+ }
2574
+ function Fn(t, e, r = !1) {
2575
+ G(t);
2576
+ const n = t.length, i = Hn(e), s = Kn(e);
2577
+ if (n < 16 || n < s || n > 1024)
2578
+ throw new Error("expected " + s + "-1024 bytes of input, got " + n);
2579
+ const o = r ? Ln(t) : De(t), a = fe(o, e - re) + re;
2580
+ return r ? On(a, i) : Ot(a, i);
2581
+ }
2582
+ const Te = /* @__PURE__ */ BigInt(0), Ae = /* @__PURE__ */ BigInt(1);
2583
+ function Ge(t, e) {
2584
+ const r = e.negate();
2585
+ return t ? r : e;
2586
+ }
2587
+ function nn(t, e) {
2588
+ const r = Un(t.Fp, e.map((n) => n.Z));
2589
+ return e.map((n, i) => t.fromAffine(n.toAffine(r[i])));
2590
+ }
2591
+ function Vn(t, e) {
2592
+ if (!Number.isSafeInteger(t) || t <= 0 || t > e)
2593
+ throw new Error("invalid window size, expected [1.." + e + "], got W=" + t);
2594
+ }
2595
+ function ut(t, e) {
2596
+ Vn(t, e);
2597
+ const r = Math.ceil(e / t) + 1, n = 2 ** (t - 1), i = 2 ** t, s = It(t), o = BigInt(t);
2598
+ return { windows: r, windowSize: n, mask: s, maxNumber: i, shiftBy: o };
2599
+ }
2600
+ function rn(t, e, r) {
2601
+ const { windowSize: n, mask: i, maxNumber: s, shiftBy: o } = r;
2602
+ let a = Number(t & i), u = t >> o;
2603
+ a > n && (a -= s, u += Ae);
2604
+ const w = e * n, T = w + Math.abs(a) - 1, R = a === 0, _ = a < 0, k = e % 2 !== 0;
2605
+ return { nextN: u, offset: T, isZero: R, isNeg: _, isNegF: k, offsetF: w };
2606
+ }
2607
+ const lt = /* @__PURE__ */ new WeakMap(), Zn = /* @__PURE__ */ new WeakMap();
2608
+ function ft(t) {
2609
+ return Zn.get(t) || 1;
2610
+ }
2611
+ function sn(t) {
2612
+ if (t !== Te)
2613
+ throw new Error("invalid wNAF");
2614
+ }
2615
+ class gi {
2616
+ BASE;
2617
+ ZERO;
2618
+ Fn;
2619
+ bits;
2620
+ // Parametrized with a given Point class (not individual point)
2621
+ constructor(e, r) {
2622
+ this.BASE = e.BASE, this.ZERO = e.ZERO, this.Fn = e.Fn, this.bits = r;
2623
+ }
2624
+ // non-const time multiplication ladder
2625
+ _unsafeLadder(e, r, n = this.ZERO) {
2626
+ let i = e;
2627
+ for (; r > Te; )
2628
+ r & Ae && (n = n.add(i)), i = i.double(), r >>= Ae;
2629
+ return n;
2630
+ }
2631
+ /**
2632
+ * Creates a wNAF precomputation window. Used for caching.
2633
+ * Default window size is set by `utils.precompute()` and is equal to 8.
2634
+ * Number of precomputed points depends on the curve size:
2635
+ * 2^(𝑊−1) * (Math.ceil(𝑛 / 𝑊) + 1), where:
2636
+ * - 𝑊 is the window size
2637
+ * - 𝑛 is the bitlength of the curve order.
2638
+ * For a 256-bit curve and window size 8, the number of precomputed points is 128 * 33 = 4224.
2639
+ * @param point Point instance
2640
+ * @param W window size
2641
+ * @returns precomputed point tables flattened to a single array
2642
+ */
2643
+ precomputeWindow(e, r) {
2644
+ const { windows: n, windowSize: i } = ut(r, this.bits), s = [];
2645
+ let o = e, a = o;
2646
+ for (let u = 0; u < n; u++) {
2647
+ a = o, s.push(a);
2648
+ for (let w = 1; w < i; w++)
2649
+ a = a.add(o), s.push(a);
2650
+ o = a.double();
2651
+ }
2652
+ return s;
2653
+ }
2654
+ /**
2655
+ * Implements ec multiplication using precomputed tables and w-ary non-adjacent form.
2656
+ * More compact implementation:
2657
+ * https://github.com/paulmillr/noble-secp256k1/blob/47cb1669b6e506ad66b35fe7d76132ae97465da2/index.ts#L502-L541
2658
+ * @returns real and fake (for const-time) points
2659
+ */
2660
+ wNAF(e, r, n) {
2661
+ if (!this.Fn.isValid(n))
2662
+ throw new Error("invalid scalar");
2663
+ let i = this.ZERO, s = this.BASE;
2664
+ const o = ut(e, this.bits);
2665
+ for (let a = 0; a < o.windows; a++) {
2666
+ const { nextN: u, offset: w, isZero: T, isNeg: R, isNegF: _, offsetF: k } = rn(n, a, o);
2667
+ n = u, T ? s = s.add(Ge(_, r[k])) : i = i.add(Ge(R, r[w]));
2668
+ }
2669
+ return sn(n), { p: i, f: s };
2670
+ }
2671
+ /**
2672
+ * Implements ec unsafe (non const-time) multiplication using precomputed tables and w-ary non-adjacent form.
2673
+ * @param acc accumulator point to add result of multiplication
2674
+ * @returns point
2675
+ */
2676
+ wNAFUnsafe(e, r, n, i = this.ZERO) {
2677
+ const s = ut(e, this.bits);
2678
+ for (let o = 0; o < s.windows && n !== Te; o++) {
2679
+ const { nextN: a, offset: u, isZero: w, isNeg: T } = rn(n, o, s);
2680
+ if (n = a, !w) {
2681
+ const R = r[u];
2682
+ i = i.add(T ? R.negate() : R);
2683
+ }
2684
+ }
2685
+ return sn(n), i;
2686
+ }
2687
+ getPrecomputes(e, r, n) {
2688
+ let i = lt.get(r);
2689
+ return i || (i = this.precomputeWindow(r, e), e !== 1 && (typeof n == "function" && (i = n(i)), lt.set(r, i))), i;
2690
+ }
2691
+ cached(e, r, n) {
2692
+ const i = ft(e);
2693
+ return this.wNAF(i, this.getPrecomputes(i, e, n), r);
2694
+ }
2695
+ unsafe(e, r, n, i) {
2696
+ const s = ft(e);
2697
+ return s === 1 ? this._unsafeLadder(e, r, i) : this.wNAFUnsafe(s, this.getPrecomputes(s, e, n), r, i);
2698
+ }
2699
+ // We calculate precomputes for elliptic curve point multiplication
2700
+ // using windowed method. This specifies window size and
2701
+ // stores precomputed values. Usually only base point would be precomputed.
2702
+ createCache(e, r) {
2703
+ Vn(r, this.bits), Zn.set(e, r), lt.delete(e);
2704
+ }
2705
+ hasCache(e) {
2706
+ return ft(e) !== 1;
2707
+ }
2708
+ }
2709
+ function pi(t, e, r, n) {
2710
+ let i = e, s = t.ZERO, o = t.ZERO;
2711
+ for (; r > Te || n > Te; )
2712
+ r & Ae && (s = s.add(i)), n & Ae && (o = o.add(i)), i = i.double(), r >>= Ae, n >>= Ae;
2713
+ return { p1: s, p2: o };
2714
+ }
2715
+ function on(t, e, r) {
2716
+ if (e) {
2717
+ if (e.ORDER !== t)
2718
+ throw new Error("Field.ORDER must match order: Fp == p, Fn == n");
2719
+ return li(e), e;
2720
+ } else
2721
+ return nt(t, { isLE: r });
2722
+ }
2723
+ function bi(t, e, r = {}, n) {
2724
+ if (n === void 0 && (n = t === "edwards"), !e || typeof e != "object")
2725
+ throw new Error(`expected valid ${t} CURVE object`);
2726
+ for (const u of ["p", "n", "h"]) {
2727
+ const w = e[u];
2728
+ if (!(typeof w == "bigint" && w > Te))
2729
+ throw new Error(`CURVE.${u} must be positive bigint`);
2730
+ }
2731
+ const i = on(e.p, r.Fp, n), s = on(e.n, r.Fn, n), a = ["Gx", "Gy", "a", "b"];
2732
+ for (const u of a)
2733
+ if (!i.isValid(e[u]))
2734
+ throw new Error(`CURVE.${u} must be valid field element of CURVE.Fp`);
2735
+ return e = Object.freeze(Object.assign({}, e)), { CURVE: e, Fp: i, Fn: s };
2736
+ }
2737
+ function jn(t, e) {
2738
+ return function(n) {
2739
+ const i = t(n);
2740
+ return { secretKey: i, publicKey: e(i) };
2741
+ };
2742
+ }
2743
+ class zn {
2744
+ oHash;
2745
+ iHash;
2746
+ blockLen;
2747
+ outputLen;
2748
+ finished = !1;
2749
+ destroyed = !1;
2750
+ constructor(e, r) {
2751
+ if (tt(e), G(r, void 0, "key"), this.iHash = e.create(), typeof this.iHash.update != "function")
2752
+ throw new Error("Expected instance of class which extends utils.Hash");
2753
+ this.blockLen = this.iHash.blockLen, this.outputLen = this.iHash.outputLen;
2754
+ const n = this.blockLen, i = new Uint8Array(n);
2755
+ i.set(r.length > n ? e.create().update(r).digest() : r);
2756
+ for (let s = 0; s < i.length; s++)
2757
+ i[s] ^= 54;
2758
+ this.iHash.update(i), this.oHash = e.create();
2759
+ for (let s = 0; s < i.length; s++)
2760
+ i[s] ^= 106;
2761
+ this.oHash.update(i), Ne(i);
2762
+ }
2763
+ update(e) {
2764
+ return ze(this), this.iHash.update(e), this;
2765
+ }
2766
+ digestInto(e) {
2767
+ ze(this), G(e, this.outputLen, "output"), this.finished = !0, this.iHash.digestInto(e), this.oHash.update(e), this.oHash.digestInto(e), this.destroy();
2768
+ }
2769
+ digest() {
2770
+ const e = new Uint8Array(this.oHash.outputLen);
2771
+ return this.digestInto(e), e;
2772
+ }
2773
+ _cloneInto(e) {
2774
+ e ||= Object.create(Object.getPrototypeOf(this), {});
2775
+ const { oHash: r, iHash: n, finished: i, destroyed: s, blockLen: o, outputLen: a } = this;
2776
+ return e = e, e.finished = i, e.destroyed = s, e.blockLen = o, e.outputLen = a, e.oHash = r._cloneInto(e.oHash), e.iHash = n._cloneInto(e.iHash), e;
2777
+ }
2778
+ clone() {
2779
+ return this._cloneInto();
2780
+ }
2781
+ destroy() {
2782
+ this.destroyed = !0, this.oHash.destroy(), this.iHash.destroy();
2783
+ }
2784
+ }
2785
+ const qe = (t, e, r) => new zn(t, e).update(r).digest();
2786
+ qe.create = (t, e) => new zn(t, e);
2787
+ const an = (t, e) => (t + (t >= 0 ? e : -e) / Wn) / e;
2788
+ function yi(t, e, r) {
2789
+ const [[n, i], [s, o]] = e, a = an(o * t, r), u = an(-i * t, r);
2790
+ let w = t - a * n - u * s, T = -a * i - u * o;
2791
+ const R = w < pe, _ = T < pe;
2792
+ R && (w = -w), _ && (T = -T);
2793
+ const k = It(Math.ceil(ni(r) / 2)) + _e;
2794
+ if (w < pe || w >= k || T < pe || T >= k)
2795
+ throw new Error("splitScalar (endomorphism): failed, k=" + t);
2796
+ return { k1neg: R, k1: w, k2neg: _, k2: T };
2797
+ }
2798
+ function kt(t) {
2799
+ if (!["compact", "recovered", "der"].includes(t))
2800
+ throw new Error('Signature format must be "compact", "recovered", or "der"');
2801
+ return t;
2802
+ }
2803
+ function dt(t, e) {
2804
+ const r = {};
2805
+ for (let n of Object.keys(e))
2806
+ r[n] = t[n] === void 0 ? e[n] : t[n];
2807
+ return Je(r.lowS, "lowS"), Je(r.prehash, "prehash"), r.format !== void 0 && kt(r.format), r;
2808
+ }
2809
+ class wi extends Error {
2810
+ constructor(e = "") {
2811
+ super(e);
2812
+ }
2813
+ }
2814
+ const we = {
2815
+ // asn.1 DER encoding utils
2816
+ Err: wi,
2817
+ // Basic building block is TLV (Tag-Length-Value)
2818
+ _tlv: {
2819
+ encode: (t, e) => {
2820
+ const { Err: r } = we;
2821
+ if (t < 0 || t > 256)
2822
+ throw new r("tlv.encode: wrong tag");
2823
+ if (e.length & 1)
2824
+ throw new r("tlv.encode: unpadded data");
2825
+ const n = e.length / 2, i = He(n);
2826
+ if (i.length / 2 & 128)
2827
+ throw new r("tlv.encode: long form length too big");
2828
+ const s = n > 127 ? He(i.length / 2 | 128) : "";
2829
+ return He(t) + s + i + e;
2830
+ },
2831
+ // v - value, l - left bytes (unparsed)
2832
+ decode(t, e) {
2833
+ const { Err: r } = we;
2834
+ let n = 0;
2835
+ if (t < 0 || t > 256)
2836
+ throw new r("tlv.encode: wrong tag");
2837
+ if (e.length < 2 || e[n++] !== t)
2838
+ throw new r("tlv.decode: wrong tlv");
2839
+ const i = e[n++], s = !!(i & 128);
2840
+ let o = 0;
2841
+ if (!s)
2842
+ o = i;
2843
+ else {
2844
+ const u = i & 127;
2845
+ if (!u)
2846
+ throw new r("tlv.decode(long): indefinite length not supported");
2847
+ if (u > 4)
2848
+ throw new r("tlv.decode(long): byte length is too big");
2849
+ const w = e.subarray(n, n + u);
2850
+ if (w.length !== u)
2851
+ throw new r("tlv.decode: length bytes not complete");
2852
+ if (w[0] === 0)
2853
+ throw new r("tlv.decode(long): zero leftmost byte");
2854
+ for (const T of w)
2855
+ o = o << 8 | T;
2856
+ if (n += u, o < 128)
2857
+ throw new r("tlv.decode(long): not minimal encoding");
2858
+ }
2859
+ const a = e.subarray(n, n + o);
2860
+ if (a.length !== o)
2861
+ throw new r("tlv.decode: wrong value length");
2862
+ return { v: a, l: e.subarray(n + o) };
2863
+ }
2864
+ },
2865
+ // https://crypto.stackexchange.com/a/57734 Leftmost bit of first byte is 'negative' flag,
2866
+ // since we always use positive integers here. It must always be empty:
2867
+ // - add zero byte if exists
2868
+ // - if next byte doesn't have a flag, leading zero is not allowed (minimal encoding)
2869
+ _int: {
2870
+ encode(t) {
2871
+ const { Err: e } = we;
2872
+ if (t < pe)
2873
+ throw new e("integer: negative integers are not allowed");
2874
+ let r = He(t);
2875
+ if (Number.parseInt(r[0], 16) & 8 && (r = "00" + r), r.length & 1)
2876
+ throw new e("unexpected DER parsing assertion: unpadded hex");
2877
+ return r;
2878
+ },
2879
+ decode(t) {
2880
+ const { Err: e } = we;
2881
+ if (t[0] & 128)
2882
+ throw new e("invalid signature integer: negative");
2883
+ if (t[0] === 0 && !(t[1] & 128))
2884
+ throw new e("invalid signature integer: unnecessary leading zero");
2885
+ return De(t);
2886
+ }
2887
+ },
2888
+ toSig(t) {
2889
+ const { Err: e, _int: r, _tlv: n } = we, i = G(t, void 0, "signature"), { v: s, l: o } = n.decode(48, i);
2890
+ if (o.length)
2891
+ throw new e("invalid signature: left bytes after parsing");
2892
+ const { v: a, l: u } = n.decode(2, s), { v: w, l: T } = n.decode(2, u);
2893
+ if (T.length)
2894
+ throw new e("invalid signature: left bytes after parsing");
2895
+ return { r: r.decode(a), s: r.decode(w) };
2896
+ },
2897
+ hexFromSig(t) {
2898
+ const { _tlv: e, _int: r } = we, n = e.encode(2, r.encode(t.r)), i = e.encode(2, r.encode(t.s)), s = n + i;
2899
+ return e.encode(48, s);
2900
+ }
2901
+ }, pe = BigInt(0), _e = BigInt(1), Wn = BigInt(2), Ke = BigInt(3), vi = BigInt(4);
2902
+ function mi(t, e = {}) {
2903
+ const r = bi("weierstrass", t, e), { Fp: n, Fn: i } = r;
2904
+ let s = r.CURVE;
2905
+ const { h: o, n: a } = s;
2906
+ Pt(e, {}, {
2907
+ allowInfinityPoint: "boolean",
2908
+ clearCofactor: "function",
2909
+ isTorsionFree: "function",
2910
+ fromBytes: "function",
2911
+ toBytes: "function",
2912
+ endo: "object"
2913
+ });
2914
+ const { endo: u } = e;
2915
+ if (u && (!n.is0(s.a) || typeof u.beta != "bigint" || !Array.isArray(u.basises)))
2916
+ throw new Error('invalid endo: expected "beta": bigint and "basises": array');
2917
+ const w = Jn(n, i);
2918
+ function T() {
2919
+ if (!n.isOdd)
2920
+ throw new Error("compression is not supported: Field does not have .isOdd()");
2921
+ }
2922
+ function R(c, d, f) {
2923
+ const { x: l, y: v } = d.toAffine(), A = n.toBytes(l);
2924
+ if (Je(f, "isCompressed"), f) {
2925
+ T();
2926
+ const C = !n.isOdd(v);
2927
+ return oe(Yn(C), A);
2928
+ } else
2929
+ return oe(Uint8Array.of(4), A, n.toBytes(v));
2930
+ }
2931
+ function _(c) {
2932
+ G(c, void 0, "Point");
2933
+ const { publicKey: d, publicKeyUncompressed: f } = w, l = c.length, v = c[0], A = c.subarray(1);
2934
+ if (l === d && (v === 2 || v === 3)) {
2935
+ const C = n.fromBytes(A);
2936
+ if (!n.isValid(C))
2937
+ throw new Error("bad point: is not on curve, wrong x");
2938
+ const I = q(C);
2939
+ let O;
2940
+ try {
2941
+ O = n.sqrt(I);
2942
+ } catch (j) {
2943
+ const Y = j instanceof Error ? ": " + j.message : "";
2944
+ throw new Error("bad point: is not on curve, sqrt error" + Y);
2945
+ }
2946
+ T();
2947
+ const $ = n.isOdd(O);
2948
+ return (v & 1) === 1 !== $ && (O = n.neg(O)), { x: C, y: O };
2949
+ } else if (l === f && v === 4) {
2950
+ const C = n.BYTES, I = n.fromBytes(A.subarray(0, C)), O = n.fromBytes(A.subarray(C, C * 2));
2951
+ if (!U(I, O))
2952
+ throw new Error("bad point: is not on curve");
2953
+ return { x: I, y: O };
2954
+ } else
2955
+ throw new Error(`bad point: got length ${l}, expected compressed=${d} or uncompressed=${f}`);
2956
+ }
2957
+ const k = e.toBytes || R, P = e.fromBytes || _;
2958
+ function q(c) {
2959
+ const d = n.sqr(c), f = n.mul(d, c);
2960
+ return n.add(n.add(f, n.mul(c, s.a)), s.b);
2961
+ }
2962
+ function U(c, d) {
2963
+ const f = n.sqr(d), l = q(c);
2964
+ return n.eql(f, l);
2965
+ }
2966
+ if (!U(s.Gx, s.Gy))
2967
+ throw new Error("bad curve params: generator point");
2968
+ const H = n.mul(n.pow(s.a, Ke), vi), W = n.mul(n.sqr(s.b), BigInt(27));
2969
+ if (n.is0(n.add(H, W)))
2970
+ throw new Error("bad curve params: a or b");
2971
+ function ne(c, d, f = !1) {
2972
+ if (!n.isValid(d) || f && n.is0(d))
2973
+ throw new Error(`bad point coordinate ${c}`);
2974
+ return d;
2975
+ }
2976
+ function Q(c) {
2977
+ if (!(c instanceof g))
2978
+ throw new Error("Weierstrass Point expected");
2979
+ }
2980
+ function M(c) {
2981
+ if (!u || !u.basises)
2982
+ throw new Error("no endo");
2983
+ return yi(c, u.basises, i.ORDER);
2984
+ }
2985
+ const L = Qt((c, d) => {
2986
+ const { X: f, Y: l, Z: v } = c;
2987
+ if (n.eql(v, n.ONE))
2988
+ return { x: f, y: l };
2989
+ const A = c.is0();
2990
+ d == null && (d = A ? n.ONE : n.inv(v));
2991
+ const C = n.mul(f, d), I = n.mul(l, d), O = n.mul(v, d);
2992
+ if (A)
2993
+ return { x: n.ZERO, y: n.ZERO };
2994
+ if (!n.eql(O, n.ONE))
2995
+ throw new Error("invZ was invalid");
2996
+ return { x: C, y: I };
2997
+ }), x = Qt((c) => {
2998
+ if (c.is0()) {
2999
+ if (e.allowInfinityPoint && !n.is0(c.Y))
3000
+ return;
3001
+ throw new Error("bad point: ZERO");
3002
+ }
3003
+ const { x: d, y: f } = c.toAffine();
3004
+ if (!n.isValid(d) || !n.isValid(f))
3005
+ throw new Error("bad point: x or y not field elements");
3006
+ if (!U(d, f))
3007
+ throw new Error("bad point: equation left != right");
3008
+ if (!c.isTorsionFree())
3009
+ throw new Error("bad point: not in prime-order subgroup");
3010
+ return !0;
3011
+ });
3012
+ function B(c, d, f, l, v) {
3013
+ return f = new g(n.mul(f.X, c), f.Y, f.Z), d = Ge(l, d), f = Ge(v, f), d.add(f);
3014
+ }
3015
+ class g {
3016
+ // base / generator point
3017
+ static BASE = new g(s.Gx, s.Gy, n.ONE);
3018
+ // zero / infinity / identity point
3019
+ static ZERO = new g(n.ZERO, n.ONE, n.ZERO);
3020
+ // 0, 1, 0
3021
+ // math field
3022
+ static Fp = n;
3023
+ // scalar field
3024
+ static Fn = i;
3025
+ X;
3026
+ Y;
3027
+ Z;
3028
+ /** Does NOT validate if the point is valid. Use `.assertValidity()`. */
3029
+ constructor(d, f, l) {
3030
+ this.X = ne("x", d), this.Y = ne("y", f, !0), this.Z = ne("z", l), Object.freeze(this);
3031
+ }
3032
+ static CURVE() {
3033
+ return s;
3034
+ }
3035
+ /** Does NOT validate if the point is valid. Use `.assertValidity()`. */
3036
+ static fromAffine(d) {
3037
+ const { x: f, y: l } = d || {};
3038
+ if (!d || !n.isValid(f) || !n.isValid(l))
3039
+ throw new Error("invalid affine point");
3040
+ if (d instanceof g)
3041
+ throw new Error("projective point not allowed");
3042
+ return n.is0(f) && n.is0(l) ? g.ZERO : new g(f, l, n.ONE);
3043
+ }
3044
+ static fromBytes(d) {
3045
+ const f = g.fromAffine(P(G(d, void 0, "point")));
3046
+ return f.assertValidity(), f;
3047
+ }
3048
+ static fromHex(d) {
3049
+ return g.fromBytes(ie(d));
3050
+ }
3051
+ get x() {
3052
+ return this.toAffine().x;
3053
+ }
3054
+ get y() {
3055
+ return this.toAffine().y;
3056
+ }
3057
+ /**
3058
+ *
3059
+ * @param windowSize
3060
+ * @param isLazy true will defer table computation until the first multiplication
3061
+ * @returns
3062
+ */
3063
+ precompute(d = 8, f = !0) {
3064
+ return h.createCache(this, d), f || this.multiply(Ke), this;
3065
+ }
3066
+ // TODO: return `this`
3067
+ /** A point on curve is valid if it conforms to equation. */
3068
+ assertValidity() {
3069
+ x(this);
3070
+ }
3071
+ hasEvenY() {
3072
+ const { y: d } = this.toAffine();
3073
+ if (!n.isOdd)
3074
+ throw new Error("Field doesn't support isOdd");
3075
+ return !n.isOdd(d);
3076
+ }
3077
+ /** Compare one point to another. */
3078
+ equals(d) {
3079
+ Q(d);
3080
+ const { X: f, Y: l, Z: v } = this, { X: A, Y: C, Z: I } = d, O = n.eql(n.mul(f, I), n.mul(A, v)), $ = n.eql(n.mul(l, I), n.mul(C, v));
3081
+ return O && $;
3082
+ }
3083
+ /** Flips point to one corresponding to (x, -y) in Affine coordinates. */
3084
+ negate() {
3085
+ return new g(this.X, n.neg(this.Y), this.Z);
3086
+ }
3087
+ // Renes-Costello-Batina exception-free doubling formula.
3088
+ // There is 30% faster Jacobian formula, but it is not complete.
3089
+ // https://eprint.iacr.org/2015/1060, algorithm 3
3090
+ // Cost: 8M + 3S + 3*a + 2*b3 + 15add.
3091
+ double() {
3092
+ const { a: d, b: f } = s, l = n.mul(f, Ke), { X: v, Y: A, Z: C } = this;
3093
+ let I = n.ZERO, O = n.ZERO, $ = n.ZERO, D = n.mul(v, v), j = n.mul(A, A), Y = n.mul(C, C), Z = n.mul(v, A);
3094
+ return Z = n.add(Z, Z), $ = n.mul(v, C), $ = n.add($, $), I = n.mul(d, $), O = n.mul(l, Y), O = n.add(I, O), I = n.sub(j, O), O = n.add(j, O), O = n.mul(I, O), I = n.mul(Z, I), $ = n.mul(l, $), Y = n.mul(d, Y), Z = n.sub(D, Y), Z = n.mul(d, Z), Z = n.add(Z, $), $ = n.add(D, D), D = n.add($, D), D = n.add(D, Y), D = n.mul(D, Z), O = n.add(O, D), Y = n.mul(A, C), Y = n.add(Y, Y), D = n.mul(Y, Z), I = n.sub(I, D), $ = n.mul(Y, j), $ = n.add($, $), $ = n.add($, $), new g(I, O, $);
3095
+ }
3096
+ // Renes-Costello-Batina exception-free addition formula.
3097
+ // There is 30% faster Jacobian formula, but it is not complete.
3098
+ // https://eprint.iacr.org/2015/1060, algorithm 1
3099
+ // Cost: 12M + 0S + 3*a + 3*b3 + 23add.
3100
+ add(d) {
3101
+ Q(d);
3102
+ const { X: f, Y: l, Z: v } = this, { X: A, Y: C, Z: I } = d;
3103
+ let O = n.ZERO, $ = n.ZERO, D = n.ZERO;
3104
+ const j = s.a, Y = n.mul(s.b, Ke);
3105
+ let Z = n.mul(f, A), J = n.mul(l, C), ee = n.mul(v, I), y = n.add(f, l), b = n.add(A, C);
3106
+ y = n.mul(y, b), b = n.add(Z, J), y = n.sub(y, b), b = n.add(f, v);
3107
+ let p = n.add(A, I);
3108
+ return b = n.mul(b, p), p = n.add(Z, ee), b = n.sub(b, p), p = n.add(l, v), O = n.add(C, I), p = n.mul(p, O), O = n.add(J, ee), p = n.sub(p, O), D = n.mul(j, b), O = n.mul(Y, ee), D = n.add(O, D), O = n.sub(J, D), D = n.add(J, D), $ = n.mul(O, D), J = n.add(Z, Z), J = n.add(J, Z), ee = n.mul(j, ee), b = n.mul(Y, b), J = n.add(J, ee), ee = n.sub(Z, ee), ee = n.mul(j, ee), b = n.add(b, ee), Z = n.mul(J, b), $ = n.add($, Z), Z = n.mul(p, b), O = n.mul(y, O), O = n.sub(O, Z), Z = n.mul(y, J), D = n.mul(p, D), D = n.add(D, Z), new g(O, $, D);
3109
+ }
3110
+ subtract(d) {
3111
+ return this.add(d.negate());
3112
+ }
3113
+ is0() {
3114
+ return this.equals(g.ZERO);
3115
+ }
3116
+ /**
3117
+ * Constant time multiplication.
3118
+ * Uses wNAF method. Windowed method may be 10% faster,
3119
+ * but takes 2x longer to generate and consumes 2x memory.
3120
+ * Uses precomputes when available.
3121
+ * Uses endomorphism for Koblitz curves.
3122
+ * @param scalar by which the point would be multiplied
3123
+ * @returns New point
3124
+ */
3125
+ multiply(d) {
3126
+ const { endo: f } = e;
3127
+ if (!i.isValidNot0(d))
3128
+ throw new Error("invalid scalar: out of range");
3129
+ let l, v;
3130
+ const A = (C) => h.cached(this, C, (I) => nn(g, I));
3131
+ if (f) {
3132
+ const { k1neg: C, k1: I, k2neg: O, k2: $ } = M(d), { p: D, f: j } = A(I), { p: Y, f: Z } = A($);
3133
+ v = j.add(Z), l = B(f.beta, D, Y, C, O);
3134
+ } else {
3135
+ const { p: C, f: I } = A(d);
3136
+ l = C, v = I;
3137
+ }
3138
+ return nn(g, [l, v])[0];
3139
+ }
3140
+ /**
3141
+ * Non-constant-time multiplication. Uses double-and-add algorithm.
3142
+ * It's faster, but should only be used when you don't care about
3143
+ * an exposed secret key e.g. sig verification, which works over *public* keys.
3144
+ */
3145
+ multiplyUnsafe(d) {
3146
+ const { endo: f } = e, l = this;
3147
+ if (!i.isValid(d))
3148
+ throw new Error("invalid scalar: out of range");
3149
+ if (d === pe || l.is0())
3150
+ return g.ZERO;
3151
+ if (d === _e)
3152
+ return l;
3153
+ if (h.hasCache(this))
3154
+ return this.multiply(d);
3155
+ if (f) {
3156
+ const { k1neg: v, k1: A, k2neg: C, k2: I } = M(d), { p1: O, p2: $ } = pi(g, l, A, I);
3157
+ return B(f.beta, O, $, v, C);
3158
+ } else
3159
+ return h.unsafe(l, d);
3160
+ }
3161
+ /**
3162
+ * Converts Projective point to affine (x, y) coordinates.
3163
+ * @param invertedZ Z^-1 (inverted zero) - optional, precomputation is useful for invertBatch
3164
+ */
3165
+ toAffine(d) {
3166
+ return L(this, d);
3167
+ }
3168
+ /**
3169
+ * Checks whether Point is free of torsion elements (is in prime subgroup).
3170
+ * Always torsion-free for cofactor=1 curves.
3171
+ */
3172
+ isTorsionFree() {
3173
+ const { isTorsionFree: d } = e;
3174
+ return o === _e ? !0 : d ? d(g, this) : h.unsafe(this, a).is0();
3175
+ }
3176
+ clearCofactor() {
3177
+ const { clearCofactor: d } = e;
3178
+ return o === _e ? this : d ? d(g, this) : this.multiplyUnsafe(o);
3179
+ }
3180
+ isSmallOrder() {
3181
+ return this.multiplyUnsafe(o).is0();
3182
+ }
3183
+ toBytes(d = !0) {
3184
+ return Je(d, "isCompressed"), this.assertValidity(), k(g, this, d);
3185
+ }
3186
+ toHex(d = !0) {
3187
+ return le(this.toBytes(d));
3188
+ }
3189
+ toString() {
3190
+ return `<Point ${this.is0() ? "ZERO" : this.toHex()}>`;
3191
+ }
3192
+ }
3193
+ const E = i.BITS, h = new gi(g, e.endo ? Math.ceil(E / 2) : E);
3194
+ return g.BASE.precompute(8), g;
3195
+ }
3196
+ function Yn(t) {
3197
+ return Uint8Array.of(t ? 2 : 3);
3198
+ }
3199
+ function Jn(t, e) {
3200
+ return {
3201
+ secretKey: e.BYTES,
3202
+ publicKey: 1 + t.BYTES,
3203
+ publicKeyUncompressed: 1 + 2 * t.BYTES,
3204
+ publicKeyHasPrefix: !0,
3205
+ signature: 2 * e.BYTES
3206
+ };
3207
+ }
3208
+ function xi(t, e = {}) {
3209
+ const { Fn: r } = t, n = e.randomBytes || $e, i = Object.assign(Jn(t.Fp, r), { seed: Kn(r.ORDER) });
3210
+ function s(k) {
3211
+ try {
3212
+ const P = r.fromBytes(k);
3213
+ return r.isValidNot0(P);
3214
+ } catch {
3215
+ return !1;
3216
+ }
3217
+ }
3218
+ function o(k, P) {
3219
+ const { publicKey: q, publicKeyUncompressed: U } = i;
3220
+ try {
3221
+ const H = k.length;
3222
+ return P === !0 && H !== q || P === !1 && H !== U ? !1 : !!t.fromBytes(k);
3223
+ } catch {
3224
+ return !1;
3225
+ }
3226
+ }
3227
+ function a(k = n(i.seed)) {
3228
+ return Fn(G(k, i.seed, "seed"), r.ORDER);
3229
+ }
3230
+ function u(k, P = !0) {
3231
+ return t.BASE.multiply(r.fromBytes(k)).toBytes(P);
3232
+ }
3233
+ function w(k) {
3234
+ const { secretKey: P, publicKey: q, publicKeyUncompressed: U } = i;
3235
+ if (!_t(k) || "_lengths" in r && r._lengths || P === q)
3236
+ return;
3237
+ const H = G(k, void 0, "key").length;
3238
+ return H === q || H === U;
3239
+ }
3240
+ function T(k, P, q = !0) {
3241
+ if (w(k) === !0)
3242
+ throw new Error("first arg must be private key");
3243
+ if (w(P) === !1)
3244
+ throw new Error("second arg must be public key");
3245
+ const U = r.fromBytes(k);
3246
+ return t.fromBytes(P).multiply(U).toBytes(q);
3247
+ }
3248
+ const R = {
3249
+ isValidSecretKey: s,
3250
+ isValidPublicKey: o,
3251
+ randomSecretKey: a
3252
+ }, _ = jn(a, u);
3253
+ return Object.freeze({ getPublicKey: u, getSharedSecret: T, keygen: _, Point: t, utils: R, lengths: i });
3254
+ }
3255
+ function Ei(t, e, r = {}) {
3256
+ tt(e), Pt(r, {}, {
3257
+ hmac: "function",
3258
+ lowS: "boolean",
3259
+ randomBytes: "function",
3260
+ bits2int: "function",
3261
+ bits2int_modN: "function"
3262
+ }), r = Object.assign({}, r);
3263
+ const n = r.randomBytes || $e, i = r.hmac || ((f, l) => qe(e, f, l)), { Fp: s, Fn: o } = t, { ORDER: a, BITS: u } = o, { keygen: w, getPublicKey: T, getSharedSecret: R, utils: _, lengths: k } = xi(t, r), P = {
3264
+ prehash: !0,
3265
+ lowS: typeof r.lowS == "boolean" ? r.lowS : !0,
3266
+ format: "compact",
3267
+ extraEntropy: !1
3268
+ }, q = a * Wn < s.ORDER;
3269
+ function U(f) {
3270
+ const l = a >> _e;
3271
+ return f > l;
3272
+ }
3273
+ function H(f, l) {
3274
+ if (!o.isValidNot0(l))
3275
+ throw new Error(`invalid signature ${f}: out of range 1..Point.Fn.ORDER`);
3276
+ return l;
3277
+ }
3278
+ function W() {
3279
+ if (q)
3280
+ throw new Error('"recovered" sig type is not supported for cofactor >2 curves');
3281
+ }
3282
+ function ne(f, l) {
3283
+ kt(l);
3284
+ const v = k.signature, A = l === "compact" ? v : l === "recovered" ? v + 1 : void 0;
3285
+ return G(f, A);
3286
+ }
3287
+ class Q {
3288
+ r;
3289
+ s;
3290
+ recovery;
3291
+ constructor(l, v, A) {
3292
+ if (this.r = H("r", l), this.s = H("s", v), A != null) {
3293
+ if (W(), ![0, 1, 2, 3].includes(A))
3294
+ throw new Error("invalid recovery id");
3295
+ this.recovery = A;
3296
+ }
3297
+ Object.freeze(this);
3298
+ }
3299
+ static fromBytes(l, v = P.format) {
3300
+ ne(l, v);
3301
+ let A;
3302
+ if (v === "der") {
3303
+ const { r: $, s: D } = we.toSig(G(l));
3304
+ return new Q($, D);
3305
+ }
3306
+ v === "recovered" && (A = l[0], v = "compact", l = l.subarray(1));
3307
+ const C = k.signature / 2, I = l.subarray(0, C), O = l.subarray(C, C * 2);
3308
+ return new Q(o.fromBytes(I), o.fromBytes(O), A);
3309
+ }
3310
+ static fromHex(l, v) {
3311
+ return this.fromBytes(ie(l), v);
3312
+ }
3313
+ assertRecovery() {
3314
+ const { recovery: l } = this;
3315
+ if (l == null)
3316
+ throw new Error("invalid recovery id: must be present");
3317
+ return l;
3318
+ }
3319
+ addRecoveryBit(l) {
3320
+ return new Q(this.r, this.s, l);
3321
+ }
3322
+ recoverPublicKey(l) {
3323
+ const { r: v, s: A } = this, C = this.assertRecovery(), I = C === 2 || C === 3 ? v + a : v;
3324
+ if (!s.isValid(I))
3325
+ throw new Error("invalid recovery id: sig.r+curve.n != R.x");
3326
+ const O = s.toBytes(I), $ = t.fromBytes(oe(Yn((C & 1) === 0), O)), D = o.inv(I), j = L(G(l, void 0, "msgHash")), Y = o.create(-j * D), Z = o.create(A * D), J = t.BASE.multiplyUnsafe(Y).add($.multiplyUnsafe(Z));
3327
+ if (J.is0())
3328
+ throw new Error("invalid recovery: point at infinify");
3329
+ return J.assertValidity(), J;
3330
+ }
3331
+ // Signatures should be low-s, to prevent malleability.
3332
+ hasHighS() {
3333
+ return U(this.s);
3334
+ }
3335
+ toBytes(l = P.format) {
3336
+ if (kt(l), l === "der")
3337
+ return ie(we.hexFromSig(this));
3338
+ const { r: v, s: A } = this, C = o.toBytes(v), I = o.toBytes(A);
3339
+ return l === "recovered" ? (W(), oe(Uint8Array.of(this.assertRecovery()), C, I)) : oe(C, I);
3340
+ }
3341
+ toHex(l) {
3342
+ return le(this.toBytes(l));
3343
+ }
3344
+ }
3345
+ const M = r.bits2int || function(l) {
3346
+ if (l.length > 8192)
3347
+ throw new Error("input is too large");
3348
+ const v = De(l), A = l.length * 8 - u;
3349
+ return A > 0 ? v >> BigInt(A) : v;
3350
+ }, L = r.bits2int_modN || function(l) {
3351
+ return o.create(M(l));
3352
+ }, x = It(u);
3353
+ function B(f) {
3354
+ return ti("num < 2^" + u, f, pe, x), o.toBytes(f);
3355
+ }
3356
+ function g(f, l) {
3357
+ return G(f, void 0, "message"), l ? G(e(f), void 0, "prehashed message") : f;
3358
+ }
3359
+ function E(f, l, v) {
3360
+ const { lowS: A, prehash: C, extraEntropy: I } = dt(v, P);
3361
+ f = g(f, C);
3362
+ const O = L(f), $ = o.fromBytes(l);
3363
+ if (!o.isValidNot0($))
3364
+ throw new Error("invalid private key");
3365
+ const D = [B($), B(O)];
3366
+ if (I != null && I !== !1) {
3367
+ const J = I === !0 ? n(k.secretKey) : I;
3368
+ D.push(G(J, void 0, "extraEntropy"));
3369
+ }
3370
+ const j = oe(...D), Y = O;
3371
+ function Z(J) {
3372
+ const ee = M(J);
3373
+ if (!o.isValidNot0(ee))
3374
+ return;
3375
+ const y = o.inv(ee), b = t.BASE.multiply(ee).toAffine(), p = o.create(b.x);
3376
+ if (p === pe)
3377
+ return;
3378
+ const m = o.create(y * o.create(Y + p * $));
3379
+ if (m === pe)
3380
+ return;
3381
+ let S = (b.x === p ? 0 : 2) | Number(b.y & _e), N = m;
3382
+ return A && U(m) && (N = o.neg(m), S ^= 1), new Q(p, N, q ? void 0 : S);
3383
+ }
3384
+ return { seed: j, k2sig: Z };
3385
+ }
3386
+ function h(f, l, v = {}) {
3387
+ const { seed: A, k2sig: C } = E(f, l, v);
3388
+ return ri(e.outputLen, o.BYTES, i)(A, C).toBytes(v.format);
3389
+ }
3390
+ function c(f, l, v, A = {}) {
3391
+ const { lowS: C, prehash: I, format: O } = dt(A, P);
3392
+ if (v = G(v, void 0, "publicKey"), l = g(l, I), !_t(f)) {
3393
+ const $ = f instanceof Q ? ", use sig.toBytes()" : "";
3394
+ throw new Error("verify expects Uint8Array signature" + $);
3395
+ }
3396
+ ne(f, O);
3397
+ try {
3398
+ const $ = Q.fromBytes(f, O), D = t.fromBytes(v);
3399
+ if (C && $.hasHighS())
3400
+ return !1;
3401
+ const { r: j, s: Y } = $, Z = L(l), J = o.inv(Y), ee = o.create(Z * J), y = o.create(j * J), b = t.BASE.multiplyUnsafe(ee).add(D.multiplyUnsafe(y));
3402
+ return b.is0() ? !1 : o.create(b.x) === j;
3403
+ } catch {
3404
+ return !1;
3405
+ }
3406
+ }
3407
+ function d(f, l, v = {}) {
3408
+ const { prehash: A } = dt(v, P);
3409
+ return l = g(l, A), Q.fromBytes(f, "recovered").recoverPublicKey(l).toBytes();
3410
+ }
3411
+ return Object.freeze({
3412
+ keygen: w,
3413
+ getPublicKey: T,
3414
+ getSharedSecret: R,
3415
+ utils: _,
3416
+ lengths: k,
3417
+ Point: t,
3418
+ sign: h,
3419
+ verify: c,
3420
+ recoverPublicKey: d,
3421
+ Signature: Q,
3422
+ hash: e
3423
+ });
3424
+ }
3425
+ const rt = {
3426
+ p: BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),
3427
+ n: BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),
3428
+ h: BigInt(1),
3429
+ a: BigInt(0),
3430
+ b: BigInt(7),
3431
+ Gx: BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),
3432
+ Gy: BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")
3433
+ }, ki = {
3434
+ beta: BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),
3435
+ basises: [
3436
+ [BigInt("0x3086d221a7d46bcde86c90e49284eb15"), -BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],
3437
+ [BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"), BigInt("0x3086d221a7d46bcde86c90e49284eb15")]
3438
+ ]
3439
+ }, Ai = /* @__PURE__ */ BigInt(0), At = /* @__PURE__ */ BigInt(2);
3440
+ function Si(t) {
3441
+ const e = rt.p, r = BigInt(3), n = BigInt(6), i = BigInt(11), s = BigInt(22), o = BigInt(23), a = BigInt(44), u = BigInt(88), w = t * t * t % e, T = w * w * t % e, R = ue(T, r, e) * T % e, _ = ue(R, r, e) * T % e, k = ue(_, At, e) * w % e, P = ue(k, i, e) * k % e, q = ue(P, s, e) * P % e, U = ue(q, a, e) * q % e, H = ue(U, u, e) * U % e, W = ue(H, a, e) * q % e, ne = ue(W, r, e) * T % e, Q = ue(ne, o, e) * P % e, M = ue(Q, n, e) * w % e, L = ue(M, At, e);
3442
+ if (!Xe.eql(Xe.sqr(L), t))
3443
+ throw new Error("Cannot find square root");
3444
+ return L;
3445
+ }
3446
+ const Xe = nt(rt.p, { sqrt: Si }), Be = /* @__PURE__ */ mi(rt, {
3447
+ Fp: Xe,
3448
+ endo: ki
3449
+ }), Bi = /* @__PURE__ */ Ei(Be, xe), cn = {};
3450
+ function Qe(t, ...e) {
3451
+ let r = cn[t];
3452
+ if (r === void 0) {
3453
+ const n = xe(Qr(t));
3454
+ r = oe(n, n), cn[t] = r;
3455
+ }
3456
+ return xe(oe(r, ...e));
3457
+ }
3458
+ const Nt = (t) => t.toBytes(!0).slice(1), $t = (t) => t % At === Ai;
3459
+ function St(t) {
3460
+ const { Fn: e, BASE: r } = Be, n = e.fromBytes(t), i = r.multiply(n);
3461
+ return { scalar: $t(i.y) ? n : e.neg(n), bytes: Nt(i) };
3462
+ }
3463
+ function Gn(t) {
3464
+ const e = Xe;
3465
+ if (!e.isValidNot0(t))
3466
+ throw new Error("invalid x: Fail if x ≥ p");
3467
+ const r = e.create(t * t), n = e.create(r * t + BigInt(7));
3468
+ let i = e.sqrt(n);
3469
+ $t(i) || (i = e.neg(i));
3470
+ const s = Be.fromAffine({ x: t, y: i });
3471
+ return s.assertValidity(), s;
3472
+ }
3473
+ const Me = De;
3474
+ function Xn(...t) {
3475
+ return Be.Fn.create(Me(Qe("BIP0340/challenge", ...t)));
3476
+ }
3477
+ function un(t) {
3478
+ return St(t).bytes;
3479
+ }
3480
+ function Ri(t, e, r = $e(32)) {
3481
+ const { Fn: n } = Be, i = G(t, void 0, "message"), { bytes: s, scalar: o } = St(e), a = G(r, 32, "auxRand"), u = n.toBytes(o ^ Me(Qe("BIP0340/aux", a))), w = Qe("BIP0340/nonce", u, s, i), { bytes: T, scalar: R } = St(w), _ = Xn(T, s, i), k = new Uint8Array(64);
3482
+ if (k.set(T, 0), k.set(n.toBytes(n.create(R + _ * o)), 32), !Qn(k, i, s))
3483
+ throw new Error("sign: Invalid signature produced");
3484
+ return k;
3485
+ }
3486
+ function Qn(t, e, r) {
3487
+ const { Fp: n, Fn: i, BASE: s } = Be, o = G(t, 64, "signature"), a = G(e, void 0, "message"), u = G(r, 32, "publicKey");
3488
+ try {
3489
+ const w = Gn(Me(u)), T = Me(o.subarray(0, 32));
3490
+ if (!n.isValidNot0(T))
3491
+ return !1;
3492
+ const R = Me(o.subarray(32, 64));
3493
+ if (!i.isValidNot0(R))
3494
+ return !1;
3495
+ const _ = Xn(i.toBytes(T), Nt(w), a), k = s.multiplyUnsafe(R).add(w.multiplyUnsafe(i.neg(_))), { x: P, y: q } = k.toAffine();
3496
+ return !(k.is0() || !$t(q) || P !== T);
3497
+ } catch {
3498
+ return !1;
3499
+ }
3500
+ }
3501
+ const he = /* @__PURE__ */ (() => {
3502
+ const r = (n = $e(48)) => Fn(n, rt.n);
3503
+ return {
3504
+ keygen: jn(r, un),
3505
+ getPublicKey: un,
3506
+ sign: Ri,
3507
+ verify: Qn,
3508
+ Point: Be,
3509
+ utils: {
3510
+ randomSecretKey: r,
3511
+ taggedHash: Qe,
3512
+ lift_x: Gn,
3513
+ pointToBytes: Nt
3514
+ },
3515
+ lengths: {
3516
+ secretKey: 32,
3517
+ publicKey: 32,
3518
+ publicKeyHasPrefix: !1,
3519
+ signature: 64,
3520
+ seed: 48
3521
+ }
3522
+ };
3523
+ })();
3524
+ var Re = /* @__PURE__ */ Symbol("verified"), _i = (t) => t instanceof Object;
3525
+ function Ti(t) {
3526
+ if (!_i(t) || typeof t.kind != "number" || typeof t.content != "string" || typeof t.created_at != "number" || typeof t.pubkey != "string" || !t.pubkey.match(/^[a-f0-9]{64}$/) || !Array.isArray(t.tags))
3527
+ return !1;
3528
+ for (let e = 0; e < t.tags.length; e++) {
3529
+ let r = t.tags[e];
3530
+ if (!Array.isArray(r))
3531
+ return !1;
3532
+ for (let n = 0; n < r.length; n++)
3533
+ if (typeof r[n] != "string")
3534
+ return !1;
3535
+ }
3536
+ return !0;
3537
+ }
3538
+ new TextDecoder("utf-8");
3539
+ var Ci = new TextEncoder(), Li = class {
3540
+ generateSecretKey() {
3541
+ return he.utils.randomSecretKey();
3542
+ }
3543
+ getPublicKey(e) {
3544
+ return le(he.getPublicKey(e));
3545
+ }
3546
+ finalizeEvent(e, r) {
3547
+ const n = e;
3548
+ return n.pubkey = le(he.getPublicKey(r)), n.id = ht(n), n.sig = le(he.sign(ie(ht(n)), r)), n[Re] = !0, n;
3549
+ }
3550
+ verifyEvent(e) {
3551
+ if (typeof e[Re] == "boolean")
3552
+ return e[Re];
3553
+ try {
3554
+ const r = ht(e);
3555
+ if (r !== e.id)
3556
+ return e[Re] = !1, !1;
3557
+ const n = he.verify(ie(e.sig), ie(r), ie(e.pubkey));
3558
+ return e[Re] = n, n;
3559
+ } catch {
3560
+ return e[Re] = !1, !1;
3561
+ }
3562
+ }
3563
+ };
3564
+ function Oi(t) {
3565
+ if (!Ti(t))
3566
+ throw new Error("can't serialize event with wrong or missing properties");
3567
+ return JSON.stringify([0, t.pubkey, t.created_at, t.kind, t.tags, t.content]);
3568
+ }
3569
+ function ht(t) {
3570
+ let e = xe(Ci.encode(Oi(t)));
3571
+ return le(e);
3572
+ }
3573
+ var it = new Li(), er = it.generateSecretKey, Ii = it.getPublicKey;
3574
+ it.finalizeEvent;
3575
+ it.verifyEvent;
3576
+ function Pi(t) {
3577
+ return t instanceof Uint8Array || ArrayBuffer.isView(t) && t.constructor.name === "Uint8Array";
3578
+ }
3579
+ function ln(t) {
3580
+ if (typeof t != "boolean")
3581
+ throw new Error(`boolean expected, not ${t}`);
3582
+ }
3583
+ function gt(t) {
3584
+ if (!Number.isSafeInteger(t) || t < 0)
3585
+ throw new Error("positive integer expected, got " + t);
3586
+ }
3587
+ function Le(t, e, r = "") {
3588
+ const n = Pi(t), i = t?.length, s = e !== void 0;
3589
+ if (!n || s && i !== e) {
3590
+ const o = r && `"${r}" `, a = s ? ` of length ${e}` : "", u = n ? `length=${i}` : `type=${typeof t}`;
3591
+ throw new Error(o + "expected Uint8Array" + a + ", got " + u);
3592
+ }
3593
+ return t;
3594
+ }
3595
+ function ve(t) {
3596
+ return new Uint32Array(t.buffer, t.byteOffset, Math.floor(t.byteLength / 4));
3597
+ }
3598
+ function Mi(...t) {
3599
+ for (let e = 0; e < t.length; e++)
3600
+ t[e].fill(0);
3601
+ }
3602
+ function Ni(t, e) {
3603
+ if (e == null || typeof e != "object")
3604
+ throw new Error("options must be defined");
3605
+ return Object.assign(t, e);
3606
+ }
3607
+ function $i(t, e) {
3608
+ if (t.length !== e.length)
3609
+ return !1;
3610
+ let r = 0;
3611
+ for (let n = 0; n < t.length; n++)
3612
+ r |= t[n] ^ e[n];
3613
+ return r === 0;
3614
+ }
3615
+ function fn(t) {
3616
+ return Uint8Array.from(t);
3617
+ }
3618
+ const tr = (t) => Uint8Array.from(t.split(""), (e) => e.charCodeAt(0)), Di = tr("expand 16-byte k"), qi = tr("expand 32-byte k"), Ui = ve(Di), Hi = ve(qi);
3619
+ function z(t, e) {
3620
+ return t << e | t >>> 32 - e;
3621
+ }
3622
+ function Bt(t) {
3623
+ return t.byteOffset % 4 === 0;
3624
+ }
3625
+ const Fe = 64, Ki = 16, nr = 2 ** 32 - 1, dn = Uint32Array.of();
3626
+ function Fi(t, e, r, n, i, s, o, a) {
3627
+ const u = i.length, w = new Uint8Array(Fe), T = ve(w), R = Bt(i) && Bt(s), _ = R ? ve(i) : dn, k = R ? ve(s) : dn;
3628
+ for (let P = 0; P < u; o++) {
3629
+ if (t(e, r, n, T, o, a), o >= nr)
3630
+ throw new Error("arx: counter overflow");
3631
+ const q = Math.min(Fe, u - P);
3632
+ if (R && q === Fe) {
3633
+ const U = P / 4;
3634
+ if (P % 4 !== 0)
3635
+ throw new Error("arx: invalid block position");
3636
+ for (let H = 0, W; H < Ki; H++)
3637
+ W = U + H, k[W] = _[W] ^ T[H];
3638
+ P += Fe;
3639
+ continue;
3640
+ }
3641
+ for (let U = 0, H; U < q; U++)
3642
+ H = P + U, s[H] = i[H] ^ w[U];
3643
+ P += q;
3644
+ }
3645
+ }
3646
+ function Vi(t, e) {
3647
+ const { allowShortKeys: r, extendNonceFn: n, counterLength: i, counterRight: s, rounds: o } = Ni({ allowShortKeys: !1, counterLength: 8, counterRight: !1, rounds: 20 }, e);
3648
+ if (typeof t != "function")
3649
+ throw new Error("core must be a function");
3650
+ return gt(i), gt(o), ln(s), ln(r), (a, u, w, T, R = 0) => {
3651
+ Le(a, void 0, "key"), Le(u, void 0, "nonce"), Le(w, void 0, "data");
3652
+ const _ = w.length;
3653
+ if (T === void 0 && (T = new Uint8Array(_)), Le(T, void 0, "output"), gt(R), R < 0 || R >= nr)
3654
+ throw new Error("arx: counter overflow");
3655
+ if (T.length < _)
3656
+ throw new Error(`arx: output (${T.length}) is shorter than data (${_})`);
3657
+ const k = [];
3658
+ let P = a.length, q, U;
3659
+ if (P === 32)
3660
+ k.push(q = fn(a)), U = Hi;
3661
+ else if (P === 16 && r)
3662
+ q = new Uint8Array(32), q.set(a), q.set(a, 16), U = Ui, k.push(q);
3663
+ else
3664
+ throw Le(a, 32, "arx key"), new Error("invalid key size");
3665
+ Bt(u) || k.push(u = fn(u));
3666
+ const H = ve(q);
3667
+ if (n) {
3668
+ if (u.length !== 24)
3669
+ throw new Error("arx: extended nonce must be 24 bytes");
3670
+ n(U, H, ve(u.subarray(0, 16)), H), u = u.subarray(16);
3671
+ }
3672
+ const W = 16 - i;
3673
+ if (W !== u.length)
3674
+ throw new Error(`arx: nonce must be ${W} or 16 bytes`);
3675
+ if (W !== 12) {
3676
+ const Q = new Uint8Array(12);
3677
+ Q.set(u, s ? 0 : 12 - u.length), u = Q, k.push(u);
3678
+ }
3679
+ const ne = ve(u);
3680
+ return Fi(t, U, H, ne, w, T, R, o), Mi(...k), T;
3681
+ };
3682
+ }
3683
+ function Zi(t, e, r, n, i, s = 20) {
3684
+ let o = t[0], a = t[1], u = t[2], w = t[3], T = e[0], R = e[1], _ = e[2], k = e[3], P = e[4], q = e[5], U = e[6], H = e[7], W = i, ne = r[0], Q = r[1], M = r[2], L = o, x = a, B = u, g = w, E = T, h = R, c = _, d = k, f = P, l = q, v = U, A = H, C = W, I = ne, O = Q, $ = M;
3685
+ for (let j = 0; j < s; j += 2)
3686
+ L = L + E | 0, C = z(C ^ L, 16), f = f + C | 0, E = z(E ^ f, 12), L = L + E | 0, C = z(C ^ L, 8), f = f + C | 0, E = z(E ^ f, 7), x = x + h | 0, I = z(I ^ x, 16), l = l + I | 0, h = z(h ^ l, 12), x = x + h | 0, I = z(I ^ x, 8), l = l + I | 0, h = z(h ^ l, 7), B = B + c | 0, O = z(O ^ B, 16), v = v + O | 0, c = z(c ^ v, 12), B = B + c | 0, O = z(O ^ B, 8), v = v + O | 0, c = z(c ^ v, 7), g = g + d | 0, $ = z($ ^ g, 16), A = A + $ | 0, d = z(d ^ A, 12), g = g + d | 0, $ = z($ ^ g, 8), A = A + $ | 0, d = z(d ^ A, 7), L = L + h | 0, $ = z($ ^ L, 16), v = v + $ | 0, h = z(h ^ v, 12), L = L + h | 0, $ = z($ ^ L, 8), v = v + $ | 0, h = z(h ^ v, 7), x = x + c | 0, C = z(C ^ x, 16), A = A + C | 0, c = z(c ^ A, 12), x = x + c | 0, C = z(C ^ x, 8), A = A + C | 0, c = z(c ^ A, 7), B = B + d | 0, I = z(I ^ B, 16), f = f + I | 0, d = z(d ^ f, 12), B = B + d | 0, I = z(I ^ B, 8), f = f + I | 0, d = z(d ^ f, 7), g = g + E | 0, O = z(O ^ g, 16), l = l + O | 0, E = z(E ^ l, 12), g = g + E | 0, O = z(O ^ g, 8), l = l + O | 0, E = z(E ^ l, 7);
3687
+ let D = 0;
3688
+ n[D++] = o + L | 0, n[D++] = a + x | 0, n[D++] = u + B | 0, n[D++] = w + g | 0, n[D++] = T + E | 0, n[D++] = R + h | 0, n[D++] = _ + c | 0, n[D++] = k + d | 0, n[D++] = P + f | 0, n[D++] = q + l | 0, n[D++] = U + v | 0, n[D++] = H + A | 0, n[D++] = W + C | 0, n[D++] = ne + I | 0, n[D++] = Q + O | 0, n[D++] = M + $ | 0;
3689
+ }
3690
+ const rr = /* @__PURE__ */ Vi(Zi, {
3691
+ counterRight: !1,
3692
+ counterLength: 4,
3693
+ allowShortKeys: !1
3694
+ });
3695
+ function ji(t, e, r) {
3696
+ return tt(t), r === void 0 && (r = new Uint8Array(t.outputLen)), qe(t, r, e);
3697
+ }
3698
+ const pt = /* @__PURE__ */ Uint8Array.of(0), hn = /* @__PURE__ */ Uint8Array.of();
3699
+ function zi(t, e, r, n = 32) {
3700
+ tt(t), me(n, "length");
3701
+ const i = t.outputLen;
3702
+ if (n > 255 * i)
3703
+ throw new Error("Length must be <= 255*HashLen");
3704
+ const s = Math.ceil(n / i);
3705
+ r === void 0 ? r = hn : G(r, void 0, "info");
3706
+ const o = new Uint8Array(s * i), a = qe.create(t, e), u = a._cloneInto(), w = new Uint8Array(a.outputLen);
3707
+ for (let T = 0; T < s; T++)
3708
+ pt[0] = T + 1, u.update(T === 0 ? hn : w).update(r).update(pt).digestInto(w), o.set(w, i * T), a._cloneInto(u);
3709
+ return a.destroy(), u.destroy(), Ne(w, pt), o.slice(0, n);
3710
+ }
3711
+ var Ee = /* @__PURE__ */ Symbol("verified"), Wi = (t) => t instanceof Object;
3712
+ function Yi(t) {
3713
+ if (!Wi(t) || typeof t.kind != "number" || typeof t.content != "string" || typeof t.created_at != "number" || typeof t.pubkey != "string" || !t.pubkey.match(/^[a-f0-9]{64}$/) || !Array.isArray(t.tags))
3714
+ return !1;
3715
+ for (let e = 0; e < t.tags.length; e++) {
3716
+ let r = t.tags[e];
3717
+ if (!Array.isArray(r))
3718
+ return !1;
3719
+ for (let n = 0; n < r.length; n++)
3720
+ if (typeof r[n] != "string")
3721
+ return !1;
3722
+ }
3723
+ return !0;
3724
+ }
3725
+ var Ji = new TextDecoder("utf-8"), Dt = new TextEncoder();
3726
+ function Oe(t) {
3727
+ try {
3728
+ t.indexOf("://") === -1 && (t = "wss://" + t);
3729
+ let e = new URL(t);
3730
+ return e.protocol === "http:" ? e.protocol = "ws:" : e.protocol === "https:" && (e.protocol = "wss:"), e.pathname = e.pathname.replace(/\/+/g, "/"), e.pathname.endsWith("/") && (e.pathname = e.pathname.slice(0, -1)), (e.port === "80" && e.protocol === "ws:" || e.port === "443" && e.protocol === "wss:") && (e.port = ""), e.searchParams.sort(), e.hash = "", e.toString();
3731
+ } catch {
3732
+ throw new Error(`Invalid URL: ${t}`);
3733
+ }
3734
+ }
3735
+ var Gi = class {
3736
+ generateSecretKey() {
3737
+ return he.utils.randomSecretKey();
3738
+ }
3739
+ getPublicKey(t) {
3740
+ return le(he.getPublicKey(t));
3741
+ }
3742
+ finalizeEvent(t, e) {
3743
+ const r = t;
3744
+ return r.pubkey = le(he.getPublicKey(e)), r.id = bt(r), r.sig = le(he.sign(ie(bt(r)), e)), r[Ee] = !0, r;
3745
+ }
3746
+ verifyEvent(t) {
3747
+ if (typeof t[Ee] == "boolean")
3748
+ return t[Ee];
3749
+ try {
3750
+ const e = bt(t);
3751
+ if (e !== t.id)
3752
+ return t[Ee] = !1, !1;
3753
+ const r = he.verify(ie(t.sig), ie(e), ie(t.pubkey));
3754
+ return t[Ee] = r, r;
3755
+ } catch {
3756
+ return t[Ee] = !1, !1;
3757
+ }
3758
+ }
3759
+ };
3760
+ function Xi(t) {
3761
+ if (!Yi(t))
3762
+ throw new Error("can't serialize event with wrong or missing properties");
3763
+ return JSON.stringify([0, t.pubkey, t.created_at, t.kind, t.tags, t.content]);
3764
+ }
3765
+ function bt(t) {
3766
+ let e = xe(Dt.encode(Xi(t)));
3767
+ return le(e);
3768
+ }
3769
+ var st = new Gi();
3770
+ st.generateSecretKey;
3771
+ var gn = st.getPublicKey, Qi = st.finalizeEvent, ir = st.verifyEvent, sr = 1, or = 65535;
3772
+ function yt(t, e) {
3773
+ const r = Bi.getSharedSecret(t, ie("02" + e)).subarray(1, 33);
3774
+ return ji(xe, r, Dt.encode("nip44-v2"));
3775
+ }
3776
+ function ar(t, e) {
3777
+ const r = zi(xe, t, e, 76);
3778
+ return {
3779
+ chacha_key: r.subarray(0, 32),
3780
+ chacha_nonce: r.subarray(32, 44),
3781
+ hmac_key: r.subarray(44, 76)
3782
+ };
3783
+ }
3784
+ function cr(t) {
3785
+ if (!Number.isSafeInteger(t) || t < 1)
3786
+ throw new Error("expected positive integer");
3787
+ if (t <= 32)
3788
+ return 32;
3789
+ const e = 1 << Math.floor(Math.log2(t - 1)) + 1, r = e <= 256 ? 32 : e / 8;
3790
+ return r * (Math.floor((t - 1) / r) + 1);
3791
+ }
3792
+ function es(t) {
3793
+ if (!Number.isSafeInteger(t) || t < sr || t > or)
3794
+ throw new Error("invalid plaintext size: must be between 1 and 65535 bytes");
3795
+ const e = new Uint8Array(2);
3796
+ return new DataView(e.buffer).setUint16(0, t, !1), e;
3797
+ }
3798
+ function ts(t) {
3799
+ const e = Dt.encode(t), r = e.length, n = es(r), i = new Uint8Array(cr(r) - r);
3800
+ return oe(n, e, i);
3801
+ }
3802
+ function ns(t) {
3803
+ const e = new DataView(t.buffer).getUint16(0), r = t.subarray(2, 2 + e);
3804
+ if (e < sr || e > or || r.length !== e || t.length !== 2 + cr(e))
3805
+ throw new Error("invalid padding");
3806
+ return Ji.decode(r);
3807
+ }
3808
+ function ur(t, e, r) {
3809
+ if (r.length !== 32)
3810
+ throw new Error("AAD associated data must be 32 bytes");
3811
+ const n = oe(r, e);
3812
+ return qe(xe, t, n);
3813
+ }
3814
+ function rs(t) {
3815
+ if (typeof t != "string")
3816
+ throw new Error("payload must be a valid string");
3817
+ const e = t.length;
3818
+ if (e < 132 || e > 87472)
3819
+ throw new Error("invalid payload length: " + e);
3820
+ if (t[0] === "#")
3821
+ throw new Error("unknown encryption version");
3822
+ let r;
3823
+ try {
3824
+ r = Sn.decode(t);
3825
+ } catch (s) {
3826
+ throw new Error("invalid base64: " + s.message);
3827
+ }
3828
+ const n = r.length;
3829
+ if (n < 99 || n > 65603)
3830
+ throw new Error("invalid data length: " + n);
3831
+ const i = r[0];
3832
+ if (i !== 2)
3833
+ throw new Error("unknown encryption version " + i);
3834
+ return {
3835
+ nonce: r.subarray(1, 33),
3836
+ ciphertext: r.subarray(33, -32),
3837
+ mac: r.subarray(-32)
3838
+ };
3839
+ }
3840
+ function is(t, e, r = $e(32)) {
3841
+ const { chacha_key: n, chacha_nonce: i, hmac_key: s } = ar(e, r), o = ts(t), a = rr(n, i, o), u = ur(s, a, r);
3842
+ return Sn.encode(oe(new Uint8Array([2]), r, a, u));
3843
+ }
3844
+ function pn(t, e) {
3845
+ const { nonce: r, ciphertext: n, mac: i } = rs(t), { chacha_key: s, chacha_nonce: o, hmac_key: a } = ar(e, r), u = ur(a, n, r);
3846
+ if (!$i(u, i))
3847
+ throw new Error("invalid MAC");
3848
+ const w = rr(s, o, n);
3849
+ return ns(w);
3850
+ }
3851
+ var ss = /^(?:([\w.+-]+)@)?([\w_-]+(\.[\w_-]+)+)$/, os;
3852
+ try {
3853
+ os = fetch;
3854
+ } catch {
3855
+ }
3856
+ var as = 22242, wt = 24133;
3857
+ function cs(t, e) {
3858
+ if (t.ids && t.ids.indexOf(e.id) === -1 || t.kinds && t.kinds.indexOf(e.kind) === -1 || t.authors && t.authors.indexOf(e.pubkey) === -1)
3859
+ return !1;
3860
+ for (let r in t)
3861
+ if (r[0] === "#") {
3862
+ let n = r.slice(1), i = t[`#${n}`];
3863
+ if (i && !e.tags.find(([s, o]) => s === r.slice(1) && i.indexOf(o) !== -1))
3864
+ return !1;
3865
+ }
3866
+ return !(t.since && e.created_at < t.since || t.until && e.created_at > t.until);
3867
+ }
3868
+ function us(t, e) {
3869
+ for (let r = 0; r < t.length; r++)
3870
+ if (cs(t[r], e))
3871
+ return !0;
3872
+ return !1;
3873
+ }
3874
+ function ls(t, e) {
3875
+ let r = e.length + 3, n = t.indexOf(`"${e}":`) + r, i = t.slice(n).indexOf('"') + n + 1;
3876
+ return t.slice(i, i + 64);
3877
+ }
3878
+ function fs(t) {
3879
+ let e = t.slice(0, 22).indexOf('"EVENT"');
3880
+ if (e === -1)
3881
+ return null;
3882
+ let r = t.slice(e + 7 + 1).indexOf('"');
3883
+ if (r === -1)
3884
+ return null;
3885
+ let n = e + 7 + 1 + r, i = t.slice(n + 1, 80).indexOf('"');
3886
+ if (i === -1)
3887
+ return null;
3888
+ let s = n + 1 + i;
3889
+ return t.slice(n + 1, s);
3890
+ }
3891
+ function ds(t, e) {
3892
+ return {
3893
+ kind: as,
3894
+ created_at: Math.floor(Date.now() / 1e3),
3895
+ tags: [
3896
+ ["relay", t],
3897
+ ["challenge", e]
3898
+ ],
3899
+ content: ""
3900
+ };
3901
+ }
3902
+ var lr = class extends Error {
3903
+ constructor(t, e) {
3904
+ super(`Tried to send message '${t} on a closed connection to ${e}.`), this.name = "SendingOnClosedConnection";
3905
+ }
3906
+ }, fr = class {
3907
+ url;
3908
+ _connected = !1;
3909
+ onclose = null;
3910
+ onnotice = (t) => console.debug(`NOTICE from ${this.url}: ${t}`);
3911
+ onauth;
3912
+ baseEoseTimeout = 4400;
3913
+ publishTimeout = 4400;
3914
+ pingFrequency = 29e3;
3915
+ pingTimeout = 2e4;
3916
+ resubscribeBackoff = [1e4, 1e4, 1e4, 2e4, 2e4, 3e4, 6e4];
3917
+ openSubs = /* @__PURE__ */ new Map();
3918
+ enablePing;
3919
+ enableReconnect;
3920
+ idleSince = Date.now();
3921
+ ongoingOperations = 0;
3922
+ reconnectTimeoutHandle;
3923
+ pingIntervalHandle;
3924
+ reconnectAttempts = 0;
3925
+ skipReconnection = !1;
3926
+ connectionPromise;
3927
+ openCountRequests = /* @__PURE__ */ new Map();
3928
+ openEventPublishes = /* @__PURE__ */ new Map();
3929
+ ws;
3930
+ challenge;
3931
+ authPromise;
3932
+ serial = 0;
3933
+ verifyEvent;
3934
+ _WebSocket;
3935
+ constructor(t, e) {
3936
+ this.url = Oe(t), this.verifyEvent = e.verifyEvent, this._WebSocket = e.websocketImplementation || WebSocket, this.enablePing = e.enablePing, this.enableReconnect = e.enableReconnect || !1;
3937
+ }
3938
+ static async connect(t, e) {
3939
+ const r = new fr(t, e);
3940
+ return await r.connect(e), r;
3941
+ }
3942
+ closeAllSubscriptions(t) {
3943
+ for (let [e, r] of this.openSubs)
3944
+ r.close(t);
3945
+ this.openSubs.clear();
3946
+ for (let [e, r] of this.openEventPublishes)
3947
+ r.reject(new Error(t));
3948
+ this.openEventPublishes.clear();
3949
+ for (let [e, r] of this.openCountRequests)
3950
+ r.reject(new Error(t));
3951
+ this.openCountRequests.clear();
3952
+ }
3953
+ get connected() {
3954
+ return this._connected;
3955
+ }
3956
+ async reconnect() {
3957
+ const t = this.resubscribeBackoff[Math.min(this.reconnectAttempts, this.resubscribeBackoff.length - 1)];
3958
+ this.reconnectAttempts++, this.reconnectTimeoutHandle = setTimeout(async () => {
3959
+ try {
3960
+ await this.connect();
3961
+ } catch {
3962
+ }
3963
+ }, t);
3964
+ }
3965
+ handleHardClose(t) {
3966
+ this.pingIntervalHandle && (clearInterval(this.pingIntervalHandle), this.pingIntervalHandle = void 0), this._connected = !1, this.connectionPromise = void 0, this.idleSince = void 0, this.enableReconnect && !this.skipReconnection ? this.reconnect() : (this.onclose?.(), this.closeAllSubscriptions(t));
3967
+ }
3968
+ async connect(t) {
3969
+ let e;
3970
+ return this.connectionPromise ? this.connectionPromise : (this.challenge = void 0, this.authPromise = void 0, this.skipReconnection = !1, this.connectionPromise = new Promise((r, n) => {
3971
+ t?.timeout && (e = setTimeout(() => {
3972
+ n("connection timed out"), this.connectionPromise = void 0, this.skipReconnection = !0, this.onclose?.(), this.handleHardClose("relay connection timed out");
3973
+ }, t.timeout)), t?.abort && (t.abort.onabort = n);
3974
+ try {
3975
+ this.ws = new this._WebSocket(this.url);
3976
+ } catch (i) {
3977
+ clearTimeout(e), n(i);
3978
+ return;
3979
+ }
3980
+ this.ws.onopen = () => {
3981
+ this.reconnectTimeoutHandle && (clearTimeout(this.reconnectTimeoutHandle), this.reconnectTimeoutHandle = void 0), clearTimeout(e), this._connected = !0;
3982
+ const i = this.reconnectAttempts > 0;
3983
+ this.reconnectAttempts = 0;
3984
+ for (const s of this.openSubs.values()) {
3985
+ if (s.eosed = !1, i)
3986
+ for (let o = 0; o < s.filters.length; o++)
3987
+ s.lastEmitted && (s.filters[o].since = s.lastEmitted + 1);
3988
+ s.fire();
3989
+ }
3990
+ this.enablePing && (this.pingIntervalHandle = setInterval(() => this.pingpong(), this.pingFrequency)), r();
3991
+ }, this.ws.onerror = () => {
3992
+ clearTimeout(e), n("connection failed"), this.connectionPromise = void 0, this.skipReconnection = !0, this.onclose?.(), this.handleHardClose("relay connection failed");
3993
+ }, this.ws.onclose = (i) => {
3994
+ clearTimeout(e), n(i.message || "websocket closed"), this.handleHardClose("relay connection closed");
3995
+ }, this.ws.onmessage = this._onmessage.bind(this);
3996
+ }), this.connectionPromise);
3997
+ }
3998
+ waitForPingPong() {
3999
+ return new Promise((t) => {
4000
+ this.ws.once("pong", () => t(!0)), this.ws.ping();
4001
+ });
4002
+ }
4003
+ waitForDummyReq() {
4004
+ return new Promise((t, e) => {
4005
+ if (!this.connectionPromise)
4006
+ return e(new Error(`no connection to ${this.url}, can't ping`));
4007
+ try {
4008
+ const r = this.subscribe(
4009
+ [{ ids: ["aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"], limit: 0 }],
4010
+ {
4011
+ label: "<forced-ping>",
4012
+ oneose: () => {
4013
+ t(!0), r.close();
4014
+ },
4015
+ onclose() {
4016
+ t(!0);
4017
+ },
4018
+ eoseTimeout: this.pingTimeout + 1e3
4019
+ }
4020
+ );
4021
+ } catch (r) {
4022
+ e(r);
4023
+ }
4024
+ });
4025
+ }
4026
+ async pingpong() {
4027
+ this.ws?.readyState === 1 && (await Promise.any([
4028
+ this.ws && this.ws.ping && this.ws.once ? this.waitForPingPong() : this.waitForDummyReq(),
4029
+ new Promise((e) => setTimeout(() => e(!1), this.pingTimeout))
4030
+ ]) || this.ws?.readyState === this._WebSocket.OPEN && this.ws?.close());
4031
+ }
4032
+ async send(t) {
4033
+ if (!this.connectionPromise)
4034
+ throw new lr(t, this.url);
4035
+ this.connectionPromise.then(() => {
4036
+ this.ws?.send(t);
4037
+ });
4038
+ }
4039
+ async auth(t) {
4040
+ const e = this.challenge;
4041
+ if (!e)
4042
+ throw new Error("can't perform auth, no challenge was received");
4043
+ return this.authPromise ? this.authPromise : (this.authPromise = new Promise(async (r, n) => {
4044
+ try {
4045
+ let i = await t(ds(this.url, e)), s = setTimeout(() => {
4046
+ let o = this.openEventPublishes.get(i.id);
4047
+ o && (o.reject(new Error("auth timed out")), this.openEventPublishes.delete(i.id));
4048
+ }, this.publishTimeout);
4049
+ this.openEventPublishes.set(i.id, { resolve: r, reject: n, timeout: s }), this.send('["AUTH",' + JSON.stringify(i) + "]");
4050
+ } catch (i) {
4051
+ console.warn("subscribe auth function failed:", i);
4052
+ }
4053
+ }), this.authPromise);
4054
+ }
4055
+ async publish(t) {
4056
+ this.idleSince = void 0, this.ongoingOperations++;
4057
+ const e = new Promise((r, n) => {
4058
+ const i = setTimeout(() => {
4059
+ const s = this.openEventPublishes.get(t.id);
4060
+ s && (s.reject(new Error("publish timed out")), this.openEventPublishes.delete(t.id));
4061
+ }, this.publishTimeout);
4062
+ this.openEventPublishes.set(t.id, { resolve: r, reject: n, timeout: i });
4063
+ });
4064
+ return this.send('["EVENT",' + JSON.stringify(t) + "]"), this.ongoingOperations--, this.ongoingOperations === 0 && (this.idleSince = Date.now()), e;
4065
+ }
4066
+ async count(t, e) {
4067
+ this.serial++;
4068
+ const r = e?.id || "count:" + this.serial, n = new Promise((i, s) => {
4069
+ this.openCountRequests.set(r, { resolve: i, reject: s });
4070
+ });
4071
+ return this.send('["COUNT","' + r + '",' + JSON.stringify(t).substring(1)), n;
4072
+ }
4073
+ subscribe(t, e) {
4074
+ e.label !== "<forced-ping>" && (this.idleSince = void 0, this.ongoingOperations++);
4075
+ const r = this.prepareSubscription(t, e);
4076
+ return r.fire(), e.abort && (e.abort.onabort = () => r.close(String(e.abort.reason || "<aborted>"))), r;
4077
+ }
4078
+ prepareSubscription(t, e) {
4079
+ this.serial++;
4080
+ const r = e.id || (e.label ? e.label + ":" : "sub:") + this.serial, n = new hs(this, r, t, e);
4081
+ return this.openSubs.set(r, n), n;
4082
+ }
4083
+ close() {
4084
+ this.skipReconnection = !0, this.reconnectTimeoutHandle && (clearTimeout(this.reconnectTimeoutHandle), this.reconnectTimeoutHandle = void 0), this.pingIntervalHandle && (clearInterval(this.pingIntervalHandle), this.pingIntervalHandle = void 0), this.closeAllSubscriptions("relay connection closed by us"), this._connected = !1, this.idleSince = void 0, this.onclose?.(), this.ws?.readyState === this._WebSocket.OPEN && this.ws?.close();
4085
+ }
4086
+ _onmessage(t) {
4087
+ const e = t.data;
4088
+ if (!e)
4089
+ return;
4090
+ const r = fs(e);
4091
+ if (r) {
4092
+ const n = this.openSubs.get(r);
4093
+ if (!n)
4094
+ return;
4095
+ const i = ls(e, "id"), s = n.alreadyHaveEvent?.(i);
4096
+ if (n.receivedEvent?.(this, i), s)
4097
+ return;
4098
+ }
4099
+ try {
4100
+ let n = JSON.parse(e);
4101
+ switch (n[0]) {
4102
+ case "EVENT": {
4103
+ const i = this.openSubs.get(n[1]), s = n[2];
4104
+ this.verifyEvent(s) && us(i.filters, s) ? i.onevent(s) : i.oninvalidevent?.(s), (!i.lastEmitted || i.lastEmitted < s.created_at) && (i.lastEmitted = s.created_at);
4105
+ return;
4106
+ }
4107
+ case "COUNT": {
4108
+ const i = n[1], s = n[2], o = this.openCountRequests.get(i);
4109
+ o && (o.resolve(s.count), this.openCountRequests.delete(i));
4110
+ return;
4111
+ }
4112
+ case "EOSE": {
4113
+ const i = this.openSubs.get(n[1]);
4114
+ if (!i)
4115
+ return;
4116
+ i.receivedEose();
4117
+ return;
4118
+ }
4119
+ case "OK": {
4120
+ const i = n[1], s = n[2], o = n[3], a = this.openEventPublishes.get(i);
4121
+ a && (clearTimeout(a.timeout), s ? a.resolve(o) : a.reject(new Error(o)), this.openEventPublishes.delete(i));
4122
+ return;
4123
+ }
4124
+ case "CLOSED": {
4125
+ const i = n[1], s = this.openSubs.get(i);
4126
+ if (!s)
4127
+ return;
4128
+ s.closed = !0, s.close(n[2]);
4129
+ return;
4130
+ }
4131
+ case "NOTICE": {
4132
+ this.onnotice(n[1]);
4133
+ return;
4134
+ }
4135
+ case "AUTH": {
4136
+ this.challenge = n[1], this.onauth && this.auth(this.onauth);
4137
+ return;
4138
+ }
4139
+ default: {
4140
+ this.openSubs.get(n[1])?.oncustom?.(n);
4141
+ return;
4142
+ }
4143
+ }
4144
+ } catch (n) {
4145
+ try {
4146
+ const [i, s, o] = JSON.parse(e);
4147
+ console.warn(`[nostr] relay ${this.url} error processing message:`, n, o);
4148
+ } catch {
4149
+ console.warn(`[nostr] relay ${this.url} error processing message:`, n);
4150
+ }
4151
+ return;
4152
+ }
4153
+ }
4154
+ }, hs = class {
4155
+ relay;
4156
+ id;
4157
+ lastEmitted;
4158
+ closed = !1;
4159
+ eosed = !1;
4160
+ filters;
4161
+ alreadyHaveEvent;
4162
+ receivedEvent;
4163
+ onevent;
4164
+ oninvalidevent;
4165
+ oneose;
4166
+ onclose;
4167
+ oncustom;
4168
+ eoseTimeout;
4169
+ eoseTimeoutHandle;
4170
+ constructor(t, e, r, n) {
4171
+ if (r.length === 0)
4172
+ throw new Error("subscription can't be created with zero filters");
4173
+ this.relay = t, this.filters = r, this.id = e, this.alreadyHaveEvent = n.alreadyHaveEvent, this.receivedEvent = n.receivedEvent, this.eoseTimeout = n.eoseTimeout || t.baseEoseTimeout, this.oneose = n.oneose, this.onclose = n.onclose, this.oninvalidevent = n.oninvalidevent, this.onevent = n.onevent || ((i) => {
4174
+ console.warn(
4175
+ `onevent() callback not defined for subscription '${this.id}' in relay ${this.relay.url}. event received:`,
4176
+ i
4177
+ );
4178
+ });
4179
+ }
4180
+ fire() {
4181
+ this.relay.send('["REQ","' + this.id + '",' + JSON.stringify(this.filters).substring(1)), this.eoseTimeoutHandle = setTimeout(this.receivedEose.bind(this), this.eoseTimeout);
4182
+ }
4183
+ receivedEose() {
4184
+ this.eosed || (clearTimeout(this.eoseTimeoutHandle), this.eosed = !0, this.oneose?.());
4185
+ }
4186
+ close(t = "closed by caller") {
4187
+ if (!this.closed && this.relay.connected) {
4188
+ try {
4189
+ this.relay.send('["CLOSE",' + JSON.stringify(this.id) + "]");
4190
+ } catch (e) {
4191
+ if (!(e instanceof lr)) throw e;
4192
+ }
4193
+ this.closed = !0;
4194
+ }
4195
+ this.relay.openSubs.delete(this.id), this.relay.ongoingOperations--, this.relay.ongoingOperations === 0 && (this.relay.idleSince = Date.now()), this.onclose?.(t);
4196
+ }
4197
+ }, gs = (t) => (t[Ee] = !0, !0), ps = class {
4198
+ relays = /* @__PURE__ */ new Map();
4199
+ seenOn = /* @__PURE__ */ new Map();
4200
+ trackRelays = !1;
4201
+ verifyEvent;
4202
+ enablePing;
4203
+ enableReconnect;
4204
+ automaticallyAuth;
4205
+ trustedRelayURLs = /* @__PURE__ */ new Set();
4206
+ onRelayConnectionFailure;
4207
+ onRelayConnectionSuccess;
4208
+ allowConnectingToRelay;
4209
+ maxWaitForConnection;
4210
+ _WebSocket;
4211
+ constructor(t) {
4212
+ this.verifyEvent = t.verifyEvent, this._WebSocket = t.websocketImplementation, this.enablePing = t.enablePing, this.enableReconnect = t.enableReconnect || !1, this.automaticallyAuth = t.automaticallyAuth, this.onRelayConnectionFailure = t.onRelayConnectionFailure, this.onRelayConnectionSuccess = t.onRelayConnectionSuccess, this.allowConnectingToRelay = t.allowConnectingToRelay, this.maxWaitForConnection = t.maxWaitForConnection || 3e3;
4213
+ }
4214
+ async ensureRelay(t, e) {
4215
+ t = Oe(t);
4216
+ let r = this.relays.get(t);
4217
+ if (r || (r = new fr(t, {
4218
+ verifyEvent: this.trustedRelayURLs.has(t) ? gs : this.verifyEvent,
4219
+ websocketImplementation: this._WebSocket,
4220
+ enablePing: this.enablePing,
4221
+ enableReconnect: this.enableReconnect
4222
+ }), r.onclose = () => {
4223
+ this.relays.delete(t);
4224
+ }, this.relays.set(t, r)), this.automaticallyAuth) {
4225
+ const n = this.automaticallyAuth(t);
4226
+ n && (r.onauth = n);
4227
+ }
4228
+ try {
4229
+ await r.connect({
4230
+ timeout: e?.connectionTimeout,
4231
+ abort: e?.abort
4232
+ });
4233
+ } catch (n) {
4234
+ throw this.relays.delete(t), n;
4235
+ }
4236
+ return r;
4237
+ }
4238
+ close(t) {
4239
+ t.map(Oe).forEach((e) => {
4240
+ this.relays.get(e)?.close(), this.relays.delete(e);
4241
+ });
4242
+ }
4243
+ subscribe(t, e, r) {
4244
+ const n = [], i = [];
4245
+ for (let s = 0; s < t.length; s++) {
4246
+ const o = Oe(t[s]);
4247
+ n.find((a) => a.url === o) || i.indexOf(o) === -1 && (i.push(o), n.push({ url: o, filter: e }));
4248
+ }
4249
+ return this.subscribeMap(n, r);
4250
+ }
4251
+ subscribeMany(t, e, r) {
4252
+ return this.subscribe(t, e, r);
4253
+ }
4254
+ subscribeMap(t, e) {
4255
+ const r = /* @__PURE__ */ new Map();
4256
+ for (const _ of t) {
4257
+ const { url: k, filter: P } = _;
4258
+ r.has(k) || r.set(k, []), r.get(k).push(P);
4259
+ }
4260
+ const n = Array.from(r.entries()).map(([_, k]) => ({ url: _, filters: k }));
4261
+ this.trackRelays && (e.receivedEvent = (_, k) => {
4262
+ let P = this.seenOn.get(k);
4263
+ P || (P = /* @__PURE__ */ new Set(), this.seenOn.set(k, P)), P.add(_);
4264
+ });
4265
+ const i = /* @__PURE__ */ new Set(), s = [], o = [];
4266
+ let a = (_) => {
4267
+ o[_] || (o[_] = !0, o.filter((k) => k).length === n.length && (e.oneose?.(), a = () => {
4268
+ }));
4269
+ };
4270
+ const u = [];
4271
+ let w = (_, k) => {
4272
+ u[_] || (a(_), u[_] = k, u.filter((P) => P).length === n.length && (e.onclose?.(u), w = () => {
4273
+ }));
4274
+ };
4275
+ const T = (_) => {
4276
+ if (e.alreadyHaveEvent?.(_))
4277
+ return !0;
4278
+ const k = i.has(_);
4279
+ return i.add(_), k;
4280
+ }, R = Promise.all(
4281
+ n.map(async ({ url: _, filters: k }, P) => {
4282
+ if (this.allowConnectingToRelay?.(_, ["read", k]) === !1) {
4283
+ w(P, "connection skipped by allowConnectingToRelay");
4284
+ return;
4285
+ }
4286
+ let q;
4287
+ try {
4288
+ q = await this.ensureRelay(_, {
4289
+ connectionTimeout: this.maxWaitForConnection < (e.maxWait || 0) ? Math.max(e.maxWait * 0.8, e.maxWait - 1e3) : this.maxWaitForConnection,
4290
+ abort: e.abort
4291
+ });
4292
+ } catch (H) {
4293
+ this.onRelayConnectionFailure?.(_), w(P, H?.message || String(H));
4294
+ return;
4295
+ }
4296
+ this.onRelayConnectionSuccess?.(_);
4297
+ let U = q.subscribe(k, {
4298
+ ...e,
4299
+ oneose: () => a(P),
4300
+ onclose: (H) => {
4301
+ H.startsWith("auth-required: ") && e.onauth ? q.auth(e.onauth).then(() => {
4302
+ q.subscribe(k, {
4303
+ ...e,
4304
+ oneose: () => a(P),
4305
+ onclose: (W) => {
4306
+ w(P, W);
4307
+ },
4308
+ alreadyHaveEvent: T,
4309
+ eoseTimeout: e.maxWait,
4310
+ abort: e.abort
4311
+ });
4312
+ }).catch((W) => {
4313
+ w(P, `auth was required and attempted, but failed with: ${W}`);
4314
+ }) : w(P, H);
4315
+ },
4316
+ alreadyHaveEvent: T,
4317
+ eoseTimeout: e.maxWait,
4318
+ abort: e.abort
4319
+ });
4320
+ s.push(U);
4321
+ })
4322
+ );
4323
+ return {
4324
+ async close(_) {
4325
+ await R, s.forEach((k) => {
4326
+ k.close(_);
4327
+ });
4328
+ }
4329
+ };
4330
+ }
4331
+ subscribeEose(t, e, r) {
4332
+ let n;
4333
+ return n = this.subscribe(t, e, {
4334
+ ...r,
4335
+ oneose() {
4336
+ const i = "closed automatically on eose";
4337
+ n ? n.close(i) : r.onclose?.(t.map((s) => i));
4338
+ }
4339
+ }), n;
4340
+ }
4341
+ subscribeManyEose(t, e, r) {
4342
+ return this.subscribeEose(t, e, r);
4343
+ }
4344
+ async querySync(t, e, r) {
4345
+ return new Promise(async (n) => {
4346
+ const i = [];
4347
+ this.subscribeEose(t, e, {
4348
+ ...r,
4349
+ onevent(s) {
4350
+ i.push(s);
4351
+ },
4352
+ onclose(s) {
4353
+ n(i);
4354
+ }
4355
+ });
4356
+ });
4357
+ }
4358
+ async get(t, e, r) {
4359
+ e.limit = 1;
4360
+ const n = await this.querySync(t, e, r);
4361
+ return n.sort((i, s) => s.created_at - i.created_at), n[0] || null;
4362
+ }
4363
+ publish(t, e, r) {
4364
+ return t.map(Oe).map(async (n, i, s) => {
4365
+ if (s.indexOf(n) !== i)
4366
+ return Promise.reject("duplicate url");
4367
+ if (this.allowConnectingToRelay?.(n, ["write", e]) === !1)
4368
+ return Promise.reject("connection skipped by allowConnectingToRelay");
4369
+ let o;
4370
+ try {
4371
+ o = await this.ensureRelay(n, {
4372
+ connectionTimeout: this.maxWaitForConnection < (r?.maxWait || 0) ? Math.max(r.maxWait * 0.8, r.maxWait - 1e3) : this.maxWaitForConnection,
4373
+ abort: r?.abort
4374
+ });
4375
+ } catch (a) {
4376
+ return this.onRelayConnectionFailure?.(n), "connection failure: " + String(a);
4377
+ }
4378
+ return o.publish(e).catch(async (a) => {
4379
+ if (a instanceof Error && a.message.startsWith("auth-required: ") && r?.onauth)
4380
+ return await o.auth(r.onauth), o.publish(e);
4381
+ throw a;
4382
+ }).then((a) => {
4383
+ if (this.trackRelays) {
4384
+ let u = this.seenOn.get(e.id);
4385
+ u || (u = /* @__PURE__ */ new Set(), this.seenOn.set(e.id, u)), u.add(o);
4386
+ }
4387
+ return a;
4388
+ });
4389
+ });
4390
+ }
4391
+ listConnectionStatus() {
4392
+ const t = /* @__PURE__ */ new Map();
4393
+ return this.relays.forEach((e, r) => t.set(r, e.connected)), t;
4394
+ }
4395
+ destroy() {
4396
+ this.relays.forEach((t) => t.close()), this.relays = /* @__PURE__ */ new Map();
4397
+ }
4398
+ pruneIdleRelays(t = 1e4) {
4399
+ const e = [];
4400
+ for (const [r, n] of this.relays)
4401
+ n.idleSince && Date.now() - n.idleSince >= t && (this.relays.delete(r), e.push(r), n.close());
4402
+ return e;
4403
+ }
4404
+ }, dr;
4405
+ try {
4406
+ dr = WebSocket;
4407
+ } catch {
4408
+ }
4409
+ var bs = class extends ps {
4410
+ constructor(t) {
4411
+ super({ verifyEvent: ir, websocketImplementation: dr, maxWaitForConnection: 3e3, ...t });
4412
+ }
4413
+ }, hr;
4414
+ try {
4415
+ hr = fetch;
4416
+ } catch {
4417
+ }
4418
+ var ys = /^bunker:\/\/([0-9a-f]{64})\??([?\/\w:.=&%-]*)$/;
4419
+ async function ws(t) {
4420
+ let e = t.match(ys);
4421
+ if (e)
4422
+ try {
4423
+ const r = e[1], n = new URLSearchParams(e[2]);
4424
+ return {
4425
+ pubkey: r,
4426
+ relays: n.getAll("relay"),
4427
+ secret: n.get("secret")
4428
+ };
4429
+ } catch {
4430
+ }
4431
+ return vs(t);
4432
+ }
4433
+ async function vs(t) {
4434
+ const e = t.match(ss);
4435
+ if (!e)
4436
+ return null;
4437
+ const [r, n = "_", i] = e;
4438
+ try {
4439
+ const s = `https://${i}/.well-known/nostr.json?name=${n}`, o = await (await hr(s, { redirect: "error" })).json();
4440
+ let a = o.names[n], u = o.nip46[a] || [];
4441
+ return { pubkey: a, relays: u, secret: null };
4442
+ } catch {
4443
+ return null;
4444
+ }
4445
+ }
4446
+ function ms(t) {
4447
+ const e = new URLSearchParams();
4448
+ return t.relays.forEach((r) => {
4449
+ e.append("relay", r);
4450
+ }), e.append("secret", t.secret), t.perms && t.perms.length > 0 && e.append("perms", t.perms.join(",")), t.name && e.append("name", t.name), t.url && e.append("url", t.url), t.image && e.append("image", t.image), `nostrconnect://${t.clientPubkey}?${e.toString()}`;
4451
+ }
4452
+ var et = class {
4453
+ params;
4454
+ pool;
4455
+ subCloser;
4456
+ isOpen;
4457
+ serial;
4458
+ idPrefix;
4459
+ listeners;
4460
+ waitingForAuth;
4461
+ secretKey;
4462
+ conversationKey;
4463
+ bp;
4464
+ cachedPubKey;
4465
+ constructor(t, e) {
4466
+ this.params = e, this.pool = e.pool || new bs(), this.secretKey = t, this.isOpen = !1, this.idPrefix = Math.random().toString(36).substring(7), this.serial = 0, this.listeners = {}, this.waitingForAuth = {};
4467
+ }
4468
+ static fromBunker(t, e, r = {}) {
4469
+ if (e.relays.length === 0)
4470
+ throw new Error("no relays specified for this bunker");
4471
+ const n = new et(t, r);
4472
+ return n.conversationKey = yt(t, e.pubkey), n.bp = e, n.setupSubscription(), n;
4473
+ }
4474
+ static async fromURI(t, e, r = {}, n = 3e5) {
4475
+ const i = new et(t, r), s = new URL(e), o = gn(t);
4476
+ return new Promise((a, u) => {
4477
+ let w = !1;
4478
+ const T = i.pool.subscribe(
4479
+ s.searchParams.getAll("relay"),
4480
+ {
4481
+ kinds: [wt],
4482
+ "#p": [o],
4483
+ limit: 0
4484
+ },
4485
+ {
4486
+ onevent: async (R) => {
4487
+ try {
4488
+ const _ = yt(t, R.pubkey), k = pn(R.content, _);
4489
+ JSON.parse(k).result === s.searchParams.get("secret") && (T.close(), i.bp = {
4490
+ pubkey: R.pubkey,
4491
+ relays: s.searchParams.getAll("relay"),
4492
+ secret: s.searchParams.get("secret")
4493
+ }, i.conversationKey = yt(t, R.pubkey), i.setupSubscription(), w = !0, await Promise.race([new Promise((q) => setTimeout(q, 1e3)), i.switchRelays()]), a(i));
4494
+ } catch (_) {
4495
+ console.warn("failed to process potential connection event", _);
4496
+ }
4497
+ },
4498
+ onclose: () => {
4499
+ w || u(new Error("subscription closed before connection was established."));
4500
+ },
4501
+ maxWait: typeof n == "number" ? n : void 0,
4502
+ abort: typeof n != "number" ? n : void 0
4503
+ }
4504
+ );
4505
+ });
4506
+ }
4507
+ setupSubscription() {
4508
+ const t = this.listeners, e = this.waitingForAuth, r = this.conversationKey;
4509
+ this.subCloser = this.pool.subscribe(
4510
+ this.bp.relays,
4511
+ {
4512
+ kinds: [wt],
4513
+ authors: [this.bp.pubkey],
4514
+ "#p": [gn(this.secretKey)],
4515
+ limit: 0
4516
+ },
4517
+ {
4518
+ onevent: async (n) => {
4519
+ const i = JSON.parse(pn(n.content, r)), { id: s, result: o, error: a } = i;
4520
+ if (o === "auth_url" && e[s]) {
4521
+ delete e[s], this.params.onauth ? this.params.onauth(a) : console.warn(
4522
+ `nostr-tools/nip46: remote signer ${this.bp.pubkey} tried to send an "auth_url"='${a}' but there was no onauth() callback configured.`
4523
+ );
4524
+ return;
4525
+ }
4526
+ let u = t[s];
4527
+ u && (a ? u.reject(a) : o && u.resolve(o), delete t[s]);
4528
+ },
4529
+ onclose: () => {
4530
+ this.subCloser = void 0;
4531
+ }
4532
+ }
4533
+ ), this.isOpen = !0;
4534
+ }
4535
+ async switchRelays() {
4536
+ try {
4537
+ const t = await this.sendRequest("switch_relays", []);
4538
+ let e = JSON.parse(t);
4539
+ if (!e || JSON.stringify(e.sort()) === JSON.stringify(this.bp.relays))
4540
+ return !1;
4541
+ this.bp.relays = e;
4542
+ let r = this.subCloser;
4543
+ return setTimeout(() => {
4544
+ r.close();
4545
+ }, 5e3), this.subCloser = void 0, this.setupSubscription(), !0;
4546
+ } catch {
4547
+ return !1;
4548
+ }
4549
+ }
4550
+ async close() {
4551
+ this.isOpen = !1, this.subCloser.close();
4552
+ }
4553
+ async sendRequest(t, e) {
4554
+ return new Promise(async (r, n) => {
4555
+ try {
4556
+ if (!this.isOpen)
4557
+ throw new Error("this signer is not open anymore, create a new one");
4558
+ this.subCloser || this.setupSubscription(), this.serial++;
4559
+ const i = `${this.idPrefix}-${this.serial}`, s = is(JSON.stringify({ id: i, method: t, params: e }), this.conversationKey), o = Qi(
4560
+ {
4561
+ kind: wt,
4562
+ tags: [["p", this.bp.pubkey]],
4563
+ content: s,
4564
+ created_at: Math.floor(Date.now() / 1e3)
4565
+ },
4566
+ this.secretKey
4567
+ );
4568
+ this.listeners[i] = { resolve: r, reject: n }, this.waitingForAuth[i] = !0, await Promise.any(this.pool.publish(this.bp.relays, o));
4569
+ } catch (i) {
4570
+ n(i);
4571
+ }
4572
+ });
4573
+ }
4574
+ async ping() {
4575
+ let t = await this.sendRequest("ping", []);
4576
+ if (t !== "pong")
4577
+ throw new Error(`result is not pong: ${t}`);
4578
+ }
4579
+ async connect() {
4580
+ await this.sendRequest("connect", [this.bp.pubkey, this.bp.secret || ""]);
4581
+ }
4582
+ async getPublicKey() {
4583
+ return this.cachedPubKey || (this.cachedPubKey = await this.sendRequest("get_public_key", [])), this.cachedPubKey;
4584
+ }
4585
+ async signEvent(t) {
4586
+ let e = await this.sendRequest("sign_event", [JSON.stringify(t)]), r = JSON.parse(e);
4587
+ if (ir(r))
4588
+ return r;
4589
+ throw new Error(`event returned from bunker is improperly signed: ${JSON.stringify(r)}`);
4590
+ }
4591
+ async nip04Encrypt(t, e) {
4592
+ return await this.sendRequest("nip04_encrypt", [t, e]);
4593
+ }
4594
+ async nip04Decrypt(t, e) {
4595
+ return await this.sendRequest("nip04_decrypt", [t, e]);
4596
+ }
4597
+ async nip44Encrypt(t, e) {
4598
+ return await this.sendRequest("nip44_encrypt", [t, e]);
4599
+ }
4600
+ async nip44Decrypt(t, e) {
4601
+ return await this.sendRequest("nip44_decrypt", [t, e]);
4602
+ }
4603
+ };
4604
+ const xs = "wss://bucket.coracle.social";
4605
+ function Es() {
4606
+ return !!window.nostr;
4607
+ }
4608
+ function ks() {
4609
+ if (!window.nostr) throw new Error("No Nostr signer extension found");
4610
+ const t = window.nostr;
4611
+ return {
4612
+ getPublicKey: () => t.getPublicKey(),
4613
+ signEvent: (e) => t.signEvent(e),
4614
+ close() {
4615
+ }
4616
+ };
4617
+ }
4618
+ async function As(t) {
4619
+ const e = er(), r = await ws(t);
4620
+ if (!r) throw new Error("Invalid bunker URI");
4621
+ const n = et.fromBunker(e, r);
4622
+ return await n.connect(), gr(n);
4623
+ }
4624
+ function Ss(t) {
4625
+ const e = er(), r = Ii(e), n = Array.from(
4626
+ crypto.getRandomValues(new Uint8Array(16)),
4627
+ (s) => s.toString(16).padStart(2, "0")
4628
+ ).join(""), i = ms({
4629
+ clientPubkey: r,
4630
+ relays: [t],
4631
+ secret: n,
4632
+ name: "nsite deploy"
4633
+ });
4634
+ return {
4635
+ uri: i,
4636
+ async connect(s) {
4637
+ const o = await et.fromURI(e, i, {}, s ?? 3e5);
4638
+ return gr(o);
4639
+ }
4640
+ };
4641
+ }
4642
+ function gr(t) {
4643
+ return {
4644
+ getPublicKey: () => t.getPublicKey(),
4645
+ signEvent: (e) => t.signEvent(e),
4646
+ close: () => t.close()
4647
+ };
4648
+ }
4649
+ const qt = class qt extends HTMLElement {
4650
+ constructor() {
4651
+ super(), this.state = "idle", this.ctx = null, this.manifest = null, this.signer = null, this.userPubkey = "", this.userRelays = [], this.deployedUrl = "", this.errorMsg = "", this.statusMsg = "", this.slug = "", this.siteTitle = "", this.siteDescription = "", this.deployAsRoot = !0, this.hasRootSite = null, this.nostrConnectUri = "", this.nip46Relay = xs, this.qrAbort = null, this.ncConnect = null, this.manifestPromise = null, this.relaysPromise = null, this.thieves = [], this.thievesExpanded = !1, this.shadow = this.attachShadow({ mode: "open" }), this.ctx = Pr(), this.ctx && (this.manifestPromise = Wt(this.ctx), this.manifestPromise.then((e) => {
4652
+ e && (this.thieves = Dr(e), this.thieves.length > 0 && this.state === "idle" && this.render());
4653
+ }), this.render());
4654
+ }
4655
+ attributeChangedCallback() {
4656
+ this.state === "idle" && this.render();
4657
+ }
4658
+ get buttonLabel() {
4659
+ return this.getAttribute("label") || "Borrow this";
4660
+ }
4661
+ esc(e) {
4662
+ return e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
4663
+ }
4664
+ modal(e) {
4665
+ return `<div class="nd-overlay"><div class="nd-modal">${e}</div></div>`;
4666
+ }
4667
+ render() {
4668
+ this.preserveFormValues();
4669
+ let e = `<style>${pr}</style>`;
4670
+ switch (this.state) {
4671
+ case "idle":
4672
+ e += `<button class="nd-trigger" part="trigger">${this.esc(this.buttonLabel)}</button>`, e += this.paperTrailContent();
4673
+ break;
4674
+ case "auth":
4675
+ e += `<button class="nd-trigger" disabled>${this.esc(this.buttonLabel)}</button>`, e += this.modal(this.authContent());
4676
+ break;
4677
+ case "connecting":
4678
+ e += '<button class="nd-trigger" disabled>Connecting...</button>', e += this.modal(`
4679
+ <div class="nd-header">
4680
+ <h2 class="nd-title">Connecting</h2>
4681
+ <button class="nd-close" data-action="close">&times;</button>
4682
+ </div>
4683
+ <div class="nd-msg"><span class="nd-spinner"></span>${this.esc(this.statusMsg)}</div>
4684
+ `);
4685
+ break;
4686
+ case "loading":
4687
+ e += '<button class="nd-trigger" disabled>Loading...</button>', e += this.modal(`
4688
+ <div class="nd-msg"><span class="nd-spinner"></span>Fetching site manifest...</div>
4689
+ `);
4690
+ break;
4691
+ case "form":
4692
+ e += `<button class="nd-trigger" disabled>${this.esc(this.buttonLabel)}</button>`, e += this.modal(this.formContent());
4693
+ break;
4694
+ case "confirm":
4695
+ e += `<button class="nd-trigger" disabled>${this.esc(this.buttonLabel)}</button>`, e += this.modal(this.confirmContent());
4696
+ break;
4697
+ case "deploying":
4698
+ e += '<button class="nd-trigger" disabled>Deploying...</button>', e += this.modal(`
4699
+ <h2 class="nd-title">Deploying</h2>
4700
+ <div class="nd-msg"><span class="nd-spinner"></span>${this.esc(this.statusMsg)}</div>
4701
+ `);
4702
+ break;
4703
+ case "success":
4704
+ e += '<button class="nd-trigger" disabled>Deployed!</button>', e += this.modal(`
4705
+ <div class="nd-header">
4706
+ <h2 class="nd-title">Deployed!</h2>
4707
+ <button class="nd-close" data-action="close">&times;</button>
4708
+ </div>
4709
+ <div class="nd-status nd-status-ok">Your site is live</div>
4710
+ <a class="nd-link" href="${this.esc(this.deployedUrl)}" target="_blank" rel="noopener">${this.esc(this.deployedUrl)}</a>
4711
+ <div class="nd-actions">
4712
+ <button class="nd-btn nd-btn-secondary" data-action="close">Close</button>
4713
+ </div>
4714
+ `);
4715
+ break;
4716
+ case "error":
4717
+ e += `<button class="nd-trigger" part="trigger">${this.esc(this.buttonLabel)}</button>`, e += this.modal(`
4718
+ <div class="nd-header">
4719
+ <h2 class="nd-title">Error</h2>
4720
+ <button class="nd-close" data-action="close">&times;</button>
4721
+ </div>
4722
+ <div class="nd-status nd-status-err">${this.esc(this.errorMsg)}</div>
4723
+ <div class="nd-actions">
4724
+ <button class="nd-btn nd-btn-secondary" data-action="close">Close</button>
4725
+ </div>
4726
+ `);
4727
+ break;
4728
+ }
4729
+ this.shadow.innerHTML = e, this.bind();
4730
+ }
4731
+ // --- Content builders ---
4732
+ paperTrailContent() {
4733
+ if (this.thieves.length === 0) return "";
4734
+ let e = `<div class="nd-trail">
4735
+ <button class="nd-trail-toggle" data-action="toggle-trail">Stolen by ${this.thieves.length} npub${this.thieves.length === 1 ? "" : "s"}</button>`;
4736
+ if (this.thievesExpanded) {
4737
+ e += '<div class="nd-trail-list">';
4738
+ const r = this.thieves[0], n = this.thieves.length > 1 ? this.thieves[1] : null;
4739
+ if (e += this.thiefItem(r), n && n.index > r.index + 1) {
4740
+ const i = n.index - r.index - 1;
4741
+ e += `<div class="nd-trail-gap">... ${i} more</div>`;
4742
+ }
4743
+ for (let i = 1; i < this.thieves.length; i++)
4744
+ e += this.thiefItem(this.thieves[i]);
4745
+ e += "</div>";
4746
+ }
4747
+ return e += "</div>", e;
4748
+ }
4749
+ thiefItem(e) {
4750
+ const r = Bn(e.pubkey), n = r.slice(0, 12) + "..." + r.slice(-4);
4751
+ return `<div class="nd-trail-item">
4752
+ <span class="nd-trail-idx">#${e.index}</span>
4753
+ <span class="nd-trail-pk">${n}</span>
4754
+ </div>`;
4755
+ }
4756
+ authContent() {
4757
+ const e = Es(), r = this.nostrConnectUri ? Zr(this.nostrConnectUri) : "";
4758
+ let n = `
4759
+ <div class="nd-header">
4760
+ <h2 class="nd-title">Sign In</h2>
4761
+ <button class="nd-close" data-action="close">&times;</button>
4762
+ </div>`;
4763
+ return e && (n += `
4764
+ <div class="nd-auth-option">
4765
+ <button class="nd-btn-ext" data-action="ext">Sign in with Extension</button>
4766
+ </div>
4767
+ <div class="nd-divider">or</div>`), n += `
4768
+ <div class="nd-auth-option">
4769
+ <div class="nd-qr-label" style="margin-bottom:6px">Paste a bunker URI</div>
4770
+ <div class="nd-bunker-row">
4771
+ <input type="text" placeholder="bunker://..." id="nd-bunker" />
4772
+ <button data-action="bunker">Connect</button>
4773
+ </div>
4774
+ </div>
4775
+ <div class="nd-divider">or scan</div>
4776
+ <div class="nd-auth-option">
4777
+ <div class="nd-qr-wrap">
4778
+ <div class="nd-qr-label">Scan with your signer app</div>
4779
+ <div class="nd-qr-code">${r}</div>
4780
+ <div class="nd-relay-row">
4781
+ <label>relay</label>
4782
+ <input type="text" id="nd-nip46-relay" value="${this.esc(this.nip46Relay)}" />
4783
+ </div>
4784
+ <div class="nd-qr-uri">
4785
+ <input readonly value="${this.esc(this.nostrConnectUri)}" id="nd-nc-uri" />
4786
+ <button data-action="copy-uri">Copy</button>
4787
+ </div>
4788
+ </div>
4789
+ </div>`, n;
4790
+ }
4791
+ formContent() {
4792
+ let e = `
4793
+ <div class="nd-header">
4794
+ <h2 class="nd-title">Deploy this Page</h2>
4795
+ <button class="nd-close" data-action="close">&times;</button>
4796
+ </div>
4797
+ ${this.hasRootSite ? `<div class="nd-toggle">
4798
+ <button class="nd-toggle-btn ${this.deployAsRoot ? "active" : ""}" data-action="type-root">Root Site</button>
4799
+ <button class="nd-toggle-btn ${this.deployAsRoot ? "" : "active"}" data-action="type-named">Named Site</button>
4800
+ </div>` : ""}`;
4801
+ return this.deployAsRoot ? e += '<div class="nd-root-hint">Your primary site, served at your npub subdomain.</div>' : e += `
4802
+ <div class="nd-root-hint">A sub-site with its own name, served alongside your root site.</div>
4803
+ <div class="nd-field">
4804
+ <label for="nd-slug">Site name</label>
4805
+ <input id="nd-slug" type="text" placeholder="my-site" value="${this.esc(this.slug)}" maxlength="13" autocomplete="off" />
4806
+ <div class="nd-hint">Lowercase a-z, 0-9, hyphens. 1-13 chars.</div>
4807
+ <div class="nd-field-error" id="nd-slug-err"></div>
4808
+ </div>`, e += `
4809
+ <div class="nd-field">
4810
+ <label for="nd-title">Title</label>
4811
+ <input id="nd-title" type="text" placeholder="Optional" value="${this.esc(this.siteTitle)}" />
4812
+ </div>
4813
+ <div class="nd-field">
4814
+ <label for="nd-desc">Description</label>
4815
+ <textarea id="nd-desc" placeholder="Optional">${this.esc(this.siteDescription)}</textarea>
4816
+ </div>
4817
+ <div class="nd-actions">
4818
+ <button class="nd-btn nd-btn-secondary" data-action="close">Cancel</button>
4819
+ <button class="nd-btn nd-btn-primary" data-action="deploy" ${this.hasRootSite === null ? "disabled" : ""}>
4820
+ ${this.hasRootSite === null ? '<span class="nd-spinner"></span>Checking...' : "Deploy"}
4821
+ </button>
4822
+ </div>`, e;
4823
+ }
4824
+ confirmContent() {
4825
+ return `
4826
+ <div class="nd-header">
4827
+ <h2 class="nd-title">Site Already Exists</h2>
4828
+ <button class="nd-close" data-action="close">&times;</button>
4829
+ </div>
4830
+ <div class="nd-warn">
4831
+ You already have ${this.deployAsRoot ? "a root site" : `a site named "${this.esc(this.slug)}"`}. Deploying will replace it with this page's content.
4832
+ </div>
4833
+ <div class="nd-actions">
4834
+ <button class="nd-btn nd-btn-secondary" data-action="back">Back</button>
4835
+ <button class="nd-btn nd-btn-warn" data-action="confirm-deploy">Overwrite</button>
4836
+ </div>`;
4837
+ }
4838
+ // --- Bindings ---
4839
+ bind() {
4840
+ this.shadow.querySelector(".nd-trigger:not([disabled])")?.addEventListener("click", () => this.open()), this.shadow.querySelectorAll('[data-action="close"]').forEach((r) => r.addEventListener("click", () => this.close())), this.shadow.querySelector('[data-action="deploy"]')?.addEventListener("click", () => this.onDeploy()), this.shadow.querySelector('[data-action="confirm-deploy"]')?.addEventListener("click", () => this.executeDeploy()), this.shadow.querySelector('[data-action="back"]')?.addEventListener("click", () => this.setState("form")), this.shadow.querySelector('[data-action="ext"]')?.addEventListener("click", () => this.authExtension()), this.shadow.querySelector('[data-action="bunker"]')?.addEventListener("click", () => this.authBunker()), this.shadow.querySelector('[data-action="copy-uri"]')?.addEventListener("click", () => this.copyUri()), this.shadow.querySelector('[data-action="toggle-trail"]')?.addEventListener("click", () => {
4841
+ this.thievesExpanded = !this.thievesExpanded, this.render();
4842
+ }), this.shadow.querySelector('[data-action="type-named"]')?.addEventListener("click", () => {
4843
+ this.deployAsRoot = !1, this.setState("form");
4844
+ }), this.shadow.querySelector('[data-action="type-root"]')?.addEventListener("click", () => {
4845
+ this.deployAsRoot = !0, this.setState("form");
4846
+ }), this.shadow.querySelector(".nd-overlay")?.addEventListener("click", (r) => {
4847
+ r.target.classList.contains("nd-overlay") && this.close();
4848
+ });
4849
+ const e = this.shadow.querySelector("#nd-nip46-relay");
4850
+ if (e) {
4851
+ const r = () => {
4852
+ const n = e.value.trim();
4853
+ n && n !== this.nip46Relay && (this.nip46Relay = n, this.startNostrConnect());
4854
+ };
4855
+ e.addEventListener("blur", r), e.addEventListener("keydown", (n) => {
4856
+ n.key === "Enter" && (n.preventDefault(), r());
4857
+ });
4858
+ }
4859
+ }
4860
+ preserveFormValues() {
4861
+ if (this.state !== "form") return;
4862
+ const e = this.shadow.querySelector("#nd-slug"), r = this.shadow.querySelector("#nd-title"), n = this.shadow.querySelector("#nd-desc");
4863
+ e && (this.slug = e.value), r && (this.siteTitle = r.value), n && (this.siteDescription = n.value);
4864
+ }
4865
+ setState(e) {
4866
+ this.state = e, this.render();
4867
+ }
4868
+ close() {
4869
+ this.cancelQr(), this.signer?.close(), this.signer = null, this.setState("idle");
4870
+ }
4871
+ cancelQr() {
4872
+ this.qrAbort?.abort(), this.qrAbort = null, this.ncConnect = null;
4873
+ }
4874
+ showError(e) {
4875
+ this.errorMsg = e, this.setState("error");
4876
+ }
4877
+ // --- Nostrconnect lifecycle ---
4878
+ startNostrConnect() {
4879
+ this.cancelQr(), this.ncConnect = Ss(this.nip46Relay), this.nostrConnectUri = this.ncConnect.uri, this.state === "auth" && this.render(), this.qrAbort = new AbortController(), this.ncConnect.connect(this.qrAbort.signal).then((e) => {
4880
+ this.state === "auth" || this.state === "connecting" ? (this.signer = e, this.onAuthenticated()) : e.close();
4881
+ }).catch(() => {
4882
+ });
4883
+ }
4884
+ // --- Auth ---
4885
+ async open() {
4886
+ !this.manifestPromise && this.ctx && (this.manifestPromise = Wt(this.ctx)), this.state = "auth", this.startNostrConnect();
4887
+ }
4888
+ async authExtension() {
4889
+ this.cancelQr();
4890
+ try {
4891
+ this.signer = ks(), this.onAuthenticated();
4892
+ } catch (e) {
4893
+ this.showError(e instanceof Error ? e.message : String(e));
4894
+ }
4895
+ }
4896
+ async authBunker() {
4897
+ const e = this.shadow.querySelector("#nd-bunker")?.value.trim();
4898
+ if (e) {
4899
+ this.cancelQr(), this.statusMsg = "Connecting to bunker...", this.setState("connecting");
4900
+ try {
4901
+ this.signer = await As(e), this.onAuthenticated();
4902
+ } catch (r) {
4903
+ this.showError(r instanceof Error ? r.message : String(r));
4904
+ }
4905
+ }
4906
+ }
4907
+ async copyUri() {
4908
+ try {
4909
+ await navigator.clipboard.writeText(this.nostrConnectUri);
4910
+ const e = this.shadow.querySelector('[data-action="copy-uri"]');
4911
+ e && (e.textContent = "Copied!", setTimeout(() => {
4912
+ e.isConnected && (e.textContent = "Copy");
4913
+ }, 2e3));
4914
+ } catch {
4915
+ }
4916
+ }
4917
+ // --- Post-auth ---
4918
+ async onAuthenticated() {
4919
+ this.setState("loading");
4920
+ try {
4921
+ if (this.userPubkey = await this.signer.getPublicKey(), this.manifest = await this.manifestPromise, !this.manifest) {
4922
+ this.showError("Could not find the site manifest on any relay.");
4923
+ return;
4924
+ }
4925
+ this.siteTitle = "", this.siteDescription = "", this.slug = this.ctx.identifier ?? "", this.deployAsRoot = !0, this.hasRootSite = null, this.setState("form"), this.relaysPromise = Yt(this.userPubkey), this.relaysPromise.then(async (e) => {
4926
+ this.userRelays = e;
4927
+ const r = await Jt(e, this.userPubkey);
4928
+ this.hasRootSite = r, r && this.state === "form" && this.deployAsRoot && (this.deployAsRoot = !1), this.state === "form" && this.render();
4929
+ });
4930
+ } catch (e) {
4931
+ this.showError(e instanceof Error ? e.message : String(e));
4932
+ }
4933
+ }
4934
+ // --- Deploy ---
4935
+ readFormValues() {
4936
+ if (!this.deployAsRoot) {
4937
+ const n = this.shadow.querySelector("#nd-slug");
4938
+ n && (this.slug = n.value.trim());
4939
+ }
4940
+ const e = this.shadow.querySelector("#nd-title"), r = this.shadow.querySelector("#nd-desc");
4941
+ e && (this.siteTitle = e.value.trim()), r && (this.siteDescription = r.value.trim());
4942
+ }
4943
+ async onDeploy() {
4944
+ if (this.readFormValues(), !this.deployAsRoot) {
4945
+ const e = this.shadow.querySelector("#nd-slug-err");
4946
+ if (!this.slug) {
4947
+ e.textContent = "Site name is required";
4948
+ return;
4949
+ }
4950
+ if (!Mr(this.slug)) {
4951
+ e.textContent = "Lowercase a-z, 0-9, hyphens only. Cannot end with hyphen.";
4952
+ return;
4953
+ }
4954
+ }
4955
+ this.statusMsg = "Checking for existing site...", this.setState("deploying");
4956
+ try {
4957
+ this.relaysPromise && (this.userRelays = await this.relaysPromise), this.userRelays.length === 0 && (this.userRelays = await Yt(this.userPubkey));
4958
+ const e = this.deployAsRoot ? void 0 : this.slug;
4959
+ if (await Jt(this.userRelays, this.userPubkey, e)) {
4960
+ this.setState("confirm");
4961
+ return;
4962
+ }
4963
+ await this.executeDeploy();
4964
+ } catch (e) {
4965
+ this.showError(e instanceof Error ? e.message : String(e));
4966
+ }
4967
+ }
4968
+ async executeDeploy() {
4969
+ this.statusMsg = "Creating event...", this.setState("deploying");
4970
+ try {
4971
+ const e = this.deployAsRoot ? void 0 : this.slug, r = qr(this.manifest, {
4972
+ slug: e,
4973
+ title: this.siteTitle || void 0,
4974
+ description: this.siteDescription || void 0,
4975
+ deployerPubkey: this.userPubkey,
4976
+ deployerRelays: this.userRelays
4977
+ });
4978
+ this.statusMsg = "Waiting for signature...", this.render();
4979
+ const n = await this.signer.signEvent(r);
4980
+ if (this.statusMsg = `Publishing to ${this.userRelays.length} relay${this.userRelays.length === 1 ? "" : "s"}...`, this.render(), await $r(this.userRelays, n) === 0) {
4981
+ this.showError("Failed to publish to any relay. Please try again.");
4982
+ return;
4983
+ }
4984
+ this.deployedUrl = Ur(this.ctx.baseDomain, this.userPubkey, e), this.setState("success");
4985
+ } catch (e) {
4986
+ this.showError(e instanceof Error ? e.message : String(e));
4987
+ }
4988
+ }
4989
+ };
4990
+ qt.observedAttributes = ["label"];
4991
+ let Rt = qt;
4992
+ customElements.define("nsite-deploy", Rt);
4993
+ function bn() {
4994
+ if (!document.querySelector("nsite-deploy")) {
4995
+ const t = document.createElement("nsite-deploy");
4996
+ t.classList.add("nd-fixed"), document.body.appendChild(t);
4997
+ }
4998
+ }
4999
+ document.readyState === "loading" ? document.addEventListener("DOMContentLoaded", bn) : bn();