@libp2p/utils 6.7.2-da78fa851 → 6.7.2-f0afebfdf
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 +2 -2
- package/dist/index.min.js.map +4 -4
- package/dist/src/index.d.ts +0 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +0 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/queue/index.d.ts +0 -6
- package/dist/src/queue/index.d.ts.map +1 -1
- package/dist/src/queue/index.js.map +1 -1
- package/package.json +7 -9
- package/src/index.ts +0 -1
- package/src/queue/index.ts +0 -7
- package/dist/src/socket-writer.browser.d.ts +0 -2
- package/dist/src/socket-writer.browser.d.ts.map +0 -1
- package/dist/src/socket-writer.browser.js +0 -4
- package/dist/src/socket-writer.browser.js.map +0 -1
- package/dist/src/socket-writer.d.ts +0 -19
- package/dist/src/socket-writer.d.ts.map +0 -1
- package/dist/src/socket-writer.js +0 -43
- package/dist/src/socket-writer.js.map +0 -1
- package/src/socket-writer.browser.ts +0 -3
- package/src/socket-writer.ts +0 -64
package/dist/index.min.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
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 zs=Object.create;var Vt=Object.defineProperty;var Vs=Object.getOwnPropertyDescriptor;var qs=Object.getOwnPropertyNames;var js=Object.getPrototypeOf,Ws=Object.prototype.hasOwnProperty;var Gs=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),V=(t,e)=>{for(var r in e)Vt(t,r,{get:e[r],enumerable:!0})},io=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of qs(e))!Ws.call(t,o)&&o!==r&&Vt(t,o,{get:()=>e[o],enumerable:!(n=Vs(e,o))||n.enumerable});return t};var Hs=(t,e,r)=>(r=t!=null?zs(js(t)):{},io(e||!t||!t.__esModule?Vt(r,"default",{value:t,enumerable:!0}):r,t)),Ks=t=>io(Vt({},"__esModule",{value:!0}),t);var jo=Gs(Ct=>{(function(){var t,e,r,n,o,i,s,a;a=function(f){var c,u,d,h;return c=(f&255<<24)>>>24,u=(f&255<<16)>>>16,d=(f&65280)>>>8,h=f&255,[c,u,d,h].join(".")},s=function(f){var c,u,d,h,g,b;for(c=[],d=h=0;h<=3&&f.length!==0;d=++h){if(d>0){if(f[0]!==".")throw new Error("Invalid IP");f=f.substring(1)}b=e(f),g=b[0],u=b[1],f=f.substring(u),c.push(g)}if(f.length!==0)throw new Error("Invalid IP");switch(c.length){case 1:if(c[0]>4294967295)throw new Error("Invalid IP");return c[0]>>>0;case 2:if(c[0]>255||c[1]>16777215)throw new Error("Invalid IP");return(c[0]<<24|c[1])>>>0;case 3:if(c[0]>255||c[1]>255||c[2]>65535)throw new Error("Invalid IP");return(c[0]<<24|c[1]<<16|c[2])>>>0;case 4:if(c[0]>255||c[1]>255||c[2]>255||c[3]>255)throw new Error("Invalid IP");return(c[0]<<24|c[1]<<16|c[2]<<8|c[3])>>>0;default:throw new Error("Invalid IP")}},r=function(f){return f.charCodeAt(0)},n=r("0"),i=r("a"),o=r("A"),e=function(f){var c,u,d,h,g;for(h=0,c=10,u="9",d=0,f.length>1&&f[d]==="0"&&(f[d+1]==="x"||f[d+1]==="X"?(d+=2,c=16):"0"<=f[d+1]&&f[d+1]<="9"&&(d++,c=8,u="7")),g=d;d<f.length;){if("0"<=f[d]&&f[d]<=u)h=h*c+(r(f[d])-n)>>>0;else if(c===16)if("a"<=f[d]&&f[d]<="f")h=h*c+(10+r(f[d])-i)>>>0;else if("A"<=f[d]&&f[d]<="F")h=h*c+(10+r(f[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 f(c,u){var d,h,g,b;if(typeof c!="string")throw new Error("Missing `net' parameter");if(u||(b=c.split("/",2),c=b[0],u=b[1]),u||(u=32),typeof u=="string"&&u.indexOf(".")>-1){try{this.maskLong=s(u)}catch(w){throw d=w,new Error("Invalid mask: "+u)}for(h=g=32;g>=0;h=--g)if(this.maskLong===4294967295<<32-h>>>0){this.bitmask=h;break}}else if(u||u===0)this.bitmask=parseInt(u,10),this.maskLong=0,this.bitmask>0&&(this.maskLong=4294967295<<32-this.bitmask>>>0);else throw new Error("Invalid mask: empty");try{this.netLong=(s(c)&this.maskLong)>>>0}catch(w){throw d=w,new Error("Invalid net address: "+c)}if(!(this.bitmask<=32))throw new Error("Invalid mask for ip4: "+u);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 f.prototype.contains=function(c){return typeof c=="string"&&(c.indexOf("/")>0||c.split(".").length!==4)&&(c=new f(c)),c instanceof f?this.contains(c.base)&&this.contains(c.broadcast||c.last):(s(c)&this.maskLong)>>>0===(this.netLong&this.maskLong)>>>0},f.prototype.next=function(c){return c==null&&(c=1),new f(a(this.netLong+this.size*c),this.mask)},f.prototype.forEach=function(c){var u,d,h;for(h=s(this.first),d=s(this.last),u=0;h<=d;)c(a(h),h,u),u++,h++},f.prototype.toString=function(){return this.base+"/"+this.bitmask},f})(),Ct.ip2long=s,Ct.long2ip=a,Ct.Netmask=t}).call(Ct)});var cl={};V(cl,{AbstractMessageStream:()=>Be,AbstractMultiaddrConnection:()=>Tt,AbstractStream:()=>Pe,AbstractStreamMuxer:()=>Dt,AdaptiveTimeout:()=>Sn,BloomFilter:()=>Et,CuckooFilter:()=>we,DEFAULT_FAILURE_MULTIPLIER:()=>Qo,DEFAULT_INTERVAL:()=>Zo,DEFAULT_MAX_TIMEOUT:()=>Jo,DEFAULT_MIN_TIMEOUT:()=>Xo,DEFAULT_TIMEOUT_MULTIPLIER:()=>Ko,InvalidDataLengthError:()=>fr,InvalidDataLengthLengthError:()=>lr,InvalidMessageLengthError:()=>rt,LengthPrefixedDecoder:()=>Nn,MaxEarlyStreamsError:()=>At,MemoryStorage:()=>Pr,MockStream:()=>Zn,MovingAverage:()=>Ne,PeerQueue:()=>to,PriorityQueue:()=>ro,Queue:()=>ne,QueueFullError:()=>It,RateLimitError:()=>Lt,RateLimiter:()=>no,ScalableCuckooFilter:()=>vt,UnexpectedEOFError:()=>_e,UnwrappedError:()=>kt,byteStream:()=>vi,createBloomFilter:()=>Bo,createCuckooFilter:()=>Po,createScalableCuckooFilter:()=>No,debounce:()=>et,echo:()=>Pn,echoStream:()=>ol,getNetConfig:()=>j,getThinWaistAddresses:()=>Du,ipPortToMultiaddr:()=>ku,isAsyncGenerator:()=>Uu,isGenerator:()=>Bu,isGlobalUnicast:()=>bc,isGlobalUnicastIp:()=>Fu,isLinkLocal:()=>wc,isLinkLocalIp:()=>Ju,isLoopback:()=>Ec,isNetworkAddress:()=>vc,isPrivate:()=>Dc,isPrivateIp:()=>xn,isPromise:()=>_n,lpStream:()=>_i,mergeOptions:()=>nf,messageStreamToDuplex:()=>Si,mockMuxer:()=>Fr,multiaddrConnectionPair:()=>eo,pbStream:()=>Gu,pipe:()=>Ku,repeatingTask:()=>nl,socketWriter:()=>il,streamPair:()=>$s,trackedList:()=>sl,trackedMap:()=>al});var le=class extends Error{static name="AbortError";constructor(e="The operation was aborted"){super(e),this.name="AbortError"}};var M=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"}};var jt=class extends Error{static name="StreamResetError";constructor(e="The stream has been reset"){super(e),this.name="StreamResetError"}};var Ie=class extends Error{static name="StreamStateError";constructor(e="The stream is in an invalid state"){super(e),this.name="StreamStateError"}},ht=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}},Ve=class extends Event{error;local;constructor(e,r,n){super("close",n),this.error=r,this.local=e}},Wt=class extends Ve{constructor(e,r){super(!0,e,r)}},Gt=class extends Ve{constructor(e,r){super(!1,e,r)}};var ae=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:i})=>i!==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 $r={};V($r,{base58btc:()=>J,base58flickr:()=>ta});var hl=new Uint8Array(0);function so(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 de(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 ao(t){return new TextEncoder().encode(t)}function co(t){return new TextDecoder().decode(t)}function Qs(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 i=t.charAt(o),s=i.charCodeAt(0);if(r[s]!==255)throw new TypeError(i+" is ambiguous");r[s]=o}var a=t.length,f=t.charAt(0),c=Math.log(a)/Math.log(256),u=Math.log(256)/Math.log(a);function d(b){if(b instanceof Uint8Array||(ArrayBuffer.isView(b)?b=new Uint8Array(b.buffer,b.byteOffset,b.byteLength):Array.isArray(b)&&(b=Uint8Array.from(b))),!(b instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(b.length===0)return"";for(var w=0,y=0,_=0,L=b.length;_!==L&&b[_]===0;)_++,w++;for(var I=(L-_)*u+1>>>0,A=new Uint8Array(I);_!==L;){for(var $=b[_],Q=0,z=I-1;($!==0||Q<y)&&z!==-1;z--,Q++)$+=256*A[z]>>>0,A[z]=$%a>>>0,$=$/a>>>0;if($!==0)throw new Error("Non-zero carry");y=Q,_++}for(var X=I-y;X!==I&&A[X]===0;)X++;for(var ze=f.repeat(w);X<I;++X)ze+=t.charAt(A[X]);return ze}function h(b){if(typeof b!="string")throw new TypeError("Expected String");if(b.length===0)return new Uint8Array;var w=0;if(b[w]!==" "){for(var y=0,_=0;b[w]===f;)y++,w++;for(var L=(b.length-w)*c+1>>>0,I=new Uint8Array(L);b[w];){var A=r[b.charCodeAt(w)];if(A===255)return;for(var $=0,Q=L-1;(A!==0||$<_)&&Q!==-1;Q--,$++)A+=a*I[Q]>>>0,I[Q]=A%256>>>0,A=A/256>>>0;if(A!==0)throw new Error("Non-zero carry");_=$,w++}if(b[w]!==" "){for(var z=L-_;z!==L&&I[z]===0;)z++;for(var X=new Uint8Array(y+(L-z)),ze=y;z!==L;)X[ze++]=I[z++];return X}}}function g(b){var w=h(b);if(w)return w;throw new Error(`Non-${e} character`)}return{encode:d,decodeUnsafe:h,decode:g}}var Xs=Qs,Js=Xs,fo=Js;var Nr=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")}},Mr=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 lo(this,e)}},Or=class{decoders;constructor(e){this.decoders=e}or(e){return lo(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 lo(t,e){return new Or({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var Rr=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 Nr(e,r,n),this.decoder=new Mr(e,r,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function qe({name:t,prefix:e,encode:r,decode:n}){return new Rr(t,e,r,n)}function ye({name:t,prefix:e,alphabet:r}){let{encode:n,decode:o}=fo(r,t);return qe({prefix:e,name:t,encode:n,decode:i=>de(o(i))})}function Zs(t,e,r,n){let o=t.length;for(;t[o-1]==="=";)--o;let i=new Uint8Array(o*r/8|0),s=0,a=0,f=0;for(let c=0;c<o;++c){let u=e[t[c]];if(u===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|u,s+=r,s>=8&&(s-=8,i[f++]=255&a>>s)}if(s>=r||(255&a<<8-s)!==0)throw new SyntaxError("Unexpected end of data");return i}function Ys(t,e,r){let n=e[e.length-1]==="=",o=(1<<r)-1,i="",s=0,a=0;for(let f=0;f<t.length;++f)for(a=a<<8|t[f],s+=8;s>r;)s-=r,i+=e[o&a>>s];if(s!==0&&(i+=e[o&a<<r-s]),n)for(;(i.length*r&7)!==0;)i+="=";return i}function ea(t){let e={};for(let r=0;r<t.length;++r)e[t[r]]=r;return e}function S({name:t,prefix:e,bitsPerChar:r,alphabet:n}){let o=ea(n);return qe({prefix:e,name:t,encode(i){return Ys(i,n,r)},decode(i){return Zs(i,o,r,t)}})}var J=ye({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),ta=ye({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var zr={};V(zr,{base32:()=>ce,base32hex:()=>ia,base32hexpad:()=>aa,base32hexpadupper:()=>ca,base32hexupper:()=>sa,base32pad:()=>na,base32padupper:()=>oa,base32upper:()=>ra,base32z:()=>ua});var ce=S({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),ra=S({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),na=S({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),oa=S({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),ia=S({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),sa=S({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),aa=S({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),ca=S({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),ua=S({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Vr={};V(Vr,{base36:()=>pt,base36upper:()=>fa});var pt=ye({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),fa=ye({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var la=mo,ho=128,da=127,ha=~da,pa=Math.pow(2,31);function mo(t,e,r){e=e||[],r=r||0;for(var n=r;t>=pa;)e[r++]=t&255|ho,t/=128;for(;t&ha;)e[r++]=t&255|ho,t>>>=7;return e[r]=t|0,mo.bytes=r-n+1,e}var ma=qr,ga=128,po=127;function qr(t,n){var r=0,n=n||0,o=0,i=n,s,a=t.length;do{if(i>=a)throw qr.bytes=0,new RangeError("Could not decode varint");s=t[i++],r+=o<28?(s&po)<<o:(s&po)*Math.pow(2,o),o+=7}while(s>=ga);return qr.bytes=i-n,r}var ya=Math.pow(2,7),xa=Math.pow(2,14),ba=Math.pow(2,21),wa=Math.pow(2,28),Ea=Math.pow(2,35),va=Math.pow(2,42),_a=Math.pow(2,49),Sa=Math.pow(2,56),Ca=Math.pow(2,63),La=function(t){return t<ya?1:t<xa?2:t<ba?3:t<wa?4:t<Ea?5:t<va?6:t<_a?7:t<Sa?8:t<Ca?9:10},Ia={encode:la,decode:ma,encodingLength:La},Aa=Ia,mt=Aa;function gt(t,e=0){return[mt.decode(t,e),mt.decode.bytes]}function je(t,e,r=0){return mt.encode(t,e,r),e}function We(t){return mt.encodingLength(t)}function He(t,e){let r=e.byteLength,n=We(t),o=n+We(r),i=new Uint8Array(o+r);return je(t,i,0),je(r,i,n),i.set(e,o),new Ge(t,r,e,i)}function go(t){let e=de(t),[r,n]=gt(e),[o,i]=gt(e.subarray(n)),s=e.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new Ge(r,o,s,e)}function yo(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&so(t.bytes,r.bytes)}}var Ge=class{code;size;digest;bytes;constructor(e,r,n,o){this.code=e,this.size=r,this.digest=n,this.bytes=o}};function xo(t,e){let{bytes:r,version:n}=t;switch(n){case 0:return Da(r,jr(t),e??J.encoder);default:return Fa(r,jr(t),e??ce.encoder)}}var bo=new WeakMap;function jr(t){let e=bo.get(t);if(e==null){let r=new Map;return bo.set(t,r),r}return e}var Ke=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!==xt)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==ka)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=He(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&&yo(e.multihash,n.multihash)}toString(e){return xo(this,e)}toJSON(){return{"/":xo(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let r=e;if(r instanceof t)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:i,bytes:s}=r;return new t(n,o,i,s??wo(n,o,i.bytes))}else if(r[Ua]===!0){let{version:n,multihash:o,code:i}=r,s=go(o);return t.create(n,i,s)}else return null}static create(e,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(r!==xt)throw new Error(`Version 0 CID must use dag-pb (code: ${xt}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let o=wo(e,r,n.bytes);return new t(e,r,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,xt,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=de(e.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let i=o.subarray(r.multihashSize-r.digestSize),s=new Ge(r.multihashCode,r.digestSize,i,o);return[r.version===0?t.createV0(s):t.createV1(r.codec,s),e.subarray(r.size)]}static inspectBytes(e){let r=0,n=()=>{let[d,h]=gt(e.subarray(r));return r+=h,d},o=n(),i=xt;if(o===18?(o=0,r=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let s=r,a=n(),f=n(),c=r+f,u=c-s;return{version:o,codec:i,multihashCode:a,digestSize:f,multihashSize:u,size:c}}static parse(e,r){let[n,o]=Ta(e,r),i=t.decode(o);if(i.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return jr(i).set(n,e),i}};function Ta(t,e){switch(t[0]){case"Q":{let r=e??J;return[J.prefix,r.decode(`${J.prefix}${t}`)]}case J.prefix:{let r=e??J;return[J.prefix,r.decode(t)]}case ce.prefix:{let r=e??ce;return[ce.prefix,r.decode(t)]}case pt.prefix:{let r=e??pt;return[pt.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 Da(t,e,r){let{prefix:n}=r;if(n!==J.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=e.get(n);if(o==null){let i=r.encode(t).slice(1);return e.set(n,i),i}else return o}function Fa(t,e,r){let{prefix:n}=r,o=e.get(n);if(o==null){let i=r.encode(t);return e.set(n,i),i}else return o}var xt=112,ka=18;function wo(t,e,r){let n=We(t),o=n+We(e),i=new Uint8Array(o+r.byteLength);return je(t,i,0),je(e,i,n),i.set(r,o),i}var Ua=Symbol.for("@ipld/js-cid/CID");var Wr={};V(Wr,{identity:()=>Na});var Eo=0,Ba="identity",vo=de;function Pa(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 He(Eo,vo(t))}var Na={code:Eo,name:Ba,encode:vo,digest:Pa};function Qe(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 q(t=0){return new Uint8Array(t)}function ee(t=0){return new Uint8Array(t)}function xe(t,e){e==null&&(e=t.reduce((o,i)=>o+i.length,0));let r=ee(e),n=0;for(let o of t)r.set(o,n),n+=o.length;return r}var So=Symbol.for("@achingbrain/uint8arraylist");function _o(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 Xe(t){return!!t?.[So]}var C=class t{bufs;length;[So]=!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(Xe(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(Xe(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=_o(this.bufs,e);return r.buf[r.index]}set(e,r){let n=_o(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(Xe(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 xe(n,o)}subarray(e,r){let{bufs:n,length:o}=this._subList(e,r);return n.length===1?n[0]:xe(n,o)}sublist(e,r){let{bufs:n,length:o}=this._subList(e,r),i=new t;return i.length=o,i.bufs=[...n],i}_subList(e,r){if(e=e??0,r=r??this.length,e<0&&(e=this.length+e),r<0&&(r=this.length+r),e<0||r>this.length)throw new RangeError("index is out of bounds");if(e===r)return{bufs:[],length:0};if(e===0&&r===this.length)return{bufs:this.bufs,length:this.length};let n=[],o=0;for(let i=0;i<this.bufs.length;i++){let s=this.bufs[i],a=o,f=a+s.byteLength;if(o=f,e>=f)continue;let c=e>=a&&e<f,u=r>a&&r<=f;if(c&&u){if(e===a&&r===f){n.push(s);break}let d=e-a;n.push(s.subarray(d,d+(r-e)));break}if(c){if(e===0){n.push(s);continue}n.push(s.subarray(e-a));continue}if(u){if(r===f){n.push(s);break}n.push(s.subarray(0,r-a));break}n.push(s)}return{bufs:n,length:r-e}}indexOf(e,r=0){if(!Xe(e)&&!(e instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=e instanceof Uint8Array?e:e.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),e.length===0)return r>this.length?this.length:r;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let i=256,s=new Int32Array(i);for(let d=0;d<i;d++)s[d]=-1;for(let d=0;d<o;d++)s[n[d]]=d;let a=s,f=this.byteLength-n.byteLength,c=n.byteLength-1,u;for(let d=r;d<=f;d+=u){u=0;for(let h=c;h>=0;h--){let g=this.get(d+h);if(n[h]!==g){u=Math.max(1,h-a[g]);break}}if(u===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=ee(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=q(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=q(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=q(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=ee(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=q(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=q(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=q(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=q(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=q(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(!Qe(this.bufs[r],e.bufs[r]))return!1;return!0}static fromUint8Arrays(e,r){let n=new t;return n.bufs=e,r==null&&(r=e.reduce((o,i)=>o+i.byteLength,0)),n.length=r,n}};var Gr={};V(Gr,{base10:()=>Ma});var Ma=ye({prefix:"9",name:"base10",alphabet:"0123456789"});var Hr={};V(Hr,{base16:()=>Oa,base16upper:()=>Ra});var Oa=S({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Ra=S({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Kr={};V(Kr,{base2:()=>$a});var $a=S({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Qr={};V(Qr,{base256emoji:()=>Wa});var Co=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}"),za=Co.reduce((t,e,r)=>(t[r]=e,t),[]),Va=Co.reduce((t,e,r)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return t[n]=r,t},[]);function qa(t){return t.reduce((e,r)=>(e+=za[r],e),"")}function ja(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=Va[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(o)}return new Uint8Array(e)}var Wa=qe({prefix:"\u{1F680}",name:"base256emoji",encode:qa,decode:ja});var Zr={};V(Zr,{base64:()=>Xr,base64pad:()=>Ga,base64url:()=>Jr,base64urlpad:()=>Ha});var Xr=S({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Ga=S({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Jr=S({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Ha=S({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Yr={};V(Yr,{base8:()=>Ka});var Ka=S({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var en={};V(en,{identity:()=>Qa});var Qa=qe({prefix:"\0",name:"identity",encode:t=>co(t),decode:t=>ao(t)});var Xl=new TextEncoder,Jl=new TextDecoder;var nn={};V(nn,{sha256:()=>Ya,sha512:()=>ec});var Za=20;function rn({name:t,code:e,encode:r,minDigestLength:n,maxDigestLength:o}){return new tn(t,e,r,n,o)}var tn=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,r,n,o,i){this.name=e,this.code=r,this.encode=n,this.minDigestLength=o??Za,this.maxDigestLength=i}digest(e,r){if(r?.truncate!=null){if(r.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&r.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(e instanceof Uint8Array){let n=this.encode(e);return n instanceof Uint8Array?Lo(n,this.code,r?.truncate):n.then(o=>Lo(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function Lo(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 He(e,t)}function Ao(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}var Ya=rn({name:"sha2-256",code:18,encode:Ao("SHA-256")}),ec=rn({name:"sha2-512",code:19,encode:Ao("SHA-512")});var bt={...en,...Kr,...Yr,...Gr,...Hr,...zr,...Vr,...$r,...Zr,...Qr},ud={...nn,...Wr};function Do(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var To=Do("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),on=Do("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=ee(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),tc={utf8:To,"utf-8":To,hex:bt.base16,latin1:on,ascii:on,binary:on,...bt},Kt=tc;function T(t,e="utf8"){let r=Kt[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}function Ae(t,e="utf8"){let r=Kt[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.encoder.encode(t).substring(1)}var Te=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function Fo(t=32){if(Te&&typeof Te.getRandomValues=="function")return Te.getRandomValues(new Uint8Array(t));if(Te&&typeof Te.randomBytes=="function")return Uint8Array.from(Te.randomBytes(t));throw new Error("crypto.getRandomValues must be defined")}var rc=Math.pow(2,7),nc=Math.pow(2,14),oc=Math.pow(2,21),sn=Math.pow(2,28),an=Math.pow(2,35),cn=Math.pow(2,42),un=Math.pow(2,49),v=128,P=127;function N(t){if(t<rc)return 1;if(t<nc)return 2;if(t<oc)return 3;if(t<sn)return 4;if(t<an)return 5;if(t<cn)return 6;if(t<un)return 7;if(Number.MAX_SAFE_INTEGER!=null&&t>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Qt(t,e,r=0){switch(N(t)){case 8:e[r++]=t&255|v,t/=128;case 7:e[r++]=t&255|v,t/=128;case 6:e[r++]=t&255|v,t/=128;case 5:e[r++]=t&255|v,t/=128;case 4:e[r++]=t&255|v,t>>>=7;case 3:e[r++]=t&255|v,t>>>=7;case 2:e[r++]=t&255|v,t>>>=7;case 1:{e[r++]=t&255,t>>>=7;break}default:throw new Error("unreachable")}return e}function ic(t,e,r=0){switch(N(t)){case 8:e.set(r++,t&255|v),t/=128;case 7:e.set(r++,t&255|v),t/=128;case 6:e.set(r++,t&255|v),t/=128;case 5:e.set(r++,t&255|v),t/=128;case 4:e.set(r++,t&255|v),t>>>=7;case 3:e.set(r++,t&255|v),t>>>=7;case 2:e.set(r++,t&255|v),t>>>=7;case 1:{e.set(r++,t&255),t>>>=7;break}default:throw new Error("unreachable")}return e}function sc(t,e){let r=t[e],n=0;if(n+=r&P,r<v||(r=t[e+1],n+=(r&P)<<7,r<v)||(r=t[e+2],n+=(r&P)<<14,r<v)||(r=t[e+3],n+=(r&P)<<21,r<v)||(r=t[e+4],n+=(r&P)*sn,r<v)||(r=t[e+5],n+=(r&P)*an,r<v)||(r=t[e+6],n+=(r&P)*cn,r<v)||(r=t[e+7],n+=(r&P)*un,r<v))return n;throw new RangeError("Could not decode varint")}function ac(t,e){let r=t.get(e),n=0;if(n+=r&P,r<v||(r=t.get(e+1),n+=(r&P)<<7,r<v)||(r=t.get(e+2),n+=(r&P)<<14,r<v)||(r=t.get(e+3),n+=(r&P)<<21,r<v)||(r=t.get(e+4),n+=(r&P)*sn,r<v)||(r=t.get(e+5),n+=(r&P)*an,r<v)||(r=t.get(e+6),n+=(r&P)*cn,r<v)||(r=t.get(e+7),n+=(r&P)*un,r<v))return n;throw new RangeError("Could not decode varint")}function Xt(t,e,r=0){return e==null&&(e=ee(N(t))),e instanceof Uint8Array?Qt(t,e,r):ic(t,e,r)}function he(t,e=0){return t instanceof Uint8Array?sc(t,e):ac(t,e)}function Jt(t){if(isNaN(t)||t<=0)throw new M("random bytes length must be a Number bigger than 0");return Fo(t)}var fn={32:16777619n,64:1099511628211n,128:309485009821345068724781371n,256:374144419156711147060143317175368453031918731002211n,512:35835915874844867368919076489095108449946327955754392558399825615420669938882575126094039892345713852759n,1024:5016456510113118655434598811035278955030765345404790744303017523831112055108147451509157692220295382716162651878526895249385292291816524375083746691371804094271873160484737966720260389217684476157468082573n},ko={32:2166136261n,64:14695981039346656037n,128:144066263297769815596495629667062367629n,256:100029257958052580907070968620625704837092796014241193945225284501741471925557n,512:9659303129496669498009435400716310466090418745672637896108374329434462657994582932197716438449813051892206539805784495328239340083876191928701583869517785n,1024:14197795064947621068722070641403218320880622795441933960878474914617582723252296732303717722150864096521202355549365628174669108571814760471015076148029755969804077320157692458563003215304957150157403644460363550505412711285966361610267868082893823963790439336411086884584107735010676915n},Uo=new globalThis.TextEncoder;function cc(t,e){let r=fn[e],n=ko[e];for(let o=0;o<t.length;o++)n^=BigInt(t[o]),n=BigInt.asUintN(e,n*r);return n}function uc(t,e,r){if(r.length===0)throw new Error("The `utf8Buffer` option must have a length greater than zero");let n=fn[e],o=ko[e],i=t;for(;i.length>0;){let s=Uo.encodeInto(i,r);i=i.slice(s.read);for(let a=0;a<s.written;a++)o^=BigInt(r[a]),o=BigInt.asUintN(e,o*n)}return o}function ln(t,{size:e=32,utf8Buffer:r}={}){if(!fn[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 uc(t,e,r);t=Uo.encode(t)}return cc(t,e)}var be={hash:t=>Number(ln(t,{size:32})),hashV:(t,e)=>fc(be.hash(t,e))};function fc(t){let e=t.toString(16);return e.length%2===1&&(e=`0${e}`),T(e,"base16")}var lc=Math.LN2*Math.LN2,Et=class{seeds;bits;buffer;constructor(e={}){e.seeds!=null?this.seeds=e.seeds:this.seeds=hc(e.hashes??8),this.bits=e.bits??1024,this.buffer=q(Math.ceil(this.bits/8))}add(e){typeof e=="string"&&(e=T(e));for(let r=0;r<this.seeds.length;r++){let o=be.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=be.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 Bo(t,e=.005){let r=dc(t,e);return new Et(r)}function dc(t,e=.005){let r=Math.round(-1*t*Math.log(e)/lc),n=Math.round(r/t*Math.LN2);return{bits:r,hashes:n}}function hc(t){let e,r,n=[];for(let o=0;o<t;o++)for(e=new C(Jt(4)),n[o]=e.getUint32(0,!0),r=0;r<o;r++)if(n[o]===n[r]){o--;break}return n}var dn=64,te=class{fp;h;seed;constructor(e,r,n,o=2){if(o>dn)throw new TypeError("Invalid Fingerprint Size");let i=r.hashV(e,n),s=q(o);for(let a=0;a<s.length;a++)s[a]=i[a];s.length===0&&(s[0]=7),this.fp=s,this.h=r,this.seed=n}hash(){return this.h.hash(this.fp,this.seed)}equals(e){return e?.fp instanceof Uint8Array?Qe(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 te))throw new TypeError("Invalid Fingerprint");return this.contents.some(r=>e.equals(r))}add(e){if(!(e instanceof te))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 te))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 te))throw new TypeError("Invalid Fingerprint");let r=this.contents.findIndex(n=>e.equals(n));return r>-1?(this.contents[r]=null,!0):!1}};var pc=500,we=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??be,this.seed=e.seed??De(0,Math.pow(2,10))}add(e){typeof e=="string"&&(e=T(e));let r=new te(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 i=[n,o],s=i[De(0,i.length-1)];this.buckets[s]==null&&(this.buckets[s]=new Fe(this.bucketSize));for(let a=0;a<pc;a++){let f=this.buckets[s].swap(r);if(f!=null&&(s=(s^f.hash())%this.filterSize,this.buckets[s]==null&&(this.buckets[s]=new Fe(this.bucketSize)),this.buckets[s].add(f)))return this.count++,!0}return!1}has(e){typeof e=="string"&&(e=T(e));let r=new te(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 i=(n^r.hash())%this.filterSize;return this.buckets[i]?.has(r)??!1}remove(e){typeof e=="string"&&(e=T(e));let r=new te(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 i=(n^r.hash())%this.filterSize,s=this.buckets[i]?.remove(r)??!1;return s&&this.count--,s}get reliable(){return Math.floor(100*(this.count/this.filterSize))<=90}},mc={1:.5,2:.84,4:.95,8:.98};function gc(t=.001){return t>.002?2:t>1e-5?4:8}function hn(t,e=.001){let r=gc(e),n=mc[r],o=Math.round(t/n),i=Math.min(Math.ceil(Math.log2(1/e)+Math.log2(2*r)),dn);return{filterSize:o,bucketSize:r,fingerprintSize:i}}function Po(t,e=.005){let r=hn(t,e);return new we(r)}var vt=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??be,this.seed=e.seed??De(0,Math.pow(2,10)),this.filterSeries=[new we({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 we({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 No(t,e=.001,r){return new vt({...hn(t,e),...r??{}})}function j(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 M(`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 i=0,s=0,a=this.peekChar();if(a===void 0)return;let f=a==="0",c=2**(8*o)-1;for(;;){let u=this.readAtomically(()=>{let d=this.readChar();if(d===void 0)return;let h=Number.parseInt(d,e);if(!Number.isNaN(h))return h});if(u===void 0)break;if(i*=e,i+=u,i>c||(s+=1,r!==void 0&&s>r))return}if(s!==0)return!n&&f&&s>1?void 0:i})}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 s=this.readSeparator(":",n,()=>this.readIPv4Addr());if(s!==void 0)return r[o]=s[0],r[o+1]=s[1],r[o+2]=s[2],r[o+3]=s[3],[o+4,!0]}let i=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(i===void 0)return[o,!1];r[o]=i>>8,r[o+1]=i&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 i=new Uint8Array(14),s=16-(n+2),[a]=e(i.subarray(0,s));return r.set(i.subarray(0,a),16-a),r})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var Mo=45,yc=15,Je=new Zt;function Yt(t){if(!(t.length>yc))return Je.new(t).parseWith(()=>Je.readIPv4Addr())}function er(t){if(t.includes("%")&&(t=t.split("%")[0]),!(t.length>Mo))return Je.new(t).parseWith(()=>Je.readIPv6Addr())}function Ze(t,e=!1){if(t.includes("%")&&(t=t.split("%")[0]),t.length>Mo)return;let r=Je.new(t).parseWith(()=>Je.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 Oo(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 Ro(t,e,r,n){let o=0;for(let i of t)if(!(o<r)){if(o>n)break;if(i!==e[o])return!1;o++}return!0}function pn(t){switch(t.length){case ke:return t.join(".");case Ue:{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 $o(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 zo(t){let e="0x";for(let r of t)e+=(r>>4).toString(16)+(r&15).toString(16);return e}var ke=4,Ue=16,ph=parseInt("0xFFFF",16),xc=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function _t(t,e){e.length===Ue&&t.length===ke&&Oo(e,0,11)&&(e=e.slice(12)),e.length===ke&&t.length===Ue&&Ro(t,xc,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 Vo(t,e){if(typeof e=="string"&&(e=Ze(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 mn(t){let[e,r]=t.split("/");if(!e||!r)throw new Error("Failed to parse given CIDR: "+t);let n=ke,o=Yt(e);if(o==null&&(n=Ue,o=er(e),o==null))throw new Error("Failed to parse given CIDR: "+t);let i=parseInt(r,10);if(Number.isNaN(i)||String(i).length!==r.length||i<0||i>n*8)throw new Error("Failed to parse given CIDR: "+t);let s=gn(i,8*n);return{network:_t(o,s),mask:s}}function gn(t,e){if(e!==8*ke&&e!==8*Ue)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 St=class{constructor(e,r){if(r==null)({network:this.network,mask:this.mask}=mn(e));else{let n=Ze(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 i=Ze(r);if(i==null)throw new Error("Failed to parse mask");this.mask=i}else this.mask=gn(o,8*n.length);this.network=_t(n,this.mask)}}contains(e){return Vo({network:this.network,mask:this.mask},e)}toString(){let e=$o(this.mask),r=e!==-1?String(e):zo(this.mask);return pn(this.network)+"/"+r}};function tr(t,e){return new St(t).contains(e)}function bc(t){try{let e=j(t);switch(e.type){case"ip6":return tr("2000::/3",e.host);default:return!1}}catch{return!1}}function wc(t){try{let e=j(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 qo(t){return/^127\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/i.test(t)||/^::1$/.test(t)}function Ec(t){try{let e=j(t);switch(e.type){case"ip4":case"ip6":return qo(e.host);default:return!1}}catch{return!1}}function vc(t){try{return j(t),!0}catch{return!1}}function Ee(t){return!!Yt(t)}function ve(t){return!!er(t)}var Wo=Hs(jo(),1),_c=["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"],Sc=_c.map(t=>new Wo.Netmask(t));function yn(t){for(let e of Sc)if(e.contains(t))return!0;return!1}function Cc(t){return/^::ffff:([0-9a-fA-F]{1,4}):([0-9a-fA-F]{1,4})$/.test(t)}function Lc(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 yn(o)}function Ic(t){return/^::ffff:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(t)}function Ac(t){let e=t.split(":"),r=e[e.length-1];return yn(r)}function Tc(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 xn(t){if(Ee(t))return yn(t);if(Cc(t))return Lc(t);if(Ic(t))return Ac(t);if(ve(t))return Tc(t)}function Dc(t){try{let e=j(t);switch(e.type){case"ip4":case"ip6":return xn(e.host)??!1;default:return e.host==="localhost"}}catch{return!1}}function re(){let t={};return t.promise=new Promise((e,r)=>{t.resolve=e,t.reject=r}),t}var rr=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 rr(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 rr(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 bn=class extends Error{type;code;constructor(e,r){super(e??"The operation was aborted"),this.type="aborted",this.code=r??"ABORT_ERR"}};function ue(t={}){return Fc(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 Fc(t,e){e=e??{};let r=e.onEnd,n=new Ye,o,i,s,a=re(),f=async()=>{try{return n.isEmpty()?s?{done:!0}:await new Promise((y,_)=>{i=L=>{i=null,n.push(L);try{y(t(n))}catch(I){_(I)}return o}}):t(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=re()})}},c=y=>i!=null?i(y):(n.push(y),o),u=y=>(n=new Ye,i!=null?i({error:y}):(n.push({error:y}),o)),d=y=>{if(s)return o;if(e?.objectMode!==!0&&y?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return c({done:!1,value:y})},h=y=>s?o:(s=!0,y!=null?u(y):c({done:!0})),g=()=>(n=new Ye,h(),{done:!0}),b=y=>(h(y),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:f,return:g,throw:b,push:d,end:h,get readableLength(){return n.size},onEmpty:async y=>{let _=y?.signal;if(_?.throwIfAborted(),n.isEmpty())return;let L,I;_!=null&&(L=new Promise((A,$)=>{I=()=>{$(new bn)},_.addEventListener("abort",I)}));try{await Promise.race([a.promise,L])}finally{I!=null&&_!=null&&_?.removeEventListener("abort",I)}}},r==null)return o;let w=o;return o={[Symbol.asyncIterator](){return this},next(){return w.next()},throw(y){return w.throw(y),r!=null&&(r(y),r=void 0),{done:!0}},return(){return w.return(),r!=null&&(r(),r=void 0),{done:!0}},push:d,end(y){return w.end(y),r!=null&&(r(y),r=void 0),o},get readableLength(){return w.readableLength},onEmpty:y=>w.onEmpty(y)},o}var wn=class extends Error{constructor(e){super(e),this.name="TimeoutError"}},En=class extends Error{constructor(e){super(),this.name="AbortError",this.message=e}},Go=t=>globalThis.DOMException===void 0?new En(t):new DOMException(t),Ho=t=>{let e=t.reason===void 0?Go("This operation was aborted."):t.reason;return e instanceof Error?e:Go(e)};function vn(t,e){let{milliseconds:r,fallback:n,message:o,customTimers:i={setTimeout,clearTimeout}}=e,s,a,c=new Promise((u,d)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(e.signal){let{signal:g}=e;g.aborted&&d(Ho(g)),a=()=>{d(Ho(g))},g.addEventListener("abort",a,{once:!0})}if(r===Number.POSITIVE_INFINITY){t.then(u,d);return}let h=new wn;s=i.setTimeout.call(void 0,()=>{if(n){try{u(n())}catch(g){d(g)}return}typeof t.cancel=="function"&&t.cancel(),o===!1?u():o instanceof Error?d(o):(h.message=o??`Promise timed out after ${r} milliseconds`,d(h))},r),(async()=>{try{u(await t)}catch(g){d(g)}})()}).finally(()=>{c.clear(),a&&e.signal&&e.signal.removeEventListener("abort",a)});return c.clear=()=>{i.clearTimeout.call(void 0,s),s=void 0},c}var kc=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 Uc(t,e,r){let n,o=new Promise((i,s)=>{if(r={rejectionEvents:["error"],multiArgs:!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(),f=[],{addListener:c,removeListener:u}=kc(t),d=(...g)=>{let b=r.multiArgs?g:g[0];r.filter&&!r.filter(b)||(f.push(b),r.count===f.length&&(n(),i(f)))},h=g=>{n(),s(g)};n=()=>{for(let g of a)u(g,d);for(let g of r.rejectionEvents)u(g,h)};for(let g of a)c(g,d);for(let g of r.rejectionEvents)c(g,h);r.signal&&r.signal.addEventListener("abort",()=>{h(r.signal.reason)},{once:!0}),r.resolveImmediately&&i(f)});if(o.cancel=n,typeof r.timeout=="number"){let i=vn(o,{milliseconds:r.timeout});return i.cancel=n,i}return o}function D(t,e,r){typeof r=="function"&&(r={filter:r}),r={...r,count:1,resolveImmediately:!1};let n=Uc(t,e,r),o=n.then(i=>i[0]);return o.cancel=n.cancel,o}function et(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 Lt=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}},It=class extends Error{static name="QueueFullError";constructor(e="The queue was full"){super(e),this.name="QueueFullError"}},_e=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"},At=class extends Error{static name="MaxEarlyStreamsError";name="MaxEarlyStreamsError"};function Bc(t){return t.reason}async function O(t,e,r){if(e==null)return t;let n=r?.translateError??Bc;if(e.aborted)return t.catch(()=>{}),Promise.reject(n(e));let o;try{return await Promise.race([t,new Promise((i,s)=>{o=()=>{s(n(e))},e.addEventListener("abort",o)})])}finally{o!=null&&e.removeEventListener("abort",o)}}var nr=class{deferred;signal;constructor(e){this.signal=e,this.deferred=re(),this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(this.signal?.reason??new le)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function Pc(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var or=class{id;fn;options;recipients;status;timeline;controller;constructor(e,r){this.id=Pc(),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 le),this.cleanup())}async join(e={}){let r=new nr(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 O(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 ne=class extends ae{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=et(this.emitEmpty.bind(this),1),this.emitIdle=et(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 It;let n=new or(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 i=0;i<this.queue.length;i++)if(this.queue[i]===n){this.queue.splice(i,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 le)}),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=ue({objectMode:!0}),n=f=>{f!=null?this.abort():this.clear(),r.end(f)},o=f=>{f.detail!=null&&r.push(f.detail)},i=f=>{n(f.detail.error)},s=()=>{n()},a=()=>{n(new le("Queue aborted"))};this.addEventListener("completed",o),this.addEventListener("failure",i),this.addEventListener("idle",s),e?.signal?.addEventListener("abort",a);try{yield*r}finally{this.removeEventListener("completed",o),this.removeEventListener("failure",i),this.removeEventListener("idle",s),e?.signal?.removeEventListener("abort",a),n()}}};var Nc=Math.pow(2,20)*4,Be=class extends ae{status;timeline;inactivityTimeout;maxReadBufferLength;maxWriteBufferLength;log;direction;maxMessageSize;readStatus;writeStatus;remoteReadStatus;remoteWriteStatus;writableNeedsDrain;readBuffer;writeBuffer;sendingData;constructor(e){super(),this.status="open",this.log=e.log,this.direction=e.direction??"outbound",this.inactivityTimeout=e.inactivityTimeout??12e4,this.maxReadBufferLength=e.maxReadBufferLength??Nc,this.maxWriteBufferLength=e.maxWriteBufferLength,this.maxMessageSize=e.maxMessageSize,this.readBuffer=new C,this.writeBuffer=new C,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.addEventListener("drain",r)}async*[Symbol.asyncIterator](){if(this.readStatus!=="readable"&&this.readStatus!=="paused")return;let e=ue(),r=i=>{e.push(i.data)};this.addEventListener("message",r);let n=i=>{e.end(i.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 Ie(`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 Wt(e))}}pause(){if(this.readStatus==="closed"||this.readStatus==="closing")throw new Ie("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 Ie("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 Ie(`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)}}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 jt;this.dispatchEvent(new Gt(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 Ve))}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 i=this.writeBuffer.sublist(0,o),s=new C(i);this.writeBuffer.consume(i.byteLength);let a=this.sendData(i);if(e=a.canSendMore,n+=a.sentBytes,a.sentBytes!==s.byteLength&&(s.consume(a.sentBytes),this.writeBuffer.prepend(s)),!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 ht(`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 ht(`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 Tt=class extends Be{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 _n(t){return t==null?!1:typeof t.then=="function"&&typeof t.catch=="function"&&typeof t.finally=="function"}var Dt=class extends ae{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=s=>{try{this.onData(s.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(s=>{s.onMuxerDrain()})};this.maConn.addEventListener("drain",o);let i=()=>{this.log("underlying stream closed with status %s and %d streams",this.status,this.streams.length),this.onTransportClosed()};this.maConn.addEventListener("close",i)}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 O(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 _n(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 At(`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(i=>i===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 Pe=class extends Be{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(){e.abort();for(let i of t)i?.removeEventListener!=null&&i.removeEventListener("abort",r)}for(let i of t){if(i?.aborted===!0){r();break}i?.addEventListener!=null&&i.addEventListener("abort",r)}function n(){for(let i of t)i?.removeEventListener!=null&&i.removeEventListener("abort",r)}let o=e.signal;return o.clear=n,o}var Ne=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,i=n*o;this.movingAverage=n*e+(1-n)*this.movingAverage,this.variance=(1-n)*(this.variance+o*i),this.deviation=Math.sqrt(this.variance),this.forecast=this.movingAverage+n*o}else this.movingAverage=e;this.previousTime=r}};var Ko=1.2,Qo=2,Xo=5e3,Jo=6e4,Zo=5e3,Sn=class{success;failure;next;metric;timeoutMultiplier;failureMultiplier;minTimeout;maxTimeout;constructor(e={}){let r=e.interval??Zo;this.success=new Ne(r),this.failure=new Ne(r),this.next=new Ne(r),this.failureMultiplier=e.failureMultiplier??Qo,this.timeoutMultiplier=e.timeoutMultiplier??Ko,this.minTimeout=e.minTimeout??Xo,this.maxTimeout=e.maxTimeout??Jo,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 U=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},pe=class extends Error{static name="ValidationError";name="ValidationError"},sr=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},ar=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};function Ln(t){return e=>Ae(e,t)}function In(t){return e=>T(e,t)}function tt(t){return new DataView(t.buffer).getUint16(t.byteOffset).toString()}function Me(t){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,typeof t=="string"?parseInt(t):t),new Uint8Array(e)}function Yo(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=Me(n);return xe([r,o],r.length+o.length)}function ei(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=ce.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=Me(n);return xe([r,o],r.length+o.length)}function An(t){let e=t.subarray(0,t.length-2),r=t.subarray(t.length-2),n=Ae(e,"base32"),o=tt(r);return`${n}:${o}`}var Tn=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 U("Invalid byte value in IP address");e[n]=o}),e},ti=function(t){let e=0;t=t.toString().trim();let r=t.split(":",8),n;for(n=0;n<r.length;n++){let i=Ee(r[n]),s;i&&(s=Tn(r[n]),r[n]=Ae(s.subarray(0,2),"base16")),s!=null&&++n<8&&r.splice(n,0,Ae(s.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 i=[n,1];for(n=9-r.length;n>0;n--)i.push("0");r.splice.apply(r,i)}let o=new Uint8Array(e+16);for(n=0;n<r.length;n++){r[n]===""&&(r[n]="0");let i=parseInt(r[n],16);if(isNaN(i)||i<0||i>65535)throw new U("Invalid byte value in IP address");o[e++]=i>>8&255,o[e++]=i&255}return o},ri=function(t){if(t.byteLength!==4)throw new U("IPv4 address was incorrect length");let e=[];for(let r=0;r<t.byteLength;r++)e.push(t[r]);return e.join(".")},ni=function(t){if(t.byteLength!==16)throw new U("IPv6 address was incorrect length");let e=[];for(let n=0;n<t.byteLength;n+=2){let o=t[n],i=t[n+1],s=`${o.toString(16).padStart(2,"0")}${i.toString(16).padStart(2,"0")}`;e.push(s)}let r=e.join(":");try{let n=new URL(`http://[${r}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new U(`Invalid IPv6 address "${r}"`)}};function oi(t){try{let e=new URL(`http://[${t}]`);return e.hostname.substring(1,e.hostname.length-1)}catch{throw new U(`Invalid IPv6 address "${t}"`)}}var Cn=Object.values(bt).map(t=>t.decoder),Mc=(function(){let t=Cn[0].or(Cn[1]);return Cn.slice(2).forEach(e=>t=t.or(e)),t})();function ii(t){return Mc.decode(t)}function si(t){return e=>t.encoder.encode(e)}function Oc(t){if(parseInt(t).toString()!==t)throw new pe("Value must be an integer")}function Rc(t){if(t<0)throw new pe("Value must be a positive integer, or zero")}function $c(t){return e=>{if(e>t)throw new pe(`Value must be smaller than or equal to ${t}`)}}function zc(...t){return e=>{for(let r of t)r(e)}}var Ft=zc(Oc,Rc,$c(65535));var F=-1,Dn=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 ar(`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)}))}},me=new Dn,Cu=[{code:4,name:"ip4",size:32,valueToBytes:Tn,bytesToValue:ri,validate:t=>{if(!Ee(t))throw new pe(`Invalid IPv4 address "${t}"`)}},{code:6,name:"tcp",size:16,valueToBytes:Me,bytesToValue:tt,validate:Ft},{code:273,name:"udp",size:16,valueToBytes:Me,bytesToValue:tt,validate:Ft},{code:33,name:"dccp",size:16,valueToBytes:Me,bytesToValue:tt,validate:Ft},{code:41,name:"ip6",size:128,valueToBytes:ti,bytesToValue:ni,stringToValue:oi,validate:t=>{if(!ve(t))throw new pe(`Invalid IPv6 address "${t}"`)}},{code:42,name:"ip6zone",size:F},{code:43,name:"ipcidr",size:8,bytesToValue:Ln("base10"),valueToBytes:In("base10")},{code:53,name:"dns",size:F},{code:54,name:"dns4",size:F},{code:55,name:"dns6",size:F},{code:56,name:"dnsaddr",size:F},{code:132,name:"sctp",size:16,valueToBytes:Me,bytesToValue:tt,validate:Ft},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:F,stringToValue:t=>decodeURIComponent(t),valueToString:t=>encodeURIComponent(t)},{code:421,name:"p2p",aliases:["ipfs"],size:F,bytesToValue:Ln("base58btc"),valueToBytes:t=>t.startsWith("Q")||t.startsWith("1")?In("base58btc")(t):Ke.parse(t).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:An,valueToBytes:Yo},{code:445,name:"onion3",size:296,bytesToValue:An,valueToBytes:ei},{code:446,name:"garlic64",size:F},{code:447,name:"garlic32",size:F},{code:448,name:"tls"},{code:449,name:"sni",size:F},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:F,bytesToValue:si(Jr),valueToBytes:ii},{code:480,name:"http"},{code:481,name:"http-path",size:F,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:F}];Cu.forEach(t=>{me.addProtocol(t)});function fi(t){let e=[],r=0;for(;r<t.length;){let n=he(t,r),o=me.getProtocol(n),i=N(n),s=Lu(o,t,r+i),a=0;s>0&&o.size===F&&(a=N(s));let f=i+a+s,c={code:n,name:o.name,bytes:t.subarray(r,r+f)};if(s>0){let u=r+i+a,d=t.subarray(u,u+s);c.value=o.bytesToValue?.(d)??Ae(d)}e.push(c),r+=f}return e}function li(t){let e=0,r=[];for(let n of t){if(n.bytes==null){let o=me.getProtocol(n.code),i=N(n.code),s,a=0,f=0;n.value!=null&&(s=o.valueToBytes?.(n.value)??T(n.value),a=s.byteLength,o.size===F&&(f=N(a)));let c=new Uint8Array(i+f+a),u=0;Qt(n.code,c,u),u+=i,s!=null&&(o.size===F&&(Qt(a,c,u),u+=f),c.set(s,u)),n.bytes=c}r.push(n.bytes),e+=n.bytes.byteLength}return xe(r,e)}function di(t){if(t.charAt(0)!=="/")throw new U('String multiaddr must start with "/"');let e=[],r="protocol",n="",o="";for(let i=1;i<t.length;i++){let s=t.charAt(i);s!=="/"&&(r==="protocol"?o+=t.charAt(i):n+=t.charAt(i));let a=i===t.length-1;if(s==="/"||a){let f=me.getProtocol(o);if(r==="protocol"){if(f.size==null||f.size===0){e.push({code:f.code,name:f.name}),n="",o="",r="protocol";continue}else if(a)throw new U(`Component ${o} was missing value`);r="value"}else if(r==="value"){let c={code:f.code,name:f.name};if(f.size!=null&&f.size!==0){if(n==="")throw new U(`Component ${o} was missing value`);c.value=f.stringToValue?.(n)??n}e.push(c),n="",o="",r="protocol"}}}if(o!==""&&n!=="")throw new U("Incomplete multiaddr");return e}function hi(t){return`/${t.flatMap(e=>{if(e.value==null)return e.name;let r=me.getProtocol(e.code);if(r==null)throw new U(`Unknown protocol code ${e.code}`);return[e.name,r.valueToString?.(e.value)??e.value]}).join("/")}`}function Lu(t,e,r){return t.size==null||t.size===0?0:t.size>0?t.size/8:he(e,r)}var Iu=Symbol.for("nodejs.util.inspect.custom"),Fn=Symbol.for("@multiformats/multiaddr");function Au(t){if(t==null&&(t="/"),pi(t))return t.getComponents();if(t instanceof Uint8Array)return fi(t);if(typeof t=="string")return t=t.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),t===""&&(t="/"),di(t);if(Array.isArray(t))return t;throw new U("Must be a string, Uint8Array, Component[], or another Multiaddr")}var cr=class t{[Fn]=!0;#e;#t;#r;constructor(e="/",r={}){this.#e=Au(e),r.validate!==!1&&Tu(this)}get bytes(){return this.#r==null&&(this.#r=li(this.#e)),this.#r}toString(){return this.#t==null&&(this.#t=hi(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 sr(`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 Qe(this.bytes,e.bytes)}[Iu](){return`Multiaddr(${this.toString()})`}};function Tu(t){t.getComponents().forEach(e=>{let r=me.getProtocol(e.code);e.value!=null&&r.validate?.(e.value)})}function pi(t){return!!t?.[Fn]}function Se(t){return new cr(t)}function mi(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),Se(`/${n.join("/")}`)}function Du(t,e){if(t==null)return[];let r=j(t);return[mi(r,e)]}function Fu(t){return ve(t)?tr("2000::/3",t):!1}function ku(t,e){if(typeof t!="string")throw new M(`invalid ip provided: ${t}`);if(typeof e=="string"&&(e=parseInt(e)),isNaN(e))throw new M(`invalid port provided: ${e}`);if(Ee(t))return Se(`/ip4/${t}/tcp/${e}`);if(ve(t))return Se(`/ip6/${t}/tcp/${e}`);throw new M(`invalid ip:port for creating a multiaddr: ${t}:${e}`)}function Uu(t){return t==null||typeof t?.[Symbol.asyncIterator]!="function"?!1:typeof t.next=="function"}function Bu(t){return t==null||typeof t?.[Symbol.iterator]!="function"?!1:typeof t.next=="function"}var ur=class extends Error{type;code;constructor(e,r,n){super(e??"The operation was aborted"),this.type="aborted",this.name=n??"AbortError",this.code=r??"ABORT_ERR"}};async function gi(t,e,r){if(e==null)return t;if(e.aborted)return t.catch(()=>{}),Promise.reject(new ur(r?.errorMessage,r?.errorCode,r?.errorName));let n,o=new ur(r?.errorMessage,r?.errorCode,r?.errorName);try{return await Promise.race([t,new Promise((i,s)=>{n=()=>{s(o)},e.addEventListener("abort",n)})])}finally{n!=null&&e.removeEventListener("abort",n)}}var kn=class{readNext;haveNext;ended;nextResult;error;constructor(){this.ended=!1,this.readNext=re(),this.haveNext=re()}[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=re(),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=re(),await gi(this.readNext.promise,r?.signal,r)}};function yi(){return new kn}function Pu(t){return t[Symbol.asyncIterator]!=null}async function Nu(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*Mu(t){let e=new AbortController,r=yi();Nu(t,r,e.signal).catch(()=>{});try{yield*r}finally{e.abort()}}function*Ou(t){for(let e of t)yield*e}function Ru(...t){let e=[];for(let r of t)Pu(r)||e.push(r);return e.length===t.length?Ou(e):Mu(t)}var xi=Ru;function bi(t,...e){if(t==null)throw new Error("Empty pipeline");if(Un(t)){let n=t;t=()=>n.source}else if(Ei(t)||wi(t)){let n=t;t=()=>n}let r=[t,...e];if(r.length>1&&Un(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++)Un(r[n])&&(r[n]=zu(r[n]));return $u(...r)}var $u=(...t)=>{let e;for(;t.length>0;)e=t.shift()(e);return e},wi=t=>t?.[Symbol.asyncIterator]!=null,Ei=t=>t?.[Symbol.iterator]!=null,Un=t=>t==null?!1:t.sink!=null&&t.source!=null,zu=t=>e=>{let r=t.sink(e);if(r?.then!=null){let n=ue({objectMode:!0});r.then(()=>{n.end()},s=>{n.end(s)});let o,i=t.source;if(wi(i))o=async function*(){yield*i,n.end()};else if(Ei(i))o=function*(){yield*i,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return xi(n,o())}return t.source};var Vu=4194304,kt=class extends Error{static name="UnwrappedError";name="UnwrappedError"},rt=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 qu(t){return typeof t?.closeRead=="function"}function ju(t){return typeof t?.close=="function"}function Bn(t){return qu(t)?t.readStatus==="closing"||t.readStatus==="closed":ju(t)?t.status!=="open":!1}function Wu(t){return t?.addEventListener!=null&&t?.removeEventListener!=null&&t?.send!=null&&t?.push!=null&&t?.log!=null}function vi(t,e){let r=e?.maxBufferSize??Vu,n=new C,o=Promise.withResolvers(),i=!1;if(!Wu(t))throw new M("Argument should be a Stream or a Multiaddr");let s=u=>{if(n.append(u.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",s);let a=u=>{u.error!=null?o.reject(u.error):o.resolve()};t.addEventListener("close",a);let f=()=>{o.resolve()};t.addEventListener("remoteCloseWrite",f);let c={readBuffer:n,async read(u){if(i===!0)throw new kt("Stream was unwrapped");if(Bn(t)){if(u?.bytes==null)return null;if(n.byteLength<u.bytes)throw t.log.error("closed after reading %d/%d bytes",n.byteLength,u.bytes),new _e(`Unexpected EOF - stream closed after reading ${n.byteLength}/${u.bytes} bytes`)}let d=u?.bytes??1;for(;;){if(n.byteLength>=d){o.resolve();break}if(await O(o.promise,u?.signal),Bn(t)){if(n.byteLength===0&&u?.bytes==null)return null;break}o=Promise.withResolvers()}let h=u?.bytes??n.byteLength;if(n.byteLength<h){if(Bn(t))throw t.log.error("closed while reading %d/%d bytes",n.byteLength,h),new _e(`Unexpected EOF - stream closed while reading ${n.byteLength}/${h} bytes`);return c.read(u)}let g=n.sublist(0,h);return n.consume(h),g},async write(u,d){if(i===!0)throw new kt("Stream was unwrapped");t.send(u)||await D(t,"drain",{signal:d?.signal,rejectionEvents:["close"]})},unwrap(){return i||(i=!0,t.removeEventListener("message",s),t.removeEventListener("close",a),t.removeEventListener("remoteCloseWrite",f),n.byteLength>0&&(t.log("stream unwrapped with %d unread bytes",n.byteLength),t.push(n))),t}};return c}function _i(t,e={}){let r=vi(t,e);e.maxDataLength!=null&&e.maxLengthLength==null&&(e.maxLengthLength=N(e.maxDataLength));let n=e?.lengthDecoder??he,o=e?.lengthEncoder??Xt;return{async read(s){let a=-1,f=new C;for(;;){let u=await r.read({...s,bytes:1});if(u==null)break;f.append(u);try{a=n(f)}catch(d){if(d instanceof RangeError)continue;throw d}if(a<0)throw new rt("Invalid message length");if(e?.maxLengthLength!=null&&f.byteLength>e.maxLengthLength)throw new lr(`Message length length too long - ${f.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 c=await r.read({...s,bytes:a});if(c==null)throw t.log.error("tried to read %d bytes but the stream closed",a),new _e(`Unexpected EOF - tried to read ${a} bytes but the stream closed`);if(c.byteLength!==a)throw t.log.error("read %d/%d bytes before the stream closed",c.byteLength,a),new _e(`Unexpected EOF - read ${c.byteLength}/${a} bytes before the stream closed`);return c},async write(s,a){await r.write(new C(o(s.byteLength),s),a)},async writeV(s,a){let f=new C(...s.flatMap(c=>[o(c.byteLength),c]));await r.write(f,a)},unwrap(){return r.unwrap()}}}function Gu(t,e){let r=_i(t,e),n={read:async(o,i)=>{let s=await r.read(i);return o.decode(s)},write:async(o,i,s)=>{await r.write(i.encode(o),s)},writeV:async(o,i,s)=>{await r.writeV(o.map(a=>i.encode(a)),s)},pb:o=>({read:async i=>n.read(o,i),write:async(i,s)=>n.write(i,o,s),writeV:async(i,s)=>n.writeV(i,o,s),unwrap:()=>n}),unwrap:()=>r.unwrap()};return n}async function Pn(t,e){let r=t.log.newScope("echo"),n=Date.now(),o=0;try{for await(let i of t)o+=i.byteLength,t.send(i)||(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(i){t.abort(i)}}function Hu(t){return t?.addEventListener!=null}function Si(t){let e=ue(),r,n=s=>{e.push(s.data)},o=()=>{e.end(),t.removeEventListener("message",n),t.removeEventListener("close",i),t.removeEventListener("remoteCloseWrite",o)},i=s=>{e.end(s.error),s.error!=null&&r?.reject(s.error),t.removeEventListener("message",n),t.removeEventListener("close",i),t.removeEventListener("remoteCloseWrite",o)};return t.addEventListener("message",n),t.addEventListener("close",i,{once:!0}),t.addEventListener("remoteCloseWrite",o,{once:!0}),{source:e,async sink(s){async function*a(){yield*s}let f=a();for(;;){r=Promise.withResolvers();let{done:c,value:u}=await Promise.race([f.next(),r.promise]);if(t.writeStatus==="closing"||t.writeStatus==="closed"||(u!=null&&(t.send(u)||await Promise.race([D(t,"drain",{rejectionEvents:["close"]})])),c===!0))break}await t.close()}}}function Ku(...t){let e=t.map(r=>Hu(r)?Si(r):r);return bi(...e)}var Qu=1024*1024*4,Xu=1024*1024*4,Nn=class{buffer;maxBufferSize;lengthDecoder;maxDataLength;encodingLength;constructor(e={}){this.buffer=new C,this.maxBufferSize=e.maxBufferSize??Qu,this.maxDataLength=e.maxDataLength??Xu,this.lengthDecoder=e.lengthDecoder??he,this.encodingLength=e.encodingLength??N}*decode(e){if(this.buffer.append(e),this.buffer.byteLength>this.maxBufferSize)throw new M(`Buffer length limit exceeded - ${this.buffer.byteLength}/${this.maxBufferSize}`);for(;;){let r;try{r=this.lengthDecoder(this.buffer)}catch(i){if(i instanceof RangeError)break;throw i}if(r<0||r>this.maxDataLength)throw new rt("Invalid message length");let n=this.encodingLength(r),o=n+r;if(this.buffer.byteLength>=o){let i=this.buffer.sublist(n,o);this.buffer.consume(o),i.byteLength>0&&(yield i)}else break}}};function Ju(t){return!!(t.startsWith("169.254.")||t.toLowerCase().startsWith("fe80"))}function nt(t){if(typeof t!="object"||t===null)return!1;let e=Object.getPrototypeOf(t);return(e===null||e===Object.prototype||Object.getPrototypeOf(e)===null)&&!(Symbol.toStringTag in t)&&!(Symbol.iterator in t)}var{hasOwnProperty:Li}=Object.prototype,{propertyIsEnumerable:Zu}=Object,ot=(t,e,r)=>{Object.defineProperty(t,e,{value:r,writable:!0,enumerable:!0,configurable:!0})},Yu=void 0,Ci={concatArrays:!1,ignoreUndefined:!1},dr=t=>{let e=[];for(let r in t)Li.call(t,r)&&e.push(r);if(Object.getOwnPropertySymbols){let r=Object.getOwnPropertySymbols(t);for(let n of r)Zu.call(t,n)&&e.push(n)}return e};function it(t){return Array.isArray(t)?ef(t):nt(t)?tf(t):t}function ef(t){let e=t.slice(0,0);return dr(t).forEach(r=>{ot(e,r,it(t[r]))}),e}function tf(t){let e=Object.getPrototypeOf(t)===null?Object.create(null):{};return dr(t).forEach(r=>{ot(e,r,it(t[r]))}),e}var Ii=(t,e,r,n)=>(r.forEach(o=>{typeof e[o]>"u"&&n.ignoreUndefined||(o in t&&t[o]!==Object.getPrototypeOf(t)?ot(t,o,Mn(t[o],e[o],n)):ot(t,o,it(e[o])))}),t),rf=(t,e,r)=>{let n=t.slice(0,0),o=0;return[t,e].forEach(i=>{let s=[];for(let a=0;a<i.length;a++)Li.call(i,a)&&(s.push(String(a)),i===t?ot(n,o++,i[a]):ot(n,o++,it(i[a])));n=Ii(n,i,dr(i).filter(a=>!s.includes(a)),r)}),n};function Mn(t,e,r){return r.concatArrays&&Array.isArray(t)&&Array.isArray(e)?rf(t,e,r):!nt(e)||!nt(t)?it(e):Ii(t,e,dr(e),r)}function nf(...t){let e=Mn(it(Ci),this!==Yu&&this||{},Ci),r={_:{}};for(let n of t)if(n!==void 0){if(!nt(n))throw new TypeError("`"+n+"` is not an Option Object");r=Mn(r,{_:n},e)}return r._}var of=["string","number","bigint","symbol"],sf=["Function","Generator","AsyncGenerator","GeneratorFunction","AsyncGeneratorFunction","AsyncFunction","Observable","Array","Buffer","Object","RegExp","Date","Error","Map","Set","WeakMap","WeakSet","ArrayBuffer","SharedArrayBuffer","DataView","Promise","URL","HTMLElement","Int8Array","Uint8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array"];function Ai(t){if(t===null)return"null";if(t===void 0)return"undefined";if(t===!0||t===!1)return"boolean";let e=typeof t;if(of.includes(e))return e;if(e==="function")return"Function";if(Array.isArray(t))return"Array";if(af(t))return"Buffer";let r=cf(t);return r||"Object"}function af(t){return t&&t.constructor&&t.constructor.isBuffer&&t.constructor.isBuffer.call(null,t)}function cf(t){let e=Object.prototype.toString.call(t).slice(8,-1);if(sf.includes(e))return e}var l=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}};l.uint=new l(0,"uint",!0);l.negint=new l(1,"negint",!0);l.bytes=new l(2,"bytes",!0);l.string=new l(3,"string",!0);l.array=new l(4,"array",!1);l.map=new l(5,"map",!1);l.tag=new l(6,"tag",!1);l.float=new l(7,"float",!0);l.false=new l(7,"false",!0);l.true=new l(7,"true",!0);l.null=new l(7,"null",!0);l.undefined=new l(7,"undefined",!0);l.break=new l(7,"break",!0);var m=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 st=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",uf=new TextDecoder,ff=new TextEncoder;function hr(t){return st&&globalThis.Buffer.isBuffer(t)}function On(t){return t instanceof Uint8Array?hr(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):t:Uint8Array.from(t)}var ki=st?(t,e,r)=>r-e>64?globalThis.Buffer.from(t.subarray(e,r)).toString("utf8"):Di(t,e,r):(t,e,r)=>r-e>64?uf.decode(t.subarray(e,r)):Di(t,e,r),Ui=st?t=>t.length>64?globalThis.Buffer.from(t):Ti(t):t=>t.length>64?ff.encode(t):Ti(t),fe=t=>Uint8Array.from(t),at=st?(t,e,r)=>hr(t)?new Uint8Array(t.subarray(e,r)):t.slice(e,r):(t,e,r)=>t.slice(e,r),Bi=st?(t,e)=>(t=t.map(r=>r instanceof Uint8Array?r:globalThis.Buffer.from(r)),On(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},Pi=st?t=>globalThis.Buffer.allocUnsafe(t):t=>new Uint8Array(t);function Ni(t,e){if(hr(t)&&hr(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 Ti(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):(e[r++]=o>>12|224,e[r++]=o>>6&63|128,e[r++]=o&63|128)}return e}function Di(t,e,r){let n=[];for(;e<r;){let o=t[e],i=null,s=o>239?4:o>223?3:o>191?2:1;if(e+s<=r){let a,f,c,u;switch(s){case 1:o<128&&(i=o);break;case 2:a=t[e+1],(a&192)===128&&(u=(o&31)<<6|a&63,u>127&&(i=u));break;case 3:a=t[e+1],f=t[e+2],(a&192)===128&&(f&192)===128&&(u=(o&15)<<12|(a&63)<<6|f&63,u>2047&&(u<55296||u>57343)&&(i=u));break;case 4:a=t[e+1],f=t[e+2],c=t[e+3],(a&192)===128&&(f&192)===128&&(c&192)===128&&(u=(o&15)<<18|(a&63)<<12|(f&63)<<6|c&63,u>65535&&u<1114112&&(i=u))}}i===null?(i=65533,s=1):i>65535&&(i-=65536,n.push(i>>>10&1023|55296),i=56320|i&1023),n.push(i),e+=s}return lf(n)}var Fi=4096;function lf(t){let e=t.length;if(e<=Fi)return String.fromCharCode.apply(String,t);let r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.slice(n,n+=Fi));return r}var df=256,Ut=class{constructor(e=df){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=Pi(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=at(n,0,this.cursor)}else r=Bi(this.chunks,this.cursor);return e&&this.reset(),r}};var x="CBOR decode error:",Rn="CBOR encode error:",Bt=[];Bt[23]=1;Bt[24]=2;Bt[25]=3;Bt[26]=5;Bt[27]=9;function ge(t,e,r){if(t.length-e<r)throw new Error(`${x} not enough data for type`)}var k=[24,256,65536,4294967296,BigInt("18446744073709551616")];function W(t,e,r){ge(t,e,1);let n=t[e];if(r.strict===!0&&n<k[0])throw new Error(`${x} integer encoded in more bytes than necessary (strict decode)`);return n}function G(t,e,r){ge(t,e,2);let n=t[e]<<8|t[e+1];if(r.strict===!0&&n<k[1])throw new Error(`${x} integer encoded in more bytes than necessary (strict decode)`);return n}function H(t,e,r){ge(t,e,4);let n=t[e]*16777216+(t[e+1]<<16)+(t[e+2]<<8)+t[e+3];if(r.strict===!0&&n<k[2])throw new Error(`${x} integer encoded in more bytes than necessary (strict decode)`);return n}function K(t,e,r){ge(t,e,8);let n=t[e]*16777216+(t[e+1]<<16)+(t[e+2]<<8)+t[e+3],o=t[e+4]*16777216+(t[e+5]<<16)+(t[e+6]<<8)+t[e+7],i=(BigInt(n)<<BigInt(32))+BigInt(o);if(r.strict===!0&&i<k[3])throw new Error(`${x} integer encoded in more bytes than necessary (strict decode)`);if(i<=Number.MAX_SAFE_INTEGER)return Number(i);if(r.allowBigInt===!0)return i;throw new Error(`${x} integers outside of the safe integer range are not supported`)}function Mi(t,e,r,n){return new m(l.uint,W(t,e+1,n),2)}function Oi(t,e,r,n){return new m(l.uint,G(t,e+1,n),3)}function Ri(t,e,r,n){return new m(l.uint,H(t,e+1,n),5)}function $i(t,e,r,n){return new m(l.uint,K(t,e+1,n),9)}function Z(t,e){return B(t,0,e.value)}function B(t,e,r){if(r<k[0]){let n=Number(r);t.push([e|n])}else if(r<k[1]){let n=Number(r);t.push([e|24,n])}else if(r<k[2]){let n=Number(r);t.push([e|25,n>>>8,n&255])}else if(r<k[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<k[4]){let o=[e|27,0,0,0,0,0,0,0],i=Number(n&BigInt(4294967295)),s=Number(n>>BigInt(32)&BigInt(4294967295));o[8]=i&255,i=i>>8,o[7]=i&255,i=i>>8,o[6]=i&255,i=i>>8,o[5]=i&255,o[4]=s&255,s=s>>8,o[3]=s&255,s=s>>8,o[2]=s&255,s=s>>8,o[1]=s&255,t.push(o)}else throw new Error(`${x} encountered BigInt larger than allowable range`)}}Z.encodedSize=function(e){return B.encodedSize(e.value)};B.encodedSize=function(e){return e<k[0]?1:e<k[1]?2:e<k[2]?3:e<k[3]?5:9};Z.compareTokens=function(e,r){return e.value<r.value?-1:e.value>r.value?1:0};function zi(t,e,r,n){return new m(l.negint,-1-W(t,e+1,n),2)}function Vi(t,e,r,n){return new m(l.negint,-1-G(t,e+1,n),3)}function qi(t,e,r,n){return new m(l.negint,-1-H(t,e+1,n),5)}var $n=BigInt(-1),ji=BigInt(1);function Wi(t,e,r,n){let o=K(t,e+1,n);if(typeof o!="bigint"){let i=-1-o;if(i>=Number.MIN_SAFE_INTEGER)return new m(l.negint,i,9)}if(n.allowBigInt!==!0)throw new Error(`${x} integers outside of the safe integer range are not supported`);return new m(l.negint,$n-BigInt(o),9)}function pr(t,e){let r=e.value,n=typeof r=="bigint"?r*$n-ji:r*-1-1;B(t,e.type.majorEncoded,n)}pr.encodedSize=function(e){let r=e.value,n=typeof r=="bigint"?r*$n-ji:r*-1-1;return n<k[0]?1:n<k[1]?2:n<k[2]?3:n<k[3]?5:9};pr.compareTokens=function(e,r){return e.value<r.value?1:e.value>r.value?-1:0};function Pt(t,e,r,n){ge(t,e,r+n);let o=at(t,e+r,e+r+n);return new m(l.bytes,o,r+n)}function Gi(t,e,r,n){return Pt(t,e,1,r)}function Hi(t,e,r,n){return Pt(t,e,2,W(t,e+1,n))}function Ki(t,e,r,n){return Pt(t,e,3,G(t,e+1,n))}function Qi(t,e,r,n){return Pt(t,e,5,H(t,e+1,n))}function Xi(t,e,r,n){let o=K(t,e+1,n);if(typeof o=="bigint")throw new Error(`${x} 64-bit integer bytes lengths not supported`);return Pt(t,e,9,o)}function mr(t){return t.encodedBytes===void 0&&(t.encodedBytes=t.type===l.string?Ui(t.value):t.value),t.encodedBytes}function ct(t,e){let r=mr(e);B(t,e.type.majorEncoded,r.length),t.push(r)}ct.encodedSize=function(e){let r=mr(e);return B.encodedSize(r.length)+r.length};ct.compareTokens=function(e,r){return pf(mr(e),mr(r))};function pf(t,e){return t.length<e.length?-1:t.length>e.length?1:Ni(t,e)}function Nt(t,e,r,n,o){let i=r+n;ge(t,e,i);let s=new m(l.string,ki(t,e+r,e+i),i);return o.retainStringBytes===!0&&(s.byteValue=at(t,e+r,e+i)),s}function Ji(t,e,r,n){return Nt(t,e,1,r,n)}function Zi(t,e,r,n){return Nt(t,e,2,W(t,e+1,n),n)}function Yi(t,e,r,n){return Nt(t,e,3,G(t,e+1,n),n)}function es(t,e,r,n){return Nt(t,e,5,H(t,e+1,n),n)}function ts(t,e,r,n){let o=K(t,e+1,n);if(typeof o=="bigint")throw new Error(`${x} 64-bit integer string lengths not supported`);return Nt(t,e,9,o,n)}var rs=ct;function ut(t,e,r,n){return new m(l.array,n,r)}function ns(t,e,r,n){return ut(t,e,1,r)}function os(t,e,r,n){return ut(t,e,2,W(t,e+1,n))}function is(t,e,r,n){return ut(t,e,3,G(t,e+1,n))}function ss(t,e,r,n){return ut(t,e,5,H(t,e+1,n))}function as(t,e,r,n){let o=K(t,e+1,n);if(typeof o=="bigint")throw new Error(`${x} 64-bit integer array lengths not supported`);return ut(t,e,9,o)}function cs(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${x} indefinite length items not allowed`);return ut(t,e,1,1/0)}function gr(t,e){B(t,l.array.majorEncoded,e.value)}gr.compareTokens=Z.compareTokens;gr.encodedSize=function(e){return B.encodedSize(e.value)};function ft(t,e,r,n){return new m(l.map,n,r)}function us(t,e,r,n){return ft(t,e,1,r)}function fs(t,e,r,n){return ft(t,e,2,W(t,e+1,n))}function ls(t,e,r,n){return ft(t,e,3,G(t,e+1,n))}function ds(t,e,r,n){return ft(t,e,5,H(t,e+1,n))}function hs(t,e,r,n){let o=K(t,e+1,n);if(typeof o=="bigint")throw new Error(`${x} 64-bit integer map lengths not supported`);return ft(t,e,9,o)}function ps(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${x} indefinite length items not allowed`);return ft(t,e,1,1/0)}function yr(t,e){B(t,l.map.majorEncoded,e.value)}yr.compareTokens=Z.compareTokens;yr.encodedSize=function(e){return B.encodedSize(e.value)};function ms(t,e,r,n){return new m(l.tag,r,1)}function gs(t,e,r,n){return new m(l.tag,W(t,e+1,n),2)}function ys(t,e,r,n){return new m(l.tag,G(t,e+1,n),3)}function xs(t,e,r,n){return new m(l.tag,H(t,e+1,n),5)}function bs(t,e,r,n){return new m(l.tag,K(t,e+1,n),9)}function xr(t,e){B(t,l.tag.majorEncoded,e.value)}xr.compareTokens=Z.compareTokens;xr.encodedSize=function(e){return B.encodedSize(e.value)};var wf=20,Ef=21,vf=22,_f=23;function ws(t,e,r,n){if(n.allowUndefined===!1)throw new Error(`${x} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new m(l.null,null,1):new m(l.undefined,void 0,1)}function Es(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${x} indefinite length items not allowed`);return new m(l.break,void 0,1)}function zn(t,e,r){if(r){if(r.allowNaN===!1&&Number.isNaN(t))throw new Error(`${x} NaN values are not supported`);if(r.allowInfinity===!1&&(t===1/0||t===-1/0))throw new Error(`${x} Infinity values are not supported`)}return new m(l.float,t,e)}function vs(t,e,r,n){return zn(Vn(t,e+1),3,n)}function _s(t,e,r,n){return zn(qn(t,e+1),5,n)}function Ss(t,e,r,n){return zn(As(t,e+1),9,n)}function br(t,e,r){let n=e.value;if(n===!1)t.push([l.float.majorEncoded|wf]);else if(n===!0)t.push([l.float.majorEncoded|Ef]);else if(n===null)t.push([l.float.majorEncoded|vf]);else if(n===void 0)t.push([l.float.majorEncoded|_f]);else{let o,i=!1;(!r||r.float64!==!0)&&(Ls(n),o=Vn(oe,1),n===o||Number.isNaN(n)?(oe[0]=249,t.push(oe.slice(0,3)),i=!0):(Is(n),o=qn(oe,1),n===o&&(oe[0]=250,t.push(oe.slice(0,5)),i=!0))),i||(Sf(n),o=As(oe,1),oe[0]=251,t.push(oe.slice(0,9)))}}br.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){Ls(n);let o=Vn(oe,1);if(n===o||Number.isNaN(n))return 3;if(Is(n),o=qn(oe,1),n===o)return 5}return 9};var Cs=new ArrayBuffer(9),Y=new DataView(Cs,1),oe=new Uint8Array(Cs,0);function Ls(t){if(t===1/0)Y.setUint16(0,31744,!1);else if(t===-1/0)Y.setUint16(0,64512,!1);else if(Number.isNaN(t))Y.setUint16(0,32256,!1);else{Y.setFloat32(0,t);let e=Y.getUint32(0),r=(e&2139095040)>>23,n=e&8388607;if(r===255)Y.setUint16(0,31744,!1);else if(r===0)Y.setUint16(0,(t&2147483648)>>16|n>>13,!1);else{let o=r-127;o<-24?Y.setUint16(0,0):o<-14?Y.setUint16(0,(e&2147483648)>>16|1<<24+o,!1):Y.setUint16(0,(e&2147483648)>>16|o+15<<10|n>>13,!1)}}}function Vn(t,e){if(t.length-e<2)throw new Error(`${x} not enough data for float16`);let r=(t[e]<<8)+t[e+1];if(r===31744)return 1/0;if(r===64512)return-1/0;if(r===32256)return NaN;let n=r>>10&31,o=r&1023,i;return n===0?i=o*2**-24:n!==31?i=(o+1024)*2**(n-25):i=o===0?1/0:NaN,r&32768?-i:i}function Is(t){Y.setFloat32(0,t,!1)}function qn(t,e){if(t.length-e<4)throw new Error(`${x} not enough data for float32`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,4).getFloat32(0,!1)}function Sf(t){Y.setFloat64(0,t,!1)}function As(t,e){if(t.length-e<8)throw new Error(`${x} not enough data for float64`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,8).getFloat64(0,!1)}br.compareTokens=Z.compareTokens;function E(t,e,r){throw new Error(`${x} encountered invalid minor (${r}) for major ${t[e]>>>5}`)}function wr(t){return()=>{throw new Error(`${x} ${t}`)}}var p=[];for(let t=0;t<=23;t++)p[t]=E;p[24]=Mi;p[25]=Oi;p[26]=Ri;p[27]=$i;p[28]=E;p[29]=E;p[30]=E;p[31]=E;for(let t=32;t<=55;t++)p[t]=E;p[56]=zi;p[57]=Vi;p[58]=qi;p[59]=Wi;p[60]=E;p[61]=E;p[62]=E;p[63]=E;for(let t=64;t<=87;t++)p[t]=Gi;p[88]=Hi;p[89]=Ki;p[90]=Qi;p[91]=Xi;p[92]=E;p[93]=E;p[94]=E;p[95]=wr("indefinite length bytes/strings are not supported");for(let t=96;t<=119;t++)p[t]=Ji;p[120]=Zi;p[121]=Yi;p[122]=es;p[123]=ts;p[124]=E;p[125]=E;p[126]=E;p[127]=wr("indefinite length bytes/strings are not supported");for(let t=128;t<=151;t++)p[t]=ns;p[152]=os;p[153]=is;p[154]=ss;p[155]=as;p[156]=E;p[157]=E;p[158]=E;p[159]=cs;for(let t=160;t<=183;t++)p[t]=us;p[184]=fs;p[185]=ls;p[186]=ds;p[187]=hs;p[188]=E;p[189]=E;p[190]=E;p[191]=ps;for(let t=192;t<=215;t++)p[t]=ms;p[216]=gs;p[217]=ys;p[218]=xs;p[219]=bs;p[220]=E;p[221]=E;p[222]=E;p[223]=E;for(let t=224;t<=243;t++)p[t]=wr("simple values are not supported");p[244]=E;p[245]=E;p[246]=E;p[247]=ws;p[248]=wr("simple values are not supported");p[249]=vs;p[250]=_s;p[251]=Ss;p[252]=E;p[253]=E;p[254]=E;p[255]=Es;var ie=[];for(let t=0;t<24;t++)ie[t]=new m(l.uint,t,1);for(let t=-1;t>=-24;t--)ie[31-t]=new m(l.negint,t,1);ie[64]=new m(l.bytes,new Uint8Array(0),1);ie[96]=new m(l.string,"",1);ie[128]=new m(l.array,0,1);ie[160]=new m(l.map,0,1);ie[244]=new m(l.false,!1,1);ie[245]=new m(l.true,!0,1);ie[246]=new m(l.null,null,1);function Ts(t){switch(t.type){case l.false:return fe([244]);case l.true:return fe([245]);case l.null:return fe([246]);case l.bytes:return t.value.length?void 0:fe([64]);case l.string:return t.value===""?fe([96]):void 0;case l.array:return t.value===0?fe([128]):void 0;case l.map:return t.value===0?fe([160]):void 0;case l.uint:return t.value<24?fe([Number(t.value)]):void 0;case l.negint:if(t.value>=-24)return fe([31-Number(t.value)])}}var Lf={float64:!1,mapSorter:Tf,quickEncodeToken:Ts};function If(){let t=[];return t[l.uint.major]=Z,t[l.negint.major]=pr,t[l.bytes.major]=ct,t[l.string.major]=rs,t[l.array.major]=gr,t[l.map.major]=yr,t[l.tag.major]=xr,t[l.float.major]=br,t}var Ds=If(),jn=new Ut,vr=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(`${Rn} object contains circular references`);return new t(r,e)}},Ce={null:new m(l.null,null),undefined:new m(l.undefined,void 0),true:new m(l.true,!0),false:new m(l.false,!1),emptyArray:new m(l.array,0),emptyMap:new m(l.map,0)},Le={number(t,e,r,n){return!Number.isInteger(t)||!Number.isSafeInteger(t)?new m(l.float,t):t>=0?new m(l.uint,t):new m(l.negint,t)},bigint(t,e,r,n){return t>=BigInt(0)?new m(l.uint,t):new m(l.negint,t)},Uint8Array(t,e,r,n){return new m(l.bytes,t)},string(t,e,r,n){return new m(l.string,t)},boolean(t,e,r,n){return t?Ce.true:Ce.false},null(t,e,r,n){return Ce.null},undefined(t,e,r,n){return Ce.undefined},ArrayBuffer(t,e,r,n){return new m(l.bytes,new Uint8Array(t))},DataView(t,e,r,n){return new m(l.bytes,new Uint8Array(t.buffer,t.byteOffset,t.byteLength))},Array(t,e,r,n){if(!t.length)return r.addBreakTokens===!0?[Ce.emptyArray,new m(l.break)]:Ce.emptyArray;n=vr.createCheck(n,t);let o=[],i=0;for(let s of t)o[i++]=Er(s,r,n);return r.addBreakTokens?[new m(l.array,t.length),o,new m(l.break)]:[new m(l.array,t.length),o]},Object(t,e,r,n){let o=e!=="Object",i=o?t.keys():Object.keys(t),s=o?t.size:i.length;if(!s)return r.addBreakTokens===!0?[Ce.emptyMap,new m(l.break)]:Ce.emptyMap;n=vr.createCheck(n,t);let a=[],f=0;for(let c of i)a[f++]=[Er(c,r,n),Er(o?t.get(c):t[c],r,n)];return Af(a,r),r.addBreakTokens?[new m(l.map,s),a,new m(l.break)]:[new m(l.map,s),a]}};Le.Map=Le.Object;Le.Buffer=Le.Uint8Array;for(let t of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))Le[`${t}Array`]=Le.DataView;function Er(t,e={},r){let n=Ai(t),o=e&&e.typeEncoders&&e.typeEncoders[n]||Le[n];if(typeof o=="function"){let s=o(t,n,e,r);if(s!=null)return s}let i=Le[n];if(!i)throw new Error(`${Rn} unsupported type: ${n}`);return i(t,n,e,r)}function Af(t,e){e.mapSorter&&t.sort(e.mapSorter)}function Tf(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,i=Ds[o].compareTokens(r,n);return i===0&&console.warn("WARNING: complex key types used, CBOR key sorting guarantees are gone"),i}function Fs(t,e,r,n){if(Array.isArray(e))for(let o of e)Fs(t,o,r,n);else r[e.type.major](t,e,n)}function Df(t,e,r){let n=Er(t,r);if(!Array.isArray(n)&&r.quickEncodeToken){let o=r.quickEncodeToken(n);if(o)return o;let i=e[n.type.major];if(i.encodedSize){let s=i.encodedSize(n,r),a=new Ut(s);if(i(a,n,r),a.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${n} was wrong`);return On(a.chunks[0])}}return jn.reset(),Fs(jn,n,e,r),jn.toBytes(!0)}function Wn(t,e){return e=Object.assign({},Lf,e),Df(t,Ds,e)}var Ff={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},_r=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=ie[e];if(r===void 0){let n=p[e];if(!n)throw new Error(`${x} 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}},Mt=Symbol.for("DONE"),Sr=Symbol.for("BREAK");function kf(t,e,r){let n=[];for(let o=0;o<t.value;o++){let i=lt(e,r);if(i===Sr){if(t.value===1/0)break;throw new Error(`${x} got unexpected break to lengthed array`)}if(i===Mt)throw new Error(`${x} found array but not enough entries (got ${o}, expected ${t.value})`);n[o]=i}return n}function Uf(t,e,r){let n=r.useMaps===!0,o=n?void 0:{},i=n?new Map:void 0;for(let s=0;s<t.value;s++){let a=lt(e,r);if(a===Sr){if(t.value===1/0)break;throw new Error(`${x} got unexpected break to lengthed map`)}if(a===Mt)throw new Error(`${x} found map but not enough entries (got ${s} [no key], expected ${t.value})`);if(n!==!0&&typeof a!="string")throw new Error(`${x} non-string keys not supported (got ${typeof a})`);if(r.rejectDuplicateMapKeys===!0&&(n&&i.has(a)||!n&&a in o))throw new Error(`${x} found repeat map key "${a}"`);let f=lt(e,r);if(f===Mt)throw new Error(`${x} found map but not enough entries (got ${s} [no value], expected ${t.value})`);n?i.set(a,f):o[a]=f}return n?i:o}function lt(t,e){if(t.done())return Mt;let r=t.next();if(r.type===l.break)return Sr;if(r.type.terminal)return r.value;if(r.type===l.array)return kf(r,t,e);if(r.type===l.map)return Uf(r,t,e);if(r.type===l.tag){if(e.tags&&typeof e.tags[r.value]=="function"){let n=lt(t,e);return e.tags[r.value](n)}throw new Error(`${x} tag not supported (${r.value})`)}throw new Error("unsupported")}function ks(t,e){if(!(t instanceof Uint8Array))throw new Error(`${x} data to decode must be a Uint8Array`);e=Object.assign({},Ff,e);let r=e.tokenizer||new _r(t,e),n=lt(r,e);if(n===Mt)throw new Error(`${x} did not find any content to decode`);if(n===Sr)throw new Error(`${x} got unexpected break`);return[n,t.subarray(r.pos())]}function Gn(t,e){let[r,n]=ks(t,e);if(n.length>0)throw new Error(`${x} too many terminals, data makes no sense`);return r}var Cr=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},dt=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},Lr=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"},Ot=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};function Ir(t){return t[Symbol.asyncIterator]!=null}function Us(t,e){if(t.byteLength>e)throw new dt("Message length too long")}var Tr=t=>{let e=N(t),r=ee(e);return Xt(t,r),Tr.bytes=e,r};Tr.bytes=0;function Dr(t,e){e=e??{};let r=e.lengthEncoder??Tr,n=e?.maxDataLength??4194304;function*o(i){Us(i,n);let s=r(i.byteLength);s instanceof Uint8Array?yield s:yield*s,i instanceof Uint8Array?yield i:yield*i}return Ir(t)?(async function*(){for await(let i of t)yield*o(i)})():(function*(){for(let i of t)yield*o(i)})()}Dr.single=(t,e)=>{e=e??{};let r=e.lengthEncoder??Tr,n=e?.maxDataLength??4194304;return Us(t,n),new C(r(t.byteLength),t)};var Re;(function(t){t[t.LENGTH=0]="LENGTH",t[t.DATA=1]="DATA"})(Re||(Re={}));var Hn=t=>{let e=he(t);return Hn.bytes=N(e),e};Hn.bytes=0;function Rt(t,e){let r=new C,n=Re.LENGTH,o=-1,i=e?.lengthDecoder??Hn,s=e?.maxLengthLength??8,a=e?.maxDataLength??4194304;function*f(){for(;r.byteLength>0;){if(n===Re.LENGTH)try{if(o=i(r),o<0)throw new Cr("Invalid message length");if(o>a)throw new dt("Message length too long");let c=i.bytes;r.consume(c),e?.onLength!=null&&e.onLength(o),n=Re.DATA}catch(c){if(c instanceof RangeError){if(r.byteLength>s)throw new Lr("Message length length too long");break}throw c}if(n===Re.DATA){if(r.byteLength<o)break;let c=r.sublist(0,o);r.consume(o),e?.onData!=null&&e.onData(c),yield c,n=Re.LENGTH}}}return Ir(t)?(async function*(){for await(let c of t)r.append(c),yield*f();if(r.byteLength>0)throw new Ot("Unexpected end of input")})():(function*(){for(let c of t)r.append(c),yield*f();if(r.byteLength>0)throw new Ot("Unexpected end of input")})()}Rt.fromReader=(t,e)=>{let r=1,n=(async function*(){for(;;)try{let{done:i,value:s}=await t.next(r);if(i===!0)return;s!=null&&(yield s)}catch(i){if(i.code==="ERR_UNDER_READ")return{done:!0,value:null};throw i}finally{r=1}})();return Rt(n,{...e??{},onLength:i=>{r=i}})};var Kn=class extends Pe{sendMessage;dataQueue;encoding;constructor(e){super(e),this.sendMessage=e.sendMessage,this.encoding=e.encoding,this.dataQueue=new ne({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()}},Bs=30,Qn=class extends Dt{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)+Bs,this.encoding=r.encoding??"base64",this.input=ue(),this.sendMessage=this.sendMessage.bind(this),this.nextStreamId=this.maConn.direction==="outbound"?0:1,Promise.resolve().then(async()=>{for await(let n of Rt(this.input,{maxDataLength:this.maxMessageSize}))this.onMessage(Gn(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=Wn(e),n=Dr.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 Kn({...this.streamOptions,...n,id:e,direction:r,log:this.log.newScope(`stream:${r}:${e}`),sendMessage:this.sendMessage,encoding:this.encoding,maxMessageSize:this.maxMessageSize-Bs,protocol:""})}},Xn=class{protocol="/mock-muxer/1.0.0";init;constructor(e){this.init=e}createStreamMuxer(e){return new Qn(e,{...this.init})}};function Fr(t={}){return new Xn(t)}function Mf(t,e){if(typeof t=="string")return Of(t);if(typeof t=="number")return zf(t,e);throw Error(`Value provided to ms() must be a string or number. value=${JSON.stringify(t)}`)}var kr=Mf;function Of(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),i=n.toLowerCase();switch(i){case"years":case"year":case"yrs":case"yr":case"y":return o*315576e5;case"months":case"month":case"mo":return o*26298e5;case"weeks":case"week":case"w":return o*6048e5;case"days":case"day":case"d":return o*864e5;case"hours":case"hour":case"hrs":case"hr":case"h":return o*36e5;case"minutes":case"minute":case"mins":case"min":case"m":return o*6e4;case"seconds":case"second":case"secs":case"sec":case"s":return o*1e3;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return o;default:throw Error(`Unknown unit "${i}" provided to ms.parse(). value=${JSON.stringify(t)}`)}}function Rf(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 $f(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 zf(t,e){if(typeof t!="number"||!Number.isFinite(t))throw Error("Value provided to ms.format() must be of type number.");return e?.long?$f(t):Rf(t)}function $e(t,e,r,n){let o=e>=r*1.5;return`${Math.round(t/r)} ${n}${o?"s":""}`}function Jn(t){r.debug=r,r.default=r,r.coerce=f,r.disable=i,r.enable=o,r.enabled=s,r.humanize=kr,r.destroy=c,Object.keys(t).forEach(u=>{r[u]=t[u]}),r.names=[],r.skips=[],r.formatters={};function e(u){let d=0;for(let h=0;h<u.length;h++)d=(d<<5)-d+u.charCodeAt(h),d|=0;return r.colors[Math.abs(d)%r.colors.length]}r.selectColor=e;function r(u){let d,h=null,g,b;function w(...y){if(!w.enabled)return;let _=w,L=Number(new Date),I=L-(d||L);_.diff=I,_.prev=d,_.curr=L,d=L,y[0]=r.coerce(y[0]),typeof y[0]!="string"&&y.unshift("%O");let A=0;y[0]=y[0].replace(/%([a-zA-Z%])/g,(Q,z)=>{if(Q==="%%")return"%";A++;let X=r.formatters[z];if(typeof X=="function"){let ze=y[A];Q=X.call(_,ze),y.splice(A,1),A--}return Q}),r.formatArgs.call(_,y),(_.log||r.log).apply(_,y)}return w.namespace=u,w.useColors=r.useColors(),w.color=r.selectColor(u),w.extend=n,w.destroy=r.destroy,Object.defineProperty(w,"enabled",{enumerable:!0,configurable:!1,get:()=>h!==null?h:(g!==r.namespaces&&(g=r.namespaces,b=r.enabled(u)),b),set:y=>{h=y}}),typeof r.init=="function"&&r.init(w),w}function n(u,d){let h=r(this.namespace+(typeof d>"u"?":":d)+u);return h.log=this.log,h}function o(u){r.save(u),r.namespaces=u,r.names=[],r.skips=[];let d,h=(typeof u=="string"?u:"").split(/[\s,]+/),g=h.length;for(d=0;d<g;d++)h[d]&&(u=h[d].replace(/\*/g,".*?"),u[0]==="-"?r.skips.push(new RegExp("^"+u.substr(1)+"$")):r.names.push(new RegExp("^"+u+"$")))}function i(){let u=[...r.names.map(a),...r.skips.map(a).map(d=>"-"+d)].join(",");return r.enable(""),u}function s(u){if(u[u.length-1]==="*")return!0;let d,h;for(d=0,h=r.skips.length;d<h;d++)if(r.skips[d].test(u))return!1;for(d=0,h=r.names.length;d<h;d++)if(r.names[d].test(u))return!0;return!1}function a(u){return u.toString().substring(2,u.toString().length-2).replace(/\.\*\?$/,"*")}function f(u){return u instanceof Error?u.stack??u.message:u}function c(){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 Ur=Kf(),Vf=["#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 qf(){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 jf(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 Wf=console.debug??console.log??(()=>{});function Gf(t){try{t?Ur?.setItem("debug",t):Ur?.removeItem("debug")}catch{}}function Hf(){let t;try{t=Ur?.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 Qf(t){t.j=function(e){try{return JSON.stringify(e)}catch(r){return"[UnexpectedJSONParseError]: "+r.message}}}var Ps=Jn({formatArgs:jf,save:Gf,load:Hf,useColors:qf,setupFormatters:Qf,colors:Vf,storage:Ur,log:Wf});var R=Ps;R.formatters.b=t=>t==null?"undefined":J.baseEncode(t);R.formatters.t=t=>t==null?"undefined":ce.baseEncode(t);R.formatters.m=t=>t==null?"undefined":Xr.baseEncode(t);R.formatters.p=t=>t==null?"undefined":t.toString();R.formatters.c=t=>t==null?"undefined":t.toString();R.formatters.k=t=>t==null?"undefined":t.toString();R.formatters.a=t=>t==null?"undefined":t.toString();R.formatters.e=t=>{if(t==null)return"undefined";let e=Ns(t.message),r=Ns(t.stack);return e!=null&&r!=null?r.includes(e)?r:`${e}
|
|
3
|
-
${r}`:r??e??t.toString()};function Xf(t){let e=()=>{};return e.enabled=!1,e.color="",e.diff=0,e.log=()=>{},e.namespace=t,e.destroy=()=>!0,e.extend=()=>e,e}function $t(){return{forComponent(t){return Ms(t)}}}function Ms(t){let e=Xf(`${t}:trace`);return R.enabled(`${t}:trace`)&&R.names.map(r=>r.toString()).find(r=>r.includes(":trace"))!=null&&(e=R(`${t}:trace`)),Object.assign(R(t),{error:R(`${t}:error`),trace:e,newScope:r=>Ms(`${t}:${r}`)})}function Ns(t){if(t!=null&&(t=t.trim(),t.length!==0))return t}var Jf=0,Zn=class extends Pe{local;remote;constructor(e){let r=`${Jf++}`;super({...e,id:r,log:$t().forComponent(`libp2p:stream-pair:${e.direction}:${r}`)}),this.local=e.local,this.remote=e.remote,this.local.addEventListener("drain",()=>{this.safeDispatchEvent("drain")}),this.remote.addEventListener("message",n=>{this.onData(n.data)}),this.remote.addEventListener("reset",n=>{this.onRemoteReset()}),this.remote.addEventListener("closeWrite",n=>{this.onRemoteCloseWrite()})}sendData(e){let r=this.local.send(new se(e));return{sentBytes:e.byteLength,canSendMore:r}}sendReset(){this.local.send(new Event("reset"))}async sendCloseWrite(e){return O(new Promise((r,n)=>{this.local.send(new Event("closeWrite")),this.local.onIdle().then(r,n)}),e?.signal)}async sendCloseRead(e){return O(new Promise((r,n)=>{this.local.send(new Event("closeRead")),this.local.onIdle().then(r,n)}),e?.signal)}sendPause(){this.local.send(new Event("pause"))}sendResume(){this.local.send(new Event("resume"))}onRemotePaused(){this.local.pause()}onRemoteResumed(){this.local.resume()}onMuxerDrain(){this.local.resume()}};var Os=()=>{let t=new Error("Delay aborted");return t.name="AbortError",t},Zf=new WeakMap;function Yf({clearTimeout:t,setTimeout:e}={}){return(r,{value:n,signal:o}={})=>{if(o?.aborted)return Promise.reject(Os());let i,s,a,f=t??clearTimeout,c=()=>{f(i),a(Os())},u=()=>{o&&o.removeEventListener("abort",c)},d=new Promise((h,g)=>{s=()=>{u(),h(n)},a=g,i=(e??setTimeout)(s,r)});return o&&o.addEventListener("abort",c,{once:!0}),Zf.set(d,()=>{f(i),i=null,s()}),d}}var el=Yf(),Yn=el;var tl=1024*64,zt=class extends ae{needsDrain;queue;capacity;delay;log;chunkSize;constructor(e){super(),this.needsDrain=!1,this.queue=new ne({concurrency:1}),this.capacity=e.capacity??5,this.delay=e.delay??0,this.log=e.log,this.chunkSize=e.chunkSize??tl,this.queue.addEventListener("idle",()=>{this.needsDrain?(this.log("network send queue drained"),this.needsDrain=!1,this.safeDispatchEvent("drain")):this.log("network send queue idle")})}send(e){if(rl(e)){let r=new C(e.data);for(;r.byteLength>0;){let n=Math.min(this.chunkSize,r.byteLength),o=r.sublist(0,n);r.consume(o.byteLength);let i=new se(o);this.queue.add(async s=>{this.delay>0&&await O(Yn(this.delay),s.signal),this.dispatchEvent(s.evt)},{evt:i})}}else this.queue.add(async r=>{this.delay>0&&await O(Yn(this.delay),r.signal),this.dispatchEvent(r.evt)},{evt:e});return this.queue.size>=this.capacity?(this.log("network send queue full"),this.needsDrain=!0,!1):!0}pause(){this.queue.pause()}resume(){this.queue.resume()}onIdle(){return this.queue.onIdle()}size(){return this.queue.size}};function rl(t){return t?.data instanceof Uint8Array||Xe(t?.data)}var Rs=0,Br=class extends Tt{local;remote;constructor(e){super(e),this.local=e.local,this.remote=e.remote,this.local.addEventListener("drain",()=>{this.safeDispatchEvent("drain")}),this.remote.addEventListener("message",r=>{this.status==="open"&&this.onData(r.data)}),this.remote.addEventListener("reset",r=>{this.status==="open"&&this.onRemoteReset()}),this.remote.addEventListener("close",r=>{this.onTransportClosed()}),this.remote.addEventListener("pause",r=>{this.local.pause()}),this.remote.addEventListener("resume",r=>{this.local.resume()})}sendData(e){let r=this.local.send(new se(e));return{sentBytes:e.byteLength,canSendMore:r}}sendReset(){this.local.send(new Event("reset"))}async sendClose(e){return this.local.needsDrain&&await D(this.local,"drain",{signal:e?.signal}),O(new Promise((r,n)=>{this.local.send(new Event("close")),this.local.onIdle().then(r,n)}),e?.signal)}sendPause(){this.local.send(new Event("pause"))}sendResume(){this.local.send(new Event("resume"))}};function eo(t={}){let e=`${Rs++}`,r=`${Rs++}`,n=$t().forComponent(`libp2p:mock-maconn:outbound:${e}`),o=$t().forComponent(`libp2p:mock-maconn:inbound:${r}`),i=new zt({...t,log:n}),s=new zt({...t,log:o});return[new Br({...t.outbound,id:r,direction:"outbound",local:i,remote:s,remoteAddr:t?.outbound?.remoteAddr??Se(`/ip4/127.0.0.1/tcp/${r}`),log:n}),new Br({...t.inbound,id:e,direction:"inbound",local:s,remote:i,remoteAddr:t?.inbound?.remoteAddr??Se(`/ip4/127.0.0.1/tcp/${e}`),log:o})]}var to=class extends ne{has(e){return this.find(e)!=null}find(e){return this.queue.find(r=>e.equals(r.options.peerId))}};var ro=class extends ne{constructor(e={}){super({...e,sort:(r,n)=>r.options.priority>n.options.priority?-1:r.options.priority<n.options.priority?1:0})}};var no=class{memoryStorage;points;duration;blockDuration;keyPrefix;constructor(e={}){this.points=e.points??4,this.duration=e.duration??1,this.blockDuration=e.blockDuration??0,this.keyPrefix=e.keyPrefix??"rlflx",this.memoryStorage=new Pr}consume(e,r=1,n={}){let o=this.getKey(e),i=this._getKeySecDuration(n),s=this.memoryStorage.incrby(o,r,i);if(s.remainingPoints=Math.max(this.points-s.consumedPoints,0),s.consumedPoints>this.points)throw this.blockDuration>0&&s.consumedPoints<=this.points+r&&(s=this.memoryStorage.set(o,s.consumedPoints,this.blockDuration)),new Lt("Rate limit exceeded",s);return s}penalty(e,r=1,n={}){let o=this.getKey(e),i=this._getKeySecDuration(n),s=this.memoryStorage.incrby(o,r,i);return s.remainingPoints=Math.max(this.points-s.consumedPoints,0),s}reward(e,r=1,n={}){let o=this.getKey(e),i=this._getKeySecDuration(n),s=this.memoryStorage.incrby(o,-r,i);return s.remainingPoints=Math.max(this.points-s.consumedPoints,0),s}block(e,r){let n=r*1e3,o=this.points+1;return this.memoryStorage.set(this.getKey(e),o,r),{remainingPoints:0,msBeforeNext:n===0?-1:n,consumedPoints:o,isFirstInDuration:!1}}set(e,r,n=0){let o=(n>=0?n:this.duration)*1e3;return this.memoryStorage.set(this.getKey(e),r,n),{remainingPoints:0,msBeforeNext:o===0?-1:o,consumedPoints:r,isFirstInDuration:!1}}get(e){let r=this.memoryStorage.get(this.getKey(e));return r!=null&&(r.remainingPoints=Math.max(this.points-r.consumedPoints,0)),r}delete(e){this.memoryStorage.delete(this.getKey(e))}_getKeySecDuration(e){return e?.customDuration!=null&&e.customDuration>=0?e.customDuration:this.duration}getKey(e){return this.keyPrefix.length>0?`${this.keyPrefix}:${e}`:e}parseKey(e){return e.substring(this.keyPrefix.length)}},Pr=class{storage;constructor(){this.storage=new Map}incrby(e,r,n){let o=this.storage.get(e);if(o!=null){let i=o.expiresAt!=null?o.expiresAt.getTime()-new Date().getTime():-1;return o.expiresAt==null||i>0?(o.value+=r,{remainingPoints:0,msBeforeNext:i,consumedPoints:o.value,isFirstInDuration:!1}):this.set(e,r,n)}return this.set(e,r,n)}set(e,r,n){let o=n*1e3,i=this.storage.get(e);i!=null&&clearTimeout(i.timeoutId);let s={value:r,expiresAt:o>0?new Date(Date.now()+o):void 0};return this.storage.set(e,s),o>0&&(s.timeoutId=setTimeout(()=>{this.storage.delete(e)},o),s.timeoutId.unref!=null&&s.timeoutId.unref()),{remainingPoints:0,msBeforeNext:o===0?-1:o,consumedPoints:s.value,isFirstInDuration:!0}}get(e){let r=this.storage.get(e);if(r!=null)return{remainingPoints:0,msBeforeNext:r.expiresAt!=null?r.expiresAt.getTime()-new Date().getTime():-1,consumedPoints:r.value,isFirstInDuration:!1}}delete(e){let r=this.storage.get(e);return r!=null?(r.timeoutId!=null&&clearTimeout(r.timeoutId),this.storage.delete(e),!0):!1}};function nl(t,e,r){let n,o,i=!1;function s(){let c={signal:o.signal};if(r?.timeout!=null){let u=ir([o.signal,AbortSignal.timeout(r.timeout)]);c.signal=u}i=!0,Promise.resolve().then(async()=>{await t(c)}).catch(()=>{}).finally(()=>{i=!1,!o.signal.aborted&&(n=setTimeout(s,e))})}let a=et(s,r?.debounce??100),f=!1;return{setInterval:c=>{e!==c&&(e=c,n!=null&&(clearTimeout(n),n=setTimeout(s,e)))},setTimeout:c=>{r??={},r.timeout=c},run:()=>{i||(clearTimeout(n),a())},start:()=>{f||(f=!0,o=new AbortController,o.signal,r?.runImmediately===!0?queueMicrotask(()=>{s()}):n=setTimeout(s,e))},stop:()=>{clearTimeout(n),o?.abort(),f=!1}}}async function $s(t={}){let[e,r]=eo({...t,outbound:t.outboundConnection,inbound:t.inboundConnection}),n=Fr({streamOptions:t.outbound}).createStreamMuxer(e),o=Fr({streamOptions:t.inbound}).createStreamMuxer(r),[i,s]=await Promise.all([D(o,"stream").then(a=>a.detail),n.createStream({...t.outbound,protocol:t.protocol})]);return[s,i]}async function ol(t={}){let[e,r]=await $s(t);return Pn(r),e}function il(
|
|
2
|
+
"use strict";var Libp2PUtils=(()=>{var zs=Object.create;var Vt=Object.defineProperty;var Vs=Object.getOwnPropertyDescriptor;var qs=Object.getOwnPropertyNames;var js=Object.getPrototypeOf,Ws=Object.prototype.hasOwnProperty;var Gs=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),V=(t,e)=>{for(var r in e)Vt(t,r,{get:e[r],enumerable:!0})},io=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of qs(e))!Ws.call(t,o)&&o!==r&&Vt(t,o,{get:()=>e[o],enumerable:!(n=Vs(e,o))||n.enumerable});return t};var Hs=(t,e,r)=>(r=t!=null?zs(js(t)):{},io(e||!t||!t.__esModule?Vt(r,"default",{value:t,enumerable:!0}):r,t)),Ks=t=>io(Vt({},"__esModule",{value:!0}),t);var jo=Gs(Ct=>{(function(){var t,e,r,n,o,i,s,a;a=function(f){var c,u,d,h;return c=(f&255<<24)>>>24,u=(f&255<<16)>>>16,d=(f&65280)>>>8,h=f&255,[c,u,d,h].join(".")},s=function(f){var c,u,d,h,g,b;for(c=[],d=h=0;h<=3&&f.length!==0;d=++h){if(d>0){if(f[0]!==".")throw new Error("Invalid IP");f=f.substring(1)}b=e(f),g=b[0],u=b[1],f=f.substring(u),c.push(g)}if(f.length!==0)throw new Error("Invalid IP");switch(c.length){case 1:if(c[0]>4294967295)throw new Error("Invalid IP");return c[0]>>>0;case 2:if(c[0]>255||c[1]>16777215)throw new Error("Invalid IP");return(c[0]<<24|c[1])>>>0;case 3:if(c[0]>255||c[1]>255||c[2]>65535)throw new Error("Invalid IP");return(c[0]<<24|c[1]<<16|c[2])>>>0;case 4:if(c[0]>255||c[1]>255||c[2]>255||c[3]>255)throw new Error("Invalid IP");return(c[0]<<24|c[1]<<16|c[2]<<8|c[3])>>>0;default:throw new Error("Invalid IP")}},r=function(f){return f.charCodeAt(0)},n=r("0"),i=r("a"),o=r("A"),e=function(f){var c,u,d,h,g;for(h=0,c=10,u="9",d=0,f.length>1&&f[d]==="0"&&(f[d+1]==="x"||f[d+1]==="X"?(d+=2,c=16):"0"<=f[d+1]&&f[d+1]<="9"&&(d++,c=8,u="7")),g=d;d<f.length;){if("0"<=f[d]&&f[d]<=u)h=h*c+(r(f[d])-n)>>>0;else if(c===16)if("a"<=f[d]&&f[d]<="f")h=h*c+(10+r(f[d])-i)>>>0;else if("A"<=f[d]&&f[d]<="F")h=h*c+(10+r(f[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 f(c,u){var d,h,g,b;if(typeof c!="string")throw new Error("Missing `net' parameter");if(u||(b=c.split("/",2),c=b[0],u=b[1]),u||(u=32),typeof u=="string"&&u.indexOf(".")>-1){try{this.maskLong=s(u)}catch(w){throw d=w,new Error("Invalid mask: "+u)}for(h=g=32;g>=0;h=--g)if(this.maskLong===4294967295<<32-h>>>0){this.bitmask=h;break}}else if(u||u===0)this.bitmask=parseInt(u,10),this.maskLong=0,this.bitmask>0&&(this.maskLong=4294967295<<32-this.bitmask>>>0);else throw new Error("Invalid mask: empty");try{this.netLong=(s(c)&this.maskLong)>>>0}catch(w){throw d=w,new Error("Invalid net address: "+c)}if(!(this.bitmask<=32))throw new Error("Invalid mask for ip4: "+u);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 f.prototype.contains=function(c){return typeof c=="string"&&(c.indexOf("/")>0||c.split(".").length!==4)&&(c=new f(c)),c instanceof f?this.contains(c.base)&&this.contains(c.broadcast||c.last):(s(c)&this.maskLong)>>>0===(this.netLong&this.maskLong)>>>0},f.prototype.next=function(c){return c==null&&(c=1),new f(a(this.netLong+this.size*c),this.mask)},f.prototype.forEach=function(c){var u,d,h;for(h=s(this.first),d=s(this.last),u=0;h<=d;)c(a(h),h,u),u++,h++},f.prototype.toString=function(){return this.base+"/"+this.bitmask},f})(),Ct.ip2long=s,Ct.long2ip=a,Ct.Netmask=t}).call(Ct)});var al={};V(al,{AbstractMessageStream:()=>Be,AbstractMultiaddrConnection:()=>Tt,AbstractStream:()=>Pe,AbstractStreamMuxer:()=>Dt,AdaptiveTimeout:()=>Sn,BloomFilter:()=>Et,CuckooFilter:()=>we,DEFAULT_FAILURE_MULTIPLIER:()=>Qo,DEFAULT_INTERVAL:()=>Zo,DEFAULT_MAX_TIMEOUT:()=>Jo,DEFAULT_MIN_TIMEOUT:()=>Xo,DEFAULT_TIMEOUT_MULTIPLIER:()=>Ko,InvalidDataLengthError:()=>fr,InvalidDataLengthLengthError:()=>lr,InvalidMessageLengthError:()=>rt,LengthPrefixedDecoder:()=>Nn,MaxEarlyStreamsError:()=>At,MemoryStorage:()=>Pr,MockStream:()=>Zn,MovingAverage:()=>Ne,PeerQueue:()=>to,PriorityQueue:()=>ro,Queue:()=>ne,QueueFullError:()=>It,RateLimitError:()=>Lt,RateLimiter:()=>no,ScalableCuckooFilter:()=>vt,UnexpectedEOFError:()=>_e,UnwrappedError:()=>kt,byteStream:()=>vi,createBloomFilter:()=>Bo,createCuckooFilter:()=>Po,createScalableCuckooFilter:()=>No,debounce:()=>et,echo:()=>Pn,echoStream:()=>ol,getNetConfig:()=>j,getThinWaistAddresses:()=>Du,ipPortToMultiaddr:()=>ku,isAsyncGenerator:()=>Uu,isGenerator:()=>Bu,isGlobalUnicast:()=>bc,isGlobalUnicastIp:()=>Fu,isLinkLocal:()=>wc,isLinkLocalIp:()=>Ju,isLoopback:()=>Ec,isNetworkAddress:()=>vc,isPrivate:()=>Dc,isPrivateIp:()=>xn,isPromise:()=>_n,lpStream:()=>_i,mergeOptions:()=>nf,messageStreamToDuplex:()=>Si,mockMuxer:()=>Fr,multiaddrConnectionPair:()=>eo,pbStream:()=>Gu,pipe:()=>Ku,repeatingTask:()=>nl,streamPair:()=>$s,trackedList:()=>il,trackedMap:()=>sl});var le=class extends Error{static name="AbortError";constructor(e="The operation was aborted"){super(e),this.name="AbortError"}};var M=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"}},jt=class extends Error{static name="StreamResetError";constructor(e="The stream has been reset"){super(e),this.name="StreamResetError"}};var Ie=class extends Error{static name="StreamStateError";constructor(e="The stream is in an invalid state"){super(e),this.name="StreamStateError"}},ht=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}},Ve=class extends Event{error;local;constructor(e,r,n){super("close",n),this.error=r,this.local=e}},Wt=class extends Ve{constructor(e,r){super(!0,e,r)}},Gt=class extends Ve{constructor(e,r){super(!1,e,r)}};var ae=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:i})=>i!==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 $r={};V($r,{base58btc:()=>J,base58flickr:()=>ta});var dl=new Uint8Array(0);function so(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 de(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 ao(t){return new TextEncoder().encode(t)}function co(t){return new TextDecoder().decode(t)}function Qs(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 i=t.charAt(o),s=i.charCodeAt(0);if(r[s]!==255)throw new TypeError(i+" is ambiguous");r[s]=o}var a=t.length,f=t.charAt(0),c=Math.log(a)/Math.log(256),u=Math.log(256)/Math.log(a);function d(b){if(b instanceof Uint8Array||(ArrayBuffer.isView(b)?b=new Uint8Array(b.buffer,b.byteOffset,b.byteLength):Array.isArray(b)&&(b=Uint8Array.from(b))),!(b instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(b.length===0)return"";for(var w=0,y=0,_=0,L=b.length;_!==L&&b[_]===0;)_++,w++;for(var I=(L-_)*u+1>>>0,A=new Uint8Array(I);_!==L;){for(var $=b[_],Q=0,z=I-1;($!==0||Q<y)&&z!==-1;z--,Q++)$+=256*A[z]>>>0,A[z]=$%a>>>0,$=$/a>>>0;if($!==0)throw new Error("Non-zero carry");y=Q,_++}for(var X=I-y;X!==I&&A[X]===0;)X++;for(var ze=f.repeat(w);X<I;++X)ze+=t.charAt(A[X]);return ze}function h(b){if(typeof b!="string")throw new TypeError("Expected String");if(b.length===0)return new Uint8Array;var w=0;if(b[w]!==" "){for(var y=0,_=0;b[w]===f;)y++,w++;for(var L=(b.length-w)*c+1>>>0,I=new Uint8Array(L);b[w];){var A=r[b.charCodeAt(w)];if(A===255)return;for(var $=0,Q=L-1;(A!==0||$<_)&&Q!==-1;Q--,$++)A+=a*I[Q]>>>0,I[Q]=A%256>>>0,A=A/256>>>0;if(A!==0)throw new Error("Non-zero carry");_=$,w++}if(b[w]!==" "){for(var z=L-_;z!==L&&I[z]===0;)z++;for(var X=new Uint8Array(y+(L-z)),ze=y;z!==L;)X[ze++]=I[z++];return X}}}function g(b){var w=h(b);if(w)return w;throw new Error(`Non-${e} character`)}return{encode:d,decodeUnsafe:h,decode:g}}var Xs=Qs,Js=Xs,fo=Js;var Nr=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")}},Mr=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 lo(this,e)}},Or=class{decoders;constructor(e){this.decoders=e}or(e){return lo(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 lo(t,e){return new Or({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var Rr=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 Nr(e,r,n),this.decoder=new Mr(e,r,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function qe({name:t,prefix:e,encode:r,decode:n}){return new Rr(t,e,r,n)}function ye({name:t,prefix:e,alphabet:r}){let{encode:n,decode:o}=fo(r,t);return qe({prefix:e,name:t,encode:n,decode:i=>de(o(i))})}function Zs(t,e,r,n){let o=t.length;for(;t[o-1]==="=";)--o;let i=new Uint8Array(o*r/8|0),s=0,a=0,f=0;for(let c=0;c<o;++c){let u=e[t[c]];if(u===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|u,s+=r,s>=8&&(s-=8,i[f++]=255&a>>s)}if(s>=r||(255&a<<8-s)!==0)throw new SyntaxError("Unexpected end of data");return i}function Ys(t,e,r){let n=e[e.length-1]==="=",o=(1<<r)-1,i="",s=0,a=0;for(let f=0;f<t.length;++f)for(a=a<<8|t[f],s+=8;s>r;)s-=r,i+=e[o&a>>s];if(s!==0&&(i+=e[o&a<<r-s]),n)for(;(i.length*r&7)!==0;)i+="=";return i}function ea(t){let e={};for(let r=0;r<t.length;++r)e[t[r]]=r;return e}function S({name:t,prefix:e,bitsPerChar:r,alphabet:n}){let o=ea(n);return qe({prefix:e,name:t,encode(i){return Ys(i,n,r)},decode(i){return Zs(i,o,r,t)}})}var J=ye({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),ta=ye({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var zr={};V(zr,{base32:()=>ce,base32hex:()=>ia,base32hexpad:()=>aa,base32hexpadupper:()=>ca,base32hexupper:()=>sa,base32pad:()=>na,base32padupper:()=>oa,base32upper:()=>ra,base32z:()=>ua});var ce=S({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),ra=S({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),na=S({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),oa=S({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),ia=S({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),sa=S({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),aa=S({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),ca=S({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),ua=S({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Vr={};V(Vr,{base36:()=>pt,base36upper:()=>fa});var pt=ye({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),fa=ye({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var la=mo,ho=128,da=127,ha=~da,pa=Math.pow(2,31);function mo(t,e,r){e=e||[],r=r||0;for(var n=r;t>=pa;)e[r++]=t&255|ho,t/=128;for(;t&ha;)e[r++]=t&255|ho,t>>>=7;return e[r]=t|0,mo.bytes=r-n+1,e}var ma=qr,ga=128,po=127;function qr(t,n){var r=0,n=n||0,o=0,i=n,s,a=t.length;do{if(i>=a)throw qr.bytes=0,new RangeError("Could not decode varint");s=t[i++],r+=o<28?(s&po)<<o:(s&po)*Math.pow(2,o),o+=7}while(s>=ga);return qr.bytes=i-n,r}var ya=Math.pow(2,7),xa=Math.pow(2,14),ba=Math.pow(2,21),wa=Math.pow(2,28),Ea=Math.pow(2,35),va=Math.pow(2,42),_a=Math.pow(2,49),Sa=Math.pow(2,56),Ca=Math.pow(2,63),La=function(t){return t<ya?1:t<xa?2:t<ba?3:t<wa?4:t<Ea?5:t<va?6:t<_a?7:t<Sa?8:t<Ca?9:10},Ia={encode:la,decode:ma,encodingLength:La},Aa=Ia,mt=Aa;function gt(t,e=0){return[mt.decode(t,e),mt.decode.bytes]}function je(t,e,r=0){return mt.encode(t,e,r),e}function We(t){return mt.encodingLength(t)}function He(t,e){let r=e.byteLength,n=We(t),o=n+We(r),i=new Uint8Array(o+r);return je(t,i,0),je(r,i,n),i.set(e,o),new Ge(t,r,e,i)}function go(t){let e=de(t),[r,n]=gt(e),[o,i]=gt(e.subarray(n)),s=e.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new Ge(r,o,s,e)}function yo(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&so(t.bytes,r.bytes)}}var Ge=class{code;size;digest;bytes;constructor(e,r,n,o){this.code=e,this.size=r,this.digest=n,this.bytes=o}};function xo(t,e){let{bytes:r,version:n}=t;switch(n){case 0:return Da(r,jr(t),e??J.encoder);default:return Fa(r,jr(t),e??ce.encoder)}}var bo=new WeakMap;function jr(t){let e=bo.get(t);if(e==null){let r=new Map;return bo.set(t,r),r}return e}var Ke=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!==xt)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==ka)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=He(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&&yo(e.multihash,n.multihash)}toString(e){return xo(this,e)}toJSON(){return{"/":xo(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let r=e;if(r instanceof t)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:i,bytes:s}=r;return new t(n,o,i,s??wo(n,o,i.bytes))}else if(r[Ua]===!0){let{version:n,multihash:o,code:i}=r,s=go(o);return t.create(n,i,s)}else return null}static create(e,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(r!==xt)throw new Error(`Version 0 CID must use dag-pb (code: ${xt}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let o=wo(e,r,n.bytes);return new t(e,r,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,xt,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=de(e.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let i=o.subarray(r.multihashSize-r.digestSize),s=new Ge(r.multihashCode,r.digestSize,i,o);return[r.version===0?t.createV0(s):t.createV1(r.codec,s),e.subarray(r.size)]}static inspectBytes(e){let r=0,n=()=>{let[d,h]=gt(e.subarray(r));return r+=h,d},o=n(),i=xt;if(o===18?(o=0,r=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let s=r,a=n(),f=n(),c=r+f,u=c-s;return{version:o,codec:i,multihashCode:a,digestSize:f,multihashSize:u,size:c}}static parse(e,r){let[n,o]=Ta(e,r),i=t.decode(o);if(i.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return jr(i).set(n,e),i}};function Ta(t,e){switch(t[0]){case"Q":{let r=e??J;return[J.prefix,r.decode(`${J.prefix}${t}`)]}case J.prefix:{let r=e??J;return[J.prefix,r.decode(t)]}case ce.prefix:{let r=e??ce;return[ce.prefix,r.decode(t)]}case pt.prefix:{let r=e??pt;return[pt.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 Da(t,e,r){let{prefix:n}=r;if(n!==J.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=e.get(n);if(o==null){let i=r.encode(t).slice(1);return e.set(n,i),i}else return o}function Fa(t,e,r){let{prefix:n}=r,o=e.get(n);if(o==null){let i=r.encode(t);return e.set(n,i),i}else return o}var xt=112,ka=18;function wo(t,e,r){let n=We(t),o=n+We(e),i=new Uint8Array(o+r.byteLength);return je(t,i,0),je(e,i,n),i.set(r,o),i}var Ua=Symbol.for("@ipld/js-cid/CID");var Wr={};V(Wr,{identity:()=>Na});var Eo=0,Ba="identity",vo=de;function Pa(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 He(Eo,vo(t))}var Na={code:Eo,name:Ba,encode:vo,digest:Pa};function Qe(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 q(t=0){return new Uint8Array(t)}function ee(t=0){return new Uint8Array(t)}function xe(t,e){e==null&&(e=t.reduce((o,i)=>o+i.length,0));let r=ee(e),n=0;for(let o of t)r.set(o,n),n+=o.length;return r}var So=Symbol.for("@achingbrain/uint8arraylist");function _o(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 Xe(t){return!!t?.[So]}var C=class t{bufs;length;[So]=!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(Xe(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(Xe(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=_o(this.bufs,e);return r.buf[r.index]}set(e,r){let n=_o(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(Xe(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 xe(n,o)}subarray(e,r){let{bufs:n,length:o}=this._subList(e,r);return n.length===1?n[0]:xe(n,o)}sublist(e,r){let{bufs:n,length:o}=this._subList(e,r),i=new t;return i.length=o,i.bufs=[...n],i}_subList(e,r){if(e=e??0,r=r??this.length,e<0&&(e=this.length+e),r<0&&(r=this.length+r),e<0||r>this.length)throw new RangeError("index is out of bounds");if(e===r)return{bufs:[],length:0};if(e===0&&r===this.length)return{bufs:this.bufs,length:this.length};let n=[],o=0;for(let i=0;i<this.bufs.length;i++){let s=this.bufs[i],a=o,f=a+s.byteLength;if(o=f,e>=f)continue;let c=e>=a&&e<f,u=r>a&&r<=f;if(c&&u){if(e===a&&r===f){n.push(s);break}let d=e-a;n.push(s.subarray(d,d+(r-e)));break}if(c){if(e===0){n.push(s);continue}n.push(s.subarray(e-a));continue}if(u){if(r===f){n.push(s);break}n.push(s.subarray(0,r-a));break}n.push(s)}return{bufs:n,length:r-e}}indexOf(e,r=0){if(!Xe(e)&&!(e instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=e instanceof Uint8Array?e:e.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),e.length===0)return r>this.length?this.length:r;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let i=256,s=new Int32Array(i);for(let d=0;d<i;d++)s[d]=-1;for(let d=0;d<o;d++)s[n[d]]=d;let a=s,f=this.byteLength-n.byteLength,c=n.byteLength-1,u;for(let d=r;d<=f;d+=u){u=0;for(let h=c;h>=0;h--){let g=this.get(d+h);if(n[h]!==g){u=Math.max(1,h-a[g]);break}}if(u===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=ee(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=q(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=q(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=q(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=ee(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=q(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=q(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=q(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=q(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=q(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(!Qe(this.bufs[r],e.bufs[r]))return!1;return!0}static fromUint8Arrays(e,r){let n=new t;return n.bufs=e,r==null&&(r=e.reduce((o,i)=>o+i.byteLength,0)),n.length=r,n}};var Gr={};V(Gr,{base10:()=>Ma});var Ma=ye({prefix:"9",name:"base10",alphabet:"0123456789"});var Hr={};V(Hr,{base16:()=>Oa,base16upper:()=>Ra});var Oa=S({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Ra=S({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Kr={};V(Kr,{base2:()=>$a});var $a=S({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Qr={};V(Qr,{base256emoji:()=>Wa});var Co=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}"),za=Co.reduce((t,e,r)=>(t[r]=e,t),[]),Va=Co.reduce((t,e,r)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return t[n]=r,t},[]);function qa(t){return t.reduce((e,r)=>(e+=za[r],e),"")}function ja(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=Va[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(o)}return new Uint8Array(e)}var Wa=qe({prefix:"\u{1F680}",name:"base256emoji",encode:qa,decode:ja});var Zr={};V(Zr,{base64:()=>Xr,base64pad:()=>Ga,base64url:()=>Jr,base64urlpad:()=>Ha});var Xr=S({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Ga=S({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Jr=S({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Ha=S({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Yr={};V(Yr,{base8:()=>Ka});var Ka=S({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var en={};V(en,{identity:()=>Qa});var Qa=qe({prefix:"\0",name:"identity",encode:t=>co(t),decode:t=>ao(t)});var Ql=new TextEncoder,Xl=new TextDecoder;var nn={};V(nn,{sha256:()=>Ya,sha512:()=>ec});var Za=20;function rn({name:t,code:e,encode:r,minDigestLength:n,maxDigestLength:o}){return new tn(t,e,r,n,o)}var tn=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,r,n,o,i){this.name=e,this.code=r,this.encode=n,this.minDigestLength=o??Za,this.maxDigestLength=i}digest(e,r){if(r?.truncate!=null){if(r.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&r.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(e instanceof Uint8Array){let n=this.encode(e);return n instanceof Uint8Array?Lo(n,this.code,r?.truncate):n.then(o=>Lo(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function Lo(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 He(e,t)}function Ao(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}var Ya=rn({name:"sha2-256",code:18,encode:Ao("SHA-256")}),ec=rn({name:"sha2-512",code:19,encode:Ao("SHA-512")});var bt={...en,...Kr,...Yr,...Gr,...Hr,...zr,...Vr,...$r,...Zr,...Qr},cd={...nn,...Wr};function Do(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var To=Do("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),on=Do("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=ee(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),tc={utf8:To,"utf-8":To,hex:bt.base16,latin1:on,ascii:on,binary:on,...bt},Kt=tc;function T(t,e="utf8"){let r=Kt[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}function Ae(t,e="utf8"){let r=Kt[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.encoder.encode(t).substring(1)}var Te=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function Fo(t=32){if(Te&&typeof Te.getRandomValues=="function")return Te.getRandomValues(new Uint8Array(t));if(Te&&typeof Te.randomBytes=="function")return Uint8Array.from(Te.randomBytes(t));throw new Error("crypto.getRandomValues must be defined")}var rc=Math.pow(2,7),nc=Math.pow(2,14),oc=Math.pow(2,21),sn=Math.pow(2,28),an=Math.pow(2,35),cn=Math.pow(2,42),un=Math.pow(2,49),v=128,P=127;function N(t){if(t<rc)return 1;if(t<nc)return 2;if(t<oc)return 3;if(t<sn)return 4;if(t<an)return 5;if(t<cn)return 6;if(t<un)return 7;if(Number.MAX_SAFE_INTEGER!=null&&t>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Qt(t,e,r=0){switch(N(t)){case 8:e[r++]=t&255|v,t/=128;case 7:e[r++]=t&255|v,t/=128;case 6:e[r++]=t&255|v,t/=128;case 5:e[r++]=t&255|v,t/=128;case 4:e[r++]=t&255|v,t>>>=7;case 3:e[r++]=t&255|v,t>>>=7;case 2:e[r++]=t&255|v,t>>>=7;case 1:{e[r++]=t&255,t>>>=7;break}default:throw new Error("unreachable")}return e}function ic(t,e,r=0){switch(N(t)){case 8:e.set(r++,t&255|v),t/=128;case 7:e.set(r++,t&255|v),t/=128;case 6:e.set(r++,t&255|v),t/=128;case 5:e.set(r++,t&255|v),t/=128;case 4:e.set(r++,t&255|v),t>>>=7;case 3:e.set(r++,t&255|v),t>>>=7;case 2:e.set(r++,t&255|v),t>>>=7;case 1:{e.set(r++,t&255),t>>>=7;break}default:throw new Error("unreachable")}return e}function sc(t,e){let r=t[e],n=0;if(n+=r&P,r<v||(r=t[e+1],n+=(r&P)<<7,r<v)||(r=t[e+2],n+=(r&P)<<14,r<v)||(r=t[e+3],n+=(r&P)<<21,r<v)||(r=t[e+4],n+=(r&P)*sn,r<v)||(r=t[e+5],n+=(r&P)*an,r<v)||(r=t[e+6],n+=(r&P)*cn,r<v)||(r=t[e+7],n+=(r&P)*un,r<v))return n;throw new RangeError("Could not decode varint")}function ac(t,e){let r=t.get(e),n=0;if(n+=r&P,r<v||(r=t.get(e+1),n+=(r&P)<<7,r<v)||(r=t.get(e+2),n+=(r&P)<<14,r<v)||(r=t.get(e+3),n+=(r&P)<<21,r<v)||(r=t.get(e+4),n+=(r&P)*sn,r<v)||(r=t.get(e+5),n+=(r&P)*an,r<v)||(r=t.get(e+6),n+=(r&P)*cn,r<v)||(r=t.get(e+7),n+=(r&P)*un,r<v))return n;throw new RangeError("Could not decode varint")}function Xt(t,e,r=0){return e==null&&(e=ee(N(t))),e instanceof Uint8Array?Qt(t,e,r):ic(t,e,r)}function he(t,e=0){return t instanceof Uint8Array?sc(t,e):ac(t,e)}function Jt(t){if(isNaN(t)||t<=0)throw new M("random bytes length must be a Number bigger than 0");return Fo(t)}var fn={32:16777619n,64:1099511628211n,128:309485009821345068724781371n,256:374144419156711147060143317175368453031918731002211n,512:35835915874844867368919076489095108449946327955754392558399825615420669938882575126094039892345713852759n,1024:5016456510113118655434598811035278955030765345404790744303017523831112055108147451509157692220295382716162651878526895249385292291816524375083746691371804094271873160484737966720260389217684476157468082573n},ko={32:2166136261n,64:14695981039346656037n,128:144066263297769815596495629667062367629n,256:100029257958052580907070968620625704837092796014241193945225284501741471925557n,512:9659303129496669498009435400716310466090418745672637896108374329434462657994582932197716438449813051892206539805784495328239340083876191928701583869517785n,1024:14197795064947621068722070641403218320880622795441933960878474914617582723252296732303717722150864096521202355549365628174669108571814760471015076148029755969804077320157692458563003215304957150157403644460363550505412711285966361610267868082893823963790439336411086884584107735010676915n},Uo=new globalThis.TextEncoder;function cc(t,e){let r=fn[e],n=ko[e];for(let o=0;o<t.length;o++)n^=BigInt(t[o]),n=BigInt.asUintN(e,n*r);return n}function uc(t,e,r){if(r.length===0)throw new Error("The `utf8Buffer` option must have a length greater than zero");let n=fn[e],o=ko[e],i=t;for(;i.length>0;){let s=Uo.encodeInto(i,r);i=i.slice(s.read);for(let a=0;a<s.written;a++)o^=BigInt(r[a]),o=BigInt.asUintN(e,o*n)}return o}function ln(t,{size:e=32,utf8Buffer:r}={}){if(!fn[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 uc(t,e,r);t=Uo.encode(t)}return cc(t,e)}var be={hash:t=>Number(ln(t,{size:32})),hashV:(t,e)=>fc(be.hash(t,e))};function fc(t){let e=t.toString(16);return e.length%2===1&&(e=`0${e}`),T(e,"base16")}var lc=Math.LN2*Math.LN2,Et=class{seeds;bits;buffer;constructor(e={}){e.seeds!=null?this.seeds=e.seeds:this.seeds=hc(e.hashes??8),this.bits=e.bits??1024,this.buffer=q(Math.ceil(this.bits/8))}add(e){typeof e=="string"&&(e=T(e));for(let r=0;r<this.seeds.length;r++){let o=be.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=be.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 Bo(t,e=.005){let r=dc(t,e);return new Et(r)}function dc(t,e=.005){let r=Math.round(-1*t*Math.log(e)/lc),n=Math.round(r/t*Math.LN2);return{bits:r,hashes:n}}function hc(t){let e,r,n=[];for(let o=0;o<t;o++)for(e=new C(Jt(4)),n[o]=e.getUint32(0,!0),r=0;r<o;r++)if(n[o]===n[r]){o--;break}return n}var dn=64,te=class{fp;h;seed;constructor(e,r,n,o=2){if(o>dn)throw new TypeError("Invalid Fingerprint Size");let i=r.hashV(e,n),s=q(o);for(let a=0;a<s.length;a++)s[a]=i[a];s.length===0&&(s[0]=7),this.fp=s,this.h=r,this.seed=n}hash(){return this.h.hash(this.fp,this.seed)}equals(e){return e?.fp instanceof Uint8Array?Qe(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 te))throw new TypeError("Invalid Fingerprint");return this.contents.some(r=>e.equals(r))}add(e){if(!(e instanceof te))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 te))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 te))throw new TypeError("Invalid Fingerprint");let r=this.contents.findIndex(n=>e.equals(n));return r>-1?(this.contents[r]=null,!0):!1}};var pc=500,we=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??be,this.seed=e.seed??De(0,Math.pow(2,10))}add(e){typeof e=="string"&&(e=T(e));let r=new te(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 i=[n,o],s=i[De(0,i.length-1)];this.buckets[s]==null&&(this.buckets[s]=new Fe(this.bucketSize));for(let a=0;a<pc;a++){let f=this.buckets[s].swap(r);if(f!=null&&(s=(s^f.hash())%this.filterSize,this.buckets[s]==null&&(this.buckets[s]=new Fe(this.bucketSize)),this.buckets[s].add(f)))return this.count++,!0}return!1}has(e){typeof e=="string"&&(e=T(e));let r=new te(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 i=(n^r.hash())%this.filterSize;return this.buckets[i]?.has(r)??!1}remove(e){typeof e=="string"&&(e=T(e));let r=new te(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 i=(n^r.hash())%this.filterSize,s=this.buckets[i]?.remove(r)??!1;return s&&this.count--,s}get reliable(){return Math.floor(100*(this.count/this.filterSize))<=90}},mc={1:.5,2:.84,4:.95,8:.98};function gc(t=.001){return t>.002?2:t>1e-5?4:8}function hn(t,e=.001){let r=gc(e),n=mc[r],o=Math.round(t/n),i=Math.min(Math.ceil(Math.log2(1/e)+Math.log2(2*r)),dn);return{filterSize:o,bucketSize:r,fingerprintSize:i}}function Po(t,e=.005){let r=hn(t,e);return new we(r)}var vt=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??be,this.seed=e.seed??De(0,Math.pow(2,10)),this.filterSeries=[new we({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 we({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 No(t,e=.001,r){return new vt({...hn(t,e),...r??{}})}function j(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 M(`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 i=0,s=0,a=this.peekChar();if(a===void 0)return;let f=a==="0",c=2**(8*o)-1;for(;;){let u=this.readAtomically(()=>{let d=this.readChar();if(d===void 0)return;let h=Number.parseInt(d,e);if(!Number.isNaN(h))return h});if(u===void 0)break;if(i*=e,i+=u,i>c||(s+=1,r!==void 0&&s>r))return}if(s!==0)return!n&&f&&s>1?void 0:i})}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 s=this.readSeparator(":",n,()=>this.readIPv4Addr());if(s!==void 0)return r[o]=s[0],r[o+1]=s[1],r[o+2]=s[2],r[o+3]=s[3],[o+4,!0]}let i=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(i===void 0)return[o,!1];r[o]=i>>8,r[o+1]=i&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 i=new Uint8Array(14),s=16-(n+2),[a]=e(i.subarray(0,s));return r.set(i.subarray(0,a),16-a),r})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var Mo=45,yc=15,Je=new Zt;function Yt(t){if(!(t.length>yc))return Je.new(t).parseWith(()=>Je.readIPv4Addr())}function er(t){if(t.includes("%")&&(t=t.split("%")[0]),!(t.length>Mo))return Je.new(t).parseWith(()=>Je.readIPv6Addr())}function Ze(t,e=!1){if(t.includes("%")&&(t=t.split("%")[0]),t.length>Mo)return;let r=Je.new(t).parseWith(()=>Je.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 Oo(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 Ro(t,e,r,n){let o=0;for(let i of t)if(!(o<r)){if(o>n)break;if(i!==e[o])return!1;o++}return!0}function pn(t){switch(t.length){case ke:return t.join(".");case Ue:{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 $o(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 zo(t){let e="0x";for(let r of t)e+=(r>>4).toString(16)+(r&15).toString(16);return e}var ke=4,Ue=16,hh=parseInt("0xFFFF",16),xc=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function _t(t,e){e.length===Ue&&t.length===ke&&Oo(e,0,11)&&(e=e.slice(12)),e.length===ke&&t.length===Ue&&Ro(t,xc,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 Vo(t,e){if(typeof e=="string"&&(e=Ze(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 mn(t){let[e,r]=t.split("/");if(!e||!r)throw new Error("Failed to parse given CIDR: "+t);let n=ke,o=Yt(e);if(o==null&&(n=Ue,o=er(e),o==null))throw new Error("Failed to parse given CIDR: "+t);let i=parseInt(r,10);if(Number.isNaN(i)||String(i).length!==r.length||i<0||i>n*8)throw new Error("Failed to parse given CIDR: "+t);let s=gn(i,8*n);return{network:_t(o,s),mask:s}}function gn(t,e){if(e!==8*ke&&e!==8*Ue)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 St=class{constructor(e,r){if(r==null)({network:this.network,mask:this.mask}=mn(e));else{let n=Ze(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 i=Ze(r);if(i==null)throw new Error("Failed to parse mask");this.mask=i}else this.mask=gn(o,8*n.length);this.network=_t(n,this.mask)}}contains(e){return Vo({network:this.network,mask:this.mask},e)}toString(){let e=$o(this.mask),r=e!==-1?String(e):zo(this.mask);return pn(this.network)+"/"+r}};function tr(t,e){return new St(t).contains(e)}function bc(t){try{let e=j(t);switch(e.type){case"ip6":return tr("2000::/3",e.host);default:return!1}}catch{return!1}}function wc(t){try{let e=j(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 qo(t){return/^127\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/i.test(t)||/^::1$/.test(t)}function Ec(t){try{let e=j(t);switch(e.type){case"ip4":case"ip6":return qo(e.host);default:return!1}}catch{return!1}}function vc(t){try{return j(t),!0}catch{return!1}}function Ee(t){return!!Yt(t)}function ve(t){return!!er(t)}var Wo=Hs(jo(),1),_c=["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"],Sc=_c.map(t=>new Wo.Netmask(t));function yn(t){for(let e of Sc)if(e.contains(t))return!0;return!1}function Cc(t){return/^::ffff:([0-9a-fA-F]{1,4}):([0-9a-fA-F]{1,4})$/.test(t)}function Lc(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 yn(o)}function Ic(t){return/^::ffff:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(t)}function Ac(t){let e=t.split(":"),r=e[e.length-1];return yn(r)}function Tc(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 xn(t){if(Ee(t))return yn(t);if(Cc(t))return Lc(t);if(Ic(t))return Ac(t);if(ve(t))return Tc(t)}function Dc(t){try{let e=j(t);switch(e.type){case"ip4":case"ip6":return xn(e.host)??!1;default:return e.host==="localhost"}}catch{return!1}}function re(){let t={};return t.promise=new Promise((e,r)=>{t.resolve=e,t.reject=r}),t}var rr=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 rr(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 rr(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 bn=class extends Error{type;code;constructor(e,r){super(e??"The operation was aborted"),this.type="aborted",this.code=r??"ABORT_ERR"}};function ue(t={}){return Fc(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 Fc(t,e){e=e??{};let r=e.onEnd,n=new Ye,o,i,s,a=re(),f=async()=>{try{return n.isEmpty()?s?{done:!0}:await new Promise((y,_)=>{i=L=>{i=null,n.push(L);try{y(t(n))}catch(I){_(I)}return o}}):t(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=re()})}},c=y=>i!=null?i(y):(n.push(y),o),u=y=>(n=new Ye,i!=null?i({error:y}):(n.push({error:y}),o)),d=y=>{if(s)return o;if(e?.objectMode!==!0&&y?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return c({done:!1,value:y})},h=y=>s?o:(s=!0,y!=null?u(y):c({done:!0})),g=()=>(n=new Ye,h(),{done:!0}),b=y=>(h(y),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:f,return:g,throw:b,push:d,end:h,get readableLength(){return n.size},onEmpty:async y=>{let _=y?.signal;if(_?.throwIfAborted(),n.isEmpty())return;let L,I;_!=null&&(L=new Promise((A,$)=>{I=()=>{$(new bn)},_.addEventListener("abort",I)}));try{await Promise.race([a.promise,L])}finally{I!=null&&_!=null&&_?.removeEventListener("abort",I)}}},r==null)return o;let w=o;return o={[Symbol.asyncIterator](){return this},next(){return w.next()},throw(y){return w.throw(y),r!=null&&(r(y),r=void 0),{done:!0}},return(){return w.return(),r!=null&&(r(),r=void 0),{done:!0}},push:d,end(y){return w.end(y),r!=null&&(r(y),r=void 0),o},get readableLength(){return w.readableLength},onEmpty:y=>w.onEmpty(y)},o}var wn=class extends Error{constructor(e){super(e),this.name="TimeoutError"}},En=class extends Error{constructor(e){super(),this.name="AbortError",this.message=e}},Go=t=>globalThis.DOMException===void 0?new En(t):new DOMException(t),Ho=t=>{let e=t.reason===void 0?Go("This operation was aborted."):t.reason;return e instanceof Error?e:Go(e)};function vn(t,e){let{milliseconds:r,fallback:n,message:o,customTimers:i={setTimeout,clearTimeout}}=e,s,a,c=new Promise((u,d)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(e.signal){let{signal:g}=e;g.aborted&&d(Ho(g)),a=()=>{d(Ho(g))},g.addEventListener("abort",a,{once:!0})}if(r===Number.POSITIVE_INFINITY){t.then(u,d);return}let h=new wn;s=i.setTimeout.call(void 0,()=>{if(n){try{u(n())}catch(g){d(g)}return}typeof t.cancel=="function"&&t.cancel(),o===!1?u():o instanceof Error?d(o):(h.message=o??`Promise timed out after ${r} milliseconds`,d(h))},r),(async()=>{try{u(await t)}catch(g){d(g)}})()}).finally(()=>{c.clear(),a&&e.signal&&e.signal.removeEventListener("abort",a)});return c.clear=()=>{i.clearTimeout.call(void 0,s),s=void 0},c}var kc=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 Uc(t,e,r){let n,o=new Promise((i,s)=>{if(r={rejectionEvents:["error"],multiArgs:!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(),f=[],{addListener:c,removeListener:u}=kc(t),d=(...g)=>{let b=r.multiArgs?g:g[0];r.filter&&!r.filter(b)||(f.push(b),r.count===f.length&&(n(),i(f)))},h=g=>{n(),s(g)};n=()=>{for(let g of a)u(g,d);for(let g of r.rejectionEvents)u(g,h)};for(let g of a)c(g,d);for(let g of r.rejectionEvents)c(g,h);r.signal&&r.signal.addEventListener("abort",()=>{h(r.signal.reason)},{once:!0}),r.resolveImmediately&&i(f)});if(o.cancel=n,typeof r.timeout=="number"){let i=vn(o,{milliseconds:r.timeout});return i.cancel=n,i}return o}function D(t,e,r){typeof r=="function"&&(r={filter:r}),r={...r,count:1,resolveImmediately:!1};let n=Uc(t,e,r),o=n.then(i=>i[0]);return o.cancel=n.cancel,o}function et(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 Lt=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}},It=class extends Error{static name="QueueFullError";constructor(e="The queue was full"){super(e),this.name="QueueFullError"}},_e=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"},At=class extends Error{static name="MaxEarlyStreamsError";name="MaxEarlyStreamsError"};function Bc(t){return t.reason}async function O(t,e,r){if(e==null)return t;let n=r?.translateError??Bc;if(e.aborted)return t.catch(()=>{}),Promise.reject(n(e));let o;try{return await Promise.race([t,new Promise((i,s)=>{o=()=>{s(n(e))},e.addEventListener("abort",o)})])}finally{o!=null&&e.removeEventListener("abort",o)}}var nr=class{deferred;signal;constructor(e){this.signal=e,this.deferred=re(),this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(this.signal?.reason??new le)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function Pc(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var or=class{id;fn;options;recipients;status;timeline;controller;constructor(e,r){this.id=Pc(),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 le),this.cleanup())}async join(e={}){let r=new nr(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 O(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 ne=class extends ae{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=et(this.emitEmpty.bind(this),1),this.emitIdle=et(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 It;let n=new or(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 i=0;i<this.queue.length;i++)if(this.queue[i]===n){this.queue.splice(i,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 le)}),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=ue({objectMode:!0}),n=f=>{f!=null?this.abort():this.clear(),r.end(f)},o=f=>{f.detail!=null&&r.push(f.detail)},i=f=>{n(f.detail.error)},s=()=>{n()},a=()=>{n(new le("Queue aborted"))};this.addEventListener("completed",o),this.addEventListener("failure",i),this.addEventListener("idle",s),e?.signal?.addEventListener("abort",a);try{yield*r}finally{this.removeEventListener("completed",o),this.removeEventListener("failure",i),this.removeEventListener("idle",s),e?.signal?.removeEventListener("abort",a),n()}}};var Nc=Math.pow(2,20)*4,Be=class extends ae{status;timeline;inactivityTimeout;maxReadBufferLength;maxWriteBufferLength;log;direction;maxMessageSize;readStatus;writeStatus;remoteReadStatus;remoteWriteStatus;writableNeedsDrain;readBuffer;writeBuffer;sendingData;constructor(e){super(),this.status="open",this.log=e.log,this.direction=e.direction??"outbound",this.inactivityTimeout=e.inactivityTimeout??12e4,this.maxReadBufferLength=e.maxReadBufferLength??Nc,this.maxWriteBufferLength=e.maxWriteBufferLength,this.maxMessageSize=e.maxMessageSize,this.readBuffer=new C,this.writeBuffer=new C,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.addEventListener("drain",r)}async*[Symbol.asyncIterator](){if(this.readStatus!=="readable"&&this.readStatus!=="paused")return;let e=ue(),r=i=>{e.push(i.data)};this.addEventListener("message",r);let n=i=>{e.end(i.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 Ie(`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 Wt(e))}}pause(){if(this.readStatus==="closed"||this.readStatus==="closing")throw new Ie("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 Ie("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 Ie(`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)}}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 jt;this.dispatchEvent(new Gt(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 Ve))}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 i=this.writeBuffer.sublist(0,o),s=new C(i);this.writeBuffer.consume(i.byteLength);let a=this.sendData(i);if(e=a.canSendMore,n+=a.sentBytes,a.sentBytes!==s.byteLength&&(s.consume(a.sentBytes),this.writeBuffer.prepend(s)),!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 ht(`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 ht(`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 Tt=class extends Be{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 _n(t){return t==null?!1:typeof t.then=="function"&&typeof t.catch=="function"&&typeof t.finally=="function"}var Dt=class extends ae{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=s=>{try{this.onData(s.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(s=>{s.onMuxerDrain()})};this.maConn.addEventListener("drain",o);let i=()=>{this.log("underlying stream closed with status %s and %d streams",this.status,this.streams.length),this.onTransportClosed()};this.maConn.addEventListener("close",i)}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 O(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 _n(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 At(`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(i=>i===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 Pe=class extends Be{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(){e.abort();for(let i of t)i?.removeEventListener!=null&&i.removeEventListener("abort",r)}for(let i of t){if(i?.aborted===!0){r();break}i?.addEventListener!=null&&i.addEventListener("abort",r)}function n(){for(let i of t)i?.removeEventListener!=null&&i.removeEventListener("abort",r)}let o=e.signal;return o.clear=n,o}var Ne=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,i=n*o;this.movingAverage=n*e+(1-n)*this.movingAverage,this.variance=(1-n)*(this.variance+o*i),this.deviation=Math.sqrt(this.variance),this.forecast=this.movingAverage+n*o}else this.movingAverage=e;this.previousTime=r}};var Ko=1.2,Qo=2,Xo=5e3,Jo=6e4,Zo=5e3,Sn=class{success;failure;next;metric;timeoutMultiplier;failureMultiplier;minTimeout;maxTimeout;constructor(e={}){let r=e.interval??Zo;this.success=new Ne(r),this.failure=new Ne(r),this.next=new Ne(r),this.failureMultiplier=e.failureMultiplier??Qo,this.timeoutMultiplier=e.timeoutMultiplier??Ko,this.minTimeout=e.minTimeout??Xo,this.maxTimeout=e.maxTimeout??Jo,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 U=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},pe=class extends Error{static name="ValidationError";name="ValidationError"},sr=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},ar=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};function Ln(t){return e=>Ae(e,t)}function In(t){return e=>T(e,t)}function tt(t){return new DataView(t.buffer).getUint16(t.byteOffset).toString()}function Me(t){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,typeof t=="string"?parseInt(t):t),new Uint8Array(e)}function Yo(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=Me(n);return xe([r,o],r.length+o.length)}function ei(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=ce.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=Me(n);return xe([r,o],r.length+o.length)}function An(t){let e=t.subarray(0,t.length-2),r=t.subarray(t.length-2),n=Ae(e,"base32"),o=tt(r);return`${n}:${o}`}var Tn=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 U("Invalid byte value in IP address");e[n]=o}),e},ti=function(t){let e=0;t=t.toString().trim();let r=t.split(":",8),n;for(n=0;n<r.length;n++){let i=Ee(r[n]),s;i&&(s=Tn(r[n]),r[n]=Ae(s.subarray(0,2),"base16")),s!=null&&++n<8&&r.splice(n,0,Ae(s.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 i=[n,1];for(n=9-r.length;n>0;n--)i.push("0");r.splice.apply(r,i)}let o=new Uint8Array(e+16);for(n=0;n<r.length;n++){r[n]===""&&(r[n]="0");let i=parseInt(r[n],16);if(isNaN(i)||i<0||i>65535)throw new U("Invalid byte value in IP address");o[e++]=i>>8&255,o[e++]=i&255}return o},ri=function(t){if(t.byteLength!==4)throw new U("IPv4 address was incorrect length");let e=[];for(let r=0;r<t.byteLength;r++)e.push(t[r]);return e.join(".")},ni=function(t){if(t.byteLength!==16)throw new U("IPv6 address was incorrect length");let e=[];for(let n=0;n<t.byteLength;n+=2){let o=t[n],i=t[n+1],s=`${o.toString(16).padStart(2,"0")}${i.toString(16).padStart(2,"0")}`;e.push(s)}let r=e.join(":");try{let n=new URL(`http://[${r}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new U(`Invalid IPv6 address "${r}"`)}};function oi(t){try{let e=new URL(`http://[${t}]`);return e.hostname.substring(1,e.hostname.length-1)}catch{throw new U(`Invalid IPv6 address "${t}"`)}}var Cn=Object.values(bt).map(t=>t.decoder),Mc=(function(){let t=Cn[0].or(Cn[1]);return Cn.slice(2).forEach(e=>t=t.or(e)),t})();function ii(t){return Mc.decode(t)}function si(t){return e=>t.encoder.encode(e)}function Oc(t){if(parseInt(t).toString()!==t)throw new pe("Value must be an integer")}function Rc(t){if(t<0)throw new pe("Value must be a positive integer, or zero")}function $c(t){return e=>{if(e>t)throw new pe(`Value must be smaller than or equal to ${t}`)}}function zc(...t){return e=>{for(let r of t)r(e)}}var Ft=zc(Oc,Rc,$c(65535));var F=-1,Dn=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 ar(`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)}))}},me=new Dn,Cu=[{code:4,name:"ip4",size:32,valueToBytes:Tn,bytesToValue:ri,validate:t=>{if(!Ee(t))throw new pe(`Invalid IPv4 address "${t}"`)}},{code:6,name:"tcp",size:16,valueToBytes:Me,bytesToValue:tt,validate:Ft},{code:273,name:"udp",size:16,valueToBytes:Me,bytesToValue:tt,validate:Ft},{code:33,name:"dccp",size:16,valueToBytes:Me,bytesToValue:tt,validate:Ft},{code:41,name:"ip6",size:128,valueToBytes:ti,bytesToValue:ni,stringToValue:oi,validate:t=>{if(!ve(t))throw new pe(`Invalid IPv6 address "${t}"`)}},{code:42,name:"ip6zone",size:F},{code:43,name:"ipcidr",size:8,bytesToValue:Ln("base10"),valueToBytes:In("base10")},{code:53,name:"dns",size:F},{code:54,name:"dns4",size:F},{code:55,name:"dns6",size:F},{code:56,name:"dnsaddr",size:F},{code:132,name:"sctp",size:16,valueToBytes:Me,bytesToValue:tt,validate:Ft},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:F,stringToValue:t=>decodeURIComponent(t),valueToString:t=>encodeURIComponent(t)},{code:421,name:"p2p",aliases:["ipfs"],size:F,bytesToValue:Ln("base58btc"),valueToBytes:t=>t.startsWith("Q")||t.startsWith("1")?In("base58btc")(t):Ke.parse(t).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:An,valueToBytes:Yo},{code:445,name:"onion3",size:296,bytesToValue:An,valueToBytes:ei},{code:446,name:"garlic64",size:F},{code:447,name:"garlic32",size:F},{code:448,name:"tls"},{code:449,name:"sni",size:F},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:F,bytesToValue:si(Jr),valueToBytes:ii},{code:480,name:"http"},{code:481,name:"http-path",size:F,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:F}];Cu.forEach(t=>{me.addProtocol(t)});function fi(t){let e=[],r=0;for(;r<t.length;){let n=he(t,r),o=me.getProtocol(n),i=N(n),s=Lu(o,t,r+i),a=0;s>0&&o.size===F&&(a=N(s));let f=i+a+s,c={code:n,name:o.name,bytes:t.subarray(r,r+f)};if(s>0){let u=r+i+a,d=t.subarray(u,u+s);c.value=o.bytesToValue?.(d)??Ae(d)}e.push(c),r+=f}return e}function li(t){let e=0,r=[];for(let n of t){if(n.bytes==null){let o=me.getProtocol(n.code),i=N(n.code),s,a=0,f=0;n.value!=null&&(s=o.valueToBytes?.(n.value)??T(n.value),a=s.byteLength,o.size===F&&(f=N(a)));let c=new Uint8Array(i+f+a),u=0;Qt(n.code,c,u),u+=i,s!=null&&(o.size===F&&(Qt(a,c,u),u+=f),c.set(s,u)),n.bytes=c}r.push(n.bytes),e+=n.bytes.byteLength}return xe(r,e)}function di(t){if(t.charAt(0)!=="/")throw new U('String multiaddr must start with "/"');let e=[],r="protocol",n="",o="";for(let i=1;i<t.length;i++){let s=t.charAt(i);s!=="/"&&(r==="protocol"?o+=t.charAt(i):n+=t.charAt(i));let a=i===t.length-1;if(s==="/"||a){let f=me.getProtocol(o);if(r==="protocol"){if(f.size==null||f.size===0){e.push({code:f.code,name:f.name}),n="",o="",r="protocol";continue}else if(a)throw new U(`Component ${o} was missing value`);r="value"}else if(r==="value"){let c={code:f.code,name:f.name};if(f.size!=null&&f.size!==0){if(n==="")throw new U(`Component ${o} was missing value`);c.value=f.stringToValue?.(n)??n}e.push(c),n="",o="",r="protocol"}}}if(o!==""&&n!=="")throw new U("Incomplete multiaddr");return e}function hi(t){return`/${t.flatMap(e=>{if(e.value==null)return e.name;let r=me.getProtocol(e.code);if(r==null)throw new U(`Unknown protocol code ${e.code}`);return[e.name,r.valueToString?.(e.value)??e.value]}).join("/")}`}function Lu(t,e,r){return t.size==null||t.size===0?0:t.size>0?t.size/8:he(e,r)}var Iu=Symbol.for("nodejs.util.inspect.custom"),Fn=Symbol.for("@multiformats/multiaddr");function Au(t){if(t==null&&(t="/"),pi(t))return t.getComponents();if(t instanceof Uint8Array)return fi(t);if(typeof t=="string")return t=t.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),t===""&&(t="/"),di(t);if(Array.isArray(t))return t;throw new U("Must be a string, Uint8Array, Component[], or another Multiaddr")}var cr=class t{[Fn]=!0;#e;#t;#r;constructor(e="/",r={}){this.#e=Au(e),r.validate!==!1&&Tu(this)}get bytes(){return this.#r==null&&(this.#r=li(this.#e)),this.#r}toString(){return this.#t==null&&(this.#t=hi(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 sr(`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 Qe(this.bytes,e.bytes)}[Iu](){return`Multiaddr(${this.toString()})`}};function Tu(t){t.getComponents().forEach(e=>{let r=me.getProtocol(e.code);e.value!=null&&r.validate?.(e.value)})}function pi(t){return!!t?.[Fn]}function Se(t){return new cr(t)}function mi(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),Se(`/${n.join("/")}`)}function Du(t,e){if(t==null)return[];let r=j(t);return[mi(r,e)]}function Fu(t){return ve(t)?tr("2000::/3",t):!1}function ku(t,e){if(typeof t!="string")throw new M(`invalid ip provided: ${t}`);if(typeof e=="string"&&(e=parseInt(e)),isNaN(e))throw new M(`invalid port provided: ${e}`);if(Ee(t))return Se(`/ip4/${t}/tcp/${e}`);if(ve(t))return Se(`/ip6/${t}/tcp/${e}`);throw new M(`invalid ip:port for creating a multiaddr: ${t}:${e}`)}function Uu(t){return t==null||typeof t?.[Symbol.asyncIterator]!="function"?!1:typeof t.next=="function"}function Bu(t){return t==null||typeof t?.[Symbol.iterator]!="function"?!1:typeof t.next=="function"}var ur=class extends Error{type;code;constructor(e,r,n){super(e??"The operation was aborted"),this.type="aborted",this.name=n??"AbortError",this.code=r??"ABORT_ERR"}};async function gi(t,e,r){if(e==null)return t;if(e.aborted)return t.catch(()=>{}),Promise.reject(new ur(r?.errorMessage,r?.errorCode,r?.errorName));let n,o=new ur(r?.errorMessage,r?.errorCode,r?.errorName);try{return await Promise.race([t,new Promise((i,s)=>{n=()=>{s(o)},e.addEventListener("abort",n)})])}finally{n!=null&&e.removeEventListener("abort",n)}}var kn=class{readNext;haveNext;ended;nextResult;error;constructor(){this.ended=!1,this.readNext=re(),this.haveNext=re()}[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=re(),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=re(),await gi(this.readNext.promise,r?.signal,r)}};function yi(){return new kn}function Pu(t){return t[Symbol.asyncIterator]!=null}async function Nu(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*Mu(t){let e=new AbortController,r=yi();Nu(t,r,e.signal).catch(()=>{});try{yield*r}finally{e.abort()}}function*Ou(t){for(let e of t)yield*e}function Ru(...t){let e=[];for(let r of t)Pu(r)||e.push(r);return e.length===t.length?Ou(e):Mu(t)}var xi=Ru;function bi(t,...e){if(t==null)throw new Error("Empty pipeline");if(Un(t)){let n=t;t=()=>n.source}else if(Ei(t)||wi(t)){let n=t;t=()=>n}let r=[t,...e];if(r.length>1&&Un(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++)Un(r[n])&&(r[n]=zu(r[n]));return $u(...r)}var $u=(...t)=>{let e;for(;t.length>0;)e=t.shift()(e);return e},wi=t=>t?.[Symbol.asyncIterator]!=null,Ei=t=>t?.[Symbol.iterator]!=null,Un=t=>t==null?!1:t.sink!=null&&t.source!=null,zu=t=>e=>{let r=t.sink(e);if(r?.then!=null){let n=ue({objectMode:!0});r.then(()=>{n.end()},s=>{n.end(s)});let o,i=t.source;if(wi(i))o=async function*(){yield*i,n.end()};else if(Ei(i))o=function*(){yield*i,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return xi(n,o())}return t.source};var Vu=4194304,kt=class extends Error{static name="UnwrappedError";name="UnwrappedError"},rt=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 qu(t){return typeof t?.closeRead=="function"}function ju(t){return typeof t?.close=="function"}function Bn(t){return qu(t)?t.readStatus==="closing"||t.readStatus==="closed":ju(t)?t.status!=="open":!1}function Wu(t){return t?.addEventListener!=null&&t?.removeEventListener!=null&&t?.send!=null&&t?.push!=null&&t?.log!=null}function vi(t,e){let r=e?.maxBufferSize??Vu,n=new C,o=Promise.withResolvers(),i=!1;if(!Wu(t))throw new M("Argument should be a Stream or a Multiaddr");let s=u=>{if(n.append(u.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",s);let a=u=>{u.error!=null?o.reject(u.error):o.resolve()};t.addEventListener("close",a);let f=()=>{o.resolve()};t.addEventListener("remoteCloseWrite",f);let c={readBuffer:n,async read(u){if(i===!0)throw new kt("Stream was unwrapped");if(Bn(t)){if(u?.bytes==null)return null;if(n.byteLength<u.bytes)throw t.log.error("closed after reading %d/%d bytes",n.byteLength,u.bytes),new _e(`Unexpected EOF - stream closed after reading ${n.byteLength}/${u.bytes} bytes`)}let d=u?.bytes??1;for(;;){if(n.byteLength>=d){o.resolve();break}if(await O(o.promise,u?.signal),Bn(t)){if(n.byteLength===0&&u?.bytes==null)return null;break}o=Promise.withResolvers()}let h=u?.bytes??n.byteLength;if(n.byteLength<h){if(Bn(t))throw t.log.error("closed while reading %d/%d bytes",n.byteLength,h),new _e(`Unexpected EOF - stream closed while reading ${n.byteLength}/${h} bytes`);return c.read(u)}let g=n.sublist(0,h);return n.consume(h),g},async write(u,d){if(i===!0)throw new kt("Stream was unwrapped");t.send(u)||await D(t,"drain",{signal:d?.signal,rejectionEvents:["close"]})},unwrap(){return i||(i=!0,t.removeEventListener("message",s),t.removeEventListener("close",a),t.removeEventListener("remoteCloseWrite",f),n.byteLength>0&&(t.log("stream unwrapped with %d unread bytes",n.byteLength),t.push(n))),t}};return c}function _i(t,e={}){let r=vi(t,e);e.maxDataLength!=null&&e.maxLengthLength==null&&(e.maxLengthLength=N(e.maxDataLength));let n=e?.lengthDecoder??he,o=e?.lengthEncoder??Xt;return{async read(s){let a=-1,f=new C;for(;;){let u=await r.read({...s,bytes:1});if(u==null)break;f.append(u);try{a=n(f)}catch(d){if(d instanceof RangeError)continue;throw d}if(a<0)throw new rt("Invalid message length");if(e?.maxLengthLength!=null&&f.byteLength>e.maxLengthLength)throw new lr(`Message length length too long - ${f.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 c=await r.read({...s,bytes:a});if(c==null)throw t.log.error("tried to read %d bytes but the stream closed",a),new _e(`Unexpected EOF - tried to read ${a} bytes but the stream closed`);if(c.byteLength!==a)throw t.log.error("read %d/%d bytes before the stream closed",c.byteLength,a),new _e(`Unexpected EOF - read ${c.byteLength}/${a} bytes before the stream closed`);return c},async write(s,a){await r.write(new C(o(s.byteLength),s),a)},async writeV(s,a){let f=new C(...s.flatMap(c=>[o(c.byteLength),c]));await r.write(f,a)},unwrap(){return r.unwrap()}}}function Gu(t,e){let r=_i(t,e),n={read:async(o,i)=>{let s=await r.read(i);return o.decode(s)},write:async(o,i,s)=>{await r.write(i.encode(o),s)},writeV:async(o,i,s)=>{await r.writeV(o.map(a=>i.encode(a)),s)},pb:o=>({read:async i=>n.read(o,i),write:async(i,s)=>n.write(i,o,s),writeV:async(i,s)=>n.writeV(i,o,s),unwrap:()=>n}),unwrap:()=>r.unwrap()};return n}async function Pn(t,e){let r=t.log.newScope("echo"),n=Date.now(),o=0;try{for await(let i of t)o+=i.byteLength,t.send(i)||(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(i){t.abort(i)}}function Hu(t){return t?.addEventListener!=null}function Si(t){let e=ue(),r,n=s=>{e.push(s.data)},o=()=>{e.end(),t.removeEventListener("message",n),t.removeEventListener("close",i),t.removeEventListener("remoteCloseWrite",o)},i=s=>{e.end(s.error),s.error!=null&&r?.reject(s.error),t.removeEventListener("message",n),t.removeEventListener("close",i),t.removeEventListener("remoteCloseWrite",o)};return t.addEventListener("message",n),t.addEventListener("close",i,{once:!0}),t.addEventListener("remoteCloseWrite",o,{once:!0}),{source:e,async sink(s){async function*a(){yield*s}let f=a();for(;;){r=Promise.withResolvers();let{done:c,value:u}=await Promise.race([f.next(),r.promise]);if(t.writeStatus==="closing"||t.writeStatus==="closed"||(u!=null&&(t.send(u)||await Promise.race([D(t,"drain",{rejectionEvents:["close"]})])),c===!0))break}await t.close()}}}function Ku(...t){let e=t.map(r=>Hu(r)?Si(r):r);return bi(...e)}var Qu=1024*1024*4,Xu=1024*1024*4,Nn=class{buffer;maxBufferSize;lengthDecoder;maxDataLength;encodingLength;constructor(e={}){this.buffer=new C,this.maxBufferSize=e.maxBufferSize??Qu,this.maxDataLength=e.maxDataLength??Xu,this.lengthDecoder=e.lengthDecoder??he,this.encodingLength=e.encodingLength??N}*decode(e){if(this.buffer.append(e),this.buffer.byteLength>this.maxBufferSize)throw new M(`Buffer length limit exceeded - ${this.buffer.byteLength}/${this.maxBufferSize}`);for(;;){let r;try{r=this.lengthDecoder(this.buffer)}catch(i){if(i instanceof RangeError)break;throw i}if(r<0||r>this.maxDataLength)throw new rt("Invalid message length");let n=this.encodingLength(r),o=n+r;if(this.buffer.byteLength>=o){let i=this.buffer.sublist(n,o);this.buffer.consume(o),i.byteLength>0&&(yield i)}else break}}};function Ju(t){return!!(t.startsWith("169.254.")||t.toLowerCase().startsWith("fe80"))}function nt(t){if(typeof t!="object"||t===null)return!1;let e=Object.getPrototypeOf(t);return(e===null||e===Object.prototype||Object.getPrototypeOf(e)===null)&&!(Symbol.toStringTag in t)&&!(Symbol.iterator in t)}var{hasOwnProperty:Li}=Object.prototype,{propertyIsEnumerable:Zu}=Object,ot=(t,e,r)=>{Object.defineProperty(t,e,{value:r,writable:!0,enumerable:!0,configurable:!0})},Yu=void 0,Ci={concatArrays:!1,ignoreUndefined:!1},dr=t=>{let e=[];for(let r in t)Li.call(t,r)&&e.push(r);if(Object.getOwnPropertySymbols){let r=Object.getOwnPropertySymbols(t);for(let n of r)Zu.call(t,n)&&e.push(n)}return e};function it(t){return Array.isArray(t)?ef(t):nt(t)?tf(t):t}function ef(t){let e=t.slice(0,0);return dr(t).forEach(r=>{ot(e,r,it(t[r]))}),e}function tf(t){let e=Object.getPrototypeOf(t)===null?Object.create(null):{};return dr(t).forEach(r=>{ot(e,r,it(t[r]))}),e}var Ii=(t,e,r,n)=>(r.forEach(o=>{typeof e[o]>"u"&&n.ignoreUndefined||(o in t&&t[o]!==Object.getPrototypeOf(t)?ot(t,o,Mn(t[o],e[o],n)):ot(t,o,it(e[o])))}),t),rf=(t,e,r)=>{let n=t.slice(0,0),o=0;return[t,e].forEach(i=>{let s=[];for(let a=0;a<i.length;a++)Li.call(i,a)&&(s.push(String(a)),i===t?ot(n,o++,i[a]):ot(n,o++,it(i[a])));n=Ii(n,i,dr(i).filter(a=>!s.includes(a)),r)}),n};function Mn(t,e,r){return r.concatArrays&&Array.isArray(t)&&Array.isArray(e)?rf(t,e,r):!nt(e)||!nt(t)?it(e):Ii(t,e,dr(e),r)}function nf(...t){let e=Mn(it(Ci),this!==Yu&&this||{},Ci),r={_:{}};for(let n of t)if(n!==void 0){if(!nt(n))throw new TypeError("`"+n+"` is not an Option Object");r=Mn(r,{_:n},e)}return r._}var of=["string","number","bigint","symbol"],sf=["Function","Generator","AsyncGenerator","GeneratorFunction","AsyncGeneratorFunction","AsyncFunction","Observable","Array","Buffer","Object","RegExp","Date","Error","Map","Set","WeakMap","WeakSet","ArrayBuffer","SharedArrayBuffer","DataView","Promise","URL","HTMLElement","Int8Array","Uint8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array"];function Ai(t){if(t===null)return"null";if(t===void 0)return"undefined";if(t===!0||t===!1)return"boolean";let e=typeof t;if(of.includes(e))return e;if(e==="function")return"Function";if(Array.isArray(t))return"Array";if(af(t))return"Buffer";let r=cf(t);return r||"Object"}function af(t){return t&&t.constructor&&t.constructor.isBuffer&&t.constructor.isBuffer.call(null,t)}function cf(t){let e=Object.prototype.toString.call(t).slice(8,-1);if(sf.includes(e))return e}var l=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}};l.uint=new l(0,"uint",!0);l.negint=new l(1,"negint",!0);l.bytes=new l(2,"bytes",!0);l.string=new l(3,"string",!0);l.array=new l(4,"array",!1);l.map=new l(5,"map",!1);l.tag=new l(6,"tag",!1);l.float=new l(7,"float",!0);l.false=new l(7,"false",!0);l.true=new l(7,"true",!0);l.null=new l(7,"null",!0);l.undefined=new l(7,"undefined",!0);l.break=new l(7,"break",!0);var m=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 st=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",uf=new TextDecoder,ff=new TextEncoder;function hr(t){return st&&globalThis.Buffer.isBuffer(t)}function On(t){return t instanceof Uint8Array?hr(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):t:Uint8Array.from(t)}var ki=st?(t,e,r)=>r-e>64?globalThis.Buffer.from(t.subarray(e,r)).toString("utf8"):Di(t,e,r):(t,e,r)=>r-e>64?uf.decode(t.subarray(e,r)):Di(t,e,r),Ui=st?t=>t.length>64?globalThis.Buffer.from(t):Ti(t):t=>t.length>64?ff.encode(t):Ti(t),fe=t=>Uint8Array.from(t),at=st?(t,e,r)=>hr(t)?new Uint8Array(t.subarray(e,r)):t.slice(e,r):(t,e,r)=>t.slice(e,r),Bi=st?(t,e)=>(t=t.map(r=>r instanceof Uint8Array?r:globalThis.Buffer.from(r)),On(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},Pi=st?t=>globalThis.Buffer.allocUnsafe(t):t=>new Uint8Array(t);function Ni(t,e){if(hr(t)&&hr(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 Ti(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):(e[r++]=o>>12|224,e[r++]=o>>6&63|128,e[r++]=o&63|128)}return e}function Di(t,e,r){let n=[];for(;e<r;){let o=t[e],i=null,s=o>239?4:o>223?3:o>191?2:1;if(e+s<=r){let a,f,c,u;switch(s){case 1:o<128&&(i=o);break;case 2:a=t[e+1],(a&192)===128&&(u=(o&31)<<6|a&63,u>127&&(i=u));break;case 3:a=t[e+1],f=t[e+2],(a&192)===128&&(f&192)===128&&(u=(o&15)<<12|(a&63)<<6|f&63,u>2047&&(u<55296||u>57343)&&(i=u));break;case 4:a=t[e+1],f=t[e+2],c=t[e+3],(a&192)===128&&(f&192)===128&&(c&192)===128&&(u=(o&15)<<18|(a&63)<<12|(f&63)<<6|c&63,u>65535&&u<1114112&&(i=u))}}i===null?(i=65533,s=1):i>65535&&(i-=65536,n.push(i>>>10&1023|55296),i=56320|i&1023),n.push(i),e+=s}return lf(n)}var Fi=4096;function lf(t){let e=t.length;if(e<=Fi)return String.fromCharCode.apply(String,t);let r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.slice(n,n+=Fi));return r}var df=256,Ut=class{constructor(e=df){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=Pi(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=at(n,0,this.cursor)}else r=Bi(this.chunks,this.cursor);return e&&this.reset(),r}};var x="CBOR decode error:",Rn="CBOR encode error:",Bt=[];Bt[23]=1;Bt[24]=2;Bt[25]=3;Bt[26]=5;Bt[27]=9;function ge(t,e,r){if(t.length-e<r)throw new Error(`${x} not enough data for type`)}var k=[24,256,65536,4294967296,BigInt("18446744073709551616")];function W(t,e,r){ge(t,e,1);let n=t[e];if(r.strict===!0&&n<k[0])throw new Error(`${x} integer encoded in more bytes than necessary (strict decode)`);return n}function G(t,e,r){ge(t,e,2);let n=t[e]<<8|t[e+1];if(r.strict===!0&&n<k[1])throw new Error(`${x} integer encoded in more bytes than necessary (strict decode)`);return n}function H(t,e,r){ge(t,e,4);let n=t[e]*16777216+(t[e+1]<<16)+(t[e+2]<<8)+t[e+3];if(r.strict===!0&&n<k[2])throw new Error(`${x} integer encoded in more bytes than necessary (strict decode)`);return n}function K(t,e,r){ge(t,e,8);let n=t[e]*16777216+(t[e+1]<<16)+(t[e+2]<<8)+t[e+3],o=t[e+4]*16777216+(t[e+5]<<16)+(t[e+6]<<8)+t[e+7],i=(BigInt(n)<<BigInt(32))+BigInt(o);if(r.strict===!0&&i<k[3])throw new Error(`${x} integer encoded in more bytes than necessary (strict decode)`);if(i<=Number.MAX_SAFE_INTEGER)return Number(i);if(r.allowBigInt===!0)return i;throw new Error(`${x} integers outside of the safe integer range are not supported`)}function Mi(t,e,r,n){return new m(l.uint,W(t,e+1,n),2)}function Oi(t,e,r,n){return new m(l.uint,G(t,e+1,n),3)}function Ri(t,e,r,n){return new m(l.uint,H(t,e+1,n),5)}function $i(t,e,r,n){return new m(l.uint,K(t,e+1,n),9)}function Z(t,e){return B(t,0,e.value)}function B(t,e,r){if(r<k[0]){let n=Number(r);t.push([e|n])}else if(r<k[1]){let n=Number(r);t.push([e|24,n])}else if(r<k[2]){let n=Number(r);t.push([e|25,n>>>8,n&255])}else if(r<k[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<k[4]){let o=[e|27,0,0,0,0,0,0,0],i=Number(n&BigInt(4294967295)),s=Number(n>>BigInt(32)&BigInt(4294967295));o[8]=i&255,i=i>>8,o[7]=i&255,i=i>>8,o[6]=i&255,i=i>>8,o[5]=i&255,o[4]=s&255,s=s>>8,o[3]=s&255,s=s>>8,o[2]=s&255,s=s>>8,o[1]=s&255,t.push(o)}else throw new Error(`${x} encountered BigInt larger than allowable range`)}}Z.encodedSize=function(e){return B.encodedSize(e.value)};B.encodedSize=function(e){return e<k[0]?1:e<k[1]?2:e<k[2]?3:e<k[3]?5:9};Z.compareTokens=function(e,r){return e.value<r.value?-1:e.value>r.value?1:0};function zi(t,e,r,n){return new m(l.negint,-1-W(t,e+1,n),2)}function Vi(t,e,r,n){return new m(l.negint,-1-G(t,e+1,n),3)}function qi(t,e,r,n){return new m(l.negint,-1-H(t,e+1,n),5)}var $n=BigInt(-1),ji=BigInt(1);function Wi(t,e,r,n){let o=K(t,e+1,n);if(typeof o!="bigint"){let i=-1-o;if(i>=Number.MIN_SAFE_INTEGER)return new m(l.negint,i,9)}if(n.allowBigInt!==!0)throw new Error(`${x} integers outside of the safe integer range are not supported`);return new m(l.negint,$n-BigInt(o),9)}function pr(t,e){let r=e.value,n=typeof r=="bigint"?r*$n-ji:r*-1-1;B(t,e.type.majorEncoded,n)}pr.encodedSize=function(e){let r=e.value,n=typeof r=="bigint"?r*$n-ji:r*-1-1;return n<k[0]?1:n<k[1]?2:n<k[2]?3:n<k[3]?5:9};pr.compareTokens=function(e,r){return e.value<r.value?1:e.value>r.value?-1:0};function Pt(t,e,r,n){ge(t,e,r+n);let o=at(t,e+r,e+r+n);return new m(l.bytes,o,r+n)}function Gi(t,e,r,n){return Pt(t,e,1,r)}function Hi(t,e,r,n){return Pt(t,e,2,W(t,e+1,n))}function Ki(t,e,r,n){return Pt(t,e,3,G(t,e+1,n))}function Qi(t,e,r,n){return Pt(t,e,5,H(t,e+1,n))}function Xi(t,e,r,n){let o=K(t,e+1,n);if(typeof o=="bigint")throw new Error(`${x} 64-bit integer bytes lengths not supported`);return Pt(t,e,9,o)}function mr(t){return t.encodedBytes===void 0&&(t.encodedBytes=t.type===l.string?Ui(t.value):t.value),t.encodedBytes}function ct(t,e){let r=mr(e);B(t,e.type.majorEncoded,r.length),t.push(r)}ct.encodedSize=function(e){let r=mr(e);return B.encodedSize(r.length)+r.length};ct.compareTokens=function(e,r){return pf(mr(e),mr(r))};function pf(t,e){return t.length<e.length?-1:t.length>e.length?1:Ni(t,e)}function Nt(t,e,r,n,o){let i=r+n;ge(t,e,i);let s=new m(l.string,ki(t,e+r,e+i),i);return o.retainStringBytes===!0&&(s.byteValue=at(t,e+r,e+i)),s}function Ji(t,e,r,n){return Nt(t,e,1,r,n)}function Zi(t,e,r,n){return Nt(t,e,2,W(t,e+1,n),n)}function Yi(t,e,r,n){return Nt(t,e,3,G(t,e+1,n),n)}function es(t,e,r,n){return Nt(t,e,5,H(t,e+1,n),n)}function ts(t,e,r,n){let o=K(t,e+1,n);if(typeof o=="bigint")throw new Error(`${x} 64-bit integer string lengths not supported`);return Nt(t,e,9,o,n)}var rs=ct;function ut(t,e,r,n){return new m(l.array,n,r)}function ns(t,e,r,n){return ut(t,e,1,r)}function os(t,e,r,n){return ut(t,e,2,W(t,e+1,n))}function is(t,e,r,n){return ut(t,e,3,G(t,e+1,n))}function ss(t,e,r,n){return ut(t,e,5,H(t,e+1,n))}function as(t,e,r,n){let o=K(t,e+1,n);if(typeof o=="bigint")throw new Error(`${x} 64-bit integer array lengths not supported`);return ut(t,e,9,o)}function cs(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${x} indefinite length items not allowed`);return ut(t,e,1,1/0)}function gr(t,e){B(t,l.array.majorEncoded,e.value)}gr.compareTokens=Z.compareTokens;gr.encodedSize=function(e){return B.encodedSize(e.value)};function ft(t,e,r,n){return new m(l.map,n,r)}function us(t,e,r,n){return ft(t,e,1,r)}function fs(t,e,r,n){return ft(t,e,2,W(t,e+1,n))}function ls(t,e,r,n){return ft(t,e,3,G(t,e+1,n))}function ds(t,e,r,n){return ft(t,e,5,H(t,e+1,n))}function hs(t,e,r,n){let o=K(t,e+1,n);if(typeof o=="bigint")throw new Error(`${x} 64-bit integer map lengths not supported`);return ft(t,e,9,o)}function ps(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${x} indefinite length items not allowed`);return ft(t,e,1,1/0)}function yr(t,e){B(t,l.map.majorEncoded,e.value)}yr.compareTokens=Z.compareTokens;yr.encodedSize=function(e){return B.encodedSize(e.value)};function ms(t,e,r,n){return new m(l.tag,r,1)}function gs(t,e,r,n){return new m(l.tag,W(t,e+1,n),2)}function ys(t,e,r,n){return new m(l.tag,G(t,e+1,n),3)}function xs(t,e,r,n){return new m(l.tag,H(t,e+1,n),5)}function bs(t,e,r,n){return new m(l.tag,K(t,e+1,n),9)}function xr(t,e){B(t,l.tag.majorEncoded,e.value)}xr.compareTokens=Z.compareTokens;xr.encodedSize=function(e){return B.encodedSize(e.value)};var wf=20,Ef=21,vf=22,_f=23;function ws(t,e,r,n){if(n.allowUndefined===!1)throw new Error(`${x} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new m(l.null,null,1):new m(l.undefined,void 0,1)}function Es(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${x} indefinite length items not allowed`);return new m(l.break,void 0,1)}function zn(t,e,r){if(r){if(r.allowNaN===!1&&Number.isNaN(t))throw new Error(`${x} NaN values are not supported`);if(r.allowInfinity===!1&&(t===1/0||t===-1/0))throw new Error(`${x} Infinity values are not supported`)}return new m(l.float,t,e)}function vs(t,e,r,n){return zn(Vn(t,e+1),3,n)}function _s(t,e,r,n){return zn(qn(t,e+1),5,n)}function Ss(t,e,r,n){return zn(As(t,e+1),9,n)}function br(t,e,r){let n=e.value;if(n===!1)t.push([l.float.majorEncoded|wf]);else if(n===!0)t.push([l.float.majorEncoded|Ef]);else if(n===null)t.push([l.float.majorEncoded|vf]);else if(n===void 0)t.push([l.float.majorEncoded|_f]);else{let o,i=!1;(!r||r.float64!==!0)&&(Ls(n),o=Vn(oe,1),n===o||Number.isNaN(n)?(oe[0]=249,t.push(oe.slice(0,3)),i=!0):(Is(n),o=qn(oe,1),n===o&&(oe[0]=250,t.push(oe.slice(0,5)),i=!0))),i||(Sf(n),o=As(oe,1),oe[0]=251,t.push(oe.slice(0,9)))}}br.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){Ls(n);let o=Vn(oe,1);if(n===o||Number.isNaN(n))return 3;if(Is(n),o=qn(oe,1),n===o)return 5}return 9};var Cs=new ArrayBuffer(9),Y=new DataView(Cs,1),oe=new Uint8Array(Cs,0);function Ls(t){if(t===1/0)Y.setUint16(0,31744,!1);else if(t===-1/0)Y.setUint16(0,64512,!1);else if(Number.isNaN(t))Y.setUint16(0,32256,!1);else{Y.setFloat32(0,t);let e=Y.getUint32(0),r=(e&2139095040)>>23,n=e&8388607;if(r===255)Y.setUint16(0,31744,!1);else if(r===0)Y.setUint16(0,(t&2147483648)>>16|n>>13,!1);else{let o=r-127;o<-24?Y.setUint16(0,0):o<-14?Y.setUint16(0,(e&2147483648)>>16|1<<24+o,!1):Y.setUint16(0,(e&2147483648)>>16|o+15<<10|n>>13,!1)}}}function Vn(t,e){if(t.length-e<2)throw new Error(`${x} not enough data for float16`);let r=(t[e]<<8)+t[e+1];if(r===31744)return 1/0;if(r===64512)return-1/0;if(r===32256)return NaN;let n=r>>10&31,o=r&1023,i;return n===0?i=o*2**-24:n!==31?i=(o+1024)*2**(n-25):i=o===0?1/0:NaN,r&32768?-i:i}function Is(t){Y.setFloat32(0,t,!1)}function qn(t,e){if(t.length-e<4)throw new Error(`${x} not enough data for float32`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,4).getFloat32(0,!1)}function Sf(t){Y.setFloat64(0,t,!1)}function As(t,e){if(t.length-e<8)throw new Error(`${x} not enough data for float64`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,8).getFloat64(0,!1)}br.compareTokens=Z.compareTokens;function E(t,e,r){throw new Error(`${x} encountered invalid minor (${r}) for major ${t[e]>>>5}`)}function wr(t){return()=>{throw new Error(`${x} ${t}`)}}var p=[];for(let t=0;t<=23;t++)p[t]=E;p[24]=Mi;p[25]=Oi;p[26]=Ri;p[27]=$i;p[28]=E;p[29]=E;p[30]=E;p[31]=E;for(let t=32;t<=55;t++)p[t]=E;p[56]=zi;p[57]=Vi;p[58]=qi;p[59]=Wi;p[60]=E;p[61]=E;p[62]=E;p[63]=E;for(let t=64;t<=87;t++)p[t]=Gi;p[88]=Hi;p[89]=Ki;p[90]=Qi;p[91]=Xi;p[92]=E;p[93]=E;p[94]=E;p[95]=wr("indefinite length bytes/strings are not supported");for(let t=96;t<=119;t++)p[t]=Ji;p[120]=Zi;p[121]=Yi;p[122]=es;p[123]=ts;p[124]=E;p[125]=E;p[126]=E;p[127]=wr("indefinite length bytes/strings are not supported");for(let t=128;t<=151;t++)p[t]=ns;p[152]=os;p[153]=is;p[154]=ss;p[155]=as;p[156]=E;p[157]=E;p[158]=E;p[159]=cs;for(let t=160;t<=183;t++)p[t]=us;p[184]=fs;p[185]=ls;p[186]=ds;p[187]=hs;p[188]=E;p[189]=E;p[190]=E;p[191]=ps;for(let t=192;t<=215;t++)p[t]=ms;p[216]=gs;p[217]=ys;p[218]=xs;p[219]=bs;p[220]=E;p[221]=E;p[222]=E;p[223]=E;for(let t=224;t<=243;t++)p[t]=wr("simple values are not supported");p[244]=E;p[245]=E;p[246]=E;p[247]=ws;p[248]=wr("simple values are not supported");p[249]=vs;p[250]=_s;p[251]=Ss;p[252]=E;p[253]=E;p[254]=E;p[255]=Es;var ie=[];for(let t=0;t<24;t++)ie[t]=new m(l.uint,t,1);for(let t=-1;t>=-24;t--)ie[31-t]=new m(l.negint,t,1);ie[64]=new m(l.bytes,new Uint8Array(0),1);ie[96]=new m(l.string,"",1);ie[128]=new m(l.array,0,1);ie[160]=new m(l.map,0,1);ie[244]=new m(l.false,!1,1);ie[245]=new m(l.true,!0,1);ie[246]=new m(l.null,null,1);function Ts(t){switch(t.type){case l.false:return fe([244]);case l.true:return fe([245]);case l.null:return fe([246]);case l.bytes:return t.value.length?void 0:fe([64]);case l.string:return t.value===""?fe([96]):void 0;case l.array:return t.value===0?fe([128]):void 0;case l.map:return t.value===0?fe([160]):void 0;case l.uint:return t.value<24?fe([Number(t.value)]):void 0;case l.negint:if(t.value>=-24)return fe([31-Number(t.value)])}}var Lf={float64:!1,mapSorter:Tf,quickEncodeToken:Ts};function If(){let t=[];return t[l.uint.major]=Z,t[l.negint.major]=pr,t[l.bytes.major]=ct,t[l.string.major]=rs,t[l.array.major]=gr,t[l.map.major]=yr,t[l.tag.major]=xr,t[l.float.major]=br,t}var Ds=If(),jn=new Ut,vr=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(`${Rn} object contains circular references`);return new t(r,e)}},Ce={null:new m(l.null,null),undefined:new m(l.undefined,void 0),true:new m(l.true,!0),false:new m(l.false,!1),emptyArray:new m(l.array,0),emptyMap:new m(l.map,0)},Le={number(t,e,r,n){return!Number.isInteger(t)||!Number.isSafeInteger(t)?new m(l.float,t):t>=0?new m(l.uint,t):new m(l.negint,t)},bigint(t,e,r,n){return t>=BigInt(0)?new m(l.uint,t):new m(l.negint,t)},Uint8Array(t,e,r,n){return new m(l.bytes,t)},string(t,e,r,n){return new m(l.string,t)},boolean(t,e,r,n){return t?Ce.true:Ce.false},null(t,e,r,n){return Ce.null},undefined(t,e,r,n){return Ce.undefined},ArrayBuffer(t,e,r,n){return new m(l.bytes,new Uint8Array(t))},DataView(t,e,r,n){return new m(l.bytes,new Uint8Array(t.buffer,t.byteOffset,t.byteLength))},Array(t,e,r,n){if(!t.length)return r.addBreakTokens===!0?[Ce.emptyArray,new m(l.break)]:Ce.emptyArray;n=vr.createCheck(n,t);let o=[],i=0;for(let s of t)o[i++]=Er(s,r,n);return r.addBreakTokens?[new m(l.array,t.length),o,new m(l.break)]:[new m(l.array,t.length),o]},Object(t,e,r,n){let o=e!=="Object",i=o?t.keys():Object.keys(t),s=o?t.size:i.length;if(!s)return r.addBreakTokens===!0?[Ce.emptyMap,new m(l.break)]:Ce.emptyMap;n=vr.createCheck(n,t);let a=[],f=0;for(let c of i)a[f++]=[Er(c,r,n),Er(o?t.get(c):t[c],r,n)];return Af(a,r),r.addBreakTokens?[new m(l.map,s),a,new m(l.break)]:[new m(l.map,s),a]}};Le.Map=Le.Object;Le.Buffer=Le.Uint8Array;for(let t of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))Le[`${t}Array`]=Le.DataView;function Er(t,e={},r){let n=Ai(t),o=e&&e.typeEncoders&&e.typeEncoders[n]||Le[n];if(typeof o=="function"){let s=o(t,n,e,r);if(s!=null)return s}let i=Le[n];if(!i)throw new Error(`${Rn} unsupported type: ${n}`);return i(t,n,e,r)}function Af(t,e){e.mapSorter&&t.sort(e.mapSorter)}function Tf(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,i=Ds[o].compareTokens(r,n);return i===0&&console.warn("WARNING: complex key types used, CBOR key sorting guarantees are gone"),i}function Fs(t,e,r,n){if(Array.isArray(e))for(let o of e)Fs(t,o,r,n);else r[e.type.major](t,e,n)}function Df(t,e,r){let n=Er(t,r);if(!Array.isArray(n)&&r.quickEncodeToken){let o=r.quickEncodeToken(n);if(o)return o;let i=e[n.type.major];if(i.encodedSize){let s=i.encodedSize(n,r),a=new Ut(s);if(i(a,n,r),a.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${n} was wrong`);return On(a.chunks[0])}}return jn.reset(),Fs(jn,n,e,r),jn.toBytes(!0)}function Wn(t,e){return e=Object.assign({},Lf,e),Df(t,Ds,e)}var Ff={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},_r=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=ie[e];if(r===void 0){let n=p[e];if(!n)throw new Error(`${x} 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}},Mt=Symbol.for("DONE"),Sr=Symbol.for("BREAK");function kf(t,e,r){let n=[];for(let o=0;o<t.value;o++){let i=lt(e,r);if(i===Sr){if(t.value===1/0)break;throw new Error(`${x} got unexpected break to lengthed array`)}if(i===Mt)throw new Error(`${x} found array but not enough entries (got ${o}, expected ${t.value})`);n[o]=i}return n}function Uf(t,e,r){let n=r.useMaps===!0,o=n?void 0:{},i=n?new Map:void 0;for(let s=0;s<t.value;s++){let a=lt(e,r);if(a===Sr){if(t.value===1/0)break;throw new Error(`${x} got unexpected break to lengthed map`)}if(a===Mt)throw new Error(`${x} found map but not enough entries (got ${s} [no key], expected ${t.value})`);if(n!==!0&&typeof a!="string")throw new Error(`${x} non-string keys not supported (got ${typeof a})`);if(r.rejectDuplicateMapKeys===!0&&(n&&i.has(a)||!n&&a in o))throw new Error(`${x} found repeat map key "${a}"`);let f=lt(e,r);if(f===Mt)throw new Error(`${x} found map but not enough entries (got ${s} [no value], expected ${t.value})`);n?i.set(a,f):o[a]=f}return n?i:o}function lt(t,e){if(t.done())return Mt;let r=t.next();if(r.type===l.break)return Sr;if(r.type.terminal)return r.value;if(r.type===l.array)return kf(r,t,e);if(r.type===l.map)return Uf(r,t,e);if(r.type===l.tag){if(e.tags&&typeof e.tags[r.value]=="function"){let n=lt(t,e);return e.tags[r.value](n)}throw new Error(`${x} tag not supported (${r.value})`)}throw new Error("unsupported")}function ks(t,e){if(!(t instanceof Uint8Array))throw new Error(`${x} data to decode must be a Uint8Array`);e=Object.assign({},Ff,e);let r=e.tokenizer||new _r(t,e),n=lt(r,e);if(n===Mt)throw new Error(`${x} did not find any content to decode`);if(n===Sr)throw new Error(`${x} got unexpected break`);return[n,t.subarray(r.pos())]}function Gn(t,e){let[r,n]=ks(t,e);if(n.length>0)throw new Error(`${x} too many terminals, data makes no sense`);return r}var Cr=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},dt=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},Lr=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"},Ot=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};function Ir(t){return t[Symbol.asyncIterator]!=null}function Us(t,e){if(t.byteLength>e)throw new dt("Message length too long")}var Tr=t=>{let e=N(t),r=ee(e);return Xt(t,r),Tr.bytes=e,r};Tr.bytes=0;function Dr(t,e){e=e??{};let r=e.lengthEncoder??Tr,n=e?.maxDataLength??4194304;function*o(i){Us(i,n);let s=r(i.byteLength);s instanceof Uint8Array?yield s:yield*s,i instanceof Uint8Array?yield i:yield*i}return Ir(t)?(async function*(){for await(let i of t)yield*o(i)})():(function*(){for(let i of t)yield*o(i)})()}Dr.single=(t,e)=>{e=e??{};let r=e.lengthEncoder??Tr,n=e?.maxDataLength??4194304;return Us(t,n),new C(r(t.byteLength),t)};var Re;(function(t){t[t.LENGTH=0]="LENGTH",t[t.DATA=1]="DATA"})(Re||(Re={}));var Hn=t=>{let e=he(t);return Hn.bytes=N(e),e};Hn.bytes=0;function Rt(t,e){let r=new C,n=Re.LENGTH,o=-1,i=e?.lengthDecoder??Hn,s=e?.maxLengthLength??8,a=e?.maxDataLength??4194304;function*f(){for(;r.byteLength>0;){if(n===Re.LENGTH)try{if(o=i(r),o<0)throw new Cr("Invalid message length");if(o>a)throw new dt("Message length too long");let c=i.bytes;r.consume(c),e?.onLength!=null&&e.onLength(o),n=Re.DATA}catch(c){if(c instanceof RangeError){if(r.byteLength>s)throw new Lr("Message length length too long");break}throw c}if(n===Re.DATA){if(r.byteLength<o)break;let c=r.sublist(0,o);r.consume(o),e?.onData!=null&&e.onData(c),yield c,n=Re.LENGTH}}}return Ir(t)?(async function*(){for await(let c of t)r.append(c),yield*f();if(r.byteLength>0)throw new Ot("Unexpected end of input")})():(function*(){for(let c of t)r.append(c),yield*f();if(r.byteLength>0)throw new Ot("Unexpected end of input")})()}Rt.fromReader=(t,e)=>{let r=1,n=(async function*(){for(;;)try{let{done:i,value:s}=await t.next(r);if(i===!0)return;s!=null&&(yield s)}catch(i){if(i.code==="ERR_UNDER_READ")return{done:!0,value:null};throw i}finally{r=1}})();return Rt(n,{...e??{},onLength:i=>{r=i}})};var Kn=class extends Pe{sendMessage;dataQueue;encoding;constructor(e){super(e),this.sendMessage=e.sendMessage,this.encoding=e.encoding,this.dataQueue=new ne({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()}},Bs=30,Qn=class extends Dt{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)+Bs,this.encoding=r.encoding??"base64",this.input=ue(),this.sendMessage=this.sendMessage.bind(this),this.nextStreamId=this.maConn.direction==="outbound"?0:1,Promise.resolve().then(async()=>{for await(let n of Rt(this.input,{maxDataLength:this.maxMessageSize}))this.onMessage(Gn(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=Wn(e),n=Dr.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 Kn({...this.streamOptions,...n,id:e,direction:r,log:this.log.newScope(`stream:${r}:${e}`),sendMessage:this.sendMessage,encoding:this.encoding,maxMessageSize:this.maxMessageSize-Bs,protocol:""})}},Xn=class{protocol="/mock-muxer/1.0.0";init;constructor(e){this.init=e}createStreamMuxer(e){return new Qn(e,{...this.init})}};function Fr(t={}){return new Xn(t)}function Mf(t,e){if(typeof t=="string")return Of(t);if(typeof t=="number")return zf(t,e);throw Error(`Value provided to ms() must be a string or number. value=${JSON.stringify(t)}`)}var kr=Mf;function Of(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),i=n.toLowerCase();switch(i){case"years":case"year":case"yrs":case"yr":case"y":return o*315576e5;case"months":case"month":case"mo":return o*26298e5;case"weeks":case"week":case"w":return o*6048e5;case"days":case"day":case"d":return o*864e5;case"hours":case"hour":case"hrs":case"hr":case"h":return o*36e5;case"minutes":case"minute":case"mins":case"min":case"m":return o*6e4;case"seconds":case"second":case"secs":case"sec":case"s":return o*1e3;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return o;default:throw Error(`Unknown unit "${i}" provided to ms.parse(). value=${JSON.stringify(t)}`)}}function Rf(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 $f(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 zf(t,e){if(typeof t!="number"||!Number.isFinite(t))throw Error("Value provided to ms.format() must be of type number.");return e?.long?$f(t):Rf(t)}function $e(t,e,r,n){let o=e>=r*1.5;return`${Math.round(t/r)} ${n}${o?"s":""}`}function Jn(t){r.debug=r,r.default=r,r.coerce=f,r.disable=i,r.enable=o,r.enabled=s,r.humanize=kr,r.destroy=c,Object.keys(t).forEach(u=>{r[u]=t[u]}),r.names=[],r.skips=[],r.formatters={};function e(u){let d=0;for(let h=0;h<u.length;h++)d=(d<<5)-d+u.charCodeAt(h),d|=0;return r.colors[Math.abs(d)%r.colors.length]}r.selectColor=e;function r(u){let d,h=null,g,b;function w(...y){if(!w.enabled)return;let _=w,L=Number(new Date),I=L-(d||L);_.diff=I,_.prev=d,_.curr=L,d=L,y[0]=r.coerce(y[0]),typeof y[0]!="string"&&y.unshift("%O");let A=0;y[0]=y[0].replace(/%([a-zA-Z%])/g,(Q,z)=>{if(Q==="%%")return"%";A++;let X=r.formatters[z];if(typeof X=="function"){let ze=y[A];Q=X.call(_,ze),y.splice(A,1),A--}return Q}),r.formatArgs.call(_,y),(_.log||r.log).apply(_,y)}return w.namespace=u,w.useColors=r.useColors(),w.color=r.selectColor(u),w.extend=n,w.destroy=r.destroy,Object.defineProperty(w,"enabled",{enumerable:!0,configurable:!1,get:()=>h!==null?h:(g!==r.namespaces&&(g=r.namespaces,b=r.enabled(u)),b),set:y=>{h=y}}),typeof r.init=="function"&&r.init(w),w}function n(u,d){let h=r(this.namespace+(typeof d>"u"?":":d)+u);return h.log=this.log,h}function o(u){r.save(u),r.namespaces=u,r.names=[],r.skips=[];let d,h=(typeof u=="string"?u:"").split(/[\s,]+/),g=h.length;for(d=0;d<g;d++)h[d]&&(u=h[d].replace(/\*/g,".*?"),u[0]==="-"?r.skips.push(new RegExp("^"+u.substr(1)+"$")):r.names.push(new RegExp("^"+u+"$")))}function i(){let u=[...r.names.map(a),...r.skips.map(a).map(d=>"-"+d)].join(",");return r.enable(""),u}function s(u){if(u[u.length-1]==="*")return!0;let d,h;for(d=0,h=r.skips.length;d<h;d++)if(r.skips[d].test(u))return!1;for(d=0,h=r.names.length;d<h;d++)if(r.names[d].test(u))return!0;return!1}function a(u){return u.toString().substring(2,u.toString().length-2).replace(/\.\*\?$/,"*")}function f(u){return u instanceof Error?u.stack??u.message:u}function c(){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 Ur=Kf(),Vf=["#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 qf(){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 jf(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 Wf=console.debug??console.log??(()=>{});function Gf(t){try{t?Ur?.setItem("debug",t):Ur?.removeItem("debug")}catch{}}function Hf(){let t;try{t=Ur?.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 Qf(t){t.j=function(e){try{return JSON.stringify(e)}catch(r){return"[UnexpectedJSONParseError]: "+r.message}}}var Ps=Jn({formatArgs:jf,save:Gf,load:Hf,useColors:qf,setupFormatters:Qf,colors:Vf,storage:Ur,log:Wf});var R=Ps;R.formatters.b=t=>t==null?"undefined":J.baseEncode(t);R.formatters.t=t=>t==null?"undefined":ce.baseEncode(t);R.formatters.m=t=>t==null?"undefined":Xr.baseEncode(t);R.formatters.p=t=>t==null?"undefined":t.toString();R.formatters.c=t=>t==null?"undefined":t.toString();R.formatters.k=t=>t==null?"undefined":t.toString();R.formatters.a=t=>t==null?"undefined":t.toString();R.formatters.e=t=>{if(t==null)return"undefined";let e=Ns(t.message),r=Ns(t.stack);return e!=null&&r!=null?r.includes(e)?r:`${e}
|
|
3
|
+
${r}`:r??e??t.toString()};function Xf(t){let e=()=>{};return e.enabled=!1,e.color="",e.diff=0,e.log=()=>{},e.namespace=t,e.destroy=()=>!0,e.extend=()=>e,e}function $t(){return{forComponent(t){return Ms(t)}}}function Ms(t){let e=Xf(`${t}:trace`);return R.enabled(`${t}:trace`)&&R.names.map(r=>r.toString()).find(r=>r.includes(":trace"))!=null&&(e=R(`${t}:trace`)),Object.assign(R(t),{error:R(`${t}:error`),trace:e,newScope:r=>Ms(`${t}:${r}`)})}function Ns(t){if(t!=null&&(t=t.trim(),t.length!==0))return t}var Jf=0,Zn=class extends Pe{local;remote;constructor(e){let r=`${Jf++}`;super({...e,id:r,log:$t().forComponent(`libp2p:stream-pair:${e.direction}:${r}`)}),this.local=e.local,this.remote=e.remote,this.local.addEventListener("drain",()=>{this.safeDispatchEvent("drain")}),this.remote.addEventListener("message",n=>{this.onData(n.data)}),this.remote.addEventListener("reset",n=>{this.onRemoteReset()}),this.remote.addEventListener("closeWrite",n=>{this.onRemoteCloseWrite()})}sendData(e){let r=this.local.send(new se(e));return{sentBytes:e.byteLength,canSendMore:r}}sendReset(){this.local.send(new Event("reset"))}async sendCloseWrite(e){return O(new Promise((r,n)=>{this.local.send(new Event("closeWrite")),this.local.onIdle().then(r,n)}),e?.signal)}async sendCloseRead(e){return O(new Promise((r,n)=>{this.local.send(new Event("closeRead")),this.local.onIdle().then(r,n)}),e?.signal)}sendPause(){this.local.send(new Event("pause"))}sendResume(){this.local.send(new Event("resume"))}onRemotePaused(){this.local.pause()}onRemoteResumed(){this.local.resume()}onMuxerDrain(){this.local.resume()}};var Os=()=>{let t=new Error("Delay aborted");return t.name="AbortError",t},Zf=new WeakMap;function Yf({clearTimeout:t,setTimeout:e}={}){return(r,{value:n,signal:o}={})=>{if(o?.aborted)return Promise.reject(Os());let i,s,a,f=t??clearTimeout,c=()=>{f(i),a(Os())},u=()=>{o&&o.removeEventListener("abort",c)},d=new Promise((h,g)=>{s=()=>{u(),h(n)},a=g,i=(e??setTimeout)(s,r)});return o&&o.addEventListener("abort",c,{once:!0}),Zf.set(d,()=>{f(i),i=null,s()}),d}}var el=Yf(),Yn=el;var tl=1024*64,zt=class extends ae{needsDrain;queue;capacity;delay;log;chunkSize;constructor(e){super(),this.needsDrain=!1,this.queue=new ne({concurrency:1}),this.capacity=e.capacity??5,this.delay=e.delay??0,this.log=e.log,this.chunkSize=e.chunkSize??tl,this.queue.addEventListener("idle",()=>{this.needsDrain?(this.log("network send queue drained"),this.needsDrain=!1,this.safeDispatchEvent("drain")):this.log("network send queue idle")})}send(e){if(rl(e)){let r=new C(e.data);for(;r.byteLength>0;){let n=Math.min(this.chunkSize,r.byteLength),o=r.sublist(0,n);r.consume(o.byteLength);let i=new se(o);this.queue.add(async s=>{this.delay>0&&await O(Yn(this.delay),s.signal),this.dispatchEvent(s.evt)},{evt:i})}}else this.queue.add(async r=>{this.delay>0&&await O(Yn(this.delay),r.signal),this.dispatchEvent(r.evt)},{evt:e});return this.queue.size>=this.capacity?(this.log("network send queue full"),this.needsDrain=!0,!1):!0}pause(){this.queue.pause()}resume(){this.queue.resume()}onIdle(){return this.queue.onIdle()}size(){return this.queue.size}};function rl(t){return t?.data instanceof Uint8Array||Xe(t?.data)}var Rs=0,Br=class extends Tt{local;remote;constructor(e){super(e),this.local=e.local,this.remote=e.remote,this.local.addEventListener("drain",()=>{this.safeDispatchEvent("drain")}),this.remote.addEventListener("message",r=>{this.status==="open"&&this.onData(r.data)}),this.remote.addEventListener("reset",r=>{this.status==="open"&&this.onRemoteReset()}),this.remote.addEventListener("close",r=>{this.onTransportClosed()}),this.remote.addEventListener("pause",r=>{this.local.pause()}),this.remote.addEventListener("resume",r=>{this.local.resume()})}sendData(e){let r=this.local.send(new se(e));return{sentBytes:e.byteLength,canSendMore:r}}sendReset(){this.local.send(new Event("reset"))}async sendClose(e){return this.local.needsDrain&&await D(this.local,"drain",{signal:e?.signal}),O(new Promise((r,n)=>{this.local.send(new Event("close")),this.local.onIdle().then(r,n)}),e?.signal)}sendPause(){this.local.send(new Event("pause"))}sendResume(){this.local.send(new Event("resume"))}};function eo(t={}){let e=`${Rs++}`,r=`${Rs++}`,n=$t().forComponent(`libp2p:mock-maconn:outbound:${e}`),o=$t().forComponent(`libp2p:mock-maconn:inbound:${r}`),i=new zt({...t,log:n}),s=new zt({...t,log:o});return[new Br({...t.outbound,id:r,direction:"outbound",local:i,remote:s,remoteAddr:t?.outbound?.remoteAddr??Se(`/ip4/127.0.0.1/tcp/${r}`),log:n}),new Br({...t.inbound,id:e,direction:"inbound",local:s,remote:i,remoteAddr:t?.inbound?.remoteAddr??Se(`/ip4/127.0.0.1/tcp/${e}`),log:o})]}var to=class extends ne{has(e){return this.find(e)!=null}find(e){return this.queue.find(r=>e.equals(r.options.peerId))}};var ro=class extends ne{constructor(e={}){super({...e,sort:(r,n)=>r.options.priority>n.options.priority?-1:r.options.priority<n.options.priority?1:0})}};var no=class{memoryStorage;points;duration;blockDuration;keyPrefix;constructor(e={}){this.points=e.points??4,this.duration=e.duration??1,this.blockDuration=e.blockDuration??0,this.keyPrefix=e.keyPrefix??"rlflx",this.memoryStorage=new Pr}consume(e,r=1,n={}){let o=this.getKey(e),i=this._getKeySecDuration(n),s=this.memoryStorage.incrby(o,r,i);if(s.remainingPoints=Math.max(this.points-s.consumedPoints,0),s.consumedPoints>this.points)throw this.blockDuration>0&&s.consumedPoints<=this.points+r&&(s=this.memoryStorage.set(o,s.consumedPoints,this.blockDuration)),new Lt("Rate limit exceeded",s);return s}penalty(e,r=1,n={}){let o=this.getKey(e),i=this._getKeySecDuration(n),s=this.memoryStorage.incrby(o,r,i);return s.remainingPoints=Math.max(this.points-s.consumedPoints,0),s}reward(e,r=1,n={}){let o=this.getKey(e),i=this._getKeySecDuration(n),s=this.memoryStorage.incrby(o,-r,i);return s.remainingPoints=Math.max(this.points-s.consumedPoints,0),s}block(e,r){let n=r*1e3,o=this.points+1;return this.memoryStorage.set(this.getKey(e),o,r),{remainingPoints:0,msBeforeNext:n===0?-1:n,consumedPoints:o,isFirstInDuration:!1}}set(e,r,n=0){let o=(n>=0?n:this.duration)*1e3;return this.memoryStorage.set(this.getKey(e),r,n),{remainingPoints:0,msBeforeNext:o===0?-1:o,consumedPoints:r,isFirstInDuration:!1}}get(e){let r=this.memoryStorage.get(this.getKey(e));return r!=null&&(r.remainingPoints=Math.max(this.points-r.consumedPoints,0)),r}delete(e){this.memoryStorage.delete(this.getKey(e))}_getKeySecDuration(e){return e?.customDuration!=null&&e.customDuration>=0?e.customDuration:this.duration}getKey(e){return this.keyPrefix.length>0?`${this.keyPrefix}:${e}`:e}parseKey(e){return e.substring(this.keyPrefix.length)}},Pr=class{storage;constructor(){this.storage=new Map}incrby(e,r,n){let o=this.storage.get(e);if(o!=null){let i=o.expiresAt!=null?o.expiresAt.getTime()-new Date().getTime():-1;return o.expiresAt==null||i>0?(o.value+=r,{remainingPoints:0,msBeforeNext:i,consumedPoints:o.value,isFirstInDuration:!1}):this.set(e,r,n)}return this.set(e,r,n)}set(e,r,n){let o=n*1e3,i=this.storage.get(e);i!=null&&clearTimeout(i.timeoutId);let s={value:r,expiresAt:o>0?new Date(Date.now()+o):void 0};return this.storage.set(e,s),o>0&&(s.timeoutId=setTimeout(()=>{this.storage.delete(e)},o),s.timeoutId.unref!=null&&s.timeoutId.unref()),{remainingPoints:0,msBeforeNext:o===0?-1:o,consumedPoints:s.value,isFirstInDuration:!0}}get(e){let r=this.storage.get(e);if(r!=null)return{remainingPoints:0,msBeforeNext:r.expiresAt!=null?r.expiresAt.getTime()-new Date().getTime():-1,consumedPoints:r.value,isFirstInDuration:!1}}delete(e){let r=this.storage.get(e);return r!=null?(r.timeoutId!=null&&clearTimeout(r.timeoutId),this.storage.delete(e),!0):!1}};function nl(t,e,r){let n,o,i=!1;function s(){let c={signal:o.signal};if(r?.timeout!=null){let u=ir([o.signal,AbortSignal.timeout(r.timeout)]);c.signal=u}i=!0,Promise.resolve().then(async()=>{await t(c)}).catch(()=>{}).finally(()=>{i=!1,!o.signal.aborted&&(n=setTimeout(s,e))})}let a=et(s,r?.debounce??100),f=!1;return{setInterval:c=>{e!==c&&(e=c,n!=null&&(clearTimeout(n),n=setTimeout(s,e)))},setTimeout:c=>{r??={},r.timeout=c},run:()=>{i||(clearTimeout(n),a())},start:()=>{f||(f=!0,o=new AbortController,o.signal,r?.runImmediately===!0?queueMicrotask(()=>{s()}):n=setTimeout(s,e))},stop:()=>{clearTimeout(n),o?.abort(),f=!1}}}async function $s(t={}){let[e,r]=eo({...t,outbound:t.outboundConnection,inbound:t.inboundConnection}),n=Fr({streamOptions:t.outbound}).createStreamMuxer(e),o=Fr({streamOptions:t.inbound}).createStreamMuxer(r),[i,s]=await Promise.all([D(o,"stream").then(a=>a.detail),n.createStream({...t.outbound,protocol:t.protocol})]);return[s,i]}async function ol(t={}){let[e,r]=await $s(t);return Pn(r),e}function il(t){let{name:e,metrics:r}=t,n=[];return r?.registerMetric(e,{calculate:()=>n.length}),n}var oo=class extends Map{metric;constructor(e){super();let{name:r,metrics:n}=e;this.metric=n.registerMetric(r),this.updateComponentMetric()}set(e,r){return super.set(e,r),this.updateComponentMetric(),this}delete(e){let r=super.delete(e);return this.updateComponentMetric(),r}clear(){super.clear(),this.updateComponentMetric()}updateComponentMetric(){this.metric.update(this.size)}};function sl(t){let{name:e,metrics:r}=t,n;return r!=null?n=new oo({name:e,metrics:r}):n=new Map,n}return Ks(al);})();
|
|
4
4
|
/*! Bundled license information:
|
|
5
5
|
|
|
6
6
|
@noble/hashes/esm/utils.js:
|