@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,546 @@
1
+ (function(){"use strict";const pr=`
2
+ :host {
3
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
4
+ }
5
+
6
+ .nd-trigger {
7
+ padding: 10px 18px;
8
+ background: #9b59b6;
9
+ color: #fff;
10
+ border: none;
11
+ border-radius: 8px;
12
+ font-size: 14px;
13
+ font-weight: 600;
14
+ cursor: pointer;
15
+ transition: background 0.2s;
16
+ }
17
+ .nd-trigger:hover { background: #8e44ad; }
18
+ .nd-trigger:disabled { opacity: 0.6; cursor: default; }
19
+ :host(.nd-fixed) .nd-trigger {
20
+ position: fixed;
21
+ bottom: 20px;
22
+ right: 20px;
23
+ z-index: 99999;
24
+ box-shadow: 0 2px 12px rgba(0,0,0,0.3);
25
+ }
26
+
27
+ .nd-overlay {
28
+ position: fixed;
29
+ inset: 0;
30
+ background: rgba(0,0,0,0.6);
31
+ display: flex;
32
+ align-items: center;
33
+ justify-content: center;
34
+ z-index: 100000;
35
+ backdrop-filter: blur(4px);
36
+ }
37
+
38
+ .nd-modal {
39
+ background: #1a1a2e;
40
+ border: 1px solid #0f3460;
41
+ border-radius: 12px;
42
+ padding: 24px;
43
+ width: 90%;
44
+ max-width: 420px;
45
+ color: #e0e0e0;
46
+ max-height: 90vh;
47
+ overflow-y: auto;
48
+ }
49
+
50
+ .nd-header {
51
+ display: flex;
52
+ justify-content: space-between;
53
+ align-items: center;
54
+ margin-bottom: 16px;
55
+ }
56
+ .nd-title {
57
+ margin: 0;
58
+ font-size: 18px;
59
+ font-weight: 700;
60
+ }
61
+ .nd-close {
62
+ background: none;
63
+ border: none;
64
+ color: #888;
65
+ font-size: 22px;
66
+ cursor: pointer;
67
+ padding: 0 0 0 8px;
68
+ line-height: 1;
69
+ }
70
+ .nd-close:hover { color: #e0e0e0; }
71
+
72
+ /* Auth section */
73
+ .nd-auth-option {
74
+ margin-bottom: 16px;
75
+ }
76
+ .nd-auth-option:last-child {
77
+ margin-bottom: 0;
78
+ }
79
+
80
+ .nd-divider {
81
+ display: flex;
82
+ align-items: center;
83
+ gap: 12px;
84
+ margin: 16px 0;
85
+ font-size: 12px;
86
+ color: #555;
87
+ text-transform: uppercase;
88
+ letter-spacing: 0.05em;
89
+ }
90
+ .nd-divider::before, .nd-divider::after {
91
+ content: '';
92
+ flex: 1;
93
+ height: 1px;
94
+ background: #0f3460;
95
+ }
96
+
97
+ .nd-btn-ext {
98
+ width: 100%;
99
+ padding: 12px;
100
+ background: #9b59b6;
101
+ color: #fff;
102
+ border: none;
103
+ border-radius: 8px;
104
+ font-size: 14px;
105
+ font-weight: 600;
106
+ cursor: pointer;
107
+ transition: background 0.2s;
108
+ }
109
+ .nd-btn-ext:hover { background: #8e44ad; }
110
+
111
+ .nd-bunker-row {
112
+ display: flex;
113
+ gap: 8px;
114
+ }
115
+ .nd-bunker-row input {
116
+ flex: 1;
117
+ padding: 8px 12px;
118
+ background: #16213e;
119
+ border: 1px solid #0f3460;
120
+ border-radius: 6px;
121
+ color: #e0e0e0;
122
+ font-size: 13px;
123
+ font-family: inherit;
124
+ box-sizing: border-box;
125
+ min-width: 0;
126
+ }
127
+ .nd-bunker-row input:focus {
128
+ outline: none;
129
+ border-color: #9b59b6;
130
+ }
131
+ .nd-bunker-row button {
132
+ padding: 8px 14px;
133
+ background: #16213e;
134
+ border: 1px solid #0f3460;
135
+ border-radius: 6px;
136
+ color: #e0e0e0;
137
+ font-size: 13px;
138
+ font-weight: 600;
139
+ cursor: pointer;
140
+ white-space: nowrap;
141
+ }
142
+ .nd-bunker-row button:hover { background: #0f3460; }
143
+
144
+ .nd-qr-wrap {
145
+ display: flex;
146
+ flex-direction: column;
147
+ align-items: center;
148
+ gap: 10px;
149
+ }
150
+ .nd-qr-label {
151
+ font-size: 12px;
152
+ color: #888;
153
+ }
154
+ .nd-qr-code {
155
+ background: #fff;
156
+ border-radius: 8px;
157
+ padding: 12px;
158
+ display: inline-flex;
159
+ }
160
+ .nd-qr-code svg {
161
+ display: block;
162
+ width: 200px;
163
+ height: 200px;
164
+ }
165
+ .nd-relay-row {
166
+ display: flex;
167
+ gap: 0;
168
+ width: 100%;
169
+ max-width: 300px;
170
+ }
171
+ .nd-relay-row label {
172
+ padding: 6px 10px;
173
+ background: #0f3460;
174
+ border: 1px solid #0f3460;
175
+ border-right: none;
176
+ border-radius: 4px 0 0 4px;
177
+ color: #888;
178
+ font-size: 11px;
179
+ white-space: nowrap;
180
+ display: flex;
181
+ align-items: center;
182
+ }
183
+ .nd-relay-row input {
184
+ flex: 1;
185
+ padding: 6px 8px;
186
+ background: #16213e;
187
+ border: 1px solid #0f3460;
188
+ border-radius: 0 4px 4px 0;
189
+ color: #e0e0e0;
190
+ font-size: 11px;
191
+ font-family: monospace;
192
+ min-width: 0;
193
+ box-sizing: border-box;
194
+ }
195
+ .nd-relay-row input:focus {
196
+ outline: none;
197
+ border-color: #9b59b6;
198
+ }
199
+ .nd-qr-uri {
200
+ display: flex;
201
+ gap: 6px;
202
+ width: 100%;
203
+ max-width: 300px;
204
+ }
205
+ .nd-qr-uri input {
206
+ flex: 1;
207
+ padding: 6px 8px;
208
+ background: #16213e;
209
+ border: 1px solid #0f3460;
210
+ border-radius: 4px;
211
+ color: #888;
212
+ font-size: 11px;
213
+ font-family: monospace;
214
+ min-width: 0;
215
+ box-sizing: border-box;
216
+ }
217
+ .nd-qr-uri button {
218
+ padding: 6px 10px;
219
+ background: #16213e;
220
+ border: 1px solid #0f3460;
221
+ border-radius: 4px;
222
+ color: #e0e0e0;
223
+ font-size: 11px;
224
+ cursor: pointer;
225
+ white-space: nowrap;
226
+ }
227
+ .nd-qr-uri button:hover { background: #0f3460; }
228
+
229
+ /* Toggle */
230
+ .nd-toggle {
231
+ display: flex;
232
+ margin-bottom: 16px;
233
+ background: #16213e;
234
+ border-radius: 6px;
235
+ padding: 3px;
236
+ }
237
+ .nd-toggle-btn {
238
+ flex: 1;
239
+ padding: 8px;
240
+ background: transparent;
241
+ border: none;
242
+ border-radius: 4px;
243
+ color: #888;
244
+ font-size: 13px;
245
+ font-weight: 600;
246
+ cursor: pointer;
247
+ transition: all 0.2s;
248
+ }
249
+ .nd-toggle-btn.active {
250
+ background: #9b59b6;
251
+ color: #fff;
252
+ }
253
+
254
+ /* Warning */
255
+ .nd-warn {
256
+ background: rgba(231, 76, 60, 0.1);
257
+ border: 1px solid rgba(231, 76, 60, 0.3);
258
+ border-radius: 6px;
259
+ padding: 12px;
260
+ font-size: 13px;
261
+ color: #e74c3c;
262
+ line-height: 1.5;
263
+ }
264
+ .nd-btn-warn {
265
+ background: #e74c3c;
266
+ color: #fff;
267
+ }
268
+ .nd-btn-warn:hover { background: #c0392b; }
269
+
270
+ .nd-root-hint {
271
+ font-size: 13px;
272
+ color: #888;
273
+ margin-bottom: 12px;
274
+ word-break: break-all;
275
+ }
276
+ .nd-root-hint strong {
277
+ color: #e0e0e0;
278
+ }
279
+
280
+ /* Form fields */
281
+ .nd-field {
282
+ margin-bottom: 12px;
283
+ }
284
+ .nd-field label {
285
+ display: block;
286
+ font-size: 11px;
287
+ color: #888;
288
+ margin-bottom: 4px;
289
+ text-transform: uppercase;
290
+ letter-spacing: 0.05em;
291
+ }
292
+ .nd-field input, .nd-field textarea {
293
+ width: 100%;
294
+ padding: 8px 12px;
295
+ background: #16213e;
296
+ border: 1px solid #0f3460;
297
+ border-radius: 6px;
298
+ color: #e0e0e0;
299
+ font-size: 14px;
300
+ font-family: inherit;
301
+ box-sizing: border-box;
302
+ }
303
+ .nd-field input:focus, .nd-field textarea:focus {
304
+ outline: none;
305
+ border-color: #9b59b6;
306
+ }
307
+ .nd-field textarea {
308
+ resize: vertical;
309
+ min-height: 60px;
310
+ }
311
+ .nd-hint {
312
+ font-size: 11px;
313
+ color: #888;
314
+ margin-top: 3px;
315
+ }
316
+ .nd-field-error {
317
+ font-size: 11px;
318
+ color: #e74c3c;
319
+ margin-top: 3px;
320
+ }
321
+
322
+ /* Actions */
323
+ .nd-actions {
324
+ display: flex;
325
+ gap: 8px;
326
+ margin-top: 16px;
327
+ }
328
+ .nd-btn {
329
+ flex: 1;
330
+ padding: 10px;
331
+ border: none;
332
+ border-radius: 6px;
333
+ font-size: 14px;
334
+ font-weight: 600;
335
+ cursor: pointer;
336
+ transition: background 0.2s;
337
+ }
338
+ .nd-btn-primary {
339
+ background: #9b59b6;
340
+ color: #fff;
341
+ }
342
+ .nd-btn-primary:hover { background: #8e44ad; }
343
+ .nd-btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
344
+ .nd-btn-secondary {
345
+ background: #16213e;
346
+ color: #e0e0e0;
347
+ border: 1px solid #0f3460;
348
+ }
349
+ .nd-btn-secondary:hover { background: #0f3460; }
350
+
351
+ /* Status */
352
+ .nd-status {
353
+ margin-top: 12px;
354
+ font-size: 13px;
355
+ color: #888;
356
+ }
357
+ .nd-status-ok { color: #2ecc71; }
358
+ .nd-status-err { color: #e74c3c; }
359
+
360
+ .nd-link {
361
+ display: block;
362
+ margin-top: 12px;
363
+ padding: 10px;
364
+ background: #16213e;
365
+ border: 1px solid #0f3460;
366
+ border-radius: 6px;
367
+ color: #9b59b6;
368
+ text-decoration: none;
369
+ text-align: center;
370
+ font-size: 13px;
371
+ word-break: break-all;
372
+ }
373
+ .nd-link:hover { background: #0f3460; }
374
+
375
+ .nd-msg {
376
+ text-align: center;
377
+ padding: 20px 0;
378
+ font-size: 14px;
379
+ color: #888;
380
+ }
381
+
382
+ /* Paper trail */
383
+ .nd-trail {
384
+ margin-top: 8px;
385
+ text-align: center;
386
+ }
387
+ .nd-trail-toggle {
388
+ background: none;
389
+ border: none;
390
+ color: #888;
391
+ font-size: 12px;
392
+ cursor: pointer;
393
+ padding: 4px 8px;
394
+ transition: color 0.2s;
395
+ }
396
+ .nd-trail-toggle:hover { color: #e0e0e0; }
397
+ .nd-trail-list {
398
+ margin-top: 6px;
399
+ text-align: left;
400
+ font-size: 12px;
401
+ color: #888;
402
+ max-height: 200px;
403
+ overflow-y: auto;
404
+ }
405
+ .nd-trail-item {
406
+ padding: 3px 0;
407
+ font-family: monospace;
408
+ font-size: 11px;
409
+ display: flex;
410
+ gap: 6px;
411
+ }
412
+ .nd-trail-idx {
413
+ color: #555;
414
+ min-width: 24px;
415
+ text-align: right;
416
+ }
417
+ .nd-trail-pk {
418
+ color: #9b59b6;
419
+ }
420
+ .nd-trail-gap {
421
+ padding: 3px 0;
422
+ color: #555;
423
+ font-style: italic;
424
+ }
425
+
426
+ @keyframes nd-spin {
427
+ to { transform: rotate(360deg); }
428
+ }
429
+ .nd-spinner {
430
+ display: inline-block;
431
+ width: 18px;
432
+ height: 18px;
433
+ border: 2px solid #555;
434
+ border-top-color: #9b59b6;
435
+ border-radius: 50%;
436
+ animation: nd-spin 0.8s linear infinite;
437
+ vertical-align: middle;
438
+ margin-right: 8px;
439
+ }
440
+ `;function ot(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function be(t,e=""){if(!Number.isSafeInteger(t)||t<0){const r=e&&`"${e}" `;throw new Error(`${r}expected integer >= 0, got ${t}`)}}function G(t,e,r=""){const n=ot(t),i=t?.length,s=e!==void 0;if(!n||s&&i!==e){const o=r&&`"${r}" `,a=s?` of length ${e}`:"",u=n?`length=${i}`:`type=${typeof t}`;throw new Error(o+"expected Uint8Array"+a+", got "+u)}return t}function Ue(t){if(typeof t!="function"||typeof t.create!="function")throw new Error("Hash must wrapped by utils.createHasher");be(t.outputLen),be(t.blockLen)}function He(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}function br(t,e){G(t,void 0,"digestInto() output");const r=e.outputLen;if(t.length<r)throw new Error('"digestInto() output" expected to be of length >='+r)}function Ce(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function at(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function de(t,e){return t<<32-e|t>>>e}const Ut=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",yr=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function ae(t){if(G(t),Ut)return t.toHex();let e="";for(let r=0;r<t.length;r++)e+=yr[t[r]];return e}const ge={_0:48,_9:57,A:65,F:70,a:97,f:102};function Ht(t){if(t>=ge._0&&t<=ge._9)return t-ge._0;if(t>=ge.A&&t<=ge.F)return t-(ge.A-10);if(t>=ge.a&&t<=ge.f)return t-(ge.a-10)}function ie(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);if(Ut)return Uint8Array.fromHex(t);const e=t.length,r=e/2;if(e%2)throw new Error("hex string expected, got unpadded hex of length "+e);const n=new Uint8Array(r);for(let i=0,s=0;i<r;i++,s+=2){const o=Ht(t.charCodeAt(s)),a=Ht(t.charCodeAt(s+1));if(o===void 0||a===void 0){const u=t[s]+t[s+1];throw new Error('hex string expected, got non-hex character "'+u+'" at index '+s)}n[i]=o*16+a}return n}function oe(...t){let e=0;for(let n=0;n<t.length;n++){const i=t[n];G(i),e+=i.length}const r=new Uint8Array(e);for(let n=0,i=0;n<t.length;n++){const s=t[n];r.set(s,i),i+=s.length}return r}function wr(t,e={}){const r=(i,s)=>t(s).update(i).digest(),n=t(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.create=i=>t(i),Object.assign(r,e),Object.freeze(r)}function Le(t=32){const e=typeof globalThis=="object"?globalThis.crypto:null;if(typeof e?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");return e.getRandomValues(new Uint8Array(t))}const vr=t=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,t])});function ct(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function mr(t){if(!ct(t))throw new Error("Uint8Array expected")}function Kt(t,e){return Array.isArray(e)?e.length===0?!0:t?e.every(r=>typeof r=="string"):e.every(r=>Number.isSafeInteger(r)):!1}function xr(t){if(typeof t!="function")throw new Error("function expected");return!0}function Ee(t,e){if(typeof e!="string")throw new Error(`${t}: string expected`);return!0}function ut(t){if(!Number.isSafeInteger(t))throw new Error(`invalid integer: ${t}`)}function lt(t){if(!Array.isArray(t))throw new Error("array expected")}function Ke(t,e){if(!Kt(!0,e))throw new Error(`${t}: array of strings expected`)}function Ft(t,e){if(!Kt(!1,e))throw new Error(`${t}: array of numbers expected`)}function Vt(...t){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);return{encode:n,decode:i}}function Zt(t){const e=typeof t=="string"?t.split(""):t,r=e.length;Ke("alphabet",e);const n=new Map(e.map((i,s)=>[i,s]));return{encode:i=>(lt(i),i.map(s=>{if(!Number.isSafeInteger(s)||s<0||s>=r)throw new Error(`alphabet.encode: digit index outside alphabet "${s}". Allowed: ${t}`);return e[s]})),decode:i=>(lt(i),i.map(s=>{Ee("alphabet.decode",s);const o=n.get(s);if(o===void 0)throw new Error(`Unknown letter: "${s}". Allowed: ${t}`);return o}))}}function jt(t=""){return Ee("join",t),{encode:e=>(Ke("join.decode",e),e.join(t)),decode:e=>(Ee("join.decode",e),e.split(t))}}function Er(t,e="="){return ut(t),Ee("padding",e),{encode(r){for(Ke("padding.encode",r);r.length*t%8;)r.push(e);return r},decode(r){Ke("padding.decode",r);let n=r.length;if(n*t%8)throw new Error("padding: invalid, string should have whole number of bytes");for(;n>0&&r[n-1]===e;n--)if((n-1)*t%8===0)throw new Error("padding: invalid, string has too much padding");return r.slice(0,n)}}}const zt=(t,e)=>e===0?t:zt(e,t%e),Fe=(t,e)=>t+(e-zt(t,e)),Ve=(()=>{let t=[];for(let e=0;e<40;e++)t.push(2**e);return t})();function ft(t,e,r,n){if(lt(t),e<=0||e>32)throw new Error(`convertRadix2: wrong from=${e}`);if(r<=0||r>32)throw new Error(`convertRadix2: wrong to=${r}`);if(Fe(e,r)>32)throw new Error(`convertRadix2: carry overflow from=${e} to=${r} carryBits=${Fe(e,r)}`);let i=0,s=0;const o=Ve[e],a=Ve[r]-1,u=[];for(const w of t){if(ut(w),w>=o)throw new Error(`convertRadix2: invalid data word=${w} from=${e}`);if(i=i<<e|w,s+e>32)throw new Error(`convertRadix2: carry overflow pos=${s} from=${e}`);for(s+=e;s>=r;s-=r)u.push((i>>s-r&a)>>>0);const T=Ve[s];if(T===void 0)throw new Error("invalid carry");i&=T-1}if(i=i<<r-s&a,!n&&s>=e)throw new Error("Excess padding");if(!n&&i>0)throw new Error(`Non-zero padding: ${i}`);return n&&s>0&&u.push(i>>>0),u}function Wt(t,e=!1){if(ut(t),t<=0||t>32)throw new Error("radix2: bits should be in (0..32]");if(Fe(8,t)>32||Fe(t,8)>32)throw new Error("radix2: carry overflow");return{encode:r=>{if(!ct(r))throw new Error("radix2.encode input should be Uint8Array");return ft(Array.from(r),8,t,!e)},decode:r=>(Ft("radix2.decode",r),Uint8Array.from(ft(r,t,8,e)))}}function Yt(t){return xr(t),function(...e){try{return t.apply(null,e)}catch{}}}const kr=typeof Uint8Array.from([]).toBase64=="function"&&typeof Uint8Array.fromBase64=="function",Ar=(t,e)=>{Ee("base64",t);const r=/^[A-Za-z0-9=+/]+$/,n="base64";if(t.length>0&&!r.test(t))throw new Error("invalid base64");return Uint8Array.fromBase64(t,{alphabet:n,lastChunkHandling:"strict"})},Jt=kr?{encode(t){return mr(t),t.toBase64()},decode(t){return Ar(t)}}:Vt(Wt(6),Zt("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),Er(6),jt("")),dt=Vt(Zt("qpzry9x8gf2tvdw0s3jn54khce6mua7l"),jt("")),Gt=[996825010,642813549,513874426,1027748829,705979059];function Oe(t){const e=t>>25;let r=(t&33554431)<<5;for(let n=0;n<Gt.length;n++)(e>>n&1)===1&&(r^=Gt[n]);return r}function Xt(t,e,r=1){const n=t.length;let i=1;for(let s=0;s<n;s++){const o=t.charCodeAt(s);if(o<33||o>126)throw new Error(`Invalid prefix (${t})`);i=Oe(i)^o>>5}i=Oe(i);for(let s=0;s<n;s++)i=Oe(i)^t.charCodeAt(s)&31;for(let s of e)i=Oe(i)^s;for(let s=0;s<6;s++)i=Oe(i);return i^=r,dt.encode(ft([i%Ve[30]],30,5,!1))}function Sr(t){const e=t==="bech32"?1:734539939,r=Wt(5),n=r.decode,i=r.encode,s=Yt(n);function o(R,_,k=90){Ee("bech32.encode prefix",R),ct(_)&&(_=Array.from(_)),Ft("bech32.encode",_);const P=R.length;if(P===0)throw new TypeError(`Invalid prefix length ${P}`);const q=P+7+_.length;if(k!==!1&&q>k)throw new TypeError(`Length ${q} exceeds limit ${k}`);const U=R.toLowerCase(),H=Xt(U,_,e);return`${U}1${dt.encode(_)}${H}`}function a(R,_=90){Ee("bech32.decode input",R);const k=R.length;if(k<8||_!==!1&&k>_)throw new TypeError(`invalid string length: ${k} (${R}). Expected (8..${_})`);const P=R.toLowerCase();if(R!==P&&R!==R.toUpperCase())throw new Error("String must be lowercase or uppercase");const q=P.lastIndexOf("1");if(q===0||q===-1)throw new Error('Letter "1" must be present between prefix and data only');const U=P.slice(0,q),H=P.slice(q+1);if(H.length<6)throw new Error("Data must be at least 6 characters long");const W=dt.decode(H).slice(0,-6),ne=Xt(U,W,e);if(!H.endsWith(ne))throw new Error(`Invalid checksum in ${R}: expected "${ne}"`);return{prefix:U,words:W}}const u=Yt(a);function w(R){const{prefix:_,words:k}=a(R,!1);return{prefix:_,words:k,bytes:n(k)}}function T(R,_){return o(R,i(_))}return{encode:o,decode:a,encodeFromBytes:T,decodeToBytes:w,decodeUnsafe:u,fromWords:n,fromWordsUnsafe:s,toWords:i}}const Qt=Sr("bech32");new TextDecoder("utf-8"),new TextEncoder;var Br=5e3;function en(t){return _r("npub",ie(t))}function Rr(t,e){let r=Qt.toWords(e);return Qt.encode(t,r,Br)}function _r(t,e){return Rr(t,e)}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}$/;function Lr(t){return BigInt("0x"+t).toString(36).padStart(Ze,"0")}function Or(t){let e=0n;for(const r of t)e=e*36n+BigInt(parseInt(r,36));return e.toString(16).padStart(64,"0")}function Ir(t){if(!t.startsWith("npub1"))return null;const e="qpzry9x8gf2tvdw0s3jn54khce6mua7l",r=[];for(const a of t.slice(5)){const u=e.indexOf(a);if(u===-1)return null;r.push(u)}const n=r.slice(0,-6);let i=0,s=0;const o=[];for(const a of n)for(i=i<<5|a,s+=5;s>=8;)s-=8,o.push(i>>s&255);return o.length!==32?null:o.map(a=>a.toString(16).padStart(2,"0")).join("")}function Pr(){const t=window.location.hostname.split(".");for(let r=0;r<t.length;r++)if(t[r].startsWith("npub1")&&t[r].length>=63){const n=Ir(t[r]);if(n)return{pubkey:n,baseDomain:t.slice(r+1).join(".")}}const e=t[0];if(e&&e.length>Ze&&e.length<=63&&Cr.test(e)&&!e.endsWith("-"))try{return{pubkey:Or(e.slice(0,Ze)),identifier:e.slice(Ze),baseDomain:t.slice(1).join(".")}}catch{}return null}function Mr(t){return Tr.test(t)&&!t.endsWith("-")}function tn(t,e,r,n=5e3){return new Promise(i=>{try{const s=new WebSocket(t),o=setTimeout(()=>{try{s.close()}catch{}i()},n),a=()=>{clearTimeout(o);try{s.close()}catch{}i()};s.onopen=()=>s.send(JSON.stringify(e)),s.onmessage=u=>{try{r(JSON.parse(u.data))&&a()}catch{}},s.onerror=()=>a()}catch{i()}})}async function Pe(t,e){const r=new Map,n=Math.random().toString(36).slice(2,8);return await Promise.allSettled(t.map(i=>tn(i,["REQ",n,e],s=>(s[0]==="EVENT"&&s[1]===n&&r.set(s[2].id,s[2]),s[0]==="EOSE"&&s[1]===n)))),[...r.values()]}async function Nr(t,e){let r=!1;return await tn(t,["EVENT",e],n=>n[0]==="OK"?(r=n[2]===!0,!0):!1),r}async function $r(t,e){return(await Promise.allSettled(t.map(n=>Nr(n,e)))).filter(n=>n.status==="fulfilled"&&n.value).length}function nn(t){const e=new Set;for(const r of t)for(const n of r.tags)n[0]==="r"&&n[1]?.startsWith("wss://")&&(!n[2]||n[2]==="write")&&e.add(n[1].trim());return[...e]}async function rn(t){const e=t.identifier?{kinds:[35128],authors:[t.pubkey],"#d":[t.identifier]}:{kinds:[15128],authors:[t.pubkey],limit:1},[r,n]=await Promise.all([Pe(Ie,e),Pe(Ie,{kinds:[10002],authors:[t.pubkey],limit:5})]);if(r.length>0)return r.sort((o,a)=>a.created_at-o.created_at)[0];const i=nn(n).filter(o=>!Ie.includes(o));return i.length===0?null:(await Pe(i,e)).sort((o,a)=>a.created_at-o.created_at)[0]??null}async function sn(t){const e=await Pe(Ie,{kinds:[10002],authors:[t],limit:5}),r=nn(e);return r.length>0?r:Ie.filter(n=>n!=="wss://purplepag.es")}async function on(t,e,r){return(await Pe(t,r?{kinds:[35128],authors:[e],"#d":[r],limit:1}:{kinds:[15128],authors:[e],limit:1})).length>0}const an=9;function Dr(t){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)}function qr(t,e){const r=[];e.slug&&r.push(["d",e.slug]);for(const a of t.tags)(a[0]==="path"||a[0]==="server")&&r.push([...a]);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];if(o.length>an){const a=o[0],u=o.slice(o.length-(an-1));r.push(a,...u)}else for(const a of o)r.push(a);return e.title&&r.push(["title",e.title]),e.description&&r.push(["description",e.description]),{kind:e.slug?35128:15128,created_at:Math.floor(Date.now()/1e3),tags:r,content:""}}function Ur(t,e,r){return r?`https://${Lr(e)}${r}.${t}`:`https://${en(e)}.${t}`}function Hr(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var ht={exports:{}},cn;function Kr(){return cn||(cn=1,(function(t,e){var r=(function(){var n=function(M,L){var x=236,B=17,g=M,E=s[L],h=null,c=0,d=null,f=[],l={},v=function(y,b){c=g*4+17,h=(function(p){for(var m=new Array(p),S=0;S<p;S+=1){m[S]=new Array(p);for(var N=0;N<p;N+=1)m[S][N]=null}return m})(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)),z(d,b)},A=function(y,b){for(var p=-1;p<=7;p+=1)if(!(y+p<=-1||c<=y+p))for(var m=-1;m<=7;m+=1)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)},C=function(){for(var y=0,b=0,p=0;p<8;p+=1){v(!0,p);var m=a.getLostPoint(l);(p==0||y>m)&&(y=m,b=p)}return b},I=function(){for(var y=8;y<c-8;y+=1)h[y][6]==null&&(h[y][6]=y%2==0);for(var b=8;b<c-8;b+=1)h[6][b]==null&&(h[6][b]=b%2==0)},O=function(){for(var y=a.getPatternPosition(g),b=0;b<y.length;b+=1)for(var p=0;p<y.length;p+=1){var m=y[b],S=y[p];if(h[m][S]==null)for(var N=-2;N<=2;N+=1)for(var F=-2;F<=2;F+=1)N==-2||N==2||F==-2||F==2||N==0&&F==0?h[m+N][S+F]=!0:h[m+N][S+F]=!1}},$=function(y){for(var b=a.getBCHTypeNumber(g),p=0;p<18;p+=1){var m=!y&&(b>>p&1)==1;h[Math.floor(p/3)][p%3+c-8-3]=m}for(var p=0;p<18;p+=1){var m=!y&&(b>>p&1)==1;h[p%3+c-8-3][Math.floor(p/3)]=m}},D=function(y,b){for(var p=E<<3|b,m=a.getBCHTypeInfo(p),S=0;S<15;S+=1){var N=!y&&(m>>S&1)==1;S<6?h[S][8]=N:S<8?h[S+1][8]=N:h[c-15+S][8]=N}for(var S=0;S<15;S+=1){var N=!y&&(m>>S&1)==1;S<8?h[8][c-S-1]=N:S<9?h[8][15-S-1+1]=N:h[8][15-S-1]=N}h[c-8][8]=!y},z=function(y,b){for(var p=-1,m=c-1,S=7,N=0,F=a.getMaskFunction(b),K=c-1;K>0;K-=2)for(K==6&&(K-=1);;){for(var X=0;X<2;X+=1)if(h[m][K-X]==null){var te=!1;N<y.length&&(te=(y[N]>>>S&1)==1);var V=F(m,K-X);V&&(te=!te),h[m][K-X]=te,S-=1,S==-1&&(N+=1,S=7)}if(m+=p,m<0||c<=m){m-=p,p=-p;break}}},Y=function(y,b){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){var X=b[K].dataCount,te=b[K].totalCount-X;m=Math.max(m,X),S=Math.max(S,te),N[K]=new Array(X);for(var V=0;V<N[K].length;V+=1)N[K][V]=255&y.getBuffer()[V+p];p+=X;var ue=a.getErrorCorrectPolynomial(te),le=w(N[K],ue.getLength()-1),dr=le.mod(ue);F[K]=new Array(ue.getLength()-1);for(var V=0;V<F[K].length;V+=1){var hr=V+dr.getLength()-F[K].length;F[K][V]=hr>=0?dr.getAt(hr):0}}for(var gr=0,V=0;V<b.length;V+=1)gr+=b[V].totalCount;for(var qt=new Array(gr),st=0,V=0;V<m;V+=1)for(var K=0;K<b.length;K+=1)V<N[K].length&&(qt[st]=N[K][V],st+=1);for(var V=0;V<S;V+=1)for(var K=0;K<b.length;K+=1)V<F[K].length&&(qt[st]=F[K][V],st+=1);return qt},Z=function(y,b,p){for(var m=T.getRSBlocks(y,b),S=R(),N=0;N<p.length;N+=1){var F=p[N];S.put(F.getMode(),4),S.put(F.getLength(),a.getLengthInBits(F.getMode(),y)),F.write(S)}for(var K=0,N=0;N<m.length;N+=1)K+=m[N].dataCount;if(S.getLengthInBits()>K*8)throw"code length overflow. ("+S.getLengthInBits()+">"+K*8+")";for(S.getLengthInBits()+4<=K*8&&S.put(0,4);S.getLengthInBits()%8!=0;)S.putBit(!1);for(;!(S.getLengthInBits()>=K*8||(S.put(x,8),S.getLengthInBits()>=K*8));)S.put(B,8);return Y(S,m)};l.addData=function(y,b){b=b||"Byte";var p=null;switch(b){case"Numeric":p=_(y);break;case"Alphanumeric":p=k(y);break;case"Byte":p=P(y);break;case"Kanji":p=q(y);break;default:throw"mode:"+b}f.push(p),d=null},l.isDark=function(y,b){if(y<0||c<=y||b<0||c<=b)throw y+","+b;return h[y][b]},l.getModuleCount=function(){return c},l.make=function(){if(g<1){for(var y=1;y<40;y++){for(var b=T.getRSBlocks(y,E),p=R(),m=0;m<f.length;m++){var S=f[m];p.put(S.getMode(),4),p.put(S.getLength(),a.getLengthInBits(S.getMode(),y)),S.write(p)}for(var N=0,m=0;m<b.length;m++)N+=b[m].dataCount;if(p.getLengthInBits()<=N*8)break}g=y}v(!1,C())},l.createTableTag=function(y,b){y=y||2,b=typeof b>"u"?y*4:b;var p="";p+='<table style="',p+=" border-width: 0px; border-style: none;",p+=" border-collapse: collapse;",p+=" padding: 0px; margin: "+b+"px;",p+='">',p+="<tbody>";for(var m=0;m<l.getModuleCount();m+=1){p+="<tr>";for(var S=0;S<l.getModuleCount();S+=1)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+='"/>';p+="</tr>"}return p+="</tbody>",p+="</table>",p},l.createSvgTag=function(y,b,p,m){var S={};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;var N=l.getModuleCount()*y+b*2,F,K,X,te,V="",ue;for(ue="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)for(te=X*y+b,F=0;F<l.getModuleCount();F+=1)l.isDark(X,F)&&(K=F*y+b,V+="M"+K+","+te+ue);return V+='" stroke="transparent" fill="black"/>',V+="</svg>",V},l.createDataURL=function(y,b){y=y||2,b=typeof b>"u"?y*4:b;var p=l.getModuleCount()*y+b*2,m=b,S=p-b;return Q(p,p,function(N,F){if(m<=N&&N<S&&m<=F&&F<S){var K=Math.floor((N-m)/y),X=Math.floor((F-m)/y);return l.isDark(X,K)?0:1}else return 1})},l.createImgTag=function(y,b,p){y=y||2,b=typeof b>"u"?y*4:b;var m=l.getModuleCount()*y+b*2,S="";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};var J=function(y){for(var b="",p=0;p<y.length;p+=1){var m=y.charAt(p);switch(m){case"<":b+="&lt;";break;case">":b+="&gt;";break;case"&":b+="&amp;";break;case'"':b+="&quot;";break;default:b+=m;break}}return b},ee=function(y){var b=1;y=typeof y>"u"?b*2:y;var p=l.getModuleCount()*b+y*2,m=y,S=p-y,N,F,K,X,te,V={"██":"█","█ ":"▀"," █":"▄"," ":" "},ue={"██":"▀","█ ":"▀"," █":" "," ":" "},le="";for(N=0;N<p;N+=2){for(K=Math.floor((N-m)/b),X=Math.floor((N+1-m)/b),F=0;F<p;F+=1)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+="█",le+=y<1&&N+1>=S?ue[te]:V[te];le+=`
441
+ `}return p%2&&y>0?le.substring(0,le.length-p-1)+Array(p+1).join("▀"):le.substring(0,le.length-1)};return l.createASCII=function(y,b){if(y=y||1,y<2)return ee(b);y-=1,b=typeof b>"u"?y*2:b;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(" "),ue="",le="";for(N=0;N<p;N+=1){for(K=Math.floor((N-m)/y),le="",F=0;F<p;F+=1)X=1,m<=F&&F<S&&m<=N&&N<S&&l.isDark(K,Math.floor((F-m)/y))&&(X=0),le+=X?te:V;for(K=0;K<y;K+=1)ue+=le+`
442
+ `}return ue.substring(0,ue.length-1)},l.renderTo2dContext=function(y,b){b=b||2;for(var p=l.getModuleCount(),m=0;m<p;m++)for(var S=0;S<p;S++)y.fillStyle=l.isDark(m,S)?"black":"white",y.fillRect(m*b,S*b,b,b)},l};n.stringToBytesFuncs={default:function(M){for(var L=[],x=0;x<M.length;x+=1){var B=M.charCodeAt(x);L.push(B&255)}return L}},n.stringToBytes=n.stringToBytesFuncs.default,n.createStringToBytes=function(M,L){var x=(function(){for(var g=W(M),E=function(){var I=g.read();if(I==-1)throw"eof";return I},h=0,c={};;){var d=g.read();if(d==-1)break;var f=E(),l=E(),v=E(),A=String.fromCharCode(d<<8|f),C=l<<8|v;c[A]=C,h+=1}if(h!=L)throw h+" != "+L;return c})(),B=63;return function(g){for(var E=[],h=0;h<g.length;h+=1){var c=g.charCodeAt(h);if(c<128)E.push(c);else{var d=x[g.charAt(h)];typeof d=="number"?(d&255)==d?E.push(d):(E.push(d>>>8),E.push(d&255)):E.push(B)}}return E}};var i={MODE_NUMBER:1,MODE_ALPHA_NUM:2,MODE_8BIT_BYTE:4,MODE_KANJI:8},s={L:1,M:0,Q:3,H:2},o={PATTERN000:0,PATTERN001:1,PATTERN010:2,PATTERN011:3,PATTERN100:4,PATTERN101:5,PATTERN110:6,PATTERN111:7},a=(function(){var M=[[],[6,18],[6,22],[6,26],[6,30],[6,34],[6,22,38],[6,24,42],[6,26,46],[6,28,50],[6,30,54],[6,32,58],[6,34,62],[6,26,46,66],[6,26,48,70],[6,26,50,74],[6,30,54,78],[6,30,56,82],[6,30,58,86],[6,34,62,90],[6,28,50,72,94],[6,26,50,74,98],[6,30,54,78,102],[6,28,54,80,106],[6,32,58,84,110],[6,30,58,86,114],[6,34,62,90,118],[6,26,50,74,98,122],[6,30,54,78,102,126],[6,26,52,78,104,130],[6,30,56,82,108,134],[6,34,60,86,112,138],[6,30,58,86,114,142],[6,34,62,90,118,146],[6,30,54,78,102,126,150],[6,24,50,76,102,128,154],[6,28,54,80,106,132,158],[6,32,58,84,110,136,162],[6,26,54,82,110,138,166],[6,30,58,86,114,142,170]],L=1335,x=7973,B=21522,g={},E=function(h){for(var c=0;h!=0;)c+=1,h>>>=1;return c};return g.getBCHTypeInfo=function(h){for(var c=h<<10;E(c)-E(L)>=0;)c^=L<<E(c)-E(L);return(h<<10|c)^B},g.getBCHTypeNumber=function(h){for(var c=h<<12;E(c)-E(x)>=0;)c^=x<<E(c)-E(x);return h<<12|c},g.getPatternPosition=function(h){return M[h-1]},g.getMaskFunction=function(h){switch(h){case o.PATTERN000:return function(c,d){return(c+d)%2==0};case o.PATTERN001:return function(c,d){return c%2==0};case o.PATTERN010:return function(c,d){return d%3==0};case o.PATTERN011:return function(c,d){return(c+d)%3==0};case o.PATTERN100:return function(c,d){return(Math.floor(c/2)+Math.floor(d/3))%2==0};case o.PATTERN101:return function(c,d){return c*d%2+c*d%3==0};case o.PATTERN110:return function(c,d){return(c*d%2+c*d%3)%2==0};case o.PATTERN111:return function(c,d){return(c*d%3+(c+d)%2)%2==0};default:throw"bad maskPattern:"+h}},g.getErrorCorrectPolynomial=function(h){for(var c=w([1],0),d=0;d<h;d+=1)c=c.multiply(w([1,u.gexp(d)],0));return c},g.getLengthInBits=function(h,c){if(1<=c&&c<10)switch(h){case i.MODE_NUMBER:return 10;case i.MODE_ALPHA_NUM:return 9;case i.MODE_8BIT_BYTE:return 8;case i.MODE_KANJI:return 8;default:throw"mode:"+h}else if(c<27)switch(h){case i.MODE_NUMBER:return 12;case i.MODE_ALPHA_NUM:return 11;case i.MODE_8BIT_BYTE:return 16;case i.MODE_KANJI:return 10;default:throw"mode:"+h}else if(c<41)switch(h){case i.MODE_NUMBER:return 14;case i.MODE_ALPHA_NUM:return 13;case i.MODE_8BIT_BYTE:return 16;case i.MODE_KANJI:return 12;default:throw"mode:"+h}else throw"type:"+c},g.getLostPoint=function(h){for(var c=h.getModuleCount(),d=0,f=0;f<c;f+=1)for(var l=0;l<c;l+=1){for(var v=0,A=h.isDark(f,l),C=-1;C<=1;C+=1)if(!(f+C<0||c<=f+C))for(var I=-1;I<=1;I+=1)l+I<0||c<=l+I||C==0&&I==0||A==h.isDark(f+C,l+I)&&(v+=1);v>5&&(d+=3+v-5)}for(var f=0;f<c-1;f+=1)for(var l=0;l<c-1;l+=1){var O=0;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)}for(var f=0;f<c;f+=1)for(var l=0;l<c-6;l+=1)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);for(var l=0;l<c;l+=1)for(var f=0;f<c-6;f+=1)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);for(var $=0,l=0;l<c;l+=1)for(var f=0;f<c;f+=1)h.isDark(f,l)&&($+=1);var D=Math.abs(100*$/c/c-50)/5;return d+=D*10,d},g})(),u=(function(){for(var M=new Array(256),L=new Array(256),x=0;x<8;x+=1)M[x]=1<<x;for(var x=8;x<256;x+=1)M[x]=M[x-4]^M[x-5]^M[x-6]^M[x-8];for(var x=0;x<255;x+=1)L[M[x]]=x;var B={};return B.glog=function(g){if(g<1)throw"glog("+g+")";return L[g]},B.gexp=function(g){for(;g<0;)g+=255;for(;g>=256;)g-=255;return M[g]},B})();function w(M,L){if(typeof M.length>"u")throw M.length+"/"+L;var x=(function(){for(var g=0;g<M.length&&M[g]==0;)g+=1;for(var E=new Array(M.length-g+L),h=0;h<M.length-g;h+=1)E[h]=M[h+g];return E})(),B={};return B.getAt=function(g){return x[g]},B.getLength=function(){return x.length},B.multiply=function(g){for(var E=new Array(B.getLength()+g.getLength()-1),h=0;h<B.getLength();h+=1)for(var c=0;c<g.getLength();c+=1)E[h+c]^=u.gexp(u.glog(B.getAt(h))+u.glog(g.getAt(c)));return w(E,0)},B.mod=function(g){if(B.getLength()-g.getLength()<0)return B;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)h[c]=B.getAt(c);for(var c=0;c<g.getLength();c+=1)h[c]^=u.gexp(u.glog(g.getAt(c))+E);return w(h,0).mod(g)},B}var T=(function(){var M=[[1,26,19],[1,26,16],[1,26,13],[1,26,9],[1,44,34],[1,44,28],[1,44,22],[1,44,16],[1,70,55],[1,70,44],[2,35,17],[2,35,13],[1,100,80],[2,50,32],[2,50,24],[4,25,9],[1,134,108],[2,67,43],[2,33,15,2,34,16],[2,33,11,2,34,12],[2,86,68],[4,43,27],[4,43,19],[4,43,15],[2,98,78],[4,49,31],[2,32,14,4,33,15],[4,39,13,1,40,14],[2,121,97],[2,60,38,2,61,39],[4,40,18,2,41,19],[4,40,14,2,41,15],[2,146,116],[3,58,36,2,59,37],[4,36,16,4,37,17],[4,36,12,4,37,13],[2,86,68,2,87,69],[4,69,43,1,70,44],[6,43,19,2,44,20],[6,43,15,2,44,16],[4,101,81],[1,80,50,4,81,51],[4,50,22,4,51,23],[3,36,12,8,37,13],[2,116,92,2,117,93],[6,58,36,2,59,37],[4,46,20,6,47,21],[7,42,14,4,43,15],[4,133,107],[8,59,37,1,60,38],[8,44,20,4,45,21],[12,33,11,4,34,12],[3,145,115,1,146,116],[4,64,40,5,65,41],[11,36,16,5,37,17],[11,36,12,5,37,13],[5,109,87,1,110,88],[5,65,41,5,66,42],[5,54,24,7,55,25],[11,36,12,7,37,13],[5,122,98,1,123,99],[7,73,45,3,74,46],[15,43,19,2,44,20],[3,45,15,13,46,16],[1,135,107,5,136,108],[10,74,46,1,75,47],[1,50,22,15,51,23],[2,42,14,17,43,15],[5,150,120,1,151,121],[9,69,43,4,70,44],[17,50,22,1,51,23],[2,42,14,19,43,15],[3,141,113,4,142,114],[3,70,44,11,71,45],[17,47,21,4,48,22],[9,39,13,16,40,14],[3,135,107,5,136,108],[3,67,41,13,68,42],[15,54,24,5,55,25],[15,43,15,10,44,16],[4,144,116,4,145,117],[17,68,42],[17,50,22,6,51,23],[19,46,16,6,47,17],[2,139,111,7,140,112],[17,74,46],[7,54,24,16,55,25],[34,37,13],[4,151,121,5,152,122],[4,75,47,14,76,48],[11,54,24,14,55,25],[16,45,15,14,46,16],[6,147,117,4,148,118],[6,73,45,14,74,46],[11,54,24,16,55,25],[30,46,16,2,47,17],[8,132,106,4,133,107],[8,75,47,13,76,48],[7,54,24,22,55,25],[22,45,15,13,46,16],[10,142,114,2,143,115],[19,74,46,4,75,47],[28,50,22,6,51,23],[33,46,16,4,47,17],[8,152,122,4,153,123],[22,73,45,3,74,46],[8,53,23,26,54,24],[12,45,15,28,46,16],[3,147,117,10,148,118],[3,73,45,23,74,46],[4,54,24,31,55,25],[11,45,15,31,46,16],[7,146,116,7,147,117],[21,73,45,7,74,46],[1,53,23,37,54,24],[19,45,15,26,46,16],[5,145,115,10,146,116],[19,75,47,10,76,48],[15,54,24,25,55,25],[23,45,15,25,46,16],[13,145,115,3,146,116],[2,74,46,29,75,47],[42,54,24,1,55,25],[23,45,15,28,46,16],[17,145,115],[10,74,46,23,75,47],[10,54,24,35,55,25],[19,45,15,35,46,16],[17,145,115,1,146,116],[14,74,46,21,75,47],[29,54,24,19,55,25],[11,45,15,46,46,16],[13,145,115,6,146,116],[14,74,46,23,75,47],[44,54,24,7,55,25],[59,46,16,1,47,17],[12,151,121,7,152,122],[12,75,47,26,76,48],[39,54,24,14,55,25],[22,45,15,41,46,16],[6,151,121,14,152,122],[6,75,47,34,76,48],[46,54,24,10,55,25],[2,45,15,64,46,16],[17,152,122,4,153,123],[29,74,46,14,75,47],[49,54,24,10,55,25],[24,45,15,46,46,16],[4,152,122,18,153,123],[13,74,46,32,75,47],[48,54,24,14,55,25],[42,45,15,32,46,16],[20,147,117,4,148,118],[40,75,47,7,76,48],[43,54,24,22,55,25],[10,45,15,67,46,16],[19,148,118,6,149,119],[18,75,47,31,76,48],[34,54,24,34,55,25],[20,45,15,61,46,16]],L=function(g,E){var h={};return h.totalCount=g,h.dataCount=E,h},x={},B=function(g,E){switch(E){case s.L:return M[(g-1)*4+0];case s.M:return M[(g-1)*4+1];case s.Q:return M[(g-1)*4+2];case s.H:return M[(g-1)*4+3];default:return}};return x.getRSBlocks=function(g,E){var h=B(g,E);if(typeof h>"u")throw"bad rs block @ typeNumber:"+g+"/errorCorrectionLevel:"+E;for(var c=h.length/3,d=[],f=0;f<c;f+=1)for(var l=h[f*3+0],v=h[f*3+1],A=h[f*3+2],C=0;C<l;C+=1)d.push(L(v,A));return d},x})(),R=function(){var M=[],L=0,x={};return x.getBuffer=function(){return M},x.getAt=function(B){var g=Math.floor(B/8);return(M[g]>>>7-B%8&1)==1},x.put=function(B,g){for(var E=0;E<g;E+=1)x.putBit((B>>>g-E-1&1)==1)},x.getLengthInBits=function(){return L},x.putBit=function(B){var g=Math.floor(L/8);M.length<=g&&M.push(0),B&&(M[g]|=128>>>L%8),L+=1},x},_=function(M){var L=i.MODE_NUMBER,x=M,B={};B.getMode=function(){return L},B.getLength=function(h){return x.length},B.write=function(h){for(var c=x,d=0;d+2<c.length;)h.put(g(c.substring(d,d+3)),10),d+=3;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))};var g=function(h){for(var c=0,d=0;d<h.length;d+=1)c=c*10+E(h.charAt(d));return c},E=function(h){if("0"<=h&&h<="9")return h.charCodeAt(0)-48;throw"illegal char :"+h};return B},k=function(M){var L=i.MODE_ALPHA_NUM,x=M,B={};B.getMode=function(){return L},B.getLength=function(E){return x.length},B.write=function(E){for(var h=x,c=0;c+1<h.length;)E.put(g(h.charAt(c))*45+g(h.charAt(c+1)),11),c+=2;c<h.length&&E.put(g(h.charAt(c)),6)};var g=function(E){if("0"<=E&&E<="9")return E.charCodeAt(0)-48;if("A"<=E&&E<="Z")return E.charCodeAt(0)-65+10;switch(E){case" ":return 36;case"$":return 37;case"%":return 38;case"*":return 39;case"+":return 40;case"-":return 41;case".":return 42;case"/":return 43;case":":return 44;default:throw"illegal char :"+E}};return B},P=function(M){var L=i.MODE_8BIT_BYTE,x=n.stringToBytes(M),B={};return B.getMode=function(){return L},B.getLength=function(g){return x.length},B.write=function(g){for(var E=0;E<x.length;E+=1)g.put(x[E],8)},B},q=function(M){var L=i.MODE_KANJI,x=n.stringToBytesFuncs.SJIS;if(!x)throw"sjis not supported.";(function(E,h){var c=x(E);if(c.length!=2||(c[0]<<8|c[1])!=h)throw"sjis not supported."})("友",38726);var B=x(M),g={};return g.getMode=function(){return L},g.getLength=function(E){return~~(B.length/2)},g.write=function(E){for(var h=B,c=0;c+1<h.length;){var d=(255&h[c])<<8|255&h[c+1];if(33088<=d&&d<=40956)d-=33088;else if(57408<=d&&d<=60351)d-=49472;else throw"illegal char at "+(c+1)+"/"+d;d=(d>>>8&255)*192+(d&255),E.put(d,13),c+=2}if(c<h.length)throw"illegal char at "+(c+1)},g},U=function(){var M=[],L={};return L.writeByte=function(x){M.push(x&255)},L.writeShort=function(x){L.writeByte(x),L.writeByte(x>>>8)},L.writeBytes=function(x,B,g){B=B||0,g=g||x.length;for(var E=0;E<g;E+=1)L.writeByte(x[E+B])},L.writeString=function(x){for(var B=0;B<x.length;B+=1)L.writeByte(x.charCodeAt(B))},L.toByteArray=function(){return M},L.toString=function(){var x="";x+="[";for(var B=0;B<M.length;B+=1)B>0&&(x+=","),x+=M[B];return x+="]",x},L},H=function(){var M=0,L=0,x=0,B="",g={},E=function(c){B+=String.fromCharCode(h(c&63))},h=function(c){if(!(c<0)){if(c<26)return 65+c;if(c<52)return 97+(c-26);if(c<62)return 48+(c-52);if(c==62)return 43;if(c==63)return 47}throw"n:"+c};return g.writeByte=function(c){for(M=M<<8|c&255,L+=8,x+=1;L>=6;)E(M>>>L-6),L-=6},g.flush=function(){if(L>0&&(E(M<<6-L),M=0,L=0),x%3!=0)for(var c=3-x%3,d=0;d<c;d+=1)B+="="},g.toString=function(){return B},g},W=function(M){var L=M,x=0,B=0,g=0,E={};E.read=function(){for(;g<8;){if(x>=L.length){if(g==0)return-1;throw"unexpected end of file./"+g}var c=L.charAt(x);if(x+=1,c=="=")return g=0,-1;if(c.match(/^\s$/))continue;B=B<<6|h(c.charCodeAt(0)),g+=6}var d=B>>>g-8&255;return g-=8,d};var h=function(c){if(65<=c&&c<=90)return c-65;if(97<=c&&c<=122)return c-97+26;if(48<=c&&c<=57)return c-48+52;if(c==43)return 62;if(c==47)return 63;throw"c:"+c};return E},ne=function(M,L){var x=M,B=L,g=new Array(M*L),E={};E.setPixel=function(f,l,v){g[l*x+f]=v},E.write=function(f){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);var l=2,v=c(l);f.writeByte(l);for(var A=0;v.length-A>255;)f.writeByte(255),f.writeBytes(v,A,255),A+=255;f.writeByte(v.length-A),f.writeBytes(v,A,v.length-A),f.writeByte(0),f.writeString(";")};var h=function(f){var l=f,v=0,A=0,C={};return C.write=function(I,O){if(I>>>O)throw"length over";for(;v+O>=8;)l.writeByte(255&(I<<v|A)),O-=8-v,I>>>=8-v,A=0,v=0;A=I<<v|A,v=v+O},C.flush=function(){v>0&&l.writeByte(A)},C},c=function(f){for(var l=1<<f,v=(1<<f)+1,A=f+1,C=d(),I=0;I<l;I+=1)C.add(String.fromCharCode(I));C.add(String.fromCharCode(l)),C.add(String.fromCharCode(v));var O=U(),$=h(O);$.write(l,A);var D=0,z=String.fromCharCode(g[D]);for(D+=1;D<g.length;){var Y=String.fromCharCode(g[D]);D+=1,C.contains(z+Y)?z=z+Y:($.write(C.indexOf(z),A),C.size()<4095&&(C.size()==1<<A&&(A+=1),C.add(z+Y)),z=Y)}return $.write(C.indexOf(z),A),$.write(v,A),$.flush(),O.toByteArray()},d=function(){var f={},l=0,v={};return v.add=function(A){if(v.contains(A))throw"dup key:"+A;f[A]=l,l+=1},v.size=function(){return l},v.indexOf=function(A){return f[A]},v.contains=function(A){return typeof f[A]<"u"},v};return E},Q=function(M,L,x){for(var B=ne(M,L),g=0;g<L;g+=1)for(var E=0;E<M;E+=1)B.setPixel(E,g,x(E,g));var h=U();B.write(h);for(var c=H(),d=h.toByteArray(),f=0;f<d.length;f+=1)c.writeByte(d[f]);return c.flush(),"data:image/gif;base64,"+c};return n})();(function(){r.stringToBytesFuncs["UTF-8"]=function(n){function i(s){for(var o=[],a=0;a<s.length;a++){var u=s.charCodeAt(a);u<128?o.push(u):u<2048?o.push(192|u>>6,128|u&63):u<55296||u>=57344?o.push(224|u>>12,128|u>>6&63,128|u&63):(a++,u=65536+((u&1023)<<10|s.charCodeAt(a)&1023),o.push(240|u>>18,128|u>>12&63,128|u>>6&63,128|u&63))}return o}return i(n)}})(),(function(n){t.exports=n()})(function(){return r})})(ht)),ht.exports}var Fr=Kr();const Vr=Hr(Fr);function Zr(t){const e=Vr(0,"L");return e.addData(t),e.make(),e.createSvgTag({cellSize:3,margin:2,scalable:!0})}function jr(t,e,r){return t&e^~t&r}function zr(t,e,r){return t&e^t&r^e&r}class Wr{blockLen;outputLen;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(e,r,n,i){this.blockLen=e,this.outputLen=r,this.padOffset=n,this.isLE=i,this.buffer=new Uint8Array(e),this.view=at(this.buffer)}update(e){He(this),G(e);const{view:r,buffer:n,blockLen:i}=this,s=e.length;for(let o=0;o<s;){const a=Math.min(i-this.pos,s-o);if(a===i){const u=at(e);for(;i<=s-o;o+=i)this.process(u,o);continue}n.set(e.subarray(o,o+a),this.pos),this.pos+=a,o+=a,this.pos===i&&(this.process(r,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){He(this),br(e,this),this.finished=!0;const{buffer:r,view:n,blockLen:i,isLE:s}=this;let{pos:o}=this;r[o++]=128,Ce(this.buffer.subarray(o)),this.padOffset>i-o&&(this.process(n,0),o=0);for(let R=o;R<i;R++)r[R]=0;n.setBigUint64(i-8,BigInt(this.length*8),s),this.process(n,0);const a=at(e),u=this.outputLen;if(u%4)throw new Error("_sha2: outputLen must be aligned to 32bit");const w=u/4,T=this.get();if(w>T.length)throw new Error("_sha2: outputLen bigger than state");for(let R=0;R<w;R++)a.setUint32(4*R,T[R],s)}digest(){const{buffer:e,outputLen:r}=this;this.digestInto(e);const n=e.slice(0,r);return this.destroy(),n}_cloneInto(e){e||=new this.constructor,e.set(...this.get());const{blockLen:r,buffer:n,length:i,finished:s,destroyed:o,pos:a}=this;return e.destroyed=o,e.finished=s,e.length=i,e.pos=a,i%r&&e.buffer.set(n),e}clone(){return this._cloneInto()}}const ye=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Yr=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),we=new Uint32Array(64);class Jr extends Wr{constructor(e){super(64,e,8,!1)}get(){const{A:e,B:r,C:n,D:i,E:s,F:o,G:a,H:u}=this;return[e,r,n,i,s,o,a,u]}set(e,r,n,i,s,o,a,u){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}process(e,r){for(let R=0;R<16;R++,r+=4)we[R]=e.getUint32(r,!1);for(let R=16;R<64;R++){const _=we[R-15],k=we[R-2],P=de(_,7)^de(_,18)^_>>>3,q=de(k,17)^de(k,19)^k>>>10;we[R]=q+we[R-7]+P+we[R-16]|0}let{A:n,B:i,C:s,D:o,E:a,F:u,G:w,H:T}=this;for(let R=0;R<64;R++){const _=de(a,6)^de(a,11)^de(a,25),k=T+_+jr(a,u,w)+Yr[R]+we[R]|0,q=(de(n,2)^de(n,13)^de(n,22))+zr(n,i,s)|0;T=w,w=u,u=a,a=o+k|0,o=s,s=i,i=n,n=k+q|0}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)}roundClean(){Ce(we)}destroy(){this.set(0,0,0,0,0,0,0,0),Ce(this.buffer)}}class Gr extends Jr{A=ye[0]|0;B=ye[1]|0;C=ye[2]|0;D=ye[3]|0;E=ye[4]|0;F=ye[5]|0;G=ye[6]|0;H=ye[7]|0;constructor(){super(32)}}const ve=wr(()=>new Gr,vr(1));const gt=BigInt(0),pt=BigInt(1);function je(t,e=""){if(typeof t!="boolean"){const r=e&&`"${e}" `;throw new Error(r+"expected boolean, got type="+typeof t)}return t}function un(t){if(typeof t=="bigint"){if(!We(t))throw new Error("positive bigint expected, got "+t)}else be(t);return t}function ze(t){const e=un(t).toString(16);return e.length&1?"0"+e:e}function ln(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);return t===""?gt:BigInt("0x"+t)}function Me(t){return ln(ae(t))}function fn(t){return ln(ae(Xr(G(t)).reverse()))}function bt(t,e){be(e),t=un(t);const r=ie(t.toString(16).padStart(e*2,"0"));if(r.length!==e)throw new Error("number too large");return r}function dn(t,e){return bt(t,e).reverse()}function Xr(t){return Uint8Array.from(t)}function Qr(t){return Uint8Array.from(t,(e,r)=>{const n=e.charCodeAt(0);if(e.length!==1||n>127)throw new Error(`string contains non-ASCII character "${t[r]}" with code ${n} at position ${r}`);return n})}const We=t=>typeof t=="bigint"&&gt<=t;function ei(t,e,r){return We(t)&&We(e)&&We(r)&&e<=t&&t<r}function ti(t,e,r,n){if(!ei(e,r,n))throw new Error("expected valid "+t+": "+r+" <= n < "+n+", got "+e)}function ni(t){let e;for(e=0;t>gt;t>>=pt,e+=1);return e}const yt=t=>(pt<<BigInt(t))-pt;function ri(t,e,r){if(be(t,"hashLen"),be(e,"qByteLen"),typeof r!="function")throw new Error("hmacFn must be a function");const n=U=>new Uint8Array(U),i=Uint8Array.of(),s=Uint8Array.of(0),o=Uint8Array.of(1),a=1e3;let u=n(t),w=n(t),T=0;const R=()=>{u.fill(1),w.fill(0),T=0},_=(...U)=>r(w,oe(u,...U)),k=(U=i)=>{w=_(s,U),u=_(),U.length!==0&&(w=_(o,U),u=_())},P=()=>{if(T++>=a)throw new Error("drbg: tried max amount of iterations");let U=0;const H=[];for(;U<e;){u=_();const W=u.slice();H.push(W),U+=u.length}return oe(...H)};return(U,H)=>{R(),k(U);let W;for(;!(W=H(P()));)k();return R(),W}}function wt(t,e={},r={}){if(!t||typeof t!="object")throw new Error("expected valid options object");function n(s,o,a){const u=t[s];if(a&&u===void 0)return;const w=typeof u;if(w!==o||u===null)throw new Error(`param "${s}" is invalid: expected ${o}, got ${w}`)}const i=(s,o)=>Object.entries(s).forEach(([a,u])=>n(a,u,o));i(e,!1),i(r,!0)}function hn(t){const e=new WeakMap;return(r,...n)=>{const i=e.get(r);if(i!==void 0)return i;const s=t(r,...n);return e.set(r,s),s}}const se=BigInt(0),re=BigInt(1),ke=BigInt(2),gn=BigInt(3),pn=BigInt(4),bn=BigInt(5),ii=BigInt(7),yn=BigInt(8),si=BigInt(9),wn=BigInt(16);function fe(t,e){const r=t%e;return r>=se?r:e+r}function ce(t,e,r){let n=t;for(;e-- >se;)n*=n,n%=r;return n}function vn(t,e){if(t===se)throw new Error("invert: expected non-zero number");if(e<=se)throw new Error("invert: expected positive modulus, got "+e);let r=fe(t,e),n=e,i=se,s=re;for(;r!==se;){const a=n/r,u=n%r,w=i-s*a;n=r,r=u,i=s,s=w}if(n!==re)throw new Error("invert: does not exist");return fe(i,e)}function vt(t,e,r){if(!t.eql(t.sqr(e),r))throw new Error("Cannot find square root")}function mn(t,e){const r=(t.ORDER+re)/pn,n=t.pow(e,r);return vt(t,n,e),n}function oi(t,e){const r=(t.ORDER-bn)/yn,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));return vt(t,a,e),a}function ai(t){const e=Ye(t),r=xn(t),n=r(e,e.neg(e.ONE)),i=r(e,n),s=r(e,e.neg(n)),o=(t+ii)/wn;return(a,u)=>{let w=a.pow(u,o),T=a.mul(w,n);const R=a.mul(w,i),_=a.mul(w,s),k=a.eql(a.sqr(T),u),P=a.eql(a.sqr(R),u);w=a.cmov(w,T,k),T=a.cmov(_,R,P);const q=a.eql(a.sqr(T),u),U=a.cmov(w,T,q);return vt(a,U,u),U}}function xn(t){if(t<gn)throw new Error("sqrt is not defined for small field");let e=t-re,r=0;for(;e%ke===se;)e/=ke,r++;let n=ke;const i=Ye(t);for(;kn(i,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return mn;let s=i.pow(n,e);const o=(e+re)/ke;return function(u,w){if(u.is0(w))return w;if(kn(u,w)!==1)throw new Error("Cannot find square root");let T=r,R=u.mul(u.ONE,s),_=u.pow(w,e),k=u.pow(w,o);for(;!u.eql(_,u.ONE);){if(u.is0(_))return u.ZERO;let P=1,q=u.sqr(_);for(;!u.eql(q,u.ONE);)if(P++,q=u.sqr(q),P===T)throw new Error("Cannot find square root");const U=re<<BigInt(T-P-1),H=u.pow(R,U);T=P,R=u.sqr(H),_=u.mul(_,R),k=u.mul(k,H)}return k}}function ci(t){return t%pn===gn?mn:t%yn===bn?oi:t%wn===si?ai(t):xn(t)}const ui=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function li(t){const e={ORDER:"bigint",BYTES:"number",BITS:"number"},r=ui.reduce((n,i)=>(n[i]="function",n),e);return wt(t,r),t}function fi(t,e,r){if(r<se)throw new Error("invalid exponent, negatives unsupported");if(r===se)return t.ONE;if(r===re)return e;let n=t.ONE,i=e;for(;r>se;)r&re&&(n=t.mul(n,i)),i=t.sqr(i),r>>=re;return n}function En(t,e,r=!1){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);return e.reduceRight((o,a,u)=>t.is0(a)?o:(n[u]=t.mul(o,n[u]),t.mul(o,a)),s),n}function kn(t,e){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));if(!i&&!s&&!o)throw new Error("invalid Legendre symbol result");return i?1:s?0:-1}function di(t,e){e!==void 0&&be(e);const r=e!==void 0?e:t.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}class hi{ORDER;BITS;BYTES;isLE;ZERO=se;ONE=re;_lengths;_sqrt;_mod;constructor(e,r={}){if(e<=se)throw new Error("invalid field: expected ORDER > 0, got "+e);let n;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));const{nBitLength:i,nByteLength:s}=di(e,n);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=e,this.BITS=i,this.BYTES=s,this._sqrt=void 0,Object.preventExtensions(this)}create(e){return fe(e,this.ORDER)}isValid(e){if(typeof e!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof e);return se<=e&&e<this.ORDER}is0(e){return e===se}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}isOdd(e){return(e&re)===re}neg(e){return fe(-e,this.ORDER)}eql(e,r){return e===r}sqr(e){return fe(e*e,this.ORDER)}add(e,r){return fe(e+r,this.ORDER)}sub(e,r){return fe(e-r,this.ORDER)}mul(e,r){return fe(e*r,this.ORDER)}pow(e,r){return fi(this,e,r)}div(e,r){return fe(e*vn(r,this.ORDER),this.ORDER)}sqrN(e){return e*e}addN(e,r){return e+r}subN(e,r){return e-r}mulN(e,r){return e*r}inv(e){return vn(e,this.ORDER)}sqrt(e){return this._sqrt||(this._sqrt=ci(this.ORDER)),this._sqrt(this,e)}toBytes(e){return this.isLE?dn(e,this.BYTES):bt(e,this.BYTES)}fromBytes(e,r=!1){G(e);const{_lengths:n,BYTES:i,isLE:s,ORDER:o,_mod:a}=this;if(n){if(!n.includes(e.length)||e.length>i)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+e.length);const w=new Uint8Array(i);w.set(e,s?0:w.length-e.length),e=w}if(e.length!==i)throw new Error("Field.fromBytes: expected "+i+" bytes, got "+e.length);let u=s?fn(e):Me(e);if(a&&(u=fe(u,o)),!r&&!this.isValid(u))throw new Error("invalid field element: outside of range 0..ORDER");return u}invertBatch(e){return En(this,e)}cmov(e,r,n){return n?r:e}}function Ye(t,e={}){return new hi(t,e)}function An(t){if(typeof t!="bigint")throw new Error("field order must be bigint");const e=t.toString(2).length;return Math.ceil(e/8)}function Sn(t){const e=An(t);return e+Math.ceil(e/2)}function Bn(t,e,r=!1){G(t);const n=t.length,i=An(e),s=Sn(e);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);const o=r?fn(t):Me(t),a=fe(o,e-re)+re;return r?dn(a,i):bt(a,i)}const Re=BigInt(0),Ae=BigInt(1);function Je(t,e){const r=e.negate();return t?r:e}function Rn(t,e){const r=En(t.Fp,e.map(n=>n.Z));return e.map((n,i)=>t.fromAffine(n.toAffine(r[i])))}function _n(t,e){if(!Number.isSafeInteger(t)||t<=0||t>e)throw new Error("invalid window size, expected [1.."+e+"], got W="+t)}function mt(t,e){_n(t,e);const r=Math.ceil(e/t)+1,n=2**(t-1),i=2**t,s=yt(t),o=BigInt(t);return{windows:r,windowSize:n,mask:s,maxNumber:i,shiftBy:o}}function Tn(t,e,r){const{windowSize:n,mask:i,maxNumber:s,shiftBy:o}=r;let a=Number(t&i),u=t>>o;a>n&&(a-=s,u+=Ae);const w=e*n,T=w+Math.abs(a)-1,R=a===0,_=a<0,k=e%2!==0;return{nextN:u,offset:T,isZero:R,isNeg:_,isNegF:k,offsetF:w}}const xt=new WeakMap,Cn=new WeakMap;function Et(t){return Cn.get(t)||1}function Ln(t){if(t!==Re)throw new Error("invalid wNAF")}class gi{BASE;ZERO;Fn;bits;constructor(e,r){this.BASE=e.BASE,this.ZERO=e.ZERO,this.Fn=e.Fn,this.bits=r}_unsafeLadder(e,r,n=this.ZERO){let i=e;for(;r>Re;)r&Ae&&(n=n.add(i)),i=i.double(),r>>=Ae;return n}precomputeWindow(e,r){const{windows:n,windowSize:i}=mt(r,this.bits),s=[];let o=e,a=o;for(let u=0;u<n;u++){a=o,s.push(a);for(let w=1;w<i;w++)a=a.add(o),s.push(a);o=a.double()}return s}wNAF(e,r,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let i=this.ZERO,s=this.BASE;const o=mt(e,this.bits);for(let a=0;a<o.windows;a++){const{nextN:u,offset:w,isZero:T,isNeg:R,isNegF:_,offsetF:k}=Tn(n,a,o);n=u,T?s=s.add(Je(_,r[k])):i=i.add(Je(R,r[w]))}return Ln(n),{p:i,f:s}}wNAFUnsafe(e,r,n,i=this.ZERO){const s=mt(e,this.bits);for(let o=0;o<s.windows&&n!==Re;o++){const{nextN:a,offset:u,isZero:w,isNeg:T}=Tn(n,o,s);if(n=a,!w){const R=r[u];i=i.add(T?R.negate():R)}}return Ln(n),i}getPrecomputes(e,r,n){let i=xt.get(r);return i||(i=this.precomputeWindow(r,e),e!==1&&(typeof n=="function"&&(i=n(i)),xt.set(r,i))),i}cached(e,r,n){const i=Et(e);return this.wNAF(i,this.getPrecomputes(i,e,n),r)}unsafe(e,r,n,i){const s=Et(e);return s===1?this._unsafeLadder(e,r,i):this.wNAFUnsafe(s,this.getPrecomputes(s,e,n),r,i)}createCache(e,r){_n(r,this.bits),Cn.set(e,r),xt.delete(e)}hasCache(e){return Et(e)!==1}}function pi(t,e,r,n){let i=e,s=t.ZERO,o=t.ZERO;for(;r>Re||n>Re;)r&Ae&&(s=s.add(i)),n&Ae&&(o=o.add(i)),i=i.double(),r>>=Ae,n>>=Ae;return{p1:s,p2:o}}function On(t,e,r){if(e){if(e.ORDER!==t)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return li(e),e}else return Ye(t,{isLE:r})}function bi(t,e,r={},n){if(n===void 0&&(n=t==="edwards"),!e||typeof e!="object")throw new Error(`expected valid ${t} CURVE object`);for(const u of["p","n","h"]){const w=e[u];if(!(typeof w=="bigint"&&w>Re))throw new Error(`CURVE.${u} must be positive bigint`)}const i=On(e.p,r.Fp,n),s=On(e.n,r.Fn,n),a=["Gx","Gy","a","b"];for(const u of a)if(!i.isValid(e[u]))throw new Error(`CURVE.${u} must be valid field element of CURVE.Fp`);return e=Object.freeze(Object.assign({},e)),{CURVE:e,Fp:i,Fn:s}}function In(t,e){return function(n){const i=t(n);return{secretKey:i,publicKey:e(i)}}}class Pn{oHash;iHash;blockLen;outputLen;finished=!1;destroyed=!1;constructor(e,r){if(Ue(e),G(r,void 0,"key"),this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;const n=this.blockLen,i=new Uint8Array(n);i.set(r.length>n?e.create().update(r).digest():r);for(let s=0;s<i.length;s++)i[s]^=54;this.iHash.update(i),this.oHash=e.create();for(let s=0;s<i.length;s++)i[s]^=106;this.oHash.update(i),Ce(i)}update(e){return He(this),this.iHash.update(e),this}digestInto(e){He(this),G(e,this.outputLen,"output"),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){const e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||=Object.create(Object.getPrototypeOf(this),{});const{oHash:r,iHash:n,finished:i,destroyed:s,blockLen:o,outputLen:a}=this;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}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}const Ne=(t,e,r)=>new Pn(t,e).update(r).digest();Ne.create=(t,e)=>new Pn(t,e);const Mn=(t,e)=>(t+(t>=0?e:-e)/Nn)/e;function yi(t,e,r){const[[n,i],[s,o]]=e,a=Mn(o*t,r),u=Mn(-i*t,r);let w=t-a*n-u*s,T=-a*i-u*o;const R=w<pe,_=T<pe;R&&(w=-w),_&&(T=-T);const k=yt(Math.ceil(ni(r)/2))+_e;if(w<pe||w>=k||T<pe||T>=k)throw new Error("splitScalar (endomorphism): failed, k="+t);return{k1neg:R,k1:w,k2neg:_,k2:T}}function kt(t){if(!["compact","recovered","der"].includes(t))throw new Error('Signature format must be "compact", "recovered", or "der"');return t}function At(t,e){const r={};for(let n of Object.keys(e))r[n]=t[n]===void 0?e[n]:t[n];return je(r.lowS,"lowS"),je(r.prehash,"prehash"),r.format!==void 0&&kt(r.format),r}class wi extends Error{constructor(e=""){super(e)}}const me={Err:wi,_tlv:{encode:(t,e)=>{const{Err:r}=me;if(t<0||t>256)throw new r("tlv.encode: wrong tag");if(e.length&1)throw new r("tlv.encode: unpadded data");const n=e.length/2,i=ze(n);if(i.length/2&128)throw new r("tlv.encode: long form length too big");const s=n>127?ze(i.length/2|128):"";return ze(t)+s+i+e},decode(t,e){const{Err:r}=me;let n=0;if(t<0||t>256)throw new r("tlv.encode: wrong tag");if(e.length<2||e[n++]!==t)throw new r("tlv.decode: wrong tlv");const i=e[n++],s=!!(i&128);let o=0;if(!s)o=i;else{const u=i&127;if(!u)throw new r("tlv.decode(long): indefinite length not supported");if(u>4)throw new r("tlv.decode(long): byte length is too big");const w=e.subarray(n,n+u);if(w.length!==u)throw new r("tlv.decode: length bytes not complete");if(w[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(const T of w)o=o<<8|T;if(n+=u,o<128)throw new r("tlv.decode(long): not minimal encoding")}const a=e.subarray(n,n+o);if(a.length!==o)throw new r("tlv.decode: wrong value length");return{v:a,l:e.subarray(n+o)}}},_int:{encode(t){const{Err:e}=me;if(t<pe)throw new e("integer: negative integers are not allowed");let r=ze(t);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new e("unexpected DER parsing assertion: unpadded hex");return r},decode(t){const{Err:e}=me;if(t[0]&128)throw new e("invalid signature integer: negative");if(t[0]===0&&!(t[1]&128))throw new e("invalid signature integer: unnecessary leading zero");return Me(t)}},toSig(t){const{Err:e,_int:r,_tlv:n}=me,i=G(t,void 0,"signature"),{v:s,l:o}=n.decode(48,i);if(o.length)throw new e("invalid signature: left bytes after parsing");const{v:a,l:u}=n.decode(2,s),{v:w,l:T}=n.decode(2,u);if(T.length)throw new e("invalid signature: left bytes after parsing");return{r:r.decode(a),s:r.decode(w)}},hexFromSig(t){const{_tlv:e,_int:r}=me,n=e.encode(2,r.encode(t.r)),i=e.encode(2,r.encode(t.s)),s=n+i;return e.encode(48,s)}},pe=BigInt(0),_e=BigInt(1),Nn=BigInt(2),Ge=BigInt(3),vi=BigInt(4);function mi(t,e={}){const r=bi("weierstrass",t,e),{Fp:n,Fn:i}=r;let s=r.CURVE;const{h:o,n:a}=s;wt(e,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object"});const{endo:u}=e;if(u&&(!n.is0(s.a)||typeof u.beta!="bigint"||!Array.isArray(u.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');const w=Dn(n,i);function T(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function R(c,d,f){const{x:l,y:v}=d.toAffine(),A=n.toBytes(l);if(je(f,"isCompressed"),f){T();const C=!n.isOdd(v);return oe($n(C),A)}else return oe(Uint8Array.of(4),A,n.toBytes(v))}function _(c){G(c,void 0,"Point");const{publicKey:d,publicKeyUncompressed:f}=w,l=c.length,v=c[0],A=c.subarray(1);if(l===d&&(v===2||v===3)){const C=n.fromBytes(A);if(!n.isValid(C))throw new Error("bad point: is not on curve, wrong x");const I=q(C);let O;try{O=n.sqrt(I)}catch(z){const Y=z instanceof Error?": "+z.message:"";throw new Error("bad point: is not on curve, sqrt error"+Y)}T();const $=n.isOdd(O);return(v&1)===1!==$&&(O=n.neg(O)),{x:C,y:O}}else if(l===f&&v===4){const C=n.BYTES,I=n.fromBytes(A.subarray(0,C)),O=n.fromBytes(A.subarray(C,C*2));if(!U(I,O))throw new Error("bad point: is not on curve");return{x:I,y:O}}else throw new Error(`bad point: got length ${l}, expected compressed=${d} or uncompressed=${f}`)}const k=e.toBytes||R,P=e.fromBytes||_;function q(c){const d=n.sqr(c),f=n.mul(d,c);return n.add(n.add(f,n.mul(c,s.a)),s.b)}function U(c,d){const f=n.sqr(d),l=q(c);return n.eql(f,l)}if(!U(s.Gx,s.Gy))throw new Error("bad curve params: generator point");const H=n.mul(n.pow(s.a,Ge),vi),W=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(H,W)))throw new Error("bad curve params: a or b");function ne(c,d,f=!1){if(!n.isValid(d)||f&&n.is0(d))throw new Error(`bad point coordinate ${c}`);return d}function Q(c){if(!(c instanceof g))throw new Error("Weierstrass Point expected")}function M(c){if(!u||!u.basises)throw new Error("no endo");return yi(c,u.basises,i.ORDER)}const L=hn((c,d)=>{const{X:f,Y:l,Z:v}=c;if(n.eql(v,n.ONE))return{x:f,y:l};const A=c.is0();d==null&&(d=A?n.ONE:n.inv(v));const C=n.mul(f,d),I=n.mul(l,d),O=n.mul(v,d);if(A)return{x:n.ZERO,y:n.ZERO};if(!n.eql(O,n.ONE))throw new Error("invZ was invalid");return{x:C,y:I}}),x=hn(c=>{if(c.is0()){if(e.allowInfinityPoint&&!n.is0(c.Y))return;throw new Error("bad point: ZERO")}const{x:d,y:f}=c.toAffine();if(!n.isValid(d)||!n.isValid(f))throw new Error("bad point: x or y not field elements");if(!U(d,f))throw new Error("bad point: equation left != right");if(!c.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function B(c,d,f,l,v){return f=new g(n.mul(f.X,c),f.Y,f.Z),d=Je(l,d),f=Je(v,f),d.add(f)}class g{static BASE=new g(s.Gx,s.Gy,n.ONE);static ZERO=new g(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=i;X;Y;Z;constructor(d,f,l){this.X=ne("x",d),this.Y=ne("y",f,!0),this.Z=ne("z",l),Object.freeze(this)}static CURVE(){return s}static fromAffine(d){const{x:f,y:l}=d||{};if(!d||!n.isValid(f)||!n.isValid(l))throw new Error("invalid affine point");if(d instanceof g)throw new Error("projective point not allowed");return n.is0(f)&&n.is0(l)?g.ZERO:new g(f,l,n.ONE)}static fromBytes(d){const f=g.fromAffine(P(G(d,void 0,"point")));return f.assertValidity(),f}static fromHex(d){return g.fromBytes(ie(d))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(d=8,f=!0){return h.createCache(this,d),f||this.multiply(Ge),this}assertValidity(){x(this)}hasEvenY(){const{y:d}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(d)}equals(d){Q(d);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));return O&&$}negate(){return new g(this.X,n.neg(this.Y),this.Z)}double(){const{a:d,b:f}=s,l=n.mul(f,Ge),{X:v,Y:A,Z:C}=this;let I=n.ZERO,O=n.ZERO,$=n.ZERO,D=n.mul(v,v),z=n.mul(A,A),Y=n.mul(C,C),Z=n.mul(v,A);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(z,O),O=n.add(z,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,z),$=n.add($,$),$=n.add($,$),new g(I,O,$)}add(d){Q(d);const{X:f,Y:l,Z:v}=this,{X:A,Y:C,Z:I}=d;let O=n.ZERO,$=n.ZERO,D=n.ZERO;const z=s.a,Y=n.mul(s.b,Ge);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);y=n.mul(y,b),b=n.add(Z,J),y=n.sub(y,b),b=n.add(f,v);let p=n.add(A,I);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(z,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(z,ee),b=n.mul(Y,b),J=n.add(J,ee),ee=n.sub(Z,ee),ee=n.mul(z,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)}subtract(d){return this.add(d.negate())}is0(){return this.equals(g.ZERO)}multiply(d){const{endo:f}=e;if(!i.isValidNot0(d))throw new Error("invalid scalar: out of range");let l,v;const A=C=>h.cached(this,C,I=>Rn(g,I));if(f){const{k1neg:C,k1:I,k2neg:O,k2:$}=M(d),{p:D,f:z}=A(I),{p:Y,f:Z}=A($);v=z.add(Z),l=B(f.beta,D,Y,C,O)}else{const{p:C,f:I}=A(d);l=C,v=I}return Rn(g,[l,v])[0]}multiplyUnsafe(d){const{endo:f}=e,l=this;if(!i.isValid(d))throw new Error("invalid scalar: out of range");if(d===pe||l.is0())return g.ZERO;if(d===_e)return l;if(h.hasCache(this))return this.multiply(d);if(f){const{k1neg:v,k1:A,k2neg:C,k2:I}=M(d),{p1:O,p2:$}=pi(g,l,A,I);return B(f.beta,O,$,v,C)}else return h.unsafe(l,d)}toAffine(d){return L(this,d)}isTorsionFree(){const{isTorsionFree:d}=e;return o===_e?!0:d?d(g,this):h.unsafe(this,a).is0()}clearCofactor(){const{clearCofactor:d}=e;return o===_e?this:d?d(g,this):this.multiplyUnsafe(o)}isSmallOrder(){return this.multiplyUnsafe(o).is0()}toBytes(d=!0){return je(d,"isCompressed"),this.assertValidity(),k(g,this,d)}toHex(d=!0){return ae(this.toBytes(d))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}const E=i.BITS,h=new gi(g,e.endo?Math.ceil(E/2):E);return g.BASE.precompute(8),g}function $n(t){return Uint8Array.of(t?2:3)}function Dn(t,e){return{secretKey:e.BYTES,publicKey:1+t.BYTES,publicKeyUncompressed:1+2*t.BYTES,publicKeyHasPrefix:!0,signature:2*e.BYTES}}function xi(t,e={}){const{Fn:r}=t,n=e.randomBytes||Le,i=Object.assign(Dn(t.Fp,r),{seed:Sn(r.ORDER)});function s(k){try{const P=r.fromBytes(k);return r.isValidNot0(P)}catch{return!1}}function o(k,P){const{publicKey:q,publicKeyUncompressed:U}=i;try{const H=k.length;return P===!0&&H!==q||P===!1&&H!==U?!1:!!t.fromBytes(k)}catch{return!1}}function a(k=n(i.seed)){return Bn(G(k,i.seed,"seed"),r.ORDER)}function u(k,P=!0){return t.BASE.multiply(r.fromBytes(k)).toBytes(P)}function w(k){const{secretKey:P,publicKey:q,publicKeyUncompressed:U}=i;if(!ot(k)||"_lengths"in r&&r._lengths||P===q)return;const H=G(k,void 0,"key").length;return H===q||H===U}function T(k,P,q=!0){if(w(k)===!0)throw new Error("first arg must be private key");if(w(P)===!1)throw new Error("second arg must be public key");const U=r.fromBytes(k);return t.fromBytes(P).multiply(U).toBytes(q)}const R={isValidSecretKey:s,isValidPublicKey:o,randomSecretKey:a},_=In(a,u);return Object.freeze({getPublicKey:u,getSharedSecret:T,keygen:_,Point:t,utils:R,lengths:i})}function Ei(t,e,r={}){Ue(e),wt(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),r=Object.assign({},r);const n=r.randomBytes||Le,i=r.hmac||((f,l)=>Ne(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={prehash:!0,lowS:typeof r.lowS=="boolean"?r.lowS:!0,format:"compact",extraEntropy:!1},q=a*Nn<s.ORDER;function U(f){const l=a>>_e;return f>l}function H(f,l){if(!o.isValidNot0(l))throw new Error(`invalid signature ${f}: out of range 1..Point.Fn.ORDER`);return l}function W(){if(q)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function ne(f,l){kt(l);const v=k.signature,A=l==="compact"?v:l==="recovered"?v+1:void 0;return G(f,A)}class Q{r;s;recovery;constructor(l,v,A){if(this.r=H("r",l),this.s=H("s",v),A!=null){if(W(),![0,1,2,3].includes(A))throw new Error("invalid recovery id");this.recovery=A}Object.freeze(this)}static fromBytes(l,v=P.format){ne(l,v);let A;if(v==="der"){const{r:$,s:D}=me.toSig(G(l));return new Q($,D)}v==="recovered"&&(A=l[0],v="compact",l=l.subarray(1));const C=k.signature/2,I=l.subarray(0,C),O=l.subarray(C,C*2);return new Q(o.fromBytes(I),o.fromBytes(O),A)}static fromHex(l,v){return this.fromBytes(ie(l),v)}assertRecovery(){const{recovery:l}=this;if(l==null)throw new Error("invalid recovery id: must be present");return l}addRecoveryBit(l){return new Q(this.r,this.s,l)}recoverPublicKey(l){const{r:v,s:A}=this,C=this.assertRecovery(),I=C===2||C===3?v+a:v;if(!s.isValid(I))throw new Error("invalid recovery id: sig.r+curve.n != R.x");const O=s.toBytes(I),$=t.fromBytes(oe($n((C&1)===0),O)),D=o.inv(I),z=L(G(l,void 0,"msgHash")),Y=o.create(-z*D),Z=o.create(A*D),J=t.BASE.multiplyUnsafe(Y).add($.multiplyUnsafe(Z));if(J.is0())throw new Error("invalid recovery: point at infinify");return J.assertValidity(),J}hasHighS(){return U(this.s)}toBytes(l=P.format){if(kt(l),l==="der")return ie(me.hexFromSig(this));const{r:v,s:A}=this,C=o.toBytes(v),I=o.toBytes(A);return l==="recovered"?(W(),oe(Uint8Array.of(this.assertRecovery()),C,I)):oe(C,I)}toHex(l){return ae(this.toBytes(l))}}const M=r.bits2int||function(l){if(l.length>8192)throw new Error("input is too large");const v=Me(l),A=l.length*8-u;return A>0?v>>BigInt(A):v},L=r.bits2int_modN||function(l){return o.create(M(l))},x=yt(u);function B(f){return ti("num < 2^"+u,f,pe,x),o.toBytes(f)}function g(f,l){return G(f,void 0,"message"),l?G(e(f),void 0,"prehashed message"):f}function E(f,l,v){const{lowS:A,prehash:C,extraEntropy:I}=At(v,P);f=g(f,C);const O=L(f),$=o.fromBytes(l);if(!o.isValidNot0($))throw new Error("invalid private key");const D=[B($),B(O)];if(I!=null&&I!==!1){const J=I===!0?n(k.secretKey):I;D.push(G(J,void 0,"extraEntropy"))}const z=oe(...D),Y=O;function Z(J){const ee=M(J);if(!o.isValidNot0(ee))return;const y=o.inv(ee),b=t.BASE.multiply(ee).toAffine(),p=o.create(b.x);if(p===pe)return;const m=o.create(y*o.create(Y+p*$));if(m===pe)return;let S=(b.x===p?0:2)|Number(b.y&_e),N=m;return A&&U(m)&&(N=o.neg(m),S^=1),new Q(p,N,q?void 0:S)}return{seed:z,k2sig:Z}}function h(f,l,v={}){const{seed:A,k2sig:C}=E(f,l,v);return ri(e.outputLen,o.BYTES,i)(A,C).toBytes(v.format)}function c(f,l,v,A={}){const{lowS:C,prehash:I,format:O}=At(A,P);if(v=G(v,void 0,"publicKey"),l=g(l,I),!ot(f)){const $=f instanceof Q?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+$)}ne(f,O);try{const $=Q.fromBytes(f,O),D=t.fromBytes(v);if(C&&$.hasHighS())return!1;const{r:z,s:Y}=$,Z=L(l),J=o.inv(Y),ee=o.create(Z*J),y=o.create(z*J),b=t.BASE.multiplyUnsafe(ee).add(D.multiplyUnsafe(y));return b.is0()?!1:o.create(b.x)===z}catch{return!1}}function d(f,l,v={}){const{prehash:A}=At(v,P);return l=g(l,A),Q.fromBytes(f,"recovered").recoverPublicKey(l).toBytes()}return Object.freeze({keygen:w,getPublicKey:T,getSharedSecret:R,utils:_,lengths:k,Point:t,sign:h,verify:c,recoverPublicKey:d,Signature:Q,hash:e})}const Xe={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},ki={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]},Ai=BigInt(0),St=BigInt(2);function Si(t){const e=Xe.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=ce(T,r,e)*T%e,_=ce(R,r,e)*T%e,k=ce(_,St,e)*w%e,P=ce(k,i,e)*k%e,q=ce(P,s,e)*P%e,U=ce(q,a,e)*q%e,H=ce(U,u,e)*U%e,W=ce(H,a,e)*q%e,ne=ce(W,r,e)*T%e,Q=ce(ne,o,e)*P%e,M=ce(Q,n,e)*w%e,L=ce(M,St,e);if(!Qe.eql(Qe.sqr(L),t))throw new Error("Cannot find square root");return L}const Qe=Ye(Xe.p,{sqrt:Si}),Se=mi(Xe,{Fp:Qe,endo:ki}),Bi=Ei(Se,ve),qn={};function et(t,...e){let r=qn[t];if(r===void 0){const n=ve(Qr(t));r=oe(n,n),qn[t]=r}return ve(oe(r,...e))}const Bt=t=>t.toBytes(!0).slice(1),Rt=t=>t%St===Ai;function _t(t){const{Fn:e,BASE:r}=Se,n=e.fromBytes(t),i=r.multiply(n);return{scalar:Rt(i.y)?n:e.neg(n),bytes:Bt(i)}}function Un(t){const e=Qe;if(!e.isValidNot0(t))throw new Error("invalid x: Fail if x ≥ p");const r=e.create(t*t),n=e.create(r*t+BigInt(7));let i=e.sqrt(n);Rt(i)||(i=e.neg(i));const s=Se.fromAffine({x:t,y:i});return s.assertValidity(),s}const $e=Me;function Hn(...t){return Se.Fn.create($e(et("BIP0340/challenge",...t)))}function Kn(t){return _t(t).bytes}function Ri(t,e,r=Le(32)){const{Fn:n}=Se,i=G(t,void 0,"message"),{bytes:s,scalar:o}=_t(e),a=G(r,32,"auxRand"),u=n.toBytes(o^$e(et("BIP0340/aux",a))),w=et("BIP0340/nonce",u,s,i),{bytes:T,scalar:R}=_t(w),_=Hn(T,s,i),k=new Uint8Array(64);if(k.set(T,0),k.set(n.toBytes(n.create(R+_*o)),32),!Fn(k,i,s))throw new Error("sign: Invalid signature produced");return k}function Fn(t,e,r){const{Fp:n,Fn:i,BASE:s}=Se,o=G(t,64,"signature"),a=G(e,void 0,"message"),u=G(r,32,"publicKey");try{const w=Un($e(u)),T=$e(o.subarray(0,32));if(!n.isValidNot0(T))return!1;const R=$e(o.subarray(32,64));if(!i.isValidNot0(R))return!1;const _=Hn(i.toBytes(T),Bt(w),a),k=s.multiplyUnsafe(R).add(w.multiplyUnsafe(i.neg(_))),{x:P,y:q}=k.toAffine();return!(k.is0()||!Rt(q)||P!==T)}catch{return!1}}const he=(()=>{const r=(n=Le(48))=>Bn(n,Xe.n);return{keygen:In(r,Kn),getPublicKey:Kn,sign:Ri,verify:Fn,Point:Se,utils:{randomSecretKey:r,taggedHash:et,lift_x:Un,pointToBytes:Bt},lengths:{secretKey:32,publicKey:32,publicKeyHasPrefix:!1,signature:64,seed:48}}})();var Te=Symbol("verified"),_i=t=>t instanceof Object;function Ti(t){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))return!1;for(let e=0;e<t.tags.length;e++){let r=t.tags[e];if(!Array.isArray(r))return!1;for(let n=0;n<r.length;n++)if(typeof r[n]!="string")return!1}return!0}new TextDecoder("utf-8");var Ci=new TextEncoder,Li=class{generateSecretKey(){return he.utils.randomSecretKey()}getPublicKey(e){return ae(he.getPublicKey(e))}finalizeEvent(e,r){const n=e;return n.pubkey=ae(he.getPublicKey(r)),n.id=Tt(n),n.sig=ae(he.sign(ie(Tt(n)),r)),n[Te]=!0,n}verifyEvent(e){if(typeof e[Te]=="boolean")return e[Te];try{const r=Tt(e);if(r!==e.id)return e[Te]=!1,!1;const n=he.verify(ie(e.sig),ie(r),ie(e.pubkey));return e[Te]=n,n}catch{return e[Te]=!1,!1}}};function Oi(t){if(!Ti(t))throw new Error("can't serialize event with wrong or missing properties");return JSON.stringify([0,t.pubkey,t.created_at,t.kind,t.tags,t.content])}function Tt(t){let e=ve(Ci.encode(Oi(t)));return ae(e)}var tt=new Li,Vn=tt.generateSecretKey,Ii=tt.getPublicKey;tt.finalizeEvent,tt.verifyEvent;function Pi(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function Zn(t){if(typeof t!="boolean")throw new Error(`boolean expected, not ${t}`)}function Ct(t){if(!Number.isSafeInteger(t)||t<0)throw new Error("positive integer expected, got "+t)}function De(t,e,r=""){const n=Pi(t),i=t?.length,s=e!==void 0;if(!n||s&&i!==e){const o=r&&`"${r}" `,a=s?` of length ${e}`:"",u=n?`length=${i}`:`type=${typeof t}`;throw new Error(o+"expected Uint8Array"+a+", got "+u)}return t}function xe(t){return new Uint32Array(t.buffer,t.byteOffset,Math.floor(t.byteLength/4))}function Mi(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function Ni(t,e){if(e==null||typeof e!="object")throw new Error("options must be defined");return Object.assign(t,e)}function $i(t,e){if(t.length!==e.length)return!1;let r=0;for(let n=0;n<t.length;n++)r|=t[n]^e[n];return r===0}function jn(t){return Uint8Array.from(t)}const zn=t=>Uint8Array.from(t.split(""),e=>e.charCodeAt(0)),Di=zn("expand 16-byte k"),qi=zn("expand 32-byte k"),Ui=xe(Di),Hi=xe(qi);function j(t,e){return t<<e|t>>>32-e}function Lt(t){return t.byteOffset%4===0}const nt=64,Ki=16,Wn=2**32-1,Yn=Uint32Array.of();function Fi(t,e,r,n,i,s,o,a){const u=i.length,w=new Uint8Array(nt),T=xe(w),R=Lt(i)&&Lt(s),_=R?xe(i):Yn,k=R?xe(s):Yn;for(let P=0;P<u;o++){if(t(e,r,n,T,o,a),o>=Wn)throw new Error("arx: counter overflow");const q=Math.min(nt,u-P);if(R&&q===nt){const U=P/4;if(P%4!==0)throw new Error("arx: invalid block position");for(let H=0,W;H<Ki;H++)W=U+H,k[W]=_[W]^T[H];P+=nt;continue}for(let U=0,H;U<q;U++)H=P+U,s[H]=i[H]^w[U];P+=q}}function Vi(t,e){const{allowShortKeys:r,extendNonceFn:n,counterLength:i,counterRight:s,rounds:o}=Ni({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},e);if(typeof t!="function")throw new Error("core must be a function");return Ct(i),Ct(o),Zn(s),Zn(r),(a,u,w,T,R=0)=>{De(a,void 0,"key"),De(u,void 0,"nonce"),De(w,void 0,"data");const _=w.length;if(T===void 0&&(T=new Uint8Array(_)),De(T,void 0,"output"),Ct(R),R<0||R>=Wn)throw new Error("arx: counter overflow");if(T.length<_)throw new Error(`arx: output (${T.length}) is shorter than data (${_})`);const k=[];let P=a.length,q,U;if(P===32)k.push(q=jn(a)),U=Hi;else if(P===16&&r)q=new Uint8Array(32),q.set(a),q.set(a,16),U=Ui,k.push(q);else throw De(a,32,"arx key"),new Error("invalid key size");Lt(u)||k.push(u=jn(u));const H=xe(q);if(n){if(u.length!==24)throw new Error("arx: extended nonce must be 24 bytes");n(U,H,xe(u.subarray(0,16)),H),u=u.subarray(16)}const W=16-i;if(W!==u.length)throw new Error(`arx: nonce must be ${W} or 16 bytes`);if(W!==12){const Q=new Uint8Array(12);Q.set(u,s?0:12-u.length),u=Q,k.push(u)}const ne=xe(u);return Fi(t,U,H,ne,w,T,R,o),Mi(...k),T}}function Zi(t,e,r,n,i,s=20){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;for(let z=0;z<s;z+=2)L=L+E|0,C=j(C^L,16),f=f+C|0,E=j(E^f,12),L=L+E|0,C=j(C^L,8),f=f+C|0,E=j(E^f,7),x=x+h|0,I=j(I^x,16),l=l+I|0,h=j(h^l,12),x=x+h|0,I=j(I^x,8),l=l+I|0,h=j(h^l,7),B=B+c|0,O=j(O^B,16),v=v+O|0,c=j(c^v,12),B=B+c|0,O=j(O^B,8),v=v+O|0,c=j(c^v,7),g=g+d|0,$=j($^g,16),A=A+$|0,d=j(d^A,12),g=g+d|0,$=j($^g,8),A=A+$|0,d=j(d^A,7),L=L+h|0,$=j($^L,16),v=v+$|0,h=j(h^v,12),L=L+h|0,$=j($^L,8),v=v+$|0,h=j(h^v,7),x=x+c|0,C=j(C^x,16),A=A+C|0,c=j(c^A,12),x=x+c|0,C=j(C^x,8),A=A+C|0,c=j(c^A,7),B=B+d|0,I=j(I^B,16),f=f+I|0,d=j(d^f,12),B=B+d|0,I=j(I^B,8),f=f+I|0,d=j(d^f,7),g=g+E|0,O=j(O^g,16),l=l+O|0,E=j(E^l,12),g=g+E|0,O=j(O^g,8),l=l+O|0,E=j(E^l,7);let D=0;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}const Jn=Vi(Zi,{counterRight:!1,counterLength:4,allowShortKeys:!1});function ji(t,e,r){return Ue(t),r===void 0&&(r=new Uint8Array(t.outputLen)),Ne(t,r,e)}const Ot=Uint8Array.of(0),Gn=Uint8Array.of();function zi(t,e,r,n=32){Ue(t),be(n,"length");const i=t.outputLen;if(n>255*i)throw new Error("Length must be <= 255*HashLen");const s=Math.ceil(n/i);r===void 0?r=Gn:G(r,void 0,"info");const o=new Uint8Array(s*i),a=Ne.create(t,e),u=a._cloneInto(),w=new Uint8Array(a.outputLen);for(let T=0;T<s;T++)Ot[0]=T+1,u.update(T===0?Gn:w).update(r).update(Ot).digestInto(w),o.set(w,i*T),a._cloneInto(u);return a.destroy(),u.destroy(),Ce(w,Ot),o.slice(0,n)}var Be=Symbol("verified"),Wi=t=>t instanceof Object;function Yi(t){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))return!1;for(let e=0;e<t.tags.length;e++){let r=t.tags[e];if(!Array.isArray(r))return!1;for(let n=0;n<r.length;n++)if(typeof r[n]!="string")return!1}return!0}var Ji=new TextDecoder("utf-8"),It=new TextEncoder;function qe(t){try{t.indexOf("://")===-1&&(t="wss://"+t);let e=new URL(t);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()}catch{throw new Error(`Invalid URL: ${t}`)}}var Gi=class{generateSecretKey(){return he.utils.randomSecretKey()}getPublicKey(t){return ae(he.getPublicKey(t))}finalizeEvent(t,e){const r=t;return r.pubkey=ae(he.getPublicKey(e)),r.id=Pt(r),r.sig=ae(he.sign(ie(Pt(r)),e)),r[Be]=!0,r}verifyEvent(t){if(typeof t[Be]=="boolean")return t[Be];try{const e=Pt(t);if(e!==t.id)return t[Be]=!1,!1;const r=he.verify(ie(t.sig),ie(e),ie(t.pubkey));return t[Be]=r,r}catch{return t[Be]=!1,!1}}};function Xi(t){if(!Yi(t))throw new Error("can't serialize event with wrong or missing properties");return JSON.stringify([0,t.pubkey,t.created_at,t.kind,t.tags,t.content])}function Pt(t){let e=ve(It.encode(Xi(t)));return ae(e)}var rt=new Gi;rt.generateSecretKey;var Xn=rt.getPublicKey,Qi=rt.finalizeEvent,Qn=rt.verifyEvent,er=1,tr=65535;function Mt(t,e){const r=Bi.getSharedSecret(t,ie("02"+e)).subarray(1,33);return ji(ve,r,It.encode("nip44-v2"))}function nr(t,e){const r=zi(ve,t,e,76);return{chacha_key:r.subarray(0,32),chacha_nonce:r.subarray(32,44),hmac_key:r.subarray(44,76)}}function rr(t){if(!Number.isSafeInteger(t)||t<1)throw new Error("expected positive integer");if(t<=32)return 32;const e=1<<Math.floor(Math.log2(t-1))+1,r=e<=256?32:e/8;return r*(Math.floor((t-1)/r)+1)}function es(t){if(!Number.isSafeInteger(t)||t<er||t>tr)throw new Error("invalid plaintext size: must be between 1 and 65535 bytes");const e=new Uint8Array(2);return new DataView(e.buffer).setUint16(0,t,!1),e}function ts(t){const e=It.encode(t),r=e.length,n=es(r),i=new Uint8Array(rr(r)-r);return oe(n,e,i)}function ns(t){const e=new DataView(t.buffer).getUint16(0),r=t.subarray(2,2+e);if(e<er||e>tr||r.length!==e||t.length!==2+rr(e))throw new Error("invalid padding");return Ji.decode(r)}function ir(t,e,r){if(r.length!==32)throw new Error("AAD associated data must be 32 bytes");const n=oe(r,e);return Ne(ve,t,n)}function rs(t){if(typeof t!="string")throw new Error("payload must be a valid string");const e=t.length;if(e<132||e>87472)throw new Error("invalid payload length: "+e);if(t[0]==="#")throw new Error("unknown encryption version");let r;try{r=Jt.decode(t)}catch(s){throw new Error("invalid base64: "+s.message)}const n=r.length;if(n<99||n>65603)throw new Error("invalid data length: "+n);const i=r[0];if(i!==2)throw new Error("unknown encryption version "+i);return{nonce:r.subarray(1,33),ciphertext:r.subarray(33,-32),mac:r.subarray(-32)}}function is(t,e,r=Le(32)){const{chacha_key:n,chacha_nonce:i,hmac_key:s}=nr(e,r),o=ts(t),a=Jn(n,i,o),u=ir(s,a,r);return Jt.encode(oe(new Uint8Array([2]),r,a,u))}function sr(t,e){const{nonce:r,ciphertext:n,mac:i}=rs(t),{chacha_key:s,chacha_nonce:o,hmac_key:a}=nr(e,r),u=ir(a,n,r);if(!$i(u,i))throw new Error("invalid MAC");const w=Jn(s,o,n);return ns(w)}var ss=/^(?:([\w.+-]+)@)?([\w_-]+(\.[\w_-]+)+)$/,os;try{os=fetch}catch{}var as=22242,Nt=24133;function cs(t,e){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)return!1;for(let r in t)if(r[0]==="#"){let n=r.slice(1),i=t[`#${n}`];if(i&&!e.tags.find(([s,o])=>s===r.slice(1)&&i.indexOf(o)!==-1))return!1}return!(t.since&&e.created_at<t.since||t.until&&e.created_at>t.until)}function us(t,e){for(let r=0;r<t.length;r++)if(cs(t[r],e))return!0;return!1}function ls(t,e){let r=e.length+3,n=t.indexOf(`"${e}":`)+r,i=t.slice(n).indexOf('"')+n+1;return t.slice(i,i+64)}function fs(t){let e=t.slice(0,22).indexOf('"EVENT"');if(e===-1)return null;let r=t.slice(e+7+1).indexOf('"');if(r===-1)return null;let n=e+7+1+r,i=t.slice(n+1,80).indexOf('"');if(i===-1)return null;let s=n+1+i;return t.slice(n+1,s)}function ds(t,e){return{kind:as,created_at:Math.floor(Date.now()/1e3),tags:[["relay",t],["challenge",e]],content:""}}var or=class extends Error{constructor(t,e){super(`Tried to send message '${t} on a closed connection to ${e}.`),this.name="SendingOnClosedConnection"}},ar=class{url;_connected=!1;onclose=null;onnotice=t=>console.debug(`NOTICE from ${this.url}: ${t}`);onauth;baseEoseTimeout=4400;publishTimeout=4400;pingFrequency=29e3;pingTimeout=2e4;resubscribeBackoff=[1e4,1e4,1e4,2e4,2e4,3e4,6e4];openSubs=new Map;enablePing;enableReconnect;idleSince=Date.now();ongoingOperations=0;reconnectTimeoutHandle;pingIntervalHandle;reconnectAttempts=0;skipReconnection=!1;connectionPromise;openCountRequests=new Map;openEventPublishes=new Map;ws;challenge;authPromise;serial=0;verifyEvent;_WebSocket;constructor(t,e){this.url=qe(t),this.verifyEvent=e.verifyEvent,this._WebSocket=e.websocketImplementation||WebSocket,this.enablePing=e.enablePing,this.enableReconnect=e.enableReconnect||!1}static async connect(t,e){const r=new ar(t,e);return await r.connect(e),r}closeAllSubscriptions(t){for(let[e,r]of this.openSubs)r.close(t);this.openSubs.clear();for(let[e,r]of this.openEventPublishes)r.reject(new Error(t));this.openEventPublishes.clear();for(let[e,r]of this.openCountRequests)r.reject(new Error(t));this.openCountRequests.clear()}get connected(){return this._connected}async reconnect(){const t=this.resubscribeBackoff[Math.min(this.reconnectAttempts,this.resubscribeBackoff.length-1)];this.reconnectAttempts++,this.reconnectTimeoutHandle=setTimeout(async()=>{try{await this.connect()}catch{}},t)}handleHardClose(t){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))}async connect(t){let e;return this.connectionPromise?this.connectionPromise:(this.challenge=void 0,this.authPromise=void 0,this.skipReconnection=!1,this.connectionPromise=new Promise((r,n)=>{t?.timeout&&(e=setTimeout(()=>{n("connection timed out"),this.connectionPromise=void 0,this.skipReconnection=!0,this.onclose?.(),this.handleHardClose("relay connection timed out")},t.timeout)),t?.abort&&(t.abort.onabort=n);try{this.ws=new this._WebSocket(this.url)}catch(i){clearTimeout(e),n(i);return}this.ws.onopen=()=>{this.reconnectTimeoutHandle&&(clearTimeout(this.reconnectTimeoutHandle),this.reconnectTimeoutHandle=void 0),clearTimeout(e),this._connected=!0;const i=this.reconnectAttempts>0;this.reconnectAttempts=0;for(const s of this.openSubs.values()){if(s.eosed=!1,i)for(let o=0;o<s.filters.length;o++)s.lastEmitted&&(s.filters[o].since=s.lastEmitted+1);s.fire()}this.enablePing&&(this.pingIntervalHandle=setInterval(()=>this.pingpong(),this.pingFrequency)),r()},this.ws.onerror=()=>{clearTimeout(e),n("connection failed"),this.connectionPromise=void 0,this.skipReconnection=!0,this.onclose?.(),this.handleHardClose("relay connection failed")},this.ws.onclose=i=>{clearTimeout(e),n(i.message||"websocket closed"),this.handleHardClose("relay connection closed")},this.ws.onmessage=this._onmessage.bind(this)}),this.connectionPromise)}waitForPingPong(){return new Promise(t=>{this.ws.once("pong",()=>t(!0)),this.ws.ping()})}waitForDummyReq(){return new Promise((t,e)=>{if(!this.connectionPromise)return e(new Error(`no connection to ${this.url}, can't ping`));try{const r=this.subscribe([{ids:["aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"],limit:0}],{label:"<forced-ping>",oneose:()=>{t(!0),r.close()},onclose(){t(!0)},eoseTimeout:this.pingTimeout+1e3})}catch(r){e(r)}})}async pingpong(){this.ws?.readyState===1&&(await Promise.any([this.ws&&this.ws.ping&&this.ws.once?this.waitForPingPong():this.waitForDummyReq(),new Promise(e=>setTimeout(()=>e(!1),this.pingTimeout))])||this.ws?.readyState===this._WebSocket.OPEN&&this.ws?.close())}async send(t){if(!this.connectionPromise)throw new or(t,this.url);this.connectionPromise.then(()=>{this.ws?.send(t)})}async auth(t){const e=this.challenge;if(!e)throw new Error("can't perform auth, no challenge was received");return this.authPromise?this.authPromise:(this.authPromise=new Promise(async(r,n)=>{try{let i=await t(ds(this.url,e)),s=setTimeout(()=>{let o=this.openEventPublishes.get(i.id);o&&(o.reject(new Error("auth timed out")),this.openEventPublishes.delete(i.id))},this.publishTimeout);this.openEventPublishes.set(i.id,{resolve:r,reject:n,timeout:s}),this.send('["AUTH",'+JSON.stringify(i)+"]")}catch(i){console.warn("subscribe auth function failed:",i)}}),this.authPromise)}async publish(t){this.idleSince=void 0,this.ongoingOperations++;const e=new Promise((r,n)=>{const i=setTimeout(()=>{const s=this.openEventPublishes.get(t.id);s&&(s.reject(new Error("publish timed out")),this.openEventPublishes.delete(t.id))},this.publishTimeout);this.openEventPublishes.set(t.id,{resolve:r,reject:n,timeout:i})});return this.send('["EVENT",'+JSON.stringify(t)+"]"),this.ongoingOperations--,this.ongoingOperations===0&&(this.idleSince=Date.now()),e}async count(t,e){this.serial++;const r=e?.id||"count:"+this.serial,n=new Promise((i,s)=>{this.openCountRequests.set(r,{resolve:i,reject:s})});return this.send('["COUNT","'+r+'",'+JSON.stringify(t).substring(1)),n}subscribe(t,e){e.label!=="<forced-ping>"&&(this.idleSince=void 0,this.ongoingOperations++);const r=this.prepareSubscription(t,e);return r.fire(),e.abort&&(e.abort.onabort=()=>r.close(String(e.abort.reason||"<aborted>"))),r}prepareSubscription(t,e){this.serial++;const r=e.id||(e.label?e.label+":":"sub:")+this.serial,n=new hs(this,r,t,e);return this.openSubs.set(r,n),n}close(){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()}_onmessage(t){const e=t.data;if(!e)return;const r=fs(e);if(r){const n=this.openSubs.get(r);if(!n)return;const i=ls(e,"id"),s=n.alreadyHaveEvent?.(i);if(n.receivedEvent?.(this,i),s)return}try{let n=JSON.parse(e);switch(n[0]){case"EVENT":{const i=this.openSubs.get(n[1]),s=n[2];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);return}case"COUNT":{const i=n[1],s=n[2],o=this.openCountRequests.get(i);o&&(o.resolve(s.count),this.openCountRequests.delete(i));return}case"EOSE":{const i=this.openSubs.get(n[1]);if(!i)return;i.receivedEose();return}case"OK":{const i=n[1],s=n[2],o=n[3],a=this.openEventPublishes.get(i);a&&(clearTimeout(a.timeout),s?a.resolve(o):a.reject(new Error(o)),this.openEventPublishes.delete(i));return}case"CLOSED":{const i=n[1],s=this.openSubs.get(i);if(!s)return;s.closed=!0,s.close(n[2]);return}case"NOTICE":{this.onnotice(n[1]);return}case"AUTH":{this.challenge=n[1],this.onauth&&this.auth(this.onauth);return}default:{this.openSubs.get(n[1])?.oncustom?.(n);return}}}catch(n){try{const[i,s,o]=JSON.parse(e);console.warn(`[nostr] relay ${this.url} error processing message:`,n,o)}catch{console.warn(`[nostr] relay ${this.url} error processing message:`,n)}return}}},hs=class{relay;id;lastEmitted;closed=!1;eosed=!1;filters;alreadyHaveEvent;receivedEvent;onevent;oninvalidevent;oneose;onclose;oncustom;eoseTimeout;eoseTimeoutHandle;constructor(t,e,r,n){if(r.length===0)throw new Error("subscription can't be created with zero filters");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=>{console.warn(`onevent() callback not defined for subscription '${this.id}' in relay ${this.relay.url}. event received:`,i)})}fire(){this.relay.send('["REQ","'+this.id+'",'+JSON.stringify(this.filters).substring(1)),this.eoseTimeoutHandle=setTimeout(this.receivedEose.bind(this),this.eoseTimeout)}receivedEose(){this.eosed||(clearTimeout(this.eoseTimeoutHandle),this.eosed=!0,this.oneose?.())}close(t="closed by caller"){if(!this.closed&&this.relay.connected){try{this.relay.send('["CLOSE",'+JSON.stringify(this.id)+"]")}catch(e){if(!(e instanceof or))throw e}this.closed=!0}this.relay.openSubs.delete(this.id),this.relay.ongoingOperations--,this.relay.ongoingOperations===0&&(this.relay.idleSince=Date.now()),this.onclose?.(t)}},gs=t=>(t[Be]=!0,!0),ps=class{relays=new Map;seenOn=new Map;trackRelays=!1;verifyEvent;enablePing;enableReconnect;automaticallyAuth;trustedRelayURLs=new Set;onRelayConnectionFailure;onRelayConnectionSuccess;allowConnectingToRelay;maxWaitForConnection;_WebSocket;constructor(t){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}async ensureRelay(t,e){t=qe(t);let r=this.relays.get(t);if(r||(r=new ar(t,{verifyEvent:this.trustedRelayURLs.has(t)?gs:this.verifyEvent,websocketImplementation:this._WebSocket,enablePing:this.enablePing,enableReconnect:this.enableReconnect}),r.onclose=()=>{this.relays.delete(t)},this.relays.set(t,r)),this.automaticallyAuth){const n=this.automaticallyAuth(t);n&&(r.onauth=n)}try{await r.connect({timeout:e?.connectionTimeout,abort:e?.abort})}catch(n){throw this.relays.delete(t),n}return r}close(t){t.map(qe).forEach(e=>{this.relays.get(e)?.close(),this.relays.delete(e)})}subscribe(t,e,r){const n=[],i=[];for(let s=0;s<t.length;s++){const o=qe(t[s]);n.find(a=>a.url===o)||i.indexOf(o)===-1&&(i.push(o),n.push({url:o,filter:e}))}return this.subscribeMap(n,r)}subscribeMany(t,e,r){return this.subscribe(t,e,r)}subscribeMap(t,e){const r=new Map;for(const _ of t){const{url:k,filter:P}=_;r.has(k)||r.set(k,[]),r.get(k).push(P)}const n=Array.from(r.entries()).map(([_,k])=>({url:_,filters:k}));this.trackRelays&&(e.receivedEvent=(_,k)=>{let P=this.seenOn.get(k);P||(P=new Set,this.seenOn.set(k,P)),P.add(_)});const i=new Set,s=[],o=[];let a=_=>{o[_]||(o[_]=!0,o.filter(k=>k).length===n.length&&(e.oneose?.(),a=()=>{}))};const u=[];let w=(_,k)=>{u[_]||(a(_),u[_]=k,u.filter(P=>P).length===n.length&&(e.onclose?.(u),w=()=>{}))};const T=_=>{if(e.alreadyHaveEvent?.(_))return!0;const k=i.has(_);return i.add(_),k},R=Promise.all(n.map(async({url:_,filters:k},P)=>{if(this.allowConnectingToRelay?.(_,["read",k])===!1){w(P,"connection skipped by allowConnectingToRelay");return}let q;try{q=await this.ensureRelay(_,{connectionTimeout:this.maxWaitForConnection<(e.maxWait||0)?Math.max(e.maxWait*.8,e.maxWait-1e3):this.maxWaitForConnection,abort:e.abort})}catch(H){this.onRelayConnectionFailure?.(_),w(P,H?.message||String(H));return}this.onRelayConnectionSuccess?.(_);let U=q.subscribe(k,{...e,oneose:()=>a(P),onclose:H=>{H.startsWith("auth-required: ")&&e.onauth?q.auth(e.onauth).then(()=>{q.subscribe(k,{...e,oneose:()=>a(P),onclose:W=>{w(P,W)},alreadyHaveEvent:T,eoseTimeout:e.maxWait,abort:e.abort})}).catch(W=>{w(P,`auth was required and attempted, but failed with: ${W}`)}):w(P,H)},alreadyHaveEvent:T,eoseTimeout:e.maxWait,abort:e.abort});s.push(U)}));return{async close(_){await R,s.forEach(k=>{k.close(_)})}}}subscribeEose(t,e,r){let n;return n=this.subscribe(t,e,{...r,oneose(){const i="closed automatically on eose";n?n.close(i):r.onclose?.(t.map(s=>i))}}),n}subscribeManyEose(t,e,r){return this.subscribeEose(t,e,r)}async querySync(t,e,r){return new Promise(async n=>{const i=[];this.subscribeEose(t,e,{...r,onevent(s){i.push(s)},onclose(s){n(i)}})})}async get(t,e,r){e.limit=1;const n=await this.querySync(t,e,r);return n.sort((i,s)=>s.created_at-i.created_at),n[0]||null}publish(t,e,r){return t.map(qe).map(async(n,i,s)=>{if(s.indexOf(n)!==i)return Promise.reject("duplicate url");if(this.allowConnectingToRelay?.(n,["write",e])===!1)return Promise.reject("connection skipped by allowConnectingToRelay");let o;try{o=await this.ensureRelay(n,{connectionTimeout:this.maxWaitForConnection<(r?.maxWait||0)?Math.max(r.maxWait*.8,r.maxWait-1e3):this.maxWaitForConnection,abort:r?.abort})}catch(a){return this.onRelayConnectionFailure?.(n),"connection failure: "+String(a)}return o.publish(e).catch(async a=>{if(a instanceof Error&&a.message.startsWith("auth-required: ")&&r?.onauth)return await o.auth(r.onauth),o.publish(e);throw a}).then(a=>{if(this.trackRelays){let u=this.seenOn.get(e.id);u||(u=new Set,this.seenOn.set(e.id,u)),u.add(o)}return a})})}listConnectionStatus(){const t=new Map;return this.relays.forEach((e,r)=>t.set(r,e.connected)),t}destroy(){this.relays.forEach(t=>t.close()),this.relays=new Map}pruneIdleRelays(t=1e4){const e=[];for(const[r,n]of this.relays)n.idleSince&&Date.now()-n.idleSince>=t&&(this.relays.delete(r),e.push(r),n.close());return e}},cr;try{cr=WebSocket}catch{}var bs=class extends ps{constructor(t){super({verifyEvent:Qn,websocketImplementation:cr,maxWaitForConnection:3e3,...t})}},ur;try{ur=fetch}catch{}var ys=/^bunker:\/\/([0-9a-f]{64})\??([?\/\w:.=&%-]*)$/;async function ws(t){let e=t.match(ys);if(e)try{const r=e[1],n=new URLSearchParams(e[2]);return{pubkey:r,relays:n.getAll("relay"),secret:n.get("secret")}}catch{}return vs(t)}async function vs(t){const e=t.match(ss);if(!e)return null;const[r,n="_",i]=e;try{const s=`https://${i}/.well-known/nostr.json?name=${n}`,o=await(await ur(s,{redirect:"error"})).json();let a=o.names[n],u=o.nip46[a]||[];return{pubkey:a,relays:u,secret:null}}catch{return null}}function ms(t){const e=new URLSearchParams;return t.relays.forEach(r=>{e.append("relay",r)}),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()}`}var it=class{params;pool;subCloser;isOpen;serial;idPrefix;listeners;waitingForAuth;secretKey;conversationKey;bp;cachedPubKey;constructor(t,e){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={}}static fromBunker(t,e,r={}){if(e.relays.length===0)throw new Error("no relays specified for this bunker");const n=new it(t,r);return n.conversationKey=Mt(t,e.pubkey),n.bp=e,n.setupSubscription(),n}static async fromURI(t,e,r={},n=3e5){const i=new it(t,r),s=new URL(e),o=Xn(t);return new Promise((a,u)=>{let w=!1;const T=i.pool.subscribe(s.searchParams.getAll("relay"),{kinds:[Nt],"#p":[o],limit:0},{onevent:async R=>{try{const _=Mt(t,R.pubkey),k=sr(R.content,_);JSON.parse(k).result===s.searchParams.get("secret")&&(T.close(),i.bp={pubkey:R.pubkey,relays:s.searchParams.getAll("relay"),secret:s.searchParams.get("secret")},i.conversationKey=Mt(t,R.pubkey),i.setupSubscription(),w=!0,await Promise.race([new Promise(q=>setTimeout(q,1e3)),i.switchRelays()]),a(i))}catch(_){console.warn("failed to process potential connection event",_)}},onclose:()=>{w||u(new Error("subscription closed before connection was established."))},maxWait:typeof n=="number"?n:void 0,abort:typeof n!="number"?n:void 0})})}setupSubscription(){const t=this.listeners,e=this.waitingForAuth,r=this.conversationKey;this.subCloser=this.pool.subscribe(this.bp.relays,{kinds:[Nt],authors:[this.bp.pubkey],"#p":[Xn(this.secretKey)],limit:0},{onevent:async n=>{const i=JSON.parse(sr(n.content,r)),{id:s,result:o,error:a}=i;if(o==="auth_url"&&e[s]){delete e[s],this.params.onauth?this.params.onauth(a):console.warn(`nostr-tools/nip46: remote signer ${this.bp.pubkey} tried to send an "auth_url"='${a}' but there was no onauth() callback configured.`);return}let u=t[s];u&&(a?u.reject(a):o&&u.resolve(o),delete t[s])},onclose:()=>{this.subCloser=void 0}}),this.isOpen=!0}async switchRelays(){try{const t=await this.sendRequest("switch_relays",[]);let e=JSON.parse(t);if(!e||JSON.stringify(e.sort())===JSON.stringify(this.bp.relays))return!1;this.bp.relays=e;let r=this.subCloser;return setTimeout(()=>{r.close()},5e3),this.subCloser=void 0,this.setupSubscription(),!0}catch{return!1}}async close(){this.isOpen=!1,this.subCloser.close()}async sendRequest(t,e){return new Promise(async(r,n)=>{try{if(!this.isOpen)throw new Error("this signer is not open anymore, create a new one");this.subCloser||this.setupSubscription(),this.serial++;const i=`${this.idPrefix}-${this.serial}`,s=is(JSON.stringify({id:i,method:t,params:e}),this.conversationKey),o=Qi({kind:Nt,tags:[["p",this.bp.pubkey]],content:s,created_at:Math.floor(Date.now()/1e3)},this.secretKey);this.listeners[i]={resolve:r,reject:n},this.waitingForAuth[i]=!0,await Promise.any(this.pool.publish(this.bp.relays,o))}catch(i){n(i)}})}async ping(){let t=await this.sendRequest("ping",[]);if(t!=="pong")throw new Error(`result is not pong: ${t}`)}async connect(){await this.sendRequest("connect",[this.bp.pubkey,this.bp.secret||""])}async getPublicKey(){return this.cachedPubKey||(this.cachedPubKey=await this.sendRequest("get_public_key",[])),this.cachedPubKey}async signEvent(t){let e=await this.sendRequest("sign_event",[JSON.stringify(t)]),r=JSON.parse(e);if(Qn(r))return r;throw new Error(`event returned from bunker is improperly signed: ${JSON.stringify(r)}`)}async nip04Encrypt(t,e){return await this.sendRequest("nip04_encrypt",[t,e])}async nip04Decrypt(t,e){return await this.sendRequest("nip04_decrypt",[t,e])}async nip44Encrypt(t,e){return await this.sendRequest("nip44_encrypt",[t,e])}async nip44Decrypt(t,e){return await this.sendRequest("nip44_decrypt",[t,e])}};const xs="wss://bucket.coracle.social";function Es(){return!!window.nostr}function ks(){if(!window.nostr)throw new Error("No Nostr signer extension found");const t=window.nostr;return{getPublicKey:()=>t.getPublicKey(),signEvent:e=>t.signEvent(e),close(){}}}async function As(t){const e=Vn(),r=await ws(t);if(!r)throw new Error("Invalid bunker URI");const n=it.fromBunker(e,r);return await n.connect(),lr(n)}function Ss(t){const e=Vn(),r=Ii(e),n=Array.from(crypto.getRandomValues(new Uint8Array(16)),s=>s.toString(16).padStart(2,"0")).join(""),i=ms({clientPubkey:r,relays:[t],secret:n,name:"nsite deploy"});return{uri:i,async connect(s){const o=await it.fromURI(e,i,{},s??3e5);return lr(o)}}}function lr(t){return{getPublicKey:()=>t.getPublicKey(),signEvent:e=>t.signEvent(e),close:()=>t.close()}}const Dt=class Dt extends HTMLElement{constructor(){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=rn(this.ctx),this.manifestPromise.then(e=>{e&&(this.thieves=Dr(e),this.thieves.length>0&&this.state==="idle"&&this.render())}),this.render())}attributeChangedCallback(){this.state==="idle"&&this.render()}get buttonLabel(){return this.getAttribute("label")||"Borrow this"}esc(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}modal(e){return`<div class="nd-overlay"><div class="nd-modal">${e}</div></div>`}render(){this.preserveFormValues();let e=`<style>${pr}</style>`;switch(this.state){case"idle":e+=`<button class="nd-trigger" part="trigger">${this.esc(this.buttonLabel)}</button>`,e+=this.paperTrailContent();break;case"auth":e+=`<button class="nd-trigger" disabled>${this.esc(this.buttonLabel)}</button>`,e+=this.modal(this.authContent());break;case"connecting":e+='<button class="nd-trigger" disabled>Connecting...</button>',e+=this.modal(`
443
+ <div class="nd-header">
444
+ <h2 class="nd-title">Connecting</h2>
445
+ <button class="nd-close" data-action="close">&times;</button>
446
+ </div>
447
+ <div class="nd-msg"><span class="nd-spinner"></span>${this.esc(this.statusMsg)}</div>
448
+ `);break;case"loading":e+='<button class="nd-trigger" disabled>Loading...</button>',e+=this.modal(`
449
+ <div class="nd-msg"><span class="nd-spinner"></span>Fetching site manifest...</div>
450
+ `);break;case"form":e+=`<button class="nd-trigger" disabled>${this.esc(this.buttonLabel)}</button>`,e+=this.modal(this.formContent());break;case"confirm":e+=`<button class="nd-trigger" disabled>${this.esc(this.buttonLabel)}</button>`,e+=this.modal(this.confirmContent());break;case"deploying":e+='<button class="nd-trigger" disabled>Deploying...</button>',e+=this.modal(`
451
+ <h2 class="nd-title">Deploying</h2>
452
+ <div class="nd-msg"><span class="nd-spinner"></span>${this.esc(this.statusMsg)}</div>
453
+ `);break;case"success":e+='<button class="nd-trigger" disabled>Deployed!</button>',e+=this.modal(`
454
+ <div class="nd-header">
455
+ <h2 class="nd-title">Deployed!</h2>
456
+ <button class="nd-close" data-action="close">&times;</button>
457
+ </div>
458
+ <div class="nd-status nd-status-ok">Your site is live</div>
459
+ <a class="nd-link" href="${this.esc(this.deployedUrl)}" target="_blank" rel="noopener">${this.esc(this.deployedUrl)}</a>
460
+ <div class="nd-actions">
461
+ <button class="nd-btn nd-btn-secondary" data-action="close">Close</button>
462
+ </div>
463
+ `);break;case"error":e+=`<button class="nd-trigger" part="trigger">${this.esc(this.buttonLabel)}</button>`,e+=this.modal(`
464
+ <div class="nd-header">
465
+ <h2 class="nd-title">Error</h2>
466
+ <button class="nd-close" data-action="close">&times;</button>
467
+ </div>
468
+ <div class="nd-status nd-status-err">${this.esc(this.errorMsg)}</div>
469
+ <div class="nd-actions">
470
+ <button class="nd-btn nd-btn-secondary" data-action="close">Close</button>
471
+ </div>
472
+ `);break}this.shadow.innerHTML=e,this.bind()}paperTrailContent(){if(this.thieves.length===0)return"";let e=`<div class="nd-trail">
473
+ <button class="nd-trail-toggle" data-action="toggle-trail">Stolen by ${this.thieves.length} npub${this.thieves.length===1?"":"s"}</button>`;if(this.thievesExpanded){e+='<div class="nd-trail-list">';const r=this.thieves[0],n=this.thieves.length>1?this.thieves[1]:null;if(e+=this.thiefItem(r),n&&n.index>r.index+1){const i=n.index-r.index-1;e+=`<div class="nd-trail-gap">... ${i} more</div>`}for(let i=1;i<this.thieves.length;i++)e+=this.thiefItem(this.thieves[i]);e+="</div>"}return e+="</div>",e}thiefItem(e){const r=en(e.pubkey),n=r.slice(0,12)+"..."+r.slice(-4);return`<div class="nd-trail-item">
474
+ <span class="nd-trail-idx">#${e.index}</span>
475
+ <span class="nd-trail-pk">${n}</span>
476
+ </div>`}authContent(){const e=Es(),r=this.nostrConnectUri?Zr(this.nostrConnectUri):"";let n=`
477
+ <div class="nd-header">
478
+ <h2 class="nd-title">Sign In</h2>
479
+ <button class="nd-close" data-action="close">&times;</button>
480
+ </div>`;return e&&(n+=`
481
+ <div class="nd-auth-option">
482
+ <button class="nd-btn-ext" data-action="ext">Sign in with Extension</button>
483
+ </div>
484
+ <div class="nd-divider">or</div>`),n+=`
485
+ <div class="nd-auth-option">
486
+ <div class="nd-qr-label" style="margin-bottom:6px">Paste a bunker URI</div>
487
+ <div class="nd-bunker-row">
488
+ <input type="text" placeholder="bunker://..." id="nd-bunker" />
489
+ <button data-action="bunker">Connect</button>
490
+ </div>
491
+ </div>
492
+ <div class="nd-divider">or scan</div>
493
+ <div class="nd-auth-option">
494
+ <div class="nd-qr-wrap">
495
+ <div class="nd-qr-label">Scan with your signer app</div>
496
+ <div class="nd-qr-code">${r}</div>
497
+ <div class="nd-relay-row">
498
+ <label>relay</label>
499
+ <input type="text" id="nd-nip46-relay" value="${this.esc(this.nip46Relay)}" />
500
+ </div>
501
+ <div class="nd-qr-uri">
502
+ <input readonly value="${this.esc(this.nostrConnectUri)}" id="nd-nc-uri" />
503
+ <button data-action="copy-uri">Copy</button>
504
+ </div>
505
+ </div>
506
+ </div>`,n}formContent(){let e=`
507
+ <div class="nd-header">
508
+ <h2 class="nd-title">Deploy this Page</h2>
509
+ <button class="nd-close" data-action="close">&times;</button>
510
+ </div>
511
+ ${this.hasRootSite?`<div class="nd-toggle">
512
+ <button class="nd-toggle-btn ${this.deployAsRoot?"active":""}" data-action="type-root">Root Site</button>
513
+ <button class="nd-toggle-btn ${this.deployAsRoot?"":"active"}" data-action="type-named">Named Site</button>
514
+ </div>`:""}`;return this.deployAsRoot?e+='<div class="nd-root-hint">Your primary site, served at your npub subdomain.</div>':e+=`
515
+ <div class="nd-root-hint">A sub-site with its own name, served alongside your root site.</div>
516
+ <div class="nd-field">
517
+ <label for="nd-slug">Site name</label>
518
+ <input id="nd-slug" type="text" placeholder="my-site" value="${this.esc(this.slug)}" maxlength="13" autocomplete="off" />
519
+ <div class="nd-hint">Lowercase a-z, 0-9, hyphens. 1-13 chars.</div>
520
+ <div class="nd-field-error" id="nd-slug-err"></div>
521
+ </div>`,e+=`
522
+ <div class="nd-field">
523
+ <label for="nd-title">Title</label>
524
+ <input id="nd-title" type="text" placeholder="Optional" value="${this.esc(this.siteTitle)}" />
525
+ </div>
526
+ <div class="nd-field">
527
+ <label for="nd-desc">Description</label>
528
+ <textarea id="nd-desc" placeholder="Optional">${this.esc(this.siteDescription)}</textarea>
529
+ </div>
530
+ <div class="nd-actions">
531
+ <button class="nd-btn nd-btn-secondary" data-action="close">Cancel</button>
532
+ <button class="nd-btn nd-btn-primary" data-action="deploy" ${this.hasRootSite===null?"disabled":""}>
533
+ ${this.hasRootSite===null?'<span class="nd-spinner"></span>Checking...':"Deploy"}
534
+ </button>
535
+ </div>`,e}confirmContent(){return`
536
+ <div class="nd-header">
537
+ <h2 class="nd-title">Site Already Exists</h2>
538
+ <button class="nd-close" data-action="close">&times;</button>
539
+ </div>
540
+ <div class="nd-warn">
541
+ You already have ${this.deployAsRoot?"a root site":`a site named "${this.esc(this.slug)}"`}. Deploying will replace it with this page's content.
542
+ </div>
543
+ <div class="nd-actions">
544
+ <button class="nd-btn nd-btn-secondary" data-action="back">Back</button>
545
+ <button class="nd-btn nd-btn-warn" data-action="confirm-deploy">Overwrite</button>
546
+ </div>`}bind(){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",()=>{this.thievesExpanded=!this.thievesExpanded,this.render()}),this.shadow.querySelector('[data-action="type-named"]')?.addEventListener("click",()=>{this.deployAsRoot=!1,this.setState("form")}),this.shadow.querySelector('[data-action="type-root"]')?.addEventListener("click",()=>{this.deployAsRoot=!0,this.setState("form")}),this.shadow.querySelector(".nd-overlay")?.addEventListener("click",r=>{r.target.classList.contains("nd-overlay")&&this.close()});const e=this.shadow.querySelector("#nd-nip46-relay");if(e){const r=()=>{const n=e.value.trim();n&&n!==this.nip46Relay&&(this.nip46Relay=n,this.startNostrConnect())};e.addEventListener("blur",r),e.addEventListener("keydown",n=>{n.key==="Enter"&&(n.preventDefault(),r())})}}preserveFormValues(){if(this.state!=="form")return;const e=this.shadow.querySelector("#nd-slug"),r=this.shadow.querySelector("#nd-title"),n=this.shadow.querySelector("#nd-desc");e&&(this.slug=e.value),r&&(this.siteTitle=r.value),n&&(this.siteDescription=n.value)}setState(e){this.state=e,this.render()}close(){this.cancelQr(),this.signer?.close(),this.signer=null,this.setState("idle")}cancelQr(){this.qrAbort?.abort(),this.qrAbort=null,this.ncConnect=null}showError(e){this.errorMsg=e,this.setState("error")}startNostrConnect(){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=>{this.state==="auth"||this.state==="connecting"?(this.signer=e,this.onAuthenticated()):e.close()}).catch(()=>{})}async open(){!this.manifestPromise&&this.ctx&&(this.manifestPromise=rn(this.ctx)),this.state="auth",this.startNostrConnect()}async authExtension(){this.cancelQr();try{this.signer=ks(),this.onAuthenticated()}catch(e){this.showError(e instanceof Error?e.message:String(e))}}async authBunker(){const e=this.shadow.querySelector("#nd-bunker")?.value.trim();if(e){this.cancelQr(),this.statusMsg="Connecting to bunker...",this.setState("connecting");try{this.signer=await As(e),this.onAuthenticated()}catch(r){this.showError(r instanceof Error?r.message:String(r))}}}async copyUri(){try{await navigator.clipboard.writeText(this.nostrConnectUri);const e=this.shadow.querySelector('[data-action="copy-uri"]');e&&(e.textContent="Copied!",setTimeout(()=>{e.isConnected&&(e.textContent="Copy")},2e3))}catch{}}async onAuthenticated(){this.setState("loading");try{if(this.userPubkey=await this.signer.getPublicKey(),this.manifest=await this.manifestPromise,!this.manifest){this.showError("Could not find the site manifest on any relay.");return}this.siteTitle="",this.siteDescription="",this.slug=this.ctx.identifier??"",this.deployAsRoot=!0,this.hasRootSite=null,this.setState("form"),this.relaysPromise=sn(this.userPubkey),this.relaysPromise.then(async e=>{this.userRelays=e;const r=await on(e,this.userPubkey);this.hasRootSite=r,r&&this.state==="form"&&this.deployAsRoot&&(this.deployAsRoot=!1),this.state==="form"&&this.render()})}catch(e){this.showError(e instanceof Error?e.message:String(e))}}readFormValues(){if(!this.deployAsRoot){const n=this.shadow.querySelector("#nd-slug");n&&(this.slug=n.value.trim())}const e=this.shadow.querySelector("#nd-title"),r=this.shadow.querySelector("#nd-desc");e&&(this.siteTitle=e.value.trim()),r&&(this.siteDescription=r.value.trim())}async onDeploy(){if(this.readFormValues(),!this.deployAsRoot){const e=this.shadow.querySelector("#nd-slug-err");if(!this.slug){e.textContent="Site name is required";return}if(!Mr(this.slug)){e.textContent="Lowercase a-z, 0-9, hyphens only. Cannot end with hyphen.";return}}this.statusMsg="Checking for existing site...",this.setState("deploying");try{this.relaysPromise&&(this.userRelays=await this.relaysPromise),this.userRelays.length===0&&(this.userRelays=await sn(this.userPubkey));const e=this.deployAsRoot?void 0:this.slug;if(await on(this.userRelays,this.userPubkey,e)){this.setState("confirm");return}await this.executeDeploy()}catch(e){this.showError(e instanceof Error?e.message:String(e))}}async executeDeploy(){this.statusMsg="Creating event...",this.setState("deploying");try{const e=this.deployAsRoot?void 0:this.slug,r=qr(this.manifest,{slug:e,title:this.siteTitle||void 0,description:this.siteDescription||void 0,deployerPubkey:this.userPubkey,deployerRelays:this.userRelays});this.statusMsg="Waiting for signature...",this.render();const n=await this.signer.signEvent(r);if(this.statusMsg=`Publishing to ${this.userRelays.length} relay${this.userRelays.length===1?"":"s"}...`,this.render(),await $r(this.userRelays,n)===0){this.showError("Failed to publish to any relay. Please try again.");return}this.deployedUrl=Ur(this.ctx.baseDomain,this.userPubkey,e),this.setState("success")}catch(e){this.showError(e instanceof Error?e.message:String(e))}}};Dt.observedAttributes=["label"];let $t=Dt;customElements.define("nsite-deploy",$t);function fr(){if(!document.querySelector("nsite-deploy")){const t=document.createElement("nsite-deploy");t.classList.add("nd-fixed"),document.body.appendChild(t)}}document.readyState==="loading"?document.addEventListener("DOMContentLoaded",fr):fr()})();