Files
next.orly.dev/app/web/dist/bundle.js
woikos 7ed1aea0f1
Some checks failed
Go / build-and-release (push) Has been cancelled
Add NIP-46 bunker service for remote signing with CAT support (v0.44.0)
- Add bunker-service.js: NIP-46 signer that handles signing requests from remote clients
- Add cashu-client.js: Cashu token minting for bunker authorization
- Update BunkerView.svelte: Add Start/Stop service toggle, CAT token generation, status indicator
- Update App.svelte: Pass userPrivkey to BunkerView for signing
- Add @noble/curves and @noble/hashes dependencies
- Include CAT token in bunker URL format: bunker://<pubkey>?relay=...&secret=...&cat=...
- Improve PWA manifest with maskable icons

Files modified:
- app/web/src/bunker-service.js: NEW - NIP-46 signer implementation
- app/web/src/cashu-client.js: NEW - Cashu token minting client
- app/web/src/BunkerView.svelte: Add service controls and CAT integration
- app/web/src/App.svelte: Add userPrivkey state and prop
- app/web/package.json: Add noble crypto dependencies
- app/web/public/manifest.json: Add maskable icon variants
- pkg/version/version: Bump to v0.44.0

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-29 12:57:13 +01:00

36 lines
561 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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 i(e){return"function"==typeof e}function o(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 l="undefined"!=typeof window?window:"undefined"!=typeof globalThis?globalThis:global;function c(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.createElementNS("http://www.w3.org/2000/svg",e)}function g(e){return document.createTextNode(e)}function m(){return g(" ")}function y(){return g("")}function w(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 A(e,t,n){null==n?e.removeAttribute(t):e.getAttribute(t)!==n&&e.setAttribute(t,n)}function b(e){return""===e?null:+e}function k(e,t){t=""+t,e.data!==t&&(e.data=t)}function I(e,t){e.value=null==t?"":t}function E(e,t,n,r){null==n?e.style.removeProperty(t):e.style.setProperty(t,n,r?"important":"")}function C(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 x(e){const t=e.querySelector(":checked");return t&&t.__value}function B(e,t,n){e.classList[n?"add":"remove"](t)}let S;function F(e){S=e}function Q(){if(!S)throw new Error("Function called outside component initialization");return S}function R(e){Q().$$.on_mount.push(e)}function D(e){Q().$$.on_destroy.push(e)}function P(){const e=Q();return(t,n,{cancelable:r=!1}={})=>{const i=e.$$.callbacks[t];if(i){const o=function(e,t,{bubbles:n=!1,cancelable:r=!1}={}){const i=document.createEvent("CustomEvent");return i.initCustomEvent(e,n,r,t),i}(t,n,{cancelable:r});return i.slice().forEach(t=>{t.call(e,o)}),!o.defaultPrevented}return!0}}function T(e,t){const n=e.$$.callbacks[t.type];n&&n.slice().forEach(e=>e.call(this,t))}const U=[],$=[];let N=[];const L=[],O=Promise.resolve();let M=!1;function _(e){N.push(e)}function H(e){L.push(e)}const j=new Set;let G=0;function K(){if(0!==G)return;const e=S;do{try{for(;G<U.length;){const e=U[G];G++,F(e),J(e.$$)}}catch(e){throw U.length=0,G=0,e}for(F(null),U.length=0,G=0;$.length;)$.pop()();for(let e=0;e<N.length;e+=1){const t=N[e];j.has(t)||(j.add(t),t())}N.length=0}while(U.length);for(;L.length;)L.pop()();M=!1,j.clear(),F(e)}function J(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(_)}}const V=new Set;let q;function z(){q={r:0,c:[],p:q}}function Y(){q.r||r(q.c),q=q.p}function W(e,t){e&&e.i&&(V.delete(e),e.i(t))}function Z(e,t,n,r){if(e&&e.o){if(V.has(e))return;V.add(e),q.c.push(()=>{V.delete(e),r&&(n&&e.d(1),r())}),e.o(t)}else r&&r()}function X(e,t,n){const r=e.$$.props[t];void 0!==r&&(e.$$.bound[r]=n,n(e.$$.ctx[r]))}function ee(e){e&&e.c()}function te(e,n,o,s){const{fragment:a,after_update:l}=e.$$;a&&a.m(n,o),s||_(()=>{const n=e.$$.on_mount.map(t).filter(i);e.$$.on_destroy?e.$$.on_destroy.push(...n):r(n),e.$$.on_mount=[]}),l.forEach(_)}function ne(e,t){const n=e.$$;null!==n.fragment&&(!function(e){const t=[],n=[];N.forEach(r=>-1===e.indexOf(r)?t.push(r):n.push(r)),n.forEach(e=>e()),N=t}(n.after_update),r(n.on_destroy),n.fragment&&n.fragment.d(t),n.on_destroy=n.fragment=null,n.ctx=[])}function re(e,t){-1===e.$$.dirty[0]&&(U.push(e),M||(M=!0,O.then(K)),e.$$.dirty.fill(0)),e.$$.dirty[t/31|0]|=1<<t%31}function ie(t,i,o,s,a,l,c,u=[-1]){const f=S;F(t);const h=t.$$={fragment:null,ctx:[],props:l,update:e,not_equal:a,bound:n(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(i.context||(f?f.$$.context:[])),callbacks:n(),dirty:u,skip_bound:!1,root:i.target||f.$$.root};c&&c(h.root);let p=!1;if(h.ctx=o?o(t,i.props||{},(e,n,...r)=>{const i=r.length?r[0]:n;return h.ctx&&a(h.ctx[e],h.ctx[e]=i)&&(!h.skip_bound&&h.bound[e]&&h.bound[e](i),p&&re(t,e)),n}):[],h.update(),p=!0,r(h.before_update),h.fragment=!!s&&s(h.ctx),i.target){if(i.hydrate){const e=function(e){return Array.from(e.childNodes)}(i.target);h.fragment&&h.fragment.l(e),e.forEach(d)}else h.fragment&&h.fragment.c();i.intro&&W(t.$$.fragment),te(t,i.target,i.anchor,i.customElement),K()}F(f)}class oe{$destroy(){ne(this,1),this.$destroy=e}$on(t,n){if(!i(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 se(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`Wrong positive integer: ${e}`)}function ae(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 le(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 ce="object"==typeof globalThis&&"crypto"in globalThis?globalThis.crypto:void 0,ue=e=>e instanceof Uint8Array,de=e=>new DataView(e.buffer,e.byteOffset,e.byteLength),fe=(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 he(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)),!ue(e))throw new Error("expected Uint8Array, got "+typeof e);return e}let pe=class{clone(){return this._cloneInto()}};function ge(e){const t=t=>e().update(he(t)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function me(e=32){if(ce&&"function"==typeof ce.getRandomValues)return ce.getRandomValues(new Uint8Array(e));throw new Error("crypto.getRandomValues must be defined")}let ye=class extends pe{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=de(this.buffer)}update(e){le(this);const{view:t,buffer:n,blockLen:r}=this,i=(e=he(e)).length;for(let o=0;o<i;){const s=Math.min(r-this.pos,i-o);if(s===r){const t=de(e);for(;r<=i-o;o+=r)this.process(t,o);continue}n.set(e.subarray(o,o+s),this.pos),this.pos+=s,o+=s,this.pos===r&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){le(this),function(e,t){ae(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:i}=this;let{pos:o}=this;t[o++]=128,this.buffer.subarray(o).fill(0),this.padOffset>r-o&&(this.process(n,0),o=0);for(let e=o;e<r;e++)t[e]=0;!function(e,t,n,r){if("function"==typeof e.setBigUint64)return e.setBigUint64(t,n,r);const i=BigInt(32),o=BigInt(4294967295),s=Number(n>>i&o),a=Number(n&o),l=r?4:0,c=r?0:4;e.setUint32(t+l,s,r),e.setUint32(t+c,a,r)}(n,r-8,BigInt(8*this.length),i),this.process(n,0);const s=de(e),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const l=a/4,c=this.get();if(l>c.length)throw new Error("_sha2: outputLen bigger than state");for(let e=0;e<l;e++)s.setUint32(4*e,c[e],i)}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:i,destroyed:o,pos:s}=this;return e.length=r,e.pos=s,e.finished=i,e.destroyed=o,r%t&&e.buffer.set(n),e}};const we=(e,t,n)=>e&t^~e&n,ve=(e,t,n)=>e&t^e&n^t&n,Ae=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]),be=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),ke=new Uint32Array(64);let Ie=class extends ye{constructor(){super(64,32,8,!1),this.A=0|be[0],this.B=0|be[1],this.C=0|be[2],this.D=0|be[3],this.E=0|be[4],this.F=0|be[5],this.G=0|be[6],this.H=0|be[7]}get(){const{A:e,B:t,C:n,D:r,E:i,F:o,G:s,H:a}=this;return[e,t,n,r,i,o,s,a]}set(e,t,n,r,i,o,s,a){this.A=0|e,this.B=0|t,this.C=0|n,this.D=0|r,this.E=0|i,this.F=0|o,this.G=0|s,this.H=0|a}process(e,t){for(let n=0;n<16;n++,t+=4)ke[n]=e.getUint32(t,!1);for(let e=16;e<64;e++){const t=ke[e-15],n=ke[e-2],r=fe(t,7)^fe(t,18)^t>>>3,i=fe(n,17)^fe(n,19)^n>>>10;ke[e]=i+ke[e-7]+r+ke[e-16]|0}let{A:n,B:r,C:i,D:o,E:s,F:a,G:l,H:c}=this;for(let e=0;e<64;e++){const t=c+(fe(s,6)^fe(s,11)^fe(s,25))+we(s,a,l)+Ae[e]+ke[e]|0,u=(fe(n,2)^fe(n,13)^fe(n,22))+ve(n,r,i)|0;c=l,l=a,a=s,s=o+t|0,o=i,i=r,r=n,n=t+u|0}n=n+this.A|0,r=r+this.B|0,i=i+this.C|0,o=o+this.D|0,s=s+this.E|0,a=a+this.F|0,l=l+this.G|0,c=c+this.H|0,this.set(n,r,i,o,s,a,l,c)}roundClean(){ke.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};const Ee=ge(()=>new Ie),Ce=BigInt(0),xe=BigInt(1),Be=BigInt(2),Se=e=>e instanceof Uint8Array,Fe=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function Qe(e){if(!Se(e))throw new Error("Uint8Array expected");let t="";for(let n=0;n<e.length;n++)t+=Fe[e[n]];return t}function Re(e){const t=e.toString(16);return 1&t.length?`0${t}`:t}function De(e){if("string"!=typeof e)throw new Error("hex string expected, got "+typeof e);return BigInt(""===e?"0":`0x${e}`)}function Pe(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,i=e.slice(r,r+2),o=Number.parseInt(i,16);if(Number.isNaN(o)||o<0)throw new Error("Invalid byte sequence");n[t]=o}return n}function Te(e){return De(Qe(e))}function Ue(e){if(!Se(e))throw new Error("Uint8Array expected");return De(Qe(Uint8Array.from(e).reverse()))}function $e(e,t){return Pe(e.toString(16).padStart(2*t,"0"))}function Ne(e,t){return $e(e,t).reverse()}function Le(e,t,n){let r;if("string"==typeof t)try{r=Pe(t)}catch(n){throw new Error(`${e} must be valid hex string, got "${t}". Cause: ${n}`)}else{if(!Se(t))throw new Error(`${e} must be hex string or Uint8Array`);r=Uint8Array.from(t)}const i=r.length;if("number"==typeof n&&i!==n)throw new Error(`${e} expected ${n} bytes, got ${i}`);return r}function Oe(...e){const t=new Uint8Array(e.reduce((e,t)=>e+t.length,0));let n=0;return e.forEach(e=>{if(!Se(e))throw new Error("Uint8Array expected");t.set(e,n),n+=e.length}),t}const Me=e=>(Be<<BigInt(e-1))-xe,_e=e=>new Uint8Array(e),He=e=>Uint8Array.from(e);function je(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=_e(e),i=_e(e),o=0;const s=()=>{r.fill(1),i.fill(0),o=0},a=(...e)=>n(i,r,...e),l=(e=_e())=>{i=a(He([0]),e),r=a(),0!==e.length&&(i=a(He([1]),e),r=a())},c=()=>{if(o++>=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 Oe(...n)};return(e,t)=>{let n;for(s(),l(e);!(n=t(c()));)l();return s(),n}}const Ge={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 Ke(e,t,n={}){const r=(t,n,r)=>{const i=Ge[n];if("function"!=typeof i)throw new Error(`Invalid validator "${n}", expected function`);const o=e[t];if(!(r&&void 0===o||i(o,e)))throw new Error(`Invalid param ${String(t)}=${o} (${typeof o}), 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 Je=Object.freeze({__proto__:null,bitGet:function(e,t){return e>>BigInt(t)&xe},bitLen:function(e){let t;for(t=0;e>Ce;e>>=xe,t+=1);return t},bitMask:Me,bitSet:(e,t,n)=>e|(n?xe:Ce)<<BigInt(t),bytesToHex:Qe,bytesToNumberBE:Te,bytesToNumberLE:Ue,concatBytes:Oe,createHmacDrbg:je,ensureBytes:Le,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:Pe,hexToNumber:De,numberToBytesBE:$e,numberToBytesLE:Ne,numberToHexUnpadded:Re,numberToVarBytesBE:function(e){return Pe(Re(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:Ke});
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Ve=BigInt(0),qe=BigInt(1),ze=BigInt(2),Ye=BigInt(3),We=BigInt(4),Ze=BigInt(5),Xe=BigInt(8);function et(e,t){const n=e%t;return n>=Ve?n:t+n}function tt(e,t,n){if(n<=Ve||t<Ve)throw new Error("Expected power/modulo > 0");if(n===qe)return Ve;let r=qe;for(;t>Ve;)t&qe&&(r=r*e%n),e=e*e%n,t>>=qe;return r}function nt(e,t,n){let r=e;for(;t-- >Ve;)r*=r,r%=n;return r}function rt(e,t){if(e===Ve||t<=Ve)throw new Error(`invert: expected positive integers, got n=${e} mod=${t}`);let n=et(e,t),r=t,i=Ve,o=qe;for(;n!==Ve;){const e=r%n,t=i-o*(r/n);r=n,n=e,i=o,o=t}if(r!==qe)throw new Error("invert: does not exist");return et(i,t)}function it(e){if(e%We===Ye){const t=(e+qe)/We;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%Xe===Ze){const t=(e-Ze)/Xe;return function(e,n){const r=e.mul(n,ze),i=e.pow(r,t),o=e.mul(n,i),s=e.mul(e.mul(o,ze),i),a=e.mul(o,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-qe)/ze;let n,r,i;for(n=e-qe,r=0;n%ze===Ve;n/=ze,r++);for(i=ze;i<e&&tt(i,t,e)!==e-qe;i++);if(1===r){const t=(e+qe)/We;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 o=(n+qe)/ze;return function(e,s){if(e.pow(s,t)===e.neg(e.ONE))throw new Error("Cannot find square root");let a=r,l=e.pow(e.mul(e.ONE,i),n),c=e.pow(s,o),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(l,qe<<BigInt(a-t-1));l=e.sqr(n),c=e.mul(c,n),u=e.mul(u,l),a=t}return c}}(e)}BigInt(9),BigInt(16);const ot=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function st(e,t){const n=void 0!==t?t:e.toString(2).length;return{nBitLength:n,nByteLength:Math.ceil(n/8)}}function at(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 lt(e){const t=at(e);return t+Math.ceil(t/2)}
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
const ct=BigInt(0),ut=BigInt(1);function dt(e){return function(e){const t=ot.reduce((e,t)=>(e[t]="function",e),{ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"});Ke(e,t)}(e.Fp),Ke(e,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...st(e.n,e.nBitLength),...e,p:e.Fp.ORDER})}
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const{bytesToNumberBE:ft,hexToBytes:ht}=Je,pt={Err:class extends Error{constructor(e=""){super(e)}},_parseInt(e){const{Err:t}=pt;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:ft(r),l:e.subarray(n+2)}},toSig(e){const{Err:t}=pt,n="string"==typeof e?ht(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:i,l:o}=pt._parseInt(n.subarray(2)),{d:s,l:a}=pt._parseInt(o);if(a.length)throw new t("Invalid signature: left bytes after parsing");return{r:i,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)),i=t(n(e.r)),o=r.length/2,s=i.length/2,a=n(o),l=n(s);return`30${n(s+o+4)}02${l}${i}02${a}${r}`}},gt=BigInt(0),mt=BigInt(1);BigInt(2);const yt=BigInt(3);function wt(e){const t=function(e){const t=dt(e);Ke(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:i}=t;if(n){if(!r.eql(i,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 i=t.toAffine();return Oe(Uint8Array.from([4]),n.toBytes(i.x),n.toBytes(i.y))}),i=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 o(e){const{a:r,b:i}=t,o=n.sqr(e),s=n.mul(o,e);return n.add(n.add(s,n.mul(e,r)),i)}if(!n.eql(n.sqr(t.Gy),o(t.Gx)))throw new Error("bad generator point: equation left != right");function s(e){return"bigint"==typeof e&&gt<e&&e<t.n}function a(e){if(!s(e))throw new Error("Expected valid bigint: 0 < bigint < curve.n")}function l(e){const{allowedPrivateKeyLengths:n,nByteLength:r,wrapPrivateKey:i,n:o}=t;if(n&&"bigint"!=typeof e){if(e instanceof Uint8Array&&(e=Qe(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(Le("private key",e,r))}catch(t){throw new Error(`private key must be ${r} bytes, hex or bigint, not ${typeof e}`)}return i&&(s=et(s,o)),a(s),s}const c=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 i=e=>n.eql(e,n.ZERO);return i(t)&&i(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(i(Le("pointHex",e)));return t.assertValidity(),t}static fromPrivateKey(e){return d.BASE.multiply(l(e))}_setWindowSize(e){this._WINDOW_SIZE=e,c.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 i=n.sqr(r),s=o(e);if(!n.eql(i,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:i}=this,{px:o,py:s,pz:a}=e,l=n.eql(n.mul(t,a),n.mul(o,i)),c=n.eql(n.mul(r,a),n.mul(s,i));return l&&c}negate(){return new d(this.px,n.neg(this.py),this.pz)}double(){const{a:e,b:r}=t,i=n.mul(r,yt),{px:o,py:s,pz:a}=this;let l=n.ZERO,c=n.ZERO,u=n.ZERO,f=n.mul(o,o),h=n.mul(s,s),p=n.mul(a,a),g=n.mul(o,s);return g=n.add(g,g),u=n.mul(o,a),u=n.add(u,u),l=n.mul(e,u),c=n.mul(i,p),c=n.add(l,c),l=n.sub(h,c),c=n.add(h,c),c=n.mul(l,c),l=n.mul(g,l),u=n.mul(i,u),p=n.mul(e,p),g=n.sub(f,p),g=n.mul(e,g),g=n.add(g,u),u=n.add(f,f),f=n.add(u,f),f=n.add(f,p),f=n.mul(f,g),c=n.add(c,f),p=n.mul(s,a),p=n.add(p,p),f=n.mul(p,g),l=n.sub(l,f),u=n.mul(p,h),u=n.add(u,u),u=n.add(u,u),new d(l,c,u)}add(e){u(e);const{px:r,py:i,pz:o}=this,{px:s,py:a,pz:l}=e;let c=n.ZERO,f=n.ZERO,h=n.ZERO;const p=t.a,g=n.mul(t.b,yt);let m=n.mul(r,s),y=n.mul(i,a),w=n.mul(o,l),v=n.add(r,i),A=n.add(s,a);v=n.mul(v,A),A=n.add(m,y),v=n.sub(v,A),A=n.add(r,o);let b=n.add(s,l);return A=n.mul(A,b),b=n.add(m,w),A=n.sub(A,b),b=n.add(i,o),c=n.add(a,l),b=n.mul(b,c),c=n.add(y,w),b=n.sub(b,c),h=n.mul(p,A),c=n.mul(g,w),h=n.add(c,h),c=n.sub(y,h),h=n.add(y,h),f=n.mul(c,h),y=n.add(m,m),y=n.add(y,m),w=n.mul(p,w),A=n.mul(g,A),y=n.add(y,w),w=n.sub(m,w),w=n.mul(p,w),A=n.add(A,w),m=n.mul(y,A),f=n.add(f,m),m=n.mul(b,A),c=n.mul(v,c),c=n.sub(c,m),m=n.mul(v,y),h=n.mul(b,h),h=n.add(h,m),new d(c,f,h)}subtract(e){return this.add(e.negate())}is0(){return this.equals(d.ZERO)}wNAF(e){return h.wNAFCached(this,c,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===gt)return r;if(a(e),e===mt)return this;const{endo:i}=t;if(!i)return h.unsafeLadder(this,e);let{k1neg:o,k1:s,k2neg:l,k2:c}=i.splitScalar(e),u=r,f=r,p=this;for(;s>gt||c>gt;)s&mt&&(u=u.add(p)),c&mt&&(f=f.add(p)),p=p.double(),s>>=mt,c>>=mt;return o&&(u=u.negate()),l&&(f=f.negate()),f=new d(n.mul(f.px,i.beta),f.py,f.pz),u.add(f)}multiply(e){a(e);let r,i,o=e;const{endo:s}=t;if(s){const{k1neg:e,k1:t,k2neg:a,k2:l}=s.splitScalar(o);let{p:c,f:u}=this.wNAF(t),{p:f,f:p}=this.wNAF(l);c=h.constTimeNegate(e,c),f=h.constTimeNegate(a,f),f=new d(n.mul(f.px,s.beta),f.py,f.pz),r=c.add(f),i=u.add(p)}else{const{p:e,f:t}=this.wNAF(o);r=e,i=t}return d.normalizeZ([r,i])[0]}multiplyAndAddUnsafe(e,t,n){const r=d.BASE,i=(e,t)=>t!==gt&&t!==mt&&e.equals(r)?e.multiply(t):e.multiplyUnsafe(t),o=i(this,t).add(i(e,n));return o.is0()?void 0:o}toAffine(e){const{px:t,py:r,pz:i}=this,o=this.is0();null==e&&(e=o?n.ONE:n.inv(i));const s=n.mul(t,e),a=n.mul(r,e),l=n.mul(i,e);if(o)return{x:n.ZERO,y:n.ZERO};if(!n.eql(l,n.ONE))throw new Error("invZ was invalid");return{x:s,y:a}}isTorsionFree(){const{h:e,isTorsionFree:n}=t;if(e===mt)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===mt?this:n?n(d,this):this.multiplyUnsafe(t.h)}toRawBytes(e=!0){return this.assertValidity(),r(d,this,e)}toHex(e=!0){return Qe(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,i=t;for(;n>ct;)n&ut&&(r=r.add(i)),i=i.double(),n>>=ut;return r},precomputeWindow(e,t){const{windows:n,windowSize:i}=r(t),o=[];let s=e,a=s;for(let e=0;e<n;e++){a=s,o.push(a);for(let e=1;e<i;e++)a=a.add(s),o.push(a);s=a.double()}return o},wNAF(t,i,o){const{windows:s,windowSize:a}=r(t);let l=e.ZERO,c=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(o&u);o>>=f,r>a&&(r-=d,o+=ut);const s=t,h=t+Math.abs(r)-1,p=e%2!=0,g=r<0;0===r?c=c.add(n(p,i[s])):l=l.add(n(g,i[h]))}return{p:l,f:c}},wNAFCached(e,t,n,r){const i=e._WINDOW_SIZE||1;let o=t.get(e);return o||(o=this.precomputeWindow(e,i),1!==i&&t.set(e,r(o))),this.wNAF(i,o,n)}}}(d,t.endo?Math.ceil(f/2):f);return{CURVE:t,ProjectivePoint:d,normPrivateKeyToScalar:l,weierstrassEquation:o,isWithinCurveOrder:s}}function vt(e){const t=function(e){const t=dt(e);return Ke(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,i=n.BYTES+1,o=2*n.BYTES+1;function s(e){return et(e,r)}function a(e){return rt(e,r)}const{ProjectivePoint:l,normPrivateKeyToScalar:c,weierstrassEquation:u,isWithinCurveOrder:d}=wt({...t,toBytes(e,t,r){const i=t.toAffine(),o=n.toBytes(i.x),s=Oe;return r?s(Uint8Array.from([t.hasEvenY()?2:3]),o):s(Uint8Array.from([4]),o,n.toBytes(i.y))},fromBytes(e){const t=e.length,r=e[0],s=e.subarray(1);if(t!==i||2!==r&&3!==r){if(t===o&&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 ${i} compressed bytes or ${o} uncompressed bytes`)}{const e=Te(s);if(!(gt<(a=e)&&a<n.ORDER))throw new Error("Point is not on curve");const t=u(e);let i=n.sqrt(t);return!(1&~r)!==((i&mt)===mt)&&(i=n.neg(i)),{x:e,y:i}}var a}}),f=e=>Qe($e(e,t.nByteLength));function h(e){return e>r>>mt}const p=(e,t,n)=>Te(e.slice(t,n));class g{constructor(e,t,n){this.r=e,this.s=t,this.recovery=n,this.assertValidity()}static fromCompact(e){const n=t.nByteLength;return e=Le("compactSignature",e,2*n),new g(p(e,0,n),p(e,n,2*n))}static fromDER(e){const{r:t,s:n}=pt.toSig(Le("DER",e));return new g(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 g(this.r,this.s,e)}recoverPublicKey(e){const{r:r,s:i,recovery:o}=this,c=v(Le("msgHash",e));if(null==o||![0,1,2,3].includes(o))throw new Error("recovery id invalid");const u=2===o||3===o?r+t.n:r;if(u>=n.ORDER)throw new Error("recovery id 2 or 3 invalid");const d=1&o?"03":"02",h=l.fromHex(d+f(u)),p=a(u),g=s(-c*p),m=s(i*p),y=l.BASE.multiplyAndAddUnsafe(h,g,m);if(!y)throw new Error("point at infinify");return y.assertValidity(),y}hasHighS(){return h(this.s)}normalizeS(){return this.hasHighS()?new g(this.r,s(-this.s),this.recovery):this}toDERRawBytes(){return Pe(this.toDERHex())}toDERHex(){return pt.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return Pe(this.toCompactHex())}toCompactHex(){return f(this.r)+f(this.s)}}const m={isValidPrivateKey(e){try{return c(e),!0}catch(e){return!1}},normPrivateKeyToScalar:c,randomPrivateKey:()=>{const e=lt(t.n);return function(e,t,n=!1){const r=e.length,i=at(t),o=lt(t);if(r<16||r<o||r>1024)throw new Error(`expected ${o}-1024 bytes of input, got ${r}`);const s=et(n?Te(e):Ue(e),t-qe)+qe;return n?Ne(s,i):$e(s,i)}(t.randomBytes(e),t.n)},precompute:(e=8,t=l.BASE)=>(t._setWindowSize(e),t.multiply(BigInt(3)),t)};function y(e){const t=e instanceof Uint8Array,n="string"==typeof e,r=(t||n)&&e.length;return t?r===i||r===o:n?r===2*i||r===2*o:e instanceof l}const w=t.bits2int||function(e){const n=Te(e),r=8*e.length-t.nBitLength;return r>0?n>>BigInt(r):n},v=t.bits2int_modN||function(e){return s(w(e))},A=Me(t.nBitLength);function b(e){if("bigint"!=typeof e)throw new Error("bigint expected");if(!(gt<=e&&e<A))throw new Error(`bigint expected < 2^${t.nBitLength}`);return $e(e,t.nByteLength)}function k(e,r,i=I){if(["recovered","canonical"].some(e=>e in i))throw new Error("sign() legacy options not supported");const{hash:o,randomBytes:u}=t;let{lowS:f,prehash:p,extraEntropy:m}=i;null==f&&(f=!0),e=Le("msgHash",e),p&&(e=Le("prehashed msgHash",o(e)));const y=v(e),A=c(r),k=[b(A),b(y)];if(null!=m){const e=!0===m?u(n.BYTES):m;k.push(Le("extraEntropy",e))}const E=Oe(...k),C=y;return{seed:E,k2sig:function(e){const t=w(e);if(!d(t))return;const n=a(t),r=l.BASE.multiply(t).toAffine(),i=s(r.x);if(i===gt)return;const o=s(n*s(C+i*A));if(o===gt)return;let c=(r.x===i?0:2)|Number(r.y&mt),u=o;return f&&h(o)&&(u=function(e){return h(e)?s(-e):e}(o),c^=1),new g(i,u,c)}}}const I={lowS:t.lowS,prehash:!1},E={lowS:t.lowS,prehash:!1};return l.BASE._setWindowSize(8),{CURVE:t,getPublicKey:function(e,t=!0){return l.fromPrivateKey(e).toRawBytes(t)},getSharedSecret:function(e,t,n=!0){if(y(e))throw new Error("first arg must be private key");if(!y(t))throw new Error("second arg must be public key");return l.fromHex(t).multiply(c(e)).toRawBytes(n)},sign:function(e,n,r=I){const{seed:i,k2sig:o}=k(e,n,r),s=t;return je(s.hash.outputLen,s.nByteLength,s.hmac)(i,o)},verify:function(e,n,r,i=E){const o=e;if(n=Le("msgHash",n),r=Le("publicKey",r),"strict"in i)throw new Error("options.strict was renamed to lowS");const{lowS:c,prehash:u}=i;let d,f;try{if("string"==typeof o||o instanceof Uint8Array)try{d=g.fromDER(o)}catch(e){if(!(e instanceof pt.Err))throw e;d=g.fromCompact(o)}else{if("object"!=typeof o||"bigint"!=typeof o.r||"bigint"!=typeof o.s)throw new Error("PARSE");{const{r:e,s:t}=o;d=new g(e,t)}}f=l.fromHex(r)}catch(e){if("PARSE"===e.message)throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(c&&d.hasHighS())return!1;u&&(n=t.hash(n));const{r:h,s:p}=d,m=v(n),y=a(p),w=s(m*y),A=s(h*y),b=l.BASE.multiplyAndAddUnsafe(f,w,A)?.toAffine();return!!b&&s(b.x)===h},ProjectivePoint:l,Signature:g,utils:m}}BigInt(4);let At=class extends pe{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");se(e.outputLen),se(e.blockLen)}(e);const n=he(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,i=new Uint8Array(r);i.set(n.length>r?e.create().update(n).digest():n);for(let e=0;e<i.length;e++)i[e]^=54;this.iHash.update(i),this.oHash=e.create();for(let e=0;e<i.length;e++)i[e]^=106;this.oHash.update(i),i.fill(0)}update(e){return le(this),this.iHash.update(e),this}digestInto(e){le(this),ae(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:i,blockLen:o,outputLen:s}=this;return e.finished=r,e.destroyed=i,e.blockLen=o,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 bt=(e,t,n)=>new At(e,t).update(n).digest();
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
function kt(e){return{hash:e,hmac:(t,...n)=>bt(e,t,function(...e){const t=new Uint8Array(e.reduce((e,t)=>e+t.length,0));let n=0;return e.forEach(e=>{if(!ue(e))throw new Error("Uint8Array expected");t.set(e,n),n+=e.length}),t}(...n)),randomBytes:me}}bt.create=(e,t)=>new At(e,t);
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
const It=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),Et=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),Ct=BigInt(1),xt=BigInt(2),Bt=(e,t)=>(e+t/xt)/t;function St(e){const t=It,n=BigInt(3),r=BigInt(6),i=BigInt(11),o=BigInt(22),s=BigInt(23),a=BigInt(44),l=BigInt(88),c=e*e*e%t,u=c*c*e%t,d=nt(u,n,t)*u%t,f=nt(d,n,t)*u%t,h=nt(f,xt,t)*c%t,p=nt(h,i,t)*h%t,g=nt(p,o,t)*p%t,m=nt(g,a,t)*g%t,y=nt(m,l,t)*m%t,w=nt(y,a,t)*g%t,v=nt(w,n,t)*u%t,A=nt(v,s,t)*p%t,b=nt(A,r,t)*c%t,k=nt(b,xt,t);if(!Ft.eql(Ft.sqr(k),e))throw new Error("Cannot find square root");return k}const Ft=function(e,t,n=!1,r={}){if(e<=Ve)throw new Error(`Expected Field ORDER > 0, got ${e}`);const{nBitLength:i,nByteLength:o}=st(e,t);if(o>2048)throw new Error("Field lengths over 2048 bytes are not supported");const s=it(e),a=Object.freeze({ORDER:e,BITS:i,BYTES:o,MASK:Me(i),ZERO:Ve,ONE:qe,create:t=>et(t,e),isValid:t=>{if("bigint"!=typeof t)throw new Error("Invalid field element: expected bigint, got "+typeof t);return Ve<=t&&t<e},is0:e=>e===Ve,isOdd:e=>(e&qe)===qe,neg:t=>et(-t,e),eql:(e,t)=>e===t,sqr:t=>et(t*t,e),add:(t,n)=>et(t+n,e),sub:(t,n)=>et(t-n,e),mul:(t,n)=>et(t*n,e),pow:(e,t)=>function(e,t,n){if(n<Ve)throw new Error("Expected power > 0");if(n===Ve)return e.ONE;if(n===qe)return t;let r=e.ONE,i=t;for(;n>Ve;)n&qe&&(r=e.mul(r,i)),i=e.sqr(i),n>>=qe;return r}(a,e,t),div:(t,n)=>et(t*rt(n,e),e),sqrN:e=>e*e,addN:(e,t)=>e+t,subN:(e,t)=>e-t,mulN:(e,t)=>e*t,inv:t=>rt(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,i)=>e.is0(r)?t:(n[i]=t,e.mul(t,r)),e.ONE),i=e.inv(r);return t.reduceRight((t,r,i)=>e.is0(r)?t:(n[i]=e.mul(t,n[i]),e.mul(t,r)),i),n}(a,e),cmov:(e,t,n)=>n?t:e,toBytes:e=>n?Ne(e,o):$e(e,o),fromBytes:e=>{if(e.length!==o)throw new Error(`Fp.fromBytes: expected ${o}, got ${e.length}`);return n?Ue(e):Te(e)}});return Object.freeze(a)}(It,void 0,void 0,{sqrt:St}),Qt=function(e,t){const n=t=>vt({...e,...kt(t)});return Object.freeze({...n(t),create:n})}({a:BigInt(0),b:BigInt(7),Fp:Ft,n:Et,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:e=>{const t=Et,n=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),r=-Ct*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),i=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),o=n,s=BigInt("0x100000000000000000000000000000000"),a=Bt(o*e,t),l=Bt(-r*e,t);let c=et(e-a*n-l*i,t),u=et(-a*r-l*o,t);const d=c>s,f=u>s;if(d&&(c=t-c),f&&(u=t-u),c>s||u>s)throw new Error("splitScalar: Endomorphism failed, k="+e);return{k1neg:d,k1:c,k2neg:f,k2:u}}}},Ee),Rt=BigInt(0),Dt=e=>"bigint"==typeof e&&Rt<e&&e<It,Pt={};function Tt(e,...t){let n=Pt[e];if(void 0===n){const t=Ee(Uint8Array.from(e,e=>e.charCodeAt(0)));n=Oe(t,t),Pt[e]=n}return Ee(Oe(n,...t))}const Ut=e=>e.toRawBytes(!0).slice(1),$t=e=>$e(e,32),Nt=e=>et(e,It),Lt=e=>et(e,Et),Ot=Qt.ProjectivePoint;function Mt(e){let t=Qt.utils.normPrivateKeyToScalar(e),n=Ot.fromPrivateKey(t);return{scalar:n.hasEvenY()?t:Lt(-t),bytes:Ut(n)}}function _t(e){if(!Dt(e))throw new Error("bad x: need 0 < x < p");const t=Nt(e*e);let n=St(Nt(t*e+BigInt(7)));n%xt!==Rt&&(n=Nt(-n));const r=new Ot(e,n,Ct);return r.assertValidity(),r}function Ht(...e){return Lt(Te(Tt("BIP0340/challenge",...e)))}function jt(e){return Mt(e).bytes}function Gt(e,t,n=me(32)){const r=Le("message",e),{bytes:i,scalar:o}=Mt(t),s=Le("auxRand",n,32),a=$t(o^Te(Tt("BIP0340/aux",s))),l=Tt("BIP0340/nonce",a,i,r),c=Lt(Te(l));if(c===Rt)throw new Error("sign failed: k is zero");const{bytes:u,scalar:d}=Mt(c),f=Ht(u,i,r),h=new Uint8Array(64);if(h.set(u,0),h.set($t(Lt(d+f*o)),32),!Kt(h,r,i))throw new Error("sign: Invalid signature produced");return h}function Kt(e,t,n){const r=Le("signature",e,64),i=Le("message",t),o=Le("publicKey",n,32);try{const e=_t(Te(o)),t=Te(r.subarray(0,32));if(!Dt(t))return!1;const n=Te(r.subarray(32,64));if(!("bigint"==typeof(c=n)&&Rt<c&&c<Et))return!1;const u=Ht($t(t),Ut(e),i),d=(s=e,a=n,l=Lt(-u),Ot.BASE.multiplyAndAddUnsafe(s,a,l));return!(!d||!d.hasEvenY()||d.toAffine().x!==t)}catch(e){return!1}var s,a,l,c}const Jt=(()=>({getPublicKey:jt,sign:Gt,verify:Kt,utils:{randomPrivateKey:Qt.utils.randomPrivateKey,lift_x:_t,pointToBytes:Ut,numberToBytesBE:$e,bytesToNumberBE:Te,taggedHash:Tt,mod:et}}))(),Vt="object"==typeof globalThis&&"crypto"in globalThis?globalThis.crypto:void 0,qt=e=>e instanceof Uint8Array,zt=e=>new DataView(e.buffer,e.byteOffset,e.byteLength),Yt=(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 Wt=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Zt(e){if(!qt(e))throw new Error("Uint8Array expected");let t="";for(let n=0;n<e.length;n++)t+=Wt[e[n]];return t}function Xt(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,i=e.slice(r,r+2),o=Number.parseInt(i,16);if(Number.isNaN(o)||o<0)throw new Error("Invalid byte sequence");n[t]=o}return n}function en(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)),!qt(e))throw new Error("expected Uint8Array, got "+typeof e);return e}function tn(...e){const t=new Uint8Array(e.reduce((e,t)=>e+t.length,0));let n=0;return e.forEach(e=>{if(!qt(e))throw new Error("Uint8Array expected");t.set(e,n),n+=e.length}),t}let nn=class{clone(){return this._cloneInto()}};function rn(e){const t=t=>e().update(en(t)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function on(e=32){if(Vt&&"function"==typeof Vt.getRandomValues)return Vt.getRandomValues(new Uint8Array(e));throw new Error("crypto.getRandomValues must be defined")}function sn(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`Wrong positive integer: ${e}`)}function an(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 ln={number:sn,bool:function(e){if("boolean"!=typeof e)throw new Error(`Expected boolean, not ${e}`)},bytes:an,hash:function(e){if("function"!=typeof e||"function"!=typeof e.create)throw new Error("Hash should be wrapped by utils.wrapConstructor");sn(e.outputLen),sn(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){an(e);const n=t.outputLen;if(e.length<n)throw new Error(`digestInto() expects output buffer of length at least ${n}`)}};class cn extends nn{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=zt(this.buffer)}update(e){ln.exists(this);const{view:t,buffer:n,blockLen:r}=this,i=(e=en(e)).length;for(let o=0;o<i;){const s=Math.min(r-this.pos,i-o);if(s===r){const t=zt(e);for(;r<=i-o;o+=r)this.process(t,o);continue}n.set(e.subarray(o,o+s),this.pos),this.pos+=s,o+=s,this.pos===r&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){ln.exists(this),ln.output(e,this),this.finished=!0;const{buffer:t,view:n,blockLen:r,isLE:i}=this;let{pos:o}=this;t[o++]=128,this.buffer.subarray(o).fill(0),this.padOffset>r-o&&(this.process(n,0),o=0);for(let e=o;e<r;e++)t[e]=0;!function(e,t,n,r){if("function"==typeof e.setBigUint64)return e.setBigUint64(t,n,r);const i=BigInt(32),o=BigInt(4294967295),s=Number(n>>i&o),a=Number(n&o),l=r?4:0,c=r?0:4;e.setUint32(t+l,s,r),e.setUint32(t+c,a,r)}(n,r-8,BigInt(8*this.length),i),this.process(n,0);const s=zt(e),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const l=a/4,c=this.get();if(l>c.length)throw new Error("_sha2: outputLen bigger than state");for(let e=0;e<l;e++)s.setUint32(4*e,c[e],i)}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:i,destroyed:o,pos:s}=this;return e.length=r,e.pos=s,e.finished=i,e.destroyed=o,r%t&&e.buffer.set(n),e}}const un=(e,t,n)=>e&t^~e&n,dn=(e,t,n)=>e&t^e&n^t&n,fn=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]),hn=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),pn=new Uint32Array(64);let gn=class extends cn{constructor(){super(64,32,8,!1),this.A=0|hn[0],this.B=0|hn[1],this.C=0|hn[2],this.D=0|hn[3],this.E=0|hn[4],this.F=0|hn[5],this.G=0|hn[6],this.H=0|hn[7]}get(){const{A:e,B:t,C:n,D:r,E:i,F:o,G:s,H:a}=this;return[e,t,n,r,i,o,s,a]}set(e,t,n,r,i,o,s,a){this.A=0|e,this.B=0|t,this.C=0|n,this.D=0|r,this.E=0|i,this.F=0|o,this.G=0|s,this.H=0|a}process(e,t){for(let n=0;n<16;n++,t+=4)pn[n]=e.getUint32(t,!1);for(let e=16;e<64;e++){const t=pn[e-15],n=pn[e-2],r=Yt(t,7)^Yt(t,18)^t>>>3,i=Yt(n,17)^Yt(n,19)^n>>>10;pn[e]=i+pn[e-7]+r+pn[e-16]|0}let{A:n,B:r,C:i,D:o,E:s,F:a,G:l,H:c}=this;for(let e=0;e<64;e++){const t=c+(Yt(s,6)^Yt(s,11)^Yt(s,25))+un(s,a,l)+fn[e]+pn[e]|0,u=(Yt(n,2)^Yt(n,13)^Yt(n,22))+dn(n,r,i)|0;c=l,l=a,a=s,s=o+t|0,o=i,i=r,r=n,n=t+u|0}n=n+this.A|0,r=r+this.B|0,i=i+this.C|0,o=o+this.D|0,s=s+this.E|0,a=a+this.F|0,l=l+this.G|0,c=c+this.H|0,this.set(n,r,i,o,s,a,l,c)}roundClean(){pn.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};class mn extends gn{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 yn=rn(()=>new gn);rn(()=>new mn);var wn=Symbol("verified");function vn(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 An=new TextEncoder;function bn(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 kn=class{value;next=null;prev=null;constructor(e){this.value=e}},In=class{first;last;constructor(){this.first=null,this.last=null}enqueue(e){const t=new kn(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 En(e){return Zt(yn(An.encode(function(e){if(!vn(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 Cn=new class{generateSecretKey(){return Jt.utils.randomPrivateKey()}getPublicKey(e){return Zt(Jt.getPublicKey(e))}finalizeEvent(e,t){const n=e;return n.pubkey=Zt(Jt.getPublicKey(t)),n.id=En(n),n.sig=Zt(Jt.sign(En(n),t)),n[wn]=!0,n}verifyEvent(e){if("boolean"==typeof e[wn])return e[wn];const t=En(e);if(t!==e.id)return e[wn]=!1,!1;try{const n=Jt.verify(e.sig,t,e.pubkey);return e[wn]=n,n}catch(t){return e[wn]=!1,!1}}};Cn.generateSecretKey,Cn.getPublicKey,Cn.finalizeEvent;var xn=Cn.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 Sn(){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 Fn,Qn=e=>(e[wn]=!0,!0),Rn=class extends Error{constructor(e,t){super(`Tried to send message '${e} on a closed connection to ${t}.`),this.name="SendingOnClosedConnection"}},Dn=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 In;queueRunning=!1;challenge;authPromise;serial=0;verifyEvent;_WebSocket;constructor(e,t){this.url=bn(e),this.verifyEvent=t.verifyEvent,this._WebSocket=t.websocketImplementation||WebSocket,this.enablePing=t.enablePing}static async connect(e,t){const n=new Dn(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 Sn();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,i=e.slice(r+1,80).indexOf('"');if(-1===i)return null;let o=r+1+i;return e.slice(r+1,o)}(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,i=e.slice(r).indexOf('"')+r+1;return e.slice(i,i+64)}(e,"id"),i=n.alreadyHaveEvent?.(r);if(n.receivedEvent?.(this,r),i)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],i=this.openEventPublishes.get(e);return void(i&&(clearTimeout(i.timeout),n?i.resolve(r):i.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 Rn(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 i=await e(function(e,t){return{kind:22242,created_at:Math.floor(Date.now()/1e3),tags:[["relay",e],["challenge",t]],content:""}}(this.url,t)),o=setTimeout(()=>{let e=this.openEventPublishes.get(i.id);e&&(e.reject(new Error("auth timed out")),this.openEventPublishes.delete(i.id))},this.publishTimeout);this.openEventPublishes.set(i.id,{resolve:n,reject:r,timeout:o}),this.send('["AUTH",'+JSON.stringify(i)+"]")}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 Pn(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()}},Pn=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 Rn))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=bn(e);let n=this.relays.get(e);return n||(n=new Dn(e,{verifyEvent:this.trustedRelayURLs.has(e)?Qn: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(bn).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 i=bn(e[n]);r.find(e=>e.url===i)||r.push({url:i,filter:t})}return this.subscribeMap(r,n)}subscribeMany(e,t,n){n.onauth=n.onauth||n.doauth;const r=[],i=[];for(let n=0;n<e.length;n++){const o=bn(e[n]);-1===i.indexOf(o)&&(i.push(o),r.push({url:o,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 i=new Set,o=[],s=[];let a=n=>{s[n]||(s[n]=!0,s.filter(e=>e).length===e.length&&(t.oneose?.(),a=()=>{}))};const l=[];let c=(n,r)=>{l[n]||(a(n),l[n]=r,l.filter(e=>e).length===e.length&&(t.onclose?.(l),c=()=>{}))};const u=e=>{if(t.alreadyHaveEvent?.(e))return!0;const n=i.has(e);return i.add(e),n},d=Promise.all(r.map(async({url:e,filters:n},r)=>{let i;try{i=await this.ensureRelay(e,{connectionTimeout:t.maxWait?Math.max(.8*t.maxWait,t.maxWait-1e3):void 0})}catch(e){return void c(r,e?.message||String(e))}let s=i.subscribe(n,{...t,oneose:()=>a(r),onclose:e=>{e.startsWith("auth-required: ")&&t.onauth?i.auth(t.onauth).then(()=>{i.subscribe(n,{...t,oneose:()=>a(r),onclose:e=>{c(r,e)},alreadyHaveEvent:u,eoseTimeout:t.maxWait})}).catch(e=>{c(r,`auth was required and attempted, but failed with: ${e}`)}):c(r,e)},alreadyHaveEvent:u,eoseTimeout:t.maxWait});o.push(s)}));return{async close(e){await d,o.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 i=[];this.subscribeEose(e,t,{...n,onevent(e){i.push(e)},onclose(e){r(i)}})})}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(bn).map(async(e,r,i)=>{if(i.indexOf(e)!==r)return Promise.reject("duplicate url");let o=await this.ensureRelay(e);return o.publish(t).catch(async e=>{if(e instanceof Error&&e.message.startsWith("auth-required: ")&&n?.onauth)return await o.auth(n.onauth),o.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(o)}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{Fn=WebSocket}catch{}var Un=class extends Tn{constructor(e){super({verifyEvent:xn,websocketImplementation:Fn,...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 Nn(...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 Ln(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 On(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 Mn(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 _n(e){if("function"!=typeof e)throw new Error("normalize fn should be function");return{encode:e=>e,decode:t=>e(t)}}function Hn(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 i=[],o=Array.from(e);for(o.forEach(e=>{if($n(e),e<0||e>=t)throw new Error(`Wrong integer: ${e}`)});;){let e=0,s=!0;for(let i=r;i<o.length;i++){const a=o[i],l=t*e+a;if(!Number.isSafeInteger(l)||t*e/t!==e||l-a!==t*e)throw new Error("convertRadix: carry overflow");if(e=l%n,o[i]=Math.floor(l/n),!Number.isSafeInteger(o[i])||o[i]*n+e!==l)throw new Error("convertRadix: carry overflow");s&&(o[i]?s=!1:r=i)}if(i.push(e),s)break}for(let t=0;t<e.length-1&&0===e[t];t++)i.push(0);return i.reverse()}const jn=(e,t)=>t?jn(t,e%t):e,Gn=(e,t)=>e+(t-jn(e,t));function Kn(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(Gn(t,n)>32)throw new Error(`convertRadix2: carry overflow from=${t} to=${n} carryBits=${Gn(t,n)}`);let i=0,o=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(i=i<<t|r,o+t>32)throw new Error(`convertRadix2: carry overflow pos=${o} from=${t}`);for(o+=t;o>=n;o-=n)a.push((i>>o-n&s)>>>0);i&=2**o-1}if(i=i<<n-o&s,!r&&o>=t)throw new Error("Excess padding");if(!r&&i)throw new Error(`Non-zero padding: ${i}`);return r&&o>0&&a.push(i>>>0),a}function Jn(e,t=!1){if($n(e),e<=0||e>32)throw new Error("radix2: bits should be in (0..32]");if(Gn(8,e)>32||Gn(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 Kn(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(Kn(n,e,8,t))}}}function Vn(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 qn=Nn(Jn(4),Ln("0123456789ABCDEF"),On("")),zn=Nn(Jn(5),Ln("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"),Mn(5),On(""));Nn(Jn(5),Ln("0123456789ABCDEFGHIJKLMNOPQRSTUV"),Mn(5),On("")),Nn(Jn(5),Ln("0123456789ABCDEFGHJKMNPQRSTVWXYZ"),On(""),_n(e=>e.toUpperCase().replace(/O/g,"0").replace(/[IL]/g,"1")));const Yn=Nn(Jn(6),Ln("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),Mn(6),On("")),Wn=Nn(Jn(6),Ln("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"),Mn(6),On("")),Zn=e=>{return Nn(($n(t=58),{encode:e=>{if(!(e instanceof Uint8Array))throw new Error("radix.encode input should be Uint8Array");return Hn(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(Hn(e,t,256))}}),Ln(e),On(""));var t},Xn=Zn("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");Zn("123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"),Zn("rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz");const er=[0,2,3,5,6,7,9,10,11],tr={encode(e){let t="";for(let n=0;n<e.length;n+=8){const r=e.subarray(n,n+8);t+=Xn.encode(r).padStart(er[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),i=er.indexOf(r.length),o=Xn.decode(r);for(let e=0;e<o.length-i;e++)if(0!==o[e])throw new Error("base58xmr: wrong padding");t=t.concat(Array.from(o.slice(o.length-i)))}return Uint8Array.from(t)}},nr=Nn(Ln("qpzry9x8gf2tvdw0s3jn54khce6mua7l"),On("")),rr=[996825010,642813549,513874426,1027748829,705979059];function ir(e){const t=e>>25;let n=(33554431&e)<<5;for(let e=0;e<rr.length;e++)1==(t>>e&1)&&(n^=rr[e]);return n}function or(e,t,n=1){const r=e.length;let i=1;for(let t=0;t<r;t++){const n=e.charCodeAt(t);if(n<33||n>126)throw new Error(`Invalid prefix (${e})`);i=ir(i)^n>>5}i=ir(i);for(let t=0;t<r;t++)i=ir(i)^31&e.charCodeAt(t);for(let e of t)i=ir(i)^e;for(let e=0;e<6;e++)i=ir(i);return i^=n,nr.encode(Kn([i%2**30],30,5,!1))}function sr(e){const t="bech32"===e?1:734539939,n=Jn(5),r=n.decode,i=n.encode,o=Vn(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 i=(e=r).lastIndexOf("1");if(0===i||-1===i)throw new Error('Letter "1" must be present between prefix and data only');const o=e.slice(0,i),s=e.slice(i+1);if(s.length<6)throw new Error("Data must be at least 6 characters long");const a=nr.decode(s).slice(0,-6),l=or(o,a,t);if(!s.endsWith(l))throw new Error(`Invalid checksum in ${e}: expected "${l}"`);return{prefix:o,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 i=e.length+7+n.length;if(!1!==r&&i>r)throw new TypeError(`Length ${i} exceeds limit ${r}`);return`${e=e.toLowerCase()}1${nr.encode(n)}${or(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:Vn(s),fromWords:r,fromWordsUnsafe:o,toWords:i}}const ar=sr("bech32");sr("bech32m");const lr={utf8:{encode:e=>(new TextDecoder).decode(e),decode:e=>(new TextEncoder).encode(e)},hex:Nn(Jn(4),Ln("0123456789abcdef"),On(""),_n(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:qn,base32:zn,base64:Yn,base64url:Wn,base58:Xn,base58xmr:tr};function cr(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`positive integer expected, not ${e}`)}function ur(e){if("boolean"!=typeof e)throw new Error(`boolean expected, not ${e}`)}function dr(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(lr).join(", ");const fr=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 hr=16;function pr(e){return e<<1^283&-(e>>7)}function gr(e,t){let n=0;for(;t>0;t>>=1)n^=e&-(1&t),e=pr(e);return n}const mr=(()=>{let e=new Uint8Array(256);for(let t=0,n=1;t<256;t++,n^=pr(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})(),yr=mr.map((e,t)=>mr.indexOf(t)),wr=e=>e<<24|e>>>8,vr=e=>e<<8|e>>>24;function Ar(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(vr),i=r.map(vr),o=i.map(vr),s=new Uint32Array(65536),a=new Uint32Array(65536),l=new Uint16Array(65536);for(let t=0;t<256;t++)for(let c=0;c<256;c++){const u=256*t+c;s[u]=n[t]^r[c],a[u]=i[t]^o[c],l[u]=e[t]<<8|e[c]}return{sbox:e,sbox2:l,T0:n,T1:r,T2:i,T3:o,T01:s,T23:a}}const br=Ar(mr,e=>gr(e,3)<<24|e<<16|e<<8|gr(e,2)),kr=Ar(yr,e=>gr(e,11)<<24|gr(e,13)<<16|gr(e,9)<<8|gr(e,14)),Ir=(()=>{const e=new Uint8Array(16);for(let t=0,n=1;t<16;t++,n=pr(n))e[t]=n;return e})();function Er(e){dr(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}=br,r=fr(e),i=r.length,o=e=>xr(n,e,e,e,e),s=new Uint32Array(t+28);s.set(r);for(let e=i;e<s.length;e++){let t=s[e-1];e%i===0?t=o(wr(t))^Ir[e/i-1]:i>6&&e%i===4&&(t=o(t)),s[e]=s[e-i]^t}return s}function Cr(e,t,n,r,i,o){return e[n<<8&65280|r>>>8&255]^t[i>>>8&65280|o>>>24&255]}function xr(e,t,n,r,i){return e[255&t|65280&n]|e[r>>>16&255|i>>>16&65280]<<16}function Br(e,t,n,r,i){const{sbox2:o,T01:s,T23:a}=br;let l=0;t^=e[l++],n^=e[l++],r^=e[l++],i^=e[l++];const c=e.length/4-2;for(let o=0;o<c;o++){const o=e[l++]^Cr(s,a,t,n,r,i),c=e[l++]^Cr(s,a,n,r,i,t),u=e[l++]^Cr(s,a,r,i,t,n),d=e[l++]^Cr(s,a,i,t,n,r);t=o,n=c,r=u,i=d}return{s0:e[l++]^xr(o,t,n,r,i),s1:e[l++]^xr(o,n,r,i,t),s2:e[l++]^xr(o,r,i,t,n),s3:e[l++]^xr(o,i,t,n,r)}}function Sr(e,t,n,r,i){const{sbox2:o,T01:s,T23:a}=kr;let l=0;t^=e[l++],n^=e[l++],r^=e[l++],i^=e[l++];const c=e.length/4-2;for(let o=0;o<c;o++){const o=e[l++]^Cr(s,a,t,i,r,n),c=e[l++]^Cr(s,a,n,t,i,r),u=e[l++]^Cr(s,a,r,n,t,i),d=e[l++]^Cr(s,a,i,r,n,t);t=o,n=c,r=u,i=d}return{s0:e[l++]^xr(o,t,i,r,n),s1:e[l++]^xr(o,n,t,i,r),s2:e[l++]^xr(o,r,n,t,i),s3:e[l++]^xr(o,i,r,n,t)}}function Fr(e,t){if(!t)return new Uint8Array(e);if(dr(t),t.length<e)throw new Error(`aes: wrong destination length, expected at least ${e}, got: ${t.length}`);return t}const Qr=(Rr={blockSize:16,nonceLength:16},Dr=function(e,t,n={}){dr(e),dr(t,16);const r=!n.disablePadding;return{encrypt:(n,i)=>{const o=Er(e),{b:s,o:a,out:l}=function(e,t,n){let r=e.length;const i=r%hr;if(!t&&0!==i)throw new Error("aec/(cbc-ecb): unpadded plaintext with disabled padding");const o=fr(e);if(t){let e=hr-i;e||(e=hr),r+=e}const s=Fr(r,n);return{b:o,o:fr(s),out:s}}(n,r,i),c=fr(t);let u=c[0],d=c[1],f=c[2],h=c[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(o,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=fr(t);t.set(e);const r=hr-e.length;for(let e=hr-r;e<hr;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(o,u,d,f,h)),a[p++]=u,a[p++]=d,a[p++]=f,a[p++]=h}return o.fill(0),l},decrypt:(n,i)=>{!function(e){if(dr(e),e.length%hr!==0)throw new Error("aes/(cbc-ecb).decrypt ciphertext should consist of blocks with size 16")}(n);const o=function(e){const t=Er(e),n=t.slice(),r=t.length,{sbox2:i}=br,{T0:o,T1:s,T2:a,T3:l}=kr;for(let e=0;e<r;e+=4)for(let i=0;i<4;i++)n[e+i]=t[r-e-4+i];t.fill(0);for(let e=4;e<r-4;e++){const t=n[e],r=xr(i,t,t,t,t);n[e]=o[255&r]^s[r>>>8&255]^a[r>>>16&255]^l[r>>>24]}return n}(e),s=fr(t),a=Fr(n.length,i),l=fr(n),c=fr(a);let u=s[0],d=s[1],f=s[2],h=s[3];for(let e=0;e+4<=l.length;){const t=u,n=d,r=f,i=h;u=l[e+0],d=l[e+1],f=l[e+2],h=l[e+3];const{s0:s,s1:a,s2:p,s3:g}=Sr(o,u,d,f,h);c[e++]=s^t,c[e++]=a^n,c[e++]=p^r,c[e++]=g^i}return o.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 i=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 i}(a,r)}}},Object.assign(Dr,Rr),Dr);var Rr,Dr;const Pr=e=>Uint8Array.from(e.split("").map(e=>e.charCodeAt(0))),Tr=Pr("expand 16-byte k"),Ur=Pr("expand 32-byte k"),$r=fr(Tr),Nr=fr(Ur);function Lr(e,t){return e<<t|e>>>32-t}function Or(e){return e.byteOffset%4==0}Nr.slice();const Mr=2**32-1,_r=new Uint32Array;function Hr(e,t){const{allowShortKeys:n,extendNonceFn:r,counterLength:i,counterRight:o,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 cr(i),cr(s),ur(o),ur(n),(t,a,l,c,u=0)=>{dr(t),dr(a),dr(l);const d=l.length;if(c||(c=new Uint8Array(d)),dr(c),cr(u),u<0||u>=Mr)throw new Error("arx: counter overflow");if(c.length<d)throw new Error(`arx: output (${c.length}) is shorter than data (${d})`);const f=[];let h,p,g=t.length;if(32===g)h=t.slice(),f.push(h),p=Nr;else{if(16!==g||!n)throw new Error(`arx: invalid 32-byte key, got length=${g}`);h=new Uint8Array(32),h.set(t),h.set(t,16),p=$r,f.push(h)}Or(a)||(a=a.slice(),f.push(a));const m=fr(h);if(r){if(24!==a.length)throw new Error("arx: extended nonce must be 24 bytes");r(p,m,fr(a.subarray(0,16)),m),a=a.subarray(16)}const y=16-i;if(y!==a.length)throw new Error(`arx: nonce must be ${y} or 16 bytes`);if(12!==y){const e=new Uint8Array(12);e.set(a,o?0:12-a.length),a=e,f.push(a)}const w=fr(a);for(!function(e,t,n,r,i,o,s,a){const l=i.length,c=new Uint8Array(64),u=fr(c),d=Or(i)&&Or(o),f=d?fr(i):_r,h=d?fr(o):_r;for(let p=0;p<l;s++){if(e(t,n,r,u,s,a),s>=Mr)throw new Error("arx: counter overflow");const g=Math.min(64,l-p);if(d&&64===g){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<g;t++)e=p+t,o[e]=i[e]^c[t];p+=g}}(e,p,m,w,l,c,u,s);f.length>0;)f.pop().fill(0);return c}}function jr(e,t,n,r,i,o=20){let s=e[0],a=e[1],l=e[2],c=e[3],u=t[0],d=t[1],f=t[2],h=t[3],p=t[4],g=t[5],m=t[6],y=t[7],w=i,v=n[0],A=n[1],b=n[2],k=s,I=a,E=l,C=c,x=u,B=d,S=f,F=h,Q=p,R=g,D=m,P=y,T=w,U=v,$=A,N=b;for(let e=0;e<o;e+=2)k=k+x|0,T=Lr(T^k,16),Q=Q+T|0,x=Lr(x^Q,12),k=k+x|0,T=Lr(T^k,8),Q=Q+T|0,x=Lr(x^Q,7),I=I+B|0,U=Lr(U^I,16),R=R+U|0,B=Lr(B^R,12),I=I+B|0,U=Lr(U^I,8),R=R+U|0,B=Lr(B^R,7),E=E+S|0,$=Lr($^E,16),D=D+$|0,S=Lr(S^D,12),E=E+S|0,$=Lr($^E,8),D=D+$|0,S=Lr(S^D,7),C=C+F|0,N=Lr(N^C,16),P=P+N|0,F=Lr(F^P,12),C=C+F|0,N=Lr(N^C,8),P=P+N|0,F=Lr(F^P,7),k=k+B|0,N=Lr(N^k,16),D=D+N|0,B=Lr(B^D,12),k=k+B|0,N=Lr(N^k,8),D=D+N|0,B=Lr(B^D,7),I=I+S|0,T=Lr(T^I,16),P=P+T|0,S=Lr(S^P,12),I=I+S|0,T=Lr(T^I,8),P=P+T|0,S=Lr(S^P,7),E=E+F|0,U=Lr(U^E,16),Q=Q+U|0,F=Lr(F^Q,12),E=E+F|0,U=Lr(U^E,8),Q=Q+U|0,F=Lr(F^Q,7),C=C+x|0,$=Lr($^C,16),R=R+$|0,x=Lr(x^R,12),C=C+x|0,$=Lr($^C,8),R=R+$|0,x=Lr(x^R,7);let L=0;r[L++]=s+k|0,r[L++]=a+I|0,r[L++]=l+E|0,r[L++]=c+C|0,r[L++]=u+x|0,r[L++]=d+B|0,r[L++]=f+S|0,r[L++]=h+F|0,r[L++]=p+Q|0,r[L++]=g+R|0,r[L++]=m+D|0,r[L++]=y+P|0,r[L++]=w+T|0,r[L++]=v+U|0,r[L++]=A+$|0,r[L++]=b+N|0}const Gr=Hr(jr,{counterRight:!1,counterLength:4,allowShortKeys:!1});let Kr=class extends nn{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,ln.hash(e);const n=en(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,i=new Uint8Array(r);i.set(n.length>r?e.create().update(n).digest():n);for(let e=0;e<i.length;e++)i[e]^=54;this.iHash.update(i),this.oHash=e.create();for(let e=0;e<i.length;e++)i[e]^=106;this.oHash.update(i),i.fill(0)}update(e){return ln.exists(this),this.iHash.update(e),this}digestInto(e){ln.exists(this),ln.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:i,blockLen:o,outputLen:s}=this;return e.finished=r,e.destroyed=i,e.blockLen=o,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 Jr=(e,t,n)=>new Kr(e,t).update(n).digest();Jr.create=(e,t)=>new Kr(e,t);const Vr=new Uint8Array([0]),qr=new Uint8Array;var zr=Object.defineProperty,Yr=(e,t)=>{for(var n in t)zr(e,n,{get:t[n],enumerable:!0})},Wr=Symbol("verified");function Zr(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}Yr({},{Queue:()=>si,QueueNode:()=>oi,binarySearch:()=>ii,bytesToHex:()=>Zt,hexToBytes:()=>Xt,insertEventIntoAscendingList:()=>ri,insertEventIntoDescendingList:()=>ni,normalizeURL:()=>ti,utf8Decoder:()=>Xr,utf8Encoder:()=>ei});var Xr=new TextDecoder("utf-8"),ei=new TextEncoder;function ti(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 ni(e,t){const[n,r]=ii(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 ri(e,t){const[n,r]=ii(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 ii(e,t){let n=0,r=e.length-1;for(;n<=r;){const i=Math.floor((n+r)/2),o=t(e[i]);if(0===o)return[i,!0];o<0?r=i-1:n=i+1}return[n,!1]}var oi=class{value;next=null;prev=null;constructor(e){this.value=e}},si=class{first;last;constructor(){this.first=null,this.last=null}enqueue(e){const t=new oi(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 ai(e){return Zt(yn(ei.encode(function(e){if(!Zr(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 li=new class{generateSecretKey(){return Jt.utils.randomPrivateKey()}getPublicKey(e){return Zt(Jt.getPublicKey(e))}finalizeEvent(e,t){const n=e;return n.pubkey=Zt(Jt.getPublicKey(t)),n.id=ai(n),n.sig=Zt(Jt.sign(ai(n),t)),n[Wr]=!0,n}verifyEvent(e){if("boolean"==typeof e[Wr])return e[Wr];const t=ai(e);if(t!==e.id)return e[Wr]=!1,!1;try{const n=Jt.verify(e.sig,t,e.pubkey);return e[Wr]=n,n}catch(t){return e[Wr]=!1,!1}}},ci=li.generateSecretKey,ui=li.getPublicKey,di=li.finalizeEvent,fi=li.verifyEvent,hi={};function pi(e){return 1e3<=e&&e<1e4||[1,2,4,5,6,7,8,16,40,41,42,43,44].includes(e)}function gi(e){return[0,3].includes(e)||1e4<=e&&e<2e4}function mi(e){return 2e4<=e&&e<3e4}function yi(e){return 3e4<=e&&e<4e4}function wi(e){return pi(e)?"regular":gi(e)?"replaceable":mi(e)?"ephemeral":yi(e)?"parameterized":"unknown"}function vi(e,t){const n=t instanceof Array?t:[t];return Zr(e)&&n.includes(e.kind)||!1}Yr(hi,{Application:()=>Do,BadgeAward:()=>Si,BadgeDefinition:()=>Co,BlockedRelaysList:()=>oo,BookmarkList:()=>no,Bookmarksets:()=>ko,Calendar:()=>Oo,CalendarEventRSVP:()=>Mo,ChannelCreation:()=>Di,ChannelHideMessage:()=>Ui,ChannelMessage:()=>Ti,ChannelMetadata:()=>Pi,ChannelMuteUser:()=>$i,ClassifiedListing:()=>Uo,ClientAuth:()=>po,CommunitiesList:()=>ro,CommunityDefinition:()=>jo,CommunityPostApproval:()=>Ki,Contacts:()=>Ii,CreateOrUpdateProduct:()=>So,CreateOrUpdateStall:()=>Bo,Curationsets:()=>Io,Date:()=>No,DirectMessageRelaysList:()=>co,DraftClassifiedListing:()=>$o,DraftLong:()=>Qo,Emojisets:()=>Ro,EncryptedDirectMessage:()=>Ei,EventDeletion:()=>Ci,FileMetadata:()=>Oi,FileServerPreference:()=>uo,Followsets:()=>vo,GenericRepost:()=>Ri,Genericlists:()=>Ao,GiftWrap:()=>Li,HTTPAuth:()=>wo,Handlerinformation:()=>Ho,Handlerrecommendation:()=>_o,Highlights:()=>Zi,InterestsList:()=>ao,Interestsets:()=>xo,JobFeedback:()=>qi,JobRequest:()=>Ji,JobResult:()=>Vi,Label:()=>Gi,LightningPubRPC:()=>ho,LiveChatMessage:()=>Mi,LiveEvent:()=>Po,LongFormArticle:()=>Fo,Metadata:()=>Ai,Mutelist:()=>Xi,NWCWalletInfo:()=>fo,NWCWalletRequest:()=>go,NWCWalletResponse:()=>mo,NostrConnect:()=>yo,OpenTimestamps:()=>Ni,Pinlist:()=>eo,PrivateDirectMessage:()=>Qi,ProblemTracker:()=>_i,ProfileBadges:()=>Eo,PublicChatsList:()=>io,Reaction:()=>Bi,RecommendRelay:()=>ki,RelayList:()=>to,Relaysets:()=>bo,Report:()=>Hi,Reporting:()=>ji,Repost:()=>xi,Seal:()=>Fi,SearchRelaysList:()=>so,ShortTextNote:()=>bi,Time:()=>Lo,UserEmojiList:()=>lo,UserStatuses:()=>To,Zap:()=>Wi,ZapGoal:()=>zi,ZapRequest:()=>Yi,classifyKind:()=>wi,isAddressableKind:()=>yi,isEphemeralKind:()=>mi,isKind:()=>vi,isRegularKind:()=>pi,isReplaceableKind:()=>gi});var Ai=0,bi=1,ki=2,Ii=3,Ei=4,Ci=5,xi=6,Bi=7,Si=8,Fi=13,Qi=14,Ri=16,Di=40,Pi=41,Ti=42,Ui=43,$i=44,Ni=1040,Li=1059,Oi=1063,Mi=1311,_i=1971,Hi=1984,ji=1984,Gi=1985,Ki=4550,Ji=5999,Vi=6999,qi=7e3,zi=9041,Yi=9734,Wi=9735,Zi=9802,Xi=1e4,eo=10001,to=10002,no=10003,ro=10004,io=10005,oo=10006,so=10007,ao=10015,lo=10030,co=10050,uo=10096,fo=13194,ho=21e3,po=22242,go=23194,mo=23195,yo=24133,wo=27235,vo=3e4,Ao=30001,bo=30002,ko=30003,Io=30004,Eo=30008,Co=30009,xo=30015,Bo=30017,So=30018,Fo=30023,Qo=30024,Ro=30030,Do=30078,Po=30311,To=30315,Uo=30402,$o=30403,No=31922,Lo=31923,Oo=31924,Mo=31925,_o=31989,Ho=31990,jo=34550;function Go(e,t){let n=t.length+3,r=e.indexOf(`"${t}":`)+n,i=e.slice(r).indexOf('"')+r+1;return e.slice(i,i+64)}function Ko(e,t){let n=t.length,r=e.indexOf(`"${t}":`)+n+3,i=e.slice(r),o=Math.min(i.indexOf(","),i.indexOf("}"));return parseInt(i.slice(0,o),10)}function Jo(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,i=e.slice(r+1,80).indexOf('"');if(-1===i)return null;let o=r+1+i;return e.slice(r+1,o)}function Vo(e,t){return t===Go(e,"id")}function qo(e,t){return t===Go(e,"pubkey")}function zo(e,t){return t===Ko(e,"kind")}Yr({},{getHex64:()=>Go,getInt:()=>Ko,getSubscriptionId:()=>Jo,matchEventId:()=>Vo,matchEventKind:()=>zo,matchEventPubkey:()=>qo});function Yo(e,t){return{kind:po,created_at:Math.floor(Date.now()/1e3),tags:[["relay",e],["challenge",t]],content:""}}Yr({},{makeAuthEvent:()=>Yo});try{WebSocket}catch{}try{WebSocket}catch{}var Wo={};Yr(Wo,{BECH32_REGEX:()=>es,Bech32MaxSize:()=>Xo,NostrTypeGuard:()=>Zo,decode:()=>ns,decodeNostrURI:()=>ts,encodeBytes:()=>ls,naddrEncode:()=>ds,neventEncode:()=>us,noteEncode:()=>ss,nprofileEncode:()=>cs,npubEncode:()=>os,nsecEncode:()=>is});var Zo={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||"")},Xo=5e3,es=/[\x21-\x7E]{1,83}1[023456789acdefghjklmnpqrstuvwxyz]{6,}/;function ts(e){try{return e.startsWith("nostr:")&&(e=e.substring(6)),ns(e)}catch(e){return{type:"invalid",data:null}}}function ns(e){let{prefix:t,words:n}=ar.decode(e,Xo),r=new Uint8Array(ar.fromWords(n));switch(t){case"nprofile":{let e=rs(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:Zt(e[0][0]),relays:e[1]?e[1].map(e=>Xr.decode(e)):[]}}}case"nevent":{let e=rs(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:Zt(e[0][0]),relays:e[1]?e[1].map(e=>Xr.decode(e)):[],author:e[2]?.[0]?Zt(e[2][0]):void 0,kind:e[3]?.[0]?parseInt(Zt(e[3][0]),16):void 0}}}case"naddr":{let e=rs(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:Xr.decode(e[0][0]),pubkey:Zt(e[2][0]),kind:parseInt(Zt(e[3][0]),16),relays:e[1]?e[1].map(e=>Xr.decode(e)):[]}}}case"nsec":return{type:t,data:r};case"npub":case"note":return{type:t,data:Zt(r)};default:throw new Error(`unknown prefix ${t}`)}}function rs(e){let t={},n=e;for(;n.length>0;){let e=n[0],r=n[1],i=n.slice(2,2+r);if(n=n.slice(2+r),i.length<r)throw new Error(`not enough data to read on TLV ${e}`);t[e]=t[e]||[],t[e].push(i)}return t}function is(e){return ls("nsec",e)}function os(e){return ls("npub",Xt(e))}function ss(e){return ls("note",Xt(e))}function as(e,t){let n=ar.toWords(t);return ar.encode(e,n,Xo)}function ls(e,t){return as(e,t)}function cs(e){return as("nprofile",fs({0:[Xt(e.pubkey)],1:(e.relays||[]).map(e=>ei.encode(e))}))}function us(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)),as("nevent",fs({0:[Xt(e.id)],1:(e.relays||[]).map(e=>ei.encode(e)),2:e.author?[Xt(e.author)]:[],3:t?[new Uint8Array(t)]:[]}))}function ds(e){let t=new ArrayBuffer(4);return new DataView(t).setUint32(0,e.kind,!1),as("naddr",fs({0:[ei.encode(e.identifier)],1:(e.relays||[]).map(e=>ei.encode(e)),2:[Xt(e.pubkey)],3:[new Uint8Array(t)]}))}function fs(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)})}),tn(...t)}var hs={};function ps(e,t,n){const r=e instanceof Uint8Array?Zt(e):e,i=ms(Qt.getSharedSecret(r,"02"+t));let o=Uint8Array.from(on(16)),s=ei.encode(n),a=Qr(i,o).encrypt(s);return`${Yn.encode(new Uint8Array(a))}?iv=${Yn.encode(new Uint8Array(o.buffer))}`}function gs(e,t,n){const r=e instanceof Uint8Array?Zt(e):e;let[i,o]=n.split("?iv="),s=ms(Qt.getSharedSecret(r,"02"+t)),a=Yn.decode(o),l=Yn.decode(i),c=Qr(s,a).decrypt(l);return Xr.decode(c)}function ms(e){return e.slice(1,33)}Yr(hs,{decrypt:()=>gs,encrypt:()=>ps});Yr({},{NIP05_REGEX:()=>ws,isNip05:()=>vs,isValid:()=>Is,queryProfile:()=>ks,searchDomain:()=>bs,useFetchImplementation:()=>As});var ys,ws=/^(?:([\w.+-]+)@)?([\w_-]+(\.[\w_-]+)+)$/,vs=e=>ws.test(e||"");try{ys=fetch}catch(e){}function As(e){ys=e}async function bs(e,t=""){try{const n=`https://${e}/.well-known/nostr.json?name=${t}`,r=await ys(n,{redirect:"manual"});if(200!==r.status)throw Error("Wrong response code");return(await r.json()).names}catch(e){return{}}}async function ks(e){const t=e.match(ws);if(!t)return null;const[,n="_",r]=t;try{const e=`https://${r}/.well-known/nostr.json?name=${n}`,t=await ys(e,{redirect:"manual"});if(200!==t.status)throw Error("Wrong response code");const i=await t.json(),o=i.names[n];return o?{pubkey:o,relays:i.relays?.[o]}:null}catch(e){return null}}async function Is(e,t){const n=await ks(t);return!!n&&n.pubkey===e}function Es(e){const t={reply:void 0,root:void 0,mentions:[],profiles:[],quotes:[]};let n,r;for(let i=e.tags.length-1;i>=0;i--){const o=e.tags[i];if("e"===o[0]&&o[1]){const[e,i,s,a,l]=o,c={id:i,relays:s?[s]:[],author:l};if("root"===a){t.root=c;continue}if("reply"===a){t.reply=c;continue}if("mention"===a){t.mentions.push(c);continue}n?r=c:n=c,t.mentions.push(c);continue}if("q"===o[0]&&o[1]){const[e,n,r]=o;t.quotes.push({id:n,relays:r?[r]:[]})}"p"===o[0]&&o[1]&&t.profiles.push({pubkey:o[1],relays:o[2]?[o[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}Yr({},{parse:()=>Es});Yr({},{fetchRelayInformation:()=>xs,useFetchImplementation:()=>Cs});try{fetch}catch{}function Cs(e){0}async function xs(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 Ss(e,t){let n=0;const r=e,i=["nonce",n.toString(),t.toString()];for(r.tags.push(i);;){const e=Math.floor((new Date).getTime()/1e3);if(e!==r.created_at&&(n=0,r.created_at=e),i[1]=(++n).toString(),r.id=Fs(r),Bs(r.id)>=t)break}return r}function Fs(e){return Zt(yn(ei.encode(JSON.stringify([0,e.pubkey,e.created_at,e.kind,e.tags,e.content]))))}Yr({},{fastEventHash:()=>Fs,getPow:()=>Bs,minePow:()=>Ss});Yr({},{unwrapEvent:()=>ta,unwrapManyEvents:()=>na,wrapEvent:()=>Xs,wrapManyEvents:()=>ea});Yr({},{createRumor:()=>Js,createSeal:()=>Vs,createWrap:()=>qs,unwrapEvent:()=>Ws,unwrapManyEvents:()=>Zs,wrapEvent:()=>zs,wrapManyEvents:()=>Ys});var Qs={};Yr(Qs,{decrypt:()=>Os,encrypt:()=>Ls,getConversationKey:()=>Ps,v2:()=>Ms});var Rs=1,Ds=65535;function Ps(e,t){const n=Qt.getSharedSecret(e,"02"+t).subarray(1,33);return function(e,t,n){return ln.hash(e),void 0===n&&(n=new Uint8Array(e.outputLen)),Jr(e,en(n),en(t))}(yn,n,"nip44-v2")}function Ts(e,t){const n=function(e,t,n,r=32){if(ln.hash(e),ln.number(r),r>255*e.outputLen)throw new Error("Length should be <= 255*HashLen");const i=Math.ceil(r/e.outputLen);void 0===n&&(n=qr);const o=new Uint8Array(i*e.outputLen),s=Jr.create(e,t),a=s._cloneInto(),l=new Uint8Array(s.outputLen);for(let t=0;t<i;t++)Vr[0]=t+1,a.update(0===t?qr:l).update(n).update(Vr).digestInto(l),o.set(l,e.outputLen*t),s._cloneInto(a);return s.destroy(),a.destroy(),l.fill(0),Vr.fill(0),o.slice(0,r)}(yn,e,t,76);return{chacha_key:n.subarray(0,32),chacha_nonce:n.subarray(32,44),hmac_key:n.subarray(44,76)}}function Us(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=ei.encode(e),n=t.length;return tn(function(e){if(!Number.isSafeInteger(e)||e<Rs||e>Ds)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(Us(n)-n))}function Ns(e,t,n){if(32!==n.length)throw new Error("AAD associated data must be 32 bytes");const r=tn(n,t);return Jr(yn,e,r)}function Ls(e,t,n=on(32)){const{chacha_key:r,chacha_nonce:i,hmac_key:o}=Ts(t,n),s=$s(e),a=Gr(r,i,s),l=Ns(o,a,n);return Yn.encode(tn(new Uint8Array([2]),n,a,l))}function Os(e,t){const{nonce:n,ciphertext:r,mac:i}=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=Yn.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 i=n[0];if(2!==i)throw new Error("unknown encryption version "+i);return{nonce:n.subarray(1,33),ciphertext:n.subarray(33,-32),mac:n.subarray(-32)}}(e),{chacha_key:o,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}(Ns(a,r,n),i))throw new Error("invalid MAC");return function(e){const t=new DataView(e.buffer).getUint16(0),n=e.subarray(2,2+t);if(t<Rs||t>Ds||n.length!==t||e.length!==2+Us(t))throw new Error("invalid padding");return Xr.decode(n)}(Gr(o,s,r))}var Ms={utils:{getConversationKey:Ps,calcPaddedLen:Us},encrypt:Ls,decrypt:Os},_s=()=>Math.round(Date.now()/1e3),Hs=()=>Math.round(_s()-172800*Math.random()),js=(e,t)=>Ps(e,t),Gs=(e,t,n)=>Ls(JSON.stringify(e),js(t,n)),Ks=(e,t)=>JSON.parse(Os(e.content,js(t,e.pubkey)));function Js(e,t){const n={created_at:_s(),content:"",tags:[],...e,pubkey:ui(t)};return n.id=ai(n),n}function Vs(e,t,n){return di({kind:Fi,content:Gs(e,t,n),created_at:Hs(),tags:[]},t)}function qs(e,t){const n=ci();return di({kind:Li,content:Gs(e,n,t),created_at:Hs(),tags:[["p",t]]},n)}function zs(e,t,n){return qs(Vs(Js(e,t),t,n),n)}function Ys(e,t,n){if(!n||0===n.length)throw new Error("At least one recipient is required.");const r=ui(t),i=[zs(e,t,r)];return n.forEach(n=>{i.push(zs(e,t,n))}),i}function Ws(e,t){const n=Ks(e,t);return Ks(n,t)}function Zs(e,t){let n=[];return e.forEach(e=>{n.push(Ws(e,t))}),n.sort((e,t)=>e.created_at-t.created_at),n}function Xs(e,t,n,r,i){const o=function(e,t,n,r){const i={created_at:Math.ceil(Date.now()/1e3),kind:Qi,tags:[],content:t};return(Array.isArray(e)?e:[e]).forEach(({publicKey:e,relayUrl:t})=>{i.tags.push(t?["p",e,t]:["p",e])}),r&&i.tags.push(["e",r.eventId,r.relayUrl||"","reply"]),n&&i.tags.push(["subject",n]),i}(t,n,r,i);return zs(o,e,t.publicKey)}function ea(e,t,n,r,i){if(!t||0===t.length)throw new Error("At least one recipient is required.");return[{publicKey:ui(e)},...t].map(t=>Xs(e,t,n,r,i))}var ta=Ws,na=Zs;function ra(e,t,n,r){let i;const o=[...e.tags??[],["e",t.id,n],["p",t.pubkey]];return t.kind===bi?i=xi:(i=Ri,o.push(["k",String(t.kind)])),di({kind:i,tags:o,content:""===e.content||t.tags?.find(e=>"-"===e[0])?"":JSON.stringify(t),created_at:e.created_at},r)}function ia(e){if(![xi,Ri].includes(e.kind))return;let t,n;for(let r=e.tags.length-1;r>=0&&(void 0===t||void 0===n);r--){const i=e.tags[r];i.length>=2&&("e"===i[0]&&void 0===t?t=i:"p"===i[0]&&void 0===n&&(n=i))}return void 0!==t?{id:t[1],relays:[t[2],n?.[2]].filter(e=>"string"==typeof e),author:n?.[1]}:void 0}function oa(e,{skipVerification:t}={}){const n=ia(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||fi(r))?r:void 0}Yr({},{finishRepostEvent:()=>ra,getRepostedEvent:()=>oa,getRepostedEventPointer:()=>ia});Yr({},{NOSTR_URI_REGEX:()=>sa,parse:()=>la,test:()=>aa});var sa=new RegExp(`nostr:(${es.source})`);function aa(e){return"string"==typeof e&&new RegExp(`^${sa.source}$`).test(e)}function la(e){const t=e.match(new RegExp(`^${sa.source}$`));if(!t)throw new Error(`Invalid Nostr URI: ${e}`);return{uri:t[0],value:t[1],decoded:ns(t[1])}}function ca(e,t,n){const r=t.tags.filter(e=>e.length>=2&&("e"===e[0]||"p"===e[0]));return di({...e,kind:Bi,tags:[...e.tags??[],...r,["e",t.id],["p",t.pubkey]],content:e.content??"+"},n)}function ua(e){if(e.kind!==Bi)return;let t,n;for(let r=e.tags.length-1;r>=0&&(void 0===t||void 0===n);r--){const i=e.tags[r];i.length>=2&&("e"===i[0]&&void 0===t?t=i:"p"===i[0]&&void 0===n&&(n=i))}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}Yr({},{finishReactionEvent:()=>ca,getReactedEventPointer:()=>ua});Yr({},{parse:()=>ha});var da=/\W/m,fa=/\W |\W$|$|,| /m;function*ha(e){const t=e.length;let n=0,r=0;for(;r<t;){let i=e.indexOf(":",r);if(-1===i)break;if("nostr"===e.substring(i-5,i)){const o=e.substring(i+60).match(da),s=o?i+60+o.index:t;try{let t,{data:o,type:a}=ns(e.substring(i+1,s));switch(a){case"npub":t={pubkey:o};break;case"nsec":case"note":r=s+1;continue;default:t=o}n!==i-5&&(yield{type:"text",text:e.substring(n,i-5)}),yield{type:"reference",pointer:t},r=s,n=r;continue}catch(e){r=i+1;continue}}else if("https"===e.substring(i-5,i)||"http"===e.substring(i-4,i)){const o=e.substring(i+4).match(fa),s=o?i+4+o.index:t,a="s"===e[i-1]?5:4;try{let t=new URL(e.substring(i-a,s));if(-1===t.hostname.indexOf("."))throw new Error("invalid url");if(n!==i-a&&(yield{type:"text",text:e.substring(n,i-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(i-3,i)&&"ws"!==e.substring(i-2,i)){r=i+1;continue}{const o=e.substring(i+4).match(fa),s=o?i+4+o.index:t,a="s"===e[i-1]?3:2;try{let t=new URL(e.substring(i-a,s));if(-1===t.hostname.indexOf("."))throw new Error("invalid ws url");n!==i-a&&(yield{type:"text",text:e.substring(n,i-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)})}Yr({},{channelCreateEvent:()=>pa,channelHideMessageEvent:()=>ya,channelMessageEvent:()=>ma,channelMetadataEvent:()=>ga,channelMuteUserEvent:()=>wa});var pa=(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 di({kind:Di,tags:[...e.tags??[]],content:n,created_at:e.created_at},t)},ga=(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 di({kind:Pi,tags:[["e",e.channel_create_event_id],...e.tags??[]],content:n,created_at:e.created_at},t)},ma=(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"]),di({kind:Ti,tags:[...n,...e.tags??[]],content:e.content,created_at:e.created_at},t)},ya=(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 di({kind:Ui,tags:[["e",e.channel_message_event_id],...e.tags??[]],content:n,created_at:e.created_at},t)},wa=(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 di({kind:$i,tags:[["p",e.pubkey_to_mute],...e.tags??[]],content:n,created_at:e.created_at},t)};Yr({},{EMOJI_SHORTCODE_REGEX:()=>va,matchAll:()=>ba,regex:()=>Aa,replaceAll:()=>ka});var va=/:(\w+):/,Aa=()=>new RegExp(`\\B${va.source}\\B`,"g");function*ba(e){const t=e.matchAll(Aa());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 ka(e,t){return e.replaceAll(Aa(),(e,n)=>t({shortcode:e,name:n}))}var Ia;Yr({},{useFetchImplementation:()=>Ea,validateGithub:()=>Ca});try{Ia=fetch}catch{}function Ea(e){Ia=e}async function Ca(e,t,n){try{return await(await Ia(`https://gist.github.com/${t}/${n}/raw`)).text()===`Verifying that I control the following Nostr public key: ${e}`}catch(e){return!1}}function xa(e){const{host:t,pathname:n,searchParams:r}=new URL(e),i=n||t,o=r.get("relay"),s=r.get("secret");if(!i||!o||!s)throw new Error("invalid connection string");return{pubkey:i,relay:o,secret:s}}async function Ba(e,t,n){const r={method:"pay_invoice",params:{invoice:n}},i=ps(t,e,JSON.stringify(r)),o={kind:go,created_at:Math.round(Date.now()/1e3),content:i,tags:[["p",e]]};return di(o,t)}Yr({},{makeNwcRequestEvent:()=>Ba,parseConnectionString:()=>xa});function Sa(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("")}Yr({},{normalizeIdentifier:()=>Sa});var Fa;Yr({},{getSatoshisAmountFromBolt11:()=>Ua,getZapEndpoint:()=>Ra,makeZapReceipt:()=>Ta,makeZapRequest:()=>Da,useFetchImplementation:()=>Qa,validateZapRequest:()=>Pa});try{Fa=fetch}catch{}function Qa(e){Fa=e}async function Ra(e){try{let t="",{lud06:n,lud16:r}=JSON.parse(e.content);if(n){let{words:e}=ar.decode(n,1e3),r=ar.fromWords(e);t=Xr.decode(r)}else{if(!r)return null;{let[e,n]=r.split("@");t=new URL(`/.well-known/lnurlp/${e}`,`https://${n}`).toString()}}let i=await Fa(t),o=await i.json();if(o.allowsNostr&&o.nostrPubkey)return o.callback}catch(e){}return null}function Da(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]),gi(e.event.kind)){const n=["a",`${e.event.kind}:${e.event.pubkey}:`];t.tags.push(n)}else if(yi(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 Pa(e){let t;try{t=JSON.parse(e)}catch(e){return"Invalid zap request JSON."}if(!Zr(t))return"Zap request is not a valid Nostr event.";if(!fi(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 i=JSON.parse(e),o=i.tags.filter(([e])=>"e"===e||"p"===e||"a"===e),s={kind:9735,created_at:Math.round(r.getTime()/1e3),content:"",tags:[...o,["P",i.pubkey],["bolt11",n],["description",e]]};return t&&s.tags.push(["preimage",t]),s}function Ua(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 i=r[r.length-1],o=i.charCodeAt(0)-"0".charCodeAt(0),s=o>=0&&o<=9;let a=r.length-1;if(s&&a++,a<1)return 0;const l=parseInt(r.substring(0,a));switch(i){case"m":return 1e5*l;case"u":return 100*l;case"n":return l/10;case"p":return l/1e4;default:return 1e8*l}}Yr({},{getToken:()=>Na,hashPayload:()=>Ga,unpackEventFromToken:()=>Oa,validateEvent:()=>Ja,validateEventKind:()=>_a,validateEventMethodTag:()=>ja,validateEventPayloadTag:()=>Ka,validateEventTimestamp:()=>Ma,validateEventUrlTag:()=>Ha,validateToken:()=>La});var $a="Nostr ";async function Na(e,t,n,r=!1,i){const o={kind:wo,tags:[["u",e],["method",t]],created_at:Math.round((new Date).getTime()/1e3),content:""};i&&o.tags.push(["payload",Ga(i)]);const s=await n(o);return(r?$a:"")+Yn.encode(ei.encode(JSON.stringify(s)))}async function La(e,t,n){const r=await Oa(e).catch(e=>{throw e});return await Ja(r,t,n).catch(e=>{throw e})}async function Oa(e){if(!e)throw new Error("Missing token");e=e.replace($a,"");const t=Xr.decode(Yn.decode(e));if(!t||0===t.length||!t.startsWith("{"))throw new Error("Invalid token");return JSON.parse(t)}function Ma(e){return!!e.created_at&&Math.round((new Date).getTime()/1e3)-e.created_at<60}function _a(e){return e.kind===wo}function Ha(e,t){const n=e.tags.find(e=>"u"===e[0]);return!!n&&(n.length>0&&n[1]===t)}function ja(e,t){const n=e.tags.find(e=>"method"===e[0]);return!!n&&(n.length>0&&n[1].toLowerCase()===t.toLowerCase())}function Ga(e){return Zt(yn(ei.encode(JSON.stringify(e))))}function Ka(e,t){const n=e.tags.find(e=>"payload"===e[0]);if(!n)return!1;const r=Ga(t);return n.length>0&&n[1]===r}async function Ja(e,t,n,r){if(!fi(e))throw new Error("Invalid nostr event, signature invalid");if(!_a(e))throw new Error("Invalid nostr event, kind invalid");if(!Ma(e))throw new Error("Invalid nostr event, created_at timestamp invalid");if(!Ha(e,t))throw new Error("Invalid nostr event, url tag invalid");if(!ja(e,n))throw new Error("Invalid nostr event, method tag invalid");if(Boolean(r)&&"object"==typeof r&&Object.keys(r).length>0&&!Ka(e,r))throw new Error("Invalid nostr event, payload tag does not match request body hash");return!0}function Va(e){return[0,3].includes(e)||1e4<=e&&e<2e4}function qa(e){return 3e4<=e&&e<4e4}var za=function(e,t){return za=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])},za(e,t)};function Ya(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}za(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}function Wa(e,t,n,r){return new(n||(n=Promise))(function(i,o){function s(e){try{l(r.next(e))}catch(e){o(e)}}function a(e){try{l(r.throw(e))}catch(e){o(e)}}function l(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(s,a)}l((r=r.apply(e,t||[])).next())})}function Za(e,t){var n,r,i,o={label:0,sent:function(){if(1&i[0])throw i[1];return i[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(l){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(o=0)),o;)try{if(n=1,r&&(i=2&a[0]?r.return:a[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,a[1])).done)return i;switch(r=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return o.label++,{value:a[1],done:!1};case 5:o.label++,r=a[1],a=[0];continue;case 7:a=o.ops.pop(),o.trys.pop();continue;default:if(!(i=o.trys,(i=i.length>0&&i[i.length-1])||6!==a[0]&&2!==a[0])){o=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]<i[3])){o.label=a[1];break}if(6===a[0]&&o.label<i[1]){o.label=i[1],i=a;break}if(i&&o.label<i[2]){o.label=i[2],o.ops.push(a);break}i[2]&&o.ops.pop(),o.trys.pop();continue}a=t.call(e,o)}catch(e){a=[6,e],r=0}finally{n=i=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,l])}}}function Xa(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 el(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,i,o=n.call(e),s=[];try{for(;(void 0===t||t-- >0)&&!(r=o.next()).done;)s.push(r.value)}catch(e){i={error:e}}finally{try{r&&!r.done&&(n=o.return)&&n.call(o)}finally{if(i)throw i.error}}return s}function tl(e,t,n){if(n||2===arguments.length)for(var r,i=0,o=t.length;i<o;i++)!r&&i in t||(r||(r=Array.prototype.slice.call(t,0,i)),r[i]=t[i]);return e.concat(r||Array.prototype.slice.call(t))}function nl(e){return this instanceof nl?(this.v=e,this):new nl(e)}function rl(e,t,n){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var r,i=n.apply(e,t||[]),o=[];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,c)}}),r[Symbol.asyncIterator]=function(){return this},r;function s(e,t){i[e]&&(r[e]=function(t){return new Promise(function(n,r){o.push([e,t,n,r])>1||a(e,t)})},t&&(r[e]=t(r[e])))}function a(e,t){try{(n=i[e](t)).value instanceof nl?Promise.resolve(n.value.v).then(l,c):u(o[0][2],n)}catch(e){u(o[0][3],e)}var n}function l(e){a("next",e)}function c(e){a("throw",e)}function u(e,t){e(t),o.shift(),o.length&&a(o[0][0],o[0][1])}}function il(e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t,n=e[Symbol.asyncIterator];return n?n.call(e):(e=Xa(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,i){(function(e,t,n,r){Promise.resolve(r).then(function(t){e({value:t,done:n})},t)})(r,i,(t=e[n](t)).done,t.value)})}}}function ol(e){return"function"==typeof e}function sl(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 al=sl(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 ll(e,t){if(e){var n=e.indexOf(t);0<=n&&e.splice(n,1)}}var cl=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,i;if(!this.closed){this.closed=!0;var o=this._parentage;if(o)if(this._parentage=null,Array.isArray(o))try{for(var s=Xa(o),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 o.remove(this);var l=this.initialTeardown;if(ol(l))try{l()}catch(e){i=e instanceof al?e.errors:[e]}var c=this._finalizers;if(c){this._finalizers=null;try{for(var u=Xa(c),d=u.next();!d.done;d=u.next()){var f=d.value;try{fl(f)}catch(e){i=null!=i?i:[],e instanceof al?i=tl(tl([],el(i)),el(e.errors)):i.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(i)throw new al(i)}},e.prototype.add=function(t){var n;if(t&&t!==this)if(this.closed)fl(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)&&ll(t,e)},e.prototype.remove=function(t){var n=this._finalizers;n&&ll(n,t),t instanceof e&&t._removeParent(this)},e.EMPTY=function(){var t=new e;return t.closed=!0,t}(),e}(),ul=cl.EMPTY;function dl(e){return e instanceof cl||e&&"closed"in e&&ol(e.remove)&&ol(e.add)&&ol(e.unsubscribe)}function fl(e){ol(e)?e():e.unsubscribe()}var hl={onUnhandledError:null,onStoppedNotification:null,Promise:void 0,useDeprecatedSynchronousErrorHandling:!1,useDeprecatedNextContext:!1},pl={setTimeout:function(e,t){for(var n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];var i=pl.delegate;return(null==i?void 0:i.setTimeout)?i.setTimeout.apply(i,tl([e,t],el(n))):setTimeout.apply(void 0,tl([e,t],el(n)))},clearTimeout:function(e){var t=pl.delegate;return((null==t?void 0:t.clearTimeout)||clearTimeout)(e)},delegate:void 0};function gl(e){pl.setTimeout(function(){throw e})}function ml(){}function yl(e){e()}var wl=function(e){function t(t){var n=e.call(this)||this;return n.isStopped=!1,t?(n.destination=t,dl(t)&&t.add(n)):n.destination=El,n}return Ya(t,e),t.create=function(e,t,n){return new kl(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}(cl),vl=Function.prototype.bind;function Al(e,t){return vl.call(e,t)}var bl=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){Il(e)}},e.prototype.error=function(e){var t=this.partialObserver;if(t.error)try{t.error(e)}catch(e){Il(e)}else Il(e)},e.prototype.complete=function(){var e=this.partialObserver;if(e.complete)try{e.complete()}catch(e){Il(e)}},e}(),kl=function(e){function t(t,n,r){var i,o,s=e.call(this)||this;ol(t)||!t?i={next:null!=t?t:void 0,error:null!=n?n:void 0,complete:null!=r?r:void 0}:s&&hl.useDeprecatedNextContext?((o=Object.create(t)).unsubscribe=function(){return s.unsubscribe()},i={next:t.next&&Al(t.next,o),error:t.error&&Al(t.error,o),complete:t.complete&&Al(t.complete,o)}):i=t;return s.destination=new bl(i),s}return Ya(t,e),t}(wl);function Il(e){gl(e)}var El={closed:!0,next:ml,error:function(e){throw e},complete:ml},Cl="function"==typeof Symbol&&Symbol.observable||"@@observable";function xl(e){return e}var Bl=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,i=this,o=(r=e)&&r instanceof wl||function(e){return e&&ol(e.next)&&ol(e.error)&&ol(e.complete)}(r)&&dl(r)?e:new kl(e,t,n);return yl(function(){var e=i,t=e.operator,n=e.source;o.add(t?t.call(o,n):n?i._subscribe(o):i._trySubscribe(o))}),o},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=Sl(t))(function(t,r){var i=new kl({next:function(t){try{e(t)}catch(e){r(e),i.unsubscribe()}},error:r,complete:t});n.subscribe(i)})},e.prototype._subscribe=function(e){var t;return null===(t=this.source)||void 0===t?void 0:t.subscribe(e)},e.prototype[Cl]=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?xl: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=Sl(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 Sl(e){var t;return null!==(t=null!=e?e:hl.Promise)&&void 0!==t?t:Promise}function Fl(e){return function(t){if(function(e){return ol(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 Ql(e,t,n,r,i){return new Rl(e,t,n,r,i)}var Rl=function(e){function t(t,n,r,i,o,s){var a=e.call(this,t)||this;return a.onFinalize=o,a.shouldUnsubscribe=s,a._next=n?function(e){try{n(e)}catch(e){t.error(e)}}:e.prototype._next,a._error=i?function(e){try{i(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 Ya(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}(wl),Dl=sl(function(e){return function(){e(this),this.name="ObjectUnsubscribedError",this.message="object unsubscribed"}}),Pl=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 Ya(t,e),t.prototype.lift=function(e){var t=new Tl(this,this);return t.operator=e,t},t.prototype._throwIfClosed=function(){if(this.closed)throw new Dl},t.prototype.next=function(e){var t=this;yl(function(){var n,r;if(t._throwIfClosed(),!t.isStopped){t.currentObservers||(t.currentObservers=Array.from(t.observers));try{for(var i=Xa(t.currentObservers),o=i.next();!o.done;o=i.next()){o.value.next(e)}}catch(e){n={error:e}}finally{try{o&&!o.done&&(r=i.return)&&r.call(i)}finally{if(n)throw n.error}}}})},t.prototype.error=function(e){var t=this;yl(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;yl(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,i=n.isStopped,o=n.observers;return r||i?ul:(this.currentObservers=null,o.push(e),new cl(function(){t.currentObservers=null,ll(o,e)}))},t.prototype._checkFinalizedStatuses=function(e){var t=this,n=t.hasError,r=t.thrownError,i=t.isStopped;n?e.error(r):i&&e.complete()},t.prototype.asObservable=function(){var e=new Bl;return e.source=this,e},t.create=function(e,t){return new Tl(e,t)},t}(Bl),Tl=function(e){function t(t,n){var r=e.call(this)||this;return r.destination=t,r.source=n,r}return Ya(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:ul},t}(Pl),Ul={now:function(){return(Ul.delegate||Date).now()},delegate:void 0},$l=function(e){function t(t,n,r){void 0===t&&(t=1/0),void 0===n&&(n=1/0),void 0===r&&(r=Ul);var i=e.call(this)||this;return i._bufferSize=t,i._windowTime=n,i._timestampProvider=r,i._buffer=[],i._infiniteTimeWindow=!0,i._infiniteTimeWindow=n===1/0,i._bufferSize=Math.max(1,t),i._windowTime=Math.max(1,n),i}return Ya(t,e),t.prototype.next=function(t){var n=this,r=n.isStopped,i=n._buffer,o=n._infiniteTimeWindow,s=n._timestampProvider,a=n._windowTime;r||(i.push(t),!o&&i.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(),i=0;i<r.length&&!e.closed;i+=n?1:2)e.next(r[i]);return this._checkFinalizedStatuses(e),t},t.prototype._trimBuffer=function(){var e=this,t=e._bufferSize,n=e._timestampProvider,r=e._buffer,i=e._infiniteTimeWindow,o=(i?1:2)*t;if(t<1/0&&o<r.length&&r.splice(0,r.length-o),!i){for(var s=n.now(),a=0,l=1;l<r.length&&r[l]<=s;l+=2)a=l;a&&r.splice(0,a+1)}},t}(Pl),Nl=function(e){function t(t,n){return e.call(this)||this}return Ya(t,e),t.prototype.schedule=function(e,t){return this},t}(cl),Ll={setInterval:function(e,t){for(var n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];var i=Ll.delegate;return(null==i?void 0:i.setInterval)?i.setInterval.apply(i,tl([e,t],el(n))):setInterval.apply(void 0,tl([e,t],el(n)))},clearInterval:function(e){var t=Ll.delegate;return((null==t?void 0:t.clearInterval)||clearInterval)(e)},delegate:void 0},Ol=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 Ya(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,i=this.scheduler;return null!=r&&(this.id=this.recycleAsyncId(i,r,t)),this.pending=!0,this.delay=t,this.id=null!==(n=this.id)&&void 0!==n?n:this.requestAsyncId(i,this.id,t),this},t.prototype.requestAsyncId=function(e,t,n){return void 0===n&&(n=0),Ll.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&&Ll.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,ll(r,this),null!=t&&(this.id=this.recycleAsyncId(n,t,null)),this.delay=null,e.prototype.unsubscribe.call(this)}},t}(Nl),Ml=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=Ul.now,e}(),_l=function(e){function t(t,n){void 0===n&&(n=Ml.now);var r=e.call(this,t,n)||this;return r.actions=[],r._active=!1,r}return Ya(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}(Ml),Hl=new _l(Ol),jl=new Bl(function(e){return e.complete()});function Gl(e){return e&&ol(e.schedule)}function Kl(e){return e[e.length-1]}function Jl(e){return Gl(Kl(e))?e.pop():void 0}function Vl(e,t){return"number"==typeof Kl(e)?e.pop():t}var ql=function(e){return e&&"number"==typeof e.length&&"function"!=typeof e};function zl(e){return ol(null==e?void 0:e.then)}function Yl(e){return ol(e[Cl])}function Wl(e){return Symbol.asyncIterator&&ol(null==e?void 0:e[Symbol.asyncIterator])}function Zl(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 Xl="function"==typeof Symbol&&Symbol.iterator?Symbol.iterator:"@@iterator";function ec(e){return ol(null==e?void 0:e[Xl])}function tc(e){return rl(this,arguments,function(){var t,n,r;return Za(this,function(i){switch(i.label){case 0:t=e.getReader(),i.label=1;case 1:i.trys.push([1,,9,10]),i.label=2;case 2:return[4,nl(t.read())];case 3:return n=i.sent(),r=n.value,n.done?[4,nl(void 0)]:[3,5];case 4:return[2,i.sent()];case 5:return[4,nl(r)];case 6:return[4,i.sent()];case 7:return i.sent(),[3,2];case 8:return[3,10];case 9:return t.releaseLock(),[7];case 10:return[2]}})})}function nc(e){return ol(null==e?void 0:e.getReader)}function rc(e){if(e instanceof Bl)return e;if(null!=e){if(Yl(e))return i=e,new Bl(function(e){var t=i[Cl]();if(ol(t.subscribe))return t.subscribe(e);throw new TypeError("Provided object does not correctly implement Symbol.observable")});if(ql(e))return r=e,new Bl(function(e){for(var t=0;t<r.length&&!e.closed;t++)e.next(r[t]);e.complete()});if(zl(e))return n=e,new Bl(function(e){n.then(function(t){e.closed||(e.next(t),e.complete())},function(t){return e.error(t)}).then(null,gl)});if(Wl(e))return ic(e);if(ec(e))return t=e,new Bl(function(e){var n,r;try{for(var i=Xa(t),o=i.next();!o.done;o=i.next()){var s=o.value;if(e.next(s),e.closed)return}}catch(e){n={error:e}}finally{try{o&&!o.done&&(r=i.return)&&r.call(i)}finally{if(n)throw n.error}}e.complete()});if(nc(e))return ic(tc(e))}var t,n,r,i;throw Zl(e)}function ic(e){return new Bl(function(t){(function(e,t){var n,r,i,o;return Wa(this,void 0,void 0,function(){var s,a;return Za(this,function(l){switch(l.label){case 0:l.trys.push([0,5,6,11]),n=il(e),l.label=1;case 1:return[4,n.next()];case 2:if((r=l.sent()).done)return[3,4];if(s=r.value,t.next(s),t.closed)return[2];l.label=3;case 3:return[3,1];case 4:return[3,11];case 5:return a=l.sent(),i={error:a},[3,11];case 6:return l.trys.push([6,,9,10]),r&&!r.done&&(o=n.return)?[4,o.call(n)]:[3,8];case 7:l.sent(),l.label=8;case 8:return[3,10];case 9:if(i)throw i.error;return[7];case 10:return[7];case 11:return t.complete(),[2]}})})})(e,t).catch(function(e){return t.error(e)})})}function oc(e,t,n,r,i){void 0===r&&(r=0),void 0===i&&(i=!1);var o=t.schedule(function(){n(),i?e.add(this.schedule(null,r)):this.unsubscribe()},r);if(e.add(o),!i)return o}function sc(e,t){return void 0===t&&(t=0),Fl(function(n,r){n.subscribe(Ql(r,function(n){return oc(r,e,function(){return r.next(n)},t)},function(){return oc(r,e,function(){return r.complete()},t)},function(n){return oc(r,e,function(){return r.error(n)},t)}))})}function ac(e,t){return void 0===t&&(t=0),Fl(function(n,r){r.add(e.schedule(function(){return n.subscribe(r)},t))})}function lc(e,t){if(!e)throw new Error("Iterable cannot be null");return new Bl(function(n){oc(n,t,function(){var r=e[Symbol.asyncIterator]();oc(n,t,function(){r.next().then(function(e){e.done?n.complete():n.next(e.value)})},0,!0)})})}function cc(e,t){if(null!=e){if(Yl(e))return function(e,t){return rc(e).pipe(ac(t),sc(t))}(e,t);if(ql(e))return function(e,t){return new Bl(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(zl(e))return function(e,t){return rc(e).pipe(ac(t),sc(t))}(e,t);if(Wl(e))return lc(e,t);if(ec(e))return function(e,t){return new Bl(function(n){var r;return oc(n,t,function(){r=e[Xl](),oc(n,t,function(){var e,t,i;try{t=(e=r.next()).value,i=e.done}catch(e){return void n.error(e)}i?n.complete():n.next(t)},0,!0)}),function(){return ol(null==r?void 0:r.return)&&r.return()}})}(e,t);if(nc(e))return function(e,t){return lc(tc(e),t)}(e,t)}throw Zl(e)}function uc(e,t){return t?cc(e,t):rc(e)}function dc(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return uc(e,Jl(e))}function fc(e,t){return Fl(function(n,r){var i=0;n.subscribe(Ql(r,function(n){r.next(e.call(t,n,i++))}))})}var hc=Array.isArray;function pc(e){return fc(function(t){return function(e,t){return hc(t)?e.apply(void 0,tl([],el(t))):e(t)}(e,t)})}var gc=Array.isArray,mc=Object.getPrototypeOf,yc=Object.prototype,wc=Object.keys;function vc(e){if(1===e.length){var t=e[0];if(gc(t))return{args:t,keys:null};if((r=t)&&"object"==typeof r&&mc(r)===yc){var n=wc(t);return{args:n.map(function(e){return t[e]}),keys:n}}}var r;return{args:e,keys:null}}function Ac(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=Jl(e),r=function(e){return ol(Kl(e))?e.pop():void 0}(e),i=vc(e),o=i.args,s=i.keys;if(0===o.length)return uc([],n);var a=new Bl(function(e,t,n){void 0===n&&(n=xl);return function(r){bc(t,function(){for(var i=e.length,o=new Array(i),s=i,a=i,l=function(i){bc(t,function(){var l=uc(e[i],t),c=!1;l.subscribe(Ql(r,function(e){o[i]=e,c||(c=!0,a--),a||r.next(n(o.slice()))},function(){--s||r.complete()}))},r)},c=0;c<i;c++)l(c)},r)}}(o,n,s?function(e){return function(e,t){return e.reduce(function(e,n,r){return e[n]=t[r],e},{})}(s,e)}:xl));return r?a.pipe(pc(r)):a}function bc(e,t,n){e?oc(n,e,t):t()}function kc(e,t,n){return void 0===n&&(n=1/0),ol(t)?kc(function(n,r){return fc(function(e,i){return t(n,e,r,i)})(rc(e(n,r)))},n):("number"==typeof t&&(n=t),Fl(function(t,r){return function(e,t,n,r,i,o,s,a){var l=[],c=0,u=0,d=!1,f=function(){!d||l.length||c||t.complete()},h=function(e){return c<r?p(e):l.push(e)},p=function(e){o&&t.next(e),c++;var a=!1;rc(n(e,u++)).subscribe(Ql(t,function(e){null==i||i(e),o?h(e):t.next(e)},function(){a=!0},void 0,function(){if(a)try{c--;for(var e=function(){var e=l.shift();s?oc(t,s,function(){return p(e)}):p(e)};l.length&&c<r;)e();f()}catch(e){t.error(e)}}))};return e.subscribe(Ql(t,h,function(){d=!0,f()})),function(){null==a||a()}}(t,r,e,n)}))}function Ic(e){return void 0===e&&(e=1/0),kc(xl,e)}function Ec(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return Ic(1)(uc(e,Jl(e)))}function Cc(e){return new Bl(function(t){rc(e()).subscribe(t)})}function xc(e,t,n){void 0===e&&(e=0),void 0===n&&(n=Hl);var r=-1;return null!=t&&(Gl(t)?n=t:r=t),new Bl(function(t){var i,o=(i=e)instanceof Date&&!isNaN(i)?+e-n.now():e;o<0&&(o=0);var s=0;return n.schedule(function(){t.closed||(t.next(s++),0<=r?this.schedule(void 0,r):t.complete())},o)})}function Bc(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=Jl(e),r=Vl(e,1/0),i=e;return i.length?1===i.length?rc(i[0]):Ic(r)(uc(i,n)):jl}function Sc(e,t){return Fl(function(n,r){var i=0;n.subscribe(Ql(r,function(n){return e.call(t,n,i++)&&r.next(n)}))})}function Fc(e){return e<=0?function(){return jl}:Fl(function(t,n){var r=0;t.subscribe(Ql(n,function(t){++r<=e&&(n.next(t),e<=r&&n.complete())}))})}function Qc(e,t){return void 0===t&&(t=xl),e=null!=e?e:Rc,Fl(function(n,r){var i,o=!0;n.subscribe(Ql(r,function(n){var s=t(n);!o&&e(i,s)||(o=!1,i=s,r.next(n))}))})}function Rc(e,t){return e===t}function Dc(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return function(t){return Ec(t,dc.apply(void 0,tl([],el(e))))}}function Pc(e){return Fl(function(t,n){try{t.subscribe(n)}finally{n.add(e)}})}function Tc(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=Jl(e),r=Vl(e,1/0);return Fl(function(t,i){Ic(r)(uc(tl([t],el(e)),n)).subscribe(i)})}function Uc(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return Tc.apply(void 0,tl([],el(e)))}function $c(e,t){return Fl(function(e,t,n,r,i){return function(o,s){var a=n,l=t,c=0;o.subscribe(Ql(s,function(t){var n=c++;l=a?e(l,t,n):(a=!0,t),r&&s.next(l)},i&&function(){a&&s.next(l),s.complete()}))}}(e,t,arguments.length>=2,!0))}function Nc(e,t){for(var n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];if(!0!==t){if(!1!==t){var i=new kl({next:function(){i.unsubscribe(),e()}});return rc(t.apply(void 0,tl([],el(n)))).subscribe(i)}}else e()}function Lc(e,t){return Fl(function(n,r){var i=null,o=0,s=!1,a=function(){return s&&!i&&r.complete()};n.subscribe(Ql(r,function(n){null==i||i.unsubscribe();var s=0,l=o++;rc(e(n,l)).subscribe(i=Ql(r,function(e){return r.next(t?t(n,e,l,s++):e)},function(){i=null,a()}))},function(){s=!0,a()}))})}function Oc(e,t,n){var r=ol(e)||t||n?{next:e,error:t,complete:n}:e;return r?Fl(function(e,t){var n;null===(n=r.subscribe)||void 0===n||n.call(r);var i=!0;e.subscribe(Ql(t,function(e){var n;null===(n=r.next)||void 0===n||n.call(r,e),t.next(e)},function(){var e;i=!1,null===(e=r.complete)||void 0===e||e.call(r),t.complete()},function(e){var n;i=!1,null===(n=r.error)||void 0===n||n.call(r,e),t.error(e)},function(){var e,t;i&&(null===(e=r.unsubscribe)||void 0===e||e.call(r)),null===(t=r.finalize)||void 0===t||t.call(r)}))}):xl}function Mc(e,t){return void 0!==e[0]&&void 0!==e[1]&&(!t||e[0]===t)}function _c(e){return Mc(e,"e")}function Hc(e){return Mc(e,"p")}function jc(e){return Mc(e,"r")}function Gc(e){return Mc(e,"a")}function Kc(e){return Mc(e,"t")}const Jc=(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);var Vc=Symbol("verified");function qc(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 zc=new TextEncoder;function Yc(e){return Zt(yn(zc.encode(function(e){if(!qc(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 Wc=new class{generateSecretKey(){return Jt.utils.randomPrivateKey()}getPublicKey(e){return Zt(Jt.getPublicKey(e))}finalizeEvent(e,t){const n=e;return n.pubkey=Zt(Jt.getPublicKey(t)),n.id=Yc(n),n.sig=Zt(Jt.sign(Yc(n),t)),n[Vc]=!0,n}verifyEvent(e){if("boolean"==typeof e[Vc])return e[Vc];const t=Yc(e);if(t!==e.id)return e[Vc]=!1,!1;try{const n=Jt.verify(e.sig,t,e.pubkey);return e[Vc]=n,n}catch(t){return e[Vc]=!1,!1}}},Zc=Wc.generateSecretKey,Xc=Wc.getPublicKey;function eu(e,t,n){if(Reflect.has(e,t))return Reflect.get(e,t);{const r=n();return Reflect.set(e,t,r),r}}function tu(e,t){const[n,r]=nu(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 nu(e,t){let n=0,r=e.length-1;for(;n<=r;){const i=Math.floor((n+r)/2),o=t(e[i]);if(0===o)return[i,!0];o<0?r=i-1:n=i+1}return[n,!1]}Wc.finalizeEvent,Wc.verifyEvent,new TextDecoder("utf-8"),new TextEncoder;const ru=Symbol.for("event-store"),iu=Symbol.for("event-uid"),ou=Symbol.for("replaceable-address"),su=Symbol.for("from-cache"),au=Symbol.for("replaceable-identifier");function lu(e){return Va(e)||qa(e)}function cu(e){let t=Reflect.get(e,iu);return t||(t=qa(e.kind)||Va(e.kind)?uu(e):e.id,Reflect.set(e,iu,t)),t}function uu(e){if(!qa(e.kind)&&!Va(e.kind))throw new Error("Event is not replaceable or addressable");return eu(e,ou,()=>du(e.kind,e.pubkey,fu(e)))}function du(e,t,n){return e+":"+t+":"+(n??"")}function fu(e){return eu(e,au,()=>e.tags.find(e=>"d"===e[0])?.[1]??"")}function hu(){return Math.round(Date.now()/1e3)}const pu=Symbol("expiration-timestamp");function gu(e){return eu(e,pu,()=>{const t=e.tags.find(e=>"expiration"===e[0])?.[1];return t?parseInt(t):void 0})}var mu=new TextDecoder("utf-8");new TextEncoder;function yu(e){let{prefix:t,words:n}=ar.decode(e,5e3),r=new Uint8Array(ar.fromWords(n));switch(t){case"nprofile":{let e=wu(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:Zt(e[0][0]),relays:e[1]?e[1].map(e=>mu.decode(e)):[]}}}case"nevent":{let e=wu(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:Zt(e[0][0]),relays:e[1]?e[1].map(e=>mu.decode(e)):[],author:e[2]?.[0]?Zt(e[2][0]):void 0,kind:e[3]?.[0]?parseInt(Zt(e[3][0]),16):void 0}}}case"naddr":{let e=wu(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:mu.decode(e[0][0]),pubkey:Zt(e[2][0]),kind:parseInt(Zt(e[3][0]),16),relays:e[1]?e[1].map(e=>mu.decode(e)):[]}}}case"nsec":return{type:t,data:r};case"npub":case"note":return{type:t,data:Zt(r)};default:throw new Error(`unknown prefix ${t}`)}}function wu(e){let t={},n=e;for(;n.length>0;){let e=n[0],r=n[1],i=n.slice(2,2+r);if(n=n.slice(2+r),i.length<r)throw new Error(`not enough data to read on TLV ${e}`);t[e]=t[e]||[],t[e].push(i)}return t}function vu(e){return Au("npub",Xt(e))}function Au(e,t){return function(e,t){let n=ar.toWords(t);return ar.encode(e,n,5e3)}(e,t)}function bu(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 ku=Symbol.for("seen-relays");function Iu(e,t){return e[ku]||(e[ku]=new Set),e[ku].add(t),e[ku]}const Eu=/^wss?:\/\/([-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}|localhost)\b([-a-zA-Z0-9()@:%_\+.~#?&\/\/=]*)$/;function Cu(e){return e.length>=8&&Eu.test(e)}function xu(e){return!!e?.toLowerCase()?.match(/^[0-9a-f]{64}$/)}const Bu="object"==typeof globalThis&&"crypto"in globalThis?globalThis.crypto:void 0;
/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */function Su(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&"Uint8Array"===e.constructor.name}function Fu(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function Qu(e,...t){if(!Su(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)}function Ru(e){if("function"!=typeof e||"function"!=typeof e.create)throw new Error("Hash should be wrapped by utils.createHasher");Fu(e.outputLen),Fu(e.blockLen)}function Du(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function Pu(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function Tu(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function Uu(e,t){return e<<32-t|e>>>t}const $u=(()=>"function"==typeof Uint8Array.from([]).toHex&&"function"==typeof Uint8Array.fromHex)(),Nu=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Lu(e){if(Qu(e),$u)return e.toHex();let t="";for(let n=0;n<e.length;n++)t+=Nu[e[n]];return t}const Ou=48,Mu=57,_u=65,Hu=70,ju=97,Gu=102;function Ku(e){return e>=Ou&&e<=Mu?e-Ou:e>=_u&&e<=Hu?e-(_u-10):e>=ju&&e<=Gu?e-(ju-10):void 0}function Ju(e){if("string"!=typeof e)throw new Error("hex string expected, got "+typeof e);if($u)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,i=0;t<n;t++,i+=2){const n=Ku(e.charCodeAt(i)),o=Ku(e.charCodeAt(i+1));if(void 0===n||void 0===o){const t=e[i]+e[i+1];throw new Error('hex string expected, got non-hex character "'+t+'" at index '+i)}r[t]=16*n+o}return r}function Vu(e){return"string"==typeof e&&(e=function(e){if("string"!=typeof e)throw new Error("string expected");return new Uint8Array((new TextEncoder).encode(e))}(e)),Qu(e),e}function qu(...e){let t=0;for(let n=0;n<e.length;n++){const r=e[n];Qu(r),t+=r.length}const n=new Uint8Array(t);for(let t=0,r=0;t<e.length;t++){const i=e[t];n.set(i,r),r+=i.length}return n}class zu{}function Yu(e){const t=t=>e().update(Vu(t)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function Wu(e=32){if(Bu&&"function"==typeof Bu.getRandomValues)return Bu.getRandomValues(new Uint8Array(e));if(Bu&&"function"==typeof Bu.randomBytes)return Uint8Array.from(Bu.randomBytes(e));throw new Error("crypto.getRandomValues must be defined")}function Zu(e,t=!1,n=!0){const r=e.split(":"),i=r[0]?parseInt(r[0]):void 0,o=r[1],s=r[2];if(void 0===i){if(n)return null;throw new Error("Missing kind")}if(void 0===o||""===o){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:i,pubkey:o,identifier:s}}function Xu(e){if(!e[1])throw new Error("Missing coordinate in tag");const t=Zu(e[1],!0,!1);return e[2]&&Cu(e[2])&&(t.relays=[e[2]]),t}function ed(e){if(!e[1])throw new Error("Missing pubkey in tag");if(!xu(e[1]))throw new Error("Invalid pubkey");const t={pubkey:e[1]};return e[2]&&Cu(e[2])&&(t.relays=[bu(e[2])]),t}function td(e){return e.kind+":"+e.pubkey+":"+e.identifier}const nd=Symbol.for("encrypted-content"),rd={[hi.EncryptedDirectMessage]:"nip04",[hi.Seal]:"nip44",[hi.GiftWrap]:"nip44"};function id(e,t){return rd[e]=t,e}const od=nd,sd=new Set([id(hi.DraftLong,"nip04")]);function ad(e,t){return sd.add(id(e,t)),e}function ld(e){return function(e){return void 0!==rd[e]}(e)&&sd.has(e)}function cd(e){return!!ld(e.kind)&&(function(e){return!0===Reflect.has(e,nd)}(e)&&!0===Reflect.has(e,od))}function ud(e){if(ld(e.kind))return cd(e)?e[nd]:function(e){return Reflect.get(e,nd)}(e)}const dd=Symbol.for("hidden-tags"),fd=new Set([ad(hi.BookmarkList,"nip04"),ad(hi.InterestsList,"nip04"),ad(hi.Mutelist,"nip04"),ad(hi.CommunitiesList,"nip04"),ad(hi.PublicChatsList,"nip04"),ad(hi.SearchRelaysList,"nip04"),ad(10009,"nip04"),ad(hi.Bookmarksets,"nip04"),ad(hi.Relaysets,"nip04"),ad(hi.Followsets,"nip04"),ad(hi.Curationsets,"nip04"),ad(hi.Interestsets,"nip04")]);function hd(e){return ld(e)&&fd.has(e)}function pd(e){return!!hd(e.kind)&&(cd(e)&&Reflect.has(e,"HiddenTagsSymbol"))}function gd(e){if(!hd(e.kind))return;if(pd(e))return e[dd];const t=ud(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,dd,r),r}const md="abcdefghijklmnopqrstuvwxyz",yd=new Set((md+md.toUpperCase()).split("")),wd=Symbol.for("indexable-tags");function vd(e){let t=Reflect.get(e,wd);if(!t){const n=new Set;for(const t of e.tags)t.length>=2&&1===t[0].length&&yd.has(t[0])&&n.add(t[0]+":"+t[1]);t=n,Reflect.set(e,wd,n)}return t}class Ad{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 i;if(n||this.has(e)){if(i=this.items[e],i.value=t,!1===n&&r&&(i.expiry=this.ttl>0?Date.now()+this.ttl:this.ttl),this.last!==i){const e=this.last,t=i.next,n=i.prev;this.first===i&&(this.first=i.next),i.next=null,i.prev=this.last,e.next=i,null!==n&&(n.next=t),null!==t&&(t.prev=n)}}else this.max>0&&this.size===this.max&&this.evict(!0),i=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=i:this.last.next=i;return this.last=i,this}values(e=this.keys()){return e.map(e=>this.get(e))}}function bd(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var kd,Id,Ed={exports:{}};function Cd(){if(Id)return kd;Id=1;var e=1e3,t=60*e,n=60*t,r=24*n,i=7*r,o=365.25*r;function s(e,t,n,r){var i=t>=1.5*n;return Math.round(e/n)+" "+r+(i?"s":"")}return kd=function(a,l){l=l||{};var c=typeof a;if("string"===c&&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 l=parseFloat(a[1]);switch((a[2]||"ms").toLowerCase()){case"years":case"year":case"yrs":case"yr":case"y":return l*o;case"weeks":case"week":case"w":return l*i;case"days":case"day":case"d":return l*r;case"hours":case"hour":case"hrs":case"hr":case"h":return l*n;case"minutes":case"minute":case"mins":case"min":case"m":return l*t;case"seconds":case"second":case"secs":case"sec":case"s":return l*e;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return l;default:return}}(a);if("number"===c&&isFinite(a))return l.long?function(i){var o=Math.abs(i);if(o>=r)return s(i,o,r,"day");if(o>=n)return s(i,o,n,"hour");if(o>=t)return s(i,o,t,"minute");if(o>=e)return s(i,o,e,"second");return i+" ms"}(a):function(i){var o=Math.abs(i);if(o>=r)return Math.round(i/r)+"d";if(o>=n)return Math.round(i/n)+"h";if(o>=t)return Math.round(i/t)+"m";if(o>=e)return Math.round(i/e)+"s";return i+"ms"}(a);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(a))}}var xd=function(e){function t(e){let r,i,o,s=null;function a(...e){if(!a.enabled)return;const n=a,i=Number(new Date),o=i-(r||i);n.diff=o,n.prev=r,n.curr=i,r=i,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,i)=>{if("%%"===r)return"%";s++;const o=t.formatters[i];if("function"==typeof o){const t=e[s];r=o.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:(i!==t.namespaces&&(i=t.namespaces,o=t.enabled(e)),o),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,i=-1,o=0;for(;n<e.length;)if(r<t.length&&(t[r]===e[n]||"*"===t[r]))"*"===t[r]?(i=r,o=n,r++):(n++,r++);else{if(-1===i)return!1;r=i+1,o++,n=o}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=Cd(),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,i=0;t[0].replace(/%[a-zA-Z%]/g,e=>{"%%"!==e&&(r++,"%c"===e&&(i=r))}),t.splice(i,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=xd(t);const{formatters:n}=e.exports;n.j=function(e){try{return JSON.stringify(e)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}}}(Ed,Ed.exports);const Bd=bd(Ed.exports)("applesauce");class Sd{log=Bd.extend("EventMemory");kinds=new Map;authors=new Map;tags=new Ad;created_at=[];kindAuthor=new Map;events=new Ad;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(du(e,t,n));return!!r&&r.length>0}getReplaceable(e,t,n){const r=du(e,t,n),i=this.replaceable.get(r);return i?.[0]}getReplaceableHistory(e,t,n){const r=du(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)tu(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),this.getKindAuthorIndex(e.kind,e.pubkey).add(e);for(const t of vd(e))this.tags.has(t)&&this.getTagIndex(t).add(e);if(tu(this.created_at,e),lu(e.kind)){const t=e.tags.find(e=>"d"===e[0])?.[1],n=du(e.kind,e.pubkey,t);let r=this.replaceable.get(n);this.replaceable.has(n)||(r=[],this.replaceable.set(n,r)),tu(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);const r=`${t.kind}:${t.pubkey}`;this.kindAuthor.has(r)&&this.kindAuthor.get(r).delete(t);for(const e of vd(t))this.tags.has(e)&&this.getTagIndex(e).delete(t);if(this.removeFromSortedArray(this.created_at,t),this.events.delete(n),lu(t.kind)){const e=t.tags.find(e=>"d"===e[0])?.[1],n=du(t.kind,t.pubkey,e),r=this.replaceable.get(n);r&&this.removeFromSortedArray(r,t)}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){const t=this.claims.get(e)||0;this.claims.set(e,t+1),this.touch(e)}isClaimed(e){const t=this.claims.get(e);return void 0!==t&&t>0}removeClaim(e){const t=this.claims.get(e);if(void 0!==t&&t>0){const n=t-1;0===n?this.claims.delete(e):this.claims.set(e,n)}}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)}getKindAuthorIndex(e,t){const n=`${e}:${t}`;return this.kindAuthor.has(n)||this.kindAuthor.set(n,new Set),this.kindAuthor.get(n)}getTagIndex(e){if(!this.tags.has(e)){const t=new Set,n=Date.now();for(const n of this.events.values())vd(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)}removeFromSortedArray(e,t){if(0===e.length)return;const n=nu(e,e=>e.created_at-t.created_at);if(n){let r=n[0],i=!1;if(e[r]===t)return void e.splice(r,1);for(let n=r-1;n>=0&&e[n].created_at===t.created_at;n--)if(e[n]===t){e.splice(n,1),i=!0;break}if(i)return;for(let n=r+1;n<e.length&&e[n].created_at===t.created_at;n++)if(e[n]===t)return void e.splice(n,1)}const r=e.indexOf(t);-1!==r&&e.splice(r,1)}*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,i=t?nu(this.created_at,e=>e.created_at-t):void 0;i&&(n=i[0]);const o=e?nu(this.created_at,t=>t.created_at-e):void 0;o&&(r=o[0]);for(let i=n;i<=r;i++){const n=this.created_at[i];if(!(void 0!==t&&n.created_at>t)){if(void 0!==e&&n.created_at<e)break;yield n}}}*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 i=null;void 0!==e.since&&(i=Array.from(this.iterateTime(e.since,e.until)),r(i));for(const t of yd){const n=e[`&${t}`];if(n?.length)for(const e of n)r(this.iterateTag(t,[e]))}for(const t of yd){const n=e[`#${t}`];if(n?.length){const i=e[`&${t}`],o=i?n.filter(e=>!i.includes(e)):n;o.length>0&&r(this.iterateTag(t,o))}}if(e.authors&&e.kinds&&e.authors.length*e.kinds.length<=20){const t=new Set;for(const n of e.kinds)for(const r of e.authors){const e=`${n}:${r}`,i=this.kindAuthor.get(e);if(i)for(const e of i)t.add(e)}r(t)}else e.authors&&r(this.iterateAuthors(e.authors)),e.kinds&&r(this.iterateKinds(e.kinds));if(void 0===e.since&&void 0!==e.until&&(i=Array.from(this.iterateTime(e.since,e.until)),r(i)),t)return new Set(this.events.values());if(e.limit&&i){const t=new Set;for(const r of i){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.kindAuthor.clear(),this.tags.clear(),this.created_at=[],this.replaceable.clear(),this.claims=new WeakMap}}function Fd(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 Qd(e,t,n,r){var i,o=Fd(Fd(Fd(e,n),(i=t,Object.prototype.toString.call(i))),typeof t);if(null===t)return Fd(o,"null");if(void 0===t)return Fd(o,"undefined");if("object"==typeof t||"function"==typeof t){if(-1!==r.indexOf(t))return Fd(o,"[Circular]"+n);r.push(t);var s=function(e,t,n){return Object.keys(t).sort().reduce(function(e,r){return Qd(e,t[r],r,n)},e)}(o,t,r);if(!("valueOf"in t)||"function"!=typeof t.valueOf)return s;try{return Fd(s,String(t.valueOf()))}catch(e){return Fd(s,"[valueOf exception]"+(e.stack||e.message))}}return Fd(o,t.toString())}var Rd=function(e){return function(e,t){for(;e.length<t;)e="0"+e;return e}(Qd(0,e,"",[]).toString(16),8)},Dd=bd(Rd);function Pd(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;if(e.since&&t.created_at<e.since)return!1;if(e.until&&t.created_at>e.until)return!1;for(let n in e)if("&"===n[0]){let r=n.slice(1),i=e[n];if(i&&i.length>0){const e=vd(t);for(const t of i)if(!e.has(r+":"+t))return!1}}for(let n in e)if("#"===n[0]){let r=n.slice(1),i=e[n];if(i){const n=e[`&${r}`],o=n?i.filter(e=>!n.includes(e)):i;if(0===o.length)continue;const s=vd(t);if(!1===o.some(e=>s.has(r+":"+e)))return!1}}return!0}function Td(e,t){for(let n=0;n<e.length;n++)if(Pd(e[n],t))return!0;return!1}function Ud(e){return"string"==typeof e&&(e={pubkey:e}),t=>t.replaceable({kind:10063,pubkey:e.pubkey,relays:e.relays}).pipe(fc(e=>e?function(e){const t=Array.isArray(e)?e:e.tags;return Jc(t,e=>Mc(e,"server")&&URL.canParse(e[1])?new URL("/",e[1]):void 0)}(e):[]))}const $d=Symbol.for("profile-content");function Nd(e){return eu(e,$d,()=>{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 Ld(e){return!!e&&((e.kind===hi.Metadata||e.kind===hi.Handlerinformation)&&!!Nd(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 i(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 o(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 i=0;const o=[],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 o=i;o<s.length;o++){const a=s[o],l=n*e+a;if(!Number.isSafeInteger(l)||n*e/n!==e||l-a!==n*e)throw new Error("convertRadix: carry overflow");if(e=l%r,s[o]=Math.floor(l/r),!Number.isSafeInteger(s[o])||s[o]*r+e!==l)throw new Error("convertRadix: carry overflow");t&&(s[o]?t=!1:i=o)}if(o.push(e),t)break}for(let t=0;t<e.length-1&&0===e[t];t++)o.push(0);return o.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 l=(e,t)=>t?l(t,e%t):e,c=(e,t)=>e+(t-l(e,t));function u(e,n,r,i){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(c(n,r)>32)throw new Error(`convertRadix2: carry overflow from=${n} to=${r} carryBits=${c(n,r)}`);let o=0,s=0;const a=2**r-1,l=[];for(const i of e){if(t(i),i>=2**n)throw new Error(`convertRadix2: invalid data word=${i} from=${n}`);if(o=o<<n|i,s+n>32)throw new Error(`convertRadix2: carry overflow pos=${s} from=${n}`);for(s+=n;s>=r;s-=r)l.push((o>>s-r&a)>>>0);o&=2**s-1}if(o=o<<r-s&a,!i&&s>=n)throw new Error("Excess padding");if(!i&&o)throw new Error(`Non-zero padding: ${o}`);return i&&s>0&&l.push(o>>>0),l}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(c(8,e)>32||c(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),i=new Uint8Array(t.length+e);return i.set(t),i.set(r,t.length),i},decode(t){if(!(t instanceof Uint8Array))throw new Error("checksum.decode: input should be Uint8Array");const r=t.slice(0,-e),i=n(r).slice(0,e),o=t.slice(-e);for(let t=0;t<e;t++)if(i[t]!==o[t])throw new Error("Invalid checksum");return r}}}e.utils={alphabet:r,chain:n,checksum:p,radix:d,radix2:f,join:i,padding:o},e.base16=n(f(4),r("0123456789ABCDEF"),i("")),e.base32=n(f(5),r("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"),o(5),i("")),e.base32hex=n(f(5),r("0123456789ABCDEFGHIJKLMNOPQRSTUV"),o(5),i("")),e.base32crockford=n(f(5),r("0123456789ABCDEFGHJKMNPQRSTVWXYZ"),i(""),s(e=>e.toUpperCase().replace(/O/g,"0").replace(/[IL]/g,"1"))),e.base64=n(f(6),r("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),o(6),i("")),e.base64url=n(f(6),r("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"),o(6),i(""));const g=e=>n(d(58),r(e),i(""));e.base58=g("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"),e.base58flickr=g("123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"),e.base58xrp=g("rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz");const m=[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 i=t.subarray(r,r+8);n+=e.base58.encode(i).padStart(m[i.length],"1")}return n},decode(t){let n=[];for(let r=0;r<t.length;r+=11){const i=t.slice(r,r+11),o=m.indexOf(i.length),s=e.base58.decode(i);for(let e=0;e<s.length-o;e++)if(0!==s[e])throw new Error("base58xmr: wrong padding");n=n.concat(Array.from(s.slice(s.length-o)))}return Uint8Array.from(n)}};e.base58check=t=>n(p(4,e=>t(t(e))),e.base58);const y=n(r("qpzry9x8gf2tvdw0s3jn54khce6mua7l"),i("")),w=[996825010,642813549,513874426,1027748829,705979059];function v(e){const t=e>>25;let n=(33554431&e)<<5;for(let e=0;e<w.length;e++)1==(t>>e&1)&&(n^=w[e]);return n}function A(e,t,n=1){const r=e.length;let i=1;for(let t=0;t<r;t++){const n=e.charCodeAt(t);if(n<33||n>126)throw new Error(`Invalid prefix (${e})`);i=v(i)^n>>5}i=v(i);for(let t=0;t<r;t++)i=v(i)^31&e.charCodeAt(t);for(let e of t)i=v(i)^e;for(let e=0;e<6;e++)i=v(i);return i^=n,y.encode(u([i%2**30],30,5,!1))}function b(e){const t="bech32"===e?1:734539939,n=f(5),r=n.decode,i=n.encode,o=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 i=(e=r).lastIndexOf("1");if(0===i||-1===i)throw new Error('Letter "1" must be present between prefix and data only');const o=e.slice(0,i),s=e.slice(i+1);if(s.length<6)throw new Error("Data must be at least 6 characters long");const a=y.decode(s).slice(0,-6),l=A(o,a,t);if(!s.endsWith(l))throw new Error(`Invalid checksum in ${e}: expected "${l}"`);return{prefix:o,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 i=e.length+7+n.length;if(!1!==r&&i>r)throw new TypeError(`Length ${i} exceeds limit ${r}`);return`${e=e.toLowerCase()}1${y.encode(n)}${A(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:o,toWords:i}}e.bech32=b("bech32"),e.bech32m=b("bech32m"),e.utf8={encode:e=>(new TextDecoder).decode(e),decode:e=>(new TextEncoder).encode(e)},e.hex=n(f(4),r("0123456789abcdef"),i(""),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 k={utf8:e.utf8,hex:e.hex,base16:e.base16,base32:e.base32,base64:e.base64,base64url:e.base64url,base58:e.base58,base58xmr:e.base58xmr},I=`Invalid encoding type. Available types: ${Object.keys(k).join(", ")}`;e.bytesToString=(e,t)=>{if("string"!=typeof e||!k.hasOwnProperty(e))throw new TypeError(I);if(!(t instanceof Uint8Array))throw new TypeError("bytesToString() expects Uint8Array");return k[e].encode(t)},e.str=e.bytesToString;e.stringToBytes=(e,t)=>{if(!k.hasOwnProperty(e))throw new TypeError(I);if("string"!=typeof t)throw new TypeError("stringToBytes() expects string");return k[e].decode(t)},e.bytes=e.stringToBytes}({}),BigInt(1e3),BigInt(1e6),BigInt(1e9),BigInt(1e12),BigInt("2100000000000000000"),BigInt(1e11);const Od={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(Od);e<t.length;e++)t[e],Od[t[e]].toString();const Md=Symbol.for("public-contacts"),_d=Symbol.for("hidden-contacts");function Hd(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 eu(e,Md,()=>Jc(e.tags,e=>Hc(e)?e:void 0,ed))}(e),function(e){if(function(e){return pd(e)&&Reflect.has(e,_d)}(e))return e[_d];const t=gd(e);if(!t)return;const n=Jc(t,e=>Hc(e)?e:void 0,ed);return Reflect.set(e,_d,n),n}(e))}Bd.extend("EncryptedContentCache"),Bd.extend("event-cache"),new TextDecoder;const jd=Symbol.for("mailboxes-inboxes"),Gd=Symbol.for("mailboxes-outboxes");function Kd(e){return eu(e,jd,()=>{const t=[];for(const n of e.tags)if(jc(n))try{const[,e,r]=n;!e||!Cu(e)||t.includes(e)||"read"!==r&&void 0!==r||t.push(bu(e))}catch{}return t})}function Jd(e){return eu(e,Gd,()=>{const t=[];for(const n of e.tags)if(jc(n))try{const[e,r,i]=n;"r"!==e||!Cu(r)||t.includes(r)||"write"!==i&&void 0!==i||t.push(bu(r))}catch{}return t})}const Vd=Symbol.for("mute-public"),qd=Symbol.for("mute-hidden");function zd(e){return{pubkeys:new Set(e.filter(Hc).map(e=>e[1])),threads:new Set(e.filter(_c).map(e=>e[1])),hashtags:new Set(e.filter(Kc).map(e=>e[1].toLocaleLowerCase())),words:new Set(e.filter(e=>"word"===e[0]&&e[1]).map(e=>e[1].toLocaleLowerCase()))}}function Yd(e){const t=function(e){if(function(e){return pd(e)&&Reflect.has(e,qd)}(e))return e[qd];const t=gd(e);if(!t)return;const n=zd(t);return Reflect.set(e,qd,n),n}(e),n=function(e){return eu(e,Vd,()=>zd(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 Wd;!function(e){e.nudity="nudity",e.malware="malware",e.profanity="profanity",e.illegal="illegal",e.spam="spam",e.impersonation="impersonation",e.other="other"}(Wd||(Wd={}));const Zd=Symbol.for("nip10-thread-refs");function Xd(e){if(!e[1])throw new Error("Missing event id in tag");let t={id:e[1]};return e[2]&&Cu(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 ef(e){return t=>{const n=new Set;return t.pipe(Oc(t=>{if(void 0!==t)if(Array.isArray(t))for(const r of t)n.has(r)||(n.add(r),e.claim(r));else n.has(t)||(n.add(t),e.claim(t))}),Pc(()=>{for(const t of n)e.removeClaim(t)}))}}function tf(e){return t=>{let n;return t.pipe(Oc(t=>{n!==t&&(n&&e.removeClaim(n),t&&e.claim(t),n=t)}),Pc(()=>{n&&e.removeClaim(n)}))}}function nf(){return e=>e.pipe(Sc(e=>null!=e))}function rf(e){return t=>new Bl(n=>{let r=!1;const i=t.subscribe({next:e=>{r=!0,n.next(e)},error:e=>n.error(e),complete:()=>n.complete()});return r||n.next(e),i})}function of(e){return"string"==typeof e&&(e={id:e}),t=>Bc(Cc(()=>function(e,t){const n=e.getEvent(t.id);return n instanceof Promise?uc(n):dc(n)}(t,e)).pipe(function(e,t){return Lc(n=>n?dc(n):e.eventLoader?uc(e.eventLoader(t)):jl)}(t,e),nf()),t.insert$.pipe(Sc(t=>t.id===e.id)),t.remove$.pipe(Sc(t=>t.id===e.id),Fc(1),Fl(function(e,t){e.subscribe(Ql(t,ml))}),Dc(void 0))).pipe(tf(t),Qc((e,t)=>e?.id===t?.id),rf(void 0))}function sf(e){return t=>{let n;return Bc(Cc(()=>function(e,t){const n=e.getReplaceable(t.kind,t.pubkey,t.identifier);return n instanceof Promise?uc(n):dc(n)}(t,e)).pipe(function(e,t){return Lc(n=>n?dc(n):void 0!==t.identifier?e.addressableLoader?uc(e.addressableLoader(t)).pipe(Sc(e=>!!e)):jl:e.replaceableLoader?uc(e.replaceableLoader(t)).pipe(Sc(e=>!!e)):jl)}(t,e),nf()),t.insert$.pipe(Sc(t=>t.pubkey==e.pubkey&&t.kind===e.kind&&(void 0===e.identifier||fu(t)===e.identifier)))).pipe(Qc((e,t)=>e.created_at>=t.created_at),Oc(e=>n=e),(r=t.remove$.pipe(Sc(e=>e.id===n?.id)),Fl(function(e,t){rc(r).subscribe(Ql(t,function(){return t.complete()},ml)),!t.closed&&e.subscribe(t)})),Dc(void 0),function(e){var t,n,r=1/0;return null!=e&&("object"==typeof e?(t=e.count,r=void 0===t?1/0:t,n=e.delay):r=e),r<=0?function(){return jl}:Fl(function(e,t){var i,o=0,s=function(){if(null==i||i.unsubscribe(),i=null,null!=n){var e="number"==typeof n?xc(n):rc(n(o)),r=Ql(t,function(){r.unsubscribe(),a()});e.subscribe(r)}else a()},a=function(){var n=!1;i=e.subscribe(Ql(t,void 0,function(){++o<r?i?s():n=!0:t.complete()})),n&&s()};a()})}(),tf(t),rf(void 0));var r}}function af(e,t){return e=Array.isArray(e)?e:[e],n=>{const r=new Map;return Cc(()=>{const t=n.getTimeline(e);return t instanceof Promise?uc(t):dc(t)}).pipe(ef(n),Uc(n.insert$.pipe(Sc(t=>Td(e,t)),ef(n))),Uc(n.remove$.pipe(Sc(t=>Td(e,t)),fc(e=>e.id))),$c((e,n)=>{if("string"==typeof n)return e.filter(e=>e.id!==n);if(Array.isArray(n)){if(!t)for(const e of n)lu(e.kind)&&r.set(cu(e),e);return n}let i=[...e];if(!t&&lu(n.kind)){const t=cu(n),o=r.get(t);if(o&&n.created_at<o.created_at)return e;r.set(t,n),o&&i.slice(i.indexOf(o),1)}return tu(i,n),i},[]),Qc(),Pc(()=>r.clear()))}}function lf(e){return t=>Ac(Object.fromEntries(e.map(e=>[e,t.model(of,{id:e})])))}function cf(e){return t=>Ac(Object.fromEntries(e.map(e=>[du(e.kind,e.pubkey,e.identifier),t.model(sf,e)])))}function uf(e){return t=>{let n;return Bc(t.pipe(Oc(e=>n=e)),e.update$.pipe(Sc(e=>e.id===n?.id)))}}function df(e){return"string"==typeof e&&(e={pubkey:e}),t=>t.replaceable({kind:hi.Contacts,pubkey:e.pubkey,relays:e.relays}).pipe(uf(t),fc(e=>e?Hd(e):[]))}function ff(e){return t=>{const n=[{kinds:[1111],"#e":[e.id]}];return qa(e.kind)&&n.push({kinds:[1111],"#a":[uu(e)]}),t.timeline(n)}}function hf(e){return"string"==typeof e&&(e={pubkey:e}),t=>t.replaceable({kind:hi.RelayList,pubkey:e.pubkey,relays:e.relays}).pipe(fc(e=>e&&{inboxes:Kd(e),outboxes:Jd(e)}))}function pf(e){return"string"==typeof e&&(e={pubkey:e}),t=>t.replaceable({kind:hi.Mutelist,pubkey:e.pubkey,relays:e.relays}).pipe(uf(t),fc(e=>e&&Yd(e)))}function gf(e){return"string"==typeof e&&(e={pubkey:e}),t=>t.replaceable({kind:hi.Metadata,pubkey:e.pubkey,relays:e.relays}).pipe(Sc(Ld),fc(e=>e&&Nd(e)),rf(void 0))}function mf(e){return t=>t.timeline(lu(e.kind)?[{kinds:[hi.Reaction],"#e":[e.id]},{kinds:[hi.Reaction],"#a":[cu(e)]}]:[{kinds:[hi.Reaction],"#e":[e.id]}])}const yf={kinds:[hi.ShortTextNote]};function wf(e,t){const n=new Map,r=new Map,{kinds:i}={...yf,...t};let o="";const s={},a={kinds:i};var l;return"string"!=typeof(l=e)&&Reflect.has(l,"identifier")&&Reflect.has(l,"pubkey")&&Reflect.has(l,"kind")?(o=td(e),s.kinds=[e.kind],s.authors=[e.pubkey],s["#d"]=[e.identifier],a["#a"]=[o]):"string"==typeof e?(o=e,s.ids=[e],a["#e"]=[e]):(o=e.id,s.ids=[e.id],a["#e"]=[e.id]),e=>e.filters([s,a]).pipe(fc(e=>{if(!r.has(cu(e))){const t=function(e){return eu(e,Zd,()=>{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]),i=t.find(e=>"reply"===e[3]),o=n.find(e=>"root"===e[3]),s=n.find(e=>"reply"===e[3]);if(r&&i||(r=i=r||i),o&&s||(o=s=o||s),!r&&!i){const e=t.filter(e=>!e[3]);e.length>=1&&(r=e[0],i=e[e.length-1]??r)}return{root:r||o?{e:r,a:o}:void 0,reply:i||s?{e:i,a:s}:void 0}}(e.tags);let n,r;if(t.root)try{n={e:t.root.e&&Xd(t.root.e),a:t.root.a&&Xu(t.root.a)}}catch(e){}if(t.reply)try{r={e:t.reply.e&&Xd(t.reply.e),a:t.reply.a&&Xu(t.reply.a)}}catch(e){}return{root:n,reply:r}})}(e),i=n.get(cu(e))||new Set,o={event:e,refs:t,replies:i};for(const e of i)e.parent=o;if(t.reply?.e||t.reply?.a){let e=t.reply.e?t.reply.e.id:td(t.reply.a);if(o.parent=r.get(e),o.parent)o.parent.replies.add(o);else{let t=n.get(e);t||(t=new Set,n.set(e,t)),t.add(o)}}r.set(cu(e),o)}return{root:r.get(o),all:r}}))}function vf(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):Dd(t);let i=n.get(r);if(!i){const o=()=>{n.get(r)===i&&n.delete(r)};i=e(...t)(this).pipe(Pc(o),function(e){void 0===e&&(e={});var t=e.connector,n=void 0===t?function(){return new Pl}:t,r=e.resetOnError,i=void 0===r||r,o=e.resetOnComplete,s=void 0===o||o,a=e.resetOnRefCountZero,l=void 0===a||a;return function(e){var t,r,o,a=0,c=!1,u=!1,d=function(){null==r||r.unsubscribe(),r=void 0},f=function(){d(),t=o=void 0,c=u=!1},h=function(){var e=t;f(),null==e||e.unsubscribe()};return Fl(function(e,p){a++,u||c||d();var g=o=null!=o?o:n();p.add(function(){0!==--a||u||c||(r=Nc(h,l))}),g.subscribe(p),!t&&a>0&&(t=new kl({next:function(e){return g.next(e)},error:function(e){u=!0,d(),r=Nc(f,i,e),g.error(e)},complete:function(){c=!0,d(),r=Nc(f,s),g.complete()}}),rc(e).subscribe(t))})(e)}}({connector:()=>new $l(1),resetOnComplete:()=>xc(this.modelKeepWarm),resetOnRefCountZero:()=>xc(this.modelKeepWarm)})),n.set(r,i)}return i}filters(e,t=!1){e=Array.isArray(e)?e:[e];const n=this.getByFilters(e);return Bc(t?jl:n&&"function"==typeof n.then?uc(n).pipe(kc(e=>uc(Array.from(e)))):uc(Array.from(n)),this.insert$.pipe(Sc(t=>Td(e,t))))}event(e){return"string"==typeof e&&(e={id:e}),this.model(of,e)}replaceable(...e){let t;if(1===e.length)t=e[0];else if(3===e.length||2===e.length){let[n,r,i]=e;t={kind:n,pubkey:r,identifier:i}}if(!t)throw new Error("Invalid arguments, expected address pointer or kind, pubkey, identifier");return this.model(sf,t)}addressable(e){return this.model(sf,e)}timeline(e,t=!1){return this.model(af,e,t)}profile(e){return this.model(gf,e)}contacts(e){return"string"==typeof e&&(e={pubkey:e}),this.model(df,e)}mutes(e){return"string"==typeof e&&(e={pubkey:e}),this.model(pf,e)}mailboxes(e){return"string"==typeof e&&(e={pubkey:e}),this.model(hf,e)}blossomServers(e){return"string"==typeof e&&(e={pubkey:e}),this.model(Ud,e)}reactions(e){return this.model(mf,e)}thread(e){return this.model(wf,e)}comments(e){return this.model(ff,e)}events(e){return this.model(lf,e)}replaceableSet(e){return this.model(cf,e)}}}class Af extends(vf(class{})){database;memory;keepOldVersions=!1;keepExpired=!1;verifyEvent;insert$=new Pl;update$=new Pl;remove$=new Pl;eventLoader;replaceableLoader;addressableLoader;constructor(e=new Sd){super(),e?(this.database=e,this.memory=new Sd):this.database=this.memory=new Sd,this.insert$.subscribe(e=>{Reflect.set(e,ru,this)}),this.remove$.subscribe(e=>{Reflect.deleteProperty(e,ru)})}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(qa(e.kind)){const t=e.tags.find(e=>"d"===e[0])?.[1],n=this.deletedCoords.get(du(e.kind,e.pubkey,t));if(n)return n>e.created_at}return!1}expirations=new Map;addExpiration(e){const t=gu(e);t&&Number.isFinite(t)&&this.expirations.set(e.id,t)}expirationTimeout=null;nextExpirationCheck=null;handleExpiringEvent(e){const t=gu(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-hu();this.expirationTimeout=setTimeout(this.pruneExpired.bind(this),1e3*n+10),this.nextExpirationCheck=t}pruneExpired(){const e=hu();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(_c).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(Gc).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=Zu(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[ku];if(n)for(const e of n)Iu(t,e);const r=Reflect.get(e,su);r&&!Reflect.get(t,su)&&Reflect.set(t,su,r)}add(e,t){if(e.kind===hi.EventDeletion&&this.handleDeleteEvent(e),this.checkDeleted(e))return e;const n=gu(e);if(!1===this.keepExpired&&n&&n<=hu())return null;const r=lu(e.kind)?e.tags.find(e=>"d"===e[0])?.[1]:void 0;if(!this.keepOldVersions&&lu(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 Af.mergeDuplicateEvent(e,t[0]),t[0]}if(this.verifyEvent&&!1===this.verifyEvent(e))return null;const i=this.memory?.add(e);if(i&&i!==e)return Af.mergeDuplicateEvent(e,i),t&&Iu(i,t),i;const o=this.mapToMemory(this.database.add(e));if(e!==o&&Af.mergeDuplicateEvent(e,o),t&&Iu(o,t),o===e&&this.insert$.next(o),!this.keepOldVersions&&lu(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(o),o}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){return this.memory?.claim(e)}isClaimed(e){return this.memory?.isClaimed(e)??!1}removeClaim(e){return this.memory?.removeClaim(e)}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)?jl:this.remove$.pipe(Sc(t=>t.id===e),Fc(1),kc(()=>jl))}updated(e){return this.update$.pipe(Sc(t=>t.id===e||t===e))}}function bf(){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 kf,If;ad(hi.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"}(kf||(kf={})),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"}(If||(If={}));class Ef{key;constructor(e){this.key=e||ci()}async getPublicKey(){return ui(this.key)}async signEvent(e){return di(e,this.key)}nip04={encrypt:async(e,t)=>hs.encrypt(this.key,e,t),decrypt:async(e,t)=>hs.decrypt(this.key,e,t)};nip44={encrypt:async(e,t)=>Qs.v2.encrypt(t,Qs.v2.utils.getConversationKey(this.key,e)),decrypt:async(e,t)=>Qs.v2.decrypt(t,Qs.v2.utils.getConversationKey(this.key,e))};static fromKey(e){return new Ef(function(e){if(e instanceof Uint8Array)return e;if(xu(e))return Ju(e);{const t=Wo.decode(e);if("nsec"!==t.type)throw new Error(`Cant get secret key from ${t.type}`);return t.data}}(e))}}
/*! noble-secp256k1 - MIT License (c) 2019 Paul Miller (paulmillr.com) */const Cf=BigInt(0),xf=BigInt(1),Bf=BigInt(2),Sf=BigInt(3),Ff=BigInt(8),Qf=Object.freeze({a:Cf,b:BigInt(7),P:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:xf,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee")}),Rf=(e,t)=>(e+t/Bf)/t,Df={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar(e){const{n:t}=Qf,n=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),r=-xf*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),i=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),o=n,s=BigInt("0x100000000000000000000000000000000"),a=Rf(o*e,t),l=Rf(-r*e,t);let c=rh(e-a*n-l*i,t),u=rh(-a*r-l*o,t);const d=c>s,f=u>s;if(d&&(c=t-c),f&&(u=t-u),c>s||u>s)throw new Error("splitScalarEndo: Endomorphism failed, k="+e);return{k1neg:d,k1:c,k2neg:f,k2:u}}},Pf=32;function Tf(e){const{a:t,b:n}=Qf,r=rh(e*e),i=rh(r*e);return rh(i+t*e+n)}const Uf=Qf.a===Cf;function $f(e){if(!(e instanceof Nf))throw new TypeError("JacobianPoint expected")}class Nf{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)?Nf.ZERO:new Nf(e.x,e.y,xf)}static toAffineBatch(e){const t=function(e,t=Qf.P){const n=new Array(e.length),r=e.reduce((e,r,i)=>r===Cf?e:(n[i]=e,rh(e*r,t)),xf),i=oh(r,t);return e.reduceRight((e,r,i)=>r===Cf?e:(n[i]=rh(e*n[i],t),rh(e*r,t)),i),n}(e.map(e=>e.z));return e.map((e,n)=>e.toAffine(t[n]))}static normalizeZ(e){return Nf.toAffineBatch(e).map(Nf.fromAffine)}equals(e){$f(e);const{x:t,y:n,z:r}=this,{x:i,y:o,z:s}=e,a=rh(r*r),l=rh(s*s),c=rh(t*l),u=rh(i*a),d=rh(rh(n*s)*l),f=rh(rh(o*r)*a);return c===u&&d===f}negate(){return new Nf(this.x,rh(-this.y),this.z)}double(){const{x:e,y:t,z:n}=this,r=rh(e*e),i=rh(t*t),o=rh(i*i),s=e+i,a=rh(Bf*(rh(s*s)-r-o)),l=rh(Sf*r),c=rh(l*l),u=rh(c-Bf*a),d=rh(l*(a-u)-Ff*o),f=rh(Bf*t*n);return new Nf(u,d,f)}add(e){$f(e);const{x:t,y:n,z:r}=this,{x:i,y:o,z:s}=e;if(i===Cf||o===Cf)return this;if(t===Cf||n===Cf)return e;const a=rh(r*r),l=rh(s*s),c=rh(t*l),u=rh(i*a),d=rh(rh(n*s)*l),f=rh(rh(o*r)*a),h=rh(u-c),p=rh(f-d);if(h===Cf)return p===Cf?this.double():Nf.ZERO;const g=rh(h*h),m=rh(h*g),y=rh(c*g),w=rh(p*p-m-Bf*y),v=rh(p*(y-w)-d*m),A=rh(r*s*h);return new Nf(w,v,A)}subtract(e){return this.add(e.negate())}multiplyUnsafe(e){const t=Nf.ZERO;if("bigint"==typeof e&&e===Cf)return t;let n=nh(e);if(n===xf)return this;if(!Uf){let e=t,r=this;for(;n>Cf;)n&xf&&(e=e.add(r)),r=r.double(),n>>=xf;return e}let{k1neg:r,k1:i,k2neg:o,k2:s}=Df.splitScalar(n),a=t,l=t,c=this;for(;i>Cf||s>Cf;)i&xf&&(a=a.add(c)),s&xf&&(l=l.add(c)),c=c.double(),i>>=xf,s>>=xf;return r&&(a=a.negate()),o&&(l=l.negate()),l=new Nf(rh(l.x*Df.beta),l.y,l.z),a.add(l)}precomputeWindow(e){const t=Uf?128/e+1:256/e+1,n=[];let r=this,i=r;for(let o=0;o<t;o++){i=r,n.push(i);for(let t=1;t<2**(e-1);t++)i=i.add(r),n.push(i);r=i.double()}return n}wNAF(e,t){!t&&this.equals(Nf.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&&Of.get(t);r||(r=this.precomputeWindow(n),t&&1!==n&&(r=Nf.normalizeZ(r),Of.set(t,r)));let i=Nf.ZERO,o=Nf.BASE;const s=1+(Uf?128/n:256/n),a=2**(n-1),l=BigInt(2**n-1),c=2**n,u=BigInt(n);for(let t=0;t<s;t++){const n=t*a;let s=Number(e&l);e>>=u,s>a&&(s-=c,e+=xf);const d=n,f=n+Math.abs(s)-1,h=t%2!=0,p=s<0;0===s?o=o.add(Lf(h,r[d])):i=i.add(Lf(p,r[f]))}return{p:i,f:o}}multiply(e,t){let n,r,i=nh(e);if(Uf){const{k1neg:e,k1:o,k2neg:s,k2:a}=Df.splitScalar(i);let{p:l,f:c}=this.wNAF(o,t),{p:u,f:d}=this.wNAF(a,t);l=Lf(e,l),u=Lf(s,u),u=new Nf(rh(u.x*Df.beta),u.y,u.z),n=l.add(u),r=c.add(d)}else{const{p:e,f:o}=this.wNAF(i,t);n=e,r=o}return Nf.normalizeZ([n,r])[0]}toAffine(e){const{x:t,y:n,z:r}=this,i=this.equals(Nf.ZERO);null==e&&(e=i?Ff:oh(r));const o=e,s=rh(o*o),a=rh(s*o),l=rh(t*s),c=rh(n*a),u=rh(r*o);if(i)return Mf.ZERO;if(u!==xf)throw new Error("invZ was invalid");return new Mf(l,c)}}function Lf(e,t){const n=t.negate();return e?n:t}Nf.BASE=new Nf(Qf.Gx,Qf.Gy,xf),Nf.ZERO=new Nf(Cf,xf,Cf);const Of=new WeakMap;class Mf{constructor(e,t){this.x=e,this.y=t}_setWindowSize(e){this._WINDOW_SIZE=e,Of.delete(this)}hasEvenY(){return this.y%Bf===Cf}static fromCompressedHex(e){const t=32===e.length,n=eh(t?e:e.subarray(1));if(!ah(n))throw new Error("Point is not on curve");let r=function(e){const{P:t}=Qf,n=BigInt(6),r=BigInt(11),i=BigInt(22),o=BigInt(23),s=BigInt(44),a=BigInt(88),l=e*e*e%t,c=l*l*e%t,u=ih(c,Sf)*c%t,d=ih(u,Sf)*c%t,f=ih(d,Bf)*l%t,h=ih(f,r)*f%t,p=ih(h,i)*h%t,g=ih(p,s)*p%t,m=ih(g,a)*g%t,y=ih(m,s)*p%t,w=ih(y,Sf)*c%t,v=ih(w,o)*h%t,A=ih(v,n)*l%t,b=ih(A,Bf);if(b*b%t!==e)throw new Error("Cannot find square root");return b}(Tf(n));const i=(r&xf)===xf;if(t)i&&(r=rh(-r));else{!(1&~e[0])!==i&&(r=rh(-r))}const o=new Mf(n,r);return o.assertValidity(),o}static fromUncompressedHex(e){const t=eh(e.subarray(1,33)),n=eh(e.subarray(33,65)),r=new Mf(t,n);return r.assertValidity(),r}static fromHex(e){const t=th(e),n=t.length,r=t[0];if(n===Pf)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=Xf(e)}else{if(!Gf(e))throw new TypeError("Expected valid private key");if(32!==e.length)throw new Error("Expected 32 bytes of private key");t=eh(e)}if(!sh(t))throw new Error("Expected private key: 0 < key < n");return t}(e))}static fromSignature(e,t,n){const{r:r,s:i}=function(e){if(e instanceof jf)return e.assertValidity(),e;try{return jf.fromDER(e)}catch(t){return jf.fromCompact(e)}}(t);if(![0,1,2,3].includes(n))throw new Error("Cannot recover: invalid recovery bit");const o=function(e,t=!1){const n=function(e){const t=8*e.length-256,n=eh(e);return t>0?n>>BigInt(t):n}(e);if(t)return n;const{n:r}=Qf;return n>=r?n-r:n}(th(e)),{n:s}=Qf,a=2===n||3===n?r+s:r,l=oh(a,s),c=rh(-o*l,s),u=rh(i*l,s),d=1&n?"03":"02",f=Mf.fromHex(d+Wf(a)),h=Mf.BASE.multiplyAndAddUnsafe(f,c,u);if(!h)throw new Error("Cannot recover signature: point at infinify");return h.assertValidity(),h}toRawBytes(e=!1){return zf(this.toHex(e))}toHex(e=!1){const t=Wf(this.x);if(e){return`${this.hasEvenY()?"02":"03"}${t}`}return`04${t}${Wf(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(!ah(t)||!ah(n))throw new Error(e);const r=rh(n*n);if(rh(r-Tf(t))!==Cf)throw new Error(e)}equals(e){return this.x===e.x&&this.y===e.y}negate(){return new Mf(this.x,rh(-this.y))}double(){return Nf.fromAffine(this).double().toAffine()}add(e){return Nf.fromAffine(this).add(Nf.fromAffine(e)).toAffine()}subtract(e){return this.add(e.negate())}multiply(e){return Nf.fromAffine(this).multiply(e,this).toAffine()}multiplyAndAddUnsafe(e,t,n){const r=Nf.fromAffine(this),i=t===Cf||t===xf||this!==Mf.BASE?r.multiplyUnsafe(t):r.multiply(t),o=Nf.fromAffine(e).multiplyUnsafe(n),s=i.add(o);return s.equals(Nf.ZERO)?void 0:s.toAffine()}}function _f(e){return Number.parseInt(e[0],16)>=8?"00"+e:e}function Hf(e){if(e.length<2||2!==e[0])throw new Error(`Invalid signature integer tag: ${Jf(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:eh(n),left:e.subarray(t+2)}}Mf.BASE=new Mf(Qf.Gx,Qf.Gy),Mf.ZERO=new Mf(Cf,Cf);class jf{constructor(e,t){this.r=e,this.s=t,this.assertValidity()}static fromCompact(e){const t=Gf(e),n="Signature.fromCompact";if("string"!=typeof e&&!t)throw new TypeError(`${n}: Expected string or Uint8Array`);const r=t?Jf(e):e;if(128!==r.length)throw new Error(`${n}: Expected 64-byte hex`);return new jf(Xf(r.slice(0,64)),Xf(r.slice(64,128)))}static fromDER(e){const t=Gf(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: ${Jf(e)}`);if(e[1]!==e.length-2)throw new Error("Invalid signature: incorrect length");const{data:t,left:n}=Hf(e.subarray(2)),{data:r,left:i}=Hf(n);if(i.length)throw new Error(`Invalid signature: left bytes after parsing: ${Jf(i)}`);return{r:t,s:r}}(t?e:zf(e));return new jf(n,r)}static fromHex(e){return this.fromDER(e)}assertValidity(){const{r:e,s:t}=this;if(!sh(e))throw new Error("Invalid Signature: r must be 0 < r < n");if(!sh(t))throw new Error("Invalid Signature: s must be 0 < s < n")}hasHighS(){const e=Qf.n>>xf;return this.s>e}normalizeS(){return this.hasHighS()?new jf(this.r,rh(-this.s,Qf.n)):this}toDERRawBytes(){return zf(this.toDERHex())}toDERHex(){const e=_f(Zf(this.s)),t=_f(Zf(this.r)),n=e.length/2,r=t.length/2,i=Zf(n),o=Zf(r);return`30${Zf(r+n+4)}02${o}${t}02${i}${e}`}toRawBytes(){return this.toDERRawBytes()}toHex(){return this.toDERHex()}toCompactRawBytes(){return zf(this.toCompactHex())}toCompactHex(){return Wf(this.r)+Wf(this.s)}}function Gf(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&"Uint8Array"===e.constructor.name}const Kf=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Jf(e){!function(e){if(!Gf(e))throw new Error("Uint8Array expected")}(e);let t="";for(let n=0;n<e.length;n++)t+=Kf[e[n]];return t}const Vf={_0:48,_9:57,A:65,F:70,a:97,f:102};function qf(e){return e>=Vf._0&&e<=Vf._9?e-Vf._0:e>=Vf.A&&e<=Vf.F?e-(Vf.A-10):e>=Vf.a&&e<=Vf.f?e-(Vf.a-10):void 0}function zf(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,i=0;t<n;t++,i+=2){const n=qf(e.charCodeAt(i)),o=qf(e.charCodeAt(i+1));if(void 0===n||void 0===o){const t=e[i]+e[i+1];throw new Error('hex string expected, got non-hex character "'+t+'" at index '+i)}r[t]=16*n+o}return r}const Yf=BigInt("0x10000000000000000000000000000000000000000000000000000000000000000");function Wf(e){if("bigint"!=typeof e)throw new Error("Expected bigint");if(!(Cf<=e&&e<Yf))throw new Error("Expected number 0 <= n < 2^256");return e.toString(16).padStart(64,"0")}function Zf(e){const t=e.toString(16);return 1&t.length?`0${t}`:t}function Xf(e){if("string"!=typeof e)throw new TypeError("hexToNumber: expected string, got "+typeof e);return BigInt(`0x${e}`)}function eh(e){return Xf(Jf(e))}function th(e){return Gf(e)?Uint8Array.from(e):zf(e)}function nh(e){if("number"==typeof e&&Number.isSafeInteger(e)&&e>0)return BigInt(e);if("bigint"==typeof e&&sh(e))return e;throw new TypeError("Expected valid private scalar: 0 < scalar < curve.n")}function rh(e,t=Qf.P){const n=e%t;return n>=Cf?n:t+n}function ih(e,t){const{P:n}=Qf;let r=e;for(;t-- >Cf;)r*=r,r%=n;return r}function oh(e,t=Qf.P){if(e===Cf||t<=Cf)throw new Error(`invert: expected positive integers, got n=${e} mod=${t}`);let n=rh(e,t),r=t,i=Cf,o=xf;for(;n!==Cf;){const e=r%n,t=i-o*(r/n);r=n,n=e,i=o,o=t}if(r!==xf)throw new Error("invert: does not exist");return rh(i,t)}function sh(e){return Cf<e&&e<Qf.n}function ah(e){return Cf<e&&e<Qf.P}
/*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) */
function lh(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&"Uint8Array"===e.constructor.name}function ch(e,t){return!!Array.isArray(t)&&(0===t.length||(e?t.every(e=>"string"==typeof e):t.every(e=>Number.isSafeInteger(e))))}function uh(e,t){if("string"!=typeof t)throw new Error(`${e}: string expected`);return!0}function dh(e){if(!Number.isSafeInteger(e))throw new Error(`invalid integer: ${e}`)}function fh(e){if(!Array.isArray(e))throw new Error("array expected")}function hh(e,t){if(!ch(!0,t))throw new Error(`${e}: array of strings expected`)}Mf.BASE._setWindowSize(8);const ph=(e,t)=>0===t?e:ph(t,e%t),gh=(e,t)=>e+(t-ph(e,t)),mh=(()=>{let e=[];for(let t=0;t<40;t++)e.push(2**t);return e})();function yh(e,t,n,r){if(fh(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(gh(t,n)>32)throw new Error(`convertRadix2: carry overflow from=${t} to=${n} carryBits=${gh(t,n)}`);let i=0,o=0;const s=mh[t],a=mh[n]-1,l=[];for(const r of e){if(dh(r),r>=s)throw new Error(`convertRadix2: invalid data word=${r} from=${t}`);if(i=i<<t|r,o+t>32)throw new Error(`convertRadix2: carry overflow pos=${o} from=${t}`);for(o+=t;o>=n;o-=n)l.push((i>>o-n&a)>>>0);const e=mh[o];if(void 0===e)throw new Error("invalid carry");i&=e-1}if(i=i<<n-o&a,!r&&o>=t)throw new Error("Excess padding");if(!r&&i>0)throw new Error(`Non-zero padding: ${i}`);return r&&o>0&&l.push(i>>>0),l}const wh=(()=>"function"==typeof Uint8Array.from([]).toBase64&&"function"==typeof Uint8Array.fromBase64)()?{encode:e=>(function(e,...t){if(!lh(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)=>{uh("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(dh(e),e<=0||e>32)throw new Error("radix2: bits should be in (0..32]");if(gh(8,e)>32||gh(e,8)>32)throw new Error("radix2: carry overflow");return{encode:n=>{if(!lh(n))throw new Error("radix2.encode input should be Uint8Array");return yh(Array.from(n),8,e,!t)},decode:n=>(function(e,t){if(!ch(!1,t))throw new Error(`${e}: array of numbers expected`)}("radix2.decode",n),Uint8Array.from(yh(n,e,8,t)))}}(6),function(e){const t="string"==typeof e?e.split(""):e,n=t.length;hh("alphabet",t);const r=new Map(t.map((e,t)=>[e,t]));return{encode:r=>(fh(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=>(fh(t),t.map(t=>{uh("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 dh(e),uh("padding",t),{encode(n){for(hh("padding.encode",n);n.length*e%8;)n.push(t);return n},decode(n){hh("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 uh("join",e),{encode:t=>(hh("join.decode",t),t.join(e)),decode:t=>(uh("join.decode",t),t.split(e))}}(""));function vh(e){return Mf.fromHex(e).toHex().substring(2)}const Ah=new TextDecoder("utf-8"),bh=new TextEncoder;class kh{log=Bd.extend("SerialPortSigner");writer=null;pubkey;get isConnected(){return!!this.writer}verifyEvent=fi;nip04;constructor(){this.nip04={encrypt:this.nip04Encrypt.bind(this),decrypt:this.nip04Decrypt.bind(this)}}lastCommand=null;async callMethodOnDevice(e,t,n={}){if(!kh.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=bf();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 i,o=await window.navigator.serial.requestPort();await o.open({baudRate:9600}),await(e=>new Promise(t=>setTimeout(t,e)))(1e3),(async()=>{for(;o&&o.readable;){const e=new window.TextDecoderStream;o.readable.pipeTo(e.writable),i=e.readable.getReader();const t=this.readFromSerialPort(i);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===kh.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(o.writable),this.writer=s.writable.getWriter(),await this.sendCommand(kh.METHOD_PING),await this.sendCommand(kh.METHOD_PING,[window.location.host]),e&&e(),o.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 i=[];for(t&&(i.push(t),t=void 0);;){const{value:o,done:s}=await e.read();if(o){const e=o.split(r);if(e.length>1)return i.push(e.shift()),t=e.pop(),n=e,{value:i.join("").trim(),done:!1};i.push(o)}if(s)return{value:i.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=Ju(await this.callMethodOnDevice(kh.METHOD_SHARED_SECRET,[vh(e)]));let r=Uint8Array.from(Wu(16)),i=bh.encode(t),o=await crypto.subtle.importKey("raw",n,{name:"AES-CBC"},!1,["encrypt"]),s=await crypto.subtle.encrypt({name:"AES-CBC",iv:r},o,i);return`${wh.encode(new Uint8Array(s))}?iv=${wh.encode(new Uint8Array(r.buffer))}`}async nip04Decrypt(e,t){let[n,r]=t.split("?iv=");const i=Ju(await this.callMethodOnDevice(kh.METHOD_SHARED_SECRET,[vh(e)]));let o=await crypto.subtle.importKey("raw",i,{name:"AES-CBC"},!1,["decrypt"]),s=wh.decode(n),a=wh.decode(r),l=await crypto.subtle.decrypt({name:"AES-CBC",iv:a},o,s);return Ah.decode(l)}async getPublicKey(){const e=await this.callMethodOnDevice(kh.METHOD_PUBLIC_KEY,[]);return this.pubkey=e,e}async restore(e){await this.callMethodOnDevice(kh.METHOD_RESTORE,[Lu(e)])}async signEvent(e){const t=e.pubkey||this.pubkey;if(!t)throw new Error("Unknown signer pubkey");const n={...e,id:ai({...e,pubkey:t})},r=await this.callMethodOnDevice(kh.METHOD_SIGN_MESSAGE,[n.id]),i={...n,sig:r,pubkey:t};if(!this.verifyEvent(i))throw new Error("Invalid signature");return i}ping(){this.sendCommand(kh.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=[kh.METHOD_PUBLIC_KEY,kh.METHOD_SIGN_MESSAGE,kh.METHOD_SHARED_SECRET,kh.METHOD_RESTORE]}const Ih=[`${window.location.protocol.startsWith("https")?"wss:":"ws:"}//${window.location.host}/`],Eh=[{value:0,label:"User Metadata (0)"},{value:3,label:"Follows (3)"},{value:1e4,label:"Mute list (10000)"},{value:10001,label:"Pin list (10001)"},{value:10002,label:"Relay List Metadata (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:10009,label:"User groups (10009)"},{value:10012,label:"Favorite relays list (10012)"},{value:10013,label:"Private event relay list (10013)"},{value:10015,label:"Interests list (10015)"},{value:10019,label:"Nutzap Mint Recommendation (10019)"},{value:10020,label:"Media follows (10020)"},{value:10030,label:"User emoji list (10030)"},{value:10050,label:"Relay list to receive DMs (10050)"},{value:10051,label:"KeyPackage Relays List (10051)"},{value:10063,label:"User server list (10063)"},{value:10096,label:"File storage server list (10096)"},{value:10166,label:"Relay Monitor Announcement (10166)"},{value:10312,label:"Room Presence (10312)"},{value:10377,label:"Proxy Announcement (10377)"},{value:11111,label:"Transport Method Announcement (11111)"},{value:13194,label:"Wallet Info (13194)"},{value:17375,label:"Cashu Wallet Event (17375)"},{value:3e4,label:"Follow sets (30000)"},{value:30001,label:"Generic lists (30001)"},{value:30002,label:"Relay sets (30002)"},{value:30003,label:"Bookmark sets (30003)"},{value:30004,label:"Curation sets (30004)"},{value:30005,label:"Video sets (30005)"},{value:30007,label:"Kind mute sets (30007)"},{value:30008,label:"Profile Badges (30008)"},{value:30009,label:"Badge Definition (30009)"},{value:30015,label:"Interest sets (30015)"},{value:30017,label:"Create or update a stall (30017)"},{value:30018,label:"Create or update a product (30018)"},{value:30019,label:"Marketplace UI/UX (30019)"},{value:30020,label:"Product sold as an auction (30020)"},{value:30023,label:"Long-form Content (30023)"},{value:30024,label:"Draft Long-form Content (30024)"},{value:30030,label:"Emoji sets (30030)"},{value:30040,label:"Curated Publication Index (30040)"},{value:30041,label:"Curated Publication Content (30041)"},{value:30063,label:"Release artifact sets (30063)"},{value:30078,label:"Application-specific Data (30078)"},{value:30166,label:"Relay Discovery (30166)"},{value:30267,label:"App curation sets (30267)"},{value:30311,label:"Live Event (30311)"},{value:30312,label:"Interactive Room (30312)"},{value:30313,label:"Conference Event (30313)"},{value:30315,label:"User Statuses (30315)"},{value:30388,label:"Slide Set (30388)"},{value:30402,label:"Classified Listing (30402)"},{value:30403,label:"Draft Classified Listing (30403)"},{value:30617,label:"Repository announcements (30617)"},{value:30618,label:"Repository state announcements (30618)"},{value:30818,label:"Wiki article (30818)"},{value:30819,label:"Redirects (30819)"},{value:31234,label:"Draft Event (31234)"},{value:31388,label:"Link Set (31388)"},{value:31890,label:"Feed (31890)"},{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:32267,label:"Software Application (32267)"},{value:34550,label:"Community Definition (34550)"},{value:37516,label:"Geocache listing (37516)"},{value:38172,label:"Cashu Mint Announcement (38172)"},{value:38173,label:"Fedimint Announcement (38173)"},{value:38383,label:"Peer-to-peer Order events (38383)"},{value:39089,label:"Starter packs (39089)"},{value:39092,label:"Media starter packs (39092)"},{value:39701,label:"Web bookmarks (39701)"}],Ch={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"},xh=3e5;class Bh{constructor(){this.pool=new Un,this.eventStore=new Af,this.isConnected=!1,this.signer=null,this.relays=[...Ih]}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,t=null){this.isConnected||(console.warn("Not connected to any relays, attempting to connect first"),await this.connect());try{const n=t||this.relays,r=this.pool.publish(n,e);return await Promise.allSettled(r),console.log("✓ Event published successfully"),await Th([e]),console.log("Event stored in IndexedDB"),{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 Sh=new Bh,Fh="nostrCache",Qh=2,Rh="events";function Dh(){return new Promise((e,t)=>{try{const n=indexedDB.open(Fh,Qh);n.onupgradeneeded=e=>{const t=n.result;e.oldVersion;let r;r=t.objectStoreNames.contains(Rh)?n.transaction.objectStore(Rh):t.createObjectStore(Rh,{keyPath:"id"}),r.indexNames.contains("byKindAuthor")||r.createIndex("byKindAuthor",["kind","pubkey"],{unique:!1}),r.indexNames.contains("byKindAuthorCreated")||r.createIndex("byKindAuthorCreated",["kind","pubkey","created_at"],{unique:!1}),r.indexNames.contains("byKind")||r.createIndex("byKind","kind",{unique:!1}),r.indexNames.contains("byAuthor")||r.createIndex("byAuthor","pubkey",{unique:!1}),r.indexNames.contains("byCreatedAt")||r.createIndex("byCreatedAt","created_at",{unique:!1})},n.onsuccess=()=>e(n.result),n.onerror=()=>t(n.error)}catch(e){console.error("Failed to open IndexedDB",e),t(e)}})}async function Ph(e){try{const t=await Dh();await new Promise((n,r)=>{const i=t.transaction(Rh,"readwrite");i.oncomplete=()=>n(),i.onerror=()=>r(i.error),i.objectStore(Rh).put(e)})}catch(e){console.warn("IDB putEvent failed",e)}}async function Th(e){if(e&&0!==e.length)try{const t=await Dh();await new Promise((n,r)=>{const i=t.transaction(Rh,"readwrite");i.oncomplete=()=>n(),i.onerror=()=>r(i.error);const o=i.objectStore(Rh);for(const t of e)o.put(t)}),console.log(`Stored ${e.length} events in IndexedDB`)}catch(e){console.warn("IDB putEvents failed",e)}}async function Uh(e){try{const t=await Dh(),n=[];console.log("QueryEventsFromDB: Starting query with filters:",e);for(const r of e){console.log("QueryEventsFromDB: Processing filter:",r);const e=await new Promise((e,n)=>{const i=t.transaction(Rh,"readonly").objectStore(Rh),o=[];let s;if(r.kinds&&r.kinds.length>0&&r.authors&&r.authors.length>0){const e=r.kinds[0],t=r.authors[0];console.log(`QueryEventsFromDB: Using byKindAuthorCreated index for kind=${e}, author=${t.substring(0,8)}...`);const n=i.index("byKindAuthorCreated"),o=IDBKeyRange.bound([e,t,-1/0],[e,t,1/0]);s=n.openCursor(o,"prev")}else if(r.kinds&&r.kinds.length>0){console.log(`QueryEventsFromDB: Using byKind index for kind=${r.kinds[0]}`);const e=i.index("byKind");s=e.openCursor(IDBKeyRange.only(r.kinds[0]))}else if(r.authors&&r.authors.length>0){console.log(`QueryEventsFromDB: Using byAuthor index for author=${r.authors[0].substring(0,8)}...`);const e=i.index("byAuthor");s=e.openCursor(IDBKeyRange.only(r.authors[0]))}else console.log("QueryEventsFromDB: Scanning all events (no specific index)"),s=i.openCursor();s.onsuccess=t=>{const n=t.target.result;if(n){const t=n.value;let i=!0;if(r.kinds&&r.kinds.length>0&&!r.kinds.includes(t.kind)&&(i=!1),r.authors&&r.authors.length>0&&!r.authors.includes(t.pubkey)&&(i=!1),r.since&&t.created_at<r.since&&(i=!1),r.until&&t.created_at>r.until&&(i=!1),r.ids&&r.ids.length>0&&!r.ids.includes(t.id)&&(i=!1),i&&o.push(t),r.limit&&o.length>=r.limit)return console.log(`QueryEventsFromDB: Reached limit of ${r.limit}, found ${o.length} matching events`),void e(o);n.continue()}else console.log(`QueryEventsFromDB: Cursor exhausted, found ${o.length} matching events`),e(o)},s.onerror=()=>{console.error("QueryEventsFromDB: Cursor error:",s.error),n(s.error)}});console.log(`QueryEventsFromDB: Found ${e.length} events for this filter`),n.push(...e)}return n.sort((e,t)=>t.created_at-e.created_at),console.log(`QueryEventsFromDB: Returning ${n.length} total events`),n}catch(e){return console.error("QueryEventsFromDB failed:",e),[]}}function $h(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 Nh(e){console.log(`Starting profile fetch for pubkey: ${e}`);try{const t=await async function(e){try{const t=await Dh();return await new Promise((n,r)=>{const i=t.transaction(Rh,"readonly").objectStore(Rh).index("byKindAuthorCreated"),o=IDBKeyRange.bound([0,e,-1/0],[0,e,1/0]),s=i.openCursor(o,"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 $h(t)}}catch(e){console.warn("Failed to load cached profile",e)}try{const t=[{kinds:[0],authors:[e],limit:1}],n=await Oh(t,{timeout:1e4});if(n.length>0){const t=n[0];console.log("Profile fetched:",t),await Ph(t);try{console.log("Publishing profile event to local relay:",t.id),await Sh.publish(t),console.log("Profile event successfully saved to local relay")}catch(e){console.warn("Failed to publish profile to local relay:",e)}const r=$h(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}return console.log("No profile found for pubkey, creating default:",e),await Lh(e)}catch(t){console.error("Failed to fetch profile:",t);try{return await Lh(e)}catch(e){return console.error("Failed to create default profile:",e),null}}}async function Lh(e){const t=`testuser${e.slice(0,6)}`,n=`${window.location.origin}/orly.png`,r={name:t,display_name:t,picture:n,about:"New ORLY user"},i={name:t,displayName:t,picture:n,about:"New ORLY user",pubkey:e};if(Sh.signer)try{const e={kind:0,content:JSON.stringify(r),tags:[],created_at:Math.floor(Date.now()/1e3)},t=await Sh.signer.signEvent(e);await Sh.publish(t),console.log("Default profile published:",t.id)}catch(e){console.warn("Failed to publish default profile:",e)}return i}async function Oh(e,t={}){console.log("Starting event fetch with filters:",JSON.stringify(e,null,2)),console.log("Current relays:",Sh.relays),Sh.isConnected&&0!==Sh.relays.length||(console.warn("Client not connected, initializing..."),await Hh());const{timeout:n=3e4,useCache:r=!0}=t;if(r)try{const t=await Uh(e);t.length>0&&console.log(`Found ${t.length} cached events in IndexedDB`)}catch(e){console.warn("Failed to query cached events",e)}return new Promise((t,r)=>{const i=[],o=setTimeout(()=>{console.log(`Timeout reached after ${n}ms, returning ${i.length} events`),sub.close(),i.length>0&&Th(i).catch(e=>console.warn("Failed to cache events",e)),t(i)},n);try{const n=Math.random().toString(36).substring(7);console.log(`📤 REQ [${n}]:`,JSON.stringify(["REQ",n,...e],null,2));const r=Sh.pool.subscribeMany(Sh.relays,e,{onevent(e){console.log(`📥 EVENT received for REQ [${n}]:`,{id:e.id?.substring(0,8)+"...",kind:e.kind,pubkey:e.pubkey?.substring(0,8)+"...",created_at:e.created_at,content_preview:e.content?.substring(0,50)}),i.push(e),Ph(e).catch(e=>console.warn("Failed to cache event",e))},oneose(){console.log(`✅ EOSE received for REQ [${n}], got ${i.length} events`),clearTimeout(o),r.close(),i.length>0&&Th(i).catch(e=>console.warn("Failed to cache events",e)),t(i)}})}catch(e){clearTimeout(o),console.error("Failed to fetch events:",e),r(e)}})}async function Mh(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 Oh(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 _h(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 Oh(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 Hh(){await Sh.connect()}async function jh(e,t={}){const{timeout:n=3e4,cacheFirst:r=!0,cacheOnly:i=!1}=t;let o=[];if(r||i)try{if(o=await Uh(e),console.log(`Found ${o.length} events in cache`),i||o.length>0)return o}catch(e){console.warn("Failed to query cache",e)}if(!i){const t=await Oh(e,{timeout:n,useCache:!1});return console.log(`Fetched ${t.length} events from relay`),t}return o}async function Gh(){try{const e=await Dh(),t=e.transaction(Rh,"readonly").objectStore(Rh),n=await new Promise((e,n)=>{const r=t.getAll();r.onsuccess=()=>e(r.result),r.onerror=()=>n(r.error)}),r=n.reduce((e,t)=>(e[t.kind]=(e[t.kind]||0)+1,e),{});return console.log("===== IndexedDB Contents ====="),console.log(`Total events: ${n.length}`),console.log("Events by kind:",r),console.log("Kind 0 events:",n.filter(e=>0===e.kind)),console.log("All event IDs:",n.map(e=>({id:e.id.substring(0,8),kind:e.kind,pubkey:e.pubkey.substring(0,8)}))),console.log("=============================="),{total:n.length,byKind:r,events:n}}catch(e){return console.error("Failed to debug IndexedDB:",e),null}}
/*!
* hash-wasm (https://www.npmjs.com/package/hash-wasm)
* (c) Dani Biro
* @license MIT
*/function Kh(e,t,n,r){return new(n||(n=Promise))(function(i,o){function s(e){try{l(r.next(e))}catch(e){o(e)}}function a(e){try{l(r.throw(e))}catch(e){o(e)}}function l(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(s,a)}l((r=r.apply(e,t||[])).next())})}"function"==typeof SuppressedError&&SuppressedError;class Jh{constructor(){this.mutex=Promise.resolve()}lock(){let e=()=>{};return this.mutex=this.mutex.then(()=>new Promise(e)),new Promise(t=>{e=t})}dispatch(e){return Kh(this,void 0,void 0,function*(){const t=yield this.lock();try{return yield Promise.resolve(e())}finally{t()}})}}var Vh;const qh="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:global,zh=null!==(Vh=qh.Buffer)&&void 0!==Vh?Vh:null,Yh=qh.TextEncoder?new qh.TextEncoder:null;function Wh(e,t){return(15&e)+(e>>6|e>>3&8)<<4|(15&t)+(t>>6|t>>3&8)}function Zh(e,t){const n=t.length>>1;for(let r=0;r<n;r++){const n=r<<1;e[r]=Wh(t.charCodeAt(n),t.charCodeAt(n+1))}}const Xh="a".charCodeAt(0)-10,ep="0".charCodeAt(0);function tp(e,t,n){let r=0;for(let i=0;i<n;i++){let n=t[i]>>>4;e[r++]=n>9?n+Xh:n+ep,n=15&t[i],e[r++]=n>9?n+Xh:n+ep}return String.fromCharCode.apply(null,e)}const np=null!==zh?e=>{if("string"==typeof e){const t=zh.from(e,"utf8");return new Uint8Array(t.buffer,t.byteOffset,t.length)}if(zh.isBuffer(e))return new Uint8Array(e.buffer,e.byteOffset,e.length);if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);throw new Error("Invalid data type!")}:e=>{if("string"==typeof e)return Yh.encode(e);if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);throw new Error("Invalid data type!")},rp="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",ip=new Uint8Array(256);for(let e=0;e<64;e++)ip[rp.charCodeAt(e)]=e;function op(e,t=!0){const n=e.length,r=n%3,i=[],o=n-r;for(let t=0;t<o;t+=3){const n=(e[t]<<16&16711680)+(e[t+1]<<8&65280)+(255&e[t+2]),r=rp.charAt(n>>18&63)+rp.charAt(n>>12&63)+rp.charAt(n>>6&63)+rp.charAt(63&n);i.push(r)}if(1===r){const r=e[n-1],o=rp.charAt(r>>2),s=rp.charAt(r<<4&63);i.push(`${o}${s}`),t&&i.push("==")}else if(2===r){const r=(e[n-2]<<8)+e[n-1],o=rp.charAt(r>>10),s=rp.charAt(r>>4&63),a=rp.charAt(r<<2&63);i.push(`${o}${s}${a}`),t&&i.push("=")}return i.join("")}function sp(e){const t=function(e){let t=Math.floor(.75*e.length);const n=e.length;return"="===e[n-1]&&(t-=1,"="===e[n-2]&&(t-=1)),t}(e),n=e.length,r=new Uint8Array(t);let i=0;for(let t=0;t<n;t+=4){const n=ip[e.charCodeAt(t)],o=ip[e.charCodeAt(t+1)],s=ip[e.charCodeAt(t+2)],a=ip[e.charCodeAt(t+3)];r[i]=n<<2|o>>4,i+=1,r[i]=(15&o)<<4|s>>2,i+=1,r[i]=(3&s)<<6|63&a,i+=1}return r}const ap=16384,lp=new Jh,cp=new Map;function up(e,t){return Kh(this,void 0,void 0,function*(){let n=null,r=null,i=!1;if("undefined"==typeof WebAssembly)throw new Error("WebAssembly is not supported in this environment!");const o=()=>new DataView(n.exports.memory.buffer).getUint32(n.exports.STATE_SIZE,!0),s=lp.dispatch(()=>Kh(this,void 0,void 0,function*(){if(!cp.has(e.name)){const t=sp(e.data),n=WebAssembly.compile(t);cp.set(e.name,n)}const t=yield cp.get(e.name);n=yield WebAssembly.instantiate(t,{})})),a=(e=null)=>{i=!0,n.exports.Hash_Init(e)},l=e=>{if(!i)throw new Error("update() called before init()");(e=>{let t=0;for(;t<e.length;){const i=e.subarray(t,t+ap);t+=i.length,r.set(i),n.exports.Hash_Update(i.length)}})(np(e))},c=new Uint8Array(2*t),u=(e,o=null)=>{if(!i)throw new Error("digest() called before init()");return i=!1,n.exports.Hash_Final(o),"binary"===e?r.slice(0,t):tp(c,r,t)},d=e=>"string"==typeof e?e.length<4096:e.byteLength<ap;let f=d;switch(e.name){case"argon2":case"scrypt":f=()=>!0;break;case"blake2b":case"blake2s":f=(e,t)=>t<=512&&d(e);break;case"blake3":f=(e,t)=>0===t&&d(e);break;case"xxhash64":case"xxhash3":case"xxhash128":case"crc64":f=()=>!1}return yield(()=>Kh(this,void 0,void 0,function*(){n||(yield s);const e=n.exports.Hash_GetBuffer(),t=n.exports.memory.buffer;r=new Uint8Array(t,e,ap)}))(),{getMemory:()=>r,writeMemory:(e,t=0)=>{r.set(e,t)},getExports:()=>n.exports,setMemorySize:e=>{n.exports.Hash_SetMemorySize(e);const t=n.exports.Hash_GetBuffer(),i=n.exports.memory.buffer;r=new Uint8Array(i,t,e)},init:a,update:l,digest:u,save:()=>{if(!i)throw new Error("save() can only be called after init() and before digest()");const t=n.exports.Hash_GetState(),r=o(),s=n.exports.memory.buffer,a=new Uint8Array(s,t,r),l=new Uint8Array(4+r);return Zh(l,e.hash),l.set(a,4),l},load:t=>{if(!(t instanceof Uint8Array))throw new Error("load() expects an Uint8Array generated by save()");const r=n.exports.Hash_GetState(),s=o(),a=4+s,l=n.exports.memory.buffer;if(t.length!==a)throw new Error(`Bad state length (expected ${a} bytes, got ${t.length})`);if(!function(e,t){if(e.length!==2*t.length)return!1;for(let n=0;n<t.length;n++){const r=n<<1;if(t[n]!==Wh(e.charCodeAt(r),e.charCodeAt(r+1)))return!1}return!0}(e.hash,t.subarray(0,4)))throw new Error("This state was written by an incompatible hash implementation");const c=t.subarray(4);new Uint8Array(l,r,s).set(c),i=!0},calculate:(e,i=null,o=null)=>{if(!f(e,i))return a(i),l(e),u("hex",o);const s=np(e);return r.set(s),n.exports.Hash_Calculate(s.length,i,o),tp(c,r,t)},hashLength:t}})}new Jh;var dp={name:"argon2",data:"AGFzbQEAAAABKQVgAX8Bf2AAAX9gEH9/f39/f39/f39/f39/f38AYAR/f39/AGACf38AAwYFAAECAwQFBgEBAoCAAgYIAX8BQZCoBAsHQQQGbWVtb3J5AgASSGFzaF9TZXRNZW1vcnlTaXplAAAOSGFzaF9HZXRCdWZmZXIAAQ5IYXNoX0NhbGN1bGF0ZQAECvEyBVgBAn9BACEBAkAgAEEAKAKICCICRg0AAkAgACACayIAQRB2IABBgIB8cSAASWoiAEAAQX9HDQBB/wHADwtBACEBQQBBACkDiAggAEEQdK18NwOICAsgAcALcAECfwJAQQAoAoAIIgANAEEAPwBBEHQiADYCgAhBACgCiAgiAUGAgCBGDQACQEGAgCAgAWsiAEEQdiAAQYCAfHEgAElqIgBAAEF/Rw0AQQAPC0EAQQApA4gIIABBEHStfDcDiAhBACgCgAghAAsgAAvcDgECfiAAIAQpAwAiECAAKQMAIhF8IBFCAYZC/v///x+DIBBC/////w+DfnwiEDcDACAMIBAgDCkDAIVCIIkiEDcDACAIIBAgCCkDACIRfCARQgGGQv7///8fgyAQQv////8Pg358IhA3AwAgBCAQIAQpAwCFQiiJIhA3AwAgACAQIAApAwAiEXwgEEL/////D4MgEUIBhkL+////H4N+fCIQNwMAIAwgECAMKQMAhUIwiSIQNwMAIAggECAIKQMAIhF8IBBC/////w+DIBFCAYZC/v///x+DfnwiEDcDACAEIBAgBCkDAIVCAYk3AwAgASAFKQMAIhAgASkDACIRfCARQgGGQv7///8fgyAQQv////8Pg358IhA3AwAgDSAQIA0pAwCFQiCJIhA3AwAgCSAQIAkpAwAiEXwgEUIBhkL+////H4MgEEL/////D4N+fCIQNwMAIAUgECAFKQMAhUIoiSIQNwMAIAEgECABKQMAIhF8IBBC/////w+DIBFCAYZC/v///x+DfnwiEDcDACANIBAgDSkDAIVCMIkiEDcDACAJIBAgCSkDACIRfCAQQv////8PgyARQgGGQv7///8fg358IhA3AwAgBSAQIAUpAwCFQgGJNwMAIAIgBikDACIQIAIpAwAiEXwgEUIBhkL+////H4MgEEL/////D4N+fCIQNwMAIA4gECAOKQMAhUIgiSIQNwMAIAogECAKKQMAIhF8IBFCAYZC/v///x+DIBBC/////w+DfnwiEDcDACAGIBAgBikDAIVCKIkiEDcDACACIBAgAikDACIRfCAQQv////8PgyARQgGGQv7///8fg358IhA3AwAgDiAQIA4pAwCFQjCJIhA3AwAgCiAQIAopAwAiEXwgEEL/////D4MgEUIBhkL+////H4N+fCIQNwMAIAYgECAGKQMAhUIBiTcDACADIAcpAwAiECADKQMAIhF8IBFCAYZC/v///x+DIBBC/////w+DfnwiEDcDACAPIBAgDykDAIVCIIkiEDcDACALIBAgCykDACIRfCARQgGGQv7///8fgyAQQv////8Pg358IhA3AwAgByAQIAcpAwCFQiiJIhA3AwAgAyAQIAMpAwAiEXwgEEL/////D4MgEUIBhkL+////H4N+fCIQNwMAIA8gECAPKQMAhUIwiSIQNwMAIAsgECALKQMAIhF8IBBC/////w+DIBFCAYZC/v///x+DfnwiEDcDACAHIBAgBykDAIVCAYk3AwAgACAFKQMAIhAgACkDACIRfCARQgGGQv7///8fgyAQQv////8Pg358IhA3AwAgDyAQIA8pAwCFQiCJIhA3AwAgCiAQIAopAwAiEXwgEUIBhkL+////H4MgEEL/////D4N+fCIQNwMAIAUgECAFKQMAhUIoiSIQNwMAIAAgECAAKQMAIhF8IBBC/////w+DIBFCAYZC/v///x+DfnwiEDcDACAPIBAgDykDAIVCMIkiEDcDACAKIBAgCikDACIRfCAQQv////8PgyARQgGGQv7///8fg358IhA3AwAgBSAQIAUpAwCFQgGJNwMAIAEgBikDACIQIAEpAwAiEXwgEUIBhkL+////H4MgEEL/////D4N+fCIQNwMAIAwgECAMKQMAhUIgiSIQNwMAIAsgECALKQMAIhF8IBFCAYZC/v///x+DIBBC/////w+DfnwiEDcDACAGIBAgBikDAIVCKIkiEDcDACABIBAgASkDACIRfCAQQv////8PgyARQgGGQv7///8fg358IhA3AwAgDCAQIAwpAwCFQjCJIhA3AwAgCyAQIAspAwAiEXwgEEL/////D4MgEUIBhkL+////H4N+fCIQNwMAIAYgECAGKQMAhUIBiTcDACACIAcpAwAiECACKQMAIhF8IBFCAYZC/v///x+DIBBC/////w+DfnwiEDcDACANIBAgDSkDAIVCIIkiEDcDACAIIBAgCCkDACIRfCARQgGGQv7///8fgyAQQv////8Pg358IhA3AwAgByAQIAcpAwCFQiiJIhA3AwAgAiAQIAIpAwAiEXwgEEL/////D4MgEUIBhkL+////H4N+fCIQNwMAIA0gECANKQMAhUIwiSIQNwMAIAggECAIKQMAIhF8IBBC/////w+DIBFCAYZC/v///x+DfnwiEDcDACAHIBAgBykDAIVCAYk3AwAgAyAEKQMAIhAgAykDACIRfCARQgGGQv7///8fgyAQQv////8Pg358IhA3AwAgDiAQIA4pAwCFQiCJIhA3AwAgCSAQIAkpAwAiEXwgEUIBhkL+////H4MgEEL/////D4N+fCIQNwMAIAQgECAEKQMAhUIoiSIQNwMAIAMgECADKQMAIhF8IBBC/////w+DIBFCAYZC/v///x+DfnwiEDcDACAOIBAgDikDAIVCMIkiEDcDACAJIBAgCSkDACIRfCAQQv////8PgyARQgGGQv7///8fg358IhA3AwAgBCAQIAQpAwCFQgGJNwMAC98aAQN/QQAhBEEAIAIpAwAgASkDAIU3A5AIQQAgAikDCCABKQMIhTcDmAhBACACKQMQIAEpAxCFNwOgCEEAIAIpAxggASkDGIU3A6gIQQAgAikDICABKQMghTcDsAhBACACKQMoIAEpAyiFNwO4CEEAIAIpAzAgASkDMIU3A8AIQQAgAikDOCABKQM4hTcDyAhBACACKQNAIAEpA0CFNwPQCEEAIAIpA0ggASkDSIU3A9gIQQAgAikDUCABKQNQhTcD4AhBACACKQNYIAEpA1iFNwPoCEEAIAIpA2AgASkDYIU3A/AIQQAgAikDaCABKQNohTcD+AhBACACKQNwIAEpA3CFNwOACUEAIAIpA3ggASkDeIU3A4gJQQAgAikDgAEgASkDgAGFNwOQCUEAIAIpA4gBIAEpA4gBhTcDmAlBACACKQOQASABKQOQAYU3A6AJQQAgAikDmAEgASkDmAGFNwOoCUEAIAIpA6ABIAEpA6ABhTcDsAlBACACKQOoASABKQOoAYU3A7gJQQAgAikDsAEgASkDsAGFNwPACUEAIAIpA7gBIAEpA7gBhTcDyAlBACACKQPAASABKQPAAYU3A9AJQQAgAikDyAEgASkDyAGFNwPYCUEAIAIpA9ABIAEpA9ABhTcD4AlBACACKQPYASABKQPYAYU3A+gJQQAgAikD4AEgASkD4AGFNwPwCUEAIAIpA+gBIAEpA+gBhTcD+AlBACACKQPwASABKQPwAYU3A4AKQQAgAikD+AEgASkD+AGFNwOICkEAIAIpA4ACIAEpA4AChTcDkApBACACKQOIAiABKQOIAoU3A5gKQQAgAikDkAIgASkDkAKFNwOgCkEAIAIpA5gCIAEpA5gChTcDqApBACACKQOgAiABKQOgAoU3A7AKQQAgAikDqAIgASkDqAKFNwO4CkEAIAIpA7ACIAEpA7AChTcDwApBACACKQO4AiABKQO4AoU3A8gKQQAgAikDwAIgASkDwAKFNwPQCkEAIAIpA8gCIAEpA8gChTcD2ApBACACKQPQAiABKQPQAoU3A+AKQQAgAikD2AIgASkD2AKFNwPoCkEAIAIpA+ACIAEpA+AChTcD8ApBACACKQPoAiABKQPoAoU3A/gKQQAgAikD8AIgASkD8AKFNwOAC0EAIAIpA/gCIAEpA/gChTcDiAtBACACKQOAAyABKQOAA4U3A5ALQQAgAikDiAMgASkDiAOFNwOYC0EAIAIpA5ADIAEpA5ADhTcDoAtBACACKQOYAyABKQOYA4U3A6gLQQAgAikDoAMgASkDoAOFNwOwC0EAIAIpA6gDIAEpA6gDhTcDuAtBACACKQOwAyABKQOwA4U3A8ALQQAgAikDuAMgASkDuAOFNwPIC0EAIAIpA8ADIAEpA8ADhTcD0AtBACACKQPIAyABKQPIA4U3A9gLQQAgAikD0AMgASkD0AOFNwPgC0EAIAIpA9gDIAEpA9gDhTcD6AtBACACKQPgAyABKQPgA4U3A/ALQQAgAikD6AMgASkD6AOFNwP4C0EAIAIpA/ADIAEpA/ADhTcDgAxBACACKQP4AyABKQP4A4U3A4gMQQAgAikDgAQgASkDgASFNwOQDEEAIAIpA4gEIAEpA4gEhTcDmAxBACACKQOQBCABKQOQBIU3A6AMQQAgAikDmAQgASkDmASFNwOoDEEAIAIpA6AEIAEpA6AEhTcDsAxBACACKQOoBCABKQOoBIU3A7gMQQAgAikDsAQgASkDsASFNwPADEEAIAIpA7gEIAEpA7gEhTcDyAxBACACKQPABCABKQPABIU3A9AMQQAgAikDyAQgASkDyASFNwPYDEEAIAIpA9AEIAEpA9AEhTcD4AxBACACKQPYBCABKQPYBIU3A+gMQQAgAikD4AQgASkD4ASFNwPwDEEAIAIpA+gEIAEpA+gEhTcD+AxBACACKQPwBCABKQPwBIU3A4ANQQAgAikD+AQgASkD+ASFNwOIDUEAIAIpA4AFIAEpA4AFhTcDkA1BACACKQOIBSABKQOIBYU3A5gNQQAgAikDkAUgASkDkAWFNwOgDUEAIAIpA5gFIAEpA5gFhTcDqA1BACACKQOgBSABKQOgBYU3A7ANQQAgAikDqAUgASkDqAWFNwO4DUEAIAIpA7AFIAEpA7AFhTcDwA1BACACKQO4BSABKQO4BYU3A8gNQQAgAikDwAUgASkDwAWFNwPQDUEAIAIpA8gFIAEpA8gFhTcD2A1BACACKQPQBSABKQPQBYU3A+ANQQAgAikD2AUgASkD2AWFNwPoDUEAIAIpA+AFIAEpA+AFhTcD8A1BACACKQPoBSABKQPoBYU3A/gNQQAgAikD8AUgASkD8AWFNwOADkEAIAIpA/gFIAEpA/gFhTcDiA5BACACKQOABiABKQOABoU3A5AOQQAgAikDiAYgASkDiAaFNwOYDkEAIAIpA5AGIAEpA5AGhTcDoA5BACACKQOYBiABKQOYBoU3A6gOQQAgAikDoAYgASkDoAaFNwOwDkEAIAIpA6gGIAEpA6gGhTcDuA5BACACKQOwBiABKQOwBoU3A8AOQQAgAikDuAYgASkDuAaFNwPIDkEAIAIpA8AGIAEpA8AGhTcD0A5BACACKQPIBiABKQPIBoU3A9gOQQAgAikD0AYgASkD0AaFNwPgDkEAIAIpA9gGIAEpA9gGhTcD6A5BACACKQPgBiABKQPgBoU3A/AOQQAgAikD6AYgASkD6AaFNwP4DkEAIAIpA/AGIAEpA/AGhTcDgA9BACACKQP4BiABKQP4BoU3A4gPQQAgAikDgAcgASkDgAeFNwOQD0EAIAIpA4gHIAEpA4gHhTcDmA9BACACKQOQByABKQOQB4U3A6APQQAgAikDmAcgASkDmAeFNwOoD0EAIAIpA6AHIAEpA6AHhTcDsA9BACACKQOoByABKQOoB4U3A7gPQQAgAikDsAcgASkDsAeFNwPAD0EAIAIpA7gHIAEpA7gHhTcDyA9BACACKQPAByABKQPAB4U3A9APQQAgAikDyAcgASkDyAeFNwPYD0EAIAIpA9AHIAEpA9AHhTcD4A9BACACKQPYByABKQPYB4U3A+gPQQAgAikD4AcgASkD4AeFNwPwD0EAIAIpA+gHIAEpA+gHhTcD+A9BACACKQPwByABKQPwB4U3A4AQQQAgAikD+AcgASkD+AeFNwOIEEGQCEGYCEGgCEGoCEGwCEG4CEHACEHICEHQCEHYCEHgCEHoCEHwCEH4CEGACUGICRACQZAJQZgJQaAJQagJQbAJQbgJQcAJQcgJQdAJQdgJQeAJQegJQfAJQfgJQYAKQYgKEAJBkApBmApBoApBqApBsApBuApBwApByApB0ApB2ApB4ApB6ApB8ApB+ApBgAtBiAsQAkGQC0GYC0GgC0GoC0GwC0G4C0HAC0HIC0HQC0HYC0HgC0HoC0HwC0H4C0GADEGIDBACQZAMQZgMQaAMQagMQbAMQbgMQcAMQcgMQdAMQdgMQeAMQegMQfAMQfgMQYANQYgNEAJBkA1BmA1BoA1BqA1BsA1BuA1BwA1ByA1B0A1B2A1B4A1B6A1B8A1B+A1BgA5BiA4QAkGQDkGYDkGgDkGoDkGwDkG4DkHADkHIDkHQDkHYDkHgDkHoDkHwDkH4DkGAD0GIDxACQZAPQZgPQaAPQagPQbAPQbgPQcAPQcgPQdAPQdgPQeAPQegPQfAPQfgPQYAQQYgQEAJBkAhBmAhBkAlBmAlBkApBmApBkAtBmAtBkAxBmAxBkA1BmA1BkA5BmA5BkA9BmA8QAkGgCEGoCEGgCUGoCUGgCkGoCkGgC0GoC0GgDEGoDEGgDUGoDUGgDkGoDkGgD0GoDxACQbAIQbgIQbAJQbgJQbAKQbgKQbALQbgLQbAMQbgMQbANQbgNQbAOQbgOQbAPQbgPEAJBwAhByAhBwAlByAlBwApByApBwAtByAtBwAxByAxBwA1ByA1BwA5ByA5BwA9ByA8QAkHQCEHYCEHQCUHYCUHQCkHYCkHQC0HYC0HQDEHYDEHQDUHYDUHQDkHYDkHQD0HYDxACQeAIQegIQeAJQegJQeAKQegKQeALQegLQeAMQegMQeANQegNQeAOQegOQeAPQegPEAJB8AhB+AhB8AlB+AlB8ApB+ApB8AtB+AtB8AxB+AxB8A1B+A1B8A5B+A5B8A9B+A8QAkGACUGICUGACkGICkGAC0GIC0GADEGIDEGADUGIDUGADkGIDkGAD0GID0GAEEGIEBACAkACQCADRQ0AA0AgACAEaiIDIAIgBGoiBSkDACABIARqIgYpAwCFIARBkAhqKQMAhSADKQMAhTcDACADQQhqIgMgBUEIaikDACAGQQhqKQMAhSAEQZgIaikDAIUgAykDAIU3AwAgBEEQaiIEQYAIRw0ADAILC0EAIQQDQCAAIARqIgMgAiAEaiIFKQMAIAEgBGoiBikDAIUgBEGQCGopAwCFNwMAIANBCGogBUEIaikDACAGQQhqKQMAhSAEQZgIaikDAIU3AwAgBEEQaiIEQYAIRw0ACwsL5QcMBX8BfgR/An4BfwF+AX8Bfgd/AX4DfwF+AkBBACgCgAgiAiABQQp0aiIDKAIIIAFHDQAgAygCDCEEIAMoAgAhBUEAIAMoAhQiBq03A7gQQQAgBK0iBzcDsBBBACAFIAEgBUECdG4iCGwiCUECdK03A6gQAkACQAJAAkAgBEUNAEF/IQogBUUNASAIQQNsIQsgCEECdCIErSEMIAWtIQ0gBkF/akECSSEOQgAhDwNAQQAgDzcDkBAgD6chEEIAIRFBACEBA0BBACARNwOgECAPIBGEUCIDIA5xIRIgBkEBRiAPUCITIAZBAkYgEUICVHFxciEUQX8gAUEBakEDcSAIbEF/aiATGyEVIAEgEHIhFiABIAhsIRcgA0EBdCEYQgAhGQNAQQBCADcDwBBBACAZNwOYECAYIQECQCASRQ0AQQBCATcDwBBBkBhBkBBBkCBBABADQZAYQZAYQZAgQQAQA0ECIQELAkAgASAITw0AIAQgGaciGmwgF2ogAWohAwNAIANBACAEIAEbQQAgEVAiGxtqQX9qIRwCQAJAIBQNAEEAKAKACCICIBxBCnQiHGohCgwBCwJAIAFB/wBxIgINAEEAQQApA8AQQgF8NwPAEEGQGEGQEEGQIEEAEANBkBhBkBhBkCBBABADCyAcQQp0IRwgAkEDdEGQGGohCkEAKAKACCECCyACIANBCnRqIAIgHGogAiAKKQMAIh1CIIinIAVwIBogFhsiHCAEbCABIAFBACAZIBytUSIcGyIKIBsbIBdqIAogC2ogExsgAUUgHHJrIhsgFWqtIB1C/////w+DIh0gHX5CIIggG61+QiCIfSAMgqdqQQp0akEBEAMgA0EBaiEDIAggAUEBaiIBRw0ACwsgGUIBfCIZIA1SDQALIBFCAXwiEachASARQgRSDQALIA9CAXwiDyAHUg0AC0EAKAKACCECCyAJQQx0QYB4aiEXIAVBf2oiCkUNAgwBC0EAQgM3A6AQQQAgBEF/aq03A5AQQYB4IRcLIAIgF2ohGyAIQQx0IQhBACEcA0AgCCAcQQFqIhxsQYB4aiEEQQAhAQNAIBsgAWoiAyADKQMAIAIgBCABamopAwCFNwMAIANBCGoiAyADKQMAIAIgBCABQQhyamopAwCFNwMAIAFBCGohAyABQRBqIQEgA0H4B0kNAAsgHCAKRw0ACwsgAiAXaiEbQXghAQNAIAIgAWoiA0EIaiAbIAFqIgRBCGopAwA3AwAgA0EQaiAEQRBqKQMANwMAIANBGGogBEEYaikDADcDACADQSBqIARBIGopAwA3AwAgAUEgaiIBQfgHSQ0ACwsL",hash:"e4cdc523"},fp={name:"blake2b",data:"AGFzbQEAAAABEQRgAAF/YAJ/fwBgAX8AYAAAAwoJAAECAwECAgABBQQBAQICBg4CfwFBsIsFC38AQYAICwdwCAZtZW1vcnkCAA5IYXNoX0dldEJ1ZmZlcgAACkhhc2hfRmluYWwAAwlIYXNoX0luaXQABQtIYXNoX1VwZGF0ZQAGDUhhc2hfR2V0U3RhdGUABw5IYXNoX0NhbGN1bGF0ZQAIClNUQVRFX1NJWkUDAQrTOAkFAEGACQvrAgIFfwF+AkAgAUEBSA0AAkACQAJAIAFBgAFBACgC4IoBIgJrIgNKDQAgASEEDAELQQBBADYC4IoBAkAgAkH/AEoNACACQeCJAWohBSAAIQRBACEGA0AgBSAELQAAOgAAIARBAWohBCAFQQFqIQUgAyAGQQFqIgZB/wFxSg0ACwtBAEEAKQPAiQEiB0KAAXw3A8CJAUEAQQApA8iJASAHQv9+Vq18NwPIiQFB4IkBEAIgACADaiEAAkAgASADayIEQYEBSA0AIAIgAWohBQNAQQBBACkDwIkBIgdCgAF8NwPAiQFBAEEAKQPIiQEgB0L/flatfDcDyIkBIAAQAiAAQYABaiEAIAVBgH9qIgVBgAJLDQALIAVBgH9qIQQMAQsgBEEATA0BC0EAIQUDQCAFQQAoAuCKAWpB4IkBaiAAIAVqLQAAOgAAIAQgBUEBaiIFQf8BcUoNAAsLQQBBACgC4IoBIARqNgLgigELC78uASR+QQBBACkD0IkBQQApA7CJASIBQQApA5CJAXwgACkDICICfCIDhULr+obav7X2wR+FQiCJIgRCq/DT9K/uvLc8fCIFIAGFQiiJIgYgA3wgACkDKCIBfCIHIASFQjCJIgggBXwiCSAGhUIBiSIKQQApA8iJAUEAKQOoiQEiBEEAKQOIiQF8IAApAxAiA3wiBYVCn9j52cKR2oKbf4VCIIkiC0K7zqqm2NDrs7t/fCIMIASFQiiJIg0gBXwgACkDGCIEfCIOfCAAKQNQIgV8Ig9BACkDwIkBQQApA6CJASIQQQApA4CJASIRfCAAKQMAIgZ8IhKFQtGFmu/6z5SH0QCFQiCJIhNCiJLznf/M+YTqAHwiFCAQhUIoiSIVIBJ8IAApAwgiEHwiFiAThUIwiSIXhUIgiSIYQQApA9iJAUEAKQO4iQEiE0EAKQOYiQF8IAApAzAiEnwiGYVC+cL4m5Gjs/DbAIVCIIkiGkLx7fT4paf9p6V/fCIbIBOFQiiJIhwgGXwgACkDOCITfCIZIBqFQjCJIhogG3wiG3wiHSAKhUIoiSIeIA98IAApA1giCnwiDyAYhUIwiSIYIB18Ih0gDiALhUIwiSIOIAx8Ih8gDYVCAYkiDCAWfCAAKQNAIgt8Ig0gGoVCIIkiFiAJfCIaIAyFQiiJIiAgDXwgACkDSCIJfCIhIBaFQjCJIhYgGyAchUIBiSIMIAd8IAApA2AiB3wiDSAOhUIgiSIOIBcgFHwiFHwiFyAMhUIoiSIbIA18IAApA2giDHwiHCAOhUIwiSIOIBd8IhcgG4VCAYkiGyAZIBQgFYVCAYkiFHwgACkDcCINfCIVIAiFQiCJIhkgH3wiHyAUhUIoiSIUIBV8IAApA3giCHwiFXwgDHwiIoVCIIkiI3wiJCAbhUIoiSIbICJ8IBJ8IiIgFyAYIBUgGYVCMIkiFSAffCIZIBSFQgGJIhQgIXwgDXwiH4VCIIkiGHwiFyAUhUIoiSIUIB98IAV8Ih8gGIVCMIkiGCAXfCIXIBSFQgGJIhR8IAF8IiEgFiAafCIWIBUgHSAehUIBiSIaIBx8IAl8IhyFQiCJIhV8Ih0gGoVCKIkiGiAcfCAIfCIcIBWFQjCJIhWFQiCJIh4gGSAOIBYgIIVCAYkiFiAPfCACfCIPhUIgiSIOfCIZIBaFQiiJIhYgD3wgC3wiDyAOhUIwiSIOIBl8Ihl8IiAgFIVCKIkiFCAhfCAEfCIhIB6FQjCJIh4gIHwiICAiICOFQjCJIiIgJHwiIyAbhUIBiSIbIBx8IAp8IhwgDoVCIIkiDiAXfCIXIBuFQiiJIhsgHHwgE3wiHCAOhUIwiSIOIBkgFoVCAYkiFiAffCAQfCIZICKFQiCJIh8gFSAdfCIVfCIdIBaFQiiJIhYgGXwgB3wiGSAfhUIwiSIfIB18Ih0gFoVCAYkiFiAVIBqFQgGJIhUgD3wgBnwiDyAYhUIgiSIYICN8IhogFYVCKIkiFSAPfCADfCIPfCAHfCIihUIgiSIjfCIkIBaFQiiJIhYgInwgBnwiIiAjhUIwiSIjICR8IiQgFoVCAYkiFiAOIBd8Ig4gDyAYhUIwiSIPICAgFIVCAYkiFCAZfCAKfCIXhUIgiSIYfCIZIBSFQiiJIhQgF3wgC3wiF3wgBXwiICAPIBp8Ig8gHyAOIBuFQgGJIg4gIXwgCHwiGoVCIIkiG3wiHyAOhUIoiSIOIBp8IAx8IhogG4VCMIkiG4VCIIkiISAdIB4gDyAVhUIBiSIPIBx8IAF8IhWFQiCJIhx8Ih0gD4VCKIkiDyAVfCADfCIVIByFQjCJIhwgHXwiHXwiHiAWhUIoiSIWICB8IA18IiAgIYVCMIkiISAefCIeIBogFyAYhUIwiSIXIBl8IhggFIVCAYkiFHwgCXwiGSAchUIgiSIaICR8IhwgFIVCKIkiFCAZfCACfCIZIBqFQjCJIhogHSAPhUIBiSIPICJ8IAR8Ih0gF4VCIIkiFyAbIB98Iht8Ih8gD4VCKIkiDyAdfCASfCIdIBeFQjCJIhcgH3wiHyAPhUIBiSIPIBsgDoVCAYkiDiAVfCATfCIVICOFQiCJIhsgGHwiGCAOhUIoiSIOIBV8IBB8IhV8IAx8IiKFQiCJIiN8IiQgD4VCKIkiDyAifCAHfCIiICOFQjCJIiMgJHwiJCAPhUIBiSIPIBogHHwiGiAVIBuFQjCJIhUgHiAWhUIBiSIWIB18IAR8IhuFQiCJIhx8Ih0gFoVCKIkiFiAbfCAQfCIbfCABfCIeIBUgGHwiFSAXIBogFIVCAYkiFCAgfCATfCIYhUIgiSIXfCIaIBSFQiiJIhQgGHwgCXwiGCAXhUIwiSIXhUIgiSIgIB8gISAVIA6FQgGJIg4gGXwgCnwiFYVCIIkiGXwiHyAOhUIoiSIOIBV8IA18IhUgGYVCMIkiGSAffCIffCIhIA+FQiiJIg8gHnwgBXwiHiAghUIwiSIgICF8IiEgGyAchUIwiSIbIB18IhwgFoVCAYkiFiAYfCADfCIYIBmFQiCJIhkgJHwiHSAWhUIoiSIWIBh8IBJ8IhggGYVCMIkiGSAfIA6FQgGJIg4gInwgAnwiHyAbhUIgiSIbIBcgGnwiF3wiGiAOhUIoiSIOIB98IAZ8Ih8gG4VCMIkiGyAafCIaIA6FQgGJIg4gFSAXIBSFQgGJIhR8IAh8IhUgI4VCIIkiFyAcfCIcIBSFQiiJIhQgFXwgC3wiFXwgBXwiIoVCIIkiI3wiJCAOhUIoiSIOICJ8IAh8IiIgGiAgIBUgF4VCMIkiFSAcfCIXIBSFQgGJIhQgGHwgCXwiGIVCIIkiHHwiGiAUhUIoiSIUIBh8IAZ8IhggHIVCMIkiHCAafCIaIBSFQgGJIhR8IAR8IiAgGSAdfCIZIBUgISAPhUIBiSIPIB98IAN8Ih2FQiCJIhV8Ih8gD4VCKIkiDyAdfCACfCIdIBWFQjCJIhWFQiCJIiEgFyAbIBkgFoVCAYkiFiAefCABfCIZhUIgiSIbfCIXIBaFQiiJIhYgGXwgE3wiGSAbhUIwiSIbIBd8Ihd8Ih4gFIVCKIkiFCAgfCAMfCIgICGFQjCJIiEgHnwiHiAiICOFQjCJIiIgJHwiIyAOhUIBiSIOIB18IBJ8Ih0gG4VCIIkiGyAafCIaIA6FQiiJIg4gHXwgC3wiHSAbhUIwiSIbIBcgFoVCAYkiFiAYfCANfCIXICKFQiCJIhggFSAffCIVfCIfIBaFQiiJIhYgF3wgEHwiFyAYhUIwiSIYIB98Ih8gFoVCAYkiFiAVIA+FQgGJIg8gGXwgCnwiFSAchUIgiSIZICN8IhwgD4VCKIkiDyAVfCAHfCIVfCASfCIihUIgiSIjfCIkIBaFQiiJIhYgInwgBXwiIiAjhUIwiSIjICR8IiQgFoVCAYkiFiAbIBp8IhogFSAZhUIwiSIVIB4gFIVCAYkiFCAXfCADfCIXhUIgiSIZfCIbIBSFQiiJIhQgF3wgB3wiF3wgAnwiHiAVIBx8IhUgGCAaIA6FQgGJIg4gIHwgC3wiGoVCIIkiGHwiHCAOhUIoiSIOIBp8IAR8IhogGIVCMIkiGIVCIIkiICAfICEgFSAPhUIBiSIPIB18IAZ8IhWFQiCJIh18Ih8gD4VCKIkiDyAVfCAKfCIVIB2FQjCJIh0gH3wiH3wiISAWhUIoiSIWIB58IAx8Ih4gIIVCMIkiICAhfCIhIBogFyAZhUIwiSIXIBt8IhkgFIVCAYkiFHwgEHwiGiAdhUIgiSIbICR8Ih0gFIVCKIkiFCAafCAJfCIaIBuFQjCJIhsgHyAPhUIBiSIPICJ8IBN8Ih8gF4VCIIkiFyAYIBx8Ihh8IhwgD4VCKIkiDyAffCABfCIfIBeFQjCJIhcgHHwiHCAPhUIBiSIPIBggDoVCAYkiDiAVfCAIfCIVICOFQiCJIhggGXwiGSAOhUIoiSIOIBV8IA18IhV8IA18IiKFQiCJIiN8IiQgD4VCKIkiDyAifCAMfCIiICOFQjCJIiMgJHwiJCAPhUIBiSIPIBsgHXwiGyAVIBiFQjCJIhUgISAWhUIBiSIWIB98IBB8IhiFQiCJIh18Ih8gFoVCKIkiFiAYfCAIfCIYfCASfCIhIBUgGXwiFSAXIBsgFIVCAYkiFCAefCAHfCIZhUIgiSIXfCIbIBSFQiiJIhQgGXwgAXwiGSAXhUIwiSIXhUIgiSIeIBwgICAVIA6FQgGJIg4gGnwgAnwiFYVCIIkiGnwiHCAOhUIoiSIOIBV8IAV8IhUgGoVCMIkiGiAcfCIcfCIgIA+FQiiJIg8gIXwgBHwiISAehUIwiSIeICB8IiAgGCAdhUIwiSIYIB98Ih0gFoVCAYkiFiAZfCAGfCIZIBqFQiCJIhogJHwiHyAWhUIoiSIWIBl8IBN8IhkgGoVCMIkiGiAcIA6FQgGJIg4gInwgCXwiHCAYhUIgiSIYIBcgG3wiF3wiGyAOhUIoiSIOIBx8IAN8IhwgGIVCMIkiGCAbfCIbIA6FQgGJIg4gFSAXIBSFQgGJIhR8IAt8IhUgI4VCIIkiFyAdfCIdIBSFQiiJIhQgFXwgCnwiFXwgBHwiIoVCIIkiI3wiJCAOhUIoiSIOICJ8IAl8IiIgGyAeIBUgF4VCMIkiFSAdfCIXIBSFQgGJIhQgGXwgDHwiGYVCIIkiHXwiGyAUhUIoiSIUIBl8IAp8IhkgHYVCMIkiHSAbfCIbIBSFQgGJIhR8IAN8Ih4gGiAffCIaIBUgICAPhUIBiSIPIBx8IAd8IhyFQiCJIhV8Ih8gD4VCKIkiDyAcfCAQfCIcIBWFQjCJIhWFQiCJIiAgFyAYIBogFoVCAYkiFiAhfCATfCIahUIgiSIYfCIXIBaFQiiJIhYgGnwgDXwiGiAYhUIwiSIYIBd8Ihd8IiEgFIVCKIkiFCAefCAFfCIeICCFQjCJIiAgIXwiISAiICOFQjCJIiIgJHwiIyAOhUIBiSIOIBx8IAt8IhwgGIVCIIkiGCAbfCIbIA6FQiiJIg4gHHwgEnwiHCAYhUIwiSIYIBcgFoVCAYkiFiAZfCABfCIXICKFQiCJIhkgFSAffCIVfCIfIBaFQiiJIhYgF3wgBnwiFyAZhUIwiSIZIB98Ih8gFoVCAYkiFiAVIA+FQgGJIg8gGnwgCHwiFSAdhUIgiSIaICN8Ih0gD4VCKIkiDyAVfCACfCIVfCANfCIihUIgiSIjfCIkIBaFQiiJIhYgInwgCXwiIiAjhUIwiSIjICR8IiQgFoVCAYkiFiAYIBt8IhggFSAahUIwiSIVICEgFIVCAYkiFCAXfCASfCIXhUIgiSIafCIbIBSFQiiJIhQgF3wgCHwiF3wgB3wiISAVIB18IhUgGSAYIA6FQgGJIg4gHnwgBnwiGIVCIIkiGXwiHSAOhUIoiSIOIBh8IAt8IhggGYVCMIkiGYVCIIkiHiAfICAgFSAPhUIBiSIPIBx8IAp8IhWFQiCJIhx8Ih8gD4VCKIkiDyAVfCAEfCIVIByFQjCJIhwgH3wiH3wiICAWhUIoiSIWICF8IAN8IiEgHoVCMIkiHiAgfCIgIBggFyAahUIwiSIXIBt8IhogFIVCAYkiFHwgBXwiGCAchUIgiSIbICR8IhwgFIVCKIkiFCAYfCABfCIYIBuFQjCJIhsgHyAPhUIBiSIPICJ8IAx8Ih8gF4VCIIkiFyAZIB18Ihl8Ih0gD4VCKIkiDyAffCATfCIfIBeFQjCJIhcgHXwiHSAPhUIBiSIPIBkgDoVCAYkiDiAVfCAQfCIVICOFQiCJIhkgGnwiGiAOhUIoiSIOIBV8IAJ8IhV8IBN8IiKFQiCJIiN8IiQgD4VCKIkiDyAifCASfCIiICOFQjCJIiMgJHwiJCAPhUIBiSIPIBsgHHwiGyAVIBmFQjCJIhUgICAWhUIBiSIWIB98IAt8IhmFQiCJIhx8Ih8gFoVCKIkiFiAZfCACfCIZfCAJfCIgIBUgGnwiFSAXIBsgFIVCAYkiFCAhfCAFfCIahUIgiSIXfCIbIBSFQiiJIhQgGnwgA3wiGiAXhUIwiSIXhUIgiSIhIB0gHiAVIA6FQgGJIg4gGHwgEHwiFYVCIIkiGHwiHSAOhUIoiSIOIBV8IAF8IhUgGIVCMIkiGCAdfCIdfCIeIA+FQiiJIg8gIHwgDXwiICAhhUIwiSIhIB58Ih4gGSAchUIwiSIZIB98IhwgFoVCAYkiFiAafCAIfCIaIBiFQiCJIhggJHwiHyAWhUIoiSIWIBp8IAp8IhogGIVCMIkiGCAdIA6FQgGJIg4gInwgBHwiHSAZhUIgiSIZIBcgG3wiF3wiGyAOhUIoiSIOIB18IAd8Ih0gGYVCMIkiGSAbfCIbIA6FQgGJIg4gFSAXIBSFQgGJIhR8IAx8IhUgI4VCIIkiFyAcfCIcIBSFQiiJIhQgFXwgBnwiFXwgEnwiIoVCIIkiI3wiJCAOhUIoiSIOICJ8IBN8IiIgGyAhIBUgF4VCMIkiFSAcfCIXIBSFQgGJIhQgGnwgBnwiGoVCIIkiHHwiGyAUhUIoiSIUIBp8IBB8IhogHIVCMIkiHCAbfCIbIBSFQgGJIhR8IA18IiEgGCAffCIYIBUgHiAPhUIBiSIPIB18IAJ8Ih2FQiCJIhV8Ih4gD4VCKIkiDyAdfCABfCIdIBWFQjCJIhWFQiCJIh8gFyAZIBggFoVCAYkiFiAgfCADfCIYhUIgiSIZfCIXIBaFQiiJIhYgGHwgBHwiGCAZhUIwiSIZIBd8Ihd8IiAgFIVCKIkiFCAhfCAIfCIhIB+FQjCJIh8gIHwiICAiICOFQjCJIiIgJHwiIyAOhUIBiSIOIB18IAd8Ih0gGYVCIIkiGSAbfCIbIA6FQiiJIg4gHXwgDHwiHSAZhUIwiSIZIBcgFoVCAYkiFiAafCALfCIXICKFQiCJIhogFSAefCIVfCIeIBaFQiiJIhYgF3wgCXwiFyAahUIwiSIaIB58Ih4gFoVCAYkiFiAVIA+FQgGJIg8gGHwgBXwiFSAchUIgiSIYICN8IhwgD4VCKIkiDyAVfCAKfCIVfCACfCIChUIgiSIifCIjIBaFQiiJIhYgAnwgC3wiAiAihUIwiSILICN8IiIgFoVCAYkiFiAZIBt8IhkgFSAYhUIwiSIVICAgFIVCAYkiFCAXfCANfCINhUIgiSIXfCIYIBSFQiiJIhQgDXwgBXwiBXwgEHwiECAVIBx8Ig0gGiAZIA6FQgGJIg4gIXwgDHwiDIVCIIkiFXwiGSAOhUIoiSIOIAx8IBJ8IhIgFYVCMIkiDIVCIIkiFSAeIB8gDSAPhUIBiSINIB18IAl8IgmFQiCJIg98IhogDYVCKIkiDSAJfCAIfCIJIA+FQjCJIgggGnwiD3wiGiAWhUIoiSIWIBB8IAd8IhAgEYUgDCAZfCIHIA6FQgGJIgwgCXwgCnwiCiALhUIgiSILIAUgF4VCMIkiBSAYfCIJfCIOIAyFQiiJIgwgCnwgE3wiEyALhUIwiSIKIA58IguFNwOAiQFBACADIAYgDyANhUIBiSINIAJ8fCICIAWFQiCJIgUgB3wiBiANhUIoiSIHIAJ8fCICQQApA4iJAYUgBCABIBIgCSAUhUIBiSIDfHwiASAIhUIgiSISICJ8IgkgA4VCKIkiAyABfHwiASAShUIwiSIEIAl8IhKFNwOIiQFBACATQQApA5CJAYUgECAVhUIwiSIQIBp8IhOFNwOQiQFBACABQQApA5iJAYUgAiAFhUIwiSICIAZ8IgGFNwOYiQFBACASIAOFQgGJQQApA6CJAYUgAoU3A6CJAUEAIBMgFoVCAYlBACkDqIkBhSAKhTcDqIkBQQAgASAHhUIBiUEAKQOwiQGFIASFNwOwiQFBACALIAyFQgGJQQApA7iJAYUgEIU3A7iJAQvdAgUBfwF+AX8BfgJ/IwBBwABrIgAkAAJAQQApA9CJAUIAUg0AQQBBACkDwIkBIgFBACgC4IoBIgKsfCIDNwPAiQFBAEEAKQPIiQEgAyABVK18NwPIiQECQEEALQDoigFFDQBBAEJ/NwPYiQELQQBCfzcD0IkBAkAgAkH/AEoNAEEAIQQDQCACIARqQeCJAWpBADoAACAEQQFqIgRBgAFBACgC4IoBIgJrSA0ACwtB4IkBEAIgAEEAKQOAiQE3AwAgAEEAKQOIiQE3AwggAEEAKQOQiQE3AxAgAEEAKQOYiQE3AxggAEEAKQOgiQE3AyAgAEEAKQOoiQE3AyggAEEAKQOwiQE3AzAgAEEAKQO4iQE3AzhBACgC5IoBIgVBAUgNAEEAIQRBACECA0AgBEGACWogACAEai0AADoAACAEQQFqIQQgBSACQQFqIgJB/wFxSg0ACwsgAEHAAGokAAv9AwMBfwF+AX8jAEGAAWsiAiQAQQBBgQI7AfKKAUEAIAE6APGKAUEAIAA6APCKAUGQfiEAA0AgAEGAiwFqQgA3AAAgAEH4igFqQgA3AAAgAEHwigFqQgA3AAAgAEEYaiIADQALQQAhAEEAQQApA/CKASIDQoiS853/zPmE6gCFNwOAiQFBAEEAKQP4igFCu86qptjQ67O7f4U3A4iJAUEAQQApA4CLAUKr8NP0r+68tzyFNwOQiQFBAEEAKQOIiwFC8e30+KWn/aelf4U3A5iJAUEAQQApA5CLAULRhZrv+s+Uh9EAhTcDoIkBQQBBACkDmIsBQp/Y+dnCkdqCm3+FNwOoiQFBAEEAKQOgiwFC6/qG2r+19sEfhTcDsIkBQQBBACkDqIsBQvnC+JuRo7Pw2wCFNwO4iQFBACADp0H/AXE2AuSKAQJAIAFBAUgNACACQgA3A3ggAkIANwNwIAJCADcDaCACQgA3A2AgAkIANwNYIAJCADcDUCACQgA3A0ggAkIANwNAIAJCADcDOCACQgA3AzAgAkIANwMoIAJCADcDICACQgA3AxggAkIANwMQIAJCADcDCCACQgA3AwBBACEEA0AgAiAAaiAAQYAJai0AADoAACAAQQFqIQAgBEEBaiIEQf8BcSABSA0ACyACQYABEAELIAJBgAFqJAALEgAgAEEDdkH/P3EgAEEQdhAECwkAQYAJIAAQAQsGAEGAiQELGwAgAUEDdkH/P3EgAUEQdhAEQYAJIAAQARADCwsLAQBBgAgLBPAAAAA=",hash:"c6f286e6"};function hp(e){return!Number.isInteger(e)||e<8||e>512||e%8!=0?new Error("Invalid variant! Valid values: 8, 16, ..., 512"):null}function pp(e=512,t=null){if(hp(e))return Promise.reject(hp(e));let n=null,r=e;if(null!==t){if(n=np(t),n.length>64)return Promise.reject(new Error("Max key length is 64 bytes"));i=e,o=n.length,r=i|o<<16}var i,o;const s=e/8;return up(fp,s).then(e=>{r>512&&e.writeMemory(n),e.init(r);const t={init:r>512?()=>(e.writeMemory(n),e.init(r),t):()=>(e.init(r),t),update:n=>(e.update(n),t),digest:t=>e.digest(t),save:()=>e.save(),load:n=>(e.load(n),t),blockSize:128,digestSize:s};return t})}new Jh;const gp=new DataView(new ArrayBuffer(4));function mp(e){return gp.setInt32(0,e,!0),new Uint8Array(gp.buffer)}function yp(e,t,n){return Kh(this,void 0,void 0,function*(){if(n<=64){const e=yield pp(8*n);return e.update(mp(n)),e.update(t),e.digest("binary")}const r=Math.ceil(n/32)-2,i=new Uint8Array(n);e.init(),e.update(mp(n)),e.update(t);let o=e.digest("binary");i.set(o.subarray(0,32),0);for(let t=1;t<r;t++)e.init(),e.update(o),o=e.digest("binary"),i.set(o.subarray(0,32),32*t);const s=n-32*r;let a;return 64===s?(a=e,a.init()):a=yield pp(8*s),a.update(o),o=a.digest("binary"),i.set(o.subarray(0,s),32*r),i})}function wp(e){return Kh(this,void 0,void 0,function*(){var t;const{parallelism:n,iterations:r,hashLength:i}=e,o=np(e.password),s=np(e.salt),a=function(e){switch(e){case"d":return 0;case"i":return 1;default:return 2}}(e.hashType),{memorySize:l}=e,c=np(null!==(t=e.secret)&&void 0!==t?t:""),[u,d]=yield Promise.all([up(dp,1024),pp(512)]);u.setMemorySize(1024*l+1024);const f=new Uint8Array(24),h=new DataView(f.buffer);h.setInt32(0,n,!0),h.setInt32(4,i,!0),h.setInt32(8,l,!0),h.setInt32(12,r,!0),h.setInt32(16,19,!0),h.setInt32(20,a,!0),u.writeMemory(f,1024*l),d.init(),d.update(f),d.update(mp(o.length)),d.update(o),d.update(mp(s.length)),d.update(s),d.update(mp(c.length)),d.update(c),d.update(mp(0));const p=4*Math.floor(l/(4*n)),g=new Uint8Array(72),m=d.digest("binary");g.set(m);for(let e=0;e<n;e++){g.set(mp(0),64),g.set(mp(e),68);let t=e*p,n=yield yp(d,g,1024);u.writeMemory(n,1024*t),t+=1,g.set(mp(1),64),n=yield yp(d,g,1024),u.writeMemory(n,1024*t)}const y=new Uint8Array(1024);Zh(y,u.calculate(new Uint8Array([]),l));const w=yield yp(d,y,i);if("hex"===e.outputType){return tp(new Uint8Array(2*i),w,i)}return"encoded"===e.outputType?function(e,t,n){const r=[`m=${t.memorySize}`,`t=${t.iterations}`,`p=${t.parallelism}`].join(",");return`$argon2${t.hashType}$v=19$${r}$${op(e,!1)}$${op(n,!1)}`}(s,e,w):w})}function vp(e){return Kh(this,void 0,void 0,function*(){return(e=>{var t;if(!e||"object"!=typeof e)throw new Error("Invalid options parameter. It requires an object.");if(!e.password)throw new Error("Password must be specified");if(e.password=np(e.password),e.password.length<1)throw new Error("Password must be specified");if(!e.salt)throw new Error("Salt must be specified");if(e.salt=np(e.salt),e.salt.length<8)throw new Error("Salt should be at least 8 bytes long");if(e.secret=np(null!==(t=e.secret)&&void 0!==t?t:""),!Number.isInteger(e.iterations)||e.iterations<1)throw new Error("Iterations should be a positive number");if(!Number.isInteger(e.parallelism)||e.parallelism<1)throw new Error("Parallelism should be a positive number");if(!Number.isInteger(e.hashLength)||e.hashLength<4)throw new Error("Hash length should be at least 4 bytes.");if(!Number.isInteger(e.memorySize))throw new Error("Memory size should be specified.");if(e.memorySize<8*e.parallelism)throw new Error("Memory size should be at least 8 * parallelism.");if(void 0===e.outputType&&(e.outputType="hex"),!["hex","binary","encoded"].includes(e.outputType))throw new Error(`Insupported output type ${e.outputType}. Valid values: ['hex', 'binary', 'encoded']`)})(e),wp(Object.assign(Object.assign({},e),{hashType:"id"}))})}new Jh,new Jh,new Jh,new Jh,new Jh,new Jh,new Jh,new Jh,new Jh,new Jh,new Jh,new Jh,new Jh,new Jh,new Jh,new Jh,new Jh,new Jh,new Jh,new Jh;const Ap={parallelism:4,iterations:8,memorySize:262144,hashLength:32,outputType:"binary"};let bp=null,kp=0;const Ip=new Map;async function Ep(e,t){try{const n=function(){if(bp)return bp;const e=new Blob(["\n importScripts('https://cdn.jsdelivr.net/npm/hash-wasm@4.11.0/dist/argon2.umd.min.js');\n\n const ARGON2_CONFIG = {\n parallelism: 4,\n iterations: 8,\n memorySize: 262144,\n hashLength: 32,\n outputType: \"binary\"\n };\n\n self.onmessage = async function(e) {\n const { password, salt, id } = e.data;\n\n try {\n const result = await hashwasm.argon2id({\n password: password,\n salt: new Uint8Array(salt),\n ...ARGON2_CONFIG\n });\n\n self.postMessage({\n id,\n success: true,\n result: Array.from(result)\n });\n } catch (error) {\n self.postMessage({\n id,\n success: false,\n error: error.message\n });\n }\n };\n "],{type:"application/javascript"});return bp=new Worker(URL.createObjectURL(e)),bp.onmessage=function(e){const{id:t,success:n,result:r,error:i}=e.data,o=Ip.get(t);o&&(Ip.delete(t),n?o.resolve(new Uint8Array(r)):o.reject(new Error(i)))},bp.onerror=function(e){console.error("Argon2 worker error:",e)},bp}(),r=++kp;return new Promise((i,o)=>{Ip.set(r,{resolve:i,reject:o}),n.postMessage({id:r,password:e,salt:Array.from(t)})})}catch(n){console.warn("Worker failed, falling back to main thread:",n);return await vp({password:e,salt:t,...Ap})}}const{window:Cp}=l;function xp(e){let t,n,i,o,s,a,l,f,p,g,y,b,k,I,E,C,x,S;function F(e,t){return"extension"===e[2]?Sp:Bp}let Q=F(e),R=Q(e),D=e[10]&&Mp(e),P=e[11]&&_p(e);return{c(){t=h("div"),n=h("div"),i=h("div"),o=h("h2"),o.textContent="Login to Nostr",s=m(),a=h("button"),a.textContent="×",l=m(),f=h("div"),p=h("div"),g=h("button"),g.textContent="Extension",y=m(),b=h("button"),b.textContent="Nsec",k=m(),I=h("div"),R.c(),E=m(),D&&D.c(),C=m(),P&&P.c(),A(o,"class","svelte-4xpfbi"),A(a,"class","close-btn svelte-4xpfbi"),A(i,"class","modal-header svelte-4xpfbi"),A(g,"class","tab-btn svelte-4xpfbi"),B(g,"active","extension"===e[2]),A(b,"class","tab-btn svelte-4xpfbi"),B(b,"active","nsec"===e[2]),A(p,"class","tabs svelte-4xpfbi"),A(I,"class","tab-content svelte-4xpfbi"),A(f,"class","tab-container svelte-4xpfbi"),A(n,"class","modal svelte-4xpfbi"),B(n,"dark-theme",e[1]),A(t,"class","modal-overlay svelte-4xpfbi"),A(t,"role","button"),A(t,"tabindex","0")},m(r,d){u(r,t,d),c(t,n),c(n,i),c(i,o),c(i,s),c(i,a),c(n,l),c(n,f),c(f,p),c(p,g),c(p,y),c(p,b),c(f,k),c(f,I),R.m(I,null),c(I,E),D&&D.m(I,null),c(I,C),P&&P.m(I,null),x||(S=[w(a,"click",e[17]),w(g,"click",e[26]),w(b,"click",e[27]),w(n,"click",v(e[24])),w(n,"keydown",v(e[25])),w(t,"click",e[17]),w(t,"keydown",e[32])],x=!0)},p(e,t){4&t[0]&&B(g,"active","extension"===e[2]),4&t[0]&&B(b,"active","nsec"===e[2]),Q===(Q=F(e))&&R?R.p(e,t):(R.d(1),R=Q(e),R&&(R.c(),R.m(I,E))),e[10]?D?D.p(e,t):(D=Mp(e),D.c(),D.m(I,C)):D&&(D.d(1),D=null),e[11]?P?P.p(e,t):(P=_p(e),P.c(),P.m(I,null)):P&&(P.d(1),P=null),2&t[0]&&B(n,"dark-theme",e[1])},d(e){e&&d(t),R.d(),D&&D.d(),P&&P.d(),x=!1,r(S)}}}function Bp(e){let t;function n(e,t){return e[14]?Qp:Fp}let r=n(e),i=r(e);return{c(){t=h("div"),i.c(),A(t,"class","nsec-login svelte-4xpfbi")},m(e,n){u(e,t,n),i.m(t,null)},p(e,o){r===(r=n(e))&&i?i.p(e,o):(i.d(1),i=r(e),i&&(i.c(),i.m(t,null)))},d(e){e&&d(t),i.d()}}}function Sp(e){let t,n,r,i,o,s,a,l=e[7]?"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=m(),i=h("button"),o=g(l),A(n,"class","svelte-4xpfbi"),A(i,"class","login-extension-btn svelte-4xpfbi"),i.disabled=e[7],A(t,"class","extension-login svelte-4xpfbi")},m(l,d){u(l,t,d),c(t,n),c(t,r),c(t,i),c(i,o),s||(a=w(i,"click",e[21]),s=!0)},p(e,t){128&t[0]&&l!==(l=e[7]?"Connecting...":"Log in using extension")&&k(o,l),128&t[0]&&(i.disabled=e[7])},d(e){e&&d(t),s=!1,a()}}}function Fp(e){let t,n,i,o,s,a,l,f,p,y,v,b,E,C,x,B,S,F,Q,R,D,P,T,U=e[8]?"Generating...":"Generate New Key",$=e[12]&&Rp(e),N=e[4]&&Dp(e);function L(e,t){return e[9]?Up:e[7]?Tp:Pp}let O=L(e),M=O(e);return{c(){t=h("p"),t.textContent="Enter your nsec or generate a new one. Optionally\n set a password to encrypt it securely.",n=m(),i=h("button"),o=g(U),a=m(),$&&$.c(),l=m(),f=h("input"),y=m(),v=h("div"),b=h("label"),b.textContent="Encryption Password (optional but recommended):",E=m(),C=h("input"),B=m(),N&&N.c(),S=m(),F=h("small"),F.textContent="Password uses Argon2id with ~3 second derivation time for security.",Q=m(),R=h("button"),M.c(),A(t,"class","svelte-4xpfbi"),A(i,"class","generate-btn svelte-4xpfbi"),i.disabled=s=e[7]||e[8],A(f,"type","password"),A(f,"placeholder","nsec1..."),f.disabled=p=e[7]||e[9],A(f,"class","nsec-input svelte-4xpfbi"),A(b,"class","svelte-4xpfbi"),A(C,"type","password"),A(C,"placeholder","Enter password (min 8 chars)"),C.disabled=x=e[7]||e[9],A(C,"class","password-input svelte-4xpfbi"),A(F,"class","password-hint svelte-4xpfbi"),A(v,"class","password-section svelte-4xpfbi"),A(R,"class","login-nsec-btn svelte-4xpfbi"),R.disabled=D=e[7]||e[9]||!e[3].trim()},m(r,s){u(r,t,s),u(r,n,s),u(r,i,s),c(i,o),u(r,a,s),$&&$.m(r,s),u(r,l,s),u(r,f,s),I(f,e[3]),u(r,y,s),u(r,v,s),c(v,b),c(v,E),c(v,C),I(C,e[4]),c(v,B),N&&N.m(v,null),c(v,S),c(v,F),u(r,Q,s),u(r,R,s),M.m(R,null),P||(T=[w(i,"click",e[20]),w(f,"input",e[29]),w(C,"input",e[30]),w(R,"click",e[22])],P=!0)},p(e,t){256&t[0]&&U!==(U=e[8]?"Generating...":"Generate New Key")&&k(o,U),384&t[0]&&s!==(s=e[7]||e[8])&&(i.disabled=s),e[12]?$?$.p(e,t):($=Rp(e),$.c(),$.m(l.parentNode,l)):$&&($.d(1),$=null),640&t[0]&&p!==(p=e[7]||e[9])&&(f.disabled=p),8&t[0]&&f.value!==e[3]&&I(f,e[3]),640&t[0]&&x!==(x=e[7]||e[9])&&(C.disabled=x),16&t[0]&&C.value!==e[4]&&I(C,e[4]),e[4]?N?N.p(e,t):(N=Dp(e),N.c(),N.m(v,S)):N&&(N.d(1),N=null),O!==(O=L(e))&&(M.d(1),M=O(e),M&&(M.c(),M.m(R,null))),648&t[0]&&D!==(D=e[7]||e[9]||!e[3].trim())&&(R.disabled=D)},d(e){e&&d(t),e&&d(n),e&&d(i),e&&d(a),$&&$.d(e),e&&d(l),e&&d(f),e&&d(y),e&&d(v),N&&N.d(),e&&d(Q),e&&d(R),M.d(),P=!1,r(T)}}}function Qp(e){let t,n,i,o,s,a,l,f,p,y,v,b,k,E,C=e[15]&&$p(e);function x(e,t){return e[9]?Op:e[7]?Lp:Np}let B=x(e),S=B(e);return{c(){t=h("p"),t.textContent="You have a stored encrypted key. Enter your\n password to unlock it.",n=m(),C&&C.c(),i=m(),o=h("input"),a=m(),l=h("button"),S.c(),p=m(),y=h("button"),v=g("Clear stored key & start fresh"),A(t,"class","svelte-4xpfbi"),A(o,"type","password"),A(o,"placeholder","Enter your password"),o.disabled=s=e[7]||e[9],A(o,"class","password-input svelte-4xpfbi"),A(l,"class","login-nsec-btn svelte-4xpfbi"),l.disabled=f=e[7]||e[9]||!e[6],A(y,"class","clear-btn svelte-4xpfbi"),y.disabled=b=e[7]||e[9]},m(r,s){u(r,t,s),u(r,n,s),C&&C.m(r,s),u(r,i,s),u(r,o,s),I(o,e[6]),u(r,a,s),u(r,l,s),S.m(l,null),u(r,p,s),u(r,y,s),c(y,v),k||(E=[w(o,"input",e[28]),w(l,"click",e[18]),w(y,"click",e[16])],k=!0)},p(e,t){e[15]?C?C.p(e,t):(C=$p(e),C.c(),C.m(i.parentNode,i)):C&&(C.d(1),C=null),640&t[0]&&s!==(s=e[7]||e[9])&&(o.disabled=s),64&t[0]&&o.value!==e[6]&&I(o,e[6]),B!==(B=x(e))&&(S.d(1),S=B(e),S&&(S.c(),S.m(l,null))),704&t[0]&&f!==(f=e[7]||e[9]||!e[6])&&(l.disabled=f),640&t[0]&&b!==(b=e[7]||e[9])&&(y.disabled=b)},d(e){e&&d(t),e&&d(n),C&&C.d(e),e&&d(i),e&&d(o),e&&d(a),e&&d(l),S.d(),e&&d(p),e&&d(y),k=!1,r(E)}}}function Rp(e){let t,n,r,i,o;return{c(){t=h("div"),n=h("label"),n.textContent="Your new public key (npub):",r=m(),i=h("code"),o=g(e[12]),A(n,"class","svelte-4xpfbi"),A(i,"class","npub-display svelte-4xpfbi"),A(t,"class","generated-info svelte-4xpfbi")},m(e,s){u(e,t,s),c(t,n),c(t,r),c(t,i),c(i,o)},p(e,t){4096&t[0]&&k(o,e[12])},d(e){e&&d(t)}}}function Dp(e){let t,n,r,i;return{c(){t=h("input"),A(t,"type","password"),A(t,"placeholder","Confirm password"),t.disabled=n=e[7]||e[9],A(t,"class","password-input svelte-4xpfbi")},m(n,o){u(n,t,o),I(t,e[5]),r||(i=w(t,"input",e[31]),r=!0)},p(e,r){640&r[0]&&n!==(n=e[7]||e[9])&&(t.disabled=n),32&r[0]&&t.value!==e[5]&&I(t,e[5])},d(e){e&&d(t),r=!1,i()}}}function Pp(e){let t;return{c(){t=g("Log in with nsec")},m(e,n){u(e,t,n)},d(e){e&&d(t)}}}function Tp(e){let t;return{c(){t=g("Logging in...")},m(e,n){u(e,t,n)},d(e){e&&d(t)}}}function Up(e){let t;return{c(){t=g("Deriving key...")},m(e,n){u(e,t,n)},d(e){e&&d(t)}}}function $p(e){let t,n,r,i,o,s,a,l=e[15].slice(0,16)+"",f=e[15].slice(-8)+"";return{c(){t=h("div"),n=h("label"),n.textContent="Stored public key:",r=m(),i=h("code"),o=g(l),s=g("..."),a=g(f),A(n,"class","svelte-4xpfbi"),A(i,"class","npub-display svelte-4xpfbi"),A(t,"class","stored-info svelte-4xpfbi")},m(e,l){u(e,t,l),c(t,n),c(t,r),c(t,i),c(i,o),c(i,s),c(i,a)},p(e,t){32768&t[0]&&l!==(l=e[15].slice(0,16)+"")&&k(o,l),32768&t[0]&&f!==(f=e[15].slice(-8)+"")&&k(a,f)},d(e){e&&d(t)}}}function Np(e){let t;return{c(){t=g("Unlock")},m(e,n){u(e,t,n)},d(e){e&&d(t)}}}function Lp(e){let t;return{c(){t=g("Unlocking...")},m(e,n){u(e,t,n)},d(e){e&&d(t)}}}function Op(e){let t;return{c(){t=g("Deriving key...")},m(e,n){u(e,t,n)},d(e){e&&d(t)}}}function Mp(e){let t,n;return{c(){t=h("div"),n=g(e[10]),A(t,"class","message error-message svelte-4xpfbi")},m(e,r){u(e,t,r),c(t,n)},p(e,t){1024&t[0]&&k(n,e[10])},d(e){e&&d(t)}}}function _p(e){let t,n;return{c(){t=h("div"),n=g(e[11]),A(t,"class","message success-message svelte-4xpfbi")},m(e,r){u(e,t,r),c(t,n)},p(e,t){2048&t[0]&&k(n,e[11])},d(e){e&&d(t)}}}function Hp(e){let t,n,r,i,o,s,a,l,f,p,y,w=e[13].toFixed(1)+"";return{c(){t=h("div"),n=h("div"),r=h("div"),i=m(),o=h("h3"),o.textContent="Deriving encryption key",s=m(),a=h("div"),l=g(w),f=g("s"),p=m(),y=h("p"),y.textContent="This may take 3-6 seconds for security",A(r,"class","deriving-spinner svelte-4xpfbi"),A(o,"class","svelte-4xpfbi"),A(a,"class","deriving-timer svelte-4xpfbi"),A(y,"class","deriving-note svelte-4xpfbi"),A(n,"class","deriving-modal svelte-4xpfbi"),B(n,"dark-theme",e[1]),A(t,"class","deriving-overlay svelte-4xpfbi")},m(e,d){u(e,t,d),c(t,n),c(n,r),c(n,i),c(n,o),c(n,s),c(n,a),c(a,l),c(a,f),c(n,p),c(n,y)},p(e,t){8192&t[0]&&w!==(w=e[13].toFixed(1)+"")&&k(l,w),2&t[0]&&B(n,"dark-theme",e[1])},d(e){e&&d(t)}}}function jp(t){let n,r,i,o,s=t[0]&&xp(t),a=t[9]&&Hp(t);return{c(){s&&s.c(),n=m(),a&&a.c(),r=y()},m(e,l){s&&s.m(e,l),u(e,n,l),a&&a.m(e,l),u(e,r,l),i||(o=w(Cp,"keydown",t[23]),i=!0)},p(e,t){e[0]?s?s.p(e,t):(s=xp(e),s.c(),s.m(n.parentNode,n)):s&&(s.d(1),s=null),e[9]?a?a.p(e,t):(a=Hp(e),a.c(),a.m(r.parentNode,r)):a&&(a.d(1),a=null)},i:e,o:e,d(e){s&&s.d(e),e&&d(n),a&&a.d(e),e&&d(r),i=!1,o()}}}function Gp(e,t,n){const r=P();let{showModal:i=!1}=t,{isDarkTheme:o=!1}=t,s="extension",a="",l="",c="",u="",d=!1,f=!1,h=!1,p="",g="",m="",y="",w=0,v=null,A=null;function b(){n(13,w=0),v=performance.now(),k()}function k(){null!==v&&(n(13,w=(performance.now()-v)/1e3),A=requestAnimationFrame(k))}function I(){v=null,A&&(cancelAnimationFrame(A),A=null)}D(()=>{I()});let E=!1,C="";function x(){n(14,E=!!localStorage.getItem("nostr_privkey_encrypted")),n(15,C=localStorage.getItem("nostr_pubkey")||"")}function B(){n(0,i=!1),n(3,a=""),n(4,l=""),n(5,c=""),n(6,u=""),n(10,p=""),n(11,g=""),m="",n(12,y=""),r("close")}function S(e){n(2,s=e),n(10,p=""),n(11,g=""),m="",n(12,y="")}async function F(){n(7,d=!0),n(10,p=""),n(11,g="");try{if(!a.trim())throw new Error("Please enter your nsec");if(!function(e){if(!e||!e.startsWith("nsec1"))return!1;try{return"nsec"===yu(e).type}catch{return!1}}(a.trim()))throw new Error("Invalid nsec format or checksum");if(l){if(l.length<8)throw new Error("Password must be at least 8 characters");if(l!==c)throw new Error("Passwords do not match")}const e=Ef.fromKey(a.trim()),t=await e.getPublicKey();if(localStorage.setItem("nostr_auth_method","nsec"),localStorage.setItem("nostr_pubkey",t),l){n(9,h=!0),b();const e=await async function(e,t){if(!e.startsWith("nsec1"))throw new Error("Invalid nsec format - must start with nsec1");try{if("nsec"!==yu(e).type)throw new Error("Invalid nsec - wrong type")}catch(e){throw new Error("Invalid nsec - bech32 checksum failed")}const n=crypto.getRandomValues(new Uint8Array(32)),r=crypto.getRandomValues(new Uint8Array(12)),i=await Ep(t,n),o=await crypto.subtle.importKey("raw",i,{name:"AES-GCM"},!1,["encrypt"]),s=new TextEncoder,a=await crypto.subtle.encrypt({name:"AES-GCM",iv:r},o,s.encode(e)),l=new Uint8Array(n.length+r.length+a.byteLength);return l.set(n,0),l.set(r,n.length),l.set(new Uint8Array(a),n.length+r.length),btoa(String.fromCharCode(...l))}(a.trim(),l);I(),n(9,h=!1),localStorage.setItem("nostr_privkey_encrypted",e),localStorage.removeItem("nostr_privkey")}else localStorage.setItem("nostr_privkey",a.trim()),localStorage.removeItem("nostr_privkey_encrypted"),n(11,g="Successfully logged in with nsec!");r("login",{method:"nsec",pubkey:t,privateKey:a.trim(),signer:e}),setTimeout(()=>{B()},1500)}catch(e){n(10,p=e.message)}finally{n(7,d=!1)}}R(()=>{x()});return e.$$set=e=>{"showModal"in e&&n(0,i=e.showModal),"isDarkTheme"in e&&n(1,o=e.isDarkTheme)},e.$$.update=()=>{1&e.$$.dirty[0]&&i&&x()},[i,o,s,a,l,c,u,d,f,h,p,g,y,w,E,C,function(){localStorage.removeItem("nostr_privkey_encrypted"),localStorage.removeItem("nostr_privkey"),localStorage.removeItem("nostr_pubkey"),localStorage.removeItem("nostr_auth_method"),n(14,E=!1),n(15,C=""),n(6,u=""),n(10,p=""),n(11,g="")},B,async function(){n(7,d=!0),n(9,h=!0),b(),n(10,p=""),n(11,g="");try{if(!u)throw new Error("Please enter your password");const e=localStorage.getItem("nostr_privkey_encrypted");if(!e)throw new Error("No encrypted key found");const t=await async function(e,t){const n=new Uint8Array(atob(e).split("").map(e=>e.charCodeAt(0)));if(n.length<60)throw new Error("Invalid encrypted data - too short");const r=n.slice(0,32),i=n.slice(32,44),o=n.slice(44),s=await Ep(t,r),a=await crypto.subtle.importKey("raw",s,{name:"AES-GCM"},!1,["decrypt"]);let l;try{l=await crypto.subtle.decrypt({name:"AES-GCM",iv:i},a,o)}catch(e){throw new Error("Decryption failed - invalid password or corrupted data")}const c=(new TextDecoder).decode(l);if(!c.startsWith("nsec1"))throw new Error("Decryption produced invalid data - not an nsec");try{if("nsec"!==yu(c).type)throw new Error("Decryption produced invalid nsec type")}catch(e){throw new Error("Decryption produced invalid nsec - bech32 checksum failed")}return c}(e,u);I(),n(9,h=!1);const i=Ef.fromKey(t),o=await i.getPublicKey();r("login",{method:"nsec",pubkey:o,privateKey:t,signer:i}),B()}catch(e){I(),e.message.includes("decrypt")||e.message.includes("tag")?n(10,p="Invalid password"):n(10,p=e.message)}finally{n(7,d=!1),n(9,h=!1),I()}},S,async function(){n(8,f=!0),n(10,p=""),n(11,g="");try{const e=Zc(),t=Au("nsec",e),r=vu(Xc(e));m=t,n(12,y=r),n(3,a=t),n(11,g="New key generated! Set an encryption password below to secure it.")}catch(e){n(10,p="Failed to generate key: "+e.message)}finally{n(8,f=!1)}},async function(){n(7,d=!0),n(10,p=""),n(11,g="");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(11,g="Successfully logged in with extension!"),r("login",{method:"extension",pubkey:e,signer:window.nostr}),setTimeout(()=>{B()},1500))}catch(e){n(10,p=e.message)}finally{n(7,d=!1)}},F,function(e){"Escape"===e.key&&B(),"Enter"===e.key&&"nsec"===s&&F()},function(t){T.call(this,e,t)},function(t){T.call(this,e,t)},()=>S("extension"),()=>S("nsec"),function(){u=this.value,n(6,u)},function(){a=this.value,n(3,a)},function(){l=this.value,n(4,l)},function(){c=this.value,n(5,c)},e=>"Escape"===e.key&&B()]}class Kp extends oe{constructor(e){super(),ie(this,e,Gp,jp,o,{showModal:0,isDarkTheme:1},null,[-1,-1])}}function Jp(e,t,n){const r=e.slice();return r[72]=t[n],r}function Vp(e,t,n){const r=e.slice();return r[75]=t[n],r}function qp(e,t,n){const r=e.slice();return r[72]=t[n],r}function zp(e,t,n){const r=e.slice();return r[72]=t[n],r}function Yp(e,t,n){const r=e.slice();return r[72]=t[n],r}function Wp(e,t,n){const r=e.slice();return r[72]=t[n],r}function Zp(e,t,n){const r=e.slice();return r[72]=t[n],r}function Xp(e){let t,n,r;return{c(){t=h("div"),n=g(e[3]),A(t,"class",r="message "+e[4]+" svelte-1y8wjwc")},m(e,r){u(e,t,r),c(t,n)},p(e,i){8&i[0]&&k(n,e[3]),16&i[0]&&r!==(r="message "+e[4]+" svelte-1y8wjwc")&&A(t,"class",r)},d(e){e&&d(t)}}}function eg(e){let t,n,i,o,s,a,l,f,p,y,v,b,k,E,C,x,B,S,F,Q,R,D,P,T,U,$,N,L;function O(e,t){return e[5]&&e[5].length>0?ng:tg}let M=O(e),_=M(e);function H(e,t){return e[8]&&e[8].length>0?sg:og}let j=H(e),G=j(e);return{c(){t=h("div"),n=h("div"),i=h("h3"),i.textContent="Banned Pubkeys",o=m(),s=h("div"),a=h("input"),l=m(),f=h("input"),p=m(),y=h("button"),v=g("Ban Pubkey"),b=m(),k=h("div"),_.c(),E=m(),C=h("div"),x=h("h3"),x.textContent="Allowed Pubkeys",B=m(),S=h("div"),F=h("input"),Q=m(),R=h("input"),D=m(),P=h("button"),T=g("Allow Pubkey"),U=m(),$=h("div"),G.c(),A(i,"class","svelte-1y8wjwc"),A(a,"type","text"),A(a,"placeholder","Pubkey (64 hex chars)"),A(a,"class","svelte-1y8wjwc"),A(f,"type","text"),A(f,"placeholder","Reason (optional)"),A(f,"class","svelte-1y8wjwc"),y.disabled=e[2],A(y,"class","svelte-1y8wjwc"),A(s,"class","add-form svelte-1y8wjwc"),A(k,"class","list svelte-1y8wjwc"),A(n,"class","section svelte-1y8wjwc"),A(x,"class","svelte-1y8wjwc"),A(F,"type","text"),A(F,"placeholder","Pubkey (64 hex chars)"),A(F,"class","svelte-1y8wjwc"),A(R,"type","text"),A(R,"placeholder","Reason (optional)"),A(R,"class","svelte-1y8wjwc"),P.disabled=e[2],A(P,"class","svelte-1y8wjwc"),A(S,"class","add-form svelte-1y8wjwc"),A($,"class","list svelte-1y8wjwc"),A(C,"class","section svelte-1y8wjwc"),A(t,"class","pubkeys-section")},m(r,d){u(r,t,d),c(t,n),c(n,i),c(n,o),c(n,s),c(s,a),I(a,e[6]),c(s,l),c(s,f),I(f,e[7]),c(s,p),c(s,y),c(y,v),c(n,b),c(n,k),_.m(k,null),c(t,E),c(t,C),c(C,x),c(C,B),c(C,S),c(S,F),I(F,e[9]),c(S,Q),c(S,R),I(R,e[10]),c(S,D),c(S,P),c(P,T),c(C,U),c(C,$),G.m($,null),N||(L=[w(a,"input",e[43]),w(f,"input",e[44]),w(y,"click",e[25]),w(F,"input",e[45]),w(R,"input",e[46]),w(P,"click",e[26])],N=!0)},p(e,t){64&t[0]&&a.value!==e[6]&&I(a,e[6]),128&t[0]&&f.value!==e[7]&&I(f,e[7]),4&t[0]&&(y.disabled=e[2]),M===(M=O(e))&&_?_.p(e,t):(_.d(1),_=M(e),_&&(_.c(),_.m(k,null))),512&t[0]&&F.value!==e[9]&&I(F,e[9]),1024&t[0]&&R.value!==e[10]&&I(R,e[10]),4&t[0]&&(P.disabled=e[2]),j===(j=H(e))&&G?G.p(e,t):(G.d(1),G=j(e),G&&(G.c(),G.m($,null)))},d(e){e&&d(t),_.d(),G.d(),N=!1,r(L)}}}function tg(t){let n;return{c(){n=h("div"),n.innerHTML="<p>No banned pubkeys configured.</p>",A(n,"class","no-items svelte-1y8wjwc")},m(e,t){u(e,n,t)},p:e,d(e){e&&d(n)}}}function ng(e){let t,n=e[5],r=[];for(let t=0;t<n.length;t+=1)r[t]=ig(Zp(e,n,t));return{c(){for(let e=0;e<r.length;e+=1)r[e].c();t=y()},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,i){if(32&i[0]){let o;for(n=e[5],o=0;o<n.length;o+=1){const s=Zp(e,n,o);r[o]?r[o].p(s,i):(r[o]=ig(s),r[o].c(),r[o].m(t.parentNode,t))}for(;o<r.length;o+=1)r[o].d(1);r.length=n.length}},d(e){f(r,e),e&&d(t)}}}function rg(e){let t,n,r=e[72].reason+"";return{c(){t=h("span"),n=g(r),A(t,"class","reason svelte-1y8wjwc")},m(e,r){u(e,t,r),c(t,n)},p(e,t){32&t[0]&&r!==(r=e[72].reason+"")&&k(n,r)},d(e){e&&d(t)}}}function ig(e){let t,n,r,i,o,s=e[72].pubkey+"",a=e[72].reason&&rg(e);return{c(){t=h("div"),n=h("span"),r=g(s),i=m(),a&&a.c(),o=m(),A(n,"class","pubkey svelte-1y8wjwc"),A(t,"class","list-item svelte-1y8wjwc")},m(e,s){u(e,t,s),c(t,n),c(n,r),c(t,i),a&&a.m(t,null),c(t,o)},p(e,n){32&n[0]&&s!==(s=e[72].pubkey+"")&&k(r,s),e[72].reason?a?a.p(e,n):(a=rg(e),a.c(),a.m(t,o)):a&&(a.d(1),a=null)},d(e){e&&d(t),a&&a.d()}}}function og(t){let n;return{c(){n=h("div"),n.innerHTML="<p>No allowed pubkeys configured.</p>",A(n,"class","no-items svelte-1y8wjwc")},m(e,t){u(e,n,t)},p:e,d(e){e&&d(n)}}}function sg(e){let t,n=e[8],r=[];for(let t=0;t<n.length;t+=1)r[t]=lg(Wp(e,n,t));return{c(){for(let e=0;e<r.length;e+=1)r[e].c();t=y()},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,i){if(256&i[0]){let o;for(n=e[8],o=0;o<n.length;o+=1){const s=Wp(e,n,o);r[o]?r[o].p(s,i):(r[o]=lg(s),r[o].c(),r[o].m(t.parentNode,t))}for(;o<r.length;o+=1)r[o].d(1);r.length=n.length}},d(e){f(r,e),e&&d(t)}}}function ag(e){let t,n,r=e[72].reason+"";return{c(){t=h("span"),n=g(r),A(t,"class","reason svelte-1y8wjwc")},m(e,r){u(e,t,r),c(t,n)},p(e,t){256&t[0]&&r!==(r=e[72].reason+"")&&k(n,r)},d(e){e&&d(t)}}}function lg(e){let t,n,r,i,o,s=e[72].pubkey+"",a=e[72].reason&&ag(e);return{c(){t=h("div"),n=h("span"),r=g(s),i=m(),a&&a.c(),o=m(),A(n,"class","pubkey svelte-1y8wjwc"),A(t,"class","list-item svelte-1y8wjwc")},m(e,s){u(e,t,s),c(t,n),c(n,r),c(t,i),a&&a.m(t,null),c(t,o)},p(e,n){256&n[0]&&s!==(s=e[72].pubkey+"")&&k(r,s),e[72].reason?a?a.p(e,n):(a=ag(e),a.c(),a.m(t,o)):a&&(a.d(1),a=null)},d(e){e&&d(t),a&&a.d()}}}function cg(e){let t,n,i,o,s,a,l,f,p,y,v,b,k,E,C,x,B,S,F,Q,R,D,P,T,U,$,N,L;function O(e,t){return e[11]&&e[11].length>0?dg:ug}let M=O(e),_=M(e);let H=function(e){return e[22]&&e[22].length>0?gg:pg}(e),j=H(e);return{c(){t=h("div"),n=h("div"),i=h("h3"),i.textContent="Banned Events",o=m(),s=h("div"),a=h("input"),l=m(),f=h("input"),p=m(),y=h("button"),v=g("Ban Event"),b=m(),k=h("div"),_.c(),E=m(),C=h("div"),x=h("h3"),x.textContent="Allowed Events",B=m(),S=h("div"),F=h("input"),Q=m(),R=h("input"),D=m(),P=h("button"),T=g("Allow Event"),U=m(),$=h("div"),j.c(),A(i,"class","svelte-1y8wjwc"),A(a,"type","text"),A(a,"placeholder","Event ID (64 hex chars)"),A(a,"class","svelte-1y8wjwc"),A(f,"type","text"),A(f,"placeholder","Reason (optional)"),A(f,"class","svelte-1y8wjwc"),y.disabled=e[2],A(y,"class","svelte-1y8wjwc"),A(s,"class","add-form svelte-1y8wjwc"),A(k,"class","list svelte-1y8wjwc"),A(n,"class","section svelte-1y8wjwc"),A(x,"class","svelte-1y8wjwc"),A(F,"type","text"),A(F,"placeholder","Event ID (64 hex chars)"),A(F,"class","svelte-1y8wjwc"),A(R,"type","text"),A(R,"placeholder","Reason (optional)"),A(R,"class","svelte-1y8wjwc"),P.disabled=e[2],A(P,"class","svelte-1y8wjwc"),A(S,"class","add-form svelte-1y8wjwc"),A($,"class","list svelte-1y8wjwc"),A(C,"class","section svelte-1y8wjwc"),A(t,"class","events-section")},m(r,d){u(r,t,d),c(t,n),c(n,i),c(n,o),c(n,s),c(s,a),I(a,e[12]),c(s,l),c(s,f),I(f,e[13]),c(s,p),c(s,y),c(y,v),c(n,b),c(n,k),_.m(k,null),c(t,E),c(t,C),c(C,x),c(C,B),c(C,S),c(S,F),I(F,e[14]),c(S,Q),c(S,R),I(R,e[15]),c(S,D),c(S,P),c(P,T),c(C,U),c(C,$),j.m($,null),N||(L=[w(a,"input",e[47]),w(f,"input",e[48]),w(y,"click",e[27]),w(F,"input",e[49]),w(R,"input",e[50]),w(P,"click",e[28])],N=!0)},p(e,t){4096&t[0]&&a.value!==e[12]&&I(a,e[12]),8192&t[0]&&f.value!==e[13]&&I(f,e[13]),4&t[0]&&(y.disabled=e[2]),M===(M=O(e))&&_?_.p(e,t):(_.d(1),_=M(e),_&&(_.c(),_.m(k,null))),16384&t[0]&&F.value!==e[14]&&I(F,e[14]),32768&t[0]&&R.value!==e[15]&&I(R,e[15]),4&t[0]&&(P.disabled=e[2]),j.p(e,t)},d(e){e&&d(t),_.d(),j.d(),N=!1,r(L)}}}function ug(t){let n;return{c(){n=h("div"),n.innerHTML="<p>No banned events configured.</p>",A(n,"class","no-items svelte-1y8wjwc")},m(e,t){u(e,n,t)},p:e,d(e){e&&d(n)}}}function dg(e){let t,n=e[11],r=[];for(let t=0;t<n.length;t+=1)r[t]=hg(Yp(e,n,t));return{c(){for(let e=0;e<r.length;e+=1)r[e].c();t=y()},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,i){if(2048&i[0]){let o;for(n=e[11],o=0;o<n.length;o+=1){const s=Yp(e,n,o);r[o]?r[o].p(s,i):(r[o]=hg(s),r[o].c(),r[o].m(t.parentNode,t))}for(;o<r.length;o+=1)r[o].d(1);r.length=n.length}},d(e){f(r,e),e&&d(t)}}}function fg(e){let t,n,r=e[72].reason+"";return{c(){t=h("span"),n=g(r),A(t,"class","reason svelte-1y8wjwc")},m(e,r){u(e,t,r),c(t,n)},p(e,t){2048&t[0]&&r!==(r=e[72].reason+"")&&k(n,r)},d(e){e&&d(t)}}}function hg(e){let t,n,r,i,o,s=e[72].id+"",a=e[72].reason&&fg(e);return{c(){t=h("div"),n=h("span"),r=g(s),i=m(),a&&a.c(),o=m(),A(n,"class","event-id svelte-1y8wjwc"),A(t,"class","list-item svelte-1y8wjwc")},m(e,s){u(e,t,s),c(t,n),c(n,r),c(t,i),a&&a.m(t,null),c(t,o)},p(e,n){2048&n[0]&&s!==(s=e[72].id+"")&&k(r,s),e[72].reason?a?a.p(e,n):(a=fg(e),a.c(),a.m(t,o)):a&&(a.d(1),a=null)},d(e){e&&d(t),a&&a.d()}}}function pg(t){let n;return{c(){n=h("div"),n.innerHTML="<p>No allowed events configured.</p>",A(n,"class","no-items svelte-1y8wjwc")},m(e,t){u(e,n,t)},p:e,d(e){e&&d(n)}}}function gg(e){let t,n=e[22],r=[];for(let t=0;t<n.length;t+=1)r[t]=mg(zp(e,n,t));return{c(){for(let e=0;e<r.length;e+=1)r[e].c();t=y()},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,i){if(4194304&i[0]){let o;for(n=e[22],o=0;o<n.length;o+=1){const s=zp(e,n,o);r[o]?r[o].p(s,i):(r[o]=mg(s),r[o].c(),r[o].m(t.parentNode,t))}for(;o<r.length;o+=1)r[o].d(1);r.length=n.length}},d(e){f(r,e),e&&d(t)}}}function mg(t){let n,r,i,o,s,a=t[72].id+"",l=t[72].reason&&function(t){let n,r,i=t[72].reason+"";return{c(){n=h("span"),r=g(i),A(n,"class","reason svelte-1y8wjwc")},m(e,t){u(e,n,t),c(n,r)},p:e,d(e){e&&d(n)}}}(t);return{c(){n=h("div"),r=h("span"),i=g(a),o=m(),l&&l.c(),s=m(),A(r,"class","event-id svelte-1y8wjwc"),A(n,"class","list-item svelte-1y8wjwc")},m(e,t){u(e,n,t),c(n,r),c(r,i),c(n,o),l&&l.m(n,null),c(n,s)},p(e,t){e[72].reason&&l.p(e,t)},d(e){e&&d(n),l&&l.d()}}}function yg(e){let t,n,i,o,s,a,l,f,p,y,v,b,k,E,C;function x(e,t){return e[16]&&e[16].length>0?vg:wg}let B=x(e),S=B(e);return{c(){t=h("div"),n=h("div"),i=h("h3"),i.textContent="Blocked IPs",o=m(),s=h("div"),a=h("input"),l=m(),f=h("input"),p=m(),y=h("button"),v=g("Block IP"),b=m(),k=h("div"),S.c(),A(i,"class","svelte-1y8wjwc"),A(a,"type","text"),A(a,"placeholder","IP Address"),A(a,"class","svelte-1y8wjwc"),A(f,"type","text"),A(f,"placeholder","Reason (optional)"),A(f,"class","svelte-1y8wjwc"),y.disabled=e[2],A(y,"class","svelte-1y8wjwc"),A(s,"class","add-form svelte-1y8wjwc"),A(k,"class","list svelte-1y8wjwc"),A(n,"class","section svelte-1y8wjwc"),A(t,"class","ips-section")},m(r,d){u(r,t,d),c(t,n),c(n,i),c(n,o),c(n,s),c(s,a),I(a,e[17]),c(s,l),c(s,f),I(f,e[18]),c(s,p),c(s,y),c(y,v),c(n,b),c(n,k),S.m(k,null),E||(C=[w(a,"input",e[51]),w(f,"input",e[52]),w(y,"click",e[29])],E=!0)},p(e,t){131072&t[0]&&a.value!==e[17]&&I(a,e[17]),262144&t[0]&&f.value!==e[18]&&I(f,e[18]),4&t[0]&&(y.disabled=e[2]),B===(B=x(e))&&S?S.p(e,t):(S.d(1),S=B(e),S&&(S.c(),S.m(k,null)))},d(e){e&&d(t),S.d(),E=!1,r(C)}}}function wg(t){let n;return{c(){n=h("div"),n.innerHTML="<p>No blocked IPs configured.</p>",A(n,"class","no-items svelte-1y8wjwc")},m(e,t){u(e,n,t)},p:e,d(e){e&&d(n)}}}function vg(e){let t,n=e[16],r=[];for(let t=0;t<n.length;t+=1)r[t]=bg(qp(e,n,t));return{c(){for(let e=0;e<r.length;e+=1)r[e].c();t=y()},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,i){if(65536&i[0]){let o;for(n=e[16],o=0;o<n.length;o+=1){const s=qp(e,n,o);r[o]?r[o].p(s,i):(r[o]=bg(s),r[o].c(),r[o].m(t.parentNode,t))}for(;o<r.length;o+=1)r[o].d(1);r.length=n.length}},d(e){f(r,e),e&&d(t)}}}function Ag(e){let t,n,r=e[72].reason+"";return{c(){t=h("span"),n=g(r),A(t,"class","reason svelte-1y8wjwc")},m(e,r){u(e,t,r),c(t,n)},p(e,t){65536&t[0]&&r!==(r=e[72].reason+"")&&k(n,r)},d(e){e&&d(t)}}}function bg(e){let t,n,r,i,o,s=e[72].ip+"",a=e[72].reason&&Ag(e);return{c(){t=h("div"),n=h("span"),r=g(s),i=m(),a&&a.c(),o=m(),A(n,"class","ip svelte-1y8wjwc"),A(t,"class","list-item svelte-1y8wjwc")},m(e,s){u(e,t,s),c(t,n),c(n,r),c(t,i),a&&a.m(t,null),c(t,o)},p(e,n){65536&n[0]&&s!==(s=e[72].ip+"")&&k(r,s),e[72].reason?a?a.p(e,n):(a=Ag(e),a.c(),a.m(t,o)):a&&(a.d(1),a=null)},d(e){e&&d(t),a&&a.d()}}}function kg(e){let t,n,i,o,s,a,l,f,p,y,v,k,E;function C(e,t){return e[19]&&e[19].length>0?Eg:Ig}let x=C(e),B=x(e);return{c(){t=h("div"),n=h("div"),i=h("h3"),i.textContent="Allowed Event Kinds",o=m(),s=h("div"),a=h("input"),l=m(),f=h("button"),p=g("Allow Kind"),y=m(),v=h("div"),B.c(),A(i,"class","svelte-1y8wjwc"),A(a,"type","number"),A(a,"placeholder","Kind number"),A(a,"class","svelte-1y8wjwc"),f.disabled=e[2],A(f,"class","svelte-1y8wjwc"),A(s,"class","add-form svelte-1y8wjwc"),A(v,"class","list svelte-1y8wjwc"),A(n,"class","section svelte-1y8wjwc"),A(t,"class","kinds-section")},m(r,d){u(r,t,d),c(t,n),c(n,i),c(n,o),c(n,s),c(s,a),I(a,e[20]),c(s,l),c(s,f),c(f,p),c(n,y),c(n,v),B.m(v,null),k||(E=[w(a,"input",e[53]),w(f,"click",e[30])],k=!0)},p(e,t){1048576&t[0]&&b(a.value)!==e[20]&&I(a,e[20]),4&t[0]&&(f.disabled=e[2]),x===(x=C(e))&&B?B.p(e,t):(B.d(1),B=x(e),B&&(B.c(),B.m(v,null)))},d(e){e&&d(t),B.d(),k=!1,r(E)}}}function Ig(t){let n;return{c(){n=h("div"),n.innerHTML="<p>No allowed kinds configured. All kinds are\n allowed by default.</p>",A(n,"class","no-items svelte-1y8wjwc")},m(e,t){u(e,n,t)},p:e,d(e){e&&d(n)}}}function Eg(e){let t,n=e[19],r=[];for(let t=0;t<n.length;t+=1)r[t]=Cg(Vp(e,n,t));return{c(){for(let e=0;e<r.length;e+=1)r[e].c();t=y()},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,i){if(524288&i[0]|1&i[1]){let o;for(n=e[19],o=0;o<n.length;o+=1){const s=Vp(e,n,o);r[o]?r[o].p(s,i):(r[o]=Cg(s),r[o].c(),r[o].m(t.parentNode,t))}for(;o<r.length;o+=1)r[o].d(1);r.length=n.length}},d(e){f(r,e),e&&d(t)}}}function Cg(e){let t,n,r,i,o,s,a,l,f,p=e[75]+"";function y(){return e[54](e[75])}return{c(){t=h("div"),n=h("span"),r=g("Kind "),i=g(p),o=m(),s=h("button"),s.textContent="Remove",a=m(),A(n,"class","kind svelte-1y8wjwc"),A(s,"class","remove-btn svelte-1y8wjwc"),A(t,"class","list-item svelte-1y8wjwc")},m(e,d){u(e,t,d),c(t,n),c(n,r),c(n,i),c(t,o),c(t,s),c(t,a),l||(f=w(s,"click",y),l=!0)},p(t,n){e=t,524288&n[0]&&p!==(p=e[75]+"")&&k(i,p)},d(e){e&&d(t),l=!1,f()}}}function xg(e){let t,n,r,i,o,s,a,l,f,p;function y(e,t){return e[21]&&e[21].length>0?Sg:Bg}let v=y(e),b=v(e);return{c(){t=h("div"),n=h("div"),r=h("h3"),r.textContent="Events Needing Moderation",i=m(),o=h("button"),s=g("Refresh"),a=m(),l=h("div"),b.c(),A(r,"class","svelte-1y8wjwc"),o.disabled=e[2],A(l,"class","list svelte-1y8wjwc"),A(n,"class","section svelte-1y8wjwc"),A(t,"class","moderation-section")},m(d,h){u(d,t,h),c(t,n),c(n,r),c(n,i),c(n,o),c(o,s),c(n,a),c(n,l),b.m(l,null),f||(p=w(o,"click",e[24]),f=!0)},p(e,t){4&t[0]&&(o.disabled=e[2]),v===(v=y(e))&&b?b.p(e,t):(b.d(1),b=v(e),b&&(b.c(),b.m(l,null)))},d(e){e&&d(t),b.d(),f=!1,p()}}}function Bg(t){let n;return{c(){n=h("div"),n.innerHTML="<p>No events need moderation at this time.</p>",A(n,"class","no-items svelte-1y8wjwc")},m(e,t){u(e,n,t)},p:e,d(e){e&&d(n)}}}function Sg(e){let t,n=e[21],r=[];for(let t=0;t<n.length;t+=1)r[t]=Qg(Jp(e,n,t));return{c(){for(let e=0;e<r.length;e+=1)r[e].c();t=y()},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,i){if(2097152&i[0]|12&i[1]){let o;for(n=e[21],o=0;o<n.length;o+=1){const s=Jp(e,n,o);r[o]?r[o].p(s,i):(r[o]=Qg(s),r[o].c(),r[o].m(t.parentNode,t))}for(;o<r.length;o+=1)r[o].d(1);r.length=n.length}},d(e){f(r,e),e&&d(t)}}}function Fg(e){let t,n,r=e[72].reason+"";return{c(){t=h("span"),n=g(r),A(t,"class","reason svelte-1y8wjwc")},m(e,r){u(e,t,r),c(t,n)},p(e,t){2097152&t[0]&&r!==(r=e[72].reason+"")&&k(n,r)},d(e){e&&d(t)}}}function Qg(e){let t,n,i,o,s,a,l,f,p,y,v,b,I=e[72].id+"",E=e[72].reason&&Fg(e);function C(){return e[55](e[72])}function x(){return e[56](e[72])}return{c(){t=h("div"),n=h("span"),i=g(I),o=m(),E&&E.c(),s=m(),a=h("div"),l=h("button"),l.textContent="Allow",f=m(),p=h("button"),p.textContent="Ban",y=m(),A(n,"class","event-id svelte-1y8wjwc"),A(l,"class","svelte-1y8wjwc"),A(p,"class","svelte-1y8wjwc"),A(a,"class","actions svelte-1y8wjwc"),A(t,"class","list-item svelte-1y8wjwc")},m(e,r){u(e,t,r),c(t,n),c(n,i),c(t,o),E&&E.m(t,null),c(t,s),c(t,a),c(a,l),c(a,f),c(a,p),c(t,y),v||(b=[w(l,"click",C),w(p,"click",x)],v=!0)},p(n,r){e=n,2097152&r[0]&&I!==(I=e[72].id+"")&&k(i,I),e[72].reason?E?E.p(e,r):(E=Fg(e),E.c(),E.m(t,s)):E&&(E.d(1),E=null)},d(e){e&&d(t),E&&E.d(),v=!1,r(b)}}}function Rg(e){let t,n,i,o,s,a,l,f,p,y,v,b,k,E,C,x,B,S,F,Q,R,D,P,T,U,$,N,L;function O(e,t){return e[2]?Pg:Dg}let M=O(e),_=M(e);return{c(){t=h("div"),n=h("div"),i=h("h3"),i.textContent="Relay Configuration",o=m(),s=h("div"),a=h("button"),l=g("🔄 Refresh from Relay Info"),f=m(),p=h("div"),y=h("div"),v=h("label"),v.textContent="Relay Name",b=m(),k=h("input"),E=m(),C=h("div"),x=h("label"),x.textContent="Relay Description",B=m(),S=h("textarea"),F=m(),Q=h("div"),R=h("label"),R.textContent="Relay Icon URL",D=m(),P=h("input"),T=m(),U=h("div"),$=h("button"),_.c(),A(i,"class","svelte-1y8wjwc"),a.disabled=e[2],A(a,"class","refresh-btn svelte-1y8wjwc"),A(s,"class","config-actions svelte-1y8wjwc"),A(v,"for","relay-name"),A(v,"class","svelte-1y8wjwc"),A(k,"id","relay-name"),A(k,"type","text"),A(k,"placeholder","Enter relay name"),A(k,"class","svelte-1y8wjwc"),A(y,"class","form-group svelte-1y8wjwc"),A(x,"for","relay-description"),A(x,"class","svelte-1y8wjwc"),A(S,"id","relay-description"),A(S,"placeholder","Enter relay description"),A(S,"class","svelte-1y8wjwc"),A(C,"class","form-group svelte-1y8wjwc"),A(R,"for","relay-icon"),A(R,"class","svelte-1y8wjwc"),A(P,"id","relay-icon"),A(P,"type","url"),A(P,"placeholder","Enter icon URL"),A(P,"class","svelte-1y8wjwc"),A(Q,"class","form-group svelte-1y8wjwc"),$.disabled=e[2],A($,"class","update-all-btn svelte-1y8wjwc"),A(U,"class","config-update-section svelte-1y8wjwc"),A(p,"class","config-form svelte-1y8wjwc"),A(n,"class","section svelte-1y8wjwc"),A(t,"class","relay-section")},m(r,d){u(r,t,d),c(t,n),c(n,i),c(n,o),c(n,s),c(s,a),c(a,l),c(n,f),c(n,p),c(p,y),c(y,v),c(y,b),c(y,k),I(k,e[0].relay_name),c(p,E),c(p,C),c(C,x),c(C,B),c(C,S),I(S,e[0].relay_description),c(p,F),c(p,Q),c(Q,R),c(Q,D),c(Q,P),I(P,e[0].relay_icon),c(p,T),c(p,U),c(U,$),_.m($,null),N||(L=[w(a,"click",e[23]),w(k,"input",e[57]),w(S,"input",e[58]),w(P,"input",e[59]),w($,"click",e[32])],N=!0)},p(e,t){4&t[0]&&(a.disabled=e[2]),1&t[0]&&k.value!==e[0].relay_name&&I(k,e[0].relay_name),1&t[0]&&I(S,e[0].relay_description),1&t[0]&&P.value!==e[0].relay_icon&&I(P,e[0].relay_icon),M!==(M=O(e))&&(_.d(1),_=M(e),_&&(_.c(),_.m($,null))),4&t[0]&&($.disabled=e[2])},d(e){e&&d(t),_.d(),N=!1,r(L)}}}function Dg(e){let t;return{c(){t=g("💾 Update Configuration")},m(e,n){u(e,t,n)},d(e){e&&d(t)}}}function Pg(e){let t;return{c(){t=g("⏳ Updating...")},m(e,n){u(e,t,n)},d(e){e&&d(t)}}}function Tg(t){let n,i,o,s,a,l,f,p,y,v,b,k,I,E,C,x,B,S,F,Q,R,D,P,T,U,$,N,L,O,M,_,H,j,G,K,J,V,q=t[3]&&Xp(t),z="pubkeys"===t[1]&&eg(t),Y="events"===t[1]&&cg(t),W="ips"===t[1]&&yg(t),Z="kinds"===t[1]&&kg(t),X="moderation"===t[1]&&xg(t),ee="relay"===t[1]&&Rg(t);return{c(){n=h("div"),i=h("div"),i.innerHTML='<h2 class="svelte-1y8wjwc">Managed ACL Configuration</h2> \n <p class="svelte-1y8wjwc">Configure access control using NIP-86 management API</p> \n <div class="owner-only-notice svelte-1y8wjwc"><strong>Owner Only:</strong> This interface is restricted to relay owners\n only.</div>',o=m(),q&&q.c(),s=m(),a=h("div"),l=h("button"),f=g("Pubkeys"),y=m(),v=h("button"),b=g("Events"),I=m(),E=h("button"),C=g("IPs"),B=m(),S=h("button"),F=g("Kinds"),R=m(),D=h("button"),P=g("Moderation"),U=m(),$=h("button"),N=g("Relay Config"),O=m(),M=h("div"),z&&z.c(),_=m(),Y&&Y.c(),H=m(),W&&W.c(),j=m(),Z&&Z.c(),G=m(),X&&X.c(),K=m(),ee&&ee.c(),A(i,"class","header svelte-1y8wjwc"),A(l,"class",p="tab "+("pubkeys"===t[1]?"active":"")+" svelte-1y8wjwc"),A(v,"class",k="tab "+("events"===t[1]?"active":"")+" svelte-1y8wjwc"),A(E,"class",x="tab "+("ips"===t[1]?"active":"")+" svelte-1y8wjwc"),A(S,"class",Q="tab "+("kinds"===t[1]?"active":"")+" svelte-1y8wjwc"),A(D,"class",T="tab "+("moderation"===t[1]?"active":"")+" svelte-1y8wjwc"),A($,"class",L="tab "+("relay"===t[1]?"active":"")+" svelte-1y8wjwc"),A(a,"class","tabs svelte-1y8wjwc"),A(M,"class","tab-content svelte-1y8wjwc")},m(e,r){u(e,n,r),c(n,i),c(n,o),q&&q.m(n,null),c(n,s),c(n,a),c(a,l),c(l,f),c(a,y),c(a,v),c(v,b),c(a,I),c(a,E),c(E,C),c(a,B),c(a,S),c(S,F),c(a,R),c(a,D),c(D,P),c(a,U),c(a,$),c($,N),c(n,O),c(n,M),z&&z.m(M,null),c(M,_),Y&&Y.m(M,null),c(M,H),W&&W.m(M,null),c(M,j),Z&&Z.m(M,null),c(M,G),X&&X.m(M,null),c(M,K),ee&&ee.m(M,null),J||(V=[w(l,"click",t[37]),w(v,"click",t[38]),w(E,"click",t[39]),w(S,"click",t[40]),w(D,"click",t[41]),w($,"click",t[42])],J=!0)},p(e,t){e[3]?q?q.p(e,t):(q=Xp(e),q.c(),q.m(n,s)):q&&(q.d(1),q=null),2&t[0]&&p!==(p="tab "+("pubkeys"===e[1]?"active":"")+" svelte-1y8wjwc")&&A(l,"class",p),2&t[0]&&k!==(k="tab "+("events"===e[1]?"active":"")+" svelte-1y8wjwc")&&A(v,"class",k),2&t[0]&&x!==(x="tab "+("ips"===e[1]?"active":"")+" svelte-1y8wjwc")&&A(E,"class",x),2&t[0]&&Q!==(Q="tab "+("kinds"===e[1]?"active":"")+" svelte-1y8wjwc")&&A(S,"class",Q),2&t[0]&&T!==(T="tab "+("moderation"===e[1]?"active":"")+" svelte-1y8wjwc")&&A(D,"class",T),2&t[0]&&L!==(L="tab "+("relay"===e[1]?"active":"")+" svelte-1y8wjwc")&&A($,"class",L),"pubkeys"===e[1]?z?z.p(e,t):(z=eg(e),z.c(),z.m(M,_)):z&&(z.d(1),z=null),"events"===e[1]?Y?Y.p(e,t):(Y=cg(e),Y.c(),Y.m(M,H)):Y&&(Y.d(1),Y=null),"ips"===e[1]?W?W.p(e,t):(W=yg(e),W.c(),W.m(M,j)):W&&(W.d(1),W=null),"kinds"===e[1]?Z?Z.p(e,t):(Z=kg(e),Z.c(),Z.m(M,G)):Z&&(Z.d(1),Z=null),"moderation"===e[1]?X?X.p(e,t):(X=xg(e),X.c(),X.m(M,K)):X&&(X.d(1),X=null),"relay"===e[1]?ee?ee.p(e,t):(ee=Rg(e),ee.c(),ee.m(M,null)):ee&&(ee.d(1),ee=null)},i:e,o:e,d(e){e&&d(n),q&&q.d(),z&&z.d(),Y&&Y.d(),W&&W.d(),Z&&Z.d(),X&&X.d(),ee&&ee.d(),J=!1,r(V)}}}function Ug(e,t,n){let{userSigner:r}=t,{userPubkey:i}=t,o="pubkeys",s=!1,a="",l="info",c=[],u="",d="",f=[],h="",p="",g=[],m="",y="",w="",v="",A=[],k="",I="",E=[],C="",x=[],B={relay_name:"",relay_description:"",relay_icon:""};async function S(){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,B={relay_name:t.name||"",relay_description:t.description||"",relay_icon:t.icon||""}),console.log("Updated relayConfig:",B),console.log("Loaded relay info:",t),n(3,a="Relay configuration loaded successfully"),n(4,l="success")}else console.error("Failed to fetch relay info, status:",e.status),n(3,a=`Failed to fetch relay info: ${e.status}`),n(4,l="error")}catch(e){console.error("Failed to fetch relay info:",e),n(3,a=`Failed to fetch relay info: ${e.message}`),n(4,l="error")}finally{n(2,s=!1)}}async function F(e,t=[]){try{n(2,s=!0),n(3,a="");const o={method:e,params:t},l=await async function(e,t){if(!r)throw new Error("No signer available for authentication. Please log in with a Nostr extension.");if(!i)throw new Error("No user pubkey available for authentication.");const n=window.location.origin+t,o={kind:27235,created_at:Math.floor(Date.now()/1e3),tags:[["u",n],["method",e]],content:"",pubkey:i},s=await r.signEvent(o),a=JSON.stringify(s);return`Nostr ${btoa(a)}`}("POST","/api/nip86"),c=await fetch("/api/nip86",{method:"POST",headers:{"Content-Type":"application/nostr+json+rpc",Authorization:l},body:JSON.stringify(o)});if(!c.ok)throw new Error(`HTTP ${c.status}: ${c.statusText}`);const u=await c.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,l="error"),e}finally{n(2,s=!1)}}async function Q(){try{n(5,c=await F("listbannedpubkeys"))}catch(e){console.error("Failed to load banned pubkeys:",e)}}async function D(){try{n(8,f=await F("listallowedpubkeys"))}catch(e){console.error("Failed to load allowed pubkeys:",e)}}async function P(){try{n(11,g=await F("listbannedevents"))}catch(e){console.error("Failed to load banned events:",e)}}async function T(){try{n(16,A=await F("listblockedips"))}catch(e){console.error("Failed to load blocked IPs:",e)}}async function U(){try{n(19,E=await F("listallowedkinds"))}catch(e){console.error("Failed to load allowed kinds:",e)}}async function $(){try{n(2,s=!0),n(21,x=await F("listeventsneedingmoderation")),console.log("Loaded events needing moderation:",x)}catch(e){console.error("Failed to load events needing moderation:",e),n(3,a=`Failed to load moderation events: ${e.message}`),n(4,l="error"),n(21,x=[])}finally{n(2,s=!1)}}async function N(e){try{await F("disallowkind",[e]),n(3,a="Kind disallowed successfully"),n(4,l="success"),await U()}catch(e){console.error("Failed to disallow kind:",e)}}async function L(e){try{await F("allowevent",[e,"Approved from moderation queue"]),n(3,a="Event allowed successfully"),n(4,l="success"),await $()}catch(e){console.error("Failed to allow event from moderation:",e)}}async function O(e){try{await F("banevent",[e,"Banned from moderation queue"]),n(3,a="Event banned successfully"),n(4,l="success"),await $()}catch(e){console.error("Failed to ban event from moderation:",e)}}R(()=>{setTimeout(()=>{S()},100)}),async function(){await Promise.all([Q(),D(),P(),T(),U()])}();return e.$$set=e=>{"userSigner"in e&&n(35,r=e.userSigner),"userPubkey"in e&&n(36,i=e.userPubkey)},e.$$.update=()=>{1&e.$$.dirty[0]&&console.log("relayConfig changed:",B)},[B,o,s,a,l,c,u,d,f,h,p,g,m,y,w,v,A,k,I,E,C,x,[],S,$,async function(){if(u)try{await F("banpubkey",[u,d]),n(3,a="Pubkey banned successfully"),n(4,l="success"),n(6,u=""),n(7,d=""),await Q()}catch(e){console.error("Failed to ban pubkey:",e)}},async function(){if(h)try{await F("allowpubkey",[h,p]),n(3,a="Pubkey allowed successfully"),n(4,l="success"),n(9,h=""),n(10,p=""),await D()}catch(e){console.error("Failed to allow pubkey:",e)}},async function(){if(m)try{await F("banevent",[m,y]),n(3,a="Event banned successfully"),n(4,l="success"),n(12,m=""),n(13,y=""),await P()}catch(e){console.error("Failed to ban event:",e)}},async function(){if(w)try{await F("allowevent",[w,v]),n(3,a="Event allowed successfully"),n(4,l="success"),n(14,w=""),n(15,v="")}catch(e){console.error("Failed to allow event:",e)}},async function(){if(k)try{await F("blockip",[k,I]),n(3,a="IP blocked successfully"),n(4,l="success"),n(17,k=""),n(18,I=""),await T()}catch(e){console.error("Failed to block IP:",e)}},async function(){if(!C)return;const e=parseInt(C);if(isNaN(e))return n(3,a="Invalid kind number"),void n(4,l="error");try{await F("allowkind",[e]),n(3,a="Kind allowed successfully"),n(4,l="success"),n(20,C=""),await U()}catch(e){console.error("Failed to allow kind:",e)}},N,async function(){try{n(2,s=!0),n(3,a="");const e=[];if(B.relay_name&&e.push(F("changerelayname",[B.relay_name])),B.relay_description&&e.push(F("changerelaydescription",[B.relay_description])),B.relay_icon&&e.push(F("changerelayicon",[B.relay_icon])),0===e.length)return n(3,a="No changes to update"),void n(4,l="info");await Promise.all(e),n(3,a="Relay configuration updated successfully"),n(4,l="success"),await S()}catch(e){console.error("Failed to update relay configuration:",e),n(3,a=`Failed to update relay configuration: ${e.message}`),n(4,l="error")}finally{n(2,s=!1)}},L,O,r,i,()=>n(1,o="pubkeys"),()=>n(1,o="events"),()=>n(1,o="ips"),()=>n(1,o="kinds"),()=>{n(1,o="moderation"),x&&0!==x.length||$()},()=>n(1,o="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(){m=this.value,n(12,m)},function(){y=this.value,n(13,y)},function(){w=this.value,n(14,w)},function(){v=this.value,n(15,v)},function(){k=this.value,n(17,k)},function(){I=this.value,n(18,I)},function(){C=b(this.value),n(20,C)},e=>N(e),e=>L(e.id),e=>O(e.id),function(){B.relay_name=this.value,n(0,B)},function(){B.relay_description=this.value,n(0,B)},function(){B.relay_icon=this.value,n(0,B)}]}class $g extends oe{constructor(e){super(),ie(this,e,Ug,Tg,o,{userSigner:35,userPubkey:36},null,[-1,-1,-1])}}function Ng(e){let t,n;return{c(){t=h("span"),n=g(e[3]),A(t,"class","permission-badge svelte-1qkhxam")},m(e,r){u(e,t,r),c(t,n)},p(e,t){8&t&&k(n,e[3])},d(e){e&&d(t)}}}function Lg(t){let n,r,i;return{c(){n=h("button"),n.textContent="Log in",A(n,"class","login-btn svelte-1qkhxam")},m(e,o){u(e,n,o),r||(i=w(n,"click",t[7]),r=!0)},p:e,d(e){e&&d(n),r=!1,i()}}}function Og(e){let t,n,r,i,o,s,a=(e[4]?.name||e[5])+"";function l(e,t){return e[4]?.picture?_g:Mg}let f=l(e),p=f(e);return{c(){t=h("button"),p.c(),n=m(),r=h("span"),i=g(a),A(r,"class","user-name svelte-1qkhxam"),A(t,"class","user-profile-btn svelte-1qkhxam")},m(a,l){u(a,t,l),p.m(t,null),c(t,n),c(t,r),c(r,i),o||(s=w(t,"click",e[6]),o=!0)},p(e,r){f===(f=l(e))&&p?p.p(e,r):(p.d(1),p=f(e),p&&(p.c(),p.m(t,n))),48&r&&a!==(a=(e[4]?.name||e[5])+"")&&k(i,a)},d(e){e&&d(t),p.d(),o=!1,s()}}}function Mg(t){let n;return{c(){n=h("div"),n.textContent="👤",A(n,"class","user-avatar-placeholder svelte-1qkhxam")},m(e,t){u(e,n,t)},p:e,d(e){e&&d(n)}}}function _g(e){let t,n;return{c(){t=h("img"),a(t.src,n=e[4].picture)||A(t,"src",n),A(t,"alt","User avatar"),A(t,"class","user-avatar svelte-1qkhxam")},m(e,n){u(e,t,n)},p(e,r){16&r&&!a(t.src,n=e[4].picture)&&A(t,"src",n)},d(e){e&&d(t)}}}function Hg(t){let n,r,i,o,s,l,f,p,y,w,v=t[1]&&t[2]&&Ng(t);function b(e,t){return e[1]?Og:Lg}let k=b(t),I=k(t);return{c(){n=h("header"),r=h("div"),i=h("img"),s=m(),l=h("div"),f=h("span"),p=g("ORLY? dashboard\n "),v&&v.c(),y=m(),w=h("div"),I.c(),a(i.src,o="/orly.png")||A(i,"src","/orly.png"),A(i,"alt","ORLY Logo"),A(i,"class","logo svelte-1qkhxam"),A(f,"class","app-title svelte-1qkhxam"),A(l,"class","header-title svelte-1qkhxam"),A(w,"class","header-buttons svelte-1qkhxam"),A(r,"class","header-content svelte-1qkhxam"),A(n,"class","main-header svelte-1qkhxam"),B(n,"dark-theme",t[0])},m(e,t){u(e,n,t),c(n,r),c(r,i),c(r,s),c(r,l),c(l,f),c(f,p),v&&v.m(f,null),c(r,y),c(r,w),I.m(w,null)},p(e,[t]){e[1]&&e[2]?v?v.p(e,t):(v=Ng(e),v.c(),v.m(f,null)):v&&(v.d(1),v=null),k===(k=b(e))&&I?I.p(e,t):(I.d(1),I=k(e),I&&(I.c(),I.m(w,null))),1&t&&B(n,"dark-theme",e[0])},i:e,o:e,d(e){e&&d(n),v&&v.d(),I.d()}}}function jg(e,t,n){let{isDarkTheme:r=!1}=t,{isLoggedIn:i=!1}=t,{userRole:o=""}=t,{currentEffectiveRole:s=""}=t,{userProfile:a=null}=t,{userPubkey:l=""}=t;const c=P();return e.$$set=e=>{"isDarkTheme"in e&&n(0,r=e.isDarkTheme),"isLoggedIn"in e&&n(1,i=e.isLoggedIn),"userRole"in e&&n(2,o=e.userRole),"currentEffectiveRole"in e&&n(3,s=e.currentEffectiveRole),"userProfile"in e&&n(4,a=e.userProfile),"userPubkey"in e&&n(5,l=e.userPubkey)},[r,i,o,s,a,l,function(){c("openSettingsDrawer")},function(){c("openLoginModal")}]}class Gg extends oe{constructor(e){super(),ie(this,e,jg,Hg,o,{isDarkTheme:0,isLoggedIn:1,userRole:2,currentEffectiveRole:3,userProfile:4,userPubkey:5})}}function Kg(e,t,n){const r=e.slice();return r[10]=t[n],r}function Jg(e){let t,n,i;function o(){return e[6](e[10])}function s(...t){return e[7](e[10],...t)}return{c(){t=h("span"),t.textContent="✕",A(t,"class","tab-close-icon svelte-wfmuj"),A(t,"role","button"),A(t,"tabindex","0")},m(e,r){u(e,t,r),n||(i=[w(t,"click",v(o)),w(t,"keydown",s)],n=!0)},p(t,n){e=t},d(e){e&&d(t),n=!1,r(i)}}}function Vg(e){let t,n,r,i,o,s,a,l,f,p,y=e[10].icon+"",v=e[10].label+"",b=e[10].isSearchTab&&Jg(e);function I(){return e[8](e[10])}return{c(){t=h("button"),n=h("span"),r=g(y),i=m(),o=h("span"),s=g(v),a=m(),b&&b.c(),l=m(),A(n,"class","tab-icon svelte-wfmuj"),A(o,"class","tab-label svelte-wfmuj"),A(t,"class","tab svelte-wfmuj"),B(t,"active",e[2]===e[10].id)},m(e,d){u(e,t,d),c(t,n),c(n,r),c(t,i),c(t,o),c(o,s),c(t,a),b&&b.m(t,null),c(t,l),f||(p=w(t,"click",I),f=!0)},p(n,i){e=n,2&i&&y!==(y=e[10].icon+"")&&k(r,y),2&i&&v!==(v=e[10].label+"")&&k(s,v),e[10].isSearchTab?b?b.p(e,i):(b=Jg(e),b.c(),b.m(t,l)):b&&(b.d(1),b=null),6&i&&B(t,"active",e[2]===e[10].id)},d(e){e&&d(t),b&&b.d(),f=!1,p()}}}function qg(e){let t,n,r,i,o,s,a,l;return{c(){t=h("a"),n=p("svg"),r=p("path"),i=p("path"),o=m(),s=h("span"),a=g("v"),l=g(e[3]),A(r,"d","M5 6h12v2h1.5c1.38 0 2.5 1.12 2.5 2.5v1c0 1.38-1.12 2.5-2.5 2.5H17v1c0 1.66-1.34 3-3 3H8c-1.66 0-3-1.34-3-3V6zm12 6h1.5c.28 0 .5-.22.5-.5v-1c0-.28-.22-.5-.5-.5H17v2z"),A(i,"d","M9 9c1.5 0 3 .5 3 2.5S10.5 14 9 14c0-1.5.5-3.5 2-4.5"),A(i,"stroke","currentColor"),A(i,"stroke-width","1"),A(i,"fill","none"),A(n,"class","version-icon svelte-wfmuj"),A(n,"viewBox","0 0 24 24"),A(n,"fill","currentColor"),A(n,"xmlns","http://www.w3.org/2000/svg"),A(s,"class","version-text svelte-wfmuj"),A(t,"href","https://next.orly.dev"),A(t,"target","_blank"),A(t,"rel","noopener noreferrer"),A(t,"class","version-link svelte-wfmuj")},m(e,d){u(e,t,d),c(t,n),c(n,r),c(n,i),c(t,o),c(t,s),c(s,a),c(s,l)},p(e,t){8&t&&k(l,e[3])},d(e){e&&d(t)}}}function zg(t){let n,r,i,o,s=t[1],a=[];for(let e=0;e<s.length;e+=1)a[e]=Vg(Kg(t,s,e));let l=t[3]&&qg(t);return{c(){n=h("aside"),r=h("div"),i=h("div");for(let e=0;e<a.length;e+=1)a[e].c();o=m(),l&&l.c(),A(i,"class","tabs svelte-wfmuj"),A(r,"class","sidebar-content svelte-wfmuj"),A(n,"class","sidebar svelte-wfmuj"),B(n,"dark-theme",t[0])},m(e,t){u(e,n,t),c(n,r),c(r,i);for(let e=0;e<a.length;e+=1)a[e]&&a[e].m(i,null);c(n,o),l&&l.m(n,null)},p(e,[t]){if(54&t){let n;for(s=e[1],n=0;n<s.length;n+=1){const r=Kg(e,s,n);a[n]?a[n].p(r,t):(a[n]=Vg(r),a[n].c(),a[n].m(i,null))}for(;n<a.length;n+=1)a[n].d(1);a.length=s.length}e[3]?l?l.p(e,t):(l=qg(e),l.c(),l.m(n,null)):l&&(l.d(1),l=null),1&t&&B(n,"dark-theme",e[0])},i:e,o:e,d(e){e&&d(n),f(a,e),l&&l.d()}}}function Yg(e,t,n){let{isDarkTheme:r=!1}=t,{tabs:i=[]}=t,{selectedTab:o=""}=t,{version:s=""}=t;const a=P();function l(e){a("selectTab",e)}function c(e){a("closeSearchTab",e)}return e.$$set=e=>{"isDarkTheme"in e&&n(0,r=e.isDarkTheme),"tabs"in e&&n(1,i=e.tabs),"selectedTab"in e&&n(2,o=e.selectedTab),"version"in e&&n(3,s=e.version)},[r,i,o,s,l,c,e=>c(e.id),(e,t)=>"Enter"===t.key&&c(e.id),e=>l(e.id)]}class Wg extends oe{constructor(e){super(),ie(this,e,Yg,zg,o,{isDarkTheme:0,tabs:1,selectedTab:2,version:3})}}function Zg(t){let n,r,i,o,s,a;return{c(){n=h("div"),r=h("p"),r.textContent="Please log in to access export functionality.",i=m(),o=h("button"),o.textContent="Log In",A(r,"class","svelte-jzrdtj"),A(o,"class","login-btn svelte-jzrdtj"),A(n,"class","login-prompt svelte-jzrdtj")},m(e,l){u(e,n,l),c(n,r),c(n,i),c(n,o),s||(a=w(o,"click",t[5]),s=!0)},p:e,d(e){e&&d(n),s=!1,a()}}}function Xg(e){let t,n,r=e[0]&&em(e),i=e[1]&&tm(e);return{c(){r&&r.c(),t=m(),i&&i.c(),n=y()},m(e,o){r&&r.m(e,o),u(e,t,o),i&&i.m(e,o),u(e,n,o)},p(e,o){e[0]?r?r.p(e,o):(r=em(e),r.c(),r.m(t.parentNode,t)):r&&(r.d(1),r=null),e[1]?i?i.p(e,o):(i=tm(e),i.c(),i.m(n.parentNode,n)):i&&(i.d(1),i=null)},d(e){r&&r.d(e),e&&d(t),i&&i.d(e),e&&d(n)}}}function em(t){let n,r,i,o,s,a,l,f;return{c(){n=h("div"),r=h("h3"),r.textContent="Export My Events",i=m(),o=h("p"),o.textContent="Download your personal events as a JSONL file.",s=m(),a=h("button"),a.textContent="📤 Export My Events",A(r,"class","svelte-jzrdtj"),A(o,"class","svelte-jzrdtj"),A(a,"class","export-btn svelte-jzrdtj"),A(n,"class","export-section svelte-jzrdtj")},m(e,d){u(e,n,d),c(n,r),c(n,i),c(n,o),c(n,s),c(n,a),l||(f=w(a,"click",t[3]),l=!0)},p:e,d(e){e&&d(n),l=!1,f()}}}function tm(t){let n,r,i,o,s,a,l,f;return{c(){n=h("div"),r=h("h3"),r.textContent="Export All Events",i=m(),o=h("p"),o.textContent="Download the complete database as a JSONL file. This includes\n all events from all users.",s=m(),a=h("button"),a.textContent="📤 Export All Events",A(r,"class","svelte-jzrdtj"),A(o,"class","svelte-jzrdtj"),A(a,"class","export-btn svelte-jzrdtj"),A(n,"class","export-section svelte-jzrdtj")},m(e,d){u(e,n,d),c(n,r),c(n,i),c(n,o),c(n,s),c(n,a),l||(f=w(a,"click",t[4]),l=!0)},p:e,d(e){e&&d(n),l=!1,f()}}}function nm(t){let n;function r(e,t){return e[2]?Xg:Zg}let i=r(t),o=i(t);return{c(){o.c(),n=y()},m(e,t){o.m(e,t),u(e,n,t)},p(e,[t]){i===(i=r(e))&&o?o.p(e,t):(o.d(1),o=i(e),o&&(o.c(),o.m(n.parentNode,n)))},i:e,o:e,d(e){o.d(e),e&&d(n)}}}function rm(e,t,n){let r,i,{isLoggedIn:o=!1}=t,{currentEffectiveRole:s=""}=t,{aclMode:a=""}=t;const l=P();return e.$$set=e=>{"isLoggedIn"in e&&n(0,o=e.isLoggedIn),"currentEffectiveRole"in e&&n(6,s=e.currentEffectiveRole),"aclMode"in e&&n(7,a=e.aclMode)},e.$$.update=()=>{129&e.$$.dirty&&n(2,r="none"===a||o),192&e.$$.dirty&&n(1,i="none"===a||"admin"===s||"owner"===s)},[o,i,r,function(){l("exportMyEvents")},function(){l("exportAllEvents")},function(){l("openLoginModal")},s,a]}class im extends oe{constructor(e){super(),ie(this,e,rm,nm,o,{isLoggedIn:0,currentEffectiveRole:6,aclMode:7})}}function om(t){let n,r,i,o,s,a,l,f;return{c(){n=h("div"),r=h("h3"),r.textContent="Import Events",i=m(),o=h("p"),o.textContent="Please log in to access import functionality.",s=m(),a=h("button"),a.textContent="Log In",A(r,"class","recovery-header svelte-nonyqh"),A(o,"class","recovery-description svelte-nonyqh"),A(a,"class","login-btn svelte-nonyqh"),A(n,"class","login-prompt svelte-nonyqh")},m(e,d){u(e,n,d),c(n,r),c(n,i),c(n,o),c(n,s),c(n,a),l||(f=w(a,"click",t[6]),l=!0)},p:e,d(e){e&&d(n),l=!1,f()}}}function sm(t){let n;return{c(){n=h("div"),n.innerHTML='<h3 class="recovery-header svelte-nonyqh">Import Events</h3> \n <p class="recovery-description svelte-nonyqh">Admin or owner permission required for import functionality.</p>',A(n,"class","permission-denied svelte-nonyqh")},m(e,t){u(e,n,t)},p:e,d(e){e&&d(n)}}}function am(e){let t,n,i,o,s,a,l,f,p,y,v,b,k,I,E=e[2]&&lm(e);return{c(){t=h("h3"),t.textContent="Import Events",n=m(),i=h("p"),i.textContent="Upload a JSONL file to import events into the database.",o=m(),s=h("div"),a=h("input"),l=m(),f=h("div"),p=h("button"),y=g("Import Events"),b=m(),E&&E.c(),A(t,"class","svelte-nonyqh"),A(i,"class","svelte-nonyqh"),A(a,"type","file"),A(a,"id","import-file"),A(a,"accept",".jsonl,.txt"),A(a,"class","svelte-nonyqh"),A(p,"class","import-btn svelte-nonyqh"),p.disabled=v=!e[1]||"Uploading..."===e[2],A(f,"class","import-row svelte-nonyqh"),A(s,"class","recovery-controls-card svelte-nonyqh")},m(r,d){u(r,t,d),u(r,n,d),u(r,i,d),u(r,o,d),u(r,s,d),c(s,a),c(s,l),c(s,f),c(f,p),c(p,y),c(f,b),E&&E.m(f,null),k||(I=[w(a,"change",e[4]),w(p,"click",e[5])],k=!0)},p(e,t){6&t&&v!==(v=!e[1]||"Uploading..."===e[2])&&(p.disabled=v),e[2]?E?E.p(e,t):(E=lm(e),E.c(),E.m(f,null)):E&&(E.d(1),E=null)},d(e){e&&d(t),e&&d(n),e&&d(i),e&&d(o),e&&d(s),E&&E.d(),k=!1,r(I)}}}function lm(e){let t,n;return{c(){t=h("span"),n=g(e[2]),A(t,"class","import-message svelte-nonyqh"),B(t,"uploading","Uploading..."===e[2]),B(t,"success","Upload complete"===e[2]),B(t,"error",e[2].startsWith("Import failed")||e[2].startsWith("Admin")||e[2].startsWith("Please"))},m(e,r){u(e,t,r),c(t,n)},p(e,r){4&r&&k(n,e[2]),4&r&&B(t,"uploading","Uploading..."===e[2]),4&r&&B(t,"success","Upload complete"===e[2]),4&r&&B(t,"error",e[2].startsWith("Import failed")||e[2].startsWith("Admin")||e[2].startsWith("Please"))},d(e){e&&d(t)}}}function cm(t){let n;function r(e,t){return e[3]?am:e[0]?sm:om}let i=r(t),o=i(t);return{c(){n=h("div"),o.c(),A(n,"class","import-section svelte-nonyqh")},m(e,t){u(e,n,t),o.m(n,null)},p(e,[t]){i===(i=r(e))&&o?o.p(e,t):(o.d(1),o=i(e),o&&(o.c(),o.m(n,null)))},i:e,o:e,d(e){e&&d(n),o.d()}}}function um(e,t,n){let r,{isLoggedIn:i=!1}=t,{currentEffectiveRole:o=""}=t,{selectedFile:s=null}=t,{aclMode:a=""}=t,{importMessage:l=""}=t;const c=P();return e.$$set=e=>{"isLoggedIn"in e&&n(0,i=e.isLoggedIn),"currentEffectiveRole"in e&&n(7,o=e.currentEffectiveRole),"selectedFile"in e&&n(1,s=e.selectedFile),"aclMode"in e&&n(8,a=e.aclMode),"importMessage"in e&&n(2,l=e.importMessage)},e.$$.update=()=>{385&e.$$.dirty&&n(3,r="none"===a||i&&("admin"===o||"owner"===o))},[i,s,l,r,function(e){c("fileSelect",e)},function(){c("importEvents")},function(){c("openLoginModal")},o,a]}class dm extends oe{constructor(e){super(),ie(this,e,um,cm,o,{isLoggedIn:0,currentEffectiveRole:7,selectedFile:1,aclMode:8,importMessage:2})}}const fm={0:"Profile Metadata",1:"Text Note",2:"Recommend Relay",3:"Contacts",4:"Encrypted DM",5:"Delete Request",6:"Repost",7:"Reaction",8:"Badge Award",16:"Generic Repost",40:"Channel Creation",41:"Channel Metadata",42:"Channel Message",43:"Channel Hide Message",44:"Channel Mute User",1063:"File Metadata",1311:"Live Chat Message",1984:"Reporting",1985:"Label",9734:"Zap Request",9735:"Zap Receipt",1e4:"Mute List",10001:"Pin List",10002:"Relay List Metadata",10003:"Bookmark List",10004:"Communities List",10005:"Public Chats List",10006:"Blocked Relays List",10007:"Search Relays List",10009:"User Groups",10015:"Interests List",10030:"User Emoji List",13194:"Wallet Info",22242:"Client Auth",23194:"Wallet Request",23195:"Wallet Response",24133:"Nostr Connect",27235:"HTTP Auth",3e4:"Categorized People List",30001:"Categorized Bookmarks",30002:"Categorized Relay List",30003:"Bookmark Sets",30004:"Curation Sets",30005:"Video Sets",30008:"Profile Badges",30009:"Badge Definition",30015:"Interest Sets",30017:"Create/Update Stall",30018:"Create/Update Product",30019:"Marketplace UI/UX",30020:"Product Sold As Auction",30023:"Long-form Content",30024:"Draft Long-form Content",30030:"Emoji Sets",30063:"Release Artifact Sets",30078:"Application-specific Data",30311:"Live Event",30315:"User Statuses",30388:"Slide Set",30402:"Classified Listing",30403:"Draft Classified Listing",30617:"Repository Announcement",30618:"Repository State Announcement",30818:"Wiki Article",30819:"Redirects",31922:"Date-Based Calendar Event",31923:"Time-Based Calendar Event",31924:"Calendar",31925:"Calendar Event RSVP",31989:"Handler Recommendation",31990:"Handler Information",34550:"Community Definition",34551:"Community Post Approval"};function hm(e,t=null){if(!e||"string"!=typeof e)return!1;return!!/^[0-9a-fA-F]+$/.test(e)&&(!t||e.length===t)}function pm(e){const t=new Date(1e3*e);return`${t.getFullYear()}-${String(t.getMonth()+1).padStart(2,"0")}-${String(t.getDate()).padStart(2,"0")}T${String(t.getHours()).padStart(2,"0")}:${String(t.getMinutes()).padStart(2,"0")}`}function gm(e){return Math.floor(new Date(e).getTime()/1e3)}function mm(e,t,n){const r=e.slice();return r[62]=t[n],r[64]=n,r}function ym(e,t,n){const r=e.slice();return r[65]=t[n],r}function wm(e,t,n){const r=e.slice();return r[68]=t[n],r}function vm(e,t,n){const r=e.slice();return r[71]=t[n],r}function Am(e,t,n){const r=e.slice();return r[71]=t[n].kind,r[74]=t[n].name,r}function bm(e){let t,n,r,i,o,s,a=e[20],l=[];for(let t=0;t<a.length;t+=1)l[t]=km(Am(e,a,t));return{c(){t=h("div"),n=h("input"),r=m(),i=h("div");for(let e=0;e<l.length;e+=1)l[e].c();A(n,"type","text"),A(n,"placeholder","Search kinds..."),A(n,"class","filter-input kind-search svelte-1a1v6k0"),A(i,"class","kinds-list svelte-1a1v6k0"),A(t,"class","kinds-picker svelte-1a1v6k0")},m(a,d){u(a,t,d),c(t,n),I(n,e[9]),c(t,r),c(t,i);for(let e=0;e<l.length;e+=1)l[e]&&l[e].m(i,null);o||(s=w(n,"input",e[40]),o=!0)},p(e,t){if(512&t[0]&&n.value!==e[9]&&I(n,e[9]),9437186&t[0]){let n;for(a=e[20],n=0;n<a.length;n+=1){const r=Am(e,a,n);l[n]?l[n].p(r,t):(l[n]=km(r),l[n].c(),l[n].m(i,null))}for(;n<l.length;n+=1)l[n].d(1);l.length=a.length}},d(e){e&&d(t),f(l,e),o=!1,s()}}}function km(e){let t,n,r,i,o,s,a,l,f,p,y,v,b=e[71]+"",I=e[74]+"";function E(){return e[41](e[71])}return{c(){t=h("label"),n=h("input"),i=m(),o=h("span"),s=g(b),a=m(),l=h("span"),f=g(I),p=m(),A(n,"type","checkbox"),n.checked=r=e[1].includes(e[71]),A(n,"class","svelte-1a1v6k0"),A(o,"class","kind-number svelte-1a1v6k0"),A(l,"class","kind-name svelte-1a1v6k0"),A(t,"class","kind-checkbox svelte-1a1v6k0")},m(e,r){u(e,t,r),c(t,n),c(t,i),c(t,o),c(o,s),c(t,a),c(t,l),c(l,f),c(t,p),y||(v=w(n,"change",E),y=!0)},p(t,i){e=t,1048578&i[0]&&r!==(r=e[1].includes(e[71]))&&(n.checked=r),1048576&i[0]&&b!==(b=e[71]+"")&&k(s,b),1048576&i[0]&&I!==(I=e[74]+"")&&k(f,I)},d(e){e&&d(t),y=!1,v()}}}function Im(e){let t,n=e[1],r=[];for(let t=0;t<n.length;t+=1)r[t]=Em(vm(e,n,t));return{c(){t=h("div");for(let e=0;e<r.length;e+=1)r[e].c();A(t,"class","chips-container svelte-1a1v6k0")},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,i){if(16777218&i[0]){let o;for(n=e[1],o=0;o<n.length;o+=1){const s=vm(e,n,o);r[o]?r[o].p(s,i):(r[o]=Em(s),r[o].c(),r[o].m(t,null))}for(;o<r.length;o+=1)r[o].d(1);r.length=n.length}},d(e){e&&d(t),f(r,e)}}}function Em(e){let t,n,r,i,o,s,a,l,f,p,y=e[71]+"",v=(fm[e[71]]||`Kind ${e[71]}`)+"";function b(){return e[42](e[71])}return{c(){t=h("div"),n=h("span"),r=g(y),i=g(": "),o=g(v),s=m(),a=h("button"),a.textContent="×",l=m(),A(n,"class","chip-text svelte-1a1v6k0"),A(a,"class","chip-remove svelte-1a1v6k0"),A(t,"class","chip svelte-1a1v6k0")},m(e,d){u(e,t,d),c(t,n),c(n,r),c(n,i),c(n,o),c(t,s),c(t,a),c(t,l),f||(p=w(a,"click",b),f=!0)},p(t,n){e=t,2&n[0]&&y!==(y=e[71]+"")&&k(r,y),2&n[0]&&v!==(v=(fm[e[71]]||`Kind ${e[71]}`)+"")&&k(o,v)},d(e){e&&d(t),f=!1,p()}}}function Cm(e){let t,n;return{c(){t=h("div"),n=g(e[17]),A(t,"class","error-message svelte-1a1v6k0")},m(e,r){u(e,t,r),c(t,n)},p(e,t){131072&t[0]&&k(n,e[17])},d(e){e&&d(t)}}}function xm(e){let t,n=e[2],r=[];for(let t=0;t<n.length;t+=1)r[t]=Bm(wm(e,n,t));return{c(){t=h("div");for(let e=0;e<r.length;e+=1)r[e].c();A(t,"class","list-items svelte-1a1v6k0")},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,i){if(67108868&i[0]){let o;for(n=e[2],o=0;o<n.length;o+=1){const s=wm(e,n,o);r[o]?r[o].p(s,i):(r[o]=Bm(s),r[o].c(),r[o].m(t,null))}for(;o<r.length;o+=1)r[o].d(1);r.length=n.length}},d(e){e&&d(t),f(r,e)}}}function Bm(e){let t,n,r,i,o,s,a,l,f=e[68]+"";function p(){return e[45](e[68])}return{c(){t=h("div"),n=h("span"),r=g(f),i=m(),o=h("button"),o.textContent="×",s=m(),A(n,"class","list-item-text svelte-1a1v6k0"),A(o,"class","list-item-remove svelte-1a1v6k0"),A(t,"class","list-item svelte-1a1v6k0")},m(e,d){u(e,t,d),c(t,n),c(n,r),c(t,i),c(t,o),c(t,s),a||(l=w(o,"click",p),a=!0)},p(t,n){e=t,4&n[0]&&f!==(f=e[68]+"")&&k(r,f)},d(e){e&&d(t),a=!1,l()}}}function Sm(e){let t,n;return{c(){t=h("div"),n=g(e[18]),A(t,"class","error-message svelte-1a1v6k0")},m(e,r){u(e,t,r),c(t,n)},p(e,t){262144&t[0]&&k(n,e[18])},d(e){e&&d(t)}}}function Fm(e){let t,n=e[3],r=[];for(let t=0;t<n.length;t+=1)r[t]=Qm(ym(e,n,t));return{c(){t=h("div");for(let e=0;e<r.length;e+=1)r[e].c();A(t,"class","list-items svelte-1a1v6k0")},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,i){if(268435464&i[0]){let o;for(n=e[3],o=0;o<n.length;o+=1){const s=ym(e,n,o);r[o]?r[o].p(s,i):(r[o]=Qm(s),r[o].c(),r[o].m(t,null))}for(;o<r.length;o+=1)r[o].d(1);r.length=n.length}},d(e){e&&d(t),f(r,e)}}}function Qm(e){let t,n,r,i,o,s,a,l,f=e[65]+"";function p(){return e[48](e[65])}return{c(){t=h("div"),n=h("span"),r=g(f),i=m(),o=h("button"),o.textContent="×",s=m(),A(n,"class","list-item-text svelte-1a1v6k0"),A(o,"class","list-item-remove svelte-1a1v6k0"),A(t,"class","list-item svelte-1a1v6k0")},m(e,d){u(e,t,d),c(t,n),c(n,r),c(t,i),c(t,o),c(t,s),a||(l=w(o,"click",p),a=!0)},p(t,n){e=t,8&n[0]&&f!==(f=e[65]+"")&&k(r,f)},d(e){e&&d(t),a=!1,l()}}}function Rm(e){let t,n;return{c(){t=h("div"),n=g(e[19]),A(t,"class","error-message svelte-1a1v6k0")},m(e,r){u(e,t,r),c(t,n)},p(e,t){524288&t[0]&&k(n,e[19])},d(e){e&&d(t)}}}function Dm(e){let t,n=e[4],r=[];for(let t=0;t<n.length;t+=1)r[t]=Pm(mm(e,n,t));return{c(){t=h("div");for(let e=0;e<r.length;e+=1)r[e].c();A(t,"class","list-items svelte-1a1v6k0")},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,i){if(1073741840&i[0]){let o;for(n=e[4],o=0;o<n.length;o+=1){const s=mm(e,n,o);r[o]?r[o].p(s,i):(r[o]=Pm(s),r[o].c(),r[o].m(t,null))}for(;o<r.length;o+=1)r[o].d(1);r.length=n.length}},d(e){e&&d(t),f(r,e)}}}function Pm(e){let t,n,r,i,o,s,a,l,f,p,y,v=e[62].name+"",b=e[62].value+"";function I(){return e[52](e[64])}return{c(){t=h("div"),n=h("span"),r=g("#"),i=g(v),o=g(": "),s=g(b),a=m(),l=h("button"),l.textContent="×",f=m(),A(n,"class","list-item-text svelte-1a1v6k0"),A(l,"class","list-item-remove svelte-1a1v6k0"),A(t,"class","list-item svelte-1a1v6k0")},m(e,d){u(e,t,d),c(t,n),c(n,r),c(n,i),c(n,o),c(n,s),c(t,a),c(t,l),c(t,f),p||(y=w(l,"click",I),p=!0)},p(t,n){e=t,16&n[0]&&v!==(v=e[62].name+"")&&k(i,v),16&n[0]&&b!==(b=e[62].value+"")&&k(s,b)},d(e){e&&d(t),p=!1,y()}}}function Tm(t){let n,r,i;return{c(){n=h("button"),n.textContent="×",A(n,"class","clear-timestamp-btn svelte-1a1v6k0")},m(e,o){u(e,n,o),r||(i=w(n,"click",t[53]),r=!0)},p:e,d(e){e&&d(n),r=!1,i()}}}function Um(t){let n,r,i;return{c(){n=h("button"),n.textContent="×",A(n,"class","clear-timestamp-btn svelte-1a1v6k0")},m(e,o){u(e,n,o),r||(i=w(n,"click",t[54]),r=!0)},p:e,d(e){e&&d(n),r=!1,i()}}}function $m(e){let t,n,i,o,s,a,l,f,p,g=e[11]&&Nm(e);return{c(){t=h("div"),n=h("label"),n.textContent="Filter JSON",i=m(),o=h("textarea"),s=m(),g&&g.c(),a=m(),l=h("button"),l.textContent="Apply JSON",A(n,"for","json-editor"),A(n,"class","svelte-1a1v6k0"),A(o,"id","json-editor"),A(o,"class","json-editor svelte-1a1v6k0"),A(o,"placeholder",'{"kinds": [1], "limit": 100}'),A(o,"rows","8"),A(l,"class","apply-json-btn svelte-1a1v6k0"),A(t,"class","json-editor-section svelte-1a1v6k0")},m(r,d){u(r,t,d),c(t,n),c(t,i),c(t,o),I(o,e[10]),c(t,s),g&&g.m(t,null),c(t,a),c(t,l),f||(p=[w(o,"input",e[56]),w(l,"click",e[22])],f=!0)},p(e,n){1024&n[0]&&I(o,e[10]),e[11]?g?g.p(e,n):(g=Nm(e),g.c(),g.m(t,a)):g&&(g.d(1),g=null)},d(e){e&&d(t),g&&g.d(),f=!1,r(p)}}}function Nm(e){let t,n;return{c(){t=h("div"),n=g(e[11]),A(t,"class","json-error svelte-1a1v6k0")},m(e,r){u(e,t,r),c(t,n)},p(e,t){2048&t[0]&&k(n,e[11])},d(e){e&&d(t)}}}function Lm(t){let n,i,o,s,a,l,f,p,y,v,E,C,x,S,F,Q,R,D,P,T,U,$,N,L,O,M,_,H,j,G,K,J,V,q,z,Y,W,Z,X,ee,te,ne,re,ie,oe,se,ae,le,ce,ue,de,fe,he,pe,ge,me,ye,we,ve,Ae,be,ke,Ie,Ee,Ce,xe,Be,Se,Fe,Qe,Re,De,Pe,Te,Ue,$e,Ne,Le,Oe,Me=t[12]?"▼":"▶",_e=t[1].length+"",He=t[12]&&bm(t),je=t[1].length>0&&Im(t),Ge=t[17]&&Cm(t),Ke=t[2].length>0&&xm(t),Je=t[18]&&Sm(t),Ve=t[3].length>0&&Fm(t),qe=t[19]&&Rm(t),ze=t[4].length>0&&Dm(t),Ye=t[5]&&Tm(t),We=t[6]&&Um(t),Ze=t[8]&&$m(t);return{c(){n=h("div"),i=h("div"),o=h("div"),s=h("label"),s.textContent="Search Text (NIP-50)",a=m(),l=h("div"),f=h("input"),p=m(),y=h("label"),y.textContent="Event Kinds",v=m(),E=h("div"),C=h("button"),x=g(Me),S=g(" Select Kinds ("),F=g(_e),Q=g(" selected)"),R=m(),He&&He.c(),D=m(),je&&je.c(),P=m(),T=h("label"),T.textContent="Authors (Pubkeys)",U=m(),$=h("div"),N=h("div"),L=h("input"),O=m(),M=h("button"),M.textContent="Add",_=m(),Ge&&Ge.c(),H=m(),Ke&&Ke.c(),j=m(),G=h("label"),G.textContent="Event IDs",K=m(),J=h("div"),V=h("div"),q=h("input"),z=m(),Y=h("button"),Y.textContent="Add",W=m(),Je&&Je.c(),Z=m(),Ve&&Ve.c(),X=m(),ee=h("label"),ee.textContent="Tags (#e, #p, #a)",te=m(),ne=h("div"),re=h("div"),ie=h("span"),ie.textContent="#",oe=m(),se=h("input"),ae=m(),le=h("input"),ce=m(),ue=h("button"),ue.textContent="Add",de=m(),qe&&qe.c(),fe=m(),ze&&ze.c(),he=m(),pe=h("label"),pe.textContent="Since",ge=m(),me=h("div"),ye=h("input"),we=m(),Ye&&Ye.c(),ve=m(),Ae=h("label"),Ae.textContent="Until",be=m(),ke=h("div"),Ie=h("input"),Ee=m(),We&&We.c(),Ce=m(),xe=h("label"),xe.textContent="Limit",Be=m(),Se=h("div"),Fe=h("input"),Qe=m(),Ze&&Ze.c(),Re=m(),De=h("div"),Pe=h("button"),Pe.textContent="🧹",Te=m(),Ue=h("div"),$e=m(),Ne=h("button"),Ne.textContent="</>",A(s,"for","search-text"),A(s,"class","svelte-1a1v6k0"),A(f,"id","search-text"),A(f,"type","text"),A(f,"placeholder","Search events..."),A(f,"class","filter-input svelte-1a1v6k0"),A(l,"class","field-content svelte-1a1v6k0"),A(y,"class","svelte-1a1v6k0"),A(C,"class","picker-toggle-btn svelte-1a1v6k0"),A(E,"class","field-content svelte-1a1v6k0"),A(T,"class","svelte-1a1v6k0"),A(L,"type","text"),A(L,"placeholder","64 character hex pubkey..."),A(L,"class","filter-input svelte-1a1v6k0"),A(L,"maxlength","64"),A(M,"class","add-btn svelte-1a1v6k0"),A(N,"class","input-group svelte-1a1v6k0"),A($,"class","field-content svelte-1a1v6k0"),A(G,"class","svelte-1a1v6k0"),A(q,"type","text"),A(q,"placeholder","64 character hex event ID..."),A(q,"class","filter-input svelte-1a1v6k0"),A(q,"maxlength","64"),A(Y,"class","add-btn svelte-1a1v6k0"),A(V,"class","input-group svelte-1a1v6k0"),A(J,"class","field-content svelte-1a1v6k0"),A(ee,"class","svelte-1a1v6k0"),A(ie,"class","hash-prefix svelte-1a1v6k0"),A(se,"type","text"),A(se,"placeholder","Tag"),A(se,"class","filter-input tag-name-input svelte-1a1v6k0"),A(se,"maxlength","1"),A(le,"type","text"),A(le,"placeholder","Value..."),A(le,"class","filter-input tag-value-input svelte-1a1v6k0"),A(ue,"class","add-btn svelte-1a1v6k0"),A(re,"class","tag-input-group svelte-1a1v6k0"),A(ne,"class","field-content svelte-1a1v6k0"),A(pe,"for","since-timestamp"),A(pe,"class","svelte-1a1v6k0"),A(ye,"id","since-timestamp"),A(ye,"type","datetime-local"),ye.value=t[32](),A(ye,"class","filter-input svelte-1a1v6k0"),A(me,"class","field-content timestamp-field svelte-1a1v6k0"),A(Ae,"for","until-timestamp"),A(Ae,"class","svelte-1a1v6k0"),A(Ie,"id","until-timestamp"),A(Ie,"type","datetime-local"),Ie.value=t[33](),A(Ie,"class","filter-input svelte-1a1v6k0"),A(ke,"class","field-content timestamp-field svelte-1a1v6k0"),A(xe,"for","limit"),A(xe,"class","svelte-1a1v6k0"),A(Fe,"id","limit"),A(Fe,"type","number"),A(Fe,"placeholder","Max events to return"),A(Fe,"class","filter-input svelte-1a1v6k0"),A(Fe,"min","1"),A(Se,"class","field-content svelte-1a1v6k0"),A(o,"class","filter-grid svelte-1a1v6k0"),A(i,"class","filter-content svelte-1a1v6k0"),A(Pe,"class","clear-all-btn svelte-1a1v6k0"),A(Pe,"title","Clear all filters"),A(Ue,"class","spacer svelte-1a1v6k0"),A(Ne,"class","json-toggle-btn svelte-1a1v6k0"),A(Ne,"title","Edit filter JSON"),B(Ne,"active",t[8]),A(De,"class","clear-column svelte-1a1v6k0"),A(n,"class","filter-builder svelte-1a1v6k0")},m(e,r){u(e,n,r),c(n,i),c(i,o),c(o,s),c(o,a),c(o,l),c(l,f),I(f,t[0]),c(o,p),c(o,y),c(o,v),c(o,E),c(E,C),c(C,x),c(C,S),c(C,F),c(C,Q),c(E,R),He&&He.m(E,null),c(E,D),je&&je.m(E,null),c(o,P),c(o,T),c(o,U),c(o,$),c($,N),c(N,L),I(L,t[13]),c(N,O),c(N,M),c($,_),Ge&&Ge.m($,null),c($,H),Ke&&Ke.m($,null),c(o,j),c(o,G),c(o,K),c(o,J),c(J,V),c(V,q),I(q,t[14]),c(V,z),c(V,Y),c(J,W),Je&&Je.m(J,null),c(J,Z),Ve&&Ve.m(J,null),c(o,X),c(o,ee),c(o,te),c(o,ne),c(ne,re),c(re,ie),c(re,oe),c(re,se),I(se,t[15]),c(re,ae),c(re,le),I(le,t[16]),c(re,ce),c(re,ue),c(ne,de),qe&&qe.m(ne,null),c(ne,fe),ze&&ze.m(ne,null),c(o,he),c(o,pe),c(o,ge),c(o,me),c(me,ye),c(me,we),Ye&&Ye.m(me,null),c(o,ve),c(o,Ae),c(o,be),c(o,ke),c(ke,Ie),c(ke,Ee),We&&We.m(ke,null),c(o,Ce),c(o,xe),c(o,Be),c(o,Se),c(Se,Fe),I(Fe,t[7]),c(o,Qe),Ze&&Ze.m(o,null),c(n,Re),c(n,De),c(De,Pe),c(De,Te),c(De,Ue),c(De,$e),c(De,Ne),Le||(Oe=[w(f,"input",t[38]),w(C,"click",t[39]),w(L,"input",t[43]),w(L,"keydown",t[44]),w(M,"click",t[25]),w(q,"input",t[46]),w(q,"keydown",t[47]),w(Y,"click",t[27]),w(se,"input",t[49]),w(le,"input",t[50]),w(le,"keydown",t[51]),w(ue,"click",t[29]),w(ye,"change",t[34]),w(Ie,"change",t[35]),w(Fe,"input",t[55]),w(Pe,"click",t[31]),w(Ne,"click",t[57])],Le=!0)},p(e,t){1&t[0]&&f.value!==e[0]&&I(f,e[0]),4096&t[0]&&Me!==(Me=e[12]?"▼":"▶")&&k(x,Me),2&t[0]&&_e!==(_e=e[1].length+"")&&k(F,_e),e[12]?He?He.p(e,t):(He=bm(e),He.c(),He.m(E,D)):He&&(He.d(1),He=null),e[1].length>0?je?je.p(e,t):(je=Im(e),je.c(),je.m(E,null)):je&&(je.d(1),je=null),8192&t[0]&&L.value!==e[13]&&I(L,e[13]),e[17]?Ge?Ge.p(e,t):(Ge=Cm(e),Ge.c(),Ge.m($,H)):Ge&&(Ge.d(1),Ge=null),e[2].length>0?Ke?Ke.p(e,t):(Ke=xm(e),Ke.c(),Ke.m($,null)):Ke&&(Ke.d(1),Ke=null),16384&t[0]&&q.value!==e[14]&&I(q,e[14]),e[18]?Je?Je.p(e,t):(Je=Sm(e),Je.c(),Je.m(J,Z)):Je&&(Je.d(1),Je=null),e[3].length>0?Ve?Ve.p(e,t):(Ve=Fm(e),Ve.c(),Ve.m(J,null)):Ve&&(Ve.d(1),Ve=null),32768&t[0]&&se.value!==e[15]&&I(se,e[15]),65536&t[0]&&le.value!==e[16]&&I(le,e[16]),e[19]?qe?qe.p(e,t):(qe=Rm(e),qe.c(),qe.m(ne,fe)):qe&&(qe.d(1),qe=null),e[4].length>0?ze?ze.p(e,t):(ze=Dm(e),ze.c(),ze.m(ne,null)):ze&&(ze.d(1),ze=null),e[5]?Ye?Ye.p(e,t):(Ye=Tm(e),Ye.c(),Ye.m(me,null)):Ye&&(Ye.d(1),Ye=null),e[6]?We?We.p(e,t):(We=Um(e),We.c(),We.m(ke,null)):We&&(We.d(1),We=null),128&t[0]&&b(Fe.value)!==e[7]&&I(Fe,e[7]),e[8]?Ze?Ze.p(e,t):(Ze=$m(e),Ze.c(),Ze.m(o,null)):Ze&&(Ze.d(1),Ze=null),256&t[0]&&B(Ne,"active",e[8])},i:e,o:e,d(e){e&&d(n),He&&He.d(),je&&je.d(),Ge&&Ge.d(),Ke&&Ke.d(),Je&&Je.d(),Ve&&Ve.d(),qe&&qe.d(),ze&&ze.d(),Ye&&Ye.d(),We&&We.d(),Ze&&Ze.d(),Le=!1,r(Oe)}}}function Om(e,t,n){let r,i;const o=P();let{searchText:s=""}=t,{selectedKinds:a=[]}=t,{pubkeys:l=[]}=t,{eventIds:c=[]}=t,{tags:u=[]}=t,{sinceTimestamp:d=null}=t,{untilTimestamp:f=null}=t,{limit:h=null}=t,{showJsonEditor:p=!1}=t,g="",m="",y=!1,w="",v="",A="",k="",I="",E="",C="",x="",B=null,S=!1;function F(e){a.includes(e)?n(1,a=a.filter(t=>t!==e)):n(1,a=[...a,e].sort((e,t)=>e-t))}function Q(e){n(1,a=a.filter(t=>t!==e))}function R(){const e=v.trim();e&&(hm(e,64)?l.includes(e)?n(17,E="Pubkey already added"):(n(2,l=[...l,e]),n(13,v=""),n(17,E="")):n(17,E="Invalid pubkey: must be 64 character hex string"))}function T(e){n(2,l=l.filter(t=>t!==e))}function U(){const e=A.trim();e&&(hm(e,64)?c.includes(e)?n(18,C="Event ID already added"):(n(3,c=[...c,e]),n(14,A=""),n(18,C="")):n(18,C="Invalid event ID: must be 64 character hex string"))}function $(e){n(3,c=c.filter(t=>t!==e))}function N(){const e=k.trim(),t=I.trim();e&&t&&(/^[a-zA-Z]$/.test(e)?u.some(n=>n.name===e&&n.value===t)?n(19,x="Tag already added"):(n(4,u=[...u,{name:e,value:t}]),n(15,k=""),n(16,I=""),n(19,x="")):n(19,x="Invalid tag name: must be single letter a-z or A-Z"))}function L(e){n(4,u=u.filter((t,n)=>n!==e))}function O(){o("apply",{searchText:s,selectedKinds:a,pubkeys:l,eventIds:c,tags:u,sinceTimestamp:d,untilTimestamp:f,limit:h})}D(()=>{B&&clearTimeout(B)});return e.$$set=e=>{"searchText"in e&&n(0,s=e.searchText),"selectedKinds"in e&&n(1,a=e.selectedKinds),"pubkeys"in e&&n(2,l=e.pubkeys),"eventIds"in e&&n(3,c=e.eventIds),"tags"in e&&n(4,u=e.tags),"sinceTimestamp"in e&&n(5,d=e.sinceTimestamp),"untilTimestamp"in e&&n(6,f=e.untilTimestamp),"limit"in e&&n(7,h=e.limit),"showJsonEditor"in e&&n(8,p=e.showJsonEditor)},e.$$.update=()=>{if(256&e.$$.dirty[0]&&p){const e=function(){const e={};return a.length>0&&(e.kinds=a),l.length>0&&(e.authors=l),c.length>0&&(e.ids=c),d&&(e.since=d),f&&(e.until=f),h&&(e.limit=h),s&&(e.search=s),u.forEach(t=>{const n=`#${t.name}`;e[n]||(e[n]=[]),e[n].push(t.value)}),e}();n(10,g=JSON.stringify(e,null,2))}255&e.$$.dirty[0]|32&e.$$.dirty[1]&&(S?(B&&clearTimeout(B),B=setTimeout(()=>{O()},1e3)):n(36,S=!0)),512&e.$$.dirty[0]|64&e.$$.dirty[1]&&n(20,i=r.filter(e=>e.kind.toString().includes(w)||e.name.toLowerCase().includes(w.toLowerCase())))},n(37,r=Object.entries(fm).map(([e,t])=>({kind:parseInt(e),name:t})).sort((e,t)=>e.kind-t.kind)),[s,a,l,c,u,d,f,h,p,w,g,m,y,v,A,k,I,E,C,x,i,o,function(){try{const e=JSON.parse(g);n(11,m=""),n(1,a=e.kinds||[]),n(2,l=e.authors||[]),n(3,c=e.ids||[]),n(5,d=e.since||null),n(6,f=e.until||null),n(7,h=e.limit||null),n(0,s=e.search||""),n(4,u=[]),Object.keys(e).forEach(t=>{if(t.startsWith("#")&&2===t.length){const n=t.slice(1);(Array.isArray(e[t])?e[t]:[e[t]]).forEach(e=>{u.push({name:n,value:String(e)})})}}),n(4,u),B&&clearTimeout(B),O()}catch(e){n(11,m="Invalid JSON: "+e.message)}},F,Q,R,T,U,$,N,L,function(){n(0,s=""),n(1,a=[]),n(2,l=[]),n(3,c=[]),n(4,u=[]),n(5,d=null),n(6,f=null),n(7,h=null),o("clear")},function(){return d?pm(d):""},function(){return f?pm(f):""},function(e){const t=e.target.value;n(5,d=t?gm(t):null)},function(e){const t=e.target.value;n(6,f=t?gm(t):null)},S,r,function(){s=this.value,n(0,s)},()=>n(12,y=!y),function(){w=this.value,n(9,w)},e=>F(e),e=>Q(e),function(){v=this.value,n(13,v)},e=>"Enter"===e.key&&R(),e=>T(e),function(){A=this.value,n(14,A)},e=>"Enter"===e.key&&U(),e=>$(e),function(){k=this.value,n(15,k)},function(){I=this.value,n(16,I)},e=>"Enter"===e.key&&N(),e=>L(e),()=>n(5,d=null),()=>n(6,f=null),function(){h=b(this.value),n(7,h)},function(){g=this.value,n(10,g),n(8,p)},()=>o("toggleJson")]}class Mm extends oe{constructor(e){super(),ie(this,e,Om,Lm,o,{searchText:0,selectedKinds:1,pubkeys:2,eventIds:3,tags:4,sinceTimestamp:5,untilTimestamp:6,limit:7,showJsonEditor:8},null,[-1,-1,-1])}}function _m(e,t,n){const r=e.slice();return r[28]=t[n],r}function Hm(e,t,n){const r=e.slice();return r[31]=t[n],r}function jm(t){let n;return{c(){n=h("div"),n.innerHTML="<p>❌ Read, write, admin, or owner permission required to view all\n events.</p>",A(n,"class","permission-denied svelte-5kb1ec")},m(e,t){u(e,n,t)},p:e,d(e){e&&d(n)}}}function Gm(e){let t,n,r,i;function o(e,t){return e[4].length>0?Jm:e[6]?void 0:Km}let s=o(e),a=s&&s(e),l=e[6]&&ey();return{c(){t=h("div"),a&&a.c(),n=m(),l&&l.c(),A(t,"class","events-view-content svelte-5kb1ec")},m(o,s){u(o,t,s),a&&a.m(t,null),c(t,n),l&&l.m(t,null),r||(i=w(t,"scroll",e[9]),r=!0)},p(e,r){s===(s=o(e))&&a?a.p(e,r):(a&&a.d(1),a=s&&s(e),a&&(a.c(),a.m(t,n))),e[6]?l||(l=ey(),l.c(),l.m(t,null)):l&&(l.d(1),l=null)},d(e){e&&d(t),a&&a.d(),l&&l.d(),r=!1,i()}}}function Km(t){let n;return{c(){n=h("div"),n.innerHTML="<p>No events found.</p>",A(n,"class","no-events svelte-5kb1ec")},m(e,t){u(e,n,t)},p:e,d(e){e&&d(n)}}}function Jm(e){let t,n=e[4],r=[];for(let t=0;t<n.length;t+=1)r[t]=Xm(_m(e,n,t));return{c(){for(let e=0;e<r.length;e+=1)r[e].c();t=y()},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,i){if(7228&i[0]){let o;for(n=e[4],o=0;o<n.length;o+=1){const s=_m(e,n,o);r[o]?r[o].p(s,i):(r[o]=Xm(s),r[o].c(),r[o].m(t.parentNode,t))}for(;o<r.length;o+=1)r[o].d(1);r.length=n.length}},d(e){f(r,e),e&&d(t)}}}function Vm(e){let t,n,r=ly(e[28].content)+"";return{c(){t=h("div"),n=g(r),A(t,"class","event-content-single-line svelte-5kb1ec")},m(e,r){u(e,t,r),c(t,n)},p(e,t){16&t[0]&&r!==(r=ly(e[28].content)+"")&&k(n,r)},d(e){e&&d(t)}}}function qm(e){let t,n,r,i=e[28].tags&&e[28].tags.length>0&&zm(e);return{c(){t=h("div"),n=h("span"),n.textContent="🗑️ Delete Event",r=m(),i&&i.c(),A(n,"class","delete-event-label svelte-5kb1ec"),A(t,"class","delete-event-info svelte-5kb1ec")},m(e,o){u(e,t,o),c(t,n),c(t,r),i&&i.m(t,null)},p(e,n){e[28].tags&&e[28].tags.length>0?i?i.p(e,n):(i=zm(e),i.c(),i.m(t,null)):i&&(i.d(1),i=null)},d(e){e&&d(t),i&&i.d()}}}function zm(e){let t,n=e[28].tags.filter(cy),r=[];for(let t=0;t<n.length;t+=1)r[t]=Ym(Hm(e,n,t));return{c(){t=h("div");for(let e=0;e<r.length;e+=1)r[e].c();A(t,"class","delete-targets svelte-5kb1ec")},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,i){if(16&i[0]){let o;for(n=e[28].tags.filter(cy),o=0;o<n.length;o+=1){const s=Hm(e,n,o);r[o]?r[o].p(s,i):(r[o]=Ym(s),r[o].c(),r[o].m(t,null))}for(;o<r.length;o+=1)r[o].d(1);r.length=n.length}},d(e){e&&d(t),f(r,e)}}}function Ym(e){let t,n,r,i,o,s=e[31][1].slice(0,8)+"",a=e[31][1].slice(-8)+"";return{c(){t=h("span"),n=g("Target: "),r=g(s),i=g("..."),o=g(a),A(t,"class","delete-target svelte-5kb1ec")},m(e,s){u(e,t,s),c(t,n),c(t,r),c(t,i),c(t,o)},p(e,t){16&t[0]&&s!==(s=e[31][1].slice(0,8)+"")&&k(r,s),16&t[0]&&a!==(a=e[31][1].slice(-8)+"")&&k(o,a)},d(e){e&&d(t)}}}function Wm(e){let t,n,r;function i(){return e[19](e[28])}return{c(){t=h("button"),t.textContent="🗑️",A(t,"class","delete-btn svelte-5kb1ec")},m(e,o){u(e,t,o),n||(r=w(t,"click",v(i)),n=!0)},p(t,n){e=t},d(e){e&&d(t),n=!1,r()}}}function Zm(e){let t,n,r,i,o,s,a,l,f=JSON.stringify(e[28],null,2)+"";function p(...t){return e[22](e[28],...t)}return{c(){t=h("div"),n=h("div"),r=h("pre"),i=g(f),o=m(),s=h("button"),s.textContent="📋",A(r,"class","event-json svelte-5kb1ec"),A(s,"class","copy-json-btn svelte-5kb1ec"),A(s,"title","Copy minified JSON to clipboard"),A(n,"class","json-container svelte-5kb1ec"),A(t,"class","events-view-details svelte-5kb1ec")},m(e,d){u(e,t,d),c(t,n),c(n,r),c(r,i),c(n,o),c(n,s),a||(l=w(s,"click",v(p)),a=!0)},p(t,n){e=t,16&n[0]&&f!==(f=JSON.stringify(e[28],null,2)+"")&&k(i,f)},d(e){e&&d(t),a=!1,l()}}}function Xm(e){let t,n,i,o,s,a,l,f,p,y,v,b,I,E,C,x,S,F,Q,R,D,P,T,U,$=oy(e[28].pubkey)+"",N=e[28].kind+"",L=sy(e[28].kind)+"",O=ay(e[28].created_at)+"",M=e[5].has(e[28].id);function _(e,t){return 5===e[28].kind?qm:Vm}let H=_(e),j=H(e),G=5!==e[28].kind&&("admin"===e[2]||"owner"===e[2]||"write"===e[2]&&e[28].pubkey&&e[28].pubkey===e[3])&&Wm(e);function K(){return e[20](e[28])}function J(...t){return e[21](e[28],...t)}let V=M&&Zm(e);return{c(){t=h("div"),n=h("div"),i=h("div"),i.innerHTML='<div class="avatar-placeholder svelte-5kb1ec">👤</div>',o=m(),s=h("div"),a=h("div"),l=g($),f=m(),p=h("div"),y=h("span"),v=g(N),b=m(),I=h("span"),E=g(L),C=m(),x=h("div"),S=h("div"),F=g(O),Q=m(),j.c(),R=m(),G&&G.c(),D=m(),V&&V.c(),P=m(),A(i,"class","events-view-avatar svelte-5kb1ec"),A(a,"class","events-view-author svelte-5kb1ec"),A(y,"class","kind-number svelte-5kb1ec"),B(y,"delete-event",5===e[28].kind),A(I,"class","kind-name svelte-5kb1ec"),A(p,"class","events-view-kind svelte-5kb1ec"),A(s,"class","events-view-info svelte-5kb1ec"),A(S,"class","event-timestamp svelte-5kb1ec"),A(x,"class","events-view-content svelte-5kb1ec"),A(n,"class","events-view-row svelte-5kb1ec"),A(n,"role","button"),A(n,"tabindex","0"),A(t,"class","events-view-item svelte-5kb1ec"),B(t,"expanded",e[5].has(e[28].id))},m(e,r){u(e,t,r),c(t,n),c(n,i),c(n,o),c(n,s),c(s,a),c(a,l),c(s,f),c(s,p),c(p,y),c(y,v),c(p,b),c(p,I),c(I,E),c(n,C),c(n,x),c(x,S),c(S,F),c(x,Q),j.m(x,null),c(n,R),G&&G.m(n,null),c(t,D),V&&V.m(t,null),c(t,P),T||(U=[w(n,"click",K),w(n,"keydown",J)],T=!0)},p(r,i){e=r,16&i[0]&&$!==($=oy(e[28].pubkey)+"")&&k(l,$),16&i[0]&&N!==(N=e[28].kind+"")&&k(v,N),16&i[0]&&B(y,"delete-event",5===e[28].kind),16&i[0]&&L!==(L=sy(e[28].kind)+"")&&k(E,L),16&i[0]&&O!==(O=ay(e[28].created_at)+"")&&k(F,O),H===(H=_(e))&&j?j.p(e,i):(j.d(1),j=H(e),j&&(j.c(),j.m(x,null))),5!==e[28].kind&&("admin"===e[2]||"owner"===e[2]||"write"===e[2]&&e[28].pubkey&&e[28].pubkey===e[3])?G?G.p(e,i):(G=Wm(e),G.c(),G.m(n,null)):G&&(G.d(1),G=null),48&i[0]&&(M=e[5].has(e[28].id)),M?V?V.p(e,i):(V=Zm(e),V.c(),V.m(t,P)):V&&(V.d(1),V=null),48&i[0]&&B(t,"expanded",e[5].has(e[28].id))},d(e){e&&d(t),j.d(),G&&G.d(),V&&V.d(),T=!1,r(U)}}}function ey(e){let t;return{c(){t=h("div"),t.innerHTML='<div class="spinner svelte-5kb1ec"></div> \n <p>Loading events...</p>',A(t,"class","loading-events svelte-5kb1ec")},m(e,n){u(e,t,n)},d(e){e&&d(t)}}}function ty(e){let t,n,i,o,s,a,l,f,p,y,v,b,k,I,E,C,x,S,F,Q,R,D,P,T;function U(e,t){return e[6]?ry:ny}i=new Mm({props:{showJsonEditor:e[8]}}),i.$on("apply",e[17]),i.$on("clear",e[18]),i.$on("toggleJson",e[16]);let $=U(e),N=$(e);return{c(){t=h("div"),n=h("div"),ee(i.$$.fragment),o=m(),s=h("div"),a=h("div"),l=h("button"),l.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="svelte-5kb1ec"><polygon points="22 3 2 3 10 12.46 10 19 14 21 14 12.46 22 3"></polygon></svg>',f=m(),p=h("div"),y=h("label"),v=h("input"),b=m(),k=h("span"),I=m(),E=h("span"),E.textContent="Only show my events",C=m(),x=h("div"),S=h("button"),F=g("🔄 Load More"),Q=m(),R=h("button"),N.c(),A(n,"class","filter-panel svelte-5kb1ec"),B(n,"open",e[7]),A(l,"class","filter-btn svelte-5kb1ec"),A(l,"title","Filter events"),B(l,"active",e[7]),A(v,"type","checkbox"),A(v,"class","svelte-5kb1ec"),A(k,"class","toggle-slider svelte-5kb1ec"),A(E,"class","toggle-label svelte-5kb1ec"),A(y,"class","toggle-container svelte-5kb1ec"),A(p,"class","events-view-toggle svelte-5kb1ec"),A(a,"class","events-view-left svelte-5kb1ec"),A(S,"class","refresh-btn svelte-5kb1ec"),S.disabled=e[6],A(R,"class","reload-btn svelte-5kb1ec"),R.disabled=e[6],A(x,"class","events-view-buttons svelte-5kb1ec"),A(s,"class","events-view-header svelte-5kb1ec"),A(t,"class","events-view-footer svelte-5kb1ec")},m(r,d){u(r,t,d),c(t,n),te(i,n,null),c(t,o),c(t,s),c(s,a),c(a,l),c(a,f),c(a,p),c(p,y),c(y,v),v.checked=e[0],c(y,b),c(y,k),c(y,I),c(y,E),c(s,C),c(s,x),c(x,S),c(S,F),c(x,Q),c(x,R),N.m(R,null),D=!0,P||(T=[w(l,"click",e[15]),w(v,"change",e[23]),w(v,"change",e[24]),w(S,"click",e[25]),w(R,"click",e[26])],P=!0)},p(e,t){const r={};256&t[0]&&(r.showJsonEditor=e[8]),i.$set(r),(!D||128&t[0])&&B(n,"open",e[7]),(!D||128&t[0])&&B(l,"active",e[7]),1&t[0]&&(v.checked=e[0]),(!D||64&t[0])&&(S.disabled=e[6]),$!==($=U(e))&&(N.d(1),N=$(e),N&&(N.c(),N.m(R,null))),(!D||64&t[0])&&(R.disabled=e[6])},i(e){D||(W(i.$$.fragment,e),D=!0)},o(e){Z(i.$$.fragment,e),D=!1},d(e){e&&d(t),ne(i),N.d(),P=!1,r(T)}}}function ny(e){let t;return{c(){t=g("🔄")},m(e,n){u(e,t,n)},d(e){e&&d(t)}}}function ry(e){let t;return{c(){t=h("div"),A(t,"class","spinner svelte-5kb1ec")},m(e,n){u(e,t,n)},d(e){e&&d(t)}}}function iy(e){let t,n,r;function i(e,t){return!e[1]||"read"!==e[2]&&"write"!==e[2]&&"admin"!==e[2]&&"owner"!==e[2]?jm:Gm}let o=i(e),s=o(e),a=e[1]&&("read"===e[2]||"write"===e[2]||"admin"===e[2]||"owner"===e[2])&&ty(e);return{c(){t=h("div"),s.c(),n=m(),a&&a.c(),A(t,"class","events-view-container svelte-5kb1ec")},m(e,i){u(e,t,i),s.m(t,null),c(t,n),a&&a.m(t,null),r=!0},p(e,r){o===(o=i(e))&&s?s.p(e,r):(s.d(1),s=o(e),s&&(s.c(),s.m(t,n))),!e[1]||"read"!==e[2]&&"write"!==e[2]&&"admin"!==e[2]&&"owner"!==e[2]?a&&(z(),Z(a,1,1,()=>{a=null}),Y()):a?(a.p(e,r),6&r[0]&&W(a,1)):(a=ty(e),a.c(),W(a,1),a.m(t,null))},i(e){r||(W(a),r=!0)},o(e){Z(a),r=!1},d(e){e&&d(t),s.d(),a&&a.d()}}}function oy(e){return e?e.slice(0,8)+"..."+e.slice(-8):""}function sy(e){return{0:"Profile",1:"Text Note",2:"Recommend Relay",3:"Contacts",4:"Encrypted DM",5:"Delete",6:"Repost",7:"Reaction",8:"Badge Award",16:"Generic Repost",40:"Channel Creation",41:"Channel Metadata",42:"Channel Message",43:"Channel Hide Message",44:"Channel Mute User",1984:"Reporting",9734:"Zap Request",9735:"Zap",1e4:"Mute List",10001:"Pin List",10002:"Relay List",22242:"Client Auth",24133:"Nostr Connect",27235:"HTTP Auth",3e4:"Categorized People",30001:"Categorized Bookmarks",30008:"Profile Badges",30009:"Badge Definition",30017:"Create or update a stall",30018:"Create or update a product",30023:"Long-form Content",30024:"Draft Long-form Content",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",34550:"Community Definition"}[e]||`Kind ${e}`}function ay(e){return new Date(1e3*e).toLocaleString()}function ly(e){return e?e.length>100?e.slice(0,100)+"...":e:""}const cy=e=>"e"===e[0];function uy(e,t,n){let{isLoggedIn:r=!1}=t,{userRole:i=""}=t,{userPubkey:o=""}=t,{filteredEvents:s=[]}=t,{expandedEvents:a=new Set}=t,{isLoadingEvents:l=!1}=t,{showOnlyMyEvents:c=!1}=t,{showFilterBuilder:u=!1}=t;const d=P();let f=!1;function h(e){d("toggleEventExpansion",e)}function p(e){d("deleteEvent",e)}function g(e,t){d("copyEventToClipboard",{event:e,e:t})}function m(){d("toggleChange")}function y(e,t){d("loadAllEvents",{refresh:e,authors:t})}return e.$$set=e=>{"isLoggedIn"in e&&n(1,r=e.isLoggedIn),"userRole"in e&&n(2,i=e.userRole),"userPubkey"in e&&n(3,o=e.userPubkey),"filteredEvents"in e&&n(4,s=e.filteredEvents),"expandedEvents"in e&&n(5,a=e.expandedEvents),"isLoadingEvents"in e&&n(6,l=e.isLoadingEvents),"showOnlyMyEvents"in e&&n(0,c=e.showOnlyMyEvents),"showFilterBuilder"in e&&n(7,u=e.showFilterBuilder)},[c,r,i,o,s,a,l,u,f,function(e){d("scroll",e)},h,p,g,m,y,function(){d("toggleFilterBuilder")},function(){n(8,f=!f)},function(e){d("filterApply",e.detail)},function(){d("filterClear")},e=>p(e.id),e=>h(e.id),(e,t)=>"Enter"===t.key&&h(e.id),(e,t)=>g(e,t),function(){c=this.checked,n(0,c)},()=>m(),()=>{y(!1,c&&o?[o]:null)},()=>{y(!0,c&&o?[o]:null)}]}class dy extends oe{constructor(e){super(),ie(this,e,uy,iy,o,{isLoggedIn:1,userRole:2,userPubkey:3,filteredEvents:4,expandedEvents:5,isLoadingEvents:6,showOnlyMyEvents:0,showFilterBuilder:7},null,[-1,-1])}}const fy=[{kind:0,name:"Metadata",description:"User profile information (name, about, picture, nip05, etc.)",nip:"01",isReplaceable:!0,template:{kind:0,content:"",tags:[]}},{kind:1,name:"Short Text Note",description:"Short-form text post (like a tweet)",nip:"01",template:{kind:1,content:"",tags:[]}},{kind:2,name:"Recommend Relay",description:"Relay recommendation",nip:"01",deprecated:!0,template:{kind:2,content:"",tags:[]}},{kind:3,name:"Follows",description:"Following list with optional relay hints",nip:"02",isReplaceable:!0,template:{kind:3,content:"",tags:[]}},{kind:4,name:"Encrypted Direct Message",description:"Private message using NIP-04 encryption",nip:"04",deprecated:!0,template:{kind:4,content:"",tags:[]}},{kind:5,name:"Event Deletion Request",description:"Request to delete events",nip:"09",template:{kind:5,content:"",tags:[]}},{kind:6,name:"Repost",description:"Share/repost another text note",nip:"18",template:{kind:6,content:"",tags:[]}},{kind:7,name:"Reaction",description:"Like, emoji reaction to an event",nip:"25",template:{kind:7,content:"",tags:[]}},{kind:8,name:"Badge Award",description:"Award a badge to someone",nip:"58",template:{kind:8,content:"",tags:[]}},{kind:9,name:"Chat Message",description:"Chat message",nip:"C7",template:{kind:9,content:"",tags:[]}},{kind:10,name:"Group Chat Threaded Reply",description:"Threaded reply in group chat",nip:"29",deprecated:!0,template:{kind:10,content:"",tags:[]}},{kind:11,name:"Thread",description:"Thread event",nip:"7D",template:{kind:11,content:"",tags:[]}},{kind:12,name:"Group Thread Reply",description:"Reply in group thread",nip:"29",deprecated:!0,template:{kind:12,content:"",tags:[]}},{kind:13,name:"Seal",description:"Sealed/encrypted event wrapper",nip:"59",template:{kind:13,content:"",tags:[]}},{kind:14,name:"Direct Message",description:"Private direct message using NIP-17",nip:"17",template:{kind:14,content:"",tags:[]}},{kind:15,name:"File Message",description:"File message in DMs",nip:"17",template:{kind:15,content:"",tags:[]}},{kind:16,name:"Generic Repost",description:"Repost any event kind",nip:"18",template:{kind:16,content:"",tags:[]}},{kind:17,name:"Reaction to Website",description:"Reaction to a website URL",nip:"25",template:{kind:17,content:"",tags:[]}},{kind:20,name:"Picture",description:"Picture-first feed post",nip:"68",template:{kind:20,content:"",tags:[]}},{kind:21,name:"Video Event",description:"Horizontal video event",nip:"71",template:{kind:21,content:"",tags:[]}},{kind:22,name:"Short-form Video",description:"Short-form portrait video (like TikTok)",nip:"71",template:{kind:22,content:"",tags:[]}},{kind:40,name:"Channel Creation",description:"Create a public chat channel",nip:"28",template:{kind:40,content:"",tags:[]}},{kind:41,name:"Channel Metadata",description:"Set channel name, about, picture",nip:"28",template:{kind:41,content:"",tags:[]}},{kind:42,name:"Channel Message",description:"Post message in channel",nip:"28",template:{kind:42,content:"",tags:[]}},{kind:43,name:"Channel Hide Message",description:"Hide a message in channel",nip:"28",template:{kind:43,content:"",tags:[]}},{kind:44,name:"Channel Mute User",description:"Mute a user in channel",nip:"28",template:{kind:44,content:"",tags:[]}},{kind:62,name:"Request to Vanish",description:"Request permanent deletion of all user data",nip:"62",template:{kind:62,content:"",tags:[]}},{kind:64,name:"Chess (PGN)",description:"Chess game in PGN format",nip:"64",template:{kind:64,content:"",tags:[]}},{kind:443,name:"KeyPackage",description:"Marmot protocol key package",nip:null,spec:"Marmot",template:{kind:443,content:"",tags:[]}},{kind:444,name:"Welcome Message",description:"Marmot protocol welcome message",nip:null,spec:"Marmot",template:{kind:444,content:"",tags:[]}},{kind:445,name:"Group Event",description:"Marmot protocol group event",nip:null,spec:"Marmot",template:{kind:445,content:"",tags:[]}},{kind:818,name:"Merge Requests",description:"Git merge request",nip:"54",template:{kind:818,content:"",tags:[]}},{kind:1018,name:"Poll Response",description:"Response to a poll",nip:"88",template:{kind:1018,content:"",tags:[]}},{kind:1021,name:"Bid",description:"Auction bid",nip:"15",template:{kind:1021,content:"",tags:[]}},{kind:1022,name:"Bid Confirmation",description:"Confirmation of auction bid",nip:"15",template:{kind:1022,content:"",tags:[]}},{kind:1040,name:"OpenTimestamps",description:"OpenTimestamps attestation",nip:"03",template:{kind:1040,content:"",tags:[]}},{kind:1059,name:"Gift Wrap",description:"Encrypted gift-wrapped event",nip:"59",template:{kind:1059,content:"",tags:[]}},{kind:1060,name:"Gift Wrap (Kind 4)",description:"Gift wrap variant for NIP-04 compatibility",nip:"59",template:{kind:1060,content:"",tags:[]}},{kind:1063,name:"File Metadata",description:"Metadata for shared files",nip:"94",template:{kind:1063,content:"",tags:[]}},{kind:1068,name:"Poll",description:"Create a poll",nip:"88",template:{kind:1068,content:"",tags:[]}},{kind:1111,name:"Comment",description:"Comment on events or external content",nip:"22",template:{kind:1111,content:"",tags:[]}},{kind:1222,name:"Voice Message",description:"Voice message",nip:"A0",template:{kind:1222,content:"",tags:[]}},{kind:1244,name:"Voice Message Comment",description:"Comment on voice message",nip:"A0",template:{kind:1244,content:"",tags:[]}},{kind:1311,name:"Live Chat Message",description:"Message in live stream chat",nip:"53",template:{kind:1311,content:"",tags:[]}},{kind:1337,name:"Code Snippet",description:"Code snippet post",nip:"C0",template:{kind:1337,content:"",tags:[]}},{kind:1517,name:"Bitcoin Block",description:"Bitcoin block data",nip:null,spec:"Nostrocket",template:{kind:1517,content:"",tags:[]}},{kind:1617,name:"Patches",description:"Git patches",nip:"34",template:{kind:1617,content:"",tags:[]}},{kind:1618,name:"Pull Requests",description:"Git pull request",nip:"34",template:{kind:1618,content:"",tags:[]}},{kind:1619,name:"Pull Request Updates",description:"Updates to git pull request",nip:"34",template:{kind:1619,content:"",tags:[]}},{kind:1621,name:"Issues",description:"Git issues",nip:"34",template:{kind:1621,content:"",tags:[]}},{kind:1622,name:"Git Replies",description:"Replies on git objects",nip:"34",deprecated:!0,template:{kind:1622,content:"",tags:[]}},{kind:1630,name:"Status",description:"Git status",nip:"34",template:{kind:1630,content:"",tags:[]}},{kind:1631,name:"Status",description:"Git status",nip:"34",template:{kind:1631,content:"",tags:[]}},{kind:1632,name:"Status",description:"Git status",nip:"34",template:{kind:1632,content:"",tags:[]}},{kind:1633,name:"Status",description:"Git status",nip:"34",template:{kind:1633,content:"",tags:[]}},{kind:1808,name:"Live Stream",description:"Live streaming event",nip:null,spec:"zap.stream",template:{kind:1808,content:"",tags:[]}},{kind:1971,name:"Problem Tracker",description:"Problem tracking",nip:null,spec:"Nostrocket",template:{kind:1971,content:"",tags:[]}},{kind:1984,name:"Reporting",description:"Report content or users",nip:"56",template:{kind:1984,content:"",tags:[]}},{kind:1985,name:"Label",description:"Label/tag content with namespace",nip:"32",template:{kind:1985,content:"",tags:[]}},{kind:1986,name:"Relay Reviews",description:"Reviews of relays",nip:null,template:{kind:1986,content:"",tags:[]}},{kind:1987,name:"AI Embeddings",description:"AI embeddings/vector lists",nip:null,spec:"NKBIP-02",template:{kind:1987,content:"",tags:[]}},{kind:2003,name:"Torrent",description:"Torrent magnet link",nip:"35",template:{kind:2003,content:"",tags:[]}},{kind:2004,name:"Torrent Comment",description:"Comment on torrent",nip:"35",template:{kind:2004,content:"",tags:[]}},{kind:2022,name:"Coinjoin Pool",description:"Coinjoin coordination",nip:null,spec:"joinstr",template:{kind:2022,content:"",tags:[]}},{kind:4550,name:"Community Post Approval",description:"Approve post in community",nip:"72",template:{kind:4550,content:"",tags:[]}},{kind:5e3,name:"Job Request",description:"Data vending machine job request (start of range)",nip:"90",template:{kind:5e3,content:"",tags:[]}},{kind:6e3,name:"Job Result",description:"Data vending machine job result (start of range)",nip:"90",template:{kind:6e3,content:"",tags:[]}},{kind:7e3,name:"Job Feedback",description:"Feedback on job request/result",nip:"90",template:{kind:7e3,content:"",tags:[]}},{kind:7374,name:"Reserved Cashu Wallet Tokens",description:"Reserved Cashu wallet tokens",nip:"60",template:{kind:7374,content:"",tags:[]}},{kind:7375,name:"Cashu Wallet Tokens",description:"Cashu wallet tokens",nip:"60",template:{kind:7375,content:"",tags:[]}},{kind:7376,name:"Cashu Wallet History",description:"Cashu wallet transaction history",nip:"60",template:{kind:7376,content:"",tags:[]}},{kind:7516,name:"Geocache Log",description:"Geocaching log entry",nip:null,spec:"geocaching",template:{kind:7516,content:"",tags:[]}},{kind:7517,name:"Geocache Proof of Find",description:"Proof of geocache find",nip:null,spec:"geocaching",template:{kind:7517,content:"",tags:[]}},{kind:8e3,name:"Add User",description:"Add user to group",nip:"43",template:{kind:8e3,content:"",tags:[]}},{kind:8001,name:"Remove User",description:"Remove user from group",nip:"43",template:{kind:8001,content:"",tags:[]}},{kind:9e3,name:"Group Control Events",description:"Group control events (start of range)",nip:"29",template:{kind:9e3,content:"",tags:[]}},{kind:9041,name:"Zap Goal",description:"Fundraising goal for zaps",nip:"75",template:{kind:9041,content:"",tags:[]}},{kind:9321,name:"Nutzap",description:"Cashu nutzap",nip:"61",template:{kind:9321,content:"",tags:[]}},{kind:9467,name:"Tidal Login",description:"Tidal streaming login",nip:null,spec:"Tidal-nostr",template:{kind:9467,content:"",tags:[]}},{kind:9734,name:"Zap Request",description:"Request Lightning payment",nip:"57",template:{kind:9734,content:"",tags:[]}},{kind:9735,name:"Zap",description:"Lightning payment receipt",nip:"57",template:{kind:9735,content:"",tags:[]}},{kind:9802,name:"Highlights",description:"Highlighted text selection",nip:"84",template:{kind:9802,content:"",tags:[]}},{kind:1e4,name:"Mute List",description:"List of muted users/content",nip:"51",isReplaceable:!0,template:{kind:1e4,content:"",tags:[]}},{kind:10001,name:"Pin List",description:"Pinned events",nip:"51",isReplaceable:!0,template:{kind:10001,content:"",tags:[]}},{kind:10002,name:"Relay List Metadata",description:"User's preferred relays for read/write",nip:"65",isReplaceable:!0,template:{kind:10002,content:"",tags:[]}},{kind:10003,name:"Bookmark List",description:"Bookmarked events",nip:"51",isReplaceable:!0,template:{kind:10003,content:"",tags:[]}},{kind:10004,name:"Communities List",description:"Communities user belongs to",nip:"51",isReplaceable:!0,template:{kind:10004,content:"",tags:[]}},{kind:10005,name:"Public Chats List",description:"Public chats user is in",nip:"51",isReplaceable:!0,template:{kind:10005,content:"",tags:[]}},{kind:10006,name:"Blocked Relays List",description:"Relays user has blocked",nip:"51",isReplaceable:!0,template:{kind:10006,content:"",tags:[]}},{kind:10007,name:"Search Relays List",description:"Preferred search relays",nip:"51",isReplaceable:!0,template:{kind:10007,content:"",tags:[]}},{kind:10008,name:"Relay Group Configuration",description:"Relay group configuration",nip:null,isReplaceable:!0,template:{kind:10008,content:"",tags:[]}},{kind:10009,name:"User Groups",description:"Groups user belongs to",nip:"29",isReplaceable:!0,template:{kind:10009,content:"",tags:[]}},{kind:10012,name:"Favorite Relays List",description:"User's favorite relays",nip:"51",isReplaceable:!0,template:{kind:10012,content:"",tags:[]}},{kind:10013,name:"Private Event Relay List",description:"Relays for private events",nip:"37",isReplaceable:!0,template:{kind:10013,content:"",tags:[]}},{kind:10015,name:"Interests List",description:"User interests/topics",nip:"51",isReplaceable:!0,template:{kind:10015,content:"",tags:[]}},{kind:10019,name:"Nutzap Mint Recommendation",description:"Recommended Cashu mints for nutzaps",nip:"61",isReplaceable:!0,template:{kind:10019,content:"",tags:[]}},{kind:10020,name:"Media Follows",description:"Followed media accounts",nip:"51",isReplaceable:!0,template:{kind:10020,content:"",tags:[]}},{kind:10030,name:"User Emoji List",description:"Custom emoji list",nip:"51",isReplaceable:!0,template:{kind:10030,content:"",tags:[]}},{kind:10050,name:"DM Relays List",description:"Relays to receive DMs on",nip:"17",isReplaceable:!0,template:{kind:10050,content:"",tags:[]}},{kind:10051,name:"KeyPackage Relays List",description:"Marmot key package relays",nip:null,isReplaceable:!0,spec:"Marmot",template:{kind:10051,content:"",tags:[]}},{kind:10063,name:"User Server List",description:"Blossom server list",nip:null,isReplaceable:!0,spec:"Blossom",template:{kind:10063,content:"",tags:[]}},{kind:10096,name:"File Storage Server List",description:"File storage servers",nip:"96",isReplaceable:!0,deprecated:!0,template:{kind:10096,content:"",tags:[]}},{kind:10166,name:"Relay Monitor Announcement",description:"Relay monitoring announcement",nip:"66",isReplaceable:!0,template:{kind:10166,content:"",tags:[]}},{kind:10312,name:"Room Presence",description:"Presence in live room",nip:"53",isReplaceable:!0,template:{kind:10312,content:"",tags:[]}},{kind:10377,name:"Proxy Announcement",description:"Nostr proxy announcement",nip:null,isReplaceable:!0,spec:"Nostr Epoxy",template:{kind:10377,content:"",tags:[]}},{kind:11111,name:"Transport Method Announcement",description:"Transport method announcement",nip:null,isReplaceable:!0,spec:"Nostr Epoxy",template:{kind:11111,content:"",tags:[]}},{kind:12345,name:"Relay Policy Configuration",description:"Relay-internal policy configuration (admin only)",nip:null,isReplaceable:!0,spec:"orly",template:{kind:12345,content:"",tags:[]}},{kind:13004,name:"JWT Binding",description:"Link between JWT certificate and pubkey",nip:null,isReplaceable:!0,template:{kind:13004,content:"",tags:[]}},{kind:13194,name:"Wallet Service Info",description:"NWC wallet service information",nip:"47",isReplaceable:!0,template:{kind:13194,content:"",tags:[]}},{kind:13534,name:"Membership Lists",description:"Group membership lists",nip:"43",isReplaceable:!0,template:{kind:13534,content:"",tags:[]}},{kind:14388,name:"User Sound Effect Lists",description:"Sound effect lists",nip:null,isReplaceable:!0,spec:"Corny Chat",template:{kind:14388,content:"",tags:[]}},{kind:17375,name:"Cashu Wallet Event",description:"Cashu wallet event",nip:"60",isReplaceable:!0,template:{kind:17375,content:"",tags:[]}},{kind:21e3,name:"Lightning Pub RPC",description:"Lightning.Pub RPC",nip:null,isEphemeral:!0,spec:"Lightning.Pub",template:{kind:21e3,content:"",tags:[]}},{kind:22242,name:"Client Authentication",description:"Authenticate to relay",nip:"42",isEphemeral:!0,template:{kind:22242,content:"",tags:[]}},{kind:23194,name:"Wallet Request",description:"NWC wallet request",nip:"47",isEphemeral:!0,template:{kind:23194,content:"",tags:[]}},{kind:23195,name:"Wallet Response",description:"NWC wallet response",nip:"47",isEphemeral:!0,template:{kind:23195,content:"",tags:[]}},{kind:23196,name:"Wallet Notification (NIP-04)",description:"NWC wallet notification (NIP-04 encrypted)",nip:"47",isEphemeral:!0,template:{kind:23196,content:"",tags:[]}},{kind:23197,name:"Wallet Notification",description:"NWC wallet notification",nip:"47",isEphemeral:!0,template:{kind:23197,content:"",tags:[]}},{kind:24133,name:"Nostr Connect",description:"Remote signer connection",nip:"46",isEphemeral:!0,template:{kind:24133,content:"",tags:[]}},{kind:24242,name:"Blobs Stored on Mediaservers",description:"Blossom blob storage",nip:null,isEphemeral:!0,spec:"Blossom",template:{kind:24242,content:"",tags:[]}},{kind:27235,name:"HTTP Auth",description:"Authenticate HTTP requests",nip:"98",isEphemeral:!0,template:{kind:27235,content:"",tags:[]}},{kind:28934,name:"Join Request",description:"Request to join group",nip:"43",isEphemeral:!0,template:{kind:28934,content:"",tags:[]}},{kind:28935,name:"Invite Request",description:"Invite to group",nip:"43",isEphemeral:!0,template:{kind:28935,content:"",tags:[]}},{kind:28936,name:"Leave Request",description:"Leave group request",nip:"43",isEphemeral:!0,template:{kind:28936,content:"",tags:[]}},{kind:3e4,name:"Follow Sets",description:"Categorized people lists",nip:"51",isAddressable:!0,template:{kind:3e4,content:"",tags:[["d","identifier"]]}},{kind:30001,name:"Generic Lists",description:"Generic categorized lists",nip:"51",isAddressable:!0,deprecated:!0,template:{kind:30001,content:"",tags:[["d","identifier"]]}},{kind:30002,name:"Relay Sets",description:"Categorized relay lists",nip:"51",isAddressable:!0,template:{kind:30002,content:"",tags:[["d","identifier"]]}},{kind:30003,name:"Bookmark Sets",description:"Categorized bookmark lists",nip:"51",isAddressable:!0,template:{kind:30003,content:"",tags:[["d","identifier"]]}},{kind:30004,name:"Curation Sets",description:"Curated content sets",nip:"51",isAddressable:!0,template:{kind:30004,content:"",tags:[["d","identifier"]]}},{kind:30005,name:"Video Sets",description:"Video playlists",nip:"51",isAddressable:!0,template:{kind:30005,content:"",tags:[["d","identifier"]]}},{kind:30007,name:"Kind Mute Sets",description:"Muted event kinds",nip:"51",isAddressable:!0,template:{kind:30007,content:"",tags:[["d","identifier"]]}},{kind:30008,name:"Profile Badges",description:"Badges displayed on profile",nip:"58",isAddressable:!0,template:{kind:30008,content:"",tags:[["d","identifier"]]}},{kind:30009,name:"Badge Definition",description:"Define a badge/achievement",nip:"58",isAddressable:!0,template:{kind:30009,content:"",tags:[["d","identifier"]]}},{kind:30015,name:"Interest Sets",description:"Interest/topic sets",nip:"51",isAddressable:!0,template:{kind:30015,content:"",tags:[["d","identifier"]]}},{kind:30017,name:"Stall",description:"Marketplace stall definition",nip:"15",isAddressable:!0,template:{kind:30017,content:"",tags:[["d","identifier"]]}},{kind:30018,name:"Product",description:"Marketplace product listing",nip:"15",isAddressable:!0,template:{kind:30018,content:"",tags:[["d","identifier"]]}},{kind:30019,name:"Marketplace UI/UX",description:"Marketplace interface settings",nip:"15",isAddressable:!0,template:{kind:30019,content:"",tags:[["d","identifier"]]}},{kind:30020,name:"Product Sold as Auction",description:"Auction product listing",nip:"15",isAddressable:!0,template:{kind:30020,content:"",tags:[["d","identifier"]]}},{kind:30023,name:"Long-form Content",description:"Blog post, article in markdown",nip:"23",isAddressable:!0,template:{kind:30023,content:"",tags:[["d","identifier"]]}},{kind:30024,name:"Draft Long-form Content",description:"Draft article",nip:"23",isAddressable:!0,template:{kind:30024,content:"",tags:[["d","identifier"]]}},{kind:30030,name:"Emoji Sets",description:"Custom emoji sets",nip:"51",isAddressable:!0,template:{kind:30030,content:"",tags:[["d","identifier"]]}},{kind:30040,name:"Curated Publication Index",description:"Publication index",nip:null,isAddressable:!0,spec:"NKBIP-01",template:{kind:30040,content:"",tags:[["d","identifier"]]}},{kind:30041,name:"Curated Publication Content",description:"Publication content",nip:null,isAddressable:!0,spec:"NKBIP-01",template:{kind:30041,content:"",tags:[["d","identifier"]]}},{kind:30063,name:"Release Artifact Sets",description:"Software release artifacts",nip:"51",isAddressable:!0,template:{kind:30063,content:"",tags:[["d","identifier"]]}},{kind:30078,name:"Application-specific Data",description:"App-specific key-value storage",nip:"78",isAddressable:!0,template:{kind:30078,content:"",tags:[["d","identifier"]]}},{kind:30166,name:"Relay Discovery",description:"Relay discovery/monitoring",nip:"66",isAddressable:!0,template:{kind:30166,content:"",tags:[["d","identifier"]]}},{kind:30267,name:"App Curation Sets",description:"Curated app sets",nip:"51",isAddressable:!0,template:{kind:30267,content:"",tags:[["d","identifier"]]}},{kind:30311,name:"Live Event",description:"Live streaming event",nip:"53",isAddressable:!0,template:{kind:30311,content:"",tags:[["d","identifier"]]}},{kind:30312,name:"Interactive Room",description:"Interactive live room",nip:"53",isAddressable:!0,template:{kind:30312,content:"",tags:[["d","identifier"]]}},{kind:30313,name:"Conference Event",description:"Conference/meetup event",nip:"53",isAddressable:!0,template:{kind:30313,content:"",tags:[["d","identifier"]]}},{kind:30315,name:"User Statuses",description:"User status updates",nip:"38",isAddressable:!0,template:{kind:30315,content:"",tags:[["d","identifier"]]}},{kind:30388,name:"Slide Set",description:"Presentation slides",nip:null,isAddressable:!0,spec:"Corny Chat",template:{kind:30388,content:"",tags:[["d","identifier"]]}},{kind:30402,name:"Classified Listing",description:"Classified ad listing",nip:"99",isAddressable:!0,template:{kind:30402,content:"",tags:[["d","identifier"]]}},{kind:30403,name:"Draft Classified Listing",description:"Draft classified ad",nip:"99",isAddressable:!0,template:{kind:30403,content:"",tags:[["d","identifier"]]}},{kind:30617,name:"Repository Announcements",description:"Git repository announcement",nip:"34",isAddressable:!0,template:{kind:30617,content:"",tags:[["d","identifier"]]}},{kind:30618,name:"Repository State Announcements",description:"Git repository state",nip:"34",isAddressable:!0,template:{kind:30618,content:"",tags:[["d","identifier"]]}},{kind:30818,name:"Wiki Article",description:"Wiki article",nip:"54",isAddressable:!0,template:{kind:30818,content:"",tags:[["d","identifier"]]}},{kind:30819,name:"Redirects",description:"URL redirects",nip:"54",isAddressable:!0,template:{kind:30819,content:"",tags:[["d","identifier"]]}},{kind:31234,name:"Draft Event",description:"Draft of any event",nip:"37",isAddressable:!0,template:{kind:31234,content:"",tags:[["d","identifier"]]}},{kind:31388,name:"Link Set",description:"Link collection",nip:null,isAddressable:!0,spec:"Corny Chat",template:{kind:31388,content:"",tags:[["d","identifier"]]}},{kind:31890,name:"Feed",description:"Custom feed definition",nip:null,isAddressable:!0,spec:"NUD: Custom Feeds",template:{kind:31890,content:"",tags:[["d","identifier"]]}},{kind:31922,name:"Date-Based Calendar Event",description:"All-day calendar event",nip:"52",isAddressable:!0,template:{kind:31922,content:"",tags:[["d","identifier"]]}},{kind:31923,name:"Time-Based Calendar Event",description:"Calendar event with time",nip:"52",isAddressable:!0,template:{kind:31923,content:"",tags:[["d","identifier"]]}},{kind:31924,name:"Calendar",description:"Calendar definition",nip:"52",isAddressable:!0,template:{kind:31924,content:"",tags:[["d","identifier"]]}},{kind:31925,name:"Calendar Event RSVP",description:"RSVP to calendar event",nip:"52",isAddressable:!0,template:{kind:31925,content:"",tags:[["d","identifier"]]}},{kind:31989,name:"Handler Recommendation",description:"Recommended app for event kind",nip:"89",isAddressable:!0,template:{kind:31989,content:"",tags:[["d","identifier"]]}},{kind:31990,name:"Handler Information",description:"App handler declaration",nip:"89",isAddressable:!0,template:{kind:31990,content:"",tags:[["d","identifier"]]}},{kind:32123,name:"WaveLake Track",description:"WaveLake music track",nip:null,isAddressable:!0,spec:"WaveLake",template:{kind:32123,content:"",tags:[["d","identifier"]]}},{kind:32267,name:"Software Application",description:"Software application listing",nip:null,isAddressable:!0,template:{kind:32267,content:"",tags:[["d","identifier"]]}},{kind:32388,name:"User Room Favorites",description:"Favorite rooms",nip:null,isAddressable:!0,spec:"Corny Chat",template:{kind:32388,content:"",tags:[["d","identifier"]]}},{kind:33388,name:"High Scores",description:"Game high scores",nip:null,isAddressable:!0,spec:"Corny Chat",template:{kind:33388,content:"",tags:[["d","identifier"]]}},{kind:34235,name:"Video Event Horizontal",description:"Horizontal video event",nip:"71",isAddressable:!0,template:{kind:34235,content:"",tags:[["d","identifier"]]}},{kind:34236,name:"Video Event Vertical",description:"Vertical video event",nip:"71",isAddressable:!0,template:{kind:34236,content:"",tags:[["d","identifier"]]}},{kind:34388,name:"Sound Effects",description:"Sound effect definitions",nip:null,isAddressable:!0,spec:"Corny Chat",template:{kind:34388,content:"",tags:[["d","identifier"]]}},{kind:34550,name:"Community Definition",description:"Define a community",nip:"72",isAddressable:!0,template:{kind:34550,content:"",tags:[["d","identifier"]]}},{kind:37516,name:"Geocache Listing",description:"Geocache location listing",nip:null,isAddressable:!0,spec:"geocaching",template:{kind:37516,content:"",tags:[["d","identifier"]]}},{kind:38172,name:"Cashu Mint Announcement",description:"Cashu mint announcement",nip:"87",isAddressable:!0,template:{kind:38172,content:"",tags:[["d","identifier"]]}},{kind:38173,name:"Fedimint Announcement",description:"Fedimint announcement",nip:"87",isAddressable:!0,template:{kind:38173,content:"",tags:[["d","identifier"]]}},{kind:38383,name:"Peer-to-peer Order Events",description:"P2P trading orders",nip:"69",isAddressable:!0,template:{kind:38383,content:"",tags:[["d","identifier"]]}},{kind:39e3,name:"Group Metadata Events",description:"Group metadata (start of range)",nip:"29",isAddressable:!0,template:{kind:39e3,content:"",tags:[["d","identifier"]]}},{kind:39089,name:"Starter Packs",description:"Starter pack lists",nip:"51",isAddressable:!0,template:{kind:39089,content:"",tags:[["d","identifier"]]}},{kind:39092,name:"Media Starter Packs",description:"Media starter packs",nip:"51",isAddressable:!0,template:{kind:39092,content:"",tags:[["d","identifier"]]}},{kind:39701,name:"Web Bookmarks",description:"Web URL bookmarks",nip:"B0",isAddressable:!0,template:{kind:39701,content:"",tags:[["d","identifier"]]}},{kind:39998,name:"ACL Event",description:"Access control list event",nip:null,isAddressable:!0,template:{kind:39998,content:"",tags:[["d","identifier"]]}}];function hy(e,t=null){const n=function(e){return fy.find(t=>t.kind===e)}(e);return n?{...n.template,created_at:Math.floor(Date.now()/1e3),pubkey:t||"<your_pubkey_here>"}:{kind:e,content:"",tags:[],created_at:Math.floor(Date.now()/1e3),pubkey:t||"<your_pubkey_here>"}}const py=[{id:"all",name:"All Kinds",filter:()=>!0},{id:"regular",name:"Regular Events (0-9999)",filter:e=>e.kind<1e4&&!e.isReplaceable},{id:"replaceable",name:"Replaceable (10000-19999)",filter:e=>e.isReplaceable},{id:"ephemeral",name:"Ephemeral (20000-29999)",filter:e=>e.isEphemeral},{id:"addressable",name:"Addressable (30000-39999)",filter:e=>e.isAddressable},{id:"social",name:"Social",filter:e=>[0,1,3,6,7].includes(e.kind)},{id:"messaging",name:"Messaging",filter:e=>[4,9,10,11,12,14,15,40,41,42].includes(e.kind)},{id:"lists",name:"Lists",filter:e=>e.name.toLowerCase().includes("list")||e.name.toLowerCase().includes("set")},{id:"marketplace",name:"Marketplace",filter:e=>[30017,30018,30019,30020,1021,1022,30402,30403].includes(e.kind)},{id:"lightning",name:"Lightning/Zaps",filter:e=>[9734,9735,9041,9321,7374,7375,7376].includes(e.kind)},{id:"media",name:"Media",filter:e=>[20,21,22,1063,1222,1244].includes(e.kind)},{id:"git",name:"Git/Code",filter:e=>[818,1337,1617,1618,1619,1621,1622,30617,30618].includes(e.kind)},{id:"calendar",name:"Calendar",filter:e=>[31922,31923,31924,31925].includes(e.kind)},{id:"groups",name:"Groups",filter:e=>e.kind>=9e3&&e.kind<=9030||e.kind>=39e3&&e.kind<=39009}];function gy(e,t,n){const r=e.slice();return r[13]=t[n],r}function my(e,t,n){const r=e.slice();return r[16]=t[n],r}function yy(e){let t,n,i,o,s,a,l,p,y,v,b,E,C,x,B,S,F,Q,R,D,P,T,U,$,N,L=e[3].length+"",O=1!==e[3].length?"s":"",M=py,_=[];for(let t=0;t<M.length;t+=1)_[t]=wy(my(e,M,t));function H(e,t){return 0===e[3].length?Ay:vy}let j=H(e),G=j(e);return{c(){t=h("div"),n=h("div"),i=h("div"),o=h("h2"),o.textContent="Generate Event Template",s=m(),a=h("button"),a.textContent="×",l=m(),p=h("div"),y=h("div"),v=h("input"),b=m(),E=h("div");for(let e=0;e<_.length;e+=1)_[e].c();C=m(),x=h("div"),B=h("div"),G.c(),S=m(),F=h("div"),Q=h("span"),R=g(L),D=g(" event type"),P=g(O),T=m(),U=h("button"),U.textContent="Cancel",A(o,"class","svelte-v55ls1"),A(a,"class","close-btn svelte-v55ls1"),A(i,"class","modal-header svelte-v55ls1"),A(v,"type","text"),A(v,"placeholder","Search by name, description, or kind number..."),A(v,"class","search-input svelte-v55ls1"),A(y,"class","search-box svelte-v55ls1"),A(E,"class","category-tabs svelte-v55ls1"),A(p,"class","modal-filters svelte-v55ls1"),A(B,"class","kinds-list svelte-v55ls1"),A(x,"class","modal-body svelte-v55ls1"),A(Q,"class","result-count svelte-v55ls1"),A(U,"class","cancel-btn svelte-v55ls1"),A(F,"class","modal-footer svelte-v55ls1"),A(n,"class","modal-content svelte-v55ls1"),A(t,"class","modal-backdrop svelte-v55ls1")},m(r,d){u(r,t,d),c(t,n),c(n,i),c(i,o),c(i,s),c(i,a),c(n,l),c(n,p),c(p,y),c(y,v),I(v,e[1]),c(p,b),c(p,E);for(let e=0;e<_.length;e+=1)_[e]&&_[e].m(E,null);c(n,C),c(n,x),c(x,B),G.m(B,null),c(n,S),c(n,F),c(F,Q),c(Q,R),c(Q,D),c(Q,P),c(F,T),c(F,U),$||(N=[w(a,"click",e[5]),w(v,"input",e[9]),w(U,"click",e[5]),w(t,"click",e[7])],$=!0)},p(e,t){if(2&t&&v.value!==e[1]&&I(v,e[1]),4&t){let n;for(M=py,n=0;n<M.length;n+=1){const r=my(e,M,n);_[n]?_[n].p(r,t):(_[n]=wy(r),_[n].c(),_[n].m(E,null))}for(;n<_.length;n+=1)_[n].d(1);_.length=M.length}j===(j=H(e))&&G?G.p(e,t):(G.d(1),G=j(e),G&&(G.c(),G.m(B,null))),8&t&&L!==(L=e[3].length+"")&&k(R,L),8&t&&O!==(O=1!==e[3].length?"s":"")&&k(P,O)},d(e){e&&d(t),f(_,e),G.d(),$=!1,r(N)}}}function wy(e){let t,n,r,i,o,s=e[16].name+"";function a(){return e[10](e[16])}return{c(){t=h("button"),n=g(s),r=m(),A(t,"class","category-tab svelte-v55ls1"),B(t,"active",e[2]===e[16].id)},m(e,s){u(e,t,s),c(t,n),c(t,r),i||(o=w(t,"click",a),i=!0)},p(n,r){e=n,4&r&&B(t,"active",e[2]===e[16].id)},d(e){e&&d(t),i=!1,o()}}}function vy(e){let t,n=e[3],r=[];for(let t=0;t<n.length;t+=1)r[t]=ky(gy(e,n,t));return{c(){for(let e=0;e<r.length;e+=1)r[e].c();t=y()},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,i){if(24&i){let o;for(n=e[3],o=0;o<n.length;o+=1){const s=gy(e,n,o);r[o]?r[o].p(s,i):(r[o]=ky(s),r[o].c(),r[o].m(t.parentNode,t))}for(;o<r.length;o+=1)r[o].d(1);r.length=n.length}},d(e){f(r,e),e&&d(t)}}}function Ay(e){let t,n,r,i;return{c(){t=h("div"),n=g('No event kinds found matching "'),r=g(e[1]),i=g('"'),A(t,"class","no-results svelte-v55ls1")},m(e,o){u(e,t,o),c(t,n),c(t,r),c(t,i)},p(e,t){2&t&&k(r,e[1])},d(e){e&&d(t)}}}function by(e){let t,n,r,i=e[13].nip+"";return{c(){t=h("span"),n=g("NIP-"),r=g(i),A(t,"class","nip-badge svelte-v55ls1")},m(e,i){u(e,t,i),c(t,n),c(t,r)},p(e,t){8&t&&i!==(i=e[13].nip+"")&&k(r,i)},d(e){e&&d(t)}}}function ky(e){let t,n,r,i,o,s,a,l,f,p,y,v,b,I,E,C,x,B,S,F=e[13].kind+"",Q=Cy(e[13])+"",R=e[13].name+"",D=e[13].description+"",P=e[13].nip&&"XX"!==e[13].nip&&by(e);function T(){return e[11](e[13])}return{c(){t=h("button"),n=h("div"),r=h("span"),i=g("Kind "),o=g(F),s=m(),a=h("span"),l=g(Q),p=m(),P&&P.c(),y=m(),v=h("div"),b=g(R),I=m(),E=h("div"),C=g(D),x=m(),A(r,"class","kind-number svelte-v55ls1"),A(a,"class",f="kind-badge "+Ey(e[13])+" svelte-v55ls1"),A(n,"class","kind-header svelte-v55ls1"),A(v,"class","kind-name svelte-v55ls1"),A(E,"class","kind-description svelte-v55ls1"),A(t,"class","kind-item svelte-v55ls1")},m(e,d){u(e,t,d),c(t,n),c(n,r),c(r,i),c(r,o),c(n,s),c(n,a),c(a,l),c(n,p),P&&P.m(n,null),c(t,y),c(t,v),c(v,b),c(t,I),c(t,E),c(E,C),c(t,x),B||(S=w(t,"click",T),B=!0)},p(t,r){e=t,8&r&&F!==(F=e[13].kind+"")&&k(o,F),8&r&&Q!==(Q=Cy(e[13])+"")&&k(l,Q),8&r&&f!==(f="kind-badge "+Ey(e[13])+" svelte-v55ls1")&&A(a,"class",f),e[13].nip&&"XX"!==e[13].nip?P?P.p(e,r):(P=by(e),P.c(),P.m(n,null)):P&&(P.d(1),P=null),8&r&&R!==(R=e[13].name+"")&&k(b,R),8&r&&D!==(D=e[13].description+"")&&k(C,D)},d(e){e&&d(t),P&&P.d(),B=!1,S()}}}function Iy(t){let n,r,i,o=t[0]&&yy(t);return{c(){o&&o.c(),n=y()},m(e,s){o&&o.m(e,s),u(e,n,s),r||(i=w(window,"keydown",t[6]),r=!0)},p(e,[t]){e[0]?o?o.p(e,t):(o=yy(e),o.c(),o.m(n.parentNode,n)):o&&(o.d(1),o=null)},i:e,o:e,d(e){o&&o.d(e),e&&d(n),r=!1,i()}}}function Ey(e){return e.isAddressable?"badge-addressable":e.isReplaceable?"badge-replaceable":e.kind>=2e4&&e.kind<3e4?"badge-ephemeral":"badge-regular"}function Cy(e){return e.isAddressable?"Addressable":e.isReplaceable?"Replaceable":e.kind>=2e4&&e.kind<3e4?"Ephemeral":"Regular"}function xy(e,t,n){let{isOpen:r=!1}=t,{userPubkey:i=""}=t;const o=P();let s="",a="all",l=fy;function c(e){const t=hy(e.kind,i);o("select",{kind:e,template:t}),u()}function u(){n(0,r=!1),n(1,s=""),n(2,a="all"),o("close")}return e.$$set=e=>{"isOpen"in e&&n(0,r=e.isOpen),"userPubkey"in e&&n(8,i=e.userPubkey)},e.$$.update=()=>{if(6&e.$$.dirty){let e=fy;const t=py.find(e=>e.id===a);if(t&&(e=e.filter(t.filter)),s.trim()){const t=s.toLowerCase();e=e.filter(e=>e.name.toLowerCase().includes(t)||e.description.toLowerCase().includes(t)||e.kind.toString().includes(t)||e.nip&&e.nip.includes(t))}n(3,l=e)}},[r,s,a,l,c,u,function(e){"Escape"===e.key&&u()},function(e){e.target===e.currentTarget&&u()},i,function(){s=this.value,n(1,s)},e=>n(2,a=e.id),e=>c(e)]}class By extends oe{constructor(e){super(),ie(this,e,xy,Iy,o,{isOpen:0,userPubkey:8})}}function Sy(e){let t,n,r,i,o,s,a,l,f,p;return{c(){t=h("div"),n=h("div"),r=h("span"),r.textContent="⚠",i=m(),o=h("span"),s=g(e[1]),a=m(),l=h("button"),l.textContent="×",A(r,"class","error-icon svelte-46pmgb"),A(o,"class","error-message svelte-46pmgb"),A(n,"class","error-content svelte-46pmgb"),A(l,"class","error-dismiss svelte-46pmgb"),A(t,"class","error-banner svelte-46pmgb")},m(d,h){u(d,t,h),c(t,n),c(n,r),c(n,i),c(n,o),c(o,s),c(t,a),c(t,l),f||(p=w(l,"click",e[10]),f=!0)},p(e,t){2&t&&k(s,e[1])},d(e){e&&d(t),f=!1,p()}}}function Fy(e){let t,n,i,o,s,a,l,f,p,g,y,v,b,k,E,C,x,B,S,F=e[1]&&Sy(e);function Q(t){e[14](t)}let R={userPubkey:e[2]};return void 0!==e[3]&&(R.isOpen=e[3]),E=new By({props:R}),$.push(()=>X(E,"isOpen",Q)),E.$on("select",e[8]),E.$on("close",e[9]),{c(){t=h("div"),n=h("div"),i=h("button"),i.textContent="Generate Template",o=m(),s=h("button"),s.textContent="Reformat",a=m(),l=h("button"),l.textContent="Sign",f=m(),p=h("button"),p.textContent="Publish",g=m(),F&&F.c(),y=m(),v=h("div"),b=h("textarea"),k=m(),ee(E.$$.fragment),A(i,"class","compose-btn template-btn svelte-46pmgb"),A(s,"class","compose-btn reformat-btn svelte-46pmgb"),A(l,"class","compose-btn sign-btn svelte-46pmgb"),A(p,"class","compose-btn publish-btn svelte-46pmgb"),A(n,"class","compose-header svelte-46pmgb"),A(b,"class","compose-textarea svelte-46pmgb"),A(b,"placeholder","Enter your Nostr event JSON here, or click 'Generate Template' to start with a template..."),A(b,"spellcheck","false"),A(v,"class","compose-editor svelte-46pmgb"),A(t,"class","compose-view svelte-46pmgb")},m(r,d){u(r,t,d),c(t,n),c(n,i),c(n,o),c(n,s),c(n,a),c(n,l),c(n,f),c(n,p),c(t,g),F&&F.m(t,null),c(t,y),c(t,v),c(v,b),I(b,e[0]),u(r,k,d),te(E,r,d),x=!0,B||(S=[w(i,"click",e[7]),w(s,"click",e[4]),w(l,"click",e[5]),w(p,"click",e[6]),w(b,"input",e[13])],B=!0)},p(e,[n]){e[1]?F?F.p(e,n):(F=Sy(e),F.c(),F.m(t,y)):F&&(F.d(1),F=null),1&n&&I(b,e[0]);const r={};4&n&&(r.userPubkey=e[2]),!C&&8&n&&(C=!0,r.isOpen=e[3],H(()=>C=!1)),E.$set(r)},i(e){x||(W(E.$$.fragment,e),x=!0)},o(e){Z(E.$$.fragment,e),x=!1},d(e){e&&d(t),F&&F.d(),e&&d(k),ne(E,e),B=!1,r(S)}}}function Qy(e,t,n){let{composeEventJson:r=""}=t,{userPubkey:i=""}=t,{userRole:o=""}=t,{policyEnabled:s=!1}=t,{publishError:a=""}=t;const l=P();let c=!1;return e.$$set=e=>{"composeEventJson"in e&&n(0,r=e.composeEventJson),"userPubkey"in e&&n(2,i=e.userPubkey),"userRole"in e&&n(11,o=e.userRole),"policyEnabled"in e&&n(12,s=e.policyEnabled),"publishError"in e&&n(1,a=e.publishError)},[r,a,i,c,function(){l("reformatJson")},function(){l("signEvent")},function(){l("publishEvent")},function(){n(3,c=!0)},function(e){const{kind:t,template:i}=e.detail;n(0,r=JSON.stringify(i,null,2)),l("templateSelected",{kind:t,template:i})},function(){n(3,c=!1)},function(){n(1,a=""),l("clearError")},o,s,function(){r=this.value,n(0,r)},function(e){c=e,n(3,c)}]}class Ry extends oe{constructor(e){super(),ie(this,e,Qy,Fy,o,{composeEventJson:0,userPubkey:2,userRole:11,policyEnabled:12,publishError:1})}}function Dy(e,t,n){const r=e.slice();return r[23]=t[n],r}function Py(t){let n,r,i,o,s,a;return{c(){n=h("div"),r=h("p"),r.textContent="Please log in to access sprocket management.",i=m(),o=h("button"),o.textContent="Log In",A(r,"class","svelte-fiaj1r"),A(o,"class","login-btn svelte-fiaj1r"),A(n,"class","login-prompt svelte-fiaj1r")},m(e,l){u(e,n,l),c(n,r),c(n,i),c(n,o),s||(a=w(o,"click",t[18]),s=!0)},p:e,d(e){e&&d(n),s=!1,a()}}}function Ty(e){let t,n,r,i,o,s,a,l,f,p=(e[2]||"none")+"";return{c(){t=h("div"),n=h("p"),n.textContent="❌ Owner permission required for sprocket management.",r=m(),i=h("p"),i.innerHTML='To enable sprocket functionality, set the <code class="svelte-fiaj1r">ORLY_OWNERS</code> environment variable with your npub when starting the relay.',o=m(),s=h("p"),a=g("Current user role: "),l=h("strong"),f=g(p),A(n,"class","svelte-fiaj1r"),A(i,"class","svelte-fiaj1r"),A(s,"class","svelte-fiaj1r"),A(t,"class","permission-denied svelte-fiaj1r")},m(e,d){u(e,t,d),c(t,n),c(t,r),c(t,i),c(t,o),c(t,s),c(s,a),c(s,l),c(l,f)},p(e,t){4&t&&p!==(p=(e[2]||"none")+"")&&k(f,p)},d(e){e&&d(t)}}}function Uy(e){let t,n,i,o,s,a,l,p,y,v,b,E,C,x,S,F,Q,R,D,P,T,U,$,N,L,O,M,_,H,j,G,K,J,V,q,z,Y,W,Z,X,ee,te,ne,re,ie,oe,se,ae,le,ce,ue,de,fe,he,pe,ge,me=e[3]?.is_running?"🟢 Running":"🔴 Stopped",ye=e[3]?.script_exists?"✅ Exists":"❌ Not found",we=e[3]?.pid&&$y(e),ve=e[6]&&Ny(e),Ae=e[8],be=[];for(let t=0;t<Ae.length;t+=1)be[t]=My(Dy(e,Ae,t));return{c(){t=h("div"),n=h("div"),i=h("h3"),i.textContent="Script Editor",o=m(),s=h("div"),a=h("button"),l=g("🔄 Restart"),p=m(),y=h("button"),v=g("🗑️ Delete Script"),E=m(),C=h("div"),x=h("h4"),x.textContent="Upload Script",S=m(),F=h("div"),Q=h("input"),R=m(),D=h("button"),P=g("📤 Upload & Update"),U=m(),$=h("div"),N=h("div"),L=h("span"),L.textContent="Status:",O=m(),M=h("span"),_=g(me),H=m(),we&&we.c(),j=m(),G=h("div"),K=h("span"),K.textContent="Script:",J=m(),V=h("span"),q=g(ye),z=m(),Y=h("div"),W=h("textarea"),Z=m(),X=h("div"),ee=h("button"),te=g("💾 Save & Update"),ne=m(),re=h("button"),ie=g("📥 Load Current"),oe=m(),ve&&ve.c(),se=m(),ae=h("div"),le=h("h3"),le.textContent="Script Versions",ce=m(),ue=h("div");for(let e=0;e<be.length;e+=1)be[e].c();de=m(),fe=h("button"),he=g("🔄 Refresh Versions"),A(i,"class","svelte-fiaj1r"),A(a,"class","sprocket-btn restart-btn svelte-fiaj1r"),a.disabled=e[4],A(y,"class","sprocket-btn delete-btn svelte-fiaj1r"),y.disabled=b=e[4]||!e[3]?.script_exists,A(s,"class","sprocket-controls svelte-fiaj1r"),A(n,"class","sprocket-header svelte-fiaj1r"),A(x,"class","svelte-fiaj1r"),A(Q,"type","file"),A(Q,"id","sprocket-upload-file"),A(Q,"accept",".sh,.bash"),Q.disabled=e[4],A(Q,"class","svelte-fiaj1r"),A(D,"class","sprocket-btn upload-btn svelte-fiaj1r"),D.disabled=T=e[4]||!e[5],A(F,"class","upload-controls svelte-fiaj1r"),A(C,"class","sprocket-upload-section svelte-fiaj1r"),A(L,"class","status-label svelte-fiaj1r"),A(M,"class","status-value svelte-fiaj1r"),B(M,"running",e[3]?.is_running),A(N,"class","status-item svelte-fiaj1r"),A(K,"class","status-label svelte-fiaj1r"),A(V,"class","status-value svelte-fiaj1r"),A(G,"class","status-item svelte-fiaj1r"),A($,"class","sprocket-status svelte-fiaj1r"),A(W,"class","script-editor svelte-fiaj1r"),A(W,"placeholder","#!/bin/bash # Enter your sprocket script here..."),W.disabled=e[4],A(Y,"class","script-editor-container svelte-fiaj1r"),A(ee,"class","sprocket-btn save-btn svelte-fiaj1r"),ee.disabled=e[4],A(re,"class","sprocket-btn load-btn svelte-fiaj1r"),re.disabled=e[4],A(X,"class","script-actions svelte-fiaj1r"),A(t,"class","sprocket-section svelte-fiaj1r"),A(ue,"class","versions-list svelte-fiaj1r"),A(fe,"class","sprocket-btn refresh-btn svelte-fiaj1r"),fe.disabled=e[4],A(ae,"class","sprocket-section svelte-fiaj1r")},m(r,d){u(r,t,d),c(t,n),c(n,i),c(n,o),c(n,s),c(s,a),c(a,l),c(s,p),c(s,y),c(y,v),c(t,E),c(t,C),c(C,x),c(C,S),c(C,F),c(F,Q),c(F,R),c(F,D),c(D,P),c(t,U),c(t,$),c($,N),c(N,L),c(N,O),c(N,M),c(M,_),c($,H),we&&we.m($,null),c($,j),c($,G),c(G,K),c(G,J),c(G,V),c(V,q),c(t,z),c(t,Y),c(Y,W),I(W,e[0]),c(t,Z),c(t,X),c(X,ee),c(ee,te),c(X,ne),c(X,re),c(re,ie),c(t,oe),ve&&ve.m(t,null),u(r,se,d),u(r,ae,d),c(ae,le),c(ae,ce),c(ae,ue);for(let e=0;e<be.length;e+=1)be[e]&&be[e].m(ue,null);c(ae,de),c(ae,fe),c(fe,he),pe||(ge=[w(a,"click",e[9]),w(y,"click",e[10]),w(Q,"change",e[11]),w(D,"click",e[12]),w(W,"input",e[19]),w(ee,"click",e[13]),w(re,"click",e[14]),w(fe,"click",e[15])],pe=!0)},p(e,n){if(16&n&&(a.disabled=e[4]),24&n&&b!==(b=e[4]||!e[3]?.script_exists)&&(y.disabled=b),16&n&&(Q.disabled=e[4]),48&n&&T!==(T=e[4]||!e[5])&&(D.disabled=T),8&n&&me!==(me=e[3]?.is_running?"🟢 Running":"🔴 Stopped")&&k(_,me),8&n&&B(M,"running",e[3]?.is_running),e[3]?.pid?we?we.p(e,n):(we=$y(e),we.c(),we.m($,j)):we&&(we.d(1),we=null),8&n&&ye!==(ye=e[3]?.script_exists?"✅ Exists":"❌ Not found")&&k(q,ye),16&n&&(W.disabled=e[4]),1&n&&I(W,e[0]),16&n&&(ee.disabled=e[4]),16&n&&(re.disabled=e[4]),e[6]?ve?ve.p(e,n):(ve=Ny(e),ve.c(),ve.m(t,null)):ve&&(ve.d(1),ve=null),196880&n){let t;for(Ae=e[8],t=0;t<Ae.length;t+=1){const r=Dy(e,Ae,t);be[t]?be[t].p(r,n):(be[t]=My(r),be[t].c(),be[t].m(ue,null))}for(;t<be.length;t+=1)be[t].d(1);be.length=Ae.length}16&n&&(fe.disabled=e[4])},d(e){e&&d(t),we&&we.d(),ve&&ve.d(),e&&d(se),e&&d(ae),f(be,e),pe=!1,r(ge)}}}function $y(e){let t,n,r,i,o,s=e[3].pid+"";return{c(){t=h("div"),n=h("span"),n.textContent="PID:",r=m(),i=h("span"),o=g(s),A(n,"class","status-label svelte-fiaj1r"),A(i,"class","status-value svelte-fiaj1r"),A(t,"class","status-item svelte-fiaj1r")},m(e,s){u(e,t,s),c(t,n),c(t,r),c(t,i),c(i,o)},p(e,t){8&t&&s!==(s=e[3].pid+"")&&k(o,s)},d(e){e&&d(t)}}}function Ny(e){let t,n;return{c(){t=h("div"),n=g(e[6]),A(t,"class","sprocket-message svelte-fiaj1r"),B(t,"error","error"===e[7])},m(e,r){u(e,t,r),c(t,n)},p(e,r){64&r&&k(n,e[6]),128&r&&B(t,"error","error"===e[7])},d(e){e&&d(t)}}}function Ly(e){let t;return{c(){t=h("span"),t.textContent="Current",A(t,"class","current-badge svelte-fiaj1r")},m(e,n){u(e,t,n)},d(e){e&&d(t)}}}function Oy(e){let t,n,r,i;function o(){return e[21](e[23])}return{c(){t=h("button"),n=g("🗑️ Delete"),A(t,"class","version-btn delete-btn svelte-fiaj1r"),t.disabled=e[4]},m(e,s){u(e,t,s),c(t,n),r||(i=w(t,"click",o),r=!0)},p(n,r){e=n,16&r&&(t.disabled=e[4])},d(e){e&&d(t),r=!1,i()}}}function My(e){let t,n,r,i,o,s,a,l,f,p,y,v,b,I,E,C,x=e[23].name+"",S=new Date(e[23].modified).toLocaleString()+"",F=e[23].is_current&&Ly();function Q(){return e[20](e[23])}let R=!e[23].is_current&&Oy(e);return{c(){t=h("div"),n=h("div"),r=h("div"),i=g(x),o=m(),s=h("div"),a=g(S),l=m(),F&&F.c(),f=m(),p=h("div"),y=h("button"),v=g("📥 Load"),b=m(),R&&R.c(),I=m(),A(r,"class","version-name svelte-fiaj1r"),A(s,"class","version-date svelte-fiaj1r"),A(n,"class","version-info svelte-fiaj1r"),A(y,"class","version-btn load-btn svelte-fiaj1r"),y.disabled=e[4],A(p,"class","version-actions svelte-fiaj1r"),A(t,"class","version-item svelte-fiaj1r"),B(t,"current",e[23].is_current)},m(e,d){u(e,t,d),c(t,n),c(n,r),c(r,i),c(n,o),c(n,s),c(s,a),c(s,l),F&&F.m(s,null),c(t,f),c(t,p),c(p,y),c(y,v),c(p,b),R&&R.m(p,null),c(t,I),E||(C=w(y,"click",Q),E=!0)},p(n,r){e=n,256&r&&x!==(x=e[23].name+"")&&k(i,x),256&r&&S!==(S=new Date(e[23].modified).toLocaleString()+"")&&k(a,S),e[23].is_current?F||(F=Ly(),F.c(),F.m(s,null)):F&&(F.d(1),F=null),16&r&&(y.disabled=e[4]),e[23].is_current?R&&(R.d(1),R=null):R?R.p(e,r):(R=Oy(e),R.c(),R.m(p,null)),256&r&&B(t,"current",e[23].is_current)},d(e){e&&d(t),F&&F.d(),R&&R.d(),E=!1,C()}}}function _y(t){let n,r,i;function o(e,t){return e[1]&&"owner"===e[2]?Uy:e[1]?Ty:Py}let s=o(t),a=s(t);return{c(){n=h("div"),r=h("h2"),r.textContent="Sprocket Script Management",i=m(),a.c(),A(r,"class","svelte-fiaj1r"),A(n,"class","sprocket-view svelte-fiaj1r")},m(e,t){u(e,n,t),c(n,r),c(n,i),a.m(n,null)},p(e,[t]){s===(s=o(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 Hy(e,t,n){let{isLoggedIn:r=!1}=t,{userRole:i=""}=t,{sprocketStatus:o=null}=t,{isLoadingSprocket:s=!1}=t,{sprocketUploadFile:a=null}=t,{sprocketScript:l=""}=t,{sprocketMessage:c=""}=t,{sprocketMessageType:u=""}=t,{sprocketVersions:d=[]}=t;const f=P();function h(e){f("loadVersion",e)}function p(e){f("deleteVersion",e)}return e.$$set=e=>{"isLoggedIn"in e&&n(1,r=e.isLoggedIn),"userRole"in e&&n(2,i=e.userRole),"sprocketStatus"in e&&n(3,o=e.sprocketStatus),"isLoadingSprocket"in e&&n(4,s=e.isLoadingSprocket),"sprocketUploadFile"in e&&n(5,a=e.sprocketUploadFile),"sprocketScript"in e&&n(0,l=e.sprocketScript),"sprocketMessage"in e&&n(6,c=e.sprocketMessage),"sprocketMessageType"in e&&n(7,u=e.sprocketMessageType),"sprocketVersions"in e&&n(8,d=e.sprocketVersions)},[l,r,i,o,s,a,c,u,d,function(){f("restartSprocket")},function(){f("deleteSprocket")},function(e){f("sprocketFileSelect",e)},function(){f("uploadSprocketScript")},function(){f("saveSprocket")},function(){f("loadSprocket")},function(){f("loadVersions")},h,p,function(){f("openLoginModal")},function(){l=this.value,n(0,l)},e=>h(e),e=>p(e.name)]}class jy extends oe{constructor(e){super(),ie(this,e,Hy,_y,o,{isLoggedIn:1,userRole:2,sprocketStatus:3,isLoadingSprocket:4,sprocketUploadFile:5,sprocketScript:0,sprocketMessage:6,sprocketMessageType:7,sprocketVersions:8})}}function Gy(e,t,n){const r=e.slice();return r[26]=t[n],r}function Ky(e,t,n){const r=e.slice();return r[29]=t[n],r}function Jy(e,t,n){const r=e.slice();return r[32]=t[n],r}function Vy(t){let n,r,i,o,s,a;return{c(){n=h("div"),r=h("p"),r.textContent="Please log in to access policy configuration.",i=m(),o=h("button"),o.textContent="Log In",A(r,"class","svelte-gkxvxc"),A(o,"class","login-btn svelte-gkxvxc"),A(n,"class","login-prompt svelte-gkxvxc")},m(e,l){u(e,n,l),c(n,r),c(n,i),c(n,o),s||(a=w(o,"click",t[16]),s=!0)},p:e,d(e){e&&d(n),s=!1,a()}}}function qy(e){let t,n,r,i,o,s,a,l,f,p=(e[3]||"none")+"";return{c(){t=h("div"),n=h("p"),n.textContent="Policy configuration requires owner or policy admin permissions.",r=m(),i=h("p"),i.innerHTML='To become a policy admin, ask an existing policy admin to add your pubkey\n to the <code class="svelte-gkxvxc">policy_admins</code> list.',o=m(),s=h("p"),a=g("Current user role: "),l=h("strong"),f=g(p),A(n,"class","svelte-gkxvxc"),A(i,"class","svelte-gkxvxc"),A(s,"class","svelte-gkxvxc"),A(t,"class","permission-denied svelte-gkxvxc")},m(e,d){u(e,t,d),c(t,n),c(t,r),c(t,i),c(t,o),c(t,s),c(s,a),c(s,l),c(l,f)},p(e,t){8&t[0]&&p!==(p=(e[3]||"none")+"")&&k(f,p)},d(e){e&&d(t)}}}function zy(e){let t,n,i,o,s,a,l,f,p,y,v,b,E,C,x,S,F,Q,R,D,P,T,U,$,N,L,O,M,_,H,j,G,K,J,V,q,z,Y,W,Z,X,ee,te,ne,re,ie,oe,se,ae,le,ce,ue,de,fe,he,pe,ge,me,ye,we,ve,Ae,be,ke,Ie,Ee,Ce,xe,Be,Se,Fe,Qe,Re,De,Pe,Te=e[5]?"Policy Enabled":"Policy Disabled",Ue=e[10].length+"",$e=e[4]&&Yy(),Ne=e[9].length>0&&Wy(e),Le=e[7]&&Xy(e);function Oe(e,t){return 0===e[1].length?tw:ew}let Me=Oe(e),_e=Me(e);function He(e,t){return 0===e[10].length?iw:rw}let je=He(e),Ge=je(e);return{c(){t=h("div"),n=h("div"),i=h("h3"),i.textContent="Policy Editor",o=m(),s=h("div"),a=h("span"),l=g(Te),f=m(),$e&&$e.c(),p=m(),y=h("div"),y.innerHTML='<p class="svelte-gkxvxc">Edit the policy JSON below and click &quot;Save &amp; Publish&quot; to update the relay&#39;s policy configuration.\n Changes are applied immediately after validation.</p> \n <p class="info-note svelte-gkxvxc">Policy updates are published as kind 12345 events and require policy admin permissions.</p>',v=m(),b=h("div"),E=h("textarea"),C=m(),Ne&&Ne.c(),x=m(),S=h("div"),F=h("button"),Q=g("Load Current"),R=m(),D=h("button"),P=g("Format JSON"),T=m(),U=h("button"),$=g("Validate"),N=m(),L=h("button"),O=g("Save & Publish"),M=m(),Le&&Le.c(),_=m(),H=h("div"),j=h("h3"),j.textContent="Policy Administrators",G=m(),K=h("div"),K.innerHTML='<p class="svelte-gkxvxc">Policy admins can update the relay&#39;s policy configuration via kind 12345 events.\n Their follows get whitelisted if <code>policy_follow_whitelist_enabled</code> is true in the policy.</p> \n <p class="info-note svelte-gkxvxc"><strong>Note:</strong> Policy admins are separate from relay admins (ORLY_ADMINS).\n Changes here update the JSON editor - click &quot;Save &amp; Publish&quot; to apply.</p>',J=m(),V=h("div"),_e.c(),q=m(),z=h("div"),Y=h("input"),W=m(),Z=h("button"),X=g("+ Add Admin"),te=m(),ne=h("div"),re=h("h3"),re.textContent="Policy Follow Whitelist",ie=m(),oe=h("div"),oe.innerHTML='<p class="svelte-gkxvxc">Pubkeys followed by policy admins (kind 3 events).\n These get automatic read+write access when rules have <code>write_allow_follows: true</code>.</p>',se=m(),ae=h("div"),le=h("span"),ce=g(Ue),ue=g(" pubkey(s) in whitelist"),de=m(),fe=h("button"),he=g("🔄 Refresh Follows"),pe=m(),ge=h("div"),Ge.c(),me=m(),ye=h("div"),we=h("h3"),we.textContent="Policy Reference",ve=m(),Ae=h("div"),be=h("h4"),be.textContent="Structure Overview",ke=m(),Ie=h("ul"),Ie.innerHTML='<li class="svelte-gkxvxc"><code class="svelte-gkxvxc">kind.whitelist</code> - Only allow these event kinds (takes precedence)</li> \n <li class="svelte-gkxvxc"><code class="svelte-gkxvxc">kind.blacklist</code> - Deny these event kinds (if no whitelist)</li> \n <li class="svelte-gkxvxc"><code class="svelte-gkxvxc">global</code> - Rules applied to all events</li> \n <li class="svelte-gkxvxc"><code class="svelte-gkxvxc">rules</code> - Per-kind rules (keyed by kind number as string)</li> \n <li class="svelte-gkxvxc"><code class="svelte-gkxvxc">default_policy</code> - &quot;allow&quot; or &quot;deny&quot; when no rules match</li> \n <li class="svelte-gkxvxc"><code class="svelte-gkxvxc">policy_admins</code> - Hex pubkeys that can update policy</li> \n <li class="svelte-gkxvxc"><code class="svelte-gkxvxc">policy_follow_whitelist_enabled</code> - Enable follow-based access</li>',Ee=m(),Ce=h("h4"),Ce.textContent="Rule Fields",xe=m(),Be=h("ul"),Be.innerHTML='<li class="svelte-gkxvxc"><code class="svelte-gkxvxc">description</code> - Human-readable rule description</li> \n <li class="svelte-gkxvxc"><code class="svelte-gkxvxc">write_allow</code> / <code class="svelte-gkxvxc">write_deny</code> - Pubkey lists for write access</li> \n <li class="svelte-gkxvxc"><code class="svelte-gkxvxc">read_allow</code> / <code class="svelte-gkxvxc">read_deny</code> - Pubkey lists for read access</li> \n <li class="svelte-gkxvxc"><code class="svelte-gkxvxc">write_allow_follows</code> - Grant access to policy admin follows</li> \n <li class="svelte-gkxvxc"><code class="svelte-gkxvxc">size_limit</code> - Max total event size in bytes</li> \n <li class="svelte-gkxvxc"><code class="svelte-gkxvxc">content_limit</code> - Max content field size in bytes</li> \n <li class="svelte-gkxvxc"><code class="svelte-gkxvxc">max_expiry</code> - Max expiry offset in seconds</li> \n <li class="svelte-gkxvxc"><code class="svelte-gkxvxc">max_age_of_event</code> - Max age of created_at in seconds</li> \n <li class="svelte-gkxvxc"><code class="svelte-gkxvxc">max_age_event_in_future</code> - Max future offset in seconds</li> \n <li class="svelte-gkxvxc"><code class="svelte-gkxvxc">must_have_tags</code> - Required tag letters (e.g., [&quot;d&quot;, &quot;t&quot;])</li> \n <li class="svelte-gkxvxc"><code class="svelte-gkxvxc">tag_validation</code> - Regex patterns for tag values</li> \n <li class="svelte-gkxvxc"><code class="svelte-gkxvxc">script</code> - Path to external validation script</li>',Se=m(),Fe=h("h4"),Fe.textContent="Example Policy",Qe=m(),Re=h("pre"),Re.textContent=`${e[20]}`,A(i,"class","svelte-gkxvxc"),A(a,"class","status-badge svelte-gkxvxc"),B(a,"enabled",e[5]),A(s,"class","policy-status svelte-gkxvxc"),A(n,"class","policy-header svelte-gkxvxc"),A(y,"class","policy-info svelte-gkxvxc"),A(E,"class","policy-editor svelte-gkxvxc"),A(E,"placeholder","Loading policy configuration..."),E.disabled=e[6],A(E,"spellcheck","false"),A(b,"class","editor-container svelte-gkxvxc"),A(F,"class","policy-btn load-btn svelte-gkxvxc"),F.disabled=e[6],A(D,"class","policy-btn format-btn svelte-gkxvxc"),D.disabled=e[6],A(U,"class","policy-btn validate-btn svelte-gkxvxc"),U.disabled=e[6],A(L,"class","policy-btn save-btn svelte-gkxvxc"),L.disabled=e[6],A(S,"class","policy-actions svelte-gkxvxc"),A(t,"class","policy-section svelte-gkxvxc"),A(K,"class","policy-info svelte-gkxvxc"),A(V,"class","admin-list svelte-gkxvxc"),A(Y,"type","text"),A(Y,"placeholder","npub or hex pubkey"),Y.disabled=e[6],A(Y,"class","svelte-gkxvxc"),A(Z,"class","policy-btn add-btn svelte-gkxvxc"),Z.disabled=ee=e[6]||!e[11].trim(),A(z,"class","add-admin svelte-gkxvxc"),A(H,"class","policy-section svelte-gkxvxc"),A(oe,"class","policy-info svelte-gkxvxc"),A(le,"class","follows-count svelte-gkxvxc"),A(fe,"class","policy-btn refresh-btn svelte-gkxvxc"),fe.disabled=e[6],A(ae,"class","follows-header svelte-gkxvxc"),A(ge,"class","follows-list svelte-gkxvxc"),A(ne,"class","policy-section svelte-gkxvxc"),A(be,"class","svelte-gkxvxc"),A(Ie,"class","field-list svelte-gkxvxc"),A(Ce,"class","svelte-gkxvxc"),A(Be,"class","field-list svelte-gkxvxc"),A(Fe,"class","svelte-gkxvxc"),A(Re,"class","example-json svelte-gkxvxc"),A(Ae,"class","reference-content svelte-gkxvxc"),A(ye,"class","policy-section svelte-gkxvxc")},m(r,d){u(r,t,d),c(t,n),c(n,i),c(n,o),c(n,s),c(s,a),c(a,l),c(s,f),$e&&$e.m(s,null),c(t,p),c(t,y),c(t,v),c(t,b),c(b,E),I(E,e[0]),c(t,C),Ne&&Ne.m(t,null),c(t,x),c(t,S),c(S,F),c(F,Q),c(S,R),c(S,D),c(D,P),c(S,T),c(S,U),c(U,$),c(S,N),c(S,L),c(L,O),c(t,M),Le&&Le.m(t,null),u(r,_,d),u(r,H,d),c(H,j),c(H,G),c(H,K),c(H,J),c(H,V),_e.m(V,null),c(H,q),c(H,z),c(z,Y),I(Y,e[11]),c(z,W),c(z,Z),c(Z,X),u(r,te,d),u(r,ne,d),c(ne,re),c(ne,ie),c(ne,oe),c(ne,se),c(ne,ae),c(ae,le),c(le,ce),c(le,ue),c(ae,de),c(ae,fe),c(fe,he),c(ne,pe),c(ne,ge),Ge.m(ge,null),u(r,me,d),u(r,ye,d),c(ye,we),c(ye,ve),c(ye,Ae),c(Ae,be),c(Ae,ke),c(Ae,Ie),c(Ae,Ee),c(Ae,Ce),c(Ae,xe),c(Ae,Be),c(Ae,Se),c(Ae,Fe),c(Ae,Qe),c(Ae,Re),De||(Pe=[w(E,"input",e[21]),w(F,"click",e[12]),w(D,"click",e[15]),w(U,"click",e[13]),w(L,"click",e[14]),w(Y,"input",e[23]),w(Y,"keydown",e[24]),w(Z,"click",e[18]),w(fe,"click",e[17])],De=!0)},p(e,n){32&n[0]&&Te!==(Te=e[5]?"Policy Enabled":"Policy Disabled")&&k(l,Te),32&n[0]&&B(a,"enabled",e[5]),e[4]?$e||($e=Yy(),$e.c(),$e.m(s,null)):$e&&($e.d(1),$e=null),64&n[0]&&(E.disabled=e[6]),1&n[0]&&I(E,e[0]),e[9].length>0?Ne?Ne.p(e,n):(Ne=Wy(e),Ne.c(),Ne.m(t,x)):Ne&&(Ne.d(1),Ne=null),64&n[0]&&(F.disabled=e[6]),64&n[0]&&(D.disabled=e[6]),64&n[0]&&(U.disabled=e[6]),64&n[0]&&(L.disabled=e[6]),e[7]?Le?Le.p(e,n):(Le=Xy(e),Le.c(),Le.m(t,null)):Le&&(Le.d(1),Le=null),Me===(Me=Oe(e))&&_e?_e.p(e,n):(_e.d(1),_e=Me(e),_e&&(_e.c(),_e.m(V,null))),64&n[0]&&(Y.disabled=e[6]),2048&n[0]&&Y.value!==e[11]&&I(Y,e[11]),2112&n[0]&&ee!==(ee=e[6]||!e[11].trim())&&(Z.disabled=ee),1024&n[0]&&Ue!==(Ue=e[10].length+"")&&k(ce,Ue),64&n[0]&&(fe.disabled=e[6]),je===(je=He(e))&&Ge?Ge.p(e,n):(Ge.d(1),Ge=je(e),Ge&&(Ge.c(),Ge.m(ge,null)))},d(e){e&&d(t),$e&&$e.d(),Ne&&Ne.d(),Le&&Le.d(),e&&d(_),e&&d(H),_e.d(),e&&d(te),e&&d(ne),Ge.d(),e&&d(me),e&&d(ye),De=!1,r(Pe)}}}function Yy(e){let t;return{c(){t=h("span"),t.textContent="Policy Admin",A(t,"class","admin-badge svelte-gkxvxc")},m(e,n){u(e,t,n)},d(e){e&&d(t)}}}function Wy(e){let t,n,r,i,o=e[9],s=[];for(let t=0;t<o.length;t+=1)s[t]=Zy(Jy(e,o,t));return{c(){t=h("div"),n=h("h4"),n.textContent="Validation Errors:",r=m(),i=h("ul");for(let e=0;e<s.length;e+=1)s[e].c();A(n,"class","svelte-gkxvxc"),A(i,"class","svelte-gkxvxc"),A(t,"class","validation-errors svelte-gkxvxc")},m(e,o){u(e,t,o),c(t,n),c(t,r),c(t,i);for(let e=0;e<s.length;e+=1)s[e]&&s[e].m(i,null)},p(e,t){if(512&t[0]){let n;for(o=e[9],n=0;n<o.length;n+=1){const r=Jy(e,o,n);s[n]?s[n].p(r,t):(s[n]=Zy(r),s[n].c(),s[n].m(i,null))}for(;n<s.length;n+=1)s[n].d(1);s.length=o.length}},d(e){e&&d(t),f(s,e)}}}function Zy(e){let t,n,r=e[32]+"";return{c(){t=h("li"),n=g(r),A(t,"class","svelte-gkxvxc")},m(e,r){u(e,t,r),c(t,n)},p(e,t){512&t[0]&&r!==(r=e[32]+"")&&k(n,r)},d(e){e&&d(t)}}}function Xy(e){let t,n;return{c(){t=h("div"),n=g(e[7]),A(t,"class","policy-message svelte-gkxvxc"),B(t,"error","error"===e[8]),B(t,"success","success"===e[8])},m(e,r){u(e,t,r),c(t,n)},p(e,r){128&r[0]&&k(n,e[7]),256&r[0]&&B(t,"error","error"===e[8]),256&r[0]&&B(t,"success","success"===e[8])},d(e){e&&d(t)}}}function ew(e){let t,n=e[1],r=[];for(let t=0;t<n.length;t+=1)r[t]=nw(Ky(e,n,t));return{c(){for(let e=0;e<r.length;e+=1)r[e].c();t=y()},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,i){if(524354&i[0]){let o;for(n=e[1],o=0;o<n.length;o+=1){const s=Ky(e,n,o);r[o]?r[o].p(s,i):(r[o]=nw(s),r[o].c(),r[o].m(t.parentNode,t))}for(;o<r.length;o+=1)r[o].d(1);r.length=n.length}},d(e){f(r,e),e&&d(t)}}}function tw(t){let n;return{c(){n=h("p"),n.textContent="No policy admins configured",A(n,"class","no-items svelte-gkxvxc")},m(e,t){u(e,n,t)},p:e,d(e){e&&d(n)}}}function nw(e){let t,n,r,i,o,s,a,l,f,p,y,v,b=e[29].substring(0,16)+"",I=e[29].substring(e[29].length-8)+"";function E(){return e[22](e[29])}return{c(){t=h("div"),n=h("span"),r=g(b),i=g("..."),o=g(I),a=m(),l=h("button"),f=g("✕"),p=m(),A(n,"class","admin-pubkey svelte-gkxvxc"),A(n,"title",s=e[29]),A(l,"class","remove-btn svelte-gkxvxc"),l.disabled=e[6],A(l,"title","Remove admin"),A(t,"class","admin-item svelte-gkxvxc")},m(e,s){u(e,t,s),c(t,n),c(n,r),c(n,i),c(n,o),c(t,a),c(t,l),c(l,f),c(t,p),y||(v=w(l,"click",E),y=!0)},p(t,i){e=t,2&i[0]&&b!==(b=e[29].substring(0,16)+"")&&k(r,b),2&i[0]&&I!==(I=e[29].substring(e[29].length-8)+"")&&k(o,I),2&i[0]&&s!==(s=e[29])&&A(n,"title",s),64&i[0]&&(l.disabled=e[6])},d(e){e&&d(t),y=!1,v()}}}function rw(e){let t,n=e[10],r=[];for(let t=0;t<n.length;t+=1)r[t]=ow(Gy(e,n,t));return{c(){t=h("div");for(let e=0;e<r.length;e+=1)r[e].c();A(t,"class","follows-grid svelte-gkxvxc")},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,i){if(1024&i[0]){let o;for(n=e[10],o=0;o<n.length;o+=1){const s=Gy(e,n,o);r[o]?r[o].p(s,i):(r[o]=ow(s),r[o].c(),r[o].m(t,null))}for(;o<r.length;o+=1)r[o].d(1);r.length=n.length}},d(e){e&&d(t),f(r,e)}}}function iw(t){let n;return{c(){n=h("p"),n.textContent='No follows loaded. Click "Refresh Follows" to load from database.',A(n,"class","no-items svelte-gkxvxc")},m(e,t){u(e,n,t)},p:e,d(e){e&&d(n)}}}function ow(e){let t,n,r,i,o,s,a=e[26].substring(0,12)+"",l=e[26].substring(e[26].length-6)+"";return{c(){t=h("div"),n=g(a),r=g("..."),i=g(l),o=m(),A(t,"class","follow-item svelte-gkxvxc"),A(t,"title",s=e[26])},m(e,s){u(e,t,s),c(t,n),c(t,r),c(t,i),c(t,o)},p(e,r){1024&r[0]&&a!==(a=e[26].substring(0,12)+"")&&k(n,a),1024&r[0]&&l!==(l=e[26].substring(e[26].length-6)+"")&&k(i,l),1024&r[0]&&s!==(s=e[26])&&A(t,"title",s)},d(e){e&&d(t)}}}function sw(t){let n,r,i;function o(e,t){return e[2]&&("owner"===e[3]||e[4])?zy:e[2]?qy:Vy}let s=o(t),a=s(t);return{c(){n=h("div"),r=h("h2"),r.textContent="Policy Configuration",i=m(),a.c(),A(r,"class","svelte-gkxvxc"),A(n,"class","policy-view svelte-gkxvxc")},m(e,t){u(e,n,t),c(n,r),c(n,i),a.m(n,null)},p(e,t){s===(s=o(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 aw(e,t,n){let{isLoggedIn:r=!1}=t,{userRole:i=""}=t,{isPolicyAdmin:o=!1}=t,{policyEnabled:s=!1}=t,{policyJson:a=""}=t,{isLoadingPolicy:l=!1}=t,{policyMessage:c=""}=t,{policyMessageType:u=""}=t,{validationErrors:d=[]}=t,{policyAdmins:f=[]}=t,{policyFollows:h=[]}=t;const p=P();let g="";function m(){g.trim()&&(p("addPolicyAdmin",g.trim()),n(11,g=""))}function y(e){p("removePolicyAdmin",e)}return e.$$set=e=>{"isLoggedIn"in e&&n(2,r=e.isLoggedIn),"userRole"in e&&n(3,i=e.userRole),"isPolicyAdmin"in e&&n(4,o=e.isPolicyAdmin),"policyEnabled"in e&&n(5,s=e.policyEnabled),"policyJson"in e&&n(0,a=e.policyJson),"isLoadingPolicy"in e&&n(6,l=e.isLoadingPolicy),"policyMessage"in e&&n(7,c=e.policyMessage),"policyMessageType"in e&&n(8,u=e.policyMessageType),"validationErrors"in e&&n(9,d=e.validationErrors),"policyAdmins"in e&&n(1,f=e.policyAdmins),"policyFollows"in e&&n(10,h=e.policyFollows)},e.$$.update=()=>{if(1&e.$$.dirty[0])try{if(a){const e=JSON.parse(a);n(1,f=e.policy_admins||[])}}catch(e){}},[a,f,r,i,o,s,l,c,u,d,h,g,function(){p("loadPolicy")},function(){p("validatePolicy")},function(){p("savePolicy")},function(){p("formatJson")},function(){p("openLoginModal")},function(){p("refreshFollows")},m,y,'{\n "kind": {\n "whitelist": [0, 1, 3, 6, 7, 10002],\n "blacklist": []\n },\n "global": {\n "description": "Global rules applied to all events",\n "size_limit": 65536,\n "max_age_of_event": 86400,\n "max_age_event_in_future": 300\n },\n "rules": {\n "1": {\n "description": "Kind 1 (short text notes)",\n "content_limit": 8192,\n "write_allow_follows": true\n },\n "30023": {\n "description": "Long-form articles",\n "content_limit": 100000,\n "tag_validation": {\n "d": "^[a-z0-9-]{1,64}$",\n "t": "^[a-z0-9-]{1,32}$"\n }\n }\n },\n "default_policy": "allow",\n "policy_admins": ["<your-hex-pubkey>"],\n "policy_follow_whitelist_enabled": true\n}',function(){a=this.value,n(0,a)},e=>y(e),function(){g=this.value,n(11,g)},e=>"Enter"===e.key&&m()]}class lw extends oe{constructor(e){super(),ie(this,e,aw,sw,o,{isLoggedIn:2,userRole:3,isPolicyAdmin:4,policyEnabled:5,policyJson:0,isLoadingPolicy:6,policyMessage:7,policyMessageType:8,validationErrors:9,policyAdmins:1,policyFollows:10},null,[-1,-1])}}const{window:cw}=l;function uw(e,t,n){const r=e.slice();return r[57]=t[n],r}function dw(e,t,n){const r=e.slice();return r[54]=t[n],r}function fw(t){let n,r,i,o,s,a;return{c(){n=h("div"),r=h("p"),r.textContent="Please log in to view your Blossom storage.",i=m(),o=h("button"),o.textContent="Log In",A(r,"class","svelte-on0yal"),A(o,"class","login-btn svelte-on0yal"),A(n,"class","login-prompt svelte-on0yal")},m(e,l){u(e,n,l),c(n,r),c(n,i),c(n,o),s||(a=w(o,"click",t[20]),s=!0)},p:e,d(e){e&&d(n),s=!1,a()}}}function hw(e){let t,n,r,i,o,s,a,l,f,p,y,v,b,I,E=e[0]||e[12]?"Loading...":"Refresh";function C(e,t){return e[13]?mw:e[10]?gw:pw}let x=C(e),B=x(e),S=e[14]&&!e[10]&&!e[13]&&ww(e),F=!e[10]&&!e[13]&&vw(e),Q=e[2]&&bw(e);function R(e,t){return e[10]&&!e[13]?Iw:kw}let D=R(e),P=D(e);return{c(){t=h("div"),n=h("div"),B.c(),r=m(),i=h("div"),S&&S.c(),o=m(),s=h("button"),a=g("🔄 "),l=g(E),p=m(),F&&F.c(),y=m(),Q&&Q.c(),v=m(),P.c(),A(s,"class","refresh-btn svelte-on0yal"),s.disabled=f=e[0]||e[12],A(i,"class","header-buttons svelte-on0yal"),A(n,"class","header-section svelte-on0yal"),A(t,"class","blossom-view svelte-on0yal")},m(d,f){u(d,t,f),c(t,n),B.m(n,null),c(n,r),c(n,i),S&&S.m(i,null),c(i,o),c(i,s),c(s,a),c(s,l),c(t,p),F&&F.m(t,null),c(t,y),Q&&Q.m(t,null),c(t,v),P.m(t,null),b||(I=w(s,"click",e[30]),b=!0)},p(e,a){x===(x=C(e))&&B?B.p(e,a):(B.d(1),B=x(e),B&&(B.c(),B.m(n,r))),!e[14]||e[10]||e[13]?S&&(S.d(1),S=null):S?S.p(e,a):(S=ww(e),S.c(),S.m(i,o)),4097&a[0]&&E!==(E=e[0]||e[12]?"Loading...":"Refresh")&&k(l,E),4097&a[0]&&f!==(f=e[0]||e[12])&&(s.disabled=f),e[10]||e[13]?F&&(F.d(1),F=null):F?F.p(e,a):(F=vw(e),F.c(),F.m(t,y)),e[2]?Q?Q.p(e,a):(Q=bw(e),Q.c(),Q.m(t,v)):Q&&(Q.d(1),Q=null),D===(D=R(e))&&P?P.p(e,a):(P.d(1),P=D(e),P&&(P.c(),P.m(t,null)))},d(e){e&&d(t),B.d(),S&&S.d(),F&&F.d(),Q&&Q.d(),P.d(),b=!1,I()}}}function pw(t){let n;return{c(){n=h("h3"),n.textContent="Blossom Media Storage",A(n,"class","svelte-on0yal")},m(e,t){u(e,n,t)},p:e,d(e){e&&d(n)}}}function gw(t){let n,r,i,o,s;return{c(){n=h("button"),n.textContent="← Back",r=m(),i=h("h3"),i.textContent="All Users Storage",A(n,"class","back-btn svelte-on0yal"),A(i,"class","svelte-on0yal")},m(e,a){u(e,n,a),u(e,r,a),u(e,i,a),o||(s=w(n,"click",t[27]),o=!0)},p:e,d(e){e&&d(n),e&&d(r),e&&d(i),o=!1,s()}}}function mw(e){let t,n,r,i,o,s,a,l=(e[13].profile?.name||Xw(e[25](e[13].pubkey)))+"",f=e[13].profile?.picture&&yw(e);return{c(){t=h("button"),t.textContent="← Back",n=m(),r=h("h3"),f&&f.c(),i=m(),o=g(l),A(t,"class","back-btn svelte-on0yal"),A(r,"class","user-header svelte-on0yal")},m(l,d){u(l,t,d),u(l,n,d),u(l,r,d),f&&f.m(r,null),c(r,i),c(r,o),s||(a=w(t,"click",e[29]),s=!0)},p(e,t){e[13].profile?.picture?f?f.p(e,t):(f=yw(e),f.c(),f.m(r,i)):f&&(f.d(1),f=null),8192&t[0]&&l!==(l=(e[13].profile?.name||Xw(e[25](e[13].pubkey)))+"")&&k(o,l)},d(e){e&&d(t),e&&d(n),e&&d(r),f&&f.d(),s=!1,a()}}}function yw(e){let t,n;return{c(){t=h("img"),a(t.src,n=e[13].profile.picture)||A(t,"src",n),A(t,"alt",""),A(t,"class","header-avatar svelte-on0yal")},m(e,n){u(e,t,n)},p(e,r){8192&r[0]&&!a(t.src,n=e[13].profile.picture)&&A(t,"src",n)},d(e){e&&d(t)}}}function ww(e){let t,n,r,i;return{c(){t=h("button"),n=g("Admin"),A(t,"class","admin-btn svelte-on0yal"),t.disabled=e[0]},m(o,s){u(o,t,s),c(t,n),r||(i=w(t,"click",e[26]),r=!0)},p(e,n){1&n[0]&&(t.disabled=e[0])},d(e){e&&d(t),r=!1,i()}}}function vw(e){let t,n,i,o,s,a,l,f,p,y,v=e[3].length>0&&Aw(e);return{c(){t=h("div"),n=h("span"),n.textContent="Upload new files",i=m(),o=h("input"),s=m(),v&&v.c(),a=m(),l=h("button"),f=g("Select Files"),A(n,"class","upload-label svelte-on0yal"),A(o,"type","file"),o.multiple=!0,A(o,"class","file-input-hidden svelte-on0yal"),A(l,"class","select-btn svelte-on0yal"),l.disabled=e[4],A(t,"class","upload-section svelte-on0yal")},m(r,d){u(r,t,d),c(t,n),c(t,i),c(t,o),e[39](o),c(t,s),v&&v.m(t,null),c(t,a),c(t,l),c(l,f),p||(y=[w(o,"change",e[22]),w(l,"click",e[23])],p=!0)},p(e,n){e[3].length>0?v?v.p(e,n):(v=Aw(e),v.c(),v.m(t,a)):v&&(v.d(1),v=null),16&n[0]&&(l.disabled=e[4])},d(n){n&&d(t),e[39](null),v&&v.d(),p=!1,r(y)}}}function Aw(e){let t,n,r,i,o,s,a,l,f=e[3].length+"",p=(e[4]?e[5]:"Upload")+"";return{c(){t=h("span"),n=g(f),r=g(" file(s) selected"),i=m(),o=h("button"),s=g(p),A(t,"class","selected-count svelte-on0yal"),A(o,"class","upload-btn svelte-on0yal"),o.disabled=e[4]},m(d,f){u(d,t,f),c(t,n),c(t,r),u(d,i,f),u(d,o,f),c(o,s),a||(l=w(o,"click",e[24]),a=!0)},p(e,t){8&t[0]&&f!==(f=e[3].length+"")&&k(n,f),48&t[0]&&p!==(p=(e[4]?e[5]:"Upload")+"")&&k(s,p),16&t[0]&&(o.disabled=e[4])},d(e){e&&d(t),e&&d(i),e&&d(o),a=!1,l()}}}function bw(e){let t,n;return{c(){t=h("div"),n=g(e[2]),A(t,"class","error-message svelte-on0yal")},m(e,r){u(e,t,r),c(t,n)},p(e,t){4&t[0]&&k(n,e[2])},d(e){e&&d(t)}}}function kw(e){let t,n,r;function i(e,r){return 1&r[0]&&(t=null),null==t&&(t=!(!e[0]||0!==e[31]().length)),t?xw:(null==n&&(n=!(0!==e[31]().length)),n?Cw:Ew)}let o=i(e,[-1,-1]),s=o(e);return{c(){s.c(),r=y()},m(e,t){s.m(e,t),u(e,r,t)},p(e,t){o===(o=i(e,t))&&s?s.p(e,t):(s.d(1),s=o(e),s&&(s.c(),s.m(r.parentNode,r)))},d(e){s.d(e),e&&d(r)}}}function Iw(e){let t;function n(e,t){return e[12]?Pw:0===e[11].length?Dw:Rw}let r=n(e),i=r(e);return{c(){i.c(),t=y()},m(e,n){i.m(e,n),u(e,t,n)},p(e,o){r===(r=n(e))&&i?i.p(e,o):(i.d(1),i=r(e),i&&(i.c(),i.m(t.parentNode,t)))},d(e){i.d(e),e&&d(t)}}}function Ew(e){let t,n=e[31](),r=[];for(let t=0;t<n.length;t+=1)r[t]=Qw(uw(e,n,t));return{c(){t=h("div");for(let e=0;e<r.length;e+=1)r[e].c();A(t,"class","blob-list svelte-on0yal")},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,i){if(2129920&i[0]|1&i[1]){let o;for(n=e[31](),o=0;o<n.length;o+=1){const s=uw(e,n,o);r[o]?r[o].p(s,i):(r[o]=Qw(s),r[o].c(),r[o].m(t,null))}for(;o<r.length;o+=1)r[o].d(1);r.length=n.length}},d(e){e&&d(t),f(r,e)}}}function Cw(e){let t,n,r,i=e[13]?"No files found for this user.":"No files found in your Blossom storage.";return{c(){t=h("div"),n=h("p"),r=g(i),A(t,"class","empty-state svelte-on0yal")},m(e,i){u(e,t,i),c(t,n),c(n,r)},p(e,t){8192&t[0]&&i!==(i=e[13]?"No files found for this user.":"No files found in your Blossom storage.")&&k(r,i)},d(e){e&&d(t)}}}function xw(t){let n;return{c(){n=h("div"),n.textContent="Loading blobs...",A(n,"class","loading svelte-on0yal")},m(e,t){u(e,n,t)},p:e,d(e){e&&d(n)}}}function Bw(t){let n,r,i=Ww(t[57].type)+"";return{c(){n=h("span"),r=g(i),A(n,"class","thumbnail-icon svelte-on0yal")},m(e,t){u(e,n,t),c(n,r)},p:e,d(e){e&&d(n)}}}function Sw(t){let n,r;return{c(){n=h("video"),a(n.src,r=Zw(t[57]))||A(n,"src",r),A(n,"class","thumbnail-video svelte-on0yal"),n.muted=!0,A(n,"preload","metadata")},m(e,t){u(e,n,t)},p:e,d(e){e&&d(n)}}}function Fw(t){let n,r;return{c(){n=h("img"),a(n.src,r=Zw(t[57]))||A(n,"src",r),A(n,"alt",""),A(n,"class","thumbnail-img svelte-on0yal")},m(e,t){u(e,n,t)},p:e,d(e){e&&d(n)}}}function Qw(e){let t,n,i,o,s,a,l,f,p,y,b,k,I,E,C,x,B,S,F,Q,R,D,P,T,U,$=e[57].sha256+"",N=zw(e[57].sha256)+"",L=Vw(e[57].size)+"",O=(e[57].type||"unknown")+"",M=qw(e[57].uploaded)+"";let _=function(e){return"image"===Yw(e[57].type)?Fw:"video"===Yw(e[57].type)?Sw:Bw}(e),H=_(e);function j(){return e[42](e[57])}function G(){return e[43](e[57])}function K(...t){return e[44](e[57],...t)}return{c(){t=h("div"),n=h("div"),H.c(),i=m(),o=h("div"),s=h("div"),a=h("span"),l=g($),f=m(),p=h("span"),y=g(N),b=m(),k=h("div"),I=h("span"),E=g(L),C=m(),x=h("span"),B=g(O),S=m(),F=h("div"),Q=g(M),R=m(),D=h("button"),D.textContent="X",P=m(),A(n,"class","blob-thumbnail svelte-on0yal"),A(a,"class","hash-full svelte-on0yal"),A(p,"class","hash-truncated svelte-on0yal"),A(s,"class","blob-hash svelte-on0yal"),A(s,"title",e[57].sha256),A(I,"class","blob-size"),A(x,"class","blob-type"),A(k,"class","blob-meta svelte-on0yal"),A(o,"class","blob-info svelte-on0yal"),A(F,"class","blob-date svelte-on0yal"),A(D,"class","delete-btn svelte-on0yal"),A(D,"title","Delete"),A(t,"class","blob-item svelte-on0yal"),A(t,"role","button"),A(t,"tabindex","0")},m(e,r){u(e,t,r),c(t,n),H.m(n,null),c(t,i),c(t,o),c(o,s),c(s,a),c(a,l),c(s,f),c(s,p),c(p,y),c(o,b),c(o,k),c(k,I),c(I,E),c(k,C),c(k,x),c(x,B),c(t,S),c(t,F),c(F,Q),c(t,R),c(t,D),c(t,P),T||(U=[w(D,"click",v(j)),w(t,"click",G),w(t,"keypress",K)],T=!0)},p(t,n){e=t,H.p(e,n)},d(e){e&&d(t),H.d(),T=!1,r(U)}}}function Rw(e){let t,n=e[11],r=[];for(let t=0;t<n.length;t+=1)r[t]=$w(dw(e,n,t));return{c(){t=h("div");for(let e=0;e<r.length;e+=1)r[e].c();A(t,"class","admin-users-list svelte-on0yal")},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,i){if(301991936&i[0]){let o;for(n=e[11],o=0;o<n.length;o+=1){const s=dw(e,n,o);r[o]?r[o].p(s,i):(r[o]=$w(s),r[o].c(),r[o].m(t,null))}for(;o<r.length;o+=1)r[o].d(1);r.length=n.length}},d(e){e&&d(t),f(r,e)}}}function Dw(t){let n;return{c(){n=h("div"),n.innerHTML="<p>No users have uploaded files yet.</p>",A(n,"class","empty-state svelte-on0yal")},m(e,t){u(e,n,t)},p:e,d(e){e&&d(n)}}}function Pw(t){let n;return{c(){n=h("div"),n.textContent="Loading user statistics...",A(n,"class","loading svelte-on0yal")},m(e,t){u(e,n,t)},p:e,d(e){e&&d(n)}}}function Tw(t){let n;return{c(){n=h("div"),A(n,"class","user-avatar-placeholder svelte-on0yal")},m(e,t){u(e,n,t)},p:e,d(e){e&&d(n)}}}function Uw(e){let t,n;return{c(){t=h("img"),a(t.src,n=e[54].profile.picture)||A(t,"src",n),A(t,"alt",""),A(t,"class","user-avatar svelte-on0yal")},m(e,n){u(e,t,n)},p(e,r){2048&r[0]&&!a(t.src,n=e[54].profile.picture)&&A(t,"src",n)},d(e){e&&d(t)}}}function $w(e){let t,n,i,o,s,a,l,f,p,y,v,b,I,E,C,x,B,S,F,Q,R,D,P,T,U,$=(e[54].profile?.name||Xw(e[25](e[54].pubkey)))+"",N=e[25](e[54].pubkey)+"",L=Xw(e[25](e[54].pubkey))+"",O=e[54].blob_count+"",M=Vw(e[54].total_size_bytes)+"";function _(e,t){return e[54].profile?.picture?Uw:Tw}let H=_(e),j=H(e);function G(){return e[40](e[54])}function K(...t){return e[41](e[54],...t)}return{c(){t=h("div"),n=h("div"),j.c(),i=m(),o=h("div"),s=h("div"),a=g($),l=m(),f=h("div"),p=h("span"),y=g(N),v=m(),b=h("span"),I=g(L),C=m(),x=h("div"),B=h("span"),S=g(O),F=g(" files"),Q=m(),R=h("span"),D=g(M),P=m(),A(n,"class","user-avatar-container svelte-on0yal"),A(s,"class","user-name svelte-on0yal"),A(p,"class","npub-full svelte-on0yal"),A(b,"class","npub-truncated svelte-on0yal"),A(f,"class","user-npub svelte-on0yal"),A(f,"title",E=e[54].pubkey),A(o,"class","user-info svelte-on0yal"),A(B,"class","blob-count svelte-on0yal"),A(R,"class","total-size svelte-on0yal"),A(x,"class","user-stats svelte-on0yal"),A(t,"class","user-stat-item svelte-on0yal"),A(t,"role","button"),A(t,"tabindex","0")},m(e,r){u(e,t,r),c(t,n),j.m(n,null),c(t,i),c(t,o),c(o,s),c(s,a),c(o,l),c(o,f),c(f,p),c(p,y),c(f,v),c(f,b),c(b,I),c(t,C),c(t,x),c(x,B),c(B,S),c(B,F),c(x,Q),c(x,R),c(R,D),c(t,P),T||(U=[w(t,"click",G),w(t,"keypress",K)],T=!0)},p(t,r){H===(H=_(e=t))&&j?j.p(e,r):(j.d(1),j=H(e),j&&(j.c(),j.m(n,null))),2048&r[0]&&$!==($=(e[54].profile?.name||Xw(e[25](e[54].pubkey)))+"")&&k(a,$),2048&r[0]&&N!==(N=e[25](e[54].pubkey)+"")&&k(y,N),2048&r[0]&&L!==(L=Xw(e[25](e[54].pubkey))+"")&&k(I,L),2048&r[0]&&E!==(E=e[54].pubkey)&&A(f,"title",E),2048&r[0]&&O!==(O=e[54].blob_count+"")&&k(S,O),2048&r[0]&&M!==(M=Vw(e[54].total_size_bytes)+"")&&k(D,M)},d(e){e&&d(t),j.d(),T=!1,r(U)}}}function Nw(e){let t,n,i,o,s,a,l,f,p,y,b,I,E,C,x,B,S,F,Q,R,D,P,T,U,$,N,L,O,M,_,H,j,G,K,J,V,q,z,Y,W,Z,X,ee,te=zw(e[8].sha256)+"",ne=(e[8].type||"unknown")+"",re="image"===Yw(e[8].type),ie=Vw(e[8].size)+"",oe=qw(e[8].uploaded)+"",se=re&&Lw(e);function ae(e,t){return 256&t[0]&&(B=null),256&t[0]&&(S=null),256&t[0]&&(F=null),null==B&&(B=!("image"!==Yw(e[8].type))),B?Hw:(null==S&&(S=!("video"!==Yw(e[8].type))),S?_w:(null==F&&(F=!("audio"!==Yw(e[8].type))),F?Mw:Ow))}let le=ae(e,[-1,-1]),ce=le(e);return{c(){t=h("div"),n=h("div"),i=h("div"),o=h("div"),s=h("span"),a=g(te),l=m(),f=h("span"),p=g(ne),y=m(),b=h("div"),se&&se.c(),I=m(),E=h("button"),E.textContent="X",C=m(),x=h("div"),ce.c(),Q=m(),R=h("div"),D=h("div"),P=h("span"),T=g("Size: "),U=g(ie),$=m(),N=h("span"),L=g("Uploaded: "),O=g(oe),M=m(),_=h("div"),H=h("input"),G=m(),K=h("button"),K.textContent="Copy",J=m(),V=h("div"),q=h("a"),z=g("Open in New Tab"),W=m(),Z=h("button"),Z.textContent="Delete",A(s,"class","modal-hash svelte-on0yal"),A(f,"class","modal-type svelte-on0yal"),A(o,"class","modal-title svelte-on0yal"),A(E,"class","close-btn svelte-on0yal"),A(b,"class","modal-controls svelte-on0yal"),A(i,"class","modal-header svelte-on0yal"),A(x,"class","modal-body svelte-on0yal"),A(D,"class","blob-details svelte-on0yal"),A(H,"type","text"),H.readOnly=!0,H.value=j=Zw(e[8]),A(H,"class","blob-url-input svelte-on0yal"),A(K,"class","copy-btn svelte-on0yal"),A(_,"class","blob-url-section svelte-on0yal"),A(q,"href",Y=Zw(e[8])),A(q,"target","_blank"),A(q,"rel","noopener noreferrer"),A(q,"class","action-btn svelte-on0yal"),A(Z,"class","action-btn danger svelte-on0yal"),A(V,"class","modal-actions svelte-on0yal"),A(R,"class","modal-footer svelte-on0yal"),A(n,"class","modal-content svelte-on0yal"),A(n,"role","dialog"),A(t,"class","modal-overlay svelte-on0yal"),A(t,"role","button"),A(t,"tabindex","0")},m(r,d){u(r,t,d),c(t,n),c(n,i),c(i,o),c(o,s),c(s,a),c(o,l),c(o,f),c(f,p),c(i,y),c(i,b),se&&se.m(b,null),c(b,I),c(b,E),c(n,C),c(n,x),ce.m(x,null),c(n,Q),c(n,R),c(R,D),c(D,P),c(P,T),c(P,U),c(D,$),c(D,N),c(N,L),c(N,O),c(R,M),c(R,_),c(_,H),c(_,G),c(_,K),c(R,J),c(R,V),c(V,q),c(q,z),c(V,W),c(V,Z),X||(ee=[w(E,"click",e[16]),w(H,"click",ev),w(K,"click",e[45]),w(Z,"click",e[46]),w(n,"click",v(e[37])),w(n,"keypress",v(e[38])),w(t,"click",e[16]),w(t,"keypress",e[47])],X=!0)},p(e,t){256&t[0]&&te!==(te=zw(e[8].sha256)+"")&&k(a,te),256&t[0]&&ne!==(ne=(e[8].type||"unknown")+"")&&k(p,ne),256&t[0]&&(re="image"===Yw(e[8].type)),re?se?se.p(e,t):(se=Lw(e),se.c(),se.m(b,I)):se&&(se.d(1),se=null),le===(le=ae(e,t))&&ce?ce.p(e,t):(ce.d(1),ce=le(e),ce&&(ce.c(),ce.m(x,null))),256&t[0]&&ie!==(ie=Vw(e[8].size)+"")&&k(U,ie),256&t[0]&&oe!==(oe=qw(e[8].uploaded)+"")&&k(O,oe),256&t[0]&&j!==(j=Zw(e[8]))&&H.value!==j&&(H.value=j),256&t[0]&&Y!==(Y=Zw(e[8]))&&A(q,"href",Y)},d(e){e&&d(t),se&&se.d(),ce.d(),X=!1,r(ee)}}}function Lw(e){let t,n,i,o,s,a,l,f,p,y,v,b,I,E=Math.round(100*e[9])+"";return{c(){t=h("button"),n=g("-"),o=m(),s=h("span"),a=g(E),l=g("%"),f=m(),p=h("button"),y=g("+"),A(t,"class","zoom-btn svelte-on0yal"),t.disabled=i=e[9]<=Gw,A(s,"class","zoom-level svelte-on0yal"),A(p,"class","zoom-btn svelte-on0yal"),p.disabled=v=e[9]>=Kw},m(r,i){u(r,t,i),c(t,n),u(r,o,i),u(r,s,i),c(s,a),c(s,l),u(r,f,i),u(r,p,i),c(p,y),b||(I=[w(t,"click",e[18]),w(p,"click",e[17])],b=!0)},p(e,n){512&n[0]&&i!==(i=e[9]<=Gw)&&(t.disabled=i),512&n[0]&&E!==(E=Math.round(100*e[9])+"")&&k(a,E),512&n[0]&&v!==(v=e[9]>=Kw)&&(p.disabled=v)},d(e){e&&d(t),e&&d(o),e&&d(s),e&&d(f),e&&d(p),b=!1,r(I)}}}function Ow(e){let t,n,r,i,o,s,a,l,f,p=Ww(e[8].type)+"";return{c(){t=h("div"),n=h("div"),r=g(p),i=m(),o=h("p"),o.textContent="Preview not available for this file type.",s=m(),a=h("a"),l=g("Download File"),A(n,"class","file-icon svelte-on0yal"),A(a,"href",f=Zw(e[8])),A(a,"target","_blank"),A(a,"rel","noopener noreferrer"),A(a,"class","download-link svelte-on0yal"),A(t,"class","file-preview svelte-on0yal")},m(e,d){u(e,t,d),c(t,n),c(n,r),c(t,i),c(t,o),c(t,s),c(t,a),c(a,l)},p(e,t){256&t[0]&&p!==(p=Ww(e[8].type)+"")&&k(r,p),256&t[0]&&f!==(f=Zw(e[8]))&&A(a,"href",f)},d(e){e&&d(t)}}}function Mw(e){let t,n,r;return{c(){t=h("div"),n=h("audio"),n.controls=!0,a(n.src,r=Zw(e[8]))||A(n,"src",r),A(n,"class","svelte-on0yal"),A(t,"class","media-container audio svelte-on0yal")},m(e,r){u(e,t,r),c(t,n)},p(e,t){256&t[0]&&!a(n.src,r=Zw(e[8]))&&A(n,"src",r)},d(e){e&&d(t)}}}function _w(e){let t,n,r,i;return{c(){t=h("div"),n=h("video"),r=h("track"),A(r,"kind","captions"),n.controls=!0,a(n.src,i=Zw(e[8]))||A(n,"src",i),A(n,"class","svelte-on0yal"),A(t,"class","media-container svelte-on0yal")},m(e,i){u(e,t,i),c(t,n),c(n,r)},p(e,t){256&t[0]&&!a(n.src,i=Zw(e[8]))&&A(n,"src",i)},d(e){e&&d(t)}}}function Hw(e){let t,n,r;return{c(){t=h("div"),n=h("img"),a(n.src,r=Zw(e[8]))||A(n,"src",r),A(n,"alt","Blob content"),A(n,"class","svelte-on0yal"),A(t,"class","media-container svelte-on0yal"),E(t,"transform","scale("+e[9]+")")},m(e,r){u(e,t,r),c(t,n)},p(e,i){256&i[0]&&!a(n.src,r=Zw(e[8]))&&A(n,"src",r),512&i[0]&&E(t,"transform","scale("+e[9]+")")},d(e){e&&d(t)}}}function jw(t){let n,r,i,o;function s(e,t){return e[1]?hw:fw}let a=s(t),l=a(t),c=t[7]&&t[8]&&Nw(t);return{c(){l.c(),n=m(),c&&c.c(),r=y()},m(e,s){l.m(e,s),u(e,n,s),c&&c.m(e,s),u(e,r,s),i||(o=w(cw,"keydown",t[19]),i=!0)},p(e,t){a===(a=s(e))&&l?l.p(e,t):(l.d(1),l=a(e),l&&(l.c(),l.m(n.parentNode,n))),e[7]&&e[8]?c?c.p(e,t):(c=Nw(e),c.c(),c.m(r.parentNode,r)):c&&(c.d(1),c=null)},i:e,o:e,d(e){l.d(e),e&&d(n),c&&c.d(e),e&&d(r),i=!1,o()}}}const Gw=.25,Kw=4;async function Jw(e,t,n=null){if(!e)return console.log("No signer available for Blossom auth"),null;try{const r=Math.floor(Date.now()/1e3),i=[["t",t],["expiration",(r+60).toString()]];n&&i.push(["x",n]);const o={kind:24242,created_at:r,tags:i,content:`Blossom ${t} operation`},s=await e.signEvent(o);return btoa(JSON.stringify(s)).replace(/\+/g,"-").replace(/\//g,"_")}catch(e){return console.error("Error creating Blossom auth:",e),null}}function Vw(e){if(!e)return"0 B";const t=["B","KB","MB","GB"];let n=0,r=e;for(;r>=1024&&n<t.length-1;)r/=1024,n++;return`${r.toFixed(0===n?0:1)} ${t[n]}`}function qw(e){return e?new Date(1e3*e).toLocaleString():"Unknown"}function zw(e){return e?`${e.slice(0,8)}...${e.slice(-8)}`:""}function Yw(e){return e?e.startsWith("image/")?"image":e.startsWith("video/")?"video":e.startsWith("audio/")?"audio":"file":"unknown"}function Ww(e){switch(Yw(e)){case"image":return"🖼️";case"video":return"🎬";case"audio":return"🎵";default:return"📄"}}function Zw(e){return e.url?e.url.startsWith("http://")||e.url.startsWith("https://")?e.url:e.url.startsWith("/")?`${window.location.origin}${e.url}`:`http://${e.url}`:`${window.location.origin}/blossom/${e.sha256}`}function Xw(e){return e?`${e.slice(0,12)}...${e.slice(-8)}`:""}const ev=e=>e.target.select();function tv(e,t,n){let r,i,{isLoggedIn:o=!1}=t,{userPubkey:s=""}=t,{userSigner:a=null}=t,{currentEffectiveRole:l=""}=t;const c=P();let u,d=[],f=!1,h="",p=[],g=!1,m="",y=!1,w=null,v=1,A=!1,b=[],k=!1,I=null,E=[],C=!1;async function x(){if(s){n(0,f=!0),n(2,h="");try{const e=`${window.location.origin}/blossom/list/${s}`,t=await Jw(a,"list"),n=await fetch(e,{headers:t?{Authorization:`Nostr ${t}`}:{}});if(!n.ok)throw new Error(`Failed to load blobs: ${n.statusText}`);const r=await n.json();d=Array.isArray(r)?r:[],d.sort((e,t)=>(t.uploaded||0)-(e.uploaded||0)),console.log("Loaded blobs:",d)}catch(e){console.error("Error loading blobs:",e),n(2,h=e.message||"Failed to load blobs")}finally{n(0,f=!1)}}}function B(e){n(8,w=e),n(9,v=1),n(7,y=!0)}function S(){n(7,y=!1),n(8,w=null),n(9,v=1)}function F(){v<Kw&&n(9,v=Math.min(Kw,v+.25))}function Q(){v>Gw&&n(9,v=Math.max(Gw,v-.25))}async function D(e){if(confirm(`Delete blob ${zw(e.sha256)}?`))try{const t=`${window.location.origin}/blossom/${e.sha256}`,n=await Jw(a,"delete",e.sha256),r=await fetch(t,{method:"DELETE",headers:n?{Authorization:`Nostr ${n}`}:{}});if(!r.ok)throw new Error(`Failed to delete: ${r.statusText}`);d=d.filter(t=>t.sha256!==e.sha256),w?.sha256===e.sha256&&S()}catch(e){console.error("Error deleting blob:",e),alert(`Failed to delete blob: ${e.message}`)}}async function U(){n(12,k=!0),n(2,h="");try{const e=`${window.location.origin}/blossom/admin/users`,t=await Jw(a,"admin"),r=await fetch(e,{headers:t?{Authorization:`Nostr ${t}`}:{}});if(!r.ok)throw new Error(`Failed to load user stats: ${r.statusText}`);n(11,b=await r.json());for(const e of b)Nh(e.pubkey).then(t=>{e.profile=t||{name:"",picture:""},n(11,b)}).catch(()=>{e.profile={name:"",picture:""}})}catch(e){console.error("Error fetching admin user stats:",e),n(2,h=e.message||"Failed to load user stats")}finally{n(12,k=!1)}}async function N(e){n(0,f=!0),n(2,h="");try{const t=`${window.location.origin}/blossom/list/${e}`,n=await Jw(a,"list"),r=await fetch(t,{headers:n?{Authorization:`Nostr ${n}`}:{}});if(!r.ok)throw new Error(`Failed to load user blobs: ${r.statusText}`);E=await r.json(),E.sort((e,t)=>(t.uploaded||0)-(e.uploaded||0))}catch(e){console.error("Error loading user blobs:",e),n(2,h=e.message||"Failed to load user blobs")}finally{n(0,f=!1)}}async function L(e){n(13,I={pubkey:e.pubkey,profile:e.profile}),await N(e.pubkey)}R(()=>{r&&!C&&(n(36,C=!0),x())});return e.$$set=e=>{"isLoggedIn"in e&&n(32,o=e.isLoggedIn),"userPubkey"in e&&n(33,s=e.userPubkey),"userSigner"in e&&n(34,a=e.userSigner),"currentEffectiveRole"in e&&n(35,l=e.currentEffectiveRole)},e.$$.update=()=>{6&e.$$.dirty[1]&&n(1,r=o&&s),16&e.$$.dirty[1]&&n(14,i="admin"===l||"owner"===l),3&e.$$.dirty[0]|32&e.$$.dirty[1]&&(!r||C||f||(n(36,C=!0),x()))},[f,r,h,p,g,m,u,y,w,v,A,b,k,I,i,B,S,F,Q,function(e){y&&("Escape"===e.key?S():"+"===e.key||"="===e.key?F():"-"===e.key&&Q())},function(){c("openLoginModal")},D,function(e){n(3,p=Array.from(e.target.files))},function(){u?.click()},async function(){if(0===p.length)return;n(4,g=!0),n(2,h="");const e=[],t=[];for(let r=0;r<p.length;r++){const i=p[r];n(5,m=`Uploading ${r+1}/${p.length}: ${i.name}`);try{const t=`${window.location.origin}/blossom/upload`,n=await Jw(a,"upload"),r=await fetch(t,{method:"PUT",headers:{"Content-Type":i.type||"application/octet-stream",...n?{Authorization:`Nostr ${n}`}:{}},body:i});if(!r.ok){const e=r.headers.get("X-Reason")||r.statusText;throw new Error(e)}const o=await r.json();console.log("Upload response:",o),e.push(o)}catch(e){console.error(`Error uploading ${i.name}:`,e),t.push({name:i.name,error:e.message})}}n(4,g=!1),n(5,m=""),n(3,p=[]),u&&n(6,u.value="",u),e.length>0&&await x(),t.length>0&&n(2,h=`Failed to upload: ${t.map(e=>e.name).join(", ")}`)},function(e){try{return vu(e)}catch(t){return zw(e)}},function(){n(10,A=!0),U()},function(){n(10,A=!1),n(11,b=[]),n(13,I=null),E=[]},L,function(){n(13,I=null),E=[]},function(){I?N(I.pubkey):A?U():x()},function(){return I?E:d},o,s,a,l,C,function(t){T.call(this,e,t)},function(t){T.call(this,e,t)},function(e){$[e?"unshift":"push"](()=>{u=e,n(6,u)})},e=>L(e),(e,t)=>"Enter"===t.key&&L(e),e=>D(e),e=>B(e),(e,t)=>"Enter"===t.key&&B(e),()=>{navigator.clipboard.writeText(Zw(w))},()=>D(w),e=>"Enter"===e.key&&S()]}class nv extends oe{constructor(e){super(),ie(this,e,tv,jw,o,{isLoggedIn:32,userPubkey:33,userSigner:34,currentEffectiveRole:35},null,[-1,-1])}}var rv={},iv={},ov={};let sv;const av=[0,26,44,70,100,134,172,196,242,292,346,404,466,532,581,655,733,815,901,991,1085,1156,1258,1364,1474,1588,1706,1828,1921,2051,2185,2323,2465,2611,2761,2876,3034,3196,3362,3532,3706];ov.getSymbolSize=function(e){if(!e)throw new Error('"version" cannot be null or undefined');if(e<1||e>40)throw new Error('"version" should be in range from 1 to 40');return 4*e+17},ov.getSymbolTotalCodewords=function(e){return av[e]},ov.getBCHDigit=function(e){let t=0;for(;0!==e;)t++,e>>>=1;return t},ov.setToSJISFunction=function(e){if("function"!=typeof e)throw new Error('"toSJISFunc" is not a valid function.');sv=e},ov.isKanjiModeEnabled=function(){return void 0!==sv},ov.toSJIS=function(e){return sv(e)};var lv,cv={};function uv(){this.buffer=[],this.length=0}(lv=cv).L={bit:1},lv.M={bit:0},lv.Q={bit:3},lv.H={bit:2},lv.isValid=function(e){return e&&void 0!==e.bit&&e.bit>=0&&e.bit<4},lv.from=function(e,t){if(lv.isValid(e))return e;try{return function(e){if("string"!=typeof e)throw new Error("Param is not a string");switch(e.toLowerCase()){case"l":case"low":return lv.L;case"m":case"medium":return lv.M;case"q":case"quartile":return lv.Q;case"h":case"high":return lv.H;default:throw new Error("Unknown EC Level: "+e)}}(e)}catch(e){return t}},uv.prototype={get:function(e){const t=Math.floor(e/8);return 1==(this.buffer[t]>>>7-e%8&1)},put:function(e,t){for(let n=0;n<t;n++)this.putBit(1==(e>>>t-n-1&1))},getLengthInBits:function(){return this.length},putBit:function(e){const t=Math.floor(this.length/8);this.buffer.length<=t&&this.buffer.push(0),e&&(this.buffer[t]|=128>>>this.length%8),this.length++}};var dv=uv;function fv(e){if(!e||e<1)throw new Error("BitMatrix size must be defined and greater than 0");this.size=e,this.data=new Uint8Array(e*e),this.reservedBit=new Uint8Array(e*e)}fv.prototype.set=function(e,t,n,r){const i=e*this.size+t;this.data[i]=n,r&&(this.reservedBit[i]=!0)},fv.prototype.get=function(e,t){return this.data[e*this.size+t]},fv.prototype.xor=function(e,t,n){this.data[e*this.size+t]^=n},fv.prototype.isReserved=function(e,t){return this.reservedBit[e*this.size+t]};var hv=fv,pv={};!function(e){const t=ov.getSymbolSize;e.getRowColCoords=function(e){if(1===e)return[];const n=Math.floor(e/7)+2,r=t(e),i=145===r?26:2*Math.ceil((r-13)/(2*n-2)),o=[r-7];for(let e=1;e<n-1;e++)o[e]=o[e-1]-i;return o.push(6),o.reverse()},e.getPositions=function(t){const n=[],r=e.getRowColCoords(t),i=r.length;for(let e=0;e<i;e++)for(let t=0;t<i;t++)0===e&&0===t||0===e&&t===i-1||e===i-1&&0===t||n.push([r[e],r[t]]);return n}}(pv);var gv={};const mv=ov.getSymbolSize;gv.getPositions=function(e){const t=mv(e);return[[0,0],[t-7,0],[0,t-7]]};var yv={};!function(e){e.Patterns={PATTERN000:0,PATTERN001:1,PATTERN010:2,PATTERN011:3,PATTERN100:4,PATTERN101:5,PATTERN110:6,PATTERN111:7};const t=3,n=3,r=40,i=10;function o(t,n,r){switch(t){case e.Patterns.PATTERN000:return(n+r)%2==0;case e.Patterns.PATTERN001:return n%2==0;case e.Patterns.PATTERN010:return r%3==0;case e.Patterns.PATTERN011:return(n+r)%3==0;case e.Patterns.PATTERN100:return(Math.floor(n/2)+Math.floor(r/3))%2==0;case e.Patterns.PATTERN101:return n*r%2+n*r%3==0;case e.Patterns.PATTERN110:return(n*r%2+n*r%3)%2==0;case e.Patterns.PATTERN111:return(n*r%3+(n+r)%2)%2==0;default:throw new Error("bad maskPattern:"+t)}}e.isValid=function(e){return null!=e&&""!==e&&!isNaN(e)&&e>=0&&e<=7},e.from=function(t){return e.isValid(t)?parseInt(t,10):void 0},e.getPenaltyN1=function(e){const n=e.size;let r=0,i=0,o=0,s=null,a=null;for(let l=0;l<n;l++){i=o=0,s=a=null;for(let c=0;c<n;c++){let n=e.get(l,c);n===s?i++:(i>=5&&(r+=t+(i-5)),s=n,i=1),n=e.get(c,l),n===a?o++:(o>=5&&(r+=t+(o-5)),a=n,o=1)}i>=5&&(r+=t+(i-5)),o>=5&&(r+=t+(o-5))}return r},e.getPenaltyN2=function(e){const t=e.size;let r=0;for(let n=0;n<t-1;n++)for(let i=0;i<t-1;i++){const t=e.get(n,i)+e.get(n,i+1)+e.get(n+1,i)+e.get(n+1,i+1);4!==t&&0!==t||r++}return r*n},e.getPenaltyN3=function(e){const t=e.size;let n=0,i=0,o=0;for(let r=0;r<t;r++){i=o=0;for(let s=0;s<t;s++)i=i<<1&2047|e.get(r,s),s>=10&&(1488===i||93===i)&&n++,o=o<<1&2047|e.get(s,r),s>=10&&(1488===o||93===o)&&n++}return n*r},e.getPenaltyN4=function(e){let t=0;const n=e.data.length;for(let r=0;r<n;r++)t+=e.data[r];return Math.abs(Math.ceil(100*t/n/5)-10)*i},e.applyMask=function(e,t){const n=t.size;for(let r=0;r<n;r++)for(let i=0;i<n;i++)t.isReserved(i,r)||t.xor(i,r,o(e,i,r))},e.getBestMask=function(t,n){const r=Object.keys(e.Patterns).length;let i=0,o=1/0;for(let s=0;s<r;s++){n(s),e.applyMask(s,t);const r=e.getPenaltyN1(t)+e.getPenaltyN2(t)+e.getPenaltyN3(t)+e.getPenaltyN4(t);e.applyMask(s,t),r<o&&(o=r,i=s)}return i}}(yv);var wv={};const vv=cv,Av=[1,1,1,1,1,1,1,1,1,1,2,2,1,2,2,4,1,2,4,4,2,4,4,4,2,4,6,5,2,4,6,6,2,5,8,8,4,5,8,8,4,5,8,11,4,8,10,11,4,9,12,16,4,9,16,16,6,10,12,18,6,10,17,16,6,11,16,19,6,13,18,21,7,14,21,25,8,16,20,25,8,17,23,25,9,17,23,34,9,18,25,30,10,20,27,32,12,21,29,35,12,23,34,37,12,25,34,40,13,26,35,42,14,28,38,45,15,29,40,48,16,31,43,51,17,33,45,54,18,35,48,57,19,37,51,60,19,38,53,63,20,40,56,66,21,43,59,70,22,45,62,74,24,47,65,77,25,49,68,81],bv=[7,10,13,17,10,16,22,28,15,26,36,44,20,36,52,64,26,48,72,88,36,64,96,112,40,72,108,130,48,88,132,156,60,110,160,192,72,130,192,224,80,150,224,264,96,176,260,308,104,198,288,352,120,216,320,384,132,240,360,432,144,280,408,480,168,308,448,532,180,338,504,588,196,364,546,650,224,416,600,700,224,442,644,750,252,476,690,816,270,504,750,900,300,560,810,960,312,588,870,1050,336,644,952,1110,360,700,1020,1200,390,728,1050,1260,420,784,1140,1350,450,812,1200,1440,480,868,1290,1530,510,924,1350,1620,540,980,1440,1710,570,1036,1530,1800,570,1064,1590,1890,600,1120,1680,1980,630,1204,1770,2100,660,1260,1860,2220,720,1316,1950,2310,750,1372,2040,2430];wv.getBlocksCount=function(e,t){switch(t){case vv.L:return Av[4*(e-1)+0];case vv.M:return Av[4*(e-1)+1];case vv.Q:return Av[4*(e-1)+2];case vv.H:return Av[4*(e-1)+3];default:return}},wv.getTotalCodewordsCount=function(e,t){switch(t){case vv.L:return bv[4*(e-1)+0];case vv.M:return bv[4*(e-1)+1];case vv.Q:return bv[4*(e-1)+2];case vv.H:return bv[4*(e-1)+3];default:return}};var kv={},Iv={};const Ev=new Uint8Array(512),Cv=new Uint8Array(256);!function(){let e=1;for(let t=0;t<255;t++)Ev[t]=e,Cv[e]=t,e<<=1,256&e&&(e^=285);for(let e=255;e<512;e++)Ev[e]=Ev[e-255]}(),Iv.log=function(e){if(e<1)throw new Error("log("+e+")");return Cv[e]},Iv.exp=function(e){return Ev[e]},Iv.mul=function(e,t){return 0===e||0===t?0:Ev[Cv[e]+Cv[t]]},function(e){const t=Iv;e.mul=function(e,n){const r=new Uint8Array(e.length+n.length-1);for(let i=0;i<e.length;i++)for(let o=0;o<n.length;o++)r[i+o]^=t.mul(e[i],n[o]);return r},e.mod=function(e,n){let r=new Uint8Array(e);for(;r.length-n.length>=0;){const e=r[0];for(let i=0;i<n.length;i++)r[i]^=t.mul(n[i],e);let i=0;for(;i<r.length&&0===r[i];)i++;r=r.slice(i)}return r},e.generateECPolynomial=function(n){let r=new Uint8Array([1]);for(let i=0;i<n;i++)r=e.mul(r,new Uint8Array([1,t.exp(i)]));return r}}(kv);const xv=kv;function Bv(e){this.genPoly=void 0,this.degree=e,this.degree&&this.initialize(this.degree)}Bv.prototype.initialize=function(e){this.degree=e,this.genPoly=xv.generateECPolynomial(this.degree)},Bv.prototype.encode=function(e){if(!this.genPoly)throw new Error("Encoder not initialized");const t=new Uint8Array(e.length+this.degree);t.set(e);const n=xv.mod(t,this.genPoly),r=this.degree-n.length;if(r>0){const e=new Uint8Array(this.degree);return e.set(n,r),e}return n};var Sv=Bv,Fv={},Qv={},Rv={isValid:function(e){return!isNaN(e)&&e>=1&&e<=40}},Dv={};const Pv="[0-9]+";let Tv="(?:[u3000-u303F]|[u3040-u309F]|[u30A0-u30FF]|[uFF00-uFFEF]|[u4E00-u9FAF]|[u2605-u2606]|[u2190-u2195]|u203B|[u2010u2015u2018u2019u2025u2026u201Cu201Du2225u2260]|[u0391-u0451]|[u00A7u00A8u00B1u00B4u00D7u00F7])+";Tv=Tv.replace(/u/g,"\\u");const Uv="(?:(?![A-Z0-9 $%*+\\-./:]|"+Tv+")(?:.|[\r\n]))+";Dv.KANJI=new RegExp(Tv,"g"),Dv.BYTE_KANJI=new RegExp("[^A-Z0-9 $%*+\\-./:]+","g"),Dv.BYTE=new RegExp(Uv,"g"),Dv.NUMERIC=new RegExp(Pv,"g"),Dv.ALPHANUMERIC=new RegExp("[A-Z $%*+\\-./:]+","g");const $v=new RegExp("^"+Tv+"$"),Nv=new RegExp("^"+Pv+"$"),Lv=new RegExp("^[A-Z0-9 $%*+\\-./:]+$");Dv.testKanji=function(e){return $v.test(e)},Dv.testNumeric=function(e){return Nv.test(e)},Dv.testAlphanumeric=function(e){return Lv.test(e)},function(e){const t=Rv,n=Dv;e.NUMERIC={id:"Numeric",bit:1,ccBits:[10,12,14]},e.ALPHANUMERIC={id:"Alphanumeric",bit:2,ccBits:[9,11,13]},e.BYTE={id:"Byte",bit:4,ccBits:[8,16,16]},e.KANJI={id:"Kanji",bit:8,ccBits:[8,10,12]},e.MIXED={bit:-1},e.getCharCountIndicator=function(e,n){if(!e.ccBits)throw new Error("Invalid mode: "+e);if(!t.isValid(n))throw new Error("Invalid version: "+n);return n>=1&&n<10?e.ccBits[0]:n<27?e.ccBits[1]:e.ccBits[2]},e.getBestModeForData=function(t){return n.testNumeric(t)?e.NUMERIC:n.testAlphanumeric(t)?e.ALPHANUMERIC:n.testKanji(t)?e.KANJI:e.BYTE},e.toString=function(e){if(e&&e.id)return e.id;throw new Error("Invalid mode")},e.isValid=function(e){return e&&e.bit&&e.ccBits},e.from=function(t,n){if(e.isValid(t))return t;try{return function(t){if("string"!=typeof t)throw new Error("Param is not a string");switch(t.toLowerCase()){case"numeric":return e.NUMERIC;case"alphanumeric":return e.ALPHANUMERIC;case"kanji":return e.KANJI;case"byte":return e.BYTE;default:throw new Error("Unknown mode: "+t)}}(t)}catch(e){return n}}}(Qv),function(e){const t=ov,n=wv,r=cv,i=Qv,o=Rv,s=t.getBCHDigit(7973);function a(e,t){return i.getCharCountIndicator(e,t)+4}function l(e,t){let n=0;return e.forEach(function(e){const r=a(e.mode,t);n+=r+e.getBitsLength()}),n}e.from=function(e,t){return o.isValid(e)?parseInt(e,10):t},e.getCapacity=function(e,r,s){if(!o.isValid(e))throw new Error("Invalid QR Code version");void 0===s&&(s=i.BYTE);const l=8*(t.getSymbolTotalCodewords(e)-n.getTotalCodewordsCount(e,r));if(s===i.MIXED)return l;const c=l-a(s,e);switch(s){case i.NUMERIC:return Math.floor(c/10*3);case i.ALPHANUMERIC:return Math.floor(c/11*2);case i.KANJI:return Math.floor(c/13);case i.BYTE:default:return Math.floor(c/8)}},e.getBestVersionForData=function(t,n){let o;const s=r.from(n,r.M);if(Array.isArray(t)){if(t.length>1)return function(t,n){for(let r=1;r<=40;r++)if(l(t,r)<=e.getCapacity(r,n,i.MIXED))return r}(t,s);if(0===t.length)return 1;o=t[0]}else o=t;return function(t,n,r){for(let i=1;i<=40;i++)if(n<=e.getCapacity(i,r,t))return i}(o.mode,o.getLength(),s)},e.getEncodedBits=function(e){if(!o.isValid(e)||e<7)throw new Error("Invalid QR Code version");let n=e<<12;for(;t.getBCHDigit(n)-s>=0;)n^=7973<<t.getBCHDigit(n)-s;return e<<12|n}}(Fv);var Ov={};const Mv=ov,_v=Mv.getBCHDigit(1335);Ov.getEncodedBits=function(e,t){const n=e.bit<<3|t;let r=n<<10;for(;Mv.getBCHDigit(r)-_v>=0;)r^=1335<<Mv.getBCHDigit(r)-_v;return 21522^(n<<10|r)};var Hv={};const jv=Qv;function Gv(e){this.mode=jv.NUMERIC,this.data=e.toString()}Gv.getBitsLength=function(e){return 10*Math.floor(e/3)+(e%3?e%3*3+1:0)},Gv.prototype.getLength=function(){return this.data.length},Gv.prototype.getBitsLength=function(){return Gv.getBitsLength(this.data.length)},Gv.prototype.write=function(e){let t,n,r;for(t=0;t+3<=this.data.length;t+=3)n=this.data.substr(t,3),r=parseInt(n,10),e.put(r,10);const i=this.data.length-t;i>0&&(n=this.data.substr(t),r=parseInt(n,10),e.put(r,3*i+1))};var Kv=Gv;const Jv=Qv,Vv=["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"," ","$","%","*","+","-",".","/",":"];function qv(e){this.mode=Jv.ALPHANUMERIC,this.data=e}qv.getBitsLength=function(e){return 11*Math.floor(e/2)+e%2*6},qv.prototype.getLength=function(){return this.data.length},qv.prototype.getBitsLength=function(){return qv.getBitsLength(this.data.length)},qv.prototype.write=function(e){let t;for(t=0;t+2<=this.data.length;t+=2){let n=45*Vv.indexOf(this.data[t]);n+=Vv.indexOf(this.data[t+1]),e.put(n,11)}this.data.length%2&&e.put(Vv.indexOf(this.data[t]),6)};var zv=qv;const Yv=Qv;function Wv(e){this.mode=Yv.BYTE,this.data="string"==typeof e?(new TextEncoder).encode(e):new Uint8Array(e)}Wv.getBitsLength=function(e){return 8*e},Wv.prototype.getLength=function(){return this.data.length},Wv.prototype.getBitsLength=function(){return Wv.getBitsLength(this.data.length)},Wv.prototype.write=function(e){for(let t=0,n=this.data.length;t<n;t++)e.put(this.data[t],8)};var Zv=Wv;const Xv=Qv,eA=ov;function tA(e){this.mode=Xv.KANJI,this.data=e}tA.getBitsLength=function(e){return 13*e},tA.prototype.getLength=function(){return this.data.length},tA.prototype.getBitsLength=function(){return tA.getBitsLength(this.data.length)},tA.prototype.write=function(e){let t;for(t=0;t<this.data.length;t++){let n=eA.toSJIS(this.data[t]);if(n>=33088&&n<=40956)n-=33088;else{if(!(n>=57408&&n<=60351))throw new Error("Invalid SJIS character: "+this.data[t]+"\nMake sure your charset is UTF-8");n-=49472}n=192*(n>>>8&255)+(255&n),e.put(n,13)}};var nA=tA,rA={exports:{}};!function(e){var t={single_source_shortest_paths:function(e,n,r){var i={},o={};o[n]=0;var s,a,l,c,u,d,f,h=t.PriorityQueue.make();for(h.push(n,0);!h.empty();)for(l in a=(s=h.pop()).value,c=s.cost,u=e[a]||{})u.hasOwnProperty(l)&&(d=c+u[l],f=o[l],(void 0===o[l]||f>d)&&(o[l]=d,h.push(l,d),i[l]=a));if(void 0!==r&&void 0===o[r]){var p=["Could not find a path from ",n," to ",r,"."].join("");throw new Error(p)}return i},extract_shortest_path_from_predecessor_list:function(e,t){for(var n=[],r=t;r;)n.push(r),e[r],r=e[r];return n.reverse(),n},find_path:function(e,n,r){var i=t.single_source_shortest_paths(e,n,r);return t.extract_shortest_path_from_predecessor_list(i,r)},PriorityQueue:{make:function(e){var n,r=t.PriorityQueue,i={};for(n in e=e||{},r)r.hasOwnProperty(n)&&(i[n]=r[n]);return i.queue=[],i.sorter=e.sorter||r.default_sorter,i},default_sorter:function(e,t){return e.cost-t.cost},push:function(e,t){var n={value:e,cost:t};this.queue.push(n),this.queue.sort(this.sorter)},pop:function(){return this.queue.shift()},empty:function(){return 0===this.queue.length}}};e.exports=t}(rA);var iA=rA.exports;!function(e){const t=Qv,n=Kv,r=zv,i=Zv,o=nA,s=Dv,a=ov,l=iA;function c(e){return unescape(encodeURIComponent(e)).length}function u(e,t,n){const r=[];let i;for(;null!==(i=e.exec(n));)r.push({data:i[0],index:i.index,mode:t,length:i[0].length});return r}function d(e){const n=u(s.NUMERIC,t.NUMERIC,e),r=u(s.ALPHANUMERIC,t.ALPHANUMERIC,e);let i,o;a.isKanjiModeEnabled()?(i=u(s.BYTE,t.BYTE,e),o=u(s.KANJI,t.KANJI,e)):(i=u(s.BYTE_KANJI,t.BYTE,e),o=[]);return n.concat(r,i,o).sort(function(e,t){return e.index-t.index}).map(function(e){return{data:e.data,mode:e.mode,length:e.length}})}function f(e,s){switch(s){case t.NUMERIC:return n.getBitsLength(e);case t.ALPHANUMERIC:return r.getBitsLength(e);case t.KANJI:return o.getBitsLength(e);case t.BYTE:return i.getBitsLength(e)}}function h(e,s){let l;const c=t.getBestModeForData(e);if(l=t.from(s,c),l!==t.BYTE&&l.bit<c.bit)throw new Error('"'+e+'" cannot be encoded with mode '+t.toString(l)+".\n Suggested mode is: "+t.toString(c));switch(l!==t.KANJI||a.isKanjiModeEnabled()||(l=t.BYTE),l){case t.NUMERIC:return new n(e);case t.ALPHANUMERIC:return new r(e);case t.KANJI:return new o(e);case t.BYTE:return new i(e)}}e.fromArray=function(e){return e.reduce(function(e,t){return"string"==typeof t?e.push(h(t,null)):t.data&&e.push(h(t.data,t.mode)),e},[])},e.fromString=function(n,r){const i=function(e){const n=[];for(let r=0;r<e.length;r++){const i=e[r];switch(i.mode){case t.NUMERIC:n.push([i,{data:i.data,mode:t.ALPHANUMERIC,length:i.length},{data:i.data,mode:t.BYTE,length:i.length}]);break;case t.ALPHANUMERIC:n.push([i,{data:i.data,mode:t.BYTE,length:i.length}]);break;case t.KANJI:n.push([i,{data:i.data,mode:t.BYTE,length:c(i.data)}]);break;case t.BYTE:n.push([{data:i.data,mode:t.BYTE,length:c(i.data)}])}}return n}(d(n,a.isKanjiModeEnabled())),o=function(e,n){const r={},i={start:{}};let o=["start"];for(let s=0;s<e.length;s++){const a=e[s],l=[];for(let e=0;e<a.length;e++){const c=a[e],u=""+s+e;l.push(u),r[u]={node:c,lastCount:0},i[u]={};for(let e=0;e<o.length;e++){const s=o[e];r[s]&&r[s].node.mode===c.mode?(i[s][u]=f(r[s].lastCount+c.length,c.mode)-f(r[s].lastCount,c.mode),r[s].lastCount+=c.length):(r[s]&&(r[s].lastCount=c.length),i[s][u]=f(c.length,c.mode)+4+t.getCharCountIndicator(c.mode,n))}}o=l}for(let e=0;e<o.length;e++)i[o[e]].end=0;return{map:i,table:r}}(i,r),s=l.find_path(o.map,"start","end"),u=[];for(let e=1;e<s.length-1;e++)u.push(o.table[s[e]].node);return e.fromArray(function(e){return e.reduce(function(e,t){const n=e.length-1>=0?e[e.length-1]:null;return n&&n.mode===t.mode?(e[e.length-1].data+=t.data,e):(e.push(t),e)},[])}(u))},e.rawSplit=function(t){return e.fromArray(d(t,a.isKanjiModeEnabled()))}}(Hv);const oA=ov,sA=cv,aA=dv,lA=hv,cA=pv,uA=gv,dA=yv,fA=wv,hA=Sv,pA=Fv,gA=Ov,mA=Qv,yA=Hv;function wA(e,t,n){const r=e.size,i=gA.getEncodedBits(t,n);let o,s;for(o=0;o<15;o++)s=1==(i>>o&1),o<6?e.set(o,8,s,!0):o<8?e.set(o+1,8,s,!0):e.set(r-15+o,8,s,!0),o<8?e.set(8,r-o-1,s,!0):o<9?e.set(8,15-o-1+1,s,!0):e.set(8,15-o-1,s,!0);e.set(r-8,8,1,!0)}function vA(e,t,n){const r=new aA;n.forEach(function(t){r.put(t.mode.bit,4),r.put(t.getLength(),mA.getCharCountIndicator(t.mode,e)),t.write(r)});const i=8*(oA.getSymbolTotalCodewords(e)-fA.getTotalCodewordsCount(e,t));for(r.getLengthInBits()+4<=i&&r.put(0,4);r.getLengthInBits()%8!=0;)r.putBit(0);const o=(i-r.getLengthInBits())/8;for(let e=0;e<o;e++)r.put(e%2?17:236,8);return function(e,t,n){const r=oA.getSymbolTotalCodewords(t),i=fA.getTotalCodewordsCount(t,n),o=r-i,s=fA.getBlocksCount(t,n),a=r%s,l=s-a,c=Math.floor(r/s),u=Math.floor(o/s),d=u+1,f=c-u,h=new hA(f);let p=0;const g=new Array(s),m=new Array(s);let y=0;const w=new Uint8Array(e.buffer);for(let e=0;e<s;e++){const t=e<l?u:d;g[e]=w.slice(p,p+t),m[e]=h.encode(g[e]),p+=t,y=Math.max(y,t)}const v=new Uint8Array(r);let A,b,k=0;for(A=0;A<y;A++)for(b=0;b<s;b++)A<g[b].length&&(v[k++]=g[b][A]);for(A=0;A<f;A++)for(b=0;b<s;b++)v[k++]=m[b][A];return v}(r,e,t)}function AA(e,t,n,r){let i;if(Array.isArray(e))i=yA.fromArray(e);else{if("string"!=typeof e)throw new Error("Invalid data");{let r=t;if(!r){const t=yA.rawSplit(e);r=pA.getBestVersionForData(t,n)}i=yA.fromString(e,r||40)}}const o=pA.getBestVersionForData(i,n);if(!o)throw new Error("The amount of data is too big to be stored in a QR Code");if(t){if(t<o)throw new Error("\nThe chosen QR Code version cannot contain this amount of data.\nMinimum version required to store current data is: "+o+".\n")}else t=o;const s=vA(t,n,i),a=oA.getSymbolSize(t),l=new lA(a);return function(e,t){const n=e.size,r=uA.getPositions(t);for(let t=0;t<r.length;t++){const i=r[t][0],o=r[t][1];for(let t=-1;t<=7;t++)if(!(i+t<=-1||n<=i+t))for(let r=-1;r<=7;r++)o+r<=-1||n<=o+r||(t>=0&&t<=6&&(0===r||6===r)||r>=0&&r<=6&&(0===t||6===t)||t>=2&&t<=4&&r>=2&&r<=4?e.set(i+t,o+r,!0,!0):e.set(i+t,o+r,!1,!0))}}(l,t),function(e){const t=e.size;for(let n=8;n<t-8;n++){const t=n%2==0;e.set(n,6,t,!0),e.set(6,n,t,!0)}}(l),function(e,t){const n=cA.getPositions(t);for(let t=0;t<n.length;t++){const r=n[t][0],i=n[t][1];for(let t=-2;t<=2;t++)for(let n=-2;n<=2;n++)-2===t||2===t||-2===n||2===n||0===t&&0===n?e.set(r+t,i+n,!0,!0):e.set(r+t,i+n,!1,!0)}}(l,t),wA(l,n,0),t>=7&&function(e,t){const n=e.size,r=pA.getEncodedBits(t);let i,o,s;for(let t=0;t<18;t++)i=Math.floor(t/3),o=t%3+n-8-3,s=1==(r>>t&1),e.set(i,o,s,!0),e.set(o,i,s,!0)}(l,t),function(e,t){const n=e.size;let r=-1,i=n-1,o=7,s=0;for(let a=n-1;a>0;a-=2)for(6===a&&a--;;){for(let n=0;n<2;n++)if(!e.isReserved(i,a-n)){let r=!1;s<t.length&&(r=1==(t[s]>>>o&1)),e.set(i,a-n,r),o--,-1===o&&(s++,o=7)}if(i+=r,i<0||n<=i){i-=r,r=-r;break}}}(l,s),isNaN(r)&&(r=dA.getBestMask(l,wA.bind(null,l,n))),dA.applyMask(r,l),wA(l,n,r),{modules:l,version:t,errorCorrectionLevel:n,maskPattern:r,segments:i}}iv.create=function(e,t){if(void 0===e||""===e)throw new Error("No input text");let n,r,i=sA.M;return void 0!==t&&(i=sA.from(t.errorCorrectionLevel,sA.M),n=pA.from(t.version),r=dA.from(t.maskPattern),t.toSJISFunc&&oA.setToSJISFunction(t.toSJISFunc)),AA(e,n,i,r)};var bA={},kA={};!function(e){function t(e){if("number"==typeof e&&(e=e.toString()),"string"!=typeof e)throw new Error("Color should be defined as hex string");let t=e.slice().replace("#","").split("");if(t.length<3||5===t.length||t.length>8)throw new Error("Invalid hex color: "+e);3!==t.length&&4!==t.length||(t=Array.prototype.concat.apply([],t.map(function(e){return[e,e]}))),6===t.length&&t.push("F","F");const n=parseInt(t.join(""),16);return{r:n>>24&255,g:n>>16&255,b:n>>8&255,a:255&n,hex:"#"+t.slice(0,6).join("")}}e.getOptions=function(e){e||(e={}),e.color||(e.color={});const n=void 0===e.margin||null===e.margin||e.margin<0?4:e.margin,r=e.width&&e.width>=21?e.width:void 0,i=e.scale||4;return{width:r,scale:r?4:i,margin:n,color:{dark:t(e.color.dark||"#000000ff"),light:t(e.color.light||"#ffffffff")},type:e.type,rendererOpts:e.rendererOpts||{}}},e.getScale=function(e,t){return t.width&&t.width>=e+2*t.margin?t.width/(e+2*t.margin):t.scale},e.getImageWidth=function(t,n){const r=e.getScale(t,n);return Math.floor((t+2*n.margin)*r)},e.qrToImageData=function(t,n,r){const i=n.modules.size,o=n.modules.data,s=e.getScale(i,r),a=Math.floor((i+2*r.margin)*s),l=r.margin*s,c=[r.color.light,r.color.dark];for(let e=0;e<a;e++)for(let n=0;n<a;n++){let u=4*(e*a+n),d=r.color.light;if(e>=l&&n>=l&&e<a-l&&n<a-l){d=c[o[Math.floor((e-l)/s)*i+Math.floor((n-l)/s)]?1:0]}t[u++]=d.r,t[u++]=d.g,t[u++]=d.b,t[u]=d.a}}}(kA),function(e){const t=kA;e.render=function(e,n,r){let i=r,o=n;void 0!==i||n&&n.getContext||(i=n,n=void 0),n||(o=function(){try{return document.createElement("canvas")}catch(e){throw new Error("You need to specify a canvas element")}}()),i=t.getOptions(i);const s=t.getImageWidth(e.modules.size,i),a=o.getContext("2d"),l=a.createImageData(s,s);return t.qrToImageData(l.data,e,i),function(e,t,n){e.clearRect(0,0,t.width,t.height),t.style||(t.style={}),t.height=n,t.width=n,t.style.height=n+"px",t.style.width=n+"px"}(a,o,s),a.putImageData(l,0,0),o},e.renderToDataURL=function(t,n,r){let i=r;void 0!==i||n&&n.getContext||(i=n,n=void 0),i||(i={});const o=e.render(t,n,i),s=i.type||"image/png",a=i.rendererOpts||{};return o.toDataURL(s,a.quality)}}(bA);var IA={};const EA=kA;function CA(e,t){const n=e.a/255,r=t+'="'+e.hex+'"';return n<1?r+" "+t+'-opacity="'+n.toFixed(2).slice(1)+'"':r}function xA(e,t,n){let r=e+t;return void 0!==n&&(r+=" "+n),r}IA.render=function(e,t,n){const r=EA.getOptions(t),i=e.modules.size,o=e.modules.data,s=i+2*r.margin,a=r.color.light.a?"<path "+CA(r.color.light,"fill")+' d="M0 0h'+s+"v"+s+'H0z"/>':"",l="<path "+CA(r.color.dark,"stroke")+' d="'+function(e,t,n){let r="",i=0,o=!1,s=0;for(let a=0;a<e.length;a++){const l=Math.floor(a%t),c=Math.floor(a/t);l||o||(o=!0),e[a]?(s++,a>0&&l>0&&e[a-1]||(r+=o?xA("M",l+n,.5+c+n):xA("m",i,0),i=0,o=!1),l+1<t&&e[a+1]||(r+=xA("h",s),s=0)):i++}return r}(o,i,r.margin)+'"/>',c='viewBox="0 0 '+s+" "+s+'"',u='<svg xmlns="http://www.w3.org/2000/svg" '+(r.width?'width="'+r.width+'" height="'+r.width+'" ':"")+c+' shape-rendering="crispEdges">'+a+l+"</svg>\n";return"function"==typeof n&&n(null,u),u};const BA=function(){return"function"==typeof Promise&&Promise.prototype&&Promise.prototype.then},SA=iv,FA=bA,QA=IA;function RA(e,t,n,r,i){const o=[].slice.call(arguments,1),s=o.length,a="function"==typeof o[s-1];if(!a&&!BA())throw new Error("Callback required as last argument");if(!a){if(s<1)throw new Error("Too few arguments provided");return 1===s?(n=t,t=r=void 0):2!==s||t.getContext||(r=n,n=t,t=void 0),new Promise(function(i,o){try{const o=SA.create(n,r);i(e(o,t,r))}catch(e){o(e)}})}if(s<2)throw new Error("Too few arguments provided");2===s?(i=n,n=t,t=r=void 0):3===s&&(t.getContext&&void 0===i?(i=r,r=void 0):(i=r,r=n,n=t,t=void 0));try{const o=SA.create(n,r);i(null,e(o,t,r))}catch(e){i(e)}}function DA(e,t,n){return e&t^~e&n}function PA(e,t,n){return e&t^e&n^t&n}rv.create=SA.create,rv.toCanvas=RA.bind(null,FA.render),rv.toDataURL=RA.bind(null,FA.renderToDataURL),rv.toString=RA.bind(null,function(e,t,n){return QA.render(e,n)});class TA extends zu{constructor(e,t,n,r){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=r,this.buffer=new Uint8Array(e),this.view=Tu(this.buffer)}update(e){Du(this),Qu(e=Vu(e));const{view:t,buffer:n,blockLen:r}=this,i=e.length;for(let o=0;o<i;){const s=Math.min(r-this.pos,i-o);if(s===r){const t=Tu(e);for(;r<=i-o;o+=r)this.process(t,o);continue}n.set(e.subarray(o,o+s),this.pos),this.pos+=s,o+=s,this.pos===r&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){Du(this),function(e,t){Qu(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:i}=this;let{pos:o}=this;t[o++]=128,Pu(this.buffer.subarray(o)),this.padOffset>r-o&&(this.process(n,0),o=0);for(let e=o;e<r;e++)t[e]=0;!function(e,t,n,r){if("function"==typeof e.setBigUint64)return e.setBigUint64(t,n,r);const i=BigInt(32),o=BigInt(4294967295),s=Number(n>>i&o),a=Number(n&o),l=r?4:0,c=r?0:4;e.setUint32(t+l,s,r),e.setUint32(t+c,a,r)}(n,r-8,BigInt(8*this.length),i),this.process(n,0);const s=Tu(e),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const l=a/4,c=this.get();if(l>c.length)throw new Error("_sha2: outputLen bigger than state");for(let e=0;e<l;e++)s.setUint32(4*e,c[e],i)}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:i,destroyed:o,pos:s}=this;return e.destroyed=o,e.finished=i,e.length=r,e.pos=s,r%t&&e.buffer.set(n),e}clone(){return this._cloneInto()}}const UA=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),$A=Uint32Array.from([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]),NA=new Uint32Array(64);class LA extends TA{constructor(e=32){super(64,e,8,!1),this.A=0|UA[0],this.B=0|UA[1],this.C=0|UA[2],this.D=0|UA[3],this.E=0|UA[4],this.F=0|UA[5],this.G=0|UA[6],this.H=0|UA[7]}get(){const{A:e,B:t,C:n,D:r,E:i,F:o,G:s,H:a}=this;return[e,t,n,r,i,o,s,a]}set(e,t,n,r,i,o,s,a){this.A=0|e,this.B=0|t,this.C=0|n,this.D=0|r,this.E=0|i,this.F=0|o,this.G=0|s,this.H=0|a}process(e,t){for(let n=0;n<16;n++,t+=4)NA[n]=e.getUint32(t,!1);for(let e=16;e<64;e++){const t=NA[e-15],n=NA[e-2],r=Uu(t,7)^Uu(t,18)^t>>>3,i=Uu(n,17)^Uu(n,19)^n>>>10;NA[e]=i+NA[e-7]+r+NA[e-16]|0}let{A:n,B:r,C:i,D:o,E:s,F:a,G:l,H:c}=this;for(let e=0;e<64;e++){const t=c+(Uu(s,6)^Uu(s,11)^Uu(s,25))+DA(s,a,l)+$A[e]+NA[e]|0,u=(Uu(n,2)^Uu(n,13)^Uu(n,22))+PA(n,r,i)|0;c=l,l=a,a=s,s=o+t|0,o=i,i=r,r=n,n=t+u|0}n=n+this.A|0,r=r+this.B|0,i=i+this.C|0,o=o+this.D|0,s=s+this.E|0,a=a+this.F|0,l=l+this.G|0,c=c+this.H|0,this.set(n,r,i,o,s,a,l,c)}roundClean(){Pu(NA)}destroy(){this.set(0,0,0,0,0,0,0,0),Pu(this.buffer)}}const OA=Yu(()=>new LA);class MA extends zu{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,Ru(e);const n=Vu(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,i=new Uint8Array(r);i.set(n.length>r?e.create().update(n).digest():n);for(let e=0;e<i.length;e++)i[e]^=54;this.iHash.update(i),this.oHash=e.create();for(let e=0;e<i.length;e++)i[e]^=106;this.oHash.update(i),Pu(i)}update(e){return Du(this),this.iHash.update(e),this}digestInto(e){Du(this),Qu(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:i,blockLen:o,outputLen:s}=this;return e.finished=r,e.destroyed=i,e.blockLen=o,e.outputLen=s,e.oHash=t._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}const _A=(e,t,n)=>new MA(e,t).update(n).digest();_A.create=(e,t)=>new MA(e,t);
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
const HA=BigInt(0),jA=BigInt(1);function GA(e,t=""){if("boolean"!=typeof e){throw new Error((t&&`"${t}"`)+"expected boolean, got type="+typeof e)}return e}function KA(e,t,n=""){const r=Su(e),i=e?.length,o=void 0!==t;if(!r||o&&i!==t){throw new Error((n&&`"${n}" `)+"expected Uint8Array"+(o?` of length ${t}`:"")+", got "+(r?`length=${i}`:"type="+typeof e))}return e}function JA(e){const t=e.toString(16);return 1&t.length?"0"+t:t}function VA(e){if("string"!=typeof e)throw new Error("hex string expected, got "+typeof e);return""===e?HA:BigInt("0x"+e)}function qA(e){return VA(Lu(e))}function zA(e){return Qu(e),VA(Lu(Uint8Array.from(e).reverse()))}function YA(e,t){return Ju(e.toString(16).padStart(2*t,"0"))}function WA(e,t){return YA(e,t).reverse()}function ZA(e,t,n){let r;if("string"==typeof t)try{r=Ju(t)}catch(t){throw new Error(e+" must be hex string or Uint8Array, cause: "+t)}else{if(!Su(t))throw new Error(e+" must be hex string or Uint8Array");r=Uint8Array.from(t)}const i=r.length;if("number"==typeof n&&i!==n)throw new Error(e+" of length "+n+" expected, got "+i);return r}const XA=e=>"bigint"==typeof e&&HA<=e;function eb(e,t,n,r){if(!function(e,t,n){return XA(e)&&XA(t)&&XA(n)&&t<=e&&e<n}(t,n,r))throw new Error("expected valid "+e+": "+n+" <= n < "+r+", got "+t)}function tb(e){let t;for(t=0;e>HA;e>>=jA,t+=1);return t}const nb=e=>(jA<<BigInt(e))-jA;function rb(e,t,n={}){if(!e||"object"!=typeof e)throw new Error("expected valid options object");function r(t,n,r){const i=e[t];if(r&&void 0===i)return;const o=typeof i;if(o!==n||null===i)throw new Error(`param "${t}" is invalid: expected ${n}, got ${o}`)}Object.entries(t).forEach(([e,t])=>r(e,t,!1)),Object.entries(n).forEach(([e,t])=>r(e,t,!0))}function ib(e){const t=new WeakMap;return(n,...r)=>{const i=t.get(n);if(void 0!==i)return i;const o=e(n,...r);return t.set(n,o),o}}
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const ob=BigInt(0),sb=BigInt(1),ab=BigInt(2),lb=BigInt(3),cb=BigInt(4),ub=BigInt(5),db=BigInt(7),fb=BigInt(8),hb=BigInt(9),pb=BigInt(16);function gb(e,t){const n=e%t;return n>=ob?n:t+n}function mb(e,t,n){let r=e;for(;t-- >ob;)r*=r,r%=n;return r}function yb(e,t){if(e===ob)throw new Error("invert: expected non-zero number");if(t<=ob)throw new Error("invert: expected positive modulus, got "+t);let n=gb(e,t),r=t,i=ob,o=sb;for(;n!==ob;){const e=r%n,t=i-o*(r/n);r=n,n=e,i=o,o=t}if(r!==sb)throw new Error("invert: does not exist");return gb(i,t)}function wb(e,t,n){if(!e.eql(e.sqr(t),n))throw new Error("Cannot find square root")}function vb(e,t){const n=(e.ORDER+sb)/cb,r=e.pow(t,n);return wb(e,r,t),r}function Ab(e,t){const n=(e.ORDER-ub)/fb,r=e.mul(t,ab),i=e.pow(r,n),o=e.mul(t,i),s=e.mul(e.mul(o,ab),i),a=e.mul(o,e.sub(s,e.ONE));return wb(e,a,t),a}function bb(e){if(e<lb)throw new Error("sqrt is not defined for small field");let t=e-sb,n=0;for(;t%ab===ob;)t/=ab,n++;let r=ab;const i=Bb(e);for(;1===Cb(i,r);)if(r++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(1===n)return vb;let o=i.pow(r,t);const s=(t+sb)/ab;return function(e,r){if(e.is0(r))return r;if(1!==Cb(e,r))throw new Error("Cannot find square root");let i=n,a=e.mul(e.ONE,o),l=e.pow(r,t),c=e.pow(r,s);for(;!e.eql(l,e.ONE);){if(e.is0(l))return e.ZERO;let t=1,n=e.sqr(l);for(;!e.eql(n,e.ONE);)if(t++,n=e.sqr(n),t===i)throw new Error("Cannot find square root");const r=sb<<BigInt(i-t-1),o=e.pow(a,r);i=t,a=e.sqr(o),l=e.mul(l,a),c=e.mul(c,o)}return c}}function kb(e){return e%cb===lb?vb:e%fb===ub?Ab:e%pb===hb?function(e){const t=Bb(e),n=bb(e),r=n(t,t.neg(t.ONE)),i=n(t,r),o=n(t,t.neg(r)),s=(e+db)/pb;return(e,t)=>{let n=e.pow(t,s),a=e.mul(n,r);const l=e.mul(n,i),c=e.mul(n,o),u=e.eql(e.sqr(a),t),d=e.eql(e.sqr(l),t);n=e.cmov(n,a,u),a=e.cmov(c,l,d);const f=e.eql(e.sqr(a),t),h=e.cmov(n,a,f);return wb(e,h,t),h}}(e):bb(e)}const Ib=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Eb(e,t,n=!1){const r=new Array(t.length).fill(n?e.ZERO:void 0),i=t.reduce((t,n,i)=>e.is0(n)?t:(r[i]=t,e.mul(t,n)),e.ONE),o=e.inv(i);return t.reduceRight((t,n,i)=>e.is0(n)?t:(r[i]=e.mul(t,r[i]),e.mul(t,n)),o),r}function Cb(e,t){const n=(e.ORDER-sb)/ab,r=e.pow(t,n),i=e.eql(r,e.ONE),o=e.eql(r,e.ZERO),s=e.eql(r,e.neg(e.ONE));if(!i&&!o&&!s)throw new Error("invalid Legendre symbol result");return i?1:o?0:-1}function xb(e,t){void 0!==t&&Fu(t);const n=void 0!==t?t:e.toString(2).length;return{nBitLength:n,nByteLength:Math.ceil(n/8)}}function Bb(e,t,n=!1,r={}){if(e<=ob)throw new Error("invalid field: expected ORDER > 0, got "+e);let i,o,s,a=!1;if("object"==typeof t&&null!=t){if(r.sqrt||n)throw new Error("cannot specify opts in two arguments");const e=t;e.BITS&&(i=e.BITS),e.sqrt&&(o=e.sqrt),"boolean"==typeof e.isLE&&(n=e.isLE),"boolean"==typeof e.modFromBytes&&(a=e.modFromBytes),s=e.allowedLengths}else"number"==typeof t&&(i=t),r.sqrt&&(o=r.sqrt);const{nBitLength:l,nByteLength:c}=xb(e,i);if(c>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let u;const d=Object.freeze({ORDER:e,isLE:n,BITS:l,BYTES:c,MASK:nb(l),ZERO:ob,ONE:sb,allowedLengths:s,create:t=>gb(t,e),isValid:t=>{if("bigint"!=typeof t)throw new Error("invalid field element: expected bigint, got "+typeof t);return ob<=t&&t<e},is0:e=>e===ob,isValidNot0:e=>!d.is0(e)&&d.isValid(e),isOdd:e=>(e&sb)===sb,neg:t=>gb(-t,e),eql:(e,t)=>e===t,sqr:t=>gb(t*t,e),add:(t,n)=>gb(t+n,e),sub:(t,n)=>gb(t-n,e),mul:(t,n)=>gb(t*n,e),pow:(e,t)=>function(e,t,n){if(n<ob)throw new Error("invalid exponent, negatives unsupported");if(n===ob)return e.ONE;if(n===sb)return t;let r=e.ONE,i=t;for(;n>ob;)n&sb&&(r=e.mul(r,i)),i=e.sqr(i),n>>=sb;return r}(d,e,t),div:(t,n)=>gb(t*yb(n,e),e),sqrN:e=>e*e,addN:(e,t)=>e+t,subN:(e,t)=>e-t,mulN:(e,t)=>e*t,inv:t=>yb(t,e),sqrt:o||(t=>(u||(u=kb(e)),u(d,t))),toBytes:e=>n?WA(e,c):YA(e,c),fromBytes:(t,r=!0)=>{if(s){if(!s.includes(t.length)||t.length>c)throw new Error("Field.fromBytes: expected "+s+" bytes, got "+t.length);const e=new Uint8Array(c);e.set(t,n?0:e.length-t.length),t=e}if(t.length!==c)throw new Error("Field.fromBytes: expected "+c+" bytes, got "+t.length);let i=n?zA(t):qA(t);if(a&&(i=gb(i,e)),!r&&!d.isValid(i))throw new Error("invalid field element: outside of range 0..ORDER");return i},invertBatch:e=>Eb(d,e),cmov:(e,t,n)=>n?t:e});return Object.freeze(d)}function Sb(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 Fb(e){const t=Sb(e);return t+Math.ceil(t/2)}
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
const Qb=BigInt(0),Rb=BigInt(1);function Db(e,t){const n=t.negate();return e?n:t}function Pb(e,t){const n=Eb(e.Fp,t.map(e=>e.Z));return t.map((t,r)=>e.fromAffine(t.toAffine(n[r])))}function Tb(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function Ub(e,t){Tb(e,t);const n=2**e;return{windows:Math.ceil(t/e)+1,windowSize:2**(e-1),mask:nb(e),maxNumber:n,shiftBy:BigInt(e)}}function $b(e,t,n){const{windowSize:r,mask:i,maxNumber:o,shiftBy:s}=n;let a=Number(e&i),l=e>>s;a>r&&(a-=o,l+=Rb);const c=t*r;return{nextN:l,offset:c+Math.abs(a)-1,isZero:0===a,isNeg:a<0,isNegF:t%2!=0,offsetF:c}}const Nb=new WeakMap,Lb=new WeakMap;function Ob(e){return Lb.get(e)||1}function Mb(e){if(e!==Qb)throw new Error("invalid wNAF")}class _b{constructor(e,t){this.BASE=e.BASE,this.ZERO=e.ZERO,this.Fn=e.Fn,this.bits=t}_unsafeLadder(e,t,n=this.ZERO){let r=e;for(;t>Qb;)t&Rb&&(n=n.add(r)),r=r.double(),t>>=Rb;return n}precomputeWindow(e,t){const{windows:n,windowSize:r}=Ub(t,this.bits),i=[];let o=e,s=o;for(let e=0;e<n;e++){s=o,i.push(s);for(let e=1;e<r;e++)s=s.add(o),i.push(s);o=s.double()}return i}wNAF(e,t,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let r=this.ZERO,i=this.BASE;const o=Ub(e,this.bits);for(let e=0;e<o.windows;e++){const{nextN:s,offset:a,isZero:l,isNeg:c,isNegF:u,offsetF:d}=$b(n,e,o);n=s,l?i=i.add(Db(u,t[d])):r=r.add(Db(c,t[a]))}return Mb(n),{p:r,f:i}}wNAFUnsafe(e,t,n,r=this.ZERO){const i=Ub(e,this.bits);for(let e=0;e<i.windows&&n!==Qb;e++){const{nextN:o,offset:s,isZero:a,isNeg:l}=$b(n,e,i);if(n=o,!a){const e=t[s];r=r.add(l?e.negate():e)}}return Mb(n),r}getPrecomputes(e,t,n){let r=Nb.get(t);return r||(r=this.precomputeWindow(t,e),1!==e&&("function"==typeof n&&(r=n(r)),Nb.set(t,r))),r}cached(e,t,n){const r=Ob(e);return this.wNAF(r,this.getPrecomputes(r,e,n),t)}unsafe(e,t,n,r){const i=Ob(e);return 1===i?this._unsafeLadder(e,t,r):this.wNAFUnsafe(i,this.getPrecomputes(i,e,n),t,r)}createCache(e,t){Tb(t,this.bits),Lb.set(e,t),Nb.delete(e)}hasCache(e){return 1!==Ob(e)}}function Hb(e,t,n,r){!function(e,t){if(!Array.isArray(e))throw new Error("array expected");e.forEach((e,n)=>{if(!(e instanceof t))throw new Error("invalid point at index "+n)})}(n,e),function(e,t){if(!Array.isArray(e))throw new Error("array of scalars expected");e.forEach((e,n)=>{if(!t.isValid(e))throw new Error("invalid scalar at index "+n)})}(r,t);const i=n.length,o=r.length;if(i!==o)throw new Error("arrays of points and scalars must have equal length");const s=e.ZERO,a=tb(BigInt(i));let l=1;a>12?l=a-3:a>4?l=a-2:a>0&&(l=2);const c=nb(l),u=new Array(Number(c)+1).fill(s);let d=s;for(let e=Math.floor((t.BITS-1)/l)*l;e>=0;e-=l){u.fill(s);for(let t=0;t<o;t++){const i=r[t],o=Number(i>>BigInt(e)&c);u[o]=u[o].add(n[t])}let t=s;for(let e=u.length-1,n=s;e>0;e--)n=n.add(u[e]),t=t.add(n);if(d=d.add(t),0!==e)for(let e=0;e<l;e++)d=d.double()}return d}function jb(e,t,n){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return function(e){const t=Ib.reduce((e,t)=>(e[t]="function",e),{ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"});rb(e,t)}(t),t}return Bb(e,{isLE:n})}
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
const Gb=(e,t)=>(e+(e>=0?t:-t)/Wb)/t;function Kb(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function Jb(e,t){const n={};for(let r of Object.keys(t))n[r]=void 0===e[r]?t[r]:e[r];return GA(n.lowS,"lowS"),GA(n.prehash,"prehash"),void 0!==n.format&&Kb(n.format),n}class Vb extends Error{constructor(e=""){super(e)}}const qb={Err:Vb,_tlv:{encode:(e,t)=>{const{Err:n}=qb;if(e<0||e>256)throw new n("tlv.encode: wrong tag");if(1&t.length)throw new n("tlv.encode: unpadded data");const r=t.length/2,i=JA(r);if(i.length/2&128)throw new n("tlv.encode: long form length too big");const o=r>127?JA(i.length/2|128):"";return JA(e)+o+i+t},decode(e,t){const{Err:n}=qb;let r=0;if(e<0||e>256)throw new n("tlv.encode: wrong tag");if(t.length<2||t[r++]!==e)throw new n("tlv.decode: wrong tlv");const i=t[r++];let o=0;if(!!(128&i)){const e=127&i;if(!e)throw new n("tlv.decode(long): indefinite length not supported");if(e>4)throw new n("tlv.decode(long): byte length is too big");const s=t.subarray(r,r+e);if(s.length!==e)throw new n("tlv.decode: length bytes not complete");if(0===s[0])throw new n("tlv.decode(long): zero leftmost byte");for(const e of s)o=o<<8|e;if(r+=e,o<128)throw new n("tlv.decode(long): not minimal encoding")}else o=i;const s=t.subarray(r,r+o);if(s.length!==o)throw new n("tlv.decode: wrong value length");return{v:s,l:t.subarray(r+o)}}},_int:{encode(e){const{Err:t}=qb;if(e<zb)throw new t("integer: negative integers are not allowed");let n=JA(e);if(8&Number.parseInt(n[0],16)&&(n="00"+n),1&n.length)throw new t("unexpected DER parsing assertion: unpadded hex");return n},decode(e){const{Err:t}=qb;if(128&e[0])throw new t("invalid signature integer: negative");if(0===e[0]&&!(128&e[1]))throw new t("invalid signature integer: unnecessary leading zero");return qA(e)}},toSig(e){const{Err:t,_int:n,_tlv:r}=qb,i=ZA("signature",e),{v:o,l:s}=r.decode(48,i);if(s.length)throw new t("invalid signature: left bytes after parsing");const{v:a,l:l}=r.decode(2,o),{v:c,l:u}=r.decode(2,l);if(u.length)throw new t("invalid signature: left bytes after parsing");return{r:n.decode(a),s:n.decode(c)}},hexFromSig(e){const{_tlv:t,_int:n}=qb,r=t.encode(2,n.encode(e.r))+t.encode(2,n.encode(e.s));return t.encode(48,r)}},zb=BigInt(0),Yb=BigInt(1),Wb=BigInt(2),Zb=BigInt(3),Xb=BigInt(4);function ek(e,t){const{BYTES:n}=e;let r;if("bigint"==typeof t)r=t;else{let i=ZA("private key",t);try{r=e.fromBytes(i)}catch(e){throw new Error(`invalid private key: expected ui8a of size ${n}, got ${typeof t}`)}}if(!e.isValidNot0(r))throw new Error("invalid private key: out of range [1..N-1]");return r}function tk(e,t={}){const n=function(e,t,n={},r){if(void 0===r&&(r="edwards"===e),!t||"object"!=typeof t)throw new Error(`expected valid ${e} CURVE object`);for(const e of["p","n","h"]){const n=t[e];if(!("bigint"==typeof n&&n>Qb))throw new Error(`CURVE.${e} must be positive bigint`)}const i=jb(t.p,n.Fp,r),o=jb(t.n,n.Fn,r),s=["Gx","Gy","a","weierstrass"===e?"b":"d"];for(const e of s)if(!i.isValid(t[e]))throw new Error(`CURVE.${e} must be valid field element of CURVE.Fp`);return{CURVE:t=Object.freeze(Object.assign({},t)),Fp:i,Fn:o}}("weierstrass",e,t),{Fp:r,Fn:i}=n;let o=n.CURVE;const{h:s,n:a}=o;rb(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});const{endo:l}=t;if(l&&(!r.is0(o.a)||"bigint"!=typeof l.beta||!Array.isArray(l.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');const c=rk(r,i);function u(){if(!r.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}const d=t.toBytes||function(e,t,n){const{x:i,y:o}=t.toAffine(),s=r.toBytes(i);if(GA(n,"isCompressed"),n){u();return qu(nk(!r.isOdd(o)),s)}return qu(Uint8Array.of(4),s,r.toBytes(o))},f=t.fromBytes||function(e){KA(e,void 0,"Point");const{publicKey:t,publicKeyUncompressed:n}=c,i=e.length,o=e[0],s=e.subarray(1);if(i!==t||2!==o&&3!==o){if(i===n&&4===o){const e=r.BYTES,t=r.fromBytes(s.subarray(0,e)),n=r.fromBytes(s.subarray(e,2*e));if(!p(t,n))throw new Error("bad point: is not on curve");return{x:t,y:n}}throw new Error(`bad point: got length ${i}, expected compressed=${t} or uncompressed=${n}`)}{const e=r.fromBytes(s);if(!r.isValid(e))throw new Error("bad point: is not on curve, wrong x");const t=h(e);let n;try{n=r.sqrt(t)}catch(e){const t=e instanceof Error?": "+e.message:"";throw new Error("bad point: is not on curve, sqrt error"+t)}u();return!(1&~o)!==r.isOdd(n)&&(n=r.neg(n)),{x:e,y:n}}};function h(e){const t=r.sqr(e),n=r.mul(t,e);return r.add(r.add(n,r.mul(e,o.a)),o.b)}function p(e,t){const n=r.sqr(t),i=h(e);return r.eql(n,i)}if(!p(o.Gx,o.Gy))throw new Error("bad curve params: generator point");const g=r.mul(r.pow(o.a,Zb),Xb),m=r.mul(r.sqr(o.b),BigInt(27));if(r.is0(r.add(g,m)))throw new Error("bad curve params: a or b");function y(e,t,n=!1){if(!r.isValid(t)||n&&r.is0(t))throw new Error(`bad point coordinate ${e}`);return t}function w(e){if(!(e instanceof I))throw new Error("ProjectivePoint expected")}function v(e){if(!l||!l.basises)throw new Error("no endo");return function(e,t,n){const[[r,i],[o,s]]=t,a=Gb(s*e,n),l=Gb(-i*e,n);let c=e-a*r-l*o,u=-a*i-l*s;const d=c<zb,f=u<zb;d&&(c=-c),f&&(u=-u);const h=nb(Math.ceil(tb(n)/2))+Yb;if(c<zb||c>=h||u<zb||u>=h)throw new Error("splitScalar (endomorphism): failed, k="+e);return{k1neg:d,k1:c,k2neg:f,k2:u}}(e,l.basises,i.ORDER)}const A=ib((e,t)=>{const{X:n,Y:i,Z:o}=e;if(r.eql(o,r.ONE))return{x:n,y:i};const s=e.is0();null==t&&(t=s?r.ONE:r.inv(o));const a=r.mul(n,t),l=r.mul(i,t),c=r.mul(o,t);if(s)return{x:r.ZERO,y:r.ZERO};if(!r.eql(c,r.ONE))throw new Error("invZ was invalid");return{x:a,y:l}}),b=ib(e=>{if(e.is0()){if(t.allowInfinityPoint&&!r.is0(e.Y))return;throw new Error("bad point: ZERO")}const{x:n,y:i}=e.toAffine();if(!r.isValid(n)||!r.isValid(i))throw new Error("bad point: x or y not field elements");if(!p(n,i))throw new Error("bad point: equation left != right");if(!e.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function k(e,t,n,i,o){return n=new I(r.mul(n.X,e),n.Y,n.Z),t=Db(i,t),n=Db(o,n),t.add(n)}class I{constructor(e,t,n){this.X=y("x",e),this.Y=y("y",t,!0),this.Z=y("z",n),Object.freeze(this)}static CURVE(){return o}static fromAffine(e){const{x:t,y:n}=e||{};if(!e||!r.isValid(t)||!r.isValid(n))throw new Error("invalid affine point");if(e instanceof I)throw new Error("projective point not allowed");return r.is0(t)&&r.is0(n)?I.ZERO:new I(t,n,r.ONE)}static fromBytes(e){const t=I.fromAffine(f(KA(e,void 0,"point")));return t.assertValidity(),t}static fromHex(e){return I.fromBytes(ZA("pointHex",e))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(e=8,t=!0){return C.createCache(this,e),t||this.multiply(Zb),this}assertValidity(){b(this)}hasEvenY(){const{y:e}=this.toAffine();if(!r.isOdd)throw new Error("Field doesn't support isOdd");return!r.isOdd(e)}equals(e){w(e);const{X:t,Y:n,Z:i}=this,{X:o,Y:s,Z:a}=e,l=r.eql(r.mul(t,a),r.mul(o,i)),c=r.eql(r.mul(n,a),r.mul(s,i));return l&&c}negate(){return new I(this.X,r.neg(this.Y),this.Z)}double(){const{a:e,b:t}=o,n=r.mul(t,Zb),{X:i,Y:s,Z:a}=this;let l=r.ZERO,c=r.ZERO,u=r.ZERO,d=r.mul(i,i),f=r.mul(s,s),h=r.mul(a,a),p=r.mul(i,s);return p=r.add(p,p),u=r.mul(i,a),u=r.add(u,u),l=r.mul(e,u),c=r.mul(n,h),c=r.add(l,c),l=r.sub(f,c),c=r.add(f,c),c=r.mul(l,c),l=r.mul(p,l),u=r.mul(n,u),h=r.mul(e,h),p=r.sub(d,h),p=r.mul(e,p),p=r.add(p,u),u=r.add(d,d),d=r.add(u,d),d=r.add(d,h),d=r.mul(d,p),c=r.add(c,d),h=r.mul(s,a),h=r.add(h,h),d=r.mul(h,p),l=r.sub(l,d),u=r.mul(h,f),u=r.add(u,u),u=r.add(u,u),new I(l,c,u)}add(e){w(e);const{X:t,Y:n,Z:i}=this,{X:s,Y:a,Z:l}=e;let c=r.ZERO,u=r.ZERO,d=r.ZERO;const f=o.a,h=r.mul(o.b,Zb);let p=r.mul(t,s),g=r.mul(n,a),m=r.mul(i,l),y=r.add(t,n),v=r.add(s,a);y=r.mul(y,v),v=r.add(p,g),y=r.sub(y,v),v=r.add(t,i);let A=r.add(s,l);return v=r.mul(v,A),A=r.add(p,m),v=r.sub(v,A),A=r.add(n,i),c=r.add(a,l),A=r.mul(A,c),c=r.add(g,m),A=r.sub(A,c),d=r.mul(f,v),c=r.mul(h,m),d=r.add(c,d),c=r.sub(g,d),d=r.add(g,d),u=r.mul(c,d),g=r.add(p,p),g=r.add(g,p),m=r.mul(f,m),v=r.mul(h,v),g=r.add(g,m),m=r.sub(p,m),m=r.mul(f,m),v=r.add(v,m),p=r.mul(g,v),u=r.add(u,p),p=r.mul(A,v),c=r.mul(y,c),c=r.sub(c,p),p=r.mul(y,g),d=r.mul(A,d),d=r.add(d,p),new I(c,u,d)}subtract(e){return this.add(e.negate())}is0(){return this.equals(I.ZERO)}multiply(e){const{endo:n}=t;if(!i.isValidNot0(e))throw new Error("invalid scalar: out of range");let r,o;const s=e=>C.cached(this,e,e=>Pb(I,e));if(n){const{k1neg:t,k1:i,k2neg:a,k2:l}=v(e),{p:c,f:u}=s(i),{p:d,f:f}=s(l);o=u.add(f),r=k(n.beta,c,d,t,a)}else{const{p:t,f:n}=s(e);r=t,o=n}return Pb(I,[r,o])[0]}multiplyUnsafe(e){const{endo:n}=t,r=this;if(!i.isValid(e))throw new Error("invalid scalar: out of range");if(e===zb||r.is0())return I.ZERO;if(e===Yb)return r;if(C.hasCache(this))return this.multiply(e);if(n){const{k1neg:t,k1:i,k2neg:o,k2:s}=v(e),{p1:a,p2:l}=function(e,t,n,r){let i=t,o=e.ZERO,s=e.ZERO;for(;n>Qb||r>Qb;)n&Rb&&(o=o.add(i)),r&Rb&&(s=s.add(i)),i=i.double(),n>>=Rb,r>>=Rb;return{p1:o,p2:s}}(I,r,i,s);return k(n.beta,a,l,t,o)}return C.unsafe(r,e)}multiplyAndAddUnsafe(e,t,n){const r=this.multiplyUnsafe(t).add(e.multiplyUnsafe(n));return r.is0()?void 0:r}toAffine(e){return A(this,e)}isTorsionFree(){const{isTorsionFree:e}=t;return s===Yb||(e?e(I,this):C.unsafe(this,a).is0())}clearCofactor(){const{clearCofactor:e}=t;return s===Yb?this:e?e(I,this):this.multiplyUnsafe(s)}isSmallOrder(){return this.multiplyUnsafe(s).is0()}toBytes(e=!0){return GA(e,"isCompressed"),this.assertValidity(),d(I,this,e)}toHex(e=!0){return Lu(this.toBytes(e))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get px(){return this.X}get py(){return this.X}get pz(){return this.Z}toRawBytes(e=!0){return this.toBytes(e)}_setWindowSize(e){this.precompute(e)}static normalizeZ(e){return Pb(I,e)}static msm(e,t){return Hb(I,i,e,t)}static fromPrivateKey(e){return I.BASE.multiply(ek(i,e))}}I.BASE=new I(o.Gx,o.Gy,r.ONE),I.ZERO=new I(r.ZERO,r.ONE,r.ZERO),I.Fp=r,I.Fn=i;const E=i.BITS,C=new _b(I,t.endo?Math.ceil(E/2):E);return I.BASE.precompute(8),I}function nk(e){return Uint8Array.of(e?2:3)}function rk(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function ik(e,t={}){const{Fn:n}=e,r=t.randomBytes||Wu,i=Object.assign(rk(e.Fp,n),{seed:Fb(n.ORDER)});function o(e){try{return!!ek(n,e)}catch(e){return!1}}function s(e=r(i.seed)){return function(e,t,n=!1){const r=e.length,i=Sb(t),o=Fb(t);if(r<16||r<o||r>1024)throw new Error("expected "+o+"-1024 bytes of input, got "+r);const s=gb(n?zA(e):qA(e),t-sb)+sb;return n?WA(s,i):YA(s,i)}(KA(e,i.seed,"seed"),n.ORDER)}function a(t,r=!0){return e.BASE.multiply(ek(n,t)).toBytes(r)}function l(t){if("bigint"==typeof t)return!1;if(t instanceof e)return!0;const{secretKey:r,publicKey:o,publicKeyUncompressed:s}=i;if(n.allowedLengths||r===o)return;const a=ZA("key",t).length;return a===o||a===s}const c={isValidSecretKey:o,isValidPublicKey:function(t,n){const{publicKey:r,publicKeyUncompressed:o}=i;try{const i=t.length;return(!0!==n||i===r)&&((!1!==n||i===o)&&!!e.fromBytes(t))}catch(e){return!1}},randomSecretKey:s,isValidPrivateKey:o,randomPrivateKey:s,normPrivateKeyToScalar:e=>ek(n,e),precompute:(t=8,n=e.BASE)=>n.precompute(t,!1)};return Object.freeze({getPublicKey:a,getSharedSecret:function(t,r,i=!0){if(!0===l(t))throw new Error("first arg must be private key");if(!1===l(r))throw new Error("second arg must be public key");const o=ek(n,t);return e.fromHex(r).multiply(o).toBytes(i)},keygen:function(e){const t=s(e);return{secretKey:t,publicKey:a(t)}},Point:e,utils:c,lengths:i})}function ok(e,t,n={}){Ru(t),rb(n,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});const r=n.randomBytes||Wu,i=n.hmac||((e,...n)=>_A(t,e,qu(...n))),{Fp:o,Fn:s}=e,{ORDER:a,BITS:l}=s,{keygen:c,getPublicKey:u,getSharedSecret:d,utils:f,lengths:h}=ik(e,n),p={prehash:!1,lowS:"boolean"==typeof n.lowS&&n.lowS,format:void 0,extraEntropy:!1},g="compact";function m(e){return e>a>>Yb}function y(e,t){if(!s.isValidNot0(t))throw new Error(`invalid signature ${e}: out of range 1..Point.Fn.ORDER`);return t}class w{constructor(e,t,n){this.r=y("r",e),this.s=y("s",t),null!=n&&(this.recovery=n),Object.freeze(this)}static fromBytes(e,t=g){let n;if(function(e,t){Kb(t);const n=h.signature;KA(e,"compact"===t?n:"recovered"===t?n+1:void 0,`${t} signature`)}(e,t),"der"===t){const{r:t,s:n}=qb.toSig(KA(e));return new w(t,n)}"recovered"===t&&(n=e[0],t="compact",e=e.subarray(1));const r=s.BYTES,i=e.subarray(0,r),o=e.subarray(r,2*r);return new w(s.fromBytes(i),s.fromBytes(o),n)}static fromHex(e,t){return this.fromBytes(Ju(e),t)}addRecoveryBit(e){return new w(this.r,this.s,e)}recoverPublicKey(t){const n=o.ORDER,{r:r,s:i,recovery:l}=this;if(null==l||![0,1,2,3].includes(l))throw new Error("recovery id invalid");if(a*Wb<n&&l>1)throw new Error("recovery id is ambiguous for h>1 curve");const c=2===l||3===l?r+a:r;if(!o.isValid(c))throw new Error("recovery id 2 or 3 invalid");const u=o.toBytes(c),d=e.fromBytes(qu(nk(!(1&l)),u)),f=s.inv(c),h=A(ZA("msgHash",t)),p=s.create(-h*f),g=s.create(i*f),m=e.BASE.multiplyUnsafe(p).add(d.multiplyUnsafe(g));if(m.is0())throw new Error("point at infinify");return m.assertValidity(),m}hasHighS(){return m(this.s)}toBytes(e=g){if(Kb(e),"der"===e)return Ju(qb.hexFromSig(this));const t=s.toBytes(this.r),n=s.toBytes(this.s);if("recovered"===e){if(null==this.recovery)throw new Error("recovery bit must be present");return qu(Uint8Array.of(this.recovery),t,n)}return qu(t,n)}toHex(e){return Lu(this.toBytes(e))}assertValidity(){}static fromCompact(e){return w.fromBytes(ZA("sig",e),"compact")}static fromDER(e){return w.fromBytes(ZA("sig",e),"der")}normalizeS(){return this.hasHighS()?new w(this.r,s.neg(this.s),this.recovery):this}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return Lu(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return Lu(this.toBytes("compact"))}}const v=n.bits2int||function(e){if(e.length>8192)throw new Error("input is too large");const t=qA(e),n=8*e.length-l;return n>0?t>>BigInt(n):t},A=n.bits2int_modN||function(e){return s.create(v(e))},b=nb(l);function k(e){return eb("num < 2^"+l,e,zb,b),s.toBytes(e)}function I(e,n){return KA(e,void 0,"message"),n?KA(t(e),void 0,"prehashed message"):e}return Object.freeze({keygen:c,getPublicKey:u,getSharedSecret:d,utils:f,lengths:h,Point:e,sign:function(n,o,a={}){n=ZA("message",n);const{seed:l,k2sig:c}=function(t,n,i){if(["recovered","canonical"].some(e=>e in i))throw new Error("sign() legacy options not supported");const{lowS:o,prehash:a,extraEntropy:l}=Jb(i,p);t=I(t,a);const c=A(t),u=ek(s,n),d=[k(u),k(c)];if(null!=l&&!1!==l){const e=!0===l?r(h.secretKey):l;d.push(ZA("extraEntropy",e))}const f=qu(...d),g=c;return{seed:f,k2sig:function(t){const n=v(t);if(!s.isValidNot0(n))return;const r=s.inv(n),i=e.BASE.multiply(n).toAffine(),a=s.create(i.x);if(a===zb)return;const l=s.create(r*s.create(g+a*u));if(l===zb)return;let c=(i.x===a?0:2)|Number(i.y&Yb),d=l;return o&&m(l)&&(d=s.neg(l),c^=1),new w(a,d,c)}}}(n,o,a),u=function(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");const r=e=>new Uint8Array(e),i=e=>Uint8Array.of(e);let o=r(e),s=r(e),a=0;const l=()=>{o.fill(1),s.fill(0),a=0},c=(...e)=>n(s,o,...e),u=(e=r(0))=>{s=c(i(0),e),o=c(),0!==e.length&&(s=c(i(1),e),o=c())},d=()=>{if(a++>=1e3)throw new Error("drbg: tried 1000 values");let e=0;const n=[];for(;e<t;){o=c();const t=o.slice();n.push(t),e+=o.length}return qu(...n)};return(e,t)=>{let n;for(l(),u(e);!(n=t(d()));)u();return l(),n}}(t.outputLen,s.BYTES,i);return u(l,c)},verify:function(t,n,r,i={}){const{lowS:o,prehash:a,format:l}=Jb(i,p);if(r=ZA("publicKey",r),n=I(ZA("message",n),a),"strict"in i)throw new Error("options.strict was renamed to lowS");const c=void 0===l?function(e){let t;const n="string"==typeof e||Su(e),r=!n&&null!==e&&"object"==typeof e&&"bigint"==typeof e.r&&"bigint"==typeof e.s;if(!n&&!r)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");if(r)t=new w(e.r,e.s);else if(n){try{t=w.fromBytes(ZA("sig",e),"der")}catch(e){if(!(e instanceof qb.Err))throw e}if(!t)try{t=w.fromBytes(ZA("sig",e),"compact")}catch(e){return!1}}return t||!1}(t):w.fromBytes(ZA("sig",t),l);if(!1===c)return!1;try{const t=e.fromBytes(r);if(o&&c.hasHighS())return!1;const{r:i,s:a}=c,l=A(n),u=s.inv(a),d=s.create(l*u),f=s.create(i*u),h=e.BASE.multiplyUnsafe(d).add(t.multiplyUnsafe(f));if(h.is0())return!1;return s.create(h.x)===i}catch(e){return!1}},recoverPublicKey:function(e,t,n={}){const{prehash:r}=Jb(n,p);return t=I(t,r),w.fromBytes(e,"recovered").recoverPublicKey(t).toBytes()},Signature:w,hash:t})}function sk(e){const{CURVE:t,curveOpts:n}=function(e){const t={a:e.a,b:e.b,p:e.Fp.ORDER,n:e.n,h:e.h,Gx:e.Gx,Gy:e.Gy},n=e.Fp;let r=e.allowedPrivateKeyLengths?Array.from(new Set(e.allowedPrivateKeyLengths.map(e=>Math.ceil(e/2)))):void 0;return{CURVE:t,curveOpts:{Fp:n,Fn:Bb(t.n,{BITS:e.nBitLength,allowedLengths:r,modFromBytes:e.wrapPrivateKey}),allowInfinityPoint:e.allowInfinityPoint,endo:e.endo,isTorsionFree:e.isTorsionFree,clearCofactor:e.clearCofactor,fromBytes:e.fromBytes,toBytes:e.toBytes}}}(e),r={hmac:e.hmac,randomBytes:e.randomBytes,lowS:e.lowS,bits2int:e.bits2int,bits2int_modN:e.bits2int_modN};return{CURVE:t,curveOpts:n,hash:e.hash,ecdsaOpts:r}}function ak(e){const{CURVE:t,curveOpts:n,hash:r,ecdsaOpts:i}=sk(e);return function(e,t){const n=t.Point;return Object.assign({},t,{ProjectivePoint:n,CURVE:Object.assign({},e,xb(n.Fn.ORDER,n.Fn.BITS))})}(e,ok(tk(t,n),r,i))}
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
const lk={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},ck={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]},uk=BigInt(2);const dk=Bb(lk.p,{sqrt:function(e){const t=lk.p,n=BigInt(3),r=BigInt(6),i=BigInt(11),o=BigInt(22),s=BigInt(23),a=BigInt(44),l=BigInt(88),c=e*e*e%t,u=c*c*e%t,d=mb(u,n,t)*u%t,f=mb(d,n,t)*u%t,h=mb(f,uk,t)*c%t,p=mb(h,i,t)*h%t,g=mb(p,o,t)*p%t,m=mb(g,a,t)*g%t,y=mb(m,l,t)*m%t,w=mb(y,a,t)*g%t,v=mb(w,n,t)*u%t,A=mb(v,s,t)*p%t,b=mb(A,r,t)*c%t,k=mb(b,uk,t);if(!dk.eql(dk.sqr(k),e))throw new Error("Cannot find square root");return k}}),fk=function(e,t){const n=t=>ak({...e,hash:t});return{...n(t),create:n}}({...lk,Fp:dk,lowS:!0,endo:ck},OA),hk=OA,pk="nip46";function gk(e){let t=0n;for(const n of e)t=t<<8n|BigInt(n);return t}function mk(e){const t=fk.utils.randomPrivateKey(),n=fk.ProjectivePoint.fromHex(function(e){const t=(new TextEncoder).encode("Secp256k1_HashToCurve_Cashu_"),n=hk(new Uint8Array([...t,...e]));for(let e=0;e<65536;e++){const t=new Uint8Array(4);new DataView(t.buffer).setUint32(0,e,!0);const r=new Uint8Array([...n,...t]),i=hk(r),o=new Uint8Array([2,...i]);try{if(!fk.ProjectivePoint.fromHex(o).equals(fk.ProjectivePoint.ZERO))return o}catch{}}throw new Error("Failed to hash to curve after 65536 attempts")}(e)),r=fk.ProjectivePoint.BASE.multiply(gk(t));return{B_:n.add(r).toRawBytes(!0),secret:e,r:t}}function yk(e){const t={k:e.keysetId,s:Lu(e.secret),c:Lu(e.signature),p:Lu(e.pubkey),e:e.expiry,sc:e.scope,kinds:e.kinds,kind_ranges:e.kindRanges},n=JSON.stringify(t);return"cashuA"+btoa(n).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}async function wk(e,t,n,r,i,o){const s=mk(crypto.getRandomValues(new Uint8Array(32))),a={blinded_message:Lu(s.B_),scope:t,kinds:i,kind_ranges:o},l=`${e}/cashu/mint`,c=await r(l,"POST"),u=await fetch(l,{method:"POST",headers:{"Content-Type":"application/json",Authorization:c},body:JSON.stringify(a)});if(!u.ok){const e=await u.text();throw new Error(`Mint request failed: ${e}`)}const d=await u.json(),f=Ju(d.blinded_signature),h=Ju(d.mint_pubkey),p=function(e,t,n){const r=fk.ProjectivePoint.fromHex(e),i=fk.ProjectivePoint.fromHex(n).multiply(gk(t));return r.subtract(i).toRawBytes(!0)}(f,s.r,h);return{keysetId:d.keyset_id,secret:s.secret,signature:p,pubkey:n,expiry:d.expiry,scope:t,kinds:i,kindRanges:o}}const vk="connect",Ak="get_public_key",bk="sign_event",kk="nip04_encrypt",Ik="nip04_decrypt",Ek="ping";class Ck{constructor(e,t,n){this.relayUrl=e,this.userPubkey=t,this.userPrivkey=n,this.ws=null,this.connected=!1,this.allowedSecrets=new Set,this.connectedClients=new Map,this.requestLog=[],this.heartbeatInterval=null,this.subscriptionId=null,this.catToken=null,this.onClientConnected=null,this.onClientDisconnected=null,this.onRequest=null,this.onStatusChange=null}addAllowedSecret(e){this.allowedSecrets.add(e)}removeAllowedSecret(e){this.allowedSecrets.delete(e)}setCatToken(e){this.catToken=e}async connect(){return new Promise((e,t)=>{let n=this.relayUrl;if(n.startsWith("http://")?n="ws://"+n.slice(7):n.startsWith("https://")?n="wss://"+n.slice(8):n.startsWith("ws://")||n.startsWith("wss://")||(n="wss://"+n),this.catToken){const e=yk(this.catToken),t=new URL(n);t.searchParams.set("token",e),n=t.toString()}console.log("[BunkerService] Connecting to:",n.split("?")[0]);const r=new WebSocket(n),i=setTimeout(()=>{r.close(),t(new Error("Connection timeout"))},1e4);r.onopen=()=>{clearTimeout(i),this.ws=r,this.connected=!0,console.log("[BunkerService] Connected to relay"),this.subscriptionId=function(e=16){const t=new Uint8Array(e);return crypto.getRandomValues(t),Lu(t)}(8);const t=JSON.stringify(["REQ",this.subscriptionId,{kinds:[24133],"#p":[this.userPubkey],since:Math.floor(Date.now()/1e3)-60}]);r.send(t),console.log("[BunkerService] Subscribed to NIP-46 events"),this.startHeartbeat(),this.onStatusChange&&this.onStatusChange("connected"),e()},r.onerror=e=>{clearTimeout(i),console.error("[BunkerService] WebSocket error:",e),t(new Error("WebSocket error"))},r.onclose=()=>{this.connected=!1,this.ws=null,this.stopHeartbeat(),console.log("[BunkerService] Disconnected from relay"),this.onStatusChange&&this.onStatusChange("disconnected")},r.onmessage=e=>{this.handleMessage(e.data)}})}startHeartbeat(e=3e4){this.stopHeartbeat(),this.heartbeatInterval=setInterval(()=>{if(this.ws&&this.ws.readyState===WebSocket.OPEN){const e=JSON.stringify(["REQ",this.subscriptionId,{kinds:[24133],"#p":[this.userPubkey],since:Math.floor(Date.now()/1e3)-60}]);this.ws.send(e)}},e)}stopHeartbeat(){this.heartbeatInterval&&(clearInterval(this.heartbeatInterval),this.heartbeatInterval=null)}disconnect(){this.stopHeartbeat(),this.ws&&(this.subscriptionId&&this.ws.send(JSON.stringify(["CLOSE",this.subscriptionId])),this.ws.close(),this.ws=null),this.connected=!1,this.connectedClients.clear()}async handleMessage(e){try{const t=JSON.parse(e);if(!Array.isArray(t))return;const[n,...r]=t;if("EVENT"===n){const[,e]=r;24133===e.kind&&await this.handleNIP46Request(e)}else"OK"===n?console.log("[BunkerService] Event published:",r[0]?.substring(0,8)):"NOTICE"===n&&console.warn("[BunkerService] Relay notice:",r[0])}catch(e){console.error("[BunkerService] Failed to parse message:",e)}}async handleNIP46Request(e){try{const t=Lu(this.userPrivkey),n=await hs.decrypt(t,e.pubkey,e.content),r=JSON.parse(n);console.log("[BunkerService] Received request:",r.method,"from:",e.pubkey.substring(0,8)),this.requestLog.push({id:r.id,method:r.method,from:e.pubkey,timestamp:Date.now()}),this.requestLog.length>100&&this.requestLog.shift(),this.onRequest&&this.onRequest(r,e.pubkey);let i=null,o=null;try{switch(r.method){case vk:i=await this.handleConnect(r,e.pubkey);break;case Ak:i=await this.handleGetPublicKey(r,e.pubkey);break;case bk:i=await this.handleSignEvent(r,e.pubkey);break;case kk:i=await this.handleNip04Encrypt(r,e.pubkey);break;case Ik:i=await this.handleNip04Decrypt(r,e.pubkey);break;case Ek:i="pong";break;default:o=`Unknown method: ${r.method}`}}catch(e){console.error("[BunkerService] Error handling request:",e),o=e.message}await this.sendResponse(r.id,i,o,e.pubkey)}catch(e){console.error("[BunkerService] Failed to handle NIP-46 request:",e)}}async handleConnect(e,t){const[n,r]=e.params;if(this.allowedSecrets.size>0&&(!r||!this.allowedSecrets.has(r)))throw new Error("Invalid or missing connection secret");return this.connectedClients.set(t,{clientPubkey:n||t,connectedAt:Date.now(),lastActivity:Date.now()}),console.log("[BunkerService] Client connected:",t.substring(0,8)),this.onClientConnected&&this.onClientConnected(t),"ack"}async handleGetPublicKey(e,t){return this.connectedClients.has(t)&&(this.connectedClients.get(t).lastActivity=Date.now()),this.userPubkey}async handleSignEvent(e,t){if(!this.connectedClients.has(t))throw new Error("Not connected");this.connectedClients.get(t).lastActivity=Date.now();const[n]=e.params,r=JSON.parse(n);if(r.pubkey&&r.pubkey!==this.userPubkey)throw new Error("Event pubkey does not match signer pubkey");r.pubkey=this.userPubkey;const i=JSON.stringify([0,r.pubkey,r.created_at,r.kind,r.tags,r.content]),o=await crypto.subtle.digest("SHA-256",(new TextEncoder).encode(i));r.id=Lu(new Uint8Array(o));const s=fk.sign(Ju(r.id),this.userPrivkey);return r.sig=s.toCompactHex(),console.log("[BunkerService] Signed event:",r.id.substring(0,8),"kind:",r.kind),JSON.stringify(r)}async handleNip04Encrypt(e,t){if(!this.connectedClients.has(t))throw new Error("Not connected");this.connectedClients.get(t).lastActivity=Date.now();const[n,r]=e.params,i=Lu(this.userPrivkey);return await hs.encrypt(i,n,r)}async handleNip04Decrypt(e,t){if(!this.connectedClients.has(t))throw new Error("Not connected");this.connectedClients.get(t).lastActivity=Date.now();const[n,r]=e.params,i=Lu(this.userPrivkey);return await hs.decrypt(i,n,r)}async sendResponse(e,t,n,r){if(!this.ws||!this.connected)return void console.error("[BunkerService] Cannot send response: not connected");const i={id:e,result:null!==t?t:void 0,error:null!==n?n:void 0},o=Lu(this.userPrivkey),s=await hs.encrypt(o,r,JSON.stringify(i)),a={kind:24133,pubkey:this.userPubkey,created_at:Math.floor(Date.now()/1e3),content:s,tags:[["p",r]]},l=JSON.stringify([0,a.pubkey,a.created_at,a.kind,a.tags,a.content]),c=await crypto.subtle.digest("SHA-256",(new TextEncoder).encode(l));a.id=Lu(new Uint8Array(c));const u=fk.sign(Ju(a.id),this.userPrivkey);a.sig=u.toCompactHex(),this.ws.send(JSON.stringify(["EVENT",a])),console.log("[BunkerService] Sent response for:",e)}isConnected(){return this.connected}getConnectedClients(){return Array.from(this.connectedClients.entries()).map(([e,t])=>({pubkey:e,...t}))}getRequestLog(){return[...this.requestLog]}}function xk(e,t,n){const r=e.slice();return r[32]=t[n],r}function Bk(t){let n,r,i,o,s,a;return{c(){n=h("div"),r=h("p"),r.textContent="Please log in to access remote signing.",i=m(),o=h("button"),o.textContent="Log In",A(r,"class","svelte-z5d70s"),A(o,"class","login-btn svelte-z5d70s"),A(n,"class","login-prompt svelte-z5d70s")},m(e,l){u(e,n,l),c(n,r),c(n,i),c(n,o),s||(a=w(o,"click",t[21]),s=!0)},p:e,d(e){e&&d(n),s=!1,a()}}}function Sk(e){let t,n,r,i,o,s,a,l,f=(e[3]||"read-only")+"";return{c(){t=h("div"),n=h("div"),r=h("h3"),r.textContent="Access Denied",i=m(),o=h("p"),s=g("You need write access to use remote signing. Your current access level: "),a=h("strong"),l=g(f),A(r,"class","svelte-z5d70s"),A(o,"class","svelte-z5d70s"),A(n,"class","access-denied svelte-z5d70s"),A(t,"class","bunker-view svelte-z5d70s")},m(e,d){u(e,t,d),c(t,n),c(n,r),c(n,i),c(n,o),c(o,s),c(o,a),c(a,l)},p(e,t){8&t[0]&&f!==(f=(e[3]||"read-only")+"")&&k(l,f)},d(e){e&&d(t)}}}function Fk(e){let t,n,r,i,o,s,a,l,f,p,y,v=e[7]?"Loading...":"Refresh",b=e[8]&&Rk(e),I=e[4]?.cashu_enabled&&"none"!==e[4]?.acl_mode&&Dk();function E(e,t){return e[7]&&!e[4]?Tk:e[4]?Pk:void 0}let C=E(e),x=C&&C(e);return{c(){t=h("div"),n=h("div"),r=h("h3"),r.textContent="Remote Signing (NIP-46 Bunker)",i=m(),o=h("button"),s=g(v),a=m(),b&&b.c(),l=m(),I&&I.c(),f=m(),x&&x.c(),A(r,"class","svelte-z5d70s"),A(o,"class","refresh-btn svelte-z5d70s"),o.disabled=e[7],A(n,"class","header-section svelte-z5d70s"),A(t,"class","bunker-view svelte-z5d70s")},m(d,h){u(d,t,h),c(t,n),c(n,r),c(n,i),c(n,o),c(o,s),c(t,a),b&&b.m(t,null),c(t,l),I&&I.m(t,null),c(t,f),x&&x.m(t,null),p||(y=w(o,"click",e[18]),p=!0)},p(e,n){128&n[0]&&v!==(v=e[7]?"Loading...":"Refresh")&&k(s,v),128&n[0]&&(o.disabled=e[7]),e[8]?b?b.p(e,n):(b=Rk(e),b.c(),b.m(t,l)):b&&(b.d(1),b=null),e[4]?.cashu_enabled&&"none"!==e[4]?.acl_mode?I||(I=Dk(),I.c(),I.m(t,f)):I&&(I.d(1),I=null),C===(C=E(e))&&x?x.p(e,n):(x&&x.d(1),x=C&&C(e),x&&(x.c(),x.m(t,null)))},d(e){e&&d(t),b&&b.d(),I&&I.d(),x&&x.d(),p=!1,y()}}}function Qk(t){let n;return{c(){n=h("div"),n.innerHTML='<div class="unavailable-message svelte-z5d70s"><h3 class="svelte-z5d70s">Remote Signing Not Available</h3> \n <p class="svelte-z5d70s">This relay does not have bunker mode enabled, or ACL mode is set to &quot;none&quot;.</p> \n <p class="hint svelte-z5d70s">Remote signing requires the relay operator to enable ACL mode &quot;follows&quot; or &quot;managed&quot;.</p></div>',A(n,"class","bunker-view svelte-z5d70s")},m(e,t){u(e,n,t)},p:e,d(e){e&&d(n)}}}function Rk(e){let t,n;return{c(){t=h("div"),n=g(e[8]),A(t,"class","error-message svelte-z5d70s")},m(e,r){u(e,t,r),c(t,n)},p(e,t){256&t[0]&&k(n,e[8])},d(e){e&&d(t)}}}function Dk(e){let t;return{c(){t=h("div"),t.innerHTML="<strong>CAT Required:</strong> This relay requires Cashu Access Tokens (CAT) for bunker connections.\n Your client must support CAT authentication or connections will be rejected.",A(t,"class","cat-warning svelte-z5d70s")},m(e,n){u(e,t,n)},d(e){e&&d(t)}}}function Pk(e){let t,n,i,o,s,a,l,f,p,y,v,b,I,E,C,x,S,F,Q,R,D,P,T,U,$,N,L,O,M,_,H,j,G,K,J,V,q,z,Y,W,Z,X,ee,te,ne,re,ie,oe,se,ae,le,ce,ue,de=e[11]?"Active":"Inactive",fe=e[4].relay_url+"",he="relay"===e[10]?"Copied!":"Copy";function pe(e,t){return e[2]?Uk:$k}let ge=pe(e),me=ge(e);function ye(e,t){return e[11]?jk:Hk}let we=ye(e),ve=we(e);function Ae(e,t){return e[9]?Kk:Gk}let be=Ae(e),ke=be(e);return{c(){t=h("div"),t.innerHTML='<p class="svelte-z5d70s"><strong>How it works:</strong> Start the bunker service to allow remote apps (like Smesh) to request signatures from your ORLY account.\n Share the QR code or bunker URL with your client app.</p>',n=m(),i=h("div"),o=h("div"),s=h("h4"),s.textContent="Bunker Service",a=m(),l=h("div"),f=h("span"),p=m(),y=g(de),v=m(),me.c(),b=m(),I=h("div"),E=h("section"),C=h("h4"),C.textContent="Bunker URL for Client Apps",x=m(),S=h("p"),ve.c(),F=m(),Q=h("div"),ke.c(),R=m(),D=h("div"),P=h("code"),T=g(e[6]),U=m(),$=h("div"),$.textContent="Click QR code to copy",N=m(),L=h("div"),O=h("h4"),O.textContent="Connection Details",M=m(),_=h("div"),H=h("span"),H.textContent="Relay:",j=m(),G=h("code"),K=g(fe),J=m(),V=h("button"),q=g(he),z=m(),Y=h("div"),W=h("span"),W.textContent="Your npub:",Z=m(),X=h("code"),ee=g(e[1]),te=m(),ne=h("div"),re=h("span"),re.textContent="Secret:",ie=m(),oe=h("code"),se=g(e[5]),ae=m(),le=h("button"),le.textContent="Regenerate",A(t,"class","instructions svelte-z5d70s"),A(s,"class","svelte-z5d70s"),A(f,"class","status-dot svelte-z5d70s"),A(l,"class","service-status svelte-z5d70s"),B(l,"active",e[11]),A(o,"class","service-header svelte-z5d70s"),A(i,"class","service-control svelte-z5d70s"),A(C,"class","svelte-z5d70s"),A(S,"class","section-desc svelte-z5d70s"),A(Q,"class","qr-container clickable svelte-z5d70s"),A(Q,"role","button"),A(Q,"tabindex","0"),A(Q,"title","Click to copy bunker URL"),A(P,"class","bunker-url svelte-z5d70s"),A(D,"class","url-display svelte-z5d70s"),A($,"class","copy-hint svelte-z5d70s"),A(E,"class","qr-section svelte-z5d70s"),A(I,"class","qr-sections svelte-z5d70s"),A(O,"class","svelte-z5d70s"),A(H,"class","label svelte-z5d70s"),A(G,"class","svelte-z5d70s"),A(V,"class","copy-btn svelte-z5d70s"),A(_,"class","info-row svelte-z5d70s"),A(W,"class","label svelte-z5d70s"),A(X,"class","npub svelte-z5d70s"),A(Y,"class","info-row svelte-z5d70s"),A(re,"class","label svelte-z5d70s"),A(oe,"class","secret svelte-z5d70s"),A(le,"class","copy-btn svelte-z5d70s"),A(ne,"class","info-row svelte-z5d70s"),A(L,"class","connection-info svelte-z5d70s")},m(r,d){u(r,t,d),u(r,n,d),u(r,i,d),c(i,o),c(o,s),c(o,a),c(o,l),c(l,f),c(l,p),c(l,y),c(i,v),me.m(i,null),u(r,b,d),u(r,I,d),c(I,E),c(E,C),c(E,x),c(E,S),ve.m(S,null),c(E,F),c(E,Q),ke.m(Q,null),c(E,R),c(E,D),c(D,P),c(P,T),c(E,U),c(E,$),u(r,N,d),u(r,L,d),c(L,O),c(L,M),c(L,_),c(_,H),c(_,j),c(_,G),c(G,K),c(_,J),c(_,V),c(V,q),c(L,z),c(L,Y),c(Y,W),c(Y,Z),c(Y,X),c(X,ee),c(L,te),c(L,ne),c(ne,re),c(ne,ie),c(ne,oe),c(oe,se),c(ne,ae),c(ne,le),ce||(ue=[w(Q,"click",e[25]),w(Q,"keypress",e[26]),w(V,"click",e[27]),w(le,"click",e[19])],ce=!0)},p(e,t){2048&t[0]&&de!==(de=e[11]?"Active":"Inactive")&&k(y,de),2048&t[0]&&B(l,"active",e[11]),ge===(ge=pe(e))&&me?me.p(e,t):(me.d(1),me=ge(e),me&&(me.c(),me.m(i,null))),we!==(we=ye(e))&&(ve.d(1),ve=we(e),ve&&(ve.c(),ve.m(S,null))),be===(be=Ae(e))&&ke?ke.p(e,t):(ke.d(1),ke=be(e),ke&&(ke.c(),ke.m(Q,null))),64&t[0]&&k(T,e[6]),16&t[0]&&fe!==(fe=e[4].relay_url+"")&&k(K,fe),1024&t[0]&&he!==(he="relay"===e[10]?"Copied!":"Copy")&&k(q,he),2&t[0]&&k(ee,e[1]),32&t[0]&&k(se,e[5])},d(e){e&&d(t),e&&d(n),e&&d(i),me.d(),e&&d(b),e&&d(I),ve.d(),ke.d(),e&&d(N),e&&d(L),ce=!1,r(ue)}}}function Tk(t){let n;return{c(){n=h("div"),n.textContent="Loading bunker information...",A(n,"class","loading svelte-z5d70s")},m(e,t){u(e,n,t)},p:e,d(e){e&&d(n)}}}function Uk(e){let t,n,r,i;function o(e,t){return e[11]?Lk:Nk}let s=o(e),a=s(e),l=e[11]&&e[13].length>0&&Ok(e),c=e[14]&&_k(e);return{c(){t=h("div"),a.c(),n=m(),l&&l.c(),r=m(),c&&c.c(),i=y(),A(t,"class","service-actions svelte-z5d70s")},m(e,o){u(e,t,o),a.m(t,null),u(e,n,o),l&&l.m(e,o),u(e,r,o),c&&c.m(e,o),u(e,i,o)},p(e,n){s===(s=o(e))&&a?a.p(e,n):(a.d(1),a=s(e),a&&(a.c(),a.m(t,null))),e[11]&&e[13].length>0?l?l.p(e,n):(l=Ok(e),l.c(),l.m(r.parentNode,r)):l&&(l.d(1),l=null),e[14]?c?c.p(e,n):(c=_k(e),c.c(),c.m(i.parentNode,i)):c&&(c.d(1),c=null)},d(e){e&&d(t),a.d(),e&&d(n),l&&l.d(e),e&&d(r),c&&c.d(e),e&&d(i)}}}function $k(t){let n;return{c(){n=h("div"),n.textContent="Bunker service requires nsec login. Please log in with your private key to enable remote signing.",A(n,"class","no-privkey-warning svelte-z5d70s")},m(e,t){u(e,n,t)},p:e,d(e){e&&d(n)}}}function Nk(e){let t,n,r,i,o=e[12]?"Starting...":"Start Service";return{c(){t=h("button"),n=g(o),A(t,"class","start-btn svelte-z5d70s"),t.disabled=e[12]},m(o,s){u(o,t,s),c(t,n),r||(i=w(t,"click",e[16]),r=!0)},p(e,r){4096&r[0]&&o!==(o=e[12]?"Starting...":"Start Service")&&k(n,o),4096&r[0]&&(t.disabled=e[12])},d(e){e&&d(t),r=!1,i()}}}function Lk(t){let n,r,i;return{c(){n=h("button"),n.textContent="Stop Service",A(n,"class","stop-btn svelte-z5d70s")},m(e,o){u(e,n,o),r||(i=w(n,"click",t[17]),r=!0)},p:e,d(e){e&&d(n),r=!1,i()}}}function Ok(e){let t,n,r,i,o,s,a=e[13].length+"",l=e[13],p=[];for(let t=0;t<l.length;t+=1)p[t]=Mk(xk(e,l,t));return{c(){t=h("div"),n=h("h5"),r=g("Connected Clients ("),i=g(a),o=g(")"),s=m();for(let e=0;e<p.length;e+=1)p[e].c();A(n,"class","svelte-z5d70s"),A(t,"class","connected-clients svelte-z5d70s")},m(e,a){u(e,t,a),c(t,n),c(n,r),c(n,i),c(n,o),c(t,s);for(let e=0;e<p.length;e+=1)p[e]&&p[e].m(t,null)},p(e,n){if(8192&n[0]&&a!==(a=e[13].length+"")&&k(i,a),8192&n[0]){let r;for(l=e[13],r=0;r<l.length;r+=1){const i=xk(e,l,r);p[r]?p[r].p(i,n):(p[r]=Mk(i),p[r].c(),p[r].m(t,null))}for(;r<p.length;r+=1)p[r].d(1);p.length=l.length}},d(e){e&&d(t),f(p,e)}}}function Mk(e){let t,n,r,i,o,s,a,l,f,p=e[32].pubkey.substring(0,16)+"",y=new Date(e[32].connectedAt).toLocaleTimeString()+"";return{c(){t=h("div"),n=h("code"),r=g(p),i=g("..."),o=m(),s=h("span"),a=g("Connected "),l=g(y),f=m(),A(n,"class","svelte-z5d70s"),A(s,"class","client-time svelte-z5d70s"),A(t,"class","client-entry svelte-z5d70s")},m(e,d){u(e,t,d),c(t,n),c(n,r),c(n,i),c(t,o),c(t,s),c(s,a),c(s,l),c(t,f)},p(e,t){8192&t[0]&&p!==(p=e[32].pubkey.substring(0,16)+"")&&k(r,p),8192&t[0]&&y!==(y=new Date(e[32].connectedAt).toLocaleTimeString()+"")&&k(l,y)},d(e){e&&d(t)}}}function _k(e){let t,n,r,i,o,s,a=new Date(1e3*e[14].expiry).toLocaleString()+"";return{c(){t=h("div"),n=h("span"),n.textContent="CAT Token Active",r=m(),i=h("span"),o=g("Expires: "),s=g(a),A(n,"class","cat-badge svelte-z5d70s"),A(i,"class","cat-expiry svelte-z5d70s"),A(t,"class","cat-info svelte-z5d70s")},m(e,a){u(e,t,a),c(t,n),c(t,r),c(t,i),c(i,o),c(i,s)},p(e,t){16384&t[0]&&a!==(a=new Date(1e3*e[14].expiry).toLocaleString()+"")&&k(s,a)},d(e){e&&d(t)}}}function Hk(e){let t;return{c(){t=g("Start the bunker service above to generate a connection URL.")},m(e,n){u(e,t,n)},d(e){e&&d(t)}}}function jk(e){let t;return{c(){t=g("Scan or copy this URL in your Nostr client (e.g., Smesh) to connect:")},m(e,n){u(e,t,n)},d(e){e&&d(t)}}}function Gk(t){let n;return{c(){n=h("div"),n.textContent="Generating QR...",A(n,"class","qr-placeholder svelte-z5d70s")},m(e,t){u(e,n,t)},p:e,d(e){e&&d(n)}}}function Kk(e){let t,n,r,i;return{c(){t=h("img"),r=m(),i=h("div"),i.textContent="Copied!",a(t.src,n=e[9])||A(t,"src",n),A(t,"alt","Client Bunker QR Code"),A(t,"class","qr-code svelte-z5d70s"),A(i,"class","qr-overlay svelte-z5d70s"),B(i,"visible","client"===e[10])},m(e,n){u(e,t,n),u(e,r,n),u(e,i,n)},p(e,r){512&r[0]&&!a(t.src,n=e[9])&&A(t,"src",n),1024&r[0]&&B(i,"visible","client"===e[10])},d(e){e&&d(t),e&&d(r),e&&d(i)}}}function Jk(t){let n;function r(e,t){return e[4]?.available?e[15]?Fk:e[0]?Sk:Bk:Qk}let i=r(t),o=i(t);return{c(){o.c(),n=y()},m(e,t){o.m(e,t),u(e,n,t)},p(e,t){i===(i=r(e))&&o?o.p(e,t):(o.d(1),o=i(e),o&&(o.c(),o.m(n.parentNode,n)))},i:e,o:e,d(e){o.d(e),e&&d(n)}}}function Vk(){const e=new Uint8Array(16);return crypto.getRandomValues(e),Array.from(e,e=>e.toString(16).padStart(2,"0")).join("")}function qk(e,t,n){let r,i,o,{isLoggedIn:s=!1}=t,{userPubkey:a=""}=t,{userSigner:l=null}=t,{userPrivkey:c=null}=t,{currentEffectiveRole:u=""}=t;const d=P();let f=null,h=!1,p="",g="",m="",y="",w=null,v=!1,A=!1,b=[],k=null,I="";async function E(){n(7,h=!0),n(8,p="");try{n(4,f=await async function(){const e=`${window.location.origin}/api/bunker/info`,t=await fetch(e);if(!t.ok){const e=await t.text();throw new Error(e||`Failed to get bunker info: ${t.statusText}`)}return await t.json()}()),y||n(5,y=Vk()),await C()}catch(e){console.error("Error loading bunker info:",e),n(8,p=e.message||"Failed to load bunker information")}finally{n(7,h=!1)}}async function C(){i&&n(9,g=await rv.toDataURL(i,{width:280,margin:2,color:{dark:"#000000",light:"#ffffff"}})),o&&await rv.toDataURL(o,{width:280,margin:2,color:{dark:"#000000",light:"#ffffff"}})}function x(e,t){navigator.clipboard.writeText(e),n(10,m=t),setTimeout(()=>{n(10,m="")},2e3)}R(async()=>{await E()}),D(()=>{w&&(w.disconnect(),w=null,n(11,v=!1))});return e.$$set=e=>{"isLoggedIn"in e&&n(0,s=e.isLoggedIn),"userPubkey"in e&&n(1,a=e.userPubkey),"userSigner"in e&&n(22,l=e.userSigner),"userPrivkey"in e&&n(2,c=e.userPrivkey),"currentEffectiveRole"in e&&n(3,u=e.currentEffectiveRole)},e.$$.update=()=>{11&e.$$.dirty[0]&&n(15,r=s&&a&&("write"===u||"admin"===u||"owner"===u)),8388658&e.$$.dirty[0]&&n(6,i=f&&a?`bunker://${a}?relay=${encodeURIComponent(f.relay_url)}${y?`&secret=${y}`:""}${I?`&cat=${I}`:""}`:""),16&e.$$.dirty[0]&&n(24,o=f?`nostr+connect://${f.relay_url}`:""),16777280&e.$$.dirty[0]&&(i||o)&&C()},[s,a,c,u,f,y,i,h,p,g,m,v,A,b,k,r,async function(){if(c&&a&&f){n(12,A=!0),n(8,p="");try{if(f.cashu_enabled){console.log("CAT required, minting token...");const e=await async function(e){let t=e.replace("wss://","https://").replace("ws://","http://").replace(/\/$/,"");try{const e=await fetch(`${t}/cashu/info`);if(!e.ok)return null;const n=await e.json();return n.mintUrl=t,n}catch{return null}}(f.relay_url);if(e){const t=async(e,t)=>{const n=await async function(e,t,n,r){if(!e||!t)return console.log("No signer or pubkey available"),null;try{const t={kind:27235,created_at:Math.floor(Date.now()/1e3),tags:[["u",r],["method",n]],content:""},i=await e.signEvent(t);return btoa(JSON.stringify(i)).replace(/\+/g,"-").replace(/\//g,"_")}catch(e){return console.error("Error creating NIP-98 auth:",e),null}}(l,a,t,e);return`Nostr ${n}`};n(14,k=await wk(e.mintUrl,pk,Ju(a),t,[24133])),n(23,I=yk(k)),console.log("CAT token acquired, expires:",new Date(1e3*k.expiry).toISOString())}}w=new Ck(f.relay_url,a,c),y&&w.addAllowedSecret(y),k&&w.setCatToken(k),w.onClientConnected=e=>{n(13,b=w.getConnectedClients())},w.onStatusChange=e=>{n(11,v="connected"===e),"disconnected"===e&&n(13,b=[])},await w.connect(),n(11,v=!0),await C(),console.log("Bunker service started successfully")}catch(e){console.error("Failed to start bunker service:",e),n(8,p=e.message||"Failed to start bunker service"),w=null,n(11,v=!1),n(14,k=null),n(23,I="")}finally{n(12,A=!1)}}else n(8,p="Missing private key or bunker info")},function(){w&&(w.disconnect(),w=null),n(11,v=!1),n(13,b=[]),n(14,k=null),n(23,I=""),C()},E,async function(){n(5,y=Vk()),await C()},x,function(){d("openLoginModal")},l,I,o,()=>x(i,"client"),e=>"Enter"===e.key&&x(i,"client"),()=>x(f.relay_url,"relay")]}class zk extends oe{constructor(e){super(),ie(this,e,qk,Jk,o,{isLoggedIn:0,userPubkey:1,userSigner:22,userPrivkey:2,currentEffectiveRole:3},null,[-1,-1])}}function Yk(e,t,n){const r=e.slice();return r[29]=t[n],r}function Wk(e,t,n){const r=e.slice();return r[32]=t[n],r}function Zk(e){let t,n,r;function i(e,t){return e[0]?eI:tI}let o=i(e),s=o(e);return{c(){t=h("div"),n=h("p"),n.textContent="Log viewer is only available to relay owners.",r=m(),s.c(),A(n,"class","svelte-w6h7aj"),A(t,"class","login-prompt svelte-w6h7aj")},m(e,i){u(e,t,i),c(t,n),c(t,r),s.m(t,null)},p(e,n){o===(o=i(e))&&s?s.p(e,n):(s.d(1),s=o(e),s&&(s.c(),s.m(t,null)))},d(e){e&&d(t),s.d()}}}function Xk(e){let t,n,i,o,s,a,l,p,y,v,b,I,E,x,B,S,F,Q,R,D,P,T,U,$,N,L,O,M,H,j,G,K=e[3]?"Loading...":"Refresh",J=e[2].length+"",V=e[12],q=[];for(let t=0;t<V.length;t+=1)q[t]=nI(Wk(e,V,t));let z=e[7]&&rI(e);function Y(e,t){return 0!==e[2].length||e[3]?iI:oI}let W=Y(e),Z=W(e);return{c(){t=h("div"),n=h("div"),i=h("h3"),i.textContent="Logs",o=m(),s=h("div"),a=h("div"),l=h("label"),l.textContent="Level:",p=m(),y=h("select");for(let e=0;e<q.length;e+=1)q[e].c();v=m(),b=h("button"),I=g("Clear"),x=m(),B=h("button"),S=g("🔄 "),F=g(K),Q=m(),z&&z.c(),R=m(),D=h("div"),P=g("Showing "),T=g(J),U=g(" of "),$=g(e[6]),N=g(" logs (Level: "),L=g(e[8]),O=g(")"),M=m(),H=h("div"),Z.c(),A(i,"class","svelte-w6h7aj"),A(l,"for","log-level"),A(l,"class","svelte-w6h7aj"),A(y,"id","log-level"),A(y,"class","svelte-w6h7aj"),void 0===e[9]&&_(()=>e[18].call(y)),A(a,"class","level-selector svelte-w6h7aj"),A(b,"class","clear-btn svelte-w6h7aj"),b.disabled=E=e[3]||0===e[2].length,A(B,"class","refresh-btn svelte-w6h7aj"),B.disabled=e[3],A(s,"class","header-controls svelte-w6h7aj"),A(n,"class","header-section svelte-w6h7aj"),A(D,"class","log-info svelte-w6h7aj"),A(H,"class","log-list svelte-w6h7aj"),A(t,"class","log-view svelte-w6h7aj")},m(r,d){u(r,t,d),c(t,n),c(n,i),c(n,o),c(n,s),c(s,a),c(a,l),c(a,p),c(a,y);for(let e=0;e<q.length;e+=1)q[e]&&q[e].m(y,null);C(y,e[9],!0),c(s,v),c(s,b),c(b,I),c(s,x),c(s,B),c(B,S),c(B,F),c(t,Q),z&&z.m(t,null),c(t,R),c(t,D),c(D,P),c(D,T),c(D,U),c(D,$),c(D,N),c(D,L),c(D,O),c(t,M),c(t,H),Z.m(H,null),e[21](H),j||(G=[w(y,"change",e[18]),w(y,"change",e[14]),w(b,"click",e[15]),w(B,"click",e[19])],j=!0)},p(e,n){if(4096&n[0]){let t;for(V=e[12],t=0;t<V.length;t+=1){const r=Wk(e,V,t);q[t]?q[t].p(r,n):(q[t]=nI(r),q[t].c(),q[t].m(y,null))}for(;t<q.length;t+=1)q[t].d(1);q.length=V.length}4608&n[0]&&C(y,e[9]),12&n[0]&&E!==(E=e[3]||0===e[2].length)&&(b.disabled=E),8&n[0]&&K!==(K=e[3]?"Loading...":"Refresh")&&k(F,K),8&n[0]&&(B.disabled=e[3]),e[7]?z?z.p(e,n):(z=rI(e),z.c(),z.m(t,R)):z&&(z.d(1),z=null),4&n[0]&&J!==(J=e[2].length+"")&&k(T,J),64&n[0]&&k($,e[6]),256&n[0]&&k(L,e[8]),W===(W=Y(e))&&Z?Z.p(e,n):(Z.d(1),Z=W(e),Z&&(Z.c(),Z.m(H,null)))},d(n){n&&d(t),f(q,n),z&&z.d(),Z.d(),e[21](null),j=!1,r(G)}}}function eI(e){let t,n,r,i;return{c(){t=h("p"),n=g("Your role ("),r=g(e[1]),i=g(") does not have access to this feature."),A(t,"class","access-denied svelte-w6h7aj")},m(e,o){u(e,t,o),c(t,n),c(t,r),c(t,i)},p(e,t){2&t[0]&&k(r,e[1])},d(e){e&&d(t)}}}function tI(t){let n,r,i;return{c(){n=h("button"),n.textContent="Log In",A(n,"class","login-btn svelte-w6h7aj")},m(e,o){u(e,n,o),r||(i=w(n,"click",t[16]),r=!0)},p:e,d(e){e&&d(n),r=!1,i()}}}function nI(t){let n,r,i=t[32]+"";return{c(){n=h("option"),r=g(i),n.__value=t[32],n.value=n.__value},m(e,t){u(e,n,t),c(n,r)},p:e,d(e){e&&d(n)}}}function rI(e){let t,n;return{c(){t=h("div"),n=g(e[7]),A(t,"class","error-message svelte-w6h7aj")},m(e,r){u(e,t,r),c(t,n)},p(e,t){128&t[0]&&k(n,e[7])},d(e){e&&d(t)}}}function iI(e){let t,n,r=e[2],i=[];for(let t=0;t<r.length;t+=1)i[t]=aI(Yk(e,r,t));function o(e,t){return e[3]?uI:e[5]?cI:lI}let s=o(e),a=s(e);return{c(){for(let e=0;e<i.length;e+=1)i[e].c();t=m(),n=h("div"),a.c(),A(n,"class","load-more-trigger svelte-w6h7aj")},m(r,o){for(let e=0;e<i.length;e+=1)i[e]&&i[e].m(r,o);u(r,t,o),u(r,n,o),a.m(n,null),e[20](n)},p(e,l){if(4&l[0]){let n;for(r=e[2],n=0;n<r.length;n+=1){const o=Yk(e,r,n);i[n]?i[n].p(o,l):(i[n]=aI(o),i[n].c(),i[n].m(t.parentNode,t))}for(;n<i.length;n+=1)i[n].d(1);i.length=r.length}s!==(s=o(e))&&(a.d(1),a=s(e),a&&(a.c(),a.m(n,null)))},d(r){f(i,r),r&&d(t),r&&d(n),a.d(),e[20](null)}}}function oI(t){let n;return{c(){n=h("div"),n.innerHTML="<p>No logs available.</p>",A(n,"class","empty-state svelte-w6h7aj")},m(e,t){u(e,n,t)},p:e,d(e){e&&d(n)}}}function sI(e){let t,n,r,i,o=e[29].file+"",s=e[29].line+"";return{c(){t=h("span"),n=g(o),r=g(":"),i=g(s),A(t,"class","log-location svelte-w6h7aj")},m(e,o){u(e,t,o),c(t,n),c(t,r),c(t,i)},p(e,t){4&t[0]&&o!==(o=e[29].file+"")&&k(n,o),4&t[0]&&s!==(s=e[29].line+"")&&k(i,s)},d(e){e&&d(t)}}}function aI(e){let t,n,r,i,o,s,a,l,f,p,y,w=fI(e[29].timestamp)+"",v=e[29].level+"",b=e[29].message+"",I=e[29].file&&sI(e);return{c(){t=h("div"),n=h("span"),r=g(w),i=m(),o=h("span"),s=g(v),l=m(),I&&I.c(),f=m(),p=h("span"),y=g(b),A(n,"class","log-timestamp svelte-w6h7aj"),A(o,"class",a="log-level "+hI(e[29].level)+" svelte-w6h7aj"),A(p,"class","log-message svelte-w6h7aj"),A(t,"class","log-entry svelte-w6h7aj")},m(e,a){u(e,t,a),c(t,n),c(n,r),c(t,i),c(t,o),c(o,s),c(t,l),I&&I.m(t,null),c(t,f),c(t,p),c(p,y)},p(e,n){4&n[0]&&w!==(w=fI(e[29].timestamp)+"")&&k(r,w),4&n[0]&&v!==(v=e[29].level+"")&&k(s,v),4&n[0]&&a!==(a="log-level "+hI(e[29].level)+" svelte-w6h7aj")&&A(o,"class",a),e[29].file?I?I.p(e,n):(I=sI(e),I.c(),I.m(t,f)):I&&(I.d(1),I=null),4&n[0]&&b!==(b=e[29].message+"")&&k(y,b)},d(e){e&&d(t),I&&I.d()}}}function lI(e){let t;return{c(){t=h("span"),t.textContent="End of logs"},m(e,n){u(e,t,n)},d(e){e&&d(t)}}}function cI(e){let t;return{c(){t=h("span"),t.textContent="Scroll for more"},m(e,n){u(e,t,n)},d(e){e&&d(t)}}}function uI(e){let t;return{c(){t=h("span"),t.textContent="Loading more..."},m(e,n){u(e,t,n)},d(e){e&&d(t)}}}function dI(t){let n;function r(e,t){return e[4]?Xk:Zk}let i=r(t),o=i(t);return{c(){o.c(),n=y()},m(e,t){o.m(e,t),u(e,n,t)},p(e,t){i===(i=r(e))&&o?o.p(e,t):(o.d(1),o=i(e),o&&(o.c(),o.m(n.parentNode,n)))},i:e,o:e,d(e){o.d(e),e&&d(n)}}}function fI(e){if(!e)return"";return new Date(e).toLocaleString()}function hI(e){switch(e?.toUpperCase()){case"TRC":case"TRACE":return"level-trace";case"DBG":case"DEBUG":return"level-debug";case"INF":case"INFO":default:return"level-info";case"WRN":case"WARN":return"level-warn";case"ERR":case"ERROR":return"level-error";case"FTL":case"FATAL":return"level-fatal"}}function pI(e,t,n){let r,{isLoggedIn:i=!1}=t,{userRole:o=""}=t,{userSigner:s=null}=t;const a=P();let l=[],c=!1,u=!0,d=0,f=0,h="",p="info",g="info";const m=["trace","debug","info","warn","error","fatal"];let y,w,v;async function A(e="GET",t="/api/logs"){if(!s)return null;try{const n={kind:27235,created_at:Math.floor(Date.now()/1e3),tags:[["u",`${window.location.origin}${t}`],["method",e]],content:""},r=await s.signEvent(n);return btoa(JSON.stringify(r)).replace(/\+/g,"-").replace(/\//g,"_")}catch(e){return console.error("Error creating auth header:",e),null}}async function b(e=!1){if(!c){n(3,c=!0),n(7,h=""),e&&(d=0,n(2,l=[]));try{const t=`/api/logs?offset=${d}&limit=100`,r=await A("GET",t),i=`${window.location.origin}${t}`,o=await fetch(i,{headers:r?{Authorization:`Nostr ${r}`}:{}});if(!o.ok)throw new Error(`Failed to load logs: ${o.statusText}`);const s=await o.json();n(2,l=e?s.logs||[]:[...l,...s.logs||[]]),n(6,f=s.total||0),n(5,u=s.has_more||!1),d=l.length}catch(e){console.error("Error loading logs:",e),n(7,h=e.message||"Failed to load logs")}finally{n(3,c=!1)}}}async function k(){try{const e=await fetch(`${window.location.origin}/api/logs/level`);if(e.ok){const t=await e.json();n(8,p=t.level||"info"),n(9,g=p)}}catch(e){console.error("Error loading log level:",e)}}R(()=>{r&&(b(!0),k(),function(){if(!w)return;v=new IntersectionObserver(e=>{e[0].isIntersecting&&u&&!c&&u&&!c&&b(!1)},{threshold:.1}),v.observe(w)}())}),D(()=>{v&&v.disconnect()});return e.$$set=e=>{"isLoggedIn"in e&&n(0,i=e.isLoggedIn),"userRole"in e&&n(1,o=e.userRole),"userSigner"in e&&n(17,s=e.userSigner)},e.$$.update=()=>{3&e.$$.dirty[0]&&n(4,r=i&&"owner"===o),28&e.$$.dirty[0]&&r&&0===l.length&&!c&&(b(!0),k())},[i,o,l,c,r,u,f,h,p,g,y,w,m,b,async function(){if(g!==p)try{const e=await A("POST","/api/logs/level"),t=await fetch(`${window.location.origin}/api/logs/level`,{method:"POST",headers:{"Content-Type":"application/json",...e?{Authorization:`Nostr ${e}`}:{}},body:JSON.stringify({level:g})});if(!t.ok)throw new Error(`Failed to set log level: ${t.statusText}`);const r=await t.json();n(8,p=r.level),n(9,g=p)}catch(e){console.error("Error setting log level:",e),n(7,h=e.message||"Failed to set log level"),n(9,g=p)}},async function(){if(confirm("Are you sure you want to clear all logs?"))try{const e=await A("POST","/api/logs/clear"),t=await fetch(`${window.location.origin}/api/logs/clear`,{method:"POST",headers:e?{Authorization:`Nostr ${e}`}:{}});if(!t.ok)throw new Error(`Failed to clear logs: ${t.statusText}`);n(2,l=[]),d=0,n(5,u=!1),n(6,f=0)}catch(e){console.error("Error clearing logs:",e),n(7,h=e.message||"Failed to clear logs")}},function(){a("openLoginModal")},s,function(){g=x(this),n(9,g),n(12,m)},()=>b(!0),function(e){$[e?"unshift":"push"](()=>{w=e,n(11,w)})},function(e){$[e?"unshift":"push"](()=>{y=e,n(10,y)})}]}class gI extends oe{constructor(e){super(),ie(this,e,pI,dI,o,{isLoggedIn:0,userRole:1,userSigner:17},null,[-1,-1])}}function mI(e){let t,n,r,i,o,s,a,l,f,p,y;return{c(){t=h("div"),n=h("div"),r=h("h3"),r.textContent="Active Filter",i=m(),o=h("button"),o.textContent="🧹 Sweep",s=m(),a=h("div"),l=h("pre"),f=g(e[2]),A(r,"class","svelte-1tyqaa5"),A(o,"class","sweep-btn svelte-1tyqaa5"),A(o,"title","Clear filter"),A(n,"class","filter-display-header svelte-1tyqaa5"),A(l,"class","filter-json svelte-1tyqaa5"),A(a,"class","filter-json-container svelte-1tyqaa5"),A(t,"class","filter-display svelte-1tyqaa5")},m(d,h){u(d,t,h),c(t,n),c(n,r),c(n,i),c(n,o),c(t,s),c(t,a),c(a,l),c(l,f),p||(y=w(o,"click",e[3]),p=!0)},p(e,t){4&t&&k(f,e[2])},d(e){e&&d(t),p=!1,y()}}}function yI(t){let n,r=t[0]&&t[1]&&mI(t);return{c(){r&&r.c(),n=y()},m(e,t){r&&r.m(e,t),u(e,n,t)},p(e,[t]){e[0]&&e[1]?r?r.p(e,t):(r=mI(e),r.c(),r.m(n.parentNode,n)):r&&(r.d(1),r=null)},i:e,o:e,d(e){r&&r.d(e),e&&d(n)}}}function wI(e,t,n){let r,i;const o=P();let{filter:s={}}=t,{showFilter:a=!0}=t;return e.$$set=e=>{"filter"in e&&n(4,s=e.filter),"showFilter"in e&&n(0,a=e.showFilter)},e.$$.update=()=>{16&e.$$.dirty&&n(2,r=function(e){return JSON.stringify(e,null,2)}(s)),16&e.$$.dirty&&n(1,i=Object.keys(s).length>0)},[a,i,r,function(){o("sweep")},s]}class vI extends oe{constructor(e){super(),ie(this,e,wI,yI,o,{filter:4,showFilter:0})}}function AI(e){return Ch[e]||`Kind ${e}`}function bI(e){return e?e.slice(0,8)+"..."+e.slice(-8):"unknown"}function kI(e,t=100){return e?e.length>t?e.slice(0,t)+"...":e:""}function II(e){return e?new Date(1e3*e).toLocaleString():""}class EI{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,i]=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:",i),this.authPromise&&(this.authPromise.reject(new Error(i||"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 i=this.ws.onmessage,o=setTimeout(()=>{this.ws.onmessage=i,n(new Error("Publish timeout"))},15e3);this.ws.onmessage=async r=>{try{const s=JSON.parse(r.data),[a,l,c,u]=s;if("OK"===a&&l===e.id)if(c)clearTimeout(o),this.ws.onmessage=i,console.log("Event published successfully:",l),t({success:!0,eventId:l,reason:u});else{if(console.error("Event publish failed:",u),u&&u.includes("auth-required"))return void console.log("Authentication required, waiting for AUTH challenge...");clearTimeout(o),this.ws.onmessage=i,n(new Error(`Publish failed: ${u}`))}else if("AUTH"===a){this.challenge=s[1],console.log("Received AUTH challenge during publish:",this.challenge);try{await this.authenticate(),console.log("Authentication successful, retrying event publish...");const t=["EVENT",e];this.ws.send(JSON.stringify(t))}catch(e){clearTimeout(o),this.ws.onmessage=i,n(new Error(`Authentication failed: ${e.message}`))}}else await this.handleMessage(s)}catch(e){clearTimeout(o),this.ws.onmessage=i,n(e)}}})}close(){this.ws&&(this.ws.close(),this.ws=null),this.isAuthenticated=!1,this.challenge=null}getAuthenticated(){return this.isAuthenticated}}async function CI(e,t,n,r){const i=new EI(e,n,r);try{await i.connect();return await i.publishEvent(t)}finally{i.close()}}function xI(e,t,n){const r=e.slice();return r[170]=t[n],r}function BI(e,t,n){const r=e.slice();return r[180]=t[n],r}function SI(e,t,n){const r=e.slice();return r[173]=t[n],r}function FI(e,t,n){const r=e.slice();r[173]=t[n];const i=r[53](r[173]);return r[174]=i,r}function QI(e,t,n){const r=e.slice();return r[177]=t[n],r}function RI(t){let n;function r(e,t){return e[1]?KI:GI}let i=r(t),o=i(t);return{c(){n=h("div"),o.c(),A(n,"class","welcome-message svelte-u3u5mw")},m(e,t){u(e,n,t),o.m(n,null)},p(e,t){i===(i=r(e))&&o?o.p(e,t):(o.d(1),o=i(e),o&&(o.c(),o.m(n,null)))},i:e,o:e,d(e){e&&d(n),o.d()}}}function DI(e){let t,n,r=e[6],i=[];for(let t=0;t<r.length;t+=1)i[t]=eE(BI(e,r,t));const o=e=>Z(i[e],1,1,()=>{i[e]=null});return{c(){for(let e=0;e<i.length;e+=1)i[e].c();t=y()},m(e,r){for(let t=0;t<i.length;t+=1)i[t]&&i[t].m(e,r);u(e,t,r),n=!0},p(e,n){if(524404&n[0]|94208&n[1]|3407872&n[2]){let s;for(r=e[6],s=0;s<r.length;s+=1){const o=BI(e,r,s);i[s]?(i[s].p(o,n),W(i[s],1)):(i[s]=eE(o),i[s].c(),W(i[s],1),i[s].m(t.parentNode,t))}for(z(),s=r.length;s<i.length;s+=1)o(s);Y()}},i(e){if(!n){for(let e=0;e<r.length;e+=1)W(i[e]);n=!0}},o(e){i=i.filter(Boolean);for(let e=0;e<i.length;e+=1)Z(i[e]);n=!1},d(e){f(i,e),e&&d(t)}}}function PI(t){let n,i,o,s,a,l,p,g,y,v,k,E,x,B,S,F,Q,R,D=null!==t[36]&&void 0!==t[36]&&t[36]>=0||""!==t[37]&&parseInt(t[37])>=0,P=Eh,T=[];for(let e=0;e<P.length;e+=1)T[e]=tE(QI(t,P,e));let U=D&&nE(t);return{c(){n=h("div"),i=h("div"),i.innerHTML='<h3 class="svelte-u3u5mw">Event Recovery</h3> \n <p class="svelte-u3u5mw">Search and recover old versions of replaceable events</p>',o=m(),s=h("div"),a=h("div"),l=h("div"),p=h("label"),p.textContent="Select Event Kind:",g=m(),y=h("select"),v=h("option"),v.textContent="Choose a replaceable kind...";for(let e=0;e<T.length;e+=1)T[e].c();k=m(),E=h("div"),x=h("label"),x.textContent="Or enter custom kind number:",B=m(),S=h("input"),F=m(),U&&U.c(),A(p,"for","recovery-kind"),A(p,"class","svelte-u3u5mw"),v.__value=null,v.value=v.__value,A(y,"id","recovery-kind"),A(y,"class","svelte-u3u5mw"),void 0===t[36]&&_(()=>t[116].call(y)),A(l,"class","kind-selector svelte-u3u5mw"),A(x,"for","custom-kind"),A(x,"class","svelte-u3u5mw"),A(S,"id","custom-kind"),A(S,"type","number"),A(S,"placeholder","e.g., 10001"),A(S,"min","0"),A(S,"class","svelte-u3u5mw"),A(E,"class","custom-kind-input svelte-u3u5mw"),A(a,"class","recovery-controls svelte-u3u5mw"),A(s,"class","recovery-controls-card svelte-u3u5mw"),A(n,"class","recovery-tab svelte-u3u5mw")},m(e,r){u(e,n,r),c(n,i),c(n,o),c(n,s),c(s,a),c(a,l),c(l,p),c(l,g),c(l,y),c(y,v);for(let e=0;e<T.length;e+=1)T[e]&&T[e].m(y,null);C(y,t[36],!0),c(a,k),c(a,E),c(E,x),c(E,B),c(E,S),I(S,t[37]),c(n,F),U&&U.m(n,null),Q||(R=[w(y,"change",t[116]),w(y,"change",t[51]),w(S,"input",t[117]),w(S,"input",t[52])],Q=!0)},p(e,t){if(0&t){let n;for(P=Eh,n=0;n<P.length;n+=1){const r=QI(e,P,n);T[n]?T[n].p(r,t):(T[n]=tE(r),T[n].c(),T[n].m(y,null))}for(;n<T.length;n+=1)T[n].d(1);T.length=P.length}32&t[1]&&C(y,e[36]),64&t[1]&&b(S.value)!==e[37]&&I(S,e[37]),96&t[1]&&(D=null!==e[36]&&void 0!==e[36]&&e[36]>=0||""!==e[37]&&parseInt(e[37])>=0),D?U?U.p(e,t):(U=nE(e),U.c(),U.m(n,null)):U&&(U.d(1),U=null)},i:e,o:e,d(e){e&&d(n),f(T,e),U&&U.d(),Q=!1,r(R)}}}function TI(e){let t,n;return t=new gI({props:{isLoggedIn:e[1],userRole:e[4],userSigner:e[13]}}),t.$on("openLoginModal",e[71]),{c(){ee(t.$$.fragment)},m(e,r){te(t,e,r),n=!0},p(e,n){const r={};2&n[0]&&(r.isLoggedIn=e[1]),16&n[0]&&(r.userRole=e[4]),8192&n[0]&&(r.userSigner=e[13]),t.$set(r)},i(e){n||(W(t.$$.fragment,e),n=!0)},o(e){Z(t.$$.fragment,e),n=!1},d(e){ne(t,e)}}}function UI(e){let t,n,r;function i(t){e[115](t)}let o={isLoggedIn:e[1],userRole:e[4],isPolicyAdmin:xE,policyEnabled:e[8],isLoadingPolicy:e[28],policyMessage:e[29],policyMessageType:e[30],validationErrors:e[31],policyFollows:e[32]};return void 0!==e[27]&&(o.policyJson=e[27]),t=new lw({props:o}),$.push(()=>X(t,"policyJson",i)),t.$on("loadPolicy",e[61]),t.$on("validatePolicy",e[62]),t.$on("savePolicy",e[63]),t.$on("formatJson",e[64]),t.$on("addPolicyAdmin",e[65]),t.$on("removePolicyAdmin",e[66]),t.$on("refreshFollows",e[67]),t.$on("openLoginModal",e[71]),{c(){ee(t.$$.fragment)},m(e,n){te(t,e,n),r=!0},p(e,r){const i={};2&r[0]&&(i.isLoggedIn=e[1]),16&r[0]&&(i.userRole=e[4]),256&r[0]&&(i.policyEnabled=e[8]),268435456&r[0]&&(i.isLoadingPolicy=e[28]),536870912&r[0]&&(i.policyMessage=e[29]),1073741824&r[0]&&(i.policyMessageType=e[30]),1&r[1]&&(i.validationErrors=e[31]),2&r[1]&&(i.policyFollows=e[32]),!n&&134217728&r[0]&&(n=!0,i.policyJson=e[27],H(()=>n=!1)),t.$set(i)},i(e){r||(W(t.$$.fragment,e),r=!0)},o(e){Z(t.$$.fragment,e),r=!1},d(e){ne(t,e)}}}function $I(e){let t,n,r;function i(t){e[112](t)}let o={isLoggedIn:e[1],userRole:e[4],sprocketStatus:e[21],isLoadingSprocket:e[23],sprocketUploadFile:e[26],sprocketMessage:e[24],sprocketMessageType:e[25],sprocketVersions:e[22]};return void 0!==e[20]&&(o.sprocketScript=e[20]),t=new jy({props:o}),$.push(()=>X(t,"sprocketScript",i)),t.$on("restartSprocket",e[56]),t.$on("deleteSprocket",e[57]),t.$on("sprocketFileSelect",e[68]),t.$on("uploadSprocketScript",e[69]),t.$on("saveSprocket",e[55]),t.$on("loadSprocket",e[54]),t.$on("loadVersions",e[58]),t.$on("loadVersion",e[113]),t.$on("deleteVersion",e[114]),t.$on("openLoginModal",e[71]),{c(){ee(t.$$.fragment)},m(e,n){te(t,e,n),r=!0},p(e,r){const i={};2&r[0]&&(i.isLoggedIn=e[1]),16&r[0]&&(i.userRole=e[4]),2097152&r[0]&&(i.sprocketStatus=e[21]),8388608&r[0]&&(i.isLoadingSprocket=e[23]),67108864&r[0]&&(i.sprocketUploadFile=e[26]),16777216&r[0]&&(i.sprocketMessage=e[24]),33554432&r[0]&&(i.sprocketMessageType=e[25]),4194304&r[0]&&(i.sprocketVersions=e[22]),!n&&1048576&r[0]&&(n=!0,i.sprocketScript=e[20],H(()=>n=!1)),t.$set(i)},i(e){r||(W(t.$$.fragment,e),r=!0)},o(e){Z(t.$$.fragment,e),r=!1},d(e){ne(t,e)}}}function NI(e){let t,n,r,i;const o=[hE,fE,dE],s=[];function a(e,t){return"managed"!==e[9]?0:e[1]&&"owner"===e[4]?1:2}return n=a(e),r=s[n]=o[n](e),{c(){t=h("div"),r.c(),A(t,"class","managed-acl-view svelte-u3u5mw")},m(e,r){u(e,t,r),s[n].m(t,null),i=!0},p(e,i){let l=n;n=a(e),n===l?s[n].p(e,i):(z(),Z(s[l],1,1,()=>{s[l]=null}),Y(),r=s[n],r?r.p(e,i):(r=s[n]=o[n](e),r.c()),W(r,1),r.m(t,null))},i(e){i||(W(r),i=!0)},o(e){Z(r),i=!1},d(e){e&&d(t),s[n].d()}}}function LI(e){let t,n,r;function i(t){e[111](t)}let o={userPubkey:e[2],userRole:e[4],policyEnabled:e[8],publishError:e[35]};return void 0!==e[34]&&(o.composeEventJson=e[34]),t=new Ry({props:o}),$.push(()=>X(t,"composeEventJson",i)),t.$on("reformatJson",e[91]),t.$on("signEvent",e[92]),t.$on("publishEvent",e[93]),t.$on("clearError",e[94]),{c(){ee(t.$$.fragment)},m(e,n){te(t,e,n),r=!0},p(e,r){const i={};4&r[0]&&(i.userPubkey=e[2]),16&r[0]&&(i.userRole=e[4]),256&r[0]&&(i.policyEnabled=e[8]),16&r[1]&&(i.publishError=e[35]),!n&&8&r[1]&&(n=!0,i.composeEventJson=e[34],H(()=>n=!1)),t.$set(i)},i(e){r||(W(t.$$.fragment,e),r=!0)},o(e){Z(t.$$.fragment,e),r=!1},d(e){ne(t,e)}}}function OI(e){let t,n;return t=new zk({props:{isLoggedIn:e[1],userPubkey:e[2],userSigner:e[13],userPrivkey:e[14],currentEffectiveRole:e[10]}}),t.$on("openLoginModal",e[71]),{c(){ee(t.$$.fragment)},m(e,r){te(t,e,r),n=!0},p(e,n){const r={};2&n[0]&&(r.isLoggedIn=e[1]),4&n[0]&&(r.userPubkey=e[2]),8192&n[0]&&(r.userSigner=e[13]),16384&n[0]&&(r.userPrivkey=e[14]),1024&n[0]&&(r.currentEffectiveRole=e[10]),t.$set(r)},i(e){n||(W(t.$$.fragment,e),n=!0)},o(e){Z(t.$$.fragment,e),n=!1},d(e){ne(t,e)}}}function MI(e){let t,n;return t=new nv({props:{isLoggedIn:e[1],userPubkey:e[2],userSigner:e[13],currentEffectiveRole:e[10]}}),t.$on("openLoginModal",e[71]),{c(){ee(t.$$.fragment)},m(e,r){te(t,e,r),n=!0},p(e,n){const r={};2&n[0]&&(r.isLoggedIn=e[1]),4&n[0]&&(r.userPubkey=e[2]),8192&n[0]&&(r.userSigner=e[13]),1024&n[0]&&(r.currentEffectiveRole=e[10]),t.$set(r)},i(e){n||(W(t.$$.fragment,e),n=!0)},o(e){Z(t.$$.fragment,e),n=!1},d(e){ne(t,e)}}}function _I(e){let t,n;return t=new dy({props:{isLoggedIn:e[1],userRole:e[4],userPubkey:e[2],filteredEvents:e[42],expandedEvents:e[19],isLoadingEvents:e[7],showOnlyMyEvents:CE,showFilterBuilder:e[16]}}),t.$on("scroll",e[90]),t.$on("toggleEventExpansion",e[107]),t.$on("deleteEvent",e[108]),t.$on("copyEventToClipboard",e[109]),t.$on("toggleChange",e[46]),t.$on("loadAllEvents",e[110]),t.$on("toggleFilterBuilder",e[77]),t.$on("filterApply",e[78]),t.$on("filterClear",e[79]),{c(){ee(t.$$.fragment)},m(e,r){te(t,e,r),n=!0},p(e,n){const r={};2&n[0]&&(r.isLoggedIn=e[1]),16&n[0]&&(r.userRole=e[4]),4&n[0]&&(r.userPubkey=e[2]),2048&n[1]&&(r.filteredEvents=e[42]),524288&n[0]&&(r.expandedEvents=e[19]),128&n[0]&&(r.isLoadingEvents=e[7]),65536&n[0]&&(r.showFilterBuilder=e[16]),t.$set(r)},i(e){n||(W(t.$$.fragment,e),n=!0)},o(e){Z(t.$$.fragment,e),n=!1},d(e){ne(t,e)}}}function HI(e){let t,n;return t=new dm({props:{isLoggedIn:e[1],currentEffectiveRole:e[10],selectedFile:e[17],aclMode:e[9],importMessage:e[18]}}),t.$on("fileSelect",e[87]),t.$on("importEvents",e[88]),t.$on("openLoginModal",e[71]),{c(){ee(t.$$.fragment)},m(e,r){te(t,e,r),n=!0},p(e,n){const r={};2&n[0]&&(r.isLoggedIn=e[1]),1024&n[0]&&(r.currentEffectiveRole=e[10]),131072&n[0]&&(r.selectedFile=e[17]),512&n[0]&&(r.aclMode=e[9]),262144&n[0]&&(r.importMessage=e[18]),t.$set(r)},i(e){n||(W(t.$$.fragment,e),n=!0)},o(e){Z(t.$$.fragment,e),n=!1},d(e){ne(t,e)}}}function jI(e){let t,n;return t=new im({props:{isLoggedIn:e[1],currentEffectiveRole:e[10],aclMode:e[9]}}),t.$on("exportMyEvents",e[86]),t.$on("exportAllEvents",e[85]),t.$on("openLoginModal",e[71]),{c(){ee(t.$$.fragment)},m(e,r){te(t,e,r),n=!0},p(e,n){const r={};2&n[0]&&(r.isLoggedIn=e[1]),1024&n[0]&&(r.currentEffectiveRole=e[10]),512&n[0]&&(r.aclMode=e[9]),t.$set(r)},i(e){n||(W(t.$$.fragment,e),n=!0)},o(e){Z(t.$$.fragment,e),n=!1},d(e){ne(t,e)}}}function GI(t){let n;return{c(){n=h("p"),n.textContent="Log in to access your user dashboard",A(n,"class","svelte-u3u5mw")},m(e,t){u(e,n,t)},p:e,d(e){e&&d(n)}}}function KI(e){let t,n,r,i=(e[3]?.name||e[2].slice(0,8)+"...")+"";return{c(){t=h("p"),n=g("Welcome "),r=g(i),A(t,"class","svelte-u3u5mw")},m(e,i){u(e,t,i),c(t,n),c(t,r)},p(e,t){12&t[0]&&i!==(i=(e[3]?.name||e[2].slice(0,8)+"...")+"")&&k(r,i)},d(e){e&&d(t)}}}function JI(e){let t,n,i,o,s,a,l,f,p,y,v,b,I,E,C,x,B,S,F,Q,R,D=e[180].label+"",P=e[43].get(e[180].id)?.isLoading,T=!e[43].get(e[180].id)?.hasMore&&e[43].get(e[180].id)?.events?.length>0;function U(){return e[121](e[180])}function $(e,t){return 64&t[0]&&(E=null),64&t[0]&&(C=null),null==E&&(E=!!(e[43].get(e[180].id)?.events?.length>0)),E?qI:(null==C&&(C=!e[43].get(e[180].id)?.isLoading),C?VI:void 0)}v=new vI({props:{filter:e[43].get(e[180].id)?.filter||{}}}),v.$on("sweep",function(){return e[122](e[180])});let N=$(e,[-1,-1,-1,-1,-1,-1]),L=N&&N(e),O=P&&ZI(),M=T&&XI();function _(...t){return e[127](e[180],...t)}return{c(){t=h("div"),n=h("div"),i=h("h2"),o=g("🔍 "),s=g(D),a=m(),l=h("button"),f=g("🔄 Refresh"),y=m(),ee(v.$$.fragment),b=m(),I=h("div"),L&&L.c(),x=m(),O&&O.c(),B=m(),M&&M.c(),S=m(),A(i,"class","svelte-u3u5mw"),A(l,"class","refresh-btn svelte-u3u5mw"),l.disabled=p=e[43].get(e[180].id)?.isLoading,A(n,"class","search-results-header svelte-u3u5mw"),A(I,"class","search-results-content svelte-u3u5mw"),A(t,"class","search-results-view svelte-u3u5mw")},m(e,r){u(e,t,r),c(t,n),c(n,i),c(i,o),c(i,s),c(n,a),c(n,l),c(l,f),c(t,y),te(v,t,null),c(t,b),c(t,I),L&&L.m(I,null),c(I,x),O&&O.m(I,null),c(I,B),M&&M.m(I,null),c(t,S),F=!0,Q||(R=[w(l,"click",U),w(I,"scroll",_)],Q=!0)},p(t,n){e=t,(!F||64&n[0])&&D!==(D=e[180].label+"")&&k(s,D),(!F||64&n[0]&&p!==(p=e[43].get(e[180].id)?.isLoading))&&(l.disabled=p);const r={};64&n[0]&&(r.filter=e[43].get(e[180].id)?.filter||{}),v.$set(r),N===(N=$(e,n))&&L?L.p(e,n):(L&&L.d(1),L=N&&N(e),L&&(L.c(),L.m(I,x))),64&n[0]&&(P=e[43].get(e[180].id)?.isLoading),P?O||(O=ZI(),O.c(),O.m(I,B)):O&&(O.d(1),O=null),64&n[0]&&(T=!e[43].get(e[180].id)?.hasMore&&e[43].get(e[180].id)?.events?.length>0),T?M||(M=XI(),M.c(),M.m(I,null)):M&&(M.d(1),M=null)},i(e){F||(W(v.$$.fragment,e),F=!0)},o(e){Z(v.$$.fragment,e),F=!1},d(e){e&&d(t),ne(v),L&&L.d(),O&&O.d(),M&&M.d(),Q=!1,r(R)}}}function VI(t){let n;return{c(){n=h("div"),n.innerHTML='<p class="svelte-u3u5mw">No search results found.</p>',A(n,"class","no-search-results svelte-u3u5mw")},m(e,t){u(e,n,t)},p:e,d(e){e&&d(n)}}}function qI(e){let t,n=e[43].get(e[180].id).events,r=[];for(let t=0;t<n.length;t+=1)r[t]=WI(SI(e,n,t));return{c(){for(let e=0;e<r.length;e+=1)r[e].c();t=y()},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,i){if(524372&i[0]|94208&i[1]){let o;for(n=e[43].get(e[180].id).events,o=0;o<n.length;o+=1){const s=SI(e,n,o);r[o]?r[o].p(s,i):(r[o]=WI(s),r[o].c(),r[o].m(t.parentNode,t))}for(;o<r.length;o+=1)r[o].d(1);r.length=n.length}},d(e){f(r,e),e&&d(t)}}}function zI(e){let t,n,r;function i(){return e[123](e[173])}return{c(){t=h("button"),t.textContent="🗑️",A(t,"class","delete-btn svelte-u3u5mw")},m(e,o){u(e,t,o),n||(r=w(t,"click",v(i)),n=!0)},p(t,n){e=t},d(e){e&&d(t),n=!1,r()}}}function YI(e){let t,n,r,i,o,s,a,l,f=JSON.stringify(e[173],null,2)+"";function p(...t){return e[126](e[173],...t)}return{c(){t=h("div"),n=h("div"),r=h("pre"),i=g(f),o=m(),s=h("button"),s.textContent="📋",A(r,"class","event-json svelte-u3u5mw"),A(s,"class","copy-json-btn svelte-u3u5mw"),A(s,"title","Copy minified JSON to clipboard"),A(n,"class","json-container svelte-u3u5mw"),A(t,"class","search-result-details svelte-u3u5mw")},m(e,d){u(e,t,d),c(t,n),c(n,r),c(r,i),c(n,o),c(n,s),a||(l=w(s,"click",v(p)),a=!0)},p(t,n){e=t,64&n[0]&&f!==(f=JSON.stringify(e[173],null,2)+"")&&k(i,f)},d(e){e&&d(t),a=!1,l()}}}function WI(e){let t,n,i,o,s,a,l,f,p,y,v,b,I,E,C,x,S,F,Q,R,D,P,T,U,$,N,L=bI(e[173].pubkey)+"",O=e[173].kind+"",M=AI(e[173].kind)+"",_=II(e[173].created_at)+"",H=kI(e[173].content)+"",j=e[19].has(e[173].id),G=5!==e[173].kind&&("admin"===e[4]||"owner"===e[4]||"write"===e[4]&&e[173].pubkey&&e[173].pubkey===e[2])&&zI(e);function K(){return e[124](e[173])}function J(...t){return e[125](e[173],...t)}let V=j&&YI(e);return{c(){t=h("div"),n=h("div"),i=h("div"),i.innerHTML='<div class="avatar-placeholder svelte-u3u5mw">👤</div>',o=m(),s=h("div"),a=h("div"),l=g(L),f=m(),p=h("div"),y=h("span"),v=g(O),b=m(),I=h("span"),E=g(M),C=m(),x=h("div"),S=h("div"),F=g(_),Q=m(),R=h("div"),D=g(H),P=m(),G&&G.c(),T=m(),V&&V.c(),U=m(),A(i,"class","search-result-avatar svelte-u3u5mw"),A(a,"class","search-result-author svelte-u3u5mw"),A(y,"class","kind-number svelte-u3u5mw"),A(I,"class","kind-name svelte-u3u5mw"),A(p,"class","search-result-kind svelte-u3u5mw"),A(s,"class","search-result-info svelte-u3u5mw"),A(S,"class","event-timestamp svelte-u3u5mw"),A(R,"class","event-content-single-line svelte-u3u5mw"),A(x,"class","search-result-content svelte-u3u5mw"),A(n,"class","search-result-row svelte-u3u5mw"),A(n,"role","button"),A(n,"tabindex","0"),A(t,"class","search-result-item svelte-u3u5mw"),B(t,"expanded",e[19].has(e[173].id))},m(e,r){u(e,t,r),c(t,n),c(n,i),c(n,o),c(n,s),c(s,a),c(a,l),c(s,f),c(s,p),c(p,y),c(y,v),c(p,b),c(p,I),c(I,E),c(n,C),c(n,x),c(x,S),c(S,F),c(x,Q),c(x,R),c(R,D),c(n,P),G&&G.m(n,null),c(t,T),V&&V.m(t,null),c(t,U),$||(N=[w(n,"click",K),w(n,"keydown",J)],$=!0)},p(r,i){e=r,64&i[0]&&L!==(L=bI(e[173].pubkey)+"")&&k(l,L),64&i[0]&&O!==(O=e[173].kind+"")&&k(v,O),64&i[0]&&M!==(M=AI(e[173].kind)+"")&&k(E,M),64&i[0]&&_!==(_=II(e[173].created_at)+"")&&k(F,_),64&i[0]&&H!==(H=kI(e[173].content)+"")&&k(D,H),5!==e[173].kind&&("admin"===e[4]||"owner"===e[4]||"write"===e[4]&&e[173].pubkey&&e[173].pubkey===e[2])?G?G.p(e,i):(G=zI(e),G.c(),G.m(n,null)):G&&(G.d(1),G=null),524352&i[0]&&(j=e[19].has(e[173].id)),j?V?V.p(e,i):(V=YI(e),V.c(),V.m(t,U)):V&&(V.d(1),V=null),524352&i[0]|4096&i[1]&&B(t,"expanded",e[19].has(e[173].id))},d(e){e&&d(t),G&&G.d(),V&&V.d(),$=!1,r(N)}}}function ZI(e){let t;return{c(){t=h("div"),t.innerHTML='<div class="loading-spinner svelte-u3u5mw"></div> \n <p class="svelte-u3u5mw">Searching...</p>',A(t,"class","loading-search-results svelte-u3u5mw")},m(e,n){u(e,t,n)},d(e){e&&d(t)}}}function XI(e){let t;return{c(){t=h("div"),t.innerHTML='<p class="svelte-u3u5mw">No more search results to load.</p>',A(t,"class","end-of-search-results svelte-u3u5mw")},m(e,n){u(e,t,n)},d(e){e&&d(t)}}}function eE(e){let t,n,r=e[180].id===e[5]&&JI(e);return{c(){r&&r.c(),t=y()},m(e,i){r&&r.m(e,i),u(e,t,i),n=!0},p(e,n){e[180].id===e[5]?r?(r.p(e,n),96&n[0]&&W(r,1)):(r=JI(e),r.c(),W(r,1),r.m(t.parentNode,t)):r&&(z(),Z(r,1,1,()=>{r=null}),Y())},i(e){n||(W(r),n=!0)},o(e){Z(r),n=!1},d(e){r&&r.d(e),e&&d(t)}}}function tE(t){let n,r,i=t[177].label+"";return{c(){n=h("option"),r=g(i),n.__value=t[177].value,n.value=n.__value},m(e,t){u(e,n,t),c(n,r)},p:e,d(e){e&&d(n)}}}function nE(e){let t;function n(e,t){return e[39]?oE:0===e[38].length?iE:rE}let r=n(e),i=r(e);return{c(){t=h("div"),i.c(),A(t,"class","recovery-results svelte-u3u5mw")},m(e,n){u(e,t,n),i.m(t,null)},p(e,o){r===(r=n(e))&&i?i.p(e,o):(i.d(1),i=r(e),i&&(i.c(),i.m(t,null)))},d(e){e&&d(t),i.d()}}}function rE(e){let t,n,r,i=e[38],o=[];for(let t=0;t<i.length;t+=1)o[t]=cE(FI(e,i,t));let s=e[40]&&uE(e);return{c(){t=h("div");for(let e=0;e<o.length;e+=1)o[e].c();n=m(),s&&s.c(),r=y(),A(t,"class","events-list svelte-u3u5mw")},m(e,i){u(e,t,i);for(let e=0;e<o.length;e+=1)o[e]&&o[e].m(t,null);u(e,n,i),s&&s.m(e,i),u(e,r,i)},p(e,n){if(1024&n[0]|4997248&n[1]){let r;for(i=e[38],r=0;r<i.length;r+=1){const s=FI(e,i,r);o[r]?o[r].p(s,n):(o[r]=cE(s),o[r].c(),o[r].m(t,null))}for(;r<o.length;r+=1)o[r].d(1);o.length=i.length}e[40]?s?s.p(e,n):(s=uE(e),s.c(),s.m(r.parentNode,r)):s&&(s.d(1),s=null)},d(e){e&&d(t),f(o,e),e&&d(n),s&&s.d(e),e&&d(r)}}}function iE(t){let n;return{c(){n=h("div"),n.textContent="No events found for this kind",A(n,"class","no-events svelte-u3u5mw")},m(e,t){u(e,n,t)},p:e,d(e){e&&d(n)}}}function oE(t){let n;return{c(){n=h("div"),n.textContent="Loading events...",A(n,"class","loading svelte-u3u5mw")},m(e,t){u(e,n,t)},p:e,d(e){e&&d(n)}}}function sE(e){let t;return{c(){t=g("Current Version")},m(e,n){u(e,t,n)},d(e){e&&d(t)}}}function aE(e){let t,n,r,i,o;function s(){return e[118](e[173])}let a="read"!==e[10]&&lE(e);return{c(){t=h("button"),t.textContent="🌐 Repost to All",n=m(),a&&a.c(),r=y(),A(t,"class","repost-all-button svelte-u3u5mw")},m(e,l){u(e,t,l),u(e,n,l),a&&a.m(e,l),u(e,r,l),i||(o=w(t,"click",s),i=!0)},p(t,n){"read"!==(e=t)[10]?a?a.p(e,n):(a=lE(e),a.c(),a.m(r.parentNode,r)):a&&(a.d(1),a=null)},d(e){e&&d(t),e&&d(n),a&&a.d(e),e&&d(r),i=!1,o()}}}function lE(e){let t,n,r;function i(){return e[119](e[173])}return{c(){t=h("button"),t.textContent="🔄 Repost",A(t,"class","repost-button svelte-u3u5mw")},m(e,o){u(e,t,o),n||(r=w(t,"click",i),n=!0)},p(t,n){e=t},d(e){e&&d(t),n=!1,r()}}}function cE(e){let t,n,r,i,o,s,a,l,f,p,y,b,I,E,C,x,S,F,Q=new Date(1e3*e[173].created_at).toLocaleString()+"",R=JSON.stringify(e[173],null,2)+"",D=e[174]&&sE(),P=!e[174]&&aE(e);function T(...t){return e[120](e[173],...t)}return{c(){t=h("div"),n=h("div"),r=h("div"),i=h("span"),D&&D.c(),o=m(),s=h("span"),a=g(Q),l=m(),f=h("div"),P&&P.c(),p=m(),y=h("button"),y.textContent="📋 Copy JSON",b=m(),I=h("div"),E=h("pre"),C=g(R),x=m(),A(i,"class","event-kind svelte-u3u5mw"),A(s,"class","event-timestamp svelte-u3u5mw"),A(r,"class","event-header-left svelte-u3u5mw"),A(y,"class","copy-json-btn svelte-u3u5mw"),A(f,"class","event-header-actions svelte-u3u5mw"),A(n,"class","event-header svelte-u3u5mw"),A(E,"class","event-json svelte-u3u5mw"),A(I,"class","event-content svelte-u3u5mw"),A(t,"class","event-item svelte-u3u5mw"),B(t,"old-version",!e[174])},m(e,d){u(e,t,d),c(t,n),c(n,r),c(r,i),D&&D.m(i,null),c(r,o),c(r,s),c(s,a),c(n,l),c(n,f),P&&P.m(f,null),c(f,p),c(f,y),c(t,b),c(t,I),c(I,E),c(E,C),c(t,x),S||(F=w(y,"click",v(T)),S=!0)},p(n,r){(e=n)[174]?D||(D=sE(),D.c(),D.m(i,null)):D&&(D.d(1),D=null),128&r[1]&&Q!==(Q=new Date(1e3*e[173].created_at).toLocaleString()+"")&&k(a,Q),e[174]?P&&(P.d(1),P=null):P?P.p(e,r):(P=aE(e),P.c(),P.m(f,p)),128&r[1]&&R!==(R=JSON.stringify(e[173],null,2)+"")&&k(C,R),4194432&r[1]&&B(t,"old-version",!e[174])},d(e){e&&d(t),D&&D.d(),P&&P.d(),S=!1,F()}}}function uE(e){let t,n,r,i;return{c(){t=h("button"),n=g("Load More Events"),A(t,"class","load-more svelte-u3u5mw"),t.disabled=e[39]},m(o,s){u(o,t,s),c(t,n),r||(i=w(t,"click",e[48]),r=!0)},p(e,n){256&n[1]&&(t.disabled=e[39])},d(e){e&&d(t),r=!1,i()}}}function dE(t){let n,r,i,o,s,a;return{c(){n=h("div"),r=h("p"),r.textContent="Please log in with owner permissions to access\n managed ACL configuration.",i=m(),o=h("button"),o.textContent="Log In",A(o,"class","login-btn svelte-u3u5mw"),A(n,"class","access-denied")},m(e,l){u(e,n,l),c(n,r),c(n,i),c(n,o),s||(a=w(o,"click",t[71]),s=!0)},p:e,i:e,o:e,d(e){e&&d(n),s=!1,a()}}}function fE(e){let t,n;return t=new $g({props:{userSigner:e[13],userPubkey:e[2]}}),{c(){ee(t.$$.fragment)},m(e,r){te(t,e,r),n=!0},p(e,n){const r={};8192&n[0]&&(r.userSigner=e[13]),4&n[0]&&(r.userPubkey=e[2]),t.$set(r)},i(e){n||(W(t.$$.fragment,e),n=!0)},o(e){Z(t.$$.fragment,e),n=!1},d(e){ne(t,e)}}}function hE(t){let n,r,i,o,s,a,l,f,p,y,w,v=(t[9]||"unknown")+"";return{c(){n=h("div"),r=h("h3"),r.textContent="⚠️ Managed ACL Mode Not Active",i=m(),o=h("p"),o.textContent='To use the Managed ACL interface, you need to set\n the ACL mode to "managed" in your relay\n configuration.',s=m(),a=h("p"),l=g("Current ACL mode: "),f=h("strong"),p=g(v),y=m(),w=h("p"),w.innerHTML='Please set <code class="svelte-u3u5mw">ORLY_ACL_MODE=managed</code> in your\n environment variables and restart the relay.',A(r,"class","svelte-u3u5mw"),A(o,"class","svelte-u3u5mw"),A(a,"class","svelte-u3u5mw"),A(w,"class","svelte-u3u5mw"),A(n,"class","acl-mode-warning svelte-u3u5mw")},m(e,t){u(e,n,t),c(n,r),c(n,i),c(n,o),c(n,s),c(n,a),c(a,l),c(a,f),c(f,p),c(n,y),c(n,w)},p(e,t){512&t[0]&&v!==(v=(e[9]||"unknown")+"")&&k(p,v)},i:e,o:e,d(e){e&&d(n)}}}function pE(e){let t,n,i,o,s,a,l,f,p,g;function y(e,t){return e[3]?mE:e[1]&&e[2]?gE:void 0}let b=y(e),k=b&&b(e);return{c(){t=h("div"),n=h("div"),i=h("div"),o=h("h2"),o.textContent="Settings",s=m(),a=h("button"),a.textContent="✕",l=m(),f=h("div"),k&&k.c(),A(o,"class","svelte-u3u5mw"),A(a,"class","close-btn svelte-u3u5mw"),A(i,"class","drawer-header svelte-u3u5mw"),A(f,"class","drawer-content"),A(n,"class","settings-drawer svelte-u3u5mw"),B(n,"dark-theme",e[0]),A(t,"class","drawer-overlay svelte-u3u5mw"),A(t,"role","button"),A(t,"tabindex","0")},m(r,d){u(r,t,d),c(t,n),c(n,i),c(i,o),c(i,s),c(i,a),c(n,l),c(n,f),k&&k.m(f,null),p||(g=[w(a,"click",e[76]),w(n,"click",v(e[102])),w(n,"keydown",v(e[103])),w(t,"click",e[76]),w(t,"keydown",e[129])],p=!0)},p(e,t){b===(b=y(e))&&k?k.p(e,t):(k&&k.d(1),k=b&&b(e),k&&(k.c(),k.m(f,null))),1&t[0]&&B(n,"dark-theme",e[0])},d(e){e&&d(t),k&&k.d(),p=!1,r(g)}}}function gE(e){let t,n,i,o,s,a,l,f,p,y,v,b,I,E,C,x,B,S=e[2].slice(0,16)+"",F=e[2].slice(-8)+"";return{c(){t=h("div"),n=h("button"),n.textContent="Log out",i=m(),o=h("h3"),o.textContent="Profile Loading",s=m(),a=h("p"),a.textContent="Your profile metadata is being loaded...",l=m(),f=h("button"),f.textContent="Retry Loading Profile",p=m(),y=h("div"),v=h("strong"),v.textContent="Public Key:",b=m(),I=g(S),E=g("..."),C=g(F),A(n,"class","logout-btn floating svelte-u3u5mw"),A(o,"class","svelte-u3u5mw"),A(a,"class","svelte-u3u5mw"),A(f,"class","retry-profile-btn svelte-u3u5mw"),A(y,"class","user-pubkey-display svelte-u3u5mw"),A(t,"class","profile-loading-section svelte-u3u5mw")},m(r,d){u(r,t,d),c(t,n),c(t,i),c(t,o),c(t,s),c(t,a),c(t,l),c(t,f),c(t,p),c(t,y),c(y,v),c(y,b),c(y,I),c(y,E),c(y,C),x||(B=[w(n,"click",e[73]),w(f,"click",e[84])],x=!0)},p(e,t){4&t[0]&&S!==(S=e[2].slice(0,16)+"")&&k(I,S),4&t[0]&&F!==(F=e[2].slice(-8)+"")&&k(C,F)},d(e){e&&d(t),x=!1,r(B)}}}function mE(e){let t,n,r,i,o,s,a,l,f,p,v,b,I,E,C,x=(e[3].name||"Unknown User")+"",B=e[3].banner&&yE(e);function S(e,t){return e[3].picture?vE:wE}let F=S(e),Q=F(e),R=e[3].nip05&&AE(e),D=e[3].about&&bE(e),P=e[4]&&"read"!==e[4]&&kE(e);return{c(){t=h("div"),n=h("div"),B&&B.c(),r=m(),i=h("button"),i.textContent="Log out",o=m(),Q.c(),s=m(),a=h("div"),l=h("h3"),f=g(x),p=m(),R&&R.c(),v=m(),D&&D.c(),b=m(),P&&P.c(),I=y(),A(i,"class","logout-btn floating svelte-u3u5mw"),A(l,"class","profile-username svelte-u3u5mw"),A(a,"class","name-row svelte-u3u5mw"),A(n,"class","profile-hero svelte-u3u5mw"),A(t,"class","profile-section svelte-u3u5mw")},m(d,h){u(d,t,h),c(t,n),B&&B.m(n,null),c(n,r),c(n,i),c(n,o),Q.m(n,null),c(n,s),c(n,a),c(a,l),c(l,f),c(a,p),R&&R.m(a,null),c(t,v),D&&D.m(t,null),u(d,b,h),P&&P.m(d,h),u(d,I,h),E||(C=w(i,"click",e[73]),E=!0)},p(e,i){e[3].banner?B?B.p(e,i):(B=yE(e),B.c(),B.m(n,r)):B&&(B.d(1),B=null),F===(F=S(e))&&Q?Q.p(e,i):(Q.d(1),Q=F(e),Q&&(Q.c(),Q.m(n,s))),8&i[0]&&x!==(x=(e[3].name||"Unknown User")+"")&&k(f,x),e[3].nip05?R?R.p(e,i):(R=AE(e),R.c(),R.m(a,null)):R&&(R.d(1),R=null),e[3].about?D?D.p(e,i):(D=bE(e),D.c(),D.m(t,null)):D&&(D.d(1),D=null),e[4]&&"read"!==e[4]?P?P.p(e,i):(P=kE(e),P.c(),P.m(I.parentNode,I)):P&&(P.d(1),P=null)},d(e){e&&d(t),B&&B.d(),Q.d(),R&&R.d(),D&&D.d(),e&&d(b),P&&P.d(e),e&&d(I),E=!1,C()}}}function yE(e){let t,n;return{c(){t=h("img"),a(t.src,n=e[3].banner)||A(t,"src",n),A(t,"alt","Profile banner"),A(t,"class","profile-banner svelte-u3u5mw")},m(e,n){u(e,t,n)},p(e,r){8&r[0]&&!a(t.src,n=e[3].banner)&&A(t,"src",n)},d(e){e&&d(t)}}}function wE(t){let n;return{c(){n=h("div"),n.textContent="👤",A(n,"class","profile-avatar-placeholder overlap svelte-u3u5mw")},m(e,t){u(e,n,t)},p:e,d(e){e&&d(n)}}}function vE(e){let t,n;return{c(){t=h("img"),a(t.src,n=e[3].picture)||A(t,"src",n),A(t,"alt","User avatar"),A(t,"class","profile-avatar overlap svelte-u3u5mw")},m(e,n){u(e,t,n)},p(e,r){8&r[0]&&!a(t.src,n=e[3].picture)&&A(t,"src",n)},d(e){e&&d(t)}}}function AE(e){let t,n,r=e[3].nip05+"";return{c(){t=h("span"),n=g(r),A(t,"class","profile-nip05-inline svelte-u3u5mw")},m(e,r){u(e,t,r),c(t,n)},p(e,t){8&t[0]&&r!==(r=e[3].nip05+"")&&k(n,r)},d(e){e&&d(t)}}}function bE(e){let t,n;return{c(){t=h("div"),n=h("p"),A(n,"class","profile-about svelte-u3u5mw"),A(t,"class","about-card svelte-u3u5mw")},m(r,i){u(r,t,i),c(t,n),n.innerHTML=e[41]},p(e,t){1024&t[1]&&(n.innerHTML=e[41])},d(e){e&&d(t)}}}function kE(e){let t,n,r,i,o,s,a=e[96](),l=[];for(let t=0;t<a.length;t+=1)l[t]=IE(xI(e,a,t));return{c(){t=h("div"),n=h("h3"),n.textContent="View as Role",r=m(),i=h("p"),i.textContent="See the interface as it appears for different\n permission levels:",o=m(),s=h("div");for(let e=0;e<l.length;e+=1)l[e].c();A(n,"class","svelte-u3u5mw"),A(i,"class","svelte-u3u5mw"),A(s,"class","radio-group svelte-u3u5mw"),A(t,"class","view-as-section svelte-u3u5mw")},m(e,a){u(e,t,a),c(t,n),c(t,r),c(t,i),c(t,o),c(t,s);for(let e=0;e<l.length;e+=1)l[e]&&l[e].m(s,null)},p(e,t){if(1040&t[0]|12&t[3]){let n;for(a=e[96](),n=0;n<a.length;n+=1){const r=xI(e,a,n);l[n]?l[n].p(r,t):(l[n]=IE(r),l[n].c(),l[n].m(s,null))}for(;n<l.length;n+=1)l[n].d(1);l.length=a.length}},d(e){e&&d(t),f(l,e)}}}function IE(e){let t,n,r,i,o,s,a,l,f,p=e[170].charAt(0).toUpperCase()+e[170].slice(1)+"",y=e[170]===e[4]?" (Default)":"";function v(){return e[128](e[170])}return{c(){t=h("label"),n=h("input"),i=m(),o=g(p),s=g(y),a=m(),A(n,"type","radio"),A(n,"name","viewAsRole"),n.value=e[170],n.checked=r=e[10]===e[170],A(n,"class","svelte-u3u5mw"),A(t,"class","radio-label svelte-u3u5mw")},m(e,r){u(e,t,r),c(t,n),c(t,i),c(t,o),c(t,s),c(t,a),l||(f=w(n,"change",v),l=!0)},p(t,i){e=t,1024&i[0]&&r!==(r=e[10]===e[170])&&(n.checked=r),16&i[0]&&y!==(y=e[170]===e[4]?" (Default)":"")&&k(s,y)},d(e){e&&d(t),l=!1,f()}}}function EE(e){let t,n,r,i,o,s,a,l,f,p,g,y,w,v;t=new Gg({props:{isDarkTheme:e[0],isLoggedIn:e[1],userRole:e[4],currentEffectiveRole:e[10],userProfile:e[3],userPubkey:e[2]}}),t.$on("openSettingsDrawer",e[75]),t.$on("openLoginModal",e[71]),i=new Wg({props:{isDarkTheme:e[0],tabs:e[11],selectedTab:e[5],version:e[33]}}),i.$on("selectTab",e[105]),i.$on("closeSearchTab",e[106]);const b=[jI,HI,_I,MI,OI,LI,NI,$I,UI,TI,PI,DI,RI],k=[];function I(e,t){return 96&t[0]&&(a=null),"export"===e[5]?0:"import"===e[5]?1:"events"===e[5]?2:"blossom"===e[5]?3:"bunker"===e[5]?4:"compose"===e[5]?5:"managed-acl"===e[5]?6:"sprocket"===e[5]?7:"policy"===e[5]?8:"logs"===e[5]?9:"recovery"===e[5]?10:(null==a&&(a=!!e[6].some(e[104])),a?11:12)}l=I(e,[-1,-1,-1,-1,-1,-1]),f=k[l]=b[l](e);let E=e[15]&&pE(e);function C(t){e[130](t)}let x={isDarkTheme:e[0]};return void 0!==e[12]&&(x.showModal=e[12]),y=new Kp({props:x}),$.push(()=>X(y,"showModal",C)),y.$on("login",e[72]),y.$on("close",e[74]),{c(){ee(t.$$.fragment),n=m(),r=h("div"),ee(i.$$.fragment),o=m(),s=h("main"),f.c(),p=m(),E&&E.c(),g=m(),ee(y.$$.fragment),A(s,"class","main-content svelte-u3u5mw"),A(r,"class","app-container svelte-u3u5mw"),B(r,"dark-theme",e[0])},m(e,a){te(t,e,a),u(e,n,a),u(e,r,a),te(i,r,null),c(r,o),c(r,s),k[l].m(s,null),u(e,p,a),E&&E.m(e,a),u(e,g,a),te(y,e,a),v=!0},p(e,n){const o={};1&n[0]&&(o.isDarkTheme=e[0]),2&n[0]&&(o.isLoggedIn=e[1]),16&n[0]&&(o.userRole=e[4]),1024&n[0]&&(o.currentEffectiveRole=e[10]),8&n[0]&&(o.userProfile=e[3]),4&n[0]&&(o.userPubkey=e[2]),t.$set(o);const a={};1&n[0]&&(a.isDarkTheme=e[0]),2048&n[0]&&(a.tabs=e[11]),32&n[0]&&(a.selectedTab=e[5]),4&n[1]&&(a.version=e[33]),i.$set(a);let c=l;l=I(e,n),l===c?k[l].p(e,n):(z(),Z(k[c],1,1,()=>{k[c]=null}),Y(),f=k[l],f?f.p(e,n):(f=k[l]=b[l](e),f.c()),W(f,1),f.m(s,null)),(!v||1&n[0])&&B(r,"dark-theme",e[0]),e[15]?E?E.p(e,n):(E=pE(e),E.c(),E.m(g.parentNode,g)):E&&(E.d(1),E=null);const u={};1&n[0]&&(u.isDarkTheme=e[0]),!w&&4096&n[0]&&(w=!0,u.showModal=e[12],H(()=>w=!1)),y.$set(u)},i(e){v||(W(t.$$.fragment,e),W(i.$$.fragment,e),W(f),W(y.$$.fragment,e),v=!0)},o(e){Z(t.$$.fragment,e),Z(i.$$.fragment,e),Z(f),Z(y.$$.fragment,e),v=!1},d(e){ne(t,e),e&&d(n),e&&d(r),ne(i),k[l].d(),e&&d(p),E&&E.d(e),e&&d(g),ne(y,e)}}}let CE=!1,xE=!1;function BE(e,t,n){let r,i,o,s,a;"undefined"!=typeof window&&(window.debugIndexedDB=Gh);let l=!1,c=!1,u=!1,d="",f="",h=null,p="",g=null,m=null,y=!1,w=localStorage.getItem("selectedTab")||"export",v=!1,A={},k=[],I=[],E=null,C="",B=new Set,S=!1,F=!0,Q=null,R="",D=new Map,P=[],U=0,$=[],N=!0,L=null,O="",M=null,_=[],H=!1,j="",G="info",K=!1,J=null,V="",q=!1,z=!1,Y="",W="info",Z=[],X=[],ee="",te="",ne="",re="",ie=null,oe="",se=[],ae=!1,le=!0,ce=null;function ue(e){B.has(e)?B.delete(e):B.add(e),n(19,B)}async function de(e,t){const n=JSON.stringify(e),r=await async function(e){try{return await navigator.clipboard.writeText(e),!0}catch(t){console.error("Failed to copy to clipboard:",t);try{const t=document.createElement("textarea");return t.value=e,document.body.appendChild(t),t.select(),document.execCommand("copy"),document.body.removeChild(t),!0}catch(e){return console.error("Fallback copy also failed:",e),!1}}}(n);!function(e,t=!0){if(!e)return;const n=e.textContent,r=e.style.backgroundColor;t?(e.textContent="",e.style.backgroundColor="#4CAF50"):(e.textContent="L",e.style.backgroundColor="#f44336"),setTimeout(()=>{e.textContent=n,e.style.backgroundColor=r},2e3)}(t.target.closest(".copy-json-btn"),r),r||alert("Failed to copy to clipboard. Please copy manually.")}async function fe(e){if(!u)return void alert("Please log in first");const t=I.find(t=>t.id===e);if(!t)return void alert("Event not found");if("admin"===p||"owner"===p||"write"===p&&t.pubkey&&t.pubkey===d){if(confirm("Are you sure you want to delete this event?"))try{if(!g)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:",d),console.log("Target event:",t),console.log("Target event pubkey:",t.pubkey);const i=await g.signEvent(r);console.log("Signed delete event:",i),console.log("Signed delete event pubkey:",i.pubkey),console.log("Delete event tags:",i.tags);const o=`${window.location.protocol.startsWith("https")?"wss:":"ws:"}//${window.location.host}/`;try{const e=await CI(o,i,g,d);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===d;if(s){const t=await Sh.publish(i);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 Mh(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 _h(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===d);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(97,I=I.filter(t=>t.id!==e)),$=$.filter(t=>t.id!==e),P=P.filter(t=>t.id!==e);for(const[t,n]of D)n.events&&(n.events=n.events.filter(t=>t.id!==e),D.set(t,n));me(),console.log("Reloading events to show delete event...");const r=CE&&u&&d?[d]:null;await $e(!0,r),alert(`Event deleted successfully (accepted by ${t.okCount} relay(s))`)}}else{const t=`${window.location.protocol.startsWith("https")?"wss:":"ws:"}//${window.location.host}/`,r=new Bh;await r.connectToRelay(t);const o=await r.publish(i);if(console.log("Delete event published to local relay only:",o),!(o.success&&o.okCount>0))throw new Error("Local relay did not accept the delete event");{await new Promise(e=>setTimeout(e,2e3));try{const t=await Mh(e,{timeout:5e3});t?(console.warn("Event still exists after deletion attempt:",t),alert(`Warning: Delete event was accepted by ${o.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 _h(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===d);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(97,I=I.filter(t=>t.id!==e)),$=$.filter(t=>t.id!==e),P=P.filter(t=>t.id!==e);for(const[t,n]of D)n.events&&(n.events=n.events.filter(t=>t.id!==e),D.set(t,n));me(),console.log("Reloading events to show delete event...");const t=CE&&u&&d?[d]:null;await $e(!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 he(){const e=oe?parseInt(oe):ie;if(null==e||isNaN(e))console.log("No valid kind to load, kindToUse:",e);else if(u){console.log("Loading recovery events for kind:",e,"user:",d),n(39,ae=!0);try{const t=[{kinds:[e],authors:[d],limit:100}];ce&&(t[0].until=ce),console.log("Recovery filters:",t);const r=await jh(t,{timeout:3e4,cacheFirst:!0});console.log("Recovery events received:",r.length),console.log("Recovery events kinds:",r.map(e=>e.kind)),n(38,se=ce?[...se,...r]:r),r.length>0?(ce=Math.min(...r.map(e=>e.created_at)),n(40,le=100===r.length)):n(40,le=!1)}catch(e){console.error("Failed to load recovery events:",e)}finally{n(39,ae=!1)}}else console.log("Not logged in, cannot load recovery events")}async function pe(e){if(confirm("Are you sure you want to repost this event?"))try{const t=`${window.location.protocol.startsWith("https")?"wss:":"ws:"}//${window.location.host}/`;console.log("Reposting event to local relay:",t,e);const r={...e};if(r.created_at=Math.floor(Date.now()/1e3),r.id="",r.sig="",e.kind>=3e4&&e.kind<=39999){const t=e.tags.find(e=>"d"===e[0]);t&&(r.tags=r.tags.filter(e=>"d"!==e[0]),r.tags.push(t))}if(g){const e=await g.signEvent(r);console.log("Signed event for repost:",e);const i=await Sh.publish(e,[t]);console.log("Repost publish result:",i),i.success&&i.okCount>0?(alert("Event reposted successfully!"),n(40,le=!1),await he()):alert("Failed to repost event. Check console for details.")}else alert("No signer available. Please log in.")}catch(e){console.error("Error reposting event:",e),alert("Error reposting event: "+e.message)}}async function ge(e){if(confirm("Are you sure you want to repost this event to all your write relays?"))try{const t=await async function(){if(!d)return[];try{const e=await Uh([{kinds:[10002],authors:[d],limit:1}]);if(0===e.length)return console.log("No relay list event found for user"),[];const t=e[0];console.log("Found relay list event:",t);const n=[];for(const e of t.tags)if("r"===e[0]&&e.length>=2){const t=e[1],r=e.length>=3?e[2]:null;r&&"write"!==r||n.push(t)}return console.log("Found write relays:",n),n}catch(e){return console.error("Error fetching user write relays:",e),[]}}(),r=`${window.location.protocol.startsWith("https")?"wss:":"ws:"}//${window.location.host}/`,i=[r,...t.filter(e=>e!==r)];1===i.length&&alert("No write relays found in your relay list. Only posting to local relay."),console.log("Reposting event to all relays:",i,e);const o={...e};if(o.created_at=Math.floor(Date.now()/1e3),o.id="",o.sig="",e.kind>=3e4&&e.kind<=39999){const t=e.tags.find(e=>"d"===e[0]);t&&(o.tags=o.tags.filter(e=>"d"!==e[0]),o.tags.push(t))}if(g){const e=await g.signEvent(o);console.log("Signed event for repost to all:",e);const t=await Sh.publish(e,i);console.log("Repost to all publish result:",t),t.success&&t.okCount>0?(alert(`Event reposted successfully to ${i.length} relays!`),n(40,le=!1),await he()):alert("Failed to repost event. Check console for details.")}else alert("No signer available. Please log in.")}catch(e){console.error("Error reposting event to all:",e),alert("Error reposting event to all: "+e.message)}}if("undefined"!=typeof window&&window.matchMedia){const e=window.matchMedia("(prefers-color-scheme: dark)");l=e.matches,e.addEventListener("change",e=>{n(0,l=e.matches)})}if("undefined"!=typeof localStorage){const e=localStorage.getItem("nostr_auth_method"),t=localStorage.getItem("nostr_pubkey");e&&t&&(u=!0,d=t,f=e,"extension"===e&&window.nostr&&(g=window.nostr),Pe(),Te()),function(){if("undefined"==typeof localStorage)return;try{const t=localStorage.getItem("app_state");if(t){const r=JSON.parse(t);r.selectedTab&&Ce.some(e=>e.id===r.selectedTab)&&n(5,w=r.selectedTab),r.expandedEvents&&n(19,B=new Set(r.expandedEvents)),r.globalEventsCache&&(P=r.globalEventsCache),r.globalCacheTimestamp&&(U=r.globalCacheTimestamp),void 0!==r.hasMoreEvents&&(F=r.hasMoreEvents),r.oldestEventTimestamp&&(Q=r.oldestEventTimestamp),void 0!==r.hasMoreMyEvents&&(N=r.hasMoreMyEvents),r.oldestMyEventTimestamp&&(L=r.oldestMyEventTimestamp),P.length>0&&((e=U)&&Date.now()-e<xh)&&n(97,I=P)}}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(99,K=t.enabled)}}catch(e){console.error("Error loading sprocket config:",e)}}(),async function(){try{const e=await fetch("/api/policy/config",{method:"GET",headers:{"Content-Type":"application/json"}});if(e.ok){const t=await e.json();n(8,q=t.enabled||!1)}}catch(e){console.error("Error loading policy config:",e),n(8,q=!1)}}(),async function(){try{const e=await async function(){try{const e=await fetch(window.location.origin,{headers:{Accept:"application/nostr+json"}});if(e.ok)return await e.json()}catch(e){console.error("Error fetching relay info:",e)}return null}();e&&e.version&&n(33,te=e.version)}catch(e){console.error("Error fetching relay version:",e)}}()}function me(){if("undefined"==typeof localStorage)return;const e={selectedTab:w,expandedEvents:Array.from(B),globalEventsCache:P,globalCacheTimestamp:U,hasMoreEvents:F,oldestEventTimestamp:Q};localStorage.setItem("app_state",JSON.stringify(e))}function ye(e){P=e.sort((e,t)=>t.created_at-e.created_at),U=Date.now(),me()}async function we(){if(u&&"owner"===p&&K)try{n(23,H=!0);const e=await fetch("/api/sprocket/status",{method:"GET",headers:{Authorization:`Nostr ${await Me("GET","/api/sprocket/status")}`,"Content-Type":"application/json"}});e.ok?n(21,M=await e.json()):ke("Failed to load sprocket status","error")}catch(e){ke(`Error loading sprocket status: ${e.message}`,"error")}finally{n(23,H=!1)}}async function ve(){if(u&&"owner"===p)try{n(23,H=!0);const e=await fetch("/api/sprocket/versions",{method:"GET",headers:{Authorization:`Nostr ${await Me("GET","/api/sprocket/versions")}`,"Content-Type":"application/json"}});e.ok?n(22,_=await e.json()):ke("Failed to load versions","error")}catch(e){ke(`Error loading versions: ${e.message}`,"error")}finally{n(23,H=!1)}}async function Ae(e){u&&"owner"===p&&(n(20,O=e.content),ke(`Loaded version: ${e.name}`,"success"))}async function be(e){if(u&&"owner"===p&&confirm(`Are you sure you want to delete version ${e}?`))try{n(23,H=!0);const t=await fetch("/api/sprocket/delete-version",{method:"POST",headers:{Authorization:`Nostr ${await Me("POST","/api/sprocket/delete-version")}`,"Content-Type":"application/json"},body:JSON.stringify({filename:e})});if(t.ok)ke(`Version ${e} deleted successfully`,"success"),await ve();else{ke(`Failed to delete version: ${await t.text()}`,"error")}}catch(e){ke(`Error deleting version: ${e.message}`,"error")}finally{n(23,H=!1)}}function ke(e,t="info"){n(24,j=e),n(25,G=t),setTimeout(()=>{n(24,j="")},5e3)}function Ie(e,t="info"){n(29,Y=e),n(30,W=t),"error"!==t&&setTimeout(()=>{n(29,Y="")},5e3)}async function Ee(){if(n(31,Z=[]),!V.trim())return n(31,Z=["Policy JSON is empty"]),Ie("Validation failed","error"),!1;try{const e=JSON.parse(V);if("object"!=typeof e||null===e)return n(31,Z=["Policy must be a JSON object"]),Ie("Validation failed","error"),!1;if(e.policy_admins)if(Array.isArray(e.policy_admins))for(const t of e.policy_admins)"string"==typeof t&&/^[0-9a-fA-F]{64}$/.test(t)||Z.push(`Invalid policy_admin pubkey: ${t}`);else Z.push("policy_admins must be an array");if(e.rules)if("object"!=typeof e.rules)Z.push("rules must be an object");else for(const[t,n]of Object.entries(e.rules))if(/^\d+$/.test(t)||Z.push(`Invalid kind number: ${t}`),n.tag_validation&&"object"==typeof n.tag_validation)for(const[e,t]of Object.entries(n.tag_validation))try{new RegExp(t)}catch(n){Z.push(`Invalid regex for tag '${e}': ${t}`)}return e.default_policy&&!["allow","deny"].includes(e.default_policy)&&Z.push("default_policy must be 'allow' or 'deny'"),Z.length>0?(Ie("Validation failed - see errors below","error"),!1):(Ie("Validation passed","success"),!0)}catch(e){return n(31,Z=[`JSON parse error: ${e.message}`]),Ie("Invalid JSON syntax","error"),!1}}const Ce=[{id:"export",icon:"📤",label:"Export"},{id:"import",icon:"💾",label:"Import",requiresAdmin:!0},{id:"events",icon:"📡",label:"Events"},{id:"blossom",icon:"🌸",label:"Blossom"},{id:"bunker",icon:"🔐",label:"Bunker",requiresWrite:!0},{id:"compose",icon:"✏️",label:"Compose",requiresWrite:!0},{id:"recovery",icon:"🔄",label:"Recovery"},{id:"managed-acl",icon:"🛡️",label:"Managed ACL",requiresOwner:!0},{id:"sprocket",icon:"⚙️",label:"Sprocket",requiresOwner:!0},{id:"policy",icon:"📜",label:"Policy",requiresOwner:!0},{id:"logs",icon:"📋",label:"Logs",requiresOwner:!0}];function xe(e){n(5,w=e),"sprocket"===e&&u&&"owner"===p&&K&&(we(),ve()),me()}function Be(){n(15,y=!1)}function Se(e){Fe(e)}function Fe(e){n(6,k=k.filter(t=>t.id!==e)),D.delete(e),w===e&&n(5,w="export")}async function Qe(e,t=!0){const n=D.get(e);if(n&&!n.isLoading){n.isLoading=!0,D.set(e,n);try{const r={...n.filter};!t&&n.oldestTimestamp&&(r.until=n.oldestTimestamp),t||(r.limit=200),console.log("Loading search results with filter:",r);const i=await Oh([r],{timeout:3e4});if(console.log("Received search results:",i.length,"events"),n.events=t?i.sort((e,t)=>t.created_at-e.created_at):[...n.events,...i].sort((e,t)=>t.created_at-e.created_at),i.length>0){const e=Math.min(...i.map(e=>e.created_at));(!n.oldestTimestamp||e<n.oldestTimestamp)&&(n.oldestTimestamp=e)}n.hasMore=i.length===(t?r.limit||100:200),n.isLoading=!1,D.set(e,n)}catch(t){console.error("Failed to load search results:",t),n.isLoading=!1,D.set(e,n),alert("Failed to load search results: "+t.message)}}}function Re(e,t){const{scrollTop:n,scrollHeight:r,clientHeight:i}=e.target;if(r-n-i<100){const e=D.get(t);e&&!e.isLoading&&e.hasMore&&async function(e){await Qe(e,!1)}(t)}}async function De(){if(u&&d&&!h)try{console.log("Auto-fetching profile for:",d),await Hh(),n(3,h=await Nh(d)),console.log("Profile auto-loaded:",h)}catch(e){console.error("Failed to auto-load profile:",e)}}async function Pe(){if(u&&d)try{const e=await fetch(`/api/permissions/${d}`);if(e.ok){const t=await e.json();n(4,p=t.permission||""),console.log("User role loaded:",p),console.log("Is owner?","owner"===p)}else console.error("Failed to fetch user role:",e.status),n(4,p="")}catch(e){console.error("Error fetching user role:",e),n(4,p="")}else n(4,p="")}async function Te(){try{const e=await fetch("/api/acl-mode");if(e.ok){const t=await e.json();n(9,ee=t.acl_mode||""),console.log("ACL mode loaded:",ee)}else console.error("Failed to fetch ACL mode:",e.status),n(9,ee="")}catch(e){console.error("Error fetching ACL mode:",e),n(9,ee="")}}async function Ue(e=[]){if("none"===ee||u)if("none"===ee||0!==e.length||"admin"===a||"owner"===a)try{const t={"Content-Type":"application/json"};"none"!==ee&&u&&(t.Authorization=await Oe("/api/export","POST"));const n=await fetch("/api/export",{method:"POST",headers:t,body:JSON.stringify({pubkeys:e})});if(!n.ok)throw new Error(`Export failed: ${n.status} ${n.statusText}`);const r=await n.blob(),i=window.URL.createObjectURL(r),o=document.createElement("a");o.href=i;const s=n.headers.get("Content-Disposition");let a="events.jsonl";if(s){const e=s.match(/filename="([^"]+)"/);e&&(a=e[1])}o.download=a,document.body.appendChild(o),o.click(),document.body.removeChild(o),window.URL.revokeObjectURL(i)}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 $e(e=!1,t=null){if(!u||"read"!==p&&"write"!==p&&"admin"!==p&&"owner"!==p)alert("Read, write, admin, or owner permission required");else if(!S){n(7,S=!0),e&&(Q=null);try{console.log("Loading events with authors filter:",t,"including delete events");const r=e?Math.floor(Date.now()/1e3):Q,i=A.authors||t,o=await async function(e={}){const{limit:t=100,since:n=null,until:r=null,authors:i=null,kinds:o=null,...s}=e,a=[{...s}];return n&&(a[0].since=n),r&&(a[0].until=r),i&&(a[0].authors=i),o&&(a[0].kinds=o),t&&(a[0].limit=t),await Oh(a,{timeout:3e4})}({...A,limit:e?100:200,until:A.until||r,authors:i});if(console.log("Received events:",o.length,"events"),t&&o.length>0){const e=o.filter(e=>e.pubkey&&e.pubkey!==d);e.length>0&&console.warn("Server returned non-user events:",e.length,"out of",o.length)}if(e?(n(97,I=o.sort((e,t)=>t.created_at-e.created_at)),ye(o)):(n(97,I=[...I,...o].sort((e,t)=>t.created_at-e.created_at)),ye(I)),o.length>0){const e=Math.min(...o.map(e=>e.created_at));(!Q||e<Q)&&(Q=e)}F=o.length===(e?1e3:200),e&&F&&setTimeout(()=>{if("events"===w){const e=document.querySelectorAll(".events-view-content")[0];e&&e.scrollHeight<=e.clientHeight&&Ne()}},100)}catch(e){console.error("Failed to load events:",e),alert("Failed to load events: "+e.message)}finally{n(7,S=!1)}}}async function Ne(){await $e(!1)}let Le=!1;async function Oe(e,t){if(!u||!d)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:d};let r;if(g&&"extension"===f)try{r=await g.signEvent(n)}catch(e){throw new Error("Failed to sign with extension: "+e.message)}else{if("nsec"!==f)throw new Error("No valid signer available");n.id="mock-id-"+Date.now(),n.sig="mock-signature-"+Date.now(),r=n}const i=JSON.stringify(r);return`Nostr ${btoa(i)}`}async function Me(e,t){if(!u||!d)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:d};let r;if(g&&"extension"===f)try{r=await g.signEvent(n)}catch(e){throw new Error("Failed to sign with extension: "+e.message)}else{if("nsec"!==f)throw new Error("No valid signer available");n.id="mock-id-"+Date.now(),n.sig="mock-signature-"+Date.now(),r=n}const i=JSON.stringify(r);return btoa(i)}function _e(e,t){const n=e.toLowerCase();if(n.includes("policy")||n.includes("blocked")||n.includes("denied")){let n=`Policy Error: ${e}`;return null!==t&&(n+=`\n\nKind ${t} may be restricted by the relay's policy configuration.`),q&&(n+="\n\nThe relay has policy enforcement enabled. Contact a relay administrator to allow this event kind or adjust your permissions."),n}if(n.includes("auth")||n.includes("permission")||n.includes("unauthorized"))return`Permission Error: ${e}\n\nYour current permissions may not allow publishing this type of event. Current role: ${p||"unknown"}. Contact a relay administrator to upgrade your permissions.`;if(n.includes("kind")||n.includes("not allowed")||n.includes("restricted")){let n=`Event Type Error: ${e}`;return null!==t&&(n+=`\n\nKind ${t} is not currently allowed on this relay.`),n+="\n\nThe relay administrator may need to update the policy configuration to allow this event kind.",n}return n.includes("rate")||n.includes("limit")||n.includes("too many")?`Rate Limit Error: ${e}\n\nPlease wait a moment before trying again.`:n.includes("size")||n.includes("too large")||n.includes("content")?`Size Limit Error: ${e}\n\nThe event may exceed the relay's size limits. Try reducing the content length.`:`Publishing failed: ${e}`}function He(e){n(98,R=e),localStorage.setItem("viewAsRole",e),console.log("View as role changed to:",e,"Current effective role:",a)}R=localStorage.getItem("viewAsRole")||"";return e.$$.update=()=>{var t;if(6&e.$$.dirty[0]|16&e.$$.dirty[3]&&n(42,r=I.sort((e,t)=>t.created_at-e.created_at)),8&e.$$.dirty[0]&&n(41,i=h?.about?(t=h.about,t?t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#039;"):"").replace(/\n{2,}/g,"<br>"):""),16&e.$$.dirty[0]|32&e.$$.dirty[3]&&n(10,a=R&&""!==R?R:p),1810&e.$$.dirty[0]|96&e.$$.dirty[3]&&n(101,o=Ce.filter(e=>{const t=a;return!(e.requiresAdmin&&(!u||"admin"!==t&&"owner"!==t))&&(!(e.requiresOwner&&(!u||"owner"!==t))&&(!(e.requiresWrite&&(!u||"read"===t))&&(!("sprocket"===e.id&&!K)&&(!("policy"===e.id&&!q)&&(("managed-acl"!==e.id||"managed"===ee)&&(console.log(`Tab ${e.id} filter check:`,{isLoggedIn:u,userRole:p,viewAsRole:R,currentRole:t,requiresAdmin:e.requiresAdmin,requiresOwner:e.requiresOwner,requiresWrite:e.requiresWrite,visible:!0}),!0))))))})),64&e.$$.dirty[0]|256&e.$$.dirty[3]&&n(11,s=[...o,...k]),2578&e.$$.dirty[0]|256&e.$$.dirty[3]&&console.log("Tabs debug:",{isLoggedIn:u,userRole:p,aclMode:ee,filteredBaseTabs:o.map(e=>e.id),allTabs:s.map(e=>e.id)}),1&e.$$.dirty[0]&&"undefined"!=typeof document&&(l?document.body.classList.add("dark-theme"):document.body.classList.remove("dark-theme")),14&e.$$.dirty[0]&&u&&d&&!h&&De(),182&e.$$.dirty[0]|144&e.$$.dirty[3]&&"events"===w&&u&&("read"===p||"write"===p||"admin"===p||"owner"===p)&&0===I.length&&!Le&&!S){n(100,Le=!0);$e(!0,null)}32&e.$$.dirty[0]|16&e.$$.dirty[3]&&("events"!==w||"events"===w&&I.length>0)&&n(100,Le=!1),32&e.$$.dirty[0]&&localStorage.setItem("selectedTab",w)},[l,u,d,h,p,w,k,S,q,ee,a,s,c,g,m,y,v,E,C,B,O,M,_,H,j,G,J,V,z,Y,W,Z,X,te,ne,re,ie,oe,se,ae,le,i,r,D,ue,de,async function(){console.log("Toggle changed, showOnlyMyEvents:",CE),n(100,Le=!1),await $e(!0,null)},fe,he,pe,ge,function(){console.log("selectRecoveryKind called, recoverySelectedKind:",ie),null!=ie?(n(37,oe=""),n(38,se=[]),ce=null,n(40,le=!0),he()):console.log("No kind selected, skipping load")},function(){console.log("handleCustomKindInput called, recoveryCustomKind:",oe);const e=parseInt(oe);""!==oe&&!isNaN(e)&&e>=0&&(n(36,ie=null),n(38,se=[]),ce=null,n(40,le=!0),he())},function(e){const t=se.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(u&&"owner"===p)try{n(23,H=!0);const e=await fetch("/api/sprocket/status",{method:"GET",headers:{Authorization:`Nostr ${await Me("GET","/api/sprocket/status")}`,"Content-Type":"application/json"}});if(e.ok){const t=await e.json();n(20,O=t.script_content||""),n(21,M=t),ke("Script loaded successfully","success")}else ke("Failed to load script","error")}catch(e){ke(`Error loading script: ${e.message}`,"error")}finally{n(23,H=!1)}},async function(){if(u&&"owner"===p)try{n(23,H=!0);const e=await fetch("/api/sprocket/update",{method:"POST",headers:{Authorization:`Nostr ${await Me("POST","/api/sprocket/update")}`,"Content-Type":"text/plain"},body:O});if(e.ok)ke("Script saved and updated successfully","success"),await we(),await ve();else{ke(`Failed to save script: ${await e.text()}`,"error")}}catch(e){ke(`Error saving script: ${e.message}`,"error")}finally{n(23,H=!1)}},async function(){if(u&&"owner"===p)try{n(23,H=!0);const e=await fetch("/api/sprocket/restart",{method:"POST",headers:{Authorization:`Nostr ${await Me("POST","/api/sprocket/restart")}`,"Content-Type":"application/json"}});if(e.ok)ke("Sprocket restarted successfully","success"),await we();else{ke(`Failed to restart sprocket: ${await e.text()}`,"error")}}catch(e){ke(`Error restarting sprocket: ${e.message}`,"error")}finally{n(23,H=!1)}},async function(){if(u&&"owner"===p&&confirm("Are you sure you want to delete the sprocket script? This will stop the current process."))try{n(23,H=!0);const e=await fetch("/api/sprocket/update",{method:"POST",headers:{Authorization:`Nostr ${await Me("POST","/api/sprocket/update")}`,"Content-Type":"text/plain"},body:""});if(e.ok)n(20,O=""),ke("Sprocket script deleted successfully","success"),await we(),await ve();else{ke(`Failed to delete script: ${await e.text()}`,"error")}}catch(e){ke(`Error deleting script: ${e.message}`,"error")}finally{n(23,H=!1)}},ve,Ae,be,async function(){if(u&&("owner"===p||xE))try{n(28,z=!0),n(31,Z=[]);const e={kinds:[12345],limit:1},t=await jh(e);if(t&&t.length>0){n(27,V=t[0].content);try{n(27,V=JSON.stringify(JSON.parse(V),null,2))}catch(e){}Ie("Policy loaded successfully","success")}else{const e=await fetch("/api/policy",{method:"GET",headers:{Authorization:`Nostr ${await Me("GET","/api/policy")}`,"Content-Type":"application/json"}});if(e.ok){const t=await e.json();n(27,V=JSON.stringify(t,null,2)),Ie("Policy loaded from file","success")}else Ie("No policy configuration found","info"),n(27,V="")}}catch(e){Ie(`Error loading policy: ${e.message}`,"error")}finally{n(28,z=!1)}},Ee,async function(){if(!u||"owner"!==p&&!xE)return;if(await Ee())try{n(28,z=!0);const e={kind:12345,created_at:Math.floor(Date.now()/1e3),tags:[],content:V},t=await CI(e,g);t.success?Ie("Policy updated successfully","success"):Ie(`Failed to publish policy: ${t.error||"Unknown error"}`,"error")}catch(e){Ie(`Error saving policy: ${e.message}`,"error")}finally{n(28,z=!1)}},function(){try{const e=JSON.parse(V);n(27,V=JSON.stringify(e,null,2)),Ie("JSON formatted","success")}catch(e){Ie(`Cannot format: ${e.message}`,"error")}},function(e){const t=e.detail;if(!t)return void Ie("Please enter a pubkey","error");const r=function(e){if(!e)return null;if(/^[0-9a-fA-F]{64}$/.test(e))return e.toLowerCase();if(e.startsWith("npub1"))try{const t="qpzry9x8gf2tvdw0s3jn54khce6mua7l",n=e.slice(5);let r=[];for(const e of n){const n=t.indexOf(e.toLowerCase());if(-1===n)throw new Error("Invalid character in npub");r.push(...[...Array(5)].map((e,t)=>n>>4-t&1))}r=r.slice(0,-30);const i=[];for(let e=0;e+8<=r.length;e+=8){let t=0;for(let n=0;n<8;n++)t=t<<1|r[e+n];i.push(t)}return i.map(e=>e.toString(16).padStart(2,"0")).join("")}catch(e){return console.error("Failed to decode npub:",e),null}return null}(t);if(r&&64===r.length)try{const e=JSON.parse(V||"{}");if(e.policy_admins||(e.policy_admins=[]),e.policy_admins.includes(r))return void Ie("Admin already in list","warning");e.policy_admins.push(r),n(27,V=JSON.stringify(e,null,2)),Ie("Admin added - click 'Save & Publish' to apply","info")}catch(e){Ie(`Error adding admin: ${e.message}`,"error")}else Ie("Invalid pubkey format. Use hex (64 chars) or npub","error")},function(e){const t=e.detail;try{const e=JSON.parse(V||"{}");e.policy_admins&&(e.policy_admins=e.policy_admins.filter(e=>e!==t),n(27,V=JSON.stringify(e,null,2)),Ie("Admin removed - click 'Save & Publish' to apply","info"))}catch(e){Ie(`Error removing admin: ${e.message}`,"error")}},async function(){if(u&&("owner"===p||xE))try{n(28,z=!0),n(32,X=[]);let e=[];try{e=JSON.parse(V||"{}").policy_admins||[]}catch(e){return void Ie("Cannot parse policy JSON to get admins","error")}if(0===e.length)return void Ie("No policy admins configured","warning");const t={kinds:[3],authors:e,limit:e.length},r=await jh(t),i=new Set;for(const e of r)if(e.tags)for(const t of e.tags)"p"===t[0]&&t[1]&&64===t[1].length&&i.add(t[1]);n(32,X=Array.from(i)),Ie(`Loaded ${X.length} follows from ${r.length} admin(s)`,"success")}catch(e){Ie(`Error loading follows: ${e.message}`,"error")}finally{n(28,z=!1)}},function(e){n(26,J=e.target.files[0])},async function(){if(u&&"owner"===p&&J)try{n(23,H=!0);const e=await J.text(),t=await fetch("/api/sprocket/update",{method:"POST",headers:{Authorization:`Nostr ${await Me("POST","/api/sprocket/update")}`,"Content-Type":"text/plain"},body:e});if(t.ok)n(20,O=e),ke("Script uploaded and updated successfully","success"),await we(),await ve();else{ke(`Failed to upload script: ${await t.text()}`,"error")}}catch(e){ke(`Error uploading script: ${e.message}`,"error")}finally{n(23,H=!1),n(26,J=null);const e=document.getElementById("sprocket-upload-file");e&&(e.value="")}},xe,function(){u||n(12,c=!0)},async function(e){const{method:t,pubkey:r,privateKey:i,signer:o}=e.detail;n(1,u=!0),n(2,d=r),f=t,n(13,g=o),n(12,c=!1),n(14,m="nsec"===t&&i?i:null);try{if(await Hh(),"extension"===t&&o)Sh.setSigner(o);else if("nsec"===t&&i){const e=new Ef(i);Sh.setSigner(e)}n(3,h=await Nh(r)),console.log("Profile loaded:",h)}catch(e){console.error("Failed to load profile:",e)}await Pe(),await Te()},function(){n(1,u=!1),n(2,d=""),f="",n(3,h=null),n(4,p=""),n(13,g=null),n(14,m=null),n(15,y=!1),$=[],n(97,I=[]),P=[],U=0,me(),"undefined"!=typeof localStorage&&(localStorage.removeItem("nostr_auth_method"),localStorage.removeItem("nostr_pubkey"),localStorage.removeItem("nostr_privkey"))},function(){n(12,c=!1)},function(){n(15,y=!0)},Be,function(){n(16,v=!v)},function(e){const{searchText:t,selectedKinds:n,pubkeys:r,eventIds:i,tags:o,sinceTimestamp:s,untilTimestamp:a,limit:l}=e.detail,c=function({searchText:e=null,kinds:t=[],authors:n=[],ids:r=[],tags:i=[],since:o=null,until:s=null,limit:a=null}){const l={};return e&&e.trim()&&(l.search=e.trim()),t&&t.length>0&&(l.kinds=t),n&&n.length>0&&(l.authors=n),r&&r.length>0&&(l.ids=r),i&&i.length>0&&i.forEach(e=>{if(e.name&&e.value){const t=`#${e.name}`;l[t]||(l[t]=[]),l[t].push(e.value)}}),o&&(l.since=o),s&&(l.until=s),a&&a>0&&(l.limit=a),l}({searchText:t,kinds:n,authors:r,ids:i,tags:o,since:s,until:a,limit:l||100});A=c,$e(!0,null)},function(){A={},$e(!0,null)},Se,Fe,Qe,Re,De,async function(){await Ue([])},async function(){await Ue([d])},function(e){n(17,E=e.detail.target.files[0])},async function(){if("none"!==ee&&(!u||"admin"!==p&&"owner"!==p))return n(18,C="Admin or owner permission required"),void setTimeout(()=>{n(18,C="")},5e3);if(!E)return n(18,C="Please select a file"),void setTimeout(()=>{n(18,C="")},5e3);try{n(18,C="Uploading...");const e={};"none"!==ee&&u&&(e.Authorization=await Oe("/api/import","POST"));const t=new FormData;t.append("file",E);const r=await fetch("/api/import",{method:"POST",headers:e,body:t});if(!r.ok)throw new Error(`Import failed: ${r.status} ${r.statusText}`);await r.json();n(18,C="Upload complete"),n(17,E=null),document.getElementById("import-file").value="",setTimeout(()=>{n(18,C="")},5e3)}catch(e){console.error("Import failed:",e),n(18,C="Import failed: "+e.message),setTimeout(()=>{n(18,C="")},5e3)}},$e,function(e){const{scrollTop:t,scrollHeight:n,clientHeight:r}=e.target;n-t-r<100&&Ne()},function(){try{if(!ne.trim())return void alert("Please enter some JSON to reformat");const e=JSON.parse(ne);n(34,ne=JSON.stringify(e,null,2))}catch(e){alert("Invalid JSON: "+e.message)}},async function(){try{if(!ne.trim())return void alert("Please enter an event to sign");if(!u||!d)return void alert("Please log in to sign events");if(!g)return void alert("No signer available. Please log in with a valid authentication method.");const e=JSON.parse(ne);e.pubkey=d,e.created_at=Math.floor(Date.now()/1e3),delete e.id,delete e.sig;const t=await g.signEvent(e);n(34,ne=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(){n(35,re="");try{if(!ne.trim())return void n(35,re="Please enter an event to publish");if(!u)return void n(35,re="Please log in to publish events");if(!g)return void n(35,re="No signer available. Please log in with a valid authentication method.");let e;try{e=JSON.parse(ne)}catch(e){return void n(35,re=`Invalid JSON: ${e.message}`)}if(!e.id||!e.sig)return void n(35,re='Event must be signed before publishing. Please click "Sign" first.');if("read"===p)return void n(35,re=`Permission denied: Your current role is "${p}" which does not allow publishing events. Contact a relay administrator to upgrade your permissions.`);const t=`${window.location.protocol.startsWith("https")?"wss:":"ws:"}//${window.location.host}/`,r=await CI(t,e,g,d);if(r.success)n(35,re=""),alert("Event published successfully to ORLY relay!");else{const t=r.reason||"Unknown error";n(35,re=_e(t,e.kind))}}catch(e){console.error("Error publishing event:",e);const t=e.message||"Unknown error";n(35,re=_e(t,null))}},function(){n(35,re="")},He,function(){const e=["owner","admin","write","read"],t=e.indexOf(p);return-1===t?["read"]:e.slice(t)},I,R,K,Le,o,function(t){T.call(this,e,t)},function(t){T.call(this,e,t)},e=>e.id===w,e=>xe(e.detail),e=>Fe(e.detail),e=>ue(e.detail),e=>fe(e.detail),e=>de(e.detail.event,e.detail.e),e=>$e(e.detail.refresh,e.detail.authors),function(e){ne=e,n(34,ne)},function(e){O=e,n(20,O)},e=>Ae(e.detail),e=>be(e.detail),function(e){V=e,n(27,V)},function(){ie=x(this),n(36,ie)},function(){oe=b(this.value),n(37,oe)},e=>ge(e),e=>pe(e),(e,t)=>de(e,t),e=>Qe(e.id,!0),e=>Se(e.id),e=>fe(e.id),e=>ue(e.id),(e,t)=>"Enter"===t.key&&ue(e.id),(e,t)=>de(e,t),(e,t)=>Re(t,e.id),e=>He(e===p?"":e),e=>"Escape"===e.key&&Be(),function(e){c=e,n(12,c)}]}return new class extends oe{constructor(e){super(),ie(this,e,BE,EE,o,{},null,[-1,-1,-1,-1,-1,-1])}}({target:document.body,props:{name:"world"}})}();
//# sourceMappingURL=bundle.js.map