PageSourceSearch

https://armada.buzz/assets/vendor-nostr-CmqJCCBF.js

js armada.buzz collected 2026-09-24 13:55:16 UTC 259,379 bytes, 64 lines download raw bytes

1import{r as e,t}from"./rolldown-runtime-QTnfLwEv.js";import{Qr as n}from"./lucide-icons-WJDKjQ_0.js";function r(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name===`Uint8Array`}function i(e,t=``){if(!Number.isSafeInteger(e)||e<0){let n=t&&`"${t}" `;throw Error(`${n}expected integer >= 0, got ${e}`)}}function a(e,t,n=``){let i=r(e),a=e?.length,o=t!==void 0;if(!i||o&&a!==t){let r=n&&`"${n}" `,s=o?` of length ${t}`:``,c=i?`length=${a}`:`type=${typeof e}`;throw Error(r+`expected Uint8Array`+s+`, got `+c)}return e}function o(e){if(typeof e!=`function`||typeof e.create!=`function`)throw Error(`Hash must wrapped by utils.createHasher`);i(e.outputLen),i(e.blockLen)}function s(e,t=!0){if(e.destroyed)throw Error(`Hash instance has been destroyed`);if(t&&e.finished)throw Error(`Hash#digest() has already been called`)}function c(e,t){a(e,void 0,`digestInto() output`);let n=t.outputLen;if(e.length<n)throw Error(`"digestInto() output" expected to be of length >=`+n)}function l(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function u(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function d(e,t){return e<<32-t|e>>>t}var f=typeof Uint8Array.from([]).toHex==`function`&&typeof Uint8Array.fromHex==`function`,p=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,`0`));function m(e){if(a(e),f)return e.toHex();let t=``;for(let n=0;n<e.length;n++)t+=p[e[n]];return t}var h={_0:48,_9:57,A:65,F:70,a:97,f:102};function g(e){if(e>=h._0&&e<=h._9)return e-h._0;if(e>=h.A&&e<=h.F)return e-(h.A-10);if(e>=h.a&&e<=h.f)return e-(h.a-10)}function _(e){if(typeof e!=`string`)throw Error(`hex string expected, got `+typeof e);if(f)return Uint8Array.fromHex(e);let t=e.length,n=t/2;if(t%2)throw Error(`hex string expected, got unpadded hex of length `+t);let r=new Uint8Array(n);for(let t=0,i=0;t<n;t++,i+=2){let n=g(e.charCodeAt(i)),a=g(e.charCodeAt(i+1));if(n===void 0||a===void 0){let t=e[i]+e[i+1];throw Error(`hex string expected, got non-hex character "`+t+`" at index `+i)}r[t]=n*16+a}return r}function v(...e){let t=0;for(let n=0;n<e.length;n++){let r=e[n];a(r),t+=r.length}let n=new Uint8Array(t);for(let t=0,r=0;t<e.length;t++){let i=e[t];n.set(i,r),r+=i.length}return n}function y(e,t={}){let n=(t,n)=>e(n).update(t).digest(),r=e(void 0);return n.outputLen=r.outputLen,n.blockLen=r.blockLen,n.create=t=>e(t),Object.assign(n,t),Object.freeze(n)}function ee(e=32){let t=typeof globalThis==`object`?globalThis.crypto:null;if(typeof t?.getRandomValues!=`function`)throw Error(`crypto.getRandomValues must be defined`);return t.getRandomValues(new Uint8Array(e))}var te=e=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,e])});function b(e,t,n){return e&t^~e&n}function x(e,t,n){return e&t^e&n^t&n}var S=class{blockLen;outputLen;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(e,t,n,r){this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=r,this.buffer=new Uint8Array(e),this.view=u(this.buffer)}update(e){s(this),a(e);let{view:t,buffer:n,blockLen:r}=this,i=e.length;for(let a=0;a<i;){let o=Math.min(r-this.pos,i-a);if(o===r){let t=u(e);for(;r<=i-a;a+=r)this.process(t,a);continue}n.set(e.subarray(a,a+o),this.pos),this.pos+=o,a+=o,this.pos===r&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){s(this),c(e,this),this.finished=!0;let{buffer:t,view:n,blockLen:r,isLE:i}=this,{pos:a}=this;t[a++]=128,l(this.buffer.subarray(a)),this.padOffset>r-a&&(this.process(n,0),a=0);for(let e=a;e<r;e++)t[e]=0;n.setBigUint64(r-8,BigInt(this.length*8),i),this.process(n,0);let o=u(e),d=this.outputLen;if(d%4)throw Error(`_sha2: outputLen must be aligned to 32bit`);let f=d/4,p=this.get();if(f>p.length)throw Error(`_sha2: outputLen bigger than state`);for(let e=0;e<f;e++)o.setUint32(4*e,p[e],i)}digest(){let{buffer:e,outputLen:t}=this;this.digestInto(e);let n=e.slice(0,t);return this.destroy(),n}_cloneInto(e){e||=new this.constructor,e.set(...this.get());let{blockLen:t,buffer:n,length:r,finished:i,destroyed:a,pos:o}=this;return e.destroyed=a,e.finished=i,e.length=r,e.pos=o,r%t&&e.buffer.set(n),e}clone(){return this._cloneInto()}},C=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),w=Uint32Array.from([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,2756
1734187,3204031479,3329325298]),T=new Uint32Array(64),E=class extends S{constructor(e){super(64,e,8,!1)}get(){let{A:e,B:t,C:n,D:r,E:i,F:a,G:o,H:s}=this;return[e,t,n,r,i,a,o,s]}set(e,t,n,r,i,a,o,s){this.A=e|0,this.B=t|0,this.C=n|0,this.D=r|0,this.E=i|0,this.F=a|0,this.G=o|0,this.H=s|0}process(e,t){for(let n=0;n<16;n++,t+=4)T[n]=e.getUint32(t,!1);for(let e=16;e<64;e++){let t=T[e-15],n=T[e-2],r=d(t,7)^d(t,18)^t>>>3;T[e]=(d(n,17)^d(n,19)^n>>>10)+T[e-7]+r+T[e-16]|0}let{A:n,B:r,C:i,D:a,E:o,F:s,G:c,H:l}=this;for(let e=0;e<64;e++){let t=d(o,6)^d(o,11)^d(o,25),u=l+t+b(o,s,c)+w[e]+T[e]|0,f=(d(n,2)^d(n,13)^d(n,22))+x(n,r,i)|0;l=c,c=s,s=o,o=a+u|0,a=i,i=r,r=n,n=u+f|0}n=n+this.A|0,r=r+this.B|0,i=i+this.C|0,a=a+this.D|0,o=o+this.E|0,s=s+this.F|0,c=c+this.G|0,l=l+this.H|0,this.set(n,r,i,a,o,s,c,l)}roundClean(){l(T)}destroy(){this.set(0,0,0,0,0,0,0,0),l(this.buffer)}},D=class extends E{A=C[0]|0;B=C[1]|0;C=C[2]|0;D=C[3]|0;E=C[4]|0;F=C[5]|0;G=C[6]|0;H=C[7]|0;constructor(){super(32)}},O=y(()=>new D,te(1)),k=BigInt(0),A=BigInt(1);function j(e,t=``){if(typeof e!=`boolean`){let n=t&&`"${t}" `;throw Error(n+`expected boolean, got type=`+typeof e)}return e}function M(e){if(typeof e==`bigint`){if(!oe(e))throw Error(`positive bigint expected, got `+e)}else i(e);return e}function N(e){let t=M(e).toString(16);return t.length&1?`0`+t:t}function P(e){if(typeof e!=`string`)throw Error(`hex string expected, got `+typeof e);return e===``?k:BigInt(`0x`+e)}function F(e){return P(m(e))}function I(e){return P(m(ie(a(e)).reverse()))}function ne(e,t){i(t),e=M(e);let n=_(e.toString(16).padStart(t*2,`0`));if(n.length!==t)throw Error(`number too large`);return n}function re(e,t){return ne(e,t).reverse()}function ie(e){return Uint8Array.from(e)}function ae(e){return Uint8Array.from(e,(t,n)=>{let r=t.charCodeAt(0);if(t.length!==1||r>127)throw Error(`string contains non-ASCII character "${e[n]}" with code ${r} at position ${n}`);return r})}var oe=e=>typeof e==`bigint`&&k<=e;function se(e,t,n){return oe(e)&&oe(t)&&oe(n)&&t<=e&&e<n}function ce(e,t,n,r){if(!se(t,n,r))throw Error(`expected valid `+e+`: `+n+` <= n < `+r+`, got `+t)}function le(e){let t;for(t=0;e>k;e>>=A,t+=1);return t}var ue=e=>(A<<BigInt(e))-A;function de(e,t,n){if(i(e,`hashLen`),i(t,`qByteLen`),typeof n!=`function`)throw Error(`hmacFn must be a function`);let r=e=>new Uint8Array(e),a=Uint8Array.of(),o=Uint8Array.of(0),s=Uint8Array.of(1),c=r(e),l=r(e),u=0,d=()=>{c.fill(1),l.fill(0),u=0},f=(...e)=>n(l,v(c,...e)),p=(e=a)=>{l=f(o,e),c=f(),e.length!==0&&(l=f(s,e),c=f())},m=()=>{if(u++>=1e3)throw Error(`drbg: tried max amount of iterations`);let e=0,n=[];for(;e<t;){c=f();let t=c.slice();n.push(t),e+=c.length}return v(...n)};return(e,t)=>{d(),p(e);let n;for(;!(n=t(m()));)p();return d(),n}}function fe(e,t={},n={}){if(!e||typeof e!=`object`)throw Error(`expected valid options object`);function r(t,n,r){let i=e[t];if(r&&i===void 0)return;let a=typeof i;if(a!==n||i===null)throw Error(`param "${t}" is invalid: expected ${n}, got ${a}`)}let i=(e,t)=>Object.entries(e).forEach(([e,n])=>r(e,n,t));i(t,!1),i(n,!0)}function pe(e){let t=new WeakMap;return(n,...r)=>{let i=t.get(n);if(i!==void 0)return i;let a=e(n,...r);return t.set(n,a),a}}var me=BigInt(0),he=BigInt(1),ge=BigInt(2),_e=BigInt(3),ve=BigInt(4),ye=BigInt(5),be=BigInt(7),xe=BigInt(8),Se=BigInt(9),Ce=BigInt(16);function we(e,t){let n=e%t;return n>=me?n:t+n}function Te(e,t,n){let r=e;for(;t-- >me;)r*=r,r%=n;return r}function Ee(e,t){if(e===me)throw Error(`invert: expected non-zero number`);if(t<=me)throw Error(`invert: expected positive modulus, got `+t);let n=we(e,t),r=t,i=me,a=he,o=he,s=me;for(;n!==me;){let e=r/n,t=r%n,c=i-o*e,l=a-s*e;r=n,n=t,i=o,a=s,o=c,s=l}if(r!==he)throw Error(`invert: does not exist`);return we(i,t)}function De(e,t,n){if(!e.eql(e.sqr(t),n))throw Error(`Cannot find square root`)}function Oe(e,t){let n=(e.ORDER+he)/ve,r=e.pow(t,n);return De(e,r,t),r}function ke(e,t){let n=(e.ORDER-ye)/xe,r=e.mul(t,ge),i=e.pow(r,n),a=e.mul(t,i),o=e.mul(e.mul(a,ge),i),s=e.mul(a,e.sub(o,e.ONE));return De(e,s,t),s}function Ae(e){let t=Be(e),n=je(e),r=n(t,t.neg(t.ONE)),i=n(t,r),a=n(t,t.neg(r)),o=(e+be)/Ce;return(e,t)=>{let n=e.pow(t,o),s=e.mul(n,r),c=e.mul(n,i),l=e.mul(n,a),u=e.eql(e.sqr(s),t),d=e.eql(e.sqr(c),t);n=e.cmov(n,s,u),s=e.cmov(l,c,d);let f=e.eql(e.sqr(s),t),p=e.cmov(n,s,f);return De(e,p,t),p}}function je(e){if(e<_e)throw Error(`sqrt is not defined for small field`);let t=e-he,n=0;for(;t%ge===me;)t/=ge,n++;let r=ge,i=Be(e);for(;Le(i,r)===1;)if(r++>1e3)throw Error(`Cannot find square root: probably non-prime P`);if(n===1)return Oe;let a=i.pow(r,t),o=(t+he)/ge;return function(e,r){if(e.is0(r))return r;if(Le(e,r)!==1)throw Error(`Cannot find square root`);let i=n,s=e.mul(e.ONE,a),c=e.pow(r,t),l=e.pow(r,o);for(;!e.eql(c,e.ONE);){if(e.is0(c))return e.ZERO;let t=1,n=e.sqr(c);for(;!e.eql(n,e.ONE);)if(t++,n=e.sqr(n),t===i)throw Error(`Cannot find square root`);let r=he<<BigInt(i-t-1),a=e.pow(s,r);i=t,s=e.sqr(a),c=e.mul(c,s),l=e.mul(l,a)}return l}}function Me(e){return e%ve===_e?Oe:e%xe===ye?ke:e%Ce===Se?Ae(e):je(e)}var Ne=[`create`,`isValid`,`is0`,`neg`,`inv`,`sqrt`,`sqr`,`eql`,`add`,`sub`,`mul`,`pow`,`div`,`addN`,`subN`,`mulN`,`sqrN`];function Pe(e){return fe(e,Ne.reduce((e,t)=>
1(e[t]=`function`,e),{ORDER:`bigint`,BYTES:`number`,BITS:`number`})),e}function Fe(e,t,n){if(n<me)throw Error(`invalid exponent, negatives unsupported`);if(n===me)return e.ONE;if(n===he)return t;let r=e.ONE,i=t;for(;n>me;)n&he&&(r=e.mul(r,i)),i=e.sqr(i),n>>=he;return r}function Ie(e,t,n=!1){let r=Array(t.length).fill(n?e.ZERO:void 0),i=t.reduce((t,n,i)=>e.is0(n)?t:(r[i]=t,e.mul(t,n)),e.ONE),a=e.inv(i);return t.reduceRight((t,n,i)=>e.is0(n)?t:(r[i]=e.mul(t,r[i]),e.mul(t,n)),a),r}function Le(e,t){let n=(e.ORDER-he)/ge,r=e.pow(t,n),i=e.eql(r,e.ONE),a=e.eql(r,e.ZERO),o=e.eql(r,e.neg(e.ONE));if(!i&&!a&&!o)throw Error(`invalid Legendre symbol result`);return i?1:a?0:-1}function Re(e,t){t!==void 0&&i(t);let n=t===void 0?e.toString(2).length:t;return{nBitLength:n,nByteLength:Math.ceil(n/8)}}var ze=class{ORDER;BITS;BYTES;isLE;ZERO=me;ONE=he;_lengths;_sqrt;_mod;constructor(e,t={}){if(e<=me)throw Error(`invalid field: expected ORDER > 0, got `+e);let n;this.isLE=!1,typeof t==`object`&&t&&(typeof t.BITS==`number`&&(n=t.BITS),typeof t.sqrt==`function`&&(this.sqrt=t.sqrt),typeof t.isLE==`boolean`&&(this.isLE=t.isLE),t.allowedLengths&&(this._lengths=t.allowedLengths?.slice()),typeof t.modFromBytes==`boolean`&&(this._mod=t.modFromBytes));let{nBitLength:r,nByteLength:i}=Re(e,n);if(i>2048)throw Error(`invalid field: expected ORDER of <= 2048 bytes`);this.ORDER=e,this.BITS=r,this.BYTES=i,this._sqrt=void 0,Object.preventExtensions(this)}create(e){return we(e,this.ORDER)}isValid(e){if(typeof e!=`bigint`)throw Error(`invalid field element: expected bigint, got `+typeof e);return me<=e&&e<this.ORDER}is0(e){return e===me}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}isOdd(e){return(e&he)===he}neg(e){return we(-e,this.ORDER)}eql(e,t){return e===t}sqr(e){return we(e*e,this.ORDER)}add(e,t){return we(e+t,this.ORDER)}sub(e,t){return we(e-t,this.ORDER)}mul(e,t){return we(e*t,this.ORDER)}pow(e,t){return Fe(this,e,t)}div(e,t){return we(e*Ee(t,this.ORDER),this.ORDER)}sqrN(e){return e*e}addN(e,t){return e+t}subN(e,t){return e-t}mulN(e,t){return e*t}inv(e){return Ee(e,this.ORDER)}sqrt(e){return this._sqrt||=Me(this.ORDER),this._sqrt(this,e)}toBytes(e){return this.isLE?re(e,this.BYTES):ne(e,this.BYTES)}fromBytes(e,t=!1){a(e);let{_lengths:n,BYTES:r,isLE:i,ORDER:o,_mod:s}=this;if(n){if(!n.includes(e.length)||e.length>r)throw Error(`Field.fromBytes: expected `+n+` bytes, got `+e.length);let t=new Uint8Array(r);t.set(e,i?0:t.length-e.length),e=t}if(e.length!==r)throw Error(`Field.fromBytes: expected `+r+` bytes, got `+e.length);let c=i?I(e):F(e);if(s&&(c=we(c,o)),!t&&!this.isValid(c))throw Error(`invalid field element: outside of range 0..ORDER`);return c}invertBatch(e){return Ie(this,e)}cmov(e,t,n){return n?t:e}};function Be(e,t={}){return new ze(e,t)}function Ve(e){if(typeof e!=`bigint`)throw Error(`field order must be bigint`);let t=e.toString(2).length;return Math.ceil(t/8)}function He(e){let t=Ve(e);return t+Math.ceil(t/2)}function Ue(e,t,n=!1){a(e);let r=e.length,i=Ve(t),o=He(t);if(r<16||r<o||r>1024)throw Error(`expected `+o+`-1024 bytes of input, got `+r);let s=we(n?I(e):F(e),t-he)+he;return n?re(s,i):ne(s,i)}var We=BigInt(0),Ge=BigInt(1);function Ke(e,t){let n=t.negate();return e?n:t}function qe(e,t){let n=Ie(e.Fp,t.map(e=>e.Z));return t.map((t,r)=>e.fromAffine(t.toAffine(n[r])))}function Je(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw Error(`invalid window size, expected [1..`+t+`], got W=`+e)}function Ye(e,t){Je(e,t);let n=Math.ceil(t/e)+1,r=2**(e-1),i=2**e;return{windows:n,windowSize:r,mask:ue(e),maxNumber:i,shiftBy:BigInt(e)}}function Xe(e,t,n){let{windowSize:r,mask:i,maxNumber:a,shiftBy:o}=n,s=Number(e&i),c=e>>o;s>r&&(s-=a,c+=Ge);let l=t*r,u=l+Math.abs(s)-1,d=s===0,f=s<0,p=t%2!=0;return{nextN:c,offset:u,isZero:d,isNeg:f,isNegF:p,offsetF:l}}var Ze=new WeakMap,Qe=new WeakMap;function $e(e){return Qe.get(e)||1}function et(e){if(e!==We)throw Error(`invalid wNAF`)}var tt=class{BASE;ZERO;Fn;bits;constructor(e,t){this.BASE=e.BASE,this.ZERO=e.ZERO,this.Fn=e.Fn,this.bits=t}_unsafeLadder(e,t,n=this.ZERO){let r=e;for(;t>We;)t&Ge&&(n=n.add(r)),r=r.double(),t>>=Ge;return n}precomputeWindow(e,t){let{windows:n,windowSize:r}=Ye(t,this.bits),i=[],a=e,o=a;for(let e=0;e<n;e++){o=a,i.push(o);for(let e=1;e<r;e++)o=o.add(a),i.push(o);a=o.double()}return i}wNAF(e,t,n){if(!this.Fn.isValid(n))throw Error(`invalid scalar`);let r=this.ZERO,i=this.BASE,a=Ye(e,this.bits);for(let e=0;e<a.windows;e++){let{nextN:o,offset:s,isZero:c,isNeg:l,isNegF:u,offsetF:d}=Xe(n,e,a);n=o,c?i=i.add(Ke(u,t[d])):r=r.add(Ke(l,t[s]))}return et(n),{p:r,f:i}}wNAFUnsafe(e,t,n,r=this.ZERO){let i=Ye(e,this.bits);for(let e=0;e<i.windows&&n!==We;e++){let{nextN:a,offset:o,isZero:s,isNeg:c}=Xe(n,e,i);if(n=a,!s){let e=t[o];r=r.add(c?e.negate():e)}}return et(n),r}
1getPrecomputes(e,t,n){let r=Ze.get(t);return r||(r=this.precomputeWindow(t,e),e!==1&&(typeof n==`function`&&(r=n(r)),Ze.set(t,r))),r}cached(e,t,n){let r=$e(e);return this.wNAF(r,this.getPrecomputes(r,e,n),t)}unsafe(e,t,n,r){let i=$e(e);return i===1?this._unsafeLadder(e,t,r):this.wNAFUnsafe(i,this.getPrecomputes(i,e,n),t,r)}createCache(e,t){Je(t,this.bits),Qe.set(e,t),Ze.delete(e)}hasCache(e){return $e(e)!==1}};function nt(e,t,n,r){let i=t,a=e.ZERO,o=e.ZERO;for(;n>We||r>We;)n&Ge&&(a=a.add(i)),r&Ge&&(o=o.add(i)),i=i.double(),n>>=Ge,r>>=Ge;return{p1:a,p2:o}}function rt(e,t,n){if(t){if(t.ORDER!==e)throw Error(`Field.ORDER must match order: Fp == p, Fn == n`);return Pe(t),t}else return Be(e,{isLE:n})}function it(e,t,n={},r){if(r===void 0&&(r=e===`edwards`),!t||typeof t!=`object`)throw Error(`expected valid ${e} CURVE object`);for(let e of[`p`,`n`,`h`]){let n=t[e];if(!(typeof n==`bigint`&&n>We))throw Error(`CURVE.${e} must be positive bigint`)}let i=rt(t.p,n.Fp,r),a=rt(t.n,n.Fn,r),o=[`Gx`,`Gy`,`a`,e===`weierstrass`?`b`:`d`];for(let e of o)if(!i.isValid(t[e]))throw Error(`CURVE.${e} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:i,Fn:a}}function at(e,t){return function(n){let r=e(n);return{secretKey:r,publicKey:t(r)}}}var ot=class{oHash;iHash;blockLen;outputLen;finished=!1;destroyed=!1;constructor(e,t){if(o(e),a(t,void 0,`key`),this.iHash=e.create(),typeof this.iHash.update!=`function`)throw Error(`Expected instance of class which extends utils.Hash`);this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,r=new Uint8Array(n);r.set(t.length>n?e.create().update(t).digest():t);for(let e=0;e<r.length;e++)r[e]^=54;this.iHash.update(r),this.oHash=e.create();for(let e=0;e<r.length;e++)r[e]^=106;this.oHash.update(r),l(r)}update(e){return s(this),this.iHash.update(e),this}digestInto(e){s(this),a(e,this.outputLen,`output`),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||=Object.create(Object.getPrototypeOf(this),{});let{oHash:t,iHash:n,finished:r,destroyed:i,blockLen:a,outputLen:o}=this;return e=e,e.finished=r,e.destroyed=i,e.blockLen=a,e.outputLen=o,e.oHash=t._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},st=(e,t,n)=>new ot(e,t).update(n).digest();st.create=(e,t)=>new ot(e,t);var ct=(e,t)=>(e+(e>=0?t:-t)/ht)/t;function lt(e,t,n){let[[r,i],[a,o]]=t,s=ct(o*e,n),c=ct(-i*e,n),l=e-s*r-c*a,u=-s*i-c*o,d=l<pt,f=u<pt;d&&(l=-l),f&&(u=-u);let p=ue(Math.ceil(le(n)/2))+mt;if(l<pt||l>=p||u<pt||u>=p)throw Error(`splitScalar (endomorphism): failed, k=`+e);return{k1neg:d,k1:l,k2neg:f,k2:u}}function ut(e){if(![`compact`,`recovered`,`der`].includes(e))throw Error(`Signature format must be "compact", "recovered", or "der"`);return e}function dt(e,t){let n={};for(let r of Object.keys(t))n[r]=e[r]===void 0?t[r]:e[r];return j(n.lowS,`lowS`),j(n.prehash,`prehash`),n.format!==void 0&&ut(n.format),n}var ft={Err:class extends Error{constructor(e=``){super(e)}},_tlv:{encode:(e,t)=>{let{Err:n}=ft;if(e<0||e>256)throw new n(`tlv.encode: wrong tag`);if(t.length&1)throw new n(`tlv.encode: unpadded data`);let r=t.length/2,i=N(r);if(i.length/2&128)throw new n(`tlv.encode: long form length too big`);let a=r>127?N(i.length/2|128):``;return N(e)+a+i+t},decode(e,t){let{Err:n}=ft,r=0;if(e<0||e>256)throw new n(`tlv.encode: wrong tag`);if(t.length<2||t[r++]!==e)throw new n(`tlv.decode: wrong tlv`);let i=t[r++],a=!!(i&128),o=0;if(!a)o=i;else{let e=i&127;if(!e)throw new n(`tlv.decode(long): indefinite length not supported`);if(e>4)throw new n(`tlv.decode(long): byte length is too big`);let a=t.subarray(r,r+e);if(a.length!==e)throw new n(`tlv.decode: length bytes not complete`);if(a[0]===0)throw new n(`tlv.decode(long): zero leftmost byte`);for(let e of a)o=o<<8|e;if(r+=e,o<128)throw new n(`tlv.decode(long): not minimal encoding`)}let s=t.subarray(r,r+o);if(s.length!==o)throw new n(`tlv.decode: wrong value length`);return{v:s,l:t.subarray(r+o)}}},_int:{encode(e){let{Err:t}=ft;if(e<pt)throw new t(`integer: negative integers are not allowed`);let n=N(e);if(Number.parseInt(n[0],16)&8&&(n=`00`+n),n.length&1)throw new t(`unexpected DER parsing assertion: unpadded hex`);return n},decode(e){let{Err:t}=ft;if(e[0]&128)throw new t(`invalid signature integer: negative`);if(e[0]===0&&!(e[1]&128))throw new t(`invalid signature integer: unnecessary leading zero`);return F(e)}},toSig(e){let{Err:t,_int:n,_tlv:r}=ft,i=a(e,void 0,`signature`),{v:o,l:s}=r.decode(48,i);if(s.length)throw new t(`invalid signature: left bytes after parsing`);let{v:c,l}=r.decode(2,o),{v:u,l:d}=r.decode(2,l);if(d.length)throw new t(`invalid signature: left bytes after parsing`);return{r:n.decode(c),s:n.decode(u)}},hexFromSig(e){let{_tlv:t,_int:n}=ft,r=t.encode(2,n.encode(e.r))+t.encode(2,n.encode(e.s));return t.encode(48,r)}},pt=BigInt(0),mt=BigInt(1),ht=BigInt(2),gt=BigInt(3),_t=BigInt(4);function vt(e,t={}){let n=it(`weierstrass`,e,t),{Fp:r,Fn:i}=n,o=n.CURVE,{h:s,n:c}=o;fe(t,{},{allowInfinityPoint:`boolean`,clearCofactor:`function`,isTorsionFree:`function`,fromBytes:`function`,toBytes:`function`,endo:`object`});let{endo:l}=t;if(l&&(!r.is0(o.a)||typeof l.beta!=`bigint`||!Array.isArray(l.basises)))throw Error(`invalid endo: expected "beta": bigint and "basises": array`);let u=bt(r,i);function d(){if(!r.isOdd)throw Error(`compression is not supported: Field does not have .isOdd()`)}function f(e,t,n){let{x:i,y:a}=t.toAffine(),o=r.toBytes(i);return j(n,`isCompressed`),n?(d(),v(yt(!r.isOdd(a)),o)):v(Uint8Array.of(4),o,r.toBytes(a))}function p(e){a(e,void 0,`Point`);let{publicKey:t,publicKeyUncompressed:n}=u,i=e.length,o=e[0],s=e.subarray(1);if(i===t&&(o===2||o===3)){let e=r.fromBytes(s);if(!r.isValid(e))throw Error(`bad point: is not on curve, wrong x`);let t=y(e),n;try{n=r.sqrt(t)}catch(e){let t=e instanceof Error?`: `+e.message:``;throw Error(`bad point: is not on curve, sqrt error`+t)}d();let i=r.isOdd(n);return(o&1)==1!==i&&(n=r.neg(n)),{x:e,y:n}}else if(i===n&&o===4){let e=r.BYTES,t=r.fromBytes(s.subarray(0,e)),n=r.fromBytes(s.subarray(e,e*2));if(!ee(t,n))throw Error(`bad point: is not on curve`);return{x:t,y:n}}else throw Error(`bad point: got length ${i}, expected compressed=${t} or uncompressed=${n}`)}let h=t.toBytes||f,g=t.fromBytes||p;function y(e){let t=r.sqr(e),n=r.mul(t,e);return r.add(r.add(n,r.mul(e,o.a)),o.b)}function ee(e,t){let n=r.sqr(t),i=y(e);return r.eql(n,i)}if(!ee(o.Gx,o.Gy))throw Error(`bad curve params: generator point`);let te=r.mul(r.pow(o.a,gt),_t),b=r.mul(r.sqr(o.b),BigInt(27));if(r.is0(r.add(te,b)))throw Error(`bad curve params: a or b`);function x(e,t,n=!1){if(!r.isValid(t)||n&&r.is0(t))throw Error(`bad point coordinate ${e}`);return t}function S(e){if(!(e instanceof D))throw Error(`Weierstrass Point expected`)}function C(e){if(!l||!l.basises)throw Error(`no endo`);return lt(e,l.basises,i.ORDER)}let w=pe((e,t)=>
1{let{X:n,Y:i,Z:a}=e;if(r.eql(a,r.ONE))return{x:n,y:i};let o=e.is0();t??=o?r.ONE:r.inv(a);let s=r.mul(n,t),c=r.mul(i,t),l=r.mul(a,t);if(o)return{x:r.ZERO,y:r.ZERO};if(!r.eql(l,r.ONE))throw Error(`invZ was invalid`);return{x:s,y:c}}),T=pe(e=>{if(e.is0()){if(t.allowInfinityPoint&&!r.is0(e.Y))return;throw Error(`bad point: ZERO`)}let{x:n,y:i}=e.toAffine();if(!r.isValid(n)||!r.isValid(i))throw Error(`bad point: x or y not field elements`);if(!ee(n,i))throw Error(`bad point: equation left != right`);if(!e.isTorsionFree())throw Error(`bad point: not in prime-order subgroup`);return!0});function E(e,t,n,i,a){return n=new D(r.mul(n.X,e),n.Y,n.Z),t=Ke(i,t),n=Ke(a,n),t.add(n)}class D{static BASE=new D(o.Gx,o.Gy,r.ONE);static ZERO=new D(r.ZERO,r.ONE,r.ZERO);static Fp=r;static Fn=i;X;Y;Z;constructor(e,t,n){this.X=x(`x`,e),this.Y=x(`y`,t,!0),this.Z=x(`z`,n),Object.freeze(this)}static CURVE(){return o}static fromAffine(e){let{x:t,y:n}=e||{};if(!e||!r.isValid(t)||!r.isValid(n))throw Error(`invalid affine point`);if(e instanceof D)throw Error(`projective point not allowed`);return r.is0(t)&&r.is0(n)?D.ZERO:new D(t,n,r.ONE)}static fromBytes(e){let t=D.fromAffine(g(a(e,void 0,`point`)));return t.assertValidity(),t}static fromHex(e){return D.fromBytes(_(e))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(e=8,t=!0){return k.createCache(this,e),t||this.multiply(gt),this}assertValidity(){T(this)}hasEvenY(){let{y:e}=this.toAffine();if(!r.isOdd)throw Error(`Field doesn't support isOdd`);return!r.isOdd(e)}equals(e){S(e);let{X:t,Y:n,Z:i}=this,{X:a,Y:o,Z:s}=e,c=r.eql(r.mul(t,s),r.mul(a,i)),l=r.eql(r.mul(n,s),r.mul(o,i));return c&&l}negate(){return new D(this.X,r.neg(this.Y),this.Z)}double(){let{a:e,b:t}=o,n=r.mul(t,gt),{X:i,Y:a,Z:s}=this,c=r.ZERO,l=r.ZERO,u=r.ZERO,d=r.mul(i,i),f=r.mul(a,a),p=r.mul(s,s),m=r.mul(i,a);return m=r.add(m,m),u=r.mul(i,s),u=r.add(u,u),c=r.mul(e,u),l=r.mul(n,p),l=r.add(c,l),c=r.sub(f,l),l=r.add(f,l),l=r.mul(c,l),c=r.mul(m,c),u=r.mul(n,u),p=r.mul(e,p),m=r.sub(d,p),m=r.mul(e,m),m=r.add(m,u),u=r.add(d,d),d=r.add(u,d),d=r.add(d,p),d=r.mul(d,m),l=r.add(l,d),p=r.mul(a,s),p=r.add(p,p),d=r.mul(p,m),c=r.sub(c,d),u=r.mul(p,f),u=r.add(u,u),u=r.add(u,u),new D(c,l,u)}add(e){S(e);let{X:t,Y:n,Z:i}=this,{X:a,Y:s,Z:c}=e,l=r.ZERO,u=r.ZERO,d=r.ZERO,f=o.a,p=r.mul(o.b,gt),m=r.mul(t,a),h=r.mul(n,s),g=r.mul(i,c),_=r.add(t,n),v=r.add(a,s);_=r.mul(_,v),v=r.add(m,h),_=r.sub(_,v),v=r.add(t,i);let y=r.add(a,c);return v=r.mul(v,y),y=r.add(m,g),v=r.sub(v,y),y=r.add(n,i),l=r.add(s,c),y=r.mul(y,l),l=r.add(h,g),y=r.sub(y,l),d=r.mul(f,v),l=r.mul(p,g),d=r.add(l,d),l=r.sub(h,d),d=r.add(h,d),u=r.mul(l,d),h=r.add(m,m),h=r.add(h,m),g=r.mul(f,g),v=r.mul(p,v),h=r.add(h,g),g=r.sub(m,g),g=r.mul(f,g),v=r.add(v,g),m=r.mul(h,v),u=r.add(u,m),m=r.mul(y,v),l=r.mul(_,l),l=r.sub(l,m),m=r.mul(_,h),d=r.mul(y,d),d=r.add(d,m),new D(l,u,d)}subtract(e){return this.add(e.negate())}is0(){return this.equals(D.ZERO)}multiply(e){let{endo:n}=t;if(!i.isValidNot0(e))throw Error(`invalid scalar: out of range`);let r,a,o=e=>k.cached(this,e,e=>qe(D,e));if(n){let{k1neg:t,k1:i,k2neg:s,k2:c}=C(e),{p:l,f:u}=o(i),{p:d,f}=o(c);a=u.add(f),r=E(n.beta,l,d,t,s)}else{let{p:t,f:n}=o(e);r=t,a=n}return qe(D,[r,a])[0]}multiplyUnsafe(e){let{endo:n}=t,r=this;if(!i.isValid(e))throw Error(`invalid scalar: out of range`);if(e===pt||r.is0())return D.ZERO;if(e===mt)return r;if(k.hasCache(this))return this.multiply(e);if(n){let{k1neg:t,k1:i,k2neg:a,k2:o}=C(e),{p1:s,p2:c}=nt(D,r,i,o);return E(n.beta,s,c,t,a)}else return k.unsafe(r,e)}toAffine(e){return w(this,e)}isTorsionFree(){let{isTorsionFree:e}=t;return s===mt?!0:e?e(D,this):k.unsafe(this,c).is0()}clearCofactor(){let{clearCofactor:e}=t;return s===mt?this:e?e(D,this):this.multiplyUnsafe(s)}isSmallOrder(){return this.multiplyUnsafe(s).is0()}toBytes(e=!0){return j(e,`isCompressed`),this.assertValidity(),h(D,this,e)}toHex(e=!0){return m(this.toBytes(e))}toString(){return`<Point ${this.is0()?`ZERO`:this.toHex()}>`}}let O=i.BITS,k=new tt(D,t.endo?Math.ceil(O/2):O);return D.BASE.precompute(8),D}function yt(e){return Uint8Array.of(e?2:3)}function bt(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function xt(e,t={}){let{Fn:n}=e,i=t.randomBytes||ee,o=Object.assign(bt(e.Fp,n),{seed:He(n.ORDER)});function s(e){try{let t=n.fromBytes(e);return n.isValidNot0(t)}catch{return!1}}function c(t,n){let{publicKey:r,publicKeyUncompressed:i}=o;try{let a=t.length;return n===!0&&a!==r||n===!1&&a!==i?!1:!!e.fromBytes(t)}catch{return!1}}function l(e=i(o.seed)){return Ue(a(e,o.seed,`seed`),n.ORDER)}function u(t,r=!0){return e.BASE.multiply(n.fromBytes(t)).toBytes(r)}function d(e){let{secretKey:t,publicKey:i,publicKeyUncompressed:s}=o;if(!r(e)||`_lengths`in n&&n._lengths||t===i)return;let c=a(e,void 0,`key`).length;return c===i||c===s}function f(t,r,i=!0){if(d(t)===!0)throw Error(`first arg must be private key`);if(d(r)===!1)throw Error(`second arg must be public key`);let a=n.fromBytes(t);return e.fromBytes(r).multiply(a).toBytes(i)}let p={isValidSecretKey:s,isValidPublicKey:c,randomSecretKey:l},m=at(l,u);return Object.freeze({getPublicKey:u,getSharedSecret:f,keygen:m,Point:e,utils:p,lengths:o})}function St(e,t,n={}){o(t),fe(n,{},{hmac:`function`,lowS:`boolean`,randomBytes:`function`,bits2int:`function`,bits2int_modN:`function`}),n=Object.assign({},n);let i=n.randomBytes||ee,s=n.hmac||((e,n)=>st(t,e,n)),{Fp:c,Fn:l}=e,{ORDER:u,BITS:d}=l,{keygen:f,getPublicKey:p,getSharedSecret:h,utils:g,lengths:y}=xt(e,n),te={prehash:!0,lowS:typeof n.lowS==`boolean`?n.lowS:!0,format:`compact`,extraEntropy:!1},b=u*ht<c.ORDER;function x(e){return e>u>>mt}function S(e,t){if(!l.isValidNot0(t))throw Error(`invalid signature ${e}: out of range 1..Point.Fn.ORDER`);return t}function C(){if(b)throw Error(`"recovered" sig type is not supported for cofactor >2 curves`)}function w(e,t){ut(t);let n=y.signature;return a(e,t===`compact`?n:t===`recovered`?n+1:void 0)}class T{r;s;recovery;constructor(e,t,n){if(this.r=S(`r`,e),this.s=S(`s`,t),n!=null){if(C(),![0,1,2,3].includes(n))throw Error(`invalid recovery id`);this.recovery=n}Object.freeze(this)}static fromBytes(e,t=te.format){w(e,t);let n;
1if(t===`der`){let{r:t,s:n}=ft.toSig(a(e));return new T(t,n)}t===`recovered`&&(n=e[0],t=`compact`,e=e.subarray(1));let r=y.signature/2,i=e.subarray(0,r),o=e.subarray(r,r*2);return new T(l.fromBytes(i),l.fromBytes(o),n)}static fromHex(e,t){return this.fromBytes(_(e),t)}assertRecovery(){let{recovery:e}=this;if(e==null)throw Error(`invalid recovery id: must be present`);return e}addRecoveryBit(e){return new T(this.r,this.s,e)}recoverPublicKey(t){let{r:n,s:r}=this,i=this.assertRecovery(),o=i===2||i===3?n+u:n;if(!c.isValid(o))throw Error(`invalid recovery id: sig.r+curve.n != R.x`);let s=c.toBytes(o),d=e.fromBytes(v(yt((i&1)==0),s)),f=l.inv(o),p=D(a(t,void 0,`msgHash`)),m=l.create(-p*f),h=l.create(r*f),g=e.BASE.multiplyUnsafe(m).add(d.multiplyUnsafe(h));if(g.is0())throw Error(`invalid recovery: point at infinify`);return g.assertValidity(),g}hasHighS(){return x(this.s)}toBytes(e=te.format){if(ut(e),e===`der`)return _(ft.hexFromSig(this));let{r:t,s:n}=this,r=l.toBytes(t),i=l.toBytes(n);return e===`recovered`?(C(),v(Uint8Array.of(this.assertRecovery()),r,i)):v(r,i)}toHex(e){return m(this.toBytes(e))}}let E=n.bits2int||function(e){if(e.length>8192)throw Error(`input is too large`);let t=F(e),n=e.length*8-d;return n>0?t>>BigInt(n):t},D=n.bits2int_modN||function(e){return l.create(E(e))},O=ue(d);function k(e){return ce(`num < 2^`+d,e,pt,O),l.toBytes(e)}function A(e,n){return a(e,void 0,`message`),n?a(t(e),void 0,`prehashed message`):e}function j(t,n,r){let{lowS:o,prehash:s,extraEntropy:c}=dt(r,te);t=A(t,s);let u=D(t),d=l.fromBytes(n);if(!l.isValidNot0(d))throw Error(`invalid private key`);let f=[k(d),k(u)];if(c!=null&&c!==!1){let e=c===!0?i(y.secretKey):c;f.push(a(e,void 0,`extraEntropy`))}let p=v(...f),m=u;function h(t){let n=E(t);if(!l.isValidNot0(n))return;let r=l.inv(n),i=e.BASE.multiply(n).toAffine(),a=l.create(i.x);if(a===pt)return;let s=l.create(r*l.create(m+a*d));if(s===pt)return;let c=(i.x===a?0:2)|Number(i.y&mt),u=s;return o&&x(s)&&(u=l.neg(s),c^=1),new T(a,u,b?void 0:c)}return{seed:p,k2sig:h}}function M(e,n,r={}){let{seed:i,k2sig:a}=j(e,n,r);return de(t.outputLen,l.BYTES,s)(i,a).toBytes(r.format)}function N(t,n,i,o={}){let{lowS:s,prehash:c,format:u}=dt(o,te);if(i=a(i,void 0,`publicKey`),n=A(n,c),!r(t)){let e=t instanceof T?`, use sig.toBytes()`:``;throw Error(`verify expects Uint8Array signature`+e)}w(t,u);try{let r=T.fromBytes(t,u),a=e.fromBytes(i);if(s&&r.hasHighS())return!1;let{r:o,s:c}=r,d=D(n),f=l.inv(c),p=l.create(d*f),m=l.create(o*f),h=e.BASE.multiplyUnsafe(p).add(a.multiplyUnsafe(m));return h.is0()?!1:l.create(h.x)===o}catch{return!1}}function P(e,t,n={}){let{prehash:r}=dt(n,te);return t=A(t,r),T.fromBytes(e,`recovered`).recoverPublicKey(t).toBytes()}return Object.freeze({keygen:f,getPublicKey:p,getSharedSecret:h,utils:g,lengths:y,Point:e,sign:M,verify:N,recoverPublicKey:P,Signature:T,hash:t})}var Ct={p:BigInt(`0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f`),n:BigInt(`0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141`),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt(`0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798`),Gy:BigInt(`0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8`)},wt={beta:BigInt(`0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee`),basises:[[BigInt(`0x3086d221a7d46bcde86c90e49284eb15`),-BigInt(`0xe4437ed6010e88286f547fa90abfe4c3`)],[BigInt(`0x114ca50f7a8e2f3f657c1108d9d44cfd8`),BigInt(`0x3086d221a7d46bcde86c90e49284eb15`)]]},Tt=BigInt(0),Et=BigInt(2);function Dt(e){let t=Ct.p,n=BigInt(3),r=BigInt(6),i=BigInt(11),a=BigInt(22),o=BigInt(23),s=BigInt(44),c=BigInt(88),l=e*e*e%t,u=l*l*e%t,d=Te(Te(Te(u,n,t)*u%t,n,t)*u%t,Et,t)*l%t,f=Te(d,i,t)*d%t,p=Te(f,a,t)*f%t,m=Te(p,s,t)*p%t,h=Te(Te(Te(Te(Te(Te(m,c,t)*m%t,s,t)*p%t,n,t)*u%t,o,t)*f%t,r,t)*l%t,Et,t);if(!Ot.eql(Ot.sqr(h),e))throw Error(`Cannot find square root`);return h}var Ot=Be(Ct.p,{sqrt:Dt}),kt=vt(Ct,{Fp:Ot,endo:wt}),At=St(kt,O),jt={};function Mt(e,...t){let n=jt[e];if(n===void 0){let t=O(ae(e));n=v(t,t),jt[e]=n}return O(v(n,...t))}var Nt=e=>e.toBytes(!0).slice(1),Pt=e=>e%Et===Tt;function Ft(e){let{Fn:t,BASE:n}=kt,r=t.fromBytes(e),i=n.multiply(r);return{scalar:Pt(i.y)?r:t.neg(r),bytes:Nt(i)}}function It(e){let t=Ot;if(!t.isValidNot0(e))throw Error(`invalid x: Fail if x ≥ p`);let n=t.create(e*e),r=t.create(n*e+BigInt(7)),i=t.sqrt(r);Pt(i)||(i=t.neg(i));let a=kt.fromAffine({x:e,y:i});return a.assertValidity(),a}var Lt=F;function Rt(...e){return kt.Fn.create(Lt(Mt(`BIP0340/challenge`,...e)))}function zt(e){return Ft(e).bytes}function Bt(e,t,n=ee(32)){let{Fn:r}=kt,i=a(e,void 0,`message`),{bytes:o,scalar:s}
1=Ft(t),c=a(n,32,`auxRand`),{bytes:l,scalar:u}=Ft(Mt(`BIP0340/nonce`,r.toBytes(s^Lt(Mt(`BIP0340/aux`,c))),o,i)),d=Rt(l,o,i),f=new Uint8Array(64);if(f.set(l,0),f.set(r.toBytes(r.create(u+d*s)),32),!Vt(f,i,o))throw Error(`sign: Invalid signature produced`);return f}function Vt(e,t,n){let{Fp:r,Fn:i,BASE:o}=kt,s=a(e,64,`signature`),c=a(t,void 0,`message`),l=a(n,32,`publicKey`);try{let e=It(Lt(l)),t=Lt(s.subarray(0,32));if(!r.isValidNot0(t))return!1;let n=Lt(s.subarray(32,64));if(!i.isValidNot0(n))return!1;let a=Rt(i.toBytes(t),Nt(e),c),u=o.multiplyUnsafe(n).add(e.multiplyUnsafe(i.neg(a))),{x:d,y:f}=u.toAffine();return!(u.is0()||!Pt(f)||d!==t)}catch{return!1}}var Ht=(()=>{let e=(e=ee(48))=>Ue(e,Ct.n);return{keygen:at(e,zt),getPublicKey:zt,sign:Bt,verify:Vt,Point:kt,utils:{randomSecretKey:e,taggedHash:Mt,lift_x:It,pointToBytes:Nt},lengths:{secretKey:32,publicKey:32,publicKeyHasPrefix:!1,signature:64,seed:48}}})();function Ut(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name===`Uint8Array`}function Wt(e,t=``){if(!Number.isSafeInteger(e)||e<0){let n=t&&`"${t}" `;throw Error(`${n}expected integer >= 0, got ${e}`)}}function Gt(e,t,n=``){let r=Ut(e),i=e?.length,a=t!==void 0;if(!r||a&&i!==t){let o=n&&`"${n}" `,s=a?` of length ${t}`:``,c=r?`length=${i}`:`type=${typeof e}`;throw Error(o+`expected Uint8Array`+s+`, got `+c)}return e}function Kt(e){if(typeof e!=`function`||typeof e.create!=`function`)throw Error(`Hash must wrapped by utils.createHasher`);Wt(e.outputLen),Wt(e.blockLen)}function qt(e,t=!0){if(e.destroyed)throw Error(`Hash instance has been destroyed`);if(t&&e.finished)throw Error(`Hash#digest() has already been called`)}function Jt(e,t){Gt(e,void 0,`digestInto() output`);let n=t.outputLen;if(e.length<n)throw Error(`"digestInto() output" expected to be of length >=`+n)}function Yt(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function Xt(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function Zt(e,t){return e<<32-t|e>>>t}var Qt=typeof Uint8Array.from([]).toHex==`function`&&typeof Uint8Array.fromHex==`function`,$t=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,`0`));function L(e){if(Gt(e),Qt)return e.toHex();let t=``;for(let n=0;n<e.length;n++)t+=$t[e[n]];return t}var en={_0:48,_9:57,A:65,F:70,a:97,f:102};function tn(e){if(e>=en._0&&e<=en._9)return e-en._0;if(e>=en.A&&e<=en.F)return e-(en.A-10);if(e>=en.a&&e<=en.f)return e-(en.a-10)}function R(e){if(typeof e!=`string`)throw Error(`hex string expected, got `+typeof e);if(Qt)return Uint8Array.fromHex(e);let t=e.length,n=t/2;if(t%2)throw Error(`hex string expected, got unpadded hex of length `+t);let r=new Uint8Array(n);for(let t=0,i=0;t<n;t++,i+=2){let n=tn(e.charCodeAt(i)),a=tn(e.charCodeAt(i+1));if(n===void 0||a===void 0){let t=e[i]+e[i+1];throw Error(`hex string expected, got non-hex character "`+t+`" at index `+i)}r[t]=n*16+a}return r}function nn(...e){let t=0;for(let n=0;n<e.length;n++){let r=e[n];Gt(r),t+=r.length}let n=new Uint8Array(t);for(let t=0,r=0;t<e.length;t++){let i=e[t];n.set(i,r),r+=i.length}return n}function rn(e,t={}){let n=(t,n)=>e(n).update(t).digest(),r=e(void 0);return n.outputLen=r.outputLen,n.blockLen=r.blockLen,n.create=t=>e(t),Object.assign(n,t),Object.freeze(n)}function an(e=32){let t=typeof globalThis==`object`?globalThis.crypto:null;if(typeof t?.getRandomValues!=`function`)throw Error(`crypto.getRandomValues must be defined`);return t.getRandomValues(new Uint8Array(e))}var on=e=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,e])});function sn(e,t,n){return e&t^~e&n}function cn(e,t,n){return e&t^e&n^t&n}var ln=class{blockLen;outputLen;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(e,t,n,r){this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=r,this.buffer=new Uint8Array(e),this.view=Xt(this.buffer)}update(e){qt(this),Gt(e);let{view:t,buffer:n,blockLen:r}=this,i=e.length;for(let a=0;a<i;){let o=Math.min(r-this.pos,i-a);if(o===r){let t=Xt(e);for(;r<=i-a;a+=r)this.process(t,a);continue}n.set(e.subarray(a,a+o),this.pos),this.pos+=o,a+=o,this.pos===r&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){qt(this),Jt(e,this),this.finished=!0;let{buffer:t,view:n,blockLen:r,isLE:i}=this,{pos:a}=this;t[a++]=128,Yt(this.buffer.subarray(a)),this.padOffset>r-a&&(this.process(n,0),a=0);for(let e=a;
1e<r;e++)t[e]=0;n.setBigUint64(r-8,BigInt(this.length*8),i),this.process(n,0);let o=Xt(e),s=this.outputLen;if(s%4)throw Error(`_sha2: outputLen must be aligned to 32bit`);let c=s/4,l=this.get();if(c>l.length)throw Error(`_sha2: outputLen bigger than state`);for(let e=0;e<c;e++)o.setUint32(4*e,l[e],i)}digest(){let{buffer:e,outputLen:t}=this;this.digestInto(e);let n=e.slice(0,t);return this.destroy(),n}_cloneInto(e){e||=new this.constructor,e.set(...this.get());let{blockLen:t,buffer:n,length:r,finished:i,destroyed:a,pos:o}=this;return e.destroyed=a,e.finished=i,e.length=r,e.pos=o,r%t&&e.buffer.set(n),e}clone(){return this._cloneInto()}},un=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),dn=Uint32Array.from([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]),fn=new Uint32Array(64),pn=class extends ln{constructor(e){super(64,e,8,!1)}get(){let{A:e,B:t,C:n,D:r,E:i,F:a,G:o,H:s}=this;return[e,t,n,r,i,a,o,s]}set(e,t,n,r,i,a,o,s){this.A=e|0,this.B=t|0,this.C=n|0,this.D=r|0,this.E=i|0,this.F=a|0,this.G=o|0,this.H=s|0}process(e,t){for(let n=0;n<16;n++,t+=4)fn[n]=e.getUint32(t,!1);for(let e=16;e<64;e++){let t=fn[e-15],n=fn[e-2],r=Zt(t,7)^Zt(t,18)^t>>>3;fn[e]=(Zt(n,17)^Zt(n,19)^n>>>10)+fn[e-7]+r+fn[e-16]|0}let{A:n,B:r,C:i,D:a,E:o,F:s,G:c,H:l}=this;for(let e=0;e<64;e++){let t=Zt(o,6)^Zt(o,11)^Zt(o,25),u=l+t+sn(o,s,c)+dn[e]+fn[e]|0,d=(Zt(n,2)^Zt(n,13)^Zt(n,22))+cn(n,r,i)|0;l=c,c=s,s=o,o=a+u|0,a=i,i=r,r=n,n=u+d|0}n=n+this.A|0,r=r+this.B|0,i=i+this.C|0,a=a+this.D|0,o=o+this.E|0,s=s+this.F|0,c=c+this.G|0,l=l+this.H|0,this.set(n,r,i,a,o,s,c,l)}roundClean(){Yt(fn)}destroy(){this.set(0,0,0,0,0,0,0,0),Yt(this.buffer)}},mn=class extends pn{A=un[0]|0;B=un[1]|0;C=un[2]|0;D=un[3]|0;E=un[4]|0;F=un[5]|0;G=un[6]|0;H=un[7]|0;constructor(){super(32)}},hn=rn(()=>new mn,on(1));function gn(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name===`Uint8Array`}function _n(e){if(!gn(e))throw Error(`Uint8Array expected`)}function vn(e,t){return Array.isArray(t)?t.length===0?!0:e?t.every(e=>typeof e==`string`):t.every(e=>Number.isSafeInteger(e)):!1}function yn(e){if(typeof e!=`function`)throw Error(`function expected`);return!0}function bn(e,t){if(typeof t!=`string`)throw Error(`${e}: string expected`);return!0}function xn(e){if(!Number.isSafeInteger(e))throw Error(`invalid integer: ${e}`)}function Sn(e){if(!Array.isArray(e))throw Error(`array expected`)}
1function Cn(e,t){if(!vn(!0,t))throw Error(`${e}: array of strings expected`)}function wn(e,t){if(!vn(!1,t))throw Error(`${e}: array of numbers expected`)}function Tn(...e){let t=e=>e,n=(e,t)=>n=>e(t(n));return{encode:e.map(e=>e.encode).reduceRight(n,t),decode:e.map(e=>e.decode).reduce(n,t)}}function En(e){let t=typeof e==`string`?e.split(``):e,n=t.length;Cn(`alphabet`,t);let r=new Map(t.map((e,t)=>[e,t]));return{encode:r=>(Sn(r),r.map(r=>{if(!Number.isSafeInteger(r)||r<0||r>=n)throw Error(`alphabet.encode: digit index outside alphabet "${r}". Allowed: ${e}`);return t[r]})),decode:t=>(Sn(t),t.map(t=>{bn(`alphabet.decode`,t);let n=r.get(t);if(n===void 0)throw Error(`Unknown letter: "${t}". Allowed: ${e}`);return n}))}}function Dn(e=``){return bn(`join`,e),{encode:t=>(Cn(`join.decode`,t),t.join(e)),decode:t=>(bn(`join.decode`,t),t.split(e))}}function On(e,t=`=`){return xn(e),bn(`padding`,t),{encode(n){for(Cn(`padding.encode`,n);n.length*e%8;)n.push(t);return n},decode(n){Cn(`padding.decode`,n);let r=n.length;if(r*e%8)throw Error(`padding: invalid, string should have whole number of bytes`);for(;r>0&&n[r-1]===t;r--)if((r-1)*e%8==0)throw Error(`padding: invalid, string has too much padding`);return n.slice(0,r)}}}function kn(e){return yn(e),{encode:e=>e,decode:t=>e(t)}}var An=(e,t)=>t===0?e:An(t,e%t),jn=(e,t)=>e+(t-An(e,t)),Mn=(()=>{let e=[];for(let t=0;t<40;t++)e.push(2**t);return e})();function Nn(e,t,n,r){if(Sn(e),t<=0||t>32)throw Error(`convertRadix2: wrong from=${t}`);if(n<=0||n>32)throw Error(`convertRadix2: wrong to=${n}`);if(jn(t,n)>32)throw Error(`convertRadix2: carry overflow from=${t} to=${n} carryBits=${jn(t,n)}`);let i=0,a=0,o=Mn[t],s=Mn[n]-1,c=[];for(let r of e){if(xn(r),r>=o)throw Error(`convertRadix2: invalid data word=${r} from=${t}`);if(i=i<<t|r,a+t>32)throw Error(`convertRadix2: carry overflow pos=${a} from=${t}`);for(a+=t;a>=n;a-=n)c.push((i>>a-n&s)>>>0);let e=Mn[a];if(e===void 0)throw Error(`invalid carry`);i&=e-1}if(i=i<<n-a&s,!r&&a>=t)throw Error(`Excess padding`);if(!r&&i>0)throw Error(`Non-zero padding: ${i}`);return r&&a>0&&c.push(i>>>0),c}function Pn(e,t=!1){if(xn(e),e<=0||e>32)throw Error(`radix2: bits should be in (0..32]`);if(jn(8,e)>32||jn(e,8)>32)throw Error(`radix2: carry overflow`);return{encode:n=>{if(!gn(n))throw Error(`radix2.encode input should be Uint8Array`);return Nn(Array.from(n),8,e,!t)},decode:n=>(wn(`radix2.decode`,n),Uint8Array.from(Nn(n,e,8,t)))}}function Fn(e){return yn(e),function(...t){try{return e.apply(null,t)}catch{}}}Tn(Pn(4),En(`0123456789ABCDEF`),Dn(``)),Tn(Pn(5),En(`ABCDEFGHIJKLMNOPQRSTUVWXYZ234567`),On(5),Dn(``)),Tn(Pn(5),En(`ABCDEFGHIJKLMNOPQRSTUVWXYZ234567`),Dn(``)),Tn(Pn(5),En(`0123456789ABCDEFGHIJKLMNOPQRSTUV`),On(5),Dn(``)),Tn(Pn(5),En(`0123456789ABCDEFGHIJKLMNOPQRSTUV`),Dn(``)),Tn(Pn(5),En(`0123456789ABCDEFGHJKMNPQRSTVWXYZ`),Dn(``),kn(e=>e.toUpperCase().replace(/O/g,`0`).replace(/[IL]/g,`1`)));var In=typeof Uint8Array.from([]).toBase64==`function`&&typeof Uint8Array.fromBase64==`function`,Ln=(e,t)=>
1{bn(`base64`,e);let n=t?/^[A-Za-z0-9=_-]+$/:/^[A-Za-z0-9=+/]+$/,r=t?`base64url`:`base64`;if(e.length>0&&!n.test(e))throw Error(`invalid base64`);return Uint8Array.fromBase64(e,{alphabet:r,lastChunkHandling:`strict`})},Rn=In?{encode(e){return _n(e),e.toBase64()},decode(e){return Ln(e,!1)}}:Tn(Pn(6),En(`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/`),On(6),Dn(``));Tn(Pn(6),En(`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/`),Dn(``)),In||Tn(Pn(6),En(`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_`),On(6),Dn(``)),Tn(Pn(6),En(`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_`),Dn(``));var zn=Tn(En(`qpzry9x8gf2tvdw0s3jn54khce6mua7l`),Dn(``)),Bn=[996825010,642813549,513874426,1027748829,705979059];function Vn(e){let t=e>>25,n=(e&33554431)<<5;for(let e=0;e<Bn.length;e++)(t>>e&1)==1&&(n^=Bn[e]);return n}function Hn(e,t,n=1){let r=e.length,i=1;for(let t=0;t<r;t++){let n=e.charCodeAt(t);if(n<33||n>126)throw Error(`Invalid prefix (${e})`);i=Vn(i)^n>>5}i=Vn(i);for(let t=0;t<r;t++)i=Vn(i)^e.charCodeAt(t)&31;for(let e of t)i=Vn(i)^e;for(let e=0;e<6;e++)i=Vn(i);return i^=n,zn.encode(Nn([i%Mn[30]],30,5,!1))}function Un(e){let t=e===`bech32`?1:734539939,n=Pn(5),r=n.decode,i=n.encode,a=Fn(r);function o(e,n,r=90){bn(`bech32.encode prefix`,e),gn(n)&&(n=Array.from(n)),wn(`bech32.encode`,n);let i=e.length;if(i===0)throw TypeError(`Invalid prefix length ${i}`);let a=i+7+n.length;if(r!==!1&&a>r)throw TypeError(`Length ${a} exceeds limit ${r}`);let o=e.toLowerCase(),s=Hn(o,n,t);return`${o}1${zn.encode(n)}${s}`}function s(e,n=90){bn(`bech32.decode input`,e);let r=e.length;if(r<8||n!==!1&&r>n)throw TypeError(`invalid string length: ${r} (${e}). Expected (8..${n})`);let i=e.toLowerCase();if(e!==i&&e!==e.toUpperCase())throw Error(`String must be lowercase or uppercase`);let a=i.lastIndexOf(`1`);if(a===0||a===-1)throw Error(`Letter "1" must be present between prefix and data only`);let o=i.slice(0,a),s=i.slice(a+1);if(s.length<6)throw Error(`Data must be at least 6 characters long`);let c=zn.decode(s).slice(0,-6),l=Hn(o,c,t);if(!s.endsWith(l))throw Error(`Invalid checksum in ${e}: expected "${l}"`);return{prefix:o,words:c}}let c=Fn(s);function l(e){let{prefix:t,words:n}=s(e,!1);return{prefix:t,words:n,bytes:r(n)}}function u(e,t){return o(e,i(t))}return{encode:o,decode:s,encodeFromBytes:u,decodeToBytes:l,decodeUnsafe:c,fromWords:r,fromWordsUnsafe:a,toWords:i}}var Wn=Un(`bech32`);Un(`bech32m`),typeof Uint8Array.from([]).toHex==`function`&&typeof Uint8Array.fromHex==`function`||Tn(Pn(4),En(`0123456789abcdef`),Dn(``),kn(e=>{if(typeof e!=`string`||e.length%2!=0)throw TypeError(`hex.decode: expected string, got ${typeof e} with length ${e.length}`);return e.toLowerCase()}));function Gn(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name===`Uint8Array`}function Kn(e){if(typeof e!=`boolean`)throw Error(`boolean expected, not ${e}`)}function qn(e){if(!Number.isSafeInteger(e)||e<0)throw Error(`positive integer expected, got `+e)}function z(e,t,n=``){let r=Gn(e),i=e?.length,a=t!==void 0;if(!r||a&&i!==t){let o=n&&`"${n}" `,s=a?` of length ${t}`:``,c=r?`length=${i}`:`type=${typeof e}`;throw Error(o+`expected Uint8Array`+s+`, got `+c)}return e}function Jn(e,t=!0){if(e.destroyed)throw Error(`Hash instance has been destroyed`);if(t&&e.finished)throw Error(`Hash#digest() has already been called`)}function Yn(e,t){z(e,void 0,`output`);let n=t.outputLen;if(e.length<n)throw Error(`digestInto() expects output buffer of length at least `+n)}function B(e){return new Uint32Array(e.buffer,e.byteOffset,Math.floor(e.byteLength/4))}function Xn(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}var Zn=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function Qn(e,t){return e.buffer===t.buffer&&e.byteOffset<t.byteOffset+t.byteLength&&t.byteOffset<e.byteOffset+e.byteLength}function $n(e,t){if(Qn(e,t)&&e.byteOffset<t.byteOffset)throw Error(`complex overlap of input and output is not supported`)}function er(e,t){if(typeof t!=`object`||!t)throw Error(`options must be defined`);return Object.assign(e,t)}function tr(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}var nr=(e,t)=>
1{function n(n,...r){if(z(n,void 0,`key`),!Zn)throw Error(`Non little-endian hardware is not yet supported`);if(e.nonceLength!==void 0){let t=r[0];z(t,e.varSizeNonce?void 0:e.nonceLength,`nonce`)}let i=e.tagLength;i&&r[1]!==void 0&&z(r[1],void 0,`AAD`);let a=t(n,...r),o=(e,t)=>{if(t!==void 0){if(e!==2)throw Error(`cipher output not supported`);z(t,void 0,`output`)}},s=!1;return{encrypt(e,t){if(s)throw Error(`cannot encrypt() twice with same key + nonce`);return s=!0,z(e),o(a.encrypt.length,t),a.encrypt(e,t)},decrypt(e,t){if(z(e),i&&e.length<i)throw Error(`"ciphertext" expected length bigger than tagLength=`+i);return o(a.decrypt.length,t),a.decrypt(e,t)}}}return Object.assign(n,e),n};function rr(e,t,n=!0){if(t===void 0)return new Uint8Array(e);if(t.length!==e)throw Error(`"output" expected Uint8Array of length `+e+`, got: `+t.length);if(n&&!ir(t))throw Error(`invalid output, must be aligned`);return t}function ir(e){return e.byteOffset%4==0}function ar(e){return Uint8Array.from(e)}var or=16,sr=283;function cr(e){if(![16,24,32].includes(e.length))throw Error(`"aes key" expected Uint8Array of length 16/24/32, got length=`+e.length)}function lr(e){return e<<1^sr&-(e>>7)}function ur(e,t){let n=0;for(;t>0;t>>=1)n^=e&-(t&1),e=lr(e);return n}var dr=(()=>{let e=new Uint8Array(256);for(let t=0,n=1;t<256;t++,n^=lr(n))e[t]=n;let 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 Xn(e),t})(),fr=dr.map((e,t)=>dr.indexOf(t)),pr=e=>e<<24|e>>>8,mr=e=>e<<8|e>>>24;function hr(e,t){if(e.length!==256)throw Error(`Wrong sbox length`);let n=new Uint32Array(256).map((n,r)=>t(e[r])),r=n.map(mr),i=r.map(mr),a=i.map(mr),o=new Uint32Array(256*256),s=new Uint32Array(256*256),c=new Uint16Array(256*256);for(let t=0;t<256;t++)for(let l=0;l<256;l++){let u=t*256+l;o[u]=n[t]^r[l],s[u]=i[t]^a[l],c[u]=e[t]<<8|e[l]}return{sbox:e,sbox2:c,T0:n,T1:r,T2:i,T3:a,T01:o,T23:s}}var gr=hr(dr,e=>ur(e,3)<<24|e<<16|e<<8|ur(e,2)),_r=hr(fr,e=>ur(e,11)<<24|ur(e,13)<<16|ur(e,9)<<8|ur(e,14)),vr=(()=>{let e=new Uint8Array(16);for(let t=0,n=1;t<16;t++,n=lr(n))e[t]=n;return e})();function yr(e){z(e);let t=e.length;cr(e);let{sbox2:n}=gr,r=[];ir(e)||r.push(e=ar(e));let i=B(e),a=i.length,o=e=>Sr(n,e,e,e,e),s=new Uint32Array(t+28);s.set(i);for(let e=a;e<s.length;e++){let t=s[e-1];e%a===0?t=o(pr(t))^vr[e/a-1]:a>6&&e%a===4&&(t=o(t)),s[e]=s[e-a]^t}return Xn(...r),s}function br(e){let t=yr(e),n=t.slice(),r=t.length,{sbox2:i}=gr,{T0:a,T1:o,T2:s,T3:c}=_r;for(let e=0;e<r;e+=4)for(let i=0;i<4;i++)n[e+i]=t[r-e-4+i];Xn(t);for(let e=4;e<r-4;e++){let t=n[e],r=Sr(i,t,t,t,t);n[e]=a[r&255]^o[r>>>8&255]^s[r>>>16&255]^c[r>>>24]}return n}function xr(e,t,n,r,i,a){return e[n<<8&65280|r>>>8&255]^t[i>>>8&65280|a>>>24&255]}function Sr(e,t,n,r,i){return e[t&255|n&65280]|e[r>>>16&255|i>>>16&65280]<<16}function Cr(e,t,n,r,i){let{sbox2:a,T01:o,T23:s}=gr,c=0;t^=e[c++],n^=e[c++],r^=e[c++],i^=e[c++];let l=e.length/4-2;for(let a=0;a<l;a++){let a=e[c++]^xr(o,s,t,n,r,i),l=e[c++]^xr(o,s,n,r,i,t),u=e[c++]^xr(o,s,r,i,t,n),d=e[c++]^xr(o,s,i,t,n,r);t=a,n=l,r=u,i=d}return{s0:e[c++]^Sr(a,t,n,r,i),s1:e[c++]^Sr(a,n,r,i,t),s2:e[c++]^Sr(a,r,i,t,n),s3:e[c++]^Sr(a,i,t,n,r)}}function wr(e,t,n,r,i){let{sbox2:a,T01:o,T23:s}=_r,c=0;t^=e[c++],n^=e[c++],r^=e[c++],i^=e[c++];let l=e.length/4-2;for(let a=0;a<l;a++){let a=e[c++]^xr(o,s,t,i,r,n),l=e[c++]^xr(o,s,n,t,i,r),u=e[c++]^xr(o,s,r,n,t,i),d=e[c++]^xr(o,s,i,r,n,t);t=a,n=l,r=u,i=d}return{s0:e[c++]^Sr(a,t,i,r,n),s1:e[c++]^Sr(a,n,t,i,r),s2:e[c++]^Sr(a,r,n,t,i),s3:e[c++]^Sr(a,i,r,n,t)}}function Tr(e){if(z(e),e.length%or!==0)throw Error(`aes-(cbc/ecb).decrypt ciphertext should consist of blocks with size 16`)}function Er(e,t,n){z(e);let r=e.length,i=r%or;if(!t&&i!==0)throw Error(`aec/(cbc-ecb): unpadded plaintext with disabled padding`);ir(e)||(e=ar(e));let a=B(e);if(t){let e=or-i;e||=or,r+=e}return n=rr(r,n),$n(e,n),{b:a,o:B(n),out:n}}function Dr(e,t){if(!t)return e;let n=e.length;if(!n)throw Error(`aes/pcks5: empty ciphertext not allowed`);let r=e[n-1];if(r<=0||r>16)throw Error(`aes/pcks5: wrong padding`);let i=e.subarray(0,-r);for(let t=0;t<r;t++)if(e[n-t-1]!==r)throw Error(`aes/pcks5: wrong padding`);return i}function Or(e){let t=new Uint8Array(16),n=B(t);t.set(e);let r=or-e.length;for(let e=or-r;e<or;e++)t[e]=r;return n}var kr=nr({blockSize:16,nonceLength:16},function(e,t,n={}){let r=!n.disablePadding;return{encrypt(n,i){let a=yr(e),{b:o,o:s,out:c}=Er(n,r,i),l=t,u=[a];ir(l)||u.push(l=ar(l));let d=B(l),f=d[0],p=d[1],m=d[2],h=d[3],g=0;for(;g+4<=o.length;)f^=o[g+0],p^=o[g+1],m^=o[g+2],h^=o[g+3],{s0:f,s1:p,s2:m,s3:h}=Cr(a,f,p,m,h),s[g++]=f,s[g++]=p,s[g++]=m,s[g++]=h;if(r){let e=Or(n.subarray(g*4));f^=e[0],p^=e[1],m^=e[2],h^=e[3],{s0:f,s1:p,s2:m,s3:h}=Cr(a,f,p,m,h),s[g++]=f,s[g++]=p,s[g++]=m,s[g++]=h}return Xn(...u),c},decrypt(n,i){Tr(n);let a=br(e),o=t,s=[a];ir(o)||s.push(o=ar(o));let c=B(o);i=rr(n.length,i),ir(n)||s.push(n=ar(n)),$n(n,i);
1let l=B(n),u=B(i),d=c[0],f=c[1],p=c[2],m=c[3];for(let e=0;e+4<=l.length;){let t=d,n=f,r=p,i=m;d=l[e+0],f=l[e+1],p=l[e+2],m=l[e+3];let{s0:o,s1:s,s2:c,s3:h}=wr(a,d,f,p,m);u[e++]=o^t,u[e++]=s^n,u[e++]=c^r,u[e++]=h^i}return Xn(...s),Dr(i,r)}}});function Ar(e){return e instanceof Uint32Array||ArrayBuffer.isView(e)&&e.constructor.name===`Uint32Array`}function jr(e,t){if(z(t,16,`block`),!Ar(e))throw Error(`_encryptBlock accepts result of expandKeyLE`);let n=B(t),{s0:r,s1:i,s2:a,s3:o}=Cr(e,n[0],n[1],n[2],n[3]);return n[0]=r,n[1]=i,n[2]=a,n[3]=o,t}function Mr(e){let t=0;for(let n=or-1;n>=0;n--){let r=(e[n]&128)>>>7;e[n]=e[n]<<1|t,t=r}return t&&(e[or-1]^=135),e}function Nr(e,t){if(e.length!==t.length)throw Error(`xorBlock: blocks must have same length`);for(let n=0;n<e.length;n++)e[n]=e[n]^t[n];return e}var Pr=class{buffer;destroyed;k1;k2;xk;constructor(e){z(e),cr(e),this.xk=yr(e),this.buffer=new Uint8Array,this.destroyed=!1;let t=new Uint8Array(or);jr(this.xk,t),this.k1=Mr(t),this.k2=Mr(new Uint8Array(this.k1))}update(e){let{destroyed:t,buffer:n}=this;if(t)throw Error(`CMAC instance was destroyed`);z(e);let r=new Uint8Array(n.length+e.length);return r.set(n),r.set(e,n.length),this.buffer=r,this}digest(){if(this.destroyed)throw Error(`CMAC instance was destroyed`);let{buffer:e}=this,t=e.length,n=Math.ceil(t/or),r;n===0?(n=1,r=!1):r=t%or===0;let i=(n-1)*or,a=e.subarray(i),o;if(r)o=Nr(new Uint8Array(a),this.k1);else{let e=new Uint8Array(or);e.set(a),e[a.length]=128,o=Nr(e,this.k2)}let s=new Uint8Array(or);for(let t=0;t<n-1;t++)Nr(s,e.subarray(t*or,(t+1)*or)),jr(this.xk,s);return Nr(s,o),jr(this.xk,s),Xn(o),s}destroy(){let{buffer:e,destroyed:t,xk:n,k1:r,k2:i}=this;t||(this.destroyed=!0,Xn(e,n,r,i))}},Fr=(e,t)=>new Pr(e).update(t).digest();Fr.create=e=>new Pr(e);var Ir=e=>Uint8Array.from(e.split(``),e=>e.charCodeAt(0)),Lr=Ir(`expand 16-byte k`),Rr=Ir(`expand 32-byte k`),zr=B(Lr),Br=B(Rr);function V(e,t){return e<<t|e>>>32-t}function Vr(e){return e.byteOffset%4==0}var Hr=64,Ur=16,Wr=2**32-1,Gr=Uint32Array.of();function Kr(e,t,n,r,i,a,o,s){let c=i.length,l=new Uint8Array(Hr),u=B(l),d=Vr(i)&&Vr(a),f=d?B(i):Gr,p=d?B(a):Gr;for(let m=0;m<c;o++){if(e(t,n,r,u,o,s),o>=Wr)throw Error(`arx: counter overflow`);let h=Math.min(Hr,c-m);if(d&&h===Hr){let e=m/4;if(m%4!=0)throw Error(`arx: invalid block position`);for(let t=0,n;t<Ur;t++)n=e+t,p[n]=f[n]^u[t];m+=Hr;continue}for(let e=0,t;e<h;e++)t=m+e,a[t]=i[t]^l[e];m+=h}}function qr(e,t){let{allowShortKeys:n,extendNonceFn:r,counterLength:i,counterRight:a,rounds:o}=er({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},t);if(typeof e!=`function`)throw Error(`core must be a function`);return qn(i),qn(o),Kn(a),Kn(n),(t,s,c,l,u=0)=>{z(t,void 0,`key`),z(s,void 0,`nonce`),z(c,void 0,`data`);let d=c.length;if(l===void 0&&(l=new Uint8Array(d)),z(l,void 0,`output`),qn(u),u<0||u>=Wr)throw Error(`arx: counter overflow`);if(l.length<d)throw Error(`arx: output (${l.length}) is shorter than data (${d})`);let f=[],p=t.length,m,h;if(p===32)f.push(m=ar(t)),h=Br;else if(p===16&&n)m=new Uint8Array(32),m.set(t),m.set(t,16),h=zr,f.push(m);else throw z(t,32,`arx key`),Error(`invalid key size`);Vr(s)||f.push(s=ar(s));let g=B(m);if(r){if(s.length!==24)throw Error(`arx: extended nonce must be 24 bytes`);r(h,g,B(s.subarray(0,16)),g),s=s.subarray(16)}let _=16-i;if(_!==s.length)throw Error(`arx: nonce must be ${_} or 16 bytes`);if(_!==12){let e=new Uint8Array(12);e.set(s,a?0:12-s.length),s=e,f.push(s)}let v=B(s);return Kr(e,h,g,v,c,l,u,o),Xn(...f),l}}function Jr(e,t){return e[t++]&255|(e[t++]&255)<<8}var Yr=class{blockLen=16;outputLen=16;buffer=new Uint8Array(16);r=new Uint16Array(10);h=new Uint16Array(10);pad=new Uint16Array(8);pos=0;finished=!1;constructor(e){e=ar(z(e,32,`key`));let t=Jr(e,0),n=Jr(e,2),r=Jr(e,4),i=Jr(e,6),a=Jr(e,8),o=Jr(e,10),s=Jr(e,12),c=Jr(e,14);this.r[0]=t&8191,this.r[1]=(t>>>13|n<<3)&8191,this.r[2]=(n>>>10|r<<6)&7939,this.r[3]=(r>>>7|i<<9)&8191,this.r[4]=(i>>>4|a<<12)&255,this.r[5]=a>>>1&8190,this.r[6]=(a>>>14|o<<2)&8191,this.r[7]=(o>>>11|s<<5)&8065,this.r[8]=(s>>>8|c<<8)&8191,this.r[9]=c>>>5&127;for(let t=0;t<8;t++)this.pad[t]=Jr(e,16+2*t)}process(e,t,n=!1){let r=n?0:2048,{h:i,r:a}=this,o=a[0],s=a[1],c=a[2],l=a[3],u=a[4],d=a[5],f=a[6],p=a[7],m=a[8],h=a[9],g=Jr(e,t+0),_=Jr(e,t+2),v=Jr(e,t+4),y=Jr(e,t+6),ee=Jr(e,t+8),te=Jr(e,t+10),b=Jr(e,t+12),x=Jr(e,t+14),S=i[0]+(g&8191),C=i[1]+((g>>>13|_<<3)&8191),w=i[2]+((_>>>10|v<<6)&8191),T=i[3]+((v>>>7|y<<9)&8191),E=i[4]+((y>>>4|ee<<12)&8191),D=i[5]+(ee>>>1&8191),O=i[6]+((ee>>>14|te<<2)&8191),k=i[7]+((te>>>11|b<<5)&8191),A=i[8]+((b>>>8|x<<8)&8191),j=i[9]+(x>>>
15|r),M=0,N=M+S*o+5*h*C+5*m*w+5*p*T+5*f*E;M=N>>>13,N&=8191,N+=5*d*D+5*u*O+5*l*k+5*c*A+5*s*j,M+=N>>>13,N&=8191;let P=M+S*s+C*o+5*h*w+5*m*T+5*p*E;M=P>>>13,P&=8191,P+=5*f*D+5*d*O+5*u*k+5*l*A+5*c*j,M+=P>>>13,P&=8191;let F=M+S*c+C*s+w*o+5*h*T+5*m*E;M=F>>>13,F&=8191,F+=5*p*D+5*f*O+5*d*k+5*u*A+5*l*j,M+=F>>>13,F&=8191;let I=M+S*l+C*c+w*s+T*o+5*h*E;M=I>>>13,I&=8191,I+=5*m*D+5*p*O+5*f*k+5*d*A+5*u*j,M+=I>>>13,I&=8191;let ne=M+S*u+C*l+w*c+T*s+E*o;M=ne>>>13,ne&=8191,ne+=5*h*D+5*m*O+5*p*k+5*f*A+5*d*j,M+=ne>>>13,ne&=8191;let re=M+S*d+C*u+w*l+T*c+E*s;M=re>>>13,re&=8191,re+=D*o+5*h*O+5*m*k+5*p*A+5*f*j,M+=re>>>13,re&=8191;let ie=M+S*f+C*d+w*u+T*l+E*c;M=ie>>>13,ie&=8191,ie+=D*s+O*o+5*h*k+5*m*A+5*p*j,M+=ie>>>13,ie&=8191;let ae=M+S*p+C*f+w*d+T*u+E*l;M=ae>>>13,ae&=8191,ae+=D*c+O*s+k*o+5*h*A+5*m*j,M+=ae>>>13,ae&=8191;let oe=M+S*m+C*p+w*f+T*d+E*u;M=oe>>>13,oe&=8191,oe+=D*l+O*c+k*s+A*o+5*h*j,M+=oe>>>13,oe&=8191;let se=M+S*h+C*m+w*p+T*f+E*d;M=se>>>13,se&=8191,se+=D*u+O*l+k*c+A*s+j*o,M+=se>>>13,se&=8191,M=(M<<2)+M|0,M=M+N|0,N=M&8191,M>>>=13,P+=M,i[0]=N,i[1]=P,i[2]=F,i[3]=I,i[4]=ne,i[5]=re,i[6]=ie,i[7]=ae,i[8]=oe,i[9]=se}finalize(){let{h:e,pad:t}=this,n=new Uint16Array(10),r=e[1]>>>13;e[1]&=8191;for(let t=2;t<10;t++)e[t]+=r,r=e[t]>>>13,e[t]&=8191;e[0]+=r*5,r=e[0]>>>13,e[0]&=8191,e[1]+=r,r=e[1]>>>13,e[1]&=8191,e[2]+=r,n[0]=e[0]+5,r=n[0]>>>13,n[0]&=8191;for(let t=1;t<10;t++)n[t]=e[t]+r,r=n[t]>>>13,n[t]&=8191;n[9]-=8192;let i=(r^1)-1;for(let e=0;e<10;e++)n[e]&=i;i=~i;for(let t=0;t<10;t++)e[t]=e[t]&i|n[t];e[0]=(e[0]|e[1]<<13)&65535,e[1]=(e[1]>>>3|e[2]<<10)&65535,e[2]=(e[2]>>>6|e[3]<<7)&65535,e[3]=(e[3]>>>9|e[4]<<4)&65535,e[4]=(e[4]>>>12|e[5]<<1|e[6]<<14)&65535,e[5]=(e[6]>>>2|e[7]<<11)&65535,e[6]=(e[7]>>>5|e[8]<<8)&65535,e[7]=(e[8]>>>8|e[9]<<5)&65535;let a=e[0]+t[0];e[0]=a&65535;for(let n=1;n<8;n++)a=(e[n]+t[n]|0)+(a>>>16)|0,e[n]=a&65535;Xn(n)}update(e){Jn(this),z(e),e=ar(e);let{buffer:t,blockLen:n}=this,r=e.length;for(let i=0;i<r;){let a=Math.min(n-this.pos,r-i);if(a===n){for(;n<=r-i;i+=n)this.process(e,i);continue}t.set(e.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===n&&(this.process(t,0,!1),this.pos=0)}return this}destroy(){Xn(this.h,this.r,this.buffer,this.pad)}digestInto(e){Jn(this),Yn(e,this),this.finished=!0;let{buffer:t,h:n}=this,{pos:r}=this;if(r){for(t[r++]=1;r<16;r++)t[r]=0;this.process(t,0,!0)}this.finalize();let i=0;for(let t=0;t<8;t++)e[i++]=n[t]>>>0,e[i++]=n[t]>>>8;return e}digest(){let{buffer:e,outputLen:t}=this;this.digestInto(e);let n=e.slice(0,t);return this.destroy(),n}};function Xr(e){let t=(t,n)=>e(n).update(t).digest(),n=e(new Uint8Array(32));return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=t=>e(t),t}Xr(e=>new Yr(e));function Zr(e,t,n,r,i,a=20){let o=e[0],s=e[1],c=e[2],l=e[3],u=t[0],d=t[1],f=t[2],p=t[3],m=t[4],h=t[5],g=t[6],_=t[7],v=i,y=n[0],ee=n[1],te=n[2],b=o,x=s,S=c,C=l,w=u,T=d,E=f,D=p,O=m,k=h,A=g,j=_,M=v,N=y,P=ee,F=te;for(let e=0;e<a;e+=2)b=b+w|0,M=V(M^b,16),O=O+M|0,w=V(w^O,12),b=b+w|0,M=V(M^b,8),O=O+M|0,w=V(w^O,7),x=x+T|0,N=V(N^x,16),k=k+N|0,T=V(T^k,12),x=x+T|0,N=V(N^x,8),k=k+N|0,T=V(T^k,7),S=S+E|0,P=V(P^S,16),A=A+P|0,E=V(E^A,12),S=S+E|0,P=V(P^S,8),A=A+P|0,E=V(E^A,7),C=C+D|0,F=V(F^C,16),j=j+F|0,D=V(D^j,12),C=C+D|0,F=V(F^C,8),j=j+F|0,D=V(D^j,7),b=b+T|0,F=V(F^b,16),A=A+F|0,T=V(T^A,12),b=b+T|0,F=V(F^b,8),A=A+F|0,T=V(T^A,7),x=x+E|0,M=V(M^x,16),j=j+M|0,E=V(E^j,12),x=x+E|0,M=V(M^x,8),j=j+M|0,E=V(E^j,7),S=S+D|0,N=V(N^S,16),O=O+N|0,D=V(D^O,12),S=S+D|0,N=V(N^S,8),O=O+N|0,D=V(D^O,7),C=C+w|0,P=V(P^C,16),k=k+P|0,w=V(w^k,12),C=C+w|0,P=V(P^C,8),k=k+P|0,w=V(w^k,7);let I=0;r[I++]=o+b|0,r[I++]=s+x|0,r[I++]=c+S|0,r[I++]=l+C|0,r[I++]=u+w|0,r[I++]=d+T|0,r[I++]=f+E|0,r[I++]=p+D|0,r[I++]=m+O|0,r[I++]=h+k|0,r[I++]=g+A|0,r[I++]=_+j|0,r[I++]=v+M|0,r[I++]=y+N|0,r[I++]=ee+P|0,r[I++]=te+F|0}var Qr=qr(Zr,{counterRight:!1,counterLength:4,allowShortKeys:!1}),$r=class{oHash;iHash;blockLen;outputLen;finished=!1;destroyed=!1;constructor(e,t){if(Kt(e),Gt(t,void 0,`key`),this.iHash=e.create(),typeof this.iHash.update!=`function`)throw Error(`Expected instance of class which extends utils.Hash`);this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;
1let n=this.blockLen,r=new Uint8Array(n);r.set(t.length>n?e.create().update(t).digest():t);for(let e=0;e<r.length;e++)r[e]^=54;this.iHash.update(r),this.oHash=e.create();for(let e=0;e<r.length;e++)r[e]^=106;this.oHash.update(r),Yt(r)}update(e){return qt(this),this.iHash.update(e),this}digestInto(e){qt(this),Gt(e,this.outputLen,`output`),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||=Object.create(Object.getPrototypeOf(this),{});let{oHash:t,iHash:n,finished:r,destroyed:i,blockLen:a,outputLen:o}=this;return e=e,e.finished=r,e.destroyed=i,e.blockLen=a,e.outputLen=o,e.oHash=t._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},ei=(e,t,n)=>new $r(e,t).update(n).digest();ei.create=(e,t)=>new $r(e,t);function ti(e,t,n){return Kt(e),n===void 0&&(n=new Uint8Array(e.outputLen)),ei(e,n,t)}var ni=Uint8Array.of(0),ri=Uint8Array.of();function ii(e,t,n,r=32){Kt(e),Wt(r,`length`);let i=e.outputLen;if(r>255*i)throw Error(`Length must be <= 255*HashLen`);let a=Math.ceil(r/i);n===void 0?n=ri:Gt(n,void 0,`info`);let o=new Uint8Array(a*i),s=ei.create(e,t),c=s._cloneInto(),l=new Uint8Array(s.outputLen);for(let e=0;e<a;e++)ni[0]=e+1,c.update(e===0?ri:l).update(n).update(ni).digestInto(l),o.set(l,i*e),s._cloneInto(c);return s.destroy(),c.destroy(),Yt(l,ni),o.slice(0,r)}var ai=Object.defineProperty,H=(e,t)=>{for(var n in t)ai(e,n,{get:t[n],enumerable:!0})},oi=Symbol(`verified`),si=e=>e instanceof Object;function ci(e){if(!si(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 e=0;e<n.length;e++)if(typeof n[e]!=`string`)return!1}return!0}H({},{binarySearch:()=>mi,bytesToHex:()=>L,hexToBytes:()=>R,insertEventIntoAscendingList:()=>pi,insertEventIntoDescendingList:()=>fi,mergeReverseSortedLists:()=>hi,normalizeURL:()=>di,utf8Decoder:()=>li,utf8Encoder:()=>ui});var li=new TextDecoder(`utf-8`),ui=new TextEncoder;function di(e){try{e.indexOf(`://`)===-1&&(e=`wss://`+e);let t=new URL(e);return t.protocol===`http:`?t.protocol=`ws:`:t.protocol===`https:`&&(t.protocol=`wss:`),t.pathname=t.pathname.replace(/\/+/g,`/`),t.pathname.endsWith(`/`)&&(t.pathname=t.pathname.slice(0,-1)),(t.port===`80`&&t.protocol===`ws:`||t.port===`443`&&t.protocol===`wss:`)&&(t.port=``),t.searchParams.sort(),t.hash=``,t.toString()}catch{throw Error(`Invalid URL: ${e}`)}}function fi(e,t){let[n,r]=mi(e,e=>t.id===e.id?0:t.created_at===e.created_at?-1:e.created_at-t.created_at);return r||e.splice(n,0,t),e}function pi(e,t){let[n,r]=mi(e,e=>t.id===e.id?0:t.created_at===e.created_at?-1:t.created_at-e.created_at);return r||e.splice(n,0,t),e}function mi(e,t){let n=0,r=e.length-1;for(;n<=r;){let i=Math.floor((n+r)/2),a=t(e[i]);if(a===0)return[i,!0];a<0?r=i-1:n=i+1}return[n,!1]}function hi(e,t){let n=Array(e.length+t.length);n.length=0;let r=0,i=0,a=[];for(;r<e.length&&i<t.length;){let o;if(e[r]?.created_at>t[i]?.created_at?(o=e[r],r++):(o=t[i],i++),n.length>0&&n[n.length-1].created_at===o.created_at){if(a.includes(o.id))continue}else a.length=0;n.push(o),a.push(o.id)}for(;r<e.length;){let t=e[r];if(r++,n.length>0&&n[n.length-1].created_at===t.created_at){if(a.includes(t.id))continue}else a.length=0;n.push(t),a.push(t.id)}for(;i<t.length;){let e=t[i];if(i++,n.length>0&&n[n.length-1].created_at===e.created_at){if(a.includes(e.id))continue}else a.length=0;n.push(e),a.push(e.id)}return n}var gi=class{generateSecretKey(){return Ht.utils.randomSecretKey()}getPublicKey(e){return L(Ht.getPublicKey(e))}finalizeEvent(e,t){let n=e;return n.pubkey=L(Ht.getPublicKey(t)),n.id=vi(n),n.sig=L(Ht.sign(R(vi(n)),t)),n[oi]=!0,n}verifyEvent(e){if(typeof e[oi]==`boolean`)return e[oi];try{let t=vi(e);if(t!==e.id)return e[oi]=!1,!1;let n=Ht.verify(R(e.sig),R(t),R(e.pubkey));return e[oi]=n,n}catch{return e[oi]=!1,!1}}};function _i(e){if(!ci(e))throw 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 vi(e){return L(hn(ui.encode(_i(e))))}var yi=new gi,bi=yi.generateSecretKey,xi=yi.getPublicKey,Si=yi.finalizeEvent,Ci=yi.verifyEvent;H({},{Application:()=>eo,BadgeAward:()=>Ri,BadgeDefinition:()=>qa,BlockedRelaysList:()=>Ea,BlossomServerList:()=>Na,BookmarkList:()=>Ca,Bookmarksets:()=>Wa,Calendar:()=>so,CalendarEventRSVP:()=>co,ChannelCreation:()=>Ji,ChannelHideMessage:()=>Zi,ChannelMessage:()=>Xi,ChannelMetadata:()=>Yi,ChannelMuteUser:()=>Qi,ChatMessage:()=>zi,ClassifiedListing:()=>ro,ClientAuth:()=>Ia,Comment:()=>ra,CommunitiesList:()=>wa,CommunityDefinition:()=>po,CommunityPostApproval:()=>da,Contacts:()=>Ni,CreateOrUpdateProduct:()=>Xa,CreateOrUpdateStall:()=>Ya,Curationsets:()=>Ga,Date:()=>ao,DirectMessageRelaysList:()=>ja,DraftClassifiedListing:()=>io,DraftLong:()=>Qa,Emojisets:()=>$a,EncryptedDirectMessage:()=>
1Pi,EventDeletion:()=>Fi,FavoriteRelays:()=>Oa,FileMessage:()=>Ui,FileMetadata:()=>na,FileServerPreference:()=>Ma,Followsets:()=>Va,ForumThread:()=>Bi,GenericRepost:()=>Wi,Genericlists:()=>Ha,GiftWrap:()=>ea,GroupMetadata:()=>mo,HTTPAuth:()=>Ba,Handlerinformation:()=>fo,Handlerrecommendation:()=>uo,Highlights:()=>va,InterestsList:()=>ka,Interestsets:()=>Ja,JobFeedback:()=>ma,JobRequest:()=>fa,JobResult:()=>pa,Label:()=>ua,LightningPubRPC:()=>Fa,LiveChatMessage:()=>ia,LiveEvent:()=>to,LongFormArticle:()=>Za,Metadata:()=>Ai,Mutelist:()=>ba,NWCWalletInfo:()=>Pa,NWCWalletRequest:()=>La,NWCWalletResponse:()=>Ra,NormalVideo:()=>Ki,NostrConnect:()=>za,OpenTimestamps:()=>$i,Photo:()=>Gi,Pinlist:()=>xa,Poll:()=>ta,PollResponse:()=>ya,PrivateDirectMessage:()=>Hi,ProblemTracker:()=>sa,ProfileBadges:()=>Ka,PublicChatsList:()=>Ta,Reaction:()=>Li,RecommendRelay:()=>Mi,RelayList:()=>Sa,RelayReview:()=>lo,Relaysets:()=>Ua,Report:()=>ca,Reporting:()=>la,Repost:()=>Ii,Seal:()=>Vi,SearchRelaysList:()=>Da,ShortTextNote:()=>ji,ShortVideo:()=>qi,Time:()=>oo,UserEmojiList:()=>Aa,UserStatuses:()=>no,Voice:()=>aa,VoiceComment:()=>oa,Zap:()=>_a,ZapGoal:()=>ha,ZapRequest:()=>ga,classifyKind:()=>Oi,isAddressableKind:()=>Di,isEphemeralKind:()=>Ei,isKind:()=>ki,isRegularKind:()=>wi,isReplaceableKind:()=>Ti});function wi(e){return e<1e4&&e!==0&&e!==3}function Ti(e){return e===0||e===3||1e4<=e&&e<2e4}function Ei(e){return 2e4<=e&&e<3e4}function Di(e){return 3e4<=e&&e<4e4}function Oi(e){return wi(e)?`regular`:Ti(e)?`replaceable`:Ei(e)?`ephemeral`:Di(e)?`parameterized`:`unknown`}function ki(e,t){let n=t instanceof Array?t:[t];return ci(e)&&n.includes(e.kind)||!1}var Ai=0,ji=1,Mi=2,Ni=3,Pi=4,Fi=5,Ii=6,Li=7,Ri=8,zi=9,Bi=11,Vi=13,Hi=14,Ui=15,Wi=16,Gi=20,Ki=21,qi=22,Ji=40,Yi=41,Xi=42,Zi=43,Qi=44,$i=1040,ea=1059,ta=1068,na=1063,ra=1111,ia=1311,aa=1222,oa=1244,sa=1971,ca=1984,la=1984,ua=1985,da=4550,fa=5999,pa=6999,ma=7e3,ha=9041,ga=9734,_a=9735,va=9802,ya=1018,ba=1e4,xa=10001,Sa=10002,Ca=10003,wa=10004,Ta=10005,Ea=10006,Da=10007,Oa=10012,ka=10015,Aa=10030,ja=10050,Ma=10096,Na=10063,Pa=13194,Fa=21e3,Ia=22242,La=23194,Ra=23195,za=24133,Ba=27235,Va=3e4,Ha=30001,Ua=30002,Wa=30003,Ga=30004,Ka=30008,qa=30009,Ja=30015,Ya=30017,Xa=30018,Za=30023,Qa=30024,$a=30030,eo=30078,to=30311,no=30315,ro=30402,io=30403,ao=31922,oo=31923,so=31924,co=31925,lo=31987,uo=31989,fo=31990,po=34550,mo=39e3;function ho(e,t){if(e.ids&&e.ids.indexOf(t.id)===-1||e.kinds&&e.kinds.indexOf(t.kind)===-1||e.authors&&e.authors.indexOf(t.pubkey)===-1)return!1;for(let n in e)if(n[0]===`#`){let r=e[`#${n.slice(1)}`];if(r&&!t.tags.find(([e,t])=>e===n.slice(1)&&r.indexOf(t)!==-1))return!1}return!(e.since&&t.created_at<e.since||e.until&&t.created_at>e.until)}function go(e,t){for(let n=0;n<e.length;n++)if(ho(e[n],t))return!0;return!1}function _o(e){if(e.ids&&!e.ids.length||e.kinds&&!e.kinds.length||e.authors&&!e.authors.length)return 0;for(let[t,n]of Object.entries(e))if(t[0]===`#`&&Array.isArray(n)&&!n.length)return 0;return Math.min(Math.max(0,e.limit??1/0),e.ids?.length??1/0,e.authors?.length&&e.kinds?.every(e=>Ti(e))?e.authors.length*e.kinds.length:1/0,e.authors?.length&&e.kinds?.every(e=>Di(e))&&e[`#d`]?.length?e.authors.length*e.kinds.length*e[`#d`].length:1/0)}H({},{getHex64:()=>vo,getInt:()=>yo,getSubscriptionId:()=>bo,matchEventId:()=>xo,matchEventKind:()=>Co,matchEventPubkey:()=>So});function vo(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 yo(e,t){let n=t.length,r=e.indexOf(`"${t}":`)+n+3,i=e.slice(r),a=Math.min(i.indexOf(`,`),i.indexOf(`}`));return parseInt(i.slice(0,a),10)}function bo(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 a=r+1+i;return e.slice(r+1,a)}function xo(e,t){return t===vo(e,`id`)}function So(e,t){return t===vo(e,`pubkey`)}function Co(e,t){return t===yo(e,`kind`)}H({},{makeAuthEvent:()=>wo});function wo(e,t){return{kind:Ia,created_at:Math.floor(Date.now()/1e3),tags:[[`relay`,e],[`challenge`,t]],content:``}}var To={};H(To,{BECH32_REGEX:()=>Oo,Bech32MaxSize:()=>Do,NostrTypeGuard:()=>Eo,decode:()=>jo,decodeNostrURI:()=>Ao,encodeBytes:()=>Lo,naddrEncode:()=>Bo,neventEncode:()=>zo,noteEncode:()=>Fo,nprofileEncode:()=>Ro,npubEncode:()=>Po,nsecEncode:()=>No});var Eo={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||``)},Do=5e3,Oo=/[\x21-\x7E]{1,83}1[023456789acdefghjklmnpqrstuvwxyz]{6,}/;function ko(e){let 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 Ao(e){try{return e.startsWith(`nostr:`)&&(e=e.substring(6)),jo(e)}catch{return{type:`invalid`,data:null}}}function jo(e){let{prefix:t,words:n}
1=Wn.decode(e,Do),r=new Uint8Array(Wn.fromWords(n));switch(t){case`nprofile`:{let e=Mo(r);if(!e[0]?.[0])throw Error(`missing TLV 0 for nprofile`);if(e[0][0].length!==32)throw Error(`TLV 0 should be 32 bytes`);return{type:`nprofile`,data:{pubkey:L(e[0][0]),relays:e[1]?e[1].map(e=>li.decode(e)):[]}}}case`nevent`:{let e=Mo(r);if(!e[0]?.[0])throw Error(`missing TLV 0 for nevent`);if(e[0][0].length!==32)throw Error(`TLV 0 should be 32 bytes`);if(e[2]&&e[2][0].length!==32)throw Error(`TLV 2 should be 32 bytes`);if(e[3]&&e[3][0].length!==4)throw Error(`TLV 3 should be 4 bytes`);return{type:`nevent`,data:{id:L(e[0][0]),relays:e[1]?e[1].map(e=>li.decode(e)):[],author:e[2]?.[0]?L(e[2][0]):void 0,kind:e[3]?.[0]?parseInt(L(e[3][0]),16):void 0}}}case`naddr`:{let e=Mo(r);if(!e[0]?.[0])throw Error(`missing TLV 0 for naddr`);if(!e[2]?.[0])throw Error(`missing TLV 2 for naddr`);if(e[2][0].length!==32)throw Error(`TLV 2 should be 32 bytes`);if(!e[3]?.[0])throw Error(`missing TLV 3 for naddr`);if(e[3][0].length!==4)throw Error(`TLV 3 should be 4 bytes`);return{type:`naddr`,data:{identifier:li.decode(e[0][0]),pubkey:L(e[2][0]),kind:parseInt(L(e[3][0]),16),relays:e[1]?e[1].map(e=>li.decode(e)):[]}}}case`nsec`:return{type:t,data:r};case`npub`:case`note`:return{type:t,data:L(r)};default:throw Error(`unknown prefix ${t}`)}}function Mo(e){let t={},n=e;for(;n.length>0;){let e=n[0],r=n[1],i=n.slice(2,2+r);if(n=n.slice(2+r),i.length<r)throw Error(`not enough data to read on TLV ${e}`);t[e]=t[e]||[],t[e].push(i)}return t}function No(e){return Lo(`nsec`,e)}function Po(e){return Lo(`npub`,R(e))}function Fo(e){return Lo(`note`,R(e))}function Io(e,t){let n=Wn.toWords(t);return Wn.encode(e,n,Do)}function Lo(e,t){return Io(e,t)}function Ro(e){return Io(`nprofile`,Vo({0:[R(e.pubkey)],1:(e.relays||[]).map(e=>ui.encode(e))}))}function zo(e){let t;return e.kind!==void 0&&(t=ko(e.kind)),Io(`nevent`,Vo({0:[R(e.id)],1:(e.relays||[]).map(e=>ui.encode(e)),2:e.author?[R(e.author)]:[],3:t?[new Uint8Array(t)]:[]}))}function Bo(e){let t=new ArrayBuffer(4);return new DataView(t).setUint32(0,e.kind,!1),Io(`naddr`,Vo({0:[ui.encode(e.identifier)],1:(e.relays||[]).map(e=>ui.encode(e)),2:[R(e.pubkey)],3:[new Uint8Array(t)]}))}function Vo(e){let t=[];return Object.entries(e).reverse().forEach(([e,n])=>{n.forEach(n=>{let r=new Uint8Array(n.length+2);r.set([parseInt(e)],0),r.set([n.length],1),r.set(n,2),t.push(r)})}),nn(...t)}var Ho={};H(Ho,{decrypt:()=>Wo,encrypt:()=>Uo});function Uo(e,t,n){let r=e instanceof Uint8Array?e:R(e),i=Go(At.getSharedSecret(r,R(`02`+t))),a=Uint8Array.from(an(16)),o=ui.encode(n),s=kr(i,a).encrypt(o);return`${Rn.encode(new Uint8Array(s))}?iv=${Rn.encode(new Uint8Array(a.buffer))}`}function Wo(e,t,n){let r=e instanceof Uint8Array?e:R(e),[i,a]=n.split(`?iv=`),o=Go(At.getSharedSecret(r,R(`02`+t))),s=Rn.decode(a),c=Rn.decode(i),l=kr(o,s).decrypt(c);return li.decode(l)}function Go(e){return e.slice(1,33)}var Ko={};H(Ko,{NIP05_REGEX:()=>qo,isNip05:()=>Jo,isValid:()=>$o,queryProfile:()=>Qo,searchDomain:()=>Zo,useFetchImplementation:()=>Xo});var qo=/^(?:([\w.+-]+)@)?([\w_-]+(\.[\w_-]+)+)$/,Jo=e=>qo.test(e||``),Yo;try{Yo=fetch}catch{}function Xo(e){Yo=e}async function Zo(e,t=``){try{let n=`https://${e}/.well-known/nostr.json?name=${t}`,r=await Yo(n,{redirect:`manual`});if(r.status!==200)throw Error(`Wrong response code`);return(await r.json()).names}catch{return{}}}async function Qo(e){let t=e.match(qo);if(!t)return null;let[,n=`_`,r]=t;try{let e=`https://${r}/.well-known/nostr.json?name=${n}`,t=await Yo(e,{redirect:`manual`});if(t.status!==200)throw Error(`Wrong response code`);let i=await t.json(),a=i.names[n];return a?{pubkey:a,relays:i.relays?.[a]}:null}catch{return null}}async function $o(e,t){let n=await Qo(t);return n?n.pubkey===e:!1}H({},{parse:()=>es});function es(e){let t={reply:void 0,root:void 0,mentions:[],profiles:[],quotes:[]},n,r;for(let i=e.tags.length-1;i>=0;i--){let a=e.tags[i];if(a[0]===`e`&&a[1]){let[e,i,o,s,c]=a,l={id:i,relays:o?[o]:[],author:c};if(s===`root`){t.root=l;continue}if(s===`reply`){t.reply=l;continue}if(s===`mention`){t.mentions.push(l);continue}n?r=l:n=l,t.mentions.push(l);continue}if(a[0]===`q`&&a[1]){let[e,n,r]=a;t.quotes.push({id:n,relays:r?[r]:[]})}if(a[0]===`p`&&a[1]){t.profiles.push({pubkey:a[1],relays:a[2]?[a[2]]:[]});continue}}return t.root||=r||n||t.reply,t.reply||=n||t.root,[t.reply,t.root].forEach(e
1=>{if(!e)return;let n=t.mentions.indexOf(e);if(n!==-1&&t.mentions.splice(n,1),e.author){let n=t.profiles.find(t=>t.pubkey===e.author);n&&n.relays&&(e.relays||=[],n.relays.forEach(t=>{e.relays?.indexOf(t)===-1&&e.relays.push(t)}),n.relays=e.relays)}}),t.mentions.forEach(e=>{if(e.author){let n=t.profiles.find(t=>t.pubkey===e.author);n&&n.relays&&(e.relays||=[],n.relays.forEach(t=>{e.relays.indexOf(t)===-1&&e.relays.push(t)}),n.relays=e.relays)}}),t}H({},{fetchRelayInformation:()=>ns,useFetchImplementation:()=>ts});function ts(e){}async function ns(e){return await(await fetch(e.replace(`ws://`,`http://`).replace(`wss://`,`https://`),{headers:{Accept:`application/nostr+json`}})).json()}H({},{getPow:()=>rs,minePow:()=>as});function rs(e){let t=0;for(let n=0;n<64;n+=8){let r=parseInt(e.substring(n,n+8),16);if(r===0)t+=32;else{t+=Math.clz32(r);break}}return t}function is(e){let t=0;for(let n=0;n<e.length;n++){let r=e[n];if(r===0)t+=8;else{t+=Math.clz32(r)-24;break}}return t}function as(e,t){let n=0,r=e,i=[`nonce`,n.toString(),t.toString()];for(r.tags.push(i);;){let e=Math.floor(new Date().getTime()/1e3);e!==r.created_at&&(n=0,r.created_at=e),i[1]=(++n).toString();let a=hn(ui.encode(JSON.stringify([0,r.pubkey,r.created_at,r.kind,r.tags,r.content])));if(is(a)>=t){r.id=L(a);break}}return r}H({},{unwrapEvent:()=>Rs,unwrapManyEvents:()=>zs,wrapEvent:()=>Is,wrapManyEvents:()=>Ls}),H({},{createRumor:()=>Os,createSeal:()=>ks,createWrap:()=>As,unwrapEvent:()=>Ns,unwrapManyEvents:()=>Ps,wrapEvent:()=>js,wrapManyEvents:()=>Ms});var os={};H(os,{decrypt:()=>bs,encrypt:()=>ys,getConversationKey:()=>us,v2:()=>xs});var ss=1,cs=4294967295,ls=65536;function us(e,t){return ti(hn,At.getSharedSecret(e,R(`02`+t)).subarray(1,33),ui.encode(`nip44-v2`))}function ds(e,t){let n=ii(hn,e,t,76);return{chacha_key:n.subarray(0,32),chacha_nonce:n.subarray(32,44),hmac_key:n.subarray(44,76)}}function fs(e){if(!Number.isSafeInteger(e)||e<1)throw Error(`expected positive integer`);if(e<=32)return 32;let t=2**(Math.floor(Math.log2(e-1))+1),n=t<=256?32:t/8;return n*(Math.floor((e-1)/n)+1)}function ps(e){if(!Number.isSafeInteger(e)||e<ss||e>65535)throw Error(`invalid plaintext size: must be between 1 and 65535 bytes`);let t=new Uint8Array(2);return new DataView(t.buffer).setUint16(0,e,!1),t}function ms(e){if(!Number.isSafeInteger(e)||e<ls||e>cs)throw Error(`invalid plaintext size: must be between 65536 and 4294967295 bytes`);let t=new Uint8Array(4);return new DataView(t.buffer).setUint32(0,e,!1),t}function hs(e){let t=ui.encode(e),n=t.length;if(n<ss||n>cs)throw Error(`invalid plaintext size: must be between 1 and 4294967295 bytes`);return nn(n>=ls?nn(new Uint8Array([0,0]),ms(n)):ps(n),t,new Uint8Array(fs(n)-n))}function gs(e){let t=new DataView(e.buffer,e.byteOffset,e.byteLength),n=t.getUint16(0),r,i;if(n===0){if(r=t.getUint32(2),r<ls)throw Error(`invalid padding`);i=6}else r=n,i=2;let a=e.subarray(i,i+r);if(r<ss||r>cs||a.length!==r||e.length!==i+fs(r))throw Error(`invalid padding`);return li.decode(a)}
1function _s(e,t,n){if(n.length!==32)throw Error(`AAD associated data must be 32 bytes`);return ei(hn,e,nn(n,t))}function vs(e){if(typeof e!=`string`)throw Error(`payload must be a valid string`);let t=e.length;if(t<132)throw Error(`invalid payload length: `+t);if(e[0]===`#`)throw Error(`unknown encryption version`);let n;try{n=Rn.decode(e)}catch(e){throw Error(`invalid base64: `+e.message)}let r=n.length;if(r<99)throw Error(`invalid data length: `+r);let i=n[0];if(i!==2)throw Error(`unknown encryption version `+i);return{nonce:n.subarray(1,33),ciphertext:n.subarray(33,-32),mac:n.subarray(-32)}}function ys(e,t,n=an(32)){let{chacha_key:r,chacha_nonce:i,hmac_key:a}=ds(t,n),o=Qr(r,i,hs(e)),s=_s(a,o,n);return Rn.encode(nn(new Uint8Array([2]),n,o,s))}function bs(e,t){let{nonce:n,ciphertext:r,mac:i}=vs(e),{chacha_key:a,chacha_nonce:o,hmac_key:s}=ds(t,n);if(!tr(_s(s,r,n),i))throw Error(`invalid MAC`);return gs(Qr(a,o,r))}var xs={utils:{getConversationKey:us,calcPaddedLen:fs,pad:hs,unpad:gs},encrypt:ys,decrypt:bs},Ss=2880*60,Cs=()=>Math.round(Date.now()/1e3),ws=()=>Math.round(Cs()-Math.random()*Ss),Ts=(e,t)=>us(e,t),Es=(e,t,n)=>ys(JSON.stringify(e),Ts(t,n)),Ds=(e,t)=>JSON.parse(bs(e.content,Ts(t,e.pubkey)));function Os(e,t){let n={created_at:Cs(),content:``,tags:[],...e,pubkey:xi(t)};return n.id=vi(n),n}function ks(e,t,n){return Si({kind:Vi,content:Es(e,t,n),created_at:ws(),tags:[]},t)}function As(e,t){let n=bi();return Si({kind:ea,content:Es(e,n,t),created_at:ws(),tags:[[`p`,t]]},n)}function js(e,t,n){return As(ks(Os(e,t),t,n),n)}function Ms(e,t,n){if(!n||n.length===0)throw Error(`At least one recipient is required.`);let r=[js(e,t,xi(t))];return n.forEach(n=>{r.push(js(e,t,n))}),r}function Ns(e,t){return Ds(Ds(e,t),t)}function Ps(e,t){let n=[];return e.forEach(e=>{n.push(Ns(e,t))}),n.sort((e,t)=>e.created_at-t.created_at),n}function Fs(e,t,n,r){let i={created_at:Math.ceil(Date.now()/1e3),kind:Hi,tags:[],content:t};return(Array.isArray(e)?e:[e]).forEach(({publicKey:e,relayUrl:t})=>{i.tags.push(t?[`p`,e,t]:[`p`,e])}),r&&i.tags.push([`e`,r.eventId,r.relayUrl||``,`reply`]),n&&i.tags.push([`subject`,n]),i}function Is(e,t,n,r,i){return js(Fs(t,n,r,i),e,t.publicKey)}function Ls(e,t,n,r,i){if(!t||t.length===0)throw Error(`At least one recipient is required.`);return[{publicKey:xi(e)},...t].map(t=>Is(e,t,n,r,i))}var Rs=Ns,zs=Ps;H({},{finishRepostEvent:()=>Bs,getRepostedEvent:()=>Hs,getRepostedEventPointer:()=>Vs});function Bs(e,t,n,r){let i,a=[...e.tags??[],[`e`,t.id,n],[`p`,t.pubkey]];return t.kind===ji?i=Ii:(i=Wi,a.push([`k`,String(t.kind)])),Si({kind:i,tags:a,content:e.content===``||t.tags?.find(e=>e[0]===`-`)?``:JSON.stringify(t),created_at:e.created_at},r)}function Vs(e){if(![Ii,Wi].includes(e.kind))return;let t,n;for(let r=e.tags.length-1;r>=0&&(t===void 0||n===void 0);r--){let 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?.[2]].filter(e=>typeof e==`string`),author:n?.[1]}}function Hs(e,{skipVerification:t}={}){let n=Vs(e);if(n===void 0||e.content===``)return;let r;try{r=JSON.parse(e.content)}catch{return}if(r.id===n.id&&!(!t&&!Ci(r)))return r}H({},{NOSTR_URI_REGEX:()=>Us,parse:()=>Gs,test:()=>Ws});var Us=RegExp(`nostr:(${Oo.source})`);function Ws(e){return typeof e==`string`&&RegExp(`^${Us.source}$`).test(e)}function Gs(e){let t=e.match(RegExp(`^${Us.source}$`));if(!t)throw Error(`Invalid Nostr URI: ${e}`);return{uri:t[0],value:t[1],decoded:jo(t[1])}}H({},{parse:()=>Qs});function Ks(e){if(e)return/^\d+$/.test(e)?parseInt(e,10):e}function qs(e,t){let n=e.indexOf(`:`),r=e.indexOf(`:`,n+1);if(n===-1||r===-1)return;let i=parseInt(e.slice(0,n),10);if(!Number.isNaN(i))return{kind:i,pubkey:e.slice(n+1,r),identifier:e.slice(r+1),relays:t?[t]:[]}}function Js(e){switch(e[0]){case`E`:case`e`:return e[1]?{id:e[1],relays:e[2]?[e[2]]:[],author:e[3]}:void 0;case`A`:case`a`:return e[1]?qs(e[1],e[2]):void 0;case`I`:case`i`:return e[1]?{value:e[1],hint:e[2]}:void 0}}function Ys(e){if(e[1])return e[1].includes(`:`)?qs(e[1],e[2]):{id:e[1],relays:e[2]?[e[2]]:[],author:e[3]}}function Xs(e){return e.findLast(e=>e.tagName===`A`||e.tagName===`a`)?.pointer||e.findLast(e=>e.tagName===`I`||e.tagName===`i`)?.pointer||e.findLast(e=>e.tagName===`E`||e.tagName===`e`)?.pointer}function Zs(e,t){if(!e||!(`id`in e)||!e.author)return;let n=t.find(t=>t.pubkey===e.author);!n||!n.relays||(e.relays||=[],n.relays.forEach(t=>{e.relays.indexOf(t)===-1&&e.relays.push(t)}),n.relays=e.relays)}function Qs(e){let t={root:void 0,rootKind:void 0,reply:void 0,replyKind:void 0,mentions:[],quotes:[],profiles:[]},n=[],r=[];for(let i of e.tags){if((i[0]===`E`||i[0]===`A`||i[0]===`I`)&&i[1]){let e=Js(i);e&&n.push({tagName:i[0],pointer:e});continue}if((i[0]===`e`||i[0]===`a`||i[0]===`i`)&&i[1]){let e=Js(i);e&&r.push({tagName:i[0],pointer:e});continue}if(i[0]===`K`){t.rootKind=Ks(i[1]);continue}if(i[0]===`k`){t.replyKind=Ks(i[1]);continue}if(i[0]===`q`){let e=Ys(i);e&&t.quotes.push(e);continue}(i[0]===`P`||i[0]===`p`)&&i[1]&&t.profiles.push({pubkey:i[1],relays:i[2]?[i[2]]:[]})}return t.root=Xs(n),t.reply=Xs(r),Zs(t.root,t.profiles),Zs(t.reply,t.profiles),t.quotes.forEac
1h(e=>Zs(e,t.profiles)),t}H({},{finishReactionEvent:()=>$s,getReactedEventPointer:()=>ec});function $s(e,t,n){let r=t.tags.filter(e=>e.length>=2&&(e[0]===`e`||e[0]===`p`));return Si({...e,kind:Li,tags:[...e.tags??[],...r,[`e`,t.id],[`p`,t.pubkey]],content:e.content??`+`},n)}function ec(e){if(e.kind!==Li)return;let t,n;for(let r=e.tags.length-1;r>=0&&(t===void 0||n===void 0);r--){let 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(e=>e!==void 0),author:n[1]}}H({},{parse:()=>ic});var tc=/\W/m,nc=/[^\w\/] |[^\w\/]$|$|,| /m,rc=42;function*ic(e){let t=[];if(typeof e!=`string`){for(let n=0;n<e.tags.length;n++){let r=e.tags[n];r[0]===`emoji`&&r.length>=3&&t.push({type:`emoji`,shortcode:r[1],url:r[2]})}e=e.content}let n=e.length,r=0,i=0;mainloop:for(;i<n;){let a=e.indexOf(`:`,i),o=e.indexOf(`#`,i);if(a===-1&&o===-1)break mainloop;if(a===-1||o>=0&&o<a){if(o===0||e[o-1].match(tc)){let t=e.slice(o+1,o+rc).match(tc),a=t?o+1+t.index:n;yield{type:`text`,text:e.slice(r,o)},yield{type:`hashtag`,value:e.slice(o+1,a)},i=a,r=i;continue mainloop}i=o+1;continue mainloop}if(e.slice(a-5,a)===`nostr`){let t=e.slice(a+60).match(tc),o=t?a+60+t.index:n;try{let t,{data:n,type:s}=jo(e.slice(a+1,o));switch(s){case`npub`:t={pubkey:n};break;case`note`:t={id:n};break;case`nsec`:i=o+1;continue;default:t=n}r!==a-5&&(yield{type:`text`,text:e.slice(r,a-5)}),yield{type:`reference`,pointer:t},i=o,r=i;continue mainloop}catch{i=a+1;continue mainloop}}else if(e.slice(a-5,a)===`https`||e.slice(a-4,a)===`http`){let t=e.slice(a+4).match(nc),o=t?a+4+t.index:n,s=e[a-1]===`s`?5:4;try{let t=new URL(e.slice(a-s,o));if(t.hostname.indexOf(`.`)===-1)throw Error(`invalid url`);if(r!==a-s&&(yield{type:`text`,text:e.slice(r,a-s)}),/\.(png|jpe?g|gif|webp|heic|svg)$/i.test(t.pathname)){yield{type:`image`,url:t.toString()},i=o,r=i;continue mainloop}if(/\.(mp4|avi|webm|mkv|mov)$/i.test(t.pathname)){yield{type:`video`,url:t.toString()},i=o,r=i;continue mainloop}if(/\.(mp3|aac|ogg|opus|wav|flac)$/i.test(t.pathname)){yield{type:`audio`,url:t.toString()},i=o,r=i;continue mainloop}yield{type:`url`,url:t.toString()},i=o,r=i;continue mainloop}catch{i=o+1;continue mainloop}}else if(e.slice(a-3,a)===`wss`||e.slice(a-2,a)===`ws`){let t=e.slice(a+4).match(nc),o=t?a+4+t.index:n,s=e[a-1]===`s`?3:2;try{let t=new URL(e.slice(a-s,o));if(t.hostname.indexOf(`.`)===-1)throw Error(`invalid ws url`);r!==a-s&&(yield{type:`text`,text:e.slice(r,a-s)}),yield{type:`relay`,url:t.toString()},i=o,r=i;continue mainloop}catch{i=o+1;continue mainloop}}else{for(let n=0;n<t.length;n++){let o=t[n];if(e[a+o.shortcode.length+1]===`:`&&e.slice(a+1,a+o.shortcode.length+1)===o.shortcode){r!==a&&(yield{type:`text`,text:e.slice(r,a)}),yield o,i=a+o.shortcode.length+2,r=i;continue mainloop}}i=a+1;continue mainloop}}r!==n&&(yield{type:`text`,text:e.slice(r)})}H({},{channelCreateEvent:()=>ac,channelHideMessageEvent:()=>cc,channelMessageEvent:()=>sc,channelMetadataEvent:()=>oc,channelMuteUserEvent:()=>lc});var ac=(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 Si({kind:Ji,tags:[...e.tags??[]],content:n,created_at:e.created_at},t)},oc=(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 Si({kind:Yi,tags:[[`e`,e.channel_create_event_id],...e.tags??[]],content:n,created_at:e.created_at},t)},sc=(e,t)=>{let 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`]),Si({kind:Xi,tags:[...n,...e.tags??[]],content:e.content,created_at:e.created_at},t)},cc=(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 Si({kind:Zi,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 Si({kind:Qi,tags:[[`p`,e.pubkey_to_mute],...e.tags??[]],c
1ontent:n,created_at:e.created_at},t)};H({},{EMOJI_SHORTCODE_REGEX:()=>uc,matchAll:()=>fc,regex:()=>dc,replaceAll:()=>pc});var uc=/:(\w+):/,dc=()=>RegExp(`\\B${uc.source}\\B`,`g`);function*fc(e){let t=e.matchAll(dc());for(let e of t)try{let[t,n]=e;yield{shortcode:t,name:n,start:e.index,end:e.index+t.length}}catch{}}function pc(e,t){return e.replaceAll(dc(),(e,n)=>t({shortcode:e,name:n}))}H({},{useFetchImplementation:()=>hc,validateGithub:()=>gc});var mc;try{mc=fetch}catch{}function hc(e){mc=e}async function gc(e,t,n){try{return await(await mc(`https://gist.github.com/${t}/${n}/raw`)).text()===`Verifying that I control the following Nostr public key: ${e}`}catch{return!1}}H({},{makeNwcRequestEvent:()=>vc,parseConnectionString:()=>_c});function _c(e){let{host:t,pathname:n,searchParams:r}=new URL(e),i=n||t,a=r.getAll(`relay`),o=r.get(`secret`);if(!i||a.length===0||!o)throw Error(`invalid connection string`);return{pubkey:i,relay:a[0],relays:a,secret:o}}async function vc(e,t,n){let r=Uo(t,e,JSON.stringify({method:`pay_invoice`,params:{invoice:n}}));return Si({kind:La,created_at:Math.round(Date.now()/1e3),content:r,tags:[[`p`,e]]},t)}H({},{normalizeIdentifier:()=>yc});function yc(e){return e=e.trim().toLowerCase(),e=e.normalize(`NFKC`),Array.from(e).map(e=>/\p{Letter}/u.test(e)||/\p{Number}/u.test(e)?e:`-`).join(``)}H({},{getSatoshisAmountFromBolt11:()=>Ec,getZapEndpoint:()=>Sc,makeZapReceipt:()=>Tc,makeZapRequest:()=>Cc,useFetchImplementation:()=>xc,validateZapRequest:()=>wc});var bc;try{bc=fetch}catch{}function xc(e){bc=e}async function Sc(e){try{let t=``,{lud06:n,lud16:r}=JSON.parse(e.content);if(r){let[e,n]=r.split(`@`);t=new URL(`/.well-known/lnurlp/${e}`,`https://${n}`).toString()}else if(n){let{words:e}=Wn.decode(n,1e3),r=Wn.fromWords(e);t=li.decode(r)}else return null;let i=await(await bc(t)).json();if(i.allowsNostr&&i.nostrPubkey)return i.callback}catch{}return null}function Cc(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]),Ti(e.event.kind)){let n=[`a`,`${e.event.kind}:${e.event.pubkey}:`];t.tags.push(n)}else if(Di(e.event.kind)){let n=e.event.tags.find(([e,t])=>e===`d`&&t);if(!n)throw Error(`d tag not found or is empty`);let 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 wc(e){let t;try{t=JSON.parse(e)}catch{return`Invalid zap request JSON.`}if(!ci(t))return`Zap request is not a valid Nostr event.`;if(!Ci(t))return`Invalid signature on zap request.`;let n=t.tags.find(([e,t])=>e===`p`&&t);if(!n)return`Zap request doesn't have a 'p' tag.`;if(!n[1].match(/^[a-f0-9]{64}$/))return`Zap request 'p' tag is not valid hex.`;let r=t.tags.find(([e,t])=>e===`e`&&t);return r&&!r[1].match(/^[a-f0-9]{64}$/)?`Zap request 'e' tag is not valid hex.`:t.tags.find(([e,t])=>e===`relays`&&t)?null:`Zap request doesn't have a 'relays' tag.`}function Tc({zapRequest:e,preimage:t,bolt11:n,paidAt:r}){let i=JSON.parse(e),a=i.tags.filter(([e])=>e===`e`||e===`p`||e===`a`),o={kind:9735,created_at:Math.round(r.getTime()/1e3),content:``,tags:[...a,[`P`,i.pubkey],[`bolt11`,n],[`description`,e]]};return t&&o.tags.push([`preimage`,t]),o}function Ec(e){if(e.length<50)return 0;e=e.substring(0,50);let t=e.lastIndexOf(`1`);if(t===-1)return 0;let n=e.substring(0,t);if(!n.startsWith(`lnbc`))return 0;let r=n.substring(4);if(r.length<1)return 0;let i=r[r.length-1],a=i.charCodeAt(0)-48,o=a>=0&&a<=9,s=r.length-1;if(o&&s++,s<1)return 0;let c=parseInt(r.substring(0,s));switch(i){case`m`:return c*1e5;case`u`:return c*100;case`n`:return c/10;case`p`:return c/1e4;default:return c*1e8}}H({},{Negentropy:()=>Rc,NegentropyStorageVector:()=>Lc,NegentropySync:()=>Vc});var Dc=97,Oc=32,kc=16,Ac={Skip:0,Fingerprint:1,IdList:2},jc=class{_raw;length;constructor(e){typeof e==`number`?(this._raw=new Uint8Array(e),this.length=0):e instanceof Uint8Array?(this._raw=new Uint8Array(e),this.length=e.length):(this._raw=new Uint8Array(512),this.length=0)}unwrap(){return this._raw.subarray(0,this.length)}get capacity(){return this._raw.byteLength}extend(e){if(e instanceof jc&&(e=e.unwrap()),typeof e.length!=`number`)throw Error(`bad length`);let t=e.length+this.length;if(this.capacity<t){let e=this._raw,n=Math.max(this.capacity*2,t);this._raw=new Uint8Array(n),this._raw.set(e)}this._raw.set(e,this.length),this.length+=e.length}shift(){let e=this._raw[0];return this._raw=this._raw.subarray(1),this.length--,e}
1shiftN(e=1){let t=this._raw.subarray(0,e);return this._raw=this._raw.subarray(e),this.length-=e,t}};function Mc(e){let t=0;for(;;){if(e.length===0)throw Error(`parse ends prematurely`);let n=e.shift();if(t=t<<7|n&127,!(n&128))break}return t}function Nc(e){if(e===0)return new jc(new Uint8Array([0]));let t=[];for(;e!==0;)t.push(e&127),e>>>=7;t.reverse();for(let e=0;e<t.length-1;e++)t[e]|=128;return new jc(new Uint8Array(t))}function Pc(e){return Fc(e,1)[0]}function Fc(e,t){if(e.length<t)throw Error(`parse ends prematurely`);return e.shiftN(t)}var Ic=class{buf;constructor(){this.setToZero()}setToZero(){this.buf=new Uint8Array(Oc)}add(e){let t=0,n=0,r=new DataView(this.buf.buffer),i=new DataView(e.buffer);for(let e=0;e<8;e++){let a=e*4,o=r.getUint32(a,!0),s=i.getUint32(a,!0),c=o;c+=t,c+=s,c>4294967295&&(n=1),r.setUint32(a,c&4294967295,!0),t=n,n=0}}negate(){let e=new DataView(this.buf.buffer);for(let t=0;t<8;t++){let n=t*4;e.setUint32(n,~e.getUint32(n,!0))}let t=new Uint8Array(Oc);t[0]=1,this.add(t)}getFingerprint(e){let t=new jc;return t.extend(this.buf),t.extend(Nc(e)),hn(t.unwrap()).subarray(0,kc)}},Lc=class{items;sealed;constructor(){this.items=[],this.sealed=!1}insert(e,t){if(this.sealed)throw Error(`already sealed`);let n=R(t);if(n.byteLength!==Oc)throw Error(`bad id size for added item`);this.items.push({timestamp:e,id:n})}seal(){if(this.sealed)throw Error(`already sealed`);this.sealed=!0,this.items.sort(Bc);for(let e=1;e<this.items.length;e++)if(Bc(this.items[e-1],this.items[e])===0)throw Error(`duplicate item inserted`)}unseal(){this.sealed=!1}size(){return this._checkSealed(),this.items.length}getItem(e){if(this._checkSealed(),e>=this.items.length)throw Error(`out of range`);return this.items[e]}iterate(e,t,n){this._checkSealed(),this._checkBounds(e,t);for(let r=e;r<t&&n(this.items[r],r);++r);}findLowerBound(e,t,n){return this._checkSealed(),this._checkBounds(e,t),this._binarySearch(this.items,e,t,e=>Bc(e,n)<0)}fingerprint(e,t){let n=new Ic;return n.setToZero(),this.iterate(e,t,e=>(n.add(e.id),!0)),n.getFingerprint(t-e)}_checkSealed(){if(!this.sealed)throw Error(`not sealed`)}_checkBounds(e,t){if(e>t||t>this.items.length)throw Error(`bad range`)}_binarySearch(e,t,n,r){let i=n-t;for(;i>0;){let n=t,a=Math.floor(i/2);n+=a,r(e[n])?(t=++n,i-=a+1):i=a}return t}},Rc=class{storage;frameSizeLimit;lastTimestampIn;lastTimestampOut;constructor(e,t=6e4){if(t<4096)throw Error(`frameSizeLimit too small`);this.storage=e,this.frameSizeLimit=t,this.lastTimestampIn=0,this.lastTimestampOut=0}_bound(e,t){return{timestamp:e,id:t||new Uint8Array}}initiate(){let e=new jc;return e.extend(new Uint8Array([Dc])),this.splitRange(0,this.storage.size(),this._bound(Number.MAX_VALUE),e),L(e.unwrap())}reconcile(e,t,n){let r=new jc(R(e));this.lastTimestampIn=this.lastTimestampOut=0;let i=new jc;i.extend(new Uint8Array([Dc]));let a=Pc(r);if(a<96||a>111)throw Error(`invalid negentropy protocol version byte`);if(a!==Dc)throw Error(`unsupported negentropy protocol version requested: `+(a-96));let o=this.storage.size(),s=this._bound(0),c=0,l=!1;for(;r.length!==0;){let e=new jc,a=()=>{l&&(l=!1,e.extend(this.encodeBound(s)),e.extend(Nc(Ac.Skip)))},u=this.decodeBound(r),d=Mc(r),f=c,p=this.storage.findLowerBound(c,o,u);if(d===Ac.Skip)l=!0;else if(d===Ac.Fingerprint)zc(Fc(r,kc),this.storage.fingerprint(f,p))===0?l=!0:(a(),this.splitRange(f,p,u,e));else if(d===Ac.IdList){let e=Mc(r),i={};for(let t=0;t<e;t++){let e=Fc(r,Oc);i[L(e)]=e}if(l=!0,this.storage.iterate(f,p,e=>{let n=e.id,r=L(n);return i[r]?delete i[L(n)]:t?.(r),!0}),n)for(let e of Object.values(i))n(L(e))}else throw Error(`unexpected mode`);if(this.exceededFrameSizeLimit(i.length+e.length)){let e=this.storage.fingerprint(p,o);i.extend(this.encodeBound(this._bound(Number.MAX_VALUE))),i.extend(Nc(Ac.Fingerprint)),i.extend(e);break}else i.extend(e);c=p,s=u}return i.length===1?null:L(i.unwrap())}splitRange(e,t,n,r){let i=t-e;if(i<32)r.extend(this.encodeBound(n)),r.extend(Nc(Ac.IdList)),r.extend(Nc(i)),this.storage.iterate(e,t,e=>(r.extend(e.id),!0));else{let a=Math.floor(i/16),o=i%16,s=e;for(let e=0;e<16;e++){let i=a+ +(e<o),c=this.storage.fingerprint(s,s+i);s+=i;let l;if(s===t)l=n;else{let e,t;this.storage.iterate(s-1,s+1,(n,r)=>(r===s-1?e=n:t=n,!0)),l=this.getMinimalBound(e,t)}r.extend(this.encodeBound(l)),r.extend(Nc(Ac.Fingerprint)),r.extend(c)}}}exceededFrameSizeLimit(e){return e>this.frameSizeLimit-200}decodeTimestampIn(e){let t=Mc(e);return t=t===0?Number.MAX_VALUE:t-1,this.lastTimestampIn===Number.MAX_VALUE||t===Number.MAX_VALUE?(this.lastTimestampIn=Number.MAX_VALUE,Number.MAX_VALUE):(t+=this.lastTimestampIn,this.lastTimestampIn=t,t)}decodeBound(e){let t=this.decodeTimestampIn(e),n=Mc(e);if(n>Oc)throw Error(`bound key too long`);return{timestamp:t,id:Fc(e,n)}}encodeTimestampOut(e){if(e===Number.MAX_VALUE)return this.lastTimestampOut=Number.MAX_VALUE,Nc(0);let t=e;return e-=this.lastTimestampOut,this.lastTimestampOut=t,Nc(e+1)}encodeBound(e){let t=new jc;return t.extend(this.encodeTimestampOut(e.timestamp)),t.extend(Nc(e.id.length)),t.extend(e.id),t}getMinimalBound(e,t){if(t.timestamp!==e.timestamp)return this._bound(t.timestamp);{let n=0,r=t.id,i=e.id;for(let e=0;e<Oc&&r[e]===i[e];e++)n++;return this._bound(t.timestamp,t.id.subarray(0,n+1))}}};function zc(e,t){for(let n=0;n<e.byteLength;n++){if(e[n]<t[n])return-1;if(e[n]>t[n])return 1}return e.byteLength>t.byteLength?1:e.byteLength<t.byteLength?-1:0}function Bc(e,t){return e.timestamp===t.timestamp?zc(e.id,t.id):e.timestamp-t.timestamp}var Vc=class{relay;storage;neg;filter;subscription;onhave;onneed;constructor(e,t,n,r={}){this.relay=e,this.storage=t,this.neg=new Rc(t),this.onhave=r.onhave,this.onneed=r.onneed,this.filter=n,this.subscription=this.relay.prepareSubscription([{}],{label:r.label||`negentropy`}),this.subscription.oncustom=e=>{switch(e[0]){case`NEG-MSG`:e.length<3&&console.warn(`got invalid NEG-MSG from ${this.relay.url}: ${e}`);try{let t=this.neg.reconcile(e[2],this.onhave,this.onneed);t?this.relay.send(`["NEG-MSG", "${this.subscription.id}", "${t}"]`):(this.close(),r.onclose?.())}catch(e){console.error(`negentropy reconcile error:`,e),r?.onclose?.(`reconcile error: ${e}`)}break;case`NEG-CLOSE`:{let t=e[2];console.warn(`negentropy error:`,t),r.onclose?.(t);break}case`NEG-ERR`:r.onclose?.()}}}async start(){let e=this.neg.initiate();this.relay.send(`["NEG-OPEN","${this.subscription.id}",${JSON.stringify(this.filter)},"${e}"]`)}close(){this.relay.send(`["NEG-CLOSE","${this.subscription.id}"]`),this.subscription.close()}};H({},{getToken:()=>Uc,hashPayload:()=>Xc,unpackEventFromToken:()=>
1Gc,validateEvent:()=>Qc,validateEventKind:()=>qc,validateEventMethodTag:()=>Yc,validateEventPayloadTag:()=>Zc,validateEventTimestamp:()=>Kc,validateEventUrlTag:()=>Jc,validateToken:()=>Wc});var Hc=`Nostr `;async function Uc(e,t,n,r=!1,i){let a={kind:Ba,tags:[[`u`,e],[`method`,t]],created_at:Math.round(new Date().getTime()/1e3),content:``};i&&a.tags.push([`payload`,Xc(i)]);let o=await n(a);return(r?Hc:``)+Rn.encode(ui.encode(JSON.stringify(o)))}async function Wc(e,t,n){return await Qc(await Gc(e).catch(e=>{throw e}),t,n).catch(e=>{throw e})}async function Gc(e){if(!e)throw Error(`Missing token`);e=e.replace(Hc,``);let t=li.decode(Rn.decode(e));if(!t||t.length===0||!t.startsWith(`{`))throw Error(`Invalid token`);return JSON.parse(t)}function Kc(e){return e.created_at?Math.round(new Date().getTime()/1e3)-e.created_at<60:!1}function qc(e){return e.kind===Ba}function Jc(e,t){let n=e.tags.find(e=>e[0]===`u`);return n?n.length>0&&n[1]===t:!1}function Yc(e,t){let n=e.tags.find(e=>e[0]===`method`);return n?n.length>0&&n[1].toLowerCase()===t.toLowerCase():!1}function Xc(e){return L(hn(ui.encode(JSON.stringify(e))))}function Zc(e,t){let n=e.tags.find(e=>e[0]===`payload`);if(!n)return!1;let r=Xc(t);return n.length>0&&n[1]===r}async function Qc(e,t,n,r){if(!Ci(e))throw Error(`Invalid nostr event, signature invalid`);if(!qc(e))throw Error(`Invalid nostr event, kind invalid`);if(!Kc(e))throw Error(`Invalid nostr event, created_at timestamp invalid`);if(!Jc(e,t))throw Error(`Invalid nostr event, url tag invalid`);if(!Yc(e,n))throw Error(`Invalid nostr event, method tag invalid`);if(r&&typeof r==`object`&&Object.keys(r).length>0&&!Zc(e,r))throw Error(`Invalid nostr event, payload tag does not match request body hash`);return!0}var $c=t((e=>{var t=Symbol.for(`react.transitional.element`),n=Symbol.for(`react.fragment`);function r(e,n,r){var i=null;if(r!==void 0&&(i=``+r),n.key!==void 0&&(i=``+n.key),`key`in n)for(var a in r={},n)a!==`key`&&(r[a]=n[a]);else r=n;return n=r.ref,{$$typeof:t,type:e,key:i,ref:n===void 0?null:n,props:r}}e.Fragment=n,e.jsx=r,e.jsxs=r})),el=t(((e,t)=>{t.exports=$c()})),tl=e(n(),1),nl=el();function rl(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name===`Uint8Array`}function il(e){if(!Number.isSafeInteger(e)||e<0)throw Error(`positive integer expected, got `+e)}function al(e,...t){if(!rl(e))throw Error(`Uint8Array expected`);if(t.length>0&&!t.includes(e.length))throw Error(`Uint8Array expected of length `+t+`, got length=`+e.length)}function ol(e){if(typeof e!=`function`||typeof e.create!=`function`)throw Error(`Hash should be wrapped by utils.createHasher`);il(e.outputLen),il(e.blockLen)}function sl(e,t=!0){if(e.destroyed)throw Error(`Hash instance has been destroyed`);if(t&&e.finished)throw Error(`Hash#digest() has already been called`)}function cl(e,t){al(e);let n=t.outputLen;if(e.length<n)throw Error(`digestInto() expects output buffer of length at least `+n)}function ll(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function ul(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function dl(e,t){return e<<32-t|e>>>t}var fl=typeof Uint8Array.from([]).toHex==`function`&&typeof Uint8Array.fromHex==`function`,pl=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,`0`));function ml(e){if(al(e),fl)return e.toHex();let t=``;for(let n=0;n<e.length;n++)t+=pl[e[n]];return t}var hl={_0:48,_9:57,A:65,F:70,a:97,f:102};function gl(e){if(e>=hl._0&&e<=hl._9)return e-hl._0;if(e>=hl.A&&e<=hl.F)return e-(hl.A-10);if(e>=hl.a&&e<=hl.f)return e-(hl.a-10)}function _l(e){if(typeof e!=`string`)throw Error(`hex string expected, got `+typeof e);if(fl)return Uint8Array.fromHex(e);let t=e.length,n=t/2;if(t%2)throw Error(`hex string expected, got unpadded hex of length `+t);let r=new Uint8Array(n);for(let t=0,i=0;t<n;t++,i+=2){let n=gl(e.charCodeAt(i)),a=gl(e.charCodeAt(i+1));if(n===void 0||a===void 0){let t=e[i]+e[i+1];throw Error(`hex string expected, got non-hex character "`+t+`" at index `+i)}r[t]=n*16+a}return r}function vl(e){if(typeof e!=`string`)throw Error(`string expected`);return new Uint8Array(new TextEncoder().encode(e))}function yl(e){return typeof e==`string`&&(e=vl(e)),al(e),e}function bl(...e){let t=0;for(let n=0;n<e.length;n++){let r=e[n];al(r),t+=r.length}let n=new Uint8Array(t);for(let t=0,r=0;t<e.length;t++){let i=e[t];n.set(i,r),r+=i.length}return n}var xl=class{};function Sl(e){let t=t=>e().update(yl(t)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function Cl(e,t,n,r){if(typeof e.setBigUint64==`function`)return e.setBigUint64(t,n,r);let i=BigInt(32),a=BigInt(4294967295),o=Number(n>>i&a),s=Number(n&a),c=r?4:0,l=r?0:4;e.setUint32(t+c,o,r),e.setUint32(t+l,s,r)}function wl(e,t,n){return e&t^~e&n}function Tl(e,t,n){return e&t^e&n^t&n}var El=class extends xl{constructor(e,t,n,r){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=r,this.buffer=new Uint8Array(e),this.view=ul(this.buffer)}update(e){sl(this),e=yl(e),al(e);let{view:t,buffer:n,blockLen:r}=this,i=e.length;for(let a=0;a<i;){let o=Math.min(r-this.pos,i-a);if(o===r){let t=ul(e);for(;r<=i-a;a+=r)this.process(t,a);continue}n.set(e.subarray(a,a+o),this.pos),this.pos+=o,a+=o,this.pos===r&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){sl(this),cl(e,this),this.finished=!0;let{buffer:t,view:n,blockLen:r,isLE:i}=this,{pos:a}=this;t[a++]=128,ll(this.buffer.subarray(a)),this.padOffset>r-a&&(this.process(n,0),a=0);for(let e=a;
1e<r;e++)t[e]=0;Cl(n,r-8,BigInt(this.length*8),i),this.process(n,0);let o=ul(e),s=this.outputLen;if(s%4)throw Error(`_sha2: outputLen should be aligned to 32bit`);let c=s/4,l=this.get();if(c>l.length)throw Error(`_sha2: outputLen bigger than state`);for(let e=0;e<c;e++)o.setUint32(4*e,l[e],i)}digest(){let{buffer:e,outputLen:t}=this;this.digestInto(e);let n=e.slice(0,t);return this.destroy(),n}_cloneInto(e){e||=new this.constructor,e.set(...this.get());let{blockLen:t,buffer:n,length:r,finished:i,destroyed:a,pos:o}=this;return e.destroyed=a,e.finished=i,e.length=r,e.pos=o,r%t&&e.buffer.set(n),e}clone(){return this._cloneInto()}},Dl=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Ol=Uint32Array.from([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]),kl=new Uint32Array(64),Al=class extends El{constructor(e=32){super(64,e,8,!1),this.A=Dl[0]|0,this.B=Dl[1]|0,this.C=Dl[2]|0,this.D=Dl[3]|0,this.E=Dl[4]|0,this.F=Dl[5]|0,this.G=Dl[6]|0,this.H=Dl[7]|0}get(){let{A:e,B:t,C:n,D:r,E:i,F:a,G:o,H:s}=this;return[e,t,n,r,i,a,o,s]}set(e,t,n,r,i,a,o,s){this.A=e|0,this.B=t|0,this.C=n|0,this.D=r|0,this.E=i|0,this.F=a|0,this.G=o|0,this.H=s|0}process(e,t){for(let n=0;n<16;n++,t+=4)kl[n]=e.getUint32(t,!1);for(let e=16;e<64;e++){let t=kl[e-15],n=kl[e-2],r=dl(t,7)^dl(t,18)^t>>>3;kl[e]=(dl(n,17)^dl(n,19)^n>>>10)+kl[e-7]+r+kl[e-16]|0}let{A:n,B:r,C:i,D:a,E:o,F:s,G:c,H:l}=this;for(let e=0;e<64;e++){let t=dl(o,6)^dl(o,11)^dl(o,25),u=l+t+wl(o,s,c)+Ol[e]+kl[e]|0,d=(dl(n,2)^dl(n,13)^dl(n,22))+Tl(n,r,i)|0;l=c,c=s,s=o,o=a+u|0,a=i,i=r,r=n,n=u+d|0}n=n+this.A|0,r=r+this.B|0,i=i+this.C|0,a=a+this.D|0,o=o+this.E|0,s=s+this.F|0,c=c+this.G|0,l=l+this.H|0,this.set(n,r,i,a,o,s,c,l)}roundClean(){ll(kl)}destroy(){this.set(0,0,0,0,0,0,0,0),ll(this.buffer)}},jl=Sl(()=>new Al),Ml=new TextDecoder(`utf-8`),Nl=new TextEncoder,Pl=1,Fl=4294967295,Il=65536;function Ll(e,t){return ti(hn,At.getSharedSecret(e,R(`02`+t)).subarray(1,33),Nl.encode(`nip44-v2`))}function Rl(e,t){let n=ii(hn,e,t,76);return{chacha_key:n.subarray(0,32),chacha_nonce:n.subarray(32,44),hmac_key:n.subarray(44,76)}}function zl(e){if(!Number.isSafeInteger(e)||e<1)throw Error(`expected positive integer`);if(e<=32)return 32;let t=2**(Math.floor(Math.log2(e-1))+1),n=t<=256?32:t/8;return n*(Math.floor((e-1)/n)+1)}function Bl(e){if(!Number.isSafeInteger(e)||e<Pl||e>65535)throw Error(`invalid plaintext size: must be between 1 and 65535 bytes`);let t=new Uint8Array(2);return new DataView(t.buffer).setUint16(0,e,!1),t}function Vl(e){if(!Number.isSafeInteger(e)||e<Il||e>Fl)throw Error(`invalid plaintext size: must be between 65536 and 4294967295 bytes`);let t=new Uint8Array(4);return new DataView(t.buffer).setUint32(0,e,!1),t}function Hl(e){let t=Nl.encode(e),n=t.length;if(n<Pl||n>Fl)throw Error(`invalid plaintext size: must be between 1 and 4294967295 bytes`);return nn(n>=Il?nn(new Uint8Array([0,0]),Vl(n)):Bl(n),t,new Uint8Array(zl(n)-n))}function Ul(e){let t=new DataView(e.buffer,e.byteOffset,e.byteLength),n=t.getUint16(0),r,i;if(n===0){if(r=t.getUint32(2),r<Il)throw Error(`invalid padding`);i=6}else r=n,i=2;let a=e.subarray(i,i+r);if(r<Pl||r>Fl||a.length!==r||e.length!==i+zl(r))throw Error(`invalid padding`);return Ml.decode(a)}function Wl(e,t,n){if(n.length!==32)throw Error(`AAD associated data must be 32 bytes`);return ei(hn,e,nn(n,t))}function Gl(e){if(typeof e!=`string`)throw Error(`payload must be a valid string`);let t=e.length;if(t<132)throw Error(`invalid payload length: `+t);if(e[0]===`#`)throw Error(`unknown encryption version`);let n;try{n=Rn.decode(e)}catch(e){throw Error(`invalid base64: `+e.message)}let r=n.length;if(r<99)throw Error(`invalid data length: `+r);let i=n[0];if(i!==2)throw Error(`unknown encryption version `+i);return{nonce:n.subarray(1,33),ciphertext:n.subarray(33,-32),mac:n.subarray(-32)}}function Kl(e,t,n=an(32)){let{chacha_key:r,chacha_nonce:i,hmac_key:a}=Rl(t,n),o=Qr(r,i,Hl(e)),s=Wl(a,o,n);return Rn.encode(nn(new Uint8Array([2]),n,o,s))}function ql(e,t){let{nonce:n,ciphertext:r,mac:i}=Gl(e),{chacha_key:a,chacha_nonce:o,hmac_key:s}=Rl(t,n);if(!tr(Wl(s,r,n),i))throw Error(`invalid MAC`);return Ul(Qr(a,o,r))}var Jl=Symbol(`verified`),Yl=e=>e instanceof Object;function Xl(e){if(!Yl(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 e=0;e<n.length;e++)if(typeof n[e]!=`string`)return!1}return!0}new TextDecoder(`utf-8`);var Zl=new TextEncoder,Ql=class{generateSecretKey(){return Ht.utils.randomSecretKey()}getPublicKey(e){return L(Ht.getPublicKey(e))}finalizeEvent(e,t){let n=e;return n.pubkey=L(Ht.getPublicKey(t)),n.id=eu(n),n.sig=L(Ht.sign(R(eu(n)),t)),n[Jl]=!0,n}verifyEvent(e){if(typeof e[Jl]==`boolean`)return e[Jl];try{let t=eu(e);
1if(t!==e.id)return e[Jl]=!1,!1;let n=Ht.verify(R(e.sig),R(t),R(e.pubkey));return e[Jl]=n,n}catch{return e[Jl]=!1,!1}}};function $l(e){if(!Xl(e))throw 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 eu(e){return L(hn(Zl.encode($l(e))))}var tu=new Ql,nu=tu.generateSecretKey,ru=tu.getPublicKey,iu=tu.finalizeEvent,au=tu.verifyEvent,ou=(e,t)=>t.some(t=>e instanceof t),su,cu;function lu(){return su||=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction]}function uu(){return cu||=[IDBCursor.prototype.advance,IDBCursor.prototype.continue,IDBCursor.prototype.continuePrimaryKey]}var du=new WeakMap,fu=new WeakMap,pu=new WeakMap;function mu(e){let t=new Promise((t,n)=>{let r=()=>{e.removeEventListener(`success`,i),e.removeEventListener(`error`,a)},i=()=>{t(bu(e.result)),r()},a=()=>{n(e.error),r()};e.addEventListener(`success`,i),e.addEventListener(`error`,a)});return pu.set(t,e),t}function hu(e){if(du.has(e))return;let t=new Promise((t,n)=>{let r=()=>{e.removeEventListener(`complete`,i),e.removeEventListener(`error`,a),e.removeEventListener(`abort`,a)},i=()=>{t(),r()},a=()=>{n(e.error||new DOMException(`AbortError`,`AbortError`)),r()};e.addEventListener(`complete`,i),e.addEventListener(`error`,a),e.addEventListener(`abort`,a)});du.set(e,t)}var gu={get(e,t,n){if(e instanceof IDBTransaction){if(t===`done`)return du.get(e);if(t===`store`)return n.objectStoreNames[1]?void 0:n.objectStore(n.objectStoreNames[0])}return bu(e[t])},set(e,t,n){return e[t]=n,!0},has(e,t){return e instanceof IDBTransaction&&(t===`done`||t===`store`)?!0:t in e}};function _u(e){gu=e(gu)}function vu(e){return uu().includes(e)?function(...t){return e.apply(xu(this),t),bu(this.request)}:function(...t){return bu(e.apply(xu(this),t))}}function yu(e){return typeof e==`function`?vu(e):(e instanceof IDBTransaction&&hu(e),ou(e,lu())?new Proxy(e,gu):e)}function bu(e){if(e instanceof IDBRequest)return mu(e);if(fu.has(e))return fu.get(e);let t=yu(e);return t!==e&&(fu.set(e,t),pu.set(t,e)),t}var xu=e=>pu.get(e);function Su(e,t,{blocked:n,upgrade:r,blocking:i,terminated:a}={}){let o=indexedDB.open(e,t),s=bu(o);return r&&o.addEventListener(`upgradeneeded`,e=>{r(bu(o.result),e.oldVersion,e.newVersion,bu(o.transaction),e)}),n&&o.addEventListener(`blocked`,e=>n(e.oldVersion,e.newVersion,e)),s.then(e=>{a&&e.addEventListener(`close`,()=>a()),i&&e.addEventListener(`versionchange`,e=>i(e.oldVersion,e.newVersion,e))}).catch(()=>{}),s}var Cu=[`get`,`getKey`,`getAll`,`getAllKeys`,`count`],wu=[`put`,`add`,`delete`,`clear`],Tu=new Map;function Eu(e,t){if(!(e instanceof IDBDatabase&&!(t in e)&&typeof t==`string`))return;if(Tu.get(t))return Tu.get(t);let n=t.replace(/FromIndex$/,``),r=t!==n,i=wu.includes(n);if(!(n in(r?IDBIndex:IDBObjectStore).prototype)||!(i||Cu.includes(n)))return;let a=async function(e,...t){let a=this.transaction(e,i?`readwrite`:`readonly`),o=a.store;return r&&(o=o.index(t.shift())),(await Promise.all([o[n](...t),i&&a.done]))[0]};return Tu.set(t,a),a}_u(e=>({...e,get:(t,n,r)=>Eu(t,n)||e.get(t,n,r),has:(t,n)=>!!Eu(t,n)||e.has(t,n)}));var Du=[`continue`,`continuePrimaryKey`,`advance`],Ou={},ku=new WeakMap,Au=new WeakMap,ju={get(e,t){if(!Du.includes(t))return e[t];let n=Ou[t];return n||=Ou[t]=function(...e){ku.set(this,Au.get(this)[t](...e))},n}};async function*Mu(...e){let t=this;if(t instanceof IDBCursor||(t=await t.openCursor(...e)),!t)return;t=t;let n=new Proxy(t,ju);for(Au.set(n,t),pu.set(n,xu(t));t;)yield n,t=await(ku.get(n)||t.continue()),ku.delete(n)}function Nu(e,t){return t===Symbol.asyncIterator&&ou(e,[IDBIndex,IDBObjectStore,IDBCursor])||t===`iterate`&&ou(e,[IDBIndex,IDBObjectStore])}_u(e=>({...e,get(t,n,r){return Nu(t,n)?Mu:e.get(t,n,r)},has(t,n){return Nu(t,n)||e.has(t,n)}}));var Pu=class e{pubkey;relays;secret;constructor(e){let t=new URL(e),n=new URLSearchParams(t.search),r=t.hostname||t.pathname.slice(2),i=n.getAll(`relay`),a=n.get(`secret`)??void 0;if(!r)throw Error(`Invalid bunker URI`);this.pubkey=r,this.relays=i,this.secret=a}get href(){return this.toString()}toString(){return e.toString(this)}static fromJSON(t){return new e(e.toString(t))}static toString(e){let t=new URLSearchParams;for(let n of e.relays)t.append(`relay`,n);return e.secret&&t.set(`secret`,e.secret),`bunker://${e.pubkey}?${t.toString()}`}},Fu=class{#e;constructor(e){this.#e=e?.timeout??3e3}async awaitNostr(){let e=globalThis.nostr;if(e)return e;let t=Date.now()+this.#e;
1return new Promise((e,n)=>{let r=setInterval(()=>{let i=globalThis.nostr;i?(clearInterval(r),e(i)):Date.now()>=t&&(clearInterval(r),n(Error(`Browser extension not available`)))},100)})}async getPublicKey(){let e=await(await this.awaitNostr()).getPublicKey();if(typeof e!=`string`)throw Error(`Nostr public key retrieval failed: expected string, got ${JSON.stringify(e)}`);return e}async signEvent(e){let t=await(await this.awaitNostr()).signEvent(e);if(typeof t!=`object`||!t.id||!t.pubkey||!t.sig)throw Error(`Nostr event signing failed: expected object with id, pubkey, and sig, got ${JSON.stringify(t)}`);return t}async getRelays(){let e=await this.awaitNostr();if(!e.getRelays)return{};let t=await e.getRelays();if(typeof t!=`object`||!t)throw Error(`Nostr getRelays failed: expected object, got ${JSON.stringify(t)}`);return t}get nip04(){let e=globalThis.nostr;if(!(e&&!e.nip04))return{encrypt:async(e,t)=>{let n=await this.awaitNostr();if(!n.nip04)throw Error(`NIP-04 encryption not supported by extension`);let r=await n.nip04.encrypt(e,t);if(typeof r!=`string`)throw Error(`NIP-04 encryption failed: expected string result, got ${JSON.stringify(r)}`);return r},decrypt:async(e,t)=>{let n=await this.awaitNostr();if(!n.nip04)throw Error(`NIP-04 decryption not supported by extension`);let r=await n.nip04.decrypt(e,t);if(typeof r!=`string`)throw Error(`NIP-04 decryption failed: expected string result, got ${JSON.stringify(r)}`);return r}}}get nip44(){let e=globalThis.nostr;if(!(e&&!e.nip44))return{encrypt:async(e,t)=>{let n=await this.awaitNostr();if(!n.nip44)throw Error(`NIP-44 encryption not supported by extension`);let r=await n.nip44.encrypt(e,t);if(typeof r!=`string`)throw Error(`NIP-44 encryption failed: expected string result, got ${JSON.stringify(r)}`);return r},decrypt:async(e,t)=>{let n=await this.awaitNostr();if(!n.nip44)throw Error(`NIP-44 decryption not supported by extension`);let r=await n.nip44.decrypt(e,t);if(typeof r!=`string`)throw Error(`NIP-44 decryption failed: expected string result, got ${JSON.stringify(r)}`);return r}}}},Iu,Lu=Object.freeze({status:`aborted`});function U(e,t,n){function r(n,r){if(n._zod||Object.defineProperty(n,"_zod",{value:{def:r,constr:o,traits:new Set},enumerable:!1}),n._zod.traits.has(e))return;n._zod.traits.add(e),t(n,r);let i=o.prototype,a=Object.keys(i);for(let e=0;e<a.length;e++){let t=a[e];t in n||(n[t]=i[t].bind(n))}}let i=n?.Parent??Object;class a extends i{}Object.defineProperty(a,"name",{value:e});function o(e){var t;let i=n?.Parent?new a:this;r(i,e),(t=i._zod).deferred??(t.deferred=[]);for(let e of i._zod.deferred)e();return i}return Object.defineProperty(o,"init",{value:r}),Object.defineProperty(o,Symbol.hasInstance,{value:t=>n?.Parent&&t instanceof n.Parent?!0:t?._zod?.traits?.has(e)}),Object.defineProperty(o,"name",{value:e}),o}var Ru=class extends Error{constructor(){super(`Encountered Promise during synchronous parse. Use .parseAsync() instead.`)}},zu=class extends Error{constructor(e){super(`Encountered unidirectional transform during encode: ${e}`),this.name=`ZodEncodeError`}};(Iu=globalThis).__zod_globalConfig??(Iu.__zod_globalConfig={});var Bu=globalThis.__zod_globalConfig;function Vu(e){return e&&Object.assign(Bu,e),Bu}function Hu(e){let t=Object.values(e).filter(e=>typeof e==`number`);return Object.entries(e).filter(([e,n])=>t.indexOf(+e)===-1).map(([e,t])=>t)}function Uu(e,t){return typeof t==`bigint`?t.toString():t}function Wu(e){return{get value(){{let t=e();return Object.defineProperty(this,"value",{value:t}),t}throw Error(`cached value already set`)}}}function Gu(e){return e==null}function Ku(e){let t=+!!e.startsWith(`^`),n=e.endsWith(`$`)?e.length-1:e.length;return e.slice(t,n)}function qu(e,t){let n=e/t,r=Math.round(n),i=2**-52*Math.max(Math.abs(n),1);return Math.abs(n-r)<i?0:n-r}var Ju=Symbol(`evaluating`);function W(e,t,n){let r;Object.defineProperty(e,t,{get(){if(r!==Ju)return r===void 0&&(r=Ju,r=n()),r},set(n){Object.defineProperty(e,t,{value:n})},configurable:!0})}function Yu(e,t,n){Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0})}function Xu(...e){let t={};for(let n of e)Object.assign(t,Object.getOwnPropertyDescriptors(n));return Object.defineProperties({},t)}function Zu(e){return JSON.stringify(e)}function Qu(e){return e.toLowerCase().trim().replace(/[^\w\s-]/g,``).replace(/[\s_-]+/g,`-`).replace(/^-+|-+$/g,``)}var $u=`captureStackTrace`in Error?Error.captureStackTrace:(...e)=>{};function ed(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}var td=Wu(()=>{if(Bu.jitless||typeof navigator<`u`&&navigator?.userAgent?.includes(`Cloudflare`))return!1;try{return Function(``),!0}catch{return!1}});
vendor: 4,125 bytes, line 1
1function nd(e){if(ed(e)===!1)return!1;let t=e.constructor;if(t===void 0||typeof t!=`function`)return!0;let n=t.prototype;return!(ed(n)===!1||Object.prototype.hasOwnProperty.call(n,`isPrototypeOf`)===!1)}function rd(e){return nd(e)?{...e}:Array.isArray(e)?[...e]:e instanceof Map?new Map(e):e instanceof Set?new Set(e):e}var id=new Set([`string`,`number`,`symbol`]);function ad(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function od(e,t,n){let r=new e._zod.constr(t??e._zod.def);return(!t||n?.parent)&&(r._zod.parent=e),r}function G(e){let t=e;if(!t)return{};if(typeof t==`string`)return{error:()=>t};if(t?.message!==void 0){if(t?.error!==void 0)throw Error("Cannot specify both `message` and `error` params");t.error=t.message}return delete t.message,typeof t.error==`string`?{...t,error:()=>t.error}:t}function sd(e){return Object.keys(e).filter(t=>e[t]._zod.optin===`optional`&&e[t]._zod.optout===`optional`)}var cd={safeint:[-(2**53-1),2**53-1],int32:[-2147483648,2147483647],uint32:[0,4294967295],float32:[-34028234663852886e22,34028234663852886e22],float64:[-Number.MAX_VALUE,Number.MAX_VALUE]};function ld(e,t){let n=e._zod.def,r=n.checks;if(r&&r.length>0)throw Error(`.pick() cannot be used on object schemas containing refinements`);return od(e,Xu(e._zod.def,{get shape(){let e={};for(let r in t){if(!(r in n.shape))throw Error(`Unrecognized key: "${r}"`);t[r]&&(e[r]=n.shape[r])}return Yu(this,`shape`,e),e},checks:[]}))}function ud(e,t){let n=e._zod.def,r=n.checks;if(r&&r.length>0)throw Error(`.omit() cannot be used on object schemas containing refinements`);return od(e,Xu(e._zod.def,{get shape(){let r={...e._zod.def.shape};for(let e in t){if(!(e in n.shape))throw Error(`Unrecognized key: "${e}"`);t[e]&&delete r[e]}return Yu(this,`shape`,r),r},checks:[]}))}function dd(e,t){if(!nd(t))throw Error(`Invalid input to extend: expected a plain object`);let n=e._zod.def.checks;if(n&&n.length>0){let n=e._zod.def.shape;for(let e in t)if(Object.getOwnPropertyDescriptor(n,e)!==void 0)throw Error("Cannot overwrite keys on object schemas containing refinements. Use `.safeExtend()` instead.")}return od(e,Xu(e._zod.def,{get shape(){let n={...e._zod.def.shape,...t};return Yu(this,`shape`,n),n}}))}function fd(e,t){if(!nd(t))throw Error(`Invalid input to safeExtend: expected a plain object`);return od(e,Xu(e._zod.def,{get shape(){let n={...e._zod.def.shape,...t};return Yu(this,`shape`,n),n}}))}function pd(e,t){if(e._zod.def.checks?.length)throw Error(`.merge() cannot be used on object schemas containing refinements. Use .safeExtend() instead.`);return od(e,Xu(e._zod.def,{get shape(){let n={...e._zod.def.shape,...t._zod.def.shape};return Yu(this,`shape`,n),n},get catchall(){return t._zod.def.catchall},checks:t._zod.def.checks??[]}))}function md(e,t,n){let r=t._zod.def.checks;if(r&&r.length>0)throw Error(`.partial() cannot be used on object schemas containing refinements`);return od(t,Xu(t._zod.def,{get shape(){let r=t._zod.def.shape,i={...r};if(n)for(let t in n){if(!(t in r))throw Error(`Unrecognized key: "${t}"`);n[t]&&(i[t]=e?new e({type:`optional`,innerType:r[t]}):r[t])}else for(let t in r)i[t]=e?new e({type:`optional`,innerType:r[t]}):r[t];return Yu(this,`shape`,i),i},checks:[]}))}function hd(e,t,n){return od(t,Xu(t._zod.def,{get shape(){let r=t._zod.def.shape,i={...r};if(n)for(let t in n){if(!(t in i))throw Error(`Unrecognized key: "${t}"`);n[t]&&(i[t]=new e({type:`nonoptional`,innerType:r[t]}))}else for(let t in r)i[t]=new e({type:`nonoptional`,innerType:r[t]});return Yu(this,`shape`,i),i}}))}function gd(e,t=0){if(e.aborted===!0)return!0;for(let n=t;n<e.issues.length;n++)if(e.issues[n]?.continue!==!0)return!0;return!1}function _d(e,t=0){if(e.aborted===!0)return!0;for(let n=t;n<e.issues.length;n++)if(e.issues[n]?.continue===!1)return!0;return!1}function vd(e,t){return t.map(t=>{var n;return(n=t).path??(n.path=[]),t.path.unshift(e),t})}function yd(e){return typeof e==`string`?e:e?.message}function bd(e,t,n){let r=e.message?e.message:yd(e.inst?._zod.def?.error?.(e))??yd(t?.error?.(e))??yd(n.customError?.(e))??yd(n.localeError?.(e))??`Invalid input`,{inst:i,continue:a,input
vendor: 4,447 bytes, line 1
1:o,...s}=e;return s.path??=[],s.message=r,t?.reportInput&&(s.input=o),s}function xd(e){return Array.isArray(e)?`array`:typeof e==`string`?`string`:`unknown`}function Sd(...e){let[t,n,r]=e;return typeof t==`string`?{message:t,code:`custom`,input:n,inst:r}:{...t}}var Cd=(e,t)=>{e.name=`$ZodError`,Object.defineProperty(e,"_zod",{value:e._zod,enumerable:!1}),Object.defineProperty(e,"issues",{value:t,enumerable:!1}),e.message=JSON.stringify(t,Uu,2),Object.defineProperty(e,"toString",{value:()=>e.message,enumerable:!1})},wd=U(`$ZodError`,Cd),Td=U(`$ZodError`,Cd,{Parent:Error});function Ed(e,t=e=>e.message){let n={},r=[];for(let i of e.issues)i.path.length>0?(n[i.path[0]]=n[i.path[0]]||[],n[i.path[0]].push(t(i))):r.push(t(i));return{formErrors:r,fieldErrors:n}}function Dd(e,t=e=>e.message){let n={_errors:[]},r=(e,i=[])=>{for(let a of e.issues)if(a.code===`invalid_union`&&a.errors.length)a.errors.map(e=>r({issues:e},[...i,...a.path]));else if(a.code===`invalid_key`)r({issues:a.issues},[...i,...a.path]);else if(a.code===`invalid_element`)r({issues:a.issues},[...i,...a.path]);else{let e=[...i,...a.path];if(e.length===0)n._errors.push(t(a));else{let r=n,i=0;for(;i<e.length;){let n=e[i];i===e.length-1?(r[n]=r[n]||{_errors:[]},r[n]._errors.push(t(a))):r[n]=r[n]||{_errors:[]},r=r[n],i++}}}};return r(e),n}var Od=e=>(t,n,r,i)=>{let a=r?{...r,async:!1}:{async:!1},o=t._zod.run({value:n,issues:[]},a);if(o instanceof Promise)throw new Ru;if(o.issues.length){let t=new(i?.Err??e)(o.issues.map(e=>bd(e,a,Vu())));throw $u(t,i?.callee),t}return o.value},kd=Od(Td),Ad=e=>async(t,n,r,i)=>{let a=r?{...r,async:!0}:{async:!0},o=t._zod.run({value:n,issues:[]},a);if(o instanceof Promise&&(o=await o),o.issues.length){let t=new(i?.Err??e)(o.issues.map(e=>bd(e,a,Vu())));throw $u(t,i?.callee),t}return o.value},jd=Ad(Td),Md=e=>(t,n,r)=>{let i=r?{...r,async:!1}:{async:!1},a=t._zod.run({value:n,issues:[]},i);if(a instanceof Promise)throw new Ru;return a.issues.length?{success:!1,error:new(e??wd)(a.issues.map(e=>bd(e,i,Vu())))}:{success:!0,data:a.value}},Nd=Md(Td),Pd=e=>async(t,n,r)=>{let i=r?{...r,async:!0}:{async:!0},a=t._zod.run({value:n,issues:[]},i);return a instanceof Promise&&(a=await a),a.issues.length?{success:!1,error:new e(a.issues.map(e=>bd(e,i,Vu())))}:{success:!0,data:a.value}},Fd=Pd(Td),Id=e=>(t,n,r)=>{let i=r?{...r,direction:`backward`}:{direction:`backward`};return Od(e)(t,n,i)},Ld=e=>(t,n,r)=>Od(e)(t,n,r),Rd=e=>async(t,n,r)=>{let i=r?{...r,direction:`backward`}:{direction:`backward`};return Ad(e)(t,n,i)},zd=e=>async(t,n,r)=>Ad(e)(t,n,r),Bd=e=>(t,n,r)=>{let i=r?{...r,direction:`backward`}:{direction:`backward`};return Md(e)(t,n,i)},Vd=e=>(t,n,r)=>Md(e)(t,n,r),Hd=e=>async(t,n,r)=>{let i=r?{...r,direction:`backward`}:{direction:`backward`};return Pd(e)(t,n,i)},Ud=e=>async(t,n,r)=>Pd(e)(t,n,r),Wd=/^[cC][0-9a-z]{6,}$/,Gd=/^[0-9a-z]+$/,Kd=/^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/,qd=/^[0-9a-vA-V]{20}$/,Jd=/^[A-Za-z0-9]{27}$/,Yd=/^[a-zA-Z0-9_-]{21}$/,Xd=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/,Zd=/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/,Qd=e=>e?RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${e}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`):/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/,$d=/^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/,ef=`^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;function tf(){return new RegExp(ef,`u`)}var nf=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,rf=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$/,af=/^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/,of=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,sf=/^$|^(?:[0-9a-zA-Z+/]{4}
vendor: 5,937 bytes, line 1
1)*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/,cf=/^[A-Za-z0-9_-]*$/,lf=/^https?$/,uf=/^\+[1-9]\d{6,14}$/,df=`(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))`,ff=RegExp(`^${df}$`);function pf(e){let t=`(?:[01]\\d|2[0-3]):[0-5]\\d`;return typeof e.precision==`number`?e.precision===-1?`${t}`:e.precision===0?`${t}:[0-5]\\d`:`${t}:[0-5]\\d\\.\\d{${e.precision}}`:`${t}(?::[0-5]\\d(?:\\.\\d+)?)?`}function mf(e){return RegExp(`^${pf(e)}$`)}function hf(e){let t=pf({precision:e.precision}),n=[`Z`];e.local&&n.push(``),e.offset&&n.push(`([+-](?:[01]\\d|2[0-3]):[0-5]\\d)`);let r=`${t}(?:${n.join(`|`)})`;return RegExp(`^${df}T(?:${r})$`)}var gf=e=>{let t=e?`[\\s\\S]{${e?.minimum??0},${e?.maximum??``}}`:`[\\s\\S]*`;return RegExp(`^${t}$`)},_f=/^-?\d+$/,vf=/^-?\d+(?:\.\d+)?$/,yf=/^(?:true|false)$/i,bf=/^[^A-Z]*$/,xf=/^[^a-z]*$/,Sf=U(`$ZodCheck`,(e,t)=>{var n;e._zod??={},e._zod.def=t,(n=e._zod).onattach??(n.onattach=[])}),Cf={number:`number`,bigint:`bigint`,object:`date`},wf=U(`$ZodCheckLessThan`,(e,t)=>{Sf.init(e,t);let n=Cf[typeof t.value];e._zod.onattach.push(e=>{let n=e._zod.bag,r=(t.inclusive?n.maximum:n.exclusiveMaximum)??1/0;t.value<r&&(t.inclusive?n.maximum=t.value:n.exclusiveMaximum=t.value)}),e._zod.check=r=>{(t.inclusive?r.value<=t.value:r.value<t.value)||r.issues.push({origin:n,code:`too_big`,maximum:typeof t.value==`object`?t.value.getTime():t.value,input:r.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),Tf=U(`$ZodCheckGreaterThan`,(e,t)=>{Sf.init(e,t);let n=Cf[typeof t.value];e._zod.onattach.push(e=>{let n=e._zod.bag,r=(t.inclusive?n.minimum:n.exclusiveMinimum)??-1/0;t.value>r&&(t.inclusive?n.minimum=t.value:n.exclusiveMinimum=t.value)}),e._zod.check=r=>{(t.inclusive?r.value>=t.value:r.value>t.value)||r.issues.push({origin:n,code:`too_small`,minimum:typeof t.value==`object`?t.value.getTime():t.value,input:r.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),Ef=U(`$ZodCheckMultipleOf`,(e,t)=>{Sf.init(e,t),e._zod.onattach.push(e=>{var n;(n=e._zod.bag).multipleOf??(n.multipleOf=t.value)}),e._zod.check=n=>{if(typeof n.value!=typeof t.value)throw Error(`Cannot mix number and bigint in multiple_of check.`);(typeof n.value==`bigint`?n.value%t.value===BigInt(0):qu(n.value,t.value)===0)||n.issues.push({origin:typeof n.value,code:`not_multiple_of`,divisor:t.value,input:n.value,inst:e,continue:!t.abort})}}),Df=U(`$ZodCheckNumberFormat`,(e,t)=>{Sf.init(e,t),t.format=t.format||`float64`;let n=t.format?.includes(`int`),r=n?`int`:`number`,[i,a]=cd[t.format];e._zod.onattach.push(e=>{let r=e._zod.bag;r.format=t.format,r.minimum=i,r.maximum=a,n&&(r.pattern=_f)}),e._zod.check=o=>{let s=o.value;if(n){if(!Number.isInteger(s)){o.issues.push({expected:r,format:t.format,code:`invalid_type`,continue:!1,input:s,inst:e});return}if(!Number.isSafeInteger(s)){s>0?o.issues.push({input:s,code:`too_big`,maximum:2**53-1,note:`Integers must be within the safe integer range.`,inst:e,origin:r,inclusive:!0,continue:!t.abort}):o.issues.push({input:s,code:`too_small`,minimum:-(2**53-1),note:`Integers must be within the safe integer range.`,inst:e,origin:r,inclusive:!0,continue:!t.abort});return}}s<i&&o.issues.push({origin:`number`,input:s,code:`too_small`,minimum:i,inclusive:!0,inst:e,continue:!t.abort}),s>a&&o.issues.push({origin:`number`,input:s,code:`too_big`,maximum:a,inclusive:!0,inst:e,continue:!t.abort})}}),Of=U(`$ZodCheckMaxLength`,(e,t)=>{var n;Sf.init(e,t),(n=e._zod.def).when??(n.when=e=>{let t=e.value;return!Gu(t)&&t.length!==void 0}),e._zod.onattach.push(e=>{let n=e._zod.bag.maximum??1/0;t.maximum<n&&(e._zod.bag.maximum=t.maximum)}),e._zod.check=n=>{let r=n.value;if(r.length<=t.maximum)return;let i=xd(r);n.issues.push({origin:i,code:`too_big`,maximum:t.maximum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),kf=U(`$ZodCheckMinLength`,(e,t)=>{var n;Sf.init(e,t),(n=e._zod.def).when??(n.when=e=>{let t=e.value;return!Gu(t)&&t.length!==void 0}),e._zod.onattach.push(e=>{let n=e._zod.bag.minimum??-1/0;t.minimum>n&&(e._zod.bag.minimum=t.minimum)}),e._zod.check=n=>{let r=n.value;if(r.length>=t.minimum)return;let i=xd(r);n.issues.push({origin:i,code:`too_small`,minimum:t.minimum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),Af=U(`$ZodCheckLengthEquals`,(e,t)=>{var n;Sf.init(e,t),(n=e._zod.def).when??(n.when=e=>{let t=e.value;return!Gu(t)&&t.length!==void 0}),e._zod.onattach.push(e=>{let n=e._zod.bag;n.minimum=t.length,n.maximum=t.length,n.length=t.length}),e._zod.check=n=>{let r=n.value,i=r.length;if(i===t.length)return;let a=xd(r),o=i>t.length;n.issues.push({origin:a,...o?{code:`too_big`,maximum:t.length}:{code:`too_small`,minimum:t.length},inclusive:!0,exact:!0,input:n.value,inst:e,continue:!t.abort})}}),jf=U(`$ZodCheckStringFormat`,(e,t)=>{var n,r;Sf.init(e,t),e._zod.onattach.push(e=>{let n=e._zod.bag;n.format=t.format,t.pattern&&(n.patterns??=new Set,n.patterns.add(t.pattern))}),t.pattern?(n=e._zod).check??(n.check=n=>{t.pattern.lastIndex=0,!t.pattern.test(n.value)&&n.issues.push({origin:`string`,code:`invalid_format`,format:t.format,input:n.value,...t.pattern?{pattern:t.pattern.toString()}:{},inst:e,continue:!t.abort})}):(r=e._zod).check??(r.check=()=>{})}),Mf=U(`$ZodCheckRegex`,(e,t)=>{jf.init(e,t),e._zod.check=n=>{t.pattern.lastIndex=0,!t.pattern.test(n.value)&&n.issues.push({origin:`string`,code:`invalid_format`,format:`regex`,input:n.value,pattern:t.pattern.toString(),inst:e,continue:!t.abort})}}),Nf=U(`$ZodCheckLowerCase`,(e,t)=>{t.pattern??=bf,jf.init(e,t)}),Pf=U(`$ZodCheckUpperCase`,(e,t)=>{t.pattern??=xf,jf.init(e,t)}),Ff=U(`$ZodCheckIncludes`,(e,t)=>{Sf.init(e,t);let n=ad(t.includes),r=new RegExp(typeof t.position==`number`?`^.{${t.position}}${n}`:n);t.pattern=r,e._zod.onattach.push(e=>{let t=e._zod.bag;t.patterns??=new Set,t.patterns.add(r)}),e._zod.check=n=>
vendor: 7,929 bytes, lines 1-3
1{n.value.includes(t.includes,t.position)||n.issues.push({origin:`string`,code:`invalid_format`,format:`includes`,includes:t.includes,input:n.value,inst:e,continue:!t.abort})}}),If=U(`$ZodCheckStartsWith`,(e,t)=>{Sf.init(e,t);let n=RegExp(`^${ad(t.prefix)}.*`);t.pattern??=n,e._zod.onattach.push(e=>{let t=e._zod.bag;t.patterns??=new Set,t.patterns.add(n)}),e._zod.check=n=>{n.value.startsWith(t.prefix)||n.issues.push({origin:`string`,code:`invalid_format`,format:`starts_with`,prefix:t.prefix,input:n.value,inst:e,continue:!t.abort})}}),Lf=U(`$ZodCheckEndsWith`,(e,t)=>{Sf.init(e,t);let n=RegExp(`.*${ad(t.suffix)}$`);t.pattern??=n,e._zod.onattach.push(e=>{let t=e._zod.bag;t.patterns??=new Set,t.patterns.add(n)}),e._zod.check=n=>{n.value.endsWith(t.suffix)||n.issues.push({origin:`string`,code:`invalid_format`,format:`ends_with`,suffix:t.suffix,input:n.value,inst:e,continue:!t.abort})}}),Rf=U(`$ZodCheckOverwrite`,(e,t)=>{Sf.init(e,t),e._zod.check=e=>{e.value=t.tx(e.value)}}),zf=class{constructor(e=[]){this.content=[],this.indent=0,this&&(this.args=e)}indented(e){this.indent+=1,e(this),--this.indent}write(e){if(typeof e==`function`){e(this,{execution:`sync`}),e(this,{execution:`async`});return}let t=e.split(`
2`).filter(e=>e),n=Math.min(...t.map(e=>e.length-e.trimStart().length)),r=t.map(e=>e.slice(n)).map(e=>` `.repeat(this.indent*2)+e);for(let e of r)this.content.push(e)}compile(){let e=Function,t=this?.args,n=[...(this?.content??[``]).map(e=>`  ${e}`)];return new e(...t,n.join(`
3`))}},Bf={major:4,minor:4,patch:3},K=U(`$ZodType`,(e,t)=>{var n;e??={},e._zod.def=t,e._zod.bag=e._zod.bag||{},e._zod.version=Bf;let r=[...e._zod.def.checks??[]];e._zod.traits.has(`$ZodCheck`)&&r.unshift(e);for(let t of r)for(let n of t._zod.onattach)n(e);if(r.length===0)(n=e._zod).deferred??(n.deferred=[]),e._zod.deferred?.push(()=>{e._zod.run=e._zod.parse});else{let t=(e,t,n)=>{let r=gd(e),i;for(let a of t){if(a._zod.def.when){if(_d(e)||!a._zod.def.when(e))continue}else if(r)continue;let t=e.issues.length,o=a._zod.check(e);if(o instanceof Promise&&n?.async===!1)throw new Ru;if(i||o instanceof Promise)i=(i??Promise.resolve()).then(async()=>{await o,e.issues.length!==t&&(r||=gd(e,t))});else{if(e.issues.length===t)continue;r||=gd(e,t)}}return i?i.then(()=>e):e},n=(n,i,a)=>{if(gd(n))return n.aborted=!0,n;let o=t(i,r,a);if(o instanceof Promise){if(a.async===!1)throw new Ru;return o.then(t=>e._zod.parse(t,a))}return e._zod.parse(o,a)};e._zod.run=(i,a)=>{if(a.skipChecks)return e._zod.parse(i,a);if(a.direction===`backward`){let t=e._zod.parse({value:i.value,issues:[]},{...a,skipChecks:!0});return t instanceof Promise?t.then(e=>n(e,i,a)):n(t,i,a)}let o=e._zod.parse(i,a);if(o instanceof Promise){if(a.async===!1)throw new Ru;return o.then(e=>t(e,r,a))}return t(o,r,a)}}W(e,`~standard`,()=>({validate:t=>{try{let n=Nd(e,t);return n.success?{value:n.data}:{issues:n.error?.issues}}catch{return Fd(e,t).then(e=>e.success?{value:e.data}:{issues:e.error?.issues})}},vendor:`zod`,version:1}))}),Vf=U(`$ZodString`,(e,t)=>{K.init(e,t),e._zod.pattern=[...e?._zod.bag?.patterns??[]].pop()??gf(e._zod.bag),e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=String(n.value)}catch{}return typeof n.value==`string`||n.issues.push({expected:`string`,code:`invalid_type`,input:n.value,inst:e}),n}}),q=U(`$ZodStringFormat`,(e,t)=>{jf.init(e,t),Vf.init(e,t)}),Hf=U(`$ZodGUID`,(e,t)=>{t.pattern??=Zd,q.init(e,t)}),Uf=U(`$ZodUUID`,(e,t)=>{if(t.version){let e={v1:1,v2:2,v3:3,v4:4,v5:5,v6:6,v7:7,v8:8}[t.version];if(e===void 0)throw Error(`Invalid UUID version: "${t.version}"`);t.pattern??=Qd(e)}else t.pattern??=Qd();q.init(e,t)}),Wf=U(`$ZodEmail`,(e,t)=>{t.pattern??=$d,q.init(e,t)}),Gf=U(`$ZodURL`,(e,t)=>{q.init(e,t),e._zod.check=n=>{try{let r=n.value.trim();if(!t.normalize&&t.protocol?.source===lf.source&&!/^https?:\/\//i.test(r)){n.issues.push({code:`invalid_format`,format:`url`,note:`Invalid URL format`,input:n.value,inst:e,continue:!t.abort});return}let i=new URL(r);t.hostname&&(t.hostname.lastIndex=0,t.hostname.test(i.hostname)||n.issues.push({code:`invalid_format`,format:`url`,note:`Invalid hostname`,pattern:t.hostname.source,input:n.value,inst:e,continue:!t.abort})),t.protocol&&(t.protocol.lastIndex=0,t.protocol.test(i.protocol.endsWith(`:`)?i.protocol.slice(0,-1):i.protocol)||n.issues.push({code:`invalid_format`,format:`url`,note:`Invalid protocol`,pattern:t.protocol.source,input:n.value,inst:e,continue:!t.abort})),t.normalize?n.value=i.href:n.value=r;return}catch{n.issues.push({code:`invalid_format`,format:`url`,input:n.value,inst:e,continue:!t.abort})}}}),Kf=U(`$ZodEmoji`,(e,t)=>{t.pattern??=tf(),q.init(e,t)}),qf=U(`$ZodNanoID`,(e,t)=>{t.pattern??=Yd,q.init(e,t)}),Jf=U(`$ZodCUID`,(e,t)=>{t.pattern??=Wd,q.init(e,t)}),Yf=U(`$ZodCUID2`,(e,t)=>{t.pattern??=Gd,q.init(e,t)}),Xf=U(`$ZodULID`,(e,t)=>{t.pattern??=Kd,q.init(e,t)}),Zf=U(`$ZodXID`,(e,t)=>{t.pattern??=qd,q.init(e,t)}),Qf=U(`$ZodKSUID`,(e,t)=>{t.pattern??=Jd,q.init(e,t)}),$f=U(`$ZodISODateTime`,(e,t)=>{t.pattern??=hf(t),q.init(e,t)}),ep=U(`$ZodISODate`,(e,t)=>{t.pattern??=ff,q.init(e,t)}),tp=U(`$ZodISOTime`,(e,t)=>{t.pattern??=mf(t),q.init(e,t)}),np=U(`$ZodISODuration`,(e,t)=>{t.pattern??=Xd,q.init(e,t)}),rp=U(`$ZodIPv4`,(e,t)=>{t.pattern??=nf,q.init(e,t),e._zod.bag.format=`ipv4`}),ip=U(`$ZodIPv6`,(e,t)=>{t.pattern??=rf,q.init(e,t),e._zod.bag.format=`ipv6`,e._zod.check=n=>{try{new URL(`http://[${n.value}]`)}catch{n.issues.push({code:`invalid_format`,format:`ipv6`,input:n.value,inst:e,continue:!t.abort})}}}),ap=U(`$ZodCIDRv4`,(e,t)=>{t.pattern??=af,q.init(e,t)}),op=U(`$ZodCIDRv6`,(e,t)=>{t.pattern??=of,q.init(e,t),e._zod.check=n=>{let r=n.value.split(`/`);try{if(r.length!==2)throw Error();let[e,t]=r;if(!t)throw Error();let n=Number(t);if(`${n}`!==t||n<0||n>128)throw Error();new URL(`http://[${e}]`)}catch{n.issues.push({code:`invalid_format`,format:`cidrv6`,input:n.value,inst:e,continue:!t.abort})}}});function sp(e){if(e===``)return!0;if(/\s/.test(e)||e.length%4!=0)return!1;try{return atob(e),!0}catch{return!1}}var cp=U(`$ZodBase64`,(e,t)=>{t.pattern??=sf,q.init(e,t),e._zod.bag.contentEncoding=`base64`,e._zod.check=n=>{sp(n.value)||n.issues.push({code:`invalid_format`,format:`base64`,input:n.value,inst:e,continue:!t.abort})}});function lp(e){if(!cf.test(e))return!1;let t=e.replace(/[-_]/g,e=>e===`-`?`+`:`/`);return sp(t.padEnd(Math.ceil(t.length/4)*4,`=`))}var up=U(`$ZodBase64URL`,(e,t)=>{t.pattern??=cf,q.init(e,t),e._zod.bag.contentEncoding=`base64url`,e._zod.check=n=>{lp(n.value)||n.issues.push({code:`invalid_format`,format:`base64url`,input:n.value,inst:e,continue:!t.abort})}}),dp=U(`$ZodE164`,(e,t)=>{t.pattern??=uf,q.init(e,t)});function fp(e,t=null){try{let n=e.split(`.`);if(n.length!==3)return!1;let[r]=n;if(!r)return!1;let i=JSON.parse(atob(r));return!(`typ`in i&&i?.typ!==`JWT`||!i.alg||t&&(!(`alg`in i)||i.alg!==t))}catch{return!1}}var pp=U(`$ZodJWT`,(e,t)=>{q.init(e,t),e._zod.check=n=>{fp(n.value,t.alg)||n.issues.push({code:`invalid_format`,format:`jwt`,input:n.value,inst:e,continue:!t.abort})}}),mp=U(`$ZodNumber`,(e,t)=>{K.init(e,t),e._zod.pattern=e._zod.bag.pattern??vf,e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=Number(n.value)}catch{}let i=n.value;if(typeof i==`number`&&!Number.isNaN(i)&&Number.isFinite(i))return n;let a=typeof i==`number`?Number.isNaN(i)?`NaN`:Number.isFinite(i)?void 0:`Infinity`:void 0;return n.issues.push({expected:`number`,code:`invalid_type`,input:i,inst:e,...a?{received:a}:{}}),n}}),hp=U(`$ZodNumberFormat`,(e,t)=>{Df.init(e,t),mp.init(e,t)}),gp=U(`$ZodBoolean`,(e,t)=>{K.init(e,t),e._zod.pattern=yf,e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=!!n.value}catch{}let i=n.value;return typeof i==`boolean`||n.issues.push({expected:`boolean`,code:`invalid_type`,input:i,inst:e}),n}}),_p=U(`$ZodUnknown`,(e,t)=>{K.init(e,t),e._zod.parse=e=>e}),vp=U(`$ZodNever`,(e,t)=>{K.init(e,t),e._zod.parse=(t,n)=>(t.issues.push({expected:`never`,code:`invalid_type`,input:t.value,inst:e}),t)});
vendor: 4,137 bytes, lines 3-46
3function yp(e,t,n){e.issues.length&&t.issues.push(...vd(n,e.issues)),t.value[n]=e.value}var bp=U(`$ZodArray`,(e,t)=>{K.init(e,t),e._zod.parse=(n,r)=>{let i=n.value;if(!Array.isArray(i))return n.issues.push({expected:`array`,code:`invalid_type`,input:i,inst:e}),n;n.value=Array(i.length);let a=[];for(let e=0;e<i.length;e++){let o=i[e],s=t.element._zod.run({value:o,issues:[]},r);s instanceof Promise?a.push(s.then(t=>yp(t,n,e))):yp(s,n,e)}return a.length?Promise.all(a).then(()=>n):n}});function xp(e,t,n,r,i,a){let o=n in r;if(e.issues.length){if(i&&a&&!o)return;t.issues.push(...vd(n,e.issues))}if(!o&&!i){e.issues.length||t.issues.push({code:`invalid_type`,expected:`nonoptional`,input:void 0,path:[n]});return}e.value===void 0?o&&(t.value[n]=void 0):t.value[n]=e.value}function Sp(e){let t=Object.keys(e.shape);for(let n of t)if(!e.shape?.[n]?._zod?.traits?.has(`$ZodType`))throw Error(`Invalid element at key "${n}": expected a Zod schema`);let n=sd(e.shape);return{...e,keys:t,keySet:new Set(t),numKeys:t.length,optionalKeys:new Set(n)}}function Cp(e,t,n,r,i,a){let o=[],s=i.keySet,c=i.catchall._zod,l=c.def.type,u=c.optin===`optional`,d=c.optout===`optional`;for(let i in t){if(i===`__proto__`||s.has(i))continue;if(l===`never`){o.push(i);continue}let a=c.run({value:t[i],issues:[]},r);a instanceof Promise?e.push(a.then(e=>xp(e,n,i,t,u,d))):xp(a,n,i,t,u,d)}return o.length&&n.issues.push({code:`unrecognized_keys`,keys:o,input:t,inst:a}),e.length?Promise.all(e).then(()=>n):n}var wp=U(`$ZodObject`,(e,t)=>{if(K.init(e,t),!Object.getOwnPropertyDescriptor(t,`shape`)?.get){let e=t.shape;Object.defineProperty(t,"shape",{get:()=>{let n={...e};return Object.defineProperty(t,"shape",{value:n}),n}})}let n=Wu(()=>Sp(t));W(e._zod,`propValues`,()=>{let e=t.shape,n={};for(let t in e){let r=e[t]._zod;if(r.values){n[t]??(n[t]=new Set);for(let e of r.values)n[t].add(e)}}return n});let r=ed,i=t.catchall,a;e._zod.parse=(t,o)=>{a??=n.value;let s=t.value;if(!r(s))return t.issues.push({expected:`object`,code:`invalid_type`,input:s,inst:e}),t;t.value={};let c=[],l=a.shape;for(let e of a.keys){let n=l[e],r=n._zod.optin===`optional`,i=n._zod.optout===`optional`,a=n._zod.run({value:s[e],issues:[]},o);a instanceof Promise?c.push(a.then(n=>xp(n,t,e,s,r,i))):xp(a,t,e,s,r,i)}return i?Cp(c,s,t,o,n.value,e):c.length?Promise.all(c).then(()=>t):t}}),Tp=U(`$ZodObjectJIT`,(e,t)=>{wp.init(e,t);let n=e._zod.parse,r=Wu(()=>Sp(t)),i=e=>{let t=new zf([`shape`,`payload`,`ctx`]),n=r.value,i=e=>{let t=Zu(e);return`shape[${t}]._zod.run({ value: input[${t}], issues: [] }, ctx)`};t.write(`const input = payload.value;`);let a=Object.create(null),o=0;for(let e of n.keys)a[e]=`key_${o++}`;t.write(`const newResult = {};`);for(let r of n.keys){let n=a[r],o=Zu(r),s=e[r],c=s?._zod?.optin===`optional`,l=s?._zod?.optout===`optional`;t.write(`const ${n} = ${i(r)};`),c&&l?t.write(`
4        if (${n}.issues.length) {
5          if (${o} in input) {
6            payload.issues = payload.issues.concat(${n}.issues.map(iss => ({
7              ...iss,
8              path: iss.path ? [${o}, ...iss.path] : [${o}]
9            })));
10          }
11        }
12        
13        if (${n}.value === undefined) {
14          if (${o} in input) {
15            newResult[${o}] = undefined;
16          }
17        } else {
18          newResult[${o}] = ${n}.value;
19        }
20        
21      `):c?t.write(`
22        if (${n}.issues.length) {
23          payload.issues = payload.issues.concat(${n}.issues.map(iss => ({
24            ...iss,
25            path: iss.path ? [${o}, ...iss.path] : [${o}]
26          })));
27        }
28        
29        if (${n}.value === undefined) {
30          if (${o} in input) {
31            newResult[${o}] = undefined;
32          }
33        } else {
34          newResult[${o}] = ${n}.value;
35        }
36        
37      `):t.write(`
38        const ${n}_present = ${o} in input;
39        if (${n}.issues.length) {
40          payload.issues = payload.issues.concat(${n}.issues.map(iss => ({
41            ...iss,
42            path: iss.path ? [${o}, ...iss.path] : [${o}]
43          })));
44        }
45        if (!${n}_present && !${n}.issues.length) {
46          payload.issues.push({
47            code: "invalid_type",
48            expected: "nonoptional",
49            input: undefined,
50            path: [${o}]
51          });
52        }
53
54        if (${n}_present) {
55          if (${n}.value === undefined) {
56            newResult[${o}] = undefined;
57          } else {
58            newResult[${o}] = ${n}.value;
59          }
60        }
61
62      `)}t.write(`payload.value = newResult;`),t.write(`return payload;`);let s=t.compile();return(t,n)=>s(e,t,n)},a,o=ed,s=!Bu.jitless,c=s&&td.value,l=t.catchall,u;e._zod.parse=(d,f)=>{u??=r.value;let p=d.value;return o(p)?s&&c&&f?.async===!1&&f.jitless!==!0?(a||=i(t.shape),d=a(d,f),l?Cp([],p,d,f,u,e):d):n(d,f):(d.issues.push({expected:`object`,code:`invalid_type`,input:p,inst:e}),d)}});function Ep(e,t,n,r){for(let n of e)if(n.issues.length===0)return t.value=n.value,t;let i=e.filter(e=>!gd(e));return i.length===1?(t.value=i[0].value,i[0]):(t.issues.push({code:`invalid_union`,input:t.value,inst:n,errors:e.map(e=>e.issues.map(e=>bd(e,r,Vu())))}),t)}var Dp=U(`$ZodUnion`,(e,t)=>{K.init(e,t),W(e._zod,`optin`,()=>t.options.some(e=>e._zod.optin===`optional`)?`optional`:void 0),W(e._zod,`optout`,()=>t.options.some(e=>e._zod.optout===`optional`)?`optional`:void 0),W(e._zod,`values`,()=>{if(t.options.every(e=>e._zod.values))return new Set(t.options.flatMap(e=>Array.from(e._zod.values)))}),W(e._zod,`pattern`,()=>{if(t.options.every(e=>e._zod.pattern)){let e=t.options.map(e=>e._zod.pattern);return RegExp(`^(${e.map(e=>Ku(e.source)).join(`|`)})$`)}});let n=t.options.length===1?t.options[0]._zod.run:null;e._zod.parse=(r,i)=>{if(n)return n(r,i);let a=!1,o=[];for(let e of t.options){let t=e._zod.run({value:r.value,issues:[]},i);if(t instanceof Promise)o.push(t),a=!0;else{if(t.issues.length===0)return t;o.push(t)}}return a?Promise.all(o).then(t=>Ep(t,r,e,i)):Ep(o,r,e,i)}}),Op=U(`$ZodIntersection`,(e,t)=>{K.init(e,t),e._zod.parse=(e,n)=>{let r=e.value,i=t.left._zod.run({value:r,issues:[]},n),a=t.right._zod.run({value:r,issues:[]},n);return i instanceof Promise||a instanceof Promise?Promise.all([i,a]).then(([t,n])=>Ap(e,t,n)):Ap(e,i,a)}});function kp(e,t){if(e===t||e instanceof Date&&t instanceof Date&&+e==+t)return{valid:!0,data:e};if(nd(e)&&nd(t)){let n=Object.keys(t),r=Object.keys(e).filter(e=>n.indexOf(e)!==-1),i={...e,...t};for(let n of r){let r=kp(e[n],t[n]);if(!r.valid)return{valid:!1,mergeErrorPath:[n,...r.mergeErrorPath]};i[n]=r.data}return{valid:!0,data:i}}if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return{valid:!1,mergeErrorPath:[]};let n=[];for(let r=0;r<e.length;r++){let i=e[r],a=t[r],o=kp(i,a);if(!o.valid)return{valid:!1,mergeErrorPath:[r,...o.mergeErrorPath]};n.push(o.data)}return{valid:!0,data:n}}return{valid:!1,mergeErrorPath:[]}}function Ap(e,t,n){let r=new Map,i;for(let n of t.issues)if(n.code===`unrecognized_keys`){i??=n;for(let e of n.keys)r.has(e)||r.set(e,{}),r.get(e).l=!0}else e.issues.push(n);for(let t of n.issues)if(t.code===`unrecognized_keys`)for(let e of t.keys)r.has(e)||r.set(e,{}),r.get(e).r=!0;else e.issues.push(t);let a=[...r].filter(([,e])=>e.l&&e.r).map(([e])=>e);if(a.length&&i&&e.issues.push({...i,keys:a}),gd(e))return e;let o=kp(t.value,n.value);if(!o.valid)throw Error(`Unmergable intersection. Error path: ${JSON.stringify(o.mergeErrorPath)}`);return e.value=o.data,e}var jp=U(`$ZodTuple`,(e,t)=>{K.init(e,t);let n=t.items;e._zod.parse=(r,i)=>{let a=r.value;if(!Array.isArray(a))return r.issues.push({input:a,inst:e,expected:`tuple`,code:`invalid_type`}),r;r.value=[];let o=[],s=Mp(n,`optin`),c=Mp(n,`optout`);if(!t.rest){if(a.length<s)return r.issues.push({code:`too_small`,minimum:s,inclusive:!0,input:a,inst:e,origin:`array`}),r;a.length>n.length&&r.issues.push({code:`too_big`,maximum:n.length,inclusive:!0,input:a,inst:e,origin:`array`})}let l=Array(n.length);for(let e=0;e<n.length;e++){let t=n[e]._zod.run({value:a[e],issues:[]},i);t instanceof Promise?o.push(t.then(t=>{l[e]=t})):l[e]=t}if(t.rest){let e=n.length-1,s=a.slice(n.length);for(let n of s){e++;let a=t.rest._zod.run({value:n,issues:[]},i);a instanceof Promise?o.push(a.then(t=>Np(t,r,e))):Np(a,r,e)}}return o.length?Promise.all(o).then(()=>Pp(l,r,n,a,c)):Pp(l,r,n,a,c)}});function Mp(e,t){for(let n=e.length-1;n>=0;n--)if(e[n]._zod[t]!==`optional`)return n+1;return 0}
vendor: 4,227 bytes, line 62
62function Np(e,t,n){e.issues.length&&t.issues.push(...vd(n,e.issues)),t.value[n]=e.value}function Pp(e,t,n,r,i){for(let a=0;a<n.length;a++){let n=e[a],o=a<r.length;if(n.issues.length){if(!o&&a>=i){t.value.length=a;break}t.issues.push(...vd(a,n.issues))}t.value[a]=n.value}for(let e=t.value.length-1;e>=r.length&&n[e]._zod.optout===`optional`&&t.value[e]===void 0;e--)t.value.length=e;return t}var Fp=U(`$ZodRecord`,(e,t)=>{K.init(e,t),e._zod.parse=(n,r)=>{let i=n.value;if(!nd(i))return n.issues.push({expected:`record`,code:`invalid_type`,input:i,inst:e}),n;let a=[],o=t.keyType._zod.values;if(o){n.value={};let s=new Set;for(let c of o)if(typeof c==`string`||typeof c==`number`||typeof c==`symbol`){s.add(typeof c==`number`?c.toString():c);let o=t.keyType._zod.run({value:c,issues:[]},r);if(o instanceof Promise)throw Error(`Async schemas not supported in object keys currently`);if(o.issues.length){n.issues.push({code:`invalid_key`,origin:`record`,issues:o.issues.map(e=>bd(e,r,Vu())),input:c,path:[c],inst:e});continue}let l=o.value,u=t.valueType._zod.run({value:i[c],issues:[]},r);u instanceof Promise?a.push(u.then(e=>{e.issues.length&&n.issues.push(...vd(c,e.issues)),n.value[l]=e.value})):(u.issues.length&&n.issues.push(...vd(c,u.issues)),n.value[l]=u.value)}let c;for(let e in i)s.has(e)||(c??=[],c.push(e));c&&c.length>0&&n.issues.push({code:`unrecognized_keys`,input:i,inst:e,keys:c})}else{n.value={};for(let o of Reflect.ownKeys(i)){if(o===`__proto__`||!Object.prototype.propertyIsEnumerable.call(i,o))continue;let s=t.keyType._zod.run({value:o,issues:[]},r);if(s instanceof Promise)throw Error(`Async schemas not supported in object keys currently`);if(typeof o==`string`&&vf.test(o)&&s.issues.length){let e=t.keyType._zod.run({value:Number(o),issues:[]},r);if(e instanceof Promise)throw Error(`Async schemas not supported in object keys currently`);e.issues.length===0&&(s=e)}if(s.issues.length){t.mode===`loose`?n.value[o]=i[o]:n.issues.push({code:`invalid_key`,origin:`record`,issues:s.issues.map(e=>bd(e,r,Vu())),input:o,path:[o],inst:e});continue}let c=t.valueType._zod.run({value:i[o],issues:[]},r);c instanceof Promise?a.push(c.then(e=>{e.issues.length&&n.issues.push(...vd(o,e.issues)),n.value[s.value]=e.value})):(c.issues.length&&n.issues.push(...vd(o,c.issues)),n.value[s.value]=c.value)}}return a.length?Promise.all(a).then(()=>n):n}}),Ip=U(`$ZodEnum`,(e,t)=>{K.init(e,t);let n=Hu(t.entries),r=new Set(n);e._zod.values=r,e._zod.pattern=RegExp(`^(${n.filter(e=>id.has(typeof e)).map(e=>typeof e==`string`?ad(e):e.toString()).join(`|`)})$`),e._zod.parse=(t,i)=>{let a=t.value;return r.has(a)||t.issues.push({code:`invalid_value`,values:n,input:a,inst:e}),t}}),Lp=U(`$ZodLiteral`,(e,t)=>{if(K.init(e,t),t.values.length===0)throw Error(`Cannot create literal schema with no valid values`);let n=new Set(t.values);e._zod.values=n,e._zod.pattern=RegExp(`^(${t.values.map(e=>typeof e==`string`?ad(e):e?ad(e.toString()):String(e)).join(`|`)})$`),e._zod.parse=(r,i)=>{let a=r.value;return n.has(a)||r.issues.push({code:`invalid_value`,values:t.values,input:a,inst:e}),r}}),Rp=U(`$ZodTransform`,(e,t)=>{K.init(e,t),e._zod.optin=`optional`,e._zod.parse=(n,r)=>{if(r.direction===`backward`)throw new zu(e.constructor.name);let i=t.transform(n.value,n);if(r.async)return(i instanceof Promise?i:Promise.resolve(i)).then(e=>(n.value=e,n.fallback=!0,n));if(i instanceof Promise)throw new Ru;return n.value=i,n.fallback=!0,n}});function zp(e,t){return t===void 0&&(e.issues.length||e.fallback)?{issues:[],value:void 0}:e}var Bp=U(`$ZodOptional`,(e,t)=>{K.init(e,t),e._zod.optin=`optional`,e._zod.optout=`optional`,W(e._zod,`values`,()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,void 0]):void 0),W(e._zod,`pattern`,()=>{let e=t.innerType._zod.pattern;return e?RegExp(`^(${Ku(e.source)})?$`):void 0}),e._zod.parse=(e,n)=>{if(t.innerType._zod.optin===`optional`){let r=e.value,i=t.innerType._zod.run(e,n);return i instanceof Promise?i.then(e=>zp(e,r)):zp(i,r)}return e.value===void 0?e:t.innerType._zod.run(e,n)}}),Vp=U(`$ZodExactOptional`,(e,t)=>{Bp.init(e,t),W(e._zod,`values`,()=>t.innerType._zod.values),W(e._zod,`pattern`,()=>t.innerType._zod.pattern),e._zod.parse=(e,n)=>t.innerType._zod.run(e,n)}
vendor: 5,570 bytes, line 62
62),Hp=U(`$ZodNullable`,(e,t)=>{K.init(e,t),W(e._zod,`optin`,()=>t.innerType._zod.optin),W(e._zod,`optout`,()=>t.innerType._zod.optout),W(e._zod,`pattern`,()=>{let e=t.innerType._zod.pattern;return e?RegExp(`^(${Ku(e.source)}|null)$`):void 0}),W(e._zod,`values`,()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,null]):void 0),e._zod.parse=(e,n)=>e.value===null?e:t.innerType._zod.run(e,n)}),Up=U(`$ZodDefault`,(e,t)=>{K.init(e,t),e._zod.optin=`optional`,W(e._zod,`values`,()=>t.innerType._zod.values),e._zod.parse=(e,n)=>{if(n.direction===`backward`)return t.innerType._zod.run(e,n);if(e.value===void 0)return e.value=t.defaultValue,e;let r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(e=>Wp(e,t)):Wp(r,t)}});function Wp(e,t){return e.value===void 0&&(e.value=t.defaultValue),e}var Gp=U(`$ZodPrefault`,(e,t)=>{K.init(e,t),e._zod.optin=`optional`,W(e._zod,`values`,()=>t.innerType._zod.values),e._zod.parse=(e,n)=>(n.direction===`backward`||e.value===void 0&&(e.value=t.defaultValue),t.innerType._zod.run(e,n))}),Kp=U(`$ZodNonOptional`,(e,t)=>{K.init(e,t),W(e._zod,`values`,()=>{let e=t.innerType._zod.values;return e?new Set([...e].filter(e=>e!==void 0)):void 0}),e._zod.parse=(n,r)=>{let i=t.innerType._zod.run(n,r);return i instanceof Promise?i.then(t=>qp(t,e)):qp(i,e)}});function qp(e,t){return!e.issues.length&&e.value===void 0&&e.issues.push({code:`invalid_type`,expected:`nonoptional`,input:e.value,inst:t}),e}var Jp=U(`$ZodCatch`,(e,t)=>{K.init(e,t),e._zod.optin=`optional`,W(e._zod,`optout`,()=>t.innerType._zod.optout),W(e._zod,`values`,()=>t.innerType._zod.values),e._zod.parse=(e,n)=>{if(n.direction===`backward`)return t.innerType._zod.run(e,n);let r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(r=>(e.value=r.value,r.issues.length&&(e.value=t.catchValue({...e,error:{issues:r.issues.map(e=>bd(e,n,Vu()))},input:e.value}),e.issues=[],e.fallback=!0),e)):(e.value=r.value,r.issues.length&&(e.value=t.catchValue({...e,error:{issues:r.issues.map(e=>bd(e,n,Vu()))},input:e.value}),e.issues=[],e.fallback=!0),e)}}),Yp=U(`$ZodPipe`,(e,t)=>{K.init(e,t),W(e._zod,`values`,()=>t.in._zod.values),W(e._zod,`optin`,()=>t.in._zod.optin),W(e._zod,`optout`,()=>t.out._zod.optout),W(e._zod,`propValues`,()=>t.in._zod.propValues),e._zod.parse=(e,n)=>{if(n.direction===`backward`){let r=t.out._zod.run(e,n);return r instanceof Promise?r.then(e=>Xp(e,t.in,n)):Xp(r,t.in,n)}let r=t.in._zod.run(e,n);return r instanceof Promise?r.then(e=>Xp(e,t.out,n)):Xp(r,t.out,n)}});function Xp(e,t,n){return e.issues.length?(e.aborted=!0,e):t._zod.run({value:e.value,issues:e.issues,fallback:e.fallback},n)}var Zp=U(`$ZodReadonly`,(e,t)=>{K.init(e,t),W(e._zod,`propValues`,()=>t.innerType._zod.propValues),W(e._zod,`values`,()=>t.innerType._zod.values),W(e._zod,`optin`,()=>t.innerType?._zod?.optin),W(e._zod,`optout`,()=>t.innerType?._zod?.optout),e._zod.parse=(e,n)=>{if(n.direction===`backward`)return t.innerType._zod.run(e,n);let r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(Qp):Qp(r)}});function Qp(e){return e.value=Object.freeze(e.value),e}var $p=U(`$ZodCustom`,(e,t)=>{Sf.init(e,t),K.init(e,t),e._zod.parse=(e,t)=>e,e._zod.check=n=>{let r=n.value,i=t.fn(r);if(i instanceof Promise)return i.then(t=>em(t,n,r,e));em(i,n,r,e)}});function em(e,t,n,r){if(!e){let e={code:`custom`,input:n,inst:r,path:[...r._zod.def.path??[]],continue:!r._zod.def.abort};r._zod.def.params&&(e.params=r._zod.def.params),t.issues.push(Sd(e))}}var tm,nm=class{constructor(){this._map=new WeakMap,this._idmap=new Map}add(e,...t){let n=t[0];return this._map.set(e,n),n&&typeof n==`object`&&`id`in n&&this._idmap.set(n.id,e),this}clear(){return this._map=new WeakMap,this._idmap=new Map,this}remove(e){let t=this._map.get(e);return t&&typeof t==`object`&&`id`in t&&this._idmap.delete(t.id),this._map.delete(e),this}get(e){let t=e._zod.parent;if(t){let n={...this.get(t)??{}};delete n.id;let r={...n,...this._map.get(e)};return Object.keys(r).length?r:void 0}return this._map.get(e)}has(e){return this._map.has(e)}};function rm(){return new nm}(tm=globalThis).__zod_globalRegistry??(tm.__zod_globalRegistry=rm());var im=globalThis.__zod_globalRegistry;function am(e,t){return new e({type:`string`,...G(t)})}function om(e,t){return new e({type:`string`,format:`email`,check:`string_format`,abort:!1,...G(t)})}function sm(e,t){return new e({type:`string`,format:`guid`,check:`string_format`,abort:!1,...G(t)})}function cm(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,...G(t)})}function lm(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v4`,...G(t)})}function um(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v6`,...G(t)})}function dm(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v7`,...G(t)})}function fm(e,t){return new e({type:`string`,format:`url`,check:`string_format`,abort:!1,...G(t)})}function pm(e,t){return new e({type:`string`,format:`emoji`,check:`string_format`,abort:!1,...G(t)})}function mm(e,t){return new e({type:`string`,format:`nanoid`,check:`string_format`,abort:!1,...G(t)})}function hm(e,t){return new e({type:`string`,format:`cuid`,check:`string_format`,abort:!1,...G(t)})}function gm(e,t){return new e({type:`string`,format:`cuid2`,check:`string_format`,abort:!1,...G(t)})}function _m(e,t){return new e({type:`string`,format:`ulid`,check:`string_format`,abort:!1,...G(t)})}function vm(e,t){return new e({type:`string`,format:`xid`,check:`string_format`,abort:!1,...G(t)})}
vendor: 3,602 bytes, line 62
62function ym(e,t){return new e({type:`string`,format:`ksuid`,check:`string_format`,abort:!1,...G(t)})}function bm(e,t){return new e({type:`string`,format:`ipv4`,check:`string_format`,abort:!1,...G(t)})}function xm(e,t){return new e({type:`string`,format:`ipv6`,check:`string_format`,abort:!1,...G(t)})}function Sm(e,t){return new e({type:`string`,format:`cidrv4`,check:`string_format`,abort:!1,...G(t)})}function Cm(e,t){return new e({type:`string`,format:`cidrv6`,check:`string_format`,abort:!1,...G(t)})}function wm(e,t){return new e({type:`string`,format:`base64`,check:`string_format`,abort:!1,...G(t)})}function Tm(e,t){return new e({type:`string`,format:`base64url`,check:`string_format`,abort:!1,...G(t)})}function Em(e,t){return new e({type:`string`,format:`e164`,check:`string_format`,abort:!1,...G(t)})}function Dm(e,t){return new e({type:`string`,format:`jwt`,check:`string_format`,abort:!1,...G(t)})}function Om(e,t){return new e({type:`string`,format:`datetime`,check:`string_format`,offset:!1,local:!1,precision:null,...G(t)})}function km(e,t){return new e({type:`string`,format:`date`,check:`string_format`,...G(t)})}function Am(e,t){return new e({type:`string`,format:`time`,check:`string_format`,precision:null,...G(t)})}function jm(e,t){return new e({type:`string`,format:`duration`,check:`string_format`,...G(t)})}function Mm(e,t){return new e({type:`number`,checks:[],...G(t)})}function Nm(e,t){return new e({type:`number`,check:`number_format`,abort:!1,format:`safeint`,...G(t)})}function Pm(e,t){return new e({type:`boolean`,...G(t)})}function Fm(e){return new e({type:`unknown`})}function Im(e,t){return new e({type:`never`,...G(t)})}function Lm(e,t){return new wf({check:`less_than`,...G(t),value:e,inclusive:!1})}function Rm(e,t){return new wf({check:`less_than`,...G(t),value:e,inclusive:!0})}function zm(e,t){return new Tf({check:`greater_than`,...G(t),value:e,inclusive:!1})}function Bm(e,t){return new Tf({check:`greater_than`,...G(t),value:e,inclusive:!0})}function Vm(e,t){return new Ef({check:`multiple_of`,...G(t),value:e})}function Hm(e,t){return new Of({check:`max_length`,...G(t),maximum:e})}function Um(e,t){return new kf({check:`min_length`,...G(t),minimum:e})}function Wm(e,t){return new Af({check:`length_equals`,...G(t),length:e})}function Gm(e,t){return new Mf({check:`string_format`,format:`regex`,...G(t),pattern:e})}function Km(e){return new Nf({check:`string_format`,format:`lowercase`,...G(e)})}function qm(e){return new Pf({check:`string_format`,format:`uppercase`,...G(e)})}function Jm(e,t){return new Ff({check:`string_format`,format:`includes`,...G(t),includes:e})}function Ym(e,t){return new If({check:`string_format`,format:`starts_with`,...G(t),prefix:e})}function Xm(e,t){return new Lf({check:`string_format`,format:`ends_with`,...G(t),suffix:e})}function Zm(e){return new Rf({check:`overwrite`,tx:e})}function Qm(e){return Zm(t=>t.normalize(e))}function $m(){return Zm(e=>e.trim())}function eh(){return Zm(e=>e.toLowerCase())}function th(){return Zm(e=>e.toUpperCase())}function nh(){return Zm(e=>Qu(e))}function rh(e,t,n){return new e({type:`array`,element:t,...G(n)})}function ih(e,t,n){return new e({type:`custom`,check:`custom`,fn:t,...G(n)})}function ah(e,t){let n=oh(t=>(t.addIssue=e=>{if(typeof e==`string`)t.issues.push(Sd(e,t.value,n._zod.def));else{let r=e;r.fatal&&(r.continue=!1),r.code??=`custom`,r.input??=t.value,r.inst??=n,r.continue??=!n._zod.def.abort,t.issues.push(Sd(r))}},e(t.value,t)),t);return n}function oh(e,t){let n=new Sf({check:`custom`,...G(t)});return n._zod.check=e,n}function sh(e){let t=e?.target??`draft-2020-12`;
vendor: 13,235 bytes, lines 62-64
62return t===`draft-4`&&(t=`draft-04`),t===`draft-7`&&(t=`draft-07`),{processors:e.processors??{},metadataRegistry:e?.metadata??im,target:t,unrepresentable:e?.unrepresentable??`throw`,override:e?.override??(()=>{}),io:e?.io??`output`,counter:0,seen:new Map,cycles:e?.cycles??`ref`,reused:e?.reused??`inline`,external:e?.external??void 0}}function J(e,t,n={path:[],schemaPath:[]}){var r;let i=e._zod.def,a=t.seen.get(e);if(a)return a.count++,n.schemaPath.includes(e)&&(a.cycle=n.path),a.schema;let o={schema:{},count:1,cycle:void 0,path:n.path};t.seen.set(e,o);let s=e._zod.toJSONSchema?.();if(s)o.schema=s;else{let r={...n,schemaPath:[...n.schemaPath,e],path:n.path};if(e._zod.processJSONSchema)e._zod.processJSONSchema(t,o.schema,r);else{let n=o.schema,a=t.processors[i.type];if(!a)throw Error(`[toJSONSchema]: Non-representable type encountered: ${i.type}`);a(e,t,n,r)}let a=e._zod.parent;a&&(o.ref||=a,J(a,t,r),t.seen.get(a).isParent=!0)}let c=t.metadataRegistry.get(e);return c&&Object.assign(o.schema,c),t.io===`input`&&uh(e)&&(delete o.schema.examples,delete o.schema.default),t.io===`input`&&`_prefault`in o.schema&&((r=o.schema).default??(r.default=o.schema._prefault)),delete o.schema._prefault,t.seen.get(e).schema}function ch(e,t){let n=e.seen.get(t);if(!n)throw Error(`Unprocessed schema. This is a bug in Zod.`);let r=new Map;for(let t of e.seen.entries()){let n=e.metadataRegistry.get(t[0])?.id;if(n){let e=r.get(n);if(e&&e!==t[0])throw Error(`Duplicate schema id "${n}" detected during JSON Schema conversion. Two different schemas cannot share the same id when converted together.`);r.set(n,t[0])}}let i=t=>{let r=e.target===`draft-2020-12`?`$defs`:`definitions`;if(e.external){let n=e.external.registry.get(t[0])?.id,i=e.external.uri??(e=>e);if(n)return{ref:i(n)};let a=t[1].defId??t[1].schema.id??`schema${e.counter++}`;return t[1].defId=a,{defId:a,ref:`${i(`__shared`)}#/${r}/${a}`}}if(t[1]===n)return{ref:`#`};let i=`#/${r}/`,a=t[1].schema.id??`__schema${e.counter++}`;return{defId:a,ref:i+a}},a=e=>{if(e[1].schema.$ref)return;let t=e[1],{ref:n,defId:r}=i(e);t.def={...t.schema},r&&(t.defId=r);let a=t.schema;for(let e in a)delete a[e];a.$ref=n};if(e.cycles===`throw`)for(let t of e.seen.entries()){let e=t[1];if(e.cycle)throw Error(`Cycle detected: #/${e.cycle?.join(`/`)}/<root>
63
64Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`)}for(let n of e.seen.entries()){let r=n[1];if(t===n[0]){a(n);continue}if(e.external){let r=e.external.registry.get(n[0])?.id;if(t!==n[0]&&r){a(n);continue}}if(e.metadataRegistry.get(n[0])?.id){a(n);continue}if(r.cycle){a(n);continue}if(r.count>1&&e.reused===`ref`){a(n);continue}}}function lh(e,t){let n=e.seen.get(t);if(!n)throw Error(`Unprocessed schema. This is a bug in Zod.`);let r=t=>{let n=e.seen.get(t);if(n.ref===null)return;let i=n.def??n.schema,a={...i},o=n.ref;if(n.ref=null,o){r(o);let n=e.seen.get(o),s=n.schema;if(s.$ref&&(e.target===`draft-07`||e.target===`draft-04`||e.target===`openapi-3.0`)?(i.allOf=i.allOf??[],i.allOf.push(s)):Object.assign(i,s),Object.assign(i,a),t._zod.parent===o)for(let e in i)e===`$ref`||e===`allOf`||e in a||delete i[e];if(s.$ref&&n.def)for(let e in i)e===`$ref`||e===`allOf`||e in n.def&&JSON.stringify(i[e])===JSON.stringify(n.def[e])&&delete i[e]}let s=t._zod.parent;if(s&&s!==o){r(s);let t=e.seen.get(s);if(t?.schema.$ref&&(i.$ref=t.schema.$ref,t.def))for(let e in i)e===`$ref`||e===`allOf`||e in t.def&&JSON.stringify(i[e])===JSON.stringify(t.def[e])&&delete i[e]}e.override({zodSchema:t,jsonSchema:i,path:n.path??[]})};for(let t of[...e.seen.entries()].reverse())r(t[0]);let i={};if(e.target===`draft-2020-12`?i.$schema=`https://json-schema.org/draft/2020-12/schema`:e.target===`draft-07`?i.$schema=`http://json-schema.org/draft-07/schema#`:e.target===`draft-04`?i.$schema=`http://json-schema.org/draft-04/schema#`:e.target,e.external?.uri){let n=e.external.registry.get(t)?.id;if(!n)throw Error("Schema is missing an `id` property");i.$id=e.external.uri(n)}Object.assign(i,n.def??n.schema);let a=e.metadataRegistry.get(t)?.id;a!==void 0&&i.id===a&&delete i.id;let o=e.external?.defs??{};for(let t of e.seen.entries()){let e=t[1];e.def&&e.defId&&(e.def.id===e.defId&&delete e.def.id,o[e.defId]=e.def)}e.external||Object.keys(o).length>0&&(e.target===`draft-2020-12`?i.$defs=o:i.definitions=o);try{let n=JSON.parse(JSON.stringify(i));return Object.defineProperty(n,"~standard",{value:{...t[`~standard`],jsonSchema:{input:fh(t,`input`,e.processors),output:fh(t,`output`,e.processors)}},enumerable:!1,writable:!1}),n}catch{throw Error(`Error converting schema to JSON.`)}}function uh(e,t){let n=t??{seen:new Set};if(n.seen.has(e))return!1;n.seen.add(e);let r=e._zod.def;if(r.type===`transform`)return!0;if(r.type===`array`)return uh(r.element,n);if(r.type===`set`)return uh(r.valueType,n);if(r.type===`lazy`)return uh(r.getter(),n);if(r.type===`promise`||r.type===`optional`||r.type===`nonoptional`||r.type===`nullable`||r.type===`readonly`||r.type==="default"||r.type===`prefault`)return uh(r.innerType,n);if(r.type===`intersection`)return uh(r.left,n)||uh(r.right,n);if(r.type===`record`||r.type===`map`)return uh(r.keyType,n)||uh(r.valueType,n);if(r.type===`pipe`)return e._zod.traits.has(`$ZodCodec`)?!0:uh(r.in,n)||uh(r.out,n);if(r.type===`object`){for(let e in r.shape)if(uh(r.shape[e],n))return!0;return!1}if(r.type===`union`){for(let e of r.options)if(uh(e,n))return!0;return!1}if(r.type===`tuple`){for(let e of r.items)if(uh(e,n))return!0;return!!(r.rest&&uh(r.rest,n))}return!1}var dh=(e,t={})=>n=>{let r=sh({...n,processors:t});return J(e,r),ch(r,e),lh(r,e)},fh=(e,t,n={})=>r=>{let{libraryOptions:i,target:a}=r??{},o=sh({...i??{},target:a,io:t,processors:n});return J(e,o),ch(o,e),lh(o,e)},ph={guid:`uuid`,url:`uri`,datetime:`date-time`,json_string:`json-string`,regex:``},mh=(e,t,n,r)=>{let i=n;i.type=`string`;let{minimum:a,maximum:o,format:s,patterns:c,contentEncoding:l}=e._zod.bag;if(typeof a==`number`&&(i.minLength=a),typeof o==`number`&&(i.maxLength=o),s&&(i.format=ph[s]??s,i.format===``&&delete i.format,s===`time`&&delete i.format),l&&(i.contentEncoding=l),c&&c.size>0){let e=[...c];e.length===1?i.pattern=e[0].source:e.length>1&&(i.allOf=[...e.map(e=>({...t.target===`draft-07`||t.target===`draft-04`||t.target===`openapi-3.0`?{type:`string`}:{},pattern:e.source}))])}},hh=(e,t,n,r)=>{let i=n,{minimum:a,maximum:o,format:s,multipleOf:c,exclusiveMaximum:l,exclusiveMinimum:u}=e._zod.bag;typeof s==`string`&&s.includes(`int`)?i.type=`integer`:i.type=`number`;let d=typeof u==`number`&&u>=(a??-1/0),f=typeof l==`number`&&l<=(o??1/0),p=t.target===`draft-04`||t.target===`openapi-3.0`;d?p?(i.minimum=u,i.exclusiveMinimum=!0):i.exclusiveMinimum=u:typeof a==`number`&&(i.minimum=a),f?p?(i.maximum=l,i.exclusiveMaximum=!0):i.exclusiveMaximum=l:typeof o==`number`&&(i.maximum=o),typeof c==`number`&&(i.multipleOf=c)},gh=(e,t,n,r)=>{n.type=`boolean`},_h=(e,t,n,r)=>{n.not={}},vh=(e,t,n,r)=>{let i=e._zod.def,a=Hu(i.entries);a.every(e=>typeof e==`number`)&&(n.type=`number`),a.every(e=>typeof e==`string`)&&(n.type=`string`),n.enum=a},yh=(e,t,n,r)=>{let i=e._zod.def,a=[];for(let e of i.values)if(e===void 0){if(t.unrepresentable===`throw`)throw Error("Literal `undefined` cannot be represented in JSON Schema")}else if(typeof e==`bigint`){if(t.unrepresentable===`throw`)throw Error(`BigInt literals cannot be represented in JSON Schema`);a.push(Number(e))}else a.push(e);if(a.length!==0)if(a.length===1){let e=a[0];n.type=e===null?`null`:typeof e,t.target===`draft-04`||t.target===`openapi-3.0`?n.enum=[e]:n.const=e}else a.every(e=>typeof e==`number`)&&(n.type=`number`),a.every(e=>typeof e==`string`)&&(n.type=`string`),a.every(e=>typeof e==`boolean`)&&(n.type=`boolean`),a.every(e=>e===null)&&(n.type=`null`),n.enum=a},bh=(e,t,n,r)=>{if(t.unrepresentable===`throw`)throw Error(`Custom types cannot be represented in JSON Schema`)},xh=(e,t,n,r)=>{if(t.unrepresentable===`throw`)throw Error(`Transforms cannot be represented in JSON Schema`)},Sh=(e,t,n,r)=>{let i=n,a=e._zod.def,{minimum:o,maximum:s}=e._zod.bag;typeof o==`number`&&(i.minItems=o),typeof s==`number`&&(i.maxItems=s),i.type=`array`,i.items=J(a.element,t,{...r,path:[...r.path,`items`]})},Ch=(e,t,n,r)=>{let i=n,a=e._zod.def;i.type=`object`,i.properties={};let o=a.shape;for(let e in o)i.properties[e]=J(o[e],t,{...r,path:[...r.path,`properties`,e]});let s=new Set(Object.keys(o)),c=new Set([...s].filter(e=>{let n=a.shape[e]._zod;return t.io===`input`?n.optin===void 0:n.optout===void 0}));c.size>0&&(i.required=Array.from(c)),a.catchall?._zod.def.type===`never`?i.additionalProperties=!1:a.catchall?a.catchall&&(i.additionalProperties=J(a.catchall,t,{...r,path:[...r.path,`additionalProperties`]})):t.io===`output`&&(i.additionalProperties=!1)},wh=(e,t,n,r)=>{let i=e._zod.def,a=i.inclusive===!1,o=i.options.map((e,n)=>J(e,t,{...r,path:[...r.path,a?`oneOf`:`anyOf`,n]}));a?n.oneOf=o:n.anyOf=o},Th=(e,t,n,r)=>{let i=e._zod.def,a=J(i.left,t,{...r,path:[...r.path,`allOf`,0]}),o=J(i.right,t,{...r,path:[...r.path,`allOf`,1]}),s=e=>`allOf`in e&&Object.keys(e).length===1;n.allOf=[...s(a)?a.allOf:[a],...s(o)?o.allOf:[o]]},Eh=(e,t,n,r)=>{let i=n,a=e._zod.def;i.type=`array`;let o=t.target===`draft-2020-12`?`prefixItems`:`items`,s=t.target===`draft-2020-12`||t.target===`openapi-3.0`?`items`:`additionalItems`,c=a.items.map((e,n)=>J(e,t,{...r,path:[...r.path,o,n]})),l=a.rest?J(a.rest,t,{...r,path:[...r.path,s,...t.target===`openapi-3.0`?[a.items.length]:[]]}):null;t.target===`draft-2020-12`?(i.prefixItems=c,l&&(i.items=l)):t.target===`openapi-3.0`?(i.items={anyOf:c},l&&i.items.anyOf.push(l),i.minItems=c.length,l||(i.maxItems=c.length)):(i.items=c,l&&(i.additionalItems=l));let{minimum:u,maximum:d}=e._zod.bag;typeof u==`number`&&(i.minItems=u),typeof d==`number`&&(i.maxItems=d)},Dh=(e,t,n,r)=>{let i=n,a=e._zod.def;i.type=`object`;let o=a.keyType,s=o._zod.bag?.patterns;if(a.mode===`loose`&&s&&s.size>0){let e=J(a.valueType,t,{...r,path:[...r.path,`patternProperties`,`*`]});i.patternProperties={};for(let t of s)i.patternProperties[t.source]=e}else (t.target===`draft-07`||t.target===`draft-2020-12`)&&(i.propertyNames=J(a.keyType,t,{...r,path:[...r.path,`propertyNames`]})),i.additionalProperties=J(a.valueType,t,{...r,path:[...r.path,`additionalProperties`]});let c=o._zod.values;if(c){let e=[...c].filter(e=>typeof e==`string`||typeof e==`number`);e.length>0&&(i.required=e)}},Oh=(e,t,n,r)=>{let i=e._zod.def,a=J(i.innerType,t,r),o=t.seen.get(e);t.target===`openapi-3.0`?(o.ref=i.innerType,n.nullable=!0):n.anyOf=[a,{type:`null`}]},kh=(e,t,n,r)=>{let i=e._zod.def;J(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType},Ah=(e,t,n,r)=>{let i=e._zod.def;J(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType,n.default=JSON.parse(JSON.stringify(i.defaultValue))},jh=(e,t,n,r)=>{let i=e._zod.def;J(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType,t.io===`input`&&(n._prefault=JSON.parse(JSON.stringify(i.defaultValue)))},Mh=(e,t,n,r)=>{let i=e._zod.def;J(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType;let o;try{o=i.catchValue(void 0)}catch{throw Error(`Dynamic catch values are not supported in JSON Schema`)}n.default=o},Nh=(e,t,n,r)=>{let i=e._zod.def,a=i.in._zod.traits.has(`$ZodTransform`),o=t.io===`input`?a?i.out:i.in:i.out;J(o,t,r);let s=t.seen.get(e);s.ref=o},Ph=(e,t,n,r)=>{let i=e._zod.def;J(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType,n.readOnly=!0},Fh=(e,t,n,r)=>{let i=e._zod.def;J(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType},Ih=U(`ZodISODateTime`,(e,t)=>{$f.init(e,t),Z.init(e,t)});function Lh(e){return Om(Ih,e)}var Rh=U(`ZodISODate`,(e,t)=>{ep.init(e,t),Z.init(e,t)});function zh(e){return km(Rh,e)}var Bh=U(`ZodISOTime`,(e,t)=>{tp.init(e,t),Z.init(e,t)});function Vh(e){return Am(Bh,e)}var Hh=U(`ZodISODuration`,(e,t)=>{np.init(e,t),Z.init(e,t)});function Uh(e){return jm(Hh,e)}var Wh=U(`ZodError`,(e,t)=>{wd.init(e,t),e.name=`ZodError`,Object.defineProperties(e,{format:{value:t=>Dd(e,t)},flatten:{value:t=>Ed(e,t)},addIssue:{value:t=>{e.issues.push(t),e.message=JSON.stringify(e.issues,Uu,2)}},addIssues:{value:t=>{e.issues.push(...t),e.message=JSON.stringify(e.issues,Uu,2)}},isEmpty:{get(){return e.issues.length===0}}})},{Parent:Error}),Gh=Od(Wh),Kh=Ad(Wh),qh=Md(Wh),Jh=Pd(Wh),Yh=Id(Wh),Xh=Ld(Wh),Zh=Rd(Wh),Qh=zd(Wh),$h=Bd(Wh),eg=Vd(Wh),tg=Hd(Wh),ng=Ud(Wh),rg=new WeakMap;function ig(e,t,n){let r=Object.getPrototypeOf(e),i=rg.get(r);if(i||(i=new Set,rg.set(r,i)),!i.has(t)){i.add(t);for(let e in n){let t=n[e];Object.defineProperty(r,e,{configurable:!0,enumerable:!1,get(){let n=t.bind(this);return Object.defineProperty(this,e,{configurable:!0,writable:!0,enumerable:!0,value:n}),n},set(t){Object.defineProperty(this,e,{configurable:!0,writable:!0,enumerable:!0,value:t})}})}}}var Y=U(`ZodType`,(e,t)=>(K.init(e,t),Object.assign(e[`~standard`],{jsonSchema:{input:fh(e,`input`),output:fh(e,`output`)}}),e.toJSONSchema=dh(e,{}),e.def=t,e.type=t.type,Object.defineProperty(e,"_def",{value:t}),e.parse=(t,n)=>Gh(e,t,n,{callee:e.parse}),e.safeParse=(t,n)=>qh(e,t,n),e.parseAsync=async(t,n)=>Kh(e,t,n,{callee:e.parseAsync}),e.safeParseAsync=async(t,n)=>Jh(e,t,n),e.spa=e.safeParseAsync,e.encode=(t,n)=>Yh(e,t,n),e.decode=(t,n)=>Xh(e,t,n),e.encodeAsync=async(t,n)=>
vendor: 6,141 bytes, line 64
64Zh(e,t,n),e.decodeAsync=async(t,n)=>Qh(e,t,n),e.safeEncode=(t,n)=>$h(e,t,n),e.safeDecode=(t,n)=>eg(e,t,n),e.safeEncodeAsync=async(t,n)=>tg(e,t,n),e.safeDecodeAsync=async(t,n)=>ng(e,t,n),ig(e,`ZodType`,{check(...e){let t=this.def;return this.clone(Xu(t,{checks:[...t.checks??[],...e.map(e=>typeof e==`function`?{_zod:{check:e,def:{check:`custom`},onattach:[]}}:e)]}),{parent:!0})},with(...e){return this.check(...e)},clone(e,t){return od(this,e,t)},brand(){return this},register(e,t){return e.add(this,t),this},refine(e,t){return this.check(x_(e,t))},superRefine(e,t){return this.check(S_(e,t))},overwrite(e){return this.check(Zm(e))},optional(){return r_(this)},exactOptional(){return a_(this)},nullable(){return s_(this)},nullish(){return r_(s_(this))},nonoptional(e){return p_(this,e)},array(){return Rg(this)},or(e){return Ug([this,e])},and(e){return Gg(this,e)},transform(e){return __(this,t_(e))},default(e){return l_(this,e)},prefault(e){return d_(this,e)},catch(e){return h_(this,e)},pipe(e){return __(this,e)},readonly(){return y_(this)},describe(e){let t=this.clone();return im.add(t,{description:e}),t},meta(...e){if(e.length===0)return im.get(this);let t=this.clone();return im.add(t,e[0]),t},isOptional(){return this.safeParse(void 0).success},isNullable(){return this.safeParse(null).success},apply(e){return e(this)}}),Object.defineProperty(e,"description",{get(){return im.get(e)?.description},configurable:!0}),e)),ag=U(`_ZodString`,(e,t)=>{Vf.init(e,t),Y.init(e,t),e._zod.processJSONSchema=(t,n,r)=>mh(e,t,n,r);let n=e._zod.bag;e.format=n.format??null,e.minLength=n.minimum??null,e.maxLength=n.maximum??null,ig(e,`_ZodString`,{regex(...e){return this.check(Gm(...e))},includes(...e){return this.check(Jm(...e))},startsWith(...e){return this.check(Ym(...e))},endsWith(...e){return this.check(Xm(...e))},min(...e){return this.check(Um(...e))},max(...e){return this.check(Hm(...e))},length(...e){return this.check(Wm(...e))},nonempty(...e){return this.check(Um(1,...e))},lowercase(e){return this.check(Km(e))},uppercase(e){return this.check(qm(e))},trim(){return this.check($m())},normalize(...e){return this.check(Qm(...e))},toLowerCase(){return this.check(eh())},toUpperCase(){return this.check(th())},slugify(){return this.check(nh())}})}),og=U(`ZodString`,(e,t)=>{Vf.init(e,t),ag.init(e,t),e.email=t=>e.check(om(sg,t)),e.url=t=>e.check(fm(dg,t)),e.jwt=t=>e.check(Dm(Dg,t)),e.emoji=t=>e.check(pm(pg,t)),e.guid=t=>e.check(sm(lg,t)),e.uuid=t=>e.check(cm(ug,t)),e.uuidv4=t=>e.check(lm(ug,t)),e.uuidv6=t=>e.check(um(ug,t)),e.uuidv7=t=>e.check(dm(ug,t)),e.nanoid=t=>e.check(mm(mg,t)),e.guid=t=>e.check(sm(lg,t)),e.cuid=t=>e.check(hm(hg,t)),e.cuid2=t=>e.check(gm(gg,t)),e.ulid=t=>e.check(_m(_g,t)),e.base64=t=>e.check(wm(wg,t)),e.base64url=t=>e.check(Tm(Tg,t)),e.xid=t=>e.check(vm(vg,t)),e.ksuid=t=>e.check(ym(yg,t)),e.ipv4=t=>e.check(bm(bg,t)),e.ipv6=t=>e.check(xm(xg,t)),e.cidrv4=t=>e.check(Sm(Sg,t)),e.cidrv6=t=>e.check(Cm(Cg,t)),e.e164=t=>e.check(Em(Eg,t)),e.datetime=t=>e.check(Lh(t)),e.date=t=>e.check(zh(t)),e.time=t=>e.check(Vh(t)),e.duration=t=>e.check(Uh(t))});function X(e){return am(og,e)}var Z=U(`ZodStringFormat`,(e,t)=>{q.init(e,t),ag.init(e,t)}),sg=U(`ZodEmail`,(e,t)=>{Wf.init(e,t),Z.init(e,t)});function cg(e){return om(sg,e)}var lg=U(`ZodGUID`,(e,t)=>{Hf.init(e,t),Z.init(e,t)}),ug=U(`ZodUUID`,(e,t)=>{Uf.init(e,t),Z.init(e,t)}),dg=U(`ZodURL`,(e,t)=>{Gf.init(e,t),Z.init(e,t)});function fg(e){return fm(dg,e)}var pg=U(`ZodEmoji`,(e,t)=>{Kf.init(e,t),Z.init(e,t)}),mg=U(`ZodNanoID`,(e,t)=>{qf.init(e,t),Z.init(e,t)}),hg=U(`ZodCUID`,(e,t)=>{Jf.init(e,t),Z.init(e,t)}),gg=U(`ZodCUID2`,(e,t)=>{Yf.init(e,t),Z.init(e,t)}),_g=U(`ZodULID`,(e,t)=>{Xf.init(e,t),Z.init(e,t)}),vg=U(`ZodXID`,(e,t)=>{Zf.init(e,t),Z.init(e,t)}),yg=U(`ZodKSUID`,(e,t)=>{Qf.init(e,t),Z.init(e,t)}),bg=U(`ZodIPv4`,(e,t)=>{rp.init(e,t),Z.init(e,t)}),xg=U(`ZodIPv6`,(e,t)=>{ip.init(e,t),Z.init(e,t)}),Sg=U(`ZodCIDRv4`,(e,t)=>{ap.init(e,t),Z.init(e,t)}),Cg=U(`ZodCIDRv6`,(e,t)=>{op.init(e,t),Z.init(e,t)}),wg=U(`ZodBase64`,(e,t)=>{cp.init(e,t),Z.init(e,t)}),Tg=U(`ZodBase64URL`,(e,t)=>{up.init(e,t),Z.init(e,t)}),Eg=U(`ZodE164`,(e,t)=>{dp.init(e,t),Z.init(e,t)}),Dg=U(`ZodJWT`,(e,t)=>{pp.init(e,t),Z.init(e,t)}),Og=U(`ZodNumber`,(e,t)=>{mp.init(e,t),Y.init(e,t),e._zod.processJSONSchema=(t,n,r)=>hh(e,t,n,r),ig(e,`ZodNumber`,{gt(e,t){return this.check(zm(e,t))},gte(e,t){return this.check(Bm(e,t))},min(e,t){return this.check(Bm(e,t))},lt(e,t){return this.check(Lm(e,t))},lte(e,t){return this.check(Rm(e,t))},max(e,t){return this.check(Rm(e,t))},int(e){return this.check(Ag(e))},safe(e){return this.check(Ag(e))},positive(e){return this.check(zm(0,e))},nonnegative(e){return this.check(Bm(0,e))},negative(e){return this.check(Lm(0,e))},nonpositive(e){return this.check(Rm(0,e))},multipleOf(e,t){return this.check(Vm(e,t))},step(e,t){return this.check(Vm(e,t))},finite(){return this}});let n=e._zod.bag;e.minValue=Math.max(n.minimum??-1/0,n.exclusiveMinimum??-1/0)??null,e.maxValue=Math.min(n.maximum??1/0,n.exclusiveMaximum??1/0)??null,e.isInt=(n.format??``).includes(`int`)||Number.isSafeInteger(n.multipleOf??.5),e.isFinite=!0,e.format=n.format??null});function Q(e){return Mm(Og,e)}var kg=U(`ZodNumberFormat`,(e,t)=>{hp.init(e,t),Og.init(e,t)});function Ag(e){return Nm(kg,e)}var jg=U(`ZodBoolean`,(e,t)=>{gp.init(e,t),Y.init(e,t),e._zod.processJSONSchema=(t,n,r)=>gh(e,t,n,r)});function Mg(e){return Pm(jg,e)}var Ng=U(`ZodUnknown`,(e,t)=>{_p.init(e,t),Y.init(e,t),e._zod.processJSONSchema=(e,t,n)=>void 0});function Pg(){return Fm(Ng)}var Fg=U(`ZodNever`,(e,t)=>{vp.init(e,t),Y.init(e,t),e._zod.processJSONSchema=(t,n,r)=>_h(e,t,n,r)});function Ig(e){return Im(Fg,e)}var Lg=U(`ZodArray`,(e,t)=>{bp.init(e,t),Y.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Sh(e,t,n,r),e.element=t.element,ig(e,`ZodArray`,{min(e,t){return this.check(Um(e,t))},nonempty(e){return this.check(Um(1,e))},max(e,t){return this.check(Hm(e,t))},length(e,t){return this.check(Wm(e,t))},unwrap(){return this.element}})});function Rg(e,t){return rh(Lg,e,t)}var zg=U(`ZodObject`,(e,t)=>{Tp.init(e,t),Y.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ch(e,t,n,r),W(e,`shape`,()=>
vendor: 2,493 bytes, line 64
64t.shape),ig(e,`ZodObject`,{keyof(){return Zg(Object.keys(this._zod.def.shape))},catchall(e){return this.clone({...this._zod.def,catchall:e})},passthrough(){return this.clone({...this._zod.def,catchall:Pg()})},loose(){return this.clone({...this._zod.def,catchall:Pg()})},strict(){return this.clone({...this._zod.def,catchall:Ig()})},strip(){return this.clone({...this._zod.def,catchall:void 0})},extend(e){return dd(this,e)},safeExtend(e){return fd(this,e)},merge(e){return pd(this,e)},pick(e){return ld(this,e)},omit(e){return ud(this,e)},partial(...e){return md(n_,this,e[0])},required(...e){return hd(f_,this,e[0])}})});function Bg(e,t){return new zg({type:`object`,shape:e??{},...G(t)})}function Vg(e,t){return new zg({type:`object`,shape:e,catchall:Pg(),...G(t)})}var Hg=U(`ZodUnion`,(e,t)=>{Dp.init(e,t),Y.init(e,t),e._zod.processJSONSchema=(t,n,r)=>wh(e,t,n,r),e.options=t.options});function Ug(e,t){return new Hg({type:`union`,options:e,...G(t)})}var Wg=U(`ZodIntersection`,(e,t)=>{Op.init(e,t),Y.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Th(e,t,n,r)});function Gg(e,t){return new Wg({type:`intersection`,left:e,right:t})}var Kg=U(`ZodTuple`,(e,t)=>{jp.init(e,t),Y.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Eh(e,t,n,r),e.rest=t=>e.clone({...e._zod.def,rest:t})});function qg(e,t,n){let r=t instanceof K;return new Kg({type:`tuple`,items:e,rest:r?t:null,...G(r?n:t)})}var Jg=U(`ZodRecord`,(e,t)=>{Fp.init(e,t),Y.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Dh(e,t,n,r),e.keyType=t.keyType,e.valueType=t.valueType});function Yg(e,t,n){return!t||!t._zod?new Jg({type:`record`,keyType:X(),valueType:e,...G(t)}):new Jg({type:`record`,keyType:e,valueType:t,...G(n)})}var Xg=U(`ZodEnum`,(e,t)=>{Ip.init(e,t),Y.init(e,t),e._zod.processJSONSchema=(t,n,r)=>vh(e,t,n,r),e.enum=t.entries,e.options=Object.values(t.entries);let n=new Set(Object.keys(t.entries));e.extract=(e,r)=>{let i={};for(let r of e)if(n.has(r))i[r]=t.entries[r];else throw Error(`Key ${r} not found in enum`);return new Xg({...t,checks:[],...G(r),entries:i})},e.exclude=(e,r)=>{let i={...t.entries};for(let t of e)if(n.has(t))delete i[t];else throw Error(`Key ${t} not found in enum`);return new Xg({...t,checks:[],...G(r),entries:i})}});function Zg(e,t){return new Xg({type:`enum`,entries:Array.isArray(e)?Object.fromEntries(e.map(e=>[e,e])):e,...G(t)})}var Qg=U(`ZodLiteral`,(e,t)=>{Lp.init(e,t),Y.init(e,t),e._zod.processJSONSchema=(t,n,r)=>yh(e,t,n,r),e.values=new Set(t.values),Object.defineProperty(e,"value",{get(){if
64(t.values.length>1)throw Error("This schema contains multiple valid literal values. Use `.values` instead.");return t.values[0]}})});function $g(e,t){return new Qg({type:`literal`,values:Array.isArray(e)?e:[e],...G(t)})}var e_=U(`ZodTransform`,(e,t)=>{Rp.init(e,t),Y.init(e,t),e._zod.processJSONSchema=(t,n,r)=>xh(e,t,n,r),e._zod.parse=(n,r)=>{if(r.direction===`backward`)throw new zu(e.constructor.name);n.addIssue=r=>{if(typeof r==`string`)n.issues.push(Sd(r,n.value,t));else{let t=r;t.fatal&&(t.continue=!1),t.code??=`custom`,t.input??=n.value,t.inst??=e,n.issues.push(Sd(t))}};let i=t.transform(n.value,n);return i instanceof Promise?i.then(e=>(n.value=e,n.fallback=!0,n)):(n.value=i,n.fallback=!0,n)}});function t_(e){return new e_({type:`transform`,transform:e})}var n_=U(`ZodOptional`,(e,t)=>{Bp.init(e,t),Y.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Fh(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function r_(e){return new n_({type:`optional`,innerType:e})}var i_=U(`ZodExactOptional`,(e,t)=>{Vp.init(e,t),Y.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Fh(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function a_(e){return new i_({type:`optional`,innerType:e})}var o_=U(`ZodNullable`,(e,t)=>{Hp.init(e,t),Y.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Oh(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function s_(e){return new o_({type:`nullable`,innerType:e})}var c_=U(`ZodDefault`,(e,t)=>{Up.init(e,t),Y.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ah(e,t,n,r),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});function l_(e,t){return new c_({type:`default`,innerType:e,get defaultValue(){return typeof t==`function`?t():rd(t)}})}var u_=U(`ZodPrefault`,(e,t)=>{Gp.init(e,t),Y.init(e,t),e._zod.processJSONSchema=(t,n,r)=>jh(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function d_(e,t){return new u_({type:`prefault`,innerType:e,get defaultValue(){return typeof t==`function`?t():rd(t)}})}var f_=U(`ZodNonOptional`,(e,t)=>{Kp.init(e,t),Y.init(e,t),e._zod.processJSONSchema=(t,n,r)=>kh(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function p_(e,t){return new f_({type:`nonoptional`,innerType:e,...G(t)})}var m_=U(`ZodCatch`,(e,t)=>{Jp.init(e,t),Y.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Mh(e,t,n,r),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});function h_(e,t){return new m_({type:`catch`,innerType:e,catchValue:typeof t==`function`?t:()=>t})}var g_=U(`ZodPipe`,(e,t)=>{Yp.init(e,t),Y.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Nh(e,t,n,r),e.in=t.in,e.out=t.out});function __(e,t){return new g_({type:`pipe`,in:e,out:t})}var v_=U(`ZodReadonly`,(e,t)=>{Zp.init(e,t),Y.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ph(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function y_(e){return new v_({type:`readonly`,innerType:e})}var b_=U(`ZodCustom`,(e,t)=>{$p.init(e,t),Y.init(e,t),e._zod.processJSONSchema=(t,n,r)=>bh(e,t,n,r)});function x_(e,t={}){return ih(b_,e,t)}function S_(e,t){return ah(e,t)}var C_={invalid_type:`invalid_type`,too_big:`too_big`,too_small:`too_small`,invalid_format:`invalid_format`,not_multiple_of:`not_multiple_of`,unrecognized_keys:`unrecognized_keys`,invalid_union:`invalid_union`,invalid_key:`invalid_key`,invalid_element:`invalid_element`,invalid_value:`invalid_value`,custom:`custom`},w_;w_||={};var T_=class e{static id(){return X().regex(/^[0-9a-f]{64}$/)}static event(){return Bg({id:e.id(),kind:Q().int().nonnegative().max(65535),pubkey:e.id(),tags:X().array().array(),content:X(),created_at:Q().int().nonnegative(),sig:X()})}static filter(){let t=[`ids`,`authors`,`kinds`,`since`,`until`,`limit`,`search`];return Bg({kinds:Q().int().nonnegative().max(65535).array().optional(),ids:e.id().array().optional(),authors:e.id().array().optional(),since:Q().int().nonnegative().optional(),until:Q().int().nonnegative().optional(),limit:Q().int().nonnegative().optional(),search:X().optional()}).catchall(X().array()).superRefine((e,n)=>{for(let r of Object.keys(e))t.includes(r)||r.startsWith(`#`)&&r.length>=2||n.addIssue({code:`custom`,message:`Unrecognized filter key: "${r}"`,path:[r]})}).transform(e=>e)}static bech32(e){return X().regex(/^[\x21-\x7E]{1,83}1[023456789acdefghjklmnpqrstuvwxyz]{6,}$/).refine(t=>e?t.startsWith(`${e}1`):!0,e?{message:`Expected bech32 prefix "${e}1"`}:void 0)}static relayUrl(){return fg().regex(/^wss?:\/\//)}static clientEVENT(){return qg([$g(`EVENT`),e.event()])}static clientREQ(){return qg([$g(`REQ`),X()]).rest(e.filter())}static clientCOUNT(){return qg([$g(`COUNT`),X()]).rest(e.filter())}static clientCLOSE(){return qg([$g(`CLOSE`),X()])}static clientAUTH(){return qg([$g(`AUTH`),e.event()])}
64static clientMsg(){return Ug([e.clientEVENT(),e.clientREQ(),e.clientCOUNT(),e.clientCLOSE(),e.clientAUTH()])}static relayEVENT(){return qg([$g(`EVENT`),X(),e.event()])}static relayOK(){return qg([$g(`OK`),e.id(),Mg(),X()])}static relayEOSE(){return qg([$g(`EOSE`),X()])}static relayNOTICE(){return qg([$g(`NOTICE`),X()])}static relayCLOSED(){return qg([$g(`CLOSED`),X(),X()])}static relayAUTH(){return qg([$g(`AUTH`),X()])}static relayCOUNT(){return qg([$g(`COUNT`),X(),Bg({count:Q().int().nonnegative(),approximate:Mg().optional()})])}static relayMsg(){return Ug([e.relayEVENT(),e.relayOK(),e.relayEOSE(),e.relayNOTICE(),e.relayCLOSED(),e.relayAUTH(),e.relayCOUNT()])}static metadata(){return Vg({about:X().optional().catch(void 0),banner:fg().optional().catch(void 0),bot:Mg().optional().catch(void 0),display_name:X().optional().catch(void 0),lud06:e.bech32(`lnurl`).optional().catch(void 0),lud16:cg().optional().catch(void 0),name:X().optional().catch(void 0),nip05:cg().optional().catch(void 0),picture:fg().optional().catch(void 0),website:fg().optional().catch(void 0)})}static relayInfo(){return Vg({name:X().optional().catch(void 0),description:X().optional().catch(void 0),banner:X().optional().catch(void 0),icon:X().optional().catch(void 0),pubkey:e.id().optional().catch(void 0),self:e.id().optional().catch(void 0),contact:X().optional().catch(void 0),supported_nips:Q().int().nonnegative().array().optional().catch(void 0),software:X().optional().catch(void 0),version:X().optional().catch(void 0),terms_of_service:X().optional().catch(void 0),limitation:Vg({max_message_length:Q().int().nonnegative().optional().catch(void 0),max_subscriptions:Q().int().nonnegative().optional().catch(void 0),max_filters:Q().int().nonnegative().optional().catch(void 0),max_limit:Q().int().nonnegative().optional().catch(void 0),max_subid_length:Q().int().nonnegative().optional().catch(void 0),max_event_tags:Q().int().nonnegative().optional().catch(void 0),max_content_length:Q().int().nonnegative().optional().catch(void 0),min_pow_difficulty:Q().int().nonnegative().optional().catch(void 0),auth_required:Mg().optional().catch(void 0),payment_required:Mg().optional().catch(void 0),restricted_writes:Mg().optional().catch(void 0),created_at_lower_limit:Q().int().nonnegative().optional().catch(void 0),created_at_upper_limit:Q().int().nonnegative().optional().catch(void 0),default_limit:Q().int().nonnegative().optional().catch(void 0)}).optional().catch(void 0),retention:Rg(Bg({time:Q().int().nullable(),count:Q().int().nonnegative().optional(),kinds:Q().int().nonnegative().array().optional()})).optional().catch(void 0),relay_countries:X().array().optional().catch(void 0),language_tags:X().array().optional().catch(void 0),tags:X().array().optional().catch(void 0),posting_policy:X().optional().catch(void 0),payments_url:X().optional().catch(void 0),fees:Yg(X(),Rg(Bg({amount:Q(),unit:X(),period:Q().int().nonnegative().optional(),kinds:Q().int().nonnegative().array().optional()}))).optional().catch(void 0)})}static connectRequest(){return Bg({id:X(),method:X(),params:X().array()})}static connectResponse(){return Bg({id:X(),result:X(),error:X().optional()})}static json(){return X().transform((e,t)=>{try{return JSON.parse(e)}catch{return t.addIssue({code:C_.custom,message:`Invalid JSON`}),Lu}})}},E_=class e{static eventSchema=T_.json().pipe(T_.event());static responseSchema=T_.json().pipe(T_.connectResponse());static relaysSchema=T_.json().pipe(Yg(X(),Bg({read:Mg(),write:Mg()})));relay;pubkey;signer;timeout;encryption;constructor({relay:e,pubkey:t,signer:n,timeout:r,encryption:i=`nip44`}){this.relay=e,this.pubkey=t,this.signer=n,this.timeout=r,this.encryption=i}async getPublicKey(){return this.cmd(`get_public_key`,[])}async signEvent(t){let n=await this.cmd(`sign_event`,[JSON.stringify(t)]);return e.eventSchema.parse(n)}async getRelays(){let t=await this.cmd(`get_relays`,[]);return e.relaysSchema.parse(t)}nip04={encrypt:async(e,t)=>this.cmd(`nip04_encrypt`,[e,t]),decrypt:async(e,t)=>this.cmd(`nip04_decrypt`,[e,t])};nip44={encrypt:async(e,t)=>this.cmd(`nip44_encrypt`,[e,t]),decrypt:async(e,t)=>this.cmd(`nip44_decrypt`,[e,t])};async connect(e){let t=[this.pubkey];return e&&t.push(e),this.cmd(`connect`,t)}async ping(){return this.cmd(`ping`,[])}async cmd(e,t){let n=typeof this.timeout==`number`?AbortSignal.timeout(this.timeout):void 0,{result:r,error:i}=await this.send({id:crypto.randomUUID(),method:e,params:t},{signal:n});if(i)throw Error(i);return r}async send(t,n={}){let{signal:r}=n,i=await this.signer.signEvent({kind:24133,content:await this.encrypt
64(this.pubkey,JSON.stringify(t)),created_at:Math.floor(Date.now()/1e3),tags:[[`p`,this.pubkey]]}),a=await this.signer.getPublicKey(),o=this.relay.req([{kinds:[24133],authors:[this.pubkey],"#p":[a]}],{signal:r}),s=new Promise((n,r)=>{(async()=>{try{for await(let r of o){if(r[0]===`CLOSED`)throw Error(`Subscription closed`);if(r[0]===`EVENT`){let i=r[2],a=await this.decrypt(this.pubkey,i.content),o=e.responseSchema.parse(a);if(o.id===t.id){n(o);return}}}}catch(e){r(e)}})()});return await this.relay.event(i,{signal:r}),s}async encrypt(e,t){switch(this.encryption){case`nip04`:return this.signer.nip04.encrypt(e,t);case`nip44`:return this.signer.nip44.encrypt(e,t)}}async decrypt(e,t){switch(this.encryption){case`nip04`:return this.signer.nip04.decrypt(e,t);case`nip44`:return this.signer.nip44.decrypt(e,t)}}};(class e{static regex(){return/^(?:([\w.+-]+)@)?((?:[\w-]+\.)+[\w-]+)$/}static profilePointerSchema=Bg({pubkey:T_.id(),relays:T_.relayUrl().array().optional()});static async lookup(t,n){let{fetch:r=globalThis.fetch.bind(globalThis),signal:i}=n??{},a=t.match(e.regex());if(!a)throw Error(`NIP-05: invalid name ${t}`);let[o,s=`_`,c]=a,l=new URL(`/.well-known/nostr.json`,`https://${c}/`);l.searchParams.set(`name`,s);let u=await(await r(l,{signal:i})).json();try{let t=u.names[s],n=u.relays?.[t];return e.profilePointerSchema.parse({pubkey:t,relays:n})}catch{throw Error(`NIP-05: no match for ${t}`)}}});var D_=class{static parseInput(e){let t=/(\B-\w+:[^\s"]+)|(\b\w+:[^\s"]+)|(".*?")|(\S+)/g,n=[],r;for(;(r=t.exec(e))!==null;)if(r[1]||r[2]){let[e,...t]=(r[1]||r[2]).split(`:`);n.push({key:e,value:t.join(`:`)})}else r[3]?n.push(r[3].replace(/"/g,``)):r[4]&&n.push(r[4]);return n}},O_=`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/`,k_=Object.entries(O_).reduce((e,[t,n])=>(e[n]=Number(t),e),{}),A_=O_.split(``),j_=e=>{let t=e.length/4*3;e.slice(-2)===`==`?t-=2:e.slice(-1)===`=`&&t--;let n=new ArrayBuffer(t),r=new DataView(n);for(let t=0;t<e.length;t+=4){let n=0,i=0;for(let r=t,a=t+3;r<=a;r++)if(e[r]!==`=`){if(!(e[r]in k_))throw TypeError(`Invalid character ${e[r]} in base64 string.`);n|=k_[e[r]]<<(a-r)*6,i+=6}else n>>=6;let a=t/4*3;n>>=i%8;let o=Math.floor(i/8);for(let e=0;e<o;e++){let t=(o-e-1)*8;r.setUint8(a+e,(n&255<<t)>>t)}}return new Uint8Array(n)},M_=e=>new TextEncoder().encode(e);function N_(e){let t;t=typeof e==`string`?M_(e):e;let n=typeof t==`object`&&typeof t.length==`number`,r=typeof t==`object`&&typeof t.byteOffset==`number`&&typeof t.byteLength==`number`;if(!n&&!r)throw Error(`@smithy/util-base64: toBase64 encoder function only accepts string | Uint8Array.`);let i=``;for(let e=0;e<t.length;e+=3){let n=0,r=0;for(let i=e,a=Math.min(e+3,t.length);i<a;i++)n|=t[i]<<(a-i-1)*8,r+=8;let a=Math.ceil(r/6);n<<=a*6-r;for(let e=1;e<=a;e++){let t=(a-e)*6;i+=A_[(n&63<<t)>>t]}i+=`==`.slice(0,4-a)}return i}var P_={},F_={};for(let e=0;e<256;e++){let t=e.toString(16).toLowerCase();t.length===1&&(t=`0${t}`),P_[e]=t,F_[t]=e}function I_(e){let t=``;for(let n=0;n<e.byteLength;n++)t+=P_[e[n]];return t}var L_=T_.json().pipe(T_.event()),R_=class{static encodeEvent(e){return N_(JSON.stringify(e))}static encodeEventUrl(e){return N_(JSON.stringify(e)).replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=+$/,``)}static decodeEvent(e){let t=e.replace(/-/g,`+`).replace(/_/g,`/`);for(;t.length%4!=0;)t+=`=`;let n=j_(t),r=new TextDecoder().decode(n);return L_.parse(r)}},z_=class{static async template(e,t){let{validatePayload:n=[`POST`,`PUT`,`PATCH`].includes(e.method)}=t??{},{method:r,url:i}=e,a=[[`method`,r],[`u`,i]];if(n){let t=await e.clone().arrayBuffer(),n=await crypto.subtle.digest(`SHA-256`,t);a.push([`payload`,I_(new Uint8Array(n))])}return{kind:27235,content:``,tags:a,created_at:Math.floor(Date.now()/1e3)}}static async verify(e,t){let{maxAge:n=6e4,validatePayload:r=[`POST`,`PUT`,`PATCH`].includes(e.method),verifyEvent:i=Ci}=t??{},a=e.headers.get(`authorization`);if(!a)throw Error(`Missing Nostr authorization header`);let o=a.match(/^Nostr (.+)$/)?.[1];if(!o)throw Error(`Missing Nostr authorization token`);let s;try{s=R_.decodeEvent(o)}catch{throw Error(`Invalid token`)}
64if(!i(s))throw Error(`Event signature is invalid`);let c=Date.now()-s.created_at*1e3,l=s.tags.find(([e])=>e===`u`)?.[1],u=s.tags.find(([e])=>e===`method`)?.[1],d=s.tags.find(([e])=>e===`payload`)?.[1];if(s.kind!==27235)throw Error(`Event must be kind 27235`);if(l!==e.url)throw Error(`Event URL does not match request URL`);if(u!==e.method)throw Error(`Event method does not match HTTP request method`);if(c>=n)throw Error(`Event expired`);if(r&&d!==void 0){let t=await e.clone().arrayBuffer(),n=await crypto.subtle.digest(`SHA-256`,t);if(I_(new Uint8Array(n))!==d)throw Error(`Event payload does not match request body`)}return s}},B_=class e{static regular(e){return 1e3<=e&&e<1e4||[1,2,4,5,6,7,8,16,40,41,42,43,44].includes(e)}static replaceable(e){return 1e4<=e&&e<2e4||[0,3].includes(e)}static ephemeral(e){return 2e4<=e&&e<3e4}static addressable(e){return 3e4<=e&&e<4e4}static parameterizedReplaceable(t){return e.addressable(t)}};function V_(e){return W_(e)?e.limit??1/0:_o(e)}var H_=new Set([`kinds`,`authors`,`since`,`until`,`limit`]),U_=new Set([`kinds`,`authors`,`#d`,`since`,`until`,`limit`]);function W_(e){let t=e.kinds,n=e.authors;if(!t||t.length!==1||!n||n.length!==1)return!1;let r=t[0];if(B_.replaceable(r))return G_(e,H_);if(B_.addressable(r)){let t=e[`#d`];return!t||t.length!==1?!1:G_(e,U_)}return!1}function G_(e,t){for(let n of Object.keys(e))if(!t.has(n))return!1;return!0}var K_=class{set;capacity;constructor(e){this.set=new Set,this.capacity=e}
64add(e){if(!this.set.has(e)){if(this.set.size>=this.capacity){let e=this.set.values().next().value;e&&this.set.delete(e)}this.set.add(e)}}has(e){return this.set.has(e)}[Symbol.iterator](){return this.set.values()}},q_=class e{#e=new Map;#t=new Map;#n=new Map;get size(){return this.#e.size}add(t){let{id:n,kind:r,pubkey:i}=t;if(r===5&&this.#r(t),this.#e.has(n)||this.#n.has(`${i}:${n}`))return;let a=e.#s(t);if(a!==void 0){let r=this.#t.get(a),i=r===void 0?void 0:this.#e.get(r);if(i){if(!e.#c(t,i))return;this.#i(i)}this.#t.set(a,n)}this.#e.set(n,t),r===5&&this.#a(t)}toArray(){return[...this.#e.values()].sort(e.#l)}toReceivedArray(){return[...this.#e.values()]}#r(e){for(let[t,n]of e.tags){if(t!==`e`)continue;let r=this.#e.get(n);r&&r.pubkey===e.pubkey&&this.#i(r)}}#i(t){this.#e.delete(t.id);let n=e.#s(t);n!==void 0&&this.#t.get(n)===t.id&&this.#t.delete(n),t.kind===5&&this.#o(t)}#a(e){for(let[t,n]of e.tags){if(t!==`e`)continue;let r=`${e.pubkey}:${n}`,i=this.#n.get(r);i?i.add(e.id):this.#n.set(r,new Set([e.id]))}}#o(e){for(let[t,n]of e.tags){if(t!==`e`)continue;let r=`${e.pubkey}:${n}`,i=this.#n.get(r);i&&(i.delete(e.id),i.size||this.#n.delete(r))}}static#s(e){let{kind:t,pubkey:n}=e;if(B_.replaceable(t))return`${t}:${n}:`;if(B_.addressable(t))return`${t}:${n}:${e.tags.find(([e])=>e===`d`)?.[1]||``}`}static#c(t,n){return e.#l(t,n)<0}static#l(e,t){return e.created_at===t.created_at?e.id.localeCompare(t.id):t.created_at-e.created_at}},J_=class{#e=[];#t;#n=!1;constructor(e){e?.aborted?this.abort():e?.addEventListener(`abort`,()=>this.abort(),{once:!0})}async*[Symbol.asyncIterator](){for(;!this.#n;){if(this.#e.length){yield this.#e.shift();continue}await new Promise(e=>{this.#t=e})}throw new DOMException(`The signal has been aborted`,`AbortError`)}push(e){this.#e.push(e),this.#t?.()}abort(){this.#n=!0,this.#t?.()}},Y_=class e{_relays=new Map;opts;constructor(e){this.opts=e}relay(e){let t=this._relays.get(e);if(t)return t;{let t=this.opts.open(e);return this._relays.set(e,t),t}}group(t){return new e({open:e=>this.relay(e),reqRouter:e=>new Map(t.map(t=>[t,e])),eventRouter:()=>t,eoseTimeout:this.opts.eoseTimeout})}get relays(){return this._relays}async*req(e,t){let n=new AbortController,r=t?.signal?AbortSignal.any([t.signal,n.signal]):n.signal,i=t?.relays?new Map(t.relays.map(t=>[t,e])):await this.opts.reqRouter(e);if(i.size<1)return;let a=new J_(r),o=new Set,s=new Set,c=new K_(1e3),l=t?.eoseTimeout,u,d,f=[];for(let[e,t]of i.entries()){let p=this.relay(e),m=(async()=>{try{for await(let f of p.req(t,{signal:r}))if(f[0]===`EOSE`&&(o.add(e),o.size===1&&l!==void 0&&l>0&&(d=performance.now(),u===void 0&&(u=setTimeout(()=>{n.abort()},l))),d!==void 0&&l!==void 0&&l>0&&performance.now()-d>=l&&n.abort(),o.size===i.size&&a.push(f)),f[0]===`CLOSED`&&(s.add(e),s.size===i.size&&a.push(f)),f[0]===`EVENT`){d!==void 0&&l!==void 0&&l>0&&performance.now()-d>=l&&n.abort();let[,,e]=f;c.has(e.id)||(c.add(e.id),a.push(f))}}catch{}})();f.push(m)}try{for await(let e of a)yield e}finally{u!==void 0&&clearTimeout(u),n.abort(),await Promise.allSettled(f)}}async event(e,t){let n=t?.relays??await this.opts.eventRouter(e);n.length&&await Promise.any(n.map(n=>this.relay(n).event(e,t)))}async query(e,t){let n=new q_;if(e.reduce((e,t)=>
64e+V_(t),0)===0)return[];let r=this.opts.eoseTimeout??1e3;try{for await(let i of this.req(e,{...t,eoseTimeout:r}))if(i[0]===`EOSE`||(i[0]===`EVENT`&&n.add(i[2]),i[0]===`CLOSED`))break}catch{}return e.some(e=>typeof e.search==`string`)?n.toReceivedArray():n.toArray()}async close(){await Promise.all([...this._relays.values()].map(e=>e.close()))}async[Symbol.asyncDispose](){await this.close()}},X_=class{constructor(e,t){if(this._retries=0,!Number.isInteger(e)||e<0)throw Error(`Base must be a positive integer or zero`);if(t!==void 0&&(!Number.isInteger(t)||t<0))throw Error(`ExpMax must be undefined, a positive integer, or zero`);this.base=e,this.expMax=t,this.i=0}get retries(){return this._retries}get current(){return this.base*2**this.i}next(){return this._retries++,this.i=this.expMax===void 0?this.i+1:Math.min(this.i+1,this.expMax),this.current}reset(){this._retries=0,this.i=0}},Z_=class{constructor(){this.elements=[]}add(e){this.elements.push(e)}clear(){this.elements.length=0}forEach(e){this.elements.forEach(e)}length(){return this.elements.length}isEmpty(){return this.elements.length===0}peek(){return this.elements[0]}read(){return this.elements.shift()}},$={open:`open`,close:`close`,error:`error`,message:`message`,retry:`retry`,reconnect:`reconnect`},Q_=class{constructor(e,t,n){this._closedByUser=!1,this.handleOpenEvent=e=>this.handleEvent($.open,e),this.handleErrorEvent=e=>this.handleEvent($.error,e),this.handleCloseEvent=e=>this.handleEvent($.close,e),this.handleMessageEvent=e=>this.handleEvent($.message,e),this._urlProvider=e,this._protocols=t,this._options={buffer:n?.buffer,retry:{maxRetries:n?.retry?.maxRetries,instantReconnect:n?.retry?.instantReconnect,backoff:n?.retry?.backoff},listeners:{open:[...n?.listeners?.open??[]],close:[...n?.listeners?.close??[]],error:[...n?.listeners?.error??[]],message:[...n?.listeners?.message??[]],retry:[...n?.listeners?.retry??[]],reconnect:[...n?.listeners?.reconnect??[]]}},this._underlyingWebsocket=this.tryConnect()}get url(){return this._url}get protocols(){return this._protocols}get buffer(){return this._options.buffer}get maxRetries(){return this._options.retry.maxRetries}get instantReconnect(){return this._options.retry.instantReconnect}get backoff(){return this._options.retry.backoff}get closedByUser(){return this._closedByUser}get lastConnection(){return this._lastConnection}get underlyingWebsocket(){return this._underlyingWebsocket}get readyState(){return this._underlyingWebsocket.readyState}get bufferedAmount(){return this._underlyingWebsocket.bufferedAmount}get extensions(){return this._underlyingWebsocket.extensions}get binaryType(){return this._underlyingWebsocket.binaryType}set binaryType(e){this._underlyingWebsocket.binaryType=e}send(e){this.closedByUser||(this._underlyingWebsocket.readyState===this._underlyingWebsocket.OPEN?this._underlyingWebsocket.send(e):this.buffer!==void 0&&this.buffer.add(e))}close(e,t){this.cancelScheduledConnectionRetry(),this._closedByUser=!0,this._underlyingWebsocket.close(e,t)}addEventListener(e,t,n){this._options.listeners[e].push({listener:t,options:n})}removeEventListener(e,t,n){let r=e=>e.listener!==t||e.options!==n;this._options.listeners[e]=this._options.listeners[e].filter(r)}tryConnect(){return this._url=typeof this._urlProvider==`function`?this._urlProvider():this._urlProvider,this._underlyingWebsocket=new WebSocket(this._url,this.protocols),this._underlyingWebsocket.addEventListener($.open,this.handleOpenEvent),this._underlyingWebsocket.addEventListener($.close,this.handleCloseEvent),this._underlyingWebsocket.addEventListener($.error,this.handleErrorEvent),this._underlyingWebsocket.addEventListener($.message,this.handleMessageEvent),this._underlyingWebsocket}clearWebsocket(){this._underlyingWebsocket.removeEventListener($.open,this.handleOpenEvent),this._underlyingWebsocket.removeEventListener($.close,this.handleCloseEvent),this._underlyingWebsocket.removeEventListener($.error,this.handleErrorEvent),this._underlyingWebsocket.removeEventListener($.message,this.handleMessageEvent),this._underlyingWebsocket.close()}dispatchEvent(e,t){let n=this._options.listeners[e],r=[];
64n.forEach(({listener:e,options:n})=>{e(this,t),(n===void 0||n.once===void 0||!n.once)&&r.push({listener:e,options:n})}),this._options.listeners[e]=r}handleEvent(e,t){switch(e){case $.close:this.dispatchEvent(e,t),this.scheduleConnectionRetryIfNeeded();break;case $.open:if(this.backoff!==void 0&&this._lastConnection!==void 0){let e={retries:this.backoff.retries,lastConnection:new Date(this._lastConnection)},t=new CustomEvent($.reconnect,{detail:e});this.dispatchEvent($.reconnect,t),this.backoff.reset()}this._lastConnection=new Date,this.dispatchEvent(e,t),this.sendBufferedData();break;case $.retry:this.dispatchEvent(e,t),this.clearWebsocket(),this.tryConnect();break;default:this.dispatchEvent(e,t);break}}sendBufferedData(){if(this.buffer!==void 0)for(let e=this.buffer.read();e!==void 0;e=this.buffer.read())this.send(e)}scheduleConnectionRetryIfNeeded(){if(this.closedByUser||this.backoff===void 0)return;let e=e=>{let t=new CustomEvent($.retry,{detail:e});this.handleEvent($.retry,t)},t={backoff:this._options.retry.instantReconnect===!0?0:this.backoff.next(),retries:this._options.retry.instantReconnect===!0?0:this.backoff.retries,lastConnection:this._lastConnection};(this._options.retry.maxRetries===void 0||t.retries<=this._options.retry.maxRetries)&&(this.retryTimeout=globalThis.setTimeout(()=>e(t),t.backoff))}cancelScheduledConnectionRetry(){globalThis.clearTimeout(this.retryTimeout)}},$_=class{constructor(e){this._url=e}get url(){return this._url}withProtocols(e){return this._protocols=e,this}get protocols(){return this._protocols}withMaxRetries(e){return this._options=Object.assign(Object.assign({},this._options),{retry:Object.assign(Object.assign({},this._options?.retry),{maxRetries:e})}),this}get maxRetries(){return this._options?.retry?.maxRetries}withInstantReconnect(e){return this._options=Object.assign(Object.assign({},this._options),{retry:Object.assign(Object.assign({},this._options?.retry),{instantReconnect:e})}),this}get instantReconnect(){return this._options?.retry?.instantReconnect}withBackoff(e){return this._options=Object.assign(Object.assign({},this._options),{retry:Object.assign(Object.assign({},this._options?.retry),{backoff:e})}),this}get backoff(){return this._options?.retry?.backoff}withBuffer(e){return this._options=Object.assign(Object.assign({},this._options),{buffer:e}),this}get buffer(){return this._options?.buffer}onOpen(e,t){return this.addListener($.open,e,t),this}onClose(e,t){return this.addListener($.close,e,t),this}onError(e,t){return this.addListener($.error,e,t),this}onMessage(e,t){return this.addListener($.message,e,t),this}onRetry(e,t){return this.addListener($.retry,e,t),this}onReconnect(e,t){return this.addListener($.reconnect,e,t),this}build(){return new Q_(this._url,this._protocols,this._options)}addListener(e,t,n){return this._options=Object.assign(Object.assign({},this._options),{listeners:{open:this._options?.listeners?.open??[],close:this._options?.listeners?.close??[],error:this._options?.listeners?.error??[],message:this._options?.listeners?.message??[],retry:this._options?.listeners?.retry??[],reconnect:this._options?.listeners?.reconnect??[],[e]:[...this._options?.listeners?.[e]??[],{listener:t,options:n}]}}),this}},ev=class e{static msgSchema=T_.json().pipe(T_.relayMsg());static relayInfoSchema=T_.relayInfo();socket;subs=new Map;closedByUser=!1;idleTimer;controller=new AbortController;url;opts;relayInfoPromise;authPromise;authRetriedSubs=new Set;authRetriedEvents=new Set;pendingEvents=new Map;ee=new EventTarget;get subscriptions(){return[...this.subs.values()]}log(e){this.opts.log?.({...e,url:this.url})}constructor(e,t={}){this.url=e,this.opts=t,this.socket=this.createSocket(),this.maybeStartIdleTimer()}async fetchRelayInfo(t){try{let{fetch:n=globalThis.fetch}=this.opts,{signal:r}=t||{},i=await n(this.url.replace(/^wss?:\/\//,e=>e===`ws://`?`http://`:`https://`),{headers:{Accept:`application/nostr+json`},signal:r});if(!i.ok){this.log({level:`warn`,ns:`relay.nip11`,status:i.status,message:`Failed to fetch relay info`});return}let a=await i.json(),o=e.relayInfoSchema.safeParse(a);if(!o.success){this.log({level:`warn`,ns:`relay.nip11`,error:o.error,message:`Invalid relay info format`});return}return this.log({level:`debug`,ns:`relay.nip11`,message:`Successfully fetched relay info`}),o.data}catch(e){this.log({level:`warn`,ns:`relay.nip11`,error:e instanceof Error?e:Error(String(e)),message:`Error fetching relay info`});return}}async getRelayInfo(e){return this.relayInfoPromise||=this.fetchRelayInfo(e),this.relayInfoPromise}createSocket(){let{backoff:t=new X_(1e3)}=this.opts;return new $_(this.url).withBuffer(new Z_).withBackoff(t===!1?void 0:t).onOpen(e=>{this.log({level:`debug`,ns:`relay.ws.state`,state:`open`,readyState:e.readyState});for(let e of this.subs.values())this.send(e)}).onClose(e=>{this.log({level:`debug`,ns:`relay.ws.state`,state:`close`,readyState:e.readyState}),this.subs.size||this.socket.close()}).onReconnect(e=>{this.log({level:`debug`,ns:`relay.ws.state`,state:`reconnect`,readyState:e.readyState})}).onRetry((e,t)=>{this.log({level:`warn`,ns:`relay.ws.retry`,readyState:e.readyState,backoff:t.detail.backoff})}).onError(e=>
64{this.log({level:`error`,ns:`relay.ws.error`,readyState:e.readyState})}).onMessage((t,n)=>{if(typeof n.data!=`string`){this.close();return}let r=e.msgSchema.safeParse(n.data);r.success?(this.log({level:`trace`,ns:`relay.ws.message`,data:r.data}),this.receive(r.data)):this.log({level:`warn`,ns:`relay.ws.message`,error:r.error})}).build()}receive(e){let{auth:t,verifyEvent:n=Ci}=this.opts;switch(e[0]){case`EVENT`:if(!n(e[2]))break;this.ee.dispatchEvent(new CustomEvent(`sub:${e[1]}`,{detail:e}));break;case`EOSE`:this.ee.dispatchEvent(new CustomEvent(`sub:${e[1]}`,{detail:e}));break;case`CLOSED`:if(t&&e[2].startsWith(`auth-required:`)&&!this.authRetriedSubs.has(e[1])){this.retrySubAfterAuth(e[1]);break}this.subs.delete(e[1]),this.authRetriedSubs.delete(e[1]),this.maybeStartIdleTimer(),this.ee.dispatchEvent(new CustomEvent(`sub:${e[1]}`,{detail:e})),this.ee.dispatchEvent(new CustomEvent(`count:${e[1]}`,{detail:e}));break;case`OK`:if(t&&!e[2]&&e[3].startsWith(`auth-required:`)&&!this.authRetriedEvents.has(e[1])){this.retryEventAfterAuth(e[1]);break}this.pendingEvents.delete(e[1]),this.authRetriedEvents.delete(e[1]),this.ee.dispatchEvent(new CustomEvent(`ok:${e[1]}`,{detail:e}));break;case`NOTICE`:this.ee.dispatchEvent(new CustomEvent(`notice`,{detail:e}));break;case`COUNT`:this.ee.dispatchEvent(new CustomEvent(`count:${e[1]}`,{detail:e}));break;case`AUTH`:t&&(this.authPromise=this.doAuth(t,e[1]))}}async doAuth(e,t){try{let n=await e(t),r=this.once(`ok:${n.id}`);this.send([`AUTH`,n]);let[,,i]=await r;i||this.log({level:`warn`,ns:`relay.auth`,message:`AUTH failed`})}catch{}}async retrySubAfterAuth(e){let t=this.subs.get(e);if(t){this.authRetriedSubs.add(e);try{await this.authPromise}catch{}this.subs.has(e)&&this.send(t)}}async retryEventAfterAuth(e){let t=this.pendingEvents.get(e);if(t){this.authRetriedEvents.add(e);try{await this.authPromise}catch{}this.pendingEvents.has(e)&&this.send([`EVENT`,t])}}send(e){switch(this.log({level:`trace`,ns:`relay.ws.send`,data:e}),this.wake(),e[0]){case`REQ`:this.subs.set(e[1],e);break;case`CLOSE`:this.subs.delete(e[1]),this.maybeStartIdleTimer();break;case`EVENT`:return this.pendingEvents.set(e[1].id,e[1]),this.socket.send(JSON.stringify(e));case`COUNT`:return this.socket.send(JSON.stringify(e))}this.socket.readyState===WebSocket.OPEN&&this.socket.send(JSON.stringify(e))}async*req(e,t={}){let{signal:n}=t,r=crypto.randomUUID(),i=this.on(`sub:${r}`,n),a=[`REQ`,r,...e];this.send(a);try{for await(let t of i){if(t[0]===`EOSE`&&(yield t),t[0]===`CLOSED`)break;if(t[0]===`EVENT`)if(go(e,t[2]))yield t;else continue}}finally{this.send([`CLOSE`,r])}}async query(e,t){let n=new q_,r=e.reduce((e,t)=>
64e+V_(t),0);if(r===0)return[];for await(let i of this.req(e,t)){if(i[0]===`EOSE`)break;if(i[0]===`EVENT`&&n.add(i[2]),i[0]===`CLOSED`)throw Error(`Subscription closed`);if(n.size>=r)break}return e.some(e=>typeof e.search==`string`)?n.toReceivedArray():n.toArray()}async event(e,t){let n=this.once(`ok:${e.id}`,t?.signal);try{this.send([`EVENT`,e])}catch(e){throw n.catch(()=>{}),e}let[,,r,i]=await n;if(!r)throw Error(i)}async count(e,t){let n=crypto.randomUUID(),r=this.once(`count:${n}`,t?.signal);try{this.send([`COUNT`,n,...e])}catch(e){throw r.catch(()=>{}),e}let i=await r;switch(i[0]){case`CLOSED`:throw Error(`Subscription closed`);case`COUNT`:{let[,,e]=i;return e}}throw Error(`Count ended -- this should never happen`)}async*on(e,t){let n=t?AbortSignal.any([this.controller.signal,t]):this.controller.signal;if(n.aborted)throw this.abortError();let r=new J_(n),i=e=>r.push(e.detail);this.ee.addEventListener(e,i);try{for await(let e of r)yield e}finally{this.ee.removeEventListener(e,i)}}async once(e,t){for await(let n of this.on(e,t))return n;throw Error(`Unreachable`)}abortError(){return new DOMException(`The signal has been aborted`,`AbortError`)}maybeStartIdleTimer(){let{idleTimeout:e=3e4}=this.opts;e!==!1&&(this.idleTimer||this.subs.size||this.closedByUser||(this.log({level:`debug`,ns:`relay.idletimer`,state:`running`,timeout:e}),this.idleTimer=setTimeout(()=>{this.log({level:`debug`,ns:`relay.idletimer`,state:`aborted`,timeout:e}),this.socket.close()},e)))}stopIdleTimer(){this.log({level:`debug`,ns:`relay.idletimer`,state:`stopped`}),clearTimeout(this.idleTimer),this.idleTimer=void 0}wake(){this.stopIdleTimer(),!this.closedByUser&&this.socket.closedByUser?(this.log({level:`debug`,ns:`relay.wake`,state:`awoken`}),this.socket=this.createSocket()):this.closedByUser||this.socket.closedByUser?this.log({level:`debug`,ns:`relay.wake`,state:`closed`}):this.log({level:`debug`,ns:`relay.wake`,state:`awake`})}async close(){this.closedByUser=!0,this.socket.close(),this.stopIdleTimer(),this.controller.abort(),this.socket.readyState!==WebSocket.CLOSED&&await new Promise(e=>{this.socket.addEventListener($.close,e,{once:!0})})}async[Symbol.asyncDispose](){await this.close()}},tv=class{#e;pubkey;constructor(e){this.#e=e}async getPublicKey(){return this.pubkey??=xi(this.#e)}async signEvent(e){return Si(e,this.#e)}nip04={encrypt:async(e,t)=>Ho.encrypt(this.#e,e,t),decrypt:async(e,t)=>Ho.decrypt(this.#e,e,t)};#t(e){return os.v2.utils.getConversationKey(this.#e,e)}nip44={encrypt:async(e,t)=>{let n=this.#t(e);return os.v2.encrypt(t,n)},decrypt:async(e,t)=>{let n=this.#t(e);return os.v2.decrypt(t,n)}}},nv=`events`,rv=1,iv=256,av={createdAt:`by-created_at`,pubkey:`by-pubkey`,kind:`by-kind`,pubkeyKind:`by-pubkey-kind`,tag:`by-tag`},ov=class e{pendingWrites=new Map;pendingResolvers=[];flushScheduled=!1;indexTags;db;constructor(t,n={}){this.db=e.openDatabase(t),this.indexTags=n.indexTags??e.indexTags}static async openDatabase(e){if(typeof indexedDB>`u`)return null;try{return await Su(e,rv,{upgrade(e){let t=e.createObjectStore(nv,{keyPath:`id`});t.createIndex(av.createdAt,`created_at`),t.createIndex(av.pubkey,[`pubkey`,`created_at`]),t.createIndex(av.kind,[`kind`,`created_at`]),t.createIndex(av.pubkeyKind,[`pubkey`,`kind`,`created_at`]),t.createIndex(av.tag,`_tagsCreated`,{multiEntry:!0})}})}catch{return null}}getDB(){return this.db}static indexTags(e){return e.tags.filter(([e,t])=>e.length===1&&!!t&&t.length<200)}event(e,t){if(B_.ephemeral(e.kind))return Promise.resolve();this.pendingWrites.set(e.id,e);let n=new Promise(e=>{this.pendingResolvers.push(e)});return this.scheduleFlush(),n}scheduleFlush(){if(this.flushScheduled)return;this.flushScheduled=!0;let e=()=>void this.flushWrites();typeof requestIdleCallback==`function`?requestIdleCallback(e,{timeout:1e3}):setTimeout(e,0)}async flushWrites(){this.flushScheduled=!1;let e=[...this.pendingWrites.values()],t=this.pendingResolvers;this.pendingWrites=new Map,this.pendingResolvers=[];let n=await this.getDB();if(!n||e.length===0){for(let e of t)e();return}try{let t=n.transaction(nv,`readwrite`),r=t.objectStore(nv),i=await this.resolveSupersession(r,e);for(let t of e){let e=i.get(t.id);if(e!==null){if(e)for(let t of e)r.delete(t);r.put(this.toStored(t))}}await this.applyDeletions(r,e),await t.done}catch{}finally{for(let e of t)e()}}async resolveSupersession(t,n){let r=new Map,i=new Map;for(let t of n){if(!B_.replaceable(t.kind)&&!B_.addressable(t.kind)){r.set(t.i
64d,void 0);continue}let n=B_.addressable(t.kind)?e.getDTag(t):``,a=`${t.kind}:${t.pubkey}:${n}`;(i.get(a)??i.set(a,[]).get(a)).push(t)}let a=[...i.values()],o=await Promise.all(a.map(([e])=>t.index(av.pubkeyKind).getAll(IDBKeyRange.bound([e.pubkey,e.kind,0],[e.pubkey,e.kind,1/0]))));return a.forEach((t,n)=>{let i=B_.addressable(t[0].kind)?e.getDTag(t[0]):``,a=o[n].filter(t=>!B_.addressable(t.kind)||e.getDTag(t)===i),s=t.reduce((t,n)=>e.isNewer(n,t)?n:t);for(let e of t)e!==s&&r.set(e.id,null);let c=[],l=!1;for(let t of a)if(t.id!==s.id){if(e.isNewer(t,s)){l=!0;break}c.push(t.id)}r.set(s.id,l?null:c)}),r}async applyDeletions(t,n){let r=n.filter(e=>e.kind===5);if(r.length!==0){for(let n of r)for(let[r,i]of n.tags)if(r===`e`){if(!i)continue;let e=await t.get(i);e&&e.pubkey===n.pubkey&&t.delete(i)}else if(r===`a`){if(!i)continue;let[r,a,...o]=i.split(`:`),s=Number(r);if(!Number.isInteger(s)||a!==n.pubkey)continue;let c=o.join(`:`),l=await t.index(av.pubkeyKind).getAll(IDBKeyRange.bound([a,s,0],[a,s,1/0]));for(let r of l)B_.addressable(r.kind)&&e.getDTag(r)!==c||r.created_at>n.created_at||t.delete(r.id)}}}async query(t,n){let r=await this.getDB();if(!r)return[];let i=new Map;try{let a=r.transaction(nv,`readonly`).objectStore(nv),o=await Promise.all(t.map(e=>this.queryFilter(a,new sv(e),n?.signal)));for(let t of o)for(let n of t)i.set(n.id,e.fromStored(n))}catch(e){if(n?.signal?.aborted)throw e;return[]}return[...i.values()].sort(e.compareNewest)}async queryFilter(t,n,r){if(n.neverMatch)return[];let i=n.limit??1/0;if(i<=0)return[];r?.throwIfAborted();let a=e.planScan(n),o=e=>a.indexOnly?n.matchesTime(e.created_at):n.matches(e);if(a.ids){let n=(await Promise.all(a.ids.map(e=>t.get(e)))).filter(e=>e!==void 0&&o(e));return n.sort(e.compareNewest),n.length>i?n.slice(0,i):n}if(n.searchKeywords)return e.searchScan(t,a,o,i,r);if(i===1/0){let n=await Promise.all(a.cursors.map(({indexName:e,range:n})=>(e?t.index(e):t).getAll(n)));r?.throwIfAborted();let i=a.disjoint?void 0:new Set,s=[];for(let e of n)for(let t of e){if(i){if(i.has(t.id))continue;i.add(t.id)}o(t)&&s.push(t)}return s.sort(e.compareNewest),s}let s=(await Promise.all(a.cursors.map(({indexName:e,range:n})=>(e?t.index(e):t).openCursor(n,`prev`)))).filter(e=>e!==null),c=a.disjoint?void 0:new Set,l=[];for(;s.length>0&&l.length<i;){r?.throwIfAborted();let e=0;for(let t=1;t<s.length;t++)s[t].value.created_at>s[e].value.created_at&&(e=t);let t=s[e],n=t.value;!c?.has(n.id)&&o(n)&&(c?.add(n.id),l.push(n)),await t.continue()===null&&s.splice(e,1)}return l.sort(e.compareNewest),l}static async searchScan(t,n,r,i,a){let o=await Promise.all(n.cursors.map(n=>e.searchScanCursor(t,n,r,i,a))),s=n.disjoint?void 0:new Set,c=[];for(let e of o)for(let t of e){if(s){if(s.has(t.id))continue;s.add(t.id)}c.push(t)}return c.sort(e.compareNewest),c.length>i?c.slice(0,i):c}static async searchScanCursor(e,{indexName:t,range:n},r,i,a){let o=t?e.index(t):e,s=[],c=await o.openKeyCursor(n,`prevunique`);for(;c!==null&&s.length<i;){a?.throwIfAborted();let e=c.key;c=await c.advance(iv-1);let t=c===null?IDBKeyRange.bound(n.lower,e,n.lowerOpen):IDBKeyRange.bound(c.key,e),l=await o.getAll(t);for(let e=l.length-1;e>=0&&s.length<i;e--)r(l[e])&&s.push(l[e]);c&&=await c.continue()}return s}static planScan(e){let t=e.since??0,n=e.until??1/0;if(e.ids)return{indexOnly:e.indexOnly,disjoint:!0,ids:e.ids,cursors:[]};if(e.tags.length>0){let r=e.tags.reduce((e,t)=>t.values.length<e.values.length?t:e);return{indexOnly:e.indexOnly,disjoint:r.values.length===1,cursors:r.values.map(e=>({indexName:av.tag,range:IDBKeyRange.bound([r.name,e,t],[r.name,e,n])}))}}if(e.authors&&e.kinds&&e.authors.length*e.kinds.length<1e3){let r=[];for(let i of e.authors)for(let a of e.kinds)r.push({indexName:av.pubkeyKind,range:IDBKeyRange.bound([i,a,t],[i,a,n])});return{indexOnly:e.indexOnly,disjoint:!0,cursors:r}}return e.authors?{indexOnly:e.indexOnly&&!e.kinds,disjoint:!0,cursors:e.authors.map(e=>({indexName:av.pubkey,range:IDBKeyRange.bound([e,t],[e,n])}))}:e.kinds?{indexOnly:e.indexOnly,disjoint:!0,cursors:e.kinds.map(e=>({indexName:av.kind,range:IDBKeyRange.bound([e,t],[e,n])}))}:{indexOnly:e.indexOnly,disjoint:!0,cursors:[{indexName:av.createdAt,range:IDBKeyRange.bound(t,n)}]}}async count(t,n){let r=await this.getDB();if(!r)return{count:0,approximate:!1};if(t.length===1){let n=new sv(t[0]);if(n.neverMatch)return{count:0,approximate:!1};if(n.limit===void 0&&n.indexOnly){let t=e.planScan(n);if(t.disjoint&&!t.ids)try{let e=r.transaction(nv,`readonly`).objectStore(nv);return{count:(await Promise.all(t.cursors.map(({indexName:t,range:n})=>(t?e.index(t):e).count(n)))).reduce((e,t)=>
64e+t,0),approximate:!1}}catch{}}}return{count:(await this.query(t,n)).length,approximate:!1}}async remove(e,t){let n=await this.getDB();if(!n)return;let r=await this.query(e,t);try{let e=n.transaction(nv,`readwrite`);await Promise.all(r.map(t=>e.store.delete(t.id))),await e.done}catch{}}async close(){(await this.getDB())?.close()}toStored(e){let t=[],n=new Set;for(let[r,i]of this.indexTags(e)){if(typeof r!=`string`||typeof i!=`string`)continue;let a=`${r}\0${i}`;n.has(a)||(n.add(a),t.push([r,i,e.created_at]))}return t.length>0?{...e,_tagsCreated:t}:{...e}}static fromStored(e){if(!(`_tagsCreated`in e))return e;let{_tagsCreated:t,...n}=e;return n}static getDTag(e){return e.tags.find(([e])=>e===`d`)?.[1]??``}static isNewer(e,t){return e.created_at>t.created_at?!0:e.created_at<t.created_at?!1:e.id<t.id}static compareNewest(e,t){return e.created_at===t.created_at?e.id<t.id?-1:+(e.id>t.id):t.created_at-e.created_at}[Symbol.toStringTag]=`NIndexedDB`},sv=class{ids;authors;kinds;tags;search;searchKeywords;since;until;limit;idSet;authorSet;kindSet;neverMatch;indexOnly;constructor(e){let t=!1,n=0,r=[];for(let[i,a]of Object.entries(e)){if(Array.isArray(a)&&a.length===0){t=!0;continue}if(i===`ids`)this.ids=cv(a),n++;else if(i===`authors`)this.authors=cv(a),n++;else if(i===`kinds`)this.kinds=lv(a),n++;else if(i===`since`)this.since=a;else if(i===`until`)this.until=a;else if(i===`limit`)this.limit=a;else if(i===`search`)this.search=a;else if(i.startsWith(`#`)&&i.length>=2){let e=cv(a);r.push({name:i.slice(1),values:e,valueSet:new Set(e)}),n++}}if(this.tags=r,this.neverMatch=t,this.idSet=this.ids&&new Set(this.ids),this.authorSet=this.authors&&new Set(this.authors),this.kindSet=this.kinds&&new Set(this.kinds),this.search!==void 0){let e=[],t=[];for(let n of D_.parseInput(this.search)){if(typeof n!=`string`)continue;let r=n.toLowerCase();r.startsWith(`-`)?r.length>1&&t.push(r.slice(1)):r.length>0&&e.push(r)}(e.length>0||t.length>0)&&(this.searchKeywords={required:e,negated:t})}this.indexOnly=!this.searchKeywords&&(n<=1||n===2&&!!this.authors&&!!this.kinds)}matchesTime(e){return!(this.since!==void 0&&e<this.since||this.until!==void 0&&e>this.until)}matches(e){if(this.neverMatch||!this.matchesTime(e.created_at)||this.idSet&&!this.idSet.has(e.id)||this.authorSet&&!this.authorSet.has(e.pubkey)||this.kindSet&&!this.kindSet.has(e.kind))return!1;for(let{name:t,valueSet:n}of this.tags)if(!e.tags.some(([e,r])=>e===t&&n.has(r)))return!1;if(this.searchKeywords){let t=e.content.toLowerCase();for(let e of this.searchKeywords.required)if(!t.includes(e))return!1;for(let e of this.searchKeywords.negated)if(t.includes(e))return!1}return!0}};function cv(e){return[...new Set(e)].sort()}function lv(e){return[...new Set(e)].sort((e,t)=>e-t)}function uv(e){let t=bi();return{clientSecretKey:t,clientPubkey:xi(t),secret:crypto.randomUUID(),relays:e}}function dv(e,t){let n=new URLSearchParams;for(let t of e.relays)n.append(`relay`,t);return n.set(`secret`,e.secret),t?.name&&n.set(`name`,t.name),t?.callback&&n.set(`callback`,t.callback),`nostrconnect://${e.clientPubkey}?${n.toString()}`}var fv=class e{id;type;pubkey;createdAt;data;constructor(e,t,n){this.id=`${e}:${t}`,this.type=e,this.pubkey=t,this.createdAt=new Date().toISOString(),this.data=n}static fromNsec(t){let n=To.decode(t);if(n.type!==`nsec`)throw Error(`Invalid nsec`);let r=n.data;return new e(`nsec`,xi(r),{nsec:To.nsecEncode(r)})}static async fromBunker(t,n){let{pubkey:r,secret:i,relays:a}=new Pu(t);if(!a.length)throw Error(`No relay provided`);let o=bi(),s=To.nsecEncode(o),c=new tv(o),l=new E_({relay:n.group(a),pubkey:r,signer:c,timeout:6e4});return await l.connect(i),new e(`bunker`,await l.getPublicKey(),{bunkerPubkey:r,clientNsec:s,relays:a})}static async fromNostrConnect(t,n,r){let i=new tv(t.clientSecretKey),a=n.group(t.relays),o=r?.signal??AbortSignal.timeout(12e4);r?.onStatus?.(`awaiting-connect`);let s=a.req([{kinds:[24133],"#p":[t.clientPubkey]}],{signal:o});for await(let n of s){if(n[0]===`CLOSED`)throw Error(`Connection closed before remote signer responded`);if(n[0]===`EVENT`){let o=n[2],s;try{let e=await i.nip44.decrypt(o.pubkey,o.content);s=JSON.parse(e)}catch{continue}if(s.result!==t.secret)continue;r?.onStatus?.(`getting-public-key`);let c=o.pubkey;return new e(`bunker`,await new E_({relay:a,pubkey:c,signer:i,timeout:6e4}).getPublicKey(),{bunkerPubkey:c,clientNsec:To.nsecEncode(t.clientSecretKey),relays:t.relays})}}throw Error(`Timeout waiting for remote signer`)}static async fromExtension(){let t=globalThis.nostr;if(!t)throw Error(`Nostr extension is not available`);return new e(`extension`,await t.getPublicKey(),null)}
64toJSON(){return{id:this.id,type:this.type,pubkey:this.pubkey,createdAt:this.createdAt,data:this.data}}},pv=(0,tl.createContext)(void 0);function mv(e,t){switch(t.type){case`login.add`:{let n=e.filter(e=>e.id!==t.login.id);return t.set?[t.login,...n]:[...n,t.login]}case`login.remove`:return e.filter(e=>e.id!==t.id);case`login.set`:{let n=e.find(e=>e.id===t.id);return n?[n,...e.filter(e=>e.id!==t.id)]:e}case`login.clear`:return[];default:return e}}var hv=({children:e,initialLogins:t,storageKey:n,storage:r})=>{let[i,a]=(0,tl.useReducer)(mv,t);(0,tl.useEffect)(()=>{r.setItem(n,JSON.stringify(i))},[i,n,r]);let o={logins:i,addLogin:e=>a({type:`login.add`,login:e}),removeLogin:e=>a({type:`login.remove`,id:e}),setLogin:e=>a({type:`login.set`,id:e}),clearLogins:()=>a({type:`login.clear`})};return(0,nl.jsx)(pv.Provider,{value:o,children:e})},gv=({children:e,storageKey:t,storage:n=localStorage,fallback:r=null})=>{let[i,a]=(0,tl.useState)(null);return(0,tl.useEffect)(()=>{let e=!1;return Promise.resolve(n.getItem(t)).then(t=>{e||a(t?JSON.parse(t):[])}),()=>{e=!0}},[t,n]),i===null?(0,nl.jsx)(nl.Fragment,{children:r}):(0,nl.jsx)(hv,{initialLogins:i,storageKey:t,storage:n,children:e})},_v=class e{constructor(e,t,n){this.method=e,this.pubkey=t,this.signer=n}static fromNsecLogin(t){let n=To.decode(t.data.nsec);return new e(t.type,t.pubkey,new tv(n.data))}static fromBunkerLogin(t,n){let r=new tv(To.decode(t.data.clientNsec).data);return new e(t.type,t.pubkey,new E_({relay:n.group(t.data.relays),pubkey:t.data.bunkerPubkey,signer:r,timeout:6e4}))}static fromExtensionLogin(t){return new e(t.type,t.pubkey,new Fu)}};function vv(){let e=(0,tl.useContext)(pv);if(!e)throw Error(`useNostrLogin must be used within a NostrLoginProvider`);return e}var yv=(0,tl.createContext)(void 0);function bv(){let e=(0,tl.useContext)(yv);if(!e)throw Error(`useNostr must be used within a NostrProvider`);return e}function xv(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name===`Uint8Array`&&`BYTES_PER_ELEMENT`in e&&e.BYTES_PER_ELEMENT===1}function Sv(e){if(!xv(e))throw TypeError(`Uint8Array expected`)}function Cv(e,t){return Array.isArray(t)?t.length===0?!0:e?t.every(e=>typeof e==`string`):t.every(e=>Number.isSafeInteger(e)):!1}function wv(e){if(typeof e!=`function`)throw TypeError(`function expected`);return!0}function Tv(e,t){if(typeof t!=`string`)throw TypeError(`${e}: string expected`);return!0}function Ev(e){if(typeof e!=`number`)throw TypeError(`number expected, got ${typeof e}`);if(!Number.isSafeInteger(e))throw RangeError(`invalid integer: ${e}`)}function Dv(e){if(!Array.isArray(e))throw TypeError(`array expected`)}function Ov(e,t){if(!Cv(!0,t))throw TypeError(`${e}: array of strings expected`)}function kv(e,t){if(!Cv(!1,t))throw TypeError(`${e}: array of numbers expected`)}function Av(...e){let t=e=>e,n=(e,t)=>n=>e(t(n));return{encode:e.map(e=>e.encode).reduceRight(n,t),decode:e.map(e=>e.decode).reduce(n,t)}}function jv(e){let t=typeof e==`string`?e.split(``):e,n=t.length;Ov(`alphabet`,t);let r=new Map(t.map((e,t)=>[e,t]));return{encode:r=>(Dv(r),r.map(r=>{if(!Number.isSafeInteger(r)||r<0||r>=n)throw Error(`alphabet.encode: digit index outside alphabet "${r}". Allowed: ${e}`);return t[r]})),decode:t=>(Dv(t),t.map(t=>{Tv(`alphabet.decode`,t);let n=r.get(t);if(n===void 0)throw Error(`Unknown letter: "${t}". Allowed: ${e}`);return n}))}}function Mv(e=``){return Tv(`join`,e),{encode:t=>(Ov(`join.decode`,t),t.join(e)),decode:t=>(Tv(`join.decode`,t),t.split(e))}}function Nv(e,t=`=`){return Ev(e),Tv(`padding`,t),{encode(n){for(Ov(`padding.encode`,n);n.length*e%8;)n.push(t);return n},decode(n){Ov(`padding.decode`,n);let r=n.length;if(r*e%8)throw Error(`padding: invalid, string should have whole number of bytes`);for(;r>0&&n[r-1]===t;r--)if((r-1)*e%8==0)throw Error(`padding: invalid, string has too much padding`);return n.slice(0,r)}}}function Pv(e){return wv(e),{encode:e=>e,decode:t=>e(t)}}function Fv(e,t,n){if(t<2)throw RangeError(`convertRadix: invalid from=${t}, base cannot be less than 2`);if(n<2)throw RangeError(`convertRadix: invalid to=${n}, base cannot be less than 2`);if(Dv(e),!e.length)return[];let r=0,i=[],a=Array.from(e,e=>
64{if(Ev(e),e<0||e>=t)throw Error(`invalid integer: ${e}`);return e}),o=a.length;for(;;){let e=0,s=!0;for(let i=r;i<o;i++){let o=a[i],c=t*e,l=c+o;if(!Number.isSafeInteger(l)||c/t!==e||l-o!==c)throw Error(`convertRadix: carry overflow`);let u=l/n;e=l%n;let d=Math.floor(u);if(a[i]=d,!Number.isSafeInteger(d)||d*n+e!==l)throw Error(`convertRadix: carry overflow`);if(s)d?s=!1:r=i;else continue}if(i.push(e),s)break}for(let t=0;t<e.length-1&&e[t]===0;t++)i.push(0);return i.reverse()}var Iv=(e,t)=>t===0?e:Iv(t,e%t),Lv=(e,t)=>e+(t-Iv(e,t)),Rv=(()=>{let e=[];for(let t=0;t<40;t++)e.push(2**t);return e})();function zv(e,t,n,r){if(Dv(e),t<=0||t>32)throw RangeError(`convertRadix2: wrong from=${t}`);if(n<=0||n>32)throw RangeError(`convertRadix2: wrong to=${n}`);if(Lv(t,n)>32)throw Error(`convertRadix2: carry overflow from=${t} to=${n} carryBits=${Lv(t,n)}`);let i=0,a=0,o=Rv[t],s=Rv[n]-1,c=[];for(let r of e){if(Ev(r),r>=o)throw Error(`convertRadix2: invalid data word=${r} from=${t}`);if(i=i<<t|r,a+t>32)throw Error(`convertRadix2: carry overflow pos=${a} from=${t}`);for(a+=t;a>=n;a-=n)c.push((i>>a-n&s)>>>0);let e=Rv[a];if(e===void 0)throw Error(`invalid carry`);i&=e-1}if(i=i<<n-a&s,!r&&a>=t)throw Error(`Excess padding`);if(!r&&i>0)throw Error(`Non-zero padding: ${i}`);return r&&a>0&&c.push(i>>>0),c}function Bv(e){return Ev(e),{encode:t=>{if(!xv(t))throw TypeError(`radix.encode input should be Uint8Array`);return Fv(Array.from(t),256,e)},decode:t=>(kv(`radix.decode`,t),Uint8Array.from(Fv(t,e,256)))}}function Vv(e,t=!1){if(Ev(e),e<=0||e>32)throw RangeError(`radix2: bits should be in (0..32]`);if(Lv(8,e)>32||Lv(e,8)>32)throw RangeError(`radix2: carry overflow`);return{encode:n=>{if(!xv(n))throw TypeError(`radix2.encode input should be Uint8Array`);return zv(Array.from(n),8,e,!t)},decode:n=>(kv(`radix2.decode`,n),Uint8Array.from(zv(n,e,8,t)))}}function Hv(e){return wv(e),function(...t){try{return e.apply(null,t)}catch{}}}function Uv(e,t){if(Ev(e),e<=0)throw RangeError(`checksum length must be positive: ${e}`);wv(t);let n=t;return{encode(t){if(!xv(t))throw TypeError(`checksum.encode: input should be Uint8Array`);let r=n(t).slice(0,e),i=new Uint8Array(t.length+e);return i.set(t),i.set(r,t.length),i},decode(t){if(!xv(t))throw TypeError(`checksum.decode: input should be Uint8Array`);let r=t.slice(0,-e),i=t.slice(-e),a=n(r).slice(0,e);for(let t=0;t<e;t++)if(a[t]!==i[t])throw Error(`Invalid checksum`);return r}}}Av(Vv(4),jv(`0123456789ABCDEF`),Mv(``)),Av(Vv(5),jv(`ABCDEFGHIJKLMNOPQRSTUVWXYZ234567`),Nv(5),Mv(``)),Av(Vv(5),jv(`ABCDEFGHIJKLMNOPQRSTUVWXYZ234567`),Mv(``)),Av(Vv(5),jv(`0123456789ABCDEFGHIJKLMNOPQRSTUV`),Nv(5),Mv(``)),Av(Vv(5),jv(`0123456789ABCDEFGHIJKLMNOPQRSTUV`),Mv(``)),Av(Vv(5),jv(`0123456789ABCDEFGHJKMNPQRSTVWXYZ`),Mv(``),Pv(e=>e.toUpperCase().replace(/O/g,`0`).replace(/[IL]/g,`1`)));var Wv=typeof Uint8Array.from([]).toBase64==`function`&&typeof Uint8Array.fromBase64==`function`,Gv=/[\t\n\f\r ]/,Kv=(e,t)=>{Tv(`base64`,e);let n=t?`base64url`:`base64`;if(e.length>0&&Gv.test(e))throw Error(`invalid base64`);return Uint8Array.fromBase64(e,{alphabet:n,lastChunkHandling:`strict`})},qv=Object.freeze(Wv?{encode(e){return Sv(e),e.toBase64()},decode(e){return Kv(e,!1)}}:Av(Vv(6),jv(`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/`),Nv(6),Mv(``)));Av(Vv(6),jv(`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/`),Mv(``)),Wv||Av(Vv(6),jv(`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_`),Nv(6),Mv(``)),Av(Vv(6),jv(`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_`),Mv(``));var Jv=Object.freeze((e=>Av(Bv(58),jv(e),Mv(``)))(`123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz`)),Yv=e=>{wv(e);let t=e;return Av(Uv(4,e=>t(t(e))),Jv)},Xv=Yv,Zv=Av(jv(`qpzry9x8gf2tvdw0s3jn54khce6mua7l`),Mv(``)),Qv=[996825010,642813549,513874426,1027748829,705979059];function $v(e){let t=e>>25,n=(e&33554431)<<5;for(let e=0;e<Qv.length;e++)(t>>e&1)==1&&(n^=Qv[e]);return n}function ey(e,t,n=1){let r=e.length,i=1;for(let t=0;t<r;t++){let n=e.charCodeAt(t);if(n<33||n>126)throw Error(`Invalid prefix (${e})`);i=$v(i)^n>>5}i=$v(i);for(let t=0;t<r;t++)i=$v(i)^e.charCodeAt(t)&31;for(let e of t)i=$v(i)^e;for(let e=0;e<6;e++)i=$v(i);return i^=n,Zv.encode(zv([i%Rv[30]],30,5,!1))}function ty(e){let t=e===`bech32`?1:734539939,n=Vv(5),r=n.decode,i=n.encode,a=Hv(r);function o(e,n,r=90){Tv(`bech32.encode prefix`,e),xv(n)&&(n=Array.from(n)),kv(`bech32.encode`,n);let i=e.length;if(i===0)throw TypeError(`Invalid prefix length ${i}`);let a=i+7+n.length;if(r!==!1&&a>r)throw TypeError(`Length ${a} exceeds limit ${r}`);let o=e.toLowerCase(),s=ey(o,n,t);return`${o}1${Zv.encode(n)}${s}`}function s(e,n=90){Tv(`bech32.decode input`,e);let r=e.length;if(r<8||n!==!1&&r>n)throw TypeError(`invalid string length: ${r} (${e}). Expected (8..${n})`);let i=e.toLowerCase();if(e!==i&&e!==e.toUpperCase())throw Error(`String must be lowercase or uppercase`);let a=i.lastIndexOf(`1`);if(a===0||a===-1)throw Error(`Letter "1" must be present between prefix and data only`);let o=i.slice(0,a),s=i.slice(a+1);if(s.length<6)throw Error(`Data must be at least 6 characters long`);let c=Zv.decode(s).slice(0,-6),l=ey(o,c,t);if(!s.endsWith(l))throw Error(`Invalid checksum in ${e}: expected "${l}"`);return{prefix:o,words:c}}let c=Hv(s);function l(e){let{prefix:t,words:n}=s(e,!1);return{prefix:t,words:n,bytes:r(n)}}function u(e,t){return o(e,i(t))}return{encode:o,decode:s,encodeFromBytes:u,decodeToBytes:l,decodeUnsafe:c,fromWords:r,fromWordsUnsafe:a,toWords:i}}var ny=Object.freeze(ty(`bech32`)),ry=Object.freeze(ty(`bech32m`)),iy=typeof``.
64isWellFormed==`function`?e=>e.isWellFormed():e=>{try{return encodeURI(e)!==null}catch{return!1}},ay=Object.freeze({encode(e){Sv(e);let t=``;for(let n=0;n<e.length;){let r=e[n++];if(r<128){t+=String.fromCharCode(r);continue}if(r<194||n>=e.length)throw TypeError(`invalid utf8 at byte ${n-1}`);let i=e[n++];if((i&192)!=128)throw TypeError(`invalid utf8 at byte ${n-1}`);let a=(r&31)<<6|i&63;if(r>=224){if(n>=e.length)throw TypeError(`invalid utf8 at byte ${n-1}`);let t=e[n++];if((t&192)!=128||r===224&&i<160||r===237&&i>=160)throw TypeError(`invalid utf8 at byte ${n-1}`);if(a=(r&15)<<12|(i&63)<<6|t&63,r>=240){if(n>=e.length)throw TypeError(`invalid utf8 at byte ${n-1}`);let o=e[n++];if(r>244||(o&192)!=128||r===240&&i<144||r===244&&i>=144)throw TypeError(`invalid utf8 at byte ${n-1}`);a=(r&7)<<18|(i&63)<<12|(t&63)<<6|o&63}}a<65536?t+=String.fromCharCode(a):(a-=65536,t+=String.fromCharCode((a>>10)+55296,(a&1023)+56320))}return t},decode(e){if(Tv(`utf8`,e),!iy(e))throw TypeError(`utf8 expected well-formed string`);let t=new Uint8Array(e.length*3),n=0;for(let r=0;r<e.length;r++){let i=e.charCodeAt(r);if(i<128){t[n++]=i;continue}if(i>=55296&&i<=57343){let t=e.charCodeAt(++r);i=65536+(i-55296<<10)+t-56320}i>=65536?(t[n++]=i>>18|240,t[n++]=i>>12&63|128):i>=2048?t[n++]=i>>12|224:t[n++]=i>>6|192,i>=2048&&(t[n++]=i>>6&63|128),t[n++]=i&63|128}return t.subarray(0,n)}}),oy=(()=>{let e,t,n={encode(e){return Sv(e),(t||=new TextDecoder(`utf-8`,{ignoreBOM:!0,fatal:!0})).decode(e)},decode(t){if(Tv(`utf8`,t),!iy(t))throw TypeError(`utf8 expected well-formed string`);return(e||=new TextEncoder).encode(t)}};return Object.freeze({encode:typeof TextDecoder==`function`?n.encode:ay.encode,decode:typeof TextEncoder==`function`?n.decode:ay.decode})})(),sy=typeof Uint8Array.from([]).toHex==`function`&&typeof Uint8Array.fromHex==`function`,cy=Object.freeze(sy?{encode(e){return Sv(e),e.toHex()},decode(e){return Tv(`hex`,e),Uint8Array.fromHex(e)}}:Av(Vv(4),jv(`0123456789abcdef`),Mv(``),Pv(e=>{if(typeof e!=`string`||e.length%2!=0)throw TypeError(`hex.decode: expected string, got ${typeof e} with length ${e.length}`);return e.toLowerCase()}))),ly=jl,uy=t((e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.bytes=e.stringToBytes=e.str=e.bytesToString=e.hex=e.utf8=e.bech32m=e.bech32=e.base58check=e.base58xmr=e.base58xrp=e.base58flickr=e.base58=e.base64url=e.base64=e.base32crockford=e.base32hex=e.base32=e.base16=e.utils=e.assertNumber=void 0;function t(e){if(!Number.isSafeInteger(e))throw Error(`Wrong integer: ${e}`)}e.assertNumber=t;function n(...e){let t=(e,t)=>n=>e(t(n));return{encode:Array.from(e).reverse().reduce((e,n)=>e?t(e,n.encode):n.encode,void 0),decode:e.reduce((e,n)=>e?t(e,n.decode):n.decode,void 0)}}function r(e){return{encode:n=>{if(!Array.isArray(n)||n.length&&typeof n[0]!=`number`)throw Error(`alphabet.encode input should be an array of numbers`);return n.map(n=>{if(t(n),n<0||n>=e.length)throw 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 Error(`alphabet.decode input should be array of strings`);return t.map(t=>{if(typeof t!=`string`)throw Error(`alphabet.decode: not string element=${t}`);let n=e.indexOf(t);if(n===-1)throw Error(`Unknown letter: "${t}". Allowed: ${e}`);return n})}}}function i(e=``){if(typeof e!=`string`)throw Error(`join separator should be string`);return{encode:t=>{if(!Array.isArray(t)||t.length&&typeof t[0]!=`string`)throw Error(`join.encode input should be array of strings`);for(let e of t)if(typeof e!=`string`)throw Error(`join.encode: non-string input=${e}`);return t.join(e)},decode:t=>{if(typeof t!=`string`)throw Error(`join.decode input should be string`);return t.split(e)}}}function a(e,n=`=`){if(t(e),typeof n!=`string`)throw Error(`padding chr should be string`);return{encode(t){if(!Array.isArray(t)||t.length&&typeof t[0]!=`string`)throw Error(`padding.encode input should be array of strings`);for(let e of t)if(typeof e!=`string`)throw Error(`padding.encode: non-string input=${e}`);for(;t.length*e%8;)t.push(n);return t},decode(t){if(!Array.isArray(t)||t.length&&typeof t[0]!=`string`)throw Error(`padding.encode input should be array of str
64ings`);for(let e of t)if(typeof e!=`string`)throw Error(`padding.decode: non-string input=${e}`);let r=t.length;if(r*e%8)throw Error(`Invalid padding: string should have whole number of bytes`);for(;r>0&&t[r-1]===n;r--)if(!((r-1)*e%8))throw Error(`Invalid padding: string has too much padding`);return t.slice(0,r)}}}function o(e){if(typeof e!=`function`)throw Error(`normalize fn should be function`);return{encode:e=>e,decode:t=>e(t)}}function s(e,n,r){if(n<2)throw Error(`convertRadix: wrong from=${n}, base cannot be less than 2`);if(r<2)throw Error(`convertRadix: wrong to=${r}, base cannot be less than 2`);if(!Array.isArray(e))throw Error(`convertRadix: data should be array`);if(!e.length)return[];let i=0,a=[],o=Array.from(e);for(o.forEach(e=>{if(t(e),e<0||e>=n)throw Error(`Wrong integer: ${e}`)});;){let e=0,t=!0;for(let a=i;a<o.length;a++){let s=o[a],c=n*e+s;if(!Number.isSafeInteger(c)||n*e/n!==e||c-s!==n*e||(e=c%r,o[a]=Math.floor(c/r),!Number.isSafeInteger(o[a])||o[a]*r+e!==c))throw Error(`convertRadix: carry overflow`);if(t)o[a]?t=!1:i=a;else continue}if(a.push(e),t)break}for(let t=0;t<e.length-1&&e[t]===0;t++)a.push(0);return a.reverse()}var c=(e,t)=>t?c(t,e%t):e,l=(e,t)=>e+(t-c(e,t));function u(e,n,r,i){if(!Array.isArray(e))throw Error(`convertRadix2: data should be array`);if(n<=0||n>32)throw Error(`convertRadix2: wrong from=${n}`);if(r<=0||r>32)throw Error(`convertRadix2: wrong to=${r}`);if(l(n,r)>32)throw Error(`convertRadix2: carry overflow from=${n} to=${r} carryBits=${l(n,r)}`);let a=0,o=0,s=2**r-1,c=[];for(let i of e){if(t(i),i>=2**n)throw Error(`convertRadix2: invalid data word=${i} from=${n}`);if(a=a<<n|i,o+n>32)throw Error(`convertRadix2: carry overflow pos=${o} from=${n}`);for(o+=n;o>=r;o-=r)c.push((a>>o-r&s)>>>0);a&=2**o-1}if(a=a<<r-o&s,!i&&o>=n)throw Error(`Excess padding`);if(!i&&a)throw Error(`Non-zero padding: ${a}`);return i&&o>0&&c.push(a>>>0),c}function d(e){return t(e),{encode:t=>{if(!(t instanceof Uint8Array))throw Error(`radix.encode input should be Uint8Array`);return s(Array.from(t),2**8,e)},decode:t=>{if(!Array.isArray(t)||t.length&&typeof t[0]!=`number`)throw Error(`radix.decode input should be array of strings`);return Uint8Array.from(s(t,e,2**8))}}}function f(e,n=!1){if(t(e),e<=0||e>32)throw Error(`radix2: bits should be in (0..32]`);if(l(8,e)>32||l(e,8)>32)throw Error(`radix2: carry overflow`);return{encode:t=>{if(!(t instanceof Uint8Array))throw Error(`radix2.encode input should be Uint8Array`);return u(Array.from(t),8,e,!n)},decode:t=>{if(!Array.isArray(t)||t.length&&typeof t[0]!=`number`)throw Error(`radix2.decode input should be array of strings`);return Uint8Array.from(u(t,e,8,n))}}}function p(e){if(typeof e!=`function`)throw Error(`unsafeWrapper fn should be function`);return function(...t){try{return e.apply(null,t)}catch{}}}function m(e,n){if(t(e),typeof n!=`function`)throw Error(`checksum fn should be function`);return{encode(t){if(!(t instanceof Uint8Array))throw Error(`checksum.encode: input should be Uint8Array`);let r=n(t).slice(0,e),i=new Uint8Array(t.length+e);return i.set(t),i.set(r,t.length),i},decode(t){if(!(t instanceof Uint8Array))throw Error(`checksum.decode: input should be Uint8Array`);let r=t.slice(0,-e),i=n(r).slice(0,e),a=t.slice(-e);for(let t=0;t<e;t++)if(i[t]!==a[t])throw Error(`Invalid checksum`);return r}}}e.utils={alphabet:r,chain:n,checksum:m,radix:d,radix2:f,join:i,padding:a},e.base16=n(f(4),r(`0123456789ABCDEF`),i(``)),e.base32=n(f(5),r(`ABCDEFGHIJKLMNOPQRSTUVWXYZ234567`),a(5),i(``)),e.base32hex=n(f(5),r(`0123456789ABCDEFGHIJKLMNOPQRSTUV`),a(5),i(``)),e.base32crockford=n(f(5),r(`0123456789ABCDEFGHJKMNPQRSTVWXYZ`),i(``),o(e=>e.toUpperCase().replace(/O/g,`0`).replace(/[IL]/g,`1`))),e.base64=n(f(6),r(`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/`),a(6),i(``)),e.base64url=n(f(6),r(`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_`),a(6),i(``));var h=e=>n(d(58),r(e),i(``));e.base58=h(`123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz`),e.base58flickr=h(`123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ`),e.base58xrp=h(`rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz`);var g=[0,2,3,5,6,7,9,10,11];e.base58xmr={encode(t){let n=``;for(let r=0;r<t.length;r+=8){let i=t.subarray(r,r+8);n+=e.base58.encode(i).padStart(g[i.length],`1`)}return n},decode(t){let n=[];for(let r=0;r<t.length;r+=11){let i=t.slice(r,r+11),a=g.indexOf(i.length),o=e.base58.decode(i);for(let e=0;e<o.length-a;e++)if(o[e]!==0)throw Error(`base58xmr: wrong padding`);
64n=n.concat(Array.from(o.slice(o.length-a)))}return Uint8Array.from(n)}},e.base58check=t=>n(m(4,e=>t(t(e))),e.base58);var _=n(r(`qpzry9x8gf2tvdw0s3jn54khce6mua7l`),i(``)),v=[996825010,642813549,513874426,1027748829,705979059];function y(e){let t=e>>25,n=(e&33554431)<<5;for(let e=0;e<v.length;e++)(t>>e&1)==1&&(n^=v[e]);return n}function ee(e,t,n=1){let r=e.length,i=1;for(let t=0;t<r;t++){let n=e.charCodeAt(t);if(n<33||n>126)throw Error(`Invalid prefix (${e})`);i=y(i)^n>>5}i=y(i);for(let t=0;t<r;t++)i=y(i)^e.charCodeAt(t)&31;for(let e of t)i=y(i)^e;for(let e=0;e<6;e++)i=y(i);return i^=n,_.encode(u([i%2**30],30,5,!1))}function te(e){let t=e===`bech32`?1:734539939,n=f(5),r=n.decode,i=n.encode,a=p(r);function o(e,n,r=90){if(typeof e!=`string`)throw Error(`bech32.encode prefix should be string, not ${typeof e}`);if(!Array.isArray(n)||n.length&&typeof n[0]!=`number`)throw Error(`bech32.encode words should be array of numbers, not ${typeof n}`);let i=e.length+7+n.length;if(r!==!1&&i>r)throw TypeError(`Length ${i} exceeds limit ${r}`);return e=e.toLowerCase(),`${e}1${_.encode(n)}${ee(e,n,t)}`}function s(e,n=90){if(typeof e!=`string`)throw Error(`bech32.decode input should be string, not ${typeof e}`);if(e.length<8||n!==!1&&e.length>n)throw TypeError(`Wrong string length: ${e.length} (${e}). Expected (8..${n})`);let r=e.toLowerCase();if(e!==r&&e!==e.toUpperCase())throw Error(`String must be lowercase or uppercase`);e=r;let i=e.lastIndexOf(`1`);if(i===0||i===-1)throw Error(`Letter "1" must be present between prefix and data only`);let a=e.slice(0,i),o=e.slice(i+1);if(o.length<6)throw Error(`Data must be at least 6 characters long`);let s=_.decode(o).slice(0,-6),c=ee(a,s,t);if(!o.endsWith(c))throw Error(`Invalid checksum in ${e}: expected "${c}"`);return{prefix:a,words:s}}let c=p(s);function l(e){let{prefix:t,words:n}=s(e,!1);return{prefix:t,words:n,bytes:r(n)}}return{encode:o,decode:s,decodeToBytes:l,decodeUnsafe:c,fromWords:r,fromWordsUnsafe:a,toWords:i}}e.bech32=te(`bech32`),e.bech32m=te(`bech32m`),e.utf8={encode:e=>new TextDecoder().decode(e),decode:e=>new TextEncoder().encode(e)},e.hex=n(f(4),r(`0123456789abcdef`),i(``),o(e=>{if(typeof e!=`string`||e.length%2)throw TypeError(`hex.decode: expected string, got ${typeof e} with length ${e.length}`);return e.toLowerCase()}));var b={utf8:e.utf8,hex:e.hex,base16:e.base16,base32:e.base32,base64:e.base64,base64url:e.base64url,base58:e.base58,base58xmr:e.base58xmr},x=`Invalid encoding type. Available types: ${Object.keys(b).join(`, `)}`;e.bytesToString=(e,t)=>{if(typeof e!=`string`||!b.hasOwnProperty(e))throw TypeError(x);if(!(t instanceof Uint8Array))throw TypeError(`bytesToString() expects Uint8Array`);return b[e].encode(t)},e.str=e.bytesToString,e.stringToBytes=(e,t)=>{if(!b.hasOwnProperty(e))throw TypeError(x);if(typeof t!=`string`)throw TypeError(`stringToBytes() expects string`);return b[e].decode(t)},e.bytes=e.stringToBytes})),dy=class extends xl{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,ol(e);let n=yl(t);if(this.iHash=e.create(),typeof this.iHash.update!=`function`)throw Error(`Expected instance of class which extends utils.Hash`);this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let r=this.blockLen,i=new Uint8Array(r);i.set(n.length>r?e.create().update(n).digest():n);for(let e=0;e<i.length;e++)i[e]^=54;this.iHash.update(i),this.oHash=e.create();for(let e=0;e<i.length;e++)i[e]^=106;this.oHash.update(i),ll(i)}update(e){return sl(this),this.iHash.update(e),this}digestInto(e){sl(this),al(e,this.outputLen),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||=Object.create(Object.getPrototypeOf(this),{});let{oHash:t,iHash:n,finished:r,destroyed:i,blockLen:a,outputLen:o}=this;return e=e,e.finished=r,e.destroyed=i,e.blockLen=a,e.outputLen=o,e.oHash=t._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},fy=(e,t,n)=>new dy(e,t).update(n).digest();fy.create=(e,t)=>
64new dy(e,t);function py(e,t,n){return ol(e),n===void 0&&(n=new Uint8Array(e.outputLen)),fy(e,yl(n),yl(t))}var my=Uint8Array.from([0]),hy=Uint8Array.of();function gy(e,t,n,r=32){ol(e),il(r);let i=e.outputLen;if(r>255*i)throw Error(`Length should be <= 255*HashLen`);let a=Math.ceil(r/i);n===void 0&&(n=hy);let o=new Uint8Array(a*i),s=fy.create(e,t),c=s._cloneInto(),l=new Uint8Array(s.outputLen);for(let e=0;e<a;e++)my[0]=e+1,c.update(e===0?hy:l).update(n).update(my).digestInto(l),o.set(l,i*e),s._cloneInto(c);return s.destroy(),c.destroy(),ll(l,my),o.slice(0,r)}var _y=(e,t,n,r,i)=>gy(e,py(e,t,n),r,i),vy=new TextDecoder(`utf-8`),yy=new TextEncoder,by=5e3;function xy(e){let{prefix:t,words:n}=Wn.decode(e,by),r=new Uint8Array(Wn.fromWords(n));switch(t){case`nprofile`:{let e=Sy(r);if(!e[0]?.[0])throw Error(`missing TLV 0 for nprofile`);if(e[0][0].length!==32)throw Error(`TLV 0 should be 32 bytes`);return{type:`nprofile`,data:{pubkey:L(e[0][0]),relays:e[1]?e[1].map(e=>vy.decode(e)):[]}}}case`nevent`:{let e=Sy(r);if(!e[0]?.[0])throw Error(`missing TLV 0 for nevent`);if(e[0][0].length!==32)throw Error(`TLV 0 should be 32 bytes`);if(e[2]&&e[2][0].length!==32)throw Error(`TLV 2 should be 32 bytes`);if(e[3]&&e[3][0].length!==4)throw Error(`TLV 3 should be 4 bytes`);return{type:`nevent`,data:{id:L(e[0][0]),relays:e[1]?e[1].map(e=>vy.decode(e)):[],author:e[2]?.[0]?L(e[2][0]):void 0,kind:e[3]?.[0]?parseInt(L(e[3][0]),16):void 0}}}case`naddr`:{let e=Sy(r);if(!e[0]?.[0])throw Error(`missing TLV 0 for naddr`);if(!e[2]?.[0])throw Error(`missing TLV 2 for naddr`);if(e[2][0].length!==32)throw Error(`TLV 2 should be 32 bytes`);if(!e[3]?.[0])throw Error(`missing TLV 3 for naddr`);if(e[3][0].length!==4)throw Error(`TLV 3 should be 4 bytes`);return{type:`naddr`,data:{identifier:vy.decode(e[0][0]),pubkey:L(e[2][0]),kind:parseInt(L(e[3][0]),16),relays:e[1]?e[1].map(e=>vy.decode(e)):[]}}}case`nsec`:return{type:t,data:r};case`npub`:case`note`:return{type:t,data:L(r)};default:throw Error(`unknown prefix ${t}`)}}function Sy(e){let t={},n=e;for(;n.length>0;){let e=n[0],r=n[1],i=n.slice(2,2+r);if(n=n.slice(2+r),i.length<r)throw Error(`not enough data to read on TLV ${e}`);t[e]=t[e]||[],t[e].push(i)}return t}function Cy(e){return Ty(`npub`,R(e))}function wy(e,t){let n=Wn.toWords(t);return Wn.encode(e,n,by)}function Ty(e,t){return wy(e,t)}function Ey(e){let t=new ArrayBuffer(4);return new DataView(t).setUint32(0,e.kind,!1),wy(`naddr`,Dy({0:[yy.encode(e.identifier)],1:(e.relays||[]).map(e=>yy.encode(e)),2:[R(e.pubkey)],3:[new Uint8Array(t)]}))}function Dy(e){let t=[];return Object.entries(e).reverse().forEach(([e,n])=>{n.forEach(n=>{let r=new Uint8Array(n.length+2);r.set([parseInt(e)],0),r.set([n.length],1),r.set(n,2),t.push(r)})}),nn(...t)}var Oy=class e{servers;signer;fetch;expiresIn;scopeToServer;constructor(e){this.servers=e.servers,this.signer=e.signer,this.fetch=e.fetch??globalThis.fetch.bind(globalThis),this.expiresIn=e.expiresIn??6e4,this.scopeToServer=e.scopeToServer??!1}async upload(t,n){let r=await e.sha256(t),i=await this.authorizer({verb:`upload`,content:`Upload ${t.name}`,x:r});return Promise.any(this.servers.map(async a=>{let o=await i(a),s=await this.fetch(new URL(`/upload`,a),{method:`PUT`,body:t,headers:{authorization:o,"content-type":t.type,"x-sha-256":r},signal:n?.signal});return e.parse(s,r)}))}async media(t,n){let r=await e.sha256(t),i=await this.authorizer({verb:`media`,content:`Optimize ${t.name}`,x:r});return Promise.any(this.servers.map(async a=>{let o=await i(a),s=await this.fetch(new URL(`/media`,a),{method:`PUT`,body:t,headers:{authorization:o,"content-type":t.type,"x-sha-256":r},signal:n?.signal});return e.parse(s,r)}))}async mirror(t,n){let r=n?.sha256??e.hashFromUrl(t),i=await this.authorizer({verb:`upload`,content:`Mirror ${t}`,x:r});return Promise.any(this.servers.map(async a=>{let o=await i(a),s=await this.fetch(new URL(`/mirror`,a),{method:`PUT`,body:JSON.stringify({url:t}),headers:{authorization:o,"content-type":`application/json`},signal:n?.signal});return e.parse(s,r)}))}async authorizer(e){if(this.scopeToServer)return t=>this.authorize(e,t);let t=await this.authorize(e);return()=>Promise.resolve(t)}async authorize(e,t){let n=Date.now(),r=[[`t`,e.verb],[`expiration`,Math.floor((n+this.expiresIn)/1e3).toString()]];e.x&&r.push([`x`,e.x]),t&&r.push([`server`,new URL(t).hostname]);let i=await this.signer.signEvent({kind:24242,content:e.content,created_at:Math.floor(n/1e3),tags:r});return`Nostr ${R_.encodeEventUrl(i)}`}static async parse(t,n){let r=await t.text();if(!t.ok){let e=t.headers.get(`x-reason`);throw Error(`Blossom request failed (${t.status}): ${e??r}`)}let i;try{i=JSON.parse(r)}catch{throw Error(`Blossom server returned non-JSON response: ${r}`)}let a=e.schema.parse(i);if(a.nip94?.length){let e=a.nip94.find(([e])=>e===`url`)?.[1]??a.url,t=a.nip94.filter(([e])=>e!==`url`);return[[`url`,e],...t]}let o=[[`url`,a.url],[`x`,a.sha256],[`ox`,n??a.sha256],[`size`,a.size.toString()]];return a.dim&&o.push([`dim`,a.dim]),a.type&&o.push([`m`,a.type]),o}static async sha256(e){let t=await crypto.subtle.digest(`SHA-256`,await e.arrayBuffer());return I_(new Uint8Array(t))}static hashFromUrl(e){return new URL(e).pathname.match(/[0-9a-f]{64}/)?.[0]}static schema=Bg({url:X(),sha256:X(),size:Q(),type:X().optional(),uploaded:Q().optional(),dim:X().regex(/^\d+x\d+$/).optional().catch(void 0),nip94:Rg(Rg(X())).optional().catch(void 0)})};(class e{endpoint;signer;fetch;constructor(e){this.endpoint=e?.endpoint??`https://nostr.build/api/v2/upload/files`,this.signer=e?.signer,this.fetch=e?.fetch??globalThis.fetch.bind(globalThis)}async upload(t,n){let r=new FormData;r.append(`fileToUpload`,t);
64let i=new Request(this.endpoint,{method:`POST`,body:r,signal:n?.signal});if(this.signer){let e=await z_.template(i),t=await this.signer.signEvent(e);i.headers.set(`authorization`,`Nostr ${R_.encodeEvent(t)}`)}let a=await(await this.fetch(i)).json();console.log(a);let[o]=e.schema.parse(a).data,s=[[`url`,o.url],[`m`,o.mime],[`x`,o.sha256],[`ox`,o.original_sha256],[`size`,o.size.toString()]];return o.dimensions&&s.push([`dim`,`${o.dimensions.width}x${o.dimensions.height}`]),o.blurhash&&s.push([`blurhash`,o.blurhash]),s}static schema=Bg({data:Bg({url:X().url(),blurhash:X().optional().catch(void 0),sha256:X(),original_sha256:X(),mime:X(),size:Q(),dimensions:Bg({width:Q().positive(),height:Q().positive()}).optional().catch(void 0)}).array().min(1)})});export{ru as $,R_ as A,Yg as B,uv as C,ev as D,tv as E,Mg as F,jd as G,Ug as H,$g as I,Pu as J,wd as K,Vg as L,T_ as M,Zg as N,Y_ as O,Rg as P,eu as Q,Q as R,fv as S,ov as T,fg as U,X as V,kd as W,iu as X,Su as Y,nu as Z,bv as _,At as _t,gy as a,ml as at,_v as b,uy as c,el as ct,qv as d,xi as dt,au as et,ny as f,Ko as ft,oy as g,Ht as gt,cy as h,tr as ht,Cy as i,jl as it,D_ as j,B_ as k,ly as l,Si as lt,Yv as m,Qr as mt,xy as n,Kl as nt,_y as o,bl as ot,ry as p,To as pt,Fu as q,Ey as r,Ll as rt,fy as 
64s,_l as st,Oy as t,ql as tt,Xv as u,bi as ut,yv as v,dv as w,gv as x,vv as y,Bg as z};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.