@helia/ipns 10.2.0 → 10.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.min.js +9 -9
- package/dist/index.min.js.map +4 -4
- package/dist/src/pb/ipns.d.ts +14 -3
- package/dist/src/pb/ipns.d.ts.map +1 -1
- package/dist/src/pb/ipns.js +28 -28
- package/dist/src/pb/ipns.js.map +1 -1
- package/dist/src/pb/metadata.d.ts +8 -3
- package/dist/src/pb/metadata.d.ts.map +1 -1
- package/dist/src/pb/metadata.js +16 -16
- package/dist/src/pb/metadata.js.map +1 -1
- package/dist/typedoc-urls.json +1 -0
- package/package.json +3 -3
- package/src/pb/ipns.ts +45 -33
- package/src/pb/metadata.ts +27 -21
package/dist/index.min.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.HeliaIpns = factory()}(typeof self !== 'undefined' ? self : this, function () {
|
|
2
|
-
"use strict";var HeliaIpns=(()=>{var
|
|
3
|
-
`,R:"%H:%M",T:"%H:%M:%S",t:" ",X:"%T",Z:"GMT",z:"+0000"};return b;function b(w,E,v){var N=this;if(!(N instanceof b))return new b(w,E,v);N.time=+w||0,N.nano=+E||0,N.year=+v||0,y(N)}function y(w){var E,v,N,L=w.year,z=w.time,I=w.nano,k=((I<0||a<=I)&&(I-=(v=Math.floor(I/a))*a,z+=v,v=1),L%e);return(z<-i||i<z||k)&&((E=f(z/o))&&(L+=E*e,z-=E*o),(N=S(z)).setUTCFullYear(k+N.getUTCFullYear()),N=(z=+N)+(E=f((L-=k)/e))*o,E&&-i<=N&&N<=i&&(L-=E*e,z=N),v=1),v&&(w.year=L,w.time=z,w.nano=I),w}function S(w){var E=new Date(0);return E.setTime(w),E}function T(L,N){L=+L||0;var v=f((N=(N|0)*s)/n)+f(L/n),N=N%n+L%n,L=f(N/n);return L&&(v+=L,N-=L*n),new b(1e3*N,0,v*e)}function g(w,E,v,N,L,z){return function(k,O){var Y=y(this);k=k||new Array(8),C(k,O|=0);var W=Math.floor(Y.time/1e3),Y=Y.year*(r*t/e),P=f(Y/s)+f(W/s),Y=Y%s+W%s,W=Math.floor(Y/s);return W&&(P+=W,Y-=W*s),I(k,O+L,P),I(k,O+z,Y),k};function I(k,O,P){k[O+w]=P>>24&255,k[O+E]=P>>16&255,k[O+v]=P>>8&255,k[O+N]=255&P}}function D(w,E,v,N,L,z){return function(k,O){C(k,O|=0);var P=I(k,O+L);return T(I(k,O+z),P)};function I(k,O){return 16777216*k[O+w]+(k[O+E]<<16|k[O+v]<<8|k[O+N])}}function C(w,E){if(w=w&&w.length,w==null)throw new TypeError("Invalid Buffer");if(w<E+8)throw new RangeError("Out of range")}function V(w){return(9<w?"":"0")+(0|w)}function q(w,E){return(c+(0|w)).substr(-E)}})()});var Bm={};_e(Bm,{IPNSEntry:()=>Q,InvalidEmbeddedPublicKeyError:()=>cr,InvalidRecordDataError:()=>Hr,InvalidTopicError:()=>$r,InvalidValueError:()=>ct,RecordExpiredError:()=>qr,RecordNotFoundError:()=>sr,RecordObsoleteError:()=>ar,RecordTooLargeError:()=>zr,RecordsFailedValidationError:()=>Kr,SignatureCreationError:()=>Vr,SignatureVerificationError:()=>Ke,UnsupportedValidityError:()=>Mt,createIPNSRecord:()=>Ur,heliaIPNSRouting:()=>ur,ipns:()=>Tm,ipnsResolver:()=>Im,ipnsSelector:()=>Ye,ipnsValidator:()=>Oe,isLocalStoreRouting:()=>Bn,multihashFromIPNSRoutingKey:()=>ni,multihashToIPNSRoutingKey:()=>He,pubSubIPNSRouting:()=>Xf,routerName:()=>Ot});var yi={};_e(yi,{base32:()=>bt,base32hex:()=>wl,base32hexpad:()=>El,base32hexpadupper:()=>Sl,base32hexupper:()=>xl,base32pad:()=>gl,base32padupper:()=>bl,base32upper:()=>yl,base32z:()=>vl});var _m=new Uint8Array(0);function ua(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}function Me(t){if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return Pt(t);if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return Pt(new Uint8Array(t.buffer,t.byteOffset,t.byteLength));throw new Error("Unknown type, must be binary type")}function fa(t){let e=new Uint8Array(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}var ca=4096;function la(t){let e=t.length;if(e<=ca)return String.fromCharCode.apply(String,t);let r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.subarray(n,n+=ca));return r}function ul(t){return t?.buffer instanceof ArrayBuffer}function Pt(t){return ul(t)?t:t.slice()}function fl(t,e,r){if(t.length>=255)throw new TypeError("Alphabet too long");for(var n=new Uint8Array(256),o=0;o<n.length;o++)n[o]=255;for(var i=0;i<t.length;i++){var s=t.charAt(i),a=s.charCodeAt(0);if(n[a]!==255)throw new TypeError(s+" is ambiguous");if(n[a]=i,r){var c=s.toLowerCase().charCodeAt(0),f=s.toUpperCase().charCodeAt(0);c!==a&&(n[c]=i),f!==a&&(n[f]=i)}}var u=t.length,l=t.charAt(0),h=Math.log(u)/Math.log(256),m=Math.log(256)/Math.log(u);function R(S){if(S instanceof Uint8Array||(ArrayBuffer.isView(S)?S=new Uint8Array(S.buffer,S.byteOffset,S.byteLength):Array.isArray(S)&&(S=Uint8Array.from(S))),!(S instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(S.length===0)return"";for(var T=0,g=0,D=0,C=S.length;D!==C&&S[D]===0;)D++,T++;for(var V=(C-D)*m+1>>>0,q=new Uint8Array(V);D!==C;){for(var w=S[D],E=0,v=V-1;(w!==0||E<g)&&v!==-1;v--,E++)w+=256*q[v]>>>0,q[v]=w%u>>>0,w=w/u>>>0;if(w!==0)throw new Error("Non-zero carry");g=E,D++}for(var N=V-g;N!==V&&q[N]===0;)N++;for(var L=l.repeat(T);N<V;++N)L+=t.charAt(q[N]);return L}function b(S){if(typeof S!="string")throw new TypeError("Expected String");if(S.length===0)return new Uint8Array;var T=0;if(S[T]!==" "){for(var g=0,D=0;S[T]===l;)g++,T++;for(var C=(S.length-T)*h+1>>>0,V=new Uint8Array(C);S[T];){var q=n[S.charCodeAt(T)];if(q===255)return;for(var w=0,E=C-1;(q!==0||w<D)&&E!==-1;E--,w++)q+=u*V[E]>>>0,V[E]=q%256>>>0,q=q/256>>>0;if(q!==0)throw new Error("Non-zero carry");D=w,T++}if(S[T]!==" "){for(var v=C-D;v!==C&&V[v]===0;)v++;for(var N=new Uint8Array(g+(C-v)),L=g;v!==C;)N[L++]=V[v++];return N}}}function y(S){var T=b(S);if(T)return T;throw new Error(`Non-${e} character`)}return{encode:R,decodeUnsafe:b,decode:y}}var ll=fl,dl=ll,ha=dl;var di=class{name;prefix;baseEncode;constructor(e,r,n){this.name=e,this.prefix=r,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},hi=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,r,n){this.name=e,this.prefix=r;let o=r.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return pa(this,e)}},pi=class{decoders;constructor(e){this.decoders=e}or(e){return pa(this,e)}decode(e){let r=e[0],n=this.decoders[r];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function pa(t,e){return new pi({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var mi=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,r,n,o){this.name=e,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new di(e,r,n),this.decoder=new hi(e,r,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function tr({name:t,prefix:e,encode:r,decode:n}){return new mi(t,e,r,n)}function gt({name:t,prefix:e,alphabet:r,caseInsensitive:n=!1}){let{encode:o,decode:i}=ha(r,t,n);return tr({prefix:e,name:t,encode:o,decode:s=>Me(i(s))})}function hl(t,e,r,n){let o=t.length;for(;t[o-1]==="=";)--o;let i=new Uint8Array(o*r/8|0),s=0,a=0,c=0;for(let f=0;f<o;++f){let u=e[t[f]];if(u===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|u,s+=r,s>=8&&(s-=8,i[c++]=255&a>>s)}if(s>=r||(255&a<<8-s)!==0)throw new SyntaxError("Unexpected end of data");return i}function pl(t,e,r){let n=e[e.length-1]==="=",o=(1<<r)-1,i="",s=0,a=0;for(let c=0;c<t.length;++c)for(a=a<<8|t[c],s+=8;s>r;)s-=r,i+=e[o&a>>s];if(s!==0&&(i+=e[o&a<<r-s]),n)for(;(i.length*r&7)!==0;)i+="=";return i}function ml(t,e){let r={};for(let n=0;n<t.length;++n)if(r[t[n]]=n,e){let o=t[n].toLowerCase(),i=t[n].toUpperCase();o!==t[n]&&(r[o]=n),i!==t[n]&&(r[i]=n)}return r}function ce({name:t,prefix:e,bitsPerChar:r,alphabet:n,caseInsensitive:o=!1}){let i=ml(n,o);return tr({prefix:e,name:t,encode(s){return pl(s,n,r)},decode(s){return hl(s,i,r,t)}})}var bt=ce({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5,caseInsensitive:!0}),yl=ce({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5,caseInsensitive:!0}),gl=ce({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5,caseInsensitive:!0}),bl=ce({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5,caseInsensitive:!0}),wl=ce({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5,caseInsensitive:!0}),xl=ce({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5,caseInsensitive:!0}),El=ce({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5,caseInsensitive:!0}),Sl=ce({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5,caseInsensitive:!0}),vl=ce({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var gi={};_e(gi,{base36:()=>Ae,base36upper:()=>Al});var Ae=gt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz",caseInsensitive:!0}),Al=gt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",caseInsensitive:!0});var bi={};_e(bi,{base58btc:()=>re,base58flickr:()=>Tl});var re=gt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Tl=gt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Il=ga,ma=128,Bl=127,Cl=~Bl,_l=Math.pow(2,31);function ga(t,e,r){e=e||[],r=r||0;for(var n=r;t>=_l;)e[r++]=t&255|ma,t/=128;for(;t&Cl;)e[r++]=t&255|ma,t>>>=7;return e[r]=t|0,ga.bytes=r-n+1,e}var Rl=wi,Dl=128,ya=127;function wi(t,n){var r=0,n=n||0,o=0,i=n,s,a=t.length;do{if(i>=a)throw wi.bytes=0,new RangeError("Could not decode varint");s=t[i++],r+=o<28?(s&ya)<<o:(s&ya)*Math.pow(2,o),o+=7}while(s>=Dl);return wi.bytes=i-n,r}var Ll=Math.pow(2,7),Nl=Math.pow(2,14),kl=Math.pow(2,21),Ul=Math.pow(2,28),Fl=Math.pow(2,35),Ol=Math.pow(2,42),Pl=Math.pow(2,49),Ml=Math.pow(2,56),Kl=Math.pow(2,63),$l=function(t){return t<Ll?1:t<Nl?2:t<kl?3:t<Ul?4:t<Fl?5:t<Ol?6:t<Pl?7:t<Ml?8:t<Kl?9:10},Vl={encode:Il,decode:Rl,encodingLength:$l},ql=Vl,Or=ql;function Pr(t,e=0){let r=Or.decode(t,e),n=Or.decode.bytes;if(n>9)throw new RangeError("Invalid varint: too long");if(n>1&&t[e+n-1]===0)throw new RangeError("Invalid varint: not minimally encoded");return[r,n]}function rr(t,e,r=0){return Or.encode(t,e,r),e}function nr(t){return Or.encodingLength(t)}function ir(t,e){let r=e.byteLength,n=nr(t),o=n+nr(r),i=new Uint8Array(o+r);return rr(t,i,0),rr(r,i,n),i.set(e,o),new or(t,r,e,i)}function wt(t){let e=Me(t),[r,n]=Pr(e),[o,i]=Pr(e.subarray(n)),s=e.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new or(r,o,s,e)}function ba(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&ua(t.bytes,r.bytes)}}var or=class{code;size;digest;bytes;constructor(e,r,n,o){this.code=e,this.size=r,this.digest=Pt(n),this.bytes=Pt(o)}};function wa(t,e){let{bytes:r,version:n}=t;return n===0?Hl(r,xi(t),e??re.encoder):jl(r,xi(t),e??bt.encoder)}var xa=new WeakMap;function xi(t){let e=xa.get(t);if(e==null){let r=new Map;return xa.set(t,r),r}return e}var se=class t{code;version;multihash;bytes;"/";constructor(e,r,n,o){this.code=r,this.version=e,this.multihash=n,this.bytes=Pt(o),this["/"]=this.bytes}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:r}=this;if(e!==Mr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Yl)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return t.createV0(r)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:e,digest:r}=this.multihash,n=ir(e,r);return t.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(e){return t.equals(this,e)}static equals(e,r){let n=r;return n!=null&&e.code===n.code&&e.version===n.version&&ba(e.multihash,n.multihash)}toString(e){return wa(this,e)}toJSON(){return{"/":wa(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let r=e;if(r instanceof t)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:i,bytes:s}=r;return new t(n,o,i,s??Ea(n,o,i.bytes))}else if(r[Zl]===!0){let{version:n,multihash:o,code:i}=r,s=wt(o);return t.create(n,i,s)}else return null}static create(e,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(r!==Mr)throw new Error(`Version 0 CID must use dag-pb (code: ${Mr}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let o=Ea(e,r,n.bytes);return new t(e,r,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,Mr,e)}static createV1(e,r){return t.create(1,e,r)}static decode(e){let[r,n]=t.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(e){let r=t.inspectBytes(e),n=r.size-r.multihashSize,o=Me(e.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let i=o.subarray(r.multihashSize-r.digestSize),s=new or(r.multihashCode,r.digestSize,i,o);return[r.version===0?t.createV0(s):t.createV1(r.codec,s),e.subarray(r.size)]}static inspectBytes(e){let r=0,n=()=>{let[l,h]=Pr(e.subarray(r));return r+=h,l},o=n(),i=Mr;if(o===18?(o=0,r=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let s=r,a=n(),c=n(),f=r+c,u=f-s;return{version:o,codec:i,multihashCode:a,digestSize:c,multihashSize:u,size:f}}static parse(e,r){let[n,o]=zl(e,r),i=t.decode(o);if(i.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return xi(i).set(n,e),i}};function zl(t,e){switch(t[0]){case"Q":{let r=e??re;return[re.prefix,r.decode(`${re.prefix}${t}`)]}case re.prefix:{let r=e??re;return[re.prefix,r.decode(t)]}case bt.prefix:{let r=e??bt;return[bt.prefix,r.decode(t)]}case Ae.prefix:{let r=e??Ae;return[Ae.prefix,r.decode(t)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[t[0],e.decode(t)]}}}function Hl(t,e,r){let{prefix:n}=r;if(n!==re.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=e.get(n);if(o==null){let i=r.encode(t).slice(1);return e.set(n,i),i}else return o}function jl(t,e,r){let{prefix:n}=r,o=e.get(n);if(o==null){let i=r.encode(t);return e.set(n,i),i}else return o}var Mr=112,Yl=18;function Ea(t,e,r){let n=nr(t),o=n+nr(e),i=new Uint8Array(o+r.byteLength);return rr(t,i,0),rr(e,i,n),i.set(r,o),i}var Zl=Symbol.for("@ipld/js-cid/CID");var Dn=BigInt(6e4)*5000000n,Sa=5;var Kr=class extends Error{static name="RecordsFailedValidationError";name="RecordsFailedValidationError"},ct=class extends Error{static name="InvalidValueError";name="InvalidValueError"},$r=class extends Error{static name="InvalidTopicError";name="InvalidTopicError"},sr=class extends Error{static name="RecordNotFoundError";name="RecordNotFoundError"},ar=class extends Error{static name="RecordObsoleteError";name="RecordObsoleteError";record;constructor(e,r){super(e),this.record=r}},Vr=class extends Error{static name="SignatureCreationError";name="SignatureCreationError"},Ke=class extends Error{static name="SignatureVerificationError";name="SignatureVerificationError"},qr=class extends Error{static name="RecordExpiredError";name="RecordExpiredError"},Mt=class extends Error{static name="UnsupportedValidityError";name="UnsupportedValidityError"},zr=class extends Error{static name="RecordTooLargeError";name="RecordTooLargeError"},Hr=class extends Error{static name="InvalidRecordDataError";name="InvalidRecordDataError"},cr=class extends Error{static name="InvalidEmbeddedPublicKeyError";name="InvalidEmbeddedPublicKeyError"};function $e(t=0){return new Uint8Array(t)}function Re(t=0){return new Uint8Array(t)}var Gl=Math.pow(2,7),Xl=Math.pow(2,14),Wl=Math.pow(2,21),va=Math.pow(2,28),Aa=Math.pow(2,35),Ta=Math.pow(2,42),Ia=Math.pow(2,49),Se=128,Et=127;function jr(t){if(t<Gl)return 1;if(t<Xl)return 2;if(t<Wl)return 3;if(t<va)return 4;if(t<Aa)return 5;if(t<Ta)return 6;if(t<Ia)return 7;if(Number.MAX_SAFE_INTEGER!=null&&t>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Ba(t,e,r=0){switch(jr(t)){case 8:e[r++]=t&255|Se,t/=128;case 7:e[r++]=t&255|Se,t/=128;case 6:e[r++]=t&255|Se,t/=128;case 5:e[r++]=t&255|Se,t/=128;case 4:e[r++]=t&255|Se,t>>>=7;case 3:e[r++]=t&255|Se,t>>>=7;case 2:e[r++]=t&255|Se,t>>>=7;case 1:{e[r++]=t&255,t>>>=7;break}default:throw new Error("unreachable")}return e}function Ca(t,e){let r=t[e],n=0;if(n+=r&Et,r<Se||(r=t[e+1],n+=(r&Et)<<7,r<Se)||(r=t[e+2],n+=(r&Et)<<14,r<Se)||(r=t[e+3],n+=(r&Et)<<21,r<Se)||(r=t[e+4],n+=(r&Et)*va,r<Se)||(r=t[e+5],n+=(r&Et)*Aa,r<Se)||(r=t[e+6],n+=(r&Et)*Ta,r<Se)||(r=t[e+7],n+=(r&Et)*Ia,r<Se))return n;throw new RangeError("Could not decode varint")}function Ql(t){return t.buffer instanceof ArrayBuffer}function Te(t){return Ql(t)?t:t.slice()}var Ei=new Float32Array([-0]),St=new Uint8Array(Ei.buffer);function _a(t,e,r){Ei[0]=t,e[r]=St[0],e[r+1]=St[1],e[r+2]=St[2],e[r+3]=St[3]}function Ra(t,e){return St[0]=t[e],St[1]=t[e+1],St[2]=t[e+2],St[3]=t[e+3],Ei[0]}var Si=new Float64Array([-0]),xe=new Uint8Array(Si.buffer);function Da(t,e,r){Si[0]=t,e[r]=xe[0],e[r+1]=xe[1],e[r+2]=xe[2],e[r+3]=xe[3],e[r+4]=xe[4],e[r+5]=xe[5],e[r+6]=xe[6],e[r+7]=xe[7]}function La(t,e){return xe[0]=t[e],xe[1]=t[e+1],xe[2]=t[e+2],xe[3]=t[e+3],xe[4]=t[e+4],xe[5]=t[e+5],xe[6]=t[e+6],xe[7]=t[e+7],Si[0]}var Jl=BigInt(Number.MAX_SAFE_INTEGER),ed=BigInt(Number.MIN_SAFE_INTEGER),De=class t{lo;hi;constructor(e,r){this.lo=e|0,this.hi=r|0}toNumber(e=!1){if(!e&&this.hi>>>31>0){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(r+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(e=!1){if(e)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(BigInt(r)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(e=!1){return this.toBigInt(e).toString()}zzEncode(){let e=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^e)>>>0,this.lo=(this.lo<<1^e)>>>0,this}zzDecode(){let e=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^e)>>>0,this.hi=(this.hi>>>1^e)>>>0,this}length(){let e=this.lo,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?e<16384?e<128?1:2:e<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(e){if(e===0n)return Kt;if(e<Jl&&e>ed)return this.fromNumber(Number(e));let r=e<0n;r&&(e=-e);let n=e>>32n,o=e-(n<<32n);return r&&(n=~n|0n,o=~o|0n,++o>Na&&(o=0n,++n>Na&&(n=0n))),new t(Number(o),Number(n))}static fromNumber(e){if(e===0)return Kt;let r=e<0;r&&(e=-e);let n=e>>>0,o=(e-n)/4294967296>>>0;return r&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new t(n,o)}static from(e){return typeof e=="number"?t.fromNumber(e):typeof e=="bigint"?t.fromBigInt(e):typeof e=="string"?t.fromBigInt(BigInt(e)):e.low!=null||e.high!=null?new t(e.low>>>0,e.high>>>0):Kt}},Kt=new De(0,0);Kt.toBigInt=function(){return 0n};Kt.zzEncode=Kt.zzDecode=function(){return this};Kt.length=function(){return 1};var Na=4294967296n;function ka(t){let e=0,r=0;for(let n=0;n<t.length;++n)r=t.charCodeAt(n),r<128?e+=1:r<2048?e+=2:(r&64512)===55296&&(t.charCodeAt(n+1)&64512)===56320?(++n,e+=4):e+=3;return e}function Ua(t,e,r){if(r-e<1)return"";let o,i=[],s=0,a;for(;e<r;)a=t[e++],a<128?i[s++]=a:a>191&&a<224?i[s++]=(a&31)<<6|t[e++]&63:a>239&&a<365?(a=((a&7)<<18|(t[e++]&63)<<12|(t[e++]&63)<<6|t[e++]&63)-65536,i[s++]=55296+(a>>10),i[s++]=56320+(a&1023)):i[s++]=(a&15)<<12|(t[e++]&63)<<6|t[e++]&63,s>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,i)),s=0);return o!=null?(s>0&&o.push(String.fromCharCode.apply(String,i.slice(0,s))),o.join("")):String.fromCharCode.apply(String,i.slice(0,s))}function vi(t,e,r){let n=r,o,i;for(let s=0;s<t.length;++s)o=t.charCodeAt(s),o<128?e[r++]=o:o<2048?(e[r++]=o>>6|192,e[r++]=o&63|128):(o&64512)===55296&&((i=t.charCodeAt(s+1))&64512)===56320?(o=65536+((o&1023)<<10)+(i&1023),++s,e[r++]=o>>18|240,e[r++]=o>>12&63|128,e[r++]=o>>6&63|128,e[r++]=o&63|128):(e[r++]=o>>12|224,e[r++]=o>>6&63|128,e[r++]=o&63|128);return r-n}function Ze(t,e){return RangeError(`index out of range: ${t.pos} + ${e??1} > ${t.len}`)}function Ln(t,e){return(t[e-4]|t[e-3]<<8|t[e-2]<<16|t[e-1]<<24)>>>0}var Ai=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(e){this.buf=Te(e),this.pos=0,this.len=e.length}uint32(){let e=4294967295;if(e=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(e=(e|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return e;if((this.pos+=5)>this.len)throw this.pos=this.len,Ze(this,10);return e}int32(){return this.uint32()|0}sint32(){let e=this.uint32();return e>>>1^-(e&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw Ze(this,4);return Ln(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Ze(this,4);return Ln(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Ze(this,4);let e=Ra(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw Ze(this,4);let e=La(this.buf,this.pos);return this.pos+=8,e}bytes(){let e=this.uint32(),r=this.pos,n=this.pos+e;if(n>this.len)throw Ze(this,e);return this.pos+=e,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let e=this.bytes();return Ua(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw Ze(this,e);this.pos+=e}else do if(this.pos>=this.len)throw Ze(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(e){switch(e){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(e=this.uint32()&7)!==4;)this.skipType(e);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${e} at offset ${this.pos}`)}return this}readLongVarint(){let e=new De(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(e.lo=(e.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return e;if(e.lo=(e.lo|(this.buf[this.pos]&127)<<28)>>>0,e.hi=(e.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return e;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw Ze(this);if(e.lo=(e.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return e}return e.lo=(e.lo|(this.buf[this.pos++]&127)<<r*7)>>>0,e}if(this.len-this.pos>4){for(;r<5;++r)if(e.hi=(e.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return e}else for(;r<5;++r){if(this.pos>=this.len)throw Ze(this);if(e.hi=(e.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return e}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Ze(this,8);let e=Ln(this.buf,this.pos+=4),r=Ln(this.buf,this.pos+=4);return new De(e,r)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let e=Ca(this.buf,this.pos);return this.pos+=jr(e),e}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function Yr(t){return new Ai(t instanceof Uint8Array?t:t.subarray())}function Qe(t,e,r){let n=Yr(t);return e.decode(n,void 0,r)}var Ti={};_e(Ti,{base10:()=>td});var td=gt({prefix:"9",name:"base10",alphabet:"0123456789"});var Ii={};_e(Ii,{base16:()=>rd,base16upper:()=>nd});var rd=ce({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4,caseInsensitive:!0}),nd=ce({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4,caseInsensitive:!0});var Bi={};_e(Bi,{base2:()=>od});var od=ce({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Ci={};_e(Ci,{base256emoji:()=>ud});var Oa=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),id=Oa.reduce((t,e,r)=>(t[r]=e,t),[]),sd=Oa.reduce((t,e,r)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return t[n]=r,t},[]);function ad(t){return t.reduce((e,r)=>(e+=id[r],e),"")}function cd(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=sd[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(o)}return new Uint8Array(e)}var ud=tr({prefix:"\u{1F680}",name:"base256emoji",encode:ad,decode:cd});var Ri={};_e(Ri,{base64:()=>_i,base64pad:()=>fd,base64url:()=>ld,base64urlpad:()=>dd});var _i=ce({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),fd=ce({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),ld=ce({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),dd=ce({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Di={};_e(Di,{base8:()=>hd});var hd=ce({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Li={};_e(Li,{identity:()=>pd});var pd=tr({prefix:"\0",name:"identity",encode:t=>la(Me(t)),decode:t=>Me(fa(t))});var m0=new TextEncoder,y0=new TextDecoder;var Ni={};_e(Ni,{identity:()=>Ge});var Pa=0,gd="identity",Ma=Me;function bd(t,e){if(e?.truncate!=null&&e.truncate!==t.byteLength){if(e.truncate<0||e.truncate>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,e.truncate)}return ir(Pa,Ma(t))}var Ge={code:Pa,name:gd,encode:Ma,digest:bd};var Fi={};_e(Fi,{sha256:()=>Zr,sha512:()=>xd});var wd=20;function Ui({name:t,code:e,encode:r,minDigestLength:n,maxDigestLength:o}){return new ki(t,e,r,n,o)}var ki=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,r,n,o,i){this.name=e,this.code=r,this.encode=n,this.minDigestLength=o??wd,this.maxDigestLength=i}digest(e,r){if(r?.truncate!=null){if(r.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&r.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(e instanceof Uint8Array){let n=this.encode(e);return n instanceof Uint8Array?Ka(n,this.code,r?.truncate):n.then(o=>Ka(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function Ka(t,e,r){if(r!=null&&r!==t.byteLength){if(r>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,r)}return ir(e,t)}function Va(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}var Zr=Ui({name:"sha2-256",code:18,encode:Va("SHA-256")}),xd=Ui({name:"sha2-512",code:19,encode:Va("SHA-512")});var Oi={...Li,...Bi,...Di,...Ti,...Ii,...yi,...gi,...bi,...Ri,...Ci},_0={...Fi,...Ni};function za(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var qa=za("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),Pi=za("ascii","a",t=>{let e="a";for(let r=0;r<t.length;r++)e+=String.fromCharCode(t[r]);return e},t=>{t=t.substring(1);let e=Re(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),Ed={utf8:qa,"utf-8":qa,hex:Oi.base16,latin1:Pi,ascii:Pi,binary:Pi,...Oi},Nn=Ed;function le(t,e="utf8"){let r=Nn[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}function Mi(t){let e=t??8192,r=e>>>1,n,o=e;return function(s){if(s<1||s>r)return Re(s);o+s>e&&(n=Re(e),o=0);let a=n.subarray(o,o+=s);return(o&7)!==0&&(o=(o|7)+1),a}}var $t=class{fn;len;next;val;constructor(e,r,n){this.fn=e,this.len=r,this.next=void 0,this.val=n}};function Ki(){}var Vi=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},Sd=Mi();function vd(t){return globalThis.Buffer!=null?Re(t):Sd(t)}var Xr=class{len;head;tail;states;constructor(){this.len=0,this.head=new $t(Ki,0,0),this.tail=this.head,this.states=null}_push(e,r,n){return this.tail=this.tail.next=new $t(e,r,n),this.len+=r,this}uint32(e){return this.len+=(this.tail=this.tail.next=new qi((e=e>>>0)<128?1:e<16384?2:e<2097152?3:e<268435456?4:5,e)).len,this}int32(e){return e<0?this._push(kn,10,De.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let r=De.fromBigInt(e);return this._push(kn,r.length(),r)}uint64Number(e){return this._push(Ba,jr(e),e)}uint64String(e){return this.uint64(BigInt(e))}int64(e){return this.uint64(e)}int64Number(e){return this.uint64Number(e)}int64String(e){return this.uint64String(e)}sint64(e){let r=De.fromBigInt(e).zzEncode();return this._push(kn,r.length(),r)}sint64Number(e){let r=De.fromNumber(e).zzEncode();return this._push(kn,r.length(),r)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push($i,1,e?1:0)}fixed32(e){return this._push(Gr,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let r=De.fromBigInt(e);return this._push(Gr,4,r.lo)._push(Gr,4,r.hi)}fixed64Number(e){let r=De.fromNumber(e);return this._push(Gr,4,r.lo)._push(Gr,4,r.hi)}fixed64String(e){return this.fixed64(BigInt(e))}sfixed64(e){return this.fixed64(e)}sfixed64Number(e){return this.fixed64Number(e)}sfixed64String(e){return this.fixed64String(e)}float(e){return this._push(_a,4,e)}double(e){return this._push(Da,8,e)}bytes(e){let r=e.length>>>0;return r===0?this._push($i,1,0):this.uint32(r)._push(Td,r,e)}string(e){let r=ka(e);return r!==0?this.uint32(r)._push(vi,r,e):this._push($i,1,0)}fork(){return this.states=new Vi(this),this.head=this.tail=new $t(Ki,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new $t(Ki,0,0),this.len=0),this}ldelim(){let e=this.head,r=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=e.next,this.tail=r,this.len+=n),this}finish(){let e=this.head.next,r=vd(this.len),n=0;for(;e!=null;)e.fn(e.val,r,n),n+=e.len,e=e.next;return r}};function $i(t,e,r){e[r]=t&255}function Ad(t,e,r){for(;t>127;)e[r++]=t&127|128,t>>>=7;e[r]=t}var qi=class extends $t{next;constructor(e,r){super(Ad,e,r),this.next=void 0}};function kn(t,e,r){for(;t.hi!==0;)e[r++]=t.lo&127|128,t.lo=(t.lo>>>7|t.hi<<25)>>>0,t.hi>>>=7;for(;t.lo>127;)e[r++]=t.lo&127|128,t.lo=t.lo>>>7;e[r++]=t.lo}function Gr(t,e,r){e[r]=t&255,e[r+1]=t>>>8&255,e[r+2]=t>>>16&255,e[r+3]=t>>>24}function Td(t,e,r){e.set(t,r)}globalThis.Buffer!=null&&(Xr.prototype.bytes=function(t){let e=t.length>>>0;return this.uint32(e),e>0&&this._push(Id,e,t),this},Xr.prototype.string=function(t){let e=globalThis.Buffer.byteLength(t);return this.uint32(e),e>0&&this._push(Bd,e,t),this});function Id(t,e,r){e.set(t,r)}function Bd(t,e,r){t.length<40?vi(t,e,r):e.utf8Write!=null?e.utf8Write(t,r):e.set(le(t),r)}function zi(){return new Xr}function Je(t,e){let r=zi();return e.encode(t,r,{lengthDelimited:!1}),r.finish()}function*et(t,e,r){let n=Yr(t);yield*e.stream(n,void 0,".",r)}var Un={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function Fn(t,e,r,n,o){return{name:t,type:e,encode:r,decode:n,stream:o}}function Vt(t){function e(i){if(t[i.toString()]==null)throw new Error("Invalid enum value");return t[i]}let r=function(s,a){let c=e(s);a.int32(c)},n=function(s){let a=s.int32();return e(a)},o=function*(s,a){};return Fn("enum",Un.VARINT,r,n,o)}function tt(t,e,r){return Fn("message",Un.LENGTH_DELIMITED,t,e,r)}var Q;(function(t){let e;(function(a){a.EOL="EOL"})(e=t.ValidityType||(t.ValidityType={}));let r;(function(a){a[a.EOL=0]="EOL"})(r||(r={})),(function(a){a.codec=()=>Vt(r)})(e=t.ValidityType||(t.ValidityType={}));let n;t.codec=()=>(n==null&&(n=tt((a,c,f={})=>{f.lengthDelimited!==!1&&c.fork(),a.value!=null&&(c.uint32(10),c.bytes(a.value)),a.signatureV1!=null&&(c.uint32(18),c.bytes(a.signatureV1)),a.validityType!=null&&(c.uint32(24),t.ValidityType.codec().encode(a.validityType,c)),a.validity!=null&&(c.uint32(34),c.bytes(a.validity)),a.sequence!=null&&(c.uint32(40),c.uint64(a.sequence)),a.ttl!=null&&(c.uint32(48),c.uint64(a.ttl)),a.publicKey!=null&&(c.uint32(58),c.bytes(a.publicKey)),a.signatureV2!=null&&(c.uint32(66),c.bytes(a.signatureV2)),a.data!=null&&(c.uint32(74),c.bytes(a.data)),f.lengthDelimited!==!1&&c.ldelim()},(a,c,f={})=>{let u={},l=c==null?a.len:a.pos+c;for(;a.pos<l;){let h=a.uint32();switch(h>>>3){case 1:{u.value=a.bytes();break}case 2:{u.signatureV1=a.bytes();break}case 3:{u.validityType=t.ValidityType.codec().decode(a);break}case 4:{u.validity=a.bytes();break}case 5:{u.sequence=a.uint64();break}case 6:{u.ttl=a.uint64();break}case 7:{u.publicKey=a.bytes();break}case 8:{u.signatureV2=a.bytes();break}case 9:{u.data=a.bytes();break}default:{a.skipType(h&7);break}}}return u},function*(a,c,f,u={}){let l=c==null?a.len:a.pos+c;for(f!=="."&&(yield{field:f.endsWith(".")?f.substring(0,f.length-1):f,type:"start",message:"IPNSEntry"});a.pos<l;){let h=a.uint32();switch(h>>>3){case 1:{yield{field:`${f}value`,value:a.bytes()};break}case 2:{yield{field:`${f}signatureV1`,value:a.bytes()};break}case 3:{yield{field:`${f}validityType`,value:t.ValidityType.codec().decode(a)};break}case 4:{yield{field:`${f}validity`,value:a.bytes()};break}case 5:{yield{field:`${f}sequence`,value:a.uint64()};break}case 6:{yield{field:`${f}ttl`,value:a.uint64()};break}case 7:{yield{field:`${f}publicKey`,value:a.bytes()};break}case 8:{yield{field:`${f}signatureV2`,value:a.bytes()};break}case 9:{yield{field:`${f}data`,value:a.bytes()};break}default:{a.skipType(h&7);break}}}f!=="."&&(yield{field:f.endsWith(".")?f.substring(0,f.length-1):f,type:"end",message:"IPNSEntry"})})),n);function o(a){return Je(a,t.codec())}t.encode=o;function i(a,c){return Qe(a,t.codec(),c)}t.decode=i;function s(a,c){return et(a,t.codec(),c)}t.stream=s})(Q||(Q={}));var pe=class extends Event{type;detail;constructor(e,r){super(e),this.type=e,this.detail=r}};var Hi=class{routing;constructor(e){this.routing=e}async put(e,r,n={}){try{await this.routing.put(e,r,n)}catch(o){throw n.onProgress?.(new pe("ipns:routing:helia:error",o)),o}}async get(e,r={}){try{return await this.routing.get(e,r)}catch(n){throw r.onProgress?.(new pe("ipns:routing:helia:error",n)),n}}toString(){return"HeliaRouting()"}};function ur(t){return new Hi(t)}var rt=class extends Error{static name="AbortError";constructor(e="The operation was aborted"){super(e),this.name="AbortError"}};var ut=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}},On=class extends Error{static name="InvalidPublicKeyError";constructor(e="Invalid public key"){super(e),this.name="InvalidPublicKeyError"}};var qt=class extends Error{static name="NotFoundError";constructor(e="Not found"){super(e),this.name="NotFoundError"}};var Pn=class extends Error{static name="InvalidMultihashError";constructor(e="Invalid Multihash"){super(e),this.name="InvalidMultihashError"}};var Wr=class extends Error{static name="UnsupportedKeyTypeError";constructor(e="Unsupported key type"){super(e),this.name="UnsupportedKeyTypeError"}};function Ha(t){return t==null?!1:(t.type==="RSA"||t.type==="Ed25519"||t.type==="secp256k1"||t.type==="ECDSA")&&t.raw instanceof Uint8Array&&typeof t.equals=="function"&&typeof t.toMultihash=="function"&&typeof t.toCID=="function"&&typeof t.verify=="function"}var ji=Symbol.for("@libp2p/peer-id");function Cd(t){return typeof t?.handleEvent=="function"}function _d(t){return t===!0||t===!1}function Rd(t){return _d(t)?t:t?.capture??!1}function Yi(t){let e={capture:Rd(t),once:!!t?.once};return t?.passive!=null&&(e.passive=t?.passive),t?.signal!=null&&(e.signal=t?.signal),e}function ja(t,e){return Yi(t).capture===Yi(e).capture}var Mn=class extends EventTarget{#e=new Map;constructor(){super()}listenerCount(e){let r=this.#e.get(e);return r==null?0:r.length}addEventListener(e,r,n){let o=Yi(n);if(o?.signal?.aborted===!0)return;let i=f=>{o.once&&this.removeEventListener(e,r,o),Cd(r)?r.handleEvent(f):r(f)},s=this.#e.get(e);if(s==null&&(s=[],this.#e.set(e,s)),s.some(f=>f.callback!==r?!1:ja(f.options,o)))return;super.addEventListener(e,i,o);let c=()=>{this.removeEventListener(e,r,o)};o.signal?.addEventListener("abort",c),s.push({callback:r,wrapper:i,options:o,onAbort:c})}removeEventListener(e,r,n){let o=this.#e.get(e);if(o==null){super.removeEventListener(e,r??null,n);return}this.#e.set(e,o.filter(i=>i.callback===r&&ja(i.options,n)?(super.removeEventListener(e,i.wrapper,n),i.options?.signal?.removeEventListener("abort",i.onAbort),!1):!0))}safeDispatchEvent(e,r={}){return this.dispatchEvent(new CustomEvent(e,r))}};function Kn(t,e){if(typeof t=="string")return Dd(t);if(typeof t=="number")return kd(t,e);throw new Error(`Value provided to ms() must be a string or number. value=${JSON.stringify(t)}`)}function Dd(t){if(typeof t!="string"||t.length===0||t.length>100)throw new Error(`Value provided to ms.parse() must be a string with length between 1 and 99. value=${JSON.stringify(t)}`);let e=/^(?<value>-?\d*\.?\d+) *(?<unit>milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|months?|mo|years?|yrs?|y)?$/i.exec(t);if(!e?.groups)return NaN;let{value:r,unit:n="ms"}=e.groups,o=parseFloat(r),i=n.toLowerCase();switch(i){case"years":case"year":case"yrs":case"yr":case"y":return o*315576e5;case"months":case"month":case"mo":return o*26298e5;case"weeks":case"week":case"w":return o*6048e5;case"days":case"day":case"d":return o*864e5;case"hours":case"hour":case"hrs":case"hr":case"h":return o*36e5;case"minutes":case"minute":case"mins":case"min":case"m":return o*6e4;case"seconds":case"second":case"secs":case"sec":case"s":return o*1e3;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return o;default:throw new Error(`Unknown unit "${i}" provided to ms.parse(). value=${JSON.stringify(t)}`)}}function Ld(t){let e=Math.abs(t);return e>=315576e5?`${Math.round(t/315576e5)}y`:e>=26298e5?`${Math.round(t/26298e5)}mo`:e>=6048e5?`${Math.round(t/6048e5)}w`:e>=864e5?`${Math.round(t/864e5)}d`:e>=36e5?`${Math.round(t/36e5)}h`:e>=6e4?`${Math.round(t/6e4)}m`:e>=1e3?`${Math.round(t/1e3)}s`:`${t}ms`}function Nd(t){let e=Math.abs(t);return e>=315576e5?zt(t,e,315576e5,"year"):e>=26298e5?zt(t,e,26298e5,"month"):e>=6048e5?zt(t,e,6048e5,"week"):e>=864e5?zt(t,e,864e5,"day"):e>=36e5?zt(t,e,36e5,"hour"):e>=6e4?zt(t,e,6e4,"minute"):e>=1e3?zt(t,e,1e3,"second"):`${t} ms`}function kd(t,e){if(typeof t!="number"||!Number.isFinite(t))throw new Error("Value provided to ms.format() must be of type number.");return e?.long?Nd(t):Ld(t)}function zt(t,e,r,n){let o=e>=r*1.5;return`${Math.round(t/r)} ${n}${o?"s":""}`}function Zi(t){r.debug=r,r.default=r,r.coerce=c,r.disable=i,r.enable=o,r.enabled=s,r.humanize=Kn,r.destroy=f,Object.keys(t).forEach(u=>{r[u]=t[u]}),r.names=[],r.skips=[],r.formatters={};function e(u){let l=0;for(let h=0;h<u.length;h++)l=(l<<5)-l+u.charCodeAt(h),l|=0;return r.colors[Math.abs(l)%r.colors.length]}r.selectColor=e;function r(u,l){let h,m=null,R,b;function y(...S){if(!y.enabled)return;let T=y,g=Number(new Date),D=g-(h||g);T.diff=D,T.prev=h,T.curr=g,h=g,S[0]=r.coerce(S[0]),typeof S[0]!="string"&&S.unshift("%O");let C=0;S[0]=S[0].replace(/%([a-zA-Z%])/g,(q,w)=>{if(q==="%%")return"%";C++;let E=r.formatters[w];if(typeof E=="function"){let v=S[C];q=E.call(T,v),S.splice(C,1),C--}return q}),r.formatArgs.call(T,S),l?.onLog!=null&&l.onLog(...S),(T.log||r.log).apply(T,S)}return y.namespace=u,y.useColors=r.useColors(),y.color=r.selectColor(u),y.extend=n,y.destroy=r.destroy,Object.defineProperty(y,"enabled",{enumerable:!0,configurable:!1,get:()=>m!==null?m:(R!==r.namespaces&&(R=r.namespaces,b=r.enabled(u)),b),set:S=>{m=S}}),typeof r.init=="function"&&r.init(y),y}function n(u,l){let h=r(this.namespace+(typeof l>"u"?":":l)+u);return h.log=this.log,h}function o(u){r.save(u),r.namespaces=u,r.names=[],r.skips=[];let l,h=(typeof u=="string"?u:"").split(/[\s,]+/),m=h.length;for(l=0;l<m;l++)h[l]&&(u=h[l].replace(/\*/g,".*?"),u[0]==="-"?r.skips.push(new RegExp("^"+u.substr(1)+"$")):r.names.push(new RegExp("^"+u+"$")))}function i(){let u=[...r.names.map(a),...r.skips.map(a).map(l=>"-"+l)].join(",");return r.enable(""),u}function s(u){if(u[u.length-1]==="*")return!0;let l,h;for(l=0,h=r.skips.length;l<h;l++)if(r.skips[l].test(u))return!1;for(l=0,h=r.names.length;l<h;l++)if(r.names[l].test(u))return!0;return!1}function a(u){return u.toString().substring(2,u.toString().length-2).replace(/\.\*\?$/,"*")}function c(u){return u instanceof Error?u.stack??u.message:u}function f(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")}return r.setupFormatters(r.formatters),r.enable(r.load()),r}var $n=$d(),Ud=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"];function Fd(){return typeof window<"u"&&window.process&&(window.process.type==="renderer"||window.process.__nwjs)?!0:typeof navigator<"u"&&navigator.userAgent?.toLowerCase().match(/(edge|trident)\/(\d+)/)!=null?!1:typeof document<"u"&&document.documentElement?.style?.WebkitAppearance||typeof window<"u"&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator<"u"&&navigator.userAgent?.toLowerCase().match(/firefox\/(\d+)/)!=null&&parseInt(RegExp.$1,10)>=31||typeof navigator<"u"&&navigator.userAgent?.toLowerCase().match(/applewebkit\/(\d+)/)}function Od(t){if(t[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+t[0]+(this.useColors?"%c ":" ")+"+"+Kn(this.diff),!this.useColors)return;let e="color: "+this.color;t.splice(1,0,e,"color: inherit");let r=0,n=0;t[0].replace(/%[a-zA-Z%]/g,o=>{o!=="%%"&&(r++,o==="%c"&&(n=r))}),t.splice(n,0,e)}var Pd=console.debug??console.log??(()=>{});function Md(t){try{t?$n?.setItem("debug",t):$n?.removeItem("debug")}catch{}}function Kd(){let t;try{t=$n?.getItem("debug")}catch{}return!t&&typeof globalThis.process<"u"&&"env"in globalThis.process&&(t=globalThis.process.env.DEBUG),t}function $d(){try{return localStorage}catch{}}function Vd(t){t.j=function(e){try{return JSON.stringify(e)}catch(r){return"[UnexpectedJSONParseError]: "+r.message}}}var Ya=Zi({formatArgs:Od,save:Md,load:Kd,useColors:Fd,setupFormatters:Vd,colors:Ud,storage:$n,log:Pd});var Ie=Ya;Ie.formatters.b=t=>t==null?"undefined":re.baseEncode(t);Ie.formatters.t=t=>t==null?"undefined":bt.baseEncode(t);Ie.formatters.m=t=>t==null?"undefined":_i.baseEncode(t);Ie.formatters.p=t=>t==null?"undefined":t.toString();Ie.formatters.c=t=>t==null?"undefined":t.toString();Ie.formatters.k=t=>t==null?"undefined":t.toString();Ie.formatters.a=t=>t==null?"undefined":t.toString();function Za(t,e=""){let r=Ga(t.message),n=Ga(t.stack);return r!=null&&n!=null?n.includes(r)?`${n.split(`
|
|
2
|
+
"use strict";var HeliaIpns=(()=>{var wd=Object.create;var Zn=Object.defineProperty;var xd=Object.getOwnPropertyDescriptor;var Ed=Object.getOwnPropertyNames;var Sd=Object.getPrototypeOf,Ad=Object.prototype.hasOwnProperty;var Td=(e,t)=>()=>{try{return t||e((t={exports:{}}).exports,t),t.exports}catch(r){throw t=0,r}},Dt=(e,t)=>{for(var r in t)Zn(e,r,{get:t[r],enumerable:!0})},fc=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Ed(t))!Ad.call(e,o)&&o!==r&&Zn(e,o,{get:()=>t[o],enumerable:!(n=xd(t,o))||n.enumerable});return e};var Gn=(e,t,r)=>(r=e!=null?wd(Sd(e)):{},fc(t||!e||!e.__esModule?Zn(r,"default",{value:e,enumerable:!0}):r,e)),Bd=e=>fc(Zn({},"__esModule",{value:!0}),e);var jn=Td((nS,nc)=>{var rS=(function(){typeof nc<"u"&&(nc.exports=b);var e=86400,t=3200,r=146097*t/400,n=e*r,o=1e3*n,i=864e13,s=4294967296,a=1e6,c="000000000",u=Math.trunc||function(w){var E=w-w%1;return E==0&&(w<0||w===0&&1/w!=1/0)?-0:E},f=b.prototype,l=(b.fromDate=function(w){return new b(+w)},b.fromInt64BE=N(0,1,2,3,0,4),b.fromInt64LE=N(3,2,1,0,4,0),b.fromString=function(L){var E,A=new b,L=(L+="").replace(/^\s*[+\-]?\d+/,function(z){var z=+z,I=1970+(z-1970)%400;return A.year=z-I,I}).replace(/(?:Z|([+\-]\d{2}):?(\d{2}))$/,function(D,z,I){return z<0&&(I*=-1),E=6e4*(60*+z+ +I),""}).replace(/\.\d+$/,function(D){return A.nano=+(D+c).substr(1,9),""}).split(/\D+/);if(1<L.length?L[1]--:L[1]=0,A.time=E=Date.UTC.apply(Date,L)-(E||0),isNaN(E))throw new TypeError("Invalid Date");return g(A)},b.fromTimeT=function(w){return B(w,0)},f.year=0,f.time=0,f.nano=0,f.addNano=function(w){return this.nano+=+w||0,this},f.getNano=function(){var w=g(this);return(w.time%1e3*a+ +w.nano+1e9)%1e9},f.getTimeT=function(){var E=g(this),w=Math.floor(E.time/1e3),E=E.year;return E&&(w+=E*r*e/t),w},f.getYear=function(){return this.toDate().getUTCFullYear()+this.year},f.toDate=function(){return S(g(this).time)},f.toJSON=function(){return this.toString().replace(/0{1,6}Z$/,"Z")},f.toString=function(w){var E=this,A=E.toDate(),L={H:function(){return $(A.getUTCHours())},L:function(){return q(A.getUTCMilliseconds(),3)},M:function(){return $(A.getUTCMinutes())},N:function(){return q(E.getNano(),9)},S:function(){return $(A.getUTCSeconds())},Y:function(){var D=E.getYear();return 999999<D?"+"+D:9999<D?"+"+q(D,6):0<=D?q(D,4):-999999<=D?"-"+q(-D,6):D},a:function(){return m[A.getUTCDay()]},b:function(){return h[A.getUTCMonth()]},d:function(){return $(A.getUTCDate())},e:function(){return(function(D){return(9<D?"":" ")+(0|D)})(A.getUTCDate())},m:function(){return $(A.getUTCMonth()+1)}};return(function D(z){return z.replace(/%./g,function(I){var O=I[1],F=R[O],O=L[O];return F?D(F):O?O():I})})(w||l)},f.writeInt64BE=y(0,1,2,3,0,4),f.writeInt64LE=y(3,2,1,0,4,0),"%Y-%m-%dT%H:%M:%S.%NZ"),h=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],m=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],R={"%":"%",F:"%Y-%m-%d",n:`
|
|
3
|
+
`,R:"%H:%M",T:"%H:%M:%S",t:" ",X:"%T",Z:"GMT",z:"+0000"};return b;function b(w,E,A){var L=this;if(!(L instanceof b))return new b(w,E,A);L.time=+w||0,L.nano=+E||0,L.year=+A||0,g(L)}function g(w){var E,A,L,D=w.year,z=w.time,I=w.nano,F=((I<0||a<=I)&&(I-=(A=Math.floor(I/a))*a,z+=A,A=1),D%t);return(z<-i||i<z||F)&&((E=u(z/o))&&(D+=E*t,z-=E*o),(L=S(z)).setUTCFullYear(F+L.getUTCFullYear()),L=(z=+L)+(E=u((D-=F)/t))*o,E&&-i<=L&&L<=i&&(D-=E*t,z=L),A=1),A&&(w.year=D,w.time=z,w.nano=I),w}function S(w){var E=new Date(0);return E.setTime(w),E}function B(D,L){D=+D||0;var A=u((L=(L|0)*s)/n)+u(D/n),L=L%n+D%n,D=u(L/n);return D&&(A+=D,L-=D*n),new b(1e3*L,0,A*t)}function y(w,E,A,L,D,z){return function(F,O){var Y=g(this);F=F||new Array(8),C(F,O|=0);var W=Math.floor(Y.time/1e3),Y=Y.year*(r*e/t),P=u(Y/s)+u(W/s),Y=Y%s+W%s,W=Math.floor(Y/s);return W&&(P+=W,Y-=W*s),I(F,O+D,P),I(F,O+z,Y),F};function I(F,O,P){F[O+w]=P>>24&255,F[O+E]=P>>16&255,F[O+A]=P>>8&255,F[O+L]=255&P}}function N(w,E,A,L,D,z){return function(F,O){C(F,O|=0);var P=I(F,O+D);return B(I(F,O+z),P)};function I(F,O){return 16777216*F[O+w]+(F[O+E]<<16|F[O+A]<<8|F[O+L])}}function C(w,E){if(w=w&&w.length,w==null)throw new TypeError("Invalid Buffer");if(w<E+8)throw new RangeError("Out of range")}function $(w){return(9<w?"":"0")+(0|w)}function q(w,E){return(c+(0|w)).substr(-E)}})()});var sg={};Dt(sg,{IPNSEntry:()=>Q,InvalidEmbeddedPublicKeyError:()=>gr,InvalidRecordDataError:()=>en,InvalidTopicError:()=>Wr,InvalidValueError:()=>le,RecordExpiredError:()=>Jr,RecordNotFoundError:()=>pr,RecordObsoleteError:()=>mr,RecordTooLargeError:()=>tn,RecordsFailedValidationError:()=>Xr,SignatureCreationError:()=>Qr,SignatureVerificationError:()=>Ht,UnsupportedValidityError:()=>ze,createIPNSRecord:()=>Hr,heliaIPNSRouting:()=>wr,ipns:()=>og,ipnsResolver:()=>ig,ipnsSelector:()=>Qt,ipnsValidator:()=>$t,isLocalStoreRouting:()=>Yn,multihashFromIPNSRoutingKey:()=>Li,multihashToIPNSRoutingKey:()=>Xt,pubSubIPNSRouting:()=>hd,routerName:()=>$e});var ji={};Dt(ji,{base32:()=>Ee,base32hex:()=>Ud,base32hexpad:()=>Pd,base32hexpadupper:()=>Md,base32hexupper:()=>Od,base32pad:()=>Fd,base32padupper:()=>kd,base32upper:()=>Ld,base32z:()=>Kd});var cg=new Uint8Array(0);function dc(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function zt(e){if(e instanceof Uint8Array&&e.constructor.name==="Uint8Array")return qe(e);if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return qe(new Uint8Array(e.buffer,e.byteOffset,e.byteLength));throw new Error("Unknown type, must be binary type")}function hc(e){let t=new Uint8Array(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}var lc=4096;function pc(e){let t=e.length;if(t<=lc)return String.fromCharCode.apply(String,e);let r="",n=0;for(;n<t;)r+=String.fromCharCode.apply(String,e.subarray(n,n+=lc));return r}function Id(e){return e?.buffer instanceof ArrayBuffer}function qe(e){return Id(e)?e:e.slice()}function vd(e,t,r){if(e.length>=255)throw new TypeError("Alphabet too long");for(var n=new Uint8Array(256),o=0;o<n.length;o++)n[o]=255;for(var i=0;i<e.length;i++){var s=e.charAt(i),a=s.charCodeAt(0);if(n[a]!==255)throw new TypeError(s+" is ambiguous");if(n[a]=i,r){var c=s.toLowerCase().charCodeAt(0),u=s.toUpperCase().charCodeAt(0);c!==a&&(n[c]=i),u!==a&&(n[u]=i)}}var f=e.length,l=e.charAt(0),h=Math.log(f)/Math.log(256),m=Math.log(256)/Math.log(f);function R(S){if(S instanceof Uint8Array||(ArrayBuffer.isView(S)?S=new Uint8Array(S.buffer,S.byteOffset,S.byteLength):Array.isArray(S)&&(S=Uint8Array.from(S))),!(S instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(S.length===0)return"";for(var B=0,y=0,N=0,C=S.length;N!==C&&S[N]===0;)N++,B++;for(var $=(C-N)*m+1>>>0,q=new Uint8Array($);N!==C;){for(var w=S[N],E=0,A=$-1;(w!==0||E<y)&&A!==-1;A--,E++)w+=256*q[A]>>>0,q[A]=w%f>>>0,w=w/f>>>0;if(w!==0)throw new Error("Non-zero carry");y=E,N++}for(var L=$-y;L!==$&&q[L]===0;)L++;for(var D=l.repeat(B);L<$;++L)D+=e.charAt(q[L]);return D}function b(S){if(typeof S!="string")throw new TypeError("Expected String");if(S.length===0)return new Uint8Array;var B=0;if(S[B]!==" "){for(var y=0,N=0;S[B]===l;)y++,B++;for(var C=(S.length-B)*h+1>>>0,$=new Uint8Array(C);S[B];){var q=n[S.charCodeAt(B)];if(q===255)return;for(var w=0,E=C-1;(q!==0||w<N)&&E!==-1;E--,w++)q+=f*$[E]>>>0,$[E]=q%256>>>0,q=q/256>>>0;if(q!==0)throw new Error("Non-zero carry");N=w,B++}if(S[B]!==" "){for(var A=C-N;A!==C&&$[A]===0;)A++;for(var L=new Uint8Array(y+(C-A)),D=y;A!==C;)L[D++]=$[A++];return L}}}function g(S){var B=b(S);if(B)return B;throw new Error(`Non-${t} character`)}return{encode:R,decodeUnsafe:b,decode:g}}var Cd=vd,_d=Cd,gc=_d;var $i=class{name;prefix;baseEncode;constructor(t,r,n){this.name=t,this.prefix=r,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},qi=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,r,n){this.name=t,this.prefix=r;let o=r.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return yc(this,t)}},zi=class{decoders;constructor(t){this.decoders=t}or(t){return yc(this,t)}decode(t){let r=t[0],n=this.decoders[r];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function yc(e,t){return new zi({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var Hi=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,r,n,o){this.name=t,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new $i(t,r,n),this.decoder=new qi(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function ur({name:e,prefix:t,encode:r,decode:n}){return new Hi(e,t,r,n)}function xe({name:e,prefix:t,alphabet:r,caseInsensitive:n=!1}){let{encode:o,decode:i}=gc(r,e,n);return ur({prefix:t,name:e,encode:o,decode:s=>zt(i(s))})}function Rd(e,t,r,n){let o=e.length;for(;e[o-1]==="=";)--o;let i=new Uint8Array(o*r/8|0),s=0,a=0,c=0;for(let u=0;u<o;++u){let f=t[e[u]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|f,s+=r,s>=8&&(s-=8,i[c++]=255&a>>s)}if(s>=r||(255&a<<8-s)!==0)throw new SyntaxError("Unexpected end of data");return i}function Nd(e,t,r){let n=t[t.length-1]==="=",o=(1<<r)-1,i="",s=0,a=0;for(let c=0;c<e.length;++c)for(a=a<<8|e[c],s+=8;s>r;)s-=r,i+=t[o&a>>s];if(s!==0&&(i+=t[o&a<<r-s]),n)for(;(i.length*r&7)!==0;)i+="=";return i}function Dd(e,t){let r={};for(let n=0;n<e.length;++n)if(r[e[n]]=n,t){let o=e[n].toLowerCase(),i=e[n].toUpperCase();o!==e[n]&&(r[o]=n),i!==e[n]&&(r[i]=n)}return r}function ft({name:e,prefix:t,bitsPerChar:r,alphabet:n,caseInsensitive:o=!1}){let i=Dd(n,o);return ur({prefix:t,name:e,encode(s){return Nd(s,n,r)},decode(s){return Rd(s,i,r,e)}})}var Ee=ft({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5,caseInsensitive:!0}),Ld=ft({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5,caseInsensitive:!0}),Fd=ft({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5,caseInsensitive:!0}),kd=ft({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5,caseInsensitive:!0}),Ud=ft({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5,caseInsensitive:!0}),Od=ft({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5,caseInsensitive:!0}),Pd=ft({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5,caseInsensitive:!0}),Md=ft({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5,caseInsensitive:!0}),Kd=ft({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Yi={};Dt(Yi,{base36:()=>Ct,base36upper:()=>Vd});var Ct=xe({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz",caseInsensitive:!0}),Vd=xe({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",caseInsensitive:!0});var Zi={};Dt(Zi,{base58btc:()=>rt,base58flickr:()=>$d});var rt=xe({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),$d=xe({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var qd=xc,bc=128,zd=127,Hd=~zd,jd=Math.pow(2,31);function xc(e,t,r){t=t||[],r=r||0;for(var n=r;e>=jd;)t[r++]=e&255|bc,e/=128;for(;e&Hd;)t[r++]=e&255|bc,e>>>=7;return t[r]=e|0,xc.bytes=r-n+1,t}var Yd=Gi,Zd=128,wc=127;function Gi(e,n){var r=0,n=n||0,o=0,i=n,s,a=e.length;do{if(i>=a)throw Gi.bytes=0,new RangeError("Could not decode varint");s=e[i++],r+=o<28?(s&wc)<<o:(s&wc)*Math.pow(2,o),o+=7}while(s>=Zd);return Gi.bytes=i-n,r}var Gd=Math.pow(2,7),Xd=Math.pow(2,14),Wd=Math.pow(2,21),Qd=Math.pow(2,28),Jd=Math.pow(2,35),th=Math.pow(2,42),eh=Math.pow(2,49),rh=Math.pow(2,56),nh=Math.pow(2,63),oh=function(e){return e<Gd?1:e<Xd?2:e<Wd?3:e<Qd?4:e<Jd?5:e<th?6:e<eh?7:e<rh?8:e<nh?9:10},ih={encode:qd,decode:Yd,encodingLength:oh},sh=ih,Yr=sh;function Zr(e,t=0){let r=Yr.decode(e,t),n=Yr.decode.bytes;if(n>9)throw new RangeError("Invalid varint: too long");if(n>1&&e[t+n-1]===0)throw new RangeError("Invalid varint: not minimally encoded");return[r,n]}function fr(e,t,r=0){return Yr.encode(e,t,r),t}function lr(e){return Yr.encodingLength(e)}function hr(e,t){let r=t.byteLength,n=lr(e),o=n+lr(r),i=new Uint8Array(o+r);return fr(e,i,0),fr(r,i,n),i.set(t,o),new dr(e,r,t,i)}function Se(e){let t=zt(e),[r,n]=Zr(t),[o,i]=Zr(t.subarray(n)),s=t.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new dr(r,o,s,t)}function Ec(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&dc(e.bytes,r.bytes)}}var dr=class{code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=qe(n),this.bytes=qe(o)}};function Sc(e,t){let{bytes:r,version:n}=e;return n===0?ch(r,Xi(e),t??rt.encoder):uh(r,Xi(e),t??Ee.encoder)}var Ac=new WeakMap;function Xi(e){let t=Ac.get(e);if(t==null){let r=new Map;return Ac.set(e,r),r}return t}var at=class e{code;version;multihash;bytes;"/";constructor(t,r,n,o){this.code=r,this.version=t,this.multihash=n,this.bytes=qe(o),this["/"]=this.bytes}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:r}=this;if(t!==Gr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==fh)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return e.createV0(r)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:t,digest:r}=this.multihash,n=hr(t,r);return e.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return e.equals(this,t)}static equals(t,r){let n=r;return n!=null&&t.code===n.code&&t.version===n.version&&Ec(t.multihash,n.multihash)}toString(t){return Sc(this,t)}toJSON(){return{"/":Sc(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let r=t;if(r instanceof e)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:i,bytes:s}=r;return new e(n,o,i,s??Tc(n,o,i.bytes))}else if(r[lh]===!0){let{version:n,multihash:o,code:i}=r,s=Se(o);return e.create(n,i,s)}else return null}static create(t,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(r!==Gr)throw new Error(`Version 0 CID must use dag-pb (code: ${Gr}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=Tc(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,Gr,t)}static createV1(t,r){return e.create(1,t,r)}static decode(t){let[r,n]=e.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(t){let r=e.inspectBytes(t),n=r.size-r.multihashSize,o=zt(t.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let i=o.subarray(r.multihashSize-r.digestSize),s=new dr(r.multihashCode,r.digestSize,i,o);return[r.version===0?e.createV0(s):e.createV1(r.codec,s),t.subarray(r.size)]}static inspectBytes(t){let r=0,n=()=>{let[l,h]=Zr(t.subarray(r));return r+=h,l},o=n(),i=Gr;if(o===18?(o=0,r=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let s=r,a=n(),c=n(),u=r+c,f=u-s;return{version:o,codec:i,multihashCode:a,digestSize:c,multihashSize:f,size:u}}static parse(t,r){let[n,o]=ah(t,r),i=e.decode(o);if(i.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Xi(i).set(n,t),i}};function ah(e,t){switch(e[0]){case"Q":{let r=t??rt;return[rt.prefix,r.decode(`${rt.prefix}${e}`)]}case rt.prefix:{let r=t??rt;return[rt.prefix,r.decode(e)]}case Ee.prefix:{let r=t??Ee;return[Ee.prefix,r.decode(e)]}case Ct.prefix:{let r=t??Ct;return[Ct.prefix,r.decode(e)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[e[0],t.decode(e)]}}}function ch(e,t,r){let{prefix:n}=r;if(n!==rt.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=t.get(n);if(o==null){let i=r.encode(e).slice(1);return t.set(n,i),i}else return o}function uh(e,t,r){let{prefix:n}=r,o=t.get(n);if(o==null){let i=r.encode(e);return t.set(n,i),i}else return o}var Gr=112,fh=18;function Tc(e,t,r){let n=lr(e),o=n+lr(t),i=new Uint8Array(o+r.byteLength);return fr(e,i,0),fr(t,i,n),i.set(r,o),i}var lh=Symbol.for("@ipld/js-cid/CID");var Wn=BigInt(6e4)*5000000n,Bc=5;var Xr=class extends Error{static name="RecordsFailedValidationError";name="RecordsFailedValidationError"},le=class extends Error{static name="InvalidValueError";name="InvalidValueError"},Wr=class extends Error{static name="InvalidTopicError";name="InvalidTopicError"},pr=class extends Error{static name="RecordNotFoundError";name="RecordNotFoundError"},mr=class extends Error{static name="RecordObsoleteError";name="RecordObsoleteError";record;constructor(t,r){super(t),this.record=r}},Qr=class extends Error{static name="SignatureCreationError";name="SignatureCreationError"},Ht=class extends Error{static name="SignatureVerificationError";name="SignatureVerificationError"},Jr=class extends Error{static name="RecordExpiredError";name="RecordExpiredError"},ze=class extends Error{static name="UnsupportedValidityError";name="UnsupportedValidityError"},tn=class extends Error{static name="RecordTooLargeError";name="RecordTooLargeError"},en=class extends Error{static name="InvalidRecordDataError";name="InvalidRecordDataError"},gr=class extends Error{static name="InvalidEmbeddedPublicKeyError";name="InvalidEmbeddedPublicKeyError"};function jt(e=0){return new Uint8Array(e)}function ct(e=0){return new Uint8Array(e)}var dh=Math.pow(2,7),hh=Math.pow(2,14),ph=Math.pow(2,21),Ic=Math.pow(2,28),vc=Math.pow(2,35),Cc=Math.pow(2,42),_c=Math.pow(2,49),It=128,Te=127;function Lt(e){if(e<dh)return 1;if(e<hh)return 2;if(e<ph)return 3;if(e<Ic)return 4;if(e<vc)return 5;if(e<Cc)return 6;if(e<_c)return 7;if(Number.MAX_SAFE_INTEGER!=null&&e>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function yr(e,t,r=0){switch(Lt(e)){case 8:t[r++]=e&255|It,e/=128;case 7:t[r++]=e&255|It,e/=128;case 6:t[r++]=e&255|It,e/=128;case 5:t[r++]=e&255|It,e/=128;case 4:t[r++]=e&255|It,e>>>=7;case 3:t[r++]=e&255|It,e>>>=7;case 2:t[r++]=e&255|It,e>>>=7;case 1:{t[r++]=e&255,e>>>=7;break}default:throw new Error("unreachable")}return t}function br(e,t){let r=e[t],n=0;if(n+=r&Te,r<It||(r=e[t+1],n+=(r&Te)<<7,r<It)||(r=e[t+2],n+=(r&Te)<<14,r<It)||(r=e[t+3],n+=(r&Te)<<21,r<It)||(r=e[t+4],n+=(r&Te)*Ic,r<It)||(r=e[t+5],n+=(r&Te)*vc,r<It)||(r=e[t+6],n+=(r&Te)*Cc,r<It)||(r=e[t+7],n+=(r&Te)*_c,r<It))return n;throw new RangeError("Could not decode varint")}function mh(e){return e.buffer instanceof ArrayBuffer}function xt(e){return mh(e)?e:e.slice()}var Wi=new Float32Array([-0]),Be=new Uint8Array(Wi.buffer);function Rc(e,t,r){Wi[0]=e,t[r]=Be[0],t[r+1]=Be[1],t[r+2]=Be[2],t[r+3]=Be[3]}function Nc(e,t){return Be[0]=e[t],Be[1]=e[t+1],Be[2]=e[t+2],Be[3]=e[t+3],Wi[0]}var Qi=new Float64Array([-0]),St=new Uint8Array(Qi.buffer);function Dc(e,t,r){Qi[0]=e,t[r]=St[0],t[r+1]=St[1],t[r+2]=St[2],t[r+3]=St[3],t[r+4]=St[4],t[r+5]=St[5],t[r+6]=St[6],t[r+7]=St[7]}function Lc(e,t){return St[0]=e[t],St[1]=e[t+1],St[2]=e[t+2],St[3]=e[t+3],St[4]=e[t+4],St[5]=e[t+5],St[6]=e[t+6],St[7]=e[t+7],Qi[0]}var gh=BigInt(Number.MAX_SAFE_INTEGER),yh=BigInt(Number.MIN_SAFE_INTEGER),Ft=class e{lo;hi;constructor(t,r){this.lo=t|0,this.hi=r|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(r+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(BigInt(r)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?t<16384?t<128?1:2:t<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return He;if(t<gh&&t>yh)return this.fromNumber(Number(t));let r=t<0n;r&&(t=-t);let n=t>>32n,o=t-(n<<32n);return r&&(n=~n|0n,o=~o|0n,++o>Fc&&(o=0n,++n>Fc&&(n=0n))),new e(Number(o),Number(n))}static fromNumber(t){if(t===0)return He;let r=t<0;r&&(t=-t);let n=t>>>0,o=(t-n)/4294967296>>>0;return r&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new e(n,o)}static from(t){return typeof t=="number"?e.fromNumber(t):typeof t=="bigint"?e.fromBigInt(t):typeof t=="string"?e.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new e(t.low>>>0,t.high>>>0):He}},He=new Ft(0,0);He.toBigInt=function(){return 0n};He.zzEncode=He.zzDecode=function(){return this};He.length=function(){return 1};var Fc=4294967296n;function kc(e){let t=0,r=0;for(let n=0;n<e.length;++n)r=e.charCodeAt(n),r<128?t+=1:r<2048?t+=2:(r&64512)===55296&&(e.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function Uc(e,t,r){if(r-t<1)return"";let o,i=[],s=0,a;for(;t<r;)a=e[t++],a<128?i[s++]=a:a>191&&a<224?i[s++]=(a&31)<<6|e[t++]&63:a>239&&a<365?(a=((a&7)<<18|(e[t++]&63)<<12|(e[t++]&63)<<6|e[t++]&63)-65536,i[s++]=55296+(a>>10),i[s++]=56320+(a&1023)):i[s++]=(a&15)<<12|(e[t++]&63)<<6|e[t++]&63,s>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,i)),s=0);return o!=null?(s>0&&o.push(String.fromCharCode.apply(String,i.slice(0,s))),o.join("")):String.fromCharCode.apply(String,i.slice(0,s))}function Ji(e,t,r){let n=r,o,i;for(let s=0;s<e.length;++s)o=e.charCodeAt(s),o<128?t[r++]=o:o<2048?(t[r++]=o>>6|192,t[r++]=o&63|128):(o&64512)===55296&&((i=e.charCodeAt(s+1))&64512)===56320?(o=65536+((o&1023)<<10)+(i&1023),++s,t[r++]=o>>18|240,t[r++]=o>>12&63|128,t[r++]=o>>6&63|128,t[r++]=o&63|128):(t[r++]=o>>12|224,t[r++]=o>>6&63|128,t[r++]=o&63|128);return r-n}function Jt(e,t){return RangeError(`index out of range: ${e.pos} + ${t??1} > ${e.len}`)}function Qn(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}var ts=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=xt(t),this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,Jt(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw Jt(this,4);return Qn(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Jt(this,4);return Qn(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Jt(this,4);let t=Nc(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Jt(this,4);let t=Lc(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),r=this.pos,n=this.pos+t;if(n>this.len)throw Jt(this,t);return this.pos+=t,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let t=this.bytes();return Uc(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Jt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Jt(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new Ft(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw Jt(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<r*7)>>>0,t}if(this.len-this.pos>4){for(;r<5;++r)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;r<5;++r){if(this.pos>=this.len)throw Jt(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Jt(this,8);let t=Qn(this.buf,this.pos+=4),r=Qn(this.buf,this.pos+=4);return new Ft(t,r)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=br(this.buf,this.pos);return this.pos+=Lt(t),t}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function rn(e){return new ts(e instanceof Uint8Array?e:e.subarray())}function nn(e,t,r){let n=rn(e);return t.decode(n,void 0,r)}var es={};Dt(es,{base10:()=>bh});var bh=xe({prefix:"9",name:"base10",alphabet:"0123456789"});var rs={};Dt(rs,{base16:()=>wh,base16upper:()=>xh});var wh=ft({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4,caseInsensitive:!0}),xh=ft({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4,caseInsensitive:!0});var ns={};Dt(ns,{base2:()=>Eh});var Eh=ft({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var os={};Dt(os,{base256emoji:()=>Ih});var Pc=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),Sh=Pc.reduce((e,t,r)=>(e[r]=t,e),[]),Ah=Pc.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function Th(e){return e.reduce((t,r)=>(t+=Sh[r],t),"")}function Bh(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=Ah[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(o)}return new Uint8Array(t)}var Ih=ur({prefix:"\u{1F680}",name:"base256emoji",encode:Th,decode:Bh});var ss={};Dt(ss,{base64:()=>is,base64pad:()=>vh,base64url:()=>Ch,base64urlpad:()=>_h});var is=ft({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),vh=ft({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Ch=ft({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),_h=ft({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var as={};Dt(as,{base8:()=>Rh});var Rh=ft({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var cs={};Dt(cs,{identity:()=>Nh});var Nh=ur({prefix:"\0",name:"identity",encode:e=>pc(zt(e)),decode:e=>zt(hc(e))});var Zg=new TextEncoder,Gg=new TextDecoder;var us={};Dt(us,{identity:()=>te});var Mc=0,Fh="identity",Kc=zt;function kh(e,t){if(t?.truncate!=null&&t.truncate!==e.byteLength){if(t.truncate<0||t.truncate>e.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${e.byteLength}`);e=e.subarray(0,t.truncate)}return hr(Mc,Kc(e))}var te={code:Mc,name:Fh,encode:Kc,digest:kh};var ds={};Dt(ds,{sha256:()=>on,sha512:()=>Oh});var Uh=20;function ls({name:e,code:t,encode:r,minDigestLength:n,maxDigestLength:o}){return new fs(e,t,r,n,o)}var fs=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,r,n,o,i){this.name=t,this.code=r,this.encode=n,this.minDigestLength=o??Uh,this.maxDigestLength=i}digest(t,r){if(r?.truncate!=null){if(r.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&r.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(t instanceof Uint8Array){let n=this.encode(t);return n instanceof Uint8Array?Vc(n,this.code,r?.truncate):n.then(o=>Vc(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function Vc(e,t,r){if(r!=null&&r!==e.byteLength){if(r>e.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${e.byteLength}`);e=e.subarray(0,r)}return hr(t,e)}function qc(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var on=ls({name:"sha2-256",code:18,encode:qc("SHA-256")}),Oh=ls({name:"sha2-512",code:19,encode:qc("SHA-512")});var hs={...cs,...ns,...as,...es,...rs,...ji,...Yi,...Zi,...ss,...os},cy={...ds,...us};function Hc(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var zc=Hc("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),ps=Hc("ascii","a",e=>{let t="a";for(let r=0;r<e.length;r++)t+=String.fromCharCode(e[r]);return t},e=>{e=e.substring(1);let t=ct(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),Ph={utf8:zc,"utf-8":zc,hex:hs.base16,latin1:ps,ascii:ps,binary:ps,...hs},Jn=Ph;function nt(e,t="utf8"){let r=Jn[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function ms(e){let t=e??8192,r=t>>>1,n,o=t;return function(s){if(s<1||s>r)return ct(s);o+s>t&&(n=ct(t),o=0);let a=n.subarray(o,o+=s);return(o&7)!==0&&(o=(o|7)+1),a}}var je=class{fn;len;next;val;constructor(t,r,n){this.fn=t,this.len=r,this.next=void 0,this.val=n}};function gs(){}var bs=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Mh=ms();function Kh(e){return globalThis.Buffer!=null?ct(e):Mh(e)}var an=class{len;head;tail;states;constructor(){this.len=0,this.head=new je(gs,0,0),this.tail=this.head,this.states=null}_push(t,r,n){return this.tail=this.tail.next=new je(t,r,n),this.len+=r,this}uint32(t){return this.len+=(this.tail=this.tail.next=new ws((t=t>>>0)<128?1:t<16384?2:t<2097152?3:t<268435456?4:5,t)).len,this}int32(t){return t<0?this._push(to,10,Ft.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let r=Ft.fromBigInt(t);return this._push(to,r.length(),r)}uint64Number(t){return this._push(yr,Lt(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let r=Ft.fromBigInt(t).zzEncode();return this._push(to,r.length(),r)}sint64Number(t){let r=Ft.fromNumber(t).zzEncode();return this._push(to,r.length(),r)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(ys,1,t?1:0)}fixed32(t){return this._push(sn,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let r=Ft.fromBigInt(t);return this._push(sn,4,r.lo)._push(sn,4,r.hi)}fixed64Number(t){let r=Ft.fromNumber(t);return this._push(sn,4,r.lo)._push(sn,4,r.hi)}fixed64String(t){return this.fixed64(BigInt(t))}sfixed64(t){return this.fixed64(t)}sfixed64Number(t){return this.fixed64Number(t)}sfixed64String(t){return this.fixed64String(t)}float(t){return this._push(Rc,4,t)}double(t){return this._push(Dc,8,t)}bytes(t){let r=t.length>>>0;return r===0?this._push(ys,1,0):this.uint32(r)._push($h,r,t)}string(t){let r=kc(t);return r!==0?this.uint32(r)._push(Ji,r,t):this._push(ys,1,0)}fork(){return this.states=new bs(this),this.head=this.tail=new je(gs,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new je(gs,0,0),this.len=0),this}ldelim(){let t=this.head,r=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=r,this.len+=n),this}finish(){let t=this.head.next,r=Kh(this.len),n=0;for(;t!=null;)t.fn(t.val,r,n),n+=t.len,t=t.next;return r}};function ys(e,t,r){t[r]=e&255}function Vh(e,t,r){for(;e>127;)t[r++]=e&127|128,e>>>=7;t[r]=e}var ws=class extends je{next;constructor(t,r){super(Vh,t,r),this.next=void 0}};function to(e,t,r){for(;e.hi!==0;)t[r++]=e.lo&127|128,e.lo=(e.lo>>>7|e.hi<<25)>>>0,e.hi>>>=7;for(;e.lo>127;)t[r++]=e.lo&127|128,e.lo=e.lo>>>7;t[r++]=e.lo}function sn(e,t,r){t[r]=e&255,t[r+1]=e>>>8&255,t[r+2]=e>>>16&255,t[r+3]=e>>>24}function $h(e,t,r){t.set(e,r)}globalThis.Buffer!=null&&(an.prototype.bytes=function(e){let t=e.length>>>0;return this.uint32(t),t>0&&this._push(qh,t,e),this},an.prototype.string=function(e){let t=globalThis.Buffer.byteLength(e);return this.uint32(t),t>0&&this._push(zh,t,e),this});function qh(e,t,r){t.set(e,r)}function zh(e,t,r){e.length<40?Ji(e,t,r):t.utf8Write!=null?t.utf8Write(e,r):t.set(nt(e),r)}function xs(){return new an}function cn(e,t){let r=xs();return t.encode(e,r,{lengthDelimited:!1}),r.finish()}function*un(e,t,r){let n=rn(e);yield*t.stream(n,void 0,".",r)}var eo={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function ro(e,t,r,n,o){return{name:e,type:t,encode:r,decode:n,stream:o}}function fn(e){function t(i){if(e[i.toString()]==null)throw new Error("Invalid enum value");return e[i]}let r=function(s,a){let c=t(s);a.int32(c)},n=function(s){let a=s.int32();return t(a)},o=function*(s,a){};return ro("enum",eo.VARINT,r,n,o)}function ln(e,t,r){return ro("message",eo.LENGTH_DELIMITED,e,t,r)}var Q;(function(e){let t;(function(a){a.EOL="EOL"})(t=e.ValidityType||(e.ValidityType={}));let r;(function(a){a[a.EOL=0]="EOL"})(r||(r={})),(function(a){a.codec=()=>fn(r)})(t=e.ValidityType||(e.ValidityType={}));let n;e.codec=()=>(n==null&&(n=ln((a,c,u={})=>{u.lengthDelimited!==!1&&c.fork(),a.value!=null&&(c.uint32(10),c.bytes(a.value)),a.signatureV1!=null&&(c.uint32(18),c.bytes(a.signatureV1)),a.validityType!=null&&(c.uint32(24),e.ValidityType.codec().encode(a.validityType,c)),a.validity!=null&&(c.uint32(34),c.bytes(a.validity)),a.sequence!=null&&(c.uint32(40),c.uint64(a.sequence)),a.ttl!=null&&(c.uint32(48),c.uint64(a.ttl)),a.publicKey!=null&&(c.uint32(58),c.bytes(a.publicKey)),a.signatureV2!=null&&(c.uint32(66),c.bytes(a.signatureV2)),a.data!=null&&(c.uint32(74),c.bytes(a.data)),u.lengthDelimited!==!1&&c.ldelim()},(a,c)=>{let u={},f=c==null?a.len:a.pos+c;for(;a.pos<f;){let l=a.uint32();switch(l>>>3){case 1:{u.value=a.bytes();break}case 2:{u.signatureV1=a.bytes();break}case 3:{u.validityType=e.ValidityType.codec().decode(a);break}case 4:{u.validity=a.bytes();break}case 5:{u.sequence=a.uint64();break}case 6:{u.ttl=a.uint64();break}case 7:{u.publicKey=a.bytes();break}case 8:{u.signatureV2=a.bytes();break}case 9:{u.data=a.bytes();break}default:{a.skipType(l&7);break}}}return u},function*(a,c,u){let f=c==null?a.len:a.pos+c;for(u!=="."&&(yield{field:u.endsWith(".")?u.substring(0,u.length-1):u,type:"start",message:"IPNSEntry"});a.pos<f;){let l=a.uint32();switch(l>>>3){case 1:{yield{field:`${u}value`,value:a.bytes()};break}case 2:{yield{field:`${u}signatureV1`,value:a.bytes()};break}case 3:{yield{field:`${u}validityType`,value:e.ValidityType.codec().decode(a)};break}case 4:{yield{field:`${u}validity`,value:a.bytes()};break}case 5:{yield{field:`${u}sequence`,value:a.uint64()};break}case 6:{yield{field:`${u}ttl`,value:a.uint64()};break}case 7:{yield{field:`${u}publicKey`,value:a.bytes()};break}case 8:{yield{field:`${u}signatureV2`,value:a.bytes()};break}case 9:{yield{field:`${u}data`,value:a.bytes()};break}default:{a.skipType(l&7);break}}}u!=="."&&(yield{field:u.endsWith(".")?u.substring(0,u.length-1):u,type:"end",message:"IPNSEntry"})})),n);function o(a){return cn(a,e.codec())}e.encode=o;function i(a,c){return nn(a,e.codec(),c)}e.decode=i;function s(a,c){return un(a,e.codec(),c)}e.stream=s})(Q||(Q={}));var mt=class extends Event{type;detail;constructor(t,r){super(t),this.type=t,this.detail=r}};var Es=class{routing;constructor(t){this.routing=t}async put(t,r,n={}){try{await this.routing.put(t,r,n)}catch(o){throw n.onProgress?.(new mt("ipns:routing:helia:error",o)),o}}async get(t,r={}){try{return await this.routing.get(t,r)}catch(n){throw r.onProgress?.(new mt("ipns:routing:helia:error",n)),n}}toString(){return"HeliaRouting()"}};function wr(e){return new Es(e)}var ie=class extends Error{static name="AbortError";constructor(t="The operation was aborted"){super(t),this.name="AbortError"}};var de=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},no=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var Ye=class extends Error{static name="NotFoundError";constructor(t="Not found"){super(t),this.name="NotFoundError"}};var oo=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var dn=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};function jc(e){return e==null?!1:(e.type==="RSA"||e.type==="Ed25519"||e.type==="secp256k1"||e.type==="ECDSA")&&e.raw instanceof Uint8Array&&typeof e.equals=="function"&&typeof e.toMultihash=="function"&&typeof e.toCID=="function"&&typeof e.verify=="function"}var Ss=Symbol.for("@libp2p/peer-id");function Hh(e){return typeof e?.handleEvent=="function"}function jh(e){return e===!0||e===!1}function Yh(e){return jh(e)?e:e?.capture??!1}function As(e){let t={capture:Yh(e),once:!!e?.once};return e?.passive!=null&&(t.passive=e?.passive),e?.signal!=null&&(t.signal=e?.signal),t}function Yc(e,t){return As(e).capture===As(t).capture}var io=class extends EventTarget{#t=new Map;constructor(){super()}listenerCount(t){let r=this.#t.get(t);return r==null?0:r.length}addEventListener(t,r,n){let o=As(n);if(o?.signal?.aborted===!0)return;let i=u=>{o.once&&this.removeEventListener(t,r,o),Hh(r)?r.handleEvent(u):r(u)},s=this.#t.get(t);if(s==null&&(s=[],this.#t.set(t,s)),s.some(u=>u.callback!==r?!1:Yc(u.options,o)))return;super.addEventListener(t,i,o);let c=()=>{this.removeEventListener(t,r,o)};o.signal?.addEventListener("abort",c),s.push({callback:r,wrapper:i,options:o,onAbort:c})}removeEventListener(t,r,n){let o=this.#t.get(t);if(o==null){super.removeEventListener(t,r??null,n);return}this.#t.set(t,o.filter(i=>i.callback===r&&Yc(i.options,n)?(super.removeEventListener(t,i.wrapper,n),i.options?.signal?.removeEventListener("abort",i.onAbort),!1):!0))}safeDispatchEvent(t,r={}){return this.dispatchEvent(new CustomEvent(t,r))}};function so(e,t){if(typeof e=="string")return Zh(e);if(typeof e=="number")return Wh(e,t);throw new Error(`Value provided to ms() must be a string or number. value=${JSON.stringify(e)}`)}function Zh(e){if(typeof e!="string"||e.length===0||e.length>100)throw new Error(`Value provided to ms.parse() must be a string with length between 1 and 99. value=${JSON.stringify(e)}`);let t=/^(?<value>-?\d*\.?\d+) *(?<unit>milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|months?|mo|years?|yrs?|y)?$/i.exec(e);if(!t?.groups)return NaN;let{value:r,unit:n="ms"}=t.groups,o=parseFloat(r),i=n.toLowerCase();switch(i){case"years":case"year":case"yrs":case"yr":case"y":return o*315576e5;case"months":case"month":case"mo":return o*26298e5;case"weeks":case"week":case"w":return o*6048e5;case"days":case"day":case"d":return o*864e5;case"hours":case"hour":case"hrs":case"hr":case"h":return o*36e5;case"minutes":case"minute":case"mins":case"min":case"m":return o*6e4;case"seconds":case"second":case"secs":case"sec":case"s":return o*1e3;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return o;default:throw new Error(`Unknown unit "${i}" provided to ms.parse(). value=${JSON.stringify(e)}`)}}function Gh(e){let t=Math.abs(e);return t>=315576e5?`${Math.round(e/315576e5)}y`:t>=26298e5?`${Math.round(e/26298e5)}mo`:t>=6048e5?`${Math.round(e/6048e5)}w`:t>=864e5?`${Math.round(e/864e5)}d`:t>=36e5?`${Math.round(e/36e5)}h`:t>=6e4?`${Math.round(e/6e4)}m`:t>=1e3?`${Math.round(e/1e3)}s`:`${e}ms`}function Xh(e){let t=Math.abs(e);return t>=315576e5?Ze(e,t,315576e5,"year"):t>=26298e5?Ze(e,t,26298e5,"month"):t>=6048e5?Ze(e,t,6048e5,"week"):t>=864e5?Ze(e,t,864e5,"day"):t>=36e5?Ze(e,t,36e5,"hour"):t>=6e4?Ze(e,t,6e4,"minute"):t>=1e3?Ze(e,t,1e3,"second"):`${e} ms`}function Wh(e,t){if(typeof e!="number"||!Number.isFinite(e))throw new Error("Value provided to ms.format() must be of type number.");return t?.long?Xh(e):Gh(e)}function Ze(e,t,r,n){let o=t>=r*1.5;return`${Math.round(e/r)} ${n}${o?"s":""}`}function Ts(e){r.debug=r,r.default=r,r.coerce=c,r.disable=i,r.enable=o,r.enabled=s,r.humanize=so,r.destroy=u,Object.keys(e).forEach(f=>{r[f]=e[f]}),r.names=[],r.skips=[],r.formatters={};function t(f){let l=0;for(let h=0;h<f.length;h++)l=(l<<5)-l+f.charCodeAt(h),l|=0;return r.colors[Math.abs(l)%r.colors.length]}r.selectColor=t;function r(f,l){let h,m=null,R,b;function g(...S){if(!g.enabled)return;let B=g,y=Number(new Date),N=y-(h||y);B.diff=N,B.prev=h,B.curr=y,h=y,S[0]=r.coerce(S[0]),typeof S[0]!="string"&&S.unshift("%O");let C=0;S[0]=S[0].replace(/%([a-zA-Z%])/g,(q,w)=>{if(q==="%%")return"%";C++;let E=r.formatters[w];if(typeof E=="function"){let A=S[C];q=E.call(B,A),S.splice(C,1),C--}return q}),r.formatArgs.call(B,S),l?.onLog!=null&&l.onLog(...S),(B.log||r.log).apply(B,S)}return g.namespace=f,g.useColors=r.useColors(),g.color=r.selectColor(f),g.extend=n,g.destroy=r.destroy,Object.defineProperty(g,"enabled",{enumerable:!0,configurable:!1,get:()=>m!==null?m:(R!==r.namespaces&&(R=r.namespaces,b=r.enabled(f)),b),set:S=>{m=S}}),typeof r.init=="function"&&r.init(g),g}function n(f,l){let h=r(this.namespace+(typeof l>"u"?":":l)+f);return h.log=this.log,h}function o(f){r.save(f),r.namespaces=f,r.names=[],r.skips=[];let l,h=(typeof f=="string"?f:"").split(/[\s,]+/),m=h.length;for(l=0;l<m;l++)h[l]&&(f=h[l].replace(/\*/g,".*?"),f[0]==="-"?r.skips.push(new RegExp("^"+f.substr(1)+"$")):r.names.push(new RegExp("^"+f+"$")))}function i(){let f=[...r.names.map(a),...r.skips.map(a).map(l=>"-"+l)].join(",");return r.enable(""),f}function s(f){if(f[f.length-1]==="*")return!0;let l,h;for(l=0,h=r.skips.length;l<h;l++)if(r.skips[l].test(f))return!1;for(l=0,h=r.names.length;l<h;l++)if(r.names[l].test(f))return!0;return!1}function a(f){return f.toString().substring(2,f.toString().length-2).replace(/\.\*\?$/,"*")}function c(f){return f instanceof Error?f.stack??f.message:f}function u(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")}return r.setupFormatters(r.formatters),r.enable(r.load()),r}var ao=op(),Qh=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"];function Jh(){return typeof window<"u"&&window.process&&(window.process.type==="renderer"||window.process.__nwjs)?!0:typeof navigator<"u"&&navigator.userAgent?.toLowerCase().match(/(edge|trident)\/(\d+)/)!=null?!1:typeof document<"u"&&document.documentElement?.style?.WebkitAppearance||typeof window<"u"&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator<"u"&&navigator.userAgent?.toLowerCase().match(/firefox\/(\d+)/)!=null&&parseInt(RegExp.$1,10)>=31||typeof navigator<"u"&&navigator.userAgent?.toLowerCase().match(/applewebkit\/(\d+)/)}function tp(e){if(e[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+e[0]+(this.useColors?"%c ":" ")+"+"+so(this.diff),!this.useColors)return;let t="color: "+this.color;e.splice(1,0,t,"color: inherit");let r=0,n=0;e[0].replace(/%[a-zA-Z%]/g,o=>{o!=="%%"&&(r++,o==="%c"&&(n=r))}),e.splice(n,0,t)}var ep=console.debug??console.log??(()=>{});function rp(e){try{e?ao?.setItem("debug",e):ao?.removeItem("debug")}catch{}}function np(){let e;try{e=ao?.getItem("debug")}catch{}return!e&&typeof globalThis.process<"u"&&"env"in globalThis.process&&(e=globalThis.process.env.DEBUG),e}function op(){try{return localStorage}catch{}}function ip(e){e.j=function(t){try{return JSON.stringify(t)}catch(r){return"[UnexpectedJSONParseError]: "+r.message}}}var Zc=Ts({formatArgs:tp,save:rp,load:np,useColors:Jh,setupFormatters:ip,colors:Qh,storage:ao,log:ep});var _t=Zc;_t.formatters.b=e=>e==null?"undefined":rt.baseEncode(e);_t.formatters.t=e=>e==null?"undefined":Ee.baseEncode(e);_t.formatters.m=e=>e==null?"undefined":is.baseEncode(e);_t.formatters.p=e=>e==null?"undefined":e.toString();_t.formatters.c=e=>e==null?"undefined":e.toString();_t.formatters.k=e=>e==null?"undefined":e.toString();_t.formatters.a=e=>e==null?"undefined":e.toString();function Gc(e,t=""){let r=Xc(e.message),n=Xc(e.stack);return r!=null&&n!=null?n.includes(r)?`${n.split(`
|
|
4
4
|
`).join(`
|
|
5
|
-
${
|
|
6
|
-
${
|
|
5
|
+
${t}`)}`:`${r}
|
|
6
|
+
${t}${n.split(`
|
|
7
7
|
`).join(`
|
|
8
|
-
${
|
|
8
|
+
${t}`)}`:n!=null?`${n.split(`
|
|
9
9
|
`).join(`
|
|
10
|
-
${
|
|
11
|
-
${
|
|
12
|
-
${
|
|
13
|
-
${e}[Error list was empty]`,r.trim()}return Za(t,e)}Ie.formatters.e=t=>t==null?"undefined":Xa(t);function zd(t){let e=()=>{};return e.enabled=!1,e.color="",e.diff=0,e.log=()=>{},e.namespace=t,e.destroy=()=>!0,e.extend=()=>e,e.useColors=()=>!1,e}function Qr(t,e){let r=zd(`${t}:trace`);return Ie.enabled(`${t}:trace`)&&Ie.names.map(n=>n.toString()).find(n=>n.includes(":trace"))!=null&&(r=Ie(`${t}:trace`,e)),Object.assign(Ie(t,e),{error:Ie(`${t}:error`,e),trace:r,newScope:n=>Qr(`${t}:${n}`,e)})}function Ga(t){if(t!=null&&(t=t.trim(),t.length!==0))return t}function de(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}async function Wa(t,e,r,n){let o=await crypto.subtle.importKey("jwk",t,{name:"ECDSA",namedCurve:t.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let i=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,Te(e),Te(r.subarray()));return n?.signal?.throwIfAborted(),i}function Hd(t){return t?.buffer instanceof ArrayBuffer}function Qa(t){if(Hd(t))return t;let e=t.slice();return new Uint8Array(e.buffer,0,e.byteLength)}function vt(t,e){e==null&&(e=t.reduce((o,i)=>o+i.length,0));let r=Re(e),n=0;for(let o of t)r.set(o,n),n+=o.length;return Qa(r)}var ec=Symbol.for("@achingbrain/uint8arraylist");function Ja(t,e){if(e==null||e<0)throw new RangeError("index is out of bounds");let r=0;for(let n of t){let o=r+n.byteLength;if(e<o)return{buf:n,index:e-r};r=o}throw new RangeError("index is out of bounds")}function Vn(t){return!!t?.[ec]}var Le=class t{bufs;length;[ec]=!0;constructor(...e){this.bufs=[],this.length=0,e.length>0&&this.appendAll(e)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...e){this.appendAll(e)}appendAll(e){let r=0;for(let n of e)if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.push(n);else if(Vn(n)){r+=n.byteLength;for(let o of n.bufs)this.bufs.push(o)}else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}prepend(...e){this.prependAll(e)}prependAll(e){let r=0;for(let n of e.reverse())if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.unshift(n);else if(Vn(n))r+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}get(e){let r=Ja(this.bufs,e);return r.buf[r.index]}set(e,r){let n=Ja(this.bufs,e);n.buf[n.index]=r}write(e,r=0){if(e instanceof Uint8Array)for(let n=0;n<e.length;n++)this.set(r+n,e[n]);else if(Vn(e))for(let n=0;n<e.length;n++)this.set(r+n,e.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(e){if(e=Math.trunc(e),!(Number.isNaN(e)||e<=0)){if(e===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(e>=this.bufs[0].byteLength)e-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(e),this.length-=e;break}}}slice(e,r){let{bufs:n,length:o}=this._subList(e,r);return vt(n,o)}subarray(e,r){let{bufs:n,length:o}=this._subList(e,r);return n.length===1?n[0]:vt(n,o)}sublist(e,r){let{bufs:n,length:o}=this._subList(e,r),i=new t;return i.length=o,i.bufs=n,i}_subList(e,r){if(e=e??0,r=r??this.length,e<0&&(e=this.length+e),r<0&&(r=this.length+r),e<0||r>this.length)throw new RangeError("index is out of bounds");if(e===r)return{bufs:[],length:0};if(e===0&&r===this.length)return{bufs:[...this.bufs],length:this.length};let n=[],o=0;for(let i=0;i<this.bufs.length;i++){let s=this.bufs[i],a=o,c=a+s.byteLength;if(o=c,e>=c)continue;let f=e>=a&&e<c,u=r>a&&r<=c;if(f&&u){if(e===a&&r===c){n.push(s);break}let l=e-a;n.push(s.subarray(l,l+(r-e)));break}if(f){if(e===0){n.push(s);continue}n.push(s.subarray(e-a));continue}if(u){if(r===c){n.push(s);break}n.push(s.subarray(0,r-a));break}n.push(s)}return{bufs:n,length:r-e}}indexOf(e,r=0){if(!Vn(e)&&!(e instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=e instanceof Uint8Array?e:e.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),e.length===0)return r>this.length?this.length:r;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let i=256,s=new Int32Array(i);for(let l=0;l<i;l++)s[l]=-1;for(let l=0;l<o;l++)s[n[l]]=l;let a=s,c=this.byteLength-n.byteLength,f=n.byteLength-1,u;for(let l=r;l<=c;l+=u){u=0;for(let h=f;h>=0;h--){let m=this.get(l+h);if(n[h]!==m){u=Math.max(1,h-a[m]);break}}if(u===0)return l}return-1}getInt8(e){let r=this.subarray(e,e+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(e,r){let n=Re(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,r),this.write(n,e)}getInt16(e,r){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,r)}setInt16(e,r,n){let o=$e(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,r,n),this.write(o,e)}getInt32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,r)}setInt32(e,r,n){let o=$e(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,r,n),this.write(o,e)}getBigInt64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,r)}setBigInt64(e,r,n){let o=$e(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,r,n),this.write(o,e)}getUint8(e){let r=this.subarray(e,e+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint8(0)}setUint8(e,r){let n=Re(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,r),this.write(n,e)}getUint16(e,r){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,r)}setUint16(e,r,n){let o=$e(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,r,n),this.write(o,e)}getUint32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,r)}setUint32(e,r,n){let o=$e(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,r,n),this.write(o,e)}getBigUint64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,r)}setBigUint64(e,r,n){let o=$e(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,r,n),this.write(o,e)}getFloat32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,r)}setFloat32(e,r,n){let o=$e(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,r,n),this.write(o,e)}getFloat64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,r)}setFloat64(e,r,n){let o=$e(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,r,n),this.write(o,e)}equals(e){if(e==null||!(e instanceof t)||e.bufs.length!==this.bufs.length)return!1;for(let r=0;r<this.bufs.length;r++)if(!de(this.bufs[r],e.bufs[r]))return!1;return!0}static fromUint8Arrays(e,r){let n=new t;return n.bufs=e,r==null&&(r=e.reduce((o,i)=>o+i.byteLength,0)),n.length=r,n}};function te(t,e="utf8"){let r=Nn[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.encoder.encode(t).substring(1)}var jd=parseInt("11111",2),Gi=parseInt("10000000",2),Yd=parseInt("01111111",2),tc={0:Jr,1:Jr,2:Zd,3:Wd,4:Qd,5:Xd,6:Gd,16:Jr,22:Jr,48:Jr};function Xi(t,e={offset:0}){let r=t[e.offset]&jd;if(e.offset++,tc[r]!=null)return tc[r](t,e);throw new Error("No decoder for tag "+r)}function en(t,e){let r=0;if((t[e.offset]&Gi)===Gi){let n=t[e.offset]&Yd,o="0x";e.offset++;for(let i=0;i<n;i++,e.offset++){if(e.offset>=t.byteLength)throw new Error("invalid DER element length");o+=t[e.offset].toString(16).padStart(2,"0")}r=parseInt(o,16)}else r=t[e.offset],e.offset++;if(!Number.isInteger(r)||r<0||r>t.byteLength-e.offset)throw new Error("invalid DER element length");return r}function Jr(t,e){en(t,e);let r=[];for(;!(e.offset>=t.byteLength);){let n=Xi(t,e);if(n===null)break;r.push(n)}return r}function Zd(t,e){let r=en(t,e),n=e.offset,o=e.offset+r,i=[];for(let s=n;s<o;s++)s===n&&t[s]===0||i.push(t[s]);return e.offset+=r,Uint8Array.from(i)}function Gd(t,e){let r=en(t,e),n=e.offset+r,o=t[e.offset];e.offset++;let i=0,s=0;o<40?(i=0,s=o):o<80?(i=1,s=o-40):(i=2,s=o-80);let a=`${i}.${s}`,c=[];for(;e.offset<n;){let f=t[e.offset];if(e.offset++,c.push(f&127),f<128){c.reverse();let u=0;for(let l=0;l<c.length;l++)u+=c[l]<<l*7;a+=`.${u}`,c=[]}}return a}function Xd(t,e){return e.offset++,null}function Wd(t,e){let r=en(t,e),n=t[e.offset];e.offset++;let o=t.subarray(e.offset,e.offset+r-1);if(e.offset+=r,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function Qd(t,e){let r=en(t,e),n=t.subarray(e.offset,e.offset+r);return e.offset+=r,n}function Jd(t){let e=t.toString(16);e.length%2===1&&(e="0"+e);let r=new Le;for(let n=0;n<e.length;n+=2)r.append(Uint8Array.from([parseInt(`${e[n]}${e[n+1]}`,16)]));return r}function Wi(t){if(t.byteLength<128)return Uint8Array.from([t.byteLength]);let e=Jd(t.byteLength);return new Le(Uint8Array.from([e.byteLength|Gi]),e)}function rc(t){let e=new Le,r=128;return(t.subarray()[0]&r)===r&&e.append(Uint8Array.from([0])),e.append(t),new Le(Uint8Array.from([2]),Wi(e),e)}function nc(t){let e=Uint8Array.from([0]),r=new Le(e,t);return new Le(Uint8Array.from([3]),Wi(r),r)}function qn(t,e=48){let r=new Le;for(let n of t)r.append(n);return new Le(Uint8Array.from([e]),Wi(r),r)}var eh=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),th=Uint8Array.from([6,5,43,129,4,0,34]),rh=Uint8Array.from([6,5,43,129,4,0,35]),nh={ext:!0,kty:"EC",crv:"P-256"},oh={ext:!0,kty:"EC",crv:"P-384"},ih={ext:!0,kty:"EC",crv:"P-521"},Qi=32,Ji=48,es=66;function oc(t){let e=Xi(t);return ic(e)}function ic(t){let e=t[1][1][0],r=1,n,o;if(e.byteLength===Qi*2+1)return n=te(e.subarray(r,r+Qi),"base64url"),o=te(e.subarray(r+Qi),"base64url"),new fr({...nh,key_ops:["verify"],x:n,y:o});if(e.byteLength===Ji*2+1)return n=te(e.subarray(r,r+Ji),"base64url"),o=te(e.subarray(r+Ji),"base64url"),new fr({...oh,key_ops:["verify"],x:n,y:o});if(e.byteLength===es*2+1)return n=te(e.subarray(r,r+es),"base64url"),o=te(e.subarray(r+es),"base64url"),new fr({...ih,key_ops:["verify"],x:n,y:o});throw new ut(`coordinates were wrong length, got ${e.byteLength}, expected 65, 97 or 133`)}function sc(t){return qn([rc(Uint8Array.from([1])),qn([sh(t.crv)],160),qn([nc(new Le(Uint8Array.from([4]),le(t.x??"","base64url"),le(t.y??"","base64url")))],161)]).subarray()}function sh(t){if(t==="P-256")return eh;if(t==="P-384")return th;if(t==="P-521")return rh;throw new ut(`Invalid curve ${t}`)}var fr=class{type="ECDSA";jwk;_raw;constructor(e){this.jwk=e}get raw(){return this._raw==null&&(this._raw=sc(this.jwk)),this._raw}toMultihash(){return Ge.digest(lr(this))}toCID(){return se.createV1(114,this.toMultihash())}toString(){return re.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:de(this.raw,e.raw)}async verify(e,r,n){return Wa(this.jwk,r,e,n)}};var zn=BigInt(4294967295),ac=BigInt(32);function ah(t,e=!1){return e?{h:Number(t&zn),l:Number(t>>ac&zn)}:{h:Number(t>>ac&zn)|0,l:Number(t&zn)|0}}function cc(t,e=!1){let r=t.length,n=new Uint32Array(r),o=new Uint32Array(r);for(let i=0;i<r;i++){let{h:s,l:a}=ah(t[i],e);[n[i],o[i]]=[s,a]}return[n,o]}var ch=t=>t/2**32|0,uh=t=>t>>>0;function uc(t,e,r,n){let o=ch(r),i=uh(r);t.setUint32(e,n?i:o,n),t.setUint32(e+4,n?o:i,n)}var ts=(t,e,r)=>t>>>r,rs=(t,e,r)=>t<<32-r|e>>>r,Ht=(t,e,r)=>t>>>r|e<<32-r,jt=(t,e,r)=>t<<32-r|e>>>r,tn=(t,e,r)=>t<<64-r|e>>>r-32,rn=(t,e,r)=>t>>>r-32|e<<64-r;function nt(t,e,r,n){let o=(e>>>0)+(n>>>0);return{h:t+r+(o/2**32|0)|0,l:o|0}}var fc=(t,e,r)=>(t>>>0)+(e>>>0)+(r>>>0),lc=(t,e,r,n)=>e+r+n+(t/2**32|0)|0,dc=(t,e,r,n)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0),hc=(t,e,r,n,o)=>e+r+n+o+(t/2**32|0)|0,pc=(t,e,r,n,o)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0)+(o>>>0),mc=(t,e,r,n,o,i)=>e+r+n+o+i+(t/2**32|0)|0;function Hn(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in t&&t.BYTES_PER_ELEMENT===1}var ns=t=>t?`"${t}" `:"";function ft(t,e=""){if(typeof t!="number")throw new TypeError(ns(e)+"expected number, got "+typeof t);if(!Number.isSafeInteger(t)||t<0)throw new RangeError(ns(e)+"expected integer >= 0, got "+t);return t}function Ve(t,e,r=""){if(Hn(t)&&(e===void 0||t.length===e))return t;e!==void 0&&ft(e,"length");let n=Hn(t),o=e!==void 0?` of length ${e}`:"",i=n?`length=${t.length}`:`type=${typeof t}`,s=ns(r)+"expected Uint8Array"+o+", got "+i;throw n?new RangeError(s):new TypeError(s)}function jn(t){if(typeof t!="function"||typeof t.create!="function")throw new TypeError("expected hash wrapped by utils.createHasher");if(ft(t.outputLen),ft(t.blockLen),t.outputLen<1||t.blockLen<1)throw new Error("hash blockLen / outputLen must be >= 1")}var lh=(t,e)=>{if(t===null||typeof t!="object"||Array.isArray(t))throw new TypeError((e==="object"?"":`"${e}" `)+"expected object, got type="+typeof t)},yc=(t,e)=>{lh(t,e);let r=Object.getPrototypeOf(t);if(r!==Object.prototype&&r!==null)throw new TypeError(`"${e}" expected plain object`);if(Object.hasOwn(t,"__proto__"))throw new TypeError(`"${e}.__proto__" is not allowed`)};function dr(t,e=!0){if(t.destroyed)throw new Error("hash was destroyed");if(e&&t.finished)throw new Error("digest() was already called")}function Yn(t,e){Ve(t,void 0,"output");let r=e.outputLen;if(!(t.length>=r))throw new RangeError('"output" expected length >= '+r)}function Yt(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function Zn(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function Xe(t,e){return t<<32-e|t>>>e}var bc=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",dh=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function Gn(t){if(Ve(t),bc)return t.toHex();let e="";for(let r=0;r<t.length;r++)e+=dh[t[r]];return e}function gc(t){return t>=48&&t<=57?t-48:t>=65&&t<=70?t-55:t>=97&&t<=102?t-87:void 0}function Xn(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);if(bc)try{return Uint8Array.fromHex(t)}catch(o){throw o instanceof SyntaxError?new RangeError(o.message):o}let e=t.length,r=e/2;if(e%2)throw new RangeError("hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(r);for(let o=0,i=0;o<r;o++,i+=2){let s=gc(t.charCodeAt(i)),a=gc(t.charCodeAt(i+1));if(s===void 0||a===void 0){let c=t[i]+t[i+1];throw new RangeError('hex string expected, got non-hex character "'+c+'" at index '+i)}n[o]=s*16+a}return n}function os(...t){let e=0;for(let n=0;n<t.length;n++){let o=t[n];Ve(o),e+=o.length}let r=new Uint8Array(e);for(let n=0,o=0;n<t.length;n++){let i=t[n];r.set(i,o),o+=i.length}return r}function hh(t,e,r="opts"){return yc(t,"defaults"),e!==void 0&&yc(e,r),Object.assign(Object.create(null),t,e)}function is(t,e={}){if(typeof t!="function")throw new TypeError('"hashCons" expected function, got type='+typeof t);e=hh({},e,"info");let r=(o,i)=>t(i).update(o).digest(),n=t(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.canXOF=n.canXOF,r.create=o=>t(o),Object.assign(r,e),Object.freeze(r)}function wc(t=32){ft(t,"bytesLength");let e=typeof globalThis=="object"?globalThis.crypto:null;if(typeof e?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");if(t>65536)throw new RangeError(`"bytesLength" expected <= 65536, got ${t}`);return e.getRandomValues(new Uint8Array(t))}var ss=t=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,t])});function xc(t,e,r){return t&e^~t&r}function Ec(t,e,r){return t&e^t&r^e&r}var nn=class{blockLen;outputLen;canXOF=!1;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(e,r,n,o){this.blockLen=e,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(e),this.view=Zn(this.buffer)}update(e){dr(this),Ve(e);let{view:r,buffer:n,blockLen:o}=this,i=e.length,s=!1;for(let a=0;a<i;){let c=Math.min(o-this.pos,i-a);if(c===o){let f=Zn(e);for(;o<=i-a;a+=o)this.process(f,a);s=!0;continue}n.set(a===0&&c===i?e:e.subarray(a,a+c),this.pos),this.pos+=c,a+=c,this.pos===o&&(this.process(r,0),this.pos=0,s=!0)}return this.length+=e.length,s&&this.roundClean(),this}digestInto(e){dr(this),Yn(e,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:i}=this,{pos:s}=this;r[s++]=128,r.fill(0,s),this.padOffset>o-s&&(this.process(n,0),r.fill(0)),uc(n,o-8,this.length*8,i),this.process(n,0),this.roundClean();let a=e===r?n:Zn(e),c=this.outputLen,f=c/4,u=this.get();if(c%4||f>u.length)throw new Error("invalid outputLen");for(let l=0;l<f;l++)a.setUint32(4*l,u[l],i)}digest(){let{buffer:e,outputLen:r}=this;this.digestInto(e);let n=e.slice(0,r);return this.destroy(),n}_cloneIntoMeta(e){let{buffer:r,length:n,finished:o,destroyed:i,pos:s}=this;return e.destroyed=i,e.finished=o,e.length=n,e.pos=s,s&&e.buffer.set(r),e}clone(){return this._cloneInto()}},Sc=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var vc=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var ph=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]),At=new Uint32Array(64),as=class extends nn{A=0;B=0;C=0;D=0;E=0;F=0;G=0;H=0;constructor(e,r){super(64,e,8,!1),this.A=r[0]|0,this.B=r[1]|0,this.C=r[2]|0,this.D=r[3]|0,this.E=r[4]|0,this.F=r[5]|0,this.G=r[6]|0,this.H=r[7]|0}get(){let{A:e,B:r,C:n,D:o,E:i,F:s,G:a,H:c}=this;return[e,r,n,o,i,s,a,c]}set(e,r,n,o,i,s,a,c){this.A=e|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=i|0,this.F=s|0,this.G=a|0,this.H=c|0}_cloneInto(e){return(e||=new this.constructor).set(...this.get()),this._cloneIntoMeta(e)}process(e,r){for(let l=0;l<16;l++,r+=4)At[l]=e.getUint32(r,!1);for(let l=16;l<64;l++){let h=At[l-15],m=At[l-2],R=Xe(h,7)^Xe(h,18)^h>>>3,b=Xe(m,17)^Xe(m,19)^m>>>10;At[l]=b+At[l-7]+R+At[l-16]|0}let{A:n,B:o,C:i,D:s,E:a,F:c,G:f,H:u}=this;for(let l=0;l<64;l++){let h=Xe(a,6)^Xe(a,11)^Xe(a,25),m=u+h+xc(a,c,f)+ph[l]+At[l]|0,b=(Xe(n,2)^Xe(n,13)^Xe(n,22))+Ec(n,o,i)|0;u=f,f=c,c=a,a=s+m|0,s=i,i=o,o=n,n=m+b|0}n=n+this.A|0,o=o+this.B|0,i=i+this.C|0,s=s+this.D|0,a=a+this.E|0,c=c+this.F|0,f=f+this.G|0,u=u+this.H|0,this.set(n,o,i,s,a,c,f,u)}roundClean(){Yt(At)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),Yt(this.buffer)}},cs=class extends as{constructor(){super(32,Sc)}};var Ac=cc(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(t=>BigInt(t))),mh=Ac[0],yh=Ac[1],Tt=new Uint32Array(80),It=new Uint32Array(80),us=class extends nn{Ah=0;Al=0;Bh=0;Bl=0;Ch=0;Cl=0;Dh=0;Dl=0;Eh=0;El=0;Fh=0;Fl=0;Gh=0;Gl=0;Hh=0;Hl=0;constructor(e,r){super(128,e,16,!1),this.Ah=r[0]|0,this.Al=r[1]|0,this.Bh=r[2]|0,this.Bl=r[3]|0,this.Ch=r[4]|0,this.Cl=r[5]|0,this.Dh=r[6]|0,this.Dl=r[7]|0,this.Eh=r[8]|0,this.El=r[9]|0,this.Fh=r[10]|0,this.Fl=r[11]|0,this.Gh=r[12]|0,this.Gl=r[13]|0,this.Hh=r[14]|0,this.Hl=r[15]|0}get(){let{Ah:e,Al:r,Bh:n,Bl:o,Ch:i,Cl:s,Dh:a,Dl:c,Eh:f,El:u,Fh:l,Fl:h,Gh:m,Gl:R,Hh:b,Hl:y}=this;return[e,r,n,o,i,s,a,c,f,u,l,h,m,R,b,y]}set(e,r,n,o,i,s,a,c,f,u,l,h,m,R,b,y){this.Ah=e|0,this.Al=r|0,this.Bh=n|0,this.Bl=o|0,this.Ch=i|0,this.Cl=s|0,this.Dh=a|0,this.Dl=c|0,this.Eh=f|0,this.El=u|0,this.Fh=l|0,this.Fl=h|0,this.Gh=m|0,this.Gl=R|0,this.Hh=b|0,this.Hl=y|0}_cloneInto(e){return(e||=new this.constructor).set(...this.get()),this._cloneIntoMeta(e)}process(e,r){for(let g=0;g<16;g++,r+=4)Tt[g]=e.getUint32(r),It[g]=e.getUint32(r+=4);for(let g=16;g<80;g++){let D=Tt[g-15]|0,C=It[g-15]|0,V=Ht(D,C,1)^Ht(D,C,8)^ts(D,C,7),q=jt(D,C,1)^jt(D,C,8)^rs(D,C,7),w=Tt[g-2]|0,E=It[g-2]|0,v=Ht(w,E,19)^tn(w,E,61)^ts(w,E,6),N=jt(w,E,19)^rn(w,E,61)^rs(w,E,6),L=dc(q,N,It[g-7],It[g-16]),z=hc(L,V,v,Tt[g-7],Tt[g-16]);Tt[g]=z|0,It[g]=L|0}let{Ah:n,Al:o,Bh:i,Bl:s,Ch:a,Cl:c,Dh:f,Dl:u,Eh:l,El:h,Fh:m,Fl:R,Gh:b,Gl:y,Hh:S,Hl:T}=this;for(let g=0;g<80;g++){let D=Ht(l,h,14)^Ht(l,h,18)^tn(l,h,41),C=jt(l,h,14)^jt(l,h,18)^rn(l,h,41),V=l&m^~l&b,q=h&R^~h&y,w=pc(T,C,q,yh[g],It[g]),E=mc(w,S,D,V,mh[g],Tt[g]),v=w|0,N=Ht(n,o,28)^tn(n,o,34)^tn(n,o,39),L=jt(n,o,28)^rn(n,o,34)^rn(n,o,39),z=n&i^n&a^i&a,I=o&s^o&c^s&c;S=b|0,T=y|0,b=m|0,y=R|0,m=l|0,R=h|0,{h:l,l:h}=nt(f|0,u|0,E|0,v|0),f=a|0,u=c|0,a=i|0,c=s|0,i=n|0,s=o|0;let k=fc(v,L,I);n=lc(k,E,N,z),o=k|0}({h:n,l:o}=nt(this.Ah|0,this.Al|0,n|0,o|0)),{h:i,l:s}=nt(this.Bh|0,this.Bl|0,i|0,s|0),{h:a,l:c}=nt(this.Ch|0,this.Cl|0,a|0,c|0),{h:f,l:u}=nt(this.Dh|0,this.Dl|0,f|0,u|0),{h:l,l:h}=nt(this.Eh|0,this.El|0,l|0,h|0),{h:m,l:R}=nt(this.Fh|0,this.Fl|0,m|0,R|0),{h:b,l:y}=nt(this.Gh|0,this.Gl|0,b|0,y|0),{h:S,l:T}=nt(this.Hh|0,this.Hl|0,S|0,T|0),this.set(n,o,i,s,a,c,f,u,l,h,m,R,b,y,S,T)}roundClean(){Yt(Tt,It)}destroy(){this.destroyed=!0,Yt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},fs=class extends us{constructor(){super(64,vc)}};var Tc=is(()=>new cs,ss(1));var ls=is(()=>new fs,ss(3));function Qn(t,e,r=()=>{}){if(!Array.isArray(t))throw new TypeError(`"${e}" expected array, got type=${typeof t}`);for(let n=0;n<t.length;n++)r(t[n],`${e}[${n}]`);return t}var J=(t,e,r)=>Ve(t,e,r),ds=ft;function Bc(t,e=""){if(typeof t!="string"){let r=e&&`"${e}" `;throw new TypeError(r+"expected string, got type="+typeof t)}return t}function Bt(t,e="object"){if(t===null||typeof t!="object"||Array.isArray(t))throw new TypeError(e==="object"?"expected valid options object":`"${e}" expected object, got type=${typeof t}`);return t}function Zt(t,e){if(typeof t!="function")throw new TypeError(`"${e}" is invalid: expected function, got ${typeof t}`);return t}var on=Gn,qe=(...t)=>os(...t),hr=t=>Xn(t),_t=Hn,Gt=t=>wc(t),Wn=BigInt(0),Ic=BigInt(1),gh=t=>t?`"${t}" `:"";function Be(t,e=""){if(typeof t!="boolean")throw new TypeError(gh(e)+"expected boolean, got type="+typeof t);return t}function Jn(t){if(typeof t=="bigint"){if(!Ct(t))throw new RangeError("positive bigint expected, got "+t)}else ds(t);return t}function lt(t,e=""){if(typeof t!="number"){let r=e&&`"${e}" `;throw new TypeError(r+"expected number, got type="+typeof t)}if(!Number.isSafeInteger(t)){let r=e&&`"${e}" `;throw new RangeError(r+"expected safe integer, got "+t)}}function sn(t){let e=Jn(t).toString(16);return e.length&1?"0"+e:e}function Cc(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);return t===""?Wn:BigInt("0x"+t)}function ot(t){return Cc(Gn(t))}function Xt(t){return Cc(Gn(an(Ve(t)).reverse()))}function eo(t,e){if(ft(e),e===0)throw new Error("zero output length is invalid");t=Jn(t);let r=e*2,n=t.toString(16);if(n.length>r)throw new RangeError("number is too large");return Xn(n.padStart(r,"0"))}function hs(t,e){return eo(t,e).reverse()}function an(t){return Uint8Array.from(J(t))}function Ct(t){return typeof t=="bigint"&&Wn<=t}function ps(t,e,r){return Ct(t)&&Ct(e)&&Ct(r)&&e<=t&&t<r}function pr(t,e,r,n){if(!ps(e,r,n))throw new RangeError("expected valid "+t+": "+r+" <= n < "+n+", got "+e)}function mr(t){if(t<Wn)throw new Error("expected non-negative bigint, got "+t);return t===Wn?0:t.toString(2).length}var cn=t=>(lt(t,"n"),(Ic<<BigInt(t))-Ic);function _c(t,e,r){if(ft(t,"hashLen"),ft(e,"qByteLen"),typeof r!="function")throw new TypeError("hmacFn must be a function");let n=y=>new Uint8Array(y),o=Uint8Array.of(),i=Uint8Array.of(0),s=Uint8Array.of(1),a=1e3,c=n(t),f=n(t),u=0,l=()=>{c.fill(1),f.fill(0),u=0},h=(...y)=>r(f,qe(c,...y)),m=(y=o)=>{f=h(i,y),c=h(),y.length!==0&&(f=h(s,y),c=h())},R=()=>{if(u++>=a)throw new Error("drbg: tried max amount of iterations");let y=0,S=[];for(;y<e;){c=h();let T=c.slice();S.push(T),y+=c.length}return qe(...S)};return(y,S)=>{l(),m(y);let T;for(;(T=S(R()))===void 0;)m();return l(),T}}function Ce(t,e={},r={},n="object"){Bt(t,n),Bt(e,"fields"),Bt(r,"optFields");function o(s,a,c){let f=n==="object"?`param "${String(s)}"`:`"${n}.${String(s)}"`,u=t[s];if(!Object.hasOwn(t,s)&&(c?u!==void 0:a!=="function"))throw new TypeError(`${f} is invalid: expected own property`);if(c&&u===void 0)return;let l=typeof u;if(l!==a||u===null)throw new TypeError(`${f} is invalid: expected ${a}, got ${l}`)}let i=(s,a)=>Object.entries(s).forEach(([c,f])=>o(c,f,a));i(e,!1),i(r,!0)}var me=BigInt(0),ee=BigInt(1),Rt=BigInt(2),Lc=BigInt(3),ms=BigInt(4),Nc=BigInt(5),bh=BigInt(7),kc=BigInt(8),wh=BigInt(9),xh=BigInt(15),Uc=BigInt(16),Eh=BigInt("0x10000000000000000");function ae(t,e){if(e<=me)throw new Error("mod: expected positive modulus, got "+e);let r=t%e;return r>=me?r:e+r}function Fc(t,e,r){if(r<=ee)throw new Error("pow: expected modulus > 1, got "+r);if(typeof e!="bigint")throw new TypeError("invalid exponent: expected bigint, got "+typeof e);if(e<me)throw new Error("invalid exponent, negatives unsupported");if(e===me)return ee;if(e===ee)return t;let n=t%r;if(n<me&&(n+=r),e<Eh){let a=ee;for(;e>me;)e&ee&&(a=a*n%r),n=n*n%r,e>>=ee;return a}let o=[];for(;e>me;)o.push(Number(e&xh)),e>>=ms;let i=new Array(16);i[0]=ee,i[1]=n;for(let a=2;a<16;a++)i[a]=i[a-1]*n%r;let s=i[o[o.length-1]];for(let a=o.length-2;a>=0;a--){s=s*s%r,s=s*s%r,s=s*s%r,s=s*s%r;let c=o[a];c!==0&&(s=s*i[c]%r)}return s}function ie(t,e,r){if(r<=ee)throw new Error("pow2: expected modulus > 1, got "+r);if(e<me)throw new Error("pow2: expected non-negative exponent, got "+e);let n=t;for(;e-- >me;)n*=n,n%=r;return n}function Rc(t,e){if(t===me)throw new Error("invert: expected non-zero number");if(e<=ee)throw new Error("invert: expected modulus > 1, got "+e);let r=ae(t,e),n=e,o=me,i=ee;for(;r!==me;){let a=n/r,c=n-r*a,f=o-i*a;n=r,r=c,o=i,i=f}if(n!==ee)throw new Error("invert: does not exist");return ae(o,e)}function Oc(t,e){if(e<=ee)throw new Error("invertCt: expected prime modulus > 1, got "+e);let r=ae(t,e);if(r===me)throw new Error("invertCt: expected non-zero number");let n=Fc(r,e-Rt,e);if(ae(r*n,e)!==ee)throw new Error("invertCt: does not exist");return n}function ys(t,e,r){let n=t;if(!n.eql(n.sqr(e),r))throw new Error("Cannot find square root")}function gs(t,e){if((t&ee)===me)throw new Error(e+": expected odd modulus, got "+t)}function Pc(t,e){let r=t,n=(r.ORDER+ee)/ms,o=r.pow(e,n);return ys(r,o,e),o}function Sh(t,e){let r=t,n=(r.ORDER-Nc)/kc,o=r.mul(e,Rt),i=r.pow(o,n),s=r.mul(e,i),a=r.mul(r.mul(s,Rt),i),c=r.mul(s,r.sub(a,r.ONE));return ys(r,c,e),c}function vh(t){let e=gr(t),r=Mc(t),n=r(e,e.neg(e.ONE)),o=r(e,n),i=r(e,e.neg(n)),s=(t+bh)/Uc;return((a,c)=>{let f=a,u=f.pow(c,s),l=f.mul(u,n),h=f.mul(u,o),m=f.mul(u,i),R=f.eql(f.sqr(l),c),b=f.eql(f.sqr(h),c);u=f.cmov(u,l,R),l=f.cmov(m,h,b);let y=f.eql(f.sqr(l),c),S=f.cmov(u,l,y);return ys(f,S,c),S})}function Mc(t){if(t<Lc)throw new Error("sqrt is not defined for small field");gs(t,"tonelliShanks");let e=t-ee,r=0;for(;e%Rt===me;)e/=Rt,r++;let n=Rt,o=gr(t);for(;un(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return Pc;let i=o.pow(n,e),s=(e+ee)/Rt;return function(c,f){let u=c;if(u.is0(f))return f;if(un(u,f)!==1)throw new Error("Cannot find square root");let l=r,h=u.mul(u.ONE,i),m=u.pow(f,e),R=u.pow(f,s);for(;!u.eql(m,u.ONE);){if(u.is0(m))throw new Error("Cannot find square root: probably non-prime P");let b=1,y=u.sqr(m);for(;!u.eql(y,u.ONE);)if(b++,y=u.sqr(y),b===l)throw new Error("Cannot find square root");let S=ee<<BigInt(l-b-1),T=u.pow(h,S);l=b,h=u.sqr(T),m=u.mul(m,h),R=u.mul(R,T)}return R}}function Ah(t){return gs(t,"Fp.sqrt"),t%ms===Lc?Pc:t%kc===Nc?Sh:t%Uc===wh?vh(t):Mc(t)}var Kc=(t,e)=>(ae(t,e)&ee)===ee,Th=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function yr(t){if(Bt(t,"field"),typeof t.ORDER!="bigint")throw new TypeError('param "ORDER" is invalid: expected bigint, got '+typeof t.ORDER);lt(t.BYTES,"BYTES"),lt(t.BITS,"BITS");for(let e of Th)Zt(t[e],"field."+e);if(t.BYTES<1||t.BITS<1)throw new Error("invalid field: expected BYTES/BITS > 0");if(t.ORDER<=ee)throw new Error("invalid field: expected ORDER > 1, got "+t.ORDER);return t}function ro(t,e,r=!1){yr(t),Qn(e,"nums"),Be(r,"passZero");let n=t,o=new Array(e.length).fill(r?n.ZERO:void 0),i=e.reduce((a,c,f)=>n.is0(c)?a:(o[f]=a,n.mul(a,c)),n.ONE),s=n.inv(i);return e.reduceRight((a,c,f)=>n.is0(c)?a:(o[f]=n.mul(a,o[f]),n.mul(a,c)),s),o}function un(t,e){yr(t);let r=t;gs(r.ORDER,"FpLegendre");let n=(r.ORDER-ee)/Rt,o=r.pow(e,n),i=r.eql(o,r.ONE),s=r.eql(o,r.ZERO),a=r.eql(o,r.neg(r.ONE));if(!i&&!s&&!a)throw new Error("invalid Legendre symbol result");return i?1:s?0:-1}function Ih(t,e){if(e!==void 0&&ds(e),t<=me)throw new Error("invalid n length: expected positive n, got "+t);if(e!==void 0&&e<1)throw new Error("invalid n length: expected positive bit length, got "+e);let r=mr(t);if(e!==void 0&&e<r)throw new Error(`invalid n length: expected nBitLength (${e}) >= bitLen(n) (${r})`);let n=e!==void 0?e:r,o=Math.ceil(n/8);return{nBitLength:n,nByteLength:o}}var Dc=new WeakMap,to=class{ORDER;BITS;BYTES;isLE;ZERO=me;ONE=ee;_lengths;_mod;constructor(e,r={}){if(e<=ee)throw new Error("invalid field: expected ORDER > 1, got "+e);let n;this.isLE=!1,r!=null&&typeof r=="object"&&(typeof r.BITS=="number"&&(n=r.BITS),typeof r.sqrt=="function"&&Object.defineProperty(this,"sqrt",{value:r.sqrt,enumerable:!0}),typeof r.isLE=="boolean"&&(this.isLE=r.isLE),r.allowedLengths&&(this._lengths=Object.freeze(r.allowedLengths.slice())),typeof r.modFromBytes=="boolean"&&(this._mod=r.modFromBytes));let{nBitLength:o,nByteLength:i}=Ih(e,n);if(i>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=e,this.BITS=o,this.BYTES=i,Object.freeze(this)}create(e){return ae(e,this.ORDER)}isValid(e){if(typeof e!="bigint")throw new TypeError("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&ee)===ee}neg(e){return ae(-e,this.ORDER)}eql(e,r){return e===r}sqr(e){return ae(e*e,this.ORDER)}add(e,r){return ae(e+r,this.ORDER)}sub(e,r){return ae(e-r,this.ORDER)}mul(e,r){return ae(e*r,this.ORDER)}pow(e,r){return Fc(e,r,this.ORDER)}div(e,r){return ae(e*Rc(r,this.ORDER),this.ORDER)}sqrN(e){return e*e}addN(e,r){return e+r}subN(e,r){return e-r}mulN(e,r){return e*r}inv(e){return Rc(e,this.ORDER)}sqrt(e){let r=Dc.get(this);return r||Dc.set(this,r=Ah(this.ORDER)),r(this,e)}toBytes(e){return this.isLE?hs(e,this.BYTES):eo(e,this.BYTES)}fromBytes(e,r=!1){J(e);let{_lengths:n,BYTES:o,isLE:i,ORDER:s,_mod:a}=this;if(n){if(e.length<1||!n.includes(e.length)||e.length>o)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+e.length);let f=new Uint8Array(o);f.set(e,i?0:f.length-e.length),e=f}if(e.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+e.length);let c=i?Xt(e):ot(e);if(a&&(c=ae(c,s)),!r&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(e){return ro(this,e,!0)}cmov(e,r,n){return Be(n,"condition"),n?r:e}};function gr(t,e={}){return Object.freeze(to.prototype),new to(t,e)}function $c(t){if(typeof t!="bigint")throw new Error("field order must be bigint");if(t<=ee)throw new Error("field order must be greater than 1");let e=mr(t-ee);return Math.ceil(e/8)}function no(t){let e=$c(t);return e+Math.ceil(e/2)}function oo(t,e,r=!1){J(t);let n=t.length,o=$c(e),i=Math.max(no(e),16);if(n<i||n>1024)throw new Error("expected "+i+"-1024 bytes of input, got "+n);let s=r?Xt(t):ot(t),a=ae(s,e-ee)+ee;return r?hs(a,o):eo(a,o)}var xs=BigInt(0),fn=BigInt(1),Bh=BigInt(4),bs=16,Vc=128,Ch=5,qc=2**31;function Dt(t){let e=t;if(typeof e!="function")throw new TypeError('"Point" expected constructor, got type='+typeof t);Zt(e.fromAffine,"Point.fromAffine"),Zt(e.fromBytes,"Point.fromBytes"),Zt(e.fromHex,"Point.fromHex"),Bt(e.BASE,"Point.BASE"),Bt(e.ZERO,"Point.ZERO"),yr(e.Fp),yr(e.Fn)}function io(t,e){Dt(t),Hc(e,t);let r=ro(t.Fp,e.map(n=>n.Z));return e.map((n,o)=>t.fromAffine(n.toAffine(r[o])))}function _h(t,e,r=1){if(!Number.isSafeInteger(t)||t<r||t>e)throw new Error("invalid window size, expected ["+r+".."+e+"], got W="+t)}function Rh(t,e){let r=t*(4*e+128);if(r>qc)throw new Error("invalid window size: table would need ~"+Math.ceil(r/2**20)+" MiB, max "+qc/2**20+" MiB")}function Es(t,e){if(t!==void 0){Zt(t,"randomBytes");try{let r=t(e);if(!_t(r)||r.length!==e)return}catch{return}return t}}function Hc(t,e){Qn(t,"points"),t.forEach((r,n)=>{if(!(r instanceof e))throw new Error("invalid point at index "+n)})}function Dh(t,e,r){if(!Array.isArray(t))throw new Error("array of scalars expected");t.forEach((n,o)=>{if(!(r===void 0?e.isValid(n):Ct(n)&&n<r))throw new Error("invalid scalar at index "+o)})}var jc=new WeakMap;function ws(t){return jc.get(t)||1}function Lh(t,e){let r=t.double(),n=[t];for(let o=1;o<e;o++)n.push(n[o-1].add(r));return n}function Nh(t,e){let r=2**e,n=r/2,o=BigInt(r-1),i=[];for(;t>xs;){let s=0;t&fn&&(s=Number(t&o),s>=n&&(s-=r),t-=BigInt(s)),i.push(s),t>>=fn}return i}function kh(t,e,r){let n=2**e,o=n/2,i=BigInt(n-1),s=BigInt(e),a=[];for(let c=0;c<r;c++){let f=Number(t&i);t>>=s,f>o&&(f-=n,t+=fn),a.push(f)}if(t!==xs)throw new Error("invalid wnaf");return a}function Uh(t,e,r){let n=0;for(let i of r)n=Math.max(n,i.length);let o=t;for(let i=n-1;i>=0;i--){i!==n-1&&(o=o.double());for(let s=0;s<r.length;s++){let a=r[s][i];if(a){let c=e[s][Math.abs(a)-1>>1];o=o.add(a<0?c.negate():c)}}}return o}var br=class{Point;BASE;ZERO;randomBytes;wnafPrecomputes=new WeakMap;baseCanBeBlinded;bits;constructor(e,r){Dt(e),this.randomBytes=Es(r,bs),this.Point=e,this.BASE=e.BASE,this.ZERO=e.ZERO,this.bits=e.Fn.BITS}buildWnafTable(e,r,n){let o=Math.ceil(n/r)+1,i=2**(r-1),s=[],a=e;for(let c=0;c<o;c++){let f=a;for(let u=0;u<i;u++)s.push(f),f=f.add(a);a=s[s.length-1].double()}return{W:r,bits:n,windows:o,comp:s}}wnafCachedCT(e,r){let{W:n,windows:o,comp:i}=e,s=2**(n-1),a=kh(r,n,o),c=this.ZERO,f=this.BASE;for(let u=0;u<o;u++){let l=a[u],h=u*s,m=Math.abs(l)-1,R=i[h];for(let y=1;y<s;y++)R=y===m?i[h+y]:R;let b=R.negate();l===0?f=f.add(i[h]):c=c.add(l<0?b:R)}return{p:c,f}}getWnafPrecomputes(e,r,n,o){let i=this.wnafPrecomputes.get(r),s=i?.find(a=>a.W===e&&a.bits===n);return s||(s=this.buildWnafTable(r,e,n),typeof o=="function"&&(s={...s,comp:o(s.comp)}),i||(i=[],this.wnafPrecomputes.set(r,i)),i.push(s)),s}assertPoint(e){if(!(e instanceof this.Point))throw new TypeError('"point" expected Point instance, got type='+typeof e)}validateMulInput(e,r){if(this.assertPoint(e),!ps(r,fn,this.Point.Fn.ORDER))throw new Error("invalid scalar")}runCT(e,r,n,o){let i=ws(e);return i===1?this.fixedWindowCT(e,r,n):this.wnafCachedCT(this.getWnafPrecomputes(i,e,n,o),r)}mulCT(e,r,n){return this.validateMulInput(e,r),this.runCT(e,r,this.bits,n)}mulCTBlinded(e,r,n){if(this.validateMulInput(e,r),this.randomBytes===void 0)throw new Error("randomBytes is required for scalar blinding");let o=this.Point.Fn.BITS+Vc,i=this.randomBytes(bs);if(!_t(i)||i.length!==bs)throw new Error("randomBytes returned invalid byte array");i[0]=i[0]&63|128;let s=r+ot(i)*this.Point.Fn.ORDER;return this.runCT(e,s,o,n)}fixedWindowCT(e,r,n){let o=Ch,i=1<<o,s=cn(o),a=new Array(i);a[0]=this.ZERO;for(let u=1;u<i;u++)a[u]=a[u-1].add(e);let c=Math.ceil(n/o),f=this.ZERO;for(let u=c-1;u>=0;u--){if(u!==c-1)for(let m=0;m<o;m++)f=f.double();let l=Number(r>>BigInt(u*o)&s),h=a[0];for(let m=1;m<i;m++)h=m===l?a[m]:h;f=f.add(h)}return{p:f,f}}shouldBlind(e,r){return this.randomBytes===void 0?!1:r===fn?!0:e!==this.BASE?!1:(this.baseCanBeBlinded===void 0&&(this.baseCanBeBlinded=this.mulUnsafe(this.BASE,this.Point.Fn.ORDER).is0()),this.baseCanBeBlinded)}mulSecret(e,r,n,o){return this.shouldBlind(e,n)?this.mulCTBlinded(e,r,o):this.mulCT(e,r,o)}mulUnsafe(e,r,n){if(this.assertPoint(e),!Ct(r))throw new Error("invalid scalar");let o=ws(e);if(o===1||r>=this.Point.Fn.ORDER)return so(this.Point,[e],[r],!0);let i=this.getWnafPrecomputes(o,e,this.bits,n);return this.wnafCachedCT(i,r).p}setWindowSize(e,r){this.assertPoint(e),_h(r,this.bits);let n=Math.ceil((this.bits+Vc)/r)+1;Rh(n*2**(r-1),this.Point.Fp.BYTES),jc.set(e,r),this.wnafPrecomputes.delete(e)}hasWindowSize(e){return ws(e)!==1}};function so(t,e,r,n=!1){if(Dt(t),Hc(e,t),Be(n,"allowOversized"),Dh(r,t.Fn,n?t.Fn.ORDER**Bh:void 0),e.length!==r.length)throw new Error("arrays of points and scalars must have equal length");let o=e.map(s=>Lh(s,4)),i=r.map(s=>Nh(s,4));return Uh(t.ZERO,o,i)}function zc(t,e,r){if(e){if(e.ORDER!==t)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return yr(e),e}else return gr(t,{isLE:r})}function ao(t,e,r={},n){if(t!=="weierstrass"&&t!=="edwards")throw new Error('expected curve type "weierstrass" or "edwards"');if(n===void 0&&(n=t==="edwards"),!e||typeof e!="object")throw new Error(`expected valid ${t} CURVE object`);Ce(r);for(let c of["p","n","h"]){let f=e[c];if(!(Ct(f)&&f!==xs))throw new Error(`CURVE.${c} must be positive bigint`)}let o=zc(e.p,r.Fp,n),i=zc(e.n,r.Fn,n),a=["Gx","Gy","a",t==="weierstrass"?"b":"d"];for(let c of a)if(!o.isValid(e[c]))throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);return e=Object.freeze(Object.assign({},e)),{CURVE:e,Fp:o,Fn:i}}function co(t,e){return function(n){let o=t(n);return{secretKey:o,publicKey:e(o)}}}var uo=BigInt(0),fo=BigInt(1),lo=BigInt(2),Fh=BigInt(4),Yc=BigInt(8);function Oh(t,e,r,n){let o=t.sqr(r),i=t.sqr(n),s=t.add(t.mul(e.a,o),i),a=t.add(t.ONE,t.mul(e.d,t.mul(o,i)));return t.eql(s,a)}function Zc(t,e={}){Ce(e,{},{},"extraOpts");let r=e,n=ao("edwards",t,r,r.FpFnLE),{Fp:o,Fn:i}=n,s=n.CURVE,{h:a}=s;if(un(o,s.a)!==1)throw new Error("edwards: CURVE.a must be a square in Fp for complete addition formulas");if(un(o,s.d)!==-1)throw new Error("edwards: CURVE.d must be a non-square in Fp for complete addition formulas");Ce(r,{},{uvRatio:"function",randomBytes:"function"});let c=r.randomBytes===void 0?Gt:r.randomBytes,f=lo<<BigInt(o.BYTES*8)-fo;function u(T){if(!o.isOdd)throw new Error("Field does not have .isOdd()");return o.isOdd(T)}let l=r.uvRatio===void 0?(T,g)=>{try{return{isValid:!0,value:o.sqrt(o.div(T,g))}}catch{return{isValid:!1,value:uo}}}:r.uvRatio;if(!Oh(o,s,s.Gx,s.Gy))throw new Error("bad curve params: generator point");let h=o.eql(s.a,o.neg(o.ONE))?T=>o.neg(T):o.eql(s.a,o.ONE)?T=>T:T=>o.mul(s.a,T);function m(T,g,D=!1){let C=D?fo:uo;return pr("coordinate "+T,g,C,f),g}function R(T){if(!(T instanceof b))throw new Error("EdwardsPoint expected")}class b{static BASE=new b(s.Gx,s.Gy,o.ONE,o.mul(s.Gx,s.Gy));static ZERO=new b(o.ZERO,o.ONE,o.ONE,o.ZERO);static Fp=o;static Fn=i;X;Y;Z;T;constructor(g,D,C,V){this.X=m("x",g),this.Y=m("y",D),this.Z=m("z",C,!0),this.T=m("t",V),Object.freeze(this)}static CURVE(){return s}static fromAffine(g){if(g instanceof b)throw new Error("extended point not allowed");let{x:D,y:C}=g||{};return m("x",D),m("y",C),new b(D,C,o.ONE,o.mul(D,C))}static fromBytes(g,D=!1){let C=o.BYTES,{a:V,d:q}=s;g=an(J(g,C,"point")),Be(D,"zip215");let w=an(g),E=g[C-1];w[C-1]=E&-129;let v=Xt(w),N=D?f:o.ORDER;pr("point.y",v,uo,N);let L=o.sqr(v),z=o.sub(L,o.ONE),I=o.sub(o.mulN(q,L),V),{isValid:k,value:O}=l(z,I);if(!k)throw new Error("bad point: invalid y coordinate");let P=u(O),Y=(E&128)!==0;if(!D&&o.is0(O)&&Y)throw new Error("bad point: x=0 and x_0=1");return Y!==P&&(O=o.neg(O)),b.fromAffine({x:O,y:v})}static fromHex(g,D=!1){return b.fromBytes(hr(g),D)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(g=6,D=!0){return S.setWindowSize(this,g),D||this.multiply(lo),this}assertValidity(){let g=this,{a:D,d:C}=s;if(g.is0())throw new Error("bad point: ZERO");let{X:V,Y:q,Z:w,T:E}=g,v=o.sqr(V),N=o.sqr(q),L=o.sqr(w),z=o.sqr(L),I=o.mul(v,D),k=o.mul(o.add(I,N),L),O=o.add(z,o.mul(C,o.mul(v,N)));if(!o.eql(k,O))throw new Error("bad point: equation left != right (1)");let P=o.mul(V,q),Y=o.mul(w,E);if(!o.eql(P,Y))throw new Error("bad point: equation left != right (2)")}equals(g){R(g);let{X:D,Y:C,Z:V}=this,{X:q,Y:w,Z:E}=g,v=o.mul(D,E),N=o.mul(q,V),L=o.mul(C,E),z=o.mul(w,V);return o.eql(v,N)&&o.eql(L,z)}is0(){return this.equals(b.ZERO)}negate(){return new b(o.neg(this.X),this.Y,this.Z,o.neg(this.T))}double(){let{X:g,Y:D,Z:C}=this,V=o.sqr(g),q=o.sqr(D),w=o.mul(o.sqr(C),lo),E=h(V),v=o.addN(g,D),N=o.sub(o.subN(o.sqr(v),V),q),L=o.addN(E,q),z=o.subN(L,w),I=o.subN(E,q),k=o.mul(N,z),O=o.mul(L,I),P=o.mul(N,I),Y=o.mul(z,L);return new b(k,O,Y,P)}add(g){R(g);let{d:D}=s,{X:C,Y:V,Z:q,T:w}=this,{X:E,Y:v,Z:N,T:L}=g,z=o.mul(C,E),I=o.mul(V,v),k=o.mul(o.mulN(w,D),L),O=o.mul(q,N),P=o.sub(o.subN(o.mulN(o.addN(C,V),o.addN(E,v)),z),I),Y=o.subN(O,k),W=o.addN(O,k),U=o.sub(I,h(z)),p=o.mul(P,Y),x=o.mul(W,U),A=o.mul(P,U),F=o.mul(Y,W);return new b(p,x,F,A)}subtract(g){return R(g),this.add(g.negate())}multiply(g){if(!i.isValidNot0(g))throw new RangeError("invalid scalar: expected 1 <= sc < curve.n");let{p:D,f:C}=S.mulSecret(this,g,a,y);return y([D,C])[0]}multiplyUnsafe(g){if(!i.isValid(g))throw new RangeError("invalid scalar: expected 0 <= sc < curve.n");return g===uo?b.ZERO:this.is0()||g===fo?this:S.mulUnsafe(this,g,y)}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){return S.mulUnsafe(this,s.n).is0()}toAffine(g){let D=this,C=g;if(C!=null&&typeof C!="bigint")throw new TypeError('"invertedZ" expected bigint, got type='+typeof C);let{X:V,Y:q,Z:w}=D,E=D.is0();C==null&&(C=E?o.create(Yc):o.inv(w));let v=o.mul(V,C),N=o.mul(q,C),L=o.mul(w,C);if(E)return{x:o.ZERO,y:o.ONE};if(!o.eql(L,o.ONE))throw new Error("invZ was invalid");return{x:v,y:N}}clearCofactor(){return a===fo?this:a===lo?this.double():a===Fh?this.double().double():a===Yc?this.double().double().double():this.multiplyUnsafe(a)}toBytes(){let{x:g,y:D}=this.toAffine(),C=o.toBytes(D);return C[C.length-1]|=u(g)?128:0,C}toHex(){return on(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let y=T=>io(b,T),S=new br(b,c);return S.bits>=6&&b.BASE.precompute(6),Object.freeze(b.prototype),Object.freeze(b),b}function Gc(t,e,r={}){if(Dt(t),typeof e!="function")throw new Error('"hash" function param is required');let n=e,o=r;Ce(o,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",zip215:"boolean",mapToCurve:"function",toMontgomery:"function",toMontgomerySecret:"function"});let{prehash:i}=o,{BASE:s,Fp:a,Fn:c}=t,f=n.outputLen,u=2*a.BYTES;if(f!==void 0&&(lt(f,"hash.outputLen"),f!==u))throw new Error(`hash.outputLen must be ${u}, got ${f}`);let l=o.randomBytes===void 0?Gt:o.randomBytes,h=o.toMontgomery,m=o.toMontgomerySecret,R=o.adjustScalarBytes===void 0?I=>I:o.adjustScalarBytes,b=o.domain===void 0?(I,k,O)=>{if(Be(O,"phflag"),k.length||O)throw new Error("Contexts/pre-hash are not supported");return I}:o.domain;function y(I){return c.create(Xt(I))}function S(I){let k=E.secretKey;J(I,E.secretKey,"secretKey");let O=J(n(I),2*k,"hashedSecretKey"),P=R(O.slice(0,k)),Y=O.slice(k,2*k),W=y(P);return{head:P,prefix:Y,scalar:W}}function T(I){let{head:k,prefix:O,scalar:P}=S(I),Y=s.multiply(P),W=Y.toBytes();return{head:k,prefix:O,scalar:P,point:Y,pointBytes:W}}function g(I){return T(I).pointBytes}function D(I=Uint8Array.of(),...k){let O=qe(...k);return y(n(b(O,J(I,void 0,"context"),!!i)))}function C(I,k,O={}){Ce(O,{},{},"options"),I=an(J(I,void 0,"message")),i&&(I=i(I));let{prefix:P,scalar:Y,pointBytes:W}=T(k),U=D(O.context,P,I),p=s.multiply(U).toBytes(),x=D(O.context,p,W,I),A=c.create(U+x*Y);if(!c.isValid(A))throw new Error("sign failed: invalid s");let F=qe(p,c.toBytes(A));return J(F,E.signature,"result")}let V={zip215:o.zip215};function q(I,k,O,P=V){Ce(P);let{context:Y}=P,W=P.zip215===void 0?!!V.zip215:P.zip215,U=E.signature;I=J(I,U,"signature"),k=J(k,void 0,"message"),O=J(O,E.publicKey,"publicKey"),W!==void 0&&Be(W,"zip215"),i&&(k=i(k));let p=U/2,x=I.subarray(0,p),A=Xt(I.subarray(p,U)),F,M,K;try{F=t.fromBytes(O,W),M=t.fromBytes(x,W),K=s.multiplyUnsafe(A)}catch{return!1}if(!W&&F.isSmallOrder())return!1;let H=D(Y,x,O,k);return M.add(F.multiplyUnsafe(H)).subtract(K).clearCofactor().is0()}let w=a.BYTES,E={secretKey:w,publicKey:w,signature:2*w,seed:w};function v(I){return I=I===void 0?l(E.seed):I,J(I,E.seed,"seed")}function N(I){return _t(I)&&I.length===E.secretKey}function L(I,k){try{return!!t.fromBytes(I,k===void 0?V.zip215:k)}catch{return!1}}let z={getExtendedPublicKey:T,randomSecretKey:v,isValidSecretKey:N,isValidPublicKey:L,toMontgomery(I){if(h===void 0)throw new Error("Montgomery conversion is not supported for this curve");return h(t.fromBytes(I))},toMontgomerySecret(I){if(m===void 0)throw new Error("Montgomery conversion is not supported for this curve");return m(I)}};return Object.freeze(E),Object.freeze(z),Object.freeze({keygen:co(v,g),getPublicKey:g,sign:C,verify:q,utils:z,Point:t,lengths:E})}var Ss=BigInt(1),Xc=BigInt(2);var Ph=BigInt(5),Mh=BigInt(8),vs=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),Kh={p:vs,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:Mh,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function $h(t){let e=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),i=vs,a=t*t%i*t%i,c=ie(a,Xc,i)*a%i,f=ie(c,Ss,i)*t%i,u=ie(f,Ph,i)*f%i,l=ie(u,e,i)*u%i,h=ie(l,r,i)*l%i,m=ie(h,n,i)*h%i,R=ie(m,o,i)*m%i,b=ie(R,o,i)*m%i,y=ie(b,e,i)*u%i;return{pow_p_5_8:ie(y,Xc,i)*t%i,b2:a}}function Jc(t){return t[0]&=248,t[31]&=127,t[31]|=64,t}var Wc=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function Vh(t,e){let r=vs,n=ae(e*e*e,r),o=ae(n*n*e,r),i=$h(t*o).pow_p_5_8,s=ae(t*n*i,r),a=ae(e*s*s,r),c=s,f=ae(s*Wc,r),u=a===t,l=a===ae(-t,r),h=a===ae(-t*Wc,r);return u&&(s=c),(l||h)&&(s=f),Kc(s,r)&&(s=ae(-s,r)),{isValid:u||l,value:s}}var As=Zc(Kh,{uvRatio:Vh}),Qc=As.Fp;function qh(t){let{y:e}=t;return Qc.toBytes(Qc.div(Ss+e,Ss-e))}function zh(t){let e=As.Fp.BYTES;return Ve(t,e),Jc(ls(t.subarray(0,e))).subarray(0,e)}function Hh(t){return Gc(As,ls,Object.assign({adjustScalarBytes:Jc,toMontgomery:qh,toMontgomerySecret:zh,zip215:!0},t))}var eu=Hh({});var ln=class extends Error{constructor(e="An error occurred while verifying a message"){super(e),this.name="VerificationError"}},ho=class extends Error{constructor(e="Missing Web Crypto API"){super(e),this.name="WebCryptoMissingError"}};var po={get(t=globalThis){let e=t.crypto;if(e?.subtle==null)throw new ho("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api");return e}};var mo=32;var Ts,jh=(async()=>{try{return await po.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function Yh(t,e,r){if(t.buffer instanceof ArrayBuffer){let n=await po.get().subtle.importKey("raw",t.buffer,{name:"Ed25519"},!1,["verify"]);return await po.get().subtle.verify({name:"Ed25519"},n,Te(e),Te(r instanceof Uint8Array?r:r.subarray()))}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function Zh(t,e,r){return eu.verify(e,r instanceof Uint8Array?r:r.subarray(),t)}async function tu(t,e,r){return Ts==null&&(Ts=await jh),Ts?Yh(t,e,r):Zh(t,e,r)}function yo(t){return t==null?!1:typeof t.then=="function"&&typeof t.catch=="function"&&typeof t.finally=="function"}var go=class{type="Ed25519";raw;constructor(e){this.raw=Is(e,mo)}toMultihash(){return Ge.digest(lr(this))}toCID(){return se.createV1(114,this.toMultihash())}toString(){return re.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:de(this.raw,e.raw)}verify(e,r,n){n?.signal?.throwIfAborted();let o=tu(this.raw,r,e);return yo(o)?o.then(i=>(n?.signal?.throwIfAborted(),i)):o}};function nu(t){return t=Is(t,mo),new go(t)}function Is(t,e){if(t=Uint8Array.from(t??[]),t.length!==e)throw new ut(`Key must be a Uint8Array of length ${e}, got ${t.length}`);return t}var ve;(function(t){t.RSA="RSA",t.Ed25519="Ed25519",t.secp256k1="secp256k1",t.ECDSA="ECDSA"})(ve||(ve={}));var Bs;(function(t){t[t.RSA=0]="RSA",t[t.Ed25519=1]="Ed25519",t[t.secp256k1=2]="secp256k1",t[t.ECDSA=3]="ECDSA"})(Bs||(Bs={}));(function(t){t.codec=()=>Vt(Bs)})(ve||(ve={}));var dn;(function(t){let e;t.codec=()=>(e==null&&(e=tt((i,s,a={})=>{a.lengthDelimited!==!1&&s.fork(),i.Type!=null&&(s.uint32(8),ve.codec().encode(i.Type,s)),i.Data!=null&&(s.uint32(18),s.bytes(i.Data)),a.lengthDelimited!==!1&&s.ldelim()},(i,s,a={})=>{let c={},f=s==null?i.len:i.pos+s;for(;i.pos<f;){let u=i.uint32();switch(u>>>3){case 1:{c.Type=ve.codec().decode(i);break}case 2:{c.Data=i.bytes();break}default:{i.skipType(u&7);break}}}return c},function*(i,s,a,c={}){let f=s==null?i.len:i.pos+s;for(;i.pos<f;){let u=i.uint32();switch(u>>>3){case 1:{yield{field:`${a}.Type`,value:ve.codec().decode(i)};break}case 2:{yield{field:`${a}.Data`,value:i.bytes()};break}default:{i.skipType(u&7);break}}}})),e);function r(i){return Je(i,t.codec())}t.encode=r;function n(i,s){return Qe(i,t.codec(),s)}t.decode=n;function o(i,s){return et(i,t.codec(),s)}t.stream=o})(dn||(dn={}));var Cs;(function(t){let e;t.codec=()=>(e==null&&(e=tt((i,s,a={})=>{a.lengthDelimited!==!1&&s.fork(),i.Type!=null&&(s.uint32(8),ve.codec().encode(i.Type,s)),i.Data!=null&&(s.uint32(18),s.bytes(i.Data)),a.lengthDelimited!==!1&&s.ldelim()},(i,s,a={})=>{let c={},f=s==null?i.len:i.pos+s;for(;i.pos<f;){let u=i.uint32();switch(u>>>3){case 1:{c.Type=ve.codec().decode(i);break}case 2:{c.Data=i.bytes();break}default:{i.skipType(u&7);break}}}return c},function*(i,s,a,c={}){let f=s==null?i.len:i.pos+s;for(;i.pos<f;){let u=i.uint32();switch(u>>>3){case 1:{yield{field:`${a}.Type`,value:ve.codec().decode(i)};break}case 2:{yield{field:`${a}.Data`,value:i.bytes()};break}default:{i.skipType(u&7);break}}}})),e);function r(i){return Je(i,t.codec())}t.encode=r;function n(i,s){return Qe(i,t.codec(),s)}t.decode=n;function o(i,s){return et(i,t.codec(),s)}t.stream=o})(Cs||(Cs={}));var bo=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(e,r){if(jn(e),Ve(r,void 0,"key"),this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("expected Hash instance");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,o=new Uint8Array(n);o.set(r.length>n?e.create().update(r).digest():r);for(let i=0;i<o.length;i++)o[i]^=54;this.iHash.update(o),this.oHash=e.create();for(let i=0;i<o.length;i++)o[i]^=106;this.oHash.update(o),Yt(o)}update(e){return dr(this),this.iHash.update(e),this}digestInto(e){dr(this),Yn(e,this),this.finished=!0;let r=e.subarray(0,this.outputLen);this.iHash.digestInto(r),this.oHash.update(r),this.oHash.digestInto(r),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:r,iHash:n,finished:o,destroyed:i,blockLen:s,outputLen:a,canXOF:c}=this;return e=e,e.finished=o,e.destroyed=i,e.blockLen=s,e.outputLen=a,e.canXOF=c,e.oHash=r._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},ou=(()=>{let t=((e,r,n)=>new bo(e,r).update(n).digest());return t.create=(e,r)=>new bo(e,r),t})();var Wh=BigInt(0),_s=class extends Error{constructor(e=""){super(e)}},dt={Err:_s,_tlv:{encode:(t,e)=>{let{Err:r}=dt;if(lt(t,"tag"),t<0||t>255)throw new r("tlv.encode: wrong tag");if(Bc(e,"data"),e.length&1)throw new r("tlv.encode: unpadded data");let n=e.length/2,o=sn(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let i=n>127?sn(o.length/2|128):"";return sn(t)+i+o+e},decode(t,e){let{Err:r}=dt;e=J(e,void 0,"DER data");let n=0;if(t<0||t>255)throw new r("tlv.decode: wrong tag");if(e.length<2||e[n++]!==t)throw new r("tlv.decode: wrong tlv");let o=e[n++],i=!!(o&128),s=0;if(!i)s=o;else{let c=o&127;if(!c)throw new r("tlv.decode(long): indefinite length not supported");if(c>4)throw new r("tlv.decode(long): byte length is too big");let f=e.subarray(n,n+c);if(f.length!==c)throw new r("tlv.decode: length bytes not complete");if(f[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let u of f)s=s<<8|u;if(n+=c,s<128)throw new r("tlv.decode(long): not minimal encoding")}let a=e.subarray(n,n+s);if(a.length!==s)throw new r("tlv.decode: wrong value length");return{v:a,l:e.subarray(n+s)}}},_int:{encode(t){let{Err:e}=dt;if(Jn(t),t<Wh)throw new e("integer: negative integers are not allowed");let r=sn(t);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new e("unexpected DER parsing assertion: unpadded hex");return r},decode(t){let{Err:e}=dt;if(t.length<1)throw new e("invalid signature integer: empty");if(t[0]&128)throw new e("invalid signature integer: negative");if(t.length>1&&t[0]===0&&!(t[1]&128))throw new e("invalid signature integer: unnecessary leading zero");return ot(t)}},toSig(t,e){let{Err:r,_int:n,_tlv:o}=dt;if(e!==void 0&&(lt(e,"maxScalarBytes"),e<1))throw new r("invalid signature: maxScalarBytes must be positive");let i=J(t,void 0,"signature"),{v:s,l:a}=o.decode(48,i);if(a.length)throw new r("invalid signature: left bytes after parsing");let{v:c,l:f}=o.decode(2,s),{v:u,l}=o.decode(2,f);if(l.length)throw new r("invalid signature: left bytes after parsing");if(e!==void 0&&(c.length>e||u.length>e))throw new r("invalid signature: integer too large");return{r:n.decode(c),s:n.decode(u)}},hexFromSig(t){let{_tlv:e,_int:r}=dt;Ce(t,{r:"bigint",s:"bigint"},{},"sig");let n=e.encode(2,r.encode(t.r)),o=e.encode(2,r.encode(t.s)),i=n+o;return e.encode(48,i)}},wo=(Object.freeze(dt._tlv),Object.freeze(dt._int),Object.freeze(dt));var iu=(t,e)=>(t+(t>=0?e:-e)/su)/e;function Qh(t,e,r){pr("scalar",t,ht,r);let[[n,o],[i,s]]=e,a=iu(s*t,r),c=iu(-o*t,r),f=t-a*n-c*i,u=-a*o-c*s,l=f<ht,h=u<ht;l&&(f=-f),h&&(u=-u);let m=cn(Math.ceil(mr(r)/2))+Wt;if(f<ht||f>=m||u<ht||u>=m)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:l,k1:f,k2neg:h,k2:u}}function Ls(t){if(!["compact","recovered","der"].includes(t))throw new Error('Signature format must be "compact", "recovered", or "der"');return t}function Rs(t,e){Ce(t);let r={};for(let n of Object.keys(e))r[n]=t[n]===void 0?e[n]:t[n];return Be(r.lowS,"lowS"),Be(r.prehash,"prehash"),r.format!==void 0&&Ls(r.format),r}var ht=BigInt(0),Wt=BigInt(1),su=BigInt(2),Ds=BigInt(3),Jh=BigInt(4);function au(t,e={}){let r=ao("weierstrass",t,e),n=r.Fp,o=r.Fn,i=r.CURVE,{h:s,n:a}=i;Ce(e,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",randomBytes:"function"});let{endo:c,allowInfinityPoint:f,clearCofactor:u,isTorsionFree:l,fromBytes:h,toBytes:m}=e,R=e.randomBytes===void 0?Gt:e.randomBytes;if(c&&(!n.is0(i.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let b=c?{beta:c.beta,basises:c.basises.map(U=>[...U])}:void 0,y=uu(n,o);function S(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function T(U,p,x){if(p.is0()){if(!f)throw new Error("bad point: ZERO");return Uint8Array.of(0)}let{x:A,y:F}=p.toAffine(),M=n.toBytes(A);if(Be(x,"isCompressed"),x){S();let K=!n.isOdd(F);return qe(cu(K),M)}else return qe(Uint8Array.of(4),M,n.toBytes(F))}function g(U){J(U,void 0,"Point");let{publicKey:p,publicKeyUncompressed:x}=y,A=U.length,F=U[0],M=U.subarray(1);if(f&&A===1&&F===0)return{x:n.ZERO,y:n.ZERO};if(A===p&&(F===2||F===3)){let K=n.fromBytes(M);if(!n.isValid(K))throw new Error("bad point: is not on curve, wrong x");let H=w(K),j;try{j=n.sqrt(H)}catch(ue){let ne=ue instanceof Error?": "+ue.message:"";throw new Error("bad point: is not on curve, sqrt error"+ne)}S();let X=n.isOdd(j);return(F&1)===1!==X&&(j=n.neg(j)),{x:K,y:j}}else if(A===x&&F===4){let K=n.BYTES,H=n.fromBytes(M.subarray(0,K)),j=n.fromBytes(M.subarray(K,K*2));if(!E(H,j))throw new Error("bad point: is not on curve");return{x:H,y:j}}else throw new Error(`bad point: got length ${A}, expected compressed=${p} or uncompressed=${x}`)}let D=m===void 0?T:m,C=h===void 0?g:h,V=n.mul(i.b,Ds),q=n.is0(i.a)?U=>n.ZERO:U=>n.mul(i.a,U);function w(U){let p=n.sqr(U),x=n.mul(p,U);return n.add(n.add(x,n.mul(U,i.a)),i.b)}function E(U,p){let x=n.sqr(p),A=w(U);return n.eql(x,A)}if(!E(i.Gx,i.Gy))throw new Error("bad curve params: generator point");let v=n.mul(n.pow(i.a,Ds),Jh),N=n.mul(n.sqr(i.b),BigInt(27));if(n.is0(n.add(v,N)))throw new Error("bad curve params: a or b");function L(U,p,x=!1){if(!n.isValid(p)||x&&n.is0(p))throw new Error(`bad point coordinate ${U}`);return typeof p=="object"&&p!==null?n.create(p):p}function z(U){if(!(U instanceof P))throw new Error("Weierstrass Point expected")}function I(U){if(!b||!b.basises)throw new Error("no endo");return Qh(U,b.basises,o.ORDER)}function k(U,p,x,A){if(!o.isValid(A))throw new RangeError("invalid scalar: out of range");if(b){let{k1neg:F,k1:M,k2neg:K,k2:H}=I(A),j=new P(n.mul(x.X,b.beta),x.Y,x.Z);U.push(F?x.negate():x,K?j.negate():j),p.push(M,H)}else U.push(x),p.push(A)}let O=new WeakSet;class P{static BASE=new P(i.Gx,i.Gy,n.ONE);static ZERO=new P(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(p,x,A){this.X=L("x",p),this.Y=L("y",x,!0),this.Z=L("z",A),Object.freeze(this)}static CURVE(){return i}static fromAffine(p){let{x,y:A}=p||{};if(!p||!n.isValid(x)||!n.isValid(A))throw new Error("invalid affine point");if(p instanceof P)throw new Error("projective point not allowed");return n.is0(x)&&n.is0(A)?P.ZERO:new P(x,A,n.ONE)}static fromBytes(p){let x=P.fromAffine(C(J(p,void 0,"point")));return x.assertValidity(),x}static fromHex(p){return P.fromBytes(hr(p))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(p=6,x=!0){return W.setWindowSize(this,p),x||this.multiply(Ds),this}assertValidity(){let p=this;if(p.is0()){if(f&&n.is0(p.X)&&n.eql(p.Y,n.ONE)&&n.is0(p.Z))return;throw new Error("bad point: ZERO")}if(O.has(p))return;let{x,y:A}=p.toAffine();if(!n.isValid(x)||!n.isValid(A))throw new Error("bad point: x or y not field elements");if(!E(x,A))throw new Error("bad point: equation left != right");if(!p.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");O.add(p)}hasEvenY(){let{y:p}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(p)}equals(p){z(p);let{X:x,Y:A,Z:F}=this,{X:M,Y:K,Z:H}=p,j=n.eql(n.mul(x,H),n.mul(M,F)),X=n.eql(n.mul(A,H),n.mul(K,F));return j&&X}negate(){return new P(this.X,n.neg(this.Y),this.Z)}double(){let{X:p,Y:x,Z:A}=this,F=n.ZERO,M=n.ZERO,K=n.ZERO,H=n.mul(p,p),j=n.mul(x,x),X=n.mul(A,A),Z=n.mul(p,x);return Z=n.add(Z,Z),K=n.mul(p,A),K=n.add(K,K),F=q(K),M=n.mul(V,X),M=n.add(F,M),F=n.sub(j,M),M=n.add(j,M),M=n.mul(F,M),F=n.mul(Z,F),K=n.mul(V,K),X=q(X),Z=n.sub(H,X),Z=q(Z),Z=n.add(Z,K),K=n.add(H,H),H=n.add(K,H),H=n.add(H,X),H=n.mul(H,Z),M=n.add(M,H),X=n.mul(x,A),X=n.add(X,X),H=n.mul(X,Z),F=n.sub(F,H),K=n.mul(X,j),K=n.add(K,K),K=n.add(K,K),new P(F,M,K)}add(p){z(p);let{X:x,Y:A,Z:F}=this,{X:M,Y:K,Z:H}=p,j=n.ZERO,X=n.ZERO,Z=n.ZERO,ue=n.mul(x,M),ne=n.mul(A,K),be=n.mul(F,H),Pe=n.add(x,A),oe=n.add(M,K);Pe=n.mul(Pe,oe),oe=n.add(ue,ne),Pe=n.sub(Pe,oe),oe=n.add(x,F);let fe=n.add(M,H);return oe=n.mul(oe,fe),fe=n.add(ue,be),oe=n.sub(oe,fe),fe=n.add(A,F),j=n.add(K,H),fe=n.mul(fe,j),j=n.add(ne,be),fe=n.sub(fe,j),Z=q(oe),j=n.mul(V,be),Z=n.add(j,Z),j=n.sub(ne,Z),Z=n.add(ne,Z),X=n.mul(j,Z),ne=n.add(ue,ue),ne=n.add(ne,ue),be=q(be),oe=n.mul(V,oe),ne=n.add(ne,be),be=n.sub(ue,be),be=q(be),oe=n.add(oe,be),ue=n.mul(ne,oe),X=n.add(X,ue),ue=n.mul(fe,oe),j=n.mul(Pe,j),j=n.sub(j,ue),ue=n.mul(Pe,ne),Z=n.mul(fe,Z),Z=n.add(Z,ue),new P(j,X,Z)}subtract(p){return z(p),this.add(p.negate())}is0(){return this.equals(P.ZERO)}multiply(p){if(!o.isValidNot0(p))throw new RangeError("invalid scalar: out of range");let{p:x,f:A}=W.mulSecret(this,p,s,Y);return Y([x,A])[0]}multiplyUnsafe(p){let x=this,A=p;if(!o.isValid(A))throw new RangeError("invalid scalar: out of range");if(A===ht||x.is0())return P.ZERO;if(A===Wt)return x;if(W.hasWindowSize(this))return W.mulUnsafe(x,A,Y);let F=[],M=[];return k(F,M,x,A),so(P,F,M)}mulAddUnsafe(p,x,A){z(x);let F=[],M=[];return k(F,M,this,p),k(F,M,x,A),so(P,F,M)}toAffine(p){let x=this,A=p;if(A!=null&&!n.isValid(A))throw new RangeError('"invertedZ" expected valid field element');let{X:F,Y:M,Z:K}=x;if(n.eql(K,n.ONE))return{x:F,y:M};let H=x.is0();A==null&&(A=H?n.ONE:n.inv(K));let j=n.mul(F,A),X=n.mul(M,A),Z=n.mul(K,A);if(H)return{x:n.ZERO,y:n.ZERO};if(!n.eql(Z,n.ONE))throw new Error("invZ was invalid");return{x:j,y:X}}isTorsionFree(){return s===Wt?!0:l?l(P,this):W.mulUnsafe(this,a).is0()}clearCofactor(){return s===Wt?this:u?u(P,this):this.multiplyUnsafe(s)}isSmallOrder(){return s===Wt?this.is0():this.clearCofactor().is0()}toBytes(p=!0){return Be(p,"isCompressed"),this.assertValidity(),D(P,this,p)}toHex(p=!0){return on(this.toBytes(p))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let Y=U=>io(P,U),W=new br(P,R);return W.bits>=6&&P.BASE.precompute(6),Object.freeze(P.prototype),Object.freeze(P),P}function cu(t){return Uint8Array.of(t?2:3)}function uu(t,e){return{secretKey:e.BYTES,publicKey:1+t.BYTES,publicKeyUncompressed:1+2*t.BYTES,publicKeyHasPrefix:!0,signature:2*e.BYTES}}function ep(t,e={}){Dt(t);let{Fn:r}=t,n=e.randomBytes===void 0?Gt:e.randomBytes,o=Object.assign(uu(t.Fp,r),{seed:Math.max(no(r.ORDER),16)});function i(m){try{let R=r.fromBytes(m);return r.isValidNot0(R)}catch{return!1}}function s(m,R){let{publicKey:b,publicKeyUncompressed:y}=o;try{let S=m.length;return R===!0&&S!==b||R===!1&&S!==y?!1:!t.fromBytes(m).is0()}catch{return!1}}function a(m){return m=m===void 0?n(o.seed):m,oo(J(m,o.seed,"seed"),r.ORDER)}function c(m,R=!0){return t.BASE.multiply(r.fromBytes(m)).toBytes(R)}function f(m){let{secretKey:R,publicKey:b,publicKeyUncompressed:y}=o,S=r._lengths;if(!_t(m))return;let T=J(m,void 0,"key").length,g=T===b||T===y,D=T===R||!!S?.includes(T);if(!(g&&D))return g}function u(m,R,b=!0){if(f(m)===!0)throw new Error("first arg must be private key");if(f(R)===!1)throw new Error("second arg must be public key");let y=r.fromBytes(m),S=t.fromBytes(R);if(S.is0())throw new Error("invalid public key: point at infinity");return S.multiply(y).toBytes(b)}let l={isValidSecretKey:i,isValidPublicKey:s,randomSecretKey:a},h=co(a,c);return Object.freeze(l),Object.freeze(o),Object.freeze({getPublicKey:c,getSharedSecret:u,keygen:h,Point:t,utils:l,lengths:o})}function fu(t,e,r={}){Dt(t);let n=e;jn(n),Ce(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let o=Object.assign({},r),i=o.randomBytes===void 0?Gt:o.randomBytes,s=o.hmac===void 0?(U,p)=>ou(n,U,p):o.hmac,{Fp:a,Fn:c}=t,{ORDER:f,BITS:u}=c,l=no(f),h=Es(i,l),{keygen:m,getPublicKey:R,getSharedSecret:b,utils:y,lengths:S}=ep(t,o),T={prehash:!0,lowS:typeof o.lowS=="boolean"?o.lowS:!0,format:"compact",extraEntropy:!1},g=f*su+Wt<a.ORDER;function D(U){let p=f>>Wt;return U>p}function C(U,p){if(!c.isValidNot0(p))throw new Error(`invalid signature ${U}: out of range 1..Point.Fn.ORDER`);return p}function V(){if(!a.isOdd)throw new Error("Field doesn't support isOdd")}function q(U,p,x){return V(),(U===x?0:2)|Number(a.isOdd(p))}function w(){if(g)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function E(U,p){Ls(p);let x=S.signature,A=p==="compact"?x:p==="recovered"?x+1:void 0;return J(U,A)}class v{r;s;recovery;constructor(p,x,A){if(this.r=C("r",p),this.s=C("s",x),A!=null){if(w(),![0,1,2,3].includes(A))throw new Error("invalid recovery id");this.recovery=A}Object.freeze(this)}static fromBytes(p,x=T.format){E(p,x);let A;if(x==="der"){if(p.length>2*c.BYTES+16)throw new wo.Err("invalid signature: DER signature too long");let{r:H,s:j}=wo.toSig(J(p),c.BYTES+1);return new v(H,j)}x==="recovered"&&(A=p[0],x="compact",p=p.subarray(1));let F=S.signature/2,M=p.subarray(0,F),K=p.subarray(F,F*2);return new v(c.fromBytes(M),c.fromBytes(K),A)}static fromHex(p,x){return this.fromBytes(hr(p),x)}assertRecovery(){let{recovery:p}=this;if(p==null)throw new Error("invalid recovery id: must be present");return p}addRecoveryBit(p){return new v(this.r,this.s,p)}recoverPublicKey(p){let{r:x,s:A}=this,F=this.assertRecovery(),M=F===2||F===3?x+f:x;if(!a.isValid(M))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let K=a.toBytes(M),H=t.fromBytes(qe(cu((F&1)===0),K)),j=c.inv(M),X=L(J(p,void 0,"msgHash")),Z=c.create(-X*j),ue=c.create(A*j),ne=t.BASE.mulAddUnsafe(Z,H,ue);if(ne.is0())throw new Error("invalid recovery: point at infinify");return ne.assertValidity(),ne}hasHighS(){return D(this.s)}toBytes(p=T.format){if(Ls(p),p==="der")return hr(wo.hexFromSig(this));let{r:x,s:A}=this,F=c.toBytes(x),M=c.toBytes(A);return p==="recovered"?(w(),qe(Uint8Array.of(this.assertRecovery()),F,M)):qe(F,M)}toHex(p){return on(this.toBytes(p))}}Object.freeze(v.prototype),Object.freeze(v);let N=o.bits2int===void 0?function(p){if(p.length>8192)throw new Error("input is too large");let x=ot(p),A=p.length*8-u;return A>0?x>>BigInt(A):x}:o.bits2int,L=o.bits2int_modN===void 0?function(p){return c.create(N(p))}:o.bits2int_modN,z=cn(u);function I(U){return pr("num < 2^"+u,U,ht,z),c.toBytes(U)}function k(U,p){return J(U,void 0,"message"),p?J(n(U),void 0,"prehashed message"):U}function O(U,p,x){let{lowS:A,prehash:F,extraEntropy:M}=Rs(x,T);U=k(U,F);let K=L(U),H=c.fromBytes(p);if(!c.isValidNot0(H))throw new Error("invalid private key");let j=[I(H),I(K)];if(M!=null&&M!==!1){let ne=M===!0?i(S.secretKey):M;j.push(J(ne,void 0,"extraEntropy"))}let X=qe(...j),Z=K;function ue(ne){let be=N(ne);if(!c.isValidNot0(be))return;let Pe=t.BASE.multiply(be).toAffine(),oe=c.create(Pe.x);if(oe===ht)return;let fe;if(h!==void 0){let Fr=ot(oo(h(l),f)),Jf=c.inv(c.mul(Fr,be)),el=c.mul(Fr,Z),tl=c.mul(Fr,H);fe=c.create(Jf*c.create(el+tl*oe))}else{let Fr=Oc(be,f);fe=c.create(Fr*c.create(Z+oe*H))}if(fe===ht)return;let li=q(Pe.x,Pe.y,oe),sa=fe;return A&&D(fe)&&(sa=c.neg(fe),li^=1),new v(oe,sa,g?void 0:li)}return{seed:X,k2sig:ue}}function P(U,p,x={}){let{seed:A,k2sig:F}=O(U,p,x);return _c(n.outputLen,c.BYTES,s)(A,F).toBytes(x.format)}function Y(U,p,x,A={}){let{lowS:F,prehash:M,format:K}=Rs(A,T);if(x=J(x,void 0,"publicKey"),p=k(p,M),!_t(U)){let H=U instanceof v?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+H)}E(U,K);try{let H=v.fromBytes(U,K),j=t.fromBytes(x);if(j.is0()||F&&H.hasHighS())return!1;let{r:X,s:Z}=H,ue=L(p),ne=c.inv(Z),be=c.create(ue*ne),Pe=c.create(X*ne),oe=t.BASE.mulAddUnsafe(be,j,Pe);if(oe.is0())return!1;let fe=oe.toAffine();return!(c.create(fe.x)!==X||K==="recovered"&&H.recovery!==q(fe.x,fe.y,X))}catch{return!1}}function W(U,p,x={}){let{prehash:A}=Rs(x,T);return p=k(p,A),v.fromBytes(U,"recovered").recoverPublicKey(p).toBytes()}return Object.freeze({keygen:m,getPublicKey:R,getSharedSecret:b,utils:y,lengths:S,Point:t,sign:P,verify:Y,recoverPublicKey:W,Signature:v,hash:n})}var ks={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},tp={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var lu=BigInt(2);function rp(t){let e=ks.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),i=BigInt(22),s=BigInt(23),a=BigInt(44),c=BigInt(88),f=t*t*t%e,u=f*f*t%e,l=ie(u,r,e)*u%e,h=ie(l,r,e)*u%e,m=ie(h,lu,e)*f%e,R=ie(m,o,e)*m%e,b=ie(R,i,e)*R%e,y=ie(b,a,e)*b%e,S=ie(y,c,e)*y%e,T=ie(S,a,e)*b%e,g=ie(T,r,e)*u%e,D=ie(g,s,e)*R%e,C=ie(D,n,e)*f%e,V=ie(C,lu,e);if(!Ns.eql(Ns.sqr(V),t))throw new Error("Cannot find square root");return V}var Ns=gr(ks.p,{sqrt:rp}),np=au(ks,{Fp:Ns,endo:tp}),wr=fu(np,Tc);function du(t,e,r,n){let o=Zr.digest(r instanceof Uint8Array?r:r.subarray());if(yo(o))return o.then(({digest:i})=>(n?.signal?.throwIfAborted(),wr.verify(e,i,t,{prehash:!1,format:"der"}))).catch(i=>{throw i.name==="AbortError"?i:new ln(String(i))});try{return n?.signal?.throwIfAborted(),wr.verify(e,o.digest,t,{prehash:!1,format:"der"})}catch(i){throw new ln(String(i))}}var xo=class{type="secp256k1";raw;_key;constructor(e){this._key=pu(e),this.raw=hu(this._key)}toMultihash(){return Ge.digest(lr(this))}toCID(){return se.createV1(114,this.toMultihash())}toString(){return re.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:de(this.raw,e.raw)}verify(e,r,n){return du(this._key,r,e,n)}};function mu(t){return new xo(t)}function hu(t){return wr.Point.fromBytes(t).toBytes()}function pu(t){try{return wr.Point.fromBytes(t),t}catch(e){throw new On(String(e))}}function yu(t){let{Type:e,Data:r}=dn.decode(t.digest),n=r??new Uint8Array;switch(e){case ve.Ed25519:return nu(n);case ve.secp256k1:return mu(n);case ve.ECDSA:return oc(n);default:throw new Wr}}function lr(t){return dn.encode({Type:ve[t.type],Data:t.raw})}var gu=Symbol.for("nodejs.util.inspect.custom"),op=114,hn=class{type;multihash;publicKey;string;constructor(e){this.type=e.type,this.multihash=e.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[ji]=!0;toString(){return this.string==null&&(this.string=re.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return se.createV1(op,this.multihash)}toJSON(){return this.toString()}equals(e){if(e==null)return!1;if(e instanceof Uint8Array)return de(this.multihash.bytes,e);if(typeof e=="string")return this.toString()===e;if(e?.toMultihash()?.bytes!=null)return de(this.multihash.bytes,e.toMultihash().bytes);throw new Error("not valid Id")}[gu](){return`PeerId(${this.toString()})`}},Eo=class extends hn{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},So=class extends hn{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.publicKey}},vo=class extends hn{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.publicKey}},ip=2336,Ao=class{type="url";multihash;publicKey;url;constructor(e){this.url=e.toString(),this.multihash=Ge.digest(le(this.url))}[gu](){return`PeerId(${this.url})`}[ji]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return se.createV1(ip,this.toMultihash())}toJSON(){return this.toString()}equals(e){return e==null?!1:(e instanceof Uint8Array&&(e=te(e)),e.toString()===this.toString())}};function bu(t){if(ap(t))return new Eo({multihash:t});if(sp(t))try{let e=yu(t);if(e.type==="Ed25519")return new So({multihash:t,publicKey:e});if(e.type==="secp256k1")return new vo({multihash:t,publicKey:e})}catch{let r=te(t.digest);return new Ao(new URL(r))}throw new Pn("Supplied PeerID Multihash is invalid")}function sp(t){return t.code===Ge.code}function ap(t){return t.code===Zr.code}function Us(t,e){let r={[Symbol.iterator]:()=>r,next:()=>{let n=t.next(),o=n.value;return n.done===!0||o==null?{done:!0,value:void 0}:{done:!1,value:e(o)}}};return r}function To(t){let e=wt(re.decode(`z${t}`));return bu(e)}var pn=class t{set;constructor(e){if(this.set=new Set,e!=null)for(let r of e)this.set.add(r.toString())}get size(){return this.set.size}[Symbol.iterator](){return this.values()}add(e){this.set.add(e.toString())}clear(){this.set.clear()}delete(e){this.set.delete(e.toString())}entries(){return Us(this.set.entries(),e=>{let r=To(e[0]);return[r,r]})}forEach(e){this.set.forEach(r=>{let n=To(r);e(n,n,this)})}has(e){return this.set.has(e.toString())}values(){return Us(this.set.values(),e=>To(e))}intersection(e){let r=new t;for(let n of e)this.has(n)&&r.add(n);return r}difference(e){let r=new t;for(let n of this)e.has(n)||r.add(n);return r}union(e){let r=new t;for(let n of e)r.add(n);for(let n of this)r.add(n);return r}};function xr(){let t={};return t.promise=new Promise((e,r)=>{t.resolve=e,t.reject=r}),t}var Io=class{buffer;mask;top;btm;next;constructor(e){if(!(e>0)||(e-1&e)!==0)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(e),this.mask=e-1,this.top=0,this.btm=0,this.next=null}push(e){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=e,this.top=this.top+1&this.mask,!0)}shift(){let e=this.buffer[this.btm];if(e!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,e}isEmpty(){return this.buffer[this.btm]===void 0}},Er=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new Io(this.hwm),this.tail=this.head,this.size=0}calculateSize(e){return e?.byteLength!=null?e.byteLength:1}push(e){if(e?.value!=null&&(this.size+=this.calculateSize(e.value)),!this.head.push(e)){let r=this.head;this.head=r.next=new Io(2*this.head.buffer.length),this.head.push(e)}}shift(){let e=this.tail.shift();if(e===void 0&&this.tail.next!=null){let r=this.tail.next;this.tail.next=null,this.tail=r,e=this.tail.shift()}return e?.value!=null&&(this.size-=this.calculateSize(e.value)),e}isEmpty(){return this.head.isEmpty()}};var Fs=class extends Error{type;code;constructor(e,r){super(e??"The operation was aborted"),this.type="aborted",this.code=r??"ABORT_ERR"}};function wu(t={}){return cp(r=>{let n=r.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},t)}function cp(t,e){e=e??{};let r=e.onEnd,n=new Er,o,i,s,a=xr(),c=async()=>{try{return n.isEmpty()?s?{done:!0}:await new Promise((y,S)=>{i=T=>{i=null,n.push(T);try{y(t(n))}catch(g){S(g)}return o}}):t(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=xr()})}},f=y=>i!=null?i(y):(n.push(y),o),u=y=>(n=new Er,i!=null?i({error:y}):(n.push({error:y}),o)),l=y=>{if(s)return o;if(e?.objectMode!==!0&&y?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return f({done:!1,value:y})},h=y=>s?o:(s=!0,y!=null?u(y):f({done:!0})),m=()=>(n=new Er,h(),{done:!0}),R=y=>(h(y),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:m,throw:R,push:l,end:h,get readableLength(){return n.size},onEmpty:async y=>{let S=y?.signal;if(S?.throwIfAborted(),n.isEmpty())return;let T,g;S!=null&&(T=new Promise((D,C)=>{g=()=>{C(new Fs)},S.addEventListener("abort",g)}));try{await Promise.race([a.promise,T])}finally{g!=null&&S!=null&&S?.removeEventListener("abort",g)}}},r==null)return o;let b=o;return o={[Symbol.asyncIterator](){return this},next(){return b.next()},throw(y){return b.throw(y),r!=null&&(r(y),r=void 0),{done:!0}},return(){return b.return(),r!=null&&(r(),r=void 0),{done:!0}},push:l,end(y){return b.end(y),r!=null&&(r(y),r=void 0),o},get readableLength(){return b.readableLength},onEmpty:y=>b.onEmpty(y)},o}var Os=class t extends Error{name="TimeoutError";constructor(e,r){super(e,r),Error.captureStackTrace?.(this,t)}},xu=t=>t.reason??new DOMException("This operation was aborted.","AbortError");function Ps(t,e){let{milliseconds:r,fallback:n,message:o,customTimers:i={setTimeout,clearTimeout},signal:s}=e,a,c,u=new Promise((l,h)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(s?.aborted){h(xu(s)),t.then(l,h);return}if(s&&(c=()=>{h(xu(s))},s.addEventListener("abort",c,{once:!0})),t.then(l,h),r===Number.POSITIVE_INFINITY)return;let m=new Os;a=i.setTimeout.call(void 0,()=>{if(n){try{l(n())}catch(R){h(R)}return}typeof t.cancel=="function"&&t.cancel(),o===!1?l():o instanceof Error?h(o):(m.message=o??`Promise timed out after ${r} milliseconds`,h(m))},r)}).finally(()=>{u.clear(),c&&s&&s.removeEventListener("abort",c)});return u.clear=()=>{i.clearTimeout.call(void 0,a),a=void 0},u}var up=t=>{let e=t.addEventListener||t.on||t.addListener,r=t.removeEventListener||t.off||t.removeListener;if(!e||!r)throw new TypeError("Emitter is not compatible");return{addListener:e.bind(t),removeListener:r.bind(t)}};function fp(t,e,r){let n,o=new Promise((i,s)=>{if(r={rejectionEvents:["error"],multiArgs:!1,rejectionMultiArgs:!1,resolveImmediately:!1,...r},!(r.count>=0&&(r.count===Number.POSITIVE_INFINITY||Number.isInteger(r.count))))throw new TypeError("The `count` option should be at least 0 or more");r.signal?.throwIfAborted();let a=[e].flat(),c=[],{addListener:f,removeListener:u}=up(t),l=async(...m)=>{let R=r.multiArgs?m:m[0];if(r.filter)try{if(!await r.filter(R))return}catch(b){n(),s(b);return}c.push(R),r.count===c.length&&(n(),i(c))},h=(...m)=>{n(),s(r.rejectionMultiArgs?m:m[0])};n=()=>{for(let m of a)u(m,l);for(let m of r.rejectionEvents)a.includes(m)||u(m,h)};for(let m of a)f(m,l);for(let m of r.rejectionEvents)a.includes(m)||f(m,h);r.signal&&r.signal.addEventListener("abort",()=>{h(r.signal.reason)},{once:!0}),r.resolveImmediately&&i(c)});if(o.cancel=n,typeof r.timeout=="number"){let i=Ps(o,{milliseconds:r.timeout});return i.cancel=()=>{n(),i.clear()},i}return o}function Bo(t,e,r){typeof r=="function"&&(r={filter:r}),r={...r,count:1,resolveImmediately:!1};let n=fp(t,e,r),o=n.then(i=>i[0]);return o.cancel=n.cancel,o}function mn(t,e){let r,n=function(){let o=function(){r=void 0,t()};clearTimeout(r),r=setTimeout(o,e)};return n.start=()=>{},n.stop=()=>{clearTimeout(r)},n}var Co=class extends Error{static name="QueueFullError";constructor(e="The queue was full"){super(e),this.name="QueueFullError"}};function lp(t){return t.reason}function _o(t,e,r){if(e==null||t==null)return t;let n=r?.translateError??lp;if(e.aborted)return t.catch(()=>{}),Promise.reject(n(e));let o;return Promise.race([t,new Promise((i,s)=>{o=()=>{s(n(e))},e.addEventListener("abort",o)})]).finally(()=>{o!=null&&e.removeEventListener("abort",o)})}var Ro=class{deferred;signal;onProgress;constructor(e){this.signal=e?.signal,this.onProgress=e?.onProgress,this.deferred=xr(),this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(this.signal?.reason??new rt)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function dp(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var Eu=new WeakMap,Do=class{id;fn;options;recipients;status;timeline;controller;dispatchingProgress;constructor(e,r){this.id=dp(),this.status="queued",this.fn=e,this.options=r,this.recipients=[],this.timeline={created:Date.now()},this.controller=new AbortController,this.controller.signal,this.dispatchingProgress=!1,this.onAbort=this.onAbort.bind(this)}abort(e){this.controller.abort(e)}onAbort(){this.recipients.reduce((r,n)=>r&&n.signal?.aborted===!0,!0)&&(this.controller.abort(new rt),this.cleanup())}async join(e){let r=new Ro(e);return this.recipients.push(r),e?.signal?.addEventListener("abort",this.onAbort),r.deferred.promise}async run(){this.status="running",this.timeline.started=Date.now();try{this.controller.signal.throwIfAborted();let e=await _o(this.fn({...this.options??{},signal:this.controller.signal,onProgress:r=>{if(this.recipients.length!==0&&!this.dispatchingProgress){if(typeof r=="object"&&r!==null){let n=Eu.get(r);if(n==null&&(n=new WeakSet,Eu.set(r,n)),n.has(this))return;n.add(this)}this.dispatchingProgress=!0;try{this.recipients.forEach(n=>{n.onProgress?.(r)})}finally{this.dispatchingProgress=!1}}}}),this.controller.signal);this.recipients.forEach(r=>{r.deferred.resolve(e)}),this.status="complete"}catch(e){this.recipients.forEach(r=>{r.deferred.reject(e)}),this.status="errored"}finally{this.timeline.finished=Date.now(),this.cleanup()}}cleanup(){this.recipients.forEach(e=>{e.deferred.reject(e.signal?.reason??new rt),e.cleanup(),e.signal?.removeEventListener("abort",this.onAbort)}),this.recipients.splice(0,this.recipients.length)}};var Sr=class extends Mn{concurrency;maxSize;queue;pending;sort;paused;constructor(e={}){super(),this.concurrency=e.concurrency??Number.POSITIVE_INFINITY,this.maxSize=e.maxSize??Number.POSITIVE_INFINITY,this.pending=0,this.paused=!1,e.metricName!=null&&e.metrics?.registerMetricGroup(e.metricName,{calculate:()=>({size:this.queue.length,running:this.pending,queued:this.queue.length-this.pending})}),this.sort=e.sort,this.queue=[],this.emitEmpty=mn(this.emitEmpty.bind(this),1),this.emitIdle=mn(this.emitIdle.bind(this),1)}emitEmpty(){this.size===0&&this.safeDispatchEvent("empty")}emitIdle(){this.running===0&&this.safeDispatchEvent("idle")}pause(){this.paused=!0}resume(){this.paused&&(this.paused=!1,this.tryToStartAnother())}tryToStartAnother(){if(this.paused)return!1;if(this.size===0)return this.emitEmpty(),this.running===0&&this.emitIdle(),!1;if(this.pending<this.concurrency){let e;for(let r of this.queue)if(r.status==="queued"){e=r;break}return e==null?!1:(this.safeDispatchEvent("active"),this.pending++,e.run().finally(()=>{for(let r=0;r<this.queue.length;r++)if(this.queue[r]===e){this.queue.splice(r,1);break}this.pending--,this.tryToStartAnother(),this.safeDispatchEvent("next")}),!0)}return!1}enqueue(e){this.queue.push(e),this.sort!=null&&this.queue.sort(this.sort)}async add(e,r){if(r?.signal?.throwIfAborted(),this.size===this.maxSize)throw new Co;let n=new Do(e,r);this.enqueue(n),this.safeDispatchEvent("add");let o=n.join(r).then(i=>(this.safeDispatchEvent("completed",{detail:i}),this.safeDispatchEvent("success",{detail:{job:n,result:i}}),i)).catch(i=>{if(n.status==="queued"){for(let s=0;s<this.queue.length;s++)if(this.queue[s]===n){this.queue.splice(s,1);break}}throw this.safeDispatchEvent("failure",{detail:{job:n,error:i}}),i});return this.tryToStartAnother(),o}clear(){this.queue.splice(0,this.queue.length)}abort(){this.queue.forEach(e=>{e.abort(new rt)}),this.clear()}async onEmpty(e){this.size!==0&&await Bo(this,"empty",e)}async onSizeLessThan(e,r){this.size<e||await Bo(this,"next",{...r,filter:()=>this.size<e})}async onIdle(e){this.pending===0&&this.size===0||await Bo(this,"idle",e)}get size(){return this.queue.length}get queued(){return this.queue.length-this.pending}get running(){return this.pending}async*toGenerator(e){e?.signal?.throwIfAborted();let r=wu({objectMode:!0}),n=c=>{c!=null?this.abort():this.clear(),r.end(c)},o=c=>{c.detail!=null&&r.push(c.detail)},i=c=>{n(c.detail.error)},s=()=>{n()},a=()=>{n(new rt("Queue aborted"))};this.addEventListener("completed",o),this.addEventListener("failure",i),this.addEventListener("idle",s),e?.signal?.addEventListener("abort",a);try{yield*r}finally{this.removeEventListener("completed",o),this.removeEventListener("failure",i),this.removeEventListener("idle",s),e?.signal?.removeEventListener("abort",a),n()}}};function yn(t){let e=new globalThis.AbortController;function r(){let i=t.filter(s=>s?.aborted===!0).map(s=>s?.reason).pop();e.abort(i);for(let s of t)s?.removeEventListener!=null&&s.removeEventListener("abort",r)}for(let i of t){if(i?.aborted===!0){r();break}i?.addEventListener!=null&&i.addEventListener("abort",r)}function n(){for(let i of t)i?.removeEventListener!=null&&i.removeEventListener("abort",r)}let o=e.signal;return o.clear=n,o}var hp=["Object","RegExp","Date","Error","Map","Set","WeakMap","WeakSet","ArrayBuffer","SharedArrayBuffer","DataView","Promise","URL","HTMLElement","Int8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array","Tagged"];function Ms(t){if(t===null)return"null";if(t===void 0)return"undefined";if(t===!0||t===!1)return"boolean";let e=typeof t;if(e==="string"||e==="number"||e==="bigint"||e==="symbol")return e;if(e==="function")return"Function";if(Array.isArray(t))return"Array";if(t instanceof Uint8Array)return"Uint8Array";if(t.constructor===Object)return"Object";let r=pp(t);return r||"Object"}function pp(t){let e=Object.prototype.toString.call(t).slice(8,-1);if(hp.includes(e))return e}var d=class{constructor(e,r,n){this.major=e,this.majorEncoded=e<<5,this.name=r,this.terminal=n}toString(){return`Type[${this.major}].${this.name}`}compare(e){return this.major<e.major?-1:this.major>e.major?1:0}static equals(e,r){return e===r||e.major===r.major&&e.name===r.name}};d.uint=new d(0,"uint",!0);d.negint=new d(1,"negint",!0);d.bytes=new d(2,"bytes",!0);d.string=new d(3,"string",!0);d.array=new d(4,"array",!1);d.map=new d(5,"map",!1);d.tag=new d(6,"tag",!1);d.float=new d(7,"float",!0);d.false=new d(7,"false",!0);d.true=new d(7,"true",!0);d.null=new d(7,"null",!0);d.undefined=new d(7,"undefined",!0);d.break=new d(7,"break",!0);var _=class{constructor(e,r,n){this.type=e,this.value=r,this.encodedLength=n,this.encodedBytes=void 0,this.byteValue=void 0}toString(){return`Token[${this.type}].${this.value}`}};var gn=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",mp=new TextEncoder;function Lo(t){return gn&&globalThis.Buffer.isBuffer(t)}function bn(t){return t instanceof Uint8Array?Lo(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):t:Uint8Array.from(t)}var yp=24,gp=200,No=gn?t=>t.length>=yp?globalThis.Buffer.from(t):Su(t):t=>t.length>=gp?mp.encode(t):Su(t),it=t=>Uint8Array.from(t),vu=gn?(t,e,r)=>Lo(t)?new Uint8Array(t.subarray(e,r)):t.slice(e,r):(t,e,r)=>t.slice(e,r),Au=gn?(t,e)=>(t=t.map(r=>r instanceof Uint8Array?r:globalThis.Buffer.from(r)),bn(globalThis.Buffer.concat(t,e))):(t,e)=>{let r=new Uint8Array(e),n=0;for(let o of t)n+o.length>r.length&&(o=o.subarray(0,r.length-n)),r.set(o,n),n+=o.length;return r},Ks=gn?t=>globalThis.Buffer.allocUnsafe(t):t=>new Uint8Array(t);function vr(t,e){if(Lo(t)&&Lo(e))return t.compare(e);for(let r=0;r<t.length;r++)if(t[r]!==e[r])return t[r]<e[r]?-1:1;return 0}function Su(t){let e=[],r=0;for(let n=0;n<t.length;n++){let o=t.charCodeAt(n);o<128?e[r++]=o:o<2048?(e[r++]=o>>6|192,e[r++]=o&63|128):(o&64512)===55296&&n+1<t.length&&(t.charCodeAt(n+1)&64512)===56320?(o=65536+((o&1023)<<10)+(t.charCodeAt(++n)&1023),e[r++]=o>>18|240,e[r++]=o>>12&63|128,e[r++]=o>>6&63|128,e[r++]=o&63|128):(o>=55296&&o<=57343&&(o=65533),e[r++]=o>>12|224,e[r++]=o>>6&63|128,e[r++]=o&63|128)}return e}var bp=256,wn=class{constructor(e=bp){this.chunkSize=e,this.cursor=0,this.maxCursor=-1,this.chunks=[],this._initReuseChunk=null}reset(){this.cursor=0,this.maxCursor=-1,this.chunks.length&&(this.chunks=[]),this._initReuseChunk!==null&&(this.chunks.push(this._initReuseChunk),this.maxCursor=this._initReuseChunk.length-1)}pushByte(e){let r=this.chunks[this.chunks.length-1];this.cursor>this.maxCursor&&(r=Ks(this.chunkSize),this.chunks.push(r),this.maxCursor+=r.length,this._initReuseChunk===null&&(this._initReuseChunk=r));let n=r.length-(this.maxCursor-this.cursor)-1;r[n]=e,this.cursor++}push(e){let r=this.chunks[this.chunks.length-1];if(this.cursor+e.length<=this.maxCursor+1){let o=r.length-(this.maxCursor-this.cursor)-1;r.set(e,o)}else{if(r){let o=r.length-(this.maxCursor-this.cursor)-1;o<r.length&&(this.chunks[this.chunks.length-1]=r.subarray(0,o),this.maxCursor=this.cursor-1)}e.length<64&&e.length<this.chunkSize?(r=Ks(this.chunkSize),this.chunks.push(r),this.maxCursor+=r.length,this._initReuseChunk===null&&(this._initReuseChunk=r),r.set(e,0)):(this.chunks.push(e),this.maxCursor+=e.length)}this.cursor+=e.length}toBytes(e=!1){let r;if(this.chunks.length===1){let n=this.chunks[0];e&&this.cursor>n.length/2?(r=this.cursor===n.length?n:n.subarray(0,this.cursor),this._initReuseChunk=null,this.chunks=[]):r=vu(n,0,this.cursor)}else r=Au(this.chunks,this.cursor);return e&&this.reset(),r}},ko=class{constructor(e){this.dest=e,this.cursor=0,this.chunks=[e]}reset(){this.cursor=0}pushByte(e){if(this.cursor>=this.dest.length)throw new Error("write out of bounds, destination buffer is too small");this.dest[this.cursor++]=e}push(e){if(this.cursor+e.length>this.dest.length)throw new Error("write out of bounds, destination buffer is too small");this.dest.set(e,this.cursor),this.cursor+=e.length}toBytes(e=!1){let r=this.dest.subarray(0,this.cursor);return e&&this.reset(),r}};var $="CBOR decode error:",Uo="CBOR encode error:",xn=[];xn[23]=1;xn[24]=2;xn[25]=3;xn[26]=5;xn[27]=9;function pt(t,e,r){if(t.length-e<r)throw new Error(`${$} not enough data for type`)}var we=[24,256,65536,4294967296,BigInt("18446744073709551616")];function Ne(t,e,r){pt(t,e,1);let n=t[e];if(r.strict===!0&&n<we[0])throw new Error(`${$} integer encoded in more bytes than necessary (strict decode)`);return n}function ke(t,e,r){pt(t,e,2);let n=t[e]<<8|t[e+1];if(r.strict===!0&&n<we[1])throw new Error(`${$} integer encoded in more bytes than necessary (strict decode)`);return n}function Ue(t,e,r){pt(t,e,4);let n=t[e]*16777216+(t[e+1]<<16)+(t[e+2]<<8)+t[e+3];if(r.strict===!0&&n<we[2])throw new Error(`${$} integer encoded in more bytes than necessary (strict decode)`);return n}function Fe(t,e,r){pt(t,e,8);let n=t[e]*16777216+(t[e+1]<<16)+(t[e+2]<<8)+t[e+3],o=t[e+4]*16777216+(t[e+5]<<16)+(t[e+6]<<8)+t[e+7],i=(BigInt(n)<<BigInt(32))+BigInt(o);if(r.strict===!0&&i<we[3])throw new Error(`${$} integer encoded in more bytes than necessary (strict decode)`);if(i<=Number.MAX_SAFE_INTEGER)return Number(i);if(r.allowBigInt===!0)return i;throw new Error(`${$} integers outside of the safe integer range are not supported`)}function Tu(t,e,r,n){return new _(d.uint,Ne(t,e+1,n),2)}function Iu(t,e,r,n){return new _(d.uint,ke(t,e+1,n),3)}function Bu(t,e,r,n){return new _(d.uint,Ue(t,e+1,n),5)}function Cu(t,e,r,n){return new _(d.uint,Fe(t,e+1,n),9)}function st(t,e){return ye(t,0,e.value)}function ye(t,e,r){if(r<we[0]){let n=Number(r);t.pushByte(e|n)}else if(r<we[1]){let n=Number(r);t.push([e|24,n])}else if(r<we[2]){let n=Number(r);t.push([e|25,n>>>8,n&255])}else if(r<we[3]){let n=Number(r);t.push([e|26,n>>>24&255,n>>>16&255,n>>>8&255,n&255])}else{let n=BigInt(r);if(n<we[4]){let o=[e|27,0,0,0,0,0,0,0],i=Number(n&BigInt(4294967295)),s=Number(n>>BigInt(32)&BigInt(4294967295));o[8]=i&255,i=i>>8,o[7]=i&255,i=i>>8,o[6]=i&255,i=i>>8,o[5]=i&255,o[4]=s&255,s=s>>8,o[3]=s&255,s=s>>8,o[2]=s&255,s=s>>8,o[1]=s&255,t.push(o)}else throw new Error(`${$} encountered BigInt larger than allowable range`)}}st.encodedSize=function(e){return ye.encodedSize(e.value)};ye.encodedSize=function(e){return e<we[0]?1:e<we[1]?2:e<we[2]?3:e<we[3]?5:9};st.compareTokens=function(e,r){return e.value<r.value?-1:e.value>r.value?1:0};function _u(t,e,r,n){return new _(d.negint,-1-Ne(t,e+1,n),2)}function Ru(t,e,r,n){return new _(d.negint,-1-ke(t,e+1,n),3)}function Du(t,e,r,n){return new _(d.negint,-1-Ue(t,e+1,n),5)}var $s=BigInt(-1),Lu=BigInt(1);function Nu(t,e,r,n){let o=Fe(t,e+1,n);if(typeof o!="bigint"){let i=-1-o;if(i>=Number.MIN_SAFE_INTEGER)return new _(d.negint,i,9)}if(n.allowBigInt!==!0)throw new Error(`${$} integers outside of the safe integer range are not supported`);return new _(d.negint,$s-BigInt(o),9)}function Fo(t,e){let r=e.value,n=typeof r=="bigint"?r*$s-Lu:r*-1-1;ye(t,e.type.majorEncoded,n)}Fo.encodedSize=function(e){let r=e.value,n=typeof r=="bigint"?r*$s-Lu:r*-1-1;return n<we[0]?1:n<we[1]?2:n<we[2]?3:n<we[3]?5:9};Fo.compareTokens=function(e,r){return e.value<r.value?1:e.value>r.value?-1:0};function En(t,e,r,n){pt(t,e,r+n);let o=t.slice(e+r,e+r+n);return new _(d.bytes,o,r+n)}function ku(t,e,r,n){return En(t,e,1,r)}function Uu(t,e,r,n){return En(t,e,2,Ne(t,e+1,n))}function Fu(t,e,r,n){return En(t,e,3,ke(t,e+1,n))}function Ou(t,e,r,n){return En(t,e,5,Ue(t,e+1,n))}function Pu(t,e,r,n){let o=Fe(t,e+1,n);if(typeof o=="bigint")throw new Error(`${$} 64-bit integer bytes lengths not supported`);return En(t,e,9,o)}function Oo(t){return t.encodedBytes===void 0&&(t.encodedBytes=d.equals(t.type,d.string)?No(t.value):t.value),t.encodedBytes}function Ar(t,e){let r=Oo(e);ye(t,e.type.majorEncoded,r.length),t.push(r)}Ar.encodedSize=function(e){let r=Oo(e);return ye.encodedSize(r.length)+r.length};Ar.compareTokens=function(e,r){return xp(Oo(e),Oo(r))};function xp(t,e){return t.length<e.length?-1:t.length>e.length?1:vr(t,e)}var Mu=new TextDecoder,Sp=32;function vp(t,e,r){if(r-e<Sp){let o="";for(let i=e;i<r;i++){let s=t[i];if(s&128)return Mu.decode(t.subarray(e,r));o+=String.fromCharCode(s)}return o}return Mu.decode(t.subarray(e,r))}function Sn(t,e,r,n,o){let i=r+n;pt(t,e,i);let s=new _(d.string,vp(t,e+r,e+i),i);return o.retainStringBytes===!0&&(s.byteValue=t.slice(e+r,e+i)),s}function Ku(t,e,r,n){return Sn(t,e,1,r,n)}function $u(t,e,r,n){return Sn(t,e,2,Ne(t,e+1,n),n)}function Vu(t,e,r,n){return Sn(t,e,3,ke(t,e+1,n),n)}function qu(t,e,r,n){return Sn(t,e,5,Ue(t,e+1,n),n)}function zu(t,e,r,n){let o=Fe(t,e+1,n);if(typeof o=="bigint")throw new Error(`${$} 64-bit integer string lengths not supported`);return Sn(t,e,9,o,n)}var Hu=Ar;function Tr(t,e,r,n){return new _(d.array,n,r)}function ju(t,e,r,n){return Tr(t,e,1,r)}function Yu(t,e,r,n){return Tr(t,e,2,Ne(t,e+1,n))}function Zu(t,e,r,n){return Tr(t,e,3,ke(t,e+1,n))}function Gu(t,e,r,n){return Tr(t,e,5,Ue(t,e+1,n))}function Xu(t,e,r,n){let o=Fe(t,e+1,n);if(typeof o=="bigint")throw new Error(`${$} 64-bit integer array lengths not supported`);return Tr(t,e,9,o)}function Wu(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${$} indefinite length items not allowed`);return Tr(t,e,1,1/0)}function Po(t,e){ye(t,d.array.majorEncoded,e.value)}Po.compareTokens=st.compareTokens;Po.encodedSize=function(e){return ye.encodedSize(e.value)};function Ir(t,e,r,n){return new _(d.map,n,r)}function Qu(t,e,r,n){return Ir(t,e,1,r)}function Ju(t,e,r,n){return Ir(t,e,2,Ne(t,e+1,n))}function ef(t,e,r,n){return Ir(t,e,3,ke(t,e+1,n))}function tf(t,e,r,n){return Ir(t,e,5,Ue(t,e+1,n))}function rf(t,e,r,n){let o=Fe(t,e+1,n);if(typeof o=="bigint")throw new Error(`${$} 64-bit integer map lengths not supported`);return Ir(t,e,9,o)}function nf(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${$} indefinite length items not allowed`);return Ir(t,e,1,1/0)}function Mo(t,e){ye(t,d.map.majorEncoded,e.value)}Mo.compareTokens=st.compareTokens;Mo.encodedSize=function(e){return ye.encodedSize(e.value)};function of(t,e,r,n){return new _(d.tag,r,1)}function sf(t,e,r,n){return new _(d.tag,Ne(t,e+1,n),2)}function af(t,e,r,n){return new _(d.tag,ke(t,e+1,n),3)}function cf(t,e,r,n){return new _(d.tag,Ue(t,e+1,n),5)}function uf(t,e,r,n){return new _(d.tag,Fe(t,e+1,n),9)}function Ko(t,e){ye(t,d.tag.majorEncoded,e.value)}Ko.compareTokens=st.compareTokens;Ko.encodedSize=function(e){return ye.encodedSize(e.value)};var $o=20,Vo=21,qo=22,zo=23;function lf(t,e,r,n){if(n.allowUndefined===!1)throw new Error(`${$} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new _(d.null,null,1):new _(d.undefined,void 0,1)}function df(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${$} indefinite length items not allowed`);return new _(d.break,void 0,1)}function Vs(t,e,r){if(r){if(r.allowNaN===!1&&Number.isNaN(t))throw new Error(`${$} NaN values are not supported`);if(r.allowInfinity===!1&&(t===1/0||t===-1/0))throw new Error(`${$} Infinity values are not supported`)}return new _(d.float,t,e)}function hf(t,e,r,n){return Vs(Ho(t,e+1),3,n)}function pf(t,e,r,n){return Vs(jo(t,e+1),5,n)}function mf(t,e,r,n){return Vs(bf(t,e+1),9,n)}function vn(t,e,r){let n=e.value;if(n===!1)t.pushByte(d.float.majorEncoded|$o);else if(n===!0)t.pushByte(d.float.majorEncoded|Vo);else if(n===null)t.pushByte(d.float.majorEncoded|qo);else if(n===void 0)t.pushByte(d.float.majorEncoded|zo);else{let o,i=!1;(!r||r.float64!==!0)&&(qs(n),o=Ho(ge,1),n===o||Number.isNaN(n)?(ge[0]=249,t.push(ge.slice(0,3)),i=!0):(zs(n),o=jo(ge,1),n===o&&(ge[0]=250,t.push(ge.slice(0,5)),i=!0))),i||(gf(n),o=bf(ge,1),ge[0]=251,t.push(ge.slice(0,9)))}}vn.encodedSize=function(e,r){let n=e.value;if(n===!1||n===!0||n===null||n===void 0)return 1;if(!r||r.float64!==!0){qs(n);let o=Ho(ge,1);if(n===o||Number.isNaN(n))return 3;if(zs(n),o=jo(ge,1),n===o)return 5}return 9};var yf=new ArrayBuffer(9),ze=new DataView(yf,1),ge=new Uint8Array(yf,0);function qs(t){if(t===1/0)ze.setUint16(0,31744,!1);else if(t===-1/0)ze.setUint16(0,64512,!1);else if(Number.isNaN(t))ze.setUint16(0,32256,!1);else{ze.setFloat32(0,t);let e=ze.getUint32(0),r=(e&2139095040)>>23,n=e&8388607;if(r===255)ze.setUint16(0,31744,!1);else if(r===0)ze.setUint16(0,(e&2147483648)>>16|n>>13,!1);else{let o=r-127;o<-24?ze.setUint16(0,0):o<-14?ze.setUint16(0,(e&2147483648)>>16|1<<24+o,!1):ze.setUint16(0,(e&2147483648)>>16|o+15<<10|n>>13,!1)}}}function Ho(t,e){if(t.length-e<2)throw new Error(`${$} not enough data for float16`);let r=(t[e]<<8)+t[e+1];if(r===31744)return 1/0;if(r===64512)return-1/0;if(r===32256)return NaN;let n=r>>10&31,o=r&1023,i;return n===0?i=o*2**-24:n!==31?i=(o+1024)*2**(n-25):i=o===0?1/0:NaN,r&32768?-i:i}function zs(t){ze.setFloat32(0,t,!1)}function jo(t,e){if(t.length-e<4)throw new Error(`${$} not enough data for float32`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,4).getFloat32(0,!1)}function gf(t){ze.setFloat64(0,t,!1)}function bf(t,e){if(t.length-e<8)throw new Error(`${$} not enough data for float64`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,8).getFloat64(0,!1)}function Cp(t,e){let r=t.value;if(r===!1)return Uint8Array.of(d.float.majorEncoded|$o);if(r===!0)return Uint8Array.of(d.float.majorEncoded|Vo);if(r===null)return Uint8Array.of(d.float.majorEncoded|qo);if(r===void 0)return Uint8Array.of(d.float.majorEncoded|zo);if(!e){if(qs(r),r===Ho(ge,1)||Number.isNaN(r))return ge[0]=249,ge.slice(0,3);if(zs(r),r===jo(ge,1))return ge[0]=250,ge.slice(0,5)}return gf(r),ge[0]=251,ge.slice(0,9)}function ff(t,e){let r=t,n=e?.float64===!0,o=n?r._keyBytesFloat64:r._keyBytes;if(o!==void 0)return o;let i=Cp(t,n);return n?r._keyBytesFloat64=i:r._keyBytes=i,i}vn.compareTokens=function(e,r,n){let o=ff(e,n),i=ff(r,n);return o.length!==i.length?o.length<i.length?-1:1:vr(o,i)};function G(t,e,r){throw new Error(`${$} encountered invalid minor (${r}) for major ${t[e]>>>5}`)}function Yo(t){return()=>{throw new Error(`${$} ${t}`)}}var B=[];for(let t=0;t<=23;t++)B[t]=G;B[24]=Tu;B[25]=Iu;B[26]=Bu;B[27]=Cu;B[28]=G;B[29]=G;B[30]=G;B[31]=G;for(let t=32;t<=55;t++)B[t]=G;B[56]=_u;B[57]=Ru;B[58]=Du;B[59]=Nu;B[60]=G;B[61]=G;B[62]=G;B[63]=G;for(let t=64;t<=87;t++)B[t]=ku;B[88]=Uu;B[89]=Fu;B[90]=Ou;B[91]=Pu;B[92]=G;B[93]=G;B[94]=G;B[95]=Yo("indefinite length bytes/strings are not supported");for(let t=96;t<=119;t++)B[t]=Ku;B[120]=$u;B[121]=Vu;B[122]=qu;B[123]=zu;B[124]=G;B[125]=G;B[126]=G;B[127]=Yo("indefinite length bytes/strings are not supported");for(let t=128;t<=151;t++)B[t]=ju;B[152]=Yu;B[153]=Zu;B[154]=Gu;B[155]=Xu;B[156]=G;B[157]=G;B[158]=G;B[159]=Wu;for(let t=160;t<=183;t++)B[t]=Qu;B[184]=Ju;B[185]=ef;B[186]=tf;B[187]=rf;B[188]=G;B[189]=G;B[190]=G;B[191]=nf;for(let t=192;t<=215;t++)B[t]=of;B[216]=sf;B[217]=af;B[218]=cf;B[219]=uf;B[220]=G;B[221]=G;B[222]=G;B[223]=G;for(let t=224;t<=243;t++)B[t]=Yo("simple values are not supported");B[244]=G;B[245]=G;B[246]=G;B[247]=lf;B[248]=Yo("simple values are not supported");B[249]=hf;B[250]=pf;B[251]=mf;B[252]=G;B[253]=G;B[254]=G;B[255]=df;var We=[];for(let t=0;t<24;t++)We[t]=new _(d.uint,t,1);for(let t=-1;t>=-24;t--)We[31-t]=new _(d.negint,t,1);We[64]=new _(d.bytes,new Uint8Array(0),1);We[96]=new _(d.string,"",1);We[128]=new _(d.array,0,1);We[160]=new _(d.map,0,1);We[244]=new _(d.false,!1,1);We[245]=new _(d.true,!0,1);We[246]=new _(d.null,null,1);function Hs(t){switch(t.type){case d.false:return it([244]);case d.true:return it([245]);case d.null:return it([246]);case d.bytes:return t.value.length?void 0:it([64]);case d.string:return t.value===""?it([96]):void 0;case d.array:return t.value===0?it([128]):void 0;case d.map:return t.value===0?it([160]):void 0;case d.uint:return t.value<24?it([Number(t.value)]):void 0;case d.negint:if(t.value>=-24)return it([31-Number(t.value)])}}var Rp={float64:!1,mapSorter:Ys,quickEncodeToken:Hs},vf=Object.freeze({mapSorter:Np,quickEncodeToken:Hs});function Dp(){let t=[];return t[d.uint.major]=st,t[d.negint.major]=Fo,t[d.bytes.major]=Ar,t[d.string.major]=Hu,t[d.array.major]=Po,t[d.map.major]=Mo,t[d.tag.major]=Ko,t[d.float.major]=vn,t}var er=Dp(),Zo=new wn,Cr=class t{constructor(e,r){this.obj=e,this.parent=r}includes(e){let r=this;do if(r.obj===e)return!0;while(r=r.parent);return!1}static createCheck(e,r){if(e&&e.includes(r))throw new Error(`${Uo} object contains circular references`);return new t(r,e)}},Lt={null:new _(d.null,null),undefined:new _(d.undefined,void 0),true:new _(d.true,!0),false:new _(d.false,!1),emptyArray:new _(d.array,0),emptyMap:new _(d.map,0)},at={number(t,e,r,n){return!Number.isInteger(t)||!Number.isSafeInteger(t)?new _(d.float,t):t>=0?new _(d.uint,t):new _(d.negint,t)},bigint(t,e,r,n){return t>=BigInt(0)?new _(d.uint,t):new _(d.negint,t)},Uint8Array(t,e,r,n){return new _(d.bytes,t)},string(t,e,r,n){return new _(d.string,t)},boolean(t,e,r,n){return t?Lt.true:Lt.false},null(t,e,r,n){return Lt.null},undefined(t,e,r,n){return Lt.undefined},ArrayBuffer(t,e,r,n){return new _(d.bytes,new Uint8Array(t))},DataView(t,e,r,n){return new _(d.bytes,new Uint8Array(t.buffer,t.byteOffset,t.byteLength))},Array(t,e,r,n){if(!t.length)return r.addBreakTokens===!0?[Lt.emptyArray,new _(d.break)]:Lt.emptyArray;n=Cr.createCheck(n,t);let o=[],i=0;for(let s of t)o[i++]=Jt(s,r,n);return r.addBreakTokens?[new _(d.array,t.length),o,new _(d.break)]:[new _(d.array,t.length),o]},Object(t,e,r,n){let o=e!=="Object",i=o?t.keys():Object.keys(t),s=o?t.size:i.length,a;if(s){a=new Array(s),n=Cr.createCheck(n,t);let c=!o&&r.ignoreUndefinedProperties,f=0;for(let u of i){let l=o?t.get(u):t[u];c&&l===void 0||(a[f++]=[Jt(u,r,n),Jt(l,r,n)])}f<s&&(a.length=f)}return a?.length?(Lp(a,r),r.addBreakTokens?[new _(d.map,a.length),a,new _(d.break)]:[new _(d.map,a.length),a]):r.addBreakTokens===!0?[Lt.emptyMap,new _(d.break)]:Lt.emptyMap},Tagged(t,e,r,n){return[new _(d.tag,t.tag),Jt(t.value,r,n)]}};at.Map=at.Object;at.Buffer=at.Uint8Array;for(let t of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))at[`${t}Array`]=at.DataView;function Jt(t,e={},r){let n=Ms(t),o=e&&e.typeEncoders&&e.typeEncoders[n]||at[n];if(typeof o=="function"){let s=o(t,n,e,r);if(s!=null)return s}let i=at[n];if(!i)throw new Error(`${Uo} unsupported type: ${n}`);return i(t,n,e,r)}function Lp(t,e){let r=e.mapSorter;r&&t.sort((n,o)=>r(n,o,e))}function Ys(t,e,r){let n=Array.isArray(t[0])?t[0][0]:t[0],o=Array.isArray(e[0])?e[0][0]:e[0];if(n.type.major!==o.type.major)return n.type.compare(o.type);let i=n.type.major,s=er[i].compareTokens(n,o,r);return s===0&&console.warn("WARNING: complex key types used, CBOR key sorting guarantees are gone"),s}function Np(t,e){if(t[0]instanceof _&&e[0]instanceof _){let r=t[0],n=e[0];return r._keyBytes||(r._keyBytes=wf(r.value)),n._keyBytes||(n._keyBytes=wf(n.value)),vr(r._keyBytes,n._keyBytes)}throw new Error("rfc8949MapSorter: complex key types are not supported yet")}function wf(t){return Af(t,er,vf)}function Br(t,e,r,n){if(Array.isArray(e))for(let o of e)Br(t,o,r,n);else r[e.type.major](t,e,n)}var xf=d.uint.majorEncoded,Ef=d.negint.majorEncoded,kp=d.bytes.majorEncoded,Up=d.string.majorEncoded,Sf=d.array.majorEncoded,js=d.map.majorEncoded,Fp=d.float.majorEncoded|$o,Op=d.float.majorEncoded|Vo,Pp=d.float.majorEncoded|qo,Mp=d.float.majorEncoded|zo,Kp=BigInt(-1),$p=BigInt(1);function Nt(t,e,r){r<24?t.pushByte(e|Number(r)):ye(t,e,r)}function Vp(t){return t.addBreakTokens!==!0}function qp(t,e,r,n,o){let i=r==="Map",s=i?e.keys():Object.keys(e),a=i?e.size:s.length;if(!a){t.pushByte(js);return}o=Cr.createCheck(o,e);let c=!i&&n.ignoreUndefinedProperties,f=new Array(a),u=0;for(let l of s){let h=i?e.get(l):e[l];c&&h===void 0||(f[u++]=[Jt(l,n,o),h])}if(u===0){t.pushByte(js);return}u<a&&(f.length=u),f.sort((l,h)=>Ys(l,h,n)),Nt(t,js,u);for(let[l,h]of f)Br(t,l,er,n),Zs(t,h,n,o)}function Zs(t,e,r,n){let o=Ms(e),i=r.typeEncoders&&r.typeEncoders[o];if(i){let s=i(e,o,r,n);if(s!=null){Br(t,s,er,r);return}}switch(o){case"null":t.pushByte(Pp);return;case"undefined":t.pushByte(Mp);return;case"boolean":t.pushByte(e?Op:Fp);return;case"number":!Number.isInteger(e)||!Number.isSafeInteger(e)?vn(t,new _(d.float,e),r):e>=0?Nt(t,xf,e):Nt(t,Ef,e*-1-1);return;case"bigint":e>=BigInt(0)?Nt(t,xf,e):Nt(t,Ef,e*Kp-$p);return;case"string":{let s=No(e);Nt(t,Up,s.length),t.push(s);return}case"Uint8Array":Nt(t,kp,e.length),t.push(e);return;case"Array":if(!e.length){t.pushByte(Sf);return}n=Cr.createCheck(n,e),Nt(t,Sf,e.length);for(let s of e)Zs(t,s,r,n);return;case"Object":case"Map":if(r.mapSorter===Ys)qp(t,e,o,r,n);else{let s=at.Object(e,o,r,n);Br(t,s,er,r)}return;default:{let s=at[o];if(!s)throw new Error(`${Uo} unsupported type: ${o}`);let a=s(e,o,r,n);Br(t,a,er,r)}}}function Af(t,e,r,n){let o=n instanceof Uint8Array,i=o?new ko(n):Zo,s=Jt(t,r);if(!Array.isArray(s)&&r.quickEncodeToken){let a=r.quickEncodeToken(s);if(a)return o?(i.push(a),i.toBytes()):a;let c=e[s.type.major];if(c.encodedSize){let f=c.encodedSize(s,r);if(o||(i=new wn(f)),c(i,s,r),i.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${s} was wrong`);return o?i.toBytes():bn(i.chunks[0])}}return i.reset(),Br(i,s,e,r),i.toBytes(!0)}function Gs(t,e){return e=Object.assign({},Rp,e),Vp(e)?(Zo.reset(),Zs(Zo,t,e,void 0),Zo.toBytes(!0)):Af(t,er,e)}var zp={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},Go=class{constructor(e,r={}){this._pos=0,this.data=e,this.options=r}pos(){return this._pos}done(){return this._pos>=this.data.length}next(){let e=this.data[this._pos],r=We[e];if(r===void 0){let n=B[e];if(!n)throw new Error(`${$} no decoder for major type ${e>>>5} (byte 0x${e.toString(16).padStart(2,"0")})`);let o=e&31;r=n(this.data,this._pos,o,this.options)}return this._pos+=r.encodedLength,r}},kt=Symbol.for("DONE"),_r=Symbol.for("BREAK");function Hp(t,e,r){let n=[];for(let o=0;o<t.value;o++){let i=Ut(e,r);if(i===_r){if(t.value===1/0)break;throw new Error(`${$} got unexpected break to lengthed array`)}if(i===kt)throw new Error(`${$} found array but not enough entries (got ${o}, expected ${t.value})`);n[o]=i}return n}function jp(t,e,r){let n=r.useMaps===!0,o=r.rejectDuplicateMapKeys===!0,i=n?void 0:{},s=n?new Map:void 0;for(let a=0;a<t.value;a++){let c=Ut(e,r);if(c===_r){if(t.value===1/0)break;throw new Error(`${$} got unexpected break to lengthed map`)}if(c===kt)throw new Error(`${$} found map but not enough entries (got ${a} [no key], expected ${t.value})`);if(!n&&typeof c!="string")throw new Error(`${$} non-string keys not supported (got ${typeof c})`);if(o&&(n&&s.has(c)||!n&&Object.hasOwn(i,c)))throw new Error(`${$} found repeat map key "${c}"`);let f=Ut(e,r);if(f===kt)throw new Error(`${$} found map but not enough entries (got ${a} [no value], expected ${t.value})`);n?s.set(c,f):c==="__proto__"?Object.defineProperty(i,c,{value:f,configurable:!0,enumerable:!0,writable:!0}):i[c]=f}return n?s:i}function*Yp(t,e,r){for(let n=0;n<t.value;n++){let o=Ut(e,r);if(o===_r){if(t.value===1/0)break;throw new Error(`${$} got unexpected break to lengthed map`)}if(o===kt)throw new Error(`${$} found map but not enough entries (got ${n} [no key], expected ${t.value})`);let i=Ut(e,r);if(i===kt)throw new Error(`${$} found map but not enough entries (got ${n} [no value], expected ${t.value})`);yield[o,i]}}function Zp(t,e){let r=function(){if(r._called)throw new Error(`${$} tag decode() may only be called once`);r._called=!0;let n=Ut(t,e);if(n===kt)throw new Error(`${$} tag content missing`);if(n===_r)throw new Error(`${$} got unexpected break in tag content`);return n};return r.entries=function(){if(r._called)throw new Error(`${$} tag decode() may only be called once`);r._called=!0;let n=t.next();if(!d.equals(n.type,d.map))throw new Error(`${$} entries() requires map content, got ${n.type.name}`);let o=[];for(let i of Yp(n,t,e))o.push(i);return o},r._called=!1,r}function Ut(t,e){if(t.done())return kt;let r=t.next();if(d.equals(r.type,d.break))return _r;if(r.type.terminal)return r.value;if(d.equals(r.type,d.array))return Hp(r,t,e);if(d.equals(r.type,d.map))return jp(r,t,e);if(d.equals(r.type,d.tag)){if(e.tags&&typeof e.tags[r.value]=="function"){let n=Zp(t,e),o=e.tags[r.value](n);if(!n._called)throw new Error(`${$} tag decoder must call decode() or entries()`);return o}throw new Error(`${$} tag not supported (${r.value})`)}throw new Error("unsupported")}function Tf(t,e){if(!(t instanceof Uint8Array))throw new Error(`${$} data to decode must be a Uint8Array`);e=Object.assign({},zp,e);let r=bn(t),n=e.tokenizer||new Go(r,e),o=Ut(n,e);if(o===kt)throw new Error(`${$} did not find any content to decode`);if(o===_r)throw new Error(`${$} got unexpected break`);return[o,t.subarray(n.pos())]}function Xs(t,e){let[r,n]=Tf(t,e);if(n.length>0)throw new Error(`${$} too many terminals, data makes no sense`);return r}var Xo=class t{constructor(e,r){if(typeof e!="number"||!Number.isInteger(e)||e<0)throw new TypeError("Tagged: tag must be a non-negative integer");this.tag=e,this.value=r}static decoder(e){return r=>new t(e,r())}static preserve(...e){let r={};for(let n of e)r[n]=t.decoder(n);return r}};Object.defineProperty(Xo.prototype,Symbol.toStringTag,{value:"Tagged"});var If=Symbol.for("sindresorhus/unlimited-timeout#brand");function Bf(t,e,...r){if(typeof t!="function")throw new TypeError("Expected callback to be a function");e??=0,e=Number(e);let n=!1,o={[If]:!0,id:void 0,cleared:!1,ref(){return n=!1,o.id?.ref?.(),o},unref(){return n=!0,o.id?.unref?.(),o}};if(e===Number.POSITIVE_INFINITY||e>Number.MAX_SAFE_INTEGER)return o;(!Number.isFinite(e)||e<0)&&(e=0);let i=performance.now()+e,s=a=>{o.cleared||(a<=2147483647?(o.id=globalThis.setTimeout(()=>{o.cleared||t(...r)},a),n&&o.id?.unref?.()):(o.id=globalThis.setTimeout(()=>{let c=performance.now(),f=Math.max(0,i-c);s(f)},2147483647),n&&o.id?.unref?.()))};return s(e),o}function Cf(t){!t||typeof t!="object"||!t[If]||(t.cleared=!0,t.id!==void 0&&(globalThis.clearTimeout(t.id),t.id=void 0))}var Xp=new WeakMap;function Wp({clearTimeout:t,setTimeout:e}={}){return(r,{value:n,signal:o}={})=>{if(o?.aborted)return Promise.reject(o.reason);let i,s,a,c=t??clearTimeout,f=()=>{c(i),a(o.reason)},u=()=>{o&&o.removeEventListener("abort",f)},l=new Promise((h,m)=>{s=()=>{u(),h(n)},a=m,i=(e??setTimeout)(s,r)});return o&&o.addEventListener("abort",f,{once:!0}),Xp.set(l,()=>{c(i),i=null,s()}),l}}var Qp=Wp({setTimeout:Bf,clearTimeout:Cf}),_f=Qp;function Rf(t,e,r){let n,o,i=!1;function s(){let f={signal:o.signal},u;r?.timeout!=null&&(u=yn([o.signal,AbortSignal.timeout(r.timeout)]),f.signal=u),i=!0,Promise.resolve().then(async()=>{await t(f)}).catch(()=>{}).finally(()=>{u!=null&&(u.aborted?u.clear():u.addEventListener("abort",()=>{u.clear()},{once:!0})),i=!1,!o.signal.aborted&&(n=setTimeout(s,e))})}let a=mn(s,r?.debounce??100),c=!1;return{setInterval:f=>{e!==f&&(e=f,n!=null&&(clearTimeout(n),n=setTimeout(s,e)))},setTimeout:f=>{r??={},r.timeout=f},run:()=>{i||(clearTimeout(n),a())},start:()=>{c||(c=!0,o=new AbortController,o.signal,r?.runImmediately===!0?queueMicrotask(()=>{s()}):n=setTimeout(s,e))},stop:()=>{clearTimeout(n),o?.abort(),c=!1}}}var An;(function(t){let e;t.codec=()=>(e==null&&(e=tt((i,s,a={})=>{a.lengthDelimited!==!1&&s.fork(),i.key!=null&&i.key.byteLength>0&&(s.uint32(10),s.bytes(i.key)),i.value!=null&&i.value.byteLength>0&&(s.uint32(18),s.bytes(i.value)),i.timeReceived!=null&&i.timeReceived!==""&&(s.uint32(42),s.string(i.timeReceived)),a.lengthDelimited!==!1&&s.ldelim()},(i,s,a={})=>{let c={key:$e(0),value:$e(0),timeReceived:""},f=s==null?i.len:i.pos+s;for(;i.pos<f;){let u=i.uint32();switch(u>>>3){case 1:{c.key=i.bytes();break}case 2:{c.value=i.bytes();break}case 5:{c.timeReceived=i.string();break}default:{i.skipType(u&7);break}}}return c},function*(i,s,a,c={}){let f=s==null?i.len:i.pos+s;for(;i.pos<f;){let u=i.uint32();switch(u>>>3){case 1:{yield{field:`${a}.key`,value:i.bytes()};break}case 2:{yield{field:`${a}.value`,value:i.bytes()};break}case 5:{yield{field:`${a}.timeReceived`,value:i.string()};break}default:{i.skipType(u&7);break}}}})),e);function r(i){return Je(i,t.codec())}t.encode=r;function n(i,s){return Qe(i,t.codec(),s)}t.decode=n;function o(i,s){return et(i,t.codec(),s)}t.stream=o})(An||(An={}));function Df(t){let e=t.getUTCFullYear(),r=String(t.getUTCMonth()+1).padStart(2,"0"),n=String(t.getUTCDate()).padStart(2,"0"),o=String(t.getUTCHours()).padStart(2,"0"),i=String(t.getUTCMinutes()).padStart(2,"0"),s=String(t.getUTCSeconds()).padStart(2,"0"),a=t.getUTCMilliseconds(),c=String(a*1e3*1e3).padStart(9,"0");return`${e}-${r}-${n}T${o}:${i}:${s}.${c}Z`}function Lf(t){let e=new RegExp("(\\d{4})-(\\d{2})-(\\d{2})T(\\d{2}):(\\d{2}):(\\d{2})\\.(\\d+)Z"),r=String(t).trim().match(e);if(r==null)throw new Error("Invalid format");let n=parseInt(r[1],10),o=parseInt(r[2],10)-1,i=parseInt(r[3],10),s=parseInt(r[4],10),a=parseInt(r[5],10),c=parseInt(r[6],10),f=parseInt(r[7].slice(0,-6),10);return new Date(Date.UTC(n,o,i,s,a,c,f))}var Ft=class t{key;value;timeReceived;constructor(e,r,n){if(!(e instanceof Uint8Array))throw new Error("key must be a Uint8Array");if(!(r instanceof Uint8Array))throw new Error("value must be a Uint8Array");this.key=e,this.value=r,this.timeReceived=n}serialize(){return An.encode(this.prepareSerialize())}prepareSerialize(){return{key:this.key,value:this.value,timeReceived:Df(this.timeReceived)}}static deserialize(e){let r=An.decode(e);return new t(r.key,r.value,new Date(r.timeReceived))}static fromDeserialized(e){let r=Lf(e.timeReceived);if(e.key==null)throw new Error("key missing from deserialized object");if(e.value==null)throw new Error("value missing from deserialized object");return new t(e.key,e.value,r)}};var mt="/",Nf=new TextEncoder().encode(mt),Wo=Nf[0],Rr=class t{_buf;constructor(e,r){if(typeof e=="string")this._buf=le(e);else if(e instanceof Uint8Array)this._buf=e;else throw new Error("Invalid key, should be String of Uint8Array");if(r==null&&(r=!0),r&&this.clean(),this._buf.byteLength===0||this._buf[0]!==Wo)throw new Error("Invalid key")}toString(e="utf8"){return te(this._buf,e)}uint8Array(){return this._buf}get[Symbol.toStringTag](){return`Key(${this.toString()})`}static withNamespaces(e){return new t(e.join(mt))}static random(){return new t(Math.random().toString().substring(2))}static asKey(e){return e instanceof Uint8Array||typeof e=="string"?new t(e):typeof e.uint8Array=="function"?new t(e.uint8Array()):null}clean(){if((this._buf==null||this._buf.byteLength===0)&&(this._buf=Nf),this._buf[0]!==Wo){let e=new Uint8Array(this._buf.byteLength+1);e.fill(Wo,0,1),e.set(this._buf,1),this._buf=e}for(;this._buf.byteLength>1&&this._buf[this._buf.byteLength-1]===Wo;)this._buf=this._buf.subarray(0,-1)}less(e){let r=this.list(),n=e.list();for(let o=0;o<r.length;o++){if(n.length<o+1)return!1;let i=r[o],s=n[o];if(i<s)return!0;if(i>s)return!1}return r.length<n.length}reverse(){return t.withNamespaces(this.list().slice().reverse())}namespaces(){return this.list()}baseNamespace(){let e=this.namespaces();return e[e.length-1]}list(){return this.toString().split(mt).slice(1)}type(){return em(this.baseNamespace())}name(){return tm(this.baseNamespace())}instance(e){return new t(this.toString()+":"+e)}path(){let e=this.parent().toString();return e.endsWith(mt)||(e+=mt),e+=this.type(),new t(e)}parent(){let e=this.list();return e.length===1?new t(mt):new t(e.slice(0,-1).join(mt))}child(e){return this.toString()===mt?e:e.toString()===mt?this:new t(this.toString()+e.toString(),!1)}isAncestorOf(e){return e.toString()===this.toString()?!1:e.toString().startsWith(this.toString())}isDecendantOf(e){return e.toString()===this.toString()?!1:this.toString().startsWith(e.toString())}isTopLevel(){return this.list().length===1}concat(...e){return t.withNamespaces([...this.namespaces(),...rm(e.map(r=>r.namespaces()))])}};function em(t){let e=t.split(":");return e.length<2?"":e.slice(0,-1).join(":")}function tm(t){let e=t.split(":");return e[e.length-1]}function rm(t){return[].concat(...t)}var kf;(function(t){t[t.SEND_QUERY=0]="SEND_QUERY",t[t.PEER_RESPONSE=1]="PEER_RESPONSE",t[t.FINAL_PEER=2]="FINAL_PEER",t[t.QUERY_ERROR=3]="QUERY_ERROR",t[t.PROVIDER=4]="PROVIDER",t[t.VALUE=5]="VALUE",t[t.ADD_PEER=6]="ADD_PEER",t[t.DIAL_PEER=7]="DIAL_PEER",t[t.PATH_ENDED=8]="PATH_ENDED"})(kf||(kf={}));var Ee;(function(t){t.reissue="reissue",t.rebroadcast="rebroadcast",t.none="none"})(Ee||(Ee={}));var Qo;(function(t){t[t.reissue=0]="reissue",t[t.rebroadcast=1]="rebroadcast",t[t.none=2]="none"})(Qo||(Qo={}));(function(t){t.codec=()=>Vt(Qo)})(Ee||(Ee={}));var Dr;(function(t){let e;t.codec=()=>(e==null&&(e=tt((i,s,a={})=>{a.lengthDelimited!==!1&&s.fork(),i.keyName!=null&&i.keyName!==""&&(s.uint32(10),s.string(i.keyName)),i.lifetime!=null&&i.lifetime!==0&&(s.uint32(16),s.uint32(i.lifetime)),i.upkeep!=null&&Qo[i.upkeep]!==0&&(s.uint32(24),Ee.codec().encode(i.upkeep,s)),a.lengthDelimited!==!1&&s.ldelim()},(i,s,a={})=>{let c={keyName:"",lifetime:0,upkeep:Ee.reissue},f=s==null?i.len:i.pos+s;for(;i.pos<f;){let u=i.uint32();switch(u>>>3){case 1:{c.keyName=i.string();break}case 2:{c.lifetime=i.uint32();break}case 3:{c.upkeep=Ee.codec().decode(i);break}default:{i.skipType(u&7);break}}}return c},function*(i,s,a,c={}){let f=s==null?i.len:i.pos+s;for(a!=="."&&(yield{field:a.endsWith(".")?a.substring(0,a.length-1):a,type:"start",message:"IPNSPublishMetadata"});i.pos<f;){let u=i.uint32();switch(u>>>3){case 1:{yield{field:`${a}keyName`,value:i.string()};break}case 2:{yield{field:`${a}lifetime`,value:i.uint32()};break}case 3:{yield{field:`${a}upkeep`,value:Ee.codec().decode(i)};break}default:{i.skipType(u&7);break}}}a!=="."&&(yield{field:a.endsWith(".")?a.substring(0,a.length-1):a,type:"end",message:"IPNSPublishMetadata"})})),e);function r(i){return Je(i,t.codec())}t.encode=r;function n(i,s){return Qe(i,t.codec(),s)}t.decode=n;function o(i,s){return et(i,t.codec(),s)}t.stream=o})(Dr||(Dr={}));function Jo(t){return t==null?!1:typeof t.type=="string"&&typeof t.code=="number"&&typeof t.verify=="function"}var Uf=42;function nm(t){return t instanceof ArrayBuffer?new Uint8Array(t,0,t.byteLength):t}function om(t){if(t.asCID!==t&&t["/"]!==t.bytes)return null;let e=se.asCID(t);if(!e)return null;let r=new Uint8Array(e.bytes.byteLength+1);return r.set(e.bytes,1),[new _(d.tag,Uf),new _(d.bytes,r)]}function im(){throw new Error("`undefined` is not supported by the IPLD Data Model and cannot be encoded")}function sm(t){if(Number.isNaN(t))throw new Error("`NaN` is not supported by the IPLD Data Model and cannot be encoded");if(t===1/0||t===-1/0)throw new Error("`Infinity` and `-Infinity` is not supported by the IPLD Data Model and cannot be encoded");return null}function am(t){for(let e of t.keys())if(typeof e!="string"||e.length===0)throw new Error("Non-string Map keys are not supported by the IPLD Data Model and cannot be encoded");return null}var Ws={float64:!0,typeEncoders:{Map:am,Object:om,undefined:im,number:sm}},k1={...Ws,typeEncoders:{...Ws.typeEncoders}};function cm(t){let e=t();if(e[0]!==0)throw new Error("Invalid CID for CBOR tag 42; expected leading 0x00");return se.decode(e.subarray(1))}var Qs={allowIndefinite:!1,coerceUndefinedToNull:!0,allowNaN:!1,allowInfinity:!1,allowBigInt:!0,strict:!0,useMaps:!1,rejectDuplicateMapKeys:!0,tags:{[Uf]:cm}},U1={...Qs,tags:{...Qs.tags}};var Ff=t=>Gs(t,Ws),Of=t=>Xs(nm(t),Qs);var Pf=114,Mf=0;var Kf=le("/ipns/"),ei="/ipns/";function $f(t,e){return t.code===e}var ti="/dht/record/",lm="/ipns/metadata/";function Tn(t){return new Rr(ti+te(t,"base32"),!1)}function Lr(t){return new Rr(lm+te(t,"base32"),!1)}function Vf(t,e){let r=Date.now();return t.getTime()+1728e5-r<864e5||e.getTime()-r<864e5}function qf(t,e,r){let n=le(e);return vt([t,r,n],t.byteLength+r.byteLength+n.byteLength)}function ri(t){let e=le("ipns-signature:");return vt([e,t])}function Js(t){try{return`/ipfs/${se.decode(t)}`}catch{}return te(t)}function He(t){return vt([Kf,t.bytes])}function ni(t){return wt(t.slice(Kf.length))}function zf(t){return Te(Ff(t))}function je(t){if(t==null)throw new Hr("Record data is missing");let e=Of(t);if(e.ValidityType===0&&(e.ValidityType=Q.ValidityType.EOL),e.ValidityType!==Q.ValidityType.EOL)throw new Mt("The validity type is unsupported");return Number.isInteger(e.Sequence)&&(e.Sequence=BigInt(e.Sequence)),Number.isInteger(e.TTL)&&(e.TTL=BigInt(e.TTL)),e}function oi(t){if(t!=null){if(Jo(t))return`/ipns/${t.toCID().toV1().toString(Ae)}`;let e=Yf(t);if(e!=null)return e.code===Pf?`/ipns/${e.toV1().toString(Ae)}`:`/ipfs/${e.toV1()}`;if(hm(t))return`/ipns/${Ae.encode(t.bytes)}`;let r=t.toString().trim();if(r.startsWith("/ipfs/")){let[,n,...o]=r.split("/").filter(i=>i.trim()!=="");return`/ipfs/${se.parse(n).toV1()}${o.length>0?`/${o.join("/")}`:""}`}if(r.startsWith("/")&&r.length>1)return r}throw new ct("Value must be a valid content path starting with /")}function dm(t){return typeof t.code=="number"&&t.digest instanceof Uint8Array&&typeof t.size=="number"&&t.bytes instanceof Uint8Array}function yt(t){if(t!=null){if(Jo(t))return{digest:t.toMultihash(),path:"/"};let e=Yf(t);if(e!=null){if(e.code!==Pf)throw new ct("CIDs must have the `libp2p-key` codec");return{digest:e.multihash,path:"/"}}if(dm(t))return{digest:t,path:"/"};if(t=t.toString(),t.startsWith("/ipns/")){let[,,r,...n]=t.split("/"),o=Ae;(r.startsWith("1")||r.startsWith("Q"))&&(r=`z${r}`,o=re);let i=o.decode(r),s;try{s=se.decode(i).multihash}catch{s=wt(i)}return{digest:s,path:`/${n.join("/")}`}}}throw new ct("Value must be a valid IPNS path starting with /")}function Hf(t){if(typeof t!="string")return yt(t).digest;try{return yt(t).digest}catch{return t}}function jf(t,e){if(!de(e.Value,t.value??new Uint8Array(0)))throw new Ke('Field "value" did not match between protobuf and CBOR');if(!de(e.Validity,t.validity??new Uint8Array(0)))throw new Ke('Field "validity" did not match between protobuf and CBOR');if(e.ValidityType!==t.validityType)throw new Ke('Field "validityType" did not match between protobuf and CBOR');if(e.Sequence!==t.sequence)throw new Ke('Field "sequence" did not match between protobuf and CBOR');if(e.TTL!==t.ttl)throw new Ke('Field "ttl" did not match between protobuf and CBOR')}function hm(t){return t.bytes instanceof Uint8Array}function pm(t){return typeof t?.toCID=="function"}function Yf(t){if(pm(t))return t.toCID();try{return se.parse(t)}catch{}return se.asCID(t)}async function mm(t,e,r,n){let o=r;try{o={...Dr.decode(await t.get(Lr(e),n)),...r}}catch(i){if(i.name!=="NotFoundError")throw i}if(o.upkeep===Ee.reissue&&(o.keyName==null||o.keyName===""))throw new Error("a keyName is required to reissue a record");return o}async function ym(t,e,r,n){try{return Dr.decode(await t.get(Lr(e),n))}catch(o){o.name!=="NotFoundError"&&r.error("error deserializing metadata for %b - %e",e,o);return}}function Nr(t,e){return{async put(r,n,o={}){try{let i=Tn(r);if(o.overwrite!==!0)try{let c=await t.get(i),f=Ft.deserialize(c);if(de(f.value,n))return}catch(c){if(c.name!=="NotFoundError")throw c}let s=new Ft(r,n,new Date);o.onProgress?.(new pe("ipns:routing:datastore:put"));let a=t.batch();if(a.put(i,s.serialize()),o.metadata!=null){let c=await mm(t,r,o.metadata,o);a.put(Lr(r),Dr.encode(c))}await a.commit(o)}catch(i){throw o.onProgress?.(new pe("ipns:routing:datastore:error",i)),i}},async get(r,n={}){try{let o=Tn(r);n.onProgress?.(new pe("ipns:routing:datastore:get"));let i=await t.get(o,n),s=Ft.deserialize(i);return{record:Te(s.value),created:s.timeReceived}}catch(o){throw n.onProgress?.(new pe("ipns:routing:datastore:error",o)),o}},async has(r,n={}){let o=Tn(r);return t.has(o,n)},async delete(r,n){let o=Tn(r),i=t.batch();i.delete(o),i.delete(Lr(r)),await i.commit(n)},async deleteMetadata(r,n){await t.delete(Lr(r),n)},async*list(r={}){try{r.onProgress?.(new pe("ipns:routing:datastore:list"));for await(let{key:n,value:o}of t.query({prefix:ti},r))try{let i=Ft.deserialize(o),a=n.toString().substring(ti.length),c=le(a,"base32"),f=await ym(t,c,e,r);yield{routingKey:c,metadata:f,record:i.value,created:i.timeReceived}}catch(i){e.error("Error deserializing record - %e",i)}}catch(n){throw r.onProgress?.(new pe("ipns:routing:datastore:error",n)),n}}}}var ta=_n(In(),1);function Ye(t,e){let r=e.map((n,o)=>({record:n,index:o}));return r.sort((n,o)=>{let i=je(n.record.data),s=je(o.record.data),a=i.Sequence,c=s.Sequence;if(a>c)return-1;if(a<c)return 1;if(i.ValidityType===Q.ValidityType.EOL&&s.ValidityType===Q.ValidityType.EOL){let f=ta.default.fromString(te(i.Validity)).toDate(),u=ta.default.fromString(te(s.Validity)).toDate();if(f.getTime()>u.getTime())return-1;if(f.getTime()<u.getTime())return 1}return 0}),r[0].index}var Zf=_n(In(),1);var gm=1024*10;async function Oe(t,e,r,n){if(e.byteLength>gm)throw new zr("The record is too large");let o=Q.decode(e);if(o.signatureV2==null)throw new Ke("Missing signatureV2");let i=je(o.data),s=te(i.Validity),a=await ra(t,o,r,n),c;try{if(o.data==null)throw new Error("Missing data");let f=ri(o.data);c=await a.verify(f,o.signatureV2,n)}catch{c=!1}if(!c)throw new Ke("Record signature verification failed");if(i.ValidityType===Q.ValidityType.EOL){if(Zf.default.fromString(s).toDate().getTime()<Date.now())throw new qr("record has expired")}else if(i.ValidityType!=null)throw new Mt(`The validity type ${i.ValidityType} is unsupported`);return o.value!=null&&o.signatureV1!=null&&jf(o,i),o}async function ra(t,e,r,n){let o=ni(t);if($f(o,0))return r.loadPublicKeyFromProtobuf(o.digest,n);if(e.publicKey!=null){let i=await r.loadPublicKeyFromProtobuf(e.publicKey,n);if(!de(i.toMultihash().bytes,o.bytes))throw new cr("Embedded public key does not match the routing key");return i}throw new cr("Could not extract public key from IPNS record or routing key")}var he=Qr("helia:ipns:routing:pubsub"),oa=class{subscriptions;localStore;libp2p;fetchConcurrency;fetchTimeout;fetchDelay;fetchQueue;fetchPeers;shutdownController;fetchTopologyId;keychain;constructor(e,r={}){if(this.subscriptions=new Set,this.shutdownController=new AbortController,this.shutdownController.signal,this.fetchPeers=new pn,this.localStore=Nr(e.datastore,e.logger.forComponent("helia:ipns:local-store")),this.libp2p=e.libp2p,this.fetchConcurrency=r.fetchConcurrency??8,this.fetchDelay=r.fetchDelay??0,this.keychain=e.keychain,this.fetchTimeout=r.fetchTimeout??2500,this.fetchQueue=new Sr({concurrency:this.fetchConcurrency,metrics:e.metrics,metricName:"helia_ipns_pubsub_fetch_queue"}),this.libp2p.services.pubsub.addEventListener("message",n=>{let o=n.detail;this.subscriptions.has(o.topic)&&this.#e(o,{signal:this.shutdownController.signal}).catch(i=>{he.error("Error processing message - %e",i)})}),this.libp2p.services.fetch!=null)try{this.libp2p.services.pubsub.addEventListener("subscription-change",n=>{let{peerId:o,subscriptions:i}=n.detail;if(this.fetchPeers.has(o))for(let s of i){if(!this.subscriptions.has(s.topic)||s.subscribe===!1)continue;he("peer %s joined topic %s",o,s.topic);let a=Gf(s.topic);this.#t(s.topic,a,o,{signal:this.shutdownController.signal}).catch(c=>{he.error("failed to fetch IPNS record for %m from peer %s - %e",a,o,c)})}}),this.libp2p.services.fetch.registerLookupFunction(ei,async n=>{try{let{record:o}=await this.localStore.get(n,{signal:this.shutdownController.signal});return o}catch(o){if(o.name!=="NotFoundError")throw o}}),he("registered lookup function for IPNS with libp2p/fetch service")}catch(n){he("unable to register lookup function for IPNS with libp2p/fetch service - %e",n)}else he("no libp2p/fetch service found. Skipping registration of lookup function for IPNS.")}async#e(e,r){if(he("message received for topic",e.topic),e.type!=="signed"){he.error("unsigned message received, this module can only work with signed messages");return}if(e.from.equals(this.libp2p.peerId)){he("not storing record from self");return}await this.#r(e.topic,Gf(e.topic),e.data,!1,r)}async#t(e,r,n,o){let i=await this.fetchQueue.add(async({signal:s})=>{he("fetching ipns record for %m from peer %s",r,n);let a=yn([s,AbortSignal.timeout(this.fetchTimeout)]);try{return await this.libp2p.services.fetch?.fetch(n,r,{signal:a})}finally{a.clear()}},o);if(i==null)throw new qt(`Peer ${n} did not have record for routing key ${te(r,"base64")}`);return he("fetched ipns record for %m from peer %s",r,n),this.#r(e,r,i,!0,o)}async#r(e,r,n,o,i){let s=await Oe(r,n,this.keychain,i);if(this.shutdownController.signal.throwIfAborted(),await this.localStore.has(r)){let{record:a}=await this.localStore.get(r,i),c=await Oe(r,a,this.keychain,i);if(de(a,n))return he.trace("found identical record for %m",r),a;if(Ye(r,[c,s])===0)return he.trace("found old record for %m",r),a}if(he("found new record for %m",r),await this.localStore.put(r,n,i),o){he("publish value for topic %s",e);try{let a=await this.libp2p.services.pubsub.publish(e,n);he("published record on topic %s to %d recipients",e,a.recipients)}catch(a){he.error("could not publish record on topic %s - %e",a)}}return Te(n)}async put(e,r,n={}){try{let o=na(e);he("publish value for topic %s",o);let i=await this.libp2p.services.pubsub.publish(o,r);n?.signal?.throwIfAborted(),he("published record on topic %s to %d recipients",o,i.recipients),n.onProgress?.(new pe("ipns:pubsub:publish",{topic:o,result:i}))}catch(o){throw n.onProgress?.(new pe("ipns:pubsub:error",o)),o}}async get(e,r={}){let n=na(e);try{this.libp2p.services.pubsub.getTopics().includes(n)||(he("add subscription for topic",n),this.libp2p.services.pubsub.subscribe(n),this.subscriptions.add(n),r.onProgress?.(new pe("ipns:pubsub:subscribe",{topic:n})))}catch(s){throw r.onProgress?.(new pe("ipns:pubsub:error",s)),s}await _o(_f(this.fetchDelay),this.shutdownController.signal);let o=new AbortController,i=[];for(let s of this.libp2p.services.pubsub.getSubscribers(n)){let a=yn([r?.signal,o.signal]);i.push(this.#t(n,e,s,{...r,signal:a}).finally(()=>{a.clear()}))}if(i.length>0){let s=await Promise.any(i);if(o.abort(),s!=null)return s}throw new qt("Pubsub routing does not actively query peers")}getSubscriptions(){return[...this.subscriptions]}cancel(e){let r=Ha(e)?e.toMultihash():e,n=He(r),o=na(n);this.subscriptions.has(o)&&(this.libp2p.services.pubsub.unsubscribe(o),this.subscriptions.delete(o))}toString(){return"PubSubRouting()"}async start(){this.shutdownController=new AbortController,this.shutdownController.signal,this.libp2p.services.fetch!=null&&(this.fetchTopologyId=await this.libp2p.register(this.libp2p.services.fetch.protocol,{onConnect:e=>{this.fetchPeers.add(e)},onDisconnect:e=>{this.fetchPeers.delete(e)}},{signal:this.shutdownController.signal}))}stop(){this.fetchQueue.abort(),this.shutdownController.abort(),this.fetchTopologyId!=null&&this.libp2p.unregister(this.fetchTopologyId)}},ii="/record/";function na(t){let e=te(t,"base64url");return`${ii}${e}`}function Gf(t){if(t.substring(0,ii.length)!==ii)throw new $r("Topic received is not from a record");let e=t.substring(ii.length);return le(e,"base64url")}function Xf(t,e={}){return new oa(t,e)}function Ot(t){if(t.toString===Object.prototype.toString)return"CustomRouting()";let e=t.toString();return typeof e!="string"||e===""?"CustomRouting()":e}function Bn(t){return String(t)==="LocalStoreRouting()"}var kr=class{routers;localStore;log;keychain;constructor(e,r){this.log=e.logger.forComponent("helia:ipns"),this.localStore=r.localStore,this.routers=r.routers,this.keychain=e.keychain}async*resolve(e,r={}){let{digest:n}=yt(e);for(;;){let o=He(n),i=await this.#e(o,r),s="";if(i.data!=null){let a=je(i.data);s=Js(a.Value)}else if(i.value!=null)s=Js(i.value);else throw new ct(`Record for key ${Ae.encode(n.bytes)} contained no value`);if(yield{record:i,value:s},!s.startsWith(ei))break;({digest:n}=yt(s))}}async#e(e,r={}){let n=[];if(await this.localStore.has(e,r))if(this.log("record is present in the cache"),r.nocache!==!0)try{let{record:c,created:f}=await this.localStore.get(e,r);this.log("record retrieved from cache");let u;r.validate===!1?(u=Q.decode(c),this.log("skipped validation of record")):(u=await Oe(e,c,this.keychain,r),this.log("record was valid"));let l=je(u.data),h=Number((l.TTL??Dn)/1000000n);if(f.getTime()+h>Date.now())return this.log("record TTL was valid"),u;if(r.offline===!0)return this.log("record TTL has been reached but we are resolving offline-only, returning record"),u;this.log("record TTL has been reached, searching routing for updates"),n.push(u)}catch(c){this.log("cached record was invalid - %e",c),await this.localStore.delete(e,r)}else this.log("ignoring local cache due to nocache=true option");if(r.offline===!0)throw new sr("Record was not present in the cache or has expired");this.log("did not have record locally");let{records:i,foundInvalid:s}=await si(this.routers,e,this.keychain,this.log,r,r.validate!==!1);if(n.push(...i),n.length===0)throw s>0?new Kr(`${s>1?`${s} records`:"Record"} found for routing key ${s>1?"were":"was"} invalid`):new sr("Could not find record for routing key");let a=n[Ye(e,n)];return await this.localStore.put(e,Q.encode(a),r),a}};async function si(t,e,r,n,o={},i=!0){let s=[],a=0;return await Promise.all(t.map(async c=>{if(Bn(c))return;let f;try{f=await c.get(e,{...o,validate:!1})}catch(u){n.error("error finding IPNS record using router %s - %e",Ot(c),u);return}try{let u=i?await Oe(e,f,r,o):Q.decode(f);s.push(u)}catch(u){a++,n.error("error reading IPNS record from router %s - %e",Ot(c),u)}})),{records:s,foundInvalid:a}}var Wf=_n(In(),1);var bm=Qr("ipns"),wm=300000000000n;async function Ur(t,e,r,n,o){r=BigInt(r),e=oi(e);let i=le(e),s=o?.ttlNs??wm,a=new Wf.default((o?.now??Date.now())+Number(n)),c=Q.ValidityType.EOL,f=le(a.toString()),u=zf({...o?.data??{},Value:i,Validity:f,ValidityType:0,Sequence:r,TTL:s}),l=ri(u),h=await t.sign(l,o),m;return o?.v1Compatible===!1?m={signatureV2:h,data:u}:m={value:i,signatureV1:await xm(t,i,c,f),validityType:c,validity:f,sequence:r,ttl:s,signatureV2:h,data:u},Em(t.publicKey)&&(m.publicKey=t.publicKey.toProtobuf()),m}var xm=async(t,e,r,n,o)=>{try{let i=qf(e,r,n);return await t.sign(i,o)}catch(i){throw bm.error("record signature creation failed",i),new Vr("Record signature creation failed")}};function Em(t){return t.toMultihash().code!==Mf}var ai=class{routers;localStore;keychain;constructor(e,r){this.keychain=e.keychain,this.localStore=r.localStore,this.routers=r.routers}async publish(e,r,n={}){try{let o=await this.#e(e,n),i=o.publicKey.toMultihash(),s=He(i),a=1n;if(await this.localStore.has(s,n)){let{record:h}=await this.localStore.get(s,n),m=Q.decode(h);a=(je(m.data).Sequence??0n)+1n}let c=n.lifetime??1728e5,f=await Ur(o,r,a,c,{...n,ttlNs:n.ttl!=null?BigInt(n.ttl)*1000000n:void 0}),u=Q.encode(f),l={keyName:e,lifetime:c,upkeep:Ee[n.upkeep??"reissue"]};return n.offline===!0?await this.localStore.put(s,u,{...n,metadata:l}):await Promise.all(this.routers.map(async h=>{await h.put(s,u,{...n,metadata:l})})),{record:f,name:`/ipns/${o.publicKey.toCID().toString(Ae)}`,publicKey:o.publicKey}}catch(o){throw n.onProgress?.(new pe("ipns:publish:error",o)),o}}async#e(e,r){try{return await this.keychain.exportKey(e,r)}catch(n){if(n.name==="NotFoundError")return this.keychain.generateKey(e,r);throw n}}async unpublish(e,r){typeof e=="string"&&(e=(await this.keychain.exportKey(e,r)).publicKey.toMultihash());let n=He(e);if(r?.removeRecord===!0){await this.localStore.delete(n,r);return}await this.localStore.deleteMetadata(n,r)}};var Qf=_n(In(),1);var ci=class{routers;localStore;republishTask;log;keychain;started=!1;republishConcurrency;constructor(e,r){this.log=e.logger.forComponent("helia:ipns"),this.localStore=r.localStore,this.keychain=e.keychain,this.republishConcurrency=r.republishConcurrency||Sa,this.started=!1,this.routers=r.routers??[],this.republishTask=Rf(this.#e.bind(this),r.republishInterval??36e5,{runImmediately:!0}),this.started&&this.republishTask.start()}start(){this.started||(this.started=!0,this.republishTask.start())}stop(){this.started&&(this.started=!1,this.republishTask.stop())}async#e(e={}){if(!this.started)return;this.log("starting ipns republish records loop");let r=new Sr({concurrency:this.republishConcurrency});try{let n=[],o=[],i=0;for await(let{routingKey:s,record:a,metadata:c,created:f}of this.localStore.list(e)){if(i++,c==null){this.log("no metadata found for record %b, skipping",s);continue}if(c.upkeep===Ee.none){this.log("republishing is disabled for record %b, skipping",s);continue}let u;try{u=Q.decode(a)}catch(y){this.log.error("skipping stored record %b, could not decode it - %e",s,y);continue}if(u.data==null){this.log.error("skipping stored record %b, its data is missing",s);continue}let l;try{l=je(u.data)}catch(y){this.log.error("skipping stored record %b, could not decode its data - %e",s,y);continue}let h;try{h=Qf.default.fromString(te(l.Validity)).toDate()}catch(y){this.log.error("skipping stored record %b, could not parse its validity - %e",s,y);continue}if(!Vf(f,h)){this.log.trace("skipping record %b within republish threshold",s);continue}if(c.upkeep===Ee.rebroadcast){if(h.getTime()<=Date.now()){this.log.trace("skipping expired record %b for rebroadcast",s);continue}o.push({routingKey:s,record:u});continue}let m=l.Sequence+1n,R=l.TTL??Dn,b;try{b=await this.keychain.exportKey(c.keyName)}catch(y){this.log.error("missing key %s, skipping republishing record - %e",c.keyName,y);continue}try{let y=await Ur(b,te(l.Value),m,c.lifetime,{...e,ttlNs:R});n.push({routingKey:s,record:y})}catch(y){this.log.error("error creating updated IPNS record for %b - %e",s,y);continue}}this.log(`reissuing ${n.length} and rebroadcasting ${o.length} of ${i} records`);for(let{routingKey:s,record:a}of n)r.add(async()=>this.#t(s,Q.encode(a),e),e).catch(c=>{this.log.error("failed to reissue record %b - %e",s,c)});for(let{routingKey:s,record:a}of o)r.add(async()=>{let{records:c}=await si(this.routers,s,this.keychain,this.log,e),f=[a,...c],u=f[Ye(s,f)];await this.#t(s,Q.encode(u),{...e,overwrite:!0})},e).catch(c=>{this.log.error("failed to rebroadcast record %b - %e",s,c)})}catch(n){this.log.error("error during republish - %e",n)}}async#t(e,r,n){let o=this.routers.find(Bn);o!=null&&(await o.put(e,r,n),this.log("published record %b to %s",e,Ot(o))),await Promise.all(this.routers.filter(i=>i!==o).map(async i=>{try{await i.put(e,r,n),this.log("published record %b to %s",e,Ot(i))}catch(s){this.log.error("failed to publish record %b to %s - %e",e,Ot(i),s)}}))}async republish(e,r={}){let n=He(e),o;try{({record:o}=await this.localStore.get(n,r))}catch(a){throw a.name!=="NotFoundError"?a:new qt("No local record found to republish - import it first")}let i=await Oe(n,o,this.keychain,r);if(r.skipResolution!==!0){let{records:a}=await si(this.routers,n,this.keychain,this.log,r),c=[i,...a],f=Ye(n,c);if(f!==0)throw new ar("A newer record is already published for this key",c[f])}let s={upkeep:Ee[r.upkeep??"rebroadcast"]};return await this.#t(n,o,{...r,overwrite:!0,metadata:s}),{record:i,publicKey:await ra(n,i,this.keychain,r)}}async import(e,r,n){let o=He(e),i=r instanceof Uint8Array?Q.decode(r):r,s=Q.encode(i);await Oe(o,s,this.keychain,n);try{let{record:a}=await this.localStore.get(o,n),c=Q.decode(a);if(Ye(o,[i,c])!==0)throw new ar("A newer record is already stored for this key",c)}catch(a){if(a.name!=="NotFoundError")throw a}await this.localStore.put(o,s,n)}};var ia=class{localStore;constructor(e){this.localStore=e}async put(e,r,n){await this.localStore.put(e,r,n)}async get(e,r){let{record:n}=await this.localStore.get(e,r);return n}toString(){return"LocalStoreRouting()"}};function ui(t){return new ia(t)}var fi=class{routers;publisher;republisher;resolver;localStore;components;started;constructor(e,r={}){this.localStore=Nr(e.datastore,e.logger.forComponent("helia:ipns:local-store")),this.components=e,this.started=!1,this.routers=[ui(this.localStore),ur(e.routing),...r.routers??[]],this.publisher=new ai(e,{...r,routers:this.routers,localStore:this.localStore}),this.resolver=new kr(e,{...r,routers:this.routers,localStore:this.localStore}),this.republisher=new ci(e,{...r,routers:this.routers,localStore:this.localStore}),e.events.addEventListener("start",this.start.bind(this)),e.events.addEventListener("stop",this.stop.bind(this)),this.started&&this.republisher.start();for(let n of Object.values(this.components))if(vm(n))for(let o of Object.values(n.services))Am(o)&&(o.selectors.ipns=async(i,s)=>{let a=s.map(c=>Q.decode(c));return Ye(i,a)},o.validators.ipns=async(i,s)=>{await Oe(i,s,this.components.keychain)})}start(){this.started||(this.started=!0,this.republisher.start())}stop(){this.started&&(this.started=!1,this.republisher.stop())}async publish(e,r,n={}){return this.publisher.publish(e,oi(r),n)}async*resolve(e,r={}){let{digest:n}=yt(e);yield*this.resolver.resolve(n,r)}async unpublish(e,r){return e=Hf(e),this.publisher.unpublish(e,r)}async republish(e,r={}){let{digest:n}=yt(e);return this.republisher.republish(n,r)}async import(e,r,n){let{digest:o}=yt(e);return this.republisher.import(o,r,n)}};function vm(t){return t?.services!=null}function Am(t){return t?.validators!=null&&t?.selectors!=null}function Tm(t,e={}){return new fi(t,e)}function Im(t,e={}){let r=Nr(t.datastore,t.logger.forComponent("helia:ipns:local-store")),n=[ui(r),ur(t.routing),...e.routers??[]];return new kr(t,{routers:n,localStore:r})}return cl(Bm);})();
|
|
10
|
+
${t}`)}`:r!=null?`${r}`:`${e.toString()}`}function sp(e){return e instanceof AggregateError||e?.name==="AggregateError"&&Array.isArray(e.errors)}function Wc(e,t=""){if(sp(e)){let r=Gc(e,t);return e.errors.length>0?(t=`${t} `,r+=`
|
|
11
|
+
${t}${e.errors.map(n=>`${Wc(n,`${t}`)}`).join(`
|
|
12
|
+
${t}`)}`):r+=`
|
|
13
|
+
${t}[Error list was empty]`,r.trim()}return Gc(e,t)}_t.formatters.e=e=>e==null?"undefined":Wc(e);function ap(e){let t=()=>{};return t.enabled=!1,t.color="",t.diff=0,t.log=()=>{},t.namespace=e,t.destroy=()=>!0,t.extend=()=>t,t.useColors=()=>!1,t}function hn(e,t){let r=ap(`${e}:trace`);return _t.enabled(`${e}:trace`)&&_t.names.map(n=>n.toString()).find(n=>n.includes(":trace"))!=null&&(r=_t(`${e}:trace`,t)),Object.assign(_t(e,t),{error:_t(`${e}:error`,t),trace:r,newScope:n=>hn(`${e}:${n}`,t)})}function Xc(e){if(e!=null&&(e=e.trim(),e.length!==0))return e}function ht(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}async function Qc(e,t,r,n){let o=await crypto.subtle.importKey("jwk",e,{name:"ECDSA",namedCurve:e.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let i=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,xt(t),xt(r.subarray()));return n?.signal?.throwIfAborted(),i}function cp(e){return e?.buffer instanceof ArrayBuffer}function Jc(e){if(cp(e))return e;let t=e.slice();return new Uint8Array(t.buffer,0,t.byteLength)}function Ie(e,t){t==null&&(t=e.reduce((o,i)=>o+i.length,0));let r=ct(t),n=0;for(let o of e)r.set(o,n),n+=o.length;return Jc(r)}var eu=Symbol.for("@achingbrain/uint8arraylist");function tu(e,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let r=0;for(let n of e){let o=r+n.byteLength;if(t<o)return{buf:n,index:t-r};r=o}throw new RangeError("index is out of bounds")}function co(e){return!!e?.[eu]}var kt=class e{bufs;length;[eu]=!0;constructor(...t){this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let r=0;for(let n of t)if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.push(n);else if(co(n)){r+=n.byteLength;for(let o of n.bufs)this.bufs.push(o)}else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}prepend(...t){this.prependAll(t)}prependAll(t){let r=0;for(let n of t.reverse())if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.unshift(n);else if(co(n))r+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}get(t){let r=tu(this.bufs,t);return r.buf[r.index]}set(t,r){let n=tu(this.bufs,t);n.buf[n.index]=r}write(t,r=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(r+n,t[n]);else if(co(t))for(let n=0;n<t.length;n++)this.set(r+n,t.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,r){let{bufs:n,length:o}=this._subList(t,r);return Ie(n,o)}subarray(t,r){let{bufs:n,length:o}=this._subList(t,r);return n.length===1?n[0]:Ie(n,o)}sublist(t,r){let{bufs:n,length:o}=this._subList(t,r),i=new e;return i.length=o,i.bufs=n,i}_subList(t,r){if(t=t??0,r=r??this.length,t<0&&(t=this.length+t),r<0&&(r=this.length+r),t<0||r>this.length)throw new RangeError("index is out of bounds");if(t===r)return{bufs:[],length:0};if(t===0&&r===this.length)return{bufs:[...this.bufs],length:this.length};let n=[],o=0;for(let i=0;i<this.bufs.length;i++){let s=this.bufs[i],a=o,c=a+s.byteLength;if(o=c,t>=c)continue;let u=t>=a&&t<c,f=r>a&&r<=c;if(u&&f){if(t===a&&r===c){n.push(s);break}let l=t-a;n.push(s.subarray(l,l+(r-t)));break}if(u){if(t===0){n.push(s);continue}n.push(s.subarray(t-a));continue}if(f){if(r===c){n.push(s);break}n.push(s.subarray(0,r-a));break}n.push(s)}return{bufs:n,length:r-t}}indexOf(t,r=0){if(!co(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),t.length===0)return r>this.length?this.length:r;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let i=256,s=new Int32Array(i);for(let l=0;l<i;l++)s[l]=-1;for(let l=0;l<o;l++)s[n[l]]=l;let a=s,c=this.byteLength-n.byteLength,u=n.byteLength-1,f;for(let l=r;l<=c;l+=f){f=0;for(let h=u;h>=0;h--){let m=this.get(l+h);if(n[h]!==m){f=Math.max(1,h-a[m]);break}}if(f===0)return l}return-1}getInt8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(t,r){let n=ct(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,r),this.write(n,t)}getInt16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,r)}setInt16(t,r,n){let o=jt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,r,n),this.write(o,t)}getInt32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,r)}setInt32(t,r,n){let o=jt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,r,n),this.write(o,t)}getBigInt64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,r)}setBigInt64(t,r,n){let o=jt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,r,n),this.write(o,t)}getUint8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint8(0)}setUint8(t,r){let n=ct(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,r),this.write(n,t)}getUint16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,r)}setUint16(t,r,n){let o=jt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,r,n),this.write(o,t)}getUint32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,r)}setUint32(t,r,n){let o=jt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,r,n),this.write(o,t)}getBigUint64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,r)}setBigUint64(t,r,n){let o=jt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,r,n),this.write(o,t)}getFloat32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,r)}setFloat32(t,r,n){let o=jt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,r,n),this.write(o,t)}getFloat64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,r)}setFloat64(t,r,n){let o=jt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,r,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof e)||t.bufs.length!==this.bufs.length)return!1;for(let r=0;r<this.bufs.length;r++)if(!ht(this.bufs[r],t.bufs[r]))return!1;return!0}static fromUint8Arrays(t,r){let n=new e;return n.bufs=t,r==null&&(r=t.reduce((o,i)=>o+i.byteLength,0)),n.length=r,n}};function et(e,t="utf8"){let r=Jn[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var up=parseInt("11111",2),Bs=parseInt("10000000",2),fp=parseInt("01111111",2),ru={0:pn,1:pn,2:lp,3:pp,4:mp,5:hp,6:dp,16:pn,22:pn,48:pn};function Is(e,t={offset:0}){let r=e[t.offset]&up;if(t.offset++,ru[r]!=null)return ru[r](e,t);throw new Error("No decoder for tag "+r)}function mn(e,t){let r=0;if((e[t.offset]&Bs)===Bs){let n=e[t.offset]&fp,o="0x";t.offset++;for(let i=0;i<n;i++,t.offset++){if(t.offset>=e.byteLength)throw new Error("invalid DER element length");o+=e[t.offset].toString(16).padStart(2,"0")}r=parseInt(o,16)}else r=e[t.offset],t.offset++;if(!Number.isInteger(r)||r<0||r>e.byteLength-t.offset)throw new Error("invalid DER element length");return r}function pn(e,t){mn(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=Is(e,t);if(n===null)break;r.push(n)}return r}function lp(e,t){let r=mn(e,t),n=t.offset,o=t.offset+r,i=[];for(let s=n;s<o;s++)s===n&&e[s]===0||i.push(e[s]);return t.offset+=r,Uint8Array.from(i)}function dp(e,t){let r=mn(e,t),n=t.offset+r,o=e[t.offset];t.offset++;let i=0,s=0;o<40?(i=0,s=o):o<80?(i=1,s=o-40):(i=2,s=o-80);let a=`${i}.${s}`,c=[];for(;t.offset<n;){let u=e[t.offset];if(t.offset++,c.push(u&127),u<128){c.reverse();let f=0;for(let l=0;l<c.length;l++)f+=c[l]<<l*7;a+=`.${f}`,c=[]}}return a}function hp(e,t){return t.offset++,null}function pp(e,t){let r=mn(e,t),n=e[t.offset];t.offset++;let o=e.subarray(t.offset,t.offset+r-1);if(t.offset+=r,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function mp(e,t){let r=mn(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function gp(e){let t=e.toString(16);t.length%2===1&&(t="0"+t);let r=new kt;for(let n=0;n<t.length;n+=2)r.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return r}function vs(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);let t=gp(e.byteLength);return new kt(Uint8Array.from([t.byteLength|Bs]),t)}function nu(e){let t=new kt,r=128;return(e.subarray()[0]&r)===r&&t.append(Uint8Array.from([0])),t.append(e),new kt(Uint8Array.from([2]),vs(t),t)}function ou(e){let t=Uint8Array.from([0]),r=new kt(t,e);return new kt(Uint8Array.from([3]),vs(r),r)}function uo(e,t=48){let r=new kt;for(let n of e)r.append(n);return new kt(Uint8Array.from([t]),vs(r),r)}var yp=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),bp=Uint8Array.from([6,5,43,129,4,0,34]),wp=Uint8Array.from([6,5,43,129,4,0,35]),xp={ext:!0,kty:"EC",crv:"P-256"},Ep={ext:!0,kty:"EC",crv:"P-384"},Sp={ext:!0,kty:"EC",crv:"P-521"},Cs=32,_s=48,Rs=66;function iu(e){let t=Is(e);return su(t)}function su(e){let t=e[1][1][0],r=1,n,o;if(t.byteLength===Cs*2+1)return n=et(t.subarray(r,r+Cs),"base64url"),o=et(t.subarray(r+Cs),"base64url"),new xr({...xp,key_ops:["verify"],x:n,y:o});if(t.byteLength===_s*2+1)return n=et(t.subarray(r,r+_s),"base64url"),o=et(t.subarray(r+_s),"base64url"),new xr({...Ep,key_ops:["verify"],x:n,y:o});if(t.byteLength===Rs*2+1)return n=et(t.subarray(r,r+Rs),"base64url"),o=et(t.subarray(r+Rs),"base64url"),new xr({...Sp,key_ops:["verify"],x:n,y:o});throw new de(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function au(e){return uo([nu(Uint8Array.from([1])),uo([Ap(e.crv)],160),uo([ou(new kt(Uint8Array.from([4]),nt(e.x??"","base64url"),nt(e.y??"","base64url")))],161)]).subarray()}function Ap(e){if(e==="P-256")return yp;if(e==="P-384")return bp;if(e==="P-521")return wp;throw new de(`Invalid curve ${e}`)}var xr=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=au(this.jwk)),this._raw}toMultihash(){return te.digest(Er(this))}toCID(){return at.createV1(114,this.toMultihash())}toString(){return rt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ht(this.raw,t.raw)}async verify(t,r,n){return Qc(this.jwk,r,t,n)}};var fo=BigInt(4294967295),cu=BigInt(32);function Tp(e,t=!1){return t?{h:Number(e&fo),l:Number(e>>cu&fo)}:{h:Number(e>>cu&fo)|0,l:Number(e&fo)|0}}function uu(e,t=!1){let r=e.length,n=new Uint32Array(r),o=new Uint32Array(r);for(let i=0;i<r;i++){let{h:s,l:a}=Tp(e[i],t);[n[i],o[i]]=[s,a]}return[n,o]}var Bp=e=>e/2**32|0,Ip=e=>e>>>0;function fu(e,t,r,n){let o=Bp(r),i=Ip(r);e.setUint32(t,n?i:o,n),e.setUint32(t+4,n?o:i,n)}var Ns=(e,t,r)=>e>>>r,Ds=(e,t,r)=>e<<32-r|t>>>r,Ge=(e,t,r)=>e>>>r|t<<32-r,Xe=(e,t,r)=>e<<32-r|t>>>r,gn=(e,t,r)=>e<<64-r|t>>>r-32,yn=(e,t,r)=>e>>>r-32|t<<64-r;function se(e,t,r,n){let o=(t>>>0)+(n>>>0);return{h:e+r+(o/2**32|0)|0,l:o|0}}var lu=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),du=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,hu=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),pu=(e,t,r,n,o)=>t+r+n+o+(e/2**32|0)|0,mu=(e,t,r,n,o)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(o>>>0),gu=(e,t,r,n,o,i)=>t+r+n+o+i+(e/2**32|0)|0;function lo(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in e&&e.BYTES_PER_ELEMENT===1}var Ls=e=>e?`"${e}" `:"";function he(e,t=""){if(typeof e!="number")throw new TypeError(Ls(t)+"expected number, got "+typeof e);if(!Number.isSafeInteger(e)||e<0)throw new RangeError(Ls(t)+"expected integer >= 0, got "+e);return e}function Yt(e,t,r=""){if(lo(e)&&(t===void 0||e.length===t))return e;t!==void 0&&he(t,"length");let n=lo(e),o=t!==void 0?` of length ${t}`:"",i=n?`length=${e.length}`:`type=${typeof e}`,s=Ls(r)+"expected Uint8Array"+o+", got "+i;throw n?new RangeError(s):new TypeError(s)}function ho(e){if(typeof e!="function"||typeof e.create!="function")throw new TypeError("expected hash wrapped by utils.createHasher");if(he(e.outputLen),he(e.blockLen),e.outputLen<1||e.blockLen<1)throw new Error("hash blockLen / outputLen must be >= 1")}var Cp=(e,t)=>{if(e===null||typeof e!="object"||Array.isArray(e))throw new TypeError((t==="object"?"":`"${t}" `)+"expected object, got type="+typeof e)},yu=(e,t)=>{Cp(e,t);let r=Object.getPrototypeOf(e);if(r!==Object.prototype&&r!==null)throw new TypeError(`"${t}" expected plain object`);if(Object.hasOwn(e,"__proto__"))throw new TypeError(`"${t}.__proto__" is not allowed`)};function Sr(e,t=!0){if(e.destroyed)throw new Error("hash was destroyed");if(t&&e.finished)throw new Error("digest() was already called")}function po(e,t){Yt(e,void 0,"output");let r=t.outputLen;if(!(e.length>=r))throw new RangeError('"output" expected length >= '+r)}function We(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function mo(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function ee(e,t){return e<<32-t|e>>>t}var wu=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",_p=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function go(e){if(Yt(e),wu)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=_p[e[r]];return t}function bu(e){return e>=48&&e<=57?e-48:e>=65&&e<=70?e-55:e>=97&&e<=102?e-87:void 0}function yo(e){if(typeof e!="string")throw new TypeError("hex string expected, got "+typeof e);if(wu)try{return Uint8Array.fromHex(e)}catch(o){throw o instanceof SyntaxError?new RangeError(o.message):o}let t=e.length,r=t/2;if(t%2)throw new RangeError("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(r);for(let o=0,i=0;o<r;o++,i+=2){let s=bu(e.charCodeAt(i)),a=bu(e.charCodeAt(i+1));if(s===void 0||a===void 0){let c=e[i]+e[i+1];throw new RangeError('hex string expected, got non-hex character "'+c+'" at index '+i)}n[o]=s*16+a}return n}function Fs(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];Yt(o),t+=o.length}let r=new Uint8Array(t);for(let n=0,o=0;n<e.length;n++){let i=e[n];r.set(i,o),o+=i.length}return r}function Rp(e,t,r="opts"){return yu(e,"defaults"),t!==void 0&&yu(t,r),Object.assign(Object.create(null),e,t)}function ks(e,t={}){if(typeof e!="function")throw new TypeError('"hashCons" expected function, got type='+typeof e);t=Rp({},t,"info");let r=(o,i)=>e(i).update(o).digest(),n=e(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.canXOF=n.canXOF,r.create=o=>e(o),Object.assign(r,t),Object.freeze(r)}function xu(e=32){he(e,"bytesLength");let t=typeof globalThis=="object"?globalThis.crypto:null;if(typeof t?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");if(e>65536)throw new RangeError(`"bytesLength" expected <= 65536, got ${e}`);return t.getRandomValues(new Uint8Array(e))}var Us=e=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,e])});function Eu(e,t,r){return e&t^~e&r}function Su(e,t,r){return e&t^e&r^t&r}var bn=class{blockLen;outputLen;canXOF=!1;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(t,r,n,o){this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=mo(this.buffer)}update(t){Sr(this),Yt(t);let{view:r,buffer:n,blockLen:o}=this,i=t.length,s=!1;for(let a=0;a<i;){let c=Math.min(o-this.pos,i-a);if(c===o){let u=mo(t);for(;o<=i-a;a+=o)this.process(u,a);s=!0;continue}n.set(a===0&&c===i?t:t.subarray(a,a+c),this.pos),this.pos+=c,a+=c,this.pos===o&&(this.process(r,0),this.pos=0,s=!0)}return this.length+=t.length,s&&this.roundClean(),this}digestInto(t){Sr(this),po(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:i}=this,{pos:s}=this;r[s++]=128,r.fill(0,s),this.padOffset>o-s&&(this.process(n,0),r.fill(0)),fu(n,o-8,this.length*8,i),this.process(n,0),this.roundClean();let a=t===r?n:mo(t),c=this.outputLen,u=c/4,f=this.get();if(c%4||u>f.length)throw new Error("invalid outputLen");for(let l=0;l<u;l++)a.setUint32(4*l,f[l],i)}digest(){let{buffer:t,outputLen:r}=this;this.digestInto(t);let n=t.slice(0,r);return this.destroy(),n}_cloneIntoMeta(t){let{buffer:r,length:n,finished:o,destroyed:i,pos:s}=this;return t.destroyed=i,t.finished=o,t.length=n,t.pos=s,s&&t.buffer.set(r),t}clone(){return this._cloneInto()}},Au=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var Tu=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Np=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]),ve=new Uint32Array(64),Os=class extends bn{A=0;B=0;C=0;D=0;E=0;F=0;G=0;H=0;constructor(t,r){super(64,t,8,!1),this.A=r[0]|0,this.B=r[1]|0,this.C=r[2]|0,this.D=r[3]|0,this.E=r[4]|0,this.F=r[5]|0,this.G=r[6]|0,this.H=r[7]|0}get(){let{A:t,B:r,C:n,D:o,E:i,F:s,G:a,H:c}=this;return[t,r,n,o,i,s,a,c]}set(t,r,n,o,i,s,a,c){this.A=t|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=i|0,this.F=s|0,this.G=a|0,this.H=c|0}_cloneInto(t){return(t||=new this.constructor).set(...this.get()),this._cloneIntoMeta(t)}process(t,r){for(let l=0;l<16;l++,r+=4)ve[l]=t.getUint32(r,!1);for(let l=16;l<64;l++){let h=ve[l-15],m=ve[l-2],R=ee(h,7)^ee(h,18)^h>>>3,b=ee(m,17)^ee(m,19)^m>>>10;ve[l]=b+ve[l-7]+R+ve[l-16]|0}let{A:n,B:o,C:i,D:s,E:a,F:c,G:u,H:f}=this;for(let l=0;l<64;l++){let h=ee(a,6)^ee(a,11)^ee(a,25),m=f+h+Eu(a,c,u)+Np[l]+ve[l]|0,b=(ee(n,2)^ee(n,13)^ee(n,22))+Su(n,o,i)|0;f=u,u=c,c=a,a=s+m|0,s=i,i=o,o=n,n=m+b|0}n=n+this.A|0,o=o+this.B|0,i=i+this.C|0,s=s+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,f=f+this.H|0,this.set(n,o,i,s,a,c,u,f)}roundClean(){We(ve)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),We(this.buffer)}},Ps=class extends Os{constructor(){super(32,Au)}};var Bu=uu(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(e=>BigInt(e))),Dp=Bu[0],Lp=Bu[1],Ce=new Uint32Array(80),_e=new Uint32Array(80),Ms=class extends bn{Ah=0;Al=0;Bh=0;Bl=0;Ch=0;Cl=0;Dh=0;Dl=0;Eh=0;El=0;Fh=0;Fl=0;Gh=0;Gl=0;Hh=0;Hl=0;constructor(t,r){super(128,t,16,!1),this.Ah=r[0]|0,this.Al=r[1]|0,this.Bh=r[2]|0,this.Bl=r[3]|0,this.Ch=r[4]|0,this.Cl=r[5]|0,this.Dh=r[6]|0,this.Dl=r[7]|0,this.Eh=r[8]|0,this.El=r[9]|0,this.Fh=r[10]|0,this.Fl=r[11]|0,this.Gh=r[12]|0,this.Gl=r[13]|0,this.Hh=r[14]|0,this.Hl=r[15]|0}get(){let{Ah:t,Al:r,Bh:n,Bl:o,Ch:i,Cl:s,Dh:a,Dl:c,Eh:u,El:f,Fh:l,Fl:h,Gh:m,Gl:R,Hh:b,Hl:g}=this;return[t,r,n,o,i,s,a,c,u,f,l,h,m,R,b,g]}set(t,r,n,o,i,s,a,c,u,f,l,h,m,R,b,g){this.Ah=t|0,this.Al=r|0,this.Bh=n|0,this.Bl=o|0,this.Ch=i|0,this.Cl=s|0,this.Dh=a|0,this.Dl=c|0,this.Eh=u|0,this.El=f|0,this.Fh=l|0,this.Fl=h|0,this.Gh=m|0,this.Gl=R|0,this.Hh=b|0,this.Hl=g|0}_cloneInto(t){return(t||=new this.constructor).set(...this.get()),this._cloneIntoMeta(t)}process(t,r){for(let y=0;y<16;y++,r+=4)Ce[y]=t.getUint32(r),_e[y]=t.getUint32(r+=4);for(let y=16;y<80;y++){let N=Ce[y-15]|0,C=_e[y-15]|0,$=Ge(N,C,1)^Ge(N,C,8)^Ns(N,C,7),q=Xe(N,C,1)^Xe(N,C,8)^Ds(N,C,7),w=Ce[y-2]|0,E=_e[y-2]|0,A=Ge(w,E,19)^gn(w,E,61)^Ns(w,E,6),L=Xe(w,E,19)^yn(w,E,61)^Ds(w,E,6),D=hu(q,L,_e[y-7],_e[y-16]),z=pu(D,$,A,Ce[y-7],Ce[y-16]);Ce[y]=z|0,_e[y]=D|0}let{Ah:n,Al:o,Bh:i,Bl:s,Ch:a,Cl:c,Dh:u,Dl:f,Eh:l,El:h,Fh:m,Fl:R,Gh:b,Gl:g,Hh:S,Hl:B}=this;for(let y=0;y<80;y++){let N=Ge(l,h,14)^Ge(l,h,18)^gn(l,h,41),C=Xe(l,h,14)^Xe(l,h,18)^yn(l,h,41),$=l&m^~l&b,q=h&R^~h&g,w=mu(B,C,q,Lp[y],_e[y]),E=gu(w,S,N,$,Dp[y],Ce[y]),A=w|0,L=Ge(n,o,28)^gn(n,o,34)^gn(n,o,39),D=Xe(n,o,28)^yn(n,o,34)^yn(n,o,39),z=n&i^n&a^i&a,I=o&s^o&c^s&c;S=b|0,B=g|0,b=m|0,g=R|0,m=l|0,R=h|0,{h:l,l:h}=se(u|0,f|0,E|0,A|0),u=a|0,f=c|0,a=i|0,c=s|0,i=n|0,s=o|0;let F=lu(A,D,I);n=du(F,E,L,z),o=F|0}({h:n,l:o}=se(this.Ah|0,this.Al|0,n|0,o|0)),{h:i,l:s}=se(this.Bh|0,this.Bl|0,i|0,s|0),{h:a,l:c}=se(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l:f}=se(this.Dh|0,this.Dl|0,u|0,f|0),{h:l,l:h}=se(this.Eh|0,this.El|0,l|0,h|0),{h:m,l:R}=se(this.Fh|0,this.Fl|0,m|0,R|0),{h:b,l:g}=se(this.Gh|0,this.Gl|0,b|0,g|0),{h:S,l:B}=se(this.Hh|0,this.Hl|0,S|0,B|0),this.set(n,o,i,s,a,c,u,f,l,h,m,R,b,g,S,B)}roundClean(){We(Ce,_e)}destroy(){this.destroyed=!0,We(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},Ks=class extends Ms{constructor(){super(64,Tu)}};var Iu=ks(()=>new Ps,Us(1));var Vs=ks(()=>new Ks,Us(3));function wo(e,t,r=()=>{}){if(!Array.isArray(e))throw new TypeError(`"${t}" expected array, got type=${typeof e}`);for(let n=0;n<e.length;n++)r(e[n],`${t}[${n}]`);return e}var J=(e,t,r)=>Yt(e,t,r),$s=he;function Cu(e,t=""){if(typeof e!="string"){let r=t&&`"${t}" `;throw new TypeError(r+"expected string, got type="+typeof e)}return e}function Re(e,t="object"){if(e===null||typeof e!="object"||Array.isArray(e))throw new TypeError(t==="object"?"expected valid options object":`"${t}" expected object, got type=${typeof e}`);return e}function Qe(e,t){if(typeof e!="function")throw new TypeError(`"${t}" is invalid: expected function, got ${typeof e}`);return e}var wn=go,Zt=(...e)=>Fs(...e),Ar=e=>yo(e),De=lo,Je=e=>xu(e),bo=BigInt(0),vu=BigInt(1),Fp=e=>e?`"${e}" `:"";function Rt(e,t=""){if(typeof e!="boolean")throw new TypeError(Fp(t)+"expected boolean, got type="+typeof e);return e}function xo(e){if(typeof e=="bigint"){if(!Ne(e))throw new RangeError("positive bigint expected, got "+e)}else $s(e);return e}function pe(e,t=""){if(typeof e!="number"){let r=t&&`"${t}" `;throw new TypeError(r+"expected number, got type="+typeof e)}if(!Number.isSafeInteger(e)){let r=t&&`"${t}" `;throw new RangeError(r+"expected safe integer, got "+e)}}function xn(e){let t=xo(e).toString(16);return t.length&1?"0"+t:t}function _u(e){if(typeof e!="string")throw new TypeError("hex string expected, got "+typeof e);return e===""?bo:BigInt("0x"+e)}function ae(e){return _u(go(e))}function tr(e){return _u(go(En(Yt(e)).reverse()))}function Eo(e,t){if(he(t),t===0)throw new Error("zero output length is invalid");e=xo(e);let r=t*2,n=e.toString(16);if(n.length>r)throw new RangeError("number is too large");return yo(n.padStart(r,"0"))}function qs(e,t){return Eo(e,t).reverse()}function En(e){return Uint8Array.from(J(e))}function Ne(e){return typeof e=="bigint"&&bo<=e}function zs(e,t,r){return Ne(e)&&Ne(t)&&Ne(r)&&t<=e&&e<r}function Tr(e,t,r,n){if(!zs(t,r,n))throw new RangeError("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function Br(e){if(e<bo)throw new Error("expected non-negative bigint, got "+e);return e===bo?0:e.toString(2).length}var Sn=e=>(pe(e,"n"),(vu<<BigInt(e))-vu);function Ru(e,t,r){if(he(e,"hashLen"),he(t,"qByteLen"),typeof r!="function")throw new TypeError("hmacFn must be a function");let n=g=>new Uint8Array(g),o=Uint8Array.of(),i=Uint8Array.of(0),s=Uint8Array.of(1),a=1e3,c=n(e),u=n(e),f=0,l=()=>{c.fill(1),u.fill(0),f=0},h=(...g)=>r(u,Zt(c,...g)),m=(g=o)=>{u=h(i,g),c=h(),g.length!==0&&(u=h(s,g),c=h())},R=()=>{if(f++>=a)throw new Error("drbg: tried max amount of iterations");let g=0,S=[];for(;g<t;){c=h();let B=c.slice();S.push(B),g+=c.length}return Zt(...S)};return(g,S)=>{l(),m(g);let B;for(;(B=S(R()))===void 0;)m();return l(),B}}function Nt(e,t={},r={},n="object"){Re(e,n),Re(t,"fields"),Re(r,"optFields");function o(s,a,c){let u=n==="object"?`param "${String(s)}"`:`"${n}.${String(s)}"`,f=e[s];if(!Object.hasOwn(e,s)&&(c?f!==void 0:a!=="function"))throw new TypeError(`${u} is invalid: expected own property`);if(c&&f===void 0)return;let l=typeof f;if(l!==a||f===null)throw new TypeError(`${u} is invalid: expected ${a}, got ${l}`)}let i=(s,a)=>Object.entries(s).forEach(([c,u])=>o(c,u,a));i(t,!1),i(r,!0)}var gt=BigInt(0),tt=BigInt(1),Le=BigInt(2),Lu=BigInt(3),Hs=BigInt(4),Fu=BigInt(5),kp=BigInt(7),ku=BigInt(8),Up=BigInt(9),Op=BigInt(15),Uu=BigInt(16),Pp=BigInt("0x10000000000000000");function ut(e,t){if(t<=gt)throw new Error("mod: expected positive modulus, got "+t);let r=e%t;return r>=gt?r:t+r}function Ou(e,t,r){if(r<=tt)throw new Error("pow: expected modulus > 1, got "+r);if(typeof t!="bigint")throw new TypeError("invalid exponent: expected bigint, got "+typeof t);if(t<gt)throw new Error("invalid exponent, negatives unsupported");if(t===gt)return tt;if(t===tt)return e;let n=e%r;if(n<gt&&(n+=r),t<Pp){let a=tt;for(;t>gt;)t&tt&&(a=a*n%r),n=n*n%r,t>>=tt;return a}let o=[];for(;t>gt;)o.push(Number(t&Op)),t>>=Hs;let i=new Array(16);i[0]=tt,i[1]=n;for(let a=2;a<16;a++)i[a]=i[a-1]*n%r;let s=i[o[o.length-1]];for(let a=o.length-2;a>=0;a--){s=s*s%r,s=s*s%r,s=s*s%r,s=s*s%r;let c=o[a];c!==0&&(s=s*i[c]%r)}return s}function st(e,t,r){if(r<=tt)throw new Error("pow2: expected modulus > 1, got "+r);if(t<gt)throw new Error("pow2: expected non-negative exponent, got "+t);let n=e;for(;t-- >gt;)n*=n,n%=r;return n}function Nu(e,t){if(e===gt)throw new Error("invert: expected non-zero number");if(t<=tt)throw new Error("invert: expected modulus > 1, got "+t);let r=ut(e,t),n=t,o=gt,i=tt;for(;r!==gt;){let a=n/r,c=n-r*a,u=o-i*a;n=r,r=c,o=i,i=u}if(n!==tt)throw new Error("invert: does not exist");return ut(o,t)}function Pu(e,t){if(t<=tt)throw new Error("invertCt: expected prime modulus > 1, got "+t);let r=ut(e,t);if(r===gt)throw new Error("invertCt: expected non-zero number");let n=Ou(r,t-Le,t);if(ut(r*n,t)!==tt)throw new Error("invertCt: does not exist");return n}function js(e,t,r){let n=e;if(!n.eql(n.sqr(t),r))throw new Error("Cannot find square root")}function Ys(e,t){if((e&tt)===gt)throw new Error(t+": expected odd modulus, got "+e)}function Mu(e,t){let r=e,n=(r.ORDER+tt)/Hs,o=r.pow(t,n);return js(r,o,t),o}function Mp(e,t){let r=e,n=(r.ORDER-Fu)/ku,o=r.mul(t,Le),i=r.pow(o,n),s=r.mul(t,i),a=r.mul(r.mul(s,Le),i),c=r.mul(s,r.sub(a,r.ONE));return js(r,c,t),c}function Kp(e){let t=vr(e),r=Ku(e),n=r(t,t.neg(t.ONE)),o=r(t,n),i=r(t,t.neg(n)),s=(e+kp)/Uu;return((a,c)=>{let u=a,f=u.pow(c,s),l=u.mul(f,n),h=u.mul(f,o),m=u.mul(f,i),R=u.eql(u.sqr(l),c),b=u.eql(u.sqr(h),c);f=u.cmov(f,l,R),l=u.cmov(m,h,b);let g=u.eql(u.sqr(l),c),S=u.cmov(f,l,g);return js(u,S,c),S})}function Ku(e){if(e<Lu)throw new Error("sqrt is not defined for small field");Ys(e,"tonelliShanks");let t=e-tt,r=0;for(;t%Le===gt;)t/=Le,r++;let n=Le,o=vr(e);for(;An(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return Mu;let i=o.pow(n,t),s=(t+tt)/Le;return function(c,u){let f=c;if(f.is0(u))return u;if(An(f,u)!==1)throw new Error("Cannot find square root");let l=r,h=f.mul(f.ONE,i),m=f.pow(u,t),R=f.pow(u,s);for(;!f.eql(m,f.ONE);){if(f.is0(m))throw new Error("Cannot find square root: probably non-prime P");let b=1,g=f.sqr(m);for(;!f.eql(g,f.ONE);)if(b++,g=f.sqr(g),b===l)throw new Error("Cannot find square root");let S=tt<<BigInt(l-b-1),B=f.pow(h,S);l=b,h=f.sqr(B),m=f.mul(m,h),R=f.mul(R,B)}return R}}function Vp(e){return Ys(e,"Fp.sqrt"),e%Hs===Lu?Mu:e%ku===Fu?Mp:e%Uu===Up?Kp(e):Ku(e)}var Vu=(e,t)=>(ut(e,t)&tt)===tt,$p=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Ir(e){if(Re(e,"field"),typeof e.ORDER!="bigint")throw new TypeError('param "ORDER" is invalid: expected bigint, got '+typeof e.ORDER);pe(e.BYTES,"BYTES"),pe(e.BITS,"BITS");for(let t of $p)Qe(e[t],"field."+t);if(e.BYTES<1||e.BITS<1)throw new Error("invalid field: expected BYTES/BITS > 0");if(e.ORDER<=tt)throw new Error("invalid field: expected ORDER > 1, got "+e.ORDER);return e}function Ao(e,t,r=!1){Ir(e),wo(t,"nums"),Rt(r,"passZero");let n=e,o=new Array(t.length).fill(r?n.ZERO:void 0),i=t.reduce((a,c,u)=>n.is0(c)?a:(o[u]=a,n.mul(a,c)),n.ONE),s=n.inv(i);return t.reduceRight((a,c,u)=>n.is0(c)?a:(o[u]=n.mul(a,o[u]),n.mul(a,c)),s),o}function An(e,t){Ir(e);let r=e;Ys(r.ORDER,"FpLegendre");let n=(r.ORDER-tt)/Le,o=r.pow(t,n),i=r.eql(o,r.ONE),s=r.eql(o,r.ZERO),a=r.eql(o,r.neg(r.ONE));if(!i&&!s&&!a)throw new Error("invalid Legendre symbol result");return i?1:s?0:-1}function qp(e,t){if(t!==void 0&&$s(t),e<=gt)throw new Error("invalid n length: expected positive n, got "+e);if(t!==void 0&&t<1)throw new Error("invalid n length: expected positive bit length, got "+t);let r=Br(e);if(t!==void 0&&t<r)throw new Error(`invalid n length: expected nBitLength (${t}) >= bitLen(n) (${r})`);let n=t!==void 0?t:r,o=Math.ceil(n/8);return{nBitLength:n,nByteLength:o}}var Du=new WeakMap,So=class{ORDER;BITS;BYTES;isLE;ZERO=gt;ONE=tt;_lengths;_mod;constructor(t,r={}){if(t<=tt)throw new Error("invalid field: expected ORDER > 1, got "+t);let n;this.isLE=!1,r!=null&&typeof r=="object"&&(typeof r.BITS=="number"&&(n=r.BITS),typeof r.sqrt=="function"&&Object.defineProperty(this,"sqrt",{value:r.sqrt,enumerable:!0}),typeof r.isLE=="boolean"&&(this.isLE=r.isLE),r.allowedLengths&&(this._lengths=Object.freeze(r.allowedLengths.slice())),typeof r.modFromBytes=="boolean"&&(this._mod=r.modFromBytes));let{nBitLength:o,nByteLength:i}=qp(t,n);if(i>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=t,this.BITS=o,this.BYTES=i,Object.freeze(this)}create(t){return ut(t,this.ORDER)}isValid(t){if(typeof t!="bigint")throw new TypeError("invalid field element: expected bigint, got "+typeof t);return gt<=t&&t<this.ORDER}is0(t){return t===gt}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}isOdd(t){return(t&tt)===tt}neg(t){return ut(-t,this.ORDER)}eql(t,r){return t===r}sqr(t){return ut(t*t,this.ORDER)}add(t,r){return ut(t+r,this.ORDER)}sub(t,r){return ut(t-r,this.ORDER)}mul(t,r){return ut(t*r,this.ORDER)}pow(t,r){return Ou(t,r,this.ORDER)}div(t,r){return ut(t*Nu(r,this.ORDER),this.ORDER)}sqrN(t){return t*t}addN(t,r){return t+r}subN(t,r){return t-r}mulN(t,r){return t*r}inv(t){return Nu(t,this.ORDER)}sqrt(t){let r=Du.get(this);return r||Du.set(this,r=Vp(this.ORDER)),r(this,t)}toBytes(t){return this.isLE?qs(t,this.BYTES):Eo(t,this.BYTES)}fromBytes(t,r=!1){J(t);let{_lengths:n,BYTES:o,isLE:i,ORDER:s,_mod:a}=this;if(n){if(t.length<1||!n.includes(t.length)||t.length>o)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+t.length);let u=new Uint8Array(o);u.set(t,i?0:u.length-t.length),t=u}if(t.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+t.length);let c=i?tr(t):ae(t);if(a&&(c=ut(c,s)),!r&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(t){return Ao(this,t,!0)}cmov(t,r,n){return Rt(n,"condition"),n?r:t}};function vr(e,t={}){return Object.freeze(So.prototype),new So(e,t)}function $u(e){if(typeof e!="bigint")throw new Error("field order must be bigint");if(e<=tt)throw new Error("field order must be greater than 1");let t=Br(e-tt);return Math.ceil(t/8)}function To(e){let t=$u(e);return t+Math.ceil(t/2)}function Bo(e,t,r=!1){J(e);let n=e.length,o=$u(t),i=Math.max(To(t),16);if(n<i||n>1024)throw new Error("expected "+i+"-1024 bytes of input, got "+n);let s=r?tr(e):ae(e),a=ut(s,t-tt)+tt;return r?qs(a,o):Eo(a,o)}var Xs=BigInt(0),Tn=BigInt(1),zp=BigInt(4),Zs=16,qu=128,Hp=5,zu=2**31;function Fe(e){let t=e;if(typeof t!="function")throw new TypeError('"Point" expected constructor, got type='+typeof e);Qe(t.fromAffine,"Point.fromAffine"),Qe(t.fromBytes,"Point.fromBytes"),Qe(t.fromHex,"Point.fromHex"),Re(t.BASE,"Point.BASE"),Re(t.ZERO,"Point.ZERO"),Ir(t.Fp),Ir(t.Fn)}function Io(e,t){Fe(e),ju(t,e);let r=Ao(e.Fp,t.map(n=>n.Z));return t.map((n,o)=>e.fromAffine(n.toAffine(r[o])))}function jp(e,t,r=1){if(!Number.isSafeInteger(e)||e<r||e>t)throw new Error("invalid window size, expected ["+r+".."+t+"], got W="+e)}function Yp(e,t){let r=e*(4*t+128);if(r>zu)throw new Error("invalid window size: table would need ~"+Math.ceil(r/2**20)+" MiB, max "+zu/2**20+" MiB")}function Ws(e,t){if(e!==void 0){Qe(e,"randomBytes");try{let r=e(t);if(!De(r)||r.length!==t)return}catch{return}return e}}function ju(e,t){wo(e,"points"),e.forEach((r,n)=>{if(!(r instanceof t))throw new Error("invalid point at index "+n)})}function Zp(e,t,r){if(!Array.isArray(e))throw new Error("array of scalars expected");e.forEach((n,o)=>{if(!(r===void 0?t.isValid(n):Ne(n)&&n<r))throw new Error("invalid scalar at index "+o)})}var Yu=new WeakMap;function Gs(e){return Yu.get(e)||1}function Gp(e,t){let r=e.double(),n=[e];for(let o=1;o<t;o++)n.push(n[o-1].add(r));return n}function Xp(e,t){let r=2**t,n=r/2,o=BigInt(r-1),i=[];for(;e>Xs;){let s=0;e&Tn&&(s=Number(e&o),s>=n&&(s-=r),e-=BigInt(s)),i.push(s),e>>=Tn}return i}function Wp(e,t,r){let n=2**t,o=n/2,i=BigInt(n-1),s=BigInt(t),a=[];for(let c=0;c<r;c++){let u=Number(e&i);e>>=s,u>o&&(u-=n,e+=Tn),a.push(u)}if(e!==Xs)throw new Error("invalid wnaf");return a}function Qp(e,t,r){let n=0;for(let i of r)n=Math.max(n,i.length);let o=e;for(let i=n-1;i>=0;i--){i!==n-1&&(o=o.double());for(let s=0;s<r.length;s++){let a=r[s][i];if(a){let c=t[s][Math.abs(a)-1>>1];o=o.add(a<0?c.negate():c)}}}return o}var Cr=class{Point;BASE;ZERO;randomBytes;wnafPrecomputes=new WeakMap;baseCanBeBlinded;bits;constructor(t,r){Fe(t),this.randomBytes=Ws(r,Zs),this.Point=t,this.BASE=t.BASE,this.ZERO=t.ZERO,this.bits=t.Fn.BITS}buildWnafTable(t,r,n){let o=Math.ceil(n/r)+1,i=2**(r-1),s=[],a=t;for(let c=0;c<o;c++){let u=a;for(let f=0;f<i;f++)s.push(u),u=u.add(a);a=s[s.length-1].double()}return{W:r,bits:n,windows:o,comp:s}}wnafCachedCT(t,r){let{W:n,windows:o,comp:i}=t,s=2**(n-1),a=Wp(r,n,o),c=this.ZERO,u=this.BASE;for(let f=0;f<o;f++){let l=a[f],h=f*s,m=Math.abs(l)-1,R=i[h];for(let g=1;g<s;g++)R=g===m?i[h+g]:R;let b=R.negate();l===0?u=u.add(i[h]):c=c.add(l<0?b:R)}return{p:c,f:u}}getWnafPrecomputes(t,r,n,o){let i=this.wnafPrecomputes.get(r),s=i?.find(a=>a.W===t&&a.bits===n);return s||(s=this.buildWnafTable(r,t,n),typeof o=="function"&&(s={...s,comp:o(s.comp)}),i||(i=[],this.wnafPrecomputes.set(r,i)),i.push(s)),s}assertPoint(t){if(!(t instanceof this.Point))throw new TypeError('"point" expected Point instance, got type='+typeof t)}validateMulInput(t,r){if(this.assertPoint(t),!zs(r,Tn,this.Point.Fn.ORDER))throw new Error("invalid scalar")}runCT(t,r,n,o){let i=Gs(t);return i===1?this.fixedWindowCT(t,r,n):this.wnafCachedCT(this.getWnafPrecomputes(i,t,n,o),r)}mulCT(t,r,n){return this.validateMulInput(t,r),this.runCT(t,r,this.bits,n)}mulCTBlinded(t,r,n){if(this.validateMulInput(t,r),this.randomBytes===void 0)throw new Error("randomBytes is required for scalar blinding");let o=this.Point.Fn.BITS+qu,i=this.randomBytes(Zs);if(!De(i)||i.length!==Zs)throw new Error("randomBytes returned invalid byte array");i[0]=i[0]&63|128;let s=r+ae(i)*this.Point.Fn.ORDER;return this.runCT(t,s,o,n)}fixedWindowCT(t,r,n){let o=Hp,i=1<<o,s=Sn(o),a=new Array(i);a[0]=this.ZERO;for(let f=1;f<i;f++)a[f]=a[f-1].add(t);let c=Math.ceil(n/o),u=this.ZERO;for(let f=c-1;f>=0;f--){if(f!==c-1)for(let m=0;m<o;m++)u=u.double();let l=Number(r>>BigInt(f*o)&s),h=a[0];for(let m=1;m<i;m++)h=m===l?a[m]:h;u=u.add(h)}return{p:u,f:u}}shouldBlind(t,r){return this.randomBytes===void 0?!1:r===Tn?!0:t!==this.BASE?!1:(this.baseCanBeBlinded===void 0&&(this.baseCanBeBlinded=this.mulUnsafe(this.BASE,this.Point.Fn.ORDER).is0()),this.baseCanBeBlinded)}mulSecret(t,r,n,o){return this.shouldBlind(t,n)?this.mulCTBlinded(t,r,o):this.mulCT(t,r,o)}mulUnsafe(t,r,n){if(this.assertPoint(t),!Ne(r))throw new Error("invalid scalar");let o=Gs(t);if(o===1||r>=this.Point.Fn.ORDER)return vo(this.Point,[t],[r],!0);let i=this.getWnafPrecomputes(o,t,this.bits,n);return this.wnafCachedCT(i,r).p}setWindowSize(t,r){this.assertPoint(t),jp(r,this.bits);let n=Math.ceil((this.bits+qu)/r)+1;Yp(n*2**(r-1),this.Point.Fp.BYTES),Yu.set(t,r),this.wnafPrecomputes.delete(t)}hasWindowSize(t){return Gs(t)!==1}};function vo(e,t,r,n=!1){if(Fe(e),ju(t,e),Rt(n,"allowOversized"),Zp(r,e.Fn,n?e.Fn.ORDER**zp:void 0),t.length!==r.length)throw new Error("arrays of points and scalars must have equal length");let o=t.map(s=>Gp(s,4)),i=r.map(s=>Xp(s,4));return Qp(e.ZERO,o,i)}function Hu(e,t,r){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Ir(t),t}else return vr(e,{isLE:r})}function Co(e,t,r={},n){if(e!=="weierstrass"&&e!=="edwards")throw new Error('expected curve type "weierstrass" or "edwards"');if(n===void 0&&(n=e==="edwards"),!t||typeof t!="object")throw new Error(`expected valid ${e} CURVE object`);Nt(r);for(let c of["p","n","h"]){let u=t[c];if(!(Ne(u)&&u!==Xs))throw new Error(`CURVE.${c} must be positive bigint`)}let o=Hu(t.p,r.Fp,n),i=Hu(t.n,r.Fn,n),a=["Gx","Gy","a",e==="weierstrass"?"b":"d"];for(let c of a)if(!o.isValid(t[c]))throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:o,Fn:i}}function _o(e,t){return function(n){let o=e(n);return{secretKey:o,publicKey:t(o)}}}var Ro=BigInt(0),No=BigInt(1),Do=BigInt(2),Jp=BigInt(4),Zu=BigInt(8);function t0(e,t,r,n){let o=e.sqr(r),i=e.sqr(n),s=e.add(e.mul(t.a,o),i),a=e.add(e.ONE,e.mul(t.d,e.mul(o,i)));return e.eql(s,a)}function Gu(e,t={}){Nt(t,{},{},"extraOpts");let r=t,n=Co("edwards",e,r,r.FpFnLE),{Fp:o,Fn:i}=n,s=n.CURVE,{h:a}=s;if(An(o,s.a)!==1)throw new Error("edwards: CURVE.a must be a square in Fp for complete addition formulas");if(An(o,s.d)!==-1)throw new Error("edwards: CURVE.d must be a non-square in Fp for complete addition formulas");Nt(r,{},{uvRatio:"function",randomBytes:"function"});let c=r.randomBytes===void 0?Je:r.randomBytes,u=Do<<BigInt(o.BYTES*8)-No;function f(B){if(!o.isOdd)throw new Error("Field does not have .isOdd()");return o.isOdd(B)}let l=r.uvRatio===void 0?(B,y)=>{try{return{isValid:!0,value:o.sqrt(o.div(B,y))}}catch{return{isValid:!1,value:Ro}}}:r.uvRatio;if(!t0(o,s,s.Gx,s.Gy))throw new Error("bad curve params: generator point");let h=o.eql(s.a,o.neg(o.ONE))?B=>o.neg(B):o.eql(s.a,o.ONE)?B=>B:B=>o.mul(s.a,B);function m(B,y,N=!1){let C=N?No:Ro;return Tr("coordinate "+B,y,C,u),y}function R(B){if(!(B instanceof b))throw new Error("EdwardsPoint expected")}class b{static BASE=new b(s.Gx,s.Gy,o.ONE,o.mul(s.Gx,s.Gy));static ZERO=new b(o.ZERO,o.ONE,o.ONE,o.ZERO);static Fp=o;static Fn=i;X;Y;Z;T;constructor(y,N,C,$){this.X=m("x",y),this.Y=m("y",N),this.Z=m("z",C,!0),this.T=m("t",$),Object.freeze(this)}static CURVE(){return s}static fromAffine(y){if(y instanceof b)throw new Error("extended point not allowed");let{x:N,y:C}=y||{};return m("x",N),m("y",C),new b(N,C,o.ONE,o.mul(N,C))}static fromBytes(y,N=!1){let C=o.BYTES,{a:$,d:q}=s;y=En(J(y,C,"point")),Rt(N,"zip215");let w=En(y),E=y[C-1];w[C-1]=E&-129;let A=tr(w),L=N?u:o.ORDER;Tr("point.y",A,Ro,L);let D=o.sqr(A),z=o.sub(D,o.ONE),I=o.sub(o.mulN(q,D),$),{isValid:F,value:O}=l(z,I);if(!F)throw new Error("bad point: invalid y coordinate");let P=f(O),Y=(E&128)!==0;if(!N&&o.is0(O)&&Y)throw new Error("bad point: x=0 and x_0=1");return Y!==P&&(O=o.neg(O)),b.fromAffine({x:O,y:A})}static fromHex(y,N=!1){return b.fromBytes(Ar(y),N)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(y=6,N=!0){return S.setWindowSize(this,y),N||this.multiply(Do),this}assertValidity(){let y=this,{a:N,d:C}=s;if(y.is0())throw new Error("bad point: ZERO");let{X:$,Y:q,Z:w,T:E}=y,A=o.sqr($),L=o.sqr(q),D=o.sqr(w),z=o.sqr(D),I=o.mul(A,N),F=o.mul(o.add(I,L),D),O=o.add(z,o.mul(C,o.mul(A,L)));if(!o.eql(F,O))throw new Error("bad point: equation left != right (1)");let P=o.mul($,q),Y=o.mul(w,E);if(!o.eql(P,Y))throw new Error("bad point: equation left != right (2)")}equals(y){R(y);let{X:N,Y:C,Z:$}=this,{X:q,Y:w,Z:E}=y,A=o.mul(N,E),L=o.mul(q,$),D=o.mul(C,E),z=o.mul(w,$);return o.eql(A,L)&&o.eql(D,z)}is0(){return this.equals(b.ZERO)}negate(){return new b(o.neg(this.X),this.Y,this.Z,o.neg(this.T))}double(){let{X:y,Y:N,Z:C}=this,$=o.sqr(y),q=o.sqr(N),w=o.mul(o.sqr(C),Do),E=h($),A=o.addN(y,N),L=o.sub(o.subN(o.sqr(A),$),q),D=o.addN(E,q),z=o.subN(D,w),I=o.subN(E,q),F=o.mul(L,z),O=o.mul(D,I),P=o.mul(L,I),Y=o.mul(z,D);return new b(F,O,Y,P)}add(y){R(y);let{d:N}=s,{X:C,Y:$,Z:q,T:w}=this,{X:E,Y:A,Z:L,T:D}=y,z=o.mul(C,E),I=o.mul($,A),F=o.mul(o.mulN(w,N),D),O=o.mul(q,L),P=o.sub(o.subN(o.mulN(o.addN(C,$),o.addN(E,A)),z),I),Y=o.subN(O,F),W=o.addN(O,F),k=o.sub(I,h(z)),p=o.mul(P,Y),x=o.mul(W,k),T=o.mul(P,k),U=o.mul(Y,W);return new b(p,x,U,T)}subtract(y){return R(y),this.add(y.negate())}multiply(y){if(!i.isValidNot0(y))throw new RangeError("invalid scalar: expected 1 <= sc < curve.n");let{p:N,f:C}=S.mulSecret(this,y,a,g);return g([N,C])[0]}multiplyUnsafe(y){if(!i.isValid(y))throw new RangeError("invalid scalar: expected 0 <= sc < curve.n");return y===Ro?b.ZERO:this.is0()||y===No?this:S.mulUnsafe(this,y,g)}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){return S.mulUnsafe(this,s.n).is0()}toAffine(y){let N=this,C=y;if(C!=null&&typeof C!="bigint")throw new TypeError('"invertedZ" expected bigint, got type='+typeof C);let{X:$,Y:q,Z:w}=N,E=N.is0();C==null&&(C=E?o.create(Zu):o.inv(w));let A=o.mul($,C),L=o.mul(q,C),D=o.mul(w,C);if(E)return{x:o.ZERO,y:o.ONE};if(!o.eql(D,o.ONE))throw new Error("invZ was invalid");return{x:A,y:L}}clearCofactor(){return a===No?this:a===Do?this.double():a===Jp?this.double().double():a===Zu?this.double().double().double():this.multiplyUnsafe(a)}toBytes(){let{x:y,y:N}=this.toAffine(),C=o.toBytes(N);return C[C.length-1]|=f(y)?128:0,C}toHex(){return wn(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let g=B=>Io(b,B),S=new Cr(b,c);return S.bits>=6&&b.BASE.precompute(6),Object.freeze(b.prototype),Object.freeze(b),b}function Xu(e,t,r={}){if(Fe(e),typeof t!="function")throw new Error('"hash" function param is required');let n=t,o=r;Nt(o,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",zip215:"boolean",mapToCurve:"function",toMontgomery:"function",toMontgomerySecret:"function"});let{prehash:i}=o,{BASE:s,Fp:a,Fn:c}=e,u=n.outputLen,f=2*a.BYTES;if(u!==void 0&&(pe(u,"hash.outputLen"),u!==f))throw new Error(`hash.outputLen must be ${f}, got ${u}`);let l=o.randomBytes===void 0?Je:o.randomBytes,h=o.toMontgomery,m=o.toMontgomerySecret,R=o.adjustScalarBytes===void 0?I=>I:o.adjustScalarBytes,b=o.domain===void 0?(I,F,O)=>{if(Rt(O,"phflag"),F.length||O)throw new Error("Contexts/pre-hash are not supported");return I}:o.domain;function g(I){return c.create(tr(I))}function S(I){let F=E.secretKey;J(I,E.secretKey,"secretKey");let O=J(n(I),2*F,"hashedSecretKey"),P=R(O.slice(0,F)),Y=O.slice(F,2*F),W=g(P);return{head:P,prefix:Y,scalar:W}}function B(I){let{head:F,prefix:O,scalar:P}=S(I),Y=s.multiply(P),W=Y.toBytes();return{head:F,prefix:O,scalar:P,point:Y,pointBytes:W}}function y(I){return B(I).pointBytes}function N(I=Uint8Array.of(),...F){let O=Zt(...F);return g(n(b(O,J(I,void 0,"context"),!!i)))}function C(I,F,O={}){Nt(O,{},{},"options"),I=En(J(I,void 0,"message")),i&&(I=i(I));let{prefix:P,scalar:Y,pointBytes:W}=B(F),k=N(O.context,P,I),p=s.multiply(k).toBytes(),x=N(O.context,p,W,I),T=c.create(k+x*Y);if(!c.isValid(T))throw new Error("sign failed: invalid s");let U=Zt(p,c.toBytes(T));return J(U,E.signature,"result")}let $={zip215:o.zip215};function q(I,F,O,P=$){Nt(P);let{context:Y}=P,W=P.zip215===void 0?!!$.zip215:P.zip215,k=E.signature;I=J(I,k,"signature"),F=J(F,void 0,"message"),O=J(O,E.publicKey,"publicKey"),W!==void 0&&Rt(W,"zip215"),i&&(F=i(F));let p=k/2,x=I.subarray(0,p),T=tr(I.subarray(p,k)),U,M,K;try{U=e.fromBytes(O,W),M=e.fromBytes(x,W),K=s.multiplyUnsafe(T)}catch{return!1}if(!W&&U.isSmallOrder())return!1;let H=N(Y,x,O,F);return M.add(U.multiplyUnsafe(H)).subtract(K).clearCofactor().is0()}let w=a.BYTES,E={secretKey:w,publicKey:w,signature:2*w,seed:w};function A(I){return I=I===void 0?l(E.seed):I,J(I,E.seed,"seed")}function L(I){return De(I)&&I.length===E.secretKey}function D(I,F){try{return!!e.fromBytes(I,F===void 0?$.zip215:F)}catch{return!1}}let z={getExtendedPublicKey:B,randomSecretKey:A,isValidSecretKey:L,isValidPublicKey:D,toMontgomery(I){if(h===void 0)throw new Error("Montgomery conversion is not supported for this curve");return h(e.fromBytes(I))},toMontgomerySecret(I){if(m===void 0)throw new Error("Montgomery conversion is not supported for this curve");return m(I)}};return Object.freeze(E),Object.freeze(z),Object.freeze({keygen:_o(A,y),getPublicKey:y,sign:C,verify:q,utils:z,Point:e,lengths:E})}var Qs=BigInt(1),Wu=BigInt(2);var e0=BigInt(5),r0=BigInt(8),Js=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),n0={p:Js,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:r0,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function o0(e){let t=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),i=Js,a=e*e%i*e%i,c=st(a,Wu,i)*a%i,u=st(c,Qs,i)*e%i,f=st(u,e0,i)*u%i,l=st(f,t,i)*f%i,h=st(l,r,i)*l%i,m=st(h,n,i)*h%i,R=st(m,o,i)*m%i,b=st(R,o,i)*m%i,g=st(b,t,i)*f%i;return{pow_p_5_8:st(g,Wu,i)*e%i,b2:a}}function tf(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}var Qu=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function i0(e,t){let r=Js,n=ut(t*t*t,r),o=ut(n*n*t,r),i=o0(e*o).pow_p_5_8,s=ut(e*n*i,r),a=ut(t*s*s,r),c=s,u=ut(s*Qu,r),f=a===e,l=a===ut(-e,r),h=a===ut(-e*Qu,r);return f&&(s=c),(l||h)&&(s=u),Vu(s,r)&&(s=ut(-s,r)),{isValid:f||l,value:s}}var ta=Gu(n0,{uvRatio:i0}),Ju=ta.Fp;function s0(e){let{y:t}=e;return Ju.toBytes(Ju.div(Qs+t,Qs-t))}function a0(e){let t=ta.Fp.BYTES;return Yt(e,t),tf(Vs(e.subarray(0,t))).subarray(0,t)}function c0(e){return Xu(ta,Vs,Object.assign({adjustScalarBytes:tf,toMontgomery:s0,toMontgomerySecret:a0,zip215:!0},e))}var ef=c0({});var Bn=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},Lo=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var Fo={get(e=globalThis){let t=e.crypto;if(t?.subtle==null)throw new Lo("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api");return t}};var ko=32;var ea,u0=(async()=>{try{return await Fo.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function f0(e,t,r){if(e.buffer instanceof ArrayBuffer){let n=await Fo.get().subtle.importKey("raw",e.buffer,{name:"Ed25519"},!1,["verify"]);return await Fo.get().subtle.verify({name:"Ed25519"},n,xt(t),xt(r instanceof Uint8Array?r:r.subarray()))}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function l0(e,t,r){return ef.verify(t,r instanceof Uint8Array?r:r.subarray(),e)}async function rf(e,t,r){return ea==null&&(ea=await u0),ea?f0(e,t,r):l0(e,t,r)}function Uo(e){return e==null?!1:typeof e.then=="function"&&typeof e.catch=="function"&&typeof e.finally=="function"}var Oo=class{type="Ed25519";raw;constructor(t){this.raw=ra(t,ko)}toMultihash(){return te.digest(Er(this))}toCID(){return at.createV1(114,this.toMultihash())}toString(){return rt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ht(this.raw,t.raw)}verify(t,r,n){n?.signal?.throwIfAborted();let o=rf(this.raw,r,t);return Uo(o)?o.then(i=>(n?.signal?.throwIfAborted(),i)):o}};function of(e){return e=ra(e,ko),new Oo(e)}function ra(e,t){if(e=Uint8Array.from(e??[]),e.length!==t)throw new de(`Key must be a Uint8Array of length ${t}, got ${e.length}`);return e}var na=new Float32Array([-0]),ke=new Uint8Array(na.buffer);function sf(e,t,r){na[0]=e,t[r]=ke[0],t[r+1]=ke[1],t[r+2]=ke[2],t[r+3]=ke[3]}function af(e,t){return ke[0]=e[t],ke[1]=e[t+1],ke[2]=e[t+2],ke[3]=e[t+3],na[0]}var oa=new Float64Array([-0]),At=new Uint8Array(oa.buffer);function cf(e,t,r){oa[0]=e,t[r]=At[0],t[r+1]=At[1],t[r+2]=At[2],t[r+3]=At[3],t[r+4]=At[4],t[r+5]=At[5],t[r+6]=At[6],t[r+7]=At[7]}function uf(e,t){return At[0]=e[t],At[1]=e[t+1],At[2]=e[t+2],At[3]=e[t+3],At[4]=e[t+4],At[5]=e[t+5],At[6]=e[t+6],At[7]=e[t+7],oa[0]}var h0=BigInt(Number.MAX_SAFE_INTEGER),p0=BigInt(Number.MIN_SAFE_INTEGER),Ut=class e{lo;hi;constructor(t,r){this.lo=t|0,this.hi=r|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(r+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(BigInt(r)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?t<16384?t<128?1:2:t<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return er;if(t<h0&&t>p0)return this.fromNumber(Number(t));let r=t<0n;r&&(t=-t);let n=t>>32n,o=t-(n<<32n);return r&&(n=~n|0n,o=~o|0n,++o>ff&&(o=0n,++n>ff&&(n=0n))),new e(Number(o),Number(n))}static fromNumber(t){if(t===0)return er;let r=t<0;r&&(t=-t);let n=t>>>0,o=(t-n)/4294967296>>>0;return r&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new e(n,o)}static from(t){return typeof t=="number"?e.fromNumber(t):typeof t=="bigint"?e.fromBigInt(t):typeof t=="string"?e.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new e(t.low>>>0,t.high>>>0):er}},er=new Ut(0,0);er.toBigInt=function(){return 0n};er.zzEncode=er.zzDecode=function(){return this};er.length=function(){return 1};var ff=4294967296n;function lf(e){let t=0,r=0;for(let n=0;n<e.length;++n)r=e.charCodeAt(n),r<128?t+=1:r<2048?t+=2:(r&64512)===55296&&(e.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function df(e,t,r){if(r-t<1)return"";let o,i=[],s=0,a;for(;t<r;)a=e[t++],a<128?i[s++]=a:a>191&&a<224?i[s++]=(a&31)<<6|e[t++]&63:a>239&&a<365?(a=((a&7)<<18|(e[t++]&63)<<12|(e[t++]&63)<<6|e[t++]&63)-65536,i[s++]=55296+(a>>10),i[s++]=56320+(a&1023)):i[s++]=(a&15)<<12|(e[t++]&63)<<6|e[t++]&63,s>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,i)),s=0);return o!=null?(s>0&&o.push(String.fromCharCode.apply(String,i.slice(0,s))),o.join("")):String.fromCharCode.apply(String,i.slice(0,s))}function ia(e,t,r){let n=r,o,i;for(let s=0;s<e.length;++s)o=e.charCodeAt(s),o<128?t[r++]=o:o<2048?(t[r++]=o>>6|192,t[r++]=o&63|128):(o&64512)===55296&&((i=e.charCodeAt(s+1))&64512)===56320?(o=65536+((o&1023)<<10)+(i&1023),++s,t[r++]=o>>18|240,t[r++]=o>>12&63|128,t[r++]=o>>6&63|128,t[r++]=o&63|128):(t[r++]=o>>12|224,t[r++]=o>>6&63|128,t[r++]=o&63|128);return r-n}function re(e,t){return RangeError(`index out of range: ${e.pos} + ${t??1} > ${e.len}`)}function Po(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}var sa=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=xt(t),this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,re(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw re(this,4);return Po(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw re(this,4);return Po(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw re(this,4);let t=af(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw re(this,4);let t=uf(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),r=this.pos,n=this.pos+t;if(n>this.len)throw re(this,t);return this.pos+=t,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let t=this.bytes();return df(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw re(this,t);this.pos+=t}else do if(this.pos>=this.len)throw re(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new Ut(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw re(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<r*7)>>>0,t}if(this.len-this.pos>4){for(;r<5;++r)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;r<5;++r){if(this.pos>=this.len)throw re(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw re(this,8);let t=Po(this.buf,this.pos+=4),r=Po(this.buf,this.pos+=4);return new Ut(t,r)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=br(this.buf,this.pos);return this.pos+=Lt(t),t}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function In(e){return new sa(e instanceof Uint8Array?e:e.subarray())}function Mo(e,t,r){let n=In(e);return t.decode(n,void 0,r)}function aa(e){let t=e??8192,r=t>>>1,n,o=t;return function(s){if(s<1||s>r)return ct(s);o+s>t&&(n=ct(t),o=0);let a=n.subarray(o,o+=s);return(o&7)!==0&&(o=(o|7)+1),a}}var rr=class{fn;len;next;val;constructor(t,r,n){this.fn=t,this.len=r,this.next=void 0,this.val=n}};function ca(){}var fa=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},m0=aa();function g0(e){return globalThis.Buffer!=null?ct(e):m0(e)}var Cn=class{len;head;tail;states;constructor(){this.len=0,this.head=new rr(ca,0,0),this.tail=this.head,this.states=null}_push(t,r,n){return this.tail=this.tail.next=new rr(t,r,n),this.len+=r,this}uint32(t){return this.len+=(this.tail=this.tail.next=new la((t=t>>>0)<128?1:t<16384?2:t<2097152?3:t<268435456?4:5,t)).len,this}int32(t){return t<0?this._push(Ko,10,Ut.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let r=Ut.fromBigInt(t);return this._push(Ko,r.length(),r)}uint64Number(t){return this._push(yr,Lt(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let r=Ut.fromBigInt(t).zzEncode();return this._push(Ko,r.length(),r)}sint64Number(t){let r=Ut.fromNumber(t).zzEncode();return this._push(Ko,r.length(),r)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(ua,1,t?1:0)}fixed32(t){return this._push(vn,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let r=Ut.fromBigInt(t);return this._push(vn,4,r.lo)._push(vn,4,r.hi)}fixed64Number(t){let r=Ut.fromNumber(t);return this._push(vn,4,r.lo)._push(vn,4,r.hi)}fixed64String(t){return this.fixed64(BigInt(t))}sfixed64(t){return this.fixed64(t)}sfixed64Number(t){return this.fixed64Number(t)}sfixed64String(t){return this.fixed64String(t)}float(t){return this._push(sf,4,t)}double(t){return this._push(cf,8,t)}bytes(t){let r=t.length>>>0;return r===0?this._push(ua,1,0):this.uint32(r)._push(b0,r,t)}string(t){let r=lf(t);return r!==0?this.uint32(r)._push(ia,r,t):this._push(ua,1,0)}fork(){return this.states=new fa(this),this.head=this.tail=new rr(ca,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new rr(ca,0,0),this.len=0),this}ldelim(){let t=this.head,r=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=r,this.len+=n),this}finish(){let t=this.head.next,r=g0(this.len),n=0;for(;t!=null;)t.fn(t.val,r,n),n+=t.len,t=t.next;return r}};function ua(e,t,r){t[r]=e&255}function y0(e,t,r){for(;e>127;)t[r++]=e&127|128,e>>>=7;t[r]=e}var la=class extends rr{next;constructor(t,r){super(y0,t,r),this.next=void 0}};function Ko(e,t,r){for(;e.hi!==0;)t[r++]=e.lo&127|128,e.lo=(e.lo>>>7|e.hi<<25)>>>0,e.hi>>>=7;for(;e.lo>127;)t[r++]=e.lo&127|128,e.lo=e.lo>>>7;t[r++]=e.lo}function vn(e,t,r){t[r]=e&255,t[r+1]=e>>>8&255,t[r+2]=e>>>16&255,t[r+3]=e>>>24}function b0(e,t,r){t.set(e,r)}globalThis.Buffer!=null&&(Cn.prototype.bytes=function(e){let t=e.length>>>0;return this.uint32(t),t>0&&this._push(w0,t,e),this},Cn.prototype.string=function(e){let t=globalThis.Buffer.byteLength(e);return this.uint32(t),t>0&&this._push(x0,t,e),this});function w0(e,t,r){t.set(e,r)}function x0(e,t,r){e.length<40?ia(e,t,r):t.utf8Write!=null?t.utf8Write(e,r):t.set(nt(e),r)}function da(){return new Cn}function Vo(e,t){let r=da();return t.encode(e,r,{lengthDelimited:!1}),r.finish()}function*$o(e,t,r){let n=In(e);yield*t.stream(n,void 0,".",r)}var qo={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function zo(e,t,r,n,o){return{name:e,type:t,encode:r,decode:n,stream:o}}function ha(e){function t(i){if(e[i.toString()]==null)throw new Error("Invalid enum value");return e[i]}let r=function(s,a){let c=t(s);a.int32(c)},n=function(s){let a=s.int32();return t(a)},o=function*(s,a){};return zo("enum",qo.VARINT,r,n,o)}function Ho(e,t,r){return zo("message",qo.LENGTH_DELIMITED,e,t,r)}var vt;(function(e){e.RSA="RSA",e.Ed25519="Ed25519",e.secp256k1="secp256k1",e.ECDSA="ECDSA"})(vt||(vt={}));var pa;(function(e){e[e.RSA=0]="RSA",e[e.Ed25519=1]="Ed25519",e[e.secp256k1=2]="secp256k1",e[e.ECDSA=3]="ECDSA"})(pa||(pa={}));(function(e){e.codec=()=>ha(pa)})(vt||(vt={}));var _n;(function(e){let t;e.codec=()=>(t==null&&(t=Ho((i,s,a={})=>{a.lengthDelimited!==!1&&s.fork(),i.Type!=null&&(s.uint32(8),vt.codec().encode(i.Type,s)),i.Data!=null&&(s.uint32(18),s.bytes(i.Data)),a.lengthDelimited!==!1&&s.ldelim()},(i,s,a={})=>{let c={},u=s==null?i.len:i.pos+s;for(;i.pos<u;){let f=i.uint32();switch(f>>>3){case 1:{c.Type=vt.codec().decode(i);break}case 2:{c.Data=i.bytes();break}default:{i.skipType(f&7);break}}}return c},function*(i,s,a,c={}){let u=s==null?i.len:i.pos+s;for(;i.pos<u;){let f=i.uint32();switch(f>>>3){case 1:{yield{field:`${a}.Type`,value:vt.codec().decode(i)};break}case 2:{yield{field:`${a}.Data`,value:i.bytes()};break}default:{i.skipType(f&7);break}}}})),t);function r(i){return Vo(i,e.codec())}e.encode=r;function n(i,s){return Mo(i,e.codec(),s)}e.decode=n;function o(i,s){return $o(i,e.codec(),s)}e.stream=o})(_n||(_n={}));var ma;(function(e){let t;e.codec=()=>(t==null&&(t=Ho((i,s,a={})=>{a.lengthDelimited!==!1&&s.fork(),i.Type!=null&&(s.uint32(8),vt.codec().encode(i.Type,s)),i.Data!=null&&(s.uint32(18),s.bytes(i.Data)),a.lengthDelimited!==!1&&s.ldelim()},(i,s,a={})=>{let c={},u=s==null?i.len:i.pos+s;for(;i.pos<u;){let f=i.uint32();switch(f>>>3){case 1:{c.Type=vt.codec().decode(i);break}case 2:{c.Data=i.bytes();break}default:{i.skipType(f&7);break}}}return c},function*(i,s,a,c={}){let u=s==null?i.len:i.pos+s;for(;i.pos<u;){let f=i.uint32();switch(f>>>3){case 1:{yield{field:`${a}.Type`,value:vt.codec().decode(i)};break}case 2:{yield{field:`${a}.Data`,value:i.bytes()};break}default:{i.skipType(f&7);break}}}})),t);function r(i){return Vo(i,e.codec())}e.encode=r;function n(i,s){return Mo(i,e.codec(),s)}e.decode=n;function o(i,s){return $o(i,e.codec(),s)}e.stream=o})(ma||(ma={}));var jo=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(t,r){if(ho(t),Yt(r,void 0,"key"),this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("expected Hash instance");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,o=new Uint8Array(n);o.set(r.length>n?t.create().update(r).digest():r);for(let i=0;i<o.length;i++)o[i]^=54;this.iHash.update(o),this.oHash=t.create();for(let i=0;i<o.length;i++)o[i]^=106;this.oHash.update(o),We(o)}update(t){return Sr(this),this.iHash.update(t),this}digestInto(t){Sr(this),po(t,this),this.finished=!0;let r=t.subarray(0,this.outputLen);this.iHash.digestInto(r),this.oHash.update(r),this.oHash.digestInto(r),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||=Object.create(Object.getPrototypeOf(this),{});let{oHash:r,iHash:n,finished:o,destroyed:i,blockLen:s,outputLen:a,canXOF:c}=this;return t=t,t.finished=o,t.destroyed=i,t.blockLen=s,t.outputLen=a,t.canXOF=c,t.oHash=r._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},pf=(()=>{let e=((t,r,n)=>new jo(t,r).update(n).digest());return e.create=(t,r)=>new jo(t,r),e})();var S0=BigInt(0),ga=class extends Error{constructor(t=""){super(t)}},me={Err:ga,_tlv:{encode:(e,t)=>{let{Err:r}=me;if(pe(e,"tag"),e<0||e>255)throw new r("tlv.encode: wrong tag");if(Cu(t,"data"),t.length&1)throw new r("tlv.encode: unpadded data");let n=t.length/2,o=xn(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let i=n>127?xn(o.length/2|128):"";return xn(e)+i+o+t},decode(e,t){let{Err:r}=me;t=J(t,void 0,"DER data");let n=0;if(e<0||e>255)throw new r("tlv.decode: wrong tag");if(t.length<2||t[n++]!==e)throw new r("tlv.decode: wrong tlv");let o=t[n++],i=!!(o&128),s=0;if(!i)s=o;else{let c=o&127;if(!c)throw new r("tlv.decode(long): indefinite length not supported");if(c>4)throw new r("tlv.decode(long): byte length is too big");let u=t.subarray(n,n+c);if(u.length!==c)throw new r("tlv.decode: length bytes not complete");if(u[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let f of u)s=s<<8|f;if(n+=c,s<128)throw new r("tlv.decode(long): not minimal encoding")}let a=t.subarray(n,n+s);if(a.length!==s)throw new r("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+s)}}},_int:{encode(e){let{Err:t}=me;if(xo(e),e<S0)throw new t("integer: negative integers are not allowed");let r=xn(e);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new t("unexpected DER parsing assertion: unpadded hex");return r},decode(e){let{Err:t}=me;if(e.length<1)throw new t("invalid signature integer: empty");if(e[0]&128)throw new t("invalid signature integer: negative");if(e.length>1&&e[0]===0&&!(e[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return ae(e)}},toSig(e,t){let{Err:r,_int:n,_tlv:o}=me;if(t!==void 0&&(pe(t,"maxScalarBytes"),t<1))throw new r("invalid signature: maxScalarBytes must be positive");let i=J(e,void 0,"signature"),{v:s,l:a}=o.decode(48,i);if(a.length)throw new r("invalid signature: left bytes after parsing");let{v:c,l:u}=o.decode(2,s),{v:f,l}=o.decode(2,u);if(l.length)throw new r("invalid signature: left bytes after parsing");if(t!==void 0&&(c.length>t||f.length>t))throw new r("invalid signature: integer too large");return{r:n.decode(c),s:n.decode(f)}},hexFromSig(e){let{_tlv:t,_int:r}=me;Nt(e,{r:"bigint",s:"bigint"},{},"sig");let n=t.encode(2,r.encode(e.r)),o=t.encode(2,r.encode(e.s)),i=n+o;return t.encode(48,i)}},Yo=(Object.freeze(me._tlv),Object.freeze(me._int),Object.freeze(me));var mf=(e,t)=>(e+(e>=0?t:-t)/gf)/t;function A0(e,t,r){Tr("scalar",e,ge,r);let[[n,o],[i,s]]=t,a=mf(s*e,r),c=mf(-o*e,r),u=e-a*n-c*i,f=-a*o-c*s,l=u<ge,h=f<ge;l&&(u=-u),h&&(f=-f);let m=Sn(Math.ceil(Br(r)/2))+nr;if(u<ge||u>=m||f<ge||f>=m)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:l,k1:u,k2neg:h,k2:f}}function wa(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function ya(e,t){Nt(e);let r={};for(let n of Object.keys(t))r[n]=e[n]===void 0?t[n]:e[n];return Rt(r.lowS,"lowS"),Rt(r.prehash,"prehash"),r.format!==void 0&&wa(r.format),r}var ge=BigInt(0),nr=BigInt(1),gf=BigInt(2),ba=BigInt(3),T0=BigInt(4);function yf(e,t={}){let r=Co("weierstrass",e,t),n=r.Fp,o=r.Fn,i=r.CURVE,{h:s,n:a}=i;Nt(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",randomBytes:"function"});let{endo:c,allowInfinityPoint:u,clearCofactor:f,isTorsionFree:l,fromBytes:h,toBytes:m}=t,R=t.randomBytes===void 0?Je:t.randomBytes;if(c&&(!n.is0(i.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let b=c?{beta:c.beta,basises:c.basises.map(k=>[...k])}:void 0,g=wf(n,o);function S(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function B(k,p,x){if(p.is0()){if(!u)throw new Error("bad point: ZERO");return Uint8Array.of(0)}let{x:T,y:U}=p.toAffine(),M=n.toBytes(T);if(Rt(x,"isCompressed"),x){S();let K=!n.isOdd(U);return Zt(bf(K),M)}else return Zt(Uint8Array.of(4),M,n.toBytes(U))}function y(k){J(k,void 0,"Point");let{publicKey:p,publicKeyUncompressed:x}=g,T=k.length,U=k[0],M=k.subarray(1);if(u&&T===1&&U===0)return{x:n.ZERO,y:n.ZERO};if(T===p&&(U===2||U===3)){let K=n.fromBytes(M);if(!n.isValid(K))throw new Error("bad point: is not on curve, wrong x");let H=w(K),j;try{j=n.sqrt(H)}catch(lt){let ot=lt instanceof Error?": "+lt.message:"";throw new Error("bad point: is not on curve, sqrt error"+ot)}S();let X=n.isOdd(j);return(U&1)===1!==X&&(j=n.neg(j)),{x:K,y:j}}else if(T===x&&U===4){let K=n.BYTES,H=n.fromBytes(M.subarray(0,K)),j=n.fromBytes(M.subarray(K,K*2));if(!E(H,j))throw new Error("bad point: is not on curve");return{x:H,y:j}}else throw new Error(`bad point: got length ${T}, expected compressed=${p} or uncompressed=${x}`)}let N=m===void 0?B:m,C=h===void 0?y:h,$=n.mul(i.b,ba),q=n.is0(i.a)?k=>n.ZERO:k=>n.mul(i.a,k);function w(k){let p=n.sqr(k),x=n.mul(p,k);return n.add(n.add(x,n.mul(k,i.a)),i.b)}function E(k,p){let x=n.sqr(p),T=w(k);return n.eql(x,T)}if(!E(i.Gx,i.Gy))throw new Error("bad curve params: generator point");let A=n.mul(n.pow(i.a,ba),T0),L=n.mul(n.sqr(i.b),BigInt(27));if(n.is0(n.add(A,L)))throw new Error("bad curve params: a or b");function D(k,p,x=!1){if(!n.isValid(p)||x&&n.is0(p))throw new Error(`bad point coordinate ${k}`);return typeof p=="object"&&p!==null?n.create(p):p}function z(k){if(!(k instanceof P))throw new Error("Weierstrass Point expected")}function I(k){if(!b||!b.basises)throw new Error("no endo");return A0(k,b.basises,o.ORDER)}function F(k,p,x,T){if(!o.isValid(T))throw new RangeError("invalid scalar: out of range");if(b){let{k1neg:U,k1:M,k2neg:K,k2:H}=I(T),j=new P(n.mul(x.X,b.beta),x.Y,x.Z);k.push(U?x.negate():x,K?j.negate():j),p.push(M,H)}else k.push(x),p.push(T)}let O=new WeakSet;class P{static BASE=new P(i.Gx,i.Gy,n.ONE);static ZERO=new P(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(p,x,T){this.X=D("x",p),this.Y=D("y",x,!0),this.Z=D("z",T),Object.freeze(this)}static CURVE(){return i}static fromAffine(p){let{x,y:T}=p||{};if(!p||!n.isValid(x)||!n.isValid(T))throw new Error("invalid affine point");if(p instanceof P)throw new Error("projective point not allowed");return n.is0(x)&&n.is0(T)?P.ZERO:new P(x,T,n.ONE)}static fromBytes(p){let x=P.fromAffine(C(J(p,void 0,"point")));return x.assertValidity(),x}static fromHex(p){return P.fromBytes(Ar(p))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(p=6,x=!0){return W.setWindowSize(this,p),x||this.multiply(ba),this}assertValidity(){let p=this;if(p.is0()){if(u&&n.is0(p.X)&&n.eql(p.Y,n.ONE)&&n.is0(p.Z))return;throw new Error("bad point: ZERO")}if(O.has(p))return;let{x,y:T}=p.toAffine();if(!n.isValid(x)||!n.isValid(T))throw new Error("bad point: x or y not field elements");if(!E(x,T))throw new Error("bad point: equation left != right");if(!p.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");O.add(p)}hasEvenY(){let{y:p}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(p)}equals(p){z(p);let{X:x,Y:T,Z:U}=this,{X:M,Y:K,Z:H}=p,j=n.eql(n.mul(x,H),n.mul(M,U)),X=n.eql(n.mul(T,H),n.mul(K,U));return j&&X}negate(){return new P(this.X,n.neg(this.Y),this.Z)}double(){let{X:p,Y:x,Z:T}=this,U=n.ZERO,M=n.ZERO,K=n.ZERO,H=n.mul(p,p),j=n.mul(x,x),X=n.mul(T,T),Z=n.mul(p,x);return Z=n.add(Z,Z),K=n.mul(p,T),K=n.add(K,K),U=q(K),M=n.mul($,X),M=n.add(U,M),U=n.sub(j,M),M=n.add(j,M),M=n.mul(U,M),U=n.mul(Z,U),K=n.mul($,K),X=q(X),Z=n.sub(H,X),Z=q(Z),Z=n.add(Z,K),K=n.add(H,H),H=n.add(K,H),H=n.add(H,X),H=n.mul(H,Z),M=n.add(M,H),X=n.mul(x,T),X=n.add(X,X),H=n.mul(X,Z),U=n.sub(U,H),K=n.mul(X,j),K=n.add(K,K),K=n.add(K,K),new P(U,M,K)}add(p){z(p);let{X:x,Y:T,Z:U}=this,{X:M,Y:K,Z:H}=p,j=n.ZERO,X=n.ZERO,Z=n.ZERO,lt=n.mul(x,M),ot=n.mul(T,K),wt=n.mul(U,H),qt=n.add(x,T),it=n.add(M,K);qt=n.mul(qt,it),it=n.add(lt,ot),qt=n.sub(qt,it),it=n.add(x,U);let dt=n.add(M,H);return it=n.mul(it,dt),dt=n.add(lt,wt),it=n.sub(it,dt),dt=n.add(T,U),j=n.add(K,H),dt=n.mul(dt,j),j=n.add(ot,wt),dt=n.sub(dt,j),Z=q(it),j=n.mul($,wt),Z=n.add(j,Z),j=n.sub(ot,Z),Z=n.add(ot,Z),X=n.mul(j,Z),ot=n.add(lt,lt),ot=n.add(ot,lt),wt=q(wt),it=n.mul($,it),ot=n.add(ot,wt),wt=n.sub(lt,wt),wt=q(wt),it=n.add(it,wt),lt=n.mul(ot,it),X=n.add(X,lt),lt=n.mul(dt,it),j=n.mul(qt,j),j=n.sub(j,lt),lt=n.mul(qt,ot),Z=n.mul(dt,Z),Z=n.add(Z,lt),new P(j,X,Z)}subtract(p){return z(p),this.add(p.negate())}is0(){return this.equals(P.ZERO)}multiply(p){if(!o.isValidNot0(p))throw new RangeError("invalid scalar: out of range");let{p:x,f:T}=W.mulSecret(this,p,s,Y);return Y([x,T])[0]}multiplyUnsafe(p){let x=this,T=p;if(!o.isValid(T))throw new RangeError("invalid scalar: out of range");if(T===ge||x.is0())return P.ZERO;if(T===nr)return x;if(W.hasWindowSize(this))return W.mulUnsafe(x,T,Y);let U=[],M=[];return F(U,M,x,T),vo(P,U,M)}mulAddUnsafe(p,x,T){z(x);let U=[],M=[];return F(U,M,this,p),F(U,M,x,T),vo(P,U,M)}toAffine(p){let x=this,T=p;if(T!=null&&!n.isValid(T))throw new RangeError('"invertedZ" expected valid field element');let{X:U,Y:M,Z:K}=x;if(n.eql(K,n.ONE))return{x:U,y:M};let H=x.is0();T==null&&(T=H?n.ONE:n.inv(K));let j=n.mul(U,T),X=n.mul(M,T),Z=n.mul(K,T);if(H)return{x:n.ZERO,y:n.ZERO};if(!n.eql(Z,n.ONE))throw new Error("invZ was invalid");return{x:j,y:X}}isTorsionFree(){return s===nr?!0:l?l(P,this):W.mulUnsafe(this,a).is0()}clearCofactor(){return s===nr?this:f?f(P,this):this.multiplyUnsafe(s)}isSmallOrder(){return s===nr?this.is0():this.clearCofactor().is0()}toBytes(p=!0){return Rt(p,"isCompressed"),this.assertValidity(),N(P,this,p)}toHex(p=!0){return wn(this.toBytes(p))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let Y=k=>Io(P,k),W=new Cr(P,R);return W.bits>=6&&P.BASE.precompute(6),Object.freeze(P.prototype),Object.freeze(P),P}function bf(e){return Uint8Array.of(e?2:3)}function wf(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function B0(e,t={}){Fe(e);let{Fn:r}=e,n=t.randomBytes===void 0?Je:t.randomBytes,o=Object.assign(wf(e.Fp,r),{seed:Math.max(To(r.ORDER),16)});function i(m){try{let R=r.fromBytes(m);return r.isValidNot0(R)}catch{return!1}}function s(m,R){let{publicKey:b,publicKeyUncompressed:g}=o;try{let S=m.length;return R===!0&&S!==b||R===!1&&S!==g?!1:!e.fromBytes(m).is0()}catch{return!1}}function a(m){return m=m===void 0?n(o.seed):m,Bo(J(m,o.seed,"seed"),r.ORDER)}function c(m,R=!0){return e.BASE.multiply(r.fromBytes(m)).toBytes(R)}function u(m){let{secretKey:R,publicKey:b,publicKeyUncompressed:g}=o,S=r._lengths;if(!De(m))return;let B=J(m,void 0,"key").length,y=B===b||B===g,N=B===R||!!S?.includes(B);if(!(y&&N))return y}function f(m,R,b=!0){if(u(m)===!0)throw new Error("first arg must be private key");if(u(R)===!1)throw new Error("second arg must be public key");let g=r.fromBytes(m),S=e.fromBytes(R);if(S.is0())throw new Error("invalid public key: point at infinity");return S.multiply(g).toBytes(b)}let l={isValidSecretKey:i,isValidPublicKey:s,randomSecretKey:a},h=_o(a,c);return Object.freeze(l),Object.freeze(o),Object.freeze({getPublicKey:c,getSharedSecret:f,keygen:h,Point:e,utils:l,lengths:o})}function xf(e,t,r={}){Fe(e);let n=t;ho(n),Nt(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let o=Object.assign({},r),i=o.randomBytes===void 0?Je:o.randomBytes,s=o.hmac===void 0?(k,p)=>pf(n,k,p):o.hmac,{Fp:a,Fn:c}=e,{ORDER:u,BITS:f}=c,l=To(u),h=Ws(i,l),{keygen:m,getPublicKey:R,getSharedSecret:b,utils:g,lengths:S}=B0(e,o),B={prehash:!0,lowS:typeof o.lowS=="boolean"?o.lowS:!0,format:"compact",extraEntropy:!1},y=u*gf+nr<a.ORDER;function N(k){let p=u>>nr;return k>p}function C(k,p){if(!c.isValidNot0(p))throw new Error(`invalid signature ${k}: out of range 1..Point.Fn.ORDER`);return p}function $(){if(!a.isOdd)throw new Error("Field doesn't support isOdd")}function q(k,p,x){return $(),(k===x?0:2)|Number(a.isOdd(p))}function w(){if(y)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function E(k,p){wa(p);let x=S.signature,T=p==="compact"?x:p==="recovered"?x+1:void 0;return J(k,T)}class A{r;s;recovery;constructor(p,x,T){if(this.r=C("r",p),this.s=C("s",x),T!=null){if(w(),![0,1,2,3].includes(T))throw new Error("invalid recovery id");this.recovery=T}Object.freeze(this)}static fromBytes(p,x=B.format){E(p,x);let T;if(x==="der"){if(p.length>2*c.BYTES+16)throw new Yo.Err("invalid signature: DER signature too long");let{r:H,s:j}=Yo.toSig(J(p),c.BYTES+1);return new A(H,j)}x==="recovered"&&(T=p[0],x="compact",p=p.subarray(1));let U=S.signature/2,M=p.subarray(0,U),K=p.subarray(U,U*2);return new A(c.fromBytes(M),c.fromBytes(K),T)}static fromHex(p,x){return this.fromBytes(Ar(p),x)}assertRecovery(){let{recovery:p}=this;if(p==null)throw new Error("invalid recovery id: must be present");return p}addRecoveryBit(p){return new A(this.r,this.s,p)}recoverPublicKey(p){let{r:x,s:T}=this,U=this.assertRecovery(),M=U===2||U===3?x+u:x;if(!a.isValid(M))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let K=a.toBytes(M),H=e.fromBytes(Zt(bf((U&1)===0),K)),j=c.inv(M),X=D(J(p,void 0,"msgHash")),Z=c.create(-X*j),lt=c.create(T*j),ot=e.BASE.mulAddUnsafe(Z,H,lt);if(ot.is0())throw new Error("invalid recovery: point at infinify");return ot.assertValidity(),ot}hasHighS(){return N(this.s)}toBytes(p=B.format){if(wa(p),p==="der")return Ar(Yo.hexFromSig(this));let{r:x,s:T}=this,U=c.toBytes(x),M=c.toBytes(T);return p==="recovered"?(w(),Zt(Uint8Array.of(this.assertRecovery()),U,M)):Zt(U,M)}toHex(p){return wn(this.toBytes(p))}}Object.freeze(A.prototype),Object.freeze(A);let L=o.bits2int===void 0?function(p){if(p.length>8192)throw new Error("input is too large");let x=ae(p),T=p.length*8-f;return T>0?x>>BigInt(T):x}:o.bits2int,D=o.bits2int_modN===void 0?function(p){return c.create(L(p))}:o.bits2int_modN,z=Sn(f);function I(k){return Tr("num < 2^"+f,k,ge,z),c.toBytes(k)}function F(k,p){return J(k,void 0,"message"),p?J(n(k),void 0,"prehashed message"):k}function O(k,p,x){let{lowS:T,prehash:U,extraEntropy:M}=ya(x,B);k=F(k,U);let K=D(k),H=c.fromBytes(p);if(!c.isValidNot0(H))throw new Error("invalid private key");let j=[I(H),I(K)];if(M!=null&&M!==!1){let ot=M===!0?i(S.secretKey):M;j.push(J(ot,void 0,"extraEntropy"))}let X=Zt(...j),Z=K;function lt(ot){let wt=L(ot);if(!c.isValidNot0(wt))return;let qt=e.BASE.multiply(wt).toAffine(),it=c.create(qt.x);if(it===ge)return;let dt;if(h!==void 0){let jr=ae(Bo(h(l),u)),gd=c.inv(c.mul(jr,wt)),yd=c.mul(jr,Z),bd=c.mul(jr,H);dt=c.create(gd*c.create(yd+bd*it))}else{let jr=Pu(wt,u);dt=c.create(jr*c.create(Z+it*H))}if(dt===ge)return;let Vi=q(qt.x,qt.y,it),uc=dt;return T&&N(dt)&&(uc=c.neg(dt),Vi^=1),new A(it,uc,y?void 0:Vi)}return{seed:X,k2sig:lt}}function P(k,p,x={}){let{seed:T,k2sig:U}=O(k,p,x);return Ru(n.outputLen,c.BYTES,s)(T,U).toBytes(x.format)}function Y(k,p,x,T={}){let{lowS:U,prehash:M,format:K}=ya(T,B);if(x=J(x,void 0,"publicKey"),p=F(p,M),!De(k)){let H=k instanceof A?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+H)}E(k,K);try{let H=A.fromBytes(k,K),j=e.fromBytes(x);if(j.is0()||U&&H.hasHighS())return!1;let{r:X,s:Z}=H,lt=D(p),ot=c.inv(Z),wt=c.create(lt*ot),qt=c.create(X*ot),it=e.BASE.mulAddUnsafe(wt,j,qt);if(it.is0())return!1;let dt=it.toAffine();return!(c.create(dt.x)!==X||K==="recovered"&&H.recovery!==q(dt.x,dt.y,X))}catch{return!1}}function W(k,p,x={}){let{prehash:T}=ya(x,B);return p=F(p,T),A.fromBytes(k,"recovered").recoverPublicKey(p).toBytes()}return Object.freeze({keygen:m,getPublicKey:R,getSharedSecret:b,utils:g,lengths:S,Point:e,sign:P,verify:Y,recoverPublicKey:W,Signature:A,hash:n})}var Ea={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},I0={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var Ef=BigInt(2);function v0(e){let t=Ea.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),i=BigInt(22),s=BigInt(23),a=BigInt(44),c=BigInt(88),u=e*e*e%t,f=u*u*e%t,l=st(f,r,t)*f%t,h=st(l,r,t)*f%t,m=st(h,Ef,t)*u%t,R=st(m,o,t)*m%t,b=st(R,i,t)*R%t,g=st(b,a,t)*b%t,S=st(g,c,t)*g%t,B=st(S,a,t)*b%t,y=st(B,r,t)*f%t,N=st(y,s,t)*R%t,C=st(N,n,t)*u%t,$=st(C,Ef,t);if(!xa.eql(xa.sqr($),e))throw new Error("Cannot find square root");return $}var xa=vr(Ea.p,{sqrt:v0}),C0=yf(Ea,{Fp:xa,endo:I0}),_r=xf(C0,Iu);function Sf(e,t,r,n){let o=on.digest(r instanceof Uint8Array?r:r.subarray());if(Uo(o))return o.then(({digest:i})=>(n?.signal?.throwIfAborted(),_r.verify(t,i,e,{prehash:!1,format:"der"}))).catch(i=>{throw i.name==="AbortError"?i:new Bn(String(i))});try{return n?.signal?.throwIfAborted(),_r.verify(t,o.digest,e,{prehash:!1,format:"der"})}catch(i){throw new Bn(String(i))}}var Zo=class{type="secp256k1";raw;_key;constructor(t){this._key=Tf(t),this.raw=Af(this._key)}toMultihash(){return te.digest(Er(this))}toCID(){return at.createV1(114,this.toMultihash())}toString(){return rt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ht(this.raw,t.raw)}verify(t,r,n){return Sf(this._key,r,t,n)}};function Bf(e){return new Zo(e)}function Af(e){return _r.Point.fromBytes(e).toBytes()}function Tf(e){try{return _r.Point.fromBytes(e),e}catch(t){throw new no(String(t))}}function If(e){let{Type:t,Data:r}=_n.decode(e.digest),n=r??new Uint8Array;switch(t){case vt.Ed25519:return of(n);case vt.secp256k1:return Bf(n);case vt.ECDSA:return iu(n);default:throw new dn}}function Er(e){return _n.encode({Type:vt[e.type],Data:e.raw})}var vf=Symbol.for("nodejs.util.inspect.custom"),_0=114,Rn=class{type;multihash;publicKey;string;constructor(t){this.type=t.type,this.multihash=t.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[Ss]=!0;toString(){return this.string==null&&(this.string=rt.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return at.createV1(_0,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return ht(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return ht(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[vf](){return`PeerId(${this.toString()})`}},Go=class extends Rn{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},Xo=class extends Rn{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},Wo=class extends Rn{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},R0=2336,Qo=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=te.digest(nt(this.url))}[vf](){return`PeerId(${this.url})`}[Ss]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return at.createV1(R0,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=et(t)),t.toString()===this.toString())}};function Cf(e){if(D0(e))return new Go({multihash:e});if(N0(e))try{let t=If(e);if(t.type==="Ed25519")return new Xo({multihash:e,publicKey:t});if(t.type==="secp256k1")return new Wo({multihash:e,publicKey:t})}catch{let r=et(e.digest);return new Qo(new URL(r))}throw new oo("Supplied PeerID Multihash is invalid")}function N0(e){return e.code===te.code}function D0(e){return e.code===on.code}function Sa(e,t){let r={[Symbol.iterator]:()=>r,next:()=>{let n=e.next(),o=n.value;return n.done===!0||o==null?{done:!0,value:void 0}:{done:!1,value:t(o)}}};return r}function Jo(e){let t=Se(rt.decode(`z${e}`));return Cf(t)}var Nn=class e{set;constructor(t){if(this.set=new Set,t!=null)for(let r of t)this.set.add(r.toString())}get size(){return this.set.size}[Symbol.iterator](){return this.values()}add(t){this.set.add(t.toString())}clear(){this.set.clear()}delete(t){this.set.delete(t.toString())}entries(){return Sa(this.set.entries(),t=>{let r=Jo(t[0]);return[r,r]})}forEach(t){this.set.forEach(r=>{let n=Jo(r);t(n,n,this)})}has(t){return this.set.has(t.toString())}values(){return Sa(this.set.values(),t=>Jo(t))}intersection(t){let r=new e;for(let n of t)this.has(n)&&r.add(n);return r}difference(t){let r=new e;for(let n of this)t.has(n)||r.add(n);return r}union(t){let r=new e;for(let n of t)r.add(n);for(let n of this)r.add(n);return r}};function Rr(){let e={};return e.promise=new Promise((t,r)=>{e.resolve=t,e.reject=r}),e}var ti=class{buffer;mask;top;btm;next;constructor(t){if(!(t>0)||(t-1&t)!==0)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(t),this.mask=t-1,this.top=0,this.btm=0,this.next=null}push(t){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=t,this.top=this.top+1&this.mask,!0)}shift(){let t=this.buffer[this.btm];if(t!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,t}isEmpty(){return this.buffer[this.btm]===void 0}},Nr=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new ti(this.hwm),this.tail=this.head,this.size=0}calculateSize(t){return t?.byteLength!=null?t.byteLength:1}push(t){if(t?.value!=null&&(this.size+=this.calculateSize(t.value)),!this.head.push(t)){let r=this.head;this.head=r.next=new ti(2*this.head.buffer.length),this.head.push(t)}}shift(){let t=this.tail.shift();if(t===void 0&&this.tail.next!=null){let r=this.tail.next;this.tail.next=null,this.tail=r,t=this.tail.shift()}return t?.value!=null&&(this.size-=this.calculateSize(t.value)),t}isEmpty(){return this.head.isEmpty()}};var Aa=class extends Error{type;code;constructor(t,r){super(t??"The operation was aborted"),this.type="aborted",this.code=r??"ABORT_ERR"}};function _f(e={}){return L0(r=>{let n=r.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},e)}function L0(e,t){t=t??{};let r=t.onEnd,n=new Nr,o,i,s,a=Rr(),c=async()=>{try{return n.isEmpty()?s?{done:!0}:await new Promise((g,S)=>{i=B=>{i=null,n.push(B);try{g(e(n))}catch(y){S(y)}return o}}):e(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=Rr()})}},u=g=>i!=null?i(g):(n.push(g),o),f=g=>(n=new Nr,i!=null?i({error:g}):(n.push({error:g}),o)),l=g=>{if(s)return o;if(t?.objectMode!==!0&&g?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return u({done:!1,value:g})},h=g=>s?o:(s=!0,g!=null?f(g):u({done:!0})),m=()=>(n=new Nr,h(),{done:!0}),R=g=>(h(g),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:m,throw:R,push:l,end:h,get readableLength(){return n.size},onEmpty:async g=>{let S=g?.signal;if(S?.throwIfAborted(),n.isEmpty())return;let B,y;S!=null&&(B=new Promise((N,C)=>{y=()=>{C(new Aa)},S.addEventListener("abort",y)}));try{await Promise.race([a.promise,B])}finally{y!=null&&S!=null&&S?.removeEventListener("abort",y)}}},r==null)return o;let b=o;return o={[Symbol.asyncIterator](){return this},next(){return b.next()},throw(g){return b.throw(g),r!=null&&(r(g),r=void 0),{done:!0}},return(){return b.return(),r!=null&&(r(),r=void 0),{done:!0}},push:l,end(g){return b.end(g),r!=null&&(r(g),r=void 0),o},get readableLength(){return b.readableLength},onEmpty:g=>b.onEmpty(g)},o}var Ta=class e extends Error{name="TimeoutError";constructor(t,r){super(t,r),Error.captureStackTrace?.(this,e)}},Rf=e=>e.reason??new DOMException("This operation was aborted.","AbortError");function Ba(e,t){let{milliseconds:r,fallback:n,message:o,customTimers:i={setTimeout,clearTimeout},signal:s}=t,a,c,f=new Promise((l,h)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(s?.aborted){h(Rf(s)),e.then(l,h);return}if(s&&(c=()=>{h(Rf(s))},s.addEventListener("abort",c,{once:!0})),e.then(l,h),r===Number.POSITIVE_INFINITY)return;let m=new Ta;a=i.setTimeout.call(void 0,()=>{if(n){try{l(n())}catch(R){h(R)}return}typeof e.cancel=="function"&&e.cancel(),o===!1?l():o instanceof Error?h(o):(m.message=o??`Promise timed out after ${r} milliseconds`,h(m))},r)}).finally(()=>{f.clear(),c&&s&&s.removeEventListener("abort",c)});return f.clear=()=>{i.clearTimeout.call(void 0,a),a=void 0},f}var F0=e=>{let t=e.addEventListener||e.on||e.addListener,r=e.removeEventListener||e.off||e.removeListener;if(!t||!r)throw new TypeError("Emitter is not compatible");return{addListener:t.bind(e),removeListener:r.bind(e)}};function k0(e,t,r){let n,o=new Promise((i,s)=>{if(r={rejectionEvents:["error"],multiArgs:!1,rejectionMultiArgs:!1,resolveImmediately:!1,...r},!(r.count>=0&&(r.count===Number.POSITIVE_INFINITY||Number.isInteger(r.count))))throw new TypeError("The `count` option should be at least 0 or more");r.signal?.throwIfAborted();let a=[t].flat(),c=[],{addListener:u,removeListener:f}=F0(e),l=async(...m)=>{let R=r.multiArgs?m:m[0];if(r.filter)try{if(!await r.filter(R))return}catch(b){n(),s(b);return}c.push(R),r.count===c.length&&(n(),i(c))},h=(...m)=>{n(),s(r.rejectionMultiArgs?m:m[0])};n=()=>{for(let m of a)f(m,l);for(let m of r.rejectionEvents)a.includes(m)||f(m,h)};for(let m of a)u(m,l);for(let m of r.rejectionEvents)a.includes(m)||u(m,h);r.signal&&r.signal.addEventListener("abort",()=>{h(r.signal.reason)},{once:!0}),r.resolveImmediately&&i(c)});if(o.cancel=n,typeof r.timeout=="number"){let i=Ba(o,{milliseconds:r.timeout});return i.cancel=()=>{n(),i.clear()},i}return o}function ei(e,t,r){typeof r=="function"&&(r={filter:r}),r={...r,count:1,resolveImmediately:!1};let n=k0(e,t,r),o=n.then(i=>i[0]);return o.cancel=n.cancel,o}function Dn(e,t){let r,n=function(){let o=function(){r=void 0,e()};clearTimeout(r),r=setTimeout(o,t)};return n.start=()=>{},n.stop=()=>{clearTimeout(r)},n}var ri=class extends Error{static name="QueueFullError";constructor(t="The queue was full"){super(t),this.name="QueueFullError"}};function U0(e){return e.reason}function ni(e,t,r){if(t==null||e==null)return e;let n=r?.translateError??U0;if(t.aborted)return e.catch(()=>{}),Promise.reject(n(t));let o;return Promise.race([e,new Promise((i,s)=>{o=()=>{s(n(t))},t.addEventListener("abort",o)})]).finally(()=>{o!=null&&t.removeEventListener("abort",o)})}var oi=class{deferred;signal;onProgress;constructor(t){this.signal=t?.signal,this.onProgress=t?.onProgress,this.deferred=Rr(),this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(this.signal?.reason??new ie)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function O0(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var Nf=new WeakMap,ii=class{id;fn;options;recipients;status;timeline;controller;dispatchingProgress;constructor(t,r){this.id=O0(),this.status="queued",this.fn=t,this.options=r,this.recipients=[],this.timeline={created:Date.now()},this.controller=new AbortController,this.controller.signal,this.dispatchingProgress=!1,this.onAbort=this.onAbort.bind(this)}abort(t){this.controller.abort(t)}onAbort(){this.recipients.reduce((r,n)=>r&&n.signal?.aborted===!0,!0)&&(this.controller.abort(new ie),this.cleanup())}async join(t){let r=new oi(t);return this.recipients.push(r),t?.signal?.addEventListener("abort",this.onAbort),r.deferred.promise}async run(){this.status="running",this.timeline.started=Date.now();try{this.controller.signal.throwIfAborted();let t=await ni(this.fn({...this.options??{},signal:this.controller.signal,onProgress:r=>{if(this.recipients.length!==0&&!this.dispatchingProgress){if(typeof r=="object"&&r!==null){let n=Nf.get(r);if(n==null&&(n=new WeakSet,Nf.set(r,n)),n.has(this))return;n.add(this)}this.dispatchingProgress=!0;try{this.recipients.forEach(n=>{n.onProgress?.(r)})}finally{this.dispatchingProgress=!1}}}}),this.controller.signal);this.recipients.forEach(r=>{r.deferred.resolve(t)}),this.status="complete"}catch(t){this.recipients.forEach(r=>{r.deferred.reject(t)}),this.status="errored"}finally{this.timeline.finished=Date.now(),this.cleanup()}}cleanup(){this.recipients.forEach(t=>{t.deferred.reject(t.signal?.reason??new ie),t.cleanup(),t.signal?.removeEventListener("abort",this.onAbort)}),this.recipients.splice(0,this.recipients.length)}};var Dr=class extends io{concurrency;maxSize;queue;pending;sort;paused;constructor(t={}){super(),this.concurrency=t.concurrency??Number.POSITIVE_INFINITY,this.maxSize=t.maxSize??Number.POSITIVE_INFINITY,this.pending=0,this.paused=!1,t.metricName!=null&&t.metrics?.registerMetricGroup(t.metricName,{calculate:()=>({size:this.queue.length,running:this.pending,queued:this.queue.length-this.pending})}),this.sort=t.sort,this.queue=[],this.emitEmpty=Dn(this.emitEmpty.bind(this),1),this.emitIdle=Dn(this.emitIdle.bind(this),1)}emitEmpty(){this.size===0&&this.safeDispatchEvent("empty")}emitIdle(){this.running===0&&this.safeDispatchEvent("idle")}pause(){this.paused=!0}resume(){this.paused&&(this.paused=!1,this.tryToStartAnother())}tryToStartAnother(){if(this.paused)return!1;if(this.size===0)return this.emitEmpty(),this.running===0&&this.emitIdle(),!1;if(this.pending<this.concurrency){let t;for(let r of this.queue)if(r.status==="queued"){t=r;break}return t==null?!1:(this.safeDispatchEvent("active"),this.pending++,t.run().finally(()=>{for(let r=0;r<this.queue.length;r++)if(this.queue[r]===t){this.queue.splice(r,1);break}this.pending--,this.tryToStartAnother(),this.safeDispatchEvent("next")}),!0)}return!1}enqueue(t){this.queue.push(t),this.sort!=null&&this.queue.sort(this.sort)}async add(t,r){if(r?.signal?.throwIfAborted(),this.size===this.maxSize)throw new ri;let n=new ii(t,r);this.enqueue(n),this.safeDispatchEvent("add");let o=n.join(r).then(i=>(this.safeDispatchEvent("completed",{detail:i}),this.safeDispatchEvent("success",{detail:{job:n,result:i}}),i)).catch(i=>{if(n.status==="queued"){for(let s=0;s<this.queue.length;s++)if(this.queue[s]===n){this.queue.splice(s,1);break}}throw this.safeDispatchEvent("failure",{detail:{job:n,error:i}}),i});return this.tryToStartAnother(),o}clear(){this.queue.splice(0,this.queue.length)}abort(){this.queue.forEach(t=>{t.abort(new ie)}),this.clear()}async onEmpty(t){this.size!==0&&await ei(this,"empty",t)}async onSizeLessThan(t,r){this.size<t||await ei(this,"next",{...r,filter:()=>this.size<t})}async onIdle(t){this.pending===0&&this.size===0||await ei(this,"idle",t)}get size(){return this.queue.length}get queued(){return this.queue.length-this.pending}get running(){return this.pending}async*toGenerator(t){t?.signal?.throwIfAborted();let r=_f({objectMode:!0}),n=c=>{c!=null?this.abort():this.clear(),r.end(c)},o=c=>{c.detail!=null&&r.push(c.detail)},i=c=>{n(c.detail.error)},s=()=>{n()},a=()=>{n(new ie("Queue aborted"))};this.addEventListener("completed",o),this.addEventListener("failure",i),this.addEventListener("idle",s),t?.signal?.addEventListener("abort",a);try{yield*r}finally{this.removeEventListener("completed",o),this.removeEventListener("failure",i),this.removeEventListener("idle",s),t?.signal?.removeEventListener("abort",a),n()}}};function Ln(e){let t=new globalThis.AbortController;function r(){let i=e.filter(s=>s?.aborted===!0).map(s=>s?.reason).pop();t.abort(i);for(let s of e)s?.removeEventListener!=null&&s.removeEventListener("abort",r)}for(let i of e){if(i?.aborted===!0){r();break}i?.addEventListener!=null&&i.addEventListener("abort",r)}function n(){for(let i of e)i?.removeEventListener!=null&&i.removeEventListener("abort",r)}let o=t.signal;return o.clear=n,o}var P0=["Object","RegExp","Date","Error","Map","Set","WeakMap","WeakSet","ArrayBuffer","SharedArrayBuffer","DataView","Promise","URL","HTMLElement","Int8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array","Tagged"];function Ia(e){if(e===null)return"null";if(e===void 0)return"undefined";if(e===!0||e===!1)return"boolean";let t=typeof e;if(t==="string"||t==="number"||t==="bigint"||t==="symbol")return t;if(t==="function")return"Function";if(Array.isArray(e))return"Array";if(e instanceof Uint8Array)return"Uint8Array";if(e.constructor===Object)return"Object";let r=M0(e);return r||"Object"}function M0(e){let t=Object.prototype.toString.call(e).slice(8,-1);if(P0.includes(t))return t}var d=class{constructor(t,r,n){this.major=t,this.majorEncoded=t<<5,this.name=r,this.terminal=n}toString(){return`Type[${this.major}].${this.name}`}compare(t){return this.major<t.major?-1:this.major>t.major?1:0}static equals(t,r){return t===r||t.major===r.major&&t.name===r.name}};d.uint=new d(0,"uint",!0);d.negint=new d(1,"negint",!0);d.bytes=new d(2,"bytes",!0);d.string=new d(3,"string",!0);d.array=new d(4,"array",!1);d.map=new d(5,"map",!1);d.tag=new d(6,"tag",!1);d.float=new d(7,"float",!0);d.false=new d(7,"false",!0);d.true=new d(7,"true",!0);d.null=new d(7,"null",!0);d.undefined=new d(7,"undefined",!0);d.break=new d(7,"break",!0);var _=class{constructor(t,r,n){this.type=t,this.value=r,this.encodedLength=n,this.encodedBytes=void 0,this.byteValue=void 0}toString(){return`Token[${this.type}].${this.value}`}};var Fn=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",K0=new TextEncoder;function si(e){return Fn&&globalThis.Buffer.isBuffer(e)}function kn(e){return e instanceof Uint8Array?si(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):e:Uint8Array.from(e)}var V0=24,$0=200,ai=Fn?e=>e.length>=V0?globalThis.Buffer.from(e):Df(e):e=>e.length>=$0?K0.encode(e):Df(e),ce=e=>Uint8Array.from(e),Lf=Fn?(e,t,r)=>si(e)?new Uint8Array(e.subarray(t,r)):e.slice(t,r):(e,t,r)=>e.slice(t,r),Ff=Fn?(e,t)=>(e=e.map(r=>r instanceof Uint8Array?r:globalThis.Buffer.from(r)),kn(globalThis.Buffer.concat(e,t))):(e,t)=>{let r=new Uint8Array(t),n=0;for(let o of e)n+o.length>r.length&&(o=o.subarray(0,r.length-n)),r.set(o,n),n+=o.length;return r},va=Fn?e=>globalThis.Buffer.allocUnsafe(e):e=>new Uint8Array(e);function Lr(e,t){if(si(e)&&si(t))return e.compare(t);for(let r=0;r<e.length;r++)if(e[r]!==t[r])return e[r]<t[r]?-1:1;return 0}function Df(e){let t=[],r=0;for(let n=0;n<e.length;n++){let o=e.charCodeAt(n);o<128?t[r++]=o:o<2048?(t[r++]=o>>6|192,t[r++]=o&63|128):(o&64512)===55296&&n+1<e.length&&(e.charCodeAt(n+1)&64512)===56320?(o=65536+((o&1023)<<10)+(e.charCodeAt(++n)&1023),t[r++]=o>>18|240,t[r++]=o>>12&63|128,t[r++]=o>>6&63|128,t[r++]=o&63|128):(o>=55296&&o<=57343&&(o=65533),t[r++]=o>>12|224,t[r++]=o>>6&63|128,t[r++]=o&63|128)}return t}var q0=256,Un=class{constructor(t=q0){this.chunkSize=t,this.cursor=0,this.maxCursor=-1,this.chunks=[],this._initReuseChunk=null}reset(){this.cursor=0,this.maxCursor=-1,this.chunks.length&&(this.chunks=[]),this._initReuseChunk!==null&&(this.chunks.push(this._initReuseChunk),this.maxCursor=this._initReuseChunk.length-1)}pushByte(t){let r=this.chunks[this.chunks.length-1];this.cursor>this.maxCursor&&(r=va(this.chunkSize),this.chunks.push(r),this.maxCursor+=r.length,this._initReuseChunk===null&&(this._initReuseChunk=r));let n=r.length-(this.maxCursor-this.cursor)-1;r[n]=t,this.cursor++}push(t){let r=this.chunks[this.chunks.length-1];if(this.cursor+t.length<=this.maxCursor+1){let o=r.length-(this.maxCursor-this.cursor)-1;r.set(t,o)}else{if(r){let o=r.length-(this.maxCursor-this.cursor)-1;o<r.length&&(this.chunks[this.chunks.length-1]=r.subarray(0,o),this.maxCursor=this.cursor-1)}t.length<64&&t.length<this.chunkSize?(r=va(this.chunkSize),this.chunks.push(r),this.maxCursor+=r.length,this._initReuseChunk===null&&(this._initReuseChunk=r),r.set(t,0)):(this.chunks.push(t),this.maxCursor+=t.length)}this.cursor+=t.length}toBytes(t=!1){let r;if(this.chunks.length===1){let n=this.chunks[0];t&&this.cursor>n.length/2?(r=this.cursor===n.length?n:n.subarray(0,this.cursor),this._initReuseChunk=null,this.chunks=[]):r=Lf(n,0,this.cursor)}else r=Ff(this.chunks,this.cursor);return t&&this.reset(),r}},ci=class{constructor(t){this.dest=t,this.cursor=0,this.chunks=[t]}reset(){this.cursor=0}pushByte(t){if(this.cursor>=this.dest.length)throw new Error("write out of bounds, destination buffer is too small");this.dest[this.cursor++]=t}push(t){if(this.cursor+t.length>this.dest.length)throw new Error("write out of bounds, destination buffer is too small");this.dest.set(t,this.cursor),this.cursor+=t.length}toBytes(t=!1){let r=this.dest.subarray(0,this.cursor);return t&&this.reset(),r}};var V="CBOR decode error:",ui="CBOR encode error:",On=[];On[23]=1;On[24]=2;On[25]=3;On[26]=5;On[27]=9;function ye(e,t,r){if(e.length-t<r)throw new Error(`${V} not enough data for type`)}var Et=[24,256,65536,4294967296,BigInt("18446744073709551616")];function Ot(e,t,r){ye(e,t,1);let n=e[t];if(r.strict===!0&&n<Et[0])throw new Error(`${V} integer encoded in more bytes than necessary (strict decode)`);return n}function Pt(e,t,r){ye(e,t,2);let n=e[t]<<8|e[t+1];if(r.strict===!0&&n<Et[1])throw new Error(`${V} integer encoded in more bytes than necessary (strict decode)`);return n}function Mt(e,t,r){ye(e,t,4);let n=e[t]*16777216+(e[t+1]<<16)+(e[t+2]<<8)+e[t+3];if(r.strict===!0&&n<Et[2])throw new Error(`${V} integer encoded in more bytes than necessary (strict decode)`);return n}function Kt(e,t,r){ye(e,t,8);let n=e[t]*16777216+(e[t+1]<<16)+(e[t+2]<<8)+e[t+3],o=e[t+4]*16777216+(e[t+5]<<16)+(e[t+6]<<8)+e[t+7],i=(BigInt(n)<<BigInt(32))+BigInt(o);if(r.strict===!0&&i<Et[3])throw new Error(`${V} integer encoded in more bytes than necessary (strict decode)`);if(i<=Number.MAX_SAFE_INTEGER)return Number(i);if(r.allowBigInt===!0)return i;throw new Error(`${V} integers outside of the safe integer range are not supported`)}function kf(e,t,r,n){return new _(d.uint,Ot(e,t+1,n),2)}function Uf(e,t,r,n){return new _(d.uint,Pt(e,t+1,n),3)}function Of(e,t,r,n){return new _(d.uint,Mt(e,t+1,n),5)}function Pf(e,t,r,n){return new _(d.uint,Kt(e,t+1,n),9)}function ue(e,t){return yt(e,0,t.value)}function yt(e,t,r){if(r<Et[0]){let n=Number(r);e.pushByte(t|n)}else if(r<Et[1]){let n=Number(r);e.push([t|24,n])}else if(r<Et[2]){let n=Number(r);e.push([t|25,n>>>8,n&255])}else if(r<Et[3]){let n=Number(r);e.push([t|26,n>>>24&255,n>>>16&255,n>>>8&255,n&255])}else{let n=BigInt(r);if(n<Et[4]){let o=[t|27,0,0,0,0,0,0,0],i=Number(n&BigInt(4294967295)),s=Number(n>>BigInt(32)&BigInt(4294967295));o[8]=i&255,i=i>>8,o[7]=i&255,i=i>>8,o[6]=i&255,i=i>>8,o[5]=i&255,o[4]=s&255,s=s>>8,o[3]=s&255,s=s>>8,o[2]=s&255,s=s>>8,o[1]=s&255,e.push(o)}else throw new Error(`${V} encountered BigInt larger than allowable range`)}}ue.encodedSize=function(t){return yt.encodedSize(t.value)};yt.encodedSize=function(t){return t<Et[0]?1:t<Et[1]?2:t<Et[2]?3:t<Et[3]?5:9};ue.compareTokens=function(t,r){return t.value<r.value?-1:t.value>r.value?1:0};function Mf(e,t,r,n){return new _(d.negint,-1-Ot(e,t+1,n),2)}function Kf(e,t,r,n){return new _(d.negint,-1-Pt(e,t+1,n),3)}function Vf(e,t,r,n){return new _(d.negint,-1-Mt(e,t+1,n),5)}var Ca=BigInt(-1),$f=BigInt(1);function qf(e,t,r,n){let o=Kt(e,t+1,n);if(typeof o!="bigint"){let i=-1-o;if(i>=Number.MIN_SAFE_INTEGER)return new _(d.negint,i,9)}if(n.allowBigInt!==!0)throw new Error(`${V} integers outside of the safe integer range are not supported`);return new _(d.negint,Ca-BigInt(o),9)}function fi(e,t){let r=t.value,n=typeof r=="bigint"?r*Ca-$f:r*-1-1;yt(e,t.type.majorEncoded,n)}fi.encodedSize=function(t){let r=t.value,n=typeof r=="bigint"?r*Ca-$f:r*-1-1;return n<Et[0]?1:n<Et[1]?2:n<Et[2]?3:n<Et[3]?5:9};fi.compareTokens=function(t,r){return t.value<r.value?1:t.value>r.value?-1:0};function Pn(e,t,r,n){ye(e,t,r+n);let o=e.slice(t+r,t+r+n);return new _(d.bytes,o,r+n)}function zf(e,t,r,n){return Pn(e,t,1,r)}function Hf(e,t,r,n){return Pn(e,t,2,Ot(e,t+1,n))}function jf(e,t,r,n){return Pn(e,t,3,Pt(e,t+1,n))}function Yf(e,t,r,n){return Pn(e,t,5,Mt(e,t+1,n))}function Zf(e,t,r,n){let o=Kt(e,t+1,n);if(typeof o=="bigint")throw new Error(`${V} 64-bit integer bytes lengths not supported`);return Pn(e,t,9,o)}function li(e){return e.encodedBytes===void 0&&(e.encodedBytes=d.equals(e.type,d.string)?ai(e.value):e.value),e.encodedBytes}function Fr(e,t){let r=li(t);yt(e,t.type.majorEncoded,r.length),e.push(r)}Fr.encodedSize=function(t){let r=li(t);return yt.encodedSize(r.length)+r.length};Fr.compareTokens=function(t,r){return H0(li(t),li(r))};function H0(e,t){return e.length<t.length?-1:e.length>t.length?1:Lr(e,t)}var Gf=new TextDecoder,Y0=32;function Z0(e,t,r){if(r-t<Y0){let o="";for(let i=t;i<r;i++){let s=e[i];if(s&128)return Gf.decode(e.subarray(t,r));o+=String.fromCharCode(s)}return o}return Gf.decode(e.subarray(t,r))}function Mn(e,t,r,n,o){let i=r+n;ye(e,t,i);let s=new _(d.string,Z0(e,t+r,t+i),i);return o.retainStringBytes===!0&&(s.byteValue=e.slice(t+r,t+i)),s}function Xf(e,t,r,n){return Mn(e,t,1,r,n)}function Wf(e,t,r,n){return Mn(e,t,2,Ot(e,t+1,n),n)}function Qf(e,t,r,n){return Mn(e,t,3,Pt(e,t+1,n),n)}function Jf(e,t,r,n){return Mn(e,t,5,Mt(e,t+1,n),n)}function tl(e,t,r,n){let o=Kt(e,t+1,n);if(typeof o=="bigint")throw new Error(`${V} 64-bit integer string lengths not supported`);return Mn(e,t,9,o,n)}var el=Fr;function kr(e,t,r,n){return new _(d.array,n,r)}function rl(e,t,r,n){return kr(e,t,1,r)}function nl(e,t,r,n){return kr(e,t,2,Ot(e,t+1,n))}function ol(e,t,r,n){return kr(e,t,3,Pt(e,t+1,n))}function il(e,t,r,n){return kr(e,t,5,Mt(e,t+1,n))}function sl(e,t,r,n){let o=Kt(e,t+1,n);if(typeof o=="bigint")throw new Error(`${V} 64-bit integer array lengths not supported`);return kr(e,t,9,o)}function al(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${V} indefinite length items not allowed`);return kr(e,t,1,1/0)}function di(e,t){yt(e,d.array.majorEncoded,t.value)}di.compareTokens=ue.compareTokens;di.encodedSize=function(t){return yt.encodedSize(t.value)};function Ur(e,t,r,n){return new _(d.map,n,r)}function cl(e,t,r,n){return Ur(e,t,1,r)}function ul(e,t,r,n){return Ur(e,t,2,Ot(e,t+1,n))}function fl(e,t,r,n){return Ur(e,t,3,Pt(e,t+1,n))}function ll(e,t,r,n){return Ur(e,t,5,Mt(e,t+1,n))}function dl(e,t,r,n){let o=Kt(e,t+1,n);if(typeof o=="bigint")throw new Error(`${V} 64-bit integer map lengths not supported`);return Ur(e,t,9,o)}function hl(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${V} indefinite length items not allowed`);return Ur(e,t,1,1/0)}function hi(e,t){yt(e,d.map.majorEncoded,t.value)}hi.compareTokens=ue.compareTokens;hi.encodedSize=function(t){return yt.encodedSize(t.value)};function pl(e,t,r,n){return new _(d.tag,r,1)}function ml(e,t,r,n){return new _(d.tag,Ot(e,t+1,n),2)}function gl(e,t,r,n){return new _(d.tag,Pt(e,t+1,n),3)}function yl(e,t,r,n){return new _(d.tag,Mt(e,t+1,n),5)}function bl(e,t,r,n){return new _(d.tag,Kt(e,t+1,n),9)}function pi(e,t){yt(e,d.tag.majorEncoded,t.value)}pi.compareTokens=ue.compareTokens;pi.encodedSize=function(t){return yt.encodedSize(t.value)};var mi=20,gi=21,yi=22,bi=23;function xl(e,t,r,n){if(n.allowUndefined===!1)throw new Error(`${V} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new _(d.null,null,1):new _(d.undefined,void 0,1)}function El(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${V} indefinite length items not allowed`);return new _(d.break,void 0,1)}function _a(e,t,r){if(r){if(r.allowNaN===!1&&Number.isNaN(e))throw new Error(`${V} NaN values are not supported`);if(r.allowInfinity===!1&&(e===1/0||e===-1/0))throw new Error(`${V} Infinity values are not supported`)}return new _(d.float,e,t)}function Sl(e,t,r,n){return _a(wi(e,t+1),3,n)}function Al(e,t,r,n){return _a(xi(e,t+1),5,n)}function Tl(e,t,r,n){return _a(vl(e,t+1),9,n)}function Kn(e,t,r){let n=t.value;if(n===!1)e.pushByte(d.float.majorEncoded|mi);else if(n===!0)e.pushByte(d.float.majorEncoded|gi);else if(n===null)e.pushByte(d.float.majorEncoded|yi);else if(n===void 0)e.pushByte(d.float.majorEncoded|bi);else{let o,i=!1;(!r||r.float64!==!0)&&(Ra(n),o=wi(bt,1),n===o||Number.isNaN(n)?(bt[0]=249,e.push(bt.slice(0,3)),i=!0):(Na(n),o=xi(bt,1),n===o&&(bt[0]=250,e.push(bt.slice(0,5)),i=!0))),i||(Il(n),o=vl(bt,1),bt[0]=251,e.push(bt.slice(0,9)))}}Kn.encodedSize=function(t,r){let n=t.value;if(n===!1||n===!0||n===null||n===void 0)return 1;if(!r||r.float64!==!0){Ra(n);let o=wi(bt,1);if(n===o||Number.isNaN(n))return 3;if(Na(n),o=xi(bt,1),n===o)return 5}return 9};var Bl=new ArrayBuffer(9),Gt=new DataView(Bl,1),bt=new Uint8Array(Bl,0);function Ra(e){if(e===1/0)Gt.setUint16(0,31744,!1);else if(e===-1/0)Gt.setUint16(0,64512,!1);else if(Number.isNaN(e))Gt.setUint16(0,32256,!1);else{Gt.setFloat32(0,e);let t=Gt.getUint32(0),r=(t&2139095040)>>23,n=t&8388607;if(r===255)Gt.setUint16(0,31744,!1);else if(r===0)Gt.setUint16(0,(t&2147483648)>>16|n>>13,!1);else{let o=r-127;o<-24?Gt.setUint16(0,0):o<-14?Gt.setUint16(0,(t&2147483648)>>16|1<<24+o,!1):Gt.setUint16(0,(t&2147483648)>>16|o+15<<10|n>>13,!1)}}}function wi(e,t){if(e.length-t<2)throw new Error(`${V} not enough data for float16`);let r=(e[t]<<8)+e[t+1];if(r===31744)return 1/0;if(r===64512)return-1/0;if(r===32256)return NaN;let n=r>>10&31,o=r&1023,i;return n===0?i=o*2**-24:n!==31?i=(o+1024)*2**(n-25):i=o===0?1/0:NaN,r&32768?-i:i}function Na(e){Gt.setFloat32(0,e,!1)}function xi(e,t){if(e.length-t<4)throw new Error(`${V} not enough data for float32`);let r=(e.byteOffset||0)+t;return new DataView(e.buffer,r,4).getFloat32(0,!1)}function Il(e){Gt.setFloat64(0,e,!1)}function vl(e,t){if(e.length-t<8)throw new Error(`${V} not enough data for float64`);let r=(e.byteOffset||0)+t;return new DataView(e.buffer,r,8).getFloat64(0,!1)}function J0(e,t){let r=e.value;if(r===!1)return Uint8Array.of(d.float.majorEncoded|mi);if(r===!0)return Uint8Array.of(d.float.majorEncoded|gi);if(r===null)return Uint8Array.of(d.float.majorEncoded|yi);if(r===void 0)return Uint8Array.of(d.float.majorEncoded|bi);if(!t){if(Ra(r),r===wi(bt,1)||Number.isNaN(r))return bt[0]=249,bt.slice(0,3);if(Na(r),r===xi(bt,1))return bt[0]=250,bt.slice(0,5)}return Il(r),bt[0]=251,bt.slice(0,9)}function wl(e,t){let r=e,n=t?.float64===!0,o=n?r._keyBytesFloat64:r._keyBytes;if(o!==void 0)return o;let i=J0(e,n);return n?r._keyBytesFloat64=i:r._keyBytes=i,i}Kn.compareTokens=function(t,r,n){let o=wl(t,n),i=wl(r,n);return o.length!==i.length?o.length<i.length?-1:1:Lr(o,i)};function G(e,t,r){throw new Error(`${V} encountered invalid minor (${r}) for major ${e[t]>>>5}`)}function Ei(e){return()=>{throw new Error(`${V} ${e}`)}}var v=[];for(let e=0;e<=23;e++)v[e]=G;v[24]=kf;v[25]=Uf;v[26]=Of;v[27]=Pf;v[28]=G;v[29]=G;v[30]=G;v[31]=G;for(let e=32;e<=55;e++)v[e]=G;v[56]=Mf;v[57]=Kf;v[58]=Vf;v[59]=qf;v[60]=G;v[61]=G;v[62]=G;v[63]=G;for(let e=64;e<=87;e++)v[e]=zf;v[88]=Hf;v[89]=jf;v[90]=Yf;v[91]=Zf;v[92]=G;v[93]=G;v[94]=G;v[95]=Ei("indefinite length bytes/strings are not supported");for(let e=96;e<=119;e++)v[e]=Xf;v[120]=Wf;v[121]=Qf;v[122]=Jf;v[123]=tl;v[124]=G;v[125]=G;v[126]=G;v[127]=Ei("indefinite length bytes/strings are not supported");for(let e=128;e<=151;e++)v[e]=rl;v[152]=nl;v[153]=ol;v[154]=il;v[155]=sl;v[156]=G;v[157]=G;v[158]=G;v[159]=al;for(let e=160;e<=183;e++)v[e]=cl;v[184]=ul;v[185]=fl;v[186]=ll;v[187]=dl;v[188]=G;v[189]=G;v[190]=G;v[191]=hl;for(let e=192;e<=215;e++)v[e]=pl;v[216]=ml;v[217]=gl;v[218]=yl;v[219]=bl;v[220]=G;v[221]=G;v[222]=G;v[223]=G;for(let e=224;e<=243;e++)v[e]=Ei("simple values are not supported");v[244]=G;v[245]=G;v[246]=G;v[247]=xl;v[248]=Ei("simple values are not supported");v[249]=Sl;v[250]=Al;v[251]=Tl;v[252]=G;v[253]=G;v[254]=G;v[255]=El;var ne=[];for(let e=0;e<24;e++)ne[e]=new _(d.uint,e,1);for(let e=-1;e>=-24;e--)ne[31-e]=new _(d.negint,e,1);ne[64]=new _(d.bytes,new Uint8Array(0),1);ne[96]=new _(d.string,"",1);ne[128]=new _(d.array,0,1);ne[160]=new _(d.map,0,1);ne[244]=new _(d.false,!1,1);ne[245]=new _(d.true,!0,1);ne[246]=new _(d.null,null,1);function Da(e){switch(e.type){case d.false:return ce([244]);case d.true:return ce([245]);case d.null:return ce([246]);case d.bytes:return e.value.length?void 0:ce([64]);case d.string:return e.value===""?ce([96]):void 0;case d.array:return e.value===0?ce([128]):void 0;case d.map:return e.value===0?ce([160]):void 0;case d.uint:return e.value<24?ce([Number(e.value)]):void 0;case d.negint:if(e.value>=-24)return ce([31-Number(e.value)])}}var em={float64:!1,mapSorter:Fa,quickEncodeToken:Da},Dl=Object.freeze({mapSorter:om,quickEncodeToken:Da});function rm(){let e=[];return e[d.uint.major]=ue,e[d.negint.major]=fi,e[d.bytes.major]=Fr,e[d.string.major]=el,e[d.array.major]=di,e[d.map.major]=hi,e[d.tag.major]=pi,e[d.float.major]=Kn,e}var sr=rm(),Si=new Un,Pr=class e{constructor(t,r){this.obj=t,this.parent=r}includes(t){let r=this;do if(r.obj===t)return!0;while(r=r.parent);return!1}static createCheck(t,r){if(t&&t.includes(r))throw new Error(`${ui} object contains circular references`);return new e(r,t)}},Ue={null:new _(d.null,null),undefined:new _(d.undefined,void 0),true:new _(d.true,!0),false:new _(d.false,!1),emptyArray:new _(d.array,0),emptyMap:new _(d.map,0)},fe={number(e,t,r,n){return!Number.isInteger(e)||!Number.isSafeInteger(e)?new _(d.float,e):e>=0?new _(d.uint,e):new _(d.negint,e)},bigint(e,t,r,n){return e>=BigInt(0)?new _(d.uint,e):new _(d.negint,e)},Uint8Array(e,t,r,n){return new _(d.bytes,e)},string(e,t,r,n){return new _(d.string,e)},boolean(e,t,r,n){return e?Ue.true:Ue.false},null(e,t,r,n){return Ue.null},undefined(e,t,r,n){return Ue.undefined},ArrayBuffer(e,t,r,n){return new _(d.bytes,new Uint8Array(e))},DataView(e,t,r,n){return new _(d.bytes,new Uint8Array(e.buffer,e.byteOffset,e.byteLength))},Array(e,t,r,n){if(!e.length)return r.addBreakTokens===!0?[Ue.emptyArray,new _(d.break)]:Ue.emptyArray;n=Pr.createCheck(n,e);let o=[],i=0;for(let s of e)o[i++]=ir(s,r,n);return r.addBreakTokens?[new _(d.array,e.length),o,new _(d.break)]:[new _(d.array,e.length),o]},Object(e,t,r,n){let o=t!=="Object",i=o?e.keys():Object.keys(e),s=o?e.size:i.length,a;if(s){a=new Array(s),n=Pr.createCheck(n,e);let c=!o&&r.ignoreUndefinedProperties,u=0;for(let f of i){let l=o?e.get(f):e[f];c&&l===void 0||(a[u++]=[ir(f,r,n),ir(l,r,n)])}u<s&&(a.length=u)}return a?.length?(nm(a,r),r.addBreakTokens?[new _(d.map,a.length),a,new _(d.break)]:[new _(d.map,a.length),a]):r.addBreakTokens===!0?[Ue.emptyMap,new _(d.break)]:Ue.emptyMap},Tagged(e,t,r,n){return[new _(d.tag,e.tag),ir(e.value,r,n)]}};fe.Map=fe.Object;fe.Buffer=fe.Uint8Array;for(let e of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))fe[`${e}Array`]=fe.DataView;function ir(e,t={},r){let n=Ia(e),o=t&&t.typeEncoders&&t.typeEncoders[n]||fe[n];if(typeof o=="function"){let s=o(e,n,t,r);if(s!=null)return s}let i=fe[n];if(!i)throw new Error(`${ui} unsupported type: ${n}`);return i(e,n,t,r)}function nm(e,t){let r=t.mapSorter;r&&e.sort((n,o)=>r(n,o,t))}function Fa(e,t,r){let n=Array.isArray(e[0])?e[0][0]:e[0],o=Array.isArray(t[0])?t[0][0]:t[0];if(n.type.major!==o.type.major)return n.type.compare(o.type);let i=n.type.major,s=sr[i].compareTokens(n,o,r);return s===0&&console.warn("WARNING: complex key types used, CBOR key sorting guarantees are gone"),s}function om(e,t){if(e[0]instanceof _&&t[0]instanceof _){let r=e[0],n=t[0];return r._keyBytes||(r._keyBytes=Cl(r.value)),n._keyBytes||(n._keyBytes=Cl(n.value)),Lr(r._keyBytes,n._keyBytes)}throw new Error("rfc8949MapSorter: complex key types are not supported yet")}function Cl(e){return Ll(e,sr,Dl)}function Or(e,t,r,n){if(Array.isArray(t))for(let o of t)Or(e,o,r,n);else r[t.type.major](e,t,n)}var _l=d.uint.majorEncoded,Rl=d.negint.majorEncoded,im=d.bytes.majorEncoded,sm=d.string.majorEncoded,Nl=d.array.majorEncoded,La=d.map.majorEncoded,am=d.float.majorEncoded|mi,cm=d.float.majorEncoded|gi,um=d.float.majorEncoded|yi,fm=d.float.majorEncoded|bi,lm=BigInt(-1),dm=BigInt(1);function Oe(e,t,r){r<24?e.pushByte(t|Number(r)):yt(e,t,r)}function hm(e){return e.addBreakTokens!==!0}function pm(e,t,r,n,o){let i=r==="Map",s=i?t.keys():Object.keys(t),a=i?t.size:s.length;if(!a){e.pushByte(La);return}o=Pr.createCheck(o,t);let c=!i&&n.ignoreUndefinedProperties,u=new Array(a),f=0;for(let l of s){let h=i?t.get(l):t[l];c&&h===void 0||(u[f++]=[ir(l,n,o),h])}if(f===0){e.pushByte(La);return}f<a&&(u.length=f),u.sort((l,h)=>Fa(l,h,n)),Oe(e,La,f);for(let[l,h]of u)Or(e,l,sr,n),ka(e,h,n,o)}function ka(e,t,r,n){let o=Ia(t),i=r.typeEncoders&&r.typeEncoders[o];if(i){let s=i(t,o,r,n);if(s!=null){Or(e,s,sr,r);return}}switch(o){case"null":e.pushByte(um);return;case"undefined":e.pushByte(fm);return;case"boolean":e.pushByte(t?cm:am);return;case"number":!Number.isInteger(t)||!Number.isSafeInteger(t)?Kn(e,new _(d.float,t),r):t>=0?Oe(e,_l,t):Oe(e,Rl,t*-1-1);return;case"bigint":t>=BigInt(0)?Oe(e,_l,t):Oe(e,Rl,t*lm-dm);return;case"string":{let s=ai(t);Oe(e,sm,s.length),e.push(s);return}case"Uint8Array":Oe(e,im,t.length),e.push(t);return;case"Array":if(!t.length){e.pushByte(Nl);return}n=Pr.createCheck(n,t),Oe(e,Nl,t.length);for(let s of t)ka(e,s,r,n);return;case"Object":case"Map":if(r.mapSorter===Fa)pm(e,t,o,r,n);else{let s=fe.Object(t,o,r,n);Or(e,s,sr,r)}return;default:{let s=fe[o];if(!s)throw new Error(`${ui} unsupported type: ${o}`);let a=s(t,o,r,n);Or(e,a,sr,r)}}}function Ll(e,t,r,n){let o=n instanceof Uint8Array,i=o?new ci(n):Si,s=ir(e,r);if(!Array.isArray(s)&&r.quickEncodeToken){let a=r.quickEncodeToken(s);if(a)return o?(i.push(a),i.toBytes()):a;let c=t[s.type.major];if(c.encodedSize){let u=c.encodedSize(s,r);if(o||(i=new Un(u)),c(i,s,r),i.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${s} was wrong`);return o?i.toBytes():kn(i.chunks[0])}}return i.reset(),Or(i,s,t,r),i.toBytes(!0)}function Ua(e,t){return t=Object.assign({},em,t),hm(t)?(Si.reset(),ka(Si,e,t,void 0),Si.toBytes(!0)):Ll(e,sr,t)}var mm={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},Ai=class{constructor(t,r={}){this._pos=0,this.data=t,this.options=r}pos(){return this._pos}done(){return this._pos>=this.data.length}next(){let t=this.data[this._pos],r=ne[t];if(r===void 0){let n=v[t];if(!n)throw new Error(`${V} no decoder for major type ${t>>>5} (byte 0x${t.toString(16).padStart(2,"0")})`);let o=t&31;r=n(this.data,this._pos,o,this.options)}return this._pos+=r.encodedLength,r}},Pe=Symbol.for("DONE"),Mr=Symbol.for("BREAK");function gm(e,t,r){let n=[];for(let o=0;o<e.value;o++){let i=Me(t,r);if(i===Mr){if(e.value===1/0)break;throw new Error(`${V} got unexpected break to lengthed array`)}if(i===Pe)throw new Error(`${V} found array but not enough entries (got ${o}, expected ${e.value})`);n[o]=i}return n}function ym(e,t,r){let n=r.useMaps===!0,o=r.rejectDuplicateMapKeys===!0,i=n?void 0:{},s=n?new Map:void 0;for(let a=0;a<e.value;a++){let c=Me(t,r);if(c===Mr){if(e.value===1/0)break;throw new Error(`${V} got unexpected break to lengthed map`)}if(c===Pe)throw new Error(`${V} found map but not enough entries (got ${a} [no key], expected ${e.value})`);if(!n&&typeof c!="string")throw new Error(`${V} non-string keys not supported (got ${typeof c})`);if(o&&(n&&s.has(c)||!n&&Object.hasOwn(i,c)))throw new Error(`${V} found repeat map key "${c}"`);let u=Me(t,r);if(u===Pe)throw new Error(`${V} found map but not enough entries (got ${a} [no value], expected ${e.value})`);n?s.set(c,u):c==="__proto__"?Object.defineProperty(i,c,{value:u,configurable:!0,enumerable:!0,writable:!0}):i[c]=u}return n?s:i}function*bm(e,t,r){for(let n=0;n<e.value;n++){let o=Me(t,r);if(o===Mr){if(e.value===1/0)break;throw new Error(`${V} got unexpected break to lengthed map`)}if(o===Pe)throw new Error(`${V} found map but not enough entries (got ${n} [no key], expected ${e.value})`);let i=Me(t,r);if(i===Pe)throw new Error(`${V} found map but not enough entries (got ${n} [no value], expected ${e.value})`);yield[o,i]}}function wm(e,t){let r=function(){if(r._called)throw new Error(`${V} tag decode() may only be called once`);r._called=!0;let n=Me(e,t);if(n===Pe)throw new Error(`${V} tag content missing`);if(n===Mr)throw new Error(`${V} got unexpected break in tag content`);return n};return r.entries=function(){if(r._called)throw new Error(`${V} tag decode() may only be called once`);r._called=!0;let n=e.next();if(!d.equals(n.type,d.map))throw new Error(`${V} entries() requires map content, got ${n.type.name}`);let o=[];for(let i of bm(n,e,t))o.push(i);return o},r._called=!1,r}function Me(e,t){if(e.done())return Pe;let r=e.next();if(d.equals(r.type,d.break))return Mr;if(r.type.terminal)return r.value;if(d.equals(r.type,d.array))return gm(r,e,t);if(d.equals(r.type,d.map))return ym(r,e,t);if(d.equals(r.type,d.tag)){if(t.tags&&typeof t.tags[r.value]=="function"){let n=wm(e,t),o=t.tags[r.value](n);if(!n._called)throw new Error(`${V} tag decoder must call decode() or entries()`);return o}throw new Error(`${V} tag not supported (${r.value})`)}throw new Error("unsupported")}function Fl(e,t){if(!(e instanceof Uint8Array))throw new Error(`${V} data to decode must be a Uint8Array`);t=Object.assign({},mm,t);let r=kn(e),n=t.tokenizer||new Ai(r,t),o=Me(n,t);if(o===Pe)throw new Error(`${V} did not find any content to decode`);if(o===Mr)throw new Error(`${V} got unexpected break`);return[o,e.subarray(n.pos())]}function Oa(e,t){let[r,n]=Fl(e,t);if(n.length>0)throw new Error(`${V} too many terminals, data makes no sense`);return r}var Ti=class e{constructor(t,r){if(typeof t!="number"||!Number.isInteger(t)||t<0)throw new TypeError("Tagged: tag must be a non-negative integer");this.tag=t,this.value=r}static decoder(t){return r=>new e(t,r())}static preserve(...t){let r={};for(let n of t)r[n]=e.decoder(n);return r}};Object.defineProperty(Ti.prototype,Symbol.toStringTag,{value:"Tagged"});var kl=Symbol.for("sindresorhus/unlimited-timeout#brand");function Ul(e,t,...r){if(typeof e!="function")throw new TypeError("Expected callback to be a function");t??=0,t=Number(t);let n=!1,o={[kl]:!0,id:void 0,cleared:!1,ref(){return n=!1,o.id?.ref?.(),o},unref(){return n=!0,o.id?.unref?.(),o}};if(t===Number.POSITIVE_INFINITY||t>Number.MAX_SAFE_INTEGER)return o;(!Number.isFinite(t)||t<0)&&(t=0);let i=performance.now()+t,s=a=>{o.cleared||(a<=2147483647?(o.id=globalThis.setTimeout(()=>{o.cleared||e(...r)},a),n&&o.id?.unref?.()):(o.id=globalThis.setTimeout(()=>{let c=performance.now(),u=Math.max(0,i-c);s(u)},2147483647),n&&o.id?.unref?.()))};return s(t),o}function Ol(e){!e||typeof e!="object"||!e[kl]||(e.cleared=!0,e.id!==void 0&&(globalThis.clearTimeout(e.id),e.id=void 0))}var Em=new WeakMap;function Sm({clearTimeout:e,setTimeout:t}={}){return(r,{value:n,signal:o}={})=>{if(o?.aborted)return Promise.reject(o.reason);let i,s,a,c=e??clearTimeout,u=()=>{c(i),a(o.reason)},f=()=>{o&&o.removeEventListener("abort",u)},l=new Promise((h,m)=>{s=()=>{f(),h(n)},a=m,i=(t??setTimeout)(s,r)});return o&&o.addEventListener("abort",u,{once:!0}),Em.set(l,()=>{c(i),i=null,s()}),l}}var Am=Sm({setTimeout:Ul,clearTimeout:Ol}),Pl=Am;function Ml(e,t,r){let n,o,i=!1;function s(){let u={signal:o.signal},f;r?.timeout!=null&&(f=Ln([o.signal,AbortSignal.timeout(r.timeout)]),u.signal=f),i=!0,Promise.resolve().then(async()=>{await e(u)}).catch(()=>{}).finally(()=>{f!=null&&(f.aborted?f.clear():f.addEventListener("abort",()=>{f.clear()},{once:!0})),i=!1,!o.signal.aborted&&(n=setTimeout(s,t))})}let a=Dn(s,r?.debounce??100),c=!1;return{setInterval:u=>{t!==u&&(t=u,n!=null&&(clearTimeout(n),n=setTimeout(s,t)))},setTimeout:u=>{r??={},r.timeout=u},run:()=>{i||(clearTimeout(n),a())},start:()=>{c||(c=!0,o=new AbortController,o.signal,r?.runImmediately===!0?queueMicrotask(()=>{s()}):n=setTimeout(s,t))},stop:()=>{clearTimeout(n),o?.abort(),c=!1}}}var Pa=new Float32Array([-0]),Ke=new Uint8Array(Pa.buffer);function Kl(e,t,r){Pa[0]=e,t[r]=Ke[0],t[r+1]=Ke[1],t[r+2]=Ke[2],t[r+3]=Ke[3]}function Vl(e,t){return Ke[0]=e[t],Ke[1]=e[t+1],Ke[2]=e[t+2],Ke[3]=e[t+3],Pa[0]}var Ma=new Float64Array([-0]),Tt=new Uint8Array(Ma.buffer);function $l(e,t,r){Ma[0]=e,t[r]=Tt[0],t[r+1]=Tt[1],t[r+2]=Tt[2],t[r+3]=Tt[3],t[r+4]=Tt[4],t[r+5]=Tt[5],t[r+6]=Tt[6],t[r+7]=Tt[7]}function ql(e,t){return Tt[0]=e[t],Tt[1]=e[t+1],Tt[2]=e[t+2],Tt[3]=e[t+3],Tt[4]=e[t+4],Tt[5]=e[t+5],Tt[6]=e[t+6],Tt[7]=e[t+7],Ma[0]}var Tm=BigInt(Number.MAX_SAFE_INTEGER),Bm=BigInt(Number.MIN_SAFE_INTEGER),Vt=class e{lo;hi;constructor(t,r){this.lo=t|0,this.hi=r|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(r+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(BigInt(r)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?t<16384?t<128?1:2:t<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return ar;if(t<Tm&&t>Bm)return this.fromNumber(Number(t));let r=t<0n;r&&(t=-t);let n=t>>32n,o=t-(n<<32n);return r&&(n=~n|0n,o=~o|0n,++o>zl&&(o=0n,++n>zl&&(n=0n))),new e(Number(o),Number(n))}static fromNumber(t){if(t===0)return ar;let r=t<0;r&&(t=-t);let n=t>>>0,o=(t-n)/4294967296>>>0;return r&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new e(n,o)}static from(t){return typeof t=="number"?e.fromNumber(t):typeof t=="bigint"?e.fromBigInt(t):typeof t=="string"?e.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new e(t.low>>>0,t.high>>>0):ar}},ar=new Vt(0,0);ar.toBigInt=function(){return 0n};ar.zzEncode=ar.zzDecode=function(){return this};ar.length=function(){return 1};var zl=4294967296n;function Hl(e){let t=0,r=0;for(let n=0;n<e.length;++n)r=e.charCodeAt(n),r<128?t+=1:r<2048?t+=2:(r&64512)===55296&&(e.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function jl(e,t,r){if(r-t<1)return"";let o,i=[],s=0,a;for(;t<r;)a=e[t++],a<128?i[s++]=a:a>191&&a<224?i[s++]=(a&31)<<6|e[t++]&63:a>239&&a<365?(a=((a&7)<<18|(e[t++]&63)<<12|(e[t++]&63)<<6|e[t++]&63)-65536,i[s++]=55296+(a>>10),i[s++]=56320+(a&1023)):i[s++]=(a&15)<<12|(e[t++]&63)<<6|e[t++]&63,s>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,i)),s=0);return o!=null?(s>0&&o.push(String.fromCharCode.apply(String,i.slice(0,s))),o.join("")):String.fromCharCode.apply(String,i.slice(0,s))}function Ka(e,t,r){let n=r,o,i;for(let s=0;s<e.length;++s)o=e.charCodeAt(s),o<128?t[r++]=o:o<2048?(t[r++]=o>>6|192,t[r++]=o&63|128):(o&64512)===55296&&((i=e.charCodeAt(s+1))&64512)===56320?(o=65536+((o&1023)<<10)+(i&1023),++s,t[r++]=o>>18|240,t[r++]=o>>12&63|128,t[r++]=o>>6&63|128,t[r++]=o&63|128):(t[r++]=o>>12|224,t[r++]=o>>6&63|128,t[r++]=o&63|128);return r-n}function oe(e,t){return RangeError(`index out of range: ${e.pos} + ${t??1} > ${e.len}`)}function Bi(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}var Va=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=xt(t),this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,oe(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw oe(this,4);return Bi(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw oe(this,4);return Bi(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw oe(this,4);let t=Vl(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw oe(this,4);let t=ql(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),r=this.pos,n=this.pos+t;if(n>this.len)throw oe(this,t);return this.pos+=t,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let t=this.bytes();return jl(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw oe(this,t);this.pos+=t}else do if(this.pos>=this.len)throw oe(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new Vt(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw oe(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<r*7)>>>0,t}if(this.len-this.pos>4){for(;r<5;++r)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;r<5;++r){if(this.pos>=this.len)throw oe(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw oe(this,8);let t=Bi(this.buf,this.pos+=4),r=Bi(this.buf,this.pos+=4);return new Vt(t,r)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=br(this.buf,this.pos);return this.pos+=Lt(t),t}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function Vn(e){return new Va(e instanceof Uint8Array?e:e.subarray())}function $a(e,t,r){let n=Vn(e);return t.decode(n,void 0,r)}function qa(e){let t=e??8192,r=t>>>1,n,o=t;return function(s){if(s<1||s>r)return ct(s);o+s>t&&(n=ct(t),o=0);let a=n.subarray(o,o+=s);return(o&7)!==0&&(o=(o|7)+1),a}}var cr=class{fn;len;next;val;constructor(t,r,n){this.fn=t,this.len=r,this.next=void 0,this.val=n}};function za(){}var ja=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Im=qa();function vm(e){return globalThis.Buffer!=null?ct(e):Im(e)}var qn=class{len;head;tail;states;constructor(){this.len=0,this.head=new cr(za,0,0),this.tail=this.head,this.states=null}_push(t,r,n){return this.tail=this.tail.next=new cr(t,r,n),this.len+=r,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Ya((t=t>>>0)<128?1:t<16384?2:t<2097152?3:t<268435456?4:5,t)).len,this}int32(t){return t<0?this._push(Ii,10,Vt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let r=Vt.fromBigInt(t);return this._push(Ii,r.length(),r)}uint64Number(t){return this._push(yr,Lt(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let r=Vt.fromBigInt(t).zzEncode();return this._push(Ii,r.length(),r)}sint64Number(t){let r=Vt.fromNumber(t).zzEncode();return this._push(Ii,r.length(),r)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Ha,1,t?1:0)}fixed32(t){return this._push($n,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let r=Vt.fromBigInt(t);return this._push($n,4,r.lo)._push($n,4,r.hi)}fixed64Number(t){let r=Vt.fromNumber(t);return this._push($n,4,r.lo)._push($n,4,r.hi)}fixed64String(t){return this.fixed64(BigInt(t))}sfixed64(t){return this.fixed64(t)}sfixed64Number(t){return this.fixed64Number(t)}sfixed64String(t){return this.fixed64String(t)}float(t){return this._push(Kl,4,t)}double(t){return this._push($l,8,t)}bytes(t){let r=t.length>>>0;return r===0?this._push(Ha,1,0):this.uint32(r)._push(_m,r,t)}string(t){let r=Hl(t);return r!==0?this.uint32(r)._push(Ka,r,t):this._push(Ha,1,0)}fork(){return this.states=new ja(this),this.head=this.tail=new cr(za,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new cr(za,0,0),this.len=0),this}ldelim(){let t=this.head,r=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=r,this.len+=n),this}finish(){let t=this.head.next,r=vm(this.len),n=0;for(;t!=null;)t.fn(t.val,r,n),n+=t.len,t=t.next;return r}};function Ha(e,t,r){t[r]=e&255}function Cm(e,t,r){for(;e>127;)t[r++]=e&127|128,e>>>=7;t[r]=e}var Ya=class extends cr{next;constructor(t,r){super(Cm,t,r),this.next=void 0}};function Ii(e,t,r){for(;e.hi!==0;)t[r++]=e.lo&127|128,e.lo=(e.lo>>>7|e.hi<<25)>>>0,e.hi>>>=7;for(;e.lo>127;)t[r++]=e.lo&127|128,e.lo=e.lo>>>7;t[r++]=e.lo}function $n(e,t,r){t[r]=e&255,t[r+1]=e>>>8&255,t[r+2]=e>>>16&255,t[r+3]=e>>>24}function _m(e,t,r){t.set(e,r)}globalThis.Buffer!=null&&(qn.prototype.bytes=function(e){let t=e.length>>>0;return this.uint32(t),t>0&&this._push(Rm,t,e),this},qn.prototype.string=function(e){let t=globalThis.Buffer.byteLength(e);return this.uint32(t),t>0&&this._push(Nm,t,e),this});function Rm(e,t,r){t.set(e,r)}function Nm(e,t,r){e.length<40?Ka(e,t,r):t.utf8Write!=null?t.utf8Write(e,r):t.set(nt(e),r)}function Za(){return new qn}function Ga(e,t){let r=Za();return t.encode(e,r,{lengthDelimited:!1}),r.finish()}function*Xa(e,t,r){let n=Vn(e);yield*t.stream(n,void 0,".",r)}var Wa={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function Qa(e,t,r,n,o){return{name:e,type:t,encode:r,decode:n,stream:o}}function Ja(e,t,r){return Qa("message",Wa.LENGTH_DELIMITED,e,t,r)}var zn;(function(e){let t;e.codec=()=>(t==null&&(t=Ja((i,s,a={})=>{a.lengthDelimited!==!1&&s.fork(),i.key!=null&&i.key.byteLength>0&&(s.uint32(10),s.bytes(i.key)),i.value!=null&&i.value.byteLength>0&&(s.uint32(18),s.bytes(i.value)),i.timeReceived!=null&&i.timeReceived!==""&&(s.uint32(42),s.string(i.timeReceived)),a.lengthDelimited!==!1&&s.ldelim()},(i,s,a={})=>{let c={key:jt(0),value:jt(0),timeReceived:""},u=s==null?i.len:i.pos+s;for(;i.pos<u;){let f=i.uint32();switch(f>>>3){case 1:{c.key=i.bytes();break}case 2:{c.value=i.bytes();break}case 5:{c.timeReceived=i.string();break}default:{i.skipType(f&7);break}}}return c},function*(i,s,a,c={}){let u=s==null?i.len:i.pos+s;for(;i.pos<u;){let f=i.uint32();switch(f>>>3){case 1:{yield{field:`${a}.key`,value:i.bytes()};break}case 2:{yield{field:`${a}.value`,value:i.bytes()};break}case 5:{yield{field:`${a}.timeReceived`,value:i.string()};break}default:{i.skipType(f&7);break}}}})),t);function r(i){return Ga(i,e.codec())}e.encode=r;function n(i,s){return $a(i,e.codec(),s)}e.decode=n;function o(i,s){return Xa(i,e.codec(),s)}e.stream=o})(zn||(zn={}));function Zl(e){let t=e.getUTCFullYear(),r=String(e.getUTCMonth()+1).padStart(2,"0"),n=String(e.getUTCDate()).padStart(2,"0"),o=String(e.getUTCHours()).padStart(2,"0"),i=String(e.getUTCMinutes()).padStart(2,"0"),s=String(e.getUTCSeconds()).padStart(2,"0"),a=e.getUTCMilliseconds(),c=String(a*1e3*1e3).padStart(9,"0");return`${t}-${r}-${n}T${o}:${i}:${s}.${c}Z`}function Gl(e){let t=new RegExp("(\\d{4})-(\\d{2})-(\\d{2})T(\\d{2}):(\\d{2}):(\\d{2})\\.(\\d+)Z"),r=String(e).trim().match(t);if(r==null)throw new Error("Invalid format");let n=parseInt(r[1],10),o=parseInt(r[2],10)-1,i=parseInt(r[3],10),s=parseInt(r[4],10),a=parseInt(r[5],10),c=parseInt(r[6],10),u=parseInt(r[7].slice(0,-6),10);return new Date(Date.UTC(n,o,i,s,a,c,u))}var Ve=class e{key;value;timeReceived;constructor(t,r,n){if(!(t instanceof Uint8Array))throw new Error("key must be a Uint8Array");if(!(r instanceof Uint8Array))throw new Error("value must be a Uint8Array");this.key=t,this.value=r,this.timeReceived=n}serialize(){return zn.encode(this.prepareSerialize())}prepareSerialize(){return{key:this.key,value:this.value,timeReceived:Zl(this.timeReceived)}}static deserialize(t){let r=zn.decode(t);return new e(r.key,r.value,new Date(r.timeReceived))}static fromDeserialized(t){let r=Gl(t.timeReceived);if(t.key==null)throw new Error("key missing from deserialized object");if(t.value==null)throw new Error("value missing from deserialized object");return new e(t.key,t.value,r)}};var be="/",Xl=new TextEncoder().encode(be),vi=Xl[0],Kr=class e{_buf;constructor(t,r){if(typeof t=="string")this._buf=nt(t);else if(t instanceof Uint8Array)this._buf=t;else throw new Error("Invalid key, should be String of Uint8Array");if(r==null&&(r=!0),r&&this.clean(),this._buf.byteLength===0||this._buf[0]!==vi)throw new Error("Invalid key")}toString(t="utf8"){return et(this._buf,t)}uint8Array(){return this._buf}get[Symbol.toStringTag](){return`Key(${this.toString()})`}static withNamespaces(t){return new e(t.join(be))}static random(){return new e(Math.random().toString().substring(2))}static asKey(t){return t instanceof Uint8Array||typeof t=="string"?new e(t):typeof t.uint8Array=="function"?new e(t.uint8Array()):null}clean(){if((this._buf==null||this._buf.byteLength===0)&&(this._buf=Xl),this._buf[0]!==vi){let t=new Uint8Array(this._buf.byteLength+1);t.fill(vi,0,1),t.set(this._buf,1),this._buf=t}for(;this._buf.byteLength>1&&this._buf[this._buf.byteLength-1]===vi;)this._buf=this._buf.subarray(0,-1)}less(t){let r=this.list(),n=t.list();for(let o=0;o<r.length;o++){if(n.length<o+1)return!1;let i=r[o],s=n[o];if(i<s)return!0;if(i>s)return!1}return r.length<n.length}reverse(){return e.withNamespaces(this.list().slice().reverse())}namespaces(){return this.list()}baseNamespace(){let t=this.namespaces();return t[t.length-1]}list(){return this.toString().split(be).slice(1)}type(){return Lm(this.baseNamespace())}name(){return Fm(this.baseNamespace())}instance(t){return new e(this.toString()+":"+t)}path(){let t=this.parent().toString();return t.endsWith(be)||(t+=be),t+=this.type(),new e(t)}parent(){let t=this.list();return t.length===1?new e(be):new e(t.slice(0,-1).join(be))}child(t){return this.toString()===be?t:t.toString()===be?this:new e(this.toString()+t.toString(),!1)}isAncestorOf(t){return t.toString()===this.toString()?!1:t.toString().startsWith(this.toString())}isDecendantOf(t){return t.toString()===this.toString()?!1:this.toString().startsWith(t.toString())}isTopLevel(){return this.list().length===1}concat(...t){return e.withNamespaces([...this.namespaces(),...km(t.map(r=>r.namespaces()))])}};function Lm(e){let t=e.split(":");return t.length<2?"":t.slice(0,-1).join(":")}function Fm(e){let t=e.split(":");return t[t.length-1]}function km(e){return[].concat(...e)}var Wl;(function(e){e[e.SEND_QUERY=0]="SEND_QUERY",e[e.PEER_RESPONSE=1]="PEER_RESPONSE",e[e.FINAL_PEER=2]="FINAL_PEER",e[e.QUERY_ERROR=3]="QUERY_ERROR",e[e.PROVIDER=4]="PROVIDER",e[e.VALUE=5]="VALUE",e[e.ADD_PEER=6]="ADD_PEER",e[e.DIAL_PEER=7]="DIAL_PEER",e[e.PATH_ENDED=8]="PATH_ENDED"})(Wl||(Wl={}));var Bt;(function(e){e.reissue="reissue",e.rebroadcast="rebroadcast",e.none="none"})(Bt||(Bt={}));var Ci;(function(e){e[e.reissue=0]="reissue",e[e.rebroadcast=1]="rebroadcast",e[e.none=2]="none"})(Ci||(Ci={}));(function(e){e.codec=()=>fn(Ci)})(Bt||(Bt={}));var Vr;(function(e){let t;e.codec=()=>(t==null&&(t=ln((i,s,a={})=>{a.lengthDelimited!==!1&&s.fork(),i.keyName!=null&&i.keyName!==""&&(s.uint32(10),s.string(i.keyName)),i.lifetime!=null&&i.lifetime!==0&&(s.uint32(16),s.uint32(i.lifetime)),i.upkeep!=null&&Ci[i.upkeep]!==0&&(s.uint32(24),Bt.codec().encode(i.upkeep,s)),a.lengthDelimited!==!1&&s.ldelim()},(i,s)=>{let a={keyName:"",lifetime:0,upkeep:Bt.reissue},c=s==null?i.len:i.pos+s;for(;i.pos<c;){let u=i.uint32();switch(u>>>3){case 1:{a.keyName=i.string();break}case 2:{a.lifetime=i.uint32();break}case 3:{a.upkeep=Bt.codec().decode(i);break}default:{i.skipType(u&7);break}}}return a},function*(i,s,a){let c=s==null?i.len:i.pos+s;for(a!=="."&&(yield{field:a.endsWith(".")?a.substring(0,a.length-1):a,type:"start",message:"IPNSPublishMetadata"});i.pos<c;){let u=i.uint32();switch(u>>>3){case 1:{yield{field:`${a}keyName`,value:i.string()};break}case 2:{yield{field:`${a}lifetime`,value:i.uint32()};break}case 3:{yield{field:`${a}upkeep`,value:Bt.codec().decode(i)};break}default:{i.skipType(u&7);break}}}a!=="."&&(yield{field:a.endsWith(".")?a.substring(0,a.length-1):a,type:"end",message:"IPNSPublishMetadata"})})),t);function r(i){return cn(i,e.codec())}e.encode=r;function n(i,s){return nn(i,e.codec(),s)}e.decode=n;function o(i,s){return un(i,e.codec(),s)}e.stream=o})(Vr||(Vr={}));function _i(e){return e==null?!1:typeof e.type=="string"&&typeof e.code=="number"&&typeof e.verify=="function"}var Ql=42;function Um(e){return e instanceof ArrayBuffer?new Uint8Array(e,0,e.byteLength):e}function Om(e){if(e.asCID!==e&&e["/"]!==e.bytes)return null;let t=at.asCID(e);if(!t)return null;let r=new Uint8Array(t.bytes.byteLength+1);return r.set(t.bytes,1),[new _(d.tag,Ql),new _(d.bytes,r)]}function Pm(){throw new Error("`undefined` is not supported by the IPLD Data Model and cannot be encoded")}function Mm(e){if(Number.isNaN(e))throw new Error("`NaN` is not supported by the IPLD Data Model and cannot be encoded");if(e===1/0||e===-1/0)throw new Error("`Infinity` and `-Infinity` is not supported by the IPLD Data Model and cannot be encoded");return null}function Km(e){for(let t of e.keys())if(typeof t!="string"||t.length===0)throw new Error("Non-string Map keys are not supported by the IPLD Data Model and cannot be encoded");return null}var tc={float64:!0,typeEncoders:{Map:Km,Object:Om,undefined:Pm,number:Mm}},R6={...tc,typeEncoders:{...tc.typeEncoders}};function Vm(e){let t=e();if(t[0]!==0)throw new Error("Invalid CID for CBOR tag 42; expected leading 0x00");return at.decode(t.subarray(1))}var ec={allowIndefinite:!1,coerceUndefinedToNull:!0,allowNaN:!1,allowInfinity:!1,allowBigInt:!0,strict:!0,useMaps:!1,rejectDuplicateMapKeys:!0,tags:{[Ql]:Vm}},N6={...ec,tags:{...ec.tags}};var Jl=e=>Ua(e,tc),td=e=>Oa(Um(e),ec);var ed=114,rd=0;var nd=nt("/ipns/"),Ri="/ipns/";function od(e,t){return e.code===t}var Ni="/dht/record/",zm="/ipns/metadata/";function Hn(e){return new Kr(Ni+et(e,"base32"),!1)}function $r(e){return new Kr(zm+et(e,"base32"),!1)}function id(e,t){let r=Date.now();return e.getTime()+1728e5-r<864e5||t.getTime()-r<864e5}function sd(e,t,r){let n=nt(t);return Ie([e,r,n],e.byteLength+r.byteLength+n.byteLength)}function Di(e){let t=nt("ipns-signature:");return Ie([t,e])}function rc(e){try{return`/ipfs/${at.decode(e)}`}catch{}return et(e)}function Xt(e){return Ie([nd,e.bytes])}function Li(e){return Se(e.slice(nd.length))}function ad(e){return xt(Jl(e))}function Wt(e){if(e==null)throw new en("Record data is missing");let t=td(e);if(t.ValidityType===0&&(t.ValidityType=Q.ValidityType.EOL),t.ValidityType!==Q.ValidityType.EOL)throw new ze("The validity type is unsupported");return Number.isInteger(t.Sequence)&&(t.Sequence=BigInt(t.Sequence)),Number.isInteger(t.TTL)&&(t.TTL=BigInt(t.TTL)),t}function Fi(e){if(e!=null){if(_i(e))return`/ipns/${e.toCID().toV1().toString(Ct)}`;let t=fd(e);if(t!=null)return t.code===ed?`/ipns/${t.toV1().toString(Ct)}`:`/ipfs/${t.toV1()}`;if(jm(e))return`/ipns/${Ct.encode(e.bytes)}`;let r=e.toString().trim();if(r.startsWith("/ipfs/")){let[,n,...o]=r.split("/").filter(i=>i.trim()!=="");return`/ipfs/${at.parse(n).toV1()}${o.length>0?`/${o.join("/")}`:""}`}if(r.startsWith("/")&&r.length>1)return r}throw new le("Value must be a valid content path starting with /")}function Hm(e){return typeof e.code=="number"&&e.digest instanceof Uint8Array&&typeof e.size=="number"&&e.bytes instanceof Uint8Array}function we(e){if(e!=null){if(_i(e))return{digest:e.toMultihash(),path:"/"};let t=fd(e);if(t!=null){if(t.code!==ed)throw new le("CIDs must have the `libp2p-key` codec");return{digest:t.multihash,path:"/"}}if(Hm(e))return{digest:e,path:"/"};if(e=e.toString(),e.startsWith("/ipns/")){let[,,r,...n]=e.split("/"),o=Ct;(r.startsWith("1")||r.startsWith("Q"))&&(r=`z${r}`,o=rt);let i=o.decode(r),s;try{s=at.decode(i).multihash}catch{s=Se(i)}return{digest:s,path:`/${n.join("/")}`}}}throw new le("Value must be a valid IPNS path starting with /")}function cd(e){if(typeof e!="string")return we(e).digest;try{return we(e).digest}catch{return e}}function ud(e,t){if(!ht(t.Value,e.value??new Uint8Array(0)))throw new Ht('Field "value" did not match between protobuf and CBOR');if(!ht(t.Validity,e.validity??new Uint8Array(0)))throw new Ht('Field "validity" did not match between protobuf and CBOR');if(t.ValidityType!==e.validityType)throw new Ht('Field "validityType" did not match between protobuf and CBOR');if(t.Sequence!==e.sequence)throw new Ht('Field "sequence" did not match between protobuf and CBOR');if(t.TTL!==e.ttl)throw new Ht('Field "ttl" did not match between protobuf and CBOR')}function jm(e){return e.bytes instanceof Uint8Array}function Ym(e){return typeof e?.toCID=="function"}function fd(e){if(Ym(e))return e.toCID();try{return at.parse(e)}catch{}return at.asCID(e)}async function Zm(e,t,r,n){let o=r;try{o={...Vr.decode(await e.get($r(t),n)),...r}}catch(i){if(i.name!=="NotFoundError")throw i}if(o.upkeep===Bt.reissue&&(o.keyName==null||o.keyName===""))throw new Error("a keyName is required to reissue a record");return o}async function Gm(e,t,r,n){try{return Vr.decode(await e.get($r(t),n))}catch(o){o.name!=="NotFoundError"&&r.error("error deserializing metadata for %b - %e",t,o);return}}function qr(e,t){return{async put(r,n,o={}){try{let i=Hn(r);if(o.overwrite!==!0)try{let c=await e.get(i),u=Ve.deserialize(c);if(ht(u.value,n))return}catch(c){if(c.name!=="NotFoundError")throw c}let s=new Ve(r,n,new Date);o.onProgress?.(new mt("ipns:routing:datastore:put"));let a=e.batch();if(a.put(i,s.serialize()),o.metadata!=null){let c=await Zm(e,r,o.metadata,o);a.put($r(r),Vr.encode(c))}await a.commit(o)}catch(i){throw o.onProgress?.(new mt("ipns:routing:datastore:error",i)),i}},async get(r,n={}){try{let o=Hn(r);n.onProgress?.(new mt("ipns:routing:datastore:get"));let i=await e.get(o,n),s=Ve.deserialize(i);return{record:xt(s.value),created:s.timeReceived}}catch(o){throw n.onProgress?.(new mt("ipns:routing:datastore:error",o)),o}},async has(r,n={}){let o=Hn(r);return e.has(o,n)},async delete(r,n){let o=Hn(r),i=e.batch();i.delete(o),i.delete($r(r)),await i.commit(n)},async deleteMetadata(r,n){await e.delete($r(r),n)},async*list(r={}){try{r.onProgress?.(new mt("ipns:routing:datastore:list"));for await(let{key:n,value:o}of e.query({prefix:Ni},r))try{let i=Ve.deserialize(o),a=n.toString().substring(Ni.length),c=nt(a,"base32"),u=await Gm(e,c,t,r);yield{routingKey:c,metadata:u,record:i.value,created:i.timeReceived}}catch(i){t.error("Error deserializing record - %e",i)}}catch(n){throw r.onProgress?.(new mt("ipns:routing:datastore:error",n)),n}}}}var oc=Gn(jn(),1);function Qt(e,t){let r=t.map((n,o)=>({record:n,index:o}));return r.sort((n,o)=>{let i=Wt(n.record.data),s=Wt(o.record.data),a=i.Sequence,c=s.Sequence;if(a>c)return-1;if(a<c)return 1;if(i.ValidityType===Q.ValidityType.EOL&&s.ValidityType===Q.ValidityType.EOL){let u=oc.default.fromString(et(i.Validity)).toDate(),f=oc.default.fromString(et(s.Validity)).toDate();if(u.getTime()>f.getTime())return-1;if(u.getTime()<f.getTime())return 1}return 0}),r[0].index}var ld=Gn(jn(),1);var Xm=1024*10;async function $t(e,t,r,n){if(t.byteLength>Xm)throw new tn("The record is too large");let o=Q.decode(t);if(o.signatureV2==null)throw new Ht("Missing signatureV2");let i=Wt(o.data),s=et(i.Validity),a=await ic(e,o,r,n),c;try{if(o.data==null)throw new Error("Missing data");let u=Di(o.data);c=await a.verify(u,o.signatureV2,n)}catch{c=!1}if(!c)throw new Ht("Record signature verification failed");if(i.ValidityType===Q.ValidityType.EOL){if(ld.default.fromString(s).toDate().getTime()<Date.now())throw new Jr("record has expired")}else if(i.ValidityType!=null)throw new ze(`The validity type ${i.ValidityType} is unsupported`);return o.value!=null&&o.signatureV1!=null&&ud(o,i),o}async function ic(e,t,r,n){let o=Li(e);if(od(o,0))return r.loadPublicKeyFromProtobuf(o.digest,n);if(t.publicKey!=null){let i=await r.loadPublicKeyFromProtobuf(t.publicKey,n);if(!ht(i.toMultihash().bytes,o.bytes))throw new gr("Embedded public key does not match the routing key");return i}throw new gr("Could not extract public key from IPNS record or routing key")}var pt=hn("helia:ipns:routing:pubsub"),ac=class{subscriptions;localStore;libp2p;fetchConcurrency;fetchTimeout;fetchDelay;fetchQueue;fetchPeers;shutdownController;fetchTopologyId;keychain;constructor(t,r={}){if(this.subscriptions=new Set,this.shutdownController=new AbortController,this.shutdownController.signal,this.fetchPeers=new Nn,this.localStore=qr(t.datastore,t.logger.forComponent("helia:ipns:local-store")),this.libp2p=t.libp2p,this.fetchConcurrency=r.fetchConcurrency??8,this.fetchDelay=r.fetchDelay??0,this.keychain=t.keychain,this.fetchTimeout=r.fetchTimeout??2500,this.fetchQueue=new Dr({concurrency:this.fetchConcurrency,metrics:t.metrics,metricName:"helia_ipns_pubsub_fetch_queue"}),this.libp2p.services.pubsub.addEventListener("message",n=>{let o=n.detail;this.subscriptions.has(o.topic)&&this.#t(o,{signal:this.shutdownController.signal}).catch(i=>{pt.error("Error processing message - %e",i)})}),this.libp2p.services.fetch!=null)try{this.libp2p.services.pubsub.addEventListener("subscription-change",n=>{let{peerId:o,subscriptions:i}=n.detail;if(this.fetchPeers.has(o))for(let s of i){if(!this.subscriptions.has(s.topic)||s.subscribe===!1)continue;pt("peer %s joined topic %s",o,s.topic);let a=dd(s.topic);this.#e(s.topic,a,o,{signal:this.shutdownController.signal}).catch(c=>{pt.error("failed to fetch IPNS record for %m from peer %s - %e",a,o,c)})}}),this.libp2p.services.fetch.registerLookupFunction(Ri,async n=>{try{let{record:o}=await this.localStore.get(n,{signal:this.shutdownController.signal});return o}catch(o){if(o.name!=="NotFoundError")throw o}}),pt("registered lookup function for IPNS with libp2p/fetch service")}catch(n){pt("unable to register lookup function for IPNS with libp2p/fetch service - %e",n)}else pt("no libp2p/fetch service found. Skipping registration of lookup function for IPNS.")}async#t(t,r){if(pt("message received for topic",t.topic),t.type!=="signed"){pt.error("unsigned message received, this module can only work with signed messages");return}if(t.from.equals(this.libp2p.peerId)){pt("not storing record from self");return}await this.#r(t.topic,dd(t.topic),t.data,!1,r)}async#e(t,r,n,o){let i=await this.fetchQueue.add(async({signal:s})=>{pt("fetching ipns record for %m from peer %s",r,n);let a=Ln([s,AbortSignal.timeout(this.fetchTimeout)]);try{return await this.libp2p.services.fetch?.fetch(n,r,{signal:a})}finally{a.clear()}},o);if(i==null)throw new Ye(`Peer ${n} did not have record for routing key ${et(r,"base64")}`);return pt("fetched ipns record for %m from peer %s",r,n),this.#r(t,r,i,!0,o)}async#r(t,r,n,o,i){let s=await $t(r,n,this.keychain,i);if(this.shutdownController.signal.throwIfAborted(),await this.localStore.has(r)){let{record:a}=await this.localStore.get(r,i),c=await $t(r,a,this.keychain,i);if(ht(a,n))return pt.trace("found identical record for %m",r),a;if(Qt(r,[c,s])===0)return pt.trace("found old record for %m",r),a}if(pt("found new record for %m",r),await this.localStore.put(r,n,i),o){pt("publish value for topic %s",t);try{let a=await this.libp2p.services.pubsub.publish(t,n);pt("published record on topic %s to %d recipients",t,a.recipients)}catch(a){pt.error("could not publish record on topic %s - %e",a)}}return xt(n)}async put(t,r,n={}){try{let o=sc(t);pt("publish value for topic %s",o);let i=await this.libp2p.services.pubsub.publish(o,r);n?.signal?.throwIfAborted(),pt("published record on topic %s to %d recipients",o,i.recipients),n.onProgress?.(new mt("ipns:pubsub:publish",{topic:o,result:i}))}catch(o){throw n.onProgress?.(new mt("ipns:pubsub:error",o)),o}}async get(t,r={}){let n=sc(t);try{this.libp2p.services.pubsub.getTopics().includes(n)||(pt("add subscription for topic",n),this.libp2p.services.pubsub.subscribe(n),this.subscriptions.add(n),r.onProgress?.(new mt("ipns:pubsub:subscribe",{topic:n})))}catch(s){throw r.onProgress?.(new mt("ipns:pubsub:error",s)),s}await ni(Pl(this.fetchDelay),this.shutdownController.signal);let o=new AbortController,i=[];for(let s of this.libp2p.services.pubsub.getSubscribers(n)){let a=Ln([r?.signal,o.signal]);i.push(this.#e(n,t,s,{...r,signal:a}).finally(()=>{a.clear()}))}if(i.length>0){let s=await Promise.any(i);if(o.abort(),s!=null)return s}throw new Ye("Pubsub routing does not actively query peers")}getSubscriptions(){return[...this.subscriptions]}cancel(t){let r=jc(t)?t.toMultihash():t,n=Xt(r),o=sc(n);this.subscriptions.has(o)&&(this.libp2p.services.pubsub.unsubscribe(o),this.subscriptions.delete(o))}toString(){return"PubSubRouting()"}async start(){this.shutdownController=new AbortController,this.shutdownController.signal,this.libp2p.services.fetch!=null&&(this.fetchTopologyId=await this.libp2p.register(this.libp2p.services.fetch.protocol,{onConnect:t=>{this.fetchPeers.add(t)},onDisconnect:t=>{this.fetchPeers.delete(t)}},{signal:this.shutdownController.signal}))}stop(){this.fetchQueue.abort(),this.shutdownController.abort(),this.fetchTopologyId!=null&&this.libp2p.unregister(this.fetchTopologyId)}},ki="/record/";function sc(e){let t=et(e,"base64url");return`${ki}${t}`}function dd(e){if(e.substring(0,ki.length)!==ki)throw new Wr("Topic received is not from a record");let t=e.substring(ki.length);return nt(t,"base64url")}function hd(e,t={}){return new ac(e,t)}function $e(e){if(e.toString===Object.prototype.toString)return"CustomRouting()";let t=e.toString();return typeof t!="string"||t===""?"CustomRouting()":t}function Yn(e){return String(e)==="LocalStoreRouting()"}var zr=class{routers;localStore;log;keychain;constructor(t,r){this.log=t.logger.forComponent("helia:ipns"),this.localStore=r.localStore,this.routers=r.routers,this.keychain=t.keychain}async*resolve(t,r={}){let{digest:n}=we(t);for(;;){let o=Xt(n),i=await this.#t(o,r),s="";if(i.data!=null){let a=Wt(i.data);s=rc(a.Value)}else if(i.value!=null)s=rc(i.value);else throw new le(`Record for key ${Ct.encode(n.bytes)} contained no value`);if(yield{record:i,value:s},!s.startsWith(Ri))break;({digest:n}=we(s))}}async#t(t,r={}){let n=[];if(await this.localStore.has(t,r))if(this.log("record is present in the cache"),r.nocache!==!0)try{let{record:c,created:u}=await this.localStore.get(t,r);this.log("record retrieved from cache");let f;r.validate===!1?(f=Q.decode(c),this.log("skipped validation of record")):(f=await $t(t,c,this.keychain,r),this.log("record was valid"));let l=Wt(f.data),h=Number((l.TTL??Wn)/1000000n);if(u.getTime()+h>Date.now())return this.log("record TTL was valid"),f;if(r.offline===!0)return this.log("record TTL has been reached but we are resolving offline-only, returning record"),f;this.log("record TTL has been reached, searching routing for updates"),n.push(f)}catch(c){this.log("cached record was invalid - %e",c),await this.localStore.delete(t,r)}else this.log("ignoring local cache due to nocache=true option");if(r.offline===!0)throw new pr("Record was not present in the cache or has expired");this.log("did not have record locally");let{records:i,foundInvalid:s}=await Ui(this.routers,t,this.keychain,this.log,r,r.validate!==!1);if(n.push(...i),n.length===0)throw s>0?new Xr(`${s>1?`${s} records`:"Record"} found for routing key ${s>1?"were":"was"} invalid`):new pr("Could not find record for routing key");let a=n[Qt(t,n)];return await this.localStore.put(t,Q.encode(a),r),a}};async function Ui(e,t,r,n,o={},i=!0){let s=[],a=0;return await Promise.all(e.map(async c=>{if(Yn(c))return;let u;try{u=await c.get(t,{...o,validate:!1})}catch(f){n.error("error finding IPNS record using router %s - %e",$e(c),f);return}try{let f=i?await $t(t,u,r,o):Q.decode(u);s.push(f)}catch(f){a++,n.error("error reading IPNS record from router %s - %e",$e(c),f)}})),{records:s,foundInvalid:a}}var pd=Gn(jn(),1);var Wm=hn("ipns"),Qm=300000000000n;async function Hr(e,t,r,n,o){r=BigInt(r),t=Fi(t);let i=nt(t),s=o?.ttlNs??Qm,a=new pd.default((o?.now??Date.now())+Number(n)),c=Q.ValidityType.EOL,u=nt(a.toString()),f=ad({...o?.data??{},Value:i,Validity:u,ValidityType:0,Sequence:r,TTL:s}),l=Di(f),h=await e.sign(l,o),m;return o?.v1Compatible===!1?m={signatureV2:h,data:f}:m={value:i,signatureV1:await Jm(e,i,c,u),validityType:c,validity:u,sequence:r,ttl:s,signatureV2:h,data:f},tg(e.publicKey)&&(m.publicKey=e.publicKey.toProtobuf()),m}var Jm=async(e,t,r,n,o)=>{try{let i=sd(t,r,n);return await e.sign(i,o)}catch(i){throw Wm.error("record signature creation failed",i),new Qr("Record signature creation failed")}};function tg(e){return e.toMultihash().code!==rd}var Oi=class{routers;localStore;keychain;constructor(t,r){this.keychain=t.keychain,this.localStore=r.localStore,this.routers=r.routers}async publish(t,r,n={}){try{let o=await this.#t(t,n),i=o.publicKey.toMultihash(),s=Xt(i),a=1n;if(await this.localStore.has(s,n)){let{record:h}=await this.localStore.get(s,n),m=Q.decode(h);a=(Wt(m.data).Sequence??0n)+1n}let c=n.lifetime??1728e5,u=await Hr(o,r,a,c,{...n,ttlNs:n.ttl!=null?BigInt(n.ttl)*1000000n:void 0}),f=Q.encode(u),l={keyName:t,lifetime:c,upkeep:Bt[n.upkeep??"reissue"]};return n.offline===!0?await this.localStore.put(s,f,{...n,metadata:l}):await Promise.all(this.routers.map(async h=>{await h.put(s,f,{...n,metadata:l})})),{record:u,name:`/ipns/${o.publicKey.toCID().toString(Ct)}`,publicKey:o.publicKey}}catch(o){throw n.onProgress?.(new mt("ipns:publish:error",o)),o}}async#t(t,r){try{return await this.keychain.exportKey(t,r)}catch(n){if(n.name==="NotFoundError")return this.keychain.generateKey(t,r);throw n}}async unpublish(t,r){typeof t=="string"&&(t=(await this.keychain.exportKey(t,r)).publicKey.toMultihash());let n=Xt(t);if(r?.removeRecord===!0){await this.localStore.delete(n,r);return}await this.localStore.deleteMetadata(n,r)}};var md=Gn(jn(),1);var Pi=class{routers;localStore;republishTask;log;keychain;started=!1;republishConcurrency;constructor(t,r){this.log=t.logger.forComponent("helia:ipns"),this.localStore=r.localStore,this.keychain=t.keychain,this.republishConcurrency=r.republishConcurrency||Bc,this.started=!1,this.routers=r.routers??[],this.republishTask=Ml(this.#t.bind(this),r.republishInterval??36e5,{runImmediately:!0}),this.started&&this.republishTask.start()}start(){this.started||(this.started=!0,this.republishTask.start())}stop(){this.started&&(this.started=!1,this.republishTask.stop())}async#t(t={}){if(!this.started)return;this.log("starting ipns republish records loop");let r=new Dr({concurrency:this.republishConcurrency});try{let n=[],o=[],i=0;for await(let{routingKey:s,record:a,metadata:c,created:u}of this.localStore.list(t)){if(i++,c==null){this.log("no metadata found for record %b, skipping",s);continue}if(c.upkeep===Bt.none){this.log("republishing is disabled for record %b, skipping",s);continue}let f;try{f=Q.decode(a)}catch(g){this.log.error("skipping stored record %b, could not decode it - %e",s,g);continue}if(f.data==null){this.log.error("skipping stored record %b, its data is missing",s);continue}let l;try{l=Wt(f.data)}catch(g){this.log.error("skipping stored record %b, could not decode its data - %e",s,g);continue}let h;try{h=md.default.fromString(et(l.Validity)).toDate()}catch(g){this.log.error("skipping stored record %b, could not parse its validity - %e",s,g);continue}if(!id(u,h)){this.log.trace("skipping record %b within republish threshold",s);continue}if(c.upkeep===Bt.rebroadcast){if(h.getTime()<=Date.now()){this.log.trace("skipping expired record %b for rebroadcast",s);continue}o.push({routingKey:s,record:f});continue}let m=l.Sequence+1n,R=l.TTL??Wn,b;try{b=await this.keychain.exportKey(c.keyName)}catch(g){this.log.error("missing key %s, skipping republishing record - %e",c.keyName,g);continue}try{let g=await Hr(b,et(l.Value),m,c.lifetime,{...t,ttlNs:R});n.push({routingKey:s,record:g})}catch(g){this.log.error("error creating updated IPNS record for %b - %e",s,g);continue}}this.log(`reissuing ${n.length} and rebroadcasting ${o.length} of ${i} records`);for(let{routingKey:s,record:a}of n)r.add(async()=>this.#e(s,Q.encode(a),t),t).catch(c=>{this.log.error("failed to reissue record %b - %e",s,c)});for(let{routingKey:s,record:a}of o)r.add(async()=>{let{records:c}=await Ui(this.routers,s,this.keychain,this.log,t),u=[a,...c],f=u[Qt(s,u)];await this.#e(s,Q.encode(f),{...t,overwrite:!0})},t).catch(c=>{this.log.error("failed to rebroadcast record %b - %e",s,c)})}catch(n){this.log.error("error during republish - %e",n)}}async#e(t,r,n){let o=this.routers.find(Yn);o!=null&&(await o.put(t,r,n),this.log("published record %b to %s",t,$e(o))),await Promise.all(this.routers.filter(i=>i!==o).map(async i=>{try{await i.put(t,r,n),this.log("published record %b to %s",t,$e(i))}catch(s){this.log.error("failed to publish record %b to %s - %e",t,$e(i),s)}}))}async republish(t,r={}){let n=Xt(t),o;try{({record:o}=await this.localStore.get(n,r))}catch(a){throw a.name!=="NotFoundError"?a:new Ye("No local record found to republish - import it first")}let i=await $t(n,o,this.keychain,r);if(r.skipResolution!==!0){let{records:a}=await Ui(this.routers,n,this.keychain,this.log,r),c=[i,...a],u=Qt(n,c);if(u!==0)throw new mr("A newer record is already published for this key",c[u])}let s={upkeep:Bt[r.upkeep??"rebroadcast"]};return await this.#e(n,o,{...r,overwrite:!0,metadata:s}),{record:i,publicKey:await ic(n,i,this.keychain,r)}}async import(t,r,n){let o=Xt(t),i=r instanceof Uint8Array?Q.decode(r):r,s=Q.encode(i);await $t(o,s,this.keychain,n);try{let{record:a}=await this.localStore.get(o,n),c=Q.decode(a);if(Qt(o,[i,c])!==0)throw new mr("A newer record is already stored for this key",c)}catch(a){if(a.name!=="NotFoundError")throw a}await this.localStore.put(o,s,n)}};var cc=class{localStore;constructor(t){this.localStore=t}async put(t,r,n){await this.localStore.put(t,r,n)}async get(t,r){let{record:n}=await this.localStore.get(t,r);return n}toString(){return"LocalStoreRouting()"}};function Mi(e){return new cc(e)}var Ki=class{routers;publisher;republisher;resolver;localStore;components;started;constructor(t,r={}){this.localStore=qr(t.datastore,t.logger.forComponent("helia:ipns:local-store")),this.components=t,this.started=!1,this.routers=[Mi(this.localStore),wr(t.routing),...r.routers??[]],this.publisher=new Oi(t,{...r,routers:this.routers,localStore:this.localStore}),this.resolver=new zr(t,{...r,routers:this.routers,localStore:this.localStore}),this.republisher=new Pi(t,{...r,routers:this.routers,localStore:this.localStore}),t.events.addEventListener("start",this.start.bind(this)),t.events.addEventListener("stop",this.stop.bind(this)),this.started&&this.republisher.start();for(let n of Object.values(this.components))if(rg(n))for(let o of Object.values(n.services))ng(o)&&(o.selectors.ipns=async(i,s)=>{let a=s.map(c=>Q.decode(c));return Qt(i,a)},o.validators.ipns=async(i,s)=>{await $t(i,s,this.components.keychain)})}start(){this.started||(this.started=!0,this.republisher.start())}stop(){this.started&&(this.started=!1,this.republisher.stop())}async publish(t,r,n={}){return this.publisher.publish(t,Fi(r),n)}async*resolve(t,r={}){let{digest:n}=we(t);yield*this.resolver.resolve(n,r)}async unpublish(t,r){return t=cd(t),this.publisher.unpublish(t,r)}async republish(t,r={}){let{digest:n}=we(t);return this.republisher.republish(n,r)}async import(t,r,n){let{digest:o}=we(t);return this.republisher.import(o,r,n)}};function rg(e){return e?.services!=null}function ng(e){return e?.validators!=null&&e?.selectors!=null}function og(e,t={}){return new Ki(e,t)}function ig(e,t={}){let r=qr(e.datastore,e.logger.forComponent("helia:ipns:local-store")),n=[Mi(r),wr(e.routing),...t.routers??[]];return new zr(e,{routers:n,localStore:r})}return Bd(sg);})();
|
|
14
14
|
/*! Bundled license information:
|
|
15
15
|
|
|
16
16
|
@noble/curves/utils.js:
|