nostr-double-ratchet 0.0.5 → 0.0.6

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 Nc=Object.defineProperty;var Ic=(q,G,Ce)=>G in q?Nc(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,Bt=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=Bt(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=Bt(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=Bt(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 Nt=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 kt(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 Ut(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 Ne(...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),Bn=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(Bn([0]),u),r=c(),u.length!==0&&(i=c(Bn([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 Ne(...d)};return(u,d)=>{s(),a(u);let g;for(;!(g=d(l()));)a();return s(),g}}const Bi={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=Bi[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:kt,concatBytes:Ne,createHmacDrbg:Cn,ensureBytes:F,equalBytes:mi,hexToBytes:Pe,hexToNumber:It,numberToBytesBE:be,numberToBytesLE:Ut,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),Ni=BigInt(3),$t=BigInt(4),Nn=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 Tt(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 ki(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)/$t;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 Ui(e){if(e%$t===Ni){const t=(e+D)/$t;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===Nn){const t=(e-Nn)/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 ki(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 $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 Ti(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 kn(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}=kn(e,t);if(o>2048)throw new Error("Field lengths over 2048 bytes are not supported");const s=Ui(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)=>$i(c,a,l),div:(a,l)=>V(a*Tt(l,e),e),sqrN:a=>a*a,addN:(a,l)=>a+l,subN:(a,l)=>a-l,mulN:(a,l)=>a*l,inv:a=>Tt(a,e),sqrt:r.sqrt||(a=>s(c,a)),invertBatch:a=>Ti(c,a),cmov:(a,l,f)=>f?l:a,toBytes:a=>n?Ut(a,o):be(a,o),fromBytes:a=>{if(a.length!==o)throw new Error(`Fp.fromBytes: expected ${o}, got ${a.length}`);return n?kt(a):J(a)}});return Object.freeze(c)}function Un(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=Un(e);return t+Math.ceil(t/2)}function Pi(e,t,n=!1){const r=e.length,i=Un(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):kt(e),c=V(s,t-D)+D;return n?Ut(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,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,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({...kn(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,ke={Err:class extends Error{constructor(t=""){super(t)}},_parseInt(e){const{Err:t}=ke;if(e.length<2||e[0]!==2)throw new t("Invalid signature integer tag");const n=e[1],r=e.subarray(2,n+2);if(!n||r.length!==n)throw new t("Invalid signature integer: wrong length");if(r[0]&128)throw new t("Invalid signature integer: negative");if(r[0]===0&&!(r[1]&128))throw new t("Invalid signature integer: unnecessary leading zero");return{d:qi(r),l:e.subarray(n+2)}},toSig(e){const{Err:t}=ke,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}=ke._parseInt(n.subarray(2)),{d:s,l:c}=ke._parseInt(o);if(c.length)throw new t("Invalid signature: left bytes after parsing");return{r:i,s}},hexFromSig(e){const t=l=>Number.parseInt(l[0],16)&8?"00"+l:l,n=l=>{const f=l.toString(16);return f.length&1?`0${f}`:f},r=t(n(e.s)),i=t(n(e.r)),o=r.length/2,s=i.length/2,c=n(o),a=n(s);return`30${n(s+o+4)}02${a}${i}02${c}${r}`}},ue=BigInt(0),Q=BigInt(1);BigInt(2);const $n=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 Ne(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:U,pz:N}=h,E=n.eql(n.mul(y,N),n.mul(K,m)),x=n.eql(n.mul(w,N),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 N=n.ZERO,E=n.ZERO,x=n.ZERO,S=n.mul(m,m),O=n.mul(K,K),k=n.mul(U,U),B=n.mul(m,K);return B=n.add(B,B),x=n.mul(m,U),x=n.add(x,x),N=n.mul(h,x),E=n.mul(w,k),E=n.add(N,E),N=n.sub(O,E),E=n.add(O,E),E=n.mul(N,E),N=n.mul(B,N),x=n.mul(w,x),k=n.mul(h,k),B=n.sub(S,k),B=n.mul(h,B),B=n.add(B,x),x=n.add(S,S),S=n.add(x,S),S=n.add(S,k),S=n.mul(S,B),E=n.add(E,S),k=n.mul(K,U),k=n.add(k,k),S=n.mul(k,B),N=n.sub(N,S),x=n.mul(k,O),x=n.add(x,x),x=n.add(x,x),new u(N,E,x)}add(h){f(h);const{px:y,py:w,pz:m}=this,{px:K,py:U,pz:N}=h;let E=n.ZERO,x=n.ZERO,S=n.ZERO;const O=t.a,k=n.mul(t.b,$n);let B=n.mul(y,K),T=n.mul(w,U),R=n.mul(m,N),H=n.add(y,w),b=n.add(K,U);H=n.mul(H,b),b=n.add(B,T),H=n.sub(H,b),b=n.add(y,m);let v=n.add(K,N);return b=n.mul(b,v),v=n.add(B,R),b=n.sub(b,v),v=n.add(w,m),E=n.add(U,N),v=n.mul(v,E),E=n.add(T,R),v=n.sub(v,E),S=n.mul(O,b),E=n.mul(k,R),S=n.add(E,S),E=n.sub(T,S),S=n.add(T,S),x=n.mul(E,S),T=n.add(B,B),T=n.add(T,B),R=n.mul(O,R),b=n.mul(k,b),T=n.add(T,R),R=n.sub(B,R),R=n.mul(O,R),b=n.add(b,R),B=n.mul(T,b),x=n.add(x,B),B=n.mul(v,b),E=n.mul(H,E),E=n.sub(E,B),B=n.mul(H,T),S=n.mul(v,S),S=n.add(S,B),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:U,k2:N}=w.splitScalar(h),E=y,x=y,S=this;for(;K>ue||N>ue;)K&Q&&(E=E.add(S)),N&Q&&(x=x.add(S)),S=S.double(),K>>=Q,N>>=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){c(h);let y=h,w,m;const{endo:K}=t;if(K){const{k1neg:U,k1:N,k2neg:E,k2:x}=K.splitScalar(y);let{p:S,f:O}=this.wNAF(N),{p:k,f:B}=this.wNAF(x);S=g.constTimeNegate(U,S),k=g.constTimeNegate(E,k),k=new u(n.mul(k.px,K.beta),k.py,k.pz),w=S.add(k),m=O.add(B)}else{const{p:U,f:N}=this.wNAF(y);w=U,m=N}return u.normalizeZ([w,m])[0]}multiplyAndAddUnsafe(h,y,w){const m=u.BASE,K=(N,E)=>E===ue||E===Q||!N.equals(m)?N.multiplyUnsafe(E):N.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),N=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:N}}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 Tt(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=Ne;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 $=(P&Q)===Q;return(A&1)===1!==$&&(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}=ke.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 $=C&1?"03":"02",te=l.fromHex($+g(P)),Ke=a(P),je=c(-L*Ke),nt=c(I*Ke),Be=l.BASE.multiplyAndAddUnsafe(te,je,nt);if(!Be)throw new Error("point at infinify");return Be.assertValidity(),Be}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 ke.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 U(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 N(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=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 k(b,v,A=B){if(["recovered","canonical"].some(Te=>Te in A))throw new Error("sign() legacy options not supported");const{hash:I,randomBytes:C}=t;let{lowS:L,prehash:P,extraEntropy:$}=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($!=null){const Te=$===!0?C(n.BYTES):$;je.push(F("extraEntropy",Te))}const nt=Ne(...je),Be=te;function En(Te){const ze=E(Te);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(Be+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 B={lowS:t.lowS,prehash:!1},T={lowS:t.lowS,prehash:!1};function R(b,v,A=B){const{seed:I,k2sig:C}=k(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=T){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 $,te;try{if(typeof C=="string"||C instanceof Uint8Array)try{$=w.fromDER(C)}catch(ne){if(!(ne instanceof ke.Err))throw ne;$=w.fromCompact(C)}else if(typeof C=="object"&&typeof C.r=="bigint"&&typeof C.s=="bigint"){const{r:ne,s:Ze}=C;$=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&&$.hasHighS())return!1;P&&(v=t.hash(v));const{r:Ke,s:je}=$,nt=x(v),Be=a(je),En=c(nt*Be),Te=c(Ke*Be),ze=(Ve=l.BASE.multiplyAndAddUnsafe(te,En,Te))==null?void 0:Ve.toAffine();return ze?c(ze.x)===Ke:!1}return{CURVE:t,getPublicKey:K,getSharedSecret:N,sign:R,verify:H,ProjectivePoint:l,Signature:w,utils:m}}let Tn=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 Tn(e,t).update(n).digest();Rn.create=(e,t)=>new Tn(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,U=X(K,s,t)*p%t,N=X(U,r,t)*l%t,E=X(N,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}),Ue=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}}}},Nt),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=Nt(Uint8Array.from(e,i=>i.charCodeAt(0)));n=Ne(r,r),qn[e]=n}return Nt(Ne(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=Ue.ProjectivePoint,Gi=(e,t,n)=>qt.BASE.multiplyAndAddUnsafe(e,t,n);function Dt(e){let t=Ue.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:Ue.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 Bo(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 No(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 ko(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 Uo(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=Uo(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)=>{No(o);const c=Bo(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,U=h;d=f[y+0],g=f[y+1],p=f[y+2],h=f[y+3];const{s0:N,s1:E,s2:x,s3:S}=Co(c,d,g,p,h);u[y++]=N^w,u[y++]=E^m,u[y++]=x^K,u[y++]=S^U}return c.fill(0),ko(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"),$o=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,To=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<To;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=$o,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 U=new Uint8Array(12);U.set(a,o?0:12-a.length),a=U,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],U=n[1],N=n[2],E=s,x=c,S=a,O=l,k=f,B=u,T=d,R=g,H=p,b=h,v=y,A=w,I=m,C=K,L=U,P=N;for(let te=0;te<o;te+=2)E=E+k|0,I=_(I^E,16),H=H+I|0,k=_(k^H,12),E=E+k|0,I=_(I^E,8),H=H+I|0,k=_(k^H,7),x=x+B|0,C=_(C^x,16),b=b+C|0,B=_(B^b,12),x=x+B|0,C=_(C^x,8),b=b+C|0,B=_(B^b,7),S=S+T|0,L=_(L^S,16),v=v+L|0,T=_(T^v,12),S=S+T|0,L=_(L^S,8),v=v+L|0,T=_(T^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+B|0,P=_(P^E,16),v=v+P|0,B=_(B^v,12),E=E+B|0,P=_(P^E,8),v=v+P|0,B=_(B^v,7),x=x+T|0,I=_(I^x,16),A=A+I|0,T=_(T^A,12),x=x+T|0,I=_(I^x,8),A=A+I|0,T=_(T^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+k|0,L=_(L^O,16),b=b+L|0,k=_(k^b,12),O=O+k|0,L=_(L^O,8),b=b+L|0,k=_(k^b,7);let $=0;r[$++]=s+E|0,r[$++]=c+x|0,r[$++]=a+S|0,r[$++]=l+O|0,r[$++]=f+k|0,r[$++]=u+B|0,r[$++]=d+T|0,r[$++]=g+R|0,r[$++]=p+H|0,r[$++]=h+b|0,r[$++]=y+v|0,r[$++]=w+A|0,r[$++]=m+I|0,r[$++]=K+C|0,r[$++]=U+L|0,r[$++]=N+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:()=>Bs,BookmarkList:()=>Ss,Bookmarksets:()=>Os,Calendar:()=>ta,CalendarEventRSVP:()=>na,ChannelCreation:()=>Kr,ChannelHideMessage:()=>Nr,ChannelMessage:()=>Cr,ChannelMetadata:()=>Br,ChannelMuteUser:()=>Ir,ClassifiedListing:()=>Ys,ClientAuth:()=>kr,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:()=>ks,Followsets:()=>Ts,GenericRepost:()=>is,Genericlists:()=>Rs,HTTPAuth:()=>un,Handlerinformation:()=>ia,Handlerrecommendation:()=>ra,Highlights:()=>vs,InterestsList:()=>Ns,Interestsets:()=>Ds,JobFeedback:()=>gs,JobRequest:()=>ds,JobResult:()=>ys,Label:()=>fs,LightningPubRPC:()=>_s,LiveChatMessage:()=>as,LiveEvent:()=>Gs,LongFormArticle:()=>Vs,Metadata:()=>Jo,Mutelist:()=>Es,NWCWalletInfo:()=>Us,NWCWalletRequest:()=>Ur,NWCWalletResponse:()=>Ls,NostrConnect:()=>$s,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,Br=41,Cr=42,Nr=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,Bs=10006,Cs=10007,Ns=10015,Is=10030,ks=10096,Us=13194,_s=21e3,kr=22242,Ur=23194,Ls=23195,$s=24133,un=27235,Ts=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:kr,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:()=>$r});async function $r(e,t,n){const r=e instanceof Uint8Array?M(e):e,i=Ue.getSharedSecret(r,"02"+t),o=Tr(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=Ue.getSharedSecret(r,"02"+t),c=Tr(s),a=ye.decode(o),l=ye.decode(i),f=ur(c,a).decrypt(l);return ce.decode(f)}function Tr(e){return e.slice(1,33)}var Ka={};j(Ka,{NIP05_REGEX:()=>Rr,isValid:()=>Na,queryProfile:()=>Pr,searchDomain:()=>Ca,useFetchImplementation:()=>Ba});var Rr=/^(?:([\w.+-]+)@)?([\w_-]+(\.[\w_-]+)+)$/,xt;try{xt=fetch}catch{}function Ba(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 Na(e,t){let n=await Pr(t);return n?n.pubkey===e:!1}var Ia={};j(Ia,{parse:()=>ka});function ka(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 Ua={};j(Ua,{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 $a={};j($a,{getPow:()=>Mr,minePow:()=>Ta});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 Ta(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:Br,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:Nr,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=Ue.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 $r(t,e,JSON.stringify({method:"pay_invoice",params:{invoice:n}})),o={kind:Ur,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*Bc(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 $e(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]=$e(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]=$e(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]=$e(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]=$e(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]=$e(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]=$e(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=Ue.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 n=new URL(t),r=n.pathname.slice(1),i=n.searchParams.get("s"),o=n.hash.slice(1);if(!r)throw new Error("Inviter not found in the URL");if(!i)throw new Error("Session key not found in the URL");const s=Xe.decode(r),c=Xe.decode(i);if(typeof s.data!="string")throw new Error("Decoded inviter is not a string");if(typeof c.data!="string")throw new Error("Decoded session key is not a string");const a=s.data,l=c.data;return new tt(l,o,a)}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=new URL(`${t}/${Xe.npubEncode(this.inviter)}`);return n.searchParams.set("s",Xe.npubEncode(this.inviterSessionPublicKey)),n.hash=this.linkSecret,n.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=Bc,q.deserializeChannelState=Kc,q.kdf=$e,q.serializeChannelState=Ac,q.skippedMessageIndexKey=vn,Object.defineProperty(q,Symbol.toStringTag,{value:"Module"})});
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"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nostr-double-ratchet",
3
- "version": "0.0.5",
3
+ "version": "0.0.6",
4
4
  "type": "module",
5
5
  "packageManager": "yarn@1.22.22",
6
6
  "description": "Nostr double ratchet library",
package/src/Channel.ts CHANGED
@@ -212,6 +212,8 @@ export class Channel {
212
212
  }
213
213
 
214
214
  throw new Error("Failed to decrypt header with both current and next secrets");
215
+
216
+ // what if it was a skipped message? need to store our old private keys for that?
215
217
  }
216
218
 
217
219
  private handleNostrEvent(e: any) {
package/src/InviteLink.ts CHANGED
@@ -44,19 +44,26 @@ export class InviteLink {
44
44
 
45
45
  static fromUrl(url: string): InviteLink {
46
46
  const parsedUrl = new URL(url);
47
- const inviter = parsedUrl.pathname.slice(1);
48
- const inviterSessionPublicKey = parsedUrl.searchParams.get('s');
49
- const linkSecret = parsedUrl.hash.slice(1);
50
-
51
- if (!inviter) {
52
- throw new Error("Inviter not found in the URL");
47
+ const rawHash = parsedUrl.hash.slice(1);
48
+ if (!rawHash) {
49
+ throw new Error("No invite data found in the URL hash.");
53
50
  }
54
- if (!inviterSessionPublicKey) {
55
- throw new Error("Session key not found in the URL");
51
+
52
+ const decodedHash = decodeURIComponent(rawHash);
53
+ let data: any;
54
+ try {
55
+ data = JSON.parse(decodedHash);
56
+ } catch (err) {
57
+ throw new Error("Invite data in URL hash is not valid JSON: " + err);
58
+ }
59
+
60
+ const { inviter, sessionKey, linkSecret } = data;
61
+ if (!inviter || !sessionKey || !linkSecret) {
62
+ throw new Error("Missing required fields (inviter, sessionKey, linkSecret) in invite data.");
56
63
  }
57
64
 
58
65
  const decodedInviter = nip19.decode(inviter);
59
- const decodedSessionKey = nip19.decode(inviterSessionPublicKey);
66
+ const decodedSessionKey = nip19.decode(sessionKey);
60
67
 
61
68
  if (typeof decodedInviter.data !== 'string') {
62
69
  throw new Error("Decoded inviter is not a string");
@@ -65,10 +72,11 @@ export class InviteLink {
65
72
  throw new Error("Decoded session key is not a string");
66
73
  }
67
74
 
68
- const inviterHexPub = decodedInviter.data;
69
- const inviterSessionPublicKeyHex = decodedSessionKey.data;
70
-
71
- return new InviteLink(inviterSessionPublicKeyHex, linkSecret, inviterHexPub);
75
+ return new InviteLink(
76
+ decodedSessionKey.data,
77
+ linkSecret,
78
+ decodedInviter.data
79
+ );
72
80
  }
73
81
 
74
82
  static deserialize(json: string): InviteLink {
@@ -97,10 +105,15 @@ export class InviteLink {
97
105
  }
98
106
 
99
107
  getUrl(root = "https://iris.to") {
100
- const url = new URL(`${root}/${nip19.npubEncode(this.inviter)}`)
101
- url.searchParams.set('s', nip19.npubEncode(this.inviterSessionPublicKey))
102
- url.hash = this.linkSecret
103
- return url.toString()
108
+ const data = {
109
+ inviter: nip19.npubEncode(this.inviter),
110
+ sessionKey: nip19.npubEncode(this.inviterSessionPublicKey),
111
+ linkSecret: this.linkSecret
112
+ };
113
+ const url = new URL(root);
114
+ url.hash = encodeURIComponent(JSON.stringify(data));
115
+ console.log('url', url.toString())
116
+ return url.toString();
104
117
  }
105
118
 
106
119
  /**