nostr-double-ratchet 0.0.35 → 0.0.37
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.
- package/dist/Invite.d.ts +2 -1
- package/dist/Invite.d.ts.map +1 -1
- package/dist/SessionManager.d.ts +69 -30
- package/dist/SessionManager.d.ts.map +1 -1
- package/dist/StorageAdapter.d.ts +9 -0
- package/dist/StorageAdapter.d.ts.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/nostr-double-ratchet.es.js +2714 -2176
- package/dist/nostr-double-ratchet.umd.js +1 -1
- package/package.json +1 -1
- package/src/Invite.ts +5 -2
- package/src/SessionManager.ts +766 -344
- package/src/StorageAdapter.ts +65 -6
- package/src/index.ts +2 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(P,J){typeof exports=="object"&&typeof module<"u"?J(exports):typeof define=="function"&&define.amd?define(["exports"],J):(P=typeof globalThis<"u"?globalThis:P||self,J(P["nostr-double-ratchet"]={}))})(this,function(P){"use strict";var du=Object.defineProperty;var yu=(P,J,ke)=>J in P?du(P,J,{enumerable:!0,configurable:!0,writable:!0,value:ke}):P[J]=ke;var te=(P,J,ke)=>yu(P,typeof J!="symbol"?J+"":J,ke);function J(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`Wrong positive integer: ${e}`)}function ke(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");J(e.outputLen),J(e.blockLen)}function nt(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function Ci(e,t){ke(e);const n=t.outputLen;if(e.length<n)throw new Error(`digestInto() expects output buffer of length at least ${n}`)}const St=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Bn=e=>e instanceof Uint8Array,At=e=>new DataView(e.buffer,e.byteOffset,e.byteLength),se=(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 ki(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=ki(e)),!Bn(e))throw new Error(`expected Uint8Array, got ${typeof e}`);return e}function Ii(...e){const t=new Uint8Array(e.reduce((r,i)=>r+i.length,0));let n=0;return e.forEach(r=>{if(!Bn(r))throw new Error("Uint8Array expected");t.set(r,n),n+=r.length}),t}let _n=class{clone(){return this._cloneInto()}};function Bi(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 Un(e=32){if(St&&typeof St.getRandomValues=="function")return St.getRandomValues(new Uint8Array(e));throw new Error("crypto.getRandomValues must be defined")}function _i(e,t,n,r){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,n,r);const i=BigInt(32),s=BigInt(4294967295),o=Number(n>>i&s),c=Number(n&s),a=r?4:0,l=r?0:4;e.setUint32(t+a,o,r),e.setUint32(t+l,c,r)}let Ui=class extends _n{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=At(this.buffer)}update(t){nt(this);const{view:n,buffer:r,blockLen:i}=this;t=Ct(t);const s=t.length;for(let o=0;o<s;){const c=Math.min(i-this.pos,s-o);if(c===i){const a=At(t);for(;i<=s-o;o+=i)this.process(a,o);continue}r.set(t.subarray(o,o+c),this.pos),this.pos+=c,o+=c,this.pos===i&&(this.process(n,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){nt(this),Ci(t,this),this.finished=!0;const{buffer:n,view:r,blockLen:i,isLE:s}=this;let{pos:o}=this;n[o++]=128,this.buffer.subarray(o).fill(0),this.padOffset>i-o&&(this.process(r,0),o=0);for(let u=o;u<i;u++)n[u]=0;_i(r,i-8,BigInt(this.length*8),s),this.process(r,0);const c=At(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],s)}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:s,destroyed:o,pos:c}=this;return t.length=i,t.pos=c,t.finished=s,t.destroyed=o,i%n&&t.buffer.set(r),t}};const Li=(e,t,n)=>e&t^~e&n,$i=(e,t,n)=>e&t^e&n^t&n,Ti=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),be=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),ve=new Uint32Array(64);let Ri=class extends Ui{constructor(){super(64,32,8,!1),this.A=be[0]|0,this.B=be[1]|0,this.C=be[2]|0,this.D=be[3]|0,this.E=be[4]|0,this.F=be[5]|0,this.G=be[6]|0,this.H=be[7]|0}get(){const{A:t,B:n,C:r,D:i,E:s,F:o,G:c,H:a}=this;return[t,n,r,i,s,o,c,a]}set(t,n,r,i,s,o,c,a){this.A=t|0,this.B=n|0,this.C=r|0,this.D=i|0,this.E=s|0,this.F=o|0,this.G=c|0,this.H=a|0}process(t,n){for(let u=0;u<16;u++,n+=4)ve[u]=t.getUint32(n,!1);for(let u=16;u<64;u++){const p=ve[u-15],w=ve[u-2],g=se(p,7)^se(p,18)^p>>>3,h=se(w,17)^se(w,19)^w>>>10;ve[u]=h+ve[u-7]+g+ve[u-16]|0}let{A:r,B:i,C:s,D:o,E:c,F:a,G:l,H:f}=this;for(let u=0;u<64;u++){const p=se(c,6)^se(c,11)^se(c,25),w=f+p+Li(c,a,l)+Ti[u]+ve[u]|0,h=(se(r,2)^se(r,13)^se(r,22))+$i(r,i,s)|0;f=l,l=a,a=c,c=o+w|0,o=s,s=i,i=r,r=w+h|0}r=r+this.A|0,i=i+this.B|0,s=s+this.C|0,o=o+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,s,o,c,a,l,f)}roundClean(){ve.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};const kt=Bi(()=>new Ri);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Ln=BigInt(0),rt=BigInt(1),Oi=BigInt(2),it=e=>e instanceof Uint8Array,Mi=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Me(e){if(!it(e))throw new Error("Uint8Array expected");let t="";for(let n=0;n<e.length;n++)t+=Mi[e[n]];return t}function $n(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,s=e.slice(i,i+2),o=Number.parseInt(s,16);if(Number.isNaN(o)||o<0)throw new Error("Invalid byte sequence");n[r]=o}return n}function Y(e){return It(Me(e))}function Bt(e){if(!it(e))throw new Error("Uint8Array expected");return It(Me(Uint8Array.from(e).reverse()))}function me(e,t){return Pe(e.toString(16).padStart(t*2,"0"))}function _t(e,t){return me(e,t).reverse()}function Pi(e){return Pe($n(e))}function G(e,t,n){let r;if(typeof t=="string")try{r=Pe(t)}catch(s){throw new Error(`${e} must be valid hex string, got "${t}". Cause: ${s}`)}else if(it(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 Ie(...e){const t=new Uint8Array(e.reduce((r,i)=>r+i.length,0));let n=0;return e.forEach(r=>{if(!it(r))throw new Error("Uint8Array expected");t.set(r,n),n+=r.length}),t}function Hi(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 Di(e){if(typeof e!="string")throw new Error(`utf8ToBytes expected string, got ${typeof e}`);return new Uint8Array(new TextEncoder().encode(e))}function qi(e){let t;for(t=0;e>Ln;e>>=rt,t+=1);return t}function ji(e,t){return e>>BigInt(t)&rt}const zi=(e,t,n)=>e|(n?rt:Ln)<<BigInt(t),Ut=e=>(Oi<<BigInt(e-1))-rt,Lt=e=>new Uint8Array(e),Tn=e=>Uint8Array.from(e);function Rn(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),s=0;const o=()=>{r.fill(1),i.fill(0),s=0},c=(...u)=>n(i,r,...u),a=(u=Lt())=>{i=c(Tn([0]),u),r=c(),u.length!==0&&(i=c(Tn([1]),u),r=c())},l=()=>{if(s++>=1e3)throw new Error("drbg: tried 1000 values");let u=0;const p=[];for(;u<t;){r=c();const w=r.slice();p.push(w),u+=r.length}return Ie(...p)};return(u,p)=>{o(),a(u);let w;for(;!(w=p(l()));)a();return o(),w}}const Vi={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,s,o)=>{const c=Vi[s];if(typeof c!="function")throw new Error(`Invalid validator "${s}", expected function`);const a=e[i];if(!(o&&a===void 0)&&!c(a,e))throw new Error(`Invalid param ${String(i)}=${a} (${typeof a}), expected ${s}`)};for(const[i,s]of Object.entries(t))r(i,s,!1);for(const[i,s]of Object.entries(n))r(i,s,!0);return e}const Wi=Object.freeze(Object.defineProperty({__proto__:null,bitGet:ji,bitLen:qi,bitMask:Ut,bitSet:zi,bytesToHex:Me,bytesToNumberBE:Y,bytesToNumberLE:Bt,concatBytes:Ie,createHmacDrbg:Rn,ensureBytes:G,equalBytes:Hi,hexToBytes:Pe,hexToNumber:It,numberToBytesBE:me,numberToBytesLE:_t,numberToHexUnpadded:$n,numberToVarBytesBE:Pi,utf8ToBytes:Di,validateObject:Fe},Symbol.toStringTag,{value:"Module"}));/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const W=BigInt(0),z=BigInt(1),Be=BigInt(2),Zi=BigInt(3),$t=BigInt(4),On=BigInt(5),Mn=BigInt(8);BigInt(9),BigInt(16);function Z(e,t){const n=e%t;return n>=W?n:t+n}function Gi(e,t,n){if(n<=W||t<W)throw new Error("Expected power/modulo > 0");if(n===z)return W;let r=z;for(;t>W;)t&z&&(r=r*e%n),e=e*e%n,t>>=z;return r}function X(e,t,n){let r=e;for(;t-- >W;)r*=r,r%=n;return r}function Tt(e,t){if(e===W||t<=W)throw new Error(`invert: expected positive integers, got n=${e} mod=${t}`);let n=Z(e,t),r=t,i=W,s=z;for(;n!==W;){const c=r/n,a=r%n,l=i-s*c;r=n,n=a,i=s,s=l}if(r!==z)throw new Error("invert: does not exist");return Z(i,t)}function Fi(e){const t=(e-z)/Be;let n,r,i;for(n=e-z,r=0;n%Be===W;n/=Be,r++);for(i=Be;i<e&&Gi(i,t,e)!==e-z;i++);if(r===1){const o=(e+z)/$t;return function(a,l){const f=a.pow(l,o);if(!a.eql(a.sqr(f),l))throw new Error("Cannot find square root");return f}}const s=(n+z)/Be;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,s),p=c.pow(a,n);for(;!c.eql(p,c.ONE);){if(c.eql(p,c.ZERO))return c.ZERO;let w=1;for(let h=c.sqr(p);w<l&&!c.eql(h,c.ONE);w++)h=c.sqr(h);const g=c.pow(f,z<<BigInt(l-w-1));f=c.sqr(g),u=c.mul(u,g),p=c.mul(p,f),l=w}return u}}function Ji(e){if(e%$t===Zi){const t=(e+z)/$t;return function(r,i){const s=r.pow(i,t);if(!r.eql(r.sqr(s),i))throw new Error("Cannot find square root");return s}}if(e%Mn===On){const t=(e-On)/Mn;return function(r,i){const s=r.mul(i,Be),o=r.pow(s,t),c=r.mul(i,o),a=r.mul(r.mul(c,Be),o),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 Fi(e)}const Yi=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Xi(e){const t={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},n=Yi.reduce((r,i)=>(r[i]="function",r),t);return Fe(e,n)}function Qi(e,t,n){if(n<W)throw new Error("Expected power > 0");if(n===W)return e.ONE;if(n===z)return t;let r=e.ONE,i=t;for(;n>W;)n&z&&(r=e.mul(r,i)),i=e.sqr(i),n>>=z;return r}function es(e,t){const n=new Array(t.length),r=t.reduce((s,o,c)=>e.is0(o)?s:(n[c]=s,e.mul(s,o)),e.ONE),i=e.inv(r);return t.reduceRight((s,o,c)=>e.is0(o)?s:(n[c]=e.mul(s,n[c]),e.mul(s,o)),i),n}function Pn(e,t){const n=t!==void 0?t:e.toString(2).length,r=Math.ceil(n/8);return{nBitLength:n,nByteLength:r}}function ts(e,t,n=!1,r={}){if(e<=W)throw new Error(`Expected Field ORDER > 0, got ${e}`);const{nBitLength:i,nByteLength:s}=Pn(e,t);if(s>2048)throw new Error("Field lengths over 2048 bytes are not supported");const o=Ji(e),c=Object.freeze({ORDER:e,BITS:i,BYTES:s,MASK:Ut(i),ZERO:W,ONE:z,create:a=>Z(a,e),isValid:a=>{if(typeof a!="bigint")throw new Error(`Invalid field element: expected bigint, got ${typeof a}`);return W<=a&&a<e},is0:a=>a===W,isOdd:a=>(a&z)===z,neg:a=>Z(-a,e),eql:(a,l)=>a===l,sqr:a=>Z(a*a,e),add:(a,l)=>Z(a+l,e),sub:(a,l)=>Z(a-l,e),mul:(a,l)=>Z(a*l,e),pow:(a,l)=>Qi(c,a,l),div:(a,l)=>Z(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=>o(c,a)),invertBatch:a=>es(c,a),cmov:(a,l,f)=>f?l:a,toBytes:a=>n?_t(a,s):me(a,s),fromBytes:a=>{if(a.length!==s)throw new Error(`Fp.fromBytes: expected ${s}, got ${a.length}`);return n?Bt(a):Y(a)}});return Object.freeze(c)}function Hn(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 Dn(e){const t=Hn(e);return t+Math.ceil(t/2)}function ns(e,t,n=!1){const r=e.length,i=Hn(t),s=Dn(t);if(r<16||r<s||r>1024)throw new Error(`expected ${s}-1024 bytes of input, got ${r}`);const o=n?Y(e):Bt(e),c=Z(o,t-z)+z;return n?_t(c,i):me(c,i)}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const rs=BigInt(0),Rt=BigInt(1);function is(e,t){const n=(i,s)=>{const o=s.negate();return i?o:s},r=i=>{const s=Math.ceil(t/i)+1,o=2**(i-1);return{windows:s,windowSize:o}};return{constTimeNegate:n,unsafeLadder(i,s){let o=e.ZERO,c=i;for(;s>rs;)s&Rt&&(o=o.add(c)),c=c.double(),s>>=Rt;return o},precomputeWindow(i,s){const{windows:o,windowSize:c}=r(s),a=[];let l=i,f=l;for(let u=0;u<o;u++){f=l,a.push(f);for(let p=1;p<c;p++)f=f.add(l),a.push(f);l=f.double()}return a},wNAF(i,s,o){const{windows:c,windowSize:a}=r(i);let l=e.ZERO,f=e.BASE;const u=BigInt(2**i-1),p=2**i,w=BigInt(i);for(let g=0;g<c;g++){const h=g*a;let d=Number(o&u);o>>=w,d>a&&(d-=p,o+=Rt);const y=h,m=h+Math.abs(d)-1,S=g%2!==0,_=d<0;d===0?f=f.add(n(S,s[y])):l=l.add(n(_,s[m]))}return{p:l,f}},wNAFCached(i,s,o,c){const a=i._WINDOW_SIZE||1;let l=s.get(i);return l||(l=this.precomputeWindow(i,a),a!==1&&s.set(i,c(l))),this.wNAF(a,l,o)}}}function qn(e){return Xi(e.Fp),Fe(e,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...Pn(e.n,e.nBitLength),...e,p:e.Fp.ORDER})}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function ss(e){const t=qn(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:os,hexToBytes:as}=Wi,_e={Err:class extends Error{constructor(t=""){super(t)}},_parseInt(e){const{Err:t}=_e;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:os(r),l:e.subarray(n+2)}},toSig(e){const{Err:t}=_e,n=typeof e=="string"?as(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:s}=_e._parseInt(n.subarray(2)),{d:o,l:c}=_e._parseInt(s);if(c.length)throw new t("Invalid signature: left bytes after parsing");return{r:i,s:o}},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)),s=r.length/2,o=i.length/2,c=n(s),a=n(o);return`30${n(o+s+4)}02${a}${i}02${c}${r}`}},le=BigInt(0),Q=BigInt(1);BigInt(2);const jn=BigInt(3);BigInt(4);function cs(e){const t=ss(e),{Fp:n}=t,r=t.toBytes||((g,h,d)=>{const y=h.toAffine();return Ie(Uint8Array.from([4]),n.toBytes(y.x),n.toBytes(y.y))}),i=t.fromBytes||(g=>{const h=g.subarray(1),d=n.fromBytes(h.subarray(0,n.BYTES)),y=n.fromBytes(h.subarray(n.BYTES,2*n.BYTES));return{x:d,y}});function s(g){const{a:h,b:d}=t,y=n.sqr(g),m=n.mul(y,g);return n.add(n.add(m,n.mul(g,h)),d)}if(!n.eql(n.sqr(t.Gy),s(t.Gx)))throw new Error("bad generator point: equation left != right");function o(g){return typeof g=="bigint"&&le<g&&g<t.n}function c(g){if(!o(g))throw new Error("Expected valid bigint: 0 < bigint < curve.n")}function a(g){const{allowedPrivateKeyLengths:h,nByteLength:d,wrapPrivateKey:y,n:m}=t;if(h&&typeof g!="bigint"){if(g instanceof Uint8Array&&(g=Me(g)),typeof g!="string"||!h.includes(g.length))throw new Error("Invalid key");g=g.padStart(d*2,"0")}let S;try{S=typeof g=="bigint"?g:Y(G("private key",g,d))}catch{throw new Error(`private key must be ${d} bytes, hex or bigint, not ${typeof g}`)}return y&&(S=Z(S,m)),c(S),S}const l=new Map;function f(g){if(!(g instanceof u))throw new Error("ProjectivePoint expected")}class u{constructor(h,d,y){if(this.px=h,this.py=d,this.pz=y,h==null||!n.isValid(h))throw new Error("x required");if(d==null||!n.isValid(d))throw new Error("y required");if(y==null||!n.isValid(y))throw new Error("z required")}static fromAffine(h){const{x:d,y}=h||{};if(!h||!n.isValid(d)||!n.isValid(y))throw new Error("invalid affine point");if(h instanceof u)throw new Error("projective point not allowed");const m=S=>n.eql(S,n.ZERO);return m(d)&&m(y)?u.ZERO:new u(d,y,n.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(h){const d=n.invertBatch(h.map(y=>y.pz));return h.map((y,m)=>y.toAffine(d[m])).map(u.fromAffine)}static fromHex(h){const d=u.fromAffine(i(G("pointHex",h)));return d.assertValidity(),d}static fromPrivateKey(h){return u.BASE.multiply(a(h))}_setWindowSize(h){this._WINDOW_SIZE=h,l.delete(this)}assertValidity(){if(this.is0()){if(t.allowInfinityPoint&&!n.is0(this.py))return;throw new Error("bad point: ZERO")}const{x:h,y:d}=this.toAffine();if(!n.isValid(h)||!n.isValid(d))throw new Error("bad point: x or y not FE");const y=n.sqr(d),m=s(h);if(!n.eql(y,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:d,py:y,pz:m}=this,{px:S,py:_,pz:k}=h,E=n.eql(n.mul(d,k),n.mul(S,m)),x=n.eql(n.mul(y,k),n.mul(_,m));return E&&x}negate(){return new u(this.px,n.neg(this.py),this.pz)}double(){const{a:h,b:d}=t,y=n.mul(d,jn),{px:m,py:S,pz:_}=this;let k=n.ZERO,E=n.ZERO,x=n.ZERO,K=n.mul(m,m),M=n.mul(S,S),B=n.mul(_,_),A=n.mul(m,S);return A=n.add(A,A),x=n.mul(m,_),x=n.add(x,x),k=n.mul(h,x),E=n.mul(y,B),E=n.add(k,E),k=n.sub(M,E),E=n.add(M,E),E=n.mul(k,E),k=n.mul(A,k),x=n.mul(y,x),B=n.mul(h,B),A=n.sub(K,B),A=n.mul(h,A),A=n.add(A,x),x=n.add(K,K),K=n.add(x,K),K=n.add(K,B),K=n.mul(K,A),E=n.add(E,K),B=n.mul(S,_),B=n.add(B,B),K=n.mul(B,A),k=n.sub(k,K),x=n.mul(B,M),x=n.add(x,x),x=n.add(x,x),new u(k,E,x)}add(h){f(h);const{px:d,py:y,pz:m}=this,{px:S,py:_,pz:k}=h;let E=n.ZERO,x=n.ZERO,K=n.ZERO;const M=t.a,B=n.mul(t.b,jn);let A=n.mul(d,S),T=n.mul(y,_),R=n.mul(m,k),j=n.add(d,y),b=n.add(S,_);j=n.mul(j,b),b=n.add(A,T),j=n.sub(j,b),b=n.add(d,m);let v=n.add(S,k);return b=n.mul(b,v),v=n.add(A,R),b=n.sub(b,v),v=n.add(y,m),E=n.add(_,k),v=n.mul(v,E),E=n.add(T,R),v=n.sub(v,E),K=n.mul(M,b),E=n.mul(B,R),K=n.add(E,K),E=n.sub(T,K),K=n.add(T,K),x=n.mul(E,K),T=n.add(A,A),T=n.add(T,A),R=n.mul(M,R),b=n.mul(B,b),T=n.add(T,R),R=n.sub(A,R),R=n.mul(M,R),b=n.add(b,R),A=n.mul(T,b),x=n.add(x,A),A=n.mul(v,b),E=n.mul(j,E),E=n.sub(E,A),A=n.mul(j,T),K=n.mul(v,K),K=n.add(K,A),new u(E,x,K)}subtract(h){return this.add(h.negate())}is0(){return this.equals(u.ZERO)}wNAF(h){return w.wNAFCached(this,l,h,d=>{const y=n.invertBatch(d.map(m=>m.pz));return d.map((m,S)=>m.toAffine(y[S])).map(u.fromAffine)})}multiplyUnsafe(h){const d=u.ZERO;if(h===le)return d;if(c(h),h===Q)return this;const{endo:y}=t;if(!y)return w.unsafeLadder(this,h);let{k1neg:m,k1:S,k2neg:_,k2:k}=y.splitScalar(h),E=d,x=d,K=this;for(;S>le||k>le;)S&Q&&(E=E.add(K)),k&Q&&(x=x.add(K)),K=K.double(),S>>=Q,k>>=Q;return m&&(E=E.negate()),_&&(x=x.negate()),x=new u(n.mul(x.px,y.beta),x.py,x.pz),E.add(x)}multiply(h){c(h);let d=h,y,m;const{endo:S}=t;if(S){const{k1neg:_,k1:k,k2neg:E,k2:x}=S.splitScalar(d);let{p:K,f:M}=this.wNAF(k),{p:B,f:A}=this.wNAF(x);K=w.constTimeNegate(_,K),B=w.constTimeNegate(E,B),B=new u(n.mul(B.px,S.beta),B.py,B.pz),y=K.add(B),m=M.add(A)}else{const{p:_,f:k}=this.wNAF(d);y=_,m=k}return u.normalizeZ([y,m])[0]}multiplyAndAddUnsafe(h,d,y){const m=u.BASE,S=(k,E)=>E===le||E===Q||!k.equals(m)?k.multiplyUnsafe(E):k.multiply(E),_=S(this,d).add(S(h,y));return _.is0()?void 0:_}toAffine(h){const{px:d,py:y,pz:m}=this,S=this.is0();h==null&&(h=S?n.ONE:n.inv(m));const _=n.mul(d,h),k=n.mul(y,h),E=n.mul(m,h);if(S)return{x:n.ZERO,y:n.ZERO};if(!n.eql(E,n.ONE))throw new Error("invZ was invalid");return{x:_,y:k}}isTorsionFree(){const{h,isTorsionFree:d}=t;if(h===Q)return!0;if(d)return d(u,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){const{h,clearCofactor:d}=t;return h===Q?this:d?d(u,this):this.multiplyUnsafe(t.h)}toRawBytes(h=!0){return this.assertValidity(),r(u,this,h)}toHex(h=!0){return Me(this.toRawBytes(h))}}u.BASE=new u(t.Gx,t.Gy,n.ONE),u.ZERO=new u(n.ZERO,n.ONE,n.ZERO);const p=t.nBitLength,w=is(u,t.endo?Math.ceil(p/2):p);return{CURVE:t,ProjectivePoint:u,normPrivateKeyToScalar:a,weierstrassEquation:s,isWithinCurveOrder:o}}function us(e){const t=qn(e);return Fe(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}function ls(e){const t=us(e),{Fp:n,n:r}=t,i=n.BYTES+1,s=2*n.BYTES+1;function o(b){return le<b&&b<n.ORDER}function c(b){return Z(b,r)}function a(b){return Tt(b,r)}const{ProjectivePoint:l,normPrivateKeyToScalar:f,weierstrassEquation:u,isWithinCurveOrder:p}=cs({...t,toBytes(b,v,N){const I=v.toAffine(),C=n.toBytes(I.x),L=Ie;return N?L(Uint8Array.from([v.hasEvenY()?2:3]),C):L(Uint8Array.from([4]),C,n.toBytes(I.y))},fromBytes(b){const v=b.length,N=b[0],I=b.subarray(1);if(v===i&&(N===2||N===3)){const C=Y(I);if(!o(C))throw new Error("Point is not on curve");const L=u(C);let O=n.sqrt(L);const $=(O&Q)===Q;return(N&1)===1!==$&&(O=n.neg(O)),{x:C,y:O}}else if(v===s&&N===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 ${s} uncompressed bytes`)}}),w=b=>Me(me(b,t.nByteLength));function g(b){const v=r>>Q;return b>v}function h(b){return g(b)?c(-b):b}const d=(b,v,N)=>Y(b.slice(v,N));class y{constructor(v,N,I){this.r=v,this.s=N,this.recovery=I,this.assertValidity()}static fromCompact(v){const N=t.nByteLength;return v=G("compactSignature",v,N*2),new y(d(v,0,N),d(v,N,2*N))}static fromDER(v){const{r:N,s:I}=_e.toSig(G("DER",v));return new y(N,I)}assertValidity(){if(!p(this.r))throw new Error("r must be 0 < r < CURVE.n");if(!p(this.s))throw new Error("s must be 0 < s < CURVE.n")}addRecoveryBit(v){return new y(this.r,this.s,v)}recoverPublicKey(v){const{r:N,s:I,recovery:C}=this,L=x(G("msgHash",v));if(C==null||![0,1,2,3].includes(C))throw new Error("recovery id invalid");const O=C===2||C===3?N+t.n:N;if(O>=n.ORDER)throw new Error("recovery id 2 or 3 invalid");const $=(C&1)===0?"02":"03",re=l.fromHex($+w(O)),Ae=a(O),Ve=c(-L*Ae),tt=c(I*Ae),Ce=l.BASE.multiplyAndAddUnsafe(re,Ve,tt);if(!Ce)throw new Error("point at infinify");return Ce.assertValidity(),Ce}hasHighS(){return g(this.s)}normalizeS(){return this.hasHighS()?new y(this.r,c(-this.s),this.recovery):this}toDERRawBytes(){return Pe(this.toDERHex())}toDERHex(){return _e.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return Pe(this.toCompactHex())}toCompactHex(){return w(this.r)+w(this.s)}}const m={isValidPrivateKey(b){try{return f(b),!0}catch{return!1}},normPrivateKeyToScalar:f,randomPrivateKey:()=>{const b=Dn(t.n);return ns(t.randomBytes(b),t.n)},precompute(b=8,v=l.BASE){return v._setWindowSize(b),v.multiply(BigInt(3)),v}};function S(b,v=!0){return l.fromPrivateKey(b).toRawBytes(v)}function _(b){const v=b instanceof Uint8Array,N=typeof b=="string",I=(v||N)&&b.length;return v?I===i||I===s:N?I===2*i||I===2*s:b instanceof l}function k(b,v,N=!0){if(_(b))throw new Error("first arg must be private key");if(!_(v))throw new Error("second arg must be public key");return l.fromHex(v).multiply(f(b)).toRawBytes(N)}const E=t.bits2int||function(b){const v=Y(b),N=b.length*8-t.nBitLength;return N>0?v>>BigInt(N):v},x=t.bits2int_modN||function(b){return c(E(b))},K=Ut(t.nBitLength);function M(b){if(typeof b!="bigint")throw new Error("bigint expected");if(!(le<=b&&b<K))throw new Error(`bigint expected < 2^${t.nBitLength}`);return me(b,t.nByteLength)}function B(b,v,N=A){if(["recovered","canonical"].some(Oe=>Oe in N))throw new Error("sign() legacy options not supported");const{hash:I,randomBytes:C}=t;let{lowS:L,prehash:O,extraEntropy:$}=N;L==null&&(L=!0),b=G("msgHash",b),O&&(b=G("prehashed msgHash",I(b)));const re=x(b),Ae=f(v),Ve=[M(Ae),M(re)];if($!=null){const Oe=$===!0?C(n.BYTES):$;Ve.push(G("extraEntropy",Oe))}const tt=Ie(...Ve),Ce=re;function In(Oe){const We=E(Oe);if(!p(We))return;const Ki=a(We),Ze=l.BASE.multiply(We).toAffine(),ie=c(Ze.x);if(ie===le)return;const Ge=c(Ki*c(Ce+ie*Ae));if(Ge===le)return;let Ni=(Ze.x===ie?0:2)|Number(Ze.y&Q),Si=Ge;return L&&g(Ge)&&(Si=h(Ge),Ni^=1),new y(ie,Si,Ni)}return{seed:tt,k2sig:In}}const A={lowS:t.lowS,prehash:!1},T={lowS:t.lowS,prehash:!1};function R(b,v,N=A){const{seed:I,k2sig:C}=B(b,v,N),L=t;return Rn(L.hash.outputLen,L.nByteLength,L.hmac)(I,C)}l.BASE._setWindowSize(8);function j(b,v,N,I=T){var Ze;const C=b;if(v=G("msgHash",v),N=G("publicKey",N),"strict"in I)throw new Error("options.strict was renamed to lowS");const{lowS:L,prehash:O}=I;let $,re;try{if(typeof C=="string"||C instanceof Uint8Array)try{$=y.fromDER(C)}catch(ie){if(!(ie instanceof _e.Err))throw ie;$=y.fromCompact(C)}else if(typeof C=="object"&&typeof C.r=="bigint"&&typeof C.s=="bigint"){const{r:ie,s:Ge}=C;$=new y(ie,Ge)}else throw new Error("PARSE");re=l.fromHex(N)}catch(ie){if(ie.message==="PARSE")throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(L&&$.hasHighS())return!1;O&&(v=t.hash(v));const{r:Ae,s:Ve}=$,tt=x(v),Ce=a(Ve),In=c(tt*Ce),Oe=c(Ae*Ce),We=(Ze=l.BASE.multiplyAndAddUnsafe(re,In,Oe))==null?void 0:Ze.toAffine();return We?c(We.x)===Ae:!1}return{CURVE:t,getPublicKey:S,getSharedSecret:k,sign:R,verify:j,ProjectivePoint:l,Signature:y,utils:m}}let zn=class extends _n{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,s=new Uint8Array(i);s.set(r.length>i?t.create().update(r).digest():r);for(let o=0;o<s.length;o++)s[o]^=54;this.iHash.update(s),this.oHash=t.create();for(let o=0;o<s.length;o++)s[o]^=106;this.oHash.update(s),s.fill(0)}update(t){return nt(this),this.iHash.update(t),this}digestInto(t){nt(this),ke(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:s,blockLen:o,outputLen:c}=this;return t=t,t.finished=i,t.destroyed=s,t.blockLen=o,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 Vn=(e,t,n)=>new zn(e,t).update(n).digest();Vn.create=(e,t)=>new zn(e,t);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function fs(e){return{hash:e,hmac:(t,...n)=>Vn(e,t,Ii(...n)),randomBytes:Un}}function hs(e,t){const n=r=>ls({...e,...fs(r)});return Object.freeze({...n(t),create:n})}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const st=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),ot=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),Wn=BigInt(1),at=BigInt(2),Zn=(e,t)=>(e+t/at)/t;function Gn(e){const t=st,n=BigInt(3),r=BigInt(6),i=BigInt(11),s=BigInt(22),o=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,p=X(u,n,t)*f%t,w=X(p,at,t)*l%t,g=X(w,i,t)*w%t,h=X(g,s,t)*g%t,d=X(h,c,t)*h%t,y=X(d,a,t)*d%t,m=X(y,c,t)*h%t,S=X(m,n,t)*f%t,_=X(S,o,t)*g%t,k=X(_,r,t)*l%t,E=X(k,at,t);if(!Ot.eql(Ot.sqr(E),e))throw new Error("Cannot find square root");return E}const Ot=ts(st,void 0,void 0,{sqrt:Gn}),Ue=hs({a:BigInt(0),b:BigInt(7),Fp:Ot,n:ot,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:e=>{const t=ot,n=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),r=-Wn*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),i=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),s=n,o=BigInt("0x100000000000000000000000000000000"),c=Zn(s*e,t),a=Zn(-r*e,t);let l=Z(e-c*n-a*i,t),f=Z(-c*r-a*s,t);const u=l>o,p=f>o;if(u&&(l=t-l),p&&(f=t-f),l>o||f>o)throw new Error("splitScalar: Endomorphism failed, k="+e);return{k1neg:u,k1:l,k2neg:p,k2:f}}}},kt),ct=BigInt(0),Fn=e=>typeof e=="bigint"&&ct<e&&e<st,ds=e=>typeof e=="bigint"&&ct<e&&e<ot,Jn={};function ut(e,...t){let n=Jn[e];if(n===void 0){const r=kt(Uint8Array.from(e,i=>i.charCodeAt(0)));n=Ie(r,r),Jn[e]=n}return kt(Ie(n,...t))}const Mt=e=>e.toRawBytes(!0).slice(1),Pt=e=>me(e,32),Ht=e=>Z(e,st),Je=e=>Z(e,ot),Dt=Ue.ProjectivePoint,ys=(e,t,n)=>Dt.BASE.multiplyAndAddUnsafe(e,t,n);function qt(e){let t=Ue.utils.normPrivateKeyToScalar(e),n=Dt.fromPrivateKey(t);return{scalar:n.hasEvenY()?t:Je(-t),bytes:Mt(n)}}function Yn(e){if(!Fn(e))throw new Error("bad x: need 0 < x < p");const t=Ht(e*e),n=Ht(t*e+BigInt(7));let r=Gn(n);r%at!==ct&&(r=Ht(-r));const i=new Dt(e,r,Wn);return i.assertValidity(),i}function Xn(...e){return Je(Y(ut("BIP0340/challenge",...e)))}function ps(e){return qt(e).bytes}function gs(e,t,n=Un(32)){const r=G("message",e),{bytes:i,scalar:s}=qt(t),o=G("auxRand",n,32),c=Pt(s^Y(ut("BIP0340/aux",o))),a=ut("BIP0340/nonce",c,i,r),l=Je(Y(a));if(l===ct)throw new Error("sign failed: k is zero");const{bytes:f,scalar:u}=qt(l),p=Xn(f,i,r),w=new Uint8Array(64);if(w.set(f,0),w.set(Pt(Je(u+p*s)),32),!Qn(w,r,i))throw new Error("sign: Invalid signature produced");return w}function Qn(e,t,n){const r=G("signature",e,64),i=G("message",t),s=G("publicKey",n,32);try{const o=Yn(Y(s)),c=Y(r.subarray(0,32));if(!Fn(c))return!1;const a=Y(r.subarray(32,64));if(!ds(a))return!1;const l=Xn(Pt(c),Mt(o),i),f=ys(o,a,Je(-l));return!(!f||!f.hasEvenY()||f.toAffine().x!==c)}catch{return!1}}const Ye={getPublicKey:ps,sign:gs,verify:Qn,utils:{randomPrivateKey:Ue.utils.randomPrivateKey,lift_x:Yn,pointToBytes:Mt,numberToBytesBE:me,bytesToNumberBE:Y,taggedHash:ut,mod:Z}},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 ws=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function H(e){if(!zt(e))throw new Error("Uint8Array expected");let t="";for(let n=0;n<e.length;n++)t+=ws[e[n]];return t}function V(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,s=e.slice(i,i+2),o=Number.parseInt(s,16);if(Number.isNaN(o)||o<0)throw new Error("Invalid byte sequence");n[r]=o}return n}function bs(e){if(typeof e!="string")throw new Error(`utf8ToBytes expected string, got ${typeof e}`);return new Uint8Array(new TextEncoder().encode(e))}function Xe(e){if(typeof e=="string"&&(e=bs(e)),!zt(e))throw new Error(`expected Uint8Array, got ${typeof e}`);return e}function lt(...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 er{clone(){return this._cloneInto()}}function tr(e){const t=r=>e().update(Xe(r)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function nr(e=32){if(jt&&typeof jt.getRandomValues=="function")return jt.getRandomValues(new Uint8Array(e));throw new Error("crypto.getRandomValues must be defined")}function Wt(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`Wrong positive integer: ${e}`)}function vs(e){if(typeof e!="boolean")throw new Error(`Expected boolean, not ${e}`)}function rr(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 ms(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");Wt(e.outputLen),Wt(e.blockLen)}function Es(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 xs(e,t){rr(e);const n=t.outputLen;if(e.length<n)throw new Error(`digestInto() expects output buffer of length at least ${n}`)}const ae={number:Wt,bool:vs,bytes:rr,hash:ms,exists:Es,output:xs};function Ks(e,t,n,r){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,n,r);const i=BigInt(32),s=BigInt(4294967295),o=Number(n>>i&s),c=Number(n&s),a=r?4:0,l=r?0:4;e.setUint32(t+a,o,r),e.setUint32(t+l,c,r)}class Ns extends er{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){ae.exists(this);const{view:n,buffer:r,blockLen:i}=this;t=Xe(t);const s=t.length;for(let o=0;o<s;){const c=Math.min(i-this.pos,s-o);if(c===i){const a=Vt(t);for(;i<=s-o;o+=i)this.process(a,o);continue}r.set(t.subarray(o,o+c),this.pos),this.pos+=c,o+=c,this.pos===i&&(this.process(n,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){ae.exists(this),ae.output(t,this),this.finished=!0;const{buffer:n,view:r,blockLen:i,isLE:s}=this;let{pos:o}=this;n[o++]=128,this.buffer.subarray(o).fill(0),this.padOffset>i-o&&(this.process(r,0),o=0);for(let u=o;u<i;u++)n[u]=0;Ks(r,i-8,BigInt(this.length*8),s),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],s)}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:s,destroyed:o,pos:c}=this;return t.length=i,t.pos=c,t.finished=s,t.destroyed=o,i%n&&t.buffer.set(r),t}}const Ss=(e,t,n)=>e&t^~e&n,As=(e,t,n)=>e&t^e&n^t&n,Cs=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]),Ee=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),xe=new Uint32Array(64);class ir extends Ns{constructor(){super(64,32,8,!1),this.A=Ee[0]|0,this.B=Ee[1]|0,this.C=Ee[2]|0,this.D=Ee[3]|0,this.E=Ee[4]|0,this.F=Ee[5]|0,this.G=Ee[6]|0,this.H=Ee[7]|0}get(){const{A:t,B:n,C:r,D:i,E:s,F:o,G:c,H:a}=this;return[t,n,r,i,s,o,c,a]}set(t,n,r,i,s,o,c,a){this.A=t|0,this.B=n|0,this.C=r|0,this.D=i|0,this.E=s|0,this.F=o|0,this.G=c|0,this.H=a|0}process(t,n){for(let u=0;u<16;u++,n+=4)xe[u]=t.getUint32(n,!1);for(let u=16;u<64;u++){const p=xe[u-15],w=xe[u-2],g=oe(p,7)^oe(p,18)^p>>>3,h=oe(w,17)^oe(w,19)^w>>>10;xe[u]=h+xe[u-7]+g+xe[u-16]|0}let{A:r,B:i,C:s,D:o,E:c,F:a,G:l,H:f}=this;for(let u=0;u<64;u++){const p=oe(c,6)^oe(c,11)^oe(c,25),w=f+p+Ss(c,a,l)+Cs[u]+xe[u]|0,h=(oe(r,2)^oe(r,13)^oe(r,22))+As(r,i,s)|0;f=l,l=a,a=c,c=o+w|0,o=s,s=i,i=r,r=w+h|0}r=r+this.A|0,i=i+this.B|0,s=s+this.C|0,o=o+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,s,o,c,a,l,f)}roundClean(){xe.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}}class ks extends ir{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 fe=tr(()=>new ir);tr(()=>new ks);/*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) */function He(e){if(!Number.isSafeInteger(e))throw new Error(`Wrong integer: ${e}`)}function he(...e){const t=(i,s)=>o=>i(s(o)),n=Array.from(e).reverse().reduce((i,s)=>i?t(i,s.encode):s.encode,void 0),r=e.reduce((i,s)=>i?t(i,s.decode):s.decode,void 0);return{encode:n,decode:r}}function de(e){return{encode:t=>{if(!Array.isArray(t)||t.length&&typeof t[0]!="number")throw new Error("alphabet.encode input should be an array of numbers");return t.map(n=>{if(He(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 ye(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 ft(e,t="="){if(He(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 sr(e){if(typeof e!="function")throw new Error("normalize fn should be function");return{encode:t=>t,decode:t=>e(t)}}function or(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=[],s=Array.from(e);for(s.forEach(o=>{if(He(o),o<0||o>=t)throw new Error(`Wrong integer: ${o}`)});;){let o=0,c=!0;for(let a=r;a<s.length;a++){const l=s[a],f=t*o+l;if(!Number.isSafeInteger(f)||t*o/t!==o||f-l!==t*o)throw new Error("convertRadix: carry overflow");if(o=f%n,s[a]=Math.floor(f/n),!Number.isSafeInteger(s[a])||s[a]*n+o!==f)throw new Error("convertRadix: carry overflow");if(c)s[a]?c=!1:r=a;else continue}if(i.push(o),c)break}for(let o=0;o<e.length-1&&e[o]===0;o++)i.push(0);return i.reverse()}const ar=(e,t)=>t?ar(t,e%t):e,ht=(e,t)=>e+(t-ar(e,t));function Zt(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(ht(t,n)>32)throw new Error(`convertRadix2: carry overflow from=${t} to=${n} carryBits=${ht(t,n)}`);let i=0,s=0;const o=2**n-1,c=[];for(const a of e){if(He(a),a>=2**t)throw new Error(`convertRadix2: invalid data word=${a} from=${t}`);if(i=i<<t|a,s+t>32)throw new Error(`convertRadix2: carry overflow pos=${s} from=${t}`);for(s+=t;s>=n;s-=n)c.push((i>>s-n&o)>>>0);i&=2**s-1}if(i=i<<n-s&o,!r&&s>=t)throw new Error("Excess padding");if(!r&&i)throw new Error(`Non-zero padding: ${i}`);return r&&s>0&&c.push(i>>>0),c}function Is(e){return He(e),{encode:t=>{if(!(t instanceof Uint8Array))throw new Error("radix.encode input should be Uint8Array");return or(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(or(t,e,2**8))}}}function Ke(e,t=!1){if(He(e),e<=0||e>32)throw new Error("radix2: bits should be in (0..32]");if(ht(8,e)>32||ht(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 Zt(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(Zt(n,e,8,t))}}}function cr(e){if(typeof e!="function")throw new Error("unsafeWrapper fn should be function");return function(...t){try{return e.apply(null,t)}catch{}}}const Bs=he(Ke(4),de("0123456789ABCDEF"),ye("")),_s=he(Ke(5),de("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"),ft(5),ye(""));he(Ke(5),de("0123456789ABCDEFGHIJKLMNOPQRSTUV"),ft(5),ye("")),he(Ke(5),de("0123456789ABCDEFGHJKMNPQRSTVWXYZ"),ye(""),sr(e=>e.toUpperCase().replace(/O/g,"0").replace(/[IL]/g,"1")));const pe=he(Ke(6),de("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),ft(6),ye("")),Us=he(Ke(6),de("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"),ft(6),ye("")),Gt=e=>he(Is(58),de(e),ye("")),Ft=Gt("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");Gt("123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"),Gt("rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz");const ur=[0,2,3,5,6,7,9,10,11],Ls={encode(e){let t="";for(let n=0;n<e.length;n+=8){const r=e.subarray(n,n+8);t+=Ft.encode(r).padStart(ur[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=ur.indexOf(r.length),s=Ft.decode(r);for(let o=0;o<s.length-i;o++)if(s[o]!==0)throw new Error("base58xmr: wrong padding");t=t.concat(Array.from(s.slice(s.length-i)))}return Uint8Array.from(t)}},Jt=he(de("qpzry9x8gf2tvdw0s3jn54khce6mua7l"),ye("")),lr=[996825010,642813549,513874426,1027748829,705979059];function Qe(e){const t=e>>25;let n=(e&33554431)<<5;for(let r=0;r<lr.length;r++)(t>>r&1)===1&&(n^=lr[r]);return n}function fr(e,t,n=1){const r=e.length;let i=1;for(let s=0;s<r;s++){const o=e.charCodeAt(s);if(o<33||o>126)throw new Error(`Invalid prefix (${e})`);i=Qe(i)^o>>5}i=Qe(i);for(let s=0;s<r;s++)i=Qe(i)^e.charCodeAt(s)&31;for(let s of t)i=Qe(i)^s;for(let s=0;s<6;s++)i=Qe(i);return i^=n,Jt.encode(Zt([i%2**30],30,5,!1))}function hr(e){const t=e==="bech32"?1:734539939,n=Ke(5),r=n.decode,i=n.encode,s=cr(r);function o(f,u,p=90){if(typeof f!="string")throw new Error(`bech32.encode prefix should be string, not ${typeof f}`);if(!Array.isArray(u)||u.length&&typeof u[0]!="number")throw new Error(`bech32.encode words should be array of numbers, not ${typeof u}`);const w=f.length+7+u.length;if(p!==!1&&w>p)throw new TypeError(`Length ${w} exceeds limit ${p}`);return f=f.toLowerCase(),`${f}1${Jt.encode(u)}${fr(f,u,t)}`}function c(f,u=90){if(typeof f!="string")throw new Error(`bech32.decode input should be string, not ${typeof f}`);if(f.length<8||u!==!1&&f.length>u)throw new TypeError(`Wrong string length: ${f.length} (${f}). Expected (8..${u})`);const p=f.toLowerCase();if(f!==p&&f!==f.toUpperCase())throw new Error("String must be lowercase or uppercase");f=p;const w=f.lastIndexOf("1");if(w===0||w===-1)throw new Error('Letter "1" must be present between prefix and data only');const g=f.slice(0,w),h=f.slice(w+1);if(h.length<6)throw new Error("Data must be at least 6 characters long");const d=Jt.decode(h).slice(0,-6),y=fr(g,d,t);if(!h.endsWith(y))throw new Error(`Invalid checksum in ${f}: expected "${y}"`);return{prefix:g,words:d}}const a=cr(c);function l(f){const{prefix:u,words:p}=c(f,!1);return{prefix:u,words:p,bytes:r(p)}}return{encode:o,decode:c,decodeToBytes:l,decodeUnsafe:a,fromWords:r,fromWordsUnsafe:s,toWords:i}}const De=hr("bech32");hr("bech32m");const $s={encode:e=>new TextDecoder().decode(e),decode:e=>new TextEncoder().encode(e)},Ts=he(Ke(4),de("0123456789abcdef"),ye(""),sr(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:$s,hex:Ts,base16:Bs,base32:_s,base64:pe,base64url:Us,base58:Ft,base58xmr:Ls}).join(", ")}`;function Yt(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`positive integer expected, not ${e}`)}function dr(e){if(typeof e!="boolean")throw new Error(`boolean expected, not ${e}`)}function Rs(e){return e instanceof Uint8Array||e!=null&&typeof e=="object"&&e.constructor.name==="Uint8Array"}function ge(e,...t){if(!Rs(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 F=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 Os(e,t){if(t==null||typeof t!="object")throw new Error("options must be defined");return Object.assign(e,t)}function Ms(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 Ps=(e,t)=>(Object.assign(t,e),t),Ne=16,Hs=283;function Xt(e){return e<<1^Hs&-(e>>7)}function qe(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})(),Ds=Qt.map((e,t)=>Qt.indexOf(t)),qs=e=>e<<24|e>>>8,en=e=>e<<8|e>>>24;function yr(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),s=i.map(en),o=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;o[u]=n[l]^r[f],c[u]=i[l]^s[f],a[u]=e[l]<<8|e[f]}return{sbox:e,sbox2:a,T0:n,T1:r,T2:i,T3:s,T01:o,T23:c}}const tn=yr(Qt,e=>qe(e,3)<<24|e<<16|e<<8|qe(e,2)),pr=yr(Ds,e=>qe(e,11)<<24|qe(e,13)<<16|qe(e,9)<<8|qe(e,14)),js=(()=>{const e=new Uint8Array(16);for(let t=0,n=1;t<16;t++,n=Xt(n))e[t]=n;return e})();function gr(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=F(e),i=r.length,s=c=>ce(n,c,c,c,c),o=new Uint32Array(t+28);o.set(r);for(let c=i;c<o.length;c++){let a=o[c-1];c%i===0?a=s(qs(a))^js[c/i-1]:i>6&&c%i===4&&(a=s(a)),o[c]=o[c-i]^a}return o}function zs(e){const t=gr(e),n=t.slice(),r=t.length,{sbox2:i}=tn,{T0:s,T1:o,T2:c,T3:a}=pr;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=ce(i,f,f,f,f);n[l]=s[u&255]^o[u>>>8&255]^c[u>>>16&255]^a[u>>>24]}return n}function Se(e,t,n,r,i,s){return e[n<<8&65280|r>>>8&255]^t[i>>>8&65280|s>>>24&255]}function ce(e,t,n,r,i){return e[t&255|n&65280]|e[r>>>16&255|i>>>16&65280]<<16}function wr(e,t,n,r,i){const{sbox2:s,T01:o,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 g=0;g<l;g++){const h=e[a++]^Se(o,c,t,n,r,i),d=e[a++]^Se(o,c,n,r,i,t),y=e[a++]^Se(o,c,r,i,t,n),m=e[a++]^Se(o,c,i,t,n,r);t=h,n=d,r=y,i=m}const f=e[a++]^ce(s,t,n,r,i),u=e[a++]^ce(s,n,r,i,t),p=e[a++]^ce(s,r,i,t,n),w=e[a++]^ce(s,i,t,n,r);return{s0:f,s1:u,s2:p,s3:w}}function Vs(e,t,n,r,i){const{sbox2:s,T01:o,T23:c}=pr;let a=0;t^=e[a++],n^=e[a++],r^=e[a++],i^=e[a++];const l=e.length/4-2;for(let g=0;g<l;g++){const h=e[a++]^Se(o,c,t,i,r,n),d=e[a++]^Se(o,c,n,t,i,r),y=e[a++]^Se(o,c,r,n,t,i),m=e[a++]^Se(o,c,i,r,n,t);t=h,n=d,r=y,i=m}const f=e[a++]^ce(s,t,i,r,n),u=e[a++]^ce(s,n,t,i,r),p=e[a++]^ce(s,r,n,t,i),w=e[a++]^ce(s,i,r,n,t);return{s0:f,s1:u,s2:p,s3:w}}function br(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 Ws(e){if(ge(e),e.length%Ne!==0)throw new Error(`aes/(cbc-ecb).decrypt ciphertext should consist of blocks with size ${Ne}`)}function Zs(e,t,n){let r=e.length;const i=r%Ne;if(!t&&i!==0)throw new Error("aec/(cbc-ecb): unpadded plaintext with disabled padding");const s=F(e);if(t){let a=Ne-i;a||(a=Ne),r=r+a}const o=br(r,n),c=F(o);return{b:s,o:c,out:o}}function Gs(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 s=0;s<r;s++)if(e[n-s-1]!==r)throw new Error("aes/pcks5: wrong padding");return i}function Fs(e){const t=new Uint8Array(16),n=F(t);t.set(e);const r=Ne-e.length;for(let i=Ne-r;i<Ne;i++)t[i]=r;return n}const vr=Ps({blockSize:16,nonceLength:16},function(t,n,r={}){ge(t),ge(n,16);const i=!r.disablePadding;return{encrypt:(s,o)=>{const c=gr(t),{b:a,o:l,out:f}=Zs(s,i,o),u=F(n);let p=u[0],w=u[1],g=u[2],h=u[3],d=0;for(;d+4<=a.length;)p^=a[d+0],w^=a[d+1],g^=a[d+2],h^=a[d+3],{s0:p,s1:w,s2:g,s3:h}=wr(c,p,w,g,h),l[d++]=p,l[d++]=w,l[d++]=g,l[d++]=h;if(i){const y=Fs(s.subarray(d*4));p^=y[0],w^=y[1],g^=y[2],h^=y[3],{s0:p,s1:w,s2:g,s3:h}=wr(c,p,w,g,h),l[d++]=p,l[d++]=w,l[d++]=g,l[d++]=h}return c.fill(0),f},decrypt:(s,o)=>{Ws(s);const c=zs(t),a=F(n),l=br(s.length,o),f=F(s),u=F(l);let p=a[0],w=a[1],g=a[2],h=a[3];for(let d=0;d+4<=f.length;){const y=p,m=w,S=g,_=h;p=f[d+0],w=f[d+1],g=f[d+2],h=f[d+3];const{s0:k,s1:E,s2:x,s3:K}=Vs(c,p,w,g,h);u[d++]=k^y,u[d++]=E^m,u[d++]=x^S,u[d++]=K^_}return c.fill(0),Gs(l,i)}}}),mr=e=>Uint8Array.from(e.split("").map(t=>t.charCodeAt(0))),Js=mr("expand 16-byte k"),Ys=mr("expand 32-byte k"),Xs=F(Js),Er=F(Ys);Er.slice();function U(e,t){return e<<t|e>>>32-t}function nn(e){return e.byteOffset%4===0}const dt=64,Qs=16,xr=2**32-1,Kr=new Uint32Array;function eo(e,t,n,r,i,s,o,c){const a=i.length,l=new Uint8Array(dt),f=F(l),u=nn(i)&&nn(s),p=u?F(i):Kr,w=u?F(s):Kr;for(let g=0;g<a;o++){if(e(t,n,r,f,o,c),o>=xr)throw new Error("arx: counter overflow");const h=Math.min(dt,a-g);if(u&&h===dt){const d=g/4;if(g%4!==0)throw new Error("arx: invalid block position");for(let y=0,m;y<Qs;y++)m=d+y,w[m]=p[m]^f[y];g+=dt;continue}for(let d=0,y;d<h;d++)y=g+d,s[y]=i[y]^l[d];g+=h}}function to(e,t){const{allowShortKeys:n,extendNonceFn:r,counterLength:i,counterRight:s,rounds:o}=Os({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(o),dr(s),dr(n),(c,a,l,f,u=0)=>{ge(c),ge(a),ge(l);const p=l.length;if(f||(f=new Uint8Array(p)),ge(f),Yt(u),u<0||u>=xr)throw new Error("arx: counter overflow");if(f.length<p)throw new Error(`arx: output (${f.length}) is shorter than data (${p})`);const w=[];let g=c.length,h,d;if(g===32)h=c.slice(),w.push(h),d=Er;else if(g===16&&n)h=new Uint8Array(32),h.set(c),h.set(c,16),d=Xs,w.push(h);else throw new Error(`arx: invalid 32-byte key, got length=${g}`);nn(a)||(a=a.slice(),w.push(a));const y=F(h);if(r){if(a.length!==24)throw new Error("arx: extended nonce must be 24 bytes");r(d,y,F(a.subarray(0,16)),y),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 _=new Uint8Array(12);_.set(a,s?0:12-a.length),a=_,w.push(a)}const S=F(a);for(eo(e,d,y,S,l,f,u,o);w.length>0;)w.pop().fill(0);return f}}function no(e,t,n,r,i,s=20){let o=e[0],c=e[1],a=e[2],l=e[3],f=t[0],u=t[1],p=t[2],w=t[3],g=t[4],h=t[5],d=t[6],y=t[7],m=i,S=n[0],_=n[1],k=n[2],E=o,x=c,K=a,M=l,B=f,A=u,T=p,R=w,j=g,b=h,v=d,N=y,I=m,C=S,L=_,O=k;for(let re=0;re<s;re+=2)E=E+B|0,I=U(I^E,16),j=j+I|0,B=U(B^j,12),E=E+B|0,I=U(I^E,8),j=j+I|0,B=U(B^j,7),x=x+A|0,C=U(C^x,16),b=b+C|0,A=U(A^b,12),x=x+A|0,C=U(C^x,8),b=b+C|0,A=U(A^b,7),K=K+T|0,L=U(L^K,16),v=v+L|0,T=U(T^v,12),K=K+T|0,L=U(L^K,8),v=v+L|0,T=U(T^v,7),M=M+R|0,O=U(O^M,16),N=N+O|0,R=U(R^N,12),M=M+R|0,O=U(O^M,8),N=N+O|0,R=U(R^N,7),E=E+A|0,O=U(O^E,16),v=v+O|0,A=U(A^v,12),E=E+A|0,O=U(O^E,8),v=v+O|0,A=U(A^v,7),x=x+T|0,I=U(I^x,16),N=N+I|0,T=U(T^N,12),x=x+T|0,I=U(I^x,8),N=N+I|0,T=U(T^N,7),K=K+R|0,C=U(C^K,16),j=j+C|0,R=U(R^j,12),K=K+R|0,C=U(C^K,8),j=j+C|0,R=U(R^j,7),M=M+B|0,L=U(L^M,16),b=b+L|0,B=U(B^b,12),M=M+B|0,L=U(L^M,8),b=b+L|0,B=U(B^b,7);let $=0;r[$++]=o+E|0,r[$++]=c+x|0,r[$++]=a+K|0,r[$++]=l+M|0,r[$++]=f+B|0,r[$++]=u+A|0,r[$++]=p+T|0,r[$++]=w+R|0,r[$++]=g+j|0,r[$++]=h+b|0,r[$++]=d+v|0,r[$++]=y+N|0,r[$++]=m+I|0,r[$++]=S+C|0,r[$++]=_+L|0,r[$++]=k+O|0}const Nr=to(no,{counterRight:!1,counterLength:4,allowShortKeys:!1});class Sr extends er{constructor(t,n){super(),this.finished=!1,this.destroyed=!1,ae.hash(t);const r=Xe(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,s=new Uint8Array(i);s.set(r.length>i?t.create().update(r).digest():r);for(let o=0;o<s.length;o++)s[o]^=54;this.iHash.update(s),this.oHash=t.create();for(let o=0;o<s.length;o++)s[o]^=106;this.oHash.update(s),s.fill(0)}update(t){return ae.exists(this),this.iHash.update(t),this}digestInto(t){ae.exists(this),ae.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:s,blockLen:o,outputLen:c}=this;return t=t,t.finished=i,t.destroyed=s,t.blockLen=o,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 yt=(e,t,n)=>new Sr(e,t).update(n).digest();yt.create=(e,t)=>new Sr(e,t);function rn(e,t,n){return ae.hash(e),n===void 0&&(n=new Uint8Array(e.outputLen)),yt(e,Xe(n),Xe(t))}const sn=new Uint8Array([0]),Ar=new Uint8Array;function Cr(e,t,n,r=32){if(ae.hash(e),ae.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=Ar);const s=new Uint8Array(i*e.outputLen),o=yt.create(e,t),c=o._cloneInto(),a=new Uint8Array(o.outputLen);for(let l=0;l<i;l++)sn[0]=l+1,c.update(l===0?Ar:a).update(n).update(sn).digestInto(a),s.set(a,e.outputLen*l),o._cloneInto(c);return o.destroy(),c.destroy(),a.fill(0),sn.fill(0),s.slice(0,r)}var ro=Object.defineProperty,D=(e,t)=>{for(var n in t)ro(e,n,{get:t[n],enumerable:!0})},je=Symbol("verified"),io=e=>e instanceof Object;function pt(e){if(!io(e)||typeof e.kind!="number"||typeof e.content!="string"||typeof e.created_at!="number"||typeof e.pubkey!="string"||!e.pubkey.match(/^[a-f0-9]{64}$/)||!Array.isArray(e.tags))return!1;for(let t=0;t<e.tags.length;t++){let n=e.tags[t];if(!Array.isArray(n))return!1;for(let r=0;r<n.length;r++)if(typeof n[r]!="string")return!1}return!0}var so={};D(so,{Queue:()=>uo,QueueNode:()=>kr,binarySearch:()=>on,bytesToHex:()=>H,hexToBytes:()=>V,insertEventIntoAscendingList:()=>co,insertEventIntoDescendingList:()=>ao,normalizeURL:()=>oo,utf8Decoder:()=>we,utf8Encoder:()=>ne});var we=new TextDecoder("utf-8"),ne=new TextEncoder;function oo(e){try{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()}catch{throw new Error(`Invalid URL: ${e}`)}}function ao(e,t){const[n,r]=on(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 co(e,t){const[n,r]=on(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 on(e,t){let n=0,r=e.length-1;for(;n<=r;){const i=Math.floor((n+r)/2),s=t(e[i]);if(s===0)return[i,!0];s<0?r=i-1:n=i+1}return[n,!1]}var kr=class{constructor(e){te(this,"value");te(this,"next",null);te(this,"prev",null);this.value=e}},uo=class{constructor(){te(this,"first");te(this,"last");this.first=null,this.last=null}enqueue(e){const t=new kr(e);return this.last?this.last===this.first?(this.last=t,this.last.prev=this.first,this.first.next=t):(t.prev=this.last,this.last.next=t,this.last=t):(this.first=t,this.last=t),!0}dequeue(){if(!this.first)return null;if(this.first===this.last){const t=this.first;return this.first=null,this.last=null,t.value}const e=this.first;return this.first=e.next,this.first&&(this.first.prev=null),e.value}},lo=class{generateSecretKey(){return Ye.utils.randomPrivateKey()}getPublicKey(e){return H(Ye.getPublicKey(e))}finalizeEvent(e,t){const n=e;return n.pubkey=H(Ye.getPublicKey(t)),n.id=ze(n),n.sig=H(Ye.sign(ze(n),t)),n[je]=!0,n}verifyEvent(e){if(typeof e[je]=="boolean")return e[je];const t=ze(e);if(t!==e.id)return e[je]=!1,!1;try{const n=Ye.verify(e.sig,t,e.pubkey);return e[je]=n,n}catch{return e[je]=!1,!1}}};function fo(e){if(!pt(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 ze(e){let t=fe(ne.encode(fo(e)));return H(t)}var gt=new lo,Le=gt.generateSecretKey,ue=gt.getPublicKey,ee=gt.finalizeEvent,wt=gt.verifyEvent,ho={};D(ho,{Application:()=>ha,BadgeAward:()=>Eo,BadgeDefinition:()=>sa,BlockedRelaysList:()=>jo,BookmarkList:()=>Ho,Bookmarksets:()=>na,Calendar:()=>va,CalendarEventRSVP:()=>ma,ChannelCreation:()=>$r,ChannelHideMessage:()=>Or,ChannelMessage:()=>Rr,ChannelMetadata:()=>Tr,ChannelMuteUser:()=>Mr,ClassifiedListing:()=>pa,ClientAuth:()=>Hr,CommunitiesList:()=>Do,CommunityDefinition:()=>Ka,CommunityPostApproval:()=>Io,Contacts:()=>bo,CreateOrUpdateProduct:()=>ca,CreateOrUpdateStall:()=>aa,Curationsets:()=>ra,Date:()=>wa,DirectMessageRelaysList:()=>Zo,DraftClassifiedListing:()=>ga,DraftLong:()=>la,Emojisets:()=>fa,EncryptedDirectMessage:()=>vo,EventDeletion:()=>mo,FileMetadata:()=>Ko,FileServerPreference:()=>Go,Followsets:()=>Qo,GenericRepost:()=>fn,Genericlists:()=>ea,GiftWrap:()=>Pr,HTTPAuth:()=>hn,Handlerinformation:()=>xa,Handlerrecommendation:()=>Ea,Highlights:()=>Ro,InterestsList:()=>Vo,Interestsets:()=>oa,JobFeedback:()=>Uo,JobRequest:()=>Bo,JobResult:()=>_o,Label:()=>ko,LightningPubRPC:()=>Jo,LiveChatMessage:()=>No,LiveEvent:()=>da,LongFormArticle:()=>ua,Metadata:()=>go,Mutelist:()=>Oo,NWCWalletInfo:()=>Fo,NWCWalletRequest:()=>Dr,NWCWalletResponse:()=>Yo,NostrConnect:()=>Xo,OpenTimestamps:()=>xo,Pinlist:()=>Mo,PrivateDirectMessage:()=>Lr,ProblemTracker:()=>So,ProfileBadges:()=>ia,PublicChatsList:()=>qo,Reaction:()=>ln,RecommendRelay:()=>wo,RelayList:()=>Po,Relaysets:()=>ta,Report:()=>Ao,Reporting:()=>Co,Repost:()=>un,Seal:()=>Ur,SearchRelaysList:()=>zo,ShortTextNote:()=>_r,Time:()=>ba,UserEmojiList:()=>Wo,UserStatuses:()=>ya,Zap:()=>To,ZapGoal:()=>Lo,ZapRequest:()=>$o,classifyKind:()=>yo,isAddressableKind:()=>cn,isEphemeralKind:()=>Br,isKind:()=>po,isRegularKind:()=>Ir,isReplaceableKind:()=>an});function Ir(e){return 1e3<=e&&e<1e4||[1,2,4,5,6,7,8,16,40,41,42,43,44].includes(e)}function an(e){return[0,3].includes(e)||1e4<=e&&e<2e4}function Br(e){return 2e4<=e&&e<3e4}function cn(e){return 3e4<=e&&e<4e4}function yo(e){return Ir(e)?"regular":an(e)?"replaceable":Br(e)?"ephemeral":cn(e)?"parameterized":"unknown"}function po(e,t){const n=t instanceof Array?t:[t];return pt(e)&&n.includes(e.kind)||!1}var go=0,_r=1,wo=2,bo=3,vo=4,mo=5,un=6,ln=7,Eo=8,Ur=13,Lr=14,fn=16,$r=40,Tr=41,Rr=42,Or=43,Mr=44,xo=1040,Pr=1059,Ko=1063,No=1311,So=1971,Ao=1984,Co=1984,ko=1985,Io=4550,Bo=5999,_o=6999,Uo=7e3,Lo=9041,$o=9734,To=9735,Ro=9802,Oo=1e4,Mo=10001,Po=10002,Ho=10003,Do=10004,qo=10005,jo=10006,zo=10007,Vo=10015,Wo=10030,Zo=10050,Go=10096,Fo=13194,Jo=21e3,Hr=22242,Dr=23194,Yo=23195,Xo=24133,hn=27235,Qo=3e4,ea=30001,ta=30002,na=30003,ra=30004,ia=30008,sa=30009,oa=30015,aa=30017,ca=30018,ua=30023,la=30024,fa=30030,ha=30078,da=30311,ya=30315,pa=30402,ga=30403,wa=31922,ba=31923,va=31924,ma=31925,Ea=31989,xa=31990,Ka=34550,Na={};D(Na,{getHex64:()=>dn,getInt:()=>qr,getSubscriptionId:()=>Sa,matchEventId:()=>Aa,matchEventKind:()=>ka,matchEventPubkey:()=>Ca});function dn(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 qr(e,t){let n=t.length,r=e.indexOf(`"${t}":`)+n+3,i=e.slice(r),s=Math.min(i.indexOf(","),i.indexOf("}"));return parseInt(i.slice(0,s),10)}function Sa(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 s=r+1+i;return e.slice(r+1,s)}function Aa(e,t){return t===dn(e,"id")}function Ca(e,t){return t===dn(e,"pubkey")}function ka(e,t){return t===qr(e,"kind")}var Ia={};D(Ia,{makeAuthEvent:()=>Ba});function Ba(e,t){return{kind:Hr,created_at:Math.floor(Date.now()/1e3),tags:[["relay",e],["challenge",t]],content:""}}var _a;try{_a=WebSocket}catch{}var Ua;try{Ua=WebSocket}catch{}var La={};D(La,{BECH32_REGEX:()=>jr,Bech32MaxSize:()=>yn,NostrTypeGuard:()=>$a,decode:()=>bt,decodeNostrURI:()=>Ra,encodeBytes:()=>mt,naddrEncode:()=>qa,neventEncode:()=>Da,noteEncode:()=>Pa,nprofileEncode:()=>Ha,npubEncode:()=>Ma,nsecEncode:()=>Oa});var $a={isNProfile:e=>/^nprofile1[a-z\d]+$/.test(e||""),isNEvent:e=>/^nevent1[a-z\d]+$/.test(e||""),isNAddr:e=>/^naddr1[a-z\d]+$/.test(e||""),isNSec:e=>/^nsec1[a-z\d]{58}$/.test(e||""),isNPub:e=>/^npub1[a-z\d]{58}$/.test(e||""),isNote:e=>/^note1[a-z\d]+$/.test(e||""),isNcryptsec:e=>/^ncryptsec1[a-z\d]+$/.test(e||"")},yn=5e3,jr=/[\x21-\x7E]{1,83}1[023456789acdefghjklmnpqrstuvwxyz]{6,}/;function Ta(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 Ra(e){try{return e.startsWith("nostr:")&&(e=e.substring(6)),bt(e)}catch{return{type:"invalid",data:null}}}function bt(e){var i,s,o,c,a,l,f;let{prefix:t,words:n}=De.decode(e,yn),r=new Uint8Array(De.fromWords(n));switch(t){case"nprofile":{let u=pn(r);if(!((i=u[0])!=null&&i[0]))throw new Error("missing TLV 0 for nprofile");if(u[0][0].length!==32)throw new Error("TLV 0 should be 32 bytes");return{type:"nprofile",data:{pubkey:H(u[0][0]),relays:u[1]?u[1].map(p=>we.decode(p)):[]}}}case"nevent":{let u=pn(r);if(!((s=u[0])!=null&&s[0]))throw new Error("missing TLV 0 for nevent");if(u[0][0].length!==32)throw new Error("TLV 0 should be 32 bytes");if(u[2]&&u[2][0].length!==32)throw new Error("TLV 2 should be 32 bytes");if(u[3]&&u[3][0].length!==4)throw new Error("TLV 3 should be 4 bytes");return{type:"nevent",data:{id:H(u[0][0]),relays:u[1]?u[1].map(p=>we.decode(p)):[],author:(o=u[2])!=null&&o[0]?H(u[2][0]):void 0,kind:(c=u[3])!=null&&c[0]?parseInt(H(u[3][0]),16):void 0}}}case"naddr":{let u=pn(r);if(!((a=u[0])!=null&&a[0]))throw new Error("missing TLV 0 for naddr");if(!((l=u[2])!=null&&l[0]))throw new Error("missing TLV 2 for naddr");if(u[2][0].length!==32)throw new Error("TLV 2 should be 32 bytes");if(!((f=u[3])!=null&&f[0]))throw new Error("missing TLV 3 for naddr");if(u[3][0].length!==4)throw new Error("TLV 3 should be 4 bytes");return{type:"naddr",data:{identifier:we.decode(u[0][0]),pubkey:H(u[2][0]),kind:parseInt(H(u[3][0]),16),relays:u[1]?u[1].map(p=>we.decode(p)):[]}}}case"nsec":return{type:t,data:r};case"npub":case"note":return{type:t,data:H(r)};default:throw new Error(`unknown prefix ${t}`)}}function pn(e){let t={},n=e;for(;n.length>0;){let r=n[0],i=n[1],s=n.slice(2,2+i);if(n=n.slice(2+i),s.length<i)throw new Error(`not enough data to read on TLV ${r}`);t[r]=t[r]||[],t[r].push(s)}return t}function Oa(e){return mt("nsec",e)}function Ma(e){return mt("npub",V(e))}function Pa(e){return mt("note",V(e))}function vt(e,t){let n=De.toWords(t);return De.encode(e,n,yn)}function mt(e,t){return vt(e,t)}function Ha(e){let t=gn({0:[V(e.pubkey)],1:(e.relays||[]).map(n=>ne.encode(n))});return vt("nprofile",t)}function Da(e){let t;e.kind!==void 0&&(t=Ta(e.kind));let n=gn({0:[V(e.id)],1:(e.relays||[]).map(r=>ne.encode(r)),2:e.author?[V(e.author)]:[],3:t?[new Uint8Array(t)]:[]});return vt("nevent",n)}function qa(e){let t=new ArrayBuffer(4);new DataView(t).setUint32(0,e.kind,!1);let n=gn({0:[ne.encode(e.identifier)],1:(e.relays||[]).map(r=>ne.encode(r)),2:[V(e.pubkey)],3:[new Uint8Array(t)]});return vt("naddr",n)}function gn(e){let t=[];return Object.entries(e).reverse().forEach(([n,r])=>{r.forEach(i=>{let s=new Uint8Array(i.length+2);s.set([parseInt(n)],0),s.set([i.length],1),s.set(i,2),t.push(s)})}),lt(...t)}var ja={};D(ja,{decrypt:()=>za,encrypt:()=>zr});function zr(e,t,n){const r=e instanceof Uint8Array?H(e):e,i=Ue.getSharedSecret(r,"02"+t),s=Vr(i);let o=Uint8Array.from(nr(16)),c=ne.encode(n),a=vr(s,o).encrypt(c),l=pe.encode(new Uint8Array(a)),f=pe.encode(new Uint8Array(o.buffer));return`${l}?iv=${f}`}function za(e,t,n){const r=e instanceof Uint8Array?H(e):e;let[i,s]=n.split("?iv="),o=Ue.getSharedSecret(r,"02"+t),c=Vr(o),a=pe.decode(s),l=pe.decode(i),f=vr(c,a).decrypt(l);return we.decode(f)}function Vr(e){return e.slice(1,33)}var Va={};D(Va,{NIP05_REGEX:()=>wn,isNip05:()=>Wa,isValid:()=>Fa,queryProfile:()=>Wr,searchDomain:()=>Ga,useFetchImplementation:()=>Za});var wn=/^(?:([\w.+-]+)@)?([\w_-]+(\.[\w_-]+)+)$/,Wa=e=>wn.test(e||""),Et;try{Et=fetch}catch{}function Za(e){Et=e}async function Ga(e,t=""){try{const n=`https://${e}/.well-known/nostr.json?name=${t}`,r=await Et(n,{redirect:"manual"});if(r.status!==200)throw Error("Wrong response code");return(await r.json()).names}catch{return{}}}async function Wr(e){var i;const t=e.match(wn);if(!t)return null;const[,n="_",r]=t;try{const s=`https://${r}/.well-known/nostr.json?name=${n}`,o=await Et(s,{redirect:"manual"});if(o.status!==200)throw Error("Wrong response code");const c=await o.json(),a=c.names[n];return a?{pubkey:a,relays:(i=c.relays)==null?void 0:i[a]}:null}catch{return null}}async function Fa(e,t){const n=await Wr(t);return n?n.pubkey===e:!1}var Ja={};D(Ja,{parse:()=>Ya});function Ya(e){const t={reply:void 0,root:void 0,mentions:[],profiles:[],quotes:[]};let n,r;for(let i=e.tags.length-1;i>=0;i--){const s=e.tags[i];if(s[0]==="e"&&s[1]){const[o,c,a,l,f]=s,u={id:c,relays:a?[a]:[],author:f};if(l==="root"){t.root=u;continue}if(l==="reply"){t.reply=u;continue}if(l==="mention"){t.mentions.push(u);continue}n?r=u:n=u,t.mentions.push(u);continue}if(s[0]==="q"&&s[1]){const[o,c,a]=s;t.quotes.push({id:c,relays:a?[a]:[]})}if(s[0]==="p"&&s[1]){t.profiles.push({pubkey:s[1],relays:s[2]?[s[2]]:[]});continue}}return t.root||(t.root=r||n||t.reply),t.reply||(t.reply=n||t.root),[t.reply,t.root].forEach(i=>{if(!i)return;let s=t.mentions.indexOf(i);if(s!==-1&&t.mentions.splice(s,1),i.author){let o=t.profiles.find(c=>c.pubkey===i.author);o&&o.relays&&(i.relays||(i.relays=[]),o.relays.forEach(c=>{var a;((a=i.relays)==null?void 0:a.indexOf(c))===-1&&i.relays.push(c)}),o.relays=i.relays)}}),t.mentions.forEach(i=>{if(i.author){let s=t.profiles.find(o=>o.pubkey===i.author);s&&s.relays&&(i.relays||(i.relays=[]),s.relays.forEach(o=>{i.relays.indexOf(o)===-1&&i.relays.push(o)}),s.relays=i.relays)}}),t}var Xa={};D(Xa,{fetchRelayInformation:()=>ec,useFetchImplementation:()=>Qa});var Zr;try{Zr=fetch}catch{}function Qa(e){Zr=e}async function ec(e){return await(await fetch(e.replace("ws://","http://").replace("wss://","https://"),{headers:{Accept:"application/nostr+json"}})).json()}var tc={};D(tc,{fastEventHash:()=>Fr,getPow:()=>Gr,minePow:()=>nc});function Gr(e){let t=0;for(let n=0;n<64;n+=8){const r=parseInt(e.substring(n,n+8),16);if(r===0)t+=32;else{t+=Math.clz32(r);break}}return t}function nc(e,t){let n=0;const r=e,i=["nonce",n.toString(),t.toString()];for(r.tags.push(i);;){const s=Math.floor(new Date().getTime()/1e3);if(s!==r.created_at&&(n=0,r.created_at=s),i[1]=(++n).toString(),r.id=Fr(r),Gr(r.id)>=t)break}return r}function Fr(e){return H(fe(ne.encode(JSON.stringify([0,e.pubkey,e.created_at,e.kind,e.tags,e.content]))))}var rc={};D(rc,{unwrapEvent:()=>yc,unwrapManyEvents:()=>pc,wrapEvent:()=>ui,wrapManyEvents:()=>dc});var ic={};D(ic,{createRumor:()=>si,createSeal:()=>oi,createWrap:()=>ai,unwrapEvent:()=>xn,unwrapManyEvents:()=>ci,wrapEvent:()=>xt,wrapManyEvents:()=>fc});var q={};D(q,{decrypt:()=>En,encrypt:()=>mn,getConversationKey:()=>bn,v2:()=>uc});var Jr=1,Yr=65535;function bn(e,t){const n=Ue.getSharedSecret(e,"02"+t).subarray(1,33);return rn(fe,n,"nip44-v2")}function Xr(e,t){const n=Cr(fe,e,t,76);return{chacha_key:n.subarray(0,32),chacha_nonce:n.subarray(32,44),hmac_key:n.subarray(44,76)}}function vn(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<Jr||e>Yr)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 oc(e){const t=ne.encode(e),n=t.length,r=sc(n),i=new Uint8Array(vn(n)-n);return lt(r,t,i)}function ac(e){const t=new DataView(e.buffer).getUint16(0),n=e.subarray(2,2+t);if(t<Jr||t>Yr||n.length!==t||e.length!==2+vn(t))throw new Error("invalid padding");return we.decode(n)}function Qr(e,t,n){if(n.length!==32)throw new Error("AAD associated data must be 32 bytes");const r=lt(n,t);return yt(fe,e,r)}function cc(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=pe.decode(e)}catch(s){throw new Error("invalid base64: "+s.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 mn(e,t,n=nr(32)){const{chacha_key:r,chacha_nonce:i,hmac_key:s}=Xr(t,n),o=oc(e),c=Nr(r,i,o),a=Qr(s,c,n);return pe.encode(lt(new Uint8Array([2]),n,c,a))}function En(e,t){const{nonce:n,ciphertext:r,mac:i}=cc(e),{chacha_key:s,chacha_nonce:o,hmac_key:c}=Xr(t,n),a=Qr(c,r,n);if(!Ms(a,i))throw new Error("invalid MAC");const l=Nr(s,o,r);return ac(l)}var uc={utils:{getConversationKey:bn,calcPaddedLen:vn},encrypt:mn,decrypt:En},lc=2*24*60*60,ei=()=>Math.round(Date.now()/1e3),ti=()=>Math.round(ei()-Math.random()*lc),ni=(e,t)=>bn(e,t),ri=(e,t,n)=>mn(JSON.stringify(e),ni(t,n)),ii=(e,t)=>JSON.parse(En(e.content,ni(t,e.pubkey)));function si(e,t){const n={created_at:ei(),content:"",tags:[],...e,pubkey:ue(t)};return n.id=ze(n),n}function oi(e,t,n){return ee({kind:Ur,content:ri(e,t,n),created_at:ti(),tags:[]},t)}function ai(e,t){const n=Le();return ee({kind:Pr,content:ri(e,n,t),created_at:ti(),tags:[["p",t]]},n)}function xt(e,t,n){const r=si(e,t),i=oi(r,t,n);return ai(i,n)}function fc(e,t,n){if(!n||n.length===0)throw new Error("At least one recipient is required.");const r=ue(t),i=[xt(e,t,r)];return n.forEach(s=>{i.push(xt(e,t,s))}),i}function xn(e,t){const n=ii(e,t);return ii(n,t)}function ci(e,t){let n=[];return e.forEach(r=>{n.push(xn(r,t))}),n.sort((r,i)=>r.created_at-i.created_at),n}function hc(e,t,n,r){const i={created_at:Math.ceil(Date.now()/1e3),kind:Lr,tags:[],content:t};return(Array.isArray(e)?e:[e]).forEach(({publicKey:o,relayUrl:c})=>{i.tags.push(c?["p",o,c]:["p",o])}),r&&i.tags.push(["e",r.eventId,r.relayUrl||"","reply"]),n&&i.tags.push(["subject",n]),i}function ui(e,t,n,r,i){const s=hc(t,n,r,i);return xt(s,e,t.publicKey)}function dc(e,t,n,r,i){if(!t||t.length===0)throw new Error("At least one recipient is required.");return[{publicKey:ue(e)},...t].map(o=>ui(e,o,n,r,i))}var yc=xn,pc=ci,gc={};D(gc,{finishRepostEvent:()=>wc,getRepostedEvent:()=>bc,getRepostedEventPointer:()=>li});function wc(e,t,n,r){var o;let i;const s=[...e.tags??[],["e",t.id,n],["p",t.pubkey]];return t.kind===_r?i=un:(i=fn,s.push(["k",String(t.kind)])),ee({kind:i,tags:s,content:e.content===""||(o=t.tags)!=null&&o.find(c=>c[0]==="-")?"":JSON.stringify(t),created_at:e.created_at},r)}function li(e){if(![un,fn].includes(e.kind))return;let t,n;for(let r=e.tags.length-1;r>=0&&(t===void 0||n===void 0);r--){const i=e.tags[r];i.length>=2&&(i[0]==="e"&&t===void 0?t=i:i[0]==="p"&&n===void 0&&(n=i))}if(t!==void 0)return{id:t[1],relays:[t[2],n==null?void 0:n[2]].filter(r=>typeof r=="string"),author:n==null?void 0:n[1]}}function bc(e,{skipVerification:t}={}){const n=li(e);if(n===void 0||e.content==="")return;let r;try{r=JSON.parse(e.content)}catch{return}if(r.id===n.id&&!(!t&&!wt(r)))return r}var vc={};D(vc,{NOSTR_URI_REGEX:()=>Kn,parse:()=>Ec,test:()=>mc});var Kn=new RegExp(`nostr:(${jr.source})`);function mc(e){return typeof e=="string"&&new RegExp(`^${Kn.source}$`).test(e)}function Ec(e){const t=e.match(new RegExp(`^${Kn.source}$`));if(!t)throw new Error(`Invalid Nostr URI: ${e}`);return{uri:t[0],value:t[1],decoded:bt(t[1])}}var xc={};D(xc,{finishReactionEvent:()=>Kc,getReactedEventPointer:()=>Nc});function Kc(e,t,n){const r=t.tags.filter(i=>i.length>=2&&(i[0]==="e"||i[0]==="p"));return ee({...e,kind:ln,tags:[...e.tags??[],...r,["e",t.id],["p",t.pubkey]],content:e.content??"+"},n)}function Nc(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 Sc={};D(Sc,{parse:()=>Cc});var Ac=/\W/m,fi=/\W |\W$|$|,| /m;function*Cc(e){const t=e.length;let n=0,r=0;for(;r<t;){let i=e.indexOf(":",r);if(i===-1)break;if(e.substring(i-5,i)==="nostr"){const s=e.substring(i+60).match(Ac),o=s?i+60+s.index:t;try{let c,{data:a,type:l}=bt(e.substring(i+1,o));switch(l){case"npub":c={pubkey:a};break;case"nsec":case"note":r=o+1;continue;default:c=a}n!==i-5&&(yield{type:"text",text:e.substring(n,i-5)}),yield{type:"reference",pointer:c},r=o,n=r;continue}catch{r=i+1;continue}}else if(e.substring(i-5,i)==="https"||e.substring(i-4,i)==="http"){const s=e.substring(i+4).match(fi),o=s?i+4+s.index:t,c=e[i-1]==="s"?5:4;try{let a=new URL(e.substring(i-c,o));if(a.hostname.indexOf(".")===-1)throw new Error("invalid url");if(n!==i-c&&(yield{type:"text",text:e.substring(n,i-c)}),a.pathname.endsWith(".png")||a.pathname.endsWith(".jpg")||a.pathname.endsWith(".jpeg")||a.pathname.endsWith(".gif")||a.pathname.endsWith(".webp")){yield{type:"image",url:a.toString()},r=o,n=r;continue}if(a.pathname.endsWith(".mp4")||a.pathname.endsWith(".avi")||a.pathname.endsWith(".webm")||a.pathname.endsWith(".mkv")){yield{type:"video",url:a.toString()},r=o,n=r;continue}if(a.pathname.endsWith(".mp3")||a.pathname.endsWith(".aac")||a.pathname.endsWith(".ogg")||a.pathname.endsWith(".opus")){yield{type:"audio",url:a.toString()},r=o,n=r;continue}yield{type:"url",url:a.toString()},r=o,n=r;continue}catch{r=o+1;continue}}else if(e.substring(i-3,i)==="wss"||e.substring(i-2,i)==="ws"){const s=e.substring(i+4).match(fi),o=s?i+4+s.index:t,c=e[i-1]==="s"?3:2;try{let a=new URL(e.substring(i-c,o));if(a.hostname.indexOf(".")===-1)throw new Error("invalid ws url");n!==i-c&&(yield{type:"text",text:e.substring(n,i-c)}),yield{type:"relay",url:a.toString()},r=o,n=r;continue}catch{r=o+1;continue}}else{r=i+1;continue}}n!==t&&(yield{type:"text",text:e.substring(n)})}var kc={};D(kc,{channelCreateEvent:()=>Ic,channelHideMessageEvent:()=>Uc,channelMessageEvent:()=>_c,channelMetadataEvent:()=>Bc,channelMuteUserEvent:()=>Lc});var Ic=(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 ee({kind:$r,tags:[...e.tags??[]],content:n,created_at:e.created_at},t)},Bc=(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 ee({kind:Tr,tags:[["e",e.channel_create_event_id],...e.tags??[]],content:n,created_at:e.created_at},t)},_c=(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"]),ee({kind:Rr,tags:[...n,...e.tags??[]],content:e.content,created_at:e.created_at},t)},Uc=(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 ee({kind:Or,tags:[["e",e.channel_message_event_id],...e.tags??[]],content:n,created_at:e.created_at},t)},Lc=(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 ee({kind:Mr,tags:[["p",e.pubkey_to_mute],...e.tags??[]],content:n,created_at:e.created_at},t)},$c={};D($c,{EMOJI_SHORTCODE_REGEX:()=>hi,matchAll:()=>Tc,regex:()=>Nn,replaceAll:()=>Rc});var hi=/:(\w+):/,Nn=()=>new RegExp(`\\B${hi.source}\\B`,"g");function*Tc(e){const t=e.matchAll(Nn());for(const n of t)try{const[r,i]=n;yield{shortcode:r,name:i,start:n.index,end:n.index+r.length}}catch{}}function Rc(e,t){return e.replaceAll(Nn(),(n,r)=>t({shortcode:n,name:r}))}var Oc={};D(Oc,{useFetchImplementation:()=>Mc,validateGithub:()=>Pc});var Sn;try{Sn=fetch}catch{}function Mc(e){Sn=e}async function Pc(e,t,n){try{return await(await Sn(`https://gist.github.com/${t}/${n}/raw`)).text()===`Verifying that I control the following Nostr public key: ${e}`}catch{return!1}}var Hc={};D(Hc,{makeNwcRequestEvent:()=>qc,parseConnectionString:()=>Dc});function Dc(e){const{host:t,pathname:n,searchParams:r}=new URL(e),i=n||t,s=r.get("relay"),o=r.get("secret");if(!i||!s||!o)throw new Error("invalid connection string");return{pubkey:i,relay:s,secret:o}}async function qc(e,t,n){const i=zr(t,e,JSON.stringify({method:"pay_invoice",params:{invoice:n}})),s={kind:Dr,created_at:Math.round(Date.now()/1e3),content:i,tags:[["p",e]]};return ee(s,t)}var jc={};D(jc,{normalizeIdentifier:()=>zc});function zc(e){return e=e.trim().toLowerCase(),e=e.normalize("NFKC"),Array.from(e).map(t=>new RegExp("\\p{Letter}","u").test(t)||new RegExp("\\p{Number}","u").test(t)?t:"-").join("")}var Vc={};D(Vc,{getSatoshisAmountFromBolt11:()=>Yc,getZapEndpoint:()=>Zc,makeZapReceipt:()=>Jc,makeZapRequest:()=>Gc,useFetchImplementation:()=>Wc,validateZapRequest:()=>Fc});var An;try{An=fetch}catch{}function Wc(e){An=e}async function Zc(e){try{let t="",{lud06:n,lud16:r}=JSON.parse(e.content);if(n){let{words:o}=De.decode(n,1e3),c=De.fromWords(o);t=we.decode(c)}else if(r){let[o,c]=r.split("@");t=new URL(`/.well-known/lnurlp/${o}`,`https://${c}`).toString()}else return null;let s=await(await An(t)).json();if(s.allowsNostr&&s.nostrPubkey)return s.callback}catch{}return null}function Gc(e){let t={kind:9734,created_at:Math.round(Date.now()/1e3),content:e.comment||"",tags:[["p","pubkey"in e?e.pubkey:e.event.pubkey],["amount",e.amount.toString()],["relays",...e.relays]]};if("event"in e){if(t.tags.push(["e",e.event.id]),an(e.event.kind)){const n=["a",`${e.event.kind}:${e.event.pubkey}:`];t.tags.push(n)}else if(cn(e.event.kind)){let n=e.event.tags.find(([i,s])=>i==="d"&&s);if(!n)throw new Error("d tag not found or is empty");const r=["a",`${e.event.kind}:${e.event.pubkey}:${n[1]}`];t.tags.push(r)}t.tags.push(["k",e.event.kind.toString()])}return t}function Fc(e){let t;try{t=JSON.parse(e)}catch{return"Invalid zap request JSON."}if(!pt(t))return"Zap request is not a valid Nostr event.";if(!wt(t))return"Invalid signature on zap request.";let n=t.tags.find(([s,o])=>s==="p"&&o);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(([s,o])=>s==="e"&&o);return r&&!r[1].match(/^[a-f0-9]{64}$/)?"Zap request 'e' tag is not valid hex.":t.tags.find(([s,o])=>s==="relays"&&o)?null:"Zap request doesn't have a 'relays' tag."}function Jc({zapRequest:e,preimage:t,bolt11:n,paidAt:r}){let i=JSON.parse(e),s=i.tags.filter(([c])=>c==="e"||c==="p"||c==="a"),o={kind:9735,created_at:Math.round(r.getTime()/1e3),content:"",tags:[...s,["P",i.pubkey],["bolt11",n],["description",e]]};return t&&o.tags.push(["preimage",t]),o}function Yc(e){if(e.length<50)return 0;e=e.substring(0,50);const t=e.lastIndexOf("1");if(t===-1)return 0;const n=e.substring(0,t);if(!n.startsWith("lnbc"))return 0;const r=n.substring(4);if(r.length<1)return 0;const i=r[r.length-1],s=i.charCodeAt(0)-48,o=s>=0&&s<=9;let c=r.length-1;if(o&&c++,c<1)return 0;const a=parseInt(r.substring(0,c));switch(i){case"m":return a*1e5;case"u":return a*100;case"n":return a/10;case"p":return a/1e4;default:return a*1e8}}var Xc={};D(Xc,{getToken:()=>Qc,hashPayload:()=>Cn,unpackEventFromToken:()=>yi,validateEvent:()=>mi,validateEventKind:()=>gi,validateEventMethodTag:()=>bi,validateEventPayloadTag:()=>vi,validateEventTimestamp:()=>pi,validateEventUrlTag:()=>wi,validateToken:()=>eu});var di="Nostr ";async function Qc(e,t,n,r=!1,i){const s={kind:hn,tags:[["u",e],["method",t]],created_at:Math.round(new Date().getTime()/1e3),content:""};i&&s.tags.push(["payload",Cn(i)]);const o=await n(s);return(r?di:"")+pe.encode(ne.encode(JSON.stringify(o)))}async function eu(e,t,n){const r=await yi(e).catch(s=>{throw s});return await mi(r,t,n).catch(s=>{throw s})}async function yi(e){if(!e)throw new Error("Missing token");e=e.replace(di,"");const t=we.decode(pe.decode(e));if(!t||t.length===0||!t.startsWith("{"))throw new Error("Invalid token");return JSON.parse(t)}function pi(e){return e.created_at?Math.round(new Date().getTime()/1e3)-e.created_at<60:!1}function gi(e){return e.kind===hn}function wi(e,t){const n=e.tags.find(r=>r[0]==="u");return n?n.length>0&&n[1]===t:!1}function bi(e,t){const n=e.tags.find(r=>r[0]==="method");return n?n.length>0&&n[1].toLowerCase()===t.toLowerCase():!1}function Cn(e){const t=fe(ne.encode(JSON.stringify(e)));return H(t)}function vi(e,t){const n=e.tags.find(i=>i[0]==="payload");if(!n)return!1;const r=Cn(t);return n.length>0&&n[1]===r}async function mi(e,t,n,r){if(!wt(e))throw new Error("Invalid nostr event, signature invalid");if(!gi(e))throw new Error("Invalid nostr event, kind invalid");if(!pi(e))throw new Error("Invalid nostr event, created_at timestamp invalid");if(!wi(e,t))throw new Error("Invalid nostr event, url tag invalid");if(!bi(e,n))throw new Error("Invalid nostr event, method tag invalid");if(r&&typeof r=="object"&&Object.keys(r).length>0&&!vi(e,r))throw new Error("Invalid nostr event, payload tag does not match request body hash");return!0}const $e=1060,Kt=30078,kn=1059,Ei=14,tu=100,nu=1;function ru(e){return JSON.stringify({version:nu,rootKey:H(e.rootKey),theirCurrentNostrPublicKey:e.theirCurrentNostrPublicKey,theirNextNostrPublicKey:e.theirNextNostrPublicKey,ourCurrentNostrKey:e.ourCurrentNostrKey?{publicKey:e.ourCurrentNostrKey.publicKey,privateKey:H(e.ourCurrentNostrKey.privateKey)}:void 0,ourNextNostrKey:{publicKey:e.ourNextNostrKey.publicKey,privateKey:H(e.ourNextNostrKey.privateKey)},receivingChainKey:e.receivingChainKey?H(e.receivingChainKey):void 0,sendingChainKey:e.sendingChainKey?H(e.sendingChainKey):void 0,sendingChainMessageNumber:e.sendingChainMessageNumber,receivingChainMessageNumber:e.receivingChainMessageNumber,previousSendingChainMessageCount:e.previousSendingChainMessageCount,skippedKeys:Object.fromEntries(Object.entries(e.skippedKeys).map(([t,n])=>[t,{headerKeys:n.headerKeys.map(r=>H(r)),messageKeys:Object.fromEntries(Object.entries(n.messageKeys).map(([r,i])=>[r,H(i)]))}]))})}function iu(e){const t=JSON.parse(e);if(!t.version){const n={};return t.skippedMessageKeys&&Object.entries(t.skippedMessageKeys).forEach(([r,i])=>{var s;n[r]={headerKeys:((s=t.skippedHeaderKeys)==null?void 0:s[r])||[],messageKeys:i}}),{rootKey:V(t.rootKey),theirCurrentNostrPublicKey:t.theirCurrentNostrPublicKey,theirNextNostrPublicKey:t.theirNextNostrPublicKey,ourCurrentNostrKey:t.ourCurrentNostrKey?{publicKey:t.ourCurrentNostrKey.publicKey,privateKey:V(t.ourCurrentNostrKey.privateKey)}:void 0,ourNextNostrKey:{publicKey:t.ourNextNostrKey.publicKey,privateKey:V(t.ourNextNostrKey.privateKey)},receivingChainKey:t.receivingChainKey?V(t.receivingChainKey):void 0,sendingChainKey:t.sendingChainKey?V(t.sendingChainKey):void 0,sendingChainMessageNumber:t.sendingChainMessageNumber,receivingChainMessageNumber:t.receivingChainMessageNumber,previousSendingChainMessageCount:t.previousSendingChainMessageCount,skippedKeys:n}}return{rootKey:V(t.rootKey),theirCurrentNostrPublicKey:t.theirCurrentNostrPublicKey,theirNextNostrPublicKey:t.theirNextNostrPublicKey,ourCurrentNostrKey:t.ourCurrentNostrKey?{publicKey:t.ourCurrentNostrKey.publicKey,privateKey:V(t.ourCurrentNostrKey.privateKey)}:void 0,ourNextNostrKey:{publicKey:t.ourNextNostrKey.publicKey,privateKey:V(t.ourNextNostrKey.privateKey)},receivingChainKey:t.receivingChainKey?V(t.receivingChainKey):void 0,sendingChainKey:t.sendingChainKey?V(t.sendingChainKey):void 0,sendingChainMessageNumber:t.sendingChainMessageNumber,receivingChainMessageNumber:t.receivingChainMessageNumber,previousSendingChainMessageCount:t.previousSendingChainMessageCount,skippedKeys:Object.fromEntries(Object.entries(t.skippedKeys||{}).map(([n,r])=>[n,{headerKeys:r.headerKeys.map(i=>V(i)),messageKeys:Object.fromEntries(Object.entries(r.messageKeys).map(([i,s])=>[i,V(s)]))}]))}}function xi(e){return{rootKey:new Uint8Array(e.rootKey),theirCurrentNostrPublicKey:e.theirCurrentNostrPublicKey,theirNextNostrPublicKey:e.theirNextNostrPublicKey,ourCurrentNostrKey:e.ourCurrentNostrKey?{publicKey:e.ourCurrentNostrKey.publicKey,privateKey:new Uint8Array(e.ourCurrentNostrKey.privateKey)}:void 0,ourNextNostrKey:{publicKey:e.ourNextNostrKey.publicKey,privateKey:new Uint8Array(e.ourNextNostrKey.privateKey)},receivingChainKey:e.receivingChainKey?new Uint8Array(e.receivingChainKey):void 0,sendingChainKey:e.sendingChainKey?new Uint8Array(e.sendingChainKey):void 0,sendingChainMessageNumber:e.sendingChainMessageNumber,receivingChainMessageNumber:e.receivingChainMessageNumber,previousSendingChainMessageCount:e.previousSendingChainMessageCount,skippedKeys:Object.fromEntries(Object.entries(e.skippedKeys).map(([t,n])=>[t,{headerKeys:n.headerKeys.map(r=>new Uint8Array(r)),messageKeys:Object.fromEntries(Object.entries(n.messageKeys).map(([r,i])=>[r,new Uint8Array(i)]))}]))}}async function*su(e){const t=[];let n=null;const r=e.onEvent(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(fe,e,t),i=[];for(let s=1;s<=n;s++)i.push(Cr(fe,r,new Uint8Array([s]),32));return i}function ou(e,t){return`${e}:${t}`}function au(e){var n;const t=(n=e.tags)==null?void 0:n.find(r=>r[0]==="ms");return t?parseInt(t[1]):e.created_at*1e3}const cu=1e3,uu="0000000000000000000000000000000000000000000000000000000000000000";class et{constructor(t,n){te(this,"skippedSubscription");te(this,"nostrUnsubscribe");te(this,"nostrNextUnsubscribe");te(this,"internalSubscriptions",new Map);te(this,"currentInternalSubscriptionId",0);te(this,"name");this.nostrSubscribe=t,this.state=n,this.name=Math.random().toString(36).substring(2,6)}static init(t,n,r,i,s,o){const c=Le();let a,l,f,u;i?([a,l]=Te(s,q.getConversationKey(c,n),2),f={publicKey:ue(r),privateKey:r},u={publicKey:ue(c),privateKey:c}):(a=s,l=void 0,f=void 0,u={publicKey:ue(r),privateKey:r});const p={rootKey:a,theirNextNostrPublicKey:n,ourCurrentNostrKey:f,ourNextNostrKey:u,receivingChainKey:void 0,sendingChainKey:l,sendingChainMessageNumber:0,receivingChainMessageNumber:0,previousSendingChainMessageCount:0,skippedKeys:{}},w=new et(t,p);return o&&(w.name=o),w}send(t){return this.sendEvent({content:t,kind:Ei})}sendEvent(t){if(!this.state.theirNextNostrPublicKey||!this.state.ourCurrentNostrKey)throw new Error("we are not the initiator, so we can't send the first message");if("sig"in t)throw new Error("Event must be unsigned "+JSON.stringify(t));const n=Date.now(),r={...t,content:t.content||"",kind:t.kind||$e,created_at:t.created_at||Math.floor(n/1e3),tags:t.tags||[],pubkey:t.pubkey||uu};r.tags.some(([l])=>l==="ms")||r.tags.push(["ms",String(n)]),r.id=ze(r);const[i,s]=this.ratchetEncrypt(JSON.stringify(r)),o=q.getConversationKey(this.state.ourCurrentNostrKey.privateKey,this.state.theirNextNostrPublicKey),c=q.encrypt(JSON.stringify(i),o);return{event:ee({content:s,kind:$e,tags:[["header",c]],created_at:Math.floor(n/1e3)},this.state.ourCurrentNostrKey.privateKey),innerEvent:r}}onEvent(t){const n=this.currentInternalSubscriptionId++;return this.internalSubscriptions.set(n,t),this.subscribeToNostrEvents(),()=>this.internalSubscriptions.delete(n)}close(){var t,n,r;(t=this.nostrUnsubscribe)==null||t.call(this),(n=this.nostrNextUnsubscribe)==null||n.call(this),(r=this.skippedSubscription)==null||r.call(this),this.internalSubscriptions.clear()}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,previousChainLength:this.state.previousSendingChainMessageCount},q.encrypt(t,r)]}ratchetDecrypt(t,n,r){const i=this.trySkippedMessageKeys(t,n,r);if(i)return i;this.skipMessageKeys(t.number,r);const[s,o]=Te(this.state.receivingChainKey,new Uint8Array([1]),2);return this.state.receivingChainKey=s,this.state.receivingChainMessageNumber++,q.decrypt(n,o)}ratchetStep(){this.state.previousSendingChainMessageCount=this.state.sendingChainMessageNumber,this.state.sendingChainMessageNumber=0,this.state.receivingChainMessageNumber=0;const t=q.getConversationKey(this.state.ourNextNostrKey.privateKey,this.state.theirNextNostrPublicKey),[n,r]=Te(this.state.rootKey,t,2);this.state.receivingChainKey=r,this.state.ourCurrentNostrKey=this.state.ourNextNostrKey;const i=Le();this.state.ourNextNostrKey={publicKey:ue(i),privateKey:i};const s=q.getConversationKey(this.state.ourNextNostrKey.privateKey,this.state.theirNextNostrPublicKey),[o,c]=Te(n,s,2);this.state.rootKey=o,this.state.sendingChainKey=c}skipMessageKeys(t,n){if(!(t<=this.state.receivingChainMessageNumber)){if(t>this.state.receivingChainMessageNumber+cu)throw new Error("Too many skipped messages");if(!this.state.skippedKeys[n]){if(this.state.skippedKeys[n]={headerKeys:[],messageKeys:{}},this.state.ourCurrentNostrKey){const i=q.getConversationKey(this.state.ourCurrentNostrKey.privateKey,n);this.state.skippedKeys[n].headerKeys.includes(i)||this.state.skippedKeys[n].headerKeys.push(i)}const r=q.getConversationKey(this.state.ourNextNostrKey.privateKey,n);this.state.skippedKeys[n].headerKeys.includes(r)||this.state.skippedKeys[n].headerKeys.push(r)}for(;this.state.receivingChainMessageNumber<t;){const[r,i]=Te(this.state.receivingChainKey,new Uint8Array([1]),2);this.state.receivingChainKey=r,this.state.skippedKeys[n].messageKeys[this.state.receivingChainMessageNumber]=i,this.state.receivingChainMessageNumber++}}}trySkippedMessageKeys(t,n,r){const i=this.state.skippedKeys[r];if(!i)return null;const s=i.messageKeys[t.number];return s?(delete i.messageKeys[t.number],Object.keys(i.messageKeys).length===0&&delete this.state.skippedKeys[r],q.decrypt(n,s)):null}decryptHeader(t){const n=t.tags[0][1];if(this.state.ourCurrentNostrKey){const s=q.getConversationKey(this.state.ourCurrentNostrKey.privateKey,t.pubkey);try{return[JSON.parse(q.decrypt(n,s)),!1,!1]}catch{}}const r=q.getConversationKey(this.state.ourNextNostrKey.privateKey,t.pubkey);try{return[JSON.parse(q.decrypt(n,r)),!0,!1]}catch{}const i=this.state.skippedKeys[t.pubkey];if(i!=null&&i.headerKeys)for(const s of i.headerKeys)try{return[JSON.parse(q.decrypt(n,s)),!1,!0]}catch{}throw new Error("Failed to decrypt header with current and skipped header keys")}handleNostrEvent(t){var i,s;const n=xi(this.state);let r=!1;try{const[o,c,a]=this.decryptHeader(t);if(!a&&this.state.theirNextNostrPublicKey!==o.nextPublicKey&&(this.state.theirCurrentNostrPublicKey=this.state.theirNextNostrPublicKey,this.state.theirNextNostrPublicKey=o.nextPublicKey,r=!0),!a)c&&(this.skipMessageKeys(o.previousChainLength,t.pubkey),this.ratchetStep());else if(!((i=this.state.skippedKeys[t.pubkey])!=null&&i.messageKeys[o.number]))return;const l=this.ratchetDecrypt(o,t.content,t.pubkey),f=JSON.parse(l);if(!pt(f)){this.state=n;return}if(f.id!==ze(f)){this.state=n;return}r&&((s=this.nostrUnsubscribe)==null||s.call(this),this.nostrUnsubscribe=this.nostrNextUnsubscribe,this.nostrNextUnsubscribe=this.nostrSubscribe({authors:[this.state.theirNextNostrPublicKey],kinds:[$e]},u=>this.handleNostrEvent(u))),this.internalSubscriptions.forEach(u=>u(f,t))}catch(o){if(this.state=n,o instanceof Error&&(o.message.includes("Failed to decrypt header")||o.message==="invalid MAC"))return;throw o}}subscribeToNostrEvents(){if(this.nostrNextUnsubscribe)return;this.nostrNextUnsubscribe=this.nostrSubscribe({authors:[this.state.theirNextNostrPublicKey],kinds:[$e]},n=>this.handleNostrEvent(n)),this.state.theirCurrentNostrPublicKey&&(this.nostrUnsubscribe=this.nostrSubscribe({authors:[this.state.theirCurrentNostrPublicKey],kinds:[$e]},n=>this.handleNostrEvent(n)));const t=Object.keys(this.state.skippedKeys);t.length&&(this.skippedSubscription=this.nostrSubscribe({authors:t,kinds:[$e]},n=>this.handleNostrEvent(n)))}}new TextDecoder("utf-8"),new TextEncoder;function Nt(e,t){const n=Ue.getSharedSecret(e,"02"+t).subarray(1,33);return rn(fe,n,"nip44-v2")}const lu=2*24*60*60,fu=()=>Math.round(Date.now()/1e3),hu=()=>Math.round(fu()-Math.random()*lu);class Re{constructor(t,n,r,i,s,o,c=[]){this.inviterEphemeralPublicKey=t,this.sharedSecret=n,this.inviter=r,this.inviterEphemeralPrivateKey=i,this.deviceId=s,this.maxUses=o,this.usedBy=c}static createNew(t,n,r){if(!t)throw new Error("Inviter public key is required");const i=Le(),s=ue(i),o=H(Le());return new Re(s,o,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 s;try{s=JSON.parse(i)}catch(l){throw new Error("Invite data in URL hash is not valid JSON: "+l)}const{inviter:o,ephemeralKey:c,sharedSecret:a}=s;if(!o||!c||!a)throw new Error("Missing required fields (inviter, ephemeralKey, sharedSecret) in invite data.");return new Re(c,a,o)}static deserialize(t){const n=JSON.parse(t);return new Re(n.inviterEphemeralPublicKey,n.sharedSecret,n.inviter,n.inviterEphemeralPrivateKey?new Uint8Array(n.inviterEphemeralPrivateKey):void 0,n.deviceId,n.maxUses,n.usedBy)}static fromEvent(t){var a,l,f,u;if(!t.sig)throw new Error("Event is not signed");if(!wt(t))throw new Error("Event signature is invalid");const{tags:n}=t;if(!n)throw new Error("Invalid invite event: missing tags");const r=(a=n.find(([p])=>p==="ephemeralKey"))==null?void 0:a[1],i=(l=n.find(([p])=>p==="sharedSecret"))==null?void 0:l[1],s=t.pubkey,o=(f=n.find(([p])=>p==="d"))==null?void 0:f[1],c=(u=o==null?void 0:o.split("/"))==null?void 0:u[2];if(!r||!i)throw new Error("Invalid invite event: missing session key or sharedSecret");return new Re(r,i,s,void 0,c)}static fromUser(t,n,r){const i={kinds:[Kt],authors:[t],"#l":["double-ratchet/invites"]},s=new Set;return n(i,c=>{if(c.pubkey!==t){console.error("Got invite event from wrong user",c.pubkey,"expected",t);return}if(!s.has(c.id)){s.add(c.id);try{const a=Re.fromEvent(c);r(a)}catch{}}})}serialize(){return JSON.stringify({inviterEphemeralPublicKey:this.inviterEphemeralPublicKey,sharedSecret:this.sharedSecret,inviter:this.inviter,inviterEphemeralPrivateKey:this.inviterEphemeralPrivateKey?Array.from(this.inviterEphemeralPrivateKey):void 0,deviceId:this.deviceId,maxUses:this.maxUses,usedBy:this.usedBy})}getUrl(t="https://iris.to"){const n={inviter:this.inviter,ephemeralKey:this.inviterEphemeralPublicKey,sharedSecret:this.sharedSecret},r=new URL(t);return r.hash=encodeURIComponent(JSON.stringify(n)),r.toString()}getEvent(){if(!this.deviceId)throw new Error("Device ID is required");return{kind:Kt,pubkey:this.inviter,content:"",created_at:Math.floor(Date.now()/1e3),tags:[["ephemeralKey",this.inviterEphemeralPublicKey],["sharedSecret",this.sharedSecret],["d","double-ratchet/invites/"+this.deviceId],["l","double-ratchet/invites"]]}}getDeletionEvent(){if(!this.deviceId)throw new Error("Device ID is required");return{kind:Kt,pubkey:this.inviter,content:"",created_at:Math.floor(Date.now()/1e3),tags:[["ephemeralKey",this.inviterEphemeralPublicKey],["sharedSecret",this.sharedSecret],["d","double-ratchet/invites/"+this.deviceId]]}}async accept(t,n,r,i){const s=Le(),o=ue(s),c=this.inviter||this.inviterEphemeralPublicKey,a=V(this.sharedSecret),l=et.init(t,this.inviterEphemeralPublicKey,s,!0,a,void 0),f=typeof r=="function"?r:(m,S)=>Promise.resolve(q.encrypt(m,Nt(r,S))),u=JSON.stringify({sessionKey:o,deviceId:i}),p=await f(u,c),w={pubkey:n,content:await q.encrypt(p,a),created_at:Math.floor(Date.now()/1e3)},g=JSON.stringify(w),h=Le(),d=ue(h),y={kind:kn,pubkey:d,content:q.encrypt(g,Nt(h,this.inviterEphemeralPublicKey)),created_at:hu(),tags:[["p",this.inviterEphemeralPublicKey]]};return{session:l,event:ee(y,h)}}listen(t,n,r){if(!this.inviterEphemeralPrivateKey)throw new Error("Inviter session key is not available");const i={kinds:[kn],"#p":[this.inviterEphemeralPublicKey]};return n(i,async s=>{try{if(this.maxUses&&this.usedBy.length>=this.maxUses)return;const o=await q.decrypt(s.content,Nt(this.inviterEphemeralPrivateKey,s.pubkey)),c=JSON.parse(o),a=V(this.sharedSecret),l=c.pubkey;this.usedBy.push(l);const f=await q.decrypt(c.content,a),p=await(typeof t=="function"?t:(y,m)=>Promise.resolve(q.decrypt(y,Nt(t,m))))(f,l);let w,g;try{const y=JSON.parse(p);w=y.sessionKey,g=y.deviceId}catch{w=p}const h=s.id,d=et.init(n,w,this.inviterEphemeralPrivateKey,!1,a,h);r(d,l,g)}catch{}})}}P.CHAT_MESSAGE_KIND=Ei,P.INVITE_EVENT_KIND=Kt,P.INVITE_RESPONSE_KIND=kn,P.Invite=Re,P.MAX_SKIP=tu,P.MESSAGE_EVENT_KIND=$e,P.Session=et,P.createEventStream=su,P.deepCopyState=xi,P.deserializeSessionState=iu,P.getMillisecondTimestamp=au,P.kdf=Te,P.serializeSessionState=ru,P.skippedMessageIndexKey=ou,Object.defineProperty(P,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(L,Y){typeof exports=="object"&&typeof module<"u"?Y(exports):typeof define=="function"&&define.amd?define(["exports"],Y):(L=typeof globalThis<"u"?globalThis:L||self,Y(L["nostr-double-ratchet"]={}))})(this,function(L){"use strict";var gu=Object.defineProperty;var wu=(L,Y,Ue)=>Y in L?gu(L,Y,{enumerable:!0,configurable:!0,writable:!0,value:Ue}):L[Y]=Ue;var $=(L,Y,Ue)=>wu(L,typeof Y!="symbol"?Y+"":Y,Ue);function Y(t){if(!Number.isSafeInteger(t)||t<0)throw new Error(`Wrong positive integer: ${t}`)}function Ue(t,...e){if(!(t instanceof Uint8Array))throw new Error("Expected Uint8Array");if(e.length>0&&!e.includes(t.length))throw new Error(`Expected Uint8Array of length ${e}, not of length=${t.length}`)}function ki(t){if(typeof t!="function"||typeof t.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");Y(t.outputLen),Y(t.blockLen)}function rt(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}function Bi(t,e){Ue(t);const n=e.outputLen;if(t.length<n)throw new Error(`digestInto() expects output buffer of length at least ${n}`)}const Nt=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Rn=t=>t instanceof Uint8Array,At=t=>new DataView(t.buffer,t.byteOffset,t.byteLength),oe=(t,e)=>t<<32-e|t>>>e;if(!(new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68))throw new Error("Non little-endian hardware is not supported");function _i(t){if(typeof t!="string")throw new Error(`utf8ToBytes expected string, got ${typeof t}`);return new Uint8Array(new TextEncoder().encode(t))}function It(t){if(typeof t=="string"&&(t=_i(t)),!Rn(t))throw new Error(`expected Uint8Array, got ${typeof t}`);return t}function Ri(...t){const e=new Uint8Array(t.reduce((r,i)=>r+i.length,0));let n=0;return t.forEach(r=>{if(!Rn(r))throw new Error("Uint8Array expected");e.set(r,n),n+=r.length}),e}let $n=class{clone(){return this._cloneInto()}};function $i(t){const e=r=>t().update(It(r)).digest(),n=t();return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=()=>t(),e}function Tn(t=32){if(Nt&&typeof Nt.getRandomValues=="function")return Nt.getRandomValues(new Uint8Array(t));throw new Error("crypto.getRandomValues must be defined")}function Ti(t,e,n,r){if(typeof t.setBigUint64=="function")return t.setBigUint64(e,n,r);const i=BigInt(32),s=BigInt(4294967295),o=Number(n>>i&s),c=Number(n&s),a=r?4:0,u=r?0:4;t.setUint32(e+a,o,r),t.setUint32(e+u,c,r)}let Li=class extends $n{constructor(e,n,r,i){super(),this.blockLen=e,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(e),this.view=At(this.buffer)}update(e){rt(this);const{view:n,buffer:r,blockLen:i}=this;e=It(e);const s=e.length;for(let o=0;o<s;){const c=Math.min(i-this.pos,s-o);if(c===i){const a=At(e);for(;i<=s-o;o+=i)this.process(a,o);continue}r.set(e.subarray(o,o+c),this.pos),this.pos+=c,o+=c,this.pos===i&&(this.process(n,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){rt(this),Bi(e,this),this.finished=!0;const{buffer:n,view:r,blockLen:i,isLE:s}=this;let{pos:o}=this;n[o++]=128,this.buffer.subarray(o).fill(0),this.padOffset>i-o&&(this.process(r,0),o=0);for(let l=o;l<i;l++)n[l]=0;Ti(r,i-8,BigInt(this.length*8),s),this.process(r,0);const c=At(e),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const u=a/4,h=this.get();if(u>h.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<u;l++)c.setUint32(4*l,h[l],s)}digest(){const{buffer:e,outputLen:n}=this;this.digestInto(e);const r=e.slice(0,n);return this.destroy(),r}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());const{blockLen:n,buffer:r,length:i,finished:s,destroyed:o,pos:c}=this;return e.length=i,e.pos=c,e.finished=s,e.destroyed=o,i%n&&e.buffer.set(r),e}};const Mi=(t,e,n)=>t&e^~t&n,Pi=(t,e,n)=>t&e^t&n^e&n,Oi=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),be=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),me=new Uint32Array(64);let Hi=class extends Li{constructor(){super(64,32,8,!1),this.A=be[0]|0,this.B=be[1]|0,this.C=be[2]|0,this.D=be[3]|0,this.E=be[4]|0,this.F=be[5]|0,this.G=be[6]|0,this.H=be[7]|0}get(){const{A:e,B:n,C:r,D:i,E:s,F:o,G:c,H:a}=this;return[e,n,r,i,s,o,c,a]}set(e,n,r,i,s,o,c,a){this.A=e|0,this.B=n|0,this.C=r|0,this.D=i|0,this.E=s|0,this.F=o|0,this.G=c|0,this.H=a|0}process(e,n){for(let l=0;l<16;l++,n+=4)me[l]=e.getUint32(n,!1);for(let l=16;l<64;l++){const y=me[l-15],w=me[l-2],g=oe(y,7)^oe(y,18)^y>>>3,d=oe(w,17)^oe(w,19)^w>>>10;me[l]=d+me[l-7]+g+me[l-16]|0}let{A:r,B:i,C:s,D:o,E:c,F:a,G:u,H:h}=this;for(let l=0;l<64;l++){const y=oe(c,6)^oe(c,11)^oe(c,25),w=h+y+Mi(c,a,u)+Oi[l]+me[l]|0,d=(oe(r,2)^oe(r,13)^oe(r,22))+Pi(r,i,s)|0;h=u,u=a,a=c,c=o+w|0,o=s,s=i,i=r,r=w+d|0}r=r+this.A|0,i=i+this.B|0,s=s+this.C|0,o=o+this.D|0,c=c+this.E|0,a=a+this.F|0,u=u+this.G|0,h=h+this.H|0,this.set(r,i,s,o,c,a,u,h)}roundClean(){me.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};const Ct=$i(()=>new Hi);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Ln=BigInt(0),it=BigInt(1),Di=BigInt(2),st=t=>t instanceof Uint8Array,qi=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function He(t){if(!st(t))throw new Error("Uint8Array expected");let e="";for(let n=0;n<t.length;n++)e+=qi[t[n]];return e}function Mn(t){const e=t.toString(16);return e.length&1?`0${e}`:e}function Ut(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);return BigInt(t===""?"0":`0x${t}`)}function De(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);const e=t.length;if(e%2)throw new Error("padded hex string expected, got unpadded hex of length "+e);const n=new Uint8Array(e/2);for(let r=0;r<n.length;r++){const i=r*2,s=t.slice(i,i+2),o=Number.parseInt(s,16);if(Number.isNaN(o)||o<0)throw new Error("Invalid byte sequence");n[r]=o}return n}function X(t){return Ut(He(t))}function kt(t){if(!st(t))throw new Error("Uint8Array expected");return Ut(He(Uint8Array.from(t).reverse()))}function Ee(t,e){return De(t.toString(16).padStart(e*2,"0"))}function Bt(t,e){return Ee(t,e).reverse()}function ji(t){return De(Mn(t))}function G(t,e,n){let r;if(typeof e=="string")try{r=De(e)}catch(s){throw new Error(`${t} must be valid hex string, got "${e}". Cause: ${s}`)}else if(st(e))r=Uint8Array.from(e);else throw new Error(`${t} must be hex string or Uint8Array`);const i=r.length;if(typeof n=="number"&&i!==n)throw new Error(`${t} expected ${n} bytes, got ${i}`);return r}function ke(...t){const e=new Uint8Array(t.reduce((r,i)=>r+i.length,0));let n=0;return t.forEach(r=>{if(!st(r))throw new Error("Uint8Array expected");e.set(r,n),n+=r.length}),e}function zi(t,e){if(t.length!==e.length)return!1;for(let n=0;n<t.length;n++)if(t[n]!==e[n])return!1;return!0}function Vi(t){if(typeof t!="string")throw new Error(`utf8ToBytes expected string, got ${typeof t}`);return new Uint8Array(new TextEncoder().encode(t))}function Wi(t){let e;for(e=0;t>Ln;t>>=it,e+=1);return e}function Fi(t,e){return t>>BigInt(e)&it}const Zi=(t,e,n)=>t|(n?it:Ln)<<BigInt(e),_t=t=>(Di<<BigInt(t-1))-it,Rt=t=>new Uint8Array(t),Pn=t=>Uint8Array.from(t);function On(t,e,n){if(typeof t!="number"||t<2)throw new Error("hashLen must be a number");if(typeof e!="number"||e<2)throw new Error("qByteLen must be a number");if(typeof n!="function")throw new Error("hmacFn must be a function");let r=Rt(t),i=Rt(t),s=0;const o=()=>{r.fill(1),i.fill(0),s=0},c=(...l)=>n(i,r,...l),a=(l=Rt())=>{i=c(Pn([0]),l),r=c(),l.length!==0&&(i=c(Pn([1]),l),r=c())},u=()=>{if(s++>=1e3)throw new Error("drbg: tried 1000 values");let l=0;const y=[];for(;l<e;){r=c();const w=r.slice();y.push(w),l+=r.length}return ke(...y)};return(l,y)=>{o(),a(l);let w;for(;!(w=y(u()));)a();return o(),w}}const Gi={bigint:t=>typeof t=="bigint",function:t=>typeof t=="function",boolean:t=>typeof t=="boolean",string:t=>typeof t=="string",stringOrUint8Array:t=>typeof t=="string"||t instanceof Uint8Array,isSafeInteger:t=>Number.isSafeInteger(t),array:t=>Array.isArray(t),field:(t,e)=>e.Fp.isValid(t),hash:t=>typeof t=="function"&&Number.isSafeInteger(t.outputLen)};function Ye(t,e,n={}){const r=(i,s,o)=>{const c=Gi[s];if(typeof c!="function")throw new Error(`Invalid validator "${s}", expected function`);const a=t[i];if(!(o&&a===void 0)&&!c(a,t))throw new Error(`Invalid param ${String(i)}=${a} (${typeof a}), expected ${s}`)};for(const[i,s]of Object.entries(e))r(i,s,!1);for(const[i,s]of Object.entries(n))r(i,s,!0);return t}const Ji=Object.freeze(Object.defineProperty({__proto__:null,bitGet:Fi,bitLen:Wi,bitMask:_t,bitSet:Zi,bytesToHex:He,bytesToNumberBE:X,bytesToNumberLE:kt,concatBytes:ke,createHmacDrbg:On,ensureBytes:G,equalBytes:zi,hexToBytes:De,hexToNumber:Ut,numberToBytesBE:Ee,numberToBytesLE:Bt,numberToHexUnpadded:Mn,numberToVarBytesBE:ji,utf8ToBytes:Vi,validateObject:Ye},Symbol.toStringTag,{value:"Module"}));/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const F=BigInt(0),V=BigInt(1),Be=BigInt(2),Yi=BigInt(3),$t=BigInt(4),Hn=BigInt(5),Dn=BigInt(8);BigInt(9),BigInt(16);function Z(t,e){const n=t%e;return n>=F?n:e+n}function Xi(t,e,n){if(n<=F||e<F)throw new Error("Expected power/modulo > 0");if(n===V)return F;let r=V;for(;e>F;)e&V&&(r=r*t%n),t=t*t%n,e>>=V;return r}function Q(t,e,n){let r=t;for(;e-- >F;)r*=r,r%=n;return r}function Tt(t,e){if(t===F||e<=F)throw new Error(`invert: expected positive integers, got n=${t} mod=${e}`);let n=Z(t,e),r=e,i=F,s=V;for(;n!==F;){const c=r/n,a=r%n,u=i-s*c;r=n,n=a,i=s,s=u}if(r!==V)throw new Error("invert: does not exist");return Z(i,e)}function Qi(t){const e=(t-V)/Be;let n,r,i;for(n=t-V,r=0;n%Be===F;n/=Be,r++);for(i=Be;i<t&&Xi(i,e,t)!==t-V;i++);if(r===1){const o=(t+V)/$t;return function(a,u){const h=a.pow(u,o);if(!a.eql(a.sqr(h),u))throw new Error("Cannot find square root");return h}}const s=(n+V)/Be;return function(c,a){if(c.pow(a,e)===c.neg(c.ONE))throw new Error("Cannot find square root");let u=r,h=c.pow(c.mul(c.ONE,i),n),l=c.pow(a,s),y=c.pow(a,n);for(;!c.eql(y,c.ONE);){if(c.eql(y,c.ZERO))return c.ZERO;let w=1;for(let d=c.sqr(y);w<u&&!c.eql(d,c.ONE);w++)d=c.sqr(d);const g=c.pow(h,V<<BigInt(u-w-1));h=c.sqr(g),l=c.mul(l,g),y=c.mul(y,h),u=w}return l}}function es(t){if(t%$t===Yi){const e=(t+V)/$t;return function(r,i){const s=r.pow(i,e);if(!r.eql(r.sqr(s),i))throw new Error("Cannot find square root");return s}}if(t%Dn===Hn){const e=(t-Hn)/Dn;return function(r,i){const s=r.mul(i,Be),o=r.pow(s,e),c=r.mul(i,o),a=r.mul(r.mul(c,Be),o),u=r.mul(c,r.sub(a,r.ONE));if(!r.eql(r.sqr(u),i))throw new Error("Cannot find square root");return u}}return Qi(t)}const ts=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function ns(t){const e={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},n=ts.reduce((r,i)=>(r[i]="function",r),e);return Ye(t,n)}function rs(t,e,n){if(n<F)throw new Error("Expected power > 0");if(n===F)return t.ONE;if(n===V)return e;let r=t.ONE,i=e;for(;n>F;)n&V&&(r=t.mul(r,i)),i=t.sqr(i),n>>=V;return r}function is(t,e){const n=new Array(e.length),r=e.reduce((s,o,c)=>t.is0(o)?s:(n[c]=s,t.mul(s,o)),t.ONE),i=t.inv(r);return e.reduceRight((s,o,c)=>t.is0(o)?s:(n[c]=t.mul(s,n[c]),t.mul(s,o)),i),n}function qn(t,e){const n=e!==void 0?e:t.toString(2).length,r=Math.ceil(n/8);return{nBitLength:n,nByteLength:r}}function ss(t,e,n=!1,r={}){if(t<=F)throw new Error(`Expected Field ORDER > 0, got ${t}`);const{nBitLength:i,nByteLength:s}=qn(t,e);if(s>2048)throw new Error("Field lengths over 2048 bytes are not supported");const o=es(t),c=Object.freeze({ORDER:t,BITS:i,BYTES:s,MASK:_t(i),ZERO:F,ONE:V,create:a=>Z(a,t),isValid:a=>{if(typeof a!="bigint")throw new Error(`Invalid field element: expected bigint, got ${typeof a}`);return F<=a&&a<t},is0:a=>a===F,isOdd:a=>(a&V)===V,neg:a=>Z(-a,t),eql:(a,u)=>a===u,sqr:a=>Z(a*a,t),add:(a,u)=>Z(a+u,t),sub:(a,u)=>Z(a-u,t),mul:(a,u)=>Z(a*u,t),pow:(a,u)=>rs(c,a,u),div:(a,u)=>Z(a*Tt(u,t),t),sqrN:a=>a*a,addN:(a,u)=>a+u,subN:(a,u)=>a-u,mulN:(a,u)=>a*u,inv:a=>Tt(a,t),sqrt:r.sqrt||(a=>o(c,a)),invertBatch:a=>is(c,a),cmov:(a,u,h)=>h?u:a,toBytes:a=>n?Bt(a,s):Ee(a,s),fromBytes:a=>{if(a.length!==s)throw new Error(`Fp.fromBytes: expected ${s}, got ${a.length}`);return n?kt(a):X(a)}});return Object.freeze(c)}function jn(t){if(typeof t!="bigint")throw new Error("field order must be bigint");const e=t.toString(2).length;return Math.ceil(e/8)}function zn(t){const e=jn(t);return e+Math.ceil(e/2)}function os(t,e,n=!1){const r=t.length,i=jn(e),s=zn(e);if(r<16||r<s||r>1024)throw new Error(`expected ${s}-1024 bytes of input, got ${r}`);const o=n?X(t):kt(t),c=Z(o,e-V)+V;return n?Bt(c,i):Ee(c,i)}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const as=BigInt(0),Lt=BigInt(1);function cs(t,e){const n=(i,s)=>{const o=s.negate();return i?o:s},r=i=>{const s=Math.ceil(e/i)+1,o=2**(i-1);return{windows:s,windowSize:o}};return{constTimeNegate:n,unsafeLadder(i,s){let o=t.ZERO,c=i;for(;s>as;)s&Lt&&(o=o.add(c)),c=c.double(),s>>=Lt;return o},precomputeWindow(i,s){const{windows:o,windowSize:c}=r(s),a=[];let u=i,h=u;for(let l=0;l<o;l++){h=u,a.push(h);for(let y=1;y<c;y++)h=h.add(u),a.push(h);u=h.double()}return a},wNAF(i,s,o){const{windows:c,windowSize:a}=r(i);let u=t.ZERO,h=t.BASE;const l=BigInt(2**i-1),y=2**i,w=BigInt(i);for(let g=0;g<c;g++){const d=g*a;let f=Number(o&l);o>>=w,f>a&&(f-=y,o+=Lt);const p=d,m=d+Math.abs(f)-1,N=g%2!==0,B=f<0;f===0?h=h.add(n(N,s[p])):u=u.add(n(B,s[m]))}return{p:u,f:h}},wNAFCached(i,s,o,c){const a=i._WINDOW_SIZE||1;let u=s.get(i);return u||(u=this.precomputeWindow(i,a),a!==1&&s.set(i,c(u))),this.wNAF(a,u,o)}}}function Vn(t){return ns(t.Fp),Ye(t,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...qn(t.n,t.nBitLength),...t,p:t.Fp.ORDER})}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function us(t){const e=Vn(t);Ye(e,{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}=e;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({...e})}const{bytesToNumberBE:ls,hexToBytes:hs}=Ji,_e={Err:class extends Error{constructor(e=""){super(e)}},_parseInt(t){const{Err:e}=_e;if(t.length<2||t[0]!==2)throw new e("Invalid signature integer tag");const n=t[1],r=t.subarray(2,n+2);if(!n||r.length!==n)throw new e("Invalid signature integer: wrong length");if(r[0]&128)throw new e("Invalid signature integer: negative");if(r[0]===0&&!(r[1]&128))throw new e("Invalid signature integer: unnecessary leading zero");return{d:ls(r),l:t.subarray(n+2)}},toSig(t){const{Err:e}=_e,n=typeof t=="string"?hs(t):t;if(!(n instanceof Uint8Array))throw new Error("ui8a expected");let r=n.length;if(r<2||n[0]!=48)throw new e("Invalid signature tag");if(n[1]!==r-2)throw new e("Invalid signature: incorrect length");const{d:i,l:s}=_e._parseInt(n.subarray(2)),{d:o,l:c}=_e._parseInt(s);if(c.length)throw new e("Invalid signature: left bytes after parsing");return{r:i,s:o}},hexFromSig(t){const e=u=>Number.parseInt(u[0],16)&8?"00"+u:u,n=u=>{const h=u.toString(16);return h.length&1?`0${h}`:h},r=e(n(t.s)),i=e(n(t.r)),s=r.length/2,o=i.length/2,c=n(s),a=n(o);return`30${n(o+s+4)}02${a}${i}02${c}${r}`}},he=BigInt(0),ee=BigInt(1);BigInt(2);const Wn=BigInt(3);BigInt(4);function ds(t){const e=us(t),{Fp:n}=e,r=e.toBytes||((g,d,f)=>{const p=d.toAffine();return ke(Uint8Array.from([4]),n.toBytes(p.x),n.toBytes(p.y))}),i=e.fromBytes||(g=>{const d=g.subarray(1),f=n.fromBytes(d.subarray(0,n.BYTES)),p=n.fromBytes(d.subarray(n.BYTES,2*n.BYTES));return{x:f,y:p}});function s(g){const{a:d,b:f}=e,p=n.sqr(g),m=n.mul(p,g);return n.add(n.add(m,n.mul(g,d)),f)}if(!n.eql(n.sqr(e.Gy),s(e.Gx)))throw new Error("bad generator point: equation left != right");function o(g){return typeof g=="bigint"&&he<g&&g<e.n}function c(g){if(!o(g))throw new Error("Expected valid bigint: 0 < bigint < curve.n")}function a(g){const{allowedPrivateKeyLengths:d,nByteLength:f,wrapPrivateKey:p,n:m}=e;if(d&&typeof g!="bigint"){if(g instanceof Uint8Array&&(g=He(g)),typeof g!="string"||!d.includes(g.length))throw new Error("Invalid key");g=g.padStart(f*2,"0")}let N;try{N=typeof g=="bigint"?g:X(G("private key",g,f))}catch{throw new Error(`private key must be ${f} bytes, hex or bigint, not ${typeof g}`)}return p&&(N=Z(N,m)),c(N),N}const u=new Map;function h(g){if(!(g instanceof l))throw new Error("ProjectivePoint expected")}class l{constructor(d,f,p){if(this.px=d,this.py=f,this.pz=p,d==null||!n.isValid(d))throw new Error("x required");if(f==null||!n.isValid(f))throw new Error("y required");if(p==null||!n.isValid(p))throw new Error("z required")}static fromAffine(d){const{x:f,y:p}=d||{};if(!d||!n.isValid(f)||!n.isValid(p))throw new Error("invalid affine point");if(d instanceof l)throw new Error("projective point not allowed");const m=N=>n.eql(N,n.ZERO);return m(f)&&m(p)?l.ZERO:new l(f,p,n.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(d){const f=n.invertBatch(d.map(p=>p.pz));return d.map((p,m)=>p.toAffine(f[m])).map(l.fromAffine)}static fromHex(d){const f=l.fromAffine(i(G("pointHex",d)));return f.assertValidity(),f}static fromPrivateKey(d){return l.BASE.multiply(a(d))}_setWindowSize(d){this._WINDOW_SIZE=d,u.delete(this)}assertValidity(){if(this.is0()){if(e.allowInfinityPoint&&!n.is0(this.py))return;throw new Error("bad point: ZERO")}const{x:d,y:f}=this.toAffine();if(!n.isValid(d)||!n.isValid(f))throw new Error("bad point: x or y not FE");const p=n.sqr(f),m=s(d);if(!n.eql(p,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:d}=this.toAffine();if(n.isOdd)return!n.isOdd(d);throw new Error("Field doesn't support isOdd")}equals(d){h(d);const{px:f,py:p,pz:m}=this,{px:N,py:B,pz:C}=d,E=n.eql(n.mul(f,C),n.mul(N,m)),x=n.eql(n.mul(p,C),n.mul(B,m));return E&&x}negate(){return new l(this.px,n.neg(this.py),this.pz)}double(){const{a:d,b:f}=e,p=n.mul(f,Wn),{px:m,py:N,pz:B}=this;let C=n.ZERO,E=n.ZERO,x=n.ZERO,S=n.mul(m,m),H=n.mul(N,N),k=n.mul(B,B),A=n.mul(m,N);return A=n.add(A,A),x=n.mul(m,B),x=n.add(x,x),C=n.mul(d,x),E=n.mul(p,k),E=n.add(C,E),C=n.sub(H,E),E=n.add(H,E),E=n.mul(C,E),C=n.mul(A,C),x=n.mul(p,x),k=n.mul(d,k),A=n.sub(S,k),A=n.mul(d,A),A=n.add(A,x),x=n.add(S,S),S=n.add(x,S),S=n.add(S,k),S=n.mul(S,A),E=n.add(E,S),k=n.mul(N,B),k=n.add(k,k),S=n.mul(k,A),C=n.sub(C,S),x=n.mul(k,H),x=n.add(x,x),x=n.add(x,x),new l(C,E,x)}add(d){h(d);const{px:f,py:p,pz:m}=this,{px:N,py:B,pz:C}=d;let E=n.ZERO,x=n.ZERO,S=n.ZERO;const H=e.a,k=n.mul(e.b,Wn);let A=n.mul(f,N),M=n.mul(p,B),P=n.mul(m,C),z=n.add(f,p),v=n.add(N,B);z=n.mul(z,v),v=n.add(A,M),z=n.sub(z,v),v=n.add(f,m);let b=n.add(N,C);return v=n.mul(v,b),b=n.add(A,P),v=n.sub(v,b),b=n.add(p,m),E=n.add(B,C),b=n.mul(b,E),E=n.add(M,P),b=n.sub(b,E),S=n.mul(H,v),E=n.mul(k,P),S=n.add(E,S),E=n.sub(M,S),S=n.add(M,S),x=n.mul(E,S),M=n.add(A,A),M=n.add(M,A),P=n.mul(H,P),v=n.mul(k,v),M=n.add(M,P),P=n.sub(A,P),P=n.mul(H,P),v=n.add(v,P),A=n.mul(M,v),x=n.add(x,A),A=n.mul(b,v),E=n.mul(z,E),E=n.sub(E,A),A=n.mul(z,M),S=n.mul(b,S),S=n.add(S,A),new l(E,x,S)}subtract(d){return this.add(d.negate())}is0(){return this.equals(l.ZERO)}wNAF(d){return w.wNAFCached(this,u,d,f=>{const p=n.invertBatch(f.map(m=>m.pz));return f.map((m,N)=>m.toAffine(p[N])).map(l.fromAffine)})}multiplyUnsafe(d){const f=l.ZERO;if(d===he)return f;if(c(d),d===ee)return this;const{endo:p}=e;if(!p)return w.unsafeLadder(this,d);let{k1neg:m,k1:N,k2neg:B,k2:C}=p.splitScalar(d),E=f,x=f,S=this;for(;N>he||C>he;)N&ee&&(E=E.add(S)),C&ee&&(x=x.add(S)),S=S.double(),N>>=ee,C>>=ee;return m&&(E=E.negate()),B&&(x=x.negate()),x=new l(n.mul(x.px,p.beta),x.py,x.pz),E.add(x)}multiply(d){c(d);let f=d,p,m;const{endo:N}=e;if(N){const{k1neg:B,k1:C,k2neg:E,k2:x}=N.splitScalar(f);let{p:S,f:H}=this.wNAF(C),{p:k,f:A}=this.wNAF(x);S=w.constTimeNegate(B,S),k=w.constTimeNegate(E,k),k=new l(n.mul(k.px,N.beta),k.py,k.pz),p=S.add(k),m=H.add(A)}else{const{p:B,f:C}=this.wNAF(f);p=B,m=C}return l.normalizeZ([p,m])[0]}multiplyAndAddUnsafe(d,f,p){const m=l.BASE,N=(C,E)=>E===he||E===ee||!C.equals(m)?C.multiplyUnsafe(E):C.multiply(E),B=N(this,f).add(N(d,p));return B.is0()?void 0:B}toAffine(d){const{px:f,py:p,pz:m}=this,N=this.is0();d==null&&(d=N?n.ONE:n.inv(m));const B=n.mul(f,d),C=n.mul(p,d),E=n.mul(m,d);if(N)return{x:n.ZERO,y:n.ZERO};if(!n.eql(E,n.ONE))throw new Error("invZ was invalid");return{x:B,y:C}}isTorsionFree(){const{h:d,isTorsionFree:f}=e;if(d===ee)return!0;if(f)return f(l,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){const{h:d,clearCofactor:f}=e;return d===ee?this:f?f(l,this):this.multiplyUnsafe(e.h)}toRawBytes(d=!0){return this.assertValidity(),r(l,this,d)}toHex(d=!0){return He(this.toRawBytes(d))}}l.BASE=new l(e.Gx,e.Gy,n.ONE),l.ZERO=new l(n.ZERO,n.ONE,n.ZERO);const y=e.nBitLength,w=cs(l,e.endo?Math.ceil(y/2):y);return{CURVE:e,ProjectivePoint:l,normPrivateKeyToScalar:a,weierstrassEquation:s,isWithinCurveOrder:o}}function fs(t){const e=Vn(t);return Ye(e,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...e})}function ys(t){const e=fs(t),{Fp:n,n:r}=e,i=n.BYTES+1,s=2*n.BYTES+1;function o(v){return he<v&&v<n.ORDER}function c(v){return Z(v,r)}function a(v){return Tt(v,r)}const{ProjectivePoint:u,normPrivateKeyToScalar:h,weierstrassEquation:l,isWithinCurveOrder:y}=ds({...e,toBytes(v,b,K){const U=b.toAffine(),I=n.toBytes(U.x),R=ke;return K?R(Uint8Array.from([b.hasEvenY()?2:3]),I):R(Uint8Array.from([4]),I,n.toBytes(U.y))},fromBytes(v){const b=v.length,K=v[0],U=v.subarray(1);if(b===i&&(K===2||K===3)){const I=X(U);if(!o(I))throw new Error("Point is not on curve");const R=l(I);let O=n.sqrt(R);const T=(O&ee)===ee;return(K&1)===1!==T&&(O=n.neg(O)),{x:I,y:O}}else if(b===s&&K===4){const I=n.fromBytes(U.subarray(0,n.BYTES)),R=n.fromBytes(U.subarray(n.BYTES,2*n.BYTES));return{x:I,y:R}}else throw new Error(`Point of length ${b} was invalid. Expected ${i} compressed bytes or ${s} uncompressed bytes`)}}),w=v=>He(Ee(v,e.nByteLength));function g(v){const b=r>>ee;return v>b}function d(v){return g(v)?c(-v):v}const f=(v,b,K)=>X(v.slice(b,K));class p{constructor(b,K,U){this.r=b,this.s=K,this.recovery=U,this.assertValidity()}static fromCompact(b){const K=e.nByteLength;return b=G("compactSignature",b,K*2),new p(f(b,0,K),f(b,K,2*K))}static fromDER(b){const{r:K,s:U}=_e.toSig(G("DER",b));return new p(K,U)}assertValidity(){if(!y(this.r))throw new Error("r must be 0 < r < CURVE.n");if(!y(this.s))throw new Error("s must be 0 < s < CURVE.n")}addRecoveryBit(b){return new p(this.r,this.s,b)}recoverPublicKey(b){const{r:K,s:U,recovery:I}=this,R=x(G("msgHash",b));if(I==null||![0,1,2,3].includes(I))throw new Error("recovery id invalid");const O=I===2||I===3?K+e.n:K;if(O>=n.ORDER)throw new Error("recovery id 2 or 3 invalid");const T=(I&1)===0?"02":"03",ie=u.fromHex(T+w(O)),Ie=a(O),Fe=c(-R*Ie),nt=c(U*Ie),Ce=u.BASE.multiplyAndAddUnsafe(ie,Fe,nt);if(!Ce)throw new Error("point at infinify");return Ce.assertValidity(),Ce}hasHighS(){return g(this.s)}normalizeS(){return this.hasHighS()?new p(this.r,c(-this.s),this.recovery):this}toDERRawBytes(){return De(this.toDERHex())}toDERHex(){return _e.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return De(this.toCompactHex())}toCompactHex(){return w(this.r)+w(this.s)}}const m={isValidPrivateKey(v){try{return h(v),!0}catch{return!1}},normPrivateKeyToScalar:h,randomPrivateKey:()=>{const v=zn(e.n);return os(e.randomBytes(v),e.n)},precompute(v=8,b=u.BASE){return b._setWindowSize(v),b.multiply(BigInt(3)),b}};function N(v,b=!0){return u.fromPrivateKey(v).toRawBytes(b)}function B(v){const b=v instanceof Uint8Array,K=typeof v=="string",U=(b||K)&&v.length;return b?U===i||U===s:K?U===2*i||U===2*s:v instanceof u}function C(v,b,K=!0){if(B(v))throw new Error("first arg must be private key");if(!B(b))throw new Error("second arg must be public key");return u.fromHex(b).multiply(h(v)).toRawBytes(K)}const E=e.bits2int||function(v){const b=X(v),K=v.length*8-e.nBitLength;return K>0?b>>BigInt(K):b},x=e.bits2int_modN||function(v){return c(E(v))},S=_t(e.nBitLength);function H(v){if(typeof v!="bigint")throw new Error("bigint expected");if(!(he<=v&&v<S))throw new Error(`bigint expected < 2^${e.nBitLength}`);return Ee(v,e.nByteLength)}function k(v,b,K=A){if(["recovered","canonical"].some(Oe=>Oe in K))throw new Error("sign() legacy options not supported");const{hash:U,randomBytes:I}=e;let{lowS:R,prehash:O,extraEntropy:T}=K;R==null&&(R=!0),v=G("msgHash",v),O&&(v=G("prehashed msgHash",U(v)));const ie=x(v),Ie=h(b),Fe=[H(Ie),H(ie)];if(T!=null){const Oe=T===!0?I(n.BYTES):T;Fe.push(G("extraEntropy",Oe))}const nt=ke(...Fe),Ce=ie;function _n(Oe){const Ze=E(Oe);if(!y(Ze))return;const Ii=a(Ze),Ge=u.BASE.multiply(Ze).toAffine(),se=c(Ge.x);if(se===he)return;const Je=c(Ii*c(Ce+se*Ie));if(Je===he)return;let Ci=(Ge.x===se?0:2)|Number(Ge.y&ee),Ui=Je;return R&&g(Je)&&(Ui=d(Je),Ci^=1),new p(se,Ui,Ci)}return{seed:nt,k2sig:_n}}const A={lowS:e.lowS,prehash:!1},M={lowS:e.lowS,prehash:!1};function P(v,b,K=A){const{seed:U,k2sig:I}=k(v,b,K),R=e;return On(R.hash.outputLen,R.nByteLength,R.hmac)(U,I)}u.BASE._setWindowSize(8);function z(v,b,K,U=M){var Ge;const I=v;if(b=G("msgHash",b),K=G("publicKey",K),"strict"in U)throw new Error("options.strict was renamed to lowS");const{lowS:R,prehash:O}=U;let T,ie;try{if(typeof I=="string"||I instanceof Uint8Array)try{T=p.fromDER(I)}catch(se){if(!(se instanceof _e.Err))throw se;T=p.fromCompact(I)}else if(typeof I=="object"&&typeof I.r=="bigint"&&typeof I.s=="bigint"){const{r:se,s:Je}=I;T=new p(se,Je)}else throw new Error("PARSE");ie=u.fromHex(K)}catch(se){if(se.message==="PARSE")throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(R&&T.hasHighS())return!1;O&&(b=e.hash(b));const{r:Ie,s:Fe}=T,nt=x(b),Ce=a(Fe),_n=c(nt*Ce),Oe=c(Ie*Ce),Ze=(Ge=u.BASE.multiplyAndAddUnsafe(ie,_n,Oe))==null?void 0:Ge.toAffine();return Ze?c(Ze.x)===Ie:!1}return{CURVE:e,getPublicKey:N,getSharedSecret:C,sign:P,verify:z,ProjectivePoint:u,Signature:p,utils:m}}let Fn=class extends $n{constructor(e,n){super(),this.finished=!1,this.destroyed=!1,ki(e);const r=It(n);if(this.iHash=e.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,s=new Uint8Array(i);s.set(r.length>i?e.create().update(r).digest():r);for(let o=0;o<s.length;o++)s[o]^=54;this.iHash.update(s),this.oHash=e.create();for(let o=0;o<s.length;o++)s[o]^=106;this.oHash.update(s),s.fill(0)}update(e){return rt(this),this.iHash.update(e),this}digestInto(e){rt(this),Ue(e,this.outputLen),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){const e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||(e=Object.create(Object.getPrototypeOf(this),{}));const{oHash:n,iHash:r,finished:i,destroyed:s,blockLen:o,outputLen:c}=this;return e=e,e.finished=i,e.destroyed=s,e.blockLen=o,e.outputLen=c,e.oHash=n._cloneInto(e.oHash),e.iHash=r._cloneInto(e.iHash),e}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}};const Zn=(t,e,n)=>new Fn(t,e).update(n).digest();Zn.create=(t,e)=>new Fn(t,e);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function ps(t){return{hash:t,hmac:(e,...n)=>Zn(t,e,Ri(...n)),randomBytes:Tn}}function gs(t,e){const n=r=>ys({...t,...ps(r)});return Object.freeze({...n(e),create:n})}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const ot=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),at=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),Gn=BigInt(1),ct=BigInt(2),Jn=(t,e)=>(t+e/ct)/e;function Yn(t){const e=ot,n=BigInt(3),r=BigInt(6),i=BigInt(11),s=BigInt(22),o=BigInt(23),c=BigInt(44),a=BigInt(88),u=t*t*t%e,h=u*u*t%e,l=Q(h,n,e)*h%e,y=Q(l,n,e)*h%e,w=Q(y,ct,e)*u%e,g=Q(w,i,e)*w%e,d=Q(g,s,e)*g%e,f=Q(d,c,e)*d%e,p=Q(f,a,e)*f%e,m=Q(p,c,e)*d%e,N=Q(m,n,e)*h%e,B=Q(N,o,e)*g%e,C=Q(B,r,e)*u%e,E=Q(C,ct,e);if(!Mt.eql(Mt.sqr(E),t))throw new Error("Cannot find square root");return E}const Mt=ss(ot,void 0,void 0,{sqrt:Yn}),Re=gs({a:BigInt(0),b:BigInt(7),Fp:Mt,n:at,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:t=>{const e=at,n=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),r=-Gn*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),i=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),s=n,o=BigInt("0x100000000000000000000000000000000"),c=Jn(s*t,e),a=Jn(-r*t,e);let u=Z(t-c*n-a*i,e),h=Z(-c*r-a*s,e);const l=u>o,y=h>o;if(l&&(u=e-u),y&&(h=e-h),u>o||h>o)throw new Error("splitScalar: Endomorphism failed, k="+t);return{k1neg:l,k1:u,k2neg:y,k2:h}}}},Ct),ut=BigInt(0),Xn=t=>typeof t=="bigint"&&ut<t&&t<ot,ws=t=>typeof t=="bigint"&&ut<t&&t<at,Qn={};function lt(t,...e){let n=Qn[t];if(n===void 0){const r=Ct(Uint8Array.from(t,i=>i.charCodeAt(0)));n=ke(r,r),Qn[t]=n}return Ct(ke(n,...e))}const Pt=t=>t.toRawBytes(!0).slice(1),Ot=t=>Ee(t,32),Ht=t=>Z(t,ot),Xe=t=>Z(t,at),Dt=Re.ProjectivePoint,vs=(t,e,n)=>Dt.BASE.multiplyAndAddUnsafe(t,e,n);function qt(t){let e=Re.utils.normPrivateKeyToScalar(t),n=Dt.fromPrivateKey(e);return{scalar:n.hasEvenY()?e:Xe(-e),bytes:Pt(n)}}function er(t){if(!Xn(t))throw new Error("bad x: need 0 < x < p");const e=Ht(t*t),n=Ht(e*t+BigInt(7));let r=Yn(n);r%ct!==ut&&(r=Ht(-r));const i=new Dt(t,r,Gn);return i.assertValidity(),i}function tr(...t){return Xe(X(lt("BIP0340/challenge",...t)))}function bs(t){return qt(t).bytes}function ms(t,e,n=Tn(32)){const r=G("message",t),{bytes:i,scalar:s}=qt(e),o=G("auxRand",n,32),c=Ot(s^X(lt("BIP0340/aux",o))),a=lt("BIP0340/nonce",c,i,r),u=Xe(X(a));if(u===ut)throw new Error("sign failed: k is zero");const{bytes:h,scalar:l}=qt(u),y=tr(h,i,r),w=new Uint8Array(64);if(w.set(h,0),w.set(Ot(Xe(l+y*s)),32),!nr(w,r,i))throw new Error("sign: Invalid signature produced");return w}function nr(t,e,n){const r=G("signature",t,64),i=G("message",e),s=G("publicKey",n,32);try{const o=er(X(s)),c=X(r.subarray(0,32));if(!Xn(c))return!1;const a=X(r.subarray(32,64));if(!ws(a))return!1;const u=tr(Ot(c),Pt(o),i),h=vs(o,a,Xe(-u));return!(!h||!h.hasEvenY()||h.toAffine().x!==c)}catch{return!1}}const Qe={getPublicKey:bs,sign:ms,verify:nr,utils:{randomPrivateKey:Re.utils.randomPrivateKey,lift_x:er,pointToBytes:Pt,numberToBytesBE:Ee,bytesToNumberBE:X,taggedHash:lt,mod:Z}},jt=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */const zt=t=>t instanceof Uint8Array,Vt=t=>new DataView(t.buffer,t.byteOffset,t.byteLength),ae=(t,e)=>t<<32-e|t>>>e;if(!(new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68))throw new Error("Non little-endian hardware is not supported");const Es=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function D(t){if(!zt(t))throw new Error("Uint8Array expected");let e="";for(let n=0;n<t.length;n++)e+=Es[t[n]];return e}function W(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);const e=t.length;if(e%2)throw new Error("padded hex string expected, got unpadded hex of length "+e);const n=new Uint8Array(e/2);for(let r=0;r<n.length;r++){const i=r*2,s=t.slice(i,i+2),o=Number.parseInt(s,16);if(Number.isNaN(o)||o<0)throw new Error("Invalid byte sequence");n[r]=o}return n}function xs(t){if(typeof t!="string")throw new Error(`utf8ToBytes expected string, got ${typeof t}`);return new Uint8Array(new TextEncoder().encode(t))}function et(t){if(typeof t=="string"&&(t=xs(t)),!zt(t))throw new Error(`expected Uint8Array, got ${typeof t}`);return t}function ht(...t){const e=new Uint8Array(t.reduce((r,i)=>r+i.length,0));let n=0;return t.forEach(r=>{if(!zt(r))throw new Error("Uint8Array expected");e.set(r,n),n+=r.length}),e}class rr{clone(){return this._cloneInto()}}function ir(t){const e=r=>t().update(et(r)).digest(),n=t();return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=()=>t(),e}function sr(t=32){if(jt&&typeof jt.getRandomValues=="function")return jt.getRandomValues(new Uint8Array(t));throw new Error("crypto.getRandomValues must be defined")}function Wt(t){if(!Number.isSafeInteger(t)||t<0)throw new Error(`Wrong positive integer: ${t}`)}function Ss(t){if(typeof t!="boolean")throw new Error(`Expected boolean, not ${t}`)}function or(t,...e){if(!(t instanceof Uint8Array))throw new Error("Expected Uint8Array");if(e.length>0&&!e.includes(t.length))throw new Error(`Expected Uint8Array of length ${e}, not of length=${t.length}`)}function Ks(t){if(typeof t!="function"||typeof t.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");Wt(t.outputLen),Wt(t.blockLen)}function Ns(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}function As(t,e){or(t);const n=e.outputLen;if(t.length<n)throw new Error(`digestInto() expects output buffer of length at least ${n}`)}const ce={number:Wt,bool:Ss,bytes:or,hash:Ks,exists:Ns,output:As};function Is(t,e,n,r){if(typeof t.setBigUint64=="function")return t.setBigUint64(e,n,r);const i=BigInt(32),s=BigInt(4294967295),o=Number(n>>i&s),c=Number(n&s),a=r?4:0,u=r?0:4;t.setUint32(e+a,o,r),t.setUint32(e+u,c,r)}class Cs extends rr{constructor(e,n,r,i){super(),this.blockLen=e,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(e),this.view=Vt(this.buffer)}update(e){ce.exists(this);const{view:n,buffer:r,blockLen:i}=this;e=et(e);const s=e.length;for(let o=0;o<s;){const c=Math.min(i-this.pos,s-o);if(c===i){const a=Vt(e);for(;i<=s-o;o+=i)this.process(a,o);continue}r.set(e.subarray(o,o+c),this.pos),this.pos+=c,o+=c,this.pos===i&&(this.process(n,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){ce.exists(this),ce.output(e,this),this.finished=!0;const{buffer:n,view:r,blockLen:i,isLE:s}=this;let{pos:o}=this;n[o++]=128,this.buffer.subarray(o).fill(0),this.padOffset>i-o&&(this.process(r,0),o=0);for(let l=o;l<i;l++)n[l]=0;Is(r,i-8,BigInt(this.length*8),s),this.process(r,0);const c=Vt(e),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const u=a/4,h=this.get();if(u>h.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<u;l++)c.setUint32(4*l,h[l],s)}digest(){const{buffer:e,outputLen:n}=this;this.digestInto(e);const r=e.slice(0,n);return this.destroy(),r}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());const{blockLen:n,buffer:r,length:i,finished:s,destroyed:o,pos:c}=this;return e.length=i,e.pos=c,e.finished=s,e.destroyed=o,i%n&&e.buffer.set(r),e}}const Us=(t,e,n)=>t&e^~t&n,ks=(t,e,n)=>t&e^t&n^e&n,Bs=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]),xe=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Se=new Uint32Array(64);class ar extends Cs{constructor(){super(64,32,8,!1),this.A=xe[0]|0,this.B=xe[1]|0,this.C=xe[2]|0,this.D=xe[3]|0,this.E=xe[4]|0,this.F=xe[5]|0,this.G=xe[6]|0,this.H=xe[7]|0}get(){const{A:e,B:n,C:r,D:i,E:s,F:o,G:c,H:a}=this;return[e,n,r,i,s,o,c,a]}set(e,n,r,i,s,o,c,a){this.A=e|0,this.B=n|0,this.C=r|0,this.D=i|0,this.E=s|0,this.F=o|0,this.G=c|0,this.H=a|0}process(e,n){for(let l=0;l<16;l++,n+=4)Se[l]=e.getUint32(n,!1);for(let l=16;l<64;l++){const y=Se[l-15],w=Se[l-2],g=ae(y,7)^ae(y,18)^y>>>3,d=ae(w,17)^ae(w,19)^w>>>10;Se[l]=d+Se[l-7]+g+Se[l-16]|0}let{A:r,B:i,C:s,D:o,E:c,F:a,G:u,H:h}=this;for(let l=0;l<64;l++){const y=ae(c,6)^ae(c,11)^ae(c,25),w=h+y+Us(c,a,u)+Bs[l]+Se[l]|0,d=(ae(r,2)^ae(r,13)^ae(r,22))+ks(r,i,s)|0;h=u,u=a,a=c,c=o+w|0,o=s,s=i,i=r,r=w+d|0}r=r+this.A|0,i=i+this.B|0,s=s+this.C|0,o=o+this.D|0,c=c+this.E|0,a=a+this.F|0,u=u+this.G|0,h=h+this.H|0,this.set(r,i,s,o,c,a,u,h)}roundClean(){Se.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}}class _s extends ar{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 de=ir(()=>new ar);ir(()=>new _s);/*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) */function qe(t){if(!Number.isSafeInteger(t))throw new Error(`Wrong integer: ${t}`)}function fe(...t){const e=(i,s)=>o=>i(s(o)),n=Array.from(t).reverse().reduce((i,s)=>i?e(i,s.encode):s.encode,void 0),r=t.reduce((i,s)=>i?e(i,s.decode):s.decode,void 0);return{encode:n,decode:r}}function ye(t){return{encode:e=>{if(!Array.isArray(e)||e.length&&typeof e[0]!="number")throw new Error("alphabet.encode input should be an array of numbers");return e.map(n=>{if(qe(n),n<0||n>=t.length)throw new Error(`Digit index outside alphabet: ${n} (alphabet: ${t.length})`);return t[n]})},decode:e=>{if(!Array.isArray(e)||e.length&&typeof e[0]!="string")throw new Error("alphabet.decode input should be array of strings");return e.map(n=>{if(typeof n!="string")throw new Error(`alphabet.decode: not string element=${n}`);const r=t.indexOf(n);if(r===-1)throw new Error(`Unknown letter: "${n}". Allowed: ${t}`);return r})}}}function pe(t=""){if(typeof t!="string")throw new Error("join separator should be string");return{encode:e=>{if(!Array.isArray(e)||e.length&&typeof e[0]!="string")throw new Error("join.encode input should be array of strings");for(let n of e)if(typeof n!="string")throw new Error(`join.encode: non-string input=${n}`);return e.join(t)},decode:e=>{if(typeof e!="string")throw new Error("join.decode input should be string");return e.split(t)}}}function dt(t,e="="){if(qe(t),typeof e!="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*t%8;)n.push(e);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*t%8)throw new Error("Invalid padding: string should have whole number of bytes");for(;r>0&&n[r-1]===e;r--)if(!((r-1)*t%8))throw new Error("Invalid padding: string has too much padding");return n.slice(0,r)}}}function cr(t){if(typeof t!="function")throw new Error("normalize fn should be function");return{encode:e=>e,decode:e=>t(e)}}function ur(t,e,n){if(e<2)throw new Error(`convertRadix: wrong from=${e}, 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(t))throw new Error("convertRadix: data should be array");if(!t.length)return[];let r=0;const i=[],s=Array.from(t);for(s.forEach(o=>{if(qe(o),o<0||o>=e)throw new Error(`Wrong integer: ${o}`)});;){let o=0,c=!0;for(let a=r;a<s.length;a++){const u=s[a],h=e*o+u;if(!Number.isSafeInteger(h)||e*o/e!==o||h-u!==e*o)throw new Error("convertRadix: carry overflow");if(o=h%n,s[a]=Math.floor(h/n),!Number.isSafeInteger(s[a])||s[a]*n+o!==h)throw new Error("convertRadix: carry overflow");if(c)s[a]?c=!1:r=a;else continue}if(i.push(o),c)break}for(let o=0;o<t.length-1&&t[o]===0;o++)i.push(0);return i.reverse()}const lr=(t,e)=>e?lr(e,t%e):t,ft=(t,e)=>t+(e-lr(t,e));function Ft(t,e,n,r){if(!Array.isArray(t))throw new Error("convertRadix2: data should be array");if(e<=0||e>32)throw new Error(`convertRadix2: wrong from=${e}`);if(n<=0||n>32)throw new Error(`convertRadix2: wrong to=${n}`);if(ft(e,n)>32)throw new Error(`convertRadix2: carry overflow from=${e} to=${n} carryBits=${ft(e,n)}`);let i=0,s=0;const o=2**n-1,c=[];for(const a of t){if(qe(a),a>=2**e)throw new Error(`convertRadix2: invalid data word=${a} from=${e}`);if(i=i<<e|a,s+e>32)throw new Error(`convertRadix2: carry overflow pos=${s} from=${e}`);for(s+=e;s>=n;s-=n)c.push((i>>s-n&o)>>>0);i&=2**s-1}if(i=i<<n-s&o,!r&&s>=e)throw new Error("Excess padding");if(!r&&i)throw new Error(`Non-zero padding: ${i}`);return r&&s>0&&c.push(i>>>0),c}function Rs(t){return qe(t),{encode:e=>{if(!(e instanceof Uint8Array))throw new Error("radix.encode input should be Uint8Array");return ur(Array.from(e),2**8,t)},decode:e=>{if(!Array.isArray(e)||e.length&&typeof e[0]!="number")throw new Error("radix.decode input should be array of strings");return Uint8Array.from(ur(e,t,2**8))}}}function Ke(t,e=!1){if(qe(t),t<=0||t>32)throw new Error("radix2: bits should be in (0..32]");if(ft(8,t)>32||ft(t,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,t,!e)},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,t,8,e))}}}function hr(t){if(typeof t!="function")throw new Error("unsafeWrapper fn should be function");return function(...e){try{return t.apply(null,e)}catch{}}}const $s=fe(Ke(4),ye("0123456789ABCDEF"),pe("")),Ts=fe(Ke(5),ye("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"),dt(5),pe(""));fe(Ke(5),ye("0123456789ABCDEFGHIJKLMNOPQRSTUV"),dt(5),pe("")),fe(Ke(5),ye("0123456789ABCDEFGHJKMNPQRSTVWXYZ"),pe(""),cr(t=>t.toUpperCase().replace(/O/g,"0").replace(/[IL]/g,"1")));const ge=fe(Ke(6),ye("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),dt(6),pe("")),Ls=fe(Ke(6),ye("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"),dt(6),pe("")),Zt=t=>fe(Rs(58),ye(t),pe("")),Gt=Zt("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");Zt("123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"),Zt("rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz");const dr=[0,2,3,5,6,7,9,10,11],Ms={encode(t){let e="";for(let n=0;n<t.length;n+=8){const r=t.subarray(n,n+8);e+=Gt.encode(r).padStart(dr[r.length],"1")}return e},decode(t){let e=[];for(let n=0;n<t.length;n+=11){const r=t.slice(n,n+11),i=dr.indexOf(r.length),s=Gt.decode(r);for(let o=0;o<s.length-i;o++)if(s[o]!==0)throw new Error("base58xmr: wrong padding");e=e.concat(Array.from(s.slice(s.length-i)))}return Uint8Array.from(e)}},Jt=fe(ye("qpzry9x8gf2tvdw0s3jn54khce6mua7l"),pe("")),fr=[996825010,642813549,513874426,1027748829,705979059];function tt(t){const e=t>>25;let n=(t&33554431)<<5;for(let r=0;r<fr.length;r++)(e>>r&1)===1&&(n^=fr[r]);return n}function yr(t,e,n=1){const r=t.length;let i=1;for(let s=0;s<r;s++){const o=t.charCodeAt(s);if(o<33||o>126)throw new Error(`Invalid prefix (${t})`);i=tt(i)^o>>5}i=tt(i);for(let s=0;s<r;s++)i=tt(i)^t.charCodeAt(s)&31;for(let s of e)i=tt(i)^s;for(let s=0;s<6;s++)i=tt(i);return i^=n,Jt.encode(Ft([i%2**30],30,5,!1))}function pr(t){const e=t==="bech32"?1:734539939,n=Ke(5),r=n.decode,i=n.encode,s=hr(r);function o(h,l,y=90){if(typeof h!="string")throw new Error(`bech32.encode prefix should be string, not ${typeof h}`);if(!Array.isArray(l)||l.length&&typeof l[0]!="number")throw new Error(`bech32.encode words should be array of numbers, not ${typeof l}`);const w=h.length+7+l.length;if(y!==!1&&w>y)throw new TypeError(`Length ${w} exceeds limit ${y}`);return h=h.toLowerCase(),`${h}1${Jt.encode(l)}${yr(h,l,e)}`}function c(h,l=90){if(typeof h!="string")throw new Error(`bech32.decode input should be string, not ${typeof h}`);if(h.length<8||l!==!1&&h.length>l)throw new TypeError(`Wrong string length: ${h.length} (${h}). Expected (8..${l})`);const y=h.toLowerCase();if(h!==y&&h!==h.toUpperCase())throw new Error("String must be lowercase or uppercase");h=y;const w=h.lastIndexOf("1");if(w===0||w===-1)throw new Error('Letter "1" must be present between prefix and data only');const g=h.slice(0,w),d=h.slice(w+1);if(d.length<6)throw new Error("Data must be at least 6 characters long");const f=Jt.decode(d).slice(0,-6),p=yr(g,f,e);if(!d.endsWith(p))throw new Error(`Invalid checksum in ${h}: expected "${p}"`);return{prefix:g,words:f}}const a=hr(c);function u(h){const{prefix:l,words:y}=c(h,!1);return{prefix:l,words:y,bytes:r(y)}}return{encode:o,decode:c,decodeToBytes:u,decodeUnsafe:a,fromWords:r,fromWordsUnsafe:s,toWords:i}}const je=pr("bech32");pr("bech32m");const Ps={encode:t=>new TextDecoder().decode(t),decode:t=>new TextEncoder().encode(t)},Os=fe(Ke(4),ye("0123456789abcdef"),pe(""),cr(t=>{if(typeof t!="string"||t.length%2)throw new TypeError(`hex.decode: expected string, got ${typeof t} with length ${t.length}`);return t.toLowerCase()}));`${Object.keys({utf8:Ps,hex:Os,base16:$s,base32:Ts,base64:ge,base64url:Ls,base58:Gt,base58xmr:Ms}).join(", ")}`;function Yt(t){if(!Number.isSafeInteger(t)||t<0)throw new Error(`positive integer expected, not ${t}`)}function gr(t){if(typeof t!="boolean")throw new Error(`boolean expected, not ${t}`)}function Hs(t){return t instanceof Uint8Array||t!=null&&typeof t=="object"&&t.constructor.name==="Uint8Array"}function we(t,...e){if(!Hs(t))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(t.length))throw new Error(`Uint8Array expected of length ${e}, not of length=${t.length}`)}/*! noble-ciphers - MIT License (c) 2023 Paul Miller (paulmillr.com) */const J=t=>new Uint32Array(t.buffer,t.byteOffset,Math.floor(t.byteLength/4));if(!(new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68))throw new Error("Non little-endian hardware is not supported");function Ds(t,e){if(e==null||typeof e!="object")throw new Error("options must be defined");return Object.assign(t,e)}function qs(t,e){if(t.length!==e.length)return!1;let n=0;for(let r=0;r<t.length;r++)n|=t[r]^e[r];return n===0}const js=(t,e)=>(Object.assign(e,t),e),Ne=16,zs=283;function Xt(t){return t<<1^zs&-(t>>7)}function ze(t,e){let n=0;for(;e>0;e>>=1)n^=t&-(e&1),t=Xt(t);return n}const Qt=(()=>{let t=new Uint8Array(256);for(let n=0,r=1;n<256;n++,r^=Xt(r))t[n]=r;const e=new Uint8Array(256);e[0]=99;for(let n=0;n<255;n++){let r=t[255-n];r|=r<<8,e[t[n]]=(r^r>>4^r>>5^r>>6^r>>7^99)&255}return e})(),Vs=Qt.map((t,e)=>Qt.indexOf(e)),Ws=t=>t<<24|t>>>8,en=t=>t<<8|t>>>24;function wr(t,e){if(t.length!==256)throw new Error("Wrong sbox length");const n=new Uint32Array(256).map((u,h)=>e(t[h])),r=n.map(en),i=r.map(en),s=i.map(en),o=new Uint32Array(256*256),c=new Uint32Array(256*256),a=new Uint16Array(256*256);for(let u=0;u<256;u++)for(let h=0;h<256;h++){const l=u*256+h;o[l]=n[u]^r[h],c[l]=i[u]^s[h],a[l]=t[u]<<8|t[h]}return{sbox:t,sbox2:a,T0:n,T1:r,T2:i,T3:s,T01:o,T23:c}}const tn=wr(Qt,t=>ze(t,3)<<24|t<<16|t<<8|ze(t,2)),vr=wr(Vs,t=>ze(t,11)<<24|ze(t,13)<<16|ze(t,9)<<8|ze(t,14)),Fs=(()=>{const t=new Uint8Array(16);for(let e=0,n=1;e<16;e++,n=Xt(n))t[e]=n;return t})();function br(t){we(t);const e=t.length;if(![16,24,32].includes(e))throw new Error(`aes: wrong key size: should be 16, 24 or 32, got: ${e}`);const{sbox2:n}=tn,r=J(t),i=r.length,s=c=>ue(n,c,c,c,c),o=new Uint32Array(e+28);o.set(r);for(let c=i;c<o.length;c++){let a=o[c-1];c%i===0?a=s(Ws(a))^Fs[c/i-1]:i>6&&c%i===4&&(a=s(a)),o[c]=o[c-i]^a}return o}function Zs(t){const e=br(t),n=e.slice(),r=e.length,{sbox2:i}=tn,{T0:s,T1:o,T2:c,T3:a}=vr;for(let u=0;u<r;u+=4)for(let h=0;h<4;h++)n[u+h]=e[r-u-4+h];e.fill(0);for(let u=4;u<r-4;u++){const h=n[u],l=ue(i,h,h,h,h);n[u]=s[l&255]^o[l>>>8&255]^c[l>>>16&255]^a[l>>>24]}return n}function Ae(t,e,n,r,i,s){return t[n<<8&65280|r>>>8&255]^e[i>>>8&65280|s>>>24&255]}function ue(t,e,n,r,i){return t[e&255|n&65280]|t[r>>>16&255|i>>>16&65280]<<16}function mr(t,e,n,r,i){const{sbox2:s,T01:o,T23:c}=tn;let a=0;e^=t[a++],n^=t[a++],r^=t[a++],i^=t[a++];const u=t.length/4-2;for(let g=0;g<u;g++){const d=t[a++]^Ae(o,c,e,n,r,i),f=t[a++]^Ae(o,c,n,r,i,e),p=t[a++]^Ae(o,c,r,i,e,n),m=t[a++]^Ae(o,c,i,e,n,r);e=d,n=f,r=p,i=m}const h=t[a++]^ue(s,e,n,r,i),l=t[a++]^ue(s,n,r,i,e),y=t[a++]^ue(s,r,i,e,n),w=t[a++]^ue(s,i,e,n,r);return{s0:h,s1:l,s2:y,s3:w}}function Gs(t,e,n,r,i){const{sbox2:s,T01:o,T23:c}=vr;let a=0;e^=t[a++],n^=t[a++],r^=t[a++],i^=t[a++];const u=t.length/4-2;for(let g=0;g<u;g++){const d=t[a++]^Ae(o,c,e,i,r,n),f=t[a++]^Ae(o,c,n,e,i,r),p=t[a++]^Ae(o,c,r,n,e,i),m=t[a++]^Ae(o,c,i,r,n,e);e=d,n=f,r=p,i=m}const h=t[a++]^ue(s,e,i,r,n),l=t[a++]^ue(s,n,e,i,r),y=t[a++]^ue(s,r,n,e,i),w=t[a++]^ue(s,i,r,n,e);return{s0:h,s1:l,s2:y,s3:w}}function Er(t,e){if(!e)return new Uint8Array(t);if(we(e),e.length<t)throw new Error(`aes: wrong destination length, expected at least ${t}, got: ${e.length}`);return e}function Js(t){if(we(t),t.length%Ne!==0)throw new Error(`aes/(cbc-ecb).decrypt ciphertext should consist of blocks with size ${Ne}`)}function Ys(t,e,n){let r=t.length;const i=r%Ne;if(!e&&i!==0)throw new Error("aec/(cbc-ecb): unpadded plaintext with disabled padding");const s=J(t);if(e){let a=Ne-i;a||(a=Ne),r=r+a}const o=Er(r,n),c=J(o);return{b:s,o:c,out:o}}function Xs(t,e){if(!e)return t;const n=t.length;if(!n)throw new Error("aes/pcks5: empty ciphertext not allowed");const r=t[n-1];if(r<=0||r>16)throw new Error(`aes/pcks5: wrong padding byte: ${r}`);const i=t.subarray(0,-r);for(let s=0;s<r;s++)if(t[n-s-1]!==r)throw new Error("aes/pcks5: wrong padding");return i}function Qs(t){const e=new Uint8Array(16),n=J(e);e.set(t);const r=Ne-t.length;for(let i=Ne-r;i<Ne;i++)e[i]=r;return n}const xr=js({blockSize:16,nonceLength:16},function(e,n,r={}){we(e),we(n,16);const i=!r.disablePadding;return{encrypt:(s,o)=>{const c=br(e),{b:a,o:u,out:h}=Ys(s,i,o),l=J(n);let y=l[0],w=l[1],g=l[2],d=l[3],f=0;for(;f+4<=a.length;)y^=a[f+0],w^=a[f+1],g^=a[f+2],d^=a[f+3],{s0:y,s1:w,s2:g,s3:d}=mr(c,y,w,g,d),u[f++]=y,u[f++]=w,u[f++]=g,u[f++]=d;if(i){const p=Qs(s.subarray(f*4));y^=p[0],w^=p[1],g^=p[2],d^=p[3],{s0:y,s1:w,s2:g,s3:d}=mr(c,y,w,g,d),u[f++]=y,u[f++]=w,u[f++]=g,u[f++]=d}return c.fill(0),h},decrypt:(s,o)=>{Js(s);const c=Zs(e),a=J(n),u=Er(s.length,o),h=J(s),l=J(u);let y=a[0],w=a[1],g=a[2],d=a[3];for(let f=0;f+4<=h.length;){const p=y,m=w,N=g,B=d;y=h[f+0],w=h[f+1],g=h[f+2],d=h[f+3];const{s0:C,s1:E,s2:x,s3:S}=Gs(c,y,w,g,d);l[f++]=C^p,l[f++]=E^m,l[f++]=x^N,l[f++]=S^B}return c.fill(0),Xs(u,i)}}}),Sr=t=>Uint8Array.from(t.split("").map(e=>e.charCodeAt(0))),eo=Sr("expand 16-byte k"),to=Sr("expand 32-byte k"),no=J(eo),Kr=J(to);Kr.slice();function _(t,e){return t<<e|t>>>32-e}function nn(t){return t.byteOffset%4===0}const yt=64,ro=16,Nr=2**32-1,Ar=new Uint32Array;function io(t,e,n,r,i,s,o,c){const a=i.length,u=new Uint8Array(yt),h=J(u),l=nn(i)&&nn(s),y=l?J(i):Ar,w=l?J(s):Ar;for(let g=0;g<a;o++){if(t(e,n,r,h,o,c),o>=Nr)throw new Error("arx: counter overflow");const d=Math.min(yt,a-g);if(l&&d===yt){const f=g/4;if(g%4!==0)throw new Error("arx: invalid block position");for(let p=0,m;p<ro;p++)m=f+p,w[m]=y[m]^h[p];g+=yt;continue}for(let f=0,p;f<d;f++)p=g+f,s[p]=i[p]^u[f];g+=d}}function so(t,e){const{allowShortKeys:n,extendNonceFn:r,counterLength:i,counterRight:s,rounds:o}=Ds({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},e);if(typeof t!="function")throw new Error("core must be a function");return Yt(i),Yt(o),gr(s),gr(n),(c,a,u,h,l=0)=>{we(c),we(a),we(u);const y=u.length;if(h||(h=new Uint8Array(y)),we(h),Yt(l),l<0||l>=Nr)throw new Error("arx: counter overflow");if(h.length<y)throw new Error(`arx: output (${h.length}) is shorter than data (${y})`);const w=[];let g=c.length,d,f;if(g===32)d=c.slice(),w.push(d),f=Kr;else if(g===16&&n)d=new Uint8Array(32),d.set(c),d.set(c,16),f=no,w.push(d);else throw new Error(`arx: invalid 32-byte key, got length=${g}`);nn(a)||(a=a.slice(),w.push(a));const p=J(d);if(r){if(a.length!==24)throw new Error("arx: extended nonce must be 24 bytes");r(f,p,J(a.subarray(0,16)),p),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 B=new Uint8Array(12);B.set(a,s?0:12-a.length),a=B,w.push(a)}const N=J(a);for(io(t,f,p,N,u,h,l,o);w.length>0;)w.pop().fill(0);return h}}function oo(t,e,n,r,i,s=20){let o=t[0],c=t[1],a=t[2],u=t[3],h=e[0],l=e[1],y=e[2],w=e[3],g=e[4],d=e[5],f=e[6],p=e[7],m=i,N=n[0],B=n[1],C=n[2],E=o,x=c,S=a,H=u,k=h,A=l,M=y,P=w,z=g,v=d,b=f,K=p,U=m,I=N,R=B,O=C;for(let ie=0;ie<s;ie+=2)E=E+k|0,U=_(U^E,16),z=z+U|0,k=_(k^z,12),E=E+k|0,U=_(U^E,8),z=z+U|0,k=_(k^z,7),x=x+A|0,I=_(I^x,16),v=v+I|0,A=_(A^v,12),x=x+A|0,I=_(I^x,8),v=v+I|0,A=_(A^v,7),S=S+M|0,R=_(R^S,16),b=b+R|0,M=_(M^b,12),S=S+M|0,R=_(R^S,8),b=b+R|0,M=_(M^b,7),H=H+P|0,O=_(O^H,16),K=K+O|0,P=_(P^K,12),H=H+P|0,O=_(O^H,8),K=K+O|0,P=_(P^K,7),E=E+A|0,O=_(O^E,16),b=b+O|0,A=_(A^b,12),E=E+A|0,O=_(O^E,8),b=b+O|0,A=_(A^b,7),x=x+M|0,U=_(U^x,16),K=K+U|0,M=_(M^K,12),x=x+M|0,U=_(U^x,8),K=K+U|0,M=_(M^K,7),S=S+P|0,I=_(I^S,16),z=z+I|0,P=_(P^z,12),S=S+P|0,I=_(I^S,8),z=z+I|0,P=_(P^z,7),H=H+k|0,R=_(R^H,16),v=v+R|0,k=_(k^v,12),H=H+k|0,R=_(R^H,8),v=v+R|0,k=_(k^v,7);let T=0;r[T++]=o+E|0,r[T++]=c+x|0,r[T++]=a+S|0,r[T++]=u+H|0,r[T++]=h+k|0,r[T++]=l+A|0,r[T++]=y+M|0,r[T++]=w+P|0,r[T++]=g+z|0,r[T++]=d+v|0,r[T++]=f+b|0,r[T++]=p+K|0,r[T++]=m+U|0,r[T++]=N+I|0,r[T++]=B+R|0,r[T++]=C+O|0}const Ir=so(oo,{counterRight:!1,counterLength:4,allowShortKeys:!1});class Cr extends rr{constructor(e,n){super(),this.finished=!1,this.destroyed=!1,ce.hash(e);const r=et(n);if(this.iHash=e.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,s=new Uint8Array(i);s.set(r.length>i?e.create().update(r).digest():r);for(let o=0;o<s.length;o++)s[o]^=54;this.iHash.update(s),this.oHash=e.create();for(let o=0;o<s.length;o++)s[o]^=106;this.oHash.update(s),s.fill(0)}update(e){return ce.exists(this),this.iHash.update(e),this}digestInto(e){ce.exists(this),ce.bytes(e,this.outputLen),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){const e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||(e=Object.create(Object.getPrototypeOf(this),{}));const{oHash:n,iHash:r,finished:i,destroyed:s,blockLen:o,outputLen:c}=this;return e=e,e.finished=i,e.destroyed=s,e.blockLen=o,e.outputLen=c,e.oHash=n._cloneInto(e.oHash),e.iHash=r._cloneInto(e.iHash),e}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}const pt=(t,e,n)=>new Cr(t,e).update(n).digest();pt.create=(t,e)=>new Cr(t,e);function rn(t,e,n){return ce.hash(t),n===void 0&&(n=new Uint8Array(t.outputLen)),pt(t,et(n),et(e))}const sn=new Uint8Array([0]),Ur=new Uint8Array;function kr(t,e,n,r=32){if(ce.hash(t),ce.number(r),r>255*t.outputLen)throw new Error("Length should be <= 255*HashLen");const i=Math.ceil(r/t.outputLen);n===void 0&&(n=Ur);const s=new Uint8Array(i*t.outputLen),o=pt.create(t,e),c=o._cloneInto(),a=new Uint8Array(o.outputLen);for(let u=0;u<i;u++)sn[0]=u+1,c.update(u===0?Ur:a).update(n).update(sn).digestInto(a),s.set(a,t.outputLen*u),o._cloneInto(c);return o.destroy(),c.destroy(),a.fill(0),sn.fill(0),s.slice(0,r)}var ao=Object.defineProperty,q=(t,e)=>{for(var n in e)ao(t,n,{get:e[n],enumerable:!0})},Ve=Symbol("verified"),co=t=>t instanceof Object;function gt(t){if(!co(t)||typeof t.kind!="number"||typeof t.content!="string"||typeof t.created_at!="number"||typeof t.pubkey!="string"||!t.pubkey.match(/^[a-f0-9]{64}$/)||!Array.isArray(t.tags))return!1;for(let e=0;e<t.tags.length;e++){let n=t.tags[e];if(!Array.isArray(n))return!1;for(let r=0;r<n.length;r++)if(typeof n[r]!="string")return!1}return!0}var uo={};q(uo,{Queue:()=>yo,QueueNode:()=>Br,binarySearch:()=>on,bytesToHex:()=>D,hexToBytes:()=>W,insertEventIntoAscendingList:()=>fo,insertEventIntoDescendingList:()=>ho,normalizeURL:()=>lo,utf8Decoder:()=>ve,utf8Encoder:()=>ne});var ve=new TextDecoder("utf-8"),ne=new TextEncoder;function lo(t){try{t.indexOf("://")===-1&&(t="wss://"+t);let e=new URL(t);return e.pathname=e.pathname.replace(/\/+/g,"/"),e.pathname.endsWith("/")&&(e.pathname=e.pathname.slice(0,-1)),(e.port==="80"&&e.protocol==="ws:"||e.port==="443"&&e.protocol==="wss:")&&(e.port=""),e.searchParams.sort(),e.hash="",e.toString()}catch{throw new Error(`Invalid URL: ${t}`)}}function ho(t,e){const[n,r]=on(t,i=>e.id===i.id?0:e.created_at===i.created_at?-1:i.created_at-e.created_at);return r||t.splice(n,0,e),t}function fo(t,e){const[n,r]=on(t,i=>e.id===i.id?0:e.created_at===i.created_at?-1:e.created_at-i.created_at);return r||t.splice(n,0,e),t}function on(t,e){let n=0,r=t.length-1;for(;n<=r;){const i=Math.floor((n+r)/2),s=e(t[i]);if(s===0)return[i,!0];s<0?r=i-1:n=i+1}return[n,!1]}var Br=class{constructor(t){$(this,"value");$(this,"next",null);$(this,"prev",null);this.value=t}},yo=class{constructor(){$(this,"first");$(this,"last");this.first=null,this.last=null}enqueue(t){const e=new Br(t);return this.last?this.last===this.first?(this.last=e,this.last.prev=this.first,this.first.next=e):(e.prev=this.last,this.last.next=e,this.last=e):(this.first=e,this.last=e),!0}dequeue(){if(!this.first)return null;if(this.first===this.last){const e=this.first;return this.first=null,this.last=null,e.value}const t=this.first;return this.first=t.next,this.first&&(this.first.prev=null),t.value}},po=class{generateSecretKey(){return Qe.utils.randomPrivateKey()}getPublicKey(t){return D(Qe.getPublicKey(t))}finalizeEvent(t,e){const n=t;return n.pubkey=D(Qe.getPublicKey(e)),n.id=$e(n),n.sig=D(Qe.sign($e(n),e)),n[Ve]=!0,n}verifyEvent(t){if(typeof t[Ve]=="boolean")return t[Ve];const e=$e(t);if(e!==t.id)return t[Ve]=!1,!1;try{const n=Qe.verify(t.sig,e,t.pubkey);return t[Ve]=n,n}catch{return t[Ve]=!1,!1}}};function go(t){if(!gt(t))throw new Error("can't serialize event with wrong or missing properties");return JSON.stringify([0,t.pubkey,t.created_at,t.kind,t.tags,t.content])}function $e(t){let e=de(ne.encode(go(t)));return D(e)}var wt=new po,Te=wt.generateSecretKey,le=wt.getPublicKey,te=wt.finalizeEvent,vt=wt.verifyEvent,wo={};q(wo,{Application:()=>ga,BadgeAward:()=>No,BadgeDefinition:()=>ua,BlockedRelaysList:()=>Fo,BookmarkList:()=>zo,Bookmarksets:()=>oa,Calendar:()=>Sa,CalendarEventRSVP:()=>Ka,ChannelCreation:()=>Mr,ChannelHideMessage:()=>Hr,ChannelMessage:()=>Or,ChannelMetadata:()=>Pr,ChannelMuteUser:()=>Dr,ClassifiedListing:()=>ba,ClientAuth:()=>jr,CommunitiesList:()=>Vo,CommunityDefinition:()=>Ia,CommunityPostApproval:()=>Ro,Contacts:()=>xo,CreateOrUpdateProduct:()=>da,CreateOrUpdateStall:()=>ha,Curationsets:()=>aa,Date:()=>Ea,DirectMessageRelaysList:()=>Yo,DraftClassifiedListing:()=>ma,DraftLong:()=>ya,Emojisets:()=>pa,EncryptedDirectMessage:()=>So,EventDeletion:()=>Ko,FileMetadata:()=>Io,FileServerPreference:()=>Xo,Followsets:()=>ra,GenericRepost:()=>hn,Genericlists:()=>ia,GiftWrap:()=>qr,HTTPAuth:()=>dn,Handlerinformation:()=>Aa,Handlerrecommendation:()=>Na,Highlights:()=>Ho,InterestsList:()=>Go,Interestsets:()=>la,JobFeedback:()=>Lo,JobRequest:()=>$o,JobResult:()=>To,Label:()=>_o,LightningPubRPC:()=>ea,LiveChatMessage:()=>Co,LiveEvent:()=>wa,LongFormArticle:()=>fa,Metadata:()=>mo,Mutelist:()=>Do,NWCWalletInfo:()=>Qo,NWCWalletRequest:()=>zr,NWCWalletResponse:()=>ta,NostrConnect:()=>na,OpenTimestamps:()=>Ao,Pinlist:()=>qo,PrivateDirectMessage:()=>Lr,ProblemTracker:()=>Uo,ProfileBadges:()=>ca,PublicChatsList:()=>Wo,Reaction:()=>ln,RecommendRelay:()=>Eo,RelayList:()=>jo,Relaysets:()=>sa,Report:()=>ko,Reporting:()=>Bo,Repost:()=>un,Seal:()=>Tr,SearchRelaysList:()=>Zo,ShortTextNote:()=>$r,Time:()=>xa,UserEmojiList:()=>Jo,UserStatuses:()=>va,Zap:()=>Oo,ZapGoal:()=>Mo,ZapRequest:()=>Po,classifyKind:()=>vo,isAddressableKind:()=>cn,isEphemeralKind:()=>Rr,isKind:()=>bo,isRegularKind:()=>_r,isReplaceableKind:()=>an});function _r(t){return 1e3<=t&&t<1e4||[1,2,4,5,6,7,8,16,40,41,42,43,44].includes(t)}function an(t){return[0,3].includes(t)||1e4<=t&&t<2e4}function Rr(t){return 2e4<=t&&t<3e4}function cn(t){return 3e4<=t&&t<4e4}function vo(t){return _r(t)?"regular":an(t)?"replaceable":Rr(t)?"ephemeral":cn(t)?"parameterized":"unknown"}function bo(t,e){const n=e instanceof Array?e:[e];return gt(t)&&n.includes(t.kind)||!1}var mo=0,$r=1,Eo=2,xo=3,So=4,Ko=5,un=6,ln=7,No=8,Tr=13,Lr=14,hn=16,Mr=40,Pr=41,Or=42,Hr=43,Dr=44,Ao=1040,qr=1059,Io=1063,Co=1311,Uo=1971,ko=1984,Bo=1984,_o=1985,Ro=4550,$o=5999,To=6999,Lo=7e3,Mo=9041,Po=9734,Oo=9735,Ho=9802,Do=1e4,qo=10001,jo=10002,zo=10003,Vo=10004,Wo=10005,Fo=10006,Zo=10007,Go=10015,Jo=10030,Yo=10050,Xo=10096,Qo=13194,ea=21e3,jr=22242,zr=23194,ta=23195,na=24133,dn=27235,ra=3e4,ia=30001,sa=30002,oa=30003,aa=30004,ca=30008,ua=30009,la=30015,ha=30017,da=30018,fa=30023,ya=30024,pa=30030,ga=30078,wa=30311,va=30315,ba=30402,ma=30403,Ea=31922,xa=31923,Sa=31924,Ka=31925,Na=31989,Aa=31990,Ia=34550,Ca={};q(Ca,{getHex64:()=>fn,getInt:()=>Vr,getSubscriptionId:()=>Ua,matchEventId:()=>ka,matchEventKind:()=>_a,matchEventPubkey:()=>Ba});function fn(t,e){let n=e.length+3,r=t.indexOf(`"${e}":`)+n,i=t.slice(r).indexOf('"')+r+1;return t.slice(i,i+64)}function Vr(t,e){let n=e.length,r=t.indexOf(`"${e}":`)+n+3,i=t.slice(r),s=Math.min(i.indexOf(","),i.indexOf("}"));return parseInt(i.slice(0,s),10)}function Ua(t){let e=t.slice(0,22).indexOf('"EVENT"');if(e===-1)return null;let n=t.slice(e+7+1).indexOf('"');if(n===-1)return null;let r=e+7+1+n,i=t.slice(r+1,80).indexOf('"');if(i===-1)return null;let s=r+1+i;return t.slice(r+1,s)}function ka(t,e){return e===fn(t,"id")}function Ba(t,e){return e===fn(t,"pubkey")}function _a(t,e){return e===Vr(t,"kind")}var Ra={};q(Ra,{makeAuthEvent:()=>$a});function $a(t,e){return{kind:jr,created_at:Math.floor(Date.now()/1e3),tags:[["relay",t],["challenge",e]],content:""}}var Ta;try{Ta=WebSocket}catch{}var La;try{La=WebSocket}catch{}var Ma={};q(Ma,{BECH32_REGEX:()=>Wr,Bech32MaxSize:()=>yn,NostrTypeGuard:()=>Pa,decode:()=>bt,decodeNostrURI:()=>Ha,encodeBytes:()=>Et,naddrEncode:()=>Wa,neventEncode:()=>Va,noteEncode:()=>ja,nprofileEncode:()=>za,npubEncode:()=>qa,nsecEncode:()=>Da});var Pa={isNProfile:t=>/^nprofile1[a-z\d]+$/.test(t||""),isNEvent:t=>/^nevent1[a-z\d]+$/.test(t||""),isNAddr:t=>/^naddr1[a-z\d]+$/.test(t||""),isNSec:t=>/^nsec1[a-z\d]{58}$/.test(t||""),isNPub:t=>/^npub1[a-z\d]{58}$/.test(t||""),isNote:t=>/^note1[a-z\d]+$/.test(t||""),isNcryptsec:t=>/^ncryptsec1[a-z\d]+$/.test(t||"")},yn=5e3,Wr=/[\x21-\x7E]{1,83}1[023456789acdefghjklmnpqrstuvwxyz]{6,}/;function Oa(t){const e=new Uint8Array(4);return e[0]=t>>24&255,e[1]=t>>16&255,e[2]=t>>8&255,e[3]=t&255,e}function Ha(t){try{return t.startsWith("nostr:")&&(t=t.substring(6)),bt(t)}catch{return{type:"invalid",data:null}}}function bt(t){var i,s,o,c,a,u,h;let{prefix:e,words:n}=je.decode(t,yn),r=new Uint8Array(je.fromWords(n));switch(e){case"nprofile":{let l=pn(r);if(!((i=l[0])!=null&&i[0]))throw new Error("missing TLV 0 for nprofile");if(l[0][0].length!==32)throw new Error("TLV 0 should be 32 bytes");return{type:"nprofile",data:{pubkey:D(l[0][0]),relays:l[1]?l[1].map(y=>ve.decode(y)):[]}}}case"nevent":{let l=pn(r);if(!((s=l[0])!=null&&s[0]))throw new Error("missing TLV 0 for nevent");if(l[0][0].length!==32)throw new Error("TLV 0 should be 32 bytes");if(l[2]&&l[2][0].length!==32)throw new Error("TLV 2 should be 32 bytes");if(l[3]&&l[3][0].length!==4)throw new Error("TLV 3 should be 4 bytes");return{type:"nevent",data:{id:D(l[0][0]),relays:l[1]?l[1].map(y=>ve.decode(y)):[],author:(o=l[2])!=null&&o[0]?D(l[2][0]):void 0,kind:(c=l[3])!=null&&c[0]?parseInt(D(l[3][0]),16):void 0}}}case"naddr":{let l=pn(r);if(!((a=l[0])!=null&&a[0]))throw new Error("missing TLV 0 for naddr");if(!((u=l[2])!=null&&u[0]))throw new Error("missing TLV 2 for naddr");if(l[2][0].length!==32)throw new Error("TLV 2 should be 32 bytes");if(!((h=l[3])!=null&&h[0]))throw new Error("missing TLV 3 for naddr");if(l[3][0].length!==4)throw new Error("TLV 3 should be 4 bytes");return{type:"naddr",data:{identifier:ve.decode(l[0][0]),pubkey:D(l[2][0]),kind:parseInt(D(l[3][0]),16),relays:l[1]?l[1].map(y=>ve.decode(y)):[]}}}case"nsec":return{type:e,data:r};case"npub":case"note":return{type:e,data:D(r)};default:throw new Error(`unknown prefix ${e}`)}}function pn(t){let e={},n=t;for(;n.length>0;){let r=n[0],i=n[1],s=n.slice(2,2+i);if(n=n.slice(2+i),s.length<i)throw new Error(`not enough data to read on TLV ${r}`);e[r]=e[r]||[],e[r].push(s)}return e}function Da(t){return Et("nsec",t)}function qa(t){return Et("npub",W(t))}function ja(t){return Et("note",W(t))}function mt(t,e){let n=je.toWords(e);return je.encode(t,n,yn)}function Et(t,e){return mt(t,e)}function za(t){let e=gn({0:[W(t.pubkey)],1:(t.relays||[]).map(n=>ne.encode(n))});return mt("nprofile",e)}function Va(t){let e;t.kind!==void 0&&(e=Oa(t.kind));let n=gn({0:[W(t.id)],1:(t.relays||[]).map(r=>ne.encode(r)),2:t.author?[W(t.author)]:[],3:e?[new Uint8Array(e)]:[]});return mt("nevent",n)}function Wa(t){let e=new ArrayBuffer(4);new DataView(e).setUint32(0,t.kind,!1);let n=gn({0:[ne.encode(t.identifier)],1:(t.relays||[]).map(r=>ne.encode(r)),2:[W(t.pubkey)],3:[new Uint8Array(e)]});return mt("naddr",n)}function gn(t){let e=[];return Object.entries(t).reverse().forEach(([n,r])=>{r.forEach(i=>{let s=new Uint8Array(i.length+2);s.set([parseInt(n)],0),s.set([i.length],1),s.set(i,2),e.push(s)})}),ht(...e)}var Fa={};q(Fa,{decrypt:()=>Za,encrypt:()=>Fr});function Fr(t,e,n){const r=t instanceof Uint8Array?D(t):t,i=Re.getSharedSecret(r,"02"+e),s=Zr(i);let o=Uint8Array.from(sr(16)),c=ne.encode(n),a=xr(s,o).encrypt(c),u=ge.encode(new Uint8Array(a)),h=ge.encode(new Uint8Array(o.buffer));return`${u}?iv=${h}`}function Za(t,e,n){const r=t instanceof Uint8Array?D(t):t;let[i,s]=n.split("?iv="),o=Re.getSharedSecret(r,"02"+e),c=Zr(o),a=ge.decode(s),u=ge.decode(i),h=xr(c,a).decrypt(u);return ve.decode(h)}function Zr(t){return t.slice(1,33)}var Ga={};q(Ga,{NIP05_REGEX:()=>wn,isNip05:()=>Ja,isValid:()=>Qa,queryProfile:()=>Gr,searchDomain:()=>Xa,useFetchImplementation:()=>Ya});var wn=/^(?:([\w.+-]+)@)?([\w_-]+(\.[\w_-]+)+)$/,Ja=t=>wn.test(t||""),xt;try{xt=fetch}catch{}function Ya(t){xt=t}async function Xa(t,e=""){try{const n=`https://${t}/.well-known/nostr.json?name=${e}`,r=await xt(n,{redirect:"manual"});if(r.status!==200)throw Error("Wrong response code");return(await r.json()).names}catch{return{}}}async function Gr(t){var i;const e=t.match(wn);if(!e)return null;const[,n="_",r]=e;try{const s=`https://${r}/.well-known/nostr.json?name=${n}`,o=await xt(s,{redirect:"manual"});if(o.status!==200)throw Error("Wrong response code");const c=await o.json(),a=c.names[n];return a?{pubkey:a,relays:(i=c.relays)==null?void 0:i[a]}:null}catch{return null}}async function Qa(t,e){const n=await Gr(e);return n?n.pubkey===t:!1}var ec={};q(ec,{parse:()=>tc});function tc(t){const e={reply:void 0,root:void 0,mentions:[],profiles:[],quotes:[]};let n,r;for(let i=t.tags.length-1;i>=0;i--){const s=t.tags[i];if(s[0]==="e"&&s[1]){const[o,c,a,u,h]=s,l={id:c,relays:a?[a]:[],author:h};if(u==="root"){e.root=l;continue}if(u==="reply"){e.reply=l;continue}if(u==="mention"){e.mentions.push(l);continue}n?r=l:n=l,e.mentions.push(l);continue}if(s[0]==="q"&&s[1]){const[o,c,a]=s;e.quotes.push({id:c,relays:a?[a]:[]})}if(s[0]==="p"&&s[1]){e.profiles.push({pubkey:s[1],relays:s[2]?[s[2]]:[]});continue}}return e.root||(e.root=r||n||e.reply),e.reply||(e.reply=n||e.root),[e.reply,e.root].forEach(i=>{if(!i)return;let s=e.mentions.indexOf(i);if(s!==-1&&e.mentions.splice(s,1),i.author){let o=e.profiles.find(c=>c.pubkey===i.author);o&&o.relays&&(i.relays||(i.relays=[]),o.relays.forEach(c=>{var a;((a=i.relays)==null?void 0:a.indexOf(c))===-1&&i.relays.push(c)}),o.relays=i.relays)}}),e.mentions.forEach(i=>{if(i.author){let s=e.profiles.find(o=>o.pubkey===i.author);s&&s.relays&&(i.relays||(i.relays=[]),s.relays.forEach(o=>{i.relays.indexOf(o)===-1&&i.relays.push(o)}),s.relays=i.relays)}}),e}var nc={};q(nc,{fetchRelayInformation:()=>ic,useFetchImplementation:()=>rc});var Jr;try{Jr=fetch}catch{}function rc(t){Jr=t}async function ic(t){return await(await fetch(t.replace("ws://","http://").replace("wss://","https://"),{headers:{Accept:"application/nostr+json"}})).json()}var sc={};q(sc,{fastEventHash:()=>Xr,getPow:()=>Yr,minePow:()=>oc});function Yr(t){let e=0;for(let n=0;n<64;n+=8){const r=parseInt(t.substring(n,n+8),16);if(r===0)e+=32;else{e+=Math.clz32(r);break}}return e}function oc(t,e){let n=0;const r=t,i=["nonce",n.toString(),e.toString()];for(r.tags.push(i);;){const s=Math.floor(new Date().getTime()/1e3);if(s!==r.created_at&&(n=0,r.created_at=s),i[1]=(++n).toString(),r.id=Xr(r),Yr(r.id)>=e)break}return r}function Xr(t){return D(de(ne.encode(JSON.stringify([0,t.pubkey,t.created_at,t.kind,t.tags,t.content]))))}var ac={};q(ac,{unwrapEvent:()=>vc,unwrapManyEvents:()=>bc,wrapEvent:()=>di,wrapManyEvents:()=>wc});var cc={};q(cc,{createRumor:()=>ci,createSeal:()=>ui,createWrap:()=>li,unwrapEvent:()=>xn,unwrapManyEvents:()=>hi,wrapEvent:()=>St,wrapManyEvents:()=>pc});var j={};q(j,{decrypt:()=>En,encrypt:()=>mn,getConversationKey:()=>vn,v2:()=>fc});var Qr=1,ei=65535;function vn(t,e){const n=Re.getSharedSecret(t,"02"+e).subarray(1,33);return rn(de,n,"nip44-v2")}function ti(t,e){const n=kr(de,t,e,76);return{chacha_key:n.subarray(0,32),chacha_nonce:n.subarray(32,44),hmac_key:n.subarray(44,76)}}function bn(t){if(!Number.isSafeInteger(t)||t<1)throw new Error("expected positive integer");if(t<=32)return 32;const e=1<<Math.floor(Math.log2(t-1))+1,n=e<=256?32:e/8;return n*(Math.floor((t-1)/n)+1)}function uc(t){if(!Number.isSafeInteger(t)||t<Qr||t>ei)throw new Error("invalid plaintext size: must be between 1 and 65535 bytes");const e=new Uint8Array(2);return new DataView(e.buffer).setUint16(0,t,!1),e}function lc(t){const e=ne.encode(t),n=e.length,r=uc(n),i=new Uint8Array(bn(n)-n);return ht(r,e,i)}function hc(t){const e=new DataView(t.buffer).getUint16(0),n=t.subarray(2,2+e);if(e<Qr||e>ei||n.length!==e||t.length!==2+bn(e))throw new Error("invalid padding");return ve.decode(n)}function ni(t,e,n){if(n.length!==32)throw new Error("AAD associated data must be 32 bytes");const r=ht(n,e);return pt(de,t,r)}function dc(t){if(typeof t!="string")throw new Error("payload must be a valid string");const e=t.length;if(e<132||e>87472)throw new Error("invalid payload length: "+e);if(t[0]==="#")throw new Error("unknown encryption version");let n;try{n=ge.decode(t)}catch(s){throw new Error("invalid base64: "+s.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 mn(t,e,n=sr(32)){const{chacha_key:r,chacha_nonce:i,hmac_key:s}=ti(e,n),o=lc(t),c=Ir(r,i,o),a=ni(s,c,n);return ge.encode(ht(new Uint8Array([2]),n,c,a))}function En(t,e){const{nonce:n,ciphertext:r,mac:i}=dc(t),{chacha_key:s,chacha_nonce:o,hmac_key:c}=ti(e,n),a=ni(c,r,n);if(!qs(a,i))throw new Error("invalid MAC");const u=Ir(s,o,r);return hc(u)}var fc={utils:{getConversationKey:vn,calcPaddedLen:bn},encrypt:mn,decrypt:En},yc=2*24*60*60,ri=()=>Math.round(Date.now()/1e3),ii=()=>Math.round(ri()-Math.random()*yc),si=(t,e)=>vn(t,e),oi=(t,e,n)=>mn(JSON.stringify(t),si(e,n)),ai=(t,e)=>JSON.parse(En(t.content,si(e,t.pubkey)));function ci(t,e){const n={created_at:ri(),content:"",tags:[],...t,pubkey:le(e)};return n.id=$e(n),n}function ui(t,e,n){return te({kind:Tr,content:oi(t,e,n),created_at:ii(),tags:[]},e)}function li(t,e){const n=Te();return te({kind:qr,content:oi(t,n,e),created_at:ii(),tags:[["p",e]]},n)}function St(t,e,n){const r=ci(t,e),i=ui(r,e,n);return li(i,n)}function pc(t,e,n){if(!n||n.length===0)throw new Error("At least one recipient is required.");const r=le(e),i=[St(t,e,r)];return n.forEach(s=>{i.push(St(t,e,s))}),i}function xn(t,e){const n=ai(t,e);return ai(n,e)}function hi(t,e){let n=[];return t.forEach(r=>{n.push(xn(r,e))}),n.sort((r,i)=>r.created_at-i.created_at),n}function gc(t,e,n,r){const i={created_at:Math.ceil(Date.now()/1e3),kind:Lr,tags:[],content:e};return(Array.isArray(t)?t:[t]).forEach(({publicKey:o,relayUrl:c})=>{i.tags.push(c?["p",o,c]:["p",o])}),r&&i.tags.push(["e",r.eventId,r.relayUrl||"","reply"]),n&&i.tags.push(["subject",n]),i}function di(t,e,n,r,i){const s=gc(e,n,r,i);return St(s,t,e.publicKey)}function wc(t,e,n,r,i){if(!e||e.length===0)throw new Error("At least one recipient is required.");return[{publicKey:le(t)},...e].map(o=>di(t,o,n,r,i))}var vc=xn,bc=hi,mc={};q(mc,{finishRepostEvent:()=>Ec,getRepostedEvent:()=>xc,getRepostedEventPointer:()=>fi});function Ec(t,e,n,r){var o;let i;const s=[...t.tags??[],["e",e.id,n],["p",e.pubkey]];return e.kind===$r?i=un:(i=hn,s.push(["k",String(e.kind)])),te({kind:i,tags:s,content:t.content===""||(o=e.tags)!=null&&o.find(c=>c[0]==="-")?"":JSON.stringify(e),created_at:t.created_at},r)}function fi(t){if(![un,hn].includes(t.kind))return;let e,n;for(let r=t.tags.length-1;r>=0&&(e===void 0||n===void 0);r--){const i=t.tags[r];i.length>=2&&(i[0]==="e"&&e===void 0?e=i:i[0]==="p"&&n===void 0&&(n=i))}if(e!==void 0)return{id:e[1],relays:[e[2],n==null?void 0:n[2]].filter(r=>typeof r=="string"),author:n==null?void 0:n[1]}}function xc(t,{skipVerification:e}={}){const n=fi(t);if(n===void 0||t.content==="")return;let r;try{r=JSON.parse(t.content)}catch{return}if(r.id===n.id&&!(!e&&!vt(r)))return r}var Sc={};q(Sc,{NOSTR_URI_REGEX:()=>Sn,parse:()=>Nc,test:()=>Kc});var Sn=new RegExp(`nostr:(${Wr.source})`);function Kc(t){return typeof t=="string"&&new RegExp(`^${Sn.source}$`).test(t)}function Nc(t){const e=t.match(new RegExp(`^${Sn.source}$`));if(!e)throw new Error(`Invalid Nostr URI: ${t}`);return{uri:e[0],value:e[1],decoded:bt(e[1])}}var Ac={};q(Ac,{finishReactionEvent:()=>Ic,getReactedEventPointer:()=>Cc});function Ic(t,e,n){const r=e.tags.filter(i=>i.length>=2&&(i[0]==="e"||i[0]==="p"));return te({...t,kind:ln,tags:[...t.tags??[],...r,["e",e.id],["p",e.pubkey]],content:t.content??"+"},n)}function Cc(t){if(t.kind!==ln)return;let e,n;for(let r=t.tags.length-1;r>=0&&(e===void 0||n===void 0);r--){const i=t.tags[r];i.length>=2&&(i[0]==="e"&&e===void 0?e=i:i[0]==="p"&&n===void 0&&(n=i))}if(!(e===void 0||n===void 0))return{id:e[1],relays:[e[2],n[2]].filter(r=>r!==void 0),author:n[1]}}var Uc={};q(Uc,{parse:()=>Bc});var kc=/\W/m,yi=/\W |\W$|$|,| /m;function*Bc(t){const e=t.length;let n=0,r=0;for(;r<e;){let i=t.indexOf(":",r);if(i===-1)break;if(t.substring(i-5,i)==="nostr"){const s=t.substring(i+60).match(kc),o=s?i+60+s.index:e;try{let c,{data:a,type:u}=bt(t.substring(i+1,o));switch(u){case"npub":c={pubkey:a};break;case"nsec":case"note":r=o+1;continue;default:c=a}n!==i-5&&(yield{type:"text",text:t.substring(n,i-5)}),yield{type:"reference",pointer:c},r=o,n=r;continue}catch{r=i+1;continue}}else if(t.substring(i-5,i)==="https"||t.substring(i-4,i)==="http"){const s=t.substring(i+4).match(yi),o=s?i+4+s.index:e,c=t[i-1]==="s"?5:4;try{let a=new URL(t.substring(i-c,o));if(a.hostname.indexOf(".")===-1)throw new Error("invalid url");if(n!==i-c&&(yield{type:"text",text:t.substring(n,i-c)}),a.pathname.endsWith(".png")||a.pathname.endsWith(".jpg")||a.pathname.endsWith(".jpeg")||a.pathname.endsWith(".gif")||a.pathname.endsWith(".webp")){yield{type:"image",url:a.toString()},r=o,n=r;continue}if(a.pathname.endsWith(".mp4")||a.pathname.endsWith(".avi")||a.pathname.endsWith(".webm")||a.pathname.endsWith(".mkv")){yield{type:"video",url:a.toString()},r=o,n=r;continue}if(a.pathname.endsWith(".mp3")||a.pathname.endsWith(".aac")||a.pathname.endsWith(".ogg")||a.pathname.endsWith(".opus")){yield{type:"audio",url:a.toString()},r=o,n=r;continue}yield{type:"url",url:a.toString()},r=o,n=r;continue}catch{r=o+1;continue}}else if(t.substring(i-3,i)==="wss"||t.substring(i-2,i)==="ws"){const s=t.substring(i+4).match(yi),o=s?i+4+s.index:e,c=t[i-1]==="s"?3:2;try{let a=new URL(t.substring(i-c,o));if(a.hostname.indexOf(".")===-1)throw new Error("invalid ws url");n!==i-c&&(yield{type:"text",text:t.substring(n,i-c)}),yield{type:"relay",url:a.toString()},r=o,n=r;continue}catch{r=o+1;continue}}else{r=i+1;continue}}n!==e&&(yield{type:"text",text:t.substring(n)})}var _c={};q(_c,{channelCreateEvent:()=>Rc,channelHideMessageEvent:()=>Lc,channelMessageEvent:()=>Tc,channelMetadataEvent:()=>$c,channelMuteUserEvent:()=>Mc});var Rc=(t,e)=>{let n;if(typeof t.content=="object")n=JSON.stringify(t.content);else if(typeof t.content=="string")n=t.content;else return;return te({kind:Mr,tags:[...t.tags??[]],content:n,created_at:t.created_at},e)},$c=(t,e)=>{let n;if(typeof t.content=="object")n=JSON.stringify(t.content);else if(typeof t.content=="string")n=t.content;else return;return te({kind:Pr,tags:[["e",t.channel_create_event_id],...t.tags??[]],content:n,created_at:t.created_at},e)},Tc=(t,e)=>{const n=[["e",t.channel_create_event_id,t.relay_url,"root"]];return t.reply_to_channel_message_event_id&&n.push(["e",t.reply_to_channel_message_event_id,t.relay_url,"reply"]),te({kind:Or,tags:[...n,...t.tags??[]],content:t.content,created_at:t.created_at},e)},Lc=(t,e)=>{let n;if(typeof t.content=="object")n=JSON.stringify(t.content);else if(typeof t.content=="string")n=t.content;else return;return te({kind:Hr,tags:[["e",t.channel_message_event_id],...t.tags??[]],content:n,created_at:t.created_at},e)},Mc=(t,e)=>{let n;if(typeof t.content=="object")n=JSON.stringify(t.content);else if(typeof t.content=="string")n=t.content;else return;return te({kind:Dr,tags:[["p",t.pubkey_to_mute],...t.tags??[]],content:n,created_at:t.created_at},e)},Pc={};q(Pc,{EMOJI_SHORTCODE_REGEX:()=>pi,matchAll:()=>Oc,regex:()=>Kn,replaceAll:()=>Hc});var pi=/:(\w+):/,Kn=()=>new RegExp(`\\B${pi.source}\\B`,"g");function*Oc(t){const e=t.matchAll(Kn());for(const n of e)try{const[r,i]=n;yield{shortcode:r,name:i,start:n.index,end:n.index+r.length}}catch{}}function Hc(t,e){return t.replaceAll(Kn(),(n,r)=>e({shortcode:n,name:r}))}var Dc={};q(Dc,{useFetchImplementation:()=>qc,validateGithub:()=>jc});var Nn;try{Nn=fetch}catch{}function qc(t){Nn=t}async function jc(t,e,n){try{return await(await Nn(`https://gist.github.com/${e}/${n}/raw`)).text()===`Verifying that I control the following Nostr public key: ${t}`}catch{return!1}}var zc={};q(zc,{makeNwcRequestEvent:()=>Wc,parseConnectionString:()=>Vc});function Vc(t){const{host:e,pathname:n,searchParams:r}=new URL(t),i=n||e,s=r.get("relay"),o=r.get("secret");if(!i||!s||!o)throw new Error("invalid connection string");return{pubkey:i,relay:s,secret:o}}async function Wc(t,e,n){const i=Fr(e,t,JSON.stringify({method:"pay_invoice",params:{invoice:n}})),s={kind:zr,created_at:Math.round(Date.now()/1e3),content:i,tags:[["p",t]]};return te(s,e)}var Fc={};q(Fc,{normalizeIdentifier:()=>Zc});function Zc(t){return t=t.trim().toLowerCase(),t=t.normalize("NFKC"),Array.from(t).map(e=>new RegExp("\\p{Letter}","u").test(e)||new RegExp("\\p{Number}","u").test(e)?e:"-").join("")}var Gc={};q(Gc,{getSatoshisAmountFromBolt11:()=>tu,getZapEndpoint:()=>Yc,makeZapReceipt:()=>eu,makeZapRequest:()=>Xc,useFetchImplementation:()=>Jc,validateZapRequest:()=>Qc});var An;try{An=fetch}catch{}function Jc(t){An=t}async function Yc(t){try{let e="",{lud06:n,lud16:r}=JSON.parse(t.content);if(n){let{words:o}=je.decode(n,1e3),c=je.fromWords(o);e=ve.decode(c)}else if(r){let[o,c]=r.split("@");e=new URL(`/.well-known/lnurlp/${o}`,`https://${c}`).toString()}else return null;let s=await(await An(e)).json();if(s.allowsNostr&&s.nostrPubkey)return s.callback}catch{}return null}function Xc(t){let e={kind:9734,created_at:Math.round(Date.now()/1e3),content:t.comment||"",tags:[["p","pubkey"in t?t.pubkey:t.event.pubkey],["amount",t.amount.toString()],["relays",...t.relays]]};if("event"in t){if(e.tags.push(["e",t.event.id]),an(t.event.kind)){const n=["a",`${t.event.kind}:${t.event.pubkey}:`];e.tags.push(n)}else if(cn(t.event.kind)){let n=t.event.tags.find(([i,s])=>i==="d"&&s);if(!n)throw new Error("d tag not found or is empty");const r=["a",`${t.event.kind}:${t.event.pubkey}:${n[1]}`];e.tags.push(r)}e.tags.push(["k",t.event.kind.toString()])}return e}function Qc(t){let e;try{e=JSON.parse(t)}catch{return"Invalid zap request JSON."}if(!gt(e))return"Zap request is not a valid Nostr event.";if(!vt(e))return"Invalid signature on zap request.";let n=e.tags.find(([s,o])=>s==="p"&&o);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=e.tags.find(([s,o])=>s==="e"&&o);return r&&!r[1].match(/^[a-f0-9]{64}$/)?"Zap request 'e' tag is not valid hex.":e.tags.find(([s,o])=>s==="relays"&&o)?null:"Zap request doesn't have a 'relays' tag."}function eu({zapRequest:t,preimage:e,bolt11:n,paidAt:r}){let i=JSON.parse(t),s=i.tags.filter(([c])=>c==="e"||c==="p"||c==="a"),o={kind:9735,created_at:Math.round(r.getTime()/1e3),content:"",tags:[...s,["P",i.pubkey],["bolt11",n],["description",t]]};return e&&o.tags.push(["preimage",e]),o}function tu(t){if(t.length<50)return 0;t=t.substring(0,50);const e=t.lastIndexOf("1");if(e===-1)return 0;const n=t.substring(0,e);if(!n.startsWith("lnbc"))return 0;const r=n.substring(4);if(r.length<1)return 0;const i=r[r.length-1],s=i.charCodeAt(0)-48,o=s>=0&&s<=9;let c=r.length-1;if(o&&c++,c<1)return 0;const a=parseInt(r.substring(0,c));switch(i){case"m":return a*1e5;case"u":return a*100;case"n":return a/10;case"p":return a/1e4;default:return a*1e8}}var nu={};q(nu,{getToken:()=>ru,hashPayload:()=>In,unpackEventFromToken:()=>wi,validateEvent:()=>Si,validateEventKind:()=>bi,validateEventMethodTag:()=>Ei,validateEventPayloadTag:()=>xi,validateEventTimestamp:()=>vi,validateEventUrlTag:()=>mi,validateToken:()=>iu});var gi="Nostr ";async function ru(t,e,n,r=!1,i){const s={kind:dn,tags:[["u",t],["method",e]],created_at:Math.round(new Date().getTime()/1e3),content:""};i&&s.tags.push(["payload",In(i)]);const o=await n(s);return(r?gi:"")+ge.encode(ne.encode(JSON.stringify(o)))}async function iu(t,e,n){const r=await wi(t).catch(s=>{throw s});return await Si(r,e,n).catch(s=>{throw s})}async function wi(t){if(!t)throw new Error("Missing token");t=t.replace(gi,"");const e=ve.decode(ge.decode(t));if(!e||e.length===0||!e.startsWith("{"))throw new Error("Invalid token");return JSON.parse(e)}function vi(t){return t.created_at?Math.round(new Date().getTime()/1e3)-t.created_at<60:!1}function bi(t){return t.kind===dn}function mi(t,e){const n=t.tags.find(r=>r[0]==="u");return n?n.length>0&&n[1]===e:!1}function Ei(t,e){const n=t.tags.find(r=>r[0]==="method");return n?n.length>0&&n[1].toLowerCase()===e.toLowerCase():!1}function In(t){const e=de(ne.encode(JSON.stringify(t)));return D(e)}function xi(t,e){const n=t.tags.find(i=>i[0]==="payload");if(!n)return!1;const r=In(e);return n.length>0&&n[1]===r}async function Si(t,e,n,r){if(!vt(t))throw new Error("Invalid nostr event, signature invalid");if(!bi(t))throw new Error("Invalid nostr event, kind invalid");if(!vi(t))throw new Error("Invalid nostr event, created_at timestamp invalid");if(!mi(t,e))throw new Error("Invalid nostr event, url tag invalid");if(!Ei(t,n))throw new Error("Invalid nostr event, method tag invalid");if(r&&typeof r=="object"&&Object.keys(r).length>0&&!xi(t,r))throw new Error("Invalid nostr event, payload tag does not match request body hash");return!0}const Le=1060,We=30078,Cn=1059,Un=14,su=100,ou=1;function kn(t){return JSON.stringify({version:ou,rootKey:D(t.rootKey),theirCurrentNostrPublicKey:t.theirCurrentNostrPublicKey,theirNextNostrPublicKey:t.theirNextNostrPublicKey,ourCurrentNostrKey:t.ourCurrentNostrKey?{publicKey:t.ourCurrentNostrKey.publicKey,privateKey:D(t.ourCurrentNostrKey.privateKey)}:void 0,ourNextNostrKey:{publicKey:t.ourNextNostrKey.publicKey,privateKey:D(t.ourNextNostrKey.privateKey)},receivingChainKey:t.receivingChainKey?D(t.receivingChainKey):void 0,sendingChainKey:t.sendingChainKey?D(t.sendingChainKey):void 0,sendingChainMessageNumber:t.sendingChainMessageNumber,receivingChainMessageNumber:t.receivingChainMessageNumber,previousSendingChainMessageCount:t.previousSendingChainMessageCount,skippedKeys:Object.fromEntries(Object.entries(t.skippedKeys).map(([e,n])=>[e,{headerKeys:n.headerKeys.map(r=>D(r)),messageKeys:Object.fromEntries(Object.entries(n.messageKeys).map(([r,i])=>[r,D(i)]))}]))})}function Bn(t){const e=JSON.parse(t);if(!e.version){const n={};return e.skippedMessageKeys&&Object.entries(e.skippedMessageKeys).forEach(([r,i])=>{var s;n[r]={headerKeys:((s=e.skippedHeaderKeys)==null?void 0:s[r])||[],messageKeys:i}}),{rootKey:W(e.rootKey),theirCurrentNostrPublicKey:e.theirCurrentNostrPublicKey,theirNextNostrPublicKey:e.theirNextNostrPublicKey,ourCurrentNostrKey:e.ourCurrentNostrKey?{publicKey:e.ourCurrentNostrKey.publicKey,privateKey:W(e.ourCurrentNostrKey.privateKey)}:void 0,ourNextNostrKey:{publicKey:e.ourNextNostrKey.publicKey,privateKey:W(e.ourNextNostrKey.privateKey)},receivingChainKey:e.receivingChainKey?W(e.receivingChainKey):void 0,sendingChainKey:e.sendingChainKey?W(e.sendingChainKey):void 0,sendingChainMessageNumber:e.sendingChainMessageNumber,receivingChainMessageNumber:e.receivingChainMessageNumber,previousSendingChainMessageCount:e.previousSendingChainMessageCount,skippedKeys:n}}return{rootKey:W(e.rootKey),theirCurrentNostrPublicKey:e.theirCurrentNostrPublicKey,theirNextNostrPublicKey:e.theirNextNostrPublicKey,ourCurrentNostrKey:e.ourCurrentNostrKey?{publicKey:e.ourCurrentNostrKey.publicKey,privateKey:W(e.ourCurrentNostrKey.privateKey)}:void 0,ourNextNostrKey:{publicKey:e.ourNextNostrKey.publicKey,privateKey:W(e.ourNextNostrKey.privateKey)},receivingChainKey:e.receivingChainKey?W(e.receivingChainKey):void 0,sendingChainKey:e.sendingChainKey?W(e.sendingChainKey):void 0,sendingChainMessageNumber:e.sendingChainMessageNumber,receivingChainMessageNumber:e.receivingChainMessageNumber,previousSendingChainMessageCount:e.previousSendingChainMessageCount,skippedKeys:Object.fromEntries(Object.entries(e.skippedKeys||{}).map(([n,r])=>[n,{headerKeys:r.headerKeys.map(i=>W(i)),messageKeys:Object.fromEntries(Object.entries(r.messageKeys).map(([i,s])=>[i,W(s)]))}]))}}function Ki(t){return{rootKey:new Uint8Array(t.rootKey),theirCurrentNostrPublicKey:t.theirCurrentNostrPublicKey,theirNextNostrPublicKey:t.theirNextNostrPublicKey,ourCurrentNostrKey:t.ourCurrentNostrKey?{publicKey:t.ourCurrentNostrKey.publicKey,privateKey:new Uint8Array(t.ourCurrentNostrKey.privateKey)}:void 0,ourNextNostrKey:{publicKey:t.ourNextNostrKey.publicKey,privateKey:new Uint8Array(t.ourNextNostrKey.privateKey)},receivingChainKey:t.receivingChainKey?new Uint8Array(t.receivingChainKey):void 0,sendingChainKey:t.sendingChainKey?new Uint8Array(t.sendingChainKey):void 0,sendingChainMessageNumber:t.sendingChainMessageNumber,receivingChainMessageNumber:t.receivingChainMessageNumber,previousSendingChainMessageCount:t.previousSendingChainMessageCount,skippedKeys:Object.fromEntries(Object.entries(t.skippedKeys).map(([e,n])=>[e,{headerKeys:n.headerKeys.map(r=>new Uint8Array(r)),messageKeys:Object.fromEntries(Object.entries(n.messageKeys).map(([r,i])=>[r,new Uint8Array(i)]))}]))}}async function*au(t){const e=[];let n=null;const r=t.onEvent(i=>{n?(n(i),n=null):e.push(i)});try{for(;;)e.length>0?yield e.shift():yield new Promise(i=>{n=i})}finally{r()}}function Me(t,e=new Uint8Array(32),n=1){const r=rn(de,t,e),i=[];for(let s=1;s<=n;s++)i.push(kr(de,r,new Uint8Array([s]),32));return i}function cu(t,e){return`${t}:${e}`}function uu(t){var n;const e=(n=t.tags)==null?void 0:n.find(r=>r[0]==="ms");return e?parseInt(e[1]):t.created_at*1e3}const lu=1e3,hu="0000000000000000000000000000000000000000000000000000000000000000";class Pe{constructor(e,n){$(this,"skippedSubscription");$(this,"nostrUnsubscribe");$(this,"nostrNextUnsubscribe");$(this,"internalSubscriptions",new Map);$(this,"currentInternalSubscriptionId",0);$(this,"name");this.nostrSubscribe=e,this.state=n,this.name=Math.random().toString(36).substring(2,6)}static init(e,n,r,i,s,o){const c=Te();let a,u,h,l;i?([a,u]=Me(s,j.getConversationKey(c,n),2),h={publicKey:le(r),privateKey:r},l={publicKey:le(c),privateKey:c}):(a=s,u=void 0,h=void 0,l={publicKey:le(r),privateKey:r});const y={rootKey:a,theirNextNostrPublicKey:n,ourCurrentNostrKey:h,ourNextNostrKey:l,receivingChainKey:void 0,sendingChainKey:u,sendingChainMessageNumber:0,receivingChainMessageNumber:0,previousSendingChainMessageCount:0,skippedKeys:{}},w=new Pe(e,y);return o&&(w.name=o),w}send(e){return this.sendEvent({content:e,kind:Un})}sendEvent(e){if(!this.state.theirNextNostrPublicKey||!this.state.ourCurrentNostrKey)throw new Error("we are not the initiator, so we can't send the first message");if("sig"in e)throw new Error("Event must be unsigned "+JSON.stringify(e));const n=Date.now(),r={...e,content:e.content||"",kind:e.kind||Le,created_at:e.created_at||Math.floor(n/1e3),tags:e.tags||[],pubkey:e.pubkey||hu};r.tags.some(([u])=>u==="ms")||r.tags.push(["ms",String(n)]),r.id=$e(r);const[i,s]=this.ratchetEncrypt(JSON.stringify(r)),o=j.getConversationKey(this.state.ourCurrentNostrKey.privateKey,this.state.theirNextNostrPublicKey),c=j.encrypt(JSON.stringify(i),o);return{event:te({content:s,kind:Le,tags:[["header",c]],created_at:Math.floor(n/1e3)},this.state.ourCurrentNostrKey.privateKey),innerEvent:r}}onEvent(e){const n=this.currentInternalSubscriptionId++;return this.internalSubscriptions.set(n,e),this.subscribeToNostrEvents(),()=>this.internalSubscriptions.delete(n)}close(){var e,n,r;(e=this.nostrUnsubscribe)==null||e.call(this),(n=this.nostrNextUnsubscribe)==null||n.call(this),(r=this.skippedSubscription)==null||r.call(this),this.internalSubscriptions.clear()}ratchetEncrypt(e){const[n,r]=Me(this.state.sendingChainKey,new Uint8Array([1]),2);return this.state.sendingChainKey=n,[{number:this.state.sendingChainMessageNumber++,nextPublicKey:this.state.ourNextNostrKey.publicKey,previousChainLength:this.state.previousSendingChainMessageCount},j.encrypt(e,r)]}ratchetDecrypt(e,n,r){const i=this.trySkippedMessageKeys(e,n,r);if(i)return i;this.skipMessageKeys(e.number,r);const[s,o]=Me(this.state.receivingChainKey,new Uint8Array([1]),2);return this.state.receivingChainKey=s,this.state.receivingChainMessageNumber++,j.decrypt(n,o)}ratchetStep(){this.state.previousSendingChainMessageCount=this.state.sendingChainMessageNumber,this.state.sendingChainMessageNumber=0,this.state.receivingChainMessageNumber=0;const e=j.getConversationKey(this.state.ourNextNostrKey.privateKey,this.state.theirNextNostrPublicKey),[n,r]=Me(this.state.rootKey,e,2);this.state.receivingChainKey=r,this.state.ourCurrentNostrKey=this.state.ourNextNostrKey;const i=Te();this.state.ourNextNostrKey={publicKey:le(i),privateKey:i};const s=j.getConversationKey(this.state.ourNextNostrKey.privateKey,this.state.theirNextNostrPublicKey),[o,c]=Me(n,s,2);this.state.rootKey=o,this.state.sendingChainKey=c}skipMessageKeys(e,n){if(!(e<=this.state.receivingChainMessageNumber)){if(e>this.state.receivingChainMessageNumber+lu)throw new Error("Too many skipped messages");if(!this.state.skippedKeys[n]){if(this.state.skippedKeys[n]={headerKeys:[],messageKeys:{}},this.state.ourCurrentNostrKey){const i=j.getConversationKey(this.state.ourCurrentNostrKey.privateKey,n);this.state.skippedKeys[n].headerKeys.includes(i)||this.state.skippedKeys[n].headerKeys.push(i)}const r=j.getConversationKey(this.state.ourNextNostrKey.privateKey,n);this.state.skippedKeys[n].headerKeys.includes(r)||this.state.skippedKeys[n].headerKeys.push(r)}for(;this.state.receivingChainMessageNumber<e;){const[r,i]=Me(this.state.receivingChainKey,new Uint8Array([1]),2);this.state.receivingChainKey=r,this.state.skippedKeys[n].messageKeys[this.state.receivingChainMessageNumber]=i,this.state.receivingChainMessageNumber++}}}trySkippedMessageKeys(e,n,r){const i=this.state.skippedKeys[r];if(!i)return null;const s=i.messageKeys[e.number];return s?(delete i.messageKeys[e.number],Object.keys(i.messageKeys).length===0&&delete this.state.skippedKeys[r],j.decrypt(n,s)):null}decryptHeader(e){const n=e.tags[0][1];if(this.state.ourCurrentNostrKey){const s=j.getConversationKey(this.state.ourCurrentNostrKey.privateKey,e.pubkey);try{return[JSON.parse(j.decrypt(n,s)),!1,!1]}catch{}}const r=j.getConversationKey(this.state.ourNextNostrKey.privateKey,e.pubkey);try{return[JSON.parse(j.decrypt(n,r)),!0,!1]}catch{}const i=this.state.skippedKeys[e.pubkey];if(i!=null&&i.headerKeys)for(const s of i.headerKeys)try{return[JSON.parse(j.decrypt(n,s)),!1,!0]}catch{}throw new Error("Failed to decrypt header with current and skipped header keys")}handleNostrEvent(e){var i,s;const n=Ki(this.state);let r=!1;try{const[o,c,a]=this.decryptHeader(e);if(!a&&this.state.theirNextNostrPublicKey!==o.nextPublicKey&&(this.state.theirCurrentNostrPublicKey=this.state.theirNextNostrPublicKey,this.state.theirNextNostrPublicKey=o.nextPublicKey,r=!0),!a)c&&(this.skipMessageKeys(o.previousChainLength,e.pubkey),this.ratchetStep());else if(!((i=this.state.skippedKeys[e.pubkey])!=null&&i.messageKeys[o.number]))return;const u=this.ratchetDecrypt(o,e.content,e.pubkey),h=JSON.parse(u);if(!gt(h)){this.state=n;return}if(h.id!==$e(h)){this.state=n;return}r&&((s=this.nostrUnsubscribe)==null||s.call(this),this.nostrUnsubscribe=this.nostrNextUnsubscribe,this.nostrNextUnsubscribe=this.nostrSubscribe({authors:[this.state.theirNextNostrPublicKey],kinds:[Le]},l=>this.handleNostrEvent(l))),this.internalSubscriptions.forEach(l=>l(h,e))}catch(o){if(this.state=n,o instanceof Error&&(o.message.includes("Failed to decrypt header")||o.message==="invalid MAC"))return;throw o}}subscribeToNostrEvents(){if(this.nostrNextUnsubscribe)return;this.nostrNextUnsubscribe=this.nostrSubscribe({authors:[this.state.theirNextNostrPublicKey],kinds:[Le]},n=>this.handleNostrEvent(n)),this.state.theirCurrentNostrPublicKey&&(this.nostrUnsubscribe=this.nostrSubscribe({authors:[this.state.theirCurrentNostrPublicKey],kinds:[Le]},n=>this.handleNostrEvent(n)));const e=Object.keys(this.state.skippedKeys);e.length&&(this.skippedSubscription=this.nostrSubscribe({authors:e,kinds:[Le]},n=>this.handleNostrEvent(n)))}}new TextDecoder("utf-8"),new TextEncoder;function Kt(t,e){const n=Re.getSharedSecret(t,"02"+e).subarray(1,33);return rn(de,n,"nip44-v2")}const du=2*24*60*60,Ni=()=>Math.round(Date.now()/1e3),fu=()=>Math.round(Ni()-Math.random()*du);class re{constructor(e,n,r,i,s,o,c=[],a=Ni()){this.inviterEphemeralPublicKey=e,this.sharedSecret=n,this.inviter=r,this.inviterEphemeralPrivateKey=i,this.deviceId=s,this.maxUses=o,this.usedBy=c,this.createdAt=a}static createNew(e,n,r){if(!e)throw new Error("Inviter public key is required");const i=Te(),s=le(i),o=D(Te());return new re(s,o,e,i,n,r)}static fromUrl(e){const r=new URL(e).hash.slice(1);if(!r)throw new Error("No invite data found in the URL hash.");const i=decodeURIComponent(r);let s;try{s=JSON.parse(i)}catch(u){throw new Error("Invite data in URL hash is not valid JSON: "+u)}const{inviter:o,ephemeralKey:c,sharedSecret:a}=s;if(!o||!c||!a)throw new Error("Missing required fields (inviter, ephemeralKey, sharedSecret) in invite data.");return new re(c,a,o)}static deserialize(e){const n=JSON.parse(e);return new re(n.inviterEphemeralPublicKey,n.sharedSecret,n.inviter,n.inviterEphemeralPrivateKey?new Uint8Array(n.inviterEphemeralPrivateKey):void 0,n.deviceId,n.maxUses,n.usedBy,n.createdAt)}static fromEvent(e){var a,u,h,l;if(!e.sig)throw new Error("Event is not signed");if(!vt(e))throw new Error("Event signature is invalid");const{tags:n}=e;if(!n)throw new Error("Invalid invite event: missing tags");const r=(a=n.find(([y])=>y==="ephemeralKey"))==null?void 0:a[1],i=(u=n.find(([y])=>y==="sharedSecret"))==null?void 0:u[1],s=e.pubkey,o=(h=n.find(([y])=>y==="d"))==null?void 0:h[1],c=(l=o==null?void 0:o.split("/"))==null?void 0:l[2];if(!r||!i)throw new Error("Invalid invite event: missing session key or sharedSecret");return new re(r,i,s,void 0,c)}static fromUser(e,n,r){const i={kinds:[We],authors:[e],"#l":["double-ratchet/invites"]},s=new Set;return n(i,c=>{if(c.pubkey!==e){console.error("Got invite event from wrong user",c.pubkey,"expected",e);return}if(!s.has(c.id)){s.add(c.id);try{const a=re.fromEvent(c);r(a)}catch{}}})}serialize(){return JSON.stringify({inviterEphemeralPublicKey:this.inviterEphemeralPublicKey,sharedSecret:this.sharedSecret,inviter:this.inviter,inviterEphemeralPrivateKey:this.inviterEphemeralPrivateKey?Array.from(this.inviterEphemeralPrivateKey):void 0,deviceId:this.deviceId,maxUses:this.maxUses,usedBy:this.usedBy,createdAt:this.createdAt})}getUrl(e="https://iris.to"){const n={inviter:this.inviter,ephemeralKey:this.inviterEphemeralPublicKey,sharedSecret:this.sharedSecret},r=new URL(e);return r.hash=encodeURIComponent(JSON.stringify(n)),r.toString()}getEvent(){if(!this.deviceId)throw new Error("Device ID is required");return{kind:We,pubkey:this.inviter,content:"",created_at:this.createdAt,tags:[["ephemeralKey",this.inviterEphemeralPublicKey],["sharedSecret",this.sharedSecret],["d","double-ratchet/invites/"+this.deviceId],["l","double-ratchet/invites"]]}}getDeletionEvent(){if(!this.deviceId)throw new Error("Device ID is required");return{kind:We,pubkey:this.inviter,content:"",created_at:Math.floor(Date.now()/1e3),tags:[["ephemeralKey",this.inviterEphemeralPublicKey],["sharedSecret",this.sharedSecret],["d","double-ratchet/invites/"+this.deviceId]]}}async accept(e,n,r,i){const s=Te(),o=le(s),c=this.inviter||this.inviterEphemeralPublicKey,a=W(this.sharedSecret),u=Pe.init(e,this.inviterEphemeralPublicKey,s,!0,a,void 0),h=typeof r=="function"?r:(m,N)=>Promise.resolve(j.encrypt(m,Kt(r,N))),l=JSON.stringify({sessionKey:o,deviceId:i}),y=await h(l,c),w={pubkey:n,content:await j.encrypt(y,a),created_at:Math.floor(Date.now()/1e3)},g=JSON.stringify(w),d=Te(),f=le(d),p={kind:Cn,pubkey:f,content:j.encrypt(g,Kt(d,this.inviterEphemeralPublicKey)),created_at:fu(),tags:[["p",this.inviterEphemeralPublicKey]]};return{session:u,event:te(p,d)}}listen(e,n,r){if(!this.inviterEphemeralPrivateKey)throw new Error("Inviter session key is not available");const i={kinds:[Cn],"#p":[this.inviterEphemeralPublicKey]};return n(i,async s=>{try{if(this.maxUses&&this.usedBy.length>=this.maxUses)return;const o=await j.decrypt(s.content,Kt(this.inviterEphemeralPrivateKey,s.pubkey)),c=JSON.parse(o),a=W(this.sharedSecret),u=c.pubkey;this.usedBy.push(u);const h=await j.decrypt(c.content,a),y=await(typeof e=="function"?e:(p,m)=>Promise.resolve(j.decrypt(p,Kt(e,m))))(h,u);let w,g;try{const p=JSON.parse(y);w=p.sessionKey,g=p.deviceId}catch{w=y}const d=s.id,f=Pe.init(n,w,this.inviterEphemeralPrivateKey,!1,a,d);r(f,u,g)}catch{}})}}class Ai{constructor(){$(this,"store",new Map)}async get(e){return this.store.get(e)}async put(e,n){this.store.set(e,n)}async del(e){this.store.delete(e)}async list(e=""){const n=[],r=Array.from(this.store.keys());for(const i of r)i.startsWith(e)&&n.push(i);return n}}class yu{constructor(e="session_"){$(this,"keyPrefix");this.keyPrefix=e}getFullKey(e){return`${this.keyPrefix}${e}`}async get(e){try{const n=localStorage.getItem(this.getFullKey(e));return n?JSON.parse(n):void 0}catch(n){console.warn(`Failed to get key ${e} from localStorage:`,n);return}}async put(e,n){try{localStorage.setItem(this.getFullKey(e),JSON.stringify(n))}catch(r){throw console.error(`Failed to put key ${e} to localStorage:`,r),r}}async del(e){try{localStorage.removeItem(this.getFullKey(e))}catch(n){console.warn(`Failed to delete key ${e} from localStorage:`,n)}}async list(e=""){const n=[],r=this.getFullKey(e);try{for(let i=0;i<localStorage.length;i++){const s=localStorage.key(i);s&&s.startsWith(r)&&n.push(s.substring(this.keyPrefix.length))}}catch(i){console.warn("Failed to list keys from localStorage:",i)}return n}}class pu{constructor(e,n,r,i,s,o){$(this,"storageVersion","1");$(this,"versionPrefix");$(this,"deviceId");$(this,"storage");$(this,"nostrSubscribe");$(this,"nostrPublish");$(this,"ourIdentityKey");$(this,"ourPublicKey");$(this,"userRecords",new Map);$(this,"messageHistory",new Map);$(this,"currentDeviceInvite",null);$(this,"ourDeviceInviteSubscription",null);$(this,"ourDeviceIntiveTombstoneSubscription",null);$(this,"inviteSubscriptions",new Map);$(this,"sessionSubscriptions",new Map);$(this,"inviteTombstoneSubscriptions",new Map);$(this,"internalSubscriptions",new Set);$(this,"initialized",!1);this.userRecords=new Map,this.nostrSubscribe=i,this.nostrPublish=s,this.ourPublicKey=e,this.ourIdentityKey=n,this.deviceId=r,this.storage=o||new Ai,this.versionPrefix=`v${this.storageVersion}`}async init(){if(this.initialized)return;this.initialized=!0,await this.runMigrations().catch(i=>{console.error("Failed to run migrations:",i)}),await this.loadAllUserRecords().catch(i=>{console.error("Failed to load user records:",i)});const n=await this.storage.get(this.deviceInviteKey(this.deviceId)).then(i=>{if(!i)return null;try{return re.deserialize(i)}catch{return null}})||re.createNew(this.ourPublicKey,this.deviceId);this.currentDeviceInvite=n,await this.storage.put(this.deviceInviteKey(this.deviceId),n.serialize()),this.ourDeviceInviteSubscription=n.listen(this.ourIdentityKey,this.nostrSubscribe,async(i,s,o)=>{if(!o||o===this.deviceId)return;const c=i.name,a=this.inviteAcceptKey(c,s,o);if(await this.storage.get(a))return;await this.storage.put(a,"1");const h=this.getOrCreateUserRecord(s),l=this.upsertDeviceRecord(h,o);this.attachSessionSubscription(s,l,i,!0)}),this.ourDeviceIntiveTombstoneSubscription||(this.ourDeviceIntiveTombstoneSubscription=this.createInviteTombstoneSubscription(this.ourPublicKey));const r=n.getEvent();this.nostrPublish(r).catch(i=>{console.error("Failed to publish our device invite:",i)})}getOrCreateUserRecord(e){let n=this.userRecords.get(e);return n||(n={publicKey:e,devices:new Map},this.userRecords.set(e,n)),n}upsertDeviceRecord(e,n){if(!n)throw new Error("Device record must include a deviceId");const r=e.devices.get(n);if(r)return r;const i={deviceId:n,inactiveSessions:[],createdAt:Date.now()};return e.devices.set(n,i),i}createInviteTombstoneSubscription(e){return this.nostrSubscribe({kinds:[We],authors:[e],"#l":["double-ratchet/invites"]},n=>{var r;try{if(!((r=n.tags)!=null&&r.some(([s])=>s==="ephemeralKey"||s==="sharedSecret"))){const s=n.tags.find(([a,u])=>a==="d"&&u.startsWith("double-ratchet/invites/")),[,o]=s||[],c=o.split("/").pop();if(!c)return;this.cleanupDevice(e,c)}}catch(i){console.error("Failed to handle device tombstone:",i)}})}sessionKey(e,n,r){return`${this.sessionKeyPrefix(e)}${n}/${r}`}inviteKey(e){return this.userInviteKey(e)}inviteAcceptKey(e,n,r){return`${this.inviteAcceptKeyPrefix(n)}${r}/${e}`}deviceInviteKey(e){return`${this.versionPrefix}/device-invite/${e}`}userInviteKey(e){return`${this.versionPrefix}/invite/${e}`}inviteAcceptKeyPrefix(e){return`${this.versionPrefix}/invite-accept/${e}/`}sessionKeyPrefix(e){return`${this.versionPrefix}/session/${e}/`}userRecordKey(e){return`${this.userRecordKeyPrefix()}${e}`}userRecordKeyPrefix(){return`${this.versionPrefix}/user/`}versionKey(){return"storage-version"}attachSessionSubscription(e,n,r,i=!1){if(n.staleAt!==void 0)return;const s=this.sessionKey(e,n.deviceId,r.name);if(this.sessionSubscriptions.has(s))return;const o=n,c=u=>{const h=o.activeSession;if(!h){o.activeSession=u;return}if(h===u||h.name===u.name){o.activeSession=u;return}o.inactiveSessions=o.inactiveSessions.filter(l=>l!==h&&l.name!==h.name),o.inactiveSessions.push(h),o.inactiveSessions=o.inactiveSessions.slice(-1),o.activeSession=u};i?o.inactiveSessions.some(h=>h===r||h.name===r.name)||(o.inactiveSessions.push(r),o.inactiveSessions=o.inactiveSessions.slice(-1)):c(r);const a=r.onEvent(u=>{for(const h of this.internalSubscriptions)h(u,e);c(r),this.storeUserRecord(e).catch(console.error)});this.storeUserRecord(e).catch(console.error),this.sessionSubscriptions.set(s,a)}attachInviteSubscription(e,n){const r=this.inviteKey(e);if(this.inviteSubscriptions.has(r))return;const i=re.fromUser(e,this.nostrSubscribe,async s=>{s.deviceId&&n&&await n(s)});this.inviteSubscriptions.set(r,i)}attachInviteTombstoneSubscription(e){if(this.inviteTombstoneSubscriptions.has(e))return;const n=this.createInviteTombstoneSubscription(e);this.inviteTombstoneSubscriptions.set(e,n)}setupUser(e){const n=this.getOrCreateUserRecord(e);this.attachInviteTombstoneSubscription(e);const r=async i=>{const{deviceId:s}=i;if(!s)return;const{session:o,event:c}=await i.accept(this.nostrSubscribe,this.ourPublicKey,this.ourIdentityKey,this.deviceId);return this.nostrPublish(c).then(()=>this.upsertDeviceRecord(n,s)).then(a=>this.attachSessionSubscription(e,a,o)).then(()=>this.sendMessageHistory(e,s)).catch(console.error)};this.attachInviteSubscription(e,async i=>{const{deviceId:s}=i;s&&(n.devices.has(s)||await r(i))})}onEvent(e){return this.internalSubscriptions.add(e),()=>{this.internalSubscriptions.delete(e)}}getDeviceId(){return this.deviceId}getDeviceInviteEphemeralKey(){var e;return((e=this.currentDeviceInvite)==null?void 0:e.inviterEphemeralPublicKey)||null}getUserRecords(){return this.userRecords}close(){var e,n;for(const r of this.inviteSubscriptions.values())r();for(const r of this.sessionSubscriptions.values())r();for(const r of this.inviteTombstoneSubscriptions.values())r();(e=this.ourDeviceInviteSubscription)==null||e.call(this),(n=this.ourDeviceIntiveTombstoneSubscription)==null||n.call(this)}deactivateCurrentSessions(e){const n=this.userRecords.get(e);if(n){for(const r of n.devices.values())r.activeSession&&(r.inactiveSessions.push(r.activeSession),r.activeSession=void 0);this.storeUserRecord(e).catch(console.error)}}async deleteUser(e){await this.init();const n=this.userRecords.get(e);if(n){for(const o of n.devices.values()){o.activeSession&&this.removeSessionSubscription(e,o.deviceId,o.activeSession.name);for(const c of o.inactiveSessions)this.removeSessionSubscription(e,o.deviceId,c.name)}this.userRecords.delete(e)}const r=this.inviteKey(e),i=this.inviteSubscriptions.get(r);i&&(i(),this.inviteSubscriptions.delete(r));const s=this.inviteTombstoneSubscriptions.get(e);s&&(s(),this.inviteTombstoneSubscriptions.delete(e)),this.messageHistory.delete(e),await Promise.allSettled([this.storage.del(this.inviteKey(e)),this.deleteUserSessionsFromStorage(e),this.storage.del(this.userRecordKey(e))])}removeSessionSubscription(e,n,r){const i=this.sessionKey(e,n,r),s=this.sessionSubscriptions.get(i);s&&(s(),this.sessionSubscriptions.delete(i))}async deleteUserSessionsFromStorage(e){const n=this.sessionKeyPrefix(e),r=await this.storage.list(n);await Promise.all(r.map(i=>this.storage.del(i)))}async sendMessageHistory(e,n){const r=this.messageHistory.get(e)||[],i=this.userRecords.get(e);if(!i)return;const s=i.devices.get(n);if(s&&s.staleAt===void 0)for(const o of r){const{activeSession:c}=s;if(!c)continue;const{event:a}=c.sendEvent(o);await this.nostrPublish(a),await this.storeUserRecord(e)}}async sendEvent(e,n){await this.init();const r=n,i=new Set([e,this.ourPublicKey]);for(const a of i){const u=this.messageHistory.get(a)||[];this.messageHistory.set(a,[...u,r])}const s=this.getOrCreateUserRecord(e),o=this.getOrCreateUserRecord(this.ourPublicKey);this.setupUser(e),this.setupUser(this.ourPublicKey);const c=[...Array.from(s.devices.values()),...Array.from(o.devices.values())].filter(a=>a.staleAt===void 0);return Promise.allSettled(c.map(async a=>{const{activeSession:u}=a;if(!u)return;const{event:h}=u.sendEvent(n);await this.nostrPublish(h).catch(console.error)})).then(()=>{this.storeUserRecord(e)}).catch(console.error),r}async sendMessage(e,n,r={}){const{kind:i=Un,tags:s=[]}=r,o=Date.now(),c=this.buildMessageTags(e,s),a={content:n,kind:i,created_at:Math.floor(o/1e3),tags:c,pubkey:this.ourPublicKey,id:""};return a.tags.some(([u])=>u==="ms")||a.tags.push(["ms",String(o)]),a.id=$e(a),this.sendEvent(e,a).catch(console.error),a}async revokeDevice(e){await this.init(),await this.publishDeviceTombstone(e).catch(n=>{console.error("Failed to publish device tombstone:",n)}),await this.cleanupDevice(this.ourPublicKey,e)}async publishDeviceTombstone(e){const n=[["l","double-ratchet/invites"],["d",`double-ratchet/invites/${e}`]],r={content:"",kind:We,created_at:Math.floor(Date.now()/1e3),tags:n,pubkey:this.ourPublicKey};await this.nostrPublish(r)}async cleanupDevice(e,n){const r=this.userRecords.get(e);if(!r)return;const i=r.devices.get(n);if(i){i.activeSession&&this.removeSessionSubscription(e,n,i.activeSession.name);for(const s of i.inactiveSessions)this.removeSessionSubscription(e,n,s.name);i.activeSession=void 0,i.inactiveSessions=[],i.staleAt=Date.now(),await this.storeUserRecord(e).catch(console.error)}}buildMessageTags(e,n){return n.some(s=>s[0]==="p"&&s[1]===e)?[...n]:[["p",e],...n]}storeUserRecord(e){var r;const n={publicKey:e,devices:Array.from(((r=this.userRecords.get(e))==null?void 0:r.devices.entries())||[]).map(([,i])=>({deviceId:i.deviceId,activeSession:i.activeSession?kn(i.activeSession.state):null,inactiveSessions:i.inactiveSessions.map(s=>kn(s.state)),createdAt:i.createdAt,staleAt:i.staleAt}))};return this.storage.put(this.userRecordKey(e),n)}loadUserRecord(e){return this.storage.get(this.userRecordKey(e)).then(n=>{if(!n)return;const r=new Map;for(const i of n.devices){const{deviceId:s,activeSession:o,inactiveSessions:c,createdAt:a,staleAt:u}=i;try{const h=o?new Pe(this.nostrSubscribe,Bn(o)):void 0,l=c.map(y=>new Pe(this.nostrSubscribe,Bn(y)));r.set(s,{deviceId:s,activeSession:h,inactiveSessions:l,createdAt:a,staleAt:u})}catch(h){console.error(`Failed to deserialize session for user ${e}, device ${s}:`,h)}}this.userRecords.set(e,{publicKey:n.publicKey,devices:r}),e!==this.ourPublicKey&&this.attachInviteTombstoneSubscription(e);for(const i of r.values()){const{deviceId:s,activeSession:o,inactiveSessions:c,staleAt:a}=i;if(!(!s||a!==void 0)){for(const u of c.reverse())this.attachSessionSubscription(e,i,u);o&&this.attachSessionSubscription(e,i,o)}}}).catch(n=>{console.error(`Failed to load user record for ${e}:`,n)})}loadAllUserRecords(){const e=this.userRecordKeyPrefix();return this.storage.list(e).then(n=>Promise.all(n.map(r=>{const i=r.slice(e.length);return this.loadUserRecord(i)})))}async runMigrations(){let e=await this.storage.get(this.versionKey());if(!e){const n="invite/",r=await this.storage.list(n);await Promise.all(r.map(async o=>{try{const c=o.slice(n.length),a=await this.storage.get(o);if(a){const u=this.userInviteKey(c),l=re.deserialize(a).serialize();await this.storage.put(u,l),await this.storage.del(o)}}catch(c){console.error("Migration error for invite:",c)}}));const i="user/",s=await this.storage.list(i);await Promise.all(s.map(async o=>{try{const c=o.slice(i.length),a=await this.storage.get(o);if(a){const u=this.userRecordKey(c),h={publicKey:a.publicKey,devices:a.devices.map(l=>({deviceId:l.deviceId,activeSession:null,createdAt:l.createdAt,inactiveSessions:[]}))};await this.storage.put(u,h),await this.storage.del(o)}}catch(c){console.error("Migration error for user record:",c)}})),e="1",await this.storage.put(this.versionKey(),e);return}}}L.CHAT_MESSAGE_KIND=Un,L.INVITE_EVENT_KIND=We,L.INVITE_RESPONSE_KIND=Cn,L.InMemoryStorageAdapter=Ai,L.Invite=re,L.LocalStorageAdapter=yu,L.MAX_SKIP=su,L.MESSAGE_EVENT_KIND=Le,L.Session=Pe,L.SessionManager=pu,L.createEventStream=au,L.deepCopyState=Ki,L.deserializeSessionState=Bn,L.getMillisecondTimestamp=uu,L.kdf=Me,L.serializeSessionState=kn,L.skippedMessageIndexKey=cu,Object.defineProperty(L,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
package/src/Invite.ts
CHANGED
|
@@ -28,6 +28,7 @@ export class Invite {
|
|
|
28
28
|
public deviceId?: string,
|
|
29
29
|
public maxUses?: number,
|
|
30
30
|
public usedBy: string[] = [],
|
|
31
|
+
public createdAt: number = now(),
|
|
31
32
|
) {
|
|
32
33
|
}
|
|
33
34
|
|
|
@@ -84,7 +85,8 @@ export class Invite {
|
|
|
84
85
|
data.inviterEphemeralPrivateKey ? new Uint8Array(data.inviterEphemeralPrivateKey) : undefined,
|
|
85
86
|
data.deviceId,
|
|
86
87
|
data.maxUses,
|
|
87
|
-
data.usedBy
|
|
88
|
+
data.usedBy,
|
|
89
|
+
data.createdAt,
|
|
88
90
|
);
|
|
89
91
|
}
|
|
90
92
|
|
|
@@ -158,6 +160,7 @@ export class Invite {
|
|
|
158
160
|
deviceId: this.deviceId,
|
|
159
161
|
maxUses: this.maxUses,
|
|
160
162
|
usedBy: this.usedBy,
|
|
163
|
+
createdAt: this.createdAt,
|
|
161
164
|
});
|
|
162
165
|
}
|
|
163
166
|
|
|
@@ -183,7 +186,7 @@ export class Invite {
|
|
|
183
186
|
kind: INVITE_EVENT_KIND,
|
|
184
187
|
pubkey: this.inviter,
|
|
185
188
|
content: "",
|
|
186
|
-
created_at:
|
|
189
|
+
created_at: this.createdAt,
|
|
187
190
|
tags: [
|
|
188
191
|
['ephemeralKey', this.inviterEphemeralPublicKey],
|
|
189
192
|
['sharedSecret', this.sharedSecret],
|