@libp2p/utils 7.0.11 → 7.0.12

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 CHANGED
@@ -1,5 +1,5 @@
1
1
  (function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PUtils = factory()}(typeof self !== 'undefined' ? self : this, function () {
2
- "use strict";var Libp2PUtils=(()=>{var qi=Object.create;var jt=Object.defineProperty;var Wi=Object.getOwnPropertyDescriptor;var Gi=Object.getOwnPropertyNames;var Hi=Object.getPrototypeOf,Xi=Object.prototype.hasOwnProperty;var Qi=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),V=(t,e)=>{for(var r in e)jt(t,r,{get:e[r],enumerable:!0})},co=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Gi(e))!Xi.call(t,o)&&o!==r&&jt(t,o,{get:()=>e[o],enumerable:!(n=Wi(e,o))||n.enumerable});return t};var Ki=(t,e,r)=>(r=t!=null?qi(Hi(t)):{},co(e||!t||!t.__esModule?jt(r,"default",{value:t,enumerable:!0}):r,t)),Ji=t=>co(jt({},"__esModule",{value:!0}),t);var Ho=Qi(wt=>{(function(){var t,e,r,n,o,s,i,a;a=function(c){var u,l,d,h;return u=(c&255<<24)>>>24,l=(c&255<<16)>>>16,d=(c&65280)>>>8,h=c&255,[u,l,d,h].join(".")},i=function(c){var u,l,d,h,g,x;for(u=[],d=h=0;h<=3&&c.length!==0;d=++h){if(d>0){if(c[0]!==".")throw new Error("Invalid IP");c=c.substring(1)}x=e(c),g=x[0],l=x[1],c=c.substring(l),u.push(g)}if(c.length!==0)throw new Error("Invalid IP");switch(u.length){case 1:if(u[0]>4294967295)throw new Error("Invalid IP");return u[0]>>>0;case 2:if(u[0]>255||u[1]>16777215)throw new Error("Invalid IP");return(u[0]<<24|u[1])>>>0;case 3:if(u[0]>255||u[1]>255||u[2]>65535)throw new Error("Invalid IP");return(u[0]<<24|u[1]<<16|u[2])>>>0;case 4:if(u[0]>255||u[1]>255||u[2]>255||u[3]>255)throw new Error("Invalid IP");return(u[0]<<24|u[1]<<16|u[2]<<8|u[3])>>>0;default:throw new Error("Invalid IP")}},r=function(c){return c.charCodeAt(0)},n=r("0"),s=r("a"),o=r("A"),e=function(c){var u,l,d,h,g;for(h=0,u=10,l="9",d=0,c.length>1&&c[d]==="0"&&(c[d+1]==="x"||c[d+1]==="X"?(d+=2,u=16):"0"<=c[d+1]&&c[d+1]<="9"&&(d++,u=8,l="7")),g=d;d<c.length;){if("0"<=c[d]&&c[d]<=l)h=h*u+(r(c[d])-n)>>>0;else if(u===16)if("a"<=c[d]&&c[d]<="f")h=h*u+(10+r(c[d])-s)>>>0;else if("A"<=c[d]&&c[d]<="F")h=h*u+(10+r(c[d])-o)>>>0;else break;else break;if(h>4294967295)throw new Error("too large");d++}if(d===g)throw new Error("empty octet");return[h,d]},t=(function(){function c(u,l){var d,h,g,x;if(typeof u!="string")throw new Error("Missing `net' parameter");if(l||(x=u.split("/",2),u=x[0],l=x[1]),l||(l=32),typeof l=="string"&&l.indexOf(".")>-1){try{this.maskLong=i(l)}catch(v){throw d=v,new Error("Invalid mask: "+l)}for(h=g=32;g>=0;h=--g)if(this.maskLong===4294967295<<32-h>>>0){this.bitmask=h;break}}else if(l||l===0)this.bitmask=parseInt(l,10),this.maskLong=0,this.bitmask>0&&(this.maskLong=4294967295<<32-this.bitmask>>>0);else throw new Error("Invalid mask: empty");try{this.netLong=(i(u)&this.maskLong)>>>0}catch(v){throw d=v,new Error("Invalid net address: "+u)}if(!(this.bitmask<=32))throw new Error("Invalid mask for ip4: "+l);this.size=Math.pow(2,32-this.bitmask),this.base=a(this.netLong),this.mask=a(this.maskLong),this.hostmask=a(~this.maskLong),this.first=this.bitmask<=30?a(this.netLong+1):this.base,this.last=this.bitmask<=30?a(this.netLong+this.size-2):a(this.netLong+this.size-1),this.broadcast=this.bitmask<=30?a(this.netLong+this.size-1):void 0}return c.prototype.contains=function(u){return typeof u=="string"&&(u.indexOf("/")>0||u.split(".").length!==4)&&(u=new c(u)),u instanceof c?this.contains(u.base)&&this.contains(u.broadcast||u.last):(i(u)&this.maskLong)>>>0===(this.netLong&this.maskLong)>>>0},c.prototype.next=function(u){return u==null&&(u=1),new c(a(this.netLong+this.size*u),this.mask)},c.prototype.forEach=function(u){var l,d,h;for(h=i(this.first),d=i(this.last),l=0;h<=d;)u(a(h),h,l),l++,h++},c.prototype.toString=function(){return this.base+"/"+this.bitmask},c})(),wt.ip2long=i,wt.long2ip=a,wt.Netmask=t}).call(wt)});var fl={};V(fl,{AbstractMessageStream:()=>ke,AbstractMultiaddrConnection:()=>Ct,AbstractStream:()=>Be,AbstractStreamMuxer:()=>Lt,AdaptiveTimeout:()=>Cn,BloomFilter:()=>gt,CuckooFilter:()=>ve,DEFAULT_FAILURE_MULTIPLIER:()=>Jo,DEFAULT_INTERVAL:()=>es,DEFAULT_MAX_TIMEOUT:()=>Zo,DEFAULT_MIN_TIMEOUT:()=>Yo,DEFAULT_TIMEOUT_MULTIPLIER:()=>Ko,InvalidDataLengthError:()=>fr,InvalidDataLengthLengthError:()=>lr,InvalidMessageLengthError:()=>tt,LengthPrefixedDecoder:()=>Pn,MaxEarlyStreamsError:()=>_t,MemoryStorage:()=>Pr,MockStream:()=>to,MovingAverage:()=>Me,PeerQueue:()=>oo,PriorityQueue:()=>so,Queue:()=>re,QueueFullError:()=>vt,RateLimitError:()=>Et,RateLimiter:()=>io,ScalableCuckooFilter:()=>yt,StreamClosedError:()=>St,UnexpectedEOFError:()=>Ce,UnwrappedError:()=>At,byteStream:()=>_s,createBloomFilter:()=>Po,createCuckooFilter:()=>Oo,createScalableCuckooFilter:()=>Ro,debounce:()=>Ze,echo:()=>Mn,echoStream:()=>al,getNetConfig:()=>q,getThinWaistAddresses:()=>Nu,ipPortToMultiaddr:()=>Bu,isAsyncGenerator:()=>Mu,isGenerator:()=>Pu,isGlobalUnicast:()=>vc,isGlobalUnicastIp:()=>ku,isLinkLocal:()=>_c,isLinkLocalIp:()=>ef,isLoopback:()=>Sc,isNetworkAddress:()=>Cc,isPrivate:()=>Nc,isPrivateIp:()=>wn,isPromise:()=>Sn,lpStream:()=>Ss,messageStreamToDuplex:()=>Cs,mockMuxer:()=>Nr,multiaddrConnectionPair:()=>no,pbStream:()=>Qu,pipe:()=>Ju,repeatingTask:()=>il,streamPair:()=>Vi,trackedList:()=>cl,trackedMap:()=>ul});var de=class extends Error{static name="AbortError";constructor(e="The operation was aborted"){super(e),this.name="AbortError"}};var $=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}};var qt=class extends Error{static name="MuxerClosedError";constructor(e="The muxer is closed"){super(e),this.name="MuxerClosedError"}},Wt=class extends Error{static name="StreamResetError";constructor(e="The stream has been reset"){super(e),this.name="StreamResetError"}};var be=class extends Error{static name="StreamStateError";constructor(e="The stream is in an invalid state"){super(e),this.name="StreamStateError"}},ct=class extends Error{static name="StreamBufferError";constructor(e="The stream buffer was full"){super(e),this.name="StreamBufferError"}};var se=class extends Event{data;constructor(e,r){super("message",r),this.data=e}},ze=class extends Event{error;local;constructor(e,r,n){super("close",n),this.error=r,this.local=e}},Gt=class extends ze{constructor(e,r){super(!0,e,r)}},Ht=class extends ze{constructor(e,r){super(!1,e,r)}};var ie=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){super.addEventListener(e,r,n);let o=this.#e.get(e);o==null&&(o=[],this.#e.set(e,o)),o.push({callback:r,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(e,r,n){super.removeEventListener(e.toString(),r??null,n);let o=this.#e.get(e);o!=null&&(o=o.filter(({callback:s})=>s!==r),this.#e.set(e,o))}dispatchEvent(e){let r=super.dispatchEvent(e),n=this.#e.get(e.type);return n==null||(n=n.filter(({once:o})=>!o),this.#e.set(e.type,n)),r}safeDispatchEvent(e,r={}){return this.dispatchEvent(new CustomEvent(e,r))}};var Vr={};V(Vr,{base58btc:()=>Q,base58flickr:()=>oa});var pl=new Uint8Array(0);function uo(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 he(t){if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return t;if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);throw new Error("Unknown type, must be binary type")}function fo(t){return new TextEncoder().encode(t)}function lo(t){return new TextDecoder().decode(t)}function Yi(t,e){if(t.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var o=0;o<t.length;o++){var s=t.charAt(o),i=s.charCodeAt(0);if(r[i]!==255)throw new TypeError(s+" is ambiguous");r[i]=o}var a=t.length,c=t.charAt(0),u=Math.log(a)/Math.log(256),l=Math.log(256)/Math.log(a);function d(x){if(x instanceof Uint8Array||(ArrayBuffer.isView(x)?x=new Uint8Array(x.buffer,x.byteOffset,x.byteLength):Array.isArray(x)&&(x=Uint8Array.from(x))),!(x instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(x.length===0)return"";for(var v=0,b=0,w=0,C=x.length;w!==C&&x[w]===0;)w++,v++;for(var L=(C-w)*l+1>>>0,O=new Uint8Array(L);w!==C;){for(var k=x[w],le=0,R=L-1;(k!==0||le<b)&&R!==-1;R--,le++)k+=256*O[R]>>>0,O[R]=k%a>>>0,k=k/a>>>0;if(k!==0)throw new Error("Non-zero carry");b=le,w++}for(var Y=L-b;Y!==L&&O[Y]===0;)Y++;for(var Ae=c.repeat(v);Y<L;++Y)Ae+=t.charAt(O[Y]);return Ae}function h(x){if(typeof x!="string")throw new TypeError("Expected String");if(x.length===0)return new Uint8Array;var v=0;if(x[v]!==" "){for(var b=0,w=0;x[v]===c;)b++,v++;for(var C=(x.length-v)*u+1>>>0,L=new Uint8Array(C);x[v];){var O=r[x.charCodeAt(v)];if(O===255)return;for(var k=0,le=C-1;(O!==0||k<w)&&le!==-1;le--,k++)O+=a*L[le]>>>0,L[le]=O%256>>>0,O=O/256>>>0;if(O!==0)throw new Error("Non-zero carry");w=k,v++}if(x[v]!==" "){for(var R=C-w;R!==C&&L[R]===0;)R++;for(var Y=new Uint8Array(b+(C-R)),Ae=b;R!==C;)Y[Ae++]=L[R++];return Y}}}function g(x){var v=h(x);if(v)return v;throw new Error(`Non-${e} character`)}return{encode:d,decodeUnsafe:h,decode:g}}var Zi=Yi,ea=Zi,mo=ea;var Or=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")}},Rr=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 po(this,e)}},$r=class{decoders;constructor(e){this.decoders=e}or(e){return po(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 po(t,e){return new $r({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var zr=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 Or(e,r,n),this.decoder=new Rr(e,r,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function Ve({name:t,prefix:e,encode:r,decode:n}){return new zr(t,e,r,n)}function xe({name:t,prefix:e,alphabet:r}){let{encode:n,decode:o}=mo(r,t);return Ve({prefix:e,name:t,encode:n,decode:s=>he(o(s))})}function ta(t,e,r,n){let o=t.length;for(;t[o-1]==="=";)--o;let s=new Uint8Array(o*r/8|0),i=0,a=0,c=0;for(let u=0;u<o;++u){let l=e[t[u]];if(l===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|l,i+=r,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=r||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function ra(t,e,r){let n=e[e.length-1]==="=",o=(1<<r)-1,s="",i=0,a=0;for(let c=0;c<t.length;++c)for(a=a<<8|t[c],i+=8;i>r;)i-=r,s+=e[o&a>>i];if(i!==0&&(s+=e[o&a<<r-i]),n)for(;(s.length*r&7)!==0;)s+="=";return s}function na(t){let e={};for(let r=0;r<t.length;++r)e[t[r]]=r;return e}function I({name:t,prefix:e,bitsPerChar:r,alphabet:n}){let o=na(n);return Ve({prefix:e,name:t,encode(s){return ra(s,n,r)},decode(s){return ta(s,o,r,t)}})}var Q=xe({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),oa=xe({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var jr={};V(jr,{base32:()=>ae,base32hex:()=>ca,base32hexpad:()=>fa,base32hexpadupper:()=>la,base32hexupper:()=>ua,base32pad:()=>ia,base32padupper:()=>aa,base32upper:()=>sa,base32z:()=>da});var ae=I({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),sa=I({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),ia=I({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),aa=I({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),ca=I({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),ua=I({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),fa=I({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),la=I({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),da=I({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var qr={};V(qr,{base36:()=>ut,base36upper:()=>ha});var ut=xe({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),ha=xe({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var ma=bo,go=128,pa=127,ga=~pa,ya=Math.pow(2,31);function bo(t,e,r){e=e||[],r=r||0;for(var n=r;t>=ya;)e[r++]=t&255|go,t/=128;for(;t&ga;)e[r++]=t&255|go,t>>>=7;return e[r]=t|0,bo.bytes=r-n+1,e}var ba=Wr,xa=128,yo=127;function Wr(t,n){var r=0,n=n||0,o=0,s=n,i,a=t.length;do{if(s>=a)throw Wr.bytes=0,new RangeError("Could not decode varint");i=t[s++],r+=o<28?(i&yo)<<o:(i&yo)*Math.pow(2,o),o+=7}while(i>=xa);return Wr.bytes=s-n,r}var wa=Math.pow(2,7),Ea=Math.pow(2,14),va=Math.pow(2,21),_a=Math.pow(2,28),Sa=Math.pow(2,35),Ca=Math.pow(2,42),La=Math.pow(2,49),Ia=Math.pow(2,56),Aa=Math.pow(2,63),Ta=function(t){return t<wa?1:t<Ea?2:t<va?3:t<_a?4:t<Sa?5:t<Ca?6:t<La?7:t<Ia?8:t<Aa?9:10},Da={encode:ma,decode:ba,encodingLength:Ta},Fa=Da,ft=Fa;function lt(t,e=0){return[ft.decode(t,e),ft.decode.bytes]}function je(t,e,r=0){return ft.encode(t,e,r),e}function qe(t){return ft.encodingLength(t)}function Ge(t,e){let r=e.byteLength,n=qe(t),o=n+qe(r),s=new Uint8Array(o+r);return je(t,s,0),je(r,s,n),s.set(e,o),new We(t,r,e,s)}function xo(t){let e=he(t),[r,n]=lt(e),[o,s]=lt(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new We(r,o,i,e)}function wo(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&uo(t.bytes,r.bytes)}}var We=class{code;size;digest;bytes;constructor(e,r,n,o){this.code=e,this.size=r,this.digest=n,this.bytes=o}};function Eo(t,e){let{bytes:r,version:n}=t;switch(n){case 0:return Na(r,Gr(t),e??Q.encoder);default:return ka(r,Gr(t),e??ae.encoder)}}var vo=new WeakMap;function Gr(t){let e=vo.get(t);if(e==null){let r=new Map;return vo.set(t,r),r}return e}var He=class t{code;version;multihash;bytes;"/";constructor(e,r,n,o){this.code=r,this.version=e,this.multihash=n,this.bytes=o,this["/"]=o}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!==ht)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Ba)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=Ge(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&&wo(e.multihash,n.multihash)}toString(e){return Eo(this,e)}toJSON(){return{"/":Eo(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:s,bytes:i}=r;return new t(n,o,s,i??_o(n,o,s.bytes))}else if(r[Ma]===!0){let{version:n,multihash:o,code:s}=r,i=xo(o);return t.create(n,s,i)}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!==ht)throw new Error(`Version 0 CID must use dag-pb (code: ${ht}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let o=_o(e,r,n.bytes);return new t(e,r,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,ht,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=he(e.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let s=o.subarray(r.multihashSize-r.digestSize),i=new We(r.multihashCode,r.digestSize,s,o);return[r.version===0?t.createV0(i):t.createV1(r.codec,i),e.subarray(r.size)]}static inspectBytes(e){let r=0,n=()=>{let[d,h]=lt(e.subarray(r));return r+=h,d},o=n(),s=ht;if(o===18?(o=0,r=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=r,a=n(),c=n(),u=r+c,l=u-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:l,size:u}}static parse(e,r){let[n,o]=Ua(e,r),s=t.decode(o);if(s.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Gr(s).set(n,e),s}};function Ua(t,e){switch(t[0]){case"Q":{let r=e??Q;return[Q.prefix,r.decode(`${Q.prefix}${t}`)]}case Q.prefix:{let r=e??Q;return[Q.prefix,r.decode(t)]}case ae.prefix:{let r=e??ae;return[ae.prefix,r.decode(t)]}case ut.prefix:{let r=e??ut;return[ut.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 Na(t,e,r){let{prefix:n}=r;if(n!==Q.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=e.get(n);if(o==null){let s=r.encode(t).slice(1);return e.set(n,s),s}else return o}function ka(t,e,r){let{prefix:n}=r,o=e.get(n);if(o==null){let s=r.encode(t);return e.set(n,s),s}else return o}var ht=112,Ba=18;function _o(t,e,r){let n=qe(t),o=n+qe(e),s=new Uint8Array(o+r.byteLength);return je(t,s,0),je(e,s,n),s.set(r,o),s}var Ma=Symbol.for("@ipld/js-cid/CID");var Hr={};V(Hr,{identity:()=>Ra});var So=0,Pa="identity",Co=he;function Oa(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 Ge(So,Co(t))}var Ra={code:So,name:Pa,encode:Co,digest:Oa};function Xe(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 j(t=0){return new Uint8Array(t)}function Z(t=0){return new Uint8Array(t)}function we(t,e){e==null&&(e=t.reduce((o,s)=>o+s.length,0));let r=Z(e),n=0;for(let o of t)r.set(o,n),n+=o.length;return r}var Io=Symbol.for("@achingbrain/uint8arraylist");function Lo(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 Qe(t){return!!t?.[Io]}var A=class t{bufs;length;[Io]=!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(Qe(n))r+=n.byteLength,this.bufs.push(...n.bufs);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(Qe(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=Lo(this.bufs,e);return r.buf[r.index]}set(e,r){let n=Lo(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(Qe(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 we(n,o)}subarray(e,r){let{bufs:n,length:o}=this._subList(e,r);return n.length===1?n[0]:we(n,o)}sublist(e,r){let{bufs:n,length:o}=this._subList(e,r),s=new t;return s.length=o,s.bufs=[...n],s}_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 s=0;s<this.bufs.length;s++){let i=this.bufs[s],a=o,c=a+i.byteLength;if(o=c,e>=c)continue;let u=e>=a&&e<c,l=r>a&&r<=c;if(u&&l){if(e===a&&r===c){n.push(i);break}let d=e-a;n.push(i.subarray(d,d+(r-e)));break}if(u){if(e===0){n.push(i);continue}n.push(i.subarray(e-a));continue}if(l){if(r===c){n.push(i);break}n.push(i.subarray(0,r-a));break}n.push(i)}return{bufs:n,length:r-e}}indexOf(e,r=0){if(!Qe(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 s=256,i=new Int32Array(s);for(let d=0;d<s;d++)i[d]=-1;for(let d=0;d<o;d++)i[n[d]]=d;let a=i,c=this.byteLength-n.byteLength,u=n.byteLength-1,l;for(let d=r;d<=c;d+=l){l=0;for(let h=u;h>=0;h--){let g=this.get(d+h);if(n[h]!==g){l=Math.max(1,h-a[g]);break}}if(l===0)return d}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=Z(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=j(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=j(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=j(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=Z(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=j(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=j(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=j(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=j(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=j(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(!Xe(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,s)=>o+s.byteLength,0)),n.length=r,n}};var Xr={};V(Xr,{base10:()=>$a});var $a=xe({prefix:"9",name:"base10",alphabet:"0123456789"});var Qr={};V(Qr,{base16:()=>za,base16upper:()=>Va});var za=I({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Va=I({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Kr={};V(Kr,{base2:()=>ja});var ja=I({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Jr={};V(Jr,{base256emoji:()=>Xa});var Ao=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}"),qa=Ao.reduce((t,e,r)=>(t[r]=e,t),[]),Wa=Ao.reduce((t,e,r)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return t[n]=r,t},[]);function Ga(t){return t.reduce((e,r)=>(e+=qa[r],e),"")}function Ha(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=Wa[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(o)}return new Uint8Array(e)}var Xa=Ve({prefix:"\u{1F680}",name:"base256emoji",encode:Ga,decode:Ha});var en={};V(en,{base64:()=>Yr,base64pad:()=>Qa,base64url:()=>Zr,base64urlpad:()=>Ka});var Yr=I({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Qa=I({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Zr=I({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Ka=I({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var tn={};V(tn,{base8:()=>Ja});var Ja=I({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var rn={};V(rn,{identity:()=>Ya});var Ya=Ve({prefix:"\0",name:"identity",encode:t=>lo(t),decode:t=>fo(t)});var Yl=new TextEncoder,Zl=new TextDecoder;var sn={};V(sn,{sha256:()=>rc,sha512:()=>nc});var tc=20;function on({name:t,code:e,encode:r,minDigestLength:n,maxDigestLength:o}){return new nn(t,e,r,n,o)}var nn=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,r,n,o,s){this.name=e,this.code=r,this.encode=n,this.minDigestLength=o??tc,this.maxDigestLength=s}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?To(n,this.code,r?.truncate):n.then(o=>To(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function To(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 Ge(e,t)}function Fo(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}var rc=on({name:"sha2-256",code:18,encode:Fo("SHA-256")}),nc=on({name:"sha2-512",code:19,encode:Fo("SHA-512")});var mt={...rn,...Kr,...tn,...Xr,...Qr,...jr,...qr,...Vr,...en,...Jr},ld={...sn,...Hr};function No(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var Uo=No("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),an=No("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=Z(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),oc={utf8:Uo,"utf-8":Uo,hex:mt.base16,latin1:an,ascii:an,binary:an,...mt},Qt=oc;function T(t,e="utf8"){let r=Qt[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}function Te(t,e="utf8"){let r=Qt[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.encoder.encode(t).substring(1)}function ko(t=32){let e=typeof globalThis=="object"?globalThis.crypto:null;if(typeof e?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");return e.getRandomValues(new Uint8Array(t))}var sc=Math.pow(2,7),ic=Math.pow(2,14),ac=Math.pow(2,21),cn=Math.pow(2,28),un=Math.pow(2,35),fn=Math.pow(2,42),ln=Math.pow(2,49),_=128,M=127;function P(t){if(t<sc)return 1;if(t<ic)return 2;if(t<ac)return 3;if(t<cn)return 4;if(t<un)return 5;if(t<fn)return 6;if(t<ln)return 7;if(Number.MAX_SAFE_INTEGER!=null&&t>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Kt(t,e,r=0){switch(P(t)){case 8:e[r++]=t&255|_,t/=128;case 7:e[r++]=t&255|_,t/=128;case 6:e[r++]=t&255|_,t/=128;case 5:e[r++]=t&255|_,t/=128;case 4:e[r++]=t&255|_,t>>>=7;case 3:e[r++]=t&255|_,t>>>=7;case 2:e[r++]=t&255|_,t>>>=7;case 1:{e[r++]=t&255,t>>>=7;break}default:throw new Error("unreachable")}return e}function cc(t,e,r=0){switch(P(t)){case 8:e.set(r++,t&255|_),t/=128;case 7:e.set(r++,t&255|_),t/=128;case 6:e.set(r++,t&255|_),t/=128;case 5:e.set(r++,t&255|_),t/=128;case 4:e.set(r++,t&255|_),t>>>=7;case 3:e.set(r++,t&255|_),t>>>=7;case 2:e.set(r++,t&255|_),t>>>=7;case 1:{e.set(r++,t&255),t>>>=7;break}default:throw new Error("unreachable")}return e}function uc(t,e){let r=t[e],n=0;if(n+=r&M,r<_||(r=t[e+1],n+=(r&M)<<7,r<_)||(r=t[e+2],n+=(r&M)<<14,r<_)||(r=t[e+3],n+=(r&M)<<21,r<_)||(r=t[e+4],n+=(r&M)*cn,r<_)||(r=t[e+5],n+=(r&M)*un,r<_)||(r=t[e+6],n+=(r&M)*fn,r<_)||(r=t[e+7],n+=(r&M)*ln,r<_))return n;throw new RangeError("Could not decode varint")}function fc(t,e){let r=t.get(e),n=0;if(n+=r&M,r<_||(r=t.get(e+1),n+=(r&M)<<7,r<_)||(r=t.get(e+2),n+=(r&M)<<14,r<_)||(r=t.get(e+3),n+=(r&M)<<21,r<_)||(r=t.get(e+4),n+=(r&M)*cn,r<_)||(r=t.get(e+5),n+=(r&M)*un,r<_)||(r=t.get(e+6),n+=(r&M)*fn,r<_)||(r=t.get(e+7),n+=(r&M)*ln,r<_))return n;throw new RangeError("Could not decode varint")}function Jt(t,e,r=0){return e==null&&(e=Z(P(t))),e instanceof Uint8Array?Kt(t,e,r):cc(t,e,r)}function me(t,e=0){return t instanceof Uint8Array?uc(t,e):fc(t,e)}function Yt(t){if(isNaN(t)||t<=0)throw new $("random bytes length must be a Number bigger than 0");return ko(t)}var dn={32:16777619n,64:1099511628211n,128:309485009821345068724781371n,256:374144419156711147060143317175368453031918731002211n,512:35835915874844867368919076489095108449946327955754392558399825615420669938882575126094039892345713852759n,1024:5016456510113118655434598811035278955030765345404790744303017523831112055108147451509157692220295382716162651878526895249385292291816524375083746691371804094271873160484737966720260389217684476157468082573n},Bo={32:2166136261n,64:14695981039346656037n,128:144066263297769815596495629667062367629n,256:100029257958052580907070968620625704837092796014241193945225284501741471925557n,512:9659303129496669498009435400716310466090418745672637896108374329434462657994582932197716438449813051892206539805784495328239340083876191928701583869517785n,1024:14197795064947621068722070641403218320880622795441933960878474914617582723252296732303717722150864096521202355549365628174669108571814760471015076148029755969804077320157692458563003215304957150157403644460363550505412711285966361610267868082893823963790439336411086884584107735010676915n},Mo=new globalThis.TextEncoder;function lc(t,e){let r=dn[e],n=Bo[e];for(let o=0;o<t.length;o++)n^=BigInt(t[o]),n=BigInt.asUintN(e,n*r);return n}function dc(t,e,r){if(r.length===0)throw new Error("The `utf8Buffer` option must have a length greater than zero");let n=dn[e],o=Bo[e],s=t;for(;s.length>0;){let i=Mo.encodeInto(s,r);s=s.slice(i.read);for(let a=0;a<i.written;a++)o^=BigInt(r[a]),o=BigInt.asUintN(e,o*n)}return o}function hn(t,{size:e=32,utf8Buffer:r}={}){if(!dn[e])throw new Error("The `size` option must be one of 32, 64, 128, 256, 512, or 1024");if(typeof t=="string"){if(r)return dc(t,e,r);t=Mo.encode(t)}return lc(t,e)}var Ee={hash:t=>Number(hn(t,{size:32})),hashV:(t,e)=>hc(Ee.hash(t,e))};function hc(t){let e=t.toString(16);return e.length%2===1&&(e=`0${e}`),T(e,"base16")}var mc=Math.LN2*Math.LN2,gt=class{seeds;bits;buffer;constructor(e={}){e.seeds!=null?this.seeds=e.seeds:this.seeds=gc(e.hashes??8),this.bits=e.bits??1024,this.buffer=j(Math.ceil(this.bits/8))}add(e){typeof e=="string"&&(e=T(e));for(let r=0;r<this.seeds.length;r++){let o=Ee.hash(e,this.seeds[r])%this.bits;this.setbit(o)}}has(e){typeof e=="string"&&(e=T(e));for(let r=0;r<this.seeds.length;r++){let o=Ee.hash(e,this.seeds[r])%this.bits;if(!this.getbit(o))return!1}return!0}clear(){this.buffer.fill(0)}setbit(e){let r=Math.floor(e/8),n=e%8,o=this.buffer[r];o|=1<<n,this.buffer[r]=o}getbit(e){let r=Math.floor(e/8),n=e%8;return(this.buffer[r]&1<<n)!==0}};function Po(t,e=.005){let r=pc(t,e);return new gt(r)}function pc(t,e=.005){let r=Math.round(-1*t*Math.log(e)/mc),n=Math.round(r/t*Math.LN2);return{bits:r,hashes:n}}function gc(t){let e,r,n=[];for(let o=0;o<t;o++)for(e=new A(Yt(4)),n[o]=e.getUint32(0,!0),r=0;r<o;r++)if(n[o]===n[r]){o--;break}return n}var mn=64,ee=class{fp;h;seed;constructor(e,r,n,o=2){if(o>mn)throw new TypeError("Invalid Fingerprint Size");let s=r.hashV(e,n),i=j(o);for(let a=0;a<i.length;a++)i[a]=s[a];i.length===0&&(i[0]=7),this.fp=i,this.h=r,this.seed=n}hash(){return this.h.hash(this.fp,this.seed)}equals(e){return e?.fp instanceof Uint8Array?Xe(this.fp,e.fp):!1}};function De(t,e){return Math.floor(Math.random()*(e-t))+t}var Fe=class{contents;constructor(e){this.contents=new Array(e).fill(null)}has(e){if(!(e instanceof ee))throw new TypeError("Invalid Fingerprint");return this.contents.some(r=>e.equals(r))}add(e){if(!(e instanceof ee))throw new TypeError("Invalid Fingerprint");for(let r=0;r<this.contents.length;r++)if(this.contents[r]==null)return this.contents[r]=e,!0;return!0}swap(e){if(!(e instanceof ee))throw new TypeError("Invalid Fingerprint");let r=De(0,this.contents.length-1),n=this.contents[r];return this.contents[r]=e,n}remove(e){if(!(e instanceof ee))throw new TypeError("Invalid Fingerprint");let r=this.contents.findIndex(n=>e.equals(n));return r>-1?(this.contents[r]=null,!0):!1}};var yc=500,ve=class{bucketSize;filterSize;fingerprintSize;buckets;count;hash;seed;constructor(e){this.filterSize=e.filterSize,this.bucketSize=e.bucketSize??4,this.fingerprintSize=e.fingerprintSize??2,this.count=0,this.buckets=[],this.hash=e.hash??Ee,this.seed=e.seed??De(0,Math.pow(2,10))}add(e){typeof e=="string"&&(e=T(e));let r=new ee(e,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(e,this.seed)%this.filterSize,o=(n^r.hash())%this.filterSize;if(this.buckets[n]==null&&(this.buckets[n]=new Fe(this.bucketSize)),this.buckets[o]==null&&(this.buckets[o]=new Fe(this.bucketSize)),this.buckets[n].add(r)||this.buckets[o].add(r))return this.count++,!0;let s=[n,o],i=s[De(0,s.length-1)];this.buckets[i]==null&&(this.buckets[i]=new Fe(this.bucketSize));for(let a=0;a<yc;a++){let c=this.buckets[i].swap(r);if(c!=null&&(i=(i^c.hash())%this.filterSize,this.buckets[i]==null&&(this.buckets[i]=new Fe(this.bucketSize)),this.buckets[i].add(c)))return this.count++,!0}return!1}has(e){typeof e=="string"&&(e=T(e));let r=new ee(e,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(e,this.seed)%this.filterSize,o=this.buckets[n]?.has(r)??!1;if(o)return o;let s=(n^r.hash())%this.filterSize;return this.buckets[s]?.has(r)??!1}remove(e){typeof e=="string"&&(e=T(e));let r=new ee(e,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(e,this.seed)%this.filterSize,o=this.buckets[n]?.remove(r)??!1;if(o)return this.count--,o;let s=(n^r.hash())%this.filterSize,i=this.buckets[s]?.remove(r)??!1;return i&&this.count--,i}get reliable(){return Math.floor(100*(this.count/this.filterSize))<=90}},bc={1:.5,2:.84,4:.95,8:.98};function xc(t=.001){return t>.002?2:t>1e-5?4:8}function pn(t,e=.001){let r=xc(e),n=bc[r],o=Math.round(t/n),s=Math.min(Math.ceil(Math.log2(1/e)+Math.log2(2*r)),mn);return{filterSize:o,bucketSize:r,fingerprintSize:s}}function Oo(t,e=.005){let r=pn(t,e);return new ve(r)}var yt=class{filterSize;bucketSize;fingerprintSize;scale;filterSeries;hash;seed;constructor(e){this.bucketSize=e.bucketSize??4,this.filterSize=e.filterSize??(1<<18)/this.bucketSize,this.fingerprintSize=e.fingerprintSize??2,this.scale=e.scale??2,this.hash=e.hash??Ee,this.seed=e.seed??De(0,Math.pow(2,10)),this.filterSeries=[new ve({filterSize:this.filterSize,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed})]}add(e){if(typeof e=="string"&&(e=T(e)),this.has(e))return!0;let r=this.filterSeries.find(n=>n.reliable);if(r==null){let n=this.filterSize*Math.pow(this.scale,this.filterSeries.length);r=new ve({filterSize:n,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed}),this.filterSeries.push(r)}return r.add(e)}has(e){typeof e=="string"&&(e=T(e));for(let r=0;r<this.filterSeries.length;r++)if(this.filterSeries[r].has(e))return!0;return!1}remove(e){typeof e=="string"&&(e=T(e));for(let r=0;r<this.filterSeries.length;r++)if(this.filterSeries[r].remove(e))return!0;return!1}get count(){return this.filterSeries.reduce((e,r)=>e+r.count,0)}};function Ro(t,e=.001,r){return new yt({...pn(t,e),...r??{}})}function q(t){let e=t.getComponents(),r={},n=0;if(e[n]?.name==="ip6zone"&&(r.zone=`${e[n].value}`,n++),e[n].name==="ip4"||e[n].name==="ip6"||e[n].name==="dns"||e[n].name==="dns4"||e[n].name==="dns6"?(r.type=e[n].name,r.host=e[n].value,n++):e[n].name==="dnsaddr"&&(r.type=e[n].name,r.host=`_dnsaddr.${e[n].value}`,n++),(e[n]?.name==="tcp"||e[n]?.name==="udp")&&(r.protocol=e[n].name==="tcp"?"tcp":"udp",r.port=parseInt(`${e[n].value}`),n++),e[n]?.name==="ipcidr"&&(r.type==="ip4"?r.cidr=parseInt(`${e[n].value}`):r.type==="ip6"&&(r.cidr=`${e[n].value}`),n++),r.type==null||r.host==null)throw new $(`Multiaddr ${t} was not an IPv4, IPv6, DNS, DNS4, DNS6 or DNSADDR address`);return e[n]?.name==="tls"&&e[n+1]?.name==="sni"&&(r.sni=e[n+1].value,n+=2),r}var Zt=class{index=0;input="";new(e){return this.index=0,this.input=e,this}readAtomically(e){let r=this.index,n=e();return n===void 0&&(this.index=r),n}parseWith(e){let r=e();if(this.index===this.input.length)return r}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(e){return this.readAtomically(()=>{let r=this.readChar();if(r===e)return r})}readSeparator(e,r,n){return this.readAtomically(()=>{if(!(r>0&&this.readGivenChar(e)===void 0))return n()})}readNumber(e,r,n,o){return this.readAtomically(()=>{let s=0,i=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",u=2**(8*o)-1;for(;;){let l=this.readAtomically(()=>{let d=this.readChar();if(d===void 0)return;let h=Number.parseInt(d,e);if(!Number.isNaN(h))return h});if(l===void 0)break;if(s*=e,s+=l,s>u||(i+=1,r!==void 0&&i>r))return}if(i!==0)return!n&&c&&i>1?void 0:s})}readIPv4Addr(){return this.readAtomically(()=>{let e=new Uint8Array(4);for(let r=0;r<e.length;r++){let n=this.readSeparator(".",r,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;e[r]=n}return e})}readIPv6Addr(){let e=r=>{for(let n=0;n<r.length/2;n++){let o=n*2;if(n<r.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return r[o]=i[0],r[o+1]=i[1],r[o+2]=i[2],r[o+3]=i[3],[o+4,!0]}let s=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(s===void 0)return[o,!1];r[o]=s>>8,r[o+1]=s&255}return[r.length,!1]};return this.readAtomically(()=>{let r=new Uint8Array(16),[n,o]=e(r);if(n===16)return r;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let s=new Uint8Array(14),i=16-(n+2),[a]=e(s.subarray(0,i));return r.set(s.subarray(0,a),16-a),r})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var $o=45,wc=15,Ke=new Zt;function er(t){if(!(t.length>wc))return Ke.new(t).parseWith(()=>Ke.readIPv4Addr())}function tr(t){if(t.includes("%")&&(t=t.split("%")[0]),!(t.length>$o))return Ke.new(t).parseWith(()=>Ke.readIPv6Addr())}function Je(t,e=!1){if(t.includes("%")&&(t=t.split("%")[0]),t.length>$o)return;let r=Ke.new(t).parseWith(()=>Ke.readIPAddr());if(r)return e&&r.length===4?Uint8Array.from([0,0,0,0,0,0,0,0,0,0,255,255,r[0],r[1],r[2],r[3]]):r}function zo(t,e,r){let n=0;for(let o of t)if(!(n<e)){if(n>r)break;if(o!==255)return!1;n++}return!0}function Vo(t,e,r,n){let o=0;for(let s of t)if(!(o<r)){if(o>n)break;if(s!==e[o])return!1;o++}return!0}function gn(t){switch(t.length){case Ue:return t.join(".");case Ne:{let e=[];for(let r=0;r<t.length;r++)r%2===0&&e.push(t[r].toString(16).padStart(2,"0")+t[r+1].toString(16).padStart(2,"0"));return e.join(":")}default:throw new Error("Invalid ip length")}}function jo(t){let e=0;for(let[r,n]of t.entries()){if(n===255){e+=8;continue}for(;(n&128)!=0;)e++,n=n<<1;if((n&128)!=0)return-1;for(let o=r+1;o<t.length;o++)if(t[o]!=0)return-1;break}return e}function qo(t){let e="0x";for(let r of t)e+=(r>>4).toString(16)+(r&15).toString(16);return e}var Ue=4,Ne=16,mh=parseInt("0xFFFF",16),Ec=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function bt(t,e){e.length===Ne&&t.length===Ue&&zo(e,0,11)&&(e=e.slice(12)),e.length===Ue&&t.length===Ne&&Vo(t,Ec,0,11)&&(t=t.slice(12));let r=t.length;if(r!=e.length)throw new Error("Failed to mask ip");let n=new Uint8Array(r);for(let o=0;o<r;o++)n[o]=t[o]&e[o];return n}function Wo(t,e){if(typeof e=="string"&&(e=Je(e)),e==null)throw new Error("Invalid ip");if(e.length!==t.network.length)return!1;for(let r=0;r<e.length;r++)if((t.network[r]&t.mask[r])!==(e[r]&t.mask[r]))return!1;return!0}function yn(t){let[e,r]=t.split("/");if(!e||!r)throw new Error("Failed to parse given CIDR: "+t);let n=Ue,o=er(e);if(o==null&&(n=Ne,o=tr(e),o==null))throw new Error("Failed to parse given CIDR: "+t);let s=parseInt(r,10);if(Number.isNaN(s)||String(s).length!==r.length||s<0||s>n*8)throw new Error("Failed to parse given CIDR: "+t);let i=bn(s,8*n);return{network:bt(o,i),mask:i}}function bn(t,e){if(e!==8*Ue&&e!==8*Ne)throw new Error("Invalid CIDR mask");if(t<0||t>e)throw new Error("Invalid CIDR mask");let r=e/8,n=new Uint8Array(r);for(let o=0;o<r;o++){if(t>=8){n[o]=255,t-=8;continue}n[o]=255-(255>>t),t=0}return n}var xt=class{constructor(e,r){if(r==null)({network:this.network,mask:this.mask}=yn(e));else{let n=Je(e);if(n==null)throw new Error("Failed to parse network");r=String(r);let o=parseInt(r,10);if(Number.isNaN(o)||String(o).length!==r.length||o<0||o>n.length*8){let s=Je(r);if(s==null)throw new Error("Failed to parse mask");this.mask=s}else this.mask=bn(o,8*n.length);this.network=bt(n,this.mask)}}contains(e){return Wo({network:this.network,mask:this.mask},e)}toString(){let e=jo(this.mask),r=e!==-1?String(e):qo(this.mask);return gn(this.network)+"/"+r}};function rr(t,e){return new xt(t).contains(e)}function vc(t){try{let e=q(t);switch(e.type){case"ip6":return rr("2000::/3",e.host);default:return!1}}catch{return!1}}function _c(t){try{let e=q(t);switch(e.type){case"ip4":return e.host.startsWith("169.254.");case"ip6":return e.host.toLowerCase().startsWith("fe80");default:return!1}}catch{return!1}}function Go(t){return/^127\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/i.test(t)||/^::1$/.test(t)}function Sc(t){try{let e=q(t);switch(e.type){case"ip4":case"ip6":return Go(e.host);default:return!1}}catch{return!1}}function Cc(t){try{return q(t),!0}catch{return!1}}function _e(t){return!!er(t)}function Se(t){return!!tr(t)}var Xo=Ki(Ho(),1),Lc=["0.0.0.0/8","10.0.0.0/8","100.64.0.0/10","127.0.0.0/8","169.254.0.0/16","172.16.0.0/12","192.0.0.0/24","192.0.0.0/29","192.0.0.8/32","192.0.0.9/32","192.0.0.10/32","192.0.0.170/32","192.0.0.171/32","192.0.2.0/24","192.31.196.0/24","192.52.193.0/24","192.88.99.0/24","192.168.0.0/16","192.175.48.0/24","198.18.0.0/15","198.51.100.0/24","203.0.113.0/24","240.0.0.0/4","255.255.255.255/32"],Ic=Lc.map(t=>new Xo.Netmask(t));function xn(t){for(let e of Ic)if(e.contains(t))return!0;return!1}function Ac(t){return/^::ffff:([0-9a-fA-F]{1,4}):([0-9a-fA-F]{1,4})$/.test(t)}function Tc(t){let e=t.split(":");if(e.length<2)return!1;let r=e[e.length-1].padStart(4,"0"),n=e[e.length-2].padStart(4,"0"),o=`${parseInt(n.substring(0,2),16)}.${parseInt(n.substring(2),16)}.${parseInt(r.substring(0,2),16)}.${parseInt(r.substring(2),16)}`;return xn(o)}function Dc(t){return/^::ffff:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(t)}function Fc(t){let e=t.split(":"),r=e[e.length-1];return xn(r)}function Uc(t){return/^::$/.test(t)||/^::1$/.test(t)||/^64:ff9b::([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(t)||/^100::([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(t)||/^2001::([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(t)||/^2001:2[0-9a-fA-F]:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(t)||/^2001:db8:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(t)||/^2002:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(t)||/^f[c-d]([0-9a-fA-F]{2,2}):/i.test(t)||/^fe[8-9a-bA-B][0-9a-fA-F]:/i.test(t)||/^ff([0-9a-fA-F]{2,2}):/i.test(t)}function wn(t){if(_e(t))return xn(t);if(Ac(t))return Tc(t);if(Dc(t))return Fc(t);if(Se(t))return Uc(t)}function Nc(t){try{let e=q(t);switch(e.type){case"ip4":case"ip6":return wn(e.host)??!1;default:return e.host==="localhost"}}catch{return!1}}function te(){let t={};return t.promise=new Promise((e,r)=>{t.resolve=e,t.reject=r}),t}var nr=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}},Ye=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new nr(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 nr(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 En=class extends Error{type;code;constructor(e,r){super(e??"The operation was aborted"),this.type="aborted",this.code=r??"ABORT_ERR"}};function ce(t={}){return kc(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 kc(t,e){e=e??{};let r=e.onEnd,n=new Ye,o,s,i,a=te(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((b,w)=>{s=C=>{s=null,n.push(C);try{b(t(n))}catch(L){w(L)}return o}}):t(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=te()})}},u=b=>s!=null?s(b):(n.push(b),o),l=b=>(n=new Ye,s!=null?s({error:b}):(n.push({error:b}),o)),d=b=>{if(i)return o;if(e?.objectMode!==!0&&b?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return u({done:!1,value:b})},h=b=>i?o:(i=!0,b!=null?l(b):u({done:!0})),g=()=>(n=new Ye,h(),{done:!0}),x=b=>(h(b),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:g,throw:x,push:d,end:h,get readableLength(){return n.size},onEmpty:async b=>{let w=b?.signal;if(w?.throwIfAborted(),n.isEmpty())return;let C,L;w!=null&&(C=new Promise((O,k)=>{L=()=>{k(new En)},w.addEventListener("abort",L)}));try{await Promise.race([a.promise,C])}finally{L!=null&&w!=null&&w?.removeEventListener("abort",L)}}},r==null)return o;let v=o;return o={[Symbol.asyncIterator](){return this},next(){return v.next()},throw(b){return v.throw(b),r!=null&&(r(b),r=void 0),{done:!0}},return(){return v.return(),r!=null&&(r(),r=void 0),{done:!0}},push:d,end(b){return v.end(b),r!=null&&(r(b),r=void 0),o},get readableLength(){return v.readableLength},onEmpty:b=>v.onEmpty(b)},o}var vn=class t extends Error{name="TimeoutError";constructor(e,r){super(e,r),Error.captureStackTrace?.(this,t)}},Qo=t=>t.reason??new DOMException("This operation was aborted.","AbortError");function _n(t,e){let{milliseconds:r,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout},signal:i}=e,a,c,l=new Promise((d,h)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(i?.aborted){h(Qo(i));return}if(i&&(c=()=>{h(Qo(i))},i.addEventListener("abort",c,{once:!0})),t.then(d,h),r===Number.POSITIVE_INFINITY)return;let g=new vn;a=s.setTimeout.call(void 0,()=>{if(n){try{d(n())}catch(x){h(x)}return}typeof t.cancel=="function"&&t.cancel(),o===!1?d():o instanceof Error?h(o):(g.message=o??`Promise timed out after ${r} milliseconds`,h(g))},r)}).finally(()=>{l.clear(),c&&i&&i.removeEventListener("abort",c)});return l.clear=()=>{s.clearTimeout.call(void 0,a),a=void 0},l}var Bc=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 Mc(t,e,r){let n,o=new Promise((s,i)=>{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:u,removeListener:l}=Bc(t),d=async(...g)=>{let x=r.multiArgs?g:g[0];if(r.filter)try{if(!await r.filter(x))return}catch(v){n(),i(v);return}c.push(x),r.count===c.length&&(n(),s(c))},h=(...g)=>{n(),i(r.rejectionMultiArgs?g:g[0])};n=()=>{for(let g of a)l(g,d);for(let g of r.rejectionEvents)a.includes(g)||l(g,h)};for(let g of a)u(g,d);for(let g of r.rejectionEvents)a.includes(g)||u(g,h);r.signal&&r.signal.addEventListener("abort",()=>{h(r.signal.reason)},{once:!0}),r.resolveImmediately&&s(c)});if(o.cancel=n,typeof r.timeout=="number"){let s=_n(o,{milliseconds:r.timeout});return s.cancel=()=>{n(),s.clear()},s}return o}function D(t,e,r){typeof r=="function"&&(r={filter:r}),r={...r,count:1,resolveImmediately:!1};let n=Mc(t,e,r),o=n.then(s=>s[0]);return o.cancel=n.cancel,o}function Ze(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 Et=class extends Error{remainingPoints;msBeforeNext;consumedPoints;isFirstInDuration;constructor(e="Rate limit exceeded",r){super(e),this.name="RateLimitError",this.remainingPoints=r.remainingPoints,this.msBeforeNext=r.msBeforeNext,this.consumedPoints=r.consumedPoints,this.isFirstInDuration=r.isFirstInDuration}},vt=class extends Error{static name="QueueFullError";constructor(e="The queue was full"){super(e),this.name="QueueFullError"}},Ce=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"},_t=class extends Error{static name="MaxEarlyStreamsError";name="MaxEarlyStreamsError"},St=class extends Error{static name="StreamClosedError";name="StreamClosedError"};function Pc(t){return t.reason}async function F(t,e,r){if(e==null)return t;let n=r?.translateError??Pc;if(e.aborted)return t.catch(()=>{}),Promise.reject(n(e));let o;try{return await Promise.race([t,new Promise((s,i)=>{o=()=>{i(n(e))},e.addEventListener("abort",o)})])}finally{o!=null&&e.removeEventListener("abort",o)}}var or=class{deferred;signal;constructor(e){this.signal=e,this.deferred=te(),this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(this.signal?.reason??new de)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function Oc(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var sr=class{id;fn;options;recipients;status;timeline;controller;constructor(e,r){this.id=Oc(),this.status="queued",this.fn=e,this.options=r,this.recipients=[],this.timeline={created:Date.now()},this.controller=new AbortController,this.controller.signal,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 de),this.cleanup())}async join(e={}){let r=new or(e.signal);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 F(this.fn({...this.options??{},signal:this.controller.signal}),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.cleanup(),e.signal?.removeEventListener("abort",this.onAbort)})}};var re=class extends ie{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=Ze(this.emitEmpty.bind(this),1),this.emitIdle=Ze(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 vt;let n=new sr(e,r);return this.enqueue(n),this.safeDispatchEvent("add"),this.tryToStartAnother(),n.join(r).then(o=>(this.safeDispatchEvent("completed",{detail:o}),this.safeDispatchEvent("success",{detail:{job:n,result:o}}),o)).catch(o=>{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:o}}),o})}clear(){this.queue.splice(0,this.queue.length)}abort(){this.queue.forEach(e=>{e.abort(new de)}),this.clear()}async onEmpty(e){this.size!==0&&await D(this,"empty",e)}async onSizeLessThan(e,r){this.size<e||await D(this,"next",{...r,filter:()=>this.size<e})}async onIdle(e){this.pending===0&&this.size===0||await D(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=ce({objectMode:!0}),n=c=>{c!=null?this.abort():this.clear(),r.end(c)},o=c=>{c.detail!=null&&r.push(c.detail)},s=c=>{n(c.detail.error)},i=()=>{n()},a=()=>{n(new de("Queue aborted"))};this.addEventListener("completed",o),this.addEventListener("failure",s),this.addEventListener("idle",i),e?.signal?.addEventListener("abort",a);try{yield*r}finally{this.removeEventListener("completed",o),this.removeEventListener("failure",s),this.removeEventListener("idle",i),e?.signal?.removeEventListener("abort",a),n()}}};var Rc=Math.pow(2,20)*4,ke=class extends ie{status;timeline;inactivityTimeout;maxReadBufferLength;maxWriteBufferLength;log;direction;maxMessageSize;readStatus;writeStatus;remoteReadStatus;remoteWriteStatus;writableNeedsDrain;readBuffer;writeBuffer;sendingData;onDrainPromise;constructor(e){super(),this.status="open",this.log=e.log,this.direction=e.direction??"outbound",this.inactivityTimeout=e.inactivityTimeout??12e4,this.maxReadBufferLength=e.maxReadBufferLength??Rc,this.maxWriteBufferLength=e.maxWriteBufferLength,this.maxMessageSize=e.maxMessageSize,this.readBuffer=new A,this.writeBuffer=new A,this.readStatus="readable",this.remoteReadStatus="readable",this.writeStatus="writable",this.remoteWriteStatus="writable",this.sendingData=!1,this.writableNeedsDrain=!1,this.timeline={open:Date.now()},this.processSendQueue=this.processSendQueue.bind(this);let r=()=>{this.writableNeedsDrain&&(this.log.trace("drain event received, continue sending data"),this.writableNeedsDrain=!1,this.processSendQueue()),this.onDrainPromise?.resolve()};this.addEventListener("drain",r);let n=o=>{this.onDrainPromise?.reject(o.error??new St)};this.addEventListener("close",n)}get readBufferLength(){return this.readBuffer.byteLength}get writeBufferLength(){return this.writeBuffer.byteLength}async onDrain(e){return this.writableNeedsDrain!==!0?Promise.resolve():(this.onDrainPromise==null&&(this.onDrainPromise=Promise.withResolvers()),F(this.onDrainPromise.promise,e?.signal))}async*[Symbol.asyncIterator](){if(this.readStatus!=="readable"&&this.readStatus!=="paused")return;let e=ce(),r=s=>{e.push(s.data)};this.addEventListener("message",r);let n=s=>{e.end(s.error)};this.addEventListener("close",n);let o=()=>{e.end()};this.addEventListener("remoteCloseWrite",o);try{yield*e}finally{this.removeEventListener("message",r),this.removeEventListener("close",n),this.removeEventListener("remoteCloseWrite",o)}}isReadable(){return this.status==="open"}send(e){if(this.writeStatus==="closed"||this.writeStatus==="closing")throw new be(`Cannot write to a stream that is ${this.writeStatus}`);return this.log.trace("append %d bytes to write buffer",e.byteLength),this.writeBuffer.append(e),this.processSendQueue()}abort(e){if(!(this.status==="aborted"||this.status==="reset"||this.status==="closed")){this.log.error("abort with error - %e",e),this.status="aborted",this.readBuffer.byteLength>0&&this.readBuffer.consume(this.readBuffer.byteLength),this.writeBuffer.byteLength>0&&(this.writeBuffer.consume(this.writeBuffer.byteLength),this.safeDispatchEvent("idle")),this.writeStatus="closed",this.remoteWriteStatus="closed",this.readStatus="closed",this.remoteReadStatus="closed",this.timeline.close=Date.now();try{this.sendReset(e)}catch(r){this.log("failed to send reset to remote - %e",r)}this.dispatchEvent(new Gt(e))}}pause(){if(this.readStatus==="closed"||this.readStatus==="closing")throw new be("Cannot pause a stream that is closing/closed");this.readStatus!=="paused"&&(this.readStatus="paused",this.sendPause())}resume(){if(this.readStatus==="closed"||this.readStatus==="closing")throw new be("Cannot resume a stream that is closing/closed");this.readStatus!=="readable"&&(this.readStatus="readable",this.dispatchReadBuffer(),this.sendResume())}push(e){if(this.readStatus==="closed"||this.readStatus==="closing")throw new be(`Cannot push data onto a stream that is ${this.readStatus}`);if(e.byteLength!==0){if(this.readBuffer.append(e),this.readStatus==="paused"||this.listenerCount("message")===0){this.checkReadBufferLength();return}setTimeout(()=>{this.dispatchReadBuffer()},0)}}unshift(e){if(this.readStatus==="closed"||this.readStatus==="closing")throw new be(`Cannot push data onto a stream that is ${this.readStatus}`);if(e.byteLength!==0){if(this.readBuffer.prepend(e),this.readStatus==="paused"||this.listenerCount("message")===0){this.checkReadBufferLength();return}setTimeout(()=>{this.dispatchReadBuffer()},0)}}onData(e){if(e.byteLength!==0){if(this.readStatus==="closing"||this.readStatus==="closed"){this.log("ignoring data - read status %s",this.readStatus);return}this.readBuffer.append(e),this.dispatchReadBuffer()}}addEventListener(...e){super.addEventListener.apply(this,e),e[0]==="message"&&this.readBuffer.byteLength>0&&queueMicrotask(()=>{this.dispatchReadBuffer()})}onRemoteReset(){this.log("remote reset"),this.status="reset",this.writeStatus="closed",this.remoteWriteStatus="closed",this.remoteReadStatus="closed",this.timeline.close=Date.now(),this.readBuffer.byteLength===0&&(this.readStatus="closed");let e=new Wt;this.dispatchEvent(new Ht(e))}onTransportClosed(e){this.log("transport closed"),this.readStatus==="readable"&&this.readBuffer.byteLength===0&&(this.log("close readable end after transport closed and read buffer is empty"),this.readStatus="closed"),this.remoteReadStatus!=="closed"&&(this.remoteReadStatus="closed"),this.remoteWriteStatus!=="closed"&&(this.remoteWriteStatus="closed"),this.writeStatus!=="closed"&&(this.writeStatus="closed"),e!=null?this.abort(e):(this.status==="open"||this.status==="closing")&&(this.timeline.close=Date.now(),this.status="closed",this.writeStatus="closed",this.remoteWriteStatus="closed",this.remoteReadStatus="closed",this.dispatchEvent(new ze))}onRemoteCloseWrite(){this.remoteWriteStatus!=="closed"&&(this.log.trace("on remote close write"),this.remoteWriteStatus="closed",this.safeDispatchEvent("remoteCloseWrite"),this.writeStatus==="closed"&&this.onTransportClosed())}onRemoteCloseRead(){this.log.trace("on remote close read"),this.remoteReadStatus="closed",this.writeBuffer.byteLength>0&&(this.writeBuffer.consume(this.writeBuffer.byteLength),this.safeDispatchEvent("idle"))}processSendQueue(){if(this.writableNeedsDrain)return this.log.trace("not processing send queue as drain is required"),this.checkWriteBufferLength(),!1;if(this.writeBuffer.byteLength===0)return this.log.trace("not processing send queue as no bytes to send"),!0;if(this.sendingData)return this.log.trace("not processing send queue as already sending data"),!0;this.sendingData=!0,this.log.trace("processing send queue with %d queued bytes",this.writeBuffer.byteLength);try{let e=!0,r=this.writeBuffer.byteLength,n=0;for(;this.writeBuffer.byteLength>0;){let o=Math.min(this.maxMessageSize??this.writeBuffer.byteLength,this.writeBuffer.byteLength);if(o===0){e=!1;break}let s=this.writeBuffer.sublist(0,o),i=new A(s);this.writeBuffer.consume(s.byteLength);let a=this.sendData(s);if(e=a.canSendMore,n+=a.sentBytes,a.sentBytes!==i.byteLength&&(i.consume(a.sentBytes),this.writeBuffer.prepend(i)),!e)break}return e||(this.log.trace("sent %d/%d bytes, pausing sending because underlying stream is full, %d bytes left in the write buffer",n,r,this.writeBuffer.byteLength),this.writableNeedsDrain=!0,this.checkWriteBufferLength()),this.writeBuffer.byteLength===0&&this.safeDispatchEvent("idle"),e}finally{this.sendingData=!1}}dispatchReadBuffer(){try{if(this.listenerCount("message")===0){this.log.trace("not dispatching pause buffer as there are no listeners for the message event");return}if(this.readBuffer.byteLength===0){this.log.trace("not dispatching pause buffer as there is no data to dispatch");return}if(this.readStatus==="paused"){this.log.trace("not dispatching pause buffer we are paused");return}if(this.readStatus==="closing"||this.readStatus==="closed"){this.log("dropping %d bytes because the readable end is %s",this.readBuffer.byteLength,this.readStatus),this.readBuffer.consume(this.readBuffer.byteLength);return}let e=this.readBuffer.sublist();this.readBuffer.consume(e.byteLength),this.dispatchEvent(new se(e))}finally{this.readBuffer.byteLength===0&&this.remoteWriteStatus==="closed"&&(this.log("close readable end after dispatching read buffer and remote writable end is closed"),this.readStatus="closed"),this.checkReadBufferLength()}}checkReadBufferLength(){this.readBuffer.byteLength>this.maxReadBufferLength&&this.abort(new ct(`Read buffer length of ${this.readBuffer.byteLength} exceeded limit of ${this.maxReadBufferLength}, read status is ${this.readStatus}`))}checkWriteBufferLength(){this.maxWriteBufferLength!=null&&this.writeBuffer.byteLength>this.maxWriteBufferLength&&this.abort(new ct(`Write buffer length of ${this.writeBuffer.byteLength} exceeded limit of ${this.maxWriteBufferLength}, write status is ${this.writeStatus}`))}onMuxerNeedsDrain(){this.writableNeedsDrain=!0}onMuxerDrain(){this.safeDispatchEvent("drain")}};var Ct=class extends ke{remoteAddr;metricPrefix;metrics;constructor(e){super(e),this.metricPrefix=e.metricPrefix??"",this.metrics=e.metrics,this.remoteAddr=e.remoteAddr,this.addEventListener("close",r=>{this.metrics?.increment({[`${this.metricPrefix}end`]:!0}),r.error!=null?r.local?this.metrics?.increment({[`${this.metricPrefix}abort`]:!0}):this.metrics?.increment({[`${this.metricPrefix}reset`]:!0}):r.local?this.metrics?.increment({[`${this.metricPrefix}_local_close`]:!0}):this.metrics?.increment({[`${this.metricPrefix}_remote_close`]:!0})})}async close(e){this.status==="open"&&(this.status="closing",this.writeStatus="closing",this.remoteWriteStatus="closing",this.remoteReadStatus="closing",(this.sendingData||this.writeBuffer.byteLength>0)&&(this.log("waiting for write queue to become idle before closing writable end of stream, %d unsent bytes",this.writeBuffer.byteLength),await D(this,"idle",{...e,rejectionEvents:["close"]})),this.writableNeedsDrain&&(this.log("waiting for write queue to drain before closing writable end of stream, %d unsent bytes",this.writeBuffer.byteLength),await D(this,"drain",{...e,rejectionEvents:["close"]})),await this.sendClose(e),this.onTransportClosed())}};function Sn(t){return t==null?!1:typeof t.then=="function"&&typeof t.catch=="function"&&typeof t.finally=="function"}var Lt=class extends ie{streams;protocol;status;log;maConn;streamOptions;earlyStreams;maxEarlyStreams;metrics;constructor(e,r){super(),this.maConn=e,this.protocol=r.protocol,this.streams=[],this.earlyStreams=[],this.status="open",this.log=e.log.newScope(r.name),this.streamOptions=r.streamOptions,this.maxEarlyStreams=r.maxEarlyStreams??10,this.metrics=r.metrics;let n=i=>{try{this.onData(i.data)}catch(a){this.abort(a),this.maConn.abort(a)}};this.maConn.addEventListener("message",n);let o=()=>{this.log("underlying stream drained, signal %d streams to continue writing",this.streams.length),this.streams.forEach(i=>{i.onMuxerDrain()})};this.maConn.addEventListener("drain",o);let s=()=>{this.log("underlying stream closed with status %s and %d streams",this.status,this.streams.length),this.onTransportClosed()};this.maConn.addEventListener("close",s)}send(e){let r=this.maConn.send(e);return r===!1&&(this.log("underlying stream saturated, signal %d streams to pause writing",this.streams.length),this.streams.forEach(n=>{n.onMuxerNeedsDrain()})),r}async close(e){this.status==="closed"||this.status==="closing"||(this.status="closing",await F(Promise.all([...this.streams].map(async r=>{await r.close(e)})),e?.signal),this.status="closed")}abort(e){this.status!=="closed"&&(this.status="closing",[...this.streams].forEach(r=>{r.abort(e)}),this.status="closed")}onTransportClosed(e){this.status="closing";try{[...this.streams].forEach(r=>{r.onTransportClosed(e)})}catch(r){this.abort(r)}this.status="closed"}async createStream(e){if(this.status!=="open")throw new qt;let r=this.onCreateStream({...this.streamOptions,...e});return Sn(r)&&(r=await r),this.streams.push(r),this.cleanUpStream(r),r}onRemoteStream(e){if(this.streams.push(e),this.cleanUpStream(e),this.listenerCount("stream")===0){this.earlyStreams.push(e),this.earlyStreams.length>this.maxEarlyStreams&&this.abort(new _t(`Too many early streams were opened - ${this.earlyStreams.length}/${this.maxEarlyStreams}`));return}this.safeDispatchEvent("stream",{detail:e})}cleanUpStream(e){let r=n=>{let o=this.streams.findIndex(s=>s===e);o!==-1&&this.streams.splice(o,1),n.error!=null?n.local?this.metrics?.increment({[`${e.direction}_stream_reset`]:!0}):this.metrics?.increment({[`${e.direction}_stream_abort`]:!0}):this.metrics?.increment({[`${e.direction}_stream_end`]:!0})};e.addEventListener("close",r),this.metrics?.increment({[`${e.direction}_stream`]:!0})}addEventListener(...e){super.addEventListener.apply(this,e),e[0]==="stream"&&this.earlyStreams.length>0&&queueMicrotask(()=>{this.earlyStreams.forEach(r=>{this.safeDispatchEvent("stream",{detail:r})}),this.earlyStreams=[]})}};var Be=class extends ke{id;protocol;constructor(e){super(e),this.id=e.id,this.protocol=e.protocol??""}async close(e){this.writeStatus==="closing"||this.writeStatus==="closed"||(this.writeStatus="closing",(this.sendingData||this.writeBuffer.byteLength>0)&&(this.log("waiting for write queue to become idle before closing writable end of stream, %d unsent bytes",this.writeBuffer.byteLength),await D(this,"idle",{...e,rejectionEvents:["close"]})),this.writableNeedsDrain&&(this.log("waiting for write queue to drain before closing writable end of stream, %d unsent bytes, sending %s",this.writeBuffer.byteLength,this.sendingData),await D(this,"drain",{...e,rejectionEvents:["close"]}),this.log("write queue drained, closing writable end of stream, %d unsent bytes, sending %s",this.writeBuffer.byteLength,this.sendingData)),await this.sendCloseWrite(e),this.writeStatus="closed",this.log("closed writable end gracefully"),this.remoteWriteStatus==="closed"&&this.onTransportClosed())}async closeRead(e){this.readStatus==="closing"||this.readStatus==="closed"||(this.readBuffer.byteLength>0&&this.readBuffer.consume(this.readBuffer.byteLength),this.readStatus="closing",await this.sendCloseRead(e),this.readStatus="closed",this.log("closed readable end gracefully"))}};function ir(t){let e=new globalThis.AbortController;function r(){let s=t.filter(i=>i?.aborted===!0).map(i=>i?.reason).pop();e.abort(s);for(let i of t)i?.removeEventListener!=null&&i.removeEventListener("abort",r)}for(let s of t){if(s?.aborted===!0){r();break}s?.addEventListener!=null&&s.addEventListener("abort",r)}function n(){for(let s of t)s?.removeEventListener!=null&&s.removeEventListener("abort",r)}let o=e.signal;return o.clear=n,o}var Me=class{movingAverage;variance;deviation;forecast;timeSpan;previousTime;constructor(e){this.timeSpan=e,this.movingAverage=0,this.variance=0,this.deviation=0,this.forecast=0}alpha(e,r){return 1-Math.exp(-(e-r)/this.timeSpan)}push(e,r=Date.now()){if(this.previousTime!=null){let n=this.alpha(r,this.previousTime),o=e-this.movingAverage,s=n*o;this.movingAverage=n*e+(1-n)*this.movingAverage,this.variance=(1-n)*(this.variance+o*s),this.deviation=Math.sqrt(this.variance),this.forecast=this.movingAverage+n*o}else this.movingAverage=e;this.previousTime=r}};var Ko=1.2,Jo=2,Yo=5e3,Zo=6e4,es=5e3,Cn=class{success;failure;next;metric;timeoutMultiplier;failureMultiplier;minTimeout;maxTimeout;constructor(e={}){let r=e.interval??es;this.success=new Me(r),this.failure=new Me(r),this.next=new Me(r),this.failureMultiplier=e.failureMultiplier??Jo,this.timeoutMultiplier=e.timeoutMultiplier??Ko,this.minTimeout=e.minTimeout??Yo,this.maxTimeout=e.maxTimeout??Zo,e.metricName!=null&&(this.metric=e.metrics?.registerMetricGroup(e.metricName))}getTimeoutSignal(e={}){let r=Math.round(this.next.movingAverage*(e.timeoutFactor??this.timeoutMultiplier));r<this.minTimeout&&(r=this.minTimeout),r>this.maxTimeout&&(r=this.maxTimeout);let n=AbortSignal.timeout(r),o=ir([e.signal,n]);return o.start=Date.now(),o.timeout=r,o}cleanUp(e){let r=Date.now()-e.start;e.aborted?(this.failure.push(r),this.next.push(r*this.failureMultiplier),this.metric?.update({failureMovingAverage:this.failure.movingAverage,failureDeviation:this.failure.deviation,failureForecast:this.failure.forecast,failureVariance:this.failure.variance,failure:r})):(this.success.push(r),this.next.push(r),this.metric?.update({successMovingAverage:this.success.movingAverage,successDeviation:this.success.deviation,successForecast:this.success.forecast,successVariance:this.success.variance,success:r}))}};var B=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},pe=class extends Error{static name="ValidationError";name="ValidationError"},ar=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},cr=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};function In(t){return e=>Te(e,t)}function An(t){return e=>T(e,t)}function et(t){return new DataView(t.buffer).getUint16(t.byteOffset).toString()}function Pe(t){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,typeof t=="string"?parseInt(t):t),new Uint8Array(e)}function ts(t){let e=t.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==16)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion address.`);let r=T(e[0],"base32"),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=Pe(n);return we([r,o],r.length+o.length)}function rs(t){let e=t.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==56)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion3 address.`);let r=ae.decode(`b${e[0]}`),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=Pe(n);return we([r,o],r.length+o.length)}function Tn(t){let e=t.subarray(0,t.length-2),r=t.subarray(t.length-2),n=Te(e,"base32"),o=et(r);return`${n}:${o}`}var Dn=function(t){t=t.toString().trim();let e=new Uint8Array(4);return t.split(/\./g).forEach((r,n)=>{let o=parseInt(r,10);if(isNaN(o)||o<0||o>255)throw new B("Invalid byte value in IP address");e[n]=o}),e},ns=function(t){let e=0;t=t.toString().trim();let r=t.split(":",8),n;for(n=0;n<r.length;n++){let s=_e(r[n]),i;s&&(i=Dn(r[n]),r[n]=Te(i.subarray(0,2),"base16")),i!=null&&++n<8&&r.splice(n,0,Te(i.subarray(2,4),"base16"))}if(r[0]==="")for(;r.length<8;)r.unshift("0");else if(r[r.length-1]==="")for(;r.length<8;)r.push("0");else if(r.length<8){for(n=0;n<r.length&&r[n]!=="";n++);let s=[n,1];for(n=9-r.length;n>0;n--)s.push("0");r.splice.apply(r,s)}let o=new Uint8Array(e+16);for(n=0;n<r.length;n++){r[n]===""&&(r[n]="0");let s=parseInt(r[n],16);if(isNaN(s)||s<0||s>65535)throw new B("Invalid byte value in IP address");o[e++]=s>>8&255,o[e++]=s&255}return o},os=function(t){if(t.byteLength!==4)throw new B("IPv4 address was incorrect length");let e=[];for(let r=0;r<t.byteLength;r++)e.push(t[r]);return e.join(".")},ss=function(t){if(t.byteLength!==16)throw new B("IPv6 address was incorrect length");let e=[];for(let n=0;n<t.byteLength;n+=2){let o=t[n],s=t[n+1],i=`${o.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}`;e.push(i)}let r=e.join(":");try{let n=new URL(`http://[${r}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new B(`Invalid IPv6 address "${r}"`)}};function is(t){try{let e=new URL(`http://[${t}]`);return e.hostname.substring(1,e.hostname.length-1)}catch{throw new B(`Invalid IPv6 address "${t}"`)}}var Ln=Object.values(mt).map(t=>t.decoder),$c=(function(){let t=Ln[0].or(Ln[1]);return Ln.slice(2).forEach(e=>t=t.or(e)),t})();function as(t){return $c.decode(t)}function cs(t){return e=>t.encoder.encode(e)}function zc(t){if(parseInt(t).toString()!==t)throw new pe("Value must be an integer")}function Vc(t){if(t<0)throw new pe("Value must be a positive integer, or zero")}function jc(t){return e=>{if(e>t)throw new pe(`Value must be smaller than or equal to ${t}`)}}function qc(...t){return e=>{for(let r of t)r(e)}}var It=qc(zc,Vc,jc(65535));var U=-1,Fn=class{protocolsByCode=new Map;protocolsByName=new Map;getProtocol(e){let r;if(typeof e=="string"?r=this.protocolsByName.get(e):r=this.protocolsByCode.get(e),r==null)throw new cr(`Protocol ${e} was unknown`);return r}addProtocol(e){this.protocolsByCode.set(e.code,e),this.protocolsByName.set(e.name,e),e.aliases?.forEach(r=>{this.protocolsByName.set(r,e)})}removeProtocol(e){let r=this.protocolsByCode.get(e);r!=null&&(this.protocolsByCode.delete(r.code),this.protocolsByName.delete(r.name),r.aliases?.forEach(n=>{this.protocolsByName.delete(n)}))}},ge=new Fn,Au=[{code:4,name:"ip4",size:32,valueToBytes:Dn,bytesToValue:os,validate:t=>{if(!_e(t))throw new pe(`Invalid IPv4 address "${t}"`)}},{code:6,name:"tcp",size:16,valueToBytes:Pe,bytesToValue:et,validate:It},{code:273,name:"udp",size:16,valueToBytes:Pe,bytesToValue:et,validate:It},{code:33,name:"dccp",size:16,valueToBytes:Pe,bytesToValue:et,validate:It},{code:41,name:"ip6",size:128,valueToBytes:ns,bytesToValue:ss,stringToValue:is,validate:t=>{if(!Se(t))throw new pe(`Invalid IPv6 address "${t}"`)}},{code:42,name:"ip6zone",size:U},{code:43,name:"ipcidr",size:8,bytesToValue:In("base10"),valueToBytes:An("base10")},{code:53,name:"dns",size:U},{code:54,name:"dns4",size:U},{code:55,name:"dns6",size:U},{code:56,name:"dnsaddr",size:U},{code:132,name:"sctp",size:16,valueToBytes:Pe,bytesToValue:et,validate:It},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:U,stringToValue:t=>decodeURIComponent(t),valueToString:t=>encodeURIComponent(t)},{code:421,name:"p2p",aliases:["ipfs"],size:U,bytesToValue:In("base58btc"),valueToBytes:t=>t.startsWith("Q")||t.startsWith("1")?An("base58btc")(t):He.parse(t).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:Tn,valueToBytes:ts},{code:445,name:"onion3",size:296,bytesToValue:Tn,valueToBytes:rs},{code:446,name:"garlic64",size:U},{code:447,name:"garlic32",size:U},{code:448,name:"tls"},{code:449,name:"sni",size:U},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:U,bytesToValue:cs(Zr),valueToBytes:as},{code:480,name:"http"},{code:481,name:"http-path",size:U,stringToValue:t=>`/${decodeURIComponent(t)}`,valueToString:t=>encodeURIComponent(t.substring(1))},{code:443,name:"https"},{code:477,name:"ws"},{code:478,name:"wss"},{code:479,name:"p2p-websocket-star"},{code:277,name:"p2p-stardust"},{code:275,name:"p2p-webrtc-star"},{code:276,name:"p2p-webrtc-direct"},{code:280,name:"webrtc-direct"},{code:281,name:"webrtc"},{code:290,name:"p2p-circuit"},{code:777,name:"memory",size:U}];Au.forEach(t=>{ge.addProtocol(t)});function ds(t){let e=[],r=0;for(;r<t.length;){let n=me(t,r),o=ge.getProtocol(n),s=P(n),i=Tu(o,t,r+s),a=0;i>0&&o.size===U&&(a=P(i));let c=s+a+i,u={code:n,name:o.name,bytes:t.subarray(r,r+c)};if(i>0){let l=r+s+a,d=t.subarray(l,l+i);u.value=o.bytesToValue?.(d)??Te(d)}e.push(u),r+=c}return e}function hs(t){let e=0,r=[];for(let n of t){if(n.bytes==null){let o=ge.getProtocol(n.code),s=P(n.code),i,a=0,c=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??T(n.value),a=i.byteLength,o.size===U&&(c=P(a)));let u=new Uint8Array(s+c+a),l=0;Kt(n.code,u,l),l+=s,i!=null&&(o.size===U&&(Kt(a,u,l),l+=c),u.set(i,l)),n.bytes=u}r.push(n.bytes),e+=n.bytes.byteLength}return we(r,e)}function ms(t){if(t.charAt(0)!=="/")throw new B('String multiaddr must start with "/"');let e=[],r="protocol",n="",o="";for(let s=1;s<t.length;s++){let i=t.charAt(s);i!=="/"&&(r==="protocol"?o+=t.charAt(s):n+=t.charAt(s));let a=s===t.length-1;if(i==="/"||a){let c=ge.getProtocol(o);if(r==="protocol"){if(c.size==null||c.size===0){e.push({code:c.code,name:c.name}),n="",o="",r="protocol";continue}else if(a)throw new B(`Component ${o} was missing value`);r="value"}else if(r==="value"){let u={code:c.code,name:c.name};if(c.size!=null&&c.size!==0){if(n==="")throw new B(`Component ${o} was missing value`);u.value=c.stringToValue?.(n)??n}e.push(u),n="",o="",r="protocol"}}}if(o!==""&&n!=="")throw new B("Incomplete multiaddr");return e}function ps(t){return`/${t.flatMap(e=>{if(e.value==null)return e.name;let r=ge.getProtocol(e.code);if(r==null)throw new B(`Unknown protocol code ${e.code}`);return[e.name,r.valueToString?.(e.value)??e.value]}).join("/")}`}function Tu(t,e,r){return t.size==null||t.size===0?0:t.size>0?t.size/8:me(e,r)}var Du=Symbol.for("nodejs.util.inspect.custom"),Un=Symbol.for("@multiformats/multiaddr");function Fu(t){if(t==null&&(t="/"),gs(t))return t.getComponents();if(t instanceof Uint8Array)return ds(t);if(typeof t=="string")return t=t.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),t===""&&(t="/"),ms(t);if(Array.isArray(t))return t;throw new B("Must be a string, Uint8Array, Component[], or another Multiaddr")}var ur=class t{[Un]=!0;#e;#t;#r;constructor(e="/",r={}){this.#e=Fu(e),r.validate!==!1&&Uu(this)}get bytes(){return this.#r==null&&(this.#r=hs(this.#e)),this.#r}toString(){return this.#t==null&&(this.#t=ps(this.#e)),this.#t}toJSON(){return this.toString()}getComponents(){return[...this.#e.map(e=>({...e}))]}encapsulate(e){let r=new t(e);return new t([...this.#e,...r.getComponents()],{validate:!1})}decapsulate(e){let r=e.toString(),n=this.toString(),o=n.lastIndexOf(r);if(o<0)throw new ar(`Address ${this.toString()} does not contain subaddress: ${r}`);return new t(n.slice(0,o),{validate:!1})}decapsulateCode(e){let r;for(let n=this.#e.length-1;n>-1;n--)if(this.#e[n].code===e){r=n;break}return new t(this.#e.slice(0,r),{validate:!1})}equals(e){return Xe(this.bytes,e.bytes)}[Du](){return`Multiaddr(${this.toString()})`}};function Uu(t){t.getComponents().forEach(e=>{let r=ge.getProtocol(e.code);e.value!=null&&r.validate?.(e.value)})}function gs(t){return!!t?.[Un]}function Le(t){return new ur(t)}function ys(t,e,r){let n=[t.type,r??t.host];if(t.protocol!=null){let o=e??t.port;o!=null&&n.push(t.protocol,o)}return t.type==="ip6"&&t.zone!=null&&n.unshift("ip6zone",t.zone),t.cidr!=null&&n.push("ipcidr",t.cidr),Le(`/${n.join("/")}`)}function Nu(t,e){if(t==null)return[];let r=q(t);return[ys(r,e)]}function ku(t){return Se(t)?rr("2000::/3",t):!1}function Bu(t,e){if(typeof t!="string")throw new $(`invalid ip provided: ${t}`);if(typeof e=="string"&&(e=parseInt(e)),isNaN(e))throw new $(`invalid port provided: ${e}`);if(_e(t))return Le(`/ip4/${t}/tcp/${e}`);if(Se(t))return Le(`/ip6/${t}/tcp/${e}`);throw new $(`invalid ip:port for creating a multiaddr: ${t}:${e}`)}function Mu(t){return t==null||typeof t?.[Symbol.asyncIterator]!="function"?!1:typeof t.next=="function"}function Pu(t){return t==null||typeof t?.[Symbol.iterator]!="function"?!1:typeof t.next=="function"}var Nn=class{readNext;haveNext;ended;nextResult;error;constructor(){this.ended=!1,this.readNext=te(),this.haveNext=te()}[Symbol.asyncIterator](){return this}async next(){if(this.nextResult==null&&await this.haveNext.promise,this.nextResult==null)throw new Error("HaveNext promise resolved but nextResult was undefined");let e=this.nextResult;return this.nextResult=void 0,this.readNext.resolve(),this.readNext=te(),e}async throw(e){return this.ended=!0,this.error=e,e!=null&&(this.haveNext.promise.catch(()=>{}),this.haveNext.reject(e)),{done:!0,value:void 0}}async return(){let e={done:!0,value:void 0};return this.ended=!0,this.nextResult=e,this.haveNext.resolve(),e}async push(e,r){await this._push(e,r)}async end(e,r){e!=null?await this.throw(e):await this._push(void 0,r)}async _push(e,r){if(e!=null&&this.ended)throw this.error??new Error("Cannot push value onto an ended pushable");for(;this.nextResult!=null;)await this.readNext.promise;e!=null?this.nextResult={done:!1,value:e}:(this.ended=!0,this.nextResult={done:!0,value:void 0}),this.haveNext.resolve(),this.haveNext=te(),await F(this.readNext.promise,r?.signal,r)}};function bs(){return new Nn}function Ou(t){return t[Symbol.asyncIterator]!=null}async function Ru(t,e,r){try{await Promise.all(t.map(async n=>{for await(let o of n)await e.push(o,{signal:r}),r.throwIfAborted()})),await e.end(void 0,{signal:r})}catch(n){await e.end(n,{signal:r}).catch(()=>{})}}async function*$u(t){let e=new AbortController,r=bs();Ru(t,r,e.signal).catch(()=>{});try{yield*r}finally{e.abort()}}function*zu(t){for(let e of t)yield*e}function Vu(...t){let e=[];for(let r of t)Ou(r)||e.push(r);return e.length===t.length?zu(e):$u(t)}var xs=Vu;function ws(t,...e){if(t==null)throw new Error("Empty pipeline");if(kn(t)){let n=t;t=()=>n.source}else if(vs(t)||Es(t)){let n=t;t=()=>n}let r=[t,...e];if(r.length>1&&kn(r[r.length-1])&&(r[r.length-1]=r[r.length-1].sink),r.length>2)for(let n=1;n<r.length-1;n++)kn(r[n])&&(r[n]=qu(r[n]));return ju(...r)}var ju=(...t)=>{let e;for(;t.length>0;)e=t.shift()(e);return e},Es=t=>t?.[Symbol.asyncIterator]!=null,vs=t=>t?.[Symbol.iterator]!=null,kn=t=>t==null?!1:t.sink!=null&&t.source!=null,qu=t=>e=>{let r=t.sink(e);if(r?.then!=null){let n=ce({objectMode:!0});r.then(()=>{n.end()},i=>{n.end(i)});let o,s=t.source;if(Es(s))o=async function*(){yield*s,n.end()};else if(vs(s))o=function*(){yield*s,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return xs(n,o())}return t.source};var Wu=4194304,At=class extends Error{static name="UnwrappedError";name="UnwrappedError"},tt=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},fr=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},lr=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function Gu(t){return typeof t?.closeRead=="function"}function Hu(t){return typeof t?.close=="function"}function Bn(t){return Gu(t)?t.remoteWriteStatus!=="writable"&&t.readBufferLength===0:Hu(t)?t.status!=="open":!1}function Xu(t){return t?.addEventListener!=null&&t?.removeEventListener!=null&&t?.send!=null&&t?.push!=null&&t?.log!=null}function _s(t,e){let r=e?.maxBufferSize??Wu,n=new A,o,s=!1;if(!Xu(t))throw new $("Argument should be a Stream or a Multiaddr");let i=l=>{if(n.append(l.data),n.byteLength>r){let d=n.byteLength;n.consume(n.byteLength),o?.reject(new Error(`Read buffer overflow - ${d} > ${r}`))}o?.resolve()};t.addEventListener("message",i);let a=l=>{l.error!=null?o?.reject(l.error):o?.resolve()};t.addEventListener("close",a);let c=()=>{o?.resolve()};t.addEventListener("remoteCloseWrite",c);let u={readBuffer:n,async read(l){if(s===!0)throw new At("Stream was unwrapped");if(Bn(t)){if(n.byteLength===0&&l?.bytes==null)return null;if(l?.bytes!=null&&n.byteLength<l.bytes)throw t.log.error("closed after reading %d/%d bytes",n.byteLength,l.bytes),new Ce(`Unexpected EOF - stream closed after reading ${n.byteLength}/${l.bytes} bytes`)}let d=l?.bytes??1;for(o=Promise.withResolvers();;){if(n.byteLength>=d){o.resolve();break}if(await F(o.promise,l?.signal),Bn(t)){if(n.byteLength===0&&l?.bytes==null)return null;break}o=Promise.withResolvers()}let h=l?.bytes??n.byteLength;if(n.byteLength<h){if(Bn(t))throw t.log.error("closed while reading %d/%d bytes",n.byteLength,h),new Ce(`Unexpected EOF - stream closed while reading ${n.byteLength}/${h} bytes`);return u.read(l)}let g=n.sublist(0,h);return n.consume(h),g},async write(l,d){if(s===!0)throw new At("Stream was unwrapped");t.send(l)||await D(t,"drain",{signal:d?.signal,rejectionEvents:["close"]})},unwrap(){return s||(s=!0,t.removeEventListener("message",i),t.removeEventListener("close",a),t.removeEventListener("remoteCloseWrite",c),n.byteLength>0&&(t.log("stream unwrapped with %d unread bytes",n.byteLength),t.push(n))),t}};return u}function Ss(t,e={}){let r=_s(t,e);e.maxDataLength!=null&&e.maxLengthLength==null&&(e.maxLengthLength=P(e.maxDataLength));let n=e?.lengthDecoder??me,o=e?.lengthEncoder??Jt;return{async read(i){let a=-1,c=new A;for(;;){let l=await r.read({...i,bytes:1});if(l==null)break;c.append(l);try{a=n(c)}catch(d){if(d instanceof RangeError)continue;throw d}if(a<0)throw new tt("Invalid message length");if(e?.maxLengthLength!=null&&c.byteLength>e.maxLengthLength)throw new lr(`Message length length too long - ${c.byteLength} > ${e.maxLengthLength}`);if(a>-1)break}if(e?.maxDataLength!=null&&a>e.maxDataLength)throw new fr(`Message length too long - ${a} > ${e.maxDataLength}`);let u=await r.read({...i,bytes:a});if(u==null)throw t.log.error("tried to read %d bytes but the stream closed",a),new Ce(`Unexpected EOF - tried to read ${a} bytes but the stream closed`);if(u.byteLength!==a)throw t.log.error("read %d/%d bytes before the stream closed",u.byteLength,a),new Ce(`Unexpected EOF - read ${u.byteLength}/${a} bytes before the stream closed`);return u},async write(i,a){await r.write(new A(o(i.byteLength),i),a)},async writeV(i,a){let c=new A(...i.flatMap(u=>[o(u.byteLength),u]));await r.write(c,a)},unwrap(){return r.unwrap()}}}function Qu(t,e){let r=Ss(t,e),n={read:async(o,s)=>{let i=await r.read(s);return o.decode(i)},write:async(o,s,i)=>{await r.write(s.encode(o),i)},writeV:async(o,s,i)=>{await r.writeV(o.map(a=>s.encode(a)),i)},pb:o=>({read:async s=>n.read(o,s),write:async(s,i)=>n.write(s,o,i),writeV:async(s,i)=>n.writeV(s,o,i),unwrap:()=>n}),unwrap:()=>r.unwrap()};return n}async function Mn(t,e){let r=t.log.newScope("echo"),n=Date.now(),o=0;try{for await(let s of t)o+=s.byteLength,t.send(s)||(t.pause(),await D(t,"drain",{rejectionEvents:["close"],...e}),t.resume());r("echoed %d bytes in %dms",o,Date.now()-n),await t.close(e)}catch(s){t.abort(s)}}function Ku(t){return t?.addEventListener!=null}function Cs(t){let e=ce(),r,n=i=>{e.push(i.data)},o=()=>{e.end(),t.removeEventListener("message",n),t.removeEventListener("close",s),t.removeEventListener("remoteCloseWrite",o)},s=i=>{e.end(i.error),i.error!=null&&r?.reject(i.error),t.removeEventListener("message",n),t.removeEventListener("close",s),t.removeEventListener("remoteCloseWrite",o)};return t.addEventListener("message",n),t.addEventListener("close",s,{once:!0}),t.addEventListener("remoteCloseWrite",o,{once:!0}),{source:e,async sink(i){async function*a(){yield*i}let c=a();for(;;){r=Promise.withResolvers();let{done:u,value:l}=await Promise.race([c.next(),r.promise]);if(t.writeStatus==="closing"||t.writeStatus==="closed"||(l!=null&&(t.send(l)||await Promise.race([D(t,"drain",{rejectionEvents:["close"]})])),u===!0))break}await t.close()}}}function Ju(...t){let e=t.map(r=>Ku(r)?Cs(r):r);return ws(...e)}var Yu=1024*1024*4,Zu=1024*1024*4,Pn=class{buffer;maxBufferSize;lengthDecoder;maxDataLength;encodingLength;constructor(e={}){this.buffer=new A,this.maxBufferSize=e.maxBufferSize??Yu,this.maxDataLength=e.maxDataLength??Zu,this.lengthDecoder=e.lengthDecoder??me,this.encodingLength=e.encodingLength??P}*decode(e){if(this.buffer.append(e),this.buffer.byteLength>this.maxBufferSize)throw new $(`Buffer length limit exceeded - ${this.buffer.byteLength}/${this.maxBufferSize}`);for(;;){let r;try{r=this.lengthDecoder(this.buffer)}catch(s){if(s instanceof RangeError)break;throw s}if(r<0||r>this.maxDataLength)throw new tt("Invalid message length");let n=this.encodingLength(r),o=n+r;if(this.buffer.byteLength>=o){let s=this.buffer.sublist(n,o);this.buffer.consume(o),s.byteLength>0&&(yield s)}else break}}};function ef(t){return!!(t.startsWith("169.254.")||t.toLowerCase().startsWith("fe80"))}var tf=["Object","RegExp","Date","Error","Map","Set","WeakMap","WeakSet","ArrayBuffer","SharedArrayBuffer","DataView","Promise","URL","HTMLElement","Int8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array"];function On(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=rf(t);return r||"Object"}function rf(t){let e=Object.prototype.toString.call(t).slice(8,-1);if(tf.includes(e))return e}var f=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}};f.uint=new f(0,"uint",!0);f.negint=new f(1,"negint",!0);f.bytes=new f(2,"bytes",!0);f.string=new f(3,"string",!0);f.array=new f(4,"array",!1);f.map=new f(5,"map",!1);f.tag=new f(6,"tag",!1);f.float=new f(7,"float",!0);f.false=new f(7,"false",!0);f.true=new f(7,"true",!0);f.null=new f(7,"null",!0);f.undefined=new f(7,"undefined",!0);f.break=new f(7,"break",!0);var p=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 Tt=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",nf=new TextEncoder;function dr(t){return Tt&&globalThis.Buffer.isBuffer(t)}function Dt(t){return t instanceof Uint8Array?dr(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):t:Uint8Array.from(t)}var of=24,sf=200,hr=Tt?t=>t.length>=of?globalThis.Buffer.from(t):Ls(t):t=>t.length>=sf?nf.encode(t):Ls(t),ue=t=>Uint8Array.from(t),Is=Tt?(t,e,r)=>dr(t)?new Uint8Array(t.subarray(e,r)):t.slice(e,r):(t,e,r)=>t.slice(e,r),As=Tt?(t,e)=>(t=t.map(r=>r instanceof Uint8Array?r:globalThis.Buffer.from(r)),Dt(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},Ts=Tt?t=>globalThis.Buffer.allocUnsafe(t):t=>new Uint8Array(t);function mr(t,e){if(dr(t)&&dr(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 Ls(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 af=256,Ft=class{constructor(e=af){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)}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=Ts(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=Is(n,0,this.cursor)}else r=As(this.chunks,this.cursor);return e&&this.reset(),r}},pr=class{constructor(e){this.dest=e,this.cursor=0,this.chunks=[e]}reset(){this.cursor=0}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 y="CBOR decode error:",gr="CBOR encode error:",Ut=[];Ut[23]=1;Ut[24]=2;Ut[25]=3;Ut[26]=5;Ut[27]=9;function ye(t,e,r){if(t.length-e<r)throw new Error(`${y} not enough data for type`)}var N=[24,256,65536,4294967296,BigInt("18446744073709551616")];function W(t,e,r){ye(t,e,1);let n=t[e];if(r.strict===!0&&n<N[0])throw new Error(`${y} integer encoded in more bytes than necessary (strict decode)`);return n}function G(t,e,r){ye(t,e,2);let n=t[e]<<8|t[e+1];if(r.strict===!0&&n<N[1])throw new Error(`${y} integer encoded in more bytes than necessary (strict decode)`);return n}function H(t,e,r){ye(t,e,4);let n=t[e]*16777216+(t[e+1]<<16)+(t[e+2]<<8)+t[e+3];if(r.strict===!0&&n<N[2])throw new Error(`${y} integer encoded in more bytes than necessary (strict decode)`);return n}function X(t,e,r){ye(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],s=(BigInt(n)<<BigInt(32))+BigInt(o);if(r.strict===!0&&s<N[3])throw new Error(`${y} integer encoded in more bytes than necessary (strict decode)`);if(s<=Number.MAX_SAFE_INTEGER)return Number(s);if(r.allowBigInt===!0)return s;throw new Error(`${y} integers outside of the safe integer range are not supported`)}function Ds(t,e,r,n){return new p(f.uint,W(t,e+1,n),2)}function Fs(t,e,r,n){return new p(f.uint,G(t,e+1,n),3)}function Us(t,e,r,n){return new p(f.uint,H(t,e+1,n),5)}function Ns(t,e,r,n){return new p(f.uint,X(t,e+1,n),9)}function K(t,e){return S(t,0,e.value)}function S(t,e,r){if(r<N[0]){let n=Number(r);t.push([e|n])}else if(r<N[1]){let n=Number(r);t.push([e|24,n])}else if(r<N[2]){let n=Number(r);t.push([e|25,n>>>8,n&255])}else if(r<N[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<N[4]){let o=[e|27,0,0,0,0,0,0,0],s=Number(n&BigInt(4294967295)),i=Number(n>>BigInt(32)&BigInt(4294967295));o[8]=s&255,s=s>>8,o[7]=s&255,s=s>>8,o[6]=s&255,s=s>>8,o[5]=s&255,o[4]=i&255,i=i>>8,o[3]=i&255,i=i>>8,o[2]=i&255,i=i>>8,o[1]=i&255,t.push(o)}else throw new Error(`${y} encountered BigInt larger than allowable range`)}}K.encodedSize=function(e){return S.encodedSize(e.value)};S.encodedSize=function(e){return e<N[0]?1:e<N[1]?2:e<N[2]?3:e<N[3]?5:9};K.compareTokens=function(e,r){return e.value<r.value?-1:e.value>r.value?1:0};function ks(t,e,r,n){return new p(f.negint,-1-W(t,e+1,n),2)}function Bs(t,e,r,n){return new p(f.negint,-1-G(t,e+1,n),3)}function Ms(t,e,r,n){return new p(f.negint,-1-H(t,e+1,n),5)}var Rn=BigInt(-1),Ps=BigInt(1);function Os(t,e,r,n){let o=X(t,e+1,n);if(typeof o!="bigint"){let s=-1-o;if(s>=Number.MIN_SAFE_INTEGER)return new p(f.negint,s,9)}if(n.allowBigInt!==!0)throw new Error(`${y} integers outside of the safe integer range are not supported`);return new p(f.negint,Rn-BigInt(o),9)}function yr(t,e){let r=e.value,n=typeof r=="bigint"?r*Rn-Ps:r*-1-1;S(t,e.type.majorEncoded,n)}yr.encodedSize=function(e){let r=e.value,n=typeof r=="bigint"?r*Rn-Ps:r*-1-1;return n<N[0]?1:n<N[1]?2:n<N[2]?3:n<N[3]?5:9};yr.compareTokens=function(e,r){return e.value<r.value?1:e.value>r.value?-1:0};function Nt(t,e,r,n){ye(t,e,r+n);let o=t.slice(e+r,e+r+n);return new p(f.bytes,o,r+n)}function Rs(t,e,r,n){return Nt(t,e,1,r)}function $s(t,e,r,n){return Nt(t,e,2,W(t,e+1,n))}function zs(t,e,r,n){return Nt(t,e,3,G(t,e+1,n))}function Vs(t,e,r,n){return Nt(t,e,5,H(t,e+1,n))}function js(t,e,r,n){let o=X(t,e+1,n);if(typeof o=="bigint")throw new Error(`${y} 64-bit integer bytes lengths not supported`);return Nt(t,e,9,o)}function br(t){return t.encodedBytes===void 0&&(t.encodedBytes=f.equals(t.type,f.string)?hr(t.value):t.value),t.encodedBytes}function rt(t,e){let r=br(e);S(t,e.type.majorEncoded,r.length),t.push(r)}rt.encodedSize=function(e){let r=br(e);return S.encodedSize(r.length)+r.length};rt.compareTokens=function(e,r){return uf(br(e),br(r))};function uf(t,e){return t.length<e.length?-1:t.length>e.length?1:mr(t,e)}var qs=new TextDecoder,lf=32;function df(t,e,r){if(r-e<lf){let o="";for(let s=e;s<r;s++){let i=t[s];if(i&128)return qs.decode(t.subarray(e,r));o+=String.fromCharCode(i)}return o}return qs.decode(t.subarray(e,r))}function kt(t,e,r,n,o){let s=r+n;ye(t,e,s);let i=new p(f.string,df(t,e+r,e+s),s);return o.retainStringBytes===!0&&(i.byteValue=t.slice(e+r,e+s)),i}function Ws(t,e,r,n){return kt(t,e,1,r,n)}function Gs(t,e,r,n){return kt(t,e,2,W(t,e+1,n),n)}function Hs(t,e,r,n){return kt(t,e,3,G(t,e+1,n),n)}function Xs(t,e,r,n){return kt(t,e,5,H(t,e+1,n),n)}function Qs(t,e,r,n){let o=X(t,e+1,n);if(typeof o=="bigint")throw new Error(`${y} 64-bit integer string lengths not supported`);return kt(t,e,9,o,n)}var Ks=rt;function nt(t,e,r,n){return new p(f.array,n,r)}function Js(t,e,r,n){return nt(t,e,1,r)}function Ys(t,e,r,n){return nt(t,e,2,W(t,e+1,n))}function Zs(t,e,r,n){return nt(t,e,3,G(t,e+1,n))}function ei(t,e,r,n){return nt(t,e,5,H(t,e+1,n))}function ti(t,e,r,n){let o=X(t,e+1,n);if(typeof o=="bigint")throw new Error(`${y} 64-bit integer array lengths not supported`);return nt(t,e,9,o)}function ri(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${y} indefinite length items not allowed`);return nt(t,e,1,1/0)}function xr(t,e){S(t,f.array.majorEncoded,e.value)}xr.compareTokens=K.compareTokens;xr.encodedSize=function(e){return S.encodedSize(e.value)};function ot(t,e,r,n){return new p(f.map,n,r)}function ni(t,e,r,n){return ot(t,e,1,r)}function oi(t,e,r,n){return ot(t,e,2,W(t,e+1,n))}function si(t,e,r,n){return ot(t,e,3,G(t,e+1,n))}function ii(t,e,r,n){return ot(t,e,5,H(t,e+1,n))}function ai(t,e,r,n){let o=X(t,e+1,n);if(typeof o=="bigint")throw new Error(`${y} 64-bit integer map lengths not supported`);return ot(t,e,9,o)}function ci(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${y} indefinite length items not allowed`);return ot(t,e,1,1/0)}function wr(t,e){S(t,f.map.majorEncoded,e.value)}wr.compareTokens=K.compareTokens;wr.encodedSize=function(e){return S.encodedSize(e.value)};function ui(t,e,r,n){return new p(f.tag,r,1)}function fi(t,e,r,n){return new p(f.tag,W(t,e+1,n),2)}function li(t,e,r,n){return new p(f.tag,G(t,e+1,n),3)}function di(t,e,r,n){return new p(f.tag,H(t,e+1,n),5)}function hi(t,e,r,n){return new p(f.tag,X(t,e+1,n),9)}function Er(t,e){S(t,f.tag.majorEncoded,e.value)}Er.compareTokens=K.compareTokens;Er.encodedSize=function(e){return S.encodedSize(e.value)};var $n=20,zn=21,Vn=22,jn=23;function mi(t,e,r,n){if(n.allowUndefined===!1)throw new Error(`${y} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new p(f.null,null,1):new p(f.undefined,void 0,1)}function pi(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${y} indefinite length items not allowed`);return new p(f.break,void 0,1)}function qn(t,e,r){if(r){if(r.allowNaN===!1&&Number.isNaN(t))throw new Error(`${y} NaN values are not supported`);if(r.allowInfinity===!1&&(t===1/0||t===-1/0))throw new Error(`${y} Infinity values are not supported`)}return new p(f.float,t,e)}function gi(t,e,r,n){return qn(Wn(t,e+1),3,n)}function yi(t,e,r,n){return qn(Gn(t,e+1),5,n)}function bi(t,e,r,n){return qn(vi(t,e+1),9,n)}function Bt(t,e,r){let n=e.value;if(n===!1)t.push([f.float.majorEncoded|$n]);else if(n===!0)t.push([f.float.majorEncoded|zn]);else if(n===null)t.push([f.float.majorEncoded|Vn]);else if(n===void 0)t.push([f.float.majorEncoded|jn]);else{let o,s=!1;(!r||r.float64!==!0)&&(wi(n),o=Wn(ne,1),n===o||Number.isNaN(n)?(ne[0]=249,t.push(ne.slice(0,3)),s=!0):(Ei(n),o=Gn(ne,1),n===o&&(ne[0]=250,t.push(ne.slice(0,5)),s=!0))),s||(yf(n),o=vi(ne,1),ne[0]=251,t.push(ne.slice(0,9)))}}Bt.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){wi(n);let o=Wn(ne,1);if(n===o||Number.isNaN(n))return 3;if(Ei(n),o=Gn(ne,1),n===o)return 5}return 9};var xi=new ArrayBuffer(9),J=new DataView(xi,1),ne=new Uint8Array(xi,0);function wi(t){if(t===1/0)J.setUint16(0,31744,!1);else if(t===-1/0)J.setUint16(0,64512,!1);else if(Number.isNaN(t))J.setUint16(0,32256,!1);else{J.setFloat32(0,t);let e=J.getUint32(0),r=(e&2139095040)>>23,n=e&8388607;if(r===255)J.setUint16(0,31744,!1);else if(r===0)J.setUint16(0,(t&2147483648)>>16|n>>13,!1);else{let o=r-127;o<-24?J.setUint16(0,0):o<-14?J.setUint16(0,(e&2147483648)>>16|1<<24+o,!1):J.setUint16(0,(e&2147483648)>>16|o+15<<10|n>>13,!1)}}}function Wn(t,e){if(t.length-e<2)throw new Error(`${y} 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,s;return n===0?s=o*2**-24:n!==31?s=(o+1024)*2**(n-25):s=o===0?1/0:NaN,r&32768?-s:s}function Ei(t){J.setFloat32(0,t,!1)}function Gn(t,e){if(t.length-e<4)throw new Error(`${y} not enough data for float32`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,4).getFloat32(0,!1)}function yf(t){J.setFloat64(0,t,!1)}function vi(t,e){if(t.length-e<8)throw new Error(`${y} not enough data for float64`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,8).getFloat64(0,!1)}Bt.compareTokens=K.compareTokens;function E(t,e,r){throw new Error(`${y} encountered invalid minor (${r}) for major ${t[e]>>>5}`)}function vr(t){return()=>{throw new Error(`${y} ${t}`)}}var m=[];for(let t=0;t<=23;t++)m[t]=E;m[24]=Ds;m[25]=Fs;m[26]=Us;m[27]=Ns;m[28]=E;m[29]=E;m[30]=E;m[31]=E;for(let t=32;t<=55;t++)m[t]=E;m[56]=ks;m[57]=Bs;m[58]=Ms;m[59]=Os;m[60]=E;m[61]=E;m[62]=E;m[63]=E;for(let t=64;t<=87;t++)m[t]=Rs;m[88]=$s;m[89]=zs;m[90]=Vs;m[91]=js;m[92]=E;m[93]=E;m[94]=E;m[95]=vr("indefinite length bytes/strings are not supported");for(let t=96;t<=119;t++)m[t]=Ws;m[120]=Gs;m[121]=Hs;m[122]=Xs;m[123]=Qs;m[124]=E;m[125]=E;m[126]=E;m[127]=vr("indefinite length bytes/strings are not supported");for(let t=128;t<=151;t++)m[t]=Js;m[152]=Ys;m[153]=Zs;m[154]=ei;m[155]=ti;m[156]=E;m[157]=E;m[158]=E;m[159]=ri;for(let t=160;t<=183;t++)m[t]=ni;m[184]=oi;m[185]=si;m[186]=ii;m[187]=ai;m[188]=E;m[189]=E;m[190]=E;m[191]=ci;for(let t=192;t<=215;t++)m[t]=ui;m[216]=fi;m[217]=li;m[218]=di;m[219]=hi;m[220]=E;m[221]=E;m[222]=E;m[223]=E;for(let t=224;t<=243;t++)m[t]=vr("simple values are not supported");m[244]=E;m[245]=E;m[246]=E;m[247]=mi;m[248]=vr("simple values are not supported");m[249]=gi;m[250]=yi;m[251]=bi;m[252]=E;m[253]=E;m[254]=E;m[255]=pi;var oe=[];for(let t=0;t<24;t++)oe[t]=new p(f.uint,t,1);for(let t=-1;t>=-24;t--)oe[31-t]=new p(f.negint,t,1);oe[64]=new p(f.bytes,new Uint8Array(0),1);oe[96]=new p(f.string,"",1);oe[128]=new p(f.array,0,1);oe[160]=new p(f.map,0,1);oe[244]=new p(f.false,!1,1);oe[245]=new p(f.true,!0,1);oe[246]=new p(f.null,null,1);function Hn(t){switch(t.type){case f.false:return ue([244]);case f.true:return ue([245]);case f.null:return ue([246]);case f.bytes:return t.value.length?void 0:ue([64]);case f.string:return t.value===""?ue([96]):void 0;case f.array:return t.value===0?ue([128]):void 0;case f.map:return t.value===0?ue([160]):void 0;case f.uint:return t.value<24?ue([Number(t.value)]):void 0;case f.negint:if(t.value>=-24)return ue([31-Number(t.value)])}}var xf={float64:!1,mapSorter:vf,quickEncodeToken:Hn},Ii=Object.freeze({float64:!0,mapSorter:_f,quickEncodeToken:Hn});function wf(){let t=[];return t[f.uint.major]=K,t[f.negint.major]=yr,t[f.bytes.major]=rt,t[f.string.major]=Ks,t[f.array.major]=xr,t[f.map.major]=wr,t[f.tag.major]=Er,t[f.float.major]=Bt,t}var st=wf(),_r=new Ft,Pt=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(`${gr} object contains circular references`);return new t(r,e)}},Ie={null:new p(f.null,null),undefined:new p(f.undefined,void 0),true:new p(f.true,!0),false:new p(f.false,!1),emptyArray:new p(f.array,0),emptyMap:new p(f.map,0)},fe={number(t,e,r,n){return!Number.isInteger(t)||!Number.isSafeInteger(t)?new p(f.float,t):t>=0?new p(f.uint,t):new p(f.negint,t)},bigint(t,e,r,n){return t>=BigInt(0)?new p(f.uint,t):new p(f.negint,t)},Uint8Array(t,e,r,n){return new p(f.bytes,t)},string(t,e,r,n){return new p(f.string,t)},boolean(t,e,r,n){return t?Ie.true:Ie.false},null(t,e,r,n){return Ie.null},undefined(t,e,r,n){return Ie.undefined},ArrayBuffer(t,e,r,n){return new p(f.bytes,new Uint8Array(t))},DataView(t,e,r,n){return new p(f.bytes,new Uint8Array(t.buffer,t.byteOffset,t.byteLength))},Array(t,e,r,n){if(!t.length)return r.addBreakTokens===!0?[Ie.emptyArray,new p(f.break)]:Ie.emptyArray;n=Pt.createCheck(n,t);let o=[],s=0;for(let i of t)o[s++]=Sr(i,r,n);return r.addBreakTokens?[new p(f.array,t.length),o,new p(f.break)]:[new p(f.array,t.length),o]},Object(t,e,r,n){let o=e!=="Object",s=o?t.keys():Object.keys(t),i=o?t.size:s.length,a;if(i){a=new Array(i),n=Pt.createCheck(n,t);let c=!o&&r.ignoreUndefinedProperties,u=0;for(let l of s){let d=o?t.get(l):t[l];c&&d===void 0||(a[u++]=[Sr(l,r,n),Sr(d,r,n)])}u<i&&(a.length=u)}return a?.length?(Ef(a,r),r.addBreakTokens?[new p(f.map,a.length),a,new p(f.break)]:[new p(f.map,a.length),a]):r.addBreakTokens===!0?[Ie.emptyMap,new p(f.break)]:Ie.emptyMap}};fe.Map=fe.Object;fe.Buffer=fe.Uint8Array;for(let t of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))fe[`${t}Array`]=fe.DataView;function Sr(t,e={},r){let n=On(t),o=e&&e.typeEncoders&&e.typeEncoders[n]||fe[n];if(typeof o=="function"){let i=o(t,n,e,r);if(i!=null)return i}let s=fe[n];if(!s)throw new Error(`${gr} unsupported type: ${n}`);return s(t,n,e,r)}function Ef(t,e){e.mapSorter&&t.sort(e.mapSorter)}function vf(t,e){let r=Array.isArray(t[0])?t[0][0]:t[0],n=Array.isArray(e[0])?e[0][0]:e[0];if(r.type!==n.type)return r.type.compare(n.type);let o=r.type.major,s=st[o].compareTokens(r,n);return s===0&&console.warn("WARNING: complex key types used, CBOR key sorting guarantees are gone"),s}function _f(t,e){if(t[0]instanceof p&&e[0]instanceof p){let r=t[0],n=e[0];return r._keyBytes||(r._keyBytes=_i(r.value)),n._keyBytes||(n._keyBytes=_i(n.value)),mr(r._keyBytes,n._keyBytes)}throw new Error("rfc8949MapSorter: complex key types are not supported yet")}function _i(t){return Ti(t,st,Ii)}function Mt(t,e,r,n){if(Array.isArray(e))for(let o of e)Mt(t,o,r,n);else r[e.type.major](t,e,n)}var Si=f.uint.majorEncoded,Ci=f.negint.majorEncoded,Sf=f.bytes.majorEncoded,Cf=f.string.majorEncoded,Li=f.array.majorEncoded,Lf=f.float.majorEncoded|$n,If=f.float.majorEncoded|zn,Af=f.float.majorEncoded|Vn,Tf=f.float.majorEncoded|jn,Df=BigInt(-1),Ff=BigInt(1);function Uf(t){return t.addBreakTokens!==!0}function Ai(t,e,r,n){let o=On(e),s=r.typeEncoders&&r.typeEncoders[o];if(s){let i=s(e,o,r,n);if(i!=null){Mt(t,i,st,r);return}}switch(o){case"null":t.push([Af]);return;case"undefined":t.push([Tf]);return;case"boolean":t.push([e?If:Lf]);return;case"number":!Number.isInteger(e)||!Number.isSafeInteger(e)?Bt(t,new p(f.float,e),r):e>=0?S(t,Si,e):S(t,Ci,e*-1-1);return;case"bigint":e>=BigInt(0)?S(t,Si,e):S(t,Ci,e*Df-Ff);return;case"string":{let i=hr(e);S(t,Cf,i.length),t.push(i);return}case"Uint8Array":S(t,Sf,e.length),t.push(e);return;case"Array":if(!e.length){t.push([Li]);return}n=Pt.createCheck(n,e),S(t,Li,e.length);for(let i of e)Ai(t,i,r,n);return;case"Object":case"Map":{let i=fe.Object(e,o,r,n);Mt(t,i,st,r)}return;default:{let i=fe[o];if(!i)throw new Error(`${gr} unsupported type: ${o}`);let a=i(e,o,r,n);Mt(t,a,st,r)}}}function Ti(t,e,r,n){let o=n instanceof Uint8Array,s=o?new pr(n):_r,i=Sr(t,r);if(!Array.isArray(i)&&r.quickEncodeToken){let a=r.quickEncodeToken(i);if(a)return o?(s.push(a),s.toBytes()):a;let c=e[i.type.major];if(c.encodedSize){let u=c.encodedSize(i,r);if(o||(s=new Ft(u)),c(s,i,r),s.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${i} was wrong`);return o?s.toBytes():Dt(s.chunks[0])}}return s.reset(),Mt(s,i,e,r),s.toBytes(!0)}function Xn(t,e){return e=Object.assign({},xf,e),Uf(e)?(_r.reset(),Ai(_r,t,e,void 0),_r.toBytes(!0)):Ti(t,st,e)}var Nf={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},Cr=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=oe[e];if(r===void 0){let n=m[e];if(!n)throw new Error(`${y} 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}},Ot=Symbol.for("DONE"),Lr=Symbol.for("BREAK");function kf(t,e,r){let n=[];for(let o=0;o<t.value;o++){let s=it(e,r);if(s===Lr){if(t.value===1/0)break;throw new Error(`${y} got unexpected break to lengthed array`)}if(s===Ot)throw new Error(`${y} found array but not enough entries (got ${o}, expected ${t.value})`);n[o]=s}return n}function Bf(t,e,r){let n=r.useMaps===!0,o=r.rejectDuplicateMapKeys===!0,s=n?void 0:{},i=n?new Map:void 0;for(let a=0;a<t.value;a++){let c=it(e,r);if(c===Lr){if(t.value===1/0)break;throw new Error(`${y} got unexpected break to lengthed map`)}if(c===Ot)throw new Error(`${y} found map but not enough entries (got ${a} [no key], expected ${t.value})`);if(!n&&typeof c!="string")throw new Error(`${y} non-string keys not supported (got ${typeof c})`);if(o&&(n&&i.has(c)||!n&&Object.hasOwn(s,c)))throw new Error(`${y} found repeat map key "${c}"`);let u=it(e,r);if(u===Ot)throw new Error(`${y} found map but not enough entries (got ${a} [no value], expected ${t.value})`);n?i.set(c,u):s[c]=u}return n?i:s}function it(t,e){if(t.done())return Ot;let r=t.next();if(f.equals(r.type,f.break))return Lr;if(r.type.terminal)return r.value;if(f.equals(r.type,f.array))return kf(r,t,e);if(f.equals(r.type,f.map))return Bf(r,t,e);if(f.equals(r.type,f.tag)){if(e.tags&&typeof e.tags[r.value]=="function"){let n=it(t,e);return e.tags[r.value](n)}throw new Error(`${y} tag not supported (${r.value})`)}throw new Error("unsupported")}function Di(t,e){if(!(t instanceof Uint8Array))throw new Error(`${y} data to decode must be a Uint8Array`);e=Object.assign({},Nf,e);let r=Dt(t),n=e.tokenizer||new Cr(r,e),o=it(n,e);if(o===Ot)throw new Error(`${y} did not find any content to decode`);if(o===Lr)throw new Error(`${y} got unexpected break`);return[o,t.subarray(n.pos())]}function Qn(t,e){let[r,n]=Di(t,e);if(n.length>0)throw new Error(`${y} too many terminals, data makes no sense`);return r}var Ir=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},at=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},Ar=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"},Rt=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};function Tr(t){return t[Symbol.asyncIterator]!=null}function Fi(t,e){if(t.byteLength>e)throw new at("Message length too long")}var Fr=t=>{let e=P(t),r=Z(e);return Jt(t,r),Fr.bytes=e,r};Fr.bytes=0;function Ur(t,e){e=e??{};let r=e.lengthEncoder??Fr,n=e?.maxDataLength??4194304;function*o(s){Fi(s,n);let i=r(s.byteLength);i instanceof Uint8Array?yield i:yield*i,s instanceof Uint8Array?yield s:yield*s}return Tr(t)?(async function*(){for await(let s of t)yield*o(s)})():(function*(){for(let s of t)yield*o(s)})()}Ur.single=(t,e)=>{e=e??{};let r=e.lengthEncoder??Fr,n=e?.maxDataLength??4194304;return Fi(t,n),new A(r(t.byteLength),t)};var Re;(function(t){t[t.LENGTH=0]="LENGTH",t[t.DATA=1]="DATA"})(Re||(Re={}));var Kn=t=>{let e=me(t);return Kn.bytes=P(e),e};Kn.bytes=0;function $t(t,e){let r=new A,n=Re.LENGTH,o=-1,s=e?.lengthDecoder??Kn,i=e?.maxLengthLength??8,a=e?.maxDataLength??4194304;function*c(){for(;r.byteLength>0;){if(n===Re.LENGTH)try{if(o=s(r),o<0)throw new Ir("Invalid message length");if(o>a)throw new at("Message length too long");let u=s.bytes;r.consume(u),e?.onLength!=null&&e.onLength(o),n=Re.DATA}catch(u){if(u instanceof RangeError){if(r.byteLength>i)throw new Ar("Message length length too long");break}throw u}if(n===Re.DATA){if(r.byteLength<o)break;let u=r.sublist(0,o);r.consume(o),e?.onData!=null&&e.onData(u),yield u,n=Re.LENGTH}}}return Tr(t)?(async function*(){for await(let u of t)r.append(u),yield*c();if(r.byteLength>0)throw new Rt("Unexpected end of input")})():(function*(){for(let u of t)r.append(u),yield*c();if(r.byteLength>0)throw new Rt("Unexpected end of input")})()}$t.fromReader=(t,e)=>{let r=1,n=(async function*(){for(;;)try{let{done:s,value:i}=await t.next(r);if(s===!0)return;i!=null&&(yield i)}catch(s){if(s.code==="ERR_UNDER_READ")return{done:!0,value:null};throw s}finally{r=1}})();return $t(n,{...e??{},onLength:s=>{r=s}})};var Jn=class extends Be{sendMessage;dataQueue;encoding;constructor(e){super(e),this.sendMessage=e.sendMessage,this.encoding=e.encoding,this.dataQueue=new re({concurrency:1}),this.direction==="outbound"&&this.sendMessage({id:this.id,type:"create",protocol:this.protocol})}sendData(e){let r=this.sendMessage({id:this.id,type:"data",chunk:e.subarray()});return{sentBytes:e.byteLength,canSendMore:r}}sendReset(){this.sendMessage({id:this.id,type:"reset"})}async sendCloseWrite(e){this.sendMessage({id:this.id,type:"closeWrite"}),e?.signal?.throwIfAborted()}async sendCloseRead(e){this.sendMessage({id:this.id,type:"closeRead"}),e?.signal?.throwIfAborted()}sendPause(){this.sendMessage({id:this.id,type:"pause"})}sendResume(){this.sendMessage({id:this.id,type:"resume"})}onRemotePaused(){this.dataQueue.pause()}onRemoteResumed(){this.dataQueue.resume()}},Ui=30,Yn=class extends Lt{input;maxInputQueueSize;encoding;maxMessageSize;nextStreamId;constructor(e,r){super(e,{...r,protocol:"/mock-muxer/1.0.0",name:"mock-muxer"}),this.maxInputQueueSize=r.maxInputQueueSize??1024*1024*10,this.maxMessageSize=(r.maxMessageSize??1024*1024*4)+Ui,this.encoding=r.encoding??"base64",this.input=ce(),this.sendMessage=this.sendMessage.bind(this),this.nextStreamId=this.maConn.direction==="outbound"?0:1,Promise.resolve().then(async()=>{for await(let n of $t(this.input,{maxDataLength:this.maxMessageSize}))this.onMessage(Qn(n.subarray()))}).catch(n=>{this.abort(n)})}onData(e){if(this.input.readableLength>=this.maxInputQueueSize){this.abort(new Error(`Input queue exceeded maximum size ${this.input.readableLength} >= ${this.maxInputQueueSize}`));return}this.input.push(e)}sendMessage(e){e.type==="data"?this.log.trace("send message %o",{...e,chunk:`[ ${e.chunk.byteLength} bytes ]`}):this.log.trace("send message %o",e);let r=Xn(e),n=Ur.single(r,{maxDataLength:this.maxMessageSize});return this.send(n)}onMessage(e){e.type==="data"?this.log.trace("incoming message %o",{...e,chunk:`[ ${e.chunk.byteLength} bytes ]`}):this.log.trace("incoming message %o",e);let r=this.streams.find(n=>n.id===e.id);if(e.type==="create"){if(r!=null)throw new Error(`Already had stream for ${e.id}`);this.log.trace("create stream inbound %s",e.id),r=this._createStream(e.id,"inbound",{protocol:e.protocol}),this.onRemoteStream(r)}if(r==null){this.log.error(`no stream found for ${e.id}`);return}e.type==="data"?r.onData(e.chunk):e.type==="reset"?r.onRemoteReset():e.type==="closeWrite"?r.onRemoteCloseWrite():e.type==="closeRead"?r.onRemoteCloseRead():e.type==="pause"?r.onRemotePaused():e.type==="resume"&&r.onRemoteResumed()}async onCreateStream(e){return this.nextStreamId+=2,this._createStream(`${this.nextStreamId}`,"outbound",e)}_createStream(e,r,n){return this.log.trace("createStream %s %s",r,e),new Jn({...this.streamOptions,...n,id:e,direction:r,log:this.log.newScope(`stream:${r}:${e}`),sendMessage:this.sendMessage,encoding:this.encoding,maxMessageSize:this.maxMessageSize-Ui,protocol:""})}},Zn=class{protocol="/mock-muxer/1.0.0";init;constructor(e){this.init=e}createStreamMuxer(e){return new Yn(e,{...this.init})}};function Nr(t={}){return new Zn(t)}function Rf(t,e){if(typeof t=="string")return $f(t);if(typeof t=="number")return jf(t,e);throw Error(`Value provided to ms() must be a string or number. value=${JSON.stringify(t)}`)}var kr=Rf;function $f(t){if(typeof t!="string"||t.length===0||t.length>100)throw 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),s=n.toLowerCase();switch(s){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 Error(`Unknown unit "${s}" provided to ms.parse(). value=${JSON.stringify(t)}`)}}function zf(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 Vf(t){let e=Math.abs(t);return e>=315576e5?$e(t,e,315576e5,"year"):e>=26298e5?$e(t,e,26298e5,"month"):e>=6048e5?$e(t,e,6048e5,"week"):e>=864e5?$e(t,e,864e5,"day"):e>=36e5?$e(t,e,36e5,"hour"):e>=6e4?$e(t,e,6e4,"minute"):e>=1e3?$e(t,e,1e3,"second"):`${t} ms`}function jf(t,e){if(typeof t!="number"||!Number.isFinite(t))throw Error("Value provided to ms.format() must be of type number.");return e?.long?Vf(t):zf(t)}function $e(t,e,r,n){let o=e>=r*1.5;return`${Math.round(t/r)} ${n}${o?"s":""}`}function eo(t){r.debug=r,r.default=r,r.coerce=c,r.disable=s,r.enable=o,r.enabled=i,r.humanize=kr,r.destroy=u,Object.keys(t).forEach(l=>{r[l]=t[l]}),r.names=[],r.skips=[],r.formatters={};function e(l){let d=0;for(let h=0;h<l.length;h++)d=(d<<5)-d+l.charCodeAt(h),d|=0;return r.colors[Math.abs(d)%r.colors.length]}r.selectColor=e;function r(l,d){let h,g=null,x,v;function b(...w){if(!b.enabled)return;let C=b,L=Number(new Date),O=L-(h||L);C.diff=O,C.prev=h,C.curr=L,h=L,w[0]=r.coerce(w[0]),typeof w[0]!="string"&&w.unshift("%O");let k=0;w[0]=w[0].replace(/%([a-zA-Z%])/g,(R,Y)=>{if(R==="%%")return"%";k++;let Ae=r.formatters[Y];if(typeof Ae=="function"){let ji=w[k];R=Ae.call(C,ji),w.splice(k,1),k--}return R}),r.formatArgs.call(C,w),d?.onLog!=null&&d.onLog(...w),(C.log||r.log).apply(C,w)}return b.namespace=l,b.useColors=r.useColors(),b.color=r.selectColor(l),b.extend=n,b.destroy=r.destroy,Object.defineProperty(b,"enabled",{enumerable:!0,configurable:!1,get:()=>g!==null?g:(x!==r.namespaces&&(x=r.namespaces,v=r.enabled(l)),v),set:w=>{g=w}}),typeof r.init=="function"&&r.init(b),b}function n(l,d){let h=r(this.namespace+(typeof d>"u"?":":d)+l);return h.log=this.log,h}function o(l){r.save(l),r.namespaces=l,r.names=[],r.skips=[];let d,h=(typeof l=="string"?l:"").split(/[\s,]+/),g=h.length;for(d=0;d<g;d++)h[d]&&(l=h[d].replace(/\*/g,".*?"),l[0]==="-"?r.skips.push(new RegExp("^"+l.substr(1)+"$")):r.names.push(new RegExp("^"+l+"$")))}function s(){let l=[...r.names.map(a),...r.skips.map(a).map(d=>"-"+d)].join(",");return r.enable(""),l}function i(l){if(l[l.length-1]==="*")return!0;let d,h;for(d=0,h=r.skips.length;d<h;d++)if(r.skips[d].test(l))return!1;for(d=0,h=r.names.length;d<h;d++)if(r.names[d].test(l))return!0;return!1}function a(l){return l.toString().substring(2,l.toString().length-2).replace(/\.\*\?$/,"*")}function c(l){return l instanceof Error?l.stack??l.message:l}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 Br=Kf(),qf=["#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 Wf(){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 Gf(t){if(t[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+t[0]+(this.useColors?"%c ":" ")+"+"+kr(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 Hf=console.debug??console.log??(()=>{});function Xf(t){try{t?Br?.setItem("debug",t):Br?.removeItem("debug")}catch{}}function Qf(){let t;try{t=Br?.getItem("debug")}catch{}return!t&&typeof globalThis.process<"u"&&"env"in globalThis.process&&(t=globalThis.process.env.DEBUG),t}function Kf(){try{return localStorage}catch{}}function Jf(t){t.j=function(e){try{return JSON.stringify(e)}catch(r){return"[UnexpectedJSONParseError]: "+r.message}}}var Ni=eo({formatArgs:Gf,save:Xf,load:Qf,useColors:Wf,setupFormatters:Jf,colors:qf,storage:Br,log:Hf});var z=Ni;z.formatters.b=t=>t==null?"undefined":Q.baseEncode(t);z.formatters.t=t=>t==null?"undefined":ae.baseEncode(t);z.formatters.m=t=>t==null?"undefined":Yr.baseEncode(t);z.formatters.p=t=>t==null?"undefined":t.toString();z.formatters.c=t=>t==null?"undefined":t.toString();z.formatters.k=t=>t==null?"undefined":t.toString();z.formatters.a=t=>t==null?"undefined":t.toString();function ki(t,e=""){let r=Bi(t.message),n=Bi(t.stack);return r!=null&&n!=null?n.includes(r)?`${n.split(`
2
+ "use strict";var Libp2PUtils=(()=>{var qi=Object.create;var jt=Object.defineProperty;var Wi=Object.getOwnPropertyDescriptor;var Gi=Object.getOwnPropertyNames;var Hi=Object.getPrototypeOf,Xi=Object.prototype.hasOwnProperty;var Qi=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),V=(t,e)=>{for(var r in e)jt(t,r,{get:e[r],enumerable:!0})},co=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Gi(e))!Xi.call(t,o)&&o!==r&&jt(t,o,{get:()=>e[o],enumerable:!(n=Wi(e,o))||n.enumerable});return t};var Ki=(t,e,r)=>(r=t!=null?qi(Hi(t)):{},co(e||!t||!t.__esModule?jt(r,"default",{value:t,enumerable:!0}):r,t)),Ji=t=>co(jt({},"__esModule",{value:!0}),t);var Ho=Qi(wt=>{(function(){var t,e,r,n,o,s,i,a;a=function(c){var u,l,d,h;return u=(c&255<<24)>>>24,l=(c&255<<16)>>>16,d=(c&65280)>>>8,h=c&255,[u,l,d,h].join(".")},i=function(c){var u,l,d,h,g,x;for(u=[],d=h=0;h<=3&&c.length!==0;d=++h){if(d>0){if(c[0]!==".")throw new Error("Invalid IP");c=c.substring(1)}x=e(c),g=x[0],l=x[1],c=c.substring(l),u.push(g)}if(c.length!==0)throw new Error("Invalid IP");switch(u.length){case 1:if(u[0]>4294967295)throw new Error("Invalid IP");return u[0]>>>0;case 2:if(u[0]>255||u[1]>16777215)throw new Error("Invalid IP");return(u[0]<<24|u[1])>>>0;case 3:if(u[0]>255||u[1]>255||u[2]>65535)throw new Error("Invalid IP");return(u[0]<<24|u[1]<<16|u[2])>>>0;case 4:if(u[0]>255||u[1]>255||u[2]>255||u[3]>255)throw new Error("Invalid IP");return(u[0]<<24|u[1]<<16|u[2]<<8|u[3])>>>0;default:throw new Error("Invalid IP")}},r=function(c){return c.charCodeAt(0)},n=r("0"),s=r("a"),o=r("A"),e=function(c){var u,l,d,h,g;for(h=0,u=10,l="9",d=0,c.length>1&&c[d]==="0"&&(c[d+1]==="x"||c[d+1]==="X"?(d+=2,u=16):"0"<=c[d+1]&&c[d+1]<="9"&&(d++,u=8,l="7")),g=d;d<c.length;){if("0"<=c[d]&&c[d]<=l)h=h*u+(r(c[d])-n)>>>0;else if(u===16)if("a"<=c[d]&&c[d]<="f")h=h*u+(10+r(c[d])-s)>>>0;else if("A"<=c[d]&&c[d]<="F")h=h*u+(10+r(c[d])-o)>>>0;else break;else break;if(h>4294967295)throw new Error("too large");d++}if(d===g)throw new Error("empty octet");return[h,d]},t=(function(){function c(u,l){var d,h,g,x;if(typeof u!="string")throw new Error("Missing `net' parameter");if(l||(x=u.split("/",2),u=x[0],l=x[1]),l||(l=32),typeof l=="string"&&l.indexOf(".")>-1){try{this.maskLong=i(l)}catch(v){throw d=v,new Error("Invalid mask: "+l)}for(h=g=32;g>=0;h=--g)if(this.maskLong===4294967295<<32-h>>>0){this.bitmask=h;break}}else if(l||l===0)this.bitmask=parseInt(l,10),this.maskLong=0,this.bitmask>0&&(this.maskLong=4294967295<<32-this.bitmask>>>0);else throw new Error("Invalid mask: empty");try{this.netLong=(i(u)&this.maskLong)>>>0}catch(v){throw d=v,new Error("Invalid net address: "+u)}if(!(this.bitmask<=32))throw new Error("Invalid mask for ip4: "+l);this.size=Math.pow(2,32-this.bitmask),this.base=a(this.netLong),this.mask=a(this.maskLong),this.hostmask=a(~this.maskLong),this.first=this.bitmask<=30?a(this.netLong+1):this.base,this.last=this.bitmask<=30?a(this.netLong+this.size-2):a(this.netLong+this.size-1),this.broadcast=this.bitmask<=30?a(this.netLong+this.size-1):void 0}return c.prototype.contains=function(u){return typeof u=="string"&&(u.indexOf("/")>0||u.split(".").length!==4)&&(u=new c(u)),u instanceof c?this.contains(u.base)&&this.contains(u.broadcast||u.last):(i(u)&this.maskLong)>>>0===(this.netLong&this.maskLong)>>>0},c.prototype.next=function(u){return u==null&&(u=1),new c(a(this.netLong+this.size*u),this.mask)},c.prototype.forEach=function(u){var l,d,h;for(h=i(this.first),d=i(this.last),l=0;h<=d;)u(a(h),h,l),l++,h++},c.prototype.toString=function(){return this.base+"/"+this.bitmask},c})(),wt.ip2long=i,wt.long2ip=a,wt.Netmask=t}).call(wt)});var fl={};V(fl,{AbstractMessageStream:()=>ke,AbstractMultiaddrConnection:()=>Ct,AbstractStream:()=>Be,AbstractStreamMuxer:()=>Lt,AdaptiveTimeout:()=>Cn,BloomFilter:()=>gt,CuckooFilter:()=>ve,DEFAULT_FAILURE_MULTIPLIER:()=>Jo,DEFAULT_INTERVAL:()=>es,DEFAULT_MAX_TIMEOUT:()=>Zo,DEFAULT_MIN_TIMEOUT:()=>Yo,DEFAULT_TIMEOUT_MULTIPLIER:()=>Ko,InvalidDataLengthError:()=>fr,InvalidDataLengthLengthError:()=>lr,InvalidMessageLengthError:()=>tt,LengthPrefixedDecoder:()=>Pn,MaxEarlyStreamsError:()=>_t,MemoryStorage:()=>Pr,MockStream:()=>to,MovingAverage:()=>Me,PeerQueue:()=>oo,PriorityQueue:()=>so,Queue:()=>re,QueueFullError:()=>vt,RateLimitError:()=>Et,RateLimiter:()=>io,ScalableCuckooFilter:()=>yt,StreamClosedError:()=>St,UnexpectedEOFError:()=>Ce,UnwrappedError:()=>At,byteStream:()=>_s,createBloomFilter:()=>Po,createCuckooFilter:()=>Oo,createScalableCuckooFilter:()=>Ro,debounce:()=>Ze,echo:()=>Mn,echoStream:()=>al,getNetConfig:()=>q,getThinWaistAddresses:()=>Nu,ipPortToMultiaddr:()=>Bu,isAsyncGenerator:()=>Mu,isGenerator:()=>Pu,isGlobalUnicast:()=>vc,isGlobalUnicastIp:()=>ku,isLinkLocal:()=>_c,isLinkLocalIp:()=>ef,isLoopback:()=>Sc,isNetworkAddress:()=>Cc,isPrivate:()=>Nc,isPrivateIp:()=>wn,isPromise:()=>Sn,lpStream:()=>Ss,messageStreamToDuplex:()=>Cs,mockMuxer:()=>Nr,multiaddrConnectionPair:()=>no,pbStream:()=>Qu,pipe:()=>Ju,repeatingTask:()=>il,streamPair:()=>Vi,trackedList:()=>cl,trackedMap:()=>ul});var de=class extends Error{static name="AbortError";constructor(e="The operation was aborted"){super(e),this.name="AbortError"}};var $=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}};var qt=class extends Error{static name="MuxerClosedError";constructor(e="The muxer is closed"){super(e),this.name="MuxerClosedError"}},Wt=class extends Error{static name="StreamResetError";constructor(e="The stream has been reset"){super(e),this.name="StreamResetError"}};var be=class extends Error{static name="StreamStateError";constructor(e="The stream is in an invalid state"){super(e),this.name="StreamStateError"}},ct=class extends Error{static name="StreamBufferError";constructor(e="The stream buffer was full"){super(e),this.name="StreamBufferError"}};var se=class extends Event{data;constructor(e,r){super("message",r),this.data=e}},ze=class extends Event{error;local;constructor(e,r,n){super("close",n),this.error=r,this.local=e}},Gt=class extends ze{constructor(e,r){super(!0,e,r)}},Ht=class extends ze{constructor(e,r){super(!1,e,r)}};var ie=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){super.addEventListener(e,r,n);let o=this.#e.get(e);o==null&&(o=[],this.#e.set(e,o)),o.push({callback:r,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(e,r,n){super.removeEventListener(e.toString(),r??null,n);let o=this.#e.get(e);o!=null&&(o=o.filter(({callback:s})=>s!==r),this.#e.set(e,o))}dispatchEvent(e){let r=super.dispatchEvent(e),n=this.#e.get(e.type);return n==null||(n=n.filter(({once:o})=>!o),this.#e.set(e.type,n)),r}safeDispatchEvent(e,r={}){return this.dispatchEvent(new CustomEvent(e,r))}};var Vr={};V(Vr,{base58btc:()=>Q,base58flickr:()=>oa});var pl=new Uint8Array(0);function uo(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 he(t){if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return t;if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);throw new Error("Unknown type, must be binary type")}function fo(t){return new TextEncoder().encode(t)}function lo(t){return new TextDecoder().decode(t)}function Yi(t,e){if(t.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var o=0;o<t.length;o++){var s=t.charAt(o),i=s.charCodeAt(0);if(r[i]!==255)throw new TypeError(s+" is ambiguous");r[i]=o}var a=t.length,c=t.charAt(0),u=Math.log(a)/Math.log(256),l=Math.log(256)/Math.log(a);function d(x){if(x instanceof Uint8Array||(ArrayBuffer.isView(x)?x=new Uint8Array(x.buffer,x.byteOffset,x.byteLength):Array.isArray(x)&&(x=Uint8Array.from(x))),!(x instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(x.length===0)return"";for(var v=0,b=0,w=0,C=x.length;w!==C&&x[w]===0;)w++,v++;for(var L=(C-w)*l+1>>>0,O=new Uint8Array(L);w!==C;){for(var k=x[w],le=0,R=L-1;(k!==0||le<b)&&R!==-1;R--,le++)k+=256*O[R]>>>0,O[R]=k%a>>>0,k=k/a>>>0;if(k!==0)throw new Error("Non-zero carry");b=le,w++}for(var Y=L-b;Y!==L&&O[Y]===0;)Y++;for(var Ae=c.repeat(v);Y<L;++Y)Ae+=t.charAt(O[Y]);return Ae}function h(x){if(typeof x!="string")throw new TypeError("Expected String");if(x.length===0)return new Uint8Array;var v=0;if(x[v]!==" "){for(var b=0,w=0;x[v]===c;)b++,v++;for(var C=(x.length-v)*u+1>>>0,L=new Uint8Array(C);x[v];){var O=r[x.charCodeAt(v)];if(O===255)return;for(var k=0,le=C-1;(O!==0||k<w)&&le!==-1;le--,k++)O+=a*L[le]>>>0,L[le]=O%256>>>0,O=O/256>>>0;if(O!==0)throw new Error("Non-zero carry");w=k,v++}if(x[v]!==" "){for(var R=C-w;R!==C&&L[R]===0;)R++;for(var Y=new Uint8Array(b+(C-R)),Ae=b;R!==C;)Y[Ae++]=L[R++];return Y}}}function g(x){var v=h(x);if(v)return v;throw new Error(`Non-${e} character`)}return{encode:d,decodeUnsafe:h,decode:g}}var Zi=Yi,ea=Zi,mo=ea;var Or=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")}},Rr=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 po(this,e)}},$r=class{decoders;constructor(e){this.decoders=e}or(e){return po(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 po(t,e){return new $r({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var zr=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 Or(e,r,n),this.decoder=new Rr(e,r,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function Ve({name:t,prefix:e,encode:r,decode:n}){return new zr(t,e,r,n)}function xe({name:t,prefix:e,alphabet:r}){let{encode:n,decode:o}=mo(r,t);return Ve({prefix:e,name:t,encode:n,decode:s=>he(o(s))})}function ta(t,e,r,n){let o=t.length;for(;t[o-1]==="=";)--o;let s=new Uint8Array(o*r/8|0),i=0,a=0,c=0;for(let u=0;u<o;++u){let l=e[t[u]];if(l===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|l,i+=r,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=r||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function ra(t,e,r){let n=e[e.length-1]==="=",o=(1<<r)-1,s="",i=0,a=0;for(let c=0;c<t.length;++c)for(a=a<<8|t[c],i+=8;i>r;)i-=r,s+=e[o&a>>i];if(i!==0&&(s+=e[o&a<<r-i]),n)for(;(s.length*r&7)!==0;)s+="=";return s}function na(t){let e={};for(let r=0;r<t.length;++r)e[t[r]]=r;return e}function I({name:t,prefix:e,bitsPerChar:r,alphabet:n}){let o=na(n);return Ve({prefix:e,name:t,encode(s){return ra(s,n,r)},decode(s){return ta(s,o,r,t)}})}var Q=xe({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),oa=xe({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var jr={};V(jr,{base32:()=>ae,base32hex:()=>ca,base32hexpad:()=>fa,base32hexpadupper:()=>la,base32hexupper:()=>ua,base32pad:()=>ia,base32padupper:()=>aa,base32upper:()=>sa,base32z:()=>da});var ae=I({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),sa=I({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),ia=I({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),aa=I({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),ca=I({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),ua=I({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),fa=I({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),la=I({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),da=I({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var qr={};V(qr,{base36:()=>ut,base36upper:()=>ha});var ut=xe({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),ha=xe({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var ma=bo,go=128,pa=127,ga=~pa,ya=Math.pow(2,31);function bo(t,e,r){e=e||[],r=r||0;for(var n=r;t>=ya;)e[r++]=t&255|go,t/=128;for(;t&ga;)e[r++]=t&255|go,t>>>=7;return e[r]=t|0,bo.bytes=r-n+1,e}var ba=Wr,xa=128,yo=127;function Wr(t,n){var r=0,n=n||0,o=0,s=n,i,a=t.length;do{if(s>=a)throw Wr.bytes=0,new RangeError("Could not decode varint");i=t[s++],r+=o<28?(i&yo)<<o:(i&yo)*Math.pow(2,o),o+=7}while(i>=xa);return Wr.bytes=s-n,r}var wa=Math.pow(2,7),Ea=Math.pow(2,14),va=Math.pow(2,21),_a=Math.pow(2,28),Sa=Math.pow(2,35),Ca=Math.pow(2,42),La=Math.pow(2,49),Ia=Math.pow(2,56),Aa=Math.pow(2,63),Ta=function(t){return t<wa?1:t<Ea?2:t<va?3:t<_a?4:t<Sa?5:t<Ca?6:t<La?7:t<Ia?8:t<Aa?9:10},Da={encode:ma,decode:ba,encodingLength:Ta},Fa=Da,ft=Fa;function lt(t,e=0){return[ft.decode(t,e),ft.decode.bytes]}function je(t,e,r=0){return ft.encode(t,e,r),e}function qe(t){return ft.encodingLength(t)}function Ge(t,e){let r=e.byteLength,n=qe(t),o=n+qe(r),s=new Uint8Array(o+r);return je(t,s,0),je(r,s,n),s.set(e,o),new We(t,r,e,s)}function xo(t){let e=he(t),[r,n]=lt(e),[o,s]=lt(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new We(r,o,i,e)}function wo(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&uo(t.bytes,r.bytes)}}var We=class{code;size;digest;bytes;constructor(e,r,n,o){this.code=e,this.size=r,this.digest=n,this.bytes=o}};function Eo(t,e){let{bytes:r,version:n}=t;switch(n){case 0:return Na(r,Gr(t),e??Q.encoder);default:return ka(r,Gr(t),e??ae.encoder)}}var vo=new WeakMap;function Gr(t){let e=vo.get(t);if(e==null){let r=new Map;return vo.set(t,r),r}return e}var He=class t{code;version;multihash;bytes;"/";constructor(e,r,n,o){this.code=r,this.version=e,this.multihash=n,this.bytes=o,this["/"]=o}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!==ht)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Ba)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=Ge(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&&wo(e.multihash,n.multihash)}toString(e){return Eo(this,e)}toJSON(){return{"/":Eo(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:s,bytes:i}=r;return new t(n,o,s,i??_o(n,o,s.bytes))}else if(r[Ma]===!0){let{version:n,multihash:o,code:s}=r,i=xo(o);return t.create(n,s,i)}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!==ht)throw new Error(`Version 0 CID must use dag-pb (code: ${ht}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let o=_o(e,r,n.bytes);return new t(e,r,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,ht,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=he(e.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let s=o.subarray(r.multihashSize-r.digestSize),i=new We(r.multihashCode,r.digestSize,s,o);return[r.version===0?t.createV0(i):t.createV1(r.codec,i),e.subarray(r.size)]}static inspectBytes(e){let r=0,n=()=>{let[d,h]=lt(e.subarray(r));return r+=h,d},o=n(),s=ht;if(o===18?(o=0,r=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=r,a=n(),c=n(),u=r+c,l=u-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:l,size:u}}static parse(e,r){let[n,o]=Ua(e,r),s=t.decode(o);if(s.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Gr(s).set(n,e),s}};function Ua(t,e){switch(t[0]){case"Q":{let r=e??Q;return[Q.prefix,r.decode(`${Q.prefix}${t}`)]}case Q.prefix:{let r=e??Q;return[Q.prefix,r.decode(t)]}case ae.prefix:{let r=e??ae;return[ae.prefix,r.decode(t)]}case ut.prefix:{let r=e??ut;return[ut.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 Na(t,e,r){let{prefix:n}=r;if(n!==Q.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=e.get(n);if(o==null){let s=r.encode(t).slice(1);return e.set(n,s),s}else return o}function ka(t,e,r){let{prefix:n}=r,o=e.get(n);if(o==null){let s=r.encode(t);return e.set(n,s),s}else return o}var ht=112,Ba=18;function _o(t,e,r){let n=qe(t),o=n+qe(e),s=new Uint8Array(o+r.byteLength);return je(t,s,0),je(e,s,n),s.set(r,o),s}var Ma=Symbol.for("@ipld/js-cid/CID");var Hr={};V(Hr,{identity:()=>Ra});var So=0,Pa="identity",Co=he;function Oa(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 Ge(So,Co(t))}var Ra={code:So,name:Pa,encode:Co,digest:Oa};function Xe(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 j(t=0){return new Uint8Array(t)}function Z(t=0){return new Uint8Array(t)}function we(t,e){e==null&&(e=t.reduce((o,s)=>o+s.length,0));let r=Z(e),n=0;for(let o of t)r.set(o,n),n+=o.length;return r}var Io=Symbol.for("@achingbrain/uint8arraylist");function Lo(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 Qe(t){return!!t?.[Io]}var A=class t{bufs;length;[Io]=!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(Qe(n))r+=n.byteLength,this.bufs.push(...n.bufs);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(Qe(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=Lo(this.bufs,e);return r.buf[r.index]}set(e,r){let n=Lo(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(Qe(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 we(n,o)}subarray(e,r){let{bufs:n,length:o}=this._subList(e,r);return n.length===1?n[0]:we(n,o)}sublist(e,r){let{bufs:n,length:o}=this._subList(e,r),s=new t;return s.length=o,s.bufs=[...n],s}_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 s=0;s<this.bufs.length;s++){let i=this.bufs[s],a=o,c=a+i.byteLength;if(o=c,e>=c)continue;let u=e>=a&&e<c,l=r>a&&r<=c;if(u&&l){if(e===a&&r===c){n.push(i);break}let d=e-a;n.push(i.subarray(d,d+(r-e)));break}if(u){if(e===0){n.push(i);continue}n.push(i.subarray(e-a));continue}if(l){if(r===c){n.push(i);break}n.push(i.subarray(0,r-a));break}n.push(i)}return{bufs:n,length:r-e}}indexOf(e,r=0){if(!Qe(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 s=256,i=new Int32Array(s);for(let d=0;d<s;d++)i[d]=-1;for(let d=0;d<o;d++)i[n[d]]=d;let a=i,c=this.byteLength-n.byteLength,u=n.byteLength-1,l;for(let d=r;d<=c;d+=l){l=0;for(let h=u;h>=0;h--){let g=this.get(d+h);if(n[h]!==g){l=Math.max(1,h-a[g]);break}}if(l===0)return d}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=Z(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=j(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=j(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=j(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=Z(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=j(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=j(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=j(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=j(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=j(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(!Xe(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,s)=>o+s.byteLength,0)),n.length=r,n}};var Xr={};V(Xr,{base10:()=>$a});var $a=xe({prefix:"9",name:"base10",alphabet:"0123456789"});var Qr={};V(Qr,{base16:()=>za,base16upper:()=>Va});var za=I({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Va=I({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Kr={};V(Kr,{base2:()=>ja});var ja=I({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Jr={};V(Jr,{base256emoji:()=>Xa});var Ao=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}"),qa=Ao.reduce((t,e,r)=>(t[r]=e,t),[]),Wa=Ao.reduce((t,e,r)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return t[n]=r,t},[]);function Ga(t){return t.reduce((e,r)=>(e+=qa[r],e),"")}function Ha(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=Wa[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(o)}return new Uint8Array(e)}var Xa=Ve({prefix:"\u{1F680}",name:"base256emoji",encode:Ga,decode:Ha});var en={};V(en,{base64:()=>Yr,base64pad:()=>Qa,base64url:()=>Zr,base64urlpad:()=>Ka});var Yr=I({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Qa=I({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Zr=I({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Ka=I({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var tn={};V(tn,{base8:()=>Ja});var Ja=I({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var rn={};V(rn,{identity:()=>Ya});var Ya=Ve({prefix:"\0",name:"identity",encode:t=>lo(t),decode:t=>fo(t)});var Yl=new TextEncoder,Zl=new TextDecoder;var sn={};V(sn,{sha256:()=>rc,sha512:()=>nc});var tc=20;function on({name:t,code:e,encode:r,minDigestLength:n,maxDigestLength:o}){return new nn(t,e,r,n,o)}var nn=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,r,n,o,s){this.name=e,this.code=r,this.encode=n,this.minDigestLength=o??tc,this.maxDigestLength=s}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?To(n,this.code,r?.truncate):n.then(o=>To(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function To(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 Ge(e,t)}function Fo(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}var rc=on({name:"sha2-256",code:18,encode:Fo("SHA-256")}),nc=on({name:"sha2-512",code:19,encode:Fo("SHA-512")});var mt={...rn,...Kr,...tn,...Xr,...Qr,...jr,...qr,...Vr,...en,...Jr},ld={...sn,...Hr};function No(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var Uo=No("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),an=No("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=Z(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),oc={utf8:Uo,"utf-8":Uo,hex:mt.base16,latin1:an,ascii:an,binary:an,...mt},Qt=oc;function T(t,e="utf8"){let r=Qt[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}function Te(t,e="utf8"){let r=Qt[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.encoder.encode(t).substring(1)}function ko(t=32){let e=typeof globalThis=="object"?globalThis.crypto:null;if(typeof e?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");return e.getRandomValues(new Uint8Array(t))}var sc=Math.pow(2,7),ic=Math.pow(2,14),ac=Math.pow(2,21),cn=Math.pow(2,28),un=Math.pow(2,35),fn=Math.pow(2,42),ln=Math.pow(2,49),_=128,M=127;function P(t){if(t<sc)return 1;if(t<ic)return 2;if(t<ac)return 3;if(t<cn)return 4;if(t<un)return 5;if(t<fn)return 6;if(t<ln)return 7;if(Number.MAX_SAFE_INTEGER!=null&&t>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Kt(t,e,r=0){switch(P(t)){case 8:e[r++]=t&255|_,t/=128;case 7:e[r++]=t&255|_,t/=128;case 6:e[r++]=t&255|_,t/=128;case 5:e[r++]=t&255|_,t/=128;case 4:e[r++]=t&255|_,t>>>=7;case 3:e[r++]=t&255|_,t>>>=7;case 2:e[r++]=t&255|_,t>>>=7;case 1:{e[r++]=t&255,t>>>=7;break}default:throw new Error("unreachable")}return e}function cc(t,e,r=0){switch(P(t)){case 8:e.set(r++,t&255|_),t/=128;case 7:e.set(r++,t&255|_),t/=128;case 6:e.set(r++,t&255|_),t/=128;case 5:e.set(r++,t&255|_),t/=128;case 4:e.set(r++,t&255|_),t>>>=7;case 3:e.set(r++,t&255|_),t>>>=7;case 2:e.set(r++,t&255|_),t>>>=7;case 1:{e.set(r++,t&255),t>>>=7;break}default:throw new Error("unreachable")}return e}function uc(t,e){let r=t[e],n=0;if(n+=r&M,r<_||(r=t[e+1],n+=(r&M)<<7,r<_)||(r=t[e+2],n+=(r&M)<<14,r<_)||(r=t[e+3],n+=(r&M)<<21,r<_)||(r=t[e+4],n+=(r&M)*cn,r<_)||(r=t[e+5],n+=(r&M)*un,r<_)||(r=t[e+6],n+=(r&M)*fn,r<_)||(r=t[e+7],n+=(r&M)*ln,r<_))return n;throw new RangeError("Could not decode varint")}function fc(t,e){let r=t.get(e),n=0;if(n+=r&M,r<_||(r=t.get(e+1),n+=(r&M)<<7,r<_)||(r=t.get(e+2),n+=(r&M)<<14,r<_)||(r=t.get(e+3),n+=(r&M)<<21,r<_)||(r=t.get(e+4),n+=(r&M)*cn,r<_)||(r=t.get(e+5),n+=(r&M)*un,r<_)||(r=t.get(e+6),n+=(r&M)*fn,r<_)||(r=t.get(e+7),n+=(r&M)*ln,r<_))return n;throw new RangeError("Could not decode varint")}function Jt(t,e,r=0){return e==null&&(e=Z(P(t))),e instanceof Uint8Array?Kt(t,e,r):cc(t,e,r)}function me(t,e=0){return t instanceof Uint8Array?uc(t,e):fc(t,e)}function Yt(t){if(isNaN(t)||t<=0)throw new $("random bytes length must be a Number bigger than 0");return ko(t)}var dn={32:16777619n,64:1099511628211n,128:309485009821345068724781371n,256:374144419156711147060143317175368453031918731002211n,512:35835915874844867368919076489095108449946327955754392558399825615420669938882575126094039892345713852759n,1024:5016456510113118655434598811035278955030765345404790744303017523831112055108147451509157692220295382716162651878526895249385292291816524375083746691371804094271873160484737966720260389217684476157468082573n},Bo={32:2166136261n,64:14695981039346656037n,128:144066263297769815596495629667062367629n,256:100029257958052580907070968620625704837092796014241193945225284501741471925557n,512:9659303129496669498009435400716310466090418745672637896108374329434462657994582932197716438449813051892206539805784495328239340083876191928701583869517785n,1024:14197795064947621068722070641403218320880622795441933960878474914617582723252296732303717722150864096521202355549365628174669108571814760471015076148029755969804077320157692458563003215304957150157403644460363550505412711285966361610267868082893823963790439336411086884584107735010676915n},Mo=new globalThis.TextEncoder;function lc(t,e){let r=dn[e],n=Bo[e];for(let o=0;o<t.length;o++)n^=BigInt(t[o]),n=BigInt.asUintN(e,n*r);return n}function dc(t,e,r){if(r.length===0)throw new Error("The `utf8Buffer` option must have a length greater than zero");let n=dn[e],o=Bo[e],s=t;for(;s.length>0;){let i=Mo.encodeInto(s,r);s=s.slice(i.read);for(let a=0;a<i.written;a++)o^=BigInt(r[a]),o=BigInt.asUintN(e,o*n)}return o}function hn(t,{size:e=32,utf8Buffer:r}={}){if(!dn[e])throw new Error("The `size` option must be one of 32, 64, 128, 256, 512, or 1024");if(typeof t=="string"){if(r)return dc(t,e,r);t=Mo.encode(t)}return lc(t,e)}var Ee={hash:t=>Number(hn(t,{size:32})),hashV:(t,e)=>hc(Ee.hash(t,e))};function hc(t){let e=t.toString(16);return e.length%2===1&&(e=`0${e}`),T(e,"base16")}var mc=Math.LN2*Math.LN2,gt=class{seeds;bits;buffer;constructor(e={}){e.seeds!=null?this.seeds=e.seeds:this.seeds=gc(e.hashes??8),this.bits=e.bits??1024,this.buffer=j(Math.ceil(this.bits/8))}add(e){typeof e=="string"&&(e=T(e));for(let r=0;r<this.seeds.length;r++){let o=Ee.hash(e,this.seeds[r])%this.bits;this.setbit(o)}}has(e){typeof e=="string"&&(e=T(e));for(let r=0;r<this.seeds.length;r++){let o=Ee.hash(e,this.seeds[r])%this.bits;if(!this.getbit(o))return!1}return!0}clear(){this.buffer.fill(0)}setbit(e){let r=Math.floor(e/8),n=e%8,o=this.buffer[r];o|=1<<n,this.buffer[r]=o}getbit(e){let r=Math.floor(e/8),n=e%8;return(this.buffer[r]&1<<n)!==0}};function Po(t,e=.005){let r=pc(t,e);return new gt(r)}function pc(t,e=.005){let r=Math.round(-1*t*Math.log(e)/mc),n=Math.round(r/t*Math.LN2);return{bits:r,hashes:n}}function gc(t){let e,r,n=[];for(let o=0;o<t;o++)for(e=new A(Yt(4)),n[o]=e.getUint32(0,!0),r=0;r<o;r++)if(n[o]===n[r]){o--;break}return n}var mn=64,ee=class{fp;h;seed;constructor(e,r,n,o=2){if(o>mn)throw new TypeError("Invalid Fingerprint Size");let s=r.hashV(e,n),i=j(o);for(let a=0;a<i.length;a++)i[a]=s[a];i.length===0&&(i[0]=7),this.fp=i,this.h=r,this.seed=n}hash(){return this.h.hash(this.fp,this.seed)}equals(e){return e?.fp instanceof Uint8Array?Xe(this.fp,e.fp):!1}};function De(t,e){return Math.floor(Math.random()*(e-t))+t}var Fe=class{contents;constructor(e){this.contents=new Array(e).fill(null)}has(e){if(!(e instanceof ee))throw new TypeError("Invalid Fingerprint");return this.contents.some(r=>e.equals(r))}add(e){if(!(e instanceof ee))throw new TypeError("Invalid Fingerprint");for(let r=0;r<this.contents.length;r++)if(this.contents[r]==null)return this.contents[r]=e,!0;return!0}swap(e){if(!(e instanceof ee))throw new TypeError("Invalid Fingerprint");let r=De(0,this.contents.length-1),n=this.contents[r];return this.contents[r]=e,n}remove(e){if(!(e instanceof ee))throw new TypeError("Invalid Fingerprint");let r=this.contents.findIndex(n=>e.equals(n));return r>-1?(this.contents[r]=null,!0):!1}};var yc=500,ve=class{bucketSize;filterSize;fingerprintSize;buckets;count;hash;seed;constructor(e){this.filterSize=e.filterSize,this.bucketSize=e.bucketSize??4,this.fingerprintSize=e.fingerprintSize??2,this.count=0,this.buckets=[],this.hash=e.hash??Ee,this.seed=e.seed??De(0,Math.pow(2,10))}add(e){typeof e=="string"&&(e=T(e));let r=new ee(e,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(e,this.seed)%this.filterSize,o=(n^r.hash())%this.filterSize;if(this.buckets[n]==null&&(this.buckets[n]=new Fe(this.bucketSize)),this.buckets[o]==null&&(this.buckets[o]=new Fe(this.bucketSize)),this.buckets[n].add(r)||this.buckets[o].add(r))return this.count++,!0;let s=[n,o],i=s[De(0,s.length-1)];this.buckets[i]==null&&(this.buckets[i]=new Fe(this.bucketSize));for(let a=0;a<yc;a++){let c=this.buckets[i].swap(r);if(c!=null&&(i=(i^c.hash())%this.filterSize,this.buckets[i]==null&&(this.buckets[i]=new Fe(this.bucketSize)),this.buckets[i].add(c)))return this.count++,!0}return!1}has(e){typeof e=="string"&&(e=T(e));let r=new ee(e,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(e,this.seed)%this.filterSize,o=this.buckets[n]?.has(r)??!1;if(o)return o;let s=(n^r.hash())%this.filterSize;return this.buckets[s]?.has(r)??!1}remove(e){typeof e=="string"&&(e=T(e));let r=new ee(e,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(e,this.seed)%this.filterSize,o=this.buckets[n]?.remove(r)??!1;if(o)return this.count--,o;let s=(n^r.hash())%this.filterSize,i=this.buckets[s]?.remove(r)??!1;return i&&this.count--,i}get reliable(){return Math.floor(100*(this.count/this.filterSize))<=90}},bc={1:.5,2:.84,4:.95,8:.98};function xc(t=.001){return t>.002?2:t>1e-5?4:8}function pn(t,e=.001){let r=xc(e),n=bc[r],o=Math.round(t/n),s=Math.min(Math.ceil(Math.log2(1/e)+Math.log2(2*r)),mn);return{filterSize:o,bucketSize:r,fingerprintSize:s}}function Oo(t,e=.005){let r=pn(t,e);return new ve(r)}var yt=class{filterSize;bucketSize;fingerprintSize;scale;filterSeries;hash;seed;constructor(e){this.bucketSize=e.bucketSize??4,this.filterSize=e.filterSize??(1<<18)/this.bucketSize,this.fingerprintSize=e.fingerprintSize??2,this.scale=e.scale??2,this.hash=e.hash??Ee,this.seed=e.seed??De(0,Math.pow(2,10)),this.filterSeries=[new ve({filterSize:this.filterSize,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed})]}add(e){if(typeof e=="string"&&(e=T(e)),this.has(e))return!0;let r=this.filterSeries.find(n=>n.reliable);if(r==null){let n=this.filterSize*Math.pow(this.scale,this.filterSeries.length);r=new ve({filterSize:n,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed}),this.filterSeries.push(r)}return r.add(e)}has(e){typeof e=="string"&&(e=T(e));for(let r=0;r<this.filterSeries.length;r++)if(this.filterSeries[r].has(e))return!0;return!1}remove(e){typeof e=="string"&&(e=T(e));for(let r=0;r<this.filterSeries.length;r++)if(this.filterSeries[r].remove(e))return!0;return!1}get count(){return this.filterSeries.reduce((e,r)=>e+r.count,0)}};function Ro(t,e=.001,r){return new yt({...pn(t,e),...r??{}})}function q(t){let e=t.getComponents(),r={},n=0;if(e[n]?.name==="ip6zone"&&(r.zone=`${e[n].value}`,n++),e[n].name==="ip4"||e[n].name==="ip6"||e[n].name==="dns"||e[n].name==="dns4"||e[n].name==="dns6"?(r.type=e[n].name,r.host=e[n].value,n++):e[n].name==="dnsaddr"&&(r.type=e[n].name,r.host=`_dnsaddr.${e[n].value}`,n++),(e[n]?.name==="tcp"||e[n]?.name==="udp")&&(r.protocol=e[n].name==="tcp"?"tcp":"udp",r.port=parseInt(`${e[n].value}`),n++),e[n]?.name==="ipcidr"&&(r.type==="ip4"?r.cidr=parseInt(`${e[n].value}`):r.type==="ip6"&&(r.cidr=`${e[n].value}`),n++),r.type==null||r.host==null)throw new $(`Multiaddr ${t} was not an IPv4, IPv6, DNS, DNS4, DNS6 or DNSADDR address`);return e[n]?.name==="tls"&&e[n+1]?.name==="sni"&&(r.sni=e[n+1].value,n+=2),r}var Zt=class{index=0;input="";new(e){return this.index=0,this.input=e,this}readAtomically(e){let r=this.index,n=e();return n===void 0&&(this.index=r),n}parseWith(e){let r=e();if(this.index===this.input.length)return r}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(e){return this.readAtomically(()=>{let r=this.readChar();if(r===e)return r})}readSeparator(e,r,n){return this.readAtomically(()=>{if(!(r>0&&this.readGivenChar(e)===void 0))return n()})}readNumber(e,r,n,o){return this.readAtomically(()=>{let s=0,i=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",u=2**(8*o)-1;for(;;){let l=this.readAtomically(()=>{let d=this.readChar();if(d===void 0)return;let h=Number.parseInt(d,e);if(!Number.isNaN(h))return h});if(l===void 0)break;if(s*=e,s+=l,s>u||(i+=1,r!==void 0&&i>r))return}if(i!==0)return!n&&c&&i>1?void 0:s})}readIPv4Addr(){return this.readAtomically(()=>{let e=new Uint8Array(4);for(let r=0;r<e.length;r++){let n=this.readSeparator(".",r,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;e[r]=n}return e})}readIPv6Addr(){let e=r=>{for(let n=0;n<r.length/2;n++){let o=n*2;if(n<r.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return r[o]=i[0],r[o+1]=i[1],r[o+2]=i[2],r[o+3]=i[3],[o+4,!0]}let s=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(s===void 0)return[o,!1];r[o]=s>>8,r[o+1]=s&255}return[r.length,!1]};return this.readAtomically(()=>{let r=new Uint8Array(16),[n,o]=e(r);if(n===16)return r;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let s=new Uint8Array(14),i=16-(n+2),[a]=e(s.subarray(0,i));return r.set(s.subarray(0,a),16-a),r})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var $o=45,wc=15,Ke=new Zt;function er(t){if(!(t.length>wc))return Ke.new(t).parseWith(()=>Ke.readIPv4Addr())}function tr(t){if(t.includes("%")&&(t=t.split("%")[0]),!(t.length>$o))return Ke.new(t).parseWith(()=>Ke.readIPv6Addr())}function Je(t,e=!1){if(t.includes("%")&&(t=t.split("%")[0]),t.length>$o)return;let r=Ke.new(t).parseWith(()=>Ke.readIPAddr());if(r)return e&&r.length===4?Uint8Array.from([0,0,0,0,0,0,0,0,0,0,255,255,r[0],r[1],r[2],r[3]]):r}function zo(t,e,r){let n=0;for(let o of t)if(!(n<e)){if(n>r)break;if(o!==255)return!1;n++}return!0}function Vo(t,e,r,n){let o=0;for(let s of t)if(!(o<r)){if(o>n)break;if(s!==e[o])return!1;o++}return!0}function gn(t){switch(t.length){case Ue:return t.join(".");case Ne:{let e=[];for(let r=0;r<t.length;r++)r%2===0&&e.push(t[r].toString(16).padStart(2,"0")+t[r+1].toString(16).padStart(2,"0"));return e.join(":")}default:throw new Error("Invalid ip length")}}function jo(t){let e=0;for(let[r,n]of t.entries()){if(n===255){e+=8;continue}for(;(n&128)!=0;)e++,n=n<<1;if((n&128)!=0)return-1;for(let o=r+1;o<t.length;o++)if(t[o]!=0)return-1;break}return e}function qo(t){let e="0x";for(let r of t)e+=(r>>4).toString(16)+(r&15).toString(16);return e}var Ue=4,Ne=16,mh=parseInt("0xFFFF",16),Ec=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function bt(t,e){e.length===Ne&&t.length===Ue&&zo(e,0,11)&&(e=e.slice(12)),e.length===Ue&&t.length===Ne&&Vo(t,Ec,0,11)&&(t=t.slice(12));let r=t.length;if(r!=e.length)throw new Error("Failed to mask ip");let n=new Uint8Array(r);for(let o=0;o<r;o++)n[o]=t[o]&e[o];return n}function Wo(t,e){if(typeof e=="string"&&(e=Je(e)),e==null)throw new Error("Invalid ip");if(e.length!==t.network.length)return!1;for(let r=0;r<e.length;r++)if((t.network[r]&t.mask[r])!==(e[r]&t.mask[r]))return!1;return!0}function yn(t){let[e,r]=t.split("/");if(!e||!r)throw new Error("Failed to parse given CIDR: "+t);let n=Ue,o=er(e);if(o==null&&(n=Ne,o=tr(e),o==null))throw new Error("Failed to parse given CIDR: "+t);let s=parseInt(r,10);if(Number.isNaN(s)||String(s).length!==r.length||s<0||s>n*8)throw new Error("Failed to parse given CIDR: "+t);let i=bn(s,8*n);return{network:bt(o,i),mask:i}}function bn(t,e){if(e!==8*Ue&&e!==8*Ne)throw new Error("Invalid CIDR mask");if(t<0||t>e)throw new Error("Invalid CIDR mask");let r=e/8,n=new Uint8Array(r);for(let o=0;o<r;o++){if(t>=8){n[o]=255,t-=8;continue}n[o]=255-(255>>t),t=0}return n}var xt=class{constructor(e,r){if(r==null)({network:this.network,mask:this.mask}=yn(e));else{let n=Je(e);if(n==null)throw new Error("Failed to parse network");r=String(r);let o=parseInt(r,10);if(Number.isNaN(o)||String(o).length!==r.length||o<0||o>n.length*8){let s=Je(r);if(s==null)throw new Error("Failed to parse mask");this.mask=s}else this.mask=bn(o,8*n.length);this.network=bt(n,this.mask)}}contains(e){return Wo({network:this.network,mask:this.mask},e)}toString(){let e=jo(this.mask),r=e!==-1?String(e):qo(this.mask);return gn(this.network)+"/"+r}};function rr(t,e){return new xt(t).contains(e)}function vc(t){try{let e=q(t);switch(e.type){case"ip6":return rr("2000::/3",e.host);default:return!1}}catch{return!1}}function _c(t){try{let e=q(t);switch(e.type){case"ip4":return e.host.startsWith("169.254.");case"ip6":return e.host.toLowerCase().startsWith("fe80");default:return!1}}catch{return!1}}function Go(t){return/^127\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/i.test(t)||/^::1$/.test(t)}function Sc(t){try{let e=q(t);switch(e.type){case"ip4":case"ip6":return Go(e.host);default:return!1}}catch{return!1}}function Cc(t){try{return q(t),!0}catch{return!1}}function _e(t){return!!er(t)}function Se(t){return!!tr(t)}var Xo=Ki(Ho(),1),Lc=["0.0.0.0/8","10.0.0.0/8","100.64.0.0/10","127.0.0.0/8","169.254.0.0/16","172.16.0.0/12","192.0.0.0/24","192.0.0.0/29","192.0.0.8/32","192.0.0.9/32","192.0.0.10/32","192.0.0.170/32","192.0.0.171/32","192.0.2.0/24","192.31.196.0/24","192.52.193.0/24","192.88.99.0/24","192.168.0.0/16","192.175.48.0/24","198.18.0.0/15","198.51.100.0/24","203.0.113.0/24","240.0.0.0/4","255.255.255.255/32"],Ic=Lc.map(t=>new Xo.Netmask(t));function xn(t){for(let e of Ic)if(e.contains(t))return!0;return!1}function Ac(t){return/^::ffff:([0-9a-fA-F]{1,4}):([0-9a-fA-F]{1,4})$/.test(t)}function Tc(t){let e=t.split(":");if(e.length<2)return!1;let r=e[e.length-1].padStart(4,"0"),n=e[e.length-2].padStart(4,"0"),o=`${parseInt(n.substring(0,2),16)}.${parseInt(n.substring(2),16)}.${parseInt(r.substring(0,2),16)}.${parseInt(r.substring(2),16)}`;return xn(o)}function Dc(t){return/^::ffff:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(t)}function Fc(t){let e=t.split(":"),r=e[e.length-1];return xn(r)}function Uc(t){return/^::$/.test(t)||/^::1$/.test(t)||/^64:ff9b::([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(t)||/^100::([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(t)||/^2001::([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(t)||/^2001:2[0-9a-fA-F]:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(t)||/^2001:db8:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(t)||/^2002:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(t)||/^f[c-d]([0-9a-fA-F]{2,2}):/i.test(t)||/^fe[8-9a-bA-B][0-9a-fA-F]:/i.test(t)||/^ff([0-9a-fA-F]{2,2}):/i.test(t)}function wn(t){if(_e(t))return xn(t);if(Ac(t))return Tc(t);if(Dc(t))return Fc(t);if(Se(t))return Uc(t)}function Nc(t){try{let e=q(t);switch(e.type){case"ip4":case"ip6":return wn(e.host)??!1;default:return e.host==="localhost"}}catch{return!1}}function te(){let t={};return t.promise=new Promise((e,r)=>{t.resolve=e,t.reject=r}),t}var nr=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}},Ye=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new nr(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 nr(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 En=class extends Error{type;code;constructor(e,r){super(e??"The operation was aborted"),this.type="aborted",this.code=r??"ABORT_ERR"}};function ce(t={}){return kc(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 kc(t,e){e=e??{};let r=e.onEnd,n=new Ye,o,s,i,a=te(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((b,w)=>{s=C=>{s=null,n.push(C);try{b(t(n))}catch(L){w(L)}return o}}):t(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=te()})}},u=b=>s!=null?s(b):(n.push(b),o),l=b=>(n=new Ye,s!=null?s({error:b}):(n.push({error:b}),o)),d=b=>{if(i)return o;if(e?.objectMode!==!0&&b?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return u({done:!1,value:b})},h=b=>i?o:(i=!0,b!=null?l(b):u({done:!0})),g=()=>(n=new Ye,h(),{done:!0}),x=b=>(h(b),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:g,throw:x,push:d,end:h,get readableLength(){return n.size},onEmpty:async b=>{let w=b?.signal;if(w?.throwIfAborted(),n.isEmpty())return;let C,L;w!=null&&(C=new Promise((O,k)=>{L=()=>{k(new En)},w.addEventListener("abort",L)}));try{await Promise.race([a.promise,C])}finally{L!=null&&w!=null&&w?.removeEventListener("abort",L)}}},r==null)return o;let v=o;return o={[Symbol.asyncIterator](){return this},next(){return v.next()},throw(b){return v.throw(b),r!=null&&(r(b),r=void 0),{done:!0}},return(){return v.return(),r!=null&&(r(),r=void 0),{done:!0}},push:d,end(b){return v.end(b),r!=null&&(r(b),r=void 0),o},get readableLength(){return v.readableLength},onEmpty:b=>v.onEmpty(b)},o}var vn=class t extends Error{name="TimeoutError";constructor(e,r){super(e,r),Error.captureStackTrace?.(this,t)}},Qo=t=>t.reason??new DOMException("This operation was aborted.","AbortError");function _n(t,e){let{milliseconds:r,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout},signal:i}=e,a,c,l=new Promise((d,h)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(i?.aborted){h(Qo(i));return}if(i&&(c=()=>{h(Qo(i))},i.addEventListener("abort",c,{once:!0})),t.then(d,h),r===Number.POSITIVE_INFINITY)return;let g=new vn;a=s.setTimeout.call(void 0,()=>{if(n){try{d(n())}catch(x){h(x)}return}typeof t.cancel=="function"&&t.cancel(),o===!1?d():o instanceof Error?h(o):(g.message=o??`Promise timed out after ${r} milliseconds`,h(g))},r)}).finally(()=>{l.clear(),c&&i&&i.removeEventListener("abort",c)});return l.clear=()=>{s.clearTimeout.call(void 0,a),a=void 0},l}var Bc=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 Mc(t,e,r){let n,o=new Promise((s,i)=>{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:u,removeListener:l}=Bc(t),d=async(...g)=>{let x=r.multiArgs?g:g[0];if(r.filter)try{if(!await r.filter(x))return}catch(v){n(),i(v);return}c.push(x),r.count===c.length&&(n(),s(c))},h=(...g)=>{n(),i(r.rejectionMultiArgs?g:g[0])};n=()=>{for(let g of a)l(g,d);for(let g of r.rejectionEvents)a.includes(g)||l(g,h)};for(let g of a)u(g,d);for(let g of r.rejectionEvents)a.includes(g)||u(g,h);r.signal&&r.signal.addEventListener("abort",()=>{h(r.signal.reason)},{once:!0}),r.resolveImmediately&&s(c)});if(o.cancel=n,typeof r.timeout=="number"){let s=_n(o,{milliseconds:r.timeout});return s.cancel=()=>{n(),s.clear()},s}return o}function D(t,e,r){typeof r=="function"&&(r={filter:r}),r={...r,count:1,resolveImmediately:!1};let n=Mc(t,e,r),o=n.then(s=>s[0]);return o.cancel=n.cancel,o}function Ze(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 Et=class extends Error{remainingPoints;msBeforeNext;consumedPoints;isFirstInDuration;constructor(e="Rate limit exceeded",r){super(e),this.name="RateLimitError",this.remainingPoints=r.remainingPoints,this.msBeforeNext=r.msBeforeNext,this.consumedPoints=r.consumedPoints,this.isFirstInDuration=r.isFirstInDuration}},vt=class extends Error{static name="QueueFullError";constructor(e="The queue was full"){super(e),this.name="QueueFullError"}},Ce=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"},_t=class extends Error{static name="MaxEarlyStreamsError";name="MaxEarlyStreamsError"},St=class extends Error{static name="StreamClosedError";name="StreamClosedError"};function Pc(t){return t.reason}async function F(t,e,r){if(e==null)return t;let n=r?.translateError??Pc;if(e.aborted)return t.catch(()=>{}),Promise.reject(n(e));let o;try{return await Promise.race([t,new Promise((s,i)=>{o=()=>{i(n(e))},e.addEventListener("abort",o)})])}finally{o!=null&&e.removeEventListener("abort",o)}}var or=class{deferred;signal;constructor(e){this.signal=e,this.deferred=te(),this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(this.signal?.reason??new de)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function Oc(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var sr=class{id;fn;options;recipients;status;timeline;controller;constructor(e,r){this.id=Oc(),this.status="queued",this.fn=e,this.options=r,this.recipients=[],this.timeline={created:Date.now()},this.controller=new AbortController,this.controller.signal,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 de),this.cleanup())}async join(e={}){let r=new or(e.signal);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 F(this.fn({...this.options??{},signal:this.controller.signal}),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.cleanup(),e.signal?.removeEventListener("abort",this.onAbort)})}};var re=class extends ie{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=Ze(this.emitEmpty.bind(this),1),this.emitIdle=Ze(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 vt;let n=new sr(e,r);return this.enqueue(n),this.safeDispatchEvent("add"),this.tryToStartAnother(),n.join(r).then(o=>(this.safeDispatchEvent("completed",{detail:o}),this.safeDispatchEvent("success",{detail:{job:n,result:o}}),o)).catch(o=>{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:o}}),o})}clear(){this.queue.splice(0,this.queue.length)}abort(){this.queue.forEach(e=>{e.abort(new de)}),this.clear()}async onEmpty(e){this.size!==0&&await D(this,"empty",e)}async onSizeLessThan(e,r){this.size<e||await D(this,"next",{...r,filter:()=>this.size<e})}async onIdle(e){this.pending===0&&this.size===0||await D(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=ce({objectMode:!0}),n=c=>{c!=null?this.abort():this.clear(),r.end(c)},o=c=>{c.detail!=null&&r.push(c.detail)},s=c=>{n(c.detail.error)},i=()=>{n()},a=()=>{n(new de("Queue aborted"))};this.addEventListener("completed",o),this.addEventListener("failure",s),this.addEventListener("idle",i),e?.signal?.addEventListener("abort",a);try{yield*r}finally{this.removeEventListener("completed",o),this.removeEventListener("failure",s),this.removeEventListener("idle",i),e?.signal?.removeEventListener("abort",a),n()}}};var Rc=Math.pow(2,20)*4,ke=class extends ie{status;timeline;inactivityTimeout;maxReadBufferLength;maxWriteBufferLength;log;direction;maxMessageSize;readStatus;writeStatus;remoteReadStatus;remoteWriteStatus;writableNeedsDrain;readBuffer;writeBuffer;sendingData;onDrainPromise;constructor(e){super(),this.status="open",this.log=e.log,this.direction=e.direction??"outbound",this.inactivityTimeout=e.inactivityTimeout??12e4,this.maxReadBufferLength=e.maxReadBufferLength??Rc,this.maxWriteBufferLength=e.maxWriteBufferLength,this.maxMessageSize=e.maxMessageSize,this.readBuffer=new A,this.writeBuffer=new A,this.readStatus="readable",this.remoteReadStatus="readable",this.writeStatus="writable",this.remoteWriteStatus="writable",this.sendingData=!1,this.writableNeedsDrain=!1,this.timeline={open:Date.now()},this.processSendQueue=this.processSendQueue.bind(this);let r=()=>{this.writableNeedsDrain&&(this.log.trace("drain event received, continue sending data"),this.writableNeedsDrain=!1,this.processSendQueue()),this.onDrainPromise?.resolve()};this.addEventListener("drain",r);let n=o=>{this.onDrainPromise?.reject(o.error??new St)};this.addEventListener("close",n)}get readBufferLength(){return this.readBuffer.byteLength}get writeBufferLength(){return this.writeBuffer.byteLength}async onDrain(e){return this.writableNeedsDrain!==!0?Promise.resolve():(this.onDrainPromise==null&&(this.onDrainPromise=Promise.withResolvers()),F(this.onDrainPromise.promise,e?.signal))}async*[Symbol.asyncIterator](){if(this.readStatus!=="readable"&&this.readStatus!=="paused")return;let e=ce(),r=s=>{e.push(s.data)};this.addEventListener("message",r);let n=s=>{e.end(s.error)};this.addEventListener("close",n);let o=()=>{e.end()};this.addEventListener("remoteCloseWrite",o);try{yield*e}finally{this.removeEventListener("message",r),this.removeEventListener("close",n),this.removeEventListener("remoteCloseWrite",o)}}isReadable(){return this.status==="open"}send(e){if(this.writeStatus==="closed"||this.writeStatus==="closing")throw new be(`Cannot write to a stream that is ${this.writeStatus}`);return this.log.trace("append %d bytes to write buffer",e.byteLength),this.writeBuffer.append(e),this.processSendQueue()}abort(e){if(!(this.status==="aborted"||this.status==="reset"||this.status==="closed")){this.log.error("abort with error - %e",e),this.status="aborted",this.readBuffer.byteLength>0&&this.readBuffer.consume(this.readBuffer.byteLength),this.writeBuffer.byteLength>0&&(this.writeBuffer.consume(this.writeBuffer.byteLength),this.safeDispatchEvent("idle")),this.writeStatus="closed",this.remoteWriteStatus="closed",this.readStatus="closed",this.remoteReadStatus="closed",this.timeline.close=Date.now();try{this.sendReset(e)}catch(r){this.log("failed to send reset to remote - %e",r)}this.dispatchEvent(new Gt(e))}}pause(){if(this.readStatus==="closed"||this.readStatus==="closing")throw new be("Cannot pause a stream that is closing/closed");this.readStatus!=="paused"&&(this.readStatus="paused",this.sendPause())}resume(){if(this.readStatus==="closed"||this.readStatus==="closing")throw new be("Cannot resume a stream that is closing/closed");this.readStatus!=="readable"&&(this.readStatus="readable",this.dispatchReadBuffer(),this.sendResume())}push(e){if(this.readStatus==="closed"||this.readStatus==="closing")throw new be(`Cannot push data onto a stream that is ${this.readStatus}`);if(e.byteLength!==0){if(this.readBuffer.append(e),this.readStatus==="paused"||this.listenerCount("message")===0){this.checkReadBufferLength();return}setTimeout(()=>{this.dispatchReadBuffer()},0)}}unshift(e){if(this.readStatus==="closed"||this.readStatus==="closing")throw new be(`Cannot push data onto a stream that is ${this.readStatus}`);if(e.byteLength!==0){if(this.readBuffer.prepend(e),this.readStatus==="paused"||this.listenerCount("message")===0){this.checkReadBufferLength();return}setTimeout(()=>{this.dispatchReadBuffer()},0)}}onData(e){if(e.byteLength!==0){if(this.readStatus==="closing"||this.readStatus==="closed"){this.log("ignoring data - read status %s",this.readStatus);return}this.readBuffer.append(e),this.dispatchReadBuffer()}}addEventListener(...e){super.addEventListener.apply(this,e),e[0]==="message"&&this.readBuffer.byteLength>0&&queueMicrotask(()=>{this.dispatchReadBuffer()})}onRemoteReset(){this.log("remote reset"),this.status="reset",this.writeStatus="closed",this.remoteWriteStatus="closed",this.remoteReadStatus="closed",this.timeline.close=Date.now(),this.readBuffer.byteLength===0&&(this.readStatus="closed");let e=new Wt;this.dispatchEvent(new Ht(e))}onTransportClosed(e){this.log("transport closed"),this.readStatus==="readable"&&this.readBuffer.byteLength===0&&(this.log("close readable end after transport closed and read buffer is empty"),this.readStatus="closed"),this.remoteReadStatus!=="closed"&&(this.remoteReadStatus="closed"),this.remoteWriteStatus!=="closed"&&(this.remoteWriteStatus="closed"),this.writeStatus!=="closed"&&(this.writeStatus="closed"),e!=null?this.abort(e):(this.status==="open"||this.status==="closing")&&(this.timeline.close=Date.now(),this.status="closed",this.writeStatus="closed",this.remoteWriteStatus="closed",this.remoteReadStatus="closed",this.dispatchEvent(new ze))}onRemoteCloseWrite(){this.remoteWriteStatus!=="closed"&&(this.log.trace("on remote close write"),this.remoteWriteStatus="closed",this.safeDispatchEvent("remoteCloseWrite"),this.writeStatus==="closed"&&this.onTransportClosed())}onRemoteCloseRead(){this.log.trace("on remote close read"),this.remoteReadStatus="closed",this.writeBuffer.byteLength>0&&(this.writeBuffer.consume(this.writeBuffer.byteLength),this.safeDispatchEvent("idle"))}processSendQueue(){if(this.writableNeedsDrain)return this.log.trace("not processing send queue as drain is required"),this.checkWriteBufferLength(),!1;if(this.writeBuffer.byteLength===0)return this.log.trace("not processing send queue as no bytes to send"),!0;if(this.sendingData)return this.log.trace("not processing send queue as already sending data"),!0;this.sendingData=!0,this.log.trace("processing send queue with %d queued bytes",this.writeBuffer.byteLength);try{let e=!0,r=this.writeBuffer.byteLength,n=0;for(;this.writeBuffer.byteLength>0;){let o=Math.min(this.maxMessageSize??this.writeBuffer.byteLength,this.writeBuffer.byteLength);if(o===0){e=!1;break}let s=this.writeBuffer.sublist(0,o),i=new A(s);this.writeBuffer.consume(s.byteLength);let a=this.sendData(s);if(e=a.canSendMore,n+=a.sentBytes,a.sentBytes!==i.byteLength&&(i.consume(a.sentBytes),this.writeBuffer.prepend(i)),!e)break}return e||(this.log.trace("sent %d/%d bytes, pausing sending because underlying stream is full, %d bytes left in the write buffer",n,r,this.writeBuffer.byteLength),this.writableNeedsDrain=!0,this.checkWriteBufferLength()),this.writeBuffer.byteLength===0&&this.safeDispatchEvent("idle"),e}finally{this.sendingData=!1}}dispatchReadBuffer(){try{if(this.listenerCount("message")===0){this.log.trace("not dispatching pause buffer as there are no listeners for the message event");return}if(this.readBuffer.byteLength===0){this.log.trace("not dispatching pause buffer as there is no data to dispatch");return}if(this.readStatus==="paused"){this.log.trace("not dispatching pause buffer we are paused");return}if(this.readStatus==="closing"||this.readStatus==="closed"){this.log("dropping %d bytes because the readable end is %s",this.readBuffer.byteLength,this.readStatus),this.readBuffer.consume(this.readBuffer.byteLength);return}let e=this.readBuffer.sublist();this.readBuffer.consume(e.byteLength),this.dispatchEvent(new se(e))}finally{this.readBuffer.byteLength===0&&this.remoteWriteStatus==="closed"&&(this.log("close readable end after dispatching read buffer and remote writable end is closed"),this.readStatus="closed"),this.checkReadBufferLength()}}checkReadBufferLength(){this.readBuffer.byteLength>this.maxReadBufferLength&&this.abort(new ct(`Read buffer length of ${this.readBuffer.byteLength} exceeded limit of ${this.maxReadBufferLength}, read status is ${this.readStatus}`))}checkWriteBufferLength(){this.maxWriteBufferLength!=null&&this.writeBuffer.byteLength>this.maxWriteBufferLength&&this.abort(new ct(`Write buffer length of ${this.writeBuffer.byteLength} exceeded limit of ${this.maxWriteBufferLength}, write status is ${this.writeStatus}`))}onMuxerNeedsDrain(){this.writableNeedsDrain=!0}onMuxerDrain(){this.safeDispatchEvent("drain")}};var Ct=class extends ke{remoteAddr;metricPrefix;metrics;constructor(e){super(e),this.metricPrefix=e.metricPrefix??"",this.metrics=e.metrics,this.remoteAddr=e.remoteAddr,this.addEventListener("close",r=>{this.metrics?.increment({[`${this.metricPrefix}end`]:!0}),r.error!=null?r.local?this.metrics?.increment({[`${this.metricPrefix}abort`]:!0}):this.metrics?.increment({[`${this.metricPrefix}reset`]:!0}):r.local?this.metrics?.increment({[`${this.metricPrefix}_local_close`]:!0}):this.metrics?.increment({[`${this.metricPrefix}_remote_close`]:!0})})}async close(e){this.status==="open"&&(this.status="closing",this.writeStatus="closing",this.remoteWriteStatus="closing",this.remoteReadStatus="closing",(this.sendingData||this.writeBuffer.byteLength>0)&&(this.log("waiting for write queue to become idle before closing writable end of stream, %d unsent bytes",this.writeBuffer.byteLength),await D(this,"idle",{...e,rejectionEvents:["close"]})),this.writableNeedsDrain&&(this.log("waiting for write queue to drain before closing writable end of stream, %d unsent bytes",this.writeBuffer.byteLength),await D(this,"drain",{...e,rejectionEvents:["close"]})),await this.sendClose(e),this.onTransportClosed())}};function Sn(t){return t==null?!1:typeof t.then=="function"&&typeof t.catch=="function"&&typeof t.finally=="function"}var Lt=class extends ie{streams;protocol;status;log;maConn;streamOptions;earlyStreams;maxEarlyStreams;metrics;constructor(e,r){super(),this.maConn=e,this.protocol=r.protocol,this.streams=[],this.earlyStreams=[],this.status="open",this.log=e.log.newScope(r.name),this.streamOptions=r.streamOptions,this.maxEarlyStreams=r.maxEarlyStreams??10,this.metrics=r.metrics;let n=i=>{try{this.onData(i.data)}catch(a){this.abort(a),this.maConn.abort(a)}};this.maConn.addEventListener("message",n);let o=()=>{this.log("underlying stream drained, signal %d streams to continue writing",this.streams.length),this.streams.forEach(i=>{i.onMuxerDrain()})};this.maConn.addEventListener("drain",o);let s=()=>{this.log("underlying stream closed with status %s and %d streams",this.status,this.streams.length),this.onTransportClosed()};this.maConn.addEventListener("close",s)}send(e){let r=this.maConn.send(e);return r===!1&&(this.log("underlying stream saturated, signal %d streams to pause writing",this.streams.length),this.streams.forEach(n=>{n.onMuxerNeedsDrain()})),r}async close(e){this.status==="closed"||this.status==="closing"||(this.status="closing",await F(Promise.all([...this.streams].map(async r=>{await r.close(e)})),e?.signal),this.status="closed")}abort(e){this.status!=="closed"&&(this.status="closing",[...this.streams].forEach(r=>{r.abort(e)}),this.status="closed")}onTransportClosed(e){this.status="closing";try{[...this.streams].forEach(r=>{r.onTransportClosed(e)})}catch(r){this.abort(r)}this.status="closed"}async createStream(e){if(this.status!=="open")throw new qt;let r=this.onCreateStream({...this.streamOptions,...e});return Sn(r)&&(r=await r),this.streams.push(r),this.cleanUpStream(r),r}onRemoteStream(e){if(this.streams.push(e),this.cleanUpStream(e),this.listenerCount("stream")===0){this.earlyStreams.push(e),this.earlyStreams.length>this.maxEarlyStreams&&this.abort(new _t(`Too many early streams were opened - ${this.earlyStreams.length}/${this.maxEarlyStreams}`));return}this.safeDispatchEvent("stream",{detail:e})}cleanUpStream(e){let r=n=>{let o=this.streams.findIndex(s=>s===e);o!==-1&&this.streams.splice(o,1),n.error!=null?n.local?this.metrics?.increment({[`${e.direction}_stream_reset`]:!0}):this.metrics?.increment({[`${e.direction}_stream_abort`]:!0}):this.metrics?.increment({[`${e.direction}_stream_end`]:!0})};e.addEventListener("close",r),this.metrics?.increment({[`${e.direction}_stream`]:!0})}addEventListener(...e){super.addEventListener.apply(this,e),e[0]==="stream"&&this.earlyStreams.length>0&&queueMicrotask(()=>{this.earlyStreams.forEach(r=>{this.safeDispatchEvent("stream",{detail:r})}),this.earlyStreams=[]})}};var Be=class extends ke{id;protocol;constructor(e){super(e),this.id=e.id,this.protocol=e.protocol??""}async close(e){this.writeStatus==="closing"||this.writeStatus==="closed"||(this.writeStatus="closing",(this.sendingData||this.writeBuffer.byteLength>0)&&(this.log("waiting for write queue to become idle before closing writable end of stream, %d unsent bytes",this.writeBuffer.byteLength),await D(this,"idle",{...e,rejectionEvents:["close"]})),this.writableNeedsDrain&&(this.log("waiting for write queue to drain before closing writable end of stream, %d unsent bytes, sending %s",this.writeBuffer.byteLength,this.sendingData),await D(this,"drain",{...e,rejectionEvents:["close"]}),this.log("write queue drained, closing writable end of stream, %d unsent bytes, sending %s",this.writeBuffer.byteLength,this.sendingData)),await this.sendCloseWrite(e),this.writeStatus="closed",this.log("closed writable end gracefully"),this.remoteWriteStatus==="closed"&&this.onTransportClosed())}async closeRead(e){this.readStatus==="closing"||this.readStatus==="closed"||(this.readBuffer.byteLength>0&&this.readBuffer.consume(this.readBuffer.byteLength),this.readStatus="closing",await this.sendCloseRead(e),this.readStatus="closed",this.log("closed readable end gracefully"))}};function ir(t){let e=new globalThis.AbortController;function r(){let s=t.filter(i=>i?.aborted===!0).map(i=>i?.reason).pop();e.abort(s);for(let i of t)i?.removeEventListener!=null&&i.removeEventListener("abort",r)}for(let s of t){if(s?.aborted===!0){r();break}s?.addEventListener!=null&&s.addEventListener("abort",r)}function n(){for(let s of t)s?.removeEventListener!=null&&s.removeEventListener("abort",r)}let o=e.signal;return o.clear=n,o}var Me=class{movingAverage;variance;deviation;forecast;timeSpan;previousTime;constructor(e){this.timeSpan=e,this.movingAverage=0,this.variance=0,this.deviation=0,this.forecast=0}alpha(e,r){return 1-Math.exp(-(e-r)/this.timeSpan)}push(e,r=Date.now()){if(this.previousTime!=null){let n=this.alpha(r,this.previousTime),o=e-this.movingAverage,s=n*o;this.movingAverage=n*e+(1-n)*this.movingAverage,this.variance=(1-n)*(this.variance+o*s),this.deviation=Math.sqrt(this.variance),this.forecast=this.movingAverage+n*o}else this.movingAverage=e;this.previousTime=r}};var Ko=1.2,Jo=2,Yo=5e3,Zo=6e4,es=5e3,Cn=class{success;failure;next;metric;timeoutMultiplier;failureMultiplier;minTimeout;maxTimeout;constructor(e={}){let r=e.interval??es;this.success=new Me(r),this.failure=new Me(r),this.next=new Me(r),this.failureMultiplier=e.failureMultiplier??Jo,this.timeoutMultiplier=e.timeoutMultiplier??Ko,this.minTimeout=e.minTimeout??Yo,this.maxTimeout=e.maxTimeout??Zo,e.metricName!=null&&(this.metric=e.metrics?.registerMetricGroup(e.metricName))}getTimeoutSignal(e={}){let r=Math.round(this.next.movingAverage*(e.timeoutFactor??this.timeoutMultiplier));r<this.minTimeout&&(r=this.minTimeout),r>this.maxTimeout&&(r=this.maxTimeout);let n=AbortSignal.timeout(r),o=ir([e.signal,n]);return o.start=Date.now(),o.timeout=r,o}cleanUp(e){e.clear();let r=Date.now()-e.start;e.aborted?(this.failure.push(r),this.next.push(r*this.failureMultiplier),this.metric?.update({failureMovingAverage:this.failure.movingAverage,failureDeviation:this.failure.deviation,failureForecast:this.failure.forecast,failureVariance:this.failure.variance,failure:r})):(this.success.push(r),this.next.push(r),this.metric?.update({successMovingAverage:this.success.movingAverage,successDeviation:this.success.deviation,successForecast:this.success.forecast,successVariance:this.success.variance,success:r}))}};var B=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},pe=class extends Error{static name="ValidationError";name="ValidationError"},ar=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},cr=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};function In(t){return e=>Te(e,t)}function An(t){return e=>T(e,t)}function et(t){return new DataView(t.buffer).getUint16(t.byteOffset).toString()}function Pe(t){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,typeof t=="string"?parseInt(t):t),new Uint8Array(e)}function ts(t){let e=t.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==16)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion address.`);let r=T(e[0],"base32"),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=Pe(n);return we([r,o],r.length+o.length)}function rs(t){let e=t.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==56)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion3 address.`);let r=ae.decode(`b${e[0]}`),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=Pe(n);return we([r,o],r.length+o.length)}function Tn(t){let e=t.subarray(0,t.length-2),r=t.subarray(t.length-2),n=Te(e,"base32"),o=et(r);return`${n}:${o}`}var Dn=function(t){t=t.toString().trim();let e=new Uint8Array(4);return t.split(/\./g).forEach((r,n)=>{let o=parseInt(r,10);if(isNaN(o)||o<0||o>255)throw new B("Invalid byte value in IP address");e[n]=o}),e},ns=function(t){let e=0;t=t.toString().trim();let r=t.split(":",8),n;for(n=0;n<r.length;n++){let s=_e(r[n]),i;s&&(i=Dn(r[n]),r[n]=Te(i.subarray(0,2),"base16")),i!=null&&++n<8&&r.splice(n,0,Te(i.subarray(2,4),"base16"))}if(r[0]==="")for(;r.length<8;)r.unshift("0");else if(r[r.length-1]==="")for(;r.length<8;)r.push("0");else if(r.length<8){for(n=0;n<r.length&&r[n]!=="";n++);let s=[n,1];for(n=9-r.length;n>0;n--)s.push("0");r.splice.apply(r,s)}let o=new Uint8Array(e+16);for(n=0;n<r.length;n++){r[n]===""&&(r[n]="0");let s=parseInt(r[n],16);if(isNaN(s)||s<0||s>65535)throw new B("Invalid byte value in IP address");o[e++]=s>>8&255,o[e++]=s&255}return o},os=function(t){if(t.byteLength!==4)throw new B("IPv4 address was incorrect length");let e=[];for(let r=0;r<t.byteLength;r++)e.push(t[r]);return e.join(".")},ss=function(t){if(t.byteLength!==16)throw new B("IPv6 address was incorrect length");let e=[];for(let n=0;n<t.byteLength;n+=2){let o=t[n],s=t[n+1],i=`${o.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}`;e.push(i)}let r=e.join(":");try{let n=new URL(`http://[${r}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new B(`Invalid IPv6 address "${r}"`)}};function is(t){try{let e=new URL(`http://[${t}]`);return e.hostname.substring(1,e.hostname.length-1)}catch{throw new B(`Invalid IPv6 address "${t}"`)}}var Ln=Object.values(mt).map(t=>t.decoder),$c=(function(){let t=Ln[0].or(Ln[1]);return Ln.slice(2).forEach(e=>t=t.or(e)),t})();function as(t){return $c.decode(t)}function cs(t){return e=>t.encoder.encode(e)}function zc(t){if(parseInt(t).toString()!==t)throw new pe("Value must be an integer")}function Vc(t){if(t<0)throw new pe("Value must be a positive integer, or zero")}function jc(t){return e=>{if(e>t)throw new pe(`Value must be smaller than or equal to ${t}`)}}function qc(...t){return e=>{for(let r of t)r(e)}}var It=qc(zc,Vc,jc(65535));var U=-1,Fn=class{protocolsByCode=new Map;protocolsByName=new Map;getProtocol(e){let r;if(typeof e=="string"?r=this.protocolsByName.get(e):r=this.protocolsByCode.get(e),r==null)throw new cr(`Protocol ${e} was unknown`);return r}addProtocol(e){this.protocolsByCode.set(e.code,e),this.protocolsByName.set(e.name,e),e.aliases?.forEach(r=>{this.protocolsByName.set(r,e)})}removeProtocol(e){let r=this.protocolsByCode.get(e);r!=null&&(this.protocolsByCode.delete(r.code),this.protocolsByName.delete(r.name),r.aliases?.forEach(n=>{this.protocolsByName.delete(n)}))}},ge=new Fn,Au=[{code:4,name:"ip4",size:32,valueToBytes:Dn,bytesToValue:os,validate:t=>{if(!_e(t))throw new pe(`Invalid IPv4 address "${t}"`)}},{code:6,name:"tcp",size:16,valueToBytes:Pe,bytesToValue:et,validate:It},{code:273,name:"udp",size:16,valueToBytes:Pe,bytesToValue:et,validate:It},{code:33,name:"dccp",size:16,valueToBytes:Pe,bytesToValue:et,validate:It},{code:41,name:"ip6",size:128,valueToBytes:ns,bytesToValue:ss,stringToValue:is,validate:t=>{if(!Se(t))throw new pe(`Invalid IPv6 address "${t}"`)}},{code:42,name:"ip6zone",size:U},{code:43,name:"ipcidr",size:8,bytesToValue:In("base10"),valueToBytes:An("base10")},{code:53,name:"dns",size:U},{code:54,name:"dns4",size:U},{code:55,name:"dns6",size:U},{code:56,name:"dnsaddr",size:U},{code:132,name:"sctp",size:16,valueToBytes:Pe,bytesToValue:et,validate:It},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:U,stringToValue:t=>decodeURIComponent(t),valueToString:t=>encodeURIComponent(t)},{code:421,name:"p2p",aliases:["ipfs"],size:U,bytesToValue:In("base58btc"),valueToBytes:t=>t.startsWith("Q")||t.startsWith("1")?An("base58btc")(t):He.parse(t).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:Tn,valueToBytes:ts},{code:445,name:"onion3",size:296,bytesToValue:Tn,valueToBytes:rs},{code:446,name:"garlic64",size:U},{code:447,name:"garlic32",size:U},{code:448,name:"tls"},{code:449,name:"sni",size:U},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:U,bytesToValue:cs(Zr),valueToBytes:as},{code:480,name:"http"},{code:481,name:"http-path",size:U,stringToValue:t=>`/${decodeURIComponent(t)}`,valueToString:t=>encodeURIComponent(t.substring(1))},{code:443,name:"https"},{code:477,name:"ws"},{code:478,name:"wss"},{code:479,name:"p2p-websocket-star"},{code:277,name:"p2p-stardust"},{code:275,name:"p2p-webrtc-star"},{code:276,name:"p2p-webrtc-direct"},{code:280,name:"webrtc-direct"},{code:281,name:"webrtc"},{code:290,name:"p2p-circuit"},{code:777,name:"memory",size:U}];Au.forEach(t=>{ge.addProtocol(t)});function ds(t){let e=[],r=0;for(;r<t.length;){let n=me(t,r),o=ge.getProtocol(n),s=P(n),i=Tu(o,t,r+s),a=0;i>0&&o.size===U&&(a=P(i));let c=s+a+i,u={code:n,name:o.name,bytes:t.subarray(r,r+c)};if(i>0){let l=r+s+a,d=t.subarray(l,l+i);u.value=o.bytesToValue?.(d)??Te(d)}e.push(u),r+=c}return e}function hs(t){let e=0,r=[];for(let n of t){if(n.bytes==null){let o=ge.getProtocol(n.code),s=P(n.code),i,a=0,c=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??T(n.value),a=i.byteLength,o.size===U&&(c=P(a)));let u=new Uint8Array(s+c+a),l=0;Kt(n.code,u,l),l+=s,i!=null&&(o.size===U&&(Kt(a,u,l),l+=c),u.set(i,l)),n.bytes=u}r.push(n.bytes),e+=n.bytes.byteLength}return we(r,e)}function ms(t){if(t.charAt(0)!=="/")throw new B('String multiaddr must start with "/"');let e=[],r="protocol",n="",o="";for(let s=1;s<t.length;s++){let i=t.charAt(s);i!=="/"&&(r==="protocol"?o+=t.charAt(s):n+=t.charAt(s));let a=s===t.length-1;if(i==="/"||a){let c=ge.getProtocol(o);if(r==="protocol"){if(c.size==null||c.size===0){e.push({code:c.code,name:c.name}),n="",o="",r="protocol";continue}else if(a)throw new B(`Component ${o} was missing value`);r="value"}else if(r==="value"){let u={code:c.code,name:c.name};if(c.size!=null&&c.size!==0){if(n==="")throw new B(`Component ${o} was missing value`);u.value=c.stringToValue?.(n)??n}e.push(u),n="",o="",r="protocol"}}}if(o!==""&&n!=="")throw new B("Incomplete multiaddr");return e}function ps(t){return`/${t.flatMap(e=>{if(e.value==null)return e.name;let r=ge.getProtocol(e.code);if(r==null)throw new B(`Unknown protocol code ${e.code}`);return[e.name,r.valueToString?.(e.value)??e.value]}).join("/")}`}function Tu(t,e,r){return t.size==null||t.size===0?0:t.size>0?t.size/8:me(e,r)}var Du=Symbol.for("nodejs.util.inspect.custom"),Un=Symbol.for("@multiformats/multiaddr");function Fu(t){if(t==null&&(t="/"),gs(t))return t.getComponents();if(t instanceof Uint8Array)return ds(t);if(typeof t=="string")return t=t.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),t===""&&(t="/"),ms(t);if(Array.isArray(t))return t;throw new B("Must be a string, Uint8Array, Component[], or another Multiaddr")}var ur=class t{[Un]=!0;#e;#t;#r;constructor(e="/",r={}){this.#e=Fu(e),r.validate!==!1&&Uu(this)}get bytes(){return this.#r==null&&(this.#r=hs(this.#e)),this.#r}toString(){return this.#t==null&&(this.#t=ps(this.#e)),this.#t}toJSON(){return this.toString()}getComponents(){return[...this.#e.map(e=>({...e}))]}encapsulate(e){let r=new t(e);return new t([...this.#e,...r.getComponents()],{validate:!1})}decapsulate(e){let r=e.toString(),n=this.toString(),o=n.lastIndexOf(r);if(o<0)throw new ar(`Address ${this.toString()} does not contain subaddress: ${r}`);return new t(n.slice(0,o),{validate:!1})}decapsulateCode(e){let r;for(let n=this.#e.length-1;n>-1;n--)if(this.#e[n].code===e){r=n;break}return new t(this.#e.slice(0,r),{validate:!1})}equals(e){return Xe(this.bytes,e.bytes)}[Du](){return`Multiaddr(${this.toString()})`}};function Uu(t){t.getComponents().forEach(e=>{let r=ge.getProtocol(e.code);e.value!=null&&r.validate?.(e.value)})}function gs(t){return!!t?.[Un]}function Le(t){return new ur(t)}function ys(t,e,r){let n=[t.type,r??t.host];if(t.protocol!=null){let o=e??t.port;o!=null&&n.push(t.protocol,o)}return t.type==="ip6"&&t.zone!=null&&n.unshift("ip6zone",t.zone),t.cidr!=null&&n.push("ipcidr",t.cidr),Le(`/${n.join("/")}`)}function Nu(t,e){if(t==null)return[];let r=q(t);return[ys(r,e)]}function ku(t){return Se(t)?rr("2000::/3",t):!1}function Bu(t,e){if(typeof t!="string")throw new $(`invalid ip provided: ${t}`);if(typeof e=="string"&&(e=parseInt(e)),isNaN(e))throw new $(`invalid port provided: ${e}`);if(_e(t))return Le(`/ip4/${t}/tcp/${e}`);if(Se(t))return Le(`/ip6/${t}/tcp/${e}`);throw new $(`invalid ip:port for creating a multiaddr: ${t}:${e}`)}function Mu(t){return t==null||typeof t?.[Symbol.asyncIterator]!="function"?!1:typeof t.next=="function"}function Pu(t){return t==null||typeof t?.[Symbol.iterator]!="function"?!1:typeof t.next=="function"}var Nn=class{readNext;haveNext;ended;nextResult;error;constructor(){this.ended=!1,this.readNext=te(),this.haveNext=te()}[Symbol.asyncIterator](){return this}async next(){if(this.nextResult==null&&await this.haveNext.promise,this.nextResult==null)throw new Error("HaveNext promise resolved but nextResult was undefined");let e=this.nextResult;return this.nextResult=void 0,this.readNext.resolve(),this.readNext=te(),e}async throw(e){return this.ended=!0,this.error=e,e!=null&&(this.haveNext.promise.catch(()=>{}),this.haveNext.reject(e)),{done:!0,value:void 0}}async return(){let e={done:!0,value:void 0};return this.ended=!0,this.nextResult=e,this.haveNext.resolve(),e}async push(e,r){await this._push(e,r)}async end(e,r){e!=null?await this.throw(e):await this._push(void 0,r)}async _push(e,r){if(e!=null&&this.ended)throw this.error??new Error("Cannot push value onto an ended pushable");for(;this.nextResult!=null;)await this.readNext.promise;e!=null?this.nextResult={done:!1,value:e}:(this.ended=!0,this.nextResult={done:!0,value:void 0}),this.haveNext.resolve(),this.haveNext=te(),await F(this.readNext.promise,r?.signal,r)}};function bs(){return new Nn}function Ou(t){return t[Symbol.asyncIterator]!=null}async function Ru(t,e,r){try{await Promise.all(t.map(async n=>{for await(let o of n)await e.push(o,{signal:r}),r.throwIfAborted()})),await e.end(void 0,{signal:r})}catch(n){await e.end(n,{signal:r}).catch(()=>{})}}async function*$u(t){let e=new AbortController,r=bs();Ru(t,r,e.signal).catch(()=>{});try{yield*r}finally{e.abort()}}function*zu(t){for(let e of t)yield*e}function Vu(...t){let e=[];for(let r of t)Ou(r)||e.push(r);return e.length===t.length?zu(e):$u(t)}var xs=Vu;function ws(t,...e){if(t==null)throw new Error("Empty pipeline");if(kn(t)){let n=t;t=()=>n.source}else if(vs(t)||Es(t)){let n=t;t=()=>n}let r=[t,...e];if(r.length>1&&kn(r[r.length-1])&&(r[r.length-1]=r[r.length-1].sink),r.length>2)for(let n=1;n<r.length-1;n++)kn(r[n])&&(r[n]=qu(r[n]));return ju(...r)}var ju=(...t)=>{let e;for(;t.length>0;)e=t.shift()(e);return e},Es=t=>t?.[Symbol.asyncIterator]!=null,vs=t=>t?.[Symbol.iterator]!=null,kn=t=>t==null?!1:t.sink!=null&&t.source!=null,qu=t=>e=>{let r=t.sink(e);if(r?.then!=null){let n=ce({objectMode:!0});r.then(()=>{n.end()},i=>{n.end(i)});let o,s=t.source;if(Es(s))o=async function*(){yield*s,n.end()};else if(vs(s))o=function*(){yield*s,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return xs(n,o())}return t.source};var Wu=4194304,At=class extends Error{static name="UnwrappedError";name="UnwrappedError"},tt=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},fr=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},lr=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function Gu(t){return typeof t?.closeRead=="function"}function Hu(t){return typeof t?.close=="function"}function Bn(t){return Gu(t)?t.remoteWriteStatus!=="writable"&&t.readBufferLength===0:Hu(t)?t.status!=="open":!1}function Xu(t){return t?.addEventListener!=null&&t?.removeEventListener!=null&&t?.send!=null&&t?.push!=null&&t?.log!=null}function _s(t,e){let r=e?.maxBufferSize??Wu,n=new A,o,s=!1;if(!Xu(t))throw new $("Argument should be a Stream or a Multiaddr");let i=l=>{if(n.append(l.data),n.byteLength>r){let d=n.byteLength;n.consume(n.byteLength),o?.reject(new Error(`Read buffer overflow - ${d} > ${r}`))}o?.resolve()};t.addEventListener("message",i);let a=l=>{l.error!=null?o?.reject(l.error):o?.resolve()};t.addEventListener("close",a);let c=()=>{o?.resolve()};t.addEventListener("remoteCloseWrite",c);let u={readBuffer:n,async read(l){if(s===!0)throw new At("Stream was unwrapped");if(Bn(t)){if(n.byteLength===0&&l?.bytes==null)return null;if(l?.bytes!=null&&n.byteLength<l.bytes)throw t.log.error("closed after reading %d/%d bytes",n.byteLength,l.bytes),new Ce(`Unexpected EOF - stream closed after reading ${n.byteLength}/${l.bytes} bytes`)}let d=l?.bytes??1;for(o=Promise.withResolvers();;){if(n.byteLength>=d){o.resolve();break}if(await F(o.promise,l?.signal),Bn(t)){if(n.byteLength===0&&l?.bytes==null)return null;break}o=Promise.withResolvers()}let h=l?.bytes??n.byteLength;if(n.byteLength<h){if(Bn(t))throw t.log.error("closed while reading %d/%d bytes",n.byteLength,h),new Ce(`Unexpected EOF - stream closed while reading ${n.byteLength}/${h} bytes`);return u.read(l)}let g=n.sublist(0,h);return n.consume(h),g},async write(l,d){if(s===!0)throw new At("Stream was unwrapped");t.send(l)||await D(t,"drain",{signal:d?.signal,rejectionEvents:["close"]})},unwrap(){return s||(s=!0,t.removeEventListener("message",i),t.removeEventListener("close",a),t.removeEventListener("remoteCloseWrite",c),n.byteLength>0&&(t.log("stream unwrapped with %d unread bytes",n.byteLength),t.push(n))),t}};return u}function Ss(t,e={}){let r=_s(t,e);e.maxDataLength!=null&&e.maxLengthLength==null&&(e.maxLengthLength=P(e.maxDataLength));let n=e?.lengthDecoder??me,o=e?.lengthEncoder??Jt;return{async read(i){let a=-1,c=new A;for(;;){let l=await r.read({...i,bytes:1});if(l==null)break;c.append(l);try{a=n(c)}catch(d){if(d instanceof RangeError)continue;throw d}if(a<0)throw new tt("Invalid message length");if(e?.maxLengthLength!=null&&c.byteLength>e.maxLengthLength)throw new lr(`Message length length too long - ${c.byteLength} > ${e.maxLengthLength}`);if(a>-1)break}if(e?.maxDataLength!=null&&a>e.maxDataLength)throw new fr(`Message length too long - ${a} > ${e.maxDataLength}`);let u=await r.read({...i,bytes:a});if(u==null)throw t.log.error("tried to read %d bytes but the stream closed",a),new Ce(`Unexpected EOF - tried to read ${a} bytes but the stream closed`);if(u.byteLength!==a)throw t.log.error("read %d/%d bytes before the stream closed",u.byteLength,a),new Ce(`Unexpected EOF - read ${u.byteLength}/${a} bytes before the stream closed`);return u},async write(i,a){await r.write(new A(o(i.byteLength),i),a)},async writeV(i,a){let c=new A(...i.flatMap(u=>[o(u.byteLength),u]));await r.write(c,a)},unwrap(){return r.unwrap()}}}function Qu(t,e){let r=Ss(t,e),n={read:async(o,s)=>{let i=await r.read(s);return o.decode(i)},write:async(o,s,i)=>{await r.write(s.encode(o),i)},writeV:async(o,s,i)=>{await r.writeV(o.map(a=>s.encode(a)),i)},pb:o=>({read:async s=>n.read(o,s),write:async(s,i)=>n.write(s,o,i),writeV:async(s,i)=>n.writeV(s,o,i),unwrap:()=>n}),unwrap:()=>r.unwrap()};return n}async function Mn(t,e){let r=t.log.newScope("echo"),n=Date.now(),o=0;try{for await(let s of t)o+=s.byteLength,t.send(s)||(t.pause(),await D(t,"drain",{rejectionEvents:["close"],...e}),t.resume());r("echoed %d bytes in %dms",o,Date.now()-n),await t.close(e)}catch(s){t.abort(s)}}function Ku(t){return t?.addEventListener!=null}function Cs(t){let e=ce(),r,n=i=>{e.push(i.data)},o=()=>{e.end(),t.removeEventListener("message",n),t.removeEventListener("close",s),t.removeEventListener("remoteCloseWrite",o)},s=i=>{e.end(i.error),i.error!=null&&r?.reject(i.error),t.removeEventListener("message",n),t.removeEventListener("close",s),t.removeEventListener("remoteCloseWrite",o)};return t.addEventListener("message",n),t.addEventListener("close",s,{once:!0}),t.addEventListener("remoteCloseWrite",o,{once:!0}),{source:e,async sink(i){async function*a(){yield*i}let c=a();for(;;){r=Promise.withResolvers();let{done:u,value:l}=await Promise.race([c.next(),r.promise]);if(t.writeStatus==="closing"||t.writeStatus==="closed"||(l!=null&&(t.send(l)||await Promise.race([D(t,"drain",{rejectionEvents:["close"]})])),u===!0))break}await t.close()}}}function Ju(...t){let e=t.map(r=>Ku(r)?Cs(r):r);return ws(...e)}var Yu=1024*1024*4,Zu=1024*1024*4,Pn=class{buffer;maxBufferSize;lengthDecoder;maxDataLength;encodingLength;constructor(e={}){this.buffer=new A,this.maxBufferSize=e.maxBufferSize??Yu,this.maxDataLength=e.maxDataLength??Zu,this.lengthDecoder=e.lengthDecoder??me,this.encodingLength=e.encodingLength??P}*decode(e){if(this.buffer.append(e),this.buffer.byteLength>this.maxBufferSize)throw new $(`Buffer length limit exceeded - ${this.buffer.byteLength}/${this.maxBufferSize}`);for(;;){let r;try{r=this.lengthDecoder(this.buffer)}catch(s){if(s instanceof RangeError)break;throw s}if(r<0||r>this.maxDataLength)throw new tt("Invalid message length");let n=this.encodingLength(r),o=n+r;if(this.buffer.byteLength>=o){let s=this.buffer.sublist(n,o);this.buffer.consume(o),s.byteLength>0&&(yield s)}else break}}};function ef(t){return!!(t.startsWith("169.254.")||t.toLowerCase().startsWith("fe80"))}var tf=["Object","RegExp","Date","Error","Map","Set","WeakMap","WeakSet","ArrayBuffer","SharedArrayBuffer","DataView","Promise","URL","HTMLElement","Int8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array"];function On(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=rf(t);return r||"Object"}function rf(t){let e=Object.prototype.toString.call(t).slice(8,-1);if(tf.includes(e))return e}var f=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}};f.uint=new f(0,"uint",!0);f.negint=new f(1,"negint",!0);f.bytes=new f(2,"bytes",!0);f.string=new f(3,"string",!0);f.array=new f(4,"array",!1);f.map=new f(5,"map",!1);f.tag=new f(6,"tag",!1);f.float=new f(7,"float",!0);f.false=new f(7,"false",!0);f.true=new f(7,"true",!0);f.null=new f(7,"null",!0);f.undefined=new f(7,"undefined",!0);f.break=new f(7,"break",!0);var p=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 Tt=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",nf=new TextEncoder;function dr(t){return Tt&&globalThis.Buffer.isBuffer(t)}function Dt(t){return t instanceof Uint8Array?dr(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):t:Uint8Array.from(t)}var of=24,sf=200,hr=Tt?t=>t.length>=of?globalThis.Buffer.from(t):Ls(t):t=>t.length>=sf?nf.encode(t):Ls(t),ue=t=>Uint8Array.from(t),Is=Tt?(t,e,r)=>dr(t)?new Uint8Array(t.subarray(e,r)):t.slice(e,r):(t,e,r)=>t.slice(e,r),As=Tt?(t,e)=>(t=t.map(r=>r instanceof Uint8Array?r:globalThis.Buffer.from(r)),Dt(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},Ts=Tt?t=>globalThis.Buffer.allocUnsafe(t):t=>new Uint8Array(t);function mr(t,e){if(dr(t)&&dr(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 Ls(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 af=256,Ft=class{constructor(e=af){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)}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=Ts(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=Is(n,0,this.cursor)}else r=As(this.chunks,this.cursor);return e&&this.reset(),r}},pr=class{constructor(e){this.dest=e,this.cursor=0,this.chunks=[e]}reset(){this.cursor=0}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 y="CBOR decode error:",gr="CBOR encode error:",Ut=[];Ut[23]=1;Ut[24]=2;Ut[25]=3;Ut[26]=5;Ut[27]=9;function ye(t,e,r){if(t.length-e<r)throw new Error(`${y} not enough data for type`)}var N=[24,256,65536,4294967296,BigInt("18446744073709551616")];function W(t,e,r){ye(t,e,1);let n=t[e];if(r.strict===!0&&n<N[0])throw new Error(`${y} integer encoded in more bytes than necessary (strict decode)`);return n}function G(t,e,r){ye(t,e,2);let n=t[e]<<8|t[e+1];if(r.strict===!0&&n<N[1])throw new Error(`${y} integer encoded in more bytes than necessary (strict decode)`);return n}function H(t,e,r){ye(t,e,4);let n=t[e]*16777216+(t[e+1]<<16)+(t[e+2]<<8)+t[e+3];if(r.strict===!0&&n<N[2])throw new Error(`${y} integer encoded in more bytes than necessary (strict decode)`);return n}function X(t,e,r){ye(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],s=(BigInt(n)<<BigInt(32))+BigInt(o);if(r.strict===!0&&s<N[3])throw new Error(`${y} integer encoded in more bytes than necessary (strict decode)`);if(s<=Number.MAX_SAFE_INTEGER)return Number(s);if(r.allowBigInt===!0)return s;throw new Error(`${y} integers outside of the safe integer range are not supported`)}function Ds(t,e,r,n){return new p(f.uint,W(t,e+1,n),2)}function Fs(t,e,r,n){return new p(f.uint,G(t,e+1,n),3)}function Us(t,e,r,n){return new p(f.uint,H(t,e+1,n),5)}function Ns(t,e,r,n){return new p(f.uint,X(t,e+1,n),9)}function K(t,e){return S(t,0,e.value)}function S(t,e,r){if(r<N[0]){let n=Number(r);t.push([e|n])}else if(r<N[1]){let n=Number(r);t.push([e|24,n])}else if(r<N[2]){let n=Number(r);t.push([e|25,n>>>8,n&255])}else if(r<N[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<N[4]){let o=[e|27,0,0,0,0,0,0,0],s=Number(n&BigInt(4294967295)),i=Number(n>>BigInt(32)&BigInt(4294967295));o[8]=s&255,s=s>>8,o[7]=s&255,s=s>>8,o[6]=s&255,s=s>>8,o[5]=s&255,o[4]=i&255,i=i>>8,o[3]=i&255,i=i>>8,o[2]=i&255,i=i>>8,o[1]=i&255,t.push(o)}else throw new Error(`${y} encountered BigInt larger than allowable range`)}}K.encodedSize=function(e){return S.encodedSize(e.value)};S.encodedSize=function(e){return e<N[0]?1:e<N[1]?2:e<N[2]?3:e<N[3]?5:9};K.compareTokens=function(e,r){return e.value<r.value?-1:e.value>r.value?1:0};function ks(t,e,r,n){return new p(f.negint,-1-W(t,e+1,n),2)}function Bs(t,e,r,n){return new p(f.negint,-1-G(t,e+1,n),3)}function Ms(t,e,r,n){return new p(f.negint,-1-H(t,e+1,n),5)}var Rn=BigInt(-1),Ps=BigInt(1);function Os(t,e,r,n){let o=X(t,e+1,n);if(typeof o!="bigint"){let s=-1-o;if(s>=Number.MIN_SAFE_INTEGER)return new p(f.negint,s,9)}if(n.allowBigInt!==!0)throw new Error(`${y} integers outside of the safe integer range are not supported`);return new p(f.negint,Rn-BigInt(o),9)}function yr(t,e){let r=e.value,n=typeof r=="bigint"?r*Rn-Ps:r*-1-1;S(t,e.type.majorEncoded,n)}yr.encodedSize=function(e){let r=e.value,n=typeof r=="bigint"?r*Rn-Ps:r*-1-1;return n<N[0]?1:n<N[1]?2:n<N[2]?3:n<N[3]?5:9};yr.compareTokens=function(e,r){return e.value<r.value?1:e.value>r.value?-1:0};function Nt(t,e,r,n){ye(t,e,r+n);let o=t.slice(e+r,e+r+n);return new p(f.bytes,o,r+n)}function Rs(t,e,r,n){return Nt(t,e,1,r)}function $s(t,e,r,n){return Nt(t,e,2,W(t,e+1,n))}function zs(t,e,r,n){return Nt(t,e,3,G(t,e+1,n))}function Vs(t,e,r,n){return Nt(t,e,5,H(t,e+1,n))}function js(t,e,r,n){let o=X(t,e+1,n);if(typeof o=="bigint")throw new Error(`${y} 64-bit integer bytes lengths not supported`);return Nt(t,e,9,o)}function br(t){return t.encodedBytes===void 0&&(t.encodedBytes=f.equals(t.type,f.string)?hr(t.value):t.value),t.encodedBytes}function rt(t,e){let r=br(e);S(t,e.type.majorEncoded,r.length),t.push(r)}rt.encodedSize=function(e){let r=br(e);return S.encodedSize(r.length)+r.length};rt.compareTokens=function(e,r){return uf(br(e),br(r))};function uf(t,e){return t.length<e.length?-1:t.length>e.length?1:mr(t,e)}var qs=new TextDecoder,lf=32;function df(t,e,r){if(r-e<lf){let o="";for(let s=e;s<r;s++){let i=t[s];if(i&128)return qs.decode(t.subarray(e,r));o+=String.fromCharCode(i)}return o}return qs.decode(t.subarray(e,r))}function kt(t,e,r,n,o){let s=r+n;ye(t,e,s);let i=new p(f.string,df(t,e+r,e+s),s);return o.retainStringBytes===!0&&(i.byteValue=t.slice(e+r,e+s)),i}function Ws(t,e,r,n){return kt(t,e,1,r,n)}function Gs(t,e,r,n){return kt(t,e,2,W(t,e+1,n),n)}function Hs(t,e,r,n){return kt(t,e,3,G(t,e+1,n),n)}function Xs(t,e,r,n){return kt(t,e,5,H(t,e+1,n),n)}function Qs(t,e,r,n){let o=X(t,e+1,n);if(typeof o=="bigint")throw new Error(`${y} 64-bit integer string lengths not supported`);return kt(t,e,9,o,n)}var Ks=rt;function nt(t,e,r,n){return new p(f.array,n,r)}function Js(t,e,r,n){return nt(t,e,1,r)}function Ys(t,e,r,n){return nt(t,e,2,W(t,e+1,n))}function Zs(t,e,r,n){return nt(t,e,3,G(t,e+1,n))}function ei(t,e,r,n){return nt(t,e,5,H(t,e+1,n))}function ti(t,e,r,n){let o=X(t,e+1,n);if(typeof o=="bigint")throw new Error(`${y} 64-bit integer array lengths not supported`);return nt(t,e,9,o)}function ri(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${y} indefinite length items not allowed`);return nt(t,e,1,1/0)}function xr(t,e){S(t,f.array.majorEncoded,e.value)}xr.compareTokens=K.compareTokens;xr.encodedSize=function(e){return S.encodedSize(e.value)};function ot(t,e,r,n){return new p(f.map,n,r)}function ni(t,e,r,n){return ot(t,e,1,r)}function oi(t,e,r,n){return ot(t,e,2,W(t,e+1,n))}function si(t,e,r,n){return ot(t,e,3,G(t,e+1,n))}function ii(t,e,r,n){return ot(t,e,5,H(t,e+1,n))}function ai(t,e,r,n){let o=X(t,e+1,n);if(typeof o=="bigint")throw new Error(`${y} 64-bit integer map lengths not supported`);return ot(t,e,9,o)}function ci(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${y} indefinite length items not allowed`);return ot(t,e,1,1/0)}function wr(t,e){S(t,f.map.majorEncoded,e.value)}wr.compareTokens=K.compareTokens;wr.encodedSize=function(e){return S.encodedSize(e.value)};function ui(t,e,r,n){return new p(f.tag,r,1)}function fi(t,e,r,n){return new p(f.tag,W(t,e+1,n),2)}function li(t,e,r,n){return new p(f.tag,G(t,e+1,n),3)}function di(t,e,r,n){return new p(f.tag,H(t,e+1,n),5)}function hi(t,e,r,n){return new p(f.tag,X(t,e+1,n),9)}function Er(t,e){S(t,f.tag.majorEncoded,e.value)}Er.compareTokens=K.compareTokens;Er.encodedSize=function(e){return S.encodedSize(e.value)};var $n=20,zn=21,Vn=22,jn=23;function mi(t,e,r,n){if(n.allowUndefined===!1)throw new Error(`${y} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new p(f.null,null,1):new p(f.undefined,void 0,1)}function pi(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${y} indefinite length items not allowed`);return new p(f.break,void 0,1)}function qn(t,e,r){if(r){if(r.allowNaN===!1&&Number.isNaN(t))throw new Error(`${y} NaN values are not supported`);if(r.allowInfinity===!1&&(t===1/0||t===-1/0))throw new Error(`${y} Infinity values are not supported`)}return new p(f.float,t,e)}function gi(t,e,r,n){return qn(Wn(t,e+1),3,n)}function yi(t,e,r,n){return qn(Gn(t,e+1),5,n)}function bi(t,e,r,n){return qn(vi(t,e+1),9,n)}function Bt(t,e,r){let n=e.value;if(n===!1)t.push([f.float.majorEncoded|$n]);else if(n===!0)t.push([f.float.majorEncoded|zn]);else if(n===null)t.push([f.float.majorEncoded|Vn]);else if(n===void 0)t.push([f.float.majorEncoded|jn]);else{let o,s=!1;(!r||r.float64!==!0)&&(wi(n),o=Wn(ne,1),n===o||Number.isNaN(n)?(ne[0]=249,t.push(ne.slice(0,3)),s=!0):(Ei(n),o=Gn(ne,1),n===o&&(ne[0]=250,t.push(ne.slice(0,5)),s=!0))),s||(yf(n),o=vi(ne,1),ne[0]=251,t.push(ne.slice(0,9)))}}Bt.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){wi(n);let o=Wn(ne,1);if(n===o||Number.isNaN(n))return 3;if(Ei(n),o=Gn(ne,1),n===o)return 5}return 9};var xi=new ArrayBuffer(9),J=new DataView(xi,1),ne=new Uint8Array(xi,0);function wi(t){if(t===1/0)J.setUint16(0,31744,!1);else if(t===-1/0)J.setUint16(0,64512,!1);else if(Number.isNaN(t))J.setUint16(0,32256,!1);else{J.setFloat32(0,t);let e=J.getUint32(0),r=(e&2139095040)>>23,n=e&8388607;if(r===255)J.setUint16(0,31744,!1);else if(r===0)J.setUint16(0,(t&2147483648)>>16|n>>13,!1);else{let o=r-127;o<-24?J.setUint16(0,0):o<-14?J.setUint16(0,(e&2147483648)>>16|1<<24+o,!1):J.setUint16(0,(e&2147483648)>>16|o+15<<10|n>>13,!1)}}}function Wn(t,e){if(t.length-e<2)throw new Error(`${y} 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,s;return n===0?s=o*2**-24:n!==31?s=(o+1024)*2**(n-25):s=o===0?1/0:NaN,r&32768?-s:s}function Ei(t){J.setFloat32(0,t,!1)}function Gn(t,e){if(t.length-e<4)throw new Error(`${y} not enough data for float32`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,4).getFloat32(0,!1)}function yf(t){J.setFloat64(0,t,!1)}function vi(t,e){if(t.length-e<8)throw new Error(`${y} not enough data for float64`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,8).getFloat64(0,!1)}Bt.compareTokens=K.compareTokens;function E(t,e,r){throw new Error(`${y} encountered invalid minor (${r}) for major ${t[e]>>>5}`)}function vr(t){return()=>{throw new Error(`${y} ${t}`)}}var m=[];for(let t=0;t<=23;t++)m[t]=E;m[24]=Ds;m[25]=Fs;m[26]=Us;m[27]=Ns;m[28]=E;m[29]=E;m[30]=E;m[31]=E;for(let t=32;t<=55;t++)m[t]=E;m[56]=ks;m[57]=Bs;m[58]=Ms;m[59]=Os;m[60]=E;m[61]=E;m[62]=E;m[63]=E;for(let t=64;t<=87;t++)m[t]=Rs;m[88]=$s;m[89]=zs;m[90]=Vs;m[91]=js;m[92]=E;m[93]=E;m[94]=E;m[95]=vr("indefinite length bytes/strings are not supported");for(let t=96;t<=119;t++)m[t]=Ws;m[120]=Gs;m[121]=Hs;m[122]=Xs;m[123]=Qs;m[124]=E;m[125]=E;m[126]=E;m[127]=vr("indefinite length bytes/strings are not supported");for(let t=128;t<=151;t++)m[t]=Js;m[152]=Ys;m[153]=Zs;m[154]=ei;m[155]=ti;m[156]=E;m[157]=E;m[158]=E;m[159]=ri;for(let t=160;t<=183;t++)m[t]=ni;m[184]=oi;m[185]=si;m[186]=ii;m[187]=ai;m[188]=E;m[189]=E;m[190]=E;m[191]=ci;for(let t=192;t<=215;t++)m[t]=ui;m[216]=fi;m[217]=li;m[218]=di;m[219]=hi;m[220]=E;m[221]=E;m[222]=E;m[223]=E;for(let t=224;t<=243;t++)m[t]=vr("simple values are not supported");m[244]=E;m[245]=E;m[246]=E;m[247]=mi;m[248]=vr("simple values are not supported");m[249]=gi;m[250]=yi;m[251]=bi;m[252]=E;m[253]=E;m[254]=E;m[255]=pi;var oe=[];for(let t=0;t<24;t++)oe[t]=new p(f.uint,t,1);for(let t=-1;t>=-24;t--)oe[31-t]=new p(f.negint,t,1);oe[64]=new p(f.bytes,new Uint8Array(0),1);oe[96]=new p(f.string,"",1);oe[128]=new p(f.array,0,1);oe[160]=new p(f.map,0,1);oe[244]=new p(f.false,!1,1);oe[245]=new p(f.true,!0,1);oe[246]=new p(f.null,null,1);function Hn(t){switch(t.type){case f.false:return ue([244]);case f.true:return ue([245]);case f.null:return ue([246]);case f.bytes:return t.value.length?void 0:ue([64]);case f.string:return t.value===""?ue([96]):void 0;case f.array:return t.value===0?ue([128]):void 0;case f.map:return t.value===0?ue([160]):void 0;case f.uint:return t.value<24?ue([Number(t.value)]):void 0;case f.negint:if(t.value>=-24)return ue([31-Number(t.value)])}}var xf={float64:!1,mapSorter:vf,quickEncodeToken:Hn},Ii=Object.freeze({float64:!0,mapSorter:_f,quickEncodeToken:Hn});function wf(){let t=[];return t[f.uint.major]=K,t[f.negint.major]=yr,t[f.bytes.major]=rt,t[f.string.major]=Ks,t[f.array.major]=xr,t[f.map.major]=wr,t[f.tag.major]=Er,t[f.float.major]=Bt,t}var st=wf(),_r=new Ft,Pt=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(`${gr} object contains circular references`);return new t(r,e)}},Ie={null:new p(f.null,null),undefined:new p(f.undefined,void 0),true:new p(f.true,!0),false:new p(f.false,!1),emptyArray:new p(f.array,0),emptyMap:new p(f.map,0)},fe={number(t,e,r,n){return!Number.isInteger(t)||!Number.isSafeInteger(t)?new p(f.float,t):t>=0?new p(f.uint,t):new p(f.negint,t)},bigint(t,e,r,n){return t>=BigInt(0)?new p(f.uint,t):new p(f.negint,t)},Uint8Array(t,e,r,n){return new p(f.bytes,t)},string(t,e,r,n){return new p(f.string,t)},boolean(t,e,r,n){return t?Ie.true:Ie.false},null(t,e,r,n){return Ie.null},undefined(t,e,r,n){return Ie.undefined},ArrayBuffer(t,e,r,n){return new p(f.bytes,new Uint8Array(t))},DataView(t,e,r,n){return new p(f.bytes,new Uint8Array(t.buffer,t.byteOffset,t.byteLength))},Array(t,e,r,n){if(!t.length)return r.addBreakTokens===!0?[Ie.emptyArray,new p(f.break)]:Ie.emptyArray;n=Pt.createCheck(n,t);let o=[],s=0;for(let i of t)o[s++]=Sr(i,r,n);return r.addBreakTokens?[new p(f.array,t.length),o,new p(f.break)]:[new p(f.array,t.length),o]},Object(t,e,r,n){let o=e!=="Object",s=o?t.keys():Object.keys(t),i=o?t.size:s.length,a;if(i){a=new Array(i),n=Pt.createCheck(n,t);let c=!o&&r.ignoreUndefinedProperties,u=0;for(let l of s){let d=o?t.get(l):t[l];c&&d===void 0||(a[u++]=[Sr(l,r,n),Sr(d,r,n)])}u<i&&(a.length=u)}return a?.length?(Ef(a,r),r.addBreakTokens?[new p(f.map,a.length),a,new p(f.break)]:[new p(f.map,a.length),a]):r.addBreakTokens===!0?[Ie.emptyMap,new p(f.break)]:Ie.emptyMap}};fe.Map=fe.Object;fe.Buffer=fe.Uint8Array;for(let t of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))fe[`${t}Array`]=fe.DataView;function Sr(t,e={},r){let n=On(t),o=e&&e.typeEncoders&&e.typeEncoders[n]||fe[n];if(typeof o=="function"){let i=o(t,n,e,r);if(i!=null)return i}let s=fe[n];if(!s)throw new Error(`${gr} unsupported type: ${n}`);return s(t,n,e,r)}function Ef(t,e){e.mapSorter&&t.sort(e.mapSorter)}function vf(t,e){let r=Array.isArray(t[0])?t[0][0]:t[0],n=Array.isArray(e[0])?e[0][0]:e[0];if(r.type!==n.type)return r.type.compare(n.type);let o=r.type.major,s=st[o].compareTokens(r,n);return s===0&&console.warn("WARNING: complex key types used, CBOR key sorting guarantees are gone"),s}function _f(t,e){if(t[0]instanceof p&&e[0]instanceof p){let r=t[0],n=e[0];return r._keyBytes||(r._keyBytes=_i(r.value)),n._keyBytes||(n._keyBytes=_i(n.value)),mr(r._keyBytes,n._keyBytes)}throw new Error("rfc8949MapSorter: complex key types are not supported yet")}function _i(t){return Ti(t,st,Ii)}function Mt(t,e,r,n){if(Array.isArray(e))for(let o of e)Mt(t,o,r,n);else r[e.type.major](t,e,n)}var Si=f.uint.majorEncoded,Ci=f.negint.majorEncoded,Sf=f.bytes.majorEncoded,Cf=f.string.majorEncoded,Li=f.array.majorEncoded,Lf=f.float.majorEncoded|$n,If=f.float.majorEncoded|zn,Af=f.float.majorEncoded|Vn,Tf=f.float.majorEncoded|jn,Df=BigInt(-1),Ff=BigInt(1);function Uf(t){return t.addBreakTokens!==!0}function Ai(t,e,r,n){let o=On(e),s=r.typeEncoders&&r.typeEncoders[o];if(s){let i=s(e,o,r,n);if(i!=null){Mt(t,i,st,r);return}}switch(o){case"null":t.push([Af]);return;case"undefined":t.push([Tf]);return;case"boolean":t.push([e?If:Lf]);return;case"number":!Number.isInteger(e)||!Number.isSafeInteger(e)?Bt(t,new p(f.float,e),r):e>=0?S(t,Si,e):S(t,Ci,e*-1-1);return;case"bigint":e>=BigInt(0)?S(t,Si,e):S(t,Ci,e*Df-Ff);return;case"string":{let i=hr(e);S(t,Cf,i.length),t.push(i);return}case"Uint8Array":S(t,Sf,e.length),t.push(e);return;case"Array":if(!e.length){t.push([Li]);return}n=Pt.createCheck(n,e),S(t,Li,e.length);for(let i of e)Ai(t,i,r,n);return;case"Object":case"Map":{let i=fe.Object(e,o,r,n);Mt(t,i,st,r)}return;default:{let i=fe[o];if(!i)throw new Error(`${gr} unsupported type: ${o}`);let a=i(e,o,r,n);Mt(t,a,st,r)}}}function Ti(t,e,r,n){let o=n instanceof Uint8Array,s=o?new pr(n):_r,i=Sr(t,r);if(!Array.isArray(i)&&r.quickEncodeToken){let a=r.quickEncodeToken(i);if(a)return o?(s.push(a),s.toBytes()):a;let c=e[i.type.major];if(c.encodedSize){let u=c.encodedSize(i,r);if(o||(s=new Ft(u)),c(s,i,r),s.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${i} was wrong`);return o?s.toBytes():Dt(s.chunks[0])}}return s.reset(),Mt(s,i,e,r),s.toBytes(!0)}function Xn(t,e){return e=Object.assign({},xf,e),Uf(e)?(_r.reset(),Ai(_r,t,e,void 0),_r.toBytes(!0)):Ti(t,st,e)}var Nf={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},Cr=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=oe[e];if(r===void 0){let n=m[e];if(!n)throw new Error(`${y} 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}},Ot=Symbol.for("DONE"),Lr=Symbol.for("BREAK");function kf(t,e,r){let n=[];for(let o=0;o<t.value;o++){let s=it(e,r);if(s===Lr){if(t.value===1/0)break;throw new Error(`${y} got unexpected break to lengthed array`)}if(s===Ot)throw new Error(`${y} found array but not enough entries (got ${o}, expected ${t.value})`);n[o]=s}return n}function Bf(t,e,r){let n=r.useMaps===!0,o=r.rejectDuplicateMapKeys===!0,s=n?void 0:{},i=n?new Map:void 0;for(let a=0;a<t.value;a++){let c=it(e,r);if(c===Lr){if(t.value===1/0)break;throw new Error(`${y} got unexpected break to lengthed map`)}if(c===Ot)throw new Error(`${y} found map but not enough entries (got ${a} [no key], expected ${t.value})`);if(!n&&typeof c!="string")throw new Error(`${y} non-string keys not supported (got ${typeof c})`);if(o&&(n&&i.has(c)||!n&&Object.hasOwn(s,c)))throw new Error(`${y} found repeat map key "${c}"`);let u=it(e,r);if(u===Ot)throw new Error(`${y} found map but not enough entries (got ${a} [no value], expected ${t.value})`);n?i.set(c,u):s[c]=u}return n?i:s}function it(t,e){if(t.done())return Ot;let r=t.next();if(f.equals(r.type,f.break))return Lr;if(r.type.terminal)return r.value;if(f.equals(r.type,f.array))return kf(r,t,e);if(f.equals(r.type,f.map))return Bf(r,t,e);if(f.equals(r.type,f.tag)){if(e.tags&&typeof e.tags[r.value]=="function"){let n=it(t,e);return e.tags[r.value](n)}throw new Error(`${y} tag not supported (${r.value})`)}throw new Error("unsupported")}function Di(t,e){if(!(t instanceof Uint8Array))throw new Error(`${y} data to decode must be a Uint8Array`);e=Object.assign({},Nf,e);let r=Dt(t),n=e.tokenizer||new Cr(r,e),o=it(n,e);if(o===Ot)throw new Error(`${y} did not find any content to decode`);if(o===Lr)throw new Error(`${y} got unexpected break`);return[o,t.subarray(n.pos())]}function Qn(t,e){let[r,n]=Di(t,e);if(n.length>0)throw new Error(`${y} too many terminals, data makes no sense`);return r}var Ir=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},at=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},Ar=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"},Rt=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};function Tr(t){return t[Symbol.asyncIterator]!=null}function Fi(t,e){if(t.byteLength>e)throw new at("Message length too long")}var Fr=t=>{let e=P(t),r=Z(e);return Jt(t,r),Fr.bytes=e,r};Fr.bytes=0;function Ur(t,e){e=e??{};let r=e.lengthEncoder??Fr,n=e?.maxDataLength??4194304;function*o(s){Fi(s,n);let i=r(s.byteLength);i instanceof Uint8Array?yield i:yield*i,s instanceof Uint8Array?yield s:yield*s}return Tr(t)?(async function*(){for await(let s of t)yield*o(s)})():(function*(){for(let s of t)yield*o(s)})()}Ur.single=(t,e)=>{e=e??{};let r=e.lengthEncoder??Fr,n=e?.maxDataLength??4194304;return Fi(t,n),new A(r(t.byteLength),t)};var Re;(function(t){t[t.LENGTH=0]="LENGTH",t[t.DATA=1]="DATA"})(Re||(Re={}));var Kn=t=>{let e=me(t);return Kn.bytes=P(e),e};Kn.bytes=0;function $t(t,e){let r=new A,n=Re.LENGTH,o=-1,s=e?.lengthDecoder??Kn,i=e?.maxLengthLength??8,a=e?.maxDataLength??4194304;function*c(){for(;r.byteLength>0;){if(n===Re.LENGTH)try{if(o=s(r),o<0)throw new Ir("Invalid message length");if(o>a)throw new at("Message length too long");let u=s.bytes;r.consume(u),e?.onLength!=null&&e.onLength(o),n=Re.DATA}catch(u){if(u instanceof RangeError){if(r.byteLength>i)throw new Ar("Message length length too long");break}throw u}if(n===Re.DATA){if(r.byteLength<o)break;let u=r.sublist(0,o);r.consume(o),e?.onData!=null&&e.onData(u),yield u,n=Re.LENGTH}}}return Tr(t)?(async function*(){for await(let u of t)r.append(u),yield*c();if(r.byteLength>0)throw new Rt("Unexpected end of input")})():(function*(){for(let u of t)r.append(u),yield*c();if(r.byteLength>0)throw new Rt("Unexpected end of input")})()}$t.fromReader=(t,e)=>{let r=1,n=(async function*(){for(;;)try{let{done:s,value:i}=await t.next(r);if(s===!0)return;i!=null&&(yield i)}catch(s){if(s.code==="ERR_UNDER_READ")return{done:!0,value:null};throw s}finally{r=1}})();return $t(n,{...e??{},onLength:s=>{r=s}})};var Jn=class extends Be{sendMessage;dataQueue;encoding;constructor(e){super(e),this.sendMessage=e.sendMessage,this.encoding=e.encoding,this.dataQueue=new re({concurrency:1}),this.direction==="outbound"&&this.sendMessage({id:this.id,type:"create",protocol:this.protocol})}sendData(e){let r=this.sendMessage({id:this.id,type:"data",chunk:e.subarray()});return{sentBytes:e.byteLength,canSendMore:r}}sendReset(){this.sendMessage({id:this.id,type:"reset"})}async sendCloseWrite(e){this.sendMessage({id:this.id,type:"closeWrite"}),e?.signal?.throwIfAborted()}async sendCloseRead(e){this.sendMessage({id:this.id,type:"closeRead"}),e?.signal?.throwIfAborted()}sendPause(){this.sendMessage({id:this.id,type:"pause"})}sendResume(){this.sendMessage({id:this.id,type:"resume"})}onRemotePaused(){this.dataQueue.pause()}onRemoteResumed(){this.dataQueue.resume()}},Ui=30,Yn=class extends Lt{input;maxInputQueueSize;encoding;maxMessageSize;nextStreamId;constructor(e,r){super(e,{...r,protocol:"/mock-muxer/1.0.0",name:"mock-muxer"}),this.maxInputQueueSize=r.maxInputQueueSize??1024*1024*10,this.maxMessageSize=(r.maxMessageSize??1024*1024*4)+Ui,this.encoding=r.encoding??"base64",this.input=ce(),this.sendMessage=this.sendMessage.bind(this),this.nextStreamId=this.maConn.direction==="outbound"?0:1,Promise.resolve().then(async()=>{for await(let n of $t(this.input,{maxDataLength:this.maxMessageSize}))this.onMessage(Qn(n.subarray()))}).catch(n=>{this.abort(n)})}onData(e){if(this.input.readableLength>=this.maxInputQueueSize){this.abort(new Error(`Input queue exceeded maximum size ${this.input.readableLength} >= ${this.maxInputQueueSize}`));return}this.input.push(e)}sendMessage(e){e.type==="data"?this.log.trace("send message %o",{...e,chunk:`[ ${e.chunk.byteLength} bytes ]`}):this.log.trace("send message %o",e);let r=Xn(e),n=Ur.single(r,{maxDataLength:this.maxMessageSize});return this.send(n)}onMessage(e){e.type==="data"?this.log.trace("incoming message %o",{...e,chunk:`[ ${e.chunk.byteLength} bytes ]`}):this.log.trace("incoming message %o",e);let r=this.streams.find(n=>n.id===e.id);if(e.type==="create"){if(r!=null)throw new Error(`Already had stream for ${e.id}`);this.log.trace("create stream inbound %s",e.id),r=this._createStream(e.id,"inbound",{protocol:e.protocol}),this.onRemoteStream(r)}if(r==null){this.log.error(`no stream found for ${e.id}`);return}e.type==="data"?r.onData(e.chunk):e.type==="reset"?r.onRemoteReset():e.type==="closeWrite"?r.onRemoteCloseWrite():e.type==="closeRead"?r.onRemoteCloseRead():e.type==="pause"?r.onRemotePaused():e.type==="resume"&&r.onRemoteResumed()}async onCreateStream(e){return this.nextStreamId+=2,this._createStream(`${this.nextStreamId}`,"outbound",e)}_createStream(e,r,n){return this.log.trace("createStream %s %s",r,e),new Jn({...this.streamOptions,...n,id:e,direction:r,log:this.log.newScope(`stream:${r}:${e}`),sendMessage:this.sendMessage,encoding:this.encoding,maxMessageSize:this.maxMessageSize-Ui,protocol:""})}},Zn=class{protocol="/mock-muxer/1.0.0";init;constructor(e){this.init=e}createStreamMuxer(e){return new Yn(e,{...this.init})}};function Nr(t={}){return new Zn(t)}function Rf(t,e){if(typeof t=="string")return $f(t);if(typeof t=="number")return jf(t,e);throw Error(`Value provided to ms() must be a string or number. value=${JSON.stringify(t)}`)}var kr=Rf;function $f(t){if(typeof t!="string"||t.length===0||t.length>100)throw 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),s=n.toLowerCase();switch(s){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 Error(`Unknown unit "${s}" provided to ms.parse(). value=${JSON.stringify(t)}`)}}function zf(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 Vf(t){let e=Math.abs(t);return e>=315576e5?$e(t,e,315576e5,"year"):e>=26298e5?$e(t,e,26298e5,"month"):e>=6048e5?$e(t,e,6048e5,"week"):e>=864e5?$e(t,e,864e5,"day"):e>=36e5?$e(t,e,36e5,"hour"):e>=6e4?$e(t,e,6e4,"minute"):e>=1e3?$e(t,e,1e3,"second"):`${t} ms`}function jf(t,e){if(typeof t!="number"||!Number.isFinite(t))throw Error("Value provided to ms.format() must be of type number.");return e?.long?Vf(t):zf(t)}function $e(t,e,r,n){let o=e>=r*1.5;return`${Math.round(t/r)} ${n}${o?"s":""}`}function eo(t){r.debug=r,r.default=r,r.coerce=c,r.disable=s,r.enable=o,r.enabled=i,r.humanize=kr,r.destroy=u,Object.keys(t).forEach(l=>{r[l]=t[l]}),r.names=[],r.skips=[],r.formatters={};function e(l){let d=0;for(let h=0;h<l.length;h++)d=(d<<5)-d+l.charCodeAt(h),d|=0;return r.colors[Math.abs(d)%r.colors.length]}r.selectColor=e;function r(l,d){let h,g=null,x,v;function b(...w){if(!b.enabled)return;let C=b,L=Number(new Date),O=L-(h||L);C.diff=O,C.prev=h,C.curr=L,h=L,w[0]=r.coerce(w[0]),typeof w[0]!="string"&&w.unshift("%O");let k=0;w[0]=w[0].replace(/%([a-zA-Z%])/g,(R,Y)=>{if(R==="%%")return"%";k++;let Ae=r.formatters[Y];if(typeof Ae=="function"){let ji=w[k];R=Ae.call(C,ji),w.splice(k,1),k--}return R}),r.formatArgs.call(C,w),d?.onLog!=null&&d.onLog(...w),(C.log||r.log).apply(C,w)}return b.namespace=l,b.useColors=r.useColors(),b.color=r.selectColor(l),b.extend=n,b.destroy=r.destroy,Object.defineProperty(b,"enabled",{enumerable:!0,configurable:!1,get:()=>g!==null?g:(x!==r.namespaces&&(x=r.namespaces,v=r.enabled(l)),v),set:w=>{g=w}}),typeof r.init=="function"&&r.init(b),b}function n(l,d){let h=r(this.namespace+(typeof d>"u"?":":d)+l);return h.log=this.log,h}function o(l){r.save(l),r.namespaces=l,r.names=[],r.skips=[];let d,h=(typeof l=="string"?l:"").split(/[\s,]+/),g=h.length;for(d=0;d<g;d++)h[d]&&(l=h[d].replace(/\*/g,".*?"),l[0]==="-"?r.skips.push(new RegExp("^"+l.substr(1)+"$")):r.names.push(new RegExp("^"+l+"$")))}function s(){let l=[...r.names.map(a),...r.skips.map(a).map(d=>"-"+d)].join(",");return r.enable(""),l}function i(l){if(l[l.length-1]==="*")return!0;let d,h;for(d=0,h=r.skips.length;d<h;d++)if(r.skips[d].test(l))return!1;for(d=0,h=r.names.length;d<h;d++)if(r.names[d].test(l))return!0;return!1}function a(l){return l.toString().substring(2,l.toString().length-2).replace(/\.\*\?$/,"*")}function c(l){return l instanceof Error?l.stack??l.message:l}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 Br=Kf(),qf=["#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 Wf(){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 Gf(t){if(t[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+t[0]+(this.useColors?"%c ":" ")+"+"+kr(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 Hf=console.debug??console.log??(()=>{});function Xf(t){try{t?Br?.setItem("debug",t):Br?.removeItem("debug")}catch{}}function Qf(){let t;try{t=Br?.getItem("debug")}catch{}return!t&&typeof globalThis.process<"u"&&"env"in globalThis.process&&(t=globalThis.process.env.DEBUG),t}function Kf(){try{return localStorage}catch{}}function Jf(t){t.j=function(e){try{return JSON.stringify(e)}catch(r){return"[UnexpectedJSONParseError]: "+r.message}}}var Ni=eo({formatArgs:Gf,save:Xf,load:Qf,useColors:Wf,setupFormatters:Jf,colors:qf,storage:Br,log:Hf});var z=Ni;z.formatters.b=t=>t==null?"undefined":Q.baseEncode(t);z.formatters.t=t=>t==null?"undefined":ae.baseEncode(t);z.formatters.m=t=>t==null?"undefined":Yr.baseEncode(t);z.formatters.p=t=>t==null?"undefined":t.toString();z.formatters.c=t=>t==null?"undefined":t.toString();z.formatters.k=t=>t==null?"undefined":t.toString();z.formatters.a=t=>t==null?"undefined":t.toString();function ki(t,e=""){let r=Bi(t.message),n=Bi(t.stack);return r!=null&&n!=null?n.includes(r)?`${n.split(`
3
3
  `).join(`
4
4
  ${e}`)}`:`${r}
5
5
  ${e}${n.split(`