nostr-double-ratchet 0.0.6 → 0.0.8

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.
@@ -1 +1 @@
1
- (function(q,G){typeof exports=="object"&&typeof module<"u"?G(exports):typeof define=="function"&&define.amd?define(["exports"],G):(q=typeof globalThis<"u"?globalThis:q||self,G(q["nostr-double-ratchet"]={}))})(this,function(q){"use strict";var Bc=Object.defineProperty;var Ic=(q,G,Ce)=>G in q?Bc(q,G,{enumerable:!0,configurable:!0,writable:!0,value:Ce}):q[G]=Ce;var re=(q,G,Ce)=>Ic(q,typeof G!="symbol"?G+"":G,Ce);function G(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`Wrong positive integer: ${e}`)}function Ce(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 ai(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");G(e.outputLen),G(e.blockLen)}function rt(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 ci(e,t){Ce(e);const n=t.outputLen;if(e.length<n)throw new Error(`digestInto() expects output buffer of length at least ${n}`)}const Kt=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */const mn=e=>e instanceof Uint8Array,Nt=e=>new DataView(e.buffer,e.byteOffset,e.byteLength),ie=(e,t)=>e<<32-t|e>>>t;if(!(new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68))throw new Error("Non little-endian hardware is not supported");function li(e){if(typeof e!="string")throw new Error(`utf8ToBytes expected string, got ${typeof e}`);return new Uint8Array(new TextEncoder().encode(e))}function Ct(e){if(typeof e=="string"&&(e=li(e)),!mn(e))throw new Error(`expected Uint8Array, got ${typeof e}`);return e}function ui(...e){const t=new Uint8Array(e.reduce((r,i)=>r+i.length,0));let n=0;return e.forEach(r=>{if(!mn(r))throw new Error("Uint8Array expected");t.set(r,n),n+=r.length}),t}let xn=class{clone(){return this._cloneInto()}};function fi(e){const t=r=>e().update(Ct(r)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function Sn(e=32){if(Kt&&typeof Kt.getRandomValues=="function")return Kt.getRandomValues(new Uint8Array(e));throw new Error("crypto.getRandomValues must be defined")}function hi(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 di=class extends xn{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=Nt(this.buffer)}update(t){rt(this);const{view:n,buffer:r,blockLen:i}=this;t=Ct(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=Nt(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){rt(this),ci(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;hi(r,i-8,BigInt(this.length*8),o),this.process(r,0);const c=Nt(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 yi=(e,t,n)=>e&t^~e&n,gi=(e,t,n)=>e&t^e&n^t&n,pi=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),pe=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),we=new Uint32Array(64);let wi=class extends di{constructor(){super(64,32,8,!1),this.A=pe[0]|0,this.B=pe[1]|0,this.C=pe[2]|0,this.D=pe[3]|0,this.E=pe[4]|0,this.F=pe[5]|0,this.G=pe[6]|0,this.H=pe[7]|0}get(){const{A: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)we[u]=t.getUint32(n,!1);for(let u=16;u<64;u++){const d=we[u-15],g=we[u-2],p=ie(d,7)^ie(d,18)^d>>>3,h=ie(g,17)^ie(g,19)^g>>>10;we[u]=h+we[u-7]+p+we[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 d=ie(c,6)^ie(c,11)^ie(c,25),g=f+d+yi(c,a,l)+pi[u]+we[u]|0,h=(ie(r,2)^ie(r,13)^ie(r,22))+gi(r,i,o)|0;f=l,l=a,a=c,c=s+g|0,s=o,o=i,i=r,r=g+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(){we.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};const Bt=fi(()=>new wi);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const An=BigInt(0),it=BigInt(1),bi=BigInt(2),ot=e=>e instanceof Uint8Array,vi=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Re(e){if(!ot(e))throw new Error("Uint8Array expected");let t="";for(let n=0;n<e.length;n++)t+=vi[e[n]];return t}function Kn(e){const t=e.toString(16);return t.length&1?`0${t}`:t}function It(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return BigInt(e===""?"0":`0x${e}`)}function Pe(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 J(e){return It(Re(e))}function Ut(e){if(!ot(e))throw new Error("Uint8Array expected");return It(Re(Uint8Array.from(e).reverse()))}function be(e,t){return Pe(e.toString(16).padStart(t*2,"0"))}function kt(e,t){return be(e,t).reverse()}function Ei(e){return Pe(Kn(e))}function F(e,t,n){let r;if(typeof t=="string")try{r=Pe(t)}catch(o){throw new Error(`${e} must be valid hex string, got "${t}". Cause: ${o}`)}else if(ot(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 Be(...e){const t=new Uint8Array(e.reduce((r,i)=>r+i.length,0));let n=0;return e.forEach(r=>{if(!ot(r))throw new Error("Uint8Array expected");t.set(r,n),n+=r.length}),t}function mi(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 xi(e){if(typeof e!="string")throw new Error(`utf8ToBytes expected string, got ${typeof e}`);return new Uint8Array(new TextEncoder().encode(e))}function Si(e){let t;for(t=0;e>An;e>>=it,t+=1);return t}function Ai(e,t){return e>>BigInt(t)&it}const Ki=(e,t,n)=>e|(n?it:An)<<BigInt(t),_t=e=>(bi<<BigInt(e-1))-it,Lt=e=>new Uint8Array(e),Nn=e=>Uint8Array.from(e);function Cn(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=Lt(e),i=Lt(e),o=0;const s=()=>{r.fill(1),i.fill(0),o=0},c=(...u)=>n(i,r,...u),a=(u=Lt())=>{i=c(Nn([0]),u),r=c(),u.length!==0&&(i=c(Nn([1]),u),r=c())},l=()=>{if(o++>=1e3)throw new Error("drbg: tried 1000 values");let u=0;const d=[];for(;u<t;){r=c();const g=r.slice();d.push(g),u+=r.length}return Be(...d)};return(u,d)=>{s(),a(u);let g;for(;!(g=d(l()));)a();return s(),g}}const Ni={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 Fe(e,t,n={}){const r=(i,o,s)=>{const c=Ni[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 Ci=Object.freeze(Object.defineProperty({__proto__:null,bitGet:Ai,bitLen:Si,bitMask:_t,bitSet:Ki,bytesToHex:Re,bytesToNumberBE:J,bytesToNumberLE:Ut,concatBytes:Be,createHmacDrbg:Cn,ensureBytes:F,equalBytes:mi,hexToBytes:Pe,hexToNumber:It,numberToBytesBE:be,numberToBytesLE:kt,numberToHexUnpadded:Kn,numberToVarBytesBE:Ei,utf8ToBytes:xi,validateObject:Fe},Symbol.toStringTag,{value:"Module"}));/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const z=BigInt(0),D=BigInt(1),Ie=BigInt(2),Bi=BigInt(3),Tt=BigInt(4),Bn=BigInt(5),In=BigInt(8);BigInt(9),BigInt(16);function V(e,t){const n=e%t;return n>=z?n:t+n}function Ii(e,t,n){if(n<=z||t<z)throw new Error("Expected power/modulo > 0");if(n===D)return z;let r=D;for(;t>z;)t&D&&(r=r*e%n),e=e*e%n,t>>=D;return r}function X(e,t,n){let r=e;for(;t-- >z;)r*=r,r%=n;return r}function $t(e,t){if(e===z||t<=z)throw new Error(`invert: expected positive integers, got n=${e} mod=${t}`);let n=V(e,t),r=t,i=z,o=D;for(;n!==z;){const c=r/n,a=r%n,l=i-o*c;r=n,n=a,i=o,o=l}if(r!==D)throw new Error("invert: does not exist");return V(i,t)}function Ui(e){const t=(e-D)/Ie;let n,r,i;for(n=e-D,r=0;n%Ie===z;n/=Ie,r++);for(i=Ie;i<e&&Ii(i,t,e)!==e-D;i++);if(r===1){const s=(e+D)/Tt;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+D)/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),d=c.pow(a,n);for(;!c.eql(d,c.ONE);){if(c.eql(d,c.ZERO))return c.ZERO;let g=1;for(let h=c.sqr(d);g<l&&!c.eql(h,c.ONE);g++)h=c.sqr(h);const p=c.pow(f,D<<BigInt(l-g-1));f=c.sqr(p),u=c.mul(u,p),d=c.mul(d,f),l=g}return u}}function ki(e){if(e%Tt===Bi){const t=(e+D)/Tt;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%In===Bn){const t=(e-Bn)/In;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 Ui(e)}const _i=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Li(e){const t={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},n=_i.reduce((r,i)=>(r[i]="function",r),t);return Fe(e,n)}function Ti(e,t,n){if(n<z)throw new Error("Expected power > 0");if(n===z)return e.ONE;if(n===D)return t;let r=e.ONE,i=t;for(;n>z;)n&D&&(r=e.mul(r,i)),i=e.sqr(i),n>>=D;return r}function $i(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 Un(e,t){const n=t!==void 0?t:e.toString(2).length,r=Math.ceil(n/8);return{nBitLength:n,nByteLength:r}}function Ri(e,t,n=!1,r={}){if(e<=z)throw new Error(`Expected Field ORDER > 0, got ${e}`);const{nBitLength:i,nByteLength:o}=Un(e,t);if(o>2048)throw new Error("Field lengths over 2048 bytes are not supported");const s=ki(e),c=Object.freeze({ORDER:e,BITS:i,BYTES:o,MASK:_t(i),ZERO:z,ONE:D,create:a=>V(a,e),isValid:a=>{if(typeof a!="bigint")throw new Error(`Invalid field element: expected bigint, got ${typeof a}`);return z<=a&&a<e},is0:a=>a===z,isOdd:a=>(a&D)===D,neg:a=>V(-a,e),eql:(a,l)=>a===l,sqr:a=>V(a*a,e),add:(a,l)=>V(a+l,e),sub:(a,l)=>V(a-l,e),mul:(a,l)=>V(a*l,e),pow:(a,l)=>Ti(c,a,l),div:(a,l)=>V(a*$t(l,e),e),sqrN:a=>a*a,addN:(a,l)=>a+l,subN:(a,l)=>a-l,mulN:(a,l)=>a*l,inv:a=>$t(a,e),sqrt:r.sqrt||(a=>s(c,a)),invertBatch:a=>$i(c,a),cmov:(a,l,f)=>f?l:a,toBytes:a=>n?kt(a,o):be(a,o),fromBytes:a=>{if(a.length!==o)throw new Error(`Fp.fromBytes: expected ${o}, got ${a.length}`);return n?Ut(a):J(a)}});return Object.freeze(c)}function kn(e){if(typeof e!="bigint")throw new Error("field order must be bigint");const t=e.toString(2).length;return Math.ceil(t/8)}function _n(e){const t=kn(e);return t+Math.ceil(t/2)}function Pi(e,t,n=!1){const r=e.length,i=kn(t),o=_n(t);if(r<16||r<o||r>1024)throw new Error(`expected ${o}-1024 bytes of input, got ${r}`);const s=n?J(e):Ut(e),c=V(s,t-D)+D;return n?kt(c,i):be(c,i)}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Oi=BigInt(0),Rt=BigInt(1);function Mi(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>Oi;)o&Rt&&(s=s.add(c)),c=c.double(),o>>=Rt;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 d=1;d<c;d++)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),d=2**i,g=BigInt(i);for(let p=0;p<c;p++){const h=p*a;let y=Number(s&u);s>>=g,y>a&&(y-=d,s+=Rt);const w=h,m=h+Math.abs(y)-1,K=p%2!==0,k=y<0;y===0?f=f.add(n(K,o[w])):l=l.add(n(k,o[m]))}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 Ln(e){return Li(e.Fp),Fe(e,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...Un(e.n,e.nBitLength),...e,p:e.Fp.ORDER})}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function Hi(e){const t=Ln(e);Fe(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:qi,hexToBytes:Di}=Ci,Ue={Err:class extends Error{constructor(t=""){super(t)}},_parseInt(e){const{Err:t}=Ue;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:qi(r),l:e.subarray(n+2)}},toSig(e){const{Err:t}=Ue,n=typeof e=="string"?Di(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}=Ue._parseInt(n.subarray(2)),{d:s,l:c}=Ue._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}`}},ue=BigInt(0),Q=BigInt(1);BigInt(2);const Tn=BigInt(3);BigInt(4);function ji(e){const t=Hi(e),{Fp:n}=t,r=t.toBytes||((p,h,y)=>{const w=h.toAffine();return Be(Uint8Array.from([4]),n.toBytes(w.x),n.toBytes(w.y))}),i=t.fromBytes||(p=>{const h=p.subarray(1),y=n.fromBytes(h.subarray(0,n.BYTES)),w=n.fromBytes(h.subarray(n.BYTES,2*n.BYTES));return{x:y,y:w}});function o(p){const{a:h,b:y}=t,w=n.sqr(p),m=n.mul(w,p);return n.add(n.add(m,n.mul(p,h)),y)}if(!n.eql(n.sqr(t.Gy),o(t.Gx)))throw new Error("bad generator point: equation left != right");function s(p){return typeof p=="bigint"&&ue<p&&p<t.n}function c(p){if(!s(p))throw new Error("Expected valid bigint: 0 < bigint < curve.n")}function a(p){const{allowedPrivateKeyLengths:h,nByteLength:y,wrapPrivateKey:w,n:m}=t;if(h&&typeof p!="bigint"){if(p instanceof Uint8Array&&(p=Re(p)),typeof p!="string"||!h.includes(p.length))throw new Error("Invalid key");p=p.padStart(y*2,"0")}let K;try{K=typeof p=="bigint"?p:J(F("private key",p,y))}catch{throw new Error(`private key must be ${y} bytes, hex or bigint, not ${typeof p}`)}return w&&(K=V(K,m)),c(K),K}const l=new Map;function f(p){if(!(p instanceof u))throw new Error("ProjectivePoint expected")}class u{constructor(h,y,w){if(this.px=h,this.py=y,this.pz=w,h==null||!n.isValid(h))throw new Error("x required");if(y==null||!n.isValid(y))throw new Error("y required");if(w==null||!n.isValid(w))throw new Error("z required")}static fromAffine(h){const{x:y,y:w}=h||{};if(!h||!n.isValid(y)||!n.isValid(w))throw new Error("invalid affine point");if(h instanceof u)throw new Error("projective point not allowed");const m=K=>n.eql(K,n.ZERO);return m(y)&&m(w)?u.ZERO:new u(y,w,n.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(h){const y=n.invertBatch(h.map(w=>w.pz));return h.map((w,m)=>w.toAffine(y[m])).map(u.fromAffine)}static fromHex(h){const y=u.fromAffine(i(F("pointHex",h)));return y.assertValidity(),y}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}=this.toAffine();if(!n.isValid(h)||!n.isValid(y))throw new Error("bad point: x or y not FE");const w=n.sqr(y),m=o(h);if(!n.eql(w,m))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:y,py:w,pz:m}=this,{px:K,py:k,pz:B}=h,E=n.eql(n.mul(y,B),n.mul(K,m)),x=n.eql(n.mul(w,B),n.mul(k,m));return E&&x}negate(){return new u(this.px,n.neg(this.py),this.pz)}double(){const{a:h,b:y}=t,w=n.mul(y,Tn),{px:m,py:K,pz:k}=this;let B=n.ZERO,E=n.ZERO,x=n.ZERO,S=n.mul(m,m),O=n.mul(K,K),U=n.mul(k,k),N=n.mul(m,K);return N=n.add(N,N),x=n.mul(m,k),x=n.add(x,x),B=n.mul(h,x),E=n.mul(w,U),E=n.add(B,E),B=n.sub(O,E),E=n.add(O,E),E=n.mul(B,E),B=n.mul(N,B),x=n.mul(w,x),U=n.mul(h,U),N=n.sub(S,U),N=n.mul(h,N),N=n.add(N,x),x=n.add(S,S),S=n.add(x,S),S=n.add(S,U),S=n.mul(S,N),E=n.add(E,S),U=n.mul(K,k),U=n.add(U,U),S=n.mul(U,N),B=n.sub(B,S),x=n.mul(U,O),x=n.add(x,x),x=n.add(x,x),new u(B,E,x)}add(h){f(h);const{px:y,py:w,pz:m}=this,{px:K,py:k,pz:B}=h;let E=n.ZERO,x=n.ZERO,S=n.ZERO;const O=t.a,U=n.mul(t.b,Tn);let N=n.mul(y,K),$=n.mul(w,k),R=n.mul(m,B),H=n.add(y,w),b=n.add(K,k);H=n.mul(H,b),b=n.add(N,$),H=n.sub(H,b),b=n.add(y,m);let v=n.add(K,B);return b=n.mul(b,v),v=n.add(N,R),b=n.sub(b,v),v=n.add(w,m),E=n.add(k,B),v=n.mul(v,E),E=n.add($,R),v=n.sub(v,E),S=n.mul(O,b),E=n.mul(U,R),S=n.add(E,S),E=n.sub($,S),S=n.add($,S),x=n.mul(E,S),$=n.add(N,N),$=n.add($,N),R=n.mul(O,R),b=n.mul(U,b),$=n.add($,R),R=n.sub(N,R),R=n.mul(O,R),b=n.add(b,R),N=n.mul($,b),x=n.add(x,N),N=n.mul(v,b),E=n.mul(H,E),E=n.sub(E,N),N=n.mul(H,$),S=n.mul(v,S),S=n.add(S,N),new u(E,x,S)}subtract(h){return this.add(h.negate())}is0(){return this.equals(u.ZERO)}wNAF(h){return g.wNAFCached(this,l,h,y=>{const w=n.invertBatch(y.map(m=>m.pz));return y.map((m,K)=>m.toAffine(w[K])).map(u.fromAffine)})}multiplyUnsafe(h){const y=u.ZERO;if(h===ue)return y;if(c(h),h===Q)return this;const{endo:w}=t;if(!w)return g.unsafeLadder(this,h);let{k1neg:m,k1:K,k2neg:k,k2:B}=w.splitScalar(h),E=y,x=y,S=this;for(;K>ue||B>ue;)K&Q&&(E=E.add(S)),B&Q&&(x=x.add(S)),S=S.double(),K>>=Q,B>>=Q;return m&&(E=E.negate()),k&&(x=x.negate()),x=new u(n.mul(x.px,w.beta),x.py,x.pz),E.add(x)}multiply(h){c(h);let y=h,w,m;const{endo:K}=t;if(K){const{k1neg:k,k1:B,k2neg:E,k2:x}=K.splitScalar(y);let{p:S,f:O}=this.wNAF(B),{p:U,f:N}=this.wNAF(x);S=g.constTimeNegate(k,S),U=g.constTimeNegate(E,U),U=new u(n.mul(U.px,K.beta),U.py,U.pz),w=S.add(U),m=O.add(N)}else{const{p:k,f:B}=this.wNAF(y);w=k,m=B}return u.normalizeZ([w,m])[0]}multiplyAndAddUnsafe(h,y,w){const m=u.BASE,K=(B,E)=>E===ue||E===Q||!B.equals(m)?B.multiplyUnsafe(E):B.multiply(E),k=K(this,y).add(K(h,w));return k.is0()?void 0:k}toAffine(h){const{px:y,py:w,pz:m}=this,K=this.is0();h==null&&(h=K?n.ONE:n.inv(m));const k=n.mul(y,h),B=n.mul(w,h),E=n.mul(m,h);if(K)return{x:n.ZERO,y:n.ZERO};if(!n.eql(E,n.ONE))throw new Error("invZ was invalid");return{x:k,y:B}}isTorsionFree(){const{h,isTorsionFree:y}=t;if(h===Q)return!0;if(y)return y(u,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){const{h,clearCofactor:y}=t;return h===Q?this:y?y(u,this):this.multiplyUnsafe(t.h)}toRawBytes(h=!0){return this.assertValidity(),r(u,this,h)}toHex(h=!0){return Re(this.toRawBytes(h))}}u.BASE=new u(t.Gx,t.Gy,n.ONE),u.ZERO=new u(n.ZERO,n.ONE,n.ZERO);const d=t.nBitLength,g=Mi(u,t.endo?Math.ceil(d/2):d);return{CURVE:t,ProjectivePoint:u,normPrivateKeyToScalar:a,weierstrassEquation:o,isWithinCurveOrder:s}}function zi(e){const t=Ln(e);return Fe(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}function Vi(e){const t=zi(e),{Fp:n,n:r}=t,i=n.BYTES+1,o=2*n.BYTES+1;function s(b){return ue<b&&b<n.ORDER}function c(b){return V(b,r)}function a(b){return $t(b,r)}const{ProjectivePoint:l,normPrivateKeyToScalar:f,weierstrassEquation:u,isWithinCurveOrder:d}=ji({...t,toBytes(b,v,A){const I=v.toAffine(),C=n.toBytes(I.x),L=Be;return A?L(Uint8Array.from([v.hasEvenY()?2:3]),C):L(Uint8Array.from([4]),C,n.toBytes(I.y))},fromBytes(b){const v=b.length,A=b[0],I=b.subarray(1);if(v===i&&(A===2||A===3)){const C=J(I);if(!s(C))throw new Error("Point is not on curve");const L=u(C);let P=n.sqrt(L);const T=(P&Q)===Q;return(A&1)===1!==T&&(P=n.neg(P)),{x:C,y:P}}else if(v===o&&A===4){const C=n.fromBytes(I.subarray(0,n.BYTES)),L=n.fromBytes(I.subarray(n.BYTES,2*n.BYTES));return{x:C,y:L}}else throw new Error(`Point of length ${v} was invalid. Expected ${i} compressed bytes or ${o} uncompressed bytes`)}}),g=b=>Re(be(b,t.nByteLength));function p(b){const v=r>>Q;return b>v}function h(b){return p(b)?c(-b):b}const y=(b,v,A)=>J(b.slice(v,A));class w{constructor(v,A,I){this.r=v,this.s=A,this.recovery=I,this.assertValidity()}static fromCompact(v){const A=t.nByteLength;return v=F("compactSignature",v,A*2),new w(y(v,0,A),y(v,A,2*A))}static fromDER(v){const{r:A,s:I}=Ue.toSig(F("DER",v));return new w(A,I)}assertValidity(){if(!d(this.r))throw new Error("r must be 0 < r < CURVE.n");if(!d(this.s))throw new Error("s must be 0 < s < CURVE.n")}addRecoveryBit(v){return new w(this.r,this.s,v)}recoverPublicKey(v){const{r:A,s:I,recovery:C}=this,L=x(F("msgHash",v));if(C==null||![0,1,2,3].includes(C))throw new Error("recovery id invalid");const P=C===2||C===3?A+t.n:A;if(P>=n.ORDER)throw new Error("recovery id 2 or 3 invalid");const T=C&1?"03":"02",te=l.fromHex(T+g(P)),Ke=a(P),je=c(-L*Ke),nt=c(I*Ke),Ne=l.BASE.multiplyAndAddUnsafe(te,je,nt);if(!Ne)throw new Error("point at infinify");return Ne.assertValidity(),Ne}hasHighS(){return p(this.s)}normalizeS(){return this.hasHighS()?new w(this.r,c(-this.s),this.recovery):this}toDERRawBytes(){return Pe(this.toDERHex())}toDERHex(){return Ue.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return Pe(this.toCompactHex())}toCompactHex(){return g(this.r)+g(this.s)}}const m={isValidPrivateKey(b){try{return f(b),!0}catch{return!1}},normPrivateKeyToScalar:f,randomPrivateKey:()=>{const b=_n(t.n);return Pi(t.randomBytes(b),t.n)},precompute(b=8,v=l.BASE){return v._setWindowSize(b),v.multiply(BigInt(3)),v}};function K(b,v=!0){return l.fromPrivateKey(b).toRawBytes(v)}function k(b){const v=b instanceof Uint8Array,A=typeof b=="string",I=(v||A)&&b.length;return v?I===i||I===o:A?I===2*i||I===2*o:b instanceof l}function B(b,v,A=!0){if(k(b))throw new Error("first arg must be private key");if(!k(v))throw new Error("second arg must be public key");return l.fromHex(v).multiply(f(b)).toRawBytes(A)}const E=t.bits2int||function(b){const v=J(b),A=b.length*8-t.nBitLength;return A>0?v>>BigInt(A):v},x=t.bits2int_modN||function(b){return c(E(b))},S=_t(t.nBitLength);function O(b){if(typeof b!="bigint")throw new Error("bigint expected");if(!(ue<=b&&b<S))throw new Error(`bigint expected < 2^${t.nBitLength}`);return be(b,t.nByteLength)}function U(b,v,A=N){if(["recovered","canonical"].some($e=>$e in A))throw new Error("sign() legacy options not supported");const{hash:I,randomBytes:C}=t;let{lowS:L,prehash:P,extraEntropy:T}=A;L==null&&(L=!0),b=F("msgHash",b),P&&(b=F("prehashed msgHash",I(b)));const te=x(b),Ke=f(v),je=[O(Ke),O(te)];if(T!=null){const $e=T===!0?C(n.BYTES):T;je.push(F("extraEntropy",$e))}const nt=Be(...je),Ne=te;function En($e){const ze=E($e);if(!d(ze))return;const ii=a(ze),Ve=l.BASE.multiply(ze).toAffine(),ne=c(Ve.x);if(ne===ue)return;const Ze=c(ii*c(Ne+ne*Ke));if(Ze===ue)return;let oi=(Ve.x===ne?0:2)|Number(Ve.y&Q),si=Ze;return L&&p(Ze)&&(si=h(Ze),oi^=1),new w(ne,si,oi)}return{seed:nt,k2sig:En}}const N={lowS:t.lowS,prehash:!1},$={lowS:t.lowS,prehash:!1};function R(b,v,A=N){const{seed:I,k2sig:C}=U(b,v,A),L=t;return Cn(L.hash.outputLen,L.nByteLength,L.hmac)(I,C)}l.BASE._setWindowSize(8);function H(b,v,A,I=$){var Ve;const C=b;if(v=F("msgHash",v),A=F("publicKey",A),"strict"in I)throw new Error("options.strict was renamed to lowS");const{lowS:L,prehash:P}=I;let T,te;try{if(typeof C=="string"||C instanceof Uint8Array)try{T=w.fromDER(C)}catch(ne){if(!(ne instanceof Ue.Err))throw ne;T=w.fromCompact(C)}else if(typeof C=="object"&&typeof C.r=="bigint"&&typeof C.s=="bigint"){const{r:ne,s:Ze}=C;T=new w(ne,Ze)}else throw new Error("PARSE");te=l.fromHex(A)}catch(ne){if(ne.message==="PARSE")throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(L&&T.hasHighS())return!1;P&&(v=t.hash(v));const{r:Ke,s:je}=T,nt=x(v),Ne=a(je),En=c(nt*Ne),$e=c(Ke*Ne),ze=(Ve=l.BASE.multiplyAndAddUnsafe(te,En,$e))==null?void 0:Ve.toAffine();return ze?c(ze.x)===Ke:!1}return{CURVE:t,getPublicKey:K,getSharedSecret:B,sign:R,verify:H,ProjectivePoint:l,Signature:w,utils:m}}let $n=class extends xn{constructor(t,n){super(),this.finished=!1,this.destroyed=!1,ai(t);const r=Ct(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 rt(this),this.iHash.update(t),this}digestInto(t){rt(this),Ce(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 Rn=(e,t,n)=>new $n(e,t).update(n).digest();Rn.create=(e,t)=>new $n(e,t);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function Zi(e){return{hash:e,hmac:(t,...n)=>Rn(e,t,ui(...n)),randomBytes:Sn}}function Fi(e,t){const n=r=>Vi({...e,...Zi(r)});return Object.freeze({...n(t),create:n})}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const st=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),at=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),Pn=BigInt(1),ct=BigInt(2),On=(e,t)=>(e+t/ct)/t;function Mn(e){const t=st,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=X(f,n,t)*f%t,d=X(u,n,t)*f%t,g=X(d,ct,t)*l%t,p=X(g,i,t)*g%t,h=X(p,o,t)*p%t,y=X(h,c,t)*h%t,w=X(y,a,t)*y%t,m=X(w,c,t)*h%t,K=X(m,n,t)*f%t,k=X(K,s,t)*p%t,B=X(k,r,t)*l%t,E=X(B,ct,t);if(!Pt.eql(Pt.sqr(E),e))throw new Error("Cannot find square root");return E}const Pt=Ri(st,void 0,void 0,{sqrt:Mn}),ke=Fi({a:BigInt(0),b:BigInt(7),Fp:Pt,n:at,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:e=>{const t=at,n=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),r=-Pn*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),i=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),o=n,s=BigInt("0x100000000000000000000000000000000"),c=On(o*e,t),a=On(-r*e,t);let l=V(e-c*n-a*i,t),f=V(-c*r-a*o,t);const u=l>s,d=f>s;if(u&&(l=t-l),d&&(f=t-f),l>s||f>s)throw new Error("splitScalar: Endomorphism failed, k="+e);return{k1neg:u,k1:l,k2neg:d,k2:f}}}},Bt),lt=BigInt(0),Hn=e=>typeof e=="bigint"&&lt<e&&e<st,Wi=e=>typeof e=="bigint"&&lt<e&&e<at,qn={};function ut(e,...t){let n=qn[e];if(n===void 0){const r=Bt(Uint8Array.from(e,i=>i.charCodeAt(0)));n=Be(r,r),qn[e]=n}return Bt(Be(n,...t))}const Ot=e=>e.toRawBytes(!0).slice(1),Mt=e=>be(e,32),Ht=e=>V(e,st),We=e=>V(e,at),qt=ke.ProjectivePoint,Gi=(e,t,n)=>qt.BASE.multiplyAndAddUnsafe(e,t,n);function Dt(e){let t=ke.utils.normPrivateKeyToScalar(e),n=qt.fromPrivateKey(t);return{scalar:n.hasEvenY()?t:We(-t),bytes:Ot(n)}}function Dn(e){if(!Hn(e))throw new Error("bad x: need 0 < x < p");const t=Ht(e*e),n=Ht(t*e+BigInt(7));let r=Mn(n);r%ct!==lt&&(r=Ht(-r));const i=new qt(e,r,Pn);return i.assertValidity(),i}function jn(...e){return We(J(ut("BIP0340/challenge",...e)))}function Ji(e){return Dt(e).bytes}function Yi(e,t,n=Sn(32)){const r=F("message",e),{bytes:i,scalar:o}=Dt(t),s=F("auxRand",n,32),c=Mt(o^J(ut("BIP0340/aux",s))),a=ut("BIP0340/nonce",c,i,r),l=We(J(a));if(l===lt)throw new Error("sign failed: k is zero");const{bytes:f,scalar:u}=Dt(l),d=jn(f,i,r),g=new Uint8Array(64);if(g.set(f,0),g.set(Mt(We(u+d*o)),32),!zn(g,r,i))throw new Error("sign: Invalid signature produced");return g}function zn(e,t,n){const r=F("signature",e,64),i=F("message",t),o=F("publicKey",n,32);try{const s=Dn(J(o)),c=J(r.subarray(0,32));if(!Hn(c))return!1;const a=J(r.subarray(32,64));if(!Wi(a))return!1;const l=jn(Mt(c),Ot(s),i),f=Gi(s,a,We(-l));return!(!f||!f.hasEvenY()||f.toAffine().x!==c)}catch{return!1}}const Ge={getPublicKey:Ji,sign:Yi,verify:zn,utils:{randomPrivateKey:ke.utils.randomPrivateKey,lift_x:Dn,pointToBytes:Ot,numberToBytesBE:be,bytesToNumberBE:J,taggedHash:ut,mod:V}},jt=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */const zt=e=>e instanceof Uint8Array,Vt=e=>new DataView(e.buffer,e.byteOffset,e.byteLength),oe=(e,t)=>e<<32-t|e>>>t;if(!(new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68))throw new Error("Non little-endian hardware is not supported");const Xi=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function M(e){if(!zt(e))throw new Error("Uint8Array expected");let t="";for(let n=0;n<e.length;n++)t+=Xi[e[n]];return t}function Y(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 Qi(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=Qi(e)),!zt(e))throw new Error(`expected Uint8Array, got ${typeof e}`);return e}function ft(...e){const t=new Uint8Array(e.reduce((r,i)=>r+i.length,0));let n=0;return e.forEach(r=>{if(!zt(r))throw new Error("Uint8Array expected");t.set(r,n),n+=r.length}),t}class Vn{clone(){return this._cloneInto()}}function Zn(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 Fn(e=32){if(jt&&typeof jt.getRandomValues=="function")return jt.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 eo(e){if(typeof e!="boolean")throw new Error(`Expected boolean, not ${e}`)}function Wn(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 to(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 no(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 ro(e,t){Wn(e);const n=t.outputLen;if(e.length<n)throw new Error(`digestInto() expects output buffer of length at least ${n}`)}const se={number:Zt,bool:eo,bytes:Wn,hash:to,exists:no,output:ro};function io(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 oo extends Vn{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=Vt(this.buffer)}update(t){se.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=Vt(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){se.exists(this),se.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;io(r,i-8,BigInt(this.length*8),o),this.process(r,0);const c=Vt(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 so=(e,t,n)=>e&t^~e&n,ao=(e,t,n)=>e&t^e&n^t&n,co=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]),ve=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Ee=new Uint32Array(64);class Gn extends oo{constructor(){super(64,32,8,!1),this.A=ve[0]|0,this.B=ve[1]|0,this.C=ve[2]|0,this.D=ve[3]|0,this.E=ve[4]|0,this.F=ve[5]|0,this.G=ve[6]|0,this.H=ve[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 d=Ee[u-15],g=Ee[u-2],p=oe(d,7)^oe(d,18)^d>>>3,h=oe(g,17)^oe(g,19)^g>>>10;Ee[u]=h+Ee[u-7]+p+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 d=oe(c,6)^oe(c,11)^oe(c,25),g=f+d+so(c,a,l)+co[u]+Ee[u]|0,h=(oe(r,2)^oe(r,13)^oe(r,22))+ao(r,i,o)|0;f=l,l=a,a=c,c=s+g|0,s=o,o=i,i=r,r=g+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 lo extends Gn{constructor(){super(),this.A=-1056596264,this.B=914150663,this.C=812702999,this.D=-150054599,this.E=-4191439,this.F=1750603025,this.G=1694076839,this.H=-1090891868,this.outputLen=28}}const me=Zn(()=>new Gn);Zn(()=>new lo);/*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) */function Oe(e){if(!Number.isSafeInteger(e))throw new Error(`Wrong integer: ${e}`)}function fe(...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 he(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(Oe(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 de(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 ht(e,t="="){if(Oe(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 Jn(e){if(typeof e!="function")throw new Error("normalize fn should be function");return{encode:t=>t,decode:t=>e(t)}}function Yn(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(Oe(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 Xn=(e,t)=>t?Xn(t,e%t):e,dt=(e,t)=>e+(t-Xn(e,t));function Ft(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(dt(t,n)>32)throw new Error(`convertRadix2: carry overflow from=${t} to=${n} carryBits=${dt(t,n)}`);let i=0,o=0;const s=2**n-1,c=[];for(const a of e){if(Oe(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 uo(e){return Oe(e),{encode:t=>{if(!(t instanceof Uint8Array))throw new Error("radix.encode input should be Uint8Array");return Yn(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(Yn(t,e,2**8))}}}function xe(e,t=!1){if(Oe(e),e<=0||e>32)throw new Error("radix2: bits should be in (0..32]");if(dt(8,e)>32||dt(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 Ft(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(Ft(n,e,8,t))}}}function Qn(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=fe(xe(4),he("0123456789ABCDEF"),de("")),ho=fe(xe(5),he("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"),ht(5),de(""));fe(xe(5),he("0123456789ABCDEFGHIJKLMNOPQRSTUV"),ht(5),de("")),fe(xe(5),he("0123456789ABCDEFGHJKMNPQRSTVWXYZ"),de(""),Jn(e=>e.toUpperCase().replace(/O/g,"0").replace(/[IL]/g,"1")));const ye=fe(xe(6),he("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),ht(6),de("")),yo=fe(xe(6),he("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"),ht(6),de("")),Wt=e=>fe(uo(58),he(e),de("")),Gt=Wt("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");Wt("123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"),Wt("rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz");const er=[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+=Gt.encode(r).padStart(er[r.length],"1")}return t},decode(e){let t=[];for(let n=0;n<e.length;n+=11){const r=e.slice(n,n+11),i=er.indexOf(r.length),o=Gt.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=fe(he("qpzry9x8gf2tvdw0s3jn54khce6mua7l"),de("")),tr=[996825010,642813549,513874426,1027748829,705979059];function Ye(e){const t=e>>25;let n=(e&33554431)<<5;for(let r=0;r<tr.length;r++)(t>>r&1)===1&&(n^=tr[r]);return n}function nr(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=Ye(i)^s>>5}i=Ye(i);for(let o=0;o<r;o++)i=Ye(i)^e.charCodeAt(o)&31;for(let o of t)i=Ye(i)^o;for(let o=0;o<6;o++)i=Ye(i);return i^=n,Jt.encode(Ft([i%2**30],30,5,!1))}function rr(e){const t=e==="bech32"?1:734539939,n=xe(5),r=n.decode,i=n.encode,o=Qn(r);function s(f,u,d=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 g=f.length+7+u.length;if(d!==!1&&g>d)throw new TypeError(`Length ${g} exceeds limit ${d}`);return f=f.toLowerCase(),`${f}1${Jt.encode(u)}${nr(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 d=f.toLowerCase();if(f!==d&&f!==f.toUpperCase())throw new Error("String must be lowercase or uppercase");f=d;const g=f.lastIndexOf("1");if(g===0||g===-1)throw new Error('Letter "1" must be present between prefix and data only');const p=f.slice(0,g),h=f.slice(g+1);if(h.length<6)throw new Error("Data must be at least 6 characters long");const y=Jt.decode(h).slice(0,-6),w=nr(p,y,t);if(!h.endsWith(w))throw new Error(`Invalid checksum in ${f}: expected "${w}"`);return{prefix:p,words:y}}const a=Qn(c);function l(f){const{prefix:u,words:d}=c(f,!1);return{prefix:u,words:d,bytes:r(d)}}return{encode:s,decode:c,decodeToBytes:l,decodeUnsafe:a,fromWords:r,fromWordsUnsafe:o,toWords:i}}const Me=rr("bech32");rr("bech32m");const po={encode:e=>new TextDecoder().decode(e),decode:e=>new TextEncoder().encode(e)},wo=fe(xe(4),he("0123456789abcdef"),de(""),Jn(e=>{if(typeof e!="string"||e.length%2)throw new TypeError(`hex.decode: expected string, got ${typeof e} with length ${e.length}`);return e.toLowerCase()}));`${Object.keys({utf8:po,hex:wo,base16:fo,base32:ho,base64:ye,base64url:yo,base58:Gt,base58xmr:go}).join(", ")}`;function Yt(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`positive integer expected, not ${e}`)}function ir(e){if(typeof e!="boolean")throw new Error(`boolean expected, not ${e}`)}function bo(e){return e instanceof Uint8Array||e!=null&&typeof e=="object"&&e.constructor.name==="Uint8Array"}function ge(e,...t){if(!bo(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 W=e=>new Uint32Array(e.buffer,e.byteOffset,Math.floor(e.byteLength/4));if(!(new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68))throw new Error("Non little-endian hardware is not supported");function vo(e,t){if(t==null||typeof t!="object")throw new Error("options must be defined");return Object.assign(e,t)}function Eo(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 mo=(e,t)=>(Object.assign(t,e),t),Se=16,xo=283;function Xt(e){return e<<1^xo&-(e>>7)}function He(e,t){let n=0;for(;t>0;t>>=1)n^=e&-(t&1),e=Xt(e);return n}const Qt=(()=>{let e=new Uint8Array(256);for(let n=0,r=1;n<256;n++,r^=Xt(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})(),So=Qt.map((e,t)=>Qt.indexOf(t)),Ao=e=>e<<24|e>>>8,en=e=>e<<8|e>>>24;function or(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(en),i=r.map(en),o=i.map(en),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 tn=or(Qt,e=>He(e,3)<<24|e<<16|e<<8|He(e,2)),sr=or(So,e=>He(e,11)<<24|He(e,13)<<16|He(e,9)<<8|He(e,14)),Ko=(()=>{const e=new Uint8Array(16);for(let t=0,n=1;t<16;t++,n=Xt(n))e[t]=n;return e})();function ar(e){ge(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}=tn,r=W(e),i=r.length,o=c=>ae(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(Ao(a))^Ko[c/i-1]:i>6&&c%i===4&&(a=o(a)),s[c]=s[c-i]^a}return s}function No(e){const t=ar(e),n=t.slice(),r=t.length,{sbox2:i}=tn,{T0:o,T1:s,T2:c,T3:a}=sr;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=ae(i,f,f,f,f);n[l]=o[u&255]^s[u>>>8&255]^c[u>>>16&255]^a[u>>>24]}return n}function Ae(e,t,n,r,i,o){return e[n<<8&65280|r>>>8&255]^t[i>>>8&65280|o>>>24&255]}function ae(e,t,n,r,i){return e[t&255|n&65280]|e[r>>>16&255|i>>>16&65280]<<16}function cr(e,t,n,r,i){const{sbox2:o,T01:s,T23:c}=tn;let a=0;t^=e[a++],n^=e[a++],r^=e[a++],i^=e[a++];const l=e.length/4-2;for(let p=0;p<l;p++){const h=e[a++]^Ae(s,c,t,n,r,i),y=e[a++]^Ae(s,c,n,r,i,t),w=e[a++]^Ae(s,c,r,i,t,n),m=e[a++]^Ae(s,c,i,t,n,r);t=h,n=y,r=w,i=m}const f=e[a++]^ae(o,t,n,r,i),u=e[a++]^ae(o,n,r,i,t),d=e[a++]^ae(o,r,i,t,n),g=e[a++]^ae(o,i,t,n,r);return{s0:f,s1:u,s2:d,s3:g}}function Co(e,t,n,r,i){const{sbox2:o,T01:s,T23:c}=sr;let a=0;t^=e[a++],n^=e[a++],r^=e[a++],i^=e[a++];const l=e.length/4-2;for(let p=0;p<l;p++){const h=e[a++]^Ae(s,c,t,i,r,n),y=e[a++]^Ae(s,c,n,t,i,r),w=e[a++]^Ae(s,c,r,n,t,i),m=e[a++]^Ae(s,c,i,r,n,t);t=h,n=y,r=w,i=m}const f=e[a++]^ae(o,t,i,r,n),u=e[a++]^ae(o,n,t,i,r),d=e[a++]^ae(o,r,n,t,i),g=e[a++]^ae(o,i,r,n,t);return{s0:f,s1:u,s2:d,s3:g}}function lr(e,t){if(!t)return new Uint8Array(e);if(ge(t),t.length<e)throw new Error(`aes: wrong destination length, expected at least ${e}, got: ${t.length}`);return t}function Bo(e){if(ge(e),e.length%Se!==0)throw new Error(`aes/(cbc-ecb).decrypt ciphertext should consist of blocks with size ${Se}`)}function Io(e,t,n){let r=e.length;const i=r%Se;if(!t&&i!==0)throw new Error("aec/(cbc-ecb): unpadded plaintext with disabled padding");const o=W(e);if(t){let a=Se-i;a||(a=Se),r=r+a}const s=lr(r,n),c=W(s);return{b:o,o:c,out:s}}function Uo(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 ko(e){const t=new Uint8Array(16),n=W(t);t.set(e);const r=Se-e.length;for(let i=Se-r;i<Se;i++)t[i]=r;return n}const ur=mo({blockSize:16,nonceLength:16},function(t,n,r={}){ge(t),ge(n,16);const i=!r.disablePadding;return{encrypt:(o,s)=>{const c=ar(t),{b:a,o:l,out:f}=Io(o,i,s),u=W(n);let d=u[0],g=u[1],p=u[2],h=u[3],y=0;for(;y+4<=a.length;)d^=a[y+0],g^=a[y+1],p^=a[y+2],h^=a[y+3],{s0:d,s1:g,s2:p,s3:h}=cr(c,d,g,p,h),l[y++]=d,l[y++]=g,l[y++]=p,l[y++]=h;if(i){const w=ko(o.subarray(y*4));d^=w[0],g^=w[1],p^=w[2],h^=w[3],{s0:d,s1:g,s2:p,s3:h}=cr(c,d,g,p,h),l[y++]=d,l[y++]=g,l[y++]=p,l[y++]=h}return c.fill(0),f},decrypt:(o,s)=>{Bo(o);const c=No(t),a=W(n),l=lr(o.length,s),f=W(o),u=W(l);let d=a[0],g=a[1],p=a[2],h=a[3];for(let y=0;y+4<=f.length;){const w=d,m=g,K=p,k=h;d=f[y+0],g=f[y+1],p=f[y+2],h=f[y+3];const{s0:B,s1:E,s2:x,s3:S}=Co(c,d,g,p,h);u[y++]=B^w,u[y++]=E^m,u[y++]=x^K,u[y++]=S^k}return c.fill(0),Uo(l,i)}}}),fr=e=>Uint8Array.from(e.split("").map(t=>t.charCodeAt(0))),_o=fr("expand 16-byte k"),Lo=fr("expand 32-byte k"),To=W(_o),hr=W(Lo);hr.slice();function _(e,t){return e<<t|e>>>32-t}function nn(e){return e.byteOffset%4===0}const yt=64,$o=16,dr=2**32-1,yr=new Uint32Array;function Ro(e,t,n,r,i,o,s,c){const a=i.length,l=new Uint8Array(yt),f=W(l),u=nn(i)&&nn(o),d=u?W(i):yr,g=u?W(o):yr;for(let p=0;p<a;s++){if(e(t,n,r,f,s,c),s>=dr)throw new Error("arx: counter overflow");const h=Math.min(yt,a-p);if(u&&h===yt){const y=p/4;if(p%4!==0)throw new Error("arx: invalid block position");for(let w=0,m;w<$o;w++)m=y+w,g[m]=d[m]^f[w];p+=yt;continue}for(let y=0,w;y<h;y++)w=p+y,o[w]=i[w]^l[y];p+=h}}function Po(e,t){const{allowShortKeys:n,extendNonceFn:r,counterLength:i,counterRight:o,rounds:s}=vo({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},t);if(typeof e!="function")throw new Error("core must be a function");return Yt(i),Yt(s),ir(o),ir(n),(c,a,l,f,u=0)=>{ge(c),ge(a),ge(l);const d=l.length;if(f||(f=new Uint8Array(d)),ge(f),Yt(u),u<0||u>=dr)throw new Error("arx: counter overflow");if(f.length<d)throw new Error(`arx: output (${f.length}) is shorter than data (${d})`);const g=[];let p=c.length,h,y;if(p===32)h=c.slice(),g.push(h),y=hr;else if(p===16&&n)h=new Uint8Array(32),h.set(c),h.set(c,16),y=To,g.push(h);else throw new Error(`arx: invalid 32-byte key, got length=${p}`);nn(a)||(a=a.slice(),g.push(a));const w=W(h);if(r){if(a.length!==24)throw new Error("arx: extended nonce must be 24 bytes");r(y,w,W(a.subarray(0,16)),w),a=a.subarray(16)}const m=16-i;if(m!==a.length)throw new Error(`arx: nonce must be ${m} or 16 bytes`);if(m!==12){const k=new Uint8Array(12);k.set(a,o?0:12-a.length),a=k,g.push(a)}const K=W(a);for(Ro(e,y,w,K,l,f,u,s);g.length>0;)g.pop().fill(0);return f}}function Oo(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],d=t[2],g=t[3],p=t[4],h=t[5],y=t[6],w=t[7],m=i,K=n[0],k=n[1],B=n[2],E=s,x=c,S=a,O=l,U=f,N=u,$=d,R=g,H=p,b=h,v=y,A=w,I=m,C=K,L=k,P=B;for(let te=0;te<o;te+=2)E=E+U|0,I=_(I^E,16),H=H+I|0,U=_(U^H,12),E=E+U|0,I=_(I^E,8),H=H+I|0,U=_(U^H,7),x=x+N|0,C=_(C^x,16),b=b+C|0,N=_(N^b,12),x=x+N|0,C=_(C^x,8),b=b+C|0,N=_(N^b,7),S=S+$|0,L=_(L^S,16),v=v+L|0,$=_($^v,12),S=S+$|0,L=_(L^S,8),v=v+L|0,$=_($^v,7),O=O+R|0,P=_(P^O,16),A=A+P|0,R=_(R^A,12),O=O+R|0,P=_(P^O,8),A=A+P|0,R=_(R^A,7),E=E+N|0,P=_(P^E,16),v=v+P|0,N=_(N^v,12),E=E+N|0,P=_(P^E,8),v=v+P|0,N=_(N^v,7),x=x+$|0,I=_(I^x,16),A=A+I|0,$=_($^A,12),x=x+$|0,I=_(I^x,8),A=A+I|0,$=_($^A,7),S=S+R|0,C=_(C^S,16),H=H+C|0,R=_(R^H,12),S=S+R|0,C=_(C^S,8),H=H+C|0,R=_(R^H,7),O=O+U|0,L=_(L^O,16),b=b+L|0,U=_(U^b,12),O=O+U|0,L=_(L^O,8),b=b+L|0,U=_(U^b,7);let T=0;r[T++]=s+E|0,r[T++]=c+x|0,r[T++]=a+S|0,r[T++]=l+O|0,r[T++]=f+U|0,r[T++]=u+N|0,r[T++]=d+$|0,r[T++]=g+R|0,r[T++]=p+H|0,r[T++]=h+b|0,r[T++]=y+v|0,r[T++]=w+A|0,r[T++]=m+I|0,r[T++]=K+C|0,r[T++]=k+L|0,r[T++]=B+P|0}const gr=Po(Oo,{counterRight:!1,counterLength:4,allowShortKeys:!1});class pr extends Vn{constructor(t,n){super(),this.finished=!1,this.destroyed=!1,se.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 se.exists(this),this.iHash.update(t),this}digestInto(t){se.exists(this),se.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 pr(e,t).update(n).digest();gt.create=(e,t)=>new pr(e,t);function rn(e,t,n){return se.hash(e),n===void 0&&(n=new Uint8Array(e.outputLen)),gt(e,Je(n),Je(t))}const on=new Uint8Array([0]),wr=new Uint8Array;function br(e,t,n,r=32){if(se.hash(e),se.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=wr);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++)on[0]=l+1,c.update(l===0?wr:a).update(n).update(on).digestInto(a),o.set(a,e.outputLen*l),s._cloneInto(c);return s.destroy(),c.destroy(),a.fill(0),on.fill(0),o.slice(0,r)}var Mo=Object.defineProperty,j=(e,t)=>{for(var n in t)Mo(e,n,{get:t[n],enumerable:!0})},qe=Symbol("verified"),Ho=e=>e instanceof Object;function vr(e){if(!Ho(e)||typeof e.kind!="number"||typeof e.content!="string"||typeof e.created_at!="number"||typeof e.pubkey!="string"||!e.pubkey.match(/^[a-f0-9]{64}$/)||!Array.isArray(e.tags))return!1;for(let t=0;t<e.tags.length;t++){let n=e.tags[t];if(!Array.isArray(n))return!1;for(let r=0;r<n.length;r++)if(typeof n[r]=="object")return!1}return!0}var qo={};j(qo,{Queue:()=>Vo,QueueNode:()=>Er,binarySearch:()=>sn,insertEventIntoAscendingList:()=>zo,insertEventIntoDescendingList:()=>jo,normalizeURL:()=>Do,utf8Decoder:()=>ce,utf8Encoder:()=>ee});var ce=new TextDecoder("utf-8"),ee=new TextEncoder;function Do(e){e.indexOf("://")===-1&&(e="wss://"+e);let t=new URL(e);return t.pathname=t.pathname.replace(/\/+/g,"/"),t.pathname.endsWith("/")&&(t.pathname=t.pathname.slice(0,-1)),(t.port==="80"&&t.protocol==="ws:"||t.port==="443"&&t.protocol==="wss:")&&(t.port=""),t.searchParams.sort(),t.hash="",t.toString()}function jo(e,t){const[n,r]=sn(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 zo(e,t){const[n,r]=sn(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 sn(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 Er=class{constructor(e){re(this,"value");re(this,"next",null);re(this,"prev",null);this.value=e}},Vo=class{constructor(){re(this,"first");re(this,"last");this.first=null,this.last=null}enqueue(e){const t=new Er(e);return this.last?this.last===this.first?(this.last=t,this.last.prev=this.first,this.first.next=t):(t.prev=this.last,this.last.next=t,this.last=t):(this.first=t,this.last=t),!0}dequeue(){if(!this.first)return null;if(this.first===this.last){const t=this.first;return this.first=null,this.last=null,t.value}const e=this.first;return this.first=e.next,e.value}},Zo=class{generateSecretKey(){return Ge.utils.randomPrivateKey()}getPublicKey(e){return M(Ge.getPublicKey(e))}finalizeEvent(e,t){const n=e;return n.pubkey=M(Ge.getPublicKey(t)),n.id=pt(n),n.sig=M(Ge.sign(pt(n),t)),n[qe]=!0,n}verifyEvent(e){if(typeof e[qe]=="boolean")return e[qe];const t=pt(e);if(t!==e.id)return e[qe]=!1,!1;try{const n=Ge.verify(e.sig,t,e.pubkey);return e[qe]=n,n}catch{return e[qe]=!1,!1}}};function Fo(e){if(!vr(e))throw new Error("can't serialize event with wrong or missing properties");return JSON.stringify([0,e.pubkey,e.created_at,e.kind,e.tags,e.content])}function pt(e){let t=me(ee.encode(Fo(e)));return M(t)}var wt=new Zo,De=wt.generateSecretKey,_e=wt.getPublicKey,le=wt.finalizeEvent,an=wt.verifyEvent,Wo={};j(Wo,{Application:()=>Ws,BadgeAward:()=>rs,BadgeDefinition:()=>qs,BlockedRelaysList:()=>Ns,BookmarkList:()=>Ss,Bookmarksets:()=>Os,Calendar:()=>ta,CalendarEventRSVP:()=>na,ChannelCreation:()=>Kr,ChannelHideMessage:()=>Br,ChannelMessage:()=>Cr,ChannelMetadata:()=>Nr,ChannelMuteUser:()=>Ir,ClassifiedListing:()=>Ys,ClientAuth:()=>Ur,CommunitiesList:()=>As,CommunityDefinition:()=>oa,CommunityPostApproval:()=>hs,Contacts:()=>Qo,CreateOrUpdateProduct:()=>zs,CreateOrUpdateStall:()=>js,Curationsets:()=>Ms,Date:()=>Qs,DraftClassifiedListing:()=>Xs,DraftLong:()=>Zs,Emojisets:()=>Fs,EncryptedDirectMessage:()=>es,EncryptedDirectMessages:()=>ts,EventDeletion:()=>ns,FileMetadata:()=>ss,FileServerPreference:()=>Us,Followsets:()=>$s,GenericRepost:()=>is,Genericlists:()=>Rs,HTTPAuth:()=>un,Handlerinformation:()=>ia,Handlerrecommendation:()=>ra,Highlights:()=>vs,InterestsList:()=>Bs,Interestsets:()=>Ds,JobFeedback:()=>gs,JobRequest:()=>ds,JobResult:()=>ys,Label:()=>fs,LightningPubRPC:()=>_s,LiveChatMessage:()=>as,LiveEvent:()=>Gs,LongFormArticle:()=>Vs,Metadata:()=>Jo,Mutelist:()=>Es,NWCWalletInfo:()=>ks,NWCWalletRequest:()=>kr,NWCWalletResponse:()=>Ls,NostrConnect:()=>Ts,OpenTimestamps:()=>os,Pinlist:()=>ms,ProblemTracker:()=>cs,ProfileBadges:()=>Hs,PublicChatsList:()=>Ks,Reaction:()=>ln,RecommendRelay:()=>Xo,RelayList:()=>xs,Relaysets:()=>Ps,Report:()=>ls,Reporting:()=>us,Repost:()=>cn,SearchRelaysList:()=>Cs,ShortTextNote:()=>Yo,Time:()=>ea,UserEmojiList:()=>Is,UserStatuses:()=>Js,Zap:()=>bs,ZapGoal:()=>ps,ZapRequest:()=>ws,classifyKind:()=>Go,isEphemeralKind:()=>Sr,isParameterizedReplaceableKind:()=>Ar,isRegularKind:()=>mr,isReplaceableKind:()=>xr});function mr(e){return 1e3<=e&&e<1e4||[1,2,4,5,6,7,8,16,40,41,42,43,44].includes(e)}function xr(e){return[0,3].includes(e)||1e4<=e&&e<2e4}function Sr(e){return 2e4<=e&&e<3e4}function Ar(e){return 3e4<=e&&e<4e4}function Go(e){return mr(e)?"regular":xr(e)?"replaceable":Sr(e)?"ephemeral":Ar(e)?"parameterized":"unknown"}var Jo=0,Yo=1,Xo=2,Qo=3,es=4,ts=4,ns=5,cn=6,ln=7,rs=8,is=16,Kr=40,Nr=41,Cr=42,Br=43,Ir=44,os=1040,ss=1063,as=1311,cs=1971,ls=1984,us=1984,fs=1985,hs=4550,ds=5999,ys=6999,gs=7e3,ps=9041,ws=9734,bs=9735,vs=9802,Es=1e4,ms=10001,xs=10002,Ss=10003,As=10004,Ks=10005,Ns=10006,Cs=10007,Bs=10015,Is=10030,Us=10096,ks=13194,_s=21e3,Ur=22242,kr=23194,Ls=23195,Ts=24133,un=27235,$s=3e4,Rs=30001,Ps=30002,Os=30003,Ms=30004,Hs=30008,qs=30009,Ds=30015,js=30017,zs=30018,Vs=30023,Zs=30024,Fs=30030,Ws=30078,Gs=30311,Js=30315,Ys=30402,Xs=30403,Qs=31922,ea=31923,ta=31924,na=31925,ra=31989,ia=31990,oa=34550,sa={};j(sa,{getHex64:()=>fn,getInt:()=>_r,getSubscriptionId:()=>aa,matchEventId:()=>ca,matchEventKind:()=>ua,matchEventPubkey:()=>la});function fn(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 _r(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 aa(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 ca(e,t){return t===fn(e,"id")}function la(e,t){return t===fn(e,"pubkey")}function ua(e,t){return t===_r(e,"kind")}var fa={};j(fa,{makeAuthEvent:()=>ha});function ha(e,t){return{kind:Ur,created_at:Math.floor(Date.now()/1e3),tags:[["relay",e],["challenge",t]],content:""}}var da;try{da=WebSocket}catch{}var ya;try{ya=WebSocket}catch{}var Xe={};j(Xe,{BECH32_REGEX:()=>Lr,Bech32MaxSize:()=>hn,decode:()=>bt,encodeBytes:()=>Et,naddrEncode:()=>ma,neventEncode:()=>Ea,noteEncode:()=>ba,nprofileEncode:()=>va,npubEncode:()=>wa,nrelayEncode:()=>xa,nsecEncode:()=>pa});var hn=5e3,Lr=/[\x21-\x7E]{1,83}1[023456789acdefghjklmnpqrstuvwxyz]{6,}/;function ga(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 bt(e){var i,o,s,c,a,l,f,u;let{prefix:t,words:n}=Me.decode(e,hn),r=new Uint8Array(Me.fromWords(n));switch(t){case"nprofile":{let d=vt(r);if(!((i=d[0])!=null&&i[0]))throw new Error("missing TLV 0 for nprofile");if(d[0][0].length!==32)throw new Error("TLV 0 should be 32 bytes");return{type:"nprofile",data:{pubkey:M(d[0][0]),relays:d[1]?d[1].map(g=>ce.decode(g)):[]}}}case"nevent":{let d=vt(r);if(!((o=d[0])!=null&&o[0]))throw new Error("missing TLV 0 for nevent");if(d[0][0].length!==32)throw new Error("TLV 0 should be 32 bytes");if(d[2]&&d[2][0].length!==32)throw new Error("TLV 2 should be 32 bytes");if(d[3]&&d[3][0].length!==4)throw new Error("TLV 3 should be 4 bytes");return{type:"nevent",data:{id:M(d[0][0]),relays:d[1]?d[1].map(g=>ce.decode(g)):[],author:(s=d[2])!=null&&s[0]?M(d[2][0]):void 0,kind:(c=d[3])!=null&&c[0]?parseInt(M(d[3][0]),16):void 0}}}case"naddr":{let d=vt(r);if(!((a=d[0])!=null&&a[0]))throw new Error("missing TLV 0 for naddr");if(!((l=d[2])!=null&&l[0]))throw new Error("missing TLV 2 for naddr");if(d[2][0].length!==32)throw new Error("TLV 2 should be 32 bytes");if(!((f=d[3])!=null&&f[0]))throw new Error("missing TLV 3 for naddr");if(d[3][0].length!==4)throw new Error("TLV 3 should be 4 bytes");return{type:"naddr",data:{identifier:ce.decode(d[0][0]),pubkey:M(d[2][0]),kind:parseInt(M(d[3][0]),16),relays:d[1]?d[1].map(g=>ce.decode(g)):[]}}}case"nrelay":{let d=vt(r);if(!((u=d[0])!=null&&u[0]))throw new Error("missing TLV 0 for nrelay");return{type:"nrelay",data:ce.decode(d[0][0])}}case"nsec":return{type:t,data:r};case"npub":case"note":return{type:t,data:M(r)};default:throw new Error(`unknown prefix ${t}`)}}function vt(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 pa(e){return Et("nsec",e)}function wa(e){return Et("npub",Y(e))}function ba(e){return Et("note",Y(e))}function Qe(e,t){let n=Me.toWords(t);return Me.encode(e,n,hn)}function Et(e,t){return Qe(e,t)}function va(e){let t=mt({0:[Y(e.pubkey)],1:(e.relays||[]).map(n=>ee.encode(n))});return Qe("nprofile",t)}function Ea(e){let t;e.kind!==void 0&&(t=ga(e.kind));let n=mt({0:[Y(e.id)],1:(e.relays||[]).map(r=>ee.encode(r)),2:e.author?[Y(e.author)]:[],3:t?[new Uint8Array(t)]:[]});return Qe("nevent",n)}function ma(e){let t=new ArrayBuffer(4);new DataView(t).setUint32(0,e.kind,!1);let n=mt({0:[ee.encode(e.identifier)],1:(e.relays||[]).map(r=>ee.encode(r)),2:[Y(e.pubkey)],3:[new Uint8Array(t)]});return Qe("naddr",n)}function xa(e){let t=mt({0:[ee.encode(e)]});return Qe("nrelay",t)}function mt(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)})}),ft(...t)}var Sa={};j(Sa,{decrypt:()=>Aa,encrypt:()=>Tr});async function Tr(e,t,n){const r=e instanceof Uint8Array?M(e):e,i=ke.getSharedSecret(r,"02"+t),o=$r(i);let s=Uint8Array.from(Fn(16)),c=ee.encode(n),a=ur(o,s).encrypt(c),l=ye.encode(new Uint8Array(a)),f=ye.encode(new Uint8Array(s.buffer));return`${l}?iv=${f}`}async function Aa(e,t,n){const r=e instanceof Uint8Array?M(e):e;let[i,o]=n.split("?iv="),s=ke.getSharedSecret(r,"02"+t),c=$r(s),a=ye.decode(o),l=ye.decode(i),f=ur(c,a).decrypt(l);return ce.decode(f)}function $r(e){return e.slice(1,33)}var Ka={};j(Ka,{NIP05_REGEX:()=>Rr,isValid:()=>Ba,queryProfile:()=>Pr,searchDomain:()=>Ca,useFetchImplementation:()=>Na});var Rr=/^(?:([\w.+-]+)@)?([\w_-]+(\.[\w_-]+)+)$/,xt;try{xt=fetch}catch{}function Na(e){xt=e}async function Ca(e,t=""){try{const n=`https://${e}/.well-known/nostr.json?name=${t}`;return(await(await xt(n,{redirect:"error"})).json()).names}catch{return{}}}async function Pr(e){var o;const t=e.match(Rr);if(!t)return null;const[n,r="_",i]=t;try{const s=`https://${i}/.well-known/nostr.json?name=${r}`,c=await(await xt(s,{redirect:"error"})).json();let a=c.names[r];return a?{pubkey:a,relays:(o=c.relays)==null?void 0:o[a]}:null}catch{return null}}async function Ba(e,t){let n=await Pr(t);return n?n.pubkey===e:!1}var Ia={};j(Ia,{parse:()=>Ua});function Ua(e){const t={reply:void 0,root:void 0,mentions:[],profiles:[]},n=[];for(const r of e.tags)r[0]==="e"&&r[1]&&n.push(r),r[0]==="p"&&r[1]&&t.profiles.push({pubkey:r[1],relays:r[2]?[r[2]]:[]});for(let r=0;r<n.length;r++){const i=n[r],[o,s,c,a]=i,l={id:s,relays:c?[c]:[]},f=r===0,u=r===n.length-1;if(a==="root"){t.root=l;continue}if(a==="reply"){t.reply=l;continue}if(a==="mention"){t.mentions.push(l);continue}if(f){t.root=l;continue}if(u){t.reply=l;continue}t.mentions.push(l)}return t}var ka={};j(ka,{fetchRelayInformation:()=>La,useFetchImplementation:()=>_a});var Or;try{Or=fetch}catch{}function _a(e){Or=e}async function La(e){return await(await fetch(e.replace("ws://","http://").replace("wss://","https://"),{headers:{Accept:"application/nostr+json"}})).json()}var Ta={};j(Ta,{getPow:()=>Mr,minePow:()=>$a});function Mr(e){let t=0;for(let n=0;n<e.length;n++){const r=parseInt(e[n],16);if(r===0)t+=4;else{t+=Math.clz32(r)-28;break}}return t}function $a(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=pt(r),Mr(r.id)>=t)break}return r}var Ra={};j(Ra,{finishRepostEvent:()=>Pa,getRepostedEvent:()=>Oa,getRepostedEventPointer:()=>Hr});function Pa(e,t,n,r){return le({kind:cn,tags:[...e.tags??[],["e",t.id,n],["p",t.pubkey]],content:e.content===""?"":JSON.stringify(t),created_at:e.created_at},r)}function Hr(e){if(e.kind!==cn)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 Oa(e,{skipVerification:t}={}){const n=Hr(e);if(n===void 0||e.content==="")return;let r;try{r=JSON.parse(e.content)}catch{return}if(r.id===n.id&&!(!t&&!an(r)))return r}var Ma={};j(Ma,{NOSTR_URI_REGEX:()=>St,parse:()=>qa,test:()=>Ha});var St=new RegExp(`nostr:(${Lr.source})`);function Ha(e){return typeof e=="string"&&new RegExp(`^${St.source}$`).test(e)}function qa(e){const t=e.match(new RegExp(`^${St.source}$`));if(!t)throw new Error(`Invalid Nostr URI: ${e}`);return{uri:t[0],value:t[1],decoded:bt(t[1])}}var Da={};j(Da,{finishReactionEvent:()=>ja,getReactedEventPointer:()=>za});function ja(e,t,n){const r=t.tags.filter(i=>i.length>=2&&(i[0]==="e"||i[0]==="p"));return le({...e,kind:ln,tags:[...e.tags??[],...r,["e",t.id],["p",t.pubkey]],content:e.content??"+"},n)}function za(e){if(e.kind!==ln)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 Va={};j(Va,{matchAll:()=>Za,regex:()=>dn,replaceAll:()=>Fa});var dn=()=>new RegExp(`\\b${St.source}\\b`,"g");function*Za(e){const t=e.matchAll(dn());for(const n of t)try{const[r,i]=n;yield{uri:r,value:i,decoded:bt(i),start:n.index,end:n.index+r.length}}catch{}}function Fa(e,t){return e.replaceAll(dn(),(n,r)=>t({uri:n,value:r,decoded:bt(r)}))}var Wa={};j(Wa,{channelCreateEvent:()=>Ga,channelHideMessageEvent:()=>Xa,channelMessageEvent:()=>Ya,channelMetadataEvent:()=>Ja,channelMuteUserEvent:()=>Qa});var Ga=(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 le({kind:Kr,tags:[...e.tags??[]],content:n,created_at:e.created_at},t)},Ja=(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 le({kind:Nr,tags:[["e",e.channel_create_event_id],...e.tags??[]],content:n,created_at:e.created_at},t)},Ya=(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"]),le({kind:Cr,tags:[...n,...e.tags??[]],content:e.content,created_at:e.created_at},t)},Xa=(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 le({kind:Br,tags:[["e",e.channel_message_event_id],...e.tags??[]],content:n,created_at:e.created_at},t)},Qa=(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 le({kind:Ir,tags:[["p",e.pubkey_to_mute],...e.tags??[]],content:n,created_at:e.created_at},t)},ec={};j(ec,{EMOJI_SHORTCODE_REGEX:()=>qr,matchAll:()=>tc,regex:()=>yn,replaceAll:()=>nc});var qr=/:(\w+):/,yn=()=>new RegExp(`\\B${qr.source}\\B`,"g");function*tc(e){const t=e.matchAll(yn());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 nc(e,t){return e.replaceAll(yn(),(n,r)=>t({shortcode:n,name:r}))}var rc={};j(rc,{useFetchImplementation:()=>ic,validateGithub:()=>oc});var gn;try{gn=fetch}catch{}function ic(e){gn=e}async function oc(e,t,n){try{return await(await gn(`https://gist.github.com/${t}/${n}/raw`)).text()===`Verifying that I control the following Nostr public key: ${e}`}catch{return!1}}var Z={};j(Z,{decrypt:()=>Wr,encrypt:()=>Fr,getConversationKey:()=>zr,v2:()=>uc});var Dr=1,jr=65535;function zr(e,t){const n=ke.getSharedSecret(e,"02"+t).subarray(1,33);return rn(me,n,"nip44-v2")}function Vr(e,t){const n=br(me,e,t,76);return{chacha_key:n.subarray(0,32),chacha_nonce:n.subarray(32,44),hmac_key:n.subarray(44,76)}}function pn(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 sc(e){if(!Number.isSafeInteger(e)||e<Dr||e>jr)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 ac(e){const t=ee.encode(e),n=t.length,r=sc(n),i=new Uint8Array(pn(n)-n);return ft(r,t,i)}function cc(e){const t=new DataView(e.buffer).getUint16(0),n=e.subarray(2,2+t);if(t<Dr||t>jr||n.length!==t||e.length!==2+pn(t))throw new Error("invalid padding");return ce.decode(n)}function Zr(e,t,n){if(n.length!==32)throw new Error("AAD associated data must be 32 bytes");const r=ft(n,t);return gt(me,e,r)}function lc(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=ye.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 Fr(e,t,n=Fn(32)){const{chacha_key:r,chacha_nonce:i,hmac_key:o}=Vr(t,n),s=ac(e),c=gr(r,i,s),a=Zr(o,c,n);return ye.encode(ft(new Uint8Array([2]),n,c,a))}function Wr(e,t){const{nonce:n,ciphertext:r,mac:i}=lc(e),{chacha_key:o,chacha_nonce:s,hmac_key:c}=Vr(t,n),a=Zr(c,r,n);if(!Eo(a,i))throw new Error("invalid MAC");const l=gr(o,s,r);return cc(l)}var uc={utils:{getConversationKey:zr,calcPaddedLen:pn},encrypt:Fr,decrypt:Wr},fc={};j(fc,{makeNwcRequestEvent:()=>dc,parseConnectionString:()=>hc});function hc(e){const{pathname:t,searchParams:n}=new URL(e),r=t,i=n.get("relay"),o=n.get("secret");if(!r||!i||!o)throw new Error("invalid connection string");return{pubkey:r,relay:i,secret:o}}async function dc(e,t,n){const i=await Tr(t,e,JSON.stringify({method:"pay_invoice",params:{invoice:n}})),o={kind:kr,created_at:Math.round(Date.now()/1e3),content:i,tags:[["p",e]]};return le(o,t)}var yc={};j(yc,{getZapEndpoint:()=>pc,makeZapReceipt:()=>vc,makeZapRequest:()=>wc,useFetchImplementation:()=>gc,validateZapRequest:()=>bc});var wn;try{wn=fetch}catch{}function gc(e){wn=e}async function pc(e){try{let t="",{lud06:n,lud16:r}=JSON.parse(e.content);if(n){let{words:s}=Me.decode(n,1e3),c=Me.fromWords(s);t=ce.decode(c)}else if(r){let[s,c]=r.split("@");t=new URL(`/.well-known/lnurlp/${s}`,`https://${c}`).toString()}else return null;let o=await(await wn(t)).json();if(o.allowsNostr&&o.nostrPubkey)return o.callback}catch{}return null}function wc({profile:e,event:t,amount:n,relays:r,comment:i=""}){if(!n)throw new Error("amount not given");if(!e)throw new Error("profile not given");let o={kind:9734,created_at:Math.round(Date.now()/1e3),content:i,tags:[["p",e],["amount",n.toString()],["relays",...r]]};return t&&o.tags.push(["e",t]),o}function bc(e){let t;try{t=JSON.parse(e)}catch{return"Invalid zap request JSON."}if(!vr(t))return"Zap request is not a valid Nostr event.";if(!an(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 vc({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}var Ec={};j(Ec,{getToken:()=>mc,hashPayload:()=>bn,unpackEventFromToken:()=>Jr,validateEvent:()=>ni,validateEventKind:()=>Xr,validateEventMethodTag:()=>ei,validateEventPayloadTag:()=>ti,validateEventTimestamp:()=>Yr,validateEventUrlTag:()=>Qr,validateToken:()=>xc});var Gr="Nostr ";async function mc(e,t,n,r=!1,i){const o={kind:un,tags:[["u",e],["method",t]],created_at:Math.round(new Date().getTime()/1e3),content:""};i&&o.tags.push(["payload",bn(i)]);const s=await n(o);return(r?Gr:"")+ye.encode(ee.encode(JSON.stringify(s)))}async function xc(e,t,n){const r=await Jr(e).catch(o=>{throw o});return await ni(r,t,n).catch(o=>{throw o})}async function Jr(e){if(!e)throw new Error("Missing token");e=e.replace(Gr,"");const t=ce.decode(ye.decode(e));if(!t||t.length===0||!t.startsWith("{"))throw new Error("Invalid token");return JSON.parse(t)}function Yr(e){return e.created_at?Math.round(new Date().getTime()/1e3)-e.created_at<60:!1}function Xr(e){return e.kind===un}function Qr(e,t){const n=e.tags.find(r=>r[0]==="u");return n?n.length>0&&n[1]===t:!1}function ei(e,t){const n=e.tags.find(r=>r[0]==="method");return n?n.length>0&&n[1].toLowerCase()===t.toLowerCase():!1}function bn(e){const t=me(ee.encode(JSON.stringify(e)));return M(t)}function ti(e,t){const n=e.tags.find(i=>i[0]==="payload");if(!n)return!1;const r=bn(t);return n.length>0&&n[1]===r}async function ni(e,t,n,r){if(!an(e))throw new Error("Invalid nostr event, signature invalid");if(!Xr(e))throw new Error("Invalid nostr event, kind invalid");if(!Yr(e))throw new Error("Invalid nostr event, created_at timestamp invalid");if(!Qr(e,t))throw new Error("Invalid nostr event, url tag invalid");if(!ei(e,n))throw new Error("Invalid nostr event, method tag invalid");if(r&&typeof r=="object"&&Object.keys(r).length>0&&!ti(e,r))throw new Error("Invalid nostr event, payload tag does not match request body hash");return!0}const Le=4,Sc=100;var ri=(e=>(e[e.Us=0]="Us",e[e.Them=1]="Them",e))(ri||{});function Ac(e){return JSON.stringify({rootKey:M(e.rootKey),theirNostrPublicKey:e.theirNostrPublicKey,ourCurrentNostrKey:e.ourCurrentNostrKey?{publicKey:e.ourCurrentNostrKey.publicKey,privateKey:M(e.ourCurrentNostrKey.privateKey)}:void 0,ourNextNostrKey:{publicKey:e.ourNextNostrKey.publicKey,privateKey:M(e.ourNextNostrKey.privateKey)},receivingChainKey:e.receivingChainKey?M(e.receivingChainKey):void 0,sendingChainKey:e.sendingChainKey?M(e.sendingChainKey):void 0,sendingChainMessageNumber:e.sendingChainMessageNumber,receivingChainMessageNumber:e.receivingChainMessageNumber,previousSendingChainMessageCount:e.previousSendingChainMessageCount,skippedMessageKeys:Object.fromEntries(Object.entries(e.skippedMessageKeys).map(([t,n])=>[t,M(n)]))})}function Kc(e){const t=JSON.parse(e);return{rootKey:Y(t.rootKey),theirNostrPublicKey:t.theirNostrPublicKey,ourCurrentNostrKey:t.ourCurrentNostrKey?{publicKey:t.ourCurrentNostrKey.publicKey,privateKey:Y(t.ourCurrentNostrKey.privateKey)}:void 0,ourNextNostrKey:{publicKey:t.ourNextNostrKey.publicKey,privateKey:Y(t.ourNextNostrKey.privateKey)},receivingChainKey:t.receivingChainKey?Y(t.receivingChainKey):void 0,sendingChainKey:t.sendingChainKey?Y(t.sendingChainKey):void 0,sendingChainMessageNumber:t.sendingChainMessageNumber,receivingChainMessageNumber:t.receivingChainMessageNumber,previousSendingChainMessageCount:t.previousSendingChainMessageCount,skippedMessageKeys:Object.fromEntries(Object.entries(t.skippedMessageKeys).map(([n,r])=>[n,Y(r)]))}}async function*Nc(e){const t=[];let n=null;const r=e.onMessage(i=>{n?(n(i),n=null):t.push(i)});try{for(;;)t.length>0?yield t.shift():yield new Promise(i=>{n=i})}finally{r()}}function Te(e,t=new Uint8Array(32),n=1){const r=rn(me,e,t),i=[];for(let o=1;o<=n;o++)i.push(br(me,r,new Uint8Array([o]),32));return i}function vn(e,t){return`${e}:${t}`}const Cc=1e3;class et{constructor(t,n){re(this,"nostrUnsubscribe");re(this,"nostrNextUnsubscribe");re(this,"internalSubscriptions",new Map);re(this,"currentInternalSubscriptionId",0);re(this,"name");this.nostrSubscribe=t,this.state=n,this.name=Math.random().toString(36).substring(2,6)}static init(t,n,r,i,o,s){const c=De(),[a,l]=Te(o,Z.getConversationKey(c,n),2);let f,u;i?(f={publicKey:_e(r),privateKey:r},u={publicKey:_e(c),privateKey:c}):u={publicKey:_e(r),privateKey:r};const d={rootKey:i?a:o,theirNostrPublicKey:n,ourCurrentNostrKey:f,ourNextNostrKey:u,receivingChainKey:void 0,sendingChainKey:i?l:void 0,sendingChainMessageNumber:0,receivingChainMessageNumber:0,previousSendingChainMessageCount:0,skippedMessageKeys:{}},g=new et(t,d);return s&&(g.name=s),g}send(t){if(!this.state.theirNostrPublicKey||!this.state.ourCurrentNostrKey)throw new Error("we are not the initiator, so we can't send the first message");const[n,r]=this.ratchetEncrypt(t),i=Z.getConversationKey(this.state.ourCurrentNostrKey.privateKey,this.state.theirNostrPublicKey),o=Z.encrypt(JSON.stringify(n),i);return le({content:r,kind:Le,tags:[["header",o]],created_at:Math.floor(Date.now()/1e3)},this.state.ourCurrentNostrKey.privateKey)}onMessage(t){const n=this.currentInternalSubscriptionId++;return this.internalSubscriptions.set(n,t),this.subscribeToNostrEvents(),()=>this.internalSubscriptions.delete(n)}ratchetEncrypt(t){const[n,r]=Te(this.state.sendingChainKey,new Uint8Array([1]),2);return this.state.sendingChainKey=n,[{number:this.state.sendingChainMessageNumber++,nextPublicKey:this.state.ourNextNostrKey.publicKey,time:Date.now(),previousChainLength:this.state.previousSendingChainMessageCount},Z.encrypt(t,r)]}ratchetDecrypt(t,n,r){const i=this.trySkippedMessageKeys(t,n,r);if(i)return i;this.skipMessageKeys(t.number,r);const[o,s]=Te(this.state.receivingChainKey,new Uint8Array([1]),2);this.state.receivingChainKey=o,this.state.receivingChainMessageNumber++;try{return Z.decrypt(n,s)}catch(c){throw console.error(this.name,"Decryption failed:",c,{messageKey:M(s).slice(0,4),receivingChainKey:M(this.state.receivingChainKey).slice(0,4),sendingChainKey:this.state.sendingChainKey&&M(this.state.sendingChainKey).slice(0,4),rootKey:M(this.state.rootKey).slice(0,4)}),c}}ratchetStep(t){this.state.previousSendingChainMessageCount=this.state.sendingChainMessageNumber,this.state.sendingChainMessageNumber=0,this.state.receivingChainMessageNumber=0,this.state.theirNostrPublicKey=t;const n=Z.getConversationKey(this.state.ourNextNostrKey.privateKey,this.state.theirNostrPublicKey),[r,i]=Te(this.state.rootKey,n,2);this.state.receivingChainKey=i,this.state.ourCurrentNostrKey=this.state.ourNextNostrKey;const o=De();this.state.ourNextNostrKey={publicKey:_e(o),privateKey:o};const s=Z.getConversationKey(this.state.ourNextNostrKey.privateKey,this.state.theirNostrPublicKey),[c,a]=Te(r,s,2);this.state.rootKey=c,this.state.sendingChainKey=a}skipMessageKeys(t,n){if(this.state.receivingChainMessageNumber+Cc<t)throw new Error("Too many skipped messages");for(;this.state.receivingChainMessageNumber<t;){const[r,i]=Te(this.state.receivingChainKey,new Uint8Array([1]),2);this.state.receivingChainKey=r;const o=vn(n,this.state.receivingChainMessageNumber);this.state.skippedMessageKeys[o]=i,this.state.receivingChainMessageNumber++}}trySkippedMessageKeys(t,n,r){const i=vn(r,t.number);if(i in this.state.skippedMessageKeys){const o=this.state.skippedMessageKeys[i];return delete this.state.skippedMessageKeys[i],Z.decrypt(n,o)}return null}decryptHeader(t){const n=t.tags[0][1];if(this.state.ourCurrentNostrKey){const i=Z.getConversationKey(this.state.ourCurrentNostrKey.privateKey,t.pubkey);try{return[JSON.parse(Z.decrypt(n,i)),!1]}catch{}}const r=Z.getConversationKey(this.state.ourNextNostrKey.privateKey,t.pubkey);try{return[JSON.parse(Z.decrypt(n,r)),!0]}catch{}throw new Error("Failed to decrypt header with both current and next secrets")}handleNostrEvent(t){var o;const[n,r]=this.decryptHeader(t);this.state.theirNostrPublicKey!==n.nextPublicKey&&(this.state.theirNostrPublicKey=n.nextPublicKey,(o=this.nostrUnsubscribe)==null||o.call(this),this.nostrUnsubscribe=this.nostrNextUnsubscribe,this.nostrNextUnsubscribe=this.nostrSubscribe({authors:[this.state.theirNostrPublicKey],kinds:[Le]},s=>this.handleNostrEvent(s))),r&&(this.skipMessageKeys(n.previousChainLength,t.pubkey),this.ratchetStep(n.nextPublicKey));const i=this.ratchetDecrypt(n,t.content,t.pubkey);this.internalSubscriptions.forEach(s=>s({id:t.id,data:i,pubkey:n.nextPublicKey,time:n.time}))}subscribeToNostrEvents(){if(this.nostrNextUnsubscribe)return;this.nostrNextUnsubscribe=this.nostrSubscribe({authors:[this.state.theirNostrPublicKey],kinds:[Le]},n=>this.handleNostrEvent(n));const t=new Set;for(const n of Object.keys(this.state.skippedMessageKeys)){const[r]=n.split(":");r!==this.state.theirNostrPublicKey&&t.add(r)}t.size>0&&(this.nostrUnsubscribe=this.nostrSubscribe({authors:Array.from(t),kinds:[Le]},n=>this.handleNostrEvent(n)))}}new TextDecoder("utf-8"),new TextEncoder;function At(e,t){const n=ke.getSharedSecret(e,"02"+t).subarray(1,33);return rn(me,n,"nip44-v2")}class tt{constructor(t,n,r,i,o,s,c=[]){this.inviterSessionPublicKey=t,this.linkSecret=n,this.inviter=r,this.inviterSessionPrivateKey=i,this.label=o,this.maxUses=s,this.usedBy=c}static createNew(t,n,r){const i=De(),o=_e(i),s=M(De());return new tt(o,s,t,i,n,r)}static fromUrl(t){const r=new URL(t).hash.slice(1);if(!r)throw new Error("No invite data found in the URL hash.");const i=decodeURIComponent(r);let o;try{o=JSON.parse(i)}catch(u){throw new Error("Invite data in URL hash is not valid JSON: "+u)}const{inviter:s,sessionKey:c,linkSecret:a}=o;if(!s||!c||!a)throw new Error("Missing required fields (inviter, sessionKey, linkSecret) in invite data.");const l=Xe.decode(s),f=Xe.decode(c);if(typeof l.data!="string")throw new Error("Decoded inviter is not a string");if(typeof f.data!="string")throw new Error("Decoded session key is not a string");return new tt(f.data,a,l.data)}static deserialize(t){const n=JSON.parse(t);return new tt(n.inviterSessionPublicKey,n.linkSecret,n.inviter,n.inviterSessionPrivateKey?new Uint8Array(n.inviterSessionPrivateKey):void 0,n.label,n.maxUses,n.usedBy)}serialize(){return JSON.stringify({inviterSessionPublicKey:this.inviterSessionPublicKey,linkSecret:this.linkSecret,inviter:this.inviter,inviterSessionPrivateKey:this.inviterSessionPrivateKey?Array.from(this.inviterSessionPrivateKey):void 0,label:this.label,maxUses:this.maxUses,usedBy:this.usedBy})}getUrl(t="https://iris.to"){const n={inviter:Xe.npubEncode(this.inviter),sessionKey:Xe.npubEncode(this.inviterSessionPublicKey),linkSecret:this.linkSecret},r=new URL(t);return r.hash=encodeURIComponent(JSON.stringify(n)),console.log("url",r.toString()),r.toString()}async acceptInvite(t,n,r){const i=De(),o=_e(i),s=this.inviter||this.inviterSessionPublicKey,c=Y(this.linkSecret),a=et.init(t,this.inviterSessionPublicKey,i,!0,c,void 0),l=De(),f=_e(l),u=typeof r=="function"?r:(p,h)=>Promise.resolve(Z.encrypt(p,At(r,h))),d={pubkey:n,tags:[["secret",this.linkSecret]],content:await u(o,s),created_at:Math.floor(Date.now()/1e3)},g={kind:Le,pubkey:f,content:Z.encrypt(JSON.stringify(d),At(l,this.inviterSessionPublicKey)),created_at:Math.floor(Date.now()/1e3),tags:[["p",this.inviterSessionPublicKey]]};return{channel:a,event:le(g,l)}}listen(t,n,r){if(!this.inviterSessionPrivateKey)throw new Error("Inviter session key is not available");const i={kinds:[Le],"#p":[this.inviterSessionPublicKey]};return n(i,async o=>{try{const s=await Z.decrypt(o.content,At(this.inviterSessionPrivateKey,o.pubkey)),c=JSON.parse(s);if(!c.tags||!c.tags.some(([g,p])=>g==="secret"&&p===this.linkSecret)){console.error("Invalid secret from event",o);return}const l=await(typeof t=="function"?t:(g,p)=>Promise.resolve(Z.decrypt(g,At(t,p))))(c.content,c.pubkey),f=Y(this.linkSecret),u=o.id,d=et.init(n,l,this.inviterSessionPrivateKey,!1,f,u);r(d,c.pubkey)}catch(s){console.error("Error processing invite message:",s)}})}}q.Channel=et,q.EVENT_KIND=Le,q.InviteLink=tt,q.MAX_SKIP=Sc,q.Sender=ri,q.createMessageStream=Nc,q.deserializeChannelState=Kc,q.kdf=Te,q.serializeChannelState=Ac,q.skippedMessageIndexKey=vn,Object.defineProperty(q,Symbol.toStringTag,{value:"Module"})});
1
+ (function(H,J){typeof exports=="object"&&typeof module<"u"?J(exports):typeof define=="function"&&define.amd?define(["exports"],J):(H=typeof globalThis<"u"?globalThis:H||self,J(H["nostr-double-ratchet"]={}))})(this,function(H){"use strict";var Bc=Object.defineProperty;var Ic=(H,J,Ce)=>J in H?Bc(H,J,{enumerable:!0,configurable:!0,writable:!0,value:Ce}):H[J]=Ce;var re=(H,J,Ce)=>Ic(H,typeof J!="symbol"?J+"":J,Ce);function J(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`Wrong positive integer: ${e}`)}function Ce(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 ci(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");J(e.outputLen),J(e.blockLen)}function rt(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 li(e,t){Ce(e);const n=t.outputLen;if(e.length<n)throw new Error(`digestInto() expects output buffer of length at least ${n}`)}const Ct=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */const xn=e=>e instanceof Uint8Array,kt=e=>new DataView(e.buffer,e.byteOffset,e.byteLength),ie=(e,t)=>e<<32-t|e>>>t;if(!(new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68))throw new Error("Non little-endian hardware is not supported");function ui(e){if(typeof e!="string")throw new Error(`utf8ToBytes expected string, got ${typeof e}`);return new Uint8Array(new TextEncoder().encode(e))}function Bt(e){if(typeof e=="string"&&(e=ui(e)),!xn(e))throw new Error(`expected Uint8Array, got ${typeof e}`);return e}function fi(...e){const t=new Uint8Array(e.reduce((r,i)=>r+i.length,0));let n=0;return e.forEach(r=>{if(!xn(r))throw new Error("Uint8Array expected");t.set(r,n),n+=r.length}),t}let Sn=class{clone(){return this._cloneInto()}};function hi(e){const t=r=>e().update(Bt(r)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function An(e=32){if(Ct&&typeof Ct.getRandomValues=="function")return Ct.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),a=Number(n&o),c=r?4:0,l=r?0:4;e.setUint32(t+c,s,r),e.setUint32(t+l,a,r)}let yi=class extends Sn{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=kt(this.buffer)}update(t){rt(this);const{view:n,buffer:r,blockLen:i}=this;t=Bt(t);const o=t.length;for(let s=0;s<o;){const a=Math.min(i-this.pos,o-s);if(a===i){const c=kt(t);for(;i<=o-s;s+=i)this.process(c,s);continue}r.set(t.subarray(s,s+a),this.pos),this.pos+=a,s+=a,this.pos===i&&(this.process(n,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){rt(this),li(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 a=kt(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const l=c/4,f=this.get();if(l>f.length)throw new Error("_sha2: outputLen bigger than state");for(let u=0;u<l;u++)a.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:a}=this;return t.length=i,t.pos=a,t.finished=o,t.destroyed=s,i%n&&t.buffer.set(r),t}};const pi=(e,t,n)=>e&t^~e&n,gi=(e,t,n)=>e&t^e&n^t&n,wi=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]),ge=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),we=new Uint32Array(64);let bi=class extends yi{constructor(){super(64,32,8,!1),this.A=ge[0]|0,this.B=ge[1]|0,this.C=ge[2]|0,this.D=ge[3]|0,this.E=ge[4]|0,this.F=ge[5]|0,this.G=ge[6]|0,this.H=ge[7]|0}get(){const{A:t,B:n,C:r,D:i,E:o,F:s,G:a,H:c}=this;return[t,n,r,i,o,s,a,c]}set(t,n,r,i,o,s,a,c){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=a|0,this.H=c|0}process(t,n){for(let u=0;u<16;u++,n+=4)we[u]=t.getUint32(n,!1);for(let u=16;u<64;u++){const d=we[u-15],p=we[u-2],g=ie(d,7)^ie(d,18)^d>>>3,h=ie(p,17)^ie(p,19)^p>>>10;we[u]=h+we[u-7]+g+we[u-16]|0}let{A:r,B:i,C:o,D:s,E:a,F:c,G:l,H:f}=this;for(let u=0;u<64;u++){const d=ie(a,6)^ie(a,11)^ie(a,25),p=f+d+pi(a,c,l)+wi[u]+we[u]|0,h=(ie(r,2)^ie(r,13)^ie(r,22))+gi(r,i,o)|0;f=l,l=c,c=a,a=s+p|0,s=o,o=i,i=r,r=p+h|0}r=r+this.A|0,i=i+this.B|0,o=o+this.C|0,s=s+this.D|0,a=a+this.E|0,c=c+this.F|0,l=l+this.G|0,f=f+this.H|0,this.set(r,i,o,s,a,c,l,f)}roundClean(){we.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};const It=hi(()=>new bi);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Kn=BigInt(0),it=BigInt(1),vi=BigInt(2),ot=e=>e instanceof Uint8Array,Ei=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Oe(e){if(!ot(e))throw new Error("Uint8Array expected");let t="";for(let n=0;n<e.length;n++)t+=Ei[e[n]];return t}function Nn(e){const t=e.toString(16);return t.length&1?`0${t}`:t}function Ut(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return BigInt(e===""?"0":`0x${e}`)}function Me(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 Y(e){return Ut(Oe(e))}function _t(e){if(!ot(e))throw new Error("Uint8Array expected");return Ut(Oe(Uint8Array.from(e).reverse()))}function be(e,t){return Me(e.toString(16).padStart(t*2,"0"))}function Lt(e,t){return be(e,t).reverse()}function mi(e){return Me(Nn(e))}function F(e,t,n){let r;if(typeof t=="string")try{r=Me(t)}catch(o){throw new Error(`${e} must be valid hex string, got "${t}". Cause: ${o}`)}else if(ot(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 ke(...e){const t=new Uint8Array(e.reduce((r,i)=>r+i.length,0));let n=0;return e.forEach(r=>{if(!ot(r))throw new Error("Uint8Array expected");t.set(r,n),n+=r.length}),t}function xi(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 Si(e){if(typeof e!="string")throw new Error(`utf8ToBytes expected string, got ${typeof e}`);return new Uint8Array(new TextEncoder().encode(e))}function Ai(e){let t;for(t=0;e>Kn;e>>=it,t+=1);return t}function Ki(e,t){return e>>BigInt(t)&it}const Ni=(e,t,n)=>e|(n?it:Kn)<<BigInt(t),Tt=e=>(vi<<BigInt(e-1))-it,$t=e=>new Uint8Array(e),Cn=e=>Uint8Array.from(e);function kn(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},a=(...u)=>n(i,r,...u),c=(u=$t())=>{i=a(Cn([0]),u),r=a(),u.length!==0&&(i=a(Cn([1]),u),r=a())},l=()=>{if(o++>=1e3)throw new Error("drbg: tried 1000 values");let u=0;const d=[];for(;u<t;){r=a();const p=r.slice();d.push(p),u+=r.length}return ke(...d)};return(u,d)=>{s(),c(u);let p;for(;!(p=d(l()));)c();return s(),p}}const Ci={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 We(e,t,n={}){const r=(i,o,s)=>{const a=Ci[o];if(typeof a!="function")throw new Error(`Invalid validator "${o}", expected function`);const c=e[i];if(!(s&&c===void 0)&&!a(c,e))throw new Error(`Invalid param ${String(i)}=${c} (${typeof c}), 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 ki=Object.freeze(Object.defineProperty({__proto__:null,bitGet:Ki,bitLen:Ai,bitMask:Tt,bitSet:Ni,bytesToHex:Oe,bytesToNumberBE:Y,bytesToNumberLE:_t,concatBytes:ke,createHmacDrbg:kn,ensureBytes:F,equalBytes:xi,hexToBytes:Me,hexToNumber:Ut,numberToBytesBE:be,numberToBytesLE:Lt,numberToHexUnpadded:Nn,numberToVarBytesBE:mi,utf8ToBytes:Si,validateObject:We},Symbol.toStringTag,{value:"Module"}));/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const z=BigInt(0),D=BigInt(1),Be=BigInt(2),Bi=BigInt(3),Rt=BigInt(4),Bn=BigInt(5),In=BigInt(8);BigInt(9),BigInt(16);function Z(e,t){const n=e%t;return n>=z?n:t+n}function Ii(e,t,n){if(n<=z||t<z)throw new Error("Expected power/modulo > 0");if(n===D)return z;let r=D;for(;t>z;)t&D&&(r=r*e%n),e=e*e%n,t>>=D;return r}function X(e,t,n){let r=e;for(;t-- >z;)r*=r,r%=n;return r}function Ot(e,t){if(e===z||t<=z)throw new Error(`invert: expected positive integers, got n=${e} mod=${t}`);let n=Z(e,t),r=t,i=z,o=D;for(;n!==z;){const a=r/n,c=r%n,l=i-o*a;r=n,n=c,i=o,o=l}if(r!==D)throw new Error("invert: does not exist");return Z(i,t)}function Ui(e){const t=(e-D)/Be;let n,r,i;for(n=e-D,r=0;n%Be===z;n/=Be,r++);for(i=Be;i<e&&Ii(i,t,e)!==e-D;i++);if(r===1){const s=(e+D)/Rt;return function(c,l){const f=c.pow(l,s);if(!c.eql(c.sqr(f),l))throw new Error("Cannot find square root");return f}}const o=(n+D)/Be;return function(a,c){if(a.pow(c,t)===a.neg(a.ONE))throw new Error("Cannot find square root");let l=r,f=a.pow(a.mul(a.ONE,i),n),u=a.pow(c,o),d=a.pow(c,n);for(;!a.eql(d,a.ONE);){if(a.eql(d,a.ZERO))return a.ZERO;let p=1;for(let h=a.sqr(d);p<l&&!a.eql(h,a.ONE);p++)h=a.sqr(h);const g=a.pow(f,D<<BigInt(l-p-1));f=a.sqr(g),u=a.mul(u,g),d=a.mul(d,f),l=p}return u}}function _i(e){if(e%Rt===Bi){const t=(e+D)/Rt;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%In===Bn){const t=(e-Bn)/In;return function(r,i){const o=r.mul(i,Be),s=r.pow(o,t),a=r.mul(i,s),c=r.mul(r.mul(a,Be),s),l=r.mul(a,r.sub(c,r.ONE));if(!r.eql(r.sqr(l),i))throw new Error("Cannot find square root");return l}}return Ui(e)}const Li=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Ti(e){const t={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},n=Li.reduce((r,i)=>(r[i]="function",r),t);return We(e,n)}function $i(e,t,n){if(n<z)throw new Error("Expected power > 0");if(n===z)return e.ONE;if(n===D)return t;let r=e.ONE,i=t;for(;n>z;)n&D&&(r=e.mul(r,i)),i=e.sqr(i),n>>=D;return r}function Ri(e,t){const n=new Array(t.length),r=t.reduce((o,s,a)=>e.is0(s)?o:(n[a]=o,e.mul(o,s)),e.ONE),i=e.inv(r);return t.reduceRight((o,s,a)=>e.is0(s)?o:(n[a]=e.mul(o,n[a]),e.mul(o,s)),i),n}function Un(e,t){const n=t!==void 0?t:e.toString(2).length,r=Math.ceil(n/8);return{nBitLength:n,nByteLength:r}}function Oi(e,t,n=!1,r={}){if(e<=z)throw new Error(`Expected Field ORDER > 0, got ${e}`);const{nBitLength:i,nByteLength:o}=Un(e,t);if(o>2048)throw new Error("Field lengths over 2048 bytes are not supported");const s=_i(e),a=Object.freeze({ORDER:e,BITS:i,BYTES:o,MASK:Tt(i),ZERO:z,ONE:D,create:c=>Z(c,e),isValid:c=>{if(typeof c!="bigint")throw new Error(`Invalid field element: expected bigint, got ${typeof c}`);return z<=c&&c<e},is0:c=>c===z,isOdd:c=>(c&D)===D,neg:c=>Z(-c,e),eql:(c,l)=>c===l,sqr:c=>Z(c*c,e),add:(c,l)=>Z(c+l,e),sub:(c,l)=>Z(c-l,e),mul:(c,l)=>Z(c*l,e),pow:(c,l)=>$i(a,c,l),div:(c,l)=>Z(c*Ot(l,e),e),sqrN:c=>c*c,addN:(c,l)=>c+l,subN:(c,l)=>c-l,mulN:(c,l)=>c*l,inv:c=>Ot(c,e),sqrt:r.sqrt||(c=>s(a,c)),invertBatch:c=>Ri(a,c),cmov:(c,l,f)=>f?l:c,toBytes:c=>n?Lt(c,o):be(c,o),fromBytes:c=>{if(c.length!==o)throw new Error(`Fp.fromBytes: expected ${o}, got ${c.length}`);return n?_t(c):Y(c)}});return Object.freeze(a)}function _n(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 Ln(e){const t=_n(e);return t+Math.ceil(t/2)}function Mi(e,t,n=!1){const r=e.length,i=_n(t),o=Ln(t);if(r<16||r<o||r>1024)throw new Error(`expected ${o}-1024 bytes of input, got ${r}`);const s=n?Y(e):_t(e),a=Z(s,t-D)+D;return n?Lt(a,i):be(a,i)}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Pi=BigInt(0),Mt=BigInt(1);function Hi(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,a=i;for(;o>Pi;)o&Mt&&(s=s.add(a)),a=a.double(),o>>=Mt;return s},precomputeWindow(i,o){const{windows:s,windowSize:a}=r(o),c=[];let l=i,f=l;for(let u=0;u<s;u++){f=l,c.push(f);for(let d=1;d<a;d++)f=f.add(l),c.push(f);l=f.double()}return c},wNAF(i,o,s){const{windows:a,windowSize:c}=r(i);let l=e.ZERO,f=e.BASE;const u=BigInt(2**i-1),d=2**i,p=BigInt(i);for(let g=0;g<a;g++){const h=g*c;let y=Number(s&u);s>>=p,y>c&&(y-=d,s+=Mt);const w=h,m=h+Math.abs(y)-1,K=g%2!==0,U=y<0;y===0?f=f.add(n(K,o[w])):l=l.add(n(U,o[m]))}return{p:l,f}},wNAFCached(i,o,s,a){const c=i._WINDOW_SIZE||1;let l=o.get(i);return l||(l=this.precomputeWindow(i,c),c!==1&&o.set(i,a(l))),this.wNAF(c,l,s)}}}function Tn(e){return Ti(e.Fp),We(e,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...Un(e.n,e.nBitLength),...e,p:e.Fp.ORDER})}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function qi(e){const t=Tn(e);We(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:Di,hexToBytes:ji}=ki,Ie={Err:class extends Error{constructor(t=""){super(t)}},_parseInt(e){const{Err:t}=Ie;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:Di(r),l:e.subarray(n+2)}},toSig(e){const{Err:t}=Ie,n=typeof e=="string"?ji(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}=Ie._parseInt(n.subarray(2)),{d:s,l:a}=Ie._parseInt(o);if(a.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,a=n(o),c=n(s);return`30${n(s+o+4)}02${c}${i}02${a}${r}`}},ue=BigInt(0),Q=BigInt(1);BigInt(2);const $n=BigInt(3);BigInt(4);function Vi(e){const t=qi(e),{Fp:n}=t,r=t.toBytes||((g,h,y)=>{const w=h.toAffine();return ke(Uint8Array.from([4]),n.toBytes(w.x),n.toBytes(w.y))}),i=t.fromBytes||(g=>{const h=g.subarray(1),y=n.fromBytes(h.subarray(0,n.BYTES)),w=n.fromBytes(h.subarray(n.BYTES,2*n.BYTES));return{x:y,y:w}});function o(g){const{a:h,b:y}=t,w=n.sqr(g),m=n.mul(w,g);return n.add(n.add(m,n.mul(g,h)),y)}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"&&ue<g&&g<t.n}function a(g){if(!s(g))throw new Error("Expected valid bigint: 0 < bigint < curve.n")}function c(g){const{allowedPrivateKeyLengths:h,nByteLength:y,wrapPrivateKey:w,n:m}=t;if(h&&typeof g!="bigint"){if(g instanceof Uint8Array&&(g=Oe(g)),typeof g!="string"||!h.includes(g.length))throw new Error("Invalid key");g=g.padStart(y*2,"0")}let K;try{K=typeof g=="bigint"?g:Y(F("private key",g,y))}catch{throw new Error(`private key must be ${y} bytes, hex or bigint, not ${typeof g}`)}return w&&(K=Z(K,m)),a(K),K}const l=new Map;function f(g){if(!(g instanceof u))throw new Error("ProjectivePoint expected")}class u{constructor(h,y,w){if(this.px=h,this.py=y,this.pz=w,h==null||!n.isValid(h))throw new Error("x required");if(y==null||!n.isValid(y))throw new Error("y required");if(w==null||!n.isValid(w))throw new Error("z required")}static fromAffine(h){const{x:y,y:w}=h||{};if(!h||!n.isValid(y)||!n.isValid(w))throw new Error("invalid affine point");if(h instanceof u)throw new Error("projective point not allowed");const m=K=>n.eql(K,n.ZERO);return m(y)&&m(w)?u.ZERO:new u(y,w,n.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(h){const y=n.invertBatch(h.map(w=>w.pz));return h.map((w,m)=>w.toAffine(y[m])).map(u.fromAffine)}static fromHex(h){const y=u.fromAffine(i(F("pointHex",h)));return y.assertValidity(),y}static fromPrivateKey(h){return u.BASE.multiply(c(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}=this.toAffine();if(!n.isValid(h)||!n.isValid(y))throw new Error("bad point: x or y not FE");const w=n.sqr(y),m=o(h);if(!n.eql(w,m))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:y,py:w,pz:m}=this,{px:K,py:U,pz:k}=h,E=n.eql(n.mul(y,k),n.mul(K,m)),x=n.eql(n.mul(w,k),n.mul(U,m));return E&&x}negate(){return new u(this.px,n.neg(this.py),this.pz)}double(){const{a:h,b:y}=t,w=n.mul(y,$n),{px:m,py:K,pz:U}=this;let k=n.ZERO,E=n.ZERO,x=n.ZERO,S=n.mul(m,m),P=n.mul(K,K),I=n.mul(U,U),N=n.mul(m,K);return N=n.add(N,N),x=n.mul(m,U),x=n.add(x,x),k=n.mul(h,x),E=n.mul(w,I),E=n.add(k,E),k=n.sub(P,E),E=n.add(P,E),E=n.mul(k,E),k=n.mul(N,k),x=n.mul(w,x),I=n.mul(h,I),N=n.sub(S,I),N=n.mul(h,N),N=n.add(N,x),x=n.add(S,S),S=n.add(x,S),S=n.add(S,I),S=n.mul(S,N),E=n.add(E,S),I=n.mul(K,U),I=n.add(I,I),S=n.mul(I,N),k=n.sub(k,S),x=n.mul(I,P),x=n.add(x,x),x=n.add(x,x),new u(k,E,x)}add(h){f(h);const{px:y,py:w,pz:m}=this,{px:K,py:U,pz:k}=h;let E=n.ZERO,x=n.ZERO,S=n.ZERO;const P=t.a,I=n.mul(t.b,$n);let N=n.mul(y,K),$=n.mul(w,U),R=n.mul(m,k),q=n.add(y,w),b=n.add(K,U);q=n.mul(q,b),b=n.add(N,$),q=n.sub(q,b),b=n.add(y,m);let v=n.add(K,k);return b=n.mul(b,v),v=n.add(N,R),b=n.sub(b,v),v=n.add(w,m),E=n.add(U,k),v=n.mul(v,E),E=n.add($,R),v=n.sub(v,E),S=n.mul(P,b),E=n.mul(I,R),S=n.add(E,S),E=n.sub($,S),S=n.add($,S),x=n.mul(E,S),$=n.add(N,N),$=n.add($,N),R=n.mul(P,R),b=n.mul(I,b),$=n.add($,R),R=n.sub(N,R),R=n.mul(P,R),b=n.add(b,R),N=n.mul($,b),x=n.add(x,N),N=n.mul(v,b),E=n.mul(q,E),E=n.sub(E,N),N=n.mul(q,$),S=n.mul(v,S),S=n.add(S,N),new u(E,x,S)}subtract(h){return this.add(h.negate())}is0(){return this.equals(u.ZERO)}wNAF(h){return p.wNAFCached(this,l,h,y=>{const w=n.invertBatch(y.map(m=>m.pz));return y.map((m,K)=>m.toAffine(w[K])).map(u.fromAffine)})}multiplyUnsafe(h){const y=u.ZERO;if(h===ue)return y;if(a(h),h===Q)return this;const{endo:w}=t;if(!w)return p.unsafeLadder(this,h);let{k1neg:m,k1:K,k2neg:U,k2:k}=w.splitScalar(h),E=y,x=y,S=this;for(;K>ue||k>ue;)K&Q&&(E=E.add(S)),k&Q&&(x=x.add(S)),S=S.double(),K>>=Q,k>>=Q;return m&&(E=E.negate()),U&&(x=x.negate()),x=new u(n.mul(x.px,w.beta),x.py,x.pz),E.add(x)}multiply(h){a(h);let y=h,w,m;const{endo:K}=t;if(K){const{k1neg:U,k1:k,k2neg:E,k2:x}=K.splitScalar(y);let{p:S,f:P}=this.wNAF(k),{p:I,f:N}=this.wNAF(x);S=p.constTimeNegate(U,S),I=p.constTimeNegate(E,I),I=new u(n.mul(I.px,K.beta),I.py,I.pz),w=S.add(I),m=P.add(N)}else{const{p:U,f:k}=this.wNAF(y);w=U,m=k}return u.normalizeZ([w,m])[0]}multiplyAndAddUnsafe(h,y,w){const m=u.BASE,K=(k,E)=>E===ue||E===Q||!k.equals(m)?k.multiplyUnsafe(E):k.multiply(E),U=K(this,y).add(K(h,w));return U.is0()?void 0:U}toAffine(h){const{px:y,py:w,pz:m}=this,K=this.is0();h==null&&(h=K?n.ONE:n.inv(m));const U=n.mul(y,h),k=n.mul(w,h),E=n.mul(m,h);if(K)return{x:n.ZERO,y:n.ZERO};if(!n.eql(E,n.ONE))throw new Error("invZ was invalid");return{x:U,y:k}}isTorsionFree(){const{h,isTorsionFree:y}=t;if(h===Q)return!0;if(y)return y(u,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){const{h,clearCofactor:y}=t;return h===Q?this:y?y(u,this):this.multiplyUnsafe(t.h)}toRawBytes(h=!0){return this.assertValidity(),r(u,this,h)}toHex(h=!0){return Oe(this.toRawBytes(h))}}u.BASE=new u(t.Gx,t.Gy,n.ONE),u.ZERO=new u(n.ZERO,n.ONE,n.ZERO);const d=t.nBitLength,p=Hi(u,t.endo?Math.ceil(d/2):d);return{CURVE:t,ProjectivePoint:u,normPrivateKeyToScalar:c,weierstrassEquation:o,isWithinCurveOrder:s}}function zi(e){const t=Tn(e);return We(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}function Zi(e){const t=zi(e),{Fp:n,n:r}=t,i=n.BYTES+1,o=2*n.BYTES+1;function s(b){return ue<b&&b<n.ORDER}function a(b){return Z(b,r)}function c(b){return Ot(b,r)}const{ProjectivePoint:l,normPrivateKeyToScalar:f,weierstrassEquation:u,isWithinCurveOrder:d}=Vi({...t,toBytes(b,v,A){const B=v.toAffine(),C=n.toBytes(B.x),L=ke;return A?L(Uint8Array.from([v.hasEvenY()?2:3]),C):L(Uint8Array.from([4]),C,n.toBytes(B.y))},fromBytes(b){const v=b.length,A=b[0],B=b.subarray(1);if(v===i&&(A===2||A===3)){const C=Y(B);if(!s(C))throw new Error("Point is not on curve");const L=u(C);let O=n.sqrt(L);const T=(O&Q)===Q;return(A&1)===1!==T&&(O=n.neg(O)),{x:C,y:O}}else if(v===o&&A===4){const C=n.fromBytes(B.subarray(0,n.BYTES)),L=n.fromBytes(B.subarray(n.BYTES,2*n.BYTES));return{x:C,y:L}}else throw new Error(`Point of length ${v} was invalid. Expected ${i} compressed bytes or ${o} uncompressed bytes`)}}),p=b=>Oe(be(b,t.nByteLength));function g(b){const v=r>>Q;return b>v}function h(b){return g(b)?a(-b):b}const y=(b,v,A)=>Y(b.slice(v,A));class w{constructor(v,A,B){this.r=v,this.s=A,this.recovery=B,this.assertValidity()}static fromCompact(v){const A=t.nByteLength;return v=F("compactSignature",v,A*2),new w(y(v,0,A),y(v,A,2*A))}static fromDER(v){const{r:A,s:B}=Ie.toSig(F("DER",v));return new w(A,B)}assertValidity(){if(!d(this.r))throw new Error("r must be 0 < r < CURVE.n");if(!d(this.s))throw new Error("s must be 0 < s < CURVE.n")}addRecoveryBit(v){return new w(this.r,this.s,v)}recoverPublicKey(v){const{r:A,s:B,recovery:C}=this,L=x(F("msgHash",v));if(C==null||![0,1,2,3].includes(C))throw new Error("recovery id invalid");const O=C===2||C===3?A+t.n:A;if(O>=n.ORDER)throw new Error("recovery id 2 or 3 invalid");const T=C&1?"03":"02",te=l.fromHex(T+p(O)),Ke=c(O),Ve=a(-L*Ke),nt=a(B*Ke),Ne=l.BASE.multiplyAndAddUnsafe(te,Ve,nt);if(!Ne)throw new Error("point at infinify");return Ne.assertValidity(),Ne}hasHighS(){return g(this.s)}normalizeS(){return this.hasHighS()?new w(this.r,a(-this.s),this.recovery):this}toDERRawBytes(){return Me(this.toDERHex())}toDERHex(){return Ie.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return Me(this.toCompactHex())}toCompactHex(){return p(this.r)+p(this.s)}}const m={isValidPrivateKey(b){try{return f(b),!0}catch{return!1}},normPrivateKeyToScalar:f,randomPrivateKey:()=>{const b=Ln(t.n);return Mi(t.randomBytes(b),t.n)},precompute(b=8,v=l.BASE){return v._setWindowSize(b),v.multiply(BigInt(3)),v}};function K(b,v=!0){return l.fromPrivateKey(b).toRawBytes(v)}function U(b){const v=b instanceof Uint8Array,A=typeof b=="string",B=(v||A)&&b.length;return v?B===i||B===o:A?B===2*i||B===2*o:b instanceof l}function k(b,v,A=!0){if(U(b))throw new Error("first arg must be private key");if(!U(v))throw new Error("second arg must be public key");return l.fromHex(v).multiply(f(b)).toRawBytes(A)}const E=t.bits2int||function(b){const v=Y(b),A=b.length*8-t.nBitLength;return A>0?v>>BigInt(A):v},x=t.bits2int_modN||function(b){return a(E(b))},S=Tt(t.nBitLength);function P(b){if(typeof b!="bigint")throw new Error("bigint expected");if(!(ue<=b&&b<S))throw new Error(`bigint expected < 2^${t.nBitLength}`);return be(b,t.nByteLength)}function I(b,v,A=N){if(["recovered","canonical"].some(Re=>Re in A))throw new Error("sign() legacy options not supported");const{hash:B,randomBytes:C}=t;let{lowS:L,prehash:O,extraEntropy:T}=A;L==null&&(L=!0),b=F("msgHash",b),O&&(b=F("prehashed msgHash",B(b)));const te=x(b),Ke=f(v),Ve=[P(Ke),P(te)];if(T!=null){const Re=T===!0?C(n.BYTES):T;Ve.push(F("extraEntropy",Re))}const nt=ke(...Ve),Ne=te;function mn(Re){const ze=E(Re);if(!d(ze))return;const oi=c(ze),Ze=l.BASE.multiply(ze).toAffine(),ne=a(Ze.x);if(ne===ue)return;const Fe=a(oi*a(Ne+ne*Ke));if(Fe===ue)return;let si=(Ze.x===ne?0:2)|Number(Ze.y&Q),ai=Fe;return L&&g(Fe)&&(ai=h(Fe),si^=1),new w(ne,ai,si)}return{seed:nt,k2sig:mn}}const N={lowS:t.lowS,prehash:!1},$={lowS:t.lowS,prehash:!1};function R(b,v,A=N){const{seed:B,k2sig:C}=I(b,v,A),L=t;return kn(L.hash.outputLen,L.nByteLength,L.hmac)(B,C)}l.BASE._setWindowSize(8);function q(b,v,A,B=$){var Ze;const C=b;if(v=F("msgHash",v),A=F("publicKey",A),"strict"in B)throw new Error("options.strict was renamed to lowS");const{lowS:L,prehash:O}=B;let T,te;try{if(typeof C=="string"||C instanceof Uint8Array)try{T=w.fromDER(C)}catch(ne){if(!(ne instanceof Ie.Err))throw ne;T=w.fromCompact(C)}else if(typeof C=="object"&&typeof C.r=="bigint"&&typeof C.s=="bigint"){const{r:ne,s:Fe}=C;T=new w(ne,Fe)}else throw new Error("PARSE");te=l.fromHex(A)}catch(ne){if(ne.message==="PARSE")throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(L&&T.hasHighS())return!1;O&&(v=t.hash(v));const{r:Ke,s:Ve}=T,nt=x(v),Ne=c(Ve),mn=a(nt*Ne),Re=a(Ke*Ne),ze=(Ze=l.BASE.multiplyAndAddUnsafe(te,mn,Re))==null?void 0:Ze.toAffine();return ze?a(ze.x)===Ke:!1}return{CURVE:t,getPublicKey:K,getSharedSecret:k,sign:R,verify:q,ProjectivePoint:l,Signature:w,utils:m}}let Rn=class extends Sn{constructor(t,n){super(),this.finished=!1,this.destroyed=!1,ci(t);const r=Bt(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 rt(this),this.iHash.update(t),this}digestInto(t){rt(this),Ce(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:a}=this;return t=t,t.finished=i,t.destroyed=o,t.blockLen=s,t.outputLen=a,t.oHash=n._cloneInto(t.oHash),t.iHash=r._cloneInto(t.iHash),t}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}};const On=(e,t,n)=>new Rn(e,t).update(n).digest();On.create=(e,t)=>new Rn(e,t);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function Fi(e){return{hash:e,hmac:(t,...n)=>On(e,t,fi(...n)),randomBytes:An}}function Wi(e,t){const n=r=>Zi({...e,...Fi(r)});return Object.freeze({...n(t),create:n})}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const st=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),at=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),Mn=BigInt(1),ct=BigInt(2),Pn=(e,t)=>(e+t/ct)/t;function Hn(e){const t=st,n=BigInt(3),r=BigInt(6),i=BigInt(11),o=BigInt(22),s=BigInt(23),a=BigInt(44),c=BigInt(88),l=e*e*e%t,f=l*l*e%t,u=X(f,n,t)*f%t,d=X(u,n,t)*f%t,p=X(d,ct,t)*l%t,g=X(p,i,t)*p%t,h=X(g,o,t)*g%t,y=X(h,a,t)*h%t,w=X(y,c,t)*y%t,m=X(w,a,t)*h%t,K=X(m,n,t)*f%t,U=X(K,s,t)*g%t,k=X(U,r,t)*l%t,E=X(k,ct,t);if(!Pt.eql(Pt.sqr(E),e))throw new Error("Cannot find square root");return E}const Pt=Oi(st,void 0,void 0,{sqrt:Hn}),Ue=Wi({a:BigInt(0),b:BigInt(7),Fp:Pt,n:at,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:e=>{const t=at,n=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),r=-Mn*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),i=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),o=n,s=BigInt("0x100000000000000000000000000000000"),a=Pn(o*e,t),c=Pn(-r*e,t);let l=Z(e-a*n-c*i,t),f=Z(-a*r-c*o,t);const u=l>s,d=f>s;if(u&&(l=t-l),d&&(f=t-f),l>s||f>s)throw new Error("splitScalar: Endomorphism failed, k="+e);return{k1neg:u,k1:l,k2neg:d,k2:f}}}},It),lt=BigInt(0),qn=e=>typeof e=="bigint"&&lt<e&&e<st,Gi=e=>typeof e=="bigint"&&lt<e&&e<at,Dn={};function ut(e,...t){let n=Dn[e];if(n===void 0){const r=It(Uint8Array.from(e,i=>i.charCodeAt(0)));n=ke(r,r),Dn[e]=n}return It(ke(n,...t))}const Ht=e=>e.toRawBytes(!0).slice(1),qt=e=>be(e,32),Dt=e=>Z(e,st),Ge=e=>Z(e,at),jt=Ue.ProjectivePoint,Ji=(e,t,n)=>jt.BASE.multiplyAndAddUnsafe(e,t,n);function Vt(e){let t=Ue.utils.normPrivateKeyToScalar(e),n=jt.fromPrivateKey(t);return{scalar:n.hasEvenY()?t:Ge(-t),bytes:Ht(n)}}function jn(e){if(!qn(e))throw new Error("bad x: need 0 < x < p");const t=Dt(e*e),n=Dt(t*e+BigInt(7));let r=Hn(n);r%ct!==lt&&(r=Dt(-r));const i=new jt(e,r,Mn);return i.assertValidity(),i}function Vn(...e){return Ge(Y(ut("BIP0340/challenge",...e)))}function Yi(e){return Vt(e).bytes}function Xi(e,t,n=An(32)){const r=F("message",e),{bytes:i,scalar:o}=Vt(t),s=F("auxRand",n,32),a=qt(o^Y(ut("BIP0340/aux",s))),c=ut("BIP0340/nonce",a,i,r),l=Ge(Y(c));if(l===lt)throw new Error("sign failed: k is zero");const{bytes:f,scalar:u}=Vt(l),d=Vn(f,i,r),p=new Uint8Array(64);if(p.set(f,0),p.set(qt(Ge(u+d*o)),32),!zn(p,r,i))throw new Error("sign: Invalid signature produced");return p}function zn(e,t,n){const r=F("signature",e,64),i=F("message",t),o=F("publicKey",n,32);try{const s=jn(Y(o)),a=Y(r.subarray(0,32));if(!qn(a))return!1;const c=Y(r.subarray(32,64));if(!Gi(c))return!1;const l=Vn(qt(a),Ht(s),i),f=Ji(s,c,Ge(-l));return!(!f||!f.hasEvenY()||f.toAffine().x!==a)}catch{return!1}}const Je={getPublicKey:Yi,sign:Xi,verify:zn,utils:{randomPrivateKey:Ue.utils.randomPrivateKey,lift_x:jn,pointToBytes:Ht,numberToBytesBE:be,bytesToNumberBE:Y,taggedHash:ut,mod:Z}},zt=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Zt=e=>e instanceof Uint8Array,Ft=e=>new DataView(e.buffer,e.byteOffset,e.byteLength),oe=(e,t)=>e<<32-t|e>>>t;if(!(new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68))throw new Error("Non little-endian hardware is not supported");const Qi=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function M(e){if(!Zt(e))throw new Error("Uint8Array expected");let t="";for(let n=0;n<e.length;n++)t+=Qi[e[n]];return t}function G(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 eo(e){if(typeof e!="string")throw new Error(`utf8ToBytes expected string, got ${typeof e}`);return new Uint8Array(new TextEncoder().encode(e))}function Ye(e){if(typeof e=="string"&&(e=eo(e)),!Zt(e))throw new Error(`expected Uint8Array, got ${typeof e}`);return e}function ft(...e){const t=new Uint8Array(e.reduce((r,i)=>r+i.length,0));let n=0;return e.forEach(r=>{if(!Zt(r))throw new Error("Uint8Array expected");t.set(r,n),n+=r.length}),t}class Zn{clone(){return this._cloneInto()}}function Fn(e){const t=r=>e().update(Ye(r)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function Wn(e=32){if(zt&&typeof zt.getRandomValues=="function")return zt.getRandomValues(new Uint8Array(e));throw new Error("crypto.getRandomValues must be defined")}function Wt(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`Wrong positive integer: ${e}`)}function to(e){if(typeof e!="boolean")throw new Error(`Expected boolean, not ${e}`)}function Gn(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");Wt(e.outputLen),Wt(e.blockLen)}function ro(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 io(e,t){Gn(e);const n=t.outputLen;if(e.length<n)throw new Error(`digestInto() expects output buffer of length at least ${n}`)}const se={number:Wt,bool:to,bytes:Gn,hash:no,exists:ro,output:io};function oo(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),a=Number(n&o),c=r?4:0,l=r?0:4;e.setUint32(t+c,s,r),e.setUint32(t+l,a,r)}class so extends Zn{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=Ft(this.buffer)}update(t){se.exists(this);const{view:n,buffer:r,blockLen:i}=this;t=Ye(t);const o=t.length;for(let s=0;s<o;){const a=Math.min(i-this.pos,o-s);if(a===i){const c=Ft(t);for(;i<=o-s;s+=i)this.process(c,s);continue}r.set(t.subarray(s,s+a),this.pos),this.pos+=a,s+=a,this.pos===i&&(this.process(n,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){se.exists(this),se.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;oo(r,i-8,BigInt(this.length*8),o),this.process(r,0);const a=Ft(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const l=c/4,f=this.get();if(l>f.length)throw new Error("_sha2: outputLen bigger than state");for(let u=0;u<l;u++)a.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:a}=this;return t.length=i,t.pos=a,t.finished=o,t.destroyed=s,i%n&&t.buffer.set(r),t}}const ao=(e,t,n)=>e&t^~e&n,co=(e,t,n)=>e&t^e&n^t&n,lo=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]),ve=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Ee=new Uint32Array(64);class Jn extends so{constructor(){super(64,32,8,!1),this.A=ve[0]|0,this.B=ve[1]|0,this.C=ve[2]|0,this.D=ve[3]|0,this.E=ve[4]|0,this.F=ve[5]|0,this.G=ve[6]|0,this.H=ve[7]|0}get(){const{A:t,B:n,C:r,D:i,E:o,F:s,G:a,H:c}=this;return[t,n,r,i,o,s,a,c]}set(t,n,r,i,o,s,a,c){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=a|0,this.H=c|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 d=Ee[u-15],p=Ee[u-2],g=oe(d,7)^oe(d,18)^d>>>3,h=oe(p,17)^oe(p,19)^p>>>10;Ee[u]=h+Ee[u-7]+g+Ee[u-16]|0}let{A:r,B:i,C:o,D:s,E:a,F:c,G:l,H:f}=this;for(let u=0;u<64;u++){const d=oe(a,6)^oe(a,11)^oe(a,25),p=f+d+ao(a,c,l)+lo[u]+Ee[u]|0,h=(oe(r,2)^oe(r,13)^oe(r,22))+co(r,i,o)|0;f=l,l=c,c=a,a=s+p|0,s=o,o=i,i=r,r=p+h|0}r=r+this.A|0,i=i+this.B|0,o=o+this.C|0,s=s+this.D|0,a=a+this.E|0,c=c+this.F|0,l=l+this.G|0,f=f+this.H|0,this.set(r,i,o,s,a,c,l,f)}roundClean(){Ee.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}}class uo extends Jn{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 me=Fn(()=>new Jn);Fn(()=>new uo);/*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) */function Pe(e){if(!Number.isSafeInteger(e))throw new Error(`Wrong integer: ${e}`)}function fe(...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 he(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(Pe(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 de(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 ht(e,t="="){if(Pe(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 Yn(e){if(typeof e!="function")throw new Error("normalize fn should be function");return{encode:t=>t,decode:t=>e(t)}}function Xn(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(Pe(s),s<0||s>=t)throw new Error(`Wrong integer: ${s}`)});;){let s=0,a=!0;for(let c=r;c<o.length;c++){const l=o[c],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[c]=Math.floor(f/n),!Number.isSafeInteger(o[c])||o[c]*n+s!==f)throw new Error("convertRadix: carry overflow");if(a)o[c]?a=!1:r=c;else continue}if(i.push(s),a)break}for(let s=0;s<e.length-1&&e[s]===0;s++)i.push(0);return i.reverse()}const Qn=(e,t)=>t?Qn(t,e%t):e,dt=(e,t)=>e+(t-Qn(e,t));function Gt(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(dt(t,n)>32)throw new Error(`convertRadix2: carry overflow from=${t} to=${n} carryBits=${dt(t,n)}`);let i=0,o=0;const s=2**n-1,a=[];for(const c of e){if(Pe(c),c>=2**t)throw new Error(`convertRadix2: invalid data word=${c} from=${t}`);if(i=i<<t|c,o+t>32)throw new Error(`convertRadix2: carry overflow pos=${o} from=${t}`);for(o+=t;o>=n;o-=n)a.push((i>>o-n&s)>>>0);i&=2**o-1}if(i=i<<n-o&s,!r&&o>=t)throw new Error("Excess padding");if(!r&&i)throw new Error(`Non-zero padding: ${i}`);return r&&o>0&&a.push(i>>>0),a}function fo(e){return Pe(e),{encode:t=>{if(!(t instanceof Uint8Array))throw new Error("radix.encode input should be Uint8Array");return Xn(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(Xn(t,e,2**8))}}}function xe(e,t=!1){if(Pe(e),e<=0||e>32)throw new Error("radix2: bits should be in (0..32]");if(dt(8,e)>32||dt(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 Gt(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(Gt(n,e,8,t))}}}function er(e){if(typeof e!="function")throw new Error("unsafeWrapper fn should be function");return function(...t){try{return e.apply(null,t)}catch{}}}const ho=fe(xe(4),he("0123456789ABCDEF"),de("")),yo=fe(xe(5),he("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"),ht(5),de(""));fe(xe(5),he("0123456789ABCDEFGHIJKLMNOPQRSTUV"),ht(5),de("")),fe(xe(5),he("0123456789ABCDEFGHJKMNPQRSTVWXYZ"),de(""),Yn(e=>e.toUpperCase().replace(/O/g,"0").replace(/[IL]/g,"1")));const ye=fe(xe(6),he("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),ht(6),de("")),po=fe(xe(6),he("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"),ht(6),de("")),Jt=e=>fe(fo(58),he(e),de("")),Yt=Jt("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");Jt("123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"),Jt("rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz");const tr=[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+=Yt.encode(r).padStart(tr[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=tr.indexOf(r.length),o=Yt.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)}},Xt=fe(he("qpzry9x8gf2tvdw0s3jn54khce6mua7l"),de("")),nr=[996825010,642813549,513874426,1027748829,705979059];function Xe(e){const t=e>>25;let n=(e&33554431)<<5;for(let r=0;r<nr.length;r++)(t>>r&1)===1&&(n^=nr[r]);return n}function rr(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=Xe(i)^s>>5}i=Xe(i);for(let o=0;o<r;o++)i=Xe(i)^e.charCodeAt(o)&31;for(let o of t)i=Xe(i)^o;for(let o=0;o<6;o++)i=Xe(i);return i^=n,Xt.encode(Gt([i%2**30],30,5,!1))}function ir(e){const t=e==="bech32"?1:734539939,n=xe(5),r=n.decode,i=n.encode,o=er(r);function s(f,u,d=90){if(typeof f!="string")throw new Error(`bech32.encode prefix should be string, not ${typeof f}`);if(!Array.isArray(u)||u.length&&typeof u[0]!="number")throw new Error(`bech32.encode words should be array of numbers, not ${typeof u}`);const p=f.length+7+u.length;if(d!==!1&&p>d)throw new TypeError(`Length ${p} exceeds limit ${d}`);return f=f.toLowerCase(),`${f}1${Xt.encode(u)}${rr(f,u,t)}`}function a(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 d=f.toLowerCase();if(f!==d&&f!==f.toUpperCase())throw new Error("String must be lowercase or uppercase");f=d;const p=f.lastIndexOf("1");if(p===0||p===-1)throw new Error('Letter "1" must be present between prefix and data only');const g=f.slice(0,p),h=f.slice(p+1);if(h.length<6)throw new Error("Data must be at least 6 characters long");const y=Xt.decode(h).slice(0,-6),w=rr(g,y,t);if(!h.endsWith(w))throw new Error(`Invalid checksum in ${f}: expected "${w}"`);return{prefix:g,words:y}}const c=er(a);function l(f){const{prefix:u,words:d}=a(f,!1);return{prefix:u,words:d,bytes:r(d)}}return{encode:s,decode:a,decodeToBytes:l,decodeUnsafe:c,fromWords:r,fromWordsUnsafe:o,toWords:i}}const He=ir("bech32");ir("bech32m");const wo={encode:e=>new TextDecoder().decode(e),decode:e=>new TextEncoder().encode(e)},bo=fe(xe(4),he("0123456789abcdef"),de(""),Yn(e=>{if(typeof e!="string"||e.length%2)throw new TypeError(`hex.decode: expected string, got ${typeof e} with length ${e.length}`);return e.toLowerCase()}));`${Object.keys({utf8:wo,hex:bo,base16:ho,base32:yo,base64:ye,base64url:po,base58:Yt,base58xmr:go}).join(", ")}`;function Qt(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`positive integer expected, not ${e}`)}function or(e){if(typeof e!="boolean")throw new Error(`boolean expected, not ${e}`)}function vo(e){return e instanceof Uint8Array||e!=null&&typeof e=="object"&&e.constructor.name==="Uint8Array"}function pe(e,...t){if(!vo(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 W=e=>new Uint32Array(e.buffer,e.byteOffset,Math.floor(e.byteLength/4));if(!(new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68))throw new Error("Non little-endian hardware is not supported");function Eo(e,t){if(t==null||typeof t!="object")throw new Error("options must be defined");return Object.assign(e,t)}function mo(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 xo=(e,t)=>(Object.assign(t,e),t),Se=16,So=283;function en(e){return e<<1^So&-(e>>7)}function qe(e,t){let n=0;for(;t>0;t>>=1)n^=e&-(t&1),e=en(e);return n}const tn=(()=>{let e=new Uint8Array(256);for(let n=0,r=1;n<256;n++,r^=en(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})(),Ao=tn.map((e,t)=>tn.indexOf(t)),Ko=e=>e<<24|e>>>8,nn=e=>e<<8|e>>>24;function sr(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(nn),i=r.map(nn),o=i.map(nn),s=new Uint32Array(256*256),a=new Uint32Array(256*256),c=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],a[u]=i[l]^o[f],c[u]=e[l]<<8|e[f]}return{sbox:e,sbox2:c,T0:n,T1:r,T2:i,T3:o,T01:s,T23:a}}const rn=sr(tn,e=>qe(e,3)<<24|e<<16|e<<8|qe(e,2)),ar=sr(Ao,e=>qe(e,11)<<24|qe(e,13)<<16|qe(e,9)<<8|qe(e,14)),No=(()=>{const e=new Uint8Array(16);for(let t=0,n=1;t<16;t++,n=en(n))e[t]=n;return e})();function cr(e){pe(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}=rn,r=W(e),i=r.length,o=a=>ae(n,a,a,a,a),s=new Uint32Array(t+28);s.set(r);for(let a=i;a<s.length;a++){let c=s[a-1];a%i===0?c=o(Ko(c))^No[a/i-1]:i>6&&a%i===4&&(c=o(c)),s[a]=s[a-i]^c}return s}function Co(e){const t=cr(e),n=t.slice(),r=t.length,{sbox2:i}=rn,{T0:o,T1:s,T2:a,T3:c}=ar;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=ae(i,f,f,f,f);n[l]=o[u&255]^s[u>>>8&255]^a[u>>>16&255]^c[u>>>24]}return n}function Ae(e,t,n,r,i,o){return e[n<<8&65280|r>>>8&255]^t[i>>>8&65280|o>>>24&255]}function ae(e,t,n,r,i){return e[t&255|n&65280]|e[r>>>16&255|i>>>16&65280]<<16}function lr(e,t,n,r,i){const{sbox2:o,T01:s,T23:a}=rn;let c=0;t^=e[c++],n^=e[c++],r^=e[c++],i^=e[c++];const l=e.length/4-2;for(let g=0;g<l;g++){const h=e[c++]^Ae(s,a,t,n,r,i),y=e[c++]^Ae(s,a,n,r,i,t),w=e[c++]^Ae(s,a,r,i,t,n),m=e[c++]^Ae(s,a,i,t,n,r);t=h,n=y,r=w,i=m}const f=e[c++]^ae(o,t,n,r,i),u=e[c++]^ae(o,n,r,i,t),d=e[c++]^ae(o,r,i,t,n),p=e[c++]^ae(o,i,t,n,r);return{s0:f,s1:u,s2:d,s3:p}}function ko(e,t,n,r,i){const{sbox2:o,T01:s,T23:a}=ar;let c=0;t^=e[c++],n^=e[c++],r^=e[c++],i^=e[c++];const l=e.length/4-2;for(let g=0;g<l;g++){const h=e[c++]^Ae(s,a,t,i,r,n),y=e[c++]^Ae(s,a,n,t,i,r),w=e[c++]^Ae(s,a,r,n,t,i),m=e[c++]^Ae(s,a,i,r,n,t);t=h,n=y,r=w,i=m}const f=e[c++]^ae(o,t,i,r,n),u=e[c++]^ae(o,n,t,i,r),d=e[c++]^ae(o,r,n,t,i),p=e[c++]^ae(o,i,r,n,t);return{s0:f,s1:u,s2:d,s3:p}}function ur(e,t){if(!t)return new Uint8Array(e);if(pe(t),t.length<e)throw new Error(`aes: wrong destination length, expected at least ${e}, got: ${t.length}`);return t}function Bo(e){if(pe(e),e.length%Se!==0)throw new Error(`aes/(cbc-ecb).decrypt ciphertext should consist of blocks with size ${Se}`)}function Io(e,t,n){let r=e.length;const i=r%Se;if(!t&&i!==0)throw new Error("aec/(cbc-ecb): unpadded plaintext with disabled padding");const o=W(e);if(t){let c=Se-i;c||(c=Se),r=r+c}const s=ur(r,n),a=W(s);return{b:o,o:a,out:s}}function Uo(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 _o(e){const t=new Uint8Array(16),n=W(t);t.set(e);const r=Se-e.length;for(let i=Se-r;i<Se;i++)t[i]=r;return n}const fr=xo({blockSize:16,nonceLength:16},function(t,n,r={}){pe(t),pe(n,16);const i=!r.disablePadding;return{encrypt:(o,s)=>{const a=cr(t),{b:c,o:l,out:f}=Io(o,i,s),u=W(n);let d=u[0],p=u[1],g=u[2],h=u[3],y=0;for(;y+4<=c.length;)d^=c[y+0],p^=c[y+1],g^=c[y+2],h^=c[y+3],{s0:d,s1:p,s2:g,s3:h}=lr(a,d,p,g,h),l[y++]=d,l[y++]=p,l[y++]=g,l[y++]=h;if(i){const w=_o(o.subarray(y*4));d^=w[0],p^=w[1],g^=w[2],h^=w[3],{s0:d,s1:p,s2:g,s3:h}=lr(a,d,p,g,h),l[y++]=d,l[y++]=p,l[y++]=g,l[y++]=h}return a.fill(0),f},decrypt:(o,s)=>{Bo(o);const a=Co(t),c=W(n),l=ur(o.length,s),f=W(o),u=W(l);let d=c[0],p=c[1],g=c[2],h=c[3];for(let y=0;y+4<=f.length;){const w=d,m=p,K=g,U=h;d=f[y+0],p=f[y+1],g=f[y+2],h=f[y+3];const{s0:k,s1:E,s2:x,s3:S}=ko(a,d,p,g,h);u[y++]=k^w,u[y++]=E^m,u[y++]=x^K,u[y++]=S^U}return a.fill(0),Uo(l,i)}}}),hr=e=>Uint8Array.from(e.split("").map(t=>t.charCodeAt(0))),Lo=hr("expand 16-byte k"),To=hr("expand 32-byte k"),$o=W(Lo),dr=W(To);dr.slice();function _(e,t){return e<<t|e>>>32-t}function on(e){return e.byteOffset%4===0}const yt=64,Ro=16,yr=2**32-1,pr=new Uint32Array;function Oo(e,t,n,r,i,o,s,a){const c=i.length,l=new Uint8Array(yt),f=W(l),u=on(i)&&on(o),d=u?W(i):pr,p=u?W(o):pr;for(let g=0;g<c;s++){if(e(t,n,r,f,s,a),s>=yr)throw new Error("arx: counter overflow");const h=Math.min(yt,c-g);if(u&&h===yt){const y=g/4;if(g%4!==0)throw new Error("arx: invalid block position");for(let w=0,m;w<Ro;w++)m=y+w,p[m]=d[m]^f[w];g+=yt;continue}for(let y=0,w;y<h;y++)w=g+y,o[w]=i[w]^l[y];g+=h}}function Mo(e,t){const{allowShortKeys:n,extendNonceFn:r,counterLength:i,counterRight:o,rounds:s}=Eo({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},t);if(typeof e!="function")throw new Error("core must be a function");return Qt(i),Qt(s),or(o),or(n),(a,c,l,f,u=0)=>{pe(a),pe(c),pe(l);const d=l.length;if(f||(f=new Uint8Array(d)),pe(f),Qt(u),u<0||u>=yr)throw new Error("arx: counter overflow");if(f.length<d)throw new Error(`arx: output (${f.length}) is shorter than data (${d})`);const p=[];let g=a.length,h,y;if(g===32)h=a.slice(),p.push(h),y=dr;else if(g===16&&n)h=new Uint8Array(32),h.set(a),h.set(a,16),y=$o,p.push(h);else throw new Error(`arx: invalid 32-byte key, got length=${g}`);on(c)||(c=c.slice(),p.push(c));const w=W(h);if(r){if(c.length!==24)throw new Error("arx: extended nonce must be 24 bytes");r(y,w,W(c.subarray(0,16)),w),c=c.subarray(16)}const m=16-i;if(m!==c.length)throw new Error(`arx: nonce must be ${m} or 16 bytes`);if(m!==12){const U=new Uint8Array(12);U.set(c,o?0:12-c.length),c=U,p.push(c)}const K=W(c);for(Oo(e,y,w,K,l,f,u,s);p.length>0;)p.pop().fill(0);return f}}function Po(e,t,n,r,i,o=20){let s=e[0],a=e[1],c=e[2],l=e[3],f=t[0],u=t[1],d=t[2],p=t[3],g=t[4],h=t[5],y=t[6],w=t[7],m=i,K=n[0],U=n[1],k=n[2],E=s,x=a,S=c,P=l,I=f,N=u,$=d,R=p,q=g,b=h,v=y,A=w,B=m,C=K,L=U,O=k;for(let te=0;te<o;te+=2)E=E+I|0,B=_(B^E,16),q=q+B|0,I=_(I^q,12),E=E+I|0,B=_(B^E,8),q=q+B|0,I=_(I^q,7),x=x+N|0,C=_(C^x,16),b=b+C|0,N=_(N^b,12),x=x+N|0,C=_(C^x,8),b=b+C|0,N=_(N^b,7),S=S+$|0,L=_(L^S,16),v=v+L|0,$=_($^v,12),S=S+$|0,L=_(L^S,8),v=v+L|0,$=_($^v,7),P=P+R|0,O=_(O^P,16),A=A+O|0,R=_(R^A,12),P=P+R|0,O=_(O^P,8),A=A+O|0,R=_(R^A,7),E=E+N|0,O=_(O^E,16),v=v+O|0,N=_(N^v,12),E=E+N|0,O=_(O^E,8),v=v+O|0,N=_(N^v,7),x=x+$|0,B=_(B^x,16),A=A+B|0,$=_($^A,12),x=x+$|0,B=_(B^x,8),A=A+B|0,$=_($^A,7),S=S+R|0,C=_(C^S,16),q=q+C|0,R=_(R^q,12),S=S+R|0,C=_(C^S,8),q=q+C|0,R=_(R^q,7),P=P+I|0,L=_(L^P,16),b=b+L|0,I=_(I^b,12),P=P+I|0,L=_(L^P,8),b=b+L|0,I=_(I^b,7);let T=0;r[T++]=s+E|0,r[T++]=a+x|0,r[T++]=c+S|0,r[T++]=l+P|0,r[T++]=f+I|0,r[T++]=u+N|0,r[T++]=d+$|0,r[T++]=p+R|0,r[T++]=g+q|0,r[T++]=h+b|0,r[T++]=y+v|0,r[T++]=w+A|0,r[T++]=m+B|0,r[T++]=K+C|0,r[T++]=U+L|0,r[T++]=k+O|0}const gr=Mo(Po,{counterRight:!1,counterLength:4,allowShortKeys:!1});class wr extends Zn{constructor(t,n){super(),this.finished=!1,this.destroyed=!1,se.hash(t);const r=Ye(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 se.exists(this),this.iHash.update(t),this}digestInto(t){se.exists(this),se.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:a}=this;return t=t,t.finished=i,t.destroyed=o,t.blockLen=s,t.outputLen=a,t.oHash=n._cloneInto(t.oHash),t.iHash=r._cloneInto(t.iHash),t}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}const pt=(e,t,n)=>new wr(e,t).update(n).digest();pt.create=(e,t)=>new wr(e,t);function sn(e,t,n){return se.hash(e),n===void 0&&(n=new Uint8Array(e.outputLen)),pt(e,Ye(n),Ye(t))}const an=new Uint8Array([0]),br=new Uint8Array;function vr(e,t,n,r=32){if(se.hash(e),se.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=br);const o=new Uint8Array(i*e.outputLen),s=pt.create(e,t),a=s._cloneInto(),c=new Uint8Array(s.outputLen);for(let l=0;l<i;l++)an[0]=l+1,a.update(l===0?br:c).update(n).update(an).digestInto(c),o.set(c,e.outputLen*l),s._cloneInto(a);return s.destroy(),a.destroy(),c.fill(0),an.fill(0),o.slice(0,r)}var Ho=Object.defineProperty,j=(e,t)=>{for(var n in t)Ho(e,n,{get:t[n],enumerable:!0})},De=Symbol("verified"),qo=e=>e instanceof Object;function Er(e){if(!qo(e)||typeof e.kind!="number"||typeof e.content!="string"||typeof e.created_at!="number"||typeof e.pubkey!="string"||!e.pubkey.match(/^[a-f0-9]{64}$/)||!Array.isArray(e.tags))return!1;for(let t=0;t<e.tags.length;t++){let n=e.tags[t];if(!Array.isArray(n))return!1;for(let r=0;r<n.length;r++)if(typeof n[r]=="object")return!1}return!0}var Do={};j(Do,{Queue:()=>Zo,QueueNode:()=>mr,binarySearch:()=>cn,insertEventIntoAscendingList:()=>zo,insertEventIntoDescendingList:()=>Vo,normalizeURL:()=>jo,utf8Decoder:()=>ce,utf8Encoder:()=>ee});var ce=new TextDecoder("utf-8"),ee=new TextEncoder;function jo(e){e.indexOf("://")===-1&&(e="wss://"+e);let t=new URL(e);return t.pathname=t.pathname.replace(/\/+/g,"/"),t.pathname.endsWith("/")&&(t.pathname=t.pathname.slice(0,-1)),(t.port==="80"&&t.protocol==="ws:"||t.port==="443"&&t.protocol==="wss:")&&(t.port=""),t.searchParams.sort(),t.hash="",t.toString()}function Vo(e,t){const[n,r]=cn(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 zo(e,t){const[n,r]=cn(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 cn(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 mr=class{constructor(e){re(this,"value");re(this,"next",null);re(this,"prev",null);this.value=e}},Zo=class{constructor(){re(this,"first");re(this,"last");this.first=null,this.last=null}enqueue(e){const t=new mr(e);return this.last?this.last===this.first?(this.last=t,this.last.prev=this.first,this.first.next=t):(t.prev=this.last,this.last.next=t,this.last=t):(this.first=t,this.last=t),!0}dequeue(){if(!this.first)return null;if(this.first===this.last){const t=this.first;return this.first=null,this.last=null,t.value}const e=this.first;return this.first=e.next,e.value}},Fo=class{generateSecretKey(){return Je.utils.randomPrivateKey()}getPublicKey(e){return M(Je.getPublicKey(e))}finalizeEvent(e,t){const n=e;return n.pubkey=M(Je.getPublicKey(t)),n.id=gt(n),n.sig=M(Je.sign(gt(n),t)),n[De]=!0,n}verifyEvent(e){if(typeof e[De]=="boolean")return e[De];const t=gt(e);if(t!==e.id)return e[De]=!1,!1;try{const n=Je.verify(e.sig,t,e.pubkey);return e[De]=n,n}catch{return e[De]=!1,!1}}};function Wo(e){if(!Er(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 gt(e){let t=me(ee.encode(Wo(e)));return M(t)}var wt=new Fo,je=wt.generateSecretKey,_e=wt.getPublicKey,le=wt.finalizeEvent,bt=wt.verifyEvent,Go={};j(Go,{Application:()=>Gs,BadgeAward:()=>is,BadgeDefinition:()=>Ds,BlockedRelaysList:()=>Cs,BookmarkList:()=>As,Bookmarksets:()=>Ps,Calendar:()=>na,CalendarEventRSVP:()=>ra,ChannelCreation:()=>Nr,ChannelHideMessage:()=>Br,ChannelMessage:()=>kr,ChannelMetadata:()=>Cr,ChannelMuteUser:()=>Ir,ClassifiedListing:()=>Xs,ClientAuth:()=>Ur,CommunitiesList:()=>Ks,CommunityDefinition:()=>sa,CommunityPostApproval:()=>ds,Contacts:()=>es,CreateOrUpdateProduct:()=>zs,CreateOrUpdateStall:()=>Vs,Curationsets:()=>Hs,Date:()=>ea,DraftClassifiedListing:()=>Qs,DraftLong:()=>Fs,Emojisets:()=>Ws,EncryptedDirectMessage:()=>ts,EncryptedDirectMessages:()=>ns,EventDeletion:()=>rs,FileMetadata:()=>as,FileServerPreference:()=>Us,Followsets:()=>Rs,GenericRepost:()=>os,Genericlists:()=>Os,HTTPAuth:()=>fn,Handlerinformation:()=>oa,Handlerrecommendation:()=>ia,Highlights:()=>Es,InterestsList:()=>Bs,Interestsets:()=>js,JobFeedback:()=>gs,JobRequest:()=>ys,JobResult:()=>ps,Label:()=>hs,LightningPubRPC:()=>Ls,LiveChatMessage:()=>cs,LiveEvent:()=>Js,LongFormArticle:()=>Zs,Metadata:()=>Yo,Mutelist:()=>ms,NWCWalletInfo:()=>_s,NWCWalletRequest:()=>_r,NWCWalletResponse:()=>Ts,NostrConnect:()=>$s,OpenTimestamps:()=>ss,Pinlist:()=>xs,ProblemTracker:()=>ls,ProfileBadges:()=>qs,PublicChatsList:()=>Ns,Reaction:()=>un,RecommendRelay:()=>Qo,RelayList:()=>Ss,Relaysets:()=>Ms,Report:()=>us,Reporting:()=>fs,Repost:()=>ln,SearchRelaysList:()=>ks,ShortTextNote:()=>Xo,Time:()=>ta,UserEmojiList:()=>Is,UserStatuses:()=>Ys,Zap:()=>vs,ZapGoal:()=>ws,ZapRequest:()=>bs,classifyKind:()=>Jo,isEphemeralKind:()=>Ar,isParameterizedReplaceableKind:()=>Kr,isRegularKind:()=>xr,isReplaceableKind:()=>Sr});function xr(e){return 1e3<=e&&e<1e4||[1,2,4,5,6,7,8,16,40,41,42,43,44].includes(e)}function Sr(e){return[0,3].includes(e)||1e4<=e&&e<2e4}function Ar(e){return 2e4<=e&&e<3e4}function Kr(e){return 3e4<=e&&e<4e4}function Jo(e){return xr(e)?"regular":Sr(e)?"replaceable":Ar(e)?"ephemeral":Kr(e)?"parameterized":"unknown"}var Yo=0,Xo=1,Qo=2,es=3,ts=4,ns=4,rs=5,ln=6,un=7,is=8,os=16,Nr=40,Cr=41,kr=42,Br=43,Ir=44,ss=1040,as=1063,cs=1311,ls=1971,us=1984,fs=1984,hs=1985,ds=4550,ys=5999,ps=6999,gs=7e3,ws=9041,bs=9734,vs=9735,Es=9802,ms=1e4,xs=10001,Ss=10002,As=10003,Ks=10004,Ns=10005,Cs=10006,ks=10007,Bs=10015,Is=10030,Us=10096,_s=13194,Ls=21e3,Ur=22242,_r=23194,Ts=23195,$s=24133,fn=27235,Rs=3e4,Os=30001,Ms=30002,Ps=30003,Hs=30004,qs=30008,Ds=30009,js=30015,Vs=30017,zs=30018,Zs=30023,Fs=30024,Ws=30030,Gs=30078,Js=30311,Ys=30315,Xs=30402,Qs=30403,ea=31922,ta=31923,na=31924,ra=31925,ia=31989,oa=31990,sa=34550,aa={};j(aa,{getHex64:()=>hn,getInt:()=>Lr,getSubscriptionId:()=>ca,matchEventId:()=>la,matchEventKind:()=>fa,matchEventPubkey:()=>ua});function hn(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 Lr(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 ca(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 la(e,t){return t===hn(e,"id")}function ua(e,t){return t===hn(e,"pubkey")}function fa(e,t){return t===Lr(e,"kind")}var ha={};j(ha,{makeAuthEvent:()=>da});function da(e,t){return{kind:Ur,created_at:Math.floor(Date.now()/1e3),tags:[["relay",e],["challenge",t]],content:""}}var ya;try{ya=WebSocket}catch{}var pa;try{pa=WebSocket}catch{}var Qe={};j(Qe,{BECH32_REGEX:()=>Tr,Bech32MaxSize:()=>dn,decode:()=>vt,encodeBytes:()=>mt,naddrEncode:()=>xa,neventEncode:()=>ma,noteEncode:()=>va,nprofileEncode:()=>Ea,npubEncode:()=>ba,nrelayEncode:()=>Sa,nsecEncode:()=>wa});var dn=5e3,Tr=/[\x21-\x7E]{1,83}1[023456789acdefghjklmnpqrstuvwxyz]{6,}/;function ga(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 vt(e){var i,o,s,a,c,l,f,u;let{prefix:t,words:n}=He.decode(e,dn),r=new Uint8Array(He.fromWords(n));switch(t){case"nprofile":{let d=Et(r);if(!((i=d[0])!=null&&i[0]))throw new Error("missing TLV 0 for nprofile");if(d[0][0].length!==32)throw new Error("TLV 0 should be 32 bytes");return{type:"nprofile",data:{pubkey:M(d[0][0]),relays:d[1]?d[1].map(p=>ce.decode(p)):[]}}}case"nevent":{let d=Et(r);if(!((o=d[0])!=null&&o[0]))throw new Error("missing TLV 0 for nevent");if(d[0][0].length!==32)throw new Error("TLV 0 should be 32 bytes");if(d[2]&&d[2][0].length!==32)throw new Error("TLV 2 should be 32 bytes");if(d[3]&&d[3][0].length!==4)throw new Error("TLV 3 should be 4 bytes");return{type:"nevent",data:{id:M(d[0][0]),relays:d[1]?d[1].map(p=>ce.decode(p)):[],author:(s=d[2])!=null&&s[0]?M(d[2][0]):void 0,kind:(a=d[3])!=null&&a[0]?parseInt(M(d[3][0]),16):void 0}}}case"naddr":{let d=Et(r);if(!((c=d[0])!=null&&c[0]))throw new Error("missing TLV 0 for naddr");if(!((l=d[2])!=null&&l[0]))throw new Error("missing TLV 2 for naddr");if(d[2][0].length!==32)throw new Error("TLV 2 should be 32 bytes");if(!((f=d[3])!=null&&f[0]))throw new Error("missing TLV 3 for naddr");if(d[3][0].length!==4)throw new Error("TLV 3 should be 4 bytes");return{type:"naddr",data:{identifier:ce.decode(d[0][0]),pubkey:M(d[2][0]),kind:parseInt(M(d[3][0]),16),relays:d[1]?d[1].map(p=>ce.decode(p)):[]}}}case"nrelay":{let d=Et(r);if(!((u=d[0])!=null&&u[0]))throw new Error("missing TLV 0 for nrelay");return{type:"nrelay",data:ce.decode(d[0][0])}}case"nsec":return{type:t,data:r};case"npub":case"note":return{type:t,data:M(r)};default:throw new Error(`unknown prefix ${t}`)}}function Et(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 wa(e){return mt("nsec",e)}function ba(e){return mt("npub",G(e))}function va(e){return mt("note",G(e))}function et(e,t){let n=He.toWords(t);return He.encode(e,n,dn)}function mt(e,t){return et(e,t)}function Ea(e){let t=xt({0:[G(e.pubkey)],1:(e.relays||[]).map(n=>ee.encode(n))});return et("nprofile",t)}function ma(e){let t;e.kind!==void 0&&(t=ga(e.kind));let n=xt({0:[G(e.id)],1:(e.relays||[]).map(r=>ee.encode(r)),2:e.author?[G(e.author)]:[],3:t?[new Uint8Array(t)]:[]});return et("nevent",n)}function xa(e){let t=new ArrayBuffer(4);new DataView(t).setUint32(0,e.kind,!1);let n=xt({0:[ee.encode(e.identifier)],1:(e.relays||[]).map(r=>ee.encode(r)),2:[G(e.pubkey)],3:[new Uint8Array(t)]});return et("naddr",n)}function Sa(e){let t=xt({0:[ee.encode(e)]});return et("nrelay",t)}function xt(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)})}),ft(...t)}var Aa={};j(Aa,{decrypt:()=>Ka,encrypt:()=>$r});async function $r(e,t,n){const r=e instanceof Uint8Array?M(e):e,i=Ue.getSharedSecret(r,"02"+t),o=Rr(i);let s=Uint8Array.from(Wn(16)),a=ee.encode(n),c=fr(o,s).encrypt(a),l=ye.encode(new Uint8Array(c)),f=ye.encode(new Uint8Array(s.buffer));return`${l}?iv=${f}`}async function Ka(e,t,n){const r=e instanceof Uint8Array?M(e):e;let[i,o]=n.split("?iv="),s=Ue.getSharedSecret(r,"02"+t),a=Rr(s),c=ye.decode(o),l=ye.decode(i),f=fr(a,c).decrypt(l);return ce.decode(f)}function Rr(e){return e.slice(1,33)}var Na={};j(Na,{NIP05_REGEX:()=>Or,isValid:()=>Ba,queryProfile:()=>Mr,searchDomain:()=>ka,useFetchImplementation:()=>Ca});var Or=/^(?:([\w.+-]+)@)?([\w_-]+(\.[\w_-]+)+)$/,St;try{St=fetch}catch{}function Ca(e){St=e}async function ka(e,t=""){try{const n=`https://${e}/.well-known/nostr.json?name=${t}`;return(await(await St(n,{redirect:"error"})).json()).names}catch{return{}}}async function Mr(e){var o;const t=e.match(Or);if(!t)return null;const[n,r="_",i]=t;try{const s=`https://${i}/.well-known/nostr.json?name=${r}`,a=await(await St(s,{redirect:"error"})).json();let c=a.names[r];return c?{pubkey:c,relays:(o=a.relays)==null?void 0:o[c]}:null}catch{return null}}async function Ba(e,t){let n=await Mr(t);return n?n.pubkey===e:!1}var Ia={};j(Ia,{parse:()=>Ua});function Ua(e){const t={reply:void 0,root:void 0,mentions:[],profiles:[]},n=[];for(const r of e.tags)r[0]==="e"&&r[1]&&n.push(r),r[0]==="p"&&r[1]&&t.profiles.push({pubkey:r[1],relays:r[2]?[r[2]]:[]});for(let r=0;r<n.length;r++){const i=n[r],[o,s,a,c]=i,l={id:s,relays:a?[a]:[]},f=r===0,u=r===n.length-1;if(c==="root"){t.root=l;continue}if(c==="reply"){t.reply=l;continue}if(c==="mention"){t.mentions.push(l);continue}if(f){t.root=l;continue}if(u){t.reply=l;continue}t.mentions.push(l)}return t}var _a={};j(_a,{fetchRelayInformation:()=>Ta,useFetchImplementation:()=>La});var Pr;try{Pr=fetch}catch{}function La(e){Pr=e}async function Ta(e){return await(await fetch(e.replace("ws://","http://").replace("wss://","https://"),{headers:{Accept:"application/nostr+json"}})).json()}var $a={};j($a,{getPow:()=>Hr,minePow:()=>Ra});function Hr(e){let t=0;for(let n=0;n<e.length;n++){const r=parseInt(e[n],16);if(r===0)t+=4;else{t+=Math.clz32(r)-28;break}}return t}function Ra(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=gt(r),Hr(r.id)>=t)break}return r}var Oa={};j(Oa,{finishRepostEvent:()=>Ma,getRepostedEvent:()=>Pa,getRepostedEventPointer:()=>qr});function Ma(e,t,n,r){return le({kind:ln,tags:[...e.tags??[],["e",t.id,n],["p",t.pubkey]],content:e.content===""?"":JSON.stringify(t),created_at:e.created_at},r)}function qr(e){if(e.kind!==ln)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 Pa(e,{skipVerification:t}={}){const n=qr(e);if(n===void 0||e.content==="")return;let r;try{r=JSON.parse(e.content)}catch{return}if(r.id===n.id&&!(!t&&!bt(r)))return r}var Ha={};j(Ha,{NOSTR_URI_REGEX:()=>At,parse:()=>Da,test:()=>qa});var At=new RegExp(`nostr:(${Tr.source})`);function qa(e){return typeof e=="string"&&new RegExp(`^${At.source}$`).test(e)}function Da(e){const t=e.match(new RegExp(`^${At.source}$`));if(!t)throw new Error(`Invalid Nostr URI: ${e}`);return{uri:t[0],value:t[1],decoded:vt(t[1])}}var ja={};j(ja,{finishReactionEvent:()=>Va,getReactedEventPointer:()=>za});function Va(e,t,n){const r=t.tags.filter(i=>i.length>=2&&(i[0]==="e"||i[0]==="p"));return le({...e,kind:un,tags:[...e.tags??[],...r,["e",t.id],["p",t.pubkey]],content:e.content??"+"},n)}function za(e){if(e.kind!==un)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 Za={};j(Za,{matchAll:()=>Fa,regex:()=>yn,replaceAll:()=>Wa});var yn=()=>new RegExp(`\\b${At.source}\\b`,"g");function*Fa(e){const t=e.matchAll(yn());for(const n of t)try{const[r,i]=n;yield{uri:r,value:i,decoded:vt(i),start:n.index,end:n.index+r.length}}catch{}}function Wa(e,t){return e.replaceAll(yn(),(n,r)=>t({uri:n,value:r,decoded:vt(r)}))}var Ga={};j(Ga,{channelCreateEvent:()=>Ja,channelHideMessageEvent:()=>Qa,channelMessageEvent:()=>Xa,channelMetadataEvent:()=>Ya,channelMuteUserEvent:()=>ec});var Ja=(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 le({kind:Nr,tags:[...e.tags??[]],content:n,created_at:e.created_at},t)},Ya=(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 le({kind:Cr,tags:[["e",e.channel_create_event_id],...e.tags??[]],content:n,created_at:e.created_at},t)},Xa=(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"]),le({kind:kr,tags:[...n,...e.tags??[]],content:e.content,created_at:e.created_at},t)},Qa=(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 le({kind:Br,tags:[["e",e.channel_message_event_id],...e.tags??[]],content:n,created_at:e.created_at},t)},ec=(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 le({kind:Ir,tags:[["p",e.pubkey_to_mute],...e.tags??[]],content:n,created_at:e.created_at},t)},tc={};j(tc,{EMOJI_SHORTCODE_REGEX:()=>Dr,matchAll:()=>nc,regex:()=>pn,replaceAll:()=>rc});var Dr=/:(\w+):/,pn=()=>new RegExp(`\\B${Dr.source}\\B`,"g");function*nc(e){const t=e.matchAll(pn());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 rc(e,t){return e.replaceAll(pn(),(n,r)=>t({shortcode:n,name:r}))}var ic={};j(ic,{useFetchImplementation:()=>oc,validateGithub:()=>sc});var gn;try{gn=fetch}catch{}function oc(e){gn=e}async function sc(e,t,n){try{return await(await gn(`https://gist.github.com/${t}/${n}/raw`)).text()===`Verifying that I control the following Nostr public key: ${e}`}catch{return!1}}var V={};j(V,{decrypt:()=>Gr,encrypt:()=>Wr,getConversationKey:()=>zr,v2:()=>fc});var jr=1,Vr=65535;function zr(e,t){const n=Ue.getSharedSecret(e,"02"+t).subarray(1,33);return sn(me,n,"nip44-v2")}function Zr(e,t){const n=vr(me,e,t,76);return{chacha_key:n.subarray(0,32),chacha_nonce:n.subarray(32,44),hmac_key:n.subarray(44,76)}}function wn(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 ac(e){if(!Number.isSafeInteger(e)||e<jr||e>Vr)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 cc(e){const t=ee.encode(e),n=t.length,r=ac(n),i=new Uint8Array(wn(n)-n);return ft(r,t,i)}function lc(e){const t=new DataView(e.buffer).getUint16(0),n=e.subarray(2,2+t);if(t<jr||t>Vr||n.length!==t||e.length!==2+wn(t))throw new Error("invalid padding");return ce.decode(n)}function Fr(e,t,n){if(n.length!==32)throw new Error("AAD associated data must be 32 bytes");const r=ft(n,t);return pt(me,e,r)}function uc(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=ye.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 Wr(e,t,n=Wn(32)){const{chacha_key:r,chacha_nonce:i,hmac_key:o}=Zr(t,n),s=cc(e),a=gr(r,i,s),c=Fr(o,a,n);return ye.encode(ft(new Uint8Array([2]),n,a,c))}function Gr(e,t){const{nonce:n,ciphertext:r,mac:i}=uc(e),{chacha_key:o,chacha_nonce:s,hmac_key:a}=Zr(t,n),c=Fr(a,r,n);if(!mo(c,i))throw new Error("invalid MAC");const l=gr(o,s,r);return lc(l)}var fc={utils:{getConversationKey:zr,calcPaddedLen:wn},encrypt:Wr,decrypt:Gr},hc={};j(hc,{makeNwcRequestEvent:()=>yc,parseConnectionString:()=>dc});function dc(e){const{pathname:t,searchParams:n}=new URL(e),r=t,i=n.get("relay"),o=n.get("secret");if(!r||!i||!o)throw new Error("invalid connection string");return{pubkey:r,relay:i,secret:o}}async function yc(e,t,n){const i=await $r(t,e,JSON.stringify({method:"pay_invoice",params:{invoice:n}})),o={kind:_r,created_at:Math.round(Date.now()/1e3),content:i,tags:[["p",e]]};return le(o,t)}var pc={};j(pc,{getZapEndpoint:()=>wc,makeZapReceipt:()=>Ec,makeZapRequest:()=>bc,useFetchImplementation:()=>gc,validateZapRequest:()=>vc});var bn;try{bn=fetch}catch{}function gc(e){bn=e}async function wc(e){try{let t="",{lud06:n,lud16:r}=JSON.parse(e.content);if(n){let{words:s}=He.decode(n,1e3),a=He.fromWords(s);t=ce.decode(a)}else if(r){let[s,a]=r.split("@");t=new URL(`/.well-known/lnurlp/${s}`,`https://${a}`).toString()}else return null;let o=await(await bn(t)).json();if(o.allowsNostr&&o.nostrPubkey)return o.callback}catch{}return null}function bc({profile:e,event:t,amount:n,relays:r,comment:i=""}){if(!n)throw new Error("amount not given");if(!e)throw new Error("profile not given");let o={kind:9734,created_at:Math.round(Date.now()/1e3),content:i,tags:[["p",e],["amount",n.toString()],["relays",...r]]};return t&&o.tags.push(["e",t]),o}function vc(e){let t;try{t=JSON.parse(e)}catch{return"Invalid zap request JSON."}if(!Er(t))return"Zap request is not a valid Nostr event.";if(!bt(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 Ec({zapRequest:e,preimage:t,bolt11:n,paidAt:r}){let i=JSON.parse(e),o=i.tags.filter(([a])=>a==="e"||a==="p"||a==="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}var mc={};j(mc,{getToken:()=>xc,hashPayload:()=>vn,unpackEventFromToken:()=>Yr,validateEvent:()=>ri,validateEventKind:()=>Qr,validateEventMethodTag:()=>ti,validateEventPayloadTag:()=>ni,validateEventTimestamp:()=>Xr,validateEventUrlTag:()=>ei,validateToken:()=>Sc});var Jr="Nostr ";async function xc(e,t,n,r=!1,i){const o={kind:fn,tags:[["u",e],["method",t]],created_at:Math.round(new Date().getTime()/1e3),content:""};i&&o.tags.push(["payload",vn(i)]);const s=await n(o);return(r?Jr:"")+ye.encode(ee.encode(JSON.stringify(s)))}async function Sc(e,t,n){const r=await Yr(e).catch(o=>{throw o});return await ri(r,t,n).catch(o=>{throw o})}async function Yr(e){if(!e)throw new Error("Missing token");e=e.replace(Jr,"");const t=ce.decode(ye.decode(e));if(!t||t.length===0||!t.startsWith("{"))throw new Error("Invalid token");return JSON.parse(t)}function Xr(e){return e.created_at?Math.round(new Date().getTime()/1e3)-e.created_at<60:!1}function Qr(e){return e.kind===fn}function ei(e,t){const n=e.tags.find(r=>r[0]==="u");return n?n.length>0&&n[1]===t:!1}function ti(e,t){const n=e.tags.find(r=>r[0]==="method");return n?n.length>0&&n[1].toLowerCase()===t.toLowerCase():!1}function vn(e){const t=me(ee.encode(JSON.stringify(e)));return M(t)}function ni(e,t){const n=e.tags.find(i=>i[0]==="payload");if(!n)return!1;const r=vn(t);return n.length>0&&n[1]===r}async function ri(e,t,n,r){if(!bt(e))throw new Error("Invalid nostr event, signature invalid");if(!Qr(e))throw new Error("Invalid nostr event, kind invalid");if(!Xr(e))throw new Error("Invalid nostr event, created_at timestamp invalid");if(!ei(e,t))throw new Error("Invalid nostr event, url tag invalid");if(!ti(e,n))throw new Error("Invalid nostr event, method tag invalid");if(r&&typeof r=="object"&&Object.keys(r).length>0&&!ni(e,r))throw new Error("Invalid nostr event, payload tag does not match request body hash");return!0}const Le=4,En=30078,Ac=100;var ii=(e=>(e[e.Us=0]="Us",e[e.Them=1]="Them",e))(ii||{});function Kc(e){return JSON.stringify({rootKey:M(e.rootKey),theirNostrPublicKey:e.theirNostrPublicKey,ourCurrentNostrKey:e.ourCurrentNostrKey?{publicKey:e.ourCurrentNostrKey.publicKey,privateKey:M(e.ourCurrentNostrKey.privateKey)}:void 0,ourNextNostrKey:{publicKey:e.ourNextNostrKey.publicKey,privateKey:M(e.ourNextNostrKey.privateKey)},receivingChainKey:e.receivingChainKey?M(e.receivingChainKey):void 0,sendingChainKey:e.sendingChainKey?M(e.sendingChainKey):void 0,sendingChainMessageNumber:e.sendingChainMessageNumber,receivingChainMessageNumber:e.receivingChainMessageNumber,previousSendingChainMessageCount:e.previousSendingChainMessageCount,skippedMessageKeys:Object.fromEntries(Object.entries(e.skippedMessageKeys).map(([t,n])=>[t,M(n)])),skippedHeaderKeys:Object.fromEntries(Object.entries(e.skippedHeaderKeys).map(([t,n])=>[t,n.map(r=>M(r))]))})}function Nc(e){const t=JSON.parse(e);return{rootKey:G(t.rootKey),theirNostrPublicKey:t.theirNostrPublicKey,ourCurrentNostrKey:t.ourCurrentNostrKey?{publicKey:t.ourCurrentNostrKey.publicKey,privateKey:G(t.ourCurrentNostrKey.privateKey)}:void 0,ourNextNostrKey:{publicKey:t.ourNextNostrKey.publicKey,privateKey:G(t.ourNextNostrKey.privateKey)},receivingChainKey:t.receivingChainKey?G(t.receivingChainKey):void 0,sendingChainKey:t.sendingChainKey?G(t.sendingChainKey):void 0,sendingChainMessageNumber:t.sendingChainMessageNumber,receivingChainMessageNumber:t.receivingChainMessageNumber,previousSendingChainMessageCount:t.previousSendingChainMessageCount,skippedMessageKeys:Object.fromEntries(Object.entries(t.skippedMessageKeys).map(([n,r])=>[n,G(r)])),skippedHeaderKeys:Object.fromEntries(Object.entries(t.skippedHeaderKeys||{}).map(([n,r])=>[n,r.map(i=>G(i))]))}}async function*Cc(e){const t=[];let n=null;const r=e.onMessage(i=>{n?(n(i),n=null):t.push(i)});try{for(;;)t.length>0?yield t.shift():yield new Promise(i=>{n=i})}finally{r()}}function Te(e,t=new Uint8Array(32),n=1){const r=sn(me,e,t),i=[];for(let o=1;o<=n;o++)i.push(vr(me,r,new Uint8Array([o]),32));return i}function Kt(e,t){return`${e}:${t}`}const kc=1e3;class tt{constructor(t,n){re(this,"nostrUnsubscribe");re(this,"nostrNextUnsubscribe");re(this,"internalSubscriptions",new Map);re(this,"currentInternalSubscriptionId",0);re(this,"name");this.nostrSubscribe=t,this.state=n,this.name=Math.random().toString(36).substring(2,6)}static init(t,n,r,i,o,s){const a=je(),[c,l]=Te(o,V.getConversationKey(a,n),2);let f,u;i?(f={publicKey:_e(r),privateKey:r},u={publicKey:_e(a),privateKey:a}):u={publicKey:_e(r),privateKey:r};const d={rootKey:i?c:o,theirNostrPublicKey:n,ourCurrentNostrKey:f,ourNextNostrKey:u,receivingChainKey:void 0,sendingChainKey:i?l:void 0,sendingChainMessageNumber:0,receivingChainMessageNumber:0,previousSendingChainMessageCount:0,skippedMessageKeys:{},skippedHeaderKeys:{}},p=new tt(t,d);return s&&(p.name=s),p}send(t){if(!this.state.theirNostrPublicKey||!this.state.ourCurrentNostrKey)throw new Error("we are not the initiator, so we can't send the first message");const[n,r]=this.ratchetEncrypt(t),i=V.getConversationKey(this.state.ourCurrentNostrKey.privateKey,this.state.theirNostrPublicKey),o=V.encrypt(JSON.stringify(n),i);return le({content:r,kind:Le,tags:[["header",o]],created_at:Math.floor(Date.now()/1e3)},this.state.ourCurrentNostrKey.privateKey)}onMessage(t){const n=this.currentInternalSubscriptionId++;return this.internalSubscriptions.set(n,t),this.subscribeToNostrEvents(),()=>this.internalSubscriptions.delete(n)}close(){var t,n;(t=this.nostrUnsubscribe)==null||t.call(this),(n=this.nostrNextUnsubscribe)==null||n.call(this)}ratchetEncrypt(t){const[n,r]=Te(this.state.sendingChainKey,new Uint8Array([1]),2);return this.state.sendingChainKey=n,[{number:this.state.sendingChainMessageNumber++,nextPublicKey:this.state.ourNextNostrKey.publicKey,time:Date.now(),previousChainLength:this.state.previousSendingChainMessageCount},V.encrypt(t,r)]}ratchetDecrypt(t,n,r){const i=this.trySkippedMessageKeys(t,n,r);if(i)return i;this.skipMessageKeys(t.number,r);const[o,s]=Te(this.state.receivingChainKey,new Uint8Array([1]),2);this.state.receivingChainKey=o,this.state.receivingChainMessageNumber++;try{return V.decrypt(n,s)}catch(a){throw console.error(this.name,"Decryption failed:",a,{messageKey:M(s).slice(0,4),receivingChainKey:M(this.state.receivingChainKey).slice(0,4),sendingChainKey:this.state.sendingChainKey&&M(this.state.sendingChainKey).slice(0,4),rootKey:M(this.state.rootKey).slice(0,4)}),a}}ratchetStep(t){this.state.previousSendingChainMessageCount=this.state.sendingChainMessageNumber,this.state.sendingChainMessageNumber=0,this.state.receivingChainMessageNumber=0,this.state.theirNostrPublicKey=t;const n=V.getConversationKey(this.state.ourNextNostrKey.privateKey,this.state.theirNostrPublicKey),[r,i]=Te(this.state.rootKey,n,2);this.state.receivingChainKey=i,this.state.ourCurrentNostrKey=this.state.ourNextNostrKey;const o=je();this.state.ourNextNostrKey={publicKey:_e(o),privateKey:o};const s=V.getConversationKey(this.state.ourNextNostrKey.privateKey,this.state.theirNostrPublicKey),[a,c]=Te(r,s,2);this.state.rootKey=a,this.state.sendingChainKey=c}skipMessageKeys(t,n){if(this.state.receivingChainMessageNumber+kc<t)throw new Error("Too many skipped messages");for(;this.state.receivingChainMessageNumber<t;){const[r,i]=Te(this.state.receivingChainKey,new Uint8Array([1]),2);this.state.receivingChainKey=r;const o=Kt(n,this.state.receivingChainMessageNumber);if(this.state.skippedMessageKeys[o]=i,!this.state.skippedHeaderKeys[n]){const s=[];if(this.state.ourCurrentNostrKey){const c=V.getConversationKey(this.state.ourCurrentNostrKey.privateKey,n);s.push(c)}const a=V.getConversationKey(this.state.ourNextNostrKey.privateKey,n);s.push(a),this.state.skippedHeaderKeys[n]=s}this.state.receivingChainMessageNumber++}}trySkippedMessageKeys(t,n,r){var o;const i=Kt(r,t.number);if(i in this.state.skippedMessageKeys){const s=this.state.skippedMessageKeys[i];return delete this.state.skippedMessageKeys[i],Object.keys(this.state.skippedMessageKeys).some(c=>c.startsWith(`${r}:`))||(delete this.state.skippedHeaderKeys[r],(o=this.nostrUnsubscribe)==null||o.call(this),this.nostrUnsubscribe=void 0),V.decrypt(n,s)}return null}decryptHeader(t){const n=t.tags[0][1];if(this.state.ourCurrentNostrKey){const o=V.getConversationKey(this.state.ourCurrentNostrKey.privateKey,t.pubkey);try{return[JSON.parse(V.decrypt(n,o)),!1,!1]}catch{}}const r=V.getConversationKey(this.state.ourNextNostrKey.privateKey,t.pubkey);try{return[JSON.parse(V.decrypt(n,r)),!0,!1]}catch{}const i=this.state.skippedHeaderKeys[t.pubkey];if(i)for(const o of i)try{return[JSON.parse(V.decrypt(n,o)),!1,!0]}catch{}throw new Error("Failed to decrypt header with current and skipped header keys")}handleNostrEvent(t){var s;const[n,r,i]=this.decryptHeader(t);if(!i)this.state.theirNostrPublicKey!==n.nextPublicKey&&(this.state.theirNostrPublicKey=n.nextPublicKey,(s=this.nostrUnsubscribe)==null||s.call(this),this.nostrUnsubscribe=this.nostrNextUnsubscribe,this.nostrNextUnsubscribe=this.nostrSubscribe({authors:[this.state.theirNostrPublicKey],kinds:[Le]},a=>this.handleNostrEvent(a))),r&&(this.skipMessageKeys(n.previousChainLength,t.pubkey),this.ratchetStep(n.nextPublicKey));else if(!(Kt(t.pubkey,n.number)in this.state.skippedMessageKeys))return;const o=this.ratchetDecrypt(n,t.content,t.pubkey);this.internalSubscriptions.forEach(a=>a({id:t.id,data:o,pubkey:n.nextPublicKey,time:n.time}))}subscribeToNostrEvents(){if(this.nostrNextUnsubscribe)return;this.nostrNextUnsubscribe=this.nostrSubscribe({authors:[this.state.theirNostrPublicKey],kinds:[Le]},n=>this.handleNostrEvent(n));const t=Object.keys(this.state.skippedHeaderKeys);t.length>0&&(this.nostrUnsubscribe=this.nostrSubscribe({authors:t,kinds:[Le]},n=>this.handleNostrEvent(n)))}}new TextDecoder("utf-8"),new TextEncoder;function Nt(e,t){const n=Ue.getSharedSecret(e,"02"+t).subarray(1,33);return sn(me,n,"nip44-v2")}class $e{constructor(t,n,r,i,o,s,a=[]){this.inviterSessionPublicKey=t,this.linkSecret=n,this.inviter=r,this.inviterSessionPrivateKey=i,this.label=o,this.maxUses=s,this.usedBy=a}static createNew(t,n,r){const i=je(),o=_e(i),s=M(je());return new $e(o,s,t,i,n,r)}static fromUrl(t){const r=new URL(t).hash.slice(1);if(!r)throw new Error("No invite data found in the URL hash.");const i=decodeURIComponent(r);let o;try{o=JSON.parse(i)}catch(u){throw new Error("Invite data in URL hash is not valid JSON: "+u)}const{inviter:s,sessionKey:a,linkSecret:c}=o;if(!s||!a||!c)throw new Error("Missing required fields (inviter, sessionKey, linkSecret) in invite data.");const l=Qe.decode(s),f=Qe.decode(a);if(typeof l.data!="string")throw new Error("Decoded inviter is not a string");if(typeof f.data!="string")throw new Error("Decoded session key is not a string");return new $e(f.data,c,l.data)}static deserialize(t){const n=JSON.parse(t);return new $e(n.inviterSessionPublicKey,n.linkSecret,n.inviter,n.inviterSessionPrivateKey?new Uint8Array(n.inviterSessionPrivateKey):void 0,n.label,n.maxUses,n.usedBy)}static fromEvent(t){var s,a;if(!t.sig)throw new Error("Event is not signed");if(!bt(t))throw new Error("Event signature is invalid");const{tags:n}=t,r=(s=n.find(([c])=>c==="sessionKey"))==null?void 0:s[1],i=(a=n.find(([c])=>c==="linkSecret"))==null?void 0:a[1],o=t.pubkey;if(!r||!i)throw new Error("Invalid invite event: missing session key or link secret");return new $e(r,i,o)}static fromUser(t,n){const r={kinds:[En],pubkey:t,limit:1,"#d":["nostr-double-ratchet/invite"]};return new Promise(i=>{const o=n(r,s=>{try{const a=$e.fromEvent(s);o(),i(a)}catch{o(),i(void 0)}});setTimeout(()=>{o(),i(void 0)},1e4)})}serialize(){return JSON.stringify({inviterSessionPublicKey:this.inviterSessionPublicKey,linkSecret:this.linkSecret,inviter:this.inviter,inviterSessionPrivateKey:this.inviterSessionPrivateKey?Array.from(this.inviterSessionPrivateKey):void 0,label:this.label,maxUses:this.maxUses,usedBy:this.usedBy})}getUrl(t="https://iris.to"){const n={inviter:Qe.npubEncode(this.inviter),sessionKey:Qe.npubEncode(this.inviterSessionPublicKey),linkSecret:this.linkSecret},r=new URL(t);return r.hash=encodeURIComponent(JSON.stringify(n)),console.log("url",r.toString()),r.toString()}getEvent(){return{kind:En,pubkey:this.inviter,content:"",created_at:Math.floor(Date.now()/1e3),tags:[["sessionKey",this.inviterSessionPublicKey],["linkSecret",this.linkSecret],["d","nostr-double-ratchet/invite"]]}}async accept(t,n,r){const i=je(),o=_e(i),s=this.inviter||this.inviterSessionPublicKey,a=G(this.linkSecret),c=tt.init(t,this.inviterSessionPublicKey,i,!0,a,void 0),l=je(),f=_e(l),u=typeof r=="function"?r:(g,h)=>Promise.resolve(V.encrypt(g,Nt(r,h))),d={pubkey:n,tags:[["secret",this.linkSecret]],content:await u(o,s),created_at:Math.floor(Date.now()/1e3)},p={kind:Le,pubkey:f,content:V.encrypt(JSON.stringify(d),Nt(l,this.inviterSessionPublicKey)),created_at:Math.floor(Date.now()/1e3),tags:[["p",this.inviterSessionPublicKey]]};return{channel:c,event:le(p,l)}}listen(t,n,r){if(!this.inviterSessionPrivateKey)throw new Error("Inviter session key is not available");const i={kinds:[Le],"#p":[this.inviterSessionPublicKey]};return n(i,async o=>{try{const s=await V.decrypt(o.content,Nt(this.inviterSessionPrivateKey,o.pubkey)),a=JSON.parse(s);if(!a.tags||!a.tags.some(([p,g])=>p==="secret"&&g===this.linkSecret)){console.error("Invalid secret from event",o);return}const l=await(typeof t=="function"?t:(p,g)=>Promise.resolve(V.decrypt(p,Nt(t,g))))(a.content,a.pubkey),f=G(this.linkSecret),u=o.id,d=tt.init(n,l,this.inviterSessionPrivateKey,!1,f,u);r(d,a.pubkey)}catch(s){console.error("Error processing invite message:",s)}})}}H.Channel=tt,H.INVITE_EVENT_KIND=En,H.Invite=$e,H.MAX_SKIP=Ac,H.MESSAGE_EVENT_KIND=Le,H.Sender=ii,H.createMessageStream=Cc,H.deserializeChannelState=Nc,H.kdf=Te,H.serializeChannelState=Kc,H.skippedMessageIndexKey=Kt,Object.defineProperty(H,Symbol.toStringTag,{value:"Module"})});
package/dist/types.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { VerifiedEvent } from "nostr-tools";
1
+ import { Filter, UnsignedEvent, VerifiedEvent } from "nostr-tools";
2
2
  /**
3
3
  * An event that has been verified to be from the Nostr network.
4
4
  */
@@ -14,10 +14,6 @@ export type Header = {
14
14
  nextPublicKey: string;
15
15
  time: number;
16
16
  };
17
- export type NostrFilter = {
18
- authors?: string[];
19
- kinds?: number[];
20
- };
21
17
  /**
22
18
  * A keypair used for encryption and decryption.
23
19
  */
@@ -49,6 +45,8 @@ export interface ChannelState {
49
45
  previousSendingChainMessageCount: number;
50
46
  /** Cache of message keys for handling out-of-order messages */
51
47
  skippedMessageKeys: Record<string, Uint8Array>;
48
+ /** Cache of header keys for handling out-of-order messages */
49
+ skippedHeaderKeys: Record<string, Uint8Array[]>;
52
50
  }
53
51
  /**
54
52
  * Unsubscribe from a subscription or event listener.
@@ -57,13 +55,14 @@ export type Unsubscribe = () => void;
57
55
  /**
58
56
  * Function that subscribes to Nostr events matching a filter and calls onEvent for each event.
59
57
  */
60
- export type NostrSubscribe = (filter: NostrFilter, onEvent: (e: VerifiedEvent) => void) => Unsubscribe;
58
+ export type NostrSubscribe = (filter: Filter, onEvent: (e: VerifiedEvent) => void) => Unsubscribe;
61
59
  /**
62
60
  * Callback function for handling decrypted messages
63
61
  * @param message - The decrypted message object
64
62
  */
65
63
  export type MessageCallback = (message: Message) => void;
66
- export declare const EVENT_KIND = 4;
64
+ export declare const MESSAGE_EVENT_KIND = 4;
65
+ export declare const INVITE_EVENT_KIND = 30078;
67
66
  export declare const MAX_SKIP = 100;
68
67
  export type NostrEvent = {
69
68
  id: string;
@@ -80,4 +79,5 @@ export declare enum Sender {
80
79
  }
81
80
  export type EncryptFunction = (plaintext: string, pubkey: string) => Promise<string>;
82
81
  export type DecryptFunction = (ciphertext: string, pubkey: string) => Promise<string>;
82
+ export type NostrPublish = (event: UnsignedEvent) => Promise<VerifiedEvent>;
83
83
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C;;GAEG;AACH,MAAM,MAAM,OAAO,GAAG;IACpB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;CACd,CAAA;AAED,MAAM,MAAM,MAAM,GAAG;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,mBAAmB,EAAE,MAAM,CAAC;IAC5B,aAAa,EAAE,MAAM,CAAC;IACtB,IAAI,EAAE,MAAM,CAAC;CACd,CAAA;AAED,MAAM,MAAM,WAAW,GAAG;IACxB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;CAClB,CAAA;AAED;;GAEG;AACH,MAAM,MAAM,OAAO,GAAG;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,UAAU,CAAC;CACxB,CAAA;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,iEAAiE;IACjE,OAAO,EAAE,UAAU,CAAC;IAEpB,iDAAiD;IACjD,mBAAmB,EAAE,MAAM,CAAC;IAE5B,sDAAsD;IACtD,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAE7B,kGAAkG;IAClG,eAAe,EAAE,OAAO,CAAC;IAEzB,4DAA4D;IAC5D,iBAAiB,CAAC,EAAE,UAAU,CAAC;IAE/B,4DAA4D;IAC5D,eAAe,CAAC,EAAE,UAAU,CAAC;IAE7B,uDAAuD;IACvD,yBAAyB,EAAE,MAAM,CAAC;IAElC,6DAA6D;IAC7D,2BAA2B,EAAE,MAAM,CAAC;IAEpC,wDAAwD;IACxD,gCAAgC,EAAE,MAAM,CAAC;IAEzC,+DAA+D;IAC/D,kBAAkB,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;CAChD;AAED;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC;AAErC;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,CAAC,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,CAAC,CAAC,EAAE,aAAa,KAAK,IAAI,KAAK,WAAW,CAAC;AAEvG;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,CAAC;AAEzD,eAAO,MAAM,UAAU,IAAI,CAAC;AAC5B,eAAO,MAAM,QAAQ,MAAM,CAAC;AAE5B,MAAM,MAAM,UAAU,GAAG;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,EAAE,EAAE,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,EAAE,MAAM,CAAC;CACb,CAAA;AAED,oBAAY,MAAM;IAChB,EAAE,IAAA;IACF,IAAI,IAAA;CACL;AAED,MAAM,MAAM,eAAe,GAAG,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;AACrF,MAAM,MAAM,eAAe,GAAG,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEnE;;GAEG;AACH,MAAM,MAAM,OAAO,GAAG;IACpB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;CACd,CAAA;AAED,MAAM,MAAM,MAAM,GAAG;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,mBAAmB,EAAE,MAAM,CAAC;IAC5B,aAAa,EAAE,MAAM,CAAC;IACtB,IAAI,EAAE,MAAM,CAAC;CACd,CAAA;AAED;;GAEG;AACH,MAAM,MAAM,OAAO,GAAG;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,UAAU,CAAC;CACxB,CAAA;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,iEAAiE;IACjE,OAAO,EAAE,UAAU,CAAC;IAEpB,iDAAiD;IACjD,mBAAmB,EAAE,MAAM,CAAC;IAE5B,sDAAsD;IACtD,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAE7B,kGAAkG;IAClG,eAAe,EAAE,OAAO,CAAC;IAEzB,4DAA4D;IAC5D,iBAAiB,CAAC,EAAE,UAAU,CAAC;IAE/B,4DAA4D;IAC5D,eAAe,CAAC,EAAE,UAAU,CAAC;IAE7B,uDAAuD;IACvD,yBAAyB,EAAE,MAAM,CAAC;IAElC,6DAA6D;IAC7D,2BAA2B,EAAE,MAAM,CAAC;IAEpC,wDAAwD;IACxD,gCAAgC,EAAE,MAAM,CAAC;IAEzC,+DAA+D;IAC/D,kBAAkB,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IAE/C,8DAA8D;IAC9D,iBAAiB,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,EAAE,CAAC,CAAC;CACjD;AAED;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC;AAErC;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC,EAAE,aAAa,KAAK,IAAI,KAAK,WAAW,CAAC;AAElG;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,CAAC;AAEzD,eAAO,MAAM,kBAAkB,IAAI,CAAC;AACpC,eAAO,MAAM,iBAAiB,QAAQ,CAAC;AACvC,eAAO,MAAM,QAAQ,MAAM,CAAC;AAE5B,MAAM,MAAM,UAAU,GAAG;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,EAAE,EAAE,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,EAAE,MAAM,CAAC;CACb,CAAA;AAED,oBAAY,MAAM;IAChB,EAAE,IAAA;IACF,IAAI,IAAA;CACL;AAED,MAAM,MAAM,eAAe,GAAG,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;AACrF,MAAM,MAAM,eAAe,GAAG,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;AACtF,MAAM,MAAM,YAAY,GAAG,CAAC,KAAK,EAAE,aAAa,KAAK,OAAO,CAAC,aAAa,CAAC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAChD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAIpC,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,YAAY,GAAG,MAAM,CAwBjE;AAED,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,CAyBlE;AAED,wBAAuB,mBAAmB,CAAC,OAAO,EAAE,OAAO,GAAG,cAAc,CAAC,OAAO,EAAE,IAAI,EAAE,OAAO,CAAC,CA0BnG;AAED,wBAAgB,GAAG,CAAC,MAAM,EAAE,UAAU,EAAE,MAAM,GAAE,UAA+B,EAAE,UAAU,GAAE,MAAU,GAAG,UAAU,EAAE,CAQrH;AAED,wBAAgB,sBAAsB,CAAC,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAElF"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAChD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAIpC,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,YAAY,GAAG,MAAM,CA8BjE;AAED,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,CA+BlE;AAED,wBAAuB,mBAAmB,CAAC,OAAO,EAAE,OAAO,GAAG,cAAc,CAAC,OAAO,EAAE,IAAI,EAAE,OAAO,CAAC,CA0BnG;AAED,wBAAgB,GAAG,CAAC,MAAM,EAAE,UAAU,EAAE,MAAM,GAAE,UAA+B,EAAE,UAAU,GAAE,MAAU,GAAG,UAAU,EAAE,CAQrH;AAED,wBAAgB,sBAAsB,CAAC,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAElF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nostr-double-ratchet",
3
- "version": "0.0.6",
3
+ "version": "0.0.8",
4
4
  "type": "module",
5
5
  "packageManager": "yarn@1.22.22",
6
6
  "description": "Nostr double ratchet library",
@@ -26,6 +26,7 @@
26
26
  "url": "https://github.com/mmalmi/nostr-double-ratchet/issues"
27
27
  },
28
28
  "homepage": "https://github.com/mmalmi/nostr-double-ratchet",
29
+ "documentation": "https://nostr-double-ratchet.iris.to/",
29
30
  "files": [
30
31
  "src",
31
32
  "dist"