window.nostr.js 0.0.5 → 0.1.1
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 +1 -1
- package/dist/index.html +2 -2
- package/dist/window.nostr.js +2 -2
- package/index.html +1 -1
- package/package.json +2 -2
- package/src/App.svelte +40 -14
- package/src/main.ts +2 -2
package/README.md
CHANGED
|
@@ -4,4 +4,4 @@ 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://
|
|
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.
|
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-
|
|
7
|
+
<script type="module" crossorigin src="/assets/index-Wl5-BfAR.js"></script>
|
|
8
8
|
</head>
|
|
9
9
|
<body
|
|
10
10
|
style="
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
</p>
|
|
63
63
|
</main>
|
|
64
64
|
<!-- <script>
|
|
65
|
-
window.
|
|
65
|
+
window.wnjParams = {
|
|
66
66
|
position: 'bottom',
|
|
67
67
|
accent: 'green' // Supported values: cyan (default), green, purple, red, orange, neutral, stone
|
|
68
68
|
}
|
package/dist/window.nostr.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var ki=Object.defineProperty;var Si=(_t,G,pt)=>G in _t?ki(_t,G,{enumerable:!0,configurable:!0,writable:!0,value:pt}):_t[G]=pt;var b=(_t,G,pt)=>(Si(_t,typeof G!="symbol"?G+"":G,pt),pt);(function(){"use strict";var br,yr;const _t='.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 pt(e){return e()}function tn(){return Object.create(null)}function $t(e){e.forEach(pt)}function en(e){return typeof e=="function"}function vr(e,t){return e!=e?t==t:e!==t||e&&typeof e=="object"||typeof e=="function"}let Xt;function te(e,t){return e===t?!0:(Xt||(Xt=document.createElement("a")),Xt.href=t,e===Xt.href)}function _r(e){return Object.keys(e).length===0}const kr=typeof window<"u"?window:typeof globalThis<"u"?globalThis:global;function T(e,t){e.appendChild(t)}function j(e,t,n){e.insertBefore(t,n||null)}function q(e){e.parentNode&&e.parentNode.removeChild(e)}function Sr(e,t){for(let n=0;n<e.length;n+=1)e[n]&&e[n].d(t)}function P(e){return document.createElement(e)}function tt(e){return document.createTextNode(e)}function D(){return tt(" ")}function st(e,t,n,r){return e.addEventListener(t,n,r),()=>e.removeEventListener(t,n,r)}function B(e,t,n){n==null?e.removeAttribute(t):e.getAttribute(t)!==n&&e.setAttribute(t,n)}function Ar(e){return Array.from(e.childNodes)}function ee(e,t){t=""+t,e.data!==t&&(e.data=t)}function Nt(e,t){e.value=t??""}function nn(e,t,n){for(let r=0;r<e.options.length;r+=1){const o=e.options[r];if(o.__value===t){o.selected=!0;return}}(!n||t!==void 0)&&(e.selectedIndex=-1)}function Br(e){const t=e.querySelector(":checked");return t&&t.__value}function rn(e,t,n){e.classList.toggle(t,!!n)}let zt;function Vt(e){zt=e}function Or(){if(!zt)throw new Error("Function called outside component initialization");return zt}function Ir(e){Or().$$.on_mount.push(e)}const Tt=[],ne=[];let Ct=[];const on=[],$r=Promise.resolve();let ye=!1;function Nr(){ye||(ye=!0,$r.then(sn))}function re(e){Ct.push(e)}const me=new Set;let Pt=0;function sn(){if(Pt!==0)return;const e=zt;do{try{for(;Pt<Tt.length;){const t=Tt[Pt];Pt++,Vt(t),Tr(t.$$)}}catch(t){throw Tt.length=0,Pt=0,t}for(Vt(null),Tt.length=0,Pt=0;ne.length;)ne.pop()();for(let t=0;t<Ct.length;t+=1){const n=Ct[t];me.has(n)||(me.add(n),n())}Ct.length=0}while(Tt.length);for(;on.length;)on.pop()();ye=!1,me.clear(),Vt(e)}function Tr(e){if(e.fragment!==null){e.update(),$t(e.before_update);const t=e.dirty;e.dirty=[-1],e.fragment&&e.fragment.p(e.ctx,t),e.after_update.forEach(re)}}function Cr(e){const t=[],n=[];Ct.forEach(r=>e.indexOf(r)===-1?t.push(r):n.push(r)),n.forEach(r=>r()),Ct=t}const Pr=new Set;function Rr(e,t){e&&e.i&&(Pr.delete(e),e.i(t))}function cn(e){return(e==null?void 0:e.length)!==void 0?e:Array.from(e)}function Ur(e,t,n){const{fragment:r,after_update:o}=e.$$;r&&r.m(t,n),re(()=>{const s=e.$$.on_mount.map(pt).filter(en);e.$$.on_destroy?e.$$.on_destroy.push(...s):$t(s),e.$$.on_mount=[]}),o.forEach(re)}function Hr(e,t){const n=e.$$;n.fragment!==null&&(Cr(n.after_update),$t(n.on_destroy),n.fragment&&n.fragment.d(t),n.on_destroy=n.fragment=null,n.ctx=[])}function Lr(e,t){e.$$.dirty[0]===-1&&(Tt.push(e),Nr(),e.$$.dirty.fill(0)),e.$$.dirty[t/31|0]|=1<<t%31}function qr(e,t,n,r,o,s,i=null,c=[-1]){const a=zt;Vt(e);const u=e.$$={fragment:null,ctx:[],props:s,update:G,not_equal:o,bound:tn(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(t.context||(a?a.$$.context:[])),callbacks:tn(),dirty:c,skip_bound:!1,root:t.target||a.$$.root};i&&i(u.root);let f=!1;if(u.ctx=n?n(e,t.props||{},(l,h,...w)=>{const p=w.length?w[0]:h;return u.ctx&&o(u.ctx[l],u.ctx[l]=p)&&(!u.skip_bound&&u.bound[l]&&u.bound[l](p),f&&Lr(e,l)),h}):[],u.update(),f=!0,$t(u.before_update),u.fragment=r?r(u.ctx):!1,t.target){if(t.hydrate){const l=Ar(t.target);u.fragment&&u.fragment.l(l),l.forEach(q)}else u.fragment&&u.fragment.c();t.intro&&Rr(e.$$.fragment),Ur(e,t.target,t.anchor),sn()}Vt(a)}class Mr{constructor(){b(this,"$$");b(this,"$$set")}$destroy(){Hr(this,1),this.$destroy=G}$on(t,n){if(!en(n))return G;const r=this.$$.callbacks[t]||(this.$$.callbacks[t]=[]);return r.push(n),()=>{const o=r.indexOf(n);o!==-1&&r.splice(o,1)}}$set(t){this.$$set&&!_r(t)&&(this.$$.skip_bound=!0,this.$$set(t),this.$$.skip_bound=!1)}}const jr="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(jr);function Kr(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var xe={exports:{}};function an(e,t=100,n={}){if(typeof e!="function")throw new TypeError(`Expected the first parameter to be a function, got \`${typeof e}\`.`);if(t<0)throw new RangeError("`wait` must not be negative.");const{immediate:r}=typeof n=="boolean"?{immediate:n}:n;let o,s,i,c,a;function u(){const l=Date.now()-c;if(l<t&&l>=0)i=setTimeout(u,t-l);else if(i=void 0,!r){const h=o,w=s;o=void 0,s=void 0,a=e.apply(h,w)}}const f=function(...l){if(o&&this!==o)throw new Error("Debounced method called with different contexts.");o=this,s=l,c=Date.now();const h=r&&!i;if(i||(i=setTimeout(u,t)),h){const w=o,p=s;o=void 0,s=void 0,a=e.apply(w,p)}return a};return f.clear=()=>{i&&(clearTimeout(i),i=void 0)},f.flush=()=>{if(!i)return;const l=o,h=s;o=void 0,s=void 0,a=e.apply(l,h),clearTimeout(i),i=void 0},f}xe.exports.debounce=an,xe.exports=an;var zr=xe.exports;const Vr=Kr(zr),Ee=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */const ln=e=>e instanceof Uint8Array,ve=e=>new DataView(e.buffer,e.byteOffset,e.byteLength),at=(e,t)=>e<<32-t|e>>>t;if(!(new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68))throw new Error("Non little-endian hardware is not supported");const Dr=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function J(e){if(!ln(e))throw new Error("Uint8Array expected");let t="";for(let n=0;n<e.length;n++)t+=Dr[e[n]];return t}function _e(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);const t=e.length;if(t%2)throw new Error("padded hex string expected, got unpadded hex of length "+t);const n=new Uint8Array(t/2);for(let r=0;r<n.length;r++){const o=r*2,s=e.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 Wr(e){if(typeof e!="string")throw new Error(`utf8ToBytes expected string, got ${typeof e}`);return new Uint8Array(new TextEncoder().encode(e))}function un(e){if(typeof e=="string"&&(e=Wr(e)),!ln(e))throw new Error(`expected Uint8Array, got ${typeof e}`);return e}let Fr=class{clone(){return this._cloneInto()}};function fn(e){const t=r=>e().update(un(r)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function Gr(e=32){if(Ee&&typeof Ee.getRandomValues=="function")return Ee.getRandomValues(new Uint8Array(e));throw new Error("crypto.getRandomValues must be defined")}function dn(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`Wrong positive integer: ${e}`)}function hn(e,...t){if(!(e instanceof Uint8Array))throw new Error("Expected Uint8Array");if(t.length>0&&!t.includes(e.length))throw new Error(`Expected Uint8Array of length ${t}, not of length=${e.length}`)}function Zr(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");dn(e.outputLen),dn(e.blockLen)}function oe(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function Jr(e,t){hn(e);const n=t.outputLen;if(e.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 wn=e=>e instanceof Uint8Array,Se=e=>new DataView(e.buffer,e.byteOffset,e.byteLength),lt=(e,t)=>e<<32-t|e>>>t;if(!(new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68))throw new Error("Non little-endian hardware is not supported");function Yr(e){if(typeof e!="string")throw new Error(`utf8ToBytes expected string, got ${typeof e}`);return new Uint8Array(new TextEncoder().encode(e))}function Ae(e){if(typeof e=="string"&&(e=Yr(e)),!wn(e))throw new Error(`expected Uint8Array, got ${typeof e}`);return e}function Qr(...e){const t=new Uint8Array(e.reduce((r,o)=>r+o.length,0));let n=0;return e.forEach(r=>{if(!wn(r))throw new Error("Uint8Array expected");t.set(r,n),n+=r.length}),t}class pn{clone(){return this._cloneInto()}}function Xr(e){const t=r=>e().update(Ae(r)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function gn(e=32){if(ke&&typeof ke.getRandomValues=="function")return ke.getRandomValues(new Uint8Array(e));throw new Error("crypto.getRandomValues must be defined")}function to(e,t,n,r){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,n,r);const o=BigInt(32),s=BigInt(4294967295),i=Number(n>>o&s),c=Number(n&s),a=r?4:0,u=r?0:4;e.setUint32(t+a,i,r),e.setUint32(t+u,c,r)}let eo=class extends pn{constructor(t,n,r,o){super(),this.blockLen=t,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(t),this.view=Se(this.buffer)}update(t){oe(this);const{view:n,buffer:r,blockLen:o}=this;t=Ae(t);const s=t.length;for(let i=0;i<s;){const c=Math.min(o-this.pos,s-i);if(c===o){const a=Se(t);for(;o<=s-i;i+=o)this.process(a,i);continue}r.set(t.subarray(i,i+c),this.pos),this.pos+=c,i+=c,this.pos===o&&(this.process(n,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){oe(this),Jr(t,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 l=i;l<o;l++)n[l]=0;to(r,o-8,BigInt(this.length*8),s),this.process(r,0);const c=Se(t),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const u=a/4,f=this.get();if(u>f.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<u;l++)c.setUint32(4*l,f[l],s)}digest(){const{buffer:t,outputLen:n}=this;this.digestInto(t);const r=t.slice(0,n);return this.destroy(),r}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());const{blockLen:n,buffer:r,length:o,finished:s,destroyed:i,pos:c}=this;return t.length=o,t.pos=c,t.finished=s,t.destroyed=i,o%n&&t.buffer.set(r),t}};const no=(e,t,n)=>e&t^~e&n,ro=(e,t,n)=>e&t^e&n^t&n,oo=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]),gt=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),bt=new Uint32Array(64);let so=class extends eo{constructor(){super(64,32,8,!1),this.A=gt[0]|0,this.B=gt[1]|0,this.C=gt[2]|0,this.D=gt[3]|0,this.E=gt[4]|0,this.F=gt[5]|0,this.G=gt[6]|0,this.H=gt[7]|0}get(){const{A:t,B:n,C:r,D:o,E:s,F:i,G:c,H:a}=this;return[t,n,r,o,s,i,c,a]}set(t,n,r,o,s,i,c,a){this.A=t|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=a|0}process(t,n){for(let l=0;l<16;l++,n+=4)bt[l]=t.getUint32(n,!1);for(let l=16;l<64;l++){const h=bt[l-15],w=bt[l-2],p=lt(h,7)^lt(h,18)^h>>>3,d=lt(w,17)^lt(w,19)^w>>>10;bt[l]=d+bt[l-7]+p+bt[l-16]|0}let{A:r,B:o,C:s,D:i,E:c,F:a,G:u,H:f}=this;for(let l=0;l<64;l++){const h=lt(c,6)^lt(c,11)^lt(c,25),w=f+h+no(c,a,u)+oo[l]+bt[l]|0,d=(lt(r,2)^lt(r,13)^lt(r,22))+ro(r,o,s)|0;f=u,u=a,a=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,a=a+this.F|0,u=u+this.G|0,f=f+this.H|0,this.set(r,o,s,i,c,a,u,f)}roundClean(){bt.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};const Be=Xr(()=>new so);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const bn=BigInt(0),se=BigInt(1),io=BigInt(2),ie=e=>e instanceof Uint8Array,co=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Rt(e){if(!ie(e))throw new Error("Uint8Array expected");let t="";for(let n=0;n<e.length;n++)t+=co[e[n]];return t}function yn(e){const t=e.toString(16);return t.length&1?`0${t}`:t}function Oe(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return BigInt(e===""?"0":`0x${e}`)}function Ut(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);const t=e.length;if(t%2)throw new Error("padded hex string expected, got unpadded hex of length "+t);const n=new Uint8Array(t/2);for(let r=0;r<n.length;r++){const o=r*2,s=e.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(e){return Oe(Rt(e))}function Ie(e){if(!ie(e))throw new Error("Uint8Array expected");return Oe(Rt(Uint8Array.from(e).reverse()))}function yt(e,t){return Ut(e.toString(16).padStart(t*2,"0"))}function $e(e,t){return yt(e,t).reverse()}function ao(e){return Ut(yn(e))}function Z(e,t,n){let r;if(typeof t=="string")try{r=Ut(t)}catch(s){throw new Error(`${e} must be valid hex string, got "${t}". Cause: ${s}`)}else if(ie(t))r=Uint8Array.from(t);else throw new Error(`${e} must be hex string or Uint8Array`);const o=r.length;if(typeof n=="number"&&o!==n)throw new Error(`${e} expected ${n} bytes, got ${o}`);return r}function kt(...e){const t=new Uint8Array(e.reduce((r,o)=>r+o.length,0));let n=0;return e.forEach(r=>{if(!ie(r))throw new Error("Uint8Array expected");t.set(r,n),n+=r.length}),t}function lo(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}function uo(e){if(typeof e!="string")throw new Error(`utf8ToBytes expected string, got ${typeof e}`);return new Uint8Array(new TextEncoder().encode(e))}function fo(e){let t;for(t=0;e>bn;e>>=se,t+=1);return t}function ho(e,t){return e>>BigInt(t)&se}const wo=(e,t,n)=>e|(n?se:bn)<<BigInt(t),Ne=e=>(io<<BigInt(e-1))-se,Te=e=>new Uint8Array(e),mn=e=>Uint8Array.from(e);function xn(e,t,n){if(typeof e!="number"||e<2)throw new Error("hashLen must be a number");if(typeof t!="number"||t<2)throw new Error("qByteLen must be a number");if(typeof n!="function")throw new Error("hmacFn must be a function");let r=Te(e),o=Te(e),s=0;const i=()=>{r.fill(1),o.fill(0),s=0},c=(...l)=>n(o,r,...l),a=(l=Te())=>{o=c(mn([0]),l),r=c(),l.length!==0&&(o=c(mn([1]),l),r=c())},u=()=>{if(s++>=1e3)throw new Error("drbg: tried 1000 values");let l=0;const h=[];for(;l<t;){r=c();const w=r.slice();h.push(w),l+=r.length}return kt(...h)};return(l,h)=>{i(),a(l);let w;for(;!(w=h(u()));)a();return i(),w}}const po={bigint:e=>typeof e=="bigint",function:e=>typeof e=="function",boolean:e=>typeof e=="boolean",string:e=>typeof e=="string",stringOrUint8Array:e=>typeof e=="string"||e instanceof Uint8Array,isSafeInteger:e=>Number.isSafeInteger(e),array:e=>Array.isArray(e),field:(e,t)=>t.Fp.isValid(e),hash:e=>typeof e=="function"&&Number.isSafeInteger(e.outputLen)};function Dt(e,t,n={}){const r=(o,s,i)=>{const c=po[s];if(typeof c!="function")throw new Error(`Invalid validator "${s}", expected function`);const a=e[o];if(!(i&&a===void 0)&&!c(a,e))throw new Error(`Invalid param ${String(o)}=${a} (${typeof a}), expected ${s}`)};for(const[o,s]of Object.entries(t))r(o,s,!1);for(const[o,s]of Object.entries(n))r(o,s,!0);return e}const go=Object.freeze(Object.defineProperty({__proto__:null,bitGet:ho,bitLen:fo,bitMask:Ne,bitSet:wo,bytesToHex:Rt,bytesToNumberBE:et,bytesToNumberLE:Ie,concatBytes:kt,createHmacDrbg:xn,ensureBytes:Z,equalBytes:lo,hexToBytes:Ut,hexToNumber:Oe,numberToBytesBE:yt,numberToBytesLE:$e,numberToHexUnpadded:yn,numberToVarBytesBE:ao,utf8ToBytes:uo,validateObject:Dt},Symbol.toStringTag,{value:"Module"}));/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const W=BigInt(0),K=BigInt(1),St=BigInt(2),bo=BigInt(3),Ce=BigInt(4),En=BigInt(5),vn=BigInt(8);BigInt(9),BigInt(16);function F(e,t){const n=e%t;return n>=W?n:t+n}function yo(e,t,n){if(n<=W||t<W)throw new Error("Expected power/modulo > 0");if(n===K)return W;let r=K;for(;t>W;)t&K&&(r=r*e%n),e=e*e%n,t>>=K;return r}function rt(e,t,n){let r=e;for(;t-- >W;)r*=r,r%=n;return r}function Pe(e,t){if(e===W||t<=W)throw new Error(`invert: expected positive integers, got n=${e} mod=${t}`);let n=F(e,t),r=t,o=W,s=K;for(;n!==W;){const c=r/n,a=r%n,u=o-s*c;r=n,n=a,o=s,s=u}if(r!==K)throw new Error("invert: does not exist");return F(o,t)}function mo(e){const t=(e-K)/St;let n,r,o;for(n=e-K,r=0;n%St===W;n/=St,r++);for(o=St;o<e&&yo(o,t,e)!==e-K;o++);if(r===1){const i=(e+K)/Ce;return function(a,u){const f=a.pow(u,i);if(!a.eql(a.sqr(f),u))throw new Error("Cannot find square root");return f}}const s=(n+K)/St;return function(c,a){if(c.pow(a,t)===c.neg(c.ONE))throw new Error("Cannot find square root");let u=r,f=c.pow(c.mul(c.ONE,o),n),l=c.pow(a,s),h=c.pow(a,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<u&&!c.eql(d,c.ONE);w++)d=c.sqr(d);const p=c.pow(f,K<<BigInt(u-w-1));f=c.sqr(p),l=c.mul(l,p),h=c.mul(h,f),u=w}return l}}function xo(e){if(e%Ce===bo){const t=(e+K)/Ce;return function(r,o){const s=r.pow(o,t);if(!r.eql(r.sqr(s),o))throw new Error("Cannot find square root");return s}}if(e%vn===En){const t=(e-En)/vn;return function(r,o){const s=r.mul(o,St),i=r.pow(s,t),c=r.mul(o,i),a=r.mul(r.mul(c,St),i),u=r.mul(c,r.sub(a,r.ONE));if(!r.eql(r.sqr(u),o))throw new Error("Cannot find square root");return u}}return mo(e)}const Eo=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function vo(e){const t={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},n=Eo.reduce((r,o)=>(r[o]="function",r),t);return Dt(e,n)}function _o(e,t,n){if(n<W)throw new Error("Expected power > 0");if(n===W)return e.ONE;if(n===K)return t;let r=e.ONE,o=t;for(;n>W;)n&K&&(r=e.mul(r,o)),o=e.sqr(o),n>>=K;return r}function ko(e,t){const n=new Array(t.length),r=t.reduce((s,i,c)=>e.is0(i)?s:(n[c]=s,e.mul(s,i)),e.ONE),o=e.inv(r);return t.reduceRight((s,i,c)=>e.is0(i)?s:(n[c]=e.mul(s,n[c]),e.mul(s,i)),o),n}function _n(e,t){const n=t!==void 0?t:e.toString(2).length,r=Math.ceil(n/8);return{nBitLength:n,nByteLength:r}}function So(e,t,n=!1,r={}){if(e<=W)throw new Error(`Expected Field ORDER > 0, got ${e}`);const{nBitLength:o,nByteLength:s}=_n(e,t);if(s>2048)throw new Error("Field lengths over 2048 bytes are not supported");const i=xo(e),c=Object.freeze({ORDER:e,BITS:o,BYTES:s,MASK:Ne(o),ZERO:W,ONE:K,create:a=>F(a,e),isValid:a=>{if(typeof a!="bigint")throw new Error(`Invalid field element: expected bigint, got ${typeof a}`);return W<=a&&a<e},is0:a=>a===W,isOdd:a=>(a&K)===K,neg:a=>F(-a,e),eql:(a,u)=>a===u,sqr:a=>F(a*a,e),add:(a,u)=>F(a+u,e),sub:(a,u)=>F(a-u,e),mul:(a,u)=>F(a*u,e),pow:(a,u)=>_o(c,a,u),div:(a,u)=>F(a*Pe(u,e),e),sqrN:a=>a*a,addN:(a,u)=>a+u,subN:(a,u)=>a-u,mulN:(a,u)=>a*u,inv:a=>Pe(a,e),sqrt:r.sqrt||(a=>i(c,a)),invertBatch:a=>ko(c,a),cmov:(a,u,f)=>f?u:a,toBytes:a=>n?$e(a,s):yt(a,s),fromBytes:a=>{if(a.length!==s)throw new Error(`Fp.fromBytes: expected ${s}, got ${a.length}`);return n?Ie(a):et(a)}});return Object.freeze(c)}function kn(e){if(typeof e!="bigint")throw new Error("field order must be bigint");const t=e.toString(2).length;return Math.ceil(t/8)}function Sn(e){const t=kn(e);return t+Math.ceil(t/2)}function Ao(e,t,n=!1){const r=e.length,o=kn(t),s=Sn(t);if(r<16||r<s||r>1024)throw new Error(`expected ${s}-1024 bytes of input, got ${r}`);const i=n?et(e):Ie(e),c=F(i,t-K)+K;return n?$e(c,o):yt(c,o)}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Bo=BigInt(0),Re=BigInt(1);function Oo(e,t){const n=(o,s)=>{const i=s.negate();return o?i:s},r=o=>{const s=Math.ceil(t/o)+1,i=2**(o-1);return{windows:s,windowSize:i}};return{constTimeNegate:n,unsafeLadder(o,s){let i=e.ZERO,c=o;for(;s>Bo;)s&Re&&(i=i.add(c)),c=c.double(),s>>=Re;return i},precomputeWindow(o,s){const{windows:i,windowSize:c}=r(s),a=[];let u=o,f=u;for(let l=0;l<i;l++){f=u,a.push(f);for(let h=1;h<c;h++)f=f.add(u),a.push(f);u=f.double()}return a},wNAF(o,s,i){const{windows:c,windowSize:a}=r(o);let u=e.ZERO,f=e.BASE;const l=BigInt(2**o-1),h=2**o,w=BigInt(o);for(let p=0;p<c;p++){const d=p*a;let g=Number(i&l);i>>=w,g>a&&(g-=h,i+=Re);const y=d,m=d+Math.abs(g)-1,E=p%2!==0,O=g<0;g===0?f=f.add(n(E,s[y])):u=u.add(n(O,s[m]))}return{p:u,f}},wNAFCached(o,s,i,c){const a=o._WINDOW_SIZE||1;let u=s.get(o);return u||(u=this.precomputeWindow(o,a),a!==1&&s.set(o,c(u))),this.wNAF(a,u,i)}}}function An(e){return vo(e.Fp),Dt(e,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({..._n(e.n,e.nBitLength),...e,p:e.Fp.ORDER})}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function Io(e){const t=An(e);Dt(t,{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}=t;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({...t})}const{bytesToNumberBE:$o,hexToBytes:No}=go,At={Err:class extends Error{constructor(t=""){super(t)}},_parseInt(e){const{Err:t}=At;if(e.length<2||e[0]!==2)throw new t("Invalid signature integer tag");const n=e[1],r=e.subarray(2,n+2);if(!n||r.length!==n)throw new t("Invalid signature integer: wrong length");if(r[0]&128)throw new t("Invalid signature integer: negative");if(r[0]===0&&!(r[1]&128))throw new t("Invalid signature integer: unnecessary leading zero");return{d:$o(r),l:e.subarray(n+2)}},toSig(e){const{Err:t}=At,n=typeof e=="string"?No(e):e;if(!(n instanceof Uint8Array))throw new Error("ui8a expected");let r=n.length;if(r<2||n[0]!=48)throw new t("Invalid signature tag");if(n[1]!==r-2)throw new t("Invalid signature: incorrect length");const{d:o,l:s}=At._parseInt(n.subarray(2)),{d:i,l:c}=At._parseInt(s);if(c.length)throw new t("Invalid signature: left bytes after parsing");return{r:o,s:i}},hexFromSig(e){const t=u=>Number.parseInt(u[0],16)&8?"00"+u:u,n=u=>{const f=u.toString(16);return f.length&1?`0${f}`:f},r=t(n(e.s)),o=t(n(e.r)),s=r.length/2,i=o.length/2,c=n(s),a=n(i);return`30${n(i+s+4)}02${a}${o}02${c}${r}`}},ft=BigInt(0),ot=BigInt(1);BigInt(2);const Bn=BigInt(3);BigInt(4);function To(e){const t=Io(e),{Fp:n}=t,r=t.toBytes||((p,d,g)=>{const y=d.toAffine();return kt(Uint8Array.from([4]),n.toBytes(y.x),n.toBytes(y.y))}),o=t.fromBytes||(p=>{const d=p.subarray(1),g=n.fromBytes(d.subarray(0,n.BYTES)),y=n.fromBytes(d.subarray(n.BYTES,2*n.BYTES));return{x:g,y}});function s(p){const{a:d,b:g}=t,y=n.sqr(p),m=n.mul(y,p);return n.add(n.add(m,n.mul(p,d)),g)}if(!n.eql(n.sqr(t.Gy),s(t.Gx)))throw new Error("bad generator point: equation left != right");function i(p){return typeof p=="bigint"&&ft<p&&p<t.n}function c(p){if(!i(p))throw new Error("Expected valid bigint: 0 < bigint < curve.n")}function a(p){const{allowedPrivateKeyLengths:d,nByteLength:g,wrapPrivateKey:y,n:m}=t;if(d&&typeof p!="bigint"){if(p instanceof Uint8Array&&(p=Rt(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(Z("private key",p,g))}catch{throw new Error(`private key must be ${g} bytes, hex or bigint, not ${typeof p}`)}return y&&(E=F(E,m)),c(E),E}const u=new Map;function f(p){if(!(p instanceof l))throw new Error("ProjectivePoint expected")}class l{constructor(d,g,y){if(this.px=d,this.py=g,this.pz=y,d==null||!n.isValid(d))throw new Error("x required");if(g==null||!n.isValid(g))throw new Error("y required");if(y==null||!n.isValid(y))throw new Error("z required")}static fromAffine(d){const{x:g,y}=d||{};if(!d||!n.isValid(g)||!n.isValid(y))throw new Error("invalid affine point");if(d instanceof l)throw new Error("projective point not allowed");const m=E=>n.eql(E,n.ZERO);return m(g)&&m(y)?l.ZERO:new l(g,y,n.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(d){const g=n.invertBatch(d.map(y=>y.pz));return d.map((y,m)=>y.toAffine(g[m])).map(l.fromAffine)}static fromHex(d){const g=l.fromAffine(o(Z("pointHex",d)));return g.assertValidity(),g}static fromPrivateKey(d){return l.BASE.multiply(a(d))}_setWindowSize(d){this._WINDOW_SIZE=d,u.delete(this)}assertValidity(){if(this.is0()){if(t.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 y=n.sqr(g),m=s(d);if(!n.eql(y,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:g,py:y,pz:m}=this,{px:E,py:O,pz:$}=d,v=n.eql(n.mul(g,$),n.mul(E,m)),_=n.eql(n.mul(y,$),n.mul(O,m));return v&&_}negate(){return new l(this.px,n.neg(this.py),this.pz)}double(){const{a:d,b:g}=t,y=n.mul(g,Bn),{px:m,py:E,pz:O}=this;let $=n.ZERO,v=n.ZERO,_=n.ZERO,S=n.mul(m,m),R=n.mul(E,E),N=n.mul(O,O),A=n.mul(m,E);return A=n.add(A,A),_=n.mul(m,O),_=n.add(_,_),$=n.mul(d,_),v=n.mul(y,N),v=n.add($,v),$=n.sub(R,v),v=n.add(R,v),v=n.mul($,v),$=n.mul(A,$),_=n.mul(y,_),N=n.mul(d,N),A=n.sub(S,N),A=n.mul(d,A),A=n.add(A,_),_=n.add(S,S),S=n.add(_,S),S=n.add(S,N),S=n.mul(S,A),v=n.add(v,S),N=n.mul(E,O),N=n.add(N,N),S=n.mul(N,A),$=n.sub($,S),_=n.mul(N,R),_=n.add(_,_),_=n.add(_,_),new l($,v,_)}add(d){f(d);const{px:g,py:y,pz:m}=this,{px:E,py:O,pz:$}=d;let v=n.ZERO,_=n.ZERO,S=n.ZERO;const R=t.a,N=n.mul(t.b,Bn);let A=n.mul(g,E),M=n.mul(y,O),U=n.mul(m,$),nt=n.add(g,y),x=n.add(E,O);nt=n.mul(nt,x),x=n.add(A,M),nt=n.sub(nt,x),x=n.add(g,m);let k=n.add(E,$);return x=n.mul(x,k),k=n.add(A,U),x=n.sub(x,k),k=n.add(y,m),v=n.add(O,$),k=n.mul(k,v),v=n.add(M,U),k=n.sub(k,v),S=n.mul(R,x),v=n.mul(N,U),S=n.add(v,S),v=n.sub(M,S),S=n.add(M,S),_=n.mul(v,S),M=n.add(A,A),M=n.add(M,A),U=n.mul(R,U),x=n.mul(N,x),M=n.add(M,U),U=n.sub(A,U),U=n.mul(R,U),x=n.add(x,U),A=n.mul(M,x),_=n.add(_,A),A=n.mul(k,x),v=n.mul(nt,v),v=n.sub(v,A),A=n.mul(nt,M),S=n.mul(k,S),S=n.add(S,A),new l(v,_,S)}subtract(d){return this.add(d.negate())}is0(){return this.equals(l.ZERO)}wNAF(d){return w.wNAFCached(this,u,d,g=>{const y=n.invertBatch(g.map(m=>m.pz));return g.map((m,E)=>m.toAffine(y[E])).map(l.fromAffine)})}multiplyUnsafe(d){const g=l.ZERO;if(d===ft)return g;if(c(d),d===ot)return this;const{endo:y}=t;if(!y)return w.unsafeLadder(this,d);let{k1neg:m,k1:E,k2neg:O,k2:$}=y.splitScalar(d),v=g,_=g,S=this;for(;E>ft||$>ft;)E&ot&&(v=v.add(S)),$&ot&&(_=_.add(S)),S=S.double(),E>>=ot,$>>=ot;return m&&(v=v.negate()),O&&(_=_.negate()),_=new l(n.mul(_.px,y.beta),_.py,_.pz),v.add(_)}multiply(d){c(d);let g=d,y,m;const{endo:E}=t;if(E){const{k1neg:O,k1:$,k2neg:v,k2:_}=E.splitScalar(g);let{p:S,f:R}=this.wNAF($),{p:N,f:A}=this.wNAF(_);S=w.constTimeNegate(O,S),N=w.constTimeNegate(v,N),N=new l(n.mul(N.px,E.beta),N.py,N.pz),y=S.add(N),m=R.add(A)}else{const{p:O,f:$}=this.wNAF(g);y=O,m=$}return l.normalizeZ([y,m])[0]}multiplyAndAddUnsafe(d,g,y){const m=l.BASE,E=($,v)=>v===ft||v===ot||!$.equals(m)?$.multiplyUnsafe(v):$.multiply(v),O=E(this,g).add(E(d,y));return O.is0()?void 0:O}toAffine(d){const{px:g,py:y,pz:m}=this,E=this.is0();d==null&&(d=E?n.ONE:n.inv(m));const O=n.mul(g,d),$=n.mul(y,d),v=n.mul(m,d);if(E)return{x:n.ZERO,y:n.ZERO};if(!n.eql(v,n.ONE))throw new Error("invZ was invalid");return{x:O,y:$}}isTorsionFree(){const{h:d,isTorsionFree:g}=t;if(d===ot)return!0;if(g)return g(l,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){const{h:d,clearCofactor:g}=t;return d===ot?this:g?g(l,this):this.multiplyUnsafe(t.h)}toRawBytes(d=!0){return this.assertValidity(),r(l,this,d)}toHex(d=!0){return Rt(this.toRawBytes(d))}}l.BASE=new l(t.Gx,t.Gy,n.ONE),l.ZERO=new l(n.ZERO,n.ONE,n.ZERO);const h=t.nBitLength,w=Oo(l,t.endo?Math.ceil(h/2):h);return{CURVE:t,ProjectivePoint:l,normPrivateKeyToScalar:a,weierstrassEquation:s,isWithinCurveOrder:i}}function Co(e){const t=An(e);return Dt(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}function Po(e){const t=Co(e),{Fp:n,n:r}=t,o=n.BYTES+1,s=2*n.BYTES+1;function i(x){return ft<x&&x<n.ORDER}function c(x){return F(x,r)}function a(x){return Pe(x,r)}const{ProjectivePoint:u,normPrivateKeyToScalar:f,weierstrassEquation:l,isWithinCurveOrder:h}=To({...t,toBytes(x,k,C){const H=k.toAffine(),L=n.toBytes(H.x),V=kt;return C?V(Uint8Array.from([k.hasEvenY()?2:3]),L):V(Uint8Array.from([4]),L,n.toBytes(H.y))},fromBytes(x){const k=x.length,C=x[0],H=x.subarray(1);if(k===o&&(C===2||C===3)){const L=et(H);if(!i(L))throw new Error("Point is not on curve");const V=l(L);let Q=n.sqrt(V);const X=(Q&ot)===ot;return(C&1)===1!==X&&(Q=n.neg(Q)),{x:L,y:Q}}else if(k===s&&C===4){const L=n.fromBytes(H.subarray(0,n.BYTES)),V=n.fromBytes(H.subarray(n.BYTES,2*n.BYTES));return{x:L,y:V}}else throw new Error(`Point of length ${k} was invalid. Expected ${o} compressed bytes or ${s} uncompressed bytes`)}}),w=x=>Rt(yt(x,t.nByteLength));function p(x){const k=r>>ot;return x>k}function d(x){return p(x)?c(-x):x}const g=(x,k,C)=>et(x.slice(k,C));class y{constructor(k,C,H){this.r=k,this.s=C,this.recovery=H,this.assertValidity()}static fromCompact(k){const C=t.nByteLength;return k=Z("compactSignature",k,C*2),new y(g(k,0,C),g(k,C,2*C))}static fromDER(k){const{r:C,s:H}=At.toSig(Z("DER",k));return new y(C,H)}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 y(this.r,this.s,k)}recoverPublicKey(k){const{r:C,s:H,recovery:L}=this,V=_(Z("msgHash",k));if(L==null||![0,1,2,3].includes(L))throw new Error("recovery id invalid");const Q=L===2||L===3?C+t.n:C;if(Q>=n.ORDER)throw new Error("recovery id 2 or 3 invalid");const X=L&1?"03":"02",ut=u.fromHex(X+w(Q)),I=a(Q),z=c(-V*I),vt=c(H*I),it=u.BASE.multiplyAndAddUnsafe(ut,z,vt);if(!it)throw new Error("point at infinify");return it.assertValidity(),it}hasHighS(){return p(this.s)}normalizeS(){return this.hasHighS()?new y(this.r,c(-this.s),this.recovery):this}toDERRawBytes(){return Ut(this.toDERHex())}toDERHex(){return At.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return Ut(this.toCompactHex())}toCompactHex(){return w(this.r)+w(this.s)}}const m={isValidPrivateKey(x){try{return f(x),!0}catch{return!1}},normPrivateKeyToScalar:f,randomPrivateKey:()=>{const x=Sn(t.n);return Ao(t.randomBytes(x),t.n)},precompute(x=8,k=u.BASE){return k._setWindowSize(x),k.multiply(BigInt(3)),k}};function E(x,k=!0){return u.fromPrivateKey(x).toRawBytes(k)}function O(x){const k=x instanceof Uint8Array,C=typeof x=="string",H=(k||C)&&x.length;return k?H===o||H===s:C?H===2*o||H===2*s:x instanceof u}function $(x,k,C=!0){if(O(x))throw new Error("first arg must be private key");if(!O(k))throw new Error("second arg must be public key");return u.fromHex(k).multiply(f(x)).toRawBytes(C)}const v=t.bits2int||function(x){const k=et(x),C=x.length*8-t.nBitLength;return C>0?k>>BigInt(C):k},_=t.bits2int_modN||function(x){return c(v(x))},S=Ne(t.nBitLength);function R(x){if(typeof x!="bigint")throw new Error("bigint expected");if(!(ft<=x&&x<S))throw new Error(`bigint expected < 2^${t.nBitLength}`);return yt(x,t.nByteLength)}function N(x,k,C=A){if(["recovered","canonical"].some(It=>It in C))throw new Error("sign() legacy options not supported");const{hash:H,randomBytes:L}=t;let{lowS:V,prehash:Q,extraEntropy:X}=C;V==null&&(V=!0),x=Z("msgHash",x),Q&&(x=Z("prehashed msgHash",H(x)));const ut=_(x),I=f(k),z=[R(I),R(ut)];if(X!=null){const It=X===!0?L(n.BYTES):X;z.push(Z("extraEntropy",It))}const vt=kt(...z),it=ut;function Qt(It){const Mt=v(It);if(!h(Mt))return;const mr=a(Mt),jt=u.BASE.multiply(Mt).toAffine(),ct=c(jt.x);if(ct===ft)return;const Kt=c(mr*c(it+ct*I));if(Kt===ft)return;let xr=(jt.x===ct?0:2)|Number(jt.y&ot),Er=Kt;return V&&p(Kt)&&(Er=d(Kt),xr^=1),new y(ct,Er,xr)}return{seed:vt,k2sig:Qt}}const A={lowS:t.lowS,prehash:!1},M={lowS:t.lowS,prehash:!1};function U(x,k,C=A){const{seed:H,k2sig:L}=N(x,k,C),V=t;return xn(V.hash.outputLen,V.nByteLength,V.hmac)(H,L)}u.BASE._setWindowSize(8);function nt(x,k,C,H=M){var jt;const L=x;if(k=Z("msgHash",k),C=Z("publicKey",C),"strict"in H)throw new Error("options.strict was renamed to lowS");const{lowS:V,prehash:Q}=H;let X,ut;try{if(typeof L=="string"||L instanceof Uint8Array)try{X=y.fromDER(L)}catch(ct){if(!(ct instanceof At.Err))throw ct;X=y.fromCompact(L)}else if(typeof L=="object"&&typeof L.r=="bigint"&&typeof L.s=="bigint"){const{r:ct,s:Kt}=L;X=new y(ct,Kt)}else throw new Error("PARSE");ut=u.fromHex(C)}catch(ct){if(ct.message==="PARSE")throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(V&&X.hasHighS())return!1;Q&&(k=t.hash(k));const{r:I,s:z}=X,vt=_(k),it=a(z),Qt=c(vt*it),It=c(I*it),Mt=(jt=u.BASE.multiplyAndAddUnsafe(ut,Qt,It))==null?void 0:jt.toAffine();return Mt?c(Mt.x)===I:!1}return{CURVE:t,getPublicKey:E,getSharedSecret:$,sign:U,verify:nt,ProjectivePoint:u,Signature:y,utils:m}}class On extends pn{constructor(t,n){super(),this.finished=!1,this.destroyed=!1,Zr(t);const r=Ae(n);if(this.iHash=t.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?t.create().update(r).digest():r);for(let i=0;i<s.length;i++)s[i]^=54;this.iHash.update(s),this.oHash=t.create();for(let i=0;i<s.length;i++)s[i]^=106;this.oHash.update(s),s.fill(0)}update(t){return oe(this),this.iHash.update(t),this}digestInto(t){oe(this),hn(t,this.outputLen),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){const t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}));const{oHash:n,iHash:r,finished:o,destroyed:s,blockLen:i,outputLen:c}=this;return t=t,t.finished=o,t.destroyed=s,t.blockLen=i,t.outputLen=c,t.oHash=n._cloneInto(t.oHash),t.iHash=r._cloneInto(t.iHash),t}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}const In=(e,t,n)=>new On(e,t).update(n).digest();In.create=(e,t)=>new On(e,t);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function Ro(e){return{hash:e,hmac:(t,...n)=>In(e,t,Qr(...n)),randomBytes:gn}}function Uo(e,t){const n=r=>Po({...e,...Ro(r)});return Object.freeze({...n(t),create:n})}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const ce=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),ae=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),$n=BigInt(1),le=BigInt(2),Nn=(e,t)=>(e+t/le)/t;function Tn(e){const t=ce,n=BigInt(3),r=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),c=BigInt(44),a=BigInt(88),u=e*e*e%t,f=u*u*e%t,l=rt(f,n,t)*f%t,h=rt(l,n,t)*f%t,w=rt(h,le,t)*u%t,p=rt(w,o,t)*w%t,d=rt(p,s,t)*p%t,g=rt(d,c,t)*d%t,y=rt(g,a,t)*g%t,m=rt(y,c,t)*d%t,E=rt(m,n,t)*f%t,O=rt(E,i,t)*p%t,$=rt(O,r,t)*u%t,v=rt($,le,t);if(!Ue.eql(Ue.sqr(v),e))throw new Error("Cannot find square root");return v}const Ue=So(ce,void 0,void 0,{sqrt:Tn}),Wt=Uo({a:BigInt(0),b:BigInt(7),Fp:Ue,n:ae,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:e=>{const t=ae,n=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),r=-$n*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),s=n,i=BigInt("0x100000000000000000000000000000000"),c=Nn(s*e,t),a=Nn(-r*e,t);let u=F(e-c*n-a*o,t),f=F(-c*r-a*s,t);const l=u>i,h=f>i;if(l&&(u=t-u),h&&(f=t-f),u>i||f>i)throw new Error("splitScalar: Endomorphism failed, k="+e);return{k1neg:l,k1:u,k2neg:h,k2:f}}}},Be),ue=BigInt(0),Cn=e=>typeof e=="bigint"&&ue<e&&e<ce,Ho=e=>typeof e=="bigint"&&ue<e&&e<ae,Pn={};function fe(e,...t){let n=Pn[e];if(n===void 0){const r=Be(Uint8Array.from(e,o=>o.charCodeAt(0)));n=kt(r,r),Pn[e]=n}return Be(kt(n,...t))}const He=e=>e.toRawBytes(!0).slice(1),Le=e=>yt(e,32),qe=e=>F(e,ce),Ft=e=>F(e,ae),Me=Wt.ProjectivePoint,Lo=(e,t,n)=>Me.BASE.multiplyAndAddUnsafe(e,t,n);function je(e){let t=Wt.utils.normPrivateKeyToScalar(e),n=Me.fromPrivateKey(t);return{scalar:n.hasEvenY()?t:Ft(-t),bytes:He(n)}}function Rn(e){if(!Cn(e))throw new Error("bad x: need 0 < x < p");const t=qe(e*e),n=qe(t*e+BigInt(7));let r=Tn(n);r%le!==ue&&(r=qe(-r));const o=new Me(e,r,$n);return o.assertValidity(),o}function Un(...e){return Ft(et(fe("BIP0340/challenge",...e)))}function qo(e){return je(e).bytes}function Mo(e,t,n=gn(32)){const r=Z("message",e),{bytes:o,scalar:s}=je(t),i=Z("auxRand",n,32),c=Le(s^et(fe("BIP0340/aux",i))),a=fe("BIP0340/nonce",c,o,r),u=Ft(et(a));if(u===ue)throw new Error("sign failed: k is zero");const{bytes:f,scalar:l}=je(u),h=Un(f,o,r),w=new Uint8Array(64);if(w.set(f,0),w.set(Le(Ft(l+h*s)),32),!Hn(w,r,o))throw new Error("sign: Invalid signature produced");return w}function Hn(e,t,n){const r=Z("signature",e,64),o=Z("message",t),s=Z("publicKey",n,32);try{const i=Rn(et(s)),c=et(r.subarray(0,32));if(!Cn(c))return!1;const a=et(r.subarray(32,64));if(!Ho(a))return!1;const u=Un(Le(c),He(i),o),f=Lo(i,a,Ft(-u));return!(!f||!f.hasEvenY()||f.toAffine().x!==c)}catch{return!1}}const Y={getPublicKey:qo,sign:Mo,verify:Hn,utils:{randomPrivateKey:Wt.utils.randomPrivateKey,lift_x:Rn,pointToBytes:He,numberToBytesBE:yt,bytesToNumberBE:et,taggedHash:fe,mod:F}};function Ke(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`Wrong positive integer: ${e}`)}function jo(e){if(typeof e!="boolean")throw new Error(`Expected boolean, not ${e}`)}function Ln(e,...t){if(!(e instanceof Uint8Array))throw new Error("Expected Uint8Array");if(t.length>0&&!t.includes(e.length))throw new Error(`Expected Uint8Array of length ${t}, not of length=${e.length}`)}function Ko(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");Ke(e.outputLen),Ke(e.blockLen)}function zo(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function Vo(e,t){Ln(e);const n=t.outputLen;if(e.length<n)throw new Error(`digestInto() expects output buffer of length at least ${n}`)}const ze={number:Ke,bool:jo,bytes:Ln,hash:Ko,exists:zo,output:Vo};function Do(e,t,n,r){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,n,r);const o=BigInt(32),s=BigInt(4294967295),i=Number(n>>o&s),c=Number(n&s),a=r?4:0,u=r?0:4;e.setUint32(t+a,i,r),e.setUint32(t+u,c,r)}class Wo extends Fr{constructor(t,n,r,o){super(),this.blockLen=t,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(t),this.view=ve(this.buffer)}update(t){ze.exists(this);const{view:n,buffer:r,blockLen:o}=this;t=un(t);const s=t.length;for(let i=0;i<s;){const c=Math.min(o-this.pos,s-i);if(c===o){const a=ve(t);for(;o<=s-i;i+=o)this.process(a,i);continue}r.set(t.subarray(i,i+c),this.pos),this.pos+=c,i+=c,this.pos===o&&(this.process(n,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){ze.exists(this),ze.output(t,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 l=i;l<o;l++)n[l]=0;Do(r,o-8,BigInt(this.length*8),s),this.process(r,0);const c=ve(t),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const u=a/4,f=this.get();if(u>f.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<u;l++)c.setUint32(4*l,f[l],s)}digest(){const{buffer:t,outputLen:n}=this;this.digestInto(t);const r=t.slice(0,n);return this.destroy(),r}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());const{blockLen:n,buffer:r,length:o,finished:s,destroyed:i,pos:c}=this;return t.length=o,t.pos=c,t.finished=s,t.destroyed=i,o%n&&t.buffer.set(r),t}}const Fo=(e,t,n)=>e&t^~e&n,Go=(e,t,n)=>e&t^e&n^t&n,Zo=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]),mt=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),xt=new Uint32Array(64);class qn extends Wo{constructor(){super(64,32,8,!1),this.A=mt[0]|0,this.B=mt[1]|0,this.C=mt[2]|0,this.D=mt[3]|0,this.E=mt[4]|0,this.F=mt[5]|0,this.G=mt[6]|0,this.H=mt[7]|0}get(){const{A:t,B:n,C:r,D:o,E:s,F:i,G:c,H:a}=this;return[t,n,r,o,s,i,c,a]}set(t,n,r,o,s,i,c,a){this.A=t|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=a|0}process(t,n){for(let l=0;l<16;l++,n+=4)xt[l]=t.getUint32(n,!1);for(let l=16;l<64;l++){const h=xt[l-15],w=xt[l-2],p=at(h,7)^at(h,18)^h>>>3,d=at(w,17)^at(w,19)^w>>>10;xt[l]=d+xt[l-7]+p+xt[l-16]|0}let{A:r,B:o,C:s,D:i,E:c,F:a,G:u,H:f}=this;for(let l=0;l<64;l++){const h=at(c,6)^at(c,11)^at(c,25),w=f+h+Fo(c,a,u)+Zo[l]+xt[l]|0,d=(at(r,2)^at(r,13)^at(r,22))+Go(r,o,s)|0;f=u,u=a,a=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,a=a+this.F|0,u=u+this.G|0,f=f+this.H|0,this.set(r,o,s,i,c,a,u,f)}roundClean(){xt.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}}class Jo extends qn{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 Ve=fn(()=>new qn);fn(()=>new Jo);var Ht=Symbol("verified"),Yo=e=>e instanceof Object;function Qo(e){if(!Yo(e)||typeof e.kind!="number"||typeof e.content!="string"||typeof e.created_at!="number"||typeof e.pubkey!="string"||!e.pubkey.match(/^[a-f0-9]{64}$/)||!Array.isArray(e.tags))return!1;for(let t=0;t<e.tags.length;t++){let n=e.tags[t];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 Xo=new TextEncoder,ts=class{generateSecretKey(){return Y.utils.randomPrivateKey()}getPublicKey(t){return J(Y.getPublicKey(t))}finalizeEvent(t,n){const r=t;return r.pubkey=J(Y.getPublicKey(n)),r.id=De(r),r.sig=J(Y.sign(De(r),n)),r[Ht]=!0,r}verifyEvent(t){if(typeof t[Ht]=="boolean")return t[Ht];const n=De(t);if(n!==t.id)return t[Ht]=!1,!1;try{const r=Y.verify(t.sig,n,t.pubkey);return t[Ht]=r,r}catch{return t[Ht]=!1,!1}}};function es(e){if(!Qo(e))throw new Error("can't serialize event with wrong or missing properties");return JSON.stringify([0,e.pubkey,e.created_at,e.kind,e.tags,e.content])}function De(e){let t=Ve(Xo.encode(es(e)));return J(t)}var de=new ts,ns=de.generateSecretKey,Mn=de.getPublicKey;de.finalizeEvent,de.verifyEvent;var Bt=Symbol("verified"),rs=e=>e instanceof Object;function os(e){if(!rs(e)||typeof e.kind!="number"||typeof e.content!="string"||typeof e.created_at!="number"||typeof e.pubkey!="string"||!e.pubkey.match(/^[a-f0-9]{64}$/)||!Array.isArray(e.tags))return!1;for(let t=0;t<e.tags.length;t++){let n=e.tags[t];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 ss=new TextEncoder;function Gt(e){e.indexOf("://")===-1&&(e="wss://"+e);let t=new URL(e);return t.pathname=t.pathname.replace(/\/+/g,"/"),t.pathname.endsWith("/")&&(t.pathname=t.pathname.slice(0,-1)),(t.port==="80"&&t.protocol==="ws:"||t.port==="443"&&t.protocol==="wss:")&&(t.port=""),t.searchParams.sort(),t.hash="",t.toString()}var is=class{constructor(t){b(this,"value");b(this,"next",null);b(this,"prev",null);this.value=t}},cs=class{constructor(){b(this,"first");b(this,"last");this.first=null,this.last=null}enqueue(t){const n=new is(t);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 t=this.first;return this.first=t.next,t.value}},as=class{generateSecretKey(){return Y.utils.randomPrivateKey()}getPublicKey(t){return J(Y.getPublicKey(t))}finalizeEvent(t,n){const r=t;return r.pubkey=J(Y.getPublicKey(n)),r.id=We(r),r.sig=J(Y.sign(We(r),n)),r[Bt]=!0,r}verifyEvent(t){if(typeof t[Bt]=="boolean")return t[Bt];const n=We(t);if(n!==t.id)return t[Bt]=!1,!1;try{const r=Y.verify(t.sig,n,t.pubkey);return t[Bt]=r,r}catch{return t[Bt]=!1,!1}}};function ls(e){if(!os(e))throw new Error("can't serialize event with wrong or missing properties");return JSON.stringify([0,e.pubkey,e.created_at,e.kind,e.tags,e.content])}function We(e){let t=Ve(ss.encode(ls(e)));return J(t)}var he=new as;he.generateSecretKey,he.getPublicKey,he.finalizeEvent;var us=he.verifyEvent,fs=22242;function ds(e,t){if(e.ids&&e.ids.indexOf(t.id)===-1&&!e.ids.some(n=>t.id.startsWith(n))||e.kinds&&e.kinds.indexOf(t.kind)===-1||e.authors&&e.authors.indexOf(t.pubkey)===-1&&!e.authors.some(n=>t.pubkey.startsWith(n)))return!1;for(let n in e)if(n[0]==="#"){let r=n.slice(1),o=e[`#${r}`];if(o&&!t.tags.find(([s,i])=>s===n.slice(1)&&o.indexOf(i)!==-1))return!1}return!(e.since&&t.created_at<e.since||e.until&&t.created_at>e.until)}function hs(e,t){for(let n=0;n<e.length;n++)if(ds(e[n],t))return!0;return!1}function ws(e,t){let n=t.length+3,r=e.indexOf(`"${t}":`)+n,o=e.slice(r).indexOf('"')+r+1;return e.slice(o,o+64)}function ps(e){let t=e.slice(0,22).indexOf('"EVENT"');if(t===-1)return null;let n=e.slice(t+7+1).indexOf('"');if(n===-1)return null;let r=t+7+1+n,o=e.slice(r+1,80).indexOf('"');if(o===-1)return null;let s=r+1+o;return e.slice(r+1,s)}function gs(e,t){return{kind:fs,created_at:Math.floor(Date.now()/1e3),tags:[["relay",e],["challenge",t]],content:""}}async function bs(){return new Promise(e=>{const t=new MessageChannel,n=()=>{t.port1.removeEventListener("message",n),e()};t.port1.addEventListener("message",n),t.port2.postMessage(0),t.port1.start()})}var ys=e=>(e[Bt]=!0,!0),jn;try{jn=WebSocket}catch{}var Kn=class{constructor(t,n){b(this,"url");b(this,"_connected",!1);b(this,"onclose",null);b(this,"onnotice",t=>console.debug(`NOTICE from ${this.url}: ${t}`));b(this,"baseEoseTimeout",4400);b(this,"connectionTimeout",4400);b(this,"openSubs",new Map);b(this,"connectionTimeoutHandle");b(this,"connectionPromise");b(this,"openCountRequests",new Map);b(this,"openEventPublishes",new Map);b(this,"ws");b(this,"incomingMessageQueue",new cs);b(this,"queueRunning",!1);b(this,"challenge");b(this,"serial",0);b(this,"verifyEvent");this.url=Gt(t),this.verifyEvent=n.verifyEvent}static async connect(t,n){const r=new Kn(t,n);return await r.connect(),r}closeAllSubscriptions(t){for(let[n,r]of this.openSubs)r.close(t);this.openSubs.clear();for(let[n,r]of this.openEventPublishes)r.reject(new Error(t));this.openEventPublishes.clear();for(let[n,r]of this.openCountRequests)r.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,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 jn(this.url)}catch(r){n(r);return}this.ws.onopen=()=>{clearTimeout(this.connectionTimeoutHandle),this._connected=!0,t()},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 bs();this.queueRunning=!1}handleNext(){var r,o;const t=this.incomingMessageQueue.dequeue();if(!t)return!1;const n=ps(t);if(n){const s=this.openSubs.get(n);if(!s)return;const i=ws(t,"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(t);switch(s[0]){case"EVENT":{const i=this.openSubs.get(s[1]),c=s[2];this.verifyEvent(c)&&hs(i.filters,c)&&i.onevent(c);return}case"COUNT":{const i=s[1],c=s[2],a=this.openCountRequests.get(i);a&&(a.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],a=s[3],u=this.openEventPublishes.get(i);c?u.resolve(a):u.reject(new Error(a)),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(t){if(!this.connectionPromise)throw new Error("sending on closed connection");this.connectionPromise.then(()=>{var n;(n=this.ws)==null||n.send(t)})}async auth(t){if(!this.challenge)throw new Error("can't perform auth, no challenge was received");const n=await t(gs(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(t){const n=new Promise((r,o)=>{this.openEventPublishes.set(t.id,{resolve:r,reject:o})});return this.send('["EVENT",'+JSON.stringify(t)+"]"),n}async count(t,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(t)+"]"),o}subscribe(t,n){const r=this.prepareSubscription(t,n);return r.fire(),r}prepareSubscription(t,n){this.serial++;const r=n.id||"sub:"+this.serial,o=new ms(this,r,t,n);return this.openSubs.set(r,o),o}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()}},ms=class{constructor(t,n,r,o){b(this,"relay");b(this,"id");b(this,"closed",!1);b(this,"eosed",!1);b(this,"filters");b(this,"alreadyHaveEvent");b(this,"receivedEvent");b(this,"onevent");b(this,"oneose");b(this,"onclose");b(this,"eoseTimeout");b(this,"eoseTimeoutHandle");this.relay=t,this.filters=r,this.id=n,this.alreadyHaveEvent=o.alreadyHaveEvent,this.receivedEvent=o.receivedEvent,this.eoseTimeout=o.eoseTimeout||t.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 t;this.eosed||(clearTimeout(this.eoseTimeoutHandle),this.eosed=!0,(t=this.oneose)==null||t.call(this))}close(t="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,t)}},xs=class{constructor(t){b(this,"relays",new Map);b(this,"seenOn",new Map);b(this,"trackRelays",!1);b(this,"verifyEvent");b(this,"trustedRelayURLs",new Set);this.verifyEvent=t.verifyEvent}async ensureRelay(t,n){t=Gt(t);let r=this.relays.get(t);return r||(r=new Kn(t,{verifyEvent:this.trustedRelayURLs.has(t)?ys:this.verifyEvent}),n!=null&&n.connectionTimeout&&(r.connectionTimeout=n.connectionTimeout),this.relays.set(t,r)),await r.connect(),r}close(t){t.map(Gt).forEach(n=>{var r;(r=this.relays.get(n))==null||r.close()})}subscribeMany(t,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===t.length&&((w=r.oneose)==null||w.call(r),c=()=>{})};const a=[];let u=(h,w)=>{var p;c(h),a[h]=w,a.filter(d=>d).length===t.length&&((p=r.onclose)==null||p.call(r,a),u=()=>{})};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},l=Promise.all(t.map(Gt).map(async(h,w,p)=>{if(p.indexOf(h)!==w){u(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(y){u(w,(y==null?void 0:y.message)||String(y));return}let g=d.subscribe(n,{...r,oneose:()=>c(w),onclose:y=>u(w,y),alreadyHaveEvent:f,eoseTimeout:r.maxWait});s.push(g)}));return{async close(){await l,s.forEach(h=>{h.close()})}}}subscribeManyEose(t,n,r){const o=this.subscribeMany(t,n,{...r,oneose(){o.close()}});return o}async querySync(t,n,r){return new Promise(async o=>{const s=[];this.subscribeManyEose(t,[n],{...r,onevent(i){s.push(i)},onclose(i){o(s)}})})}async get(t,n,r){n.limit=1;const o=await this.querySync(t,n,r);return o.sort((s,i)=>i.created_at-s.created_at),o[0]||null}publish(t,n){return t.map(Gt).map(async(r,o,s)=>s.indexOf(r)!==o?Promise.reject("duplicate url"):(await this.ensureRelay(r)).publish(n))}},Es=class extends xs{constructor(){super({verifyEvent:us})}};/*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) */function Lt(e){if(!Number.isSafeInteger(e))throw new Error(`Wrong integer: ${e}`)}function dt(...e){const t=(o,s)=>i=>o(s(i)),n=Array.from(e).reverse().reduce((o,s)=>o?t(o,s.encode):s.encode,void 0),r=e.reduce((o,s)=>o?t(o,s.decode):s.decode,void 0);return{encode:n,decode:r}}function ht(e){return{encode:t=>{if(!Array.isArray(t)||t.length&&typeof t[0]!="number")throw new Error("alphabet.encode input should be an array of numbers");return t.map(n=>{if(Lt(n),n<0||n>=e.length)throw new Error(`Digit index outside alphabet: ${n} (alphabet: ${e.length})`);return e[n]})},decode:t=>{if(!Array.isArray(t)||t.length&&typeof t[0]!="string")throw new Error("alphabet.decode input should be array of strings");return t.map(n=>{if(typeof n!="string")throw new Error(`alphabet.decode: not string element=${n}`);const r=e.indexOf(n);if(r===-1)throw new Error(`Unknown letter: "${n}". Allowed: ${e}`);return r})}}}function wt(e=""){if(typeof e!="string")throw new Error("join separator should be string");return{encode:t=>{if(!Array.isArray(t)||t.length&&typeof t[0]!="string")throw new Error("join.encode input should be array of strings");for(let n of t)if(typeof n!="string")throw new Error(`join.encode: non-string input=${n}`);return t.join(e)},decode:t=>{if(typeof t!="string")throw new Error("join.decode input should be string");return t.split(e)}}}function we(e,t="="){if(Lt(e),typeof t!="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*e%8;)n.push(t);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*e%8)throw new Error("Invalid padding: string should have whole number of bytes");for(;r>0&&n[r-1]===t;r--)if(!((r-1)*e%8))throw new Error("Invalid padding: string has too much padding");return n.slice(0,r)}}}function zn(e){if(typeof e!="function")throw new Error("normalize fn should be function");return{encode:t=>t,decode:t=>e(t)}}function Vn(e,t,n){if(t<2)throw new Error(`convertRadix: wrong from=${t}, 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(e))throw new Error("convertRadix: data should be array");if(!e.length)return[];let r=0;const o=[],s=Array.from(e);for(s.forEach(i=>{if(Lt(i),i<0||i>=t)throw new Error(`Wrong integer: ${i}`)});;){let i=0,c=!0;for(let a=r;a<s.length;a++){const u=s[a],f=t*i+u;if(!Number.isSafeInteger(f)||t*i/t!==i||f-u!==t*i)throw new Error("convertRadix: carry overflow");if(i=f%n,s[a]=Math.floor(f/n),!Number.isSafeInteger(s[a])||s[a]*n+i!==f)throw new Error("convertRadix: carry overflow");if(c)s[a]?c=!1:r=a;else continue}if(o.push(i),c)break}for(let i=0;i<e.length-1&&e[i]===0;i++)o.push(0);return o.reverse()}const Dn=(e,t)=>t?Dn(t,e%t):e,pe=(e,t)=>e+(t-Dn(e,t));function Fe(e,t,n,r){if(!Array.isArray(e))throw new Error("convertRadix2: data should be array");if(t<=0||t>32)throw new Error(`convertRadix2: wrong from=${t}`);if(n<=0||n>32)throw new Error(`convertRadix2: wrong to=${n}`);if(pe(t,n)>32)throw new Error(`convertRadix2: carry overflow from=${t} to=${n} carryBits=${pe(t,n)}`);let o=0,s=0;const i=2**n-1,c=[];for(const a of e){if(Lt(a),a>=2**t)throw new Error(`convertRadix2: invalid data word=${a} from=${t}`);if(o=o<<t|a,s+t>32)throw new Error(`convertRadix2: carry overflow pos=${s} from=${t}`);for(s+=t;s>=n;s-=n)c.push((o>>s-n&i)>>>0);o&=2**s-1}if(o=o<<n-s&i,!r&&s>=t)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 vs(e){return Lt(e),{encode:t=>{if(!(t instanceof Uint8Array))throw new Error("radix.encode input should be Uint8Array");return Vn(Array.from(t),2**8,e)},decode:t=>{if(!Array.isArray(t)||t.length&&typeof t[0]!="number")throw new Error("radix.decode input should be array of strings");return Uint8Array.from(Vn(t,e,2**8))}}}function Et(e,t=!1){if(Lt(e),e<=0||e>32)throw new Error("radix2: bits should be in (0..32]");if(pe(8,e)>32||pe(e,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 Fe(Array.from(n),8,e,!t)},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(Fe(n,e,8,t))}}}function Wn(e){if(typeof e!="function")throw new Error("unsafeWrapper fn should be function");return function(...t){try{return e.apply(null,t)}catch{}}}const _s=dt(Et(4),ht("0123456789ABCDEF"),wt("")),ks=dt(Et(5),ht("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"),we(5),wt(""));dt(Et(5),ht("0123456789ABCDEFGHIJKLMNOPQRSTUV"),we(5),wt("")),dt(Et(5),ht("0123456789ABCDEFGHJKMNPQRSTVWXYZ"),wt(""),zn(e=>e.toUpperCase().replace(/O/g,"0").replace(/[IL]/g,"1")));const Zt=dt(Et(6),ht("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),we(6),wt("")),Ss=dt(Et(6),ht("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"),we(6),wt("")),Ge=e=>dt(vs(58),ht(e),wt("")),Ze=Ge("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");Ge("123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"),Ge("rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz");const Fn=[0,2,3,5,6,7,9,10,11],As={encode(e){let t="";for(let n=0;n<e.length;n+=8){const r=e.subarray(n,n+8);t+=Ze.encode(r).padStart(Fn[r.length],"1")}return t},decode(e){let t=[];for(let n=0;n<e.length;n+=11){const r=e.slice(n,n+11),o=Fn.indexOf(r.length),s=Ze.decode(r);for(let i=0;i<s.length-o;i++)if(s[i]!==0)throw new Error("base58xmr: wrong padding");t=t.concat(Array.from(s.slice(s.length-o)))}return Uint8Array.from(t)}},Je=dt(ht("qpzry9x8gf2tvdw0s3jn54khce6mua7l"),wt("")),Gn=[996825010,642813549,513874426,1027748829,705979059];function Jt(e){const t=e>>25;let n=(e&33554431)<<5;for(let r=0;r<Gn.length;r++)(t>>r&1)===1&&(n^=Gn[r]);return n}function Zn(e,t,n=1){const r=e.length;let o=1;for(let s=0;s<r;s++){const i=e.charCodeAt(s);if(i<33||i>126)throw new Error(`Invalid prefix (${e})`);o=Jt(o)^i>>5}o=Jt(o);for(let s=0;s<r;s++)o=Jt(o)^e.charCodeAt(s)&31;for(let s of t)o=Jt(o)^s;for(let s=0;s<6;s++)o=Jt(o);return o^=n,Je.encode(Fe([o%2**30],30,5,!1))}function Jn(e){const t=e==="bech32"?1:734539939,n=Et(5),r=n.decode,o=n.encode,s=Wn(r);function i(f,l,h=90){if(typeof f!="string")throw new Error(`bech32.encode prefix should be string, not ${typeof f}`);if(!Array.isArray(l)||l.length&&typeof l[0]!="number")throw new Error(`bech32.encode words should be array of numbers, not ${typeof l}`);const w=f.length+7+l.length;if(h!==!1&&w>h)throw new TypeError(`Length ${w} exceeds limit ${h}`);return f=f.toLowerCase(),`${f}1${Je.encode(l)}${Zn(f,l,t)}`}function c(f,l=90){if(typeof f!="string")throw new Error(`bech32.decode input should be string, not ${typeof f}`);if(f.length<8||l!==!1&&f.length>l)throw new TypeError(`Wrong string length: ${f.length} (${f}). Expected (8..${l})`);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=Je.decode(d).slice(0,-6),y=Zn(p,g,t);if(!d.endsWith(y))throw new Error(`Invalid checksum in ${f}: expected "${y}"`);return{prefix:p,words:g}}const a=Wn(c);function u(f){const{prefix:l,words:h}=c(f,!1);return{prefix:l,words:h,bytes:r(h)}}return{encode:i,decode:c,decodeToBytes:u,decodeUnsafe:a,fromWords:r,fromWordsUnsafe:s,toWords:o}}const Yn=Jn("bech32");Jn("bech32m");const Bs={encode:e=>new TextDecoder().decode(e),decode:e=>new TextEncoder().encode(e)},Os=dt(Et(4),ht("0123456789abcdef"),wt(""),zn(e=>{if(typeof e!="string"||e.length%2)throw new TypeError(`hex.decode: expected string, got ${typeof e} with length ${e.length}`);return e.toLowerCase()}));`${Object.keys({utf8:Bs,hex:Os,base16:_s,base32:ks,base64:Zt,base64url:Ss,base58:Ze,base58xmr:As}).join(", ")}`;var Ot=Symbol("verified"),Is=e=>e instanceof Object;function $s(e){if(!Is(e)||typeof e.kind!="number"||typeof e.content!="string"||typeof e.created_at!="number"||typeof e.pubkey!="string"||!e.pubkey.match(/^[a-f0-9]{64}$/)||!Array.isArray(e.tags))return!1;for(let t=0;t<e.tags.length;t++){let n=e.tags[t];if(!Array.isArray(n))return!1;for(let r=0;r<n.length;r++)if(typeof n[r]=="object")return!1}return!0}var Ns=new TextDecoder("utf-8"),Qn=new TextEncoder;function Yt(e){e.indexOf("://")===-1&&(e="wss://"+e);let t=new URL(e);return t.pathname=t.pathname.replace(/\/+/g,"/"),t.pathname.endsWith("/")&&(t.pathname=t.pathname.slice(0,-1)),(t.port==="80"&&t.protocol==="ws:"||t.port==="443"&&t.protocol==="wss:")&&(t.port=""),t.searchParams.sort(),t.hash="",t.toString()}var Ts=class{constructor(e){b(this,"value");b(this,"next",null);b(this,"prev",null);this.value=e}},Cs=class{constructor(){b(this,"first");b(this,"last");this.first=null,this.last=null}enqueue(e){const t=new Ts(e);return this.last?this.last===this.first?(this.last=t,this.last.prev=this.first,this.first.next=t):(t.prev=this.last,this.last.next=t,this.last=t):(this.first=t,this.last=t),!0}dequeue(){if(!this.first)return null;if(this.first===this.last){const t=this.first;return this.first=null,this.last=null,t.value}const e=this.first;return this.first=e.next,e.value}},Ps=class{generateSecretKey(){return Y.utils.randomPrivateKey()}getPublicKey(e){return J(Y.getPublicKey(e))}finalizeEvent(e,t){const n=e;return n.pubkey=J(Y.getPublicKey(t)),n.id=Ye(n),n.sig=J(Y.sign(Ye(n),t)),n[Ot]=!0,n}verifyEvent(e){if(typeof e[Ot]=="boolean")return e[Ot];const t=Ye(e);if(t!==e.id)return e[Ot]=!1,!1;try{const n=Y.verify(e.sig,t,e.pubkey);return e[Ot]=n,n}catch{return e[Ot]=!1,!1}}};function Rs(e){if(!$s(e))throw new Error("can't serialize event with wrong or missing properties");return JSON.stringify([0,e.pubkey,e.created_at,e.kind,e.tags,e.content])}function Ye(e){let t=Ve(Qn.encode(Rs(e)));return J(t)}var ge=new Ps,Us=ge.generateSecretKey,Xn=ge.getPublicKey,Hs=ge.finalizeEvent,tr=ge.verifyEvent;typeof crypto<"u"&&!crypto.subtle&&crypto.webcrypto&&(crypto.subtle=crypto.webcrypto.subtle);async function Ls(e,t,n){const r=e instanceof Uint8Array?J(e):e,o=Wt.getSharedSecret(r,"02"+t),s=er(o);let i=Uint8Array.from(Gr(16)),c=Qn.encode(n),a=await crypto.subtle.importKey("raw",s,{name:"AES-CBC"},!1,["encrypt"]),u=await crypto.subtle.encrypt({name:"AES-CBC",iv:i},a,c),f=Zt.encode(new Uint8Array(u)),l=Zt.encode(new Uint8Array(i.buffer));return`${f}?iv=${l}`}async function qs(e,t,n){const r=e instanceof Uint8Array?J(e):e;let[o,s]=n.split("?iv="),i=Wt.getSharedSecret(r,"02"+t),c=er(i),a=await crypto.subtle.importKey("raw",c,{name:"AES-CBC"},!1,["decrypt"]),u=Zt.decode(o),f=Zt.decode(s),l=await crypto.subtle.decrypt({name:"AES-CBC",iv:f},a,u);return Ns.decode(l)}function er(e){return e.slice(1,33)}var Ms=/^(?:([\w.+-]+)@)?([\w_-]+(\.[\w_-]+)+)$/,js;try{js=fetch}catch{}var Ks=22242,Qe=24133,zs=31990;function Vs(e,t){if(e.ids&&e.ids.indexOf(t.id)===-1&&!e.ids.some(n=>t.id.startsWith(n))||e.kinds&&e.kinds.indexOf(t.kind)===-1||e.authors&&e.authors.indexOf(t.pubkey)===-1&&!e.authors.some(n=>t.pubkey.startsWith(n)))return!1;for(let n in e)if(n[0]==="#"){let r=n.slice(1),o=e[`#${r}`];if(o&&!t.tags.find(([s,i])=>s===n.slice(1)&&o.indexOf(i)!==-1))return!1}return!(e.since&&t.created_at<e.since||e.until&&t.created_at>e.until)}function Ds(e,t){for(let n=0;n<e.length;n++)if(Vs(e[n],t))return!0;return!1}function Ws(e,t){let n=t.length+3,r=e.indexOf(`"${t}":`)+n,o=e.slice(r).indexOf('"')+r+1;return e.slice(o,o+64)}function Fs(e){let t=e.slice(0,22).indexOf('"EVENT"');if(t===-1)return null;let n=e.slice(t+7+1).indexOf('"');if(n===-1)return null;let r=t+7+1+n,o=e.slice(r+1,80).indexOf('"');if(o===-1)return null;let s=r+1+o;return e.slice(r+1,s)}function Gs(e,t){return{kind:Ks,created_at:Math.floor(Date.now()/1e3),tags:[["relay",e],["challenge",t]],content:""}}async function Zs(){return new Promise(e=>{const t=new MessageChannel,n=()=>{t.port1.removeEventListener("message",n),e()};t.port1.addEventListener("message",n),t.port2.postMessage(0),t.port1.start()})}var Js=e=>(e[Ot]=!0,!0),nr;try{nr=WebSocket}catch{}var rr=class{constructor(e,t){b(this,"url");b(this,"_connected",!1);b(this,"onclose",null);b(this,"onnotice",e=>console.debug(`NOTICE from ${this.url}: ${e}`));b(this,"baseEoseTimeout",4400);b(this,"connectionTimeout",4400);b(this,"openSubs",new Map);b(this,"connectionTimeoutHandle");b(this,"connectionPromise");b(this,"openCountRequests",new Map);b(this,"openEventPublishes",new Map);b(this,"ws");b(this,"incomingMessageQueue",new Cs);b(this,"queueRunning",!1);b(this,"challenge");b(this,"serial",0);b(this,"verifyEvent");this.url=Yt(e),this.verifyEvent=t.verifyEvent}static async connect(e,t){const n=new rr(e,t);return await n.connect(),n}closeAllSubscriptions(e){for(let[t,n]of this.openSubs)n.close(e);this.openSubs.clear();for(let[t,n]of this.openEventPublishes)n.reject(new Error(e));this.openEventPublishes.clear();for(let[t,n]of this.openCountRequests)n.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,t)=>{this.connectionTimeoutHandle=setTimeout(()=>{var n;t("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 nr(this.url)}catch(n){t(n);return}this.ws.onopen=()=>{clearTimeout(this.connectionTimeoutHandle),this._connected=!0,e()},this.ws.onerror=n=>{var r;t(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 e=this.incomingMessageQueue.dequeue();if(!e)return!1;const t=Fs(e);if(t){const o=this.openSubs.get(t);if(!o)return;const s=Ws(e,"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(e);switch(o[0]){case"EVENT":{const s=this.openSubs.get(o[1]),i=o[2];this.verifyEvent(i)&&Ds(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],a=this.openEventPublishes.get(s);i?a.resolve(c):a.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(e){if(!this.connectionPromise)throw new Error("sending on closed connection");this.connectionPromise.then(()=>{var t;(t=this.ws)==null||t.send(e)})}async auth(e){if(!this.challenge)throw new Error("can't perform auth, no challenge was received");const t=await e(Gs(this.url,this.challenge)),n=new Promise((r,o)=>{this.openEventPublishes.set(t.id,{resolve:r,reject:o})});return this.send('["AUTH",'+JSON.stringify(t)+"]"),n}async publish(e){const t=new Promise((n,r)=>{this.openEventPublishes.set(e.id,{resolve:n,reject:r})});return this.send('["EVENT",'+JSON.stringify(e)+"]"),t}async count(e,t){this.serial++;const n=(t==null?void 0:t.id)||"count:"+this.serial,r=new Promise((o,s)=>{this.openCountRequests.set(n,{resolve:o,reject:s})});return this.send('["COUNT","'+n+'",'+JSON.stringify(e)+"]"),r}subscribe(e,t){const n=this.prepareSubscription(e,t);return n.fire(),n}prepareSubscription(e,t){this.serial++;const n=t.id||"sub:"+this.serial,r=new Ys(this,n,e,t);return this.openSubs.set(n,r),r}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()}},Ys=class{constructor(e,t,n,r){b(this,"relay");b(this,"id");b(this,"closed",!1);b(this,"eosed",!1);b(this,"filters");b(this,"alreadyHaveEvent");b(this,"receivedEvent");b(this,"onevent");b(this,"oneose");b(this,"onclose");b(this,"eoseTimeout");b(this,"eoseTimeoutHandle");this.relay=e,this.filters=n,this.id=t,this.alreadyHaveEvent=r.alreadyHaveEvent,this.receivedEvent=r.receivedEvent,this.eoseTimeout=r.eoseTimeout||e.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 e;this.eosed||(clearTimeout(this.eoseTimeoutHandle),this.eosed=!0,(e=this.oneose)==null||e.call(this))}close(e="closed by caller"){var t;this.closed||(this.relay.send('["CLOSE",'+JSON.stringify(this.id)+"]"),this.closed=!0),this.relay.openSubs.delete(this.id),(t=this.onclose)==null||t.call(this,e)}},Qs=class{constructor(e){b(this,"relays",new Map);b(this,"seenOn",new Map);b(this,"trackRelays",!1);b(this,"verifyEvent");b(this,"trustedRelayURLs",new Set);this.verifyEvent=e.verifyEvent}async ensureRelay(e,t){e=Yt(e);let n=this.relays.get(e);return n||(n=new rr(e,{verifyEvent:this.trustedRelayURLs.has(e)?Js:this.verifyEvent}),t!=null&&t.connectionTimeout&&(n.connectionTimeout=t.connectionTimeout),this.relays.set(e,n)),await n.connect(),n}close(e){e.map(Yt).forEach(t=>{var n;(n=this.relays.get(t))==null||n.close()})}subscribeMany(e,t,n){this.trackRelays&&(n.receivedEvent=(l,h)=>{let w=this.seenOn.get(h);w||(w=new Set,this.seenOn.set(h,w)),w.add(l)});const r=new Set,o=[],s=[];let i=l=>{var h;s[l]=!0,s.filter(w=>w).length===e.length&&((h=n.oneose)==null||h.call(n),i=()=>{})};const c=[];let a=(l,h)=>{var w;i(l),c[l]=h,c.filter(p=>p).length===e.length&&((w=n.onclose)==null||w.call(n,c),a=()=>{})};const u=l=>{var w;if((w=n.alreadyHaveEvent)!=null&&w.call(n,l))return!0;const h=r.has(l);return r.add(l),h},f=Promise.all(e.map(Yt).map(async(l,h,w)=>{if(w.indexOf(l)!==h){a(h,"duplicate url");return}let p;try{p=await this.ensureRelay(l,{connectionTimeout:n.maxWait?Math.max(n.maxWait*.8,n.maxWait-1e3):void 0})}catch(g){a(h,(g==null?void 0:g.message)||String(g));return}let d=p.subscribe(t,{...n,oneose:()=>i(h),onclose:g=>a(h,g),alreadyHaveEvent:u,eoseTimeout:n.maxWait});o.push(d)}));return{async close(){await f,o.forEach(l=>{l.close()})}}}subscribeManyEose(e,t,n){const r=this.subscribeMany(e,t,{...n,oneose(){r.close()}});return r}async querySync(e,t,n){return new Promise(async r=>{const o=[];this.subscribeManyEose(e,[t],{...n,onevent(s){o.push(s)},onclose(s){r(o)}})})}async get(e,t,n){t.limit=1;const r=await this.querySync(e,t,n);return r.sort((o,s)=>s.created_at-o.created_at),r[0]||null}publish(e,t){return e.map(Yt).map(async(n,r,o)=>o.indexOf(n)!==r?Promise.reject("duplicate url"):(await this.ensureRelay(n)).publish(t))}},Xs=class extends Qs{constructor(){super({verifyEvent:tr})}},or;try{or=fetch}catch{}var sr=/^bunker:\/\/([0-9a-f]{64})\??([?\/\w:.=&%]*)$/,ti=/^[^\s@]+@[^\s@]+\.[^\s@]+$/;async function ei(e){let t=e.match(sr);if(t)try{const n=t[1],r=new URLSearchParams(t[2]);return{pubkey:n,relays:r.getAll("relay"),secret:r.get("secret")}}catch{}return ir(e)}async function ir(e){const t=e.match(Ms);if(!t)return null;const[n,r="_",o]=t;try{const s=`https://${o}/.well-known/nostr.json?name=${r}`,i=await(await or(s,{redirect:"error"})).json();let c=i.names[r],a=i.nip46[c]||[];return{pubkey:c,relays:a,secret:null}}catch{return null}}var Xe=class{constructor(e,t,n={}){b(this,"pool");b(this,"subCloser");b(this,"isOpen");b(this,"serial");b(this,"idPrefix");b(this,"listeners");b(this,"waitingForAuth");b(this,"secretKey");b(this,"bp");if(t.relays.length===0)throw new Error("no relays are specified for this bunker");this.pool=n.pool||new Xs,this.secretKey=e,this.bp=t,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:[Qe],"#p":[Xn(this.secretKey)]}],{async onevent(s){const{id:i,result:c,error:a}=JSON.parse(await qs(e,s.pubkey,s.content));if(c==="auth_url"&&o[i]){delete r[i],n.onauth?n.onauth(a):console.warn(`nostr-tools/nip46: remote signer ${t.pubkey} tried to send an "auth_url"='${a}' but there was no onauth() callback configured.`);return}let u=r[i];u&&(a?u.reject(a):c&&u.resolve(c),delete r[i])}}),this.isOpen=!0}async close(){this.isOpen=!1,this.subCloser.close()}async sendRequest(e,t){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 Ls(this.secretKey,this.bp.pubkey,JSON.stringify({id:o,method:e,params:t})),i=Hs({kind:Qe,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 e=await this.sendRequest("ping",[]);if(e!=="pong")throw new Error(`result is not pong: ${e}`)}async connect(){await this.sendRequest("connect",[Xn(this.secretKey),this.bp.secret||""])}async getPublicKey(){return this.bp.pubkey}async getRelays(){return JSON.parse(await this.sendRequest("get_relays",[]))}async signEvent(e){let t=await this.sendRequest("sign_event",[JSON.stringify(e)]),n=JSON.parse(t);if(n.pubkey===this.bp.pubkey&&tr(n))return n;throw new Error(`event returned from bunker is improperly signed: ${JSON.stringify(n)}`)}async nip04Encrypt(e,t){return await this.sendRequest("nip04_encrypt",[e,t])}async nip04Decrypt(e,t){return await this.sendRequest("nip04_decrypt",[e,t])}async nip44GetKey(e){let t=await this.sendRequest("nip44_get_key",[e]);return _e(t)}async nip44Encrypt(e,t){return await this.sendRequest("nip44_encrypt",[e,t])}async nip44Decrypt(e,t){return await this.sendRequest("nip44_encrypt",[e,t])}};async function ni(e,t,n,r,o){if(o&&!ti.test(o))throw new Error("Invalid email");let s=Us(),i=new Xe(s,e.bunkerPointer,t),c=await i.sendRequest("create_account",[n,r,o||""]);return i.bp.pubkey=c,await i.connect(),i}async function ri(e,t){const n=await e.querySync(t,{kinds:[zs],"#k":[Qe.toString()]});return(await Promise.all(n.map(async o=>{try{const s=JSON.parse(o.content),i=await ir(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 cr=/^(?:([\w.+-]+)@)?([\w_-]+(\.[\w_-]+)+)$/,ar;try{ar=fetch}catch{}async function oi(e){var s;const t=e.match(cr);if(!t)return null;const[n,r="_",o]=t;try{const i=`https://${o}/.well-known/nostr.json?name=${r}`,c=await(await ar(i,{redirect:"error"})).json();let a=c.names[r];return a?{pubkey:a,relays:(s=c.relays)==null?void 0:s[a]}:null}catch{return null}}new TextDecoder("utf-8"),new TextEncoder;var si=5e3;function ii(e){return ai("npub",_e(e))}function ci(e,t){let n=Yn.toWords(t);return Yn.encode(e,n,si)}function ai(e,t){return ci(e,t)}const{window:li}=kr;function lr(e,t,n){const r=e.slice();return r[37]=t[n],r}function ui(e){let t,n,r,o,s,i,c,a;function u(h,w){if(h[9])return wi;if(!h[10])return hi;if(h[10])return di}let f=u(e),l=f&&f(e);return{c(){t=P("div"),n=P("button"),r=tt("⤫"),s=D(),l&&l.c(),B(n,"class",o="tw-absolute tw-top-0 tw-right-0.5 tw-bg-transparent tw-border-none tw-cursor-pointer tw-text-"+e[0]+"-950 tw-text-3xl"),B(t,"class",i="tw-w-80 tw-px-6 tw-py-8 tw-bg-"+e[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){j(h,t,w),T(t,n),T(n,r),T(t,s),l&&l.m(t,null),c||(a=st(n,"click",e[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")&&B(n,"class",o),f===(f=u(h))&&l?l.p(h,w):(l&&l.d(1),l=f&&f(h),l&&(l.c(),l.m(t,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")&&B(t,"class",i)},d(h){h&&q(t),l&&l.d(),c=!1,a()}}}function fi(e){let t,n;function r(i,c){return i[8]?bi:i[10]?pi:gi}let o=r(e),s=o(e);return{c(){t=P("div"),s.c(),B(t,"class",n="tw-px-4 tw-py-2 tw-bg-"+e[0]+"-700 hover:tw-bg-"+e[0]+"-800 tw-rounded tw-cursor-pointer tw-shadow-[0_0px_10px_0px_rgba(0,0,0,0.3)]")},m(i,c){j(i,t,c),s.m(t,null)},p(i,c){o===(o=r(i))&&s?s.p(i,c):(s.d(1),s=o(i),s&&(s.c(),s.m(t,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)]")&&B(t,"class",n)},d(i){i&&q(t),s.d()}}}function di(e){let t,n,r,o,s,i,c=e[10].npub+"",a,u,f,l,h,w,p,d,g,y,m,E=Mn(e[6])+"",O,$,v,_=(e[10].picture||e[10].name)&&ur(e);return{c(){t=P("div"),n=P("div"),n.textContent="You are connected to Nostr as",r=D(),o=P("a"),_&&_.c(),s=D(),i=P("div"),a=tt(c),f=D(),l=P("button"),h=tt("Disconnect"),p=D(),d=P("div"),g=tt("This webpage is using the public key:"),y=P("br"),m=D(),O=tt(E),B(n,"class","tw-text-sm tw-mb-4"),B(i,"class","tw-block tw-break-all"),B(o,"target","_blank"),B(o,"href",u="https://nosta.me/"+e[10].npub),B(o,"class","tw-text-white tw-no-underline tw-group"),B(t,"class","tw-text-center"),B(l,"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-"+e[0]+"-900 hover:tw-bg-"+e[0]+"-950 tw-hover:bg-indigo-900 tw-cursor-pointer tw-text-white"),B(d,"class","tw-block tw-break-all tw-mt-6 tw-text-center tw-text-sm")},m(S,R){j(S,t,R),T(t,n),T(t,r),T(t,o),_&&_.m(o,null),T(o,s),T(o,i),T(i,a),j(S,f,R),j(S,l,R),T(l,h),j(S,p,R),j(S,d,R),T(d,g),T(d,y),T(d,m),T(d,O),$||(v=st(l,"click",e[16]),$=!0)},p(S,R){S[10].picture||S[10].name?_?_.p(S,R):(_=ur(S),_.c(),_.m(o,s)):_&&(_.d(1),_=null),R[0]&1024&&c!==(c=S[10].npub+"")&&ee(a,c),R[0]&1024&&u!==(u="https://nosta.me/"+S[10].npub)&&B(o,"href",u),R[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")&&B(l,"class",w),R[0]&64&&E!==(E=Mn(S[6])+"")&&ee(O,E)},d(S){S&&(q(t),q(f),q(l),q(p),q(d)),_&&_.d(),$=!1,v()}}}function hi(e){let t,n,r,o,s,i,c,a,u,f,l,h,w,p,d,g,y;return{c(){t=P("div"),t.textContent="How do you want to connect to Nostr?",n=D(),r=P("form"),o=P("input"),s=D(),i=P("button"),c=tt("Connect »"),f=D(),l=P("div"),h=tt("Do you need a Nostr account?"),w=P("br"),p=D(),d=P("button"),d.textContent="Sign up now",B(t,"class","tw-text-lg tw-text-center"),B(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"),B(o,"placeholder","user@provider or bunker://..."),o.autofocus=!0,B(i,"class",a="tw-block tw-w-full tw-mt-4 tw-px-2 tw-py-1 tw-text-lg tw-rounded tw-border-0 tw-bg-"+e[0]+"-900 hover:tw-bg-"+e[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=u=!e[12],B(r,"class","flex tw-mt-4 tw-mb-1"),B(d,"class","tw-border-0 tw-bg-transparent tw-text-white tw-cursor-pointer tw-underline tw-text-sm"),B(l,"class","tw-mt-6 tw-text-center tw-text-sm tw-leading-3")},m(m,E){j(m,t,E),j(m,n,E),j(m,r,E),T(r,o),e[24](o),Nt(o,e[1]),T(r,s),T(r,i),T(i,c),j(m,f,E),j(m,l,E),T(l,h),T(l,w),T(l,p),T(l,d),o.focus(),g||(y=[st(o,"input",e[25]),st(r,"submit",e[15]),st(d,"click",e[17])],g=!0)},p(m,E){E[0]&2&&o.value!==m[1]&&Nt(o,m[1]),E[0]&1&&a!==(a="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")&&B(i,"class",a),E[0]&4096&&u!==(u=!m[12])&&(i.disabled=u)},d(m){m&&(q(t),q(n),q(r),q(f),q(l)),e[24](null),g=!1,$t(y)}}}function wi(e){let t,n,r,o,s,i,c,a,u,f,l,h,w,p,d,g,y,m,E,O,$,v,_,S,R=cn(e[11]),N=[];for(let A=0;A<R.length;A+=1)N[A]=hr(lr(e,R,A));return{c(){t=P("div"),t.textContent="Create a Nostr account",n=D(),r=P("form"),o=P("div"),s=P("input"),i=D(),c=P("div"),c.textContent="@",a=D(),u=P("select");for(let A=0;A<N.length;A+=1)N[A].c();f=D(),l=P("div"),l.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=
|
|
1
|
+
var wc=Object.defineProperty;var pc=(Ut,F,vt)=>F in Ut?wc(Ut,F,{enumerable:!0,configurable:!0,writable:!0,value:vt}):Ut[F]=vt;var y=(Ut,F,vt)=>(pc(Ut,typeof F!="symbol"?F+"":F,vt),vt);(function(){"use strict";var Dr,Wr;const Ut='.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 F(){}function vt(t){return t()}function yn(){return Object.create(null)}function Kt(t){t.forEach(vt)}function mn(t){return typeof t=="function"}function Fr(t,e){return t!=t?e==e:t!==e||t&&typeof t=="object"||typeof t=="function"}let ue;function fe(t,e){return t===e?!0:(ue||(ue=document.createElement("a")),ue.href=e,t===ue.href)}function Jr(t){return Object.keys(t).length===0}const Yr=typeof window<"u"?window:typeof globalThis<"u"?globalThis:global;function N(t,e){t.appendChild(e)}function j(t,e,n){t.insertBefore(e,n||null)}function q(t){t.parentNode&&t.parentNode.removeChild(t)}function Qr(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 Xr(t){return Array.from(t.childNodes)}function de(t,e){e=""+e,t.data!==e&&(t.data=e)}function Mt(t,e){t.value=e??""}function xn(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 to(t){const e=t.querySelector(":checked");return e&&e.__value}function En(t,e,n){t.classList.toggle(e,!!n)}let Xt;function te(t){Xt=t}function eo(){if(!Xt)throw new Error("Function called outside component initialization");return Xt}function no(t){eo().$$.on_mount.push(t)}const zt=[],he=[];let Vt=[];const vn=[],ro=Promise.resolve();let Te=!1;function oo(){Te||(Te=!0,ro.then(_n))}function we(t){Vt.push(t)}const Ie=new Set;let Dt=0;function _n(){if(Dt!==0)return;const t=Xt;do{try{for(;Dt<zt.length;){const e=zt[Dt];Dt++,te(e),so(e.$$)}}catch(e){throw zt.length=0,Dt=0,e}for(te(null),zt.length=0,Dt=0;he.length;)he.pop()();for(let e=0;e<Vt.length;e+=1){const n=Vt[e];Ie.has(n)||(Ie.add(n),n())}Vt.length=0}while(zt.length);for(;vn.length;)vn.pop()();Te=!1,Ie.clear(),te(t)}function so(t){if(t.fragment!==null){t.update(),Kt(t.before_update);const e=t.dirty;t.dirty=[-1],t.fragment&&t.fragment.p(t.ctx,e),t.after_update.forEach(we)}}function io(t){const e=[],n=[];Vt.forEach(r=>t.indexOf(r)===-1?e.push(r):n.push(r)),n.forEach(r=>r()),Vt=e}const co=new Set;function lo(t,e){t&&t.i&&(co.delete(t),t.i(e))}function Sn(t){return(t==null?void 0:t.length)!==void 0?t:Array.from(t)}function ao(t,e,n){const{fragment:r,after_update:o}=t.$$;r&&r.m(e,n),we(()=>{const s=t.$$.on_mount.map(vt).filter(mn);t.$$.on_destroy?t.$$.on_destroy.push(...s):Kt(s),t.$$.on_mount=[]}),o.forEach(we)}function uo(t,e){const n=t.$$;n.fragment!==null&&(io(n.after_update),Kt(n.on_destroy),n.fragment&&n.fragment.d(e),n.on_destroy=n.fragment=null,n.ctx=[])}function fo(t,e){t.$$.dirty[0]===-1&&(zt.push(t),oo(),t.$$.dirty.fill(0)),t.$$.dirty[e/31|0]|=1<<e%31}function ho(t,e,n,r,o,s,i=null,c=[-1]){const l=Xt;te(t);const a=t.$$={fragment:null,ctx:[],props:s,update:F,not_equal:o,bound:yn(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(e.context||(l?l.$$.context:[])),callbacks:yn(),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 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&&fo(t,u)),h}):[],a.update(),f=!0,Kt(a.before_update),a.fragment=r?r(a.ctx):!1,e.target){if(e.hydrate){const u=Xr(e.target);a.fragment&&a.fragment.l(u),u.forEach(q)}else a.fragment&&a.fragment.c();e.intro&&lo(t.$$.fragment),ao(t,e.target,e.anchor),_n()}te(l)}class wo{constructor(){y(this,"$$");y(this,"$$set")}$destroy(){uo(this,1),this.$destroy=F}$on(e,n){if(!mn(n))return F;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&&!Jr(e)&&(this.$$.skip_bound=!0,this.$$set(e),this.$$.skip_bound=!1)}}const po="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(po);function go(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var Ne={exports:{}};function kn(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,g=s;o=void 0,s=void 0,l=t.apply(w,g)}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}Ne.exports.debounce=kn,Ne.exports=kn;var bo=Ne.exports;const An=go(bo),Ue=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Bn=t=>t instanceof Uint8Array,Pe=t=>new DataView(t.buffer,t.byteOffset,t.byteLength),at=(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 Y(t){if(!Bn(t))throw new Error("Uint8Array expected");let e="";for(let n=0;n<t.length;n++)e+=yo[t[n]];return e}function Le(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 $n(t){if(typeof t=="string"&&(t=mo(t)),!Bn(t))throw new Error(`expected Uint8Array, got ${typeof t}`);return t}let xo=class{clone(){return this._cloneInto()}};function On(t){const e=r=>t().update($n(r)).digest(),n=t();return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=()=>t(),e}function Eo(t=32){if(Ue&&typeof Ue.getRandomValues=="function")return Ue.getRandomValues(new Uint8Array(t));throw new Error("crypto.getRandomValues must be defined")}function Tn(t){if(!Number.isSafeInteger(t)||t<0)throw new Error(`Wrong positive integer: ${t}`)}function In(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");Tn(t.outputLen),Tn(t.blockLen)}function pe(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){In(t);const n=e.outputLen;if(t.length<n)throw new Error(`digestInto() expects output buffer of length at least ${n}`)}const Ce=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Nn=t=>t instanceof Uint8Array,Re=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");function So(t){if(typeof t!="string")throw new Error(`utf8ToBytes expected string, got ${typeof t}`);return new Uint8Array(new TextEncoder().encode(t))}function He(t){if(typeof t=="string"&&(t=So(t)),!Nn(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(!Nn(r))throw new Error("Uint8Array expected");e.set(r,n),n+=r.length}),e}class Un{clone(){return this._cloneInto()}}function Ao(t){const e=r=>t().update(He(r)).digest(),n=t();return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=()=>t(),e}function Pn(t=32){if(Ce&&typeof Ce.getRandomValues=="function")return Ce.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 Un{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=Re(this.buffer)}update(e){pe(this);const{view:n,buffer:r,blockLen:o}=this;e=He(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=Re(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){pe(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=Re(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]),_t=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),St=new Uint32Array(64);let No=class extends $o{constructor(){super(64,32,8,!1),this.A=_t[0]|0,this.B=_t[1]|0,this.C=_t[2]|0,this.D=_t[3]|0,this.E=_t[4]|0,this.F=_t[5]|0,this.G=_t[6]|0,this.H=_t[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)St[u]=e.getUint32(n,!1);for(let u=16;u<64;u++){const h=St[u-15],w=St[u-2],g=ut(h,7)^ut(h,18)^h>>>3,d=ut(w,17)^ut(w,19)^w>>>10;St[u]=d+St[u-7]+g+St[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+Oo(c,l,a)+Io[u]+St[u]|0,d=(ut(r,2)^ut(r,13)^ut(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(){St.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};const qe=Ao(()=>new No);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Ln=BigInt(0),ge=BigInt(1),Uo=BigInt(2),be=t=>t instanceof Uint8Array,Po=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function Wt(t){if(!be(t))throw new Error("Uint8Array expected");let e="";for(let n=0;n<t.length;n++)e+=Po[t[n]];return e}function Cn(t){const e=t.toString(16);return e.length&1?`0${e}`:e}function je(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);return BigInt(t===""?"0":`0x${t}`)}function Zt(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 je(Wt(t))}function Ke(t){if(!be(t))throw new Error("Uint8Array expected");return je(Wt(Uint8Array.from(t).reverse()))}function kt(t,e){return Zt(t.toString(16).padStart(e*2,"0"))}function Me(t,e){return kt(t,e).reverse()}function Lo(t){return Zt(Cn(t))}function J(t,e,n){let r;if(typeof e=="string")try{r=Zt(e)}catch(s){throw new Error(`${t} must be valid hex string, got "${e}". Cause: ${s}`)}else if(be(e))r=Uint8Array.from(e);else throw new Error(`${t} must be hex string or Uint8Array`);const o=r.length;if(typeof n=="number"&&o!==n)throw new Error(`${t} expected ${n} bytes, got ${o}`);return r}function Pt(...t){const e=new Uint8Array(t.reduce((r,o)=>r+o.length,0));let n=0;return t.forEach(r=>{if(!be(r))throw new Error("Uint8Array expected");e.set(r,n),n+=r.length}),e}function 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>Ln;t>>=ge,e+=1);return e}function qo(t,e){return t>>BigInt(e)&ge}const jo=(t,e,n)=>t|(n?ge:Ln)<<BigInt(e),ze=t=>(Uo<<BigInt(t-1))-ge,Ve=t=>new Uint8Array(t),Rn=t=>Uint8Array.from(t);function Hn(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=Ve(t),o=Ve(t),s=0;const i=()=>{r.fill(1),o.fill(0),s=0},c=(...u)=>n(o,r,...u),l=(u=Ve())=>{o=c(Rn([0]),u),r=c(),u.length!==0&&(o=c(Rn([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 Pt(...h)};return(u,h)=>{i(),l(u);let w;for(;!(w=h(a()));)l();return i(),w}}const Ko={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 ee(t,e,n={}){const r=(o,s,i)=>{const c=Ko[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 Mo=Object.freeze(Object.defineProperty({__proto__:null,bitGet:qo,bitLen:Ho,bitMask:ze,bitSet:jo,bytesToHex:Wt,bytesToNumberBE:et,bytesToNumberLE:Ke,concatBytes:Pt,createHmacDrbg:Hn,ensureBytes:J,equalBytes:Co,hexToBytes:Zt,hexToNumber:je,numberToBytesBE:kt,numberToBytesLE:Me,numberToHexUnpadded:Cn,numberToVarBytesBE:Lo,utf8ToBytes:Ro,validateObject:ee},Symbol.toStringTag,{value:"Module"}));/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const W=BigInt(0),z=BigInt(1),Lt=BigInt(2),zo=BigInt(3),De=BigInt(4),qn=BigInt(5),jn=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===z)return W;let r=z;for(;e>W;)e&z&&(r=r*t%n),t=t*t%n,e>>=z;return r}function ot(t,e,n){let r=t;for(;e-- >W;)r*=r,r%=n;return r}function We(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=z;for(;n!==W;){const c=r/n,l=r%n,a=o-s*c;r=n,n=l,o=s,s=a}if(r!==z)throw new Error("invert: does not exist");return Z(o,e)}function Do(t){const e=(t-z)/Lt;let n,r,o;for(n=t-z,r=0;n%Lt===W;n/=Lt,r++);for(o=Lt;o<t&&Vo(o,e,t)!==t-z;o++);if(r===1){const i=(t+z)/De;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+z)/Lt;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 g=c.pow(f,z<<BigInt(a-w-1));f=c.sqr(g),u=c.mul(u,g),h=c.mul(h,f),a=w}return u}}function Wo(t){if(t%De===zo){const e=(t+z)/De;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%jn===qn){const e=(t-qn)/jn;return function(r,o){const s=r.mul(o,Lt),i=r.pow(s,e),c=r.mul(o,i),l=r.mul(r.mul(c,Lt),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 ee(t,n)}function Fo(t,e,n){if(n<W)throw new Error("Expected power > 0");if(n===W)return t.ONE;if(n===z)return e;let r=t.ONE,o=e;for(;n>W;)n&z&&(r=t.mul(r,o)),o=t.sqr(o),n>>=z;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 Kn(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}=Kn(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:ze(o),ZERO:W,ONE:z,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&z)===z,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*We(a,t),t),sqrN:l=>l*l,addN:(l,a)=>l+a,subN:(l,a)=>l-a,mulN:(l,a)=>l*a,inv:l=>We(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):kt(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 Mn(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 zn(t){const e=Mn(t);return e+Math.ceil(e/2)}function Qo(t,e,n=!1){const r=t.length,o=Mn(e),s=zn(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-z)+z;return n?Me(c,o):kt(c,o)}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Xo=BigInt(0),Ze=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&Ze&&(i=i.add(c)),c=c.double(),s>>=Ze;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 g=0;g<c;g++){const d=g*l;let p=Number(i&u);i>>=w,p>l&&(p-=h,i+=Ze);const b=d,m=d+Math.abs(p)-1,x=g%2!==0,O=p<0;p===0?f=f.add(n(x,s[b])):a=a.add(n(O,s[m]))}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 Vn(t){return Go(t.Fp),ee(t,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...Kn(t.n,t.nBitLength),...t,p:t.Fp.ORDER})}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function es(t){const e=Vn(t);ee(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}=Mo,Ct={Err:class extends Error{constructor(e=""){super(e)}},_parseInt(t){const{Err:e}=Ct;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}=Ct,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}=Ct._parseInt(n.subarray(2)),{d:i,l:c}=Ct._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}`}},gt=BigInt(0),st=BigInt(1);BigInt(2);const Dn=BigInt(3);BigInt(4);function os(t){const e=es(t),{Fp:n}=e,r=e.toBytes||((g,d,p)=>{const b=d.toAffine();return Pt(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 s(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),s(e.Gx)))throw new Error("bad generator point: equation left != right");function i(g){return typeof g=="bigint"&><g&&g<e.n}function c(g){if(!i(g))throw new Error("Expected valid bigint: 0 < bigint < curve.n")}function l(g){const{allowedPrivateKeyLengths:d,nByteLength:p,wrapPrivateKey:b,n:m}=e;if(d&&typeof g!="bigint"){if(g instanceof Uint8Array&&(g=Wt(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:et(J("private key",g,p))}catch{throw new Error(`private key must be ${p} bytes, hex or bigint, not ${typeof g}`)}return b&&(x=Z(x,m)),c(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(J("pointHex",d)));return p.assertValidity(),p}static fromPrivateKey(d){return u.BASE.multiply(l(d))}_setWindowSize(d){this._WINDOW_SIZE=d,a.delete(this)}assertValidity(){if(this.is0()){if(e.allowInfinityPoint&&!n.is0(this.py))return;throw new Error("bad point: ZERO")}const{x:d,y:p}=this.toAffine();if(!n.isValid(d)||!n.isValid(p))throw new Error("bad point: x or y not FE");const b=n.sqr(p),m=s(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:O,pz:k}=d,_=n.eql(n.mul(p,k),n.mul(x,m)),v=n.eql(n.mul(b,k),n.mul(O,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,Dn),{px:m,py:x,pz:O}=this;let k=n.ZERO,_=n.ZERO,v=n.ZERO,S=n.mul(m,m),U=n.mul(x,x),T=n.mul(O,O),B=n.mul(m,x);return B=n.add(B,B),v=n.mul(m,O),v=n.add(v,v),k=n.mul(d,v),_=n.mul(b,T),_=n.add(k,_),k=n.sub(U,_),_=n.add(U,_),_=n.mul(k,_),k=n.mul(B,k),v=n.mul(b,v),T=n.mul(d,T),B=n.sub(S,T),B=n.mul(d,B),B=n.add(B,v),v=n.add(S,S),S=n.add(v,S),S=n.add(S,T),S=n.mul(S,B),_=n.add(_,S),T=n.mul(x,O),T=n.add(T,T),S=n.mul(T,B),k=n.sub(k,S),v=n.mul(T,U),v=n.add(v,v),v=n.add(v,v),new u(k,_,v)}add(d){f(d);const{px:p,py:b,pz:m}=this,{px:x,py:O,pz:k}=d;let _=n.ZERO,v=n.ZERO,S=n.ZERO;const U=e.a,T=n.mul(e.b,Dn);let B=n.mul(p,x),R=n.mul(b,O),C=n.mul(m,k),rt=n.add(p,b),E=n.add(x,O);rt=n.mul(rt,E),E=n.add(B,R),rt=n.sub(rt,E),E=n.add(p,m);let A=n.add(x,k);return E=n.mul(E,A),A=n.add(B,C),E=n.sub(E,A),A=n.add(b,m),_=n.add(O,k),A=n.mul(A,_),_=n.add(R,C),A=n.sub(A,_),S=n.mul(U,E),_=n.mul(T,C),S=n.add(_,S),_=n.sub(R,S),S=n.add(R,S),v=n.mul(_,S),R=n.add(B,B),R=n.add(R,B),C=n.mul(U,C),E=n.mul(T,E),R=n.add(R,C),C=n.sub(B,C),C=n.mul(U,C),E=n.add(E,C),B=n.mul(R,E),v=n.add(v,B),B=n.mul(A,E),_=n.mul(rt,_),_=n.sub(_,B),B=n.mul(rt,R),S=n.mul(A,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,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===gt)return p;if(c(d),d===st)return this;const{endo:b}=e;if(!b)return w.unsafeLadder(this,d);let{k1neg:m,k1:x,k2neg:O,k2:k}=b.splitScalar(d),_=p,v=p,S=this;for(;x>gt||k>gt;)x&st&&(_=_.add(S)),k&st&&(v=v.add(S)),S=S.double(),x>>=st,k>>=st;return m&&(_=_.negate()),O&&(v=v.negate()),v=new u(n.mul(v.px,b.beta),v.py,v.pz),_.add(v)}multiply(d){c(d);let p=d,b,m;const{endo:x}=e;if(x){const{k1neg:O,k1:k,k2neg:_,k2:v}=x.splitScalar(p);let{p:S,f:U}=this.wNAF(k),{p:T,f:B}=this.wNAF(v);S=w.constTimeNegate(O,S),T=w.constTimeNegate(_,T),T=new u(n.mul(T.px,x.beta),T.py,T.pz),b=S.add(T),m=U.add(B)}else{const{p:O,f:k}=this.wNAF(p);b=O,m=k}return u.normalizeZ([b,m])[0]}multiplyAndAddUnsafe(d,p,b){const m=u.BASE,x=(k,_)=>_===gt||_===st||!k.equals(m)?k.multiplyUnsafe(_):k.multiply(_),O=x(this,p).add(x(d,b));return O.is0()?void 0:O}toAffine(d){const{px:p,py:b,pz:m}=this,x=this.is0();d==null&&(d=x?n.ONE:n.inv(m));const O=n.mul(p,d),k=n.mul(b,d),_=n.mul(m,d);if(x)return{x:n.ZERO,y:n.ZERO};if(!n.eql(_,n.ONE))throw new Error("invZ was invalid");return{x:O,y:k}}isTorsionFree(){const{h:d,isTorsionFree:p}=e;if(d===st)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===st?this:p?p(u,this):this.multiplyUnsafe(e.h)}toRawBytes(d=!0){return this.assertValidity(),r(u,this,d)}toHex(d=!0){return Wt(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=Vn(t);return ee(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(E){return gt<E&&E<n.ORDER}function c(E){return Z(E,r)}function l(E){return We(E,r)}const{ProjectivePoint:a,normPrivateKeyToScalar:f,weierstrassEquation:u,isWithinCurveOrder:h}=os({...e,toBytes(E,A,P){const K=A.toAffine(),H=n.toBytes(K.x),V=Pt;return P?V(Uint8Array.from([A.hasEvenY()?2:3]),H):V(Uint8Array.from([4]),H,n.toBytes(K.y))},fromBytes(E){const A=E.length,P=E[0],K=E.subarray(1);if(A===o&&(P===2||P===3)){const H=et(K);if(!i(H))throw new Error("Point is not on curve");const V=u(H);let X=n.sqrt(V);const G=(X&st)===st;return(P&1)===1!==G&&(X=n.neg(X)),{x:H,y:X}}else if(A===s&&P===4){const H=n.fromBytes(K.subarray(0,n.BYTES)),V=n.fromBytes(K.subarray(n.BYTES,2*n.BYTES));return{x:H,y:V}}else throw new Error(`Point of length ${A} was invalid. Expected ${o} compressed bytes or ${s} uncompressed bytes`)}}),w=E=>Wt(kt(E,e.nByteLength));function g(E){const A=r>>st;return E>A}function d(E){return g(E)?c(-E):E}const p=(E,A,P)=>et(E.slice(A,P));class b{constructor(A,P,K){this.r=A,this.s=P,this.recovery=K,this.assertValidity()}static fromCompact(A){const P=e.nByteLength;return A=J("compactSignature",A,P*2),new b(p(A,0,P),p(A,P,2*P))}static fromDER(A){const{r:P,s:K}=Ct.toSig(J("DER",A));return new b(P,K)}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(A){return new b(this.r,this.s,A)}recoverPublicKey(A){const{r:P,s:K,recovery:H}=this,V=v(J("msgHash",A));if(H==null||![0,1,2,3].includes(H))throw new Error("recovery id invalid");const X=H===2||H===3?P+e.n:P;if(X>=n.ORDER)throw new Error("recovery id 2 or 3 invalid");const G=H&1?"03":"02",ht=a.fromHex(G+w(X)),wt=l(X),It=c(-V*wt),jt=c(K*wt),pt=a.BASE.multiplyAndAddUnsafe(ht,It,jt);if(!pt)throw new Error("point at infinify");return pt.assertValidity(),pt}hasHighS(){return g(this.s)}normalizeS(){return this.hasHighS()?new b(this.r,c(-this.s),this.recovery):this}toDERRawBytes(){return Zt(this.toDERHex())}toDERHex(){return Ct.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return Zt(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=zn(e.n);return Qo(e.randomBytes(E),e.n)},precompute(E=8,A=a.BASE){return A._setWindowSize(E),A.multiply(BigInt(3)),A}};function x(E,A=!0){return a.fromPrivateKey(E).toRawBytes(A)}function O(E){const A=E instanceof Uint8Array,P=typeof E=="string",K=(A||P)&&E.length;return A?K===o||K===s:P?K===2*o||K===2*s:E instanceof a}function k(E,A,P=!0){if(O(E))throw new Error("first arg must be private key");if(!O(A))throw new Error("second arg must be public key");return a.fromHex(A).multiply(f(E)).toRawBytes(P)}const _=e.bits2int||function(E){const A=et(E),P=E.length*8-e.nBitLength;return P>0?A>>BigInt(P):A},v=e.bits2int_modN||function(E){return c(_(E))},S=ze(e.nBitLength);function U(E){if(typeof E!="bigint")throw new Error("bigint expected");if(!(gt<=E&&E<S))throw new Error(`bigint expected < 2^${e.nBitLength}`);return kt(E,e.nByteLength)}function T(E,A,P=B){if(["recovered","canonical"].some(M=>M in P))throw new Error("sign() legacy options not supported");const{hash:K,randomBytes:H}=e;let{lowS:V,prehash:X,extraEntropy:G}=P;V==null&&(V=!0),E=J("msgHash",E),X&&(E=J("prehashed msgHash",K(E)));const ht=v(E),wt=f(A),It=[U(wt),U(ht)];if(G!=null){const M=G===!0?H(n.BYTES):G;It.push(J("extraEntropy",M))}const jt=Pt(...It),pt=ht;function I(M){const Et=_(M);if(!h(Et))return;const ae=l(Et),Nt=a.BASE.multiply(Et).toAffine(),lt=c(Nt.x);if(lt===gt)return;const Qt=c(ae*c(pt+lt*wt));if(Qt===gt)return;let Zr=(Nt.x===lt?0:2)|Number(Nt.y&st),Gr=Qt;return V&&g(Qt)&&(Gr=d(Qt),Zr^=1),new b(lt,Gr,Zr)}return{seed:jt,k2sig:I}}const B={lowS:e.lowS,prehash:!1},R={lowS:e.lowS,prehash:!1};function C(E,A,P=B){const{seed:K,k2sig:H}=T(E,A,P),V=e;return Hn(V.hash.outputLen,V.nByteLength,V.hmac)(K,H)}a.BASE._setWindowSize(8);function rt(E,A,P,K=R){var Nt;const H=E;if(A=J("msgHash",A),P=J("publicKey",P),"strict"in K)throw new Error("options.strict was renamed to lowS");const{lowS:V,prehash:X}=K;let G,ht;try{if(typeof H=="string"||H instanceof Uint8Array)try{G=b.fromDER(H)}catch(lt){if(!(lt instanceof Ct.Err))throw lt;G=b.fromCompact(H)}else if(typeof H=="object"&&typeof H.r=="bigint"&&typeof H.s=="bigint"){const{r:lt,s:Qt}=H;G=new b(lt,Qt)}else throw new Error("PARSE");ht=a.fromHex(P)}catch(lt){if(lt.message==="PARSE")throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(V&&G.hasHighS())return!1;X&&(A=e.hash(A));const{r:wt,s:It}=G,jt=v(A),pt=l(It),I=c(jt*pt),M=c(wt*pt),Et=(Nt=a.BASE.multiplyAndAddUnsafe(ht,I,M))==null?void 0:Nt.toAffine();return Et?c(Et.x)===wt:!1}return{CURVE:e,getPublicKey:x,getSharedSecret:k,sign:C,verify:rt,ProjectivePoint:a,Signature:b,utils:m}}class Wn extends Un{constructor(e,n){super(),this.finished=!1,this.destroyed=!1,vo(e);const r=He(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 pe(this),this.iHash.update(e),this}digestInto(e){pe(this),In(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 Zn=(t,e,n)=>new Wn(t,e).update(n).digest();Zn.create=(t,e)=>new Wn(t,e);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function cs(t){return{hash:t,hmac:(e,...n)=>Zn(t,e,ko(...n)),randomBytes:Pn}}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 ye=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),me=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),Gn=BigInt(1),xe=BigInt(2),Fn=(t,e)=>(t+e/xe)/e;function Jn(t){const e=ye,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,xe,e)*a%e,g=ot(w,o,e)*w%e,d=ot(g,s,e)*g%e,p=ot(d,c,e)*d%e,b=ot(p,l,e)*p%e,m=ot(b,c,e)*d%e,x=ot(m,n,e)*f%e,O=ot(x,i,e)*g%e,k=ot(O,r,e)*a%e,_=ot(k,xe,e);if(!Ge.eql(Ge.sqr(_),t))throw new Error("Cannot find square root");return _}const Ge=Yo(ye,void 0,void 0,{sqrt:Jn}),ne=ls({a:BigInt(0),b:BigInt(7),Fp:Ge,n:me,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:t=>{const e=me,n=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),r=-Gn*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),s=n,i=BigInt("0x100000000000000000000000000000000"),c=Fn(s*t,e),l=Fn(-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}}}},qe),Ee=BigInt(0),Yn=t=>typeof t=="bigint"&&Ee<t&&t<ye,as=t=>typeof t=="bigint"&&Ee<t&&t<me,Qn={};function ve(t,...e){let n=Qn[t];if(n===void 0){const r=qe(Uint8Array.from(t,o=>o.charCodeAt(0)));n=Pt(r,r),Qn[t]=n}return qe(Pt(n,...e))}const Fe=t=>t.toRawBytes(!0).slice(1),Je=t=>kt(t,32),Ye=t=>Z(t,ye),re=t=>Z(t,me),Qe=ne.ProjectivePoint,us=(t,e,n)=>Qe.BASE.multiplyAndAddUnsafe(t,e,n);function Xe(t){let e=ne.utils.normPrivateKeyToScalar(t),n=Qe.fromPrivateKey(e);return{scalar:n.hasEvenY()?e:re(-e),bytes:Fe(n)}}function Xn(t){if(!Yn(t))throw new Error("bad x: need 0 < x < p");const e=Ye(t*t),n=Ye(e*t+BigInt(7));let r=Jn(n);r%xe!==Ee&&(r=Ye(-r));const o=new Qe(t,r,Gn);return o.assertValidity(),o}function tr(...t){return re(et(ve("BIP0340/challenge",...t)))}function fs(t){return Xe(t).bytes}function ds(t,e,n=Pn(32)){const r=J("message",t),{bytes:o,scalar:s}=Xe(e),i=J("auxRand",n,32),c=Je(s^et(ve("BIP0340/aux",i))),l=ve("BIP0340/nonce",c,o,r),a=re(et(l));if(a===Ee)throw new Error("sign failed: k is zero");const{bytes:f,scalar:u}=Xe(a),h=tr(f,o,r),w=new Uint8Array(64);if(w.set(f,0),w.set(Je(re(u+h*s)),32),!er(w,r,o))throw new Error("sign: Invalid signature produced");return w}function er(t,e,n){const r=J("signature",t,64),o=J("message",e),s=J("publicKey",n,32);try{const i=Xn(et(s)),c=et(r.subarray(0,32));if(!Yn(c))return!1;const l=et(r.subarray(32,64));if(!as(l))return!1;const a=tr(Je(c),Fe(i),o),f=us(i,l,re(-a));return!(!f||!f.hasEvenY()||f.toAffine().x!==c)}catch{return!1}}const Q={getPublicKey:fs,sign:ds,verify:er,utils:{randomPrivateKey:ne.utils.randomPrivateKey,lift_x:Xn,pointToBytes:Fe,numberToBytesBE:kt,bytesToNumberBE:et,taggedHash:ve,mod:Z}};function tn(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 nr(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");tn(t.outputLen),tn(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){nr(t);const n=e.outputLen;if(t.length<n)throw new Error(`digestInto() expects output buffer of length at least ${n}`)}const en={number:tn,bool:hs,bytes:nr,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){en.exists(this);const{view:n,buffer:r,blockLen:o}=this;e=$n(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){en.exists(this),en.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]),At=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Bt=new Uint32Array(64);class rr extends ys{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: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)Bt[u]=e.getUint32(n,!1);for(let u=16;u<64;u++){const h=Bt[u-15],w=Bt[u-2],g=at(h,7)^at(h,18)^h>>>3,d=at(w,17)^at(w,19)^w>>>10;Bt[u]=d+Bt[u-7]+g+Bt[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=at(c,6)^at(c,11)^at(c,25),w=f+h+ms(c,l,a)+Es[u]+Bt[u]|0,d=(at(r,2)^at(r,13)^at(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(){Bt.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}}class vs extends rr{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 nn=On(()=>new rr);On(()=>new vs);var Gt=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 Q.utils.randomPrivateKey()}getPublicKey(e){return Y(Q.getPublicKey(e))}finalizeEvent(e,n){const r=e;return r.pubkey=Y(Q.getPublicKey(n)),r.id=rn(r),r.sig=Y(Q.sign(rn(r),n)),r[Gt]=!0,r}verifyEvent(e){if(typeof e[Gt]=="boolean")return e[Gt];const n=rn(e);if(n!==e.id)return e[Gt]=!1,!1;try{const r=Q.verify(e.sig,n,e.pubkey);return e[Gt]=r,r}catch{return e[Gt]=!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 rn(t){let e=nn(ks.encode(Bs(t)));return Y(e)}var _e=new As,$s=_e.generateSecretKey,or=_e.getPublicKey;_e.finalizeEvent,_e.verifyEvent;var Rt=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 oe(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){y(this,"value");y(this,"next",null);y(this,"prev",null);this.value=e}},Us=class{constructor(){y(this,"first");y(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}},Ps=class{generateSecretKey(){return Q.utils.randomPrivateKey()}getPublicKey(e){return Y(Q.getPublicKey(e))}finalizeEvent(e,n){const r=e;return r.pubkey=Y(Q.getPublicKey(n)),r.id=on(r),r.sig=Y(Q.sign(on(r),n)),r[Rt]=!0,r}verifyEvent(e){if(typeof e[Rt]=="boolean")return e[Rt];const n=on(e);if(n!==e.id)return e[Rt]=!1,!1;try{const r=Q.verify(e.sig,n,e.pubkey);return e[Rt]=r,r}catch{return e[Rt]=!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 on(t){let e=nn(Is.encode(Ls(t)));return Y(e)}var Se=new Ps;Se.generateSecretKey,Se.getPublicKey,Se.finalizeEvent;var Cs=Se.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 js(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 Ks(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 Ms(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[Rt]=!0,!0),sr;try{sr=WebSocket}catch{}var ir=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 Us);y(this,"queueRunning",!1);y(this,"challenge");y(this,"serial",0);y(this,"verifyEvent");this.url=oe(e),this.verifyEvent=n.verifyEvent}static async connect(e,n){const r=new ir(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 sr(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=Ks(e);if(n){const s=this.openSubs.get(n);if(!s)return;const i=js(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(Ms(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){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||(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){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=oe(e);let r=this.relays.get(e);return r||(r=new ir(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(oe).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,s=[],i=[];let c=h=>{var w;i[h]=!0,i.filter(g=>g).length===e.length&&((w=r.oneose)==null||w.call(r),c=()=>{})};const l=[];let a=(h,w)=>{var g;c(h),l[h]=w,l.filter(d=>d).length===e.length&&((g=r.onclose)==null||g.call(r,l),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(oe).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:()=>c(w),onclose:b=>a(w,b),alreadyHaveEvent:f,eoseTimeout:r.maxWait});s.push(p)}));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(oe).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 cr(t){return t instanceof Uint8Array||t!=null&&typeof t=="object"&&t.constructor.name==="Uint8Array"}function Ht(t,...e){if(!cr(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 ke(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 lr(t,e){Ht(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 se(t){if(typeof t=="string")t=Fs(t);else if(cr(t))t=t.slice();else throw new Error(`Uint8Array expected, got ${typeof t}`);return t}const Js=(t,e)=>(Object.assign(e,t),e),bt=16,sn=new Uint8Array(16),ft=nt(sn),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 ar{constructor(e,n){this.blockLen=bt,this.outputLen=bt,this.s0=0,this.s1=0,this.s2=0,this.s3=0,this.finished=!1,e=se(e),Ht(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 g=0;g<128;g++)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 g=0;g<u;g++)for(let d=0;d<h;d++){let p=0,b=0,m=0,x=0;for(let O=0;O<a;O++){if(!(d>>>a-O-1&1))continue;const{s0:_,s1:v,s2:S,s3:U}=l[a*g+O];p^=_,b^=v,m^=S,x^=U}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: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 g of[e,n,r,o])for(let d=0;d<4;d++){const p=g>>>8*d&255;for(let b=8/s-1;b>=0;b--){const m=p>>>s*b&h,{s0:x,s1:O,s2:k,s3:_}=i[w*c+m];l^=x,a^=O,f^=k,u^=_,w+=1}}this.s0=l,this.s1=a,this.s2=f,this.s3=u}update(e){e=se(e),ke(this);const n=nt(e),r=Math.floor(e.length/bt),o=e.length%bt;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&&(sn.set(e.subarray(r*bt)),this._updateBlock(ft[0],ft[1],ft[2],ft[3]),ft.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){ke(this),lr(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(bt);return this.digestInto(e),this.destroy(),e}}class ei extends ar{constructor(e,n){e=se(e);const r=Xs(e.slice());super(r,n),r.fill(0)}update(e){e=se(e),ke(this);const n=nt(e),r=e.length%bt,o=Math.floor(e.length/bt);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&&(sn.set(e.subarray(o*bt)),this._updateBlock(it(ft[3]),it(ft[2]),it(ft[1]),it(ft[0])),ft.fill(0)),this}digestInto(e){ke(this),lr(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 ur(t){const e=(r,o)=>t(o,r.length).update(se(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}ur((t,e)=>new ar(t,e)),ur((t,e)=>new ei(t,e));const $t=16,ni=283;function cn(t){return t<<1^ni&-(t>>7)}function Ft(t,e){let n=0;for(;e>0;e>>=1)n^=t&-(e&1),t=cn(t);return n}const ln=(()=>{let t=new Uint8Array(256);for(let n=0,r=1;n<256;n++,r^=cn(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=ln.map((t,e)=>ln.indexOf(e)),oi=t=>t<<24|t>>>8,an=t=>t<<8|t>>>24;function fr(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(an),o=r.map(an),s=o.map(an),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 un=fr(ln,t=>Ft(t,3)<<24|t<<16|t<<8|Ft(t,2)),dr=fr(ri,t=>Ft(t,11)<<24|Ft(t,13)<<16|Ft(t,9)<<8|Ft(t,14)),si=(()=>{const t=new Uint8Array(16);for(let e=0,n=1;e<16;e++,n=cn(n))t[e]=n;return t})();function hr(t){Ht(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}=un,r=nt(t),o=r.length,s=c=>dt(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=hr(t),n=e.slice(),r=e.length,{sbox2:o}=un,{T0:s,T1:i,T2:c,T3:l}=dr;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=dt(o,f,f,f,f);n[a]=s[u&255]^i[u>>>8&255]^c[u>>>16&255]^l[u>>>24]}return n}function Ot(t,e,n,r,o,s){return t[n<<8&65280|r>>>8&255]^e[o>>>8&65280|s>>>24&255]}function dt(t,e,n,r,o){return t[e&255|n&65280]|t[r>>>16&255|o>>>16&65280]<<16}function wr(t,e,n,r,o){const{sbox2:s,T01:i,T23:c}=un;let l=0;e^=t[l++],n^=t[l++],r^=t[l++],o^=t[l++];const a=t.length/4-2;for(let g=0;g<a;g++){const d=t[l++]^Ot(i,c,e,n,r,o),p=t[l++]^Ot(i,c,n,r,o,e),b=t[l++]^Ot(i,c,r,o,e,n),m=t[l++]^Ot(i,c,o,e,n,r);e=d,n=p,r=b,o=m}const f=t[l++]^dt(s,e,n,r,o),u=t[l++]^dt(s,n,r,o,e),h=t[l++]^dt(s,r,o,e,n),w=t[l++]^dt(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}=dr;let l=0;e^=t[l++],n^=t[l++],r^=t[l++],o^=t[l++];const a=t.length/4-2;for(let g=0;g<a;g++){const d=t[l++]^Ot(i,c,e,o,r,n),p=t[l++]^Ot(i,c,n,e,o,r),b=t[l++]^Ot(i,c,r,n,e,o),m=t[l++]^Ot(i,c,o,r,n,e);e=d,n=p,r=b,o=m}const f=t[l++]^dt(s,e,o,r,n),u=t[l++]^dt(s,n,e,o,r),h=t[l++]^dt(s,r,n,e,o),w=t[l++]^dt(s,o,r,n,e);return{s0:f,s1:u,s2:h,s3:w}}function pr(t,e){if(!e)return new Uint8Array(t);if(Ht(e),e.length<t)throw new Error(`aes: wrong destination length, expected at least ${t}, got: ${e.length}`);return e}function li(t){if(Ht(t),t.length%$t!==0)throw new Error(`aes/(cbc-ecb).decrypt ciphertext should consist of blocks with size ${$t}`)}function ai(t,e,n){let r=t.length;const o=r%$t;if(!e&&o!==0)throw new Error("aec/(cbc-ecb): unpadded plaintext with disabled padding");const s=nt(t);if(e){let l=$t-o;l||(l=$t),r=r+l}const i=pr(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=$t-t.length;for(let o=$t-r;o<$t;o++)e[o]=r;return n}const gr=Js({blockSize:16,nonceLength:16},function(e,n,r={}){Ht(e),Ht(n,16);const o=!r.disablePadding;return{encrypt:(s,i)=>{const c=hr(e),{b:l,o:a,out:f}=ai(s,o,i),u=nt(n);let h=u[0],w=u[1],g=u[2],d=u[3],p=0;for(;p+4<=l.length;)h^=l[p+0],w^=l[p+1],g^=l[p+2],d^=l[p+3],{s0:h,s1:w,s2:g,s3:d}=wr(c,h,w,g,d),a[p++]=h,a[p++]=w,a[p++]=g,a[p++]=d;if(o){const b=fi(s.subarray(p*4));h^=b[0],w^=b[1],g^=b[2],d^=b[3],{s0:h,s1:w,s2:g,s3:d}=wr(c,h,w,g,d),a[p++]=h,a[p++]=w,a[p++]=g,a[p++]=d}return c.fill(0),f},decrypt:(s,i)=>{li(s);const c=ii(e),l=nt(n),a=pr(s.length,i),f=nt(s),u=nt(a);let h=l[0],w=l[1],g=l[2],d=l[3];for(let p=0;p+4<=f.length;){const b=h,m=w,x=g,O=d;h=f[p+0],w=f[p+1],g=f[p+2],d=f[p+3];const{s0:k,s1:_,s2:v,s3:S}=ci(c,h,w,g,d);u[p++]=k^b,u[p++]=_^m,u[p++]=v^x,u[p++]=S^O}return c.fill(0),ui(a,o)}}});/*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) */function Jt(t){if(!Number.isSafeInteger(t))throw new Error(`Wrong integer: ${t}`)}function yt(...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 mt(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(Jt(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 xt(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 Ae(t,e="="){if(Jt(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 br(t){if(typeof t!="function")throw new Error("normalize fn should be function");return{encode:e=>e,decode:e=>t(e)}}function yr(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(Jt(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 mr=(t,e)=>e?mr(e,t%e):t,Be=(t,e)=>t+(e-mr(t,e));function fn(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(Be(e,n)>32)throw new Error(`convertRadix2: carry overflow from=${e} to=${n} carryBits=${Be(e,n)}`);let o=0,s=0;const i=2**n-1,c=[];for(const l of t){if(Jt(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 Jt(t),{encode:e=>{if(!(e instanceof Uint8Array))throw new Error("radix.encode input should be Uint8Array");return yr(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(yr(e,t,2**8))}}}function Tt(t,e=!1){if(Jt(t),t<=0||t>32)throw new Error("radix2: bits should be in (0..32]");if(Be(8,t)>32||Be(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 fn(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(fn(n,t,8,e))}}}function xr(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=yt(Tt(4),mt("0123456789ABCDEF"),xt("")),wi=yt(Tt(5),mt("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"),Ae(5),xt(""));yt(Tt(5),mt("0123456789ABCDEFGHIJKLMNOPQRSTUV"),Ae(5),xt("")),yt(Tt(5),mt("0123456789ABCDEFGHJKMNPQRSTVWXYZ"),xt(""),br(t=>t.toUpperCase().replace(/O/g,"0").replace(/[IL]/g,"1")));const ie=yt(Tt(6),mt("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),Ae(6),xt("")),pi=yt(Tt(6),mt("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"),Ae(6),xt("")),dn=t=>yt(di(58),mt(t),xt("")),hn=dn("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");dn("123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"),dn("rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz");const Er=[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+=hn.encode(r).padStart(Er[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=Er.indexOf(r.length),s=hn.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)}},wn=yt(mt("qpzry9x8gf2tvdw0s3jn54khce6mua7l"),xt("")),vr=[996825010,642813549,513874426,1027748829,705979059];function ce(t){const e=t>>25;let n=(t&33554431)<<5;for(let r=0;r<vr.length;r++)(e>>r&1)===1&&(n^=vr[r]);return n}function _r(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=ce(o)^i>>5}o=ce(o);for(let s=0;s<r;s++)o=ce(o)^t.charCodeAt(s)&31;for(let s of e)o=ce(o)^s;for(let s=0;s<6;s++)o=ce(o);return o^=n,wn.encode(fn([o%2**30],30,5,!1))}function Sr(t){const e=t==="bech32"?1:734539939,n=Tt(5),r=n.decode,o=n.encode,s=xr(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${wn.encode(u)}${_r(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 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=wn.decode(d).slice(0,-6),b=_r(g,p,e);if(!d.endsWith(b))throw new Error(`Invalid checksum in ${f}: expected "${b}"`);return{prefix:g,words:p}}const l=xr(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 kr=Sr("bech32");Sr("bech32m");const bi={encode:t=>new TextDecoder().decode(t),decode:t=>new TextEncoder().encode(t)},yi=yt(Tt(4),mt("0123456789abcdef"),xt(""),br(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:ie,base64url:pi,base58:hn,base58xmr:gi}).join(", ")}`;var qt=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"),Ar=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 vi=class{constructor(t){y(this,"value");y(this,"next",null);y(this,"prev",null);this.value=t}},_i=class{constructor(){y(this,"first");y(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 Q.utils.randomPrivateKey()}getPublicKey(t){return Y(Q.getPublicKey(t))}finalizeEvent(t,e){const n=t;return n.pubkey=Y(Q.getPublicKey(e)),n.id=pn(n),n.sig=Y(Q.sign(pn(n),e)),n[qt]=!0,n}verifyEvent(t){if(typeof t[qt]=="boolean")return t[qt];const e=pn(t);if(e!==t.id)return t[qt]=!1,!1;try{const n=Q.verify(t.sig,e,t.pubkey);return t[qt]=n,n}catch{return t[qt]=!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 pn(t){let e=nn(Ar.encode(ki(t)));return Y(e)}var $e=new Si,Ai=$e.generateSecretKey,Br=$e.getPublicKey,Bi=$e.finalizeEvent,$r=$e.verifyEvent;async function $i(t,e,n){const r=t instanceof Uint8Array?Y(t):t,o=ne.getSharedSecret(r,"02"+e),s=Or(o);let i=Uint8Array.from(Eo(16)),c=Ar.encode(n),l=gr(s,i).encrypt(c),a=ie.encode(new Uint8Array(l)),f=ie.encode(new Uint8Array(i.buffer));return`${a}?iv=${f}`}async function Oi(t,e,n){const r=t instanceof Uint8Array?Y(t):t;let[o,s]=n.split("?iv="),i=ne.getSharedSecret(r,"02"+e),c=Or(i),l=ie.decode(s),a=ie.decode(o),f=gr(c,l).decrypt(a);return Ei.decode(f)}function Or(t){return t.slice(1,33)}var Ti=/^(?:([\w.+-]+)@)?([\w_-]+(\.[\w_-]+)+)$/,Ii;try{Ii=fetch}catch{}var Ni=22242,gn=24133,Ui=31990;function Pi(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(Pi(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 ji=t=>(t[qt]=!0,!0),Tr;try{Tr=WebSocket}catch{}var Ir=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 _i);y(this,"queueRunning",!1);y(this,"challenge");y(this,"serial",0);y(this,"verifyEvent");this.url=le(t),this.verifyEvent=e.verifyEvent}static async connect(t,e){const n=new Ir(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 Tr(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 Ki(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()}},Ki=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)}},Mi=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=le(t);let n=this.relays.get(t);return n||(n=new Ir(t,{verifyEvent:this.trustedRelayURLs.has(t)?ji:this.verifyEvent}),e!=null&&e.connectionTimeout&&(n.connectionTimeout=e.connectionTimeout),this.relays.set(t,n)),await n.connect(),n}close(t){t.map(le).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(g=>g).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(le).map(async(u,h,w)=>{if(w.indexOf(u)!==h){l(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){l(h,(p==null?void 0:p.message)||String(p));return}let d=g.subscribe(e,{...n,oneose:()=>i(h),onclose:p=>l(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(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(le).map(async(n,r,o)=>o.indexOf(n)!==r?Promise.reject("duplicate url"):(await this.ensureRelay(n)).publish(e))}},zi=class extends Mi{constructor(){super({verifyEvent:$r})}},Nr;try{Nr=fetch}catch{}var Ur=/^bunker:\/\/([0-9a-f]{64})\??([?\/\w:.=&%]*)$/,Vi=/^[^\s@]+@[^\s@]+\.[^\s@]+$/;async function Di(t){let e=t.match(Ur);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 Pr(t)}async function Pr(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 Nr(s,{redirect:"error"})).json();let c=i.names[r],l=i.nip46[c]||[];return{pubkey:c,relays:l,secret:null}}catch{return null}}var bn=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 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:[gn],"#p":[Br(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:gn,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",[Br(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&&$r(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 Le(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 bn(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:[Ui],"#k":[gn.toString()]});return(await Promise.all(n.map(async o=>{try{const s=JSON.parse(o.content),i=await Pr(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 Lr=/^(?:([\w.+-]+)@)?([\w_-]+(\.[\w_-]+)+)$/,Cr;try{Cr=fetch}catch{}async function Gi(t){var s;const e=t.match(Lr);if(!e)return null;const[n,r="_",o]=e;try{const i=`https://${o}/.well-known/nostr.json?name=${r}`,c=await(await Cr(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",Le(t))}function Yi(t,e){let n=kr.toWords(e);return kr.encode(t,n,Fi)}function Qi(t,e){return Yi(t,e)}const{window:Xi}=Yr;function Rr(t,e,n){const r=t.slice();return r[41]=e[n],r}function tc(t){let e,n,r,o,s,i,c,l;function a(h,w){if(h[8])return oc;if(!h[9])return rc;if(h[9])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){j(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[7]?cc:i[9]?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){j(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[9].npub+"",l,a,f,u,h,w,g,d,p,b,m,x=or(t[6])+"",O,k,_,v=(t[9].picture||t[9].name)&&Hr(t);return{c(){e=L("div"),n=L("div"),n.textContent="You are connected to Nostr as",r=D(),o=L("a"),v&&v.c(),s=D(),i=L("div"),l=tt(c),f=D(),u=L("button"),h=tt("Disconnect"),g=D(),d=L("div"),p=tt("This webpage is using the public key:"),b=L("br"),m=D(),O=tt(x),$(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[9].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){j(S,e,U),N(e,n),N(e,r),N(e,o),v&&v.m(o,null),N(o,s),N(o,i),N(i,l),j(S,f,U),j(S,u,U),N(u,h),j(S,g,U),j(S,d,U),N(d,p),N(d,b),N(d,m),N(d,O),k||(_=ct(u,"click",t[16]),k=!0)},p(S,U){S[9].picture||S[9].name?v?v.p(S,U):(v=Hr(S),v.c(),v.m(o,s)):v&&(v.d(1),v=null),U[0]&512&&c!==(c=S[9].npub+"")&&de(l,c),U[0]&512&&a!==(a="https://nosta.me/"+S[9].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&&x!==(x=or(S[6])+"")&&de(O,x)},d(S){S&&(q(e),q(f),q(u),q(g),q(d)),v&&v.d(),k=!1,_()}}}function rc(t){let e,n,r,o,s,i,c,l,a,f,u,h,w,g,d,p,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"),g=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(m,x){j(m,e,x),j(m,n,x),j(m,r,x),N(r,o),t[25](o),Mt(o,t[1]),N(r,s),N(r,i),N(i,c),j(m,f,x),j(m,u,x),N(u,h),N(u,w),N(u,g),N(u,d),o.focus(),p||(b=[ct(o,"input",t[26]),ct(r,"submit",t[15]),ct(d,"click",t[17])],p=!0)},p(m,x){x[0]&2&&o.value!==m[1]&&Mt(o,m[1]),x[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-"+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")&&$(i,"class",l),x[0]&4096&&a!==(a=!m[12])&&(i.disabled=a)},d(m){m&&(q(e),q(n),q(r),q(f),q(u)),t[25](null),p=!1,Kt(b)}}}function oc(t){let e,n,r,o,s,i,c,l,a,f,u,h,w,g,d,p,b,m,x,O,k,_,v,S,U=Sn(t[10]),T=[];for(let B=0;B<U.length;B+=1)T[B]=Kr(Rr(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<T.length;B+=1)T[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"),g=tt("Create »"),b=D(),m=L("div"),x=tt("Do you already have a Nostr address?"),O=L("br"),k=D(),_=L("button"),_.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&&we(()=>t[24].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=p=!t[5]||!t[4],$(r,"class","tw-mt-4 tw-mb-1"),$(_,"class","tw-border-0 tw-bg-transparent tw-text-white tw-cursor-pointer tw-underline tw-text-sm"),$(m,"class","tw-mt-6 tw-text-center tw-text-sm tw-leading-3")},m(B,R){j(B,e,R),j(B,n,R),j(B,r,R),N(r,o),N(o,s),t[22](s),Mt(s,t[4]),N(o,i),N(o,c),N(o,l),N(o,a);for(let C=0;C<T.length;C+=1)T[C]&&T[C].m(a,null);xn(a,t[5],!0),N(r,f),N(r,u),N(r,h),N(r,w),N(w,g),j(B,b,R),j(B,m,R),N(m,x),N(m,O),N(m,k),N(m,_),s.focus(),v||(S=[ct(s,"input",t[23]),ct(s,"input",t[20]),ct(a,"change",t[24]),ct(r,"submit",t[19]),ct(_,"click",t[18])],v=!0)},p(B,R){if(R[0]&16&&s.value!==B[4]&&Mt(s,B[4]),R[0]&1024){U=Sn(B[10]);let C;for(C=0;C<U.length;C+=1){const rt=Rr(B,U,C);T[C]?T[C].p(rt,R):(T[C]=Kr(rt),T[C].c(),T[C].m(a,null))}for(;C<T.length;C+=1)T[C].d(1);T.length=U.length}R[0]&1056&&xn(a,B[5]),R[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),R[0]&1072&&p!==(p=!B[5]||!B[4])&&(w.disabled=p)},d(B){B&&(q(e),q(n),q(r),q(b),q(m)),t[22](null),Qr(T,B),v=!1,Kt(S)}}}function Hr(t){let e,n,r=t[9].picture&&qr(t),o=t[9].name&&jr(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){j(s,e,i),r&&r.m(e,null),N(e,n),o&&o.m(e,null)},p(s,i){s[9].picture?r?r.p(s,i):(r=qr(s),r.c(),r.m(e,n)):r&&(r.d(1),r=null),s[9].name?o?o.p(s,i):(o=jr(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 qr(t){let e,n,r;return{c(){e=L("img"),fe(e.src,n=t[9].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){j(o,e,s)},p(o,s){s[0]&512&&!fe(e.src,n=o[9].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 jr(t){let e,n=t[9].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){j(o,e,s),N(e,r)},p(o,s){s[0]&512&&n!==(n=o[9].name+"")&&de(r,n)},d(o){o&&q(e)}}}function Kr(t){let e,n,r;return{c(){e=L("option"),$(e,"label",n=t[41].domain),e.__value=r=t[41],Mt(e,e.__value),$(e,"class","tw-px-2 tw-py-1 tw-text-lg")},m(o,s){j(o,e,s)},p(o,s){s[0]&1024&&n!==(n=o[41].domain)&&$(e,"label",n),s[0]&1024&&r!==(r=o[41])&&(e.__value=r,Mt(e,e.__value))},d(o){o&&q(e)}}}function sc(t){let e,n,r=(t[9].name||t[9].npub.slice(0,7)+"…"+t[9].npub.slice(-4))+"",o;function s(l,a){return l[9].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){j(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]&512&&r!==(r=(l[9].name||l[9].npub.slice(0,7)+"…"+l[9].npub.slice(-4))+"")&&de(o,r)},d(l){l&&q(e),c.d()}}}function ic(t){let e;return{c(){e=tt("Login with Nostr")},m(n,r){j(n,e,r)},p:F,d(n){n&&q(e)}}}function cc(t){let e;return{c(){e=L("div"),e.textContent="Connecting to bunker..."},m(n,r){j(n,e,r)},p:F,d(n){n&&q(e)}}}function lc(t){let e;return{c(){e=tt("☉")},m(n,r){j(n,e,r)},p:F,d(n){n&&q(e)}}}function ac(t){let e,n;return{c(){e=L("img"),fe(e.src,n=t[9].picture)||$(e,"src",n),$(e,"alt",""),$(e,"class","tw-w-5 tw-h-5 tw-rounded-full tw-mr-2")},m(r,o){j(r,e,o)},p(r,o){o[0]&512&&!fe(e.src,n=r[9].picture)&&$(e,"src",n)},d(r){r&&q(e)}}}function uc(t){let e,n,r;function o(c,l){return c[11]?tc:ec}let s=o(t),i=s(t);return{c(){e=L("div"),i.c(),$(e,"class","tw-text-white tw-font-sans"),En(e,"tw-cursor-pointer",!t[9]&&!t[11])},m(c,l){j(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]&2560&&En(e,"tw-cursor-pointer",!c[9]&&!c[11])},i:F,o:F,d(c){c&&q(e),i.d(),n=!1,r()}}}function fc(t,e,n){let r,o,{accent:s}=e;const i=window,c=new Zs;let l,a,f,u,h,w;const g=localStorage.getItem("nip46ClientSecretKey");g?w=Le(g):(w=$s(),localStorage.setItem("nip46ClientSecretKey",Y(w)));let d="closed",p,b,m,x,O,k,_,v=[];const S=An(()=>{switch(d){case"justopened":n(21,d="opened");break;case"justclosed":n(21,d="closed");break}},500);function U(){n(21,d="justopened"),S()}function T(){n(21,d="justclosed"),S()}R();let B={isWnj:!0,async getPublicKey(){return!x&&!k&&U(),(await m).bp.pubkey},async signEvent(I){return!x&&!k&&U(),(await m).signEvent(I)},async getRelays(){return!x&&!k&&U(),(await m).getRelays()},nip04:{async encrypt(I,M){return!x&&!k&&U(),(await m).nip04Encrypt(I,M)},async decrypt(I,M){return!x&&!k&&U(),(await m).nip04Decrypt(I,M)}}};function R(){T(),p=null,m=new Promise(I=>{b=I}),n(7,x=!1),n(8,O=!1),n(9,k=null),_=null}const C={pool:c,onauth(I){window.open(I,"window.nostr","width=600,height=800,popup=yes")}};no(()=>{let I=localStorage.getItem("nip46BunkerPointer");if(I&&(p=JSON.parse(I),n(7,x=!0),G(new bn(w,p,C))),i.nostr&&!i.nostr.isWnj){i.destroyWnj();return}else Object.defineProperty(window,"nostr",{get(){return B},set(M){B=M,M.isWnj||i.destroyWnj()},configurable:!0});return()=>{_&&_.close()}});function rt(I){d==="justopened"||d==="justclosed"||(I.composedPath().find(M=>M.id==="wnj")?U():T())}function E(I){T(),n(8,O=!1),I.stopPropagation()}async function A(I){if(I.preventDefault(),p=await Di(l.value),!p){l.setCustomValidity('invalid NIP-05 "name@domain.com" address or bunker:// URI');return}l.setCustomValidity(""),G(new bn(w,p,C))}async function P(I){I.preventDefault(),localStorage.removeItem("nip46BunkerPointer"),i.isWnj&&delete i.nostr,R()}async function K(I){I.preventDefault(),n(8,O=!0),v.length===0&&(n(10,v=await Zi(c,["wss://relay.nostr.band"])),n(5,h=v[0]))}function H(I){n(8,O=!1)}async function V(I){if(I.preventDefault(),!h)return;let M=await Wi(h,C,f.value,h.domain);U(),n(8,O=!1),G(M)}const X=An(async()=>{h&&f.value.length>0&&(await Gi(f.value+"@"+h.domain)?f.setCustomValidity(`'${f.value}' is already taken.`):f.setCustomValidity(""))},500);async function G(I){await I.connect(),n(9,k={pubkey:I.bp.pubkey,npub:Ji(I.bp.pubkey),event:null}),n(7,x=!1),localStorage.setItem("nip46BunkerPointer",JSON.stringify(p)),_=c.subscribeMany(["wss://purplepag.es","wss://relay.snort.social","wss://relay.nos.social"],[{kinds:[0],authors:[I.bp.pubkey]}],{onevent(M){var Et;if(!((((Et=k.event)==null?void 0:Et.created_at)||0)>=M.created_at))try{let{name:ae,picture:Nt}=JSON.parse(M.content);n(9,k.event=M,k),n(9,k.name=ae,k),n(9,k.picture=Nt,k)}catch{}}}),T(),b(I)}function ht(I){he[I?"unshift":"push"](()=>{f=I,n(3,f)})}function wt(){u=this.value,n(4,u)}function It(){h=to(this),n(5,h),n(10,v)}function jt(I){he[I?"unshift":"push"](()=>{l=I,n(2,l)})}function pt(){a=this.value,n(1,a)}return t.$$set=I=>{"accent"in I&&n(0,s=I.accent)},t.$$.update=()=>{t.$$.dirty[0]&2&&n(12,r=a&&(a.match(Ur)||a.match(Lr))),t.$$.dirty[0]&2097152&&n(11,o=d==="justopened"||d==="opened")},[s,a,l,f,u,h,w,x,O,k,v,o,r,rt,E,A,P,K,H,V,X,d,ht,wt,It,jt,pt]}class dc extends wo{constructor(e){super(),ho(this,e,fc,uc,Fr,{accent:0},null,[-1,-1])}}const Mr=window,Yt=document.createElement("div");Yt.style.position="fixed",Yt.style.right="1.5rem",((Dr=Mr.wnjParams)==null?void 0:Dr.position)==="bottom"?Yt.style.bottom="1.5rem":Yt.style.top="1.5rem",document.body.appendChild(Yt);const Oe=document.createElement("div");Oe.id="wnj",Oe.classList.add("tw-animate-fadein");const zr=document.createElement("style");zr.innerHTML=Ut;const Vr=Yt.attachShadow({mode:"open"});Vr.appendChild(Oe),Vr.appendChild(zr);const hc=new dc({target:Oe,props:{accent:((Wr=Mr.wnjParams)==null?void 0:Wr.accent)||"cyan"}});window.destroyWnj=()=>{hc.$destroy()}})();
|
package/index.html
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "window.nostr.js",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.1.1",
|
|
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.
|
|
26
|
+
"nostr-tools": "^2.3.0"
|
|
27
27
|
}
|
|
28
28
|
}
|
package/src/App.svelte
CHANGED
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
localStorage.setItem('nip46ClientSecretKey', bytesToHex(clientSecret))
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
let
|
|
43
|
+
let state: 'opened' | 'closed' | 'justopened' | 'justclosed' = 'closed'
|
|
44
44
|
let bunkerPointer: BunkerPointer | null
|
|
45
45
|
let resolveBunker: (_: BunkerSigner) => void
|
|
46
46
|
let bunker: Promise<BunkerSigner>
|
|
@@ -55,43 +55,67 @@
|
|
|
55
55
|
}
|
|
56
56
|
let metadataSub: SubCloser | null
|
|
57
57
|
let providers: BunkerProfile[] = []
|
|
58
|
-
reset()
|
|
59
58
|
|
|
60
59
|
$: bunkerInputValueIsGood =
|
|
61
60
|
bunkerInputValue &&
|
|
62
61
|
(bunkerInputValue.match(BUNKER_REGEX) ||
|
|
63
62
|
bunkerInputValue.match(NIP05_REGEX))
|
|
64
63
|
|
|
64
|
+
const delayedUpdateState = debounce(() => {
|
|
65
|
+
switch (state) {
|
|
66
|
+
case 'justopened':
|
|
67
|
+
state = 'opened'
|
|
68
|
+
break
|
|
69
|
+
case 'justclosed':
|
|
70
|
+
state = 'closed'
|
|
71
|
+
break
|
|
72
|
+
}
|
|
73
|
+
}, 500)
|
|
74
|
+
|
|
75
|
+
function open() {
|
|
76
|
+
state = 'justopened'
|
|
77
|
+
delayedUpdateState()
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function close() {
|
|
81
|
+
state = 'justclosed'
|
|
82
|
+
delayedUpdateState()
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
$: opened = state === 'justopened' || state === 'opened'
|
|
86
|
+
|
|
87
|
+
reset()
|
|
88
|
+
|
|
65
89
|
let windowNostr = {
|
|
66
90
|
isWnj: true,
|
|
67
91
|
async getPublicKey(): Promise<string> {
|
|
68
|
-
if (!connecting && !connected)
|
|
92
|
+
if (!connecting && !connected) open()
|
|
69
93
|
return (await bunker).bp.pubkey
|
|
70
94
|
},
|
|
71
95
|
async signEvent(event: NostrEvent): Promise<VerifiedEvent> {
|
|
72
|
-
if (!connecting && !connected)
|
|
96
|
+
if (!connecting && !connected) open()
|
|
73
97
|
return (await bunker).signEvent(event)
|
|
74
98
|
},
|
|
75
99
|
async getRelays(): Promise<{
|
|
76
100
|
[url: string]: {read: boolean; write: boolean}
|
|
77
101
|
}> {
|
|
78
|
-
if (!connecting && !connected)
|
|
102
|
+
if (!connecting && !connected) open()
|
|
79
103
|
return (await bunker).getRelays()
|
|
80
104
|
},
|
|
81
105
|
nip04: {
|
|
82
106
|
async encrypt(pubkey: string, plaintext: string): Promise<string> {
|
|
83
|
-
if (!connecting && !connected)
|
|
107
|
+
if (!connecting && !connected) open()
|
|
84
108
|
return (await bunker).nip04Encrypt(pubkey, plaintext)
|
|
85
109
|
},
|
|
86
110
|
async decrypt(pubkey: string, ciphertext: string): Promise<string> {
|
|
87
|
-
if (!connecting && !connected)
|
|
111
|
+
if (!connecting && !connected) open()
|
|
88
112
|
return (await bunker).nip04Decrypt(pubkey, ciphertext)
|
|
89
113
|
}
|
|
90
114
|
}
|
|
91
115
|
}
|
|
92
116
|
|
|
93
117
|
function reset() {
|
|
94
|
-
|
|
118
|
+
close()
|
|
95
119
|
bunkerPointer = null
|
|
96
120
|
bunker = new Promise(resolve => {
|
|
97
121
|
resolveBunker = resolve
|
|
@@ -149,13 +173,14 @@
|
|
|
149
173
|
})
|
|
150
174
|
|
|
151
175
|
function handleClick(ev: MouseEvent) {
|
|
152
|
-
if (
|
|
153
|
-
|
|
154
|
-
|
|
176
|
+
if (state === 'justopened' || state === 'justclosed') return
|
|
177
|
+
|
|
178
|
+
if (ev.composedPath().find((el: any) => el.id === 'wnj')) open()
|
|
179
|
+
else close()
|
|
155
180
|
}
|
|
156
181
|
|
|
157
182
|
function handleCloseModal(ev: MouseEvent) {
|
|
158
|
-
|
|
183
|
+
close()
|
|
159
184
|
creating = false
|
|
160
185
|
ev.stopPropagation()
|
|
161
186
|
}
|
|
@@ -204,7 +229,8 @@
|
|
|
204
229
|
nameInput.value,
|
|
205
230
|
chosenProvider.domain
|
|
206
231
|
)
|
|
207
|
-
|
|
232
|
+
|
|
233
|
+
open()
|
|
208
234
|
creating = false
|
|
209
235
|
|
|
210
236
|
connect(bunker)
|
|
@@ -256,7 +282,7 @@
|
|
|
256
282
|
}
|
|
257
283
|
)
|
|
258
284
|
|
|
259
|
-
|
|
285
|
+
close()
|
|
260
286
|
resolveBunker(bunker)
|
|
261
287
|
}
|
|
262
288
|
</script>
|
package/src/main.ts
CHANGED
|
@@ -18,12 +18,12 @@ base.style.right = '1.5rem'
|
|
|
18
18
|
if (win.wnjParams?.position === 'bottom') {
|
|
19
19
|
base.style.bottom = '1.5rem'
|
|
20
20
|
} else {
|
|
21
|
-
base.style.top = '1.5rem'
|
|
21
|
+
base.style.top = '1.5rem'
|
|
22
22
|
}
|
|
23
23
|
document.body.appendChild(base)
|
|
24
24
|
|
|
25
25
|
const mountPoint = document.createElement('div')
|
|
26
|
-
mountPoint.id = '
|
|
26
|
+
mountPoint.id = 'wnj'
|
|
27
27
|
mountPoint.classList.add('tw-animate-fadein')
|
|
28
28
|
|
|
29
29
|
const style = document.createElement('style')
|