|
|
/*! noble-ciphers - MIT License (c) 2023 Paul Miller (paulmillr.com) */Object.keys(rr).join(", ");const ar=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 cr=16;function lr(e){return e<<1^283&-(e>>7)}function ur(e,t){let n=0;for(;t>0;t>>=1)n^=e&-(1&t),e=lr(e);return n}const dr=(()=>{let e=new Uint8Array(256);for(let t=0,n=1;t<256;t++,n^=lr(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})(),fr=dr.map((e,t)=>dr.indexOf(t)),hr=e=>e<<24|e>>>8,pr=e=>e<<8|e>>>24;function gr(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(pr),o=r.map(pr),i=o.map(pr),s=new Uint32Array(65536),a=new Uint32Array(65536),c=new Uint16Array(65536);for(let t=0;t<256;t++)for(let l=0;l<256;l++){const u=256*t+l;s[u]=n[t]^r[l],a[u]=o[t]^i[l],c[u]=e[t]<<8|e[l]}return{sbox:e,sbox2:c,T0:n,T1:r,T2:o,T3:i,T01:s,T23:a}}const yr=gr(dr,e=>ur(e,3)<<24|e<<16|e<<8|ur(e,2)),mr=gr(fr,e=>ur(e,11)<<24|ur(e,13)<<16|ur(e,9)<<8|ur(e,14)),vr=(()=>{const e=new Uint8Array(16);for(let t=0,n=1;t<16;t++,n=lr(n))e[t]=n;return e})();function wr(e){sr(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}=yr,r=ar(e),o=r.length,i=e=>Er(n,e,e,e,e),s=new Uint32Array(t+28);s.set(r);for(let e=o;e<s.length;e++){let t=s[e-1];e%o===0?t=i(hr(t))^vr[e/o-1]:o>6&&e%o===4&&(t=i(t)),s[e]=s[e-o]^t}return s}function br(e,t,n,r,o,i){return e[n<<8&65280|r>>>8&255]^t[o>>>8&65280|i>>>24&255]}function Er(e,t,n,r,o){return e[255&t|65280&n]|e[r>>>16&255|o>>>16&65280]<<16}function kr(e,t,n,r,o){const{sbox2:i,T01:s,T23:a}=yr;let c=0;t^=e[c++],n^=e[c++],r^=e[c++],o^=e[c++];const l=e.length/4-2;for(let i=0;i<l;i++){const i=e[c++]^br(s,a,t,n,r,o),l=e[c++]^br(s,a,n,r,o,t),u=e[c++]^br(s,a,r,o,t,n),d=e[c++]^br(s,a,o,t,n,r);t=i,n=l,r=u,o=d}return{s0:e[c++]^Er(i,t,n,r,o),s1:e[c++]^Er(i,n,r,o,t),s2:e[c++]^Er(i,r,o,t,n),s3:e[c++]^Er(i,o,t,n,r)}}function xr(e,t,n,r,o){const{sbox2:i,T01:s,T23:a}=mr;let c=0;t^=e[c++],n^=e[c++],r^=e[c++],o^=e[c++];const l=e.length/4-2;for(let i=0;i<l;i++){const i=e[c++]^br(s,a,t,o,r,n),l=e[c++]^br(s,a,n,t,o,r),u=e[c++]^br(s,a,r,n,t,o),d=e[c++]^br(s,a,o,r,n,t);t=i,n=l,r=u,o=d}return{s0:e[c++]^Er(i,t,o,r,n),s1:e[c++]^Er(i,n,t,o,r),s2:e[c++]^Er(i,r,n,t,o),s3:e[c++]^Er(i,o,r,n,t)}}function Sr(e,t){if(!t)return new Uint8Array(e);if(sr(t),t.length<e)throw new Error(`aes: wrong destination length, expected at least ${e}, got: ${t.length}`);return t}const Cr=(Ar={blockSize:16,nonceLength:16},$r=function(e,t,n={}){sr(e),sr(t,16);const r=!n.disablePadding;return{encrypt:(n,o)=>{const i=wr(e),{b:s,o:a,out:c}=function(e,t,n){let r=e.length;const o=r%cr;if(!t&&0!==o)throw new Error("aec/(cbc-ecb): unpadded plaintext with disabled padding");const i=ar(e);if(t){let e=cr-o;e||(e=cr),r+=e}const s=Sr(r,n);return{b:i,o:ar(s),out:s}}(n,r,o),l=ar(t);let u=l[0],d=l[1],f=l[2],h=l[3],p=0;for(;p+4<=s.length;)u^=s[p+0],d^=s[p+1],f^=s[p+2],h^=s[p+3],({s0:u,s1:d,s2:f,s3:h}=kr(i,u,d,f,h)),a[p++]=u,a[p++]=d,a[p++]=f,a[p++]=h;if(r){const e=function(e){const t=new Uint8Array(16),n=ar(t);t.set(e);const r=cr-e.length;for(let e=cr-r;e<cr;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}=kr(i,u,d,f,h)),a[p++]=u,a[p++]=d,a[p++]=f,a[p++]=h}return i.fill(0),c},decrypt:(n,o)=>{!function(e){if(sr(e),e.length%cr!==0)throw new Error("aes/(cbc-ecb).decrypt ciphertext should consist of blocks with size 16")}(n);const i=function(e){const t=wr(e),n=t.slice(),r=t.length,{sbox2:o}=yr,{T0:i,T1:s,T2:a,T3:c}=mr;for(let e=0;e<r;e+=4)for(let o=0;o<4;o++)n[e+o]=t[r-e-4+o];t.fill(0);for(let e=4;e<r-4;e++){const t=n[e],r=Er(o,t,t,t,t);n[e]=i[255&r]^s[r>>>8&255]^a[r>>>16&255]^c[r>>>24]}return n}(e),s=ar(t),a=Sr(n.length,o),c=ar(n),l=ar(a);let u=s[0],d=s[1],f=s[2],h=s[3];for(let e=0;e+4<=c.length;){const t=u,n=d,r=f,o=h;u=c[e+0],d=c[e+1],f=c[e+2],h=c[e+3];const{s0:s,s1:a,s2:p,s3:g}=xr(i,u,d,f,h);l[e++]=s^t,l[e++]=a^n,l[e++]=p^r,l[e++]=g^o}return i.fill(0),function(e,t){if(!t)return e;const n=e.length;if(!n)throw new Error("aes/pcks5: empty ciphertext not allowed");const r=e[n-1];if(r<=0||r>16)throw new Error(`aes/pcks5: wrong padding byte: ${r}`);const o=e.subarray(0,-r);for(let t=0;t<r;t++)if(e[n-t-1]!==r)throw new Error("aes/pcks5: wrong padding");return o}(a,r)}}},Object.assign($r,Ar),$r);var Ar,$r;const Tr=e=>Uint8Array.from(e.split("").map(e=>e.charCodeAt(0))),Ir=Tr("expand 16-byte k"),_r=Tr("expand 32-byte k"),Rr=ar(Ir),jr=ar(_r);function Or(e,t){return e<<t|e>>>32-t}function Lr(e){return e.byteOffset%4==0}jr.slice();const Pr=2**32-1,Br=new Uint32Array;function Nr(e,t){const{allowShortKeys:n,extendNonceFn:r,counterLength:o,counterRight:i,rounds:s}=function(e,t){if(null==t||"object"!=typeof t)throw new Error("options must be defined");return Object.assign(e,t)}({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},t);if("function"!=typeof e)throw new Error("core must be a function");return or(o),or(s),ir(i),ir(n),(t,a,c,l,u=0)=>{sr(t),sr(a),sr(c);const d=c.length;if(l||(l=new Uint8Array(d)),sr(l),or(u),u<0||u>=Pr)throw new Error("arx: counter overflow");if(l.length<d)throw new Error(`arx: output (${l.length}) is shorter than data (${d})`);const f=[];let h,p,g=t.length;if(32===g)h=t.slice(),f.push(h),p=jr;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=Rr,f.push(h)}Lr(a)||(a=a.slice(),f.push(a));const y=ar(h);if(r){if(24!==a.length)throw new Error("arx: extended nonce must be 24 bytes");r(p,y,ar(a.subarray(0,16)),y),a=a.subarray(16)}const m=16-o;if(m!==a.length)throw new Error(`arx: nonce must be ${m} or 16 bytes`);if(12!==m){const e=new Uint8Array(12);e.set(a,i?0:12-a.length),a=e,f.push(a)}const v=ar(a);for(!function(e,t,n,r,o,i,s,a){const c=o.length,l=new Uint8Array(64),u=ar(l),d=Lr(o)&&Lr(i),f=d?ar(o):Br,h=d?ar(i):Br;for(let p=0;p<c;s++){if(e(t,n,r,u,s,a),s>=Pr)throw new Error("arx: counter overflow");const g=Math.min(64,c-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,i[e]=o[e]^l[t];p+=g}}(e,p,y,v,c,l,u,s);f.length>0;)f.pop().fill(0);return l}}function Ur(e,t,n,r,o,i=20){let s=e[0],a=e[1],c=e[2],l=e[3],u=t[0],d=t[1],f=t[2],h=t[3],p=t[4],g=t[5],y=t[6],m=t[7],v=o,w=n[0],b=n[1],E=n[2],k=s,x=a,S=c,C=l,A=u,$=d,T=f,I=h,_=p,R=g,j=y,O=m,L=v,P=w,B=b,N=E;for(let e=0;e<i;e+=2)k=k+A|0,L=Or(L^k,16),_=_+L|0,A=Or(A^_,12),k=k+A|0,L=Or(L^k,8),_=_+L|0,A=Or(A^_,7),x=x+$|0,P=Or(P^x,16),R=R+P|0,$=Or($^R,12),x=x+$|0,P=Or(P^x,8),R=R+P|0,$=Or($^R,7),S=S+T|0,B=Or(B^S,16),j=j+B|0,T=Or(T^j,12),S=S+T|0,B=Or(B^S,8),j=j+B|0,T=Or(T^j,7),C=C+I|0,N=Or(N^C,16),O=O+N|0,I=Or(I^O,12),C=C+I|0,N=Or(N^C,8),O=O+N|0,I=Or(I^O,7),k=k+$|0,N=Or(N^k,16),j=j+N|0,$=Or($^j,12),k=k+$|0,N=Or(N^k,8),j=j+N|0,$=Or($^j,7),x=x+T|0,L=Or(L^x,16),O=O+L|0,T=Or(T^O,12),x=x+T|0,L=Or(L^x,8),O=O+L|0,T=Or(T^O,7),S=S+I|0,P=Or(P^S,16),_=_+P|0,I=Or(I^_,12),S=S+I|0,P=Or(P^S,8),_=_+P|0,I=Or(I^_,7),C=C+A|0,B=Or(B^C,16),R=R+B|0,A=Or(A^R,12),C=C+A|0,B=Or(B^C,8),R=R+B|0,A=Or(A^R,7);let U=0;r[U++]=s+k|0,r[U++]=a+x|0,r[U++]=c+S|0,r[U++]=l+C|0,r[U++]=u+A|0,r[U++]=d+$|0,r[U++]=f+T|0,r[U++]=h+I|0,r[U++]=p+_|0,r[U++]=g+R|0,r[U++]=y+j|0,r[U++]=m+O|0,r[U++]=v+L|0,r[U++]=w+P|0,r[U++]=b+B|0,r[U++]=E+N|0}const Mr=Nr(Ur,{counterRight:!1,counterLength:4,allowShortKeys:!1});class Fr extends Qt{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,nn.hash(e);const n=Gt(t);if(this.iHash=e.create(),"function"!=typeof this.iHash.update)throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;const r=this.blockLen,o=new Uint8Array(r);o.set(n.length>r?e.create().update(n).digest():n);for(let e=0;e<o.length;e++)o[e]^=54;this.iHash.update(o),this.oHash=e.create();for(let e=0;e<o.length;e++)o[e]^=106;this.oHash.update(o),o.fill(0)}update(e){return nn.exists(this),this.iHash.update(e),this}digestInto(e){nn.exists(this),nn.bytes(e,this.outputLen),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){const e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||(e=Object.create(Object.getPrototypeOf(this),{}));const{oHash:t,iHash:n,finished:r,destroyed:o,blockLen:i,outputLen:s}=this;return e.finished=r,e.destroyed=o,e.blockLen=i,e.outputLen=s,e.oHash=t._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}const Dr=(e,t,n)=>new Fr(e,t).update(n).digest();Dr.create=(e,t)=>new Fr(e,t);const Hr=new Uint8Array([0]),qr=new Uint8Array;var zr=Object.defineProperty,Kr=(e,t)=>{for(var n in t)zr(e,n,{get:t[n],enumerable:!0})},Wr=Symbol("verified");function Vr(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}Kr({},{Queue:()=>to,QueueNode:()=>eo,binarySearch:()=>Xr,bytesToHex:()=>Vt,hexToBytes:()=>Jt,insertEventIntoAscendingList:()=>Yr,insertEventIntoDescendingList:()=>Qr,normalizeURL:()=>Zr,utf8Decoder:()=>Jr,utf8Encoder:()=>Gr});var Jr=new TextDecoder("utf-8"),Gr=new TextEncoder;function Zr(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 Qr(e,t){const[n,r]=Xr(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 Yr(e,t){const[n,r]=Xr(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 Xr(e,t){let n=0,r=e.length-1;for(;n<=r;){const o=Math.floor((n+r)/2),i=t(e[o]);if(0===i)return[o,!0];i<0?r=o-1:n=o+1}return[n,!1]}var eo=class{value;next=null;prev=null;constructor(e){this.value=e}},to=class{first;last;constructor(){this.first=null,this.last=null}enqueue(e){const t=new eo(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 no(e){return Vt(fn(Gr.encode(function(e){if(!Vr(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 ro=new class{generateSecretKey(){return Dt.utils.randomPrivateKey()}getPublicKey(e){return Vt(Dt.getPublicKey(e))}finalizeEvent(e,t){const n=e;return n.pubkey=Vt(Dt.getPublicKey(t)),n.id=no(n),n.sig=Vt(Dt.sign(no(n),t)),n[Wr]=!0,n}verifyEvent(e){if("boolean"==typeof e[Wr])return e[Wr];const t=no(e);if(t!==e.id)return e[Wr]=!1,!1;try{const n=Dt.verify(e.sig,t,e.pubkey);return e[Wr]=n,n}catch(t){return e[Wr]=!1,!1}}},oo=ro.generateSecretKey,io=ro.getPublicKey,so=ro.finalizeEvent,ao=ro.verifyEvent,co={};function lo(e){return 1e3<=e&&e<1e4||[1,2,4,5,6,7,8,16,40,41,42,43,44].includes(e)}function uo(e){return[0,3].includes(e)||1e4<=e&&e<2e4}function fo(e){return 2e4<=e&&e<3e4}function ho(e){return 3e4<=e&&e<4e4}function po(e){return lo(e)?"regular":uo(e)?"replaceable":fo(e)?"ephemeral":ho(e)?"parameterized":"unknown"}function go(e,t){const n=t instanceof Array?t:[t];return Vr(e)&&n.includes(e.kind)||!1}Kr(co,{Application:()=>$i,BadgeAward:()=>So,BadgeDefinition:()=>bi,BlockedRelaysList:()=>ti,BookmarkList:()=>Yo,Bookmarksets:()=>mi,Calendar:()=>Li,CalendarEventRSVP:()=>Pi,ChannelCreation:()=>To,ChannelHideMessage:()=>Ro,ChannelMessage:()=>_o,ChannelMetadata:()=>Io,ChannelMuteUser:()=>jo,ClassifiedListing:()=>_i,ClientAuth:()=>li,CommunitiesList:()=>Xo,CommunityDefinition:()=>Ui,CommunityPostApproval:()=>Do,Contacts:()=>wo,CreateOrUpdateProduct:()=>xi,CreateOrUpdateStall:()=>ki,Curationsets:()=>vi,Date:()=>ji,DirectMessageRelaysList:()=>ii,DraftClassifiedListing:()=>Ri,DraftLong:()=>Ci,Emojisets:()=>Ai,EncryptedDirectMessage:()=>bo,EventDeletion:()=>Eo,FileMetadata:()=>Po,FileServerPreference:()=>si,Followsets:()=>pi,GenericRepost:()=>$o,Genericlists:()=>gi,GiftWrap:()=>Lo,HTTPAuth:()=>hi,Handlerinformation:()=>Ni,Handlerrecommendation:()=>Bi,Highlights:()=>Jo,InterestsList:()=>ri,Interestsets:()=>Ei,JobFeedback:()=>zo,JobRequest:()=>Ho,JobResult:()=>qo,Label:()=>Fo,LightningPubRPC:()=>ci,LiveChatMessage:()=>Bo,LiveEvent:()=>Ti,LongFormArticle:()=>Si,Metadata:()=>yo,Mutelist:()=>Go,NWCWalletInfo:()=>ai,NWCWalletRequest:()=>ui,NWCWalletResponse:()=>di,NostrConnect:()=>fi,OpenTimestamps:()=>Oo,Pinlist:()=>Zo,PrivateDirectMessage:()=>Ao,ProblemTracker:()=>No,ProfileBadges:()=>wi,PublicChatsList:()=>ei,Reaction:()=>xo,RecommendRelay:()=>vo,RelayList:()=>Qo,Relaysets:()=>yi,Report:()=>Uo,Reporting:()=>Mo,Repost:()=>ko,Seal:()=>Co,SearchRelaysList:()=>ni,ShortTextNote:()=>mo,Time:()=>Oi,UserEmojiList:()=>oi,UserStatuses:()=>Ii,Zap:()=>Vo,ZapGoal:()=>Ko,ZapRequest:()=>Wo,classifyKind:()=>po,isAddressableKind:()=>ho,isEphemeralKind:()=>fo,isKind:()=>go,isRegularKind:()=>lo,isReplaceableKind:()=>uo});var yo=0,mo=1,vo=2,wo=3,bo=4,Eo=5,ko=6,xo=7,So=8,Co=13,Ao=14,$o=16,To=40,Io=41,_o=42,Ro=43,jo=44,Oo=1040,Lo=1059,Po=1063,Bo=1311,No=1971,Uo=1984,Mo=1984,Fo=1985,Do=4550,Ho=5999,qo=6999,zo=7e3,Ko=9041,Wo=9734,Vo=9735,Jo=9802,Go=1e4,Zo=10001,Qo=10002,Yo=10003,Xo=10004,ei=10005,ti=10006,ni=10007,ri=10015,oi=10030,ii=10050,si=10096,ai=13194,ci=21e3,li=22242,ui=23194,di=23195,fi=24133,hi=27235,pi=3e4,gi=30001,yi=30002,mi=30003,vi=30004,wi=30008,bi=30009,Ei=30015,ki=30017,xi=30018,Si=30023,Ci=30024,Ai=30030,$i=30078,Ti=30311,Ii=30315,_i=30402,Ri=30403,ji=31922,Oi=31923,Li=31924,Pi=31925,Bi=31989,Ni=31990,Ui=34550;function Mi(e,t){let n=t.length+3,r=e.indexOf(`"${t}":`)+n,o=e.slice(r).indexOf('"')+r+1;return e.slice(o,o+64)}function Fi(e,t){let n=t.length,r=e.indexOf(`"${t}":`)+n+3,o=e.slice(r),i=Math.min(o.indexOf(","),o.indexOf("}"));return parseInt(o.slice(0,i),10)}function Di(e){let t=e.slice(0,22).indexOf('"EVENT"');if(-1===t)return null;let n=e.slice(t+7+1).indexOf('"');if(-1===n)return null;let r=t+7+1+n,o=e.slice(r+1,80).indexOf('"');if(-1===o)return null;let i=r+1+o;return e.slice(r+1,i)}function Hi(e,t){return t===Mi(e,"id")}function qi(e,t){return t===Mi(e,"pubkey")}function zi(e,t){return t===Fi(e,"kind")}Kr({},{getHex64:()=>Mi,getInt:()=>Fi,getSubscriptionId:()=>Di,matchEventId:()=>Hi,matchEventKind:()=>zi,matchEventPubkey:()=>qi});function Ki(e,t){return{kind:li,created_at:Math.floor(Date.now()/1e3),tags:[["relay",e],["challenge",t]],content:""}}Kr({},{makeAuthEvent:()=>Ki});try{WebSocket}catch{}try{WebSocket}catch{}var Wi={};Kr(Wi,{BECH32_REGEX:()=>Gi,Bech32MaxSize:()=>Ji,NostrTypeGuard:()=>Vi,decode:()=>Qi,decodeNostrURI:()=>Zi,encodeBytes:()=>rs,naddrEncode:()=>ss,neventEncode:()=>is,noteEncode:()=>ts,nprofileEncode:()=>os,npubEncode:()=>es,nsecEncode:()=>Xi});var Vi={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||"")},Ji=5e3,Gi=/[\x21-\x7E]{1,83}1[023456789acdefghjklmnpqrstuvwxyz]{6,}/;function Zi(e){try{return e.startsWith("nostr:")&&(e=e.substring(6)),Qi(e)}catch(e){return{type:"invalid",data:null}}}function Qi(e){let{prefix:t,words:n}=nr.decode(e,Ji),r=new Uint8Array(nr.fromWords(n));switch(t){case"nprofile":{let e=Yi(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:Vt(e[0][0]),relays:e[1]?e[1].map(e=>Jr.decode(e)):[]}}}case"nevent":{let e=Yi(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:Vt(e[0][0]),relays:e[1]?e[1].map(e=>Jr.decode(e)):[],author:e[2]?.[0]?Vt(e[2][0]):void 0,kind:e[3]?.[0]?parseInt(Vt(e[3][0]),16):void 0}}}case"naddr":{let e=Yi(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:Jr.decode(e[0][0]),pubkey:Vt(e[2][0]),kind:parseInt(Vt(e[3][0]),16),relays:e[1]?e[1].map(e=>Jr.decode(e)):[]}}}case"nsec":return{type:t,data:r};case"npub":case"note":return{type:t,data:Vt(r)};default:throw new Error(`unknown prefix ${t}`)}}function Yi(e){let t={},n=e;for(;n.length>0;){let e=n[0],r=n[1],o=n.slice(2,2+r);if(n=n.slice(2+r),o.length<r)throw new Error(`not enough data to read on TLV ${e}`);t[e]=t[e]||[],t[e].push(o)}return t}function Xi(e){return rs("nsec",e)}function es(e){return rs("npub",Jt(e))}function ts(e){return rs("note",Jt(e))}function ns(e,t){let n=nr.toWords(t);return nr.encode(e,n,Ji)}function rs(e,t){return ns(e,t)}function os(e){return ns("nprofile",as({0:[Jt(e.pubkey)],1:(e.relays||[]).map(e=>Gr.encode(e))}))}function is(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)),ns("nevent",as({0:[Jt(e.id)],1:(e.relays||[]).map(e=>Gr.encode(e)),2:e.author?[Jt(e.author)]:[],3:t?[new Uint8Array(t)]:[]}))}function ss(e){let t=new ArrayBuffer(4);return new DataView(t).setUint32(0,e.kind,!1),ns("naddr",as({0:[Gr.encode(e.identifier)],1:(e.relays||[]).map(e=>Gr.encode(e)),2:[Jt(e.pubkey)],3:[new Uint8Array(t)]}))}function as(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)})}),Zt(...t)}var cs={};function ls(e,t,n){const r=e instanceof Uint8Array?Vt(e):e,o=ds(Ct.getSharedSecret(r,"02"+t));let i=Uint8Array.from(Xt(16)),s=Gr.encode(n),a=Cr(o,i).encrypt(s);return`${Kn.encode(new Uint8Array(a))}?iv=${Kn.encode(new Uint8Array(i.buffer))}`}function us(e,t,n){const r=e instanceof Uint8Array?Vt(e):e;let[o,i]=n.split("?iv="),s=ds(Ct.getSharedSecret(r,"02"+t)),a=Kn.decode(i),c=Kn.decode(o),l=Cr(s,a).decrypt(c);return Jr.decode(l)}function ds(e){return e.slice(1,33)}Kr(cs,{decrypt:()=>us,encrypt:()=>ls});Kr({},{NIP05_REGEX:()=>hs,isNip05:()=>ps,isValid:()=>vs,queryProfile:()=>ms,searchDomain:()=>ys,useFetchImplementation:()=>gs});var fs,hs=/^(?:([\w.+-]+)@)?([\w_-]+(\.[\w_-]+)+)$/,ps=e=>hs.test(e||"");try{fs=fetch}catch(e){}function gs(e){fs=e}async function ys(e,t=""){try{const n=`https://${e}/.well-known/nostr.json?name=${t}`,r=await fs(n,{redirect:"manual"});if(200!==r.status)throw Error("Wrong response code");return(await r.json()).names}catch(e){return{}}}async function ms(e){const t=e.match(hs);if(!t)return null;const[,n="_",r]=t;try{const e=`https://${r}/.well-known/nostr.json?name=${n}`,t=await fs(e,{redirect:"manual"});if(200!==t.status)throw Error("Wrong response code");const o=await t.json(),i=o.names[n];return i?{pubkey:i,relays:o.relays?.[i]}:null}catch(e){return null}}async function vs(e,t){const n=await ms(t);return!!n&&n.pubkey===e}function ws(e){const t={reply:void 0,root:void 0,mentions:[],profiles:[],quotes:[]};let n,r;for(let o=e.tags.length-1;o>=0;o--){const i=e.tags[o];if("e"===i[0]&&i[1]){const[e,o,s,a,c]=i,l={id:o,relays:s?[s]:[],author:c};if("root"===a){t.root=l;continue}if("reply"===a){t.reply=l;continue}if("mention"===a){t.mentions.push(l);continue}n?r=l:n=l,t.mentions.push(l);continue}if("q"===i[0]&&i[1]){const[e,n,r]=i;t.quotes.push({id:n,relays:r?[r]:[]})}"p"===i[0]&&i[1]&&t.profiles.push({pubkey:i[1],relays:i[2]?[i[2]]:[]})}return t.root||(t.root=r||n||t.reply),t.reply||(t.reply=n||t.root),[t.reply,t.root].forEach(e=>{if(!e)return;let n=t.mentions.indexOf(e);if(-1!==n&&t.mentions.splice(n,1),e.author){let n=t.profiles.find(t=>t.pubkey===e.author);n&&n.relays&&(e.relays||(e.relays=[]),n.relays.forEach(t=>{-1===e.relays?.indexOf(t)&&e.relays.push(t)}),n.relays=e.relays)}}),t.mentions.forEach(e=>{if(e.author){let n=t.profiles.find(t=>t.pubkey===e.author);n&&n.relays&&(e.relays||(e.relays=[]),n.relays.forEach(t=>{-1===e.relays.indexOf(t)&&e.relays.push(t)}),n.relays=e.relays)}}),t}Kr({},{parse:()=>ws});Kr({},{fetchRelayInformation:()=>Es,useFetchImplementation:()=>bs});try{fetch}catch{}function bs(e){0}async function Es(e){return await(await fetch(e.replace("ws://","http://").replace("wss://","https://"),{headers:{Accept:"application/nostr+json"}})).json()}function ks(e){let t=0;for(let n=0;n<64;n+=8){const r=parseInt(e.substring(n,n+8),16);if(0!==r){t+=Math.clz32(r);break}t+=32}return t}function xs(e,t){let n=0;const r=e,o=["nonce",n.toString(),t.toString()];for(r.tags.push(o);;){const e=Math.floor((new Date).getTime()/1e3);if(e!==r.created_at&&(n=0,r.created_at=e),o[1]=(++n).toString(),r.id=Ss(r),ks(r.id)>=t)break}return r}function Ss(e){return Vt(fn(Gr.encode(JSON.stringify([0,e.pubkey,e.created_at,e.kind,e.tags,e.content]))))}Kr({},{fastEventHash:()=>Ss,getPow:()=>ks,minePow:()=>xs});Kr({},{unwrapEvent:()=>Zs,unwrapManyEvents:()=>Qs,wrapEvent:()=>Js,wrapManyEvents:()=>Gs});Kr({},{createRumor:()=>Ds,createSeal:()=>Hs,createWrap:()=>qs,unwrapEvent:()=>Ws,unwrapManyEvents:()=>Vs,wrapEvent:()=>zs,wrapManyEvents:()=>Ks});var Cs={};Kr(Cs,{decrypt:()=>Ls,encrypt:()=>Os,getConversationKey:()=>Ts,v2:()=>Ps});var As=1,$s=65535;function Ts(e,t){const n=Ct.getSharedSecret(e,"02"+t).subarray(1,33);return function(e,t,n){return nn.hash(e),void 0===n&&(n=new Uint8Array(e.outputLen)),Dr(e,Gt(n),Gt(t))}(fn,n,"nip44-v2")}function Is(e,t){const n=function(e,t,n,r=32){if(nn.hash(e),nn.number(r),r>255*e.outputLen)throw new Error("Length should be <= 255*HashLen");const o=Math.ceil(r/e.outputLen);void 0===n&&(n=qr);const i=new Uint8Array(o*e.outputLen),s=Dr.create(e,t),a=s._cloneInto(),c=new Uint8Array(s.outputLen);for(let t=0;t<o;t++)Hr[0]=t+1,a.update(0===t?qr:c).update(n).update(Hr).digestInto(c),i.set(c,e.outputLen*t),s._cloneInto(a);return s.destroy(),a.destroy(),c.fill(0),Hr.fill(0),i.slice(0,r)}(fn,e,t,76);return{chacha_key:n.subarray(0,32),chacha_nonce:n.subarray(32,44),hmac_key:n.subarray(44,76)}}function _s(e){if(!Number.isSafeInteger(e)||e<1)throw new Error("expected positive integer");if(e<=32)return 32;const t=1<<Math.floor(Math.log2(e-1))+1,n=t<=256?32:t/8;return n*(Math.floor((e-1)/n)+1)}function Rs(e){const t=Gr.encode(e),n=t.length;return Zt(function(e){if(!Number.isSafeInteger(e)||e<As||e>$s)throw new Error("invalid plaintext size: must be between 1 and 65535 bytes");const t=new Uint8Array(2);return new DataView(t.buffer).setUint16(0,e,!1),t}(n),t,new Uint8Array(_s(n)-n))}function js(e,t,n){if(32!==n.length)throw new Error("AAD associated data must be 32 bytes");const r=Zt(n,t);return Dr(fn,e,r)}function Os(e,t,n=Xt(32)){const{chacha_key:r,chacha_nonce:o,hmac_key:i}=Is(t,n),s=Rs(e),a=Mr(r,o,s),c=js(i,a,n);return Kn.encode(Zt(new Uint8Array([2]),n,a,c))}function Ls(e,t){const{nonce:n,ciphertext:r,mac:o}=function(e){if("string"!=typeof e)throw new Error("payload must be a valid string");const t=e.length;if(t<132||t>87472)throw new Error("invalid payload length: "+t);if("#"===e[0])throw new Error("unknown encryption version");let n;try{n=Kn.decode(e)}catch(e){throw new Error("invalid base64: "+e.message)}const r=n.length;if(r<99||r>65603)throw new Error("invalid data length: "+r);const o=n[0];if(2!==o)throw new Error("unknown encryption version "+o);return{nonce:n.subarray(1,33),ciphertext:n.subarray(33,-32),mac:n.subarray(-32)}}(e),{chacha_key:i,chacha_nonce:s,hmac_key:a}=Is(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}(js(a,r,n),o))throw new Error("invalid MAC");return function(e){const t=new DataView(e.buffer).getUint16(0),n=e.subarray(2,2+t);if(t<As||t>$s||n.length!==t||e.length!==2+_s(t))throw new Error("invalid padding");return Jr.decode(n)}(Mr(i,s,r))}var Ps={utils:{getConversationKey:Ts,calcPaddedLen:_s},encrypt:Os,decrypt:Ls},Bs=()=>Math.round(Date.now()/1e3),Ns=()=>Math.round(Bs()-172800*Math.random()),Us=(e,t)=>Ts(e,t),Ms=(e,t,n)=>Os(JSON.stringify(e),Us(t,n)),Fs=(e,t)=>JSON.parse(Ls(e.content,Us(t,e.pubkey)));function Ds(e,t){const n={created_at:Bs(),content:"",tags:[],...e,pubkey:io(t)};return n.id=no(n),n}function Hs(e,t,n){return so({kind:Co,content:Ms(e,t,n),created_at:Ns(),tags:[]},t)}function qs(e,t){const n=oo();return so({kind:Lo,content:Ms(e,n,t),created_at:Ns(),tags:[["p",t]]},n)}function zs(e,t,n){return qs(Hs(Ds(e,t),t,n),n)}function Ks(e,t,n){if(!n||0===n.length)throw new Error("At least one recipient is required.");const r=io(t),o=[zs(e,t,r)];return n.forEach(n=>{o.push(zs(e,t,n))}),o}function Ws(e,t){const n=Fs(e,t);return Fs(n,t)}function Vs(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 Js(e,t,n,r,o){const i=function(e,t,n,r){const o={created_at:Math.ceil(Date.now()/1e3),kind:Ao,tags:[],content:t};return(Array.isArray(e)?e:[e]).forEach(({publicKey:e,relayUrl:t})=>{o.tags.push(t?["p",e,t]:["p",e])}),r&&o.tags.push(["e",r.eventId,r.relayUrl||"","reply"]),n&&o.tags.push(["subject",n]),o}(t,n,r,o);return zs(i,e,t.publicKey)}function Gs(e,t,n,r,o){if(!t||0===t.length)throw new Error("At least one recipient is required.");return[{publicKey:io(e)},...t].map(t=>Js(e,t,n,r,o))}var Zs=Ws,Qs=Vs;function Ys(e,t,n,r){let o;const i=[...e.tags??[],["e",t.id,n],["p",t.pubkey]];return t.kind===mo?o=ko:(o=$o,i.push(["k",String(t.kind)])),so({kind:o,tags:i,content:""===e.content||t.tags?.find(e=>"-"===e[0])?"":JSON.stringify(t),created_at:e.created_at},r)}function Xs(e){if(![ko,$o].includes(e.kind))return;let t,n;for(let r=e.tags.length-1;r>=0&&(void 0===t||void 0===n);r--){const o=e.tags[r];o.length>=2&&("e"===o[0]&&void 0===t?t=o:"p"===o[0]&&void 0===n&&(n=o))}return void 0!==t?{id:t[1],relays:[t[2],n?.[2]].filter(e=>"string"==typeof e),author:n?.[1]}:void 0}function ea(e,{skipVerification:t}={}){const n=Xs(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||ao(r))?r:void 0}Kr({},{finishRepostEvent:()=>Ys,getRepostedEvent:()=>ea,getRepostedEventPointer:()=>Xs});Kr({},{NOSTR_URI_REGEX:()=>ta,parse:()=>ra,test:()=>na});var ta=new RegExp(`nostr:(${Gi.source})`);function na(e){return"string"==typeof e&&new RegExp(`^${ta.source}$`).test(e)}function ra(e){const t=e.match(new RegExp(`^${ta.source}$`));if(!t)throw new Error(`Invalid Nostr URI: ${e}`);return{uri:t[0],value:t[1],decoded:Qi(t[1])}}function oa(e,t,n){const r=t.tags.filter(e=>e.length>=2&&("e"===e[0]||"p"===e[0]));return so({...e,kind:xo,tags:[...e.tags??[],...r,["e",t.id],["p",t.pubkey]],content:e.content??"+"},n)}function ia(e){if(e.kind!==xo)return;let t,n;for(let r=e.tags.length-1;r>=0&&(void 0===t||void 0===n);r--){const o=e.tags[r];o.length>=2&&("e"===o[0]&&void 0===t?t=o:"p"===o[0]&&void 0===n&&(n=o))}return void 0!==t&&void 0!==n?{id:t[1],relays:[t[2],n[2]].filter(e=>void 0!==e),author:n[1]}:void 0}Kr({},{finishReactionEvent:()=>oa,getReactedEventPointer:()=>ia});Kr({},{parse:()=>ca});var sa=/\W/m,aa=/\W |\W$|$|,| /m;function*ca(e){const t=e.length;let n=0,r=0;for(;r<t;){let o=e.indexOf(":",r);if(-1===o)break;if("nostr"===e.substring(o-5,o)){const i=e.substring(o+60).match(sa),s=i?o+60+i.index:t;try{let t,{data:i,type:a}=Qi(e.substring(o+1,s));switch(a){case"npub":t={pubkey:i};break;case"nsec":case"note":r=s+1;continue;default:t=i}n!==o-5&&(yield{type:"text",text:e.substring(n,o-5)}),yield{type:"reference",pointer:t},r=s,n=r;continue}catch(e){r=o+1;continue}}else if("https"===e.substring(o-5,o)||"http"===e.substring(o-4,o)){const i=e.substring(o+4).match(aa),s=i?o+4+i.index:t,a="s"===e[o-1]?5:4;try{let t=new URL(e.substring(o-a,s));if(-1===t.hostname.indexOf("."))throw new Error("invalid url");if(n!==o-a&&(yield{type:"text",text:e.substring(n,o-a)}),/\.(png|jpe?g|gif|webp)$/i.test(t.pathname)){yield{type:"image",url:t.toString()},r=s,n=r;continue}if(/\.(mp4|avi|webm|mkv)$/i.test(t.pathname)){yield{type:"video",url:t.toString()},r=s,n=r;continue}if(/\.(mp3|aac|ogg|opus)$/i.test(t.pathname)){yield{type:"audio",url:t.toString()},r=s,n=r;continue}yield{type:"url",url:t.toString()},r=s,n=r;continue}catch(e){r=s+1;continue}}else{if("wss"!==e.substring(o-3,o)&&"ws"!==e.substring(o-2,o)){r=o+1;continue}{const i=e.substring(o+4).match(aa),s=i?o+4+i.index:t,a="s"===e[o-1]?3:2;try{let t=new URL(e.substring(o-a,s));if(-1===t.hostname.indexOf("."))throw new Error("invalid ws url");n!==o-a&&(yield{type:"text",text:e.substring(n,o-a)}),yield{type:"relay",url:t.toString()},r=s,n=r;continue}catch(e){r=s+1;continue}}}}n!==t&&(yield{type:"text",text:e.substring(n)})}Kr({},{channelCreateEvent:()=>la,channelHideMessageEvent:()=>fa,channelMessageEvent:()=>da,channelMetadataEvent:()=>ua,channelMuteUserEvent:()=>ha});var la=(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 so({kind:To,tags:[...e.tags??[]],content:n,created_at:e.created_at},t)},ua=(e,t)=>{let n;if("object"==typeof e.content)n=JSON.stringify(e.content);else{if("string"!=typeof e.content)return;n=e.content}return so({kind:Io,tags:[["e",e.channel_create_event_id],...e.tags??[]],content:n,created_at:e.created_at},t)},da=(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"]),so({kind:_o,tags:[...n,...e.tags??[]],content:e.content,created_at:e.created_at},t)},fa=(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 so({kind:Ro,tags:[["e",e.channel_message_event_id],...e.tags??[]],content:n,created_at:e.created_at},t)},ha=(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 so({kind:jo,tags:[["p",e.pubkey_to_mute],...e.tags??[]],content:n,created_at:e.created_at},t)};Kr({},{EMOJI_SHORTCODE_REGEX:()=>pa,matchAll:()=>ya,regex:()=>ga,replaceAll:()=>ma});var pa=/:(\w+):/,ga=()=>new RegExp(`\\B${pa.source}\\B`,"g");function*ya(e){const t=e.matchAll(ga());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 ma(e,t){return e.replaceAll(ga(),(e,n)=>t({shortcode:e,name:n}))}var va;Kr({},{useFetchImplementation:()=>wa,validateGithub:()=>ba});try{va=fetch}catch{}function wa(e){va=e}async function ba(e,t,n){try{return await(await va(`https://gist.github.com/${t}/${n}/raw`)).text()===`Verifying that I control the following Nostr public key: ${e}`}catch(e){return!1}}function Ea(e){const{host:t,pathname:n,searchParams:r}=new URL(e),o=n||t,i=r.get("relay"),s=r.get("secret");if(!o||!i||!s)throw new Error("invalid connection string");return{pubkey:o,relay:i,secret:s}}async function ka(e,t,n){const r={method:"pay_invoice",params:{invoice:n}},o=ls(t,e,JSON.stringify(r)),i={kind:ui,created_at:Math.round(Date.now()/1e3),content:o,tags:[["p",e]]};return so(i,t)}Kr({},{makeNwcRequestEvent:()=>ka,parseConnectionString:()=>Ea});function xa(e){return e=(e=e.trim().toLowerCase()).normalize("NFKC"),Array.from(e).map(e=>/\p{Letter}/u.test(e)||/\p{Number}/u.test(e)?e:"-").join("")}Kr({},{normalizeIdentifier:()=>xa});var Sa;Kr({},{getSatoshisAmountFromBolt11:()=>_a,getZapEndpoint:()=>Aa,makeZapReceipt:()=>Ia,makeZapRequest:()=>$a,useFetchImplementation:()=>Ca,validateZapRequest:()=>Ta});try{Sa=fetch}catch{}function Ca(e){Sa=e}async function Aa(e){try{let t="",{lud06:n,lud16:r}=JSON.parse(e.content);if(n){let{words:e}=nr.decode(n,1e3),r=nr.fromWords(e);t=Jr.decode(r)}else{if(!r)return null;{let[e,n]=r.split("@");t=new URL(`/.well-known/lnurlp/${e}`,`https://${n}`).toString()}}let o=await Sa(t),i=await o.json();if(i.allowsNostr&&i.nostrPubkey)return i.callback}catch(e){}return null}function $a(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]),uo(e.event.kind)){const n=["a",`${e.event.kind}:${e.event.pubkey}:`];t.tags.push(n)}else if(ho(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 Ta(e){let t;try{t=JSON.parse(e)}catch(e){return"Invalid zap request JSON."}if(!Vr(t))return"Zap request is not a valid Nostr event.";if(!ao(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 Ia({zapRequest:e,preimage:t,bolt11:n,paidAt:r}){let o=JSON.parse(e),i=o.tags.filter(([e])=>"e"===e||"p"===e||"a"===e),s={kind:9735,created_at:Math.round(r.getTime()/1e3),content:"",tags:[...i,["P",o.pubkey],["bolt11",n],["description",e]]};return t&&s.tags.push(["preimage",t]),s}function _a(e){if(e.length<50)return 0;const t=(e=e.substring(0,50)).lastIndexOf("1");if(-1===t)return 0;const n=e.substring(0,t);if(!n.startsWith("lnbc"))return 0;const r=n.substring(4);if(r.length<1)return 0;const o=r[r.length-1],i=o.charCodeAt(0)-"0".charCodeAt(0),s=i>=0&&i<=9;let a=r.length-1;if(s&&a++,a<1)return 0;const c=parseInt(r.substring(0,a));switch(o){case"m":return 1e5*c;case"u":return 100*c;case"n":return c/10;case"p":return c/1e4;default:return 1e8*c}}Kr({},{getToken:()=>ja,hashPayload:()=>Ma,unpackEventFromToken:()=>La,validateEvent:()=>Da,validateEventKind:()=>Ba,validateEventMethodTag:()=>Ua,validateEventPayloadTag:()=>Fa,validateEventTimestamp:()=>Pa,validateEventUrlTag:()=>Na,validateToken:()=>Oa});var Ra="Nostr ";async function ja(e,t,n,r=!1,o){const i={kind:hi,tags:[["u",e],["method",t]],created_at:Math.round((new Date).getTime()/1e3),content:""};o&&i.tags.push(["payload",Ma(o)]);const s=await n(i);return(r?Ra:"")+Kn.encode(Gr.encode(JSON.stringify(s)))}async function Oa(e,t,n){const r=await La(e).catch(e=>{throw e});return await Da(r,t,n).catch(e=>{throw e})}async function La(e){if(!e)throw new Error("Missing token");e=e.replace(Ra,"");const t=Jr.decode(Kn.decode(e));if(!t||0===t.length||!t.startsWith("{"))throw new Error("Invalid token");return JSON.parse(t)}function Pa(e){return!!e.created_at&&Math.round((new Date).getTime()/1e3)-e.created_at<60}function Ba(e){return e.kind===hi}function Na(e,t){const n=e.tags.find(e=>"u"===e[0]);return!!n&&(n.length>0&&n[1]===t)}function Ua(e,t){const n=e.tags.find(e=>"method"===e[0]);return!!n&&(n.length>0&&n[1].toLowerCase()===t.toLowerCase())}function Ma(e){return Vt(fn(Gr.encode(JSON.stringify(e))))}function Fa(e,t){const n=e.tags.find(e=>"payload"===e[0]);if(!n)return!1;const r=Ma(t);return n.length>0&&n[1]===r}async function Da(e,t,n,r){if(!ao(e))throw new Error("Invalid nostr event, signature invalid");if(!Ba(e))throw new Error("Invalid nostr event, kind invalid");if(!Pa(e))throw new Error("Invalid nostr event, created_at timestamp invalid");if(!Na(e,t))throw new Error("Invalid nostr event, url tag invalid");if(!Ua(e,n))throw new Error("Invalid nostr event, method tag invalid");if(Boolean(r)&&"object"==typeof r&&Object.keys(r).length>0&&!Fa(e,r))throw new Error("Invalid nostr event, payload tag does not match request body hash");return!0}function Ha(e){return 3e4<=e&&e<4e4}var qa=function(e,t){return qa=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])},qa(e,t)};function za(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}qa(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}function Ka(e,t,n,r){return new(n||(n=Promise))(function(o,i){function s(e){try{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(s,a)}c((r=r.apply(e,t||[])).next())})}function Wa(e,t){var n,r,o,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},s=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return s.next=a(0),s.throw=a(1),s.return=a(2),"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(i=0)),i;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return i.label++,{value:a[1],done:!1};case 5:i.label++,r=a[1],a=[0];continue;case 7:a=i.ops.pop(),i.trys.pop();continue;default:if(!(o=i.trys,(o=o.length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){i=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){i.label=a[1];break}if(6===a[0]&&i.label<o[1]){i.label=o[1],o=a;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(a);break}o[2]&&i.ops.pop(),i.trys.pop();continue}a=t.call(e,i)}catch(e){a=[6,e],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}}function Va(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 Ja(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,o,i=n.call(e),s=[];try{for(;(void 0===t||t-- >0)&&!(r=i.next()).done;)s.push(r.value)}catch(e){o={error:e}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return s}function Ga(e,t,n){if(n||2===arguments.length)for(var r,o=0,i=t.length;o<i;o++)!r&&o in t||(r||(r=Array.prototype.slice.call(t,0,o)),r[o]=t[o]);return e.concat(r||Array.prototype.slice.call(t))}function Za(e){return this instanceof Za?(this.v=e,this):new Za(e)}function Qa(e,t,n){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var r,o=n.apply(e,t||[]),i=[];return r=Object.create(("function"==typeof AsyncIterator?AsyncIterator:Object).prototype),s("next"),s("throw"),s("return",function(e){return function(t){return Promise.resolve(t).then(e,l)}}),r[Symbol.asyncIterator]=function(){return this},r;function s(e,t){o[e]&&(r[e]=function(t){return new Promise(function(n,r){i.push([e,t,n,r])>1||a(e,t)})},t&&(r[e]=t(r[e])))}function a(e,t){try{(n=o[e](t)).value instanceof Za?Promise.resolve(n.value.v).then(c,l):u(i[0][2],n)}catch(e){u(i[0][3],e)}var n}function c(e){a("next",e)}function l(e){a("throw",e)}function u(e,t){e(t),i.shift(),i.length&&a(i[0][0],i[0][1])}}function Ya(e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t,n=e[Symbol.asyncIterator];return n?n.call(e):(e=Va(e),t={},r("next"),r("throw"),r("return"),t[Symbol.asyncIterator]=function(){return this},t);function r(n){t[n]=e[n]&&function(t){return new Promise(function(r,o){(function(e,t,n,r){Promise.resolve(r).then(function(t){e({value:t,done:n})},t)})(r,o,(t=e[n](t)).done,t.value)})}}}function Xa(e){return"function"==typeof e}function ec(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 tc=ec(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 nc(e,t){if(e){var n=e.indexOf(t);0<=n&&e.splice(n,1)}}var rc=function(){function e(e){this.initialTeardown=e,this.closed=!1,this._parentage=null,this._finalizers=null}return e.prototype.unsubscribe=function(){var e,t,n,r,o;if(!this.closed){this.closed=!0;var i=this._parentage;if(i)if(this._parentage=null,Array.isArray(i))try{for(var s=Va(i),a=s.next();!a.done;a=s.next()){a.value.remove(this)}}catch(t){e={error:t}}finally{try{a&&!a.done&&(t=s.return)&&t.call(s)}finally{if(e)throw e.error}}else i.remove(this);var c=this.initialTeardown;if(Xa(c))try{c()}catch(e){o=e instanceof tc?e.errors:[e]}var l=this._finalizers;if(l){this._finalizers=null;try{for(var u=Va(l),d=u.next();!d.done;d=u.next()){var f=d.value;try{sc(f)}catch(e){o=null!=o?o:[],e instanceof tc?o=Ga(Ga([],Ja(o)),Ja(e.errors)):o.push(e)}}}catch(e){n={error:e}}finally{try{d&&!d.done&&(r=u.return)&&r.call(u)}finally{if(n)throw n.error}}}if(o)throw new tc(o)}},e.prototype.add=function(t){var n;if(t&&t!==this)if(this.closed)sc(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)&&nc(t,e)},e.prototype.remove=function(t){var n=this._finalizers;n&&nc(n,t),t instanceof e&&t._removeParent(this)},e.EMPTY=function(){var t=new e;return t.closed=!0,t}(),e}(),oc=rc.EMPTY;function ic(e){return e instanceof rc||e&&"closed"in e&&Xa(e.remove)&&Xa(e.add)&&Xa(e.unsubscribe)}function sc(e){Xa(e)?e():e.unsubscribe()}var ac={onUnhandledError:null,onStoppedNotification:null,Promise:void 0,useDeprecatedSynchronousErrorHandling:!1,useDeprecatedNextContext:!1},cc={setTimeout:function(e,t){for(var n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];var o=cc.delegate;return(null==o?void 0:o.setTimeout)?o.setTimeout.apply(o,Ga([e,t],Ja(n))):setTimeout.apply(void 0,Ga([e,t],Ja(n)))},clearTimeout:function(e){var t=cc.delegate;return((null==t?void 0:t.clearTimeout)||clearTimeout)(e)},delegate:void 0};function lc(e){cc.setTimeout(function(){throw e})}function uc(){}function dc(e){e()}var fc=function(e){function t(t){var n=e.call(this)||this;return n.isStopped=!1,t?(n.destination=t,ic(t)&&t.add(n)):n.destination=vc,n}return za(t,e),t.create=function(e,t,n){return new yc(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}(rc),hc=Function.prototype.bind;function pc(e,t){return hc.call(e,t)}var gc=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){mc(e)}},e.prototype.error=function(e){var t=this.partialObserver;if(t.error)try{t.error(e)}catch(e){mc(e)}else mc(e)},e.prototype.complete=function(){var e=this.partialObserver;if(e.complete)try{e.complete()}catch(e){mc(e)}},e}(),yc=function(e){function t(t,n,r){var o,i,s=e.call(this)||this;Xa(t)||!t?o={next:null!=t?t:void 0,error:null!=n?n:void 0,complete:null!=r?r:void 0}:s&&ac.useDeprecatedNextContext?((i=Object.create(t)).unsubscribe=function(){return s.unsubscribe()},o={next:t.next&&pc(t.next,i),error:t.error&&pc(t.error,i),complete:t.complete&&pc(t.complete,i)}):o=t;return s.destination=new gc(o),s}return za(t,e),t}(fc);function mc(e){lc(e)}var vc={closed:!0,next:uc,error:function(e){throw e},complete:uc},wc="function"==typeof Symbol&&Symbol.observable||"@@observable";function bc(e){return e}var Ec=function(){function e(e){e&&(this._subscribe=e)}return e.prototype.lift=function(t){var n=new e;return n.source=this,n.operator=t,n},e.prototype.subscribe=function(e,t,n){var r,o=this,i=(r=e)&&r instanceof fc||function(e){return e&&Xa(e.next)&&Xa(e.error)&&Xa(e.complete)}(r)&&ic(r)?e:new yc(e,t,n);return dc(function(){var e=o,t=e.operator,n=e.source;i.add(t?t.call(i,n):n?o._subscribe(i):o._trySubscribe(i))}),i},e.prototype._trySubscribe=function(e){try{return this._subscribe(e)}catch(t){e.error(t)}},e.prototype.forEach=function(e,t){var n=this;return new(t=kc(t))(function(t,r){var o=new yc({next:function(t){try{e(t)}catch(e){r(e),o.unsubscribe()}},error:r,complete:t});n.subscribe(o)})},e.prototype._subscribe=function(e){var t;return null===(t=this.source)||void 0===t?void 0:t.subscribe(e)},e.prototype[wc]=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?bc: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=kc(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 kc(e){var t;return null!==(t=null!=e?e:ac.Promise)&&void 0!==t?t:Promise}function xc(e){return function(t){if(function(e){return Xa(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 Sc(e,t,n,r,o){return new Cc(e,t,n,r,o)}var Cc=function(e){function t(t,n,r,o,i,s){var a=e.call(this,t)||this;return a.onFinalize=i,a.shouldUnsubscribe=s,a._next=n?function(e){try{n(e)}catch(e){t.error(e)}}:e.prototype._next,a._error=o?function(e){try{o(e)}catch(e){t.error(e)}finally{this.unsubscribe()}}:e.prototype._error,a._complete=r?function(){try{r()}catch(e){t.error(e)}finally{this.unsubscribe()}}:e.prototype._complete,a}return za(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}(fc),Ac=ec(function(e){return function(){e(this),this.name="ObjectUnsubscribedError",this.message="object unsubscribed"}}),$c=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 za(t,e),t.prototype.lift=function(e){var t=new Tc(this,this);return t.operator=e,t},t.prototype._throwIfClosed=function(){if(this.closed)throw new Ac},t.prototype.next=function(e){var t=this;dc(function(){var n,r;if(t._throwIfClosed(),!t.isStopped){t.currentObservers||(t.currentObservers=Array.from(t.observers));try{for(var o=Va(t.currentObservers),i=o.next();!i.done;i=o.next()){i.value.next(e)}}catch(e){n={error:e}}finally{try{i&&!i.done&&(r=o.return)&&r.call(o)}finally{if(n)throw n.error}}}})},t.prototype.error=function(e){var t=this;dc(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;dc(function(){if(e._throwIfClosed(),!e.isStopped){e.isStopped=!0;for(var t=e.observers;t.length;)t.shift().complete()}})},t.prototype.unsubscribe=function(){this.isStopped=this.closed=!0,this.observers=this.currentObservers=null},Object.defineProperty(t.prototype,"observed",{get:function(){var e;return(null===(e=this.observers)||void 0===e?void 0:e.length)>0},enumerable:!1,configurable:!0}),t.prototype._trySubscribe=function(t){return this._throwIfClosed(),e.prototype._trySubscribe.call(this,t)},t.prototype._subscribe=function(e){return this._throwIfClosed(),this._checkFinalizedStatuses(e),this._innerSubscribe(e)},t.prototype._innerSubscribe=function(e){var t=this,n=this,r=n.hasError,o=n.isStopped,i=n.observers;return r||o?oc:(this.currentObservers=null,i.push(e),new rc(function(){t.currentObservers=null,nc(i,e)}))},t.prototype._checkFinalizedStatuses=function(e){var t=this,n=t.hasError,r=t.thrownError,o=t.isStopped;n?e.error(r):o&&e.complete()},t.prototype.asObservable=function(){var e=new Ec;return e.source=this,e},t.create=function(e,t){return new Tc(e,t)},t}(Ec),Tc=function(e){function t(t,n){var r=e.call(this)||this;return r.destination=t,r.source=n,r}return za(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:oc},t}($c),Ic={now:function(){return(Ic.delegate||Date).now()},delegate:void 0},_c=function(e){function t(t,n,r){void 0===t&&(t=1/0),void 0===n&&(n=1/0),void 0===r&&(r=Ic);var o=e.call(this)||this;return o._bufferSize=t,o._windowTime=n,o._timestampProvider=r,o._buffer=[],o._infiniteTimeWindow=!0,o._infiniteTimeWindow=n===1/0,o._bufferSize=Math.max(1,t),o._windowTime=Math.max(1,n),o}return za(t,e),t.prototype.next=function(t){var n=this,r=n.isStopped,o=n._buffer,i=n._infiniteTimeWindow,s=n._timestampProvider,a=n._windowTime;r||(o.push(t),!i&&o.push(s.now()+a)),this._trimBuffer(),e.prototype.next.call(this,t)},t.prototype._subscribe=function(e){this._throwIfClosed(),this._trimBuffer();for(var t=this._innerSubscribe(e),n=this._infiniteTimeWindow,r=this._buffer.slice(),o=0;o<r.length&&!e.closed;o+=n?1:2)e.next(r[o]);return this._checkFinalizedStatuses(e),t},t.prototype._trimBuffer=function(){var e=this,t=e._bufferSize,n=e._timestampProvider,r=e._buffer,o=e._infiniteTimeWindow,i=(o?1:2)*t;if(t<1/0&&i<r.length&&r.splice(0,r.length-i),!o){for(var s=n.now(),a=0,c=1;c<r.length&&r[c]<=s;c+=2)a=c;a&&r.splice(0,a+1)}},t}($c),Rc=function(e){function t(t,n){return e.call(this)||this}return za(t,e),t.prototype.schedule=function(e,t){return this},t}(rc),jc={setInterval:function(e,t){for(var n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];var o=jc.delegate;return(null==o?void 0:o.setInterval)?o.setInterval.apply(o,Ga([e,t],Ja(n))):setInterval.apply(void 0,Ga([e,t],Ja(n)))},clearInterval:function(e){var t=jc.delegate;return((null==t?void 0:t.clearInterval)||clearInterval)(e)},delegate:void 0},Oc=function(e){function t(t,n){var r=e.call(this,t,n)||this;return r.scheduler=t,r.work=n,r.pending=!1,r}return za(t,e),t.prototype.schedule=function(e,t){var n;if(void 0===t&&(t=0),this.closed)return this;this.state=e;var r=this.id,o=this.scheduler;return null!=r&&(this.id=this.recycleAsyncId(o,r,t)),this.pending=!0,this.delay=t,this.id=null!==(n=this.id)&&void 0!==n?n:this.requestAsyncId(o,this.id,t),this},t.prototype.requestAsyncId=function(e,t,n){return void 0===n&&(n=0),jc.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&&jc.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,nc(r,this),null!=t&&(this.id=this.recycleAsyncId(n,t,null)),this.delay=null,e.prototype.unsubscribe.call(this)}},t}(Rc),Lc=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=Ic.now,e}(),Pc=function(e){function t(t,n){void 0===n&&(n=Lc.now);var r=e.call(this,t,n)||this;return r.actions=[],r._active=!1,r}return za(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}(Lc),Bc=new Pc(Oc),Nc=new Ec(function(e){return e.complete()});function Uc(e){return e&&Xa(e.schedule)}function Mc(e){return e[e.length-1]}function Fc(e){return Uc(Mc(e))?e.pop():void 0}function Dc(e,t){return"number"==typeof Mc(e)?e.pop():t}var Hc=function(e){return e&&"number"==typeof e.length&&"function"!=typeof e};function qc(e){return Xa(null==e?void 0:e.then)}function zc(e){return Xa(e[wc])}function Kc(e){return Symbol.asyncIterator&&Xa(null==e?void 0:e[Symbol.asyncIterator])}function Wc(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 Vc="function"==typeof Symbol&&Symbol.iterator?Symbol.iterator:"@@iterator";function Jc(e){return Xa(null==e?void 0:e[Vc])}function Gc(e){return Qa(this,arguments,function(){var t,n,r;return Wa(this,function(o){switch(o.label){case 0:t=e.getReader(),o.label=1;case 1:o.trys.push([1,,9,10]),o.label=2;case 2:return[4,Za(t.read())];case 3:return n=o.sent(),r=n.value,n.done?[4,Za(void 0)]:[3,5];case 4:return[2,o.sent()];case 5:return[4,Za(r)];case 6:return[4,o.sent()];case 7:return o.sent(),[3,2];case 8:return[3,10];case 9:return t.releaseLock(),[7];case 10:return[2]}})})}function Zc(e){return Xa(null==e?void 0:e.getReader)}function Qc(e){if(e instanceof Ec)return e;if(null!=e){if(zc(e))return o=e,new Ec(function(e){var t=o[wc]();if(Xa(t.subscribe))return t.subscribe(e);throw new TypeError("Provided object does not correctly implement Symbol.observable")});if(Hc(e))return r=e,new Ec(function(e){for(var t=0;t<r.length&&!e.closed;t++)e.next(r[t]);e.complete()});if(qc(e))return n=e,new Ec(function(e){n.then(function(t){e.closed||(e.next(t),e.complete())},function(t){return e.error(t)}).then(null,lc)});if(Kc(e))return Yc(e);if(Jc(e))return t=e,new Ec(function(e){var n,r;try{for(var o=Va(t),i=o.next();!i.done;i=o.next()){var s=i.value;if(e.next(s),e.closed)return}}catch(e){n={error:e}}finally{try{i&&!i.done&&(r=o.return)&&r.call(o)}finally{if(n)throw n.error}}e.complete()});if(Zc(e))return Yc(Gc(e))}var t,n,r,o;throw Wc(e)}function Yc(e){return new Ec(function(t){(function(e,t){var n,r,o,i;return Ka(this,void 0,void 0,function(){var s,a;return Wa(this,function(c){switch(c.label){case 0:c.trys.push([0,5,6,11]),n=Ya(e),c.label=1;case 1:return[4,n.next()];case 2:if((r=c.sent()).done)return[3,4];if(s=r.value,t.next(s),t.closed)return[2];c.label=3;case 3:return[3,1];case 4:return[3,11];case 5:return a=c.sent(),o={error:a},[3,11];case 6:return c.trys.push([6,,9,10]),r&&!r.done&&(i=n.return)?[4,i.call(n)]:[3,8];case 7:c.sent(),c.label=8;case 8:return[3,10];case 9:if(o)throw o.error;return[7];case 10:return[7];case 11:return t.complete(),[2]}})})})(e,t).catch(function(e){return t.error(e)})})}function Xc(e,t,n,r,o){void 0===r&&(r=0),void 0===o&&(o=!1);var i=t.schedule(function(){n(),o?e.add(this.schedule(null,r)):this.unsubscribe()},r);if(e.add(i),!o)return i}function el(e,t){return void 0===t&&(t=0),xc(function(n,r){n.subscribe(Sc(r,function(n){return Xc(r,e,function(){return r.next(n)},t)},function(){return Xc(r,e,function(){return r.complete()},t)},function(n){return Xc(r,e,function(){return r.error(n)},t)}))})}function tl(e,t){return void 0===t&&(t=0),xc(function(n,r){r.add(e.schedule(function(){return n.subscribe(r)},t))})}function nl(e,t){if(!e)throw new Error("Iterable cannot be null");return new Ec(function(n){Xc(n,t,function(){var r=e[Symbol.asyncIterator]();Xc(n,t,function(){r.next().then(function(e){e.done?n.complete():n.next(e.value)})},0,!0)})})}function rl(e,t){if(null!=e){if(zc(e))return function(e,t){return Qc(e).pipe(tl(t),el(t))}(e,t);if(Hc(e))return function(e,t){return new Ec(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(qc(e))return function(e,t){return Qc(e).pipe(tl(t),el(t))}(e,t);if(Kc(e))return nl(e,t);if(Jc(e))return function(e,t){return new Ec(function(n){var r;return Xc(n,t,function(){r=e[Vc](),Xc(n,t,function(){var e,t,o;try{t=(e=r.next()).value,o=e.done}catch(e){return void n.error(e)}o?n.complete():n.next(t)},0,!0)}),function(){return Xa(null==r?void 0:r.return)&&r.return()}})}(e,t);if(Zc(e))return function(e,t){return nl(Gc(e),t)}(e,t)}throw Wc(e)}function ol(e,t){return t?rl(e,t):Qc(e)}function il(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return ol(e,Fc(e))}function sl(e,t){return xc(function(n,r){var o=0;n.subscribe(Sc(r,function(n){r.next(e.call(t,n,o++))}))})}var al=Array.isArray;function cl(e){return sl(function(t){return function(e,t){return al(t)?e.apply(void 0,Ga([],Ja(t))):e(t)}(e,t)})}var ll=Array.isArray,ul=Object.getPrototypeOf,dl=Object.prototype,fl=Object.keys;function hl(e){if(1===e.length){var t=e[0];if(ll(t))return{args:t,keys:null};if((r=t)&&"object"==typeof r&&ul(r)===dl){var n=fl(t);return{args:n.map(function(e){return t[e]}),keys:n}}}var r;return{args:e,keys:null}}function pl(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=Fc(e),r=function(e){return Xa(Mc(e))?e.pop():void 0}(e),o=hl(e),i=o.args,s=o.keys;if(0===i.length)return ol([],n);var a=new Ec(function(e,t,n){void 0===n&&(n=bc);return function(r){gl(t,function(){for(var o=e.length,i=new Array(o),s=o,a=o,c=function(o){gl(t,function(){var c=ol(e[o],t),l=!1;c.subscribe(Sc(r,function(e){i[o]=e,l||(l=!0,a--),a||r.next(n(i.slice()))},function(){--s||r.complete()}))},r)},l=0;l<o;l++)c(l)},r)}}(i,n,s?function(e){return function(e,t){return e.reduce(function(e,n,r){return e[n]=t[r],e},{})}(s,e)}:bc));return r?a.pipe(cl(r)):a}function gl(e,t,n){e?Xc(n,e,t):t()}function yl(e,t,n){return void 0===n&&(n=1/0),Xa(t)?yl(function(n,r){return sl(function(e,o){return t(n,e,r,o)})(Qc(e(n,r)))},n):("number"==typeof t&&(n=t),xc(function(t,r){return function(e,t,n,r,o,i,s,a){var c=[],l=0,u=0,d=!1,f=function(){!d||c.length||l||t.complete()},h=function(e){return l<r?p(e):c.push(e)},p=function(e){i&&t.next(e),l++;var a=!1;Qc(n(e,u++)).subscribe(Sc(t,function(e){null==o||o(e),i?h(e):t.next(e)},function(){a=!0},void 0,function(){if(a)try{l--;for(var e=function(){var e=c.shift();s?Xc(t,s,function(){return p(e)}):p(e)};c.length&&l<r;)e();f()}catch(e){t.error(e)}}))};return e.subscribe(Sc(t,h,function(){d=!0,f()})),function(){null==a||a()}}(t,r,e,n)}))}function ml(e){return void 0===e&&(e=1/0),yl(bc,e)}function vl(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return ml(1)(ol(e,Fc(e)))}function wl(e){return new Ec(function(t){Qc(e()).subscribe(t)})}function bl(e,t,n){void 0===e&&(e=0),void 0===n&&(n=Bc);var r=-1;return null!=t&&(Uc(t)?n=t:r=t),new Ec(function(t){var o,i=(o=e)instanceof Date&&!isNaN(o)?+e-n.now():e;i<0&&(i=0);var s=0;return n.schedule(function(){t.closed||(t.next(s++),0<=r?this.schedule(void 0,r):t.complete())},i)})}function El(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=Fc(e),r=Dc(e,1/0),o=e;return o.length?1===o.length?Qc(o[0]):ml(r)(ol(o,n)):Nc}function kl(e,t){return xc(function(n,r){var o=0;n.subscribe(Sc(r,function(n){return e.call(t,n,o++)&&r.next(n)}))})}function xl(e){return e<=0?function(){return Nc}:xc(function(t,n){var r=0;t.subscribe(Sc(n,function(t){++r<=e&&(n.next(t),e<=r&&n.complete())}))})}function Sl(e,t){return void 0===t&&(t=bc),e=null!=e?e:Cl,xc(function(n,r){var o,i=!0;n.subscribe(Sc(r,function(n){var s=t(n);!i&&e(o,s)||(i=!1,o=s,r.next(n))}))})}function Cl(e,t){return e===t}function Al(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return function(t){return vl(t,il.apply(void 0,Ga([],Ja(e))))}}function $l(e){return xc(function(t,n){try{t.subscribe(n)}finally{n.add(e)}})}function Tl(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=Fc(e),r=Dc(e,1/0);return xc(function(t,o){ml(r)(ol(Ga([t],Ja(e)),n)).subscribe(o)})}function Il(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return Tl.apply(void 0,Ga([],Ja(e)))}function _l(e,t){return xc(function(e,t,n,r,o){return function(i,s){var a=n,c=t,l=0;i.subscribe(Sc(s,function(t){var n=l++;c=a?e(c,t,n):(a=!0,t),r&&s.next(c)},o&&function(){a&&s.next(c),s.complete()}))}}(e,t,arguments.length>=2,!0))}function Rl(e,t){for(var n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];if(!0!==t){if(!1!==t){var o=new yc({next:function(){o.unsubscribe(),e()}});return Qc(t.apply(void 0,Ga([],Ja(n)))).subscribe(o)}}else e()}function jl(e,t){return xc(function(n,r){var o=null,i=0,s=!1,a=function(){return s&&!o&&r.complete()};n.subscribe(Sc(r,function(n){null==o||o.unsubscribe();var s=0,c=i++;Qc(e(n,c)).subscribe(o=Sc(r,function(e){return r.next(t?t(n,e,c,s++):e)},function(){o=null,a()}))},function(){s=!0,a()}))})}function Ol(e,t,n){var r=Xa(e)||t||n?{next:e,error:t,complete:n}:e;return r?xc(function(e,t){var n;null===(n=r.subscribe)||void 0===n||n.call(r);var o=!0;e.subscribe(Sc(t,function(e){var n;null===(n=r.next)||void 0===n||n.call(r,e),t.next(e)},function(){var e;o=!1,null===(e=r.complete)||void 0===e||e.call(r),t.complete()},function(e){var n;o=!1,null===(n=r.error)||void 0===n||n.call(r,e),t.error(e)},function(){var e,t;o&&(null===(e=r.unsubscribe)||void 0===e||e.call(r)),null===(t=r.finalize)||void 0===t||t.call(r)}))}):bc}function Ll(e,t){return void 0!==e[0]&&void 0!==e[1]&&(!t||e[0]===t)}function Pl(e){return Ll(e,"e")}function Bl(e){return Ll(e,"p")}function Nl(e){return Ll(e,"r")}function Ul(e){return Ll(e,"a")}function Ml(e){return Ll(e,"t")}const Fl=(e,...t)=>t.reduce((e,t)=>{const n=[];for(const r of e)try{const e=t(r);if(void 0===e)continue;n.push(e)}catch(e){}return n},e);function Dl(e,t,n){if(Reflect.has(e,t))return Reflect.get(e,t);{const r=n();return Reflect.set(e,t,r),r}}function Hl(e,t){const[n,r]=ql(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 ql(e,t){let n=0,r=e.length-1;for(;n<=r;){const o=Math.floor((n+r)/2),i=t(e[o]);if(0===i)return[o,!0];i<0?r=o-1:n=o+1}return[n,!1]}new TextDecoder("utf-8"),new TextEncoder;const zl=Symbol.for("event-store"),Kl=Symbol.for("event-uid"),Wl=Symbol.for("replaceable-address"),Vl=Symbol.for("from-cache"),Jl=Symbol.for("replaceable-identifier");function Gl(e){return function(e){return[0,3].includes(e)||1e4<=e&&e<2e4}(e)||Ha(e)}function Zl(e){let t=Reflect.get(e,Kl);return t||(t=Gl(e.kind)?Ql(e):e.id,Reflect.set(e,Kl,t)),t}function Ql(e){if(!Gl(e.kind))throw new Error("Event is not replaceable or addressable");return Dl(e,Wl,()=>{const t=Ha(e.kind)?Xl(e):void 0;return Yl(e.kind,e.pubkey,t)})}function Yl(e,t,n){return e+":"+t+":"+(n??"")}function Xl(e){return Dl(e,Jl,()=>e.tags.find(e=>"d"===e[0])?.[1]??"")}function eu(){return Math.round(Date.now()/1e3)}const tu=Symbol("expiration-timestamp");function nu(e){return Dl(e,tu,()=>{const t=e.tags.find(e=>"expiration"===e[0])?.[1];return t?parseInt(t):void 0})}function ru(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 ou=Symbol.for("seen-relays");function iu(e,t){return e[ou]||(e[ou]=new Set),e[ou].add(t),e[ou]}const su=/^wss?:\/\/([-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}|localhost)\b([-a-zA-Z0-9()@:%_\+.~#?&\/\/=]*)$/;function au(e){return e.length>=8&&su.test(e)}function cu(e){return!!e?.toLowerCase()?.match(/^[0-9a-f]{64}$/)} |
|
|
function Df(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&"Uint8Array"===e.constructor.name}function Hf(e,t){return!!Array.isArray(t)&&(0===t.length||(e?t.every(e=>"string"==typeof e):t.every(e=>Number.isSafeInteger(e))))}function qf(e,t){if("string"!=typeof t)throw new Error(`${e}: string expected`);return!0}function zf(e){if(!Number.isSafeInteger(e))throw new Error(`invalid integer: ${e}`)}function Kf(e){if(!Array.isArray(e))throw new Error("array expected")}function Wf(e,t){if(!Hf(!0,t))throw new Error(`${e}: array of strings expected`)}wf.BASE._setWindowSize(8);const Vf=(e,t)=>0===t?e:Vf(t,e%t),Jf=(e,t)=>e+(t-Vf(e,t)),Gf=(()=>{let e=[];for(let t=0;t<40;t++)e.push(2**t);return e})();function Zf(e,t,n,r){if(Kf(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(Jf(t,n)>32)throw new Error(`convertRadix2: carry overflow from=${t} to=${n} carryBits=${Jf(t,n)}`);let o=0,i=0;const s=Gf[t],a=Gf[n]-1,c=[];for(const r of e){if(zf(r),r>=s)throw new Error(`convertRadix2: invalid data word=${r} from=${t}`);if(o=o<<t|r,i+t>32)throw new Error(`convertRadix2: carry overflow pos=${i} from=${t}`);for(i+=t;i>=n;i-=n)c.push((o>>i-n&a)>>>0);const e=Gf[i];if(void 0===e)throw new Error("invalid carry");o&=e-1}if(o=o<<n-i&a,!r&&i>=t)throw new Error("Excess padding");if(!r&&o>0)throw new Error(`Non-zero padding: ${o}`);return r&&i>0&&c.push(o>>>0),c}const Qf=(()=>"function"==typeof Uint8Array.from([]).toBase64&&"function"==typeof Uint8Array.fromBase64)()?{encode:e=>(function(e,...t){if(!Df(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)=>{qf("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(zf(e),e<=0||e>32)throw new Error("radix2: bits should be in (0..32]");if(Jf(8,e)>32||Jf(e,8)>32)throw new Error("radix2: carry overflow");return{encode:n=>{if(!Df(n))throw new Error("radix2.encode input should be Uint8Array");return Zf(Array.from(n),8,e,!t)},decode:n=>(function(e,t){if(!Hf(!1,t))throw new Error(`${e}: array of numbers expected`)}("radix2.decode",n),Uint8Array.from(Zf(n,e,8,t)))}}(6),function(e){const t="string"==typeof e?e.split(""):e,n=t.length;Wf("alphabet",t);const r=new Map(t.map((e,t)=>[e,t]));return{encode:r=>(Kf(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=>(Kf(t),t.map(t=>{qf("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 zf(e),qf("padding",t),{encode(n){for(Wf("padding.encode",n);n.length*e%8;)n.push(t);return n},decode(n){Wf("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 qf("join",e),{encode:t=>(Wf("join.decode",t),t.join(e)),decode:t=>(qf("join.decode",t),t.split(e))}}(""));function Yf(e){return wf.fromHex(e).toHex().substring(2)}const Xf=new TextDecoder("utf-8"),eh=new TextEncoder;class th{log=Vu.extend("SerialPortSigner");writer=null;pubkey;get isConnected(){return!!this.writer}verifyEvent=ao;nip04;constructor(){this.nip04={encrypt:this.nip04Encrypt.bind(this),decrypt:this.nip04Decrypt.bind(this)}}lastCommand=null;async callMethodOnDevice(e,t,n={}){if(!th.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=Fd();return this.lastCommand=r,this.sendCommand(e,t),setTimeout(()=>{r.reject(new Error("Device timeout")),this.lastCommand===r&&(this.lastCommand=null)},6e3),this.lastCommand}async connectToDevice({onConnect:e,onDisconnect:t,onError:n,onDone:r}){let o,i=await window.navigator.serial.requestPort();await i.open({baudRate:9600}),await(e=>new Promise(t=>setTimeout(t,e)))(1e3),(async()=>{for(;i&&i.readable;){const e=new window.TextDecoderStream;i.readable.pipeTo(e.writable),o=e.readable.getReader();const t=this.readFromSerialPort(o);try{for(;;){const{value:e,done:n}=await t("\n");if(e){const{method:t,data:n}=this.parseResponse(e);if("/ping"===t&&this.log("Pong"),-1===th.PUBLIC_METHODS.indexOf(t))continue;this.log("Received: ",t,n),this.lastCommand&&(this.lastCommand.resolve(n),this.lastCommand=null)}if(n)return this.lastCommand=null,this.writer=null,void(r&&r())}}catch(e){if(e instanceof Error)throw this.writer=null,n&&n(e),this.lastCommand&&(this.lastCommand.reject(e),this.lastCommand=null),e}}})();const s=new window.TextEncoderStream;s.readable.pipeTo(i.writable),this.writer=s.writable.getWriter(),await this.sendCommand(th.METHOD_PING),await this.sendCommand(th.METHOD_PING,[window.location.host]),e&&e(),i.addEventListener("disconnect",()=>{this.log("Disconnected"),this.lastCommand=null,this.writer=null,t&&t()})}async sendCommand(e,t=[]){if(!this.writer)return;this.log("Send command",e,t);const n=[e].concat(t).join(" ");await this.writer.write(n+"\n")}readFromSerialPort(e){let t,n=[];return async(r="\n")=>{if(n.length)return{value:n.shift().trim(),done:!1};const o=[];for(t&&(o.push(t),t=void 0);;){const{value:i,done:s}=await e.read();if(i){const e=i.split(r);if(e.length>1)return o.push(e.shift()),t=e.pop(),n=e,{value:o.join("").trim(),done:!1};o.push(i)}if(s)return{value:o.join("").trim(),done:!0}}}}parseResponse(e){const t=e.split(" ")[0];return{method:t,data:e.substring(t.length).trim()}}async nip04Encrypt(e,t){const n=nf(await this.callMethodOnDevice(th.METHOD_SHARED_SECRET,[Yf(e)]));let r=Uint8Array.from(function(e=32){if(zd&&"function"==typeof zd.getRandomValues)return zd.getRandomValues(new Uint8Array(e));if(zd&&"function"==typeof zd.randomBytes)return Uint8Array.from(zd.randomBytes(e));throw new Error("crypto.getRandomValues must be defined")}(16)),o=eh.encode(t),i=await crypto.subtle.importKey("raw",n,{name:"AES-CBC"},!1,["encrypt"]),s=await crypto.subtle.encrypt({name:"AES-CBC",iv:r},i,o);return`${Qf.encode(new Uint8Array(s))}?iv=${Qf.encode(new Uint8Array(r.buffer))}`}async nip04Decrypt(e,t){let[n,r]=t.split("?iv=");const o=nf(await this.callMethodOnDevice(th.METHOD_SHARED_SECRET,[Yf(e)]));let i=await crypto.subtle.importKey("raw",o,{name:"AES-CBC"},!1,["decrypt"]),s=Qf.decode(n),a=Qf.decode(r),c=await crypto.subtle.decrypt({name:"AES-CBC",iv:a},i,s);return Xf.decode(c)}async getPublicKey(){const e=await this.callMethodOnDevice(th.METHOD_PUBLIC_KEY,[]);return this.pubkey=e,e}async restore(e){await this.callMethodOnDevice(th.METHOD_RESTORE,[Jd(e)])}async signEvent(e){const t=e.pubkey||this.pubkey;if(!t)throw new Error("Unknown signer pubkey");const n={...e,id:no({...e,pubkey:t})},r=await this.callMethodOnDevice(th.METHOD_SIGN_MESSAGE,[n.id]),o={...n,sig:r,pubkey:t};if(!this.verifyEvent(o))throw new Error("Invalid signature");return o}ping(){this.sendCommand(th.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=[th.METHOD_PUBLIC_KEY,th.METHOD_SIGN_MESSAGE,th.METHOD_SHARED_SECRET,th.METHOD_RESTORE]}const nh=[`wss://${window.location.host}/`];class rh{constructor(){this.pool=new _n,this.eventStore=new Md,this.isConnected=!1,this.signer=null,this.relays=[...nh]}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 uh([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 oh=new rh,ih="nostrCache",sh=2,ah="events";function ch(){return new Promise((e,t)=>{try{const n=indexedDB.open(ih,sh);n.onupgradeneeded=e=>{const t=n.result;e.oldVersion;let r;r=t.objectStoreNames.contains(ah)?n.transaction.objectStore(ah):t.createObjectStore(ah,{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 lh(e){try{const t=await ch();await new Promise((n,r)=>{const o=t.transaction(ah,"readwrite");o.oncomplete=()=>n(),o.onerror=()=>r(o.error),o.objectStore(ah).put(e)})}catch(e){console.warn("IDB putEvent failed",e)}}async function uh(e){if(e&&0!==e.length)try{const t=await ch();await new Promise((n,r)=>{const o=t.transaction(ah,"readwrite");o.oncomplete=()=>n(),o.onerror=()=>r(o.error);const i=o.objectStore(ah);for(const t of e)i.put(t)}),console.log(`Stored ${e.length} events in IndexedDB`)}catch(e){console.warn("IDB putEvents failed",e)}}async function dh(e){try{const t=await ch(),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 o=t.transaction(ah,"readonly").objectStore(ah),i=[];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=o.index("byKindAuthorCreated"),i=IDBKeyRange.bound([e,t,-1/0],[e,t,1/0]);s=n.openCursor(i,"prev")}else if(r.kinds&&r.kinds.length>0){console.log(`QueryEventsFromDB: Using byKind index for kind=${r.kinds[0]}`);const e=o.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=o.index("byAuthor");s=e.openCursor(IDBKeyRange.only(r.authors[0]))}else console.log("QueryEventsFromDB: Scanning all events (no specific index)"),s=o.openCursor();s.onsuccess=t=>{const n=t.target.result;if(n){const t=n.value;let o=!0;if(r.kinds&&r.kinds.length>0&&!r.kinds.includes(t.kind)&&(o=!1),r.authors&&r.authors.length>0&&!r.authors.includes(t.pubkey)&&(o=!1),r.since&&t.created_at<r.since&&(o=!1),r.until&&t.created_at>r.until&&(o=!1),r.ids&&r.ids.length>0&&!r.ids.includes(t.id)&&(o=!1),o&&i.push(t),r.limit&&i.length>=r.limit)return console.log(`QueryEventsFromDB: Reached limit of ${r.limit}, found ${i.length} matching events`),void e(i);n.continue()}else console.log(`QueryEventsFromDB: Cursor exhausted, found ${i.length} matching events`),e(i)},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 fh(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 hh(e){console.log(`Starting profile fetch for pubkey: ${e}`);try{const t=await async function(e){try{const t=await ch();return await new Promise((n,r)=>{const o=t.transaction(ah,"readonly").objectStore(ah).index("byKindAuthorCreated"),i=IDBKeyRange.bound([0,e,-1/0],[0,e,1/0]),s=o.openCursor(i,"prev");s.onsuccess=()=>{const e=s.result;n(e?e.value:null)},s.onerror=()=>r(s.error)})}catch(e){return console.warn("IDB getLatestProfileEvent failed",e),null}}(e);if(t){console.log("Using cached profile event");return fh(t)}}catch(e){console.warn("Failed to load cached profile",e)}try{const t=[{kinds:[0],authors:[e],limit:1}],n=await ph(t,{timeout:1e4});if(n.length>0){const t=n[0];console.log("Profile fetched:",t),await lh(t);try{console.log("Publishing profile event to local relay:",t.id),await oh.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=fh(t);try{"undefined"!=typeof window&&window.dispatchEvent&&window.dispatchEvent(new CustomEvent("profile-updated",{detail:{pubkey:e,profile:r,event:t}}))}catch(e){console.warn("Failed to dispatch profile-updated event",e)}return r}throw new Error("No profile found")}catch(e){throw console.error("Failed to fetch profile:",e),e}}async function ph(e,t={}){console.log("Starting event fetch with filters:",JSON.stringify(e,null,2)),console.log("Current relays:",oh.relays),oh.isConnected&&0!==oh.relays.length||(console.warn("Client not connected, initializing..."),await mh());const{timeout:n=3e4,useCache:r=!0}=t;if(r)try{const t=await dh(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 o=[],i=setTimeout(()=>{console.log(`Timeout reached after ${n}ms, returning ${o.length} events`),sub.close(),o.length>0&&uh(o).catch(e=>console.warn("Failed to cache events",e)),t(o)},n);try{const n=Math.random().toString(36).substring(7);console.log(`📤 REQ [${n}]:`,JSON.stringify(["REQ",n,...e],null,2));const r=oh.pool.subscribeMany(oh.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)}),o.push(e),lh(e).catch(e=>console.warn("Failed to cache event",e))},oneose(){console.log(`✅ EOSE received for REQ [${n}], got ${o.length} events`),clearTimeout(i),r.close(),o.length>0&&uh(o).catch(e=>console.warn("Failed to cache events",e)),t(o)}})}catch(e){clearTimeout(i),console.error("Failed to fetch events:",e),r(e)}})}async function gh(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 ph(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 yh(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 ph(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 mh(){await oh.connect()}async function vh(){try{const e=await ch(),t=e.transaction(ah,"readonly").objectStore(ah),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}}const{window:wh}=c;function bh(e){let t,n,o,i,s,a,c,f,p,y,b,E,k,x,C,A,$,T;function I(e,t){return"extension"===e[2]?kh:Eh}let _=I(e),R=_(e),j=e[5]&&xh(e),O=e[6]&&Sh(e);return{c(){t=h("div"),n=h("div"),o=h("div"),i=h("h2"),i.textContent="Login to Nostr",s=g(),a=h("button"),a.textContent="×",c=g(),f=h("div"),p=h("div"),y=h("button"),y.textContent="Extension",b=g(),E=h("button"),E.textContent="Nsec",k=g(),x=h("div"),R.c(),C=g(),j&&j.c(),A=g(),O&&O.c(),w(i,"class","svelte-1cle6o2"),w(a,"class","close-btn svelte-1cle6o2"),w(o,"class","modal-header svelte-1cle6o2"),w(y,"class","tab-btn svelte-1cle6o2"),S(y,"active","extension"===e[2]),w(E,"class","tab-btn svelte-1cle6o2"),S(E,"active","nsec"===e[2]),w(p,"class","tabs svelte-1cle6o2"),w(x,"class","tab-content svelte-1cle6o2"),w(f,"class","tab-container svelte-1cle6o2"),w(n,"class","modal svelte-1cle6o2"),S(n,"dark-theme",e[1]),w(t,"class","modal-overlay svelte-1cle6o2"),w(t,"role","button"),w(t,"tabindex","0")},m(r,d){u(r,t,d),l(t,n),l(n,o),l(o,i),l(o,s),l(o,a),l(n,c),l(n,f),l(f,p),l(p,y),l(p,b),l(p,E),l(f,k),l(f,x),R.m(x,null),l(x,C),j&&j.m(x,null),l(x,A),O&&O.m(x,null),$||(T=[m(a,"click",e[7]),m(y,"click",e[14]),m(E,"click",e[15]),m(n,"click",v(e[12])),m(n,"keydown",v(e[13])),m(t,"click",e[7]),m(t,"keydown",e[17])],$=!0)},p(e,t){4&t&&S(y,"active","extension"===e[2]),4&t&&S(E,"active","nsec"===e[2]),_===(_=I(e))&&R?R.p(e,t):(R.d(1),R=_(e),R&&(R.c(),R.m(x,C))),e[5]?j?j.p(e,t):(j=xh(e),j.c(),j.m(x,A)):j&&(j.d(1),j=null),e[6]?O?O.p(e,t):(O=Sh(e),O.c(),O.m(x,null)):O&&(O.d(1),O=null),2&t&&S(n,"dark-theme",e[1])},d(e){e&&d(t),R.d(),j&&j.d(),O&&O.d(),$=!1,r(T)}}}function Eh(e){let t,n,o,i,s,a,c,f,y,v,b=e[4]?"Logging in...":"Log in with nsec";return{c(){t=h("div"),n=h("p"),n.textContent="Enter your nsec (private key) to login. This\n will be stored securely in your browser.",o=g(),i=h("input"),s=g(),a=h("button"),c=p(b),w(n,"class","svelte-1cle6o2"),w(i,"type","password"),w(i,"placeholder","nsec1..."),i.disabled=e[4],w(i,"class","nsec-input svelte-1cle6o2"),w(a,"class","login-nsec-btn svelte-1cle6o2"),a.disabled=f=e[4]||!e[3].trim(),w(t,"class","nsec-login svelte-1cle6o2")},m(r,d){u(r,t,d),l(t,n),l(t,o),l(t,i),k(i,e[3]),l(t,s),l(t,a),l(a,c),y||(v=[m(i,"input",e[16]),m(a,"click",e[10])],y=!0)},p(e,t){16&t&&(i.disabled=e[4]),8&t&&i.value!==e[3]&&k(i,e[3]),16&t&&b!==(b=e[4]?"Logging in...":"Log in with nsec")&&E(c,b),24&t&&f!==(f=e[4]||!e[3].trim())&&(a.disabled=f)},d(e){e&&d(t),y=!1,r(v)}}}function kh(e){let t,n,r,o,i,s,a,c=e[4]?"Connecting...":"Log in using extension";return{c(){t=h("div"),n=h("p"),n.textContent="Login using a NIP-07 compatible browser\n extension like nos2x or Alby.",r=g(),o=h("button"),i=p(c),w(n,"class","svelte-1cle6o2"),w(o,"class","login-extension-btn svelte-1cle6o2"),o.disabled=e[4],w(t,"class","extension-login svelte-1cle6o2")},m(c,d){u(c,t,d),l(t,n),l(t,r),l(t,o),l(o,i),s||(a=m(o,"click",e[9]),s=!0)},p(e,t){16&t&&c!==(c=e[4]?"Connecting...":"Log in using extension")&&E(i,c),16&t&&(o.disabled=e[4])},d(e){e&&d(t),s=!1,a()}}}function xh(e){let t,n;return{c(){t=h("div"),n=p(e[5]),w(t,"class","message error-message svelte-1cle6o2")},m(e,r){u(e,t,r),l(t,n)},p(e,t){32&t&&E(n,e[5])},d(e){e&&d(t)}}}function Sh(e){let t,n;return{c(){t=h("div"),n=p(e[6]),w(t,"class","message success-message svelte-1cle6o2")},m(e,r){u(e,t,r),l(t,n)},p(e,t){64&t&&E(n,e[6])},d(e){e&&d(t)}}}function Ch(t){let n,r,o,i=t[0]&&bh(t);return{c(){i&&i.c(),n=y()},m(e,s){i&&i.m(e,s),u(e,n,s),r||(o=m(wh,"keydown",t[11]),r=!0)},p(e,[t]){e[0]?i?i.p(e,t):(i=bh(e),i.c(),i.m(n.parentNode,n)):i&&(i.d(1),i=null)},i:e,o:e,d(e){i&&i.d(e),e&&d(n),r=!1,o()}}}function Ah(e,t,n){const r=T();let{showModal:o=!1}=t,{isDarkTheme:i=!1}=t,s="extension",a="",c=!1,l="",u="";function d(){n(0,o=!1),n(3,a=""),n(5,l=""),n(6,u=""),r("close")}function f(e){n(2,s=e),n(5,l=""),n(6,u="")}async function h(){n(4,c=!0),n(5,l=""),n(6,u="");try{if(!a.trim())throw new Error("Please enter your nsec");if(!(e=a.trim()).startsWith("nsec1")||(e.length<60||e.length>70))throw new Error('Invalid nsec format. Must start with "nsec1"');const t=qd.fromKey(a.trim()),o=await t.getPublicKey();localStorage.setItem("nostr_auth_method","nsec"),localStorage.setItem("nostr_pubkey",o),localStorage.setItem("nostr_privkey",a.trim()),n(6,u="Successfully logged in with nsec!"),r("login",{method:"nsec",pubkey:o,privateKey:a.trim(),signer:t}),setTimeout(()=>{d()},1500)}catch(e){n(5,l=e.message)}finally{n(4,c=!1)}var e}return e.$$set=e=>{"showModal"in e&&n(0,o=e.showModal),"isDarkTheme"in e&&n(1,i=e.isDarkTheme)},[o,i,s,a,c,l,u,d,f,async function(){n(4,c=!0),n(5,l=""),n(6,u="");try{if(!window.nostr)throw new Error("No Nostr extension found. Please install a NIP-07 compatible extension like nos2x or Alby.");const e=await window.nostr.getPublicKey();e&&(localStorage.setItem("nostr_auth_method","extension"),localStorage.setItem("nostr_pubkey",e),n(6,u="Successfully logged in with extension!"),r("login",{method:"extension",pubkey:e,signer:window.nostr}),setTimeout(()=>{d()},1500))}catch(e){n(5,l=e.message)}finally{n(4,c=!1)}},h,function(e){"Escape"===e.key&&d(),"Enter"===e.key&&"nsec"===s&&h()},function(t){I.call(this,e,t)},function(t){I.call(this,e,t)},()=>f("extension"),()=>f("nsec"),function(){a=this.value,n(3,a)},e=>"Escape"===e.key&&d()]}class $h extends ee{constructor(e){super(),X(this,e,Ah,Ch,i,{showModal:0,isDarkTheme:1})}}function Th(e,t,n){const r=e.slice();return r[72]=t[n],r}function Ih(e,t,n){const r=e.slice();return r[75]=t[n],r}function _h(e,t,n){const r=e.slice();return r[72]=t[n],r}function Rh(e,t,n){const r=e.slice();return r[72]=t[n],r}function jh(e,t,n){const r=e.slice();return r[72]=t[n],r}function Oh(e,t,n){const r=e.slice();return r[72]=t[n],r}function Lh(e,t,n){const r=e.slice();return r[72]=t[n],r}function Ph(e){let t,n,r;return{c(){t=h("div"),n=p(e[3]),w(t,"class",r="message "+e[4]+" svelte-1y8wjwc")},m(e,r){u(e,t,r),l(t,n)},p(e,o){8&o[0]&&E(n,e[3]),16&o[0]&&r!==(r="message "+e[4]+" svelte-1y8wjwc")&&w(t,"class",r)},d(e){e&&d(t)}}}function Bh(e){let t,n,o,i,s,a,c,f,y,v,b,E,x,S,C,A,$,T,I,_,R,j,O,L,P,B,N,U;function M(e,t){return e[5]&&e[5].length>0?Uh:Nh}let F=M(e),D=F(e);function H(e,t){return e[8]&&e[8].length>0?Hh:Dh}let q=H(e),z=q(e);return{c(){t=h("div"),n=h("div"),o=h("h3"),o.textContent="Banned Pubkeys",i=g(),s=h("div"),a=h("input"),c=g(),f=h("input"),y=g(),v=h("button"),b=p("Ban Pubkey"),E=g(),x=h("div"),D.c(),S=g(),C=h("div"),A=h("h3"),A.textContent="Allowed Pubkeys",$=g(),T=h("div"),I=h("input"),_=g(),R=h("input"),j=g(),O=h("button"),L=p("Allow Pubkey"),P=g(),B=h("div"),z.c(),w(o,"class","svelte-1y8wjwc"),w(a,"type","text"),w(a,"placeholder","Pubkey (64 hex chars)"),w(a,"class","svelte-1y8wjwc"),w(f,"type","text"),w(f,"placeholder","Reason (optional)"),w(f,"class","svelte-1y8wjwc"),v.disabled=e[2],w(v,"class","svelte-1y8wjwc"),w(s,"class","add-form svelte-1y8wjwc"),w(x,"class","list svelte-1y8wjwc"),w(n,"class","section svelte-1y8wjwc"),w(A,"class","svelte-1y8wjwc"),w(I,"type","text"),w(I,"placeholder","Pubkey (64 hex chars)"),w(I,"class","svelte-1y8wjwc"),w(R,"type","text"),w(R,"placeholder","Reason (optional)"),w(R,"class","svelte-1y8wjwc"),O.disabled=e[2],w(O,"class","svelte-1y8wjwc"),w(T,"class","add-form svelte-1y8wjwc"),w(B,"class","list svelte-1y8wjwc"),w(C,"class","section svelte-1y8wjwc"),w(t,"class","pubkeys-section")},m(r,d){u(r,t,d),l(t,n),l(n,o),l(n,i),l(n,s),l(s,a),k(a,e[6]),l(s,c),l(s,f),k(f,e[7]),l(s,y),l(s,v),l(v,b),l(n,E),l(n,x),D.m(x,null),l(t,S),l(t,C),l(C,A),l(C,$),l(C,T),l(T,I),k(I,e[9]),l(T,_),l(T,R),k(R,e[10]),l(T,j),l(T,O),l(O,L),l(C,P),l(C,B),z.m(B,null),N||(U=[m(a,"input",e[43]),m(f,"input",e[44]),m(v,"click",e[25]),m(I,"input",e[45]),m(R,"input",e[46]),m(O,"click",e[26])],N=!0)},p(e,t){64&t[0]&&a.value!==e[6]&&k(a,e[6]),128&t[0]&&f.value!==e[7]&&k(f,e[7]),4&t[0]&&(v.disabled=e[2]),F===(F=M(e))&&D?D.p(e,t):(D.d(1),D=F(e),D&&(D.c(),D.m(x,null))),512&t[0]&&I.value!==e[9]&&k(I,e[9]),1024&t[0]&&R.value!==e[10]&&k(R,e[10]),4&t[0]&&(O.disabled=e[2]),q===(q=H(e))&&z?z.p(e,t):(z.d(1),z=q(e),z&&(z.c(),z.m(B,null)))},d(e){e&&d(t),D.d(),z.d(),N=!1,r(U)}}}function Nh(t){let n;return{c(){n=h("div"),n.innerHTML="<p>No banned pubkeys configured.</p>",w(n,"class","no-items svelte-1y8wjwc")},m(e,t){u(e,n,t)},p:e,d(e){e&&d(n)}}}function Uh(e){let t,n=e[5],r=[];for(let t=0;t<n.length;t+=1)r[t]=Fh(Lh(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,o){if(32&o[0]){let i;for(n=e[5],i=0;i<n.length;i+=1){const s=Lh(e,n,i);r[i]?r[i].p(s,o):(r[i]=Fh(s),r[i].c(),r[i].m(t.parentNode,t))}for(;i<r.length;i+=1)r[i].d(1);r.length=n.length}},d(e){f(r,e),e&&d(t)}}}function Mh(e){let t,n,r=e[72].reason+"";return{c(){t=h("span"),n=p(r),w(t,"class","reason svelte-1y8wjwc")},m(e,r){u(e,t,r),l(t,n)},p(e,t){32&t[0]&&r!==(r=e[72].reason+"")&&E(n,r)},d(e){e&&d(t)}}}function Fh(e){let t,n,r,o,i,s=e[72].pubkey+"",a=e[72].reason&&Mh(e);return{c(){t=h("div"),n=h("span"),r=p(s),o=g(),a&&a.c(),i=g(),w(n,"class","pubkey svelte-1y8wjwc"),w(t,"class","list-item svelte-1y8wjwc")},m(e,s){u(e,t,s),l(t,n),l(n,r),l(t,o),a&&a.m(t,null),l(t,i)},p(e,n){32&n[0]&&s!==(s=e[72].pubkey+"")&&E(r,s),e[72].reason?a?a.p(e,n):(a=Mh(e),a.c(),a.m(t,i)):a&&(a.d(1),a=null)},d(e){e&&d(t),a&&a.d()}}}function Dh(t){let n;return{c(){n=h("div"),n.innerHTML="<p>No allowed pubkeys configured.</p>",w(n,"class","no-items svelte-1y8wjwc")},m(e,t){u(e,n,t)},p:e,d(e){e&&d(n)}}}function Hh(e){let t,n=e[8],r=[];for(let t=0;t<n.length;t+=1)r[t]=zh(Oh(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,o){if(256&o[0]){let i;for(n=e[8],i=0;i<n.length;i+=1){const s=Oh(e,n,i);r[i]?r[i].p(s,o):(r[i]=zh(s),r[i].c(),r[i].m(t.parentNode,t))}for(;i<r.length;i+=1)r[i].d(1);r.length=n.length}},d(e){f(r,e),e&&d(t)}}}function qh(e){let t,n,r=e[72].reason+"";return{c(){t=h("span"),n=p(r),w(t,"class","reason svelte-1y8wjwc")},m(e,r){u(e,t,r),l(t,n)},p(e,t){256&t[0]&&r!==(r=e[72].reason+"")&&E(n,r)},d(e){e&&d(t)}}}function zh(e){let t,n,r,o,i,s=e[72].pubkey+"",a=e[72].reason&&qh(e);return{c(){t=h("div"),n=h("span"),r=p(s),o=g(),a&&a.c(),i=g(),w(n,"class","pubkey svelte-1y8wjwc"),w(t,"class","list-item svelte-1y8wjwc")},m(e,s){u(e,t,s),l(t,n),l(n,r),l(t,o),a&&a.m(t,null),l(t,i)},p(e,n){256&n[0]&&s!==(s=e[72].pubkey+"")&&E(r,s),e[72].reason?a?a.p(e,n):(a=qh(e),a.c(),a.m(t,i)):a&&(a.d(1),a=null)},d(e){e&&d(t),a&&a.d()}}}function Kh(e){let t,n,o,i,s,a,c,f,y,v,b,E,x,S,C,A,$,T,I,_,R,j,O,L,P,B,N,U;function M(e,t){return e[11]&&e[11].length>0?Vh:Wh}let F=M(e),D=F(e);let H=function(e){return e[22]&&e[22].length>0?Qh:Zh}(e),q=H(e);return{c(){t=h("div"),n=h("div"),o=h("h3"),o.textContent="Banned Events",i=g(),s=h("div"),a=h("input"),c=g(),f=h("input"),y=g(),v=h("button"),b=p("Ban Event"),E=g(),x=h("div"),D.c(),S=g(),C=h("div"),A=h("h3"),A.textContent="Allowed Events",$=g(),T=h("div"),I=h("input"),_=g(),R=h("input"),j=g(),O=h("button"),L=p("Allow Event"),P=g(),B=h("div"),q.c(),w(o,"class","svelte-1y8wjwc"),w(a,"type","text"),w(a,"placeholder","Event ID (64 hex chars)"),w(a,"class","svelte-1y8wjwc"),w(f,"type","text"),w(f,"placeholder","Reason (optional)"),w(f,"class","svelte-1y8wjwc"),v.disabled=e[2],w(v,"class","svelte-1y8wjwc"),w(s,"class","add-form svelte-1y8wjwc"),w(x,"class","list svelte-1y8wjwc"),w(n,"class","section svelte-1y8wjwc"),w(A,"class","svelte-1y8wjwc"),w(I,"type","text"),w(I,"placeholder","Event ID (64 hex chars)"),w(I,"class","svelte-1y8wjwc"),w(R,"type","text"),w(R,"placeholder","Reason (optional)"),w(R,"class","svelte-1y8wjwc"),O.disabled=e[2],w(O,"class","svelte-1y8wjwc"),w(T,"class","add-form svelte-1y8wjwc"),w(B,"class","list svelte-1y8wjwc"),w(C,"class","section svelte-1y8wjwc"),w(t,"class","events-section")},m(r,d){u(r,t,d),l(t,n),l(n,o),l(n,i),l(n,s),l(s,a),k(a,e[12]),l(s,c),l(s,f),k(f,e[13]),l(s,y),l(s,v),l(v,b),l(n,E),l(n,x),D.m(x,null),l(t,S),l(t,C),l(C,A),l(C,$),l(C,T),l(T,I),k(I,e[14]),l(T,_),l(T,R),k(R,e[15]),l(T,j),l(T,O),l(O,L),l(C,P),l(C,B),q.m(B,null),N||(U=[m(a,"input",e[47]),m(f,"input",e[48]),m(v,"click",e[27]),m(I,"input",e[49]),m(R,"input",e[50]),m(O,"click",e[28])],N=!0)},p(e,t){4096&t[0]&&a.value!==e[12]&&k(a,e[12]),8192&t[0]&&f.value!==e[13]&&k(f,e[13]),4&t[0]&&(v.disabled=e[2]),F===(F=M(e))&&D?D.p(e,t):(D.d(1),D=F(e),D&&(D.c(),D.m(x,null))),16384&t[0]&&I.value!==e[14]&&k(I,e[14]),32768&t[0]&&R.value!==e[15]&&k(R,e[15]),4&t[0]&&(O.disabled=e[2]),q.p(e,t)},d(e){e&&d(t),D.d(),q.d(),N=!1,r(U)}}}function Wh(t){let n;return{c(){n=h("div"),n.innerHTML="<p>No banned events configured.</p>",w(n,"class","no-items svelte-1y8wjwc")},m(e,t){u(e,n,t)},p:e,d(e){e&&d(n)}}}function Vh(e){let t,n=e[11],r=[];for(let t=0;t<n.length;t+=1)r[t]=Gh(jh(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,o){if(2048&o[0]){let i;for(n=e[11],i=0;i<n.length;i+=1){const s=jh(e,n,i);r[i]?r[i].p(s,o):(r[i]=Gh(s),r[i].c(),r[i].m(t.parentNode,t))}for(;i<r.length;i+=1)r[i].d(1);r.length=n.length}},d(e){f(r,e),e&&d(t)}}}function Jh(e){let t,n,r=e[72].reason+"";return{c(){t=h("span"),n=p(r),w(t,"class","reason svelte-1y8wjwc")},m(e,r){u(e,t,r),l(t,n)},p(e,t){2048&t[0]&&r!==(r=e[72].reason+"")&&E(n,r)},d(e){e&&d(t)}}}function Gh(e){let t,n,r,o,i,s=e[72].id+"",a=e[72].reason&&Jh(e);return{c(){t=h("div"),n=h("span"),r=p(s),o=g(),a&&a.c(),i=g(),w(n,"class","event-id svelte-1y8wjwc"),w(t,"class","list-item svelte-1y8wjwc")},m(e,s){u(e,t,s),l(t,n),l(n,r),l(t,o),a&&a.m(t,null),l(t,i)},p(e,n){2048&n[0]&&s!==(s=e[72].id+"")&&E(r,s),e[72].reason?a?a.p(e,n):(a=Jh(e),a.c(),a.m(t,i)):a&&(a.d(1),a=null)},d(e){e&&d(t),a&&a.d()}}}function Zh(t){let n;return{c(){n=h("div"),n.innerHTML="<p>No allowed events configured.</p>",w(n,"class","no-items svelte-1y8wjwc")},m(e,t){u(e,n,t)},p:e,d(e){e&&d(n)}}}function Qh(e){let t,n=e[22],r=[];for(let t=0;t<n.length;t+=1)r[t]=Yh(Rh(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,o){if(4194304&o[0]){let i;for(n=e[22],i=0;i<n.length;i+=1){const s=Rh(e,n,i);r[i]?r[i].p(s,o):(r[i]=Yh(s),r[i].c(),r[i].m(t.parentNode,t))}for(;i<r.length;i+=1)r[i].d(1);r.length=n.length}},d(e){f(r,e),e&&d(t)}}}function Yh(t){let n,r,o,i,s,a=t[72].id+"",c=t[72].reason&&function(t){let n,r,o=t[72].reason+"";return{c(){n=h("span"),r=p(o),w(n,"class","reason svelte-1y8wjwc")},m(e,t){u(e,n,t),l(n,r)},p:e,d(e){e&&d(n)}}}(t);return{c(){n=h("div"),r=h("span"),o=p(a),i=g(),c&&c.c(),s=g(),w(r,"class","event-id svelte-1y8wjwc"),w(n,"class","list-item svelte-1y8wjwc")},m(e,t){u(e,n,t),l(n,r),l(r,o),l(n,i),c&&c.m(n,null),l(n,s)},p(e,t){e[72].reason&&c.p(e,t)},d(e){e&&d(n),c&&c.d()}}}function Xh(e){let t,n,o,i,s,a,c,f,y,v,b,E,x,S,C;function A(e,t){return e[16]&&e[16].length>0?tp:ep}let $=A(e),T=$(e);return{c(){t=h("div"),n=h("div"),o=h("h3"),o.textContent="Blocked IPs",i=g(),s=h("div"),a=h("input"),c=g(),f=h("input"),y=g(),v=h("button"),b=p("Block IP"),E=g(),x=h("div"),T.c(),w(o,"class","svelte-1y8wjwc"),w(a,"type","text"),w(a,"placeholder","IP Address"),w(a,"class","svelte-1y8wjwc"),w(f,"type","text"),w(f,"placeholder","Reason (optional)"),w(f,"class","svelte-1y8wjwc"),v.disabled=e[2],w(v,"class","svelte-1y8wjwc"),w(s,"class","add-form svelte-1y8wjwc"),w(x,"class","list svelte-1y8wjwc"),w(n,"class","section svelte-1y8wjwc"),w(t,"class","ips-section")},m(r,d){u(r,t,d),l(t,n),l(n,o),l(n,i),l(n,s),l(s,a),k(a,e[17]),l(s,c),l(s,f),k(f,e[18]),l(s,y),l(s,v),l(v,b),l(n,E),l(n,x),T.m(x,null),S||(C=[m(a,"input",e[51]),m(f,"input",e[52]),m(v,"click",e[29])],S=!0)},p(e,t){131072&t[0]&&a.value!==e[17]&&k(a,e[17]),262144&t[0]&&f.value!==e[18]&&k(f,e[18]),4&t[0]&&(v.disabled=e[2]),$===($=A(e))&&T?T.p(e,t):(T.d(1),T=$(e),T&&(T.c(),T.m(x,null)))},d(e){e&&d(t),T.d(),S=!1,r(C)}}}function ep(t){let n;return{c(){n=h("div"),n.innerHTML="<p>No blocked IPs configured.</p>",w(n,"class","no-items svelte-1y8wjwc")},m(e,t){u(e,n,t)},p:e,d(e){e&&d(n)}}}function tp(e){let t,n=e[16],r=[];for(let t=0;t<n.length;t+=1)r[t]=rp(_h(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,o){if(65536&o[0]){let i;for(n=e[16],i=0;i<n.length;i+=1){const s=_h(e,n,i);r[i]?r[i].p(s,o):(r[i]=rp(s),r[i].c(),r[i].m(t.parentNode,t))}for(;i<r.length;i+=1)r[i].d(1);r.length=n.length}},d(e){f(r,e),e&&d(t)}}}function np(e){let t,n,r=e[72].reason+"";return{c(){t=h("span"),n=p(r),w(t,"class","reason svelte-1y8wjwc")},m(e,r){u(e,t,r),l(t,n)},p(e,t){65536&t[0]&&r!==(r=e[72].reason+"")&&E(n,r)},d(e){e&&d(t)}}}function rp(e){let t,n,r,o,i,s=e[72].ip+"",a=e[72].reason&&np(e);return{c(){t=h("div"),n=h("span"),r=p(s),o=g(),a&&a.c(),i=g(),w(n,"class","ip svelte-1y8wjwc"),w(t,"class","list-item svelte-1y8wjwc")},m(e,s){u(e,t,s),l(t,n),l(n,r),l(t,o),a&&a.m(t,null),l(t,i)},p(e,n){65536&n[0]&&s!==(s=e[72].ip+"")&&E(r,s),e[72].reason?a?a.p(e,n):(a=np(e),a.c(),a.m(t,i)):a&&(a.d(1),a=null)},d(e){e&&d(t),a&&a.d()}}}function op(e){let t,n,o,i,s,a,c,f,y,v,E,x,S;function C(e,t){return e[19]&&e[19].length>0?sp:ip}let A=C(e),$=A(e);return{c(){t=h("div"),n=h("div"),o=h("h3"),o.textContent="Allowed Event Kinds",i=g(),s=h("div"),a=h("input"),c=g(),f=h("button"),y=p("Allow Kind"),v=g(),E=h("div"),$.c(),w(o,"class","svelte-1y8wjwc"),w(a,"type","number"),w(a,"placeholder","Kind number"),w(a,"class","svelte-1y8wjwc"),f.disabled=e[2],w(f,"class","svelte-1y8wjwc"),w(s,"class","add-form svelte-1y8wjwc"),w(E,"class","list svelte-1y8wjwc"),w(n,"class","section svelte-1y8wjwc"),w(t,"class","kinds-section")},m(r,d){u(r,t,d),l(t,n),l(n,o),l(n,i),l(n,s),l(s,a),k(a,e[20]),l(s,c),l(s,f),l(f,y),l(n,v),l(n,E),$.m(E,null),x||(S=[m(a,"input",e[53]),m(f,"click",e[30])],x=!0)},p(e,t){1048576&t[0]&&b(a.value)!==e[20]&&k(a,e[20]),4&t[0]&&(f.disabled=e[2]),A===(A=C(e))&&$?$.p(e,t):($.d(1),$=A(e),$&&($.c(),$.m(E,null)))},d(e){e&&d(t),$.d(),x=!1,r(S)}}}function ip(t){let n;return{c(){n=h("div"),n.innerHTML="<p>No allowed kinds configured. All kinds are\n allowed by default.</p>",w(n,"class","no-items svelte-1y8wjwc")},m(e,t){u(e,n,t)},p:e,d(e){e&&d(n)}}}function sp(e){let t,n=e[19],r=[];for(let t=0;t<n.length;t+=1)r[t]=ap(Ih(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,o){if(524288&o[0]|1&o[1]){let i;for(n=e[19],i=0;i<n.length;i+=1){const s=Ih(e,n,i);r[i]?r[i].p(s,o):(r[i]=ap(s),r[i].c(),r[i].m(t.parentNode,t))}for(;i<r.length;i+=1)r[i].d(1);r.length=n.length}},d(e){f(r,e),e&&d(t)}}}function ap(e){let t,n,r,o,i,s,a,c,f,y=e[75]+"";function v(){return e[54](e[75])}return{c(){t=h("div"),n=h("span"),r=p("Kind "),o=p(y),i=g(),s=h("button"),s.textContent="Remove",a=g(),w(n,"class","kind svelte-1y8wjwc"),w(s,"class","remove-btn svelte-1y8wjwc"),w(t,"class","list-item svelte-1y8wjwc")},m(e,d){u(e,t,d),l(t,n),l(n,r),l(n,o),l(t,i),l(t,s),l(t,a),c||(f=m(s,"click",v),c=!0)},p(t,n){e=t,524288&n[0]&&y!==(y=e[75]+"")&&E(o,y)},d(e){e&&d(t),c=!1,f()}}}function cp(e){let t,n,r,o,i,s,a,c,f,y;function v(e,t){return e[21]&&e[21].length>0?up:lp}let b=v(e),E=b(e);return{c(){t=h("div"),n=h("div"),r=h("h3"),r.textContent="Events Needing Moderation",o=g(),i=h("button"),s=p("Refresh"),a=g(),c=h("div"),E.c(),w(r,"class","svelte-1y8wjwc"),i.disabled=e[2],w(c,"class","list svelte-1y8wjwc"),w(n,"class","section svelte-1y8wjwc"),w(t,"class","moderation-section")},m(d,h){u(d,t,h),l(t,n),l(n,r),l(n,o),l(n,i),l(i,s),l(n,a),l(n,c),E.m(c,null),f||(y=m(i,"click",e[24]),f=!0)},p(e,t){4&t[0]&&(i.disabled=e[2]),b===(b=v(e))&&E?E.p(e,t):(E.d(1),E=b(e),E&&(E.c(),E.m(c,null)))},d(e){e&&d(t),E.d(),f=!1,y()}}}function lp(t){let n;return{c(){n=h("div"),n.innerHTML="<p>No events need moderation at this time.</p>",w(n,"class","no-items svelte-1y8wjwc")},m(e,t){u(e,n,t)},p:e,d(e){e&&d(n)}}}function up(e){let t,n=e[21],r=[];for(let t=0;t<n.length;t+=1)r[t]=fp(Th(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,o){if(2097152&o[0]|12&o[1]){let i;for(n=e[21],i=0;i<n.length;i+=1){const s=Th(e,n,i);r[i]?r[i].p(s,o):(r[i]=fp(s),r[i].c(),r[i].m(t.parentNode,t))}for(;i<r.length;i+=1)r[i].d(1);r.length=n.length}},d(e){f(r,e),e&&d(t)}}}function dp(e){let t,n,r=e[72].reason+"";return{c(){t=h("span"),n=p(r),w(t,"class","reason svelte-1y8wjwc")},m(e,r){u(e,t,r),l(t,n)},p(e,t){2097152&t[0]&&r!==(r=e[72].reason+"")&&E(n,r)},d(e){e&&d(t)}}}function fp(e){let t,n,o,i,s,a,c,f,y,v,b,k,x=e[72].id+"",S=e[72].reason&&dp(e);function C(){return e[55](e[72])}function A(){return e[56](e[72])}return{c(){t=h("div"),n=h("span"),o=p(x),i=g(),S&&S.c(),s=g(),a=h("div"),c=h("button"),c.textContent="Allow",f=g(),y=h("button"),y.textContent="Ban",v=g(),w(n,"class","event-id svelte-1y8wjwc"),w(c,"class","svelte-1y8wjwc"),w(y,"class","svelte-1y8wjwc"),w(a,"class","actions svelte-1y8wjwc"),w(t,"class","list-item svelte-1y8wjwc")},m(e,r){u(e,t,r),l(t,n),l(n,o),l(t,i),S&&S.m(t,null),l(t,s),l(t,a),l(a,c),l(a,f),l(a,y),l(t,v),b||(k=[m(c,"click",C),m(y,"click",A)],b=!0)},p(n,r){e=n,2097152&r[0]&&x!==(x=e[72].id+"")&&E(o,x),e[72].reason?S?S.p(e,r):(S=dp(e),S.c(),S.m(t,s)):S&&(S.d(1),S=null)},d(e){e&&d(t),S&&S.d(),b=!1,r(k)}}}function hp(e){let t,n,o,i,s,a,c,f,y,v,b,E,x,S,C,A,$,T,I,_,R,j,O,L,P,B,N,U;function M(e,t){return e[2]?gp:pp}let F=M(e),D=F(e);return{c(){t=h("div"),n=h("div"),o=h("h3"),o.textContent="Relay Configuration",i=g(),s=h("div"),a=h("button"),c=p("🔄 Refresh from Relay Info"),f=g(),y=h("div"),v=h("div"),b=h("label"),b.textContent="Relay Name",E=g(),x=h("input"),S=g(),C=h("div"),A=h("label"),A.textContent="Relay Description",$=g(),T=h("textarea"),I=g(),_=h("div"),R=h("label"),R.textContent="Relay Icon URL",j=g(),O=h("input"),L=g(),P=h("div"),B=h("button"),D.c(),w(o,"class","svelte-1y8wjwc"),a.disabled=e[2],w(a,"class","refresh-btn svelte-1y8wjwc"),w(s,"class","config-actions svelte-1y8wjwc"),w(b,"for","relay-name"),w(b,"class","svelte-1y8wjwc"),w(x,"id","relay-name"),w(x,"type","text"),w(x,"placeholder","Enter relay name"),w(x,"class","svelte-1y8wjwc"),w(v,"class","form-group svelte-1y8wjwc"),w(A,"for","relay-description"),w(A,"class","svelte-1y8wjwc"),w(T,"id","relay-description"),w(T,"placeholder","Enter relay description"),w(T,"class","svelte-1y8wjwc"),w(C,"class","form-group svelte-1y8wjwc"),w(R,"for","relay-icon"),w(R,"class","svelte-1y8wjwc"),w(O,"id","relay-icon"),w(O,"type","url"),w(O,"placeholder","Enter icon URL"),w(O,"class","svelte-1y8wjwc"),w(_,"class","form-group svelte-1y8wjwc"),B.disabled=e[2],w(B,"class","update-all-btn svelte-1y8wjwc"),w(P,"class","config-update-section svelte-1y8wjwc"),w(y,"class","config-form svelte-1y8wjwc"),w(n,"class","section svelte-1y8wjwc"),w(t,"class","relay-section")},m(r,d){u(r,t,d),l(t,n),l(n,o),l(n,i),l(n,s),l(s,a),l(a,c),l(n,f),l(n,y),l(y,v),l(v,b),l(v,E),l(v,x),k(x,e[0].relay_name),l(y,S),l(y,C),l(C,A),l(C,$),l(C,T),k(T,e[0].relay_description),l(y,I),l(y,_),l(_,R),l(_,j),l(_,O),k(O,e[0].relay_icon),l(y,L),l(y,P),l(P,B),D.m(B,null),N||(U=[m(a,"click",e[23]),m(x,"input",e[57]),m(T,"input",e[58]),m(O,"input",e[59]),m(B,"click",e[32])],N=!0)},p(e,t){4&t[0]&&(a.disabled=e[2]),1&t[0]&&x.value!==e[0].relay_name&&k(x,e[0].relay_name),1&t[0]&&k(T,e[0].relay_description),1&t[0]&&O.value!==e[0].relay_icon&&k(O,e[0].relay_icon),F!==(F=M(e))&&(D.d(1),D=F(e),D&&(D.c(),D.m(B,null))),4&t[0]&&(B.disabled=e[2])},d(e){e&&d(t),D.d(),N=!1,r(U)}}}function pp(e){let t;return{c(){t=p("💾 Update Configuration")},m(e,n){u(e,t,n)},d(e){e&&d(t)}}}function gp(e){let t;return{c(){t=p("⏳ Updating...")},m(e,n){u(e,t,n)},d(e){e&&d(t)}}}function yp(t){let n,o,i,s,a,c,f,y,v,b,E,k,x,S,C,A,$,T,I,_,R,j,O,L,P,B,N,U,M,F,D,H,q,z,K,W,V,J=t[3]&&Ph(t),G="pubkeys"===t[1]&&Bh(t),Z="events"===t[1]&&Kh(t),Q="ips"===t[1]&&Xh(t),Y="kinds"===t[1]&&op(t),X="moderation"===t[1]&&cp(t),ee="relay"===t[1]&&hp(t);return{c(){n=h("div"),o=h("div"),o.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>',i=g(),J&&J.c(),s=g(),a=h("div"),c=h("button"),f=p("Pubkeys"),v=g(),b=h("button"),E=p("Events"),x=g(),S=h("button"),C=p("IPs"),$=g(),T=h("button"),I=p("Kinds"),R=g(),j=h("button"),O=p("Moderation"),P=g(),B=h("button"),N=p("Relay Config"),M=g(),F=h("div"),G&&G.c(),D=g(),Z&&Z.c(),H=g(),Q&&Q.c(),q=g(),Y&&Y.c(),z=g(),X&&X.c(),K=g(),ee&&ee.c(),w(o,"class","header svelte-1y8wjwc"),w(c,"class",y="tab "+("pubkeys"===t[1]?"active":"")+" svelte-1y8wjwc"),w(b,"class",k="tab "+("events"===t[1]?"active":"")+" svelte-1y8wjwc"),w(S,"class",A="tab "+("ips"===t[1]?"active":"")+" svelte-1y8wjwc"),w(T,"class",_="tab "+("kinds"===t[1]?"active":"")+" svelte-1y8wjwc"),w(j,"class",L="tab "+("moderation"===t[1]?"active":"")+" svelte-1y8wjwc"),w(B,"class",U="tab "+("relay"===t[1]?"active":"")+" svelte-1y8wjwc"),w(a,"class","tabs svelte-1y8wjwc"),w(F,"class","tab-content svelte-1y8wjwc")},m(e,r){u(e,n,r),l(n,o),l(n,i),J&&J.m(n,null),l(n,s),l(n,a),l(a,c),l(c,f),l(a,v),l(a,b),l(b,E),l(a,x),l(a,S),l(S,C),l(a,$),l(a,T),l(T,I),l(a,R),l(a,j),l(j,O),l(a,P),l(a,B),l(B,N),l(n,M),l(n,F),G&&G.m(F,null),l(F,D),Z&&Z.m(F,null),l(F,H),Q&&Q.m(F,null),l(F,q),Y&&Y.m(F,null),l(F,z),X&&X.m(F,null),l(F,K),ee&&ee.m(F,null),W||(V=[m(c,"click",t[37]),m(b,"click",t[38]),m(S,"click",t[39]),m(T,"click",t[40]),m(j,"click",t[41]),m(B,"click",t[42])],W=!0)},p(e,t){e[3]?J?J.p(e,t):(J=Ph(e),J.c(),J.m(n,s)):J&&(J.d(1),J=null),2&t[0]&&y!==(y="tab "+("pubkeys"===e[1]?"active":"")+" svelte-1y8wjwc")&&w(c,"class",y),2&t[0]&&k!==(k="tab "+("events"===e[1]?"active":"")+" svelte-1y8wjwc")&&w(b,"class",k),2&t[0]&&A!==(A="tab "+("ips"===e[1]?"active":"")+" svelte-1y8wjwc")&&w(S,"class",A),2&t[0]&&_!==(_="tab "+("kinds"===e[1]?"active":"")+" svelte-1y8wjwc")&&w(T,"class",_),2&t[0]&&L!==(L="tab "+("moderation"===e[1]?"active":"")+" svelte-1y8wjwc")&&w(j,"class",L),2&t[0]&&U!==(U="tab "+("relay"===e[1]?"active":"")+" svelte-1y8wjwc")&&w(B,"class",U),"pubkeys"===e[1]?G?G.p(e,t):(G=Bh(e),G.c(),G.m(F,D)):G&&(G.d(1),G=null),"events"===e[1]?Z?Z.p(e,t):(Z=Kh(e),Z.c(),Z.m(F,H)):Z&&(Z.d(1),Z=null),"ips"===e[1]?Q?Q.p(e,t):(Q=Xh(e),Q.c(),Q.m(F,q)):Q&&(Q.d(1),Q=null),"kinds"===e[1]?Y?Y.p(e,t):(Y=op(e),Y.c(),Y.m(F,z)):Y&&(Y.d(1),Y=null),"moderation"===e[1]?X?X.p(e,t):(X=cp(e),X.c(),X.m(F,K)):X&&(X.d(1),X=null),"relay"===e[1]?ee?ee.p(e,t):(ee=hp(e),ee.c(),ee.m(F,null)):ee&&(ee.d(1),ee=null)},i:e,o:e,d(e){e&&d(n),J&&J.d(),G&&G.d(),Z&&Z.d(),Q&&Q.d(),Y&&Y.d(),X&&X.d(),ee&&ee.d(),W=!1,r(V)}}}function mp(e,t,n){let{userSigner:r}=t,{userPubkey:o}=t,i="pubkeys",s=!1,a="",c="info",l=[],u="",d="",f=[],h="",p="",g=[],y="",m="",v="",w="",E=[],k="",x="",S=[],C="",A=[],T={relay_name:"",relay_description:"",relay_icon:""};var I;async function _(){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,T={relay_name:t.name||"",relay_description:t.description||"",relay_icon:t.icon||""}),console.log("Updated relayConfig:",T),console.log("Loaded relay info:",t),n(3,a="Relay configuration loaded successfully"),n(4,c="success")}else console.error("Failed to fetch relay info, status:",e.status),n(3,a=`Failed to fetch relay info: ${e.status}`),n(4,c="error")}catch(e){console.error("Failed to fetch relay info:",e),n(3,a=`Failed to fetch relay info: ${e.message}`),n(4,c="error")}finally{n(2,s=!1)}}async function R(e,t=[]){try{n(2,s=!0),n(3,a="");const i={method:e,params:t},c=await async function(e,t){if(!r)throw new Error("No signer available for authentication. Please log in with a Nostr extension.");if(!o)throw new Error("No user pubkey available for authentication.");const n=window.location.origin+t,i={kind:27235,created_at:Math.floor(Date.now()/1e3),tags:[["u",n],["method",e]],content:"",pubkey:o},s=await r.signEvent(i),a=JSON.stringify(s);return`Nostr ${btoa(a)}`}("POST","/api/nip86"),l=await fetch("/api/nip86",{method:"POST",headers:{"Content-Type":"application/nostr+json+rpc",Authorization:c},body:JSON.stringify(i)});if(!l.ok)throw new Error(`HTTP ${l.status}: ${l.statusText}`);const u=await l.json();if(u.error)throw new Error(u.error);return u.result}catch(e){throw console.error("NIP-86 API error:",e),n(3,a=e.message),n(4,c="error"),e}finally{n(2,s=!1)}}async function j(){try{n(5,l=await R("listbannedpubkeys"))}catch(e){console.error("Failed to load banned pubkeys:",e)}}async function O(){try{n(8,f=await R("listallowedpubkeys"))}catch(e){console.error("Failed to load allowed pubkeys:",e)}}async function L(){try{n(11,g=await R("listbannedevents"))}catch(e){console.error("Failed to load banned events:",e)}}async function P(){try{n(16,E=await R("listblockedips"))}catch(e){console.error("Failed to load blocked IPs:",e)}}async function B(){try{n(19,S=await R("listallowedkinds"))}catch(e){console.error("Failed to load allowed kinds:",e)}}async function N(){try{n(2,s=!0),n(21,A=await R("listeventsneedingmoderation")),console.log("Loaded events needing moderation:",A)}catch(e){console.error("Failed to load events needing moderation:",e),n(3,a=`Failed to load moderation events: ${e.message}`),n(4,c="error"),n(21,A=[])}finally{n(2,s=!1)}}async function U(e){try{await R("disallowkind",[e]),n(3,a="Kind disallowed successfully"),n(4,c="success"),await B()}catch(e){console.error("Failed to disallow kind:",e)}}async function M(e){try{await R("allowevent",[e,"Approved from moderation queue"]),n(3,a="Event allowed successfully"),n(4,c="success"),await N()}catch(e){console.error("Failed to allow event from moderation:",e)}}async function F(e){try{await R("banevent",[e,"Banned from moderation queue"]),n(3,a="Event banned successfully"),n(4,c="success"),await N()}catch(e){console.error("Failed to ban event from moderation:",e)}}I=()=>{setTimeout(()=>{_()},100)},$().$$.on_mount.push(I),async function(){await Promise.all([j(),O(),L(),P(),B()])}();return e.$$set=e=>{"userSigner"in e&&n(35,r=e.userSigner),"userPubkey"in e&&n(36,o=e.userPubkey)},e.$$.update=()=>{1&e.$$.dirty[0]&&console.log("relayConfig changed:",T)},[T,i,s,a,c,l,u,d,f,h,p,g,y,m,v,w,E,k,x,S,C,A,[],_,N,async function(){if(u)try{await R("banpubkey",[u,d]),n(3,a="Pubkey banned successfully"),n(4,c="success"),n(6,u=""),n(7,d=""),await j()}catch(e){console.error("Failed to ban pubkey:",e)}},async function(){if(h)try{await R("allowpubkey",[h,p]),n(3,a="Pubkey allowed successfully"),n(4,c="success"),n(9,h=""),n(10,p=""),await O()}catch(e){console.error("Failed to allow pubkey:",e)}},async function(){if(y)try{await R("banevent",[y,m]),n(3,a="Event banned successfully"),n(4,c="success"),n(12,y=""),n(13,m=""),await L()}catch(e){console.error("Failed to ban event:",e)}},async function(){if(v)try{await R("allowevent",[v,w]),n(3,a="Event allowed successfully"),n(4,c="success"),n(14,v=""),n(15,w="")}catch(e){console.error("Failed to allow event:",e)}},async function(){if(k)try{await R("blockip",[k,x]),n(3,a="IP blocked successfully"),n(4,c="success"),n(17,k=""),n(18,x=""),await P()}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,c="error");try{await R("allowkind",[e]),n(3,a="Kind allowed successfully"),n(4,c="success"),n(20,C=""),await B()}catch(e){console.error("Failed to allow kind:",e)}},U,async function(){try{n(2,s=!0),n(3,a="");const e=[];if(T.relay_name&&e.push(R("changerelayname",[T.relay_name])),T.relay_description&&e.push(R("changerelaydescription",[T.relay_description])),T.relay_icon&&e.push(R("changerelayicon",[T.relay_icon])),0===e.length)return n(3,a="No changes to update"),void n(4,c="info");await Promise.all(e),n(3,a="Relay configuration updated successfully"),n(4,c="success"),await _()}catch(e){console.error("Failed to update relay configuration:",e),n(3,a=`Failed to update relay configuration: ${e.message}`),n(4,c="error")}finally{n(2,s=!1)}},M,F,r,o,()=>n(1,i="pubkeys"),()=>n(1,i="events"),()=>n(1,i="ips"),()=>n(1,i="kinds"),()=>{n(1,i="moderation"),A&&0!==A.length||N()},()=>n(1,i="relay"),function(){u=this.value,n(6,u)},function(){d=this.value,n(7,d)},function(){h=this.value,n(9,h)},function(){p=this.value,n(10,p)},function(){y=this.value,n(12,y)},function(){m=this.value,n(13,m)},function(){v=this.value,n(14,v)},function(){w=this.value,n(15,w)},function(){k=this.value,n(17,k)},function(){x=this.value,n(18,x)},function(){C=b(this.value),n(20,C)},e=>U(e),e=>M(e.id),e=>F(e.id),function(){T.relay_name=this.value,n(0,T)},function(){T.relay_description=this.value,n(0,T)},function(){T.relay_icon=this.value,n(0,T)}]}class vp extends ee{constructor(e){super(),X(this,e,mp,yp,i,{userSigner:35,userPubkey:36},null,[-1,-1,-1])}}function wp(e){let t,n,r,o=e[3]&&e[4]&&Ep(e);return{c(){t=h("div"),n=h("span"),r=p("ORLY? dashboard\n "),o&&o.c(),w(n,"class","app-title svelte-1mrm2k6"),w(t,"class","header-title svelte-1mrm2k6")},m(e,i){u(e,t,i),l(t,n),l(n,r),o&&o.m(n,null)},p(e,t){e[3]&&e[4]?o?o.p(e,t):(o=Ep(e),o.c(),o.m(n,null)):o&&(o.d(1),o=null)},d(e){e&&d(t),o&&o.d()}}}function bp(e){let t,n,o,i;return{c(){t=h("div"),n=h("input"),w(n,"type","text"),w(n,"class","search-input svelte-1mrm2k6"),w(n,"placeholder","Search..."),w(t,"class","search-input-container svelte-1mrm2k6")},m(r,s){u(r,t,s),l(t,n),k(n,e[0]),o||(i=[m(n,"input",e[13]),m(n,"keydown",e[8])],o=!0)},p(e,t){1&t&&n.value!==e[0]&&k(n,e[0])},d(e){e&&d(t),o=!1,r(i)}}}function Ep(e){let t,n;return{c(){t=h("span"),n=p(e[5]),w(t,"class","permission-badge svelte-1mrm2k6")},m(e,r){u(e,t,r),l(t,n)},p(e,t){32&t&&E(n,e[5])},d(e){e&&d(t)}}}function kp(t){let n,r,o;return{c(){n=h("button"),n.textContent="Log in",w(n,"class","login-btn svelte-1mrm2k6")},m(e,i){u(e,n,i),r||(o=m(n,"click",t[12]),r=!0)},p:e,d(e){e&&d(n),r=!1,o()}}}function xp(e){let t,n,r,o,i,s,a=(e[6]?.name||e[7].slice(0,8)+"...")+"";function c(e,t){return e[6]?.picture?Cp:Sp}let f=c(e),y=f(e);return{c(){t=h("button"),y.c(),n=g(),r=h("span"),o=p(a),w(r,"class","user-name svelte-1mrm2k6"),w(t,"class","user-profile-btn svelte-1mrm2k6")},m(a,c){u(a,t,c),y.m(t,null),l(t,n),l(t,r),l(r,o),i||(s=m(t,"click",e[11]),i=!0)},p(e,r){f===(f=c(e))&&y?y.p(e,r):(y.d(1),y=f(e),y&&(y.c(),y.m(t,n))),192&r&&a!==(a=(e[6]?.name||e[7].slice(0,8)+"...")+"")&&E(o,a)},d(e){e&&d(t),y.d(),i=!1,s()}}}function Sp(t){let n;return{c(){n=h("div"),n.textContent="👤",w(n,"class","user-avatar-placeholder svelte-1mrm2k6")},m(e,t){u(e,n,t)},p:e,d(e){e&&d(n)}}}function Cp(e){let t,n;return{c(){t=h("img"),a(t.src,n=e[6].picture)||w(t,"src",n),w(t,"alt","User avatar"),w(t,"class","user-avatar svelte-1mrm2k6")},m(e,n){u(e,t,n)},p(e,r){64&r&&!a(t.src,n=e[6].picture)&&w(t,"src",n)},d(e){e&&d(t)}}}function Ap(t){let n,o,i,s,c,f,y,v,b,k,x,C,A,$,T=t[1]?"☀️":"🌙";function I(e,t){return e[2]?bp:wp}let _=I(t),R=_(t);function j(e,t){return e[3]?xp:kp}let O=j(t),L=O(t);return{c(){n=h("header"),o=h("div"),i=h("img"),c=g(),R.c(),f=g(),y=h("div"),v=h("button"),v.textContent="🔍",b=g(),k=h("button"),x=p(T),C=g(),L.c(),a(i.src,s="/orly.png")||w(i,"src","/orly.png"),w(i,"alt","ORLY Logo"),w(i,"class","logo svelte-1mrm2k6"),w(v,"class","search-btn svelte-1mrm2k6"),w(k,"class","theme-toggle-btn svelte-1mrm2k6"),w(y,"class","header-buttons svelte-1mrm2k6"),w(o,"class","header-content svelte-1mrm2k6"),w(n,"class","main-header svelte-1mrm2k6"),S(n,"dark-theme",t[1])},m(e,r){u(e,n,r),l(n,o),l(o,i),l(o,c),R.m(o,null),l(o,f),l(o,y),l(y,v),l(y,b),l(y,k),l(k,x),l(y,C),L.m(y,null),A||($=[m(v,"click",t[9]),m(k,"click",t[10])],A=!0)},p(e,[t]){_===(_=I(e))&&R?R.p(e,t):(R.d(1),R=_(e),R&&(R.c(),R.m(o,f))),2&t&&T!==(T=e[1]?"☀️":"🌙")&&E(x,T),O===(O=j(e))&&L?L.p(e,t):(L.d(1),L=O(e),L&&(L.c(),L.m(y,null))),2&t&&S(n,"dark-theme",e[1])},i:e,o:e,d(e){e&&d(n),R.d(),L.d(),A=!1,r($)}}}function $p(e,t,n){let{isDarkTheme:r=!1}=t,{isSearchMode:o=!1}=t,{searchQuery:i=""}=t,{isLoggedIn:s=!1}=t,{userRole:a=""}=t,{currentEffectiveRole:c=""}=t,{userProfile:l=null}=t,{userPubkey:u=""}=t;const d=T();return e.$$set=e=>{"isDarkTheme"in e&&n(1,r=e.isDarkTheme),"isSearchMode"in e&&n(2,o=e.isSearchMode),"searchQuery"in e&&n(0,i=e.searchQuery),"isLoggedIn"in e&&n(3,s=e.isLoggedIn),"userRole"in e&&n(4,a=e.userRole),"currentEffectiveRole"in e&&n(5,c=e.currentEffectiveRole),"userProfile"in e&&n(6,l=e.userProfile),"userPubkey"in e&&n(7,u=e.userPubkey)},[i,r,o,s,a,c,l,u,function(e){d("searchKeydown",e)},function(){d("toggleSearchMode")},function(){d("toggleTheme")},function(){d("openSettingsDrawer")},function(){d("openLoginModal")},function(){i=this.value,n(0,i)}]}class Tp extends ee{constructor(e){super(),X(this,e,$p,Ap,i,{isDarkTheme:1,isSearchMode:2,searchQuery:0,isLoggedIn:3,userRole:4,currentEffectiveRole:5,userProfile:6,userPubkey:7})}}function Ip(e,t,n){const r=e.slice();return r[9]=t[n],r}function _p(e){let t,n,o;function i(){return e[5](e[9])}function s(...t){return e[6](e[9],...t)}return{c(){t=h("span"),t.textContent="✕",w(t,"class","tab-close-icon svelte-1tm0fmz"),w(t,"role","button"),w(t,"tabindex","0")},m(e,r){u(e,t,r),n||(o=[m(t,"click",v(i)),m(t,"keydown",s)],n=!0)},p(t,n){e=t},d(e){e&&d(t),n=!1,r(o)}}}function Rp(e){let t,n,r,o,i,s,a,c,f,y,v=e[9].icon+"",b=e[9].label+"",k=e[9].isSearchTab&&_p(e);function x(){return e[7](e[9])}return{c(){t=h("button"),n=h("span"),r=p(v),o=g(),i=h("span"),s=p(b),a=g(),k&&k.c(),c=g(),w(n,"class","tab-icon svelte-1tm0fmz"),w(i,"class","tab-label svelte-1tm0fmz"),w(t,"class","tab svelte-1tm0fmz"),S(t,"active",e[2]===e[9].id)},m(e,d){u(e,t,d),l(t,n),l(n,r),l(t,o),l(t,i),l(i,s),l(t,a),k&&k.m(t,null),l(t,c),f||(y=m(t,"click",x),f=!0)},p(n,o){e=n,2&o&&v!==(v=e[9].icon+"")&&E(r,v),2&o&&b!==(b=e[9].label+"")&&E(s,b),e[9].isSearchTab?k?k.p(e,o):(k=_p(e),k.c(),k.m(t,c)):k&&(k.d(1),k=null),6&o&&S(t,"active",e[2]===e[9].id)},d(e){e&&d(t),k&&k.d(),f=!1,y()}}}function jp(t){let n,r,o,i=t[1],s=[];for(let e=0;e<i.length;e+=1)s[e]=Rp(Ip(t,i,e));return{c(){n=h("aside"),r=h("div"),o=h("div");for(let e=0;e<s.length;e+=1)s[e].c();w(o,"class","tabs svelte-1tm0fmz"),w(r,"class","sidebar-content svelte-1tm0fmz"),w(n,"class","sidebar svelte-1tm0fmz"),S(n,"dark-theme",t[0])},m(e,t){u(e,n,t),l(n,r),l(r,o);for(let e=0;e<s.length;e+=1)s[e]&&s[e].m(o,null)},p(e,[t]){if(30&t){let n;for(i=e[1],n=0;n<i.length;n+=1){const r=Ip(e,i,n);s[n]?s[n].p(r,t):(s[n]=Rp(r),s[n].c(),s[n].m(o,null))}for(;n<s.length;n+=1)s[n].d(1);s.length=i.length}1&t&&S(n,"dark-theme",e[0])},i:e,o:e,d(e){e&&d(n),f(s,e)}}}function Op(e,t,n){let{isDarkTheme:r=!1}=t,{tabs:o=[]}=t,{selectedTab:i=""}=t;const s=T();function a(e){s("selectTab",e)}function c(e){s("closeSearchTab",e)}return e.$$set=e=>{"isDarkTheme"in e&&n(0,r=e.isDarkTheme),"tabs"in e&&n(1,o=e.tabs),"selectedTab"in e&&n(2,i=e.selectedTab)},[r,o,i,a,c,e=>c(e.id),(e,t)=>"Enter"===t.key&&c(e.id),e=>a(e.id)]}class Lp extends ee{constructor(e){super(),X(this,e,Op,jp,i,{isDarkTheme:0,tabs:1,selectedTab:2})}}function Pp(t){let n,r,o,i,s,a;return{c(){n=h("div"),r=h("p"),r.textContent="Please log in to access export functionality.",o=g(),i=h("button"),i.textContent="Log In",w(r,"class","svelte-1qkvicp"),w(i,"class","login-btn svelte-1qkvicp"),w(n,"class","login-prompt svelte-1qkvicp")},m(e,c){u(e,n,c),l(n,r),l(n,o),l(n,i),s||(a=m(i,"click",t[4]),s=!0)},p:e,d(e){e&&d(n),s=!1,a()}}}function Bp(e){let t,n,r,o,i,s,a,c,f,p,v=("admin"===e[1]||"owner"===e[1])&&Np(e);return{c(){t=h("div"),n=h("h3"),n.textContent="Export My Events",r=g(),o=h("p"),o.textContent="Download your personal events as a JSONL file.",i=g(),s=h("button"),s.textContent="📤 Export My Events",a=g(),v&&v.c(),c=y(),w(n,"class","svelte-1qkvicp"),w(o,"class","svelte-1qkvicp"),w(s,"class","export-btn svelte-1qkvicp"),w(t,"class","export-section svelte-1qkvicp")},m(d,h){u(d,t,h),l(t,n),l(t,r),l(t,o),l(t,i),l(t,s),u(d,a,h),v&&v.m(d,h),u(d,c,h),f||(p=m(s,"click",e[2]),f=!0)},p(e,t){"admin"===e[1]||"owner"===e[1]?v?v.p(e,t):(v=Np(e),v.c(),v.m(c.parentNode,c)):v&&(v.d(1),v=null)},d(e){e&&d(t),e&&d(a),v&&v.d(e),e&&d(c),f=!1,p()}}}function Np(t){let n,r,o,i,s,a,c,f;return{c(){n=h("div"),r=h("h3"),r.textContent="Export All Events",o=g(),i=h("p"),i.textContent="Download the complete database as a JSONL file. This includes\n all events from all users.",s=g(),a=h("button"),a.textContent="📤 Export All Events",w(r,"class","svelte-1qkvicp"),w(i,"class","svelte-1qkvicp"),w(a,"class","export-btn svelte-1qkvicp"),w(n,"class","export-section svelte-1qkvicp")},m(e,d){u(e,n,d),l(n,r),l(n,o),l(n,i),l(n,s),l(n,a),c||(f=m(a,"click",t[3]),c=!0)},p:e,d(e){e&&d(n),c=!1,f()}}}function Up(t){let n;function r(e,t){return e[0]?Bp:Pp}let o=r(t),i=o(t);return{c(){i.c(),n=y()},m(e,t){i.m(e,t),u(e,n,t)},p(e,[t]){o===(o=r(e))&&i?i.p(e,t):(i.d(1),i=o(e),i&&(i.c(),i.m(n.parentNode,n)))},i:e,o:e,d(e){i.d(e),e&&d(n)}}}function Mp(e,t,n){let{isLoggedIn:r=!1}=t,{currentEffectiveRole:o=""}=t;const i=T();return e.$$set=e=>{"isLoggedIn"in e&&n(0,r=e.isLoggedIn),"currentEffectiveRole"in e&&n(1,o=e.currentEffectiveRole)},[r,o,function(){i("exportMyEvents")},function(){i("exportAllEvents")},function(){i("openLoginModal")}]}class Fp extends ee{constructor(e){super(),X(this,e,Mp,Up,i,{isLoggedIn:0,currentEffectiveRole:1})}}function Dp(t){let n,r,o,i,s,a,c,f;return{c(){n=h("div"),r=h("h3"),r.textContent="Import Events",o=g(),i=h("p"),i.textContent="Please log in to access import functionality.",s=g(),a=h("button"),a.textContent="Log In",w(r,"class","recovery-header svelte-1nvu2m9"),w(i,"class","recovery-description svelte-1nvu2m9"),w(a,"class","login-btn svelte-1nvu2m9"),w(n,"class","login-prompt svelte-1nvu2m9")},m(e,d){u(e,n,d),l(n,r),l(n,o),l(n,i),l(n,s),l(n,a),c||(f=m(a,"click",t[5]),c=!0)},p:e,d(e){e&&d(n),c=!1,f()}}}function Hp(t){let n;return{c(){n=h("div"),n.innerHTML='<h3 class="recovery-header svelte-1nvu2m9">Import Events</h3> \n <p class="recovery-description svelte-1nvu2m9">❌ Admin or owner permission required for import functionality.</p>',w(n,"class","permission-denied svelte-1nvu2m9")},m(e,t){u(e,n,t)},p:e,d(e){e&&d(n)}}}function qp(e){let t,n,o,i,s,a,c,f,y,v,b,E;return{c(){t=h("h3"),t.textContent="Import Events",n=g(),o=h("p"),o.textContent="Upload a JSONL file to import events into the database.",i=g(),s=h("div"),a=h("input"),c=g(),f=h("button"),y=p("Import Events"),w(t,"class","svelte-1nvu2m9"),w(o,"class","svelte-1nvu2m9"),w(a,"type","file"),w(a,"id","import-file"),w(a,"accept",".jsonl,.txt"),w(a,"class","svelte-1nvu2m9"),w(f,"class","import-btn svelte-1nvu2m9"),f.disabled=v=!e[2],w(s,"class","recovery-controls-card svelte-1nvu2m9")},m(r,d){u(r,t,d),u(r,n,d),u(r,o,d),u(r,i,d),u(r,s,d),l(s,a),l(s,c),l(s,f),l(f,y),b||(E=[m(a,"change",e[3]),m(f,"click",e[4])],b=!0)},p(e,t){4&t&&v!==(v=!e[2])&&(f.disabled=v)},d(e){e&&d(t),e&&d(n),e&&d(o),e&&d(i),e&&d(s),b=!1,r(E)}}}function zp(t){let n;function r(e,t){return!e[0]||"admin"!==e[1]&&"owner"!==e[1]?e[0]?Hp:Dp:qp}let o=r(t),i=o(t);return{c(){n=h("div"),i.c(),w(n,"class","import-section svelte-1nvu2m9")},m(e,t){u(e,n,t),i.m(n,null)},p(e,[t]){o===(o=r(e))&&i?i.p(e,t):(i.d(1),i=o(e),i&&(i.c(),i.m(n,null)))},i:e,o:e,d(e){e&&d(n),i.d()}}}function Kp(e,t,n){let{isLoggedIn:r=!1}=t,{currentEffectiveRole:o=""}=t,{selectedFile:i=null}=t;const s=T();return e.$$set=e=>{"isLoggedIn"in e&&n(0,r=e.isLoggedIn),"currentEffectiveRole"in e&&n(1,o=e.currentEffectiveRole),"selectedFile"in e&&n(2,i=e.selectedFile)},[r,o,i,function(e){s("fileSelect",e)},function(){s("importEvents")},function(){s("openLoginModal")}]}class Wp extends ee{constructor(e){super(),X(this,e,Kp,zp,i,{isLoggedIn:0,currentEffectiveRole:1,selectedFile:2})}}function Vp(e,t,n){const r=e.slice();return r[22]=t[n],r}function Jp(e,t,n){const r=e.slice();return r[25]=t[n],r}function Gp(t){let n;return{c(){n=h("div"),n.innerHTML="<p>❌ Read, write, admin, or owner permission required to view all\n events.</p>",w(n,"class","permission-denied svelte-kvggf0")},m(e,t){u(e,n,t)},p:e,d(e){e&&d(n)}}}function Zp(e){let t,n,r,o;function i(e,t){return e[4].length>0?Yp:e[6]?void 0:Qp}let s=i(e),a=s&&s(e),c=e[6]&&sg();return{c(){t=h("div"),a&&a.c(),n=g(),c&&c.c(),w(t,"class","events-view-content svelte-kvggf0")},m(i,s){u(i,t,s),a&&a.m(t,null),l(t,n),c&&c.m(t,null),r||(o=m(t,"scroll",e[7]),r=!0)},p(e,r){s===(s=i(e))&&a?a.p(e,r):(a&&a.d(1),a=s&&s(e),a&&(a.c(),a.m(t,n))),e[6]?c||(c=sg(),c.c(),c.m(t,null)):c&&(c.d(1),c=null)},d(e){e&&d(t),a&&a.d(),c&&c.d(),r=!1,o()}}}function Qp(t){let n;return{c(){n=h("div"),n.innerHTML="<p>No events found.</p>",w(n,"class","no-events svelte-kvggf0")},m(e,t){u(e,n,t)},p:e,d(e){e&&d(n)}}}function Yp(e){let t,n=e[4],r=[];for(let t=0;t<n.length;t+=1)r[t]=ig(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,o){if(1852&o){let i;for(n=e[4],i=0;i<n.length;i+=1){const s=Vp(e,n,i);r[i]?r[i].p(s,o):(r[i]=ig(s),r[i].c(),r[i].m(t.parentNode,t))}for(;i<r.length;i+=1)r[i].d(1);r.length=n.length}},d(e){f(r,e),e&&d(t)}}}function Xp(e){let t,n,r=pg(e[22].content)+"";return{c(){t=h("div"),n=p(r),w(t,"class","event-content-single-line svelte-kvggf0")},m(e,r){u(e,t,r),l(t,n)},p(e,t){16&t&&r!==(r=pg(e[22].content)+"")&&E(n,r)},d(e){e&&d(t)}}}function eg(e){let t,n,r,o=e[22].tags&&e[22].tags.length>0&&tg(e);return{c(){t=h("div"),n=h("span"),n.textContent="🗑️ Delete Event",r=g(),o&&o.c(),w(n,"class","delete-event-label svelte-kvggf0"),w(t,"class","delete-event-info svelte-kvggf0")},m(e,i){u(e,t,i),l(t,n),l(t,r),o&&o.m(t,null)},p(e,n){e[22].tags&&e[22].tags.length>0?o?o.p(e,n):(o=tg(e),o.c(),o.m(t,null)):o&&(o.d(1),o=null)},d(e){e&&d(t),o&&o.d()}}}function tg(e){let t,n=e[22].tags.filter(gg),r=[];for(let t=0;t<n.length;t+=1)r[t]=ng(Jp(e,n,t));return{c(){t=h("div");for(let e=0;e<r.length;e+=1)r[e].c();w(t,"class","delete-targets svelte-kvggf0")},m(e,n){u(e,t,n);for(let e=0;e<r.length;e+=1)r[e]&&r[e].m(t,null)},p(e,o){if(16&o){let i;for(n=e[22].tags.filter(gg),i=0;i<n.length;i+=1){const s=Jp(e,n,i);r[i]?r[i].p(s,o):(r[i]=ng(s),r[i].c(),r[i].m(t,null))}for(;i<r.length;i+=1)r[i].d(1);r.length=n.length}},d(e){e&&d(t),f(r,e)}}}function ng(e){let t,n,r,o,i,s=e[25][1].slice(0,8)+"",a=e[25][1].slice(-8)+"";return{c(){t=h("span"),n=p("Target: "),r=p(s),o=p("..."),i=p(a),w(t,"class","delete-target svelte-kvggf0")},m(e,s){u(e,t,s),l(t,n),l(t,r),l(t,o),l(t,i)},p(e,t){16&t&&s!==(s=e[25][1].slice(0,8)+"")&&E(r,s),16&t&&a!==(a=e[25][1].slice(-8)+"")&&E(i,a)},d(e){e&&d(t)}}}function rg(e){let t,n,r;function o(){return e[13](e[22])}return{c(){t=h("button"),t.textContent="🗑️",w(t,"class","delete-btn svelte-kvggf0")},m(e,i){u(e,t,i),n||(r=m(t,"click",v(o)),n=!0)},p(t,n){e=t},d(e){e&&d(t),n=!1,r()}}}function og(e){let t,n,r,o,i,s,a,c,f=JSON.stringify(e[22],null,2)+"";function y(...t){return e[16](e[22],...t)}return{c(){t=h("div"),n=h("div"),r=h("pre"),o=p(f),i=g(),s=h("button"),s.textContent="📋",w(r,"class","event-json svelte-kvggf0"),w(s,"class","copy-json-btn svelte-kvggf0"),w(s,"title","Copy minified JSON to clipboard"),w(n,"class","json-container svelte-kvggf0"),w(t,"class","events-view-details svelte-kvggf0")},m(e,d){u(e,t,d),l(t,n),l(n,r),l(r,o),l(n,i),l(n,s),a||(c=m(s,"click",v(y)),a=!0)},p(t,n){e=t,16&n&&f!==(f=JSON.stringify(e[22],null,2)+"")&&E(o,f)},d(e){e&&d(t),a=!1,c()}}}function ig(e){let t,n,o,i,s,a,c,f,y,v,b,k,x,C,A,$,T,I,_,R,j,O,L,P,B=dg(e[22].pubkey)+"",N=e[22].kind+"",U=fg(e[22].kind)+"",M=hg(e[22].created_at)+"",F=e[5].has(e[22].id);function D(e,t){return 5===e[22].kind?eg:Xp}let H=D(e),q=H(e),z=5!==e[22].kind&&("admin"===e[2]||"owner"===e[2]||"write"===e[2]&&e[22].pubkey&&e[22].pubkey===e[3])&&rg(e);function K(){return e[14](e[22])}function W(...t){return e[15](e[22],...t)}let V=F&&og(e);return{c(){t=h("div"),n=h("div"),o=h("div"),o.innerHTML='<div class="avatar-placeholder svelte-kvggf0">👤</div>',i=g(),s=h("div"),a=h("div"),c=p(B),f=g(),y=h("div"),v=h("span"),b=p(N),k=g(),x=h("span"),C=p(U),A=g(),$=h("div"),T=h("div"),I=p(M),_=g(),q.c(),R=g(),z&&z.c(),j=g(),V&&V.c(),O=g(),w(o,"class","events-view-avatar svelte-kvggf0"),w(a,"class","events-view-author svelte-kvggf0"),w(v,"class","kind-number svelte-kvggf0"),S(v,"delete-event",5===e[22].kind),w(x,"class","kind-name svelte-kvggf0"),w(y,"class","events-view-kind svelte-kvggf0"),w(s,"class","events-view-info svelte-kvggf0"),w(T,"class","event-timestamp svelte-kvggf0"),w($,"class","events-view-content svelte-kvggf0"),w(n,"class","events-view-row svelte-kvggf0"),w(n,"role","button"),w(n,"tabindex","0"),w(t,"class","events-view-item svelte-kvggf0"),S(t,"expanded",e[5].has(e[22].id))},m(e,r){u(e,t,r),l(t,n),l(n,o),l(n,i),l(n,s),l(s,a),l(a,c),l(s,f),l(s,y),l(y,v),l(v,b),l(y,k),l(y,x),l(x,C),l(n,A),l(n,$),l($,T),l(T,I),l($,_),q.m($,null),l(n,R),z&&z.m(n,null),l(t,j),V&&V.m(t,null),l(t,O),L||(P=[m(n,"click",K),m(n,"keydown",W)],L=!0)},p(r,o){e=r,16&o&&B!==(B=dg(e[22].pubkey)+"")&&E(c,B),16&o&&N!==(N=e[22].kind+"")&&E(b,N),16&o&&S(v,"delete-event",5===e[22].kind),16&o&&U!==(U=fg(e[22].kind)+"")&&E(C,U),16&o&&M!==(M=hg(e[22].created_at)+"")&&E(I,M),H===(H=D(e))&&q?q.p(e,o):(q.d(1),q=H(e),q&&(q.c(),q.m($,null))),5!==e[22].kind&&("admin"===e[2]||"owner"===e[2]||"write"===e[2]&&e[22].pubkey&&e[22].pubkey===e[3])?z?z.p(e,o):(z=rg(e),z.c(),z.m(n,null)):z&&(z.d(1),z=null),48&o&&(F=e[5].has(e[22].id)),F?V?V.p(e,o):(V=og(e),V.c(),V.m(t,O)):V&&(V.d(1),V=null),48&o&&S(t,"expanded",e[5].has(e[22].id))},d(e){e&&d(t),q.d(),z&&z.d(),V&&V.d(),L=!1,r(P)}}}function sg(e){let t;return{c(){t=h("div"),t.innerHTML='<div class="spinner svelte-kvggf0"></div> \n <p>Loading events...</p>',w(t,"class","loading-events svelte-kvggf0")},m(e,n){u(e,t,n)},d(e){e&&d(t)}}}function ag(e){let t,n,o,i,s,a,c,f,y,v,b,E,k,x,S,C;function A(e,t){return e[6]?lg:cg}let $=A(e),T=$(e);return{c(){t=h("div"),n=h("div"),o=h("label"),i=h("input"),s=g(),a=h("span"),c=g(),f=h("span"),f.textContent="Only show my events",y=g(),v=h("div"),b=h("button"),E=p("🔄 Load More"),k=g(),x=h("button"),T.c(),w(i,"type","checkbox"),w(i,"class","svelte-kvggf0"),w(a,"class","toggle-slider svelte-kvggf0"),w(f,"class","toggle-label svelte-kvggf0"),w(o,"class","toggle-container svelte-kvggf0"),w(n,"class","events-view-toggle svelte-kvggf0"),w(b,"class","refresh-btn svelte-kvggf0"),b.disabled=e[6],w(x,"class","reload-btn svelte-kvggf0"),x.disabled=e[6],w(v,"class","events-view-buttons svelte-kvggf0"),w(t,"class","events-view-header svelte-kvggf0")},m(r,d){u(r,t,d),l(t,n),l(n,o),l(o,i),i.checked=e[0],l(o,s),l(o,a),l(o,c),l(o,f),l(t,y),l(t,v),l(v,b),l(b,E),l(v,k),l(v,x),T.m(x,null),S||(C=[m(i,"change",e[17]),m(i,"change",e[18]),m(b,"click",e[19]),m(x,"click",e[20])],S=!0)},p(e,t){1&t&&(i.checked=e[0]),64&t&&(b.disabled=e[6]),$!==($=A(e))&&(T.d(1),T=$(e),T&&(T.c(),T.m(x,null))),64&t&&(x.disabled=e[6])},d(e){e&&d(t),T.d(),S=!1,r(C)}}}function cg(e){let t;return{c(){t=p("🔄")},m(e,n){u(e,t,n)},d(e){e&&d(t)}}}function lg(e){let t;return{c(){t=h("div"),w(t,"class","spinner svelte-kvggf0")},m(e,n){u(e,t,n)},d(e){e&&d(t)}}}function ug(t){let n,r;function o(e,t){return!e[1]||"read"!==e[2]&&"write"!==e[2]&&"admin"!==e[2]&&"owner"!==e[2]?Gp:Zp}let i=o(t),s=i(t),a=t[1]&&("read"===t[2]||"write"===t[2]||"admin"===t[2]||"owner"===t[2])&&ag(t);return{c(){n=h("div"),s.c(),r=g(),a&&a.c(),w(n,"class","events-view-container svelte-kvggf0")},m(e,t){u(e,n,t),s.m(n,null),l(n,r),a&&a.m(n,null)},p(e,[t]){i===(i=o(e))&&s?s.p(e,t):(s.d(1),s=i(e),s&&(s.c(),s.m(n,r))),!e[1]||"read"!==e[2]&&"write"!==e[2]&&"admin"!==e[2]&&"owner"!==e[2]?a&&(a.d(1),a=null):a?a.p(e,t):(a=ag(e),a.c(),a.m(n,null))},i:e,o:e,d(e){e&&d(n),s.d(),a&&a.d()}}}function dg(e){return e?e.slice(0,8)+"..."+e.slice(-8):""}function fg(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 hg(e){return new Date(1e3*e).toLocaleString()}function pg(e){return e?e.length>100?e.slice(0,100)+"...":e:""}const gg=e=>"e"===e[0];function yg(e,t,n){let{isLoggedIn:r=!1}=t,{userRole:o=""}=t,{userPubkey:i=""}=t,{filteredEvents:s=[]}=t,{expandedEvents:a=new Set}=t,{isLoadingEvents:c=!1}=t,{showOnlyMyEvents:l=!1}=t;const u=T();function d(e){u("toggleEventExpansion",e)}function f(e){u("deleteEvent",e)}function h(e,t){u("copyEventToClipboard",{event:e,e:t})}function p(){u("toggleChange")}function g(e,t){u("loadAllEvents",{refresh:e,authors:t})}return e.$$set=e=>{"isLoggedIn"in e&&n(1,r=e.isLoggedIn),"userRole"in e&&n(2,o=e.userRole),"userPubkey"in e&&n(3,i=e.userPubkey),"filteredEvents"in e&&n(4,s=e.filteredEvents),"expandedEvents"in e&&n(5,a=e.expandedEvents),"isLoadingEvents"in e&&n(6,c=e.isLoadingEvents),"showOnlyMyEvents"in e&&n(0,l=e.showOnlyMyEvents)},[l,r,o,i,s,a,c,function(e){u("scroll",e)},d,f,h,p,g,e=>f(e.id),e=>d(e.id),(e,t)=>"Enter"===t.key&&d(e.id),(e,t)=>h(e,t),function(){l=this.checked,n(0,l)},()=>p(),()=>{g(!1,l&&i?[i]:null)},()=>{g(!0,l&&i?[i]:null)}]}class mg extends ee{constructor(e){super(),X(this,e,yg,ug,i,{isLoggedIn:1,userRole:2,userPubkey:3,filteredEvents:4,expandedEvents:5,isLoadingEvents:6,showOnlyMyEvents:0})}}function vg(t){let n,o,i,s,a,c,f,p,y,v,b,E;return{c(){n=h("div"),o=h("div"),i=h("button"),i.textContent="Reformat",s=g(),a=h("button"),a.textContent="Sign",c=g(),f=h("button"),f.textContent="Publish",p=g(),y=h("div"),v=h("textarea"),w(i,"class","compose-btn reformat-btn svelte-mkdcsl"),w(a,"class","compose-btn sign-btn svelte-mkdcsl"),w(f,"class","compose-btn publish-btn svelte-mkdcsl"),w(o,"class","compose-header svelte-mkdcsl"),w(v,"class","compose-textarea svelte-mkdcsl"),w(v,"placeholder","Enter your Nostr event JSON here..."),w(v,"spellcheck","false"),w(y,"class","compose-editor svelte-mkdcsl"),w(n,"class","compose-view svelte-mkdcsl")},m(e,r){u(e,n,r),l(n,o),l(o,i),l(o,s),l(o,a),l(o,c),l(o,f),l(n,p),l(n,y),l(y,v),k(v,t[0]),b||(E=[m(i,"click",t[1]),m(a,"click",t[2]),m(f,"click",t[3]),m(v,"input",t[4])],b=!0)},p(e,[t]){1&t&&k(v,e[0])},i:e,o:e,d(e){e&&d(n),b=!1,r(E)}}}function wg(e,t,n){let{composeEventJson:r=""}=t;const o=T();return e.$$set=e=>{"composeEventJson"in e&&n(0,r=e.composeEventJson)},[r,function(){o("reformatJson")},function(){o("signEvent")},function(){o("publishEvent")},function(){r=this.value,n(0,r)}]}class bg extends ee{constructor(e){super(),X(this,e,wg,vg,i,{composeEventJson:0})}}function Eg(e,t,n){const r=e.slice();return r[23]=t[n],r}function kg(t){let n,r,o,i,s,a;return{c(){n=h("div"),r=h("p"),r.textContent="Please log in to access sprocket management.",o=g(),i=h("button"),i.textContent="Log In",w(r,"class","svelte-fiaj1r"),w(i,"class","login-btn svelte-fiaj1r"),w(n,"class","login-prompt svelte-fiaj1r")},m(e,c){u(e,n,c),l(n,r),l(n,o),l(n,i),s||(a=m(i,"click",t[18]),s=!0)},p:e,d(e){e&&d(n),s=!1,a()}}}function xg(e){let t,n,r,o,i,s,a,c,f,y=(e[2]||"none")+"";return{c(){t=h("div"),n=h("p"),n.textContent="❌ Owner permission required for sprocket management.",r=g(),o=h("p"),o.innerHTML='To enable sprocket functionality, set the <code class="svelte-fiaj1r">ORLY_OWNERS</code> environment variable with your npub when starting the relay.',i=g(),s=h("p"),a=p("Current user role: "),c=h("strong"),f=p(y),w(n,"class","svelte-fiaj1r"),w(o,"class","svelte-fiaj1r"),w(s,"class","svelte-fiaj1r"),w(t,"class","permission-denied svelte-fiaj1r")},m(e,d){u(e,t,d),l(t,n),l(t,r),l(t,o),l(t,i),l(t,s),l(s,a),l(s,c),l(c,f)},p(e,t){4&t&&y!==(y=(e[2]||"none")+"")&&E(f,y)},d(e){e&&d(t)}}}function Sg(e){let t,n,o,i,s,a,c,y,v,b,x,C,A,$,T,I,_,R,j,O,L,P,B,N,U,M,F,D,H,q,z,K,W,V,J,G,Z,Q,Y,X,ee,te,ne,re,oe,ie,se,ae,ce,le,ue,de,fe,he,pe,ge,ye=e[3]?.is_running?"🟢 Running":"🔴 Stopped",me=e[3]?.script_exists?"✅ Exists":"❌ Not found",ve=e[3]?.pid&&Cg(e),we=e[6]&&Ag(e),be=e[8],Ee=[];for(let t=0;t<be.length;t+=1)Ee[t]=Ig(Eg(e,be,t));return{c(){t=h("div"),n=h("div"),o=h("h3"),o.textContent="Script Editor",i=g(),s=h("div"),a=h("button"),c=p("🔄 Restart"),y=g(),v=h("button"),b=p("🗑️ Delete Script"),C=g(),A=h("div"),$=h("h4"),$.textContent="Upload Script",T=g(),I=h("div"),_=h("input"),R=g(),j=h("button"),O=p("📤 Upload & Update"),P=g(),B=h("div"),N=h("div"),U=h("span"),U.textContent="Status:",M=g(),F=h("span"),D=p(ye),H=g(),ve&&ve.c(),q=g(),z=h("div"),K=h("span"),K.textContent="Script:",W=g(),V=h("span"),J=p(me),G=g(),Z=h("div"),Q=h("textarea"),Y=g(),X=h("div"),ee=h("button"),te=p("💾 Save & Update"),ne=g(),re=h("button"),oe=p("📥 Load Current"),ie=g(),we&&we.c(),se=g(),ae=h("div"),ce=h("h3"),ce.textContent="Script Versions",le=g(),ue=h("div");for(let e=0;e<Ee.length;e+=1)Ee[e].c();de=g(),fe=h("button"),he=p("🔄 Refresh Versions"),w(o,"class","svelte-fiaj1r"),w(a,"class","sprocket-btn restart-btn svelte-fiaj1r"),a.disabled=e[4],w(v,"class","sprocket-btn delete-btn svelte-fiaj1r"),v.disabled=x=e[4]||!e[3]?.script_exists,w(s,"class","sprocket-controls svelte-fiaj1r"),w(n,"class","sprocket-header svelte-fiaj1r"),w($,"class","svelte-fiaj1r"),w(_,"type","file"),w(_,"id","sprocket-upload-file"),w(_,"accept",".sh,.bash"),_.disabled=e[4],w(_,"class","svelte-fiaj1r"),w(j,"class","sprocket-btn upload-btn svelte-fiaj1r"),j.disabled=L=e[4]||!e[5],w(I,"class","upload-controls svelte-fiaj1r"),w(A,"class","sprocket-upload-section svelte-fiaj1r"),w(U,"class","status-label svelte-fiaj1r"),w(F,"class","status-value svelte-fiaj1r"),S(F,"running",e[3]?.is_running),w(N,"class","status-item svelte-fiaj1r"),w(K,"class","status-label svelte-fiaj1r"),w(V,"class","status-value svelte-fiaj1r"),w(z,"class","status-item svelte-fiaj1r"),w(B,"class","sprocket-status svelte-fiaj1r"),w(Q,"class","script-editor svelte-fiaj1r"),w(Q,"placeholder","#!/bin/bash # Enter your sprocket script here..."),Q.disabled=e[4],w(Z,"class","script-editor-container svelte-fiaj1r"),w(ee,"class","sprocket-btn save-btn svelte-fiaj1r"),ee.disabled=e[4],w(re,"class","sprocket-btn load-btn svelte-fiaj1r"),re.disabled=e[4],w(X,"class","script-actions svelte-fiaj1r"),w(t,"class","sprocket-section svelte-fiaj1r"),w(ue,"class","versions-list svelte-fiaj1r"),w(fe,"class","sprocket-btn refresh-btn svelte-fiaj1r"),fe.disabled=e[4],w(ae,"class","sprocket-section svelte-fiaj1r")},m(r,d){u(r,t,d),l(t,n),l(n,o),l(n,i),l(n,s),l(s,a),l(a,c),l(s,y),l(s,v),l(v,b),l(t,C),l(t,A),l(A,$),l(A,T),l(A,I),l(I,_),l(I,R),l(I,j),l(j,O),l(t,P),l(t,B),l(B,N),l(N,U),l(N,M),l(N,F),l(F,D),l(B,H),ve&&ve.m(B,null),l(B,q),l(B,z),l(z,K),l(z,W),l(z,V),l(V,J),l(t,G),l(t,Z),l(Z,Q),k(Q,e[0]),l(t,Y),l(t,X),l(X,ee),l(ee,te),l(X,ne),l(X,re),l(re,oe),l(t,ie),we&&we.m(t,null),u(r,se,d),u(r,ae,d),l(ae,ce),l(ae,le),l(ae,ue);for(let e=0;e<Ee.length;e+=1)Ee[e]&&Ee[e].m(ue,null);l(ae,de),l(ae,fe),l(fe,he),pe||(ge=[m(a,"click",e[9]),m(v,"click",e[10]),m(_,"change",e[11]),m(j,"click",e[12]),m(Q,"input",e[19]),m(ee,"click",e[13]),m(re,"click",e[14]),m(fe,"click",e[15])],pe=!0)},p(e,n){if(16&n&&(a.disabled=e[4]),24&n&&x!==(x=e[4]||!e[3]?.script_exists)&&(v.disabled=x),16&n&&(_.disabled=e[4]),48&n&&L!==(L=e[4]||!e[5])&&(j.disabled=L),8&n&&ye!==(ye=e[3]?.is_running?"🟢 Running":"🔴 Stopped")&&E(D,ye),8&n&&S(F,"running",e[3]?.is_running),e[3]?.pid?ve?ve.p(e,n):(ve=Cg(e),ve.c(),ve.m(B,q)):ve&&(ve.d(1),ve=null),8&n&&me!==(me=e[3]?.script_exists?"✅ Exists":"❌ Not found")&&E(J,me),16&n&&(Q.disabled=e[4]),1&n&&k(Q,e[0]),16&n&&(ee.disabled=e[4]),16&n&&(re.disabled=e[4]),e[6]?we?we.p(e,n):(we=Ag(e),we.c(),we.m(t,null)):we&&(we.d(1),we=null),196880&n){let t;for(be=e[8],t=0;t<be.length;t+=1){const r=Eg(e,be,t);Ee[t]?Ee[t].p(r,n):(Ee[t]=Ig(r),Ee[t].c(),Ee[t].m(ue,null))}for(;t<Ee.length;t+=1)Ee[t].d(1);Ee.length=be.length}16&n&&(fe.disabled=e[4])},d(e){e&&d(t),ve&&ve.d(),we&&we.d(),e&&d(se),e&&d(ae),f(Ee,e),pe=!1,r(ge)}}}function Cg(e){let t,n,r,o,i,s=e[3].pid+"";return{c(){t=h("div"),n=h("span"),n.textContent="PID:",r=g(),o=h("span"),i=p(s),w(n,"class","status-label svelte-fiaj1r"),w(o,"class","status-value svelte-fiaj1r"),w(t,"class","status-item svelte-fiaj1r")},m(e,s){u(e,t,s),l(t,n),l(t,r),l(t,o),l(o,i)},p(e,t){8&t&&s!==(s=e[3].pid+"")&&E(i,s)},d(e){e&&d(t)}}}function Ag(e){let t,n;return{c(){t=h("div"),n=p(e[6]),w(t,"class","sprocket-message svelte-fiaj1r"),S(t,"error","error"===e[7])},m(e,r){u(e,t,r),l(t,n)},p(e,r){64&r&&E(n,e[6]),128&r&&S(t,"error","error"===e[7])},d(e){e&&d(t)}}}function $g(e){let t;return{c(){t=h("span"),t.textContent="Current",w(t,"class","current-badge svelte-fiaj1r")},m(e,n){u(e,t,n)},d(e){e&&d(t)}}}function Tg(e){let t,n,r,o;function i(){return e[21](e[23])}return{c(){t=h("button"),n=p("🗑️ Delete"),w(t,"class","version-btn delete-btn svelte-fiaj1r"),t.disabled=e[4]},m(e,s){u(e,t,s),l(t,n),r||(o=m(t,"click",i),r=!0)},p(n,r){e=n,16&r&&(t.disabled=e[4])},d(e){e&&d(t),r=!1,o()}}}function Ig(e){let t,n,r,o,i,s,a,c,f,y,v,b,k,x,C,A,$=e[23].name+"",T=new Date(e[23].modified).toLocaleString()+"",I=e[23].is_current&&$g();function _(){return e[20](e[23])}let R=!e[23].is_current&&Tg(e);return{c(){t=h("div"),n=h("div"),r=h("div"),o=p($),i=g(),s=h("div"),a=p(T),c=g(),I&&I.c(),f=g(),y=h("div"),v=h("button"),b=p("📥 Load"),k=g(),R&&R.c(),x=g(),w(r,"class","version-name svelte-fiaj1r"),w(s,"class","version-date svelte-fiaj1r"),w(n,"class","version-info svelte-fiaj1r"),w(v,"class","version-btn load-btn svelte-fiaj1r"),v.disabled=e[4],w(y,"class","version-actions svelte-fiaj1r"),w(t,"class","version-item svelte-fiaj1r"),S(t,"current",e[23].is_current)},m(e,d){u(e,t,d),l(t,n),l(n,r),l(r,o),l(n,i),l(n,s),l(s,a),l(s,c),I&&I.m(s,null),l(t,f),l(t,y),l(y,v),l(v,b),l(y,k),R&&R.m(y,null),l(t,x),C||(A=m(v,"click",_),C=!0)},p(n,r){e=n,256&r&&$!==($=e[23].name+"")&&E(o,$),256&r&&T!==(T=new Date(e[23].modified).toLocaleString()+"")&&E(a,T),e[23].is_current?I||(I=$g(),I.c(),I.m(s,null)):I&&(I.d(1),I=null),16&r&&(v.disabled=e[4]),e[23].is_current?R&&(R.d(1),R=null):R?R.p(e,r):(R=Tg(e),R.c(),R.m(y,null)),256&r&&S(t,"current",e[23].is_current)},d(e){e&&d(t),I&&I.d(),R&&R.d(),C=!1,A()}}}function _g(t){let n,r,o;function i(e,t){return e[1]&&"owner"===e[2]?Sg:e[1]?xg:kg}let s=i(t),a=s(t);return{c(){n=h("div"),r=h("h2"),r.textContent="Sprocket Script Management",o=g(),a.c(),w(r,"class","svelte-fiaj1r"),w(n,"class","sprocket-view svelte-fiaj1r")},m(e,t){u(e,n,t),l(n,r),l(n,o),a.m(n,null)},p(e,[t]){s===(s=i(e))&&a?a.p(e,t):(a.d(1),a=s(e),a&&(a.c(),a.m(n,null)))},i:e,o:e,d(e){e&&d(n),a.d()}}}function Rg(e,t,n){let{isLoggedIn:r=!1}=t,{userRole:o=""}=t,{sprocketStatus:i=null}=t,{isLoadingSprocket:s=!1}=t,{sprocketUploadFile:a=null}=t,{sprocketScript:c=""}=t,{sprocketMessage:l=""}=t,{sprocketMessageType:u=""}=t,{sprocketVersions:d=[]}=t;const f=T();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,o=e.userRole),"sprocketStatus"in e&&n(3,i=e.sprocketStatus),"isLoadingSprocket"in e&&n(4,s=e.isLoadingSprocket),"sprocketUploadFile"in e&&n(5,a=e.sprocketUploadFile),"sprocketScript"in e&&n(0,c=e.sprocketScript),"sprocketMessage"in e&&n(6,l=e.sprocketMessage),"sprocketMessageType"in e&&n(7,u=e.sprocketMessageType),"sprocketVersions"in e&&n(8,d=e.sprocketVersions)},[c,r,o,i,s,a,l,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(){c=this.value,n(0,c)},e=>h(e),e=>p(e.name)]}class jg extends ee{constructor(e){super(),X(this,e,Rg,_g,i,{isLoggedIn:1,userRole:2,sprocketStatus:3,isLoadingSprocket:4,sprocketUploadFile:5,sprocketScript:0,sprocketMessage:6,sprocketMessageType:7,sprocketVersions:8})}}class Og{constructor(e,t,n){this.relayUrl=e,this.userSigner=t,this.userPubkey=n,this.ws=null,this.challenge=null,this.isAuthenticated=!1,this.authPromise=null}async connect(){return new Promise((e,t)=>{this.ws=new WebSocket(this.relayUrl),this.ws.onopen=()=>{console.log("WebSocket connected to relay:",this.relayUrl),e()},this.ws.onmessage=async e=>{try{const t=JSON.parse(e.data);await this.handleMessage(t)}catch(e){console.error("Error parsing relay message:",e)}},this.ws.onerror=e=>{console.error("WebSocket error:",e),t(new Error("Failed to connect to relay"))},this.ws.onclose=()=>{console.log("WebSocket connection closed"),this.isAuthenticated=!1,this.challenge=null},setTimeout(()=>{this.ws.readyState!==WebSocket.OPEN&&t(new Error("Connection timeout"))},1e4)})}async handleMessage(e){const[t,...n]=e;switch(t){case"AUTH":this.challenge=n[0],console.log("Received AUTH challenge:",this.challenge),await this.authenticate();break;case"OK":const[e,r,o]=n;e&&r?(console.log("Authentication successful for event:",e),this.isAuthenticated=!0,this.authPromise&&(this.authPromise.resolve(),this.authPromise=null)):e&&!r&&(console.error("Authentication failed:",o),this.authPromise&&(this.authPromise.reject(new Error(o||"Authentication failed")),this.authPromise=null));break;case"NOTICE":console.log("Relay notice:",n[0]);break;default:console.log("Unhandled message type:",t,n)}}async authenticate(){if(!this.challenge)throw new Error("No challenge received from relay");if(!this.userSigner)throw new Error("No signer available for authentication");try{const e={kind:22242,created_at:Math.floor(Date.now()/1e3),tags:[["relay",this.relayUrl],["challenge",this.challenge]],content:"",pubkey:this.userPubkey},t=["AUTH",await this.userSigner.signEvent(e)];return this.ws.send(JSON.stringify(t)),console.log("Sent authentication event to relay"),new Promise((e,t)=>{this.authPromise={resolve:e,reject:t},setTimeout(()=>{this.authPromise&&(this.authPromise.reject(new Error("Authentication timeout")),this.authPromise=null)},1e4)})}catch(e){throw console.error("Authentication error:",e),e}}async publishEvent(e){if(!this.ws||this.ws.readyState!==WebSocket.OPEN)throw new Error("WebSocket not connected");return new Promise((t,n)=>{const r=["EVENT",e];this.ws.send(JSON.stringify(r));const o=this.ws.onmessage,i=setTimeout(()=>{this.ws.onmessage=o,n(new Error("Publish timeout"))},15e3);this.ws.onmessage=async r=>{try{const s=JSON.parse(r.data),[a,c,l,u]=s;if("OK"===a&&c===e.id)if(clearTimeout(i),this.ws.onmessage=o,l)console.log("Event published successfully:",c),t({success:!0,eventId:c,reason:u});else{if(console.error("Event publish failed:",u),u&&u.includes("auth-required")){console.log("Authentication required, attempting to authenticate...");try{await this.authenticate();const t=["EVENT",e];return void this.ws.send(JSON.stringify(t))}catch(e){return void n(new Error(`Authentication failed: ${e.message}`))}}n(new Error(`Publish failed: ${u}`))}else await this.handleMessage(s)}catch(e){clearTimeout(i),this.ws.onmessage=o,n(e)}}})}close(){this.ws&&(this.ws.close(),this.ws=null),this.isAuthenticated=!1,this.challenge=null}getAuthenticated(){return this.isAuthenticated}}async function Lg(e,t,n,r){const o=new Og(e,n,r);try{await o.connect();return await o.publishEvent(t)}finally{o.close()}}function Pg(e,t,n){const r=e.slice();return r[148]=t[n],r}function Bg(e,t,n){const r=e.slice();return r[158]=t[n],r}function Ng(e,t,n){const r=e.slice();return r[151]=t[n],r}function Ug(e,t,n){const r=e.slice();r[151]=t[n];const o=r[44](r[151]);return r[152]=o,r}function Mg(e,t,n){const r=e.slice();return r[155]=t[n],r}function Fg(t){let n;function r(e,t){return e[1]?Zg:Gg}let o=r(t),i=o(t);return{c(){n=h("div"),i.c(),w(n,"class","welcome-message svelte-7marjm")},m(e,t){u(e,n,t),i.m(n,null)},p(e,t){o===(o=r(e))&&i?i.p(e,t):(i.d(1),i=o(e),i&&(i.c(),i.m(n,null)))},i:e,o:e,d(e){e&&d(n),i.d()}}}function Dg(t){let n,r=t[6],o=[];for(let e=0;e<r.length;e+=1)o[e]=iy(Bg(t,r,e));return{c(){for(let e=0;e<o.length;e+=1)o[e].c();n=y()},m(e,t){for(let n=0;n<o.length;n+=1)o[n]&&o[n].m(e,t);u(e,n,t)},p(e,t){if(131188&t[0]|180&t[1]|24&t[2]){let i;for(r=e[6],i=0;i<r.length;i+=1){const s=Bg(e,r,i);o[i]?o[i].p(s,t):(o[i]=iy(s),o[i].c(),o[i].m(n.parentNode,n))}for(;i<o.length;i+=1)o[i].d(1);o.length=r.length}},i:e,o:e,d(e){f(o,e),e&&d(n)}}}function Hg(t){let n,o,i,s,a,c,p,y,v,E,S,C,A,$,T,I,_,R,j=null!==t[26]&&void 0!==t[26]&&t[26]>=0||""!==t[27]&&parseInt(t[27])>=0,O=t[34],L=[];for(let e=0;e<O.length;e+=1)L[e]=sy(Mg(t,O,e));let P=j&&ay(t);return{c(){n=h("div"),o=h("div"),o.innerHTML='<h3 class="svelte-7marjm">Event Recovery</h3> \n <p class="svelte-7marjm">Search and recover old versions of replaceable events</p>',i=g(),s=h("div"),a=h("div"),c=h("div"),p=h("label"),p.textContent="Select Event Kind:",y=g(),v=h("select"),E=h("option"),E.textContent="Choose a replaceable kind...";for(let e=0;e<L.length;e+=1)L[e].c();S=g(),C=h("div"),A=h("label"),A.textContent="Or enter custom kind number:",$=g(),T=h("input"),I=g(),P&&P.c(),w(p,"for","recovery-kind"),w(p,"class","svelte-7marjm"),E.__value=null,E.value=E.__value,w(v,"id","recovery-kind"),w(v,"class","svelte-7marjm"),void 0===t[26]&&B(()=>t[98].call(v)),w(c,"class","kind-selector svelte-7marjm"),w(A,"for","custom-kind"),w(A,"class","svelte-7marjm"),w(T,"id","custom-kind"),w(T,"type","number"),w(T,"placeholder","e.g., 10001"),w(T,"min","0"),w(T,"class","svelte-7marjm"),w(C,"class","custom-kind-input svelte-7marjm"),w(a,"class","recovery-controls svelte-7marjm"),w(s,"class","recovery-controls-card svelte-7marjm"),w(n,"class","recovery-tab svelte-7marjm")},m(e,r){u(e,n,r),l(n,o),l(n,i),l(n,s),l(s,a),l(a,c),l(c,p),l(c,y),l(c,v),l(v,E);for(let e=0;e<L.length;e+=1)L[e]&&L[e].m(v,null);x(v,t[26],!0),l(a,S),l(a,C),l(C,A),l(C,$),l(C,T),k(T,t[27]),l(n,I),P&&P.m(n,null),_||(R=[m(v,"change",t[98]),m(v,"change",t[42]),m(T,"input",t[99]),m(T,"input",t[43])],_=!0)},p(e,t){if(8&t[1]){let n;for(O=e[34],n=0;n<O.length;n+=1){const r=Mg(e,O,n);L[n]?L[n].p(r,t):(L[n]=sy(r),L[n].c(),L[n].m(v,null))}for(;n<L.length;n+=1)L[n].d(1);L.length=O.length}67108864&t[0]|8&t[1]&&x(v,e[26]),134217728&t[0]&&b(T.value)!==e[27]&&k(T,e[27]),201326592&t[0]&&(j=null!==e[26]&&void 0!==e[26]&&e[26]>=0||""!==e[27]&&parseInt(e[27])>=0),j?P?P.p(e,t):(P=ay(e),P.c(),P.m(n,null)):P&&(P.d(1),P=null)},i:e,o:e,d(e){e&&d(n),f(L,e),P&&P.d(),_=!1,r(R)}}}function qg(e){let t,n,r;function o(t){e[95](t)}let i={isLoggedIn:e[1],userRole:e[4],sprocketStatus:e[19],isLoadingSprocket:e[21],sprocketUploadFile:e[24],sprocketMessage:e[22],sprocketMessageType:e[23],sprocketVersions:e[20]};return void 0!==e[18]&&(i.sprocketScript=e[18]),t=new jg({props:i}),R.push(()=>J(t,"sprocketScript",o)),t.$on("restartSprocket",e[47]),t.$on("deleteSprocket",e[48]),t.$on("sprocketFileSelect",e[52]),t.$on("uploadSprocketScript",e[53]),t.$on("saveSprocket",e[46]),t.$on("loadSprocket",e[45]),t.$on("loadVersions",e[49]),t.$on("loadVersion",e[96]),t.$on("deleteVersion",e[97]),t.$on("openLoginModal",e[56]),{c(){G(t.$$.fragment)},m(e,n){Z(t,e,n),r=!0},p(e,r){const o={};2&r[0]&&(o.isLoggedIn=e[1]),16&r[0]&&(o.userRole=e[4]),524288&r[0]&&(o.sprocketStatus=e[19]),2097152&r[0]&&(o.isLoadingSprocket=e[21]),16777216&r[0]&&(o.sprocketUploadFile=e[24]),4194304&r[0]&&(o.sprocketMessage=e[22]),8388608&r[0]&&(o.sprocketMessageType=e[23]),1048576&r[0]&&(o.sprocketVersions=e[20]),!n&&262144&r[0]&&(n=!0,o.sprocketScript=e[18],N(()=>n=!1)),t.$set(o)},i(e){r||(W(t.$$.fragment,e),r=!0)},o(e){V(t.$$.fragment,e),r=!1},d(e){Q(t,e)}}}function zg(e){let t,n,r,o;const i=[vy,my,yy],s=[];function a(e,t){return"managed"!==e[8]?0:e[1]&&"owner"===e[4]?1:2}return n=a(e),r=s[n]=i[n](e),{c(){t=h("div"),r.c(),w(t,"class","managed-acl-view svelte-7marjm")},m(e,r){u(e,t,r),s[n].m(t,null),o=!0},p(e,o){let c=n;n=a(e),n===c?s[n].p(e,o):(z(),V(s[c],1,1,()=>{s[c]=null}),K(),r=s[n],r?r.p(e,o):(r=s[n]=i[n](e),r.c()),W(r,1),r.m(t,null))},i(e){o||(W(r),o=!0)},o(e){V(r),o=!1},d(e){e&&d(t),s[n].d()}}}function Kg(e){let t,n,r;function o(t){e[94](t)}let i={};return void 0!==e[25]&&(i.composeEventJson=e[25]),t=new bg({props:i}),R.push(()=>J(t,"composeEventJson",o)),t.$on("reformatJson",e[74]),t.$on("signEvent",e[75]),t.$on("publishEvent",e[76]),{c(){G(t.$$.fragment)},m(e,n){Z(t,e,n),r=!0},p(e,r){const o={};!n&&33554432&r[0]&&(n=!0,o.composeEventJson=e[25],N(()=>n=!1)),t.$set(o)},i(e){r||(W(t.$$.fragment,e),r=!0)},o(e){V(t.$$.fragment,e),r=!1},d(e){Q(t,e)}}}function Wg(e){let t,n;return t=new mg({props:{isLoggedIn:e[1],userRole:e[4],userPubkey:e[2],filteredEvents:e[32],expandedEvents:e[17],isLoadingEvents:e[7],showOnlyMyEvents:_y}}),t.$on("scroll",e[73]),t.$on("toggleEventExpansion",e[90]),t.$on("deleteEvent",e[91]),t.$on("copyEventToClipboard",e[92]),t.$on("toggleChange",e[37]),t.$on("loadAllEvents",e[93]),{c(){G(t.$$.fragment)},m(e,r){Z(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]),2&n[1]&&(r.filteredEvents=e[32]),131072&n[0]&&(r.expandedEvents=e[17]),128&n[0]&&(r.isLoadingEvents=e[7]),t.$set(r)},i(e){n||(W(t.$$.fragment,e),n=!0)},o(e){V(t.$$.fragment,e),n=!1},d(e){Q(t,e)}}}function Vg(e){let t,n;return t=new Wp({props:{isLoggedIn:e[1],currentEffectiveRole:e[9],selectedFile:e[16]}}),t.$on("fileSelect",e[70]),t.$on("importEvents",e[71]),t.$on("openLoginModal",e[56]),{c(){G(t.$$.fragment)},m(e,r){Z(t,e,r),n=!0},p(e,n){const r={};2&n[0]&&(r.isLoggedIn=e[1]),512&n[0]&&(r.currentEffectiveRole=e[9]),65536&n[0]&&(r.selectedFile=e[16]),t.$set(r)},i(e){n||(W(t.$$.fragment,e),n=!0)},o(e){V(t.$$.fragment,e),n=!1},d(e){Q(t,e)}}}function Jg(e){let t,n;return t=new Fp({props:{isLoggedIn:e[1],currentEffectiveRole:e[9]}}),t.$on("exportMyEvents",e[69]),t.$on("exportAllEvents",e[68]),t.$on("openLoginModal",e[56]),{c(){G(t.$$.fragment)},m(e,r){Z(t,e,r),n=!0},p(e,n){const r={};2&n[0]&&(r.isLoggedIn=e[1]),512&n[0]&&(r.currentEffectiveRole=e[9]),t.$set(r)},i(e){n||(W(t.$$.fragment,e),n=!0)},o(e){V(t.$$.fragment,e),n=!1},d(e){Q(t,e)}}}function Gg(t){let n;return{c(){n=h("p"),n.textContent="Log in to access your user dashboard",w(n,"class","svelte-7marjm")},m(e,t){u(e,n,t)},p:e,d(e){e&&d(n)}}}function Zg(e){let t,n,r,o=(e[3]?.name||e[2].slice(0,8)+"...")+"";return{c(){t=h("p"),n=p("Welcome "),r=p(o),w(t,"class","svelte-7marjm")},m(e,o){u(e,t,o),l(t,n),l(t,r)},p(e,t){12&t[0]&&o!==(o=(e[3]?.name||e[2].slice(0,8)+"...")+"")&&E(r,o)},d(e){e&&d(t)}}}function Qg(e){let t,n,o,i,s,a,c,f,y,v,b,k,x,S,C,A,$,T,I,_=e[158].query+"",R=e[33].get(e[158].id)?.isLoading,j=!e[33].get(e[158].id)?.hasMore&&e[33].get(e[158].id)?.events?.length>0;function O(){return e[103](e[158])}function L(e,t){return 64&t[0]&&(x=null),64&t[0]&&(S=null),null==x&&(x=!!(e[33].get(e[158].id)?.events?.length>0)),x?Xg:(null==S&&(S=!e[33].get(e[158].id)?.isLoading),S?Yg:void 0)}let P=L(e,[-1,-1,-1,-1,-1,-1]),B=P&&P(e),N=R&&ry(),U=j&&oy();function M(...t){return e[108](e[158],...t)}return{c(){t=h("div"),n=h("div"),o=h("h2"),i=p('🔍 Search Results: "'),s=p(_),a=p('"'),c=g(),f=h("button"),y=p("🔄 Refresh"),b=g(),k=h("div"),B&&B.c(),C=g(),N&&N.c(),A=g(),U&&U.c(),$=g(),w(o,"class","svelte-7marjm"),w(f,"class","refresh-btn svelte-7marjm"),f.disabled=v=e[33].get(e[158].id)?.isLoading,w(n,"class","search-results-header svelte-7marjm"),w(k,"class","search-results-content svelte-7marjm"),w(t,"class","search-results-view svelte-7marjm")},m(e,r){u(e,t,r),l(t,n),l(n,o),l(o,i),l(o,s),l(o,a),l(n,c),l(n,f),l(f,y),l(t,b),l(t,k),B&&B.m(k,null),l(k,C),N&&N.m(k,null),l(k,A),U&&U.m(k,null),l(t,$),T||(I=[m(f,"click",O),m(k,"scroll",M)],T=!0)},p(t,n){e=t,64&n[0]&&_!==(_=e[158].query+"")&&E(s,_),64&n[0]&&v!==(v=e[33].get(e[158].id)?.isLoading)&&(f.disabled=v),P===(P=L(e,n))&&B?B.p(e,n):(B&&B.d(1),B=P&&P(e),B&&(B.c(),B.m(k,C))),64&n[0]&&(R=e[33].get(e[158].id)?.isLoading),R?N||(N=ry(),N.c(),N.m(k,A)):N&&(N.d(1),N=null),64&n[0]&&(j=!e[33].get(e[158].id)?.hasMore&&e[33].get(e[158].id)?.events?.length>0),j?U||(U=oy(),U.c(),U.m(k,null)):U&&(U.d(1),U=null)},d(e){e&&d(t),B&&B.d(),N&&N.d(),U&&U.d(),T=!1,r(I)}}}function Yg(e){let t,n,r,o,i,s=e[158].query+"";return{c(){t=h("div"),n=h("p"),r=p('No search results found for "'),o=p(s),i=p('".'),w(n,"class","svelte-7marjm"),w(t,"class","no-search-results svelte-7marjm")},m(e,s){u(e,t,s),l(t,n),l(n,r),l(n,o),l(n,i)},p(e,t){64&t[0]&&s!==(s=e[158].query+"")&&E(o,s)},d(e){e&&d(t)}}}function Xg(e){let t,n=e[33].get(e[158].id).events,r=[];for(let t=0;t<n.length;t+=1)r[t]=ny(Ng(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,o){if(131156&o[0]|180&o[1]){let i;for(n=e[33].get(e[158].id).events,i=0;i<n.length;i+=1){const s=Ng(e,n,i);r[i]?r[i].p(s,o):(r[i]=ny(s),r[i].c(),r[i].m(t.parentNode,t))}for(;i<r.length;i+=1)r[i].d(1);r.length=n.length}},d(e){f(r,e),e&&d(t)}}}function ey(e){let t,n,r;function o(){return e[104](e[151])}return{c(){t=h("button"),t.textContent="🗑️",w(t,"class","delete-btn svelte-7marjm")},m(e,i){u(e,t,i),n||(r=m(t,"click",v(o)),n=!0)},p(t,n){e=t},d(e){e&&d(t),n=!1,r()}}}function ty(e){let t,n,r,o,i,s,a,c,f=JSON.stringify(e[151],null,2)+"";function y(...t){return e[107](e[151],...t)}return{c(){t=h("div"),n=h("div"),r=h("pre"),o=p(f),i=g(),s=h("button"),s.textContent="📋",w(r,"class","event-json svelte-7marjm"),w(s,"class","copy-json-btn svelte-7marjm"),w(s,"title","Copy minified JSON to clipboard"),w(n,"class","json-container svelte-7marjm"),w(t,"class","search-result-details svelte-7marjm")},m(e,d){u(e,t,d),l(t,n),l(n,r),l(r,o),l(n,i),l(n,s),a||(c=m(s,"click",v(y)),a=!0)},p(t,n){e=t,64&n[0]&&f!==(f=JSON.stringify(e[151],null,2)+"")&&E(o,f)},d(e){e&&d(t),a=!1,c()}}}function ny(e){let t,n,o,i,s,a,c,f,y,v,b,k,x,C,A,$,T,I,_,R,j,O,L,P,B,N,U=Ry(e[151].pubkey)+"",M=e[151].kind+"",F=e[35](e[151].kind)+"",D=Oy(e[151].created_at)+"",H=jy(e[151].content)+"",q=e[17].has(e[151].id),z=5!==e[151].kind&&("admin"===e[4]||"owner"===e[4]||"write"===e[4]&&e[151].pubkey&&e[151].pubkey===e[2])&&ey(e);function K(){return e[105](e[151])}function W(...t){return e[106](e[151],...t)}let V=q&&ty(e);return{c(){t=h("div"),n=h("div"),o=h("div"),o.innerHTML='<div class="avatar-placeholder svelte-7marjm">👤</div>',i=g(),s=h("div"),a=h("div"),c=p(U),f=g(),y=h("div"),v=h("span"),b=p(M),k=g(),x=h("span"),C=p(F),A=g(),$=h("div"),T=h("div"),I=p(D),_=g(),R=h("div"),j=p(H),O=g(),z&&z.c(),L=g(),V&&V.c(),P=g(),w(o,"class","search-result-avatar svelte-7marjm"),w(a,"class","search-result-author svelte-7marjm"),w(v,"class","kind-number svelte-7marjm"),w(x,"class","kind-name svelte-7marjm"),w(y,"class","search-result-kind svelte-7marjm"),w(s,"class","search-result-info svelte-7marjm"),w(T,"class","event-timestamp svelte-7marjm"),w(R,"class","event-content-single-line svelte-7marjm"),w($,"class","search-result-content svelte-7marjm"),w(n,"class","search-result-row svelte-7marjm"),w(n,"role","button"),w(n,"tabindex","0"),w(t,"class","search-result-item svelte-7marjm"),S(t,"expanded",e[17].has(e[151].id))},m(e,r){u(e,t,r),l(t,n),l(n,o),l(n,i),l(n,s),l(s,a),l(a,c),l(s,f),l(s,y),l(y,v),l(v,b),l(y,k),l(y,x),l(x,C),l(n,A),l(n,$),l($,T),l(T,I),l($,_),l($,R),l(R,j),l(n,O),z&&z.m(n,null),l(t,L),V&&V.m(t,null),l(t,P),B||(N=[m(n,"click",K),m(n,"keydown",W)],B=!0)},p(r,o){e=r,64&o[0]&&U!==(U=Ry(e[151].pubkey)+"")&&E(c,U),64&o[0]&&M!==(M=e[151].kind+"")&&E(b,M),64&o[0]&&F!==(F=e[35](e[151].kind)+"")&&E(C,F),64&o[0]&&D!==(D=Oy(e[151].created_at)+"")&&E(I,D),64&o[0]&&H!==(H=jy(e[151].content)+"")&&E(j,H),5!==e[151].kind&&("admin"===e[4]||"owner"===e[4]||"write"===e[4]&&e[151].pubkey&&e[151].pubkey===e[2])?z?z.p(e,o):(z=ey(e),z.c(),z.m(n,null)):z&&(z.d(1),z=null),131136&o[0]&&(q=e[17].has(e[151].id)),q?V?V.p(e,o):(V=ty(e),V.c(),V.m(t,P)):V&&(V.d(1),V=null),131136&o[0]|4&o[1]&&S(t,"expanded",e[17].has(e[151].id))},d(e){e&&d(t),z&&z.d(),V&&V.d(),B=!1,r(N)}}}function ry(e){let t;return{c(){t=h("div"),t.innerHTML='<div class="loading-spinner svelte-7marjm"></div> \n <p class="svelte-7marjm">Searching...</p>',w(t,"class","loading-search-results svelte-7marjm")},m(e,n){u(e,t,n)},d(e){e&&d(t)}}}function oy(e){let t;return{c(){t=h("div"),t.innerHTML='<p class="svelte-7marjm">No more search results to load.</p>',w(t,"class","end-of-search-results svelte-7marjm")},m(e,n){u(e,t,n)},d(e){e&&d(t)}}}function iy(e){let t,n=e[158].id===e[5]&&Qg(e);return{c(){n&&n.c(),t=y()},m(e,r){n&&n.m(e,r),u(e,t,r)},p(e,r){e[158].id===e[5]?n?n.p(e,r):(n=Qg(e),n.c(),n.m(t.parentNode,t)):n&&(n.d(1),n=null)},d(e){n&&n.d(e),e&&d(t)}}}function sy(t){let n,r,o=t[155].label+"";return{c(){n=h("option"),r=p(o),n.__value=t[155].value,n.value=n.__value},m(e,t){u(e,n,t),l(n,r)},p:e,d(e){e&&d(n)}}}function ay(e){let t;function n(e,t){return e[29]?uy:0===e[28].length?ly:cy}let r=n(e),o=r(e);return{c(){t=h("div"),o.c(),w(t,"class","recovery-results svelte-7marjm")},m(e,n){u(e,t,n),o.m(t,null)},p(e,i){r===(r=n(e))&&o?o.p(e,i):(o.d(1),o=r(e),o&&(o.c(),o.m(t,null)))},d(e){e&&d(t),o.d()}}}function cy(e){let t,n,r,o=e[28],i=[];for(let t=0;t<o.length;t+=1)i[t]=py(Ug(e,o,t));let s=e[30]&&gy(e);return{c(){t=h("div");for(let e=0;e<i.length;e+=1)i[e].c();n=g(),s&&s.c(),r=y(),w(t,"class","events-list svelte-7marjm")},m(e,o){u(e,t,o);for(let e=0;e<i.length;e+=1)i[e]&&i[e].m(t,null);u(e,n,o),s&&s.m(e,o),u(e,r,o)},p(e,n){if(268435968&n[0]|9728&n[1]){let r;for(o=e[28],r=0;r<o.length;r+=1){const s=Ug(e,o,r);i[r]?i[r].p(s,n):(i[r]=py(s),i[r].c(),i[r].m(t,null))}for(;r<i.length;r+=1)i[r].d(1);i.length=o.length}e[30]?s?s.p(e,n):(s=gy(e),s.c(),s.m(r.parentNode,r)):s&&(s.d(1),s=null)},d(e){e&&d(t),f(i,e),e&&d(n),s&&s.d(e),e&&d(r)}}}function ly(t){let n;return{c(){n=h("div"),n.textContent="No events found for this kind",w(n,"class","no-events svelte-7marjm")},m(e,t){u(e,n,t)},p:e,d(e){e&&d(n)}}}function uy(t){let n;return{c(){n=h("div"),n.textContent="Loading events...",w(n,"class","loading svelte-7marjm")},m(e,t){u(e,n,t)},p:e,d(e){e&&d(n)}}}function dy(e){let t;return{c(){t=p("Current Version")},m(e,n){u(e,t,n)},d(e){e&&d(t)}}}function fy(e){let t,n,r,o,i;function s(){return e[100](e[151])}let a="read"!==e[9]&&hy(e);return{c(){t=h("button"),t.textContent="🌐 Repost to All",n=g(),a&&a.c(),r=y(),w(t,"class","repost-all-button svelte-7marjm")},m(e,c){u(e,t,c),u(e,n,c),a&&a.m(e,c),u(e,r,c),o||(i=m(t,"click",s),o=!0)},p(t,n){"read"!==(e=t)[9]?a?a.p(e,n):(a=hy(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),o=!1,i()}}}function hy(e){let t,n,r;function o(){return e[101](e[151])}return{c(){t=h("button"),t.textContent="🔄 Repost",w(t,"class","repost-button svelte-7marjm")},m(e,i){u(e,t,i),n||(r=m(t,"click",o),n=!0)},p(t,n){e=t},d(e){e&&d(t),n=!1,r()}}}function py(e){let t,n,r,o,i,s,a,c,f,y,b,k,x,C,A,$,T,I,_=new Date(1e3*e[151].created_at).toLocaleString()+"",R=JSON.stringify(e[151],null,2)+"",j=e[152]&&dy(),O=!e[152]&&fy(e);function L(...t){return e[102](e[151],...t)}return{c(){t=h("div"),n=h("div"),r=h("div"),o=h("span"),j&&j.c(),i=g(),s=h("span"),a=p(_),c=g(),f=h("div"),O&&O.c(),y=g(),b=h("button"),b.textContent="📋 Copy JSON",k=g(),x=h("div"),C=h("pre"),A=p(R),$=g(),w(o,"class","event-kind svelte-7marjm"),w(s,"class","event-timestamp svelte-7marjm"),w(r,"class","event-header-left svelte-7marjm"),w(b,"class","copy-json-btn svelte-7marjm"),w(f,"class","event-header-actions svelte-7marjm"),w(n,"class","event-header svelte-7marjm"),w(C,"class","event-json svelte-7marjm"),w(x,"class","event-content svelte-7marjm"),w(t,"class","event-item svelte-7marjm"),S(t,"old-version",!e[152])},m(e,d){u(e,t,d),l(t,n),l(n,r),l(r,o),j&&j.m(o,null),l(r,i),l(r,s),l(s,a),l(n,c),l(n,f),O&&O.m(f,null),l(f,y),l(f,b),l(t,k),l(t,x),l(x,C),l(C,A),l(t,$),T||(I=m(b,"click",v(L)),T=!0)},p(n,r){(e=n)[152]?j||(j=dy(),j.c(),j.m(o,null)):j&&(j.d(1),j=null),268435456&r[0]&&_!==(_=new Date(1e3*e[151].created_at).toLocaleString()+"")&&E(a,_),e[152]?O&&(O.d(1),O=null):O?O.p(e,r):(O=fy(e),O.c(),O.m(f,y)),268435456&r[0]&&R!==(R=JSON.stringify(e[151],null,2)+"")&&E(A,R),268435456&r[0]|8192&r[1]&&S(t,"old-version",!e[152])},d(e){e&&d(t),j&&j.d(),O&&O.d(),T=!1,I()}}}function gy(e){let t,n,r,o;return{c(){t=h("button"),n=p("Load More Events"),w(t,"class","load-more svelte-7marjm"),t.disabled=e[29]},m(i,s){u(i,t,s),l(t,n),r||(o=m(t,"click",e[39]),r=!0)},p(e,n){536870912&n[0]&&(t.disabled=e[29])},d(e){e&&d(t),r=!1,o()}}}function yy(t){let n,r,o,i,s,a;return{c(){n=h("div"),r=h("p"),r.textContent="Please log in with owner permissions to access\n managed ACL configuration.",o=g(),i=h("button"),i.textContent="Log In",w(i,"class","login-btn svelte-7marjm"),w(n,"class","access-denied")},m(e,c){u(e,n,c),l(n,r),l(n,o),l(n,i),s||(a=m(i,"click",t[56]),s=!0)},p:e,i:e,o:e,d(e){e&&d(n),s=!1,a()}}}function my(e){let t,n;return t=new vp({props:{userSigner:e[12],userPubkey:e[2]}}),{c(){G(t.$$.fragment)},m(e,r){Z(t,e,r),n=!0},p(e,n){const r={};4096&n[0]&&(r.userSigner=e[12]),4&n[0]&&(r.userPubkey=e[2]),t.$set(r)},i(e){n||(W(t.$$.fragment,e),n=!0)},o(e){V(t.$$.fragment,e),n=!1},d(e){Q(t,e)}}}function vy(t){let n,r,o,i,s,a,c,f,y,m,v,b=(t[8]||"unknown")+"";return{c(){n=h("div"),r=h("h3"),r.textContent="⚠️ Managed ACL Mode Not Active",o=g(),i=h("p"),i.textContent='To use the Managed ACL interface, you need to set\n the ACL mode to "managed" in your relay\n configuration.',s=g(),a=h("p"),c=p("Current ACL mode: "),f=h("strong"),y=p(b),m=g(),v=h("p"),v.innerHTML='Please set <code class="svelte-7marjm">ORLY_ACL_MODE=managed</code> in your\n environment variables and restart the relay.',w(r,"class","svelte-7marjm"),w(i,"class","svelte-7marjm"),w(a,"class","svelte-7marjm"),w(v,"class","svelte-7marjm"),w(n,"class","acl-mode-warning svelte-7marjm")},m(e,t){u(e,n,t),l(n,r),l(n,o),l(n,i),l(n,s),l(n,a),l(a,c),l(a,f),l(f,y),l(n,m),l(n,v)},p(e,t){256&t[0]&&b!==(b=(e[8]||"unknown")+"")&&E(y,b)},i:e,o:e,d(e){e&&d(n)}}}function wy(e){let t,n,o,i,s,a,c,f,p,y;function b(e,t){return e[3]?Ey:e[1]&&e[2]?by:void 0}let E=b(e),k=E&&E(e);return{c(){t=h("div"),n=h("div"),o=h("div"),i=h("h2"),i.textContent="Settings",s=g(),a=h("button"),a.textContent="✕",c=g(),f=h("div"),k&&k.c(),w(i,"class","svelte-7marjm"),w(a,"class","close-btn svelte-7marjm"),w(o,"class","drawer-header svelte-7marjm"),w(f,"class","drawer-content"),w(n,"class","settings-drawer svelte-7marjm"),S(n,"dark-theme",e[0]),w(t,"class","drawer-overlay svelte-7marjm"),w(t,"role","button"),w(t,"tabindex","0")},m(r,d){u(r,t,d),l(t,n),l(n,o),l(o,i),l(o,s),l(o,a),l(n,c),l(n,f),k&&k.m(f,null),p||(y=[m(a,"click",e[61]),m(n,"click",v(e[84])),m(n,"keydown",v(e[85])),m(t,"click",e[61]),m(t,"keydown",e[110])],p=!0)},p(e,t){E===(E=b(e))&&k?k.p(e,t):(k&&k.d(1),k=E&&E(e),k&&(k.c(),k.m(f,null))),1&t[0]&&S(n,"dark-theme",e[0])},d(e){e&&d(t),k&&k.d(),p=!1,r(y)}}}function by(e){let t,n,o,i,s,a,c,f,y,v,b,k,x,S,C,A,$,T=e[2].slice(0,16)+"",I=e[2].slice(-8)+"";return{c(){t=h("div"),n=h("button"),n.textContent="Log out",o=g(),i=h("h3"),i.textContent="Profile Loading",s=g(),a=h("p"),a.textContent="Your profile metadata is being loaded...",c=g(),f=h("button"),f.textContent="Retry Loading Profile",y=g(),v=h("div"),b=h("strong"),b.textContent="Public Key:",k=g(),x=p(T),S=p("..."),C=p(I),w(n,"class","logout-btn floating svelte-7marjm"),w(i,"class","svelte-7marjm"),w(a,"class","svelte-7marjm"),w(f,"class","retry-profile-btn svelte-7marjm"),w(v,"class","user-pubkey-display svelte-7marjm"),w(t,"class","profile-loading-section svelte-7marjm")},m(r,d){u(r,t,d),l(t,n),l(t,o),l(t,i),l(t,s),l(t,a),l(t,c),l(t,f),l(t,y),l(t,v),l(v,b),l(v,k),l(v,x),l(v,S),l(v,C),A||($=[m(n,"click",e[58]),m(f,"click",e[67])],A=!0)},p(e,t){4&t[0]&&T!==(T=e[2].slice(0,16)+"")&&E(x,T),4&t[0]&&I!==(I=e[2].slice(-8)+"")&&E(C,I)},d(e){e&&d(t),A=!1,r($)}}}function Ey(e){let t,n,r,o,i,s,a,c,f,v,b,k,x,S,C,A=(e[3].name||"Unknown User")+"",$=e[3].banner&&ky(e);function T(e,t){return e[3].picture?Sy:xy}let I=T(e),_=I(e),R=e[3].nip05&&Cy(e),j=e[3].about&&Ay(e),O=e[4]&&"read"!==e[4]&&$y(e);return{c(){t=h("div"),n=h("div"),$&&$.c(),r=g(),o=h("button"),o.textContent="Log out",i=g(),_.c(),s=g(),a=h("div"),c=h("h3"),f=p(A),v=g(),R&&R.c(),b=g(),j&&j.c(),k=g(),O&&O.c(),x=y(),w(o,"class","logout-btn floating svelte-7marjm"),w(c,"class","profile-username svelte-7marjm"),w(a,"class","name-row svelte-7marjm"),w(n,"class","profile-hero svelte-7marjm"),w(t,"class","profile-section svelte-7marjm")},m(d,h){u(d,t,h),l(t,n),$&&$.m(n,null),l(n,r),l(n,o),l(n,i),_.m(n,null),l(n,s),l(n,a),l(a,c),l(c,f),l(a,v),R&&R.m(a,null),l(t,b),j&&j.m(t,null),u(d,k,h),O&&O.m(d,h),u(d,x,h),S||(C=m(o,"click",e[58]),S=!0)},p(e,o){e[3].banner?$?$.p(e,o):($=ky(e),$.c(),$.m(n,r)):$&&($.d(1),$=null),I===(I=T(e))&&_?_.p(e,o):(_.d(1),_=I(e),_&&(_.c(),_.m(n,s))),8&o[0]&&A!==(A=(e[3].name||"Unknown User")+"")&&E(f,A),e[3].nip05?R?R.p(e,o):(R=Cy(e),R.c(),R.m(a,null)):R&&(R.d(1),R=null),e[3].about?j?j.p(e,o):(j=Ay(e),j.c(),j.m(t,null)):j&&(j.d(1),j=null),e[4]&&"read"!==e[4]?O?O.p(e,o):(O=$y(e),O.c(),O.m(x.parentNode,x)):O&&(O.d(1),O=null)},d(e){e&&d(t),$&&$.d(),_.d(),R&&R.d(),j&&j.d(),e&&d(k),O&&O.d(e),e&&d(x),S=!1,C()}}}function ky(e){let t,n;return{c(){t=h("img"),a(t.src,n=e[3].banner)||w(t,"src",n),w(t,"alt","Profile banner"),w(t,"class","profile-banner svelte-7marjm")},m(e,n){u(e,t,n)},p(e,r){8&r[0]&&!a(t.src,n=e[3].banner)&&w(t,"src",n)},d(e){e&&d(t)}}}function xy(t){let n;return{c(){n=h("div"),n.textContent="👤",w(n,"class","profile-avatar-placeholder overlap svelte-7marjm")},m(e,t){u(e,n,t)},p:e,d(e){e&&d(n)}}}function Sy(e){let t,n;return{c(){t=h("img"),a(t.src,n=e[3].picture)||w(t,"src",n),w(t,"alt","User avatar"),w(t,"class","profile-avatar overlap svelte-7marjm")},m(e,n){u(e,t,n)},p(e,r){8&r[0]&&!a(t.src,n=e[3].picture)&&w(t,"src",n)},d(e){e&&d(t)}}}function Cy(e){let t,n,r=e[3].nip05+"";return{c(){t=h("span"),n=p(r),w(t,"class","profile-nip05-inline svelte-7marjm")},m(e,r){u(e,t,r),l(t,n)},p(e,t){8&t[0]&&r!==(r=e[3].nip05+"")&&E(n,r)},d(e){e&&d(t)}}}function Ay(e){let t,n;return{c(){t=h("div"),n=h("p"),w(n,"class","profile-about svelte-7marjm"),w(t,"class","about-card svelte-7marjm")},m(r,o){u(r,t,o),l(t,n),n.innerHTML=e[31]},p(e,t){1&t[1]&&(n.innerHTML=e[31])},d(e){e&&d(t)}}}function $y(e){let t,n,r,o,i,s,a=e[78](),c=[];for(let t=0;t<a.length;t+=1)c[t]=Ty(Pg(e,a,t));return{c(){t=h("div"),n=h("h3"),n.textContent="View as Role",r=g(),o=h("p"),o.textContent="See the interface as it appears for different\n permission levels:",i=g(),s=h("div");for(let e=0;e<c.length;e+=1)c[e].c();w(n,"class","svelte-7marjm"),w(o,"class","svelte-7marjm"),w(s,"class","radio-group svelte-7marjm"),w(t,"class","view-as-section svelte-7marjm")},m(e,a){u(e,t,a),l(t,n),l(t,r),l(t,o),l(t,i),l(t,s);for(let e=0;e<c.length;e+=1)c[e]&&c[e].m(s,null)},p(e,t){if(528&t[0]|98304&t[2]){let n;for(a=e[78](),n=0;n<a.length;n+=1){const r=Pg(e,a,n);c[n]?c[n].p(r,t):(c[n]=Ty(r),c[n].c(),c[n].m(s,null))}for(;n<c.length;n+=1)c[n].d(1);c.length=a.length}},d(e){e&&d(t),f(c,e)}}}function Ty(e){let t,n,r,o,i,s,a,c,f,y=e[148].charAt(0).toUpperCase()+e[148].slice(1)+"",v=e[148]===e[4]?" (Default)":"";function b(){return e[109](e[148])}return{c(){t=h("label"),n=h("input"),o=g(),i=p(y),s=p(v),a=g(),w(n,"type","radio"),w(n,"name","viewAsRole"),n.value=e[148],n.checked=r=e[9]===e[148],w(n,"class","svelte-7marjm"),w(t,"class","radio-label svelte-7marjm")},m(e,r){u(e,t,r),l(t,n),l(t,o),l(t,i),l(t,s),l(t,a),c||(f=m(n,"change",b),c=!0)},p(t,o){e=t,512&o[0]&&r!==(r=e[9]===e[148])&&(n.checked=r),16&o[0]&&v!==(v=e[148]===e[4]?" (Default)":"")&&E(s,v)},d(e){e&&d(t),c=!1,f()}}}function Iy(e){let t,n,r,o,i,s,a,c,f,p,y,m,v,b,E;function k(t){e[87](t)}let x={isDarkTheme:e[0],isSearchMode:e[14],isLoggedIn:e[1],userRole:e[4],currentEffectiveRole:e[9],userProfile:e[3],userPubkey:e[2]};void 0!==e[15]&&(x.searchQuery=e[15]),t=new Tp({props:x}),R.push(()=>J(t,"searchQuery",k)),t.$on("searchKeydown",e[63]),t.$on("toggleSearchMode",e[62]),t.$on("toggleTheme",e[55]),t.$on("openSettingsDrawer",e[60]),t.$on("openLoginModal",e[56]),i=new Lp({props:{isDarkTheme:e[0],tabs:e[10],selectedTab:e[5]}}),i.$on("selectTab",e[88]),i.$on("closeSearchTab",e[89]);const C=[Jg,Vg,Wg,Kg,zg,qg,Hg,Dg,Fg],A=[];function $(e,t){return 96&t[0]&&(c=null),"export"===e[5]?0:"import"===e[5]?1:"events"===e[5]?2:"compose"===e[5]?3:"managed-acl"===e[5]?4:"sprocket"===e[5]?5:"recovery"===e[5]?6:(null==c&&(c=!!e[6].some(e[86])),c?7:8)}f=$(e,[-1,-1,-1,-1,-1,-1]),p=A[f]=C[f](e);let T=e[13]&&wy(e);function I(t){e[111](t)}let _={isDarkTheme:e[0]};return void 0!==e[11]&&(_.showModal=e[11]),v=new $h({props:_}),R.push(()=>J(v,"showModal",I)),v.$on("login",e[57]),v.$on("close",e[59]),{c(){G(t.$$.fragment),r=g(),o=h("div"),G(i.$$.fragment),s=g(),a=h("main"),p.c(),y=g(),T&&T.c(),m=g(),G(v.$$.fragment),w(a,"class","main-content svelte-7marjm"),w(o,"class","app-container svelte-7marjm"),S(o,"dark-theme",e[0])},m(e,n){Z(t,e,n),u(e,r,n),u(e,o,n),Z(i,o,null),l(o,s),l(o,a),A[f].m(a,null),u(e,y,n),T&&T.m(e,n),u(e,m,n),Z(v,e,n),E=!0},p(e,r){const s={};1&r[0]&&(s.isDarkTheme=e[0]),16384&r[0]&&(s.isSearchMode=e[14]),2&r[0]&&(s.isLoggedIn=e[1]),16&r[0]&&(s.userRole=e[4]),512&r[0]&&(s.currentEffectiveRole=e[9]),8&r[0]&&(s.userProfile=e[3]),4&r[0]&&(s.userPubkey=e[2]),!n&&32768&r[0]&&(n=!0,s.searchQuery=e[15],N(()=>n=!1)),t.$set(s);const c={};1&r[0]&&(c.isDarkTheme=e[0]),1024&r[0]&&(c.tabs=e[10]),32&r[0]&&(c.selectedTab=e[5]),i.$set(c);let l=f;f=$(e,r),f===l?A[f].p(e,r):(z(),V(A[l],1,1,()=>{A[l]=null}),K(),p=A[f],p?p.p(e,r):(p=A[f]=C[f](e),p.c()),W(p,1),p.m(a,null)),(!E||1&r[0])&&S(o,"dark-theme",e[0]),e[13]?T?T.p(e,r):(T=wy(e),T.c(),T.m(m.parentNode,m)):T&&(T.d(1),T=null);const u={};1&r[0]&&(u.isDarkTheme=e[0]),!b&&2048&r[0]&&(b=!0,u.showModal=e[11],N(()=>b=!1)),v.$set(u)},i(e){E||(W(t.$$.fragment,e),W(i.$$.fragment,e),W(p),W(v.$$.fragment,e),E=!0)},o(e){V(t.$$.fragment,e),V(i.$$.fragment,e),V(p),V(v.$$.fragment,e),E=!1},d(e){Q(t,e),e&&d(r),e&&d(o),Q(i),A[f].d(),e&&d(y),T&&T.d(e),e&&d(m),Q(v,e)}}}let _y=!1;function Ry(e){return e?e.slice(0,8)+"..."+e.slice(-8):"unknown"}function jy(e,t=100){return e?e.length>t?e.slice(0,t)+"...":e:""}function Oy(e){return e?new Date(1e3*e).toLocaleString():""}async function Ly(e,t){try{const n=JSON.stringify(e);await navigator.clipboard.writeText(n);const r=t.target.closest(".copy-json-btn");if(r){const e=r.textContent;r.textContent="✅",r.style.backgroundColor="#4CAF50",setTimeout(()=>{r.textContent=e,r.style.backgroundColor=""},2e3)}}catch(n){console.error("Failed to copy to clipboard:",n);try{const n=document.createElement("textarea");n.value=JSON.stringify(e),document.body.appendChild(n),n.select(),document.execCommand("copy"),document.body.removeChild(n);const r=t.target.closest(".copy-json-btn");if(r){const e=r.textContent;r.textContent="✅",r.style.backgroundColor="#4CAF50",setTimeout(()=>{r.textContent=e,r.style.backgroundColor=""},2e3)}}catch(e){console.error("Fallback copy also failed:",e),alert("Failed to copy to clipboard. Please copy manually.")}}}function Py(e,t,n){let r,o,i,s,a;"undefined"!=typeof window&&(window.debugIndexedDB=vh);let c=!1,l=!1,u=!1,d="",f="",h=null,p="",g=null,y=!1,m=localStorage.getItem("selectedTab")||"export",v=!1,w="",E=[],k=[],x=null,S=new Set,C=!1,A=!0,$=null,T="",_=new Map,R=[],j=0;const O=3e5;let L=[],P=!0,B=null,N="",U=null,M=[],F=!1,D="",H="info",q=!1,z=null,K="",W="",V=null,J="",G=[],Z=!1,Q=!0,Y=null;const X=[{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)"}],ee={0:"User Metadata",1:"Short Text Note",2:"Recommend Relay",3:"Follows",4:"Encrypted Direct Messages",5:"Event Deletion Request",6:"Repost",7:"Reaction",8:"Badge Award",9:"Chat Message",10:"Group Chat Threaded Reply",11:"Thread",12:"Group Thread Reply",13:"Seal",14:"Direct Message",15:"File Message",16:"Generic Repost",17:"Reaction to a website",20:"Picture",40:"Channel Creation",41:"Channel Metadata",42:"Channel Message",43:"Channel Hide Message",44:"Channel Mute User",1021:"Bid",1022:"Bid Confirmation",1040:"OpenTimestamps",1063:"File Metadata",1311:"Live Chat Message",1971:"Problem Tracker",1984:"Reporting",1985:"Label",4550:"Community Post Approval",5e3:"Job Request",5999:"Job Request",6e3:"Job Result",6999:"Job Result",7e3:"Job Feedback",9041:"Zap Goal",9734:"Zap Request",9735:"Zap",9882:"Highlights",1e4:"Mute list",10001:"Pin list",10002:"Relay List Metadata",10003:"Bookmarks list",10004:"Communities list",10005:"Public Chats list",10006:"Blocked Relays list",10007:"Search Relays list",10015:"Interests",10030:"User Emoji list",10050:"DM relays",10096:"File Storage Server List",13194:"Wallet Service Info",21e3:"Lightning pub RPC",22242:"Client Authentication",23194:"Wallet Request",23195:"Wallet Response",23196:"Wallet Notification",23197:"Wallet Notification",24133:"Nostr Connect",27235:"HTTP Auth",3e4:"Follow sets",30001:"Generic lists",30002:"Relay sets",30003:"Bookmark sets",30004:"Curation sets",30008:"Profile Badges",30009:"Badge Definition",30015:"Interest sets",30017:"Stall Definition",30018:"Product Definition",30019:"Marketplace UI/UX",30020:"Product sold as an auction",30023:"Long-form Content",30024:"Draft Long-form Content",30030:"Emoji sets",30078:"Application-specific Data",30311:"Live Event",30315:"User Statuses",30402:"Classified Listing",30403:"Draft Classified Listing",31922:"Date-Based Calendar Event",31923:"Time-Based Calendar Event",31924:"Calendar",31925:"Calendar Event RSVP",31989:"Handler recommendation",31990:"Handler information",34235:"Video Event Horizontal",34236:"Video Event Vertical",34550:"Community Definition"};function te(e){S.has(e)?S.delete(e):S.add(e),n(17,S)}async function ne(e){if(!u)return void alert("Please log in first");const t=k.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 o=await g.signEvent(r);console.log("Signed delete event:",o),console.log("Signed delete event pubkey:",o.pubkey),console.log("Delete event tags:",o.tags);const i=`wss://${window.location.host}`;try{const e=await Lg(i,o,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 oh.publish(o);if(console.log("Delete event published:",t),!(t.success&&t.okCount>0))throw new Error("No relays accepted the delete event");{await new Promise(e=>setTimeout(e,2e3));try{const n=await gh(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 yh(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(79,k=k.filter(t=>t.id!==e)),L=L.filter(t=>t.id!==e),R=R.filter(t=>t.id!==e);for(const[t,n]of _)n.events&&(n.events=n.events.filter(t=>t.id!==e),_.set(t,n));se(),console.log("Reloading events to show delete event...");const r=_y&&u&&d?[d]:null;await xe(!0,r),alert(`Event deleted successfully (accepted by ${t.okCount} relay(s))`)}}else{const t=`wss://${window.location.host}/`,r=new rh;await r.connectToRelay(t);const i=await r.publish(o);if(console.log("Delete event published to local relay only:",i),!(i.success&&i.okCount>0))throw new Error("Local relay did not accept the delete event");{await new Promise(e=>setTimeout(e,2e3));try{const t=await gh(e,{timeout:5e3});t?(console.warn("Event still exists after deletion attempt:",t),alert(`Warning: Delete event was accepted by ${i.okCount} relay(s), but the event still exists on the relay. This may indicate the relay does not properly handle delete events.`)):console.log("Event successfully deleted and verified")}catch(e){console.log("Could not fetch event after deletion (likely deleted):",e.message)}try{const t=await yh(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(79,k=k.filter(t=>t.id!==e)),L=L.filter(t=>t.id!==e),R=R.filter(t=>t.id!==e);for(const[t,n]of _)n.events&&(n.events=n.events.filter(t=>t.id!==e),_.set(t,n));se(),console.log("Reloading events to show delete event...");const t=_y&&u&&d?[d]:null;await xe(!0,t),alert("Event deleted successfully (local relay only - admin/owner deleting other user's event)")}}}catch(e){console.error("Failed to delete event:",e),alert("Failed to delete event: "+e.message)}}else alert("You do not have permission to delete this event")}async function re(){const e=J?parseInt(J):V;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(29,Z=!0);try{const t=[{kinds:[e],authors:[d],limit:100}];Y&&(t[0].until=Y),console.log("Recovery filters:",t);const r=await async function(e,t={}){const{timeout:n=3e4,cacheFirst:r=!0,cacheOnly:o=!1}=t;let i=[];if(r||o)try{if(i=await dh(e),console.log(`Found ${i.length} events in cache`),o||i.length>0)return i}catch(e){console.warn("Failed to query cache",e)}if(!o){const t=await ph(e,{timeout:n,useCache:!1});return console.log(`Fetched ${t.length} events from relay`),t}return i}(t,{timeout:3e4,cacheFirst:!0});console.log("Recovery events received:",r.length),console.log("Recovery events kinds:",r.map(e=>e.kind)),n(28,G=Y?[...G,...r]:r),r.length>0?(Y=Math.min(...r.map(e=>e.created_at)),n(30,Q=100===r.length)):n(30,Q=!1)}catch(e){console.error("Failed to load recovery events:",e)}finally{n(29,Z=!1)}}else console.log("Not logged in, cannot load recovery events")}async function oe(e){if(confirm("Are you sure you want to repost this event?"))try{const t=`wss://${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 o=await oh.publish(e,[t]);console.log("Repost publish result:",o),o.success&&o.okCount>0?(alert("Event reposted successfully!"),n(30,Q=!1),await re()):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 ie(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 dh([{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=`wss://${window.location.host}/`,o=[r,...t.filter(e=>e!==r)];1===o.length&&alert("No write relays found in your relay list. Only posting to local relay."),console.log("Reposting event to all relays:",o,e);const i={...e};if(i.created_at=Math.floor(Date.now()/1e3),i.id="",i.sig="",e.kind>=3e4&&e.kind<=39999){const t=e.tags.find(e=>"d"===e[0]);t&&(i.tags=i.tags.filter(e=>"d"!==e[0]),i.tags.push(t))}if(g){const e=await g.signEvent(i);console.log("Signed event for repost to all:",e);const t=await oh.publish(e,o);console.log("Repost to all publish result:",t),t.success&&t.okCount>0?(alert(`Event reposted successfully to ${o.length} relays!`),n(30,Q=!1),await re()):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 localStorage){const e=localStorage.getItem("isDarkTheme");null!==e&&(c=JSON.parse(e));const t=localStorage.getItem("nostr_auth_method"),r=localStorage.getItem("nostr_pubkey");t&&r&&(u=!0,d=r,f=t,"extension"===t&&window.nostr&&(g=window.nostr),be(),Ee()),function(){if("undefined"==typeof localStorage)return;try{const t=localStorage.getItem("app_state");if(t){const r=JSON.parse(t);r.selectedTab&&he.some(e=>e.id===r.selectedTab)&&n(5,m=r.selectedTab),r.expandedEvents&&n(17,S=new Set(r.expandedEvents)),r.globalEventsCache&&(R=r.globalEventsCache),r.globalCacheTimestamp&&(j=r.globalCacheTimestamp),void 0!==r.hasMoreEvents&&(A=r.hasMoreEvents),r.oldestEventTimestamp&&($=r.oldestEventTimestamp),void 0!==r.hasMoreMyEvents&&(P=r.hasMoreMyEvents),r.oldestMyEventTimestamp&&(B=r.oldestMyEventTimestamp),R.length>0&&((e=j)&&Date.now()-e<O)&&n(79,k=R)}}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(81,q=t.enabled)}}catch(e){console.error("Error loading sprocket config:",e)}}()}function se(){if("undefined"==typeof localStorage)return;const e={selectedTab:m,expandedEvents:Array.from(S),globalEventsCache:R,globalCacheTimestamp:j,hasMoreEvents:A,oldestEventTimestamp:$};localStorage.setItem("app_state",JSON.stringify(e))}function ae(e){R=e.sort((e,t)=>t.created_at-e.created_at),j=Date.now(),se()}async function ce(){if(u&&"owner"===p&&q)try{n(21,F=!0);const e=await fetch("/api/sprocket/status",{method:"GET",headers:{Authorization:`Nostr ${await $e("GET","/api/sprocket/status")}`,"Content-Type":"application/json"}});e.ok?n(19,U=await e.json()):fe("Failed to load sprocket status","error")}catch(e){fe(`Error loading sprocket status: ${e.message}`,"error")}finally{n(21,F=!1)}}async function le(){if(u&&"owner"===p)try{n(21,F=!0);const e=await fetch("/api/sprocket/versions",{method:"GET",headers:{Authorization:`Nostr ${await $e("GET","/api/sprocket/versions")}`,"Content-Type":"application/json"}});e.ok?n(20,M=await e.json()):fe("Failed to load versions","error")}catch(e){fe(`Error loading versions: ${e.message}`,"error")}finally{n(21,F=!1)}}async function ue(e){u&&"owner"===p&&(n(18,N=e.content),fe(`Loaded version: ${e.name}`,"success"))}async function de(e){if(u&&"owner"===p&&confirm(`Are you sure you want to delete version ${e}?`))try{n(21,F=!0);const t=await fetch("/api/sprocket/delete-version",{method:"POST",headers:{Authorization:`Nostr ${await $e("POST","/api/sprocket/delete-version")}`,"Content-Type":"application/json"},body:JSON.stringify({filename:e})});if(t.ok)fe(`Version ${e} deleted successfully`,"success"),await le();else{fe(`Failed to delete version: ${await t.text()}`,"error")}}catch(e){fe(`Error deleting version: ${e.message}`,"error")}finally{n(21,F=!1)}}function fe(e,t="info"){n(22,D=e),n(23,H=t),setTimeout(()=>{n(22,D="")},5e3)}const he=[{id:"export",icon:"📤",label:"Export"},{id:"import",icon:"💾",label:"Import",requiresAdmin:!0},{id:"events",icon:"📡",label:"Events"},{id:"compose",icon:"✏️",label:"Compose",requiresWrite:!0},{id:"recovery",icon:"🔄",label:"Recovery"},{id:"managed-acl",icon:"🛡️",label:"Managed ACL",requiresOwner:!0},{id:"sprocket",icon:"⚙️",label:"Sprocket",requiresOwner:!0}];function pe(e){n(5,m=e),"sprocket"===e&&u&&"owner"===p&&q&&(ce(),le()),se()}function ge(){n(13,y=!1)}function ye(e){n(6,E=E.filter(t=>t.id!==e)),_.delete(e),m===e&&n(5,m="export")}async function me(e,t,n=!0){const r=_.get(e);if(r&&!r.isLoading){r.isLoading=!0,_.set(e,r);try{const o={limit:n?100:200,until:n?Math.floor(Date.now()/1e3):r.oldestTimestamp};console.log("Loading search results for query:",t,"with options:",o);const i=await async function(e,t={}){const{limit:n=100,since:r=null,until:o=null,kinds:i=null}=t,s=[{search:e}];return r&&(s[0].since=r),o&&(s[0].until=o),i&&(s[0].kinds=i),n&&(s[0].limit=n),await ph(s,{timeout:3e4})}(t,o);if(console.log("Received search results:",i.length,"events"),r.events=n?i.sort((e,t)=>t.created_at-e.created_at):[...r.events,...i].sort((e,t)=>t.created_at-e.created_at),i.length>0){const e=Math.min(...i.map(e=>e.created_at));(!r.oldestTimestamp||e<r.oldestTimestamp)&&(r.oldestTimestamp=e)}r.hasMore=i.length===(n?100:200),r.isLoading=!1,_.set(e,r)}catch(t){console.error("Failed to load search results:",t),r.isLoading=!1,_.set(e,r),alert("Failed to load search results: "+t.message)}}}function ve(e,t){const{scrollTop:n,scrollHeight:r,clientHeight:o}=e.target;if(r-n-o<100){const e=_.get(t);e&&!e.isLoading&&e.hasMore&&async function(e){const t=E.find(t=>t.id===e);t&&await me(e,t.query,!1)}(t)}}async function we(){if(u&&d&&!h)try{console.log("Auto-fetching profile for:",d),await mh(),n(3,h=await hh(d)),console.log("Profile auto-loaded:",h)}catch(e){console.error("Failed to auto-load profile:",e)}}async function be(){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 Ee(){try{const e=await fetch("/api/acl-mode");if(e.ok){const t=await e.json();n(8,K=t.acl_mode||""),console.log("ACL mode loaded:",K)}else console.error("Failed to fetch ACL mode:",e.status),n(8,K="")}catch(e){console.error("Error fetching ACL mode:",e),n(8,K="")}}async function ke(e=[]){if(u)if(0!==e.length||"admin"===a||"owner"===a)try{const t=await Ae("/api/export","POST"),n=await fetch("/api/export",{method:"POST",headers:{Authorization:t,"Content-Type":"application/json"},body:JSON.stringify({pubkeys:e})});if(!n.ok)throw new Error(`Export failed: ${n.status} ${n.statusText}`);const r=await n.blob(),o=window.URL.createObjectURL(r),i=document.createElement("a");i.href=o;const s=n.headers.get("Content-Disposition");let a="events.jsonl";if(s){const e=s.match(/filename="([^"]+)"/);e&&(a=e[1])}i.download=a,document.body.appendChild(i),i.click(),document.body.removeChild(i),window.URL.revokeObjectURL(o)}catch(e){console.error("Export failed:",e),alert("Export failed: "+e.message)}else alert("Admin or owner permission required to export all events");else alert("Please log in first")}async function xe(e=!1,t=null){if(!u||"read"!==p&&"write"!==p&&"admin"!==p&&"owner"!==p)alert("Read, write, admin, or owner permission required");else if(!C){n(7,C=!0),e&&($=null);try{console.log("Loading events with authors filter:",t,"including delete events");const r=e?Math.floor(Date.now()/1e3):$,o=await async function(e={}){const{limit:t=100,since:n=null,until:r=null,authors:o=null,kinds:i=null,...s}=e,a=[{...s}];return n&&(a[0].since=n),r&&(a[0].until=r),o&&(a[0].authors=o),i&&(a[0].kinds=i),t&&(a[0].limit=t),await ph(a,{timeout:3e4})}({limit:e?100:200,until:r,authors:t});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(79,k=o.sort((e,t)=>t.created_at-e.created_at)),ae(o)):(n(79,k=[...k,...o].sort((e,t)=>t.created_at-e.created_at)),ae(k)),o.length>0){const e=Math.min(...o.map(e=>e.created_at));(!$||e<$)&&($=e)}A=o.length===(e?1e3:200),e&&A&&setTimeout(()=>{if("events"===m){const e=document.querySelectorAll(".events-view-content")[0];e&&e.scrollHeight<=e.clientHeight&&Se()}},100)}catch(e){console.error("Failed to load events:",e),alert("Failed to load events: "+e.message)}finally{n(7,C=!1)}}}async function Se(){await xe(!1)}let Ce=!1;async function Ae(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 o=JSON.stringify(r);return`Nostr ${btoa(o)}`}async function $e(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 o=JSON.stringify(r);return btoa(o)}function Te(e){n(80,T=e),localStorage.setItem("viewAsRole",e),console.log("View as role changed to:",e,"Current effective role:",a)}T=localStorage.getItem("viewAsRole")||"";return e.$$.update=()=>{var t;if(6&e.$$.dirty[0]|131072&e.$$.dirty[2]&&n(32,r=k.sort((e,t)=>t.created_at-e.created_at)),8&e.$$.dirty[0]&&n(31,o=h?.about?(t=h.about,String(t).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")).replace(/\n{2,}/g,"<br>"):""),16&e.$$.dirty[0]|262144&e.$$.dirty[2]&&n(9,a=T&&""!==T?T:p),786&e.$$.dirty[0]|786432&e.$$.dirty[2]&&n(83,i=he.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&&!q)&&(("managed-acl"!==e.id||"managed"===K)&&(console.log(`Tab ${e.id} filter check:`,{isLoggedIn:u,userRole:p,viewAsRole:T,currentRole:t,requiresAdmin:e.requiresAdmin,requiresOwner:e.requiresOwner,requiresWrite:e.requiresWrite,visible:!0}),!0)))))})),64&e.$$.dirty[0]|2097152&e.$$.dirty[2]&&n(10,s=[...i,...E]),1298&e.$$.dirty[0]|2097152&e.$$.dirty[2]&&console.log("Tabs debug:",{isLoggedIn:u,userRole:p,aclMode:K,filteredBaseTabs:i.map(e=>e.id),allTabs:s.map(e=>e.id)}),1&e.$$.dirty[0]&&"undefined"!=typeof document&&(c?document.body.classList.add("dark-theme"):document.body.classList.remove("dark-theme")),14&e.$$.dirty[0]&&u&&d&&!h&&we(),182&e.$$.dirty[0]|1179648&e.$$.dirty[2]&&"events"===m&&u&&("read"===p||"write"===p||"admin"===p||"owner"===p)&&0===k.length&&!Ce&&!C){n(82,Ce=!0);xe(!0,null)}32&e.$$.dirty[0]|131072&e.$$.dirty[2]&&("events"!==m||"events"===m&&k.length>0)&&n(82,Ce=!1),32&e.$$.dirty[0]&&localStorage.setItem("selectedTab",m)},[c,u,d,h,p,m,E,C,K,a,s,l,g,y,v,w,x,S,N,U,M,F,D,H,z,W,V,J,G,Z,Q,o,r,_,X,function(e){return ee[e]||`Kind ${e}`},te,async function(){console.log("Toggle changed, showOnlyMyEvents:",_y),n(82,Ce=!1),await xe(!0,null)},ne,re,oe,ie,function(){console.log("selectRecoveryKind called, recoverySelectedKind:",V),null!=V?(n(27,J=""),n(28,G=[]),Y=null,n(30,Q=!0),re()):console.log("No kind selected, skipping load")},function(){console.log("handleCustomKindInput called, recoveryCustomKind:",J);const e=parseInt(J);""!==J&&!isNaN(e)&&e>=0&&(n(26,V=null),n(28,G=[]),Y=null,n(30,Q=!0),re())},function(e){const t=G.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(21,F=!0);const e=await fetch("/api/sprocket/status",{method:"GET",headers:{Authorization:`Nostr ${await $e("GET","/api/sprocket/status")}`,"Content-Type":"application/json"}});if(e.ok){const t=await e.json();n(18,N=t.script_content||""),n(19,U=t),fe("Script loaded successfully","success")}else fe("Failed to load script","error")}catch(e){fe(`Error loading script: ${e.message}`,"error")}finally{n(21,F=!1)}},async function(){if(u&&"owner"===p)try{n(21,F=!0);const e=await fetch("/api/sprocket/update",{method:"POST",headers:{Authorization:`Nostr ${await $e("POST","/api/sprocket/update")}`,"Content-Type":"text/plain"},body:N});if(e.ok)fe("Script saved and updated successfully","success"),await ce(),await le();else{fe(`Failed to save script: ${await e.text()}`,"error")}}catch(e){fe(`Error saving script: ${e.message}`,"error")}finally{n(21,F=!1)}},async function(){if(u&&"owner"===p)try{n(21,F=!0);const e=await fetch("/api/sprocket/restart",{method:"POST",headers:{Authorization:`Nostr ${await $e("POST","/api/sprocket/restart")}`,"Content-Type":"application/json"}});if(e.ok)fe("Sprocket restarted successfully","success"),await ce();else{fe(`Failed to restart sprocket: ${await e.text()}`,"error")}}catch(e){fe(`Error restarting sprocket: ${e.message}`,"error")}finally{n(21,F=!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(21,F=!0);const e=await fetch("/api/sprocket/update",{method:"POST",headers:{Authorization:`Nostr ${await $e("POST","/api/sprocket/update")}`,"Content-Type":"text/plain"},body:""});if(e.ok)n(18,N=""),fe("Sprocket script deleted successfully","success"),await ce(),await le();else{fe(`Failed to delete script: ${await e.text()}`,"error")}}catch(e){fe(`Error deleting script: ${e.message}`,"error")}finally{n(21,F=!1)}},le,ue,de,function(e){n(24,z=e.target.files[0])},async function(){if(u&&"owner"===p&&z)try{n(21,F=!0);const e=await z.text(),t=await fetch("/api/sprocket/update",{method:"POST",headers:{Authorization:`Nostr ${await $e("POST","/api/sprocket/update")}`,"Content-Type":"text/plain"},body:e});if(t.ok)n(18,N=e),fe("Script uploaded and updated successfully","success"),await ce(),await le();else{fe(`Failed to upload script: ${await t.text()}`,"error")}}catch(e){fe(`Error uploading script: ${e.message}`,"error")}finally{n(21,F=!1),n(24,z=null);const e=document.getElementById("sprocket-upload-file");e&&(e.value="")}},pe,function(){n(0,c=!c),"undefined"!=typeof localStorage&&localStorage.setItem("isDarkTheme",JSON.stringify(c))},function(){u||n(11,l=!0)},async function(e){const{method:t,pubkey:r,privateKey:o,signer:i}=e.detail;n(1,u=!0),n(2,d=r),f=t,n(12,g=i),n(11,l=!1);try{if(await mh(),"extension"===t&&i)oh.setSigner(i);else if("nsec"===t&&o){const e=new qd(o);oh.setSigner(e)}n(3,h=await hh(r)),console.log("Profile loaded:",h)}catch(e){console.error("Failed to load profile:",e)}await be(),await Ee()},function(){n(1,u=!1),n(2,d=""),f="",n(3,h=null),n(4,p=""),n(12,g=null),n(13,y=!1),L=[],n(79,k=[]),R=[],j=0,se(),"undefined"!=typeof localStorage&&(localStorage.removeItem("nostr_auth_method"),localStorage.removeItem("nostr_pubkey"),localStorage.removeItem("nostr_privkey"))},function(){n(11,l=!1)},function(){n(13,y=!0)},ge,function(){n(14,v=!v),v||n(15,w="")},function(e){"Enter"===e.key&&w.trim()?(!function(e){const t=`search-${Date.now()}`,r={id:t,icon:"🔍",label:e,isSearchTab:!0,query:e};n(6,E=[...E,r]),n(5,m=t),_.set(t,{events:[],isLoading:!1,hasMore:!0,oldestTimestamp:null}),me(t,e)}(w.trim()),n(15,w=""),n(14,v=!1)):"Escape"===e.key&&(n(14,v=!1),n(15,w=""))},ye,me,ve,we,async function(){await ke([])},async function(){await ke([d])},function(e){n(16,x=e.target.files[0])},async function(){if(!u||"admin"!==p&&"owner"!==p)alert("Admin or owner permission required");else if(x)try{const e=await Ae("/api/import","POST"),t=new FormData;t.append("file",x);const r=await fetch("/api/import",{method:"POST",headers:{Authorization:e},body:t});if(!r.ok)throw new Error(`Import failed: ${r.status} ${r.statusText}`);await r.json();alert("Import started successfully"),n(16,x=null),document.getElementById("import-file").value=""}catch(e){console.error("Import failed:",e),alert("Import failed: "+e.message)}else alert("Please select a file")},xe,function(e){const{scrollTop:t,scrollHeight:n,clientHeight:r}=e.target;n-t-r<100&&Se()},function(){try{if(!W.trim())return void alert("Please enter some JSON to reformat");const e=JSON.parse(W);n(25,W=JSON.stringify(e,null,2))}catch(e){alert("Invalid JSON: "+e.message)}},async function(){try{if(!W.trim())return void alert("Please enter an event to sign");if(!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(W);e.pubkey=d,e.created_at=Math.floor(Date.now()/1e3),delete e.id,delete e.sig;const t=await g.signEvent(e);n(25,W=JSON.stringify(t,null,2)),alert("Event signed successfully!")}catch(e){console.error("Error signing event:",e),alert("Error signing event: "+e.message)}},async function(){try{if(!W.trim())return void alert("Please enter an event to publish");if(!u)return void alert("Please log in to publish events");if(!g)return void alert("No signer available. Please log in with a valid authentication method.");const e=JSON.parse(W);if(!e.id||!e.sig)return void alert('Event must be signed before publishing. Please click "Sign" first.');const t=`wss://${window.location.host}`,n=await Lg(t,e,g,d);n.success?alert("Event published successfully to ORLY relay!"):alert(`Event publishing failed: ${n.reason||"Unknown error"}`)}catch(e){console.error("Error publishing event:",e),alert("Error publishing event: "+e.message)}},Te,function(){const e=["owner","admin","write","read"],t=e.indexOf(p);return-1===t?["read"]:e.slice(t)},k,T,q,Ce,i,function(t){I.call(this,e,t)},function(t){I.call(this,e,t)},e=>e.id===m,function(e){w=e,n(15,w)},e=>pe(e.detail),e=>ye(e.detail),e=>te(e.detail),e=>ne(e.detail),e=>Ly(e.detail.event,e.detail.e),e=>xe(e.detail.refresh,e.detail.authors),function(e){W=e,n(25,W)},function(e){N=e,n(18,N)},e=>ue(e.detail),e=>de(e.detail),function(){V=function(e){const t=e.querySelector(":checked");return t&&t.__value}(this),n(26,V),n(34,X)},function(){J=b(this.value),n(27,J)},e=>ie(e),e=>oe(e),(e,t)=>Ly(e,t),e=>me(e.id,e.query,!0),e=>ne(e.id),e=>te(e.id),(e,t)=>"Enter"===t.key&&te(e.id),(e,t)=>Ly(e,t),(e,t)=>ve(t,e.id),e=>Te(e===p?"":e),e=>"Escape"===e.key&&ge(),function(e){l=e,n(11,l)}]}return new class extends ee{constructor(e){super(),X(this,e,Py,Iy,i,{},null,[-1,-1,-1,-1,-1,-1])}}({target:document.body,props:{name:"world"}})}(); |