window.nostr.js 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -4,4 +4,12 @@ a small `<script>` you can drop in any page that already uses [NIP-07](https://n
4
4
 
5
5
  ## How to use it
6
6
 
7
- Include `<script src="https://cdn.jsdelivr.net/npm/window.nostr.js@latest/dist/window.nostr.js"></script>` in your HTML and proceed to use [`window.nostr`](https://nips.nostr.com/7) normally.
7
+ Include `<script src="https://unpkg.com/window.nostr.js/dist/window.nostr.js"></script>` in your HTML and proceed to use [`window.nostr`](https://nips.nostr.com/7) normally.
8
+
9
+ ## Bookmarklet
10
+
11
+ If a website has opted to not include this, but you like it, you can still use it on the website. Just add this to your browser bookmarks and click on it to load the widget on any website:
12
+
13
+ ```
14
+ javascript:void((function(){var%20e=document.createElement('script');e.setAttribute('src','https://unpkg.com/window.nostr.js/dist/window.nostr.js');document.body.appendChild(e)})())
15
+ ```
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-De39WRon.js"></script>
7
+ <script type="module" crossorigin src="/assets/index-BbdZ99Nt.js"></script>
8
8
  </head>
9
9
  <body
10
10
  style="
@@ -1,2 +1,2 @@
1
- var wc=Object.defineProperty;var pc=(Tt,G,xt)=>G in Tt?wc(Tt,G,{enumerable:!0,configurable:!0,writable:!0,value:xt}):Tt[G]=xt;var m=(Tt,G,xt)=>(pc(Tt,typeof G!="symbol"?G+"":G,xt),xt);(function(){"use strict";var zr,Vr;const Tt='.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-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-80{width:20rem}.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}.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-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-transition-all{transition-property:all;transition-timing-function:cubic-bezier(.4,0,.2,1);transition-duration:.15s}.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}';function G(){}function xt(t){return t()}function bn(){return Object.create(null)}function Ht(t){t.forEach(xt)}function yn(t){return typeof t=="function"}function Gr(t,e){return t!=t?e==e:t!==e||t&&typeof t=="object"||typeof t=="function"}let ae;function ue(t,e){return t===e?!0:(ae||(ae=document.createElement("a")),ae.href=e,t===ae.href)}function Fr(t){return Object.keys(t).length===0}const Jr=typeof window<"u"?window:typeof globalThis<"u"?globalThis:global;function N(t,e){t.appendChild(e)}function M(t,e,n){t.insertBefore(e,n||null)}function q(t){t.parentNode&&t.parentNode.removeChild(t)}function Yr(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 tt(t){return document.createTextNode(t)}function D(){return tt(" ")}function ct(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 Qr(t){return Array.from(t.childNodes)}function fe(t,e){e=""+e,t.data!==e&&(t.data=e)}function qt(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 Xr(t){const e=t.querySelector(":checked");return e&&e.__value}function xn(t,e,n){t.classList.toggle(e,!!n)}let Qt;function Xt(t){Qt=t}function to(){if(!Qt)throw new Error("Function called outside component initialization");return Qt}function eo(t){to().$$.on_mount.push(t)}const Kt=[],de=[];let Mt=[];const En=[],no=Promise.resolve();let Oe=!1;function ro(){Oe||(Oe=!0,no.then(vn))}function he(t){Mt.push(t)}const Te=new Set;let jt=0;function vn(){if(jt!==0)return;const t=Qt;do{try{for(;jt<Kt.length;){const e=Kt[jt];jt++,Xt(e),oo(e.$$)}}catch(e){throw Kt.length=0,jt=0,e}for(Xt(null),Kt.length=0,jt=0;de.length;)de.pop()();for(let e=0;e<Mt.length;e+=1){const n=Mt[e];Te.has(n)||(Te.add(n),n())}Mt.length=0}while(Kt.length);for(;En.length;)En.pop()();Oe=!1,Te.clear(),Xt(t)}function oo(t){if(t.fragment!==null){t.update(),Ht(t.before_update);const e=t.dirty;t.dirty=[-1],t.fragment&&t.fragment.p(t.ctx,e),t.after_update.forEach(he)}}function so(t){const e=[],n=[];Mt.forEach(r=>t.indexOf(r)===-1?e.push(r):n.push(r)),n.forEach(r=>r()),Mt=e}const io=new Set;function co(t,e){t&&t.i&&(io.delete(t),t.i(e))}function _n(t){return(t==null?void 0:t.length)!==void 0?t:Array.from(t)}function lo(t,e,n){const{fragment:r,after_update:o}=t.$$;r&&r.m(e,n),he(()=>{const s=t.$$.on_mount.map(xt).filter(yn);t.$$.on_destroy?t.$$.on_destroy.push(...s):Ht(s),t.$$.on_mount=[]}),o.forEach(he)}function ao(t,e){const n=t.$$;n.fragment!==null&&(so(n.after_update),Ht(n.on_destroy),n.fragment&&n.fragment.d(e),n.on_destroy=n.fragment=null,n.ctx=[])}function uo(t,e){t.$$.dirty[0]===-1&&(Kt.push(t),ro(),t.$$.dirty.fill(0)),t.$$.dirty[e/31|0]|=1<<e%31}function fo(t,e,n,r,o,s,i=null,c=[-1]){const l=Qt;Xt(t);const a=t.$$={fragment:null,ctx:[],props:s,update:G,not_equal:o,bound:bn(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(e.context||(l?l.$$.context:[])),callbacks:bn(),dirty:c,skip_bound:!1,root:e.target||l.$$.root};i&&i(a.root);let f=!1;if(a.ctx=n?n(t,e.props||{},(u,h,...w)=>{const p=w.length?w[0]:h;return a.ctx&&o(a.ctx[u],a.ctx[u]=p)&&(!a.skip_bound&&a.bound[u]&&a.bound[u](p),f&&uo(t,u)),h}):[],a.update(),f=!0,Ht(a.before_update),a.fragment=r?r(a.ctx):!1,e.target){if(e.hydrate){const u=Qr(e.target);a.fragment&&a.fragment.l(u),u.forEach(q)}else a.fragment&&a.fragment.c();e.intro&&co(t.$$.fragment),lo(t,e.target,e.anchor),vn()}Xt(l)}class ho{constructor(){m(this,"$$");m(this,"$$set")}$destroy(){ao(this,1),this.$destroy=G}$on(e,n){if(!yn(n))return G;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&&!Fr(e)&&(this.$$.skip_bound=!0,this.$$set(e),this.$$.skip_bound=!1)}}const wo="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(wo);function po(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var Ie={exports:{}};function Sn(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,s,i,c,l;function a(){const u=Date.now()-c;if(u<e&&u>=0)i=setTimeout(a,e-u);else if(i=void 0,!r){const h=o,w=s;o=void 0,s=void 0,l=t.apply(h,w)}}const f=function(...u){if(o&&this!==o)throw new Error("Debounced method called with different contexts.");o=this,s=u,c=Date.now();const h=r&&!i;if(i||(i=setTimeout(a,e)),h){const w=o,p=s;o=void 0,s=void 0,l=t.apply(w,p)}return l};return f.clear=()=>{i&&(clearTimeout(i),i=void 0)},f.flush=()=>{if(!i)return;const u=o,h=s;o=void 0,s=void 0,l=t.apply(u,h),clearTimeout(i),i=void 0},f}Ie.exports.debounce=Sn,Ie.exports=Sn;var go=Ie.exports;const bo=po(go),Ne=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */const kn=t=>t instanceof Uint8Array,Pe=t=>new DataView(t.buffer,t.byteOffset,t.byteLength),ut=(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 yo=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function J(t){if(!kn(t))throw new Error("Uint8Array expected");let e="";for(let n=0;n<t.length;n++)e+=yo[t[n]];return e}function Ue(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,s=t.slice(o,o+2),i=Number.parseInt(s,16);if(Number.isNaN(i)||i<0)throw new Error("Invalid byte sequence");n[r]=i}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 An(t){if(typeof t=="string"&&(t=mo(t)),!kn(t))throw new Error(`expected Uint8Array, got ${typeof t}`);return t}let xo=class{clone(){return this._cloneInto()}};function Bn(t){const e=r=>t().update(An(r)).digest(),n=t();return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=()=>t(),e}function Eo(t=32){if(Ne&&typeof Ne.getRandomValues=="function")return Ne.getRandomValues(new Uint8Array(t));throw new Error("crypto.getRandomValues must be defined")}function $n(t){if(!Number.isSafeInteger(t)||t<0)throw new Error(`Wrong positive integer: ${t}`)}function On(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 vo(t){if(typeof t!="function"||typeof t.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");$n(t.outputLen),$n(t.blockLen)}function we(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 _o(t,e){On(t);const n=e.outputLen;if(t.length<n)throw new Error(`digestInto() expects output buffer of length at least ${n}`)}const Le=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Tn=t=>t instanceof Uint8Array,Ce=t=>new DataView(t.buffer,t.byteOffset,t.byteLength),ft=(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 So(t){if(typeof t!="string")throw new Error(`utf8ToBytes expected string, got ${typeof t}`);return new Uint8Array(new TextEncoder().encode(t))}function Re(t){if(typeof t=="string"&&(t=So(t)),!Tn(t))throw new Error(`expected Uint8Array, got ${typeof t}`);return t}function ko(...t){const e=new Uint8Array(t.reduce((r,o)=>r+o.length,0));let n=0;return t.forEach(r=>{if(!Tn(r))throw new Error("Uint8Array expected");e.set(r,n),n+=r.length}),e}class In{clone(){return this._cloneInto()}}function Ao(t){const e=r=>t().update(Re(r)).digest(),n=t();return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=()=>t(),e}function Nn(t=32){if(Le&&typeof Le.getRandomValues=="function")return Le.getRandomValues(new Uint8Array(t));throw new Error("crypto.getRandomValues must be defined")}function Bo(t,e,n,r){if(typeof t.setBigUint64=="function")return t.setBigUint64(e,n,r);const o=BigInt(32),s=BigInt(4294967295),i=Number(n>>o&s),c=Number(n&s),l=r?4:0,a=r?0:4;t.setUint32(e+l,i,r),t.setUint32(e+a,c,r)}let $o=class extends In{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=Ce(this.buffer)}update(e){we(this);const{view:n,buffer:r,blockLen:o}=this;e=Re(e);const s=e.length;for(let i=0;i<s;){const c=Math.min(o-this.pos,s-i);if(c===o){const l=Ce(e);for(;o<=s-i;i+=o)this.process(l,i);continue}r.set(e.subarray(i,i+c),this.pos),this.pos+=c,i+=c,this.pos===o&&(this.process(n,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){we(this),_o(e,this),this.finished=!0;const{buffer:n,view:r,blockLen:o,isLE:s}=this;let{pos:i}=this;n[i++]=128,this.buffer.subarray(i).fill(0),this.padOffset>o-i&&(this.process(r,0),i=0);for(let u=i;u<o;u++)n[u]=0;Bo(r,o-8,BigInt(this.length*8),s),this.process(r,0);const c=Ce(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],s)}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:s,destroyed:i,pos:c}=this;return e.length=o,e.pos=c,e.finished=s,e.destroyed=i,o%n&&e.buffer.set(r),e}};const Oo=(t,e,n)=>t&e^~t&n,To=(t,e,n)=>t&e^t&n^e&n,Io=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]),Et=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),vt=new Uint32Array(64);let No=class extends $o{constructor(){super(64,32,8,!1),this.A=Et[0]|0,this.B=Et[1]|0,this.C=Et[2]|0,this.D=Et[3]|0,this.E=Et[4]|0,this.F=Et[5]|0,this.G=Et[6]|0,this.H=Et[7]|0}get(){const{A:e,B:n,C:r,D:o,E:s,F:i,G:c,H:l}=this;return[e,n,r,o,s,i,c,l]}set(e,n,r,o,s,i,c,l){this.A=e|0,this.B=n|0,this.C=r|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=c|0,this.H=l|0}process(e,n){for(let u=0;u<16;u++,n+=4)vt[u]=e.getUint32(n,!1);for(let u=16;u<64;u++){const h=vt[u-15],w=vt[u-2],p=ft(h,7)^ft(h,18)^h>>>3,d=ft(w,17)^ft(w,19)^w>>>10;vt[u]=d+vt[u-7]+p+vt[u-16]|0}let{A:r,B:o,C:s,D:i,E:c,F:l,G:a,H:f}=this;for(let u=0;u<64;u++){const h=ft(c,6)^ft(c,11)^ft(c,25),w=f+h+Oo(c,l,a)+Io[u]+vt[u]|0,d=(ft(r,2)^ft(r,13)^ft(r,22))+To(r,o,s)|0;f=a,a=l,l=c,c=i+w|0,i=s,s=o,o=r,r=w+d|0}r=r+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,c=c+this.E|0,l=l+this.F|0,a=a+this.G|0,f=f+this.H|0,this.set(r,o,s,i,c,l,a,f)}roundClean(){vt.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};const He=Ao(()=>new No);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Pn=BigInt(0),pe=BigInt(1),Po=BigInt(2),ge=t=>t instanceof Uint8Array,Uo=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function zt(t){if(!ge(t))throw new Error("Uint8Array expected");let e="";for(let n=0;n<t.length;n++)e+=Uo[t[n]];return e}function Un(t){const e=t.toString(16);return e.length&1?`0${e}`:e}function qe(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);return BigInt(t===""?"0":`0x${t}`)}function Vt(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,s=t.slice(o,o+2),i=Number.parseInt(s,16);if(Number.isNaN(i)||i<0)throw new Error("Invalid byte sequence");n[r]=i}return n}function et(t){return qe(zt(t))}function Ke(t){if(!ge(t))throw new Error("Uint8Array expected");return qe(zt(Uint8Array.from(t).reverse()))}function _t(t,e){return Vt(t.toString(16).padStart(e*2,"0"))}function Me(t,e){return _t(t,e).reverse()}function Lo(t){return Vt(Un(t))}function F(t,e,n){let r;if(typeof e=="string")try{r=Vt(e)}catch(s){throw new Error(`${t} must be valid hex string, got "${e}". Cause: ${s}`)}else if(ge(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 It(...t){const e=new Uint8Array(t.reduce((r,o)=>r+o.length,0));let n=0;return t.forEach(r=>{if(!ge(r))throw new Error("Uint8Array expected");e.set(r,n),n+=r.length}),e}function Co(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 Ro(t){if(typeof t!="string")throw new Error(`utf8ToBytes expected string, got ${typeof t}`);return new Uint8Array(new TextEncoder().encode(t))}function Ho(t){let e;for(e=0;t>Pn;t>>=pe,e+=1);return e}function qo(t,e){return t>>BigInt(e)&pe}const Ko=(t,e,n)=>t|(n?pe:Pn)<<BigInt(e),je=t=>(Po<<BigInt(t-1))-pe,ze=t=>new Uint8Array(t),Ln=t=>Uint8Array.from(t);function Cn(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=ze(t),o=ze(t),s=0;const i=()=>{r.fill(1),o.fill(0),s=0},c=(...u)=>n(o,r,...u),l=(u=ze())=>{o=c(Ln([0]),u),r=c(),u.length!==0&&(o=c(Ln([1]),u),r=c())},a=()=>{if(s++>=1e3)throw new Error("drbg: tried 1000 values");let u=0;const h=[];for(;u<e;){r=c();const w=r.slice();h.push(w),u+=r.length}return It(...h)};return(u,h)=>{i(),l(u);let w;for(;!(w=h(a()));)l();return i(),w}}const Mo={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 te(t,e,n={}){const r=(o,s,i)=>{const c=Mo[s];if(typeof c!="function")throw new Error(`Invalid validator "${s}", expected function`);const l=t[o];if(!(i&&l===void 0)&&!c(l,t))throw new Error(`Invalid param ${String(o)}=${l} (${typeof l}), expected ${s}`)};for(const[o,s]of Object.entries(e))r(o,s,!1);for(const[o,s]of Object.entries(n))r(o,s,!0);return t}const jo=Object.freeze(Object.defineProperty({__proto__:null,bitGet:qo,bitLen:Ho,bitMask:je,bitSet:Ko,bytesToHex:zt,bytesToNumberBE:et,bytesToNumberLE:Ke,concatBytes:It,createHmacDrbg:Cn,ensureBytes:F,equalBytes:Co,hexToBytes:Vt,hexToNumber:qe,numberToBytesBE:_t,numberToBytesLE:Me,numberToHexUnpadded:Un,numberToVarBytesBE:Lo,utf8ToBytes:Ro,validateObject:te},Symbol.toStringTag,{value:"Module"}));/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const W=BigInt(0),j=BigInt(1),Nt=BigInt(2),zo=BigInt(3),Ve=BigInt(4),Rn=BigInt(5),Hn=BigInt(8);BigInt(9),BigInt(16);function Z(t,e){const n=t%e;return n>=W?n:e+n}function Vo(t,e,n){if(n<=W||e<W)throw new Error("Expected power/modulo > 0");if(n===j)return W;let r=j;for(;e>W;)e&j&&(r=r*t%n),t=t*t%n,e>>=j;return r}function ot(t,e,n){let r=t;for(;e-- >W;)r*=r,r%=n;return r}function De(t,e){if(t===W||e<=W)throw new Error(`invert: expected positive integers, got n=${t} mod=${e}`);let n=Z(t,e),r=e,o=W,s=j;for(;n!==W;){const c=r/n,l=r%n,a=o-s*c;r=n,n=l,o=s,s=a}if(r!==j)throw new Error("invert: does not exist");return Z(o,e)}function Do(t){const e=(t-j)/Nt;let n,r,o;for(n=t-j,r=0;n%Nt===W;n/=Nt,r++);for(o=Nt;o<t&&Vo(o,e,t)!==t-j;o++);if(r===1){const i=(t+j)/Ve;return function(l,a){const f=l.pow(a,i);if(!l.eql(l.sqr(f),a))throw new Error("Cannot find square root");return f}}const s=(n+j)/Nt;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,s),h=c.pow(l,n);for(;!c.eql(h,c.ONE);){if(c.eql(h,c.ZERO))return c.ZERO;let w=1;for(let d=c.sqr(h);w<a&&!c.eql(d,c.ONE);w++)d=c.sqr(d);const p=c.pow(f,j<<BigInt(a-w-1));f=c.sqr(p),u=c.mul(u,p),h=c.mul(h,f),a=w}return u}}function Wo(t){if(t%Ve===zo){const e=(t+j)/Ve;return function(r,o){const s=r.pow(o,e);if(!r.eql(r.sqr(s),o))throw new Error("Cannot find square root");return s}}if(t%Hn===Rn){const e=(t-Rn)/Hn;return function(r,o){const s=r.mul(o,Nt),i=r.pow(s,e),c=r.mul(o,i),l=r.mul(r.mul(c,Nt),i),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 Do(t)}const Zo=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Go(t){const e={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},n=Zo.reduce((r,o)=>(r[o]="function",r),e);return te(t,n)}function Fo(t,e,n){if(n<W)throw new Error("Expected power > 0");if(n===W)return t.ONE;if(n===j)return e;let r=t.ONE,o=e;for(;n>W;)n&j&&(r=t.mul(r,o)),o=t.sqr(o),n>>=j;return r}function Jo(t,e){const n=new Array(e.length),r=e.reduce((s,i,c)=>t.is0(i)?s:(n[c]=s,t.mul(s,i)),t.ONE),o=t.inv(r);return e.reduceRight((s,i,c)=>t.is0(i)?s:(n[c]=t.mul(s,n[c]),t.mul(s,i)),o),n}function qn(t,e){const n=e!==void 0?e:t.toString(2).length,r=Math.ceil(n/8);return{nBitLength:n,nByteLength:r}}function Yo(t,e,n=!1,r={}){if(t<=W)throw new Error(`Expected Field ORDER > 0, got ${t}`);const{nBitLength:o,nByteLength:s}=qn(t,e);if(s>2048)throw new Error("Field lengths over 2048 bytes are not supported");const i=Wo(t),c=Object.freeze({ORDER:t,BITS:o,BYTES:s,MASK:je(o),ZERO:W,ONE:j,create:l=>Z(l,t),isValid:l=>{if(typeof l!="bigint")throw new Error(`Invalid field element: expected bigint, got ${typeof l}`);return W<=l&&l<t},is0:l=>l===W,isOdd:l=>(l&j)===j,neg:l=>Z(-l,t),eql:(l,a)=>l===a,sqr:l=>Z(l*l,t),add:(l,a)=>Z(l+a,t),sub:(l,a)=>Z(l-a,t),mul:(l,a)=>Z(l*a,t),pow:(l,a)=>Fo(c,l,a),div:(l,a)=>Z(l*De(a,t),t),sqrN:l=>l*l,addN:(l,a)=>l+a,subN:(l,a)=>l-a,mulN:(l,a)=>l*a,inv:l=>De(l,t),sqrt:r.sqrt||(l=>i(c,l)),invertBatch:l=>Jo(c,l),cmov:(l,a,f)=>f?a:l,toBytes:l=>n?Me(l,s):_t(l,s),fromBytes:l=>{if(l.length!==s)throw new Error(`Fp.fromBytes: expected ${s}, got ${l.length}`);return n?Ke(l):et(l)}});return Object.freeze(c)}function Kn(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 Mn(t){const e=Kn(t);return e+Math.ceil(e/2)}function Qo(t,e,n=!1){const r=t.length,o=Kn(e),s=Mn(e);if(r<16||r<s||r>1024)throw new Error(`expected ${s}-1024 bytes of input, got ${r}`);const i=n?et(t):Ke(t),c=Z(i,e-j)+j;return n?Me(c,o):_t(c,o)}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Xo=BigInt(0),We=BigInt(1);function ts(t,e){const n=(o,s)=>{const i=s.negate();return o?i:s},r=o=>{const s=Math.ceil(e/o)+1,i=2**(o-1);return{windows:s,windowSize:i}};return{constTimeNegate:n,unsafeLadder(o,s){let i=t.ZERO,c=o;for(;s>Xo;)s&We&&(i=i.add(c)),c=c.double(),s>>=We;return i},precomputeWindow(o,s){const{windows:i,windowSize:c}=r(s),l=[];let a=o,f=a;for(let u=0;u<i;u++){f=a,l.push(f);for(let h=1;h<c;h++)f=f.add(a),l.push(f);a=f.double()}return l},wNAF(o,s,i){const{windows:c,windowSize:l}=r(o);let a=t.ZERO,f=t.BASE;const u=BigInt(2**o-1),h=2**o,w=BigInt(o);for(let p=0;p<c;p++){const d=p*l;let g=Number(i&u);i>>=w,g>l&&(g-=h,i+=We);const b=d,y=d+Math.abs(g)-1,E=p%2!==0,A=g<0;g===0?f=f.add(n(E,s[b])):a=a.add(n(A,s[y]))}return{p:a,f}},wNAFCached(o,s,i,c){const l=o._WINDOW_SIZE||1;let a=s.get(o);return a||(a=this.precomputeWindow(o,l),l!==1&&s.set(o,c(a))),this.wNAF(l,a,i)}}}function jn(t){return Go(t.Fp),te(t,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...qn(t.n,t.nBitLength),...t,p:t.Fp.ORDER})}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function es(t){const e=jn(t);te(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:ns,hexToBytes:rs}=jo,Pt={Err:class extends Error{constructor(e=""){super(e)}},_parseInt(t){const{Err:e}=Pt;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:ns(r),l:t.subarray(n+2)}},toSig(t){const{Err:e}=Pt,n=typeof t=="string"?rs(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:s}=Pt._parseInt(n.subarray(2)),{d:i,l:c}=Pt._parseInt(s);if(c.length)throw new e("Invalid signature: left bytes after parsing");return{r:o,s:i}},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)),s=r.length/2,i=o.length/2,c=n(s),l=n(i);return`30${n(i+s+4)}02${l}${o}02${c}${r}`}},pt=BigInt(0),st=BigInt(1);BigInt(2);const zn=BigInt(3);BigInt(4);function os(t){const e=es(t),{Fp:n}=e,r=e.toBytes||((p,d,g)=>{const b=d.toAffine();return It(Uint8Array.from([4]),n.toBytes(b.x),n.toBytes(b.y))}),o=e.fromBytes||(p=>{const d=p.subarray(1),g=n.fromBytes(d.subarray(0,n.BYTES)),b=n.fromBytes(d.subarray(n.BYTES,2*n.BYTES));return{x:g,y:b}});function s(p){const{a:d,b:g}=e,b=n.sqr(p),y=n.mul(b,p);return n.add(n.add(y,n.mul(p,d)),g)}if(!n.eql(n.sqr(e.Gy),s(e.Gx)))throw new Error("bad generator point: equation left != right");function i(p){return typeof p=="bigint"&&pt<p&&p<e.n}function c(p){if(!i(p))throw new Error("Expected valid bigint: 0 < bigint < curve.n")}function l(p){const{allowedPrivateKeyLengths:d,nByteLength:g,wrapPrivateKey:b,n:y}=e;if(d&&typeof p!="bigint"){if(p instanceof Uint8Array&&(p=zt(p)),typeof p!="string"||!d.includes(p.length))throw new Error("Invalid key");p=p.padStart(g*2,"0")}let E;try{E=typeof p=="bigint"?p:et(F("private key",p,g))}catch{throw new Error(`private key must be ${g} bytes, hex or bigint, not ${typeof p}`)}return b&&(E=Z(E,y)),c(E),E}const a=new Map;function f(p){if(!(p instanceof u))throw new Error("ProjectivePoint expected")}class u{constructor(d,g,b){if(this.px=d,this.py=g,this.pz=b,d==null||!n.isValid(d))throw new Error("x required");if(g==null||!n.isValid(g))throw new Error("y required");if(b==null||!n.isValid(b))throw new Error("z required")}static fromAffine(d){const{x:g,y:b}=d||{};if(!d||!n.isValid(g)||!n.isValid(b))throw new Error("invalid affine point");if(d instanceof u)throw new Error("projective point not allowed");const y=E=>n.eql(E,n.ZERO);return y(g)&&y(b)?u.ZERO:new u(g,b,n.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(d){const g=n.invertBatch(d.map(b=>b.pz));return d.map((b,y)=>b.toAffine(g[y])).map(u.fromAffine)}static fromHex(d){const g=u.fromAffine(o(F("pointHex",d)));return g.assertValidity(),g}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:g}=this.toAffine();if(!n.isValid(d)||!n.isValid(g))throw new Error("bad point: x or y not FE");const b=n.sqr(g),y=s(d);if(!n.eql(b,y))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:g,py:b,pz:y}=this,{px:E,py:A,pz:O}=d,v=n.eql(n.mul(g,O),n.mul(E,y)),_=n.eql(n.mul(b,O),n.mul(A,y));return v&&_}negate(){return new u(this.px,n.neg(this.py),this.pz)}double(){const{a:d,b:g}=e,b=n.mul(g,zn),{px:y,py:E,pz:A}=this;let O=n.ZERO,v=n.ZERO,_=n.ZERO,S=n.mul(y,y),U=n.mul(E,E),I=n.mul(A,A),B=n.mul(y,E);return B=n.add(B,B),_=n.mul(y,A),_=n.add(_,_),O=n.mul(d,_),v=n.mul(b,I),v=n.add(O,v),O=n.sub(U,v),v=n.add(U,v),v=n.mul(O,v),O=n.mul(B,O),_=n.mul(b,_),I=n.mul(d,I),B=n.sub(S,I),B=n.mul(d,B),B=n.add(B,_),_=n.add(S,S),S=n.add(_,S),S=n.add(S,I),S=n.mul(S,B),v=n.add(v,S),I=n.mul(E,A),I=n.add(I,I),S=n.mul(I,B),O=n.sub(O,S),_=n.mul(I,U),_=n.add(_,_),_=n.add(_,_),new u(O,v,_)}add(d){f(d);const{px:g,py:b,pz:y}=this,{px:E,py:A,pz:O}=d;let v=n.ZERO,_=n.ZERO,S=n.ZERO;const U=e.a,I=n.mul(e.b,zn);let B=n.mul(g,E),K=n.mul(b,A),C=n.mul(y,O),rt=n.add(g,b),x=n.add(E,A);rt=n.mul(rt,x),x=n.add(B,K),rt=n.sub(rt,x),x=n.add(g,y);let k=n.add(E,O);return x=n.mul(x,k),k=n.add(B,C),x=n.sub(x,k),k=n.add(b,y),v=n.add(A,O),k=n.mul(k,v),v=n.add(K,C),k=n.sub(k,v),S=n.mul(U,x),v=n.mul(I,C),S=n.add(v,S),v=n.sub(K,S),S=n.add(K,S),_=n.mul(v,S),K=n.add(B,B),K=n.add(K,B),C=n.mul(U,C),x=n.mul(I,x),K=n.add(K,C),C=n.sub(B,C),C=n.mul(U,C),x=n.add(x,C),B=n.mul(K,x),_=n.add(_,B),B=n.mul(k,x),v=n.mul(rt,v),v=n.sub(v,B),B=n.mul(rt,K),S=n.mul(k,S),S=n.add(S,B),new u(v,_,S)}subtract(d){return this.add(d.negate())}is0(){return this.equals(u.ZERO)}wNAF(d){return w.wNAFCached(this,a,d,g=>{const b=n.invertBatch(g.map(y=>y.pz));return g.map((y,E)=>y.toAffine(b[E])).map(u.fromAffine)})}multiplyUnsafe(d){const g=u.ZERO;if(d===pt)return g;if(c(d),d===st)return this;const{endo:b}=e;if(!b)return w.unsafeLadder(this,d);let{k1neg:y,k1:E,k2neg:A,k2:O}=b.splitScalar(d),v=g,_=g,S=this;for(;E>pt||O>pt;)E&st&&(v=v.add(S)),O&st&&(_=_.add(S)),S=S.double(),E>>=st,O>>=st;return y&&(v=v.negate()),A&&(_=_.negate()),_=new u(n.mul(_.px,b.beta),_.py,_.pz),v.add(_)}multiply(d){c(d);let g=d,b,y;const{endo:E}=e;if(E){const{k1neg:A,k1:O,k2neg:v,k2:_}=E.splitScalar(g);let{p:S,f:U}=this.wNAF(O),{p:I,f:B}=this.wNAF(_);S=w.constTimeNegate(A,S),I=w.constTimeNegate(v,I),I=new u(n.mul(I.px,E.beta),I.py,I.pz),b=S.add(I),y=U.add(B)}else{const{p:A,f:O}=this.wNAF(g);b=A,y=O}return u.normalizeZ([b,y])[0]}multiplyAndAddUnsafe(d,g,b){const y=u.BASE,E=(O,v)=>v===pt||v===st||!O.equals(y)?O.multiplyUnsafe(v):O.multiply(v),A=E(this,g).add(E(d,b));return A.is0()?void 0:A}toAffine(d){const{px:g,py:b,pz:y}=this,E=this.is0();d==null&&(d=E?n.ONE:n.inv(y));const A=n.mul(g,d),O=n.mul(b,d),v=n.mul(y,d);if(E)return{x:n.ZERO,y:n.ZERO};if(!n.eql(v,n.ONE))throw new Error("invZ was invalid");return{x:A,y:O}}isTorsionFree(){const{h:d,isTorsionFree:g}=e;if(d===st)return!0;if(g)return g(u,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){const{h:d,clearCofactor:g}=e;return d===st?this:g?g(u,this):this.multiplyUnsafe(e.h)}toRawBytes(d=!0){return this.assertValidity(),r(u,this,d)}toHex(d=!0){return zt(this.toRawBytes(d))}}u.BASE=new u(e.Gx,e.Gy,n.ONE),u.ZERO=new u(n.ZERO,n.ONE,n.ZERO);const h=e.nBitLength,w=ts(u,e.endo?Math.ceil(h/2):h);return{CURVE:e,ProjectivePoint:u,normPrivateKeyToScalar:l,weierstrassEquation:s,isWithinCurveOrder:i}}function ss(t){const e=jn(t);return te(e,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...e})}function is(t){const e=ss(t),{Fp:n,n:r}=e,o=n.BYTES+1,s=2*n.BYTES+1;function i(x){return pt<x&&x<n.ORDER}function c(x){return Z(x,r)}function l(x){return De(x,r)}const{ProjectivePoint:a,normPrivateKeyToScalar:f,weierstrassEquation:u,isWithinCurveOrder:h}=os({...e,toBytes(x,k,P){const R=k.toAffine(),H=n.toBytes(R.x),V=It;return P?V(Uint8Array.from([k.hasEvenY()?2:3]),H):V(Uint8Array.from([4]),H,n.toBytes(R.y))},fromBytes(x){const k=x.length,P=x[0],R=x.subarray(1);if(k===o&&(P===2||P===3)){const H=et(R);if(!i(H))throw new Error("Point is not on curve");const V=u(H);let Q=n.sqrt(V);const X=(Q&st)===st;return(P&1)===1!==X&&(Q=n.neg(Q)),{x:H,y:Q}}else if(k===s&&P===4){const H=n.fromBytes(R.subarray(0,n.BYTES)),V=n.fromBytes(R.subarray(n.BYTES,2*n.BYTES));return{x:H,y:V}}else throw new Error(`Point of length ${k} was invalid. Expected ${o} compressed bytes or ${s} uncompressed bytes`)}}),w=x=>zt(_t(x,e.nByteLength));function p(x){const k=r>>st;return x>k}function d(x){return p(x)?c(-x):x}const g=(x,k,P)=>et(x.slice(k,P));class b{constructor(k,P,R){this.r=k,this.s=P,this.recovery=R,this.assertValidity()}static fromCompact(k){const P=e.nByteLength;return k=F("compactSignature",k,P*2),new b(g(k,0,P),g(k,P,2*P))}static fromDER(k){const{r:P,s:R}=Pt.toSig(F("DER",k));return new b(P,R)}assertValidity(){if(!h(this.r))throw new Error("r must be 0 < r < CURVE.n");if(!h(this.s))throw new Error("s must be 0 < s < CURVE.n")}addRecoveryBit(k){return new b(this.r,this.s,k)}recoverPublicKey(k){const{r:P,s:R,recovery:H}=this,V=_(F("msgHash",k));if(H==null||![0,1,2,3].includes(H))throw new Error("recovery id invalid");const Q=H===2||H===3?P+e.n:P;if(Q>=n.ORDER)throw new Error("recovery id 2 or 3 invalid");const X=H&1?"03":"02",wt=a.fromHex(X+w(Q)),T=l(Q),z=c(-V*T),Ot=c(R*T),lt=a.BASE.multiplyAndAddUnsafe(wt,z,Ot);if(!lt)throw new Error("point at infinify");return lt.assertValidity(),lt}hasHighS(){return p(this.s)}normalizeS(){return this.hasHighS()?new b(this.r,c(-this.s),this.recovery):this}toDERRawBytes(){return Vt(this.toDERHex())}toDERHex(){return Pt.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return Vt(this.toCompactHex())}toCompactHex(){return w(this.r)+w(this.s)}}const y={isValidPrivateKey(x){try{return f(x),!0}catch{return!1}},normPrivateKeyToScalar:f,randomPrivateKey:()=>{const x=Mn(e.n);return Qo(e.randomBytes(x),e.n)},precompute(x=8,k=a.BASE){return k._setWindowSize(x),k.multiply(BigInt(3)),k}};function E(x,k=!0){return a.fromPrivateKey(x).toRawBytes(k)}function A(x){const k=x instanceof Uint8Array,P=typeof x=="string",R=(k||P)&&x.length;return k?R===o||R===s:P?R===2*o||R===2*s:x instanceof a}function O(x,k,P=!0){if(A(x))throw new Error("first arg must be private key");if(!A(k))throw new Error("second arg must be public key");return a.fromHex(k).multiply(f(x)).toRawBytes(P)}const v=e.bits2int||function(x){const k=et(x),P=x.length*8-e.nBitLength;return P>0?k>>BigInt(P):k},_=e.bits2int_modN||function(x){return c(v(x))},S=je(e.nBitLength);function U(x){if(typeof x!="bigint")throw new Error("bigint expected");if(!(pt<=x&&x<S))throw new Error(`bigint expected < 2^${e.nBitLength}`);return _t(x,e.nByteLength)}function I(x,k,P=B){if(["recovered","canonical"].some(Rt=>Rt in P))throw new Error("sign() legacy options not supported");const{hash:R,randomBytes:H}=e;let{lowS:V,prehash:Q,extraEntropy:X}=P;V==null&&(V=!0),x=F("msgHash",x),Q&&(x=F("prehashed msgHash",R(x)));const wt=_(x),T=f(k),z=[U(T),U(wt)];if(X!=null){const Rt=X===!0?H(n.BYTES):X;z.push(F("extraEntropy",Rt))}const Ot=It(...z),lt=wt;function le(Rt){const Ft=v(Rt);if(!h(Ft))return;const Dr=l(Ft),Jt=a.BASE.multiply(Ft).toAffine(),at=c(Jt.x);if(at===pt)return;const Yt=c(Dr*c(lt+at*T));if(Yt===pt)return;let Wr=(Jt.x===at?0:2)|Number(Jt.y&st),Zr=Yt;return V&&p(Yt)&&(Zr=d(Yt),Wr^=1),new b(at,Zr,Wr)}return{seed:Ot,k2sig:le}}const B={lowS:e.lowS,prehash:!1},K={lowS:e.lowS,prehash:!1};function C(x,k,P=B){const{seed:R,k2sig:H}=I(x,k,P),V=e;return Cn(V.hash.outputLen,V.nByteLength,V.hmac)(R,H)}a.BASE._setWindowSize(8);function rt(x,k,P,R=K){var Jt;const H=x;if(k=F("msgHash",k),P=F("publicKey",P),"strict"in R)throw new Error("options.strict was renamed to lowS");const{lowS:V,prehash:Q}=R;let X,wt;try{if(typeof H=="string"||H instanceof Uint8Array)try{X=b.fromDER(H)}catch(at){if(!(at instanceof Pt.Err))throw at;X=b.fromCompact(H)}else if(typeof H=="object"&&typeof H.r=="bigint"&&typeof H.s=="bigint"){const{r:at,s:Yt}=H;X=new b(at,Yt)}else throw new Error("PARSE");wt=a.fromHex(P)}catch(at){if(at.message==="PARSE")throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(V&&X.hasHighS())return!1;Q&&(k=e.hash(k));const{r:T,s:z}=X,Ot=_(k),lt=l(z),le=c(Ot*lt),Rt=c(T*lt),Ft=(Jt=a.BASE.multiplyAndAddUnsafe(wt,le,Rt))==null?void 0:Jt.toAffine();return Ft?c(Ft.x)===T:!1}return{CURVE:e,getPublicKey:E,getSharedSecret:O,sign:C,verify:rt,ProjectivePoint:a,Signature:b,utils:y}}class Vn extends In{constructor(e,n){super(),this.finished=!1,this.destroyed=!1,vo(e);const r=Re(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,s=new Uint8Array(o);s.set(r.length>o?e.create().update(r).digest():r);for(let i=0;i<s.length;i++)s[i]^=54;this.iHash.update(s),this.oHash=e.create();for(let i=0;i<s.length;i++)s[i]^=106;this.oHash.update(s),s.fill(0)}update(e){return we(this),this.iHash.update(e),this}digestInto(e){we(this),On(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:s,blockLen:i,outputLen:c}=this;return e=e,e.finished=o,e.destroyed=s,e.blockLen=i,e.outputLen=c,e.oHash=n._cloneInto(e.oHash),e.iHash=r._cloneInto(e.iHash),e}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}const Dn=(t,e,n)=>new Vn(t,e).update(n).digest();Dn.create=(t,e)=>new Vn(t,e);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function cs(t){return{hash:t,hmac:(e,...n)=>Dn(t,e,ko(...n)),randomBytes:Nn}}function ls(t,e){const n=r=>is({...t,...cs(r)});return Object.freeze({...n(e),create:n})}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const be=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),ye=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),Wn=BigInt(1),me=BigInt(2),Zn=(t,e)=>(t+e/me)/e;function Gn(t){const e=be,n=BigInt(3),r=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),c=BigInt(44),l=BigInt(88),a=t*t*t%e,f=a*a*t%e,u=ot(f,n,e)*f%e,h=ot(u,n,e)*f%e,w=ot(h,me,e)*a%e,p=ot(w,o,e)*w%e,d=ot(p,s,e)*p%e,g=ot(d,c,e)*d%e,b=ot(g,l,e)*g%e,y=ot(b,c,e)*d%e,E=ot(y,n,e)*f%e,A=ot(E,i,e)*p%e,O=ot(A,r,e)*a%e,v=ot(O,me,e);if(!Ze.eql(Ze.sqr(v),t))throw new Error("Cannot find square root");return v}const Ze=Yo(be,void 0,void 0,{sqrt:Gn}),ee=ls({a:BigInt(0),b:BigInt(7),Fp:Ze,n:ye,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:t=>{const e=ye,n=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),r=-Wn*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),s=n,i=BigInt("0x100000000000000000000000000000000"),c=Zn(s*t,e),l=Zn(-r*t,e);let a=Z(t-c*n-l*o,e),f=Z(-c*r-l*s,e);const u=a>i,h=f>i;if(u&&(a=e-a),h&&(f=e-f),a>i||f>i)throw new Error("splitScalar: Endomorphism failed, k="+t);return{k1neg:u,k1:a,k2neg:h,k2:f}}}},He),xe=BigInt(0),Fn=t=>typeof t=="bigint"&&xe<t&&t<be,as=t=>typeof t=="bigint"&&xe<t&&t<ye,Jn={};function Ee(t,...e){let n=Jn[t];if(n===void 0){const r=He(Uint8Array.from(t,o=>o.charCodeAt(0)));n=It(r,r),Jn[t]=n}return He(It(n,...e))}const Ge=t=>t.toRawBytes(!0).slice(1),Fe=t=>_t(t,32),Je=t=>Z(t,be),ne=t=>Z(t,ye),Ye=ee.ProjectivePoint,us=(t,e,n)=>Ye.BASE.multiplyAndAddUnsafe(t,e,n);function Qe(t){let e=ee.utils.normPrivateKeyToScalar(t),n=Ye.fromPrivateKey(e);return{scalar:n.hasEvenY()?e:ne(-e),bytes:Ge(n)}}function Yn(t){if(!Fn(t))throw new Error("bad x: need 0 < x < p");const e=Je(t*t),n=Je(e*t+BigInt(7));let r=Gn(n);r%me!==xe&&(r=Je(-r));const o=new Ye(t,r,Wn);return o.assertValidity(),o}function Qn(...t){return ne(et(Ee("BIP0340/challenge",...t)))}function fs(t){return Qe(t).bytes}function ds(t,e,n=Nn(32)){const r=F("message",t),{bytes:o,scalar:s}=Qe(e),i=F("auxRand",n,32),c=Fe(s^et(Ee("BIP0340/aux",i))),l=Ee("BIP0340/nonce",c,o,r),a=ne(et(l));if(a===xe)throw new Error("sign failed: k is zero");const{bytes:f,scalar:u}=Qe(a),h=Qn(f,o,r),w=new Uint8Array(64);if(w.set(f,0),w.set(Fe(ne(u+h*s)),32),!Xn(w,r,o))throw new Error("sign: Invalid signature produced");return w}function Xn(t,e,n){const r=F("signature",t,64),o=F("message",e),s=F("publicKey",n,32);try{const i=Yn(et(s)),c=et(r.subarray(0,32));if(!Fn(c))return!1;const l=et(r.subarray(32,64));if(!as(l))return!1;const a=Qn(Fe(c),Ge(i),o),f=us(i,l,ne(-a));return!(!f||!f.hasEvenY()||f.toAffine().x!==c)}catch{return!1}}const Y={getPublicKey:fs,sign:ds,verify:Xn,utils:{randomPrivateKey:ee.utils.randomPrivateKey,lift_x:Yn,pointToBytes:Ge,numberToBytesBE:_t,bytesToNumberBE:et,taggedHash:Ee,mod:Z}};function Xe(t){if(!Number.isSafeInteger(t)||t<0)throw new Error(`Wrong positive integer: ${t}`)}function hs(t){if(typeof t!="boolean")throw new Error(`Expected boolean, not ${t}`)}function tr(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 ws(t){if(typeof t!="function"||typeof t.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");Xe(t.outputLen),Xe(t.blockLen)}function ps(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 gs(t,e){tr(t);const n=e.outputLen;if(t.length<n)throw new Error(`digestInto() expects output buffer of length at least ${n}`)}const tn={number:Xe,bool:hs,bytes:tr,hash:ws,exists:ps,output:gs};function bs(t,e,n,r){if(typeof t.setBigUint64=="function")return t.setBigUint64(e,n,r);const o=BigInt(32),s=BigInt(4294967295),i=Number(n>>o&s),c=Number(n&s),l=r?4:0,a=r?0:4;t.setUint32(e+l,i,r),t.setUint32(e+a,c,r)}class ys extends xo{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=Pe(this.buffer)}update(e){tn.exists(this);const{view:n,buffer:r,blockLen:o}=this;e=An(e);const s=e.length;for(let i=0;i<s;){const c=Math.min(o-this.pos,s-i);if(c===o){const l=Pe(e);for(;o<=s-i;i+=o)this.process(l,i);continue}r.set(e.subarray(i,i+c),this.pos),this.pos+=c,i+=c,this.pos===o&&(this.process(n,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){tn.exists(this),tn.output(e,this),this.finished=!0;const{buffer:n,view:r,blockLen:o,isLE:s}=this;let{pos:i}=this;n[i++]=128,this.buffer.subarray(i).fill(0),this.padOffset>o-i&&(this.process(r,0),i=0);for(let u=i;u<o;u++)n[u]=0;bs(r,o-8,BigInt(this.length*8),s),this.process(r,0);const c=Pe(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],s)}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:s,destroyed:i,pos:c}=this;return e.length=o,e.pos=c,e.finished=s,e.destroyed=i,o%n&&e.buffer.set(r),e}}const ms=(t,e,n)=>t&e^~t&n,xs=(t,e,n)=>t&e^t&n^e&n,Es=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]),St=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),kt=new Uint32Array(64);class er extends ys{constructor(){super(64,32,8,!1),this.A=St[0]|0,this.B=St[1]|0,this.C=St[2]|0,this.D=St[3]|0,this.E=St[4]|0,this.F=St[5]|0,this.G=St[6]|0,this.H=St[7]|0}get(){const{A:e,B:n,C:r,D:o,E:s,F:i,G:c,H:l}=this;return[e,n,r,o,s,i,c,l]}set(e,n,r,o,s,i,c,l){this.A=e|0,this.B=n|0,this.C=r|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=c|0,this.H=l|0}process(e,n){for(let u=0;u<16;u++,n+=4)kt[u]=e.getUint32(n,!1);for(let u=16;u<64;u++){const h=kt[u-15],w=kt[u-2],p=ut(h,7)^ut(h,18)^h>>>3,d=ut(w,17)^ut(w,19)^w>>>10;kt[u]=d+kt[u-7]+p+kt[u-16]|0}let{A:r,B:o,C:s,D:i,E:c,F:l,G:a,H:f}=this;for(let u=0;u<64;u++){const h=ut(c,6)^ut(c,11)^ut(c,25),w=f+h+ms(c,l,a)+Es[u]+kt[u]|0,d=(ut(r,2)^ut(r,13)^ut(r,22))+xs(r,o,s)|0;f=a,a=l,l=c,c=i+w|0,i=s,s=o,o=r,r=w+d|0}r=r+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,c=c+this.E|0,l=l+this.F|0,a=a+this.G|0,f=f+this.H|0,this.set(r,o,s,i,c,l,a,f)}roundClean(){kt.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}}class vs extends er{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 en=Bn(()=>new er);Bn(()=>new vs);var Dt=Symbol("verified"),_s=t=>t instanceof Object;function Ss(t){if(!_s(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 ks=new TextEncoder,As=class{generateSecretKey(){return Y.utils.randomPrivateKey()}getPublicKey(e){return J(Y.getPublicKey(e))}finalizeEvent(e,n){const r=e;return r.pubkey=J(Y.getPublicKey(n)),r.id=nn(r),r.sig=J(Y.sign(nn(r),n)),r[Dt]=!0,r}verifyEvent(e){if(typeof e[Dt]=="boolean")return e[Dt];const n=nn(e);if(n!==e.id)return e[Dt]=!1,!1;try{const r=Y.verify(e.sig,n,e.pubkey);return e[Dt]=r,r}catch{return e[Dt]=!1,!1}}};function Bs(t){if(!Ss(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=en(ks.encode(Bs(t)));return J(e)}var ve=new As,$s=ve.generateSecretKey,nr=ve.getPublicKey;ve.finalizeEvent,ve.verifyEvent;var Ut=Symbol("verified"),Os=t=>t instanceof Object;function Ts(t){if(!Os(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 Is=new TextEncoder;function re(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){m(this,"value");m(this,"next",null);m(this,"prev",null);this.value=e}},Ps=class{constructor(){m(this,"first");m(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}},Us=class{generateSecretKey(){return Y.utils.randomPrivateKey()}getPublicKey(e){return J(Y.getPublicKey(e))}finalizeEvent(e,n){const r=e;return r.pubkey=J(Y.getPublicKey(n)),r.id=rn(r),r.sig=J(Y.sign(rn(r),n)),r[Ut]=!0,r}verifyEvent(e){if(typeof e[Ut]=="boolean")return e[Ut];const n=rn(e);if(n!==e.id)return e[Ut]=!1,!1;try{const r=Y.verify(e.sig,n,e.pubkey);return e[Ut]=r,r}catch{return e[Ut]=!1,!1}}};function Ls(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 rn(t){let e=en(Is.encode(Ls(t)));return J(e)}var _e=new Us;_e.generateSecretKey,_e.getPublicKey,_e.finalizeEvent;var Cs=_e.verifyEvent,Rs=22242;function Hs(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(([s,i])=>s===n.slice(1)&&o.indexOf(i)!==-1))return!1}return!(t.since&&e.created_at<t.since||t.until&&e.created_at>t.until)}function qs(t,e){for(let n=0;n<t.length;n++)if(Hs(t[n],e))return!0;return!1}function Ks(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 Ms(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 s=r+1+o;return t.slice(r+1,s)}function js(t,e){return{kind:Rs,created_at:Math.floor(Date.now()/1e3),tags:[["relay",t],["challenge",e]],content:""}}async function zs(){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 Vs=t=>(t[Ut]=!0,!0),rr;try{rr=WebSocket}catch{}var or=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 Ps);m(this,"queueRunning",!1);m(this,"challenge");m(this,"serial",0);m(this,"verifyEvent");this.url=re(e),this.verifyEvent=n.verifyEvent}static async connect(e,n){const r=new or(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 rr(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 zs();this.queueRunning=!1}handleNext(){var r,o;const e=this.incomingMessageQueue.dequeue();if(!e)return!1;const n=Ms(e);if(n){const s=this.openSubs.get(n);if(!s)return;const i=Ks(e,"id"),c=(r=s.alreadyHaveEvent)==null?void 0:r.call(s,i);if((o=s.receivedEvent)==null||o.call(s,this,i),c)return}try{let s=JSON.parse(e);switch(s[0]){case"EVENT":{const i=this.openSubs.get(s[1]),c=s[2];this.verifyEvent(c)&&qs(i.filters,c)&&i.onevent(c);return}case"COUNT":{const i=s[1],c=s[2],l=this.openCountRequests.get(i);l&&(l.resolve(c.count),this.openCountRequests.delete(i));return}case"EOSE":{const i=this.openSubs.get(s[1]);if(!i)return;i.receivedEose();return}case"OK":{const i=s[1],c=s[2],l=s[3],a=this.openEventPublishes.get(i);c?a.resolve(l):a.reject(new Error(l)),this.openEventPublishes.delete(i);return}case"CLOSED":{const i=s[1],c=this.openSubs.get(i);if(!c)return;c.closed=!0,c.close(s[2]);return}case"NOTICE":this.onnotice(s[1]);return;case"AUTH":{this.challenge=s[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(js(this.url,this.challenge)),r=new Promise((o,s)=>{this.openEventPublishes.set(n.id,{resolve:o,reject:s})});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((s,i)=>{this.openCountRequests.set(r,{resolve:s,reject:i})});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 Ds(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()}},Ds=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||(s=>{console.warn(`onevent() callback not defined for subscription '${this.id}' in relay ${this.relay.url}. event received:`,s)})}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=re(e);let r=this.relays.get(e);return r||(r=new or(e,{verifyEvent:this.trustedRelayURLs.has(e)?Vs:this.verifyEvent}),n!=null&&n.connectionTimeout&&(r.connectionTimeout=n.connectionTimeout),this.relays.set(e,r)),await r.connect(),r}close(e){e.map(re).forEach(n=>{var r;(r=this.relays.get(n))==null||r.close()})}subscribeMany(e,n,r){this.trackRelays&&(r.receivedEvent=(h,w)=>{let p=this.seenOn.get(w);p||(p=new Set,this.seenOn.set(w,p)),p.add(h)});const o=new Set,s=[],i=[];let c=h=>{var w;i[h]=!0,i.filter(p=>p).length===e.length&&((w=r.oneose)==null||w.call(r),c=()=>{})};const l=[];let a=(h,w)=>{var p;c(h),l[h]=w,l.filter(d=>d).length===e.length&&((p=r.onclose)==null||p.call(r,l),a=()=>{})};const f=h=>{var p;if((p=r.alreadyHaveEvent)!=null&&p.call(r,h))return!0;const w=o.has(h);return o.add(h),w},u=Promise.all(e.map(re).map(async(h,w,p)=>{if(p.indexOf(h)!==w){a(w,"duplicate url");return}let d;try{d=await this.ensureRelay(h,{connectionTimeout:r.maxWait?Math.max(r.maxWait*.8,r.maxWait-1e3):void 0})}catch(b){a(w,(b==null?void 0:b.message)||String(b));return}let g=d.subscribe(n,{...r,oneose:()=>c(w),onclose:b=>a(w,b),alreadyHaveEvent:f,eoseTimeout:r.maxWait});s.push(g)}));return{async close(){await u,s.forEach(h=>{h.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 s=[];this.subscribeManyEose(e,[n],{...r,onevent(i){s.push(i)},onclose(i){o(s)}})})}async get(e,n,r){n.limit=1;const o=await this.querySync(e,n,r);return o.sort((s,i)=>i.created_at-s.created_at),o[0]||null}publish(e,n){return e.map(re).map(async(r,o,s)=>s.indexOf(r)!==o?Promise.reject("duplicate url"):(await this.ensureRelay(r)).publish(n))}},Zs=class extends Ws{constructor(){super({verifyEvent:Cs})}};function sr(t){return t instanceof Uint8Array||t!=null&&typeof t=="object"&&t.constructor.name==="Uint8Array"}function Lt(t,...e){if(!sr(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 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 ir(t,e){Lt(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 nt=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 Fs(t){if(typeof t!="string")throw new Error(`string expected, got ${typeof t}`);return new Uint8Array(new TextEncoder().encode(t))}function oe(t){if(typeof t=="string")t=Fs(t);else if(sr(t))t=t.slice();else throw new Error(`Uint8Array expected, got ${typeof t}`);return t}const Js=(t,e)=>(Object.assign(e,t),e),gt=16,on=new Uint8Array(16),dt=nt(on),Ys=225,Qs=(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^Ys<<24&-(o&1)}},it=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 ti=t=>t>64*1024?8:t>1024?4:2;class cr{constructor(e,n){this.blockLen=gt,this.outputLen=gt,this.s0=0,this.s1=0,this.s2=0,this.s3=0,this.finished=!1,e=oe(e),Lt(e,16);const r=Gs(e);let o=r.getUint32(0,!1),s=r.getUint32(4,!1),i=r.getUint32(8,!1),c=r.getUint32(12,!1);const l=[];for(let p=0;p<128;p++)l.push({s0:it(o),s1:it(s),s2:it(i),s3:it(c)}),{s0:o,s1:s,s2:i,s3:c}=Qs(o,s,i,c);const a=ti(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,h=this.windowSize=2**a,w=[];for(let p=0;p<u;p++)for(let d=0;d<h;d++){let g=0,b=0,y=0,E=0;for(let A=0;A<a;A++){if(!(d>>>a-A-1&1))continue;const{s0:v,s1:_,s2:S,s3:U}=l[a*p+A];g^=v,b^=_,y^=S,E^=U}w.push({s0:g,s1:b,s2:y,s3:E})}this.t=w}_updateBlock(e,n,r,o){e^=this.s0,n^=this.s1,r^=this.s2,o^=this.s3;const{W:s,t:i,windowSize:c}=this;let l=0,a=0,f=0,u=0;const h=(1<<s)-1;let w=0;for(const p of[e,n,r,o])for(let d=0;d<4;d++){const g=p>>>8*d&255;for(let b=8/s-1;b>=0;b--){const y=g>>>s*b&h,{s0:E,s1:A,s2:O,s3:v}=i[w*c+y];l^=E,a^=A,f^=O,u^=v,w+=1}}this.s0=l,this.s1=a,this.s2=f,this.s3=u}update(e){e=oe(e),Se(this);const n=nt(e),r=Math.floor(e.length/gt),o=e.length%gt;for(let s=0;s<r;s++)this._updateBlock(n[s*4+0],n[s*4+1],n[s*4+2],n[s*4+3]);return o&&(on.set(e.subarray(r*gt)),this._updateBlock(dt[0],dt[1],dt[2],dt[3]),dt.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){Se(this),ir(e,this),this.finished=!0;const{s0:n,s1:r,s2:o,s3:s}=this,i=nt(e);return i[0]=n,i[1]=r,i[2]=o,i[3]=s,e}digest(){const e=new Uint8Array(gt);return this.digestInto(e),this.destroy(),e}}class ei extends cr{constructor(e,n){e=oe(e);const r=Xs(e.slice());super(r,n),r.fill(0)}update(e){e=oe(e),Se(this);const n=nt(e),r=e.length%gt,o=Math.floor(e.length/gt);for(let s=0;s<o;s++)this._updateBlock(it(n[s*4+3]),it(n[s*4+2]),it(n[s*4+1]),it(n[s*4+0]));return r&&(on.set(e.subarray(o*gt)),this._updateBlock(it(dt[3]),it(dt[2]),it(dt[1]),it(dt[0])),dt.fill(0)),this}digestInto(e){Se(this),ir(e,this),this.finished=!0;const{s0:n,s1:r,s2:o,s3:s}=this,i=nt(e);return i[0]=n,i[1]=r,i[2]=o,i[3]=s,e.reverse()}}function lr(t){const e=(r,o)=>t(o,r.length).update(oe(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 cr(t,e)),lr((t,e)=>new ei(t,e));const At=16,ni=283;function sn(t){return t<<1^ni&-(t>>7)}function Wt(t,e){let n=0;for(;e>0;e>>=1)n^=t&-(e&1),t=sn(t);return n}const cn=(()=>{let t=new Uint8Array(256);for(let n=0,r=1;n<256;n++,r^=sn(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})(),ri=cn.map((t,e)=>cn.indexOf(e)),oi=t=>t<<24|t>>>8,ln=t=>t<<8|t>>>24;function ar(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(ln),o=r.map(ln),s=o.map(ln),i=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;i[u]=n[a]^r[f],c[u]=o[a]^s[f],l[u]=t[a]<<8|t[f]}return{sbox:t,sbox2:l,T0:n,T1:r,T2:o,T3:s,T01:i,T23:c}}const an=ar(cn,t=>Wt(t,3)<<24|t<<16|t<<8|Wt(t,2)),ur=ar(ri,t=>Wt(t,11)<<24|Wt(t,13)<<16|Wt(t,9)<<8|Wt(t,14)),si=(()=>{const t=new Uint8Array(16);for(let e=0,n=1;e<16;e++,n=sn(n))t[e]=n;return t})();function fr(t){Lt(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=nt(t),o=r.length,s=c=>ht(n,c,c,c,c),i=new Uint32Array(e+28);i.set(r);for(let c=o;c<i.length;c++){let l=i[c-1];c%o===0?l=s(oi(l))^si[c/o-1]:o>6&&c%o===4&&(l=s(l)),i[c]=i[c-o]^l}return i}function ii(t){const e=fr(t),n=e.slice(),r=e.length,{sbox2:o}=an,{T0:s,T1:i,T2:c,T3:l}=ur;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=ht(o,f,f,f,f);n[a]=s[u&255]^i[u>>>8&255]^c[u>>>16&255]^l[u>>>24]}return n}function Bt(t,e,n,r,o,s){return t[n<<8&65280|r>>>8&255]^e[o>>>8&65280|s>>>24&255]}function ht(t,e,n,r,o){return t[e&255|n&65280]|t[r>>>16&255|o>>>16&65280]<<16}function dr(t,e,n,r,o){const{sbox2:s,T01:i,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 p=0;p<a;p++){const d=t[l++]^Bt(i,c,e,n,r,o),g=t[l++]^Bt(i,c,n,r,o,e),b=t[l++]^Bt(i,c,r,o,e,n),y=t[l++]^Bt(i,c,o,e,n,r);e=d,n=g,r=b,o=y}const f=t[l++]^ht(s,e,n,r,o),u=t[l++]^ht(s,n,r,o,e),h=t[l++]^ht(s,r,o,e,n),w=t[l++]^ht(s,o,e,n,r);return{s0:f,s1:u,s2:h,s3:w}}function ci(t,e,n,r,o){const{sbox2:s,T01:i,T23:c}=ur;let l=0;e^=t[l++],n^=t[l++],r^=t[l++],o^=t[l++];const a=t.length/4-2;for(let p=0;p<a;p++){const d=t[l++]^Bt(i,c,e,o,r,n),g=t[l++]^Bt(i,c,n,e,o,r),b=t[l++]^Bt(i,c,r,n,e,o),y=t[l++]^Bt(i,c,o,r,n,e);e=d,n=g,r=b,o=y}const f=t[l++]^ht(s,e,o,r,n),u=t[l++]^ht(s,n,e,o,r),h=t[l++]^ht(s,r,n,e,o),w=t[l++]^ht(s,o,r,n,e);return{s0:f,s1:u,s2:h,s3:w}}function hr(t,e){if(!e)return new Uint8Array(t);if(Lt(e),e.length<t)throw new Error(`aes: wrong destination length, expected at least ${t}, got: ${e.length}`);return e}function li(t){if(Lt(t),t.length%At!==0)throw new Error(`aes/(cbc-ecb).decrypt ciphertext should consist of blocks with size ${At}`)}function ai(t,e,n){let r=t.length;const o=r%At;if(!e&&o!==0)throw new Error("aec/(cbc-ecb): unpadded plaintext with disabled padding");const s=nt(t);if(e){let l=At-o;l||(l=At),r=r+l}const i=hr(r,n),c=nt(i);return{b:s,o:c,out:i}}function ui(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 s=0;s<r;s++)if(t[n-s-1]!==r)throw new Error("aes/pcks5: wrong padding");return o}function fi(t){const e=new Uint8Array(16),n=nt(e);e.set(t);const r=At-t.length;for(let o=At-r;o<At;o++)e[o]=r;return n}const wr=Js({blockSize:16,nonceLength:16},function(e,n,r={}){Lt(e),Lt(n,16);const o=!r.disablePadding;return{encrypt:(s,i)=>{const c=fr(e),{b:l,o:a,out:f}=ai(s,o,i),u=nt(n);let h=u[0],w=u[1],p=u[2],d=u[3],g=0;for(;g+4<=l.length;)h^=l[g+0],w^=l[g+1],p^=l[g+2],d^=l[g+3],{s0:h,s1:w,s2:p,s3:d}=dr(c,h,w,p,d),a[g++]=h,a[g++]=w,a[g++]=p,a[g++]=d;if(o){const b=fi(s.subarray(g*4));h^=b[0],w^=b[1],p^=b[2],d^=b[3],{s0:h,s1:w,s2:p,s3:d}=dr(c,h,w,p,d),a[g++]=h,a[g++]=w,a[g++]=p,a[g++]=d}return c.fill(0),f},decrypt:(s,i)=>{li(s);const c=ii(e),l=nt(n),a=hr(s.length,i),f=nt(s),u=nt(a);let h=l[0],w=l[1],p=l[2],d=l[3];for(let g=0;g+4<=f.length;){const b=h,y=w,E=p,A=d;h=f[g+0],w=f[g+1],p=f[g+2],d=f[g+3];const{s0:O,s1:v,s2:_,s3:S}=ci(c,h,w,p,d);u[g++]=O^b,u[g++]=v^y,u[g++]=_^E,u[g++]=S^A}return c.fill(0),ui(a,o)}}});/*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) */function Zt(t){if(!Number.isSafeInteger(t))throw new Error(`Wrong integer: ${t}`)}function bt(...t){const e=(o,s)=>i=>o(s(i)),n=Array.from(t).reverse().reduce((o,s)=>o?e(o,s.encode):s.encode,void 0),r=t.reduce((o,s)=>o?e(o,s.decode):s.decode,void 0);return{encode:n,decode:r}}function yt(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(Zt(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 mt(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 ke(t,e="="){if(Zt(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 pr(t){if(typeof t!="function")throw new Error("normalize fn should be function");return{encode:e=>e,decode:e=>t(e)}}function gr(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=[],s=Array.from(t);for(s.forEach(i=>{if(Zt(i),i<0||i>=e)throw new Error(`Wrong integer: ${i}`)});;){let i=0,c=!0;for(let l=r;l<s.length;l++){const a=s[l],f=e*i+a;if(!Number.isSafeInteger(f)||e*i/e!==i||f-a!==e*i)throw new Error("convertRadix: carry overflow");if(i=f%n,s[l]=Math.floor(f/n),!Number.isSafeInteger(s[l])||s[l]*n+i!==f)throw new Error("convertRadix: carry overflow");if(c)s[l]?c=!1:r=l;else continue}if(o.push(i),c)break}for(let i=0;i<t.length-1&&t[i]===0;i++)o.push(0);return o.reverse()}const br=(t,e)=>e?br(e,t%e):t,Ae=(t,e)=>t+(e-br(t,e));function un(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(Ae(e,n)>32)throw new Error(`convertRadix2: carry overflow from=${e} to=${n} carryBits=${Ae(e,n)}`);let o=0,s=0;const i=2**n-1,c=[];for(const l of t){if(Zt(l),l>=2**e)throw new Error(`convertRadix2: invalid data word=${l} from=${e}`);if(o=o<<e|l,s+e>32)throw new Error(`convertRadix2: carry overflow pos=${s} from=${e}`);for(s+=e;s>=n;s-=n)c.push((o>>s-n&i)>>>0);o&=2**s-1}if(o=o<<n-s&i,!r&&s>=e)throw new Error("Excess padding");if(!r&&o)throw new Error(`Non-zero padding: ${o}`);return r&&s>0&&c.push(o>>>0),c}function di(t){return Zt(t),{encode:e=>{if(!(e instanceof Uint8Array))throw new Error("radix.encode input should be Uint8Array");return gr(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(gr(e,t,2**8))}}}function $t(t,e=!1){if(Zt(t),t<=0||t>32)throw new Error("radix2: bits should be in (0..32]");if(Ae(8,t)>32||Ae(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 un(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(un(n,t,8,e))}}}function yr(t){if(typeof t!="function")throw new Error("unsafeWrapper fn should be function");return function(...e){try{return t.apply(null,e)}catch{}}}const hi=bt($t(4),yt("0123456789ABCDEF"),mt("")),wi=bt($t(5),yt("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"),ke(5),mt(""));bt($t(5),yt("0123456789ABCDEFGHIJKLMNOPQRSTUV"),ke(5),mt("")),bt($t(5),yt("0123456789ABCDEFGHJKMNPQRSTVWXYZ"),mt(""),pr(t=>t.toUpperCase().replace(/O/g,"0").replace(/[IL]/g,"1")));const se=bt($t(6),yt("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),ke(6),mt("")),pi=bt($t(6),yt("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"),ke(6),mt("")),fn=t=>bt(di(58),yt(t),mt("")),dn=fn("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");fn("123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"),fn("rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz");const mr=[0,2,3,5,6,7,9,10,11],gi={encode(t){let e="";for(let n=0;n<t.length;n+=8){const r=t.subarray(n,n+8);e+=dn.encode(r).padStart(mr[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=mr.indexOf(r.length),s=dn.decode(r);for(let i=0;i<s.length-o;i++)if(s[i]!==0)throw new Error("base58xmr: wrong padding");e=e.concat(Array.from(s.slice(s.length-o)))}return Uint8Array.from(e)}},hn=bt(yt("qpzry9x8gf2tvdw0s3jn54khce6mua7l"),mt("")),xr=[996825010,642813549,513874426,1027748829,705979059];function ie(t){const e=t>>25;let n=(t&33554431)<<5;for(let r=0;r<xr.length;r++)(e>>r&1)===1&&(n^=xr[r]);return n}function Er(t,e,n=1){const r=t.length;let o=1;for(let s=0;s<r;s++){const i=t.charCodeAt(s);if(i<33||i>126)throw new Error(`Invalid prefix (${t})`);o=ie(o)^i>>5}o=ie(o);for(let s=0;s<r;s++)o=ie(o)^t.charCodeAt(s)&31;for(let s of e)o=ie(o)^s;for(let s=0;s<6;s++)o=ie(o);return o^=n,hn.encode(un([o%2**30],30,5,!1))}function vr(t){const e=t==="bech32"?1:734539939,n=$t(5),r=n.decode,o=n.encode,s=yr(r);function i(f,u,h=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 w=f.length+7+u.length;if(h!==!1&&w>h)throw new TypeError(`Length ${w} exceeds limit ${h}`);return f=f.toLowerCase(),`${f}1${hn.encode(u)}${Er(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 h=f.toLowerCase();if(f!==h&&f!==f.toUpperCase())throw new Error("String must be lowercase or uppercase");f=h;const w=f.lastIndexOf("1");if(w===0||w===-1)throw new Error('Letter "1" must be present between prefix and data only');const p=f.slice(0,w),d=f.slice(w+1);if(d.length<6)throw new Error("Data must be at least 6 characters long");const g=hn.decode(d).slice(0,-6),b=Er(p,g,e);if(!d.endsWith(b))throw new Error(`Invalid checksum in ${f}: expected "${b}"`);return{prefix:p,words:g}}const l=yr(c);function a(f){const{prefix:u,words:h}=c(f,!1);return{prefix:u,words:h,bytes:r(h)}}return{encode:i,decode:c,decodeToBytes:a,decodeUnsafe:l,fromWords:r,fromWordsUnsafe:s,toWords:o}}const _r=vr("bech32");vr("bech32m");const bi={encode:t=>new TextDecoder().decode(t),decode:t=>new TextEncoder().encode(t)},yi=bt($t(4),yt("0123456789abcdef"),mt(""),pr(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:bi,hex:yi,base16:hi,base32:wi,base64:se,base64url:pi,base58:dn,base58xmr:gi}).join(", ")}`;var Ct=Symbol("verified"),mi=t=>t instanceof Object;function xi(t){if(!mi(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 Ei=new TextDecoder("utf-8"),Sr=new TextEncoder;function ce(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 vi=class{constructor(t){m(this,"value");m(this,"next",null);m(this,"prev",null);this.value=t}},_i=class{constructor(){m(this,"first");m(this,"last");this.first=null,this.last=null}enqueue(t){const e=new vi(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}},Si=class{generateSecretKey(){return Y.utils.randomPrivateKey()}getPublicKey(t){return J(Y.getPublicKey(t))}finalizeEvent(t,e){const n=t;return n.pubkey=J(Y.getPublicKey(e)),n.id=wn(n),n.sig=J(Y.sign(wn(n),e)),n[Ct]=!0,n}verifyEvent(t){if(typeof t[Ct]=="boolean")return t[Ct];const e=wn(t);if(e!==t.id)return t[Ct]=!1,!1;try{const n=Y.verify(t.sig,e,t.pubkey);return t[Ct]=n,n}catch{return t[Ct]=!1,!1}}};function ki(t){if(!xi(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 wn(t){let e=en(Sr.encode(ki(t)));return J(e)}var Be=new Si,Ai=Be.generateSecretKey,kr=Be.getPublicKey,Bi=Be.finalizeEvent,Ar=Be.verifyEvent;async function $i(t,e,n){const r=t instanceof Uint8Array?J(t):t,o=ee.getSharedSecret(r,"02"+e),s=Br(o);let i=Uint8Array.from(Eo(16)),c=Sr.encode(n),l=wr(s,i).encrypt(c),a=se.encode(new Uint8Array(l)),f=se.encode(new Uint8Array(i.buffer));return`${a}?iv=${f}`}async function Oi(t,e,n){const r=t instanceof Uint8Array?J(t):t;let[o,s]=n.split("?iv="),i=ee.getSharedSecret(r,"02"+e),c=Br(i),l=se.decode(s),a=se.decode(o),f=wr(c,l).decrypt(a);return Ei.decode(f)}function Br(t){return t.slice(1,33)}var Ti=/^(?:([\w.+-]+)@)?([\w_-]+(\.[\w_-]+)+)$/,Ii;try{Ii=fetch}catch{}var Ni=22242,pn=24133,Pi=31990;function Ui(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(([s,i])=>s===n.slice(1)&&o.indexOf(i)!==-1))return!1}return!(t.since&&e.created_at<t.since||t.until&&e.created_at>t.until)}function Li(t,e){for(let n=0;n<t.length;n++)if(Ui(t[n],e))return!0;return!1}function Ci(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 Ri(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 s=r+1+o;return t.slice(r+1,s)}function Hi(t,e){return{kind:Ni,created_at:Math.floor(Date.now()/1e3),tags:[["relay",t],["challenge",e]],content:""}}async function qi(){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 Ki=t=>(t[Ct]=!0,!0),$r;try{$r=WebSocket}catch{}var Or=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 _i);m(this,"queueRunning",!1);m(this,"challenge");m(this,"serial",0);m(this,"verifyEvent");this.url=ce(t),this.verifyEvent=e.verifyEvent}static async connect(t,e){const n=new Or(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 $r(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 qi();this.queueRunning=!1}handleNext(){var n,r;const t=this.incomingMessageQueue.dequeue();if(!t)return!1;const e=Ri(t);if(e){const o=this.openSubs.get(e);if(!o)return;const s=Ci(t,"id"),i=(n=o.alreadyHaveEvent)==null?void 0:n.call(o,s);if((r=o.receivedEvent)==null||r.call(o,this,s),i)return}try{let o=JSON.parse(t);switch(o[0]){case"EVENT":{const s=this.openSubs.get(o[1]),i=o[2];this.verifyEvent(i)&&Li(s.filters,i)&&s.onevent(i);return}case"COUNT":{const s=o[1],i=o[2],c=this.openCountRequests.get(s);c&&(c.resolve(i.count),this.openCountRequests.delete(s));return}case"EOSE":{const s=this.openSubs.get(o[1]);if(!s)return;s.receivedEose();return}case"OK":{const s=o[1],i=o[2],c=o[3],l=this.openEventPublishes.get(s);i?l.resolve(c):l.reject(new Error(c)),this.openEventPublishes.delete(s);return}case"CLOSED":{const s=o[1],i=this.openSubs.get(s);if(!i)return;i.closed=!0,i.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(Hi(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,s)=>{this.openCountRequests.set(n,{resolve:o,reject:s})});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 Mi(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()}},Mi=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)}},ji=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=ce(t);let n=this.relays.get(t);return n||(n=new Or(t,{verifyEvent:this.trustedRelayURLs.has(t)?Ki:this.verifyEvent}),e!=null&&e.connectionTimeout&&(n.connectionTimeout=e.connectionTimeout),this.relays.set(t,n)),await n.connect(),n}close(t){t.map(ce).forEach(e=>{var n;(n=this.relays.get(e))==null||n.close()})}subscribeMany(t,e,n){this.trackRelays&&(n.receivedEvent=(u,h)=>{let w=this.seenOn.get(h);w||(w=new Set,this.seenOn.set(h,w)),w.add(u)});const r=new Set,o=[],s=[];let i=u=>{var h;s[u]=!0,s.filter(w=>w).length===t.length&&((h=n.oneose)==null||h.call(n),i=()=>{})};const c=[];let l=(u,h)=>{var w;i(u),c[u]=h,c.filter(p=>p).length===t.length&&((w=n.onclose)==null||w.call(n,c),l=()=>{})};const a=u=>{var w;if((w=n.alreadyHaveEvent)!=null&&w.call(n,u))return!0;const h=r.has(u);return r.add(u),h},f=Promise.all(t.map(ce).map(async(u,h,w)=>{if(w.indexOf(u)!==h){l(h,"duplicate url");return}let p;try{p=await this.ensureRelay(u,{connectionTimeout:n.maxWait?Math.max(n.maxWait*.8,n.maxWait-1e3):void 0})}catch(g){l(h,(g==null?void 0:g.message)||String(g));return}let d=p.subscribe(e,{...n,oneose:()=>i(h),onclose:g=>l(h,g),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(s){o.push(s)},onclose(s){r(o)}})})}async get(t,e,n){e.limit=1;const r=await this.querySync(t,e,n);return r.sort((o,s)=>s.created_at-o.created_at),r[0]||null}publish(t,e){return t.map(ce).map(async(n,r,o)=>o.indexOf(n)!==r?Promise.reject("duplicate url"):(await this.ensureRelay(n)).publish(e))}},zi=class extends ji{constructor(){super({verifyEvent:Ar})}},Tr;try{Tr=fetch}catch{}var Ir=/^bunker:\/\/([0-9a-f]{64})\??([?\/\w:.=&%]*)$/,Vi=/^[^\s@]+@[^\s@]+\.[^\s@]+$/;async function Di(t){let e=t.match(Ir);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 Nr(t)}async function Nr(t){const e=t.match(Ti);if(!e)return null;const[n,r="_",o]=e;try{const s=`https://${o}/.well-known/nostr.json?name=${r}`,i=await(await Tr(s,{redirect:"error"})).json();let c=i.names[r],l=i.nip46[c]||[];return{pubkey:c,relays:l,secret:null}}catch{return null}}var gn=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 zi,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":[kr(this.secretKey)]}],{async onevent(s){const{id:i,result:c,error:l}=JSON.parse(await Oi(t,s.pubkey,s.content));if(c==="auth_url"&&o[i]){delete r[i],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[i];a&&(l?a.reject(l):c&&a.resolve(c),delete r[i])}}),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}`,s=await $i(this.secretKey,this.bp.pubkey,JSON.stringify({id:o,method:t,params:e})),i=Bi({kind:pn,tags:[["p",this.bp.pubkey]],content:s,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,i))}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",[kr(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&&Ar(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 Ue(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 Wi(t,e,n,r,o){if(o&&!Vi.test(o))throw new Error("Invalid email");let s=Ai(),i=new gn(s,t.bunkerPointer,e),c=await i.sendRequest("create_account",[n,r,o||""]);return i.bp.pubkey=c,await i.connect(),i}async function Zi(t,e){const n=await t.querySync(e,{kinds:[Pi],"#k":[pn.toString()]});return(await Promise.all(n.map(async o=>{try{const s=JSON.parse(o.content),i=await Nr(s.nip05);if(i&&i.pubkey===o.pubkey&&i.relays.length)return{bunkerPointer:i,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 Pr=/^(?:([\w.+-]+)@)?([\w_-]+(\.[\w_-]+)+)$/,Ur;try{Ur=fetch}catch{}async function Gi(t){var s;const e=t.match(Pr);if(!e)return null;const[n,r="_",o]=e;try{const i=`https://${o}/.well-known/nostr.json?name=${r}`,c=await(await Ur(i,{redirect:"error"})).json();let l=c.names[r];return l?{pubkey:l,relays:(s=c.relays)==null?void 0:s[l]}:null}catch{return null}}new TextDecoder("utf-8"),new TextEncoder;var Fi=5e3;function Ji(t){return Qi("npub",Ue(t))}function Yi(t,e){let n=_r.toWords(e);return _r.encode(t,n,Fi)}function Qi(t,e){return Yi(t,e)}const{window:Xi}=Jr;function Lr(t,e,n){const r=t.slice();return r[37]=e[n],r}function tc(t){let e,n,r,o,s,i,c,l;function a(h,w){if(h[9])return oc;if(!h[10])return rc;if(h[10])return nc}let f=a(t),u=f&&f(t);return{c(){e=L("div"),n=L("button"),r=tt("⤫"),s=D(),u&&u.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",i="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")},m(h,w){M(h,e,w),N(e,n),N(n,r),N(e,s),u&&u.m(e,null),c||(l=ct(n,"click",t[14]),c=!0)},p(h,w){w[0]&1&&o!==(o="tw-absolute tw-top-0 tw-right-0.5 tw-bg-transparent tw-border-none tw-cursor-pointer tw-text-"+h[0]+"-950 tw-text-3xl")&&$(n,"class",o),f===(f=a(h))&&u?u.p(h,w):(u&&u.d(1),u=f&&f(h),u&&(u.c(),u.m(e,null))),w[0]&1&&i!==(i="tw-w-80 tw-px-6 tw-py-8 tw-bg-"+h[0]+"-700 tw-rounded-md tw-shadow-[0_0px_30px_0px_rgba(0,0,0,0.6)] tw-transition-all tw-animate-show")&&$(e,"class",i)},d(h){h&&q(e),u&&u.d(),c=!1,l()}}}function ec(t){let e,n;function r(i,c){return i[8]?cc:i[10]?sc:ic}let o=r(t),s=o(t);return{c(){e=L("div"),s.c(),$(e,"class",n="tw-px-4 tw-py-2 tw-bg-"+t[0]+"-700 hover:tw-bg-"+t[0]+"-800 tw-rounded tw-cursor-pointer tw-shadow-[0_0px_10px_0px_rgba(0,0,0,0.3)]")},m(i,c){M(i,e,c),s.m(e,null)},p(i,c){o===(o=r(i))&&s?s.p(i,c):(s.d(1),s=o(i),s&&(s.c(),s.m(e,null))),c[0]&1&&n!==(n="tw-px-4 tw-py-2 tw-bg-"+i[0]+"-700 hover:tw-bg-"+i[0]+"-800 tw-rounded tw-cursor-pointer tw-shadow-[0_0px_10px_0px_rgba(0,0,0,0.3)]")&&$(e,"class",n)},d(i){i&&q(e),s.d()}}}function nc(t){let e,n,r,o,s,i,c=t[10].npub+"",l,a,f,u,h,w,p,d,g,b,y,E=nr(t[6])+"",A,O,v,_=(t[10].picture||t[10].name)&&Cr(t);return{c(){e=L("div"),n=L("div"),n.textContent="You are connected to Nostr as",r=D(),o=L("a"),_&&_.c(),s=D(),i=L("div"),l=tt(c),f=D(),u=L("button"),h=tt("Disconnect"),p=D(),d=L("div"),g=tt("This webpage is using the public key:"),b=L("br"),y=D(),A=tt(E),$(n,"class","tw-text-sm tw-mb-4"),$(i,"class","tw-block tw-break-all"),$(o,"target","_blank"),$(o,"href",a="https://nosta.me/"+t[10].npub),$(o,"class","tw-text-white tw-no-underline tw-group"),$(e,"class","tw-text-center"),$(u,"class",w="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(S,U){M(S,e,U),N(e,n),N(e,r),N(e,o),_&&_.m(o,null),N(o,s),N(o,i),N(i,l),M(S,f,U),M(S,u,U),N(u,h),M(S,p,U),M(S,d,U),N(d,g),N(d,b),N(d,y),N(d,A),O||(v=ct(u,"click",t[16]),O=!0)},p(S,U){S[10].picture||S[10].name?_?_.p(S,U):(_=Cr(S),_.c(),_.m(o,s)):_&&(_.d(1),_=null),U[0]&1024&&c!==(c=S[10].npub+"")&&fe(l,c),U[0]&1024&&a!==(a="https://nosta.me/"+S[10].npub)&&$(o,"href",a),U[0]&1&&w!==(w="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-"+S[0]+"-900 hover:tw-bg-"+S[0]+"-950 tw-hover:bg-indigo-900 tw-cursor-pointer tw-text-white")&&$(u,"class",w),U[0]&64&&E!==(E=nr(S[6])+"")&&fe(A,E)},d(S){S&&(q(e),q(f),q(u),q(p),q(d)),_&&_.d(),O=!1,v()}}}function rc(t){let e,n,r,o,s,i,c,l,a,f,u,h,w,p,d,g,b;return{c(){e=L("div"),e.textContent="How do you want to connect to Nostr?",n=D(),r=L("form"),o=L("input"),s=D(),i=L("button"),c=tt("Connect »"),f=D(),u=L("div"),h=tt("Do you need a Nostr account?"),w=L("br"),p=D(),d=L("button"),d.textContent="Sign up now",$(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,$(i,"class",l="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"),i.disabled=a=!t[12],$(r,"class","flex tw-mt-4 tw-mb-1"),$(d,"class","tw-border-0 tw-bg-transparent tw-text-white tw-cursor-pointer tw-underline tw-text-sm"),$(u,"class","tw-mt-6 tw-text-center tw-text-sm tw-leading-3")},m(y,E){M(y,e,E),M(y,n,E),M(y,r,E),N(r,o),t[24](o),qt(o,t[1]),N(r,s),N(r,i),N(i,c),M(y,f,E),M(y,u,E),N(u,h),N(u,w),N(u,p),N(u,d),o.focus(),g||(b=[ct(o,"input",t[25]),ct(r,"submit",t[15]),ct(d,"click",t[17])],g=!0)},p(y,E){E[0]&2&&o.value!==y[1]&&qt(o,y[1]),E[0]&1&&l!==(l="tw-block 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")&&$(i,"class",l),E[0]&4096&&a!==(a=!y[12])&&(i.disabled=a)},d(y){y&&(q(e),q(n),q(r),q(f),q(u)),t[24](null),g=!1,Ht(b)}}}function oc(t){let e,n,r,o,s,i,c,l,a,f,u,h,w,p,d,g,b,y,E,A,O,v,_,S,U=_n(t[11]),I=[];for(let B=0;B<U.length;B+=1)I[B]=qr(Lr(t,U,B));return{c(){e=L("div"),e.textContent="Create a Nostr account",n=D(),r=L("form"),o=L("div"),s=L("input"),i=D(),c=L("div"),c.textContent="@",l=D(),a=L("select");for(let B=0;B<I.length;B+=1)I[B].c();f=D(),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`,h=D(),w=L("button"),p=tt("Create »"),b=D(),y=L("div"),E=tt("Do you already have a Nostr address?"),A=L("br"),O=D(),v=L("button"),v.textContent="Login now",$(e,"class","tw-text-lg tw-text-center"),$(s,"class","tw-box-border tw-w-40 tw-px-2 tw-py-1 tw-rounded tw-text-lg tw-border-none tw-outline-none"),$(s,"placeholder","bob"),s.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[5]===void 0&&he(()=>t[23].call(a)),$(o,"class","tw-flex items-center"),$(u,"class","tw-text-sm tw-text-center tw-mt-4 tw-leading-4"),$(w,"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"),w.disabled=g=!t[5]||!t[4],$(r,"class","tw-mt-4 tw-mb-1"),$(v,"class","tw-border-0 tw-bg-transparent tw-text-white tw-cursor-pointer tw-underline tw-text-sm"),$(y,"class","tw-mt-6 tw-text-center tw-text-sm tw-leading-3")},m(B,K){M(B,e,K),M(B,n,K),M(B,r,K),N(r,o),N(o,s),t[21](s),qt(s,t[4]),N(o,i),N(o,c),N(o,l),N(o,a);for(let C=0;C<I.length;C+=1)I[C]&&I[C].m(a,null);mn(a,t[5],!0),N(r,f),N(r,u),N(r,h),N(r,w),N(w,p),M(B,b,K),M(B,y,K),N(y,E),N(y,A),N(y,O),N(y,v),s.focus(),_||(S=[ct(s,"input",t[22]),ct(s,"input",t[20]),ct(a,"change",t[23]),ct(r,"submit",t[19]),ct(v,"click",t[18])],_=!0)},p(B,K){if(K[0]&16&&s.value!==B[4]&&qt(s,B[4]),K[0]&2048){U=_n(B[11]);let C;for(C=0;C<U.length;C+=1){const rt=Lr(B,U,C);I[C]?I[C].p(rt,K):(I[C]=qr(rt),I[C].c(),I[C].m(a,null))}for(;C<I.length;C+=1)I[C].d(1);I.length=U.length}K[0]&2080&&mn(a,B[5]),K[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-"+B[0]+"-900 hover:tw-bg-"+B[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")&&$(w,"class",d),K[0]&2096&&g!==(g=!B[5]||!B[4])&&(w.disabled=g)},d(B){B&&(q(e),q(n),q(r),q(b),q(y)),t[21](null),Yr(I,B),_=!1,Ht(S)}}}function Cr(t){let e,n,r=t[10].picture&&Rr(t),o=t[10].name&&Hr(t);return{c(){e=L("div"),r&&r.c(),n=D(),o&&o.c(),$(e,"class","tw-flex tw-items-center tw-justify-center tw-gap-2 tw-mb-2")},m(s,i){M(s,e,i),r&&r.m(e,null),N(e,n),o&&o.m(e,null)},p(s,i){s[10].picture?r?r.p(s,i):(r=Rr(s),r.c(),r.m(e,n)):r&&(r.d(1),r=null),s[10].name?o?o.p(s,i):(o=Hr(s),o.c(),o.m(e,null)):o&&(o.d(1),o=null)},d(s){s&&q(e),r&&r.d(),o&&o.d()}}}function Rr(t){let e,n,r;return{c(){e=L("img"),ue(e.src,n=t[10].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,s){M(o,e,s)},p(o,s){s[0]&1024&&!ue(e.src,n=o[10].picture)&&$(e,"src",n),s[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&&q(e)}}}function Hr(t){let e,n=t[10].name+"",r;return{c(){e=L("div"),r=tt(n),$(e,"class","tw-text-3xl group-hover:tw-underline tw-decoration-2 tw-underline-offset-4")},m(o,s){M(o,e,s),N(e,r)},p(o,s){s[0]&1024&&n!==(n=o[10].name+"")&&fe(r,n)},d(o){o&&q(e)}}}function qr(t){let e,n,r;return{c(){e=L("option"),$(e,"label",n=t[37].domain),e.__value=r=t[37],qt(e,e.__value),$(e,"class","tw-px-2 tw-py-1 tw-text-lg")},m(o,s){M(o,e,s)},p(o,s){s[0]&2048&&n!==(n=o[37].domain)&&$(e,"label",n),s[0]&2048&&r!==(r=o[37])&&(e.__value=r,qt(e,e.__value))},d(o){o&&q(e)}}}function sc(t){let e,n,r=(t[10].name||t[10].npub.slice(0,7)+"…"+t[10].npub.slice(-4))+"",o;function s(l,a){return l[10].picture?ac:lc}let i=s(t),c=i(t);return{c(){e=L("div"),c.c(),n=D(),o=tt(r),$(e,"class","tw-flex tw-items-center")},m(l,a){M(l,e,a),c.m(e,null),N(e,n),N(e,o)},p(l,a){i===(i=s(l))&&c?c.p(l,a):(c.d(1),c=i(l),c&&(c.c(),c.m(e,n))),a[0]&1024&&r!==(r=(l[10].name||l[10].npub.slice(0,7)+"…"+l[10].npub.slice(-4))+"")&&fe(o,r)},d(l){l&&q(e),c.d()}}}function ic(t){let e;return{c(){e=tt("Login with Nostr")},m(n,r){M(n,e,r)},p:G,d(n){n&&q(e)}}}function cc(t){let e;return{c(){e=L("div"),e.textContent="Connecting to bunker..."},m(n,r){M(n,e,r)},p:G,d(n){n&&q(e)}}}function lc(t){let e;return{c(){e=tt("☉")},m(n,r){M(n,e,r)},p:G,d(n){n&&q(e)}}}function ac(t){let e,n;return{c(){e=L("img"),ue(e.src,n=t[10].picture)||$(e,"src",n),$(e,"alt",""),$(e,"class","tw-w-5 tw-h-5 tw-rounded-full tw-mr-2")},m(r,o){M(r,e,o)},p(r,o){o[0]&1024&&!ue(e.src,n=r[10].picture)&&$(e,"src",n)},d(r){r&&q(e)}}}function uc(t){let e,n,r;function o(c,l){return c[7]?tc:ec}let s=o(t),i=s(t);return{c(){e=L("div"),i.c(),$(e,"class","tw-text-white tw-font-sans"),xn(e,"tw-cursor-pointer",!t[10]&&!t[7])},m(c,l){M(c,e,l),i.m(e,null),n||(r=ct(Xi,"click",t[13]),n=!0)},p(c,l){s===(s=o(c))&&i?i.p(c,l):(i.d(1),i=s(c),i&&(i.c(),i.m(e,null))),l[0]&1152&&xn(e,"tw-cursor-pointer",!c[10]&&!c[7])},i:G,o:G,d(c){c&&q(e),i.d(),n=!1,r()}}}function fc(t,e,n){let r,{accent:o}=e;const s=window,i=new Zs;let c,l,a,f,u,h;const w=localStorage.getItem("nip46ClientSecretKey");w?h=Ue(w):(h=$s(),localStorage.setItem("nip46ClientSecretKey",J(h)));let p,d,g,b,y,E,A,O,v=[];S();let _={isWnj:!0,async getPublicKey(){return!y&&!A&&n(7,p=!0),(await b).bp.pubkey},async signEvent(T){return!y&&!A&&n(7,p=!0),(await b).signEvent(T)},async getRelays(){return!y&&!A&&n(7,p=!0),(await b).getRelays()},nip04:{async encrypt(T,z){return!y&&!A&&n(7,p=!0),(await b).nip04Encrypt(T,z)},async decrypt(T,z){return!y&&!A&&n(7,p=!0),(await b).nip04Decrypt(T,z)}}};function S(){n(7,p=!1),d=null,b=new Promise(T=>{g=T}),n(8,y=!1),n(9,E=!1),n(10,A=null),O=null}const U={pool:i,onauth(T){window.open(T,"window.nostr","width=600,height=800,popup=yes")}};eo(()=>{let T=localStorage.getItem("nip46BunkerPointer");if(T&&(d=JSON.parse(T),n(8,y=!0),R(new gn(h,d,U))),s.nostr&&!s.nostr.isWnj){s.destroyWnj();return}else Object.defineProperty(window,"nostr",{get(){return _},set(z){_=z,z.isWnj||s.destroyWnj()},configurable:!0});return()=>{O&&O.close()}});function I(T){T.composedPath().find(z=>z.id==="windowNostrModal")?n(7,p=!0):n(7,p=!1)}function B(T){n(7,p=!1),n(9,E=!1),T.stopPropagation()}async function K(T){if(T.preventDefault(),d=await Di(c.value),!d){c.setCustomValidity('invalid NIP-05 "name@domain.com" address or bunker:// URI');return}c.setCustomValidity(""),R(new gn(h,d,U))}async function C(T){T.preventDefault(),localStorage.removeItem("nip46BunkerPointer"),s.isWnj&&delete s.nostr,S()}async function rt(T){T.preventDefault(),n(9,E=!0),v.length===0&&(n(11,v=await Zi(i,["wss://relay.nostr.band"])),n(5,u=v[0]))}function x(T){n(9,E=!1)}async function k(T){if(T.preventDefault(),!u)return;let z=await Wi(u,U,a.value,u.domain);n(7,p=!0),n(9,E=!1),R(z)}const P=bo(async()=>{u&&a.value.length>0&&(await Gi(a.value+"@"+u.domain)?a.setCustomValidity(`'${a.value}' is already taken.`):a.setCustomValidity(""))},500);async function R(T){await T.connect(),n(10,A={pubkey:T.bp.pubkey,npub:Ji(T.bp.pubkey),event:null}),n(8,y=!1),localStorage.setItem("nip46BunkerPointer",JSON.stringify(d)),O=i.subscribeMany(["wss://purplepag.es","wss://relay.snort.social","wss://relay.nos.social"],[{kinds:[0],authors:[T.bp.pubkey]}],{onevent(z){var Ot;if(!((((Ot=A.event)==null?void 0:Ot.created_at)||0)>=z.created_at))try{let{name:lt,picture:le}=JSON.parse(z.content);n(10,A.event=z,A),n(10,A.name=lt,A),n(10,A.picture=le,A)}catch{}}}),n(7,p=!1),g(T)}function H(T){de[T?"unshift":"push"](()=>{a=T,n(3,a)})}function V(){f=this.value,n(4,f)}function Q(){u=Xr(this),n(5,u),n(11,v)}function X(T){de[T?"unshift":"push"](()=>{c=T,n(2,c)})}function wt(){l=this.value,n(1,l)}return t.$$set=T=>{"accent"in T&&n(0,o=T.accent)},t.$$.update=()=>{t.$$.dirty[0]&2&&n(12,r=l&&(l.match(Ir)||l.match(Pr)))},[o,l,c,a,f,u,h,p,y,E,A,v,r,I,B,K,C,rt,x,k,P,H,V,Q,X,wt]}class dc extends ho{constructor(e){super(),fo(this,e,fc,uc,Gr,{accent:0},null,[-1,-1])}}const Kr=window,Gt=document.createElement("div");Gt.style.position="fixed",Gt.style.right="1.5rem",((zr=Kr.wnjParams)==null?void 0:zr.position)==="bottom"?Gt.style.bottom="1.5rem":Gt.style.top="1.5rem",document.body.appendChild(Gt);const $e=document.createElement("div");$e.id="windowNostrModal",$e.classList.add("tw-animate-fadein");const Mr=document.createElement("style");Mr.innerHTML=Tt;const jr=Gt.attachShadow({mode:"open"});jr.appendChild($e),jr.appendChild(Mr);const hc=new dc({target:$e,props:{accent:((Vr=Kr.wnjParams)==null?void 0:Vr.accent)||"cyan"}});window.destroyWnj=()=>{hc.$destroy()}})();
1
+ var Uc=Object.defineProperty;var Lc=(Rt,D,kt)=>D in Rt?Uc(Rt,D,{enumerable:!0,configurable:!0,writable:!0,value:kt}):Rt[D]=kt;var y=(Rt,D,kt)=>(Lc(Rt,typeof D!="symbol"?D+"":D,kt),kt);(function(){"use strict";var Xr,to;const Rt='.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-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}.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-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 D(){}function kt(t){return t()}function An(){return Object.create(null)}function Ct(t){t.forEach(kt)}function Bn(t){return typeof t=="function"}function On(t,e){return t!=t?e==e:t!==e||t&&typeof t=="object"||typeof t=="function"}let pe;function ge(t,e){return t===e?!0:(pe||(pe=document.createElement("a")),pe.href=e,t===pe.href)}function no(t){return Object.keys(t).length===0}function ro(t,...e){if(t==null){for(const r of e)r(void 0);return D}const n=t.subscribe(...e);return n.unsubscribe?()=>n.unsubscribe():n}function oo(t,e,n){t.$$.on_destroy.push(ro(e,n))}const io=typeof window<"u"?window:typeof globalThis<"u"?globalThis:global;function L(t,e){t.appendChild(e)}function M(t,e,n){t.insertBefore(e,n||null)}function q(t){t.parentNode&&t.parentNode.removeChild(t)}function so(t,e){for(let n=0;n<t.length;n+=1)t[n]&&t[n].d(e)}function R(t){return document.createElement(t)}function et(t){return document.createTextNode(t)}function V(){return et(" ")}function nt(t,e,n,r){return t.addEventListener(e,n,r),()=>t.removeEventListener(e,n,r)}function O(t,e,n){n==null?t.removeAttribute(e):t.getAttribute(e)!==n&&t.setAttribute(e,n)}function co(t){return Array.from(t.childNodes)}function be(t,e){e=""+e,t.data!==e&&(t.data=e)}function Vt(t,e){t.value=e??""}function In(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 lo(t){const e=t.querySelector(":checked");return e&&e.__value}function Tn(t,e,n){t.classList.toggle(e,!!n)}let ne;function re(t){ne=t}function ao(){if(!ne)throw new Error("Function called outside component initialization");return ne}function uo(t){ao().$$.on_mount.push(t)}const Wt=[],oe=[];let Zt=[];const Nn=[],fo=Promise.resolve();let Re=!1;function ho(){Re||(Re=!0,fo.then(Pn))}function ye(t){Zt.push(t)}const Ce=new Set;let Gt=0;function Pn(){if(Gt!==0)return;const t=ne;do{try{for(;Gt<Wt.length;){const e=Wt[Gt];Gt++,re(e),wo(e.$$)}}catch(e){throw Wt.length=0,Gt=0,e}for(re(null),Wt.length=0,Gt=0;oe.length;)oe.pop()();for(let e=0;e<Zt.length;e+=1){const n=Zt[e];Ce.has(n)||(Ce.add(n),n())}Zt.length=0}while(Wt.length);for(;Nn.length;)Nn.pop()();Re=!1,Ce.clear(),re(t)}function wo(t){if(t.fragment!==null){t.update(),Ct(t.before_update);const e=t.dirty;t.dirty=[-1],t.fragment&&t.fragment.p(t.ctx,e),t.after_update.forEach(ye)}}function po(t){const e=[],n=[];Zt.forEach(r=>t.indexOf(r)===-1?e.push(r):n.push(r)),n.forEach(r=>r()),Zt=e}const go=new Set;function bo(t,e){t&&t.i&&(go.delete(t),t.i(e))}function Un(t){return(t==null?void 0:t.length)!==void 0?t:Array.from(t)}function yo(t,e,n){const{fragment:r,after_update:o}=t.$$;r&&r.m(e,n),ye(()=>{const i=t.$$.on_mount.map(kt).filter(Bn);t.$$.on_destroy?t.$$.on_destroy.push(...i):Ct(i),t.$$.on_mount=[]}),o.forEach(ye)}function mo(t,e){const n=t.$$;n.fragment!==null&&(po(n.after_update),Ct(n.on_destroy),n.fragment&&n.fragment.d(e),n.on_destroy=n.fragment=null,n.ctx=[])}function Eo(t,e){t.$$.dirty[0]===-1&&(Wt.push(t),ho(),t.$$.dirty.fill(0)),t.$$.dirty[e/31|0]|=1<<e%31}function xo(t,e,n,r,o,i,s=null,l=[-1]){const c=ne;re(t);const a=t.$$={fragment:null,ctx:[],props:i,update:D,not_equal:o,bound:An(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(e.context||(c?c.$$.context:[])),callbacks:An(),dirty:l,skip_bound:!1,root:e.target||c.$$.root};s&&s(a.root);let f=!1;if(a.ctx=n?n(t,e.props||{},(u,h,...w)=>{const g=w.length?w[0]:h;return a.ctx&&o(a.ctx[u],a.ctx[u]=g)&&(!a.skip_bound&&a.bound[u]&&a.bound[u](g),f&&Eo(t,u)),h}):[],a.update(),f=!0,Ct(a.before_update),a.fragment=r?r(a.ctx):!1,e.target){if(e.hydrate){const u=co(e.target);a.fragment&&a.fragment.l(u),u.forEach(q)}else a.fragment&&a.fragment.c();e.intro&&bo(t.$$.fragment),yo(t,e.target,e.anchor),Pn()}re(c)}class vo{constructor(){y(this,"$$");y(this,"$$set")}$destroy(){mo(this,1),this.$destroy=D}$on(e,n){if(!Bn(n))return D;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&&!no(e)&&(this.$$.skip_bound=!0,this.$$set(e),this.$$.skip_bound=!1)}}const _o="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(_o);function So(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var He={exports:{}};function Ln(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,l,c;function a(){const u=Date.now()-l;if(u<e&&u>=0)s=setTimeout(a,e-u);else if(s=void 0,!r){const h=o,w=i;o=void 0,i=void 0,c=t.apply(h,w)}}const f=function(...u){if(o&&this!==o)throw new Error("Debounced method called with different contexts.");o=this,i=u,l=Date.now();const h=r&&!s;if(s||(s=setTimeout(a,e)),h){const w=o,g=i;o=void 0,i=void 0,c=t.apply(w,g)}return c};return f.clear=()=>{s&&(clearTimeout(s),s=void 0)},f.flush=()=>{if(!s)return;const u=o,h=i;o=void 0,i=void 0,c=t.apply(u,h),clearTimeout(s),s=void 0},f}He.exports.debounce=Ln,He.exports=Ln;var ko=He.exports;const $n=So(ko),qe=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Rn=t=>t instanceof Uint8Array,je=t=>new DataView(t.buffer,t.byteOffset,t.byteLength),ft=(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 Ao=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function J(t){if(!Rn(t))throw new Error("Uint8Array expected");let e="";for(let n=0;n<t.length;n++)e+=Ao[t[n]];return e}function Me(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 Bo(t){if(typeof t!="string")throw new Error(`utf8ToBytes expected string, got ${typeof t}`);return new Uint8Array(new TextEncoder().encode(t))}function Cn(t){if(typeof t=="string"&&(t=Bo(t)),!Rn(t))throw new Error(`expected Uint8Array, got ${typeof t}`);return t}let Oo=class{clone(){return this._cloneInto()}};function Hn(t){const e=r=>t().update(Cn(r)).digest(),n=t();return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=()=>t(),e}function Io(t=32){if(qe&&typeof qe.getRandomValues=="function")return qe.getRandomValues(new Uint8Array(t));throw new Error("crypto.getRandomValues must be defined")}function qn(t){if(!Number.isSafeInteger(t)||t<0)throw new Error(`Wrong positive integer: ${t}`)}function jn(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 To(t){if(typeof t!="function"||typeof t.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");qn(t.outputLen),qn(t.blockLen)}function me(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 No(t,e){jn(t);const n=e.outputLen;if(t.length<n)throw new Error(`digestInto() expects output buffer of length at least ${n}`)}const Ke=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Mn=t=>t instanceof Uint8Array,ze=t=>new DataView(t.buffer,t.byteOffset,t.byteLength),dt=(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 Po(t){if(typeof t!="string")throw new Error(`utf8ToBytes expected string, got ${typeof t}`);return new Uint8Array(new TextEncoder().encode(t))}function De(t){if(typeof t=="string"&&(t=Po(t)),!Mn(t))throw new Error(`expected Uint8Array, got ${typeof t}`);return t}function Uo(...t){const e=new Uint8Array(t.reduce((r,o)=>r+o.length,0));let n=0;return t.forEach(r=>{if(!Mn(r))throw new Error("Uint8Array expected");e.set(r,n),n+=r.length}),e}class Kn{clone(){return this._cloneInto()}}function Lo(t){const e=r=>t().update(De(r)).digest(),n=t();return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=()=>t(),e}function zn(t=32){if(Ke&&typeof Ke.getRandomValues=="function")return Ke.getRandomValues(new Uint8Array(t));throw new Error("crypto.getRandomValues must be defined")}function $o(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),l=Number(n&i),c=r?4:0,a=r?0:4;t.setUint32(e+c,s,r),t.setUint32(e+a,l,r)}let Ro=class extends Kn{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=ze(this.buffer)}update(e){me(this);const{view:n,buffer:r,blockLen:o}=this;e=De(e);const i=e.length;for(let s=0;s<i;){const l=Math.min(o-this.pos,i-s);if(l===o){const c=ze(e);for(;o<=i-s;s+=o)this.process(c,s);continue}r.set(e.subarray(s,s+l),this.pos),this.pos+=l,s+=l,this.pos===o&&(this.process(n,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){me(this),No(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;$o(r,o-8,BigInt(this.length*8),i),this.process(r,0);const l=ze(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const a=c/4,f=this.get();if(a>f.length)throw new Error("_sha2: outputLen bigger than state");for(let u=0;u<a;u++)l.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:l}=this;return e.length=o,e.pos=l,e.finished=i,e.destroyed=s,o%n&&e.buffer.set(r),e}};const Co=(t,e,n)=>t&e^~t&n,Ho=(t,e,n)=>t&e^t&n^e&n,qo=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]),At=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Bt=new Uint32Array(64);let jo=class extends Ro{constructor(){super(64,32,8,!1),this.A=At[0]|0,this.B=At[1]|0,this.C=At[2]|0,this.D=At[3]|0,this.E=At[4]|0,this.F=At[5]|0,this.G=At[6]|0,this.H=At[7]|0}get(){const{A:e,B:n,C:r,D:o,E:i,F:s,G:l,H:c}=this;return[e,n,r,o,i,s,l,c]}set(e,n,r,o,i,s,l,c){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=l|0,this.H=c|0}process(e,n){for(let u=0;u<16;u++,n+=4)Bt[u]=e.getUint32(n,!1);for(let u=16;u<64;u++){const h=Bt[u-15],w=Bt[u-2],g=dt(h,7)^dt(h,18)^h>>>3,d=dt(w,17)^dt(w,19)^w>>>10;Bt[u]=d+Bt[u-7]+g+Bt[u-16]|0}let{A:r,B:o,C:i,D:s,E:l,F:c,G:a,H:f}=this;for(let u=0;u<64;u++){const h=dt(l,6)^dt(l,11)^dt(l,25),w=f+h+Co(l,c,a)+qo[u]+Bt[u]|0,d=(dt(r,2)^dt(r,13)^dt(r,22))+Ho(r,o,i)|0;f=a,a=c,c=l,l=s+w|0,s=i,i=o,o=r,r=w+d|0}r=r+this.A|0,o=o+this.B|0,i=i+this.C|0,s=s+this.D|0,l=l+this.E|0,c=c+this.F|0,a=a+this.G|0,f=f+this.H|0,this.set(r,o,i,s,l,c,a,f)}roundClean(){Bt.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};const Ve=Lo(()=>new jo);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Dn=BigInt(0),Ee=BigInt(1),Mo=BigInt(2),xe=t=>t instanceof Uint8Array,Ko=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function Ft(t){if(!xe(t))throw new Error("Uint8Array expected");let e="";for(let n=0;n<t.length;n++)e+=Ko[t[n]];return e}function Vn(t){const e=t.toString(16);return e.length&1?`0${e}`:e}function We(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);return BigInt(t===""?"0":`0x${t}`)}function Yt(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 We(Ft(t))}function Ze(t){if(!xe(t))throw new Error("Uint8Array expected");return We(Ft(Uint8Array.from(t).reverse()))}function Ot(t,e){return Yt(t.toString(16).padStart(e*2,"0"))}function Ge(t,e){return Ot(t,e).reverse()}function zo(t){return Yt(Vn(t))}function Y(t,e,n){let r;if(typeof e=="string")try{r=Yt(e)}catch(i){throw new Error(`${t} must be valid hex string, got "${e}". Cause: ${i}`)}else if(xe(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 Ht(...t){const e=new Uint8Array(t.reduce((r,o)=>r+o.length,0));let n=0;return t.forEach(r=>{if(!xe(r))throw new Error("Uint8Array expected");e.set(r,n),n+=r.length}),e}function Do(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 Vo(t){if(typeof t!="string")throw new Error(`utf8ToBytes expected string, got ${typeof t}`);return new Uint8Array(new TextEncoder().encode(t))}function Wo(t){let e;for(e=0;t>Dn;t>>=Ee,e+=1);return e}function Zo(t,e){return t>>BigInt(e)&Ee}const Go=(t,e,n)=>t|(n?Ee:Dn)<<BigInt(e),Fe=t=>(Mo<<BigInt(t-1))-Ee,Ye=t=>new Uint8Array(t),Wn=t=>Uint8Array.from(t);function Zn(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=Ye(t),o=Ye(t),i=0;const s=()=>{r.fill(1),o.fill(0),i=0},l=(...u)=>n(o,r,...u),c=(u=Ye())=>{o=l(Wn([0]),u),r=l(),u.length!==0&&(o=l(Wn([1]),u),r=l())},a=()=>{if(i++>=1e3)throw new Error("drbg: tried 1000 values");let u=0;const h=[];for(;u<e;){r=l();const w=r.slice();h.push(w),u+=r.length}return Ht(...h)};return(u,h)=>{s(),c(u);let w;for(;!(w=h(a()));)c();return s(),w}}const Fo={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 ie(t,e,n={}){const r=(o,i,s)=>{const l=Fo[i];if(typeof l!="function")throw new Error(`Invalid validator "${i}", expected function`);const c=t[o];if(!(s&&c===void 0)&&!l(c,t))throw new Error(`Invalid param ${String(o)}=${c} (${typeof c}), 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 Yo=Object.freeze(Object.defineProperty({__proto__:null,bitGet:Zo,bitLen:Wo,bitMask:Fe,bitSet:Go,bytesToHex:Ft,bytesToNumberBE:rt,bytesToNumberLE:Ze,concatBytes:Ht,createHmacDrbg:Zn,ensureBytes:Y,equalBytes:Do,hexToBytes:Yt,hexToNumber:We,numberToBytesBE:Ot,numberToBytesLE:Ge,numberToHexUnpadded:Vn,numberToVarBytesBE:zo,utf8ToBytes:Vo,validateObject:ie},Symbol.toStringTag,{value:"Module"}));/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Z=BigInt(0),z=BigInt(1),qt=BigInt(2),Jo=BigInt(3),Je=BigInt(4),Gn=BigInt(5),Fn=BigInt(8);BigInt(9),BigInt(16);function G(t,e){const n=t%e;return n>=Z?n:e+n}function Qo(t,e,n){if(n<=Z||e<Z)throw new Error("Expected power/modulo > 0");if(n===z)return Z;let r=z;for(;e>Z;)e&z&&(r=r*t%n),t=t*t%n,e>>=z;return r}function st(t,e,n){let r=t;for(;e-- >Z;)r*=r,r%=n;return r}function Qe(t,e){if(t===Z||e<=Z)throw new Error(`invert: expected positive integers, got n=${t} mod=${e}`);let n=G(t,e),r=e,o=Z,i=z;for(;n!==Z;){const l=r/n,c=r%n,a=o-i*l;r=n,n=c,o=i,i=a}if(r!==z)throw new Error("invert: does not exist");return G(o,e)}function Xo(t){const e=(t-z)/qt;let n,r,o;for(n=t-z,r=0;n%qt===Z;n/=qt,r++);for(o=qt;o<t&&Qo(o,e,t)!==t-z;o++);if(r===1){const s=(t+z)/Je;return function(c,a){const f=c.pow(a,s);if(!c.eql(c.sqr(f),a))throw new Error("Cannot find square root");return f}}const i=(n+z)/qt;return function(l,c){if(l.pow(c,e)===l.neg(l.ONE))throw new Error("Cannot find square root");let a=r,f=l.pow(l.mul(l.ONE,o),n),u=l.pow(c,i),h=l.pow(c,n);for(;!l.eql(h,l.ONE);){if(l.eql(h,l.ZERO))return l.ZERO;let w=1;for(let d=l.sqr(h);w<a&&!l.eql(d,l.ONE);w++)d=l.sqr(d);const g=l.pow(f,z<<BigInt(a-w-1));f=l.sqr(g),u=l.mul(u,g),h=l.mul(h,f),a=w}return u}}function ti(t){if(t%Je===Jo){const e=(t+z)/Je;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%Fn===Gn){const e=(t-Gn)/Fn;return function(r,o){const i=r.mul(o,qt),s=r.pow(i,e),l=r.mul(o,s),c=r.mul(r.mul(l,qt),s),a=r.mul(l,r.sub(c,r.ONE));if(!r.eql(r.sqr(a),o))throw new Error("Cannot find square root");return a}}return Xo(t)}const ei=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function ni(t){const e={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},n=ei.reduce((r,o)=>(r[o]="function",r),e);return ie(t,n)}function ri(t,e,n){if(n<Z)throw new Error("Expected power > 0");if(n===Z)return t.ONE;if(n===z)return e;let r=t.ONE,o=e;for(;n>Z;)n&z&&(r=t.mul(r,o)),o=t.sqr(o),n>>=z;return r}function oi(t,e){const n=new Array(e.length),r=e.reduce((i,s,l)=>t.is0(s)?i:(n[l]=i,t.mul(i,s)),t.ONE),o=t.inv(r);return e.reduceRight((i,s,l)=>t.is0(s)?i:(n[l]=t.mul(i,n[l]),t.mul(i,s)),o),n}function Yn(t,e){const n=e!==void 0?e:t.toString(2).length,r=Math.ceil(n/8);return{nBitLength:n,nByteLength:r}}function ii(t,e,n=!1,r={}){if(t<=Z)throw new Error(`Expected Field ORDER > 0, got ${t}`);const{nBitLength:o,nByteLength:i}=Yn(t,e);if(i>2048)throw new Error("Field lengths over 2048 bytes are not supported");const s=ti(t),l=Object.freeze({ORDER:t,BITS:o,BYTES:i,MASK:Fe(o),ZERO:Z,ONE:z,create:c=>G(c,t),isValid:c=>{if(typeof c!="bigint")throw new Error(`Invalid field element: expected bigint, got ${typeof c}`);return Z<=c&&c<t},is0:c=>c===Z,isOdd:c=>(c&z)===z,neg:c=>G(-c,t),eql:(c,a)=>c===a,sqr:c=>G(c*c,t),add:(c,a)=>G(c+a,t),sub:(c,a)=>G(c-a,t),mul:(c,a)=>G(c*a,t),pow:(c,a)=>ri(l,c,a),div:(c,a)=>G(c*Qe(a,t),t),sqrN:c=>c*c,addN:(c,a)=>c+a,subN:(c,a)=>c-a,mulN:(c,a)=>c*a,inv:c=>Qe(c,t),sqrt:r.sqrt||(c=>s(l,c)),invertBatch:c=>oi(l,c),cmov:(c,a,f)=>f?a:c,toBytes:c=>n?Ge(c,i):Ot(c,i),fromBytes:c=>{if(c.length!==i)throw new Error(`Fp.fromBytes: expected ${i}, got ${c.length}`);return n?Ze(c):rt(c)}});return Object.freeze(l)}function Jn(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 Qn(t){const e=Jn(t);return e+Math.ceil(e/2)}function si(t,e,n=!1){const r=t.length,o=Jn(e),i=Qn(e);if(r<16||r<i||r>1024)throw new Error(`expected ${i}-1024 bytes of input, got ${r}`);const s=n?rt(t):Ze(t),l=G(s,e-z)+z;return n?Ge(l,o):Ot(l,o)}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const ci=BigInt(0),Xe=BigInt(1);function li(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,l=o;for(;i>ci;)i&Xe&&(s=s.add(l)),l=l.double(),i>>=Xe;return s},precomputeWindow(o,i){const{windows:s,windowSize:l}=r(i),c=[];let a=o,f=a;for(let u=0;u<s;u++){f=a,c.push(f);for(let h=1;h<l;h++)f=f.add(a),c.push(f);a=f.double()}return c},wNAF(o,i,s){const{windows:l,windowSize:c}=r(o);let a=t.ZERO,f=t.BASE;const u=BigInt(2**o-1),h=2**o,w=BigInt(o);for(let g=0;g<l;g++){const d=g*c;let p=Number(s&u);s>>=w,p>c&&(p-=h,s+=Xe);const b=d,m=d+Math.abs(p)-1,x=g%2!==0,I=p<0;p===0?f=f.add(n(x,i[b])):a=a.add(n(I,i[m]))}return{p:a,f}},wNAFCached(o,i,s,l){const c=o._WINDOW_SIZE||1;let a=i.get(o);return a||(a=this.precomputeWindow(o,c),c!==1&&i.set(o,l(a))),this.wNAF(c,a,s)}}}function Xn(t){return ni(t.Fp),ie(t,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...Yn(t.n,t.nBitLength),...t,p:t.Fp.ORDER})}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function ai(t){const e=Xn(t);ie(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:ui,hexToBytes:fi}=Yo,jt={Err:class extends Error{constructor(e=""){super(e)}},_parseInt(t){const{Err:e}=jt;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:ui(r),l:t.subarray(n+2)}},toSig(t){const{Err:e}=jt,n=typeof t=="string"?fi(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}=jt._parseInt(n.subarray(2)),{d:s,l}=jt._parseInt(i);if(l.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,l=n(i),c=n(s);return`30${n(s+i+4)}02${c}${o}02${l}${r}`}},yt=BigInt(0),ct=BigInt(1);BigInt(2);const tr=BigInt(3);BigInt(4);function di(t){const e=ai(t),{Fp:n}=e,r=e.toBytes||((g,d,p)=>{const b=d.toAffine();return Ht(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),m=n.mul(b,g);return n.add(n.add(m,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"&&yt<g&&g<e.n}function l(g){if(!s(g))throw new Error("Expected valid bigint: 0 < bigint < curve.n")}function c(g){const{allowedPrivateKeyLengths:d,nByteLength:p,wrapPrivateKey:b,n:m}=e;if(d&&typeof g!="bigint"){if(g instanceof Uint8Array&&(g=Ft(g)),typeof g!="string"||!d.includes(g.length))throw new Error("Invalid key");g=g.padStart(p*2,"0")}let x;try{x=typeof g=="bigint"?g:rt(Y("private key",g,p))}catch{throw new Error(`private key must be ${p} bytes, hex or bigint, not ${typeof g}`)}return b&&(x=G(x,m)),l(x),x}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 m=x=>n.eql(x,n.ZERO);return m(p)&&m(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,m)=>b.toAffine(p[m])).map(u.fromAffine)}static fromHex(d){const p=u.fromAffine(o(Y("pointHex",d)));return p.assertValidity(),p}static fromPrivateKey(d){return u.BASE.multiply(c(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),m=i(d);if(!n.eql(b,m))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:m}=this,{px:x,py:I,pz:N}=d,v=n.eql(n.mul(p,N),n.mul(x,m)),_=n.eql(n.mul(b,N),n.mul(I,m));return v&&_}negate(){return new u(this.px,n.neg(this.py),this.pz)}double(){const{a:d,b:p}=e,b=n.mul(p,tr),{px:m,py:x,pz:I}=this;let N=n.ZERO,v=n.ZERO,_=n.ZERO,k=n.mul(m,m),$=n.mul(x,x),T=n.mul(I,I),A=n.mul(m,x);return A=n.add(A,A),_=n.mul(m,I),_=n.add(_,_),N=n.mul(d,_),v=n.mul(b,T),v=n.add(N,v),N=n.sub($,v),v=n.add($,v),v=n.mul(N,v),N=n.mul(A,N),_=n.mul(b,_),T=n.mul(d,T),A=n.sub(k,T),A=n.mul(d,A),A=n.add(A,_),_=n.add(k,k),k=n.add(_,k),k=n.add(k,T),k=n.mul(k,A),v=n.add(v,k),T=n.mul(x,I),T=n.add(T,T),k=n.mul(T,A),N=n.sub(N,k),_=n.mul(T,$),_=n.add(_,_),_=n.add(_,_),new u(N,v,_)}add(d){f(d);const{px:p,py:b,pz:m}=this,{px:x,py:I,pz:N}=d;let v=n.ZERO,_=n.ZERO,k=n.ZERO;const $=e.a,T=n.mul(e.b,tr);let A=n.mul(p,x),P=n.mul(b,I),C=n.mul(m,N),F=n.add(p,b),E=n.add(x,I);F=n.mul(F,E),E=n.add(A,P),F=n.sub(F,E),E=n.add(p,m);let S=n.add(x,N);return E=n.mul(E,S),S=n.add(A,C),E=n.sub(E,S),S=n.add(b,m),v=n.add(I,N),S=n.mul(S,v),v=n.add(P,C),S=n.sub(S,v),k=n.mul($,E),v=n.mul(T,C),k=n.add(v,k),v=n.sub(P,k),k=n.add(P,k),_=n.mul(v,k),P=n.add(A,A),P=n.add(P,A),C=n.mul($,C),E=n.mul(T,E),P=n.add(P,C),C=n.sub(A,C),C=n.mul($,C),E=n.add(E,C),A=n.mul(P,E),_=n.add(_,A),A=n.mul(S,E),v=n.mul(F,v),v=n.sub(v,A),A=n.mul(F,P),k=n.mul(S,k),k=n.add(k,A),new u(v,_,k)}subtract(d){return this.add(d.negate())}is0(){return this.equals(u.ZERO)}wNAF(d){return w.wNAFCached(this,a,d,p=>{const b=n.invertBatch(p.map(m=>m.pz));return p.map((m,x)=>m.toAffine(b[x])).map(u.fromAffine)})}multiplyUnsafe(d){const p=u.ZERO;if(d===yt)return p;if(l(d),d===ct)return this;const{endo:b}=e;if(!b)return w.unsafeLadder(this,d);let{k1neg:m,k1:x,k2neg:I,k2:N}=b.splitScalar(d),v=p,_=p,k=this;for(;x>yt||N>yt;)x&ct&&(v=v.add(k)),N&ct&&(_=_.add(k)),k=k.double(),x>>=ct,N>>=ct;return m&&(v=v.negate()),I&&(_=_.negate()),_=new u(n.mul(_.px,b.beta),_.py,_.pz),v.add(_)}multiply(d){l(d);let p=d,b,m;const{endo:x}=e;if(x){const{k1neg:I,k1:N,k2neg:v,k2:_}=x.splitScalar(p);let{p:k,f:$}=this.wNAF(N),{p:T,f:A}=this.wNAF(_);k=w.constTimeNegate(I,k),T=w.constTimeNegate(v,T),T=new u(n.mul(T.px,x.beta),T.py,T.pz),b=k.add(T),m=$.add(A)}else{const{p:I,f:N}=this.wNAF(p);b=I,m=N}return u.normalizeZ([b,m])[0]}multiplyAndAddUnsafe(d,p,b){const m=u.BASE,x=(N,v)=>v===yt||v===ct||!N.equals(m)?N.multiplyUnsafe(v):N.multiply(v),I=x(this,p).add(x(d,b));return I.is0()?void 0:I}toAffine(d){const{px:p,py:b,pz:m}=this,x=this.is0();d==null&&(d=x?n.ONE:n.inv(m));const I=n.mul(p,d),N=n.mul(b,d),v=n.mul(m,d);if(x)return{x:n.ZERO,y:n.ZERO};if(!n.eql(v,n.ONE))throw new Error("invZ was invalid");return{x:I,y:N}}isTorsionFree(){const{h:d,isTorsionFree:p}=e;if(d===ct)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===ct?this:p?p(u,this):this.multiplyUnsafe(e.h)}toRawBytes(d=!0){return this.assertValidity(),r(u,this,d)}toHex(d=!0){return Ft(this.toRawBytes(d))}}u.BASE=new u(e.Gx,e.Gy,n.ONE),u.ZERO=new u(n.ZERO,n.ONE,n.ZERO);const h=e.nBitLength,w=li(u,e.endo?Math.ceil(h/2):h);return{CURVE:e,ProjectivePoint:u,normPrivateKeyToScalar:c,weierstrassEquation:i,isWithinCurveOrder:s}}function hi(t){const e=Xn(t);return ie(e,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...e})}function wi(t){const e=hi(t),{Fp:n,n:r}=e,o=n.BYTES+1,i=2*n.BYTES+1;function s(E){return yt<E&&E<n.ORDER}function l(E){return G(E,r)}function c(E){return Qe(E,r)}const{ProjectivePoint:a,normPrivateKeyToScalar:f,weierstrassEquation:u,isWithinCurveOrder:h}=di({...e,toBytes(E,S,U){const j=S.toAffine(),H=n.toBytes(j.x),K=Ht;return U?K(Uint8Array.from([S.hasEvenY()?2:3]),H):K(Uint8Array.from([4]),H,n.toBytes(j.y))},fromBytes(E){const S=E.length,U=E[0],j=E.subarray(1);if(S===o&&(U===2||U===3)){const H=rt(j);if(!s(H))throw new Error("Point is not on curve");const K=u(H);let X=n.sqrt(K);const tt=(X&ct)===ct;return(U&1)===1!==tt&&(X=n.neg(X)),{x:H,y:X}}else if(S===i&&U===4){const H=n.fromBytes(j.subarray(0,n.BYTES)),K=n.fromBytes(j.subarray(n.BYTES,2*n.BYTES));return{x:H,y:K}}else throw new Error(`Point of length ${S} was invalid. Expected ${o} compressed bytes or ${i} uncompressed bytes`)}}),w=E=>Ft(Ot(E,e.nByteLength));function g(E){const S=r>>ct;return E>S}function d(E){return g(E)?l(-E):E}const p=(E,S,U)=>rt(E.slice(S,U));class b{constructor(S,U,j){this.r=S,this.s=U,this.recovery=j,this.assertValidity()}static fromCompact(S){const U=e.nByteLength;return S=Y("compactSignature",S,U*2),new b(p(S,0,U),p(S,U,2*U))}static fromDER(S){const{r:U,s:j}=jt.toSig(Y("DER",S));return new b(U,j)}assertValidity(){if(!h(this.r))throw new Error("r must be 0 < r < CURVE.n");if(!h(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:U,s:j,recovery:H}=this,K=_(Y("msgHash",S));if(H==null||![0,1,2,3].includes(H))throw new Error("recovery id invalid");const X=H===2||H===3?U+e.n:U;if(X>=n.ORDER)throw new Error("recovery id 2 or 3 invalid");const tt=H&1?"03":"02",pt=a.fromHex(tt+w(X)),gt=c(X),$t=l(-K*gt),Dt=l(j*gt),bt=a.BASE.multiplyAndAddUnsafe(pt,$t,Dt);if(!bt)throw new Error("point at infinify");return bt.assertValidity(),bt}hasHighS(){return g(this.s)}normalizeS(){return this.hasHighS()?new b(this.r,l(-this.s),this.recovery):this}toDERRawBytes(){return Yt(this.toDERHex())}toDERHex(){return jt.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return Yt(this.toCompactHex())}toCompactHex(){return w(this.r)+w(this.s)}}const m={isValidPrivateKey(E){try{return f(E),!0}catch{return!1}},normPrivateKeyToScalar:f,randomPrivateKey:()=>{const E=Qn(e.n);return si(e.randomBytes(E),e.n)},precompute(E=8,S=a.BASE){return S._setWindowSize(E),S.multiply(BigInt(3)),S}};function x(E,S=!0){return a.fromPrivateKey(E).toRawBytes(S)}function I(E){const S=E instanceof Uint8Array,U=typeof E=="string",j=(S||U)&&E.length;return S?j===o||j===i:U?j===2*o||j===2*i:E instanceof a}function N(E,S,U=!0){if(I(E))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(E)).toRawBytes(U)}const v=e.bits2int||function(E){const S=rt(E),U=E.length*8-e.nBitLength;return U>0?S>>BigInt(U):S},_=e.bits2int_modN||function(E){return l(v(E))},k=Fe(e.nBitLength);function $(E){if(typeof E!="bigint")throw new Error("bigint expected");if(!(yt<=E&&E<k))throw new Error(`bigint expected < 2^${e.nBitLength}`);return Ot(E,e.nByteLength)}function T(E,S,U=A){if(["recovered","canonical"].some(at=>at in U))throw new Error("sign() legacy options not supported");const{hash:j,randomBytes:H}=e;let{lowS:K,prehash:X,extraEntropy:tt}=U;K==null&&(K=!0),E=Y("msgHash",E),X&&(E=Y("prehashed msgHash",j(E)));const pt=_(E),gt=f(S),$t=[$(gt),$(pt)];if(tt!=null){const at=tt===!0?H(n.BYTES):tt;$t.push(Y("extraEntropy",at))}const Dt=Ht(...$t),bt=pt;function he(at){const _t=v(at);if(!h(_t))return;const ee=c(_t),ut=a.BASE.multiply(_t).toAffine(),ot=l(ut.x);if(ot===yt)return;const St=l(ee*l(bt+ot*gt));if(St===yt)return;let we=(ut.x===ot?0:2)|Number(ut.y&ct),Le=St;return K&&g(St)&&(Le=d(St),we^=1),new b(ot,Le,we)}return{seed:Dt,k2sig:he}}const A={lowS:e.lowS,prehash:!1},P={lowS:e.lowS,prehash:!1};function C(E,S,U=A){const{seed:j,k2sig:H}=T(E,S,U),K=e;return Zn(K.hash.outputLen,K.nByteLength,K.hmac)(j,H)}a.BASE._setWindowSize(8);function F(E,S,U,j=P){var ut;const H=E;if(S=Y("msgHash",S),U=Y("publicKey",U),"strict"in j)throw new Error("options.strict was renamed to lowS");const{lowS:K,prehash:X}=j;let tt,pt;try{if(typeof H=="string"||H instanceof Uint8Array)try{tt=b.fromDER(H)}catch(ot){if(!(ot instanceof jt.Err))throw ot;tt=b.fromCompact(H)}else if(typeof H=="object"&&typeof H.r=="bigint"&&typeof H.s=="bigint"){const{r:ot,s:St}=H;tt=new b(ot,St)}else throw new Error("PARSE");pt=a.fromHex(U)}catch(ot){if(ot.message==="PARSE")throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(K&&tt.hasHighS())return!1;X&&(S=e.hash(S));const{r:gt,s:$t}=tt,Dt=_(S),bt=c($t),he=l(Dt*bt),at=l(gt*bt),_t=(ut=a.BASE.multiplyAndAddUnsafe(pt,he,at))==null?void 0:ut.toAffine();return _t?l(_t.x)===gt:!1}return{CURVE:e,getPublicKey:x,getSharedSecret:N,sign:C,verify:F,ProjectivePoint:a,Signature:b,utils:m}}class er extends Kn{constructor(e,n){super(),this.finished=!1,this.destroyed=!1,To(e);const r=De(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 me(this),this.iHash.update(e),this}digestInto(e){me(this),jn(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:l}=this;return e=e,e.finished=o,e.destroyed=i,e.blockLen=s,e.outputLen=l,e.oHash=n._cloneInto(e.oHash),e.iHash=r._cloneInto(e.iHash),e}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}const nr=(t,e,n)=>new er(t,e).update(n).digest();nr.create=(t,e)=>new er(t,e);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function pi(t){return{hash:t,hmac:(e,...n)=>nr(t,e,Uo(...n)),randomBytes:zn}}function gi(t,e){const n=r=>wi({...t,...pi(r)});return Object.freeze({...n(e),create:n})}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const ve=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),_e=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),rr=BigInt(1),Se=BigInt(2),or=(t,e)=>(t+e/Se)/e;function ir(t){const e=ve,n=BigInt(3),r=BigInt(6),o=BigInt(11),i=BigInt(22),s=BigInt(23),l=BigInt(44),c=BigInt(88),a=t*t*t%e,f=a*a*t%e,u=st(f,n,e)*f%e,h=st(u,n,e)*f%e,w=st(h,Se,e)*a%e,g=st(w,o,e)*w%e,d=st(g,i,e)*g%e,p=st(d,l,e)*d%e,b=st(p,c,e)*p%e,m=st(b,l,e)*d%e,x=st(m,n,e)*f%e,I=st(x,s,e)*g%e,N=st(I,r,e)*a%e,v=st(N,Se,e);if(!tn.eql(tn.sqr(v),t))throw new Error("Cannot find square root");return v}const tn=ii(ve,void 0,void 0,{sqrt:ir}),se=gi({a:BigInt(0),b:BigInt(7),Fp:tn,n:_e,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:t=>{const e=_e,n=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),r=-rr*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),i=n,s=BigInt("0x100000000000000000000000000000000"),l=or(i*t,e),c=or(-r*t,e);let a=G(t-l*n-c*o,e),f=G(-l*r-c*i,e);const u=a>s,h=f>s;if(u&&(a=e-a),h&&(f=e-f),a>s||f>s)throw new Error("splitScalar: Endomorphism failed, k="+t);return{k1neg:u,k1:a,k2neg:h,k2:f}}}},Ve),ke=BigInt(0),sr=t=>typeof t=="bigint"&&ke<t&&t<ve,bi=t=>typeof t=="bigint"&&ke<t&&t<_e,cr={};function Ae(t,...e){let n=cr[t];if(n===void 0){const r=Ve(Uint8Array.from(t,o=>o.charCodeAt(0)));n=Ht(r,r),cr[t]=n}return Ve(Ht(n,...e))}const en=t=>t.toRawBytes(!0).slice(1),nn=t=>Ot(t,32),rn=t=>G(t,ve),ce=t=>G(t,_e),on=se.ProjectivePoint,yi=(t,e,n)=>on.BASE.multiplyAndAddUnsafe(t,e,n);function sn(t){let e=se.utils.normPrivateKeyToScalar(t),n=on.fromPrivateKey(e);return{scalar:n.hasEvenY()?e:ce(-e),bytes:en(n)}}function lr(t){if(!sr(t))throw new Error("bad x: need 0 < x < p");const e=rn(t*t),n=rn(e*t+BigInt(7));let r=ir(n);r%Se!==ke&&(r=rn(-r));const o=new on(t,r,rr);return o.assertValidity(),o}function ar(...t){return ce(rt(Ae("BIP0340/challenge",...t)))}function mi(t){return sn(t).bytes}function Ei(t,e,n=zn(32)){const r=Y("message",t),{bytes:o,scalar:i}=sn(e),s=Y("auxRand",n,32),l=nn(i^rt(Ae("BIP0340/aux",s))),c=Ae("BIP0340/nonce",l,o,r),a=ce(rt(c));if(a===ke)throw new Error("sign failed: k is zero");const{bytes:f,scalar:u}=sn(a),h=ar(f,o,r),w=new Uint8Array(64);if(w.set(f,0),w.set(nn(ce(u+h*i)),32),!ur(w,r,o))throw new Error("sign: Invalid signature produced");return w}function ur(t,e,n){const r=Y("signature",t,64),o=Y("message",e),i=Y("publicKey",n,32);try{const s=lr(rt(i)),l=rt(r.subarray(0,32));if(!sr(l))return!1;const c=rt(r.subarray(32,64));if(!bi(c))return!1;const a=ar(nn(l),en(s),o),f=yi(s,c,ce(-a));return!(!f||!f.hasEvenY()||f.toAffine().x!==l)}catch{return!1}}const Q={getPublicKey:mi,sign:Ei,verify:ur,utils:{randomPrivateKey:se.utils.randomPrivateKey,lift_x:lr,pointToBytes:en,numberToBytesBE:Ot,bytesToNumberBE:rt,taggedHash:Ae,mod:G}};function cn(t){if(!Number.isSafeInteger(t)||t<0)throw new Error(`Wrong positive integer: ${t}`)}function xi(t){if(typeof t!="boolean")throw new Error(`Expected boolean, not ${t}`)}function fr(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 vi(t){if(typeof t!="function"||typeof t.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");cn(t.outputLen),cn(t.blockLen)}function _i(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 Si(t,e){fr(t);const n=e.outputLen;if(t.length<n)throw new Error(`digestInto() expects output buffer of length at least ${n}`)}const ln={number:cn,bool:xi,bytes:fr,hash:vi,exists:_i,output:Si};function ki(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),l=Number(n&i),c=r?4:0,a=r?0:4;t.setUint32(e+c,s,r),t.setUint32(e+a,l,r)}class Ai extends Oo{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){ln.exists(this);const{view:n,buffer:r,blockLen:o}=this;e=Cn(e);const i=e.length;for(let s=0;s<i;){const l=Math.min(o-this.pos,i-s);if(l===o){const c=je(e);for(;o<=i-s;s+=o)this.process(c,s);continue}r.set(e.subarray(s,s+l),this.pos),this.pos+=l,s+=l,this.pos===o&&(this.process(n,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){ln.exists(this),ln.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;ki(r,o-8,BigInt(this.length*8),i),this.process(r,0);const l=je(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const a=c/4,f=this.get();if(a>f.length)throw new Error("_sha2: outputLen bigger than state");for(let u=0;u<a;u++)l.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:l}=this;return e.length=o,e.pos=l,e.finished=i,e.destroyed=s,o%n&&e.buffer.set(r),e}}const Bi=(t,e,n)=>t&e^~t&n,Oi=(t,e,n)=>t&e^t&n^e&n,Ii=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);class dr extends Ai{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:l,H:c}=this;return[e,n,r,o,i,s,l,c]}set(e,n,r,o,i,s,l,c){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=l|0,this.H=c|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 h=Tt[u-15],w=Tt[u-2],g=ft(h,7)^ft(h,18)^h>>>3,d=ft(w,17)^ft(w,19)^w>>>10;Tt[u]=d+Tt[u-7]+g+Tt[u-16]|0}let{A:r,B:o,C:i,D:s,E:l,F:c,G:a,H:f}=this;for(let u=0;u<64;u++){const h=ft(l,6)^ft(l,11)^ft(l,25),w=f+h+Bi(l,c,a)+Ii[u]+Tt[u]|0,d=(ft(r,2)^ft(r,13)^ft(r,22))+Oi(r,o,i)|0;f=a,a=c,c=l,l=s+w|0,s=i,i=o,o=r,r=w+d|0}r=r+this.A|0,o=o+this.B|0,i=i+this.C|0,s=s+this.D|0,l=l+this.E|0,c=c+this.F|0,a=a+this.G|0,f=f+this.H|0,this.set(r,o,i,s,l,c,a,f)}roundClean(){Tt.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}}class Ti extends dr{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 an=Hn(()=>new dr);Hn(()=>new Ti);var Jt=Symbol("verified"),Ni=t=>t instanceof Object;function Pi(t){if(!Ni(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 Ui=new TextEncoder,Li=class{generateSecretKey(){return Q.utils.randomPrivateKey()}getPublicKey(e){return J(Q.getPublicKey(e))}finalizeEvent(e,n){const r=e;return r.pubkey=J(Q.getPublicKey(n)),r.id=un(r),r.sig=J(Q.sign(un(r),n)),r[Jt]=!0,r}verifyEvent(e){if(typeof e[Jt]=="boolean")return e[Jt];const n=un(e);if(n!==e.id)return e[Jt]=!1,!1;try{const r=Q.verify(e.sig,n,e.pubkey);return e[Jt]=r,r}catch{return e[Jt]=!1,!1}}};function $i(t){if(!Pi(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 un(t){let e=an(Ui.encode($i(t)));return J(e)}var Be=new Li,Ri=Be.generateSecretKey,hr=Be.getPublicKey;Be.finalizeEvent,Be.verifyEvent;var Mt=Symbol("verified"),Ci=t=>t instanceof Object;function Hi(t){if(!Ci(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 qi=new TextEncoder;function le(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 ji=class{constructor(e){y(this,"value");y(this,"next",null);y(this,"prev",null);this.value=e}},Mi=class{constructor(){y(this,"first");y(this,"last");this.first=null,this.last=null}enqueue(e){const n=new ji(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}},Ki=class{generateSecretKey(){return Q.utils.randomPrivateKey()}getPublicKey(e){return J(Q.getPublicKey(e))}finalizeEvent(e,n){const r=e;return r.pubkey=J(Q.getPublicKey(n)),r.id=fn(r),r.sig=J(Q.sign(fn(r),n)),r[Mt]=!0,r}verifyEvent(e){if(typeof e[Mt]=="boolean")return e[Mt];const n=fn(e);if(n!==e.id)return e[Mt]=!1,!1;try{const r=Q.verify(e.sig,n,e.pubkey);return e[Mt]=r,r}catch{return e[Mt]=!1,!1}}};function zi(t){if(!Hi(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 fn(t){let e=an(qi.encode(zi(t)));return J(e)}var Oe=new Ki;Oe.generateSecretKey,Oe.getPublicKey,Oe.finalizeEvent;var Di=Oe.verifyEvent,Vi=22242;function Wi(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 Zi(t,e){for(let n=0;n<t.length;n++)if(Wi(t[n],e))return!0;return!1}function Gi(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 Fi(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 Yi(t,e){return{kind:Vi,created_at:Math.floor(Date.now()/1e3),tags:[["relay",t],["challenge",e]],content:""}}async function Ji(){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 Qi=t=>(t[Mt]=!0,!0),wr;try{wr=WebSocket}catch{}var pr=class{constructor(e,n){y(this,"url");y(this,"_connected",!1);y(this,"onclose",null);y(this,"onnotice",e=>console.debug(`NOTICE from ${this.url}: ${e}`));y(this,"baseEoseTimeout",4400);y(this,"connectionTimeout",4400);y(this,"openSubs",new Map);y(this,"connectionTimeoutHandle");y(this,"connectionPromise");y(this,"openCountRequests",new Map);y(this,"openEventPublishes",new Map);y(this,"ws");y(this,"incomingMessageQueue",new Mi);y(this,"queueRunning",!1);y(this,"challenge");y(this,"serial",0);y(this,"verifyEvent");this.url=le(e),this.verifyEvent=n.verifyEvent}static async connect(e,n){const r=new pr(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 wr(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 Ji();this.queueRunning=!1}handleNext(){var r,o;const e=this.incomingMessageQueue.dequeue();if(!e)return!1;const n=Fi(e);if(n){const i=this.openSubs.get(n);if(!i)return;const s=Gi(e,"id"),l=(r=i.alreadyHaveEvent)==null?void 0:r.call(i,s);if((o=i.receivedEvent)==null||o.call(i,this,s),l)return}try{let i=JSON.parse(e);switch(i[0]){case"EVENT":{const s=this.openSubs.get(i[1]),l=i[2];this.verifyEvent(l)&&Zi(s.filters,l)&&s.onevent(l);return}case"COUNT":{const s=i[1],l=i[2],c=this.openCountRequests.get(s);c&&(c.resolve(l.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],l=i[2],c=i[3],a=this.openEventPublishes.get(s);l?a.resolve(c):a.reject(new Error(c)),this.openEventPublishes.delete(s);return}case"CLOSED":{const s=i[1],l=this.openSubs.get(s);if(!l)return;l.closed=!0,l.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(Yi(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 Xi(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()}},Xi=class{constructor(e,n,r,o){y(this,"relay");y(this,"id");y(this,"closed",!1);y(this,"eosed",!1);y(this,"filters");y(this,"alreadyHaveEvent");y(this,"receivedEvent");y(this,"onevent");y(this,"oneose");y(this,"onclose");y(this,"eoseTimeout");y(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)}},ts=class{constructor(e){y(this,"relays",new Map);y(this,"seenOn",new Map);y(this,"trackRelays",!1);y(this,"verifyEvent");y(this,"trustedRelayURLs",new Set);this.verifyEvent=e.verifyEvent}async ensureRelay(e,n){e=le(e);let r=this.relays.get(e);return r||(r=new pr(e,{verifyEvent:this.trustedRelayURLs.has(e)?Qi:this.verifyEvent}),n!=null&&n.connectionTimeout&&(r.connectionTimeout=n.connectionTimeout),this.relays.set(e,r)),await r.connect(),r}close(e){e.map(le).forEach(n=>{var r;(r=this.relays.get(n))==null||r.close()})}subscribeMany(e,n,r){this.trackRelays&&(r.receivedEvent=(h,w)=>{let g=this.seenOn.get(w);g||(g=new Set,this.seenOn.set(w,g)),g.add(h)});const o=new Set,i=[],s=[];let l=h=>{var w;s[h]=!0,s.filter(g=>g).length===e.length&&((w=r.oneose)==null||w.call(r),l=()=>{})};const c=[];let a=(h,w)=>{var g;l(h),c[h]=w,c.filter(d=>d).length===e.length&&((g=r.onclose)==null||g.call(r,c),a=()=>{})};const f=h=>{var g;if((g=r.alreadyHaveEvent)!=null&&g.call(r,h))return!0;const w=o.has(h);return o.add(h),w},u=Promise.all(e.map(le).map(async(h,w,g)=>{if(g.indexOf(h)!==w){a(w,"duplicate url");return}let d;try{d=await this.ensureRelay(h,{connectionTimeout:r.maxWait?Math.max(r.maxWait*.8,r.maxWait-1e3):void 0})}catch(b){a(w,(b==null?void 0:b.message)||String(b));return}let p=d.subscribe(n,{...r,oneose:()=>l(w),onclose:b=>a(w,b),alreadyHaveEvent:f,eoseTimeout:r.maxWait});i.push(p)}));return{async close(){await u,i.forEach(h=>{h.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(le).map(async(r,o,i)=>i.indexOf(r)!==o?Promise.reject("duplicate url"):(await this.ensureRelay(r)).publish(n))}},es=class extends ts{constructor(){super({verifyEvent:Di})}};function gr(t){return t instanceof Uint8Array||t!=null&&typeof t=="object"&&t.constructor.name==="Uint8Array"}function Kt(t,...e){if(!gr(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 Ie(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}function br(t,e){Kt(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)),ns=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 rs(t){if(typeof t!="string")throw new Error(`string expected, got ${typeof t}`);return new Uint8Array(new TextEncoder().encode(t))}function ae(t){if(typeof t=="string")t=rs(t);else if(gr(t))t=t.slice();else throw new Error(`Uint8Array expected, got ${typeof t}`);return t}const os=(t,e)=>(Object.assign(e,t),e),mt=16,dn=new Uint8Array(16),ht=it(dn),is=225,ss=(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^is<<24&-(o&1)}},lt=t=>(t>>>0&255)<<24|(t>>>8&255)<<16|(t>>>16&255)<<8|t>>>24&255|0;function cs(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 ls=t=>t>64*1024?8:t>1024?4:2;class yr{constructor(e,n){this.blockLen=mt,this.outputLen=mt,this.s0=0,this.s1=0,this.s2=0,this.s3=0,this.finished=!1,e=ae(e),Kt(e,16);const r=ns(e);let o=r.getUint32(0,!1),i=r.getUint32(4,!1),s=r.getUint32(8,!1),l=r.getUint32(12,!1);const c=[];for(let g=0;g<128;g++)c.push({s0:lt(o),s1:lt(i),s2:lt(s),s3:lt(l)}),{s0:o,s1:i,s2:s,s3:l}=ss(o,i,s,l);const a=ls(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,h=this.windowSize=2**a,w=[];for(let g=0;g<u;g++)for(let d=0;d<h;d++){let p=0,b=0,m=0,x=0;for(let I=0;I<a;I++){if(!(d>>>a-I-1&1))continue;const{s0:v,s1:_,s2:k,s3:$}=c[a*g+I];p^=v,b^=_,m^=k,x^=$}w.push({s0:p,s1:b,s2:m,s3:x})}this.t=w}_updateBlock(e,n,r,o){e^=this.s0,n^=this.s1,r^=this.s2,o^=this.s3;const{W:i,t:s,windowSize:l}=this;let c=0,a=0,f=0,u=0;const h=(1<<i)-1;let w=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 m=p>>>i*b&h,{s0:x,s1:I,s2:N,s3:v}=s[w*l+m];c^=x,a^=I,f^=N,u^=v,w+=1}}this.s0=c,this.s1=a,this.s2=f,this.s3=u}update(e){e=ae(e),Ie(this);const n=it(e),r=Math.floor(e.length/mt),o=e.length%mt;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&&(dn.set(e.subarray(r*mt)),this._updateBlock(ht[0],ht[1],ht[2],ht[3]),ht.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){Ie(this),br(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(mt);return this.digestInto(e),this.destroy(),e}}class as extends yr{constructor(e,n){e=ae(e);const r=cs(e.slice());super(r,n),r.fill(0)}update(e){e=ae(e),Ie(this);const n=it(e),r=e.length%mt,o=Math.floor(e.length/mt);for(let i=0;i<o;i++)this._updateBlock(lt(n[i*4+3]),lt(n[i*4+2]),lt(n[i*4+1]),lt(n[i*4+0]));return r&&(dn.set(e.subarray(o*mt)),this._updateBlock(lt(ht[3]),lt(ht[2]),lt(ht[1]),lt(ht[0])),ht.fill(0)),this}digestInto(e){Ie(this),br(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 mr(t){const e=(r,o)=>t(o,r.length).update(ae(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}mr((t,e)=>new yr(t,e)),mr((t,e)=>new as(t,e));const Nt=16,us=283;function hn(t){return t<<1^us&-(t>>7)}function Qt(t,e){let n=0;for(;e>0;e>>=1)n^=t&-(e&1),t=hn(t);return n}const wn=(()=>{let t=new Uint8Array(256);for(let n=0,r=1;n<256;n++,r^=hn(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})(),fs=wn.map((t,e)=>wn.indexOf(e)),ds=t=>t<<24|t>>>8,pn=t=>t<<8|t>>>24;function Er(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(pn),o=r.map(pn),i=o.map(pn),s=new Uint32Array(256*256),l=new Uint32Array(256*256),c=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],l[u]=o[a]^i[f],c[u]=t[a]<<8|t[f]}return{sbox:t,sbox2:c,T0:n,T1:r,T2:o,T3:i,T01:s,T23:l}}const gn=Er(wn,t=>Qt(t,3)<<24|t<<16|t<<8|Qt(t,2)),xr=Er(fs,t=>Qt(t,11)<<24|Qt(t,13)<<16|Qt(t,9)<<8|Qt(t,14)),hs=(()=>{const t=new Uint8Array(16);for(let e=0,n=1;e<16;e++,n=hn(n))t[e]=n;return t})();function vr(t){Kt(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}=gn,r=it(t),o=r.length,i=l=>wt(n,l,l,l,l),s=new Uint32Array(e+28);s.set(r);for(let l=o;l<s.length;l++){let c=s[l-1];l%o===0?c=i(ds(c))^hs[l/o-1]:o>6&&l%o===4&&(c=i(c)),s[l]=s[l-o]^c}return s}function ws(t){const e=vr(t),n=e.slice(),r=e.length,{sbox2:o}=gn,{T0:i,T1:s,T2:l,T3:c}=xr;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=wt(o,f,f,f,f);n[a]=i[u&255]^s[u>>>8&255]^l[u>>>16&255]^c[u>>>24]}return n}function Pt(t,e,n,r,o,i){return t[n<<8&65280|r>>>8&255]^e[o>>>8&65280|i>>>24&255]}function wt(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:l}=gn;let c=0;e^=t[c++],n^=t[c++],r^=t[c++],o^=t[c++];const a=t.length/4-2;for(let g=0;g<a;g++){const d=t[c++]^Pt(s,l,e,n,r,o),p=t[c++]^Pt(s,l,n,r,o,e),b=t[c++]^Pt(s,l,r,o,e,n),m=t[c++]^Pt(s,l,o,e,n,r);e=d,n=p,r=b,o=m}const f=t[c++]^wt(i,e,n,r,o),u=t[c++]^wt(i,n,r,o,e),h=t[c++]^wt(i,r,o,e,n),w=t[c++]^wt(i,o,e,n,r);return{s0:f,s1:u,s2:h,s3:w}}function ps(t,e,n,r,o){const{sbox2:i,T01:s,T23:l}=xr;let c=0;e^=t[c++],n^=t[c++],r^=t[c++],o^=t[c++];const a=t.length/4-2;for(let g=0;g<a;g++){const d=t[c++]^Pt(s,l,e,o,r,n),p=t[c++]^Pt(s,l,n,e,o,r),b=t[c++]^Pt(s,l,r,n,e,o),m=t[c++]^Pt(s,l,o,r,n,e);e=d,n=p,r=b,o=m}const f=t[c++]^wt(i,e,o,r,n),u=t[c++]^wt(i,n,e,o,r),h=t[c++]^wt(i,r,n,e,o),w=t[c++]^wt(i,o,r,n,e);return{s0:f,s1:u,s2:h,s3:w}}function Sr(t,e){if(!e)return new Uint8Array(t);if(Kt(e),e.length<t)throw new Error(`aes: wrong destination length, expected at least ${t}, got: ${e.length}`);return e}function gs(t){if(Kt(t),t.length%Nt!==0)throw new Error(`aes/(cbc-ecb).decrypt ciphertext should consist of blocks with size ${Nt}`)}function bs(t,e,n){let r=t.length;const o=r%Nt;if(!e&&o!==0)throw new Error("aec/(cbc-ecb): unpadded plaintext with disabled padding");const i=it(t);if(e){let c=Nt-o;c||(c=Nt),r=r+c}const s=Sr(r,n),l=it(s);return{b:i,o:l,out:s}}function ys(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 ms(t){const e=new Uint8Array(16),n=it(e);e.set(t);const r=Nt-t.length;for(let o=Nt-r;o<Nt;o++)e[o]=r;return n}const kr=os({blockSize:16,nonceLength:16},function(e,n,r={}){Kt(e),Kt(n,16);const o=!r.disablePadding;return{encrypt:(i,s)=>{const l=vr(e),{b:c,o:a,out:f}=bs(i,o,s),u=it(n);let h=u[0],w=u[1],g=u[2],d=u[3],p=0;for(;p+4<=c.length;)h^=c[p+0],w^=c[p+1],g^=c[p+2],d^=c[p+3],{s0:h,s1:w,s2:g,s3:d}=_r(l,h,w,g,d),a[p++]=h,a[p++]=w,a[p++]=g,a[p++]=d;if(o){const b=ms(i.subarray(p*4));h^=b[0],w^=b[1],g^=b[2],d^=b[3],{s0:h,s1:w,s2:g,s3:d}=_r(l,h,w,g,d),a[p++]=h,a[p++]=w,a[p++]=g,a[p++]=d}return l.fill(0),f},decrypt:(i,s)=>{gs(i);const l=ws(e),c=it(n),a=Sr(i.length,s),f=it(i),u=it(a);let h=c[0],w=c[1],g=c[2],d=c[3];for(let p=0;p+4<=f.length;){const b=h,m=w,x=g,I=d;h=f[p+0],w=f[p+1],g=f[p+2],d=f[p+3];const{s0:N,s1:v,s2:_,s3:k}=ps(l,h,w,g,d);u[p++]=N^b,u[p++]=v^m,u[p++]=_^x,u[p++]=k^I}return l.fill(0),ys(a,o)}}});/*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) */function Xt(t){if(!Number.isSafeInteger(t))throw new Error(`Wrong integer: ${t}`)}function Et(...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 xt(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(Xt(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 vt(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 Te(t,e="="){if(Xt(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 Ar(t){if(typeof t!="function")throw new Error("normalize fn should be function");return{encode:e=>e,decode:e=>t(e)}}function Br(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(Xt(s),s<0||s>=e)throw new Error(`Wrong integer: ${s}`)});;){let s=0,l=!0;for(let c=r;c<i.length;c++){const a=i[c],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[c]=Math.floor(f/n),!Number.isSafeInteger(i[c])||i[c]*n+s!==f)throw new Error("convertRadix: carry overflow");if(l)i[c]?l=!1:r=c;else continue}if(o.push(s),l)break}for(let s=0;s<t.length-1&&t[s]===0;s++)o.push(0);return o.reverse()}const Or=(t,e)=>e?Or(e,t%e):t,Ne=(t,e)=>t+(e-Or(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(Ne(e,n)>32)throw new Error(`convertRadix2: carry overflow from=${e} to=${n} carryBits=${Ne(e,n)}`);let o=0,i=0;const s=2**n-1,l=[];for(const c of t){if(Xt(c),c>=2**e)throw new Error(`convertRadix2: invalid data word=${c} from=${e}`);if(o=o<<e|c,i+e>32)throw new Error(`convertRadix2: carry overflow pos=${i} from=${e}`);for(i+=e;i>=n;i-=n)l.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&&l.push(o>>>0),l}function Es(t){return Xt(t),{encode:e=>{if(!(e instanceof Uint8Array))throw new Error("radix.encode input should be Uint8Array");return Br(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(Br(e,t,2**8))}}}function Ut(t,e=!1){if(Xt(t),t<=0||t>32)throw new Error("radix2: bits should be in (0..32]");if(Ne(8,t)>32||Ne(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 Ir(t){if(typeof t!="function")throw new Error("unsafeWrapper fn should be function");return function(...e){try{return t.apply(null,e)}catch{}}}const xs=Et(Ut(4),xt("0123456789ABCDEF"),vt("")),vs=Et(Ut(5),xt("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"),Te(5),vt(""));Et(Ut(5),xt("0123456789ABCDEFGHIJKLMNOPQRSTUV"),Te(5),vt("")),Et(Ut(5),xt("0123456789ABCDEFGHJKMNPQRSTVWXYZ"),vt(""),Ar(t=>t.toUpperCase().replace(/O/g,"0").replace(/[IL]/g,"1")));const ue=Et(Ut(6),xt("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),Te(6),vt("")),_s=Et(Ut(6),xt("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"),Te(6),vt("")),yn=t=>Et(Es(58),xt(t),vt("")),mn=yn("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");yn("123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"),yn("rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz");const Tr=[0,2,3,5,6,7,9,10,11],Ss={encode(t){let e="";for(let n=0;n<t.length;n+=8){const r=t.subarray(n,n+8);e+=mn.encode(r).padStart(Tr[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=Tr.indexOf(r.length),i=mn.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)}},En=Et(xt("qpzry9x8gf2tvdw0s3jn54khce6mua7l"),vt("")),Nr=[996825010,642813549,513874426,1027748829,705979059];function fe(t){const e=t>>25;let n=(t&33554431)<<5;for(let r=0;r<Nr.length;r++)(e>>r&1)===1&&(n^=Nr[r]);return n}function Pr(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=fe(o)^s>>5}o=fe(o);for(let i=0;i<r;i++)o=fe(o)^t.charCodeAt(i)&31;for(let i of e)o=fe(o)^i;for(let i=0;i<6;i++)o=fe(o);return o^=n,En.encode(bn([o%2**30],30,5,!1))}function Ur(t){const e=t==="bech32"?1:734539939,n=Ut(5),r=n.decode,o=n.encode,i=Ir(r);function s(f,u,h=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 w=f.length+7+u.length;if(h!==!1&&w>h)throw new TypeError(`Length ${w} exceeds limit ${h}`);return f=f.toLowerCase(),`${f}1${En.encode(u)}${Pr(f,u,e)}`}function l(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 h=f.toLowerCase();if(f!==h&&f!==f.toUpperCase())throw new Error("String must be lowercase or uppercase");f=h;const w=f.lastIndexOf("1");if(w===0||w===-1)throw new Error('Letter "1" must be present between prefix and data only');const g=f.slice(0,w),d=f.slice(w+1);if(d.length<6)throw new Error("Data must be at least 6 characters long");const p=En.decode(d).slice(0,-6),b=Pr(g,p,e);if(!d.endsWith(b))throw new Error(`Invalid checksum in ${f}: expected "${b}"`);return{prefix:g,words:p}}const c=Ir(l);function a(f){const{prefix:u,words:h}=l(f,!1);return{prefix:u,words:h,bytes:r(h)}}return{encode:s,decode:l,decodeToBytes:a,decodeUnsafe:c,fromWords:r,fromWordsUnsafe:i,toWords:o}}const Lr=Ur("bech32");Ur("bech32m");const ks={encode:t=>new TextDecoder().decode(t),decode:t=>new TextEncoder().encode(t)},As=Et(Ut(4),xt("0123456789abcdef"),vt(""),Ar(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:ks,hex:As,base16:xs,base32:vs,base64:ue,base64url:_s,base58:mn,base58xmr:Ss}).join(", ")}`;var zt=Symbol("verified"),Bs=t=>t instanceof Object;function Os(t){if(!Bs(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 Is=new TextDecoder("utf-8"),$r=new TextEncoder;function de(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(t){y(this,"value");y(this,"next",null);y(this,"prev",null);this.value=t}},Ns=class{constructor(){y(this,"first");y(this,"last");this.first=null,this.last=null}enqueue(t){const e=new Ts(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}},Ps=class{generateSecretKey(){return Q.utils.randomPrivateKey()}getPublicKey(t){return J(Q.getPublicKey(t))}finalizeEvent(t,e){const n=t;return n.pubkey=J(Q.getPublicKey(e)),n.id=xn(n),n.sig=J(Q.sign(xn(n),e)),n[zt]=!0,n}verifyEvent(t){if(typeof t[zt]=="boolean")return t[zt];const e=xn(t);if(e!==t.id)return t[zt]=!1,!1;try{const n=Q.verify(t.sig,e,t.pubkey);return t[zt]=n,n}catch{return t[zt]=!1,!1}}};function Us(t){if(!Os(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=an($r.encode(Us(t)));return J(e)}var Pe=new Ps,Ls=Pe.generateSecretKey,Rr=Pe.getPublicKey,$s=Pe.finalizeEvent,Cr=Pe.verifyEvent;async function Rs(t,e,n){const r=t instanceof Uint8Array?J(t):t,o=se.getSharedSecret(r,"02"+e),i=Hr(o);let s=Uint8Array.from(Io(16)),l=$r.encode(n),c=kr(i,s).encrypt(l),a=ue.encode(new Uint8Array(c)),f=ue.encode(new Uint8Array(s.buffer));return`${a}?iv=${f}`}async function Cs(t,e,n){const r=t instanceof Uint8Array?J(t):t;let[o,i]=n.split("?iv="),s=se.getSharedSecret(r,"02"+e),l=Hr(s),c=ue.decode(i),a=ue.decode(o),f=kr(l,c).decrypt(a);return Is.decode(f)}function Hr(t){return t.slice(1,33)}var Hs=/^(?:([\w.+-]+)@)?([\w_-]+(\.[\w_-]+)+)$/,qs;try{qs=fetch}catch{}var js=22242,vn=24133,Ms=31990;function Ks(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 zs(t,e){for(let n=0;n<t.length;n++)if(Ks(t[n],e))return!0;return!1}function Ds(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 Vs(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 Ws(t,e){return{kind:js,created_at:Math.floor(Date.now()/1e3),tags:[["relay",t],["challenge",e]],content:""}}async function Zs(){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 Gs=t=>(t[zt]=!0,!0),qr;try{qr=WebSocket}catch{}var jr=class{constructor(t,e){y(this,"url");y(this,"_connected",!1);y(this,"onclose",null);y(this,"onnotice",t=>console.debug(`NOTICE from ${this.url}: ${t}`));y(this,"baseEoseTimeout",4400);y(this,"connectionTimeout",4400);y(this,"openSubs",new Map);y(this,"connectionTimeoutHandle");y(this,"connectionPromise");y(this,"openCountRequests",new Map);y(this,"openEventPublishes",new Map);y(this,"ws");y(this,"incomingMessageQueue",new Ns);y(this,"queueRunning",!1);y(this,"challenge");y(this,"serial",0);y(this,"verifyEvent");this.url=de(t),this.verifyEvent=e.verifyEvent}static async connect(t,e){const n=new jr(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 qr(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 Zs();this.queueRunning=!1}handleNext(){var n,r;const t=this.incomingMessageQueue.dequeue();if(!t)return!1;const e=Vs(t);if(e){const o=this.openSubs.get(e);if(!o)return;const i=Ds(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)&&zs(i.filters,s)&&i.onevent(s);return}case"COUNT":{const i=o[1],s=o[2],l=this.openCountRequests.get(i);l&&(l.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],l=o[3],c=this.openEventPublishes.get(i);s?c.resolve(l):c.reject(new Error(l)),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(Ws(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 Fs(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()}},Fs=class{constructor(t,e,n,r){y(this,"relay");y(this,"id");y(this,"closed",!1);y(this,"eosed",!1);y(this,"filters");y(this,"alreadyHaveEvent");y(this,"receivedEvent");y(this,"onevent");y(this,"oneose");y(this,"onclose");y(this,"eoseTimeout");y(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)}},Ys=class{constructor(t){y(this,"relays",new Map);y(this,"seenOn",new Map);y(this,"trackRelays",!1);y(this,"verifyEvent");y(this,"trustedRelayURLs",new Set);this.verifyEvent=t.verifyEvent}async ensureRelay(t,e){t=de(t);let n=this.relays.get(t);return n||(n=new jr(t,{verifyEvent:this.trustedRelayURLs.has(t)?Gs:this.verifyEvent}),e!=null&&e.connectionTimeout&&(n.connectionTimeout=e.connectionTimeout),this.relays.set(t,n)),await n.connect(),n}close(t){t.map(de).forEach(e=>{var n;(n=this.relays.get(e))==null||n.close()})}subscribeMany(t,e,n){this.trackRelays&&(n.receivedEvent=(u,h)=>{let w=this.seenOn.get(h);w||(w=new Set,this.seenOn.set(h,w)),w.add(u)});const r=new Set,o=[],i=[];let s=u=>{var h;i[u]=!0,i.filter(w=>w).length===t.length&&((h=n.oneose)==null||h.call(n),s=()=>{})};const l=[];let c=(u,h)=>{var w;s(u),l[u]=h,l.filter(g=>g).length===t.length&&((w=n.onclose)==null||w.call(n,l),c=()=>{})};const a=u=>{var w;if((w=n.alreadyHaveEvent)!=null&&w.call(n,u))return!0;const h=r.has(u);return r.add(u),h},f=Promise.all(t.map(de).map(async(u,h,w)=>{if(w.indexOf(u)!==h){c(h,"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){c(h,(p==null?void 0:p.message)||String(p));return}let d=g.subscribe(e,{...n,oneose:()=>s(h),onclose:p=>c(h,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(de).map(async(n,r,o)=>o.indexOf(n)!==r?Promise.reject("duplicate url"):(await this.ensureRelay(n)).publish(e))}},Js=class extends Ys{constructor(){super({verifyEvent:Cr})}},Mr;try{Mr=fetch}catch{}var Kr=/^bunker:\/\/([0-9a-f]{64})\??([?\/\w:.=&%]*)$/,Qs=/^[^\s@]+@[^\s@]+\.[^\s@]+$/;async function Xs(t){let e=t.match(Kr);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 zr(t)}async function zr(t){const e=t.match(Hs);if(!e)return null;const[n,r="_",o]=e;try{const i=`https://${o}/.well-known/nostr.json?name=${r}`,s=await(await Mr(i,{redirect:"error"})).json();let l=s.names[r],c=s.nip46[l]||[];return{pubkey:l,relays:c,secret:null}}catch{return null}}var Ue=class{constructor(t,e,n={}){y(this,"pool");y(this,"subCloser");y(this,"isOpen");y(this,"serial");y(this,"idPrefix");y(this,"listeners");y(this,"waitingForAuth");y(this,"secretKey");y(this,"bp");if(e.relays.length===0)throw new Error("no relays are specified for this bunker");this.pool=n.pool||new Js,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:[vn],"#p":[Rr(this.secretKey)]}],{async onevent(i){const{id:s,result:l,error:c}=JSON.parse(await Cs(t,i.pubkey,i.content));if(l==="auth_url"&&o[s]){delete o[s],n.onauth?n.onauth(c):console.warn(`nostr-tools/nip46: remote signer ${e.pubkey} tried to send an "auth_url"='${c}' but there was no onauth() callback configured.`);return}let a=r[s];a&&(c?a.reject(c):l&&a.resolve(l),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 Rs(this.secretKey,this.bp.pubkey,JSON.stringify({id:o,method:t,params:e})),s=$s({kind:vn,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",[Rr(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&&Cr(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 Me(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 tc(t,e,n,r,o){if(o&&!Qs.test(o))throw new Error("Invalid email");let i=Ls(),s=new Ue(i,t.bunkerPointer,e),l=await s.sendRequest("create_account",[n,r,o||""]);return s.bp.pubkey=l,await s.connect(),s}async function ec(t,e){const n=await t.querySync(e,{kinds:[Ms],"#k":[vn.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(c=>JSON.parse(c.content).nip05===s.nip05)!==i)return}catch{}const l=await zr(s.nip05);if(l&&l.pubkey===o.pubkey&&l.relays.length)return{bunkerPointer:l,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 Dr=/^(?:([\w.+-]+)@)?([\w_-]+(\.[\w_-]+)+)$/,Vr;try{Vr=fetch}catch{}async function nc(t){var i;const e=t.match(Dr);if(!e)return null;const[n,r="_",o]=e;try{const s=`https://${o}/.well-known/nostr.json?name=${r}`,l=await(await Vr(s,{redirect:"error"})).json();let c=l.names[r];return c?{pubkey:c,relays:(i=l.relays)==null?void 0:i[c]}:null}catch{return null}}new TextDecoder("utf-8"),new TextEncoder;var rc=5e3;function oc(t){return sc("npub",Me(t))}function ic(t,e){let n=Lr.toWords(e);return Lr.encode(t,n,rc)}function sc(t,e){return ic(t,e)}const te=[];function cc(t,e=D){let n;const r=new Set;function o(l){if(On(t,l)&&(t=l,n)){const c=!te.length;for(const a of r)a[1](),te.push(a,t);if(c){for(let a=0;a<te.length;a+=2)te[a][0](te[a+1]);te.length=0}}}function i(l){o(l(t))}function s(l,c=D){const a=[l,c];return r.add(a),r.size===1&&(n=e(o,i)||D),l(t),()=>{r.delete(a),r.size===0&&n&&(n(),n=null)}}return{set:o,update:i,subscribe:s}}const lc=t=>{const{subscribe:e,set:n}=cc(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}},{window:ac}=io;function Wr(t,e,n){const r=t.slice();return r[58]=e[n],r}function uc(t){let e,n,r,o,i,s,l,c;function a(h,w){if(h[11])return wc;if(!h[12])return hc;if(h[12])return dc}let f=a(t),u=f&&f(t);return{c(){e=R("div"),n=R("button"),r=et("⤫"),i=V(),u&&u.c(),O(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"),O(e,"class",s="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[17])},m(h,w){M(h,e,w),L(e,n),L(n,r),L(e,i),u&&u.m(e,null),l||(c=nt(n,"click",t[21]),l=!0)},p(h,w){w[0]&1&&o!==(o="tw-absolute tw-top-0 tw-right-0.5 tw-bg-transparent tw-border-none tw-cursor-pointer tw-text-"+h[0]+"-950 tw-text-3xl")&&O(n,"class",o),f===(f=a(h))&&u?u.p(h,w):(u&&u.d(1),u=f&&f(h),u&&(u.c(),u.m(e,null))),w[0]&131073&&s!==(s="sm:tw-w-80 tw-px-6 tw-py-8 tw-bg-"+h[0]+"-700 tw-rounded-md tw-shadow-[0_0px_30px_0px_rgba(0,0,0,0.6)] tw-transition-all tw-animate-show "+h[17])&&O(e,"class",s)},d(h){h&&q(e),u&&u.d(),l=!1,c()}}}function fc(t){let e,n;function r(s,l){return s[10]?bc:s[12]?pc:gc}let o=r(t),i=o(t);return{c(){e=R("div"),i.c(),O(e,"class",n="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[17])},m(s,l){M(s,e,l),i.m(e,null)},p(s,l){o===(o=r(s))&&i?i.p(s,l):(i.d(1),i=o(s),i&&(i.c(),i.m(e,null))),l[0]&131073&&n!==(n="tw-px-4 tw-py-2 tw-bg-"+s[0]+"-700 hover:tw-bg-"+s[0]+"-800 tw-rounded tw-shadow-[0_0px_10px_0px_rgba(0,0,0,0.3)] tw-transition-all tw-duration-200 "+s[17])&&O(e,"class",n)},d(s){s&&q(e),i.d()}}}function dc(t){let e,n,r,o,i,s,l=t[12].npub+"",c,a,f,u,h,w,g,d,p,b,m,x=hr(t[9])+"",I,N,v,_=(t[12].picture||t[12].name)&&Zr(t);return{c(){e=R("div"),n=R("div"),n.textContent="You are connected to Nostr as",r=V(),o=R("a"),_&&_.c(),i=V(),s=R("div"),c=et(l),f=V(),u=R("button"),h=et("Disconnect"),g=V(),d=R("div"),p=et("This webpage is using the public key:"),b=R("br"),m=V(),I=et(x),O(n,"class","tw-text-sm tw-mb-4"),O(s,"class","tw-block tw-break-all"),O(o,"target","_blank"),O(o,"href",a="https://nosta.me/"+t[12].npub),O(o,"class","tw-text-white tw-no-underline tw-group"),O(e,"class","tw-text-center"),O(u,"class",w="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"),O(d,"class","tw-block tw-break-all tw-mt-6 tw-text-center tw-text-sm")},m(k,$){M(k,e,$),L(e,n),L(e,r),L(e,o),_&&_.m(o,null),L(o,i),L(o,s),L(s,c),M(k,f,$),M(k,u,$),L(u,h),M(k,g,$),M(k,d,$),L(d,p),L(d,b),L(d,m),L(d,I),N||(v=nt(u,"click",t[23]),N=!0)},p(k,$){k[12].picture||k[12].name?_?_.p(k,$):(_=Zr(k),_.c(),_.m(o,i)):_&&(_.d(1),_=null),$[0]&4096&&l!==(l=k[12].npub+"")&&be(c,l),$[0]&4096&&a!==(a="https://nosta.me/"+k[12].npub)&&O(o,"href",a),$[0]&1&&w!==(w="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")&&O(u,"class",w),$[0]&512&&x!==(x=hr(k[9])+"")&&be(I,x)},d(k){k&&(q(e),q(f),q(u),q(g),q(d)),_&&_.d(),N=!1,v()}}}function hc(t){let e,n,r,o,i,s,l,c,a,f,u,h,w,g,d,p,b;return{c(){e=R("div"),e.textContent="How do you want to connect to Nostr?",n=V(),r=R("form"),o=R("input"),i=V(),s=R("button"),l=et("Connect »"),f=V(),u=R("div"),h=et("Do you need a Nostr account?"),w=R("br"),g=V(),d=R("button"),d.textContent="Sign up now",O(e,"class","tw-text-lg tw-text-center"),O(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(o,"placeholder","user@provider or bunker://..."),o.autofocus=!0,O(s,"class",c="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"),s.disabled=a=!t[18],O(r,"class","flex tw-mt-4 tw-mb-1"),O(d,"class","tw-border-0 tw-bg-transparent tw-text-white tw-cursor-pointer tw-underline tw-text-sm"),O(u,"class","tw-mt-6 tw-text-center tw-text-sm tw-leading-3")},m(m,x){M(m,e,x),M(m,n,x),M(m,r,x),L(r,o),t[37](o),Vt(o,t[2]),L(r,i),L(r,s),L(s,l),M(m,f,x),M(m,u,x),L(u,h),L(u,w),L(u,g),L(u,d),o.focus(),p||(b=[nt(o,"input",t[38]),nt(r,"submit",t[22]),nt(d,"click",t[24])],p=!0)},p(m,x){x[0]&4&&o.value!==m[2]&&Vt(o,m[2]),x[0]&1&&c!==(c="tw-block tw-w-full tw-mt-4 tw-px-2 tw-py-1 tw-text-lg tw-rounded tw-border-0 tw-bg-"+m[0]+"-900 hover:tw-bg-"+m[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")&&O(s,"class",c),x[0]&262144&&a!==(a=!m[18])&&(s.disabled=a)},d(m){m&&(q(e),q(n),q(r),q(f),q(u)),t[37](null),p=!1,Ct(b)}}}function wc(t){let e,n,r,o,i,s,l,c,a,f,u,h,w,g,d,p,b,m,x,I,N,v,_,k,$=Un(t[13]),T=[];for(let A=0;A<$.length;A+=1)T[A]=Yr(Wr(t,$,A));return{c(){e=R("div"),e.textContent="Create a Nostr account",n=V(),r=R("form"),o=R("div"),i=R("input"),s=V(),l=R("div"),l.textContent="@",c=V(),a=R("select");for(let A=0;A<T.length;A+=1)T[A].c();f=V(),u=R("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`,h=V(),w=R("button"),g=et("Create »"),b=V(),m=R("div"),x=et("Do you already have a Nostr address?"),I=R("br"),N=V(),v=R("button"),v.textContent="Login now",O(e,"class","tw-text-lg tw-text-center"),O(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"),O(i,"placeholder","bob"),i.autofocus=!0,O(l,"class","tw-mx-2 tw-text-2xl"),O(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&&ye(()=>t[36].call(a)),O(o,"class","tw-flex items-center"),O(u,"class","tw-text-sm tw-text-center tw-mt-4 tw-leading-4"),O(w,"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"),w.disabled=p=!t[8]||!t[7],O(r,"class","tw-mt-4 tw-mb-1"),O(v,"class","tw-border-0 tw-bg-transparent tw-text-white tw-cursor-pointer tw-underline tw-text-sm"),O(m,"class","tw-mt-6 tw-text-center tw-text-sm tw-leading-3")},m(A,P){M(A,e,P),M(A,n,P),M(A,r,P),L(r,o),L(o,i),t[34](i),Vt(i,t[7]),L(o,s),L(o,l),L(o,c),L(o,a);for(let C=0;C<T.length;C+=1)T[C]&&T[C].m(a,null);In(a,t[8],!0),L(r,f),L(r,u),L(r,h),L(r,w),L(w,g),M(A,b,P),M(A,m,P),L(m,x),L(m,I),L(m,N),L(m,v),i.focus(),_||(k=[nt(i,"input",t[35]),nt(i,"input",t[27]),nt(a,"change",t[36]),nt(r,"submit",t[26]),nt(v,"click",t[25])],_=!0)},p(A,P){if(P[0]&128&&i.value!==A[7]&&Vt(i,A[7]),P[0]&8192){$=Un(A[13]);let C;for(C=0;C<$.length;C+=1){const F=Wr(A,$,C);T[C]?T[C].p(F,P):(T[C]=Yr(F),T[C].c(),T[C].m(a,null))}for(;C<T.length;C+=1)T[C].d(1);T.length=$.length}P[0]&8448&&In(a,A[8]),P[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")&&O(w,"class",d),P[0]&8576&&p!==(p=!A[8]||!A[7])&&(w.disabled=p)},d(A){A&&(q(e),q(n),q(r),q(b),q(m)),t[34](null),so(T,A),_=!1,Ct(k)}}}function Zr(t){let e,n,r=t[12].picture&&Gr(t),o=t[12].name&&Fr(t);return{c(){e=R("div"),r&&r.c(),n=V(),o&&o.c(),O(e,"class","tw-flex tw-items-center tw-justify-center tw-gap-2 tw-mb-2")},m(i,s){M(i,e,s),r&&r.m(e,null),L(e,n),o&&o.m(e,null)},p(i,s){i[12].picture?r?r.p(i,s):(r=Gr(i),r.c(),r.m(e,n)):r&&(r.d(1),r=null),i[12].name?o?o.p(i,s):(o=Fr(i),o.c(),o.m(e,null)):o&&(o.d(1),o=null)},d(i){i&&q(e),r&&r.d(),o&&o.d()}}}function Gr(t){let e,n,r;return{c(){e=R("img"),ge(e.src,n=t[12].picture)||O(e,"src",n),O(e,"alt",""),O(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){M(o,e,i)},p(o,i){i[0]&4096&&!ge(e.src,n=o[12].picture)&&O(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")&&O(e,"class",r)},d(o){o&&q(e)}}}function Fr(t){let e,n=t[12].name+"",r;return{c(){e=R("div"),r=et(n),O(e,"class","tw-text-3xl group-hover:tw-underline tw-decoration-2 tw-underline-offset-4")},m(o,i){M(o,e,i),L(e,r)},p(o,i){i[0]&4096&&n!==(n=o[12].name+"")&&be(r,n)},d(o){o&&q(e)}}}function Yr(t){let e,n,r;return{c(){e=R("option"),O(e,"label",n=t[58].domain),e.__value=r=t[58],Vt(e,e.__value),O(e,"class","tw-px-2 tw-py-1 tw-text-lg")},m(o,i){M(o,e,i)},p(o,i){i[0]&8192&&n!==(n=o[58].domain)&&O(e,"label",n),i[0]&8192&&r!==(r=o[58])&&(e.__value=r,Vt(e,e.__value))},d(o){o&&q(e)}}}function pc(t){let e,n,r=(t[12].name||t[12].npub.slice(0,7)+"…"+t[12].npub.slice(-4))+"",o;function i(c,a){return c[12].picture?mc:yc}let s=i(t),l=s(t);return{c(){e=R("div"),l.c(),n=V(),o=et(r),O(e,"class","tw-flex tw-items-center")},m(c,a){M(c,e,a),l.m(e,null),L(e,n),L(e,o)},p(c,a){s===(s=i(c))&&l?l.p(c,a):(l.d(1),l=s(c),l&&(l.c(),l.m(e,n))),a[0]&4096&&r!==(r=(c[12].name||c[12].npub.slice(0,7)+"…"+c[12].npub.slice(-4))+"")&&be(o,r)},d(c){c&&q(e),l.d()}}}function gc(t){let e;return{c(){e=et("Login with Nostr")},m(n,r){M(n,e,r)},p:D,d(n){n&&q(e)}}}function bc(t){let e;return{c(){e=R("div"),e.textContent="Connecting to bunker..."},m(n,r){M(n,e,r)},p:D,d(n){n&&q(e)}}}function yc(t){let e;return{c(){e=et("☉")},m(n,r){M(n,e,r)},p:D,d(n){n&&q(e)}}}function mc(t){let e,n;return{c(){e=R("img"),ge(e.src,n=t[12].picture)||O(e,"src",n),O(e,"alt",""),O(e,"class","tw-w-5 tw-h-5 tw-rounded-full tw-mr-2")},m(r,o){M(r,e,o)},p(r,o){o[0]&4096&&!ge(e.src,n=r[12].picture)&&O(e,"src",n)},d(r){r&&q(e)}}}function Ec(t){let e,n,r,o;function i(c,a){return c[16]?uc:fc}let s=i(t),l=s(t);return{c(){e=R("div"),l.c(),O(e,"class","tw-text-white tw-font-sans draggable tw-animate-fadein"),O(e,"style",n="position: fixed; "+(t[16]&&t[3]?"width: 100%;":"")+"; right: "+(t[16]&&t[3]?"0":t[1])+"px; user-select: none; "+(t[16]&&t[3]?"bottom: 0px":t[15]+":"+t[14]+"px")),Tn(e,"tw-cursor-pointer",!t[12]&&!t[16])},m(c,a){M(c,e,a),l.m(e,null),t[39](e),r||(o=[nt(ac,"click",t[20]),nt(e,"mouseup",t[30]),nt(e,"mousemove",t[29]),nt(e,"mousedown",t[28])],r=!0)},p(c,a){s===(s=i(c))&&l?l.p(c,a):(l.d(1),l=s(c),l&&(l.c(),l.m(e,null))),a[0]&114698&&n!==(n="position: fixed; "+(c[16]&&c[3]?"width: 100%;":"")+"; right: "+(c[16]&&c[3]?"0":c[1])+"px; user-select: none; "+(c[16]&&c[3]?"bottom: 0px":c[15]+":"+c[14]+"px"))&&O(e,"style",n),a[0]&69632&&Tn(e,"tw-cursor-pointer",!c[12]&&!c[16])},i:D,o:D,d(c){c&&q(e),l.d(),t[39](null),r=!1,Ct(o)}}}const Lt=20;function xc(t,e,n){let r,o,i,s,l,c;const a=lc("only screen and (max-width: 640px)");oo(t,a,B=>n(3,c=B));let f,{accent:u}=e,{position:h="top"}=e;const w=window,g=new es;let d,p,b,m,x,I;const N=localStorage.getItem("wnj:clientSecret");N?I=Me(N):(I=Ri(),localStorage.setItem("wnj:clientSecret",J(I)));let v="closed",_,k,$,T,A,P,C,F=[];const E=$n(()=>{switch(v){case"justopened":n(32,v="opened");break;case"justclosed":n(32,v="closed");break}},500);function S(){n(32,v="justopened"),E()}function U(){n(32,v="justclosed"),E()}H();let j={isWnj:!0,async getPublicKey(){return!T&&!P&&S(),(await $).bp.pubkey},async signEvent(B){return!T&&!P&&S(),(await $).signEvent(B)},async getRelays(){return!T&&!P&&S(),(await $).getRelays()},nip04:{async encrypt(B,W){return!T&&!P&&S(),(await $).nip04Encrypt(B,W)},async decrypt(B,W){return!T&&!P&&S(),(await $).nip04Decrypt(B,W)}}};function H(){U(),_=null,$=new Promise(B=>{k=B}),n(10,T=!1),n(11,A=!1),n(12,P=null),C=null}const K={pool:g,onauth(B){window.open(B,"window.nostr","width=600,height=800,popup=yes")}};uo(()=>{let B=localStorage.getItem("wnj:bunkerPointer");if(B&&(_=JSON.parse(B),n(10,T=!0),at(new Ue(I,_,K))),w.nostr&&!w.nostr.isWnj){w.destroyWnj();return}else Object.defineProperty(window,"nostr",{get(){return j},set(W){j=W,W.isWnj||w.destroyWnj()},configurable:!0});return()=>{C&&C.close()}});function X(B){if(!(Math.abs(s-St)>6||Date.now()-we>600)){if(T){at(new Ue(I,_,K));return}v==="justopened"||v==="justclosed"||(B.composedPath().find(W=>W.id==="wnj")?S():U())}}function tt(B){U(),n(11,A=!1),B.stopPropagation()}async function pt(B){if(B.preventDefault(),_=await Xs(d.value),!_){d.setCustomValidity('invalid NIP-05 "name@domain.com" address or bunker:// URI');return}d.setCustomValidity(""),at(new Ue(I,_,K))}async function gt(B){B.preventDefault(),localStorage.removeItem("wnj:bunkerPointer"),w.isWnj&&delete w.nostr,H()}async function $t(B){B.preventDefault(),n(11,A=!0),F.length===0&&(n(13,F=await ec(g,["wss://relay.nostr.band","wss://nos.lol","wss://nostr-pub.wellorder.net"])),n(8,x=F[0]))}function Dt(B){n(11,A=!1)}async function bt(B){if(B.preventDefault(),!x)return;let W=await tc(x,K,b.value,x.domain);S(),n(11,A=!1),at(W)}const he=$n(async()=>{x&&b.value.length>0&&(await nc(b.value+"@"+x.domain)?b.setCustomValidity(`'${b.value}' is already taken.`):b.setCustomValidity(""))},500);async function at(B){await B.connect(),_=B.bp,n(12,P={pubkey:B.bp.pubkey,npub:oc(B.bp.pubkey),event:null}),n(10,T=!1),localStorage.setItem("wnj:bunkerPointer",JSON.stringify(_)),C=g.subscribeMany(["wss://purplepag.es","wss://relay.snort.social","wss://relay.nos.social"],[{kinds:[0],authors:[B.bp.pubkey]}],{onevent(W){var $e;if(!(((($e=P.event)==null?void 0:$e.created_at)||0)>=W.created_at))try{let{name:eo,picture:Pc}=JSON.parse(W.content);n(12,P.event=W,P),n(12,P.name=eo,P),n(12,P.picture=Pc,P)}catch{}}}),U(),k(B)}let{right:_t=20}=e,ee=!1,ut=!1,ot,St,we;function Le(B){if(i)return;ee=!0;const W=f.getBoundingClientRect();ot=B.clientY-W.top,St=s,we=Date.now()}function Sc(B){ee&&(r==="top"?n(14,s=B.clientY):n(14,s=window.innerHeight-B.clientY),n(14,s-=ot),n(33,ut=!0),s<Lt&&n(14,s=Lt),s>window.innerHeight-Lt&&n(14,s=window.innerHeight-Lt))}function kc(){if(ee=!1,setTimeout(()=>{n(33,ut=!1)},10),ut){const B=f.getBoundingClientRect(),W=window.innerHeight,$e=W/2;B.top<$e?(n(15,r="top"),n(14,s=B.top)):(n(15,r="bottom"),n(14,s=W-B.bottom)),s<Lt&&n(14,s=Lt),localStorage.setItem("wnj:origin",r),localStorage.setItem("wnj:ypos",s.toString())}}function Ac(B){oe[B?"unshift":"push"](()=>{b=B,n(6,b)})}function Bc(){m=this.value,n(7,m)}function Oc(){x=lo(this),n(8,x),n(13,F)}function Ic(B){oe[B?"unshift":"push"](()=>{d=B,n(5,d)})}function Tc(){p=this.value,n(2,p)}function Nc(B){oe[B?"unshift":"push"](()=>{f=B,n(4,f)})}return t.$$set=B=>{"accent"in B&&n(0,u=B.accent),"position"in B&&n(31,h=B.position),"right"in B&&n(1,_t=B.right)},t.$$.update=()=>{t.$$.dirty[0]&8|t.$$.dirty[1]&1&&n(15,r=c?"bottom":localStorage.getItem("wnj:origin")||h),t.$$.dirty[0]&4&&n(18,o=p&&(p.match(Kr)||p.match(Dr))),t.$$.dirty[1]&2&&n(16,i=v==="justopened"||v==="opened"),t.$$.dirty[0]&8&&n(14,s=c?Lt:parseInt(localStorage.getItem("wnj:ypos")||"0")||Lt),t.$$.dirty[0]&1|t.$$.dirty[1]&4&&n(17,l=ut?"tw-cursor-grabbing tw-outline-dashed tw-outline-"+u+"-500 tw-outline-1 tw-outline-offset-4":"tw-outline-none")},[u,_t,p,c,f,d,b,m,x,I,T,A,P,F,s,r,i,l,o,a,X,tt,pt,gt,$t,Dt,bt,he,Le,Sc,kc,h,v,ut,Ac,Bc,Oc,Ic,Tc,Nc]}class vc extends vo{constructor(e){super(),xo(this,e,xc,Ec,On,{accent:0,position:31,right:1},null,[-1,-1])}}const _n=window;_n.destroyWnj=()=>{setTimeout(()=>{_c.$destroy()},1)};const Sn=document.createElement("div");Sn.style.zIndex="90000",document.body.appendChild(Sn);const kn=document.createElement("div");kn.id="wnj";const Jr=document.createElement("style");Jr.innerHTML=Rt;const Qr=Sn.attachShadow({mode:"open"});Qr.appendChild(kn),Qr.appendChild(Jr);const _c=new vc({target:kn,props:{accent:((Xr=_n.wnjParams)==null?void 0:Xr.accent)||"cyan",position:((to=_n.wnjParams)==null?void 0:to.position)==="bottom"?"bottom":"top"}})})();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "window.nostr.js",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "type": "module",
5
5
  "main": "dist/window.nostr.js",
6
6
  "devDependencies": {
@@ -23,6 +23,6 @@
23
23
  },
24
24
  "dependencies": {
25
25
  "debounce": "^2.0.0",
26
- "nostr-tools": "^2.3.0"
26
+ "nostr-tools": "2.3.1"
27
27
  }
28
28
  }
package/src/App.svelte CHANGED
@@ -13,7 +13,7 @@
13
13
  type BunkerSignerParams,
14
14
  createAccount,
15
15
  parseBunkerInput,
16
- fetchCustodialBunkers,
16
+ fetchBunkerProviders,
17
17
  type BunkerPointer,
18
18
  type BunkerProfile,
19
19
  BUNKER_REGEX
@@ -21,8 +21,17 @@
21
21
  import {NIP05_REGEX, queryProfile} from 'nostr-tools/nip05'
22
22
  import {npubEncode} from 'nostr-tools/nip19'
23
23
  import {onMount} from 'svelte'
24
+ import mediaQueryStore from './mediaQueryStore.js'
24
25
 
26
+ const mobileMode = mediaQueryStore('only screen and (max-width: 640px)')
27
+
28
+ let myself: HTMLDivElement
25
29
  export let accent: string
30
+ export let position: 'top' | 'bottom' = 'top'
31
+ $: origin = $mobileMode
32
+ ? 'bottom'
33
+ : (localStorage.getItem('wnj:origin') as 'top' | 'bottom' | null) ||
34
+ position
26
35
 
27
36
  const win = window as any
28
37
  const pool = new SimplePool()
@@ -32,15 +41,15 @@
32
41
  let nameInputValue: string
33
42
  let chosenProvider: BunkerProfile | undefined
34
43
  let clientSecret: Uint8Array
35
- const local = localStorage.getItem('nip46ClientSecretKey')
44
+ const local = localStorage.getItem('wnj:clientSecret')
36
45
  if (local) {
37
46
  clientSecret = hexToBytes(local)
38
47
  } else {
39
48
  clientSecret = generateSecretKey()
40
- localStorage.setItem('nip46ClientSecretKey', bytesToHex(clientSecret))
49
+ localStorage.setItem('wnj:clientSecret', bytesToHex(clientSecret))
41
50
  }
42
51
 
43
- let opened: Boolean
52
+ let state: 'opened' | 'closed' | 'justopened' | 'justclosed' = 'closed'
44
53
  let bunkerPointer: BunkerPointer | null
45
54
  let resolveBunker: (_: BunkerSigner) => void
46
55
  let bunker: Promise<BunkerSigner>
@@ -55,43 +64,67 @@
55
64
  }
56
65
  let metadataSub: SubCloser | null
57
66
  let providers: BunkerProfile[] = []
58
- reset()
59
67
 
60
68
  $: bunkerInputValueIsGood =
61
69
  bunkerInputValue &&
62
70
  (bunkerInputValue.match(BUNKER_REGEX) ||
63
71
  bunkerInputValue.match(NIP05_REGEX))
64
72
 
73
+ const delayedUpdateState = debounce(() => {
74
+ switch (state) {
75
+ case 'justopened':
76
+ state = 'opened'
77
+ break
78
+ case 'justclosed':
79
+ state = 'closed'
80
+ break
81
+ }
82
+ }, 500)
83
+
84
+ function open() {
85
+ state = 'justopened'
86
+ delayedUpdateState()
87
+ }
88
+
89
+ function close() {
90
+ state = 'justclosed'
91
+ delayedUpdateState()
92
+ }
93
+
94
+ $: opened = state === 'justopened' || state === 'opened'
95
+
96
+ reset()
97
+
65
98
  let windowNostr = {
66
99
  isWnj: true,
67
100
  async getPublicKey(): Promise<string> {
68
- if (!connecting && !connected) opened = true
101
+ if (!connecting && !connected) open()
69
102
  return (await bunker).bp.pubkey
70
103
  },
71
104
  async signEvent(event: NostrEvent): Promise<VerifiedEvent> {
72
- if (!connecting && !connected) opened = true
105
+ if (!connecting && !connected) open()
73
106
  return (await bunker).signEvent(event)
74
107
  },
75
108
  async getRelays(): Promise<{
76
109
  [url: string]: {read: boolean; write: boolean}
77
110
  }> {
78
- if (!connecting && !connected) opened = true
111
+ if (!connecting && !connected) open()
79
112
  return (await bunker).getRelays()
80
113
  },
81
114
  nip04: {
82
115
  async encrypt(pubkey: string, plaintext: string): Promise<string> {
83
- if (!connecting && !connected) opened = true
116
+ if (!connecting && !connected) open()
84
117
  return (await bunker).nip04Encrypt(pubkey, plaintext)
85
118
  },
86
119
  async decrypt(pubkey: string, ciphertext: string): Promise<string> {
87
- if (!connecting && !connected) opened = true
120
+ if (!connecting && !connected) open()
88
121
  return (await bunker).nip04Decrypt(pubkey, ciphertext)
89
122
  }
90
123
  }
91
124
  }
92
125
 
93
126
  function reset() {
94
- opened = false
127
+ close()
95
128
  bunkerPointer = null
96
129
  bunker = new Promise(resolve => {
97
130
  resolveBunker = resolve
@@ -110,7 +143,7 @@
110
143
  }
111
144
 
112
145
  onMount(() => {
113
- let data = localStorage.getItem('nip46BunkerPointer')
146
+ let data = localStorage.getItem('wnj:bunkerPointer')
114
147
  if (data) {
115
148
  bunkerPointer = JSON.parse(data)
116
149
  connecting = true
@@ -149,13 +182,26 @@
149
182
  })
150
183
 
151
184
  function handleClick(ev: MouseEvent) {
152
- if (ev.composedPath().find((el: any) => el.id === 'windowNostrModal'))
153
- opened = true
154
- else opened = false
185
+ if (Math.abs(ypos - yposStart) > 6 || Date.now() - clickStart > 600) {
186
+ return
187
+ }
188
+
189
+ if (connecting) {
190
+ // this could be because the popup window didn't open, so we try to open it again here
191
+ connect(
192
+ new BunkerSigner(clientSecret, bunkerPointer!, bunkerSignerParams)
193
+ )
194
+ return
195
+ }
196
+
197
+ if (state === 'justopened' || state === 'justclosed') return
198
+
199
+ if (ev.composedPath().find((el: any) => el.id === 'wnj')) open()
200
+ else close()
155
201
  }
156
202
 
157
203
  function handleCloseModal(ev: MouseEvent) {
158
- opened = false
204
+ close()
159
205
  creating = false
160
206
  ev.stopPropagation()
161
207
  }
@@ -176,7 +222,7 @@
176
222
 
177
223
  async function handleDisconnect(ev: MouseEvent) {
178
224
  ev.preventDefault()
179
- localStorage.removeItem('nip46BunkerPointer')
225
+ localStorage.removeItem('wnj:bunkerPointer')
180
226
  if (win.isWnj) delete win.nostr
181
227
  reset()
182
228
  }
@@ -185,7 +231,11 @@
185
231
  ev.preventDefault()
186
232
  creating = true
187
233
  if (providers.length === 0) {
188
- providers = await fetchCustodialBunkers(pool, ['wss://relay.nostr.band'])
234
+ providers = await fetchBunkerProviders(pool, [
235
+ 'wss://relay.nostr.band',
236
+ 'wss://nos.lol',
237
+ 'wss://nostr-pub.wellorder.net'
238
+ ])
189
239
  chosenProvider = providers[0]
190
240
  }
191
241
  }
@@ -204,7 +254,8 @@
204
254
  nameInput.value,
205
255
  chosenProvider.domain
206
256
  )
207
- opened = true
257
+
258
+ open()
208
259
  creating = false
209
260
 
210
261
  connect(bunker)
@@ -222,6 +273,7 @@
222
273
 
223
274
  async function connect(bunker: BunkerSigner) {
224
275
  await bunker.connect()
276
+ bunkerPointer = bunker.bp
225
277
 
226
278
  // set this so the floating thing will update
227
279
  connected = {
@@ -231,7 +283,7 @@
231
283
  }
232
284
  connecting = false
233
285
 
234
- localStorage.setItem('nip46BunkerPointer', JSON.stringify(bunkerPointer))
286
+ localStorage.setItem('wnj:bunkerPointer', JSON.stringify(bunkerPointer))
235
287
 
236
288
  // load metadata
237
289
  metadataSub = pool.subscribeMany(
@@ -256,21 +308,109 @@
256
308
  }
257
309
  )
258
310
 
259
- opened = false
311
+ close()
260
312
  resolveBunker(bunker)
261
313
  }
314
+
315
+ // $: console.log($mobileMode);
316
+
317
+ const BASE_YPOS = 20
318
+ export let right = 20
319
+ $: ypos = $mobileMode
320
+ ? BASE_YPOS
321
+ : parseInt(localStorage.getItem('wnj:ypos') || '0') || BASE_YPOS
322
+ let dragStarted = false
323
+ let hasMoved = false
324
+ let insidePosition: number
325
+ let yposStart: number
326
+ let clickStart: number
327
+ $: movingStyle = hasMoved
328
+ ? 'tw-cursor-grabbing tw-outline-dashed tw-outline-' +
329
+ accent +
330
+ '-500 tw-outline-1 tw-outline-offset-4'
331
+ : 'tw-outline-none'
332
+
333
+ function handleMouseDown(ev: MouseEvent) {
334
+ if (opened) return
335
+ dragStarted = true
336
+ const rect = myself.getBoundingClientRect()
337
+ insidePosition = ev.clientY - rect.top
338
+ yposStart = ypos
339
+ clickStart = Date.now()
340
+ }
341
+
342
+ function handleMouseMove(ev: MouseEvent) {
343
+ if (!dragStarted) return
344
+
345
+ if (origin === 'top') {
346
+ ypos = ev.clientY
347
+ } else {
348
+ ypos = window.innerHeight - ev.clientY
349
+ }
350
+ ypos -= insidePosition
351
+
352
+ hasMoved = true
353
+
354
+ // do not let the widget go outside the view
355
+ if (ypos < BASE_YPOS) {
356
+ ypos = BASE_YPOS
357
+ }
358
+ if (ypos > window.innerHeight - BASE_YPOS) {
359
+ ypos = window.innerHeight - BASE_YPOS
360
+ }
361
+ }
362
+
363
+ function handleMouseUp() {
364
+ dragStarted = false
365
+
366
+ setTimeout(() => {
367
+ hasMoved = false
368
+ }, 10)
369
+
370
+ if (hasMoved) {
371
+ const rect = myself.getBoundingClientRect()
372
+ const viewportHeight = window.innerHeight
373
+ const viewportMidpoint = viewportHeight / 2
374
+ if (rect.top < viewportMidpoint) {
375
+ origin = 'top'
376
+ ypos = rect.top
377
+ } else {
378
+ origin = 'bottom'
379
+ ypos = viewportHeight - rect.bottom
380
+ }
381
+
382
+ if (ypos < BASE_YPOS) {
383
+ ypos = BASE_YPOS
384
+ }
385
+
386
+ localStorage.setItem('wnj:origin', origin)
387
+ localStorage.setItem('wnj:ypos', ypos.toString())
388
+ }
389
+ }
262
390
  </script>
263
391
 
264
392
  <svelte:window on:click={handleClick} />
265
393
 
394
+ <!-- svelte-ignore a11y-no-static-element-interactions -->
266
395
  <div
267
- class="tw-text-white tw-font-sans"
396
+ class="tw-text-white tw-font-sans draggable tw-animate-fadein"
268
397
  class:tw-cursor-pointer={!connected && !opened}
398
+ style="position: fixed; {opened && $mobileMode
399
+ ? 'width: 100%;'
400
+ : ''}; right: {opened && $mobileMode
401
+ ? '0'
402
+ : right}px; user-select: none; {opened && $mobileMode
403
+ ? 'bottom: 0px'
404
+ : origin + ':' + ypos + 'px'}"
405
+ on:mouseup={handleMouseUp}
406
+ on:mousemove={handleMouseMove}
407
+ on:mousedown={handleMouseDown}
408
+ bind:this={myself}
269
409
  >
270
410
  <!-- Close status ################### -->
271
411
  {#if !opened}
272
412
  <div
273
- class="tw-px-4 tw-py-2 tw-bg-{accent}-700 hover:tw-bg-{accent}-800 tw-rounded tw-cursor-pointer tw-shadow-[0_0px_10px_0px_rgba(0,0,0,0.3)]"
413
+ class="tw-px-4 tw-py-2 tw-bg-{accent}-700 hover:tw-bg-{accent}-800 tw-rounded tw-shadow-[0_0px_10px_0px_rgba(0,0,0,0.3)] tw-transition-all tw-duration-200 {movingStyle}"
274
414
  >
275
415
  <!-- Connecting view ################### -->
276
416
  {#if connecting}
@@ -297,7 +437,7 @@
297
437
  <!-- Open status ################### -->
298
438
  {:else}
299
439
  <div
300
- class="tw-w-80 tw-px-6 tw-py-8 tw-bg-{accent}-700 tw-rounded-md tw-shadow-[0_0px_30px_0px_rgba(0,0,0,0.6)] tw-transition-all tw-animate-show"
440
+ class="sm:tw-w-80 tw-px-6 tw-py-8 tw-bg-{accent}-700 tw-rounded-md tw-shadow-[0_0px_30px_0px_rgba(0,0,0,0.6)] tw-transition-all tw-animate-show {movingStyle}"
301
441
  >
302
442
  <button
303
443
  on:click={handleCloseModal}
@@ -426,11 +566,11 @@
426
566
  </div>
427
567
 
428
568
  <!-- hack to preload tailwind colors:
429
- tw-bg-cyan-700 tw-bg-cyan-800 tw-bg-cyan-900 tw-bg-cyan-950 tw-text-cyan-950
430
- tw-bg-green-700 tw-bg-green-800 tw-bg-green-900 tw-bg-green-950 tw-text-green-950
431
- tw-bg-purple-700 tw-bg-purple-800 tw-bg-purple-900 tw-bg-purple-950 tw-text-purple-950
432
- tw-bg-red-700 tw-bg-red-800 tw-bg-red-900 tw-bg-red-950 tw-text-red-950
433
- tw-bg-orange-700 tw-bg-orange-800 tw-bg-orange-900 tw-bg-orange-950 tw-text-orange-950
434
- tw-bg-neutral-700 tw-bg-neutral-800 tw-bg-neutral-900 tw-bg-neutral-950 tw-text-neutral-950
435
- tw-bg-stone-700 tw-bg-stone-800 tw-bg-stone-900 tw-bg-stone-950 tw-text-stone-950
569
+ tw-bg-cyan-700 tw-bg-cyan-800 tw-bg-cyan-900 tw-bg-cyan-950 tw-text-cyan-950 tw-outline-cyan-500
570
+ tw-bg-green-700 tw-bg-green-800 tw-bg-green-900 tw-bg-green-950 tw-text-green-950 tw-outline-green-500
571
+ tw-bg-purple-700 tw-bg-purple-800 tw-bg-purple-900 tw-bg-purple-950 tw-text-purple-950 tw-outline-purple-500
572
+ tw-bg-red-700 tw-bg-red-800 tw-bg-red-900 tw-bg-red-950 tw-text-red-950 tw-outline-red-500
573
+ tw-bg-orange-700 tw-bg-orange-800 tw-bg-orange-900 tw-bg-orange-950 tw-text-orange-950 tw-outline-orange-500
574
+ tw-bg-neutral-700 tw-bg-neutral-800 tw-bg-neutral-900 tw-bg-neutral-950 tw-text-neutral-950 tw-outline-neutral-500
575
+ tw-bg-stone-700 tw-bg-stone-800 tw-bg-stone-900 tw-bg-stone-950 tw-text-stone-950 tw-outline-stone-500
436
576
  -->
package/src/main.ts CHANGED
@@ -12,19 +12,18 @@ import App from './App.svelte'
12
12
 
13
13
  const win = window as any
14
14
 
15
- const base = document.createElement('div')
16
- base.style.position = 'fixed'
17
- base.style.right = '1.5rem'
18
- if (win.wnjParams?.position === 'bottom') {
19
- base.style.bottom = '1.5rem'
20
- } else {
21
- base.style.top = '1.5rem'
15
+ win.destroyWnj = () => {
16
+ setTimeout(() => {
17
+ app.$destroy()
18
+ }, 1)
22
19
  }
20
+
21
+ const base = document.createElement('div')
22
+ base.style.zIndex = '90000'
23
23
  document.body.appendChild(base)
24
24
 
25
25
  const mountPoint = document.createElement('div')
26
- mountPoint.id = 'windowNostrModal'
27
- mountPoint.classList.add('tw-animate-fadein')
26
+ mountPoint.id = 'wnj'
28
27
 
29
28
  const style = document.createElement('style')
30
29
  style.innerHTML = styles
@@ -36,13 +35,9 @@ shadowRoot.appendChild(style)
36
35
  const app = new App({
37
36
  target: mountPoint,
38
37
  props: {
39
- accent: win.wnjParams?.accent || 'cyan'
38
+ accent: win.wnjParams?.accent || 'cyan',
39
+ position: win.wnjParams?.position === 'bottom' ? 'bottom' : 'top'
40
40
  }
41
41
  })
42
42
 
43
43
  export default app
44
-
45
- // ~
46
- ;(window as any).destroyWnj = () => {
47
- app.$destroy()
48
- }
@@ -0,0 +1,33 @@
1
+ import {writable} from 'svelte/store'
2
+
3
+ /**
4
+ * Svelte Media Query Store
5
+ * @param mediaQueryString { string }
6
+ */
7
+ export default mediaQueryString => {
8
+ const {subscribe, set} = writable(undefined, () => {
9
+ // Start observing media query
10
+ let mql = window.matchMedia(mediaQueryString)
11
+
12
+ // Set first media query result to the store
13
+ set(mql.matches)
14
+
15
+ // Called when media query state changes
16
+ const onchange = () => set(mql.matches)
17
+
18
+ // Listen for changes (need to support old `addListener` interface)
19
+ 'addEventListener' in mql
20
+ ? mql.addEventListener('change', onchange)
21
+ : mql.addListener(onchange)
22
+
23
+ // when no more listeners
24
+ return () => {
25
+ // stop listening (need to support old `removeListener` interface)
26
+ 'removeEventListener' in mql
27
+ ? mql.removeEventListener('change', onchange)
28
+ : mql.removeListener(onchange)
29
+ }
30
+ })
31
+
32
+ return {subscribe}
33
+ }