window.nostr.js 0.1.3 → 0.1.4

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.
package/dist/index.html CHANGED
@@ -4,7 +4,7 @@
4
4
  <meta charset="UTF-8" />
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
6
  <title>dev</title>
7
- <script type="module" crossorigin src="/assets/index-B9QHMyIY.js"></script>
7
+ <script type="module" crossorigin src="/assets/index-ubxn_Oc5.js"></script>
8
8
  </head>
9
9
  <body
10
10
  style="
@@ -1,5 +1,5 @@
1
- var Yc=Object.defineProperty;var Jc=(jt,R,kt)=>R in jt?Yc(jt,R,{enumerable:!0,configurable:!0,writable:!0,value:kt}):jt[R]=kt;var m=(jt,R,kt)=>(Jc(jt,typeof R!="symbol"?R+"":R,kt),kt);(function(){"use strict";var yo,mo;const jt='.tw-absolute{position:absolute}.tw-right-0{right:0}.tw-right-0\\.5{right:.125rem}.tw-top-0{top:0}.tw-mx-2{margin-left:.5rem;margin-right:.5rem}.tw-my-2{margin-top:.5rem;margin-bottom:.5rem}.tw-mb-1{margin-bottom:.25rem}.tw-mb-2{margin-bottom:.5rem}.tw-mb-4{margin-bottom:1rem}.tw-ml-2{margin-left:.5rem}.tw-mr-2{margin-right:.5rem}.tw-mt-4{margin-top:1rem}.tw-mt-6{margin-top:1.5rem}.tw-box-border{box-sizing:border-box}.tw-block{display:block}.tw-flex{display:flex}.tw-h-10{height:2.5rem}.tw-h-5{height:1.25rem}.tw-w-10{width:2.5rem}.tw-w-40{width:10rem}.tw-w-5{width:1.25rem}.tw-w-full{width:100%}@keyframes tw-moveIn{0%{transform:translateY(-10px)}to{transform:translateY(0)}}.tw-animate-fadein{animation:tw-fadeIn 1s ease-in-out,tw-moveIn 1s ease-in-out}@keyframes tw-fadeIn{0%{opacity:0}to{opacity:1}}.tw-animate-show{animation:tw-fadeIn .2s ease-in-out}@keyframes tw-spin{to{transform:rotate(360deg)}}.tw-animate-spin{animation:tw-spin 1s linear infinite}.tw-cursor-grabbing{cursor:grabbing}.tw-cursor-pointer{cursor:pointer}.tw-items-center{align-items:center}.tw-justify-center{justify-content:center}.tw-gap-2{gap:.5rem}.tw-break-all{word-break:break-all}.tw-rounded{border-radius:.25rem}.tw-rounded-full{border-radius:9999px}.tw-rounded-md{border-radius:.375rem}.tw-border-0{border-width:0px}.tw-border-2{border-width:2px}.tw-border-solid{border-style:solid}.tw-border-none{border-style:none}.tw-border-transparent{border-color:transparent}.tw-bg-cyan-700{--tw-bg-opacity: 1;background-color:rgb(14 116 144 / var(--tw-bg-opacity))}.tw-bg-cyan-800{--tw-bg-opacity: 1;background-color:rgb(21 94 117 / var(--tw-bg-opacity))}.tw-bg-cyan-900{--tw-bg-opacity: 1;background-color:rgb(22 78 99 / var(--tw-bg-opacity))}.tw-bg-cyan-950{--tw-bg-opacity: 1;background-color:rgb(8 51 68 / var(--tw-bg-opacity))}.tw-bg-green-700{--tw-bg-opacity: 1;background-color:rgb(21 128 61 / var(--tw-bg-opacity))}.tw-bg-green-800{--tw-bg-opacity: 1;background-color:rgb(22 101 52 / var(--tw-bg-opacity))}.tw-bg-green-900{--tw-bg-opacity: 1;background-color:rgb(20 83 45 / var(--tw-bg-opacity))}.tw-bg-green-950{--tw-bg-opacity: 1;background-color:rgb(5 46 22 / var(--tw-bg-opacity))}.tw-bg-neutral-700{--tw-bg-opacity: 1;background-color:rgb(64 64 64 / var(--tw-bg-opacity))}.tw-bg-neutral-800{--tw-bg-opacity: 1;background-color:rgb(38 38 38 / var(--tw-bg-opacity))}.tw-bg-neutral-900{--tw-bg-opacity: 1;background-color:rgb(23 23 23 / var(--tw-bg-opacity))}.tw-bg-neutral-950{--tw-bg-opacity: 1;background-color:rgb(10 10 10 / var(--tw-bg-opacity))}.tw-bg-orange-700{--tw-bg-opacity: 1;background-color:rgb(194 65 12 / var(--tw-bg-opacity))}.tw-bg-orange-800{--tw-bg-opacity: 1;background-color:rgb(154 52 18 / var(--tw-bg-opacity))}.tw-bg-orange-900{--tw-bg-opacity: 1;background-color:rgb(124 45 18 / var(--tw-bg-opacity))}.tw-bg-orange-950{--tw-bg-opacity: 1;background-color:rgb(67 20 7 / var(--tw-bg-opacity))}.tw-bg-purple-700{--tw-bg-opacity: 1;background-color:rgb(126 34 206 / var(--tw-bg-opacity))}.tw-bg-purple-800{--tw-bg-opacity: 1;background-color:rgb(107 33 168 / var(--tw-bg-opacity))}.tw-bg-purple-900{--tw-bg-opacity: 1;background-color:rgb(88 28 135 / var(--tw-bg-opacity))}.tw-bg-purple-950{--tw-bg-opacity: 1;background-color:rgb(59 7 100 / var(--tw-bg-opacity))}.tw-bg-red-700{--tw-bg-opacity: 1;background-color:rgb(185 28 28 / var(--tw-bg-opacity))}.tw-bg-red-800{--tw-bg-opacity: 1;background-color:rgb(153 27 27 / var(--tw-bg-opacity))}.tw-bg-red-900{--tw-bg-opacity: 1;background-color:rgb(127 29 29 / var(--tw-bg-opacity))}.tw-bg-red-950{--tw-bg-opacity: 1;background-color:rgb(69 10 10 / var(--tw-bg-opacity))}.tw-bg-stone-700{--tw-bg-opacity: 1;background-color:rgb(68 64 60 / var(--tw-bg-opacity))}.tw-bg-stone-800{--tw-bg-opacity: 1;background-color:rgb(41 37 36 / var(--tw-bg-opacity))}.tw-bg-stone-900{--tw-bg-opacity: 1;background-color:rgb(28 25 23 / var(--tw-bg-opacity))}.tw-bg-stone-950{--tw-bg-opacity: 1;background-color:rgb(12 10 9 / var(--tw-bg-opacity))}.tw-bg-transparent{background-color:transparent}.tw-px-2{padding-left:.5rem;padding-right:.5rem}.tw-px-4{padding-left:1rem;padding-right:1rem}.tw-px-6{padding-left:1.5rem;padding-right:1.5rem}.tw-py-1{padding-top:.25rem;padding-bottom:.25rem}.tw-py-2{padding-top:.5rem;padding-bottom:.5rem}.tw-py-8{padding-top:2rem;padding-bottom:2rem}.tw-text-center{text-align:center}.tw-font-sans{font-family:ui-sans-serif,system-ui,sans-serif,"Apple Color Emoji","Segoe UI Emoji",Segoe UI Symbol,"Noto Color Emoji"}.tw-text-2xl{font-size:1.5rem;line-height:2rem}.tw-text-3xl{font-size:1.875rem;line-height:2.25rem}.tw-text-lg{font-size:1.125rem;line-height:1.75rem}.tw-text-sm{font-size:.875rem;line-height:1.25rem}.tw-leading-3{line-height:.75rem}.tw-leading-4{line-height:1rem}.tw-text-cyan-950{--tw-text-opacity: 1;color:rgb(8 51 68 / var(--tw-text-opacity))}.tw-text-green-950{--tw-text-opacity: 1;color:rgb(5 46 22 / var(--tw-text-opacity))}.tw-text-neutral-950{--tw-text-opacity: 1;color:rgb(10 10 10 / var(--tw-text-opacity))}.tw-text-orange-950{--tw-text-opacity: 1;color:rgb(67 20 7 / var(--tw-text-opacity))}.tw-text-purple-950{--tw-text-opacity: 1;color:rgb(59 7 100 / var(--tw-text-opacity))}.tw-text-red-950{--tw-text-opacity: 1;color:rgb(69 10 10 / var(--tw-text-opacity))}.tw-text-stone-950{--tw-text-opacity: 1;color:rgb(12 10 9 / var(--tw-text-opacity))}.tw-text-white{--tw-text-opacity: 1;color:rgb(255 255 255 / var(--tw-text-opacity))}.tw-underline{text-decoration-line:underline}.tw-no-underline{text-decoration-line:none}.tw-decoration-2{text-decoration-thickness:2px}.tw-underline-offset-4{text-underline-offset:4px}.tw-opacity-25{opacity:.25}.tw-opacity-75{opacity:.75}.tw-shadow-\\[0_0px_10px_0px_rgba\\(0\\,0\\,0\\,0\\.3\\)\\]{--tw-shadow: 0 0px 10px 0px rgba(0,0,0,.3);--tw-shadow-colored: 0 0px 10px 0px var(--tw-shadow-color);box-shadow:var(--tw-ring-offset-shadow, 0 0 #0000),var(--tw-ring-shadow, 0 0 #0000),var(--tw-shadow)}.tw-shadow-\\[0_0px_30px_0px_rgba\\(0\\,0\\,0\\,0\\.6\\)\\]{--tw-shadow: 0 0px 30px 0px rgba(0,0,0,.6);--tw-shadow-colored: 0 0px 30px 0px var(--tw-shadow-color);box-shadow:var(--tw-ring-offset-shadow, 0 0 #0000),var(--tw-ring-shadow, 0 0 #0000),var(--tw-shadow)}.tw-outline-none{outline:2px solid transparent;outline-offset:2px}.tw-outline-dashed{outline-style:dashed}.tw-outline-1{outline-width:1px}.tw-outline-offset-4{outline-offset:4px}.tw-outline-cyan-500{outline-color:#06b6d4}.tw-outline-green-500{outline-color:#22c55e}.tw-outline-neutral-500{outline-color:#737373}.tw-outline-orange-500{outline-color:#f97316}.tw-outline-purple-500{outline-color:#a855f7}.tw-outline-red-500{outline-color:#ef4444}.tw-outline-stone-500{outline-color:#78716c}.tw-transition-all{transition-property:all;transition-timing-function:cubic-bezier(.4,0,.2,1);transition-duration:.15s}.tw-duration-200{transition-duration:.2s}.disabled\\:tw-cursor-default:disabled{cursor:default}.disabled\\:tw-bg-neutral-400:disabled{--tw-bg-opacity: 1;background-color:rgb(163 163 163 / var(--tw-bg-opacity))}.disabled\\:tw-text-neutral-200:disabled{--tw-text-opacity: 1;color:rgb(229 229 229 / var(--tw-text-opacity))}.tw-group:hover .group-hover\\:tw-underline{text-decoration-line:underline}@media (min-width: 640px){.sm\\:tw-w-80{width:20rem}}';function R(){}function kt(t){return t()}function qn(){return Object.create(null)}function At(t){t.forEach(kt)}function jn(t){return typeof t=="function"}function je(t,e){return t!=t?e==e:t!==e||t&&typeof t=="object"||typeof t=="function"}let ge;function be(t,e){return t===e?!0:(ge||(ge=document.createElement("a")),ge.href=e,t===ge.href)}function vo(t){return Object.keys(t).length===0}function _o(t,...e){if(t==null){for(const r of e)r(void 0);return R}const n=t.subscribe(...e);return n.unsubscribe?()=>n.unsubscribe():n}function So(t,e,n){t.$$.on_destroy.push(_o(e,n))}const ko=typeof window<"u"?window:typeof globalThis<"u"?globalThis:global;function U(t,e){t.appendChild(e)}function j(t,e,n){t.insertBefore(e,n||null)}function H(t){t.parentNode&&t.parentNode.removeChild(t)}function Ao(t,e){for(let n=0;n<t.length;n+=1)t[n]&&t[n].d(e)}function L(t){return document.createElement(t)}function Me(t){return document.createElementNS("http://www.w3.org/2000/svg",t)}function Z(t){return document.createTextNode(t)}function V(){return Z(" ")}function Bo(){return Z("")}function et(t,e,n,r){return t.addEventListener(e,n,r),()=>t.removeEventListener(e,n,r)}function _(t,e,n){n==null?t.removeAttribute(e):t.getAttribute(e)!==n&&t.setAttribute(e,n)}function Oo(t){return Array.from(t.childNodes)}function ye(t,e){e=""+e,t.data!==e&&(t.data=e)}function Gt(t,e){t.value=e??""}function Mn(t,e,n){for(let r=0;r<t.options.length;r+=1){const o=t.options[r];if(o.__value===e){o.selected=!0;return}}(!n||e!==void 0)&&(t.selectedIndex=-1)}function Io(t){const e=t.querySelector(":checked");return e&&e.__value}function zn(t,e,n){t.classList.toggle(e,!!n)}let oe;function ie(t){oe=t}function To(){if(!oe)throw new Error("Function called outside component initialization");return oe}function No(t){To().$$.on_mount.push(t)}const Ft=[],se=[];let Yt=[];const Kn=[],Po=Promise.resolve();let ze=!1;function Uo(){ze||(ze=!0,Po.then(Dn))}function me(t){Yt.push(t)}const Ke=new Set;let Jt=0;function Dn(){if(Jt!==0)return;const t=oe;do{try{for(;Jt<Ft.length;){const e=Ft[Jt];Jt++,ie(e),$o(e.$$)}}catch(e){throw Ft.length=0,Jt=0,e}for(ie(null),Ft.length=0,Jt=0;se.length;)se.pop()();for(let e=0;e<Yt.length;e+=1){const n=Yt[e];Ke.has(n)||(Ke.add(n),n())}Yt.length=0}while(Ft.length);for(;Kn.length;)Kn.pop()();ze=!1,Ke.clear(),ie(t)}function $o(t){if(t.fragment!==null){t.update(),At(t.before_update);const e=t.dirty;t.dirty=[-1],t.fragment&&t.fragment.p(t.ctx,e),t.after_update.forEach(me)}}function Co(t){const e=[],n=[];Yt.forEach(r=>t.indexOf(r)===-1?e.push(r):n.push(r)),n.forEach(r=>r()),Yt=e}const Ee=new Set;let Mt;function xe(){Mt={r:0,c:[],p:Mt}}function ve(){Mt.r||At(Mt.c),Mt=Mt.p}function ut(t,e){t&&t.i&&(Ee.delete(t),t.i(e))}function wt(t,e,n,r){if(t&&t.o){if(Ee.has(t))return;Ee.add(t),Mt.c.push(()=>{Ee.delete(t),r&&(n&&t.d(1),r())}),t.o(e)}else r&&r()}function Vn(t){return(t==null?void 0:t.length)!==void 0?t:Array.from(t)}function Wn(t){t&&t.c()}function De(t,e,n){const{fragment:r,after_update:o}=t.$$;r&&r.m(e,n),me(()=>{const i=t.$$.on_mount.map(kt).filter(jn);t.$$.on_destroy?t.$$.on_destroy.push(...i):At(i),t.$$.on_mount=[]}),o.forEach(me)}function Ve(t,e){const n=t.$$;n.fragment!==null&&(Co(n.after_update),At(n.on_destroy),n.fragment&&n.fragment.d(e),n.on_destroy=n.fragment=null,n.ctx=[])}function Lo(t,e){t.$$.dirty[0]===-1&&(Ft.push(t),Uo(),t.$$.dirty.fill(0)),t.$$.dirty[e/31|0]|=1<<e%31}function Zn(t,e,n,r,o,i,s=null,c=[-1]){const l=oe;ie(t);const a=t.$$={fragment:null,ctx:[],props:i,update:R,not_equal:o,bound:qn(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(e.context||(l?l.$$.context:[])),callbacks:qn(),dirty:c,skip_bound:!1,root:e.target||l.$$.root};s&&s(a.root);let f=!1;if(a.ctx=n?n(t,e.props||{},(u,w,...h)=>{const g=h.length?h[0]:w;return a.ctx&&o(a.ctx[u],a.ctx[u]=g)&&(!a.skip_bound&&a.bound[u]&&a.bound[u](g),f&&Lo(t,u)),w}):[],a.update(),f=!0,At(a.before_update),a.fragment=r?r(a.ctx):!1,e.target){if(e.hydrate){const u=Oo(e.target);a.fragment&&a.fragment.l(u),u.forEach(H)}else a.fragment&&a.fragment.c();e.intro&&ut(t.$$.fragment),De(t,e.target,e.anchor),Dn()}ie(l)}class Gn{constructor(){m(this,"$$");m(this,"$$set")}$destroy(){Ve(this,1),this.$destroy=R}$on(e,n){if(!jn(n))return R;const r=this.$$.callbacks[e]||(this.$$.callbacks[e]=[]);return r.push(n),()=>{const o=r.indexOf(n);o!==-1&&r.splice(o,1)}}$set(e){this.$$set&&!vo(e)&&(this.$$.skip_bound=!0,this.$$set(e),this.$$.skip_bound=!1)}}const Ro="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(Ro);function Ho(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var We={exports:{}};function Fn(t,e=100,n={}){if(typeof t!="function")throw new TypeError(`Expected the first parameter to be a function, got \`${typeof t}\`.`);if(e<0)throw new RangeError("`wait` must not be negative.");const{immediate:r}=typeof n=="boolean"?{immediate:n}:n;let o,i,s,c,l;function a(){const u=Date.now()-c;if(u<e&&u>=0)s=setTimeout(a,e-u);else if(s=void 0,!r){const w=o,h=i;o=void 0,i=void 0,l=t.apply(w,h)}}const f=function(...u){if(o&&this!==o)throw new Error("Debounced method called with different contexts.");o=this,i=u,c=Date.now();const w=r&&!s;if(s||(s=setTimeout(a,e)),w){const h=o,g=i;o=void 0,i=void 0,l=t.apply(h,g)}return l};return f.clear=()=>{s&&(clearTimeout(s),s=void 0)},f.flush=()=>{if(!s)return;const u=o,w=i;o=void 0,i=void 0,l=t.apply(u,w),clearTimeout(s),s=void 0},f}We.exports.debounce=Fn,We.exports=Fn;var qo=We.exports;const Yn=Ho(qo),Ze=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Jn=t=>t instanceof Uint8Array,Ge=t=>new DataView(t.buffer,t.byteOffset,t.byteLength),pt=(t,e)=>t<<32-e|t>>>e;if(!(new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68))throw new Error("Non little-endian hardware is not supported");const jo=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function nt(t){if(!Jn(t))throw new Error("Uint8Array expected");let e="";for(let n=0;n<t.length;n++)e+=jo[t[n]];return e}function Fe(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);const e=t.length;if(e%2)throw new Error("padded hex string expected, got unpadded hex of length "+e);const n=new Uint8Array(e/2);for(let r=0;r<n.length;r++){const o=r*2,i=t.slice(o,o+2),s=Number.parseInt(i,16);if(Number.isNaN(s)||s<0)throw new Error("Invalid byte sequence");n[r]=s}return n}function Mo(t){if(typeof t!="string")throw new Error(`utf8ToBytes expected string, got ${typeof t}`);return new Uint8Array(new TextEncoder().encode(t))}function Qn(t){if(typeof t=="string"&&(t=Mo(t)),!Jn(t))throw new Error(`expected Uint8Array, got ${typeof t}`);return t}let zo=class{clone(){return this._cloneInto()}};function Xn(t){const e=r=>t().update(Qn(r)).digest(),n=t();return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=()=>t(),e}function Ko(t=32){if(Ze&&typeof Ze.getRandomValues=="function")return Ze.getRandomValues(new Uint8Array(t));throw new Error("crypto.getRandomValues must be defined")}function tr(t){if(!Number.isSafeInteger(t)||t<0)throw new Error(`Wrong positive integer: ${t}`)}function er(t,...e){if(!(t instanceof Uint8Array))throw new Error("Expected Uint8Array");if(e.length>0&&!e.includes(t.length))throw new Error(`Expected Uint8Array of length ${e}, not of length=${t.length}`)}function Do(t){if(typeof t!="function"||typeof t.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");tr(t.outputLen),tr(t.blockLen)}function _e(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 Vo(t,e){er(t);const n=e.outputLen;if(t.length<n)throw new Error(`digestInto() expects output buffer of length at least ${n}`)}const Ye=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */const nr=t=>t instanceof Uint8Array,Je=t=>new DataView(t.buffer,t.byteOffset,t.byteLength),gt=(t,e)=>t<<32-e|t>>>e;if(!(new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68))throw new Error("Non little-endian hardware is not supported");function Wo(t){if(typeof t!="string")throw new Error(`utf8ToBytes expected string, got ${typeof t}`);return new Uint8Array(new TextEncoder().encode(t))}function Qe(t){if(typeof t=="string"&&(t=Wo(t)),!nr(t))throw new Error(`expected Uint8Array, got ${typeof t}`);return t}function Zo(...t){const e=new Uint8Array(t.reduce((r,o)=>r+o.length,0));let n=0;return t.forEach(r=>{if(!nr(r))throw new Error("Uint8Array expected");e.set(r,n),n+=r.length}),e}class rr{clone(){return this._cloneInto()}}function Go(t){const e=r=>t().update(Qe(r)).digest(),n=t();return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=()=>t(),e}function or(t=32){if(Ye&&typeof Ye.getRandomValues=="function")return Ye.getRandomValues(new Uint8Array(t));throw new Error("crypto.getRandomValues must be defined")}function Fo(t,e,n,r){if(typeof t.setBigUint64=="function")return t.setBigUint64(e,n,r);const o=BigInt(32),i=BigInt(4294967295),s=Number(n>>o&i),c=Number(n&i),l=r?4:0,a=r?0:4;t.setUint32(e+l,s,r),t.setUint32(e+a,c,r)}let Yo=class extends rr{constructor(e,n,r,o){super(),this.blockLen=e,this.outputLen=n,this.padOffset=r,this.isLE=o,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(e),this.view=Je(this.buffer)}update(e){_e(this);const{view:n,buffer:r,blockLen:o}=this;e=Qe(e);const i=e.length;for(let s=0;s<i;){const c=Math.min(o-this.pos,i-s);if(c===o){const l=Je(e);for(;o<=i-s;s+=o)this.process(l,s);continue}r.set(e.subarray(s,s+c),this.pos),this.pos+=c,s+=c,this.pos===o&&(this.process(n,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){_e(this),Vo(e,this),this.finished=!0;const{buffer:n,view:r,blockLen:o,isLE:i}=this;let{pos:s}=this;n[s++]=128,this.buffer.subarray(s).fill(0),this.padOffset>o-s&&(this.process(r,0),s=0);for(let u=s;u<o;u++)n[u]=0;Fo(r,o-8,BigInt(this.length*8),i),this.process(r,0);const c=Je(e),l=this.outputLen;if(l%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const a=l/4,f=this.get();if(a>f.length)throw new Error("_sha2: outputLen bigger than state");for(let u=0;u<a;u++)c.setUint32(4*u,f[u],i)}digest(){const{buffer:e,outputLen:n}=this;this.digestInto(e);const r=e.slice(0,n);return this.destroy(),r}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());const{blockLen:n,buffer:r,length:o,finished:i,destroyed:s,pos:c}=this;return e.length=o,e.pos=c,e.finished=i,e.destroyed=s,o%n&&e.buffer.set(r),e}};const Jo=(t,e,n)=>t&e^~t&n,Qo=(t,e,n)=>t&e^t&n^e&n,Xo=new Uint32Array([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]),Bt=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Ot=new Uint32Array(64);let ti=class extends Yo{constructor(){super(64,32,8,!1),this.A=Bt[0]|0,this.B=Bt[1]|0,this.C=Bt[2]|0,this.D=Bt[3]|0,this.E=Bt[4]|0,this.F=Bt[5]|0,this.G=Bt[6]|0,this.H=Bt[7]|0}get(){const{A:e,B:n,C:r,D:o,E:i,F:s,G:c,H:l}=this;return[e,n,r,o,i,s,c,l]}set(e,n,r,o,i,s,c,l){this.A=e|0,this.B=n|0,this.C=r|0,this.D=o|0,this.E=i|0,this.F=s|0,this.G=c|0,this.H=l|0}process(e,n){for(let u=0;u<16;u++,n+=4)Ot[u]=e.getUint32(n,!1);for(let u=16;u<64;u++){const w=Ot[u-15],h=Ot[u-2],g=gt(w,7)^gt(w,18)^w>>>3,d=gt(h,17)^gt(h,19)^h>>>10;Ot[u]=d+Ot[u-7]+g+Ot[u-16]|0}let{A:r,B:o,C:i,D:s,E:c,F:l,G:a,H:f}=this;for(let u=0;u<64;u++){const w=gt(c,6)^gt(c,11)^gt(c,25),h=f+w+Jo(c,l,a)+Xo[u]+Ot[u]|0,d=(gt(r,2)^gt(r,13)^gt(r,22))+Qo(r,o,i)|0;f=a,a=l,l=c,c=s+h|0,s=i,i=o,o=r,r=h+d|0}r=r+this.A|0,o=o+this.B|0,i=i+this.C|0,s=s+this.D|0,c=c+this.E|0,l=l+this.F|0,a=a+this.G|0,f=f+this.H|0,this.set(r,o,i,s,c,l,a,f)}roundClean(){Ot.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};const Xe=Go(()=>new ti);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const ir=BigInt(0),Se=BigInt(1),ei=BigInt(2),ke=t=>t instanceof Uint8Array,ni=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function Qt(t){if(!ke(t))throw new Error("Uint8Array expected");let e="";for(let n=0;n<t.length;n++)e+=ni[t[n]];return e}function sr(t){const e=t.toString(16);return e.length&1?`0${e}`:e}function tn(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);return BigInt(t===""?"0":`0x${t}`)}function Xt(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);const e=t.length;if(e%2)throw new Error("padded hex string expected, got unpadded hex of length "+e);const n=new Uint8Array(e/2);for(let r=0;r<n.length;r++){const o=r*2,i=t.slice(o,o+2),s=Number.parseInt(i,16);if(Number.isNaN(s)||s<0)throw new Error("Invalid byte sequence");n[r]=s}return n}function ot(t){return tn(Qt(t))}function en(t){if(!ke(t))throw new Error("Uint8Array expected");return tn(Qt(Uint8Array.from(t).reverse()))}function It(t,e){return Xt(t.toString(16).padStart(e*2,"0"))}function nn(t,e){return It(t,e).reverse()}function ri(t){return Xt(sr(t))}function J(t,e,n){let r;if(typeof e=="string")try{r=Xt(e)}catch(i){throw new Error(`${t} must be valid hex string, got "${e}". Cause: ${i}`)}else if(ke(e))r=Uint8Array.from(e);else throw new Error(`${t} must be hex string or Uint8Array`);const o=r.length;if(typeof n=="number"&&o!==n)throw new Error(`${t} expected ${n} bytes, got ${o}`);return r}function zt(...t){const e=new Uint8Array(t.reduce((r,o)=>r+o.length,0));let n=0;return t.forEach(r=>{if(!ke(r))throw new Error("Uint8Array expected");e.set(r,n),n+=r.length}),e}function oi(t,e){if(t.length!==e.length)return!1;for(let n=0;n<t.length;n++)if(t[n]!==e[n])return!1;return!0}function ii(t){if(typeof t!="string")throw new Error(`utf8ToBytes expected string, got ${typeof t}`);return new Uint8Array(new TextEncoder().encode(t))}function si(t){let e;for(e=0;t>ir;t>>=Se,e+=1);return e}function ci(t,e){return t>>BigInt(e)&Se}const li=(t,e,n)=>t|(n?Se:ir)<<BigInt(e),rn=t=>(ei<<BigInt(t-1))-Se,on=t=>new Uint8Array(t),cr=t=>Uint8Array.from(t);function lr(t,e,n){if(typeof t!="number"||t<2)throw new Error("hashLen must be a number");if(typeof e!="number"||e<2)throw new Error("qByteLen must be a number");if(typeof n!="function")throw new Error("hmacFn must be a function");let r=on(t),o=on(t),i=0;const s=()=>{r.fill(1),o.fill(0),i=0},c=(...u)=>n(o,r,...u),l=(u=on())=>{o=c(cr([0]),u),r=c(),u.length!==0&&(o=c(cr([1]),u),r=c())},a=()=>{if(i++>=1e3)throw new Error("drbg: tried 1000 values");let u=0;const w=[];for(;u<e;){r=c();const h=r.slice();w.push(h),u+=r.length}return zt(...w)};return(u,w)=>{s(),l(u);let h;for(;!(h=w(a()));)l();return s(),h}}const ai={bigint:t=>typeof t=="bigint",function:t=>typeof t=="function",boolean:t=>typeof t=="boolean",string:t=>typeof t=="string",stringOrUint8Array:t=>typeof t=="string"||t instanceof Uint8Array,isSafeInteger:t=>Number.isSafeInteger(t),array:t=>Array.isArray(t),field:(t,e)=>e.Fp.isValid(t),hash:t=>typeof t=="function"&&Number.isSafeInteger(t.outputLen)};function ce(t,e,n={}){const r=(o,i,s)=>{const c=ai[i];if(typeof c!="function")throw new Error(`Invalid validator "${i}", expected function`);const l=t[o];if(!(s&&l===void 0)&&!c(l,t))throw new Error(`Invalid param ${String(o)}=${l} (${typeof l}), expected ${i}`)};for(const[o,i]of Object.entries(e))r(o,i,!1);for(const[o,i]of Object.entries(n))r(o,i,!0);return t}const ui=Object.freeze(Object.defineProperty({__proto__:null,bitGet:ci,bitLen:si,bitMask:rn,bitSet:li,bytesToHex:Qt,bytesToNumberBE:ot,bytesToNumberLE:en,concatBytes:zt,createHmacDrbg:lr,ensureBytes:J,equalBytes:oi,hexToBytes:Xt,hexToNumber:tn,numberToBytesBE:It,numberToBytesLE:nn,numberToHexUnpadded:sr,numberToVarBytesBE:ri,utf8ToBytes:ii,validateObject:ce},Symbol.toStringTag,{value:"Module"}));/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const G=BigInt(0),K=BigInt(1),Kt=BigInt(2),fi=BigInt(3),sn=BigInt(4),ar=BigInt(5),ur=BigInt(8);BigInt(9),BigInt(16);function F(t,e){const n=t%e;return n>=G?n:e+n}function di(t,e,n){if(n<=G||e<G)throw new Error("Expected power/modulo > 0");if(n===K)return G;let r=K;for(;e>G;)e&K&&(r=r*t%n),t=t*t%n,e>>=K;return r}function ct(t,e,n){let r=t;for(;e-- >G;)r*=r,r%=n;return r}function cn(t,e){if(t===G||e<=G)throw new Error(`invert: expected positive integers, got n=${t} mod=${e}`);let n=F(t,e),r=e,o=G,i=K;for(;n!==G;){const c=r/n,l=r%n,a=o-i*c;r=n,n=l,o=i,i=a}if(r!==K)throw new Error("invert: does not exist");return F(o,e)}function hi(t){const e=(t-K)/Kt;let n,r,o;for(n=t-K,r=0;n%Kt===G;n/=Kt,r++);for(o=Kt;o<t&&di(o,e,t)!==t-K;o++);if(r===1){const s=(t+K)/sn;return function(l,a){const f=l.pow(a,s);if(!l.eql(l.sqr(f),a))throw new Error("Cannot find square root");return f}}const i=(n+K)/Kt;return function(c,l){if(c.pow(l,e)===c.neg(c.ONE))throw new Error("Cannot find square root");let a=r,f=c.pow(c.mul(c.ONE,o),n),u=c.pow(l,i),w=c.pow(l,n);for(;!c.eql(w,c.ONE);){if(c.eql(w,c.ZERO))return c.ZERO;let h=1;for(let d=c.sqr(w);h<a&&!c.eql(d,c.ONE);h++)d=c.sqr(d);const g=c.pow(f,K<<BigInt(a-h-1));f=c.sqr(g),u=c.mul(u,g),w=c.mul(w,f),a=h}return u}}function wi(t){if(t%sn===fi){const e=(t+K)/sn;return function(r,o){const i=r.pow(o,e);if(!r.eql(r.sqr(i),o))throw new Error("Cannot find square root");return i}}if(t%ur===ar){const e=(t-ar)/ur;return function(r,o){const i=r.mul(o,Kt),s=r.pow(i,e),c=r.mul(o,s),l=r.mul(r.mul(c,Kt),s),a=r.mul(c,r.sub(l,r.ONE));if(!r.eql(r.sqr(a),o))throw new Error("Cannot find square root");return a}}return hi(t)}const pi=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function gi(t){const e={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},n=pi.reduce((r,o)=>(r[o]="function",r),e);return ce(t,n)}function bi(t,e,n){if(n<G)throw new Error("Expected power > 0");if(n===G)return t.ONE;if(n===K)return e;let r=t.ONE,o=e;for(;n>G;)n&K&&(r=t.mul(r,o)),o=t.sqr(o),n>>=K;return r}function yi(t,e){const n=new Array(e.length),r=e.reduce((i,s,c)=>t.is0(s)?i:(n[c]=i,t.mul(i,s)),t.ONE),o=t.inv(r);return e.reduceRight((i,s,c)=>t.is0(s)?i:(n[c]=t.mul(i,n[c]),t.mul(i,s)),o),n}function fr(t,e){const n=e!==void 0?e:t.toString(2).length,r=Math.ceil(n/8);return{nBitLength:n,nByteLength:r}}function mi(t,e,n=!1,r={}){if(t<=G)throw new Error(`Expected Field ORDER > 0, got ${t}`);const{nBitLength:o,nByteLength:i}=fr(t,e);if(i>2048)throw new Error("Field lengths over 2048 bytes are not supported");const s=wi(t),c=Object.freeze({ORDER:t,BITS:o,BYTES:i,MASK:rn(o),ZERO:G,ONE:K,create:l=>F(l,t),isValid:l=>{if(typeof l!="bigint")throw new Error(`Invalid field element: expected bigint, got ${typeof l}`);return G<=l&&l<t},is0:l=>l===G,isOdd:l=>(l&K)===K,neg:l=>F(-l,t),eql:(l,a)=>l===a,sqr:l=>F(l*l,t),add:(l,a)=>F(l+a,t),sub:(l,a)=>F(l-a,t),mul:(l,a)=>F(l*a,t),pow:(l,a)=>bi(c,l,a),div:(l,a)=>F(l*cn(a,t),t),sqrN:l=>l*l,addN:(l,a)=>l+a,subN:(l,a)=>l-a,mulN:(l,a)=>l*a,inv:l=>cn(l,t),sqrt:r.sqrt||(l=>s(c,l)),invertBatch:l=>yi(c,l),cmov:(l,a,f)=>f?a:l,toBytes:l=>n?nn(l,i):It(l,i),fromBytes:l=>{if(l.length!==i)throw new Error(`Fp.fromBytes: expected ${i}, got ${l.length}`);return n?en(l):ot(l)}});return Object.freeze(c)}function dr(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 hr(t){const e=dr(t);return e+Math.ceil(e/2)}function Ei(t,e,n=!1){const r=t.length,o=dr(e),i=hr(e);if(r<16||r<i||r>1024)throw new Error(`expected ${i}-1024 bytes of input, got ${r}`);const s=n?ot(t):en(t),c=F(s,e-K)+K;return n?nn(c,o):It(c,o)}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const xi=BigInt(0),ln=BigInt(1);function vi(t,e){const n=(o,i)=>{const s=i.negate();return o?s:i},r=o=>{const i=Math.ceil(e/o)+1,s=2**(o-1);return{windows:i,windowSize:s}};return{constTimeNegate:n,unsafeLadder(o,i){let s=t.ZERO,c=o;for(;i>xi;)i&ln&&(s=s.add(c)),c=c.double(),i>>=ln;return s},precomputeWindow(o,i){const{windows:s,windowSize:c}=r(i),l=[];let a=o,f=a;for(let u=0;u<s;u++){f=a,l.push(f);for(let w=1;w<c;w++)f=f.add(a),l.push(f);a=f.double()}return l},wNAF(o,i,s){const{windows:c,windowSize:l}=r(o);let a=t.ZERO,f=t.BASE;const u=BigInt(2**o-1),w=2**o,h=BigInt(o);for(let g=0;g<c;g++){const d=g*l;let p=Number(s&u);s>>=h,p>l&&(p-=w,s+=ln);const b=d,v=d+Math.abs(p)-1,S=g%2!==0,A=p<0;p===0?f=f.add(n(S,i[b])):a=a.add(n(A,i[v]))}return{p:a,f}},wNAFCached(o,i,s,c){const l=o._WINDOW_SIZE||1;let a=i.get(o);return a||(a=this.precomputeWindow(o,l),l!==1&&i.set(o,c(a))),this.wNAF(l,a,s)}}}function wr(t){return gi(t.Fp),ce(t,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...fr(t.n,t.nBitLength),...t,p:t.Fp.ORDER})}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function _i(t){const e=wr(t);ce(e,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});const{endo:n,Fp:r,a:o}=e;if(n){if(!r.eql(o,r.ZERO))throw new Error("Endomorphism can only be defined for Koblitz curves that have a=0");if(typeof n!="object"||typeof n.beta!="bigint"||typeof n.splitScalar!="function")throw new Error("Expected endomorphism with beta: bigint and splitScalar: function")}return Object.freeze({...e})}const{bytesToNumberBE:Si,hexToBytes:ki}=ui,Dt={Err:class extends Error{constructor(e=""){super(e)}},_parseInt(t){const{Err:e}=Dt;if(t.length<2||t[0]!==2)throw new e("Invalid signature integer tag");const n=t[1],r=t.subarray(2,n+2);if(!n||r.length!==n)throw new e("Invalid signature integer: wrong length");if(r[0]&128)throw new e("Invalid signature integer: negative");if(r[0]===0&&!(r[1]&128))throw new e("Invalid signature integer: unnecessary leading zero");return{d:Si(r),l:t.subarray(n+2)}},toSig(t){const{Err:e}=Dt,n=typeof t=="string"?ki(t):t;if(!(n instanceof Uint8Array))throw new Error("ui8a expected");let r=n.length;if(r<2||n[0]!=48)throw new e("Invalid signature tag");if(n[1]!==r-2)throw new e("Invalid signature: incorrect length");const{d:o,l:i}=Dt._parseInt(n.subarray(2)),{d:s,l:c}=Dt._parseInt(i);if(c.length)throw new e("Invalid signature: left bytes after parsing");return{r:o,s}},hexFromSig(t){const e=a=>Number.parseInt(a[0],16)&8?"00"+a:a,n=a=>{const f=a.toString(16);return f.length&1?`0${f}`:f},r=e(n(t.s)),o=e(n(t.r)),i=r.length/2,s=o.length/2,c=n(i),l=n(s);return`30${n(s+i+4)}02${l}${o}02${c}${r}`}},mt=BigInt(0),lt=BigInt(1);BigInt(2);const pr=BigInt(3);BigInt(4);function Ai(t){const e=_i(t),{Fp:n}=e,r=e.toBytes||((g,d,p)=>{const b=d.toAffine();return zt(Uint8Array.from([4]),n.toBytes(b.x),n.toBytes(b.y))}),o=e.fromBytes||(g=>{const d=g.subarray(1),p=n.fromBytes(d.subarray(0,n.BYTES)),b=n.fromBytes(d.subarray(n.BYTES,2*n.BYTES));return{x:p,y:b}});function i(g){const{a:d,b:p}=e,b=n.sqr(g),v=n.mul(b,g);return n.add(n.add(v,n.mul(g,d)),p)}if(!n.eql(n.sqr(e.Gy),i(e.Gx)))throw new Error("bad generator point: equation left != right");function s(g){return typeof g=="bigint"&&mt<g&&g<e.n}function c(g){if(!s(g))throw new Error("Expected valid bigint: 0 < bigint < curve.n")}function l(g){const{allowedPrivateKeyLengths:d,nByteLength:p,wrapPrivateKey:b,n:v}=e;if(d&&typeof g!="bigint"){if(g instanceof Uint8Array&&(g=Qt(g)),typeof g!="string"||!d.includes(g.length))throw new Error("Invalid key");g=g.padStart(p*2,"0")}let S;try{S=typeof g=="bigint"?g:ot(J("private key",g,p))}catch{throw new Error(`private key must be ${p} bytes, hex or bigint, not ${typeof g}`)}return b&&(S=F(S,v)),c(S),S}const a=new Map;function f(g){if(!(g instanceof u))throw new Error("ProjectivePoint expected")}class u{constructor(d,p,b){if(this.px=d,this.py=p,this.pz=b,d==null||!n.isValid(d))throw new Error("x required");if(p==null||!n.isValid(p))throw new Error("y required");if(b==null||!n.isValid(b))throw new Error("z required")}static fromAffine(d){const{x:p,y:b}=d||{};if(!d||!n.isValid(p)||!n.isValid(b))throw new Error("invalid affine point");if(d instanceof u)throw new Error("projective point not allowed");const v=S=>n.eql(S,n.ZERO);return v(p)&&v(b)?u.ZERO:new u(p,b,n.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(d){const p=n.invertBatch(d.map(b=>b.pz));return d.map((b,v)=>b.toAffine(p[v])).map(u.fromAffine)}static fromHex(d){const p=u.fromAffine(o(J("pointHex",d)));return p.assertValidity(),p}static fromPrivateKey(d){return u.BASE.multiply(l(d))}_setWindowSize(d){this._WINDOW_SIZE=d,a.delete(this)}assertValidity(){if(this.is0()){if(e.allowInfinityPoint&&!n.is0(this.py))return;throw new Error("bad point: ZERO")}const{x:d,y:p}=this.toAffine();if(!n.isValid(d)||!n.isValid(p))throw new Error("bad point: x or y not FE");const b=n.sqr(p),v=i(d);if(!n.eql(b,v))throw new Error("bad point: equation left != right");if(!this.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){const{y:d}=this.toAffine();if(n.isOdd)return!n.isOdd(d);throw new Error("Field doesn't support isOdd")}equals(d){f(d);const{px:p,py:b,pz:v}=this,{px:S,py:A,pz:B}=d,y=n.eql(n.mul(p,B),n.mul(S,v)),E=n.eql(n.mul(b,B),n.mul(A,v));return y&&E}negate(){return new u(this.px,n.neg(this.py),this.pz)}double(){const{a:d,b:p}=e,b=n.mul(p,pr),{px:v,py:S,pz:A}=this;let B=n.ZERO,y=n.ZERO,E=n.ZERO,k=n.mul(v,v),C=n.mul(S,S),N=n.mul(A,A),I=n.mul(v,S);return I=n.add(I,I),E=n.mul(v,A),E=n.add(E,E),B=n.mul(d,E),y=n.mul(b,N),y=n.add(B,y),B=n.sub(C,y),y=n.add(C,y),y=n.mul(B,y),B=n.mul(I,B),E=n.mul(b,E),N=n.mul(d,N),I=n.sub(k,N),I=n.mul(d,I),I=n.add(I,E),E=n.add(k,k),k=n.add(E,k),k=n.add(k,N),k=n.mul(k,I),y=n.add(y,k),N=n.mul(S,A),N=n.add(N,N),k=n.mul(N,I),B=n.sub(B,k),E=n.mul(N,C),E=n.add(E,E),E=n.add(E,E),new u(B,y,E)}add(d){f(d);const{px:p,py:b,pz:v}=this,{px:S,py:A,pz:B}=d;let y=n.ZERO,E=n.ZERO,k=n.ZERO;const C=e.a,N=n.mul(e.b,pr);let I=n.mul(p,S),q=n.mul(b,A),P=n.mul(v,B),Q=n.add(p,b),x=n.add(S,A);Q=n.mul(Q,x),x=n.add(I,q),Q=n.sub(Q,x),x=n.add(p,v);let O=n.add(S,B);return x=n.mul(x,O),O=n.add(I,P),x=n.sub(x,O),O=n.add(b,v),y=n.add(A,B),O=n.mul(O,y),y=n.add(q,P),O=n.sub(O,y),k=n.mul(C,x),y=n.mul(N,P),k=n.add(y,k),y=n.sub(q,k),k=n.add(q,k),E=n.mul(y,k),q=n.add(I,I),q=n.add(q,I),P=n.mul(C,P),x=n.mul(N,x),q=n.add(q,P),P=n.sub(I,P),P=n.mul(C,P),x=n.add(x,P),I=n.mul(q,x),E=n.add(E,I),I=n.mul(O,x),y=n.mul(Q,y),y=n.sub(y,I),I=n.mul(Q,q),k=n.mul(O,k),k=n.add(k,I),new u(y,E,k)}subtract(d){return this.add(d.negate())}is0(){return this.equals(u.ZERO)}wNAF(d){return h.wNAFCached(this,a,d,p=>{const b=n.invertBatch(p.map(v=>v.pz));return p.map((v,S)=>v.toAffine(b[S])).map(u.fromAffine)})}multiplyUnsafe(d){const p=u.ZERO;if(d===mt)return p;if(c(d),d===lt)return this;const{endo:b}=e;if(!b)return h.unsafeLadder(this,d);let{k1neg:v,k1:S,k2neg:A,k2:B}=b.splitScalar(d),y=p,E=p,k=this;for(;S>mt||B>mt;)S&lt&&(y=y.add(k)),B&lt&&(E=E.add(k)),k=k.double(),S>>=lt,B>>=lt;return v&&(y=y.negate()),A&&(E=E.negate()),E=new u(n.mul(E.px,b.beta),E.py,E.pz),y.add(E)}multiply(d){c(d);let p=d,b,v;const{endo:S}=e;if(S){const{k1neg:A,k1:B,k2neg:y,k2:E}=S.splitScalar(p);let{p:k,f:C}=this.wNAF(B),{p:N,f:I}=this.wNAF(E);k=h.constTimeNegate(A,k),N=h.constTimeNegate(y,N),N=new u(n.mul(N.px,S.beta),N.py,N.pz),b=k.add(N),v=C.add(I)}else{const{p:A,f:B}=this.wNAF(p);b=A,v=B}return u.normalizeZ([b,v])[0]}multiplyAndAddUnsafe(d,p,b){const v=u.BASE,S=(B,y)=>y===mt||y===lt||!B.equals(v)?B.multiplyUnsafe(y):B.multiply(y),A=S(this,p).add(S(d,b));return A.is0()?void 0:A}toAffine(d){const{px:p,py:b,pz:v}=this,S=this.is0();d==null&&(d=S?n.ONE:n.inv(v));const A=n.mul(p,d),B=n.mul(b,d),y=n.mul(v,d);if(S)return{x:n.ZERO,y:n.ZERO};if(!n.eql(y,n.ONE))throw new Error("invZ was invalid");return{x:A,y:B}}isTorsionFree(){const{h:d,isTorsionFree:p}=e;if(d===lt)return!0;if(p)return p(u,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){const{h:d,clearCofactor:p}=e;return d===lt?this:p?p(u,this):this.multiplyUnsafe(e.h)}toRawBytes(d=!0){return this.assertValidity(),r(u,this,d)}toHex(d=!0){return Qt(this.toRawBytes(d))}}u.BASE=new u(e.Gx,e.Gy,n.ONE),u.ZERO=new u(n.ZERO,n.ONE,n.ZERO);const w=e.nBitLength,h=vi(u,e.endo?Math.ceil(w/2):w);return{CURVE:e,ProjectivePoint:u,normPrivateKeyToScalar:l,weierstrassEquation:i,isWithinCurveOrder:s}}function Bi(t){const e=wr(t);return ce(e,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...e})}function Oi(t){const e=Bi(t),{Fp:n,n:r}=e,o=n.BYTES+1,i=2*n.BYTES+1;function s(x){return mt<x&&x<n.ORDER}function c(x){return F(x,r)}function l(x){return cn(x,r)}const{ProjectivePoint:a,normPrivateKeyToScalar:f,weierstrassEquation:u,isWithinCurveOrder:w}=Ai({...e,toBytes(x,O,$){const M=O.toAffine(),z=n.toBytes(M.x),D=zt;return $?D(Uint8Array.from([O.hasEvenY()?2:3]),z):D(Uint8Array.from([4]),z,n.toBytes(M.y))},fromBytes(x){const O=x.length,$=x[0],M=x.subarray(1);if(O===o&&($===2||$===3)){const z=ot(M);if(!s(z))throw new Error("Point is not on curve");const D=u(z);let X=n.sqrt(D);const Y=(X&lt)===lt;return($&1)===1!==Y&&(X=n.neg(X)),{x:z,y:X}}else if(O===i&&$===4){const z=n.fromBytes(M.subarray(0,n.BYTES)),D=n.fromBytes(M.subarray(n.BYTES,2*n.BYTES));return{x:z,y:D}}else throw new Error(`Point of length ${O} was invalid. Expected ${o} compressed bytes or ${i} uncompressed bytes`)}}),h=x=>Qt(It(x,e.nByteLength));function g(x){const O=r>>lt;return x>O}function d(x){return g(x)?c(-x):x}const p=(x,O,$)=>ot(x.slice(O,$));class b{constructor(O,$,M){this.r=O,this.s=$,this.recovery=M,this.assertValidity()}static fromCompact(O){const $=e.nByteLength;return O=J("compactSignature",O,$*2),new b(p(O,0,$),p(O,$,2*$))}static fromDER(O){const{r:$,s:M}=Dt.toSig(J("DER",O));return new b($,M)}assertValidity(){if(!w(this.r))throw new Error("r must be 0 < r < CURVE.n");if(!w(this.s))throw new Error("s must be 0 < s < CURVE.n")}addRecoveryBit(O){return new b(this.r,this.s,O)}recoverPublicKey(O){const{r:$,s:M,recovery:z}=this,D=E(J("msgHash",O));if(z==null||![0,1,2,3].includes(z))throw new Error("recovery id invalid");const X=z===2||z===3?$+e.n:$;if(X>=n.ORDER)throw new Error("recovery id 2 or 3 invalid");const Y=z&1?"03":"02",ft=a.fromHex(Y+h(X)),tt=l(X),dt=c(-D*tt),Lt=c(M*tt),ht=a.BASE.multiplyAndAddUnsafe(ft,dt,Lt);if(!ht)throw new Error("point at infinify");return ht.assertValidity(),ht}hasHighS(){return g(this.s)}normalizeS(){return this.hasHighS()?new b(this.r,c(-this.s),this.recovery):this}toDERRawBytes(){return Xt(this.toDERHex())}toDERHex(){return Dt.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return Xt(this.toCompactHex())}toCompactHex(){return h(this.r)+h(this.s)}}const v={isValidPrivateKey(x){try{return f(x),!0}catch{return!1}},normPrivateKeyToScalar:f,randomPrivateKey:()=>{const x=hr(e.n);return Ei(e.randomBytes(x),e.n)},precompute(x=8,O=a.BASE){return O._setWindowSize(x),O.multiply(BigInt(3)),O}};function S(x,O=!0){return a.fromPrivateKey(x).toRawBytes(O)}function A(x){const O=x instanceof Uint8Array,$=typeof x=="string",M=(O||$)&&x.length;return O?M===o||M===i:$?M===2*o||M===2*i:x instanceof a}function B(x,O,$=!0){if(A(x))throw new Error("first arg must be private key");if(!A(O))throw new Error("second arg must be public key");return a.fromHex(O).multiply(f(x)).toRawBytes($)}const y=e.bits2int||function(x){const O=ot(x),$=x.length*8-e.nBitLength;return $>0?O>>BigInt($):O},E=e.bits2int_modN||function(x){return c(y(x))},k=rn(e.nBitLength);function C(x){if(typeof x!="bigint")throw new Error("bigint expected");if(!(mt<=x&&x<k))throw new Error(`bigint expected < 2^${e.nBitLength}`);return It(x,e.nByteLength)}function N(x,O,$=I){if(["recovered","canonical"].some(St=>St in $))throw new Error("sign() legacy options not supported");const{hash:M,randomBytes:z}=e;let{lowS:D,prehash:X,extraEntropy:Y}=$;D==null&&(D=!0),x=J("msgHash",x),X&&(x=J("prehashed msgHash",M(x)));const ft=E(x),tt=f(O),dt=[C(tt),C(ft)];if(Y!=null){const St=Y===!0?z(n.BYTES):Y;dt.push(J("extraEntropy",St))}const Lt=zt(...dt),ht=ft;function pe(St){const Rt=y(St);if(!w(Rt))return;const Re=l(Rt),Ht=a.BASE.multiply(Rt).toAffine(),st=c(Ht.x);if(st===mt)return;const qt=c(Re*c(ht+st*tt));if(qt===mt)return;let He=(Ht.x===st?0:2)|Number(Ht.y&lt),qe=qt;return D&&g(qt)&&(qe=d(qt),He^=1),new b(st,qe,He)}return{seed:Lt,k2sig:pe}}const I={lowS:e.lowS,prehash:!1},q={lowS:e.lowS,prehash:!1};function P(x,O,$=I){const{seed:M,k2sig:z}=N(x,O,$),D=e;return lr(D.hash.outputLen,D.nByteLength,D.hmac)(M,z)}a.BASE._setWindowSize(8);function Q(x,O,$,M=q){var Ht;const z=x;if(O=J("msgHash",O),$=J("publicKey",$),"strict"in M)throw new Error("options.strict was renamed to lowS");const{lowS:D,prehash:X}=M;let Y,ft;try{if(typeof z=="string"||z instanceof Uint8Array)try{Y=b.fromDER(z)}catch(st){if(!(st instanceof Dt.Err))throw st;Y=b.fromCompact(z)}else if(typeof z=="object"&&typeof z.r=="bigint"&&typeof z.s=="bigint"){const{r:st,s:qt}=z;Y=new b(st,qt)}else throw new Error("PARSE");ft=a.fromHex($)}catch(st){if(st.message==="PARSE")throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(D&&Y.hasHighS())return!1;X&&(O=e.hash(O));const{r:tt,s:dt}=Y,Lt=E(O),ht=l(dt),pe=c(Lt*ht),St=c(tt*ht),Rt=(Ht=a.BASE.multiplyAndAddUnsafe(ft,pe,St))==null?void 0:Ht.toAffine();return Rt?c(Rt.x)===tt:!1}return{CURVE:e,getPublicKey:S,getSharedSecret:B,sign:P,verify:Q,ProjectivePoint:a,Signature:b,utils:v}}class gr extends rr{constructor(e,n){super(),this.finished=!1,this.destroyed=!1,Do(e);const r=Qe(n);if(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 o=this.blockLen,i=new Uint8Array(o);i.set(r.length>o?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),i.fill(0)}update(e){return _e(this),this.iHash.update(e),this}digestInto(e){_e(this),er(e,this.outputLen),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||(e=Object.create(Object.getPrototypeOf(this),{}));const{oHash:n,iHash:r,finished:o,destroyed:i,blockLen:s,outputLen:c}=this;return e=e,e.finished=o,e.destroyed=i,e.blockLen=s,e.outputLen=c,e.oHash=n._cloneInto(e.oHash),e.iHash=r._cloneInto(e.iHash),e}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}const br=(t,e,n)=>new gr(t,e).update(n).digest();br.create=(t,e)=>new gr(t,e);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function Ii(t){return{hash:t,hmac:(e,...n)=>br(t,e,Zo(...n)),randomBytes:or}}function Ti(t,e){const n=r=>Oi({...t,...Ii(r)});return Object.freeze({...n(e),create:n})}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Ae=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),Be=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),yr=BigInt(1),Oe=BigInt(2),mr=(t,e)=>(t+e/Oe)/e;function Er(t){const e=Ae,n=BigInt(3),r=BigInt(6),o=BigInt(11),i=BigInt(22),s=BigInt(23),c=BigInt(44),l=BigInt(88),a=t*t*t%e,f=a*a*t%e,u=ct(f,n,e)*f%e,w=ct(u,n,e)*f%e,h=ct(w,Oe,e)*a%e,g=ct(h,o,e)*h%e,d=ct(g,i,e)*g%e,p=ct(d,c,e)*d%e,b=ct(p,l,e)*p%e,v=ct(b,c,e)*d%e,S=ct(v,n,e)*f%e,A=ct(S,s,e)*g%e,B=ct(A,r,e)*a%e,y=ct(B,Oe,e);if(!an.eql(an.sqr(y),t))throw new Error("Cannot find square root");return y}const an=mi(Ae,void 0,void 0,{sqrt:Er}),le=Ti({a:BigInt(0),b:BigInt(7),Fp:an,n:Be,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:t=>{const e=Be,n=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),r=-yr*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),i=n,s=BigInt("0x100000000000000000000000000000000"),c=mr(i*t,e),l=mr(-r*t,e);let a=F(t-c*n-l*o,e),f=F(-c*r-l*i,e);const u=a>s,w=f>s;if(u&&(a=e-a),w&&(f=e-f),a>s||f>s)throw new Error("splitScalar: Endomorphism failed, k="+t);return{k1neg:u,k1:a,k2neg:w,k2:f}}}},Xe),Ie=BigInt(0),xr=t=>typeof t=="bigint"&&Ie<t&&t<Ae,Ni=t=>typeof t=="bigint"&&Ie<t&&t<Be,vr={};function Te(t,...e){let n=vr[t];if(n===void 0){const r=Xe(Uint8Array.from(t,o=>o.charCodeAt(0)));n=zt(r,r),vr[t]=n}return Xe(zt(n,...e))}const un=t=>t.toRawBytes(!0).slice(1),fn=t=>It(t,32),dn=t=>F(t,Ae),ae=t=>F(t,Be),hn=le.ProjectivePoint,Pi=(t,e,n)=>hn.BASE.multiplyAndAddUnsafe(t,e,n);function wn(t){let e=le.utils.normPrivateKeyToScalar(t),n=hn.fromPrivateKey(e);return{scalar:n.hasEvenY()?e:ae(-e),bytes:un(n)}}function _r(t){if(!xr(t))throw new Error("bad x: need 0 < x < p");const e=dn(t*t),n=dn(e*t+BigInt(7));let r=Er(n);r%Oe!==Ie&&(r=dn(-r));const o=new hn(t,r,yr);return o.assertValidity(),o}function Sr(...t){return ae(ot(Te("BIP0340/challenge",...t)))}function Ui(t){return wn(t).bytes}function $i(t,e,n=or(32)){const r=J("message",t),{bytes:o,scalar:i}=wn(e),s=J("auxRand",n,32),c=fn(i^ot(Te("BIP0340/aux",s))),l=Te("BIP0340/nonce",c,o,r),a=ae(ot(l));if(a===Ie)throw new Error("sign failed: k is zero");const{bytes:f,scalar:u}=wn(a),w=Sr(f,o,r),h=new Uint8Array(64);if(h.set(f,0),h.set(fn(ae(u+w*i)),32),!kr(h,r,o))throw new Error("sign: Invalid signature produced");return h}function kr(t,e,n){const r=J("signature",t,64),o=J("message",e),i=J("publicKey",n,32);try{const s=_r(ot(i)),c=ot(r.subarray(0,32));if(!xr(c))return!1;const l=ot(r.subarray(32,64));if(!Ni(l))return!1;const a=Sr(fn(c),un(s),o),f=Pi(s,l,ae(-a));return!(!f||!f.hasEvenY()||f.toAffine().x!==c)}catch{return!1}}const rt={getPublicKey:Ui,sign:$i,verify:kr,utils:{randomPrivateKey:le.utils.randomPrivateKey,lift_x:_r,pointToBytes:un,numberToBytesBE:It,bytesToNumberBE:ot,taggedHash:Te,mod:F}};function pn(t){if(!Number.isSafeInteger(t)||t<0)throw new Error(`Wrong positive integer: ${t}`)}function Ci(t){if(typeof t!="boolean")throw new Error(`Expected boolean, not ${t}`)}function Ar(t,...e){if(!(t instanceof Uint8Array))throw new Error("Expected Uint8Array");if(e.length>0&&!e.includes(t.length))throw new Error(`Expected Uint8Array of length ${e}, not of length=${t.length}`)}function Li(t){if(typeof t!="function"||typeof t.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");pn(t.outputLen),pn(t.blockLen)}function Ri(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 Hi(t,e){Ar(t);const n=e.outputLen;if(t.length<n)throw new Error(`digestInto() expects output buffer of length at least ${n}`)}const gn={number:pn,bool:Ci,bytes:Ar,hash:Li,exists:Ri,output:Hi};function qi(t,e,n,r){if(typeof t.setBigUint64=="function")return t.setBigUint64(e,n,r);const o=BigInt(32),i=BigInt(4294967295),s=Number(n>>o&i),c=Number(n&i),l=r?4:0,a=r?0:4;t.setUint32(e+l,s,r),t.setUint32(e+a,c,r)}class ji extends zo{constructor(e,n,r,o){super(),this.blockLen=e,this.outputLen=n,this.padOffset=r,this.isLE=o,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(e),this.view=Ge(this.buffer)}update(e){gn.exists(this);const{view:n,buffer:r,blockLen:o}=this;e=Qn(e);const i=e.length;for(let s=0;s<i;){const c=Math.min(o-this.pos,i-s);if(c===o){const l=Ge(e);for(;o<=i-s;s+=o)this.process(l,s);continue}r.set(e.subarray(s,s+c),this.pos),this.pos+=c,s+=c,this.pos===o&&(this.process(n,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){gn.exists(this),gn.output(e,this),this.finished=!0;const{buffer:n,view:r,blockLen:o,isLE:i}=this;let{pos:s}=this;n[s++]=128,this.buffer.subarray(s).fill(0),this.padOffset>o-s&&(this.process(r,0),s=0);for(let u=s;u<o;u++)n[u]=0;qi(r,o-8,BigInt(this.length*8),i),this.process(r,0);const c=Ge(e),l=this.outputLen;if(l%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const a=l/4,f=this.get();if(a>f.length)throw new Error("_sha2: outputLen bigger than state");for(let u=0;u<a;u++)c.setUint32(4*u,f[u],i)}digest(){const{buffer:e,outputLen:n}=this;this.digestInto(e);const r=e.slice(0,n);return this.destroy(),r}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());const{blockLen:n,buffer:r,length:o,finished:i,destroyed:s,pos:c}=this;return e.length=o,e.pos=c,e.finished=i,e.destroyed=s,o%n&&e.buffer.set(r),e}}const Mi=(t,e,n)=>t&e^~t&n,zi=(t,e,n)=>t&e^t&n^e&n,Ki=new Uint32Array([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]),Tt=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Nt=new Uint32Array(64);class Br extends ji{constructor(){super(64,32,8,!1),this.A=Tt[0]|0,this.B=Tt[1]|0,this.C=Tt[2]|0,this.D=Tt[3]|0,this.E=Tt[4]|0,this.F=Tt[5]|0,this.G=Tt[6]|0,this.H=Tt[7]|0}get(){const{A:e,B:n,C:r,D:o,E:i,F:s,G:c,H:l}=this;return[e,n,r,o,i,s,c,l]}set(e,n,r,o,i,s,c,l){this.A=e|0,this.B=n|0,this.C=r|0,this.D=o|0,this.E=i|0,this.F=s|0,this.G=c|0,this.H=l|0}process(e,n){for(let u=0;u<16;u++,n+=4)Nt[u]=e.getUint32(n,!1);for(let u=16;u<64;u++){const w=Nt[u-15],h=Nt[u-2],g=pt(w,7)^pt(w,18)^w>>>3,d=pt(h,17)^pt(h,19)^h>>>10;Nt[u]=d+Nt[u-7]+g+Nt[u-16]|0}let{A:r,B:o,C:i,D:s,E:c,F:l,G:a,H:f}=this;for(let u=0;u<64;u++){const w=pt(c,6)^pt(c,11)^pt(c,25),h=f+w+Mi(c,l,a)+Ki[u]+Nt[u]|0,d=(pt(r,2)^pt(r,13)^pt(r,22))+zi(r,o,i)|0;f=a,a=l,l=c,c=s+h|0,s=i,i=o,o=r,r=h+d|0}r=r+this.A|0,o=o+this.B|0,i=i+this.C|0,s=s+this.D|0,c=c+this.E|0,l=l+this.F|0,a=a+this.G|0,f=f+this.H|0,this.set(r,o,i,s,c,l,a,f)}roundClean(){Nt.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}}class Di extends Br{constructor(){super(),this.A=-1056596264,this.B=914150663,this.C=812702999,this.D=-150054599,this.E=-4191439,this.F=1750603025,this.G=1694076839,this.H=-1090891868,this.outputLen=28}}const bn=Xn(()=>new Br);Xn(()=>new Di);var te=Symbol("verified"),Vi=t=>t instanceof Object;function Wi(t){if(!Vi(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 n=t.tags[e];if(!Array.isArray(n))return!1;for(let r=0;r<n.length;r++)if(typeof n[r]=="object")return!1}return!0}new TextDecoder("utf-8");var Zi=new TextEncoder,Gi=class{generateSecretKey(){return rt.utils.randomPrivateKey()}getPublicKey(e){return nt(rt.getPublicKey(e))}finalizeEvent(e,n){const r=e;return r.pubkey=nt(rt.getPublicKey(n)),r.id=yn(r),r.sig=nt(rt.sign(yn(r),n)),r[te]=!0,r}verifyEvent(e){if(typeof e[te]=="boolean")return e[te];const n=yn(e);if(n!==e.id)return e[te]=!1,!1;try{const r=rt.verify(e.sig,n,e.pubkey);return e[te]=r,r}catch{return e[te]=!1,!1}}};function Fi(t){if(!Wi(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 yn(t){let e=bn(Zi.encode(Fi(t)));return nt(e)}var Ne=new Gi,Yi=Ne.generateSecretKey,Or=Ne.getPublicKey;Ne.finalizeEvent,Ne.verifyEvent;var Vt=Symbol("verified"),Ji=t=>t instanceof Object;function Qi(t){if(!Ji(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 n=t.tags[e];if(!Array.isArray(n))return!1;for(let r=0;r<n.length;r++)if(typeof n[r]=="object")return!1}return!0}new TextDecoder("utf-8");var Xi=new TextEncoder;function ue(t){t.indexOf("://")===-1&&(t="wss://"+t);let e=new URL(t);return 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()}var ts=class{constructor(e){m(this,"value");m(this,"next",null);m(this,"prev",null);this.value=e}},es=class{constructor(){m(this,"first");m(this,"last");this.first=null,this.last=null}enqueue(e){const n=new ts(e);return this.last?this.last===this.first?(this.last=n,this.last.prev=this.first,this.first.next=n):(n.prev=this.last,this.last.next=n,this.last=n):(this.first=n,this.last=n),!0}dequeue(){if(!this.first)return null;if(this.first===this.last){const n=this.first;return this.first=null,this.last=null,n.value}const e=this.first;return this.first=e.next,e.value}},ns=class{generateSecretKey(){return rt.utils.randomPrivateKey()}getPublicKey(e){return nt(rt.getPublicKey(e))}finalizeEvent(e,n){const r=e;return r.pubkey=nt(rt.getPublicKey(n)),r.id=mn(r),r.sig=nt(rt.sign(mn(r),n)),r[Vt]=!0,r}verifyEvent(e){if(typeof e[Vt]=="boolean")return e[Vt];const n=mn(e);if(n!==e.id)return e[Vt]=!1,!1;try{const r=rt.verify(e.sig,n,e.pubkey);return e[Vt]=r,r}catch{return e[Vt]=!1,!1}}};function rs(t){if(!Qi(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 mn(t){let e=bn(Xi.encode(rs(t)));return nt(e)}var Pe=new ns;Pe.generateSecretKey,Pe.getPublicKey,Pe.finalizeEvent;var os=Pe.verifyEvent,is=22242;function ss(t,e){if(t.ids&&t.ids.indexOf(e.id)===-1&&!t.ids.some(n=>e.id.startsWith(n))||t.kinds&&t.kinds.indexOf(e.kind)===-1||t.authors&&t.authors.indexOf(e.pubkey)===-1&&!t.authors.some(n=>e.pubkey.startsWith(n)))return!1;for(let n in t)if(n[0]==="#"){let r=n.slice(1),o=t[`#${r}`];if(o&&!e.tags.find(([i,s])=>i===n.slice(1)&&o.indexOf(s)!==-1))return!1}return!(t.since&&e.created_at<t.since||t.until&&e.created_at>t.until)}function cs(t,e){for(let n=0;n<t.length;n++)if(ss(t[n],e))return!0;return!1}function ls(t,e){let n=e.length+3,r=t.indexOf(`"${e}":`)+n,o=t.slice(r).indexOf('"')+r+1;return t.slice(o,o+64)}function as(t){let e=t.slice(0,22).indexOf('"EVENT"');if(e===-1)return null;let n=t.slice(e+7+1).indexOf('"');if(n===-1)return null;let r=e+7+1+n,o=t.slice(r+1,80).indexOf('"');if(o===-1)return null;let i=r+1+o;return t.slice(r+1,i)}function us(t,e){return{kind:is,created_at:Math.floor(Date.now()/1e3),tags:[["relay",t],["challenge",e]],content:""}}async function fs(){return new Promise(t=>{const e=new MessageChannel,n=()=>{e.port1.removeEventListener("message",n),t()};e.port1.addEventListener("message",n),e.port2.postMessage(0),e.port1.start()})}var ds=t=>(t[Vt]=!0,!0),Ir;try{Ir=WebSocket}catch{}var Tr=class{constructor(e,n){m(this,"url");m(this,"_connected",!1);m(this,"onclose",null);m(this,"onnotice",e=>console.debug(`NOTICE from ${this.url}: ${e}`));m(this,"baseEoseTimeout",4400);m(this,"connectionTimeout",4400);m(this,"openSubs",new Map);m(this,"connectionTimeoutHandle");m(this,"connectionPromise");m(this,"openCountRequests",new Map);m(this,"openEventPublishes",new Map);m(this,"ws");m(this,"incomingMessageQueue",new es);m(this,"queueRunning",!1);m(this,"challenge");m(this,"serial",0);m(this,"verifyEvent");this.url=ue(e),this.verifyEvent=n.verifyEvent}static async connect(e,n){const r=new Tr(e,n);return await r.connect(),r}closeAllSubscriptions(e){for(let[n,r]of this.openSubs)r.close(e);this.openSubs.clear();for(let[n,r]of this.openEventPublishes)r.reject(new Error(e));this.openEventPublishes.clear();for(let[n,r]of this.openCountRequests)r.reject(new Error(e));this.openCountRequests.clear()}get connected(){return this._connected}async connect(){return this.connectionPromise?this.connectionPromise:(this.challenge=void 0,this.connectionPromise=new Promise((e,n)=>{this.connectionTimeoutHandle=setTimeout(()=>{var r;n("connection timed out"),this.connectionPromise=void 0,(r=this.onclose)==null||r.call(this),this.closeAllSubscriptions("relay connection timed out")},this.connectionTimeout);try{this.ws=new Ir(this.url)}catch(r){n(r);return}this.ws.onopen=()=>{clearTimeout(this.connectionTimeoutHandle),this._connected=!0,e()},this.ws.onerror=r=>{var o;n(r.message),this._connected&&((o=this.onclose)==null||o.call(this),this.closeAllSubscriptions("relay connection errored"),this._connected=!1)},this.ws.onclose=async()=>{var r;this.connectionPromise=void 0,(r=this.onclose)==null||r.call(this),this.closeAllSubscriptions("relay connection closed"),this._connected=!1},this.ws.onmessage=this._onmessage.bind(this)}),this.connectionPromise)}async runQueue(){for(this.queueRunning=!0;this.handleNext()!==!1;)await fs();this.queueRunning=!1}handleNext(){var r,o;const e=this.incomingMessageQueue.dequeue();if(!e)return!1;const n=as(e);if(n){const i=this.openSubs.get(n);if(!i)return;const s=ls(e,"id"),c=(r=i.alreadyHaveEvent)==null?void 0:r.call(i,s);if((o=i.receivedEvent)==null||o.call(i,this,s),c)return}try{let i=JSON.parse(e);switch(i[0]){case"EVENT":{const s=this.openSubs.get(i[1]),c=i[2];this.verifyEvent(c)&&cs(s.filters,c)&&s.onevent(c);return}case"COUNT":{const s=i[1],c=i[2],l=this.openCountRequests.get(s);l&&(l.resolve(c.count),this.openCountRequests.delete(s));return}case"EOSE":{const s=this.openSubs.get(i[1]);if(!s)return;s.receivedEose();return}case"OK":{const s=i[1],c=i[2],l=i[3],a=this.openEventPublishes.get(s);c?a.resolve(l):a.reject(new Error(l)),this.openEventPublishes.delete(s);return}case"CLOSED":{const s=i[1],c=this.openSubs.get(s);if(!c)return;c.closed=!0,c.close(i[2]);return}case"NOTICE":this.onnotice(i[1]);return;case"AUTH":{this.challenge=i[1];return}}}catch{return}}async send(e){if(!this.connectionPromise)throw new Error("sending on closed connection");this.connectionPromise.then(()=>{var n;(n=this.ws)==null||n.send(e)})}async auth(e){if(!this.challenge)throw new Error("can't perform auth, no challenge was received");const n=await e(us(this.url,this.challenge)),r=new Promise((o,i)=>{this.openEventPublishes.set(n.id,{resolve:o,reject:i})});return this.send('["AUTH",'+JSON.stringify(n)+"]"),r}async publish(e){const n=new Promise((r,o)=>{this.openEventPublishes.set(e.id,{resolve:r,reject:o})});return this.send('["EVENT",'+JSON.stringify(e)+"]"),n}async count(e,n){this.serial++;const r=(n==null?void 0:n.id)||"count:"+this.serial,o=new Promise((i,s)=>{this.openCountRequests.set(r,{resolve:i,reject:s})});return this.send('["COUNT","'+r+'",'+JSON.stringify(e)+"]"),o}subscribe(e,n){const r=this.prepareSubscription(e,n);return r.fire(),r}prepareSubscription(e,n){this.serial++;const r=n.id||"sub:"+this.serial,o=new hs(this,r,e,n);return this.openSubs.set(r,o),o}close(){var e;this.closeAllSubscriptions("relay connection closed by us"),this._connected=!1,(e=this.ws)==null||e.close()}_onmessage(e){this.incomingMessageQueue.enqueue(e.data),this.queueRunning||this.runQueue()}},hs=class{constructor(e,n,r,o){m(this,"relay");m(this,"id");m(this,"closed",!1);m(this,"eosed",!1);m(this,"filters");m(this,"alreadyHaveEvent");m(this,"receivedEvent");m(this,"onevent");m(this,"oneose");m(this,"onclose");m(this,"eoseTimeout");m(this,"eoseTimeoutHandle");this.relay=e,this.filters=r,this.id=n,this.alreadyHaveEvent=o.alreadyHaveEvent,this.receivedEvent=o.receivedEvent,this.eoseTimeout=o.eoseTimeout||e.baseEoseTimeout,this.oneose=o.oneose,this.onclose=o.onclose,this.onevent=o.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(){var e;this.eosed||(clearTimeout(this.eoseTimeoutHandle),this.eosed=!0,(e=this.oneose)==null||e.call(this))}close(e="closed by caller"){var n;this.closed||(this.relay.send('["CLOSE",'+JSON.stringify(this.id)+"]"),this.closed=!0),this.relay.openSubs.delete(this.id),(n=this.onclose)==null||n.call(this,e)}},ws=class{constructor(e){m(this,"relays",new Map);m(this,"seenOn",new Map);m(this,"trackRelays",!1);m(this,"verifyEvent");m(this,"trustedRelayURLs",new Set);this.verifyEvent=e.verifyEvent}async ensureRelay(e,n){e=ue(e);let r=this.relays.get(e);return r||(r=new Tr(e,{verifyEvent:this.trustedRelayURLs.has(e)?ds:this.verifyEvent}),n!=null&&n.connectionTimeout&&(r.connectionTimeout=n.connectionTimeout),this.relays.set(e,r)),await r.connect(),r}close(e){e.map(ue).forEach(n=>{var r;(r=this.relays.get(n))==null||r.close()})}subscribeMany(e,n,r){this.trackRelays&&(r.receivedEvent=(w,h)=>{let g=this.seenOn.get(h);g||(g=new Set,this.seenOn.set(h,g)),g.add(w)});const o=new Set,i=[],s=[];let c=w=>{var h;s[w]=!0,s.filter(g=>g).length===e.length&&((h=r.oneose)==null||h.call(r),c=()=>{})};const l=[];let a=(w,h)=>{var g;c(w),l[w]=h,l.filter(d=>d).length===e.length&&((g=r.onclose)==null||g.call(r,l),a=()=>{})};const f=w=>{var g;if((g=r.alreadyHaveEvent)!=null&&g.call(r,w))return!0;const h=o.has(w);return o.add(w),h},u=Promise.all(e.map(ue).map(async(w,h,g)=>{if(g.indexOf(w)!==h){a(h,"duplicate url");return}let d;try{d=await this.ensureRelay(w,{connectionTimeout:r.maxWait?Math.max(r.maxWait*.8,r.maxWait-1e3):void 0})}catch(b){a(h,(b==null?void 0:b.message)||String(b));return}let p=d.subscribe(n,{...r,oneose:()=>c(h),onclose:b=>a(h,b),alreadyHaveEvent:f,eoseTimeout:r.maxWait});i.push(p)}));return{async close(){await u,i.forEach(w=>{w.close()})}}}subscribeManyEose(e,n,r){const o=this.subscribeMany(e,n,{...r,oneose(){o.close()}});return o}async querySync(e,n,r){return new Promise(async o=>{const i=[];this.subscribeManyEose(e,[n],{...r,onevent(s){i.push(s)},onclose(s){o(i)}})})}async get(e,n,r){n.limit=1;const o=await this.querySync(e,n,r);return o.sort((i,s)=>s.created_at-i.created_at),o[0]||null}publish(e,n){return e.map(ue).map(async(r,o,i)=>i.indexOf(r)!==o?Promise.reject("duplicate url"):(await this.ensureRelay(r)).publish(n))}},ps=class extends ws{constructor(){super({verifyEvent:os})}};function Nr(t){return t instanceof Uint8Array||t!=null&&typeof t=="object"&&t.constructor.name==="Uint8Array"}function Wt(t,...e){if(!Nr(t))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(t.length))throw new Error(`Uint8Array expected of length ${e}, not of length=${t.length}`)}function Ue(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 Pr(t,e){Wt(t);const n=e.outputLen;if(t.length<n)throw new Error(`digestInto() expects output buffer of length at least ${n}`)}/*! noble-ciphers - MIT License (c) 2023 Paul Miller (paulmillr.com) */const it=t=>new Uint32Array(t.buffer,t.byteOffset,Math.floor(t.byteLength/4)),gs=t=>new DataView(t.buffer,t.byteOffset,t.byteLength);if(!(new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68))throw new Error("Non little-endian hardware is not supported");function bs(t){if(typeof t!="string")throw new Error(`string expected, got ${typeof t}`);return new Uint8Array(new TextEncoder().encode(t))}function fe(t){if(typeof t=="string")t=bs(t);else if(Nr(t))t=t.slice();else throw new Error(`Uint8Array expected, got ${typeof t}`);return t}const ys=(t,e)=>(Object.assign(e,t),e),Et=16,En=new Uint8Array(16),bt=it(En),ms=225,Es=(t,e,n,r)=>{const o=r&1;return{s3:n<<31|r>>>1,s2:e<<31|n>>>1,s1:t<<31|e>>>1,s0:t>>>1^ms<<24&-(o&1)}},at=t=>(t>>>0&255)<<24|(t>>>8&255)<<16|(t>>>16&255)<<8|t>>>24&255|0;function xs(t){t.reverse();const e=t[15]&1;let n=0;for(let r=0;r<t.length;r++){const o=t[r];t[r]=o>>>1|n,n=(o&1)<<7}return t[0]^=-e&225,t}const vs=t=>t>64*1024?8:t>1024?4:2;class Ur{constructor(e,n){this.blockLen=Et,this.outputLen=Et,this.s0=0,this.s1=0,this.s2=0,this.s3=0,this.finished=!1,e=fe(e),Wt(e,16);const r=gs(e);let o=r.getUint32(0,!1),i=r.getUint32(4,!1),s=r.getUint32(8,!1),c=r.getUint32(12,!1);const l=[];for(let g=0;g<128;g++)l.push({s0:at(o),s1:at(i),s2:at(s),s3:at(c)}),{s0:o,s1:i,s2:s,s3:c}=Es(o,i,s,c);const a=vs(n||1024);if(![1,2,4,8].includes(a))throw new Error(`ghash: wrong window size=${a}, should be 2, 4 or 8`);this.W=a;const u=128/a,w=this.windowSize=2**a,h=[];for(let g=0;g<u;g++)for(let d=0;d<w;d++){let p=0,b=0,v=0,S=0;for(let A=0;A<a;A++){if(!(d>>>a-A-1&1))continue;const{s0:y,s1:E,s2:k,s3:C}=l[a*g+A];p^=y,b^=E,v^=k,S^=C}h.push({s0:p,s1:b,s2:v,s3:S})}this.t=h}_updateBlock(e,n,r,o){e^=this.s0,n^=this.s1,r^=this.s2,o^=this.s3;const{W:i,t:s,windowSize:c}=this;let l=0,a=0,f=0,u=0;const w=(1<<i)-1;let h=0;for(const g of[e,n,r,o])for(let d=0;d<4;d++){const p=g>>>8*d&255;for(let b=8/i-1;b>=0;b--){const v=p>>>i*b&w,{s0:S,s1:A,s2:B,s3:y}=s[h*c+v];l^=S,a^=A,f^=B,u^=y,h+=1}}this.s0=l,this.s1=a,this.s2=f,this.s3=u}update(e){e=fe(e),Ue(this);const n=it(e),r=Math.floor(e.length/Et),o=e.length%Et;for(let i=0;i<r;i++)this._updateBlock(n[i*4+0],n[i*4+1],n[i*4+2],n[i*4+3]);return o&&(En.set(e.subarray(r*Et)),this._updateBlock(bt[0],bt[1],bt[2],bt[3]),bt.fill(0)),this}destroy(){const{t:e}=this;for(const n of e)n.s0=0,n.s1=0,n.s2=0,n.s3=0}digestInto(e){Ue(this),Pr(e,this),this.finished=!0;const{s0:n,s1:r,s2:o,s3:i}=this,s=it(e);return s[0]=n,s[1]=r,s[2]=o,s[3]=i,e}digest(){const e=new Uint8Array(Et);return this.digestInto(e),this.destroy(),e}}class _s extends Ur{constructor(e,n){e=fe(e);const r=xs(e.slice());super(r,n),r.fill(0)}update(e){e=fe(e),Ue(this);const n=it(e),r=e.length%Et,o=Math.floor(e.length/Et);for(let i=0;i<o;i++)this._updateBlock(at(n[i*4+3]),at(n[i*4+2]),at(n[i*4+1]),at(n[i*4+0]));return r&&(En.set(e.subarray(o*Et)),this._updateBlock(at(bt[3]),at(bt[2]),at(bt[1]),at(bt[0])),bt.fill(0)),this}digestInto(e){Ue(this),Pr(e,this),this.finished=!0;const{s0:n,s1:r,s2:o,s3:i}=this,s=it(e);return s[0]=n,s[1]=r,s[2]=o,s[3]=i,e.reverse()}}function $r(t){const e=(r,o)=>t(o,r.length).update(fe(r)).digest(),n=t(new Uint8Array(16),0);return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=(r,o)=>t(r,o),e}$r((t,e)=>new Ur(t,e)),$r((t,e)=>new _s(t,e));const Pt=16,Ss=283;function xn(t){return t<<1^Ss&-(t>>7)}function ee(t,e){let n=0;for(;e>0;e>>=1)n^=t&-(e&1),t=xn(t);return n}const vn=(()=>{let t=new Uint8Array(256);for(let n=0,r=1;n<256;n++,r^=xn(r))t[n]=r;const e=new Uint8Array(256);e[0]=99;for(let n=0;n<255;n++){let r=t[255-n];r|=r<<8,e[t[n]]=(r^r>>4^r>>5^r>>6^r>>7^99)&255}return e})(),ks=vn.map((t,e)=>vn.indexOf(e)),As=t=>t<<24|t>>>8,_n=t=>t<<8|t>>>24;function Cr(t,e){if(t.length!==256)throw new Error("Wrong sbox length");const n=new Uint32Array(256).map((a,f)=>e(t[f])),r=n.map(_n),o=r.map(_n),i=o.map(_n),s=new Uint32Array(256*256),c=new Uint32Array(256*256),l=new Uint16Array(256*256);for(let a=0;a<256;a++)for(let f=0;f<256;f++){const u=a*256+f;s[u]=n[a]^r[f],c[u]=o[a]^i[f],l[u]=t[a]<<8|t[f]}return{sbox:t,sbox2:l,T0:n,T1:r,T2:o,T3:i,T01:s,T23:c}}const Sn=Cr(vn,t=>ee(t,3)<<24|t<<16|t<<8|ee(t,2)),Lr=Cr(ks,t=>ee(t,11)<<24|ee(t,13)<<16|ee(t,9)<<8|ee(t,14)),Bs=(()=>{const t=new Uint8Array(16);for(let e=0,n=1;e<16;e++,n=xn(n))t[e]=n;return t})();function Rr(t){Wt(t);const e=t.length;if(![16,24,32].includes(e))throw new Error(`aes: wrong key size: should be 16, 24 or 32, got: ${e}`);const{sbox2:n}=Sn,r=it(t),o=r.length,i=c=>yt(n,c,c,c,c),s=new Uint32Array(e+28);s.set(r);for(let c=o;c<s.length;c++){let l=s[c-1];c%o===0?l=i(As(l))^Bs[c/o-1]:o>6&&c%o===4&&(l=i(l)),s[c]=s[c-o]^l}return s}function Os(t){const e=Rr(t),n=e.slice(),r=e.length,{sbox2:o}=Sn,{T0:i,T1:s,T2:c,T3:l}=Lr;for(let a=0;a<r;a+=4)for(let f=0;f<4;f++)n[a+f]=e[r-a-4+f];e.fill(0);for(let a=4;a<r-4;a++){const f=n[a],u=yt(o,f,f,f,f);n[a]=i[u&255]^s[u>>>8&255]^c[u>>>16&255]^l[u>>>24]}return n}function Ut(t,e,n,r,o,i){return t[n<<8&65280|r>>>8&255]^e[o>>>8&65280|i>>>24&255]}function yt(t,e,n,r,o){return t[e&255|n&65280]|t[r>>>16&255|o>>>16&65280]<<16}function Hr(t,e,n,r,o){const{sbox2:i,T01:s,T23:c}=Sn;let l=0;e^=t[l++],n^=t[l++],r^=t[l++],o^=t[l++];const a=t.length/4-2;for(let g=0;g<a;g++){const d=t[l++]^Ut(s,c,e,n,r,o),p=t[l++]^Ut(s,c,n,r,o,e),b=t[l++]^Ut(s,c,r,o,e,n),v=t[l++]^Ut(s,c,o,e,n,r);e=d,n=p,r=b,o=v}const f=t[l++]^yt(i,e,n,r,o),u=t[l++]^yt(i,n,r,o,e),w=t[l++]^yt(i,r,o,e,n),h=t[l++]^yt(i,o,e,n,r);return{s0:f,s1:u,s2:w,s3:h}}function Is(t,e,n,r,o){const{sbox2:i,T01:s,T23:c}=Lr;let l=0;e^=t[l++],n^=t[l++],r^=t[l++],o^=t[l++];const a=t.length/4-2;for(let g=0;g<a;g++){const d=t[l++]^Ut(s,c,e,o,r,n),p=t[l++]^Ut(s,c,n,e,o,r),b=t[l++]^Ut(s,c,r,n,e,o),v=t[l++]^Ut(s,c,o,r,n,e);e=d,n=p,r=b,o=v}const f=t[l++]^yt(i,e,o,r,n),u=t[l++]^yt(i,n,e,o,r),w=t[l++]^yt(i,r,n,e,o),h=t[l++]^yt(i,o,r,n,e);return{s0:f,s1:u,s2:w,s3:h}}function qr(t,e){if(!e)return new Uint8Array(t);if(Wt(e),e.length<t)throw new Error(`aes: wrong destination length, expected at least ${t}, got: ${e.length}`);return e}function Ts(t){if(Wt(t),t.length%Pt!==0)throw new Error(`aes/(cbc-ecb).decrypt ciphertext should consist of blocks with size ${Pt}`)}function Ns(t,e,n){let r=t.length;const o=r%Pt;if(!e&&o!==0)throw new Error("aec/(cbc-ecb): unpadded plaintext with disabled padding");const i=it(t);if(e){let l=Pt-o;l||(l=Pt),r=r+l}const s=qr(r,n),c=it(s);return{b:i,o:c,out:s}}function Ps(t,e){if(!e)return t;const n=t.length;if(!n)throw new Error("aes/pcks5: empty ciphertext not allowed");const r=t[n-1];if(r<=0||r>16)throw new Error(`aes/pcks5: wrong padding byte: ${r}`);const o=t.subarray(0,-r);for(let i=0;i<r;i++)if(t[n-i-1]!==r)throw new Error("aes/pcks5: wrong padding");return o}function Us(t){const e=new Uint8Array(16),n=it(e);e.set(t);const r=Pt-t.length;for(let o=Pt-r;o<Pt;o++)e[o]=r;return n}const jr=ys({blockSize:16,nonceLength:16},function(e,n,r={}){Wt(e),Wt(n,16);const o=!r.disablePadding;return{encrypt:(i,s)=>{const c=Rr(e),{b:l,o:a,out:f}=Ns(i,o,s),u=it(n);let w=u[0],h=u[1],g=u[2],d=u[3],p=0;for(;p+4<=l.length;)w^=l[p+0],h^=l[p+1],g^=l[p+2],d^=l[p+3],{s0:w,s1:h,s2:g,s3:d}=Hr(c,w,h,g,d),a[p++]=w,a[p++]=h,a[p++]=g,a[p++]=d;if(o){const b=Us(i.subarray(p*4));w^=b[0],h^=b[1],g^=b[2],d^=b[3],{s0:w,s1:h,s2:g,s3:d}=Hr(c,w,h,g,d),a[p++]=w,a[p++]=h,a[p++]=g,a[p++]=d}return c.fill(0),f},decrypt:(i,s)=>{Ts(i);const c=Os(e),l=it(n),a=qr(i.length,s),f=it(i),u=it(a);let w=l[0],h=l[1],g=l[2],d=l[3];for(let p=0;p+4<=f.length;){const b=w,v=h,S=g,A=d;w=f[p+0],h=f[p+1],g=f[p+2],d=f[p+3];const{s0:B,s1:y,s2:E,s3:k}=Is(c,w,h,g,d);u[p++]=B^b,u[p++]=y^v,u[p++]=E^S,u[p++]=k^A}return c.fill(0),Ps(a,o)}}});/*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) */function ne(t){if(!Number.isSafeInteger(t))throw new Error(`Wrong integer: ${t}`)}function xt(...t){const e=(o,i)=>s=>o(i(s)),n=Array.from(t).reverse().reduce((o,i)=>o?e(o,i.encode):i.encode,void 0),r=t.reduce((o,i)=>o?e(o,i.decode):i.decode,void 0);return{encode:n,decode:r}}function vt(t){return{encode:e=>{if(!Array.isArray(e)||e.length&&typeof e[0]!="number")throw new Error("alphabet.encode input should be an array of numbers");return e.map(n=>{if(ne(n),n<0||n>=t.length)throw new Error(`Digit index outside alphabet: ${n} (alphabet: ${t.length})`);return t[n]})},decode:e=>{if(!Array.isArray(e)||e.length&&typeof e[0]!="string")throw new Error("alphabet.decode input should be array of strings");return e.map(n=>{if(typeof n!="string")throw new Error(`alphabet.decode: not string element=${n}`);const r=t.indexOf(n);if(r===-1)throw new Error(`Unknown letter: "${n}". Allowed: ${t}`);return r})}}}function _t(t=""){if(typeof t!="string")throw new Error("join separator should be string");return{encode:e=>{if(!Array.isArray(e)||e.length&&typeof e[0]!="string")throw new Error("join.encode input should be array of strings");for(let n of e)if(typeof n!="string")throw new Error(`join.encode: non-string input=${n}`);return e.join(t)},decode:e=>{if(typeof e!="string")throw new Error("join.decode input should be string");return e.split(t)}}}function $e(t,e="="){if(ne(t),typeof e!="string")throw new Error("padding chr should be string");return{encode(n){if(!Array.isArray(n)||n.length&&typeof n[0]!="string")throw new Error("padding.encode input should be array of strings");for(let r of n)if(typeof r!="string")throw new Error(`padding.encode: non-string input=${r}`);for(;n.length*t%8;)n.push(e);return n},decode(n){if(!Array.isArray(n)||n.length&&typeof n[0]!="string")throw new Error("padding.encode input should be array of strings");for(let o of n)if(typeof o!="string")throw new Error(`padding.decode: non-string input=${o}`);let r=n.length;if(r*t%8)throw new Error("Invalid padding: string should have whole number of bytes");for(;r>0&&n[r-1]===e;r--)if(!((r-1)*t%8))throw new Error("Invalid padding: string has too much padding");return n.slice(0,r)}}}function Mr(t){if(typeof t!="function")throw new Error("normalize fn should be function");return{encode:e=>e,decode:e=>t(e)}}function zr(t,e,n){if(e<2)throw new Error(`convertRadix: wrong from=${e}, base cannot be less than 2`);if(n<2)throw new Error(`convertRadix: wrong to=${n}, base cannot be less than 2`);if(!Array.isArray(t))throw new Error("convertRadix: data should be array");if(!t.length)return[];let r=0;const o=[],i=Array.from(t);for(i.forEach(s=>{if(ne(s),s<0||s>=e)throw new Error(`Wrong integer: ${s}`)});;){let s=0,c=!0;for(let l=r;l<i.length;l++){const a=i[l],f=e*s+a;if(!Number.isSafeInteger(f)||e*s/e!==s||f-a!==e*s)throw new Error("convertRadix: carry overflow");if(s=f%n,i[l]=Math.floor(f/n),!Number.isSafeInteger(i[l])||i[l]*n+s!==f)throw new Error("convertRadix: carry overflow");if(c)i[l]?c=!1:r=l;else continue}if(o.push(s),c)break}for(let s=0;s<t.length-1&&t[s]===0;s++)o.push(0);return o.reverse()}const Kr=(t,e)=>e?Kr(e,t%e):t,Ce=(t,e)=>t+(e-Kr(t,e));function kn(t,e,n,r){if(!Array.isArray(t))throw new Error("convertRadix2: data should be array");if(e<=0||e>32)throw new Error(`convertRadix2: wrong from=${e}`);if(n<=0||n>32)throw new Error(`convertRadix2: wrong to=${n}`);if(Ce(e,n)>32)throw new Error(`convertRadix2: carry overflow from=${e} to=${n} carryBits=${Ce(e,n)}`);let o=0,i=0;const s=2**n-1,c=[];for(const l of t){if(ne(l),l>=2**e)throw new Error(`convertRadix2: invalid data word=${l} from=${e}`);if(o=o<<e|l,i+e>32)throw new Error(`convertRadix2: carry overflow pos=${i} from=${e}`);for(i+=e;i>=n;i-=n)c.push((o>>i-n&s)>>>0);o&=2**i-1}if(o=o<<n-i&s,!r&&i>=e)throw new Error("Excess padding");if(!r&&o)throw new Error(`Non-zero padding: ${o}`);return r&&i>0&&c.push(o>>>0),c}function $s(t){return ne(t),{encode:e=>{if(!(e instanceof Uint8Array))throw new Error("radix.encode input should be Uint8Array");return zr(Array.from(e),2**8,t)},decode:e=>{if(!Array.isArray(e)||e.length&&typeof e[0]!="number")throw new Error("radix.decode input should be array of strings");return Uint8Array.from(zr(e,t,2**8))}}}function $t(t,e=!1){if(ne(t),t<=0||t>32)throw new Error("radix2: bits should be in (0..32]");if(Ce(8,t)>32||Ce(t,8)>32)throw new Error("radix2: carry overflow");return{encode:n=>{if(!(n instanceof Uint8Array))throw new Error("radix2.encode input should be Uint8Array");return kn(Array.from(n),8,t,!e)},decode:n=>{if(!Array.isArray(n)||n.length&&typeof n[0]!="number")throw new Error("radix2.decode input should be array of strings");return Uint8Array.from(kn(n,t,8,e))}}}function Dr(t){if(typeof t!="function")throw new Error("unsafeWrapper fn should be function");return function(...e){try{return t.apply(null,e)}catch{}}}const Cs=xt($t(4),vt("0123456789ABCDEF"),_t("")),Ls=xt($t(5),vt("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"),$e(5),_t(""));xt($t(5),vt("0123456789ABCDEFGHIJKLMNOPQRSTUV"),$e(5),_t("")),xt($t(5),vt("0123456789ABCDEFGHJKMNPQRSTVWXYZ"),_t(""),Mr(t=>t.toUpperCase().replace(/O/g,"0").replace(/[IL]/g,"1")));const de=xt($t(6),vt("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),$e(6),_t("")),Rs=xt($t(6),vt("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"),$e(6),_t("")),An=t=>xt($s(58),vt(t),_t("")),Bn=An("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");An("123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"),An("rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz");const Vr=[0,2,3,5,6,7,9,10,11],Hs={encode(t){let e="";for(let n=0;n<t.length;n+=8){const r=t.subarray(n,n+8);e+=Bn.encode(r).padStart(Vr[r.length],"1")}return e},decode(t){let e=[];for(let n=0;n<t.length;n+=11){const r=t.slice(n,n+11),o=Vr.indexOf(r.length),i=Bn.decode(r);for(let s=0;s<i.length-o;s++)if(i[s]!==0)throw new Error("base58xmr: wrong padding");e=e.concat(Array.from(i.slice(i.length-o)))}return Uint8Array.from(e)}},On=xt(vt("qpzry9x8gf2tvdw0s3jn54khce6mua7l"),_t("")),Wr=[996825010,642813549,513874426,1027748829,705979059];function he(t){const e=t>>25;let n=(t&33554431)<<5;for(let r=0;r<Wr.length;r++)(e>>r&1)===1&&(n^=Wr[r]);return n}function Zr(t,e,n=1){const r=t.length;let o=1;for(let i=0;i<r;i++){const s=t.charCodeAt(i);if(s<33||s>126)throw new Error(`Invalid prefix (${t})`);o=he(o)^s>>5}o=he(o);for(let i=0;i<r;i++)o=he(o)^t.charCodeAt(i)&31;for(let i of e)o=he(o)^i;for(let i=0;i<6;i++)o=he(o);return o^=n,On.encode(kn([o%2**30],30,5,!1))}function Gr(t){const e=t==="bech32"?1:734539939,n=$t(5),r=n.decode,o=n.encode,i=Dr(r);function s(f,u,w=90){if(typeof f!="string")throw new Error(`bech32.encode prefix should be string, not ${typeof f}`);if(!Array.isArray(u)||u.length&&typeof u[0]!="number")throw new Error(`bech32.encode words should be array of numbers, not ${typeof u}`);const h=f.length+7+u.length;if(w!==!1&&h>w)throw new TypeError(`Length ${h} exceeds limit ${w}`);return f=f.toLowerCase(),`${f}1${On.encode(u)}${Zr(f,u,e)}`}function c(f,u=90){if(typeof f!="string")throw new Error(`bech32.decode input should be string, not ${typeof f}`);if(f.length<8||u!==!1&&f.length>u)throw new TypeError(`Wrong string length: ${f.length} (${f}). Expected (8..${u})`);const w=f.toLowerCase();if(f!==w&&f!==f.toUpperCase())throw new Error("String must be lowercase or uppercase");f=w;const h=f.lastIndexOf("1");if(h===0||h===-1)throw new Error('Letter "1" must be present between prefix and data only');const g=f.slice(0,h),d=f.slice(h+1);if(d.length<6)throw new Error("Data must be at least 6 characters long");const p=On.decode(d).slice(0,-6),b=Zr(g,p,e);if(!d.endsWith(b))throw new Error(`Invalid checksum in ${f}: expected "${b}"`);return{prefix:g,words:p}}const l=Dr(c);function a(f){const{prefix:u,words:w}=c(f,!1);return{prefix:u,words:w,bytes:r(w)}}return{encode:s,decode:c,decodeToBytes:a,decodeUnsafe:l,fromWords:r,fromWordsUnsafe:i,toWords:o}}const Fr=Gr("bech32");Gr("bech32m");const qs={encode:t=>new TextDecoder().decode(t),decode:t=>new TextEncoder().encode(t)},js=xt($t(4),vt("0123456789abcdef"),_t(""),Mr(t=>{if(typeof t!="string"||t.length%2)throw new TypeError(`hex.decode: expected string, got ${typeof t} with length ${t.length}`);return t.toLowerCase()}));`${Object.keys({utf8:qs,hex:js,base16:Cs,base32:Ls,base64:de,base64url:Rs,base58:Bn,base58xmr:Hs}).join(", ")}`;var Zt=Symbol("verified"),Ms=t=>t instanceof Object;function zs(t){if(!Ms(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 n=t.tags[e];if(!Array.isArray(n))return!1;for(let r=0;r<n.length;r++)if(typeof n[r]=="object")return!1}return!0}var Ks=new TextDecoder("utf-8"),Yr=new TextEncoder;function we(t){t.indexOf("://")===-1&&(t="wss://"+t);let e=new URL(t);return 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()}var Ds=class{constructor(t){m(this,"value");m(this,"next",null);m(this,"prev",null);this.value=t}},Vs=class{constructor(){m(this,"first");m(this,"last");this.first=null,this.last=null}enqueue(t){const e=new Ds(t);return this.last?this.last===this.first?(this.last=e,this.last.prev=this.first,this.first.next=e):(e.prev=this.last,this.last.next=e,this.last=e):(this.first=e,this.last=e),!0}dequeue(){if(!this.first)return null;if(this.first===this.last){const e=this.first;return this.first=null,this.last=null,e.value}const t=this.first;return this.first=t.next,t.value}},Ws=class{generateSecretKey(){return rt.utils.randomPrivateKey()}getPublicKey(t){return nt(rt.getPublicKey(t))}finalizeEvent(t,e){const n=t;return n.pubkey=nt(rt.getPublicKey(e)),n.id=In(n),n.sig=nt(rt.sign(In(n),e)),n[Zt]=!0,n}verifyEvent(t){if(typeof t[Zt]=="boolean")return t[Zt];const e=In(t);if(e!==t.id)return t[Zt]=!1,!1;try{const n=rt.verify(t.sig,e,t.pubkey);return t[Zt]=n,n}catch{return t[Zt]=!1,!1}}};function Zs(t){if(!zs(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 In(t){let e=bn(Yr.encode(Zs(t)));return nt(e)}var Le=new Ws,Gs=Le.generateSecretKey,Jr=Le.getPublicKey,Fs=Le.finalizeEvent,Qr=Le.verifyEvent;async function Ys(t,e,n){const r=t instanceof Uint8Array?nt(t):t,o=le.getSharedSecret(r,"02"+e),i=Xr(o);let s=Uint8Array.from(Ko(16)),c=Yr.encode(n),l=jr(i,s).encrypt(c),a=de.encode(new Uint8Array(l)),f=de.encode(new Uint8Array(s.buffer));return`${a}?iv=${f}`}async function Js(t,e,n){const r=t instanceof Uint8Array?nt(t):t;let[o,i]=n.split("?iv="),s=le.getSharedSecret(r,"02"+e),c=Xr(s),l=de.decode(i),a=de.decode(o),f=jr(c,l).decrypt(a);return Ks.decode(f)}function Xr(t){return t.slice(1,33)}var Qs=/^(?:([\w.+-]+)@)?([\w_-]+(\.[\w_-]+)+)$/,Xs;try{Xs=fetch}catch{}var tc=22242,Tn=24133,ec=31990;function nc(t,e){if(t.ids&&t.ids.indexOf(e.id)===-1&&!t.ids.some(n=>e.id.startsWith(n))||t.kinds&&t.kinds.indexOf(e.kind)===-1||t.authors&&t.authors.indexOf(e.pubkey)===-1&&!t.authors.some(n=>e.pubkey.startsWith(n)))return!1;for(let n in t)if(n[0]==="#"){let r=n.slice(1),o=t[`#${r}`];if(o&&!e.tags.find(([i,s])=>i===n.slice(1)&&o.indexOf(s)!==-1))return!1}return!(t.since&&e.created_at<t.since||t.until&&e.created_at>t.until)}function rc(t,e){for(let n=0;n<t.length;n++)if(nc(t[n],e))return!0;return!1}function oc(t,e){let n=e.length+3,r=t.indexOf(`"${e}":`)+n,o=t.slice(r).indexOf('"')+r+1;return t.slice(o,o+64)}function ic(t){let e=t.slice(0,22).indexOf('"EVENT"');if(e===-1)return null;let n=t.slice(e+7+1).indexOf('"');if(n===-1)return null;let r=e+7+1+n,o=t.slice(r+1,80).indexOf('"');if(o===-1)return null;let i=r+1+o;return t.slice(r+1,i)}function sc(t,e){return{kind:tc,created_at:Math.floor(Date.now()/1e3),tags:[["relay",t],["challenge",e]],content:""}}async function cc(){return new Promise(t=>{const e=new MessageChannel,n=()=>{e.port1.removeEventListener("message",n),t()};e.port1.addEventListener("message",n),e.port2.postMessage(0),e.port1.start()})}var lc=t=>(t[Zt]=!0,!0),to;try{to=WebSocket}catch{}var eo=class{constructor(t,e){m(this,"url");m(this,"_connected",!1);m(this,"onclose",null);m(this,"onnotice",t=>console.debug(`NOTICE from ${this.url}: ${t}`));m(this,"baseEoseTimeout",4400);m(this,"connectionTimeout",4400);m(this,"openSubs",new Map);m(this,"connectionTimeoutHandle");m(this,"connectionPromise");m(this,"openCountRequests",new Map);m(this,"openEventPublishes",new Map);m(this,"ws");m(this,"incomingMessageQueue",new Vs);m(this,"queueRunning",!1);m(this,"challenge");m(this,"serial",0);m(this,"verifyEvent");this.url=we(t),this.verifyEvent=e.verifyEvent}static async connect(t,e){const n=new eo(t,e);return await n.connect(),n}closeAllSubscriptions(t){for(let[e,n]of this.openSubs)n.close(t);this.openSubs.clear();for(let[e,n]of this.openEventPublishes)n.reject(new Error(t));this.openEventPublishes.clear();for(let[e,n]of this.openCountRequests)n.reject(new Error(t));this.openCountRequests.clear()}get connected(){return this._connected}async connect(){return this.connectionPromise?this.connectionPromise:(this.challenge=void 0,this.connectionPromise=new Promise((t,e)=>{this.connectionTimeoutHandle=setTimeout(()=>{var n;e("connection timed out"),this.connectionPromise=void 0,(n=this.onclose)==null||n.call(this),this.closeAllSubscriptions("relay connection timed out")},this.connectionTimeout);try{this.ws=new to(this.url)}catch(n){e(n);return}this.ws.onopen=()=>{clearTimeout(this.connectionTimeoutHandle),this._connected=!0,t()},this.ws.onerror=n=>{var r;e(n.message),this._connected&&((r=this.onclose)==null||r.call(this),this.closeAllSubscriptions("relay connection errored"),this._connected=!1)},this.ws.onclose=async()=>{var n;this.connectionPromise=void 0,(n=this.onclose)==null||n.call(this),this.closeAllSubscriptions("relay connection closed"),this._connected=!1},this.ws.onmessage=this._onmessage.bind(this)}),this.connectionPromise)}async runQueue(){for(this.queueRunning=!0;this.handleNext()!==!1;)await cc();this.queueRunning=!1}handleNext(){var n,r;const t=this.incomingMessageQueue.dequeue();if(!t)return!1;const e=ic(t);if(e){const o=this.openSubs.get(e);if(!o)return;const i=oc(t,"id"),s=(n=o.alreadyHaveEvent)==null?void 0:n.call(o,i);if((r=o.receivedEvent)==null||r.call(o,this,i),s)return}try{let o=JSON.parse(t);switch(o[0]){case"EVENT":{const i=this.openSubs.get(o[1]),s=o[2];this.verifyEvent(s)&&rc(i.filters,s)&&i.onevent(s);return}case"COUNT":{const i=o[1],s=o[2],c=this.openCountRequests.get(i);c&&(c.resolve(s.count),this.openCountRequests.delete(i));return}case"EOSE":{const i=this.openSubs.get(o[1]);if(!i)return;i.receivedEose();return}case"OK":{const i=o[1],s=o[2],c=o[3],l=this.openEventPublishes.get(i);s?l.resolve(c):l.reject(new Error(c)),this.openEventPublishes.delete(i);return}case"CLOSED":{const i=o[1],s=this.openSubs.get(i);if(!s)return;s.closed=!0,s.close(o[2]);return}case"NOTICE":this.onnotice(o[1]);return;case"AUTH":{this.challenge=o[1];return}}}catch{return}}async send(t){if(!this.connectionPromise)throw new Error("sending on closed connection");this.connectionPromise.then(()=>{var e;(e=this.ws)==null||e.send(t)})}async auth(t){if(!this.challenge)throw new Error("can't perform auth, no challenge was received");const e=await t(sc(this.url,this.challenge)),n=new Promise((r,o)=>{this.openEventPublishes.set(e.id,{resolve:r,reject:o})});return this.send('["AUTH",'+JSON.stringify(e)+"]"),n}async publish(t){const e=new Promise((n,r)=>{this.openEventPublishes.set(t.id,{resolve:n,reject:r})});return this.send('["EVENT",'+JSON.stringify(t)+"]"),e}async count(t,e){this.serial++;const n=(e==null?void 0:e.id)||"count:"+this.serial,r=new Promise((o,i)=>{this.openCountRequests.set(n,{resolve:o,reject:i})});return this.send('["COUNT","'+n+'",'+JSON.stringify(t)+"]"),r}subscribe(t,e){const n=this.prepareSubscription(t,e);return n.fire(),n}prepareSubscription(t,e){this.serial++;const n=e.id||"sub:"+this.serial,r=new ac(this,n,t,e);return this.openSubs.set(n,r),r}close(){var t;this.closeAllSubscriptions("relay connection closed by us"),this._connected=!1,(t=this.ws)==null||t.close()}_onmessage(t){this.incomingMessageQueue.enqueue(t.data),this.queueRunning||this.runQueue()}},ac=class{constructor(t,e,n,r){m(this,"relay");m(this,"id");m(this,"closed",!1);m(this,"eosed",!1);m(this,"filters");m(this,"alreadyHaveEvent");m(this,"receivedEvent");m(this,"onevent");m(this,"oneose");m(this,"onclose");m(this,"eoseTimeout");m(this,"eoseTimeoutHandle");this.relay=t,this.filters=n,this.id=e,this.alreadyHaveEvent=r.alreadyHaveEvent,this.receivedEvent=r.receivedEvent,this.eoseTimeout=r.eoseTimeout||t.baseEoseTimeout,this.oneose=r.oneose,this.onclose=r.onclose,this.onevent=r.onevent||(o=>{console.warn(`onevent() callback not defined for subscription '${this.id}' in relay ${this.relay.url}. event received:`,o)})}fire(){this.relay.send('["REQ","'+this.id+'",'+JSON.stringify(this.filters).substring(1)),this.eoseTimeoutHandle=setTimeout(this.receivedEose.bind(this),this.eoseTimeout)}receivedEose(){var t;this.eosed||(clearTimeout(this.eoseTimeoutHandle),this.eosed=!0,(t=this.oneose)==null||t.call(this))}close(t="closed by caller"){var e;this.closed||(this.relay.send('["CLOSE",'+JSON.stringify(this.id)+"]"),this.closed=!0),this.relay.openSubs.delete(this.id),(e=this.onclose)==null||e.call(this,t)}},uc=class{constructor(t){m(this,"relays",new Map);m(this,"seenOn",new Map);m(this,"trackRelays",!1);m(this,"verifyEvent");m(this,"trustedRelayURLs",new Set);this.verifyEvent=t.verifyEvent}async ensureRelay(t,e){t=we(t);let n=this.relays.get(t);return n||(n=new eo(t,{verifyEvent:this.trustedRelayURLs.has(t)?lc:this.verifyEvent}),e!=null&&e.connectionTimeout&&(n.connectionTimeout=e.connectionTimeout),this.relays.set(t,n)),await n.connect(),n}close(t){t.map(we).forEach(e=>{var n;(n=this.relays.get(e))==null||n.close()})}subscribeMany(t,e,n){this.trackRelays&&(n.receivedEvent=(u,w)=>{let h=this.seenOn.get(w);h||(h=new Set,this.seenOn.set(w,h)),h.add(u)});const r=new Set,o=[],i=[];let s=u=>{var w;i[u]=!0,i.filter(h=>h).length===t.length&&((w=n.oneose)==null||w.call(n),s=()=>{})};const c=[];let l=(u,w)=>{var h;s(u),c[u]=w,c.filter(g=>g).length===t.length&&((h=n.onclose)==null||h.call(n,c),l=()=>{})};const a=u=>{var h;if((h=n.alreadyHaveEvent)!=null&&h.call(n,u))return!0;const w=r.has(u);return r.add(u),w},f=Promise.all(t.map(we).map(async(u,w,h)=>{if(h.indexOf(u)!==w){l(w,"duplicate url");return}let g;try{g=await this.ensureRelay(u,{connectionTimeout:n.maxWait?Math.max(n.maxWait*.8,n.maxWait-1e3):void 0})}catch(p){l(w,(p==null?void 0:p.message)||String(p));return}let d=g.subscribe(e,{...n,oneose:()=>s(w),onclose:p=>l(w,p),alreadyHaveEvent:a,eoseTimeout:n.maxWait});o.push(d)}));return{async close(){await f,o.forEach(u=>{u.close()})}}}subscribeManyEose(t,e,n){const r=this.subscribeMany(t,e,{...n,oneose(){r.close()}});return r}async querySync(t,e,n){return new Promise(async r=>{const o=[];this.subscribeManyEose(t,[e],{...n,onevent(i){o.push(i)},onclose(i){r(o)}})})}async get(t,e,n){e.limit=1;const r=await this.querySync(t,e,n);return r.sort((o,i)=>i.created_at-o.created_at),r[0]||null}publish(t,e){return t.map(we).map(async(n,r,o)=>o.indexOf(n)!==r?Promise.reject("duplicate url"):(await this.ensureRelay(n)).publish(e))}},fc=class extends uc{constructor(){super({verifyEvent:Qr})}},no;try{no=fetch}catch{}var ro=/^bunker:\/\/([0-9a-f]{64})\??([?\/\w:.=&%]*)$/,dc=/^[^\s@]+@[^\s@]+\.[^\s@]+$/;async function hc(t){let e=t.match(ro);if(e)try{const n=e[1],r=new URLSearchParams(e[2]);return{pubkey:n,relays:r.getAll("relay"),secret:r.get("secret")}}catch{}return oo(t)}async function oo(t){const e=t.match(Qs);if(!e)return null;const[n,r="_",o]=e;try{const i=`https://${o}/.well-known/nostr.json?name=${r}`,s=await(await no(i,{redirect:"error"})).json();let c=s.names[r],l=s.nip46[c]||[];return{pubkey:c,relays:l,secret:null}}catch{return null}}var Nn=class{constructor(t,e,n={}){m(this,"pool");m(this,"subCloser");m(this,"isOpen");m(this,"serial");m(this,"idPrefix");m(this,"listeners");m(this,"waitingForAuth");m(this,"secretKey");m(this,"bp");if(e.relays.length===0)throw new Error("no relays are specified for this bunker");this.pool=n.pool||new fc,this.secretKey=t,this.bp=e,this.isOpen=!1,this.idPrefix=Math.random().toString(36).substring(7),this.serial=0,this.listeners={},this.waitingForAuth={};const r=this.listeners,o=this.waitingForAuth;this.subCloser=this.pool.subscribeMany(this.bp.relays,[{kinds:[Tn],"#p":[Jr(this.secretKey)]}],{async onevent(i){const{id:s,result:c,error:l}=JSON.parse(await Js(t,i.pubkey,i.content));if(c==="auth_url"&&o[s]){delete o[s],n.onauth?n.onauth(l):console.warn(`nostr-tools/nip46: remote signer ${e.pubkey} tried to send an "auth_url"='${l}' but there was no onauth() callback configured.`);return}let a=r[s];a&&(l?a.reject(l):c&&a.resolve(c),delete r[s])}}),this.isOpen=!0}async close(){this.isOpen=!1,this.subCloser.close()}async sendRequest(t,e){return new Promise(async(n,r)=>{try{if(!this.isOpen)throw new Error("this signer is not open anymore, create a new one");this.serial++;const o=`${this.idPrefix}-${this.serial}`,i=await Ys(this.secretKey,this.bp.pubkey,JSON.stringify({id:o,method:t,params:e})),s=Fs({kind:Tn,tags:[["p",this.bp.pubkey]],content:i,created_at:Math.floor(Date.now()/1e3)},this.secretKey);this.listeners[o]={resolve:n,reject:r},this.waitingForAuth[o]=!0,await Promise.any(this.pool.publish(this.bp.relays,s))}catch(o){r(o)}})}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",[Jr(this.secretKey),this.bp.secret||""])}async getPublicKey(){return this.bp.pubkey}async getRelays(){return JSON.parse(await this.sendRequest("get_relays",[]))}async signEvent(t){let e=await this.sendRequest("sign_event",[JSON.stringify(t)]),n=JSON.parse(e);if(n.pubkey===this.bp.pubkey&&Qr(n))return n;throw new Error(`event returned from bunker is improperly signed: ${JSON.stringify(n)}`)}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 nip44GetKey(t){let e=await this.sendRequest("nip44_get_key",[t]);return Fe(e)}async nip44Encrypt(t,e){return await this.sendRequest("nip44_encrypt",[t,e])}async nip44Decrypt(t,e){return await this.sendRequest("nip44_encrypt",[t,e])}};async function wc(t,e,n,r,o){if(o&&!dc.test(o))throw new Error("Invalid email");let i=Gs(),s=new Nn(i,t.bunkerPointer,e),c=await s.sendRequest("create_account",[n,r,o||""]);return s.bp.pubkey=c,await s.connect(),s}async function pc(t,e){const n=await t.querySync(e,{kinds:[ec],"#k":[Tn.toString()]});return n.sort((o,i)=>i.created_at-o.created_at),(await Promise.all(n.map(async(o,i)=>{try{const s=JSON.parse(o.content);try{if(n.findIndex(l=>JSON.parse(l.content).nip05===s.nip05)!==i)return}catch{}const c=await oo(s.nip05);if(c&&c.pubkey===o.pubkey&&c.relays.length)return{bunkerPointer:c,nip05:s.nip05,domain:s.nip05.split("@")[1],name:s.name||s.display_name,picture:s.picture,about:s.about,website:s.website,local:!1}}catch{return}}))).filter(o=>o!==void 0)}var io=/^(?:([\w.+-]+)@)?([\w_-]+(\.[\w_-]+)+)$/,so;try{so=fetch}catch{}async function gc(t){var i;const e=t.match(io);if(!e)return null;const[n,r="_",o]=e;try{const s=`https://${o}/.well-known/nostr.json?name=${r}`,c=await(await so(s,{redirect:"error"})).json();let l=c.names[r];return l?{pubkey:l,relays:(i=c.relays)==null?void 0:i[l]}:null}catch{return null}}new TextDecoder("utf-8"),new TextEncoder;var bc=5e3;function yc(t){return Ec("npub",Fe(t))}function mc(t,e){let n=Fr.toWords(e);return Fr.encode(t,n,bc)}function Ec(t,e){return mc(t,e)}const re=[];function xc(t,e=R){let n;const r=new Set;function o(c){if(je(t,c)&&(t=c,n)){const l=!re.length;for(const a of r)a[1](),re.push(a,t);if(l){for(let a=0;a<re.length;a+=2)re[a][0](re[a+1]);re.length=0}}}function i(c){o(c(t))}function s(c,l=R){const a=[c,l];return r.add(a),r.size===1&&(n=e(o,i)||R),c(t),()=>{r.delete(a),r.size===0&&n&&(n(),n=null)}}return{set:o,update:i,subscribe:s}}const vc=t=>{const{subscribe:e,set:n}=xc(void 0,()=>{let r=window.matchMedia(t);n(r.matches);const o=()=>n(r.matches);return"addEventListener"in r?r.addEventListener("change",o):r.addListener(o),()=>{"removeEventListener"in r?r.removeEventListener("change",o):r.removeListener(o)}});return{subscribe:e}};function _c(t){let e,n,r;return{c(){e=Me("svg"),n=Me("circle"),r=Me("path"),_(n,"class","tw-opacity-25"),_(n,"cx","12"),_(n,"cy","12"),_(n,"r","10"),_(n,"stroke","currentColor"),_(n,"stroke-width","4"),_(r,"class","tw-opacity-75"),_(r,"fill","currentColor"),_(r,"d","M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"),_(e,"class","tw-animate-spin tw-ml-2 tw-h-5 tw-w-5 tw-text-white"),_(e,"xmlns","http://www.w3.org/2000/svg"),_(e,"fill","none"),_(e,"viewBox","0 0 24 24")},m(o,i){j(o,e,i),U(e,n),U(e,r)},p:R,i:R,o:R,d(o){o&&H(e)}}}class co extends Gn{constructor(e){super(),Zn(this,e,null,_c,je,{})}}const{window:Pn}=ko;function lo(t,e,n){const r=t.slice();return r[61]=e[n],r}function Sc(t){let e,n,r,o,i,s,c,l,a,f,u;const w=[Oc,Bc,Ac],h=[];function g(d,p){return d[12]?0:d[13]?d[13]?2:-1:1}return~(s=g(t))&&(c=h[s]=w[s](t)),{c(){e=L("div"),n=L("button"),r=Z("⤫"),i=V(),c&&c.c(),_(n,"class",o="tw-absolute tw-top-0 tw-right-0.5 tw-bg-transparent tw-border-none tw-cursor-pointer tw-text-"+t[0]+"-950 tw-text-3xl"),_(e,"class",l="sm:tw-w-80 tw-px-6 tw-py-8 tw-bg-"+t[0]+"-700 tw-rounded-md tw-shadow-[0_0px_30px_0px_rgba(0,0,0,0.6)] tw-transition-all tw-animate-show "+t[19])},m(d,p){j(d,e,p),U(e,n),U(n,r),U(e,i),~s&&h[s].m(e,null),a=!0,f||(u=et(n,"click",t[22]),f=!0)},p(d,p){(!a||p[0]&1&&o!==(o="tw-absolute tw-top-0 tw-right-0.5 tw-bg-transparent tw-border-none tw-cursor-pointer tw-text-"+d[0]+"-950 tw-text-3xl"))&&_(n,"class",o);let b=s;s=g(d),s===b?~s&&h[s].p(d,p):(c&&(xe(),wt(h[b],1,1,()=>{h[b]=null}),ve()),~s?(c=h[s],c?c.p(d,p):(c=h[s]=w[s](d),c.c()),ut(c,1),c.m(e,null)):c=null),(!a||p[0]&524289&&l!==(l="sm:tw-w-80 tw-px-6 tw-py-8 tw-bg-"+d[0]+"-700 tw-rounded-md tw-shadow-[0_0px_30px_0px_rgba(0,0,0,0.6)] tw-transition-all tw-animate-show "+d[19]))&&_(e,"class",l)},i(d){a||(ut(c),a=!0)},o(d){wt(c),a=!1},d(d){d&&H(e),~s&&h[s].d(),f=!1,u()}}}function kc(t){let e,n,r,o,i;const s=[Uc,Pc,Nc],c=[];function l(a,f){return a[10]?0:a[13]?2:1}return n=l(t),r=c[n]=s[n](t),{c(){e=L("div"),r.c(),_(e,"class",o="tw-px-4 tw-py-2 tw-bg-"+t[0]+"-700 hover:tw-bg-"+t[0]+"-800 tw-rounded tw-shadow-[0_0px_10px_0px_rgba(0,0,0,0.3)] tw-transition-all tw-duration-200 "+t[19])},m(a,f){j(a,e,f),c[n].m(e,null),i=!0},p(a,f){let u=n;n=l(a),n===u?c[n].p(a,f):(xe(),wt(c[u],1,1,()=>{c[u]=null}),ve(),r=c[n],r?r.p(a,f):(r=c[n]=s[n](a),r.c()),ut(r,1),r.m(e,null)),(!i||f[0]&524289&&o!==(o="tw-px-4 tw-py-2 tw-bg-"+a[0]+"-700 hover:tw-bg-"+a[0]+"-800 tw-rounded tw-shadow-[0_0px_10px_0px_rgba(0,0,0,0.3)] tw-transition-all tw-duration-200 "+a[19]))&&_(e,"class",o)},i(a){i||(ut(r),i=!0)},o(a){wt(r),i=!1},d(a){a&&H(e),c[n].d()}}}function Ac(t){let e,n,r,o,i,s,c=t[13].npub+"",l,a,f,u,w,h,g,d,p,b,v,S=Or(t[9])+"",A,B,y,E=(t[13].picture||t[13].name)&&ao(t);return{c(){e=L("div"),n=L("div"),n.textContent="You are connected to Nostr as",r=V(),o=L("a"),E&&E.c(),i=V(),s=L("div"),l=Z(c),f=V(),u=L("button"),w=Z("Disconnect"),g=V(),d=L("div"),p=Z("This webpage is using the public key:"),b=L("br"),v=V(),A=Z(S),_(n,"class","tw-text-sm tw-mb-4"),_(s,"class","tw-block tw-break-all"),_(o,"target","_blank"),_(o,"href",a="https://nosta.me/"+t[13].npub),_(o,"class","tw-text-white tw-no-underline tw-group"),_(e,"class","tw-text-center"),_(u,"class",h="tw-block tw-w-full tw-my-2 tw-mt-6 tw-px-2 tw-py-1 tw-text-lg tw-rounded tw-border-0 tw-bg-"+t[0]+"-900 hover:tw-bg-"+t[0]+"-950 tw-hover:bg-indigo-900 tw-cursor-pointer tw-text-white"),_(d,"class","tw-block tw-break-all tw-mt-6 tw-text-center tw-text-sm")},m(k,C){j(k,e,C),U(e,n),U(e,r),U(e,o),E&&E.m(o,null),U(o,i),U(o,s),U(s,l),j(k,f,C),j(k,u,C),U(u,w),j(k,g,C),j(k,d,C),U(d,p),U(d,b),U(d,v),U(d,A),B||(y=et(u,"click",t[24]),B=!0)},p(k,C){k[13].picture||k[13].name?E?E.p(k,C):(E=ao(k),E.c(),E.m(o,i)):E&&(E.d(1),E=null),C[0]&8192&&c!==(c=k[13].npub+"")&&ye(l,c),C[0]&8192&&a!==(a="https://nosta.me/"+k[13].npub)&&_(o,"href",a),C[0]&1&&h!==(h="tw-block tw-w-full tw-my-2 tw-mt-6 tw-px-2 tw-py-1 tw-text-lg tw-rounded tw-border-0 tw-bg-"+k[0]+"-900 hover:tw-bg-"+k[0]+"-950 tw-hover:bg-indigo-900 tw-cursor-pointer tw-text-white")&&_(u,"class",h),C[0]&512&&S!==(S=Or(k[9])+"")&&ye(A,S)},i:R,o:R,d(k){k&&(H(e),H(f),H(u),H(g),H(d)),E&&E.d(),B=!1,y()}}}function Bc(t){let e,n,r,o,i,s,c,l,a,f,u,w,h,g,d,p;const b=[Tc,Ic],v=[];function S(y,E){return y[10]?0:1}c=S(t),l=v[c]=b[c](t);let A=t[10]&&t[11]&&ho(t),B=!t[10]&&wo(t);return{c(){e=L("div"),e.textContent="How do you want to connect to Nostr?",n=V(),r=L("form"),o=L("input"),i=V(),s=L("button"),l.c(),u=V(),A&&A.c(),w=V(),B&&B.c(),h=Bo(),_(e,"class","tw-text-lg tw-text-center"),_(o,"class","tw-box-border tw-w-full tw-px-2 tw-py-1 tw-rounded tw-text-lg tw-border-none tw-outline-none"),_(o,"placeholder","user@provider or bunker://..."),o.autofocus=!0,o.disabled=t[10],_(s,"class",a="tw-flex tw-w-full tw-mt-4 tw-px-2 tw-py-1 tw-text-lg tw-rounded tw-border-0 tw-bg-"+t[0]+"-900 hover:tw-bg-"+t[0]+"-950 tw-hover:bg-indigo-900 tw-cursor-pointer tw-text-white disabled:tw-bg-neutral-400 disabled:tw-text-neutral-200 disabled:tw-cursor-default tw-items-center tw-justify-center"),s.disabled=f=!t[18]||t[10],_(r,"class","flex tw-mt-4 tw-mb-1")},m(y,E){j(y,e,E),j(y,n,E),j(y,r,E),U(r,o),t[39](o),Gt(o,t[2]),U(r,i),U(r,s),v[c].m(s,null),U(r,u),A&&A.m(r,null),j(y,w,E),B&&B.m(y,E),j(y,h,E),g=!0,o.focus(),d||(p=[et(o,"input",t[40]),et(r,"submit",t[23])],d=!0)},p(y,E){(!g||E[0]&1024)&&(o.disabled=y[10]),E[0]&4&&o.value!==y[2]&&Gt(o,y[2]);let k=c;c=S(y),c!==k&&(xe(),wt(v[k],1,1,()=>{v[k]=null}),ve(),l=v[c],l||(l=v[c]=b[c](y),l.c()),ut(l,1),l.m(s,null)),(!g||E[0]&1&&a!==(a="tw-flex tw-w-full tw-mt-4 tw-px-2 tw-py-1 tw-text-lg tw-rounded tw-border-0 tw-bg-"+y[0]+"-900 hover:tw-bg-"+y[0]+"-950 tw-hover:bg-indigo-900 tw-cursor-pointer tw-text-white disabled:tw-bg-neutral-400 disabled:tw-text-neutral-200 disabled:tw-cursor-default tw-items-center tw-justify-center"))&&_(s,"class",a),(!g||E[0]&263168&&f!==(f=!y[18]||y[10]))&&(s.disabled=f),y[10]&&y[11]?A?A.p(y,E):(A=ho(y),A.c(),A.m(r,null)):A&&(A.d(1),A=null),y[10]?B&&(B.d(1),B=null):B?B.p(y,E):(B=wo(y),B.c(),B.m(h.parentNode,h))},i(y){g||(ut(l),g=!0)},o(y){wt(l),g=!1},d(y){y&&(H(e),H(n),H(r),H(w),H(h)),t[39](null),v[c].d(),A&&A.d(),B&&B.d(y),d=!1,At(p)}}}function Oc(t){let e,n,r,o,i,s,c,l,a,f,u,w,h,g,d,p,b,v,S,A,B,y,E,k,C=Vn(t[14]),N=[];for(let I=0;I<C.length;I+=1)N[I]=po(lo(t,C,I));return{c(){e=L("div"),e.textContent="Create a Nostr account",n=V(),r=L("form"),o=L("div"),i=L("input"),s=V(),c=L("div"),c.textContent="@",l=V(),a=L("select");for(let I=0;I<N.length;I+=1)N[I].c();f=V(),u=L("div"),u.textContent=`A window from the selected provider will pop up to finalize the
2
- creation; if it doesn't display check if the browser is blocking it`,w=V(),h=L("button"),g=Z("Create »"),b=V(),v=L("div"),S=Z("Do you already have a Nostr address?"),A=L("br"),B=V(),y=L("button"),y.textContent="Login now",_(e,"class","tw-text-lg tw-text-center"),_(i,"class","tw-box-border tw-w-40 tw-px-2 tw-py-1 tw-rounded tw-text-lg tw-border-none tw-outline-none"),_(i,"placeholder","bob"),i.autofocus=!0,_(c,"class","tw-mx-2 tw-text-2xl"),_(a,"class","tw-w-full tw-box-border tw-px-2 tw-py-1 tw-rounded tw-text-lg tw-border-none tw-outline-none"),t[8]===void 0&&me(()=>t[38].call(a)),_(o,"class","tw-flex items-center"),_(u,"class","tw-text-sm tw-text-center tw-mt-4 tw-leading-4"),_(h,"class",d="tw-block tw-w-full tw-mt-4 tw-px-2 tw-py-1 tw-text-lg tw-rounded tw-border-0 tw-bg-"+t[0]+"-900 hover:tw-bg-"+t[0]+"-950 tw-hover:bg-indigo-900 tw-cursor-pointer tw-text-white disabled:tw-bg-neutral-400 disabled:tw-text-neutral-200 disabled:tw-cursor-default"),h.disabled=p=!t[8]||!t[7],_(r,"class","tw-mt-4 tw-mb-1"),_(y,"class","tw-border-0 tw-bg-transparent tw-text-white tw-cursor-pointer tw-underline tw-text-sm"),_(v,"class","tw-mt-6 tw-text-center tw-text-sm tw-leading-3")},m(I,q){j(I,e,q),j(I,n,q),j(I,r,q),U(r,o),U(o,i),t[36](i),Gt(i,t[7]),U(o,s),U(o,c),U(o,l),U(o,a);for(let P=0;P<N.length;P+=1)N[P]&&N[P].m(a,null);Mn(a,t[8],!0),U(r,f),U(r,u),U(r,w),U(r,h),U(h,g),j(I,b,q),j(I,v,q),U(v,S),U(v,A),U(v,B),U(v,y),i.focus(),E||(k=[et(i,"input",t[37]),et(i,"input",t[28]),et(a,"change",t[38]),et(r,"submit",t[27]),et(y,"click",t[26])],E=!0)},p(I,q){if(q[0]&128&&i.value!==I[7]&&Gt(i,I[7]),q[0]&16384){C=Vn(I[14]);let P;for(P=0;P<C.length;P+=1){const Q=lo(I,C,P);N[P]?N[P].p(Q,q):(N[P]=po(Q),N[P].c(),N[P].m(a,null))}for(;P<N.length;P+=1)N[P].d(1);N.length=C.length}q[0]&16640&&Mn(a,I[8]),q[0]&1&&d!==(d="tw-block tw-w-full tw-mt-4 tw-px-2 tw-py-1 tw-text-lg tw-rounded tw-border-0 tw-bg-"+I[0]+"-900 hover:tw-bg-"+I[0]+"-950 tw-hover:bg-indigo-900 tw-cursor-pointer tw-text-white disabled:tw-bg-neutral-400 disabled:tw-text-neutral-200 disabled:tw-cursor-default")&&_(h,"class",d),q[0]&16768&&p!==(p=!I[8]||!I[7])&&(h.disabled=p)},i:R,o:R,d(I){I&&(H(e),H(n),H(r),H(b),H(v)),t[36](null),Ao(N,I),E=!1,At(k)}}}function ao(t){let e,n,r=t[13].picture&&uo(t),o=t[13].name&&fo(t);return{c(){e=L("div"),r&&r.c(),n=V(),o&&o.c(),_(e,"class","tw-flex tw-items-center tw-justify-center tw-gap-2 tw-mb-2")},m(i,s){j(i,e,s),r&&r.m(e,null),U(e,n),o&&o.m(e,null)},p(i,s){i[13].picture?r?r.p(i,s):(r=uo(i),r.c(),r.m(e,n)):r&&(r.d(1),r=null),i[13].name?o?o.p(i,s):(o=fo(i),o.c(),o.m(e,null)):o&&(o.d(1),o=null)},d(i){i&&H(e),r&&r.d(),o&&o.d()}}}function uo(t){let e,n,r;return{c(){e=L("img"),be(e.src,n=t[13].picture)||_(e,"src",n),_(e,"alt",""),_(e,"class",r="tw-w-10 tw-h-10 tw-rounded-full tw-border-solid tw-border-2 tw-border-transparent group-hover:tw-border-"+t[0]+"-100")},m(o,i){j(o,e,i)},p(o,i){i[0]&8192&&!be(e.src,n=o[13].picture)&&_(e,"src",n),i[0]&1&&r!==(r="tw-w-10 tw-h-10 tw-rounded-full tw-border-solid tw-border-2 tw-border-transparent group-hover:tw-border-"+o[0]+"-100")&&_(e,"class",r)},d(o){o&&H(e)}}}function fo(t){let e,n=t[13].name+"",r;return{c(){e=L("div"),r=Z(n),_(e,"class","tw-text-3xl group-hover:tw-underline tw-decoration-2 tw-underline-offset-4")},m(o,i){j(o,e,i),U(e,r)},p(o,i){i[0]&8192&&n!==(n=o[13].name+"")&&ye(r,n)},d(o){o&&H(e)}}}function Ic(t){let e;return{c(){e=Z("Connect »")},m(n,r){j(n,e,r)},i:R,o:R,d(n){n&&H(e)}}}function Tc(t){let e,n,r;return n=new co({}),{c(){e=Z(`Connecting to bunker
3
- `),Wn(n.$$.fragment)},m(o,i){j(o,e,i),De(n,o,i),r=!0},i(o){r||(ut(n.$$.fragment,o),r=!0)},o(o){wt(n.$$.fragment,o),r=!1},d(o){o&&H(e),Ve(n,o)}}}function ho(t){let e,n,r,o,i;return{c(){e=L("div"),n=Z(`Waiting too much?
4
- `),r=L("button"),r.textContent="Cancel the connection",_(r,"class","tw-border-0 tw-bg-transparent tw-text-white tw-cursor-pointer tw-underline tw-text-sm"),_(e,"class","tw-mt-6 tw-text-center tw-text-sm tw-leading-3")},m(s,c){j(s,e,c),U(e,n),U(e,r),o||(i=et(r,"click",t[29]),o=!0)},p:R,d(s){s&&H(e),o=!1,i()}}}function wo(t){let e,n,r,o,i,s,c;return{c(){e=L("div"),n=Z("Do you need a Nostr account?"),r=L("br"),o=V(),i=L("button"),i.textContent="Sign up now",_(i,"class","tw-border-0 tw-bg-transparent tw-text-white tw-cursor-pointer tw-underline tw-text-sm"),_(e,"class","tw-mt-6 tw-text-center tw-text-sm tw-leading-3")},m(l,a){j(l,e,a),U(e,n),U(e,r),U(e,o),U(e,i),s||(c=et(i,"click",t[25]),s=!0)},p:R,d(l){l&&H(e),s=!1,c()}}}function po(t){let e,n,r;return{c(){e=L("option"),_(e,"label",n=t[61].domain),e.__value=r=t[61],Gt(e,e.__value),_(e,"class","tw-px-2 tw-py-1 tw-text-lg")},m(o,i){j(o,e,i)},p(o,i){i[0]&16384&&n!==(n=o[61].domain)&&_(e,"label",n),i[0]&16384&&r!==(r=o[61])&&(e.__value=r,Gt(e,e.__value))},d(o){o&&H(e)}}}function Nc(t){let e,n,r=(t[13].name||t[13].npub.slice(0,7)+"…"+t[13].npub.slice(-4))+"",o;function i(l,a){return l[13].picture?Cc:$c}let s=i(t),c=s(t);return{c(){e=L("div"),c.c(),n=V(),o=Z(r),_(e,"class","tw-flex tw-items-center")},m(l,a){j(l,e,a),c.m(e,null),U(e,n),U(e,o)},p(l,a){s===(s=i(l))&&c?c.p(l,a):(c.d(1),c=s(l),c&&(c.c(),c.m(e,n))),a[0]&8192&&r!==(r=(l[13].name||l[13].npub.slice(0,7)+"…"+l[13].npub.slice(-4))+"")&&ye(o,r)},i:R,o:R,d(l){l&&H(e),c.d()}}}function Pc(t){let e;return{c(){e=Z("Connect with Nostr")},m(n,r){j(n,e,r)},p:R,i:R,o:R,d(n){n&&H(e)}}}function Uc(t){let e,n,r,o;return r=new co({}),{c(){e=L("div"),n=Z(`Connecting to bunker
5
- `),Wn(r.$$.fragment),_(e,"class","tw-flex tw-items-center")},m(i,s){j(i,e,s),U(e,n),De(r,e,null),o=!0},p:R,i(i){o||(ut(r.$$.fragment,i),o=!0)},o(i){wt(r.$$.fragment,i),o=!1},d(i){i&&H(e),Ve(r)}}}function $c(t){let e;return{c(){e=Z("☉")},m(n,r){j(n,e,r)},p:R,d(n){n&&H(e)}}}function Cc(t){let e,n;return{c(){e=L("img"),be(e.src,n=t[13].picture)||_(e,"src",n),_(e,"alt",""),_(e,"class","tw-w-5 tw-h-5 tw-rounded-full tw-mr-2")},m(r,o){j(r,e,o)},p(r,o){o[0]&8192&&!be(e.src,n=r[13].picture)&&_(e,"src",n)},d(r){r&&H(e)}}}function Lc(t){let e,n,r,o,i,s,c;const l=[kc,Sc],a=[];function f(u,w){return u[17]?1:0}return n=f(t),r=a[n]=l[n](t),{c(){e=L("div"),r.c(),_(e,"class","tw-text-white tw-font-sans draggable tw-animate-fadein"),_(e,"style",o="position: fixed; "+(t[17]&&t[3]?"width: 100%;":"")+"; right: "+(t[17]&&t[3]?"0":t[1])+"px; user-select: none; "+(t[17]&&t[3]?"bottom: 0px":t[16]+":"+t[15]+"px")),zn(e,"tw-cursor-pointer",!t[13]&&!t[17])},m(u,w){j(u,e,w),a[n].m(e,null),t[41](e),i=!0,s||(c=[et(Pn,"click",t[21]),et(Pn,"mouseup",t[32]),et(Pn,"mousemove",t[31]),et(e,"mousedown",t[30])],s=!0)},p(u,w){let h=n;n=f(u),n===h?a[n].p(u,w):(xe(),wt(a[h],1,1,()=>{a[h]=null}),ve(),r=a[n],r?r.p(u,w):(r=a[n]=l[n](u),r.c()),ut(r,1),r.m(e,null)),(!i||w[0]&229386&&o!==(o="position: fixed; "+(u[17]&&u[3]?"width: 100%;":"")+"; right: "+(u[17]&&u[3]?"0":u[1])+"px; user-select: none; "+(u[17]&&u[3]?"bottom: 0px":u[16]+":"+u[15]+"px")))&&_(e,"style",o),(!i||w[0]&139264)&&zn(e,"tw-cursor-pointer",!u[13]&&!u[17])},i(u){i||(ut(r),i=!0)},o(u){wt(r),i=!1},d(u){u&&H(e),a[n].d(),t[41](null),s=!1,At(c)}}}const Ct=20;function Rc(t,e,n){let r,o,i,s,c,l;const a=vc("only screen and (max-width: 640px)");So(t,a,T=>n(3,l=T));let f,{accent:u}=e,{position:w="top"}=e;const h=window,g=new ps;let d,p,b,v,S,A;const B=localStorage.getItem("wnj:clientSecret");B?A=Fe(B):(A=Yi(),localStorage.setItem("wnj:clientSecret",nt(A)));let y="closed",E,k,C,N,I=!1,q,P,Q,x=[],{right:O=20}=e,$=!1,M=!1,z,D,X;const Y={pool:g,onauth(T){window.open(T,"window.nostr","width=600,height=800,popup=yes")}},ft=Yn(()=>{switch(y){case"justopened":n(34,y="opened");break;case"justclosed":n(34,y="closed");break}},500);function tt(){n(34,y="justopened"),ft()}function dt(){n(34,y="justclosed"),ft()}ht();let Lt={isWnj:!0,async getPublicKey(){return!N&&!P&&tt(),(await C).bp.pubkey},async signEvent(T){return!N&&!P&&tt(),(await C).signEvent(T)},async getRelays(){return!N&&!P&&tt(),(await C).getRelays()},nip04:{async encrypt(T,W){return!N&&!P&&tt(),(await C).nip04Encrypt(T,W)},async decrypt(T,W){return!N&&!P&&tt(),(await C).nip04Decrypt(T,W)}}};function ht(){dt(),E=null,C=new Promise(T=>{k=T}),n(10,N=!1),n(12,q=!1),n(13,P=null),Q=null}No(()=>{let T=localStorage.getItem("wnj:bunkerPointer");if(T&&(E=JSON.parse(T),Ln(new Nn(A,E,Y))),h.nostr&&!h.nostr.isWnj){h.destroyWnj();return}else Object.defineProperty(window,"nostr",{get(){return Lt},set(W){Lt=W,W.isWnj||h.destroyWnj()},configurable:!0});return()=>{Q&&Q.close()}});function pe(T){Math.abs(o-D)>6||Date.now()-X>600||y==="justopened"||y==="justclosed"||(T.composedPath().find(W=>W.id==="wnj")?tt():dt())}function St(T){dt(),n(12,q=!1),T.stopPropagation()}async function Rt(T){if(T.preventDefault(),E=await hc(d.value),!E){d.setCustomValidity('invalid NIP-05 "name@domain.com" address or bunker:// URI');return}d.setCustomValidity(""),Ln(new Nn(A,E,Y))}async function Re(T){T.preventDefault(),localStorage.removeItem("wnj:bunkerPointer"),h.isWnj&&delete h.nostr,ht()}async function Ht(T){T.preventDefault(),n(12,q=!0),x.length===0&&(n(14,x=await pc(g,["wss://relay.nostr.band","wss://nos.lol","wss://nostr-pub.wellorder.net"])),n(8,S=x[0]))}function st(T){n(12,q=!1)}async function qt(T){if(T.preventDefault(),!S)return;let W=await wc(S,Y,b.value,S.domain);tt(),n(12,q=!1),Ln(W)}const He=Yn(async()=>{S&&b.value.length>0&&(await gc(b.value+"@"+S.domain)?b.setCustomValidity(`'${b.value}' is already taken.`):b.setCustomValidity(""))},500);function qe(){n(11,I=!1),n(10,N=!1)}async function Ln(T){let W;function Rn(){n(11,I=!0),n(17,i=!0),clearTimeout(W)}n(10,N=!0),W=setTimeout(Rn,5e3),await T.connect(),clearTimeout(W),E=T.bp,n(13,P={pubkey:T.bp.pubkey,npub:yc(T.bp.pubkey),event:null}),localStorage.setItem("wnj:bunkerPointer",JSON.stringify(E)),Q=g.subscribeMany(["wss://purplepag.es","wss://relay.snort.social","wss://relay.nos.social"],[{kinds:[0],authors:[T.bp.pubkey]}],{onevent(Hn){var Eo;if(!((((Eo=P.event)==null?void 0:Eo.created_at)||0)>=Hn.created_at))try{let{name:xo,picture:Fc}=JSON.parse(Hn.content);n(13,P.event=Hn,P),n(13,P.name=xo,P),n(13,P.picture=Fc,P)}catch{}}}),n(10,N=!1),n(11,I=!1),dt(),k(T)}function jc(T){if(i)return;$=!0;const W=f.getBoundingClientRect();z=T.clientY-W.top,D=o,X=Date.now()}function Mc(T){$&&(r==="top"?n(15,o=T.clientY):n(15,o=window.innerHeight-T.clientY),n(15,o-=z),n(35,M=!0),o<Ct&&n(15,o=Ct),o>window.innerHeight-Ct&&n(15,o=window.innerHeight-Ct))}function zc(){if($=!1,setTimeout(()=>{n(35,M=!1)},10),M){const T=f.getBoundingClientRect(),W=window.innerHeight,Rn=W/2;T.top<Rn?(n(16,r="top"),n(15,o=T.top)):(n(16,r="bottom"),n(15,o=W-T.bottom)),o<Ct&&n(15,o=Ct),localStorage.setItem("wnj:origin",r),localStorage.setItem("wnj:ypos",o.toString())}}function Kc(T){se[T?"unshift":"push"](()=>{b=T,n(6,b)})}function Dc(){v=this.value,n(7,v)}function Vc(){S=Io(this),n(8,S),n(14,x)}function Wc(T){se[T?"unshift":"push"](()=>{d=T,n(5,d)})}function Zc(){p=this.value,n(2,p)}function Gc(T){se[T?"unshift":"push"](()=>{f=T,n(4,f)})}return t.$$set=T=>{"accent"in T&&n(0,u=T.accent),"position"in T&&n(33,w=T.position),"right"in T&&n(1,O=T.right)},t.$$.update=()=>{t.$$.dirty[0]&8|t.$$.dirty[1]&4&&n(16,r=l?"bottom":localStorage.getItem("wnj:origin")||w),t.$$.dirty[0]&8&&n(15,o=l?Ct:parseInt(localStorage.getItem("wnj:ypos")||"0")||Ct),t.$$.dirty[1]&8&&n(17,i=y==="justopened"||y==="opened"),t.$$.dirty[0]&1|t.$$.dirty[1]&16&&n(19,s=M?"tw-cursor-grabbing tw-outline-dashed tw-outline-"+u+"-500 tw-outline-1 tw-outline-offset-4":"tw-outline-none"),t.$$.dirty[0]&4&&n(18,c=p&&(p.match(ro)||p.match(io)))},[u,O,p,l,f,d,b,v,S,A,N,I,q,P,x,o,r,i,c,s,a,pe,St,Rt,Re,Ht,st,qt,He,qe,jc,Mc,zc,w,y,M,Kc,Dc,Vc,Wc,Zc,Gc]}class Hc extends Gn{constructor(e){super(),Zn(this,e,Rc,Lc,je,{accent:0,position:33,right:1},null,[-1,-1,-1])}}const Un=window;Un.destroyWnj=()=>{setTimeout(()=>{qc.$destroy()},1)};const $n=document.createElement("div");$n.style.zIndex="90000",document.body.appendChild($n);const Cn=document.createElement("div");Cn.id="wnj";const go=document.createElement("style");go.innerHTML=jt;const bo=$n.attachShadow({mode:"open"});bo.appendChild(Cn),bo.appendChild(go);const qc=new Hc({target:Cn,props:{accent:((yo=Un.wnjParams)==null?void 0:yo.accent)||"cyan",position:((mo=Un.wnjParams)==null?void 0:mo.position)==="bottom"?"bottom":"top"}})})();
1
+ var nl=Object.defineProperty;var rl=(zt,q,Bt)=>q in zt?nl(zt,q,{enumerable:!0,configurable:!0,writable:!0,value:Bt}):zt[q]=Bt;var E=(zt,q,Bt)=>(rl(zt,typeof q!="symbol"?q+"":q,Bt),Bt);(function(){"use strict";var xo,vo;const zt='.tw-absolute{position:absolute}.tw-right-0{right:0}.tw-right-0\\.5{right:.125rem}.tw-top-0{top:0}.tw-mx-2{margin-left:.5rem;margin-right:.5rem}.tw-my-2{margin-top:.5rem;margin-bottom:.5rem}.tw-mb-1{margin-bottom:.25rem}.tw-mb-2{margin-bottom:.5rem}.tw-mb-4{margin-bottom:1rem}.tw-ml-2{margin-left:.5rem}.tw-mr-2{margin-right:.5rem}.tw-mt-4{margin-top:1rem}.tw-mt-6{margin-top:1.5rem}.tw-box-border{box-sizing:border-box}.tw-block{display:block}.tw-flex{display:flex}.tw-h-10{height:2.5rem}.tw-h-5{height:1.25rem}.tw-w-10{width:2.5rem}.tw-w-40{width:10rem}.tw-w-5{width:1.25rem}.tw-w-full{width:100%}@keyframes tw-moveIn{0%{transform:translateY(-10px)}to{transform:translateY(0)}}.tw-animate-fadein{animation:tw-fadeIn 1s ease-in-out,tw-moveIn 1s ease-in-out}@keyframes tw-fadeIn{0%{opacity:0}to{opacity:1}}.tw-animate-show{animation:tw-fadeIn .2s ease-in-out}@keyframes tw-spin{to{transform:rotate(360deg)}}.tw-animate-spin{animation:tw-spin 1s linear infinite}.tw-cursor-grabbing{cursor:grabbing}.tw-cursor-pointer{cursor:pointer}.tw-items-center{align-items:center}.tw-justify-center{justify-content:center}.tw-gap-2{gap:.5rem}.tw-break-all{word-break:break-all}.tw-rounded{border-radius:.25rem}.tw-rounded-full{border-radius:9999px}.tw-rounded-md{border-radius:.375rem}.tw-border-0{border-width:0px}.tw-border-2{border-width:2px}.tw-border-solid{border-style:solid}.tw-border-none{border-style:none}.tw-border-transparent{border-color:transparent}.tw-bg-cyan-700{--tw-bg-opacity: 1;background-color:rgb(14 116 144 / var(--tw-bg-opacity))}.tw-bg-cyan-800{--tw-bg-opacity: 1;background-color:rgb(21 94 117 / var(--tw-bg-opacity))}.tw-bg-cyan-900{--tw-bg-opacity: 1;background-color:rgb(22 78 99 / var(--tw-bg-opacity))}.tw-bg-cyan-950{--tw-bg-opacity: 1;background-color:rgb(8 51 68 / var(--tw-bg-opacity))}.tw-bg-green-700{--tw-bg-opacity: 1;background-color:rgb(21 128 61 / var(--tw-bg-opacity))}.tw-bg-green-800{--tw-bg-opacity: 1;background-color:rgb(22 101 52 / var(--tw-bg-opacity))}.tw-bg-green-900{--tw-bg-opacity: 1;background-color:rgb(20 83 45 / var(--tw-bg-opacity))}.tw-bg-green-950{--tw-bg-opacity: 1;background-color:rgb(5 46 22 / var(--tw-bg-opacity))}.tw-bg-neutral-700{--tw-bg-opacity: 1;background-color:rgb(64 64 64 / var(--tw-bg-opacity))}.tw-bg-neutral-800{--tw-bg-opacity: 1;background-color:rgb(38 38 38 / var(--tw-bg-opacity))}.tw-bg-neutral-900{--tw-bg-opacity: 1;background-color:rgb(23 23 23 / var(--tw-bg-opacity))}.tw-bg-neutral-950{--tw-bg-opacity: 1;background-color:rgb(10 10 10 / var(--tw-bg-opacity))}.tw-bg-orange-700{--tw-bg-opacity: 1;background-color:rgb(194 65 12 / var(--tw-bg-opacity))}.tw-bg-orange-800{--tw-bg-opacity: 1;background-color:rgb(154 52 18 / var(--tw-bg-opacity))}.tw-bg-orange-900{--tw-bg-opacity: 1;background-color:rgb(124 45 18 / var(--tw-bg-opacity))}.tw-bg-orange-950{--tw-bg-opacity: 1;background-color:rgb(67 20 7 / var(--tw-bg-opacity))}.tw-bg-purple-700{--tw-bg-opacity: 1;background-color:rgb(126 34 206 / var(--tw-bg-opacity))}.tw-bg-purple-800{--tw-bg-opacity: 1;background-color:rgb(107 33 168 / var(--tw-bg-opacity))}.tw-bg-purple-900{--tw-bg-opacity: 1;background-color:rgb(88 28 135 / var(--tw-bg-opacity))}.tw-bg-purple-950{--tw-bg-opacity: 1;background-color:rgb(59 7 100 / var(--tw-bg-opacity))}.tw-bg-red-700{--tw-bg-opacity: 1;background-color:rgb(185 28 28 / var(--tw-bg-opacity))}.tw-bg-red-800{--tw-bg-opacity: 1;background-color:rgb(153 27 27 / var(--tw-bg-opacity))}.tw-bg-red-900{--tw-bg-opacity: 1;background-color:rgb(127 29 29 / var(--tw-bg-opacity))}.tw-bg-red-950{--tw-bg-opacity: 1;background-color:rgb(69 10 10 / var(--tw-bg-opacity))}.tw-bg-stone-700{--tw-bg-opacity: 1;background-color:rgb(68 64 60 / var(--tw-bg-opacity))}.tw-bg-stone-800{--tw-bg-opacity: 1;background-color:rgb(41 37 36 / var(--tw-bg-opacity))}.tw-bg-stone-900{--tw-bg-opacity: 1;background-color:rgb(28 25 23 / var(--tw-bg-opacity))}.tw-bg-stone-950{--tw-bg-opacity: 1;background-color:rgb(12 10 9 / var(--tw-bg-opacity))}.tw-bg-transparent{background-color:transparent}.tw-bg-yellow-100{--tw-bg-opacity: 1;background-color:rgb(254 249 195 / var(--tw-bg-opacity))}.tw-p-2{padding:.5rem}.tw-px-2{padding-left:.5rem;padding-right:.5rem}.tw-px-4{padding-left:1rem;padding-right:1rem}.tw-px-6{padding-left:1.5rem;padding-right:1.5rem}.tw-py-1{padding-top:.25rem;padding-bottom:.25rem}.tw-py-2{padding-top:.5rem;padding-bottom:.5rem}.tw-py-8{padding-top:2rem;padding-bottom:2rem}.tw-text-center{text-align:center}.tw-font-sans{font-family:ui-sans-serif,system-ui,sans-serif,"Apple Color Emoji","Segoe UI Emoji",Segoe UI Symbol,"Noto Color Emoji"}.tw-text-2xl{font-size:1.5rem;line-height:2rem}.tw-text-3xl{font-size:1.875rem;line-height:2.25rem}.tw-text-lg{font-size:1.125rem;line-height:1.75rem}.tw-text-sm{font-size:.875rem;line-height:1.25rem}.tw-leading-3{line-height:.75rem}.tw-leading-4{line-height:1rem}.tw-text-cyan-950{--tw-text-opacity: 1;color:rgb(8 51 68 / var(--tw-text-opacity))}.tw-text-green-950{--tw-text-opacity: 1;color:rgb(5 46 22 / var(--tw-text-opacity))}.tw-text-neutral-950{--tw-text-opacity: 1;color:rgb(10 10 10 / var(--tw-text-opacity))}.tw-text-orange-950{--tw-text-opacity: 1;color:rgb(67 20 7 / var(--tw-text-opacity))}.tw-text-purple-950{--tw-text-opacity: 1;color:rgb(59 7 100 / var(--tw-text-opacity))}.tw-text-red-400{--tw-text-opacity: 1;color:rgb(248 113 113 / var(--tw-text-opacity))}.tw-text-red-950{--tw-text-opacity: 1;color:rgb(69 10 10 / var(--tw-text-opacity))}.tw-text-stone-950{--tw-text-opacity: 1;color:rgb(12 10 9 / var(--tw-text-opacity))}.tw-text-white{--tw-text-opacity: 1;color:rgb(255 255 255 / var(--tw-text-opacity))}.tw-underline{text-decoration-line:underline}.tw-no-underline{text-decoration-line:none}.tw-decoration-2{text-decoration-thickness:2px}.tw-underline-offset-4{text-underline-offset:4px}.tw-opacity-25{opacity:.25}.tw-opacity-75{opacity:.75}.tw-shadow-\\[0_0px_10px_0px_rgba\\(0\\,0\\,0\\,0\\.3\\)\\]{--tw-shadow: 0 0px 10px 0px rgba(0,0,0,.3);--tw-shadow-colored: 0 0px 10px 0px var(--tw-shadow-color);box-shadow:var(--tw-ring-offset-shadow, 0 0 #0000),var(--tw-ring-shadow, 0 0 #0000),var(--tw-shadow)}.tw-shadow-\\[0_0px_30px_0px_rgba\\(0\\,0\\,0\\,0\\.6\\)\\]{--tw-shadow: 0 0px 30px 0px rgba(0,0,0,.6);--tw-shadow-colored: 0 0px 30px 0px var(--tw-shadow-color);box-shadow:var(--tw-ring-offset-shadow, 0 0 #0000),var(--tw-ring-shadow, 0 0 #0000),var(--tw-shadow)}.tw-outline-none{outline:2px solid transparent;outline-offset:2px}.tw-outline-dashed{outline-style:dashed}.tw-outline-1{outline-width:1px}.tw-outline-offset-4{outline-offset:4px}.tw-outline-cyan-500{outline-color:#06b6d4}.tw-outline-green-500{outline-color:#22c55e}.tw-outline-neutral-500{outline-color:#737373}.tw-outline-orange-500{outline-color:#f97316}.tw-outline-purple-500{outline-color:#a855f7}.tw-outline-red-500{outline-color:#ef4444}.tw-outline-stone-500{outline-color:#78716c}.tw-transition-all{transition-property:all;transition-timing-function:cubic-bezier(.4,0,.2,1);transition-duration:.15s}.tw-duration-200{transition-duration:.2s}.disabled\\:tw-cursor-default:disabled{cursor:default}.disabled\\:tw-bg-neutral-400:disabled{--tw-bg-opacity: 1;background-color:rgb(163 163 163 / var(--tw-bg-opacity))}.disabled\\:tw-text-neutral-200:disabled{--tw-text-opacity: 1;color:rgb(229 229 229 / var(--tw-text-opacity))}.tw-group:hover .group-hover\\:tw-underline{text-decoration-line:underline}@media (min-width: 640px){.sm\\:tw-w-80{width:20rem}}';function q(){}function Bt(t){return t()}function qn(){return Object.create(null)}function Ot(t){t.forEach(Bt)}function jn(t){return typeof t=="function"}function ze(t,e){return t!=t?e==e:t!==e||t&&typeof t=="object"||typeof t=="function"}let me;function Ee(t,e){return t===e?!0:(me||(me=document.createElement("a")),me.href=e,t===me.href)}function ko(t){return Object.keys(t).length===0}function So(t,...e){if(t==null){for(const r of e)r(void 0);return q}const n=t.subscribe(...e);return n.unsubscribe?()=>n.unsubscribe():n}function Ao(t,e,n){t.$$.on_destroy.push(So(e,n))}const Bo=typeof window<"u"?window:typeof globalThis<"u"?globalThis:global;function U(t,e){t.appendChild(e)}function j(t,e,n){t.insertBefore(e,n||null)}function $(t){t.parentNode&&t.parentNode.removeChild(t)}function Oo(t,e){for(let n=0;n<t.length;n+=1)t[n]&&t[n].d(e)}function C(t){return document.createElement(t)}function Ke(t){return document.createElementNS("http://www.w3.org/2000/svg",t)}function Z(t){return document.createTextNode(t)}function V(){return Z(" ")}function Io(){return Z("")}function tt(t,e,n,r){return t.addEventListener(e,n,r),()=>t.removeEventListener(e,n,r)}function k(t,e,n){n==null?t.removeAttribute(e):t.getAttribute(e)!==n&&t.setAttribute(e,n)}function To(t){return Array.from(t.childNodes)}function ce(t,e){e=""+e,t.data!==e&&(t.data=e)}function Yt(t,e){t.value=e??""}function Mn(t,e,n){for(let r=0;r<t.options.length;r+=1){const o=t.options[r];if(o.__value===e){o.selected=!0;return}}(!n||e!==void 0)&&(t.selectedIndex=-1)}function No(t){const e=t.querySelector(":checked");return e&&e.__value}function zn(t,e,n){t.classList.toggle(e,!!n)}let le;function ae(t){le=t}function Po(){if(!le)throw new Error("Function called outside component initialization");return le}function Uo(t){Po().$$.on_mount.push(t)}const Jt=[],ue=[];let Qt=[];const Kn=[],Lo=Promise.resolve();let De=!1;function Co(){De||(De=!0,Lo.then(Dn))}function xe(t){Qt.push(t)}const Ve=new Set;let Xt=0;function Dn(){if(Xt!==0)return;const t=le;do{try{for(;Xt<Jt.length;){const e=Jt[Xt];Xt++,ae(e),Ro(e.$$)}}catch(e){throw Jt.length=0,Xt=0,e}for(ae(null),Jt.length=0,Xt=0;ue.length;)ue.pop()();for(let e=0;e<Qt.length;e+=1){const n=Qt[e];Ve.has(n)||(Ve.add(n),n())}Qt.length=0}while(Jt.length);for(;Kn.length;)Kn.pop()();De=!1,Ve.clear(),ae(t)}function Ro(t){if(t.fragment!==null){t.update(),Ot(t.before_update);const e=t.dirty;t.dirty=[-1],t.fragment&&t.fragment.p(t.ctx,e),t.after_update.forEach(xe)}}function Ho(t){const e=[],n=[];Qt.forEach(r=>t.indexOf(r)===-1?e.push(r):n.push(r)),n.forEach(r=>r()),Qt=e}const ve=new Set;let Kt;function _e(){Kt={r:0,c:[],p:Kt}}function ke(){Kt.r||Ot(Kt.c),Kt=Kt.p}function ft(t,e){t&&t.i&&(ve.delete(t),t.i(e))}function wt(t,e,n,r){if(t&&t.o){if(ve.has(t))return;ve.add(t),Kt.c.push(()=>{ve.delete(t),r&&(n&&t.d(1),r())}),t.o(e)}else r&&r()}function Vn(t){return(t==null?void 0:t.length)!==void 0?t:Array.from(t)}function Wn(t){t&&t.c()}function We(t,e,n){const{fragment:r,after_update:o}=t.$$;r&&r.m(e,n),xe(()=>{const i=t.$$.on_mount.map(Bt).filter(jn);t.$$.on_destroy?t.$$.on_destroy.push(...i):Ot(i),t.$$.on_mount=[]}),o.forEach(xe)}function Ze(t,e){const n=t.$$;n.fragment!==null&&(Ho(n.after_update),Ot(n.on_destroy),n.fragment&&n.fragment.d(e),n.on_destroy=n.fragment=null,n.ctx=[])}function $o(t,e){t.$$.dirty[0]===-1&&(Jt.push(t),Co(),t.$$.dirty.fill(0)),t.$$.dirty[e/31|0]|=1<<e%31}function Zn(t,e,n,r,o,i,s=null,c=[-1]){const l=le;ae(t);const a=t.$$={fragment:null,ctx:[],props:i,update:q,not_equal:o,bound:qn(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(e.context||(l?l.$$.context:[])),callbacks:qn(),dirty:c,skip_bound:!1,root:e.target||l.$$.root};s&&s(a.root);let f=!1;if(a.ctx=n?n(t,e.props||{},(u,w,...h)=>{const g=h.length?h[0]:w;return a.ctx&&o(a.ctx[u],a.ctx[u]=g)&&(!a.skip_bound&&a.bound[u]&&a.bound[u](g),f&&$o(t,u)),w}):[],a.update(),f=!0,Ot(a.before_update),a.fragment=r?r(a.ctx):!1,e.target){if(e.hydrate){const u=To(e.target);a.fragment&&a.fragment.l(u),u.forEach($)}else a.fragment&&a.fragment.c();e.intro&&ft(t.$$.fragment),We(t,e.target,e.anchor),Dn()}ae(l)}class Gn{constructor(){E(this,"$$");E(this,"$$set")}$destroy(){Ze(this,1),this.$destroy=q}$on(e,n){if(!jn(n))return q;const r=this.$$.callbacks[e]||(this.$$.callbacks[e]=[]);return r.push(n),()=>{const o=r.indexOf(n);o!==-1&&r.splice(o,1)}}$set(e){this.$$set&&!ko(e)&&(this.$$.skip_bound=!0,this.$$set(e),this.$$.skip_bound=!1)}}const qo="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(qo);function jo(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var Ge={exports:{}};function Fn(t,e=100,n={}){if(typeof t!="function")throw new TypeError(`Expected the first parameter to be a function, got \`${typeof t}\`.`);if(e<0)throw new RangeError("`wait` must not be negative.");const{immediate:r}=typeof n=="boolean"?{immediate:n}:n;let o,i,s,c,l;function a(){const u=Date.now()-c;if(u<e&&u>=0)s=setTimeout(a,e-u);else if(s=void 0,!r){const w=o,h=i;o=void 0,i=void 0,l=t.apply(w,h)}}const f=function(...u){if(o&&this!==o)throw new Error("Debounced method called with different contexts.");o=this,i=u,c=Date.now();const w=r&&!s;if(s||(s=setTimeout(a,e)),w){const h=o,g=i;o=void 0,i=void 0,l=t.apply(h,g)}return l};return f.clear=()=>{s&&(clearTimeout(s),s=void 0)},f.flush=()=>{if(!s)return;const u=o,w=i;o=void 0,i=void 0,l=t.apply(u,w),clearTimeout(s),s=void 0},f}Ge.exports.debounce=Fn,Ge.exports=Fn;var Mo=Ge.exports;const Yn=jo(Mo),Fe=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Jn=t=>t instanceof Uint8Array,Ye=t=>new DataView(t.buffer,t.byteOffset,t.byteLength),pt=(t,e)=>t<<32-e|t>>>e;if(!(new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68))throw new Error("Non little-endian hardware is not supported");const zo=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function et(t){if(!Jn(t))throw new Error("Uint8Array expected");let e="";for(let n=0;n<t.length;n++)e+=zo[t[n]];return e}function Je(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);const e=t.length;if(e%2)throw new Error("padded hex string expected, got unpadded hex of length "+e);const n=new Uint8Array(e/2);for(let r=0;r<n.length;r++){const o=r*2,i=t.slice(o,o+2),s=Number.parseInt(i,16);if(Number.isNaN(s)||s<0)throw new Error("Invalid byte sequence");n[r]=s}return n}function Ko(t){if(typeof t!="string")throw new Error(`utf8ToBytes expected string, got ${typeof t}`);return new Uint8Array(new TextEncoder().encode(t))}function Qn(t){if(typeof t=="string"&&(t=Ko(t)),!Jn(t))throw new Error(`expected Uint8Array, got ${typeof t}`);return t}let Do=class{clone(){return this._cloneInto()}};function Xn(t){const e=r=>t().update(Qn(r)).digest(),n=t();return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=()=>t(),e}function Vo(t=32){if(Fe&&typeof Fe.getRandomValues=="function")return Fe.getRandomValues(new Uint8Array(t));throw new Error("crypto.getRandomValues must be defined")}function tr(t){if(!Number.isSafeInteger(t)||t<0)throw new Error(`Wrong positive integer: ${t}`)}function er(t,...e){if(!(t instanceof Uint8Array))throw new Error("Expected Uint8Array");if(e.length>0&&!e.includes(t.length))throw new Error(`Expected Uint8Array of length ${e}, not of length=${t.length}`)}function Wo(t){if(typeof t!="function"||typeof t.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");tr(t.outputLen),tr(t.blockLen)}function Se(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 Zo(t,e){er(t);const n=e.outputLen;if(t.length<n)throw new Error(`digestInto() expects output buffer of length at least ${n}`)}const Qe=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */const nr=t=>t instanceof Uint8Array,Xe=t=>new DataView(t.buffer,t.byteOffset,t.byteLength),gt=(t,e)=>t<<32-e|t>>>e;if(!(new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68))throw new Error("Non little-endian hardware is not supported");function Go(t){if(typeof t!="string")throw new Error(`utf8ToBytes expected string, got ${typeof t}`);return new Uint8Array(new TextEncoder().encode(t))}function tn(t){if(typeof t=="string"&&(t=Go(t)),!nr(t))throw new Error(`expected Uint8Array, got ${typeof t}`);return t}function Fo(...t){const e=new Uint8Array(t.reduce((r,o)=>r+o.length,0));let n=0;return t.forEach(r=>{if(!nr(r))throw new Error("Uint8Array expected");e.set(r,n),n+=r.length}),e}class rr{clone(){return this._cloneInto()}}function Yo(t){const e=r=>t().update(tn(r)).digest(),n=t();return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=()=>t(),e}function or(t=32){if(Qe&&typeof Qe.getRandomValues=="function")return Qe.getRandomValues(new Uint8Array(t));throw new Error("crypto.getRandomValues must be defined")}function Jo(t,e,n,r){if(typeof t.setBigUint64=="function")return t.setBigUint64(e,n,r);const o=BigInt(32),i=BigInt(4294967295),s=Number(n>>o&i),c=Number(n&i),l=r?4:0,a=r?0:4;t.setUint32(e+l,s,r),t.setUint32(e+a,c,r)}let Qo=class extends rr{constructor(e,n,r,o){super(),this.blockLen=e,this.outputLen=n,this.padOffset=r,this.isLE=o,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(e),this.view=Xe(this.buffer)}update(e){Se(this);const{view:n,buffer:r,blockLen:o}=this;e=tn(e);const i=e.length;for(let s=0;s<i;){const c=Math.min(o-this.pos,i-s);if(c===o){const l=Xe(e);for(;o<=i-s;s+=o)this.process(l,s);continue}r.set(e.subarray(s,s+c),this.pos),this.pos+=c,s+=c,this.pos===o&&(this.process(n,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){Se(this),Zo(e,this),this.finished=!0;const{buffer:n,view:r,blockLen:o,isLE:i}=this;let{pos:s}=this;n[s++]=128,this.buffer.subarray(s).fill(0),this.padOffset>o-s&&(this.process(r,0),s=0);for(let u=s;u<o;u++)n[u]=0;Jo(r,o-8,BigInt(this.length*8),i),this.process(r,0);const c=Xe(e),l=this.outputLen;if(l%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const a=l/4,f=this.get();if(a>f.length)throw new Error("_sha2: outputLen bigger than state");for(let u=0;u<a;u++)c.setUint32(4*u,f[u],i)}digest(){const{buffer:e,outputLen:n}=this;this.digestInto(e);const r=e.slice(0,n);return this.destroy(),r}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());const{blockLen:n,buffer:r,length:o,finished:i,destroyed:s,pos:c}=this;return e.length=o,e.pos=c,e.finished=i,e.destroyed=s,o%n&&e.buffer.set(r),e}};const Xo=(t,e,n)=>t&e^~t&n,ti=(t,e,n)=>t&e^t&n^e&n,ei=new Uint32Array([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]),It=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Tt=new Uint32Array(64);let ni=class extends Qo{constructor(){super(64,32,8,!1),this.A=It[0]|0,this.B=It[1]|0,this.C=It[2]|0,this.D=It[3]|0,this.E=It[4]|0,this.F=It[5]|0,this.G=It[6]|0,this.H=It[7]|0}get(){const{A:e,B:n,C:r,D:o,E:i,F:s,G:c,H:l}=this;return[e,n,r,o,i,s,c,l]}set(e,n,r,o,i,s,c,l){this.A=e|0,this.B=n|0,this.C=r|0,this.D=o|0,this.E=i|0,this.F=s|0,this.G=c|0,this.H=l|0}process(e,n){for(let u=0;u<16;u++,n+=4)Tt[u]=e.getUint32(n,!1);for(let u=16;u<64;u++){const w=Tt[u-15],h=Tt[u-2],g=gt(w,7)^gt(w,18)^w>>>3,d=gt(h,17)^gt(h,19)^h>>>10;Tt[u]=d+Tt[u-7]+g+Tt[u-16]|0}let{A:r,B:o,C:i,D:s,E:c,F:l,G:a,H:f}=this;for(let u=0;u<64;u++){const w=gt(c,6)^gt(c,11)^gt(c,25),h=f+w+Xo(c,l,a)+ei[u]+Tt[u]|0,d=(gt(r,2)^gt(r,13)^gt(r,22))+ti(r,o,i)|0;f=a,a=l,l=c,c=s+h|0,s=i,i=o,o=r,r=h+d|0}r=r+this.A|0,o=o+this.B|0,i=i+this.C|0,s=s+this.D|0,c=c+this.E|0,l=l+this.F|0,a=a+this.G|0,f=f+this.H|0,this.set(r,o,i,s,c,l,a,f)}roundClean(){Tt.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};const en=Yo(()=>new ni);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const ir=BigInt(0),Ae=BigInt(1),ri=BigInt(2),Be=t=>t instanceof Uint8Array,oi=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function te(t){if(!Be(t))throw new Error("Uint8Array expected");let e="";for(let n=0;n<t.length;n++)e+=oi[t[n]];return e}function sr(t){const e=t.toString(16);return e.length&1?`0${e}`:e}function nn(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);return BigInt(t===""?"0":`0x${t}`)}function ee(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);const e=t.length;if(e%2)throw new Error("padded hex string expected, got unpadded hex of length "+e);const n=new Uint8Array(e/2);for(let r=0;r<n.length;r++){const o=r*2,i=t.slice(o,o+2),s=Number.parseInt(i,16);if(Number.isNaN(s)||s<0)throw new Error("Invalid byte sequence");n[r]=s}return n}function rt(t){return nn(te(t))}function rn(t){if(!Be(t))throw new Error("Uint8Array expected");return nn(te(Uint8Array.from(t).reverse()))}function Nt(t,e){return ee(t.toString(16).padStart(e*2,"0"))}function on(t,e){return Nt(t,e).reverse()}function ii(t){return ee(sr(t))}function Q(t,e,n){let r;if(typeof e=="string")try{r=ee(e)}catch(i){throw new Error(`${t} must be valid hex string, got "${e}". Cause: ${i}`)}else if(Be(e))r=Uint8Array.from(e);else throw new Error(`${t} must be hex string or Uint8Array`);const o=r.length;if(typeof n=="number"&&o!==n)throw new Error(`${t} expected ${n} bytes, got ${o}`);return r}function Dt(...t){const e=new Uint8Array(t.reduce((r,o)=>r+o.length,0));let n=0;return t.forEach(r=>{if(!Be(r))throw new Error("Uint8Array expected");e.set(r,n),n+=r.length}),e}function si(t,e){if(t.length!==e.length)return!1;for(let n=0;n<t.length;n++)if(t[n]!==e[n])return!1;return!0}function ci(t){if(typeof t!="string")throw new Error(`utf8ToBytes expected string, got ${typeof t}`);return new Uint8Array(new TextEncoder().encode(t))}function li(t){let e;for(e=0;t>ir;t>>=Ae,e+=1);return e}function ai(t,e){return t>>BigInt(e)&Ae}const ui=(t,e,n)=>t|(n?Ae:ir)<<BigInt(e),sn=t=>(ri<<BigInt(t-1))-Ae,cn=t=>new Uint8Array(t),cr=t=>Uint8Array.from(t);function lr(t,e,n){if(typeof t!="number"||t<2)throw new Error("hashLen must be a number");if(typeof e!="number"||e<2)throw new Error("qByteLen must be a number");if(typeof n!="function")throw new Error("hmacFn must be a function");let r=cn(t),o=cn(t),i=0;const s=()=>{r.fill(1),o.fill(0),i=0},c=(...u)=>n(o,r,...u),l=(u=cn())=>{o=c(cr([0]),u),r=c(),u.length!==0&&(o=c(cr([1]),u),r=c())},a=()=>{if(i++>=1e3)throw new Error("drbg: tried 1000 values");let u=0;const w=[];for(;u<e;){r=c();const h=r.slice();w.push(h),u+=r.length}return Dt(...w)};return(u,w)=>{s(),l(u);let h;for(;!(h=w(a()));)l();return s(),h}}const fi={bigint:t=>typeof t=="bigint",function:t=>typeof t=="function",boolean:t=>typeof t=="boolean",string:t=>typeof t=="string",stringOrUint8Array:t=>typeof t=="string"||t instanceof Uint8Array,isSafeInteger:t=>Number.isSafeInteger(t),array:t=>Array.isArray(t),field:(t,e)=>e.Fp.isValid(t),hash:t=>typeof t=="function"&&Number.isSafeInteger(t.outputLen)};function fe(t,e,n={}){const r=(o,i,s)=>{const c=fi[i];if(typeof c!="function")throw new Error(`Invalid validator "${i}", expected function`);const l=t[o];if(!(s&&l===void 0)&&!c(l,t))throw new Error(`Invalid param ${String(o)}=${l} (${typeof l}), expected ${i}`)};for(const[o,i]of Object.entries(e))r(o,i,!1);for(const[o,i]of Object.entries(n))r(o,i,!0);return t}const di=Object.freeze(Object.defineProperty({__proto__:null,bitGet:ai,bitLen:li,bitMask:sn,bitSet:ui,bytesToHex:te,bytesToNumberBE:rt,bytesToNumberLE:rn,concatBytes:Dt,createHmacDrbg:lr,ensureBytes:Q,equalBytes:si,hexToBytes:ee,hexToNumber:nn,numberToBytesBE:Nt,numberToBytesLE:on,numberToHexUnpadded:sr,numberToVarBytesBE:ii,utf8ToBytes:ci,validateObject:fe},Symbol.toStringTag,{value:"Module"}));/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const F=BigInt(0),W=BigInt(1),Vt=BigInt(2),hi=BigInt(3),ln=BigInt(4),ar=BigInt(5),ur=BigInt(8);BigInt(9),BigInt(16);function J(t,e){const n=t%e;return n>=F?n:e+n}function wi(t,e,n){if(n<=F||e<F)throw new Error("Expected power/modulo > 0");if(n===W)return F;let r=W;for(;e>F;)e&W&&(r=r*t%n),t=t*t%n,e>>=W;return r}function ct(t,e,n){let r=t;for(;e-- >F;)r*=r,r%=n;return r}function an(t,e){if(t===F||e<=F)throw new Error(`invert: expected positive integers, got n=${t} mod=${e}`);let n=J(t,e),r=e,o=F,i=W;for(;n!==F;){const c=r/n,l=r%n,a=o-i*c;r=n,n=l,o=i,i=a}if(r!==W)throw new Error("invert: does not exist");return J(o,e)}function pi(t){const e=(t-W)/Vt;let n,r,o;for(n=t-W,r=0;n%Vt===F;n/=Vt,r++);for(o=Vt;o<t&&wi(o,e,t)!==t-W;o++);if(r===1){const s=(t+W)/ln;return function(l,a){const f=l.pow(a,s);if(!l.eql(l.sqr(f),a))throw new Error("Cannot find square root");return f}}const i=(n+W)/Vt;return function(c,l){if(c.pow(l,e)===c.neg(c.ONE))throw new Error("Cannot find square root");let a=r,f=c.pow(c.mul(c.ONE,o),n),u=c.pow(l,i),w=c.pow(l,n);for(;!c.eql(w,c.ONE);){if(c.eql(w,c.ZERO))return c.ZERO;let h=1;for(let d=c.sqr(w);h<a&&!c.eql(d,c.ONE);h++)d=c.sqr(d);const g=c.pow(f,W<<BigInt(a-h-1));f=c.sqr(g),u=c.mul(u,g),w=c.mul(w,f),a=h}return u}}function gi(t){if(t%ln===hi){const e=(t+W)/ln;return function(r,o){const i=r.pow(o,e);if(!r.eql(r.sqr(i),o))throw new Error("Cannot find square root");return i}}if(t%ur===ar){const e=(t-ar)/ur;return function(r,o){const i=r.mul(o,Vt),s=r.pow(i,e),c=r.mul(o,s),l=r.mul(r.mul(c,Vt),s),a=r.mul(c,r.sub(l,r.ONE));if(!r.eql(r.sqr(a),o))throw new Error("Cannot find square root");return a}}return pi(t)}const bi=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function yi(t){const e={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},n=bi.reduce((r,o)=>(r[o]="function",r),e);return fe(t,n)}function mi(t,e,n){if(n<F)throw new Error("Expected power > 0");if(n===F)return t.ONE;if(n===W)return e;let r=t.ONE,o=e;for(;n>F;)n&W&&(r=t.mul(r,o)),o=t.sqr(o),n>>=W;return r}function Ei(t,e){const n=new Array(e.length),r=e.reduce((i,s,c)=>t.is0(s)?i:(n[c]=i,t.mul(i,s)),t.ONE),o=t.inv(r);return e.reduceRight((i,s,c)=>t.is0(s)?i:(n[c]=t.mul(i,n[c]),t.mul(i,s)),o),n}function fr(t,e){const n=e!==void 0?e:t.toString(2).length,r=Math.ceil(n/8);return{nBitLength:n,nByteLength:r}}function xi(t,e,n=!1,r={}){if(t<=F)throw new Error(`Expected Field ORDER > 0, got ${t}`);const{nBitLength:o,nByteLength:i}=fr(t,e);if(i>2048)throw new Error("Field lengths over 2048 bytes are not supported");const s=gi(t),c=Object.freeze({ORDER:t,BITS:o,BYTES:i,MASK:sn(o),ZERO:F,ONE:W,create:l=>J(l,t),isValid:l=>{if(typeof l!="bigint")throw new Error(`Invalid field element: expected bigint, got ${typeof l}`);return F<=l&&l<t},is0:l=>l===F,isOdd:l=>(l&W)===W,neg:l=>J(-l,t),eql:(l,a)=>l===a,sqr:l=>J(l*l,t),add:(l,a)=>J(l+a,t),sub:(l,a)=>J(l-a,t),mul:(l,a)=>J(l*a,t),pow:(l,a)=>mi(c,l,a),div:(l,a)=>J(l*an(a,t),t),sqrN:l=>l*l,addN:(l,a)=>l+a,subN:(l,a)=>l-a,mulN:(l,a)=>l*a,inv:l=>an(l,t),sqrt:r.sqrt||(l=>s(c,l)),invertBatch:l=>Ei(c,l),cmov:(l,a,f)=>f?a:l,toBytes:l=>n?on(l,i):Nt(l,i),fromBytes:l=>{if(l.length!==i)throw new Error(`Fp.fromBytes: expected ${i}, got ${l.length}`);return n?rn(l):rt(l)}});return Object.freeze(c)}function dr(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 hr(t){const e=dr(t);return e+Math.ceil(e/2)}function vi(t,e,n=!1){const r=t.length,o=dr(e),i=hr(e);if(r<16||r<i||r>1024)throw new Error(`expected ${i}-1024 bytes of input, got ${r}`);const s=n?rt(t):rn(t),c=J(s,e-W)+W;return n?on(c,o):Nt(c,o)}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const _i=BigInt(0),un=BigInt(1);function ki(t,e){const n=(o,i)=>{const s=i.negate();return o?s:i},r=o=>{const i=Math.ceil(e/o)+1,s=2**(o-1);return{windows:i,windowSize:s}};return{constTimeNegate:n,unsafeLadder(o,i){let s=t.ZERO,c=o;for(;i>_i;)i&un&&(s=s.add(c)),c=c.double(),i>>=un;return s},precomputeWindow(o,i){const{windows:s,windowSize:c}=r(i),l=[];let a=o,f=a;for(let u=0;u<s;u++){f=a,l.push(f);for(let w=1;w<c;w++)f=f.add(a),l.push(f);a=f.double()}return l},wNAF(o,i,s){const{windows:c,windowSize:l}=r(o);let a=t.ZERO,f=t.BASE;const u=BigInt(2**o-1),w=2**o,h=BigInt(o);for(let g=0;g<c;g++){const d=g*l;let p=Number(s&u);s>>=h,p>l&&(p-=w,s+=un);const b=d,v=d+Math.abs(p)-1,B=g%2!==0,I=p<0;p===0?f=f.add(n(B,i[b])):a=a.add(n(I,i[v]))}return{p:a,f}},wNAFCached(o,i,s,c){const l=o._WINDOW_SIZE||1;let a=i.get(o);return a||(a=this.precomputeWindow(o,l),l!==1&&i.set(o,c(a))),this.wNAF(l,a,s)}}}function wr(t){return yi(t.Fp),fe(t,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...fr(t.n,t.nBitLength),...t,p:t.Fp.ORDER})}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function Si(t){const e=wr(t);fe(e,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});const{endo:n,Fp:r,a:o}=e;if(n){if(!r.eql(o,r.ZERO))throw new Error("Endomorphism can only be defined for Koblitz curves that have a=0");if(typeof n!="object"||typeof n.beta!="bigint"||typeof n.splitScalar!="function")throw new Error("Expected endomorphism with beta: bigint and splitScalar: function")}return Object.freeze({...e})}const{bytesToNumberBE:Ai,hexToBytes:Bi}=di,Wt={Err:class extends Error{constructor(e=""){super(e)}},_parseInt(t){const{Err:e}=Wt;if(t.length<2||t[0]!==2)throw new e("Invalid signature integer tag");const n=t[1],r=t.subarray(2,n+2);if(!n||r.length!==n)throw new e("Invalid signature integer: wrong length");if(r[0]&128)throw new e("Invalid signature integer: negative");if(r[0]===0&&!(r[1]&128))throw new e("Invalid signature integer: unnecessary leading zero");return{d:Ai(r),l:t.subarray(n+2)}},toSig(t){const{Err:e}=Wt,n=typeof t=="string"?Bi(t):t;if(!(n instanceof Uint8Array))throw new Error("ui8a expected");let r=n.length;if(r<2||n[0]!=48)throw new e("Invalid signature tag");if(n[1]!==r-2)throw new e("Invalid signature: incorrect length");const{d:o,l:i}=Wt._parseInt(n.subarray(2)),{d:s,l:c}=Wt._parseInt(i);if(c.length)throw new e("Invalid signature: left bytes after parsing");return{r:o,s}},hexFromSig(t){const e=a=>Number.parseInt(a[0],16)&8?"00"+a:a,n=a=>{const f=a.toString(16);return f.length&1?`0${f}`:f},r=e(n(t.s)),o=e(n(t.r)),i=r.length/2,s=o.length/2,c=n(i),l=n(s);return`30${n(s+i+4)}02${l}${o}02${c}${r}`}},mt=BigInt(0),lt=BigInt(1);BigInt(2);const pr=BigInt(3);BigInt(4);function Oi(t){const e=Si(t),{Fp:n}=e,r=e.toBytes||((g,d,p)=>{const b=d.toAffine();return Dt(Uint8Array.from([4]),n.toBytes(b.x),n.toBytes(b.y))}),o=e.fromBytes||(g=>{const d=g.subarray(1),p=n.fromBytes(d.subarray(0,n.BYTES)),b=n.fromBytes(d.subarray(n.BYTES,2*n.BYTES));return{x:p,y:b}});function i(g){const{a:d,b:p}=e,b=n.sqr(g),v=n.mul(b,g);return n.add(n.add(v,n.mul(g,d)),p)}if(!n.eql(n.sqr(e.Gy),i(e.Gx)))throw new Error("bad generator point: equation left != right");function s(g){return typeof g=="bigint"&&mt<g&&g<e.n}function c(g){if(!s(g))throw new Error("Expected valid bigint: 0 < bigint < curve.n")}function l(g){const{allowedPrivateKeyLengths:d,nByteLength:p,wrapPrivateKey:b,n:v}=e;if(d&&typeof g!="bigint"){if(g instanceof Uint8Array&&(g=te(g)),typeof g!="string"||!d.includes(g.length))throw new Error("Invalid key");g=g.padStart(p*2,"0")}let B;try{B=typeof g=="bigint"?g:rt(Q("private key",g,p))}catch{throw new Error(`private key must be ${p} bytes, hex or bigint, not ${typeof g}`)}return b&&(B=J(B,v)),c(B),B}const a=new Map;function f(g){if(!(g instanceof u))throw new Error("ProjectivePoint expected")}class u{constructor(d,p,b){if(this.px=d,this.py=p,this.pz=b,d==null||!n.isValid(d))throw new Error("x required");if(p==null||!n.isValid(p))throw new Error("y required");if(b==null||!n.isValid(b))throw new Error("z required")}static fromAffine(d){const{x:p,y:b}=d||{};if(!d||!n.isValid(p)||!n.isValid(b))throw new Error("invalid affine point");if(d instanceof u)throw new Error("projective point not allowed");const v=B=>n.eql(B,n.ZERO);return v(p)&&v(b)?u.ZERO:new u(p,b,n.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(d){const p=n.invertBatch(d.map(b=>b.pz));return d.map((b,v)=>b.toAffine(p[v])).map(u.fromAffine)}static fromHex(d){const p=u.fromAffine(o(Q("pointHex",d)));return p.assertValidity(),p}static fromPrivateKey(d){return u.BASE.multiply(l(d))}_setWindowSize(d){this._WINDOW_SIZE=d,a.delete(this)}assertValidity(){if(this.is0()){if(e.allowInfinityPoint&&!n.is0(this.py))return;throw new Error("bad point: ZERO")}const{x:d,y:p}=this.toAffine();if(!n.isValid(d)||!n.isValid(p))throw new Error("bad point: x or y not FE");const b=n.sqr(p),v=i(d);if(!n.eql(b,v))throw new Error("bad point: equation left != right");if(!this.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){const{y:d}=this.toAffine();if(n.isOdd)return!n.isOdd(d);throw new Error("Field doesn't support isOdd")}equals(d){f(d);const{px:p,py:b,pz:v}=this,{px:B,py:I,pz:N}=d,x=n.eql(n.mul(p,N),n.mul(B,v)),m=n.eql(n.mul(b,N),n.mul(I,v));return x&&m}negate(){return new u(this.px,n.neg(this.py),this.pz)}double(){const{a:d,b:p}=e,b=n.mul(p,pr),{px:v,py:B,pz:I}=this;let N=n.ZERO,x=n.ZERO,m=n.ZERO,y=n.mul(v,v),T=n.mul(B,B),P=n.mul(I,I),A=n.mul(v,B);return A=n.add(A,A),m=n.mul(v,I),m=n.add(m,m),N=n.mul(d,m),x=n.mul(b,P),x=n.add(N,x),N=n.sub(T,x),x=n.add(T,x),x=n.mul(N,x),N=n.mul(A,N),m=n.mul(b,m),P=n.mul(d,P),A=n.sub(y,P),A=n.mul(d,A),A=n.add(A,m),m=n.add(y,y),y=n.add(m,y),y=n.add(y,P),y=n.mul(y,A),x=n.add(x,y),P=n.mul(B,I),P=n.add(P,P),y=n.mul(P,A),N=n.sub(N,y),m=n.mul(P,T),m=n.add(m,m),m=n.add(m,m),new u(N,x,m)}add(d){f(d);const{px:p,py:b,pz:v}=this,{px:B,py:I,pz:N}=d;let x=n.ZERO,m=n.ZERO,y=n.ZERO;const T=e.a,P=n.mul(e.b,pr);let A=n.mul(p,B),H=n.mul(b,I),R=n.mul(v,N),Y=n.add(p,b),_=n.add(B,I);Y=n.mul(Y,_),_=n.add(A,H),Y=n.sub(Y,_),_=n.add(p,v);let S=n.add(B,N);return _=n.mul(_,S),S=n.add(A,R),_=n.sub(_,S),S=n.add(b,v),x=n.add(I,N),S=n.mul(S,x),x=n.add(H,R),S=n.sub(S,x),y=n.mul(T,_),x=n.mul(P,R),y=n.add(x,y),x=n.sub(H,y),y=n.add(H,y),m=n.mul(x,y),H=n.add(A,A),H=n.add(H,A),R=n.mul(T,R),_=n.mul(P,_),H=n.add(H,R),R=n.sub(A,R),R=n.mul(T,R),_=n.add(_,R),A=n.mul(H,_),m=n.add(m,A),A=n.mul(S,_),x=n.mul(Y,x),x=n.sub(x,A),A=n.mul(Y,H),y=n.mul(S,y),y=n.add(y,A),new u(x,m,y)}subtract(d){return this.add(d.negate())}is0(){return this.equals(u.ZERO)}wNAF(d){return h.wNAFCached(this,a,d,p=>{const b=n.invertBatch(p.map(v=>v.pz));return p.map((v,B)=>v.toAffine(b[B])).map(u.fromAffine)})}multiplyUnsafe(d){const p=u.ZERO;if(d===mt)return p;if(c(d),d===lt)return this;const{endo:b}=e;if(!b)return h.unsafeLadder(this,d);let{k1neg:v,k1:B,k2neg:I,k2:N}=b.splitScalar(d),x=p,m=p,y=this;for(;B>mt||N>mt;)B&lt&&(x=x.add(y)),N&lt&&(m=m.add(y)),y=y.double(),B>>=lt,N>>=lt;return v&&(x=x.negate()),I&&(m=m.negate()),m=new u(n.mul(m.px,b.beta),m.py,m.pz),x.add(m)}multiply(d){c(d);let p=d,b,v;const{endo:B}=e;if(B){const{k1neg:I,k1:N,k2neg:x,k2:m}=B.splitScalar(p);let{p:y,f:T}=this.wNAF(N),{p:P,f:A}=this.wNAF(m);y=h.constTimeNegate(I,y),P=h.constTimeNegate(x,P),P=new u(n.mul(P.px,B.beta),P.py,P.pz),b=y.add(P),v=T.add(A)}else{const{p:I,f:N}=this.wNAF(p);b=I,v=N}return u.normalizeZ([b,v])[0]}multiplyAndAddUnsafe(d,p,b){const v=u.BASE,B=(N,x)=>x===mt||x===lt||!N.equals(v)?N.multiplyUnsafe(x):N.multiply(x),I=B(this,p).add(B(d,b));return I.is0()?void 0:I}toAffine(d){const{px:p,py:b,pz:v}=this,B=this.is0();d==null&&(d=B?n.ONE:n.inv(v));const I=n.mul(p,d),N=n.mul(b,d),x=n.mul(v,d);if(B)return{x:n.ZERO,y:n.ZERO};if(!n.eql(x,n.ONE))throw new Error("invZ was invalid");return{x:I,y:N}}isTorsionFree(){const{h:d,isTorsionFree:p}=e;if(d===lt)return!0;if(p)return p(u,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){const{h:d,clearCofactor:p}=e;return d===lt?this:p?p(u,this):this.multiplyUnsafe(e.h)}toRawBytes(d=!0){return this.assertValidity(),r(u,this,d)}toHex(d=!0){return te(this.toRawBytes(d))}}u.BASE=new u(e.Gx,e.Gy,n.ONE),u.ZERO=new u(n.ZERO,n.ONE,n.ZERO);const w=e.nBitLength,h=ki(u,e.endo?Math.ceil(w/2):w);return{CURVE:e,ProjectivePoint:u,normPrivateKeyToScalar:l,weierstrassEquation:i,isWithinCurveOrder:s}}function Ii(t){const e=wr(t);return fe(e,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...e})}function Ti(t){const e=Ii(t),{Fp:n,n:r}=e,o=n.BYTES+1,i=2*n.BYTES+1;function s(_){return mt<_&&_<n.ORDER}function c(_){return J(_,r)}function l(_){return an(_,r)}const{ProjectivePoint:a,normPrivateKeyToScalar:f,weierstrassEquation:u,isWithinCurveOrder:w}=Oi({...e,toBytes(_,S,L){const M=S.toAffine(),z=n.toBytes(M.x),D=Dt;return L?D(Uint8Array.from([S.hasEvenY()?2:3]),z):D(Uint8Array.from([4]),z,n.toBytes(M.y))},fromBytes(_){const S=_.length,L=_[0],M=_.subarray(1);if(S===o&&(L===2||L===3)){const z=rt(M);if(!s(z))throw new Error("Point is not on curve");const D=u(z);let G=n.sqrt(D);const X=(G&lt)===lt;return(L&1)===1!==X&&(G=n.neg(G)),{x:z,y:G}}else if(S===i&&L===4){const z=n.fromBytes(M.subarray(0,n.BYTES)),D=n.fromBytes(M.subarray(n.BYTES,2*n.BYTES));return{x:z,y:D}}else throw new Error(`Point of length ${S} was invalid. Expected ${o} compressed bytes or ${i} uncompressed bytes`)}}),h=_=>te(Nt(_,e.nByteLength));function g(_){const S=r>>lt;return _>S}function d(_){return g(_)?c(-_):_}const p=(_,S,L)=>rt(_.slice(S,L));class b{constructor(S,L,M){this.r=S,this.s=L,this.recovery=M,this.assertValidity()}static fromCompact(S){const L=e.nByteLength;return S=Q("compactSignature",S,L*2),new b(p(S,0,L),p(S,L,2*L))}static fromDER(S){const{r:L,s:M}=Wt.toSig(Q("DER",S));return new b(L,M)}assertValidity(){if(!w(this.r))throw new Error("r must be 0 < r < CURVE.n");if(!w(this.s))throw new Error("s must be 0 < s < CURVE.n")}addRecoveryBit(S){return new b(this.r,this.s,S)}recoverPublicKey(S){const{r:L,s:M,recovery:z}=this,D=m(Q("msgHash",S));if(z==null||![0,1,2,3].includes(z))throw new Error("recovery id invalid");const G=z===2||z===3?L+e.n:L;if(G>=n.ORDER)throw new Error("recovery id 2 or 3 invalid");const X=z&1?"03":"02",dt=a.fromHex(X+h(G)),ht=l(G),kt=c(-D*ht),$t=c(M*ht),it=a.BASE.multiplyAndAddUnsafe(dt,kt,$t);if(!it)throw new Error("point at infinify");return it.assertValidity(),it}hasHighS(){return g(this.s)}normalizeS(){return this.hasHighS()?new b(this.r,c(-this.s),this.recovery):this}toDERRawBytes(){return ee(this.toDERHex())}toDERHex(){return Wt.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return ee(this.toCompactHex())}toCompactHex(){return h(this.r)+h(this.s)}}const v={isValidPrivateKey(_){try{return f(_),!0}catch{return!1}},normPrivateKeyToScalar:f,randomPrivateKey:()=>{const _=hr(e.n);return vi(e.randomBytes(_),e.n)},precompute(_=8,S=a.BASE){return S._setWindowSize(_),S.multiply(BigInt(3)),S}};function B(_,S=!0){return a.fromPrivateKey(_).toRawBytes(S)}function I(_){const S=_ instanceof Uint8Array,L=typeof _=="string",M=(S||L)&&_.length;return S?M===o||M===i:L?M===2*o||M===2*i:_ instanceof a}function N(_,S,L=!0){if(I(_))throw new Error("first arg must be private key");if(!I(S))throw new Error("second arg must be public key");return a.fromHex(S).multiply(f(_)).toRawBytes(L)}const x=e.bits2int||function(_){const S=rt(_),L=_.length*8-e.nBitLength;return L>0?S>>BigInt(L):S},m=e.bits2int_modN||function(_){return c(x(_))},y=sn(e.nBitLength);function T(_){if(typeof _!="bigint")throw new Error("bigint expected");if(!(mt<=_&&_<y))throw new Error(`bigint expected < 2^${e.nBitLength}`);return Nt(_,e.nByteLength)}function P(_,S,L=A){if(["recovered","canonical"].some(ut=>ut in L))throw new Error("sign() legacy options not supported");const{hash:M,randomBytes:z}=e;let{lowS:D,prehash:G,extraEntropy:X}=L;D==null&&(D=!0),_=Q("msgHash",_),G&&(_=Q("prehashed msgHash",M(_)));const dt=m(_),ht=f(S),kt=[T(ht),T(dt)];if(X!=null){const ut=X===!0?z(n.BYTES):X;kt.push(Q("extraEntropy",ut))}const $t=Dt(...kt),it=dt;function qt(ut){const St=x(ut);if(!w(St))return;const se=l(St),jt=a.BASE.multiply(St).toAffine(),st=c(jt.x);if(st===mt)return;const Mt=c(se*c(it+st*ht));if(Mt===mt)return;let je=(jt.x===st?0:2)|Number(jt.y&lt),Me=Mt;return D&&g(Mt)&&(Me=d(Mt),je^=1),new b(st,Me,je)}return{seed:$t,k2sig:qt}}const A={lowS:e.lowS,prehash:!1},H={lowS:e.lowS,prehash:!1};function R(_,S,L=A){const{seed:M,k2sig:z}=P(_,S,L),D=e;return lr(D.hash.outputLen,D.nByteLength,D.hmac)(M,z)}a.BASE._setWindowSize(8);function Y(_,S,L,M=H){var jt;const z=_;if(S=Q("msgHash",S),L=Q("publicKey",L),"strict"in M)throw new Error("options.strict was renamed to lowS");const{lowS:D,prehash:G}=M;let X,dt;try{if(typeof z=="string"||z instanceof Uint8Array)try{X=b.fromDER(z)}catch(st){if(!(st instanceof Wt.Err))throw st;X=b.fromCompact(z)}else if(typeof z=="object"&&typeof z.r=="bigint"&&typeof z.s=="bigint"){const{r:st,s:Mt}=z;X=new b(st,Mt)}else throw new Error("PARSE");dt=a.fromHex(L)}catch(st){if(st.message==="PARSE")throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(D&&X.hasHighS())return!1;G&&(S=e.hash(S));const{r:ht,s:kt}=X,$t=m(S),it=l(kt),qt=c($t*it),ut=c(ht*it),St=(jt=a.BASE.multiplyAndAddUnsafe(dt,qt,ut))==null?void 0:jt.toAffine();return St?c(St.x)===ht:!1}return{CURVE:e,getPublicKey:B,getSharedSecret:N,sign:R,verify:Y,ProjectivePoint:a,Signature:b,utils:v}}class gr extends rr{constructor(e,n){super(),this.finished=!1,this.destroyed=!1,Wo(e);const r=tn(n);if(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 o=this.blockLen,i=new Uint8Array(o);i.set(r.length>o?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),i.fill(0)}update(e){return Se(this),this.iHash.update(e),this}digestInto(e){Se(this),er(e,this.outputLen),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||(e=Object.create(Object.getPrototypeOf(this),{}));const{oHash:n,iHash:r,finished:o,destroyed:i,blockLen:s,outputLen:c}=this;return e=e,e.finished=o,e.destroyed=i,e.blockLen=s,e.outputLen=c,e.oHash=n._cloneInto(e.oHash),e.iHash=r._cloneInto(e.iHash),e}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}const br=(t,e,n)=>new gr(t,e).update(n).digest();br.create=(t,e)=>new gr(t,e);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function Ni(t){return{hash:t,hmac:(e,...n)=>br(t,e,Fo(...n)),randomBytes:or}}function Pi(t,e){const n=r=>Ti({...t,...Ni(r)});return Object.freeze({...n(e),create:n})}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Oe=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),Ie=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),yr=BigInt(1),Te=BigInt(2),mr=(t,e)=>(t+e/Te)/e;function Er(t){const e=Oe,n=BigInt(3),r=BigInt(6),o=BigInt(11),i=BigInt(22),s=BigInt(23),c=BigInt(44),l=BigInt(88),a=t*t*t%e,f=a*a*t%e,u=ct(f,n,e)*f%e,w=ct(u,n,e)*f%e,h=ct(w,Te,e)*a%e,g=ct(h,o,e)*h%e,d=ct(g,i,e)*g%e,p=ct(d,c,e)*d%e,b=ct(p,l,e)*p%e,v=ct(b,c,e)*d%e,B=ct(v,n,e)*f%e,I=ct(B,s,e)*g%e,N=ct(I,r,e)*a%e,x=ct(N,Te,e);if(!fn.eql(fn.sqr(x),t))throw new Error("Cannot find square root");return x}const fn=xi(Oe,void 0,void 0,{sqrt:Er}),de=Pi({a:BigInt(0),b:BigInt(7),Fp:fn,n:Ie,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:t=>{const e=Ie,n=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),r=-yr*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),i=n,s=BigInt("0x100000000000000000000000000000000"),c=mr(i*t,e),l=mr(-r*t,e);let a=J(t-c*n-l*o,e),f=J(-c*r-l*i,e);const u=a>s,w=f>s;if(u&&(a=e-a),w&&(f=e-f),a>s||f>s)throw new Error("splitScalar: Endomorphism failed, k="+t);return{k1neg:u,k1:a,k2neg:w,k2:f}}}},en),Ne=BigInt(0),xr=t=>typeof t=="bigint"&&Ne<t&&t<Oe,Ui=t=>typeof t=="bigint"&&Ne<t&&t<Ie,vr={};function Pe(t,...e){let n=vr[t];if(n===void 0){const r=en(Uint8Array.from(t,o=>o.charCodeAt(0)));n=Dt(r,r),vr[t]=n}return en(Dt(n,...e))}const dn=t=>t.toRawBytes(!0).slice(1),hn=t=>Nt(t,32),wn=t=>J(t,Oe),he=t=>J(t,Ie),pn=de.ProjectivePoint,Li=(t,e,n)=>pn.BASE.multiplyAndAddUnsafe(t,e,n);function gn(t){let e=de.utils.normPrivateKeyToScalar(t),n=pn.fromPrivateKey(e);return{scalar:n.hasEvenY()?e:he(-e),bytes:dn(n)}}function _r(t){if(!xr(t))throw new Error("bad x: need 0 < x < p");const e=wn(t*t),n=wn(e*t+BigInt(7));let r=Er(n);r%Te!==Ne&&(r=wn(-r));const o=new pn(t,r,yr);return o.assertValidity(),o}function kr(...t){return he(rt(Pe("BIP0340/challenge",...t)))}function Ci(t){return gn(t).bytes}function Ri(t,e,n=or(32)){const r=Q("message",t),{bytes:o,scalar:i}=gn(e),s=Q("auxRand",n,32),c=hn(i^rt(Pe("BIP0340/aux",s))),l=Pe("BIP0340/nonce",c,o,r),a=he(rt(l));if(a===Ne)throw new Error("sign failed: k is zero");const{bytes:f,scalar:u}=gn(a),w=kr(f,o,r),h=new Uint8Array(64);if(h.set(f,0),h.set(hn(he(u+w*i)),32),!Sr(h,r,o))throw new Error("sign: Invalid signature produced");return h}function Sr(t,e,n){const r=Q("signature",t,64),o=Q("message",e),i=Q("publicKey",n,32);try{const s=_r(rt(i)),c=rt(r.subarray(0,32));if(!xr(c))return!1;const l=rt(r.subarray(32,64));if(!Ui(l))return!1;const a=kr(hn(c),dn(s),o),f=Li(s,l,he(-a));return!(!f||!f.hasEvenY()||f.toAffine().x!==c)}catch{return!1}}const nt={getPublicKey:Ci,sign:Ri,verify:Sr,utils:{randomPrivateKey:de.utils.randomPrivateKey,lift_x:_r,pointToBytes:dn,numberToBytesBE:Nt,bytesToNumberBE:rt,taggedHash:Pe,mod:J}};function bn(t){if(!Number.isSafeInteger(t)||t<0)throw new Error(`Wrong positive integer: ${t}`)}function Hi(t){if(typeof t!="boolean")throw new Error(`Expected boolean, not ${t}`)}function Ar(t,...e){if(!(t instanceof Uint8Array))throw new Error("Expected Uint8Array");if(e.length>0&&!e.includes(t.length))throw new Error(`Expected Uint8Array of length ${e}, not of length=${t.length}`)}function $i(t){if(typeof t!="function"||typeof t.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");bn(t.outputLen),bn(t.blockLen)}function qi(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 ji(t,e){Ar(t);const n=e.outputLen;if(t.length<n)throw new Error(`digestInto() expects output buffer of length at least ${n}`)}const yn={number:bn,bool:Hi,bytes:Ar,hash:$i,exists:qi,output:ji};function Mi(t,e,n,r){if(typeof t.setBigUint64=="function")return t.setBigUint64(e,n,r);const o=BigInt(32),i=BigInt(4294967295),s=Number(n>>o&i),c=Number(n&i),l=r?4:0,a=r?0:4;t.setUint32(e+l,s,r),t.setUint32(e+a,c,r)}class zi extends Do{constructor(e,n,r,o){super(),this.blockLen=e,this.outputLen=n,this.padOffset=r,this.isLE=o,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(e),this.view=Ye(this.buffer)}update(e){yn.exists(this);const{view:n,buffer:r,blockLen:o}=this;e=Qn(e);const i=e.length;for(let s=0;s<i;){const c=Math.min(o-this.pos,i-s);if(c===o){const l=Ye(e);for(;o<=i-s;s+=o)this.process(l,s);continue}r.set(e.subarray(s,s+c),this.pos),this.pos+=c,s+=c,this.pos===o&&(this.process(n,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){yn.exists(this),yn.output(e,this),this.finished=!0;const{buffer:n,view:r,blockLen:o,isLE:i}=this;let{pos:s}=this;n[s++]=128,this.buffer.subarray(s).fill(0),this.padOffset>o-s&&(this.process(r,0),s=0);for(let u=s;u<o;u++)n[u]=0;Mi(r,o-8,BigInt(this.length*8),i),this.process(r,0);const c=Ye(e),l=this.outputLen;if(l%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const a=l/4,f=this.get();if(a>f.length)throw new Error("_sha2: outputLen bigger than state");for(let u=0;u<a;u++)c.setUint32(4*u,f[u],i)}digest(){const{buffer:e,outputLen:n}=this;this.digestInto(e);const r=e.slice(0,n);return this.destroy(),r}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());const{blockLen:n,buffer:r,length:o,finished:i,destroyed:s,pos:c}=this;return e.length=o,e.pos=c,e.finished=i,e.destroyed=s,o%n&&e.buffer.set(r),e}}const Ki=(t,e,n)=>t&e^~t&n,Di=(t,e,n)=>t&e^t&n^e&n,Vi=new Uint32Array([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]),Pt=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Ut=new Uint32Array(64);class Br extends zi{constructor(){super(64,32,8,!1),this.A=Pt[0]|0,this.B=Pt[1]|0,this.C=Pt[2]|0,this.D=Pt[3]|0,this.E=Pt[4]|0,this.F=Pt[5]|0,this.G=Pt[6]|0,this.H=Pt[7]|0}get(){const{A:e,B:n,C:r,D:o,E:i,F:s,G:c,H:l}=this;return[e,n,r,o,i,s,c,l]}set(e,n,r,o,i,s,c,l){this.A=e|0,this.B=n|0,this.C=r|0,this.D=o|0,this.E=i|0,this.F=s|0,this.G=c|0,this.H=l|0}process(e,n){for(let u=0;u<16;u++,n+=4)Ut[u]=e.getUint32(n,!1);for(let u=16;u<64;u++){const w=Ut[u-15],h=Ut[u-2],g=pt(w,7)^pt(w,18)^w>>>3,d=pt(h,17)^pt(h,19)^h>>>10;Ut[u]=d+Ut[u-7]+g+Ut[u-16]|0}let{A:r,B:o,C:i,D:s,E:c,F:l,G:a,H:f}=this;for(let u=0;u<64;u++){const w=pt(c,6)^pt(c,11)^pt(c,25),h=f+w+Ki(c,l,a)+Vi[u]+Ut[u]|0,d=(pt(r,2)^pt(r,13)^pt(r,22))+Di(r,o,i)|0;f=a,a=l,l=c,c=s+h|0,s=i,i=o,o=r,r=h+d|0}r=r+this.A|0,o=o+this.B|0,i=i+this.C|0,s=s+this.D|0,c=c+this.E|0,l=l+this.F|0,a=a+this.G|0,f=f+this.H|0,this.set(r,o,i,s,c,l,a,f)}roundClean(){Ut.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}}class Wi extends Br{constructor(){super(),this.A=-1056596264,this.B=914150663,this.C=812702999,this.D=-150054599,this.E=-4191439,this.F=1750603025,this.G=1694076839,this.H=-1090891868,this.outputLen=28}}const mn=Xn(()=>new Br);Xn(()=>new Wi);var ne=Symbol("verified"),Zi=t=>t instanceof Object;function Gi(t){if(!Zi(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 n=t.tags[e];if(!Array.isArray(n))return!1;for(let r=0;r<n.length;r++)if(typeof n[r]=="object")return!1}return!0}new TextDecoder("utf-8");var Fi=new TextEncoder,Yi=class{generateSecretKey(){return nt.utils.randomPrivateKey()}getPublicKey(e){return et(nt.getPublicKey(e))}finalizeEvent(e,n){const r=e;return r.pubkey=et(nt.getPublicKey(n)),r.id=En(r),r.sig=et(nt.sign(En(r),n)),r[ne]=!0,r}verifyEvent(e){if(typeof e[ne]=="boolean")return e[ne];const n=En(e);if(n!==e.id)return e[ne]=!1,!1;try{const r=nt.verify(e.sig,n,e.pubkey);return e[ne]=r,r}catch{return e[ne]=!1,!1}}};function Ji(t){if(!Gi(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 En(t){let e=mn(Fi.encode(Ji(t)));return et(e)}var Ue=new Yi,Qi=Ue.generateSecretKey,Or=Ue.getPublicKey;Ue.finalizeEvent,Ue.verifyEvent;var Zt=Symbol("verified"),Xi=t=>t instanceof Object;function ts(t){if(!Xi(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 n=t.tags[e];if(!Array.isArray(n))return!1;for(let r=0;r<n.length;r++)if(typeof n[r]=="object")return!1}return!0}new TextDecoder("utf-8");var es=new TextEncoder;function we(t){t.indexOf("://")===-1&&(t="wss://"+t);let e=new URL(t);return 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()}var ns=class{constructor(e){E(this,"value");E(this,"next",null);E(this,"prev",null);this.value=e}},rs=class{constructor(){E(this,"first");E(this,"last");this.first=null,this.last=null}enqueue(e){const n=new ns(e);return this.last?this.last===this.first?(this.last=n,this.last.prev=this.first,this.first.next=n):(n.prev=this.last,this.last.next=n,this.last=n):(this.first=n,this.last=n),!0}dequeue(){if(!this.first)return null;if(this.first===this.last){const n=this.first;return this.first=null,this.last=null,n.value}const e=this.first;return this.first=e.next,e.value}},os=class{generateSecretKey(){return nt.utils.randomPrivateKey()}getPublicKey(e){return et(nt.getPublicKey(e))}finalizeEvent(e,n){const r=e;return r.pubkey=et(nt.getPublicKey(n)),r.id=xn(r),r.sig=et(nt.sign(xn(r),n)),r[Zt]=!0,r}verifyEvent(e){if(typeof e[Zt]=="boolean")return e[Zt];const n=xn(e);if(n!==e.id)return e[Zt]=!1,!1;try{const r=nt.verify(e.sig,n,e.pubkey);return e[Zt]=r,r}catch{return e[Zt]=!1,!1}}};function is(t){if(!ts(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 xn(t){let e=mn(es.encode(is(t)));return et(e)}var Le=new os;Le.generateSecretKey,Le.getPublicKey,Le.finalizeEvent;var ss=Le.verifyEvent,cs=22242;function ls(t,e){if(t.ids&&t.ids.indexOf(e.id)===-1&&!t.ids.some(n=>e.id.startsWith(n))||t.kinds&&t.kinds.indexOf(e.kind)===-1||t.authors&&t.authors.indexOf(e.pubkey)===-1&&!t.authors.some(n=>e.pubkey.startsWith(n)))return!1;for(let n in t)if(n[0]==="#"){let r=n.slice(1),o=t[`#${r}`];if(o&&!e.tags.find(([i,s])=>i===n.slice(1)&&o.indexOf(s)!==-1))return!1}return!(t.since&&e.created_at<t.since||t.until&&e.created_at>t.until)}function as(t,e){for(let n=0;n<t.length;n++)if(ls(t[n],e))return!0;return!1}function us(t,e){let n=e.length+3,r=t.indexOf(`"${e}":`)+n,o=t.slice(r).indexOf('"')+r+1;return t.slice(o,o+64)}function fs(t){let e=t.slice(0,22).indexOf('"EVENT"');if(e===-1)return null;let n=t.slice(e+7+1).indexOf('"');if(n===-1)return null;let r=e+7+1+n,o=t.slice(r+1,80).indexOf('"');if(o===-1)return null;let i=r+1+o;return t.slice(r+1,i)}function ds(t,e){return{kind:cs,created_at:Math.floor(Date.now()/1e3),tags:[["relay",t],["challenge",e]],content:""}}async function hs(){return new Promise(t=>{const e=new MessageChannel,n=()=>{e.port1.removeEventListener("message",n),t()};e.port1.addEventListener("message",n),e.port2.postMessage(0),e.port1.start()})}var ws=t=>(t[Zt]=!0,!0),Ir;try{Ir=WebSocket}catch{}var Tr=class{constructor(e,n){E(this,"url");E(this,"_connected",!1);E(this,"onclose",null);E(this,"onnotice",e=>console.debug(`NOTICE from ${this.url}: ${e}`));E(this,"baseEoseTimeout",4400);E(this,"connectionTimeout",4400);E(this,"openSubs",new Map);E(this,"connectionTimeoutHandle");E(this,"connectionPromise");E(this,"openCountRequests",new Map);E(this,"openEventPublishes",new Map);E(this,"ws");E(this,"incomingMessageQueue",new rs);E(this,"queueRunning",!1);E(this,"challenge");E(this,"serial",0);E(this,"verifyEvent");this.url=we(e),this.verifyEvent=n.verifyEvent}static async connect(e,n){const r=new Tr(e,n);return await r.connect(),r}closeAllSubscriptions(e){for(let[n,r]of this.openSubs)r.close(e);this.openSubs.clear();for(let[n,r]of this.openEventPublishes)r.reject(new Error(e));this.openEventPublishes.clear();for(let[n,r]of this.openCountRequests)r.reject(new Error(e));this.openCountRequests.clear()}get connected(){return this._connected}async connect(){return this.connectionPromise?this.connectionPromise:(this.challenge=void 0,this.connectionPromise=new Promise((e,n)=>{this.connectionTimeoutHandle=setTimeout(()=>{var r;n("connection timed out"),this.connectionPromise=void 0,(r=this.onclose)==null||r.call(this),this.closeAllSubscriptions("relay connection timed out")},this.connectionTimeout);try{this.ws=new Ir(this.url)}catch(r){n(r);return}this.ws.onopen=()=>{clearTimeout(this.connectionTimeoutHandle),this._connected=!0,e()},this.ws.onerror=r=>{var o;n(r.message),this._connected&&((o=this.onclose)==null||o.call(this),this.closeAllSubscriptions("relay connection errored"),this._connected=!1)},this.ws.onclose=async()=>{var r;this.connectionPromise=void 0,(r=this.onclose)==null||r.call(this),this.closeAllSubscriptions("relay connection closed"),this._connected=!1},this.ws.onmessage=this._onmessage.bind(this)}),this.connectionPromise)}async runQueue(){for(this.queueRunning=!0;this.handleNext()!==!1;)await hs();this.queueRunning=!1}handleNext(){var r,o;const e=this.incomingMessageQueue.dequeue();if(!e)return!1;const n=fs(e);if(n){const i=this.openSubs.get(n);if(!i)return;const s=us(e,"id"),c=(r=i.alreadyHaveEvent)==null?void 0:r.call(i,s);if((o=i.receivedEvent)==null||o.call(i,this,s),c)return}try{let i=JSON.parse(e);switch(i[0]){case"EVENT":{const s=this.openSubs.get(i[1]),c=i[2];this.verifyEvent(c)&&as(s.filters,c)&&s.onevent(c);return}case"COUNT":{const s=i[1],c=i[2],l=this.openCountRequests.get(s);l&&(l.resolve(c.count),this.openCountRequests.delete(s));return}case"EOSE":{const s=this.openSubs.get(i[1]);if(!s)return;s.receivedEose();return}case"OK":{const s=i[1],c=i[2],l=i[3],a=this.openEventPublishes.get(s);c?a.resolve(l):a.reject(new Error(l)),this.openEventPublishes.delete(s);return}case"CLOSED":{const s=i[1],c=this.openSubs.get(s);if(!c)return;c.closed=!0,c.close(i[2]);return}case"NOTICE":this.onnotice(i[1]);return;case"AUTH":{this.challenge=i[1];return}}}catch{return}}async send(e){if(!this.connectionPromise)throw new Error("sending on closed connection");this.connectionPromise.then(()=>{var n;(n=this.ws)==null||n.send(e)})}async auth(e){if(!this.challenge)throw new Error("can't perform auth, no challenge was received");const n=await e(ds(this.url,this.challenge)),r=new Promise((o,i)=>{this.openEventPublishes.set(n.id,{resolve:o,reject:i})});return this.send('["AUTH",'+JSON.stringify(n)+"]"),r}async publish(e){const n=new Promise((r,o)=>{this.openEventPublishes.set(e.id,{resolve:r,reject:o})});return this.send('["EVENT",'+JSON.stringify(e)+"]"),n}async count(e,n){this.serial++;const r=(n==null?void 0:n.id)||"count:"+this.serial,o=new Promise((i,s)=>{this.openCountRequests.set(r,{resolve:i,reject:s})});return this.send('["COUNT","'+r+'",'+JSON.stringify(e)+"]"),o}subscribe(e,n){const r=this.prepareSubscription(e,n);return r.fire(),r}prepareSubscription(e,n){this.serial++;const r=n.id||"sub:"+this.serial,o=new ps(this,r,e,n);return this.openSubs.set(r,o),o}close(){var e;this.closeAllSubscriptions("relay connection closed by us"),this._connected=!1,(e=this.ws)==null||e.close()}_onmessage(e){this.incomingMessageQueue.enqueue(e.data),this.queueRunning||this.runQueue()}},ps=class{constructor(e,n,r,o){E(this,"relay");E(this,"id");E(this,"closed",!1);E(this,"eosed",!1);E(this,"filters");E(this,"alreadyHaveEvent");E(this,"receivedEvent");E(this,"onevent");E(this,"oneose");E(this,"onclose");E(this,"eoseTimeout");E(this,"eoseTimeoutHandle");this.relay=e,this.filters=r,this.id=n,this.alreadyHaveEvent=o.alreadyHaveEvent,this.receivedEvent=o.receivedEvent,this.eoseTimeout=o.eoseTimeout||e.baseEoseTimeout,this.oneose=o.oneose,this.onclose=o.onclose,this.onevent=o.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(){var e;this.eosed||(clearTimeout(this.eoseTimeoutHandle),this.eosed=!0,(e=this.oneose)==null||e.call(this))}close(e="closed by caller"){var n;this.closed||(this.relay.send('["CLOSE",'+JSON.stringify(this.id)+"]"),this.closed=!0),this.relay.openSubs.delete(this.id),(n=this.onclose)==null||n.call(this,e)}},gs=class{constructor(e){E(this,"relays",new Map);E(this,"seenOn",new Map);E(this,"trackRelays",!1);E(this,"verifyEvent");E(this,"trustedRelayURLs",new Set);this.verifyEvent=e.verifyEvent}async ensureRelay(e,n){e=we(e);let r=this.relays.get(e);return r||(r=new Tr(e,{verifyEvent:this.trustedRelayURLs.has(e)?ws:this.verifyEvent}),n!=null&&n.connectionTimeout&&(r.connectionTimeout=n.connectionTimeout),this.relays.set(e,r)),await r.connect(),r}close(e){e.map(we).forEach(n=>{var r;(r=this.relays.get(n))==null||r.close()})}subscribeMany(e,n,r){this.trackRelays&&(r.receivedEvent=(w,h)=>{let g=this.seenOn.get(h);g||(g=new Set,this.seenOn.set(h,g)),g.add(w)});const o=new Set,i=[],s=[];let c=w=>{var h;s[w]=!0,s.filter(g=>g).length===e.length&&((h=r.oneose)==null||h.call(r),c=()=>{})};const l=[];let a=(w,h)=>{var g;c(w),l[w]=h,l.filter(d=>d).length===e.length&&((g=r.onclose)==null||g.call(r,l),a=()=>{})};const f=w=>{var g;if((g=r.alreadyHaveEvent)!=null&&g.call(r,w))return!0;const h=o.has(w);return o.add(w),h},u=Promise.all(e.map(we).map(async(w,h,g)=>{if(g.indexOf(w)!==h){a(h,"duplicate url");return}let d;try{d=await this.ensureRelay(w,{connectionTimeout:r.maxWait?Math.max(r.maxWait*.8,r.maxWait-1e3):void 0})}catch(b){a(h,(b==null?void 0:b.message)||String(b));return}let p=d.subscribe(n,{...r,oneose:()=>c(h),onclose:b=>a(h,b),alreadyHaveEvent:f,eoseTimeout:r.maxWait});i.push(p)}));return{async close(){await u,i.forEach(w=>{w.close()})}}}subscribeManyEose(e,n,r){const o=this.subscribeMany(e,n,{...r,oneose(){o.close()}});return o}async querySync(e,n,r){return new Promise(async o=>{const i=[];this.subscribeManyEose(e,[n],{...r,onevent(s){i.push(s)},onclose(s){o(i)}})})}async get(e,n,r){n.limit=1;const o=await this.querySync(e,n,r);return o.sort((i,s)=>s.created_at-i.created_at),o[0]||null}publish(e,n){return e.map(we).map(async(r,o,i)=>i.indexOf(r)!==o?Promise.reject("duplicate url"):(await this.ensureRelay(r)).publish(n))}},bs=class extends gs{constructor(){super({verifyEvent:ss})}};function Nr(t){return t instanceof Uint8Array||t!=null&&typeof t=="object"&&t.constructor.name==="Uint8Array"}function Gt(t,...e){if(!Nr(t))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(t.length))throw new Error(`Uint8Array expected of length ${e}, not of length=${t.length}`)}function Ce(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 Pr(t,e){Gt(t);const n=e.outputLen;if(t.length<n)throw new Error(`digestInto() expects output buffer of length at least ${n}`)}/*! noble-ciphers - MIT License (c) 2023 Paul Miller (paulmillr.com) */const ot=t=>new Uint32Array(t.buffer,t.byteOffset,Math.floor(t.byteLength/4)),ys=t=>new DataView(t.buffer,t.byteOffset,t.byteLength);if(!(new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68))throw new Error("Non little-endian hardware is not supported");function ms(t){if(typeof t!="string")throw new Error(`string expected, got ${typeof t}`);return new Uint8Array(new TextEncoder().encode(t))}function pe(t){if(typeof t=="string")t=ms(t);else if(Nr(t))t=t.slice();else throw new Error(`Uint8Array expected, got ${typeof t}`);return t}const Es=(t,e)=>(Object.assign(e,t),e),Et=16,vn=new Uint8Array(16),bt=ot(vn),xs=225,vs=(t,e,n,r)=>{const o=r&1;return{s3:n<<31|r>>>1,s2:e<<31|n>>>1,s1:t<<31|e>>>1,s0:t>>>1^xs<<24&-(o&1)}},at=t=>(t>>>0&255)<<24|(t>>>8&255)<<16|(t>>>16&255)<<8|t>>>24&255|0;function _s(t){t.reverse();const e=t[15]&1;let n=0;for(let r=0;r<t.length;r++){const o=t[r];t[r]=o>>>1|n,n=(o&1)<<7}return t[0]^=-e&225,t}const ks=t=>t>64*1024?8:t>1024?4:2;class Ur{constructor(e,n){this.blockLen=Et,this.outputLen=Et,this.s0=0,this.s1=0,this.s2=0,this.s3=0,this.finished=!1,e=pe(e),Gt(e,16);const r=ys(e);let o=r.getUint32(0,!1),i=r.getUint32(4,!1),s=r.getUint32(8,!1),c=r.getUint32(12,!1);const l=[];for(let g=0;g<128;g++)l.push({s0:at(o),s1:at(i),s2:at(s),s3:at(c)}),{s0:o,s1:i,s2:s,s3:c}=vs(o,i,s,c);const a=ks(n||1024);if(![1,2,4,8].includes(a))throw new Error(`ghash: wrong window size=${a}, should be 2, 4 or 8`);this.W=a;const u=128/a,w=this.windowSize=2**a,h=[];for(let g=0;g<u;g++)for(let d=0;d<w;d++){let p=0,b=0,v=0,B=0;for(let I=0;I<a;I++){if(!(d>>>a-I-1&1))continue;const{s0:x,s1:m,s2:y,s3:T}=l[a*g+I];p^=x,b^=m,v^=y,B^=T}h.push({s0:p,s1:b,s2:v,s3:B})}this.t=h}_updateBlock(e,n,r,o){e^=this.s0,n^=this.s1,r^=this.s2,o^=this.s3;const{W:i,t:s,windowSize:c}=this;let l=0,a=0,f=0,u=0;const w=(1<<i)-1;let h=0;for(const g of[e,n,r,o])for(let d=0;d<4;d++){const p=g>>>8*d&255;for(let b=8/i-1;b>=0;b--){const v=p>>>i*b&w,{s0:B,s1:I,s2:N,s3:x}=s[h*c+v];l^=B,a^=I,f^=N,u^=x,h+=1}}this.s0=l,this.s1=a,this.s2=f,this.s3=u}update(e){e=pe(e),Ce(this);const n=ot(e),r=Math.floor(e.length/Et),o=e.length%Et;for(let i=0;i<r;i++)this._updateBlock(n[i*4+0],n[i*4+1],n[i*4+2],n[i*4+3]);return o&&(vn.set(e.subarray(r*Et)),this._updateBlock(bt[0],bt[1],bt[2],bt[3]),bt.fill(0)),this}destroy(){const{t:e}=this;for(const n of e)n.s0=0,n.s1=0,n.s2=0,n.s3=0}digestInto(e){Ce(this),Pr(e,this),this.finished=!0;const{s0:n,s1:r,s2:o,s3:i}=this,s=ot(e);return s[0]=n,s[1]=r,s[2]=o,s[3]=i,e}digest(){const e=new Uint8Array(Et);return this.digestInto(e),this.destroy(),e}}class Ss extends Ur{constructor(e,n){e=pe(e);const r=_s(e.slice());super(r,n),r.fill(0)}update(e){e=pe(e),Ce(this);const n=ot(e),r=e.length%Et,o=Math.floor(e.length/Et);for(let i=0;i<o;i++)this._updateBlock(at(n[i*4+3]),at(n[i*4+2]),at(n[i*4+1]),at(n[i*4+0]));return r&&(vn.set(e.subarray(o*Et)),this._updateBlock(at(bt[3]),at(bt[2]),at(bt[1]),at(bt[0])),bt.fill(0)),this}digestInto(e){Ce(this),Pr(e,this),this.finished=!0;const{s0:n,s1:r,s2:o,s3:i}=this,s=ot(e);return s[0]=n,s[1]=r,s[2]=o,s[3]=i,e.reverse()}}function Lr(t){const e=(r,o)=>t(o,r.length).update(pe(r)).digest(),n=t(new Uint8Array(16),0);return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=(r,o)=>t(r,o),e}Lr((t,e)=>new Ur(t,e)),Lr((t,e)=>new Ss(t,e));const Lt=16,As=283;function _n(t){return t<<1^As&-(t>>7)}function re(t,e){let n=0;for(;e>0;e>>=1)n^=t&-(e&1),t=_n(t);return n}const kn=(()=>{let t=new Uint8Array(256);for(let n=0,r=1;n<256;n++,r^=_n(r))t[n]=r;const e=new Uint8Array(256);e[0]=99;for(let n=0;n<255;n++){let r=t[255-n];r|=r<<8,e[t[n]]=(r^r>>4^r>>5^r>>6^r>>7^99)&255}return e})(),Bs=kn.map((t,e)=>kn.indexOf(e)),Os=t=>t<<24|t>>>8,Sn=t=>t<<8|t>>>24;function Cr(t,e){if(t.length!==256)throw new Error("Wrong sbox length");const n=new Uint32Array(256).map((a,f)=>e(t[f])),r=n.map(Sn),o=r.map(Sn),i=o.map(Sn),s=new Uint32Array(256*256),c=new Uint32Array(256*256),l=new Uint16Array(256*256);for(let a=0;a<256;a++)for(let f=0;f<256;f++){const u=a*256+f;s[u]=n[a]^r[f],c[u]=o[a]^i[f],l[u]=t[a]<<8|t[f]}return{sbox:t,sbox2:l,T0:n,T1:r,T2:o,T3:i,T01:s,T23:c}}const An=Cr(kn,t=>re(t,3)<<24|t<<16|t<<8|re(t,2)),Rr=Cr(Bs,t=>re(t,11)<<24|re(t,13)<<16|re(t,9)<<8|re(t,14)),Is=(()=>{const t=new Uint8Array(16);for(let e=0,n=1;e<16;e++,n=_n(n))t[e]=n;return t})();function Hr(t){Gt(t);const e=t.length;if(![16,24,32].includes(e))throw new Error(`aes: wrong key size: should be 16, 24 or 32, got: ${e}`);const{sbox2:n}=An,r=ot(t),o=r.length,i=c=>yt(n,c,c,c,c),s=new Uint32Array(e+28);s.set(r);for(let c=o;c<s.length;c++){let l=s[c-1];c%o===0?l=i(Os(l))^Is[c/o-1]:o>6&&c%o===4&&(l=i(l)),s[c]=s[c-o]^l}return s}function Ts(t){const e=Hr(t),n=e.slice(),r=e.length,{sbox2:o}=An,{T0:i,T1:s,T2:c,T3:l}=Rr;for(let a=0;a<r;a+=4)for(let f=0;f<4;f++)n[a+f]=e[r-a-4+f];e.fill(0);for(let a=4;a<r-4;a++){const f=n[a],u=yt(o,f,f,f,f);n[a]=i[u&255]^s[u>>>8&255]^c[u>>>16&255]^l[u>>>24]}return n}function Ct(t,e,n,r,o,i){return t[n<<8&65280|r>>>8&255]^e[o>>>8&65280|i>>>24&255]}function yt(t,e,n,r,o){return t[e&255|n&65280]|t[r>>>16&255|o>>>16&65280]<<16}function $r(t,e,n,r,o){const{sbox2:i,T01:s,T23:c}=An;let l=0;e^=t[l++],n^=t[l++],r^=t[l++],o^=t[l++];const a=t.length/4-2;for(let g=0;g<a;g++){const d=t[l++]^Ct(s,c,e,n,r,o),p=t[l++]^Ct(s,c,n,r,o,e),b=t[l++]^Ct(s,c,r,o,e,n),v=t[l++]^Ct(s,c,o,e,n,r);e=d,n=p,r=b,o=v}const f=t[l++]^yt(i,e,n,r,o),u=t[l++]^yt(i,n,r,o,e),w=t[l++]^yt(i,r,o,e,n),h=t[l++]^yt(i,o,e,n,r);return{s0:f,s1:u,s2:w,s3:h}}function Ns(t,e,n,r,o){const{sbox2:i,T01:s,T23:c}=Rr;let l=0;e^=t[l++],n^=t[l++],r^=t[l++],o^=t[l++];const a=t.length/4-2;for(let g=0;g<a;g++){const d=t[l++]^Ct(s,c,e,o,r,n),p=t[l++]^Ct(s,c,n,e,o,r),b=t[l++]^Ct(s,c,r,n,e,o),v=t[l++]^Ct(s,c,o,r,n,e);e=d,n=p,r=b,o=v}const f=t[l++]^yt(i,e,o,r,n),u=t[l++]^yt(i,n,e,o,r),w=t[l++]^yt(i,r,n,e,o),h=t[l++]^yt(i,o,r,n,e);return{s0:f,s1:u,s2:w,s3:h}}function qr(t,e){if(!e)return new Uint8Array(t);if(Gt(e),e.length<t)throw new Error(`aes: wrong destination length, expected at least ${t}, got: ${e.length}`);return e}function Ps(t){if(Gt(t),t.length%Lt!==0)throw new Error(`aes/(cbc-ecb).decrypt ciphertext should consist of blocks with size ${Lt}`)}function Us(t,e,n){let r=t.length;const o=r%Lt;if(!e&&o!==0)throw new Error("aec/(cbc-ecb): unpadded plaintext with disabled padding");const i=ot(t);if(e){let l=Lt-o;l||(l=Lt),r=r+l}const s=qr(r,n),c=ot(s);return{b:i,o:c,out:s}}function Ls(t,e){if(!e)return t;const n=t.length;if(!n)throw new Error("aes/pcks5: empty ciphertext not allowed");const r=t[n-1];if(r<=0||r>16)throw new Error(`aes/pcks5: wrong padding byte: ${r}`);const o=t.subarray(0,-r);for(let i=0;i<r;i++)if(t[n-i-1]!==r)throw new Error("aes/pcks5: wrong padding");return o}function Cs(t){const e=new Uint8Array(16),n=ot(e);e.set(t);const r=Lt-t.length;for(let o=Lt-r;o<Lt;o++)e[o]=r;return n}const jr=Es({blockSize:16,nonceLength:16},function(e,n,r={}){Gt(e),Gt(n,16);const o=!r.disablePadding;return{encrypt:(i,s)=>{const c=Hr(e),{b:l,o:a,out:f}=Us(i,o,s),u=ot(n);let w=u[0],h=u[1],g=u[2],d=u[3],p=0;for(;p+4<=l.length;)w^=l[p+0],h^=l[p+1],g^=l[p+2],d^=l[p+3],{s0:w,s1:h,s2:g,s3:d}=$r(c,w,h,g,d),a[p++]=w,a[p++]=h,a[p++]=g,a[p++]=d;if(o){const b=Cs(i.subarray(p*4));w^=b[0],h^=b[1],g^=b[2],d^=b[3],{s0:w,s1:h,s2:g,s3:d}=$r(c,w,h,g,d),a[p++]=w,a[p++]=h,a[p++]=g,a[p++]=d}return c.fill(0),f},decrypt:(i,s)=>{Ps(i);const c=Ts(e),l=ot(n),a=qr(i.length,s),f=ot(i),u=ot(a);let w=l[0],h=l[1],g=l[2],d=l[3];for(let p=0;p+4<=f.length;){const b=w,v=h,B=g,I=d;w=f[p+0],h=f[p+1],g=f[p+2],d=f[p+3];const{s0:N,s1:x,s2:m,s3:y}=Ns(c,w,h,g,d);u[p++]=N^b,u[p++]=x^v,u[p++]=m^B,u[p++]=y^I}return c.fill(0),Ls(a,o)}}});/*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) */function oe(t){if(!Number.isSafeInteger(t))throw new Error(`Wrong integer: ${t}`)}function xt(...t){const e=(o,i)=>s=>o(i(s)),n=Array.from(t).reverse().reduce((o,i)=>o?e(o,i.encode):i.encode,void 0),r=t.reduce((o,i)=>o?e(o,i.decode):i.decode,void 0);return{encode:n,decode:r}}function vt(t){return{encode:e=>{if(!Array.isArray(e)||e.length&&typeof e[0]!="number")throw new Error("alphabet.encode input should be an array of numbers");return e.map(n=>{if(oe(n),n<0||n>=t.length)throw new Error(`Digit index outside alphabet: ${n} (alphabet: ${t.length})`);return t[n]})},decode:e=>{if(!Array.isArray(e)||e.length&&typeof e[0]!="string")throw new Error("alphabet.decode input should be array of strings");return e.map(n=>{if(typeof n!="string")throw new Error(`alphabet.decode: not string element=${n}`);const r=t.indexOf(n);if(r===-1)throw new Error(`Unknown letter: "${n}". Allowed: ${t}`);return r})}}}function _t(t=""){if(typeof t!="string")throw new Error("join separator should be string");return{encode:e=>{if(!Array.isArray(e)||e.length&&typeof e[0]!="string")throw new Error("join.encode input should be array of strings");for(let n of e)if(typeof n!="string")throw new Error(`join.encode: non-string input=${n}`);return e.join(t)},decode:e=>{if(typeof e!="string")throw new Error("join.decode input should be string");return e.split(t)}}}function Re(t,e="="){if(oe(t),typeof e!="string")throw new Error("padding chr should be string");return{encode(n){if(!Array.isArray(n)||n.length&&typeof n[0]!="string")throw new Error("padding.encode input should be array of strings");for(let r of n)if(typeof r!="string")throw new Error(`padding.encode: non-string input=${r}`);for(;n.length*t%8;)n.push(e);return n},decode(n){if(!Array.isArray(n)||n.length&&typeof n[0]!="string")throw new Error("padding.encode input should be array of strings");for(let o of n)if(typeof o!="string")throw new Error(`padding.decode: non-string input=${o}`);let r=n.length;if(r*t%8)throw new Error("Invalid padding: string should have whole number of bytes");for(;r>0&&n[r-1]===e;r--)if(!((r-1)*t%8))throw new Error("Invalid padding: string has too much padding");return n.slice(0,r)}}}function Mr(t){if(typeof t!="function")throw new Error("normalize fn should be function");return{encode:e=>e,decode:e=>t(e)}}function zr(t,e,n){if(e<2)throw new Error(`convertRadix: wrong from=${e}, base cannot be less than 2`);if(n<2)throw new Error(`convertRadix: wrong to=${n}, base cannot be less than 2`);if(!Array.isArray(t))throw new Error("convertRadix: data should be array");if(!t.length)return[];let r=0;const o=[],i=Array.from(t);for(i.forEach(s=>{if(oe(s),s<0||s>=e)throw new Error(`Wrong integer: ${s}`)});;){let s=0,c=!0;for(let l=r;l<i.length;l++){const a=i[l],f=e*s+a;if(!Number.isSafeInteger(f)||e*s/e!==s||f-a!==e*s)throw new Error("convertRadix: carry overflow");if(s=f%n,i[l]=Math.floor(f/n),!Number.isSafeInteger(i[l])||i[l]*n+s!==f)throw new Error("convertRadix: carry overflow");if(c)i[l]?c=!1:r=l;else continue}if(o.push(s),c)break}for(let s=0;s<t.length-1&&t[s]===0;s++)o.push(0);return o.reverse()}const Kr=(t,e)=>e?Kr(e,t%e):t,He=(t,e)=>t+(e-Kr(t,e));function Bn(t,e,n,r){if(!Array.isArray(t))throw new Error("convertRadix2: data should be array");if(e<=0||e>32)throw new Error(`convertRadix2: wrong from=${e}`);if(n<=0||n>32)throw new Error(`convertRadix2: wrong to=${n}`);if(He(e,n)>32)throw new Error(`convertRadix2: carry overflow from=${e} to=${n} carryBits=${He(e,n)}`);let o=0,i=0;const s=2**n-1,c=[];for(const l of t){if(oe(l),l>=2**e)throw new Error(`convertRadix2: invalid data word=${l} from=${e}`);if(o=o<<e|l,i+e>32)throw new Error(`convertRadix2: carry overflow pos=${i} from=${e}`);for(i+=e;i>=n;i-=n)c.push((o>>i-n&s)>>>0);o&=2**i-1}if(o=o<<n-i&s,!r&&i>=e)throw new Error("Excess padding");if(!r&&o)throw new Error(`Non-zero padding: ${o}`);return r&&i>0&&c.push(o>>>0),c}function Rs(t){return oe(t),{encode:e=>{if(!(e instanceof Uint8Array))throw new Error("radix.encode input should be Uint8Array");return zr(Array.from(e),2**8,t)},decode:e=>{if(!Array.isArray(e)||e.length&&typeof e[0]!="number")throw new Error("radix.decode input should be array of strings");return Uint8Array.from(zr(e,t,2**8))}}}function Rt(t,e=!1){if(oe(t),t<=0||t>32)throw new Error("radix2: bits should be in (0..32]");if(He(8,t)>32||He(t,8)>32)throw new Error("radix2: carry overflow");return{encode:n=>{if(!(n instanceof Uint8Array))throw new Error("radix2.encode input should be Uint8Array");return Bn(Array.from(n),8,t,!e)},decode:n=>{if(!Array.isArray(n)||n.length&&typeof n[0]!="number")throw new Error("radix2.decode input should be array of strings");return Uint8Array.from(Bn(n,t,8,e))}}}function Dr(t){if(typeof t!="function")throw new Error("unsafeWrapper fn should be function");return function(...e){try{return t.apply(null,e)}catch{}}}const Hs=xt(Rt(4),vt("0123456789ABCDEF"),_t("")),$s=xt(Rt(5),vt("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"),Re(5),_t(""));xt(Rt(5),vt("0123456789ABCDEFGHIJKLMNOPQRSTUV"),Re(5),_t("")),xt(Rt(5),vt("0123456789ABCDEFGHJKMNPQRSTVWXYZ"),_t(""),Mr(t=>t.toUpperCase().replace(/O/g,"0").replace(/[IL]/g,"1")));const ge=xt(Rt(6),vt("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),Re(6),_t("")),qs=xt(Rt(6),vt("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"),Re(6),_t("")),On=t=>xt(Rs(58),vt(t),_t("")),In=On("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");On("123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"),On("rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz");const Vr=[0,2,3,5,6,7,9,10,11],js={encode(t){let e="";for(let n=0;n<t.length;n+=8){const r=t.subarray(n,n+8);e+=In.encode(r).padStart(Vr[r.length],"1")}return e},decode(t){let e=[];for(let n=0;n<t.length;n+=11){const r=t.slice(n,n+11),o=Vr.indexOf(r.length),i=In.decode(r);for(let s=0;s<i.length-o;s++)if(i[s]!==0)throw new Error("base58xmr: wrong padding");e=e.concat(Array.from(i.slice(i.length-o)))}return Uint8Array.from(e)}},Tn=xt(vt("qpzry9x8gf2tvdw0s3jn54khce6mua7l"),_t("")),Wr=[996825010,642813549,513874426,1027748829,705979059];function be(t){const e=t>>25;let n=(t&33554431)<<5;for(let r=0;r<Wr.length;r++)(e>>r&1)===1&&(n^=Wr[r]);return n}function Zr(t,e,n=1){const r=t.length;let o=1;for(let i=0;i<r;i++){const s=t.charCodeAt(i);if(s<33||s>126)throw new Error(`Invalid prefix (${t})`);o=be(o)^s>>5}o=be(o);for(let i=0;i<r;i++)o=be(o)^t.charCodeAt(i)&31;for(let i of e)o=be(o)^i;for(let i=0;i<6;i++)o=be(o);return o^=n,Tn.encode(Bn([o%2**30],30,5,!1))}function Gr(t){const e=t==="bech32"?1:734539939,n=Rt(5),r=n.decode,o=n.encode,i=Dr(r);function s(f,u,w=90){if(typeof f!="string")throw new Error(`bech32.encode prefix should be string, not ${typeof f}`);if(!Array.isArray(u)||u.length&&typeof u[0]!="number")throw new Error(`bech32.encode words should be array of numbers, not ${typeof u}`);const h=f.length+7+u.length;if(w!==!1&&h>w)throw new TypeError(`Length ${h} exceeds limit ${w}`);return f=f.toLowerCase(),`${f}1${Tn.encode(u)}${Zr(f,u,e)}`}function c(f,u=90){if(typeof f!="string")throw new Error(`bech32.decode input should be string, not ${typeof f}`);if(f.length<8||u!==!1&&f.length>u)throw new TypeError(`Wrong string length: ${f.length} (${f}). Expected (8..${u})`);const w=f.toLowerCase();if(f!==w&&f!==f.toUpperCase())throw new Error("String must be lowercase or uppercase");f=w;const h=f.lastIndexOf("1");if(h===0||h===-1)throw new Error('Letter "1" must be present between prefix and data only');const g=f.slice(0,h),d=f.slice(h+1);if(d.length<6)throw new Error("Data must be at least 6 characters long");const p=Tn.decode(d).slice(0,-6),b=Zr(g,p,e);if(!d.endsWith(b))throw new Error(`Invalid checksum in ${f}: expected "${b}"`);return{prefix:g,words:p}}const l=Dr(c);function a(f){const{prefix:u,words:w}=c(f,!1);return{prefix:u,words:w,bytes:r(w)}}return{encode:s,decode:c,decodeToBytes:a,decodeUnsafe:l,fromWords:r,fromWordsUnsafe:i,toWords:o}}const Fr=Gr("bech32");Gr("bech32m");const Ms={encode:t=>new TextDecoder().decode(t),decode:t=>new TextEncoder().encode(t)},zs=xt(Rt(4),vt("0123456789abcdef"),_t(""),Mr(t=>{if(typeof t!="string"||t.length%2)throw new TypeError(`hex.decode: expected string, got ${typeof t} with length ${t.length}`);return t.toLowerCase()}));`${Object.keys({utf8:Ms,hex:zs,base16:Hs,base32:$s,base64:ge,base64url:qs,base58:In,base58xmr:js}).join(", ")}`;var Ft=Symbol("verified"),Ks=t=>t instanceof Object;function Ds(t){if(!Ks(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 n=t.tags[e];if(!Array.isArray(n))return!1;for(let r=0;r<n.length;r++)if(typeof n[r]=="object")return!1}return!0}var Vs=new TextDecoder("utf-8"),Yr=new TextEncoder;function ye(t){t.indexOf("://")===-1&&(t="wss://"+t);let e=new URL(t);return 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()}var Ws=class{constructor(t){E(this,"value");E(this,"next",null);E(this,"prev",null);this.value=t}},Zs=class{constructor(){E(this,"first");E(this,"last");this.first=null,this.last=null}enqueue(t){const e=new Ws(t);return this.last?this.last===this.first?(this.last=e,this.last.prev=this.first,this.first.next=e):(e.prev=this.last,this.last.next=e,this.last=e):(this.first=e,this.last=e),!0}dequeue(){if(!this.first)return null;if(this.first===this.last){const e=this.first;return this.first=null,this.last=null,e.value}const t=this.first;return this.first=t.next,t.value}},Gs=class{generateSecretKey(){return nt.utils.randomPrivateKey()}getPublicKey(t){return et(nt.getPublicKey(t))}finalizeEvent(t,e){const n=t;return n.pubkey=et(nt.getPublicKey(e)),n.id=Nn(n),n.sig=et(nt.sign(Nn(n),e)),n[Ft]=!0,n}verifyEvent(t){if(typeof t[Ft]=="boolean")return t[Ft];const e=Nn(t);if(e!==t.id)return t[Ft]=!1,!1;try{const n=nt.verify(t.sig,e,t.pubkey);return t[Ft]=n,n}catch{return t[Ft]=!1,!1}}};function Fs(t){if(!Ds(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 Nn(t){let e=mn(Yr.encode(Fs(t)));return et(e)}var $e=new Gs,Ys=$e.generateSecretKey,Jr=$e.getPublicKey,Js=$e.finalizeEvent,Qr=$e.verifyEvent;async function Qs(t,e,n){const r=t instanceof Uint8Array?et(t):t,o=de.getSharedSecret(r,"02"+e),i=Xr(o);let s=Uint8Array.from(Vo(16)),c=Yr.encode(n),l=jr(i,s).encrypt(c),a=ge.encode(new Uint8Array(l)),f=ge.encode(new Uint8Array(s.buffer));return`${a}?iv=${f}`}async function Xs(t,e,n){const r=t instanceof Uint8Array?et(t):t;let[o,i]=n.split("?iv="),s=de.getSharedSecret(r,"02"+e),c=Xr(s),l=ge.decode(i),a=ge.decode(o),f=jr(c,l).decrypt(a);return Vs.decode(f)}function Xr(t){return t.slice(1,33)}var tc=/^(?:([\w.+-]+)@)?([\w_-]+(\.[\w_-]+)+)$/,ec;try{ec=fetch}catch{}var nc=22242,Pn=24133,rc=31990;function oc(t,e){if(t.ids&&t.ids.indexOf(e.id)===-1&&!t.ids.some(n=>e.id.startsWith(n))||t.kinds&&t.kinds.indexOf(e.kind)===-1||t.authors&&t.authors.indexOf(e.pubkey)===-1&&!t.authors.some(n=>e.pubkey.startsWith(n)))return!1;for(let n in t)if(n[0]==="#"){let r=n.slice(1),o=t[`#${r}`];if(o&&!e.tags.find(([i,s])=>i===n.slice(1)&&o.indexOf(s)!==-1))return!1}return!(t.since&&e.created_at<t.since||t.until&&e.created_at>t.until)}function ic(t,e){for(let n=0;n<t.length;n++)if(oc(t[n],e))return!0;return!1}function sc(t,e){let n=e.length+3,r=t.indexOf(`"${e}":`)+n,o=t.slice(r).indexOf('"')+r+1;return t.slice(o,o+64)}function cc(t){let e=t.slice(0,22).indexOf('"EVENT"');if(e===-1)return null;let n=t.slice(e+7+1).indexOf('"');if(n===-1)return null;let r=e+7+1+n,o=t.slice(r+1,80).indexOf('"');if(o===-1)return null;let i=r+1+o;return t.slice(r+1,i)}function lc(t,e){return{kind:nc,created_at:Math.floor(Date.now()/1e3),tags:[["relay",t],["challenge",e]],content:""}}async function ac(){return new Promise(t=>{const e=new MessageChannel,n=()=>{e.port1.removeEventListener("message",n),t()};e.port1.addEventListener("message",n),e.port2.postMessage(0),e.port1.start()})}var uc=t=>(t[Ft]=!0,!0),to;try{to=WebSocket}catch{}var eo=class{constructor(t,e){E(this,"url");E(this,"_connected",!1);E(this,"onclose",null);E(this,"onnotice",t=>console.debug(`NOTICE from ${this.url}: ${t}`));E(this,"baseEoseTimeout",4400);E(this,"connectionTimeout",4400);E(this,"openSubs",new Map);E(this,"connectionTimeoutHandle");E(this,"connectionPromise");E(this,"openCountRequests",new Map);E(this,"openEventPublishes",new Map);E(this,"ws");E(this,"incomingMessageQueue",new Zs);E(this,"queueRunning",!1);E(this,"challenge");E(this,"serial",0);E(this,"verifyEvent");this.url=ye(t),this.verifyEvent=e.verifyEvent}static async connect(t,e){const n=new eo(t,e);return await n.connect(),n}closeAllSubscriptions(t){for(let[e,n]of this.openSubs)n.close(t);this.openSubs.clear();for(let[e,n]of this.openEventPublishes)n.reject(new Error(t));this.openEventPublishes.clear();for(let[e,n]of this.openCountRequests)n.reject(new Error(t));this.openCountRequests.clear()}get connected(){return this._connected}async connect(){return this.connectionPromise?this.connectionPromise:(this.challenge=void 0,this.connectionPromise=new Promise((t,e)=>{this.connectionTimeoutHandle=setTimeout(()=>{var n;e("connection timed out"),this.connectionPromise=void 0,(n=this.onclose)==null||n.call(this),this.closeAllSubscriptions("relay connection timed out")},this.connectionTimeout);try{this.ws=new to(this.url)}catch(n){e(n);return}this.ws.onopen=()=>{clearTimeout(this.connectionTimeoutHandle),this._connected=!0,t()},this.ws.onerror=n=>{var r;e(n.message),this._connected&&((r=this.onclose)==null||r.call(this),this.closeAllSubscriptions("relay connection errored"),this._connected=!1)},this.ws.onclose=async()=>{var n;this.connectionPromise=void 0,(n=this.onclose)==null||n.call(this),this.closeAllSubscriptions("relay connection closed"),this._connected=!1},this.ws.onmessage=this._onmessage.bind(this)}),this.connectionPromise)}async runQueue(){for(this.queueRunning=!0;this.handleNext()!==!1;)await ac();this.queueRunning=!1}handleNext(){var n,r;const t=this.incomingMessageQueue.dequeue();if(!t)return!1;const e=cc(t);if(e){const o=this.openSubs.get(e);if(!o)return;const i=sc(t,"id"),s=(n=o.alreadyHaveEvent)==null?void 0:n.call(o,i);if((r=o.receivedEvent)==null||r.call(o,this,i),s)return}try{let o=JSON.parse(t);switch(o[0]){case"EVENT":{const i=this.openSubs.get(o[1]),s=o[2];this.verifyEvent(s)&&ic(i.filters,s)&&i.onevent(s);return}case"COUNT":{const i=o[1],s=o[2],c=this.openCountRequests.get(i);c&&(c.resolve(s.count),this.openCountRequests.delete(i));return}case"EOSE":{const i=this.openSubs.get(o[1]);if(!i)return;i.receivedEose();return}case"OK":{const i=o[1],s=o[2],c=o[3],l=this.openEventPublishes.get(i);s?l.resolve(c):l.reject(new Error(c)),this.openEventPublishes.delete(i);return}case"CLOSED":{const i=o[1],s=this.openSubs.get(i);if(!s)return;s.closed=!0,s.close(o[2]);return}case"NOTICE":this.onnotice(o[1]);return;case"AUTH":{this.challenge=o[1];return}}}catch{return}}async send(t){if(!this.connectionPromise)throw new Error("sending on closed connection");this.connectionPromise.then(()=>{var e;(e=this.ws)==null||e.send(t)})}async auth(t){if(!this.challenge)throw new Error("can't perform auth, no challenge was received");const e=await t(lc(this.url,this.challenge)),n=new Promise((r,o)=>{this.openEventPublishes.set(e.id,{resolve:r,reject:o})});return this.send('["AUTH",'+JSON.stringify(e)+"]"),n}async publish(t){const e=new Promise((n,r)=>{this.openEventPublishes.set(t.id,{resolve:n,reject:r})});return this.send('["EVENT",'+JSON.stringify(t)+"]"),e}async count(t,e){this.serial++;const n=(e==null?void 0:e.id)||"count:"+this.serial,r=new Promise((o,i)=>{this.openCountRequests.set(n,{resolve:o,reject:i})});return this.send('["COUNT","'+n+'",'+JSON.stringify(t)+"]"),r}subscribe(t,e){const n=this.prepareSubscription(t,e);return n.fire(),n}prepareSubscription(t,e){this.serial++;const n=e.id||"sub:"+this.serial,r=new fc(this,n,t,e);return this.openSubs.set(n,r),r}close(){var t;this.closeAllSubscriptions("relay connection closed by us"),this._connected=!1,(t=this.ws)==null||t.close()}_onmessage(t){this.incomingMessageQueue.enqueue(t.data),this.queueRunning||this.runQueue()}},fc=class{constructor(t,e,n,r){E(this,"relay");E(this,"id");E(this,"closed",!1);E(this,"eosed",!1);E(this,"filters");E(this,"alreadyHaveEvent");E(this,"receivedEvent");E(this,"onevent");E(this,"oneose");E(this,"onclose");E(this,"eoseTimeout");E(this,"eoseTimeoutHandle");this.relay=t,this.filters=n,this.id=e,this.alreadyHaveEvent=r.alreadyHaveEvent,this.receivedEvent=r.receivedEvent,this.eoseTimeout=r.eoseTimeout||t.baseEoseTimeout,this.oneose=r.oneose,this.onclose=r.onclose,this.onevent=r.onevent||(o=>{console.warn(`onevent() callback not defined for subscription '${this.id}' in relay ${this.relay.url}. event received:`,o)})}fire(){this.relay.send('["REQ","'+this.id+'",'+JSON.stringify(this.filters).substring(1)),this.eoseTimeoutHandle=setTimeout(this.receivedEose.bind(this),this.eoseTimeout)}receivedEose(){var t;this.eosed||(clearTimeout(this.eoseTimeoutHandle),this.eosed=!0,(t=this.oneose)==null||t.call(this))}close(t="closed by caller"){var e;this.closed||(this.relay.send('["CLOSE",'+JSON.stringify(this.id)+"]"),this.closed=!0),this.relay.openSubs.delete(this.id),(e=this.onclose)==null||e.call(this,t)}},dc=class{constructor(t){E(this,"relays",new Map);E(this,"seenOn",new Map);E(this,"trackRelays",!1);E(this,"verifyEvent");E(this,"trustedRelayURLs",new Set);this.verifyEvent=t.verifyEvent}async ensureRelay(t,e){t=ye(t);let n=this.relays.get(t);return n||(n=new eo(t,{verifyEvent:this.trustedRelayURLs.has(t)?uc:this.verifyEvent}),e!=null&&e.connectionTimeout&&(n.connectionTimeout=e.connectionTimeout),this.relays.set(t,n)),await n.connect(),n}close(t){t.map(ye).forEach(e=>{var n;(n=this.relays.get(e))==null||n.close()})}subscribeMany(t,e,n){this.trackRelays&&(n.receivedEvent=(u,w)=>{let h=this.seenOn.get(w);h||(h=new Set,this.seenOn.set(w,h)),h.add(u)});const r=new Set,o=[],i=[];let s=u=>{var w;i[u]=!0,i.filter(h=>h).length===t.length&&((w=n.oneose)==null||w.call(n),s=()=>{})};const c=[];let l=(u,w)=>{var h;s(u),c[u]=w,c.filter(g=>g).length===t.length&&((h=n.onclose)==null||h.call(n,c),l=()=>{})};const a=u=>{var h;if((h=n.alreadyHaveEvent)!=null&&h.call(n,u))return!0;const w=r.has(u);return r.add(u),w},f=Promise.all(t.map(ye).map(async(u,w,h)=>{if(h.indexOf(u)!==w){l(w,"duplicate url");return}let g;try{g=await this.ensureRelay(u,{connectionTimeout:n.maxWait?Math.max(n.maxWait*.8,n.maxWait-1e3):void 0})}catch(p){l(w,(p==null?void 0:p.message)||String(p));return}let d=g.subscribe(e,{...n,oneose:()=>s(w),onclose:p=>l(w,p),alreadyHaveEvent:a,eoseTimeout:n.maxWait});o.push(d)}));return{async close(){await f,o.forEach(u=>{u.close()})}}}subscribeManyEose(t,e,n){const r=this.subscribeMany(t,e,{...n,oneose(){r.close()}});return r}async querySync(t,e,n){return new Promise(async r=>{const o=[];this.subscribeManyEose(t,[e],{...n,onevent(i){o.push(i)},onclose(i){r(o)}})})}async get(t,e,n){e.limit=1;const r=await this.querySync(t,e,n);return r.sort((o,i)=>i.created_at-o.created_at),r[0]||null}publish(t,e){return t.map(ye).map(async(n,r,o)=>o.indexOf(n)!==r?Promise.reject("duplicate url"):(await this.ensureRelay(n)).publish(e))}},hc=class extends dc{constructor(){super({verifyEvent:Qr})}},no;try{no=fetch}catch{}var qe=/^bunker:\/\/([0-9a-f]{64})\??([?\/\w:.=&%]*)$/,wc=/^[^\s@]+@[^\s@]+\.[^\s@]+$/;async function pc(t){let e=t.match(qe);if(e)try{const n=e[1],r=new URLSearchParams(e[2]);return{pubkey:n,relays:r.getAll("relay"),secret:r.get("secret")}}catch{}return ro(t)}async function ro(t){const e=t.match(tc);if(!e)return null;const[n,r="_",o]=e;try{const i=`https://${o}/.well-known/nostr.json?name=${r}`,s=await(await no(i,{redirect:"error"})).json();let c=s.names[r],l=s.nip46[c]||[];return{pubkey:c,relays:l,secret:null}}catch{return null}}var oo=class{constructor(t,e,n={}){E(this,"pool");E(this,"subCloser");E(this,"isOpen");E(this,"serial");E(this,"idPrefix");E(this,"listeners");E(this,"waitingForAuth");E(this,"secretKey");E(this,"bp");if(e.relays.length===0)throw new Error("no relays are specified for this bunker");this.pool=n.pool||new hc,this.secretKey=t,this.bp=e,this.isOpen=!1,this.idPrefix=Math.random().toString(36).substring(7),this.serial=0,this.listeners={},this.waitingForAuth={};const r=this.listeners,o=this.waitingForAuth;this.subCloser=this.pool.subscribeMany(this.bp.relays,[{kinds:[Pn],"#p":[Jr(this.secretKey)]}],{async onevent(i){const{id:s,result:c,error:l}=JSON.parse(await Xs(t,i.pubkey,i.content));if(c==="auth_url"&&o[s]){delete o[s],n.onauth?n.onauth(l):console.warn(`nostr-tools/nip46: remote signer ${e.pubkey} tried to send an "auth_url"='${l}' but there was no onauth() callback configured.`);return}let a=r[s];a&&(l?a.reject(l):c&&a.resolve(c),delete r[s])}}),this.isOpen=!0}async close(){this.isOpen=!1,this.subCloser.close()}async sendRequest(t,e){return new Promise(async(n,r)=>{try{if(!this.isOpen)throw new Error("this signer is not open anymore, create a new one");this.serial++;const o=`${this.idPrefix}-${this.serial}`,i=await Qs(this.secretKey,this.bp.pubkey,JSON.stringify({id:o,method:t,params:e})),s=Js({kind:Pn,tags:[["p",this.bp.pubkey]],content:i,created_at:Math.floor(Date.now()/1e3)},this.secretKey);this.listeners[o]={resolve:n,reject:r},this.waitingForAuth[o]=!0,await Promise.any(this.pool.publish(this.bp.relays,s))}catch(o){r(o)}})}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",[Jr(this.secretKey),this.bp.secret||""])}async getPublicKey(){return this.bp.pubkey}async getRelays(){return JSON.parse(await this.sendRequest("get_relays",[]))}async signEvent(t){let e=await this.sendRequest("sign_event",[JSON.stringify(t)]),n=JSON.parse(e);if(n.pubkey===this.bp.pubkey&&Qr(n))return n;throw new Error(`event returned from bunker is improperly signed: ${JSON.stringify(n)}`)}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 nip44GetKey(t){let e=await this.sendRequest("nip44_get_key",[t]);return Je(e)}async nip44Encrypt(t,e){return await this.sendRequest("nip44_encrypt",[t,e])}async nip44Decrypt(t,e){return await this.sendRequest("nip44_encrypt",[t,e])}};async function gc(t,e,n,r,o){if(o&&!wc.test(o))throw new Error("Invalid email");let i=Ys(),s=new oo(i,t.bunkerPointer,e),c=await s.sendRequest("create_account",[n,r,o||""]);return s.bp.pubkey=c,await s.connect(),s}async function bc(t,e){const n=await t.querySync(e,{kinds:[rc],"#k":[Pn.toString()]});return n.sort((o,i)=>i.created_at-o.created_at),(await Promise.all(n.map(async(o,i)=>{try{const s=JSON.parse(o.content);try{if(n.findIndex(l=>JSON.parse(l.content).nip05===s.nip05)!==i)return}catch{}const c=await ro(s.nip05);if(c&&c.pubkey===o.pubkey&&c.relays.length)return{bunkerPointer:c,nip05:s.nip05,domain:s.nip05.split("@")[1],name:s.name||s.display_name,picture:s.picture,about:s.about,website:s.website,local:!1}}catch{return}}))).filter(o=>o!==void 0)}var io=/^(?:([\w.+-]+)@)?([\w_-]+(\.[\w_-]+)+)$/,so;try{so=fetch}catch{}async function yc(t){var i;const e=t.match(io);if(!e)return null;const[n,r="_",o]=e;try{const s=`https://${o}/.well-known/nostr.json?name=${r}`,c=await(await so(s,{redirect:"error"})).json();let l=c.names[r];return l?{pubkey:l,relays:(i=c.relays)==null?void 0:i[l]}:null}catch{return null}}new TextDecoder("utf-8"),new TextEncoder;var mc=5e3;function Ec(t){return vc("npub",Je(t))}function xc(t,e){let n=Fr.toWords(e);return Fr.encode(t,n,mc)}function vc(t,e){return xc(t,e)}const ie=[];function _c(t,e=q){let n;const r=new Set;function o(c){if(ze(t,c)&&(t=c,n)){const l=!ie.length;for(const a of r)a[1](),ie.push(a,t);if(l){for(let a=0;a<ie.length;a+=2)ie[a][0](ie[a+1]);ie.length=0}}}function i(c){o(c(t))}function s(c,l=q){const a=[c,l];return r.add(a),r.size===1&&(n=e(o,i)||q),c(t),()=>{r.delete(a),r.size===0&&n&&(n(),n=null)}}return{set:o,update:i,subscribe:s}}const kc=t=>{const{subscribe:e,set:n}=_c(void 0,()=>{let r=window.matchMedia(t);n(r.matches);const o=()=>n(r.matches);return"addEventListener"in r?r.addEventListener("change",o):r.addListener(o),()=>{"removeEventListener"in r?r.removeEventListener("change",o):r.removeListener(o)}});return{subscribe:e}};function Sc(t){let e,n,r;return{c(){e=Ke("svg"),n=Ke("circle"),r=Ke("path"),k(n,"class","tw-opacity-25"),k(n,"cx","12"),k(n,"cy","12"),k(n,"r","10"),k(n,"stroke","currentColor"),k(n,"stroke-width","4"),k(r,"class","tw-opacity-75"),k(r,"fill","currentColor"),k(r,"d","M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"),k(e,"class","tw-animate-spin tw-ml-2 tw-h-5 tw-w-5 tw-text-white"),k(e,"xmlns","http://www.w3.org/2000/svg"),k(e,"fill","none"),k(e,"viewBox","0 0 24 24")},m(o,i){j(o,e,i),U(e,n),U(e,r)},p:q,i:q,o:q,d(o){o&&$(e)}}}class co extends Gn{constructor(e){super(),Zn(this,e,null,Sc,ze,{})}}const{window:Un}=Bo;function lo(t,e,n){const r=t.slice();return r[65]=e[n],r}function Ac(t){let e,n,r,o,i,s,c,l,a,f,u;const w=[Tc,Ic,Oc],h=[];function g(d,p){return d[12]?0:d[14]?d[14]?2:-1:1}return~(s=g(t))&&(c=h[s]=w[s](t)),{c(){e=C("div"),n=C("button"),r=Z("⤫"),i=V(),c&&c.c(),k(n,"class",o="tw-absolute tw-top-0 tw-right-0.5 tw-bg-transparent tw-border-none tw-cursor-pointer tw-text-"+t[0]+"-950 tw-text-3xl"),k(e,"class",l="sm:tw-w-80 tw-px-6 tw-py-8 tw-bg-"+t[0]+"-700 tw-rounded-md tw-shadow-[0_0px_30px_0px_rgba(0,0,0,0.6)] tw-transition-all tw-animate-show "+t[20])},m(d,p){j(d,e,p),U(e,n),U(n,r),U(e,i),~s&&h[s].m(e,null),a=!0,f||(u=tt(n,"click",t[23]),f=!0)},p(d,p){(!a||p[0]&1&&o!==(o="tw-absolute tw-top-0 tw-right-0.5 tw-bg-transparent tw-border-none tw-cursor-pointer tw-text-"+d[0]+"-950 tw-text-3xl"))&&k(n,"class",o);let b=s;s=g(d),s===b?~s&&h[s].p(d,p):(c&&(_e(),wt(h[b],1,1,()=>{h[b]=null}),ke()),~s?(c=h[s],c?c.p(d,p):(c=h[s]=w[s](d),c.c()),ft(c,1),c.m(e,null)):c=null),(!a||p[0]&1048577&&l!==(l="sm:tw-w-80 tw-px-6 tw-py-8 tw-bg-"+d[0]+"-700 tw-rounded-md tw-shadow-[0_0px_30px_0px_rgba(0,0,0,0.6)] tw-transition-all tw-animate-show "+d[20]))&&k(e,"class",l)},i(d){a||(ft(c),a=!0)},o(d){wt(c),a=!1},d(d){d&&$(e),~s&&h[s].d(),f=!1,u()}}}function Bc(t){let e,n,r,o,i;const s=[Cc,Lc,Uc],c=[];function l(a,f){return a[10]?0:a[14]?2:1}return n=l(t),r=c[n]=s[n](t),{c(){e=C("div"),r.c(),k(e,"class",o="tw-px-4 tw-py-2 tw-bg-"+t[0]+"-700 hover:tw-bg-"+t[0]+"-800 tw-rounded tw-shadow-[0_0px_10px_0px_rgba(0,0,0,0.3)] tw-transition-all tw-duration-200 "+t[20])},m(a,f){j(a,e,f),c[n].m(e,null),i=!0},p(a,f){let u=n;n=l(a),n===u?c[n].p(a,f):(_e(),wt(c[u],1,1,()=>{c[u]=null}),ke(),r=c[n],r?r.p(a,f):(r=c[n]=s[n](a),r.c()),ft(r,1),r.m(e,null)),(!i||f[0]&1048577&&o!==(o="tw-px-4 tw-py-2 tw-bg-"+a[0]+"-700 hover:tw-bg-"+a[0]+"-800 tw-rounded tw-shadow-[0_0px_10px_0px_rgba(0,0,0,0.3)] tw-transition-all tw-duration-200 "+a[20]))&&k(e,"class",o)},i(a){i||(ft(r),i=!0)},o(a){wt(r),i=!1},d(a){a&&$(e),c[n].d()}}}function Oc(t){let e,n,r,o,i,s,c=t[14].npub+"",l,a,f,u,w,h,g,d,p,b,v,B=Or(t[9])+"",I,N,x,m=(t[14].picture||t[14].name)&&ao(t);return{c(){e=C("div"),n=C("div"),n.textContent="You are connected to Nostr as",r=V(),o=C("a"),m&&m.c(),i=V(),s=C("div"),l=Z(c),f=V(),u=C("button"),w=Z("Disconnect"),g=V(),d=C("div"),p=Z("This webpage is using the public key:"),b=C("br"),v=V(),I=Z(B),k(n,"class","tw-text-sm tw-mb-4"),k(s,"class","tw-block tw-break-all"),k(o,"target","_blank"),k(o,"href",a="https://nosta.me/"+t[14].npub),k(o,"class","tw-text-white tw-no-underline tw-group"),k(e,"class","tw-text-center"),k(u,"class",h="tw-block tw-w-full tw-my-2 tw-mt-6 tw-px-2 tw-py-1 tw-text-lg tw-rounded tw-border-0 tw-bg-"+t[0]+"-900 hover:tw-bg-"+t[0]+"-950 tw-hover:bg-indigo-900 tw-cursor-pointer tw-text-white"),k(d,"class","tw-block tw-break-all tw-mt-6 tw-text-center tw-text-sm")},m(y,T){j(y,e,T),U(e,n),U(e,r),U(e,o),m&&m.m(o,null),U(o,i),U(o,s),U(s,l),j(y,f,T),j(y,u,T),U(u,w),j(y,g,T),j(y,d,T),U(d,p),U(d,b),U(d,v),U(d,I),N||(x=tt(u,"click",t[25]),N=!0)},p(y,T){y[14].picture||y[14].name?m?m.p(y,T):(m=ao(y),m.c(),m.m(o,i)):m&&(m.d(1),m=null),T[0]&16384&&c!==(c=y[14].npub+"")&&ce(l,c),T[0]&16384&&a!==(a="https://nosta.me/"+y[14].npub)&&k(o,"href",a),T[0]&1&&h!==(h="tw-block tw-w-full tw-my-2 tw-mt-6 tw-px-2 tw-py-1 tw-text-lg tw-rounded tw-border-0 tw-bg-"+y[0]+"-900 hover:tw-bg-"+y[0]+"-950 tw-hover:bg-indigo-900 tw-cursor-pointer tw-text-white")&&k(u,"class",h),T[0]&512&&B!==(B=Or(y[9])+"")&&ce(I,B)},i:q,o:q,d(y){y&&($(e),$(f),$(u),$(g),$(d)),m&&m.d(),N=!1,x()}}}function Ic(t){let e,n,r,o,i,s,c,l,a,f,u,w,h,g,d,p,b,v=t[13]&&ho(t);const B=[Pc,Nc],I=[];function N(y,T){return y[10]?0:1}l=N(t),a=I[l]=B[l](t);let x=t[10]&&t[11]&&wo(t),m=!t[10]&&po(t);return{c(){e=C("div"),e.textContent="How do you want to connect to Nostr?",n=V(),r=C("form"),o=C("input"),i=V(),v&&v.c(),s=V(),c=C("button"),a.c(),w=V(),x&&x.c(),h=V(),m&&m.c(),g=Io(),k(e,"class","tw-text-lg tw-text-center"),k(o,"class","tw-box-border tw-w-full tw-px-2 tw-py-1 tw-rounded tw-text-lg tw-border-none tw-outline-none"),k(o,"placeholder","user@provider or bunker://..."),o.autofocus=!0,o.disabled=t[10],k(c,"class",f="tw-flex tw-w-full tw-mt-4 tw-px-2 tw-py-1 tw-text-lg tw-rounded tw-border-0 tw-bg-"+t[0]+"-900 hover:tw-bg-"+t[0]+"-950 tw-hover:bg-indigo-900 tw-cursor-pointer tw-text-white disabled:tw-bg-neutral-400 disabled:tw-text-neutral-200 disabled:tw-cursor-default tw-items-center tw-justify-center"),c.disabled=u=!t[19]||t[10],k(r,"class","flex tw-mt-4 tw-mb-1")},m(y,T){j(y,e,T),j(y,n,T),j(y,r,T),U(r,o),t[40](o),Yt(o,t[2]),U(r,i),v&&v.m(r,null),U(r,s),U(r,c),I[l].m(c,null),U(r,w),x&&x.m(r,null),j(y,h,T),m&&m.m(y,T),j(y,g,T),d=!0,o.focus(),p||(b=[tt(o,"input",t[41]),tt(r,"submit",t[24])],p=!0)},p(y,T){(!d||T[0]&1024)&&(o.disabled=y[10]),T[0]&4&&o.value!==y[2]&&Yt(o,y[2]),y[13]?v?v.p(y,T):(v=ho(y),v.c(),v.m(r,s)):v&&(v.d(1),v=null);let P=l;l=N(y),l!==P&&(_e(),wt(I[P],1,1,()=>{I[P]=null}),ke(),a=I[l],a||(a=I[l]=B[l](y),a.c()),ft(a,1),a.m(c,null)),(!d||T[0]&1&&f!==(f="tw-flex tw-w-full tw-mt-4 tw-px-2 tw-py-1 tw-text-lg tw-rounded tw-border-0 tw-bg-"+y[0]+"-900 hover:tw-bg-"+y[0]+"-950 tw-hover:bg-indigo-900 tw-cursor-pointer tw-text-white disabled:tw-bg-neutral-400 disabled:tw-text-neutral-200 disabled:tw-cursor-default tw-items-center tw-justify-center"))&&k(c,"class",f),(!d||T[0]&525312&&u!==(u=!y[19]||y[10]))&&(c.disabled=u),y[10]&&y[11]?x?x.p(y,T):(x=wo(y),x.c(),x.m(r,null)):x&&(x.d(1),x=null),y[10]?m&&(m.d(1),m=null):m?m.p(y,T):(m=po(y),m.c(),m.m(g.parentNode,g))},i(y){d||(ft(a),d=!0)},o(y){wt(a),d=!1},d(y){y&&($(e),$(n),$(r),$(h),$(g)),t[40](null),v&&v.d(),I[l].d(),x&&x.d(),m&&m.d(y),p=!1,Ot(b)}}}function Tc(t){let e,n,r,o,i,s,c,l,a,f,u,w,h,g,d,p,b,v,B,I,N,x,m,y,T=Vn(t[15]),P=[];for(let A=0;A<T.length;A+=1)P[A]=go(lo(t,T,A));return{c(){e=C("div"),e.textContent="Create a Nostr account",n=V(),r=C("form"),o=C("div"),i=C("input"),s=V(),c=C("div"),c.textContent="@",l=V(),a=C("select");for(let A=0;A<P.length;A+=1)P[A].c();f=V(),u=C("div"),u.textContent=`A window from the selected provider will pop up to finalize the
2
+ creation; if it doesn't display check if the browser is blocking it`,w=V(),h=C("button"),g=Z("Create »"),b=V(),v=C("div"),B=Z("Do you already have a Nostr address?"),I=C("br"),N=V(),x=C("button"),x.textContent="Login now",k(e,"class","tw-text-lg tw-text-center"),k(i,"class","tw-box-border tw-w-40 tw-px-2 tw-py-1 tw-rounded tw-text-lg tw-border-none tw-outline-none"),k(i,"placeholder","bob"),i.autofocus=!0,k(c,"class","tw-mx-2 tw-text-2xl"),k(a,"class","tw-w-full tw-box-border tw-px-2 tw-py-1 tw-rounded tw-text-lg tw-border-none tw-outline-none"),t[8]===void 0&&xe(()=>t[39].call(a)),k(o,"class","tw-flex items-center"),k(u,"class","tw-text-sm tw-text-center tw-mt-4 tw-leading-4"),k(h,"class",d="tw-block tw-w-full tw-mt-4 tw-px-2 tw-py-1 tw-text-lg tw-rounded tw-border-0 tw-bg-"+t[0]+"-900 hover:tw-bg-"+t[0]+"-950 tw-hover:bg-indigo-900 tw-cursor-pointer tw-text-white disabled:tw-bg-neutral-400 disabled:tw-text-neutral-200 disabled:tw-cursor-default"),h.disabled=p=!t[8]||!t[7],k(r,"class","tw-mt-4 tw-mb-1"),k(x,"class","tw-border-0 tw-bg-transparent tw-text-white tw-cursor-pointer tw-underline tw-text-sm"),k(v,"class","tw-mt-6 tw-text-center tw-text-sm tw-leading-3")},m(A,H){j(A,e,H),j(A,n,H),j(A,r,H),U(r,o),U(o,i),t[37](i),Yt(i,t[7]),U(o,s),U(o,c),U(o,l),U(o,a);for(let R=0;R<P.length;R+=1)P[R]&&P[R].m(a,null);Mn(a,t[8],!0),U(r,f),U(r,u),U(r,w),U(r,h),U(h,g),j(A,b,H),j(A,v,H),U(v,B),U(v,I),U(v,N),U(v,x),i.focus(),m||(y=[tt(i,"input",t[38]),tt(i,"input",t[29]),tt(a,"change",t[39]),tt(r,"submit",t[28]),tt(x,"click",t[27])],m=!0)},p(A,H){if(H[0]&128&&i.value!==A[7]&&Yt(i,A[7]),H[0]&32768){T=Vn(A[15]);let R;for(R=0;R<T.length;R+=1){const Y=lo(A,T,R);P[R]?P[R].p(Y,H):(P[R]=go(Y),P[R].c(),P[R].m(a,null))}for(;R<P.length;R+=1)P[R].d(1);P.length=T.length}H[0]&33024&&Mn(a,A[8]),H[0]&1&&d!==(d="tw-block tw-w-full tw-mt-4 tw-px-2 tw-py-1 tw-text-lg tw-rounded tw-border-0 tw-bg-"+A[0]+"-900 hover:tw-bg-"+A[0]+"-950 tw-hover:bg-indigo-900 tw-cursor-pointer tw-text-white disabled:tw-bg-neutral-400 disabled:tw-text-neutral-200 disabled:tw-cursor-default")&&k(h,"class",d),H[0]&33152&&p!==(p=!A[8]||!A[7])&&(h.disabled=p)},i:q,o:q,d(A){A&&($(e),$(n),$(r),$(b),$(v)),t[37](null),Oo(P,A),m=!1,Ot(y)}}}function ao(t){let e,n,r=t[14].picture&&uo(t),o=t[14].name&&fo(t);return{c(){e=C("div"),r&&r.c(),n=V(),o&&o.c(),k(e,"class","tw-flex tw-items-center tw-justify-center tw-gap-2 tw-mb-2")},m(i,s){j(i,e,s),r&&r.m(e,null),U(e,n),o&&o.m(e,null)},p(i,s){i[14].picture?r?r.p(i,s):(r=uo(i),r.c(),r.m(e,n)):r&&(r.d(1),r=null),i[14].name?o?o.p(i,s):(o=fo(i),o.c(),o.m(e,null)):o&&(o.d(1),o=null)},d(i){i&&$(e),r&&r.d(),o&&o.d()}}}function uo(t){let e,n,r;return{c(){e=C("img"),Ee(e.src,n=t[14].picture)||k(e,"src",n),k(e,"alt",""),k(e,"class",r="tw-w-10 tw-h-10 tw-rounded-full tw-border-solid tw-border-2 tw-border-transparent group-hover:tw-border-"+t[0]+"-100")},m(o,i){j(o,e,i)},p(o,i){i[0]&16384&&!Ee(e.src,n=o[14].picture)&&k(e,"src",n),i[0]&1&&r!==(r="tw-w-10 tw-h-10 tw-rounded-full tw-border-solid tw-border-2 tw-border-transparent group-hover:tw-border-"+o[0]+"-100")&&k(e,"class",r)},d(o){o&&$(e)}}}function fo(t){let e,n=t[14].name+"",r;return{c(){e=C("div"),r=Z(n),k(e,"class","tw-text-3xl group-hover:tw-underline tw-decoration-2 tw-underline-offset-4")},m(o,i){j(o,e,i),U(e,r)},p(o,i){i[0]&16384&&n!==(n=o[14].name+"")&&ce(r,n)},d(o){o&&$(e)}}}function ho(t){let e,n;return{c(){e=C("div"),n=Z(t[13]),k(e,"class","tw-my-2 tw-p-2 tw-text-sm tw-leading-4 tw-text-red-400 tw-bg-yellow-100 tw-rounded")},m(r,o){j(r,e,o),U(e,n)},p(r,o){o[0]&8192&&ce(n,r[13])},d(r){r&&$(e)}}}function Nc(t){let e;return{c(){e=Z("Connect »")},m(n,r){j(n,e,r)},i:q,o:q,d(n){n&&$(e)}}}function Pc(t){let e,n,r;return n=new co({}),{c(){e=Z(`Connecting to bunker
3
+ `),Wn(n.$$.fragment)},m(o,i){j(o,e,i),We(n,o,i),r=!0},i(o){r||(ft(n.$$.fragment,o),r=!0)},o(o){wt(n.$$.fragment,o),r=!1},d(o){o&&$(e),Ze(n,o)}}}function wo(t){let e,n,r,o,i;return{c(){e=C("div"),n=Z(`Waiting too much?
4
+ `),r=C("button"),r.textContent="Cancel the connection",k(r,"class","tw-border-0 tw-bg-transparent tw-text-white tw-cursor-pointer tw-underline tw-text-sm"),k(e,"class","tw-mt-6 tw-text-center tw-text-sm tw-leading-3")},m(s,c){j(s,e,c),U(e,n),U(e,r),o||(i=tt(r,"click",t[30]),o=!0)},p:q,d(s){s&&$(e),o=!1,i()}}}function po(t){let e,n,r,o,i,s,c;return{c(){e=C("div"),n=Z("Do you need a Nostr account?"),r=C("br"),o=V(),i=C("button"),i.textContent="Sign up now",k(i,"class","tw-border-0 tw-bg-transparent tw-text-white tw-cursor-pointer tw-underline tw-text-sm"),k(e,"class","tw-mt-6 tw-text-center tw-text-sm tw-leading-3")},m(l,a){j(l,e,a),U(e,n),U(e,r),U(e,o),U(e,i),s||(c=tt(i,"click",t[26]),s=!0)},p:q,d(l){l&&$(e),s=!1,c()}}}function go(t){let e,n,r;return{c(){e=C("option"),k(e,"label",n=t[65].domain),e.__value=r=t[65],Yt(e,e.__value),k(e,"class","tw-px-2 tw-py-1 tw-text-lg")},m(o,i){j(o,e,i)},p(o,i){i[0]&32768&&n!==(n=o[65].domain)&&k(e,"label",n),i[0]&32768&&r!==(r=o[65])&&(e.__value=r,Yt(e,e.__value))},d(o){o&&$(e)}}}function Uc(t){let e,n,r=(t[14].name||t[14].npub.slice(0,7)+"…"+t[14].npub.slice(-4))+"",o;function i(l,a){return l[14].picture?Hc:Rc}let s=i(t),c=s(t);return{c(){e=C("div"),c.c(),n=V(),o=Z(r),k(e,"class","tw-flex tw-items-center")},m(l,a){j(l,e,a),c.m(e,null),U(e,n),U(e,o)},p(l,a){s===(s=i(l))&&c?c.p(l,a):(c.d(1),c=s(l),c&&(c.c(),c.m(e,n))),a[0]&16384&&r!==(r=(l[14].name||l[14].npub.slice(0,7)+"…"+l[14].npub.slice(-4))+"")&&ce(o,r)},i:q,o:q,d(l){l&&$(e),c.d()}}}function Lc(t){let e;return{c(){e=Z("Connect with Nostr")},m(n,r){j(n,e,r)},p:q,i:q,o:q,d(n){n&&$(e)}}}function Cc(t){let e,n,r,o;return r=new co({}),{c(){e=C("div"),n=Z(`Connecting to bunker
5
+ `),Wn(r.$$.fragment),k(e,"class","tw-flex tw-items-center")},m(i,s){j(i,e,s),U(e,n),We(r,e,null),o=!0},p:q,i(i){o||(ft(r.$$.fragment,i),o=!0)},o(i){wt(r.$$.fragment,i),o=!1},d(i){i&&$(e),Ze(r)}}}function Rc(t){let e;return{c(){e=Z("☉")},m(n,r){j(n,e,r)},p:q,d(n){n&&$(e)}}}function Hc(t){let e,n;return{c(){e=C("img"),Ee(e.src,n=t[14].picture)||k(e,"src",n),k(e,"alt",""),k(e,"class","tw-w-5 tw-h-5 tw-rounded-full tw-mr-2")},m(r,o){j(r,e,o)},p(r,o){o[0]&16384&&!Ee(e.src,n=r[14].picture)&&k(e,"src",n)},d(r){r&&$(e)}}}function $c(t){let e,n,r,o,i,s,c;const l=[Bc,Ac],a=[];function f(u,w){return u[18]?1:0}return n=f(t),r=a[n]=l[n](t),{c(){e=C("div"),r.c(),k(e,"class","tw-text-white tw-font-sans draggable tw-animate-fadein"),k(e,"style",o="position: fixed; "+(t[18]&&t[3]?"width: 100%;":"")+"; right: "+(t[18]&&t[3]?"0":t[1])+"px; user-select: none; "+(t[18]&&t[3]?"bottom: 0px":t[17]+":"+t[16]+"px")),zn(e,"tw-cursor-pointer",!t[14]&&!t[18])},m(u,w){j(u,e,w),a[n].m(e,null),t[42](e),i=!0,s||(c=[tt(Un,"click",t[22]),tt(Un,"mouseup",t[33]),tt(Un,"mousemove",t[32]),tt(e,"mousedown",t[31])],s=!0)},p(u,w){let h=n;n=f(u),n===h?a[n].p(u,w):(_e(),wt(a[h],1,1,()=>{a[h]=null}),ke(),r=a[n],r?r.p(u,w):(r=a[n]=l[n](u),r.c()),ft(r,1),r.m(e,null)),(!i||w[0]&458762&&o!==(o="position: fixed; "+(u[18]&&u[3]?"width: 100%;":"")+"; right: "+(u[18]&&u[3]?"0":u[1])+"px; user-select: none; "+(u[18]&&u[3]?"bottom: 0px":u[17]+":"+u[16]+"px")))&&k(e,"style",o),(!i||w[0]&278528)&&zn(e,"tw-cursor-pointer",!u[14]&&!u[18])},i(u){i||(ft(r),i=!0)},o(u){wt(r),i=!1},d(u){u&&$(e),a[n].d(),t[42](null),s=!1,Ot(c)}}}const bo="We could not connect to a NIP-46 bunker with that url, are you sure it is set up correctly?",yo="We were not able to connect using this address. For it to work it has to come from a NIP-46 provider.",Ht=20;function qc(t,e,n){let r,o,i,s,c,l;const a=kc("only screen and (max-width: 640px)");Ao(t,a,O=>n(3,l=O));let f,{accent:u}=e,{position:w="top"}=e;const h=window,g=new bs;let d,p,b,v,B,I;const N=localStorage.getItem("wnj:clientSecret");N?I=Je(N):(I=Qi(),localStorage.setItem("wnj:clientSecret",et(I)));let x="closed",m,y,T,P,A,H,R=!1,Y,_,S,L,M=[],{right:z=20}=e,D=!1,G=!1,X,dt,ht;const kt={pool:g,onauth(O){window.open(O,"window.nostr","width=600,height=800,popup=yes")}},$t=Yn(()=>{switch(x){case"justopened":n(35,x="opened");break;case"justclosed":n(35,x="closed");break}},500);function it(){n(35,x="justopened"),$t()}function qt(){n(35,x="justclosed"),$t()}function ut(){if(m&&!H){Hn();return}it()}se();let St={isWnj:!0,async getPublicKey(){return m?m.pubkey:(!A&&!H&&it(),(await P).bp.pubkey)},async signEvent(O){return!A&&!H&&ut(),(await P).signEvent(O)},async getRelays(){return!A&&!H&&ut(),(await P).getRelays()},nip04:{async encrypt(O,K){return!A&&!H&&ut(),(await P).nip04Encrypt(O,K)},async decrypt(O,K){return!A&&!H&&ut(),(await P).nip04Decrypt(O,K)}}};function se(){qt(),m=null,P=new Promise((O,K)=>{y=O,T=K}),n(14,S=null),n(10,A=!1),n(11,R=!1),n(12,Y=!1),H=!1,L=null,n(13,_="")}Uo(()=>{let O=localStorage.getItem("wnj:bunkerPointer");if(O&&(m=JSON.parse(O),$n()),h.nostr&&!h.nostr.isWnj){h.destroyWnj();return}else Object.defineProperty(window,"nostr",{get(){return St},set(K){St=K,K.isWnj||h.destroyWnj()},configurable:!0});return()=>{L&&L.close()}});function jt(O){Math.abs(o-dt)>6||Date.now()-ht>600||x==="justopened"||x==="justclosed"||(O.composedPath().find(K=>K.id==="wnj")?it():qt())}function st(O){qt(),n(12,Y=!1),O.stopPropagation()}async function Mt(O){O.preventDefault();try{if(m=await pc(d.value),!m){d.value.match(qe)?n(13,_=bo):n(13,_=yo);return}d.setCustomValidity(""),n(13,_=""),await Hn(),$n()}catch{d.value.match(qe)?n(13,_=bo):n(13,_=yo),n(10,A=!1)}}async function je(O){O.preventDefault(),localStorage.removeItem("wnj:bunkerPointer"),se()}async function Me(O){O.preventDefault(),n(12,Y=!0),M.length===0&&(n(15,M=await bc(g,["wss://relay.nostr.band","wss://nos.lol","wss://nostr-pub.wellorder.net"])),n(8,B=M[0]))}function zc(O){n(12,Y=!1)}async function Kc(O){if(O.preventDefault(),!B)return;let K=await gc(B,kt,b.value,B.domain);it(),n(12,Y=!1),m=K.bp,$n(),Hn(K)}const Dc=Yn(async()=>{B&&b.value.length>0&&(await yc(b.value+"@"+B.domain)?b.setCustomValidity(`'${b.value}' is already taken.`):b.setCustomValidity(""))},500);function Vc(){n(11,R=!1),n(10,A=!1),T("connection aborted"),se()}async function Hn(O=void 0){O=O||new oo(I,m,kt),n(10,A=!0);let K=setTimeout(()=>{n(11,R=!0),n(18,i=!0)},5e3);try{await O.connect(),H=!0,localStorage.setItem("wnj:bunkerPointer",JSON.stringify(m)),qt(),y(O)}catch(At){T((At==null?void 0:At.message)||String(At))}finally{clearTimeout(K),n(10,A=!1),n(11,R=!1)}}function $n(){let O=m.pubkey;n(14,S={pubkey:O,npub:Ec(O),event:null}),L=g.subscribeMany(["wss://purplepag.es","wss://relay.snort.social","wss://relay.nos.social"],[{kinds:[0],authors:[O]}],{onevent(K){var At;if(!((((At=S.event)==null?void 0:At.created_at)||0)>=K.created_at))try{let{name:_o,picture:el}=JSON.parse(K.content);n(14,S.event=K,S),n(14,S.name=_o,S),n(14,S.picture=el,S)}catch{}}})}function Wc(O){if(i)return;D=!0;const K=f.getBoundingClientRect();X=O.clientY-K.top,dt=o,ht=Date.now()}function Zc(O){D&&(r==="top"?n(16,o=O.clientY):n(16,o=window.innerHeight-O.clientY),n(16,o-=X),n(36,G=!0),o<Ht&&n(16,o=Ht),o>window.innerHeight-Ht&&n(16,o=window.innerHeight-Ht))}function Gc(){if(D=!1,setTimeout(()=>{n(36,G=!1)},10),G){const O=f.getBoundingClientRect(),K=window.innerHeight,At=K/2;O.top<At?(n(17,r="top"),n(16,o=O.top)):(n(17,r="bottom"),n(16,o=K-O.bottom)),o<Ht&&n(16,o=Ht),localStorage.setItem("wnj:origin",r),localStorage.setItem("wnj:ypos",o.toString())}}function Fc(O){ue[O?"unshift":"push"](()=>{b=O,n(6,b)})}function Yc(){v=this.value,n(7,v)}function Jc(){B=No(this),n(8,B),n(15,M)}function Qc(O){ue[O?"unshift":"push"](()=>{d=O,n(5,d)})}function Xc(){p=this.value,n(2,p)}function tl(O){ue[O?"unshift":"push"](()=>{f=O,n(4,f)})}return t.$$set=O=>{"accent"in O&&n(0,u=O.accent),"position"in O&&n(34,w=O.position),"right"in O&&n(1,z=O.right)},t.$$.update=()=>{t.$$.dirty[0]&8|t.$$.dirty[1]&8&&n(17,r=l?"bottom":localStorage.getItem("wnj:origin")||w),t.$$.dirty[0]&8&&n(16,o=l?Ht:parseInt(localStorage.getItem("wnj:ypos")||"0")||Ht),t.$$.dirty[1]&16&&n(18,i=x==="justopened"||x==="opened"),t.$$.dirty[0]&1|t.$$.dirty[1]&32&&n(20,s=G?"tw-cursor-grabbing tw-outline-dashed tw-outline-"+u+"-500 tw-outline-1 tw-outline-offset-4":"tw-outline-none"),t.$$.dirty[0]&4&&n(19,c=p&&(p.match(qe)||p.match(io)))},[u,z,p,l,f,d,b,v,B,I,A,R,Y,_,S,M,o,r,i,c,s,a,jt,st,Mt,je,Me,zc,Kc,Dc,Vc,Wc,Zc,Gc,w,x,G,Fc,Yc,Jc,Qc,Xc,tl]}class jc extends Gn{constructor(e){super(),Zn(this,e,qc,$c,ze,{accent:0,position:34,right:1},null,[-1,-1,-1])}}const Ln=window;Ln.destroyWnj=()=>{setTimeout(()=>{Mc.$destroy()},1)};const Cn=document.createElement("div");Cn.style.zIndex="90000",document.body.appendChild(Cn);const Rn=document.createElement("div");Rn.id="wnj";const mo=document.createElement("style");mo.innerHTML=zt;const Eo=Cn.attachShadow({mode:"open"});Eo.appendChild(Rn),Eo.appendChild(mo);const Mc=new jc({target:Rn,props:{accent:((xo=Ln.wnjParams)==null?void 0:xo.accent)||"cyan",position:((vo=Ln.wnjParams)==null?void 0:vo.position)==="bottom"?"bottom":"top"}})})();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "window.nostr.js",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "type": "module",
5
5
  "main": "dist/window.nostr.js",
6
6
  "devDependencies": {
package/src/App.svelte CHANGED
@@ -53,12 +53,14 @@
53
53
  let state: 'opened' | 'closed' | 'justopened' | 'justclosed' = 'closed'
54
54
  let bunkerPointer: BunkerPointer | null
55
55
  let resolveBunker: (_: BunkerSigner) => void
56
+ let rejectBunker: (_: string) => void
56
57
  let bunker: Promise<BunkerSigner>
57
58
  let connecting: boolean
58
- let longConnecting = false
59
- let cancelConnection = false
59
+ let connected: boolean
60
+ let takingTooLong = false
60
61
  let creating: boolean
61
- let connected: null | {
62
+ let errorMessage: string
63
+ let identity: null | {
62
64
  pubkey: string
63
65
  npub: string
64
66
  name?: string
@@ -67,6 +69,10 @@
67
69
  }
68
70
  let metadataSub: SubCloser | null
69
71
  let providers: BunkerProfile[] = []
72
+ const connectBunkerError =
73
+ 'We could not connect to a NIP-46 bunker with that url, are you sure it is set up correctly?'
74
+ const connectNip05Error =
75
+ 'We were not able to connect using this address. For it to work it has to come from a NIP-46 provider.'
70
76
 
71
77
  const BASE_YPOS = 20
72
78
  export let right = 20
@@ -120,31 +126,40 @@
120
126
  delayedUpdateState()
121
127
  }
122
128
 
129
+ function connectOrOpen() {
130
+ if (bunkerPointer && !connected) {
131
+ connect()
132
+ return
133
+ }
134
+ open()
135
+ }
136
+
123
137
  reset()
124
138
 
125
139
  let windowNostr = {
126
140
  isWnj: true,
127
141
  async getPublicKey(): Promise<string> {
142
+ if (bunkerPointer) return bunkerPointer.pubkey
128
143
  if (!connecting && !connected) open()
129
144
  return (await bunker).bp.pubkey
130
145
  },
131
146
  async signEvent(event: NostrEvent): Promise<VerifiedEvent> {
132
- if (!connecting && !connected) open()
147
+ if (!connecting && !connected) connectOrOpen()
133
148
  return (await bunker).signEvent(event)
134
149
  },
135
150
  async getRelays(): Promise<{
136
151
  [url: string]: {read: boolean; write: boolean}
137
152
  }> {
138
- if (!connecting && !connected) open()
153
+ if (!connecting && !connected) connectOrOpen()
139
154
  return (await bunker).getRelays()
140
155
  },
141
156
  nip04: {
142
157
  async encrypt(pubkey: string, plaintext: string): Promise<string> {
143
- if (!connecting && !connected) open()
158
+ if (!connecting && !connected) connectOrOpen()
144
159
  return (await bunker).nip04Encrypt(pubkey, plaintext)
145
160
  },
146
161
  async decrypt(pubkey: string, ciphertext: string): Promise<string> {
147
- if (!connecting && !connected) open()
162
+ if (!connecting && !connected) connectOrOpen()
148
163
  return (await bunker).nip04Decrypt(pubkey, ciphertext)
149
164
  }
150
165
  }
@@ -153,22 +168,27 @@
153
168
  function reset() {
154
169
  close()
155
170
  bunkerPointer = null
156
- bunker = new Promise(resolve => {
171
+ bunker = new Promise((resolve, reject) => {
157
172
  resolveBunker = resolve
173
+ rejectBunker = reject
158
174
  })
175
+ identity = null
159
176
  connecting = false
177
+ takingTooLong = false
160
178
  creating = false
161
- connected = null
179
+ connected = false
162
180
  metadataSub = null
181
+ errorMessage = ''
163
182
  }
164
183
 
165
184
  onMount(() => {
166
185
  let data = localStorage.getItem('wnj:bunkerPointer')
167
186
  if (data) {
168
187
  bunkerPointer = JSON.parse(data)
169
- connect(
170
- new BunkerSigner(clientSecret, bunkerPointer!, bunkerSignerParams)
171
- )
188
+ // we have a pointer, which means we can get the public key right away
189
+ // but we will only try to connect when any other method is called on window.nostr
190
+
191
+ identify()
172
192
  }
173
193
 
174
194
  if (win.nostr && !win.nostr.isWnj) {
@@ -219,22 +239,37 @@
219
239
 
220
240
  async function handleConnect(ev: SubmitEvent) {
221
241
  ev.preventDefault()
222
- bunkerPointer = await parseBunkerInput(bunkerInput.value)
223
- if (!bunkerPointer) {
224
- bunkerInput.setCustomValidity(
225
- 'invalid NIP-05 "name@domain.com" address or bunker:// URI'
226
- )
227
- return
228
- }
242
+ try {
243
+ bunkerPointer = await parseBunkerInput(bunkerInput.value)
244
+ if (!bunkerPointer) {
245
+ if (bunkerInput.value.match(BUNKER_REGEX)) {
246
+ errorMessage = connectBunkerError
247
+ } else {
248
+ errorMessage = connectNip05Error
249
+ }
250
+ return
251
+ }
229
252
 
230
- bunkerInput.setCustomValidity('')
231
- connect(new BunkerSigner(clientSecret, bunkerPointer!, bunkerSignerParams))
253
+ bunkerInput.setCustomValidity('')
254
+ errorMessage = ''
255
+ await connect()
256
+
257
+ // since we are connecting right now after the user has typed stuff
258
+ // wait until the connection has succeeded before loading user data
259
+ identify()
260
+ } catch (error) {
261
+ if (bunkerInput.value.match(BUNKER_REGEX)) {
262
+ errorMessage = connectBunkerError
263
+ } else {
264
+ errorMessage = connectNip05Error
265
+ }
266
+ connecting = false
267
+ }
232
268
  }
233
269
 
234
270
  async function handleDisconnect(ev: MouseEvent) {
235
271
  ev.preventDefault()
236
272
  localStorage.removeItem('wnj:bunkerPointer')
237
- if (win.isWnj) delete win.nostr
238
273
  reset()
239
274
  }
240
275
 
@@ -269,6 +304,8 @@
269
304
  open()
270
305
  creating = false
271
306
 
307
+ bunkerPointer = bunker.bp
308
+ identify()
272
309
  connect(bunker)
273
310
  }
274
311
 
@@ -283,64 +320,67 @@
283
320
  }, 500)
284
321
 
285
322
  function handleAbortConnection() {
286
- longConnecting = false
323
+ takingTooLong = false
287
324
  connecting = false
288
- cancelConnection = true
289
- // TODO: Effectively abort the connection
325
+ rejectBunker('connection aborted')
326
+ reset()
290
327
  }
291
328
 
292
- async function connect(bunker: BunkerSigner) {
293
- let connectionTimeout: number
329
+ async function connect(b: BunkerSigner | undefined = undefined) {
330
+ b = b || new BunkerSigner(clientSecret, bunkerPointer!, bunkerSignerParams)
331
+ connecting = true
294
332
 
295
- function allowCancel() {
296
- longConnecting = true
333
+ let connectionTimeout = setTimeout(() => {
334
+ takingTooLong = true
297
335
  opened = true
336
+ }, 5000)
337
+
338
+ try {
339
+ await b.connect()
340
+ connected = true
341
+ localStorage.setItem('wnj:bunkerPointer', JSON.stringify(bunkerPointer))
342
+ close()
343
+ resolveBunker(b)
344
+ } catch (err: any) {
345
+ rejectBunker(err?.message || String(err))
346
+ } finally {
347
+ // this still gets executed even if we return above
298
348
  clearTimeout(connectionTimeout)
349
+ connecting = false
350
+ takingTooLong = false
299
351
  }
352
+ }
300
353
 
301
- connecting = true
302
- connectionTimeout = setTimeout(allowCancel, 5000)
303
-
304
- await bunker.connect()
354
+ function identify() {
355
+ let pubkey = bunkerPointer.pubkey
305
356
 
306
- clearTimeout(connectionTimeout)
307
- bunkerPointer = bunker.bp
308
-
309
- // set this so the floating thing will update
310
- connected = {
311
- pubkey: bunker.bp.pubkey,
312
- npub: npubEncode(bunker.bp.pubkey),
357
+ identity = {
358
+ pubkey: pubkey,
359
+ npub: npubEncode(pubkey),
313
360
  event: null
314
361
  }
315
362
 
316
- localStorage.setItem('wnj:bunkerPointer', JSON.stringify(bunkerPointer))
317
-
318
- // load metadata
319
363
  metadataSub = pool.subscribeMany(
320
364
  [
321
365
  'wss://purplepag.es',
322
366
  'wss://relay.snort.social',
323
367
  'wss://relay.nos.social'
324
368
  ],
325
- [{kinds: [0], authors: [bunker.bp.pubkey]}],
369
+ [{kinds: [0], authors: [pubkey]}],
326
370
  {
327
371
  onevent(evt) {
328
- if ((connected!.event?.created_at || 0) >= evt.created_at) return
372
+ if ((identity!.event?.created_at || 0) >= evt.created_at) return
329
373
  try {
330
374
  let {name, picture} = JSON.parse(evt.content)
331
- connected!.event = evt
332
- connected!.name = name
333
- connected!.picture = picture
375
+ identity!.event = evt
376
+ identity!.name = name
377
+ identity!.picture = picture
334
378
  } catch (err) {
335
379
  /***/
336
380
  }
337
381
  }
338
382
  }
339
383
  )
340
- connecting = false
341
- longConnecting = false
342
- close()
343
- resolveBunker(bunker)
344
384
  }
345
385
 
346
386
  function handleMouseDown(ev: MouseEvent) {
@@ -411,7 +451,7 @@
411
451
  <!-- svelte-ignore a11y-no-static-element-interactions -->
412
452
  <div
413
453
  class="tw-text-white tw-font-sans draggable tw-animate-fadein"
414
- class:tw-cursor-pointer={!connected && !opened}
454
+ class:tw-cursor-pointer={!identity && !opened}
415
455
  style="position: fixed; {opened && $mobileMode
416
456
  ? 'width: 100%;'
417
457
  : ''}; right: {opened && $mobileMode
@@ -433,21 +473,21 @@
433
473
  Connecting to bunker
434
474
  <Spinner />
435
475
  </div>
436
- {:else if !connected}
476
+ {:else if !identity}
437
477
  Connect with Nostr
438
478
  {:else}
439
479
  <div class="tw-flex tw-items-center">
440
- {#if connected.picture}
480
+ {#if identity.picture}
441
481
  <img
442
- src={connected.picture}
482
+ src={identity.picture}
443
483
  alt=""
444
484
  class="tw-w-5 tw-h-5 tw-rounded-full tw-mr-2"
445
485
  />
446
486
  {:else}
447
487
 
448
488
  {/if}
449
- {connected.name ||
450
- connected.npub.slice(0, 7) + '…' + connected.npub.slice(-4)}
489
+ {identity.name ||
490
+ identity.npub.slice(0, 7) + '…' + identity.npub.slice(-4)}
451
491
  </div>
452
492
  {/if}
453
493
  </div>
@@ -510,7 +550,7 @@
510
550
  </div>
511
551
 
512
552
  <!-- Login view ################### -->
513
- {:else if !connected}
553
+ {:else if !identity}
514
554
  <div class="tw-text-lg tw-text-center">
515
555
  How do you want to connect to Nostr?
516
556
  </div>
@@ -524,6 +564,13 @@
524
564
  autofocus
525
565
  disabled={connecting}
526
566
  />
567
+ {#if errorMessage}
568
+ <div
569
+ class="tw-my-2 tw-p-2 tw-text-sm tw-leading-4 tw-text-red-400 tw-bg-yellow-100 tw-rounded"
570
+ >
571
+ {errorMessage}
572
+ </div>
573
+ {/if}
527
574
  <button
528
575
  class="tw-flex tw-w-full tw-mt-4 tw-px-2 tw-py-1 tw-text-lg tw-rounded tw-border-0 tw-bg-{accent}-900 hover:tw-bg-{accent}-950 tw-hover:bg-indigo-900 tw-cursor-pointer tw-text-white disabled:tw-bg-neutral-400 disabled:tw-text-neutral-200 disabled:tw-cursor-default tw-items-center tw-justify-center"
529
576
  disabled={!bunkerInputValueIsGood || connecting}
@@ -535,7 +582,7 @@
535
582
  Connect »
536
583
  {/if}
537
584
  </button>
538
- {#if connecting && longConnecting}
585
+ {#if connecting && takingTooLong}
539
586
  <div class="tw-mt-6 tw-text-center tw-text-sm tw-leading-3">
540
587
  Waiting too much?
541
588
  <button
@@ -556,35 +603,35 @@
556
603
  {/if}
557
604
 
558
605
  <!-- Connected view ################### -->
559
- {:else if connected}
606
+ {:else if identity}
560
607
  <div class="tw-text-center">
561
608
  <div class="tw-text-sm tw-mb-4">You are connected to Nostr as</div>
562
609
  <a
563
610
  target="_blank"
564
- href={'https://nosta.me/' + connected.npub}
611
+ href={'https://nosta.me/' + identity.npub}
565
612
  class="tw-text-white tw-no-underline tw-group"
566
613
  >
567
- {#if connected.picture || connected.name}
614
+ {#if identity.picture || identity.name}
568
615
  <div
569
616
  class="tw-flex tw-items-center tw-justify-center tw-gap-2 tw-mb-2"
570
617
  >
571
- {#if connected.picture}
618
+ {#if identity.picture}
572
619
  <img
573
- src={connected.picture}
620
+ src={identity.picture}
574
621
  alt=""
575
622
  class="tw-w-10 tw-h-10 tw-rounded-full tw-border-solid tw-border-2 tw-border-transparent group-hover:tw-border-{accent}-100"
576
623
  />
577
624
  {/if}
578
- {#if connected.name}
625
+ {#if identity.name}
579
626
  <div
580
627
  class="tw-text-3xl group-hover:tw-underline tw-decoration-2 tw-underline-offset-4"
581
628
  >
582
- {connected.name}
629
+ {identity.name}
583
630
  </div>
584
631
  {/if}
585
632
  </div>
586
633
  {/if}
587
- <div class="tw-block tw-break-all">{connected.npub}</div>
634
+ <div class="tw-block tw-break-all">{identity.npub}</div>
588
635
  </a>
589
636
  </div>
590
637
  <button