ncc-client-poc 0.1.1 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ var Ci=Object.defineProperty;var Oi=(e,t,n)=>t in e?Ci(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var m=(e,t,n)=>Oi(e,typeof t!="symbol"?t+"":t,n);function Rn(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`Wrong positive integer: ${e}`)}function Xn(e,...t){if(!(e instanceof Uint8Array))throw new Error("Expected Uint8Array");if(t.length>0&&!t.includes(e.length))throw new Error(`Expected Uint8Array of length ${t}, not of length=${e.length}`)}function Hi(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");Rn(e.outputLen),Rn(e.blockLen)}function nt(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function Pi(e,t){Xn(e);const n=t.outputLen;if(e.length<n)throw new Error(`digestInto() expects output buffer of length at least ${n}`)}const At=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Yn=e=>e instanceof Uint8Array,St=e=>new DataView(e.buffer,e.byteOffset,e.byteLength),ee=(e,t)=>e<<32-t|e>>>t,Mi=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!Mi)throw new Error("Non little-endian hardware is not supported");function qi(e){if(typeof e!="string")throw new Error(`utf8ToBytes expected string, got ${typeof e}`);return new Uint8Array(new TextEncoder().encode(e))}function Kt(e){if(typeof e=="string"&&(e=qi(e)),!Yn(e))throw new Error(`expected Uint8Array, got ${typeof e}`);return e}function Vi(...e){const t=new Uint8Array(e.reduce((r,i)=>r+i.length,0));let n=0;return e.forEach(r=>{if(!Yn(r))throw new Error("Uint8Array expected");t.set(r,n),n+=r.length}),t}let Qn=class{clone(){return this._cloneInto()}};function zi(e){const t=r=>e().update(Kt(r)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function er(e=32){if(At&&typeof At.getRandomValues=="function")return At.getRandomValues(new Uint8Array(e));throw new Error("crypto.getRandomValues must be defined")}function Di(e,t,n,r){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,n,r);const i=BigInt(32),o=BigInt(4294967295),s=Number(n>>i&o),c=Number(n&o),a=r?4:0,l=r?0:4;e.setUint32(t+a,s,r),e.setUint32(t+l,c,r)}let Fi=class extends Qn{constructor(t,n,r,i){super(),this.blockLen=t,this.outputLen=n,this.padOffset=r,this.isLE=i,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=St(this.buffer)}update(t){nt(this);const{view:n,buffer:r,blockLen:i}=this;t=Kt(t);const o=t.length;for(let s=0;s<o;){const c=Math.min(i-this.pos,o-s);if(c===i){const a=St(t);for(;i<=o-s;s+=i)this.process(a,s);continue}r.set(t.subarray(s,s+c),this.pos),this.pos+=c,s+=c,this.pos===i&&(this.process(n,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){nt(this),Pi(t,this),this.finished=!0;const{buffer:n,view:r,blockLen:i,isLE:o}=this;let{pos:s}=this;n[s++]=128,this.buffer.subarray(s).fill(0),this.padOffset>i-s&&(this.process(r,0),s=0);for(let u=s;u<i;u++)n[u]=0;Di(r,i-8,BigInt(this.length*8),o),this.process(r,0);const c=St(t),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const l=a/4,f=this.get();if(l>f.length)throw new Error("_sha2: outputLen bigger than state");for(let u=0;u<l;u++)c.setUint32(4*u,f[u],o)}digest(){const{buffer:t,outputLen:n}=this;this.digestInto(t);const r=t.slice(0,n);return this.destroy(),r}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());const{blockLen:n,buffer:r,length:i,finished:o,destroyed:s,pos:c}=this;return t.length=i,t.pos=c,t.finished=o,t.destroyed=s,i%n&&t.buffer.set(r),t}};const ji=(e,t,n)=>e&t^~e&n,Wi=(e,t,n)=>e&t^e&n^t&n,Gi=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),we=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),be=new Uint32Array(64);let Ki=class extends Fi{constructor(){super(64,32,8,!1),this.A=we[0]|0,this.B=we[1]|0,this.C=we[2]|0,this.D=we[3]|0,this.E=we[4]|0,this.F=we[5]|0,this.G=we[6]|0,this.H=we[7]|0}get(){const{A:t,B:n,C:r,D:i,E:o,F:s,G:c,H:a}=this;return[t,n,r,i,o,s,c,a]}set(t,n,r,i,o,s,c,a){this.A=t|0,this.B=n|0,this.C=r|0,this.D=i|0,this.E=o|0,this.F=s|0,this.G=c|0,this.H=a|0}process(t,n){for(let u=0;u<16;u++,n+=4)be[u]=t.getUint32(n,!1);for(let u=16;u<64;u++){const p=be[u-15],y=be[u-2],g=ee(p,7)^ee(p,18)^p>>>3,h=ee(y,17)^ee(y,19)^y>>>10;be[u]=h+be[u-7]+g+be[u-16]|0}let{A:r,B:i,C:o,D:s,E:c,F:a,G:l,H:f}=this;for(let u=0;u<64;u++){const p=ee(c,6)^ee(c,11)^ee(c,25),y=f+p+ji(c,a,l)+Gi[u]+be[u]|0,h=(ee(r,2)^ee(r,13)^ee(r,22))+Wi(r,i,o)|0;f=l,l=a,a=c,c=s+y|0,s=o,o=i,i=r,r=y+h|0}r=r+this.A|0,i=i+this.B|0,o=o+this.C|0,s=s+this.D|0,c=c+this.E|0,a=a+this.F|0,l=l+this.G|0,f=f+this.H|0,this.set(r,i,o,s,c,a,l,f)}roundClean(){be.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};const Ot=zi(()=>new Ki);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const tr=BigInt(0),ct=BigInt(1),Zi=BigInt(2),lt=e=>e instanceof Uint8Array,Ji=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Ve(e){if(!lt(e))throw new Error("Uint8Array expected");let t="";for(let n=0;n<e.length;n++)t+=Ji[e[n]];return t}function nr(e){const t=e.toString(16);return t.length&1?`0${t}`:t}function Zt(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return BigInt(e===""?"0":`0x${e}`)}function ze(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);const t=e.length;if(t%2)throw new Error("padded hex string expected, got unpadded hex of length "+t);const n=new Uint8Array(t/2);for(let r=0;r<n.length;r++){const i=r*2,o=e.slice(i,i+2),s=Number.parseInt(o,16);if(Number.isNaN(s)||s<0)throw new Error("Invalid byte sequence");n[r]=s}return n}function K(e){return Zt(Ve(e))}function Jt(e){if(!lt(e))throw new Error("Uint8Array expected");return Zt(Ve(Uint8Array.from(e).reverse()))}function Ae(e,t){return ze(e.toString(16).padStart(t*2,"0"))}function Xt(e,t){return Ae(e,t).reverse()}function Xi(e){return ze(nr(e))}function j(e,t,n){let r;if(typeof t=="string")try{r=ze(t)}catch(o){throw new Error(`${e} must be valid hex string, got "${t}". Cause: ${o}`)}else if(lt(t))r=Uint8Array.from(t);else throw new Error(`${e} must be hex string or Uint8Array`);const i=r.length;if(typeof n=="number"&&i!==n)throw new Error(`${e} expected ${n} bytes, got ${i}`);return r}function Re(...e){const t=new Uint8Array(e.reduce((r,i)=>r+i.length,0));let n=0;return e.forEach(r=>{if(!lt(r))throw new Error("Uint8Array expected");t.set(r,n),n+=r.length}),t}function Yi(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}function Qi(e){if(typeof e!="string")throw new Error(`utf8ToBytes expected string, got ${typeof e}`);return new Uint8Array(new TextEncoder().encode(e))}function eo(e){let t;for(t=0;e>tr;e>>=ct,t+=1);return t}function to(e,t){return e>>BigInt(t)&ct}const no=(e,t,n)=>e|(n?ct:tr)<<BigInt(t),Yt=e=>(Zi<<BigInt(e-1))-ct,_t=e=>new Uint8Array(e),Un=e=>Uint8Array.from(e);function rr(e,t,n){if(typeof e!="number"||e<2)throw new Error("hashLen must be a number");if(typeof t!="number"||t<2)throw new Error("qByteLen must be a number");if(typeof n!="function")throw new Error("hmacFn must be a function");let r=_t(e),i=_t(e),o=0;const s=()=>{r.fill(1),i.fill(0),o=0},c=(...u)=>n(i,r,...u),a=(u=_t())=>{i=c(Un([0]),u),r=c(),u.length!==0&&(i=c(Un([1]),u),r=c())},l=()=>{if(o++>=1e3)throw new Error("drbg: tried 1000 values");let u=0;const p=[];for(;u<t;){r=c();const y=r.slice();p.push(y),u+=r.length}return Re(...p)};return(u,p)=>{s(),a(u);let y;for(;!(y=p(l()));)a();return s(),y}}const ro={bigint:e=>typeof e=="bigint",function:e=>typeof e=="function",boolean:e=>typeof e=="boolean",string:e=>typeof e=="string",stringOrUint8Array:e=>typeof e=="string"||e instanceof Uint8Array,isSafeInteger:e=>Number.isSafeInteger(e),array:e=>Array.isArray(e),field:(e,t)=>t.Fp.isValid(e),hash:e=>typeof e=="function"&&Number.isSafeInteger(e.outputLen)};function Xe(e,t,n={}){const r=(i,o,s)=>{const c=ro[o];if(typeof c!="function")throw new Error(`Invalid validator "${o}", expected function`);const a=e[i];if(!(s&&a===void 0)&&!c(a,e))throw new Error(`Invalid param ${String(i)}=${a} (${typeof a}), expected ${o}`)};for(const[i,o]of Object.entries(t))r(i,o,!1);for(const[i,o]of Object.entries(n))r(i,o,!0);return e}const io=Object.freeze(Object.defineProperty({__proto__:null,bitGet:to,bitLen:eo,bitMask:Yt,bitSet:no,bytesToHex:Ve,bytesToNumberBE:K,bytesToNumberLE:Jt,concatBytes:Re,createHmacDrbg:rr,ensureBytes:j,equalBytes:Yi,hexToBytes:ze,hexToNumber:Zt,numberToBytesBE:Ae,numberToBytesLE:Xt,numberToHexUnpadded:nr,numberToVarBytesBE:Xi,utf8ToBytes:Qi,validateObject:Xe},Symbol.toStringTag,{value:"Module"}));/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const D=BigInt(0),z=BigInt(1),Ie=BigInt(2),oo=BigInt(3),Ht=BigInt(4),$n=BigInt(5),Nn=BigInt(8);BigInt(9);BigInt(16);function F(e,t){const n=e%t;return n>=D?n:t+n}function so(e,t,n){if(n<=D||t<D)throw new Error("Expected power/modulo > 0");if(n===z)return D;let r=z;for(;t>D;)t&z&&(r=r*e%n),e=e*e%n,t>>=z;return r}function Z(e,t,n){let r=e;for(;t-- >D;)r*=r,r%=n;return r}function Pt(e,t){if(e===D||t<=D)throw new Error(`invert: expected positive integers, got n=${e} mod=${t}`);let n=F(e,t),r=t,i=D,o=z;for(;n!==D;){const c=r/n,a=r%n,l=i-o*c;r=n,n=a,i=o,o=l}if(r!==z)throw new Error("invert: does not exist");return F(i,t)}function ao(e){const t=(e-z)/Ie;let n,r,i;for(n=e-z,r=0;n%Ie===D;n/=Ie,r++);for(i=Ie;i<e&&so(i,t,e)!==e-z;i++);if(r===1){const s=(e+z)/Ht;return function(a,l){const f=a.pow(l,s);if(!a.eql(a.sqr(f),l))throw new Error("Cannot find square root");return f}}const o=(n+z)/Ie;return function(c,a){if(c.pow(a,t)===c.neg(c.ONE))throw new Error("Cannot find square root");let l=r,f=c.pow(c.mul(c.ONE,i),n),u=c.pow(a,o),p=c.pow(a,n);for(;!c.eql(p,c.ONE);){if(c.eql(p,c.ZERO))return c.ZERO;let y=1;for(let h=c.sqr(p);y<l&&!c.eql(h,c.ONE);y++)h=c.sqr(h);const g=c.pow(f,z<<BigInt(l-y-1));f=c.sqr(g),u=c.mul(u,g),p=c.mul(p,f),l=y}return u}}function co(e){if(e%Ht===oo){const t=(e+z)/Ht;return function(r,i){const o=r.pow(i,t);if(!r.eql(r.sqr(o),i))throw new Error("Cannot find square root");return o}}if(e%Nn===$n){const t=(e-$n)/Nn;return function(r,i){const o=r.mul(i,Ie),s=r.pow(o,t),c=r.mul(i,s),a=r.mul(r.mul(c,Ie),s),l=r.mul(c,r.sub(a,r.ONE));if(!r.eql(r.sqr(l),i))throw new Error("Cannot find square root");return l}}return ao(e)}const lo=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function uo(e){const t={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},n=lo.reduce((r,i)=>(r[i]="function",r),t);return Xe(e,n)}function fo(e,t,n){if(n<D)throw new Error("Expected power > 0");if(n===D)return e.ONE;if(n===z)return t;let r=e.ONE,i=t;for(;n>D;)n&z&&(r=e.mul(r,i)),i=e.sqr(i),n>>=z;return r}function ho(e,t){const n=new Array(t.length),r=t.reduce((o,s,c)=>e.is0(s)?o:(n[c]=o,e.mul(o,s)),e.ONE),i=e.inv(r);return t.reduceRight((o,s,c)=>e.is0(s)?o:(n[c]=e.mul(o,n[c]),e.mul(o,s)),i),n}function ir(e,t){const n=t!==void 0?t:e.toString(2).length,r=Math.ceil(n/8);return{nBitLength:n,nByteLength:r}}function go(e,t,n=!1,r={}){if(e<=D)throw new Error(`Expected Field ORDER > 0, got ${e}`);const{nBitLength:i,nByteLength:o}=ir(e,t);if(o>2048)throw new Error("Field lengths over 2048 bytes are not supported");const s=co(e),c=Object.freeze({ORDER:e,BITS:i,BYTES:o,MASK:Yt(i),ZERO:D,ONE:z,create:a=>F(a,e),isValid:a=>{if(typeof a!="bigint")throw new Error(`Invalid field element: expected bigint, got ${typeof a}`);return D<=a&&a<e},is0:a=>a===D,isOdd:a=>(a&z)===z,neg:a=>F(-a,e),eql:(a,l)=>a===l,sqr:a=>F(a*a,e),add:(a,l)=>F(a+l,e),sub:(a,l)=>F(a-l,e),mul:(a,l)=>F(a*l,e),pow:(a,l)=>fo(c,a,l),div:(a,l)=>F(a*Pt(l,e),e),sqrN:a=>a*a,addN:(a,l)=>a+l,subN:(a,l)=>a-l,mulN:(a,l)=>a*l,inv:a=>Pt(a,e),sqrt:r.sqrt||(a=>s(c,a)),invertBatch:a=>ho(c,a),cmov:(a,l,f)=>f?l:a,toBytes:a=>n?Xt(a,o):Ae(a,o),fromBytes:a=>{if(a.length!==o)throw new Error(`Fp.fromBytes: expected ${o}, got ${a.length}`);return n?Jt(a):K(a)}});return Object.freeze(c)}function or(e){if(typeof e!="bigint")throw new Error("field order must be bigint");const t=e.toString(2).length;return Math.ceil(t/8)}function sr(e){const t=or(e);return t+Math.ceil(t/2)}function po(e,t,n=!1){const r=e.length,i=or(t),o=sr(t);if(r<16||r<o||r>1024)throw new Error(`expected ${o}-1024 bytes of input, got ${r}`);const s=n?K(e):Jt(e),c=F(s,t-z)+z;return n?Xt(c,i):Ae(c,i)}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const yo=BigInt(0),Bt=BigInt(1);function wo(e,t){const n=(i,o)=>{const s=o.negate();return i?s:o},r=i=>{const o=Math.ceil(t/i)+1,s=2**(i-1);return{windows:o,windowSize:s}};return{constTimeNegate:n,unsafeLadder(i,o){let s=e.ZERO,c=i;for(;o>yo;)o&Bt&&(s=s.add(c)),c=c.double(),o>>=Bt;return s},precomputeWindow(i,o){const{windows:s,windowSize:c}=r(o),a=[];let l=i,f=l;for(let u=0;u<s;u++){f=l,a.push(f);for(let p=1;p<c;p++)f=f.add(l),a.push(f);l=f.double()}return a},wNAF(i,o,s){const{windows:c,windowSize:a}=r(i);let l=e.ZERO,f=e.BASE;const u=BigInt(2**i-1),p=2**i,y=BigInt(i);for(let g=0;g<c;g++){const h=g*a;let d=Number(s&u);s>>=y,d>a&&(d-=p,s+=Bt);const w=h,v=h+Math.abs(d)-1,S=g%2!==0,L=d<0;d===0?f=f.add(n(S,o[w])):l=l.add(n(L,o[v]))}return{p:l,f}},wNAFCached(i,o,s,c){const a=i._WINDOW_SIZE||1;let l=o.get(i);return l||(l=this.precomputeWindow(i,a),a!==1&&o.set(i,c(l))),this.wNAF(a,l,s)}}}function ar(e){return uo(e.Fp),Xe(e,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...ir(e.n,e.nBitLength),...e,p:e.Fp.ORDER})}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function bo(e){const t=ar(e);Xe(t,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});const{endo:n,Fp:r,a:i}=t;if(n){if(!r.eql(i,r.ZERO))throw new Error("Endomorphism can only be defined for Koblitz curves that have a=0");if(typeof n!="object"||typeof n.beta!="bigint"||typeof n.splitScalar!="function")throw new Error("Expected endomorphism with beta: bigint and splitScalar: function")}return Object.freeze({...t})}const{bytesToNumberBE:mo,hexToBytes:Eo}=io,ke={Err:class extends Error{constructor(t=""){super(t)}},_parseInt(e){const{Err:t}=ke;if(e.length<2||e[0]!==2)throw new t("Invalid signature integer tag");const n=e[1],r=e.subarray(2,n+2);if(!n||r.length!==n)throw new t("Invalid signature integer: wrong length");if(r[0]&128)throw new t("Invalid signature integer: negative");if(r[0]===0&&!(r[1]&128))throw new t("Invalid signature integer: unnecessary leading zero");return{d:mo(r),l:e.subarray(n+2)}},toSig(e){const{Err:t}=ke,n=typeof e=="string"?Eo(e):e;if(!(n instanceof Uint8Array))throw new Error("ui8a expected");let r=n.length;if(r<2||n[0]!=48)throw new t("Invalid signature tag");if(n[1]!==r-2)throw new t("Invalid signature: incorrect length");const{d:i,l:o}=ke._parseInt(n.subarray(2)),{d:s,l:c}=ke._parseInt(o);if(c.length)throw new t("Invalid signature: left bytes after parsing");return{r:i,s}},hexFromSig(e){const t=l=>Number.parseInt(l[0],16)&8?"00"+l:l,n=l=>{const f=l.toString(16);return f.length&1?`0${f}`:f},r=t(n(e.s)),i=t(n(e.r)),o=r.length/2,s=i.length/2,c=n(o),a=n(s);return`30${n(s+o+4)}02${a}${i}02${c}${r}`}},ce=BigInt(0),J=BigInt(1);BigInt(2);const Cn=BigInt(3);BigInt(4);function vo(e){const t=bo(e),{Fp:n}=t,r=t.toBytes||((g,h,d)=>{const w=h.toAffine();return Re(Uint8Array.from([4]),n.toBytes(w.x),n.toBytes(w.y))}),i=t.fromBytes||(g=>{const h=g.subarray(1),d=n.fromBytes(h.subarray(0,n.BYTES)),w=n.fromBytes(h.subarray(n.BYTES,2*n.BYTES));return{x:d,y:w}});function o(g){const{a:h,b:d}=t,w=n.sqr(g),v=n.mul(w,g);return n.add(n.add(v,n.mul(g,h)),d)}if(!n.eql(n.sqr(t.Gy),o(t.Gx)))throw new Error("bad generator point: equation left != right");function s(g){return typeof g=="bigint"&&ce<g&&g<t.n}function c(g){if(!s(g))throw new Error("Expected valid bigint: 0 < bigint < curve.n")}function a(g){const{allowedPrivateKeyLengths:h,nByteLength:d,wrapPrivateKey:w,n:v}=t;if(h&&typeof g!="bigint"){if(g instanceof Uint8Array&&(g=Ve(g)),typeof g!="string"||!h.includes(g.length))throw new Error("Invalid key");g=g.padStart(d*2,"0")}let S;try{S=typeof g=="bigint"?g:K(j("private key",g,d))}catch{throw new Error(`private key must be ${d} bytes, hex or bigint, not ${typeof g}`)}return w&&(S=F(S,v)),c(S),S}const l=new Map;function f(g){if(!(g instanceof u))throw new Error("ProjectivePoint expected")}class u{constructor(h,d,w){if(this.px=h,this.py=d,this.pz=w,h==null||!n.isValid(h))throw new Error("x required");if(d==null||!n.isValid(d))throw new Error("y required");if(w==null||!n.isValid(w))throw new Error("z required")}static fromAffine(h){const{x:d,y:w}=h||{};if(!h||!n.isValid(d)||!n.isValid(w))throw new Error("invalid affine point");if(h instanceof u)throw new Error("projective point not allowed");const v=S=>n.eql(S,n.ZERO);return v(d)&&v(w)?u.ZERO:new u(d,w,n.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(h){const d=n.invertBatch(h.map(w=>w.pz));return h.map((w,v)=>w.toAffine(d[v])).map(u.fromAffine)}static fromHex(h){const d=u.fromAffine(i(j("pointHex",h)));return d.assertValidity(),d}static fromPrivateKey(h){return u.BASE.multiply(a(h))}_setWindowSize(h){this._WINDOW_SIZE=h,l.delete(this)}assertValidity(){if(this.is0()){if(t.allowInfinityPoint&&!n.is0(this.py))return;throw new Error("bad point: ZERO")}const{x:h,y:d}=this.toAffine();if(!n.isValid(h)||!n.isValid(d))throw new Error("bad point: x or y not FE");const w=n.sqr(d),v=o(h);if(!n.eql(w,v))throw new Error("bad point: equation left != right");if(!this.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){const{y:h}=this.toAffine();if(n.isOdd)return!n.isOdd(h);throw new Error("Field doesn't support isOdd")}equals(h){f(h);const{px:d,py:w,pz:v}=this,{px:S,py:L,pz:k}=h,x=n.eql(n.mul(d,k),n.mul(S,v)),A=n.eql(n.mul(w,k),n.mul(L,v));return x&&A}negate(){return new u(this.px,n.neg(this.py),this.pz)}double(){const{a:h,b:d}=t,w=n.mul(d,Cn),{px:v,py:S,pz:L}=this;let k=n.ZERO,x=n.ZERO,A=n.ZERO,_=n.mul(v,v),M=n.mul(S,S),U=n.mul(L,L),T=n.mul(v,S);return T=n.add(T,T),A=n.mul(v,L),A=n.add(A,A),k=n.mul(h,A),x=n.mul(w,U),x=n.add(k,x),k=n.sub(M,x),x=n.add(M,x),x=n.mul(k,x),k=n.mul(T,k),A=n.mul(w,A),U=n.mul(h,U),T=n.sub(_,U),T=n.mul(h,T),T=n.add(T,A),A=n.add(_,_),_=n.add(A,_),_=n.add(_,U),_=n.mul(_,T),x=n.add(x,_),U=n.mul(S,L),U=n.add(U,U),_=n.mul(U,T),k=n.sub(k,_),A=n.mul(U,M),A=n.add(A,A),A=n.add(A,A),new u(k,x,A)}add(h){f(h);const{px:d,py:w,pz:v}=this,{px:S,py:L,pz:k}=h;let x=n.ZERO,A=n.ZERO,_=n.ZERO;const M=t.a,U=n.mul(t.b,Cn);let T=n.mul(d,S),O=n.mul(w,L),H=n.mul(v,k),V=n.add(d,w),b=n.add(S,L);V=n.mul(V,b),b=n.add(T,O),V=n.sub(V,b),b=n.add(d,v);let E=n.add(S,k);return b=n.mul(b,E),E=n.add(T,H),b=n.sub(b,E),E=n.add(w,v),x=n.add(L,k),E=n.mul(E,x),x=n.add(O,H),E=n.sub(E,x),_=n.mul(M,b),x=n.mul(U,H),_=n.add(x,_),x=n.sub(O,_),_=n.add(O,_),A=n.mul(x,_),O=n.add(T,T),O=n.add(O,T),H=n.mul(M,H),b=n.mul(U,b),O=n.add(O,H),H=n.sub(T,H),H=n.mul(M,H),b=n.add(b,H),T=n.mul(O,b),A=n.add(A,T),T=n.mul(E,b),x=n.mul(V,x),x=n.sub(x,T),T=n.mul(V,O),_=n.mul(E,_),_=n.add(_,T),new u(x,A,_)}subtract(h){return this.add(h.negate())}is0(){return this.equals(u.ZERO)}wNAF(h){return y.wNAFCached(this,l,h,d=>{const w=n.invertBatch(d.map(v=>v.pz));return d.map((v,S)=>v.toAffine(w[S])).map(u.fromAffine)})}multiplyUnsafe(h){const d=u.ZERO;if(h===ce)return d;if(c(h),h===J)return this;const{endo:w}=t;if(!w)return y.unsafeLadder(this,h);let{k1neg:v,k1:S,k2neg:L,k2:k}=w.splitScalar(h),x=d,A=d,_=this;for(;S>ce||k>ce;)S&J&&(x=x.add(_)),k&J&&(A=A.add(_)),_=_.double(),S>>=J,k>>=J;return v&&(x=x.negate()),L&&(A=A.negate()),A=new u(n.mul(A.px,w.beta),A.py,A.pz),x.add(A)}multiply(h){c(h);let d=h,w,v;const{endo:S}=t;if(S){const{k1neg:L,k1:k,k2neg:x,k2:A}=S.splitScalar(d);let{p:_,f:M}=this.wNAF(k),{p:U,f:T}=this.wNAF(A);_=y.constTimeNegate(L,_),U=y.constTimeNegate(x,U),U=new u(n.mul(U.px,S.beta),U.py,U.pz),w=_.add(U),v=M.add(T)}else{const{p:L,f:k}=this.wNAF(d);w=L,v=k}return u.normalizeZ([w,v])[0]}multiplyAndAddUnsafe(h,d,w){const v=u.BASE,S=(k,x)=>x===ce||x===J||!k.equals(v)?k.multiplyUnsafe(x):k.multiply(x),L=S(this,d).add(S(h,w));return L.is0()?void 0:L}toAffine(h){const{px:d,py:w,pz:v}=this,S=this.is0();h==null&&(h=S?n.ONE:n.inv(v));const L=n.mul(d,h),k=n.mul(w,h),x=n.mul(v,h);if(S)return{x:n.ZERO,y:n.ZERO};if(!n.eql(x,n.ONE))throw new Error("invZ was invalid");return{x:L,y:k}}isTorsionFree(){const{h,isTorsionFree:d}=t;if(h===J)return!0;if(d)return d(u,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){const{h,clearCofactor:d}=t;return h===J?this:d?d(u,this):this.multiplyUnsafe(t.h)}toRawBytes(h=!0){return this.assertValidity(),r(u,this,h)}toHex(h=!0){return Ve(this.toRawBytes(h))}}u.BASE=new u(t.Gx,t.Gy,n.ONE),u.ZERO=new u(n.ZERO,n.ONE,n.ZERO);const p=t.nBitLength,y=wo(u,t.endo?Math.ceil(p/2):p);return{CURVE:t,ProjectivePoint:u,normPrivateKeyToScalar:a,weierstrassEquation:o,isWithinCurveOrder:s}}function xo(e){const t=ar(e);return Xe(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}function Ao(e){const t=xo(e),{Fp:n,n:r}=t,i=n.BYTES+1,o=2*n.BYTES+1;function s(b){return ce<b&&b<n.ORDER}function c(b){return F(b,r)}function a(b){return Pt(b,r)}const{ProjectivePoint:l,normPrivateKeyToScalar:f,weierstrassEquation:u,isWithinCurveOrder:p}=vo({...t,toBytes(b,E,B){const R=E.toAffine(),I=n.toBytes(R.x),$=Re;return B?$(Uint8Array.from([E.hasEvenY()?2:3]),I):$(Uint8Array.from([4]),I,n.toBytes(R.y))},fromBytes(b){const E=b.length,B=b[0],R=b.subarray(1);if(E===i&&(B===2||B===3)){const I=K(R);if(!s(I))throw new Error("Point is not on curve");const $=u(I);let P=n.sqrt($);const C=(P&J)===J;return(B&1)===1!==C&&(P=n.neg(P)),{x:I,y:P}}else if(E===o&&B===4){const I=n.fromBytes(R.subarray(0,n.BYTES)),$=n.fromBytes(R.subarray(n.BYTES,2*n.BYTES));return{x:I,y:$}}else throw new Error(`Point of length ${E} was invalid. Expected ${i} compressed bytes or ${o} uncompressed bytes`)}}),y=b=>Ve(Ae(b,t.nByteLength));function g(b){const E=r>>J;return b>E}function h(b){return g(b)?c(-b):b}const d=(b,E,B)=>K(b.slice(E,B));class w{constructor(E,B,R){this.r=E,this.s=B,this.recovery=R,this.assertValidity()}static fromCompact(E){const B=t.nByteLength;return E=j("compactSignature",E,B*2),new w(d(E,0,B),d(E,B,2*B))}static fromDER(E){const{r:B,s:R}=ke.toSig(j("DER",E));return new w(B,R)}assertValidity(){if(!p(this.r))throw new Error("r must be 0 < r < CURVE.n");if(!p(this.s))throw new Error("s must be 0 < s < CURVE.n")}addRecoveryBit(E){return new w(this.r,this.s,E)}recoverPublicKey(E){const{r:B,s:R,recovery:I}=this,$=A(j("msgHash",E));if(I==null||![0,1,2,3].includes(I))throw new Error("recovery id invalid");const P=I===2||I===3?B+t.n:B;if(P>=n.ORDER)throw new Error("recovery id 2 or 3 invalid");const C=I&1?"03":"02",X=l.fromHex(C+y(P)),pe=a(P),Ne=c(-$*pe),We=c(R*pe),ye=l.BASE.multiplyAndAddUnsafe(X,Ne,We);if(!ye)throw new Error("point at infinify");return ye.assertValidity(),ye}hasHighS(){return g(this.s)}normalizeS(){return this.hasHighS()?new w(this.r,c(-this.s),this.recovery):this}toDERRawBytes(){return ze(this.toDERHex())}toDERHex(){return ke.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return ze(this.toCompactHex())}toCompactHex(){return y(this.r)+y(this.s)}}const v={isValidPrivateKey(b){try{return f(b),!0}catch{return!1}},normPrivateKeyToScalar:f,randomPrivateKey:()=>{const b=sr(t.n);return po(t.randomBytes(b),t.n)},precompute(b=8,E=l.BASE){return E._setWindowSize(b),E.multiply(BigInt(3)),E}};function S(b,E=!0){return l.fromPrivateKey(b).toRawBytes(E)}function L(b){const E=b instanceof Uint8Array,B=typeof b=="string",R=(E||B)&&b.length;return E?R===i||R===o:B?R===2*i||R===2*o:b instanceof l}function k(b,E,B=!0){if(L(b))throw new Error("first arg must be private key");if(!L(E))throw new Error("second arg must be public key");return l.fromHex(E).multiply(f(b)).toRawBytes(B)}const x=t.bits2int||function(b){const E=K(b),B=b.length*8-t.nBitLength;return B>0?E>>BigInt(B):E},A=t.bits2int_modN||function(b){return c(x(b))},_=Yt(t.nBitLength);function M(b){if(typeof b!="bigint")throw new Error("bigint expected");if(!(ce<=b&&b<_))throw new Error(`bigint expected < 2^${t.nBitLength}`);return Ae(b,t.nByteLength)}function U(b,E,B=T){if(["recovered","canonical"].some(_e=>_e in B))throw new Error("sign() legacy options not supported");const{hash:R,randomBytes:I}=t;let{lowS:$,prehash:P,extraEntropy:C}=B;$==null&&($=!0),b=j("msgHash",b),P&&(b=j("prehashed msgHash",R(b)));const X=A(b),pe=f(E),Ne=[M(pe),M(X)];if(C!=null){const _e=C===!0?I(n.BYTES):C;Ne.push(j("extraEntropy",_e))}const We=Re(...Ne),ye=X;function xt(_e){const Ce=x(_e);if(!p(Ce))return;const In=a(Ce),Oe=l.BASE.multiply(Ce).toAffine(),Y=c(Oe.x);if(Y===ce)return;const He=c(In*c(ye+Y*pe));if(He===ce)return;let Ln=(Oe.x===Y?0:2)|Number(Oe.y&J),kn=He;return $&&g(He)&&(kn=h(He),Ln^=1),new w(Y,kn,Ln)}return{seed:We,k2sig:xt}}const T={lowS:t.lowS,prehash:!1},O={lowS:t.lowS,prehash:!1};function H(b,E,B=T){const{seed:R,k2sig:I}=U(b,E,B),$=t;return rr($.hash.outputLen,$.nByteLength,$.hmac)(R,I)}l.BASE._setWindowSize(8);function V(b,E,B,R=O){var Oe;const I=b;if(E=j("msgHash",E),B=j("publicKey",B),"strict"in R)throw new Error("options.strict was renamed to lowS");const{lowS:$,prehash:P}=R;let C,X;try{if(typeof I=="string"||I instanceof Uint8Array)try{C=w.fromDER(I)}catch(Y){if(!(Y instanceof ke.Err))throw Y;C=w.fromCompact(I)}else if(typeof I=="object"&&typeof I.r=="bigint"&&typeof I.s=="bigint"){const{r:Y,s:He}=I;C=new w(Y,He)}else throw new Error("PARSE");X=l.fromHex(B)}catch(Y){if(Y.message==="PARSE")throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if($&&C.hasHighS())return!1;P&&(E=t.hash(E));const{r:pe,s:Ne}=C,We=A(E),ye=a(Ne),xt=c(We*ye),_e=c(pe*ye),Ce=(Oe=l.BASE.multiplyAndAddUnsafe(X,xt,_e))==null?void 0:Oe.toAffine();return Ce?c(Ce.x)===pe:!1}return{CURVE:t,getPublicKey:S,getSharedSecret:k,sign:H,verify:V,ProjectivePoint:l,Signature:w,utils:v}}let cr=class extends Qn{constructor(t,n){super(),this.finished=!1,this.destroyed=!1,Hi(t);const r=Kt(n);if(this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;const i=this.blockLen,o=new Uint8Array(i);o.set(r.length>i?t.create().update(r).digest():r);for(let s=0;s<o.length;s++)o[s]^=54;this.iHash.update(o),this.oHash=t.create();for(let s=0;s<o.length;s++)o[s]^=106;this.oHash.update(o),o.fill(0)}update(t){return nt(this),this.iHash.update(t),this}digestInto(t){nt(this),Xn(t,this.outputLen),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){const t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}));const{oHash:n,iHash:r,finished:i,destroyed:o,blockLen:s,outputLen:c}=this;return t=t,t.finished=i,t.destroyed=o,t.blockLen=s,t.outputLen=c,t.oHash=n._cloneInto(t.oHash),t.iHash=r._cloneInto(t.iHash),t}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}};const lr=(e,t,n)=>new cr(e,t).update(n).digest();lr.create=(e,t)=>new cr(e,t);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function So(e){return{hash:e,hmac:(t,...n)=>lr(e,t,Vi(...n)),randomBytes:er}}function _o(e,t){const n=r=>Ao({...e,...So(r)});return Object.freeze({...n(t),create:n})}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const ut=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),rt=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),ur=BigInt(1),it=BigInt(2),On=(e,t)=>(e+t/it)/t;function fr(e){const t=ut,n=BigInt(3),r=BigInt(6),i=BigInt(11),o=BigInt(22),s=BigInt(23),c=BigInt(44),a=BigInt(88),l=e*e*e%t,f=l*l*e%t,u=Z(f,n,t)*f%t,p=Z(u,n,t)*f%t,y=Z(p,it,t)*l%t,g=Z(y,i,t)*y%t,h=Z(g,o,t)*g%t,d=Z(h,c,t)*h%t,w=Z(d,a,t)*d%t,v=Z(w,c,t)*h%t,S=Z(v,n,t)*f%t,L=Z(S,s,t)*g%t,k=Z(L,r,t)*l%t,x=Z(k,it,t);if(!Mt.eql(Mt.sqr(x),e))throw new Error("Cannot find square root");return x}const Mt=go(ut,void 0,void 0,{sqrt:fr}),Fe=_o({a:BigInt(0),b:BigInt(7),Fp:Mt,n:rt,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:e=>{const t=rt,n=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),r=-ur*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),i=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),o=n,s=BigInt("0x100000000000000000000000000000000"),c=On(o*e,t),a=On(-r*e,t);let l=F(e-c*n-a*i,t),f=F(-c*r-a*o,t);const u=l>s,p=f>s;if(u&&(l=t-l),p&&(f=t-f),l>s||f>s)throw new Error("splitScalar: Endomorphism failed, k="+e);return{k1neg:u,k1:l,k2neg:p,k2:f}}}},Ot),ft=BigInt(0),hr=e=>typeof e=="bigint"&&ft<e&&e<ut,Bo=e=>typeof e=="bigint"&&ft<e&&e<rt,Hn={};function ot(e,...t){let n=Hn[e];if(n===void 0){const r=Ot(Uint8Array.from(e,i=>i.charCodeAt(0)));n=Re(r,r),Hn[e]=n}return Ot(Re(n,...t))}const Qt=e=>e.toRawBytes(!0).slice(1),qt=e=>Ae(e,32),Tt=e=>F(e,ut),Ze=e=>F(e,rt),en=Fe.ProjectivePoint,To=(e,t,n)=>en.BASE.multiplyAndAddUnsafe(e,t,n);function Vt(e){let t=Fe.utils.normPrivateKeyToScalar(e),n=en.fromPrivateKey(t);return{scalar:n.hasEvenY()?t:Ze(-t),bytes:Qt(n)}}function dr(e){if(!hr(e))throw new Error("bad x: need 0 < x < p");const t=Tt(e*e),n=Tt(t*e+BigInt(7));let r=fr(n);r%it!==ft&&(r=Tt(-r));const i=new en(e,r,ur);return i.assertValidity(),i}function gr(...e){return Ze(K(ot("BIP0340/challenge",...e)))}function Io(e){return Vt(e).bytes}function Lo(e,t,n=er(32)){const r=j("message",e),{bytes:i,scalar:o}=Vt(t),s=j("auxRand",n,32),c=qt(o^K(ot("BIP0340/aux",s))),a=ot("BIP0340/nonce",c,i,r),l=Ze(K(a));if(l===ft)throw new Error("sign failed: k is zero");const{bytes:f,scalar:u}=Vt(l),p=gr(f,i,r),y=new Uint8Array(64);if(y.set(f,0),y.set(qt(Ze(u+p*o)),32),!pr(y,r,i))throw new Error("sign: Invalid signature produced");return y}function pr(e,t,n){const r=j("signature",e,64),i=j("message",t),o=j("publicKey",n,32);try{const s=dr(K(o)),c=K(r.subarray(0,32));if(!hr(c))return!1;const a=K(r.subarray(32,64));if(!Bo(a))return!1;const l=gr(qt(c),Qt(s),i),f=To(s,a,Ze(-l));return!(!f||!f.hasEvenY()||f.toAffine().x!==c)}catch{return!1}}const Ge={getPublicKey:Io,sign:Lo,verify:pr,utils:{randomPrivateKey:Fe.utils.randomPrivateKey,lift_x:dr,pointToBytes:Qt,numberToBytesBE:Ae,bytesToNumberBE:K,taggedHash:ot,mod:F}},It=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */const tn=e=>e instanceof Uint8Array,Lt=e=>new DataView(e.buffer,e.byteOffset,e.byteLength),te=(e,t)=>e<<32-t|e>>>t,ko=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!ko)throw new Error("Non little-endian hardware is not supported");const Ro=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function W(e){if(!tn(e))throw new Error("Uint8Array expected");let t="";for(let n=0;n<e.length;n++)t+=Ro[e[n]];return t}function Ue(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);const t=e.length;if(t%2)throw new Error("padded hex string expected, got unpadded hex of length "+t);const n=new Uint8Array(t/2);for(let r=0;r<n.length;r++){const i=r*2,o=e.slice(i,i+2),s=Number.parseInt(o,16);if(Number.isNaN(s)||s<0)throw new Error("Invalid byte sequence");n[r]=s}return n}function Uo(e){if(typeof e!="string")throw new Error(`utf8ToBytes expected string, got ${typeof e}`);return new Uint8Array(new TextEncoder().encode(e))}function Je(e){if(typeof e=="string"&&(e=Uo(e)),!tn(e))throw new Error(`expected Uint8Array, got ${typeof e}`);return e}function ht(...e){const t=new Uint8Array(e.reduce((r,i)=>r+i.length,0));let n=0;return e.forEach(r=>{if(!tn(r))throw new Error("Uint8Array expected");t.set(r,n),n+=r.length}),t}class yr{clone(){return this._cloneInto()}}function wr(e){const t=r=>e().update(Je(r)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function br(e=32){if(It&&typeof It.getRandomValues=="function")return It.getRandomValues(new Uint8Array(e));throw new Error("crypto.getRandomValues must be defined")}function zt(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`Wrong positive integer: ${e}`)}function $o(e){if(typeof e!="boolean")throw new Error(`Expected boolean, not ${e}`)}function mr(e,...t){if(!(e instanceof Uint8Array))throw new Error("Expected Uint8Array");if(t.length>0&&!t.includes(e.length))throw new Error(`Expected Uint8Array of length ${t}, not of length=${e.length}`)}function No(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");zt(e.outputLen),zt(e.blockLen)}function Co(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function Oo(e,t){mr(e);const n=t.outputLen;if(e.length<n)throw new Error(`digestInto() expects output buffer of length at least ${n}`)}const ne={number:zt,bool:$o,bytes:mr,hash:No,exists:Co,output:Oo};function Ho(e,t,n,r){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,n,r);const i=BigInt(32),o=BigInt(4294967295),s=Number(n>>i&o),c=Number(n&o),a=r?4:0,l=r?0:4;e.setUint32(t+a,s,r),e.setUint32(t+l,c,r)}class Po extends yr{constructor(t,n,r,i){super(),this.blockLen=t,this.outputLen=n,this.padOffset=r,this.isLE=i,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=Lt(this.buffer)}update(t){ne.exists(this);const{view:n,buffer:r,blockLen:i}=this;t=Je(t);const o=t.length;for(let s=0;s<o;){const c=Math.min(i-this.pos,o-s);if(c===i){const a=Lt(t);for(;i<=o-s;s+=i)this.process(a,s);continue}r.set(t.subarray(s,s+c),this.pos),this.pos+=c,s+=c,this.pos===i&&(this.process(n,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){ne.exists(this),ne.output(t,this),this.finished=!0;const{buffer:n,view:r,blockLen:i,isLE:o}=this;let{pos:s}=this;n[s++]=128,this.buffer.subarray(s).fill(0),this.padOffset>i-s&&(this.process(r,0),s=0);for(let u=s;u<i;u++)n[u]=0;Ho(r,i-8,BigInt(this.length*8),o),this.process(r,0);const c=Lt(t),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const l=a/4,f=this.get();if(l>f.length)throw new Error("_sha2: outputLen bigger than state");for(let u=0;u<l;u++)c.setUint32(4*u,f[u],o)}digest(){const{buffer:t,outputLen:n}=this;this.digestInto(t);const r=t.slice(0,n);return this.destroy(),r}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());const{blockLen:n,buffer:r,length:i,finished:o,destroyed:s,pos:c}=this;return t.length=i,t.pos=c,t.finished=o,t.destroyed=s,i%n&&t.buffer.set(r),t}}const Mo=(e,t,n)=>e&t^~e&n,qo=(e,t,n)=>e&t^e&n^t&n,Vo=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),me=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Ee=new Uint32Array(64);class Er extends Po{constructor(){super(64,32,8,!1),this.A=me[0]|0,this.B=me[1]|0,this.C=me[2]|0,this.D=me[3]|0,this.E=me[4]|0,this.F=me[5]|0,this.G=me[6]|0,this.H=me[7]|0}get(){const{A:t,B:n,C:r,D:i,E:o,F:s,G:c,H:a}=this;return[t,n,r,i,o,s,c,a]}set(t,n,r,i,o,s,c,a){this.A=t|0,this.B=n|0,this.C=r|0,this.D=i|0,this.E=o|0,this.F=s|0,this.G=c|0,this.H=a|0}process(t,n){for(let u=0;u<16;u++,n+=4)Ee[u]=t.getUint32(n,!1);for(let u=16;u<64;u++){const p=Ee[u-15],y=Ee[u-2],g=te(p,7)^te(p,18)^p>>>3,h=te(y,17)^te(y,19)^y>>>10;Ee[u]=h+Ee[u-7]+g+Ee[u-16]|0}let{A:r,B:i,C:o,D:s,E:c,F:a,G:l,H:f}=this;for(let u=0;u<64;u++){const p=te(c,6)^te(c,11)^te(c,25),y=f+p+Mo(c,a,l)+Vo[u]+Ee[u]|0,h=(te(r,2)^te(r,13)^te(r,22))+qo(r,i,o)|0;f=l,l=a,a=c,c=s+y|0,s=o,o=i,i=r,r=y+h|0}r=r+this.A|0,i=i+this.B|0,o=o+this.C|0,s=s+this.D|0,c=c+this.E|0,a=a+this.F|0,l=l+this.G|0,f=f+this.H|0,this.set(r,i,o,s,c,a,l,f)}roundClean(){Ee.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}}class zo extends Er{constructor(){super(),this.A=-1056596264,this.B=914150663,this.C=812702999,this.D=-150054599,this.E=-4191439,this.F=1750603025,this.G=1694076839,this.H=-1090891868,this.outputLen=28}}const $e=wr(()=>new Er);wr(()=>new zo);/*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) */function je(e){if(!Number.isSafeInteger(e))throw new Error(`Wrong integer: ${e}`)}function he(...e){const t=(i,o)=>s=>i(o(s)),n=Array.from(e).reverse().reduce((i,o)=>i?t(i,o.encode):o.encode,void 0),r=e.reduce((i,o)=>i?t(i,o.decode):o.decode,void 0);return{encode:n,decode:r}}function de(e){return{encode:t=>{if(!Array.isArray(t)||t.length&&typeof t[0]!="number")throw new Error("alphabet.encode input should be an array of numbers");return t.map(n=>{if(je(n),n<0||n>=e.length)throw new Error(`Digit index outside alphabet: ${n} (alphabet: ${e.length})`);return e[n]})},decode:t=>{if(!Array.isArray(t)||t.length&&typeof t[0]!="string")throw new Error("alphabet.decode input should be array of strings");return t.map(n=>{if(typeof n!="string")throw new Error(`alphabet.decode: not string element=${n}`);const r=e.indexOf(n);if(r===-1)throw new Error(`Unknown letter: "${n}". Allowed: ${e}`);return r})}}}function ge(e=""){if(typeof e!="string")throw new Error("join separator should be string");return{encode:t=>{if(!Array.isArray(t)||t.length&&typeof t[0]!="string")throw new Error("join.encode input should be array of strings");for(let n of t)if(typeof n!="string")throw new Error(`join.encode: non-string input=${n}`);return t.join(e)},decode:t=>{if(typeof t!="string")throw new Error("join.decode input should be string");return t.split(e)}}}function dt(e,t="="){if(je(e),typeof t!="string")throw new Error("padding chr should be string");return{encode(n){if(!Array.isArray(n)||n.length&&typeof n[0]!="string")throw new Error("padding.encode input should be array of strings");for(let r of n)if(typeof r!="string")throw new Error(`padding.encode: non-string input=${r}`);for(;n.length*e%8;)n.push(t);return n},decode(n){if(!Array.isArray(n)||n.length&&typeof n[0]!="string")throw new Error("padding.encode input should be array of strings");for(let i of n)if(typeof i!="string")throw new Error(`padding.decode: non-string input=${i}`);let r=n.length;if(r*e%8)throw new Error("Invalid padding: string should have whole number of bytes");for(;r>0&&n[r-1]===t;r--)if(!((r-1)*e%8))throw new Error("Invalid padding: string has too much padding");return n.slice(0,r)}}}function vr(e){if(typeof e!="function")throw new Error("normalize fn should be function");return{encode:t=>t,decode:t=>e(t)}}function Pn(e,t,n){if(t<2)throw new Error(`convertRadix: wrong from=${t}, base cannot be less than 2`);if(n<2)throw new Error(`convertRadix: wrong to=${n}, base cannot be less than 2`);if(!Array.isArray(e))throw new Error("convertRadix: data should be array");if(!e.length)return[];let r=0;const i=[],o=Array.from(e);for(o.forEach(s=>{if(je(s),s<0||s>=t)throw new Error(`Wrong integer: ${s}`)});;){let s=0,c=!0;for(let a=r;a<o.length;a++){const l=o[a],f=t*s+l;if(!Number.isSafeInteger(f)||t*s/t!==s||f-l!==t*s)throw new Error("convertRadix: carry overflow");if(s=f%n,o[a]=Math.floor(f/n),!Number.isSafeInteger(o[a])||o[a]*n+s!==f)throw new Error("convertRadix: carry overflow");if(c)o[a]?c=!1:r=a;else continue}if(i.push(s),c)break}for(let s=0;s<e.length-1&&e[s]===0;s++)i.push(0);return i.reverse()}const xr=(e,t)=>t?xr(t,e%t):e,st=(e,t)=>e+(t-xr(e,t));function Dt(e,t,n,r){if(!Array.isArray(e))throw new Error("convertRadix2: data should be array");if(t<=0||t>32)throw new Error(`convertRadix2: wrong from=${t}`);if(n<=0||n>32)throw new Error(`convertRadix2: wrong to=${n}`);if(st(t,n)>32)throw new Error(`convertRadix2: carry overflow from=${t} to=${n} carryBits=${st(t,n)}`);let i=0,o=0;const s=2**n-1,c=[];for(const a of e){if(je(a),a>=2**t)throw new Error(`convertRadix2: invalid data word=${a} from=${t}`);if(i=i<<t|a,o+t>32)throw new Error(`convertRadix2: carry overflow pos=${o} from=${t}`);for(o+=t;o>=n;o-=n)c.push((i>>o-n&s)>>>0);i&=2**o-1}if(i=i<<n-o&s,!r&&o>=t)throw new Error("Excess padding");if(!r&&i)throw new Error(`Non-zero padding: ${i}`);return r&&o>0&&c.push(i>>>0),c}function Do(e){return je(e),{encode:t=>{if(!(t instanceof Uint8Array))throw new Error("radix.encode input should be Uint8Array");return Pn(Array.from(t),2**8,e)},decode:t=>{if(!Array.isArray(t)||t.length&&typeof t[0]!="number")throw new Error("radix.decode input should be array of strings");return Uint8Array.from(Pn(t,e,2**8))}}}function Se(e,t=!1){if(je(e),e<=0||e>32)throw new Error("radix2: bits should be in (0..32]");if(st(8,e)>32||st(e,8)>32)throw new Error("radix2: carry overflow");return{encode:n=>{if(!(n instanceof Uint8Array))throw new Error("radix2.encode input should be Uint8Array");return Dt(Array.from(n),8,e,!t)},decode:n=>{if(!Array.isArray(n)||n.length&&typeof n[0]!="number")throw new Error("radix2.decode input should be array of strings");return Uint8Array.from(Dt(n,e,8,t))}}}function Mn(e){if(typeof e!="function")throw new Error("unsafeWrapper fn should be function");return function(...t){try{return e.apply(null,t)}catch{}}}const Fo=he(Se(4),de("0123456789ABCDEF"),ge("")),jo=he(Se(5),de("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"),dt(5),ge(""));he(Se(5),de("0123456789ABCDEFGHIJKLMNOPQRSTUV"),dt(5),ge(""));he(Se(5),de("0123456789ABCDEFGHJKMNPQRSTVWXYZ"),ge(""),vr(e=>e.toUpperCase().replace(/O/g,"0").replace(/[IL]/g,"1")));const fe=he(Se(6),de("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),dt(6),ge("")),Wo=he(Se(6),de("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"),dt(6),ge("")),nn=e=>he(Do(58),de(e),ge("")),Ft=nn("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");nn("123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ");nn("rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz");const qn=[0,2,3,5,6,7,9,10,11],Go={encode(e){let t="";for(let n=0;n<e.length;n+=8){const r=e.subarray(n,n+8);t+=Ft.encode(r).padStart(qn[r.length],"1")}return t},decode(e){let t=[];for(let n=0;n<e.length;n+=11){const r=e.slice(n,n+11),i=qn.indexOf(r.length),o=Ft.decode(r);for(let s=0;s<o.length-i;s++)if(o[s]!==0)throw new Error("base58xmr: wrong padding");t=t.concat(Array.from(o.slice(o.length-i)))}return Uint8Array.from(t)}},jt=he(de("qpzry9x8gf2tvdw0s3jn54khce6mua7l"),ge("")),Vn=[996825010,642813549,513874426,1027748829,705979059];function Ke(e){const t=e>>25;let n=(e&33554431)<<5;for(let r=0;r<Vn.length;r++)(t>>r&1)===1&&(n^=Vn[r]);return n}function zn(e,t,n=1){const r=e.length;let i=1;for(let o=0;o<r;o++){const s=e.charCodeAt(o);if(s<33||s>126)throw new Error(`Invalid prefix (${e})`);i=Ke(i)^s>>5}i=Ke(i);for(let o=0;o<r;o++)i=Ke(i)^e.charCodeAt(o)&31;for(let o of t)i=Ke(i)^o;for(let o=0;o<6;o++)i=Ke(i);return i^=n,jt.encode(Dt([i%2**30],30,5,!1))}function Ar(e){const t=e==="bech32"?1:734539939,n=Se(5),r=n.decode,i=n.encode,o=Mn(r);function s(f,u,p=90){if(typeof f!="string")throw new Error(`bech32.encode prefix should be string, not ${typeof f}`);if(!Array.isArray(u)||u.length&&typeof u[0]!="number")throw new Error(`bech32.encode words should be array of numbers, not ${typeof u}`);const y=f.length+7+u.length;if(p!==!1&&y>p)throw new TypeError(`Length ${y} exceeds limit ${p}`);return f=f.toLowerCase(),`${f}1${jt.encode(u)}${zn(f,u,t)}`}function c(f,u=90){if(typeof f!="string")throw new Error(`bech32.decode input should be string, not ${typeof f}`);if(f.length<8||u!==!1&&f.length>u)throw new TypeError(`Wrong string length: ${f.length} (${f}). Expected (8..${u})`);const p=f.toLowerCase();if(f!==p&&f!==f.toUpperCase())throw new Error("String must be lowercase or uppercase");f=p;const y=f.lastIndexOf("1");if(y===0||y===-1)throw new Error('Letter "1" must be present between prefix and data only');const g=f.slice(0,y),h=f.slice(y+1);if(h.length<6)throw new Error("Data must be at least 6 characters long");const d=jt.decode(h).slice(0,-6),w=zn(g,d,t);if(!h.endsWith(w))throw new Error(`Invalid checksum in ${f}: expected "${w}"`);return{prefix:g,words:d}}const a=Mn(c);function l(f){const{prefix:u,words:p}=c(f,!1);return{prefix:u,words:p,bytes:r(p)}}return{encode:s,decode:c,decodeToBytes:l,decodeUnsafe:a,fromWords:r,fromWordsUnsafe:o,toWords:i}}const De=Ar("bech32");Ar("bech32m");const Ko={encode:e=>new TextDecoder().decode(e),decode:e=>new TextEncoder().encode(e)},Zo=he(Se(4),de("0123456789abcdef"),ge(""),vr(e=>{if(typeof e!="string"||e.length%2)throw new TypeError(`hex.decode: expected string, got ${typeof e} with length ${e.length}`);return e.toLowerCase()})),Jo={utf8:Ko,hex:Zo,base16:Fo,base32:jo,base64:fe,base64url:Wo,base58:Ft,base58xmr:Go};`${Object.keys(Jo).join(", ")}`;function kt(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`positive integer expected, not ${e}`)}function Dn(e){if(typeof e!="boolean")throw new Error(`boolean expected, not ${e}`)}function Xo(e){return e instanceof Uint8Array||e!=null&&typeof e=="object"&&e.constructor.name==="Uint8Array"}function re(e,...t){if(!Xo(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error(`Uint8Array expected of length ${t}, not of length=${e.length}`)}/*! noble-ciphers - MIT License (c) 2023 Paul Miller (paulmillr.com) */const G=e=>new Uint32Array(e.buffer,e.byteOffset,Math.floor(e.byteLength/4)),Yo=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!Yo)throw new Error("Non little-endian hardware is not supported");const Qo=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Pe(e){re(e);let t="";for(let n=0;n<e.length;n++)t+=Qo[e[n]];return t}const se={_0:48,_9:57,_A:65,_F:70,_a:97,_f:102};function Fn(e){if(e>=se._0&&e<=se._9)return e-se._0;if(e>=se._A&&e<=se._F)return e-(se._A-10);if(e>=se._a&&e<=se._f)return e-(se._a-10)}function Sr(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);const t=e.length,n=t/2;if(t%2)throw new Error("padded hex string expected, got unpadded hex of length "+t);const r=new Uint8Array(n);for(let i=0,o=0;i<n;i++,o+=2){const s=Fn(e.charCodeAt(o)),c=Fn(e.charCodeAt(o+1));if(s===void 0||c===void 0){const a=e[o]+e[o+1];throw new Error('hex string expected, got non-hex character "'+a+'" at index '+o)}r[i]=s*16+c}return r}function es(e,t){if(t==null||typeof t!="object")throw new Error("options must be defined");return Object.assign(e,t)}function ts(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 n===0}const ns=(e,t)=>(Object.assign(t,e),t),xe=16,rs=283;function rn(e){return e<<1^rs&-(e>>7)}function Me(e,t){let n=0;for(;t>0;t>>=1)n^=e&-(t&1),e=rn(e);return n}const Wt=(()=>{let e=new Uint8Array(256);for(let n=0,r=1;n<256;n++,r^=rn(r))e[n]=r;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]]=(r^r>>4^r>>5^r>>6^r>>7^99)&255}return t})(),is=Wt.map((e,t)=>Wt.indexOf(t)),os=e=>e<<24|e>>>8,Rt=e=>e<<8|e>>>24;function _r(e,t){if(e.length!==256)throw new Error("Wrong sbox length");const n=new Uint32Array(256).map((l,f)=>t(e[f])),r=n.map(Rt),i=r.map(Rt),o=i.map(Rt),s=new Uint32Array(256*256),c=new Uint32Array(256*256),a=new Uint16Array(256*256);for(let l=0;l<256;l++)for(let f=0;f<256;f++){const u=l*256+f;s[u]=n[l]^r[f],c[u]=i[l]^o[f],a[u]=e[l]<<8|e[f]}return{sbox:e,sbox2:a,T0:n,T1:r,T2:i,T3:o,T01:s,T23:c}}const on=_r(Wt,e=>Me(e,3)<<24|e<<16|e<<8|Me(e,2)),Br=_r(is,e=>Me(e,11)<<24|Me(e,13)<<16|Me(e,9)<<8|Me(e,14)),ss=(()=>{const e=new Uint8Array(16);for(let t=0,n=1;t<16;t++,n=rn(n))e[t]=n;return e})();function Tr(e){re(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}=on,r=G(e),i=r.length,o=c=>ie(n,c,c,c,c),s=new Uint32Array(t+28);s.set(r);for(let c=i;c<s.length;c++){let a=s[c-1];c%i===0?a=o(os(a))^ss[c/i-1]:i>6&&c%i===4&&(a=o(a)),s[c]=s[c-i]^a}return s}function as(e){const t=Tr(e),n=t.slice(),r=t.length,{sbox2:i}=on,{T0:o,T1:s,T2:c,T3:a}=Br;for(let l=0;l<r;l+=4)for(let f=0;f<4;f++)n[l+f]=t[r-l-4+f];t.fill(0);for(let l=4;l<r-4;l++){const f=n[l],u=ie(i,f,f,f,f);n[l]=o[u&255]^s[u>>>8&255]^c[u>>>16&255]^a[u>>>24]}return n}function ve(e,t,n,r,i,o){return e[n<<8&65280|r>>>8&255]^t[i>>>8&65280|o>>>24&255]}function ie(e,t,n,r,i){return e[t&255|n&65280]|e[r>>>16&255|i>>>16&65280]<<16}function jn(e,t,n,r,i){const{sbox2:o,T01:s,T23:c}=on;let a=0;t^=e[a++],n^=e[a++],r^=e[a++],i^=e[a++];const l=e.length/4-2;for(let g=0;g<l;g++){const h=e[a++]^ve(s,c,t,n,r,i),d=e[a++]^ve(s,c,n,r,i,t),w=e[a++]^ve(s,c,r,i,t,n),v=e[a++]^ve(s,c,i,t,n,r);t=h,n=d,r=w,i=v}const f=e[a++]^ie(o,t,n,r,i),u=e[a++]^ie(o,n,r,i,t),p=e[a++]^ie(o,r,i,t,n),y=e[a++]^ie(o,i,t,n,r);return{s0:f,s1:u,s2:p,s3:y}}function cs(e,t,n,r,i){const{sbox2:o,T01:s,T23:c}=Br;let a=0;t^=e[a++],n^=e[a++],r^=e[a++],i^=e[a++];const l=e.length/4-2;for(let g=0;g<l;g++){const h=e[a++]^ve(s,c,t,i,r,n),d=e[a++]^ve(s,c,n,t,i,r),w=e[a++]^ve(s,c,r,n,t,i),v=e[a++]^ve(s,c,i,r,n,t);t=h,n=d,r=w,i=v}const f=e[a++]^ie(o,t,i,r,n),u=e[a++]^ie(o,n,t,i,r),p=e[a++]^ie(o,r,n,t,i),y=e[a++]^ie(o,i,r,n,t);return{s0:f,s1:u,s2:p,s3:y}}function Ir(e,t){if(!t)return new Uint8Array(e);if(re(t),t.length<e)throw new Error(`aes: wrong destination length, expected at least ${e}, got: ${t.length}`);return t}function ls(e){if(re(e),e.length%xe!==0)throw new Error(`aes/(cbc-ecb).decrypt ciphertext should consist of blocks with size ${xe}`)}function us(e,t,n){let r=e.length;const i=r%xe;if(!t&&i!==0)throw new Error("aec/(cbc-ecb): unpadded plaintext with disabled padding");const o=G(e);if(t){let a=xe-i;a||(a=xe),r=r+a}const s=Ir(r,n),c=G(s);return{b:o,o:c,out:s}}function fs(e,t){if(!t)return e;const n=e.length;if(!n)throw new Error("aes/pcks5: empty ciphertext not allowed");const r=e[n-1];if(r<=0||r>16)throw new Error(`aes/pcks5: wrong padding byte: ${r}`);const i=e.subarray(0,-r);for(let o=0;o<r;o++)if(e[n-o-1]!==r)throw new Error("aes/pcks5: wrong padding");return i}function hs(e){const t=new Uint8Array(16),n=G(t);t.set(e);const r=xe-e.length;for(let i=xe-r;i<xe;i++)t[i]=r;return n}const Lr=ns({blockSize:16,nonceLength:16},function(t,n,r={}){re(t),re(n,16);const i=!r.disablePadding;return{encrypt:(o,s)=>{const c=Tr(t),{b:a,o:l,out:f}=us(o,i,s),u=G(n);let p=u[0],y=u[1],g=u[2],h=u[3],d=0;for(;d+4<=a.length;)p^=a[d+0],y^=a[d+1],g^=a[d+2],h^=a[d+3],{s0:p,s1:y,s2:g,s3:h}=jn(c,p,y,g,h),l[d++]=p,l[d++]=y,l[d++]=g,l[d++]=h;if(i){const w=hs(o.subarray(d*4));p^=w[0],y^=w[1],g^=w[2],h^=w[3],{s0:p,s1:y,s2:g,s3:h}=jn(c,p,y,g,h),l[d++]=p,l[d++]=y,l[d++]=g,l[d++]=h}return c.fill(0),f},decrypt:(o,s)=>{ls(o);const c=as(t),a=G(n),l=Ir(o.length,s),f=G(o),u=G(l);let p=a[0],y=a[1],g=a[2],h=a[3];for(let d=0;d+4<=f.length;){const w=p,v=y,S=g,L=h;p=f[d+0],y=f[d+1],g=f[d+2],h=f[d+3];const{s0:k,s1:x,s2:A,s3:_}=cs(c,p,y,g,h);u[d++]=k^w,u[d++]=x^v,u[d++]=A^S,u[d++]=_^L}return c.fill(0),fs(l,i)}}}),kr=e=>Uint8Array.from(e.split("").map(t=>t.charCodeAt(0))),ds=kr("expand 16-byte k"),gs=kr("expand 32-byte k"),ps=G(ds),Rr=G(gs);Rr.slice();function N(e,t){return e<<t|e>>>32-t}function Gt(e){return e.byteOffset%4===0}const Ye=64,ys=16,Ur=2**32-1,Wn=new Uint32Array;function ws(e,t,n,r,i,o,s,c){const a=i.length,l=new Uint8Array(Ye),f=G(l),u=Gt(i)&&Gt(o),p=u?G(i):Wn,y=u?G(o):Wn;for(let g=0;g<a;s++){if(e(t,n,r,f,s,c),s>=Ur)throw new Error("arx: counter overflow");const h=Math.min(Ye,a-g);if(u&&h===Ye){const d=g/4;if(g%4!==0)throw new Error("arx: invalid block position");for(let w=0,v;w<ys;w++)v=d+w,y[v]=p[v]^f[w];g+=Ye;continue}for(let d=0,w;d<h;d++)w=g+d,o[w]=i[w]^l[d];g+=h}}function bs(e,t){const{allowShortKeys:n,extendNonceFn:r,counterLength:i,counterRight:o,rounds:s}=es({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},t);if(typeof e!="function")throw new Error("core must be a function");return kt(i),kt(s),Dn(o),Dn(n),(c,a,l,f,u=0)=>{re(c),re(a),re(l);const p=l.length;if(f||(f=new Uint8Array(p)),re(f),kt(u),u<0||u>=Ur)throw new Error("arx: counter overflow");if(f.length<p)throw new Error(`arx: output (${f.length}) is shorter than data (${p})`);const y=[];let g=c.length,h,d;if(g===32)h=c.slice(),y.push(h),d=Rr;else if(g===16&&n)h=new Uint8Array(32),h.set(c),h.set(c,16),d=ps,y.push(h);else throw new Error(`arx: invalid 32-byte key, got length=${g}`);Gt(a)||(a=a.slice(),y.push(a));const w=G(h);if(r){if(a.length!==24)throw new Error("arx: extended nonce must be 24 bytes");r(d,w,G(a.subarray(0,16)),w),a=a.subarray(16)}const v=16-i;if(v!==a.length)throw new Error(`arx: nonce must be ${v} or 16 bytes`);if(v!==12){const L=new Uint8Array(12);L.set(a,o?0:12-a.length),a=L,y.push(a)}const S=G(a);for(ws(e,d,w,S,l,f,u,s);y.length>0;)y.pop().fill(0);return f}}function ms(e,t,n,r,i,o=20){let s=e[0],c=e[1],a=e[2],l=e[3],f=t[0],u=t[1],p=t[2],y=t[3],g=t[4],h=t[5],d=t[6],w=t[7],v=i,S=n[0],L=n[1],k=n[2],x=s,A=c,_=a,M=l,U=f,T=u,O=p,H=y,V=g,b=h,E=d,B=w,R=v,I=S,$=L,P=k;for(let X=0;X<o;X+=2)x=x+U|0,R=N(R^x,16),V=V+R|0,U=N(U^V,12),x=x+U|0,R=N(R^x,8),V=V+R|0,U=N(U^V,7),A=A+T|0,I=N(I^A,16),b=b+I|0,T=N(T^b,12),A=A+T|0,I=N(I^A,8),b=b+I|0,T=N(T^b,7),_=_+O|0,$=N($^_,16),E=E+$|0,O=N(O^E,12),_=_+O|0,$=N($^_,8),E=E+$|0,O=N(O^E,7),M=M+H|0,P=N(P^M,16),B=B+P|0,H=N(H^B,12),M=M+H|0,P=N(P^M,8),B=B+P|0,H=N(H^B,7),x=x+T|0,P=N(P^x,16),E=E+P|0,T=N(T^E,12),x=x+T|0,P=N(P^x,8),E=E+P|0,T=N(T^E,7),A=A+O|0,R=N(R^A,16),B=B+R|0,O=N(O^B,12),A=A+O|0,R=N(R^A,8),B=B+R|0,O=N(O^B,7),_=_+H|0,I=N(I^_,16),V=V+I|0,H=N(H^V,12),_=_+H|0,I=N(I^_,8),V=V+I|0,H=N(H^V,7),M=M+U|0,$=N($^M,16),b=b+$|0,U=N(U^b,12),M=M+U|0,$=N($^M,8),b=b+$|0,U=N(U^b,7);let C=0;r[C++]=s+x|0,r[C++]=c+A|0,r[C++]=a+_|0,r[C++]=l+M|0,r[C++]=f+U|0,r[C++]=u+T|0,r[C++]=p+O|0,r[C++]=y+H|0,r[C++]=g+V|0,r[C++]=h+b|0,r[C++]=d+E|0,r[C++]=w+B|0,r[C++]=v+R|0,r[C++]=S+I|0,r[C++]=L+$|0,r[C++]=k+P|0}const $r=bs(ms,{counterRight:!1,counterLength:4,allowShortKeys:!1});class Nr extends yr{constructor(t,n){super(),this.finished=!1,this.destroyed=!1,ne.hash(t);const r=Je(n);if(this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;const i=this.blockLen,o=new Uint8Array(i);o.set(r.length>i?t.create().update(r).digest():r);for(let s=0;s<o.length;s++)o[s]^=54;this.iHash.update(o),this.oHash=t.create();for(let s=0;s<o.length;s++)o[s]^=106;this.oHash.update(o),o.fill(0)}update(t){return ne.exists(this),this.iHash.update(t),this}digestInto(t){ne.exists(this),ne.bytes(t,this.outputLen),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){const t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}));const{oHash:n,iHash:r,finished:i,destroyed:o,blockLen:s,outputLen:c}=this;return t=t,t.finished=i,t.destroyed=o,t.blockLen=s,t.outputLen=c,t.oHash=n._cloneInto(t.oHash),t.iHash=r._cloneInto(t.iHash),t}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}const gt=(e,t,n)=>new Nr(e,t).update(n).digest();gt.create=(e,t)=>new Nr(e,t);function Es(e,t,n){return ne.hash(e),gt(e,Je(n),Je(t))}const Ut=new Uint8Array([0]),Gn=new Uint8Array;function vs(e,t,n,r=32){if(ne.hash(e),ne.number(r),r>255*e.outputLen)throw new Error("Length should be <= 255*HashLen");const i=Math.ceil(r/e.outputLen);n===void 0&&(n=Gn);const o=new Uint8Array(i*e.outputLen),s=gt.create(e,t),c=s._cloneInto(),a=new Uint8Array(s.outputLen);for(let l=0;l<i;l++)Ut[0]=l+1,c.update(l===0?Gn:a).update(n).update(Ut).digestInto(a),o.set(a,e.outputLen*l),s._cloneInto(c);return s.destroy(),c.destroy(),a.fill(0),Ut.fill(0),o.slice(0,r)}var xs=Object.defineProperty,q=(e,t)=>{for(var n in t)xs(e,n,{get:t[n],enumerable:!0})},Te=Symbol("verified"),As=e=>e instanceof Object;function sn(e){if(!As(e)||typeof e.kind!="number"||typeof e.content!="string"||typeof e.created_at!="number"||typeof e.pubkey!="string"||!e.pubkey.match(/^[a-f0-9]{64}$/)||!Array.isArray(e.tags))return!1;for(let t=0;t<e.tags.length;t++){let n=e.tags[t];if(!Array.isArray(n))return!1;for(let r=0;r<n.length;r++)if(typeof n[r]!="string")return!1}return!0}var Ss={};q(Ss,{Queue:()=>Or,QueueNode:()=>Cr,binarySearch:()=>an,bytesToHex:()=>W,hexToBytes:()=>Ue,insertEventIntoAscendingList:()=>Bs,insertEventIntoDescendingList:()=>_s,normalizeURL:()=>Le,utf8Decoder:()=>ue,utf8Encoder:()=>Q});var ue=new TextDecoder("utf-8"),Q=new TextEncoder;function Le(e){try{e.indexOf("://")===-1&&(e="wss://"+e);let t=new URL(e);return t.protocol==="http:"?t.protocol="ws:":t.protocol==="https:"&&(t.protocol="wss:"),t.pathname=t.pathname.replace(/\/+/g,"/"),t.pathname.endsWith("/")&&(t.pathname=t.pathname.slice(0,-1)),(t.port==="80"&&t.protocol==="ws:"||t.port==="443"&&t.protocol==="wss:")&&(t.port=""),t.searchParams.sort(),t.hash="",t.toString()}catch{throw new Error(`Invalid URL: ${e}`)}}function _s(e,t){const[n,r]=an(e,i=>t.id===i.id?0:t.created_at===i.created_at?-1:i.created_at-t.created_at);return r||e.splice(n,0,t),e}function Bs(e,t){const[n,r]=an(e,i=>t.id===i.id?0:t.created_at===i.created_at?-1:t.created_at-i.created_at);return r||e.splice(n,0,t),e}function an(e,t){let n=0,r=e.length-1;for(;n<=r;){const i=Math.floor((n+r)/2),o=t(e[i]);if(o===0)return[i,!0];o<0?r=i-1:n=i+1}return[n,!1]}var Cr=class{constructor(e){m(this,"value");m(this,"next",null);m(this,"prev",null);this.value=e}},Or=class{constructor(){m(this,"first");m(this,"last");this.first=null,this.last=null}enqueue(e){const t=new Cr(e);return this.last?this.last===this.first?(this.last=t,this.last.prev=this.first,this.first.next=t):(t.prev=this.last,this.last.next=t,this.last=t):(this.first=t,this.last=t),!0}dequeue(){if(!this.first)return null;if(this.first===this.last){const t=this.first;return this.first=null,this.last=null,t.value}const e=this.first;return this.first=e.next,this.first&&(this.first.prev=null),e.value}},Ts=class{generateSecretKey(){return Ge.utils.randomPrivateKey()}getPublicKey(e){return W(Ge.getPublicKey(e))}finalizeEvent(e,t){const n=e;return n.pubkey=W(Ge.getPublicKey(t)),n.id=et(n),n.sig=W(Ge.sign(et(n),t)),n[Te]=!0,n}verifyEvent(e){if(typeof e[Te]=="boolean")return e[Te];const t=et(e);if(t!==e.id)return e[Te]=!1,!1;try{const n=Ge.verify(e.sig,t,e.pubkey);return e[Te]=n,n}catch{return e[Te]=!1,!1}}};function Is(e){if(!sn(e))throw new Error("can't serialize event with wrong or missing properties");return JSON.stringify([0,e.pubkey,e.created_at,e.kind,e.tags,e.content])}function et(e){let t=$e(Q.encode(Is(e)));return W(t)}var pt=new Ts,Ls=pt.generateSecretKey,cn=pt.getPublicKey,oe=pt.finalizeEvent,yt=pt.verifyEvent,ks={};q(ks,{Application:()=>za,BadgeAward:()=>Ps,BadgeDefinition:()=>Ca,BlockedRelaysList:()=>wa,BlossomServerList:()=>Sa,BookmarkList:()=>ga,Bookmarksets:()=>Ua,Calendar:()=>Za,CalendarEventRSVP:()=>Ja,ChannelCreation:()=>zr,ChannelHideMessage:()=>jr,ChannelMessage:()=>Fr,ChannelMetadata:()=>Dr,ChannelMuteUser:()=>Wr,ChatMessage:()=>Ms,ClassifiedListing:()=>ja,ClientAuth:()=>Kr,Comment:()=>Ks,CommunitiesList:()=>pa,CommunityDefinition:()=>ec,CommunityPostApproval:()=>na,Contacts:()=>Cs,CreateOrUpdateProduct:()=>Pa,CreateOrUpdateStall:()=>Ha,Curationsets:()=>$a,Date:()=>Ga,DirectMessageRelaysList:()=>xa,DraftClassifiedListing:()=>Wa,DraftLong:()=>qa,Emojisets:()=>Va,EncryptedDirectMessage:()=>Os,EventDeletion:()=>Hs,FavoriteRelays:()=>ma,FileMessage:()=>Vs,FileMetadata:()=>Gs,FileServerPreference:()=>Aa,Followsets:()=>La,ForumThread:()=>qs,GenericRepost:()=>dn,Genericlists:()=>ka,GiftWrap:()=>Gr,GroupMetadata:()=>tc,HTTPAuth:()=>gn,Handlerinformation:()=>Qa,Handlerrecommendation:()=>Ya,Highlights:()=>la,InterestsList:()=>Ea,Interestsets:()=>Oa,JobFeedback:()=>oa,JobRequest:()=>ra,JobResult:()=>ia,Label:()=>ta,LightningPubRPC:()=>Ba,LiveChatMessage:()=>Zs,LiveEvent:()=>Da,LongFormArticle:()=>Ma,Metadata:()=>$s,Mutelist:()=>fa,NWCWalletInfo:()=>_a,NWCWalletRequest:()=>Zr,NWCWalletResponse:()=>Ta,NormalVideo:()=>Ds,NostrConnect:()=>Ia,OpenTimestamps:()=>js,Photo:()=>zs,Pinlist:()=>ha,Poll:()=>Ws,PollResponse:()=>ua,PrivateDirectMessage:()=>Vr,ProblemTracker:()=>Ys,ProfileBadges:()=>Na,PublicChatsList:()=>ya,Reaction:()=>hn,RecommendRelay:()=>Ns,RelayList:()=>da,RelayReview:()=>Xa,Relaysets:()=>Ra,Report:()=>Qs,Reporting:()=>ea,Repost:()=>fn,Seal:()=>qr,SearchRelaysList:()=>ba,ShortTextNote:()=>Mr,ShortVideo:()=>Fs,Time:()=>Ka,UserEmojiList:()=>va,UserStatuses:()=>Fa,Voice:()=>Js,VoiceComment:()=>Xs,Zap:()=>ca,ZapGoal:()=>sa,ZapRequest:()=>aa,classifyKind:()=>Rs,isAddressableKind:()=>un,isEphemeralKind:()=>Pr,isKind:()=>Us,isRegularKind:()=>Hr,isReplaceableKind:()=>ln});function Hr(e){return e<1e4&&e!==0&&e!==3}function ln(e){return e===0||e===3||1e4<=e&&e<2e4}function Pr(e){return 2e4<=e&&e<3e4}function un(e){return 3e4<=e&&e<4e4}function Rs(e){return Hr(e)?"regular":ln(e)?"replaceable":Pr(e)?"ephemeral":un(e)?"parameterized":"unknown"}function Us(e,t){const n=t instanceof Array?t:[t];return sn(e)&&n.includes(e.kind)||!1}var $s=0,Mr=1,Ns=2,Cs=3,Os=4,Hs=5,fn=6,hn=7,Ps=8,Ms=9,qs=11,qr=13,Vr=14,Vs=15,dn=16,zs=20,Ds=21,Fs=22,zr=40,Dr=41,Fr=42,jr=43,Wr=44,js=1040,Gr=1059,Ws=1068,Gs=1063,Ks=1111,Zs=1311,Js=1222,Xs=1244,Ys=1971,Qs=1984,ea=1984,ta=1985,na=4550,ra=5999,ia=6999,oa=7e3,sa=9041,aa=9734,ca=9735,la=9802,ua=1018,fa=1e4,ha=10001,da=10002,ga=10003,pa=10004,ya=10005,wa=10006,ba=10007,ma=10012,Ea=10015,va=10030,xa=10050,Aa=10096,Sa=10063,_a=13194,Ba=21e3,Kr=22242,Zr=23194,Ta=23195,Ia=24133,gn=27235,La=3e4,ka=30001,Ra=30002,Ua=30003,$a=30004,Na=30008,Ca=30009,Oa=30015,Ha=30017,Pa=30018,Ma=30023,qa=30024,Va=30030,za=30078,Da=30311,Fa=30315,ja=30402,Wa=30403,Ga=31922,Ka=31923,Za=31924,Ja=31925,Xa=31987,Ya=31989,Qa=31990,ec=34550,tc=39e3;function nc(e,t){if(e.ids&&e.ids.indexOf(t.id)===-1||e.kinds&&e.kinds.indexOf(t.kind)===-1||e.authors&&e.authors.indexOf(t.pubkey)===-1)return!1;for(let n in e)if(n[0]==="#"){let r=n.slice(1),i=e[`#${r}`];if(i&&!t.tags.find(([o,s])=>o===n.slice(1)&&i.indexOf(s)!==-1))return!1}return!(e.since&&t.created_at<e.since||e.until&&t.created_at>e.until)}function rc(e,t){for(let n=0;n<e.length;n++)if(nc(e[n],t))return!0;return!1}var ic={};q(ic,{getHex64:()=>wt,getInt:()=>Jr,getSubscriptionId:()=>Xr,matchEventId:()=>oc,matchEventKind:()=>ac,matchEventPubkey:()=>sc});function wt(e,t){let n=t.length+3,r=e.indexOf(`"${t}":`)+n,i=e.slice(r).indexOf('"')+r+1;return e.slice(i,i+64)}function Jr(e,t){let n=t.length,r=e.indexOf(`"${t}":`)+n+3,i=e.slice(r),o=Math.min(i.indexOf(","),i.indexOf("}"));return parseInt(i.slice(0,o),10)}function Xr(e){let t=e.slice(0,22).indexOf('"EVENT"');if(t===-1)return null;let n=e.slice(t+7+1).indexOf('"');if(n===-1)return null;let r=t+7+1+n,i=e.slice(r+1,80).indexOf('"');if(i===-1)return null;let o=r+1+i;return e.slice(r+1,o)}function oc(e,t){return t===wt(e,"id")}function sc(e,t){return t===wt(e,"pubkey")}function ac(e,t){return t===Jr(e,"kind")}var cc={};q(cc,{makeAuthEvent:()=>Yr});function Yr(e,t){return{kind:Kr,created_at:Math.floor(Date.now()/1e3),tags:[["relay",e],["challenge",t]],content:""}}async function lc(){return new Promise((e,t)=>{try{if(typeof MessageChannel<"u"){const n=new MessageChannel,r=()=>{n.port1.removeEventListener("message",r),e()};n.port1.addEventListener("message",r),n.port2.postMessage(0),n.port1.start()}else typeof setImmediate<"u"?setImmediate(e):typeof setTimeout<"u"?setTimeout(e,0):e()}catch(n){console.error("during yield: ",n),t(n)}})}var uc=e=>(e[Te]=!0,!0),Qr=class extends Error{constructor(e,t){super(`Tried to send message '${e} on a closed connection to ${t}.`),this.name="SendingOnClosedConnection"}},ei=class{constructor(e,t){m(this,"url");m(this,"_connected",!1);m(this,"onclose",null);m(this,"onnotice",e=>console.debug(`NOTICE from ${this.url}: ${e}`));m(this,"onauth");m(this,"baseEoseTimeout",4400);m(this,"connectionTimeout",4400);m(this,"publishTimeout",4400);m(this,"pingFrequency",29e3);m(this,"pingTimeout",2e4);m(this,"resubscribeBackoff",[1e4,1e4,1e4,2e4,2e4,3e4,6e4]);m(this,"openSubs",new Map);m(this,"enablePing");m(this,"enableReconnect");m(this,"connectionTimeoutHandle");m(this,"reconnectTimeoutHandle");m(this,"pingIntervalHandle");m(this,"reconnectAttempts",0);m(this,"closedIntentionally",!1);m(this,"connectionPromise");m(this,"openCountRequests",new Map);m(this,"openEventPublishes",new Map);m(this,"ws");m(this,"incomingMessageQueue",new Or);m(this,"queueRunning",!1);m(this,"challenge");m(this,"authPromise");m(this,"serial",0);m(this,"verifyEvent");m(this,"_WebSocket");this.url=Le(e),this.verifyEvent=t.verifyEvent,this._WebSocket=t.websocketImplementation||WebSocket,this.enablePing=t.enablePing,this.enableReconnect=t.enableReconnect||!1}static async connect(e,t){const n=new ei(e,t);return await n.connect(),n}closeAllSubscriptions(e){for(let[t,n]of this.openSubs)n.close(e);this.openSubs.clear();for(let[t,n]of this.openEventPublishes)n.reject(new Error(e));this.openEventPublishes.clear();for(let[t,n]of this.openCountRequests)n.reject(new Error(e));this.openCountRequests.clear()}get connected(){return this._connected}async reconnect(){const e=this.resubscribeBackoff[Math.min(this.reconnectAttempts,this.resubscribeBackoff.length-1)];this.reconnectAttempts++,this.reconnectTimeoutHandle=setTimeout(async()=>{try{await this.connect()}catch{}},e)}handleHardClose(e){var n;this.pingIntervalHandle&&(clearInterval(this.pingIntervalHandle),this.pingIntervalHandle=void 0),this._connected=!1,this.connectionPromise=void 0;const t=this.closedIntentionally;this.closedIntentionally=!1,(n=this.onclose)==null||n.call(this),this.enableReconnect&&!t?this.reconnect():this.closeAllSubscriptions(e)}async connect(){return this.connectionPromise?this.connectionPromise:(this.challenge=void 0,this.authPromise=void 0,this.connectionPromise=new Promise((e,t)=>{this.connectionTimeoutHandle=setTimeout(()=>{var n;t("connection timed out"),this.connectionPromise=void 0,(n=this.onclose)==null||n.call(this),this.closeAllSubscriptions("relay connection timed out")},this.connectionTimeout);try{this.ws=new this._WebSocket(this.url)}catch(n){clearTimeout(this.connectionTimeoutHandle),t(n);return}this.ws.onopen=()=>{this.reconnectTimeoutHandle&&(clearTimeout(this.reconnectTimeoutHandle),this.reconnectTimeoutHandle=void 0),clearTimeout(this.connectionTimeoutHandle),this._connected=!0;const n=this.reconnectAttempts>0;this.reconnectAttempts=0;for(const r of this.openSubs.values()){if(r.eosed=!1,n)for(let i=0;i<r.filters.length;i++)r.lastEmitted&&(r.filters[i].since=r.lastEmitted+1);r.fire()}this.enablePing&&(this.pingIntervalHandle=setInterval(()=>this.pingpong(),this.pingFrequency)),e()},this.ws.onerror=n=>{clearTimeout(this.connectionTimeoutHandle),t(n.message||"websocket error"),this.handleHardClose("relay connection errored")},this.ws.onclose=n=>{clearTimeout(this.connectionTimeoutHandle),t(n.message||"websocket closed"),this.handleHardClose("relay connection closed")},this.ws.onmessage=this._onmessage.bind(this)}),this.connectionPromise)}waitForPingPong(){return new Promise(e=>{this.ws.once("pong",()=>e(!0)),this.ws.ping()})}waitForDummyReq(){return new Promise((e,t)=>{if(!this.connectionPromise)return t(new Error(`no connection to ${this.url}, can't ping`));try{const n=this.subscribe([{ids:["aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"],limit:0}],{label:"forced-ping",oneose:()=>{e(!0),n.close()},onclose(){e(!0)},eoseTimeout:this.pingTimeout+1e3})}catch(n){t(n)}})}async pingpong(){var e,t,n;((e=this.ws)==null?void 0:e.readyState)===1&&(await Promise.any([this.ws&&this.ws.ping&&this.ws.once?this.waitForPingPong():this.waitForDummyReq(),new Promise(i=>setTimeout(()=>i(!1),this.pingTimeout))])||((t=this.ws)==null?void 0:t.readyState)===this._WebSocket.OPEN&&((n=this.ws)==null||n.close()))}async runQueue(){for(this.queueRunning=!0;this.handleNext()!==!1;)await lc();this.queueRunning=!1}handleNext(){var n,r,i;const e=this.incomingMessageQueue.dequeue();if(!e)return!1;const t=Xr(e);if(t){const o=this.openSubs.get(t);if(!o)return;const s=wt(e,"id"),c=(n=o.alreadyHaveEvent)==null?void 0:n.call(o,s);if((r=o.receivedEvent)==null||r.call(o,this,s),c)return}try{let o=JSON.parse(e);switch(o[0]){case"EVENT":{const s=this.openSubs.get(o[1]),c=o[2];this.verifyEvent(c)&&rc(s.filters,c)&&s.onevent(c),(!s.lastEmitted||s.lastEmitted<c.created_at)&&(s.lastEmitted=c.created_at);return}case"COUNT":{const s=o[1],c=o[2],a=this.openCountRequests.get(s);a&&(a.resolve(c.count),this.openCountRequests.delete(s));return}case"EOSE":{const s=this.openSubs.get(o[1]);if(!s)return;s.receivedEose();return}case"OK":{const s=o[1],c=o[2],a=o[3],l=this.openEventPublishes.get(s);l&&(clearTimeout(l.timeout),c?l.resolve(a):l.reject(new Error(a)),this.openEventPublishes.delete(s));return}case"CLOSED":{const s=o[1],c=this.openSubs.get(s);if(!c)return;c.closed=!0,c.close(o[2]);return}case"NOTICE":{this.onnotice(o[1]);return}case"AUTH":{this.challenge=o[1],this.onauth&&this.auth(this.onauth);return}default:{const s=this.openSubs.get(o[1]);(i=s==null?void 0:s.oncustom)==null||i.call(s,o);return}}}catch{return}}async send(e){if(!this.connectionPromise)throw new Qr(e,this.url);this.connectionPromise.then(()=>{var t;(t=this.ws)==null||t.send(e)})}async auth(e){const t=this.challenge;if(!t)throw new Error("can't perform auth, no challenge was received");return this.authPromise?this.authPromise:(this.authPromise=new Promise(async(n,r)=>{try{let i=await e(Yr(this.url,t)),o=setTimeout(()=>{let s=this.openEventPublishes.get(i.id);s&&(s.reject(new Error("auth timed out")),this.openEventPublishes.delete(i.id))},this.publishTimeout);this.openEventPublishes.set(i.id,{resolve:n,reject:r,timeout:o}),this.send('["AUTH",'+JSON.stringify(i)+"]")}catch(i){console.warn("subscribe auth function failed:",i)}}),this.authPromise)}async publish(e){const t=new Promise((n,r)=>{const i=setTimeout(()=>{const o=this.openEventPublishes.get(e.id);o&&(o.reject(new Error("publish timed out")),this.openEventPublishes.delete(e.id))},this.publishTimeout);this.openEventPublishes.set(e.id,{resolve:n,reject:r,timeout:i})});return this.send('["EVENT",'+JSON.stringify(e)+"]"),t}async count(e,t){this.serial++;const n=(t==null?void 0:t.id)||"count:"+this.serial,r=new Promise((i,o)=>{this.openCountRequests.set(n,{resolve:i,reject:o})});return this.send('["COUNT","'+n+'",'+JSON.stringify(e).substring(1)),r}subscribe(e,t){const n=this.prepareSubscription(e,t);return n.fire(),n}prepareSubscription(e,t){this.serial++;const n=t.id||(t.label?t.label+":":"sub:")+this.serial,r=new fc(this,n,e,t);return this.openSubs.set(n,r),r}close(){var e,t,n;this.closedIntentionally=!0,this.reconnectTimeoutHandle&&(clearTimeout(this.reconnectTimeoutHandle),this.reconnectTimeoutHandle=void 0),this.pingIntervalHandle&&(clearInterval(this.pingIntervalHandle),this.pingIntervalHandle=void 0),this.closeAllSubscriptions("relay connection closed by us"),this._connected=!1,(e=this.onclose)==null||e.call(this),((t=this.ws)==null?void 0:t.readyState)===this._WebSocket.OPEN&&((n=this.ws)==null||n.close())}_onmessage(e){this.incomingMessageQueue.enqueue(e.data),this.queueRunning||this.runQueue()}},fc=class{constructor(e,t,n,r){m(this,"relay");m(this,"id");m(this,"lastEmitted");m(this,"closed",!1);m(this,"eosed",!1);m(this,"filters");m(this,"alreadyHaveEvent");m(this,"receivedEvent");m(this,"onevent");m(this,"oneose");m(this,"onclose");m(this,"oncustom");m(this,"eoseTimeout");m(this,"eoseTimeoutHandle");if(n.length===0)throw new Error("subscription can't be created with zero filters");this.relay=e,this.filters=n,this.id=t,this.alreadyHaveEvent=r.alreadyHaveEvent,this.receivedEvent=r.receivedEvent,this.eoseTimeout=r.eoseTimeout||e.baseEoseTimeout,this.oneose=r.oneose,this.onclose=r.onclose,this.onevent=r.onevent||(i=>{console.warn(`onevent() callback not defined for subscription '${this.id}' in relay ${this.relay.url}. event received:`,i)})}fire(){this.relay.send('["REQ","'+this.id+'",'+JSON.stringify(this.filters).substring(1)),this.eoseTimeoutHandle=setTimeout(this.receivedEose.bind(this),this.eoseTimeout)}receivedEose(){var e;this.eosed||(clearTimeout(this.eoseTimeoutHandle),this.eosed=!0,(e=this.oneose)==null||e.call(this))}close(e="closed by caller"){var t;if(!this.closed&&this.relay.connected){try{this.relay.send('["CLOSE",'+JSON.stringify(this.id)+"]")}catch(n){if(!(n instanceof Qr))throw n}this.closed=!0}this.relay.openSubs.delete(this.id),(t=this.onclose)==null||t.call(this,e)}},hc;try{hc=WebSocket}catch{}var dc=class{constructor(e){m(this,"relays",new Map);m(this,"seenOn",new Map);m(this,"trackRelays",!1);m(this,"verifyEvent");m(this,"enablePing");m(this,"enableReconnect");m(this,"automaticallyAuth");m(this,"trustedRelayURLs",new Set);m(this,"_WebSocket");this.verifyEvent=e.verifyEvent,this._WebSocket=e.websocketImplementation,this.enablePing=e.enablePing,this.enableReconnect=e.enableReconnect||!1,this.automaticallyAuth=e.automaticallyAuth}async ensureRelay(e,t){e=Le(e);let n=this.relays.get(e);if(n||(n=new ei(e,{verifyEvent:this.trustedRelayURLs.has(e)?uc:this.verifyEvent,websocketImplementation:this._WebSocket,enablePing:this.enablePing,enableReconnect:this.enableReconnect}),n.onclose=()=>{n&&!n.enableReconnect&&this.relays.delete(e)},t!=null&&t.connectionTimeout&&(n.connectionTimeout=t.connectionTimeout),this.relays.set(e,n)),this.automaticallyAuth){const r=this.automaticallyAuth(e);r&&(n.onauth=r)}return await n.connect(),n}close(e){e.map(Le).forEach(t=>{var n;(n=this.relays.get(t))==null||n.close(),this.relays.delete(t)})}subscribe(e,t,n){const r=[];for(let i=0;i<e.length;i++){const o=Le(e[i]);r.find(s=>s.url===o)||r.push({url:o,filter:t})}return this.subscribeMap(r,n)}subscribeMany(e,t,n){const r=[],i=[];for(let o=0;o<e.length;o++){const s=Le(e[o]);i.indexOf(s)===-1&&(i.push(s),r.push({url:s,filter:t}))}return this.subscribeMap(r,n)}subscribeMap(e,t){const n=new Map;for(const p of e){const{url:y,filter:g}=p;n.has(y)||n.set(y,[]),n.get(y).push(g)}const r=Array.from(n.entries()).map(([p,y])=>({url:p,filters:y}));this.trackRelays&&(t.receivedEvent=(p,y)=>{let g=this.seenOn.get(y);g||(g=new Set,this.seenOn.set(y,g)),g.add(p)});const i=new Set,o=[],s=[];let c=p=>{var y;s[p]||(s[p]=!0,s.filter(g=>g).length===r.length&&((y=t.oneose)==null||y.call(t),c=()=>{}))};const a=[];let l=(p,y)=>{var g;a[p]||(c(p),a[p]=y,a.filter(h=>h).length===r.length&&((g=t.onclose)==null||g.call(t,a),l=()=>{}))};const f=p=>{var g;if((g=t.alreadyHaveEvent)!=null&&g.call(t,p))return!0;const y=i.has(p);return i.add(p),y},u=Promise.all(r.map(async({url:p,filters:y},g)=>{let h;try{h=await this.ensureRelay(p,{connectionTimeout:t.maxWait?Math.max(t.maxWait*.8,t.maxWait-1e3):void 0})}catch(w){l(g,(w==null?void 0:w.message)||String(w));return}let d=h.subscribe(y,{...t,oneose:()=>c(g),onclose:w=>{w.startsWith("auth-required: ")&&t.onauth?h.auth(t.onauth).then(()=>{h.subscribe(y,{...t,oneose:()=>c(g),onclose:v=>{l(g,v)},alreadyHaveEvent:f,eoseTimeout:t.maxWait})}).catch(v=>{l(g,`auth was required and attempted, but failed with: ${v}`)}):l(g,w)},alreadyHaveEvent:f,eoseTimeout:t.maxWait});o.push(d)}));return{async close(p){await u,o.forEach(y=>{y.close(p)})}}}subscribeEose(e,t,n){const r=this.subscribe(e,t,{...n,oneose(){r.close("closed automatically on eose")}});return r}subscribeManyEose(e,t,n){const r=this.subscribeMany(e,t,{...n,oneose(){r.close("closed automatically on eose")}});return r}async querySync(e,t,n){return new Promise(async r=>{const i=[];this.subscribeEose(e,t,{...n,onevent(o){i.push(o)},onclose(o){r(i)}})})}async get(e,t,n){t.limit=1;const r=await this.querySync(e,t,n);return r.sort((i,o)=>o.created_at-i.created_at),r[0]||null}publish(e,t,n){return e.map(Le).map(async(r,i,o)=>{if(o.indexOf(r)!==i)return Promise.reject("duplicate url");let s=await this.ensureRelay(r);return s.publish(t).catch(async c=>{if(c instanceof Error&&c.message.startsWith("auth-required: ")&&(n!=null&&n.onauth))return await s.auth(n.onauth),s.publish(t);throw c}).then(c=>{if(this.trackRelays){let a=this.seenOn.get(t.id);a||(a=new Set,this.seenOn.set(t.id,a)),a.add(s)}return c})})}listConnectionStatus(){const e=new Map;return this.relays.forEach((t,n)=>e.set(n,t.connected)),e}destroy(){this.relays.forEach(e=>e.close()),this.relays=new Map}},ti;try{ti=WebSocket}catch{}var Kl=class extends dc{constructor(e){super({verifyEvent:yt,websocketImplementation:ti,...e})}},gc={};q(gc,{BECH32_REGEX:()=>ni,Bech32MaxSize:()=>pn,NostrTypeGuard:()=>pc,decode:()=>bt,decodeNostrURI:()=>wc,encodeBytes:()=>Et,naddrEncode:()=>Ac,neventEncode:()=>xc,noteEncode:()=>Ec,nprofileEncode:()=>vc,npubEncode:()=>mc,nsecEncode:()=>bc});var pc={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||"")},pn=5e3,ni=/[\x21-\x7E]{1,83}1[023456789acdefghjklmnpqrstuvwxyz]{6,}/;function yc(e){const t=new Uint8Array(4);return t[0]=e>>24&255,t[1]=e>>16&255,t[2]=e>>8&255,t[3]=e&255,t}function wc(e){try{return e.startsWith("nostr:")&&(e=e.substring(6)),bt(e)}catch{return{type:"invalid",data:null}}}function bt(e){var i,o,s,c,a,l,f;let{prefix:t,words:n}=De.decode(e,pn),r=new Uint8Array(De.fromWords(n));switch(t){case"nprofile":{let u=$t(r);if(!((i=u[0])!=null&&i[0]))throw new Error("missing TLV 0 for nprofile");if(u[0][0].length!==32)throw new Error("TLV 0 should be 32 bytes");return{type:"nprofile",data:{pubkey:W(u[0][0]),relays:u[1]?u[1].map(p=>ue.decode(p)):[]}}}case"nevent":{let u=$t(r);if(!((o=u[0])!=null&&o[0]))throw new Error("missing TLV 0 for nevent");if(u[0][0].length!==32)throw new Error("TLV 0 should be 32 bytes");if(u[2]&&u[2][0].length!==32)throw new Error("TLV 2 should be 32 bytes");if(u[3]&&u[3][0].length!==4)throw new Error("TLV 3 should be 4 bytes");return{type:"nevent",data:{id:W(u[0][0]),relays:u[1]?u[1].map(p=>ue.decode(p)):[],author:(s=u[2])!=null&&s[0]?W(u[2][0]):void 0,kind:(c=u[3])!=null&&c[0]?parseInt(W(u[3][0]),16):void 0}}}case"naddr":{let u=$t(r);if(!((a=u[0])!=null&&a[0]))throw new Error("missing TLV 0 for naddr");if(!((l=u[2])!=null&&l[0]))throw new Error("missing TLV 2 for naddr");if(u[2][0].length!==32)throw new Error("TLV 2 should be 32 bytes");if(!((f=u[3])!=null&&f[0]))throw new Error("missing TLV 3 for naddr");if(u[3][0].length!==4)throw new Error("TLV 3 should be 4 bytes");return{type:"naddr",data:{identifier:ue.decode(u[0][0]),pubkey:W(u[2][0]),kind:parseInt(W(u[3][0]),16),relays:u[1]?u[1].map(p=>ue.decode(p)):[]}}}case"nsec":return{type:t,data:r};case"npub":case"note":return{type:t,data:W(r)};default:throw new Error(`unknown prefix ${t}`)}}function $t(e){let t={},n=e;for(;n.length>0;){let r=n[0],i=n[1],o=n.slice(2,2+i);if(n=n.slice(2+i),o.length<i)throw new Error(`not enough data to read on TLV ${r}`);t[r]=t[r]||[],t[r].push(o)}return t}function bc(e){return Et("nsec",e)}function mc(e){return Et("npub",Ue(e))}function Ec(e){return Et("note",Ue(e))}function mt(e,t){let n=De.toWords(t);return De.encode(e,n,pn)}function Et(e,t){return mt(e,t)}function vc(e){let t=yn({0:[Ue(e.pubkey)],1:(e.relays||[]).map(n=>Q.encode(n))});return mt("nprofile",t)}function xc(e){let t;e.kind!==void 0&&(t=yc(e.kind));let n=yn({0:[Ue(e.id)],1:(e.relays||[]).map(r=>Q.encode(r)),2:e.author?[Ue(e.author)]:[],3:t?[new Uint8Array(t)]:[]});return mt("nevent",n)}function Ac(e){let t=new ArrayBuffer(4);new DataView(t).setUint32(0,e.kind,!1);let n=yn({0:[Q.encode(e.identifier)],1:(e.relays||[]).map(r=>Q.encode(r)),2:[Ue(e.pubkey)],3:[new Uint8Array(t)]});return mt("naddr",n)}function yn(e){let t=[];return Object.entries(e).reverse().forEach(([n,r])=>{r.forEach(i=>{let o=new Uint8Array(i.length+2);o.set([parseInt(n)],0),o.set([i.length],1),o.set(i,2),t.push(o)})}),ht(...t)}var Sc={};q(Sc,{decrypt:()=>_c,encrypt:()=>ri});function ri(e,t,n){const r=e instanceof Uint8Array?W(e):e,i=Fe.getSharedSecret(r,"02"+t),o=ii(i);let s=Uint8Array.from(br(16)),c=Q.encode(n),a=Lr(o,s).encrypt(c),l=fe.encode(new Uint8Array(a)),f=fe.encode(new Uint8Array(s.buffer));return`${l}?iv=${f}`}function _c(e,t,n){const r=e instanceof Uint8Array?W(e):e;let[i,o]=n.split("?iv="),s=Fe.getSharedSecret(r,"02"+t),c=ii(s),a=fe.decode(o),l=fe.decode(i),f=Lr(c,a).decrypt(l);return ue.decode(f)}function ii(e){return e.slice(1,33)}var Bc={};q(Bc,{NIP05_REGEX:()=>wn,isNip05:()=>Tc,isValid:()=>kc,queryProfile:()=>oi,searchDomain:()=>Lc,useFetchImplementation:()=>Ic});var wn=/^(?:([\w.+-]+)@)?([\w_-]+(\.[\w_-]+)+)$/,Tc=e=>wn.test(e||""),vt;try{vt=fetch}catch{}function Ic(e){vt=e}async function Lc(e,t=""){try{const n=`https://${e}/.well-known/nostr.json?name=${t}`,r=await vt(n,{redirect:"manual"});if(r.status!==200)throw Error("Wrong response code");return(await r.json()).names}catch{return{}}}async function oi(e){var i;const t=e.match(wn);if(!t)return null;const[,n="_",r]=t;try{const o=`https://${r}/.well-known/nostr.json?name=${n}`,s=await vt(o,{redirect:"manual"});if(s.status!==200)throw Error("Wrong response code");const c=await s.json(),a=c.names[n];return a?{pubkey:a,relays:(i=c.relays)==null?void 0:i[a]}:null}catch{return null}}async function kc(e,t){const n=await oi(t);return n?n.pubkey===e:!1}var Rc={};q(Rc,{parse:()=>Uc});function Uc(e){const t={reply:void 0,root:void 0,mentions:[],profiles:[],quotes:[]};let n,r;for(let i=e.tags.length-1;i>=0;i--){const o=e.tags[i];if(o[0]==="e"&&o[1]){const[s,c,a,l,f]=o,u={id:c,relays:a?[a]:[],author:f};if(l==="root"){t.root=u;continue}if(l==="reply"){t.reply=u;continue}if(l==="mention"){t.mentions.push(u);continue}n?r=u:n=u,t.mentions.push(u);continue}if(o[0]==="q"&&o[1]){const[s,c,a]=o;t.quotes.push({id:c,relays:a?[a]:[]})}if(o[0]==="p"&&o[1]){t.profiles.push({pubkey:o[1],relays:o[2]?[o[2]]:[]});continue}}return t.root||(t.root=r||n||t.reply),t.reply||(t.reply=n||t.root),[t.reply,t.root].forEach(i=>{if(!i)return;let o=t.mentions.indexOf(i);if(o!==-1&&t.mentions.splice(o,1),i.author){let s=t.profiles.find(c=>c.pubkey===i.author);s&&s.relays&&(i.relays||(i.relays=[]),s.relays.forEach(c=>{var a;((a=i.relays)==null?void 0:a.indexOf(c))===-1&&i.relays.push(c)}),s.relays=i.relays)}}),t.mentions.forEach(i=>{if(i.author){let o=t.profiles.find(s=>s.pubkey===i.author);o&&o.relays&&(i.relays||(i.relays=[]),o.relays.forEach(s=>{i.relays.indexOf(s)===-1&&i.relays.push(s)}),o.relays=i.relays)}}),t}var $c={};q($c,{fetchRelayInformation:()=>Cc,useFetchImplementation:()=>Nc});var si;try{si=fetch}catch{}function Nc(e){si=e}async function Cc(e){return await(await fetch(e.replace("ws://","http://").replace("wss://","https://"),{headers:{Accept:"application/nostr+json"}})).json()}var Oc={};q(Oc,{fastEventHash:()=>ci,getPow:()=>ai,minePow:()=>Hc});function ai(e){let t=0;for(let n=0;n<64;n+=8){const r=parseInt(e.substring(n,n+8),16);if(r===0)t+=32;else{t+=Math.clz32(r);break}}return t}function Hc(e,t){let n=0;const r=e,i=["nonce",n.toString(),t.toString()];for(r.tags.push(i);;){const o=Math.floor(new Date().getTime()/1e3);if(o!==r.created_at&&(n=0,r.created_at=o),i[1]=(++n).toString(),r.id=ci(r),ai(r.id)>=t)break}return r}function ci(e){return W($e(Q.encode(JSON.stringify([0,e.pubkey,e.created_at,e.kind,e.tags,e.content]))))}var Pc={};q(Pc,{unwrapEvent:()=>Jc,unwrapManyEvents:()=>Xc,wrapEvent:()=>vi,wrapManyEvents:()=>Zc});var Mc={};q(Mc,{createRumor:()=>wi,createSeal:()=>bi,createWrap:()=>mi,unwrapEvent:()=>xn,unwrapManyEvents:()=>Ei,wrapEvent:()=>at,wrapManyEvents:()=>Gc});var qc={};q(qc,{decrypt:()=>vn,encrypt:()=>En,getConversationKey:()=>bn,v2:()=>jc});var li=1,ui=65535;function bn(e,t){const n=Fe.getSharedSecret(e,"02"+t).subarray(1,33);return Es($e,n,"nip44-v2")}function fi(e,t){const n=vs($e,e,t,76);return{chacha_key:n.subarray(0,32),chacha_nonce:n.subarray(32,44),hmac_key:n.subarray(44,76)}}function mn(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 Vc(e){if(!Number.isSafeInteger(e)||e<li||e>ui)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}function zc(e){const t=Q.encode(e),n=t.length,r=Vc(n),i=new Uint8Array(mn(n)-n);return ht(r,t,i)}function Dc(e){const t=new DataView(e.buffer).getUint16(0),n=e.subarray(2,2+t);if(t<li||t>ui||n.length!==t||e.length!==2+mn(t))throw new Error("invalid padding");return ue.decode(n)}function hi(e,t,n){if(n.length!==32)throw new Error("AAD associated data must be 32 bytes");const r=ht(n,t);return gt($e,e,r)}function Fc(e){if(typeof e!="string")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=fe.decode(e)}catch(o){throw new Error("invalid base64: "+o.message)}const r=n.length;if(r<99||r>65603)throw new Error("invalid data length: "+r);const i=n[0];if(i!==2)throw new Error("unknown encryption version "+i);return{nonce:n.subarray(1,33),ciphertext:n.subarray(33,-32),mac:n.subarray(-32)}}function En(e,t,n=br(32)){const{chacha_key:r,chacha_nonce:i,hmac_key:o}=fi(t,n),s=zc(e),c=$r(r,i,s),a=hi(o,c,n);return fe.encode(ht(new Uint8Array([2]),n,c,a))}function vn(e,t){const{nonce:n,ciphertext:r,mac:i}=Fc(e),{chacha_key:o,chacha_nonce:s,hmac_key:c}=fi(t,n),a=hi(c,r,n);if(!ts(a,i))throw new Error("invalid MAC");const l=$r(o,s,r);return Dc(l)}var jc={utils:{getConversationKey:bn,calcPaddedLen:mn},encrypt:En,decrypt:vn},Wc=2*24*60*60,di=()=>Math.round(Date.now()/1e3),gi=()=>Math.round(di()-Math.random()*Wc),pi=(e,t)=>bn(e,t),yi=(e,t,n)=>En(JSON.stringify(e),pi(t,n)),Kn=(e,t)=>JSON.parse(vn(e.content,pi(t,e.pubkey)));function wi(e,t){const n={created_at:di(),content:"",tags:[],...e,pubkey:cn(t)};return n.id=et(n),n}function bi(e,t,n){return oe({kind:qr,content:yi(e,t,n),created_at:gi(),tags:[]},t)}function mi(e,t){const n=Ls();return oe({kind:Gr,content:yi(e,n,t),created_at:gi(),tags:[["p",t]]},n)}function at(e,t,n){const r=wi(e,t),i=bi(r,t,n);return mi(i,n)}function Gc(e,t,n){if(!n||n.length===0)throw new Error("At least one recipient is required.");const r=cn(t),i=[at(e,t,r)];return n.forEach(o=>{i.push(at(e,t,o))}),i}function xn(e,t){const n=Kn(e,t);return Kn(n,t)}function Ei(e,t){let n=[];return e.forEach(r=>{n.push(xn(r,t))}),n.sort((r,i)=>r.created_at-i.created_at),n}function Kc(e,t,n,r){const i={created_at:Math.ceil(Date.now()/1e3),kind:Vr,tags:[],content:t};return(Array.isArray(e)?e:[e]).forEach(({publicKey:s,relayUrl:c})=>{i.tags.push(c?["p",s,c]:["p",s])}),r&&i.tags.push(["e",r.eventId,r.relayUrl||"","reply"]),n&&i.tags.push(["subject",n]),i}function vi(e,t,n,r,i){const o=Kc(t,n,r,i);return at(o,e,t.publicKey)}function Zc(e,t,n,r,i){if(!t||t.length===0)throw new Error("At least one recipient is required.");return[{publicKey:cn(e)},...t].map(s=>vi(e,s,n,r,i))}var Jc=xn,Xc=Ei,Yc={};q(Yc,{finishRepostEvent:()=>Qc,getRepostedEvent:()=>el,getRepostedEventPointer:()=>xi});function Qc(e,t,n,r){var s;let i;const o=[...e.tags??[],["e",t.id,n],["p",t.pubkey]];return t.kind===Mr?i=fn:(i=dn,o.push(["k",String(t.kind)])),oe({kind:i,tags:o,content:e.content===""||(s=t.tags)!=null&&s.find(c=>c[0]==="-")?"":JSON.stringify(t),created_at:e.created_at},r)}function xi(e){if(![fn,dn].includes(e.kind))return;let t,n;for(let r=e.tags.length-1;r>=0&&(t===void 0||n===void 0);r--){const i=e.tags[r];i.length>=2&&(i[0]==="e"&&t===void 0?t=i:i[0]==="p"&&n===void 0&&(n=i))}if(t!==void 0)return{id:t[1],relays:[t[2],n==null?void 0:n[2]].filter(r=>typeof r=="string"),author:n==null?void 0:n[1]}}function el(e,{skipVerification:t}={}){const n=xi(e);if(n===void 0||e.content==="")return;let r;try{r=JSON.parse(e.content)}catch{return}if(r.id===n.id&&!(!t&&!yt(r)))return r}var tl={};q(tl,{NOSTR_URI_REGEX:()=>An,parse:()=>rl,test:()=>nl});var An=new RegExp(`nostr:(${ni.source})`);function nl(e){return typeof e=="string"&&new RegExp(`^${An.source}$`).test(e)}function rl(e){const t=e.match(new RegExp(`^${An.source}$`));if(!t)throw new Error(`Invalid Nostr URI: ${e}`);return{uri:t[0],value:t[1],decoded:bt(t[1])}}var il={};q(il,{finishReactionEvent:()=>ol,getReactedEventPointer:()=>sl});function ol(e,t,n){const r=t.tags.filter(i=>i.length>=2&&(i[0]==="e"||i[0]==="p"));return oe({...e,kind:hn,tags:[...e.tags??[],...r,["e",t.id],["p",t.pubkey]],content:e.content??"+"},n)}function sl(e){if(e.kind!==hn)return;let t,n;for(let r=e.tags.length-1;r>=0&&(t===void 0||n===void 0);r--){const i=e.tags[r];i.length>=2&&(i[0]==="e"&&t===void 0?t=i:i[0]==="p"&&n===void 0&&(n=i))}if(!(t===void 0||n===void 0))return{id:t[1],relays:[t[2],n[2]].filter(r=>r!==void 0),author:n[1]}}var al={};q(al,{parse:()=>ll});var Zn=/\W/m,Jn=/[^\w\/] |[^\w\/]$|$|,| /m,cl=42;function*ll(e){let t=[];if(typeof e!="string"){for(let o=0;o<e.tags.length;o++){const s=e.tags[o];s[0]==="emoji"&&s.length>=3&&t.push({type:"emoji",shortcode:s[1],url:s[2]})}e=e.content}const n=e.length;let r=0,i=0;e:for(;i<n;){const o=e.indexOf(":",i),s=e.indexOf("#",i);if(o===-1&&s===-1)break e;if(o===-1||s>=0&&s<o){if(s===0||e[s-1]===" "){const c=e.slice(s+1,s+cl).match(Zn),a=c?s+1+c.index:n;yield{type:"text",text:e.slice(r,s)},yield{type:"hashtag",value:e.slice(s+1,a)},i=a,r=i;continue e}i=s+1;continue e}if(e.slice(o-5,o)==="nostr"){const c=e.slice(o+60).match(Zn),a=c?o+60+c.index:n;try{let l,{data:f,type:u}=bt(e.slice(o+1,a));switch(u){case"npub":l={pubkey:f};break;case"note":l={id:f};break;case"nsec":i=a+1;continue;default:l=f}r!==o-5&&(yield{type:"text",text:e.slice(r,o-5)}),yield{type:"reference",pointer:l},i=a,r=i;continue e}catch{i=o+1;continue e}}else if(e.slice(o-5,o)==="https"||e.slice(o-4,o)==="http"){const c=e.slice(o+4).match(Jn),a=c?o+4+c.index:n,l=e[o-1]==="s"?5:4;try{let f=new URL(e.slice(o-l,a));if(f.hostname.indexOf(".")===-1)throw new Error("invalid url");if(r!==o-l&&(yield{type:"text",text:e.slice(r,o-l)}),/\.(png|jpe?g|gif|webp|heic|svg)$/i.test(f.pathname)){yield{type:"image",url:f.toString()},i=a,r=i;continue e}if(/\.(mp4|avi|webm|mkv|mov)$/i.test(f.pathname)){yield{type:"video",url:f.toString()},i=a,r=i;continue e}if(/\.(mp3|aac|ogg|opus|wav|flac)$/i.test(f.pathname)){yield{type:"audio",url:f.toString()},i=a,r=i;continue e}yield{type:"url",url:f.toString()},i=a,r=i;continue e}catch{i=a+1;continue e}}else if(e.slice(o-3,o)==="wss"||e.slice(o-2,o)==="ws"){const c=e.slice(o+4).match(Jn),a=c?o+4+c.index:n,l=e[o-1]==="s"?3:2;try{let f=new URL(e.slice(o-l,a));if(f.hostname.indexOf(".")===-1)throw new Error("invalid ws url");r!==o-l&&(yield{type:"text",text:e.slice(r,o-l)}),yield{type:"relay",url:f.toString()},i=a,r=i;continue e}catch{i=a+1;continue e}}else{for(let c=0;c<t.length;c++){const a=t[c];if(e[o+a.shortcode.length+1]===":"&&e.slice(o+1,o+a.shortcode.length+1)===a.shortcode){r!==o&&(yield{type:"text",text:e.slice(r,o)}),yield a,i=o+a.shortcode.length+2,r=i;continue e}}i=o+1;continue e}}r!==n&&(yield{type:"text",text:e.slice(r)})}var ul={};q(ul,{channelCreateEvent:()=>fl,channelHideMessageEvent:()=>gl,channelMessageEvent:()=>dl,channelMetadataEvent:()=>hl,channelMuteUserEvent:()=>pl});var fl=(e,t)=>{let n;if(typeof e.content=="object")n=JSON.stringify(e.content);else if(typeof e.content=="string")n=e.content;else return;return oe({kind:zr,tags:[...e.tags??[]],content:n,created_at:e.created_at},t)},hl=(e,t)=>{let n;if(typeof e.content=="object")n=JSON.stringify(e.content);else if(typeof e.content=="string")n=e.content;else return;return oe({kind:Dr,tags:[["e",e.channel_create_event_id],...e.tags??[]],content:n,created_at:e.created_at},t)},dl=(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"]),oe({kind:Fr,tags:[...n,...e.tags??[]],content:e.content,created_at:e.created_at},t)},gl=(e,t)=>{let n;if(typeof e.content=="object")n=JSON.stringify(e.content);else if(typeof e.content=="string")n=e.content;else return;return oe({kind:jr,tags:[["e",e.channel_message_event_id],...e.tags??[]],content:n,created_at:e.created_at},t)},pl=(e,t)=>{let n;if(typeof e.content=="object")n=JSON.stringify(e.content);else if(typeof e.content=="string")n=e.content;else return;return oe({kind:Wr,tags:[["p",e.pubkey_to_mute],...e.tags??[]],content:n,created_at:e.created_at},t)},yl={};q(yl,{EMOJI_SHORTCODE_REGEX:()=>Ai,matchAll:()=>wl,regex:()=>Sn,replaceAll:()=>bl});var Ai=/:(\w+):/,Sn=()=>new RegExp(`\\B${Ai.source}\\B`,"g");function*wl(e){const t=e.matchAll(Sn());for(const n of t)try{const[r,i]=n;yield{shortcode:r,name:i,start:n.index,end:n.index+r.length}}catch{}}function bl(e,t){return e.replaceAll(Sn(),(n,r)=>t({shortcode:n,name:r}))}var ml={};q(ml,{useFetchImplementation:()=>El,validateGithub:()=>vl});var _n;try{_n=fetch}catch{}function El(e){_n=e}async function vl(e,t,n){try{return await(await _n(`https://gist.github.com/${t}/${n}/raw`)).text()===`Verifying that I control the following Nostr public key: ${e}`}catch{return!1}}var xl={};q(xl,{makeNwcRequestEvent:()=>Sl,parseConnectionString:()=>Al});function Al(e){const{host:t,pathname:n,searchParams:r}=new URL(e),i=n||t,o=r.get("relay"),s=r.get("secret");if(!i||!o||!s)throw new Error("invalid connection string");return{pubkey:i,relay:o,secret:s}}async function Sl(e,t,n){const i=ri(t,e,JSON.stringify({method:"pay_invoice",params:{invoice:n}})),o={kind:Zr,created_at:Math.round(Date.now()/1e3),content:i,tags:[["p",e]]};return oe(o,t)}var _l={};q(_l,{normalizeIdentifier:()=>Bl});function Bl(e){return e=e.trim().toLowerCase(),e=e.normalize("NFKC"),Array.from(e).map(t=>new RegExp("\\p{Letter}","u").test(t)||new RegExp("\\p{Number}","u").test(t)?t:"-").join("")}var Tl={};q(Tl,{getSatoshisAmountFromBolt11:()=>$l,getZapEndpoint:()=>Ll,makeZapReceipt:()=>Ul,makeZapRequest:()=>kl,useFetchImplementation:()=>Il,validateZapRequest:()=>Rl});var Bn;try{Bn=fetch}catch{}function Il(e){Bn=e}async function Ll(e){try{let t="",{lud06:n,lud16:r}=JSON.parse(e.content);if(r){let[s,c]=r.split("@");t=new URL(`/.well-known/lnurlp/${s}`,`https://${c}`).toString()}else if(n){let{words:s}=De.decode(n,1e3),c=De.fromWords(s);t=ue.decode(c)}else return null;let o=await(await Bn(t)).json();if(o.allowsNostr&&o.nostrPubkey)return o.callback}catch{}return null}function kl(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]),ln(e.event.kind)){const n=["a",`${e.event.kind}:${e.event.pubkey}:`];t.tags.push(n)}else if(un(e.event.kind)){let n=e.event.tags.find(([i,o])=>i==="d"&&o);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 Rl(e){let t;try{t=JSON.parse(e)}catch{return"Invalid zap request JSON."}if(!sn(t))return"Zap request is not a valid Nostr event.";if(!yt(t))return"Invalid signature on zap request.";let n=t.tags.find(([o,s])=>o==="p"&&s);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(([o,s])=>o==="e"&&s);return r&&!r[1].match(/^[a-f0-9]{64}$/)?"Zap request 'e' tag is not valid hex.":t.tags.find(([o,s])=>o==="relays"&&s)?null:"Zap request doesn't have a 'relays' tag."}function Ul({zapRequest:e,preimage:t,bolt11:n,paidAt:r}){let i=JSON.parse(e),o=i.tags.filter(([c])=>c==="e"||c==="p"||c==="a"),s={kind:9735,created_at:Math.round(r.getTime()/1e3),content:"",tags:[...o,["P",i.pubkey],["bolt11",n],["description",e]]};return t&&s.tags.push(["preimage",t]),s}function $l(e){if(e.length<50)return 0;e=e.substring(0,50);const t=e.lastIndexOf("1");if(t===-1)return 0;const n=e.substring(0,t);if(!n.startsWith("lnbc"))return 0;const r=n.substring(4);if(r.length<1)return 0;const i=r[r.length-1],o=i.charCodeAt(0)-48,s=o>=0&&o<=9;let c=r.length-1;if(s&&c++,c<1)return 0;const a=parseInt(r.substring(0,c));switch(i){case"m":return a*1e5;case"u":return a*100;case"n":return a/10;case"p":return a/1e4;default:return a*1e8}}var Nl={};q(Nl,{Negentropy:()=>_i,NegentropyStorageVector:()=>Hl,NegentropySync:()=>Pl});var Nt=97,qe=32,Si=16,Be={Skip:0,Fingerprint:1,IdList:2},le=class{constructor(e){m(this,"_raw");m(this,"length");typeof e=="number"?(this._raw=new Uint8Array(e),this.length=0):e instanceof Uint8Array?(this._raw=new Uint8Array(e),this.length=e.length):(this._raw=new Uint8Array(512),this.length=0)}unwrap(){return this._raw.subarray(0,this.length)}get capacity(){return this._raw.byteLength}extend(e){if(e instanceof le&&(e=e.unwrap()),typeof e.length!="number")throw Error("bad length");const t=e.length+this.length;if(this.capacity<t){const n=this._raw,r=Math.max(this.capacity*2,t);this._raw=new Uint8Array(r),this._raw.set(n)}this._raw.set(e,this.length),this.length+=e.length}shift(){const e=this._raw[0];return this._raw=this._raw.subarray(1),this.length--,e}shiftN(e=1){const t=this._raw.subarray(0,e);return this._raw=this._raw.subarray(e),this.length-=e,t}};function Qe(e){let t=0;for(;;){if(e.length===0)throw Error("parse ends prematurely");let n=e.shift();if(t=t<<7|n&127,!(n&128))break}return t}function ae(e){if(e===0)return new le(new Uint8Array([0]));let t=[];for(;e!==0;)t.push(e&127),e>>>=7;t.reverse();for(let n=0;n<t.length-1;n++)t[n]|=128;return new le(new Uint8Array(t))}function Cl(e){return tt(e,1)[0]}function tt(e,t){if(e.length<t)throw Error("parse ends prematurely");return e.shiftN(t)}var Ol=class{constructor(){m(this,"buf");this.setToZero()}setToZero(){this.buf=new Uint8Array(qe)}add(e){let t=0,n=0,r=new DataView(this.buf.buffer),i=new DataView(e.buffer);for(let o=0;o<8;o++){let s=o*4,c=r.getUint32(s,!0),a=i.getUint32(s,!0),l=c;l+=t,l+=a,l>4294967295&&(n=1),r.setUint32(s,l&4294967295,!0),t=n,n=0}}negate(){let e=new DataView(this.buf.buffer);for(let n=0;n<8;n++){let r=n*4;e.setUint32(r,~e.getUint32(r,!0))}let t=new Uint8Array(qe);t[0]=1,this.add(t)}getFingerprint(e){let t=new le;return t.extend(this.buf),t.extend(ae(e)),$e(t.unwrap()).subarray(0,Si)}},Hl=class{constructor(){m(this,"items");m(this,"sealed");this.items=[],this.sealed=!1}insert(e,t){if(this.sealed)throw Error("already sealed");const n=Sr(t);if(n.byteLength!==qe)throw Error("bad id size for added item");this.items.push({timestamp:e,id:n})}seal(){if(this.sealed)throw Error("already sealed");this.sealed=!0,this.items.sort(Ct);for(let e=1;e<this.items.length;e++)if(Ct(this.items[e-1],this.items[e])===0)throw Error("duplicate item inserted")}unseal(){this.sealed=!1}size(){return this._checkSealed(),this.items.length}getItem(e){if(this._checkSealed(),e>=this.items.length)throw Error("out of range");return this.items[e]}iterate(e,t,n){this._checkSealed(),this._checkBounds(e,t);for(let r=e;r<t&&n(this.items[r],r);++r);}findLowerBound(e,t,n){return this._checkSealed(),this._checkBounds(e,t),this._binarySearch(this.items,e,t,r=>Ct(r,n)<0)}fingerprint(e,t){let n=new Ol;return n.setToZero(),this.iterate(e,t,r=>(n.add(r.id),!0)),n.getFingerprint(t-e)}_checkSealed(){if(!this.sealed)throw Error("not sealed")}_checkBounds(e,t){if(e>t||t>this.items.length)throw Error("bad range")}_binarySearch(e,t,n,r){let i=n-t;for(;i>0;){let o=t,s=Math.floor(i/2);o+=s,r(e[o])?(t=++o,i-=s+1):i=s}return t}},_i=class{constructor(e,t=6e4){m(this,"storage");m(this,"frameSizeLimit");m(this,"lastTimestampIn");m(this,"lastTimestampOut");if(t<4096)throw Error("frameSizeLimit too small");this.storage=e,this.frameSizeLimit=t,this.lastTimestampIn=0,this.lastTimestampOut=0}_bound(e,t){return{timestamp:e,id:t||new Uint8Array(0)}}initiate(){let e=new le;return e.extend(new Uint8Array([Nt])),this.splitRange(0,this.storage.size(),this._bound(Number.MAX_VALUE),e),Pe(e.unwrap())}reconcile(e,t,n){const r=new le(Sr(e));this.lastTimestampIn=this.lastTimestampOut=0;let i=new le;i.extend(new Uint8Array([Nt]));let o=Cl(r);if(o<96||o>111)throw Error("invalid negentropy protocol version byte");if(o!==Nt)throw Error("unsupported negentropy protocol version requested: "+(o-96));let s=this.storage.size(),c=this._bound(0),a=0,l=!1;for(;r.length!==0;){let f=new le,u=()=>{l&&(l=!1,f.extend(this.encodeBound(c)),f.extend(ae(Be.Skip)))},p=this.decodeBound(r),y=Qe(r),g=a,h=this.storage.findLowerBound(a,s,p);if(y===Be.Skip)l=!0;else if(y===Be.Fingerprint){let d=tt(r,Si),w=this.storage.fingerprint(g,h);Bi(d,w)!==0?(u(),this.splitRange(g,h,p,f)):l=!0}else if(y===Be.IdList){let d=Qe(r),w={};for(let v=0;v<d;v++){let S=tt(r,qe);w[Pe(S)]=S}if(l=!0,this.storage.iterate(g,h,v=>{let S=v.id;const L=Pe(S);return w[L]?delete w[Pe(S)]:t==null||t(L),!0}),n)for(let v of Object.values(w))n(Pe(v))}else throw Error("unexpected mode");if(this.exceededFrameSizeLimit(i.length+f.length)){let d=this.storage.fingerprint(h,s);i.extend(this.encodeBound(this._bound(Number.MAX_VALUE))),i.extend(ae(Be.Fingerprint)),i.extend(d);break}else i.extend(f);a=h,c=p}return i.length===1?null:Pe(i.unwrap())}splitRange(e,t,n,r){let i=t-e,o=16;if(i<o*2)r.extend(this.encodeBound(n)),r.extend(ae(Be.IdList)),r.extend(ae(i)),this.storage.iterate(e,t,s=>(r.extend(s.id),!0));else{let s=Math.floor(i/o),c=i%o,a=e;for(let l=0;l<o;l++){let f=s+(l<c?1:0),u=this.storage.fingerprint(a,a+f);a+=f;let p;if(a===t)p=n;else{let y,g;this.storage.iterate(a-1,a+1,(h,d)=>(d===a-1?y=h:g=h,!0)),p=this.getMinimalBound(y,g)}r.extend(this.encodeBound(p)),r.extend(ae(Be.Fingerprint)),r.extend(u)}}}exceededFrameSizeLimit(e){return e>this.frameSizeLimit-200}decodeTimestampIn(e){let t=Qe(e);return t=t===0?Number.MAX_VALUE:t-1,this.lastTimestampIn===Number.MAX_VALUE||t===Number.MAX_VALUE?(this.lastTimestampIn=Number.MAX_VALUE,Number.MAX_VALUE):(t+=this.lastTimestampIn,this.lastTimestampIn=t,t)}decodeBound(e){let t=this.decodeTimestampIn(e),n=Qe(e);if(n>qe)throw Error("bound key too long");let r=tt(e,n);return{timestamp:t,id:r}}encodeTimestampOut(e){if(e===Number.MAX_VALUE)return this.lastTimestampOut=Number.MAX_VALUE,ae(0);let t=e;return e-=this.lastTimestampOut,this.lastTimestampOut=t,ae(e+1)}encodeBound(e){let t=new le;return t.extend(this.encodeTimestampOut(e.timestamp)),t.extend(ae(e.id.length)),t.extend(e.id),t}getMinimalBound(e,t){if(t.timestamp!==e.timestamp)return this._bound(t.timestamp);{let n=0,r=t.id,i=e.id;for(let o=0;o<qe&&r[o]===i[o];o++)n++;return this._bound(t.timestamp,t.id.subarray(0,n+1))}}};function Bi(e,t){for(let n=0;n<e.byteLength;n++){if(e[n]<t[n])return-1;if(e[n]>t[n])return 1}return e.byteLength>t.byteLength?1:e.byteLength<t.byteLength?-1:0}function Ct(e,t){return e.timestamp===t.timestamp?Bi(e.id,t.id):e.timestamp-t.timestamp}var Pl=class{constructor(e,t,n,r={}){m(this,"relay");m(this,"storage");m(this,"neg");m(this,"filter");m(this,"subscription");m(this,"onhave");m(this,"onneed");this.relay=e,this.storage=t,this.neg=new _i(t),this.onhave=r.onhave,this.onneed=r.onneed,this.filter=n,this.subscription=this.relay.prepareSubscription([{}],{label:r.label||"negentropy"}),this.subscription.oncustom=i=>{var o,s,c,a;switch(i[0]){case"NEG-MSG":{i.length<3&&console.warn(`got invalid NEG-MSG from ${this.relay.url}: ${i}`);try{const l=this.neg.reconcile(i[2],this.onhave,this.onneed);l?this.relay.send(`["NEG-MSG", "${this.subscription.id}", "${l}"]`):(this.close(),(o=r.onclose)==null||o.call(r))}catch(l){console.error("negentropy reconcile error:",l),(s=r==null?void 0:r.onclose)==null||s.call(r,`reconcile error: ${l}`)}break}case"NEG-CLOSE":{const l=i[2];console.warn("negentropy error:",l),(c=r.onclose)==null||c.call(r,l);break}case"NEG-ERR":(a=r.onclose)==null||a.call(r)}}}async start(){const e=this.neg.initiate();this.relay.send(`["NEG-OPEN","${this.subscription.id}",${JSON.stringify(this.filter)},"${e}"]`)}close(){this.relay.send(`["NEG-CLOSE","${this.subscription.id}"]`),this.subscription.close()}},Ml={};q(Ml,{getToken:()=>ql,hashPayload:()=>Tn,unpackEventFromToken:()=>Ii,validateEvent:()=>Ni,validateEventKind:()=>ki,validateEventMethodTag:()=>Ui,validateEventPayloadTag:()=>$i,validateEventTimestamp:()=>Li,validateEventUrlTag:()=>Ri,validateToken:()=>Vl});var Ti="Nostr ";async function ql(e,t,n,r=!1,i){const o={kind:gn,tags:[["u",e],["method",t]],created_at:Math.round(new Date().getTime()/1e3),content:""};i&&o.tags.push(["payload",Tn(i)]);const s=await n(o);return(r?Ti:"")+fe.encode(Q.encode(JSON.stringify(s)))}async function Vl(e,t,n){const r=await Ii(e).catch(o=>{throw o});return await Ni(r,t,n).catch(o=>{throw o})}async function Ii(e){if(!e)throw new Error("Missing token");e=e.replace(Ti,"");const t=ue.decode(fe.decode(e));if(!t||t.length===0||!t.startsWith("{"))throw new Error("Invalid token");return JSON.parse(t)}function Li(e){return e.created_at?Math.round(new Date().getTime()/1e3)-e.created_at<60:!1}function ki(e){return e.kind===gn}function Ri(e,t){const n=e.tags.find(r=>r[0]==="u");return n?n.length>0&&n[1]===t:!1}function Ui(e,t){const n=e.tags.find(r=>r[0]==="method");return n?n.length>0&&n[1].toLowerCase()===t.toLowerCase():!1}function Tn(e){const t=$e(Q.encode(JSON.stringify(e)));return W(t)}function $i(e,t){const n=e.tags.find(i=>i[0]==="payload");if(!n)return!1;const r=Tn(t);return n.length>0&&n[1]===r}async function Ni(e,t,n,r){if(!yt(e))throw new Error("Invalid nostr event, signature invalid");if(!ki(e))throw new Error("Invalid nostr event, kind invalid");if(!Li(e))throw new Error("Invalid nostr event, created_at timestamp invalid");if(!Ri(e,t))throw new Error("Invalid nostr event, url tag invalid");if(!Ui(e,n))throw new Error("Invalid nostr event, method tag invalid");if(r&&typeof r=="object"&&Object.keys(r).length>0&&!$i(e,r))throw new Error("Invalid nostr event, payload tag does not match request body hash");return!0}export{Kl as S,gc as a,Ls as b,W as c,$e as d,oe as f,cn as g,qc as n,Ge as s};