Files
next.orly.dev/app/web/dist/bundle.js
mleku c5ff2c648c Refactor Nostr Client and Update Dependencies
- Replaced NDKPrivateKeySigner with PrivateKeySigner from applesauce-signers for improved signing functionality.
- Updated the Nostr client implementation to utilize nostr-tools for event management and connection pooling.
- Enhanced event fetching logic to support multiple versions of replaceable events based on limit parameters.
- Updated package dependencies in package.json and bun.lock, including the addition of applesauce-core and applesauce-signers.
- Refined event kind definitions and improved documentation for clarity and consistency with NIP specifications.
- Adjusted CSS styles in bundle.css for better visual consistency across components.
2025-10-25 17:27:25 +01:00

23 lines
304 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
var app=function(){"use strict";function e(){}function t(e){return e()}function n(){return Object.create(null)}function r(e){e.forEach(t)}function o(e){return"function"==typeof e}function i(e,t){return e!=e?t==t:e!==t||e&&"object"==typeof e||"function"==typeof e}let s;function a(e,t){return s||(s=document.createElement("a")),s.href=t,e===s.href}const c="undefined"!=typeof window?window:"undefined"!=typeof globalThis?globalThis:global;function l(e,t){e.appendChild(t)}function u(e,t,n){e.insertBefore(t,n||null)}function d(e){e.parentNode&&e.parentNode.removeChild(e)}function f(e,t){for(let n=0;n<e.length;n+=1)e[n]&&e[n].d(t)}function h(e){return document.createElement(e)}function p(e){return document.createTextNode(e)}function y(){return p(" ")}function g(){return p("")}function m(e,t,n,r){return e.addEventListener(t,n,r),()=>e.removeEventListener(t,n,r)}function v(e){return function(t){return t.stopPropagation(),e.call(this,t)}}function w(e,t,n){null==n?e.removeAttribute(t):e.getAttribute(t)!==n&&e.setAttribute(t,n)}function b(e){return""===e?null:+e}function x(e,t){t=""+t,e.data!==t&&(e.data=t)}function E(e,t){e.value=null==t?"":t}function k(e,t,n){for(let n=0;n<e.options.length;n+=1){const r=e.options[n];if(r.__value===t)return void(r.selected=!0)}n&&void 0===t||(e.selectedIndex=-1)}function S(e,t,n){e.classList[n?"add":"remove"](t)}let A;function C(e){A=e}function T(){if(!A)throw new Error("Function called outside component initialization");return A}function _(){const e=T();return(t,n,{cancelable:r=!1}={})=>{const o=e.$$.callbacks[t];if(o){const i=function(e,t,{bubbles:n=!1,cancelable:r=!1}={}){const o=document.createEvent("CustomEvent");return o.initCustomEvent(e,n,r,t),o}(t,n,{cancelable:r});return o.slice().forEach(t=>{t.call(e,i)}),!i.defaultPrevented}return!0}}function $(e,t){const n=e.$$.callbacks[t.type];n&&n.slice().forEach(e=>e.call(this,t))}const I=[],O=[];let R=[];const P=[],L=Promise.resolve();let B=!1;function N(e){R.push(e)}const U=new Set;let j=0;function M(){if(0!==j)return;const e=A;do{try{for(;j<I.length;){const e=I[j];j++,C(e),F(e.$$)}}catch(e){throw I.length=0,j=0,e}for(C(null),I.length=0,j=0;O.length;)O.pop()();for(let e=0;e<R.length;e+=1){const t=R[e];U.has(t)||(U.add(t),t())}R.length=0}while(I.length);for(;P.length;)P.pop()();B=!1,U.clear(),C(e)}function F(e){if(null!==e.fragment){e.update(),r(e.before_update);const t=e.dirty;e.dirty=[-1],e.fragment&&e.fragment.p(e.ctx,t),e.after_update.forEach(N)}}const D=new Set;let H;function q(){H={r:0,c:[],p:H}}function z(){H.r||r(H.c),H=H.p}function W(e,t){e&&e.i&&(D.delete(e),e.i(t))}function K(e,t,n,r){if(e&&e.o){if(D.has(e))return;D.add(e),H.c.push(()=>{D.delete(e),r&&(n&&e.d(1),r())}),e.o(t)}else r&&r()}function J(e){e&&e.c()}function V(e,n,i,s){const{fragment:a,after_update:c}=e.$$;a&&a.m(n,i),s||N(()=>{const n=e.$$.on_mount.map(t).filter(o);e.$$.on_destroy?e.$$.on_destroy.push(...n):r(n),e.$$.on_mount=[]}),c.forEach(N)}function G(e,t){const n=e.$$;null!==n.fragment&&(!function(e){const t=[],n=[];R.forEach(r=>-1===e.indexOf(r)?t.push(r):n.push(r)),n.forEach(e=>e()),R=t}(n.after_update),r(n.on_destroy),n.fragment&&n.fragment.d(t),n.on_destroy=n.fragment=null,n.ctx=[])}function Z(e,t){-1===e.$$.dirty[0]&&(I.push(e),B||(B=!0,L.then(M)),e.$$.dirty.fill(0)),e.$$.dirty[t/31|0]|=1<<t%31}function Y(t,o,i,s,a,c,l,u=[-1]){const f=A;C(t);const h=t.$$={fragment:null,ctx:[],props:c,update:e,not_equal:a,bound:n(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(o.context||(f?f.$$.context:[])),callbacks:n(),dirty:u,skip_bound:!1,root:o.target||f.$$.root};l&&l(h.root);let p=!1;if(h.ctx=i?i(t,o.props||{},(e,n,...r)=>{const o=r.length?r[0]:n;return h.ctx&&a(h.ctx[e],h.ctx[e]=o)&&(!h.skip_bound&&h.bound[e]&&h.bound[e](o),p&&Z(t,e)),n}):[],h.update(),p=!0,r(h.before_update),h.fragment=!!s&&s(h.ctx),o.target){if(o.hydrate){const e=function(e){return Array.from(e.childNodes)}(o.target);h.fragment&&h.fragment.l(e),e.forEach(d)}else h.fragment&&h.fragment.c();o.intro&&W(t.$$.fragment),V(t,o.target,o.anchor,o.customElement),M()}C(f)}class Q{$destroy(){G(this,1),this.$destroy=e}$on(t,n){if(!o(n))return e;const r=this.$$.callbacks[t]||(this.$$.callbacks[t]=[]);return r.push(n),()=>{const e=r.indexOf(n);-1!==e&&r.splice(e,1)}}$set(e){var t;this.$$set&&(t=e,0!==Object.keys(t).length)&&(this.$$.skip_bound=!0,this.$$set(e),this.$$.skip_bound=!1)}}function X(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`Wrong positive integer: ${e}`)}function ee(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 te(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")}const ne="object"==typeof globalThis&&"crypto"in globalThis?globalThis.crypto:void 0,re=e=>e instanceof Uint8Array,oe=e=>new DataView(e.buffer,e.byteOffset,e.byteLength),ie=(e,t)=>e<<32-t|e>>>t;
/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */if(!(68===new Uint8Array(new Uint32Array([287454020]).buffer)[0]))throw new Error("Non little-endian hardware is not supported");function se(e){if("string"==typeof e&&(e=function(e){if("string"!=typeof e)throw new Error("utf8ToBytes expected string, got "+typeof e);return new Uint8Array((new TextEncoder).encode(e))}(e)),!re(e))throw new Error("expected Uint8Array, got "+typeof e);return e}let ae=class{clone(){return this._cloneInto()}};function ce(e){const t=t=>e().update(se(t)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function le(e=32){if(ne&&"function"==typeof ne.getRandomValues)return ne.getRandomValues(new Uint8Array(e));throw new Error("crypto.getRandomValues must be defined")}let ue=class extends ae{constructor(e,t,n,r){super(),this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=r,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(e),this.view=oe(this.buffer)}update(e){te(this);const{view:t,buffer:n,blockLen:r}=this,o=(e=se(e)).length;for(let i=0;i<o;){const s=Math.min(r-this.pos,o-i);if(s===r){const t=oe(e);for(;r<=o-i;i+=r)this.process(t,i);continue}n.set(e.subarray(i,i+s),this.pos),this.pos+=s,i+=s,this.pos===r&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){te(this),function(e,t){ee(e);const n=t.outputLen;if(e.length<n)throw new Error(`digestInto() expects output buffer of length at least ${n}`)}(e,this),this.finished=!0;const{buffer:t,view:n,blockLen:r,isLE:o}=this;let{pos:i}=this;t[i++]=128,this.buffer.subarray(i).fill(0),this.padOffset>r-i&&(this.process(n,0),i=0);for(let e=i;e<r;e++)t[e]=0;!function(e,t,n,r){if("function"==typeof e.setBigUint64)return e.setBigUint64(t,n,r);const o=BigInt(32),i=BigInt(4294967295),s=Number(n>>o&i),a=Number(n&i),c=r?4:0,l=r?0:4;e.setUint32(t+c,s,r),e.setUint32(t+l,a,r)}(n,r-8,BigInt(8*this.length),o),this.process(n,0);const s=oe(e),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const c=a/4,l=this.get();if(c>l.length)throw new Error("_sha2: outputLen bigger than state");for(let e=0;e<c;e++)s.setUint32(4*e,l[e],o)}digest(){const{buffer:e,outputLen:t}=this;this.digestInto(e);const n=e.slice(0,t);return this.destroy(),n}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());const{blockLen:t,buffer:n,length:r,finished:o,destroyed:i,pos:s}=this;return e.length=r,e.pos=s,e.finished=o,e.destroyed=i,r%t&&e.buffer.set(n),e}};const de=(e,t,n)=>e&t^~e&n,fe=(e,t,n)=>e&t^e&n^t&n,he=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);let ge=class extends ue{constructor(){super(64,32,8,!1),this.A=0|pe[0],this.B=0|pe[1],this.C=0|pe[2],this.D=0|pe[3],this.E=0|pe[4],this.F=0|pe[5],this.G=0|pe[6],this.H=0|pe[7]}get(){const{A:e,B:t,C:n,D:r,E:o,F:i,G:s,H:a}=this;return[e,t,n,r,o,i,s,a]}set(e,t,n,r,o,i,s,a){this.A=0|e,this.B=0|t,this.C=0|n,this.D=0|r,this.E=0|o,this.F=0|i,this.G=0|s,this.H=0|a}process(e,t){for(let n=0;n<16;n++,t+=4)ye[n]=e.getUint32(t,!1);for(let e=16;e<64;e++){const t=ye[e-15],n=ye[e-2],r=ie(t,7)^ie(t,18)^t>>>3,o=ie(n,17)^ie(n,19)^n>>>10;ye[e]=o+ye[e-7]+r+ye[e-16]|0}let{A:n,B:r,C:o,D:i,E:s,F:a,G:c,H:l}=this;for(let e=0;e<64;e++){const t=l+(ie(s,6)^ie(s,11)^ie(s,25))+de(s,a,c)+he[e]+ye[e]|0,u=(ie(n,2)^ie(n,13)^ie(n,22))+fe(n,r,o)|0;l=c,c=a,a=s,s=i+t|0,i=o,o=r,r=n,n=t+u|0}n=n+this.A|0,r=r+this.B|0,o=o+this.C|0,i=i+this.D|0,s=s+this.E|0,a=a+this.F|0,c=c+this.G|0,l=l+this.H|0,this.set(n,r,o,i,s,a,c,l)}roundClean(){ye.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};const me=ce(()=>new ge),ve=BigInt(0),we=BigInt(1),be=BigInt(2),xe=e=>e instanceof Uint8Array,Ee=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function ke(e){if(!xe(e))throw new Error("Uint8Array expected");let t="";for(let n=0;n<e.length;n++)t+=Ee[e[n]];return t}function Se(e){const t=e.toString(16);return 1&t.length?`0${t}`:t}function Ae(e){if("string"!=typeof e)throw new Error("hex string expected, got "+typeof e);return BigInt(""===e?"0":`0x${e}`)}function Ce(e){if("string"!=typeof e)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 t=0;t<n.length;t++){const r=2*t,o=e.slice(r,r+2),i=Number.parseInt(o,16);if(Number.isNaN(i)||i<0)throw new Error("Invalid byte sequence");n[t]=i}return n}function Te(e){return Ae(ke(e))}function _e(e){if(!xe(e))throw new Error("Uint8Array expected");return Ae(ke(Uint8Array.from(e).reverse()))}function $e(e,t){return Ce(e.toString(16).padStart(2*t,"0"))}function Ie(e,t){return $e(e,t).reverse()}function Oe(e,t,n){let r;if("string"==typeof t)try{r=Ce(t)}catch(n){throw new Error(`${e} must be valid hex string, got "${t}". Cause: ${n}`)}else{if(!xe(t))throw new Error(`${e} must be hex string or Uint8Array`);r=Uint8Array.from(t)}const o=r.length;if("number"==typeof n&&o!==n)throw new Error(`${e} expected ${n} bytes, got ${o}`);return r}function Re(...e){const t=new Uint8Array(e.reduce((e,t)=>e+t.length,0));let n=0;return e.forEach(e=>{if(!xe(e))throw new Error("Uint8Array expected");t.set(e,n),n+=e.length}),t}const Pe=e=>(be<<BigInt(e-1))-we,Le=e=>new Uint8Array(e),Be=e=>Uint8Array.from(e);function Ne(e,t,n){if("number"!=typeof e||e<2)throw new Error("hashLen must be a number");if("number"!=typeof t||t<2)throw new Error("qByteLen must be a number");if("function"!=typeof n)throw new Error("hmacFn must be a function");let r=Le(e),o=Le(e),i=0;const s=()=>{r.fill(1),o.fill(0),i=0},a=(...e)=>n(o,r,...e),c=(e=Le())=>{o=a(Be([0]),e),r=a(),0!==e.length&&(o=a(Be([1]),e),r=a())},l=()=>{if(i++>=1e3)throw new Error("drbg: tried 1000 values");let e=0;const n=[];for(;e<t;){r=a();const t=r.slice();n.push(t),e+=r.length}return Re(...n)};return(e,t)=>{let n;for(s(),c(e);!(n=t(l()));)c();return s(),n}}const Ue={bigint:e=>"bigint"==typeof e,function:e=>"function"==typeof e,boolean:e=>"boolean"==typeof e,string:e=>"string"==typeof e,stringOrUint8Array:e=>"string"==typeof e||e instanceof Uint8Array,isSafeInteger:e=>Number.isSafeInteger(e),array:e=>Array.isArray(e),field:(e,t)=>t.Fp.isValid(e),hash:e=>"function"==typeof e&&Number.isSafeInteger(e.outputLen)};function je(e,t,n={}){const r=(t,n,r)=>{const o=Ue[n];if("function"!=typeof o)throw new Error(`Invalid validator "${n}", expected function`);const i=e[t];if(!(r&&void 0===i||o(i,e)))throw new Error(`Invalid param ${String(t)}=${i} (${typeof i}), expected ${n}`)};for(const[e,n]of Object.entries(t))r(e,n,!1);for(const[e,t]of Object.entries(n))r(e,t,!0);return e}var Me=Object.freeze({__proto__:null,bitGet:function(e,t){return e>>BigInt(t)&we},bitLen:function(e){let t;for(t=0;e>ve;e>>=we,t+=1);return t},bitMask:Pe,bitSet:(e,t,n)=>e|(n?we:ve)<<BigInt(t),bytesToHex:ke,bytesToNumberBE:Te,bytesToNumberLE:_e,concatBytes:Re,createHmacDrbg:Ne,ensureBytes:Oe,equalBytes:function(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},hexToBytes:Ce,hexToNumber:Ae,numberToBytesBE:$e,numberToBytesLE:Ie,numberToHexUnpadded:Se,numberToVarBytesBE:function(e){return Ce(Se(e))},utf8ToBytes:function(e){if("string"!=typeof e)throw new Error("utf8ToBytes expected string, got "+typeof e);return new Uint8Array((new TextEncoder).encode(e))},validateObject:je});
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Fe=BigInt(0),De=BigInt(1),He=BigInt(2),qe=BigInt(3),ze=BigInt(4),We=BigInt(5),Ke=BigInt(8);function Je(e,t){const n=e%t;return n>=Fe?n:t+n}function Ve(e,t,n){if(n<=Fe||t<Fe)throw new Error("Expected power/modulo > 0");if(n===De)return Fe;let r=De;for(;t>Fe;)t&De&&(r=r*e%n),e=e*e%n,t>>=De;return r}function Ge(e,t,n){let r=e;for(;t-- >Fe;)r*=r,r%=n;return r}function Ze(e,t){if(e===Fe||t<=Fe)throw new Error(`invert: expected positive integers, got n=${e} mod=${t}`);let n=Je(e,t),r=t,o=Fe,i=De;for(;n!==Fe;){const e=r%n,t=o-i*(r/n);r=n,n=e,o=i,i=t}if(r!==De)throw new Error("invert: does not exist");return Je(o,t)}function Ye(e){if(e%ze===qe){const t=(e+De)/ze;return function(e,n){const r=e.pow(n,t);if(!e.eql(e.sqr(r),n))throw new Error("Cannot find square root");return r}}if(e%Ke===We){const t=(e-We)/Ke;return function(e,n){const r=e.mul(n,He),o=e.pow(r,t),i=e.mul(n,o),s=e.mul(e.mul(i,He),o),a=e.mul(i,e.sub(s,e.ONE));if(!e.eql(e.sqr(a),n))throw new Error("Cannot find square root");return a}}return function(e){const t=(e-De)/He;let n,r,o;for(n=e-De,r=0;n%He===Fe;n/=He,r++);for(o=He;o<e&&Ve(o,t,e)!==e-De;o++);if(1===r){const t=(e+De)/ze;return function(e,n){const r=e.pow(n,t);if(!e.eql(e.sqr(r),n))throw new Error("Cannot find square root");return r}}const i=(n+De)/He;return function(e,s){if(e.pow(s,t)===e.neg(e.ONE))throw new Error("Cannot find square root");let a=r,c=e.pow(e.mul(e.ONE,o),n),l=e.pow(s,i),u=e.pow(s,n);for(;!e.eql(u,e.ONE);){if(e.eql(u,e.ZERO))return e.ZERO;let t=1;for(let n=e.sqr(u);t<a&&!e.eql(n,e.ONE);t++)n=e.sqr(n);const n=e.pow(c,De<<BigInt(a-t-1));c=e.sqr(n),l=e.mul(l,n),u=e.mul(u,c),a=t}return l}}(e)}BigInt(9),BigInt(16);const Qe=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Xe(e,t){const n=void 0!==t?t:e.toString(2).length;return{nBitLength:n,nByteLength:Math.ceil(n/8)}}function et(e){if("bigint"!=typeof e)throw new Error("field order must be bigint");const t=e.toString(2).length;return Math.ceil(t/8)}function tt(e){const t=et(e);return t+Math.ceil(t/2)}
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
const nt=BigInt(0),rt=BigInt(1);function ot(e){return function(e){const t=Qe.reduce((e,t)=>(e[t]="function",e),{ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"});je(e,t)}(e.Fp),je(e,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...Xe(e.n,e.nBitLength),...e,p:e.Fp.ORDER})}
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const{bytesToNumberBE:it,hexToBytes:st}=Me,at={Err:class extends Error{constructor(e=""){super(e)}},_parseInt(e){const{Err:t}=at;if(e.length<2||2!==e[0])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(128&r[0])throw new t("Invalid signature integer: negative");if(0===r[0]&&!(128&r[1]))throw new t("Invalid signature integer: unnecessary leading zero");return{d:it(r),l:e.subarray(n+2)}},toSig(e){const{Err:t}=at,n="string"==typeof e?st(e):e;if(!(n instanceof Uint8Array))throw new Error("ui8a expected");let r=n.length;if(r<2||48!=n[0])throw new t("Invalid signature tag");if(n[1]!==r-2)throw new t("Invalid signature: incorrect length");const{d:o,l:i}=at._parseInt(n.subarray(2)),{d:s,l:a}=at._parseInt(i);if(a.length)throw new t("Invalid signature: left bytes after parsing");return{r:o,s:s}},hexFromSig(e){const t=e=>8&Number.parseInt(e[0],16)?"00"+e:e,n=e=>{const t=e.toString(16);return 1&t.length?`0${t}`:t},r=t(n(e.s)),o=t(n(e.r)),i=r.length/2,s=o.length/2,a=n(i),c=n(s);return`30${n(s+i+4)}02${c}${o}02${a}${r}`}},ct=BigInt(0),lt=BigInt(1);BigInt(2);const ut=BigInt(3);function dt(e){const t=function(e){const t=ot(e);je(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("object"!=typeof n||"bigint"!=typeof n.beta||"function"!=typeof n.splitScalar)throw new Error("Expected endomorphism with beta: bigint and splitScalar: function")}return Object.freeze({...t})}(e),{Fp:n}=t,r=t.toBytes||((e,t,r)=>{const o=t.toAffine();return Re(Uint8Array.from([4]),n.toBytes(o.x),n.toBytes(o.y))}),o=t.fromBytes||(e=>{const t=e.subarray(1);return{x:n.fromBytes(t.subarray(0,n.BYTES)),y:n.fromBytes(t.subarray(n.BYTES,2*n.BYTES))}});function i(e){const{a:r,b:o}=t,i=n.sqr(e),s=n.mul(i,e);return n.add(n.add(s,n.mul(e,r)),o)}if(!n.eql(n.sqr(t.Gy),i(t.Gx)))throw new Error("bad generator point: equation left != right");function s(e){return"bigint"==typeof e&&ct<e&&e<t.n}function a(e){if(!s(e))throw new Error("Expected valid bigint: 0 < bigint < curve.n")}function c(e){const{allowedPrivateKeyLengths:n,nByteLength:r,wrapPrivateKey:o,n:i}=t;if(n&&"bigint"!=typeof e){if(e instanceof Uint8Array&&(e=ke(e)),"string"!=typeof e||!n.includes(e.length))throw new Error("Invalid key");e=e.padStart(2*r,"0")}let s;try{s="bigint"==typeof e?e:Te(Oe("private key",e,r))}catch(t){throw new Error(`private key must be ${r} bytes, hex or bigint, not ${typeof e}`)}return o&&(s=Je(s,i)),a(s),s}const l=new Map;function u(e){if(!(e instanceof d))throw new Error("ProjectivePoint expected")}class d{constructor(e,t,r){if(this.px=e,this.py=t,this.pz=r,null==e||!n.isValid(e))throw new Error("x required");if(null==t||!n.isValid(t))throw new Error("y required");if(null==r||!n.isValid(r))throw new Error("z required")}static fromAffine(e){const{x:t,y:r}=e||{};if(!e||!n.isValid(t)||!n.isValid(r))throw new Error("invalid affine point");if(e instanceof d)throw new Error("projective point not allowed");const o=e=>n.eql(e,n.ZERO);return o(t)&&o(r)?d.ZERO:new d(t,r,n.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(e){const t=n.invertBatch(e.map(e=>e.pz));return e.map((e,n)=>e.toAffine(t[n])).map(d.fromAffine)}static fromHex(e){const t=d.fromAffine(o(Oe("pointHex",e)));return t.assertValidity(),t}static fromPrivateKey(e){return d.BASE.multiply(c(e))}_setWindowSize(e){this._WINDOW_SIZE=e,l.delete(this)}assertValidity(){if(this.is0()){if(t.allowInfinityPoint&&!n.is0(this.py))return;throw new Error("bad point: ZERO")}const{x:e,y:r}=this.toAffine();if(!n.isValid(e)||!n.isValid(r))throw new Error("bad point: x or y not FE");const o=n.sqr(r),s=i(e);if(!n.eql(o,s))throw new Error("bad point: equation left != right");if(!this.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){const{y:e}=this.toAffine();if(n.isOdd)return!n.isOdd(e);throw new Error("Field doesn't support isOdd")}equals(e){u(e);const{px:t,py:r,pz:o}=this,{px:i,py:s,pz:a}=e,c=n.eql(n.mul(t,a),n.mul(i,o)),l=n.eql(n.mul(r,a),n.mul(s,o));return c&&l}negate(){return new d(this.px,n.neg(this.py),this.pz)}double(){const{a:e,b:r}=t,o=n.mul(r,ut),{px:i,py:s,pz:a}=this;let c=n.ZERO,l=n.ZERO,u=n.ZERO,f=n.mul(i,i),h=n.mul(s,s),p=n.mul(a,a),y=n.mul(i,s);return y=n.add(y,y),u=n.mul(i,a),u=n.add(u,u),c=n.mul(e,u),l=n.mul(o,p),l=n.add(c,l),c=n.sub(h,l),l=n.add(h,l),l=n.mul(c,l),c=n.mul(y,c),u=n.mul(o,u),p=n.mul(e,p),y=n.sub(f,p),y=n.mul(e,y),y=n.add(y,u),u=n.add(f,f),f=n.add(u,f),f=n.add(f,p),f=n.mul(f,y),l=n.add(l,f),p=n.mul(s,a),p=n.add(p,p),f=n.mul(p,y),c=n.sub(c,f),u=n.mul(p,h),u=n.add(u,u),u=n.add(u,u),new d(c,l,u)}add(e){u(e);const{px:r,py:o,pz:i}=this,{px:s,py:a,pz:c}=e;let l=n.ZERO,f=n.ZERO,h=n.ZERO;const p=t.a,y=n.mul(t.b,ut);let g=n.mul(r,s),m=n.mul(o,a),v=n.mul(i,c),w=n.add(r,o),b=n.add(s,a);w=n.mul(w,b),b=n.add(g,m),w=n.sub(w,b),b=n.add(r,i);let x=n.add(s,c);return b=n.mul(b,x),x=n.add(g,v),b=n.sub(b,x),x=n.add(o,i),l=n.add(a,c),x=n.mul(x,l),l=n.add(m,v),x=n.sub(x,l),h=n.mul(p,b),l=n.mul(y,v),h=n.add(l,h),l=n.sub(m,h),h=n.add(m,h),f=n.mul(l,h),m=n.add(g,g),m=n.add(m,g),v=n.mul(p,v),b=n.mul(y,b),m=n.add(m,v),v=n.sub(g,v),v=n.mul(p,v),b=n.add(b,v),g=n.mul(m,b),f=n.add(f,g),g=n.mul(x,b),l=n.mul(w,l),l=n.sub(l,g),g=n.mul(w,m),h=n.mul(x,h),h=n.add(h,g),new d(l,f,h)}subtract(e){return this.add(e.negate())}is0(){return this.equals(d.ZERO)}wNAF(e){return h.wNAFCached(this,l,e,e=>{const t=n.invertBatch(e.map(e=>e.pz));return e.map((e,n)=>e.toAffine(t[n])).map(d.fromAffine)})}multiplyUnsafe(e){const r=d.ZERO;if(e===ct)return r;if(a(e),e===lt)return this;const{endo:o}=t;if(!o)return h.unsafeLadder(this,e);let{k1neg:i,k1:s,k2neg:c,k2:l}=o.splitScalar(e),u=r,f=r,p=this;for(;s>ct||l>ct;)s&lt&&(u=u.add(p)),l&lt&&(f=f.add(p)),p=p.double(),s>>=lt,l>>=lt;return i&&(u=u.negate()),c&&(f=f.negate()),f=new d(n.mul(f.px,o.beta),f.py,f.pz),u.add(f)}multiply(e){a(e);let r,o,i=e;const{endo:s}=t;if(s){const{k1neg:e,k1:t,k2neg:a,k2:c}=s.splitScalar(i);let{p:l,f:u}=this.wNAF(t),{p:f,f:p}=this.wNAF(c);l=h.constTimeNegate(e,l),f=h.constTimeNegate(a,f),f=new d(n.mul(f.px,s.beta),f.py,f.pz),r=l.add(f),o=u.add(p)}else{const{p:e,f:t}=this.wNAF(i);r=e,o=t}return d.normalizeZ([r,o])[0]}multiplyAndAddUnsafe(e,t,n){const r=d.BASE,o=(e,t)=>t!==ct&&t!==lt&&e.equals(r)?e.multiply(t):e.multiplyUnsafe(t),i=o(this,t).add(o(e,n));return i.is0()?void 0:i}toAffine(e){const{px:t,py:r,pz:o}=this,i=this.is0();null==e&&(e=i?n.ONE:n.inv(o));const s=n.mul(t,e),a=n.mul(r,e),c=n.mul(o,e);if(i)return{x:n.ZERO,y:n.ZERO};if(!n.eql(c,n.ONE))throw new Error("invZ was invalid");return{x:s,y:a}}isTorsionFree(){const{h:e,isTorsionFree:n}=t;if(e===lt)return!0;if(n)return n(d,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){const{h:e,clearCofactor:n}=t;return e===lt?this:n?n(d,this):this.multiplyUnsafe(t.h)}toRawBytes(e=!0){return this.assertValidity(),r(d,this,e)}toHex(e=!0){return ke(this.toRawBytes(e))}}d.BASE=new d(t.Gx,t.Gy,n.ONE),d.ZERO=new d(n.ZERO,n.ONE,n.ZERO);const f=t.nBitLength,h=function(e,t){const n=(e,t)=>{const n=t.negate();return e?n:t},r=e=>({windows:Math.ceil(t/e)+1,windowSize:2**(e-1)});return{constTimeNegate:n,unsafeLadder(t,n){let r=e.ZERO,o=t;for(;n>nt;)n&rt&&(r=r.add(o)),o=o.double(),n>>=rt;return r},precomputeWindow(e,t){const{windows:n,windowSize:o}=r(t),i=[];let s=e,a=s;for(let e=0;e<n;e++){a=s,i.push(a);for(let e=1;e<o;e++)a=a.add(s),i.push(a);s=a.double()}return i},wNAF(t,o,i){const{windows:s,windowSize:a}=r(t);let c=e.ZERO,l=e.BASE;const u=BigInt(2**t-1),d=2**t,f=BigInt(t);for(let e=0;e<s;e++){const t=e*a;let r=Number(i&u);i>>=f,r>a&&(r-=d,i+=rt);const s=t,h=t+Math.abs(r)-1,p=e%2!=0,y=r<0;0===r?l=l.add(n(p,o[s])):c=c.add(n(y,o[h]))}return{p:c,f:l}},wNAFCached(e,t,n,r){const o=e._WINDOW_SIZE||1;let i=t.get(e);return i||(i=this.precomputeWindow(e,o),1!==o&&t.set(e,r(i))),this.wNAF(o,i,n)}}}(d,t.endo?Math.ceil(f/2):f);return{CURVE:t,ProjectivePoint:d,normPrivateKeyToScalar:c,weierstrassEquation:i,isWithinCurveOrder:s}}function ft(e){const t=function(e){const t=ot(e);return je(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}(e),{Fp:n,n:r}=t,o=n.BYTES+1,i=2*n.BYTES+1;function s(e){return Je(e,r)}function a(e){return Ze(e,r)}const{ProjectivePoint:c,normPrivateKeyToScalar:l,weierstrassEquation:u,isWithinCurveOrder:d}=dt({...t,toBytes(e,t,r){const o=t.toAffine(),i=n.toBytes(o.x),s=Re;return r?s(Uint8Array.from([t.hasEvenY()?2:3]),i):s(Uint8Array.from([4]),i,n.toBytes(o.y))},fromBytes(e){const t=e.length,r=e[0],s=e.subarray(1);if(t!==o||2!==r&&3!==r){if(t===i&&4===r){return{x:n.fromBytes(s.subarray(0,n.BYTES)),y:n.fromBytes(s.subarray(n.BYTES,2*n.BYTES))}}throw new Error(`Point of length ${t} was invalid. Expected ${o} compressed bytes or ${i} uncompressed bytes`)}{const e=Te(s);if(!(ct<(a=e)&&a<n.ORDER))throw new Error("Point is not on curve");const t=u(e);let o=n.sqrt(t);return!(1&~r)!==((o&lt)===lt)&&(o=n.neg(o)),{x:e,y:o}}var a}}),f=e=>ke($e(e,t.nByteLength));function h(e){return e>r>>lt}const p=(e,t,n)=>Te(e.slice(t,n));class y{constructor(e,t,n){this.r=e,this.s=t,this.recovery=n,this.assertValidity()}static fromCompact(e){const n=t.nByteLength;return e=Oe("compactSignature",e,2*n),new y(p(e,0,n),p(e,n,2*n))}static fromDER(e){const{r:t,s:n}=at.toSig(Oe("DER",e));return new y(t,n)}assertValidity(){if(!d(this.r))throw new Error("r must be 0 < r < CURVE.n");if(!d(this.s))throw new Error("s must be 0 < s < CURVE.n")}addRecoveryBit(e){return new y(this.r,this.s,e)}recoverPublicKey(e){const{r:r,s:o,recovery:i}=this,l=w(Oe("msgHash",e));if(null==i||![0,1,2,3].includes(i))throw new Error("recovery id invalid");const u=2===i||3===i?r+t.n:r;if(u>=n.ORDER)throw new Error("recovery id 2 or 3 invalid");const d=1&i?"03":"02",h=c.fromHex(d+f(u)),p=a(u),y=s(-l*p),g=s(o*p),m=c.BASE.multiplyAndAddUnsafe(h,y,g);if(!m)throw new Error("point at infinify");return m.assertValidity(),m}hasHighS(){return h(this.s)}normalizeS(){return this.hasHighS()?new y(this.r,s(-this.s),this.recovery):this}toDERRawBytes(){return Ce(this.toDERHex())}toDERHex(){return at.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return Ce(this.toCompactHex())}toCompactHex(){return f(this.r)+f(this.s)}}const g={isValidPrivateKey(e){try{return l(e),!0}catch(e){return!1}},normPrivateKeyToScalar:l,randomPrivateKey:()=>{const e=tt(t.n);return function(e,t,n=!1){const r=e.length,o=et(t),i=tt(t);if(r<16||r<i||r>1024)throw new Error(`expected ${i}-1024 bytes of input, got ${r}`);const s=Je(n?Te(e):_e(e),t-De)+De;return n?Ie(s,o):$e(s,o)}(t.randomBytes(e),t.n)},precompute:(e=8,t=c.BASE)=>(t._setWindowSize(e),t.multiply(BigInt(3)),t)};function m(e){const t=e instanceof Uint8Array,n="string"==typeof e,r=(t||n)&&e.length;return t?r===o||r===i:n?r===2*o||r===2*i:e instanceof c}const v=t.bits2int||function(e){const n=Te(e),r=8*e.length-t.nBitLength;return r>0?n>>BigInt(r):n},w=t.bits2int_modN||function(e){return s(v(e))},b=Pe(t.nBitLength);function x(e){if("bigint"!=typeof e)throw new Error("bigint expected");if(!(ct<=e&&e<b))throw new Error(`bigint expected < 2^${t.nBitLength}`);return $e(e,t.nByteLength)}function E(e,r,o=k){if(["recovered","canonical"].some(e=>e in o))throw new Error("sign() legacy options not supported");const{hash:i,randomBytes:u}=t;let{lowS:f,prehash:p,extraEntropy:g}=o;null==f&&(f=!0),e=Oe("msgHash",e),p&&(e=Oe("prehashed msgHash",i(e)));const m=w(e),b=l(r),E=[x(b),x(m)];if(null!=g){const e=!0===g?u(n.BYTES):g;E.push(Oe("extraEntropy",e))}const S=Re(...E),A=m;return{seed:S,k2sig:function(e){const t=v(e);if(!d(t))return;const n=a(t),r=c.BASE.multiply(t).toAffine(),o=s(r.x);if(o===ct)return;const i=s(n*s(A+o*b));if(i===ct)return;let l=(r.x===o?0:2)|Number(r.y&lt),u=i;return f&&h(i)&&(u=function(e){return h(e)?s(-e):e}(i),l^=1),new y(o,u,l)}}}const k={lowS:t.lowS,prehash:!1},S={lowS:t.lowS,prehash:!1};return c.BASE._setWindowSize(8),{CURVE:t,getPublicKey:function(e,t=!0){return c.fromPrivateKey(e).toRawBytes(t)},getSharedSecret:function(e,t,n=!0){if(m(e))throw new Error("first arg must be private key");if(!m(t))throw new Error("second arg must be public key");return c.fromHex(t).multiply(l(e)).toRawBytes(n)},sign:function(e,n,r=k){const{seed:o,k2sig:i}=E(e,n,r),s=t;return Ne(s.hash.outputLen,s.nByteLength,s.hmac)(o,i)},verify:function(e,n,r,o=S){const i=e;if(n=Oe("msgHash",n),r=Oe("publicKey",r),"strict"in o)throw new Error("options.strict was renamed to lowS");const{lowS:l,prehash:u}=o;let d,f;try{if("string"==typeof i||i instanceof Uint8Array)try{d=y.fromDER(i)}catch(e){if(!(e instanceof at.Err))throw e;d=y.fromCompact(i)}else{if("object"!=typeof i||"bigint"!=typeof i.r||"bigint"!=typeof i.s)throw new Error("PARSE");{const{r:e,s:t}=i;d=new y(e,t)}}f=c.fromHex(r)}catch(e){if("PARSE"===e.message)throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(l&&d.hasHighS())return!1;u&&(n=t.hash(n));const{r:h,s:p}=d,g=w(n),m=a(p),v=s(g*m),b=s(h*m),x=c.BASE.multiplyAndAddUnsafe(f,v,b)?.toAffine();return!!x&&s(x.x)===h},ProjectivePoint:c,Signature:y,utils:g}}BigInt(4);let ht=class extends ae{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,function(e){if("function"!=typeof e||"function"!=typeof e.create)throw new Error("Hash should be wrapped by utils.wrapConstructor");X(e.outputLen),X(e.blockLen)}(e);const n=se(t);if(this.iHash=e.create(),"function"!=typeof this.iHash.update)throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;const r=this.blockLen,o=new Uint8Array(r);o.set(n.length>r?e.create().update(n).digest():n);for(let e=0;e<o.length;e++)o[e]^=54;this.iHash.update(o),this.oHash=e.create();for(let e=0;e<o.length;e++)o[e]^=106;this.oHash.update(o),o.fill(0)}update(e){return te(this),this.iHash.update(e),this}digestInto(e){te(this),ee(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:t,iHash:n,finished:r,destroyed:o,blockLen:i,outputLen:s}=this;return e.finished=r,e.destroyed=o,e.blockLen=i,e.outputLen=s,e.oHash=t._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}};const pt=(e,t,n)=>new ht(e,t).update(n).digest();
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
function yt(e){return{hash:e,hmac:(t,...n)=>pt(e,t,function(...e){const t=new Uint8Array(e.reduce((e,t)=>e+t.length,0));let n=0;return e.forEach(e=>{if(!re(e))throw new Error("Uint8Array expected");t.set(e,n),n+=e.length}),t}(...n)),randomBytes:le}}pt.create=(e,t)=>new ht(e,t);
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
const gt=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),mt=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),vt=BigInt(1),wt=BigInt(2),bt=(e,t)=>(e+t/wt)/t;function xt(e){const t=gt,n=BigInt(3),r=BigInt(6),o=BigInt(11),i=BigInt(22),s=BigInt(23),a=BigInt(44),c=BigInt(88),l=e*e*e%t,u=l*l*e%t,d=Ge(u,n,t)*u%t,f=Ge(d,n,t)*u%t,h=Ge(f,wt,t)*l%t,p=Ge(h,o,t)*h%t,y=Ge(p,i,t)*p%t,g=Ge(y,a,t)*y%t,m=Ge(g,c,t)*g%t,v=Ge(m,a,t)*y%t,w=Ge(v,n,t)*u%t,b=Ge(w,s,t)*p%t,x=Ge(b,r,t)*l%t,E=Ge(x,wt,t);if(!Et.eql(Et.sqr(E),e))throw new Error("Cannot find square root");return E}const Et=function(e,t,n=!1,r={}){if(e<=Fe)throw new Error(`Expected Field ORDER > 0, got ${e}`);const{nBitLength:o,nByteLength:i}=Xe(e,t);if(i>2048)throw new Error("Field lengths over 2048 bytes are not supported");const s=Ye(e),a=Object.freeze({ORDER:e,BITS:o,BYTES:i,MASK:Pe(o),ZERO:Fe,ONE:De,create:t=>Je(t,e),isValid:t=>{if("bigint"!=typeof t)throw new Error("Invalid field element: expected bigint, got "+typeof t);return Fe<=t&&t<e},is0:e=>e===Fe,isOdd:e=>(e&De)===De,neg:t=>Je(-t,e),eql:(e,t)=>e===t,sqr:t=>Je(t*t,e),add:(t,n)=>Je(t+n,e),sub:(t,n)=>Je(t-n,e),mul:(t,n)=>Je(t*n,e),pow:(e,t)=>function(e,t,n){if(n<Fe)throw new Error("Expected power > 0");if(n===Fe)return e.ONE;if(n===De)return t;let r=e.ONE,o=t;for(;n>Fe;)n&De&&(r=e.mul(r,o)),o=e.sqr(o),n>>=De;return r}(a,e,t),div:(t,n)=>Je(t*Ze(n,e),e),sqrN:e=>e*e,addN:(e,t)=>e+t,subN:(e,t)=>e-t,mulN:(e,t)=>e*t,inv:t=>Ze(t,e),sqrt:r.sqrt||(e=>s(a,e)),invertBatch:e=>function(e,t){const n=new Array(t.length),r=t.reduce((t,r,o)=>e.is0(r)?t:(n[o]=t,e.mul(t,r)),e.ONE),o=e.inv(r);return t.reduceRight((t,r,o)=>e.is0(r)?t:(n[o]=e.mul(t,n[o]),e.mul(t,r)),o),n}(a,e),cmov:(e,t,n)=>n?t:e,toBytes:e=>n?Ie(e,i):$e(e,i),fromBytes:e=>{if(e.length!==i)throw new Error(`Fp.fromBytes: expected ${i}, got ${e.length}`);return n?_e(e):Te(e)}});return Object.freeze(a)}(gt,void 0,void 0,{sqrt:xt}),kt=function(e,t){const n=t=>ft({...e,...yt(t)});return Object.freeze({...n(t),create:n})}({a:BigInt(0),b:BigInt(7),Fp:Et,n:mt,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:e=>{const t=mt,n=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),r=-vt*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),i=n,s=BigInt("0x100000000000000000000000000000000"),a=bt(i*e,t),c=bt(-r*e,t);let l=Je(e-a*n-c*o,t),u=Je(-a*r-c*i,t);const d=l>s,f=u>s;if(d&&(l=t-l),f&&(u=t-u),l>s||u>s)throw new Error("splitScalar: Endomorphism failed, k="+e);return{k1neg:d,k1:l,k2neg:f,k2:u}}}},me),St=BigInt(0),At=e=>"bigint"==typeof e&&St<e&&e<gt,Ct={};function Tt(e,...t){let n=Ct[e];if(void 0===n){const t=me(Uint8Array.from(e,e=>e.charCodeAt(0)));n=Re(t,t),Ct[e]=n}return me(Re(n,...t))}const _t=e=>e.toRawBytes(!0).slice(1),$t=e=>$e(e,32),It=e=>Je(e,gt),Ot=e=>Je(e,mt),Rt=kt.ProjectivePoint;function Pt(e){let t=kt.utils.normPrivateKeyToScalar(e),n=Rt.fromPrivateKey(t);return{scalar:n.hasEvenY()?t:Ot(-t),bytes:_t(n)}}function Lt(e){if(!At(e))throw new Error("bad x: need 0 < x < p");const t=It(e*e);let n=xt(It(t*e+BigInt(7)));n%wt!==St&&(n=It(-n));const r=new Rt(e,n,vt);return r.assertValidity(),r}function Bt(...e){return Ot(Te(Tt("BIP0340/challenge",...e)))}function Nt(e){return Pt(e).bytes}function Ut(e,t,n=le(32)){const r=Oe("message",e),{bytes:o,scalar:i}=Pt(t),s=Oe("auxRand",n,32),a=$t(i^Te(Tt("BIP0340/aux",s))),c=Tt("BIP0340/nonce",a,o,r),l=Ot(Te(c));if(l===St)throw new Error("sign failed: k is zero");const{bytes:u,scalar:d}=Pt(l),f=Bt(u,o,r),h=new Uint8Array(64);if(h.set(u,0),h.set($t(Ot(d+f*i)),32),!jt(h,r,o))throw new Error("sign: Invalid signature produced");return h}function jt(e,t,n){const r=Oe("signature",e,64),o=Oe("message",t),i=Oe("publicKey",n,32);try{const e=Lt(Te(i)),t=Te(r.subarray(0,32));if(!At(t))return!1;const n=Te(r.subarray(32,64));if(!("bigint"==typeof(l=n)&&St<l&&l<mt))return!1;const u=Bt($t(t),_t(e),o),d=(s=e,a=n,c=Ot(-u),Rt.BASE.multiplyAndAddUnsafe(s,a,c));return!(!d||!d.hasEvenY()||d.toAffine().x!==t)}catch(e){return!1}var s,a,c,l}const Mt=(()=>({getPublicKey:Nt,sign:Ut,verify:jt,utils:{randomPrivateKey:kt.utils.randomPrivateKey,lift_x:Lt,pointToBytes:_t,numberToBytesBE:$e,bytesToNumberBE:Te,taggedHash:Tt,mod:Je}}))(),Ft="object"==typeof globalThis&&"crypto"in globalThis?globalThis.crypto:void 0,Dt=e=>e instanceof Uint8Array,Ht=e=>new DataView(e.buffer,e.byteOffset,e.byteLength),qt=(e,t)=>e<<32-t|e>>>t;if(!(68===new Uint8Array(new Uint32Array([287454020]).buffer)[0]))throw new Error("Non little-endian hardware is not supported");const zt=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Wt(e){if(!Dt(e))throw new Error("Uint8Array expected");let t="";for(let n=0;n<e.length;n++)t+=zt[e[n]];return t}function Kt(e){if("string"!=typeof e)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 t=0;t<n.length;t++){const r=2*t,o=e.slice(r,r+2),i=Number.parseInt(o,16);if(Number.isNaN(i)||i<0)throw new Error("Invalid byte sequence");n[t]=i}return n}function Jt(e){if("string"==typeof e&&(e=function(e){if("string"!=typeof e)throw new Error("utf8ToBytes expected string, got "+typeof e);return new Uint8Array((new TextEncoder).encode(e))}(e)),!Dt(e))throw new Error("expected Uint8Array, got "+typeof e);return e}function Vt(...e){const t=new Uint8Array(e.reduce((e,t)=>e+t.length,0));let n=0;return e.forEach(e=>{if(!Dt(e))throw new Error("Uint8Array expected");t.set(e,n),n+=e.length}),t}class Gt{clone(){return this._cloneInto()}}function Zt(e){const t=t=>e().update(Jt(t)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function Yt(e=32){if(Ft&&"function"==typeof Ft.getRandomValues)return Ft.getRandomValues(new Uint8Array(e));throw new Error("crypto.getRandomValues must be defined")}function Qt(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`Wrong positive integer: ${e}`)}function Xt(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}`)}const en={number:Qt,bool:function(e){if("boolean"!=typeof e)throw new Error(`Expected boolean, not ${e}`)},bytes:Xt,hash:function(e){if("function"!=typeof e||"function"!=typeof e.create)throw new Error("Hash should be wrapped by utils.wrapConstructor");Qt(e.outputLen),Qt(e.blockLen)},exists:function(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")},output:function(e,t){Xt(e);const n=t.outputLen;if(e.length<n)throw new Error(`digestInto() expects output buffer of length at least ${n}`)}};class tn extends Gt{constructor(e,t,n,r){super(),this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=r,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(e),this.view=Ht(this.buffer)}update(e){en.exists(this);const{view:t,buffer:n,blockLen:r}=this,o=(e=Jt(e)).length;for(let i=0;i<o;){const s=Math.min(r-this.pos,o-i);if(s===r){const t=Ht(e);for(;r<=o-i;i+=r)this.process(t,i);continue}n.set(e.subarray(i,i+s),this.pos),this.pos+=s,i+=s,this.pos===r&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){en.exists(this),en.output(e,this),this.finished=!0;const{buffer:t,view:n,blockLen:r,isLE:o}=this;let{pos:i}=this;t[i++]=128,this.buffer.subarray(i).fill(0),this.padOffset>r-i&&(this.process(n,0),i=0);for(let e=i;e<r;e++)t[e]=0;!function(e,t,n,r){if("function"==typeof e.setBigUint64)return e.setBigUint64(t,n,r);const o=BigInt(32),i=BigInt(4294967295),s=Number(n>>o&i),a=Number(n&i),c=r?4:0,l=r?0:4;e.setUint32(t+c,s,r),e.setUint32(t+l,a,r)}(n,r-8,BigInt(8*this.length),o),this.process(n,0);const s=Ht(e),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const c=a/4,l=this.get();if(c>l.length)throw new Error("_sha2: outputLen bigger than state");for(let e=0;e<c;e++)s.setUint32(4*e,l[e],o)}digest(){const{buffer:e,outputLen:t}=this;this.digestInto(e);const n=e.slice(0,t);return this.destroy(),n}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());const{blockLen:t,buffer:n,length:r,finished:o,destroyed:i,pos:s}=this;return e.length=r,e.pos=s,e.finished=o,e.destroyed=i,r%t&&e.buffer.set(n),e}}const nn=(e,t,n)=>e&t^~e&n,rn=(e,t,n)=>e&t^e&n^t&n,on=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]),sn=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),an=new Uint32Array(64);class cn extends tn{constructor(){super(64,32,8,!1),this.A=0|sn[0],this.B=0|sn[1],this.C=0|sn[2],this.D=0|sn[3],this.E=0|sn[4],this.F=0|sn[5],this.G=0|sn[6],this.H=0|sn[7]}get(){const{A:e,B:t,C:n,D:r,E:o,F:i,G:s,H:a}=this;return[e,t,n,r,o,i,s,a]}set(e,t,n,r,o,i,s,a){this.A=0|e,this.B=0|t,this.C=0|n,this.D=0|r,this.E=0|o,this.F=0|i,this.G=0|s,this.H=0|a}process(e,t){for(let n=0;n<16;n++,t+=4)an[n]=e.getUint32(t,!1);for(let e=16;e<64;e++){const t=an[e-15],n=an[e-2],r=qt(t,7)^qt(t,18)^t>>>3,o=qt(n,17)^qt(n,19)^n>>>10;an[e]=o+an[e-7]+r+an[e-16]|0}let{A:n,B:r,C:o,D:i,E:s,F:a,G:c,H:l}=this;for(let e=0;e<64;e++){const t=l+(qt(s,6)^qt(s,11)^qt(s,25))+nn(s,a,c)+on[e]+an[e]|0,u=(qt(n,2)^qt(n,13)^qt(n,22))+rn(n,r,o)|0;l=c,c=a,a=s,s=i+t|0,i=o,o=r,r=n,n=t+u|0}n=n+this.A|0,r=r+this.B|0,o=o+this.C|0,i=i+this.D|0,s=s+this.E|0,a=a+this.F|0,c=c+this.G|0,l=l+this.H|0,this.set(n,r,o,i,s,a,c,l)}roundClean(){an.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}}class ln extends cn{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 un=Zt(()=>new cn);Zt(()=>new ln);var dn=Symbol("verified");function fn(e){if(!(e instanceof Object))return!1;if("number"!=typeof e.kind)return!1;if("string"!=typeof e.content)return!1;if("number"!=typeof e.created_at)return!1;if("string"!=typeof e.pubkey)return!1;if(!e.pubkey.match(/^[a-f0-9]{64}$/))return!1;if(!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 e=0;e<n.length;e++)if("string"!=typeof n[e])return!1}return!0}new TextDecoder("utf-8");var hn=new TextEncoder;function pn(e){try{-1===e.indexOf("://")&&(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)),("80"===t.port&&"ws:"===t.protocol||"443"===t.port&&"wss:"===t.protocol)&&(t.port=""),t.searchParams.sort(),t.hash="",t.toString()}catch(t){throw new Error(`Invalid URL: ${e}`)}}var yn=class{value;next=null;prev=null;constructor(e){this.value=e}},gn=class{first;last;constructor(){this.first=null,this.last=null}enqueue(e){const t=new yn(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 e=this.first;return this.first=null,this.last=null,e.value}const e=this.first;return this.first=e.next,this.first&&(this.first.prev=null),e.value}};function mn(e){return Wt(un(hn.encode(function(e){if(!fn(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])}(e))))}var vn=new class{generateSecretKey(){return Mt.utils.randomPrivateKey()}getPublicKey(e){return Wt(Mt.getPublicKey(e))}finalizeEvent(e,t){const n=e;return n.pubkey=Wt(Mt.getPublicKey(t)),n.id=mn(n),n.sig=Wt(Mt.sign(mn(n),t)),n[dn]=!0,n}verifyEvent(e){if("boolean"==typeof e[dn])return e[dn];const t=mn(e);if(t!==e.id)return e[dn]=!1,!1;try{const n=Mt.verify(e.sig,t,e.pubkey);return e[dn]=n,n}catch(t){return e[dn]=!1,!1}}};vn.generateSecretKey,vn.getPublicKey,vn.finalizeEvent;var wn=vn.verifyEvent;function bn(e,t){if(e.ids&&-1===e.ids.indexOf(t.id))return!1;if(e.kinds&&-1===e.kinds.indexOf(t.kind))return!1;if(e.authors&&-1===e.authors.indexOf(t.pubkey))return!1;for(let n in e)if("#"===n[0]){let r=e[`#${n.slice(1)}`];if(r&&!t.tags.find(([e,t])=>e===n.slice(1)&&-1!==r.indexOf(t)))return!1}return!(e.since&&t.created_at<e.since)&&!(e.until&&t.created_at>e.until)}async function xn(){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 En,kn=e=>(e[dn]=!0,!0),Sn=class extends Error{constructor(e,t){super(`Tried to send message '${e} on a closed connection to ${t}.`),this.name="SendingOnClosedConnection"}},An=class{url;_connected=!1;onclose=null;onnotice=e=>console.debug(`NOTICE from ${this.url}: ${e}`);baseEoseTimeout=4400;connectionTimeout=4400;publishTimeout=4400;pingFrequency=2e4;pingTimeout=2e4;openSubs=new Map;enablePing;connectionTimeoutHandle;connectionPromise;openCountRequests=new Map;openEventPublishes=new Map;ws;incomingMessageQueue=new gn;queueRunning=!1;challenge;authPromise;serial=0;verifyEvent;_WebSocket;constructor(e,t){this.url=pn(e),this.verifyEvent=t.verifyEvent,this._WebSocket=t.websocketImplementation||WebSocket,this.enablePing=t.enablePing}static async connect(e,t){const n=new An(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.challenge=void 0,this.authPromise=void 0,this.connectionPromise=new Promise((e,t)=>{this.connectionTimeoutHandle=setTimeout(()=>{t("connection timed out"),this.connectionPromise=void 0,this.onclose?.(),this.closeAllSubscriptions("relay connection timed out")},this.connectionTimeout);try{this.ws=new this._WebSocket(this.url)}catch(e){return clearTimeout(this.connectionTimeoutHandle),void t(e)}this.ws.onopen=()=>{clearTimeout(this.connectionTimeoutHandle),this._connected=!0,this.enablePing&&this.pingpong(),e()},this.ws.onerror=e=>{clearTimeout(this.connectionTimeoutHandle),t(e.message||"websocket error"),this._connected=!1,this.connectionPromise=void 0,this.onclose?.(),this.closeAllSubscriptions("relay connection errored")},this.ws.onclose=e=>{clearTimeout(this.connectionTimeoutHandle),t(e.message||"websocket closed"),this._connected=!1,this.connectionPromise=void 0,this.onclose?.(),this.closeAllSubscriptions("relay connection closed")},this.ws.onmessage=this._onmessage.bind(this)})),this.connectionPromise}async waitForPingPong(){return new Promise((e,t)=>{this.ws&&this.ws.on&&this.ws.on("pong",()=>e(!0))||t("ws can't listen for pong"),this.ws&&this.ws.ping&&this.ws.ping()})}async waitForDummyReq(){return new Promise((e,t)=>{const n=this.subscribe([{ids:["a".repeat(64)]}],{oneose:()=>{n.close(),e(!0)},eoseTimeout:this.pingTimeout+1e3})})}async pingpong(){if(1===this.ws?.readyState){await Promise.any([this.ws&&this.ws.ping&&this.ws.on?this.waitForPingPong():this.waitForDummyReq(),new Promise(e=>setTimeout(()=>e(!1),this.pingTimeout))])?setTimeout(()=>this.pingpong(),this.pingFrequency):(this.closeAllSubscriptions("pingpong timed out"),this._connected=!1,this.onclose?.(),this.ws?.close())}}async runQueue(){for(this.queueRunning=!0;!1!==this.handleNext();)await xn();this.queueRunning=!1}handleNext(){const e=this.incomingMessageQueue.dequeue();if(!e)return!1;const t=function(e){let t=e.slice(0,22).indexOf('"EVENT"');if(-1===t)return null;let n=e.slice(t+7+1).indexOf('"');if(-1===n)return null;let r=t+7+1+n,o=e.slice(r+1,80).indexOf('"');if(-1===o)return null;let i=r+1+o;return e.slice(r+1,i)}(e);if(t){const n=this.openSubs.get(t);if(!n)return;const r=function(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)}(e,"id"),o=n.alreadyHaveEvent?.(r);if(n.receivedEvent?.(this,r),o)return}try{let t=JSON.parse(e);switch(t[0]){case"EVENT":{const e=this.openSubs.get(t[1]),n=t[2];return void(this.verifyEvent(n)&&function(e,t){for(let n=0;n<e.length;n++)if(bn(e[n],t))return!0;return!1}(e.filters,n)&&e.onevent(n))}case"COUNT":{const e=t[1],n=t[2],r=this.openCountRequests.get(e);return void(r&&(r.resolve(n.count),this.openCountRequests.delete(e)))}case"EOSE":{const e=this.openSubs.get(t[1]);if(!e)return;return void e.receivedEose()}case"OK":{const e=t[1],n=t[2],r=t[3],o=this.openEventPublishes.get(e);return void(o&&(clearTimeout(o.timeout),n?o.resolve(r):o.reject(new Error(r)),this.openEventPublishes.delete(e)))}case"CLOSED":{const e=t[1],n=this.openSubs.get(e);if(!n)return;return n.closed=!0,void n.close(t[2])}case"NOTICE":return void this.onnotice(t[1]);case"AUTH":return void(this.challenge=t[1])}}catch(e){return}}async send(e){if(!this.connectionPromise)throw new Sn(e,this.url);this.connectionPromise.then(()=>{this.ws?.send(e)})}async auth(e){const t=this.challenge;if(!t)throw new Error("can't perform auth, no challenge was received");return this.authPromise||(this.authPromise=new Promise(async(n,r)=>{try{let o=await e(function(e,t){return{kind:22242,created_at:Math.floor(Date.now()/1e3),tags:[["relay",e],["challenge",t]],content:""}}(this.url,t)),i=setTimeout(()=>{let e=this.openEventPublishes.get(o.id);e&&(e.reject(new Error("auth timed out")),this.openEventPublishes.delete(o.id))},this.publishTimeout);this.openEventPublishes.set(o.id,{resolve:n,reject:r,timeout:i}),this.send('["AUTH",'+JSON.stringify(o)+"]")}catch(e){console.warn("subscribe auth function failed:",e)}})),this.authPromise}async publish(e){const t=new Promise((t,n)=>{const r=setTimeout(()=>{const t=this.openEventPublishes.get(e.id);t&&(t.reject(new Error("publish timed out")),this.openEventPublishes.delete(e.id))},this.publishTimeout);this.openEventPublishes.set(e.id,{resolve:t,reject:n,timeout:r})});return this.send('["EVENT",'+JSON.stringify(e)+"]"),t}async count(e,t){this.serial++;const n=t?.id||"count:"+this.serial,r=new Promise((e,t)=>{this.openCountRequests.set(n,{resolve:e,reject:t})});return this.send('["COUNT","'+n+'",'+JSON.stringify(e).substring(1)),r}subscribe(e,t){const n=this.prepareSubscription(e,t);return n.fire(),n}prepareSubscription(e,t){this.serial++;const n=t.id||(t.label?t.label+":":"sub:")+this.serial,r=new Cn(this,n,e,t);return this.openSubs.set(n,r),r}close(){this.closeAllSubscriptions("relay connection closed by us"),this._connected=!1,this.onclose?.(),this.ws?.close()}_onmessage(e){this.incomingMessageQueue.enqueue(e.data),this.queueRunning||this.runQueue()}},Cn=class{relay;id;closed=!1;eosed=!1;filters;alreadyHaveEvent;receivedEvent;onevent;oneose;onclose;eoseTimeout;eoseTimeoutHandle;constructor(e,t,n,r){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||(e=>{console.warn(`onevent() callback not defined for subscription '${this.id}' in relay ${this.relay.url}. event received:`,e)})}fire(){this.relay.send('["REQ","'+this.id+'",'+JSON.stringify(this.filters).substring(1)),this.eoseTimeoutHandle=setTimeout(this.receivedEose.bind(this),this.eoseTimeout)}receivedEose(){this.eosed||(clearTimeout(this.eoseTimeoutHandle),this.eosed=!0,this.oneose?.())}close(e="closed by caller"){if(!this.closed&&this.relay.connected){try{this.relay.send('["CLOSE",'+JSON.stringify(this.id)+"]")}catch(e){if(!(e instanceof Sn))throw e}this.closed=!0}this.relay.openSubs.delete(this.id),this.onclose?.(e)}},Tn=class{relays=new Map;seenOn=new Map;trackRelays=!1;verifyEvent;enablePing;trustedRelayURLs=new Set;_WebSocket;constructor(e){this.verifyEvent=e.verifyEvent,this._WebSocket=e.websocketImplementation,this.enablePing=e.enablePing}async ensureRelay(e,t){e=pn(e);let n=this.relays.get(e);return n||(n=new An(e,{verifyEvent:this.trustedRelayURLs.has(e)?kn:this.verifyEvent,websocketImplementation:this._WebSocket,enablePing:this.enablePing}),n.onclose=()=>{this.relays.delete(e)},t?.connectionTimeout&&(n.connectionTimeout=t.connectionTimeout),this.relays.set(e,n)),await n.connect(),n}close(e){e.map(pn).forEach(e=>{this.relays.get(e)?.close(),this.relays.delete(e)})}subscribe(e,t,n){n.onauth=n.onauth||n.doauth;const r=[];for(let n=0;n<e.length;n++){const o=pn(e[n]);r.find(e=>e.url===o)||r.push({url:o,filter:t})}return this.subscribeMap(r,n)}subscribeMany(e,t,n){n.onauth=n.onauth||n.doauth;const r=[],o=[];for(let n=0;n<e.length;n++){const i=pn(e[n]);-1===o.indexOf(i)&&(o.push(i),r.push({url:i,filter:t}))}return this.subscribeMap(r,n)}subscribeMap(e,t){t.onauth=t.onauth||t.doauth;const n=new Map;for(const t of e){const{url:e,filter:r}=t;n.has(e)||n.set(e,[]),n.get(e).push(r)}const r=Array.from(n.entries()).map(([e,t])=>({url:e,filters:t}));this.trackRelays&&(t.receivedEvent=(e,t)=>{let n=this.seenOn.get(t);n||(n=new Set,this.seenOn.set(t,n)),n.add(e)});const o=new Set,i=[],s=[];let a=n=>{s[n]||(s[n]=!0,s.filter(e=>e).length===e.length&&(t.oneose?.(),a=()=>{}))};const c=[];let l=(n,r)=>{c[n]||(a(n),c[n]=r,c.filter(e=>e).length===e.length&&(t.onclose?.(c),l=()=>{}))};const u=e=>{if(t.alreadyHaveEvent?.(e))return!0;const n=o.has(e);return o.add(e),n},d=Promise.all(r.map(async({url:e,filters:n},r)=>{let o;try{o=await this.ensureRelay(e,{connectionTimeout:t.maxWait?Math.max(.8*t.maxWait,t.maxWait-1e3):void 0})}catch(e){return void l(r,e?.message||String(e))}let s=o.subscribe(n,{...t,oneose:()=>a(r),onclose:e=>{e.startsWith("auth-required: ")&&t.onauth?o.auth(t.onauth).then(()=>{o.subscribe(n,{...t,oneose:()=>a(r),onclose:e=>{l(r,e)},alreadyHaveEvent:u,eoseTimeout:t.maxWait})}).catch(e=>{l(r,`auth was required and attempted, but failed with: ${e}`)}):l(r,e)},alreadyHaveEvent:u,eoseTimeout:t.maxWait});i.push(s)}));return{async close(e){await d,i.forEach(t=>{t.close(e)})}}}subscribeEose(e,t,n){n.onauth=n.onauth||n.doauth;const r=this.subscribe(e,t,{...n,oneose(){r.close("closed automatically on eose")}});return r}subscribeManyEose(e,t,n){n.onauth=n.onauth||n.doauth;const r=this.subscribeMany(e,t,{...n,oneose(){r.close("closed automatically on eose")}});return r}async querySync(e,t,n){return new Promise(async r=>{const o=[];this.subscribeEose(e,t,{...n,onevent(e){o.push(e)},onclose(e){r(o)}})})}async get(e,t,n){t.limit=1;const r=await this.querySync(e,t,n);return r.sort((e,t)=>t.created_at-e.created_at),r[0]||null}publish(e,t,n){return e.map(pn).map(async(e,r,o)=>{if(o.indexOf(e)!==r)return Promise.reject("duplicate url");let i=await this.ensureRelay(e);return i.publish(t).catch(async e=>{if(e instanceof Error&&e.message.startsWith("auth-required: ")&&n?.onauth)return await i.auth(n.onauth),i.publish(t);throw e}).then(e=>{if(this.trackRelays){let e=this.seenOn.get(t.id);e||(e=new Set,this.seenOn.set(t.id,e)),e.add(i)}return e})})}listConnectionStatus(){const e=new Map;return this.relays.forEach((t,n)=>e.set(n,t.connected)),e}destroy(){this.relays.forEach(e=>e.close()),this.relays=new Map}};try{En=WebSocket}catch{}var _n=class extends Tn{constructor(e){super({verifyEvent:wn,websocketImplementation:En,...e})}};
/*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) */function $n(e){if(!Number.isSafeInteger(e))throw new Error(`Wrong integer: ${e}`)}function In(...e){const t=(e,t)=>n=>e(t(n)),n=Array.from(e).reverse().reduce((e,n)=>e?t(e,n.encode):n.encode,void 0),r=e.reduce((e,n)=>e?t(e,n.decode):n.decode,void 0);return{encode:n,decode:r}}function On(e){return{encode:t=>{if(!Array.isArray(t)||t.length&&"number"!=typeof t[0])throw new Error("alphabet.encode input should be an array of numbers");return t.map(t=>{if($n(t),t<0||t>=e.length)throw new Error(`Digit index outside alphabet: ${t} (alphabet: ${e.length})`);return e[t]})},decode:t=>{if(!Array.isArray(t)||t.length&&"string"!=typeof t[0])throw new Error("alphabet.decode input should be array of strings");return t.map(t=>{if("string"!=typeof t)throw new Error(`alphabet.decode: not string element=${t}`);const n=e.indexOf(t);if(-1===n)throw new Error(`Unknown letter: "${t}". Allowed: ${e}`);return n})}}}function Rn(e=""){if("string"!=typeof e)throw new Error("join separator should be string");return{encode:t=>{if(!Array.isArray(t)||t.length&&"string"!=typeof t[0])throw new Error("join.encode input should be array of strings");for(let e of t)if("string"!=typeof e)throw new Error(`join.encode: non-string input=${e}`);return t.join(e)},decode:t=>{if("string"!=typeof t)throw new Error("join.decode input should be string");return t.split(e)}}}function Pn(e,t="="){if($n(e),"string"!=typeof t)throw new Error("padding chr should be string");return{encode(n){if(!Array.isArray(n)||n.length&&"string"!=typeof n[0])throw new Error("padding.encode input should be array of strings");for(let e of n)if("string"!=typeof e)throw new Error(`padding.encode: non-string input=${e}`);for(;n.length*e%8;)n.push(t);return n},decode(n){if(!Array.isArray(n)||n.length&&"string"!=typeof n[0])throw new Error("padding.encode input should be array of strings");for(let e of n)if("string"!=typeof e)throw new Error(`padding.decode: non-string input=${e}`);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 Ln(e){if("function"!=typeof e)throw new Error("normalize fn should be function");return{encode:e=>e,decode:t=>e(t)}}function Bn(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=[],i=Array.from(e);for(i.forEach(e=>{if($n(e),e<0||e>=t)throw new Error(`Wrong integer: ${e}`)});;){let e=0,s=!0;for(let o=r;o<i.length;o++){const a=i[o],c=t*e+a;if(!Number.isSafeInteger(c)||t*e/t!==e||c-a!==t*e)throw new Error("convertRadix: carry overflow");if(e=c%n,i[o]=Math.floor(c/n),!Number.isSafeInteger(i[o])||i[o]*n+e!==c)throw new Error("convertRadix: carry overflow");s&&(i[o]?s=!1:r=o)}if(o.push(e),s)break}for(let t=0;t<e.length-1&&0===e[t];t++)o.push(0);return o.reverse()}const Nn=(e,t)=>t?Nn(t,e%t):e,Un=(e,t)=>e+(t-Nn(e,t));function jn(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(Un(t,n)>32)throw new Error(`convertRadix2: carry overflow from=${t} to=${n} carryBits=${Un(t,n)}`);let o=0,i=0;const s=2**n-1,a=[];for(const r of e){if($n(r),r>=2**t)throw new Error(`convertRadix2: invalid data word=${r} from=${t}`);if(o=o<<t|r,i+t>32)throw new Error(`convertRadix2: carry overflow pos=${i} from=${t}`);for(i+=t;i>=n;i-=n)a.push((o>>i-n&s)>>>0);o&=2**i-1}if(o=o<<n-i&s,!r&&i>=t)throw new Error("Excess padding");if(!r&&o)throw new Error(`Non-zero padding: ${o}`);return r&&i>0&&a.push(o>>>0),a}function Mn(e,t=!1){if($n(e),e<=0||e>32)throw new Error("radix2: bits should be in (0..32]");if(Un(8,e)>32||Un(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 jn(Array.from(n),8,e,!t)},decode:n=>{if(!Array.isArray(n)||n.length&&"number"!=typeof n[0])throw new Error("radix2.decode input should be array of strings");return Uint8Array.from(jn(n,e,8,t))}}}function Fn(e){if("function"!=typeof e)throw new Error("unsafeWrapper fn should be function");return function(...t){try{return e.apply(null,t)}catch(e){}}}const Dn=In(Mn(4),On("0123456789ABCDEF"),Rn("")),Hn=In(Mn(5),On("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"),Pn(5),Rn(""));In(Mn(5),On("0123456789ABCDEFGHIJKLMNOPQRSTUV"),Pn(5),Rn("")),In(Mn(5),On("0123456789ABCDEFGHJKMNPQRSTVWXYZ"),Rn(""),Ln(e=>e.toUpperCase().replace(/O/g,"0").replace(/[IL]/g,"1")));const qn=In(Mn(6),On("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),Pn(6),Rn("")),zn=In(Mn(6),On("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"),Pn(6),Rn("")),Wn=e=>{return In(($n(t=58),{encode:e=>{if(!(e instanceof Uint8Array))throw new Error("radix.encode input should be Uint8Array");return Bn(Array.from(e),256,t)},decode:e=>{if(!Array.isArray(e)||e.length&&"number"!=typeof e[0])throw new Error("radix.decode input should be array of strings");return Uint8Array.from(Bn(e,t,256))}}),On(e),Rn(""));var t},Kn=Wn("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");Wn("123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"),Wn("rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz");const Jn=[0,2,3,5,6,7,9,10,11],Vn={encode(e){let t="";for(let n=0;n<e.length;n+=8){const r=e.subarray(n,n+8);t+=Kn.encode(r).padStart(Jn[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=Jn.indexOf(r.length),i=Kn.decode(r);for(let e=0;e<i.length-o;e++)if(0!==i[e])throw new Error("base58xmr: wrong padding");t=t.concat(Array.from(i.slice(i.length-o)))}return Uint8Array.from(t)}},Gn=In(On("qpzry9x8gf2tvdw0s3jn54khce6mua7l"),Rn("")),Zn=[996825010,642813549,513874426,1027748829,705979059];function Yn(e){const t=e>>25;let n=(33554431&e)<<5;for(let e=0;e<Zn.length;e++)1==(t>>e&1)&&(n^=Zn[e]);return n}function Qn(e,t,n=1){const r=e.length;let o=1;for(let t=0;t<r;t++){const n=e.charCodeAt(t);if(n<33||n>126)throw new Error(`Invalid prefix (${e})`);o=Yn(o)^n>>5}o=Yn(o);for(let t=0;t<r;t++)o=Yn(o)^31&e.charCodeAt(t);for(let e of t)o=Yn(o)^e;for(let e=0;e<6;e++)o=Yn(o);return o^=n,Gn.encode(jn([o%2**30],30,5,!1))}function Xn(e){const t="bech32"===e?1:734539939,n=Mn(5),r=n.decode,o=n.encode,i=Fn(r);function s(e,n=90){if("string"!=typeof e)throw new Error("bech32.decode input should be string, not "+typeof e);if(e.length<8||!1!==n&&e.length>n)throw new TypeError(`Wrong string length: ${e.length} (${e}). Expected (8..${n})`);const r=e.toLowerCase();if(e!==r&&e!==e.toUpperCase())throw new Error("String must be lowercase or uppercase");const o=(e=r).lastIndexOf("1");if(0===o||-1===o)throw new Error('Letter "1" must be present between prefix and data only');const i=e.slice(0,o),s=e.slice(o+1);if(s.length<6)throw new Error("Data must be at least 6 characters long");const a=Gn.decode(s).slice(0,-6),c=Qn(i,a,t);if(!s.endsWith(c))throw new Error(`Invalid checksum in ${e}: expected "${c}"`);return{prefix:i,words:a}}return{encode:function(e,n,r=90){if("string"!=typeof e)throw new Error("bech32.encode prefix should be string, not "+typeof e);if(!Array.isArray(n)||n.length&&"number"!=typeof n[0])throw new Error("bech32.encode words should be array of numbers, not "+typeof n);const o=e.length+7+n.length;if(!1!==r&&o>r)throw new TypeError(`Length ${o} exceeds limit ${r}`);return`${e=e.toLowerCase()}1${Gn.encode(n)}${Qn(e,n,t)}`},decode:s,decodeToBytes:function(e){const{prefix:t,words:n}=s(e,!1);return{prefix:t,words:n,bytes:r(n)}},decodeUnsafe:Fn(s),fromWords:r,fromWordsUnsafe:i,toWords:o}}const er=Xn("bech32");Xn("bech32m");const tr={utf8:{encode:e=>(new TextDecoder).decode(e),decode:e=>(new TextEncoder).encode(e)},hex:In(Mn(4),On("0123456789abcdef"),Rn(""),Ln(e=>{if("string"!=typeof e||e.length%2)throw new TypeError(`hex.decode: expected string, got ${typeof e} with length ${e.length}`);return e.toLowerCase()})),base16:Dn,base32:Hn,base64:qn,base64url:zn,base58:Kn,base58xmr:Vn};function nr(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`positive integer expected, not ${e}`)}function rr(e){if("boolean"!=typeof e)throw new Error(`boolean expected, not ${e}`)}function or(e,...t){if(!((n=e)instanceof Uint8Array||null!=n&&"object"==typeof n&&"Uint8Array"===n.constructor.name))throw new Error("Uint8Array expected");var n;if(t.length>0&&!t.includes(e.length))throw new Error(`Uint8Array expected of length ${t}, not of length=${e.length}`)}
/*! noble-ciphers - MIT License (c) 2023 Paul Miller (paulmillr.com) */Object.keys(tr).join(", ");const ir=e=>new Uint32Array(e.buffer,e.byteOffset,Math.floor(e.byteLength/4));if(!(68===new Uint8Array(new Uint32Array([287454020]).buffer)[0]))throw new Error("Non little-endian hardware is not supported");const sr=16;function ar(e){return e<<1^283&-(e>>7)}function cr(e,t){let n=0;for(;t>0;t>>=1)n^=e&-(1&t),e=ar(e);return n}const lr=(()=>{let e=new Uint8Array(256);for(let t=0,n=1;t<256;t++,n^=ar(n))e[t]=n;const t=new Uint8Array(256);t[0]=99;for(let n=0;n<255;n++){let r=e[255-n];r|=r<<8,t[e[n]]=255&(r^r>>4^r>>5^r>>6^r>>7^99)}return t})(),ur=lr.map((e,t)=>lr.indexOf(t)),dr=e=>e<<24|e>>>8,fr=e=>e<<8|e>>>24;function hr(e,t){if(256!==e.length)throw new Error("Wrong sbox length");const n=new Uint32Array(256).map((n,r)=>t(e[r])),r=n.map(fr),o=r.map(fr),i=o.map(fr),s=new Uint32Array(65536),a=new Uint32Array(65536),c=new Uint16Array(65536);for(let t=0;t<256;t++)for(let l=0;l<256;l++){const u=256*t+l;s[u]=n[t]^r[l],a[u]=o[t]^i[l],c[u]=e[t]<<8|e[l]}return{sbox:e,sbox2:c,T0:n,T1:r,T2:o,T3:i,T01:s,T23:a}}const pr=hr(lr,e=>cr(e,3)<<24|e<<16|e<<8|cr(e,2)),yr=hr(ur,e=>cr(e,11)<<24|cr(e,13)<<16|cr(e,9)<<8|cr(e,14)),gr=(()=>{const e=new Uint8Array(16);for(let t=0,n=1;t<16;t++,n=ar(n))e[t]=n;return e})();function mr(e){or(e);const t=e.length;if(![16,24,32].includes(t))throw new Error(`aes: wrong key size: should be 16, 24 or 32, got: ${t}`);const{sbox2:n}=pr,r=ir(e),o=r.length,i=e=>wr(n,e,e,e,e),s=new Uint32Array(t+28);s.set(r);for(let e=o;e<s.length;e++){let t=s[e-1];e%o===0?t=i(dr(t))^gr[e/o-1]:o>6&&e%o===4&&(t=i(t)),s[e]=s[e-o]^t}return s}function vr(e,t,n,r,o,i){return e[n<<8&65280|r>>>8&255]^t[o>>>8&65280|i>>>24&255]}function wr(e,t,n,r,o){return e[255&t|65280&n]|e[r>>>16&255|o>>>16&65280]<<16}function br(e,t,n,r,o){const{sbox2:i,T01:s,T23:a}=pr;let c=0;t^=e[c++],n^=e[c++],r^=e[c++],o^=e[c++];const l=e.length/4-2;for(let i=0;i<l;i++){const i=e[c++]^vr(s,a,t,n,r,o),l=e[c++]^vr(s,a,n,r,o,t),u=e[c++]^vr(s,a,r,o,t,n),d=e[c++]^vr(s,a,o,t,n,r);t=i,n=l,r=u,o=d}return{s0:e[c++]^wr(i,t,n,r,o),s1:e[c++]^wr(i,n,r,o,t),s2:e[c++]^wr(i,r,o,t,n),s3:e[c++]^wr(i,o,t,n,r)}}function xr(e,t,n,r,o){const{sbox2:i,T01:s,T23:a}=yr;let c=0;t^=e[c++],n^=e[c++],r^=e[c++],o^=e[c++];const l=e.length/4-2;for(let i=0;i<l;i++){const i=e[c++]^vr(s,a,t,o,r,n),l=e[c++]^vr(s,a,n,t,o,r),u=e[c++]^vr(s,a,r,n,t,o),d=e[c++]^vr(s,a,o,r,n,t);t=i,n=l,r=u,o=d}return{s0:e[c++]^wr(i,t,o,r,n),s1:e[c++]^wr(i,n,t,o,r),s2:e[c++]^wr(i,r,n,t,o),s3:e[c++]^wr(i,o,r,n,t)}}function Er(e,t){if(!t)return new Uint8Array(e);if(or(t),t.length<e)throw new Error(`aes: wrong destination length, expected at least ${e}, got: ${t.length}`);return t}const kr=(Sr={blockSize:16,nonceLength:16},Ar=function(e,t,n={}){or(e),or(t,16);const r=!n.disablePadding;return{encrypt:(n,o)=>{const i=mr(e),{b:s,o:a,out:c}=function(e,t,n){let r=e.length;const o=r%sr;if(!t&&0!==o)throw new Error("aec/(cbc-ecb): unpadded plaintext with disabled padding");const i=ir(e);if(t){let e=sr-o;e||(e=sr),r+=e}const s=Er(r,n);return{b:i,o:ir(s),out:s}}(n,r,o),l=ir(t);let u=l[0],d=l[1],f=l[2],h=l[3],p=0;for(;p+4<=s.length;)u^=s[p+0],d^=s[p+1],f^=s[p+2],h^=s[p+3],({s0:u,s1:d,s2:f,s3:h}=br(i,u,d,f,h)),a[p++]=u,a[p++]=d,a[p++]=f,a[p++]=h;if(r){const e=function(e){const t=new Uint8Array(16),n=ir(t);t.set(e);const r=sr-e.length;for(let e=sr-r;e<sr;e++)t[e]=r;return n}(n.subarray(4*p));u^=e[0],d^=e[1],f^=e[2],h^=e[3],({s0:u,s1:d,s2:f,s3:h}=br(i,u,d,f,h)),a[p++]=u,a[p++]=d,a[p++]=f,a[p++]=h}return i.fill(0),c},decrypt:(n,o)=>{!function(e){if(or(e),e.length%sr!==0)throw new Error("aes/(cbc-ecb).decrypt ciphertext should consist of blocks with size 16")}(n);const i=function(e){const t=mr(e),n=t.slice(),r=t.length,{sbox2:o}=pr,{T0:i,T1:s,T2:a,T3:c}=yr;for(let e=0;e<r;e+=4)for(let o=0;o<4;o++)n[e+o]=t[r-e-4+o];t.fill(0);for(let e=4;e<r-4;e++){const t=n[e],r=wr(o,t,t,t,t);n[e]=i[255&r]^s[r>>>8&255]^a[r>>>16&255]^c[r>>>24]}return n}(e),s=ir(t),a=Er(n.length,o),c=ir(n),l=ir(a);let u=s[0],d=s[1],f=s[2],h=s[3];for(let e=0;e+4<=c.length;){const t=u,n=d,r=f,o=h;u=c[e+0],d=c[e+1],f=c[e+2],h=c[e+3];const{s0:s,s1:a,s2:p,s3:y}=xr(i,u,d,f,h);l[e++]=s^t,l[e++]=a^n,l[e++]=p^r,l[e++]=y^o}return i.fill(0),function(e,t){if(!t)return e;const n=e.length;if(!n)throw new Error("aes/pcks5: empty ciphertext not allowed");const r=e[n-1];if(r<=0||r>16)throw new Error(`aes/pcks5: wrong padding byte: ${r}`);const o=e.subarray(0,-r);for(let t=0;t<r;t++)if(e[n-t-1]!==r)throw new Error("aes/pcks5: wrong padding");return o}(a,r)}}},Object.assign(Ar,Sr),Ar);var Sr,Ar;const Cr=e=>Uint8Array.from(e.split("").map(e=>e.charCodeAt(0))),Tr=Cr("expand 16-byte k"),_r=Cr("expand 32-byte k"),$r=ir(Tr),Ir=ir(_r);function Or(e,t){return e<<t|e>>>32-t}function Rr(e){return e.byteOffset%4==0}Ir.slice();const Pr=2**32-1,Lr=new Uint32Array;function Br(e,t){const{allowShortKeys:n,extendNonceFn:r,counterLength:o,counterRight:i,rounds:s}=function(e,t){if(null==t||"object"!=typeof t)throw new Error("options must be defined");return Object.assign(e,t)}({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},t);if("function"!=typeof e)throw new Error("core must be a function");return nr(o),nr(s),rr(i),rr(n),(t,a,c,l,u=0)=>{or(t),or(a),or(c);const d=c.length;if(l||(l=new Uint8Array(d)),or(l),nr(u),u<0||u>=Pr)throw new Error("arx: counter overflow");if(l.length<d)throw new Error(`arx: output (${l.length}) is shorter than data (${d})`);const f=[];let h,p,y=t.length;if(32===y)h=t.slice(),f.push(h),p=Ir;else{if(16!==y||!n)throw new Error(`arx: invalid 32-byte key, got length=${y}`);h=new Uint8Array(32),h.set(t),h.set(t,16),p=$r,f.push(h)}Rr(a)||(a=a.slice(),f.push(a));const g=ir(h);if(r){if(24!==a.length)throw new Error("arx: extended nonce must be 24 bytes");r(p,g,ir(a.subarray(0,16)),g),a=a.subarray(16)}const m=16-o;if(m!==a.length)throw new Error(`arx: nonce must be ${m} or 16 bytes`);if(12!==m){const e=new Uint8Array(12);e.set(a,i?0:12-a.length),a=e,f.push(a)}const v=ir(a);for(!function(e,t,n,r,o,i,s,a){const c=o.length,l=new Uint8Array(64),u=ir(l),d=Rr(o)&&Rr(i),f=d?ir(o):Lr,h=d?ir(i):Lr;for(let p=0;p<c;s++){if(e(t,n,r,u,s,a),s>=Pr)throw new Error("arx: counter overflow");const y=Math.min(64,c-p);if(d&&64===y){const e=p/4;if(p%4!=0)throw new Error("arx: invalid block position");for(let t,n=0;n<16;n++)t=e+n,h[t]=f[t]^u[n];p+=64;continue}for(let e,t=0;t<y;t++)e=p+t,i[e]=o[e]^l[t];p+=y}}(e,p,g,v,c,l,u,s);f.length>0;)f.pop().fill(0);return l}}function Nr(e,t,n,r,o,i=20){let s=e[0],a=e[1],c=e[2],l=e[3],u=t[0],d=t[1],f=t[2],h=t[3],p=t[4],y=t[5],g=t[6],m=t[7],v=o,w=n[0],b=n[1],x=n[2],E=s,k=a,S=c,A=l,C=u,T=d,_=f,$=h,I=p,O=y,R=g,P=m,L=v,B=w,N=b,U=x;for(let e=0;e<i;e+=2)E=E+C|0,L=Or(L^E,16),I=I+L|0,C=Or(C^I,12),E=E+C|0,L=Or(L^E,8),I=I+L|0,C=Or(C^I,7),k=k+T|0,B=Or(B^k,16),O=O+B|0,T=Or(T^O,12),k=k+T|0,B=Or(B^k,8),O=O+B|0,T=Or(T^O,7),S=S+_|0,N=Or(N^S,16),R=R+N|0,_=Or(_^R,12),S=S+_|0,N=Or(N^S,8),R=R+N|0,_=Or(_^R,7),A=A+$|0,U=Or(U^A,16),P=P+U|0,$=Or($^P,12),A=A+$|0,U=Or(U^A,8),P=P+U|0,$=Or($^P,7),E=E+T|0,U=Or(U^E,16),R=R+U|0,T=Or(T^R,12),E=E+T|0,U=Or(U^E,8),R=R+U|0,T=Or(T^R,7),k=k+_|0,L=Or(L^k,16),P=P+L|0,_=Or(_^P,12),k=k+_|0,L=Or(L^k,8),P=P+L|0,_=Or(_^P,7),S=S+$|0,B=Or(B^S,16),I=I+B|0,$=Or($^I,12),S=S+$|0,B=Or(B^S,8),I=I+B|0,$=Or($^I,7),A=A+C|0,N=Or(N^A,16),O=O+N|0,C=Or(C^O,12),A=A+C|0,N=Or(N^A,8),O=O+N|0,C=Or(C^O,7);let j=0;r[j++]=s+E|0,r[j++]=a+k|0,r[j++]=c+S|0,r[j++]=l+A|0,r[j++]=u+C|0,r[j++]=d+T|0,r[j++]=f+_|0,r[j++]=h+$|0,r[j++]=p+I|0,r[j++]=y+O|0,r[j++]=g+R|0,r[j++]=m+P|0,r[j++]=v+L|0,r[j++]=w+B|0,r[j++]=b+N|0,r[j++]=x+U|0}const Ur=Br(Nr,{counterRight:!1,counterLength:4,allowShortKeys:!1});class jr extends Gt{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,en.hash(e);const n=Jt(t);if(this.iHash=e.create(),"function"!=typeof this.iHash.update)throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;const r=this.blockLen,o=new Uint8Array(r);o.set(n.length>r?e.create().update(n).digest():n);for(let e=0;e<o.length;e++)o[e]^=54;this.iHash.update(o),this.oHash=e.create();for(let e=0;e<o.length;e++)o[e]^=106;this.oHash.update(o),o.fill(0)}update(e){return en.exists(this),this.iHash.update(e),this}digestInto(e){en.exists(this),en.bytes(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:t,iHash:n,finished:r,destroyed:o,blockLen:i,outputLen:s}=this;return e.finished=r,e.destroyed=o,e.blockLen=i,e.outputLen=s,e.oHash=t._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}const Mr=(e,t,n)=>new jr(e,t).update(n).digest();Mr.create=(e,t)=>new jr(e,t);const Fr=new Uint8Array([0]),Dr=new Uint8Array;var Hr=Object.defineProperty,qr=(e,t)=>{for(var n in t)Hr(e,n,{get:t[n],enumerable:!0})},zr=Symbol("verified");function Wr(e){if(!(e instanceof Object))return!1;if("number"!=typeof e.kind)return!1;if("string"!=typeof e.content)return!1;if("number"!=typeof e.created_at)return!1;if("string"!=typeof e.pubkey)return!1;if(!e.pubkey.match(/^[a-f0-9]{64}$/))return!1;if(!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 e=0;e<n.length;e++)if("string"!=typeof n[e])return!1}return!0}qr({},{Queue:()=>Xr,QueueNode:()=>Qr,binarySearch:()=>Yr,bytesToHex:()=>Wt,hexToBytes:()=>Kt,insertEventIntoAscendingList:()=>Zr,insertEventIntoDescendingList:()=>Gr,normalizeURL:()=>Vr,utf8Decoder:()=>Kr,utf8Encoder:()=>Jr});var Kr=new TextDecoder("utf-8"),Jr=new TextEncoder;function Vr(e){try{-1===e.indexOf("://")&&(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)),("80"===t.port&&"ws:"===t.protocol||"443"===t.port&&"wss:"===t.protocol)&&(t.port=""),t.searchParams.sort(),t.hash="",t.toString()}catch(t){throw new Error(`Invalid URL: ${e}`)}}function Gr(e,t){const[n,r]=Yr(e,e=>t.id===e.id?0:t.created_at===e.created_at?-1:e.created_at-t.created_at);return r||e.splice(n,0,t),e}function Zr(e,t){const[n,r]=Yr(e,e=>t.id===e.id?0:t.created_at===e.created_at?-1:t.created_at-e.created_at);return r||e.splice(n,0,t),e}function Yr(e,t){let n=0,r=e.length-1;for(;n<=r;){const o=Math.floor((n+r)/2),i=t(e[o]);if(0===i)return[o,!0];i<0?r=o-1:n=o+1}return[n,!1]}var Qr=class{value;next=null;prev=null;constructor(e){this.value=e}},Xr=class{first;last;constructor(){this.first=null,this.last=null}enqueue(e){const t=new Qr(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 e=this.first;return this.first=null,this.last=null,e.value}const e=this.first;return this.first=e.next,this.first&&(this.first.prev=null),e.value}};function eo(e){return Wt(un(Jr.encode(function(e){if(!Wr(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])}(e))))}var to=new class{generateSecretKey(){return Mt.utils.randomPrivateKey()}getPublicKey(e){return Wt(Mt.getPublicKey(e))}finalizeEvent(e,t){const n=e;return n.pubkey=Wt(Mt.getPublicKey(t)),n.id=eo(n),n.sig=Wt(Mt.sign(eo(n),t)),n[zr]=!0,n}verifyEvent(e){if("boolean"==typeof e[zr])return e[zr];const t=eo(e);if(t!==e.id)return e[zr]=!1,!1;try{const n=Mt.verify(e.sig,t,e.pubkey);return e[zr]=n,n}catch(t){return e[zr]=!1,!1}}},no=to.generateSecretKey,ro=to.getPublicKey,oo=to.finalizeEvent,io=to.verifyEvent,so={};function ao(e){return 1e3<=e&&e<1e4||[1,2,4,5,6,7,8,16,40,41,42,43,44].includes(e)}function co(e){return[0,3].includes(e)||1e4<=e&&e<2e4}function lo(e){return 2e4<=e&&e<3e4}function uo(e){return 3e4<=e&&e<4e4}function fo(e){return ao(e)?"regular":co(e)?"replaceable":lo(e)?"ephemeral":uo(e)?"parameterized":"unknown"}function ho(e,t){const n=t instanceof Array?t:[t];return Wr(e)&&n.includes(e.kind)||!1}qr(so,{Application:()=>Ai,BadgeAward:()=>Eo,BadgeDefinition:()=>vi,BlockedRelaysList:()=>Xo,BookmarkList:()=>Zo,Bookmarksets:()=>yi,Calendar:()=>Ri,CalendarEventRSVP:()=>Pi,ChannelCreation:()=>Co,ChannelHideMessage:()=>$o,ChannelMessage:()=>_o,ChannelMetadata:()=>To,ChannelMuteUser:()=>Io,ClassifiedListing:()=>_i,ClientAuth:()=>ai,CommunitiesList:()=>Yo,CommunityDefinition:()=>Ni,CommunityPostApproval:()=>Mo,Contacts:()=>mo,CreateOrUpdateProduct:()=>xi,CreateOrUpdateStall:()=>bi,Curationsets:()=>gi,Date:()=>Ii,DirectMessageRelaysList:()=>ri,DraftClassifiedListing:()=>$i,DraftLong:()=>ki,Emojisets:()=>Si,EncryptedDirectMessage:()=>vo,EventDeletion:()=>wo,FileMetadata:()=>Po,FileServerPreference:()=>oi,Followsets:()=>fi,GenericRepost:()=>Ao,Genericlists:()=>hi,GiftWrap:()=>Ro,HTTPAuth:()=>di,Handlerinformation:()=>Bi,Handlerrecommendation:()=>Li,Highlights:()=>Ko,InterestsList:()=>ti,Interestsets:()=>wi,JobFeedback:()=>Ho,JobRequest:()=>Fo,JobResult:()=>Do,Label:()=>jo,LightningPubRPC:()=>si,LiveChatMessage:()=>Lo,LiveEvent:()=>Ci,LongFormArticle:()=>Ei,Metadata:()=>po,Mutelist:()=>Jo,NWCWalletInfo:()=>ii,NWCWalletRequest:()=>ci,NWCWalletResponse:()=>li,NostrConnect:()=>ui,OpenTimestamps:()=>Oo,Pinlist:()=>Vo,PrivateDirectMessage:()=>So,ProblemTracker:()=>Bo,ProfileBadges:()=>mi,PublicChatsList:()=>Qo,Reaction:()=>xo,RecommendRelay:()=>go,RelayList:()=>Go,Relaysets:()=>pi,Report:()=>No,Reporting:()=>Uo,Repost:()=>bo,Seal:()=>ko,SearchRelaysList:()=>ei,ShortTextNote:()=>yo,Time:()=>Oi,UserEmojiList:()=>ni,UserStatuses:()=>Ti,Zap:()=>Wo,ZapGoal:()=>qo,ZapRequest:()=>zo,classifyKind:()=>fo,isAddressableKind:()=>uo,isEphemeralKind:()=>lo,isKind:()=>ho,isRegularKind:()=>ao,isReplaceableKind:()=>co});var po=0,yo=1,go=2,mo=3,vo=4,wo=5,bo=6,xo=7,Eo=8,ko=13,So=14,Ao=16,Co=40,To=41,_o=42,$o=43,Io=44,Oo=1040,Ro=1059,Po=1063,Lo=1311,Bo=1971,No=1984,Uo=1984,jo=1985,Mo=4550,Fo=5999,Do=6999,Ho=7e3,qo=9041,zo=9734,Wo=9735,Ko=9802,Jo=1e4,Vo=10001,Go=10002,Zo=10003,Yo=10004,Qo=10005,Xo=10006,ei=10007,ti=10015,ni=10030,ri=10050,oi=10096,ii=13194,si=21e3,ai=22242,ci=23194,li=23195,ui=24133,di=27235,fi=3e4,hi=30001,pi=30002,yi=30003,gi=30004,mi=30008,vi=30009,wi=30015,bi=30017,xi=30018,Ei=30023,ki=30024,Si=30030,Ai=30078,Ci=30311,Ti=30315,_i=30402,$i=30403,Ii=31922,Oi=31923,Ri=31924,Pi=31925,Li=31989,Bi=31990,Ni=34550;function Ui(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 ji(e,t){let n=t.length,r=e.indexOf(`"${t}":`)+n+3,o=e.slice(r),i=Math.min(o.indexOf(","),o.indexOf("}"));return parseInt(o.slice(0,i),10)}function Mi(e){let t=e.slice(0,22).indexOf('"EVENT"');if(-1===t)return null;let n=e.slice(t+7+1).indexOf('"');if(-1===n)return null;let r=t+7+1+n,o=e.slice(r+1,80).indexOf('"');if(-1===o)return null;let i=r+1+o;return e.slice(r+1,i)}function Fi(e,t){return t===Ui(e,"id")}function Di(e,t){return t===Ui(e,"pubkey")}function Hi(e,t){return t===ji(e,"kind")}qr({},{getHex64:()=>Ui,getInt:()=>ji,getSubscriptionId:()=>Mi,matchEventId:()=>Fi,matchEventKind:()=>Hi,matchEventPubkey:()=>Di});function qi(e,t){return{kind:ai,created_at:Math.floor(Date.now()/1e3),tags:[["relay",e],["challenge",t]],content:""}}qr({},{makeAuthEvent:()=>qi});try{WebSocket}catch{}try{WebSocket}catch{}var zi={};qr(zi,{BECH32_REGEX:()=>Ji,Bech32MaxSize:()=>Ki,NostrTypeGuard:()=>Wi,decode:()=>Gi,decodeNostrURI:()=>Vi,encodeBytes:()=>ts,naddrEncode:()=>os,neventEncode:()=>rs,noteEncode:()=>Xi,nprofileEncode:()=>ns,npubEncode:()=>Qi,nsecEncode:()=>Yi});var Wi={isNProfile:e=>/^nprofile1[a-z\d]+$/.test(e||""),isNEvent:e=>/^nevent1[a-z\d]+$/.test(e||""),isNAddr:e=>/^naddr1[a-z\d]+$/.test(e||""),isNSec:e=>/^nsec1[a-z\d]{58}$/.test(e||""),isNPub:e=>/^npub1[a-z\d]{58}$/.test(e||""),isNote:e=>/^note1[a-z\d]+$/.test(e||""),isNcryptsec:e=>/^ncryptsec1[a-z\d]+$/.test(e||"")},Ki=5e3,Ji=/[\x21-\x7E]{1,83}1[023456789acdefghjklmnpqrstuvwxyz]{6,}/;function Vi(e){try{return e.startsWith("nostr:")&&(e=e.substring(6)),Gi(e)}catch(e){return{type:"invalid",data:null}}}function Gi(e){let{prefix:t,words:n}=er.decode(e,Ki),r=new Uint8Array(er.fromWords(n));switch(t){case"nprofile":{let e=Zi(r);if(!e[0]?.[0])throw new Error("missing TLV 0 for nprofile");if(32!==e[0][0].length)throw new Error("TLV 0 should be 32 bytes");return{type:"nprofile",data:{pubkey:Wt(e[0][0]),relays:e[1]?e[1].map(e=>Kr.decode(e)):[]}}}case"nevent":{let e=Zi(r);if(!e[0]?.[0])throw new Error("missing TLV 0 for nevent");if(32!==e[0][0].length)throw new Error("TLV 0 should be 32 bytes");if(e[2]&&32!==e[2][0].length)throw new Error("TLV 2 should be 32 bytes");if(e[3]&&4!==e[3][0].length)throw new Error("TLV 3 should be 4 bytes");return{type:"nevent",data:{id:Wt(e[0][0]),relays:e[1]?e[1].map(e=>Kr.decode(e)):[],author:e[2]?.[0]?Wt(e[2][0]):void 0,kind:e[3]?.[0]?parseInt(Wt(e[3][0]),16):void 0}}}case"naddr":{let e=Zi(r);if(!e[0]?.[0])throw new Error("missing TLV 0 for naddr");if(!e[2]?.[0])throw new Error("missing TLV 2 for naddr");if(32!==e[2][0].length)throw new Error("TLV 2 should be 32 bytes");if(!e[3]?.[0])throw new Error("missing TLV 3 for naddr");if(4!==e[3][0].length)throw new Error("TLV 3 should be 4 bytes");return{type:"naddr",data:{identifier:Kr.decode(e[0][0]),pubkey:Wt(e[2][0]),kind:parseInt(Wt(e[3][0]),16),relays:e[1]?e[1].map(e=>Kr.decode(e)):[]}}}case"nsec":return{type:t,data:r};case"npub":case"note":return{type:t,data:Wt(r)};default:throw new Error(`unknown prefix ${t}`)}}function Zi(e){let t={},n=e;for(;n.length>0;){let e=n[0],r=n[1],o=n.slice(2,2+r);if(n=n.slice(2+r),o.length<r)throw new Error(`not enough data to read on TLV ${e}`);t[e]=t[e]||[],t[e].push(o)}return t}function Yi(e){return ts("nsec",e)}function Qi(e){return ts("npub",Kt(e))}function Xi(e){return ts("note",Kt(e))}function es(e,t){let n=er.toWords(t);return er.encode(e,n,Ki)}function ts(e,t){return es(e,t)}function ns(e){return es("nprofile",is({0:[Kt(e.pubkey)],1:(e.relays||[]).map(e=>Jr.encode(e))}))}function rs(e){let t;return void 0!==e.kind&&(t=function(e){const t=new Uint8Array(4);return t[0]=e>>24&255,t[1]=e>>16&255,t[2]=e>>8&255,t[3]=255&e,t}(e.kind)),es("nevent",is({0:[Kt(e.id)],1:(e.relays||[]).map(e=>Jr.encode(e)),2:e.author?[Kt(e.author)]:[],3:t?[new Uint8Array(t)]:[]}))}function os(e){let t=new ArrayBuffer(4);return new DataView(t).setUint32(0,e.kind,!1),es("naddr",is({0:[Jr.encode(e.identifier)],1:(e.relays||[]).map(e=>Jr.encode(e)),2:[Kt(e.pubkey)],3:[new Uint8Array(t)]}))}function is(e){let t=[];return Object.entries(e).reverse().forEach(([e,n])=>{n.forEach(n=>{let r=new Uint8Array(n.length+2);r.set([parseInt(e)],0),r.set([n.length],1),r.set(n,2),t.push(r)})}),Vt(...t)}var ss={};function as(e,t,n){const r=e instanceof Uint8Array?Wt(e):e,o=ls(kt.getSharedSecret(r,"02"+t));let i=Uint8Array.from(Yt(16)),s=Jr.encode(n),a=kr(o,i).encrypt(s);return`${qn.encode(new Uint8Array(a))}?iv=${qn.encode(new Uint8Array(i.buffer))}`}function cs(e,t,n){const r=e instanceof Uint8Array?Wt(e):e;let[o,i]=n.split("?iv="),s=ls(kt.getSharedSecret(r,"02"+t)),a=qn.decode(i),c=qn.decode(o),l=kr(s,a).decrypt(c);return Kr.decode(l)}function ls(e){return e.slice(1,33)}qr(ss,{decrypt:()=>cs,encrypt:()=>as});qr({},{NIP05_REGEX:()=>ds,isNip05:()=>fs,isValid:()=>gs,queryProfile:()=>ys,searchDomain:()=>ps,useFetchImplementation:()=>hs});var us,ds=/^(?:([\w.+-]+)@)?([\w_-]+(\.[\w_-]+)+)$/,fs=e=>ds.test(e||"");try{us=fetch}catch(e){}function hs(e){us=e}async function ps(e,t=""){try{const n=`https://${e}/.well-known/nostr.json?name=${t}`,r=await us(n,{redirect:"manual"});if(200!==r.status)throw Error("Wrong response code");return(await r.json()).names}catch(e){return{}}}async function ys(e){const t=e.match(ds);if(!t)return null;const[,n="_",r]=t;try{const e=`https://${r}/.well-known/nostr.json?name=${n}`,t=await us(e,{redirect:"manual"});if(200!==t.status)throw Error("Wrong response code");const o=await t.json(),i=o.names[n];return i?{pubkey:i,relays:o.relays?.[i]}:null}catch(e){return null}}async function gs(e,t){const n=await ys(t);return!!n&&n.pubkey===e}function ms(e){const t={reply:void 0,root:void 0,mentions:[],profiles:[],quotes:[]};let n,r;for(let o=e.tags.length-1;o>=0;o--){const i=e.tags[o];if("e"===i[0]&&i[1]){const[e,o,s,a,c]=i,l={id:o,relays:s?[s]:[],author:c};if("root"===a){t.root=l;continue}if("reply"===a){t.reply=l;continue}if("mention"===a){t.mentions.push(l);continue}n?r=l:n=l,t.mentions.push(l);continue}if("q"===i[0]&&i[1]){const[e,n,r]=i;t.quotes.push({id:n,relays:r?[r]:[]})}"p"===i[0]&&i[1]&&t.profiles.push({pubkey:i[1],relays:i[2]?[i[2]]:[]})}return t.root||(t.root=r||n||t.reply),t.reply||(t.reply=n||t.root),[t.reply,t.root].forEach(e=>{if(!e)return;let n=t.mentions.indexOf(e);if(-1!==n&&t.mentions.splice(n,1),e.author){let n=t.profiles.find(t=>t.pubkey===e.author);n&&n.relays&&(e.relays||(e.relays=[]),n.relays.forEach(t=>{-1===e.relays?.indexOf(t)&&e.relays.push(t)}),n.relays=e.relays)}}),t.mentions.forEach(e=>{if(e.author){let n=t.profiles.find(t=>t.pubkey===e.author);n&&n.relays&&(e.relays||(e.relays=[]),n.relays.forEach(t=>{-1===e.relays.indexOf(t)&&e.relays.push(t)}),n.relays=e.relays)}}),t}qr({},{parse:()=>ms});qr({},{fetchRelayInformation:()=>ws,useFetchImplementation:()=>vs});try{fetch}catch{}function vs(e){0}async function ws(e){return await(await fetch(e.replace("ws://","http://").replace("wss://","https://"),{headers:{Accept:"application/nostr+json"}})).json()}function bs(e){let t=0;for(let n=0;n<64;n+=8){const r=parseInt(e.substring(n,n+8),16);if(0!==r){t+=Math.clz32(r);break}t+=32}return t}function xs(e,t){let n=0;const r=e,o=["nonce",n.toString(),t.toString()];for(r.tags.push(o);;){const e=Math.floor((new Date).getTime()/1e3);if(e!==r.created_at&&(n=0,r.created_at=e),o[1]=(++n).toString(),r.id=Es(r),bs(r.id)>=t)break}return r}function Es(e){return Wt(un(Jr.encode(JSON.stringify([0,e.pubkey,e.created_at,e.kind,e.tags,e.content]))))}qr({},{fastEventHash:()=>Es,getPow:()=>bs,minePow:()=>xs});qr({},{unwrapEvent:()=>Vs,unwrapManyEvents:()=>Gs,wrapEvent:()=>Ks,wrapManyEvents:()=>Js});qr({},{createRumor:()=>Ms,createSeal:()=>Fs,createWrap:()=>Ds,unwrapEvent:()=>zs,unwrapManyEvents:()=>Ws,wrapEvent:()=>Hs,wrapManyEvents:()=>qs});var ks={};qr(ks,{decrypt:()=>Rs,encrypt:()=>Os,getConversationKey:()=>Cs,v2:()=>Ps});var Ss=1,As=65535;function Cs(e,t){const n=kt.getSharedSecret(e,"02"+t).subarray(1,33);return function(e,t,n){return en.hash(e),void 0===n&&(n=new Uint8Array(e.outputLen)),Mr(e,Jt(n),Jt(t))}(un,n,"nip44-v2")}function Ts(e,t){const n=function(e,t,n,r=32){if(en.hash(e),en.number(r),r>255*e.outputLen)throw new Error("Length should be <= 255*HashLen");const o=Math.ceil(r/e.outputLen);void 0===n&&(n=Dr);const i=new Uint8Array(o*e.outputLen),s=Mr.create(e,t),a=s._cloneInto(),c=new Uint8Array(s.outputLen);for(let t=0;t<o;t++)Fr[0]=t+1,a.update(0===t?Dr:c).update(n).update(Fr).digestInto(c),i.set(c,e.outputLen*t),s._cloneInto(a);return s.destroy(),a.destroy(),c.fill(0),Fr.fill(0),i.slice(0,r)}(un,e,t,76);return{chacha_key:n.subarray(0,32),chacha_nonce:n.subarray(32,44),hmac_key:n.subarray(44,76)}}function _s(e){if(!Number.isSafeInteger(e)||e<1)throw new Error("expected positive integer");if(e<=32)return 32;const t=1<<Math.floor(Math.log2(e-1))+1,n=t<=256?32:t/8;return n*(Math.floor((e-1)/n)+1)}function $s(e){const t=Jr.encode(e),n=t.length;return Vt(function(e){if(!Number.isSafeInteger(e)||e<Ss||e>As)throw new Error("invalid plaintext size: must be between 1 and 65535 bytes");const t=new Uint8Array(2);return new DataView(t.buffer).setUint16(0,e,!1),t}(n),t,new Uint8Array(_s(n)-n))}function Is(e,t,n){if(32!==n.length)throw new Error("AAD associated data must be 32 bytes");const r=Vt(n,t);return Mr(un,e,r)}function Os(e,t,n=Yt(32)){const{chacha_key:r,chacha_nonce:o,hmac_key:i}=Ts(t,n),s=$s(e),a=Ur(r,o,s),c=Is(i,a,n);return qn.encode(Vt(new Uint8Array([2]),n,a,c))}function Rs(e,t){const{nonce:n,ciphertext:r,mac:o}=function(e){if("string"!=typeof e)throw new Error("payload must be a valid string");const t=e.length;if(t<132||t>87472)throw new Error("invalid payload length: "+t);if("#"===e[0])throw new Error("unknown encryption version");let n;try{n=qn.decode(e)}catch(e){throw new Error("invalid base64: "+e.message)}const r=n.length;if(r<99||r>65603)throw new Error("invalid data length: "+r);const o=n[0];if(2!==o)throw new Error("unknown encryption version "+o);return{nonce:n.subarray(1,33),ciphertext:n.subarray(33,-32),mac:n.subarray(-32)}}(e),{chacha_key:i,chacha_nonce:s,hmac_key:a}=Ts(t,n);if(!function(e,t){if(e.length!==t.length)return!1;let n=0;for(let r=0;r<e.length;r++)n|=e[r]^t[r];return 0===n}(Is(a,r,n),o))throw new Error("invalid MAC");return function(e){const t=new DataView(e.buffer).getUint16(0),n=e.subarray(2,2+t);if(t<Ss||t>As||n.length!==t||e.length!==2+_s(t))throw new Error("invalid padding");return Kr.decode(n)}(Ur(i,s,r))}var Ps={utils:{getConversationKey:Cs,calcPaddedLen:_s},encrypt:Os,decrypt:Rs},Ls=()=>Math.round(Date.now()/1e3),Bs=()=>Math.round(Ls()-172800*Math.random()),Ns=(e,t)=>Cs(e,t),Us=(e,t,n)=>Os(JSON.stringify(e),Ns(t,n)),js=(e,t)=>JSON.parse(Rs(e.content,Ns(t,e.pubkey)));function Ms(e,t){const n={created_at:Ls(),content:"",tags:[],...e,pubkey:ro(t)};return n.id=eo(n),n}function Fs(e,t,n){return oo({kind:ko,content:Us(e,t,n),created_at:Bs(),tags:[]},t)}function Ds(e,t){const n=no();return oo({kind:Ro,content:Us(e,n,t),created_at:Bs(),tags:[["p",t]]},n)}function Hs(e,t,n){return Ds(Fs(Ms(e,t),t,n),n)}function qs(e,t,n){if(!n||0===n.length)throw new Error("At least one recipient is required.");const r=ro(t),o=[Hs(e,t,r)];return n.forEach(n=>{o.push(Hs(e,t,n))}),o}function zs(e,t){const n=js(e,t);return js(n,t)}function Ws(e,t){let n=[];return e.forEach(e=>{n.push(zs(e,t))}),n.sort((e,t)=>e.created_at-t.created_at),n}function Ks(e,t,n,r,o){const i=function(e,t,n,r){const o={created_at:Math.ceil(Date.now()/1e3),kind:So,tags:[],content:t};return(Array.isArray(e)?e:[e]).forEach(({publicKey:e,relayUrl:t})=>{o.tags.push(t?["p",e,t]:["p",e])}),r&&o.tags.push(["e",r.eventId,r.relayUrl||"","reply"]),n&&o.tags.push(["subject",n]),o}(t,n,r,o);return Hs(i,e,t.publicKey)}function Js(e,t,n,r,o){if(!t||0===t.length)throw new Error("At least one recipient is required.");return[{publicKey:ro(e)},...t].map(t=>Ks(e,t,n,r,o))}var Vs=zs,Gs=Ws;function Zs(e,t,n,r){let o;const i=[...e.tags??[],["e",t.id,n],["p",t.pubkey]];return t.kind===yo?o=bo:(o=Ao,i.push(["k",String(t.kind)])),oo({kind:o,tags:i,content:""===e.content||t.tags?.find(e=>"-"===e[0])?"":JSON.stringify(t),created_at:e.created_at},r)}function Ys(e){if(![bo,Ao].includes(e.kind))return;let t,n;for(let r=e.tags.length-1;r>=0&&(void 0===t||void 0===n);r--){const o=e.tags[r];o.length>=2&&("e"===o[0]&&void 0===t?t=o:"p"===o[0]&&void 0===n&&(n=o))}return void 0!==t?{id:t[1],relays:[t[2],n?.[2]].filter(e=>"string"==typeof e),author:n?.[1]}:void 0}function Qs(e,{skipVerification:t}={}){const n=Ys(e);if(void 0===n||""===e.content)return;let r;try{r=JSON.parse(e.content)}catch(e){return}return r.id===n.id&&(t||io(r))?r:void 0}qr({},{finishRepostEvent:()=>Zs,getRepostedEvent:()=>Qs,getRepostedEventPointer:()=>Ys});qr({},{NOSTR_URI_REGEX:()=>Xs,parse:()=>ta,test:()=>ea});var Xs=new RegExp(`nostr:(${Ji.source})`);function ea(e){return"string"==typeof e&&new RegExp(`^${Xs.source}$`).test(e)}function ta(e){const t=e.match(new RegExp(`^${Xs.source}$`));if(!t)throw new Error(`Invalid Nostr URI: ${e}`);return{uri:t[0],value:t[1],decoded:Gi(t[1])}}function na(e,t,n){const r=t.tags.filter(e=>e.length>=2&&("e"===e[0]||"p"===e[0]));return oo({...e,kind:xo,tags:[...e.tags??[],...r,["e",t.id],["p",t.pubkey]],content:e.content??"+"},n)}function ra(e){if(e.kind!==xo)return;let t,n;for(let r=e.tags.length-1;r>=0&&(void 0===t||void 0===n);r--){const o=e.tags[r];o.length>=2&&("e"===o[0]&&void 0===t?t=o:"p"===o[0]&&void 0===n&&(n=o))}return void 0!==t&&void 0!==n?{id:t[1],relays:[t[2],n[2]].filter(e=>void 0!==e),author:n[1]}:void 0}qr({},{finishReactionEvent:()=>na,getReactedEventPointer:()=>ra});qr({},{parse:()=>sa});var oa=/\W/m,ia=/\W |\W$|$|,| /m;function*sa(e){const t=e.length;let n=0,r=0;for(;r<t;){let o=e.indexOf(":",r);if(-1===o)break;if("nostr"===e.substring(o-5,o)){const i=e.substring(o+60).match(oa),s=i?o+60+i.index:t;try{let t,{data:i,type:a}=Gi(e.substring(o+1,s));switch(a){case"npub":t={pubkey:i};break;case"nsec":case"note":r=s+1;continue;default:t=i}n!==o-5&&(yield{type:"text",text:e.substring(n,o-5)}),yield{type:"reference",pointer:t},r=s,n=r;continue}catch(e){r=o+1;continue}}else if("https"===e.substring(o-5,o)||"http"===e.substring(o-4,o)){const i=e.substring(o+4).match(ia),s=i?o+4+i.index:t,a="s"===e[o-1]?5:4;try{let t=new URL(e.substring(o-a,s));if(-1===t.hostname.indexOf("."))throw new Error("invalid url");if(n!==o-a&&(yield{type:"text",text:e.substring(n,o-a)}),/\.(png|jpe?g|gif|webp)$/i.test(t.pathname)){yield{type:"image",url:t.toString()},r=s,n=r;continue}if(/\.(mp4|avi|webm|mkv)$/i.test(t.pathname)){yield{type:"video",url:t.toString()},r=s,n=r;continue}if(/\.(mp3|aac|ogg|opus)$/i.test(t.pathname)){yield{type:"audio",url:t.toString()},r=s,n=r;continue}yield{type:"url",url:t.toString()},r=s,n=r;continue}catch(e){r=s+1;continue}}else{if("wss"!==e.substring(o-3,o)&&"ws"!==e.substring(o-2,o)){r=o+1;continue}{const i=e.substring(o+4).match(ia),s=i?o+4+i.index:t,a="s"===e[o-1]?3:2;try{let t=new URL(e.substring(o-a,s));if(-1===t.hostname.indexOf("."))throw new Error("invalid ws url");n!==o-a&&(yield{type:"text",text:e.substring(n,o-a)}),yield{type:"relay",url:t.toString()},r=s,n=r;continue}catch(e){r=s+1;continue}}}}n!==t&&(yield{type:"text",text:e.substring(n)})}qr({},{channelCreateEvent:()=>aa,channelHideMessageEvent:()=>ua,channelMessageEvent:()=>la,channelMetadataEvent:()=>ca,channelMuteUserEvent:()=>da});var aa=(e,t)=>{let n;if("object"==typeof e.content)n=JSON.stringify(e.content);else{if("string"!=typeof e.content)return;n=e.content}return oo({kind:Co,tags:[...e.tags??[]],content:n,created_at:e.created_at},t)},ca=(e,t)=>{let n;if("object"==typeof e.content)n=JSON.stringify(e.content);else{if("string"!=typeof e.content)return;n=e.content}return oo({kind:To,tags:[["e",e.channel_create_event_id],...e.tags??[]],content:n,created_at:e.created_at},t)},la=(e,t)=>{const n=[["e",e.channel_create_event_id,e.relay_url,"root"]];return e.reply_to_channel_message_event_id&&n.push(["e",e.reply_to_channel_message_event_id,e.relay_url,"reply"]),oo({kind:_o,tags:[...n,...e.tags??[]],content:e.content,created_at:e.created_at},t)},ua=(e,t)=>{let n;if("object"==typeof e.content)n=JSON.stringify(e.content);else{if("string"!=typeof e.content)return;n=e.content}return oo({kind:$o,tags:[["e",e.channel_message_event_id],...e.tags??[]],content:n,created_at:e.created_at},t)},da=(e,t)=>{let n;if("object"==typeof e.content)n=JSON.stringify(e.content);else{if("string"!=typeof e.content)return;n=e.content}return oo({kind:Io,tags:[["p",e.pubkey_to_mute],...e.tags??[]],content:n,created_at:e.created_at},t)};qr({},{EMOJI_SHORTCODE_REGEX:()=>fa,matchAll:()=>pa,regex:()=>ha,replaceAll:()=>ya});var fa=/:(\w+):/,ha=()=>new RegExp(`\\B${fa.source}\\B`,"g");function*pa(e){const t=e.matchAll(ha());for(const e of t)try{const[t,n]=e;yield{shortcode:t,name:n,start:e.index,end:e.index+t.length}}catch(e){}}function ya(e,t){return e.replaceAll(ha(),(e,n)=>t({shortcode:e,name:n}))}var ga;qr({},{useFetchImplementation:()=>ma,validateGithub:()=>va});try{ga=fetch}catch{}function ma(e){ga=e}async function va(e,t,n){try{return await(await ga(`https://gist.github.com/${t}/${n}/raw`)).text()===`Verifying that I control the following Nostr public key: ${e}`}catch(e){return!1}}function wa(e){const{host:t,pathname:n,searchParams:r}=new URL(e),o=n||t,i=r.get("relay"),s=r.get("secret");if(!o||!i||!s)throw new Error("invalid connection string");return{pubkey:o,relay:i,secret:s}}async function ba(e,t,n){const r={method:"pay_invoice",params:{invoice:n}},o=as(t,e,JSON.stringify(r)),i={kind:ci,created_at:Math.round(Date.now()/1e3),content:o,tags:[["p",e]]};return oo(i,t)}qr({},{makeNwcRequestEvent:()=>ba,parseConnectionString:()=>wa});function xa(e){return e=(e=e.trim().toLowerCase()).normalize("NFKC"),Array.from(e).map(e=>/\p{Letter}/u.test(e)||/\p{Number}/u.test(e)?e:"-").join("")}qr({},{normalizeIdentifier:()=>xa});var Ea;qr({},{getSatoshisAmountFromBolt11:()=>_a,getZapEndpoint:()=>Sa,makeZapReceipt:()=>Ta,makeZapRequest:()=>Aa,useFetchImplementation:()=>ka,validateZapRequest:()=>Ca});try{Ea=fetch}catch{}function ka(e){Ea=e}async function Sa(e){try{let t="",{lud06:n,lud16:r}=JSON.parse(e.content);if(n){let{words:e}=er.decode(n,1e3),r=er.fromWords(e);t=Kr.decode(r)}else{if(!r)return null;{let[e,n]=r.split("@");t=new URL(`/.well-known/lnurlp/${e}`,`https://${n}`).toString()}}let o=await Ea(t),i=await o.json();if(i.allowsNostr&&i.nostrPubkey)return i.callback}catch(e){}return null}function Aa(e){let t={kind:9734,created_at:Math.round(Date.now()/1e3),content:e.comment||"",tags:[["p","pubkey"in e?e.pubkey:e.event.pubkey],["amount",e.amount.toString()],["relays",...e.relays]]};if("event"in e){if(t.tags.push(["e",e.event.id]),co(e.event.kind)){const n=["a",`${e.event.kind}:${e.event.pubkey}:`];t.tags.push(n)}else if(uo(e.event.kind)){let n=e.event.tags.find(([e,t])=>"d"===e&&t);if(!n)throw new Error("d tag not found or is empty");const r=["a",`${e.event.kind}:${e.event.pubkey}:${n[1]}`];t.tags.push(r)}t.tags.push(["k",e.event.kind.toString()])}return t}function Ca(e){let t;try{t=JSON.parse(e)}catch(e){return"Invalid zap request JSON."}if(!Wr(t))return"Zap request is not a valid Nostr event.";if(!io(t))return"Invalid signature on zap request.";let n=t.tags.find(([e,t])=>"p"===e&&t);if(!n)return"Zap request doesn't have a 'p' tag.";if(!n[1].match(/^[a-f0-9]{64}$/))return"Zap request 'p' tag is not valid hex.";let r=t.tags.find(([e,t])=>"e"===e&&t);return r&&!r[1].match(/^[a-f0-9]{64}$/)?"Zap request 'e' tag is not valid hex.":t.tags.find(([e,t])=>"relays"===e&&t)?null:"Zap request doesn't have a 'relays' tag."}function Ta({zapRequest:e,preimage:t,bolt11:n,paidAt:r}){let o=JSON.parse(e),i=o.tags.filter(([e])=>"e"===e||"p"===e||"a"===e),s={kind:9735,created_at:Math.round(r.getTime()/1e3),content:"",tags:[...i,["P",o.pubkey],["bolt11",n],["description",e]]};return t&&s.tags.push(["preimage",t]),s}function _a(e){if(e.length<50)return 0;const t=(e=e.substring(0,50)).lastIndexOf("1");if(-1===t)return 0;const n=e.substring(0,t);if(!n.startsWith("lnbc"))return 0;const r=n.substring(4);if(r.length<1)return 0;const o=r[r.length-1],i=o.charCodeAt(0)-"0".charCodeAt(0),s=i>=0&&i<=9;let a=r.length-1;if(s&&a++,a<1)return 0;const c=parseInt(r.substring(0,a));switch(o){case"m":return 1e5*c;case"u":return 100*c;case"n":return c/10;case"p":return c/1e4;default:return 1e8*c}}qr({},{getToken:()=>Ia,hashPayload:()=>Ua,unpackEventFromToken:()=>Ra,validateEvent:()=>Ma,validateEventKind:()=>La,validateEventMethodTag:()=>Na,validateEventPayloadTag:()=>ja,validateEventTimestamp:()=>Pa,validateEventUrlTag:()=>Ba,validateToken:()=>Oa});var $a="Nostr ";async function Ia(e,t,n,r=!1,o){const i={kind:di,tags:[["u",e],["method",t]],created_at:Math.round((new Date).getTime()/1e3),content:""};o&&i.tags.push(["payload",Ua(o)]);const s=await n(i);return(r?$a:"")+qn.encode(Jr.encode(JSON.stringify(s)))}async function Oa(e,t,n){const r=await Ra(e).catch(e=>{throw e});return await Ma(r,t,n).catch(e=>{throw e})}async function Ra(e){if(!e)throw new Error("Missing token");e=e.replace($a,"");const t=Kr.decode(qn.decode(e));if(!t||0===t.length||!t.startsWith("{"))throw new Error("Invalid token");return JSON.parse(t)}function Pa(e){return!!e.created_at&&Math.round((new Date).getTime()/1e3)-e.created_at<60}function La(e){return e.kind===di}function Ba(e,t){const n=e.tags.find(e=>"u"===e[0]);return!!n&&(n.length>0&&n[1]===t)}function Na(e,t){const n=e.tags.find(e=>"method"===e[0]);return!!n&&(n.length>0&&n[1].toLowerCase()===t.toLowerCase())}function Ua(e){return Wt(un(Jr.encode(JSON.stringify(e))))}function ja(e,t){const n=e.tags.find(e=>"payload"===e[0]);if(!n)return!1;const r=Ua(t);return n.length>0&&n[1]===r}async function Ma(e,t,n,r){if(!io(e))throw new Error("Invalid nostr event, signature invalid");if(!La(e))throw new Error("Invalid nostr event, kind invalid");if(!Pa(e))throw new Error("Invalid nostr event, created_at timestamp invalid");if(!Ba(e,t))throw new Error("Invalid nostr event, url tag invalid");if(!Na(e,n))throw new Error("Invalid nostr event, method tag invalid");if(Boolean(r)&&"object"==typeof r&&Object.keys(r).length>0&&!ja(e,r))throw new Error("Invalid nostr event, payload tag does not match request body hash");return!0}function Fa(e){return 3e4<=e&&e<4e4}var Da=function(e,t){return Da=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},Da(e,t)};function Ha(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}Da(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}function qa(e,t,n,r){return new(n||(n=Promise))(function(o,i){function s(e){try{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(s,a)}c((r=r.apply(e,t||[])).next())})}function za(e,t){var n,r,o,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},s=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return s.next=a(0),s.throw=a(1),s.return=a(2),"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(i=0)),i;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return i.label++,{value:a[1],done:!1};case 5:i.label++,r=a[1],a=[0];continue;case 7:a=i.ops.pop(),i.trys.pop();continue;default:if(!(o=i.trys,(o=o.length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){i=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){i.label=a[1];break}if(6===a[0]&&i.label<o[1]){i.label=o[1],o=a;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(a);break}o[2]&&i.ops.pop(),i.trys.pop();continue}a=t.call(e,i)}catch(e){a=[6,e],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}}function Wa(e){var t="function"==typeof Symbol&&Symbol.iterator,n=t&&e[t],r=0;if(n)return n.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function Ka(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,o,i=n.call(e),s=[];try{for(;(void 0===t||t-- >0)&&!(r=i.next()).done;)s.push(r.value)}catch(e){o={error:e}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return s}function Ja(e,t,n){if(n||2===arguments.length)for(var r,o=0,i=t.length;o<i;o++)!r&&o in t||(r||(r=Array.prototype.slice.call(t,0,o)),r[o]=t[o]);return e.concat(r||Array.prototype.slice.call(t))}function Va(e){return this instanceof Va?(this.v=e,this):new Va(e)}function Ga(e,t,n){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var r,o=n.apply(e,t||[]),i=[];return r=Object.create(("function"==typeof AsyncIterator?AsyncIterator:Object).prototype),s("next"),s("throw"),s("return",function(e){return function(t){return Promise.resolve(t).then(e,l)}}),r[Symbol.asyncIterator]=function(){return this},r;function s(e,t){o[e]&&(r[e]=function(t){return new Promise(function(n,r){i.push([e,t,n,r])>1||a(e,t)})},t&&(r[e]=t(r[e])))}function a(e,t){try{(n=o[e](t)).value instanceof Va?Promise.resolve(n.value.v).then(c,l):u(i[0][2],n)}catch(e){u(i[0][3],e)}var n}function c(e){a("next",e)}function l(e){a("throw",e)}function u(e,t){e(t),i.shift(),i.length&&a(i[0][0],i[0][1])}}function Za(e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t,n=e[Symbol.asyncIterator];return n?n.call(e):(e=Wa(e),t={},r("next"),r("throw"),r("return"),t[Symbol.asyncIterator]=function(){return this},t);function r(n){t[n]=e[n]&&function(t){return new Promise(function(r,o){(function(e,t,n,r){Promise.resolve(r).then(function(t){e({value:t,done:n})},t)})(r,o,(t=e[n](t)).done,t.value)})}}}function Ya(e){return"function"==typeof e}function Qa(e){var t=e(function(e){Error.call(e),e.stack=(new Error).stack});return t.prototype=Object.create(Error.prototype),t.prototype.constructor=t,t}"function"==typeof SuppressedError&&SuppressedError;var Xa=Qa(function(e){return function(t){e(this),this.message=t?t.length+" errors occurred during unsubscription:\n"+t.map(function(e,t){return t+1+") "+e.toString()}).join("\n "):"",this.name="UnsubscriptionError",this.errors=t}});function ec(e,t){if(e){var n=e.indexOf(t);0<=n&&e.splice(n,1)}}var tc=function(){function e(e){this.initialTeardown=e,this.closed=!1,this._parentage=null,this._finalizers=null}return e.prototype.unsubscribe=function(){var e,t,n,r,o;if(!this.closed){this.closed=!0;var i=this._parentage;if(i)if(this._parentage=null,Array.isArray(i))try{for(var s=Wa(i),a=s.next();!a.done;a=s.next()){a.value.remove(this)}}catch(t){e={error:t}}finally{try{a&&!a.done&&(t=s.return)&&t.call(s)}finally{if(e)throw e.error}}else i.remove(this);var c=this.initialTeardown;if(Ya(c))try{c()}catch(e){o=e instanceof Xa?e.errors:[e]}var l=this._finalizers;if(l){this._finalizers=null;try{for(var u=Wa(l),d=u.next();!d.done;d=u.next()){var f=d.value;try{oc(f)}catch(e){o=null!=o?o:[],e instanceof Xa?o=Ja(Ja([],Ka(o)),Ka(e.errors)):o.push(e)}}}catch(e){n={error:e}}finally{try{d&&!d.done&&(r=u.return)&&r.call(u)}finally{if(n)throw n.error}}}if(o)throw new Xa(o)}},e.prototype.add=function(t){var n;if(t&&t!==this)if(this.closed)oc(t);else{if(t instanceof e){if(t.closed||t._hasParent(this))return;t._addParent(this)}(this._finalizers=null!==(n=this._finalizers)&&void 0!==n?n:[]).push(t)}},e.prototype._hasParent=function(e){var t=this._parentage;return t===e||Array.isArray(t)&&t.includes(e)},e.prototype._addParent=function(e){var t=this._parentage;this._parentage=Array.isArray(t)?(t.push(e),t):t?[t,e]:e},e.prototype._removeParent=function(e){var t=this._parentage;t===e?this._parentage=null:Array.isArray(t)&&ec(t,e)},e.prototype.remove=function(t){var n=this._finalizers;n&&ec(n,t),t instanceof e&&t._removeParent(this)},e.EMPTY=function(){var t=new e;return t.closed=!0,t}(),e}(),nc=tc.EMPTY;function rc(e){return e instanceof tc||e&&"closed"in e&&Ya(e.remove)&&Ya(e.add)&&Ya(e.unsubscribe)}function oc(e){Ya(e)?e():e.unsubscribe()}var ic={onUnhandledError:null,onStoppedNotification:null,Promise:void 0,useDeprecatedSynchronousErrorHandling:!1,useDeprecatedNextContext:!1},sc={setTimeout:function(e,t){for(var n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];var o=sc.delegate;return(null==o?void 0:o.setTimeout)?o.setTimeout.apply(o,Ja([e,t],Ka(n))):setTimeout.apply(void 0,Ja([e,t],Ka(n)))},clearTimeout:function(e){var t=sc.delegate;return((null==t?void 0:t.clearTimeout)||clearTimeout)(e)},delegate:void 0};function ac(e){sc.setTimeout(function(){throw e})}function cc(){}function lc(e){e()}var uc=function(e){function t(t){var n=e.call(this)||this;return n.isStopped=!1,t?(n.destination=t,rc(t)&&t.add(n)):n.destination=gc,n}return Ha(t,e),t.create=function(e,t,n){return new pc(e,t,n)},t.prototype.next=function(e){this.isStopped||this._next(e)},t.prototype.error=function(e){this.isStopped||(this.isStopped=!0,this._error(e))},t.prototype.complete=function(){this.isStopped||(this.isStopped=!0,this._complete())},t.prototype.unsubscribe=function(){this.closed||(this.isStopped=!0,e.prototype.unsubscribe.call(this),this.destination=null)},t.prototype._next=function(e){this.destination.next(e)},t.prototype._error=function(e){try{this.destination.error(e)}finally{this.unsubscribe()}},t.prototype._complete=function(){try{this.destination.complete()}finally{this.unsubscribe()}},t}(tc),dc=Function.prototype.bind;function fc(e,t){return dc.call(e,t)}var hc=function(){function e(e){this.partialObserver=e}return e.prototype.next=function(e){var t=this.partialObserver;if(t.next)try{t.next(e)}catch(e){yc(e)}},e.prototype.error=function(e){var t=this.partialObserver;if(t.error)try{t.error(e)}catch(e){yc(e)}else yc(e)},e.prototype.complete=function(){var e=this.partialObserver;if(e.complete)try{e.complete()}catch(e){yc(e)}},e}(),pc=function(e){function t(t,n,r){var o,i,s=e.call(this)||this;Ya(t)||!t?o={next:null!=t?t:void 0,error:null!=n?n:void 0,complete:null!=r?r:void 0}:s&&ic.useDeprecatedNextContext?((i=Object.create(t)).unsubscribe=function(){return s.unsubscribe()},o={next:t.next&&fc(t.next,i),error:t.error&&fc(t.error,i),complete:t.complete&&fc(t.complete,i)}):o=t;return s.destination=new hc(o),s}return Ha(t,e),t}(uc);function yc(e){ac(e)}var gc={closed:!0,next:cc,error:function(e){throw e},complete:cc},mc="function"==typeof Symbol&&Symbol.observable||"@@observable";function vc(e){return e}var wc=function(){function e(e){e&&(this._subscribe=e)}return e.prototype.lift=function(t){var n=new e;return n.source=this,n.operator=t,n},e.prototype.subscribe=function(e,t,n){var r,o=this,i=(r=e)&&r instanceof uc||function(e){return e&&Ya(e.next)&&Ya(e.error)&&Ya(e.complete)}(r)&&rc(r)?e:new pc(e,t,n);return lc(function(){var e=o,t=e.operator,n=e.source;i.add(t?t.call(i,n):n?o._subscribe(i):o._trySubscribe(i))}),i},e.prototype._trySubscribe=function(e){try{return this._subscribe(e)}catch(t){e.error(t)}},e.prototype.forEach=function(e,t){var n=this;return new(t=bc(t))(function(t,r){var o=new pc({next:function(t){try{e(t)}catch(e){r(e),o.unsubscribe()}},error:r,complete:t});n.subscribe(o)})},e.prototype._subscribe=function(e){var t;return null===(t=this.source)||void 0===t?void 0:t.subscribe(e)},e.prototype[mc]=function(){return this},e.prototype.pipe=function(){for(var e,t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];return(0===(e=t).length?vc:1===e.length?e[0]:function(t){return e.reduce(function(e,t){return t(e)},t)})(this)},e.prototype.toPromise=function(e){var t=this;return new(e=bc(e))(function(e,n){var r;t.subscribe(function(e){return r=e},function(e){return n(e)},function(){return e(r)})})},e.create=function(t){return new e(t)},e}();function bc(e){var t;return null!==(t=null!=e?e:ic.Promise)&&void 0!==t?t:Promise}function xc(e){return function(t){if(function(e){return Ya(null==e?void 0:e.lift)}(t))return t.lift(function(t){try{return e(t,this)}catch(e){this.error(e)}});throw new TypeError("Unable to lift unknown Observable type")}}function Ec(e,t,n,r,o){return new kc(e,t,n,r,o)}var kc=function(e){function t(t,n,r,o,i,s){var a=e.call(this,t)||this;return a.onFinalize=i,a.shouldUnsubscribe=s,a._next=n?function(e){try{n(e)}catch(e){t.error(e)}}:e.prototype._next,a._error=o?function(e){try{o(e)}catch(e){t.error(e)}finally{this.unsubscribe()}}:e.prototype._error,a._complete=r?function(){try{r()}catch(e){t.error(e)}finally{this.unsubscribe()}}:e.prototype._complete,a}return Ha(t,e),t.prototype.unsubscribe=function(){var t;if(!this.shouldUnsubscribe||this.shouldUnsubscribe()){var n=this.closed;e.prototype.unsubscribe.call(this),!n&&(null===(t=this.onFinalize)||void 0===t||t.call(this))}},t}(uc),Sc=Qa(function(e){return function(){e(this),this.name="ObjectUnsubscribedError",this.message="object unsubscribed"}}),Ac=function(e){function t(){var t=e.call(this)||this;return t.closed=!1,t.currentObservers=null,t.observers=[],t.isStopped=!1,t.hasError=!1,t.thrownError=null,t}return Ha(t,e),t.prototype.lift=function(e){var t=new Cc(this,this);return t.operator=e,t},t.prototype._throwIfClosed=function(){if(this.closed)throw new Sc},t.prototype.next=function(e){var t=this;lc(function(){var n,r;if(t._throwIfClosed(),!t.isStopped){t.currentObservers||(t.currentObservers=Array.from(t.observers));try{for(var o=Wa(t.currentObservers),i=o.next();!i.done;i=o.next()){i.value.next(e)}}catch(e){n={error:e}}finally{try{i&&!i.done&&(r=o.return)&&r.call(o)}finally{if(n)throw n.error}}}})},t.prototype.error=function(e){var t=this;lc(function(){if(t._throwIfClosed(),!t.isStopped){t.hasError=t.isStopped=!0,t.thrownError=e;for(var n=t.observers;n.length;)n.shift().error(e)}})},t.prototype.complete=function(){var e=this;lc(function(){if(e._throwIfClosed(),!e.isStopped){e.isStopped=!0;for(var t=e.observers;t.length;)t.shift().complete()}})},t.prototype.unsubscribe=function(){this.isStopped=this.closed=!0,this.observers=this.currentObservers=null},Object.defineProperty(t.prototype,"observed",{get:function(){var e;return(null===(e=this.observers)||void 0===e?void 0:e.length)>0},enumerable:!1,configurable:!0}),t.prototype._trySubscribe=function(t){return this._throwIfClosed(),e.prototype._trySubscribe.call(this,t)},t.prototype._subscribe=function(e){return this._throwIfClosed(),this._checkFinalizedStatuses(e),this._innerSubscribe(e)},t.prototype._innerSubscribe=function(e){var t=this,n=this,r=n.hasError,o=n.isStopped,i=n.observers;return r||o?nc:(this.currentObservers=null,i.push(e),new tc(function(){t.currentObservers=null,ec(i,e)}))},t.prototype._checkFinalizedStatuses=function(e){var t=this,n=t.hasError,r=t.thrownError,o=t.isStopped;n?e.error(r):o&&e.complete()},t.prototype.asObservable=function(){var e=new wc;return e.source=this,e},t.create=function(e,t){return new Cc(e,t)},t}(wc),Cc=function(e){function t(t,n){var r=e.call(this)||this;return r.destination=t,r.source=n,r}return Ha(t,e),t.prototype.next=function(e){var t,n;null===(n=null===(t=this.destination)||void 0===t?void 0:t.next)||void 0===n||n.call(t,e)},t.prototype.error=function(e){var t,n;null===(n=null===(t=this.destination)||void 0===t?void 0:t.error)||void 0===n||n.call(t,e)},t.prototype.complete=function(){var e,t;null===(t=null===(e=this.destination)||void 0===e?void 0:e.complete)||void 0===t||t.call(e)},t.prototype._subscribe=function(e){var t,n;return null!==(n=null===(t=this.source)||void 0===t?void 0:t.subscribe(e))&&void 0!==n?n:nc},t}(Ac),Tc={now:function(){return(Tc.delegate||Date).now()},delegate:void 0},_c=function(e){function t(t,n,r){void 0===t&&(t=1/0),void 0===n&&(n=1/0),void 0===r&&(r=Tc);var o=e.call(this)||this;return o._bufferSize=t,o._windowTime=n,o._timestampProvider=r,o._buffer=[],o._infiniteTimeWindow=!0,o._infiniteTimeWindow=n===1/0,o._bufferSize=Math.max(1,t),o._windowTime=Math.max(1,n),o}return Ha(t,e),t.prototype.next=function(t){var n=this,r=n.isStopped,o=n._buffer,i=n._infiniteTimeWindow,s=n._timestampProvider,a=n._windowTime;r||(o.push(t),!i&&o.push(s.now()+a)),this._trimBuffer(),e.prototype.next.call(this,t)},t.prototype._subscribe=function(e){this._throwIfClosed(),this._trimBuffer();for(var t=this._innerSubscribe(e),n=this._infiniteTimeWindow,r=this._buffer.slice(),o=0;o<r.length&&!e.closed;o+=n?1:2)e.next(r[o]);return this._checkFinalizedStatuses(e),t},t.prototype._trimBuffer=function(){var e=this,t=e._bufferSize,n=e._timestampProvider,r=e._buffer,o=e._infiniteTimeWindow,i=(o?1:2)*t;if(t<1/0&&i<r.length&&r.splice(0,r.length-i),!o){for(var s=n.now(),a=0,c=1;c<r.length&&r[c]<=s;c+=2)a=c;a&&r.splice(0,a+1)}},t}(Ac),$c=function(e){function t(t,n){return e.call(this)||this}return Ha(t,e),t.prototype.schedule=function(e,t){return this},t}(tc),Ic={setInterval:function(e,t){for(var n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];var o=Ic.delegate;return(null==o?void 0:o.setInterval)?o.setInterval.apply(o,Ja([e,t],Ka(n))):setInterval.apply(void 0,Ja([e,t],Ka(n)))},clearInterval:function(e){var t=Ic.delegate;return((null==t?void 0:t.clearInterval)||clearInterval)(e)},delegate:void 0},Oc=function(e){function t(t,n){var r=e.call(this,t,n)||this;return r.scheduler=t,r.work=n,r.pending=!1,r}return Ha(t,e),t.prototype.schedule=function(e,t){var n;if(void 0===t&&(t=0),this.closed)return this;this.state=e;var r=this.id,o=this.scheduler;return null!=r&&(this.id=this.recycleAsyncId(o,r,t)),this.pending=!0,this.delay=t,this.id=null!==(n=this.id)&&void 0!==n?n:this.requestAsyncId(o,this.id,t),this},t.prototype.requestAsyncId=function(e,t,n){return void 0===n&&(n=0),Ic.setInterval(e.flush.bind(e,this),n)},t.prototype.recycleAsyncId=function(e,t,n){if(void 0===n&&(n=0),null!=n&&this.delay===n&&!1===this.pending)return t;null!=t&&Ic.clearInterval(t)},t.prototype.execute=function(e,t){if(this.closed)return new Error("executing a cancelled action");this.pending=!1;var n=this._execute(e,t);if(n)return n;!1===this.pending&&null!=this.id&&(this.id=this.recycleAsyncId(this.scheduler,this.id,null))},t.prototype._execute=function(e,t){var n,r=!1;try{this.work(e)}catch(e){r=!0,n=e||new Error("Scheduled action threw falsy error")}if(r)return this.unsubscribe(),n},t.prototype.unsubscribe=function(){if(!this.closed){var t=this.id,n=this.scheduler,r=n.actions;this.work=this.state=this.scheduler=null,this.pending=!1,ec(r,this),null!=t&&(this.id=this.recycleAsyncId(n,t,null)),this.delay=null,e.prototype.unsubscribe.call(this)}},t}($c),Rc=function(){function e(t,n){void 0===n&&(n=e.now),this.schedulerActionCtor=t,this.now=n}return e.prototype.schedule=function(e,t,n){return void 0===t&&(t=0),new this.schedulerActionCtor(this,e).schedule(n,t)},e.now=Tc.now,e}(),Pc=function(e){function t(t,n){void 0===n&&(n=Rc.now);var r=e.call(this,t,n)||this;return r.actions=[],r._active=!1,r}return Ha(t,e),t.prototype.flush=function(e){var t=this.actions;if(this._active)t.push(e);else{var n;this._active=!0;do{if(n=e.execute(e.state,e.delay))break}while(e=t.shift());if(this._active=!1,n){for(;e=t.shift();)e.unsubscribe();throw n}}},t}(Rc),Lc=new Pc(Oc),Bc=new wc(function(e){return e.complete()});function Nc(e){return e&&Ya(e.schedule)}function Uc(e){return e[e.length-1]}function jc(e){return Nc(Uc(e))?e.pop():void 0}function Mc(e,t){return"number"==typeof Uc(e)?e.pop():t}var Fc=function(e){return e&&"number"==typeof e.length&&"function"!=typeof e};function Dc(e){return Ya(null==e?void 0:e.then)}function Hc(e){return Ya(e[mc])}function qc(e){return Symbol.asyncIterator&&Ya(null==e?void 0:e[Symbol.asyncIterator])}function zc(e){return new TypeError("You provided "+(null!==e&&"object"==typeof e?"an invalid object":"'"+e+"'")+" where a stream was expected. You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable.")}var Wc="function"==typeof Symbol&&Symbol.iterator?Symbol.iterator:"@@iterator";function Kc(e){return Ya(null==e?void 0:e[Wc])}function Jc(e){return Ga(this,arguments,function(){var t,n,r;return za(this,function(o){switch(o.label){case 0:t=e.getReader(),o.label=1;case 1:o.trys.push([1,,9,10]),o.label=2;case 2:return[4,Va(t.read())];case 3:return n=o.sent(),r=n.value,n.done?[4,Va(void 0)]:[3,5];case 4:return[2,o.sent()];case 5:return[4,Va(r)];case 6:return[4,o.sent()];case 7:return o.sent(),[3,2];case 8:return[3,10];case 9:return t.releaseLock(),[7];case 10:return[2]}})})}function Vc(e){return Ya(null==e?void 0:e.getReader)}function Gc(e){if(e instanceof wc)return e;if(null!=e){if(Hc(e))return o=e,new wc(function(e){var t=o[mc]();if(Ya(t.subscribe))return t.subscribe(e);throw new TypeError("Provided object does not correctly implement Symbol.observable")});if(Fc(e))return r=e,new wc(function(e){for(var t=0;t<r.length&&!e.closed;t++)e.next(r[t]);e.complete()});if(Dc(e))return n=e,new wc(function(e){n.then(function(t){e.closed||(e.next(t),e.complete())},function(t){return e.error(t)}).then(null,ac)});if(qc(e))return Zc(e);if(Kc(e))return t=e,new wc(function(e){var n,r;try{for(var o=Wa(t),i=o.next();!i.done;i=o.next()){var s=i.value;if(e.next(s),e.closed)return}}catch(e){n={error:e}}finally{try{i&&!i.done&&(r=o.return)&&r.call(o)}finally{if(n)throw n.error}}e.complete()});if(Vc(e))return Zc(Jc(e))}var t,n,r,o;throw zc(e)}function Zc(e){return new wc(function(t){(function(e,t){var n,r,o,i;return qa(this,void 0,void 0,function(){var s,a;return za(this,function(c){switch(c.label){case 0:c.trys.push([0,5,6,11]),n=Za(e),c.label=1;case 1:return[4,n.next()];case 2:if((r=c.sent()).done)return[3,4];if(s=r.value,t.next(s),t.closed)return[2];c.label=3;case 3:return[3,1];case 4:return[3,11];case 5:return a=c.sent(),o={error:a},[3,11];case 6:return c.trys.push([6,,9,10]),r&&!r.done&&(i=n.return)?[4,i.call(n)]:[3,8];case 7:c.sent(),c.label=8;case 8:return[3,10];case 9:if(o)throw o.error;return[7];case 10:return[7];case 11:return t.complete(),[2]}})})})(e,t).catch(function(e){return t.error(e)})})}function Yc(e,t,n,r,o){void 0===r&&(r=0),void 0===o&&(o=!1);var i=t.schedule(function(){n(),o?e.add(this.schedule(null,r)):this.unsubscribe()},r);if(e.add(i),!o)return i}function Qc(e,t){return void 0===t&&(t=0),xc(function(n,r){n.subscribe(Ec(r,function(n){return Yc(r,e,function(){return r.next(n)},t)},function(){return Yc(r,e,function(){return r.complete()},t)},function(n){return Yc(r,e,function(){return r.error(n)},t)}))})}function Xc(e,t){return void 0===t&&(t=0),xc(function(n,r){r.add(e.schedule(function(){return n.subscribe(r)},t))})}function el(e,t){if(!e)throw new Error("Iterable cannot be null");return new wc(function(n){Yc(n,t,function(){var r=e[Symbol.asyncIterator]();Yc(n,t,function(){r.next().then(function(e){e.done?n.complete():n.next(e.value)})},0,!0)})})}function tl(e,t){if(null!=e){if(Hc(e))return function(e,t){return Gc(e).pipe(Xc(t),Qc(t))}(e,t);if(Fc(e))return function(e,t){return new wc(function(n){var r=0;return t.schedule(function(){r===e.length?n.complete():(n.next(e[r++]),n.closed||this.schedule())})})}(e,t);if(Dc(e))return function(e,t){return Gc(e).pipe(Xc(t),Qc(t))}(e,t);if(qc(e))return el(e,t);if(Kc(e))return function(e,t){return new wc(function(n){var r;return Yc(n,t,function(){r=e[Wc](),Yc(n,t,function(){var e,t,o;try{t=(e=r.next()).value,o=e.done}catch(e){return void n.error(e)}o?n.complete():n.next(t)},0,!0)}),function(){return Ya(null==r?void 0:r.return)&&r.return()}})}(e,t);if(Vc(e))return function(e,t){return el(Jc(e),t)}(e,t)}throw zc(e)}function nl(e,t){return t?tl(e,t):Gc(e)}function rl(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return nl(e,jc(e))}function ol(e,t){return xc(function(n,r){var o=0;n.subscribe(Ec(r,function(n){r.next(e.call(t,n,o++))}))})}var il=Array.isArray;function sl(e){return ol(function(t){return function(e,t){return il(t)?e.apply(void 0,Ja([],Ka(t))):e(t)}(e,t)})}var al=Array.isArray,cl=Object.getPrototypeOf,ll=Object.prototype,ul=Object.keys;function dl(e){if(1===e.length){var t=e[0];if(al(t))return{args:t,keys:null};if((r=t)&&"object"==typeof r&&cl(r)===ll){var n=ul(t);return{args:n.map(function(e){return t[e]}),keys:n}}}var r;return{args:e,keys:null}}function fl(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=jc(e),r=function(e){return Ya(Uc(e))?e.pop():void 0}(e),o=dl(e),i=o.args,s=o.keys;if(0===i.length)return nl([],n);var a=new wc(function(e,t,n){void 0===n&&(n=vc);return function(r){hl(t,function(){for(var o=e.length,i=new Array(o),s=o,a=o,c=function(o){hl(t,function(){var c=nl(e[o],t),l=!1;c.subscribe(Ec(r,function(e){i[o]=e,l||(l=!0,a--),a||r.next(n(i.slice()))},function(){--s||r.complete()}))},r)},l=0;l<o;l++)c(l)},r)}}(i,n,s?function(e){return function(e,t){return e.reduce(function(e,n,r){return e[n]=t[r],e},{})}(s,e)}:vc));return r?a.pipe(sl(r)):a}function hl(e,t,n){e?Yc(n,e,t):t()}function pl(e,t,n){return void 0===n&&(n=1/0),Ya(t)?pl(function(n,r){return ol(function(e,o){return t(n,e,r,o)})(Gc(e(n,r)))},n):("number"==typeof t&&(n=t),xc(function(t,r){return function(e,t,n,r,o,i,s,a){var c=[],l=0,u=0,d=!1,f=function(){!d||c.length||l||t.complete()},h=function(e){return l<r?p(e):c.push(e)},p=function(e){i&&t.next(e),l++;var a=!1;Gc(n(e,u++)).subscribe(Ec(t,function(e){null==o||o(e),i?h(e):t.next(e)},function(){a=!0},void 0,function(){if(a)try{l--;for(var e=function(){var e=c.shift();s?Yc(t,s,function(){return p(e)}):p(e)};c.length&&l<r;)e();f()}catch(e){t.error(e)}}))};return e.subscribe(Ec(t,h,function(){d=!0,f()})),function(){null==a||a()}}(t,r,e,n)}))}function yl(e){return void 0===e&&(e=1/0),pl(vc,e)}function gl(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return yl(1)(nl(e,jc(e)))}function ml(e){return new wc(function(t){Gc(e()).subscribe(t)})}function vl(e,t,n){void 0===e&&(e=0),void 0===n&&(n=Lc);var r=-1;return null!=t&&(Nc(t)?n=t:r=t),new wc(function(t){var o,i=(o=e)instanceof Date&&!isNaN(o)?+e-n.now():e;i<0&&(i=0);var s=0;return n.schedule(function(){t.closed||(t.next(s++),0<=r?this.schedule(void 0,r):t.complete())},i)})}function wl(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=jc(e),r=Mc(e,1/0),o=e;return o.length?1===o.length?Gc(o[0]):yl(r)(nl(o,n)):Bc}function bl(e,t){return xc(function(n,r){var o=0;n.subscribe(Ec(r,function(n){return e.call(t,n,o++)&&r.next(n)}))})}function xl(e){return e<=0?function(){return Bc}:xc(function(t,n){var r=0;t.subscribe(Ec(n,function(t){++r<=e&&(n.next(t),e<=r&&n.complete())}))})}function El(e,t){return void 0===t&&(t=vc),e=null!=e?e:kl,xc(function(n,r){var o,i=!0;n.subscribe(Ec(r,function(n){var s=t(n);!i&&e(o,s)||(i=!1,o=s,r.next(n))}))})}function kl(e,t){return e===t}function Sl(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return function(t){return gl(t,rl.apply(void 0,Ja([],Ka(e))))}}function Al(e){return xc(function(t,n){try{t.subscribe(n)}finally{n.add(e)}})}function Cl(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=jc(e),r=Mc(e,1/0);return xc(function(t,o){yl(r)(nl(Ja([t],Ka(e)),n)).subscribe(o)})}function Tl(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return Cl.apply(void 0,Ja([],Ka(e)))}function _l(e,t){return xc(function(e,t,n,r,o){return function(i,s){var a=n,c=t,l=0;i.subscribe(Ec(s,function(t){var n=l++;c=a?e(c,t,n):(a=!0,t),r&&s.next(c)},o&&function(){a&&s.next(c),s.complete()}))}}(e,t,arguments.length>=2,!0))}function $l(e,t){for(var n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];if(!0!==t){if(!1!==t){var o=new pc({next:function(){o.unsubscribe(),e()}});return Gc(t.apply(void 0,Ja([],Ka(n)))).subscribe(o)}}else e()}function Il(e,t){return xc(function(n,r){var o=null,i=0,s=!1,a=function(){return s&&!o&&r.complete()};n.subscribe(Ec(r,function(n){null==o||o.unsubscribe();var s=0,c=i++;Gc(e(n,c)).subscribe(o=Ec(r,function(e){return r.next(t?t(n,e,c,s++):e)},function(){o=null,a()}))},function(){s=!0,a()}))})}function Ol(e,t,n){var r=Ya(e)||t||n?{next:e,error:t,complete:n}:e;return r?xc(function(e,t){var n;null===(n=r.subscribe)||void 0===n||n.call(r);var o=!0;e.subscribe(Ec(t,function(e){var n;null===(n=r.next)||void 0===n||n.call(r,e),t.next(e)},function(){var e;o=!1,null===(e=r.complete)||void 0===e||e.call(r),t.complete()},function(e){var n;o=!1,null===(n=r.error)||void 0===n||n.call(r,e),t.error(e)},function(){var e,t;o&&(null===(e=r.unsubscribe)||void 0===e||e.call(r)),null===(t=r.finalize)||void 0===t||t.call(r)}))}):vc}function Rl(e,t){return void 0!==e[0]&&void 0!==e[1]&&(!t||e[0]===t)}function Pl(e){return Rl(e,"e")}function Ll(e){return Rl(e,"p")}function Bl(e){return Rl(e,"r")}function Nl(e){return Rl(e,"a")}function Ul(e){return Rl(e,"t")}const jl=(e,...t)=>t.reduce((e,t)=>{const n=[];for(const r of e)try{const e=t(r);if(void 0===e)continue;n.push(e)}catch(e){}return n},e);function Ml(e,t,n){if(Reflect.has(e,t))return Reflect.get(e,t);{const r=n();return Reflect.set(e,t,r),r}}function Fl(e,t){const[n,r]=Dl(e,e=>t.id===e.id?0:t.created_at===e.created_at?-1:e.created_at-t.created_at);return r||e.splice(n,0,t),e}function Dl(e,t){let n=0,r=e.length-1;for(;n<=r;){const o=Math.floor((n+r)/2),i=t(e[o]);if(0===i)return[o,!0];i<0?r=o-1:n=o+1}return[n,!1]}new TextDecoder("utf-8"),new TextEncoder;const Hl=Symbol.for("event-store"),ql=Symbol.for("event-uid"),zl=Symbol.for("replaceable-address"),Wl=Symbol.for("from-cache"),Kl=Symbol.for("replaceable-identifier");function Jl(e){return function(e){return[0,3].includes(e)||1e4<=e&&e<2e4}(e)||Fa(e)}function Vl(e){let t=Reflect.get(e,ql);return t||(t=Jl(e.kind)?Gl(e):e.id,Reflect.set(e,ql,t)),t}function Gl(e){if(!Jl(e.kind))throw new Error("Event is not replaceable or addressable");return Ml(e,zl,()=>{const t=Fa(e.kind)?Yl(e):void 0;return Zl(e.kind,e.pubkey,t)})}function Zl(e,t,n){return e+":"+t+":"+(n??"")}function Yl(e){return Ml(e,Kl,()=>e.tags.find(e=>"d"===e[0])?.[1]??"")}function Ql(){return Math.round(Date.now()/1e3)}const Xl=Symbol("expiration-timestamp");function eu(e){return Ml(e,Xl,()=>{const t=e.tags.find(e=>"expiration"===e[0])?.[1];return t?parseInt(t):void 0})}function tu(e){let t=new URL(e);return t.pathname=t.pathname.replace(/\/+/g,"/"),("80"!==t.port||"ws:"!==t.protocol&&"http:"!==t.protocol)&&("443"!==t.port||"wss:"!==t.protocol&&"https:"!==t.protocol)||(t.port=""),"string"==typeof e?t.toString():t}const nu=Symbol.for("seen-relays");function ru(e,t){return e[nu]||(e[nu]=new Set),e[nu].add(t),e[nu]}const ou=/^wss?:\/\/([-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}|localhost)\b([-a-zA-Z0-9()@:%_\+.~#?&\/\/=]*)$/;function iu(e){return e.length>=8&&ou.test(e)}function su(e){return!!e?.toLowerCase()?.match(/^[0-9a-f]{64}$/)}
/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */const au=(()=>"function"==typeof Uint8Array.from([]).toHex&&"function"==typeof Uint8Array.fromHex)(),cu=48,lu=57,uu=65,du=70,fu=97,hu=102;function pu(e){return e>=cu&&e<=lu?e-cu:e>=uu&&e<=du?e-(uu-10):e>=fu&&e<=hu?e-(fu-10):void 0}function yu(e,t=!1,n=!0){const r=e.split(":"),o=r[0]?parseInt(r[0]):void 0,i=r[1],s=r[2];if(void 0===o){if(n)return null;throw new Error("Missing kind")}if(void 0===i||""===i){if(n)return null;throw new Error("Missing pubkey")}if(t&&void 0===s){if(n)return null;throw new Error("Missing identifier")}return{kind:o,pubkey:i,identifier:s}}function gu(e){if(!e[1])throw new Error("Missing coordinate in tag");const t=yu(e[1],!0,!1);return e[2]&&iu(e[2])&&(t.relays=[e[2]]),t}function mu(e){if(!e[1])throw new Error("Missing pubkey in tag");if(!su(e[1]))throw new Error("Invalid pubkey");const t={pubkey:e[1]};return e[2]&&iu(e[2])&&(t.relays=[tu(e[2])]),t}function vu(e){return e.kind+":"+e.pubkey+":"+e.identifier}function wu(e){if(e instanceof Uint8Array)return e;if(su(e))return function(e){if("string"!=typeof e)throw new Error("hex string expected, got "+typeof e);if(au)return Uint8Array.fromHex(e);const t=e.length,n=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);const r=new Uint8Array(n);for(let t=0,o=0;t<n;t++,o+=2){const n=pu(e.charCodeAt(o)),i=pu(e.charCodeAt(o+1));if(void 0===n||void 0===i){const t=e[o]+e[o+1];throw new Error('hex string expected, got non-hex character "'+t+'" at index '+o)}r[t]=16*n+i}return r}(e);{const t=zi.decode(e);if("nsec"!==t.type)throw new Error(`Cant get secret key from ${t.type}`);return t.data}}const bu=Symbol.for("encrypted-content"),xu={[so.EncryptedDirectMessage]:"nip04",[so.Seal]:"nip44",[so.GiftWrap]:"nip44"};function Eu(e,t){return xu[e]=t,e}const ku=bu,Su=new Set([Eu(so.DraftLong,"nip04")]);function Au(e,t){return Su.add(Eu(e,t)),e}function Cu(e){return function(e){return void 0!==xu[e]}(e)&&Su.has(e)}function Tu(e){return!!Cu(e.kind)&&(function(e){return!0===Reflect.has(e,bu)}(e)&&!0===Reflect.has(e,ku))}function _u(e){if(Cu(e.kind))return Tu(e)?e[bu]:function(e){return Reflect.get(e,bu)}(e)}const $u=Symbol.for("hidden-tags"),Iu=new Set([Au(so.BookmarkList,"nip04"),Au(so.InterestsList,"nip04"),Au(so.Mutelist,"nip04"),Au(so.CommunitiesList,"nip04"),Au(so.PublicChatsList,"nip04"),Au(so.SearchRelaysList,"nip04"),Au(10009,"nip04"),Au(so.Bookmarksets,"nip04"),Au(so.Relaysets,"nip04"),Au(so.Followsets,"nip04"),Au(so.Curationsets,"nip04"),Au(so.Interestsets,"nip04")]);function Ou(e){return Cu(e)&&Iu.has(e)}function Ru(e){return!!Ou(e.kind)&&(Tu(e)&&Reflect.has(e,"HiddenTagsSymbol"))}function Pu(e){if(!Ou(e.kind))return;if(Ru(e))return e[$u];const t=_u(e);if(void 0===t)return;const n=JSON.parse(t);if(!Array.isArray(n))throw new Error("Content is not an array of tags");const r=n.filter(e=>Array.isArray(e)).map(e=>e.map(e=>String(e)));return Reflect.set(e,$u,r),r}const Lu="abcdefghijklmnopqrstuvwxyz",Bu=new Set((Lu+Lu.toUpperCase()).split("")),Nu=Symbol.for("indexable-tags");function Uu(e){let t=Reflect.get(e,Nu);if(!t){const n=new Set;for(const t of e.tags)t.length>=2&&1===t[0].length&&Bu.has(t[0])&&n.add(t[0]+":"+t[1]);t=n,Reflect.set(e,Nu,n)}return t}class ju{first=null;items=Object.create(null);last=null;max;resetTtl;size;ttl;constructor(e=0,t=0,n=!1){this.first=null,this.items=Object.create(null),this.last=null,this.max=e,this.resetTtl=n,this.size=0,this.ttl=t}clear(){return this.first=null,this.items=Object.create(null),this.last=null,this.size=0,this}delete(e){if(this.has(e)){const t=this.items[e];delete this.items[e],this.size--,null!==t.prev&&(t.prev.next=t.next),null!==t.next&&(t.next.prev=t.prev),this.first===t&&(this.first=t.next),this.last===t&&(this.last=t.prev)}return this}entries(e=this.keys()){return e.map(e=>[e,this.get(e)])}evict(e=!1){if(e||this.size>0){const e=this.first;delete this.items[e.key],0===--this.size?(this.first=null,this.last=null):(this.first=e.next,this.first.prev=null)}return this}expiresAt(e){let t;return this.has(e)&&(t=this.items[e].expiry),t}get(e){let t;if(this.has(e)){const n=this.items[e];this.ttl>0&&n.expiry<=Date.now()?this.delete(e):(t=n.value,this.set(e,t,!0))}return t}has(e){return e in this.items}keys(){const e=[];let t=this.first;for(;null!==t;)e.push(t.key),t=t.next;return e}set(e,t,n=!1,r=this.resetTtl){let o;if(n||this.has(e)){if(o=this.items[e],o.value=t,!1===n&&r&&(o.expiry=this.ttl>0?Date.now()+this.ttl:this.ttl),this.last!==o){const e=this.last,t=o.next,n=o.prev;this.first===o&&(this.first=o.next),o.next=null,o.prev=this.last,e.next=o,null!==n&&(n.next=t),null!==t&&(t.prev=n)}}else this.max>0&&this.size===this.max&&this.evict(!0),o=this.items[e]={expiry:this.ttl>0?Date.now()+this.ttl:this.ttl,key:e,prev:this.last,next:null,value:t},1===++this.size?this.first=o:this.last.next=o;return this.last=o,this}values(e=this.keys()){return e.map(e=>this.get(e))}}function Mu(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var Fu,Du,Hu={exports:{}};function qu(){if(Du)return Fu;Du=1;var e=1e3,t=60*e,n=60*t,r=24*n,o=7*r,i=365.25*r;function s(e,t,n,r){var o=t>=1.5*n;return Math.round(e/n)+" "+r+(o?"s":"")}return Fu=function(a,c){c=c||{};var l=typeof a;if("string"===l&&a.length>0)return function(s){if((s=String(s)).length>100)return;var a=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(s);if(!a)return;var c=parseFloat(a[1]);switch((a[2]||"ms").toLowerCase()){case"years":case"year":case"yrs":case"yr":case"y":return c*i;case"weeks":case"week":case"w":return c*o;case"days":case"day":case"d":return c*r;case"hours":case"hour":case"hrs":case"hr":case"h":return c*n;case"minutes":case"minute":case"mins":case"min":case"m":return c*t;case"seconds":case"second":case"secs":case"sec":case"s":return c*e;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return c;default:return}}(a);if("number"===l&&isFinite(a))return c.long?function(o){var i=Math.abs(o);if(i>=r)return s(o,i,r,"day");if(i>=n)return s(o,i,n,"hour");if(i>=t)return s(o,i,t,"minute");if(i>=e)return s(o,i,e,"second");return o+" ms"}(a):function(o){var i=Math.abs(o);if(i>=r)return Math.round(o/r)+"d";if(i>=n)return Math.round(o/n)+"h";if(i>=t)return Math.round(o/t)+"m";if(i>=e)return Math.round(o/e)+"s";return o+"ms"}(a);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(a))}}var zu=function(e){function t(e){let r,o,i,s=null;function a(...e){if(!a.enabled)return;const n=a,o=Number(new Date),i=o-(r||o);n.diff=i,n.prev=r,n.curr=o,r=o,e[0]=t.coerce(e[0]),"string"!=typeof e[0]&&e.unshift("%O");let s=0;e[0]=e[0].replace(/%([a-zA-Z%])/g,(r,o)=>{if("%%"===r)return"%";s++;const i=t.formatters[o];if("function"==typeof i){const t=e[s];r=i.call(n,t),e.splice(s,1),s--}return r}),t.formatArgs.call(n,e);(n.log||t.log).apply(n,e)}return a.namespace=e,a.useColors=t.useColors(),a.color=t.selectColor(e),a.extend=n,a.destroy=t.destroy,Object.defineProperty(a,"enabled",{enumerable:!0,configurable:!1,get:()=>null!==s?s:(o!==t.namespaces&&(o=t.namespaces,i=t.enabled(e)),i),set:e=>{s=e}}),"function"==typeof t.init&&t.init(a),a}function n(e,n){const r=t(this.namespace+(void 0===n?":":n)+e);return r.log=this.log,r}function r(e,t){let n=0,r=0,o=-1,i=0;for(;n<e.length;)if(r<t.length&&(t[r]===e[n]||"*"===t[r]))"*"===t[r]?(o=r,i=n,r++):(n++,r++);else{if(-1===o)return!1;r=o+1,i++,n=i}for(;r<t.length&&"*"===t[r];)r++;return r===t.length}return t.debug=t,t.default=t,t.coerce=function(e){if(e instanceof Error)return e.stack||e.message;return e},t.disable=function(){const e=[...t.names,...t.skips.map(e=>"-"+e)].join(",");return t.enable(""),e},t.enable=function(e){t.save(e),t.namespaces=e,t.names=[],t.skips=[];const n=("string"==typeof e?e:"").trim().replace(/\s+/g,",").split(",").filter(Boolean);for(const e of n)"-"===e[0]?t.skips.push(e.slice(1)):t.names.push(e)},t.enabled=function(e){for(const n of t.skips)if(r(e,n))return!1;for(const n of t.names)if(r(e,n))return!0;return!1},t.humanize=qu(),t.destroy=function(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")},Object.keys(e).forEach(n=>{t[n]=e[n]}),t.names=[],t.skips=[],t.formatters={},t.selectColor=function(e){let n=0;for(let t=0;t<e.length;t++)n=(n<<5)-n+e.charCodeAt(t),n|=0;return t.colors[Math.abs(n)%t.colors.length]},t.enable(t.load()),t};!function(e,t){t.formatArgs=function(t){if(t[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+t[0]+(this.useColors?"%c ":" ")+"+"+e.exports.humanize(this.diff),!this.useColors)return;const n="color: "+this.color;t.splice(1,0,n,"color: inherit");let r=0,o=0;t[0].replace(/%[a-zA-Z%]/g,e=>{"%%"!==e&&(r++,"%c"===e&&(o=r))}),t.splice(o,0,n)},t.save=function(e){try{e?t.storage.setItem("debug",e):t.storage.removeItem("debug")}catch(e){}},t.load=function(){let e;try{e=t.storage.getItem("debug")||t.storage.getItem("DEBUG")}catch(e){}!e&&"undefined"!=typeof process&&"env"in process&&(e=process.env.DEBUG);return e},t.useColors=function(){if("undefined"!=typeof window&&window.process&&("renderer"===window.process.type||window.process.__nwjs))return!0;if("undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))return!1;let e;return"undefined"!=typeof document&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||"undefined"!=typeof window&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||"undefined"!=typeof navigator&&navigator.userAgent&&(e=navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/))&&parseInt(e[1],10)>=31||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)},t.storage=function(){try{return localStorage}catch(e){}}(),t.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),t.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"],t.log=console.debug||console.log||(()=>{}),e.exports=zu(t);const{formatters:n}=e.exports;n.j=function(e){try{return JSON.stringify(e)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}}}(Hu,Hu.exports);const Wu=Mu(Hu.exports)("applesauce");class Ku{log=Wu.extend("EventMemory");kinds=new Map;authors=new Map;tags=new ju;created_at=[];events=new ju;replaceable=new Map;get size(){return this.events.size}hasEvent(e){return this.events.has(e)}getEvent(e){return this.events.get(e)}hasReplaceable(e,t,n){const r=this.replaceable.get(Zl(e,t,n));return!!r&&r.length>0}getReplaceable(e,t,n){const r=Zl(e,t,n),o=this.replaceable.get(r);return o?.[0]}getReplaceableHistory(e,t,n){const r=Zl(e,t,n);return this.replaceable.get(r)}getByFilters(e){return Array.from(this.getEventsForFilters(Array.isArray(e)?e:[e]))}getTimeline(e){const t=[],n=this.getByFilters(e);for(const e of n)Fl(t,e);return t}add(e){const t=e.id,n=this.events.get(t);if(n)return n;this.events.set(t,e),this.getKindIndex(e.kind).add(e),this.getAuthorsIndex(e.pubkey).add(e);for(const t of Uu(e))this.tags.has(t)&&this.getTagIndex(t).add(e);if(Fl(this.created_at,e),Jl(e.kind)){const t=e.tags.find(e=>"d"===e[0])?.[1],n=Zl(e.kind,e.pubkey,t);let r=this.replaceable.get(n);this.replaceable.has(n)||(r=[],this.replaceable.set(n,r)),Fl(r,e)}return e}remove(e){let t="string"==typeof e?this.events.get(e):e;if(!t)return!1;const n=t.id;if(!this.events.has(n))return!1;this.getAuthorsIndex(t.pubkey).delete(t),this.getKindIndex(t.kind).delete(t);for(const e of Uu(t))this.tags.has(e)&&this.getTagIndex(e).delete(t);const r=this.created_at.indexOf(t);if(this.created_at.splice(r,1),this.events.delete(n),Jl(t.kind)){const e=t.tags.find(e=>"d"===e[0])?.[1],n=Zl(t.kind,t.pubkey,e),r=this.replaceable.get(n);if(r&&r.includes(t)){const e=r.indexOf(t);r.splice(e,1)}}return this.claims.delete(t),!0}removeByFilters(e){const t=this.getByFilters(e);let n=0;for(const e of t)this.remove(e)&&n++;return n}update(e){}claims=new WeakMap;touch(e){this.events.has(e.id)&&this.events.set(e.id,e)}claim(e,t){this.claims.has(e)||this.claims.set(e,t),this.touch(e)}isClaimed(e){return this.claims.has(e)}removeClaim(e,t){this.claims.get(e)===t&&this.claims.delete(e)}clearClaim(e){this.claims.delete(e)}*unclaimed(){let e=this.events.first;for(;e;){const t=e.value;this.isClaimed(t)||(yield t),e=e.next}return 0}prune(e){let t=0;const n=this.unclaimed();for(const r of n)if(this.remove(r),t++,e&&t>=e)break;return t}getKindIndex(e){return this.kinds.has(e)||this.kinds.set(e,new Set),this.kinds.get(e)}getAuthorsIndex(e){return this.authors.has(e)||this.authors.set(e,new Set),this.authors.get(e)}getTagIndex(e){if(!this.tags.has(e)){const t=new Set,n=Date.now();for(const n of this.events.values())Uu(n).has(e)&&t.add(n);const r=Date.now()-n;r>100&&this.log(`Built index ${e} took ${r}ms`),this.tags.set(e,t)}return this.tags.get(e)}*iterateAuthors(e){for(const t of e){const e=this.authors.get(t);if(e)for(const t of e)yield t}}*iterateTag(e,t){for(const n of t){const t=this.getTagIndex(e+":"+n);if(t)for(const e of t)yield e}}*iterateKinds(e){for(const t of e){const e=this.kinds.get(t);if(e)for(const t of e)yield t}}*iterateTime(e,t){let n=0,r=this.created_at.length-1,o=t?Dl(this.created_at,e=>e.created_at-t):void 0;o&&(n=o[0]);const i=e?Dl(this.created_at,t=>t.created_at-e):void 0;i&&(r=i[0]);for(let e=n;e<r;e++)yield this.created_at[e]}*iterateIds(e){for(const t of e)this.events.has(t)&&(yield this.events.get(t))}getEventsForFilter(e){if(e.search)return new Set;let t=!0,n=new Set;const r=e=>{const r=e instanceof Set?e:new Set(e);if(t)n=r,t=!1;else for(const e of n)r.has(e)||n.delete(e);return n};e.ids&&r(this.iterateIds(e.ids));let o=null;void 0!==e.since&&(o=Array.from(this.iterateTime(e.since,e.until)),r(o));for(const t of Bu){const n=e[`#${t}`];n?.length&&r(this.iterateTag(t,n))}if(e.authors&&r(this.iterateAuthors(e.authors)),e.kinds&&r(this.iterateKinds(e.kinds)),void 0===e.since&&void 0!==e.until&&(o=Array.from(this.iterateTime(e.since,e.until)),r(o)),e.limit&&o){const t=new Set;for(const r of o){if(t.size>=e.limit)break;n.has(r)&&t.add(r)}return t}return n}getEventsForFilters(e){if(0===e.length)return new Set;let t=new Set;for(const n of e){const e=this.getEventsForFilter(n);for(const n of e)t.add(n)}return t}reset(){this.events.clear(),this.kinds.clear(),this.authors.clear(),this.tags.clear(),this.created_at=[],this.replaceable.clear(),this.claims=new WeakMap}}function Ju(e,t){var n,r;if(0===t.length)return e;for(n=0,r=t.length;n<r;n++)e=(e<<5)-e+t.charCodeAt(n),e|=0;return e<0?-2*e:e}function Vu(e,t,n,r){var o,i=Ju(Ju(Ju(e,n),(o=t,Object.prototype.toString.call(o))),typeof t);if(null===t)return Ju(i,"null");if(void 0===t)return Ju(i,"undefined");if("object"==typeof t||"function"==typeof t){if(-1!==r.indexOf(t))return Ju(i,"[Circular]"+n);r.push(t);var s=function(e,t,n){return Object.keys(t).sort().reduce(function(e,r){return Vu(e,t[r],r,n)},e)}(i,t,r);if(!("valueOf"in t)||"function"!=typeof t.valueOf)return s;try{return Ju(s,String(t.valueOf()))}catch(e){return Ju(s,"[valueOf exception]"+(e.stack||e.message))}}return Ju(i,t.toString())}var Gu=function(e){return function(e,t){for(;e.length<t;)e="0"+e;return e}(Vu(0,e,"",[]).toString(16),8)},Zu=Mu(Gu);function Yu(e,t){if(e.ids&&-1===e.ids.indexOf(t.id))return!1;if(e.kinds&&-1===e.kinds.indexOf(t.kind))return!1;if(e.authors&&-1===e.authors.indexOf(t.pubkey))return!1;for(let n in e)if("#"===n[0]){let r=n.slice(1),o=e[n];if(o){const e=Uu(t);if(!1===o.some(t=>e.has(r+":"+t)))return!1}}return!(e.since&&t.created_at<e.since)&&!(e.until&&t.created_at>e.until)}function Qu(e,t){for(let n=0;n<e.length;n++)if(Yu(e[n],t))return!0;return!1}function Xu(e){return"string"==typeof e&&(e={pubkey:e}),t=>t.replaceable({kind:10063,pubkey:e.pubkey,relays:e.relays}).pipe(ol(e=>e?function(e){const t=Array.isArray(e)?e:e.tags;return jl(t,e=>Rl(e,"server")&&URL.canParse(e[1])?new URL("/",e[1]):void 0)}(e):[]))}const ed=Symbol.for("profile-content");function td(e){return Ml(e,ed,()=>{const t=function(e){try{return JSON.parse(e)}catch(e){return}}(e.content);if(t)return t.nip05&&"string"!=typeof t.nip05&&(t.nip05=String(t.nip05)),t.website&&t.website?.length>0&&!1===t.website?.startsWith("http")&&(t.website="https://"+t.website),t})}function nd(e){return!!e&&((e.kind===so.Metadata||e.kind===so.Handlerinformation)&&!!td(e))}!function(e){function t(e){if(!Number.isSafeInteger(e))throw new Error(`Wrong integer: ${e}`)}function n(...e){const t=(e,t)=>n=>e(t(n)),n=Array.from(e).reverse().reduce((e,n)=>e?t(e,n.encode):n.encode,void 0),r=e.reduce((e,n)=>e?t(e,n.decode):n.decode,void 0);return{encode:n,decode:r}}function r(e){return{encode:n=>{if(!Array.isArray(n)||n.length&&"number"!=typeof n[0])throw new Error("alphabet.encode input should be an array of numbers");return n.map(n=>{if(t(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&&"string"!=typeof t[0])throw new Error("alphabet.decode input should be array of strings");return t.map(t=>{if("string"!=typeof t)throw new Error(`alphabet.decode: not string element=${t}`);const n=e.indexOf(t);if(-1===n)throw new Error(`Unknown letter: "${t}". Allowed: ${e}`);return n})}}}function o(e=""){if("string"!=typeof e)throw new Error("join separator should be string");return{encode:t=>{if(!Array.isArray(t)||t.length&&"string"!=typeof t[0])throw new Error("join.encode input should be array of strings");for(let e of t)if("string"!=typeof e)throw new Error(`join.encode: non-string input=${e}`);return t.join(e)},decode:t=>{if("string"!=typeof t)throw new Error("join.decode input should be string");return t.split(e)}}}function i(e,n="="){if(t(e),"string"!=typeof n)throw new Error("padding chr should be string");return{encode(t){if(!Array.isArray(t)||t.length&&"string"!=typeof t[0])throw new Error("padding.encode input should be array of strings");for(let e of t)if("string"!=typeof e)throw new Error(`padding.encode: non-string input=${e}`);for(;t.length*e%8;)t.push(n);return t},decode(t){if(!Array.isArray(t)||t.length&&"string"!=typeof t[0])throw new Error("padding.encode input should be array of strings");for(let e of t)if("string"!=typeof e)throw new Error(`padding.decode: non-string input=${e}`);let r=t.length;if(r*e%8)throw new Error("Invalid padding: string should have whole number of bytes");for(;r>0&&t[r-1]===n;r--)if(!((r-1)*e%8))throw new Error("Invalid padding: string has too much padding");return t.slice(0,r)}}}function s(e){if("function"!=typeof e)throw new Error("normalize fn should be function");return{encode:e=>e,decode:t=>e(t)}}function a(e,n,r){if(n<2)throw new Error(`convertRadix: wrong from=${n}, base cannot be less than 2`);if(r<2)throw new Error(`convertRadix: wrong to=${r}, base cannot be less than 2`);if(!Array.isArray(e))throw new Error("convertRadix: data should be array");if(!e.length)return[];let o=0;const i=[],s=Array.from(e);for(s.forEach(e=>{if(t(e),e<0||e>=n)throw new Error(`Wrong integer: ${e}`)});;){let e=0,t=!0;for(let i=o;i<s.length;i++){const a=s[i],c=n*e+a;if(!Number.isSafeInteger(c)||n*e/n!==e||c-a!==n*e)throw new Error("convertRadix: carry overflow");if(e=c%r,s[i]=Math.floor(c/r),!Number.isSafeInteger(s[i])||s[i]*r+e!==c)throw new Error("convertRadix: carry overflow");t&&(s[i]?t=!1:o=i)}if(i.push(e),t)break}for(let t=0;t<e.length-1&&0===e[t];t++)i.push(0);return i.reverse()}
/*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) */
Object.defineProperty(e,"__esModule",{value:!0}),e.bytes=e.stringToBytes=e.str=e.bytesToString=e.hex=e.utf8=e.bech32m=e.bech32=e.base58check=e.base58xmr=e.base58xrp=e.base58flickr=e.base58=e.base64url=e.base64=e.base32crockford=e.base32hex=e.base32=e.base16=e.utils=e.assertNumber=void 0,e.assertNumber=t;const c=(e,t)=>t?c(t,e%t):e,l=(e,t)=>e+(t-c(e,t));function u(e,n,r,o){if(!Array.isArray(e))throw new Error("convertRadix2: data should be array");if(n<=0||n>32)throw new Error(`convertRadix2: wrong from=${n}`);if(r<=0||r>32)throw new Error(`convertRadix2: wrong to=${r}`);if(l(n,r)>32)throw new Error(`convertRadix2: carry overflow from=${n} to=${r} carryBits=${l(n,r)}`);let i=0,s=0;const a=2**r-1,c=[];for(const o of e){if(t(o),o>=2**n)throw new Error(`convertRadix2: invalid data word=${o} from=${n}`);if(i=i<<n|o,s+n>32)throw new Error(`convertRadix2: carry overflow pos=${s} from=${n}`);for(s+=n;s>=r;s-=r)c.push((i>>s-r&a)>>>0);i&=2**s-1}if(i=i<<r-s&a,!o&&s>=n)throw new Error("Excess padding");if(!o&&i)throw new Error(`Non-zero padding: ${i}`);return o&&s>0&&c.push(i>>>0),c}function d(e){return t(e),{encode:t=>{if(!(t instanceof Uint8Array))throw new Error("radix.encode input should be Uint8Array");return a(Array.from(t),256,e)},decode:t=>{if(!Array.isArray(t)||t.length&&"number"!=typeof t[0])throw new Error("radix.decode input should be array of strings");return Uint8Array.from(a(t,e,256))}}}function f(e,n=!1){if(t(e),e<=0||e>32)throw new Error("radix2: bits should be in (0..32]");if(l(8,e)>32||l(e,8)>32)throw new Error("radix2: carry overflow");return{encode:t=>{if(!(t instanceof Uint8Array))throw new Error("radix2.encode input should be Uint8Array");return u(Array.from(t),8,e,!n)},decode:t=>{if(!Array.isArray(t)||t.length&&"number"!=typeof t[0])throw new Error("radix2.decode input should be array of strings");return Uint8Array.from(u(t,e,8,n))}}}function h(e){if("function"!=typeof e)throw new Error("unsafeWrapper fn should be function");return function(...t){try{return e.apply(null,t)}catch(e){}}}function p(e,n){if(t(e),"function"!=typeof n)throw new Error("checksum fn should be function");return{encode(t){if(!(t instanceof Uint8Array))throw new Error("checksum.encode: input should be Uint8Array");const r=n(t).slice(0,e),o=new Uint8Array(t.length+e);return o.set(t),o.set(r,t.length),o},decode(t){if(!(t instanceof Uint8Array))throw new Error("checksum.decode: input should be Uint8Array");const r=t.slice(0,-e),o=n(r).slice(0,e),i=t.slice(-e);for(let t=0;t<e;t++)if(o[t]!==i[t])throw new Error("Invalid checksum");return r}}}e.utils={alphabet:r,chain:n,checksum:p,radix:d,radix2:f,join:o,padding:i},e.base16=n(f(4),r("0123456789ABCDEF"),o("")),e.base32=n(f(5),r("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"),i(5),o("")),e.base32hex=n(f(5),r("0123456789ABCDEFGHIJKLMNOPQRSTUV"),i(5),o("")),e.base32crockford=n(f(5),r("0123456789ABCDEFGHJKMNPQRSTVWXYZ"),o(""),s(e=>e.toUpperCase().replace(/O/g,"0").replace(/[IL]/g,"1"))),e.base64=n(f(6),r("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),i(6),o("")),e.base64url=n(f(6),r("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"),i(6),o(""));const y=e=>n(d(58),r(e),o(""));e.base58=y("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"),e.base58flickr=y("123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"),e.base58xrp=y("rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz");const g=[0,2,3,5,6,7,9,10,11];e.base58xmr={encode(t){let n="";for(let r=0;r<t.length;r+=8){const o=t.subarray(r,r+8);n+=e.base58.encode(o).padStart(g[o.length],"1")}return n},decode(t){let n=[];for(let r=0;r<t.length;r+=11){const o=t.slice(r,r+11),i=g.indexOf(o.length),s=e.base58.decode(o);for(let e=0;e<s.length-i;e++)if(0!==s[e])throw new Error("base58xmr: wrong padding");n=n.concat(Array.from(s.slice(s.length-i)))}return Uint8Array.from(n)}};e.base58check=t=>n(p(4,e=>t(t(e))),e.base58);const m=n(r("qpzry9x8gf2tvdw0s3jn54khce6mua7l"),o("")),v=[996825010,642813549,513874426,1027748829,705979059];function w(e){const t=e>>25;let n=(33554431&e)<<5;for(let e=0;e<v.length;e++)1==(t>>e&1)&&(n^=v[e]);return n}function b(e,t,n=1){const r=e.length;let o=1;for(let t=0;t<r;t++){const n=e.charCodeAt(t);if(n<33||n>126)throw new Error(`Invalid prefix (${e})`);o=w(o)^n>>5}o=w(o);for(let t=0;t<r;t++)o=w(o)^31&e.charCodeAt(t);for(let e of t)o=w(o)^e;for(let e=0;e<6;e++)o=w(o);return o^=n,m.encode(u([o%2**30],30,5,!1))}function x(e){const t="bech32"===e?1:734539939,n=f(5),r=n.decode,o=n.encode,i=h(r);function s(e,n=90){if("string"!=typeof e)throw new Error("bech32.decode input should be string, not "+typeof e);if(e.length<8||!1!==n&&e.length>n)throw new TypeError(`Wrong string length: ${e.length} (${e}). Expected (8..${n})`);const r=e.toLowerCase();if(e!==r&&e!==e.toUpperCase())throw new Error("String must be lowercase or uppercase");const o=(e=r).lastIndexOf("1");if(0===o||-1===o)throw new Error('Letter "1" must be present between prefix and data only');const i=e.slice(0,o),s=e.slice(o+1);if(s.length<6)throw new Error("Data must be at least 6 characters long");const a=m.decode(s).slice(0,-6),c=b(i,a,t);if(!s.endsWith(c))throw new Error(`Invalid checksum in ${e}: expected "${c}"`);return{prefix:i,words:a}}return{encode:function(e,n,r=90){if("string"!=typeof e)throw new Error("bech32.encode prefix should be string, not "+typeof e);if(!Array.isArray(n)||n.length&&"number"!=typeof n[0])throw new Error("bech32.encode words should be array of numbers, not "+typeof n);const o=e.length+7+n.length;if(!1!==r&&o>r)throw new TypeError(`Length ${o} exceeds limit ${r}`);return`${e=e.toLowerCase()}1${m.encode(n)}${b(e,n,t)}`},decode:s,decodeToBytes:function(e){const{prefix:t,words:n}=s(e,!1);return{prefix:t,words:n,bytes:r(n)}},decodeUnsafe:h(s),fromWords:r,fromWordsUnsafe:i,toWords:o}}e.bech32=x("bech32"),e.bech32m=x("bech32m"),e.utf8={encode:e=>(new TextDecoder).decode(e),decode:e=>(new TextEncoder).encode(e)},e.hex=n(f(4),r("0123456789abcdef"),o(""),s(e=>{if("string"!=typeof e||e.length%2)throw new TypeError(`hex.decode: expected string, got ${typeof e} with length ${e.length}`);return e.toLowerCase()}));const E={utf8:e.utf8,hex:e.hex,base16:e.base16,base32:e.base32,base64:e.base64,base64url:e.base64url,base58:e.base58,base58xmr:e.base58xmr},k=`Invalid encoding type. Available types: ${Object.keys(E).join(", ")}`;e.bytesToString=(e,t)=>{if("string"!=typeof e||!E.hasOwnProperty(e))throw new TypeError(k);if(!(t instanceof Uint8Array))throw new TypeError("bytesToString() expects Uint8Array");return E[e].encode(t)},e.str=e.bytesToString;e.stringToBytes=(e,t)=>{if(!E.hasOwnProperty(e))throw new TypeError(k);if("string"!=typeof t)throw new TypeError("stringToBytes() expects string");return E[e].decode(t)},e.bytes=e.stringToBytes}({}),BigInt(1e3),BigInt(1e6),BigInt(1e9),BigInt(1e12),BigInt("2100000000000000000"),BigInt(1e11);const rd={payment_hash:1,payment_secret:16,description:13,payee:19,description_hash:23,expiry:6,min_final_cltv_expiry:24,fallback_address:9,route_hint:3,feature_bits:5,metadata:27};for(let e=0,t=Object.keys(rd);e<t.length;e++)t[e],rd[t[e]].toString();const od=Symbol.for("public-contacts"),id=Symbol.for("hidden-contacts");function sd(e){return function(...e){const t=new Map;for(const n of e)if(Array.isArray(n))for(const e of n)e&&t.set(e.pubkey,e);else n&&t.set(n.pubkey,n);return Array.from(t.values())}(function(e){return Ml(e,od,()=>jl(e.tags,e=>Ll(e)?e:void 0,mu))}(e),function(e){if(function(e){return Ru(e)&&Reflect.has(e,id)}(e))return e[id];const t=Pu(e);if(!t)return;const n=jl(t,e=>Ll(e)?e:void 0,mu);return Reflect.set(e,id,n),n}(e))}Wu.extend("EncryptedContentCache"),Wu.extend("event-cache"),new TextDecoder;const ad=Symbol.for("mailboxes-inboxes"),cd=Symbol.for("mailboxes-outboxes");function ld(e){return Ml(e,ad,()=>{const t=[];for(const n of e.tags)if(Bl(n))try{const[,e,r]=n;!e||!iu(e)||t.includes(e)||"read"!==r&&void 0!==r||t.push(tu(e))}catch{}return t})}function ud(e){return Ml(e,cd,()=>{const t=[];for(const n of e.tags)if(Bl(n))try{const[e,r,o]=n;"r"!==e||!iu(r)||t.includes(r)||"write"!==o&&void 0!==o||t.push(tu(r))}catch{}return t})}const dd=Symbol.for("mute-public"),fd=Symbol.for("mute-hidden");function hd(e){return{pubkeys:new Set(e.filter(Ll).map(e=>e[1])),threads:new Set(e.filter(Pl).map(e=>e[1])),hashtags:new Set(e.filter(Ul).map(e=>e[1].toLocaleLowerCase())),words:new Set(e.filter(e=>"word"===e[0]&&e[1]).map(e=>e[1].toLocaleLowerCase()))}}function pd(e){const t=function(e){if(function(e){return Ru(e)&&Reflect.has(e,fd)}(e))return e[fd];const t=Pu(e);if(!t)return;const n=hd(t);return Reflect.set(e,fd,n),n}(e),n=function(e){return Ml(e,dd,()=>hd(e.tags))}(e);return t?function(...e){const t={pubkeys:new Set,threads:new Set,hashtags:new Set,words:new Set};for(const n of e){for(const e of n.pubkeys)t.pubkeys.add(e);for(const e of n.threads)t.threads.add(e);for(const e of n.hashtags)t.hashtags.add(e);for(const e of n.words)t.words.add(e)}return t}(t,n):n}var yd;!function(e){e.nudity="nudity",e.malware="malware",e.profanity="profanity",e.illegal="illegal",e.spam="spam",e.impersonation="impersonation",e.other="other"}(yd||(yd={}));const gd=Symbol.for("nip10-thread-refs");function md(e){if(!e[1])throw new Error("Missing event id in tag");let t={id:e[1]};return e[2]&&iu(e[2])&&(t.relays=[e[2]]),"e"!==e[0]||"root"!==e[3]&&"reply"!==e[3]&&"mention"!==e[3]||!e[4]||64!==e[4].length||(t.author=e[4]),t}function vd(e){return t=>{const n=new Set;return t.pipe(Ol(r=>{if(void 0!==r)if(Array.isArray(r))for(const o of r)n.add(o),e.claim(o,t);else n.add(r),e.claim(r,t)}),Al(()=>{for(const r of n)e.removeClaim(r,t)}))}}function wd(e){return t=>{let n;return t.pipe(Ol(r=>{n&&e.removeClaim(n,t),r&&e.claim(r,t),n=r}),Al(()=>{n&&e.removeClaim(n,t)}))}}function bd(){return e=>e.pipe(bl(e=>null!=e))}function xd(e){return t=>new wc(n=>{let r=!1;const o=t.subscribe({next:e=>{r=!0,n.next(e)},error:e=>n.error(e),complete:()=>n.complete()});return r||n.next(e),o})}function Ed(e){return"string"==typeof e&&(e={id:e}),t=>wl(ml(()=>function(e,t){const n=e.getEvent(t.id);return n instanceof Promise?nl(n):rl(n)}(t,e)).pipe(function(e,t){return Il(n=>n?rl(n):e.eventLoader?nl(e.eventLoader(t)):Bc)}(t,e),bd()),t.insert$.pipe(bl(t=>t.id===e.id)),t.remove$.pipe(bl(t=>t.id===e.id),xl(1),xc(function(e,t){e.subscribe(Ec(t,cc))}),Sl(void 0))).pipe(wd(t),El((e,t)=>e?.id===t?.id),xd(void 0))}function kd(e){return t=>{let n;return wl(ml(()=>function(e,t){const n=e.getReplaceable(t.kind,t.pubkey,t.identifier);return n instanceof Promise?nl(n):rl(n)}(t,e)).pipe(function(e,t){return Il(n=>n?rl(n):void 0!==t.identifier?e.addressableLoader?nl(e.addressableLoader(t)).pipe(bl(e=>!!e)):Bc:e.replaceableLoader?nl(e.replaceableLoader(t)).pipe(bl(e=>!!e)):Bc)}(t,e),bd()),t.insert$.pipe(bl(t=>t.pubkey==e.pubkey&&t.kind===e.kind&&(void 0===e.identifier||Yl(t)===e.identifier)))).pipe(El((e,t)=>e.created_at>=t.created_at),Ol(e=>n=e),(a=t.remove$.pipe(bl(e=>e.id===n?.id)),xc(function(e,t){Gc(a).subscribe(Ec(t,function(){return t.complete()},cc)),!t.closed&&e.subscribe(t)})),Sl(void 0),(s=1/0,null!=r&&("object"==typeof r?(o=r.count,s=void 0===o?1/0:o,i=r.delay):s=r),s<=0?function(){return Bc}:xc(function(e,t){var n,r=0,o=function(){if(null==n||n.unsubscribe(),n=null,null!=i){var e="number"==typeof i?vl(i):Gc(i(r)),o=Ec(t,function(){o.unsubscribe(),a()});e.subscribe(o)}else a()},a=function(){var i=!1;n=e.subscribe(Ec(t,void 0,function(){++r<s?n?o():i=!0:t.complete()})),i&&o()};a()})),wd(t),xd(void 0));var r,o,i,s,a}}function Sd(e,t){return e=Array.isArray(e)?e:[e],n=>{const r=new Map;return ml(()=>{const t=n.getTimeline(e);return t instanceof Promise?nl(t):rl(t)}).pipe(vd(n),Tl(n.insert$.pipe(bl(t=>Qu(e,t)),vd(n))),Tl(n.remove$.pipe(bl(t=>Qu(e,t)),ol(e=>e.id))),_l((e,n)=>{if("string"==typeof n)return e.filter(e=>e.id!==n);if(Array.isArray(n)){if(!t)for(const e of n)Jl(e.kind)&&r.set(Vl(e),e);return n}let o=[...e];if(!t&&Jl(n.kind)){const t=Vl(n),i=r.get(t);if(i&&n.created_at<i.created_at)return e;r.set(t,n),i&&o.slice(o.indexOf(i),1)}return Fl(o,n),o},[]),El(),Al(()=>r.clear()))}}function Ad(e){return t=>fl(Object.fromEntries(e.map(e=>[e,t.model(Ed,{id:e})])))}function Cd(e){return t=>fl(Object.fromEntries(e.map(e=>[Zl(e.kind,e.pubkey,e.identifier),t.model(kd,e)])))}function Td(e){return t=>{let n;return wl(t.pipe(Ol(e=>n=e)),e.update$.pipe(bl(e=>e.id===n?.id)))}}function _d(e){return"string"==typeof e&&(e={pubkey:e}),t=>t.replaceable({kind:so.Contacts,pubkey:e.pubkey,relays:e.relays}).pipe(Td(t),ol(e=>e?sd(e):[]))}function $d(e){return t=>{const n=[{kinds:[1111],"#e":[e.id]}];return Fa(e.kind)&&n.push({kinds:[1111],"#a":[Gl(e)]}),t.timeline(n)}}function Id(e){return"string"==typeof e&&(e={pubkey:e}),t=>t.replaceable({kind:so.RelayList,pubkey:e.pubkey,relays:e.relays}).pipe(ol(e=>e&&{inboxes:ld(e),outboxes:ud(e)}))}function Od(e){return"string"==typeof e&&(e={pubkey:e}),t=>t.replaceable({kind:so.Mutelist,pubkey:e.pubkey,relays:e.relays}).pipe(Td(t),ol(e=>e&&pd(e)))}function Rd(e){return"string"==typeof e&&(e={pubkey:e}),t=>t.replaceable({kind:so.Metadata,pubkey:e.pubkey,relays:e.relays}).pipe(bl(nd),ol(e=>e&&td(e)),xd(void 0))}function Pd(e){return t=>t.timeline(Jl(e.kind)?[{kinds:[so.Reaction],"#e":[e.id]},{kinds:[so.Reaction],"#a":[Vl(e)]}]:[{kinds:[so.Reaction],"#e":[e.id]}])}const Ld={kinds:[so.ShortTextNote]};function Bd(e,t){const n=new Map,r=new Map,{kinds:o}={...Ld,...t};let i="";const s={},a={kinds:o};var c;return"string"!=typeof(c=e)&&Reflect.has(c,"identifier")&&Reflect.has(c,"pubkey")&&Reflect.has(c,"kind")?(i=vu(e),s.kinds=[e.kind],s.authors=[e.pubkey],s["#d"]=[e.identifier],a["#a"]=[i]):"string"==typeof e?(i=e,s.ids=[e],a["#e"]=[e]):(i=e.id,s.ids=[e.id],a["#e"]=[e.id]),e=>e.filters([s,a]).pipe(ol(e=>{if(!r.has(Vl(e))){const t=function(e){return Ml(e,gd,()=>{const t=function(e){const t=e.filter(e=>"e"===e[0]&&e[1]),n=e.filter(e=>"a"===e[0]&&e[1]);let r=t.find(e=>"root"===e[3]),o=t.find(e=>"reply"===e[3]),i=n.find(e=>"root"===e[3]),s=n.find(e=>"reply"===e[3]);if(r&&o||(r=o=r||o),i&&s||(i=s=i||s),!r&&!o){const e=t.filter(e=>!e[3]);e.length>=1&&(r=e[0],o=e[e.length-1]??r)}return{root:r||i?{e:r,a:i}:void 0,reply:o||s?{e:o,a:s}:void 0}}(e.tags);let n,r;if(t.root)try{n={e:t.root.e&&md(t.root.e),a:t.root.a&&gu(t.root.a)}}catch(e){}if(t.reply)try{r={e:t.reply.e&&md(t.reply.e),a:t.reply.a&&gu(t.reply.a)}}catch(e){}return{root:n,reply:r}})}(e),o=n.get(Vl(e))||new Set,i={event:e,refs:t,replies:o};for(const e of o)e.parent=i;if(t.reply?.e||t.reply?.a){let e=t.reply.e?t.reply.e.id:vu(t.reply.a);if(i.parent=r.get(e),i.parent)i.parent.replies.add(i);else{let t=n.get(e);t||(t=new Set,n.set(e,t)),t.add(i)}}r.set(Vl(e),i)}return{root:r.get(i),all:r}}))}function Nd(e){return class extends e{models=new Map;modelKeepWarm=6e4;model(e,...t){let n=this.models.get(e);n||(n=new Map,this.models.set(e,n));const r=e.getKey?e.getKey(...t):Zu(t);let o=n.get(r);if(!o){const i=()=>{n.get(r)===o&&n.delete(r)};o=e(...t)(this).pipe(Al(i),function(e){void 0===e&&(e={});var t=e.connector,n=void 0===t?function(){return new Ac}:t,r=e.resetOnError,o=void 0===r||r,i=e.resetOnComplete,s=void 0===i||i,a=e.resetOnRefCountZero,c=void 0===a||a;return function(e){var t,r,i,a=0,l=!1,u=!1,d=function(){null==r||r.unsubscribe(),r=void 0},f=function(){d(),t=i=void 0,l=u=!1},h=function(){var e=t;f(),null==e||e.unsubscribe()};return xc(function(e,p){a++,u||l||d();var y=i=null!=i?i:n();p.add(function(){0!==--a||u||l||(r=$l(h,c))}),y.subscribe(p),!t&&a>0&&(t=new pc({next:function(e){return y.next(e)},error:function(e){u=!0,d(),r=$l(f,o,e),y.error(e)},complete:function(){l=!0,d(),r=$l(f,s),y.complete()}}),Gc(e).subscribe(t))})(e)}}({connector:()=>new _c(1),resetOnComplete:()=>vl(this.modelKeepWarm),resetOnRefCountZero:()=>vl(this.modelKeepWarm)})),n.set(r,o)}return o}filters(e,t=!1){e=Array.isArray(e)?e:[e];const n=this.getByFilters(e);return wl(t?Bc:n&&"function"==typeof n.then?nl(n).pipe(pl(e=>nl(Array.from(e)))):nl(Array.from(n)),this.insert$.pipe(bl(t=>Qu(e,t))))}event(e){return"string"==typeof e&&(e={id:e}),this.model(Ed,e)}replaceable(...e){let t;if(1===e.length)t=e[0];else if(3===e.length||2===e.length){let[n,r,o]=e;t={kind:n,pubkey:r,identifier:o}}if(!t)throw new Error("Invalid arguments, expected address pointer or kind, pubkey, identifier");return this.model(kd,t)}addressable(e){return this.model(kd,e)}timeline(e,t=!1){return this.model(Sd,e,t)}profile(e){return this.model(Rd,e)}contacts(e){return"string"==typeof e&&(e={pubkey:e}),this.model(_d,e)}mutes(e){return"string"==typeof e&&(e={pubkey:e}),this.model(Od,e)}mailboxes(e){return"string"==typeof e&&(e={pubkey:e}),this.model(Id,e)}blossomServers(e){return"string"==typeof e&&(e={pubkey:e}),this.model(Xu,e)}reactions(e){return this.model(Pd,e)}thread(e){return this.model(Bd,e)}comments(e){return this.model($d,e)}events(e){return this.model(Ad,e)}replaceableSet(e){return this.model(Cd,e)}}}class Ud extends(Nd(class{})){database;memory;keepOldVersions=!1;keepExpired=!1;verifyEvent;insert$=new Ac;update$=new Ac;remove$=new Ac;eventLoader;replaceableLoader;addressableLoader;constructor(e=new Ku){super(),e?(this.database=e,this.memory=new Ku):this.database=this.memory=new Ku,this.insert$.subscribe(e=>{Reflect.set(e,Hl,this)}),this.remove$.subscribe(e=>{Reflect.deleteProperty(e,Hl)})}mapToMemory(e){if(void 0!==e)return this.memory?this.memory.add(e):e}deletedIds=new Set;deletedCoords=new Map;checkDeleted(e){if("string"==typeof e)return this.deletedIds.has(e);if(this.deletedIds.has(e.id))return!0;if(Fa(e.kind)){const t=e.tags.find(e=>"d"===e[0])?.[1],n=this.deletedCoords.get(Zl(e.kind,e.pubkey,t));if(n)return n>e.created_at}return!1}expirations=new Map;addExpiration(e){const t=eu(e);t&&Number.isFinite(t)&&this.expirations.set(e.id,t)}expirationTimeout=null;nextExpirationCheck=null;handleExpiringEvent(e){const t=eu(e);if(!t)return;if(this.expirations.set(e.id,t),this.expirationTimeout&&this.nextExpirationCheck&&this.nextExpirationCheck<t)return;this.expirationTimeout&&clearTimeout(this.expirationTimeout);const n=t-Ql();this.expirationTimeout=setTimeout(this.pruneExpired.bind(this),1e3*n+10),this.nextExpirationCheck=t}pruneExpired(){const e=Ql();for(const[t,n]of this.expirations)n<=e&&(this.expirations.delete(t),this.remove(t));this.expirationTimeout&&clearTimeout(this.expirationTimeout),this.nextExpirationCheck=null,this.expirationTimeout=null}handleDeleteEvent(e){const t=function(e){return e.tags.filter(Pl).map(e=>e[1])}(e);for(const e of t)this.deletedIds.add(e),this.remove(e);const n=function(e){return e.tags.filter(Nl).map(e=>e[1])}(e);for(const t of n){this.deletedCoords.set(t,Math.max(this.deletedCoords.get(t)??0,e.created_at));const n=yu(t);if(!n)continue;const r=this.database.getReplaceableHistory(n.kind,n.pubkey,n.identifier)??[];for(const t of r)t.created_at<e.created_at&&this.remove(t)}}static mergeDuplicateEvent(e,t){const n=e[nu];if(n)for(const e of n)ru(t,e);const r=Reflect.get(e,Wl);r&&!Reflect.get(t,Wl)&&Reflect.set(t,Wl,r)}add(e,t){if(e.kind===so.EventDeletion&&this.handleDeleteEvent(e),this.checkDeleted(e))return e;const n=eu(e);if(!1===this.keepExpired&&n&&n<=Ql())return null;const r=Jl(e.kind)?e.tags.find(e=>"d"===e[0])?.[1]:void 0;if(!this.keepOldVersions&&Jl(e.kind)){const t=this.database.getReplaceableHistory(e.kind,e.pubkey,r);if(t&&t.length>0&&t[0].created_at>=e.created_at)return Ud.mergeDuplicateEvent(e,t[0]),t[0]}if(this.verifyEvent&&!1===this.verifyEvent(e))return null;const o=this.memory?.add(e);if(o&&o!==e)return Ud.mergeDuplicateEvent(e,o),t&&ru(o,t),o;const i=this.mapToMemory(this.database.add(e));if(e!==i&&Ud.mergeDuplicateEvent(e,i),t&&ru(i,t),i===e&&this.insert$.next(i),!this.keepOldVersions&&Jl(e.kind)){const t=this.database.getReplaceableHistory(e.kind,e.pubkey,r);if(t&&t.length>0){const n=Array.from(t).filter(t=>t.created_at<e.created_at);for(const e of n)this.remove(e);if(t.length!==n.length)return t[0]}}return!1===this.keepExpired&&n&&this.handleExpiringEvent(i),i}remove(e){let t=this.memory?.getEvent("string"==typeof e?e:e.id);this.memory&&this.memory.remove(e);const n=this.database.remove(e);return n&&t&&this.remove$.next(t),n}removeByFilters(e){const t=this.getByFilters(e);this.memory&&this.memory.removeByFilters(e);const n=this.database.removeByFilters(e);for(const e of t)this.remove$.next(e);return n}update(e){return!!this.database.add(e)&&(this.database.update?.(e),this.update$.next(e),!0)}hasEvent(e){return this.memory?.hasEvent(e)||this.database.hasEvent(e)}getEvent(e){return this.memory?.getEvent(e)??this.mapToMemory(this.database.getEvent(e))}hasReplaceable(e,t,n){return this.memory?.hasReplaceable(e,t,n)||this.database.hasReplaceable(e,t,n)}getReplaceable(e,t,n){return this.memory?.getReplaceable(e,t,n)??this.mapToMemory(this.database.getReplaceable(e,t,n))}getReplaceableHistory(e,t,n){return this.memory?.getReplaceableHistory(e,t,n)??this.database.getReplaceableHistory(e,t,n)?.map(e=>this.mapToMemory(e)??e)}getByFilters(e){const t=this.database.getByFilters(e);return this.memory?t.map(e=>this.mapToMemory(e)):t}getTimeline(e){const t=this.database.getTimeline(e);return this.memory?t.map(e=>this.mapToMemory(e)):t}touch(e){return this.memory?.touch(e)}claim(e,t){return this.memory?.claim(e,t)}isClaimed(e){return this.memory?.isClaimed(e)??!1}removeClaim(e,t){return this.memory?.removeClaim(e,t)}clearClaim(e){return this.memory?.clearClaim(e)}unclaimed(){return this.memory?.unclaimed()||function*(){}()}prune(e){return this.memory?.prune(e)??0}removed(e){return this.checkDeleted(e)?Bc:this.remove$.pipe(bl(t=>t.id===e),xl(1),pl(()=>Bc))}updated(e){return this.update$.pipe(bl(t=>t.id===e||t===e))}}function jd(){let e,t;const n=new Promise((n,r)=>{e=n,t=r});return n.resolve=e,n.reject=t,n}"navigator"in globalThis&&navigator.userAgent.includes("Android")&&navigator.clipboard&&navigator.clipboard.readText;var Md,Fd;Au(so.NostrConnect,"nip44"),function(e){e.GetPublicKey="get_pubic_key",e.SignEvent="sign_event",e.Nip04Encrypt="nip04_encrypt",e.Nip04Decrypt="nip04_decrypt",e.Nip44Encrypt="nip44_encrypt",e.Nip44Decrypt="nip44_decrypt"}(Md||(Md={})),function(e){e.Connect="connect",e.CreateAccount="create_account",e.GetPublicKey="get_public_key",e.SignEvent="sign_event",e.Nip04Encrypt="nip04_encrypt",e.Nip04Decrypt="nip04_decrypt",e.Nip44Encrypt="nip44_encrypt",e.Nip44Decrypt="nip44_decrypt"}(Fd||(Fd={}));class Dd{key;constructor(e){this.key=e||no()}async getPublicKey(){return ro(this.key)}async signEvent(e){return oo(e,this.key)}nip04={encrypt:async(e,t)=>ss.encrypt(this.key,e,t),decrypt:async(e,t)=>ss.decrypt(this.key,e,t)};nip44={encrypt:async(e,t)=>ks.v2.encrypt(t,ks.v2.utils.getConversationKey(this.key,e)),decrypt:async(e,t)=>ks.v2.decrypt(t,ks.v2.utils.getConversationKey(this.key,e))};static fromKey(e){return new Dd(wu(e))}}const Hd="object"==typeof globalThis&&"crypto"in globalThis?globalThis.crypto:void 0;
/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */function qd(e,...t){if(!((n=e)instanceof Uint8Array||ArrayBuffer.isView(n)&&"Uint8Array"===n.constructor.name))throw new Error("Uint8Array expected");var n;if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}const zd=(()=>"function"==typeof Uint8Array.from([]).toHex&&"function"==typeof Uint8Array.fromHex)(),Wd=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Kd(e){if(qd(e),zd)return e.toHex();let t="";for(let n=0;n<e.length;n++)t+=Wd[e[n]];return t}const Jd=48,Vd=57,Gd=65,Zd=70,Yd=97,Qd=102;function Xd(e){return e>=Jd&&e<=Vd?e-Jd:e>=Gd&&e<=Zd?e-(Gd-10):e>=Yd&&e<=Qd?e-(Yd-10):void 0}function ef(e){if("string"!=typeof e)throw new Error("hex string expected, got "+typeof e);if(zd)return Uint8Array.fromHex(e);const t=e.length,n=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);const r=new Uint8Array(n);for(let t=0,o=0;t<n;t++,o+=2){const n=Xd(e.charCodeAt(o)),i=Xd(e.charCodeAt(o+1));if(void 0===n||void 0===i){const t=e[o]+e[o+1];throw new Error('hex string expected, got non-hex character "'+t+'" at index '+o)}r[t]=16*n+i}return r}
/*! noble-secp256k1 - MIT License (c) 2019 Paul Miller (paulmillr.com) */
const tf=BigInt(0),nf=BigInt(1),rf=BigInt(2),of=BigInt(3),sf=BigInt(8),af=Object.freeze({a:tf,b:BigInt(7),P:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:nf,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee")}),cf=(e,t)=>(e+t/rf)/t,lf={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar(e){const{n:t}=af,n=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),r=-nf*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),i=n,s=BigInt("0x100000000000000000000000000000000"),a=cf(i*e,t),c=cf(-r*e,t);let l=Lf(e-a*n-c*o,t),u=Lf(-a*r-c*i,t);const d=l>s,f=u>s;if(d&&(l=t-l),f&&(u=t-u),l>s||u>s)throw new Error("splitScalarEndo: Endomorphism failed, k="+e);return{k1neg:d,k1:l,k2neg:f,k2:u}}},uf=32;function df(e){const{a:t,b:n}=af,r=Lf(e*e),o=Lf(r*e);return Lf(o+t*e+n)}const ff=af.a===tf;function hf(e){if(!(e instanceof pf))throw new TypeError("JacobianPoint expected")}class pf{constructor(e,t,n){this.x=e,this.y=t,this.z=n}static fromAffine(e){if(!(e instanceof mf))throw new TypeError("JacobianPoint#fromAffine: expected Point");return e.equals(mf.ZERO)?pf.ZERO:new pf(e.x,e.y,nf)}static toAffineBatch(e){const t=function(e,t=af.P){const n=new Array(e.length),r=e.reduce((e,r,o)=>r===tf?e:(n[o]=e,Lf(e*r,t)),nf),o=Nf(r,t);return e.reduceRight((e,r,o)=>r===tf?e:(n[o]=Lf(e*n[o],t),Lf(e*r,t)),o),n}(e.map(e=>e.z));return e.map((e,n)=>e.toAffine(t[n]))}static normalizeZ(e){return pf.toAffineBatch(e).map(pf.fromAffine)}equals(e){hf(e);const{x:t,y:n,z:r}=this,{x:o,y:i,z:s}=e,a=Lf(r*r),c=Lf(s*s),l=Lf(t*c),u=Lf(o*a),d=Lf(Lf(n*s)*c),f=Lf(Lf(i*r)*a);return l===u&&d===f}negate(){return new pf(this.x,Lf(-this.y),this.z)}double(){const{x:e,y:t,z:n}=this,r=Lf(e*e),o=Lf(t*t),i=Lf(o*o),s=e+o,a=Lf(rf*(Lf(s*s)-r-i)),c=Lf(of*r),l=Lf(c*c),u=Lf(l-rf*a),d=Lf(c*(a-u)-sf*i),f=Lf(rf*t*n);return new pf(u,d,f)}add(e){hf(e);const{x:t,y:n,z:r}=this,{x:o,y:i,z:s}=e;if(o===tf||i===tf)return this;if(t===tf||n===tf)return e;const a=Lf(r*r),c=Lf(s*s),l=Lf(t*c),u=Lf(o*a),d=Lf(Lf(n*s)*c),f=Lf(Lf(i*r)*a),h=Lf(u-l),p=Lf(f-d);if(h===tf)return p===tf?this.double():pf.ZERO;const y=Lf(h*h),g=Lf(h*y),m=Lf(l*y),v=Lf(p*p-g-rf*m),w=Lf(p*(m-v)-d*g),b=Lf(r*s*h);return new pf(v,w,b)}subtract(e){return this.add(e.negate())}multiplyUnsafe(e){const t=pf.ZERO;if("bigint"==typeof e&&e===tf)return t;let n=Pf(e);if(n===nf)return this;if(!ff){let e=t,r=this;for(;n>tf;)n&nf&&(e=e.add(r)),r=r.double(),n>>=nf;return e}let{k1neg:r,k1:o,k2neg:i,k2:s}=lf.splitScalar(n),a=t,c=t,l=this;for(;o>tf||s>tf;)o&nf&&(a=a.add(l)),s&nf&&(c=c.add(l)),l=l.double(),o>>=nf,s>>=nf;return r&&(a=a.negate()),i&&(c=c.negate()),c=new pf(Lf(c.x*lf.beta),c.y,c.z),a.add(c)}precomputeWindow(e){const t=ff?128/e+1:256/e+1,n=[];let r=this,o=r;for(let i=0;i<t;i++){o=r,n.push(o);for(let t=1;t<2**(e-1);t++)o=o.add(r),n.push(o);r=o.double()}return n}wNAF(e,t){!t&&this.equals(pf.BASE)&&(t=mf.BASE);const n=t&&t._WINDOW_SIZE||1;if(256%n)throw new Error("Point#wNAF: Invalid precomputation window, must be power of 2");let r=t&&gf.get(t);r||(r=this.precomputeWindow(n),t&&1!==n&&(r=pf.normalizeZ(r),gf.set(t,r)));let o=pf.ZERO,i=pf.BASE;const s=1+(ff?128/n:256/n),a=2**(n-1),c=BigInt(2**n-1),l=2**n,u=BigInt(n);for(let t=0;t<s;t++){const n=t*a;let s=Number(e&c);e>>=u,s>a&&(s-=l,e+=nf);const d=n,f=n+Math.abs(s)-1,h=t%2!=0,p=s<0;0===s?i=i.add(yf(h,r[d])):o=o.add(yf(p,r[f]))}return{p:o,f:i}}multiply(e,t){let n,r,o=Pf(e);if(ff){const{k1neg:e,k1:i,k2neg:s,k2:a}=lf.splitScalar(o);let{p:c,f:l}=this.wNAF(i,t),{p:u,f:d}=this.wNAF(a,t);c=yf(e,c),u=yf(s,u),u=new pf(Lf(u.x*lf.beta),u.y,u.z),n=c.add(u),r=l.add(d)}else{const{p:e,f:i}=this.wNAF(o,t);n=e,r=i}return pf.normalizeZ([n,r])[0]}toAffine(e){const{x:t,y:n,z:r}=this,o=this.equals(pf.ZERO);null==e&&(e=o?sf:Nf(r));const i=e,s=Lf(i*i),a=Lf(s*i),c=Lf(t*s),l=Lf(n*a),u=Lf(r*i);if(o)return mf.ZERO;if(u!==nf)throw new Error("invZ was invalid");return new mf(c,l)}}function yf(e,t){const n=t.negate();return e?n:t}pf.BASE=new pf(af.Gx,af.Gy,nf),pf.ZERO=new pf(tf,nf,tf);const gf=new WeakMap;class mf{constructor(e,t){this.x=e,this.y=t}_setWindowSize(e){this._WINDOW_SIZE=e,gf.delete(this)}hasEvenY(){return this.y%rf===tf}static fromCompressedHex(e){const t=32===e.length,n=Of(t?e:e.subarray(1));if(!jf(n))throw new Error("Point is not on curve");let r=function(e){const{P:t}=af,n=BigInt(6),r=BigInt(11),o=BigInt(22),i=BigInt(23),s=BigInt(44),a=BigInt(88),c=e*e*e%t,l=c*c*e%t,u=Bf(l,of)*l%t,d=Bf(u,of)*l%t,f=Bf(d,rf)*c%t,h=Bf(f,r)*f%t,p=Bf(h,o)*h%t,y=Bf(p,s)*p%t,g=Bf(y,a)*y%t,m=Bf(g,s)*p%t,v=Bf(m,of)*l%t,w=Bf(v,i)*h%t,b=Bf(w,n)*c%t,x=Bf(b,rf);if(x*x%t!==e)throw new Error("Cannot find square root");return x}(df(n));const o=(r&nf)===nf;if(t)o&&(r=Lf(-r));else{!(1&~e[0])!==o&&(r=Lf(-r))}const i=new mf(n,r);return i.assertValidity(),i}static fromUncompressedHex(e){const t=Of(e.subarray(1,33)),n=Of(e.subarray(33,65)),r=new mf(t,n);return r.assertValidity(),r}static fromHex(e){const t=Rf(e),n=t.length,r=t[0];if(n===uf)return this.fromCompressedHex(t);if(33===n&&(2===r||3===r))return this.fromCompressedHex(t);if(65===n&&4===r)return this.fromUncompressedHex(t);throw new Error(`Point.fromHex: received invalid point. Expected 32-33 compressed bytes or 65 uncompressed bytes, not ${n}`)}static fromPrivateKey(e){return mf.BASE.multiply(function(e){let t;if("bigint"==typeof e)t=e;else if("number"==typeof e&&Number.isSafeInteger(e)&&e>0)t=BigInt(e);else if("string"==typeof e){if(64!==e.length)throw new Error("Expected 32 bytes of private key");t=If(e)}else{if(!xf(e))throw new TypeError("Expected valid private key");if(32!==e.length)throw new Error("Expected 32 bytes of private key");t=Of(e)}if(!Uf(t))throw new Error("Expected private key: 0 < key < n");return t}(e))}static fromSignature(e,t,n){const{r:r,s:o}=function(e){if(e instanceof bf)return e.assertValidity(),e;try{return bf.fromDER(e)}catch(t){return bf.fromCompact(e)}}(t);if(![0,1,2,3].includes(n))throw new Error("Cannot recover: invalid recovery bit");const i=function(e,t=!1){const n=function(e){const t=8*e.length-256,n=Of(e);return t>0?n>>BigInt(t):n}(e);if(t)return n;const{n:r}=af;return n>=r?n-r:n}(Rf(e)),{n:s}=af,a=2===n||3===n?r+s:r,c=Nf(a,s),l=Lf(-i*c,s),u=Lf(o*c,s),d=1&n?"03":"02",f=mf.fromHex(d+_f(a)),h=mf.BASE.multiplyAndAddUnsafe(f,l,u);if(!h)throw new Error("Cannot recover signature: point at infinify");return h.assertValidity(),h}toRawBytes(e=!1){return Cf(this.toHex(e))}toHex(e=!1){const t=_f(this.x);if(e){return`${this.hasEvenY()?"02":"03"}${t}`}return`04${t}${_f(this.y)}`}toHexX(){return this.toHex(!0).slice(2)}toRawX(){return this.toRawBytes(!0).slice(1)}assertValidity(){const e="Point is not on elliptic curve",{x:t,y:n}=this;if(!jf(t)||!jf(n))throw new Error(e);const r=Lf(n*n);if(Lf(r-df(t))!==tf)throw new Error(e)}equals(e){return this.x===e.x&&this.y===e.y}negate(){return new mf(this.x,Lf(-this.y))}double(){return pf.fromAffine(this).double().toAffine()}add(e){return pf.fromAffine(this).add(pf.fromAffine(e)).toAffine()}subtract(e){return this.add(e.negate())}multiply(e){return pf.fromAffine(this).multiply(e,this).toAffine()}multiplyAndAddUnsafe(e,t,n){const r=pf.fromAffine(this),o=t===tf||t===nf||this!==mf.BASE?r.multiplyUnsafe(t):r.multiply(t),i=pf.fromAffine(e).multiplyUnsafe(n),s=o.add(i);return s.equals(pf.ZERO)?void 0:s.toAffine()}}function vf(e){return Number.parseInt(e[0],16)>=8?"00"+e:e}function wf(e){if(e.length<2||2!==e[0])throw new Error(`Invalid signature integer tag: ${kf(e)}`);const t=e[1],n=e.subarray(2,t+2);if(!t||n.length!==t)throw new Error("Invalid signature integer: wrong length");if(0===n[0]&&n[1]<=127)throw new Error("Invalid signature integer: trailing length");return{data:Of(n),left:e.subarray(t+2)}}mf.BASE=new mf(af.Gx,af.Gy),mf.ZERO=new mf(tf,tf);class bf{constructor(e,t){this.r=e,this.s=t,this.assertValidity()}static fromCompact(e){const t=xf(e),n="Signature.fromCompact";if("string"!=typeof e&&!t)throw new TypeError(`${n}: Expected string or Uint8Array`);const r=t?kf(e):e;if(128!==r.length)throw new Error(`${n}: Expected 64-byte hex`);return new bf(If(r.slice(0,64)),If(r.slice(64,128)))}static fromDER(e){const t=xf(e);if("string"!=typeof e&&!t)throw new TypeError("Signature.fromDER: Expected string or Uint8Array");const{r:n,s:r}=function(e){if(e.length<2||48!=e[0])throw new Error(`Invalid signature tag: ${kf(e)}`);if(e[1]!==e.length-2)throw new Error("Invalid signature: incorrect length");const{data:t,left:n}=wf(e.subarray(2)),{data:r,left:o}=wf(n);if(o.length)throw new Error(`Invalid signature: left bytes after parsing: ${kf(o)}`);return{r:t,s:r}}(t?e:Cf(e));return new bf(n,r)}static fromHex(e){return this.fromDER(e)}assertValidity(){const{r:e,s:t}=this;if(!Uf(e))throw new Error("Invalid Signature: r must be 0 < r < n");if(!Uf(t))throw new Error("Invalid Signature: s must be 0 < s < n")}hasHighS(){const e=af.n>>nf;return this.s>e}normalizeS(){return this.hasHighS()?new bf(this.r,Lf(-this.s,af.n)):this}toDERRawBytes(){return Cf(this.toDERHex())}toDERHex(){const e=vf($f(this.s)),t=vf($f(this.r)),n=e.length/2,r=t.length/2,o=$f(n),i=$f(r);return`30${$f(r+n+4)}02${i}${t}02${o}${e}`}toRawBytes(){return this.toDERRawBytes()}toHex(){return this.toDERHex()}toCompactRawBytes(){return Cf(this.toCompactHex())}toCompactHex(){return _f(this.r)+_f(this.s)}}function xf(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&"Uint8Array"===e.constructor.name}const Ef=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function kf(e){!function(e){if(!xf(e))throw new Error("Uint8Array expected")}(e);let t="";for(let n=0;n<e.length;n++)t+=Ef[e[n]];return t}const Sf={_0:48,_9:57,A:65,F:70,a:97,f:102};function Af(e){return e>=Sf._0&&e<=Sf._9?e-Sf._0:e>=Sf.A&&e<=Sf.F?e-(Sf.A-10):e>=Sf.a&&e<=Sf.f?e-(Sf.a-10):void 0}function Cf(e){if("string"!=typeof e)throw new Error("hex string expected, got "+typeof e);const t=e.length,n=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);const r=new Uint8Array(n);for(let t=0,o=0;t<n;t++,o+=2){const n=Af(e.charCodeAt(o)),i=Af(e.charCodeAt(o+1));if(void 0===n||void 0===i){const t=e[o]+e[o+1];throw new Error('hex string expected, got non-hex character "'+t+'" at index '+o)}r[t]=16*n+i}return r}const Tf=BigInt("0x10000000000000000000000000000000000000000000000000000000000000000");function _f(e){if("bigint"!=typeof e)throw new Error("Expected bigint");if(!(tf<=e&&e<Tf))throw new Error("Expected number 0 <= n < 2^256");return e.toString(16).padStart(64,"0")}function $f(e){const t=e.toString(16);return 1&t.length?`0${t}`:t}function If(e){if("string"!=typeof e)throw new TypeError("hexToNumber: expected string, got "+typeof e);return BigInt(`0x${e}`)}function Of(e){return If(kf(e))}function Rf(e){return xf(e)?Uint8Array.from(e):Cf(e)}function Pf(e){if("number"==typeof e&&Number.isSafeInteger(e)&&e>0)return BigInt(e);if("bigint"==typeof e&&Uf(e))return e;throw new TypeError("Expected valid private scalar: 0 < scalar < curve.n")}function Lf(e,t=af.P){const n=e%t;return n>=tf?n:t+n}function Bf(e,t){const{P:n}=af;let r=e;for(;t-- >tf;)r*=r,r%=n;return r}function Nf(e,t=af.P){if(e===tf||t<=tf)throw new Error(`invert: expected positive integers, got n=${e} mod=${t}`);let n=Lf(e,t),r=t,o=tf,i=nf;for(;n!==tf;){const e=r%n,t=o-i*(r/n);r=n,n=e,o=i,i=t}if(r!==nf)throw new Error("invert: does not exist");return Lf(o,t)}function Uf(e){return tf<e&&e<af.n}function jf(e){return tf<e&&e<af.P}
/*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) */
function Mf(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&"Uint8Array"===e.constructor.name}function Ff(e,t){return!!Array.isArray(t)&&(0===t.length||(e?t.every(e=>"string"==typeof e):t.every(e=>Number.isSafeInteger(e))))}function Df(e,t){if("string"!=typeof t)throw new Error(`${e}: string expected`);return!0}function Hf(e){if(!Number.isSafeInteger(e))throw new Error(`invalid integer: ${e}`)}function qf(e){if(!Array.isArray(e))throw new Error("array expected")}function zf(e,t){if(!Ff(!0,t))throw new Error(`${e}: array of strings expected`)}mf.BASE._setWindowSize(8);const Wf=(e,t)=>0===t?e:Wf(t,e%t),Kf=(e,t)=>e+(t-Wf(e,t)),Jf=(()=>{let e=[];for(let t=0;t<40;t++)e.push(2**t);return e})();function Vf(e,t,n,r){if(qf(e),t<=0||t>32)throw new Error(`convertRadix2: wrong from=${t}`);if(n<=0||n>32)throw new Error(`convertRadix2: wrong to=${n}`);if(Kf(t,n)>32)throw new Error(`convertRadix2: carry overflow from=${t} to=${n} carryBits=${Kf(t,n)}`);let o=0,i=0;const s=Jf[t],a=Jf[n]-1,c=[];for(const r of e){if(Hf(r),r>=s)throw new Error(`convertRadix2: invalid data word=${r} from=${t}`);if(o=o<<t|r,i+t>32)throw new Error(`convertRadix2: carry overflow pos=${i} from=${t}`);for(i+=t;i>=n;i-=n)c.push((o>>i-n&a)>>>0);const e=Jf[i];if(void 0===e)throw new Error("invalid carry");o&=e-1}if(o=o<<n-i&a,!r&&i>=t)throw new Error("Excess padding");if(!r&&o>0)throw new Error(`Non-zero padding: ${o}`);return r&&i>0&&c.push(o>>>0),c}const Gf=(()=>"function"==typeof Uint8Array.from([]).toBase64&&"function"==typeof Uint8Array.fromBase64)()?{encode:e=>(function(e,...t){if(!Mf(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}(e),e.toBase64()),decode:e=>((e,t)=>{Df("base64",e);const n=t?/^[A-Za-z0-9=_-]+$/:/^[A-Za-z0-9=+/]+$/,r=t?"base64url":"base64";if(e.length>0&&!n.test(e))throw new Error("invalid base64");return Uint8Array.fromBase64(e,{alphabet:r,lastChunkHandling:"strict"})})(e,!1)}:function(...e){const t=e=>e,n=(e,t)=>n=>e(t(n));return{encode:e.map(e=>e.encode).reduceRight(n,t),decode:e.map(e=>e.decode).reduce(n,t)}}(function(e,t=!1){if(Hf(e),e<=0||e>32)throw new Error("radix2: bits should be in (0..32]");if(Kf(8,e)>32||Kf(e,8)>32)throw new Error("radix2: carry overflow");return{encode:n=>{if(!Mf(n))throw new Error("radix2.encode input should be Uint8Array");return Vf(Array.from(n),8,e,!t)},decode:n=>(function(e,t){if(!Ff(!1,t))throw new Error(`${e}: array of numbers expected`)}("radix2.decode",n),Uint8Array.from(Vf(n,e,8,t)))}}(6),function(e){const t="string"==typeof e?e.split(""):e,n=t.length;zf("alphabet",t);const r=new Map(t.map((e,t)=>[e,t]));return{encode:r=>(qf(r),r.map(r=>{if(!Number.isSafeInteger(r)||r<0||r>=n)throw new Error(`alphabet.encode: digit index outside alphabet "${r}". Allowed: ${e}`);return t[r]})),decode:t=>(qf(t),t.map(t=>{Df("alphabet.decode",t);const n=r.get(t);if(void 0===n)throw new Error(`Unknown letter: "${t}". Allowed: ${e}`);return n}))}}("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),function(e,t="="){return Hf(e),Df("padding",t),{encode(n){for(zf("padding.encode",n);n.length*e%8;)n.push(t);return n},decode(n){zf("padding.decode",n);let r=n.length;if(r*e%8)throw new Error("padding: invalid, string should have whole number of bytes");for(;r>0&&n[r-1]===t;r--){if((r-1)*e%8==0)throw new Error("padding: invalid, string has too much padding")}return n.slice(0,r)}}}(6),function(e=""){return Df("join",e),{encode:t=>(zf("join.decode",t),t.join(e)),decode:t=>(Df("join.decode",t),t.split(e))}}(""));function Zf(e){return mf.fromHex(e).toHex().substring(2)}const Yf=new TextDecoder("utf-8"),Qf=new TextEncoder;class Xf{log=Wu.extend("SerialPortSigner");writer=null;pubkey;get isConnected(){return!!this.writer}verifyEvent=io;nip04;constructor(){this.nip04={encrypt:this.nip04Encrypt.bind(this),decrypt:this.nip04Decrypt.bind(this)}}lastCommand=null;async callMethodOnDevice(e,t,n={}){if(!Xf.SUPPORTED)throw new Error("Serial devices are not supported");if(this.writer||await this.connectToDevice(n),this.lastCommand)throw new Error("Previous command to device still pending!");const r=jd();return this.lastCommand=r,this.sendCommand(e,t),setTimeout(()=>{r.reject(new Error("Device timeout")),this.lastCommand===r&&(this.lastCommand=null)},6e3),this.lastCommand}async connectToDevice({onConnect:e,onDisconnect:t,onError:n,onDone:r}){let o,i=await window.navigator.serial.requestPort();await i.open({baudRate:9600}),await(e=>new Promise(t=>setTimeout(t,e)))(1e3),(async()=>{for(;i&&i.readable;){const e=new window.TextDecoderStream;i.readable.pipeTo(e.writable),o=e.readable.getReader();const t=this.readFromSerialPort(o);try{for(;;){const{value:e,done:n}=await t("\n");if(e){const{method:t,data:n}=this.parseResponse(e);if("/ping"===t&&this.log("Pong"),-1===Xf.PUBLIC_METHODS.indexOf(t))continue;this.log("Received: ",t,n),this.lastCommand&&(this.lastCommand.resolve(n),this.lastCommand=null)}if(n)return this.lastCommand=null,this.writer=null,void(r&&r())}}catch(e){if(e instanceof Error)throw this.writer=null,n&&n(e),this.lastCommand&&(this.lastCommand.reject(e),this.lastCommand=null),e}}})();const s=new window.TextEncoderStream;s.readable.pipeTo(i.writable),this.writer=s.writable.getWriter(),await this.sendCommand(Xf.METHOD_PING),await this.sendCommand(Xf.METHOD_PING,[window.location.host]),e&&e(),i.addEventListener("disconnect",()=>{this.log("Disconnected"),this.lastCommand=null,this.writer=null,t&&t()})}async sendCommand(e,t=[]){if(!this.writer)return;this.log("Send command",e,t);const n=[e].concat(t).join(" ");await this.writer.write(n+"\n")}readFromSerialPort(e){let t,n=[];return async(r="\n")=>{if(n.length)return{value:n.shift().trim(),done:!1};const o=[];for(t&&(o.push(t),t=void 0);;){const{value:i,done:s}=await e.read();if(i){const e=i.split(r);if(e.length>1)return o.push(e.shift()),t=e.pop(),n=e,{value:o.join("").trim(),done:!1};o.push(i)}if(s)return{value:o.join("").trim(),done:!0}}}}parseResponse(e){const t=e.split(" ")[0];return{method:t,data:e.substring(t.length).trim()}}async nip04Encrypt(e,t){const n=ef(await this.callMethodOnDevice(Xf.METHOD_SHARED_SECRET,[Zf(e)]));let r=Uint8Array.from(function(e=32){if(Hd&&"function"==typeof Hd.getRandomValues)return Hd.getRandomValues(new Uint8Array(e));if(Hd&&"function"==typeof Hd.randomBytes)return Uint8Array.from(Hd.randomBytes(e));throw new Error("crypto.getRandomValues must be defined")}(16)),o=Qf.encode(t),i=await crypto.subtle.importKey("raw",n,{name:"AES-CBC"},!1,["encrypt"]),s=await crypto.subtle.encrypt({name:"AES-CBC",iv:r},i,o);return`${Gf.encode(new Uint8Array(s))}?iv=${Gf.encode(new Uint8Array(r.buffer))}`}async nip04Decrypt(e,t){let[n,r]=t.split("?iv=");const o=ef(await this.callMethodOnDevice(Xf.METHOD_SHARED_SECRET,[Zf(e)]));let i=await crypto.subtle.importKey("raw",o,{name:"AES-CBC"},!1,["decrypt"]),s=Gf.decode(n),a=Gf.decode(r),c=await crypto.subtle.decrypt({name:"AES-CBC",iv:a},i,s);return Yf.decode(c)}async getPublicKey(){const e=await this.callMethodOnDevice(Xf.METHOD_PUBLIC_KEY,[]);return this.pubkey=e,e}async restore(e){await this.callMethodOnDevice(Xf.METHOD_RESTORE,[Kd(e)])}async signEvent(e){const t=e.pubkey||this.pubkey;if(!t)throw new Error("Unknown signer pubkey");const n={...e,id:eo({...e,pubkey:t})},r=await this.callMethodOnDevice(Xf.METHOD_SIGN_MESSAGE,[n.id]),o={...n,sig:r,pubkey:t};if(!this.verifyEvent(o))throw new Error("Invalid signature");return o}ping(){this.sendCommand(Xf.METHOD_PING,[window.location.host])}static SUPPORTED="navigator"in globalThis&&!!navigator.serial;static METHOD_PING="/ping";static METHOD_LOG="/log";static METHOD_SIGN_MESSAGE="/sign-message";static METHOD_SHARED_SECRET="/shared-secret";static METHOD_PUBLIC_KEY="/public-key";static METHOD_RESTORE="/restore";static PUBLIC_METHODS=[Xf.METHOD_PUBLIC_KEY,Xf.METHOD_SIGN_MESSAGE,Xf.METHOD_SHARED_SECRET,Xf.METHOD_RESTORE]}const eh=[`wss://${window.location.host}/`];class th{constructor(){this.pool=new _n,this.eventStore=new Ud,this.isConnected=!1,this.signer=null,this.relays=[...eh]}async connect(){console.log("Starting connection to",this.relays.length,"relays...");try{this.isConnected=!0,console.log("✓ Successfully initialized relay pool"),await new Promise(e=>setTimeout(e,1e3))}catch(e){throw console.error("✗ Connection failed:",e),e}}async connectToRelay(e){console.log(`Adding relay: ${e}`);try{return this.relays.includes(e)||this.relays.push(e),console.log(`✓ Successfully added relay ${e}`),!0}catch(t){return console.error(`✗ Failed to add relay ${e}:`,t),!1}}subscribe(e,t){console.log("Creating subscription with filters:",e);const n=this.pool.subscribeMany(this.relays,e,{onevent(e){console.log("Event received:",e),t(e)},oneose(){console.log("EOSE received"),window.dispatchEvent(new CustomEvent("nostr-eose",{detail:{subscriptionId:n.id}}))}});return n}unsubscribe(e){console.log("Closing subscription"),e&&e.close&&e.close()}disconnect(){console.log("Disconnecting relay pool"),this.pool&&this.pool.close(this.relays),this.isConnected=!1}async publish(e){console.log("Publishing event:",e);try{const t=this.pool.publish(this.relays,e);return await Promise.allSettled(t),console.log("✓ Event published successfully"),{success:!0,okCount:1,errorCount:0}}catch(e){throw console.error("✗ Failed to publish event:",e),e}}getPool(){return this.pool}getEventStore(){return this.eventStore}getSigner(){return this.signer}setSigner(e){this.signer=e}}const nh=new th,rh="events";function oh(){return new Promise((e,t)=>{try{const n=indexedDB.open("nostrCache",1);n.onupgradeneeded=()=>{const e=n.result;if(!e.objectStoreNames.contains(rh)){const t=e.createObjectStore(rh,{keyPath:"id"});t.createIndex("byKindAuthor",["kind","pubkey"],{unique:!1}),t.createIndex("byKindAuthorCreated",["kind","pubkey","created_at"],{unique:!1})}},n.onsuccess=()=>e(n.result),n.onerror=()=>t(n.error)}catch(e){t(e)}})}function ih(e){try{const t=JSON.parse(e.content||"{}");return{name:t.name||t.display_name||"",picture:t.picture||"",banner:t.banner||"",about:t.about||"",nip05:t.nip05||"",lud16:t.lud16||t.lud06||""}}catch(e){return{name:"",picture:"",banner:"",about:"",nip05:"",lud16:""}}}async function sh(e){console.log(`Starting profile fetch for pubkey: ${e}`);try{const t=await async function(e){try{const t=await oh();return await new Promise((n,r)=>{const o=t.transaction(rh,"readonly").objectStore(rh).index("byKindAuthorCreated"),i=IDBKeyRange.bound([0,e,-1/0],[0,e,1/0]),s=o.openCursor(i,"prev");s.onsuccess=()=>{const e=s.result;n(e?e.value:null)},s.onerror=()=>r(s.error)})}catch(e){return console.warn("IDB getLatestProfileEvent failed",e),null}}(e);if(t){console.log("Using cached profile event");return ih(t)}}catch(e){console.warn("Failed to load cached profile",e)}try{const t=[{kinds:[0],authors:[e],limit:1}],n=await ah(t,{timeout:1e4});if(n.length>0){const t=n[0];console.log("Profile fetched:",t),await async function(e){try{const t=await oh();await new Promise((n,r)=>{const o=t.transaction(rh,"readwrite");o.oncomplete=()=>n(),o.onerror=()=>r(o.error),o.objectStore(rh).put(e)})}catch(e){console.warn("IDB putEvent failed",e)}}(t);const r=ih(t);try{"undefined"!=typeof window&&window.dispatchEvent&&window.dispatchEvent(new CustomEvent("profile-updated",{detail:{pubkey:e,profile:r,event:t}}))}catch(e){console.warn("Failed to dispatch profile-updated event",e)}return r}throw new Error("No profile found")}catch(e){throw console.error("Failed to fetch profile:",e),e}}async function ah(e,t={}){console.log("Starting event fetch with filters:",e);const{timeout:n=3e4}=t;return new Promise((t,r)=>{const o=[],i=setTimeout(()=>{console.log(`Timeout reached after ${n}ms, returning ${o.length} events`),sub.close(),t(o)},n);try{const n=nh.pool.subscribeMany(nh.relays,e,{onevent(e){console.log("Event received:",e),o.push(e)},oneose(){console.log(`EOSE received, got ${o.length} events`),clearTimeout(i),n.close(),t(o)}})}catch(e){clearTimeout(i),console.error("Failed to fetch events:",e),r(e)}})}async function ch(e={}){const{limit:t=100,since:n=null,until:r=null,authors:o=null,kinds:i=null,...s}=e,a=[{...s}];n&&(a[0].since=n),r&&(a[0].until=r),o&&(a[0].authors=o),i&&(a[0].kinds=i),t&&(a[0].limit=t);return await ah(a,{timeout:3e4})}async function lh(e,t={}){const{timeout:n=1e4}=t;console.log(`Fetching event by ID: ${e}`);try{const t=[{ids:[e]}];console.log("Fetching event with filters:",t);const r=await ah(t,{timeout:n});return console.log(`Fetched ${r.length} events`),r.length>0?r[0]:null}catch(e){throw console.error("Failed to fetch event by ID:",e),e}}async function uh(e,t={}){const{timeout:n=1e4}=t;console.log(`Fetching delete events for target: ${e}`);try{const t=[{kinds:[5],"#e":[e]}];console.log("Fetching delete events with filters:",t);const r=await ah(t,{timeout:n});return console.log(`Fetched ${r.length} delete events`),r}catch(e){throw console.error("Failed to fetch delete events:",e),e}}async function dh(){await nh.connect()}const{window:fh}=c;function hh(e){let t,n,o,i,s,a,c,f,p,g,b,x,E,k,A,C,T,_;function $(e,t){return"extension"===e[2]?yh:ph}let I=$(e),O=I(e),R=e[5]&&gh(e),P=e[6]&&mh(e);return{c(){t=h("div"),n=h("div"),o=h("div"),i=h("h2"),i.textContent="Login to Nostr",s=y(),a=h("button"),a.textContent="×",c=y(),f=h("div"),p=h("div"),g=h("button"),g.textContent="Extension",b=y(),x=h("button"),x.textContent="Nsec",E=y(),k=h("div"),O.c(),A=y(),R&&R.c(),C=y(),P&&P.c(),w(i,"class","svelte-1wl3v5c"),w(a,"class","close-btn svelte-1wl3v5c"),w(o,"class","modal-header svelte-1wl3v5c"),w(g,"class","tab-btn svelte-1wl3v5c"),S(g,"active","extension"===e[2]),w(x,"class","tab-btn svelte-1wl3v5c"),S(x,"active","nsec"===e[2]),w(p,"class","tabs svelte-1wl3v5c"),w(k,"class","tab-content svelte-1wl3v5c"),w(f,"class","tab-container svelte-1wl3v5c"),w(n,"class","modal svelte-1wl3v5c"),S(n,"dark-theme",e[1]),w(t,"class","modal-overlay svelte-1wl3v5c"),w(t,"role","button"),w(t,"tabindex","0")},m(r,d){u(r,t,d),l(t,n),l(n,o),l(o,i),l(o,s),l(o,a),l(n,c),l(n,f),l(f,p),l(p,g),l(p,b),l(p,x),l(f,E),l(f,k),O.m(k,null),l(k,A),R&&R.m(k,null),l(k,C),P&&P.m(k,null),T||(_=[m(a,"click",e[7]),m(g,"click",e[14]),m(x,"click",e[15]),m(n,"click",v(e[12])),m(n,"keydown",v(e[13])),m(t,"click",e[7]),m(t,"keydown",e[17])],T=!0)},p(e,t){4&t&&S(g,"active","extension"===e[2]),4&t&&S(x,"active","nsec"===e[2]),I===(I=$(e))&&O?O.p(e,t):(O.d(1),O=I(e),O&&(O.c(),O.m(k,A))),e[5]?R?R.p(e,t):(R=gh(e),R.c(),R.m(k,C)):R&&(R.d(1),R=null),e[6]?P?P.p(e,t):(P=mh(e),P.c(),P.m(k,null)):P&&(P.d(1),P=null),2&t&&S(n,"dark-theme",e[1])},d(e){e&&d(t),O.d(),R&&R.d(),P&&P.d(),T=!1,r(_)}}}function ph(e){let t,n,o,i,s,a,c,f,g,v,b=e[4]?"Logging in...":"Log in with nsec";return{c(){t=h("div"),n=h("p"),n.textContent="Enter your nsec (private key) to login. This\n will be stored securely in your browser.",o=y(),i=h("input"),s=y(),a=h("button"),c=p(b),w(n,"class","svelte-1wl3v5c"),w(i,"type","password"),w(i,"placeholder","nsec1..."),i.disabled=e[4],w(i,"class","nsec-input svelte-1wl3v5c"),w(a,"class","login-nsec-btn svelte-1wl3v5c"),a.disabled=f=e[4]||!e[3].trim(),w(t,"class","nsec-login svelte-1wl3v5c")},m(r,d){u(r,t,d),l(t,n),l(t,o),l(t,i),E(i,e[3]),l(t,s),l(t,a),l(a,c),g||(v=[m(i,"input",e[16]),m(a,"click",e[10])],g=!0)},p(e,t){16&t&&(i.disabled=e[4]),8&t&&i.value!==e[3]&&E(i,e[3]),16&t&&b!==(b=e[4]?"Logging in...":"Log in with nsec")&&x(c,b),24&t&&f!==(f=e[4]||!e[3].trim())&&(a.disabled=f)},d(e){e&&d(t),g=!1,r(v)}}}function yh(e){let t,n,r,o,i,s,a,c=e[4]?"Connecting...":"Log in using extension";return{c(){t=h("div"),n=h("p"),n.textContent="Login using a NIP-07 compatible browser\n extension like nos2x or Alby.",r=y(),o=h("button"),i=p(c),w(n,"class","svelte-1wl3v5c"),w(o,"class","login-extension-btn svelte-1wl3v5c"),o.disabled=e[4],w(t,"class","extension-login svelte-1wl3v5c")},m(c,d){u(c,t,d),l(t,n),l(t,r),l(t,o),l(o,i),s||(a=m(o,"click",e[9]),s=!0)},p(e,t){16&t&&c!==(c=e[4]?"Connecting...":"Log in using extension")&&x(i,c),16&t&&(o.disabled=e[4])},d(e){e&&d(t),s=!1,a()}}}function gh(e){let t,n;return{c(){t=h("div"),n=p(e[5]),w(t,"class","message error-message svelte-1wl3v5c")},m(e,r){u(e,t,r),l(t,n)},p(e,t){32&t&&x(n,e[5])},d(e){e&&d(t)}}}function mh(e){let t,n;return{c(){t=h("div"),n=p(e[6]),w(t,"class","message success-message svelte-1wl3v5c")},m(e,r){u(e,t,r),l(t,n)},p(e,t){64&t&&x(n,e[6])},d(e){e&&d(t)}}}function vh(t){let n,r,o,i=t[0]&&hh(t);return{c(){i&&i.c(),n=g()},m(e,s){i&&i.m(e,s),u(e,n,s),r||(o=m(fh,"keydown",t[11]),r=!0)},p(e,[t]){e[0]?i?i.p(e,t):(i=hh(e),i.c(),i.m(n.parentNode,n)):i&&(i.d(1),i=null)},i:e,o:e,d(e){i&&i.d(e),e&&d(n),r=!1,o()}}}function wh(e,t,n){const r=_();let{showModal:o=!1}=t,{isDarkTheme:i=!1}=t,s="extension",a="",c=!1,l="",u="";function d(){n(0,o=!1),n(3,a=""),n(5,l=""),n(6,u=""),r("close")}function f(e){n(2,s=e),n(5,l=""),n(6,u="")}async function h(){n(4,c=!0),n(5,l=""),n(6,u="");try{if(!a.trim())throw new Error("Please enter your nsec");if(!(e=a.trim()).startsWith("nsec1")||(e.length<60||e.length>70))throw new Error('Invalid nsec format. Must start with "nsec1"');const t=Dd.fromKey(a.trim()),o=await t.getPublicKey();localStorage.setItem("nostr_auth_method","nsec"),localStorage.setItem("nostr_pubkey",o),localStorage.setItem("nostr_privkey",a.trim()),n(6,u="Successfully logged in with nsec!"),r("login",{method:"nsec",pubkey:o,privateKey:a.trim(),signer:t}),setTimeout(()=>{d()},1500)}catch(e){n(5,l=e.message)}finally{n(4,c=!1)}var e}return e.$$set=e=>{"showModal"in e&&n(0,o=e.showModal),"isDarkTheme"in e&&n(1,i=e.isDarkTheme)},[o,i,s,a,c,l,u,d,f,async function(){n(4,c=!0),n(5,l=""),n(6,u="");try{if(!window.nostr)throw new Error("No Nostr extension found. Please install a NIP-07 compatible extension like nos2x or Alby.");const e=await window.nostr.getPublicKey();e&&(localStorage.setItem("nostr_auth_method","extension"),localStorage.setItem("nostr_pubkey",e),n(6,u="Successfully logged in with extension!"),r("login",{method:"extension",pubkey:e,signer:window.nostr}),setTimeout(()=>{d()},1500))}catch(e){n(5,l=e.message)}finally{n(4,c=!1)}},h,function(e){"Escape"===e.key&&d(),"Enter"===e.key&&"nsec"===s&&h()},function(t){$.call(this,e,t)},function(t){$.call(this,e,t)},()=>f("extension"),()=>f("nsec"),function(){a=this.value,n(3,a)},e=>"Escape"===e.key&&d()]}class bh extends Q{constructor(e){super(),Y(this,e,wh,vh,i,{showModal:0,isDarkTheme:1})}}function xh(e,t,n){const r=e.slice();return r[72]=t[n],r}function Eh(e,t,n){const r=e.slice();return r[75]=t[n],r}function kh(e,t,n){const r=e.slice();return r[72]=t[n],r}function Sh(e,t,n){const r=e.slice();return r[72]=t[n],r}function Ah(e,t,n){const r=e.slice();return r[72]=t[n],r}function Ch(e,t,n){const r=e.slice();return r[72]=t[n],r}function Th(e,t,n){const r=e.slice();return r[72]=t[n],r}function _h(e){let t,n,r;return{c(){t=h("div"),n=p(e[3]),w(t,"class",r="message "+e[4]+" svelte-1smaj3x")},m(e,r){u(e,t,r),l(t,n)},p(e,o){8&o[0]&&x(n,e[3]),16&o[0]&&r!==(r="message "+e[4]+" svelte-1smaj3x")&&w(t,"class",r)},d(e){e&&d(t)}}}function $h(e){let t,n,o,i,s,a,c,f,g,v,b,x,k,S,A,C,T,_,$,I,O,R,P,L,B,N,U,j;function M(e,t){return e[5]&&e[5].length>0?Oh:Ih}let F=M(e),D=F(e);function H(e,t){return e[8]&&e[8].length>0?Bh:Lh}let q=H(e),z=q(e);return{c(){t=h("div"),n=h("div"),o=h("h3"),o.textContent="Banned Pubkeys",i=y(),s=h("div"),a=h("input"),c=y(),f=h("input"),g=y(),v=h("button"),b=p("Ban Pubkey"),x=y(),k=h("div"),D.c(),S=y(),A=h("div"),C=h("h3"),C.textContent="Allowed Pubkeys",T=y(),_=h("div"),$=h("input"),I=y(),O=h("input"),R=y(),P=h("button"),L=p("Allow Pubkey"),B=y(),N=h("div"),z.c(),w(o,"class","svelte-1smaj3x"),w(a,"type","text"),w(a,"placeholder","Pubkey (64 hex chars)"),w(a,"class","svelte-1smaj3x"),w(f,"type","text"),w(f,"placeholder","Reason (optional)"),w(f,"class","svelte-1smaj3x"),v.disabled=e[2],w(v,"class","svelte-1smaj3x"),w(s,"class","add-form svelte-1smaj3x"),w(k,"class","list svelte-1smaj3x"),w(n,"class","section svelte-1smaj3x"),w(C,"class","svelte-1smaj3x"),w($,"type","text"),w($,"placeholder","Pubkey (64 hex chars)"),w($,"class","svelte-1smaj3x"),w(O,"type","text"),w(O,"placeholder","Reason (optional)"),w(O,"class","svelte-1smaj3x"),P.disabled=e[2],w(P,"class","svelte-1smaj3x"),w(_,"class","add-form svelte-1smaj3x"),w(N,"class","list svelte-1smaj3x"),w(A,"class","section svelte-1smaj3x"),w(t,"class","pubkeys-section")},m(r,d){u(r,t,d),l(t,n),l(n,o),l(n,i),l(n,s),l(s,a),E(a,e[6]),l(s,c),l(s,f),E(f,e[7]),l(s,g),l(s,v),l(v,b),l(n,x),l(n,k),D.m(k,null),l(t,S),l(t,A),l(A,C),l(A,T),l(A,_),l(_,$),E($,e[9]),l(_,I),l(_,O),E(O,e[10]),l(_,R),l(_,P),l(P,L),l(A,B),l(A,N),z.m(N,null),U||(j=[m(a,"input",e[43]),m(f,"input",e[44]),m(v,"click",e[25]),m($,"input",e[45]),m(O,"input",e[46]),m(P,"click",e[26])],U=!0)},p(e,t){64&t[0]&&a.value!==e[6]&&E(a,e[6]),128&t[0]&&f.value!==e[7]&&E(f,e[7]),4&t[0]&&(v.disabled=e[2]),F===(F=M(e))&&D?D.p(e,t):(D.d(1),D=F(e),D&&(D.c(),D.m(k,null))),512&t[0]&&$.value!==e[9]&&E($,e[9]),1024&t[0]&&O.value!==e[10]&&E(O,e[10]),4&t[0]&&(P.disabled=e[2]),q===(q=H(e))&&z?z.p(e,t):(z.d(1),z=q(e),z&&(z.c(),z.m(N,null)))},d(e){e&&d(t),D.d(),z.d(),U=!1,r(j)}}}function Ih(t){let n;return{c(){n=h("div"),n.innerHTML="<p>No banned pubkeys configured.</p>",w(n,"class","no-items svelte-1smaj3x")},m(e,t){u(e,n,t)},p:e,d(e){e&&d(n)}}}function Oh(e){let t,n=e[5],r=[];for(let t=0;t<n.length;t+=1)r[t]=Ph(Th(e,n,t));return{c(){for(let e=0;e<r.length;e+=1)r[e].c();t=g()},m(e,n){for(let t=0;t<r.length;t+=1)r[t]&&r[t].m(e,n);u(e,t,n)},p(e,o){if(32&o[0]){let i;for(n=e[5],i=0;i<n.length;i+=1){const s=Th(e,n,i);r[i]?r[i].p(s,o):(r[i]=Ph(s),r[i].c(),r[i].m(t.parentNode,t))}for(;i<r.length;i+=1)r[i].d(1);r.length=n.length}},d(e){f(r,e),e&&d(t)}}}function Rh(e){let t,n,r=e[72].reason+"";return{c(){t=h("span"),n=p(r),w(t,"class","reason svelte-1smaj3x")},m(e,r){u(e,t,r),l(t,n)},p(e,t){32&t[0]&&r!==(r=e[72].reason+"")&&x(n,r)},d(e){e&&d(t)}}}function Ph(e){let t,n,r,o,i,s=e[72].pubkey+"",a=e[72].reason&&Rh(e);return{c(){t=h("div"),n=h("span"),r=p(s),o=y(),a&&a.c(),i=y(),w(n,"class","pubkey svelte-1smaj3x"),w(t,"class","list-item svelte-1smaj3x")},m(e,s){u(e,t,s),l(t,n),l(n,r),l(t,o),a&&a.m(t,null),l(t,i)},p(e,n){32&n[0]&&s!==(s=e[72].pubkey+"")&&x(r,s),e[72].reason?a?a.p(e,n):(a=Rh(e),a.c(),a.m(t,i)):a&&(a.d(1),a=null)},d(e){e&&d(t),a&&a.d()}}}function Lh(t){let n;return{c(){n=h("div"),n.innerHTML="<p>No allowed pubkeys configured.</p>",w(n,"class","no-items svelte-1smaj3x")},m(e,t){u(e,n,t)},p:e,d(e){e&&d(n)}}}function Bh(e){let t,n=e[8],r=[];for(let t=0;t<n.length;t+=1)r[t]=Uh(Ch(e,n,t));return{c(){for(let e=0;e<r.length;e+=1)r[e].c();t=g()},m(e,n){for(let t=0;t<r.length;t+=1)r[t]&&r[t].m(e,n);u(e,t,n)},p(e,o){if(256&o[0]){let i;for(n=e[8],i=0;i<n.length;i+=1){const s=Ch(e,n,i);r[i]?r[i].p(s,o):(r[i]=Uh(s),r[i].c(),r[i].m(t.parentNode,t))}for(;i<r.length;i+=1)r[i].d(1);r.length=n.length}},d(e){f(r,e),e&&d(t)}}}function Nh(e){let t,n,r=e[72].reason+"";return{c(){t=h("span"),n=p(r),w(t,"class","reason svelte-1smaj3x")},m(e,r){u(e,t,r),l(t,n)},p(e,t){256&t[0]&&r!==(r=e[72].reason+"")&&x(n,r)},d(e){e&&d(t)}}}function Uh(e){let t,n,r,o,i,s=e[72].pubkey+"",a=e[72].reason&&Nh(e);return{c(){t=h("div"),n=h("span"),r=p(s),o=y(),a&&a.c(),i=y(),w(n,"class","pubkey svelte-1smaj3x"),w(t,"class","list-item svelte-1smaj3x")},m(e,s){u(e,t,s),l(t,n),l(n,r),l(t,o),a&&a.m(t,null),l(t,i)},p(e,n){256&n[0]&&s!==(s=e[72].pubkey+"")&&x(r,s),e[72].reason?a?a.p(e,n):(a=Nh(e),a.c(),a.m(t,i)):a&&(a.d(1),a=null)},d(e){e&&d(t),a&&a.d()}}}function jh(e){let t,n,o,i,s,a,c,f,g,v,b,x,k,S,A,C,T,_,$,I,O,R,P,L,B,N,U,j;function M(e,t){return e[11]&&e[11].length>0?Fh:Mh}let F=M(e),D=F(e);let H=function(e){return e[22]&&e[22].length>0?zh:qh}(e),q=H(e);return{c(){t=h("div"),n=h("div"),o=h("h3"),o.textContent="Banned Events",i=y(),s=h("div"),a=h("input"),c=y(),f=h("input"),g=y(),v=h("button"),b=p("Ban Event"),x=y(),k=h("div"),D.c(),S=y(),A=h("div"),C=h("h3"),C.textContent="Allowed Events",T=y(),_=h("div"),$=h("input"),I=y(),O=h("input"),R=y(),P=h("button"),L=p("Allow Event"),B=y(),N=h("div"),q.c(),w(o,"class","svelte-1smaj3x"),w(a,"type","text"),w(a,"placeholder","Event ID (64 hex chars)"),w(a,"class","svelte-1smaj3x"),w(f,"type","text"),w(f,"placeholder","Reason (optional)"),w(f,"class","svelte-1smaj3x"),v.disabled=e[2],w(v,"class","svelte-1smaj3x"),w(s,"class","add-form svelte-1smaj3x"),w(k,"class","list svelte-1smaj3x"),w(n,"class","section svelte-1smaj3x"),w(C,"class","svelte-1smaj3x"),w($,"type","text"),w($,"placeholder","Event ID (64 hex chars)"),w($,"class","svelte-1smaj3x"),w(O,"type","text"),w(O,"placeholder","Reason (optional)"),w(O,"class","svelte-1smaj3x"),P.disabled=e[2],w(P,"class","svelte-1smaj3x"),w(_,"class","add-form svelte-1smaj3x"),w(N,"class","list svelte-1smaj3x"),w(A,"class","section svelte-1smaj3x"),w(t,"class","events-section")},m(r,d){u(r,t,d),l(t,n),l(n,o),l(n,i),l(n,s),l(s,a),E(a,e[12]),l(s,c),l(s,f),E(f,e[13]),l(s,g),l(s,v),l(v,b),l(n,x),l(n,k),D.m(k,null),l(t,S),l(t,A),l(A,C),l(A,T),l(A,_),l(_,$),E($,e[14]),l(_,I),l(_,O),E(O,e[15]),l(_,R),l(_,P),l(P,L),l(A,B),l(A,N),q.m(N,null),U||(j=[m(a,"input",e[47]),m(f,"input",e[48]),m(v,"click",e[27]),m($,"input",e[49]),m(O,"input",e[50]),m(P,"click",e[28])],U=!0)},p(e,t){4096&t[0]&&a.value!==e[12]&&E(a,e[12]),8192&t[0]&&f.value!==e[13]&&E(f,e[13]),4&t[0]&&(v.disabled=e[2]),F===(F=M(e))&&D?D.p(e,t):(D.d(1),D=F(e),D&&(D.c(),D.m(k,null))),16384&t[0]&&$.value!==e[14]&&E($,e[14]),32768&t[0]&&O.value!==e[15]&&E(O,e[15]),4&t[0]&&(P.disabled=e[2]),q.p(e,t)},d(e){e&&d(t),D.d(),q.d(),U=!1,r(j)}}}function Mh(t){let n;return{c(){n=h("div"),n.innerHTML="<p>No banned events configured.</p>",w(n,"class","no-items svelte-1smaj3x")},m(e,t){u(e,n,t)},p:e,d(e){e&&d(n)}}}function Fh(e){let t,n=e[11],r=[];for(let t=0;t<n.length;t+=1)r[t]=Hh(Ah(e,n,t));return{c(){for(let e=0;e<r.length;e+=1)r[e].c();t=g()},m(e,n){for(let t=0;t<r.length;t+=1)r[t]&&r[t].m(e,n);u(e,t,n)},p(e,o){if(2048&o[0]){let i;for(n=e[11],i=0;i<n.length;i+=1){const s=Ah(e,n,i);r[i]?r[i].p(s,o):(r[i]=Hh(s),r[i].c(),r[i].m(t.parentNode,t))}for(;i<r.length;i+=1)r[i].d(1);r.length=n.length}},d(e){f(r,e),e&&d(t)}}}function Dh(e){let t,n,r=e[72].reason+"";return{c(){t=h("span"),n=p(r),w(t,"class","reason svelte-1smaj3x")},m(e,r){u(e,t,r),l(t,n)},p(e,t){2048&t[0]&&r!==(r=e[72].reason+"")&&x(n,r)},d(e){e&&d(t)}}}function Hh(e){let t,n,r,o,i,s=e[72].id+"",a=e[72].reason&&Dh(e);return{c(){t=h("div"),n=h("span"),r=p(s),o=y(),a&&a.c(),i=y(),w(n,"class","event-id svelte-1smaj3x"),w(t,"class","list-item svelte-1smaj3x")},m(e,s){u(e,t,s),l(t,n),l(n,r),l(t,o),a&&a.m(t,null),l(t,i)},p(e,n){2048&n[0]&&s!==(s=e[72].id+"")&&x(r,s),e[72].reason?a?a.p(e,n):(a=Dh(e),a.c(),a.m(t,i)):a&&(a.d(1),a=null)},d(e){e&&d(t),a&&a.d()}}}function qh(t){let n;return{c(){n=h("div"),n.innerHTML="<p>No allowed events configured.</p>",w(n,"class","no-items svelte-1smaj3x")},m(e,t){u(e,n,t)},p:e,d(e){e&&d(n)}}}function zh(e){let t,n=e[22],r=[];for(let t=0;t<n.length;t+=1)r[t]=Wh(Sh(e,n,t));return{c(){for(let e=0;e<r.length;e+=1)r[e].c();t=g()},m(e,n){for(let t=0;t<r.length;t+=1)r[t]&&r[t].m(e,n);u(e,t,n)},p(e,o){if(4194304&o[0]){let i;for(n=e[22],i=0;i<n.length;i+=1){const s=Sh(e,n,i);r[i]?r[i].p(s,o):(r[i]=Wh(s),r[i].c(),r[i].m(t.parentNode,t))}for(;i<r.length;i+=1)r[i].d(1);r.length=n.length}},d(e){f(r,e),e&&d(t)}}}function Wh(t){let n,r,o,i,s,a=t[72].id+"",c=t[72].reason&&function(t){let n,r,o=t[72].reason+"";return{c(){n=h("span"),r=p(o),w(n,"class","reason svelte-1smaj3x")},m(e,t){u(e,n,t),l(n,r)},p:e,d(e){e&&d(n)}}}(t);return{c(){n=h("div"),r=h("span"),o=p(a),i=y(),c&&c.c(),s=y(),w(r,"class","event-id svelte-1smaj3x"),w(n,"class","list-item svelte-1smaj3x")},m(e,t){u(e,n,t),l(n,r),l(r,o),l(n,i),c&&c.m(n,null),l(n,s)},p(e,t){e[72].reason&&c.p(e,t)},d(e){e&&d(n),c&&c.d()}}}function Kh(e){let t,n,o,i,s,a,c,f,g,v,b,x,k,S,A;function C(e,t){return e[16]&&e[16].length>0?Vh:Jh}let T=C(e),_=T(e);return{c(){t=h("div"),n=h("div"),o=h("h3"),o.textContent="Blocked IPs",i=y(),s=h("div"),a=h("input"),c=y(),f=h("input"),g=y(),v=h("button"),b=p("Block IP"),x=y(),k=h("div"),_.c(),w(o,"class","svelte-1smaj3x"),w(a,"type","text"),w(a,"placeholder","IP Address"),w(a,"class","svelte-1smaj3x"),w(f,"type","text"),w(f,"placeholder","Reason (optional)"),w(f,"class","svelte-1smaj3x"),v.disabled=e[2],w(v,"class","svelte-1smaj3x"),w(s,"class","add-form svelte-1smaj3x"),w(k,"class","list svelte-1smaj3x"),w(n,"class","section svelte-1smaj3x"),w(t,"class","ips-section")},m(r,d){u(r,t,d),l(t,n),l(n,o),l(n,i),l(n,s),l(s,a),E(a,e[17]),l(s,c),l(s,f),E(f,e[18]),l(s,g),l(s,v),l(v,b),l(n,x),l(n,k),_.m(k,null),S||(A=[m(a,"input",e[51]),m(f,"input",e[52]),m(v,"click",e[29])],S=!0)},p(e,t){131072&t[0]&&a.value!==e[17]&&E(a,e[17]),262144&t[0]&&f.value!==e[18]&&E(f,e[18]),4&t[0]&&(v.disabled=e[2]),T===(T=C(e))&&_?_.p(e,t):(_.d(1),_=T(e),_&&(_.c(),_.m(k,null)))},d(e){e&&d(t),_.d(),S=!1,r(A)}}}function Jh(t){let n;return{c(){n=h("div"),n.innerHTML="<p>No blocked IPs configured.</p>",w(n,"class","no-items svelte-1smaj3x")},m(e,t){u(e,n,t)},p:e,d(e){e&&d(n)}}}function Vh(e){let t,n=e[16],r=[];for(let t=0;t<n.length;t+=1)r[t]=Zh(kh(e,n,t));return{c(){for(let e=0;e<r.length;e+=1)r[e].c();t=g()},m(e,n){for(let t=0;t<r.length;t+=1)r[t]&&r[t].m(e,n);u(e,t,n)},p(e,o){if(65536&o[0]){let i;for(n=e[16],i=0;i<n.length;i+=1){const s=kh(e,n,i);r[i]?r[i].p(s,o):(r[i]=Zh(s),r[i].c(),r[i].m(t.parentNode,t))}for(;i<r.length;i+=1)r[i].d(1);r.length=n.length}},d(e){f(r,e),e&&d(t)}}}function Gh(e){let t,n,r=e[72].reason+"";return{c(){t=h("span"),n=p(r),w(t,"class","reason svelte-1smaj3x")},m(e,r){u(e,t,r),l(t,n)},p(e,t){65536&t[0]&&r!==(r=e[72].reason+"")&&x(n,r)},d(e){e&&d(t)}}}function Zh(e){let t,n,r,o,i,s=e[72].ip+"",a=e[72].reason&&Gh(e);return{c(){t=h("div"),n=h("span"),r=p(s),o=y(),a&&a.c(),i=y(),w(n,"class","ip svelte-1smaj3x"),w(t,"class","list-item svelte-1smaj3x")},m(e,s){u(e,t,s),l(t,n),l(n,r),l(t,o),a&&a.m(t,null),l(t,i)},p(e,n){65536&n[0]&&s!==(s=e[72].ip+"")&&x(r,s),e[72].reason?a?a.p(e,n):(a=Gh(e),a.c(),a.m(t,i)):a&&(a.d(1),a=null)},d(e){e&&d(t),a&&a.d()}}}function Yh(e){let t,n,o,i,s,a,c,f,g,v,x,k,S;function A(e,t){return e[19]&&e[19].length>0?Xh:Qh}let C=A(e),T=C(e);return{c(){t=h("div"),n=h("div"),o=h("h3"),o.textContent="Allowed Event Kinds",i=y(),s=h("div"),a=h("input"),c=y(),f=h("button"),g=p("Allow Kind"),v=y(),x=h("div"),T.c(),w(o,"class","svelte-1smaj3x"),w(a,"type","number"),w(a,"placeholder","Kind number"),w(a,"class","svelte-1smaj3x"),f.disabled=e[2],w(f,"class","svelte-1smaj3x"),w(s,"class","add-form svelte-1smaj3x"),w(x,"class","list svelte-1smaj3x"),w(n,"class","section svelte-1smaj3x"),w(t,"class","kinds-section")},m(r,d){u(r,t,d),l(t,n),l(n,o),l(n,i),l(n,s),l(s,a),E(a,e[20]),l(s,c),l(s,f),l(f,g),l(n,v),l(n,x),T.m(x,null),k||(S=[m(a,"input",e[53]),m(f,"click",e[30])],k=!0)},p(e,t){1048576&t[0]&&b(a.value)!==e[20]&&E(a,e[20]),4&t[0]&&(f.disabled=e[2]),C===(C=A(e))&&T?T.p(e,t):(T.d(1),T=C(e),T&&(T.c(),T.m(x,null)))},d(e){e&&d(t),T.d(),k=!1,r(S)}}}function Qh(t){let n;return{c(){n=h("div"),n.innerHTML="<p>No allowed kinds configured. All kinds are\n allowed by default.</p>",w(n,"class","no-items svelte-1smaj3x")},m(e,t){u(e,n,t)},p:e,d(e){e&&d(n)}}}function Xh(e){let t,n=e[19],r=[];for(let t=0;t<n.length;t+=1)r[t]=ep(Eh(e,n,t));return{c(){for(let e=0;e<r.length;e+=1)r[e].c();t=g()},m(e,n){for(let t=0;t<r.length;t+=1)r[t]&&r[t].m(e,n);u(e,t,n)},p(e,o){if(524288&o[0]|1&o[1]){let i;for(n=e[19],i=0;i<n.length;i+=1){const s=Eh(e,n,i);r[i]?r[i].p(s,o):(r[i]=ep(s),r[i].c(),r[i].m(t.parentNode,t))}for(;i<r.length;i+=1)r[i].d(1);r.length=n.length}},d(e){f(r,e),e&&d(t)}}}function ep(e){let t,n,r,o,i,s,a,c,f,g=e[75]+"";function v(){return e[54](e[75])}return{c(){t=h("div"),n=h("span"),r=p("Kind "),o=p(g),i=y(),s=h("button"),s.textContent="Remove",a=y(),w(n,"class","kind svelte-1smaj3x"),w(s,"class","remove-btn svelte-1smaj3x"),w(t,"class","list-item svelte-1smaj3x")},m(e,d){u(e,t,d),l(t,n),l(n,r),l(n,o),l(t,i),l(t,s),l(t,a),c||(f=m(s,"click",v),c=!0)},p(t,n){e=t,524288&n[0]&&g!==(g=e[75]+"")&&x(o,g)},d(e){e&&d(t),c=!1,f()}}}function tp(e){let t,n,r,o,i,s,a,c,f,g;function v(e,t){return e[21]&&e[21].length>0?rp:np}let b=v(e),x=b(e);return{c(){t=h("div"),n=h("div"),r=h("h3"),r.textContent="Events Needing Moderation",o=y(),i=h("button"),s=p("Refresh"),a=y(),c=h("div"),x.c(),w(r,"class","svelte-1smaj3x"),i.disabled=e[2],w(c,"class","list svelte-1smaj3x"),w(n,"class","section svelte-1smaj3x"),w(t,"class","moderation-section")},m(d,h){u(d,t,h),l(t,n),l(n,r),l(n,o),l(n,i),l(i,s),l(n,a),l(n,c),x.m(c,null),f||(g=m(i,"click",e[24]),f=!0)},p(e,t){4&t[0]&&(i.disabled=e[2]),b===(b=v(e))&&x?x.p(e,t):(x.d(1),x=b(e),x&&(x.c(),x.m(c,null)))},d(e){e&&d(t),x.d(),f=!1,g()}}}function np(t){let n;return{c(){n=h("div"),n.innerHTML="<p>No events need moderation at this time.</p>",w(n,"class","no-items svelte-1smaj3x")},m(e,t){u(e,n,t)},p:e,d(e){e&&d(n)}}}function rp(e){let t,n=e[21],r=[];for(let t=0;t<n.length;t+=1)r[t]=ip(xh(e,n,t));return{c(){for(let e=0;e<r.length;e+=1)r[e].c();t=g()},m(e,n){for(let t=0;t<r.length;t+=1)r[t]&&r[t].m(e,n);u(e,t,n)},p(e,o){if(2097152&o[0]|12&o[1]){let i;for(n=e[21],i=0;i<n.length;i+=1){const s=xh(e,n,i);r[i]?r[i].p(s,o):(r[i]=ip(s),r[i].c(),r[i].m(t.parentNode,t))}for(;i<r.length;i+=1)r[i].d(1);r.length=n.length}},d(e){f(r,e),e&&d(t)}}}function op(e){let t,n,r=e[72].reason+"";return{c(){t=h("span"),n=p(r),w(t,"class","reason svelte-1smaj3x")},m(e,r){u(e,t,r),l(t,n)},p(e,t){2097152&t[0]&&r!==(r=e[72].reason+"")&&x(n,r)},d(e){e&&d(t)}}}function ip(e){let t,n,o,i,s,a,c,f,g,v,b,E,k=e[72].id+"",S=e[72].reason&&op(e);function A(){return e[55](e[72])}function C(){return e[56](e[72])}return{c(){t=h("div"),n=h("span"),o=p(k),i=y(),S&&S.c(),s=y(),a=h("div"),c=h("button"),c.textContent="Allow",f=y(),g=h("button"),g.textContent="Ban",v=y(),w(n,"class","event-id svelte-1smaj3x"),w(c,"class","svelte-1smaj3x"),w(g,"class","svelte-1smaj3x"),w(a,"class","actions svelte-1smaj3x"),w(t,"class","list-item svelte-1smaj3x")},m(e,r){u(e,t,r),l(t,n),l(n,o),l(t,i),S&&S.m(t,null),l(t,s),l(t,a),l(a,c),l(a,f),l(a,g),l(t,v),b||(E=[m(c,"click",A),m(g,"click",C)],b=!0)},p(n,r){e=n,2097152&r[0]&&k!==(k=e[72].id+"")&&x(o,k),e[72].reason?S?S.p(e,r):(S=op(e),S.c(),S.m(t,s)):S&&(S.d(1),S=null)},d(e){e&&d(t),S&&S.d(),b=!1,r(E)}}}function sp(e){let t,n,o,i,s,a,c,f,g,v,b,x,k,S,A,C,T,_,$,I,O,R,P,L,B,N,U,j;function M(e,t){return e[2]?cp:ap}let F=M(e),D=F(e);return{c(){t=h("div"),n=h("div"),o=h("h3"),o.textContent="Relay Configuration",i=y(),s=h("div"),a=h("button"),c=p("🔄 Refresh from Relay Info"),f=y(),g=h("div"),v=h("div"),b=h("label"),b.textContent="Relay Name",x=y(),k=h("input"),S=y(),A=h("div"),C=h("label"),C.textContent="Relay Description",T=y(),_=h("textarea"),$=y(),I=h("div"),O=h("label"),O.textContent="Relay Icon URL",R=y(),P=h("input"),L=y(),B=h("div"),N=h("button"),D.c(),w(o,"class","svelte-1smaj3x"),a.disabled=e[2],w(a,"class","refresh-btn svelte-1smaj3x"),w(s,"class","config-actions svelte-1smaj3x"),w(b,"class","svelte-1smaj3x"),w(k,"type","text"),w(k,"placeholder","Enter relay name"),w(k,"class","svelte-1smaj3x"),w(v,"class","form-group svelte-1smaj3x"),w(C,"class","svelte-1smaj3x"),w(_,"placeholder","Enter relay description"),w(_,"class","svelte-1smaj3x"),w(A,"class","form-group svelte-1smaj3x"),w(O,"class","svelte-1smaj3x"),w(P,"type","url"),w(P,"placeholder","Enter icon URL"),w(P,"class","svelte-1smaj3x"),w(I,"class","form-group svelte-1smaj3x"),N.disabled=e[2],w(N,"class","update-all-btn svelte-1smaj3x"),w(B,"class","config-update-section svelte-1smaj3x"),w(g,"class","config-form svelte-1smaj3x"),w(n,"class","section svelte-1smaj3x"),w(t,"class","relay-section")},m(r,d){u(r,t,d),l(t,n),l(n,o),l(n,i),l(n,s),l(s,a),l(a,c),l(n,f),l(n,g),l(g,v),l(v,b),l(v,x),l(v,k),E(k,e[0].relay_name),l(g,S),l(g,A),l(A,C),l(A,T),l(A,_),E(_,e[0].relay_description),l(g,$),l(g,I),l(I,O),l(I,R),l(I,P),E(P,e[0].relay_icon),l(g,L),l(g,B),l(B,N),D.m(N,null),U||(j=[m(a,"click",e[23]),m(k,"input",e[57]),m(_,"input",e[58]),m(P,"input",e[59]),m(N,"click",e[32])],U=!0)},p(e,t){4&t[0]&&(a.disabled=e[2]),1&t[0]&&k.value!==e[0].relay_name&&E(k,e[0].relay_name),1&t[0]&&E(_,e[0].relay_description),1&t[0]&&P.value!==e[0].relay_icon&&E(P,e[0].relay_icon),F!==(F=M(e))&&(D.d(1),D=F(e),D&&(D.c(),D.m(N,null))),4&t[0]&&(N.disabled=e[2])},d(e){e&&d(t),D.d(),U=!1,r(j)}}}function ap(e){let t;return{c(){t=p("💾 Update Configuration")},m(e,n){u(e,t,n)},d(e){e&&d(t)}}}function cp(e){let t;return{c(){t=p("⏳ Updating...")},m(e,n){u(e,t,n)},d(e){e&&d(t)}}}function lp(t){let n,o,i,s,a,c,f,g,v,b,x,E,k,S,A,C,T,_,$,I,O,R,P,L,B,N,U,j,M,F,D,H,q,z,W,K,J,V=t[3]&&_h(t),G="pubkeys"===t[1]&&$h(t),Z="events"===t[1]&&jh(t),Y="ips"===t[1]&&Kh(t),Q="kinds"===t[1]&&Yh(t),X="moderation"===t[1]&&tp(t),ee="relay"===t[1]&&sp(t);return{c(){n=h("div"),o=h("div"),o.innerHTML='<h2 class="svelte-1smaj3x">Managed ACL Configuration</h2> \n <p class="svelte-1smaj3x">Configure access control using NIP-86 management API</p> \n <div class="owner-only-notice svelte-1smaj3x"><strong>Owner Only:</strong> This interface is restricted to relay owners\n only.</div>',i=y(),V&&V.c(),s=y(),a=h("div"),c=h("button"),f=p("Pubkeys"),v=y(),b=h("button"),x=p("Events"),k=y(),S=h("button"),A=p("IPs"),T=y(),_=h("button"),$=p("Kinds"),O=y(),R=h("button"),P=p("Moderation"),B=y(),N=h("button"),U=p("Relay Config"),M=y(),F=h("div"),G&&G.c(),D=y(),Z&&Z.c(),H=y(),Y&&Y.c(),q=y(),Q&&Q.c(),z=y(),X&&X.c(),W=y(),ee&&ee.c(),w(o,"class","header svelte-1smaj3x"),w(c,"class",g="tab "+("pubkeys"===t[1]?"active":"")+" svelte-1smaj3x"),w(b,"class",E="tab "+("events"===t[1]?"active":"")+" svelte-1smaj3x"),w(S,"class",C="tab "+("ips"===t[1]?"active":"")+" svelte-1smaj3x"),w(_,"class",I="tab "+("kinds"===t[1]?"active":"")+" svelte-1smaj3x"),w(R,"class",L="tab "+("moderation"===t[1]?"active":"")+" svelte-1smaj3x"),w(N,"class",j="tab "+("relay"===t[1]?"active":"")+" svelte-1smaj3x"),w(a,"class","tabs svelte-1smaj3x"),w(F,"class","tab-content svelte-1smaj3x")},m(e,r){u(e,n,r),l(n,o),l(n,i),V&&V.m(n,null),l(n,s),l(n,a),l(a,c),l(c,f),l(a,v),l(a,b),l(b,x),l(a,k),l(a,S),l(S,A),l(a,T),l(a,_),l(_,$),l(a,O),l(a,R),l(R,P),l(a,B),l(a,N),l(N,U),l(n,M),l(n,F),G&&G.m(F,null),l(F,D),Z&&Z.m(F,null),l(F,H),Y&&Y.m(F,null),l(F,q),Q&&Q.m(F,null),l(F,z),X&&X.m(F,null),l(F,W),ee&&ee.m(F,null),K||(J=[m(c,"click",t[37]),m(b,"click",t[38]),m(S,"click",t[39]),m(_,"click",t[40]),m(R,"click",t[41]),m(N,"click",t[42])],K=!0)},p(e,t){e[3]?V?V.p(e,t):(V=_h(e),V.c(),V.m(n,s)):V&&(V.d(1),V=null),2&t[0]&&g!==(g="tab "+("pubkeys"===e[1]?"active":"")+" svelte-1smaj3x")&&w(c,"class",g),2&t[0]&&E!==(E="tab "+("events"===e[1]?"active":"")+" svelte-1smaj3x")&&w(b,"class",E),2&t[0]&&C!==(C="tab "+("ips"===e[1]?"active":"")+" svelte-1smaj3x")&&w(S,"class",C),2&t[0]&&I!==(I="tab "+("kinds"===e[1]?"active":"")+" svelte-1smaj3x")&&w(_,"class",I),2&t[0]&&L!==(L="tab "+("moderation"===e[1]?"active":"")+" svelte-1smaj3x")&&w(R,"class",L),2&t[0]&&j!==(j="tab "+("relay"===e[1]?"active":"")+" svelte-1smaj3x")&&w(N,"class",j),"pubkeys"===e[1]?G?G.p(e,t):(G=$h(e),G.c(),G.m(F,D)):G&&(G.d(1),G=null),"events"===e[1]?Z?Z.p(e,t):(Z=jh(e),Z.c(),Z.m(F,H)):Z&&(Z.d(1),Z=null),"ips"===e[1]?Y?Y.p(e,t):(Y=Kh(e),Y.c(),Y.m(F,q)):Y&&(Y.d(1),Y=null),"kinds"===e[1]?Q?Q.p(e,t):(Q=Yh(e),Q.c(),Q.m(F,z)):Q&&(Q.d(1),Q=null),"moderation"===e[1]?X?X.p(e,t):(X=tp(e),X.c(),X.m(F,W)):X&&(X.d(1),X=null),"relay"===e[1]?ee?ee.p(e,t):(ee=sp(e),ee.c(),ee.m(F,null)):ee&&(ee.d(1),ee=null)},i:e,o:e,d(e){e&&d(n),V&&V.d(),G&&G.d(),Z&&Z.d(),Y&&Y.d(),Q&&Q.d(),X&&X.d(),ee&&ee.d(),K=!1,r(J)}}}function up(e,t,n){let{userSigner:r}=t,{userPubkey:o}=t,i="pubkeys",s=!1,a="",c="info",l=[],u="",d="",f=[],h="",p="",y=[],g="",m="",v="",w="",x=[],E="",k="",S=[],A="",C=[],_={relay_name:"",relay_description:"",relay_icon:""};var $;async function I(){try{n(2,s=!0),console.log("Fetching relay info from /");const e=await fetch(window.location.origin+"/",{headers:{Accept:"application/nostr+json"}});if(console.log("Response status:",e.status),console.log("Response headers:",e.headers),e.ok){const t=await e.json();console.log("Raw relay info:",t),n(0,_={relay_name:t.name||"",relay_description:t.description||"",relay_icon:t.icon||""}),console.log("Updated relayConfig:",_),console.log("Loaded relay info:",t),n(3,a="Relay configuration loaded successfully"),n(4,c="success")}else console.error("Failed to fetch relay info, status:",e.status),n(3,a=`Failed to fetch relay info: ${e.status}`),n(4,c="error")}catch(e){console.error("Failed to fetch relay info:",e),n(3,a=`Failed to fetch relay info: ${e.message}`),n(4,c="error")}finally{n(2,s=!1)}}async function O(e,t=[]){try{n(2,s=!0),n(3,a="");const i={method:e,params:t},c=await async function(e,t){if(!r)throw new Error("No signer available for authentication. Please log in with a Nostr extension.");if(!o)throw new Error("No user pubkey available for authentication.");const n=window.location.origin+t,i={kind:27235,created_at:Math.floor(Date.now()/1e3),tags:[["u",n],["method",e]],content:"",pubkey:o},s=await r.signEvent(i),a=JSON.stringify(s);return`Nostr ${btoa(a)}`}("POST","/api/nip86"),l=await fetch("/api/nip86",{method:"POST",headers:{"Content-Type":"application/nostr+json+rpc",Authorization:c},body:JSON.stringify(i)});if(!l.ok)throw new Error(`HTTP ${l.status}: ${l.statusText}`);const u=await l.json();if(u.error)throw new Error(u.error);return u.result}catch(e){throw console.error("NIP-86 API error:",e),n(3,a=e.message),n(4,c="error"),e}finally{n(2,s=!1)}}async function R(){try{n(5,l=await O("listbannedpubkeys"))}catch(e){console.error("Failed to load banned pubkeys:",e)}}async function P(){try{n(8,f=await O("listallowedpubkeys"))}catch(e){console.error("Failed to load allowed pubkeys:",e)}}async function L(){try{n(11,y=await O("listbannedevents"))}catch(e){console.error("Failed to load banned events:",e)}}async function B(){try{n(16,x=await O("listblockedips"))}catch(e){console.error("Failed to load blocked IPs:",e)}}async function N(){try{n(19,S=await O("listallowedkinds"))}catch(e){console.error("Failed to load allowed kinds:",e)}}async function U(){try{n(2,s=!0),n(21,C=await O("listeventsneedingmoderation")),console.log("Loaded events needing moderation:",C)}catch(e){console.error("Failed to load events needing moderation:",e),n(3,a=`Failed to load moderation events: ${e.message}`),n(4,c="error"),n(21,C=[])}finally{n(2,s=!1)}}async function j(e){try{await O("disallowkind",[e]),n(3,a="Kind disallowed successfully"),n(4,c="success"),await N()}catch(e){console.error("Failed to disallow kind:",e)}}async function M(e){try{await O("allowevent",[e,"Approved from moderation queue"]),n(3,a="Event allowed successfully"),n(4,c="success"),await U()}catch(e){console.error("Failed to allow event from moderation:",e)}}async function F(e){try{await O("banevent",[e,"Banned from moderation queue"]),n(3,a="Event banned successfully"),n(4,c="success"),await U()}catch(e){console.error("Failed to ban event from moderation:",e)}}$=()=>{setTimeout(()=>{I()},100)},T().$$.on_mount.push($),async function(){await Promise.all([R(),P(),L(),B(),N()])}();return e.$$set=e=>{"userSigner"in e&&n(35,r=e.userSigner),"userPubkey"in e&&n(36,o=e.userPubkey)},e.$$.update=()=>{1&e.$$.dirty[0]&&console.log("relayConfig changed:",_)},[_,i,s,a,c,l,u,d,f,h,p,y,g,m,v,w,x,E,k,S,A,C,[],I,U,async function(){if(u)try{await O("banpubkey",[u,d]),n(3,a="Pubkey banned successfully"),n(4,c="success"),n(6,u=""),n(7,d=""),await R()}catch(e){console.error("Failed to ban pubkey:",e)}},async function(){if(h)try{await O("allowpubkey",[h,p]),n(3,a="Pubkey allowed successfully"),n(4,c="success"),n(9,h=""),n(10,p=""),await P()}catch(e){console.error("Failed to allow pubkey:",e)}},async function(){if(g)try{await O("banevent",[g,m]),n(3,a="Event banned successfully"),n(4,c="success"),n(12,g=""),n(13,m=""),await L()}catch(e){console.error("Failed to ban event:",e)}},async function(){if(v)try{await O("allowevent",[v,w]),n(3,a="Event allowed successfully"),n(4,c="success"),n(14,v=""),n(15,w="")}catch(e){console.error("Failed to allow event:",e)}},async function(){if(E)try{await O("blockip",[E,k]),n(3,a="IP blocked successfully"),n(4,c="success"),n(17,E=""),n(18,k=""),await B()}catch(e){console.error("Failed to block IP:",e)}},async function(){if(!A)return;const e=parseInt(A);if(isNaN(e))return n(3,a="Invalid kind number"),void n(4,c="error");try{await O("allowkind",[e]),n(3,a="Kind allowed successfully"),n(4,c="success"),n(20,A=""),await N()}catch(e){console.error("Failed to allow kind:",e)}},j,async function(){try{n(2,s=!0),n(3,a="");const e=[];if(_.relay_name&&e.push(O("changerelayname",[_.relay_name])),_.relay_description&&e.push(O("changerelaydescription",[_.relay_description])),_.relay_icon&&e.push(O("changerelayicon",[_.relay_icon])),0===e.length)return n(3,a="No changes to update"),void n(4,c="info");await Promise.all(e),n(3,a="Relay configuration updated successfully"),n(4,c="success"),await I()}catch(e){console.error("Failed to update relay configuration:",e),n(3,a=`Failed to update relay configuration: ${e.message}`),n(4,c="error")}finally{n(2,s=!1)}},M,F,r,o,()=>n(1,i="pubkeys"),()=>n(1,i="events"),()=>n(1,i="ips"),()=>n(1,i="kinds"),()=>{n(1,i="moderation"),C&&0!==C.length||U()},()=>n(1,i="relay"),function(){u=this.value,n(6,u)},function(){d=this.value,n(7,d)},function(){h=this.value,n(9,h)},function(){p=this.value,n(10,p)},function(){g=this.value,n(12,g)},function(){m=this.value,n(13,m)},function(){v=this.value,n(14,v)},function(){w=this.value,n(15,w)},function(){E=this.value,n(17,E)},function(){k=this.value,n(18,k)},function(){A=b(this.value),n(20,A)},e=>j(e),e=>M(e.id),e=>F(e.id),function(){_.relay_name=this.value,n(0,_)},function(){_.relay_description=this.value,n(0,_)},function(){_.relay_icon=this.value,n(0,_)}]}class dp extends Q{constructor(e){super(),Y(this,e,up,lp,i,{userSigner:35,userPubkey:36},null,[-1,-1,-1])}}class fp{constructor(e,t,n){this.relayUrl=e,this.userSigner=t,this.userPubkey=n,this.ws=null,this.challenge=null,this.isAuthenticated=!1,this.authPromise=null}async connect(){return new Promise((e,t)=>{this.ws=new WebSocket(this.relayUrl),this.ws.onopen=()=>{console.log("WebSocket connected to relay:",this.relayUrl),e()},this.ws.onmessage=async e=>{try{const t=JSON.parse(e.data);await this.handleMessage(t)}catch(e){console.error("Error parsing relay message:",e)}},this.ws.onerror=e=>{console.error("WebSocket error:",e),t(new Error("Failed to connect to relay"))},this.ws.onclose=()=>{console.log("WebSocket connection closed"),this.isAuthenticated=!1,this.challenge=null},setTimeout(()=>{this.ws.readyState!==WebSocket.OPEN&&t(new Error("Connection timeout"))},1e4)})}async handleMessage(e){const[t,...n]=e;switch(t){case"AUTH":this.challenge=n[0],console.log("Received AUTH challenge:",this.challenge),await this.authenticate();break;case"OK":const[e,r,o]=n;e&&r?(console.log("Authentication successful for event:",e),this.isAuthenticated=!0,this.authPromise&&(this.authPromise.resolve(),this.authPromise=null)):e&&!r&&(console.error("Authentication failed:",o),this.authPromise&&(this.authPromise.reject(new Error(o||"Authentication failed")),this.authPromise=null));break;case"NOTICE":console.log("Relay notice:",n[0]);break;default:console.log("Unhandled message type:",t,n)}}async authenticate(){if(!this.challenge)throw new Error("No challenge received from relay");if(!this.userSigner)throw new Error("No signer available for authentication");try{const e={kind:22242,created_at:Math.floor(Date.now()/1e3),tags:[["relay",this.relayUrl],["challenge",this.challenge]],content:"",pubkey:this.userPubkey},t=["AUTH",await this.userSigner.signEvent(e)];return this.ws.send(JSON.stringify(t)),console.log("Sent authentication event to relay"),new Promise((e,t)=>{this.authPromise={resolve:e,reject:t},setTimeout(()=>{this.authPromise&&(this.authPromise.reject(new Error("Authentication timeout")),this.authPromise=null)},1e4)})}catch(e){throw console.error("Authentication error:",e),e}}async publishEvent(e){if(!this.ws||this.ws.readyState!==WebSocket.OPEN)throw new Error("WebSocket not connected");return new Promise((t,n)=>{const r=["EVENT",e];this.ws.send(JSON.stringify(r));const o=this.ws.onmessage,i=setTimeout(()=>{this.ws.onmessage=o,n(new Error("Publish timeout"))},15e3);this.ws.onmessage=async r=>{try{const s=JSON.parse(r.data),[a,c,l,u]=s;if("OK"===a&&c===e.id)if(clearTimeout(i),this.ws.onmessage=o,l)console.log("Event published successfully:",c),t({success:!0,eventId:c,reason:u});else{if(console.error("Event publish failed:",u),u&&u.includes("auth-required")){console.log("Authentication required, attempting to authenticate...");try{await this.authenticate();const t=["EVENT",e];return void this.ws.send(JSON.stringify(t))}catch(e){return void n(new Error(`Authentication failed: ${e.message}`))}}n(new Error(`Publish failed: ${u}`))}else await this.handleMessage(s)}catch(e){clearTimeout(i),this.ws.onmessage=o,n(e)}}})}close(){this.ws&&(this.ws.close(),this.ws=null),this.isAuthenticated=!1,this.challenge=null}getAuthenticated(){return this.isAuthenticated}}async function hp(e,t,n,r){const o=new fp(e,n,r);try{await o.connect();return await o.publishEvent(t)}finally{o.close()}}function pp(e,t,n){const r=e.slice();return r[165]=t[n],r}function yp(e,t,n){const r=e.slice();return r[145]=t[n],r}function gp(e,t,n){const r=e.slice();r[145]=t[n];const o=r[45](r[145]);return r[154]=o,r}function mp(e,t,n){const r=e.slice();return r[157]=t[n],r}function vp(e,t,n){const r=e.slice();return r[157]=t[n],r}function wp(e,t,n){const r=e.slice();return r[162]=t[n],r}function bp(e,t,n){const r=e.slice();return r[151]=t[n],r}function xp(e,t,n){const r=e.slice();return r[145]=t[n],r}function Ep(e,t,n){const r=e.slice();return r[148]=t[n],r}function kp(e,t,n){const r=e.slice();return r[170]=t[n],r}function Sp(e){let t,n,r,o=e[1]&&e[4]&&Cp(e);return{c(){t=h("div"),n=h("span"),r=p("ORLY? dashboard\n "),o&&o.c(),w(n,"class","app-title svelte-1a66x6i"),w(t,"class","header-title svelte-1a66x6i")},m(e,i){u(e,t,i),l(t,n),l(n,r),o&&o.m(n,null)},p(e,t){e[1]&&e[4]?o?o.p(e,t):(o=Cp(e),o.c(),o.m(n,null)):o&&(o.d(1),o=null)},d(e){e&&d(t),o&&o.d()}}}function Ap(e){let t,n,o,i;return{c(){t=h("div"),n=h("input"),w(n,"type","text"),w(n,"class","search-input svelte-1a66x6i"),w(n,"placeholder","Search..."),w(t,"class","search-input-container svelte-1a66x6i")},m(r,s){u(r,t,s),l(t,n),E(n,e[15]),o||(i=[m(n,"input",e[83]),m(n,"keydown",e[64])],o=!0)},p(e,t){32768&t[0]&&n.value!==e[15]&&E(n,e[15])},d(e){e&&d(t),o=!1,r(i)}}}function Cp(e){let t,n;return{c(){t=h("span"),n=p(e[4]),w(t,"class","permission-badge svelte-1a66x6i")},m(e,r){u(e,t,r),l(t,n)},p(e,t){16&t[0]&&x(n,e[4])},d(e){e&&d(t)}}}function Tp(t){let n,r,o;return{c(){n=h("button"),n.textContent="Log in",w(n,"class","login-btn svelte-1a66x6i")},m(e,i){u(e,n,i),r||(o=m(n,"click",t[57]),r=!0)},p:e,d(e){e&&d(n),r=!1,o()}}}function _p(e){let t,n,r,o,i,s,a,c=(e[3]?.name||e[2].slice(0,8)+"...")+"";function f(e,t){return e[3]?.picture?Ip:$p}let g=f(e),v=g(e);return{c(){t=h("div"),n=h("button"),v.c(),r=y(),o=h("span"),i=p(c),w(o,"class","user-name svelte-1a66x6i"),w(n,"class","user-profile-btn svelte-1a66x6i"),w(t,"class","user-info svelte-1a66x6i")},m(c,d){u(c,t,d),l(t,n),v.m(n,null),l(n,r),l(n,o),l(o,i),s||(a=m(n,"click",e[61]),s=!0)},p(e,t){g===(g=f(e))&&v?v.p(e,t):(v.d(1),v=g(e),v&&(v.c(),v.m(n,r))),12&t[0]&&c!==(c=(e[3]?.name||e[2].slice(0,8)+"...")+"")&&x(i,c)},d(e){e&&d(t),v.d(),s=!1,a()}}}function $p(t){let n;return{c(){n=h("div"),n.textContent="👤",w(n,"class","user-avatar-placeholder svelte-1a66x6i")},m(e,t){u(e,n,t)},p:e,d(e){e&&d(n)}}}function Ip(e){let t,n;return{c(){t=h("img"),a(t.src,n=e[3].picture)||w(t,"src",n),w(t,"alt","User avatar"),w(t,"class","user-avatar svelte-1a66x6i")},m(e,n){u(e,t,n)},p(e,r){8&r[0]&&!a(t.src,n=e[3].picture)&&w(t,"src",n)},d(e){e&&d(t)}}}function Op(e){let t,n,o;function i(){return e[84](e[170])}function s(...t){return e[85](e[170],...t)}return{c(){t=h("span"),t.textContent="✕",w(t,"class","tab-close-icon svelte-1a66x6i"),w(t,"role","button"),w(t,"tabindex","0")},m(e,r){u(e,t,r),n||(o=[m(t,"click",v(i)),m(t,"keydown",s)],n=!0)},p(t,n){e=t},d(e){e&&d(t),n=!1,r(o)}}}function Rp(e){let t,n,r,o,i,s,a,c,f,g,v=e[170].icon+"",b=e[170].label+"",E=e[170].isSearchTab&&Op(e);function k(){return e[86](e[170])}return{c(){t=h("button"),n=h("span"),r=p(v),o=y(),i=h("span"),s=p(b),a=y(),E&&E.c(),c=y(),w(n,"class","tab-icon svelte-1a66x6i"),w(i,"class","tab-label svelte-1a66x6i"),w(t,"class","tab svelte-1a66x6i"),S(t,"active",e[5]===e[170].id)},m(e,d){u(e,t,d),l(t,n),l(n,r),l(t,o),l(t,i),l(i,s),l(t,a),E&&E.m(t,null),l(t,c),f||(g=m(t,"click",k),f=!0)},p(n,o){e=n,1024&o[0]&&v!==(v=e[170].icon+"")&&x(r,v),1024&o[0]&&b!==(b=e[170].label+"")&&x(s,b),e[170].isSearchTab?E?E.p(e,o):(E=Op(e),E.c(),E.m(t,c)):E&&(E.d(1),E=null),1056&o[0]&&S(t,"active",e[5]===e[170].id)},d(e){e&&d(t),E&&E.d(),f=!1,g()}}}function Pp(t){let n;function r(e,t){return e[1]?qp:Hp}let o=r(t),i=o(t);return{c(){n=h("div"),i.c(),w(n,"class","welcome-message svelte-1a66x6i")},m(e,t){u(e,n,t),i.m(n,null)},p(e,t){o===(o=r(e))&&i?i.p(e,t):(i.d(1),i=o(e),i&&(i.c(),i.m(n,null)))},i:e,o:e,d(e){e&&d(n),i.d()}}}function Lp(t){let n,r=t[6],o=[];for(let e=0;e<r.length;e+=1)o[e]=Qp(pp(t,r,e));return{c(){for(let e=0;e<o.length;e+=1)o[e].c();n=g()},m(e,t){for(let n=0;n<o.length;n+=1)o[n]&&o[n].m(e,t);u(e,n,t)},p(e,t){if(131188&t[0]|720&t[1]|48&t[2]){let i;for(r=e[6],i=0;i<r.length;i+=1){const s=pp(e,r,i);o[i]?o[i].p(s,t):(o[i]=Qp(s),o[i].c(),o[i].m(n.parentNode,n))}for(;i<o.length;i+=1)o[i].d(1);o.length=r.length}},i:e,o:e,d(e){f(o,e),e&&d(n)}}}function Bp(t){let n,o,i,s,a,c,p,g,v,x,S,A,C,T,_,$,I,O=t[36],R=[];for(let e=0;e<O.length;e+=1)R[e]=Xp(wp(t,O,e));let P=(t[28]||t[29])&&ey(t);return{c(){n=h("div"),o=h("div"),o.innerHTML='<h2 class="svelte-1a66x6i">🔄 Event Recovery</h2> \n <p class="svelte-1a66x6i">Search and recover old versions of replaceable events</p>',i=y(),s=h("div"),a=h("div"),c=h("label"),c.textContent="Select Event Kind:",p=y(),g=h("select"),v=h("option"),v.textContent="Choose a replaceable kind...";for(let e=0;e<R.length;e+=1)R[e].c();x=y(),S=h("div"),A=h("label"),A.textContent="Or enter custom kind number:",C=y(),T=h("input"),_=y(),P&&P.c(),w(o,"class","recovery-header svelte-1a66x6i"),w(c,"for","recovery-kind"),w(c,"class","svelte-1a66x6i"),v.__value=null,v.value=v.__value,w(g,"id","recovery-kind"),w(g,"class","svelte-1a66x6i"),void 0===t[28]&&N(()=>t[99].call(g)),w(a,"class","kind-selector svelte-1a66x6i"),w(A,"for","custom-kind"),w(A,"class","svelte-1a66x6i"),w(T,"id","custom-kind"),w(T,"type","number"),w(T,"placeholder","e.g., 10001"),w(T,"min","0"),w(T,"class","svelte-1a66x6i"),w(S,"class","custom-kind-input svelte-1a66x6i"),w(s,"class","recovery-controls svelte-1a66x6i"),w(n,"class","recovery-tab svelte-1a66x6i")},m(e,r){u(e,n,r),l(n,o),l(n,i),l(n,s),l(s,a),l(a,c),l(a,p),l(a,g),l(g,v);for(let e=0;e<R.length;e+=1)R[e]&&R[e].m(g,null);k(g,t[28],!0),l(s,x),l(s,S),l(S,A),l(S,C),l(S,T),E(T,t[29]),l(n,_),P&&P.m(n,null),$||(I=[m(g,"change",t[99]),m(g,"change",t[100]),m(T,"input",t[101]),m(T,"input",t[44])],$=!0)},p(e,t){if(32&t[1]){let n;for(O=e[36],n=0;n<O.length;n+=1){const r=wp(e,O,n);R[n]?R[n].p(r,t):(R[n]=Xp(r),R[n].c(),R[n].m(g,null))}for(;n<R.length;n+=1)R[n].d(1);R.length=O.length}268435456&t[0]|32&t[1]&&k(g,e[28]),536870912&t[0]&&b(T.value)!==e[29]&&E(T,e[29]),e[28]||e[29]?P?P.p(e,t):(P=ey(e),P.c(),P.m(n,null)):P&&(P.d(1),P=null)},i:e,o:e,d(e){e&&d(n),f(R,e),P&&P.d(),$=!1,r(I)}}}function Np(t){let n,r,o;function i(e,t){return e[1]&&"owner"===e[4]?yy:e[1]?py:hy}let s=i(t),a=s(t);return{c(){n=h("div"),r=h("h2"),r.textContent="Sprocket Script Management",o=y(),a.c(),w(n,"class","sprocket-view svelte-1a66x6i")},m(e,t){u(e,n,t),l(n,r),l(n,o),a.m(n,null)},p(e,t){s===(s=i(e))&&a?a.p(e,t):(a.d(1),a=s(e),a&&(a.c(),a.m(n,null)))},i:e,o:e,d(e){e&&d(n),a.d()}}}function Up(e){let t,n,r,o;const i=[ky,Ey,xy],s=[];function a(e,t){return"managed"!==e[9]?0:e[1]&&"owner"===e[4]?1:2}return n=a(e),r=s[n]=i[n](e),{c(){t=h("div"),r.c(),w(t,"class","managed-acl-view svelte-1a66x6i")},m(e,r){u(e,t,r),s[n].m(t,null),o=!0},p(e,o){let c=n;n=a(e),n===c?s[n].p(e,o):(q(),K(s[c],1,1,()=>{s[c]=null}),z(),r=s[n],r?r.p(e,o):(r=s[n]=i[n](e),r.c()),W(r,1),r.m(t,null))},i(e){o||(W(r),o=!0)},o(e){K(r),o=!1},d(e){e&&d(t),s[n].d()}}}function jp(t){let n,o,i,s,a,c,f,p,g,v,b,x;return{c(){n=h("div"),o=h("div"),i=h("button"),i.textContent="Reformat",s=y(),a=h("button"),a.textContent="Sign",c=y(),f=h("button"),f.textContent="Publish",p=y(),g=h("div"),v=h("textarea"),w(i,"class","compose-btn reformat-btn svelte-1a66x6i"),w(a,"class","compose-btn sign-btn svelte-1a66x6i"),w(f,"class","compose-btn publish-btn svelte-1a66x6i"),w(o,"class","compose-header svelte-1a66x6i"),w(v,"class","compose-textarea svelte-1a66x6i"),w(v,"placeholder","Enter your Nostr event JSON here..."),w(v,"spellcheck","false"),w(g,"class","compose-editor svelte-1a66x6i"),w(n,"class","compose-view svelte-1a66x6i")},m(e,r){u(e,n,r),l(n,o),l(o,i),l(o,s),l(o,a),l(o,c),l(o,f),l(n,p),l(n,g),l(g,v),E(v,t[27]),b||(x=[m(i,"click",t[75]),m(a,"click",t[76]),m(f,"click",t[77]),m(v,"input",t[95])],b=!0)},p(e,t){134217728&t[0]&&E(v,e[27])},i:e,o:e,d(e){e&&d(n),b=!1,r(x)}}}function Mp(t){let n,r;function o(e,t){return!e[1]||"write"!==e[4]&&"admin"!==e[4]&&"owner"!==e[4]?Sy:Ay}let i=o(t),s=i(t),a=t[1]&&("write"===t[4]||"admin"===t[4]||"owner"===t[4])&&Uy(t);return{c(){n=h("div"),s.c(),r=y(),a&&a.c(),w(n,"class","events-view-container svelte-1a66x6i")},m(e,t){u(e,n,t),s.m(n,null),l(n,r),a&&a.m(n,null)},p(e,t){i===(i=o(e))&&s?s.p(e,t):(s.d(1),s=i(e),s&&(s.c(),s.m(n,r))),!e[1]||"write"!==e[4]&&"admin"!==e[4]&&"owner"!==e[4]?a&&(a.d(1),a=null):a?a.p(e,t):(a=Uy(e),a.c(),a.m(n,null))},i:e,o:e,d(e){e&&d(n),s.d(),a&&a.d()}}}function Fp(t){let n;function r(e,t){return!e[1]||"admin"!==e[4]&&"owner"!==e[4]?e[1]?Dy:Fy:Hy}let o=r(t),i=o(t);return{c(){n=h("div"),i.c(),w(n,"class","import-view svelte-1a66x6i")},m(e,t){u(e,n,t),i.m(n,null)},p(e,t){o===(o=r(e))&&i?i.p(e,t):(i.d(1),i=o(e),i&&(i.c(),i.m(n,null)))},i:e,o:e,d(e){e&&d(n),i.d()}}}function Dp(t){let n;function r(e,t){return e[1]?zy:qy}let o=r(t),i=o(t);return{c(){i.c(),n=g()},m(e,t){i.m(e,t),u(e,n,t)},p(e,t){o===(o=r(e))&&i?i.p(e,t):(i.d(1),i=o(e),i&&(i.c(),i.m(n.parentNode,n)))},i:e,o:e,d(e){i.d(e),e&&d(n)}}}function Hp(t){let n;return{c(){n=h("p"),n.textContent="Log in to access your user dashboard",w(n,"class","svelte-1a66x6i")},m(e,t){u(e,n,t)},p:e,d(e){e&&d(n)}}}function qp(e){let t,n,r,o=(e[3]?.name||e[2].slice(0,8)+"...")+"";return{c(){t=h("p"),n=p("Welcome "),r=p(o),w(t,"class","svelte-1a66x6i")},m(e,o){u(e,t,o),l(t,n),l(t,r)},p(e,t){12&t[0]&&o!==(o=(e[3]?.name||e[2].slice(0,8)+"...")+"")&&x(r,o)},d(e){e&&d(t)}}}function zp(e){let t,n,o,i,s,a,c,f,g,v,b,E,k,S,A,C,T,_,$,I=e[165].query+"",O=e[35].get(e[165].id)?.isLoading,R=!e[35].get(e[165].id)?.hasMore&&e[35].get(e[165].id)?.events?.length>0;function P(){return e[103](e[165])}function L(e,t){return 64&t[0]&&(k=null),64&t[0]&&(S=null),null==k&&(k=!!(e[35].get(e[165].id)?.events?.length>0)),k?Kp:(null==S&&(S=!e[35].get(e[165].id)?.isLoading),S?Wp:void 0)}let B=L(e,[-1,-1,-1,-1,-1,-1]),N=B&&B(e),U=O&&Zp(),j=R&&Yp();function M(...t){return e[108](e[165],...t)}return{c(){t=h("div"),n=h("div"),o=h("h2"),i=p('🔍 Search Results: "'),s=p(I),a=p('"'),c=y(),f=h("button"),g=p("🔄 Refresh"),b=y(),E=h("div"),N&&N.c(),A=y(),U&&U.c(),C=y(),j&&j.c(),T=y(),w(o,"class","svelte-1a66x6i"),w(f,"class","refresh-btn svelte-1a66x6i"),f.disabled=v=e[35].get(e[165].id)?.isLoading,w(n,"class","search-results-header svelte-1a66x6i"),w(E,"class","search-results-content svelte-1a66x6i"),w(t,"class","search-results-view svelte-1a66x6i")},m(e,r){u(e,t,r),l(t,n),l(n,o),l(o,i),l(o,s),l(o,a),l(n,c),l(n,f),l(f,g),l(t,b),l(t,E),N&&N.m(E,null),l(E,A),U&&U.m(E,null),l(E,C),j&&j.m(E,null),l(t,T),_||($=[m(f,"click",P),m(E,"scroll",M)],_=!0)},p(t,n){e=t,64&n[0]&&I!==(I=e[165].query+"")&&x(s,I),64&n[0]&&v!==(v=e[35].get(e[165].id)?.isLoading)&&(f.disabled=v),B===(B=L(e,n))&&N?N.p(e,n):(N&&N.d(1),N=B&&B(e),N&&(N.c(),N.m(E,A))),64&n[0]&&(O=e[35].get(e[165].id)?.isLoading),O?U||(U=Zp(),U.c(),U.m(E,C)):U&&(U.d(1),U=null),64&n[0]&&(R=!e[35].get(e[165].id)?.hasMore&&e[35].get(e[165].id)?.events?.length>0),R?j||(j=Yp(),j.c(),j.m(E,null)):j&&(j.d(1),j=null)},d(e){e&&d(t),N&&N.d(),U&&U.d(),j&&j.d(),_=!1,r($)}}}function Wp(e){let t,n,r,o,i,s=e[165].query+"";return{c(){t=h("div"),n=h("p"),r=p('No search results found for "'),o=p(s),i=p('".'),w(n,"class","svelte-1a66x6i"),w(t,"class","no-search-results svelte-1a66x6i")},m(e,s){u(e,t,s),l(t,n),l(n,r),l(n,o),l(n,i)},p(e,t){64&t[0]&&s!==(s=e[165].query+"")&&x(o,s)},d(e){e&&d(t)}}}function Kp(e){let t,n=e[35].get(e[165].id).events,r=[];for(let t=0;t<n.length;t+=1)r[t]=Gp(yp(e,n,t));return{c(){for(let e=0;e<r.length;e+=1)r[e].c();t=g()},m(e,n){for(let t=0;t<r.length;t+=1)r[t]&&r[t].m(e,n);u(e,t,n)},p(e,o){if(131156&o[0]|720&o[1]){let i;for(n=e[35].get(e[165].id).events,i=0;i<n.length;i+=1){const s=yp(e,n,i);r[i]?r[i].p(s,o):(r[i]=Gp(s),r[i].c(),r[i].m(t.parentNode,t))}for(;i<r.length;i+=1)r[i].d(1);r.length=n.length}},d(e){f(r,e),e&&d(t)}}}function Jp(e){let t,n,r;function o(){return e[104](e[145])}return{c(){t=h("button"),t.textContent="🗑️",w(t,"class","delete-btn svelte-1a66x6i")},m(e,i){u(e,t,i),n||(r=m(t,"click",v(o)),n=!0)},p(t,n){e=t},d(e){e&&d(t),n=!1,r()}}}function Vp(e){let t,n,r,o,i,s,a,c,f=JSON.stringify(e[145],null,2)+"";function g(...t){return e[107](e[145],...t)}return{c(){t=h("div"),n=h("div"),r=h("pre"),o=p(f),i=y(),s=h("button"),s.textContent="📋",w(r,"class","event-json svelte-1a66x6i"),w(s,"class","copy-json-btn svelte-1a66x6i"),w(s,"title","Copy minified JSON to clipboard"),w(n,"class","json-container svelte-1a66x6i"),w(t,"class","search-result-details svelte-1a66x6i")},m(e,d){u(e,t,d),l(t,n),l(n,r),l(r,o),l(n,i),l(n,s),a||(c=m(s,"click",v(g)),a=!0)},p(t,n){e=t,64&n[0]&&f!==(f=JSON.stringify(e[145],null,2)+"")&&x(o,f)},d(e){e&&d(t),a=!1,c()}}}function Gp(e){let t,n,o,i,s,a,c,f,g,v,b,E,k,A,C,T,_,$,I,O,R,P,L,B,N,U,j=tg(e[145].pubkey)+"",M=e[145].kind+"",F=e[37](e[145].kind)+"",D=rg(e[145].created_at)+"",H=ng(e[145].content)+"",q=e[17].has(e[145].id),z=5!==e[145].kind&&("admin"===e[4]||"owner"===e[4]||"write"===e[4]&&e[145].pubkey&&e[145].pubkey===e[2])&&Jp(e);function W(){return e[105](e[145])}function K(...t){return e[106](e[145],...t)}let J=q&&Vp(e);return{c(){t=h("div"),n=h("div"),o=h("div"),o.innerHTML='<div class="avatar-placeholder svelte-1a66x6i">👤</div>',i=y(),s=h("div"),a=h("div"),c=p(j),f=y(),g=h("div"),v=h("span"),b=p(M),E=y(),k=h("span"),A=p(F),C=y(),T=h("div"),_=h("div"),$=p(D),I=y(),O=h("div"),R=p(H),P=y(),z&&z.c(),L=y(),J&&J.c(),B=y(),w(o,"class","search-result-avatar svelte-1a66x6i"),w(a,"class","search-result-author svelte-1a66x6i"),w(v,"class","kind-number svelte-1a66x6i"),w(k,"class","kind-name svelte-1a66x6i"),w(g,"class","search-result-kind svelte-1a66x6i"),w(s,"class","search-result-info svelte-1a66x6i"),w(_,"class","event-timestamp svelte-1a66x6i"),w(O,"class","event-content-single-line svelte-1a66x6i"),w(T,"class","search-result-content svelte-1a66x6i"),w(n,"class","search-result-row svelte-1a66x6i"),w(n,"role","button"),w(n,"tabindex","0"),w(t,"class","search-result-item svelte-1a66x6i"),S(t,"expanded",e[17].has(e[145].id))},m(e,r){u(e,t,r),l(t,n),l(n,o),l(n,i),l(n,s),l(s,a),l(a,c),l(s,f),l(s,g),l(g,v),l(v,b),l(g,E),l(g,k),l(k,A),l(n,C),l(n,T),l(T,_),l(_,$),l(T,I),l(T,O),l(O,R),l(n,P),z&&z.m(n,null),l(t,L),J&&J.m(t,null),l(t,B),N||(U=[m(n,"click",W),m(n,"keydown",K)],N=!0)},p(r,o){e=r,64&o[0]&&j!==(j=tg(e[145].pubkey)+"")&&x(c,j),64&o[0]&&M!==(M=e[145].kind+"")&&x(b,M),64&o[0]&&F!==(F=e[37](e[145].kind)+"")&&x(A,F),64&o[0]&&D!==(D=rg(e[145].created_at)+"")&&x($,D),64&o[0]&&H!==(H=ng(e[145].content)+"")&&x(R,H),5!==e[145].kind&&("admin"===e[4]||"owner"===e[4]||"write"===e[4]&&e[145].pubkey&&e[145].pubkey===e[2])?z?z.p(e,o):(z=Jp(e),z.c(),z.m(n,null)):z&&(z.d(1),z=null),131136&o[0]&&(q=e[17].has(e[145].id)),q?J?J.p(e,o):(J=Vp(e),J.c(),J.m(t,B)):J&&(J.d(1),J=null),131136&o[0]|16&o[1]&&S(t,"expanded",e[17].has(e[145].id))},d(e){e&&d(t),z&&z.d(),J&&J.d(),N=!1,r(U)}}}function Zp(e){let t;return{c(){t=h("div"),t.innerHTML='<div class="loading-spinner svelte-1a66x6i"></div> \n <p class="svelte-1a66x6i">Searching...</p>',w(t,"class","loading-search-results svelte-1a66x6i")},m(e,n){u(e,t,n)},d(e){e&&d(t)}}}function Yp(e){let t;return{c(){t=h("div"),t.innerHTML='<p class="svelte-1a66x6i">No more search results to load.</p>',w(t,"class","end-of-search-results svelte-1a66x6i")},m(e,n){u(e,t,n)},d(e){e&&d(t)}}}function Qp(e){let t,n=e[165].id===e[5]&&zp(e);return{c(){n&&n.c(),t=g()},m(e,r){n&&n.m(e,r),u(e,t,r)},p(e,r){e[165].id===e[5]?n?n.p(e,r):(n=zp(e),n.c(),n.m(t.parentNode,t)):n&&(n.d(1),n=null)},d(e){n&&n.d(e),e&&d(t)}}}function Xp(t){let n,r,o=t[162].label+"";return{c(){n=h("option"),r=p(o),n.__value=t[162].value,n.value=n.__value},m(e,t){u(e,n,t),l(n,r)},p:e,d(e){e&&d(n)}}}function ey(e){let t;function n(e,t){return e[31]?ry:0===e[30].length?ny:ty}let r=n(e),o=r(e);return{c(){t=h("div"),o.c(),w(t,"class","recovery-results svelte-1a66x6i")},m(e,n){u(e,t,n),o.m(t,null)},p(e,i){r===(r=n(e))&&o?o.p(e,i):(o.d(1),o=r(e),o&&(o.c(),o.m(t,null)))},d(e){e&&d(t),o.d()}}}function ty(e){let t,n,r,o=e[30],i=[];for(let t=0;t<o.length;t+=1)i[t]=dy(gp(e,o,t));let s=e[32]&&fy(e);return{c(){t=h("div");for(let e=0;e<i.length;e+=1)i[e].c();n=y(),s&&s.c(),r=g(),w(t,"class","events-list svelte-1a66x6i")},m(e,o){u(e,t,o);for(let e=0;e<i.length;e+=1)i[e]&&i[e].m(t,null);u(e,n,o),s&&s.m(e,o),u(e,r,o)},p(e,n){if(1073741824&n[0]|18432&n[1]){let r;for(o=e[30],r=0;r<o.length;r+=1){const s=gp(e,o,r);i[r]?i[r].p(s,n):(i[r]=dy(s),i[r].c(),i[r].m(t,null))}for(;r<i.length;r+=1)i[r].d(1);i.length=o.length}e[32]?s?s.p(e,n):(s=fy(e),s.c(),s.m(r.parentNode,r)):s&&(s.d(1),s=null)},d(e){e&&d(t),f(i,e),e&&d(n),s&&s.d(e),e&&d(r)}}}function ny(t){let n;return{c(){n=h("div"),n.textContent="No events found for this kind",w(n,"class","no-events svelte-1a66x6i")},m(e,t){u(e,n,t)},p:e,d(e){e&&d(n)}}}function ry(t){let n;return{c(){n=h("div"),n.textContent="Loading events...",w(n,"class","loading svelte-1a66x6i")},m(e,t){u(e,n,t)},p:e,d(e){e&&d(n)}}}function oy(e){let t,n,r;function o(){return e[102](e[145])}return{c(){t=h("button"),t.textContent="🔄 Repost",w(t,"class","repost-button svelte-1a66x6i")},m(e,i){u(e,t,i),n||(r=m(t,"click",o),n=!0)},p(t,n){e=t},d(e){e&&d(t),n=!1,r()}}}function iy(e){let t,n,r,o=e[145].content+"";return{c(){t=h("div"),n=h("pre"),r=p(o),w(n,"class","svelte-1a66x6i"),w(t,"class","generic-content svelte-1a66x6i")},m(e,o){u(e,t,o),l(t,n),l(n,r)},p(e,t){1073741824&t[0]&&o!==(o=e[145].content+"")&&x(r,o)},d(e){e&&d(t)}}}function sy(e){let t,n,r,o,i,s,a,c=e[145].tags.filter(sg).length+"",g=e[145].tags.filter(ag),m=[];for(let t=0;t<g.length;t+=1)m[t]=cy(vp(e,g,t));return{c(){t=h("div"),n=h("p"),r=p("Follows "),o=p(c),i=p(" people"),s=y(),a=h("div");for(let e=0;e<m.length;e+=1)m[e].c();w(n,"class","svelte-1a66x6i"),w(a,"class","follow-tags svelte-1a66x6i"),w(t,"class","follow-list svelte-1a66x6i")},m(e,c){u(e,t,c),l(t,n),l(n,r),l(n,o),l(n,i),l(t,s),l(t,a);for(let e=0;e<m.length;e+=1)m[e]&&m[e].m(a,null)},p(e,t){if(1073741824&t[0]&&c!==(c=e[145].tags.filter(sg).length+"")&&x(o,c),1073741824&t[0]){let n;for(g=e[145].tags.filter(ag),n=0;n<g.length;n+=1){const r=vp(e,g,n);m[n]?m[n].p(r,t):(m[n]=cy(r),m[n].c(),m[n].m(a,null))}for(;n<m.length;n+=1)m[n].d(1);m.length=g.length}},d(e){e&&d(t),f(m,e)}}}function ay(e){let t,n=e[145].content&&ly(e);return{c(){n&&n.c(),t=g()},m(e,r){n&&n.m(e,r),u(e,t,r)},p(e,r){e[145].content?n?n.p(e,r):(n=ly(e),n.c(),n.m(t.parentNode,t)):n&&(n.d(1),n=null)},d(e){n&&n.d(e),e&&d(t)}}}function cy(e){let t,n,r,o=e[157][1].substring(0,8)+"";return{c(){t=h("span"),n=p(o),r=p("..."),w(t,"class","pubkey-tag svelte-1a66x6i")},m(e,o){u(e,t,o),l(t,n),l(t,r)},p(e,t){1073741824&t[0]&&o!==(o=e[157][1].substring(0,8)+"")&&x(n,o)},d(e){e&&d(t)}}}function ly(e){let t,n,r,o=JSON.stringify(JSON.parse(e[145].content),null,2)+"";return{c(){t=h("div"),n=h("pre"),r=p(o),w(n,"class","svelte-1a66x6i"),w(t,"class","profile-content svelte-1a66x6i")},m(e,o){u(e,t,o),l(t,n),l(n,r)},p(e,t){1073741824&t[0]&&o!==(o=JSON.stringify(JSON.parse(e[145].content),null,2)+"")&&x(r,o)},d(e){e&&d(t)}}}function uy(e){let t,n,r,o,i=e[157][0]+"",s=e[157][1]+"";return{c(){t=h("span"),n=p(i),r=p(": "),o=p(s),w(t,"class","tag svelte-1a66x6i")},m(e,i){u(e,t,i),l(t,n),l(t,r),l(t,o)},p(e,t){1073741824&t[0]&&i!==(i=e[157][0]+"")&&x(n,i),1073741824&t[0]&&s!==(s=e[157][1]+"")&&x(o,s)},d(e){e&&d(t)}}}function dy(e){let t,n,r,o,i,s,a,c,g,m,v,b,E,k,A=e[145].kind+"",C=new Date(1e3*e[145].created_at).toLocaleString()+"",T=!e[154]&&oy(e);function _(e,t){return 0===e[145].kind?ay:3===e[145].kind?sy:iy}let $=_(e),I=$(e),O=e[145].tags,R=[];for(let t=0;t<O.length;t+=1)R[t]=uy(mp(e,O,t));return{c(){t=h("div"),n=h("div"),r=h("span"),o=p("Kind "),i=p(A),s=y(),a=h("span"),c=p(C),g=y(),T&&T.c(),m=y(),v=h("div"),I.c(),b=y(),E=h("div");for(let e=0;e<R.length;e+=1)R[e].c();k=y(),w(r,"class","event-kind svelte-1a66x6i"),w(a,"class","event-timestamp svelte-1a66x6i"),w(n,"class","event-header svelte-1a66x6i"),w(v,"class","event-content svelte-1a66x6i"),w(E,"class","event-tags svelte-1a66x6i"),w(t,"class","event-item svelte-1a66x6i"),S(t,"old-version",!e[154])},m(e,d){u(e,t,d),l(t,n),l(n,r),l(r,o),l(r,i),l(n,s),l(n,a),l(a,c),l(n,g),T&&T.m(n,null),l(t,m),l(t,v),I.m(v,null),l(t,b),l(t,E);for(let e=0;e<R.length;e+=1)R[e]&&R[e].m(E,null);l(t,k)},p(e,r){if(1073741824&r[0]&&A!==(A=e[145].kind+"")&&x(i,A),1073741824&r[0]&&C!==(C=new Date(1e3*e[145].created_at).toLocaleString()+"")&&x(c,C),e[154]?T&&(T.d(1),T=null):T?T.p(e,r):(T=oy(e),T.c(),T.m(n,null)),$===($=_(e))&&I?I.p(e,r):(I.d(1),I=$(e),I&&(I.c(),I.m(v,null))),1073741824&r[0]){let t;for(O=e[145].tags,t=0;t<O.length;t+=1){const n=mp(e,O,t);R[t]?R[t].p(n,r):(R[t]=uy(n),R[t].c(),R[t].m(E,null))}for(;t<R.length;t+=1)R[t].d(1);R.length=O.length}1073741824&r[0]|16384&r[1]&&S(t,"old-version",!e[154])},d(e){e&&d(t),T&&T.d(),I.d(),f(R,e)}}}function fy(e){let t,n,r,o;return{c(){t=h("button"),n=p("Load More Events"),w(t,"class","load-more svelte-1a66x6i"),t.disabled=e[31]},m(i,s){u(i,t,s),l(t,n),r||(o=m(t,"click",e[41]),r=!0)},p(e,n){1&n[1]&&(t.disabled=e[31])},d(e){e&&d(t),r=!1,o()}}}function hy(t){let n,r,o,i,s,a;return{c(){n=h("div"),r=h("p"),r.textContent="Please log in to access sprocket management.",o=y(),i=h("button"),i.textContent="Log In",w(r,"class","svelte-1a66x6i"),w(i,"class","login-btn svelte-1a66x6i"),w(n,"class","login-prompt svelte-1a66x6i")},m(e,c){u(e,n,c),l(n,r),l(n,o),l(n,i),s||(a=m(i,"click",t[57]),s=!0)},p:e,d(e){e&&d(n),s=!1,a()}}}function py(e){let t,n,r,o,i,s,a,c,f,g=(e[4]||"none")+"";return{c(){t=h("div"),n=h("p"),n.textContent="❌ Owner permission required for sprocket\n management.",r=y(),o=h("p"),o.innerHTML="To enable sprocket functionality, set the <code>ORLY_OWNERS</code> environment variable with your npub when starting the\n relay.",i=y(),s=h("p"),a=p("Current user role: "),c=h("strong"),f=p(g),w(n,"class","svelte-1a66x6i"),w(o,"class","svelte-1a66x6i"),w(s,"class","svelte-1a66x6i"),w(t,"class","permission-denied svelte-1a66x6i")},m(e,d){u(e,t,d),l(t,n),l(t,r),l(t,o),l(t,i),l(t,s),l(s,a),l(s,c),l(c,f)},p(e,t){16&t[0]&&g!==(g=(e[4]||"none")+"")&&x(f,g)},d(e){e&&d(t)}}}function yy(e){let t,n,o,i,s,a,c,g,v,b,k,A,C,T,_,$,I,O,R,P,L,B,N,U,j,M,F,D,H,q,z,W,K,J,V,G,Z,Y,Q,X,ee,te,ne,re,oe,ie,se,ae,ce,le,ue,de,fe,he,pe,ye,ge=e[21]?.is_running?"🟢 Running":"🔴 Stopped",me=e[21]?.script_exists?"✅ Exists":"❌ Not found",ve=e[21]?.pid&&gy(e),we=e[24]&&my(e),be=e[22],xe=[];for(let t=0;t<be.length;t+=1)xe[t]=by(bp(e,be,t));return{c(){t=h("div"),n=h("div"),o=h("h3"),o.textContent="Script Editor",i=y(),s=h("div"),a=h("button"),c=p("🔄 Restart"),g=y(),v=h("button"),b=p("🗑️ Delete Script"),A=y(),C=h("div"),T=h("h4"),T.textContent="Upload Script",_=y(),$=h("div"),I=h("input"),O=y(),R=h("button"),P=p("📤 Upload & Update"),B=y(),N=h("div"),U=h("div"),j=h("span"),j.textContent="Status:",M=y(),F=h("span"),D=p(ge),H=y(),ve&&ve.c(),q=y(),z=h("div"),W=h("span"),W.textContent="Script:",K=y(),J=h("span"),V=p(me),G=y(),Z=h("div"),Y=h("textarea"),Q=y(),X=h("div"),ee=h("button"),te=p("💾 Save & Update"),ne=y(),re=h("button"),oe=p("📥 Load Current"),ie=y(),we&&we.c(),se=y(),ae=h("div"),ce=h("h3"),ce.textContent="Script Versions",le=y(),ue=h("div");for(let e=0;e<xe.length;e+=1)xe[e].c();de=y(),fe=h("button"),he=p("🔄 Refresh Versions"),w(a,"class","sprocket-btn restart-btn svelte-1a66x6i"),a.disabled=e[23],w(v,"class","sprocket-btn delete-btn svelte-1a66x6i"),v.disabled=k=e[23]||!e[21]?.script_exists,w(s,"class","sprocket-controls svelte-1a66x6i"),w(n,"class","sprocket-header svelte-1a66x6i"),w(T,"class","svelte-1a66x6i"),w(I,"type","file"),w(I,"id","sprocket-upload-file"),w(I,"accept",".sh,.bash"),I.disabled=e[23],w(I,"class","svelte-1a66x6i"),w(R,"class","sprocket-btn upload-btn svelte-1a66x6i"),R.disabled=L=e[23]||!e[26],w($,"class","upload-controls svelte-1a66x6i"),w(C,"class","sprocket-upload-section svelte-1a66x6i"),w(j,"class","status-label svelte-1a66x6i"),w(F,"class","status-value svelte-1a66x6i"),S(F,"running",e[21]?.is_running),w(U,"class","status-item svelte-1a66x6i"),w(W,"class","status-label svelte-1a66x6i"),w(J,"class","status-value svelte-1a66x6i"),w(z,"class","status-item svelte-1a66x6i"),w(N,"class","sprocket-status svelte-1a66x6i"),w(Y,"class","script-editor svelte-1a66x6i"),w(Y,"placeholder","#!/bin/bash # Enter your sprocket script here..."),Y.disabled=e[23],w(Z,"class","script-editor-container svelte-1a66x6i"),w(ee,"class","sprocket-btn save-btn svelte-1a66x6i"),ee.disabled=e[23],w(re,"class","sprocket-btn load-btn svelte-1a66x6i"),re.disabled=e[23],w(X,"class","script-actions svelte-1a66x6i"),w(t,"class","sprocket-section svelte-1a66x6i"),w(ue,"class","versions-list svelte-1a66x6i"),w(fe,"class","sprocket-btn refresh-btn svelte-1a66x6i"),fe.disabled=e[23],w(ae,"class","sprocket-section svelte-1a66x6i")},m(r,d){u(r,t,d),l(t,n),l(n,o),l(n,i),l(n,s),l(s,a),l(a,c),l(s,g),l(s,v),l(v,b),l(t,A),l(t,C),l(C,T),l(C,_),l(C,$),l($,I),l($,O),l($,R),l(R,P),l(t,B),l(t,N),l(N,U),l(U,j),l(U,M),l(U,F),l(F,D),l(N,H),ve&&ve.m(N,null),l(N,q),l(N,z),l(z,W),l(z,K),l(z,J),l(J,V),l(t,G),l(t,Z),l(Z,Y),E(Y,e[20]),l(t,Q),l(t,X),l(X,ee),l(ee,te),l(X,ne),l(X,re),l(re,oe),l(t,ie),we&&we.m(t,null),u(r,se,d),u(r,ae,d),l(ae,ce),l(ae,le),l(ae,ue);for(let e=0;e<xe.length;e+=1)xe[e]&&xe[e].m(ue,null);l(ae,de),l(ae,fe),l(fe,he),pe||(ye=[m(a,"click",e[48]),m(v,"click",e[49]),m(I,"change",e[53]),m(R,"click",e[54]),m(Y,"input",e[96]),m(ee,"click",e[47]),m(re,"click",e[46]),m(fe,"click",e[50])],pe=!0)},p(e,n){if(8388608&n[0]&&(a.disabled=e[23]),10485760&n[0]&&k!==(k=e[23]||!e[21]?.script_exists)&&(v.disabled=k),8388608&n[0]&&(I.disabled=e[23]),75497472&n[0]&&L!==(L=e[23]||!e[26])&&(R.disabled=L),2097152&n[0]&&ge!==(ge=e[21]?.is_running?"🟢 Running":"🔴 Stopped")&&x(D,ge),2097152&n[0]&&S(F,"running",e[21]?.is_running),e[21]?.pid?ve?ve.p(e,n):(ve=gy(e),ve.c(),ve.m(N,q)):ve&&(ve.d(1),ve=null),2097152&n[0]&&me!==(me=e[21]?.script_exists?"✅ Exists":"❌ Not found")&&x(V,me),8388608&n[0]&&(Y.disabled=e[23]),1048576&n[0]&&E(Y,e[20]),8388608&n[0]&&(ee.disabled=e[23]),8388608&n[0]&&(re.disabled=e[23]),e[24]?we?we.p(e,n):(we=my(e),we.c(),we.m(t,null)):we&&(we.d(1),we=null),12582912&n[0]|3145728&n[1]){let t;for(be=e[22],t=0;t<be.length;t+=1){const r=bp(e,be,t);xe[t]?xe[t].p(r,n):(xe[t]=by(r),xe[t].c(),xe[t].m(ue,null))}for(;t<xe.length;t+=1)xe[t].d(1);xe.length=be.length}8388608&n[0]&&(fe.disabled=e[23])},d(e){e&&d(t),ve&&ve.d(),we&&we.d(),e&&d(se),e&&d(ae),f(xe,e),pe=!1,r(ye)}}}function gy(e){let t,n,r,o,i,s=e[21].pid+"";return{c(){t=h("div"),n=h("span"),n.textContent="PID:",r=y(),o=h("span"),i=p(s),w(n,"class","status-label svelte-1a66x6i"),w(o,"class","status-value svelte-1a66x6i"),w(t,"class","status-item svelte-1a66x6i")},m(e,s){u(e,t,s),l(t,n),l(t,r),l(t,o),l(o,i)},p(e,t){2097152&t[0]&&s!==(s=e[21].pid+"")&&x(i,s)},d(e){e&&d(t)}}}function my(e){let t,n;return{c(){t=h("div"),n=p(e[24]),w(t,"class","sprocket-message svelte-1a66x6i"),S(t,"error","error"===e[25])},m(e,r){u(e,t,r),l(t,n)},p(e,r){16777216&r[0]&&x(n,e[24]),33554432&r[0]&&S(t,"error","error"===e[25])},d(e){e&&d(t)}}}function vy(e){let t;return{c(){t=h("span"),t.textContent="Current",w(t,"class","current-badge svelte-1a66x6i")},m(e,n){u(e,t,n)},d(e){e&&d(t)}}}function wy(e){let t,n,r,o;function i(){return e[98](e[151])}return{c(){t=h("button"),n=p("🗑️ Delete"),w(t,"class","version-btn delete-btn svelte-1a66x6i"),t.disabled=e[23]},m(e,s){u(e,t,s),l(t,n),r||(o=m(t,"click",i),r=!0)},p(n,r){e=n,8388608&r[0]&&(t.disabled=e[23])},d(e){e&&d(t),r=!1,o()}}}function by(e){let t,n,r,o,i,s,a,c,f,g,v,b,E,k,A,C,T=e[151].name+"",_=new Date(e[151].modified).toLocaleString()+"",$=e[151].is_current&&vy();function I(){return e[97](e[151])}let O=!e[151].is_current&&wy(e);return{c(){t=h("div"),n=h("div"),r=h("div"),o=p(T),i=y(),s=h("div"),a=p(_),c=y(),$&&$.c(),f=y(),g=h("div"),v=h("button"),b=p("📥 Load"),E=y(),O&&O.c(),k=y(),w(r,"class","version-name svelte-1a66x6i"),w(s,"class","version-date svelte-1a66x6i"),w(n,"class","version-info svelte-1a66x6i"),w(v,"class","version-btn load-btn svelte-1a66x6i"),v.disabled=e[23],w(g,"class","version-actions svelte-1a66x6i"),w(t,"class","version-item svelte-1a66x6i"),S(t,"current",e[151].is_current)},m(e,d){u(e,t,d),l(t,n),l(n,r),l(r,o),l(n,i),l(n,s),l(s,a),l(s,c),$&&$.m(s,null),l(t,f),l(t,g),l(g,v),l(v,b),l(g,E),O&&O.m(g,null),l(t,k),A||(C=m(v,"click",I),A=!0)},p(n,r){e=n,4194304&r[0]&&T!==(T=e[151].name+"")&&x(o,T),4194304&r[0]&&_!==(_=new Date(e[151].modified).toLocaleString()+"")&&x(a,_),e[151].is_current?$||($=vy(),$.c(),$.m(s,null)):$&&($.d(1),$=null),8388608&r[0]&&(v.disabled=e[23]),e[151].is_current?O&&(O.d(1),O=null):O?O.p(e,r):(O=wy(e),O.c(),O.m(g,null)),4194304&r[0]&&S(t,"current",e[151].is_current)},d(e){e&&d(t),$&&$.d(),O&&O.d(),A=!1,C()}}}function xy(t){let n,r,o,i,s,a;return{c(){n=h("div"),r=h("p"),r.textContent="Please log in with owner permissions to access\n managed ACL configuration.",o=y(),i=h("button"),i.textContent="Log In",w(i,"class","login-btn svelte-1a66x6i"),w(n,"class","access-denied")},m(e,c){u(e,n,c),l(n,r),l(n,o),l(n,i),s||(a=m(i,"click",t[57]),s=!0)},p:e,i:e,o:e,d(e){e&&d(n),s=!1,a()}}}function Ey(e){let t,n;return t=new dp({props:{userSigner:e[12],userPubkey:e[2]}}),{c(){J(t.$$.fragment)},m(e,r){V(t,e,r),n=!0},p(e,n){const r={};4096&n[0]&&(r.userSigner=e[12]),4&n[0]&&(r.userPubkey=e[2]),t.$set(r)},i(e){n||(W(t.$$.fragment,e),n=!0)},o(e){K(t.$$.fragment,e),n=!1},d(e){G(t,e)}}}function ky(t){let n,r,o,i,s,a,c,f,g,m,v,b=(t[9]||"unknown")+"";return{c(){n=h("div"),r=h("h3"),r.textContent="⚠️ Managed ACL Mode Not Active",o=y(),i=h("p"),i.textContent='To use the Managed ACL interface, you need to set\n the ACL mode to "managed" in your relay\n configuration.',s=y(),a=h("p"),c=p("Current ACL mode: "),f=h("strong"),g=p(b),m=y(),v=h("p"),v.innerHTML='Please set <code class="svelte-1a66x6i">ORLY_ACL_MODE=managed</code> in your\n environment variables and restart the relay.',w(r,"class","svelte-1a66x6i"),w(i,"class","svelte-1a66x6i"),w(a,"class","svelte-1a66x6i"),w(v,"class","svelte-1a66x6i"),w(n,"class","acl-mode-warning svelte-1a66x6i")},m(e,t){u(e,n,t),l(n,r),l(n,o),l(n,i),l(n,s),l(n,a),l(a,c),l(a,f),l(f,g),l(n,m),l(n,v)},p(e,t){512&t[0]&&b!==(b=(e[9]||"unknown")+"")&&x(g,b)},i:e,o:e,d(e){e&&d(n)}}}function Sy(t){let n;return{c(){n=h("div"),n.innerHTML='<p class="svelte-1a66x6i">❌ Write, admin, or owner permission required to\n view all events.</p>',w(n,"class","permission-denied svelte-1a66x6i")},m(e,t){u(e,n,t)},p:e,d(e){e&&d(n)}}}function Ay(e){let t,n,r,o,i;function s(e,t){return e[34].length>0?Ty:e[18]?void 0:Cy}let a=s(e),c=a&&a(e),f=e[18]&&By(),p=!e[19]&&e[7].length>0&&Ny();return{c(){t=h("div"),c&&c.c(),n=y(),f&&f.c(),r=y(),p&&p.c(),w(t,"class","events-view-content svelte-1a66x6i")},m(s,a){u(s,t,a),c&&c.m(t,null),l(t,n),f&&f.m(t,null),l(t,r),p&&p.m(t,null),o||(i=m(t,"scroll",e[74]),o=!0)},p(e,o){a===(a=s(e))&&c?c.p(e,o):(c&&c.d(1),c=a&&a(e),c&&(c.c(),c.m(t,n))),e[18]?f||(f=By(),f.c(),f.m(t,r)):f&&(f.d(1),f=null),!e[19]&&e[7].length>0?p||(p=Ny(),p.c(),p.m(t,null)):p&&(p.d(1),p=null)},d(e){e&&d(t),c&&c.d(),f&&f.d(),p&&p.d(),o=!1,i()}}}function Cy(t){let n;return{c(){n=h("div"),n.innerHTML='<p class="svelte-1a66x6i">No events found.</p>',w(n,"class","no-events svelte-1a66x6i")},m(e,t){u(e,n,t)},p:e,d(e){e&&d(n)}}}function Ty(e){let t,n=e[34],r=[];for(let t=0;t<n.length;t+=1)r[t]=Ly(xp(e,n,t));return{c(){for(let e=0;e<r.length;e+=1)r[e].c();t=g()},m(e,n){for(let t=0;t<r.length;t+=1)r[t]&&r[t].m(e,n);u(e,t,n)},p(e,o){if(131092&o[0]|712&o[1]){let i;for(n=e[34],i=0;i<n.length;i+=1){const s=xp(e,n,i);r[i]?r[i].p(s,o):(r[i]=Ly(s),r[i].c(),r[i].m(t.parentNode,t))}for(;i<r.length;i+=1)r[i].d(1);r.length=n.length}},d(e){f(r,e),e&&d(t)}}}function _y(e){let t,n,r=ng(e[145].content)+"";return{c(){t=h("div"),n=p(r),w(t,"class","event-content-single-line svelte-1a66x6i")},m(e,r){u(e,t,r),l(t,n)},p(e,t){8&t[1]&&r!==(r=ng(e[145].content)+"")&&x(n,r)},d(e){e&&d(t)}}}function $y(e){let t,n,r,o=e[145].tags&&e[145].tags.length>0&&Iy(e);return{c(){t=h("div"),n=h("span"),n.textContent="🗑️ Delete Event",r=y(),o&&o.c(),w(n,"class","delete-event-label svelte-1a66x6i"),w(t,"class","delete-event-info svelte-1a66x6i")},m(e,i){u(e,t,i),l(t,n),l(t,r),o&&o.m(t,null)},p(e,n){e[145].tags&&e[145].tags.length>0?o?o.p(e,n):(o=Iy(e),o.c(),o.m(t,null)):o&&(o.d(1),o=null)},d(e){e&&d(t),o&&o.d()}}}function Iy(e){let t,n=e[145].tags.filter(ig),r=[];for(let t=0;t<n.length;t+=1)r[t]=Oy(Ep(e,n,t));return{c(){t=h("div");for(let e=0;e<r.length;e+=1)r[e].c();w(t,"class","delete-targets svelte-1a66x6i")},m(e,n){u(e,t,n);for(let e=0;e<r.length;e+=1)r[e]&&r[e].m(t,null)},p(e,o){if(8&o[1]){let i;for(n=e[145].tags.filter(ig),i=0;i<n.length;i+=1){const s=Ep(e,n,i);r[i]?r[i].p(s,o):(r[i]=Oy(s),r[i].c(),r[i].m(t,null))}for(;i<r.length;i+=1)r[i].d(1);r.length=n.length}},d(e){e&&d(t),f(r,e)}}}function Oy(e){let t,n,r,o,i,s=e[148][1].slice(0,8)+"",a=e[148][1].slice(-8)+"";return{c(){t=h("span"),n=p("Target: "),r=p(s),o=p("..."),i=p(a),w(t,"class","delete-target svelte-1a66x6i")},m(e,s){u(e,t,s),l(t,n),l(t,r),l(t,o),l(t,i)},p(e,t){8&t[1]&&s!==(s=e[148][1].slice(0,8)+"")&&x(r,s),8&t[1]&&a!==(a=e[148][1].slice(-8)+"")&&x(i,a)},d(e){e&&d(t)}}}function Ry(e){let t,n,r;function o(){return e[87](e[145])}return{c(){t=h("button"),t.textContent="🗑️",w(t,"class","delete-btn svelte-1a66x6i")},m(e,i){u(e,t,i),n||(r=m(t,"click",v(o)),n=!0)},p(t,n){e=t},d(e){e&&d(t),n=!1,r()}}}function Py(e){let t,n,r,o,i,s,a,c,f=JSON.stringify(e[145],null,2)+"";function g(...t){return e[90](e[145],...t)}return{c(){t=h("div"),n=h("div"),r=h("pre"),o=p(f),i=y(),s=h("button"),s.textContent="📋",w(r,"class","event-json svelte-1a66x6i"),w(s,"class","copy-json-btn svelte-1a66x6i"),w(s,"title","Copy minified JSON to clipboard"),w(n,"class","json-container svelte-1a66x6i"),w(t,"class","events-view-details svelte-1a66x6i")},m(e,d){u(e,t,d),l(t,n),l(n,r),l(r,o),l(n,i),l(n,s),a||(c=m(s,"click",v(g)),a=!0)},p(t,n){e=t,8&n[1]&&f!==(f=JSON.stringify(e[145],null,2)+"")&&x(o,f)},d(e){e&&d(t),a=!1,c()}}}function Ly(e){let t,n,o,i,s,a,c,f,g,v,b,E,k,A,C,T,_,$,I,O,R,P,L,B,N=tg(e[145].pubkey)+"",U=e[145].kind+"",j=e[37](e[145].kind)+"",M=rg(e[145].created_at)+"",F=e[17].has(e[145].id);function D(e,t){return 5===e[145].kind?$y:_y}let H=D(e),q=H(e),z=5!==e[145].kind&&("admin"===e[4]||"owner"===e[4]||"write"===e[4]&&e[145].pubkey&&e[145].pubkey===e[2])&&Ry(e);function W(){return e[88](e[145])}function K(...t){return e[89](e[145],...t)}let J=F&&Py(e);return{c(){t=h("div"),n=h("div"),o=h("div"),o.innerHTML='<div class="avatar-placeholder svelte-1a66x6i">👤</div>',i=y(),s=h("div"),a=h("div"),c=p(N),f=y(),g=h("div"),v=h("span"),b=p(U),E=y(),k=h("span"),A=p(j),C=y(),T=h("div"),_=h("div"),$=p(M),I=y(),q.c(),O=y(),z&&z.c(),R=y(),J&&J.c(),P=y(),w(o,"class","events-view-avatar svelte-1a66x6i"),w(a,"class","events-view-author svelte-1a66x6i"),w(v,"class","kind-number svelte-1a66x6i"),S(v,"delete-event",5===e[145].kind),w(k,"class","kind-name svelte-1a66x6i"),w(g,"class","events-view-kind svelte-1a66x6i"),w(s,"class","events-view-info svelte-1a66x6i"),w(_,"class","event-timestamp svelte-1a66x6i"),w(T,"class","events-view-content svelte-1a66x6i"),w(n,"class","events-view-row svelte-1a66x6i"),w(n,"role","button"),w(n,"tabindex","0"),w(t,"class","events-view-item svelte-1a66x6i"),S(t,"expanded",e[17].has(e[145].id))},m(e,r){u(e,t,r),l(t,n),l(n,o),l(n,i),l(n,s),l(s,a),l(a,c),l(s,f),l(s,g),l(g,v),l(v,b),l(g,E),l(g,k),l(k,A),l(n,C),l(n,T),l(T,_),l(_,$),l(T,I),q.m(T,null),l(n,O),z&&z.m(n,null),l(t,R),J&&J.m(t,null),l(t,P),L||(B=[m(n,"click",W),m(n,"keydown",K)],L=!0)},p(r,o){e=r,8&o[1]&&N!==(N=tg(e[145].pubkey)+"")&&x(c,N),8&o[1]&&U!==(U=e[145].kind+"")&&x(b,U),8&o[1]&&S(v,"delete-event",5===e[145].kind),8&o[1]&&j!==(j=e[37](e[145].kind)+"")&&x(A,j),8&o[1]&&M!==(M=rg(e[145].created_at)+"")&&x($,M),H===(H=D(e))&&q?q.p(e,o):(q.d(1),q=H(e),q&&(q.c(),q.m(T,null))),5!==e[145].kind&&("admin"===e[4]||"owner"===e[4]||"write"===e[4]&&e[145].pubkey&&e[145].pubkey===e[2])?z?z.p(e,o):(z=Ry(e),z.c(),z.m(n,null)):z&&(z.d(1),z=null),131072&o[0]|8&o[1]&&(F=e[17].has(e[145].id)),F?J?J.p(e,o):(J=Py(e),J.c(),J.m(t,P)):J&&(J.d(1),J=null),131072&o[0]|8&o[1]&&S(t,"expanded",e[17].has(e[145].id))},d(e){e&&d(t),q.d(),z&&z.d(),J&&J.d(),L=!1,r(B)}}}function By(e){let t;return{c(){t=h("div"),t.innerHTML='<div class="loading-spinner svelte-1a66x6i"></div> \n <p class="svelte-1a66x6i">Loading events...</p>',w(t,"class","loading-events svelte-1a66x6i")},m(e,n){u(e,t,n)},d(e){e&&d(t)}}}function Ny(e){let t;return{c(){t=h("div"),t.innerHTML='<p class="svelte-1a66x6i">No more events to load.</p>',w(t,"class","end-of-events svelte-1a66x6i")},m(e,n){u(e,t,n)},d(e){e&&d(t)}}}function Uy(e){let t,n,o,i,s,a,c,f,g,v,b,x,E,k,S,A;function C(e,t){return e[18]?My:jy}let T=C(e),_=T(e);return{c(){t=h("div"),n=h("div"),o=h("label"),i=h("input"),s=y(),a=h("span"),c=y(),f=h("span"),f.textContent="Only show my events",g=y(),v=h("div"),b=h("button"),x=p("🔄 Load More"),E=y(),k=h("button"),_.c(),w(i,"type","checkbox"),w(i,"class","svelte-1a66x6i"),w(a,"class","toggle-slider svelte-1a66x6i"),w(f,"class","toggle-label svelte-1a66x6i"),w(o,"class","toggle-container svelte-1a66x6i"),w(n,"class","events-view-toggle svelte-1a66x6i"),w(b,"class","refresh-btn svelte-1a66x6i"),b.disabled=e[18],w(k,"class","reload-btn svelte-1a66x6i"),k.disabled=e[18],w(v,"class","events-view-buttons svelte-1a66x6i"),w(t,"class","events-view-header svelte-1a66x6i")},m(r,d){u(r,t,d),l(t,n),l(n,o),l(o,i),i.checked=e[8],l(o,s),l(o,a),l(o,c),l(o,f),l(t,g),l(t,v),l(v,b),l(b,x),l(v,E),l(v,k),_.m(k,null),S||(A=[m(i,"change",e[91]),m(i,"change",e[92]),m(b,"click",e[93]),m(k,"click",e[94])],S=!0)},p(e,t){256&t[0]&&(i.checked=e[8]),262144&t[0]&&(b.disabled=e[18]),T!==(T=C(e))&&(_.d(1),_=T(e),_&&(_.c(),_.m(k,null))),262144&t[0]&&(k.disabled=e[18])},d(e){e&&d(t),_.d(),S=!1,r(A)}}}function jy(e){let t;return{c(){t=p("🔄")},m(e,n){u(e,t,n)},d(e){e&&d(t)}}}function My(e){let t;return{c(){t=h("div"),w(t,"class","spinner svelte-1a66x6i")},m(e,n){u(e,t,n)},d(e){e&&d(t)}}}function Fy(t){let n,r,o,i,s,a;return{c(){n=h("div"),r=h("p"),r.textContent="Please log in to access import functionality.",o=y(),i=h("button"),i.textContent="Log In",w(r,"class","svelte-1a66x6i"),w(i,"class","login-btn svelte-1a66x6i"),w(n,"class","login-prompt svelte-1a66x6i")},m(e,c){u(e,n,c),l(n,r),l(n,o),l(n,i),s||(a=m(i,"click",t[57]),s=!0)},p:e,d(e){e&&d(n),s=!1,a()}}}function Dy(t){let n;return{c(){n=h("div"),n.innerHTML='<p class="svelte-1a66x6i">❌ Admin or owner permission required for import\n functionality.</p>',w(n,"class","permission-denied svelte-1a66x6i")},m(e,t){u(e,n,t)},p:e,d(e){e&&d(n)}}}function Hy(e){let t,n,o,i,s,a,c,f,g,v,b;return{c(){t=h("h2"),t.textContent="Import Events",n=y(),o=h("p"),o.textContent="Upload a JSONL file to import events into the database.",i=y(),s=h("input"),a=y(),c=h("button"),f=p("📥 Import Events"),w(t,"class","svelte-1a66x6i"),w(s,"type","file"),w(s,"id","import-file"),w(s,"accept",".jsonl,.txt"),w(s,"class","svelte-1a66x6i"),w(c,"class","import-btn svelte-1a66x6i"),c.disabled=g=!e[16]},m(r,d){u(r,t,d),u(r,n,d),u(r,o,d),u(r,i,d),u(r,s,d),u(r,a,d),u(r,c,d),l(c,f),v||(b=[m(s,"change",e[71]),m(c,"click",e[72])],v=!0)},p(e,t){65536&t[0]&&g!==(g=!e[16])&&(c.disabled=g)},d(e){e&&d(t),e&&d(n),e&&d(o),e&&d(i),e&&d(s),e&&d(a),e&&d(c),v=!1,r(b)}}}function qy(t){let n,r,o,i,s,a;return{c(){n=h("div"),r=h("p"),r.textContent="Please log in to access export functionality.",o=y(),i=h("button"),i.textContent="Log In",w(r,"class","svelte-1a66x6i"),w(i,"class","login-btn svelte-1a66x6i"),w(n,"class","login-prompt svelte-1a66x6i")},m(e,c){u(e,n,c),l(n,r),l(n,o),l(n,i),s||(a=m(i,"click",t[57]),s=!0)},p:e,d(e){e&&d(n),s=!1,a()}}}function zy(e){let t,n,r,o,i,s,a,c,f,p,v=("admin"===e[4]||"owner"===e[4])&&Wy(e);return{c(){t=h("div"),n=h("h2"),n.textContent="Export My Events",r=y(),o=h("p"),o.textContent="Download your personal events as a JSONL file.",i=y(),s=h("button"),s.textContent="📤 Export My Events",a=y(),v&&v.c(),c=g(),w(o,"class","svelte-1a66x6i"),w(s,"class","export-btn svelte-1a66x6i"),w(t,"class","export-section svelte-1a66x6i")},m(d,h){u(d,t,h),l(t,n),l(t,r),l(t,o),l(t,i),l(t,s),u(d,a,h),v&&v.m(d,h),u(d,c,h),f||(p=m(s,"click",e[70]),f=!0)},p(e,t){"admin"===e[4]||"owner"===e[4]?v?v.p(e,t):(v=Wy(e),v.c(),v.m(c.parentNode,c)):v&&(v.d(1),v=null)},d(e){e&&d(t),e&&d(a),v&&v.d(e),e&&d(c),f=!1,p()}}}function Wy(t){let n,r,o,i,s,a,c,f;return{c(){n=h("div"),r=h("h3"),r.textContent="Export All Events",o=y(),i=h("p"),i.textContent="Download the complete database as a JSONL file. This\n includes all events from all users.",s=y(),a=h("button"),a.textContent="📤 Export All Events",w(r,"class","svelte-1a66x6i"),w(i,"class","svelte-1a66x6i"),w(a,"class","export-btn svelte-1a66x6i"),w(n,"class","export-section svelte-1a66x6i")},m(e,d){u(e,n,d),l(n,r),l(n,o),l(n,i),l(n,s),l(n,a),c||(f=m(a,"click",t[69]),c=!0)},p:e,d(e){e&&d(n),c=!1,f()}}}function Ky(e){let t,n,o,i,s,a,c,f,p,g;function b(e,t){return e[3]?Vy:e[1]&&e[2]?Jy:void 0}let x=b(e),E=x&&x(e);return{c(){t=h("div"),n=h("div"),o=h("div"),i=h("h2"),i.textContent="Settings",s=y(),a=h("button"),a.textContent="✕",c=y(),f=h("div"),E&&E.c(),w(i,"class","svelte-1a66x6i"),w(a,"class","close-btn svelte-1a66x6i"),w(o,"class","drawer-header svelte-1a66x6i"),w(f,"class","drawer-content"),w(n,"class","settings-drawer svelte-1a66x6i"),S(n,"dark-theme",e[0]),w(t,"class","drawer-overlay svelte-1a66x6i"),w(t,"role","button"),w(t,"tabindex","0")},m(r,d){u(r,t,d),l(t,n),l(n,o),l(o,i),l(o,s),l(o,a),l(n,c),l(n,f),E&&E.m(f,null),p||(g=[m(a,"click",e[62]),m(n,"click",v(e[80])),m(n,"keydown",v(e[81])),m(t,"click",e[62]),m(t,"keydown",e[109])],p=!0)},p(e,t){x===(x=b(e))&&E?E.p(e,t):(E&&E.d(1),E=x&&x(e),E&&(E.c(),E.m(f,null))),1&t[0]&&S(n,"dark-theme",e[0])},d(e){e&&d(t),E&&E.d(),p=!1,r(g)}}}function Jy(e){let t,n,r,o,i,s,a,c,f,g,v,b,E,k,S,A=e[2].slice(0,16)+"",C=e[2].slice(-8)+"";return{c(){t=h("div"),n=h("h3"),n.textContent="Profile Loading",r=y(),o=h("p"),o.textContent="Your profile metadata is being loaded...",i=y(),s=h("button"),s.textContent="Retry Loading Profile",a=y(),c=h("div"),f=h("strong"),f.textContent="Public Key:",g=y(),v=p(A),b=p("..."),E=p(C),w(n,"class","svelte-1a66x6i"),w(o,"class","svelte-1a66x6i"),w(s,"class","retry-profile-btn svelte-1a66x6i"),w(c,"class","user-pubkey-display svelte-1a66x6i"),w(t,"class","profile-loading-section svelte-1a66x6i")},m(d,h){u(d,t,h),l(t,n),l(t,r),l(t,o),l(t,i),l(t,s),l(t,a),l(t,c),l(c,f),l(c,g),l(c,v),l(c,b),l(c,E),k||(S=m(s,"click",e[68]),k=!0)},p(e,t){4&t[0]&&A!==(A=e[2].slice(0,16)+"")&&x(v,A),4&t[0]&&C!==(C=e[2].slice(-8)+"")&&x(E,C)},d(e){e&&d(t),k=!1,S()}}}function Vy(e){let t,n,r,o,i,s,a,c,f,g,v,b,E,k=(e[3].name||"Unknown User")+"",S=e[3].banner&&Gy(e);function A(e,t){return e[3].picture?Yy:Zy}let C=A(e),T=C(e),_=e[3].nip05&&Qy(e),$=e[3].about&&Xy(e);return{c(){t=h("div"),n=h("div"),S&&S.c(),r=y(),o=h("button"),o.textContent="Log out",i=y(),T.c(),s=y(),a=h("div"),c=h("h3"),f=p(k),g=y(),_&&_.c(),v=y(),$&&$.c(),w(o,"class","logout-btn floating svelte-1a66x6i"),w(c,"class","profile-username svelte-1a66x6i"),w(a,"class","name-row svelte-1a66x6i"),w(n,"class","profile-hero svelte-1a66x6i"),w(t,"class","profile-section svelte-1a66x6i")},m(d,h){u(d,t,h),l(t,n),S&&S.m(n,null),l(n,r),l(n,o),l(n,i),T.m(n,null),l(n,s),l(n,a),l(a,c),l(c,f),l(a,g),_&&_.m(a,null),l(t,v),$&&$.m(t,null),b||(E=m(o,"click",e[59]),b=!0)},p(e,o){e[3].banner?S?S.p(e,o):(S=Gy(e),S.c(),S.m(n,r)):S&&(S.d(1),S=null),C===(C=A(e))&&T?T.p(e,o):(T.d(1),T=C(e),T&&(T.c(),T.m(n,s))),8&o[0]&&k!==(k=(e[3].name||"Unknown User")+"")&&x(f,k),e[3].nip05?_?_.p(e,o):(_=Qy(e),_.c(),_.m(a,null)):_&&(_.d(1),_=null),e[3].about?$?$.p(e,o):($=Xy(e),$.c(),$.m(t,null)):$&&($.d(1),$=null)},d(e){e&&d(t),S&&S.d(),T.d(),_&&_.d(),$&&$.d(),b=!1,E()}}}function Gy(e){let t,n;return{c(){t=h("img"),a(t.src,n=e[3].banner)||w(t,"src",n),w(t,"alt","Profile banner"),w(t,"class","profile-banner svelte-1a66x6i")},m(e,n){u(e,t,n)},p(e,r){8&r[0]&&!a(t.src,n=e[3].banner)&&w(t,"src",n)},d(e){e&&d(t)}}}function Zy(t){let n;return{c(){n=h("div"),n.textContent="👤",w(n,"class","profile-avatar-placeholder overlap svelte-1a66x6i")},m(e,t){u(e,n,t)},p:e,d(e){e&&d(n)}}}function Yy(e){let t,n;return{c(){t=h("img"),a(t.src,n=e[3].picture)||w(t,"src",n),w(t,"alt","User avatar"),w(t,"class","profile-avatar overlap svelte-1a66x6i")},m(e,n){u(e,t,n)},p(e,r){8&r[0]&&!a(t.src,n=e[3].picture)&&w(t,"src",n)},d(e){e&&d(t)}}}function Qy(e){let t,n,r=e[3].nip05+"";return{c(){t=h("span"),n=p(r),w(t,"class","profile-nip05-inline svelte-1a66x6i")},m(e,r){u(e,t,r),l(t,n)},p(e,t){8&t[0]&&r!==(r=e[3].nip05+"")&&x(n,r)},d(e){e&&d(t)}}}function Xy(e){let t,n;return{c(){t=h("div"),n=h("p"),w(n,"class","profile-about svelte-1a66x6i"),w(t,"class","about-card svelte-1a66x6i")},m(r,o){u(r,t,o),l(t,n),n.innerHTML=e[33]},p(e,t){4&t[1]&&(n.innerHTML=e[33])},d(e){e&&d(t)}}}function eg(e){let t,n,o,i,s,c,g,v,b,E,k,A,C,T,_,$,I,R,L,B,N,U,j,M,F,D,H,Z,Y=e[0]?"☀️":"🌙";function Q(e,t){return e[14]?Ap:Sp}let X=Q(e),ee=X(e);function te(e,t){return e[1]?_p:Tp}let ne=te(e),re=ne(e),oe=e[10],ie=[];for(let t=0;t<oe.length;t+=1)ie[t]=Rp(kp(e,oe,t));const se=[Dp,Fp,Mp,jp,Up,Np,Bp,Lp,Pp],ae=[];function ce(e,t){return 96&t[0]&&(L=null),"export"===e[5]?0:"import"===e[5]?1:"events"===e[5]?2:"compose"===e[5]?3:"managed-acl"===e[5]?4:"sprocket"===e[5]?5:"recovery"===e[5]?6:(null==L&&(L=!!e[6].some(e[82])),L?7:8)}B=ce(e,[-1,-1,-1,-1,-1,-1]),N=ae[B]=se[B](e);let le=e[13]&&Ky(e);function ue(t){e[110](t)}let de={isDarkTheme:e[0]};return void 0!==e[11]&&(de.showModal=e[11]),M=new bh({props:de}),O.push(()=>function(e,t,n){const r=e.$$.props[t];void 0!==r&&(e.$$.bound[r]=n,n(e.$$.ctx[r]))}(M,"showModal",ue)),M.$on("login",e[58]),M.$on("close",e[60]),{c(){t=h("header"),n=h("div"),o=h("img"),s=y(),ee.c(),c=y(),g=h("button"),g.textContent="🔍",v=y(),b=h("button"),E=p(Y),k=y(),re.c(),A=y(),C=h("div"),T=h("aside"),_=h("div"),$=h("div");for(let e=0;e<ie.length;e+=1)ie[e].c();I=y(),R=h("main"),N.c(),U=y(),le&&le.c(),j=y(),J(M.$$.fragment),a(o.src,i="/orly.png")||w(o,"src","/orly.png"),w(o,"alt","ORLY Logo"),w(o,"class","logo svelte-1a66x6i"),w(g,"class","search-btn svelte-1a66x6i"),w(b,"class","theme-toggle-btn svelte-1a66x6i"),w(n,"class","header-content svelte-1a66x6i"),w(t,"class","main-header svelte-1a66x6i"),S(t,"dark-theme",e[0]),w($,"class","tabs svelte-1a66x6i"),w(_,"class","sidebar-content svelte-1a66x6i"),w(T,"class","sidebar svelte-1a66x6i"),S(T,"dark-theme",e[0]),w(R,"class","main-content svelte-1a66x6i"),w(C,"class","app-container svelte-1a66x6i"),S(C,"dark-theme",e[0])},m(r,i){u(r,t,i),l(t,n),l(n,o),l(n,s),ee.m(n,null),l(n,c),l(n,g),l(n,v),l(n,b),l(b,E),l(n,k),re.m(n,null),u(r,A,i),u(r,C,i),l(C,T),l(T,_),l(_,$);for(let e=0;e<ie.length;e+=1)ie[e]&&ie[e].m($,null);l(C,I),l(C,R),ae[B].m(R,null),u(r,U,i),le&&le.m(r,i),u(r,j,i),V(M,r,i),D=!0,H||(Z=[m(g,"click",e[63]),m(b,"click",e[56])],H=!0)},p(e,r){if(X===(X=Q(e))&&ee?ee.p(e,r):(ee.d(1),ee=X(e),ee&&(ee.c(),ee.m(n,c))),(!D||1&r[0])&&Y!==(Y=e[0]?"☀️":"🌙")&&x(E,Y),ne===(ne=te(e))&&re?re.p(e,r):(re.d(1),re=ne(e),re&&(re.c(),re.m(n,null))),(!D||1&r[0])&&S(t,"dark-theme",e[0]),1056&r[0]|16777216&r[1]|8&r[2]){let t;for(oe=e[10],t=0;t<oe.length;t+=1){const n=kp(e,oe,t);ie[t]?ie[t].p(n,r):(ie[t]=Rp(n),ie[t].c(),ie[t].m($,null))}for(;t<ie.length;t+=1)ie[t].d(1);ie.length=oe.length}(!D||1&r[0])&&S(T,"dark-theme",e[0]);let o=B;B=ce(e,r),B===o?ae[B].p(e,r):(q(),K(ae[o],1,1,()=>{ae[o]=null}),z(),N=ae[B],N?N.p(e,r):(N=ae[B]=se[B](e),N.c()),W(N,1),N.m(R,null)),(!D||1&r[0])&&S(C,"dark-theme",e[0]),e[13]?le?le.p(e,r):(le=Ky(e),le.c(),le.m(j.parentNode,j)):le&&(le.d(1),le=null);const i={};var s;1&r[0]&&(i.isDarkTheme=e[0]),!F&&2048&r[0]&&(F=!0,i.showModal=e[11],s=()=>F=!1,P.push(s)),M.$set(i)},i(e){D||(W(N),W(M.$$.fragment,e),D=!0)},o(e){K(N),K(M.$$.fragment,e),D=!1},d(e){e&&d(t),ee.d(),re.d(),e&&d(A),e&&d(C),f(ie,e),ae[B].d(),e&&d(U),le&&le.d(e),e&&d(j),G(M,e),H=!1,r(Z)}}}function tg(e){return e?e.slice(0,8)+"..."+e.slice(-8):"unknown"}function ng(e,t=100){return e?e.length>t?e.slice(0,t)+"...":e:""}function rg(e){return e?new Date(1e3*e).toLocaleString():""}async function og(e,t){try{const n=JSON.stringify(e);await navigator.clipboard.writeText(n);const r=t.target.closest(".copy-json-btn");if(r){const e=r.textContent;r.textContent="✅",r.style.backgroundColor="#4CAF50",setTimeout(()=>{r.textContent=e,r.style.backgroundColor=""},2e3)}}catch(n){console.error("Failed to copy to clipboard:",n);try{const n=document.createElement("textarea");n.value=JSON.stringify(e),document.body.appendChild(n),n.select(),document.execCommand("copy"),document.body.removeChild(n);const r=t.target.closest(".copy-json-btn");if(r){const e=r.textContent;r.textContent="✅",r.style.backgroundColor="#4CAF50",setTimeout(()=>{r.textContent=e,r.style.backgroundColor=""},2e3)}}catch(e){console.error("Fallback copy also failed:",e),alert("Failed to copy to clipboard. Please copy manually.")}}}const ig=e=>"e"===e[0],sg=e=>"p"===e[0],ag=e=>"p"===e[0];function cg(e,t,n){let r,o,i,s,a=!1,c=!1,l=!1,u="",d="",f=null,h="",p=null,y=!1,g="export",m=!1,v="",w=[],x=[],E=null,k=new Set,S=!1,A=!0,C=null,T=new Map,_=[],I=0;const O=3e5;let R=!1,P=[],L=!0,B=null,N="",U=null,j=[],M=!1,F="",D="info",H=!1,q=null,z="",W="",K=null,J="",V=[],G=!1,Z=!0,Y=null;const Q=[{value:0,label:"Profile Metadata (0)"},{value:3,label:"Follow List (3)"},{value:1e4,label:"Relay List Metadata (10000)"},{value:10001,label:"Mute List (10001)"},{value:10002,label:"Pin List (10002)"},{value:10003,label:"Bookmark List (10003)"},{value:10004,label:"Communities List (10004)"},{value:10005,label:"Public Chats List (10005)"},{value:10006,label:"Blocked Relays List (10006)"},{value:10007,label:"Search Relays List (10007)"},{value:10015,label:"Interests List (10015)"},{value:10030,label:"Emoji Sets (10030)"},{value:3e4,label:"Categorized People List (30000)"},{value:30001,label:"Categorized Bookmark List (30001)"},{value:30002,label:"Relay Sets (30002)"},{value:30003,label:"Bookmark Sets (30003)"},{value:30004,label:"Curation Sets (30004)"},{value:30008,label:"Profile Badges (30008)"},{value:30009,label:"Badge Definition (30009)"},{value:30015,label:"Interest Sets (30015)"},{value:30017,label:"Stall Definition (30017)"},{value:30018,label:"Product Definition (30018)"},{value:30019,label:"Marketplace UI/UX (30019)"},{value:30020,label:"Product Sold as Auction (30020)"},{value:30023,label:"Article (30023)"},{value:30024,label:"Draft Long-form Content (30024)"},{value:30030,label:"Emoji Sets (30030)"},{value:30078,label:"Application Specific Data (30078)"},{value:30311,label:"Live Event (30311)"},{value:30315,label:"User Statuses (30315)"},{value:30402,label:"Classified Listing (30402)"},{value:30403,label:"Draft Classified Listing (30403)"},{value:31922,label:"Date-based Calendar Event (31922)"},{value:31923,label:"Time-based Calendar Event (31923)"},{value:31924,label:"Calendar (31924)"},{value:31925,label:"Calendar Event RSVP (31925)"},{value:31989,label:"Handler Recommendation (31989)"},{value:31990,label:"Handler Information (31990)"},{value:32123,label:"WaveLake Track (32123)"},{value:34550,label:"Community Definition (34550)"}],X={0:"User Metadata",1:"Short Text Note",2:"Recommend Relay",3:"Follows",4:"Encrypted Direct Messages",5:"Event Deletion Request",6:"Repost",7:"Reaction",8:"Badge Award",9:"Chat Message",10:"Group Chat Threaded Reply",11:"Thread",12:"Group Thread Reply",13:"Seal",14:"Direct Message",15:"File Message",16:"Generic Repost",17:"Reaction to a website",20:"Picture",40:"Channel Creation",41:"Channel Metadata",42:"Channel Message",43:"Channel Hide Message",44:"Channel Mute User",1021:"Bid",1022:"Bid Confirmation",1040:"OpenTimestamps",1063:"File Metadata",1311:"Live Chat Message",1971:"Problem Tracker",1984:"Reporting",1985:"Label",4550:"Community Post Approval",5e3:"Job Request",5999:"Job Request",6e3:"Job Result",6999:"Job Result",7e3:"Job Feedback",9041:"Zap Goal",9734:"Zap Request",9735:"Zap",9882:"Highlights",1e4:"Mute list",10001:"Pin list",10002:"Relay List Metadata",10003:"Bookmarks list",10004:"Communities list",10005:"Public Chats list",10006:"Blocked Relays list",10007:"Search Relays list",10015:"Interests",10030:"User Emoji list",10050:"DM relays",10096:"File Storage Server List",13194:"Wallet Service Info",21e3:"Lightning pub RPC",22242:"Client Authentication",23194:"Wallet Request",23195:"Wallet Response",23196:"Wallet Notification",23197:"Wallet Notification",24133:"Nostr Connect",27235:"HTTP Auth",3e4:"Follow sets",30001:"Generic lists",30002:"Relay sets",30003:"Bookmark sets",30004:"Curation sets",30008:"Profile Badges",30009:"Badge Definition",30015:"Interest sets",30017:"Stall Definition",30018:"Product Definition",30019:"Marketplace UI/UX",30020:"Product sold as an auction",30023:"Long-form Content",30024:"Draft Long-form Content",30030:"Emoji sets",30078:"Application-specific Data",30311:"Live Event",30315:"User Statuses",30402:"Classified Listing",30403:"Draft Classified Listing",31922:"Date-Based Calendar Event",31923:"Time-Based Calendar Event",31924:"Calendar",31925:"Calendar Event RSVP",31989:"Handler recommendation",31990:"Handler information",34235:"Video Event Horizontal",34236:"Video Event Vertical",34550:"Community Definition"};function ee(e){k.has(e)?k.delete(e):k.add(e),n(17,k)}async function te(){console.log("Toggle changed, showOnlyMyEvents:",R);const e=R&&l&&u?[u]:null;await ke(!0,e)}async function ne(e){if(!l)return void alert("Please log in first");const t=x.find(t=>t.id===e);if(!t)return void alert("Event not found");if("admin"===h||"owner"===h||"write"===h&&t.pubkey&&t.pubkey===u){if(confirm("Are you sure you want to delete this event?"))try{if(!p)throw new Error("Signer not available for signing");const r={kind:5,created_at:Math.floor(Date.now()/1e3),tags:[["e",e]],content:""};console.log("Created delete event template:",r),console.log("User pubkey:",u),console.log("Target event:",t),console.log("Target event pubkey:",t.pubkey);const o=await p.signEvent(r);console.log("Signed delete event:",o),console.log("Signed delete event pubkey:",o.pubkey),console.log("Delete event tags:",o.tags);const i=`wss://${window.location.host}`;try{const e=await hp(i,o,p,u);e.success?console.log("Delete event published successfully to ORLY relay"):console.error("Failed to publish delete event:",e.reason)}catch(e){console.error("Error publishing delete event:",e)}const s=t.pubkey&&t.pubkey===u;if(s){const t=await nh.publish(o);if(console.log("Delete event published:",t),!(t.success&&t.okCount>0))throw new Error("No relays accepted the delete event");{await new Promise(e=>setTimeout(e,2e3));try{const n=await lh(e,{timeout:5e3});n?(console.warn("Event still exists after deletion attempt:",n),alert(`Warning: Delete event was accepted by ${t.okCount} relay(s), but the event still exists on the relay. This may indicate the relay does not properly handle delete events.`)):console.log("Event successfully deleted and verified")}catch(e){console.log("Could not fetch event after deletion (likely deleted):",e.message)}try{const t=await uh(e,{timeout:5e3});if(t.length>0){console.log(`Delete event verification: Found ${t.length} delete event(s) targeting ${e}`);const n=t.find(e=>e.pubkey&&e.pubkey===u);n?console.log("Our delete event found in database:",n.id):console.warn("Our delete event not found in database, but other delete events exist")}else console.warn("No delete events found in database for target event:",e)}catch(e){console.log("Could not verify delete event in database:",e.message)}n(7,x=x.filter(t=>t.id!==e)),P=P.filter(t=>t.id!==e),_=_.filter(t=>t.id!==e);for(const[t,n]of T)n.events&&(n.events=n.events.filter(t=>t.id!==e),T.set(t,n));se(),console.log("Reloading events to show delete event...");const r=R&&l&&u?[u]:null;await ke(!0,r),alert(`Event deleted successfully (accepted by ${t.okCount} relay(s))`)}}else{const t=`wss://${window.location.host}/`,r=new th;await r.connectToRelay(t);const i=await r.publish(o);if(console.log("Delete event published to local relay only:",i),!(i.success&&i.okCount>0))throw new Error("Local relay did not accept the delete event");{await new Promise(e=>setTimeout(e,2e3));try{const t=await lh(e,{timeout:5e3});t?(console.warn("Event still exists after deletion attempt:",t),alert(`Warning: Delete event was accepted by ${i.okCount} relay(s), but the event still exists on the relay. This may indicate the relay does not properly handle delete events.`)):console.log("Event successfully deleted and verified")}catch(e){console.log("Could not fetch event after deletion (likely deleted):",e.message)}try{const t=await uh(e,{timeout:5e3});if(t.length>0){console.log(`Delete event verification: Found ${t.length} delete event(s) targeting ${e}`);const n=t.find(e=>e.pubkey&&e.pubkey===u);n?console.log("Our delete event found in database:",n.id):console.warn("Our delete event not found in database, but other delete events exist")}else console.warn("No delete events found in database for target event:",e)}catch(e){console.log("Could not verify delete event in database:",e.message)}n(7,x=x.filter(t=>t.id!==e)),P=P.filter(t=>t.id!==e),_=_.filter(t=>t.id!==e);for(const[t,n]of T)n.events&&(n.events=n.events.filter(t=>t.id!==e),T.set(t,n));se(),console.log("Reloading events to show delete event...");const t=R&&l&&u?[u]:null;await ke(!0,t),alert("Event deleted successfully (local relay only - admin/owner deleting other user's event)")}}}catch(e){console.error("Failed to delete event:",e),alert("Failed to delete event: "+e.message)}}else alert("You do not have permission to delete this event")}async function re(){const e=J?parseInt(J):K;if(e&&l){console.log("Loading recovery events for kind:",e,"user:",u),n(31,G=!0);try{const t={kinds:[e],authors:[u],limit:100};Y&&(t.until=Y),console.log("Recovery filters:",t);const r=await ch(t);console.log("Recovery events received:",r.length),console.log("Recovery events kinds:",r.map(e=>e.kind)),n(30,V=Y?[...V,...r]:r),r.length>0?(Y=Math.min(...r.map(e=>e.created_at)),n(32,Z=100===r.length)):n(32,Z=!1)}catch(e){console.error("Failed to load recovery events:",e)}finally{n(31,G=!1)}}}async function oe(e){if(l&&p)try{const t={kind:e.kind,content:e.content,tags:e.tags,created_at:Math.floor(Date.now()/1e3),pubkey:u};(await hp(DEFAULT_RELAYS[0],t,p,u)).success?(alert("Event reposted successfully!"),n(30,V=[]),Y=null,await re()):alert("Failed to repost event")}catch(e){console.error("Failed to repost event:",e),alert("Failed to repost event: "+e.message)}else alert("Please log in to repost events")}function ie(e){n(28,K=e),n(29,J=""),n(30,V=[]),Y=null,n(32,Z=!0),re()}if("undefined"!=typeof localStorage){const e=localStorage.getItem("isDarkTheme");null!==e&&(a=JSON.parse(e));const t=localStorage.getItem("nostr_auth_method"),r=localStorage.getItem("nostr_pubkey");t&&r&&(l=!0,u=r,d=t,"extension"===t&&window.nostr&&(p=window.nostr),be(),xe()),function(){if("undefined"==typeof localStorage)return;try{const t=localStorage.getItem("app_state");if(t){const r=JSON.parse(t);r.selectedTab&&he.some(e=>e.id===r.selectedTab)&&n(5,g=r.selectedTab),r.expandedEvents&&n(17,k=new Set(r.expandedEvents)),r.globalEventsCache&&(_=r.globalEventsCache),r.globalCacheTimestamp&&(I=r.globalCacheTimestamp),void 0!==r.hasMoreEvents&&n(19,A=r.hasMoreEvents),r.oldestEventTimestamp&&(C=r.oldestEventTimestamp),void 0!==r.hasMoreMyEvents&&(L=r.hasMoreMyEvents),r.oldestMyEventTimestamp&&(B=r.oldestMyEventTimestamp),_.length>0&&((e=I)&&Date.now()-e<O)&&n(7,x=_)}}catch(e){console.error("Failed to load persistent state:",e)}var e}(),async function(){try{const e=await fetch("/api/sprocket/config",{method:"GET",headers:{"Content-Type":"application/json"}});if(e.ok){const t=await e.json();n(78,H=t.enabled)}}catch(e){console.error("Error loading sprocket config:",e)}}()}function se(){if("undefined"==typeof localStorage)return;const e={selectedTab:g,expandedEvents:Array.from(k),globalEventsCache:_,globalCacheTimestamp:I,hasMoreEvents:A,oldestEventTimestamp:C};localStorage.setItem("app_state",JSON.stringify(e))}function ae(e){_=e.sort((e,t)=>t.created_at-e.created_at),I=Date.now(),se()}async function ce(){if(l&&"owner"===h&&H)try{n(23,M=!0);const e=await fetch("/api/sprocket/status",{method:"GET",headers:{Authorization:`Nostr ${await Ce("GET","/api/sprocket/status")}`,"Content-Type":"application/json"}});e.ok?n(21,U=await e.json()):fe("Failed to load sprocket status","error")}catch(e){fe(`Error loading sprocket status: ${e.message}`,"error")}finally{n(23,M=!1)}}async function le(){if(l&&"owner"===h)try{n(23,M=!0);const e=await fetch("/api/sprocket/versions",{method:"GET",headers:{Authorization:`Nostr ${await Ce("GET","/api/sprocket/versions")}`,"Content-Type":"application/json"}});e.ok?n(22,j=await e.json()):fe("Failed to load versions","error")}catch(e){fe(`Error loading versions: ${e.message}`,"error")}finally{n(23,M=!1)}}async function ue(e){l&&"owner"===h&&(n(20,N=e.content),fe(`Loaded version: ${e.name}`,"success"))}async function de(e){if(l&&"owner"===h&&confirm(`Are you sure you want to delete version ${e}?`))try{n(23,M=!0);const t=await fetch("/api/sprocket/delete-version",{method:"POST",headers:{Authorization:`Nostr ${await Ce("POST","/api/sprocket/delete-version")}`,"Content-Type":"application/json"},body:JSON.stringify({filename:e})});if(t.ok)fe(`Version ${e} deleted successfully`,"success"),await le();else{fe(`Failed to delete version: ${await t.text()}`,"error")}}catch(e){fe(`Error deleting version: ${e.message}`,"error")}finally{n(23,M=!1)}}function fe(e,t="info"){n(24,F=e),n(25,D=t),setTimeout(()=>{n(24,F="")},5e3)}const he=[{id:"export",icon:"📤",label:"Export"},{id:"import",icon:"💾",label:"Import",requiresAdmin:!0},{id:"events",icon:"📡",label:"Events"},{id:"compose",icon:"✏️",label:"Compose"},{id:"recovery",icon:"🔄",label:"Recovery"},{id:"managed-acl",icon:"🛡️",label:"Managed ACL",requiresOwner:!0},{id:"sprocket",icon:"⚙️",label:"Sprocket",requiresOwner:!0}];function pe(e){n(5,g=e),"sprocket"===e&&l&&"owner"===h&&H&&(ce(),le()),se()}function ye(){n(13,y=!1)}function ge(e){n(6,w=w.filter(t=>t.id!==e)),T.delete(e),g===e&&n(5,g="export")}async function me(e,t,n=!0){const r=T.get(e);if(r&&!r.isLoading){r.isLoading=!0,T.set(e,r);try{const o={limit:n?100:200,until:n?Math.floor(Date.now()/1e3):r.oldestTimestamp};console.log("Loading search results for query:",t,"with options:",o);const i=await async function(e,t={}){const{limit:n=100,since:r=null,until:o=null,kinds:i=null}=t,s=[{search:e}];return r&&(s[0].since=r),o&&(s[0].until=o),i&&(s[0].kinds=i),n&&(s[0].limit=n),await ah(s,{timeout:3e4})}(t,o);if(console.log("Received search results:",i.length,"events"),r.events=n?i.sort((e,t)=>t.created_at-e.created_at):[...r.events,...i].sort((e,t)=>t.created_at-e.created_at),i.length>0){const e=Math.min(...i.map(e=>e.created_at));(!r.oldestTimestamp||e<r.oldestTimestamp)&&(r.oldestTimestamp=e)}r.hasMore=i.length===(n?100:200),r.isLoading=!1,T.set(e,r)}catch(t){console.error("Failed to load search results:",t),r.isLoading=!1,T.set(e,r),alert("Failed to load search results: "+t.message)}}}function ve(e,t){const{scrollTop:n,scrollHeight:r,clientHeight:o}=e.target;if(r-n-o<100){const e=T.get(t);e&&!e.isLoading&&e.hasMore&&async function(e){const t=w.find(t=>t.id===e);t&&await me(e,t.query,!1)}(t)}}async function we(){if(l&&u&&!f)try{console.log("Auto-fetching profile for:",u),await dh(),n(3,f=await sh(u)),console.log("Profile auto-loaded:",f)}catch(e){console.error("Failed to auto-load profile:",e)}}async function be(){if(l&&u)try{const e=await fetch(`/api/permissions/${u}`);if(e.ok){const t=await e.json();n(4,h=t.permission||""),console.log("User role loaded:",h),console.log("Is owner?","owner"===h)}else console.error("Failed to fetch user role:",e.status),n(4,h="")}catch(e){console.error("Error fetching user role:",e),n(4,h="")}else n(4,h="")}async function xe(){try{const e=await fetch("/api/acl-mode");if(e.ok){const t=await e.json();n(9,z=t.acl_mode||""),console.log("ACL mode loaded:",z)}else console.error("Failed to fetch ACL mode:",e.status),n(9,z="")}catch(e){console.error("Error fetching ACL mode:",e),n(9,z="")}}async function Ee(e=[]){if(l)if(0!==e.length||"admin"===h||"owner"===h)try{const t=await Ae("/api/export","POST"),n=await fetch("/api/export",{method:"POST",headers:{Authorization:t,"Content-Type":"application/json"},body:JSON.stringify({pubkeys:e})});if(!n.ok)throw new Error(`Export failed: ${n.status} ${n.statusText}`);const r=await n.blob(),o=window.URL.createObjectURL(r),i=document.createElement("a");i.href=o;const s=n.headers.get("Content-Disposition");let a="events.jsonl";if(s){const e=s.match(/filename="([^"]+)"/);e&&(a=e[1])}i.download=a,document.body.appendChild(i),i.click(),document.body.removeChild(i),window.URL.revokeObjectURL(o)}catch(e){console.error("Export failed:",e),alert("Export failed: "+e.message)}else alert("Admin or owner permission required to export all events");else alert("Please log in first")}async function ke(e=!1,t=null){if(!l||"write"!==h&&"admin"!==h&&"owner"!==h)alert("Write, admin, or owner permission required");else if(!S){n(18,S=!0),e&&(C=null);try{console.log("Loading events with authors filter:",t,"including delete events");const r=await ch({limit:e?100:200,until:e?Math.floor(Date.now()/1e3):C,authors:t});if(console.log("Received events:",r.length,"events"),t&&r.length>0){const e=r.filter(e=>e.pubkey&&e.pubkey!==u);e.length>0&&console.warn("Server returned non-user events:",e.length,"out of",r.length)}if(e?(n(7,x=r.sort((e,t)=>t.created_at-e.created_at)),ae(r)):(n(7,x=[...x,...r].sort((e,t)=>t.created_at-e.created_at)),ae(x)),r.length>0){const e=Math.min(...r.map(e=>e.created_at));(!C||e<C)&&(C=e)}n(19,A=r.length===(e?1e3:200)),e&&A&&setTimeout(()=>{if("events"===g){const e=document.querySelectorAll(".events-view-content")[0];e&&e.scrollHeight<=e.clientHeight&&Se()}},100)}catch(e){console.error("Failed to load events:",e),alert("Failed to load events: "+e.message)}finally{n(18,S=!1)}}}async function Se(){await ke(!1)}async function Ae(e,t){if(!l||!u)throw new Error("Not logged in");const n={kind:27235,created_at:Math.floor(Date.now()/1e3),tags:[["u",window.location.origin+e],["method",t.toUpperCase()]],content:"",pubkey:u};let r;if(p&&"extension"===d)try{r=await p.signEvent(n)}catch(e){throw new Error("Failed to sign with extension: "+e.message)}else{if("nsec"!==d)throw new Error("No valid signer available");n.id="mock-id-"+Date.now(),n.sig="mock-signature-"+Date.now(),r=n}const o=JSON.stringify(r);return`Nostr ${btoa(o)}`}async function Ce(e,t){if(!l||!u)throw new Error("Not logged in");const n={kind:27235,created_at:Math.floor(Date.now()/1e3),tags:[["u",window.location.origin+t],["method",e.toUpperCase()]],content:"",pubkey:u};let r;if(p&&"extension"===d)try{r=await p.signEvent(n)}catch(e){throw new Error("Failed to sign with extension: "+e.message)}else{if("nsec"!==d)throw new Error("No valid signer available");n.id="mock-id-"+Date.now(),n.sig="mock-signature-"+Date.now(),r=n}const o=JSON.stringify(r);return btoa(o)}return e.$$.update=()=>{var t;if(390&e.$$.dirty[0]&&n(34,r=(R&&l&&u?x.filter(e=>e.pubkey&&e.pubkey===u):x).sort((e,t)=>t.created_at-e.created_at)),8&e.$$.dirty[0]&&n(33,o=f?.about?(t=f.about,String(t).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;")).replace(/\n{2,}/g,"<br>"):""),530&e.$$.dirty[0]|65536&e.$$.dirty[2]&&n(79,i=he.filter(e=>!(e.requiresAdmin&&(!l||"admin"!==h&&"owner"!==h))&&(!(e.requiresOwner&&(!l||"owner"!==h))&&(!("sprocket"===e.id&&!H)&&(("managed-acl"!==e.id||"managed"===z)&&("managed-acl"===e.id&&console.log("Managed ACL tab check:",{isLoggedIn:l,userRole:h,requiresOwner:e.requiresOwner,aclMode:z}),!0)))))),64&e.$$.dirty[0]|131072&e.$$.dirty[2]&&n(10,s=[...i,...w]),1554&e.$$.dirty[0]|131072&e.$$.dirty[2]&&console.log("Tabs debug:",{isLoggedIn:l,userRole:h,aclMode:z,filteredBaseTabs:i.map(e=>e.id),allTabs:s.map(e=>e.id)}),1&e.$$.dirty[0]&&"undefined"!=typeof document&&(a?document.body.classList.add("dark-theme"):document.body.classList.remove("dark-theme")),14&e.$$.dirty[0]&&l&&u&&!f&&we(),438&e.$$.dirty[0]&&"events"===g&&l&&("write"===h||"admin"===h||"owner"===h)&&0===x.length){ke(!0,R&&u?[u]:null)}},[a,l,u,f,h,g,w,x,R,z,s,c,p,y,m,v,E,k,S,A,N,U,j,M,F,D,q,W,K,J,V,G,Z,o,r,T,Q,function(e){return X[e]||`Kind ${e}`},ee,te,ne,re,oe,ie,function(){J&&(n(28,K=null),n(30,V=[]),Y=null,n(32,Z=!0),re())},function(e){const t=V.filter(t=>t.kind===e.kind&&t.pubkey===e.pubkey),n=Math.max(...t.map(e=>e.created_at));return e.created_at===n},async function(){if(l&&"owner"===h)try{n(23,M=!0);const e=await fetch("/api/sprocket/status",{method:"GET",headers:{Authorization:`Nostr ${await Ce("GET","/api/sprocket/status")}`,"Content-Type":"application/json"}});if(e.ok){const t=await e.json();n(20,N=t.script_content||""),n(21,U=t),fe("Script loaded successfully","success")}else fe("Failed to load script","error")}catch(e){fe(`Error loading script: ${e.message}`,"error")}finally{n(23,M=!1)}},async function(){if(l&&"owner"===h)try{n(23,M=!0);const e=await fetch("/api/sprocket/update",{method:"POST",headers:{Authorization:`Nostr ${await Ce("POST","/api/sprocket/update")}`,"Content-Type":"text/plain"},body:N});if(e.ok)fe("Script saved and updated successfully","success"),await ce(),await le();else{fe(`Failed to save script: ${await e.text()}`,"error")}}catch(e){fe(`Error saving script: ${e.message}`,"error")}finally{n(23,M=!1)}},async function(){if(l&&"owner"===h)try{n(23,M=!0);const e=await fetch("/api/sprocket/restart",{method:"POST",headers:{Authorization:`Nostr ${await Ce("POST","/api/sprocket/restart")}`,"Content-Type":"application/json"}});if(e.ok)fe("Sprocket restarted successfully","success"),await ce();else{fe(`Failed to restart sprocket: ${await e.text()}`,"error")}}catch(e){fe(`Error restarting sprocket: ${e.message}`,"error")}finally{n(23,M=!1)}},async function(){if(l&&"owner"===h&&confirm("Are you sure you want to delete the sprocket script? This will stop the current process."))try{n(23,M=!0);const e=await fetch("/api/sprocket/update",{method:"POST",headers:{Authorization:`Nostr ${await Ce("POST","/api/sprocket/update")}`,"Content-Type":"text/plain"},body:""});if(e.ok)n(20,N=""),fe("Sprocket script deleted successfully","success"),await ce(),await le();else{fe(`Failed to delete script: ${await e.text()}`,"error")}}catch(e){fe(`Error deleting script: ${e.message}`,"error")}finally{n(23,M=!1)}},le,ue,de,function(e){n(26,q=e.target.files[0])},async function(){if(l&&"owner"===h&&q)try{n(23,M=!0);const e=await q.text(),t=await fetch("/api/sprocket/update",{method:"POST",headers:{Authorization:`Nostr ${await Ce("POST","/api/sprocket/update")}`,"Content-Type":"text/plain"},body:e});if(t.ok)n(20,N=e),fe("Script uploaded and updated successfully","success"),await ce(),await le();else{fe(`Failed to upload script: ${await t.text()}`,"error")}}catch(e){fe(`Error uploading script: ${e.message}`,"error")}finally{n(23,M=!1),n(26,q=null);const e=document.getElementById("sprocket-upload-file");e&&(e.value="")}},pe,function(){n(0,a=!a),"undefined"!=typeof localStorage&&localStorage.setItem("isDarkTheme",JSON.stringify(a))},function(){l||n(11,c=!0)},async function(e){const{method:t,pubkey:r,privateKey:o,signer:i}=e.detail;n(1,l=!0),n(2,u=r),d=t,n(12,p=i),n(11,c=!1);try{if(await dh(),"extension"===t&&i)nh.setSigner(i);else if("nsec"===t&&o){const e=new Dd(o);nh.setSigner(e)}n(3,f=await sh(r)),console.log("Profile loaded:",f)}catch(e){console.error("Failed to load profile:",e)}await be(),await xe()},function(){n(1,l=!1),n(2,u=""),d="",n(3,f=null),n(4,h=""),n(12,p=null),n(13,y=!1),P=[],n(7,x=[]),_=[],I=0,se(),"undefined"!=typeof localStorage&&(localStorage.removeItem("nostr_auth_method"),localStorage.removeItem("nostr_pubkey"),localStorage.removeItem("nostr_privkey"))},function(){n(11,c=!1)},function(){n(13,y=!0)},ye,function(){n(14,m=!m),m||n(15,v="")},function(e){"Enter"===e.key&&v.trim()?(!function(e){const t=`search-${Date.now()}`,r={id:t,icon:"🔍",label:e,isSearchTab:!0,query:e};n(6,w=[...w,r]),n(5,g=t),T.set(t,{events:[],isLoading:!1,hasMore:!0,oldestTimestamp:null}),me(t,e)}(v.trim()),n(15,v=""),n(14,m=!1)):"Escape"===e.key&&(n(14,m=!1),n(15,v=""))},ge,me,ve,we,async function(){await Ee([])},async function(){await Ee([u])},function(e){n(16,E=e.target.files[0])},async function(){if(!l||"admin"!==h&&"owner"!==h)alert("Admin or owner permission required");else if(E)try{const e=await Ae("/api/import","POST"),t=new FormData;t.append("file",E);const r=await fetch("/api/import",{method:"POST",headers:{Authorization:e},body:t});if(!r.ok)throw new Error(`Import failed: ${r.status} ${r.statusText}`);await r.json();alert("Import started successfully"),n(16,E=null),document.getElementById("import-file").value=""}catch(e){console.error("Import failed:",e),alert("Import failed: "+e.message)}else alert("Please select a file")},ke,function(e){const{scrollTop:t,scrollHeight:n,clientHeight:r}=e.target;n-t-r<100&&Se()},function(){try{if(!W.trim())return void alert("Please enter some JSON to reformat");const e=JSON.parse(W);n(27,W=JSON.stringify(e,null,2))}catch(e){alert("Invalid JSON: "+e.message)}},async function(){try{if(!W.trim())return void alert("Please enter an event to sign");if(!l||!u)return void alert("Please log in to sign events");if(!p)return void alert("No signer available. Please log in with a valid authentication method.");const e=JSON.parse(W);e.pubkey=u,e.created_at=Math.floor(Date.now()/1e3),delete e.id,delete e.sig;const t=await p.signEvent(e);n(27,W=JSON.stringify(t,null,2)),alert("Event signed successfully!")}catch(e){console.error("Error signing event:",e),alert("Error signing event: "+e.message)}},async function(){try{if(!W.trim())return void alert("Please enter an event to publish");if(!l)return void alert("Please log in to publish events");if(!p)return void alert("No signer available. Please log in with a valid authentication method.");const e=JSON.parse(W);if(!e.id||!e.sig)return void alert('Event must be signed before publishing. Please click "Sign" first.');const t=`wss://${window.location.host}`,n=await hp(t,e,p,u);n.success?alert("Event published successfully to ORLY relay!"):alert(`Event publishing failed: ${n.reason||"Unknown error"}`)}catch(e){console.error("Error publishing event:",e),alert("Error publishing event: "+e.message)}},H,i,function(t){$.call(this,e,t)},function(t){$.call(this,e,t)},e=>e.id===g,function(){v=this.value,n(15,v)},e=>ge(e.id),(e,t)=>"Enter"===t.key&&ge(e.id),e=>pe(e.id),e=>ne(e.id),e=>ee(e.id),(e,t)=>"Enter"===t.key&&ee(e.id),(e,t)=>og(e,t),function(){R=this.checked,n(8,R)},()=>te(),()=>{ke(!1,R&&u?[u]:null)},()=>{ke(!0,R&&u?[u]:null)},function(){W=this.value,n(27,W)},function(){N=this.value,n(20,N)},e=>ue(e),e=>de(e.name),function(){K=function(e){const t=e.querySelector(":checked");return t&&t.__value}(this),n(28,K),n(36,Q)},()=>ie(K),function(){J=b(this.value),n(29,J)},e=>oe(e),e=>me(e.id,e.query,!0),e=>ne(e.id),e=>ee(e.id),(e,t)=>"Enter"===t.key&&ee(e.id),(e,t)=>og(e,t),(e,t)=>ve(t,e.id),e=>"Escape"===e.key&&ye(),function(e){c=e,n(11,c)}]}return new class extends Q{constructor(e){super(),Y(this,e,cg,eg,i,{},null,[-1,-1,-1,-1,-1,-1])}}({target:document.body,props:{name:"world"}})}();
//# sourceMappingURL=bundle.js.map