window.nostr.js 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.html +7 -1
- package/dist/window.nostr.js +2 -3
- package/index.html +6 -0
- package/package.json +1 -1
- package/src/App.svelte +75 -14
- package/src/main.ts +37 -11
- package/tailwind.config.js +17 -1
- package/vite.config.ts +3 -0
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-CF_s7TFx.js"></script>
|
|
8
8
|
</head>
|
|
9
9
|
<body
|
|
10
10
|
style="
|
|
@@ -61,5 +61,11 @@
|
|
|
61
61
|
molestie risus rutrum ut. Proin dictum nunc at rutrum vehicula.
|
|
62
62
|
</p>
|
|
63
63
|
</main>
|
|
64
|
+
<!-- <script>
|
|
65
|
+
window.windowNostrJsParams = {
|
|
66
|
+
position: 'bottom',
|
|
67
|
+
accent: 'green' // Supported values: cyan (default), green, purple, red, orange, neutral, stone
|
|
68
|
+
}
|
|
69
|
+
</script> -->
|
|
64
70
|
</body>
|
|
65
71
|
</html>
|
package/dist/window.nostr.js
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
var gi=Object.defineProperty;var bi=(le,K,ue)=>K in le?gi(le,K,{enumerable:!0,configurable:!0,writable:!0,value:ue}):le[K]=ue;var g=(le,K,ue)=>(bi(le,typeof K!="symbol"?K+"":K,ue),ue);(function(){"use strict";var le=document.createElement("style");le.textContent=`.tw-fixed{position:fixed}.tw-absolute{position:absolute}.tw-right-0{right:0}.tw-right-0\\.5{right:.125rem}.tw-right-6{right:1.5rem}.tw-top-0{top:0}.tw-top-6{top:1.5rem}.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-5{width:1.25rem}.tw-w-80{width:20rem}.tw-w-full{width:100%}.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-900{--tw-bg-opacity: 1;background-color:rgb(22 78 99 / 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-text-xs{font-size:.75rem;line-height:1rem}.tw-leading-3{line-height:.75rem}.tw-text-cyan-950{--tw-text-opacity: 1;color:rgb(8 51 68 / 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}.hover\\:tw-bg-cyan-800:hover{--tw-bg-opacity: 1;background-color:rgb(21 94 117 / var(--tw-bg-opacity))}.hover\\:tw-bg-cyan-950:hover{--tw-bg-opacity: 1;background-color:rgb(8 51 68 / var(--tw-bg-opacity))}.tw-group:hover .group-hover\\:tw-border-cyan-100{--tw-border-opacity: 1;border-color:rgb(207 250 254 / var(--tw-border-opacity))}.tw-group:hover .group-hover\\:tw-underline{text-decoration-line:underline}
|
|
2
|
-
`,document.head.appendChild(le);function K(){}function ue(t){return t()}function Qt(){return Object.create(null)}function $e(t){t.forEach(ue)}function Xt(t){return typeof t=="function"}function hr(t,e){return t!=t?e==e:t!==e||t&&typeof t=="object"||typeof t=="function"}let Je;function Ye(t,e){return t===e?!0:(Je||(Je=document.createElement("a")),Je.href=e,t===Je.href)}function wr(t){return Object.keys(t).length===0}const pr=typeof window<"u"?window:typeof globalThis<"u"?globalThis:global;function R(t,e){t.appendChild(e)}function H(t,e,n){t.insertBefore(e,n||null)}function U(t){t.parentNode&&t.parentNode.removeChild(t)}function yr(t,e){for(let n=0;n<t.length;n+=1)t[n]&&t[n].d(e)}function C(t){return document.createElement(t)}function Ee(t){return document.createTextNode(t)}function Y(){return Ee(" ")}function fe(t,e,n,r){return t.addEventListener(e,n,r),()=>t.removeEventListener(e,n,r)}function k(t,e,n){n==null?t.removeAttribute(e):t.getAttribute(e)!==n&&t.setAttribute(e,n)}function gr(t){return Array.from(t.childNodes)}function wt(t,e){e=""+e,t.data!==e&&(t.data=e)}function en(t,e){t.value=e??""}function tn(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 br(t){const e=t.querySelector(":checked");return e&&e.__value}function nn(t,e,n){t.classList.toggle(e,!!n)}let Me;function Ke(t){Me=t}function mr(){if(!Me)throw new Error("Function called outside component initialization");return Me}function xr(t){mr().$$.on_mount.push(t)}const Oe=[],Qe=[];let Ie=[];const rn=[],Er=Promise.resolve();let pt=!1;function vr(){pt||(pt=!0,Er.then(on))}function Xe(t){Ie.push(t)}const yt=new Set;let Ne=0;function on(){if(Ne!==0)return;const t=Me;do{try{for(;Ne<Oe.length;){const e=Oe[Ne];Ne++,Ke(e),_r(e.$$)}}catch(e){throw Oe.length=0,Ne=0,e}for(Ke(null),Oe.length=0,Ne=0;Qe.length;)Qe.pop()();for(let e=0;e<Ie.length;e+=1){const n=Ie[e];yt.has(n)||(yt.add(n),n())}Ie.length=0}while(Oe.length);for(;rn.length;)rn.pop()();pt=!1,yt.clear(),Ke(t)}function _r(t){if(t.fragment!==null){t.update(),$e(t.before_update);const e=t.dirty;t.dirty=[-1],t.fragment&&t.fragment.p(t.ctx,e),t.after_update.forEach(Xe)}}function Sr(t){const e=[],n=[];Ie.forEach(r=>t.indexOf(r)===-1?e.push(r):n.push(r)),n.forEach(r=>r()),Ie=e}const Ar=new Set;function kr(t,e){t&&t.i&&(Ar.delete(t),t.i(e))}function sn(t){return(t==null?void 0:t.length)!==void 0?t:Array.from(t)}function Br(t,e,n){const{fragment:r,after_update:o}=t.$$;r&&r.m(e,n),Xe(()=>{const s=t.$$.on_mount.map(ue).filter(Xt);t.$$.on_destroy?t.$$.on_destroy.push(...s):$e(s),t.$$.on_mount=[]}),o.forEach(Xe)}function $r(t,e){const n=t.$$;n.fragment!==null&&(Sr(n.after_update),$e(n.on_destroy),n.fragment&&n.fragment.d(e),n.on_destroy=n.fragment=null,n.ctx=[])}function Or(t,e){t.$$.dirty[0]===-1&&(Oe.push(t),vr(),t.$$.dirty.fill(0)),t.$$.dirty[e/31|0]|=1<<e%31}function Ir(t,e,n,r,o,s,i=null,c=[-1]){const a=Me;Ke(t);const l=t.$$={fragment:null,ctx:[],props:s,update:K,not_equal:o,bound:Qt(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(e.context||(a?a.$$.context:[])),callbacks:Qt(),dirty:c,skip_bound:!1,root:e.target||a.$$.root};i&&i(l.root);let f=!1;if(l.ctx=n?n(t,e.props||{},(u,y,...p)=>{const w=p.length?p[0]:y;return l.ctx&&o(l.ctx[u],l.ctx[u]=w)&&(!l.skip_bound&&l.bound[u]&&l.bound[u](w),f&&Or(t,u)),y}):[],l.update(),f=!0,$e(l.before_update),l.fragment=r?r(l.ctx):!1,e.target){if(e.hydrate){const u=gr(e.target);l.fragment&&l.fragment.l(u),u.forEach(U)}else l.fragment&&l.fragment.c();e.intro&&kr(t.$$.fragment),Br(t,e.target,e.anchor),on()}Ke(a)}class Nr{constructor(){g(this,"$$");g(this,"$$set")}$destroy(){$r(this,1),this.$destroy=K}$on(e,n){if(!Xt(n))return K;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&&!wr(e)&&(this.$$.skip_bound=!0,this.$$set(e),this.$$.skip_bound=!1)}}const Tr="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(Tr);function Cr(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var gt={exports:{}};function cn(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,a;function l(){const u=Date.now()-c;if(u<e&&u>=0)i=setTimeout(l,e-u);else if(i=void 0,!r){const y=o,p=s;o=void 0,s=void 0,a=t.apply(y,p)}}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 y=r&&!i;if(i||(i=setTimeout(l,e)),y){const p=o,w=s;o=void 0,s=void 0,a=t.apply(p,w)}return a};return f.clear=()=>{i&&(clearTimeout(i),i=void 0)},f.flush=()=>{if(!i)return;const u=o,y=s;o=void 0,s=void 0,a=t.apply(u,y),clearTimeout(i),i=void 0},f}gt.exports.debounce=cn,gt.exports=cn;var Pr=gt.exports;const Rr=Cr(Pr),bt=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */const an=t=>t instanceof Uint8Array,mt=t=>new DataView(t.buffer,t.byteOffset,t.byteLength),ne=(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 Ur=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function D(t){if(!an(t))throw new Error("Uint8Array expected");let e="";for(let n=0;n<t.length;n++)e+=Ur[t[n]];return e}function xt(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);const e=t.length;if(e%2)throw new Error("padded hex string expected, got unpadded hex of length "+e);const n=new Uint8Array(e/2);for(let r=0;r<n.length;r++){const o=r*2,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 Hr(t){if(typeof t!="string")throw new Error(`utf8ToBytes expected string, got ${typeof t}`);return new Uint8Array(new TextEncoder().encode(t))}function ln(t){if(typeof t=="string"&&(t=Hr(t)),!an(t))throw new Error(`expected Uint8Array, got ${typeof t}`);return t}let Lr=class{clone(){return this._cloneInto()}};function un(t){const e=r=>t().update(ln(r)).digest(),n=t();return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=()=>t(),e}function qr(t=32){if(bt&&typeof bt.getRandomValues=="function")return bt.getRandomValues(new Uint8Array(t));throw new Error("crypto.getRandomValues must be defined")}function fn(t){if(!Number.isSafeInteger(t)||t<0)throw new Error(`Wrong positive integer: ${t}`)}function dn(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 Mr(t){if(typeof t!="function"||typeof t.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");fn(t.outputLen),fn(t.blockLen)}function et(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 Kr(t,e){dn(t);const n=e.outputLen;if(t.length<n)throw new Error(`digestInto() expects output buffer of length at least ${n}`)}const Et=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */const hn=t=>t instanceof Uint8Array,vt=t=>new DataView(t.buffer,t.byteOffset,t.byteLength),re=(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 jr(t){if(typeof t!="string")throw new Error(`utf8ToBytes expected string, got ${typeof t}`);return new Uint8Array(new TextEncoder().encode(t))}function _t(t){if(typeof t=="string"&&(t=jr(t)),!hn(t))throw new Error(`expected Uint8Array, got ${typeof t}`);return t}function zr(...t){const e=new Uint8Array(t.reduce((r,o)=>r+o.length,0));let n=0;return t.forEach(r=>{if(!hn(r))throw new Error("Uint8Array expected");e.set(r,n),n+=r.length}),e}class wn{clone(){return this._cloneInto()}}function Vr(t){const e=r=>t().update(_t(r)).digest(),n=t();return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=()=>t(),e}function pn(t=32){if(Et&&typeof Et.getRandomValues=="function")return Et.getRandomValues(new Uint8Array(t));throw new Error("crypto.getRandomValues must be defined")}function Dr(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),a=r?4:0,l=r?0:4;t.setUint32(e+a,i,r),t.setUint32(e+l,c,r)}let Wr=class extends wn{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=vt(this.buffer)}update(e){et(this);const{view:n,buffer:r,blockLen:o}=this;e=_t(e);const s=e.length;for(let i=0;i<s;){const c=Math.min(o-this.pos,s-i);if(c===o){const a=vt(e);for(;o<=s-i;i+=o)this.process(a,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){et(this),Kr(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;Dr(r,o-8,BigInt(this.length*8),s),this.process(r,0);const c=vt(e),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const l=a/4,f=this.get();if(l>f.length)throw new Error("_sha2: outputLen bigger than state");for(let u=0;u<l;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 Fr=(t,e,n)=>t&e^~t&n,Gr=(t,e,n)=>t&e^t&n^e&n,Zr=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]),de=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),he=new Uint32Array(64);let Jr=class extends Wr{constructor(){super(64,32,8,!1),this.A=de[0]|0,this.B=de[1]|0,this.C=de[2]|0,this.D=de[3]|0,this.E=de[4]|0,this.F=de[5]|0,this.G=de[6]|0,this.H=de[7]|0}get(){const{A:e,B:n,C:r,D:o,E:s,F:i,G:c,H:a}=this;return[e,n,r,o,s,i,c,a]}set(e,n,r,o,s,i,c,a){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=a|0}process(e,n){for(let u=0;u<16;u++,n+=4)he[u]=e.getUint32(n,!1);for(let u=16;u<64;u++){const y=he[u-15],p=he[u-2],w=re(y,7)^re(y,18)^y>>>3,d=re(p,17)^re(p,19)^p>>>10;he[u]=d+he[u-7]+w+he[u-16]|0}let{A:r,B:o,C:s,D:i,E:c,F:a,G:l,H:f}=this;for(let u=0;u<64;u++){const y=re(c,6)^re(c,11)^re(c,25),p=f+y+Fr(c,a,l)+Zr[u]+he[u]|0,d=(re(r,2)^re(r,13)^re(r,22))+Gr(r,o,s)|0;f=l,l=a,a=c,c=i+p|0,i=s,s=o,o=r,r=p+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,l=l+this.G|0,f=f+this.H|0,this.set(r,o,s,i,c,a,l,f)}roundClean(){he.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};const St=Vr(()=>new Jr);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const yn=BigInt(0),tt=BigInt(1),Yr=BigInt(2),nt=t=>t instanceof Uint8Array,Qr=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function Te(t){if(!nt(t))throw new Error("Uint8Array expected");let e="";for(let n=0;n<t.length;n++)e+=Qr[t[n]];return e}function gn(t){const e=t.toString(16);return e.length&1?`0${e}`:e}function At(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);return BigInt(t===""?"0":`0x${t}`)}function Ce(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 Z(t){return At(Te(t))}function kt(t){if(!nt(t))throw new Error("Uint8Array expected");return At(Te(Uint8Array.from(t).reverse()))}function we(t,e){return Ce(t.toString(16).padStart(e*2,"0"))}function Bt(t,e){return we(t,e).reverse()}function Xr(t){return Ce(gn(t))}function V(t,e,n){let r;if(typeof e=="string")try{r=Ce(e)}catch(s){throw new Error(`${t} must be valid hex string, got "${e}". Cause: ${s}`)}else if(nt(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 ve(...t){const e=new Uint8Array(t.reduce((r,o)=>r+o.length,0));let n=0;return t.forEach(r=>{if(!nt(r))throw new Error("Uint8Array expected");e.set(r,n),n+=r.length}),e}function eo(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 to(t){if(typeof t!="string")throw new Error(`utf8ToBytes expected string, got ${typeof t}`);return new Uint8Array(new TextEncoder().encode(t))}function no(t){let e;for(e=0;t>yn;t>>=tt,e+=1);return e}function ro(t,e){return t>>BigInt(e)&tt}const oo=(t,e,n)=>t|(n?tt:yn)<<BigInt(e),$t=t=>(Yr<<BigInt(t-1))-tt,Ot=t=>new Uint8Array(t),bn=t=>Uint8Array.from(t);function mn(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=Ot(t),o=Ot(t),s=0;const i=()=>{r.fill(1),o.fill(0),s=0},c=(...u)=>n(o,r,...u),a=(u=Ot())=>{o=c(bn([0]),u),r=c(),u.length!==0&&(o=c(bn([1]),u),r=c())},l=()=>{if(s++>=1e3)throw new Error("drbg: tried 1000 values");let u=0;const y=[];for(;u<e;){r=c();const p=r.slice();y.push(p),u+=r.length}return ve(...y)};return(u,y)=>{i(),a(u);let p;for(;!(p=y(l()));)a();return i(),p}}const so={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 je(t,e,n={}){const r=(o,s,i)=>{const c=so[s];if(typeof c!="function")throw new Error(`Invalid validator "${s}", expected function`);const a=t[o];if(!(i&&a===void 0)&&!c(a,t))throw new Error(`Invalid param ${String(o)}=${a} (${typeof a}), 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 io=Object.freeze(Object.defineProperty({__proto__:null,bitGet:ro,bitLen:no,bitMask:$t,bitSet:oo,bytesToHex:Te,bytesToNumberBE:Z,bytesToNumberLE:kt,concatBytes:ve,createHmacDrbg:mn,ensureBytes:V,equalBytes:eo,hexToBytes:Ce,hexToNumber:At,numberToBytesBE:we,numberToBytesLE:Bt,numberToHexUnpadded:gn,numberToVarBytesBE:Xr,utf8ToBytes:to,validateObject:je},Symbol.toStringTag,{value:"Module"}));/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const M=BigInt(0),L=BigInt(1),_e=BigInt(2),co=BigInt(3),It=BigInt(4),xn=BigInt(5),En=BigInt(8);BigInt(9),BigInt(16);function j(t,e){const n=t%e;return n>=M?n:e+n}function ao(t,e,n){if(n<=M||e<M)throw new Error("Expected power/modulo > 0");if(n===L)return M;let r=L;for(;e>M;)e&L&&(r=r*t%n),t=t*t%n,e>>=L;return r}function X(t,e,n){let r=t;for(;e-- >M;)r*=r,r%=n;return r}function Nt(t,e){if(t===M||e<=M)throw new Error(`invert: expected positive integers, got n=${t} mod=${e}`);let n=j(t,e),r=e,o=M,s=L;for(;n!==M;){const c=r/n,a=r%n,l=o-s*c;r=n,n=a,o=s,s=l}if(r!==L)throw new Error("invert: does not exist");return j(o,e)}function lo(t){const e=(t-L)/_e;let n,r,o;for(n=t-L,r=0;n%_e===M;n/=_e,r++);for(o=_e;o<t&&ao(o,e,t)!==t-L;o++);if(r===1){const i=(t+L)/It;return function(a,l){const f=a.pow(l,i);if(!a.eql(a.sqr(f),l))throw new Error("Cannot find square root");return f}}const s=(n+L)/_e;return function(c,a){if(c.pow(a,e)===c.neg(c.ONE))throw new Error("Cannot find square root");let l=r,f=c.pow(c.mul(c.ONE,o),n),u=c.pow(a,s),y=c.pow(a,n);for(;!c.eql(y,c.ONE);){if(c.eql(y,c.ZERO))return c.ZERO;let p=1;for(let d=c.sqr(y);p<l&&!c.eql(d,c.ONE);p++)d=c.sqr(d);const w=c.pow(f,L<<BigInt(l-p-1));f=c.sqr(w),u=c.mul(u,w),y=c.mul(y,f),l=p}return u}}function uo(t){if(t%It===co){const e=(t+L)/It;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%En===xn){const e=(t-xn)/En;return function(r,o){const s=r.mul(o,_e),i=r.pow(s,e),c=r.mul(o,i),a=r.mul(r.mul(c,_e),i),l=r.mul(c,r.sub(a,r.ONE));if(!r.eql(r.sqr(l),o))throw new Error("Cannot find square root");return l}}return lo(t)}const fo=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function ho(t){const e={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},n=fo.reduce((r,o)=>(r[o]="function",r),e);return je(t,n)}function wo(t,e,n){if(n<M)throw new Error("Expected power > 0");if(n===M)return t.ONE;if(n===L)return e;let r=t.ONE,o=e;for(;n>M;)n&L&&(r=t.mul(r,o)),o=t.sqr(o),n>>=L;return r}function po(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 vn(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<=M)throw new Error(`Expected Field ORDER > 0, got ${t}`);const{nBitLength:o,nByteLength:s}=vn(t,e);if(s>2048)throw new Error("Field lengths over 2048 bytes are not supported");const i=uo(t),c=Object.freeze({ORDER:t,BITS:o,BYTES:s,MASK:$t(o),ZERO:M,ONE:L,create:a=>j(a,t),isValid:a=>{if(typeof a!="bigint")throw new Error(`Invalid field element: expected bigint, got ${typeof a}`);return M<=a&&a<t},is0:a=>a===M,isOdd:a=>(a&L)===L,neg:a=>j(-a,t),eql:(a,l)=>a===l,sqr:a=>j(a*a,t),add:(a,l)=>j(a+l,t),sub:(a,l)=>j(a-l,t),mul:(a,l)=>j(a*l,t),pow:(a,l)=>wo(c,a,l),div:(a,l)=>j(a*Nt(l,t),t),sqrN:a=>a*a,addN:(a,l)=>a+l,subN:(a,l)=>a-l,mulN:(a,l)=>a*l,inv:a=>Nt(a,t),sqrt:r.sqrt||(a=>i(c,a)),invertBatch:a=>po(c,a),cmov:(a,l,f)=>f?l:a,toBytes:a=>n?Bt(a,s):we(a,s),fromBytes:a=>{if(a.length!==s)throw new Error(`Fp.fromBytes: expected ${s}, got ${a.length}`);return n?kt(a):Z(a)}});return Object.freeze(c)}function _n(t){if(typeof t!="bigint")throw new Error("field order must be bigint");const e=t.toString(2).length;return Math.ceil(e/8)}function Sn(t){const e=_n(t);return e+Math.ceil(e/2)}function go(t,e,n=!1){const r=t.length,o=_n(e),s=Sn(e);if(r<16||r<s||r>1024)throw new Error(`expected ${s}-1024 bytes of input, got ${r}`);const i=n?Z(t):kt(t),c=j(i,e-L)+L;return n?Bt(c,o):we(c,o)}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const bo=BigInt(0),Tt=BigInt(1);function mo(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>bo;)s&Tt&&(i=i.add(c)),c=c.double(),s>>=Tt;return i},precomputeWindow(o,s){const{windows:i,windowSize:c}=r(s),a=[];let l=o,f=l;for(let u=0;u<i;u++){f=l,a.push(f);for(let y=1;y<c;y++)f=f.add(l),a.push(f);l=f.double()}return a},wNAF(o,s,i){const{windows:c,windowSize:a}=r(o);let l=t.ZERO,f=t.BASE;const u=BigInt(2**o-1),y=2**o,p=BigInt(o);for(let w=0;w<c;w++){const d=w*a;let h=Number(i&u);i>>=p,h>a&&(h-=y,i+=Tt);const b=d,E=d+Math.abs(h)-1,S=w%2!==0,I=h<0;h===0?f=f.add(n(S,s[b])):l=l.add(n(I,s[E]))}return{p:l,f}},wNAFCached(o,s,i,c){const a=o._WINDOW_SIZE||1;let l=s.get(o);return l||(l=this.precomputeWindow(o,a),a!==1&&s.set(o,c(l))),this.wNAF(a,l,i)}}}function An(t){return ho(t.Fp),je(t,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...vn(t.n,t.nBitLength),...t,p:t.Fp.ORDER})}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function xo(t){const e=An(t);je(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:Eo,hexToBytes:vo}=io,Se={Err:class extends Error{constructor(e=""){super(e)}},_parseInt(t){const{Err:e}=Se;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:Eo(r),l:t.subarray(n+2)}},toSig(t){const{Err:e}=Se,n=typeof t=="string"?vo(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}=Se._parseInt(n.subarray(2)),{d:i,l:c}=Se._parseInt(s);if(c.length)throw new e("Invalid signature: left bytes after parsing");return{r:o,s:i}},hexFromSig(t){const e=l=>Number.parseInt(l[0],16)&8?"00"+l:l,n=l=>{const f=l.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),a=n(i);return`30${n(i+s+4)}02${a}${o}02${c}${r}`}},se=BigInt(0),ee=BigInt(1);BigInt(2);const kn=BigInt(3);BigInt(4);function _o(t){const e=xo(t),{Fp:n}=e,r=e.toBytes||((w,d,h)=>{const b=d.toAffine();return ve(Uint8Array.from([4]),n.toBytes(b.x),n.toBytes(b.y))}),o=e.fromBytes||(w=>{const d=w.subarray(1),h=n.fromBytes(d.subarray(0,n.BYTES)),b=n.fromBytes(d.subarray(n.BYTES,2*n.BYTES));return{x:h,y:b}});function s(w){const{a:d,b:h}=e,b=n.sqr(w),E=n.mul(b,w);return n.add(n.add(E,n.mul(w,d)),h)}if(!n.eql(n.sqr(e.Gy),s(e.Gx)))throw new Error("bad generator point: equation left != right");function i(w){return typeof w=="bigint"&&se<w&&w<e.n}function c(w){if(!i(w))throw new Error("Expected valid bigint: 0 < bigint < curve.n")}function a(w){const{allowedPrivateKeyLengths:d,nByteLength:h,wrapPrivateKey:b,n:E}=e;if(d&&typeof w!="bigint"){if(w instanceof Uint8Array&&(w=Te(w)),typeof w!="string"||!d.includes(w.length))throw new Error("Invalid key");w=w.padStart(h*2,"0")}let S;try{S=typeof w=="bigint"?w:Z(V("private key",w,h))}catch{throw new Error(`private key must be ${h} bytes, hex or bigint, not ${typeof w}`)}return b&&(S=j(S,E)),c(S),S}const l=new Map;function f(w){if(!(w instanceof u))throw new Error("ProjectivePoint expected")}class u{constructor(d,h,b){if(this.px=d,this.py=h,this.pz=b,d==null||!n.isValid(d))throw new Error("x required");if(h==null||!n.isValid(h))throw new Error("y required");if(b==null||!n.isValid(b))throw new Error("z required")}static fromAffine(d){const{x:h,y:b}=d||{};if(!d||!n.isValid(h)||!n.isValid(b))throw new Error("invalid affine point");if(d instanceof u)throw new Error("projective point not allowed");const E=S=>n.eql(S,n.ZERO);return E(h)&&E(b)?u.ZERO:new u(h,b,n.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(d){const h=n.invertBatch(d.map(b=>b.pz));return d.map((b,E)=>b.toAffine(h[E])).map(u.fromAffine)}static fromHex(d){const h=u.fromAffine(o(V("pointHex",d)));return h.assertValidity(),h}static fromPrivateKey(d){return u.BASE.multiply(a(d))}_setWindowSize(d){this._WINDOW_SIZE=d,l.delete(this)}assertValidity(){if(this.is0()){if(e.allowInfinityPoint&&!n.is0(this.py))return;throw new Error("bad point: ZERO")}const{x:d,y:h}=this.toAffine();if(!n.isValid(d)||!n.isValid(h))throw new Error("bad point: x or y not FE");const b=n.sqr(h),E=s(d);if(!n.eql(b,E))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:h,py:b,pz:E}=this,{px:S,py:I,pz:$}=d,_=n.eql(n.mul(h,$),n.mul(S,E)),A=n.eql(n.mul(b,$),n.mul(I,E));return _&&A}negate(){return new u(this.px,n.neg(this.py),this.pz)}double(){const{a:d,b:h}=e,b=n.mul(h,kn),{px:E,py:S,pz:I}=this;let $=n.ZERO,_=n.ZERO,A=n.ZERO,O=n.mul(E,E),J=n.mul(S,S),P=n.mul(I,I),N=n.mul(E,S);return N=n.add(N,N),A=n.mul(E,I),A=n.add(A,A),$=n.mul(d,A),_=n.mul(b,P),_=n.add($,_),$=n.sub(J,_),_=n.add(J,_),_=n.mul($,_),$=n.mul(N,$),A=n.mul(b,A),P=n.mul(d,P),N=n.sub(O,P),N=n.mul(d,N),N=n.add(N,A),A=n.add(O,O),O=n.add(A,O),O=n.add(O,P),O=n.mul(O,N),_=n.add(_,O),P=n.mul(S,I),P=n.add(P,P),O=n.mul(P,N),$=n.sub($,O),A=n.mul(P,J),A=n.add(A,A),A=n.add(A,A),new u($,_,A)}add(d){f(d);const{px:h,py:b,pz:E}=this,{px:S,py:I,pz:$}=d;let _=n.ZERO,A=n.ZERO,O=n.ZERO;const J=e.a,P=n.mul(e.b,kn);let N=n.mul(h,S),F=n.mul(b,I),z=n.mul(E,$),oe=n.add(h,b),m=n.add(S,I);oe=n.mul(oe,m),m=n.add(N,F),oe=n.sub(oe,m),m=n.add(h,E);let v=n.add(S,$);return m=n.mul(m,v),v=n.add(N,z),m=n.sub(m,v),v=n.add(b,E),_=n.add(I,$),v=n.mul(v,_),_=n.add(F,z),v=n.sub(v,_),O=n.mul(J,m),_=n.mul(P,z),O=n.add(_,O),_=n.sub(F,O),O=n.add(F,O),A=n.mul(_,O),F=n.add(N,N),F=n.add(F,N),z=n.mul(J,z),m=n.mul(P,m),F=n.add(F,z),z=n.sub(N,z),z=n.mul(J,z),m=n.add(m,z),N=n.mul(F,m),A=n.add(A,N),N=n.mul(v,m),_=n.mul(oe,_),_=n.sub(_,N),N=n.mul(oe,F),O=n.mul(v,O),O=n.add(O,N),new u(_,A,O)}subtract(d){return this.add(d.negate())}is0(){return this.equals(u.ZERO)}wNAF(d){return p.wNAFCached(this,l,d,h=>{const b=n.invertBatch(h.map(E=>E.pz));return h.map((E,S)=>E.toAffine(b[S])).map(u.fromAffine)})}multiplyUnsafe(d){const h=u.ZERO;if(d===se)return h;if(c(d),d===ee)return this;const{endo:b}=e;if(!b)return p.unsafeLadder(this,d);let{k1neg:E,k1:S,k2neg:I,k2:$}=b.splitScalar(d),_=h,A=h,O=this;for(;S>se||$>se;)S&ee&&(_=_.add(O)),$&ee&&(A=A.add(O)),O=O.double(),S>>=ee,$>>=ee;return E&&(_=_.negate()),I&&(A=A.negate()),A=new u(n.mul(A.px,b.beta),A.py,A.pz),_.add(A)}multiply(d){c(d);let h=d,b,E;const{endo:S}=e;if(S){const{k1neg:I,k1:$,k2neg:_,k2:A}=S.splitScalar(h);let{p:O,f:J}=this.wNAF($),{p:P,f:N}=this.wNAF(A);O=p.constTimeNegate(I,O),P=p.constTimeNegate(_,P),P=new u(n.mul(P.px,S.beta),P.py,P.pz),b=O.add(P),E=J.add(N)}else{const{p:I,f:$}=this.wNAF(h);b=I,E=$}return u.normalizeZ([b,E])[0]}multiplyAndAddUnsafe(d,h,b){const E=u.BASE,S=($,_)=>_===se||_===ee||!$.equals(E)?$.multiplyUnsafe(_):$.multiply(_),I=S(this,h).add(S(d,b));return I.is0()?void 0:I}toAffine(d){const{px:h,py:b,pz:E}=this,S=this.is0();d==null&&(d=S?n.ONE:n.inv(E));const I=n.mul(h,d),$=n.mul(b,d),_=n.mul(E,d);if(S)return{x:n.ZERO,y:n.ZERO};if(!n.eql(_,n.ONE))throw new Error("invZ was invalid");return{x:I,y:$}}isTorsionFree(){const{h:d,isTorsionFree:h}=e;if(d===ee)return!0;if(h)return h(u,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){const{h:d,clearCofactor:h}=e;return d===ee?this:h?h(u,this):this.multiplyUnsafe(e.h)}toRawBytes(d=!0){return this.assertValidity(),r(u,this,d)}toHex(d=!0){return Te(this.toRawBytes(d))}}u.BASE=new u(e.Gx,e.Gy,n.ONE),u.ZERO=new u(n.ZERO,n.ONE,n.ZERO);const y=e.nBitLength,p=mo(u,e.endo?Math.ceil(y/2):y);return{CURVE:e,ProjectivePoint:u,normPrivateKeyToScalar:a,weierstrassEquation:s,isWithinCurveOrder:i}}function So(t){const e=An(t);return je(e,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...e})}function Ao(t){const e=So(t),{Fp:n,n:r}=e,o=n.BYTES+1,s=2*n.BYTES+1;function i(m){return se<m&&m<n.ORDER}function c(m){return j(m,r)}function a(m){return Nt(m,r)}const{ProjectivePoint:l,normPrivateKeyToScalar:f,weierstrassEquation:u,isWithinCurveOrder:y}=_o({...e,toBytes(m,v,x){const B=v.toAffine(),T=n.toBytes(B.x),q=ve;return x?q(Uint8Array.from([v.hasEvenY()?2:3]),T):q(Uint8Array.from([4]),T,n.toBytes(B.y))},fromBytes(m){const v=m.length,x=m[0],B=m.subarray(1);if(v===o&&(x===2||x===3)){const T=Z(B);if(!i(T))throw new Error("Point is not on curve");const q=u(T);let G=n.sqrt(q);const Q=(G&ee)===ee;return(x&1)===1!==Q&&(G=n.neg(G)),{x:T,y:G}}else if(v===s&&x===4){const T=n.fromBytes(B.subarray(0,n.BYTES)),q=n.fromBytes(B.subarray(n.BYTES,2*n.BYTES));return{x:T,y:q}}else throw new Error(`Point of length ${v} was invalid. Expected ${o} compressed bytes or ${s} uncompressed bytes`)}}),p=m=>Te(we(m,e.nByteLength));function w(m){const v=r>>ee;return m>v}function d(m){return w(m)?c(-m):m}const h=(m,v,x)=>Z(m.slice(v,x));class b{constructor(v,x,B){this.r=v,this.s=x,this.recovery=B,this.assertValidity()}static fromCompact(v){const x=e.nByteLength;return v=V("compactSignature",v,x*2),new b(h(v,0,x),h(v,x,2*x))}static fromDER(v){const{r:x,s:B}=Se.toSig(V("DER",v));return new b(x,B)}assertValidity(){if(!y(this.r))throw new Error("r must be 0 < r < CURVE.n");if(!y(this.s))throw new Error("s must be 0 < s < CURVE.n")}addRecoveryBit(v){return new b(this.r,this.s,v)}recoverPublicKey(v){const{r:x,s:B,recovery:T}=this,q=A(V("msgHash",v));if(T==null||![0,1,2,3].includes(T))throw new Error("recovery id invalid");const G=T===2||T===3?x+e.n:x;if(G>=n.ORDER)throw new Error("recovery id 2 or 3 invalid");const Q=T&1?"03":"02",be=l.fromHex(Q+p(G)),me=a(G),Ue=c(-q*me),Ze=c(B*me),xe=l.BASE.multiplyAndAddUnsafe(be,Ue,Ze);if(!xe)throw new Error("point at infinify");return xe.assertValidity(),xe}hasHighS(){return w(this.s)}normalizeS(){return this.hasHighS()?new b(this.r,c(-this.s),this.recovery):this}toDERRawBytes(){return Ce(this.toDERHex())}toDERHex(){return Se.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return Ce(this.toCompactHex())}toCompactHex(){return p(this.r)+p(this.s)}}const E={isValidPrivateKey(m){try{return f(m),!0}catch{return!1}},normPrivateKeyToScalar:f,randomPrivateKey:()=>{const m=Sn(e.n);return go(e.randomBytes(m),e.n)},precompute(m=8,v=l.BASE){return v._setWindowSize(m),v.multiply(BigInt(3)),v}};function S(m,v=!0){return l.fromPrivateKey(m).toRawBytes(v)}function I(m){const v=m instanceof Uint8Array,x=typeof m=="string",B=(v||x)&&m.length;return v?B===o||B===s:x?B===2*o||B===2*s:m instanceof l}function $(m,v,x=!0){if(I(m))throw new Error("first arg must be private key");if(!I(v))throw new Error("second arg must be public key");return l.fromHex(v).multiply(f(m)).toRawBytes(x)}const _=e.bits2int||function(m){const v=Z(m),x=m.length*8-e.nBitLength;return x>0?v>>BigInt(x):v},A=e.bits2int_modN||function(m){return c(_(m))},O=$t(e.nBitLength);function J(m){if(typeof m!="bigint")throw new Error("bigint expected");if(!(se<=m&&m<O))throw new Error(`bigint expected < 2^${e.nBitLength}`);return we(m,e.nByteLength)}function P(m,v,x=N){if(["recovered","canonical"].some(Be=>Be in x))throw new Error("sign() legacy options not supported");const{hash:B,randomBytes:T}=e;let{lowS:q,prehash:G,extraEntropy:Q}=x;q==null&&(q=!0),m=V("msgHash",m),G&&(m=V("prehashed msgHash",B(m)));const be=A(m),me=f(v),Ue=[J(me),J(be)];if(Q!=null){const Be=Q===!0?T(n.BYTES):Q;Ue.push(V("extraEntropy",Be))}const Ze=ve(...Ue),xe=be;function Yt(Be){const He=_(Be);if(!y(He))return;const ur=a(He),Le=l.BASE.multiply(He).toAffine(),te=c(Le.x);if(te===se)return;const qe=c(ur*c(xe+te*me));if(qe===se)return;let fr=(Le.x===te?0:2)|Number(Le.y&ee),dr=qe;return q&&w(qe)&&(dr=d(qe),fr^=1),new b(te,dr,fr)}return{seed:Ze,k2sig:Yt}}const N={lowS:e.lowS,prehash:!1},F={lowS:e.lowS,prehash:!1};function z(m,v,x=N){const{seed:B,k2sig:T}=P(m,v,x),q=e;return mn(q.hash.outputLen,q.nByteLength,q.hmac)(B,T)}l.BASE._setWindowSize(8);function oe(m,v,x,B=F){var Le;const T=m;if(v=V("msgHash",v),x=V("publicKey",x),"strict"in B)throw new Error("options.strict was renamed to lowS");const{lowS:q,prehash:G}=B;let Q,be;try{if(typeof T=="string"||T instanceof Uint8Array)try{Q=b.fromDER(T)}catch(te){if(!(te instanceof Se.Err))throw te;Q=b.fromCompact(T)}else if(typeof T=="object"&&typeof T.r=="bigint"&&typeof T.s=="bigint"){const{r:te,s:qe}=T;Q=new b(te,qe)}else throw new Error("PARSE");be=l.fromHex(x)}catch(te){if(te.message==="PARSE")throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(q&&Q.hasHighS())return!1;G&&(v=e.hash(v));const{r:me,s:Ue}=Q,Ze=A(v),xe=a(Ue),Yt=c(Ze*xe),Be=c(me*xe),He=(Le=l.BASE.multiplyAndAddUnsafe(be,Yt,Be))==null?void 0:Le.toAffine();return He?c(He.x)===me:!1}return{CURVE:e,getPublicKey:S,getSharedSecret:$,sign:z,verify:oe,ProjectivePoint:l,Signature:b,utils:E}}class Bn extends wn{constructor(e,n){super(),this.finished=!1,this.destroyed=!1,Mr(e);const r=_t(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 et(this),this.iHash.update(e),this}digestInto(e){et(this),dn(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 $n=(t,e,n)=>new Bn(t,e).update(n).digest();$n.create=(t,e)=>new Bn(t,e);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function ko(t){return{hash:t,hmac:(e,...n)=>$n(t,e,zr(...n)),randomBytes:pn}}function Bo(t,e){const n=r=>Ao({...t,...ko(r)});return Object.freeze({...n(e),create:n})}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const rt=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),ot=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),On=BigInt(1),st=BigInt(2),In=(t,e)=>(t+e/st)/e;function Nn(t){const e=rt,n=BigInt(3),r=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),c=BigInt(44),a=BigInt(88),l=t*t*t%e,f=l*l*t%e,u=X(f,n,e)*f%e,y=X(u,n,e)*f%e,p=X(y,st,e)*l%e,w=X(p,o,e)*p%e,d=X(w,s,e)*w%e,h=X(d,c,e)*d%e,b=X(h,a,e)*h%e,E=X(b,c,e)*d%e,S=X(E,n,e)*f%e,I=X(S,i,e)*w%e,$=X(I,r,e)*l%e,_=X($,st,e);if(!Ct.eql(Ct.sqr(_),t))throw new Error("Cannot find square root");return _}const Ct=yo(rt,void 0,void 0,{sqrt:Nn}),ze=Bo({a:BigInt(0),b:BigInt(7),Fp:Ct,n:ot,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:t=>{const e=ot,n=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),r=-On*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),s=n,i=BigInt("0x100000000000000000000000000000000"),c=In(s*t,e),a=In(-r*t,e);let l=j(t-c*n-a*o,e),f=j(-c*r-a*s,e);const u=l>i,y=f>i;if(u&&(l=e-l),y&&(f=e-f),l>i||f>i)throw new Error("splitScalar: Endomorphism failed, k="+t);return{k1neg:u,k1:l,k2neg:y,k2:f}}}},St),it=BigInt(0),Tn=t=>typeof t=="bigint"&&it<t&&t<rt,$o=t=>typeof t=="bigint"&&it<t&&t<ot,Cn={};function ct(t,...e){let n=Cn[t];if(n===void 0){const r=St(Uint8Array.from(t,o=>o.charCodeAt(0)));n=ve(r,r),Cn[t]=n}return St(ve(n,...e))}const Pt=t=>t.toRawBytes(!0).slice(1),Rt=t=>we(t,32),Ut=t=>j(t,rt),Ve=t=>j(t,ot),Ht=ze.ProjectivePoint,Oo=(t,e,n)=>Ht.BASE.multiplyAndAddUnsafe(t,e,n);function Lt(t){let e=ze.utils.normPrivateKeyToScalar(t),n=Ht.fromPrivateKey(e);return{scalar:n.hasEvenY()?e:Ve(-e),bytes:Pt(n)}}function Pn(t){if(!Tn(t))throw new Error("bad x: need 0 < x < p");const e=Ut(t*t),n=Ut(e*t+BigInt(7));let r=Nn(n);r%st!==it&&(r=Ut(-r));const o=new Ht(t,r,On);return o.assertValidity(),o}function Rn(...t){return Ve(Z(ct("BIP0340/challenge",...t)))}function Io(t){return Lt(t).bytes}function No(t,e,n=pn(32)){const r=V("message",t),{bytes:o,scalar:s}=Lt(e),i=V("auxRand",n,32),c=Rt(s^Z(ct("BIP0340/aux",i))),a=ct("BIP0340/nonce",c,o,r),l=Ve(Z(a));if(l===it)throw new Error("sign failed: k is zero");const{bytes:f,scalar:u}=Lt(l),y=Rn(f,o,r),p=new Uint8Array(64);if(p.set(f,0),p.set(Rt(Ve(u+y*s)),32),!Un(p,r,o))throw new Error("sign: Invalid signature produced");return p}function Un(t,e,n){const r=V("signature",t,64),o=V("message",e),s=V("publicKey",n,32);try{const i=Pn(Z(s)),c=Z(r.subarray(0,32));if(!Tn(c))return!1;const a=Z(r.subarray(32,64));if(!$o(a))return!1;const l=Rn(Rt(c),Pt(i),o),f=Oo(i,a,Ve(-l));return!(!f||!f.hasEvenY()||f.toAffine().x!==c)}catch{return!1}}const W={getPublicKey:Io,sign:No,verify:Un,utils:{randomPrivateKey:ze.utils.randomPrivateKey,lift_x:Pn,pointToBytes:Pt,numberToBytesBE:we,bytesToNumberBE:Z,taggedHash:ct,mod:j}};function qt(t){if(!Number.isSafeInteger(t)||t<0)throw new Error(`Wrong positive integer: ${t}`)}function To(t){if(typeof t!="boolean")throw new Error(`Expected boolean, not ${t}`)}function Hn(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 Co(t){if(typeof t!="function"||typeof t.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");qt(t.outputLen),qt(t.blockLen)}function Po(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 Ro(t,e){Hn(t);const n=e.outputLen;if(t.length<n)throw new Error(`digestInto() expects output buffer of length at least ${n}`)}const Mt={number:qt,bool:To,bytes:Hn,hash:Co,exists:Po,output:Ro};function Uo(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),a=r?4:0,l=r?0:4;t.setUint32(e+a,i,r),t.setUint32(e+l,c,r)}class Ho extends Lr{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=mt(this.buffer)}update(e){Mt.exists(this);const{view:n,buffer:r,blockLen:o}=this;e=ln(e);const s=e.length;for(let i=0;i<s;){const c=Math.min(o-this.pos,s-i);if(c===o){const a=mt(e);for(;o<=s-i;i+=o)this.process(a,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){Mt.exists(this),Mt.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;Uo(r,o-8,BigInt(this.length*8),s),this.process(r,0);const c=mt(e),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const l=a/4,f=this.get();if(l>f.length)throw new Error("_sha2: outputLen bigger than state");for(let u=0;u<l;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 Lo=(t,e,n)=>t&e^~t&n,qo=(t,e,n)=>t&e^t&n^e&n,Mo=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]),pe=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),ye=new Uint32Array(64);class Ln extends Ho{constructor(){super(64,32,8,!1),this.A=pe[0]|0,this.B=pe[1]|0,this.C=pe[2]|0,this.D=pe[3]|0,this.E=pe[4]|0,this.F=pe[5]|0,this.G=pe[6]|0,this.H=pe[7]|0}get(){const{A:e,B:n,C:r,D:o,E:s,F:i,G:c,H:a}=this;return[e,n,r,o,s,i,c,a]}set(e,n,r,o,s,i,c,a){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=a|0}process(e,n){for(let u=0;u<16;u++,n+=4)ye[u]=e.getUint32(n,!1);for(let u=16;u<64;u++){const y=ye[u-15],p=ye[u-2],w=ne(y,7)^ne(y,18)^y>>>3,d=ne(p,17)^ne(p,19)^p>>>10;ye[u]=d+ye[u-7]+w+ye[u-16]|0}let{A:r,B:o,C:s,D:i,E:c,F:a,G:l,H:f}=this;for(let u=0;u<64;u++){const y=ne(c,6)^ne(c,11)^ne(c,25),p=f+y+Lo(c,a,l)+Mo[u]+ye[u]|0,d=(ne(r,2)^ne(r,13)^ne(r,22))+qo(r,o,s)|0;f=l,l=a,a=c,c=i+p|0,i=s,s=o,o=r,r=p+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,l=l+this.G|0,f=f+this.H|0,this.set(r,o,s,i,c,a,l,f)}roundClean(){ye.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}}class Ko extends Ln{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 Kt=un(()=>new Ln);un(()=>new Ko);var Pe=Symbol("verified"),jo=t=>t instanceof Object;function zo(t){if(!jo(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 Vo=new TextEncoder,Do=class{generateSecretKey(){return W.utils.randomPrivateKey()}getPublicKey(e){return D(W.getPublicKey(e))}finalizeEvent(e,n){const r=e;return r.pubkey=D(W.getPublicKey(n)),r.id=jt(r),r.sig=D(W.sign(jt(r),n)),r[Pe]=!0,r}verifyEvent(e){if(typeof e[Pe]=="boolean")return e[Pe];const n=jt(e);if(n!==e.id)return e[Pe]=!1,!1;try{const r=W.verify(e.sig,n,e.pubkey);return e[Pe]=r,r}catch{return e[Pe]=!1,!1}}};function Wo(t){if(!zo(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 jt(t){let e=Kt(Vo.encode(Wo(t)));return D(e)}var at=new Do,Fo=at.generateSecretKey;at.getPublicKey,at.finalizeEvent,at.verifyEvent;var Ae=Symbol("verified"),Go=t=>t instanceof Object;function Zo(t){if(!Go(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 Jo=new TextEncoder;function De(t){t.indexOf("://")===-1&&(t="wss://"+t);let e=new URL(t);return e.pathname=e.pathname.replace(/\/+/g,"/"),e.pathname.endsWith("/")&&(e.pathname=e.pathname.slice(0,-1)),(e.port==="80"&&e.protocol==="ws:"||e.port==="443"&&e.protocol==="wss:")&&(e.port=""),e.searchParams.sort(),e.hash="",e.toString()}var Yo=class{constructor(e){g(this,"value");g(this,"next",null);g(this,"prev",null);this.value=e}},Qo=class{constructor(){g(this,"first");g(this,"last");this.first=null,this.last=null}enqueue(e){const n=new Yo(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}},Xo=class{generateSecretKey(){return W.utils.randomPrivateKey()}getPublicKey(e){return D(W.getPublicKey(e))}finalizeEvent(e,n){const r=e;return r.pubkey=D(W.getPublicKey(n)),r.id=zt(r),r.sig=D(W.sign(zt(r),n)),r[Ae]=!0,r}verifyEvent(e){if(typeof e[Ae]=="boolean")return e[Ae];const n=zt(e);if(n!==e.id)return e[Ae]=!1,!1;try{const r=W.verify(e.sig,n,e.pubkey);return e[Ae]=r,r}catch{return e[Ae]=!1,!1}}};function es(t){if(!Zo(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 zt(t){let e=Kt(Jo.encode(es(t)));return D(e)}var lt=new Xo;lt.generateSecretKey,lt.getPublicKey,lt.finalizeEvent;var ts=lt.verifyEvent,ns=22242;function rs(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 os(t,e){for(let n=0;n<t.length;n++)if(rs(t[n],e))return!0;return!1}function ss(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 is(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 cs(t,e){return{kind:ns,created_at:Math.floor(Date.now()/1e3),tags:[["relay",t],["challenge",e]],content:""}}async function as(){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 ls=t=>(t[Ae]=!0,!0),qn;try{qn=WebSocket}catch{}var Mn=class{constructor(e,n){g(this,"url");g(this,"_connected",!1);g(this,"onclose",null);g(this,"onnotice",e=>console.debug(`NOTICE from ${this.url}: ${e}`));g(this,"baseEoseTimeout",4400);g(this,"connectionTimeout",4400);g(this,"openSubs",new Map);g(this,"connectionTimeoutHandle");g(this,"connectionPromise");g(this,"openCountRequests",new Map);g(this,"openEventPublishes",new Map);g(this,"ws");g(this,"incomingMessageQueue",new Qo);g(this,"queueRunning",!1);g(this,"challenge");g(this,"serial",0);g(this,"verifyEvent");this.url=De(e),this.verifyEvent=n.verifyEvent}static async connect(e,n){const r=new Mn(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 qn(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 as();this.queueRunning=!1}handleNext(){var r,o;const e=this.incomingMessageQueue.dequeue();if(!e)return!1;const n=is(e);if(n){const s=this.openSubs.get(n);if(!s)return;const i=ss(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)&&os(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],l=this.openEventPublishes.get(i);c?l.resolve(a):l.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(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(cs(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 us(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()}},us=class{constructor(e,n,r,o){g(this,"relay");g(this,"id");g(this,"closed",!1);g(this,"eosed",!1);g(this,"filters");g(this,"alreadyHaveEvent");g(this,"receivedEvent");g(this,"onevent");g(this,"oneose");g(this,"onclose");g(this,"eoseTimeout");g(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)}},fs=class{constructor(e){g(this,"relays",new Map);g(this,"seenOn",new Map);g(this,"trackRelays",!1);g(this,"verifyEvent");g(this,"trustedRelayURLs",new Set);this.verifyEvent=e.verifyEvent}async ensureRelay(e,n){e=De(e);let r=this.relays.get(e);return r||(r=new Mn(e,{verifyEvent:this.trustedRelayURLs.has(e)?ls:this.verifyEvent}),n!=null&&n.connectionTimeout&&(r.connectionTimeout=n.connectionTimeout),this.relays.set(e,r)),await r.connect(),r}close(e){e.map(De).forEach(n=>{var r;(r=this.relays.get(n))==null||r.close()})}subscribeMany(e,n,r){this.trackRelays&&(r.receivedEvent=(y,p)=>{let w=this.seenOn.get(p);w||(w=new Set,this.seenOn.set(p,w)),w.add(y)});const o=new Set,s=[],i=[];let c=y=>{var p;i[y]=!0,i.filter(w=>w).length===e.length&&((p=r.oneose)==null||p.call(r),c=()=>{})};const a=[];let l=(y,p)=>{var w;c(y),a[y]=p,a.filter(d=>d).length===e.length&&((w=r.onclose)==null||w.call(r,a),l=()=>{})};const f=y=>{var w;if((w=r.alreadyHaveEvent)!=null&&w.call(r,y))return!0;const p=o.has(y);return o.add(y),p},u=Promise.all(e.map(De).map(async(y,p,w)=>{if(w.indexOf(y)!==p){l(p,"duplicate url");return}let d;try{d=await this.ensureRelay(y,{connectionTimeout:r.maxWait?Math.max(r.maxWait*.8,r.maxWait-1e3):void 0})}catch(b){l(p,(b==null?void 0:b.message)||String(b));return}let h=d.subscribe(n,{...r,oneose:()=>c(p),onclose:b=>l(p,b),alreadyHaveEvent:f,eoseTimeout:r.maxWait});s.push(h)}));return{async close(){await u,s.forEach(y=>{y.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(De).map(async(r,o,s)=>s.indexOf(r)!==o?Promise.reject("duplicate url"):(await this.ensureRelay(r)).publish(n))}},ds=class extends fs{constructor(){super({verifyEvent:ts})}};/*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) */function Re(t){if(!Number.isSafeInteger(t))throw new Error(`Wrong integer: ${t}`)}function ie(...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 ce(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(Re(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 ae(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 ut(t,e="="){if(Re(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 Kn(t){if(typeof t!="function")throw new Error("normalize fn should be function");return{encode:e=>e,decode:e=>t(e)}}function jn(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(Re(i),i<0||i>=e)throw new Error(`Wrong integer: ${i}`)});;){let i=0,c=!0;for(let a=r;a<s.length;a++){const l=s[a],f=e*i+l;if(!Number.isSafeInteger(f)||e*i/e!==i||f-l!==e*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<t.length-1&&t[i]===0;i++)o.push(0);return o.reverse()}const zn=(t,e)=>e?zn(e,t%e):t,ft=(t,e)=>t+(e-zn(t,e));function Vt(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(ft(e,n)>32)throw new Error(`convertRadix2: carry overflow from=${e} to=${n} carryBits=${ft(e,n)}`);let o=0,s=0;const i=2**n-1,c=[];for(const a of t){if(Re(a),a>=2**e)throw new Error(`convertRadix2: invalid data word=${a} from=${e}`);if(o=o<<e|a,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 hs(t){return Re(t),{encode:e=>{if(!(e instanceof Uint8Array))throw new Error("radix.encode input should be Uint8Array");return jn(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(jn(e,t,2**8))}}}function ge(t,e=!1){if(Re(t),t<=0||t>32)throw new Error("radix2: bits should be in (0..32]");if(ft(8,t)>32||ft(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 Vt(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(Vt(n,t,8,e))}}}function Vn(t){if(typeof t!="function")throw new Error("unsafeWrapper fn should be function");return function(...e){try{return t.apply(null,e)}catch{}}}const ws=ie(ge(4),ce("0123456789ABCDEF"),ae("")),ps=ie(ge(5),ce("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"),ut(5),ae(""));ie(ge(5),ce("0123456789ABCDEFGHIJKLMNOPQRSTUV"),ut(5),ae("")),ie(ge(5),ce("0123456789ABCDEFGHJKMNPQRSTVWXYZ"),ae(""),Kn(t=>t.toUpperCase().replace(/O/g,"0").replace(/[IL]/g,"1")));const We=ie(ge(6),ce("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),ut(6),ae("")),ys=ie(ge(6),ce("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"),ut(6),ae("")),Dt=t=>ie(hs(58),ce(t),ae("")),Wt=Dt("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");Dt("123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"),Dt("rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz");const Dn=[0,2,3,5,6,7,9,10,11],gs={encode(t){let e="";for(let n=0;n<t.length;n+=8){const r=t.subarray(n,n+8);e+=Wt.encode(r).padStart(Dn[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=Dn.indexOf(r.length),s=Wt.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)}},Ft=ie(ce("qpzry9x8gf2tvdw0s3jn54khce6mua7l"),ae("")),Wn=[996825010,642813549,513874426,1027748829,705979059];function Fe(t){const e=t>>25;let n=(t&33554431)<<5;for(let r=0;r<Wn.length;r++)(e>>r&1)===1&&(n^=Wn[r]);return n}function Fn(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=Fe(o)^i>>5}o=Fe(o);for(let s=0;s<r;s++)o=Fe(o)^t.charCodeAt(s)&31;for(let s of e)o=Fe(o)^s;for(let s=0;s<6;s++)o=Fe(o);return o^=n,Ft.encode(Vt([o%2**30],30,5,!1))}function Gn(t){const e=t==="bech32"?1:734539939,n=ge(5),r=n.decode,o=n.encode,s=Vn(r);function i(f,u,y=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 p=f.length+7+u.length;if(y!==!1&&p>y)throw new TypeError(`Length ${p} exceeds limit ${y}`);return f=f.toLowerCase(),`${f}1${Ft.encode(u)}${Fn(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 y=f.toLowerCase();if(f!==y&&f!==f.toUpperCase())throw new Error("String must be lowercase or uppercase");f=y;const p=f.lastIndexOf("1");if(p===0||p===-1)throw new Error('Letter "1" must be present between prefix and data only');const w=f.slice(0,p),d=f.slice(p+1);if(d.length<6)throw new Error("Data must be at least 6 characters long");const h=Ft.decode(d).slice(0,-6),b=Fn(w,h,e);if(!d.endsWith(b))throw new Error(`Invalid checksum in ${f}: expected "${b}"`);return{prefix:w,words:h}}const a=Vn(c);function l(f){const{prefix:u,words:y}=c(f,!1);return{prefix:u,words:y,bytes:r(y)}}return{encode:i,decode:c,decodeToBytes:l,decodeUnsafe:a,fromWords:r,fromWordsUnsafe:s,toWords:o}}const Zn=Gn("bech32");Gn("bech32m");const bs={encode:t=>new TextDecoder().decode(t),decode:t=>new TextEncoder().encode(t)},ms=ie(ge(4),ce("0123456789abcdef"),ae(""),Kn(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:bs,hex:ms,base16:ws,base32:ps,base64:We,base64url:ys,base58:Wt,base58xmr:gs}).join(", ")}`;var ke=Symbol("verified"),xs=t=>t instanceof Object;function Es(t){if(!xs(t)||typeof t.kind!="number"||typeof t.content!="string"||typeof t.created_at!="number"||typeof t.pubkey!="string"||!t.pubkey.match(/^[a-f0-9]{64}$/)||!Array.isArray(t.tags))return!1;for(let e=0;e<t.tags.length;e++){let n=t.tags[e];if(!Array.isArray(n))return!1;for(let r=0;r<n.length;r++)if(typeof n[r]=="object")return!1}return!0}var vs=new TextDecoder("utf-8"),Jn=new TextEncoder;function Ge(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 _s=class{constructor(t){g(this,"value");g(this,"next",null);g(this,"prev",null);this.value=t}},Ss=class{constructor(){g(this,"first");g(this,"last");this.first=null,this.last=null}enqueue(t){const e=new _s(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}},As=class{generateSecretKey(){return W.utils.randomPrivateKey()}getPublicKey(t){return D(W.getPublicKey(t))}finalizeEvent(t,e){const n=t;return n.pubkey=D(W.getPublicKey(e)),n.id=Gt(n),n.sig=D(W.sign(Gt(n),e)),n[ke]=!0,n}verifyEvent(t){if(typeof t[ke]=="boolean")return t[ke];const e=Gt(t);if(e!==t.id)return t[ke]=!1,!1;try{const n=W.verify(t.sig,e,t.pubkey);return t[ke]=n,n}catch{return t[ke]=!1,!1}}};function ks(t){if(!Es(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 Gt(t){let e=Kt(Jn.encode(ks(t)));return D(e)}var dt=new As,Bs=dt.generateSecretKey,Yn=dt.getPublicKey,$s=dt.finalizeEvent,Qn=dt.verifyEvent;typeof crypto<"u"&&!crypto.subtle&&crypto.webcrypto&&(crypto.subtle=crypto.webcrypto.subtle);async function Os(t,e,n){const r=t instanceof Uint8Array?D(t):t,o=ze.getSharedSecret(r,"02"+e),s=Xn(o);let i=Uint8Array.from(qr(16)),c=Jn.encode(n),a=await crypto.subtle.importKey("raw",s,{name:"AES-CBC"},!1,["encrypt"]),l=await crypto.subtle.encrypt({name:"AES-CBC",iv:i},a,c),f=We.encode(new Uint8Array(l)),u=We.encode(new Uint8Array(i.buffer));return`${f}?iv=${u}`}async function Is(t,e,n){const r=t instanceof Uint8Array?D(t):t;let[o,s]=n.split("?iv="),i=ze.getSharedSecret(r,"02"+e),c=Xn(i),a=await crypto.subtle.importKey("raw",c,{name:"AES-CBC"},!1,["decrypt"]),l=We.decode(o),f=We.decode(s),u=await crypto.subtle.decrypt({name:"AES-CBC",iv:f},a,l);return vs.decode(u)}function Xn(t){return t.slice(1,33)}var Ns=/^(?:([\w.+-]+)@)?([\w_-]+(\.[\w_-]+)+)$/,Ts;try{Ts=fetch}catch{}var Cs=22242,Zt=24133,Ps=31990;function Rs(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 Us(t,e){for(let n=0;n<t.length;n++)if(Rs(t[n],e))return!0;return!1}function Hs(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 Ls(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 qs(t,e){return{kind:Cs,created_at:Math.floor(Date.now()/1e3),tags:[["relay",t],["challenge",e]],content:""}}async function Ms(){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 Ks=t=>(t[ke]=!0,!0),er;try{er=WebSocket}catch{}var tr=class{constructor(t,e){g(this,"url");g(this,"_connected",!1);g(this,"onclose",null);g(this,"onnotice",t=>console.debug(`NOTICE from ${this.url}: ${t}`));g(this,"baseEoseTimeout",4400);g(this,"connectionTimeout",4400);g(this,"openSubs",new Map);g(this,"connectionTimeoutHandle");g(this,"connectionPromise");g(this,"openCountRequests",new Map);g(this,"openEventPublishes",new Map);g(this,"ws");g(this,"incomingMessageQueue",new Ss);g(this,"queueRunning",!1);g(this,"challenge");g(this,"serial",0);g(this,"verifyEvent");this.url=Ge(t),this.verifyEvent=e.verifyEvent}static async connect(t,e){const n=new tr(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 er(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 Ms();this.queueRunning=!1}handleNext(){var n,r;const t=this.incomingMessageQueue.dequeue();if(!t)return!1;const e=Ls(t);if(e){const o=this.openSubs.get(e);if(!o)return;const s=Hs(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)&&Us(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(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(qs(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 js(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()}},js=class{constructor(t,e,n,r){g(this,"relay");g(this,"id");g(this,"closed",!1);g(this,"eosed",!1);g(this,"filters");g(this,"alreadyHaveEvent");g(this,"receivedEvent");g(this,"onevent");g(this,"oneose");g(this,"onclose");g(this,"eoseTimeout");g(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)}},zs=class{constructor(t){g(this,"relays",new Map);g(this,"seenOn",new Map);g(this,"trackRelays",!1);g(this,"verifyEvent");g(this,"trustedRelayURLs",new Set);this.verifyEvent=t.verifyEvent}async ensureRelay(t,e){t=Ge(t);let n=this.relays.get(t);return n||(n=new tr(t,{verifyEvent:this.trustedRelayURLs.has(t)?Ks:this.verifyEvent}),e!=null&&e.connectionTimeout&&(n.connectionTimeout=e.connectionTimeout),this.relays.set(t,n)),await n.connect(),n}close(t){t.map(Ge).forEach(e=>{var n;(n=this.relays.get(e))==null||n.close()})}subscribeMany(t,e,n){this.trackRelays&&(n.receivedEvent=(u,y)=>{let p=this.seenOn.get(y);p||(p=new Set,this.seenOn.set(y,p)),p.add(u)});const r=new Set,o=[],s=[];let i=u=>{var y;s[u]=!0,s.filter(p=>p).length===t.length&&((y=n.oneose)==null||y.call(n),i=()=>{})};const c=[];let a=(u,y)=>{var p;i(u),c[u]=y,c.filter(w=>w).length===t.length&&((p=n.onclose)==null||p.call(n,c),a=()=>{})};const l=u=>{var p;if((p=n.alreadyHaveEvent)!=null&&p.call(n,u))return!0;const y=r.has(u);return r.add(u),y},f=Promise.all(t.map(Ge).map(async(u,y,p)=>{if(p.indexOf(u)!==y){a(y,"duplicate url");return}let w;try{w=await this.ensureRelay(u,{connectionTimeout:n.maxWait?Math.max(n.maxWait*.8,n.maxWait-1e3):void 0})}catch(h){a(y,(h==null?void 0:h.message)||String(h));return}let d=w.subscribe(e,{...n,oneose:()=>i(y),onclose:h=>a(y,h),alreadyHaveEvent:l,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(Ge).map(async(n,r,o)=>o.indexOf(n)!==r?Promise.reject("duplicate url"):(await this.ensureRelay(n)).publish(e))}},Vs=class extends zs{constructor(){super({verifyEvent:Qn})}},nr;try{nr=fetch}catch{}var Ds=/^bunker:\/\/([0-9a-f]{64})\??([?\/\w:.=&%]*)$/,Ws=/^[^\s@]+@[^\s@]+\.[^\s@]+$/;async function Fs(t){let e=t.match(Ds);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 rr(t)}async function rr(t){const e=t.match(Ns);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],a=i.nip46[c]||[];return{pubkey:c,relays:a,secret:null}}catch{return null}}var Jt=class{constructor(t,e,n={}){g(this,"pool");g(this,"subCloser");g(this,"isOpen");g(this,"serial");g(this,"idPrefix");g(this,"listeners");g(this,"waitingForAuth");g(this,"secretKey");g(this,"bp");if(e.relays.length===0)throw new Error("no relays are specified for this bunker");this.pool=n.pool||new Vs,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:[Zt],"#p":[Yn(this.secretKey)]}],{async onevent(s){const{id:i,result:c,error:a}=JSON.parse(await Is(t,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 ${e.pubkey} tried to send an "auth_url"='${a}' but there was no onauth() callback configured.`);return}let l=r[i];l&&(a?l.reject(a):c&&l.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 Os(this.secretKey,this.bp.pubkey,JSON.stringify({id:o,method:t,params:e})),i=$s({kind:Zt,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",[Yn(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&&Qn(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 xt(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 Gs(t,e,n,r,o){if(o&&!Ws.test(o))throw new Error("Invalid email");let s=Bs(),i=new Jt(s,t.bunkerPointer,e),c=await i.sendRequest("create_account",[n,r,o||""]);return i.bp.pubkey=c,await i.connect(),i}async function Zs(t,e){const n=await t.querySync(e,{kinds:[Ps],"#k":[Zt.toString()]});return(await Promise.all(n.map(async o=>{try{const s=JSON.parse(o.content),i=await rr(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 Js=/^(?:([\w.+-]+)@)?([\w_-]+(\.[\w_-]+)+)$/,or;try{or=fetch}catch{}async function Ys(t){var s;const e=t.match(Js);if(!e)return null;const[n,r="_",o]=e;try{const i=`https://${o}/.well-known/nostr.json?name=${r}`,c=await(await or(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 Qs=5e3;function Xs(t){return ti("npub",xt(t))}function ei(t,e){let n=Zn.toWords(e);return Zn.encode(t,n,Qs)}function ti(t,e){return ei(t,e)}const{window:ni}=pr;function sr(t,e,n){const r=t.slice();return r[30]=e[n],r}function ri(t){let e,n,r,o,s;function i(l,f){if(l[5])return ci;if(!l[6])return ii;if(l[6])return si}let c=i(t),a=c&&c(t);return{c(){e=C("div"),n=C("button"),n.textContent="⤫",r=Y(),a&&a.c(),k(n,"class","tw-absolute tw-top-0 tw-right-0.5 tw-bg-transparent tw-border-none tw-cursor-pointer tw-text-cyan-950 tw-text-3xl"),k(e,"class","tw-w-80 tw-px-6 tw-py-8 tw-transition-all tw-bg-cyan-700 tw-rounded-md tw-shadow-[0_0px_30px_0px_rgba(0,0,0,0.6)]")},m(l,f){H(l,e,f),R(e,n),R(e,r),a&&a.m(e,null),o||(s=fe(n,"click",t[9]),o=!0)},p(l,f){c===(c=i(l))&&a?a.p(l,f):(a&&a.d(1),a=c&&c(l),a&&(a.c(),a.m(e,null)))},d(l){l&&U(e),a&&a.d(),o=!1,s()}}}function oi(t){let e;function n(s,i){return s[4]?ui:s[6]?ai:li}let r=n(t),o=r(t);return{c(){e=C("div"),o.c(),k(e,"class","tw-px-4 tw-py-2 tw-transition-all tw-bg-cyan-700 hover:tw-bg-cyan-800 tw-rounded tw-cursor-pointer tw-shadow-[0_0px_10px_0px_rgba(0,0,0,0.3)]")},m(s,i){H(s,e,i),o.m(e,null)},p(s,i){r===(r=n(s))&&o?o.p(s,i):(o.d(1),o=r(s),o&&(o.c(),o.m(e,null)))},d(s){s&&U(e),o.d()}}}function si(t){let e,n,r,o,s,i,c=t[6].npub+"",a,l,f,u,y,p,w=(t[6].picture||t[6].name)&&ir(t);return{c(){e=C("div"),n=C("div"),n.textContent="You are connected to Nostr as",r=Y(),o=C("a"),w&&w.c(),s=Y(),i=C("div"),a=Ee(c),f=Y(),u=C("button"),u.textContent="Disconnect",k(n,"class","tw-text-xs tw-mb-4"),k(i,"class","tw-block tw-break-all"),k(o,"target","_blank"),k(o,"href",l="https://nosta.me/"+t[6].npub),k(o,"class","tw-text-white tw-no-underline tw-group"),k(e,"class","tw-text-center"),k(u,"class","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-cyan-900 hover:tw-bg-cyan-950 tw-hover:bg-indigo-900 tw-cursor-pointer tw-text-white")},m(d,h){H(d,e,h),R(e,n),R(e,r),R(e,o),w&&w.m(o,null),R(o,s),R(o,i),R(i,a),H(d,f,h),H(d,u,h),y||(p=fe(u,"click",t[11]),y=!0)},p(d,h){d[6].picture||d[6].name?w?w.p(d,h):(w=ir(d),w.c(),w.m(o,s)):w&&(w.d(1),w=null),h[0]&64&&c!==(c=d[6].npub+"")&&wt(a,c),h[0]&64&&l!==(l="https://nosta.me/"+d[6].npub)&&k(o,"href",l)},d(d){d&&(U(e),U(f),U(u)),w&&w.d(),y=!1,p()}}}function ii(t){let e,n,r,o,s,i,c,a,l,f,u,y;return{c(){e=C("div"),e.textContent="How do you want to connect to Nostr?",n=Y(),r=C("form"),o=C("input"),s=Y(),i=C("button"),i.textContent="Connect »",c=Y(),a=C("div"),l=Ee(`Do you need a Nostr account?
|
|
3
|
-
`),f=C("button"),f.textContent="Get one now for free",k(e,"class","tw-text-lg tw-text-center"),k(o,"class","tw-box-border tw-w-full tw-px-2 tw-py-1 tw-rounded tw-text-lg tw-border-none tw-outline-none"),k(o,"placeholder","user@provider or bunker://..."),k(i,"class","tw-block tw-w-full tw-mt-4 tw-px-2 tw-py-1 tw-text-lg tw-rounded tw-border-0 tw-bg-cyan-900 hover:tw-bg-cyan-950 tw-hover:bg-indigo-900 tw-cursor-pointer tw-text-white"),k(r,"class","flex tw-mt-4 tw-mb-1"),k(f,"class","tw-border-0 tw-bg-transparent tw-text-white tw-cursor-pointer tw-underline tw-text-sm"),k(a,"class","tw-mt-6 tw-text-center tw-text-sm tw-leading-3")},m(p,w){H(p,e,w),H(p,n,w),H(p,r,w),R(r,o),t[17](o),R(r,s),R(r,i),H(p,c,w),H(p,a,w),R(a,l),R(a,f),u||(y=[fe(r,"submit",t[10]),fe(f,"click",t[12])],u=!0)},p:K,d(p){p&&(U(e),U(n),U(r),U(c),U(a)),t[17](null),u=!1,$e(y)}}}function ci(t){let e,n,r,o,s,i,c,a,l,f,u,y,p,w=sn(t[7]),d=[];for(let h=0;h<w.length;h+=1)d[h]=lr(sr(t,w,h));return{c(){e=C("div"),e.textContent="Create a new Nostr account",n=Y(),r=C("form"),o=C("div"),s=C("input"),i=Y(),c=C("div"),c.textContent="@",a=Y(),l=C("select");for(let h=0;h<d.length;h+=1)d[h].c();f=Y(),u=C("button"),u.textContent="create",k(e,"class","tw-text-lg tw-text-center"),k(s,"class","tw-box-border tw-w-full tw-px-2 tw-py-1 tw-rounded tw-text-lg tw-border-none tw-outline-none"),k(s,"placeholder","bob"),k(c,"class","tw-mx-2 tw-text-2xl"),k(l,"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[2]===void 0&&Xe(()=>t[16].call(l)),k(o,"class","tw-flex items-center"),k(u,"class","tw-block tw-w-full tw-mt-4 tw-px-2 tw-py-1 tw-text-lg tw-rounded tw-border-0 tw-bg-cyan-900 hover:tw-bg-cyan-950 tw-hover:bg-indigo-900 tw-cursor-pointer tw-text-white"),k(r,"class","tw-mt-4 tw-mb-1")},m(h,b){H(h,e,b),H(h,n,b),H(h,r,b),R(r,o),R(o,s),t[15](s),R(o,i),R(o,c),R(o,a),R(o,l);for(let E=0;E<d.length;E+=1)d[E]&&d[E].m(l,null);tn(l,t[2],!0),R(r,f),R(r,u),y||(p=[fe(s,"input",t[14]),fe(l,"change",t[16]),fe(r,"submit",t[13])],y=!0)},p(h,b){if(b[0]&128){w=sn(h[7]);let E;for(E=0;E<w.length;E+=1){const S=sr(h,w,E);d[E]?d[E].p(S,b):(d[E]=lr(S),d[E].c(),d[E].m(l,null))}for(;E<d.length;E+=1)d[E].d(1);d.length=w.length}b[0]&132&&tn(l,h[2])},d(h){h&&(U(e),U(n),U(r)),t[15](null),yr(d,h),y=!1,$e(p)}}}function ir(t){let e,n,r=t[6].picture&&cr(t),o=t[6].name&&ar(t);return{c(){e=C("div"),r&&r.c(),n=Y(),o&&o.c(),k(e,"class","tw-flex tw-items-center tw-justify-center tw-gap-2 tw-mb-2")},m(s,i){H(s,e,i),r&&r.m(e,null),R(e,n),o&&o.m(e,null)},p(s,i){s[6].picture?r?r.p(s,i):(r=cr(s),r.c(),r.m(e,n)):r&&(r.d(1),r=null),s[6].name?o?o.p(s,i):(o=ar(s),o.c(),o.m(e,null)):o&&(o.d(1),o=null)},d(s){s&&U(e),r&&r.d(),o&&o.d()}}}function cr(t){let e,n;return{c(){e=C("img"),Ye(e.src,n=t[6].picture)||k(e,"src",n),k(e,"alt",""),k(e,"class","tw-w-10 tw-h-10 tw-rounded-full tw-border-solid tw-border-2 tw-border-transparent group-hover:tw-border-cyan-100")},m(r,o){H(r,e,o)},p(r,o){o[0]&64&&!Ye(e.src,n=r[6].picture)&&k(e,"src",n)},d(r){r&&U(e)}}}function ar(t){let e,n=t[6].name+"",r;return{c(){e=C("div"),r=Ee(n),k(e,"class","tw-text-3xl group-hover:tw-underline tw-decoration-2 tw-underline-offset-4")},m(o,s){H(o,e,s),R(e,r)},p(o,s){s[0]&64&&n!==(n=o[6].name+"")&&wt(r,n)},d(o){o&&U(e)}}}function lr(t){let e,n,r;return{c(){e=C("option"),k(e,"label",n=t[30].domain),e.__value=r=t[30],en(e,e.__value),k(e,"class","tw-px-2 tw-py-1 tw-text-lg")},m(o,s){H(o,e,s)},p(o,s){s[0]&128&&n!==(n=o[30].domain)&&k(e,"label",n),s[0]&128&&r!==(r=o[30])&&(e.__value=r,en(e,e.__value))},d(o){o&&U(e)}}}function ai(t){let e,n,r=(t[6].name||t[6].npub.slice(0,7)+"…"+t[6].npub.slice(-4))+"",o;function s(a,l){return a[6].picture?di:fi}let i=s(t),c=i(t);return{c(){e=C("div"),c.c(),n=Y(),o=Ee(r),k(e,"class","tw-flex tw-items-center")},m(a,l){H(a,e,l),c.m(e,null),R(e,n),R(e,o)},p(a,l){i===(i=s(a))&&c?c.p(a,l):(c.d(1),c=i(a),c&&(c.c(),c.m(e,n))),l[0]&64&&r!==(r=(a[6].name||a[6].npub.slice(0,7)+"…"+a[6].npub.slice(-4))+"")&&wt(o,r)},d(a){a&&U(e),c.d()}}}function li(t){let e;return{c(){e=Ee("Login with Nostr")},m(n,r){H(n,e,r)},p:K,d(n){n&&U(e)}}}function ui(t){let e;return{c(){e=C("div"),e.textContent="Connecting to bunker..."},m(n,r){H(n,e,r)},p:K,d(n){n&&U(e)}}}function fi(t){let e;return{c(){e=Ee("☉")},m(n,r){H(n,e,r)},p:K,d(n){n&&U(e)}}}function di(t){let e,n;return{c(){e=C("img"),Ye(e.src,n=t[6].picture)||k(e,"src",n),k(e,"alt",""),k(e,"class","tw-w-5 tw-h-5 tw-rounded-full tw-mr-2")},m(r,o){H(r,e,o)},p(r,o){o[0]&64&&!Ye(e.src,n=r[6].picture)&&k(e,"src",n)},d(r){r&&U(e)}}}function hi(t){let e,n,r;function o(c,a){return c[3]?ri:oi}let s=o(t),i=s(t);return{c(){e=C("div"),i.c(),k(e,"class","tw-text-white tw-font-sans"),nn(e,"tw-cursor-pointer",!t[6]&&!t[3])},m(c,a){H(c,e,a),i.m(e,null),n||(r=fe(ni,"click",t[8]),n=!0)},p(c,a){s===(s=o(c))&&i?i.p(c,a):(i.d(1),i=s(c),i&&(i.c(),i.m(e,null))),a[0]&72&&nn(e,"tw-cursor-pointer",!c[6]&&!c[3])},i:K,o:K,d(c){c&&U(e),i.d(),n=!1,r()}}}function wi(t,e,n){const r=window,o=new ds;let s,i,c,a;const l=localStorage.getItem("nip46ClientSecretKey");l?a=xt(l):(a=Fo(),localStorage.setItem("nip46ClientSecretKey",D(a)));let f,u,y,p,w,d,h,b,E=[];I();let S={isWnj:!0,async getPublicKey(){return!w&&!h&&n(3,f=!0),(await p).bp.pubkey},async signEvent(x){return!w&&!h&&n(3,f=!0),(await p).signEvent(x)},async getRelays(){return!w&&!h&&n(3,f=!0),(await p).getRelays()},nip04:{async encrypt(x,B){return!w&&!h&&n(3,f=!0),(await p).nip04Encrypt(x,B)},async decrypt(x,B){return!w&&!h&&n(3,f=!0),(await p).nip04Decrypt(x,B)}}};function I(){n(3,f=!1),u=null,p=new Promise(x=>{y=x}),n(4,w=!1),n(5,d=!1),n(6,h=null),b=null}const $={pool:o,onauth(x){window.open(x,"window.nostr","width=600,height=800,popup=yes")}};xr(()=>{let x=localStorage.getItem("nip46BunkerPointer");if(x&&(u=JSON.parse(x),n(4,w=!0),z(new Jt(a,u,$))),r.nostr&&!r.nostr.isWnj){r.destroyWnj();return}else Object.defineProperty(window,"nostr",{get(){return S},set(B){S=B,B.isWnj||r.destroyWnj()},configurable:!0});return()=>{b&&b.close()}});function _(x){x.composedPath().find(B=>B.id==="windowNostrModal")?n(3,f=!0):n(3,f=!1)}function A(x){n(3,f=!1),n(5,d=!1),x.stopPropagation()}async function O(x){if(x.preventDefault(),u=await Fs(s.value),!u){s.setCustomValidity('invalid NIP-05 "name@domain.com" address or bunker:// URI');return}s.setCustomValidity(""),z(new Jt(a,u,$))}async function J(x){x.preventDefault(),localStorage.removeItem("nip46BunkerPointer"),r.isWnj&&delete r.nostr,I()}async function P(x){x.preventDefault(),n(5,d=!0),E.length===0&&n(7,E=await Zs(o,["wss://relay.nostr.band"]))}async function N(x){if(x.preventDefault(),!c)return;let B=await Gs(c,$,i.value,c.domain);n(3,f=!0),n(5,d=!1),z(B)}const F=Rr(async()=>{c&&i.value.length>0&&(await Ys(i.value+"@"+c.domain)?i.setCustomValidity(`'${i.value}' is already taken.`):i.setCustomValidity(""))},500);async function z(x){await x.connect(),n(6,h={pubkey:x.bp.pubkey,npub:Xs(x.bp.pubkey),event:null}),n(4,w=!1),localStorage.setItem("nip46BunkerPointer",JSON.stringify(u)),b=o.subscribeMany(["wss://purplepag.es","wss://relay.snort.social","wss://relay.nos.social"],[{kinds:[0],authors:[x.bp.pubkey]}],{onevent(B){var T;if(!((((T=h.event)==null?void 0:T.created_at)||0)>=B.created_at))try{let{name:q,picture:G}=JSON.parse(B.content);n(6,h.event=B,h),n(6,h.name=q,h),n(6,h.picture=G,h)}catch{}}}),n(3,f=!1),y(x)}function oe(x){Qe[x?"unshift":"push"](()=>{i=x,n(1,i)})}function m(){c=br(this),n(2,c),n(7,E)}function v(x){Qe[x?"unshift":"push"](()=>{s=x,n(0,s)})}return[s,i,c,f,w,d,h,E,_,A,O,J,P,N,F,oe,m,v]}class pi extends Nr{constructor(e){super(),Ir(this,e,wi,hi,hr,{},null,[-1,-1])}}const ht=document.createElement("div");document.body.appendChild(ht),ht.id="windowNostrModal",ht.classList.add("tw-fixed","tw-top-6","tw-right-6");const yi=new pi({target:ht});window.destroyWnj=()=>{yi.$destroy()}})();
|
|
1
|
+
var _i=Object.defineProperty;var ki=(_t,G,pt)=>G in _t?_i(_t,G,{enumerable:!0,configurable:!0,writable:!0,value:pt}):_t[G]=pt;var m=(_t,G,pt)=>(ki(_t,typeof G!="symbol"?G+"":G,pt),pt);(function(){"use strict";var wr,pr;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 mr(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 xr(e){return Object.keys(e).length===0}const vr=typeof window<"u"?window:typeof globalThis<"u"?globalThis:global;function R(e,t){e.appendChild(t)}function P(e,t,n){e.insertBefore(t,n||null)}function T(e){e.parentNode&&e.parentNode.removeChild(e)}function Er(e,t){for(let n=0;n<e.length;n+=1)e[n]&&e[n].d(t)}function N(e){return document.createElement(e)}function tt(e){return document.createTextNode(e)}function j(){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 _r(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 kr(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 Sr(){if(!zt)throw new Error("Function called outside component initialization");return zt}function Ar(e){Sr().$$.on_mount.push(e)}const Tt=[],ne=[];let Ct=[];const on=[],Br=Promise.resolve();let ye=!1;function Or(){ye||(ye=!0,Br.then(sn))}function re(e){Ct.push(e)}const me=new Set;let Rt=0;function sn(){if(Rt!==0)return;const e=zt;do{try{for(;Rt<Tt.length;){const t=Tt[Rt];Rt++,Vt(t),Ir(t.$$)}}catch(t){throw Tt.length=0,Rt=0,t}for(Vt(null),Tt.length=0,Rt=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 Ir(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 $r(e){const t=[],n=[];Ct.forEach(r=>e.indexOf(r)===-1?t.push(r):n.push(r)),n.forEach(r=>r()),Ct=t}const Nr=new Set;function Tr(e,t){e&&e.i&&(Nr.delete(e),e.i(t))}function cn(e){return(e==null?void 0:e.length)!==void 0?e:Array.from(e)}function Cr(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 Rr(e,t){const n=e.$$;n.fragment!==null&&($r(n.after_update),$t(n.on_destroy),n.fragment&&n.fragment.d(t),n.on_destroy=n.fragment=null,n.ctx=[])}function Pr(e,t){e.$$.dirty[0]===-1&&(Tt.push(e),Or(),e.$$.dirty.fill(0)),e.$$.dirty[t/31|0]|=1<<t%31}function Ur(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&&Pr(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=_r(t.target);u.fragment&&u.fragment.l(l),l.forEach(T)}else u.fragment&&u.fragment.c();t.intro&&Tr(e.$$.fragment),Cr(e,t.target,t.anchor),sn()}Vt(a)}class Hr{constructor(){m(this,"$$");m(this,"$$set")}$destroy(){Rr(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&&!xr(t)&&(this.$$.skip_bound=!0,this.$$set(t),this.$$.skip_bound=!1)}}const Lr="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(Lr);function qr(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 Mr=xe.exports;const jr=qr(Mr),ve=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,Ee=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 Kr=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+=Kr[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 zr(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=zr(e)),!ln(e))throw new Error(`expected Uint8Array, got ${typeof e}`);return e}let Vr=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 Dr(e=32){if(ve&&typeof ve.getRandomValues=="function")return ve.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 Wr(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 Fr(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 Gr(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=Gr(e)),!wn(e))throw new Error(`expected Uint8Array, got ${typeof e}`);return e}function Zr(...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 Jr(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 Yr(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 Qr=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),Fr(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;Yr(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 Xr=(e,t,n)=>e&t^~e&n,to=(e,t,n)=>e&t^e&n^t&n,eo=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 no=class extends Qr{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+Xr(c,a,u)+eo[l]+bt[l]|0,d=(lt(r,2)^lt(r,13)^lt(r,22))+to(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=Jr(()=>new no);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const bn=BigInt(0),se=BigInt(1),ro=BigInt(2),ie=e=>e instanceof Uint8Array,oo=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Pt(e){if(!ie(e))throw new Error("Uint8Array expected");let t="";for(let n=0;n<e.length;n++)t+=oo[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(Pt(e))}function Ie(e){if(!ie(e))throw new Error("Uint8Array expected");return Oe(Pt(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 so(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 io(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 co(e){if(typeof e!="string")throw new Error(`utf8ToBytes expected string, got ${typeof e}`);return new Uint8Array(new TextEncoder().encode(e))}function ao(e){let t;for(t=0;e>bn;e>>=se,t+=1);return t}function lo(e,t){return e>>BigInt(t)&se}const uo=(e,t,n)=>e|(n?se:bn)<<BigInt(t),Ne=e=>(ro<<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 fo={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=fo[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 ho=Object.freeze(Object.defineProperty({__proto__:null,bitGet:lo,bitLen:ao,bitMask:Ne,bitSet:uo,bytesToHex:Pt,bytesToNumberBE:et,bytesToNumberLE:Ie,concatBytes:kt,createHmacDrbg:xn,ensureBytes:Z,equalBytes:io,hexToBytes:Ut,hexToNumber:Oe,numberToBytesBE:yt,numberToBytesLE:$e,numberToHexUnpadded:yn,numberToVarBytesBE:so,utf8ToBytes:co,validateObject:Dt},Symbol.toStringTag,{value:"Module"}));/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const W=BigInt(0),z=BigInt(1),St=BigInt(2),wo=BigInt(3),Ce=BigInt(4),vn=BigInt(5),En=BigInt(8);BigInt(9),BigInt(16);function F(e,t){const n=e%t;return n>=W?n:t+n}function po(e,t,n){if(n<=W||t<W)throw new Error("Expected power/modulo > 0");if(n===z)return W;let r=z;for(;t>W;)t&z&&(r=r*e%n),e=e*e%n,t>>=z;return r}function rt(e,t,n){let r=e;for(;t-- >W;)r*=r,r%=n;return r}function Re(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=z;for(;n!==W;){const c=r/n,a=r%n,u=o-s*c;r=n,n=a,o=s,s=u}if(r!==z)throw new Error("invert: does not exist");return F(o,t)}function go(e){const t=(e-z)/St;let n,r,o;for(n=e-z,r=0;n%St===W;n/=St,r++);for(o=St;o<e&&po(o,t,e)!==e-z;o++);if(r===1){const i=(e+z)/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+z)/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,z<<BigInt(u-w-1));f=c.sqr(p),l=c.mul(l,p),h=c.mul(h,f),u=w}return l}}function bo(e){if(e%Ce===wo){const t=(e+z)/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%En===vn){const t=(e-vn)/En;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 go(e)}const yo=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function mo(e){const t={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},n=yo.reduce((r,o)=>(r[o]="function",r),t);return Dt(e,n)}function xo(e,t,n){if(n<W)throw new Error("Expected power > 0");if(n===W)return e.ONE;if(n===z)return t;let r=e.ONE,o=t;for(;n>W;)n&z&&(r=e.mul(r,o)),o=e.sqr(o),n>>=z;return r}function vo(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 Eo(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=bo(e),c=Object.freeze({ORDER:e,BITS:o,BYTES:s,MASK:Ne(o),ZERO:W,ONE:z,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&z)===z,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)=>xo(c,a,u),div:(a,u)=>F(a*Re(u,e),e),sqrN:a=>a*a,addN:(a,u)=>a+u,subN:(a,u)=>a-u,mulN:(a,u)=>a*u,inv:a=>Re(a,e),sqrt:r.sqrt||(a=>i(c,a)),invertBatch:a=>vo(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 _o(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-z)+z;return n?$e(c,o):yt(c,o)}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const ko=BigInt(0),Pe=BigInt(1);function So(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>ko;)s&Pe&&(i=i.add(c)),c=c.double(),s>>=Pe;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+=Pe);const y=d,x=d+Math.abs(g)-1,_=p%2!==0,S=g<0;g===0?f=f.add(n(_,s[y])):u=u.add(n(S,s[x]))}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 mo(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 Ao(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:Bo,hexToBytes:Oo}=ho,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:Bo(r),l:e.subarray(n+2)}},toSig(e){const{Err:t}=At,n=typeof e=="string"?Oo(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 Io(e){const t=Ao(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),x=n.mul(y,p);return n.add(n.add(x,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:x}=t;if(d&&typeof p!="bigint"){if(p instanceof Uint8Array&&(p=Pt(p)),typeof p!="string"||!d.includes(p.length))throw new Error("Invalid key");p=p.padStart(g*2,"0")}let _;try{_=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&&(_=F(_,x)),c(_),_}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 x=_=>n.eql(_,n.ZERO);return x(g)&&x(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,x)=>y.toAffine(g[x])).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),x=s(d);if(!n.eql(y,x))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:x}=this,{px:_,py:S,pz:E}=d,b=n.eql(n.mul(g,E),n.mul(_,x)),k=n.eql(n.mul(y,E),n.mul(S,x));return b&&k}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:x,py:_,pz:S}=this;let E=n.ZERO,b=n.ZERO,k=n.ZERO,I=n.mul(x,x),K=n.mul(_,_),C=n.mul(S,S),O=n.mul(x,_);return O=n.add(O,O),k=n.mul(x,S),k=n.add(k,k),E=n.mul(d,k),b=n.mul(y,C),b=n.add(E,b),E=n.sub(K,b),b=n.add(K,b),b=n.mul(E,b),E=n.mul(O,E),k=n.mul(y,k),C=n.mul(d,C),O=n.sub(I,C),O=n.mul(d,O),O=n.add(O,k),k=n.add(I,I),I=n.add(k,I),I=n.add(I,C),I=n.mul(I,O),b=n.add(b,I),C=n.mul(_,S),C=n.add(C,C),I=n.mul(C,O),E=n.sub(E,I),k=n.mul(C,K),k=n.add(k,k),k=n.add(k,k),new l(E,b,k)}add(d){f(d);const{px:g,py:y,pz:x}=this,{px:_,py:S,pz:E}=d;let b=n.ZERO,k=n.ZERO,I=n.ZERO;const K=t.a,C=n.mul(t.b,Bn);let O=n.mul(g,_),M=n.mul(y,S),H=n.mul(x,E),nt=n.add(g,y),v=n.add(_,S);nt=n.mul(nt,v),v=n.add(O,M),nt=n.sub(nt,v),v=n.add(g,x);let A=n.add(_,E);return v=n.mul(v,A),A=n.add(O,H),v=n.sub(v,A),A=n.add(y,x),b=n.add(S,E),A=n.mul(A,b),b=n.add(M,H),A=n.sub(A,b),I=n.mul(K,v),b=n.mul(C,H),I=n.add(b,I),b=n.sub(M,I),I=n.add(M,I),k=n.mul(b,I),M=n.add(O,O),M=n.add(M,O),H=n.mul(K,H),v=n.mul(C,v),M=n.add(M,H),H=n.sub(O,H),H=n.mul(K,H),v=n.add(v,H),O=n.mul(M,v),k=n.add(k,O),O=n.mul(A,v),b=n.mul(nt,b),b=n.sub(b,O),O=n.mul(nt,M),I=n.mul(A,I),I=n.add(I,O),new l(b,k,I)}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(x=>x.pz));return g.map((x,_)=>x.toAffine(y[_])).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:x,k1:_,k2neg:S,k2:E}=y.splitScalar(d),b=g,k=g,I=this;for(;_>ft||E>ft;)_&ot&&(b=b.add(I)),E&ot&&(k=k.add(I)),I=I.double(),_>>=ot,E>>=ot;return x&&(b=b.negate()),S&&(k=k.negate()),k=new l(n.mul(k.px,y.beta),k.py,k.pz),b.add(k)}multiply(d){c(d);let g=d,y,x;const{endo:_}=t;if(_){const{k1neg:S,k1:E,k2neg:b,k2:k}=_.splitScalar(g);let{p:I,f:K}=this.wNAF(E),{p:C,f:O}=this.wNAF(k);I=w.constTimeNegate(S,I),C=w.constTimeNegate(b,C),C=new l(n.mul(C.px,_.beta),C.py,C.pz),y=I.add(C),x=K.add(O)}else{const{p:S,f:E}=this.wNAF(g);y=S,x=E}return l.normalizeZ([y,x])[0]}multiplyAndAddUnsafe(d,g,y){const x=l.BASE,_=(E,b)=>b===ft||b===ot||!E.equals(x)?E.multiplyUnsafe(b):E.multiply(b),S=_(this,g).add(_(d,y));return S.is0()?void 0:S}toAffine(d){const{px:g,py:y,pz:x}=this,_=this.is0();d==null&&(d=_?n.ONE:n.inv(x));const S=n.mul(g,d),E=n.mul(y,d),b=n.mul(x,d);if(_)return{x:n.ZERO,y:n.ZERO};if(!n.eql(b,n.ONE))throw new Error("invZ was invalid");return{x:S,y:E}}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 Pt(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=So(l,t.endo?Math.ceil(h/2):h);return{CURVE:t,ProjectivePoint:l,normPrivateKeyToScalar:a,weierstrassEquation:s,isWithinCurveOrder:i}}function $o(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 No(e){const t=$o(e),{Fp:n,n:r}=t,o=n.BYTES+1,s=2*n.BYTES+1;function i(v){return ft<v&&v<n.ORDER}function c(v){return F(v,r)}function a(v){return Re(v,r)}const{ProjectivePoint:u,normPrivateKeyToScalar:f,weierstrassEquation:l,isWithinCurveOrder:h}=Io({...t,toBytes(v,A,U){const L=A.toAffine(),q=n.toBytes(L.x),D=kt;return U?D(Uint8Array.from([A.hasEvenY()?2:3]),q):D(Uint8Array.from([4]),q,n.toBytes(L.y))},fromBytes(v){const A=v.length,U=v[0],L=v.subarray(1);if(A===o&&(U===2||U===3)){const q=et(L);if(!i(q))throw new Error("Point is not on curve");const D=l(q);let Q=n.sqrt(D);const X=(Q&ot)===ot;return(U&1)===1!==X&&(Q=n.neg(Q)),{x:q,y:Q}}else if(A===s&&U===4){const q=n.fromBytes(L.subarray(0,n.BYTES)),D=n.fromBytes(L.subarray(n.BYTES,2*n.BYTES));return{x:q,y:D}}else throw new Error(`Point of length ${A} was invalid. Expected ${o} compressed bytes or ${s} uncompressed bytes`)}}),w=v=>Pt(yt(v,t.nByteLength));function p(v){const A=r>>ot;return v>A}function d(v){return p(v)?c(-v):v}const g=(v,A,U)=>et(v.slice(A,U));class y{constructor(A,U,L){this.r=A,this.s=U,this.recovery=L,this.assertValidity()}static fromCompact(A){const U=t.nByteLength;return A=Z("compactSignature",A,U*2),new y(g(A,0,U),g(A,U,2*U))}static fromDER(A){const{r:U,s:L}=At.toSig(Z("DER",A));return new y(U,L)}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 y(this.r,this.s,A)}recoverPublicKey(A){const{r:U,s:L,recovery:q}=this,D=k(Z("msgHash",A));if(q==null||![0,1,2,3].includes(q))throw new Error("recovery id invalid");const Q=q===2||q===3?U+t.n:U;if(Q>=n.ORDER)throw new Error("recovery id 2 or 3 invalid");const X=q&1?"03":"02",ut=u.fromHex(X+w(Q)),$=a(Q),V=c(-D*$),Et=c(L*$),it=u.BASE.multiplyAndAddUnsafe(ut,V,Et);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 x={isValidPrivateKey(v){try{return f(v),!0}catch{return!1}},normPrivateKeyToScalar:f,randomPrivateKey:()=>{const v=Sn(t.n);return _o(t.randomBytes(v),t.n)},precompute(v=8,A=u.BASE){return A._setWindowSize(v),A.multiply(BigInt(3)),A}};function _(v,A=!0){return u.fromPrivateKey(v).toRawBytes(A)}function S(v){const A=v instanceof Uint8Array,U=typeof v=="string",L=(A||U)&&v.length;return A?L===o||L===s:U?L===2*o||L===2*s:v instanceof u}function E(v,A,U=!0){if(S(v))throw new Error("first arg must be private key");if(!S(A))throw new Error("second arg must be public key");return u.fromHex(A).multiply(f(v)).toRawBytes(U)}const b=t.bits2int||function(v){const A=et(v),U=v.length*8-t.nBitLength;return U>0?A>>BigInt(U):A},k=t.bits2int_modN||function(v){return c(b(v))},I=Ne(t.nBitLength);function K(v){if(typeof v!="bigint")throw new Error("bigint expected");if(!(ft<=v&&v<I))throw new Error(`bigint expected < 2^${t.nBitLength}`);return yt(v,t.nByteLength)}function C(v,A,U=O){if(["recovered","canonical"].some(It=>It in U))throw new Error("sign() legacy options not supported");const{hash:L,randomBytes:q}=t;let{lowS:D,prehash:Q,extraEntropy:X}=U;D==null&&(D=!0),v=Z("msgHash",v),Q&&(v=Z("prehashed msgHash",L(v)));const ut=k(v),$=f(A),V=[K($),K(ut)];if(X!=null){const It=X===!0?q(n.BYTES):X;V.push(Z("extraEntropy",It))}const Et=kt(...V),it=ut;function Qt(It){const Mt=b(It);if(!h(Mt))return;const gr=a(Mt),jt=u.BASE.multiply(Mt).toAffine(),ct=c(jt.x);if(ct===ft)return;const Kt=c(gr*c(it+ct*$));if(Kt===ft)return;let br=(jt.x===ct?0:2)|Number(jt.y&ot),yr=Kt;return D&&p(Kt)&&(yr=d(Kt),br^=1),new y(ct,yr,br)}return{seed:Et,k2sig:Qt}}const O={lowS:t.lowS,prehash:!1},M={lowS:t.lowS,prehash:!1};function H(v,A,U=O){const{seed:L,k2sig:q}=C(v,A,U),D=t;return xn(D.hash.outputLen,D.nByteLength,D.hmac)(L,q)}u.BASE._setWindowSize(8);function nt(v,A,U,L=M){var jt;const q=v;if(A=Z("msgHash",A),U=Z("publicKey",U),"strict"in L)throw new Error("options.strict was renamed to lowS");const{lowS:D,prehash:Q}=L;let X,ut;try{if(typeof q=="string"||q instanceof Uint8Array)try{X=y.fromDER(q)}catch(ct){if(!(ct instanceof At.Err))throw ct;X=y.fromCompact(q)}else if(typeof q=="object"&&typeof q.r=="bigint"&&typeof q.s=="bigint"){const{r:ct,s:Kt}=q;X=new y(ct,Kt)}else throw new Error("PARSE");ut=u.fromHex(U)}catch(ct){if(ct.message==="PARSE")throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(D&&X.hasHighS())return!1;Q&&(A=t.hash(A));const{r:$,s:V}=X,Et=k(A),it=a(V),Qt=c(Et*it),It=c($*it),Mt=(jt=u.BASE.multiplyAndAddUnsafe(ut,Qt,It))==null?void 0:jt.toAffine();return Mt?c(Mt.x)===$:!1}return{CURVE:t,getPublicKey:_,getSharedSecret:E,sign:H,verify:nt,ProjectivePoint:u,Signature:y,utils:x}}class On extends pn{constructor(t,n){super(),this.finished=!1,this.destroyed=!1,Wr(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 To(e){return{hash:e,hmac:(t,...n)=>In(e,t,Zr(...n)),randomBytes:gn}}function Co(e,t){const n=r=>No({...e,...To(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,x=rt(y,c,t)*d%t,_=rt(x,n,t)*f%t,S=rt(_,i,t)*p%t,E=rt(S,r,t)*u%t,b=rt(E,le,t);if(!Ue.eql(Ue.sqr(b),e))throw new Error("Cannot find square root");return b}const Ue=Eo(ce,void 0,void 0,{sqrt:Tn}),Wt=Co({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,Ro=e=>typeof e=="bigint"&&ue<e&&e<ae,Rn={};function fe(e,...t){let n=Rn[e];if(n===void 0){const r=Be(Uint8Array.from(e,o=>o.charCodeAt(0)));n=kt(r,r),Rn[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,Po=(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 Pn(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 Uo(e){return je(e).bytes}function Ho(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=Pn(et(s)),c=et(r.subarray(0,32));if(!Cn(c))return!1;const a=et(r.subarray(32,64));if(!Ro(a))return!1;const u=Un(Le(c),He(i),o),f=Po(i,a,Ft(-u));return!(!f||!f.hasEvenY()||f.toAffine().x!==c)}catch{return!1}}const Y={getPublicKey:Uo,sign:Ho,verify:Hn,utils:{randomPrivateKey:Wt.utils.randomPrivateKey,lift_x:Pn,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 Lo(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 qo(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 Mo(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 jo(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:Lo,bytes:Ln,hash:qo,exists:Mo,output:jo};function Ko(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 zo extends Vr{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=Ee(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=Ee(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;Ko(r,o-8,BigInt(this.length*8),s),this.process(r,0);const c=Ee(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 Vo=(e,t,n)=>e&t^~e&n,Do=(e,t,n)=>e&t^e&n^t&n,Wo=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 zo{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+Vo(c,a,u)+Wo[l]+xt[l]|0,d=(at(r,2)^at(r,13)^at(r,22))+Do(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 Fo 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 Fo);var Ht=Symbol("verified"),Go=e=>e instanceof Object;function Zo(e){if(!Go(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 Jo=new TextEncoder,Yo=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 Qo(e){if(!Zo(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(Jo.encode(Qo(e)));return J(t)}var de=new Yo,Xo=de.generateSecretKey;de.getPublicKey,de.finalizeEvent,de.verifyEvent;var Bt=Symbol("verified"),ts=e=>e instanceof Object;function es(e){if(!ts(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 ns=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 rs=class{constructor(t){m(this,"value");m(this,"next",null);m(this,"prev",null);this.value=t}},os=class{constructor(){m(this,"first");m(this,"last");this.first=null,this.last=null}enqueue(t){const n=new rs(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}},ss=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 is(e){if(!es(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(ns.encode(is(e)));return J(t)}var he=new ss;he.generateSecretKey,he.getPublicKey,he.finalizeEvent;var cs=he.verifyEvent,as=22242;function ls(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 us(e,t){for(let n=0;n<e.length;n++)if(ls(e[n],t))return!0;return!1}function fs(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 ds(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 hs(e,t){return{kind:as,created_at:Math.floor(Date.now()/1e3),tags:[["relay",e],["challenge",t]],content:""}}async function ws(){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 ps=e=>(e[Bt]=!0,!0),Mn;try{Mn=WebSocket}catch{}var jn=class{constructor(t,n){m(this,"url");m(this,"_connected",!1);m(this,"onclose",null);m(this,"onnotice",t=>console.debug(`NOTICE from ${this.url}: ${t}`));m(this,"baseEoseTimeout",4400);m(this,"connectionTimeout",4400);m(this,"openSubs",new Map);m(this,"connectionTimeoutHandle");m(this,"connectionPromise");m(this,"openCountRequests",new Map);m(this,"openEventPublishes",new Map);m(this,"ws");m(this,"incomingMessageQueue",new os);m(this,"queueRunning",!1);m(this,"challenge");m(this,"serial",0);m(this,"verifyEvent");this.url=Gt(t),this.verifyEvent=n.verifyEvent}static async connect(t,n){const r=new jn(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 Mn(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 ws();this.queueRunning=!1}handleNext(){var r,o;const t=this.incomingMessageQueue.dequeue();if(!t)return!1;const n=ds(t);if(n){const s=this.openSubs.get(n);if(!s)return;const i=fs(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)&&us(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(hs(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 gs(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()}},gs=class{constructor(t,n,r,o){m(this,"relay");m(this,"id");m(this,"closed",!1);m(this,"eosed",!1);m(this,"filters");m(this,"alreadyHaveEvent");m(this,"receivedEvent");m(this,"onevent");m(this,"oneose");m(this,"onclose");m(this,"eoseTimeout");m(this,"eoseTimeoutHandle");this.relay=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)}},bs=class{constructor(t){m(this,"relays",new Map);m(this,"seenOn",new Map);m(this,"trackRelays",!1);m(this,"verifyEvent");m(this,"trustedRelayURLs",new Set);this.verifyEvent=t.verifyEvent}async ensureRelay(t,n){t=Gt(t);let r=this.relays.get(t);return r||(r=new jn(t,{verifyEvent:this.trustedRelayURLs.has(t)?ps: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))}},ys=class extends bs{constructor(){super({verifyEvent:cs})}};/*! 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 Kn(e){if(typeof e!="function")throw new Error("normalize fn should be function");return{encode:t=>t,decode:t=>e(t)}}function zn(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 Vn=(e,t)=>t?Vn(t,e%t):e,pe=(e,t)=>e+(t-Vn(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 ms(e){return Lt(e),{encode:t=>{if(!(t instanceof Uint8Array))throw new Error("radix.encode input should be Uint8Array");return zn(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(zn(t,e,2**8))}}}function vt(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 Dn(e){if(typeof e!="function")throw new Error("unsafeWrapper fn should be function");return function(...t){try{return e.apply(null,t)}catch{}}}const xs=dt(vt(4),ht("0123456789ABCDEF"),wt("")),vs=dt(vt(5),ht("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"),we(5),wt(""));dt(vt(5),ht("0123456789ABCDEFGHIJKLMNOPQRSTUV"),we(5),wt("")),dt(vt(5),ht("0123456789ABCDEFGHJKMNPQRSTVWXYZ"),wt(""),Kn(e=>e.toUpperCase().replace(/O/g,"0").replace(/[IL]/g,"1")));const Zt=dt(vt(6),ht("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),we(6),wt("")),Es=dt(vt(6),ht("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"),we(6),wt("")),Ge=e=>dt(ms(58),ht(e),wt("")),Ze=Ge("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");Ge("123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"),Ge("rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz");const Wn=[0,2,3,5,6,7,9,10,11],_s={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(Wn[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=Wn.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("")),Fn=[996825010,642813549,513874426,1027748829,705979059];function Jt(e){const t=e>>25;let n=(e&33554431)<<5;for(let r=0;r<Fn.length;r++)(t>>r&1)===1&&(n^=Fn[r]);return n}function Gn(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 Zn(e){const t=e==="bech32"?1:734539939,n=vt(5),r=n.decode,o=n.encode,s=Dn(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)}${Gn(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=Gn(p,g,t);if(!d.endsWith(y))throw new Error(`Invalid checksum in ${f}: expected "${y}"`);return{prefix:p,words:g}}const a=Dn(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 Jn=Zn("bech32");Zn("bech32m");const ks={encode:e=>new TextDecoder().decode(e),decode:e=>new TextEncoder().encode(e)},Ss=dt(vt(4),ht("0123456789abcdef"),wt(""),Kn(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:ks,hex:Ss,base16:xs,base32:vs,base64:Zt,base64url:Es,base58:Ze,base58xmr:_s}).join(", ")}`;var Ot=Symbol("verified"),As=e=>e instanceof Object;function Bs(e){if(!As(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 Os=new TextDecoder("utf-8"),Yn=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 Is=class{constructor(e){m(this,"value");m(this,"next",null);m(this,"prev",null);this.value=e}},$s=class{constructor(){m(this,"first");m(this,"last");this.first=null,this.last=null}enqueue(e){const t=new Is(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}},Ns=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 Ts(e){if(!Bs(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(Yn.encode(Ts(e)));return J(t)}var ge=new Ns,Cs=ge.generateSecretKey,Qn=ge.getPublicKey,Rs=ge.finalizeEvent,Xn=ge.verifyEvent;typeof crypto<"u"&&!crypto.subtle&&crypto.webcrypto&&(crypto.subtle=crypto.webcrypto.subtle);async function Ps(e,t,n){const r=e instanceof Uint8Array?J(e):e,o=Wt.getSharedSecret(r,"02"+t),s=tr(o);let i=Uint8Array.from(Dr(16)),c=Yn.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 Us(e,t,n){const r=e instanceof Uint8Array?J(e):e;let[o,s]=n.split("?iv="),i=Wt.getSharedSecret(r,"02"+t),c=tr(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 Os.decode(l)}function tr(e){return e.slice(1,33)}var Hs=/^(?:([\w.+-]+)@)?([\w_-]+(\.[\w_-]+)+)$/,Ls;try{Ls=fetch}catch{}var qs=22242,Qe=24133,Ms=31990;function js(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 Ks(e,t){for(let n=0;n<e.length;n++)if(js(e[n],t))return!0;return!1}function zs(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 Vs(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 Ds(e,t){return{kind:qs,created_at:Math.floor(Date.now()/1e3),tags:[["relay",e],["challenge",t]],content:""}}async function Ws(){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 Fs=e=>(e[Ot]=!0,!0),er;try{er=WebSocket}catch{}var nr=class{constructor(e,t){m(this,"url");m(this,"_connected",!1);m(this,"onclose",null);m(this,"onnotice",e=>console.debug(`NOTICE from ${this.url}: ${e}`));m(this,"baseEoseTimeout",4400);m(this,"connectionTimeout",4400);m(this,"openSubs",new Map);m(this,"connectionTimeoutHandle");m(this,"connectionPromise");m(this,"openCountRequests",new Map);m(this,"openEventPublishes",new Map);m(this,"ws");m(this,"incomingMessageQueue",new $s);m(this,"queueRunning",!1);m(this,"challenge");m(this,"serial",0);m(this,"verifyEvent");this.url=Yt(e),this.verifyEvent=t.verifyEvent}static async connect(e,t){const n=new nr(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 er(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 Ws();this.queueRunning=!1}handleNext(){var n,r;const e=this.incomingMessageQueue.dequeue();if(!e)return!1;const t=Vs(e);if(t){const o=this.openSubs.get(t);if(!o)return;const s=zs(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)&&Ks(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(Ds(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 Gs(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()}},Gs=class{constructor(e,t,n,r){m(this,"relay");m(this,"id");m(this,"closed",!1);m(this,"eosed",!1);m(this,"filters");m(this,"alreadyHaveEvent");m(this,"receivedEvent");m(this,"onevent");m(this,"oneose");m(this,"onclose");m(this,"eoseTimeout");m(this,"eoseTimeoutHandle");this.relay=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)}},Zs=class{constructor(e){m(this,"relays",new Map);m(this,"seenOn",new Map);m(this,"trackRelays",!1);m(this,"verifyEvent");m(this,"trustedRelayURLs",new Set);this.verifyEvent=e.verifyEvent}async ensureRelay(e,t){e=Yt(e);let n=this.relays.get(e);return n||(n=new nr(e,{verifyEvent:this.trustedRelayURLs.has(e)?Fs: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))}},Js=class extends Zs{constructor(){super({verifyEvent:Xn})}},rr;try{rr=fetch}catch{}var Ys=/^bunker:\/\/([0-9a-f]{64})\??([?\/\w:.=&%]*)$/,Qs=/^[^\s@]+@[^\s@]+\.[^\s@]+$/;async function Xs(e){let t=e.match(Ys);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 or(e)}async function or(e){const t=e.match(Hs);if(!t)return null;const[n,r="_",o]=t;try{const s=`https://${o}/.well-known/nostr.json?name=${r}`,i=await(await rr(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={}){m(this,"pool");m(this,"subCloser");m(this,"isOpen");m(this,"serial");m(this,"idPrefix");m(this,"listeners");m(this,"waitingForAuth");m(this,"secretKey");m(this,"bp");if(t.relays.length===0)throw new Error("no relays are specified for this bunker");this.pool=n.pool||new Js,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":[Qn(this.secretKey)]}],{async onevent(s){const{id:i,result:c,error:a}=JSON.parse(await Us(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 Ps(this.secretKey,this.bp.pubkey,JSON.stringify({id:o,method:e,params:t})),i=Rs({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",[Qn(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&&Xn(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 ti(e,t,n,r,o){if(o&&!Qs.test(o))throw new Error("Invalid email");let s=Cs(),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 ei(e,t){const n=await e.querySync(t,{kinds:[Ms],"#k":[Qe.toString()]});return(await Promise.all(n.map(async o=>{try{const s=JSON.parse(o.content),i=await or(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 ni=/^(?:([\w.+-]+)@)?([\w_-]+(\.[\w_-]+)+)$/,sr;try{sr=fetch}catch{}async function ri(e){var s;const t=e.match(ni);if(!t)return null;const[n,r="_",o]=t;try{const i=`https://${o}/.well-known/nostr.json?name=${r}`,c=await(await sr(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 oi=5e3;function si(e){return ci("npub",_e(e))}function ii(e,t){let n=Jn.toWords(t);return Jn.encode(e,n,oi)}function ci(e,t){return ii(e,t)}const{window:ai}=vr;function ir(e,t,n){const r=e.slice();return r[37]=t[n],r}function li(e){let t,n,r,o,s,i,c,a;function u(h,w){if(h[9])return hi;if(!h[10])return di;if(h[10])return fi}let f=u(e),l=f&&f(e);return{c(){t=N("div"),n=N("button"),r=tt("⤫"),s=j(),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){P(h,t,w),R(t,n),R(n,r),R(t,s),l&&l.m(t,null),c||(a=st(n,"click",e[13]),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&&T(t),l&&l.d(),c=!1,a()}}}function ui(e){let t,n;function r(i,c){return i[8]?gi:i[10]?wi:pi}let o=r(e),s=o(e);return{c(){t=N("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){P(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&&T(t),s.d()}}}function fi(e){let t,n,r,o,s,i,c=e[10].npub+"",a,u,f,l,h,w,p,d,g,y,x,_,S,E,b=(e[10].picture||e[10].name)&&cr(e);return{c(){t=N("div"),n=N("div"),n.textContent="You are currently connect to Nostr as",r=j(),o=N("a"),b&&b.c(),s=j(),i=N("div"),a=tt(c),f=j(),l=N("button"),h=tt("Disconnect"),p=j(),d=N("div"),g=tt("The bunker public key is:"),y=N("br"),x=j(),_=tt(e[6]),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(k,I){P(k,t,I),R(t,n),R(t,r),R(t,o),b&&b.m(o,null),R(o,s),R(o,i),R(i,a),P(k,f,I),P(k,l,I),R(l,h),P(k,p,I),P(k,d,I),R(d,g),R(d,y),R(d,x),R(d,_),S||(E=st(l,"click",e[15]),S=!0)},p(k,I){k[10].picture||k[10].name?b?b.p(k,I):(b=cr(k),b.c(),b.m(o,s)):b&&(b.d(1),b=null),I[0]&1024&&c!==(c=k[10].npub+"")&&ee(a,c),I[0]&1024&&u!==(u="https://nosta.me/"+k[10].npub)&&B(o,"href",u),I[0]&1&&w!==(w="tw-block tw-w-full tw-my-2 tw-mt-6 tw-px-2 tw-py-1 tw-text-lg tw-rounded tw-border-0 tw-bg-"+k[0]+"-900 hover:tw-bg-"+k[0]+"-950 tw-hover:bg-indigo-900 tw-cursor-pointer tw-text-white")&&B(l,"class",w),I[0]&64&&ee(_,k[6])},d(k){k&&(T(t),T(f),T(l),T(p),T(d)),b&&b.d(),S=!1,E()}}}function di(e){let t,n,r,o,s,i,c,a,u,f,l,h,w,p,d,g,y;return{c(){t=N("div"),t.textContent="How do you want to connect to Nostr?",n=j(),r=N("form"),o=N("input"),s=j(),i=N("button"),c=tt("Connect »"),f=j(),l=N("div"),h=tt("Do you need a Nostr account?"),w=N("br"),p=j(),d=N("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[2],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(x,_){P(x,t,_),P(x,n,_),P(x,r,_),R(r,o),e[23](o),Nt(o,e[2]),R(r,s),R(r,i),R(i,c),P(x,f,_),P(x,l,_),R(l,h),R(l,w),R(l,p),R(l,d),o.focus(),g||(y=[st(o,"input",e[24]),st(r,"submit",e[14]),st(d,"click",e[16])],g=!0)},p(x,_){_[0]&4&&o.value!==x[2]&&Nt(o,x[2]),_[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-"+x[0]+"-900 hover:tw-bg-"+x[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),_[0]&4&&u!==(u=!x[2])&&(i.disabled=u)},d(x){x&&(T(t),T(n),T(r),T(f),T(l)),e[23](null),g=!1,$t(y)}}}function hi(e){let t,n,r,o,s,i,c,a,u,f,l,h,w,p,d,g,y,x,_,S,E,b,k,I,K=cn(e[11]),C=[];for(let O=0;O<K.length;O+=1)C[O]=ur(ir(e,K,O));return{c(){t=N("div"),t.textContent="Create a Nostr account",n=j(),r=N("form"),o=N("div"),s=N("input"),i=j(),c=N("div"),c.textContent="@",a=j(),u=N("select");for(let O=0;O<C.length;O+=1)C[O].c();f=j(),l=N("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=j(),w=N("button"),p=tt("Create »"),y=j(),x=N("div"),_=tt("Do you already have a Nostr address?"),S=N("br"),E=j(),b=N("button"),b.textContent="Login now",B(t,"class","tw-text-lg tw-text-center"),B(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"),B(s,"placeholder","bob"),s.autofocus=!0,B(c,"class","tw-mx-2 tw-text-2xl"),B(u,"class","tw-w-full tw-box-border tw-px-2 tw-py-1 tw-rounded tw-text-lg tw-border-none tw-outline-none"),e[5]===void 0&&re(()=>e[22].call(u)),B(o,"class","tw-flex items-center"),B(l,"class","tw-text-sm tw-text-center tw-mt-4 tw-leading-4"),B(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-"+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"),w.disabled=g=!e[5]||!e[4],B(r,"class","tw-mt-4 tw-mb-1"),B(b,"class","tw-border-0 tw-bg-transparent tw-text-white tw-cursor-pointer tw-underline tw-text-sm"),B(x,"class","tw-mt-6 tw-text-center tw-text-sm tw-leading-3")},m(O,M){P(O,t,M),P(O,n,M),P(O,r,M),R(r,o),R(o,s),e[20](s),Nt(s,e[4]),R(o,i),R(o,c),R(o,a),R(o,u);for(let H=0;H<C.length;H+=1)C[H]&&C[H].m(u,null);nn(u,e[5],!0),R(r,f),R(r,l),R(r,h),R(r,w),R(w,p),P(O,y,M),P(O,x,M),R(x,_),R(x,S),R(x,E),R(x,b),s.focus(),k||(I=[st(s,"input",e[21]),st(s,"input",e[19]),st(u,"change",e[22]),st(r,"submit",e[18]),st(b,"click",e[17])],k=!0)},p(O,M){if(M[0]&16&&s.value!==O[4]&&Nt(s,O[4]),M[0]&2048){K=cn(O[11]);let H;for(H=0;H<K.length;H+=1){const nt=ir(O,K,H);C[H]?C[H].p(nt,M):(C[H]=ur(nt),C[H].c(),C[H].m(u,null))}for(;H<C.length;H+=1)C[H].d(1);C.length=K.length}M[0]&2080&&nn(u,O[5]),M[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-"+O[0]+"-900 hover:tw-bg-"+O[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(w,"class",d),M[0]&2096&&g!==(g=!O[5]||!O[4])&&(w.disabled=g)},d(O){O&&(T(t),T(n),T(r),T(y),T(x)),e[20](null),Er(C,O),k=!1,$t(I)}}}function cr(e){let t,n,r=e[10].picture&&ar(e),o=e[10].name&&lr(e);return{c(){t=N("div"),r&&r.c(),n=j(),o&&o.c(),B(t,"class","tw-flex tw-items-center tw-justify-center tw-gap-2 tw-mb-2")},m(s,i){P(s,t,i),r&&r.m(t,null),R(t,n),o&&o.m(t,null)},p(s,i){s[10].picture?r?r.p(s,i):(r=ar(s),r.c(),r.m(t,n)):r&&(r.d(1),r=null),s[10].name?o?o.p(s,i):(o=lr(s),o.c(),o.m(t,null)):o&&(o.d(1),o=null)},d(s){s&&T(t),r&&r.d(),o&&o.d()}}}function ar(e){let t,n,r;return{c(){t=N("img"),te(t.src,n=e[10].picture)||B(t,"src",n),B(t,"alt",""),B(t,"class",r="tw-w-10 tw-h-10 tw-rounded-full tw-border-solid tw-border-2 tw-border-transparent group-hover:tw-border-"+e[0]+"-100")},m(o,s){P(o,t,s)},p(o,s){s[0]&1024&&!te(t.src,n=o[10].picture)&&B(t,"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")&&B(t,"class",r)},d(o){o&&T(t)}}}function lr(e){let t,n=e[10].name+"",r;return{c(){t=N("div"),r=tt(n),B(t,"class","tw-text-3xl group-hover:tw-underline tw-decoration-2 tw-underline-offset-4")},m(o,s){P(o,t,s),R(t,r)},p(o,s){s[0]&1024&&n!==(n=o[10].name+"")&&ee(r,n)},d(o){o&&T(t)}}}function ur(e){let t,n,r;return{c(){t=N("option"),B(t,"label",n=e[37].domain),t.__value=r=e[37],Nt(t,t.__value),B(t,"class","tw-px-2 tw-py-1 tw-text-lg")},m(o,s){P(o,t,s)},p(o,s){s[0]&2048&&n!==(n=o[37].domain)&&B(t,"label",n),s[0]&2048&&r!==(r=o[37])&&(t.__value=r,Nt(t,t.__value))},d(o){o&&T(t)}}}function wi(e){let t,n,r=(e[10].name||e[10].npub.slice(0,7)+"…"+e[10].npub.slice(-4))+"",o;function s(a,u){return a[10].picture?yi:bi}let i=s(e),c=i(e);return{c(){t=N("div"),c.c(),n=j(),o=tt(r),B(t,"class","tw-flex tw-items-center")},m(a,u){P(a,t,u),c.m(t,null),R(t,n),R(t,o)},p(a,u){i===(i=s(a))&&c?c.p(a,u):(c.d(1),c=i(a),c&&(c.c(),c.m(t,n))),u[0]&1024&&r!==(r=(a[10].name||a[10].npub.slice(0,7)+"…"+a[10].npub.slice(-4))+"")&&ee(o,r)},d(a){a&&T(t),c.d()}}}function pi(e){let t;return{c(){t=tt("Login with Nostr")},m(n,r){P(n,t,r)},p:G,d(n){n&&T(t)}}}function gi(e){let t;return{c(){t=N("div"),t.textContent="Connecting to bunker..."},m(n,r){P(n,t,r)},p:G,d(n){n&&T(t)}}}function bi(e){let t;return{c(){t=tt("☉")},m(n,r){P(n,t,r)},p:G,d(n){n&&T(t)}}}function yi(e){let t,n;return{c(){t=N("img"),te(t.src,n=e[10].picture)||B(t,"src",n),B(t,"alt",""),B(t,"class","tw-w-5 tw-h-5 tw-rounded-full tw-mr-2")},m(r,o){P(r,t,o)},p(r,o){o[0]&1024&&!te(t.src,n=r[10].picture)&&B(t,"src",n)},d(r){r&&T(t)}}}function mi(e){let t,n,r,o,s,i,c,a,u,f,l,h,w,p,d,g,y;function x(E,b){return E[7]?li:ui}let _=x(e),S=_(e);return{c(){t=N("div"),S.c(),n=j(),r=N("div"),o=j(),s=N("div"),i=j(),c=N("div"),a=j(),u=N("div"),f=j(),l=N("div"),h=j(),w=N("div"),p=j(),d=N("div"),B(t,"class","tw-text-white tw-font-sans"),rn(t,"tw-cursor-pointer",!e[10]&&!e[7]),B(r,"class","hidden tw-bg-cyan-700 tw-bg-cyan-800 tw-bg-cyan-900 tw-bg-cyan-950 tw-text-cyan-950"),B(s,"class","hidden tw-bg-green-700 tw-bg-green-800 tw-bg-green-900 tw-bg-green-950 tw-text-green-950"),B(c,"class","hidden tw-bg-purple-700 tw-bg-purple-800 tw-bg-purple-900 tw-bg-purple-950 tw-text-purple-950"),B(u,"class","hidden tw-bg-red-700 tw-bg-red-800 tw-bg-red-900 tw-bg-red-950 tw-text-red-950"),B(l,"class","hidden tw-bg-orange-700 tw-bg-orange-800 tw-bg-orange-900 tw-bg-orange-950 tw-text-orange-950"),B(w,"class","hidden tw-bg-neutral-700 tw-bg-neutral-800 tw-bg-neutral-900 tw-bg-neutral-950 tw-text-neutral-950"),B(d,"class","hidden tw-bg-stone-700 tw-bg-stone-800 tw-bg-stone-900 tw-bg-stone-950 tw-text-stone-950")},m(E,b){P(E,t,b),S.m(t,null),P(E,n,b),P(E,r,b),P(E,o,b),P(E,s,b),P(E,i,b),P(E,c,b),P(E,a,b),P(E,u,b),P(E,f,b),P(E,l,b),P(E,h,b),P(E,w,b),P(E,p,b),P(E,d,b),g||(y=st(ai,"click",e[12]),g=!0)},p(E,b){_===(_=x(E))&&S?S.p(E,b):(S.d(1),S=_(E),S&&(S.c(),S.m(t,null))),b[0]&1152&&rn(t,"tw-cursor-pointer",!E[10]&&!E[7])},i:G,o:G,d(E){E&&(T(t),T(n),T(r),T(o),T(s),T(i),T(c),T(a),T(u),T(f),T(l),T(h),T(w),T(p),T(d)),S.d(),g=!1,y()}}}function xi(e,t,n){let{accent:r}=t;const o=window,s=new ys;let i,c,a,u,f,l,h;const w=localStorage.getItem("nip46ClientSecretKey");w?l=_e(w):(l=Xo(),localStorage.setItem("nip46ClientSecretKey",J(l)));let p,d,g,y,x,_,S,E,b=[];I();let k={isWnj:!0,async getPublicKey(){return!x&&!S&&n(7,p=!0),(await y).bp.pubkey},async signEvent($){return!x&&!S&&n(7,p=!0),(await y).signEvent($)},async getRelays(){return!x&&!S&&n(7,p=!0),(await y).getRelays()},nip04:{async encrypt($,V){return!x&&!S&&n(7,p=!0),(await y).nip04Encrypt($,V)},async decrypt($,V){return!x&&!S&&n(7,p=!0),(await y).nip04Decrypt($,V)}}};function I(){n(7,p=!1),d=null,y=new Promise($=>{g=$}),n(8,x=!1),n(9,_=!1),n(10,S=null),E=null}const K={pool:s,onauth($){window.open($,"window.nostr","width=600,height=800,popup=yes")}};Ar(()=>{let $=localStorage.getItem("nip46BunkerPointer");if($&&(d=JSON.parse($),n(8,x=!0),L(new Xe(l,d,K))),o.nostr&&!o.nostr.isWnj){o.destroyWnj();return}else Object.defineProperty(window,"nostr",{get(){return k},set(V){k=V,V.isWnj||o.destroyWnj()},configurable:!0});return()=>{E&&E.close()}});function C($){$.composedPath().find(V=>V.id==="windowNostrModal")?n(7,p=!0):n(7,p=!1)}function O($){n(7,p=!1),n(9,_=!1),$.stopPropagation()}async function M($){if($.preventDefault(),d=await Xs(i.value),!d){i.setCustomValidity('invalid NIP-05 "name@domain.com" address or bunker:// URI');return}i.setCustomValidity(""),L(new Xe(l,d,K))}async function H($){$.preventDefault(),localStorage.removeItem("nip46BunkerPointer"),o.isWnj&&delete o.nostr,I()}async function nt($){$.preventDefault(),n(9,_=!0),b.length===0&&(n(11,b=await ei(s,["wss://relay.nostr.band"])),n(5,f=b[0]))}function v($){n(9,_=!1)}async function A($){if($.preventDefault(),!f)return;let V=await ti(f,K,a.value,f.domain);n(7,p=!0),n(9,_=!1),L(V)}const U=jr(async()=>{f&&a.value.length>0&&(await ri(a.value+"@"+f.domain)?a.setCustomValidity(`'${a.value}' is already taken.`):a.setCustomValidity(""))},500);async function L($){await $.connect(),n(10,S={pubkey:$.bp.pubkey,npub:si($.bp.pubkey),event:null}),n(8,x=!1),localStorage.setItem("nip46BunkerPointer",JSON.stringify(d)),typeof(d==null?void 0:d.pubkey)=="string"&&n(6,h=d==null?void 0:d.pubkey),E=s.subscribeMany(["wss://purplepag.es","wss://relay.snort.social","wss://relay.nos.social"],[{kinds:[0],authors:[$.bp.pubkey]}],{onevent(V){var Et;if(!((((Et=S.event)==null?void 0:Et.created_at)||0)>=V.created_at))try{let{name:it,picture:Qt}=JSON.parse(V.content);n(10,S.event=V,S),n(10,S.name=it,S),n(10,S.picture=Qt,S)}catch{}}}),n(7,p=!1),g($)}function q($){ne[$?"unshift":"push"](()=>{a=$,n(3,a)})}function D(){u=this.value,n(4,u)}function Q(){f=kr(this),n(5,f),n(11,b)}function X($){ne[$?"unshift":"push"](()=>{i=$,n(1,i)})}function ut(){c=this.value,n(2,c)}return e.$$set=$=>{"accent"in $&&n(0,r=$.accent)},[r,i,c,a,u,f,h,p,x,_,S,b,C,O,M,H,nt,v,A,U,q,D,Q,X,ut]}class vi extends Hr{constructor(t){super(),Ur(this,t,xi,mi,mr,{accent:0},null,[-1,-1])}}const fr=window,qt=document.createElement("div");qt.style.position="fixed",qt.style.right="1.5rem",((wr=fr.wnjParams)==null?void 0:wr.position)==="bottom"?qt.style.bottom="1.5rem":qt.style.top="1.5rem",document.body.appendChild(qt);const be=document.createElement("div");be.id="windowNostrModal",be.classList.add("tw-animate-fadein");const dr=document.createElement("style");dr.innerHTML=_t;const hr=qt.attachShadow({mode:"open"});hr.appendChild(be),hr.appendChild(dr);const Ei=new vi({target:be,props:{accent:((pr=fr.wnjParams)==null?void 0:pr.accent)||"cyan"}});window.destroyWnj=()=>{Ei.$destroy()}})();
|
package/index.html
CHANGED
|
@@ -60,6 +60,12 @@
|
|
|
60
60
|
molestie risus rutrum ut. Proin dictum nunc at rutrum vehicula.
|
|
61
61
|
</p>
|
|
62
62
|
</main>
|
|
63
|
+
<!-- <script>
|
|
64
|
+
window.windowNostrJsParams = {
|
|
65
|
+
position: 'bottom',
|
|
66
|
+
accent: 'green' // Supported values: cyan (default), green, purple, red, orange, neutral, stone
|
|
67
|
+
}
|
|
68
|
+
</script> -->
|
|
63
69
|
<script type="module" src="/src/main.ts"></script>
|
|
64
70
|
</body>
|
|
65
71
|
</html>
|
package/package.json
CHANGED
package/src/App.svelte
CHANGED
|
@@ -20,12 +20,17 @@
|
|
|
20
20
|
import {npubEncode} from 'nostr-tools/nip19'
|
|
21
21
|
import {onMount} from 'svelte'
|
|
22
22
|
|
|
23
|
+
export let accent: string
|
|
24
|
+
|
|
23
25
|
const win = window as any
|
|
24
26
|
const pool = new SimplePool()
|
|
25
27
|
let bunkerInput: HTMLInputElement
|
|
28
|
+
let bunkerInputValue: string
|
|
26
29
|
let nameInput: HTMLInputElement
|
|
30
|
+
let nameInputValue: string
|
|
27
31
|
let chosenProvider: BunkerProfile | undefined
|
|
28
32
|
let clientSecret: Uint8Array
|
|
33
|
+
let nip46BunkerPointer: string
|
|
29
34
|
const local = localStorage.getItem('nip46ClientSecretKey')
|
|
30
35
|
if (local) {
|
|
31
36
|
clientSecret = hexToBytes(local)
|
|
@@ -173,8 +178,14 @@
|
|
|
173
178
|
async function handleOpenCreate(ev: MouseEvent) {
|
|
174
179
|
ev.preventDefault()
|
|
175
180
|
creating = true
|
|
176
|
-
if (providers.length === 0)
|
|
181
|
+
if (providers.length === 0) {
|
|
177
182
|
providers = await fetchCustodialBunkers(pool, ['wss://relay.nostr.band'])
|
|
183
|
+
chosenProvider = providers[0]
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function handleOpenLogin(_: MouseEvent) {
|
|
188
|
+
creating = false
|
|
178
189
|
}
|
|
179
190
|
|
|
180
191
|
async function handleCreate(ev: SubmitEvent) {
|
|
@@ -215,6 +226,9 @@
|
|
|
215
226
|
connecting = false
|
|
216
227
|
|
|
217
228
|
localStorage.setItem('nip46BunkerPointer', JSON.stringify(bunkerPointer))
|
|
229
|
+
if (typeof bunkerPointer?.pubkey === 'string') {
|
|
230
|
+
nip46BunkerPointer = bunkerPointer?.pubkey
|
|
231
|
+
}
|
|
218
232
|
|
|
219
233
|
// load metadata
|
|
220
234
|
metadataSub = pool.subscribeMany(
|
|
@@ -253,7 +267,7 @@
|
|
|
253
267
|
<!-- Close status ################### -->
|
|
254
268
|
{#if !opened}
|
|
255
269
|
<div
|
|
256
|
-
class="tw-px-4 tw-py-2 tw-
|
|
270
|
+
class="tw-px-4 tw-py-2 tw-bg-{accent}-700 hover:tw-bg-{accent}-800 tw-rounded tw-cursor-pointer tw-shadow-[0_0px_10px_0px_rgba(0,0,0,0.3)]"
|
|
257
271
|
>
|
|
258
272
|
<!-- Connecting view ################### -->
|
|
259
273
|
{#if connecting}
|
|
@@ -280,23 +294,26 @@
|
|
|
280
294
|
<!-- Open status ################### -->
|
|
281
295
|
{:else}
|
|
282
296
|
<div
|
|
283
|
-
class="tw-w-80 tw-px-6 tw-py-8 tw-
|
|
297
|
+
class="tw-w-80 tw-px-6 tw-py-8 tw-bg-{accent}-700 tw-rounded-md tw-shadow-[0_0px_30px_0px_rgba(0,0,0,0.6)] tw-transition-all tw-animate-show"
|
|
284
298
|
>
|
|
285
299
|
<button
|
|
286
300
|
on:click={handleCloseModal}
|
|
287
|
-
class="tw-absolute tw-top-0 tw-right-0.5 tw-bg-transparent tw-border-none tw-cursor-pointer tw-text-
|
|
301
|
+
class="tw-absolute tw-top-0 tw-right-0.5 tw-bg-transparent tw-border-none tw-cursor-pointer tw-text-{accent}-950 tw-text-3xl"
|
|
288
302
|
>⤫</button
|
|
289
303
|
>
|
|
290
304
|
<!-- Create account view ################### -->
|
|
291
305
|
{#if creating}
|
|
292
|
-
<div class="tw-text-lg tw-text-center">Create a
|
|
306
|
+
<div class="tw-text-lg tw-text-center">Create a Nostr account</div>
|
|
293
307
|
<form class="tw-mt-4 tw-mb-1" on:submit={handleCreate}>
|
|
294
308
|
<div class="tw-flex items-center">
|
|
309
|
+
<!-- svelte-ignore a11y-autofocus -->
|
|
295
310
|
<input
|
|
296
|
-
class="tw-box-border tw-w-
|
|
311
|
+
class="tw-box-border tw-w-40 tw-px-2 tw-py-1 tw-rounded tw-text-lg tw-border-none tw-outline-none"
|
|
297
312
|
placeholder="bob"
|
|
298
313
|
bind:this={nameInput}
|
|
314
|
+
bind:value={nameInputValue}
|
|
299
315
|
on:input={checkNameInput}
|
|
316
|
+
autofocus
|
|
300
317
|
/>
|
|
301
318
|
<div class="tw-mx-2 tw-text-2xl">@</div>
|
|
302
319
|
<select
|
|
@@ -312,12 +329,24 @@
|
|
|
312
329
|
{/each}
|
|
313
330
|
</select>
|
|
314
331
|
</div>
|
|
332
|
+
<div class="tw-text-sm tw-text-center tw-mt-4 tw-leading-4">
|
|
333
|
+
A window from the selected provider will pop up to finalize the
|
|
334
|
+
creation; if it doesn't display check if the browser is blocking it
|
|
335
|
+
</div>
|
|
315
336
|
<button
|
|
316
|
-
class="tw-block tw-w-full tw-mt-4 tw-px-2 tw-py-1 tw-text-lg tw-rounded tw-border-0 tw-bg-
|
|
337
|
+
class="tw-block tw-w-full tw-mt-4 tw-px-2 tw-py-1 tw-text-lg tw-rounded tw-border-0 tw-bg-{accent}-900 hover:tw-bg-{accent}-950 tw-hover:bg-indigo-900 tw-cursor-pointer tw-text-white disabled:tw-bg-neutral-400 disabled:tw-text-neutral-200 disabled:tw-cursor-default"
|
|
338
|
+
disabled={!chosenProvider || !nameInputValue}
|
|
317
339
|
>
|
|
318
|
-
|
|
340
|
+
Create »
|
|
319
341
|
</button>
|
|
320
342
|
</form>
|
|
343
|
+
<div class="tw-mt-6 tw-text-center tw-text-sm tw-leading-3">
|
|
344
|
+
Do you already have a Nostr address?<br />
|
|
345
|
+
<button
|
|
346
|
+
class="tw-border-0 tw-bg-transparent tw-text-white tw-cursor-pointer tw-underline tw-text-sm"
|
|
347
|
+
on:click={handleOpenLogin}>Login now</button
|
|
348
|
+
>
|
|
349
|
+
</div>
|
|
321
350
|
|
|
322
351
|
<!-- Login view ################### -->
|
|
323
352
|
{:else if !connected}
|
|
@@ -325,29 +354,35 @@
|
|
|
325
354
|
How do you want to connect to Nostr?
|
|
326
355
|
</div>
|
|
327
356
|
<form class="flex tw-mt-4 tw-mb-1" on:submit={handleConnect}>
|
|
357
|
+
<!-- svelte-ignore a11y-autofocus -->
|
|
328
358
|
<input
|
|
329
359
|
class="tw-box-border tw-w-full tw-px-2 tw-py-1 tw-rounded tw-text-lg tw-border-none tw-outline-none"
|
|
330
360
|
placeholder="user@provider or bunker://..."
|
|
331
361
|
bind:this={bunkerInput}
|
|
362
|
+
bind:value={bunkerInputValue}
|
|
363
|
+
autofocus
|
|
332
364
|
/>
|
|
333
365
|
<button
|
|
334
|
-
class="tw-block tw-w-full tw-mt-4 tw-px-2 tw-py-1 tw-text-lg tw-rounded tw-border-0 tw-bg-
|
|
366
|
+
class="tw-block tw-w-full tw-mt-4 tw-px-2 tw-py-1 tw-text-lg tw-rounded tw-border-0 tw-bg-{accent}-900 hover:tw-bg-{accent}-950 tw-hover:bg-indigo-900 tw-cursor-pointer tw-text-white disabled:tw-bg-neutral-400 disabled:tw-text-neutral-200 disabled:tw-cursor-default"
|
|
367
|
+
disabled={!bunkerInputValue}
|
|
335
368
|
>
|
|
336
369
|
Connect »
|
|
337
370
|
</button>
|
|
338
371
|
</form>
|
|
339
372
|
<div class="tw-mt-6 tw-text-center tw-text-sm tw-leading-3">
|
|
340
|
-
Do you need a Nostr account
|
|
373
|
+
Do you need a Nostr account?<br />
|
|
341
374
|
<button
|
|
342
375
|
class="tw-border-0 tw-bg-transparent tw-text-white tw-cursor-pointer tw-underline tw-text-sm"
|
|
343
|
-
on:click={handleOpenCreate}>
|
|
376
|
+
on:click={handleOpenCreate}>Sign up now</button
|
|
344
377
|
>
|
|
345
378
|
</div>
|
|
346
379
|
|
|
347
380
|
<!-- Connected view ################### -->
|
|
348
381
|
{:else if connected}
|
|
349
382
|
<div class="tw-text-center">
|
|
350
|
-
<div class="tw-text-
|
|
383
|
+
<div class="tw-text-sm tw-mb-4">
|
|
384
|
+
You are currently connect to Nostr as
|
|
385
|
+
</div>
|
|
351
386
|
<a
|
|
352
387
|
target="_blank"
|
|
353
388
|
href={'https://nosta.me/' + connected.npub}
|
|
@@ -361,7 +396,7 @@
|
|
|
361
396
|
<img
|
|
362
397
|
src={connected.picture}
|
|
363
398
|
alt=""
|
|
364
|
-
class="tw-w-10 tw-h-10 tw-rounded-full tw-border-solid tw-border-2 tw-border-transparent group-hover:tw-border-
|
|
399
|
+
class="tw-w-10 tw-h-10 tw-rounded-full tw-border-solid tw-border-2 tw-border-transparent group-hover:tw-border-{accent}-100"
|
|
365
400
|
/>
|
|
366
401
|
{/if}
|
|
367
402
|
{#if connected.name}
|
|
@@ -377,10 +412,36 @@
|
|
|
377
412
|
</a>
|
|
378
413
|
</div>
|
|
379
414
|
<button
|
|
380
|
-
class="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-
|
|
415
|
+
class="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-{accent}-900 hover:tw-bg-{accent}-950 tw-hover:bg-indigo-900 tw-cursor-pointer tw-text-white"
|
|
381
416
|
on:click={handleDisconnect}>Disconnect</button
|
|
382
417
|
>
|
|
418
|
+
<div class="tw-block tw-break-all tw-mt-6 tw-text-center tw-text-sm">
|
|
419
|
+
The bunker public key is:<br />
|
|
420
|
+
{nip46BunkerPointer}
|
|
421
|
+
</div>
|
|
383
422
|
{/if}
|
|
384
423
|
</div>
|
|
385
424
|
{/if}
|
|
386
425
|
</div>
|
|
426
|
+
<!-- Hack to preload tailwind colors -->
|
|
427
|
+
<div
|
|
428
|
+
class="hidden tw-bg-cyan-700 tw-bg-cyan-800 tw-bg-cyan-900 tw-bg-cyan-950 tw-text-cyan-950"
|
|
429
|
+
></div>
|
|
430
|
+
<div
|
|
431
|
+
class="hidden tw-bg-green-700 tw-bg-green-800 tw-bg-green-900 tw-bg-green-950 tw-text-green-950"
|
|
432
|
+
></div>
|
|
433
|
+
<div
|
|
434
|
+
class="hidden tw-bg-purple-700 tw-bg-purple-800 tw-bg-purple-900 tw-bg-purple-950 tw-text-purple-950"
|
|
435
|
+
></div>
|
|
436
|
+
<div
|
|
437
|
+
class="hidden tw-bg-red-700 tw-bg-red-800 tw-bg-red-900 tw-bg-red-950 tw-text-red-950"
|
|
438
|
+
></div>
|
|
439
|
+
<div
|
|
440
|
+
class="hidden tw-bg-orange-700 tw-bg-orange-800 tw-bg-orange-900 tw-bg-orange-950 tw-text-orange-950"
|
|
441
|
+
></div>
|
|
442
|
+
<div
|
|
443
|
+
class="hidden tw-bg-neutral-700 tw-bg-neutral-800 tw-bg-neutral-900 tw-bg-neutral-950 tw-text-neutral-950"
|
|
444
|
+
></div>
|
|
445
|
+
<div
|
|
446
|
+
class="hidden tw-bg-stone-700 tw-bg-stone-800 tw-bg-stone-900 tw-bg-stone-950 tw-text-stone-950"
|
|
447
|
+
></div>
|
package/src/main.ts
CHANGED
|
@@ -1,22 +1,48 @@
|
|
|
1
|
-
import './app.css'
|
|
1
|
+
import styles from './app.css?inline'
|
|
2
2
|
import App from './App.svelte'
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
4
|
+
// To customize the widget add this code before the <script src='...' inclusion
|
|
5
|
+
// --- --- --- --- --- --- --- --- ---
|
|
6
|
+
// <script>
|
|
7
|
+
// window.wnjParams = {
|
|
8
|
+
// position: 'bottom'
|
|
9
|
+
// accent: 'green' // Supported values: cyan (default), green, purple, red, orange, neutral, stone
|
|
10
|
+
// }
|
|
11
|
+
// </script>
|
|
12
|
+
|
|
13
|
+
const win = window as any
|
|
14
|
+
|
|
15
|
+
const base = document.createElement('div')
|
|
16
|
+
base.style.position = 'fixed'
|
|
17
|
+
base.style.right = '1.5rem'
|
|
18
|
+
if (win.wnjParams?.position === 'bottom') {
|
|
19
|
+
base.style.bottom = '1.5rem'
|
|
20
|
+
} else {
|
|
21
|
+
base.style.top = '1.5rem'
|
|
22
|
+
}
|
|
23
|
+
document.body.appendChild(base)
|
|
24
|
+
|
|
25
|
+
const mountPoint = document.createElement('div')
|
|
26
|
+
mountPoint.id = 'windowNostrModal'
|
|
27
|
+
mountPoint.classList.add('tw-animate-fadein')
|
|
28
|
+
|
|
29
|
+
const style = document.createElement('style')
|
|
30
|
+
style.innerHTML = styles
|
|
31
|
+
|
|
32
|
+
const shadowRoot = base.attachShadow({mode: 'open'})
|
|
33
|
+
shadowRoot.appendChild(mountPoint)
|
|
34
|
+
shadowRoot.appendChild(style)
|
|
12
35
|
|
|
13
36
|
const app = new App({
|
|
14
|
-
target:
|
|
37
|
+
target: mountPoint,
|
|
38
|
+
props: {
|
|
39
|
+
accent: win.wnjParams?.accent || 'cyan'
|
|
40
|
+
}
|
|
15
41
|
})
|
|
16
42
|
|
|
17
43
|
export default app
|
|
18
44
|
|
|
19
45
|
// ~
|
|
20
|
-
;(window as any).destroyWnj= () => {
|
|
46
|
+
;(window as any).destroyWnj = () => {
|
|
21
47
|
app.$destroy()
|
|
22
48
|
}
|
package/tailwind.config.js
CHANGED
|
@@ -2,7 +2,23 @@
|
|
|
2
2
|
export default {
|
|
3
3
|
content: ['./src/**/*.{html,js,ts,svelte}'],
|
|
4
4
|
theme: {
|
|
5
|
-
extend: {
|
|
5
|
+
extend: {
|
|
6
|
+
animation: {
|
|
7
|
+
fadein: 'fadeIn 1s ease-in-out, moveIn 1s ease-in-out',
|
|
8
|
+
show: 'fadeIn 200ms ease-in-out',
|
|
9
|
+
},
|
|
10
|
+
// that is actual animation
|
|
11
|
+
keyframes: theme => ({
|
|
12
|
+
fadeIn: {
|
|
13
|
+
'0%': { opacity: 0 },
|
|
14
|
+
'100%': { opacity: 1 },
|
|
15
|
+
},
|
|
16
|
+
moveIn: {
|
|
17
|
+
'0%': { transform: 'translateY(-10px)' },
|
|
18
|
+
'100%': { transform: 'translateY(0)' },
|
|
19
|
+
},
|
|
20
|
+
}),
|
|
21
|
+
}
|
|
6
22
|
},
|
|
7
23
|
plugins: [],
|
|
8
24
|
prefix: 'tw-'
|