@libp2p/utils 7.2.3-f144def15 → 7.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.min.js CHANGED
@@ -1,14 +1,14 @@
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 gc=Object.create;var lr=Object.defineProperty;var bc=Object.getOwnPropertyDescriptor;var yc=Object.getOwnPropertyNames;var xc=Object.getPrototypeOf,wc=Object.prototype.hasOwnProperty;var _n=(t,e)=>()=>{try{return e||t((e={exports:{}}).exports,e),e.exports}catch(r){throw e=0,r}},X=(t,e)=>{for(var r in e)lr(t,r,{get:e[r],enumerable:!0})},Is=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of yc(e))!wc.call(t,o)&&o!==r&&lr(t,o,{get:()=>e[o],enumerable:!(n=bc(e,o))||n.enumerable});return t};var Ec=(t,e,r)=>(r=t!=null?gc(xc(t)):{},Is(e||!t||!t.__esModule?lr(r,"default",{value:t,enumerable:!0}):r,t)),_c=t=>Is(lr({},"__esModule",{value:!0}),t);var to=_n(mt=>{"use strict";Object.defineProperty(mt,"__esModule",{value:!0});mt.Netmask4Impl=void 0;mt.ip2long=dt;mt.long2ip=pe;function pe(t){let e=(t&-16777216)>>>24,r=(t&255<<16)>>>16,n=(t&65280)>>>8,o=t&255;return[e,r,n,o].join(".")}var Qu=48,Xu=97,Ku=65;function Ju(t){let e=0,r=10,n="9",o=0;t.length>1&&t[o]==="0"&&(t[o+1]==="x"||t[o+1]==="X"?(o+=2,r=16):"0"<=t[o+1]&&t[o+1]<="9"&&(o++,r=8,n="7"));let s=o;for(;o<t.length;){if("0"<=t[o]&&t[o]<=n)e=e*r+(t.charCodeAt(o)-Qu)>>>0;else if(r===16)if("a"<=t[o]&&t[o]<="f")e=e*r+(10+t.charCodeAt(o)-Xu)>>>0;else if("A"<=t[o]&&t[o]<="F")e=e*r+(10+t.charCodeAt(o)-Ku)>>>0;else break;else break;if(e>4294967295)throw new Error("too large");o++}if(o===s)throw new Error("empty octet");return[e,o]}function dt(t){let e=[];for(let r=0;r<=3&&t.length!==0;r++){if(r>0){if(t[0]!==".")throw new Error("Invalid IP");t=t.substring(1)}let[n,o]=Ju(t);t=t.substring(o),e.push(n)}if(t.length!==0)throw new Error("Invalid IP");switch(e.length){case 1:if(e[0]>4294967295)throw new Error("Invalid IP");return e[0]>>>0;case 2:if(e[0]>255||e[1]>16777215)throw new Error("Invalid IP");return(e[0]<<24|e[1])>>>0;case 3:if(e[0]>255||e[1]>255||e[2]>65535)throw new Error("Invalid IP");return(e[0]<<24|e[1]<<16|e[2])>>>0;case 4:if(e[0]>255||e[1]>255||e[2]>255||e[3]>255)throw new Error("Invalid IP");return(e[0]<<24|e[1]<<16|e[2]<<8|e[3])>>>0;default:throw new Error("Invalid IP")}}var eo=class t{constructor(e,r){if(typeof e!="string")throw new Error("Missing `net' parameter");let n=r;if(!n){let o=e.split("/",2);e=o[0],n=o[1]}if(n||(n=32),typeof n=="string"&&n.indexOf(".")>-1){try{this.maskLong=dt(n)}catch{throw new Error("Invalid mask: "+n)}this.bitmask=NaN;for(let o=32;o>=0;o--)if(this.maskLong===4294967295<<32-o>>>0){this.bitmask=o;break}}else if(n||n===0)this.bitmask=parseInt(n,10),this.maskLong=0,this.bitmask>0&&(this.maskLong=4294967295<<32-this.bitmask>>>0);else throw new Error("Invalid mask: empty");try{this.netLong=(dt(e)&this.maskLong)>>>0}catch{throw new Error("Invalid net address: "+e)}if(!(this.bitmask<=32))throw new Error("Invalid mask for ip4: "+n);this.size=Math.pow(2,32-this.bitmask),this.base=pe(this.netLong),this.mask=pe(this.maskLong),this.hostmask=pe(~this.maskLong),this.first=this.bitmask<=30?pe(this.netLong+1):this.base,this.last=this.bitmask<=30?pe(this.netLong+this.size-2):pe(this.netLong+this.size-1),this.broadcast=this.bitmask<=30?pe(this.netLong+this.size-1):void 0}contains(e){return typeof e=="string"&&(e.indexOf("/")>0||e.split(".").length!==4)&&(e=new t(e)),e instanceof t?this.contains(e.base)&&this.contains(e.broadcast||e.last):(dt(e)&this.maskLong)>>>0===(this.netLong&this.maskLong)>>>0}next(e=1){return new t(pe(this.netLong+this.size*e),this.mask)}forEach(e){let r=dt(this.first),n=dt(this.last),o=0;for(;r<=n;)e(pe(r),r,o),o++,r++}toString(){return this.base+"/"+this.bitmask}};mt.Netmask4Impl=eo});var fi=_n(pt=>{"use strict";Object.defineProperty(pt,"__esModule",{value:!0});pt.Netmask6Impl=void 0;pt.ip6bigint=no;pt.bigint2ip6=Qe;var Yu=to(),ro=(1n<<128n)-1n;function no(t){let e=t.indexOf("%");e!==-1&&(t=t.substring(0,e));let r=t.lastIndexOf(":");if(r!==-1&&t.indexOf(".",r)!==-1){let n=t.substring(r+1),o=(0,Yu.ip2long)(n),s=t.substring(0,r+1)+"0:0";return ui(s)&~0xffffffffn|BigInt(o)}return ui(t)}function ui(t){let e=t.indexOf("::"),r;if(e!==-1){let o=t.substring(0,e),s=t.substring(e+2),i=o===""?[]:o.split(":"),a=s===""?[]:s.split(":"),u=8-i.length-a.length;if(u<0)throw new Error("Invalid IPv6: too many groups");r=[...i,...Array(u).fill("0"),...a]}else r=t.split(":");if(r.length!==8)throw new Error("Invalid IPv6: expected 8 groups, got "+r.length);let n=0n;for(let o=0;o<8;o++){let s=r[o];if(s.length===0||s.length>4)throw new Error('Invalid IPv6: bad group "'+s+'"');let i=parseInt(s,16);if(isNaN(i)||i<0||i>65535)throw new Error('Invalid IPv6: bad group "'+s+'"');n=n<<16n|BigInt(i)}return n}function Qe(t){if(t<0n||t>ro)throw new Error("Invalid IPv6 address value");let e=[];for(let i=0;i<8;i++)e.unshift(Number(t&0xffffn)),t>>=16n;let r=-1,n=0,o=-1,s=0;for(let i=0;i<8;i++)e[i]===0?o===-1?(o=i,s=1):s++:(s>n&&s>=2&&(r=o,n=s),o=-1,s=0);if(s>n&&s>=2&&(r=o,n=s),r!==-1&&r+n===8&&r>0)return e.slice(0,r).map(a=>a.toString(16)).join(":")+"::";if(r===0)return"::"+e.slice(n).map(a=>a.toString(16)).join(":");if(r>0){let i=e.slice(0,r).map(u=>u.toString(16)),a=e.slice(r+n).map(u=>u.toString(16));return i.join(":")+"::"+a.join(":")}else return e.map(i=>i.toString(16)).join(":")}var oo=class t{constructor(e,r){if(typeof e!="string")throw new Error("Missing `net' parameter");let n=r;if(n==null){let o=e.indexOf("/");o!==-1?(n=parseInt(e.substring(o+1),10),e=e.substring(0,o)):n=128}if(isNaN(n)||n<0||n>128)throw new Error("Invalid mask for IPv6: "+n);this.bitmask=n,this.bitmask===0?this.maskBigint=0n:this.maskBigint=ro>>BigInt(128-this.bitmask)<<BigInt(128-this.bitmask);try{this.netBigint=no(e)&this.maskBigint}catch{throw new Error("Invalid IPv6 net address: "+e)}this.size=Number(1n<<BigInt(128-this.bitmask)),this.base=Qe(this.netBigint),this.mask=Qe(this.maskBigint),this.hostmask=Qe(~this.maskBigint&ro),this.first=this.base,this.last=Qe(this.netBigint+(1n<<BigInt(128-this.bitmask))-1n),this.broadcast=void 0}contains(e){return typeof e=="string"&&e.indexOf("/")>0&&(e=new t(e)),e instanceof t?this.contains(e.base)&&this.contains(e.last):(no(e)&this.maskBigint)===this.netBigint}next(e=1){let r=1n<<BigInt(128-this.bitmask);return new t(Qe(this.netBigint+r*BigInt(e)),this.bitmask)}forEach(e){let r=this.netBigint,n=1n<<BigInt(128-this.bitmask),o=this.netBigint+n-1n,s=0;for(;r<=o;)e(Qe(r),Number(r),s),s++,r++}toString(){return this.base+"/"+this.bitmask}};pt.Netmask6Impl=oo});var li=_n(Ne=>{"use strict";Object.defineProperty(Ne,"__esModule",{value:!0});Ne.long2ip=Ne.ip2long=Ne.Netmask=void 0;var Sr=to();Object.defineProperty(Ne,"ip2long",{enumerable:!0,get:function(){return Sr.ip2long}});Object.defineProperty(Ne,"long2ip",{enumerable:!0,get:function(){return Sr.long2ip}});var Zu=fi(),so=class t{constructor(e,r){if(typeof e!="string")throw new Error("Missing `net' parameter");(e.indexOf("/")!==-1?e.substring(0,e.indexOf("/")):e).indexOf(":")!==-1?this._impl=new Zu.Netmask6Impl(e,r):this._impl=new Sr.Netmask4Impl(e,r),this.base=this._impl.base,this.mask=this._impl.mask,this.hostmask=this._impl.hostmask,this.bitmask=this._impl.bitmask,this.size=this._impl.size,this.first=this._impl.first,this.last=this._impl.last,this.broadcast=this._impl.broadcast,this._impl instanceof Sr.Netmask4Impl?(this.maskLong=this._impl.maskLong,this.netLong=this._impl.netLong):(this.maskLong=0,this.netLong=0)}contains(e){return typeof e=="string"&&(e.indexOf("/")>0?e=new t(e):e.indexOf(":")===-1&&e.split(".").length!==4&&(e=new t(e))),e instanceof t?this.contains(e.base)&&this.contains(e.broadcast||e.last):this._impl.contains(e)}next(e=1){let r=this._impl.next(e);return new t(r.base,r.bitmask)}forEach(e){this._impl.forEach(e)}toString(){return this._impl.toString()}};Ne.Netmask=so});var Dh={};X(Dh,{AbstractMessageStream:()=>Je,AbstractMultiaddrConnection:()=>Xt,AbstractStream:()=>Ye,AbstractStreamMuxer:()=>Kt,AdaptiveTimeout:()=>Ko,BloomFilter:()=>Ut,CuckooFilter:()=>De,DEFAULT_FAILURE_MULTIPLIER:()=>Ri,DEFAULT_INTERVAL:()=>Vi,DEFAULT_MAX_TIMEOUT:()=>zi,DEFAULT_MIN_TIMEOUT:()=>$i,DEFAULT_TIMEOUT_MULTIPLIER:()=>Oi,InvalidDataLengthError:()=>Qr,InvalidDataLengthLengthError:()=>Xr,InvalidMessageLengthError:()=>vt,LengthPrefixedDecoder:()=>ts,MaxEarlyStreamsError:()=>Ht,MemoryStorage:()=>En,MockStream:()=>xs,MovingAverage:()=>Ze,PeerQueue:()=>_s,PriorityQueue:()=>vs,Queue:()=>ue,QueueFullError:()=>Gt,RateLimitError:()=>qt,RateLimiter:()=>Ss,ScalableCuckooFilter:()=>Ot,StreamClosedError:()=>Qt,UnexpectedEOFError:()=>Ue,UnwrappedError:()=>Jt,byteStream:()=>Xi,circuitRelayAddressesLast:()=>Mi,createBloomFilter:()=>Zs,createCuckooFilter:()=>ei,createScalableCuckooFilter:()=>ti,debounce:()=>_t,defaultMultiaddrSorter:()=>Gf,echo:()=>es,echoStream:()=>Lh,getNetConfig:()=>ae,getThinWaistAddresses:()=>Zf,ipPortToMultiaddr:()=>tl,isAsyncGenerator:()=>rl,isGenerator:()=>nl,isGlobalUnicast:()=>qu,isGlobalUnicastIp:()=>el,isLinkLocal:()=>Gu,isLinkLocalIp:()=>wl,isLoopback:()=>vr,isNetworkAddress:()=>Hu,isPrivate:()=>Cr,isPrivateIp:()=>ao,isPromise:()=>Xo,loopbackAddressLast:()=>Ni,lpStream:()=>Ki,messageStreamToDuplex:()=>Ji,mockMuxer:()=>bn,multiaddrConnectionPair:()=>Es,pbStream:()=>pl,pipe:()=>bl,publicAddressesFirst:()=>Fi,reliableTransportsFirst:()=>Bi,repeatingTask:()=>Ih,streamPair:()=>mc,trackedList:()=>Th,trackedMap:()=>Ah,tryGetNetConfig:()=>yr});function H(t=0){return new Uint8Array(t)}function K(t=0){return new Uint8Array(t)}function vc(t){return t?.buffer instanceof ArrayBuffer}function vn(t){if(vc(t))return t;let e=t.slice();return new Uint8Array(e.buffer,0,e.byteLength)}function we(t,e){e==null&&(e=t.reduce((o,s)=>o+s.length,0));let r=K(e),n=0;for(let o of t)r.set(o,n),n+=o.length;return vn(r)}function Ve(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}var Ts=Symbol.for("@achingbrain/uint8arraylist");function Ls(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 nt(t){return!!t?.[Ts]}var N=class t{bufs;length;[Ts]=!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(nt(n)){r+=n.byteLength;for(let o of n.bufs)this.bufs.push(o)}else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}prepend(...e){this.prependAll(e)}prependAll(e){let r=0;for(let n of e.reverse())if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.unshift(n);else if(nt(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=Ls(this.bufs,e);return r.buf[r.index]}set(e,r){let n=Ls(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(nt(e))for(let n=0;n<e.length;n++)this.set(r+n,e.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(e){if(e=Math.trunc(e),!(Number.isNaN(e)||e<=0)){if(e===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(e>=this.bufs[0].byteLength)e-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(e),this.length-=e;break}}}slice(e,r){let{bufs:n,length:o}=this._subList(e,r);return we(n,o)}subarray(e,r){let{bufs:n,length:o}=this._subList(e,r);return n.length===1?n[0]:we(n,o)}sublist(e,r){let{bufs:n,length:o}=this._subList(e,r),s=new t;return s.length=o,s.bufs=n,s}_subList(e,r){if(e=e??0,r=r??this.length,e<0&&(e=this.length+e),r<0&&(r=this.length+r),e<0||r>this.length)throw new RangeError("index is out of bounds");if(e===r)return{bufs:[],length:0};if(e===0&&r===this.length)return{bufs:[...this.bufs],length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],a=o,u=a+i.byteLength;if(o=u,e>=u)continue;let l=e>=a&&e<u,f=r>a&&r<=u;if(l&&f){if(e===a&&r===u){n.push(i);break}let h=e-a;n.push(i.subarray(h,h+(r-e)));break}if(l){if(e===0){n.push(i);continue}n.push(i.subarray(e-a));continue}if(f){if(r===u){n.push(i);break}n.push(i.subarray(0,r-a));break}n.push(i)}return{bufs:n,length:r-e}}indexOf(e,r=0){if(!nt(e)&&!(e instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=e instanceof Uint8Array?e:e.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),e.length===0)return r>this.length?this.length:r;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let h=0;h<s;h++)i[h]=-1;for(let h=0;h<o;h++)i[n[h]]=h;let a=i,u=this.byteLength-n.byteLength,l=n.byteLength-1,f;for(let h=r;h<=u;h+=f){f=0;for(let p=l;p>=0;p--){let x=this.get(h+p);if(n[p]!==x){f=Math.max(1,p-a[x]);break}}if(f===0)return h}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=K(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=H(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=H(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=H(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=K(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=H(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=H(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=H(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=H(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=H(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(!Ve(this.bufs[r],e.bufs[r]))return!1;return!0}static fromUint8Arrays(e,r){let n=new t;return n.bufs=e,r==null&&(r=e.reduce((o,s)=>o+s.byteLength,0)),n.length=r,n}};var Tn={};X(Tn,{base10:()=>kc});var Vh=new Uint8Array(0);function As(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 Ee(t){if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return je(t);if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return je(new Uint8Array(t.buffer,t.byteOffset,t.byteLength));throw new Error("Unknown type, must be binary type")}function Ds(t){return new TextEncoder().encode(t)}function ks(t){return new TextDecoder().decode(t)}function Sc(t){return t?.buffer instanceof ArrayBuffer}function je(t){return Sc(t)?t:t.slice()}function Cc(t,e){if(t.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var o=0;o<t.length;o++){var s=t.charAt(o),i=s.charCodeAt(0);if(r[i]!==255)throw new TypeError(s+" is ambiguous");r[i]=o}var a=t.length,u=t.charAt(0),l=Math.log(a)/Math.log(256),f=Math.log(256)/Math.log(a);function h(E){if(E instanceof Uint8Array||(ArrayBuffer.isView(E)?E=new Uint8Array(E.buffer,E.byteOffset,E.byteLength):Array.isArray(E)&&(E=Uint8Array.from(E))),!(E instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(E.length===0)return"";for(var L=0,y=0,_=0,k=E.length;_!==k&&E[_]===0;)_++,L++;for(var P=(k-_)*f+1>>>0,q=new Uint8Array(P);_!==k;){for(var $=E[_],xe=0,G=P-1;($!==0||xe<y)&&G!==-1;G--,xe++)$+=256*q[G]>>>0,q[G]=$%a>>>0,$=$/a>>>0;if($!==0)throw new Error("Non-zero carry");y=xe,_++}for(var se=P-y;se!==P&&q[se]===0;)se++;for(var ze=u.repeat(L);se<P;++se)ze+=t.charAt(q[se]);return ze}function p(E){if(typeof E!="string")throw new TypeError("Expected String");if(E.length===0)return new Uint8Array;var L=0;if(E[L]!==" "){for(var y=0,_=0;E[L]===u;)y++,L++;for(var k=(E.length-L)*l+1>>>0,P=new Uint8Array(k);E[L];){var q=r[E.charCodeAt(L)];if(q===255)return;for(var $=0,xe=k-1;(q!==0||$<_)&&xe!==-1;xe--,$++)q+=a*P[xe]>>>0,P[xe]=q%256>>>0,q=q/256>>>0;if(q!==0)throw new Error("Non-zero carry");_=$,L++}if(E[L]!==" "){for(var G=k-_;G!==k&&P[G]===0;)G++;for(var se=new Uint8Array(y+(k-G)),ze=y;G!==k;)se[ze++]=P[G++];return se}}}function x(E){var L=p(E);if(L)return L;throw new Error(`Non-${e} character`)}return{encode:h,decodeUnsafe:p,decode:x}}var Ic=Cc,Lc=Ic,Bs=Lc;var Sn=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")}},Cn=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 Ns(this,e)}},In=class{decoders;constructor(e){this.decoders=e}or(e){return Ns(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 Ns(t,e){return new In({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var Ln=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 Sn(e,r,n),this.decoder=new Cn(e,r,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function ot({name:t,prefix:e,encode:r,decode:n}){return new Ln(t,e,r,n)}function Te({name:t,prefix:e,alphabet:r}){let{encode:n,decode:o}=Bs(r,t);return ot({prefix:e,name:t,encode:n,decode:s=>Ee(o(s))})}function Tc(t,e,r,n){let o=t.length;for(;t[o-1]==="=";)--o;let s=new Uint8Array(o*r/8|0),i=0,a=0,u=0;for(let l=0;l<o;++l){let f=e[t[l]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|f,i+=r,i>=8&&(i-=8,s[u++]=255&a>>i)}if(i>=r||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function Ac(t,e,r){let n=e[e.length-1]==="=",o=(1<<r)-1,s="",i=0,a=0;for(let u=0;u<t.length;++u)for(a=a<<8|t[u],i+=8;i>r;)i-=r,s+=e[o&a>>i];if(i!==0&&(s+=e[o&a<<r-i]),n)for(;(s.length*r&7)!==0;)s+="=";return s}function Dc(t){let e={};for(let r=0;r<t.length;++r)e[t[r]]=r;return e}function B({name:t,prefix:e,bitsPerChar:r,alphabet:n}){let o=Dc(n);return ot({prefix:e,name:t,encode(s){return Ac(s,n,r)},decode(s){return Tc(s,o,r,t)}})}var kc=Te({prefix:"9",name:"base10",alphabet:"0123456789"});var An={};X(An,{base16:()=>Pc,base16upper:()=>Bc});var Pc=B({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Bc=B({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Dn={};X(Dn,{base2:()=>Nc});var Nc=B({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var kn={};X(kn,{base256emoji:()=>Rc});var Fs=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}"),Fc=Fs.reduce((t,e,r)=>(t[r]=e,t),[]),Mc=Fs.reduce((t,e,r)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return t[n]=r,t},[]);function Uc(t){return t.reduce((e,r)=>(e+=Fc[r],e),"")}function Oc(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=Mc[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(o)}return new Uint8Array(e)}var Rc=ot({prefix:"\u{1F680}",name:"base256emoji",encode:Uc,decode:Oc});var Pn={};X(Pn,{base32:()=>he,base32hex:()=>jc,base32hexpad:()=>qc,base32hexpadupper:()=>Gc,base32hexupper:()=>Wc,base32pad:()=>zc,base32padupper:()=>Vc,base32upper:()=>$c,base32z:()=>Hc});var he=B({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),$c=B({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),zc=B({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Vc=B({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),jc=B({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Wc=B({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),qc=B({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Gc=B({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Hc=B({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Bn={};X(Bn,{base36:()=>kt,base36upper:()=>Qc});var kt=Te({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Qc=Te({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Nn={};X(Nn,{base58btc:()=>te,base58flickr:()=>Xc});var te=Te({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Xc=Te({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Un={};X(Un,{base64:()=>Fn,base64pad:()=>Kc,base64url:()=>Mn,base64urlpad:()=>Jc});var Fn=B({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Kc=B({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Mn=B({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Jc=B({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var On={};X(On,{base8:()=>Yc});var Yc=B({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Rn={};X(Rn,{identity:()=>Zc});var Zc=ot({prefix:"\0",name:"identity",encode:t=>ks(t),decode:t=>Ds(t)});var od=new TextEncoder,sd=new TextDecoder;var zn={};X(zn,{identity:()=>_u});var ru=Os,Ms=128,nu=127,ou=~nu,su=Math.pow(2,31);function Os(t,e,r){e=e||[],r=r||0;for(var n=r;t>=su;)e[r++]=t&255|Ms,t/=128;for(;t&ou;)e[r++]=t&255|Ms,t>>>=7;return e[r]=t|0,Os.bytes=r-n+1,e}var iu=$n,au=128,Us=127;function $n(t,n){var r=0,n=n||0,o=0,s=n,i,a=t.length;do{if(s>=a)throw $n.bytes=0,new RangeError("Could not decode varint");i=t[s++],r+=o<28?(i&Us)<<o:(i&Us)*Math.pow(2,o),o+=7}while(i>=au);return $n.bytes=s-n,r}var cu=Math.pow(2,7),uu=Math.pow(2,14),fu=Math.pow(2,21),lu=Math.pow(2,28),hu=Math.pow(2,35),du=Math.pow(2,42),mu=Math.pow(2,49),pu=Math.pow(2,56),gu=Math.pow(2,63),bu=function(t){return t<cu?1:t<uu?2:t<fu?3:t<lu?4:t<hu?5:t<du?6:t<mu?7:t<pu?8:t<gu?9:10},yu={encode:ru,decode:iu,encodingLength:bu},xu=yu,Pt=xu;function Bt(t,e=0){return[Pt.decode(t,e),Pt.decode.bytes]}function st(t,e,r=0){return Pt.encode(t,e,r),e}function it(t){return Pt.encodingLength(t)}function ct(t,e){let r=e.byteLength,n=it(t),o=n+it(r),s=new Uint8Array(o+r);return st(t,s,0),st(r,s,n),s.set(e,o),new at(t,r,e,s)}function Rs(t){let e=Ee(t),[r,n]=Bt(e),[o,s]=Bt(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new at(r,o,i,e)}function $s(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&As(t.bytes,r.bytes)}}var at=class{code;size;digest;bytes;constructor(e,r,n,o){this.code=e,this.size=r,this.digest=je(n),this.bytes=je(o)}};var zs=0,wu="identity",Vs=Ee;function Eu(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 ct(zs,Vs(t))}var _u={code:zs,name:wu,encode:Vs,digest:Eu};var Wn={};X(Wn,{sha256:()=>Su,sha512:()=>Cu});var vu=20;function jn({name:t,code:e,encode:r,minDigestLength:n,maxDigestLength:o}){return new Vn(t,e,r,n,o)}var Vn=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,r,n,o,s){this.name=e,this.code=r,this.encode=n,this.minDigestLength=o??vu,this.maxDigestLength=s}digest(e,r){if(r?.truncate!=null){if(r.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&r.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(e instanceof Uint8Array){let n=this.encode(e);return n instanceof Uint8Array?js(n,this.code,r?.truncate):n.then(o=>js(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function js(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 ct(e,t)}function qs(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}var Su=jn({name:"sha2-256",code:18,encode:qs("SHA-256")}),Cu=jn({name:"sha2-512",code:19,encode:qs("SHA-512")});function Gs(t,e){let{bytes:r,version:n}=t;return n===0?Lu(r,qn(t),e??te.encoder):Tu(r,qn(t),e??he.encoder)}var Hs=new WeakMap;function qn(t){let e=Hs.get(t);if(e==null){let r=new Map;return Hs.set(t,r),r}return e}var ut=class t{code;version;multihash;bytes;"/";constructor(e,r,n,o){this.code=r,this.version=e,this.multihash=n,this.bytes=je(o),this["/"]=this.bytes}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:r}=this;if(e!==Ft)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Au)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=ct(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&&$s(e.multihash,n.multihash)}toString(e){return Gs(this,e)}toJSON(){return{"/":Gs(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let r=e;if(r instanceof t)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:s,bytes:i}=r;return new t(n,o,s,i??Qs(n,o,s.bytes))}else if(r[Du]===!0){let{version:n,multihash:o,code:s}=r,i=Rs(o);return t.create(n,s,i)}else return null}static create(e,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(r!==Ft)throw new Error(`Version 0 CID must use dag-pb (code: ${Ft}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let o=Qs(e,r,n.bytes);return new t(e,r,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,Ft,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=Ee(e.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let s=o.subarray(r.multihashSize-r.digestSize),i=new at(r.multihashCode,r.digestSize,s,o);return[r.version===0?t.createV0(i):t.createV1(r.codec,i),e.subarray(r.size)]}static inspectBytes(e){let r=0,n=()=>{let[h,p]=Bt(e.subarray(r));return r+=p,h},o=n(),s=Ft;if(o===18?(o=0,r=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=r,a=n(),u=n(),l=r+u,f=l-i;return{version:o,codec:s,multihashCode:a,digestSize:u,multihashSize:f,size:l}}static parse(e,r){let[n,o]=Iu(e,r),s=t.decode(o);if(s.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return qn(s).set(n,e),s}};function Iu(t,e){switch(t[0]){case"Q":{let r=e??te;return[te.prefix,r.decode(`${te.prefix}${t}`)]}case te.prefix:{let r=e??te;return[te.prefix,r.decode(t)]}case he.prefix:{let r=e??he;return[he.prefix,r.decode(t)]}case kt.prefix:{let r=e??kt;return[kt.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 Lu(t,e,r){let{prefix:n}=r;if(n!==te.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=e.get(n);if(o==null){let s=r.encode(t).slice(1);return e.set(n,s),s}else return o}function Tu(t,e,r){let{prefix:n}=r,o=e.get(n);if(o==null){let s=r.encode(t);return e.set(n,s),s}else return o}var Ft=112,Au=18;function Qs(t,e,r){let n=it(t),o=n+it(e),s=new Uint8Array(o+r.byteLength);return st(t,s,0),st(e,s,n),s.set(r,o),s}var Du=Symbol.for("@ipld/js-cid/CID");var Mt={...Rn,...Dn,...On,...Tn,...An,...Pn,...Bn,...Nn,...Un,...kn},Ld={...Wn,...zn};function Ks(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var Xs=Ks("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),Gn=Ks("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=K(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),ku={utf8:Xs,"utf-8":Xs,hex:Mt.base16,latin1:Gn,ascii:Gn,binary:Gn,...Mt},dr=ku;function F(t,e="utf8"){let r=dr[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}var Hn={32:16777619n,64:1099511628211n,128:309485009821345068724781371n,256:374144419156711147060143317175368453031918731002211n,512:35835915874844867368919076489095108449946327955754392558399825615420669938882575126094039892345713852759n,1024:5016456510113118655434598811035278955030765345404790744303017523831112055108147451509157692220295382716162651878526895249385292291816524375083746691371804094271873160484737966720260389217684476157468082573n},Js={32:2166136261n,64:14695981039346656037n,128:144066263297769815596495629667062367629n,256:100029257958052580907070968620625704837092796014241193945225284501741471925557n,512:9659303129496669498009435400716310466090418745672637896108374329434462657994582932197716438449813051892206539805784495328239340083876191928701583869517785n,1024:14197795064947621068722070641403218320880622795441933960878474914617582723252296732303717722150864096521202355549365628174669108571814760471015076148029755969804077320157692458563003215304957150157403644460363550505412711285966361610267868082893823963790439336411086884584107735010676915n},Ys=new globalThis.TextEncoder;function Pu(t,e){let r=Hn[e],n=Js[e];for(let o=0;o<t.length;o++)n^=BigInt(t[o]),n=BigInt.asUintN(e,n*r);return n}function Bu(t,e,r){if(r.length===0)throw new Error("The `utf8Buffer` option must have a length greater than zero");let n=Hn[e],o=Js[e],s=t;for(;s.length>0;){let i=Ys.encodeInto(s,r);s=s.slice(i.read);for(let a=0;a<i.written;a++)o^=BigInt(r[a]),o=BigInt.asUintN(e,o*n)}return o}function Qn(t,{size:e=32,utf8Buffer:r}={}){if(!Hn[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 Bu(t,e,r);t=Ys.encode(t)}return Pu(t,e)}var Ae={hash:t=>Number(Qn(t,{size:32})),hashV:(t,e)=>Nu(Ae.hash(t,e))};function Nu(t){let e=t.toString(16);return e.length%2===1&&(e=`0${e}`),F(e,"base16")}var Fu=Math.LN2*Math.LN2,Ut=class{seeds;bits;buffer;constructor(e={}){e.seeds!=null?this.seeds=e.seeds:this.seeds=Uu(e.hashes??8),this.bits=e.bits??1024,this.buffer=H(Math.ceil(this.bits/8))}add(e){typeof e=="string"&&(e=F(e));for(let r=0;r<this.seeds.length;r++){let o=Ae.hash(e,this.seeds[r])%this.bits;this.setbit(o)}}has(e){typeof e=="string"&&(e=F(e));for(let r=0;r<this.seeds.length;r++){let o=Ae.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 Zs(t,e=.005){let r=Mu(t,e);return new Ut(r)}function Mu(t,e=.005){let r=Math.round(-1*t*Math.log(e)/Fu),n=Math.round(r/t*Math.LN2);return{bits:r,hashes:n}}function Uu(t){let e,r,n=[];for(let o=0;o<t;o++)for(e=new N(crypto.getRandomValues(new Uint8Array(4))),n[o]=e.getUint32(0,!0),r=0;r<o;r++)if(n[o]===n[r]){o--;break}return n}var Xn=64,ie=class{fp;h;seed;constructor(e,r,n,o=2){if(o>Xn)throw new TypeError("Invalid Fingerprint Size");let s=r.hashV(e,n),i=H(o);for(let a=0;a<i.length;a++)i[a]=s[a];i.length===0&&(i[0]=7),this.fp=i,this.h=r,this.seed=n}hash(){return this.h.hash(this.fp,this.seed)}equals(e){return e?.fp instanceof Uint8Array?Ve(this.fp,e.fp):!1}};function We(t,e){return Math.floor(Math.random()*(e-t))+t}var qe=class{contents;constructor(e){this.contents=new Array(e).fill(null)}has(e){if(!(e instanceof ie))throw new TypeError("Invalid Fingerprint");return this.contents.some(r=>e.equals(r))}add(e){if(!(e instanceof ie))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 ie))throw new TypeError("Invalid Fingerprint");let r=We(0,this.contents.length-1),n=this.contents[r];return this.contents[r]=e,n}remove(e){if(!(e instanceof ie))throw new TypeError("Invalid Fingerprint");let r=this.contents.findIndex(n=>e.equals(n));return r>-1?(this.contents[r]=null,!0):!1}};var Ou=500,De=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??Ae,this.seed=e.seed??We(0,Math.pow(2,10))}add(e){typeof e=="string"&&(e=F(e));let r=new ie(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 qe(this.bucketSize)),this.buckets[o]==null&&(this.buckets[o]=new qe(this.bucketSize)),this.buckets[n].add(r)||this.buckets[o].add(r))return this.count++,!0;let s=[n,o],i=s[We(0,s.length-1)];this.buckets[i]==null&&(this.buckets[i]=new qe(this.bucketSize));for(let a=0;a<Ou;a++){let u=this.buckets[i].swap(r);if(u!=null&&(i=(i^u.hash())%this.filterSize,this.buckets[i]==null&&(this.buckets[i]=new qe(this.bucketSize)),this.buckets[i].add(u)))return this.count++,!0}return!1}has(e){typeof e=="string"&&(e=F(e));let r=new ie(e,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(e,this.seed)%this.filterSize,o=this.buckets[n]?.has(r)??!1;if(o)return o;let s=(n^r.hash())%this.filterSize;return this.buckets[s]?.has(r)??!1}remove(e){typeof e=="string"&&(e=F(e));let r=new ie(e,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(e,this.seed)%this.filterSize,o=this.buckets[n]?.remove(r)??!1;if(o)return this.count--,o;let s=(n^r.hash())%this.filterSize,i=this.buckets[s]?.remove(r)??!1;return i&&this.count--,i}get reliable(){return Math.floor(100*(this.count/this.filterSize))<=90}},Ru={1:.5,2:.84,4:.95,8:.98};function $u(t=.001){return t>.002?2:t>1e-5?4:8}function Kn(t,e=.001){let r=$u(e),n=Ru[r],o=Math.round(t/n),s=Math.min(Math.ceil(Math.log2(1/e)+Math.log2(2*r)),Xn);return{filterSize:o,bucketSize:r,fingerprintSize:s}}function ei(t,e=.005){let r=Kn(t,e);return new De(r)}var Ot=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??Ae,this.seed=e.seed??We(0,Math.pow(2,10)),this.filterSeries=[new De({filterSize:this.filterSize,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed})]}add(e){if(typeof e=="string"&&(e=F(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 De({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=F(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=F(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 ti(t,e=.001,r){return new Ot({...Kn(t,e),...r??{}})}var _e=class extends Error{static name="AbortError";constructor(e="The operation was aborted"){super(e),this.name="AbortError"}};var re=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}};var mr=class extends Error{static name="MuxerClosedError";constructor(e="The muxer is closed"){super(e),this.name="MuxerClosedError"}},pr=class extends Error{static name="StreamResetError";constructor(e="The stream has been reset"){super(e),this.name="StreamResetError"}};var ke=class extends Error{static name="StreamStateError";constructor(e="The stream is in an invalid state"){super(e),this.name="StreamStateError"}},Rt=class extends Error{static name="StreamBufferError";constructor(e="The stream buffer was full"){super(e),this.name="StreamBufferError"}};var de=class extends Event{data;constructor(e,r){super("message",r),this.data=e}},ft=class extends Event{error;local;constructor(e,r,n){super("close",n),this.error=r,this.local=e}},gr=class extends ft{constructor(e,r){super(!0,e,r)}},br=class extends ft{constructor(e,r){super(!1,e,r)}};function zu(t){return typeof t?.handleEvent=="function"}function Vu(t){return(t!==!0&&t!==!1&&t?.once)??!1}var me=class extends EventTarget{#e=new Map;constructor(){super()}listenerCount(e){let r=this.#e.get(e);return r==null?0:r.length}addEventListener(e,r,n){let o=Vu(n);super.addEventListener(e,i=>{if(o){let a=this.#e.get(i.type);a!=null&&(a=a.filter(({callback:u})=>u!==r),this.#e.set(i.type,a))}zu(r)?r.handleEvent(i):r(i)},n);let s=this.#e.get(e);s==null&&(s=[],this.#e.set(e,s)),s.push({callback:r,once:o})}removeEventListener(e,r,n){super.removeEventListener(e.toString(),r??null,n);let o=this.#e.get(e);o!=null&&(o=o.filter(({callback:s})=>s!==r),this.#e.set(e,o))}safeDispatchEvent(e,r={}){return this.dispatchEvent(new CustomEvent(e,r))}};function yr(t){let e=t.getComponents(),r={},n=0;return 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?null:(e[n]?.name==="tls"&&e[n+1]?.name==="sni"&&(r.sni=e[n+1].value,n+=2),r)}function ae(t){let e=yr(t);if(e==null)throw new re(`Multiaddr ${t} was not an IPv4, IPv6, DNS, DNS4, DNS6 or DNSADDR address`);return e}var xr=class{index=0;input="";new(e){return this.index=0,this.input=e,this}readAtomically(e){let r=this.index,n=e();return n===void 0&&(this.index=r),n}parseWith(e){let r=e();if(this.index===this.input.length)return r}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(e){return this.readAtomically(()=>{let r=this.readChar();if(r===e)return r})}readSeparator(e,r,n){return this.readAtomically(()=>{if(!(r>0&&this.readGivenChar(e)===void 0))return n()})}readNumber(e,r,n,o){return this.readAtomically(()=>{let s=0,i=0,a=this.peekChar();if(a===void 0)return;let u=a==="0",l=2**(8*o)-1;for(;;){let f=this.readAtomically(()=>{let h=this.readChar();if(h===void 0)return;let p=Number.parseInt(h,e);if(!Number.isNaN(p))return p});if(f===void 0)break;if(s*=e,s+=f,s>l||(i+=1,r!==void 0&&i>r))return}if(i!==0)return!n&&u&&i>1?void 0:s})}readIPv4Addr(){return this.readAtomically(()=>{let e=new Uint8Array(4);for(let r=0;r<e.length;r++){let n=this.readSeparator(".",r,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;e[r]=n}return e})}readIPv6Addr(){let e=r=>{for(let n=0;n<r.length/2;n++){let o=n*2;if(n<r.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return r[o]=i[0],r[o+1]=i[1],r[o+2]=i[2],r[o+3]=i[3],[o+4,!0]}let s=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(s===void 0)return[o,!1];r[o]=s>>8,r[o+1]=s&255}return[r.length,!1]};return this.readAtomically(()=>{let r=new Uint8Array(16),[n,o]=e(r);if(n===16)return r;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let s=new Uint8Array(14),i=16-(n+2),[a]=e(s.subarray(0,i));return r.set(s.subarray(0,a),16-a),r})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var ri=45,ju=15,lt=new xr;function wr(t){if(!(t.length>ju))return lt.new(t).parseWith(()=>lt.readIPv4Addr())}function Er(t){if(t.includes("%")&&(t=t.split("%")[0]),!(t.length>ri))return lt.new(t).parseWith(()=>lt.readIPv6Addr())}function ht(t,e=!1){if(t.includes("%")&&(t=t.split("%")[0]),t.length>ri)return;let r=lt.new(t).parseWith(()=>lt.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 ni(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 oi(t,e,r,n){let o=0;for(let s of t)if(!(o<r)){if(o>n)break;if(s!==e[o])return!1;o++}return!0}function Jn(t){switch(t.length){case Ge:return t.join(".");case He:{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 si(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 ii(t){let e="0x";for(let r of t)e+=(r>>4).toString(16)+(r&15).toString(16);return e}var Ge=4,He=16,vm=parseInt("0xFFFF",16),Wu=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function $t(t,e){e.length===He&&t.length===Ge&&ni(e,0,11)&&(e=e.slice(12)),e.length===Ge&&t.length===He&&oi(t,Wu,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 ai(t,e){if(typeof e=="string"&&(e=ht(e)),e==null)throw new Error("Invalid ip");if(e.length!==t.network.length)return!1;for(let r=0;r<e.length;r++)if((t.network[r]&t.mask[r])!==(e[r]&t.mask[r]))return!1;return!0}function Yn(t){let[e,r]=t.split("/");if(!e||!r)throw new Error("Failed to parse given CIDR: "+t);let n=Ge,o=wr(e);if(o==null&&(n=He,o=Er(e),o==null))throw new Error("Failed to parse given CIDR: "+t);let s=parseInt(r,10);if(Number.isNaN(s)||String(s).length!==r.length||s<0||s>n*8)throw new Error("Failed to parse given CIDR: "+t);let i=Zn(s,8*n);return{network:$t(o,i),mask:i}}function Zn(t,e){if(e!==8*Ge&&e!==8*He)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 zt=class{constructor(e,r){if(r==null)({network:this.network,mask:this.mask}=Yn(e));else{let n=ht(e);if(n==null)throw new Error("Failed to parse network");r=String(r);let o=parseInt(r,10);if(Number.isNaN(o)||String(o).length!==r.length||o<0||o>n.length*8){let s=ht(r);if(s==null)throw new Error("Failed to parse mask");this.mask=s}else this.mask=Zn(o,8*n.length);this.network=$t(n,this.mask)}}contains(e){return ai({network:this.network,mask:this.mask},e)}toString(){let e=si(this.mask),r=e!==-1?String(e):ii(this.mask);return Jn(this.network)+"/"+r}};function _r(t,e){return new zt(t).contains(e)}function qu(t){try{let e=ae(t);return e.type==="ip6"?_r("2000::/3",e.host):!1}catch{return!1}}function Gu(t){try{let e=ae(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 ci(t){return/^127\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/i.test(t)||/^::1$/.test(t)}function vr(t){try{let e=ae(t);switch(e.type){case"ip4":case"ip6":return ci(e.host);default:return!1}}catch{return!1}}function Hu(t){return yr(t)!==null}function Pe(t){return!!wr(t)}function Be(t){return!!Er(t)}var hi=Ec(li(),1),ef=["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"],tf=ef.map(t=>new hi.Netmask(t));function io(t){for(let e of tf)if(e.contains(t))return!0;return!1}function rf(t){return/^::ffff:([0-9a-fA-F]{1,4}):([0-9a-fA-F]{1,4})$/.test(t)}function nf(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 io(o)}function of(t){return/^::ffff:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(t)}function sf(t){let e=t.split(":"),r=e[e.length-1];return io(r)}function af(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 ao(t){if(Pe(t))return io(t);if(rf(t))return nf(t);if(of(t))return sf(t);if(Be(t))return af(t)}function Cr(t){try{let e=ae(t);switch(e.type){case"ip4":case"ip6":return ao(e.host)??!1;default:return e.host==="localhost"}}catch{return!1}}var cf=Math.pow(2,7),uf=Math.pow(2,14),ff=Math.pow(2,21),co=Math.pow(2,28),uo=Math.pow(2,35),fo=Math.pow(2,42),lo=Math.pow(2,49),C=128,V=127;function j(t){if(t<cf)return 1;if(t<uf)return 2;if(t<ff)return 3;if(t<co)return 4;if(t<uo)return 5;if(t<fo)return 6;if(t<lo)return 7;if(Number.MAX_SAFE_INTEGER!=null&&t>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Ir(t,e,r=0){switch(j(t)){case 8:e[r++]=t&255|C,t/=128;case 7:e[r++]=t&255|C,t/=128;case 6:e[r++]=t&255|C,t/=128;case 5:e[r++]=t&255|C,t/=128;case 4:e[r++]=t&255|C,t>>>=7;case 3:e[r++]=t&255|C,t>>>=7;case 2:e[r++]=t&255|C,t>>>=7;case 1:{e[r++]=t&255,t>>>=7;break}default:throw new Error("unreachable")}return e}function lf(t,e,r=0){switch(j(t)){case 8:e.set(r++,t&255|C),t/=128;case 7:e.set(r++,t&255|C),t/=128;case 6:e.set(r++,t&255|C),t/=128;case 5:e.set(r++,t&255|C),t/=128;case 4:e.set(r++,t&255|C),t>>>=7;case 3:e.set(r++,t&255|C),t>>>=7;case 2:e.set(r++,t&255|C),t>>>=7;case 1:{e.set(r++,t&255),t>>>=7;break}default:throw new Error("unreachable")}return e}function hf(t,e){let r=t[e],n=0;if(n+=r&V,r<C||(r=t[e+1],n+=(r&V)<<7,r<C)||(r=t[e+2],n+=(r&V)<<14,r<C)||(r=t[e+3],n+=(r&V)<<21,r<C)||(r=t[e+4],n+=(r&V)*co,r<C)||(r=t[e+5],n+=(r&V)*uo,r<C)||(r=t[e+6],n+=(r&V)*fo,r<C)||(r=t[e+7],n+=(r&V)*lo,r<C))return n;throw new RangeError("Could not decode varint")}function df(t,e){let r=t.get(e),n=0;if(n+=r&V,r<C||(r=t.get(e+1),n+=(r&V)<<7,r<C)||(r=t.get(e+2),n+=(r&V)<<14,r<C)||(r=t.get(e+3),n+=(r&V)<<21,r<C)||(r=t.get(e+4),n+=(r&V)*co,r<C)||(r=t.get(e+5),n+=(r&V)*uo,r<C)||(r=t.get(e+6),n+=(r&V)*fo,r<C)||(r=t.get(e+7),n+=(r&V)*lo,r<C))return n;throw new RangeError("Could not decode varint")}function Lr(t,e,r=0){return e==null&&(e=K(j(t))),e instanceof Uint8Array?Ir(t,e,r):lf(t,e,r)}function ve(t,e=0){return t instanceof Uint8Array?hf(t,e):df(t,e)}function mf(t){return t.buffer instanceof ArrayBuffer}function ho(t){return mf(t)?t:t.slice()}function Fe(t,e="utf8"){let r=dr[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.encoder.encode(t).substring(1)}var z=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},Se=class extends Error{static name="ValidationError";name="ValidationError"},Tr=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},Ar=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};function po(t){return e=>Fe(e,t)}function go(t){return e=>F(e,t)}function gt(t){return new DataView(t.buffer).getUint16(t.byteOffset).toString()}function Xe(t){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,typeof t=="string"?parseInt(t):t),new Uint8Array(e)}function di(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=F(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=Xe(n);return we([r,o],r.length+o.length)}function mi(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=he.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=Xe(n);return we([r,o],r.length+o.length)}function bo(t){let e=t.subarray(0,t.length-2),r=t.subarray(t.length-2),n=Fe(e,"base32"),o=gt(r);return`${n}:${o}`}var yo=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 z("Invalid byte value in IP address");e[n]=o}),e},pi=function(t){let e=0;t=t.toString().trim();let r=t.split(":",8),n;for(n=0;n<r.length;n++){let s=Pe(r[n]),i;s&&(i=yo(r[n]),r[n]=Fe(i.subarray(0,2),"base16")),i!=null&&++n<8&&r.splice(n,0,Fe(i.subarray(2,4),"base16"))}if(r[0]==="")for(;r.length<8;)r.unshift("0");else if(r[r.length-1]==="")for(;r.length<8;)r.push("0");else if(r.length<8){for(n=0;n<r.length&&r[n]!=="";n++);let s=[n,1];for(n=9-r.length;n>0;n--)s.push("0");r.splice.apply(r,s)}let o=new Uint8Array(e+16);for(n=0;n<r.length;n++){r[n]===""&&(r[n]="0");let s=parseInt(r[n],16);if(isNaN(s)||s<0||s>65535)throw new z("Invalid byte value in IP address");o[e++]=s>>8&255,o[e++]=s&255}return o},gi=function(t){if(t.byteLength!==4)throw new z("IPv4 address was incorrect length");let e=[];for(let r=0;r<t.byteLength;r++)e.push(t[r]);return e.join(".")},bi=function(t){if(t.byteLength!==16)throw new z("IPv6 address was incorrect length");let e=[];for(let n=0;n<t.byteLength;n+=2){let o=t[n],s=t[n+1],i=`${o.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}`;e.push(i)}let r=e.join(":");try{let n=new URL(`http://[${r}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new z(`Invalid IPv6 address "${r}"`)}};function yi(t){try{let e=new URL(`http://[${t}]`);return e.hostname.substring(1,e.hostname.length-1)}catch{throw new z(`Invalid IPv6 address "${t}"`)}}var mo=Object.values(Mt).map(t=>t.decoder),pf=(function(){let t=mo[0].or(mo[1]);return mo.slice(2).forEach(e=>t=t.or(e)),t})();function xi(t){return pf.decode(t)}function wi(t){return e=>t.encoder.encode(e)}function gf(t){if(parseInt(t).toString()!==t)throw new Se("Value must be an integer")}function bf(t){if(t<0)throw new Se("Value must be a positive integer, or zero")}function yf(t){return e=>{if(e>t)throw new Se(`Value must be smaller than or equal to ${t}`)}}function xf(...t){return e=>{for(let r of t)r(e)}}var jt=xf(gf,bf,yf(65535));var M=-1,xo=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)}))}},Ie=new xo,Bf=[{code:4,name:"ip4",size:32,valueToBytes:yo,bytesToValue:gi,validate:t=>{if(!Pe(t))throw new Se(`Invalid IPv4 address "${t}"`)}},{code:6,name:"tcp",size:16,valueToBytes:Xe,bytesToValue:gt,validate:jt},{code:273,name:"udp",size:16,valueToBytes:Xe,bytesToValue:gt,validate:jt},{code:33,name:"dccp",size:16,valueToBytes:Xe,bytesToValue:gt,validate:jt},{code:41,name:"ip6",size:128,valueToBytes:pi,bytesToValue:bi,stringToValue:yi,validate:t=>{if(!Be(t))throw new Se(`Invalid IPv6 address "${t}"`)}},{code:42,name:"ip6zone",size:M},{code:43,name:"ipcidr",size:8,bytesToValue:po("base10"),valueToBytes:go("base10")},{code:53,name:"dns",size:M},{code:54,name:"dns4",size:M},{code:55,name:"dns6",size:M},{code:56,name:"dnsaddr",size:M},{code:132,name:"sctp",size:16,valueToBytes:Xe,bytesToValue:gt,validate:jt},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:M,stringToValue:t=>decodeURIComponent(t),valueToString:t=>encodeURIComponent(t)},{code:421,name:"p2p",aliases:["ipfs"],size:M,bytesToValue:po("base58btc"),valueToBytes:t=>t.startsWith("Q")||t.startsWith("1")?go("base58btc")(t):ut.parse(t).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:bo,valueToBytes:di},{code:445,name:"onion3",size:296,bytesToValue:bo,valueToBytes:mi},{code:446,name:"garlic64",size:M},{code:447,name:"garlic32",size:M},{code:448,name:"tls"},{code:449,name:"sni",size:M},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:M,bytesToValue:wi(Mn),valueToBytes:xi},{code:480,name:"http"},{code:481,name:"http-path",size:M,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:M}];Bf.forEach(t=>{Ie.addProtocol(t)});function Ei(t){let e=[],r=0;for(;r<t.length;){let n=ve(t,r),o=Ie.getProtocol(n),s=j(n),i=Nf(o,t,r+s),a=0;i>0&&o.size===M&&(a=j(i));let u=s+a+i,l={code:n,name:o.name,bytes:ho(t.subarray(r,r+u))};if(i>0){let f=r+s+a,h=t.subarray(f,f+i);l.value=o.bytesToValue?.(h)??Fe(h)}e.push(l),r+=u}return e}function _i(t){let e=0,r=[];for(let n of t){if(n.bytes==null){let o=Ie.getProtocol(n.code),s=j(n.code),i,a=0,u=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??F(n.value),a=i.byteLength,o.size===M&&(u=j(a)));let l=new Uint8Array(s+u+a),f=0;Ir(n.code,l,f),f+=s,i!=null&&(o.size===M&&(Ir(a,l,f),f+=u),l.set(i,f)),n.bytes=l}r.push(n.bytes),e+=n.bytes.byteLength}return we(r,e)}function vi(t){if(t.charAt(0)!=="/")throw new z('String multiaddr must start with "/"');let e=[],r="protocol",n="",o="";for(let s=1;s<t.length;s++){let i=t.charAt(s);i!=="/"&&(r==="protocol"?o+=t.charAt(s):n+=t.charAt(s));let a=s===t.length-1;if(i==="/"||a){let u=Ie.getProtocol(o);if(r==="protocol"){if(u.size==null||u.size===0){e.push({code:u.code,name:u.name}),n="",o="",r="protocol";continue}else if(a)throw new z(`Component ${o} was missing value`);r="value"}else if(r==="value"){let l={code:u.code,name:u.name};if(u.size!=null&&u.size!==0){if(n==="")throw new z(`Component ${o} was missing value`);l.value=u.stringToValue?.(n)??n}e.push(l),n="",o="",r="protocol"}}}if(o!==""&&n!=="")throw new z("Incomplete multiaddr");return e}function Si(t){return`/${t.flatMap(e=>{if(e.value==null)return e.name;let r=Ie.getProtocol(e.code);if(r==null)throw new z(`Unknown protocol code ${e.code}`);return[e.name,r.valueToString?.(e.value)??e.value]}).join("/")}`}function Nf(t,e,r){return t.size==null||t.size===0?0:t.size>0?t.size/8:ve(e,r)}var Ff=Symbol.for("nodejs.util.inspect.custom"),Bo=Symbol.for("@multiformats/multiaddr");function Mf(t){if(t==null&&(t="/"),Ci(t))return t.getComponents();if(t instanceof Uint8Array)return Ei(t);if(typeof t=="string")return t=t.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),t===""&&(t="/"),vi(t);if(Array.isArray(t))return t;throw new z("Must be a string, Uint8Array, Component[], or another Multiaddr")}var Or=class t{[Bo]=!0;#e;#t;#r;constructor(e="/",r={}){this.#e=Mf(e),r.validate!==!1&&Uf(this)}get bytes(){return this.#r==null&&(this.#r=_i(this.#e)),this.#r}toString(){return this.#t==null&&(this.#t=Si(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 Tr(`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 Ve(this.bytes,e.bytes)}[Ff](){return`Multiaddr(${this.toString()})`}};function Uf(t){t.getComponents().forEach(e=>{let r=Ie.getProtocol(e.code);e.value!=null&&r.validate?.(e.value)})}function Ci(t){return!!t?.[Bo]}function Me(t){return new Or(t)}var T=t=>({match:e=>{let r=e[0];return r==null||r.code!==t||r.value!=null?!1:e.slice(1)}}),b=(t,e)=>({match:r=>{let n=r[0];return n?.code!==t||n.value==null||e!=null&&n.value!==e?!1:r.slice(1)}}),Ii=t=>({match:e=>t.match(e)===!1?e:!1}),w=t=>({match:e=>{let r=t.match(e);return r===!1?e:r}}),W=(...t)=>({match:e=>{let r;for(let n of t){let o=n.match(e);o!==!1&&(r==null||o.length<r.length)&&(r=o)}return r??!1}}),v=(...t)=>({match:e=>{for(let r of t){let n=r.match(e);if(n===!1)return!1;e=n}return e}});function A(...t){function e(o){if(o==null)return!1;let s=o.getComponents();for(let i of t){let a=i.match(s);if(a===!1)return!1;s=a}return s}function r(o){return e(o)!==!1}function n(o){let s=e(o);return s===!1?!1:s.length===0}return{matchers:t,matches:r,exactMatch:n}}var Of=b(421),gg=A(Of),$r=b(54),zr=b(55),Vr=b(56),Fo=b(53),bg=A($r,w(b(421))),yg=A(zr,w(b(421))),xg=A(Vr,w(b(421))),wg=A(W(Fo,Vr,$r,zr),w(b(421))),Li=v(b(4),w(b(43))),Ti=v(w(b(42)),b(41),w(b(43))),Mo=W(Li,Ti),wt=W(Mo,Fo,$r,zr,Vr),Eg=A(W(Mo,v(W(Fo,Vr,$r,zr),w(b(421))))),_g=A(Li),vg=A(Ti),Sg=A(Mo),Uo=v(wt,b(6)),Wt=v(wt,b(273)),Oo=A(v(Uo,w(b(421)))),Cg=A(Wt),Ro=v(Wt,T(460),w(b(421))),jr=v(Wt,T(461),w(b(421))),Rf=W(Ro,jr),Ig=A(Ro),Lg=A(jr),No=W(wt,Uo,Wt,Ro,jr),Ai=W(v(No,T(477),w(b(421)))),$o=A(Ai),Di=W(v(No,T(478),w(b(421))),v(No,T(448),w(b(449)),T(477),w(b(421)))),zo=A(Di),ki=v(Wt,T(280),w(b(466)),w(b(466)),w(b(421))),Vo=A(ki),Pi=v(jr,T(465),w(b(466)),w(b(466)),w(b(421))),jo=A(Pi),Rr=W(Ai,Di,v(Uo,w(b(421))),v(Rf,w(b(421))),v(wt,w(b(421))),ki,Pi,b(421)),Tg=A(Rr),$f=v(w(Rr),T(290),Ii(T(281)),w(b(421))),Wo=A($f),zf=W(v(Rr,T(290),T(281),w(b(421))),v(Rr,T(281),w(b(421))),v(T(281),w(b(421)))),qo=A(zf),Vf=v(wt,W(v(b(6,"80")),v(b(6),T(480)),T(480)),w(b(481)),w(b(421))),Ag=A(Vf),jf=v(wt,W(v(b(6,"443")),v(b(6,"443"),T(480)),v(b(6),T(443)),v(b(6),T(448),T(480)),v(T(448),T(480)),T(448),T(443)),w(b(481)),w(b(421))),Dg=A(jf),Wf=W(v(b(777),w(b(421)))),kg=A(Wf),qf=W(v(b(400),w(b(421)))),Pg=A(qf);function Bi(t,e){let r=Oo.exactMatch(t),n=Oo.exactMatch(e);if(r&&!n)return-1;if(!r&&n)return 1;let o=zo.exactMatch(t),s=zo.exactMatch(e);if(o&&!s)return-1;if(!o&&s)return 1;let i=$o.exactMatch(t),a=$o.exactMatch(e);if(i&&!a)return-1;if(!i&&a)return 1;let u=qo.exactMatch(t),l=qo.exactMatch(e);if(u&&!l)return-1;if(!u&&l)return 1;let f=Vo.exactMatch(t),h=Vo.exactMatch(e);if(f&&!h)return-1;if(!f&&h)return 1;let p=jo.exactMatch(t),x=jo.exactMatch(e);return p&&!x?-1:!p&&x?1:0}function Ni(t,e){let r=vr(t),n=vr(e);return r&&!n?1:!r&&n?-1:0}function Fi(t,e){let r=Cr(t),n=Cr(e);return r&&!n?1:!r&&n?-1:0}function Mi(t,e){let r=Wo.exactMatch(t),n=Wo.exactMatch(e);return r&&!n?1:!r&&n?-1:0}function Gf(t){return t.sort((e,r)=>Ni(e,r)||Fi(e,r)||Mi(e,r)||Bi(e,r))}function ce(){let t={};return t.promise=new Promise((e,r)=>{t.resolve=e,t.reject=r}),t}var Wr=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}},Et=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new Wr(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 Wr(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 Go=class extends Error{type;code;constructor(e,r){super(e??"The operation was aborted"),this.type="aborted",this.code=r??"ABORT_ERR"}};function ge(t={}){return Hf(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 Hf(t,e){e=e??{};let r=e.onEnd,n=new Et,o,s,i,a=ce(),u=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((y,_)=>{s=k=>{s=null,n.push(k);try{y(t(n))}catch(P){_(P)}return o}}):t(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=ce()})}},l=y=>s!=null?s(y):(n.push(y),o),f=y=>(n=new Et,s!=null?s({error:y}):(n.push({error:y}),o)),h=y=>{if(i)return o;if(e?.objectMode!==!0&&y?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return l({done:!1,value:y})},p=y=>i?o:(i=!0,y!=null?f(y):l({done:!0})),x=()=>(n=new Et,p(),{done:!0}),E=y=>(p(y),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:u,return:x,throw:E,push:h,end:p,get readableLength(){return n.size},onEmpty:async y=>{let _=y?.signal;if(_?.throwIfAborted(),n.isEmpty())return;let k,P;_!=null&&(k=new Promise((q,$)=>{P=()=>{$(new Go)},_.addEventListener("abort",P)}));try{await Promise.race([a.promise,k])}finally{P!=null&&_!=null&&_?.removeEventListener("abort",P)}}},r==null)return o;let L=o;return o={[Symbol.asyncIterator](){return this},next(){return L.next()},throw(y){return L.throw(y),r!=null&&(r(y),r=void 0),{done:!0}},return(){return L.return(),r!=null&&(r(),r=void 0),{done:!0}},push:h,end(y){return L.end(y),r!=null&&(r(y),r=void 0),o},get readableLength(){return L.readableLength},onEmpty:y=>L.onEmpty(y)},o}var Ho=class t extends Error{name="TimeoutError";constructor(e,r){super(e,r),Error.captureStackTrace?.(this,t)}},Ui=t=>t.reason??new DOMException("This operation was aborted.","AbortError");function Qo(t,e){let{milliseconds:r,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout},signal:i}=e,a,u,f=new Promise((h,p)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(i?.aborted){p(Ui(i));return}if(i&&(u=()=>{p(Ui(i))},i.addEventListener("abort",u,{once:!0})),t.then(h,p),r===Number.POSITIVE_INFINITY)return;let x=new Ho;a=s.setTimeout.call(void 0,()=>{if(n){try{h(n())}catch(E){p(E)}return}typeof t.cancel=="function"&&t.cancel(),o===!1?h():o instanceof Error?p(o):(x.message=o??`Promise timed out after ${r} milliseconds`,p(x))},r)}).finally(()=>{f.clear(),u&&i&&i.removeEventListener("abort",u)});return f.clear=()=>{s.clearTimeout.call(void 0,a),a=void 0},f}var Qf=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 Xf(t,e,r){let n,o=new Promise((s,i)=>{if(r={rejectionEvents:["error"],multiArgs:!1,rejectionMultiArgs:!1,resolveImmediately:!1,...r},!(r.count>=0&&(r.count===Number.POSITIVE_INFINITY||Number.isInteger(r.count))))throw new TypeError("The `count` option should be at least 0 or more");r.signal?.throwIfAborted();let a=[e].flat(),u=[],{addListener:l,removeListener:f}=Qf(t),h=async(...x)=>{let E=r.multiArgs?x:x[0];if(r.filter)try{if(!await r.filter(E))return}catch(L){n(),i(L);return}u.push(E),r.count===u.length&&(n(),s(u))},p=(...x)=>{n(),i(r.rejectionMultiArgs?x:x[0])};n=()=>{for(let x of a)f(x,h);for(let x of r.rejectionEvents)a.includes(x)||f(x,p)};for(let x of a)l(x,h);for(let x of r.rejectionEvents)a.includes(x)||l(x,p);r.signal&&r.signal.addEventListener("abort",()=>{p(r.signal.reason)},{once:!0}),r.resolveImmediately&&s(u)});if(o.cancel=n,typeof r.timeout=="number"){let s=Qo(o,{milliseconds:r.timeout});return s.cancel=()=>{n(),s.clear()},s}return o}function U(t,e,r){typeof r=="function"&&(r={filter:r}),r={...r,count:1,resolveImmediately:!1};let n=Xf(t,e,r),o=n.then(s=>s[0]);return o.cancel=n.cancel,o}function _t(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 qt=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}},Gt=class extends Error{static name="QueueFullError";constructor(e="The queue was full"){super(e),this.name="QueueFullError"}},Ue=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"},Ht=class extends Error{static name="MaxEarlyStreamsError";name="MaxEarlyStreamsError"},Qt=class extends Error{static name="StreamClosedError";name="StreamClosedError"};function Kf(t){return t.reason}async function O(t,e,r){if(e==null)return t;let n=r?.translateError??Kf;if(e.aborted)return t.catch(()=>{}),Promise.reject(n(e));let o;try{return await Promise.race([t,new Promise((s,i)=>{o=()=>{i(n(e))},e.addEventListener("abort",o)})])}finally{o!=null&&e.removeEventListener("abort",o)}}var qr=class{deferred;signal;onProgress;constructor(e){this.signal=e?.signal,this.onProgress=e?.onProgress,this.deferred=ce(),this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(this.signal?.reason??new _e)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function Jf(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var Gr=class{id;fn;options;recipients;status;timeline;controller;dispatchingProgress;constructor(e,r){this.id=Jf(),this.status="queued",this.fn=e,this.options=r,this.recipients=[],this.timeline={created:Date.now()},this.controller=new AbortController,this.controller.signal,this.dispatchingProgress=!1,this.onAbort=this.onAbort.bind(this)}abort(e){this.controller.abort(e)}onAbort(){this.recipients.reduce((r,n)=>r&&n.signal?.aborted===!0,!0)&&(this.controller.abort(new _e),this.cleanup())}async join(e){let r=new qr(e);return this.recipients.push(r),e?.signal?.addEventListener("abort",this.onAbort),r.deferred.promise}async run(){this.status="running",this.timeline.started=Date.now();try{this.controller.signal.throwIfAborted();let e=await O(this.fn({...this.options??{},signal:this.controller.signal,onProgress:r=>{if(!this.dispatchingProgress){this.dispatchingProgress=!0;try{this.recipients.forEach(n=>{n.onProgress?.(r)})}finally{this.dispatchingProgress=!1}}}}),this.controller.signal);this.recipients.forEach(r=>{r.deferred.resolve(e)}),this.status="complete"}catch(e){this.recipients.forEach(r=>{r.deferred.reject(e)}),this.status="errored"}finally{this.timeline.finished=Date.now(),this.cleanup()}}cleanup(){this.recipients.forEach(e=>{e.cleanup(),e.signal?.removeEventListener("abort",this.onAbort)})}};var ue=class extends me{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=_t(this.emitEmpty.bind(this),1),this.emitIdle=_t(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 Gt;let n=new Gr(e,r);this.enqueue(n),this.safeDispatchEvent("add");let o=n.join(r).then(s=>(this.safeDispatchEvent("completed",{detail:s}),this.safeDispatchEvent("success",{detail:{job:n,result:s}}),s)).catch(s=>{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:s}}),s});return this.tryToStartAnother(),o}clear(){this.queue.splice(0,this.queue.length)}abort(){this.queue.forEach(e=>{e.abort(new _e)}),this.clear()}async onEmpty(e){this.size!==0&&await U(this,"empty",e)}async onSizeLessThan(e,r){this.size<e||await U(this,"next",{...r,filter:()=>this.size<e})}async onIdle(e){this.pending===0&&this.size===0||await U(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=ge({objectMode:!0}),n=u=>{u!=null?this.abort():this.clear(),r.end(u)},o=u=>{u.detail!=null&&r.push(u.detail)},s=u=>{n(u.detail.error)},i=()=>{n()},a=()=>{n(new _e("Queue aborted"))};this.addEventListener("completed",o),this.addEventListener("failure",s),this.addEventListener("idle",i),e?.signal?.addEventListener("abort",a);try{yield*r}finally{this.removeEventListener("completed",o),this.removeEventListener("failure",s),this.removeEventListener("idle",i),e?.signal?.removeEventListener("abort",a),n()}}};var Yf=Math.pow(2,20)*4,Je=class extends me{status;timeline;inactivityTimeout;maxReadBufferLength;maxWriteBufferLength;log;direction;maxMessageSize;readStatus;writeStatus;remoteReadStatus;remoteWriteStatus;writableNeedsDrain;readBuffer;writeBuffer;sendingData;onDrainPromise;constructor(e){super(),this.status="open",this.log=e.log,this.direction=e.direction??"outbound",this.inactivityTimeout=e.inactivityTimeout??12e4,this.maxReadBufferLength=e.maxReadBufferLength??Yf,this.maxWriteBufferLength=e.maxWriteBufferLength,this.maxMessageSize=e.maxMessageSize,this.readBuffer=new N,this.writeBuffer=new N,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,queueMicrotask(()=>{try{this.processSendQueue()}catch(o){this.log.error("processSendQueue threw - %e",o)}})),this.onDrainPromise?.resolve()};this.addEventListener("drain",r);let n=o=>{this.onDrainPromise?.reject(o.error??new Qt)};this.addEventListener("close",n)}get readBufferLength(){return this.readBuffer.byteLength}get writeBufferLength(){return this.writeBuffer.byteLength}async onDrain(e){return this.writableNeedsDrain!==!0?Promise.resolve():(this.onDrainPromise==null&&(this.onDrainPromise=Promise.withResolvers()),O(this.onDrainPromise.promise,e?.signal))}async*[Symbol.asyncIterator](){if(this.readStatus!=="readable"&&this.readStatus!=="paused")return;let e=ge(),r=s=>{e.push(s.data)};this.addEventListener("message",r);let n=s=>{e.end(s.error)};this.addEventListener("close",n);let o=()=>{e.end()};this.addEventListener("remoteCloseWrite",o);try{yield*e}finally{this.removeEventListener("message",r),this.removeEventListener("close",n),this.removeEventListener("remoteCloseWrite",o)}}isReadable(){return this.status==="open"}send(e){if(this.writeStatus==="closed"||this.writeStatus==="closing")throw new ke(`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 gr(e))}}pause(){if(this.readStatus==="closed"||this.readStatus==="closing")throw new ke("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 ke("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 ke(`Cannot push data onto a stream that is ${this.readStatus}`);if(e.byteLength!==0){if(this.readBuffer.append(e),this.readStatus==="paused"||this.listenerCount("message")===0){this.checkReadBufferLength();return}setTimeout(()=>{this.dispatchReadBuffer()},0)}}unshift(e){if(this.readStatus==="closed"||this.readStatus==="closing")throw new ke(`Cannot push data onto a stream that is ${this.readStatus}`);if(e.byteLength!==0){if(this.readBuffer.prepend(e),this.readStatus==="paused"||this.listenerCount("message")===0){this.checkReadBufferLength();return}setTimeout(()=>{this.dispatchReadBuffer()},0)}}onData(e){if(e.byteLength!==0){if(this.readStatus==="closing"||this.readStatus==="closed"){this.log("ignoring data - read status %s",this.readStatus);return}this.readBuffer.append(e),this.dispatchReadBuffer()}}addEventListener(...e){super.addEventListener.apply(this,e),e[0]==="message"&&this.readBuffer.byteLength>0&&queueMicrotask(()=>{this.dispatchReadBuffer()})}onRemoteReset(){this.log("remote reset"),this.status="reset",this.writeStatus="closed",this.remoteWriteStatus="closed",this.remoteReadStatus="closed",this.timeline.close=Date.now(),this.readBuffer.byteLength===0&&(this.readStatus="closed");let e=new pr;this.dispatchEvent(new br(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 ft))}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;if(this.writeStatus!=="writable"&&this.writeStatus!=="closing")return this.log.trace("not processing send queue as stream is %s",this.writeStatus),!1;this.sendingData=!0,this.log.trace("processing send queue with %d queued bytes",this.writeBuffer.byteLength);try{let e=!0,r=this.writeBuffer.byteLength,n=0;for(;this.writeBuffer.byteLength>0;){let o=Math.min(this.maxMessageSize??this.writeBuffer.byteLength,this.writeBuffer.byteLength);if(o===0){e=!1;break}let s=this.writeBuffer.sublist(0,o),i=new N(s);this.writeBuffer.consume(s.byteLength);let a;try{a=this.sendData(s)}catch(u){throw this.writeBuffer.prepend(i),this.abort(u),u}if(e=a.canSendMore,n+=a.sentBytes,a.sentBytes!==i.byteLength&&(i.consume(a.sentBytes),this.writeBuffer.prepend(i)),!e)break}return e||(this.log.trace("sent %d/%d bytes, pausing sending because underlying stream is full, %d bytes left in the write buffer",n,r,this.writeBuffer.byteLength),this.writableNeedsDrain=!0,this.checkWriteBufferLength()),this.writeBuffer.byteLength===0&&this.safeDispatchEvent("idle"),e}finally{this.sendingData=!1}}dispatchReadBuffer(){try{if(this.listenerCount("message")===0){this.log.trace("not dispatching pause buffer as there are no listeners for the message event");return}if(this.readBuffer.byteLength===0){this.log.trace("not dispatching pause buffer as there is no data to dispatch");return}if(this.readStatus==="paused"){this.log.trace("not dispatching pause buffer we are paused");return}if(this.readStatus==="closing"||this.readStatus==="closed"){this.log("dropping %d bytes because the readable end is %s",this.readBuffer.byteLength,this.readStatus),this.readBuffer.consume(this.readBuffer.byteLength);return}let e=this.readBuffer.sublist();this.readBuffer.consume(e.byteLength),this.dispatchEvent(new de(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 Rt(`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 Rt(`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 Xt=class extends Je{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 U(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 U(this,"drain",{...e,rejectionEvents:["close"]})),await this.sendClose(e),this.onTransportClosed())}};function Xo(t){return t==null?!1:typeof t.then=="function"&&typeof t.catch=="function"&&typeof t.finally=="function"}var Kt=class extends me{streams;protocol;status;log;maConn;streamOptions;earlyStreams;maxEarlyStreams;metrics;constructor(e,r){super(),this.maConn=e,this.protocol=r.protocol,this.streams=[],this.earlyStreams=[],this.status="open",this.log=e.log.newScope(r.name),this.streamOptions=r.streamOptions,this.maxEarlyStreams=r.maxEarlyStreams??10,this.metrics=r.metrics;let n=i=>{try{this.onData(i.data)}catch(a){this.abort(a),this.maConn.abort(a)}};this.maConn.addEventListener("message",n);let o=()=>{this.log("underlying stream drained, signal %d streams to continue writing",this.streams.length),this.streams.forEach(i=>{i.onMuxerDrain()})};this.maConn.addEventListener("drain",o);let s=()=>{this.log("underlying stream closed with status %s and %d streams",this.status,this.streams.length),this.onTransportClosed()};this.maConn.addEventListener("close",s)}send(e){let r=this.maConn.send(e);return r===!1&&(this.log("underlying stream saturated, signal %d streams to pause writing",this.streams.length),this.streams.forEach(n=>{n.onMuxerNeedsDrain()})),r}async close(e){this.status==="closed"||this.status==="closing"||(this.status="closing",await 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 mr;let r=this.onCreateStream({...this.streamOptions,...e});return Xo(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 Ht(`Too many early streams were opened - ${this.earlyStreams.length}/${this.maxEarlyStreams}`));return}this.safeDispatchEvent("stream",{detail:e})}cleanUpStream(e){let r=n=>{let o=this.streams.findIndex(s=>s===e);o!==-1&&this.streams.splice(o,1),n.error!=null?n.local?this.metrics?.increment({[`${e.direction}_stream_reset`]:!0}):this.metrics?.increment({[`${e.direction}_stream_abort`]:!0}):this.metrics?.increment({[`${e.direction}_stream_end`]:!0})};e.addEventListener("close",r),this.metrics?.increment({[`${e.direction}_stream`]:!0})}addEventListener(...e){super.addEventListener.apply(this,e),e[0]==="stream"&&this.earlyStreams.length>0&&queueMicrotask(()=>{this.earlyStreams.forEach(r=>{this.safeDispatchEvent("stream",{detail:r})}),this.earlyStreams=[]})}};var Ye=class extends Je{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 U(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 U(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 Hr(t){let e=new globalThis.AbortController;function r(){let s=t.filter(i=>i?.aborted===!0).map(i=>i?.reason).pop();e.abort(s);for(let i of t)i?.removeEventListener!=null&&i.removeEventListener("abort",r)}for(let s of t){if(s?.aborted===!0){r();break}s?.addEventListener!=null&&s.addEventListener("abort",r)}function n(){for(let s of t)s?.removeEventListener!=null&&s.removeEventListener("abort",r)}let o=e.signal;return o.clear=n,o}var Ze=class{movingAverage;variance;deviation;forecast;timeSpan;previousTime;constructor(e){this.timeSpan=e,this.movingAverage=0,this.variance=0,this.deviation=0,this.forecast=0}alpha(e,r){return 1-Math.exp(-(e-r)/this.timeSpan)}push(e,r=Date.now()){if(this.previousTime!=null){let n=this.alpha(r,this.previousTime),o=e-this.movingAverage,s=n*o;this.movingAverage=n*e+(1-n)*this.movingAverage,this.variance=(1-n)*(this.variance+o*s),this.deviation=Math.sqrt(this.variance),this.forecast=this.movingAverage+n*o}else this.movingAverage=e;this.previousTime=r}};var Oi=1.2,Ri=2,$i=5e3,zi=6e4,Vi=5e3,Ko=class{success;failure;next;metric;timeoutMultiplier;failureMultiplier;minTimeout;maxTimeout;constructor(e={}){let r=e.interval??Vi;this.success=new Ze(r),this.failure=new Ze(r),this.next=new Ze(r),this.failureMultiplier=e.failureMultiplier??Ri,this.timeoutMultiplier=e.timeoutMultiplier??Oi,this.minTimeout=e.minTimeout??$i,this.maxTimeout=e.maxTimeout??zi,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=Hr([e.signal,n]);return o.start=Date.now(),o.timeout=r,o}cleanUp(e){e.clear();let r=Date.now()-e.start;e.aborted?(this.failure.push(r),this.next.push(r*this.failureMultiplier),this.metric?.update({failureMovingAverage:this.failure.movingAverage,failureDeviation:this.failure.deviation,failureForecast:this.failure.forecast,failureVariance:this.failure.variance,failure:r})):(this.success.push(r),this.next.push(r),this.metric?.update({successMovingAverage:this.success.movingAverage,successDeviation:this.success.deviation,successForecast:this.success.forecast,successVariance:this.success.variance,success:r}))}};function ji(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),Me(`/${n.join("/")}`)}function Zf(t,e){if(t==null)return[];let r=ae(t);return[ji(r,e)]}function el(t){return Be(t)?_r("2000::/3",t):!1}function tl(t,e){if(typeof t!="string")throw new re(`invalid ip provided: ${t}`);if(typeof e=="string"&&(e=parseInt(e)),isNaN(e))throw new re(`invalid port provided: ${e}`);if(Pe(t))return Me(`/ip4/${t}/tcp/${e}`);if(Be(t))return Me(`/ip6/${t}/tcp/${e}`);throw new re(`invalid ip:port for creating a multiaddr: ${t}:${e}`)}function rl(t){return t==null||typeof t?.[Symbol.asyncIterator]!="function"?!1:typeof t.next=="function"}function nl(t){return t==null||typeof t?.[Symbol.iterator]!="function"?!1:typeof t.next=="function"}var Jo=class{readNext;haveNext;ended;nextResult;error;constructor(){this.ended=!1,this.readNext=ce(),this.haveNext=ce()}[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=ce(),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=ce(),await O(this.readNext.promise,r?.signal,r)}};function Wi(){return new Jo}function ol(t){return t[Symbol.asyncIterator]!=null}async function sl(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*il(t){let e=new AbortController,r=Wi();sl(t,r,e.signal).catch(()=>{});try{yield*r}finally{e.abort()}}function*al(t){for(let e of t)yield*e}function cl(...t){let e=[];for(let r of t)ol(r)||e.push(r);return e.length===t.length?al(e):il(t)}var qi=cl;function Gi(t,...e){if(t==null)throw new Error("Empty pipeline");if(Yo(t)){let n=t;t=()=>n.source}else if(Qi(t)||Hi(t)){let n=t;t=()=>n}let r=[t,...e];if(r.length>1&&Yo(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++)Yo(r[n])&&(r[n]=fl(r[n]));return ul(...r)}var ul=(...t)=>{let e;for(;t.length>0;)e=t.shift()(e);return e},Hi=t=>t?.[Symbol.asyncIterator]!=null,Qi=t=>t?.[Symbol.iterator]!=null,Yo=t=>t==null?!1:t.sink!=null&&t.source!=null,fl=t=>e=>{let r=t.sink(e);if(r?.then!=null){let n=ge({objectMode:!0});r.then(()=>{n.end()},i=>{n.end(i)});let o,s=t.source;if(Hi(s))o=async function*(){yield*s,n.end()};else if(Qi(s))o=function*(){yield*s,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return qi(n,o())}return t.source};var ll=4194304,Jt=class extends Error{static name="UnwrappedError";name="UnwrappedError"},vt=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},Qr=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},Xr=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function hl(t){return typeof t?.closeRead=="function"}function dl(t){return typeof t?.close=="function"}function Zo(t){return hl(t)?t.remoteWriteStatus!=="writable"&&t.readBufferLength===0:dl(t)?t.status!=="open":!1}function ml(t){return t?.addEventListener!=null&&t?.removeEventListener!=null&&t?.send!=null&&t?.push!=null&&t?.log!=null}function Xi(t,e){let r=e?.maxBufferSize??ll,n=new N,o,s=!1;if(!ml(t))throw new re("Argument should be a Stream or a Multiaddr");let i=f=>{if(n.append(f.data),n.byteLength>r){let h=n.byteLength;n.consume(n.byteLength),o?.reject(new Error(`Read buffer overflow - ${h} > ${r}`))}o?.resolve()};t.addEventListener("message",i);let a=f=>{f.error!=null?o?.reject(f.error):o?.resolve()};t.addEventListener("close",a);let u=()=>{o?.resolve()};t.addEventListener("remoteCloseWrite",u);let l={readBuffer:n,async read(f){if(s===!0)throw new Jt("Stream was unwrapped");if(Zo(t)){if(n.byteLength===0&&f?.bytes==null)return null;if(f?.bytes!=null&&n.byteLength<f.bytes)throw t.log.error("closed after reading %d/%d bytes",n.byteLength,f.bytes),new Ue(`Unexpected EOF - stream closed after reading ${n.byteLength}/${f.bytes} bytes`)}let h=f?.bytes??1;for(o=Promise.withResolvers();;){if(n.byteLength>=h){o.resolve();break}if(await O(o.promise,f?.signal),Zo(t)){if(n.byteLength===0&&f?.bytes==null)return null;break}o=Promise.withResolvers()}let p=f?.bytes??n.byteLength;if(n.byteLength<p){if(Zo(t))throw t.log.error("closed while reading %d/%d bytes",n.byteLength,p),new Ue(`Unexpected EOF - stream closed while reading ${n.byteLength}/${p} bytes`);return l.read(f)}let x=n.sublist(0,p);return n.consume(p),x},async write(f,h){if(s===!0)throw new Jt("Stream was unwrapped");t.send(f)||await U(t,"drain",{signal:h?.signal,rejectionEvents:["close"]})},unwrap(){return s||(s=!0,t.removeEventListener("message",i),t.removeEventListener("close",a),t.removeEventListener("remoteCloseWrite",u),n.byteLength>0&&(t.log("stream unwrapped with %d unread bytes",n.byteLength),t.unshift(n))),t}};return l}function Ki(t,e={}){let r=Xi(t,e);e.maxDataLength!=null&&e.maxLengthLength==null&&(e.maxLengthLength=j(e.maxDataLength));let n=e?.lengthDecoder??ve,o=e?.lengthEncoder??Lr;return{async read(i){let a=-1,u=new N;for(;;){let f=await r.read({...i,bytes:1});if(f==null)break;u.append(f);try{a=n(u)}catch(h){if(h instanceof RangeError)continue;throw h}if(a<0)throw new vt("Invalid message length");if(e?.maxLengthLength!=null&&u.byteLength>e.maxLengthLength)throw new Xr(`Message length length too long - ${u.byteLength} > ${e.maxLengthLength}`);if(a>-1)break}if(e?.maxDataLength!=null&&a>e.maxDataLength)throw new Qr(`Message length too long - ${a} > ${e.maxDataLength}`);let l=await r.read({...i,bytes:a});if(l==null)throw t.log.error("tried to read %d bytes but the stream closed",a),new Ue(`Unexpected EOF - tried to read ${a} bytes but the stream closed`);if(l.byteLength!==a)throw t.log.error("read %d/%d bytes before the stream closed",l.byteLength,a),new Ue(`Unexpected EOF - read ${l.byteLength}/${a} bytes before the stream closed`);return l},async write(i,a){await r.write(new N(o(i.byteLength),i),a)},async writeV(i,a){let u=new N(...i.flatMap(l=>[o(l.byteLength),l]));await r.write(u,a)},unwrap(){return r.unwrap()}}}function pl(t,e){let r=Ki(t,e),n={read:async(o,s)=>{let i=await r.read(s);return o.decode(i)},write:async(o,s,i)=>{await r.write(s.encode(o),i)},writeV:async(o,s,i)=>{await r.writeV(o.map(a=>s.encode(a)),i)},pb:o=>({read:async s=>n.read(o,s),write:async(s,i)=>n.write(s,o,i),writeV:async(s,i)=>n.writeV(s,o,i),unwrap:()=>n}),unwrap:()=>r.unwrap()};return n}async function es(t,e){let r=t.log.newScope("echo"),n=Date.now(),o=0;try{for await(let s of t)o+=s.byteLength,t.send(s)||(t.pause(),await U(t,"drain",{rejectionEvents:["close"],...e}),t.resume());r("echoed %d bytes in %dms",o,Date.now()-n),await t.close(e)}catch(s){t.abort(s)}}function gl(t){return t?.addEventListener!=null}function Ji(t){let e=ge(),r,n=i=>{e.push(i.data)},o=()=>{e.end(),t.removeEventListener("message",n),t.removeEventListener("close",s),t.removeEventListener("remoteCloseWrite",o)},s=i=>{e.end(i.error),i.error!=null&&r?.reject(i.error),t.removeEventListener("message",n),t.removeEventListener("close",s),t.removeEventListener("remoteCloseWrite",o)};return t.addEventListener("message",n),t.addEventListener("close",s,{once:!0}),t.addEventListener("remoteCloseWrite",o,{once:!0}),{source:e,async sink(i){async function*a(){yield*i}let u=a();for(;;){r=Promise.withResolvers();let{done:l,value:f}=await Promise.race([u.next(),r.promise]);if(t.writeStatus==="closing"||t.writeStatus==="closed"||(f!=null&&(t.send(f)||await Promise.race([U(t,"drain",{rejectionEvents:["close"]})])),l===!0))break}await t.close()}}}function bl(...t){let e=t.map(r=>gl(r)?Ji(r):r);return Gi(...e)}var yl=1024*1024*4,xl=1024*1024*4,ts=class{buffer;maxBufferSize;lengthDecoder;maxDataLength;encodingLength;constructor(e={}){this.buffer=new N,this.maxBufferSize=e.maxBufferSize??yl,this.maxDataLength=e.maxDataLength??xl,this.lengthDecoder=e.lengthDecoder??ve,this.encodingLength=e.encodingLength??j}*decode(e){if(this.buffer.append(e),this.buffer.byteLength>this.maxBufferSize)throw new re(`Buffer length limit exceeded - ${this.buffer.byteLength}/${this.maxBufferSize}`);for(;;){let r;try{r=this.lengthDecoder(this.buffer)}catch(s){if(s instanceof RangeError)break;throw s}if(r<0||r>this.maxDataLength)throw new vt("Invalid message length");let n=this.encodingLength(r),o=n+r;if(this.buffer.byteLength>=o){let s=this.buffer.sublist(n,o);this.buffer.consume(o),s.byteLength>0&&(yield s)}else break}}};function wl(t){return!!(t.startsWith("169.254.")||t.toLowerCase().startsWith("fe80"))}var El=["Object","RegExp","Date","Error","Map","Set","WeakMap","WeakSet","ArrayBuffer","SharedArrayBuffer","DataView","Promise","URL","HTMLElement","Int8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array","Tagged"];function rs(t){if(t===null)return"null";if(t===void 0)return"undefined";if(t===!0||t===!1)return"boolean";let e=typeof t;if(e==="string"||e==="number"||e==="bigint"||e==="symbol")return e;if(e==="function")return"Function";if(Array.isArray(t))return"Array";if(t instanceof Uint8Array)return"Uint8Array";if(t.constructor===Object)return"Object";let r=_l(t);return r||"Object"}function _l(t){let e=Object.prototype.toString.call(t).slice(8,-1);if(El.includes(e))return e}var c=class{constructor(e,r,n){this.major=e,this.majorEncoded=e<<5,this.name=r,this.terminal=n}toString(){return`Type[${this.major}].${this.name}`}compare(e){return this.major<e.major?-1:this.major>e.major?1:0}static equals(e,r){return e===r||e.major===r.major&&e.name===r.name}};c.uint=new c(0,"uint",!0);c.negint=new c(1,"negint",!0);c.bytes=new c(2,"bytes",!0);c.string=new c(3,"string",!0);c.array=new c(4,"array",!1);c.map=new c(5,"map",!1);c.tag=new c(6,"tag",!1);c.float=new c(7,"float",!0);c.false=new c(7,"false",!0);c.true=new c(7,"true",!0);c.null=new c(7,"null",!0);c.undefined=new c(7,"undefined",!0);c.break=new c(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 Yt=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",vl=new TextEncoder;function Kr(t){return Yt&&globalThis.Buffer.isBuffer(t)}function Zt(t){return t instanceof Uint8Array?Kr(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):t:Uint8Array.from(t)}var Sl=24,Cl=200,Jr=Yt?t=>t.length>=Sl?globalThis.Buffer.from(t):Yi(t):t=>t.length>=Cl?vl.encode(t):Yi(t),be=t=>Uint8Array.from(t),Zi=Yt?(t,e,r)=>Kr(t)?new Uint8Array(t.subarray(e,r)):t.slice(e,r):(t,e,r)=>t.slice(e,r),ea=Yt?(t,e)=>(t=t.map(r=>r instanceof Uint8Array?r:globalThis.Buffer.from(r)),Zt(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},ta=Yt?t=>globalThis.Buffer.allocUnsafe(t):t=>new Uint8Array(t);function Yr(t,e){if(Kr(t)&&Kr(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 Yi(t){let e=[],r=0;for(let n=0;n<t.length;n++){let o=t.charCodeAt(n);o<128?e[r++]=o:o<2048?(e[r++]=o>>6|192,e[r++]=o&63|128):(o&64512)===55296&&n+1<t.length&&(t.charCodeAt(n+1)&64512)===56320?(o=65536+((o&1023)<<10)+(t.charCodeAt(++n)&1023),e[r++]=o>>18|240,e[r++]=o>>12&63|128,e[r++]=o>>6&63|128,e[r++]=o&63|128):(o>=55296&&o<=57343&&(o=65533),e[r++]=o>>12|224,e[r++]=o>>6&63|128,e[r++]=o&63|128)}return e}var Il=256,er=class{constructor(e=Il){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=ta(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=Zi(n,0,this.cursor)}else r=ea(this.chunks,this.cursor);return e&&this.reset(),r}},Zr=class{constructor(e){this.dest=e,this.cursor=0,this.chunks=[e]}reset(){this.cursor=0}push(e){if(this.cursor+e.length>this.dest.length)throw new Error("write out of bounds, destination buffer is too small");this.dest.set(e,this.cursor),this.cursor+=e.length}toBytes(e=!1){let r=this.dest.subarray(0,this.cursor);return e&&this.reset(),r}};var g="CBOR decode error:",en="CBOR encode error:",tr=[];tr[23]=1;tr[24]=2;tr[25]=3;tr[26]=5;tr[27]=9;function Le(t,e,r){if(t.length-e<r)throw new Error(`${g} not enough data for type`)}var R=[24,256,65536,4294967296,BigInt("18446744073709551616")];function J(t,e,r){Le(t,e,1);let n=t[e];if(r.strict===!0&&n<R[0])throw new Error(`${g} integer encoded in more bytes than necessary (strict decode)`);return n}function Y(t,e,r){Le(t,e,2);let n=t[e]<<8|t[e+1];if(r.strict===!0&&n<R[1])throw new Error(`${g} integer encoded in more bytes than necessary (strict decode)`);return n}function Z(t,e,r){Le(t,e,4);let n=t[e]*16777216+(t[e+1]<<16)+(t[e+2]<<8)+t[e+3];if(r.strict===!0&&n<R[2])throw new Error(`${g} integer encoded in more bytes than necessary (strict decode)`);return n}function ee(t,e,r){Le(t,e,8);let n=t[e]*16777216+(t[e+1]<<16)+(t[e+2]<<8)+t[e+3],o=t[e+4]*16777216+(t[e+5]<<16)+(t[e+6]<<8)+t[e+7],s=(BigInt(n)<<BigInt(32))+BigInt(o);if(r.strict===!0&&s<R[3])throw new Error(`${g} integer encoded in more bytes than necessary (strict decode)`);if(s<=Number.MAX_SAFE_INTEGER)return Number(s);if(r.allowBigInt===!0)return s;throw new Error(`${g} integers outside of the safe integer range are not supported`)}function ra(t,e,r,n){return new m(c.uint,J(t,e+1,n),2)}function na(t,e,r,n){return new m(c.uint,Y(t,e+1,n),3)}function oa(t,e,r,n){return new m(c.uint,Z(t,e+1,n),5)}function sa(t,e,r,n){return new m(c.uint,ee(t,e+1,n),9)}function ne(t,e){return D(t,0,e.value)}function D(t,e,r){if(r<R[0]){let n=Number(r);t.push([e|n])}else if(r<R[1]){let n=Number(r);t.push([e|24,n])}else if(r<R[2]){let n=Number(r);t.push([e|25,n>>>8,n&255])}else if(r<R[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<R[4]){let o=[e|27,0,0,0,0,0,0,0],s=Number(n&BigInt(4294967295)),i=Number(n>>BigInt(32)&BigInt(4294967295));o[8]=s&255,s=s>>8,o[7]=s&255,s=s>>8,o[6]=s&255,s=s>>8,o[5]=s&255,o[4]=i&255,i=i>>8,o[3]=i&255,i=i>>8,o[2]=i&255,i=i>>8,o[1]=i&255,t.push(o)}else throw new Error(`${g} encountered BigInt larger than allowable range`)}}ne.encodedSize=function(e){return D.encodedSize(e.value)};D.encodedSize=function(e){return e<R[0]?1:e<R[1]?2:e<R[2]?3:e<R[3]?5:9};ne.compareTokens=function(e,r){return e.value<r.value?-1:e.value>r.value?1:0};function ia(t,e,r,n){return new m(c.negint,-1-J(t,e+1,n),2)}function aa(t,e,r,n){return new m(c.negint,-1-Y(t,e+1,n),3)}function ca(t,e,r,n){return new m(c.negint,-1-Z(t,e+1,n),5)}var ns=BigInt(-1),ua=BigInt(1);function fa(t,e,r,n){let o=ee(t,e+1,n);if(typeof o!="bigint"){let s=-1-o;if(s>=Number.MIN_SAFE_INTEGER)return new m(c.negint,s,9)}if(n.allowBigInt!==!0)throw new Error(`${g} integers outside of the safe integer range are not supported`);return new m(c.negint,ns-BigInt(o),9)}function tn(t,e){let r=e.value,n=typeof r=="bigint"?r*ns-ua:r*-1-1;D(t,e.type.majorEncoded,n)}tn.encodedSize=function(e){let r=e.value,n=typeof r=="bigint"?r*ns-ua:r*-1-1;return n<R[0]?1:n<R[1]?2:n<R[2]?3:n<R[3]?5:9};tn.compareTokens=function(e,r){return e.value<r.value?1:e.value>r.value?-1:0};function rr(t,e,r,n){Le(t,e,r+n);let o=t.slice(e+r,e+r+n);return new m(c.bytes,o,r+n)}function la(t,e,r,n){return rr(t,e,1,r)}function ha(t,e,r,n){return rr(t,e,2,J(t,e+1,n))}function da(t,e,r,n){return rr(t,e,3,Y(t,e+1,n))}function ma(t,e,r,n){return rr(t,e,5,Z(t,e+1,n))}function pa(t,e,r,n){let o=ee(t,e+1,n);if(typeof o=="bigint")throw new Error(`${g} 64-bit integer bytes lengths not supported`);return rr(t,e,9,o)}function rn(t){return t.encodedBytes===void 0&&(t.encodedBytes=c.equals(t.type,c.string)?Jr(t.value):t.value),t.encodedBytes}function St(t,e){let r=rn(e);D(t,e.type.majorEncoded,r.length),t.push(r)}St.encodedSize=function(e){let r=rn(e);return D.encodedSize(r.length)+r.length};St.compareTokens=function(e,r){return Tl(rn(e),rn(r))};function Tl(t,e){return t.length<e.length?-1:t.length>e.length?1:Yr(t,e)}var ga=new TextDecoder,Dl=32;function kl(t,e,r){if(r-e<Dl){let o="";for(let s=e;s<r;s++){let i=t[s];if(i&128)return ga.decode(t.subarray(e,r));o+=String.fromCharCode(i)}return o}return ga.decode(t.subarray(e,r))}function nr(t,e,r,n,o){let s=r+n;Le(t,e,s);let i=new m(c.string,kl(t,e+r,e+s),s);return o.retainStringBytes===!0&&(i.byteValue=t.slice(e+r,e+s)),i}function ba(t,e,r,n){return nr(t,e,1,r,n)}function ya(t,e,r,n){return nr(t,e,2,J(t,e+1,n),n)}function xa(t,e,r,n){return nr(t,e,3,Y(t,e+1,n),n)}function wa(t,e,r,n){return nr(t,e,5,Z(t,e+1,n),n)}function Ea(t,e,r,n){let o=ee(t,e+1,n);if(typeof o=="bigint")throw new Error(`${g} 64-bit integer string lengths not supported`);return nr(t,e,9,o,n)}var _a=St;function Ct(t,e,r,n){return new m(c.array,n,r)}function va(t,e,r,n){return Ct(t,e,1,r)}function Sa(t,e,r,n){return Ct(t,e,2,J(t,e+1,n))}function Ca(t,e,r,n){return Ct(t,e,3,Y(t,e+1,n))}function Ia(t,e,r,n){return Ct(t,e,5,Z(t,e+1,n))}function La(t,e,r,n){let o=ee(t,e+1,n);if(typeof o=="bigint")throw new Error(`${g} 64-bit integer array lengths not supported`);return Ct(t,e,9,o)}function Ta(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${g} indefinite length items not allowed`);return Ct(t,e,1,1/0)}function nn(t,e){D(t,c.array.majorEncoded,e.value)}nn.compareTokens=ne.compareTokens;nn.encodedSize=function(e){return D.encodedSize(e.value)};function It(t,e,r,n){return new m(c.map,n,r)}function Aa(t,e,r,n){return It(t,e,1,r)}function Da(t,e,r,n){return It(t,e,2,J(t,e+1,n))}function ka(t,e,r,n){return It(t,e,3,Y(t,e+1,n))}function Pa(t,e,r,n){return It(t,e,5,Z(t,e+1,n))}function Ba(t,e,r,n){let o=ee(t,e+1,n);if(typeof o=="bigint")throw new Error(`${g} 64-bit integer map lengths not supported`);return It(t,e,9,o)}function Na(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${g} indefinite length items not allowed`);return It(t,e,1,1/0)}function on(t,e){D(t,c.map.majorEncoded,e.value)}on.compareTokens=ne.compareTokens;on.encodedSize=function(e){return D.encodedSize(e.value)};function Fa(t,e,r,n){return new m(c.tag,r,1)}function Ma(t,e,r,n){return new m(c.tag,J(t,e+1,n),2)}function Ua(t,e,r,n){return new m(c.tag,Y(t,e+1,n),3)}function Oa(t,e,r,n){return new m(c.tag,Z(t,e+1,n),5)}function Ra(t,e,r,n){return new m(c.tag,ee(t,e+1,n),9)}function sn(t,e){D(t,c.tag.majorEncoded,e.value)}sn.compareTokens=ne.compareTokens;sn.encodedSize=function(e){return D.encodedSize(e.value)};var os=20,ss=21,is=22,as=23;function $a(t,e,r,n){if(n.allowUndefined===!1)throw new Error(`${g} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new m(c.null,null,1):new m(c.undefined,void 0,1)}function za(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${g} indefinite length items not allowed`);return new m(c.break,void 0,1)}function cs(t,e,r){if(r){if(r.allowNaN===!1&&Number.isNaN(t))throw new Error(`${g} NaN values are not supported`);if(r.allowInfinity===!1&&(t===1/0||t===-1/0))throw new Error(`${g} Infinity values are not supported`)}return new m(c.float,t,e)}function Va(t,e,r,n){return cs(us(t,e+1),3,n)}function ja(t,e,r,n){return cs(fs(t,e+1),5,n)}function Wa(t,e,r,n){return cs(Qa(t,e+1),9,n)}function or(t,e,r){let n=e.value;if(n===!1)t.push([c.float.majorEncoded|os]);else if(n===!0)t.push([c.float.majorEncoded|ss]);else if(n===null)t.push([c.float.majorEncoded|is]);else if(n===void 0)t.push([c.float.majorEncoded|as]);else{let o,s=!1;(!r||r.float64!==!0)&&(Ga(n),o=us(fe,1),n===o||Number.isNaN(n)?(fe[0]=249,t.push(fe.slice(0,3)),s=!0):(Ha(n),o=fs(fe,1),n===o&&(fe[0]=250,t.push(fe.slice(0,5)),s=!0))),s||(Ml(n),o=Qa(fe,1),fe[0]=251,t.push(fe.slice(0,9)))}}or.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){Ga(n);let o=us(fe,1);if(n===o||Number.isNaN(n))return 3;if(Ha(n),o=fs(fe,1),n===o)return 5}return 9};var qa=new ArrayBuffer(9),oe=new DataView(qa,1),fe=new Uint8Array(qa,0);function Ga(t){if(t===1/0)oe.setUint16(0,31744,!1);else if(t===-1/0)oe.setUint16(0,64512,!1);else if(Number.isNaN(t))oe.setUint16(0,32256,!1);else{oe.setFloat32(0,t);let e=oe.getUint32(0),r=(e&2139095040)>>23,n=e&8388607;if(r===255)oe.setUint16(0,31744,!1);else if(r===0)oe.setUint16(0,(e&2147483648)>>16|n>>13,!1);else{let o=r-127;o<-24?oe.setUint16(0,0):o<-14?oe.setUint16(0,(e&2147483648)>>16|1<<24+o,!1):oe.setUint16(0,(e&2147483648)>>16|o+15<<10|n>>13,!1)}}}function us(t,e){if(t.length-e<2)throw new Error(`${g} not enough data for float16`);let r=(t[e]<<8)+t[e+1];if(r===31744)return 1/0;if(r===64512)return-1/0;if(r===32256)return NaN;let n=r>>10&31,o=r&1023,s;return n===0?s=o*2**-24:n!==31?s=(o+1024)*2**(n-25):s=o===0?1/0:NaN,r&32768?-s:s}function Ha(t){oe.setFloat32(0,t,!1)}function fs(t,e){if(t.length-e<4)throw new Error(`${g} not enough data for float32`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,4).getFloat32(0,!1)}function Ml(t){oe.setFloat64(0,t,!1)}function Qa(t,e){if(t.length-e<8)throw new Error(`${g} not enough data for float64`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,8).getFloat64(0,!1)}or.compareTokens=ne.compareTokens;function S(t,e,r){throw new Error(`${g} encountered invalid minor (${r}) for major ${t[e]>>>5}`)}function an(t){return()=>{throw new Error(`${g} ${t}`)}}var d=[];for(let t=0;t<=23;t++)d[t]=S;d[24]=ra;d[25]=na;d[26]=oa;d[27]=sa;d[28]=S;d[29]=S;d[30]=S;d[31]=S;for(let t=32;t<=55;t++)d[t]=S;d[56]=ia;d[57]=aa;d[58]=ca;d[59]=fa;d[60]=S;d[61]=S;d[62]=S;d[63]=S;for(let t=64;t<=87;t++)d[t]=la;d[88]=ha;d[89]=da;d[90]=ma;d[91]=pa;d[92]=S;d[93]=S;d[94]=S;d[95]=an("indefinite length bytes/strings are not supported");for(let t=96;t<=119;t++)d[t]=ba;d[120]=ya;d[121]=xa;d[122]=wa;d[123]=Ea;d[124]=S;d[125]=S;d[126]=S;d[127]=an("indefinite length bytes/strings are not supported");for(let t=128;t<=151;t++)d[t]=va;d[152]=Sa;d[153]=Ca;d[154]=Ia;d[155]=La;d[156]=S;d[157]=S;d[158]=S;d[159]=Ta;for(let t=160;t<=183;t++)d[t]=Aa;d[184]=Da;d[185]=ka;d[186]=Pa;d[187]=Ba;d[188]=S;d[189]=S;d[190]=S;d[191]=Na;for(let t=192;t<=215;t++)d[t]=Fa;d[216]=Ma;d[217]=Ua;d[218]=Oa;d[219]=Ra;d[220]=S;d[221]=S;d[222]=S;d[223]=S;for(let t=224;t<=243;t++)d[t]=an("simple values are not supported");d[244]=S;d[245]=S;d[246]=S;d[247]=$a;d[248]=an("simple values are not supported");d[249]=Va;d[250]=ja;d[251]=Wa;d[252]=S;d[253]=S;d[254]=S;d[255]=za;var le=[];for(let t=0;t<24;t++)le[t]=new m(c.uint,t,1);for(let t=-1;t>=-24;t--)le[31-t]=new m(c.negint,t,1);le[64]=new m(c.bytes,new Uint8Array(0),1);le[96]=new m(c.string,"",1);le[128]=new m(c.array,0,1);le[160]=new m(c.map,0,1);le[244]=new m(c.false,!1,1);le[245]=new m(c.true,!0,1);le[246]=new m(c.null,null,1);function ls(t){switch(t.type){case c.false:return be([244]);case c.true:return be([245]);case c.null:return be([246]);case c.bytes:return t.value.length?void 0:be([64]);case c.string:return t.value===""?be([96]):void 0;case c.array:return t.value===0?be([128]):void 0;case c.map:return t.value===0?be([160]):void 0;case c.uint:return t.value<24?be([Number(t.value)]):void 0;case c.negint:if(t.value>=-24)return be([31-Number(t.value)])}}var Ol={float64:!1,mapSorter:zl,quickEncodeToken:ls},Za=Object.freeze({float64:!0,mapSorter:Vl,quickEncodeToken:ls});function Rl(){let t=[];return t[c.uint.major]=ne,t[c.negint.major]=tn,t[c.bytes.major]=St,t[c.string.major]=_a,t[c.array.major]=nn,t[c.map.major]=on,t[c.tag.major]=sn,t[c.float.major]=or,t}var Tt=Rl(),cn=new er,ir=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(`${en} object contains circular references`);return new t(r,e)}},Oe={null:new m(c.null,null),undefined:new m(c.undefined,void 0),true:new m(c.true,!0),false:new m(c.false,!1),emptyArray:new m(c.array,0),emptyMap:new m(c.map,0)},ye={number(t,e,r,n){return!Number.isInteger(t)||!Number.isSafeInteger(t)?new m(c.float,t):t>=0?new m(c.uint,t):new m(c.negint,t)},bigint(t,e,r,n){return t>=BigInt(0)?new m(c.uint,t):new m(c.negint,t)},Uint8Array(t,e,r,n){return new m(c.bytes,t)},string(t,e,r,n){return new m(c.string,t)},boolean(t,e,r,n){return t?Oe.true:Oe.false},null(t,e,r,n){return Oe.null},undefined(t,e,r,n){return Oe.undefined},ArrayBuffer(t,e,r,n){return new m(c.bytes,new Uint8Array(t))},DataView(t,e,r,n){return new m(c.bytes,new Uint8Array(t.buffer,t.byteOffset,t.byteLength))},Array(t,e,r,n){if(!t.length)return r.addBreakTokens===!0?[Oe.emptyArray,new m(c.break)]:Oe.emptyArray;n=ir.createCheck(n,t);let o=[],s=0;for(let i of t)o[s++]=Lt(i,r,n);return r.addBreakTokens?[new m(c.array,t.length),o,new m(c.break)]:[new m(c.array,t.length),o]},Object(t,e,r,n){let o=e!=="Object",s=o?t.keys():Object.keys(t),i=o?t.size:s.length,a;if(i){a=new Array(i),n=ir.createCheck(n,t);let u=!o&&r.ignoreUndefinedProperties,l=0;for(let f of s){let h=o?t.get(f):t[f];u&&h===void 0||(a[l++]=[Lt(f,r,n),Lt(h,r,n)])}l<i&&(a.length=l)}return a?.length?($l(a,r),r.addBreakTokens?[new m(c.map,a.length),a,new m(c.break)]:[new m(c.map,a.length),a]):r.addBreakTokens===!0?[Oe.emptyMap,new m(c.break)]:Oe.emptyMap},Tagged(t,e,r,n){return[new m(c.tag,t.tag),Lt(t.value,r,n)]}};ye.Map=ye.Object;ye.Buffer=ye.Uint8Array;for(let t of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))ye[`${t}Array`]=ye.DataView;function Lt(t,e={},r){let n=rs(t),o=e&&e.typeEncoders&&e.typeEncoders[n]||ye[n];if(typeof o=="function"){let i=o(t,n,e,r);if(i!=null)return i}let s=ye[n];if(!s)throw new Error(`${en} unsupported type: ${n}`);return s(t,n,e,r)}function $l(t,e){e.mapSorter&&t.sort(e.mapSorter)}function zl(t,e){let r=Array.isArray(t[0])?t[0][0]:t[0],n=Array.isArray(e[0])?e[0][0]:e[0];if(r.type!==n.type)return r.type.compare(n.type);let o=r.type.major,s=Tt[o].compareTokens(r,n);return s===0&&console.warn("WARNING: complex key types used, CBOR key sorting guarantees are gone"),s}function Vl(t,e){if(t[0]instanceof m&&e[0]instanceof m){let r=t[0],n=e[0];return r._keyBytes||(r._keyBytes=Xa(r.value)),n._keyBytes||(n._keyBytes=Xa(n.value)),Yr(r._keyBytes,n._keyBytes)}throw new Error("rfc8949MapSorter: complex key types are not supported yet")}function Xa(t){return tc(t,Tt,Za)}function sr(t,e,r,n){if(Array.isArray(e))for(let o of e)sr(t,o,r,n);else r[e.type.major](t,e,n)}var Ka=c.uint.majorEncoded,Ja=c.negint.majorEncoded,jl=c.bytes.majorEncoded,Wl=c.string.majorEncoded,Ya=c.array.majorEncoded,ql=c.float.majorEncoded|os,Gl=c.float.majorEncoded|ss,Hl=c.float.majorEncoded|is,Ql=c.float.majorEncoded|as,Xl=BigInt(-1),Kl=BigInt(1);function Jl(t){return t.addBreakTokens!==!0}function ec(t,e,r,n){let o=rs(e),s=r.typeEncoders&&r.typeEncoders[o];if(s){let i=s(e,o,r,n);if(i!=null){sr(t,i,Tt,r);return}}switch(o){case"null":t.push([Hl]);return;case"undefined":t.push([Ql]);return;case"boolean":t.push([e?Gl:ql]);return;case"number":!Number.isInteger(e)||!Number.isSafeInteger(e)?or(t,new m(c.float,e),r):e>=0?D(t,Ka,e):D(t,Ja,e*-1-1);return;case"bigint":e>=BigInt(0)?D(t,Ka,e):D(t,Ja,e*Xl-Kl);return;case"string":{let i=Jr(e);D(t,Wl,i.length),t.push(i);return}case"Uint8Array":D(t,jl,e.length),t.push(e);return;case"Array":if(!e.length){t.push([Ya]);return}n=ir.createCheck(n,e),D(t,Ya,e.length);for(let i of e)ec(t,i,r,n);return;case"Object":case"Map":{let i=ye.Object(e,o,r,n);sr(t,i,Tt,r)}return;default:{let i=ye[o];if(!i)throw new Error(`${en} unsupported type: ${o}`);let a=i(e,o,r,n);sr(t,a,Tt,r)}}}function tc(t,e,r,n){let o=n instanceof Uint8Array,s=o?new Zr(n):cn,i=Lt(t,r);if(!Array.isArray(i)&&r.quickEncodeToken){let a=r.quickEncodeToken(i);if(a)return o?(s.push(a),s.toBytes()):a;let u=e[i.type.major];if(u.encodedSize){let l=u.encodedSize(i,r);if(o||(s=new er(l)),u(s,i,r),s.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${i} was wrong`);return o?s.toBytes():Zt(s.chunks[0])}}return s.reset(),sr(s,i,e,r),s.toBytes(!0)}function hs(t,e){return e=Object.assign({},Ol,e),Jl(e)?(cn.reset(),ec(cn,t,e,void 0),cn.toBytes(!0)):tc(t,Tt,e)}var Yl={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},un=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=le[e];if(r===void 0){let n=d[e];if(!n)throw new Error(`${g} 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}},Re=Symbol.for("DONE"),At=Symbol.for("BREAK");function Zl(t,e,r){let n=[];for(let o=0;o<t.value;o++){let s=$e(e,r);if(s===At){if(t.value===1/0)break;throw new Error(`${g} got unexpected break to lengthed array`)}if(s===Re)throw new Error(`${g} found array but not enough entries (got ${o}, expected ${t.value})`);n[o]=s}return n}function eh(t,e,r){let n=r.useMaps===!0,o=r.rejectDuplicateMapKeys===!0,s=n?void 0:{},i=n?new Map:void 0;for(let a=0;a<t.value;a++){let u=$e(e,r);if(u===At){if(t.value===1/0)break;throw new Error(`${g} got unexpected break to lengthed map`)}if(u===Re)throw new Error(`${g} found map but not enough entries (got ${a} [no key], expected ${t.value})`);if(!n&&typeof u!="string")throw new Error(`${g} non-string keys not supported (got ${typeof u})`);if(o&&(n&&i.has(u)||!n&&Object.hasOwn(s,u)))throw new Error(`${g} found repeat map key "${u}"`);let l=$e(e,r);if(l===Re)throw new Error(`${g} found map but not enough entries (got ${a} [no value], expected ${t.value})`);n?i.set(u,l):s[u]=l}return n?i:s}function*th(t,e,r){for(let n=0;n<t.value;n++){let o=$e(e,r);if(o===At){if(t.value===1/0)break;throw new Error(`${g} got unexpected break to lengthed map`)}if(o===Re)throw new Error(`${g} found map but not enough entries (got ${n} [no key], expected ${t.value})`);let s=$e(e,r);if(s===Re)throw new Error(`${g} found map but not enough entries (got ${n} [no value], expected ${t.value})`);yield[o,s]}}function rh(t,e){let r=!1,n=function(){if(r)throw new Error(`${g} tag decode() may only be called once`);r=!0;let o=$e(t,e);if(o===Re)throw new Error(`${g} tag content missing`);if(o===At)throw new Error(`${g} got unexpected break in tag content`);return o};return n.entries=function(){if(r)throw new Error(`${g} tag decode() may only be called once`);r=!0;let o=t.next();if(!c.equals(o.type,c.map))throw new Error(`${g} entries() requires map content, got ${o.type.name}`);let s=[];for(let i of th(o,t,e))s.push(i);return s},Object.defineProperty(n,"_called",{get(){return r},enumerable:!1}),n}function $e(t,e){if(t.done())return Re;let r=t.next();if(c.equals(r.type,c.break))return At;if(r.type.terminal)return r.value;if(c.equals(r.type,c.array))return Zl(r,t,e);if(c.equals(r.type,c.map))return eh(r,t,e);if(c.equals(r.type,c.tag)){if(e.tags&&typeof e.tags[r.value]=="function"){let n=rh(t,e),o=e.tags[r.value](n);if(!n._called)throw new Error(`${g} tag decoder must call decode() or entries()`);return o}throw new Error(`${g} tag not supported (${r.value})`)}throw new Error("unsupported")}function rc(t,e){if(!(t instanceof Uint8Array))throw new Error(`${g} data to decode must be a Uint8Array`);e=Object.assign({},Yl,e);let r=Zt(t),n=e.tokenizer||new un(r,e),o=$e(n,e);if(o===Re)throw new Error(`${g} did not find any content to decode`);if(o===At)throw new Error(`${g} got unexpected break`);return[o,t.subarray(n.pos())]}function ds(t,e){let[r,n]=rc(t,e);if(n.length>0)throw new Error(`${g} too many terminals, data makes no sense`);return r}var fn=class t{constructor(e,r){if(typeof e!="number"||!Number.isInteger(e)||e<0)throw new TypeError("Tagged: tag must be a non-negative integer");this.tag=e,this.value=r}static decoder(e){return r=>new t(e,r())}static preserve(...e){let r={};for(let n of e)r[n]=t.decoder(n);return r}};Object.defineProperty(fn.prototype,Symbol.toStringTag,{value:"Tagged"});var ln=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},Dt=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},hn=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"},ar=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};function dn(t){return t[Symbol.asyncIterator]!=null}function nc(t,e){if(t.byteLength>e)throw new Dt("Message length too long")}var pn=t=>{let e=j(t),r=K(e);return Lr(t,r),pn.bytes=e,r};pn.bytes=0;function gn(t,e){e=e??{};let r=e.lengthEncoder??pn,n=e?.maxDataLength??4194304;function*o(s){nc(s,n);let i=r(s.byteLength);i instanceof Uint8Array?yield i:yield*i,s instanceof Uint8Array?yield s:yield*s}return dn(t)?(async function*(){for await(let s of t)yield*o(s)})():(function*(){for(let s of t)yield*o(s)})()}gn.single=(t,e)=>{e=e??{};let r=e.lengthEncoder??pn,n=e?.maxDataLength??4194304;return nc(t,n),new N(r(t.byteLength),t)};var tt;(function(t){t[t.LENGTH=0]="LENGTH",t[t.DATA=1]="DATA"})(tt||(tt={}));var ms=t=>{let e=ve(t);return ms.bytes=j(e),e};ms.bytes=0;function cr(t,e){let r=new N,n=tt.LENGTH,o=-1,s=e?.lengthDecoder??ms,i=e?.maxLengthLength??8,a=e?.maxDataLength??4194304;function*u(){for(;r.byteLength>0;){if(n===tt.LENGTH)try{if(o=s(r),o<0)throw new ln("Invalid message length");if(o>a)throw new Dt("Message length too long");let l=s.bytes;r.consume(l),e?.onLength!=null&&e.onLength(o),n=tt.DATA}catch(l){if(l instanceof RangeError){if(r.byteLength>i)throw new hn("Message length length too long");break}throw l}if(n===tt.DATA){if(r.byteLength<o)break;let l=r.sublist(0,o);r.consume(o),e?.onData!=null&&e.onData(l),yield l,n=tt.LENGTH}}}return dn(t)?(async function*(){for await(let l of t)r.append(l),yield*u();if(r.byteLength>0)throw new ar("Unexpected end of input")})():(function*(){for(let l of t)r.append(l),yield*u();if(r.byteLength>0)throw new ar("Unexpected end of input")})()}cr.fromReader=(t,e)=>{let r=1,n=(async function*(){for(;;)try{let{done:s,value:i}=await t.next(r);if(s===!0)return;i!=null&&(yield i)}catch(s){if(s.code==="ERR_UNDER_READ")return{done:!0,value:null};throw s}finally{r=1}})();return cr(n,{...e??{},onLength:s=>{r=s}})};var ps=class extends Ye{sendMessage;dataQueue;encoding;constructor(e){super(e),this.sendMessage=e.sendMessage,this.encoding=e.encoding,this.dataQueue=new ue({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()}},oc=30,gs=class extends Kt{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)+oc,this.encoding=r.encoding??"base64",this.input=ge(),this.sendMessage=this.sendMessage.bind(this),this.nextStreamId=this.maConn.direction==="outbound"?0:1,Promise.resolve().then(async()=>{for await(let n of cr(this.input,{maxDataLength:this.maxMessageSize}))this.onMessage(ds(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=hs(e),n=gn.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 ps({...this.streamOptions,...n,id:e,direction:r,log:this.log.newScope(`stream:${r}:${e}`),sendMessage:this.sendMessage,encoding:this.encoding,maxMessageSize:this.maxMessageSize-oc,protocol:""})}},bs=class{protocol="/mock-muxer/1.0.0";init;constructor(e){this.init=e}createStreamMuxer(e){return new gs(e,{...this.init})}};function bn(t={}){return new bs(t)}function yn(t,e){if(typeof t=="string")return ih(t);if(typeof t=="number")return uh(t,e);throw new Error(`Value provided to ms() must be a string or number. value=${JSON.stringify(t)}`)}function ih(t){if(typeof t!="string"||t.length===0||t.length>100)throw new Error(`Value provided to ms.parse() must be a string with length between 1 and 99. value=${JSON.stringify(t)}`);let e=/^(?<value>-?\d*\.?\d+) *(?<unit>milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|months?|mo|years?|yrs?|y)?$/i.exec(t);if(!e?.groups)return NaN;let{value:r,unit:n="ms"}=e.groups,o=parseFloat(r),s=n.toLowerCase();switch(s){case"years":case"year":case"yrs":case"yr":case"y":return o*315576e5;case"months":case"month":case"mo":return o*26298e5;case"weeks":case"week":case"w":return o*6048e5;case"days":case"day":case"d":return o*864e5;case"hours":case"hour":case"hrs":case"hr":case"h":return o*36e5;case"minutes":case"minute":case"mins":case"min":case"m":return o*6e4;case"seconds":case"second":case"secs":case"sec":case"s":return o*1e3;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return o;default:throw new Error(`Unknown unit "${s}" provided to ms.parse(). value=${JSON.stringify(t)}`)}}function ah(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 ch(t){let e=Math.abs(t);return e>=315576e5?rt(t,e,315576e5,"year"):e>=26298e5?rt(t,e,26298e5,"month"):e>=6048e5?rt(t,e,6048e5,"week"):e>=864e5?rt(t,e,864e5,"day"):e>=36e5?rt(t,e,36e5,"hour"):e>=6e4?rt(t,e,6e4,"minute"):e>=1e3?rt(t,e,1e3,"second"):`${t} ms`}function uh(t,e){if(typeof t!="number"||!Number.isFinite(t))throw new Error("Value provided to ms.format() must be of type number.");return e?.long?ch(t):ah(t)}function rt(t,e,r,n){let o=e>=r*1.5;return`${Math.round(t/r)} ${n}${o?"s":""}`}function ys(t){r.debug=r,r.default=r,r.coerce=u,r.disable=s,r.enable=o,r.enabled=i,r.humanize=yn,r.destroy=l,Object.keys(t).forEach(f=>{r[f]=t[f]}),r.names=[],r.skips=[],r.formatters={};function e(f){let h=0;for(let p=0;p<f.length;p++)h=(h<<5)-h+f.charCodeAt(p),h|=0;return r.colors[Math.abs(h)%r.colors.length]}r.selectColor=e;function r(f,h){let p,x=null,E,L;function y(..._){if(!y.enabled)return;let k=y,P=Number(new Date),q=P-(p||P);k.diff=q,k.prev=p,k.curr=P,p=P,_[0]=r.coerce(_[0]),typeof _[0]!="string"&&_.unshift("%O");let $=0;_[0]=_[0].replace(/%([a-zA-Z%])/g,(G,se)=>{if(G==="%%")return"%";$++;let ze=r.formatters[se];if(typeof ze=="function"){let pc=_[$];G=ze.call(k,pc),_.splice($,1),$--}return G}),r.formatArgs.call(k,_),h?.onLog!=null&&h.onLog(..._),(k.log||r.log).apply(k,_)}return y.namespace=f,y.useColors=r.useColors(),y.color=r.selectColor(f),y.extend=n,y.destroy=r.destroy,Object.defineProperty(y,"enabled",{enumerable:!0,configurable:!1,get:()=>x!==null?x:(E!==r.namespaces&&(E=r.namespaces,L=r.enabled(f)),L),set:_=>{x=_}}),typeof r.init=="function"&&r.init(y),y}function n(f,h){let p=r(this.namespace+(typeof h>"u"?":":h)+f);return p.log=this.log,p}function o(f){r.save(f),r.namespaces=f,r.names=[],r.skips=[];let h,p=(typeof f=="string"?f:"").split(/[\s,]+/),x=p.length;for(h=0;h<x;h++)p[h]&&(f=p[h].replace(/\*/g,".*?"),f[0]==="-"?r.skips.push(new RegExp("^"+f.substr(1)+"$")):r.names.push(new RegExp("^"+f+"$")))}function s(){let f=[...r.names.map(a),...r.skips.map(a).map(h=>"-"+h)].join(",");return r.enable(""),f}function i(f){if(f[f.length-1]==="*")return!0;let h,p;for(h=0,p=r.skips.length;h<p;h++)if(r.skips[h].test(f))return!1;for(h=0,p=r.names.length;h<p;h++)if(r.names[h].test(f))return!0;return!1}function a(f){return f.toString().substring(2,f.toString().length-2).replace(/\.\*\?$/,"*")}function u(f){return f instanceof Error?f.stack??f.message:f}function l(){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 xn=gh(),fh=["#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 lh(){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 hh(t){if(t[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+t[0]+(this.useColors?"%c ":" ")+"+"+yn(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 dh=console.debug??console.log??(()=>{});function mh(t){try{t?xn?.setItem("debug",t):xn?.removeItem("debug")}catch{}}function ph(){let t;try{t=xn?.getItem("debug")}catch{}return!t&&typeof globalThis.process<"u"&&"env"in globalThis.process&&(t=globalThis.process.env.DEBUG),t}function gh(){try{return localStorage}catch{}}function bh(t){t.j=function(e){try{return JSON.stringify(e)}catch(r){return"[UnexpectedJSONParseError]: "+r.message}}}var sc=ys({formatArgs:hh,save:mh,load:ph,useColors:lh,setupFormatters:bh,colors:fh,storage:xn,log:dh});var Q=sc;Q.formatters.b=t=>t==null?"undefined":te.baseEncode(t);Q.formatters.t=t=>t==null?"undefined":he.baseEncode(t);Q.formatters.m=t=>t==null?"undefined":Fn.baseEncode(t);Q.formatters.p=t=>t==null?"undefined":t.toString();Q.formatters.c=t=>t==null?"undefined":t.toString();Q.formatters.k=t=>t==null?"undefined":t.toString();Q.formatters.a=t=>t==null?"undefined":t.toString();function ic(t,e=""){let r=ac(t.message),n=ac(t.stack);return r!=null&&n!=null?n.includes(r)?`${n.split(`
2
+ "use strict";var Libp2PUtils=(()=>{var xc=Object.create;var mr=Object.defineProperty;var wc=Object.getOwnPropertyDescriptor;var Ec=Object.getOwnPropertyNames;var _c=Object.getPrototypeOf,vc=Object.prototype.hasOwnProperty;var Cn=(t,e)=>()=>{try{return e||t((e={exports:{}}).exports,e),e.exports}catch(r){throw e=0,r}},X=(t,e)=>{for(var r in e)mr(t,r,{get:e[r],enumerable:!0})},As=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Ec(e))!vc.call(t,o)&&o!==r&&mr(t,o,{get:()=>e[o],enumerable:!(n=wc(e,o))||n.enumerable});return t};var Sc=(t,e,r)=>(r=t!=null?xc(_c(t)):{},As(e||!t||!t.__esModule?mr(r,"default",{value:t,enumerable:!0}):r,t)),Cc=t=>As(mr({},"__esModule",{value:!0}),t);var oo=Cn(gt=>{"use strict";Object.defineProperty(gt,"__esModule",{value:!0});gt.Netmask4Impl=void 0;gt.ip2long=pt;gt.long2ip=xe;function xe(t){let e=(t&-16777216)>>>24,r=(t&255<<16)>>>16,n=(t&65280)>>>8,o=t&255;return[e,r,n,o].join(".")}var Ju=48,Yu=97,Zu=65;function ef(t){let e=0,r=10,n="9",o=0;t.length>1&&t[o]==="0"&&(t[o+1]==="x"||t[o+1]==="X"?(o+=2,r=16):"0"<=t[o+1]&&t[o+1]<="9"&&(o++,r=8,n="7"));let s=o;for(;o<t.length;){if("0"<=t[o]&&t[o]<=n)e=e*r+(t.charCodeAt(o)-Ju)>>>0;else if(r===16)if("a"<=t[o]&&t[o]<="f")e=e*r+(10+t.charCodeAt(o)-Yu)>>>0;else if("A"<=t[o]&&t[o]<="F")e=e*r+(10+t.charCodeAt(o)-Zu)>>>0;else break;else break;if(e>4294967295)throw new Error("too large");o++}if(o===s)throw new Error("empty octet");return[e,o]}function pt(t){let e=[];for(let r=0;r<=3&&t.length!==0;r++){if(r>0){if(t[0]!==".")throw new Error("Invalid IP");t=t.substring(1)}let[n,o]=ef(t);t=t.substring(o),e.push(n)}if(t.length!==0)throw new Error("Invalid IP");switch(e.length){case 1:if(e[0]>4294967295)throw new Error("Invalid IP");return e[0]>>>0;case 2:if(e[0]>255||e[1]>16777215)throw new Error("Invalid IP");return(e[0]<<24|e[1])>>>0;case 3:if(e[0]>255||e[1]>255||e[2]>65535)throw new Error("Invalid IP");return(e[0]<<24|e[1]<<16|e[2])>>>0;case 4:if(e[0]>255||e[1]>255||e[2]>255||e[3]>255)throw new Error("Invalid IP");return(e[0]<<24|e[1]<<16|e[2]<<8|e[3])>>>0;default:throw new Error("Invalid IP")}}var no=class t{constructor(e,r){if(typeof e!="string")throw new Error("Missing `net' parameter");let n=r;if(!n){let o=e.split("/",2);e=o[0],n=o[1]}if(n||(n=32),typeof n=="string"&&n.indexOf(".")>-1){try{this.maskLong=pt(n)}catch{throw new Error("Invalid mask: "+n)}this.bitmask=NaN;for(let o=32;o>=0;o--)if(this.maskLong===4294967295<<32-o>>>0){this.bitmask=o;break}}else if(n||n===0)this.bitmask=parseInt(n,10),this.maskLong=0,this.bitmask>0&&(this.maskLong=4294967295<<32-this.bitmask>>>0);else throw new Error("Invalid mask: empty");try{this.netLong=(pt(e)&this.maskLong)>>>0}catch{throw new Error("Invalid net address: "+e)}if(!(this.bitmask<=32))throw new Error("Invalid mask for ip4: "+n);this.size=Math.pow(2,32-this.bitmask),this.base=xe(this.netLong),this.mask=xe(this.maskLong),this.hostmask=xe(~this.maskLong),this.first=this.bitmask<=30?xe(this.netLong+1):this.base,this.last=this.bitmask<=30?xe(this.netLong+this.size-2):xe(this.netLong+this.size-1),this.broadcast=this.bitmask<=30?xe(this.netLong+this.size-1):void 0}contains(e){return typeof e=="string"&&(e.indexOf("/")>0||e.split(".").length!==4)&&(e=new t(e)),e instanceof t?this.contains(e.base)&&this.contains(e.broadcast||e.last):(pt(e)&this.maskLong)>>>0===(this.netLong&this.maskLong)>>>0}next(e=1){return new t(xe(this.netLong+this.size*e),this.mask)}forEach(e){let r=pt(this.first),n=pt(this.last),o=0;for(;r<=n;)e(xe(r),r,o),o++,r++}toString(){return this.base+"/"+this.bitmask}};gt.Netmask4Impl=no});var mi=Cn(bt=>{"use strict";Object.defineProperty(bt,"__esModule",{value:!0});bt.Netmask6Impl=void 0;bt.ip6bigint=io;bt.bigint2ip6=Ke;var tf=oo(),so=(1n<<128n)-1n;function io(t){let e=t.indexOf("%");e!==-1&&(t=t.substring(0,e));let r=t.lastIndexOf(":");if(r!==-1&&t.indexOf(".",r)!==-1){let n=t.substring(r+1),o=(0,tf.ip2long)(n),s=t.substring(0,r+1)+"0:0";return di(s)&~0xffffffffn|BigInt(o)}return di(t)}function di(t){let e=t.indexOf("::"),r;if(e!==-1){let o=t.substring(0,e),s=t.substring(e+2),i=o===""?[]:o.split(":"),a=s===""?[]:s.split(":"),u=8-i.length-a.length;if(u<0)throw new Error("Invalid IPv6: too many groups");r=[...i,...Array(u).fill("0"),...a]}else r=t.split(":");if(r.length!==8)throw new Error("Invalid IPv6: expected 8 groups, got "+r.length);let n=0n;for(let o=0;o<8;o++){let s=r[o];if(s.length===0||s.length>4)throw new Error('Invalid IPv6: bad group "'+s+'"');let i=parseInt(s,16);if(isNaN(i)||i<0||i>65535)throw new Error('Invalid IPv6: bad group "'+s+'"');n=n<<16n|BigInt(i)}return n}function Ke(t){if(t<0n||t>so)throw new Error("Invalid IPv6 address value");let e=[];for(let i=0;i<8;i++)e.unshift(Number(t&0xffffn)),t>>=16n;let r=-1,n=0,o=-1,s=0;for(let i=0;i<8;i++)e[i]===0?o===-1?(o=i,s=1):s++:(s>n&&s>=2&&(r=o,n=s),o=-1,s=0);if(s>n&&s>=2&&(r=o,n=s),r!==-1&&r+n===8&&r>0)return e.slice(0,r).map(a=>a.toString(16)).join(":")+"::";if(r===0)return"::"+e.slice(n).map(a=>a.toString(16)).join(":");if(r>0){let i=e.slice(0,r).map(u=>u.toString(16)),a=e.slice(r+n).map(u=>u.toString(16));return i.join(":")+"::"+a.join(":")}else return e.map(i=>i.toString(16)).join(":")}var ao=class t{constructor(e,r){if(typeof e!="string")throw new Error("Missing `net' parameter");let n=r;if(n==null){let o=e.indexOf("/");o!==-1?(n=parseInt(e.substring(o+1),10),e=e.substring(0,o)):n=128}if(isNaN(n)||n<0||n>128)throw new Error("Invalid mask for IPv6: "+n);this.bitmask=n,this.bitmask===0?this.maskBigint=0n:this.maskBigint=so>>BigInt(128-this.bitmask)<<BigInt(128-this.bitmask);try{this.netBigint=io(e)&this.maskBigint}catch{throw new Error("Invalid IPv6 net address: "+e)}this.size=Number(1n<<BigInt(128-this.bitmask)),this.base=Ke(this.netBigint),this.mask=Ke(this.maskBigint),this.hostmask=Ke(~this.maskBigint&so),this.first=this.base,this.last=Ke(this.netBigint+(1n<<BigInt(128-this.bitmask))-1n),this.broadcast=void 0}contains(e){return typeof e=="string"&&e.indexOf("/")>0&&(e=new t(e)),e instanceof t?this.contains(e.base)&&this.contains(e.last):(io(e)&this.maskBigint)===this.netBigint}next(e=1){let r=1n<<BigInt(128-this.bitmask);return new t(Ke(this.netBigint+r*BigInt(e)),this.bitmask)}forEach(e){let r=this.netBigint,n=1n<<BigInt(128-this.bitmask),o=this.netBigint+n-1n,s=0;for(;r<=o;)e(Ke(r),Number(r),s),s++,r++}toString(){return this.base+"/"+this.bitmask}};bt.Netmask6Impl=ao});var pi=Cn(Ue=>{"use strict";Object.defineProperty(Ue,"__esModule",{value:!0});Ue.long2ip=Ue.ip2long=Ue.Netmask=void 0;var Lr=oo();Object.defineProperty(Ue,"ip2long",{enumerable:!0,get:function(){return Lr.ip2long}});Object.defineProperty(Ue,"long2ip",{enumerable:!0,get:function(){return Lr.long2ip}});var rf=mi(),co=class t{constructor(e,r){if(typeof e!="string")throw new Error("Missing `net' parameter");(e.indexOf("/")!==-1?e.substring(0,e.indexOf("/")):e).indexOf(":")!==-1?this._impl=new rf.Netmask6Impl(e,r):this._impl=new Lr.Netmask4Impl(e,r),this.base=this._impl.base,this.mask=this._impl.mask,this.hostmask=this._impl.hostmask,this.bitmask=this._impl.bitmask,this.size=this._impl.size,this.first=this._impl.first,this.last=this._impl.last,this.broadcast=this._impl.broadcast,this._impl instanceof Lr.Netmask4Impl?(this.maskLong=this._impl.maskLong,this.netLong=this._impl.netLong):(this.maskLong=0,this.netLong=0)}contains(e){return typeof e=="string"&&(e.indexOf("/")>0?e=new t(e):e.indexOf(":")===-1&&e.split(".").length!==4&&(e=new t(e))),e instanceof t?this.contains(e.base)&&this.contains(e.broadcast||e.last):this._impl.contains(e)}next(e=1){let r=this._impl.next(e);return new t(r.base,r.bitmask)}forEach(e){this._impl.forEach(e)}toString(){return this._impl.toString()}};Ue.Netmask=co});var Bh={};X(Bh,{AbstractMessageStream:()=>Ze,AbstractMultiaddrConnection:()=>Jt,AbstractStream:()=>et,AbstractStreamMuxer:()=>Yt,AdaptiveTimeout:()=>Zo,BloomFilter:()=>Rt,CuckooFilter:()=>Be,DEFAULT_FAILURE_MULTIPLIER:()=>ji,DEFAULT_INTERVAL:()=>Gi,DEFAULT_MAX_TIMEOUT:()=>qi,DEFAULT_MIN_TIMEOUT:()=>Wi,DEFAULT_TIMEOUT_MULTIPLIER:()=>Vi,InvalidDataLengthError:()=>Jr,InvalidDataLengthLengthError:()=>Yr,InvalidMessageLengthError:()=>Ct,LengthPrefixedDecoder:()=>os,MaxEarlyStreamsError:()=>Xt,MemoryStorage:()=>Sn,MockStream:()=>_s,MovingAverage:()=>tt,PeerQueue:()=>Cs,PriorityQueue:()=>Is,Queue:()=>de,QueueFullError:()=>Qt,RateLimitError:()=>Ht,RateLimiter:()=>Ls,ScalableCuckooFilter:()=>$t,StreamClosedError:()=>Kt,UnexpectedEOFError:()=>$e,UnwrappedError:()=>Zt,byteStream:()=>Zi,circuitRelayAddressesLast:()=>$i,createBloomFilter:()=>ni,createCuckooFilter:()=>oi,createScalableCuckooFilter:()=>si,debounce:()=>St,defaultMultiaddrSorter:()=>Xf,echo:()=>ns,echoStream:()=>Dh,getNetConfig:()=>le,getThinWaistAddresses:()=>rl,ipPortToMultiaddr:()=>ol,isAsyncGenerator:()=>sl,isGenerator:()=>il,isGlobalUnicast:()=>Qu,isGlobalUnicastIp:()=>nl,isLinkLocal:()=>Xu,isLinkLocalIp:()=>vl,isLoopback:()=>Ir,isNetworkAddress:()=>Ku,isPrivate:()=>Tr,isPrivateIp:()=>fo,isPromise:()=>Yo,loopbackAddressLast:()=>Oi,lpStream:()=>ea,messageStreamToDuplex:()=>ta,mockMuxer:()=>wn,multiaddrConnectionPair:()=>Ss,pbStream:()=>yl,pipe:()=>wl,publicAddressesFirst:()=>Ri,reliableTransportsFirst:()=>Ui,repeatingTask:()=>Ah,streamPair:()=>yc,trackedList:()=>kh,trackedMap:()=>Ph,tryGetNetConfig:()=>Er});function G(t=0){return new Uint8Array(t)}function K(t=0){return new Uint8Array(t)}function Ic(t){return t?.buffer instanceof ArrayBuffer}function In(t){if(Ic(t))return t;let e=t.slice();return new Uint8Array(e.buffer,0,e.byteLength)}function Se(t,e){e==null&&(e=t.reduce((o,s)=>o+s.length,0));let r=K(e),n=0;for(let o of t)r.set(o,n),n+=o.length;return In(r)}function We(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}var ks=Symbol.for("@achingbrain/uint8arraylist");function Ds(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 st(t){return!!t?.[ks]}var k=class t{bufs;length;[ks]=!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(st(n)){r+=n.byteLength;for(let o of n.bufs)this.bufs.push(o)}else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}prepend(...e){this.prependAll(e)}prependAll(e){let r=0;for(let n of e.reverse())if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.unshift(n);else if(st(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=Ds(this.bufs,e);return r.buf[r.index]}set(e,r){let n=Ds(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(st(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 Se(n,o)}subarray(e,r){let{bufs:n,length:o}=this._subList(e,r);return n.length===1?n[0]:Se(n,o)}sublist(e,r){let{bufs:n,length:o}=this._subList(e,r),s=new t;return s.length=o,s.bufs=n,s}_subList(e,r){if(e=e??0,r=r??this.length,e<0&&(e=this.length+e),r<0&&(r=this.length+r),e<0||r>this.length)throw new RangeError("index is out of bounds");if(e===r)return{bufs:[],length:0};if(e===0&&r===this.length)return{bufs:[...this.bufs],length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],a=o,u=a+i.byteLength;if(o=u,e>=u)continue;let l=e>=a&&e<u,f=r>a&&r<=u;if(l&&f){if(e===a&&r===u){n.push(i);break}let h=e-a;n.push(i.subarray(h,h+(r-e)));break}if(l){if(e===0){n.push(i);continue}n.push(i.subarray(e-a));continue}if(f){if(r===u){n.push(i);break}n.push(i.subarray(0,r-a));break}n.push(i)}return{bufs:n,length:r-e}}indexOf(e,r=0){if(!st(e)&&!(e instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=e instanceof Uint8Array?e:e.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),e.length===0)return r>this.length?this.length:r;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let h=0;h<s;h++)i[h]=-1;for(let h=0;h<o;h++)i[n[h]]=h;let a=i,u=this.byteLength-n.byteLength,l=n.byteLength-1,f;for(let h=r;h<=u;h+=f){f=0;for(let p=l;p>=0;p--){let x=this.get(h+p);if(n[p]!==x){f=Math.max(1,p-a[x]);break}}if(f===0)return h}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=K(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=G(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=G(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=G(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=K(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=G(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=G(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=G(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=G(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=G(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(!We(this.bufs[r],e.bufs[r]))return!1;return!0}static fromUint8Arrays(e,r){let n=new t;return n.bufs=e,r==null&&(r=e.reduce((o,s)=>o+s.byteLength,0)),n.length=r,n}};var kn={};X(kn,{base10:()=>Nc});var qh=new Uint8Array(0);function Bs(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 re(t){if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return qe(t);if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return qe(new Uint8Array(t.buffer,t.byteOffset,t.byteLength));throw new Error("Unknown type, must be binary type")}function Ns(t){let e=new Uint8Array(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}var Ps=4096;function Fs(t){let e=t.length;if(e<=Ps)return String.fromCharCode.apply(String,t);let r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.subarray(n,n+=Ps));return r}function Lc(t){return t?.buffer instanceof ArrayBuffer}function qe(t){return Lc(t)?t:t.slice()}function Tc(t,e,r){if(t.length>=255)throw new TypeError("Alphabet too long");for(var n=new Uint8Array(256),o=0;o<n.length;o++)n[o]=255;for(var s=0;s<t.length;s++){var i=t.charAt(s),a=i.charCodeAt(0);if(n[a]!==255)throw new TypeError(i+" is ambiguous");if(n[a]=s,r){var u=i.toLowerCase().charCodeAt(0),l=i.toUpperCase().charCodeAt(0);u!==a&&(n[u]=s),l!==a&&(n[l]=s)}}var f=t.length,h=t.charAt(0),p=Math.log(f)/Math.log(256),x=Math.log(256)/Math.log(f);function ae(y){if(y instanceof Uint8Array||(ArrayBuffer.isView(y)?y=new Uint8Array(y.buffer,y.byteOffset,y.byteLength):Array.isArray(y)&&(y=Uint8Array.from(y))),!(y instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(y.length===0)return"";for(var I=0,P=0,q=0,O=y.length;q!==O&&y[q]===0;)q++,I++;for(var ce=(O-q)*x+1>>>0,$=new Uint8Array(ce);q!==O;){for(var te=y[q],ue=0,Q=ce-1;(te!==0||ue<P)&&Q!==-1;Q--,ue++)te+=256*$[Q]>>>0,$[Q]=te%f>>>0,te=te/f>>>0;if(te!==0)throw new Error("Non-zero carry");P=ue,q++}for(var ve=ce-P;ve!==ce&&$[ve]===0;)ve++;for(var dr=h.repeat(I);ve<ce;++ve)dr+=t.charAt($[ve]);return dr}function W(y){if(typeof y!="string")throw new TypeError("Expected String");if(y.length===0)return new Uint8Array;var I=0;if(y[I]!==" "){for(var P=0,q=0;y[I]===h;)P++,I++;for(var O=(y.length-I)*p+1>>>0,ce=new Uint8Array(O);y[I];){var $=n[y.charCodeAt(I)];if($===255)return;for(var te=0,ue=O-1;($!==0||te<q)&&ue!==-1;ue--,te++)$+=f*ce[ue]>>>0,ce[ue]=$%256>>>0,$=$/256>>>0;if($!==0)throw new Error("Non-zero carry");q=te,I++}if(y[I]!==" "){for(var Q=O-q;Q!==O&&ce[Q]===0;)Q++;for(var ve=new Uint8Array(P+(O-Q)),dr=P;Q!==O;)ve[dr++]=ce[Q++];return ve}}}function w(y){var I=W(y);if(I)return I;throw new Error(`Non-${e} character`)}return{encode:ae,decodeUnsafe:W,decode:w}}var Ac=Tc,Dc=Ac,Us=Dc;var Ln=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")}},Tn=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 Os(this,e)}},An=class{decoders;constructor(e){this.decoders=e}or(e){return Os(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 Os(t,e){return new An({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var Dn=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 Ln(e,r,n),this.decoder=new Tn(e,r,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function it({name:t,prefix:e,encode:r,decode:n}){return new Dn(t,e,r,n)}function ke({name:t,prefix:e,alphabet:r,caseInsensitive:n=!1}){let{encode:o,decode:s}=Us(r,t,n);return it({prefix:e,name:t,encode:o,decode:i=>re(s(i))})}function kc(t,e,r,n){let o=t.length;for(;t[o-1]==="=";)--o;let s=new Uint8Array(o*r/8|0),i=0,a=0,u=0;for(let l=0;l<o;++l){let f=e[t[l]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|f,i+=r,i>=8&&(i-=8,s[u++]=255&a>>i)}if(i>=r||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function Pc(t,e,r){let n=e[e.length-1]==="=",o=(1<<r)-1,s="",i=0,a=0;for(let u=0;u<t.length;++u)for(a=a<<8|t[u],i+=8;i>r;)i-=r,s+=e[o&a>>i];if(i!==0&&(s+=e[o&a<<r-i]),n)for(;(s.length*r&7)!==0;)s+="=";return s}function Bc(t,e){let r={};for(let n=0;n<t.length;++n)if(r[t[n]]=n,e){let o=t[n].toLowerCase(),s=t[n].toUpperCase();o!==t[n]&&(r[o]=n),s!==t[n]&&(r[s]=n)}return r}function D({name:t,prefix:e,bitsPerChar:r,alphabet:n,caseInsensitive:o=!1}){let s=Bc(n,o);return it({prefix:e,name:t,encode(i){return Pc(i,n,r)},decode(i){return kc(i,s,r,t)}})}var Nc=ke({prefix:"9",name:"base10",alphabet:"0123456789"});var Pn={};X(Pn,{base16:()=>Fc,base16upper:()=>Mc});var Fc=D({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4,caseInsensitive:!0}),Mc=D({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4,caseInsensitive:!0});var Bn={};X(Bn,{base2:()=>Uc});var Uc=D({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Nn={};X(Nn,{base256emoji:()=>Vc});var Rs=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}"),Oc=Rs.reduce((t,e,r)=>(t[r]=e,t),[]),Rc=Rs.reduce((t,e,r)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return t[n]=r,t},[]);function $c(t){return t.reduce((e,r)=>(e+=Oc[r],e),"")}function zc(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=Rc[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(o)}return new Uint8Array(e)}var Vc=it({prefix:"\u{1F680}",name:"base256emoji",encode:$c,decode:zc});var Fn={};X(Fn,{base32:()=>ge,base32hex:()=>Gc,base32hexpad:()=>Qc,base32hexpadupper:()=>Xc,base32hexupper:()=>Hc,base32pad:()=>Wc,base32padupper:()=>qc,base32upper:()=>jc,base32z:()=>Kc});var ge=D({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5,caseInsensitive:!0}),jc=D({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5,caseInsensitive:!0}),Wc=D({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5,caseInsensitive:!0}),qc=D({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5,caseInsensitive:!0}),Gc=D({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5,caseInsensitive:!0}),Hc=D({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5,caseInsensitive:!0}),Qc=D({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5,caseInsensitive:!0}),Xc=D({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5,caseInsensitive:!0}),Kc=D({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Mn={};X(Mn,{base36:()=>Bt,base36upper:()=>Jc});var Bt=ke({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz",caseInsensitive:!0}),Jc=ke({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",caseInsensitive:!0});var Un={};X(Un,{base58btc:()=>ne,base58flickr:()=>Yc});var ne=ke({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Yc=ke({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var $n={};X($n,{base64:()=>On,base64pad:()=>Zc,base64url:()=>Rn,base64urlpad:()=>eu});var On=D({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Zc=D({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Rn=D({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),eu=D({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var zn={};X(zn,{base8:()=>tu});var tu=D({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Vn={};X(Vn,{identity:()=>ru});var ru=it({prefix:"\0",name:"identity",encode:t=>Fs(re(t)),decode:t=>re(Ns(t))});var ad=new TextEncoder,cd=new TextDecoder;var Wn={};X(Wn,{identity:()=>Cu});var su=Vs,$s=128,iu=127,au=~iu,cu=Math.pow(2,31);function Vs(t,e,r){e=e||[],r=r||0;for(var n=r;t>=cu;)e[r++]=t&255|$s,t/=128;for(;t&au;)e[r++]=t&255|$s,t>>>=7;return e[r]=t|0,Vs.bytes=r-n+1,e}var uu=jn,fu=128,zs=127;function jn(t,n){var r=0,n=n||0,o=0,s=n,i,a=t.length;do{if(s>=a)throw jn.bytes=0,new RangeError("Could not decode varint");i=t[s++],r+=o<28?(i&zs)<<o:(i&zs)*Math.pow(2,o),o+=7}while(i>=fu);return jn.bytes=s-n,r}var lu=Math.pow(2,7),hu=Math.pow(2,14),du=Math.pow(2,21),mu=Math.pow(2,28),pu=Math.pow(2,35),gu=Math.pow(2,42),bu=Math.pow(2,49),yu=Math.pow(2,56),xu=Math.pow(2,63),wu=function(t){return t<lu?1:t<hu?2:t<du?3:t<mu?4:t<pu?5:t<gu?6:t<bu?7:t<yu?8:t<xu?9:10},Eu={encode:su,decode:uu,encodingLength:wu},_u=Eu,Nt=_u;function Ft(t,e=0){return[Nt.decode(t,e),Nt.decode.bytes]}function at(t,e,r=0){return Nt.encode(t,e,r),e}function ct(t){return Nt.encodingLength(t)}function ft(t,e){let r=e.byteLength,n=ct(t),o=n+ct(r),s=new Uint8Array(o+r);return at(t,s,0),at(r,s,n),s.set(e,o),new ut(t,r,e,s)}function js(t){let e=re(t),[r,n]=Ft(e),[o,s]=Ft(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new ut(r,o,i,e)}function Ws(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&Bs(t.bytes,r.bytes)}}var ut=class{code;size;digest;bytes;constructor(e,r,n,o){this.code=e,this.size=r,this.digest=qe(n),this.bytes=qe(o)}};var qs=0,vu="identity",Gs=re;function Su(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 ft(qs,Gs(t))}var Cu={code:qs,name:vu,encode:Gs,digest:Su};var Hn={};X(Hn,{sha256:()=>Lu,sha512:()=>Tu});var Iu=20;function Gn({name:t,code:e,encode:r,minDigestLength:n,maxDigestLength:o}){return new qn(t,e,r,n,o)}var qn=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,r,n,o,s){this.name=e,this.code=r,this.encode=n,this.minDigestLength=o??Iu,this.maxDigestLength=s}digest(e,r){if(r?.truncate!=null){if(r.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&r.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(e instanceof Uint8Array){let n=this.encode(e);return n instanceof Uint8Array?Hs(n,this.code,r?.truncate):n.then(o=>Hs(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function Hs(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 ft(e,t)}function Xs(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}var Lu=Gn({name:"sha2-256",code:18,encode:Xs("SHA-256")}),Tu=Gn({name:"sha2-512",code:19,encode:Xs("SHA-512")});function Ks(t,e){let{bytes:r,version:n}=t;return n===0?Du(r,Qn(t),e??ne.encoder):ku(r,Qn(t),e??ge.encoder)}var Js=new WeakMap;function Qn(t){let e=Js.get(t);if(e==null){let r=new Map;return Js.set(t,r),r}return e}var lt=class t{code;version;multihash;bytes;"/";constructor(e,r,n,o){this.code=r,this.version=e,this.multihash=n,this.bytes=qe(o),this["/"]=this.bytes}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:r}=this;if(e!==Ut)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Pu)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=ft(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&&Ws(e.multihash,n.multihash)}toString(e){return Ks(this,e)}toJSON(){return{"/":Ks(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let r=e;if(r instanceof t)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:s,bytes:i}=r;return new t(n,o,s,i??Ys(n,o,s.bytes))}else if(r[Bu]===!0){let{version:n,multihash:o,code:s}=r,i=js(o);return t.create(n,s,i)}else return null}static create(e,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(r!==Ut)throw new Error(`Version 0 CID must use dag-pb (code: ${Ut}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let o=Ys(e,r,n.bytes);return new t(e,r,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,Ut,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=re(e.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let s=o.subarray(r.multihashSize-r.digestSize),i=new ut(r.multihashCode,r.digestSize,s,o);return[r.version===0?t.createV0(i):t.createV1(r.codec,i),e.subarray(r.size)]}static inspectBytes(e){let r=0,n=()=>{let[h,p]=Ft(e.subarray(r));return r+=p,h},o=n(),s=Ut;if(o===18?(o=0,r=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=r,a=n(),u=n(),l=r+u,f=l-i;return{version:o,codec:s,multihashCode:a,digestSize:u,multihashSize:f,size:l}}static parse(e,r){let[n,o]=Au(e,r),s=t.decode(o);if(s.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Qn(s).set(n,e),s}};function Au(t,e){switch(t[0]){case"Q":{let r=e??ne;return[ne.prefix,r.decode(`${ne.prefix}${t}`)]}case ne.prefix:{let r=e??ne;return[ne.prefix,r.decode(t)]}case ge.prefix:{let r=e??ge;return[ge.prefix,r.decode(t)]}case Bt.prefix:{let r=e??Bt;return[Bt.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 Du(t,e,r){let{prefix:n}=r;if(n!==ne.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=e.get(n);if(o==null){let s=r.encode(t).slice(1);return e.set(n,s),s}else return o}function ku(t,e,r){let{prefix:n}=r,o=e.get(n);if(o==null){let s=r.encode(t);return e.set(n,s),s}else return o}var Ut=112,Pu=18;function Ys(t,e,r){let n=ct(t),o=n+ct(e),s=new Uint8Array(o+r.byteLength);return at(t,s,0),at(e,s,n),s.set(r,o),s}var Bu=Symbol.for("@ipld/js-cid/CID");var Ot={...Vn,...Bn,...zn,...kn,...Pn,...Fn,...Mn,...Un,...$n,...Nn},Dd={...Hn,...Wn};function ei(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var Zs=ei("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),Xn=ei("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=K(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),Nu={utf8:Zs,"utf-8":Zs,hex:Ot.base16,latin1:Xn,ascii:Xn,binary:Xn,...Ot},gr=Nu;function B(t,e="utf8"){let r=gr[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}var Kn={32:16777619n,64:1099511628211n,128:309485009821345068724781371n,256:374144419156711147060143317175368453031918731002211n,512:35835915874844867368919076489095108449946327955754392558399825615420669938882575126094039892345713852759n,1024:5016456510113118655434598811035278955030765345404790744303017523831112055108147451509157692220295382716162651878526895249385292291816524375083746691371804094271873160484737966720260389217684476157468082573n},ti={32:2166136261n,64:14695981039346656037n,128:144066263297769815596495629667062367629n,256:100029257958052580907070968620625704837092796014241193945225284501741471925557n,512:9659303129496669498009435400716310466090418745672637896108374329434462657994582932197716438449813051892206539805784495328239340083876191928701583869517785n,1024:14197795064947621068722070641403218320880622795441933960878474914617582723252296732303717722150864096521202355549365628174669108571814760471015076148029755969804077320157692458563003215304957150157403644460363550505412711285966361610267868082893823963790439336411086884584107735010676915n},ri=new globalThis.TextEncoder;function Fu(t,e){let r=Kn[e],n=ti[e];for(let o=0;o<t.length;o++)n^=BigInt(t[o]),n=BigInt.asUintN(e,n*r);return n}function Mu(t,e,r){if(r.length===0)throw new Error("The `utf8Buffer` option must have a length greater than zero");let n=Kn[e],o=ti[e],s=t;for(;s.length>0;){let i=ri.encodeInto(s,r);s=s.slice(i.read);for(let a=0;a<i.written;a++)o^=BigInt(r[a]),o=BigInt.asUintN(e,o*n)}return o}function Jn(t,{size:e=32,utf8Buffer:r}={}){if(!Kn[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 Mu(t,e,r);t=ri.encode(t)}return Fu(t,e)}var Pe={hash:t=>Number(Jn(t,{size:32})),hashV:(t,e)=>Uu(Pe.hash(t,e))};function Uu(t){let e=t.toString(16);return e.length%2===1&&(e=`0${e}`),B(e,"base16")}var Ou=Math.LN2*Math.LN2,Rt=class{seeds;bits;buffer;constructor(e={}){e.seeds!=null?this.seeds=e.seeds:this.seeds=$u(e.hashes??8),this.bits=e.bits??1024,this.buffer=G(Math.ceil(this.bits/8))}add(e){typeof e=="string"&&(e=B(e));for(let r=0;r<this.seeds.length;r++){let o=Pe.hash(e,this.seeds[r])%this.bits;this.setbit(o)}}has(e){typeof e=="string"&&(e=B(e));for(let r=0;r<this.seeds.length;r++){let o=Pe.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 ni(t,e=.005){let r=Ru(t,e);return new Rt(r)}function Ru(t,e=.005){let r=Math.round(-1*t*Math.log(e)/Ou),n=Math.round(r/t*Math.LN2);return{bits:r,hashes:n}}function $u(t){let e,r,n=[];for(let o=0;o<t;o++)for(e=new k(crypto.getRandomValues(new Uint8Array(4))),n[o]=e.getUint32(0,!0),r=0;r<o;r++)if(n[o]===n[r]){o--;break}return n}var Yn=64,fe=class{fp;h;seed;constructor(e,r,n,o=2){if(o>Yn)throw new TypeError("Invalid Fingerprint Size");let s=r.hashV(e,n),i=G(o);for(let a=0;a<i.length;a++)i[a]=s[a];i.length===0&&(i[0]=7),this.fp=i,this.h=r,this.seed=n}hash(){return this.h.hash(this.fp,this.seed)}equals(e){return e?.fp instanceof Uint8Array?We(this.fp,e.fp):!1}};function Ge(t,e){return Math.floor(Math.random()*(e-t))+t}var He=class{contents;constructor(e){this.contents=new Array(e).fill(null)}has(e){if(!(e instanceof fe))throw new TypeError("Invalid Fingerprint");return this.contents.some(r=>e.equals(r))}add(e){if(!(e instanceof fe))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 fe))throw new TypeError("Invalid Fingerprint");let r=Ge(0,this.contents.length-1),n=this.contents[r];return this.contents[r]=e,n}remove(e){if(!(e instanceof fe))throw new TypeError("Invalid Fingerprint");let r=this.contents.findIndex(n=>e.equals(n));return r>-1?(this.contents[r]=null,!0):!1}};var zu=500,Be=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??Pe,this.seed=e.seed??Ge(0,Math.pow(2,10))}add(e){typeof e=="string"&&(e=B(e));let r=new fe(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 He(this.bucketSize)),this.buckets[o]==null&&(this.buckets[o]=new He(this.bucketSize)),this.buckets[n].add(r)||this.buckets[o].add(r))return this.count++,!0;let s=[n,o],i=s[Ge(0,s.length-1)];this.buckets[i]==null&&(this.buckets[i]=new He(this.bucketSize));for(let a=0;a<zu;a++){let u=this.buckets[i].swap(r);if(u!=null&&(i=(i^u.hash())%this.filterSize,this.buckets[i]==null&&(this.buckets[i]=new He(this.bucketSize)),this.buckets[i].add(u)))return this.count++,!0}return!1}has(e){typeof e=="string"&&(e=B(e));let r=new fe(e,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(e,this.seed)%this.filterSize,o=this.buckets[n]?.has(r)??!1;if(o)return o;let s=(n^r.hash())%this.filterSize;return this.buckets[s]?.has(r)??!1}remove(e){typeof e=="string"&&(e=B(e));let r=new fe(e,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(e,this.seed)%this.filterSize,o=this.buckets[n]?.remove(r)??!1;if(o)return this.count--,o;let s=(n^r.hash())%this.filterSize,i=this.buckets[s]?.remove(r)??!1;return i&&this.count--,i}get reliable(){return Math.floor(100*(this.count/this.filterSize))<=90}},Vu={1:.5,2:.84,4:.95,8:.98};function ju(t=.001){return t>.002?2:t>1e-5?4:8}function Zn(t,e=.001){let r=ju(e),n=Vu[r],o=Math.round(t/n),s=Math.min(Math.ceil(Math.log2(1/e)+Math.log2(2*r)),Yn);return{filterSize:o,bucketSize:r,fingerprintSize:s}}function oi(t,e=.005){let r=Zn(t,e);return new Be(r)}var $t=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??Pe,this.seed=e.seed??Ge(0,Math.pow(2,10)),this.filterSeries=[new Be({filterSize:this.filterSize,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed})]}add(e){if(typeof e=="string"&&(e=B(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 Be({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=B(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=B(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 si(t,e=.001,r){return new $t({...Zn(t,e),...r??{}})}var Ce=class extends Error{static name="AbortError";constructor(e="The operation was aborted"){super(e),this.name="AbortError"}};var oe=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}};var br=class extends Error{static name="MuxerClosedError";constructor(e="The muxer is closed"){super(e),this.name="MuxerClosedError"}},yr=class extends Error{static name="StreamResetError";constructor(e="The stream has been reset"){super(e),this.name="StreamResetError"}};var Ne=class extends Error{static name="StreamStateError";constructor(e="The stream is in an invalid state"){super(e),this.name="StreamStateError"}},zt=class extends Error{static name="StreamBufferError";constructor(e="The stream buffer was full"){super(e),this.name="StreamBufferError"}};var be=class extends Event{data;constructor(e,r){super("message",r),this.data=e}},ht=class extends Event{error;local;constructor(e,r,n){super("close",n),this.error=r,this.local=e}},xr=class extends ht{constructor(e,r){super(!0,e,r)}},wr=class extends ht{constructor(e,r){super(!1,e,r)}};function Wu(t){return typeof t?.handleEvent=="function"}function qu(t){return(t!==!0&&t!==!1&&t?.once)??!1}var ye=class extends EventTarget{#e=new Map;constructor(){super()}listenerCount(e){let r=this.#e.get(e);return r==null?0:r.length}addEventListener(e,r,n){let o=qu(n);super.addEventListener(e,i=>{if(o){let a=this.#e.get(i.type);a!=null&&(a=a.filter(({callback:u})=>u!==r),this.#e.set(i.type,a))}Wu(r)?r.handleEvent(i):r(i)},n);let s=this.#e.get(e);s==null&&(s=[],this.#e.set(e,s)),s.push({callback:r,once:o})}removeEventListener(e,r,n){super.removeEventListener(e.toString(),r??null,n);let o=this.#e.get(e);o!=null&&(o=o.filter(({callback:s})=>s!==r),this.#e.set(e,o))}safeDispatchEvent(e,r={}){return this.dispatchEvent(new CustomEvent(e,r))}};function Er(t){let e=t.getComponents(),r={},n=0;return 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?null:(e[n]?.name==="tls"&&e[n+1]?.name==="sni"&&(r.sni=e[n+1].value,n+=2),r)}function le(t){let e=Er(t);if(e==null)throw new oe(`Multiaddr ${t} was not an IPv4, IPv6, DNS, DNS4, DNS6 or DNSADDR address`);return e}var _r=class{index=0;input="";new(e){return this.index=0,this.input=e,this}readAtomically(e){let r=this.index,n=e();return n===void 0&&(this.index=r),n}parseWith(e){let r=e();if(this.index===this.input.length)return r}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(e){return this.readAtomically(()=>{let r=this.readChar();if(r===e)return r})}readSeparator(e,r,n){return this.readAtomically(()=>{if(!(r>0&&this.readGivenChar(e)===void 0))return n()})}readNumber(e,r,n,o){return this.readAtomically(()=>{let s=0,i=0,a=this.peekChar();if(a===void 0)return;let u=a==="0",l=2**(8*o)-1;for(;;){let f=this.readAtomically(()=>{let h=this.readChar();if(h===void 0)return;let p=Number.parseInt(h,e);if(!Number.isNaN(p))return p});if(f===void 0)break;if(s*=e,s+=f,s>l||(i+=1,r!==void 0&&i>r))return}if(i!==0)return!n&&u&&i>1?void 0:s})}readIPv4Addr(){return this.readAtomically(()=>{let e=new Uint8Array(4);for(let r=0;r<e.length;r++){let n=this.readSeparator(".",r,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;e[r]=n}return e})}readIPv6Addr(){let e=r=>{for(let n=0;n<r.length/2;n++){let o=n*2;if(n<r.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return r[o]=i[0],r[o+1]=i[1],r[o+2]=i[2],r[o+3]=i[3],[o+4,!0]}let s=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(s===void 0)return[o,!1];r[o]=s>>8,r[o+1]=s&255}return[r.length,!1]};return this.readAtomically(()=>{let r=new Uint8Array(16),[n,o]=e(r);if(n===16)return r;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let s=new Uint8Array(14),i=16-(n+2),[a]=e(s.subarray(0,i));return r.set(s.subarray(0,a),16-a),r})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var ii=45,Gu=15,dt=new _r;function vr(t){if(!(t.length>Gu))return dt.new(t).parseWith(()=>dt.readIPv4Addr())}function Sr(t){if(t.includes("%")&&(t=t.split("%")[0]),!(t.length>ii))return dt.new(t).parseWith(()=>dt.readIPv6Addr())}function mt(t,e=!1){if(t.includes("%")&&(t=t.split("%")[0]),t.length>ii)return;let r=dt.new(t).parseWith(()=>dt.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 ai(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 ci(t,e,r,n){let o=0;for(let s of t)if(!(o<r)){if(o>n)break;if(s!==e[o])return!1;o++}return!0}function eo(t){switch(t.length){case Qe:return t.join(".");case Xe:{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 ui(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 fi(t){let e="0x";for(let r of t)e+=(r>>4).toString(16)+(r&15).toString(16);return e}var Qe=4,Xe=16,Im=parseInt("0xFFFF",16),Hu=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function Vt(t,e){e.length===Xe&&t.length===Qe&&ai(e,0,11)&&(e=e.slice(12)),e.length===Qe&&t.length===Xe&&ci(t,Hu,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 li(t,e){if(typeof e=="string"&&(e=mt(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 to(t){let[e,r]=t.split("/");if(!e||!r)throw new Error("Failed to parse given CIDR: "+t);let n=Qe,o=vr(e);if(o==null&&(n=Xe,o=Sr(e),o==null))throw new Error("Failed to parse given CIDR: "+t);let s=parseInt(r,10);if(Number.isNaN(s)||String(s).length!==r.length||s<0||s>n*8)throw new Error("Failed to parse given CIDR: "+t);let i=ro(s,8*n);return{network:Vt(o,i),mask:i}}function ro(t,e){if(e!==8*Qe&&e!==8*Xe)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 jt=class{constructor(e,r){if(r==null)({network:this.network,mask:this.mask}=to(e));else{let n=mt(e);if(n==null)throw new Error("Failed to parse network");r=String(r);let o=parseInt(r,10);if(Number.isNaN(o)||String(o).length!==r.length||o<0||o>n.length*8){let s=mt(r);if(s==null)throw new Error("Failed to parse mask");this.mask=s}else this.mask=ro(o,8*n.length);this.network=Vt(n,this.mask)}}contains(e){return li({network:this.network,mask:this.mask},e)}toString(){let e=ui(this.mask),r=e!==-1?String(e):fi(this.mask);return eo(this.network)+"/"+r}};function Cr(t,e){return new jt(t).contains(e)}function Qu(t){try{let e=le(t);return e.type==="ip6"?Cr("2000::/3",e.host):!1}catch{return!1}}function Xu(t){try{let e=le(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 hi(t){return/^127\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/i.test(t)||/^::1$/.test(t)}function Ir(t){try{let e=le(t);switch(e.type){case"ip4":case"ip6":return hi(e.host);default:return!1}}catch{return!1}}function Ku(t){return Er(t)!==null}function Fe(t){return!!vr(t)}function Me(t){return!!Sr(t)}var gi=Sc(pi(),1),nf=["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"],of=nf.map(t=>new gi.Netmask(t));function uo(t){for(let e of of)if(e.contains(t))return!0;return!1}function sf(t){return/^::ffff:([0-9a-fA-F]{1,4}):([0-9a-fA-F]{1,4})$/.test(t)}function af(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 uo(o)}function cf(t){return/^::ffff:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(t)}function uf(t){let e=t.split(":"),r=e[e.length-1];return uo(r)}function ff(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 fo(t){if(Fe(t))return uo(t);if(sf(t))return af(t);if(cf(t))return uf(t);if(Me(t))return ff(t)}function Tr(t){try{let e=le(t);switch(e.type){case"ip4":case"ip6":return fo(e.host)??!1;default:return e.host==="localhost"}}catch{return!1}}var lf=Math.pow(2,7),hf=Math.pow(2,14),df=Math.pow(2,21),lo=Math.pow(2,28),ho=Math.pow(2,35),mo=Math.pow(2,42),po=Math.pow(2,49),S=128,z=127;function V(t){if(t<lf)return 1;if(t<hf)return 2;if(t<df)return 3;if(t<lo)return 4;if(t<ho)return 5;if(t<mo)return 6;if(t<po)return 7;if(Number.MAX_SAFE_INTEGER!=null&&t>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Ar(t,e,r=0){switch(V(t)){case 8:e[r++]=t&255|S,t/=128;case 7:e[r++]=t&255|S,t/=128;case 6:e[r++]=t&255|S,t/=128;case 5:e[r++]=t&255|S,t/=128;case 4:e[r++]=t&255|S,t>>>=7;case 3:e[r++]=t&255|S,t>>>=7;case 2:e[r++]=t&255|S,t>>>=7;case 1:{e[r++]=t&255,t>>>=7;break}default:throw new Error("unreachable")}return e}function mf(t,e,r=0){switch(V(t)){case 8:e.set(r++,t&255|S),t/=128;case 7:e.set(r++,t&255|S),t/=128;case 6:e.set(r++,t&255|S),t/=128;case 5:e.set(r++,t&255|S),t/=128;case 4:e.set(r++,t&255|S),t>>>=7;case 3:e.set(r++,t&255|S),t>>>=7;case 2:e.set(r++,t&255|S),t>>>=7;case 1:{e.set(r++,t&255),t>>>=7;break}default:throw new Error("unreachable")}return e}function pf(t,e){let r=t[e],n=0;if(n+=r&z,r<S||(r=t[e+1],n+=(r&z)<<7,r<S)||(r=t[e+2],n+=(r&z)<<14,r<S)||(r=t[e+3],n+=(r&z)<<21,r<S)||(r=t[e+4],n+=(r&z)*lo,r<S)||(r=t[e+5],n+=(r&z)*ho,r<S)||(r=t[e+6],n+=(r&z)*mo,r<S)||(r=t[e+7],n+=(r&z)*po,r<S))return n;throw new RangeError("Could not decode varint")}function gf(t,e){let r=t.get(e),n=0;if(n+=r&z,r<S||(r=t.get(e+1),n+=(r&z)<<7,r<S)||(r=t.get(e+2),n+=(r&z)<<14,r<S)||(r=t.get(e+3),n+=(r&z)<<21,r<S)||(r=t.get(e+4),n+=(r&z)*lo,r<S)||(r=t.get(e+5),n+=(r&z)*ho,r<S)||(r=t.get(e+6),n+=(r&z)*mo,r<S)||(r=t.get(e+7),n+=(r&z)*po,r<S))return n;throw new RangeError("Could not decode varint")}function Dr(t,e,r=0){return e==null&&(e=K(V(t))),e instanceof Uint8Array?Ar(t,e,r):mf(t,e,r)}function Ie(t,e=0){return t instanceof Uint8Array?pf(t,e):gf(t,e)}function bf(t){return t.buffer instanceof ArrayBuffer}function go(t){return bf(t)?t:t.slice()}function Oe(t,e="utf8"){let r=gr[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.encoder.encode(t).substring(1)}var R=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},Le=class extends Error{static name="ValidationError";name="ValidationError"},kr=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},Pr=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};function yo(t){return e=>Oe(e,t)}function xo(t){return e=>B(e,t)}function yt(t){return new DataView(t.buffer).getUint16(t.byteOffset).toString()}function Je(t){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,typeof t=="string"?parseInt(t):t),new Uint8Array(e)}function bi(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=B(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=Je(n);return Se([r,o],r.length+o.length)}function yi(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=ge.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=Je(n);return Se([r,o],r.length+o.length)}function wo(t){let e=t.subarray(0,t.length-2),r=t.subarray(t.length-2),n=Oe(e,"base32"),o=yt(r);return`${n}:${o}`}var Eo=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 R("Invalid byte value in IP address");e[n]=o}),e},xi=function(t){let e=0;t=t.toString().trim();let r=t.split(":",8),n;for(n=0;n<r.length;n++){let s=Fe(r[n]),i;s&&(i=Eo(r[n]),r[n]=Oe(i.subarray(0,2),"base16")),i!=null&&++n<8&&r.splice(n,0,Oe(i.subarray(2,4),"base16"))}if(r[0]==="")for(;r.length<8;)r.unshift("0");else if(r[r.length-1]==="")for(;r.length<8;)r.push("0");else if(r.length<8){for(n=0;n<r.length&&r[n]!=="";n++);let s=[n,1];for(n=9-r.length;n>0;n--)s.push("0");r.splice.apply(r,s)}let o=new Uint8Array(e+16);for(n=0;n<r.length;n++){r[n]===""&&(r[n]="0");let s=parseInt(r[n],16);if(isNaN(s)||s<0||s>65535)throw new R("Invalid byte value in IP address");o[e++]=s>>8&255,o[e++]=s&255}return o},wi=function(t){if(t.byteLength!==4)throw new R("IPv4 address was incorrect length");let e=[];for(let r=0;r<t.byteLength;r++)e.push(t[r]);return e.join(".")},Ei=function(t){if(t.byteLength!==16)throw new R("IPv6 address was incorrect length");let e=[];for(let n=0;n<t.byteLength;n+=2){let o=t[n],s=t[n+1],i=`${o.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}`;e.push(i)}let r=e.join(":");try{let n=new URL(`http://[${r}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new R(`Invalid IPv6 address "${r}"`)}};function _i(t){try{let e=new URL(`http://[${t}]`);return e.hostname.substring(1,e.hostname.length-1)}catch{throw new R(`Invalid IPv6 address "${t}"`)}}var bo=Object.values(Ot).map(t=>t.decoder),yf=(function(){let t=bo[0].or(bo[1]);return bo.slice(2).forEach(e=>t=t.or(e)),t})();function vi(t){return yf.decode(t)}function Si(t){return e=>t.encoder.encode(e)}function xf(t){if(parseInt(t).toString()!==t)throw new Le("Value must be an integer")}function wf(t){if(t<0)throw new Le("Value must be a positive integer, or zero")}function Ef(t){return e=>{if(e>t)throw new Le(`Value must be smaller than or equal to ${t}`)}}function _f(...t){return e=>{for(let r of t)r(e)}}var qt=_f(xf,wf,Ef(65535));var N=-1,_o=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 Pr(`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)}))}},Ae=new _o,Mf=[{code:4,name:"ip4",size:32,valueToBytes:Eo,bytesToValue:wi,validate:t=>{if(!Fe(t))throw new Le(`Invalid IPv4 address "${t}"`)}},{code:6,name:"tcp",size:16,valueToBytes:Je,bytesToValue:yt,validate:qt},{code:273,name:"udp",size:16,valueToBytes:Je,bytesToValue:yt,validate:qt},{code:33,name:"dccp",size:16,valueToBytes:Je,bytesToValue:yt,validate:qt},{code:41,name:"ip6",size:128,valueToBytes:xi,bytesToValue:Ei,stringToValue:_i,validate:t=>{if(!Me(t))throw new Le(`Invalid IPv6 address "${t}"`)}},{code:42,name:"ip6zone",size:N},{code:43,name:"ipcidr",size:8,bytesToValue:yo("base10"),valueToBytes:xo("base10")},{code:53,name:"dns",size:N},{code:54,name:"dns4",size:N},{code:55,name:"dns6",size:N},{code:56,name:"dnsaddr",size:N},{code:132,name:"sctp",size:16,valueToBytes:Je,bytesToValue:yt,validate:qt},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:N,stringToValue:t=>decodeURIComponent(t),valueToString:t=>encodeURIComponent(t)},{code:421,name:"p2p",aliases:["ipfs"],size:N,bytesToValue:yo("base58btc"),valueToBytes:t=>t.startsWith("Q")||t.startsWith("1")?xo("base58btc")(t):lt.parse(t).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:wo,valueToBytes:bi},{code:445,name:"onion3",size:296,bytesToValue:wo,valueToBytes:yi},{code:446,name:"garlic64",size:N},{code:447,name:"garlic32",size:N},{code:448,name:"tls"},{code:449,name:"sni",size:N},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:N,bytesToValue:Si(Rn),valueToBytes:vi},{code:480,name:"http"},{code:481,name:"http-path",size:N,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:N}];Mf.forEach(t=>{Ae.addProtocol(t)});function Ci(t){let e=[],r=0;for(;r<t.length;){let n=Ie(t,r),o=Ae.getProtocol(n),s=V(n),i=Uf(o,t,r+s),a=0;i>0&&o.size===N&&(a=V(i));let u=s+a+i,l={code:n,name:o.name,bytes:go(t.subarray(r,r+u))};if(i>0){let f=r+s+a,h=t.subarray(f,f+i);l.value=o.bytesToValue?.(h)??Oe(h)}e.push(l),r+=u}return e}function Ii(t){let e=0,r=[];for(let n of t){if(n.bytes==null){let o=Ae.getProtocol(n.code),s=V(n.code),i,a=0,u=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??B(n.value),a=i.byteLength,o.size===N&&(u=V(a)));let l=new Uint8Array(s+u+a),f=0;Ar(n.code,l,f),f+=s,i!=null&&(o.size===N&&(Ar(a,l,f),f+=u),l.set(i,f)),n.bytes=l}r.push(n.bytes),e+=n.bytes.byteLength}return Se(r,e)}function Li(t){if(t.charAt(0)!=="/")throw new R('String multiaddr must start with "/"');let e=[],r="protocol",n="",o="";for(let s=1;s<t.length;s++){let i=t.charAt(s);i!=="/"&&(r==="protocol"?o+=t.charAt(s):n+=t.charAt(s));let a=s===t.length-1;if(i==="/"||a){let u=Ae.getProtocol(o);if(r==="protocol"){if(u.size==null||u.size===0){e.push({code:u.code,name:u.name}),n="",o="",r="protocol";continue}else if(a)throw new R(`Component ${o} was missing value`);r="value"}else if(r==="value"){let l={code:u.code,name:u.name};if(u.size!=null&&u.size!==0){if(n==="")throw new R(`Component ${o} was missing value`);l.value=u.stringToValue?.(n)??n}e.push(l),n="",o="",r="protocol"}}}if(o!==""&&n!=="")throw new R("Incomplete multiaddr");return e}function Ti(t){return`/${t.flatMap(e=>{if(e.value==null)return e.name;let r=Ae.getProtocol(e.code);if(r==null)throw new R(`Unknown protocol code ${e.code}`);return[e.name,r.valueToString?.(e.value)??e.value]}).join("/")}`}function Uf(t,e,r){return t.size==null||t.size===0?0:t.size>0?t.size/8:Ie(e,r)}var Of=Symbol.for("nodejs.util.inspect.custom"),Mo=Symbol.for("@multiformats/multiaddr");function Rf(t){if(t==null&&(t="/"),Ai(t))return t.getComponents();if(t instanceof Uint8Array)return Ci(t);if(typeof t=="string")return t=t.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),t===""&&(t="/"),Li(t);if(Array.isArray(t))return t;throw new R("Must be a string, Uint8Array, Component[], or another Multiaddr")}var zr=class t{[Mo]=!0;#e;#t;#r;constructor(e="/",r={}){this.#e=Rf(e),r.validate!==!1&&$f(this)}get bytes(){return this.#r==null&&(this.#r=Ii(this.#e)),this.#r}toString(){return this.#t==null&&(this.#t=Ti(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 kr(`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 We(this.bytes,e.bytes)}[Of](){return`Multiaddr(${this.toString()})`}};function $f(t){t.getComponents().forEach(e=>{let r=Ae.getProtocol(e.code);e.value!=null&&r.validate?.(e.value)})}function Ai(t){return!!t?.[Mo]}function Re(t){return new zr(t)}var L=t=>({match:e=>{let r=e[0];return r==null||r.code!==t||r.value!=null?!1:e.slice(1)}}),b=(t,e)=>({match:r=>{let n=r[0];return n?.code!==t||n.value==null||e!=null&&n.value!==e?!1:r.slice(1)}}),Di=t=>({match:e=>t.match(e)===!1?e:!1}),E=t=>({match:e=>{let r=t.match(e);return r===!1?e:r}}),j=(...t)=>({match:e=>{let r;for(let n of t){let o=n.match(e);o!==!1&&(r==null||o.length<r.length)&&(r=o)}return r??!1}}),_=(...t)=>({match:e=>{for(let r of t){let n=r.match(e);if(n===!1)return!1;e=n}return e}});function T(...t){function e(o){if(o==null)return!1;let s=o.getComponents();for(let i of t){let a=i.match(s);if(a===!1)return!1;s=a}return s}function r(o){return e(o)!==!1}function n(o){let s=e(o);return s===!1?!1:s.length===0}return{matchers:t,matches:r,exactMatch:n}}var zf=b(421),xg=T(zf),jr=b(54),Wr=b(55),qr=b(56),Oo=b(53),wg=T(jr,E(b(421))),Eg=T(Wr,E(b(421))),_g=T(qr,E(b(421))),vg=T(j(Oo,qr,jr,Wr),E(b(421))),ki=_(b(4),E(b(43))),Pi=_(E(b(42)),b(41),E(b(43))),Ro=j(ki,Pi),_t=j(Ro,Oo,jr,Wr,qr),Sg=T(j(Ro,_(j(Oo,qr,jr,Wr),E(b(421))))),Cg=T(ki),Ig=T(Pi),Lg=T(Ro),$o=_(_t,b(6)),Gt=_(_t,b(273)),zo=T(_($o,E(b(421)))),Tg=T(Gt),Vo=_(Gt,L(460),E(b(421))),Gr=_(Gt,L(461),E(b(421))),Vf=j(Vo,Gr),Ag=T(Vo),Dg=T(Gr),Uo=j(_t,$o,Gt,Vo,Gr),Bi=j(_(Uo,L(477),E(b(421)))),jo=T(Bi),Ni=j(_(Uo,L(478),E(b(421))),_(Uo,L(448),E(b(449)),L(477),E(b(421)))),Wo=T(Ni),Fi=_(Gt,L(280),E(b(466)),E(b(466)),E(b(421))),qo=T(Fi),Mi=_(Gr,L(465),E(b(466)),E(b(466)),E(b(421))),Go=T(Mi),Vr=j(Bi,Ni,_($o,E(b(421))),_(Vf,E(b(421))),_(_t,E(b(421))),Fi,Mi,b(421)),kg=T(Vr),jf=_(E(Vr),L(290),Di(L(281)),E(b(421))),Ho=T(jf),Wf=j(_(Vr,L(290),L(281),E(b(421))),_(Vr,L(281),E(b(421))),_(L(281),E(b(421)))),Qo=T(Wf),qf=_(_t,j(_(b(6,"80")),_(b(6),L(480)),L(480)),E(b(481)),E(b(421))),Pg=T(qf),Gf=_(_t,j(_(b(6,"443")),_(b(6,"443"),L(480)),_(b(6),L(443)),_(b(6),L(448),L(480)),_(L(448),L(480)),L(448),L(443)),E(b(481)),E(b(421))),Bg=T(Gf),Hf=j(_(b(777),E(b(421)))),Ng=T(Hf),Qf=j(_(b(400),E(b(421)))),Fg=T(Qf);function Ui(t,e){let r=zo.exactMatch(t),n=zo.exactMatch(e);if(r&&!n)return-1;if(!r&&n)return 1;let o=Wo.exactMatch(t),s=Wo.exactMatch(e);if(o&&!s)return-1;if(!o&&s)return 1;let i=jo.exactMatch(t),a=jo.exactMatch(e);if(i&&!a)return-1;if(!i&&a)return 1;let u=Qo.exactMatch(t),l=Qo.exactMatch(e);if(u&&!l)return-1;if(!u&&l)return 1;let f=qo.exactMatch(t),h=qo.exactMatch(e);if(f&&!h)return-1;if(!f&&h)return 1;let p=Go.exactMatch(t),x=Go.exactMatch(e);return p&&!x?-1:!p&&x?1:0}function Oi(t,e){let r=Ir(t),n=Ir(e);return r&&!n?1:!r&&n?-1:0}function Ri(t,e){let r=Tr(t),n=Tr(e);return r&&!n?1:!r&&n?-1:0}function $i(t,e){let r=Ho.exactMatch(t),n=Ho.exactMatch(e);return r&&!n?1:!r&&n?-1:0}function Xf(t){return t.sort((e,r)=>Oi(e,r)||Ri(e,r)||$i(e,r)||Ui(e,r))}function he(){let t={};return t.promise=new Promise((e,r)=>{t.resolve=e,t.reject=r}),t}var Hr=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}},vt=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new Hr(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 Hr(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 Xo=class extends Error{type;code;constructor(e,r){super(e??"The operation was aborted"),this.type="aborted",this.code=r??"ABORT_ERR"}};function we(t={}){return Kf(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 Kf(t,e){e=e??{};let r=e.onEnd,n=new vt,o,s,i,a=he(),u=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((w,y)=>{s=I=>{s=null,n.push(I);try{w(t(n))}catch(P){y(P)}return o}}):t(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=he()})}},l=w=>s!=null?s(w):(n.push(w),o),f=w=>(n=new vt,s!=null?s({error:w}):(n.push({error:w}),o)),h=w=>{if(i)return o;if(e?.objectMode!==!0&&w?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return l({done:!1,value:w})},p=w=>i?o:(i=!0,w!=null?f(w):l({done:!0})),x=()=>(n=new vt,p(),{done:!0}),ae=w=>(p(w),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:u,return:x,throw:ae,push:h,end:p,get readableLength(){return n.size},onEmpty:async w=>{let y=w?.signal;if(y?.throwIfAborted(),n.isEmpty())return;let I,P;y!=null&&(I=new Promise((q,O)=>{P=()=>{O(new Xo)},y.addEventListener("abort",P)}));try{await Promise.race([a.promise,I])}finally{P!=null&&y!=null&&y?.removeEventListener("abort",P)}}},r==null)return o;let W=o;return o={[Symbol.asyncIterator](){return this},next(){return W.next()},throw(w){return W.throw(w),r!=null&&(r(w),r=void 0),{done:!0}},return(){return W.return(),r!=null&&(r(),r=void 0),{done:!0}},push:h,end(w){return W.end(w),r!=null&&(r(w),r=void 0),o},get readableLength(){return W.readableLength},onEmpty:w=>W.onEmpty(w)},o}var Ko=class t extends Error{name="TimeoutError";constructor(e,r){super(e,r),Error.captureStackTrace?.(this,t)}},zi=t=>t.reason??new DOMException("This operation was aborted.","AbortError");function Jo(t,e){let{milliseconds:r,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout},signal:i}=e,a,u,f=new Promise((h,p)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(i?.aborted){p(zi(i));return}if(i&&(u=()=>{p(zi(i))},i.addEventListener("abort",u,{once:!0})),t.then(h,p),r===Number.POSITIVE_INFINITY)return;let x=new Ko;a=s.setTimeout.call(void 0,()=>{if(n){try{h(n())}catch(ae){p(ae)}return}typeof t.cancel=="function"&&t.cancel(),o===!1?h():o instanceof Error?p(o):(x.message=o??`Promise timed out after ${r} milliseconds`,p(x))},r)}).finally(()=>{f.clear(),u&&i&&i.removeEventListener("abort",u)});return f.clear=()=>{s.clearTimeout.call(void 0,a),a=void 0},f}var Jf=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 Yf(t,e,r){let n,o=new Promise((s,i)=>{if(r={rejectionEvents:["error"],multiArgs:!1,rejectionMultiArgs:!1,resolveImmediately:!1,...r},!(r.count>=0&&(r.count===Number.POSITIVE_INFINITY||Number.isInteger(r.count))))throw new TypeError("The `count` option should be at least 0 or more");r.signal?.throwIfAborted();let a=[e].flat(),u=[],{addListener:l,removeListener:f}=Jf(t),h=async(...x)=>{let ae=r.multiArgs?x:x[0];if(r.filter)try{if(!await r.filter(ae))return}catch(W){n(),i(W);return}u.push(ae),r.count===u.length&&(n(),s(u))},p=(...x)=>{n(),i(r.rejectionMultiArgs?x:x[0])};n=()=>{for(let x of a)f(x,h);for(let x of r.rejectionEvents)a.includes(x)||f(x,p)};for(let x of a)l(x,h);for(let x of r.rejectionEvents)a.includes(x)||l(x,p);r.signal&&r.signal.addEventListener("abort",()=>{p(r.signal.reason)},{once:!0}),r.resolveImmediately&&s(u)});if(o.cancel=n,typeof r.timeout=="number"){let s=Jo(o,{milliseconds:r.timeout});return s.cancel=()=>{n(),s.clear()},s}return o}function F(t,e,r){typeof r=="function"&&(r={filter:r}),r={...r,count:1,resolveImmediately:!1};let n=Yf(t,e,r),o=n.then(s=>s[0]);return o.cancel=n.cancel,o}function St(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 Ht=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}},Qt=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"},Xt=class extends Error{static name="MaxEarlyStreamsError";name="MaxEarlyStreamsError"},Kt=class extends Error{static name="StreamClosedError";name="StreamClosedError"};function Zf(t){return t.reason}async function M(t,e,r){if(e==null)return t;let n=r?.translateError??Zf;if(e.aborted)return t.catch(()=>{}),Promise.reject(n(e));let o;try{return await Promise.race([t,new Promise((s,i)=>{o=()=>{i(n(e))},e.addEventListener("abort",o)})])}finally{o!=null&&e.removeEventListener("abort",o)}}var Qr=class{deferred;signal;onProgress;constructor(e){this.signal=e?.signal,this.onProgress=e?.onProgress,this.deferred=he(),this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(this.signal?.reason??new Ce)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function el(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var Xr=class{id;fn;options;recipients;status;timeline;controller;dispatchingProgress;constructor(e,r){this.id=el(),this.status="queued",this.fn=e,this.options=r,this.recipients=[],this.timeline={created:Date.now()},this.controller=new AbortController,this.controller.signal,this.dispatchingProgress=!1,this.onAbort=this.onAbort.bind(this)}abort(e){this.controller.abort(e)}onAbort(){this.recipients.reduce((r,n)=>r&&n.signal?.aborted===!0,!0)&&(this.controller.abort(new Ce),this.cleanup())}async join(e){let r=new Qr(e);return this.recipients.push(r),e?.signal?.addEventListener("abort",this.onAbort),r.deferred.promise}async run(){this.status="running",this.timeline.started=Date.now();try{this.controller.signal.throwIfAborted();let e=await M(this.fn({...this.options??{},signal:this.controller.signal,onProgress:r=>{if(!this.dispatchingProgress){this.dispatchingProgress=!0;try{this.recipients.forEach(n=>{n.onProgress?.(r)})}finally{this.dispatchingProgress=!1}}}}),this.controller.signal);this.recipients.forEach(r=>{r.deferred.resolve(e)}),this.status="complete"}catch(e){this.recipients.forEach(r=>{r.deferred.reject(e)}),this.status="errored"}finally{this.timeline.finished=Date.now(),this.cleanup()}}cleanup(){this.recipients.forEach(e=>{e.cleanup(),e.signal?.removeEventListener("abort",this.onAbort)})}};var de=class extends ye{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=St(this.emitEmpty.bind(this),1),this.emitIdle=St(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 Qt;let n=new Xr(e,r);this.enqueue(n),this.safeDispatchEvent("add");let o=n.join(r).then(s=>(this.safeDispatchEvent("completed",{detail:s}),this.safeDispatchEvent("success",{detail:{job:n,result:s}}),s)).catch(s=>{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:s}}),s});return this.tryToStartAnother(),o}clear(){this.queue.splice(0,this.queue.length)}abort(){this.queue.forEach(e=>{e.abort(new Ce)}),this.clear()}async onEmpty(e){this.size!==0&&await F(this,"empty",e)}async onSizeLessThan(e,r){this.size<e||await F(this,"next",{...r,filter:()=>this.size<e})}async onIdle(e){this.pending===0&&this.size===0||await F(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=we({objectMode:!0}),n=u=>{u!=null?this.abort():this.clear(),r.end(u)},o=u=>{u.detail!=null&&r.push(u.detail)},s=u=>{n(u.detail.error)},i=()=>{n()},a=()=>{n(new Ce("Queue aborted"))};this.addEventListener("completed",o),this.addEventListener("failure",s),this.addEventListener("idle",i),e?.signal?.addEventListener("abort",a);try{yield*r}finally{this.removeEventListener("completed",o),this.removeEventListener("failure",s),this.removeEventListener("idle",i),e?.signal?.removeEventListener("abort",a),n()}}};var tl=Math.pow(2,20)*4,Ze=class extends ye{status;timeline;inactivityTimeout;maxReadBufferLength;maxWriteBufferLength;log;direction;maxMessageSize;readStatus;writeStatus;remoteReadStatus;remoteWriteStatus;writableNeedsDrain;readBuffer;writeBuffer;sendingData;onDrainPromise;constructor(e){super(),this.status="open",this.log=e.log,this.direction=e.direction??"outbound",this.inactivityTimeout=e.inactivityTimeout??12e4,this.maxReadBufferLength=e.maxReadBufferLength??tl,this.maxWriteBufferLength=e.maxWriteBufferLength,this.maxMessageSize=e.maxMessageSize,this.readBuffer=new k,this.writeBuffer=new k,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,queueMicrotask(()=>{try{this.processSendQueue()}catch(o){this.log.error("processSendQueue threw - %e",o)}})),this.onDrainPromise?.resolve()};this.addEventListener("drain",r);let n=o=>{this.onDrainPromise?.reject(o.error??new Kt)};this.addEventListener("close",n)}get readBufferLength(){return this.readBuffer.byteLength}get writeBufferLength(){return this.writeBuffer.byteLength}async onDrain(e){return this.writableNeedsDrain!==!0?Promise.resolve():(this.onDrainPromise==null&&(this.onDrainPromise=Promise.withResolvers()),M(this.onDrainPromise.promise,e?.signal))}async*[Symbol.asyncIterator](){if(this.readStatus!=="readable"&&this.readStatus!=="paused")return;let e=we(),r=s=>{e.push(s.data)};this.addEventListener("message",r);let n=s=>{e.end(s.error)};this.addEventListener("close",n);let o=()=>{e.end()};this.addEventListener("remoteCloseWrite",o);try{yield*e}finally{this.removeEventListener("message",r),this.removeEventListener("close",n),this.removeEventListener("remoteCloseWrite",o)}}isReadable(){return this.status==="open"}send(e){if(this.writeStatus==="closed"||this.writeStatus==="closing")throw new Ne(`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 xr(e))}}pause(){if(this.readStatus==="closed"||this.readStatus==="closing")throw new Ne("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 Ne("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 Ne(`Cannot push data onto a stream that is ${this.readStatus}`);if(e.byteLength!==0){if(this.readBuffer.append(e),this.readStatus==="paused"||this.listenerCount("message")===0){this.checkReadBufferLength();return}setTimeout(()=>{this.dispatchReadBuffer()},0)}}unshift(e){if(this.readStatus==="closed"||this.readStatus==="closing")throw new Ne(`Cannot push data onto a stream that is ${this.readStatus}`);if(e.byteLength!==0){if(this.readBuffer.prepend(e),this.readStatus==="paused"||this.listenerCount("message")===0){this.checkReadBufferLength();return}setTimeout(()=>{this.dispatchReadBuffer()},0)}}onData(e){if(e.byteLength!==0){if(this.readStatus==="closing"||this.readStatus==="closed"){this.log("ignoring data - read status %s",this.readStatus);return}this.readBuffer.append(e),this.dispatchReadBuffer()}}addEventListener(...e){super.addEventListener.apply(this,e),e[0]==="message"&&this.readBuffer.byteLength>0&&queueMicrotask(()=>{this.dispatchReadBuffer()})}onRemoteReset(){this.log("remote reset"),this.status="reset",this.writeStatus="closed",this.remoteWriteStatus="closed",this.remoteReadStatus="closed",this.timeline.close=Date.now(),this.readBuffer.byteLength===0&&(this.readStatus="closed");let e=new yr;this.dispatchEvent(new wr(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 ht))}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;if(this.writeStatus!=="writable"&&this.writeStatus!=="closing")return this.log.trace("not processing send queue as stream is %s",this.writeStatus),!1;this.sendingData=!0,this.log.trace("processing send queue with %d queued bytes",this.writeBuffer.byteLength);try{let e=!0,r=this.writeBuffer.byteLength,n=0;for(;this.writeBuffer.byteLength>0;){let o=Math.min(this.maxMessageSize??this.writeBuffer.byteLength,this.writeBuffer.byteLength);if(o===0){e=!1;break}let s=this.writeBuffer.sublist(0,o),i=new k(s);this.writeBuffer.consume(s.byteLength);let a;try{a=this.sendData(s)}catch(u){throw this.writeBuffer.prepend(i),this.abort(u),u}if(e=a.canSendMore,n+=a.sentBytes,a.sentBytes!==i.byteLength&&(i.consume(a.sentBytes),this.writeBuffer.prepend(i)),!e)break}return e||(this.log.trace("sent %d/%d bytes, pausing sending because underlying stream is full, %d bytes left in the write buffer",n,r,this.writeBuffer.byteLength),this.writableNeedsDrain=!0,this.checkWriteBufferLength()),this.writeBuffer.byteLength===0&&this.safeDispatchEvent("idle"),e}finally{this.sendingData=!1}}dispatchReadBuffer(){try{if(this.listenerCount("message")===0){this.log.trace("not dispatching pause buffer as there are no listeners for the message event");return}if(this.readBuffer.byteLength===0){this.log.trace("not dispatching pause buffer as there is no data to dispatch");return}if(this.readStatus==="paused"){this.log.trace("not dispatching pause buffer we are paused");return}if(this.readStatus==="closing"||this.readStatus==="closed"){this.log("dropping %d bytes because the readable end is %s",this.readBuffer.byteLength,this.readStatus),this.readBuffer.consume(this.readBuffer.byteLength);return}let e=this.readBuffer.sublist();this.readBuffer.consume(e.byteLength),this.dispatchEvent(new be(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 zt(`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 zt(`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 Jt=class extends Ze{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 F(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 F(this,"drain",{...e,rejectionEvents:["close"]})),await this.sendClose(e),this.onTransportClosed())}};function Yo(t){return t==null?!1:typeof t.then=="function"&&typeof t.catch=="function"&&typeof t.finally=="function"}var Yt=class extends ye{streams;protocol;status;log;maConn;streamOptions;earlyStreams;maxEarlyStreams;metrics;constructor(e,r){super(),this.maConn=e,this.protocol=r.protocol,this.streams=[],this.earlyStreams=[],this.status="open",this.log=e.log.newScope(r.name),this.streamOptions=r.streamOptions,this.maxEarlyStreams=r.maxEarlyStreams??10,this.metrics=r.metrics;let n=i=>{try{this.onData(i.data)}catch(a){this.abort(a),this.maConn.abort(a)}};this.maConn.addEventListener("message",n);let o=()=>{this.log("underlying stream drained, signal %d streams to continue writing",this.streams.length),this.streams.forEach(i=>{i.onMuxerDrain()})};this.maConn.addEventListener("drain",o);let s=()=>{this.log("underlying stream closed with status %s and %d streams",this.status,this.streams.length),this.onTransportClosed()};this.maConn.addEventListener("close",s)}send(e){let r=this.maConn.send(e);return r===!1&&(this.log("underlying stream saturated, signal %d streams to pause writing",this.streams.length),this.streams.forEach(n=>{n.onMuxerNeedsDrain()})),r}async close(e){this.status==="closed"||this.status==="closing"||(this.status="closing",await M(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 br;let r=this.onCreateStream({...this.streamOptions,...e});return Yo(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 Xt(`Too many early streams were opened - ${this.earlyStreams.length}/${this.maxEarlyStreams}`));return}this.safeDispatchEvent("stream",{detail:e})}cleanUpStream(e){let r=n=>{let o=this.streams.findIndex(s=>s===e);o!==-1&&this.streams.splice(o,1),n.error!=null?n.local?this.metrics?.increment({[`${e.direction}_stream_reset`]:!0}):this.metrics?.increment({[`${e.direction}_stream_abort`]:!0}):this.metrics?.increment({[`${e.direction}_stream_end`]:!0})};e.addEventListener("close",r),this.metrics?.increment({[`${e.direction}_stream`]:!0})}addEventListener(...e){super.addEventListener.apply(this,e),e[0]==="stream"&&this.earlyStreams.length>0&&queueMicrotask(()=>{this.earlyStreams.forEach(r=>{this.safeDispatchEvent("stream",{detail:r})}),this.earlyStreams=[]})}};var et=class extends Ze{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 F(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 F(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 Kr(t){let e=new globalThis.AbortController;function r(){let s=t.filter(i=>i?.aborted===!0).map(i=>i?.reason).pop();e.abort(s);for(let i of t)i?.removeEventListener!=null&&i.removeEventListener("abort",r)}for(let s of t){if(s?.aborted===!0){r();break}s?.addEventListener!=null&&s.addEventListener("abort",r)}function n(){for(let s of t)s?.removeEventListener!=null&&s.removeEventListener("abort",r)}let o=e.signal;return o.clear=n,o}var tt=class{movingAverage;variance;deviation;forecast;timeSpan;previousTime;constructor(e){this.timeSpan=e,this.movingAverage=0,this.variance=0,this.deviation=0,this.forecast=0}alpha(e,r){return 1-Math.exp(-(e-r)/this.timeSpan)}push(e,r=Date.now()){if(this.previousTime!=null){let n=this.alpha(r,this.previousTime),o=e-this.movingAverage,s=n*o;this.movingAverage=n*e+(1-n)*this.movingAverage,this.variance=(1-n)*(this.variance+o*s),this.deviation=Math.sqrt(this.variance),this.forecast=this.movingAverage+n*o}else this.movingAverage=e;this.previousTime=r}};var Vi=1.2,ji=2,Wi=5e3,qi=6e4,Gi=5e3,Zo=class{success;failure;next;metric;timeoutMultiplier;failureMultiplier;minTimeout;maxTimeout;constructor(e={}){let r=e.interval??Gi;this.success=new tt(r),this.failure=new tt(r),this.next=new tt(r),this.failureMultiplier=e.failureMultiplier??ji,this.timeoutMultiplier=e.timeoutMultiplier??Vi,this.minTimeout=e.minTimeout??Wi,this.maxTimeout=e.maxTimeout??qi,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=Kr([e.signal,n]);return o.start=Date.now(),o.timeout=r,o}cleanUp(e){e.clear();let r=Date.now()-e.start;e.aborted?(this.failure.push(r),this.next.push(r*this.failureMultiplier),this.metric?.update({failureMovingAverage:this.failure.movingAverage,failureDeviation:this.failure.deviation,failureForecast:this.failure.forecast,failureVariance:this.failure.variance,failure:r})):(this.success.push(r),this.next.push(r),this.metric?.update({successMovingAverage:this.success.movingAverage,successDeviation:this.success.deviation,successForecast:this.success.forecast,successVariance:this.success.variance,success:r}))}};function Hi(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),Re(`/${n.join("/")}`)}function rl(t,e){if(t==null)return[];let r=le(t);return[Hi(r,e)]}function nl(t){return Me(t)?Cr("2000::/3",t):!1}function ol(t,e){if(typeof t!="string")throw new oe(`invalid ip provided: ${t}`);if(typeof e=="string"&&(e=parseInt(e)),isNaN(e))throw new oe(`invalid port provided: ${e}`);if(Fe(t))return Re(`/ip4/${t}/tcp/${e}`);if(Me(t))return Re(`/ip6/${t}/tcp/${e}`);throw new oe(`invalid ip:port for creating a multiaddr: ${t}:${e}`)}function sl(t){return t==null||typeof t?.[Symbol.asyncIterator]!="function"?!1:typeof t.next=="function"}function il(t){return t==null||typeof t?.[Symbol.iterator]!="function"?!1:typeof t.next=="function"}var es=class{readNext;haveNext;ended;nextResult;error;constructor(){this.ended=!1,this.readNext=he(),this.haveNext=he()}[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=he(),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=he(),await M(this.readNext.promise,r?.signal,r)}};function Qi(){return new es}function al(t){return t[Symbol.asyncIterator]!=null}async function cl(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*ul(t){let e=new AbortController,r=Qi();cl(t,r,e.signal).catch(()=>{});try{yield*r}finally{e.abort()}}function*fl(t){for(let e of t)yield*e}function ll(...t){let e=[];for(let r of t)al(r)||e.push(r);return e.length===t.length?fl(e):ul(t)}var Xi=ll;function Ki(t,...e){if(t==null)throw new Error("Empty pipeline");if(ts(t)){let n=t;t=()=>n.source}else if(Yi(t)||Ji(t)){let n=t;t=()=>n}let r=[t,...e];if(r.length>1&&ts(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++)ts(r[n])&&(r[n]=dl(r[n]));return hl(...r)}var hl=(...t)=>{let e;for(;t.length>0;)e=t.shift()(e);return e},Ji=t=>t?.[Symbol.asyncIterator]!=null,Yi=t=>t?.[Symbol.iterator]!=null,ts=t=>t==null?!1:t.sink!=null&&t.source!=null,dl=t=>e=>{let r=t.sink(e);if(r?.then!=null){let n=we({objectMode:!0});r.then(()=>{n.end()},i=>{n.end(i)});let o,s=t.source;if(Ji(s))o=async function*(){yield*s,n.end()};else if(Yi(s))o=function*(){yield*s,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return Xi(n,o())}return t.source};var ml=4194304,Zt=class extends Error{static name="UnwrappedError";name="UnwrappedError"},Ct=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},Jr=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},Yr=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function pl(t){return typeof t?.closeRead=="function"}function gl(t){return typeof t?.close=="function"}function rs(t){return pl(t)?t.remoteWriteStatus!=="writable"&&t.readBufferLength===0:gl(t)?t.status!=="open":!1}function bl(t){return t?.addEventListener!=null&&t?.removeEventListener!=null&&t?.send!=null&&t?.push!=null&&t?.log!=null}function Zi(t,e){let r=e?.maxBufferSize??ml,n=new k,o,s=!1;if(!bl(t))throw new oe("Argument should be a Stream or a Multiaddr");let i=f=>{if(n.append(f.data),n.byteLength>r){let h=n.byteLength;n.consume(n.byteLength),o?.reject(new Error(`Read buffer overflow - ${h} > ${r}`))}o?.resolve()};t.addEventListener("message",i);let a=f=>{f.error!=null?o?.reject(f.error):o?.resolve()};t.addEventListener("close",a);let u=()=>{o?.resolve()};t.addEventListener("remoteCloseWrite",u);let l={readBuffer:n,async read(f){if(s===!0)throw new Zt("Stream was unwrapped");if(rs(t)){if(n.byteLength===0&&f?.bytes==null)return null;if(f?.bytes!=null&&n.byteLength<f.bytes)throw t.log.error("closed after reading %d/%d bytes",n.byteLength,f.bytes),new $e(`Unexpected EOF - stream closed after reading ${n.byteLength}/${f.bytes} bytes`)}let h=f?.bytes??1;for(o=Promise.withResolvers();;){if(n.byteLength>=h){o.resolve();break}if(await M(o.promise,f?.signal),rs(t)){if(n.byteLength===0&&f?.bytes==null)return null;break}o=Promise.withResolvers()}let p=f?.bytes??n.byteLength;if(n.byteLength<p){if(rs(t))throw t.log.error("closed while reading %d/%d bytes",n.byteLength,p),new $e(`Unexpected EOF - stream closed while reading ${n.byteLength}/${p} bytes`);return l.read(f)}let x=n.sublist(0,p);return n.consume(p),x},async write(f,h){if(s===!0)throw new Zt("Stream was unwrapped");t.send(f)||await F(t,"drain",{signal:h?.signal,rejectionEvents:["close"]})},unwrap(){return s||(s=!0,t.removeEventListener("message",i),t.removeEventListener("close",a),t.removeEventListener("remoteCloseWrite",u),n.byteLength>0&&(t.log("stream unwrapped with %d unread bytes",n.byteLength),t.unshift(n))),t}};return l}function ea(t,e={}){let r=Zi(t,e);e.maxDataLength!=null&&e.maxLengthLength==null&&(e.maxLengthLength=V(e.maxDataLength));let n=e?.lengthDecoder??Ie,o=e?.lengthEncoder??Dr;return{async read(i){let a=-1,u=new k;for(;;){let f=await r.read({...i,bytes:1});if(f==null)break;u.append(f);try{a=n(u)}catch(h){if(h instanceof RangeError)continue;throw h}if(a<0)throw new Ct("Invalid message length");if(e?.maxLengthLength!=null&&u.byteLength>e.maxLengthLength)throw new Yr(`Message length length too long - ${u.byteLength} > ${e.maxLengthLength}`);if(a>-1)break}if(e?.maxDataLength!=null&&a>e.maxDataLength)throw new Jr(`Message length too long - ${a} > ${e.maxDataLength}`);let l=await r.read({...i,bytes:a});if(l==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(l.byteLength!==a)throw t.log.error("read %d/%d bytes before the stream closed",l.byteLength,a),new $e(`Unexpected EOF - read ${l.byteLength}/${a} bytes before the stream closed`);return l},async write(i,a){await r.write(new k(o(i.byteLength),i),a)},async writeV(i,a){let u=new k(...i.flatMap(l=>[o(l.byteLength),l]));await r.write(u,a)},unwrap(){return r.unwrap()}}}function yl(t,e){let r=ea(t,e),n={read:async(o,s)=>{let i=await r.read(s);return o.decode(i)},write:async(o,s,i)=>{await r.write(s.encode(o),i)},writeV:async(o,s,i)=>{await r.writeV(o.map(a=>s.encode(a)),i)},pb:o=>({read:async s=>n.read(o,s),write:async(s,i)=>n.write(s,o,i),writeV:async(s,i)=>n.writeV(s,o,i),unwrap:()=>n}),unwrap:()=>r.unwrap()};return n}async function ns(t,e){let r=t.log.newScope("echo"),n=Date.now(),o=0;try{for await(let s of t)o+=s.byteLength,t.send(s)||(t.pause(),await F(t,"drain",{rejectionEvents:["close"],...e}),t.resume());r("echoed %d bytes in %dms",o,Date.now()-n),await t.close(e)}catch(s){t.abort(s)}}function xl(t){return t?.addEventListener!=null}function ta(t){let e=we(),r,n=i=>{e.push(i.data)},o=()=>{e.end(),t.removeEventListener("message",n),t.removeEventListener("close",s),t.removeEventListener("remoteCloseWrite",o)},s=i=>{e.end(i.error),i.error!=null&&r?.reject(i.error),t.removeEventListener("message",n),t.removeEventListener("close",s),t.removeEventListener("remoteCloseWrite",o)};return t.addEventListener("message",n),t.addEventListener("close",s,{once:!0}),t.addEventListener("remoteCloseWrite",o,{once:!0}),{source:e,async sink(i){async function*a(){yield*i}let u=a();for(;;){r=Promise.withResolvers();let{done:l,value:f}=await Promise.race([u.next(),r.promise]);if(t.writeStatus==="closing"||t.writeStatus==="closed"||(f!=null&&(t.send(f)||await Promise.race([F(t,"drain",{rejectionEvents:["close"]})])),l===!0))break}await t.close()}}}function wl(...t){let e=t.map(r=>xl(r)?ta(r):r);return Ki(...e)}var El=1024*1024*4,_l=1024*1024*4,os=class{buffer;maxBufferSize;lengthDecoder;maxDataLength;encodingLength;constructor(e={}){this.buffer=new k,this.maxBufferSize=e.maxBufferSize??El,this.maxDataLength=e.maxDataLength??_l,this.lengthDecoder=e.lengthDecoder??Ie,this.encodingLength=e.encodingLength??V}*decode(e){if(this.buffer.append(e),this.buffer.byteLength>this.maxBufferSize)throw new oe(`Buffer length limit exceeded - ${this.buffer.byteLength}/${this.maxBufferSize}`);for(;;){let r;try{r=this.lengthDecoder(this.buffer)}catch(s){if(s instanceof RangeError)break;throw s}if(r<0||r>this.maxDataLength)throw new Ct("Invalid message length");let n=this.encodingLength(r),o=n+r;if(this.buffer.byteLength>=o){let s=this.buffer.sublist(n,o);this.buffer.consume(o),s.byteLength>0&&(yield s)}else break}}};function vl(t){return!!(t.startsWith("169.254.")||t.toLowerCase().startsWith("fe80"))}var Sl=["Object","RegExp","Date","Error","Map","Set","WeakMap","WeakSet","ArrayBuffer","SharedArrayBuffer","DataView","Promise","URL","HTMLElement","Int8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array","Tagged"];function ss(t){if(t===null)return"null";if(t===void 0)return"undefined";if(t===!0||t===!1)return"boolean";let e=typeof t;if(e==="string"||e==="number"||e==="bigint"||e==="symbol")return e;if(e==="function")return"Function";if(Array.isArray(t))return"Array";if(t instanceof Uint8Array)return"Uint8Array";if(t.constructor===Object)return"Object";let r=Cl(t);return r||"Object"}function Cl(t){let e=Object.prototype.toString.call(t).slice(8,-1);if(Sl.includes(e))return e}var c=class{constructor(e,r,n){this.major=e,this.majorEncoded=e<<5,this.name=r,this.terminal=n}toString(){return`Type[${this.major}].${this.name}`}compare(e){return this.major<e.major?-1:this.major>e.major?1:0}static equals(e,r){return e===r||e.major===r.major&&e.name===r.name}};c.uint=new c(0,"uint",!0);c.negint=new c(1,"negint",!0);c.bytes=new c(2,"bytes",!0);c.string=new c(3,"string",!0);c.array=new c(4,"array",!1);c.map=new c(5,"map",!1);c.tag=new c(6,"tag",!1);c.float=new c(7,"float",!0);c.false=new c(7,"false",!0);c.true=new c(7,"true",!0);c.null=new c(7,"null",!0);c.undefined=new c(7,"undefined",!0);c.break=new c(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 er=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",Il=new TextEncoder;function Zr(t){return er&&globalThis.Buffer.isBuffer(t)}function tr(t){return t instanceof Uint8Array?Zr(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):t:Uint8Array.from(t)}var Ll=24,Tl=200,en=er?t=>t.length>=Ll?globalThis.Buffer.from(t):ra(t):t=>t.length>=Tl?Il.encode(t):ra(t),Ee=t=>Uint8Array.from(t),na=er?(t,e,r)=>Zr(t)?new Uint8Array(t.subarray(e,r)):t.slice(e,r):(t,e,r)=>t.slice(e,r),oa=er?(t,e)=>(t=t.map(r=>r instanceof Uint8Array?r:globalThis.Buffer.from(r)),tr(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},sa=er?t=>globalThis.Buffer.allocUnsafe(t):t=>new Uint8Array(t);function tn(t,e){if(Zr(t)&&Zr(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 ra(t){let e=[],r=0;for(let n=0;n<t.length;n++){let o=t.charCodeAt(n);o<128?e[r++]=o:o<2048?(e[r++]=o>>6|192,e[r++]=o&63|128):(o&64512)===55296&&n+1<t.length&&(t.charCodeAt(n+1)&64512)===56320?(o=65536+((o&1023)<<10)+(t.charCodeAt(++n)&1023),e[r++]=o>>18|240,e[r++]=o>>12&63|128,e[r++]=o>>6&63|128,e[r++]=o&63|128):(o>=55296&&o<=57343&&(o=65533),e[r++]=o>>12|224,e[r++]=o>>6&63|128,e[r++]=o&63|128)}return e}var Al=256,rr=class{constructor(e=Al){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=sa(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=na(n,0,this.cursor)}else r=oa(this.chunks,this.cursor);return e&&this.reset(),r}},rn=class{constructor(e){this.dest=e,this.cursor=0,this.chunks=[e]}reset(){this.cursor=0}push(e){if(this.cursor+e.length>this.dest.length)throw new Error("write out of bounds, destination buffer is too small");this.dest.set(e,this.cursor),this.cursor+=e.length}toBytes(e=!1){let r=this.dest.subarray(0,this.cursor);return e&&this.reset(),r}};var g="CBOR decode error:",nn="CBOR encode error:",nr=[];nr[23]=1;nr[24]=2;nr[25]=3;nr[26]=5;nr[27]=9;function De(t,e,r){if(t.length-e<r)throw new Error(`${g} not enough data for type`)}var U=[24,256,65536,4294967296,BigInt("18446744073709551616")];function J(t,e,r){De(t,e,1);let n=t[e];if(r.strict===!0&&n<U[0])throw new Error(`${g} integer encoded in more bytes than necessary (strict decode)`);return n}function Y(t,e,r){De(t,e,2);let n=t[e]<<8|t[e+1];if(r.strict===!0&&n<U[1])throw new Error(`${g} integer encoded in more bytes than necessary (strict decode)`);return n}function Z(t,e,r){De(t,e,4);let n=t[e]*16777216+(t[e+1]<<16)+(t[e+2]<<8)+t[e+3];if(r.strict===!0&&n<U[2])throw new Error(`${g} integer encoded in more bytes than necessary (strict decode)`);return n}function ee(t,e,r){De(t,e,8);let n=t[e]*16777216+(t[e+1]<<16)+(t[e+2]<<8)+t[e+3],o=t[e+4]*16777216+(t[e+5]<<16)+(t[e+6]<<8)+t[e+7],s=(BigInt(n)<<BigInt(32))+BigInt(o);if(r.strict===!0&&s<U[3])throw new Error(`${g} integer encoded in more bytes than necessary (strict decode)`);if(s<=Number.MAX_SAFE_INTEGER)return Number(s);if(r.allowBigInt===!0)return s;throw new Error(`${g} integers outside of the safe integer range are not supported`)}function ia(t,e,r,n){return new m(c.uint,J(t,e+1,n),2)}function aa(t,e,r,n){return new m(c.uint,Y(t,e+1,n),3)}function ca(t,e,r,n){return new m(c.uint,Z(t,e+1,n),5)}function ua(t,e,r,n){return new m(c.uint,ee(t,e+1,n),9)}function se(t,e){return A(t,0,e.value)}function A(t,e,r){if(r<U[0]){let n=Number(r);t.push([e|n])}else if(r<U[1]){let n=Number(r);t.push([e|24,n])}else if(r<U[2]){let n=Number(r);t.push([e|25,n>>>8,n&255])}else if(r<U[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<U[4]){let o=[e|27,0,0,0,0,0,0,0],s=Number(n&BigInt(4294967295)),i=Number(n>>BigInt(32)&BigInt(4294967295));o[8]=s&255,s=s>>8,o[7]=s&255,s=s>>8,o[6]=s&255,s=s>>8,o[5]=s&255,o[4]=i&255,i=i>>8,o[3]=i&255,i=i>>8,o[2]=i&255,i=i>>8,o[1]=i&255,t.push(o)}else throw new Error(`${g} encountered BigInt larger than allowable range`)}}se.encodedSize=function(e){return A.encodedSize(e.value)};A.encodedSize=function(e){return e<U[0]?1:e<U[1]?2:e<U[2]?3:e<U[3]?5:9};se.compareTokens=function(e,r){return e.value<r.value?-1:e.value>r.value?1:0};function fa(t,e,r,n){return new m(c.negint,-1-J(t,e+1,n),2)}function la(t,e,r,n){return new m(c.negint,-1-Y(t,e+1,n),3)}function ha(t,e,r,n){return new m(c.negint,-1-Z(t,e+1,n),5)}var is=BigInt(-1),da=BigInt(1);function ma(t,e,r,n){let o=ee(t,e+1,n);if(typeof o!="bigint"){let s=-1-o;if(s>=Number.MIN_SAFE_INTEGER)return new m(c.negint,s,9)}if(n.allowBigInt!==!0)throw new Error(`${g} integers outside of the safe integer range are not supported`);return new m(c.negint,is-BigInt(o),9)}function on(t,e){let r=e.value,n=typeof r=="bigint"?r*is-da:r*-1-1;A(t,e.type.majorEncoded,n)}on.encodedSize=function(e){let r=e.value,n=typeof r=="bigint"?r*is-da:r*-1-1;return n<U[0]?1:n<U[1]?2:n<U[2]?3:n<U[3]?5:9};on.compareTokens=function(e,r){return e.value<r.value?1:e.value>r.value?-1:0};function or(t,e,r,n){De(t,e,r+n);let o=t.slice(e+r,e+r+n);return new m(c.bytes,o,r+n)}function pa(t,e,r,n){return or(t,e,1,r)}function ga(t,e,r,n){return or(t,e,2,J(t,e+1,n))}function ba(t,e,r,n){return or(t,e,3,Y(t,e+1,n))}function ya(t,e,r,n){return or(t,e,5,Z(t,e+1,n))}function xa(t,e,r,n){let o=ee(t,e+1,n);if(typeof o=="bigint")throw new Error(`${g} 64-bit integer bytes lengths not supported`);return or(t,e,9,o)}function sn(t){return t.encodedBytes===void 0&&(t.encodedBytes=c.equals(t.type,c.string)?en(t.value):t.value),t.encodedBytes}function It(t,e){let r=sn(e);A(t,e.type.majorEncoded,r.length),t.push(r)}It.encodedSize=function(e){let r=sn(e);return A.encodedSize(r.length)+r.length};It.compareTokens=function(e,r){return kl(sn(e),sn(r))};function kl(t,e){return t.length<e.length?-1:t.length>e.length?1:tn(t,e)}var wa=new TextDecoder,Bl=32;function Nl(t,e,r){if(r-e<Bl){let o="";for(let s=e;s<r;s++){let i=t[s];if(i&128)return wa.decode(t.subarray(e,r));o+=String.fromCharCode(i)}return o}return wa.decode(t.subarray(e,r))}function sr(t,e,r,n,o){let s=r+n;De(t,e,s);let i=new m(c.string,Nl(t,e+r,e+s),s);return o.retainStringBytes===!0&&(i.byteValue=t.slice(e+r,e+s)),i}function Ea(t,e,r,n){return sr(t,e,1,r,n)}function _a(t,e,r,n){return sr(t,e,2,J(t,e+1,n),n)}function va(t,e,r,n){return sr(t,e,3,Y(t,e+1,n),n)}function Sa(t,e,r,n){return sr(t,e,5,Z(t,e+1,n),n)}function Ca(t,e,r,n){let o=ee(t,e+1,n);if(typeof o=="bigint")throw new Error(`${g} 64-bit integer string lengths not supported`);return sr(t,e,9,o,n)}var Ia=It;function Lt(t,e,r,n){return new m(c.array,n,r)}function La(t,e,r,n){return Lt(t,e,1,r)}function Ta(t,e,r,n){return Lt(t,e,2,J(t,e+1,n))}function Aa(t,e,r,n){return Lt(t,e,3,Y(t,e+1,n))}function Da(t,e,r,n){return Lt(t,e,5,Z(t,e+1,n))}function ka(t,e,r,n){let o=ee(t,e+1,n);if(typeof o=="bigint")throw new Error(`${g} 64-bit integer array lengths not supported`);return Lt(t,e,9,o)}function Pa(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${g} indefinite length items not allowed`);return Lt(t,e,1,1/0)}function an(t,e){A(t,c.array.majorEncoded,e.value)}an.compareTokens=se.compareTokens;an.encodedSize=function(e){return A.encodedSize(e.value)};function Tt(t,e,r,n){return new m(c.map,n,r)}function Ba(t,e,r,n){return Tt(t,e,1,r)}function Na(t,e,r,n){return Tt(t,e,2,J(t,e+1,n))}function Fa(t,e,r,n){return Tt(t,e,3,Y(t,e+1,n))}function Ma(t,e,r,n){return Tt(t,e,5,Z(t,e+1,n))}function Ua(t,e,r,n){let o=ee(t,e+1,n);if(typeof o=="bigint")throw new Error(`${g} 64-bit integer map lengths not supported`);return Tt(t,e,9,o)}function Oa(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${g} indefinite length items not allowed`);return Tt(t,e,1,1/0)}function cn(t,e){A(t,c.map.majorEncoded,e.value)}cn.compareTokens=se.compareTokens;cn.encodedSize=function(e){return A.encodedSize(e.value)};function Ra(t,e,r,n){return new m(c.tag,r,1)}function $a(t,e,r,n){return new m(c.tag,J(t,e+1,n),2)}function za(t,e,r,n){return new m(c.tag,Y(t,e+1,n),3)}function Va(t,e,r,n){return new m(c.tag,Z(t,e+1,n),5)}function ja(t,e,r,n){return new m(c.tag,ee(t,e+1,n),9)}function un(t,e){A(t,c.tag.majorEncoded,e.value)}un.compareTokens=se.compareTokens;un.encodedSize=function(e){return A.encodedSize(e.value)};var as=20,cs=21,us=22,fs=23;function Wa(t,e,r,n){if(n.allowUndefined===!1)throw new Error(`${g} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new m(c.null,null,1):new m(c.undefined,void 0,1)}function qa(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${g} indefinite length items not allowed`);return new m(c.break,void 0,1)}function ls(t,e,r){if(r){if(r.allowNaN===!1&&Number.isNaN(t))throw new Error(`${g} NaN values are not supported`);if(r.allowInfinity===!1&&(t===1/0||t===-1/0))throw new Error(`${g} Infinity values are not supported`)}return new m(c.float,t,e)}function Ga(t,e,r,n){return ls(hs(t,e+1),3,n)}function Ha(t,e,r,n){return ls(ds(t,e+1),5,n)}function Qa(t,e,r,n){return ls(Ya(t,e+1),9,n)}function ir(t,e,r){let n=e.value;if(n===!1)t.push([c.float.majorEncoded|as]);else if(n===!0)t.push([c.float.majorEncoded|cs]);else if(n===null)t.push([c.float.majorEncoded|us]);else if(n===void 0)t.push([c.float.majorEncoded|fs]);else{let o,s=!1;(!r||r.float64!==!0)&&(Ka(n),o=hs(me,1),n===o||Number.isNaN(n)?(me[0]=249,t.push(me.slice(0,3)),s=!0):(Ja(n),o=ds(me,1),n===o&&(me[0]=250,t.push(me.slice(0,5)),s=!0))),s||(Rl(n),o=Ya(me,1),me[0]=251,t.push(me.slice(0,9)))}}ir.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){Ka(n);let o=hs(me,1);if(n===o||Number.isNaN(n))return 3;if(Ja(n),o=ds(me,1),n===o)return 5}return 9};var Xa=new ArrayBuffer(9),ie=new DataView(Xa,1),me=new Uint8Array(Xa,0);function Ka(t){if(t===1/0)ie.setUint16(0,31744,!1);else if(t===-1/0)ie.setUint16(0,64512,!1);else if(Number.isNaN(t))ie.setUint16(0,32256,!1);else{ie.setFloat32(0,t);let e=ie.getUint32(0),r=(e&2139095040)>>23,n=e&8388607;if(r===255)ie.setUint16(0,31744,!1);else if(r===0)ie.setUint16(0,(e&2147483648)>>16|n>>13,!1);else{let o=r-127;o<-24?ie.setUint16(0,0):o<-14?ie.setUint16(0,(e&2147483648)>>16|1<<24+o,!1):ie.setUint16(0,(e&2147483648)>>16|o+15<<10|n>>13,!1)}}}function hs(t,e){if(t.length-e<2)throw new Error(`${g} not enough data for float16`);let r=(t[e]<<8)+t[e+1];if(r===31744)return 1/0;if(r===64512)return-1/0;if(r===32256)return NaN;let n=r>>10&31,o=r&1023,s;return n===0?s=o*2**-24:n!==31?s=(o+1024)*2**(n-25):s=o===0?1/0:NaN,r&32768?-s:s}function Ja(t){ie.setFloat32(0,t,!1)}function ds(t,e){if(t.length-e<4)throw new Error(`${g} not enough data for float32`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,4).getFloat32(0,!1)}function Rl(t){ie.setFloat64(0,t,!1)}function Ya(t,e){if(t.length-e<8)throw new Error(`${g} not enough data for float64`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,8).getFloat64(0,!1)}ir.compareTokens=se.compareTokens;function v(t,e,r){throw new Error(`${g} encountered invalid minor (${r}) for major ${t[e]>>>5}`)}function fn(t){return()=>{throw new Error(`${g} ${t}`)}}var d=[];for(let t=0;t<=23;t++)d[t]=v;d[24]=ia;d[25]=aa;d[26]=ca;d[27]=ua;d[28]=v;d[29]=v;d[30]=v;d[31]=v;for(let t=32;t<=55;t++)d[t]=v;d[56]=fa;d[57]=la;d[58]=ha;d[59]=ma;d[60]=v;d[61]=v;d[62]=v;d[63]=v;for(let t=64;t<=87;t++)d[t]=pa;d[88]=ga;d[89]=ba;d[90]=ya;d[91]=xa;d[92]=v;d[93]=v;d[94]=v;d[95]=fn("indefinite length bytes/strings are not supported");for(let t=96;t<=119;t++)d[t]=Ea;d[120]=_a;d[121]=va;d[122]=Sa;d[123]=Ca;d[124]=v;d[125]=v;d[126]=v;d[127]=fn("indefinite length bytes/strings are not supported");for(let t=128;t<=151;t++)d[t]=La;d[152]=Ta;d[153]=Aa;d[154]=Da;d[155]=ka;d[156]=v;d[157]=v;d[158]=v;d[159]=Pa;for(let t=160;t<=183;t++)d[t]=Ba;d[184]=Na;d[185]=Fa;d[186]=Ma;d[187]=Ua;d[188]=v;d[189]=v;d[190]=v;d[191]=Oa;for(let t=192;t<=215;t++)d[t]=Ra;d[216]=$a;d[217]=za;d[218]=Va;d[219]=ja;d[220]=v;d[221]=v;d[222]=v;d[223]=v;for(let t=224;t<=243;t++)d[t]=fn("simple values are not supported");d[244]=v;d[245]=v;d[246]=v;d[247]=Wa;d[248]=fn("simple values are not supported");d[249]=Ga;d[250]=Ha;d[251]=Qa;d[252]=v;d[253]=v;d[254]=v;d[255]=qa;var pe=[];for(let t=0;t<24;t++)pe[t]=new m(c.uint,t,1);for(let t=-1;t>=-24;t--)pe[31-t]=new m(c.negint,t,1);pe[64]=new m(c.bytes,new Uint8Array(0),1);pe[96]=new m(c.string,"",1);pe[128]=new m(c.array,0,1);pe[160]=new m(c.map,0,1);pe[244]=new m(c.false,!1,1);pe[245]=new m(c.true,!0,1);pe[246]=new m(c.null,null,1);function ms(t){switch(t.type){case c.false:return Ee([244]);case c.true:return Ee([245]);case c.null:return Ee([246]);case c.bytes:return t.value.length?void 0:Ee([64]);case c.string:return t.value===""?Ee([96]):void 0;case c.array:return t.value===0?Ee([128]):void 0;case c.map:return t.value===0?Ee([160]):void 0;case c.uint:return t.value<24?Ee([Number(t.value)]):void 0;case c.negint:if(t.value>=-24)return Ee([31-Number(t.value)])}}var zl={float64:!1,mapSorter:Wl,quickEncodeToken:ms},nc=Object.freeze({mapSorter:ql,quickEncodeToken:ms});function Vl(){let t=[];return t[c.uint.major]=se,t[c.negint.major]=on,t[c.bytes.major]=It,t[c.string.major]=Ia,t[c.array.major]=an,t[c.map.major]=cn,t[c.tag.major]=un,t[c.float.major]=ir,t}var Dt=Vl(),ln=new rr,cr=class t{constructor(e,r){this.obj=e,this.parent=r}includes(e){let r=this;do if(r.obj===e)return!0;while(r=r.parent);return!1}static createCheck(e,r){if(e&&e.includes(r))throw new Error(`${nn} object contains circular references`);return new t(r,e)}},ze={null:new m(c.null,null),undefined:new m(c.undefined,void 0),true:new m(c.true,!0),false:new m(c.false,!1),emptyArray:new m(c.array,0),emptyMap:new m(c.map,0)},_e={number(t,e,r,n){return!Number.isInteger(t)||!Number.isSafeInteger(t)?new m(c.float,t):t>=0?new m(c.uint,t):new m(c.negint,t)},bigint(t,e,r,n){return t>=BigInt(0)?new m(c.uint,t):new m(c.negint,t)},Uint8Array(t,e,r,n){return new m(c.bytes,t)},string(t,e,r,n){return new m(c.string,t)},boolean(t,e,r,n){return t?ze.true:ze.false},null(t,e,r,n){return ze.null},undefined(t,e,r,n){return ze.undefined},ArrayBuffer(t,e,r,n){return new m(c.bytes,new Uint8Array(t))},DataView(t,e,r,n){return new m(c.bytes,new Uint8Array(t.buffer,t.byteOffset,t.byteLength))},Array(t,e,r,n){if(!t.length)return r.addBreakTokens===!0?[ze.emptyArray,new m(c.break)]:ze.emptyArray;n=cr.createCheck(n,t);let o=[],s=0;for(let i of t)o[s++]=At(i,r,n);return r.addBreakTokens?[new m(c.array,t.length),o,new m(c.break)]:[new m(c.array,t.length),o]},Object(t,e,r,n){let o=e!=="Object",s=o?t.keys():Object.keys(t),i=o?t.size:s.length,a;if(i){a=new Array(i),n=cr.createCheck(n,t);let u=!o&&r.ignoreUndefinedProperties,l=0;for(let f of s){let h=o?t.get(f):t[f];u&&h===void 0||(a[l++]=[At(f,r,n),At(h,r,n)])}l<i&&(a.length=l)}return a?.length?(jl(a,r),r.addBreakTokens?[new m(c.map,a.length),a,new m(c.break)]:[new m(c.map,a.length),a]):r.addBreakTokens===!0?[ze.emptyMap,new m(c.break)]:ze.emptyMap},Tagged(t,e,r,n){return[new m(c.tag,t.tag),At(t.value,r,n)]}};_e.Map=_e.Object;_e.Buffer=_e.Uint8Array;for(let t of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))_e[`${t}Array`]=_e.DataView;function At(t,e={},r){let n=ss(t),o=e&&e.typeEncoders&&e.typeEncoders[n]||_e[n];if(typeof o=="function"){let i=o(t,n,e,r);if(i!=null)return i}let s=_e[n];if(!s)throw new Error(`${nn} unsupported type: ${n}`);return s(t,n,e,r)}function jl(t,e){e.mapSorter&&t.sort(e.mapSorter)}function Wl(t,e){let r=Array.isArray(t[0])?t[0][0]:t[0],n=Array.isArray(e[0])?e[0][0]:e[0];if(r.type!==n.type)return r.type.compare(n.type);let o=r.type.major,s=Dt[o].compareTokens(r,n);return s===0&&console.warn("WARNING: complex key types used, CBOR key sorting guarantees are gone"),s}function ql(t,e){if(t[0]instanceof m&&e[0]instanceof m){let r=t[0],n=e[0];return r._keyBytes||(r._keyBytes=Za(r.value)),n._keyBytes||(n._keyBytes=Za(n.value)),tn(r._keyBytes,n._keyBytes)}throw new Error("rfc8949MapSorter: complex key types are not supported yet")}function Za(t){return sc(t,Dt,nc)}function ar(t,e,r,n){if(Array.isArray(e))for(let o of e)ar(t,o,r,n);else r[e.type.major](t,e,n)}var ec=c.uint.majorEncoded,tc=c.negint.majorEncoded,Gl=c.bytes.majorEncoded,Hl=c.string.majorEncoded,rc=c.array.majorEncoded,Ql=c.float.majorEncoded|as,Xl=c.float.majorEncoded|cs,Kl=c.float.majorEncoded|us,Jl=c.float.majorEncoded|fs,Yl=BigInt(-1),Zl=BigInt(1);function eh(t){return t.addBreakTokens!==!0}function oc(t,e,r,n){let o=ss(e),s=r.typeEncoders&&r.typeEncoders[o];if(s){let i=s(e,o,r,n);if(i!=null){ar(t,i,Dt,r);return}}switch(o){case"null":t.push([Kl]);return;case"undefined":t.push([Jl]);return;case"boolean":t.push([e?Xl:Ql]);return;case"number":!Number.isInteger(e)||!Number.isSafeInteger(e)?ir(t,new m(c.float,e),r):e>=0?A(t,ec,e):A(t,tc,e*-1-1);return;case"bigint":e>=BigInt(0)?A(t,ec,e):A(t,tc,e*Yl-Zl);return;case"string":{let i=en(e);A(t,Hl,i.length),t.push(i);return}case"Uint8Array":A(t,Gl,e.length),t.push(e);return;case"Array":if(!e.length){t.push([rc]);return}n=cr.createCheck(n,e),A(t,rc,e.length);for(let i of e)oc(t,i,r,n);return;case"Object":case"Map":{let i=_e.Object(e,o,r,n);ar(t,i,Dt,r)}return;default:{let i=_e[o];if(!i)throw new Error(`${nn} unsupported type: ${o}`);let a=i(e,o,r,n);ar(t,a,Dt,r)}}}function sc(t,e,r,n){let o=n instanceof Uint8Array,s=o?new rn(n):ln,i=At(t,r);if(!Array.isArray(i)&&r.quickEncodeToken){let a=r.quickEncodeToken(i);if(a)return o?(s.push(a),s.toBytes()):a;let u=e[i.type.major];if(u.encodedSize){let l=u.encodedSize(i,r);if(o||(s=new rr(l)),u(s,i,r),s.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${i} was wrong`);return o?s.toBytes():tr(s.chunks[0])}}return s.reset(),ar(s,i,e,r),s.toBytes(!0)}function ps(t,e){return e=Object.assign({},zl,e),eh(e)?(ln.reset(),oc(ln,t,e,void 0),ln.toBytes(!0)):sc(t,Dt,e)}var th={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},hn=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=pe[e];if(r===void 0){let n=d[e];if(!n)throw new Error(`${g} 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}},Ve=Symbol.for("DONE"),kt=Symbol.for("BREAK");function rh(t,e,r){let n=[];for(let o=0;o<t.value;o++){let s=je(e,r);if(s===kt){if(t.value===1/0)break;throw new Error(`${g} got unexpected break to lengthed array`)}if(s===Ve)throw new Error(`${g} found array but not enough entries (got ${o}, expected ${t.value})`);n[o]=s}return n}function nh(t,e,r){let n=r.useMaps===!0,o=r.rejectDuplicateMapKeys===!0,s=n?void 0:{},i=n?new Map:void 0;for(let a=0;a<t.value;a++){let u=je(e,r);if(u===kt){if(t.value===1/0)break;throw new Error(`${g} got unexpected break to lengthed map`)}if(u===Ve)throw new Error(`${g} found map but not enough entries (got ${a} [no key], expected ${t.value})`);if(!n&&typeof u!="string")throw new Error(`${g} non-string keys not supported (got ${typeof u})`);if(o&&(n&&i.has(u)||!n&&Object.hasOwn(s,u)))throw new Error(`${g} found repeat map key "${u}"`);let l=je(e,r);if(l===Ve)throw new Error(`${g} found map but not enough entries (got ${a} [no value], expected ${t.value})`);n?i.set(u,l):s[u]=l}return n?i:s}function*oh(t,e,r){for(let n=0;n<t.value;n++){let o=je(e,r);if(o===kt){if(t.value===1/0)break;throw new Error(`${g} got unexpected break to lengthed map`)}if(o===Ve)throw new Error(`${g} found map but not enough entries (got ${n} [no key], expected ${t.value})`);let s=je(e,r);if(s===Ve)throw new Error(`${g} found map but not enough entries (got ${n} [no value], expected ${t.value})`);yield[o,s]}}function sh(t,e){let r=!1,n=function(){if(r)throw new Error(`${g} tag decode() may only be called once`);r=!0;let o=je(t,e);if(o===Ve)throw new Error(`${g} tag content missing`);if(o===kt)throw new Error(`${g} got unexpected break in tag content`);return o};return n.entries=function(){if(r)throw new Error(`${g} tag decode() may only be called once`);r=!0;let o=t.next();if(!c.equals(o.type,c.map))throw new Error(`${g} entries() requires map content, got ${o.type.name}`);let s=[];for(let i of oh(o,t,e))s.push(i);return s},Object.defineProperty(n,"_called",{get(){return r},enumerable:!1}),n}function je(t,e){if(t.done())return Ve;let r=t.next();if(c.equals(r.type,c.break))return kt;if(r.type.terminal)return r.value;if(c.equals(r.type,c.array))return rh(r,t,e);if(c.equals(r.type,c.map))return nh(r,t,e);if(c.equals(r.type,c.tag)){if(e.tags&&typeof e.tags[r.value]=="function"){let n=sh(t,e),o=e.tags[r.value](n);if(!n._called)throw new Error(`${g} tag decoder must call decode() or entries()`);return o}throw new Error(`${g} tag not supported (${r.value})`)}throw new Error("unsupported")}function ic(t,e){if(!(t instanceof Uint8Array))throw new Error(`${g} data to decode must be a Uint8Array`);e=Object.assign({},th,e);let r=tr(t),n=e.tokenizer||new hn(r,e),o=je(n,e);if(o===Ve)throw new Error(`${g} did not find any content to decode`);if(o===kt)throw new Error(`${g} got unexpected break`);return[o,t.subarray(n.pos())]}function gs(t,e){let[r,n]=ic(t,e);if(n.length>0)throw new Error(`${g} too many terminals, data makes no sense`);return r}var dn=class t{constructor(e,r){if(typeof e!="number"||!Number.isInteger(e)||e<0)throw new TypeError("Tagged: tag must be a non-negative integer");this.tag=e,this.value=r}static decoder(e){return r=>new t(e,r())}static preserve(...e){let r={};for(let n of e)r[n]=t.decoder(n);return r}};Object.defineProperty(dn.prototype,Symbol.toStringTag,{value:"Tagged"});var mn=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},Pt=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},pn=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"},ur=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};function gn(t){return t[Symbol.asyncIterator]!=null}function ac(t,e){if(t.byteLength>e)throw new Pt("Message length too long")}var yn=t=>{let e=V(t),r=K(e);return Dr(t,r),yn.bytes=e,r};yn.bytes=0;function xn(t,e){e=e??{};let r=e.lengthEncoder??yn,n=e?.maxDataLength??4194304;function*o(s){ac(s,n);let i=r(s.byteLength);i instanceof Uint8Array?yield i:yield*i,s instanceof Uint8Array?yield s:yield*s}return gn(t)?(async function*(){for await(let s of t)yield*o(s)})():(function*(){for(let s of t)yield*o(s)})()}xn.single=(t,e)=>{e=e??{};let r=e.lengthEncoder??yn,n=e?.maxDataLength??4194304;return ac(t,n),new k(r(t.byteLength),t)};var nt;(function(t){t[t.LENGTH=0]="LENGTH",t[t.DATA=1]="DATA"})(nt||(nt={}));var bs=t=>{let e=Ie(t);return bs.bytes=V(e),e};bs.bytes=0;function fr(t,e){let r=new k,n=nt.LENGTH,o=-1,s=e?.lengthDecoder??bs,i=e?.maxLengthLength??8,a=e?.maxDataLength??4194304;function*u(){for(;r.byteLength>0;){if(n===nt.LENGTH)try{if(o=s(r),o<0)throw new mn("Invalid message length");if(o>a)throw new Pt("Message length too long");let l=s.bytes;r.consume(l),e?.onLength!=null&&e.onLength(o),n=nt.DATA}catch(l){if(l instanceof RangeError){if(r.byteLength>i)throw new pn("Message length length too long");break}throw l}if(n===nt.DATA){if(r.byteLength<o)break;let l=r.sublist(0,o);r.consume(o),e?.onData!=null&&e.onData(l),yield l,n=nt.LENGTH}}}return gn(t)?(async function*(){for await(let l of t)r.append(l),yield*u();if(r.byteLength>0)throw new ur("Unexpected end of input")})():(function*(){for(let l of t)r.append(l),yield*u();if(r.byteLength>0)throw new ur("Unexpected end of input")})()}fr.fromReader=(t,e)=>{let r=1,n=(async function*(){for(;;)try{let{done:s,value:i}=await t.next(r);if(s===!0)return;i!=null&&(yield i)}catch(s){if(s.code==="ERR_UNDER_READ")return{done:!0,value:null};throw s}finally{r=1}})();return fr(n,{...e??{},onLength:s=>{r=s}})};var ys=class extends et{sendMessage;dataQueue;encoding;constructor(e){super(e),this.sendMessage=e.sendMessage,this.encoding=e.encoding,this.dataQueue=new de({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()}},cc=30,xs=class extends Yt{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)+cc,this.encoding=r.encoding??"base64",this.input=we(),this.sendMessage=this.sendMessage.bind(this),this.nextStreamId=this.maConn.direction==="outbound"?0:1,Promise.resolve().then(async()=>{for await(let n of fr(this.input,{maxDataLength:this.maxMessageSize}))this.onMessage(gs(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=ps(e),n=xn.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 ys({...this.streamOptions,...n,id:e,direction:r,log:this.log.newScope(`stream:${r}:${e}`),sendMessage:this.sendMessage,encoding:this.encoding,maxMessageSize:this.maxMessageSize-cc,protocol:""})}},ws=class{protocol="/mock-muxer/1.0.0";init;constructor(e){this.init=e}createStreamMuxer(e){return new xs(e,{...this.init})}};function wn(t={}){return new ws(t)}function En(t,e){if(typeof t=="string")return uh(t);if(typeof t=="number")return hh(t,e);throw new Error(`Value provided to ms() must be a string or number. value=${JSON.stringify(t)}`)}function uh(t){if(typeof t!="string"||t.length===0||t.length>100)throw new Error(`Value provided to ms.parse() must be a string with length between 1 and 99. value=${JSON.stringify(t)}`);let e=/^(?<value>-?\d*\.?\d+) *(?<unit>milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|months?|mo|years?|yrs?|y)?$/i.exec(t);if(!e?.groups)return NaN;let{value:r,unit:n="ms"}=e.groups,o=parseFloat(r),s=n.toLowerCase();switch(s){case"years":case"year":case"yrs":case"yr":case"y":return o*315576e5;case"months":case"month":case"mo":return o*26298e5;case"weeks":case"week":case"w":return o*6048e5;case"days":case"day":case"d":return o*864e5;case"hours":case"hour":case"hrs":case"hr":case"h":return o*36e5;case"minutes":case"minute":case"mins":case"min":case"m":return o*6e4;case"seconds":case"second":case"secs":case"sec":case"s":return o*1e3;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return o;default:throw new Error(`Unknown unit "${s}" provided to ms.parse(). value=${JSON.stringify(t)}`)}}function fh(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 lh(t){let e=Math.abs(t);return e>=315576e5?ot(t,e,315576e5,"year"):e>=26298e5?ot(t,e,26298e5,"month"):e>=6048e5?ot(t,e,6048e5,"week"):e>=864e5?ot(t,e,864e5,"day"):e>=36e5?ot(t,e,36e5,"hour"):e>=6e4?ot(t,e,6e4,"minute"):e>=1e3?ot(t,e,1e3,"second"):`${t} ms`}function hh(t,e){if(typeof t!="number"||!Number.isFinite(t))throw new Error("Value provided to ms.format() must be of type number.");return e?.long?lh(t):fh(t)}function ot(t,e,r,n){let o=e>=r*1.5;return`${Math.round(t/r)} ${n}${o?"s":""}`}function Es(t){r.debug=r,r.default=r,r.coerce=u,r.disable=s,r.enable=o,r.enabled=i,r.humanize=En,r.destroy=l,Object.keys(t).forEach(f=>{r[f]=t[f]}),r.names=[],r.skips=[],r.formatters={};function e(f){let h=0;for(let p=0;p<f.length;p++)h=(h<<5)-h+f.charCodeAt(p),h|=0;return r.colors[Math.abs(h)%r.colors.length]}r.selectColor=e;function r(f,h){let p,x=null,ae,W;function w(...y){if(!w.enabled)return;let I=w,P=Number(new Date),q=P-(p||P);I.diff=q,I.prev=p,I.curr=P,p=P,y[0]=r.coerce(y[0]),typeof y[0]!="string"&&y.unshift("%O");let O=0;y[0]=y[0].replace(/%([a-zA-Z%])/g,($,te)=>{if($==="%%")return"%";O++;let ue=r.formatters[te];if(typeof ue=="function"){let Q=y[O];$=ue.call(I,Q),y.splice(O,1),O--}return $}),r.formatArgs.call(I,y),h?.onLog!=null&&h.onLog(...y),(I.log||r.log).apply(I,y)}return w.namespace=f,w.useColors=r.useColors(),w.color=r.selectColor(f),w.extend=n,w.destroy=r.destroy,Object.defineProperty(w,"enabled",{enumerable:!0,configurable:!1,get:()=>x!==null?x:(ae!==r.namespaces&&(ae=r.namespaces,W=r.enabled(f)),W),set:y=>{x=y}}),typeof r.init=="function"&&r.init(w),w}function n(f,h){let p=r(this.namespace+(typeof h>"u"?":":h)+f);return p.log=this.log,p}function o(f){r.save(f),r.namespaces=f,r.names=[],r.skips=[];let h,p=(typeof f=="string"?f:"").split(/[\s,]+/),x=p.length;for(h=0;h<x;h++)p[h]&&(f=p[h].replace(/\*/g,".*?"),f[0]==="-"?r.skips.push(new RegExp("^"+f.substr(1)+"$")):r.names.push(new RegExp("^"+f+"$")))}function s(){let f=[...r.names.map(a),...r.skips.map(a).map(h=>"-"+h)].join(",");return r.enable(""),f}function i(f){if(f[f.length-1]==="*")return!0;let h,p;for(h=0,p=r.skips.length;h<p;h++)if(r.skips[h].test(f))return!1;for(h=0,p=r.names.length;h<p;h++)if(r.names[h].test(f))return!0;return!1}function a(f){return f.toString().substring(2,f.toString().length-2).replace(/\.\*\?$/,"*")}function u(f){return f instanceof Error?f.stack??f.message:f}function l(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")}return r.setupFormatters(r.formatters),r.enable(r.load()),r}var _n=xh(),dh=["#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 mh(){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 ph(t){if(t[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+t[0]+(this.useColors?"%c ":" ")+"+"+En(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 gh=console.debug??console.log??(()=>{});function bh(t){try{t?_n?.setItem("debug",t):_n?.removeItem("debug")}catch{}}function yh(){let t;try{t=_n?.getItem("debug")}catch{}return!t&&typeof globalThis.process<"u"&&"env"in globalThis.process&&(t=globalThis.process.env.DEBUG),t}function xh(){try{return localStorage}catch{}}function wh(t){t.j=function(e){try{return JSON.stringify(e)}catch(r){return"[UnexpectedJSONParseError]: "+r.message}}}var uc=Es({formatArgs:ph,save:bh,load:yh,useColors:mh,setupFormatters:wh,colors:dh,storage:_n,log:gh});var H=uc;H.formatters.b=t=>t==null?"undefined":ne.baseEncode(t);H.formatters.t=t=>t==null?"undefined":ge.baseEncode(t);H.formatters.m=t=>t==null?"undefined":On.baseEncode(t);H.formatters.p=t=>t==null?"undefined":t.toString();H.formatters.c=t=>t==null?"undefined":t.toString();H.formatters.k=t=>t==null?"undefined":t.toString();H.formatters.a=t=>t==null?"undefined":t.toString();function fc(t,e=""){let r=lc(t.message),n=lc(t.stack);return r!=null&&n!=null?n.includes(r)?`${n.split(`
3
3
  `).join(`
4
4
  ${e}`)}`:`${r}
5
5
  ${e}${n.split(`
6
6
  `).join(`
7
7
  ${e}`)}`:n!=null?`${n.split(`
8
8
  `).join(`
9
- ${e}`)}`:r!=null?`${r}`:`${t.toString()}`}function yh(t){return t instanceof AggregateError||t?.name==="AggregateError"&&Array.isArray(t.errors)}function cc(t,e=""){if(yh(t)){let r=ic(t,e);return t.errors.length>0?(e=`${e} `,r+=`
10
- ${e}${t.errors.map(n=>`${cc(n,`${e}`)}`).join(`
9
+ ${e}`)}`:r!=null?`${r}`:`${t.toString()}`}function Eh(t){return t instanceof AggregateError||t?.name==="AggregateError"&&Array.isArray(t.errors)}function hc(t,e=""){if(Eh(t)){let r=fc(t,e);return t.errors.length>0?(e=`${e} `,r+=`
10
+ ${e}${t.errors.map(n=>`${hc(n,`${e}`)}`).join(`
11
11
  ${e}`)}`):r+=`
12
- ${e}[Error list was empty]`,r.trim()}return ic(t,e)}Q.formatters.e=t=>t==null?"undefined":cc(t);function xh(t){let e=()=>{};return e.enabled=!1,e.color="",e.diff=0,e.log=()=>{},e.namespace=t,e.destroy=()=>!0,e.extend=()=>e,e.useColors=()=>!1,e}function ur(t){return{forComponent(e){return uc(e,t)}}}function uc(t,e){let r=xh(`${t}:trace`);return Q.enabled(`${t}:trace`)&&Q.names.map(n=>n.toString()).find(n=>n.includes(":trace"))!=null&&(r=Q(`${t}:trace`,e)),Object.assign(Q(t,e),{error:Q(`${t}:error`,e),trace:r,newScope:n=>uc(`${t}:${n}`,e)})}function ac(t){if(t!=null&&(t=t.trim(),t.length!==0))return t}var wh=0,xs=class extends Ye{local;remote;constructor(e){let r=`${wh++}`;super({...e,id:r,log:ur().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 de(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 fc=Symbol.for("sindresorhus/unlimited-timeout#brand");function lc(t,e,...r){if(typeof t!="function")throw new TypeError("Expected callback to be a function");e??=0,e=Number(e);let n=!1,o={[fc]:!0,id:void 0,cleared:!1,ref(){return n=!1,o.id?.ref?.(),o},unref(){return n=!0,o.id?.unref?.(),o}};if(e===Number.POSITIVE_INFINITY||e>Number.MAX_SAFE_INTEGER)return o;(!Number.isFinite(e)||e<0)&&(e=0);let s=performance.now()+e,i=a=>{o.cleared||(a<=2147483647?(o.id=globalThis.setTimeout(()=>{o.cleared||t(...r)},a),n&&o.id?.unref?.()):(o.id=globalThis.setTimeout(()=>{let u=performance.now(),l=Math.max(0,s-u);i(l)},2147483647),n&&o.id?.unref?.()))};return i(e),o}function hc(t){!t||typeof t!="object"||!t[fc]||(t.cleared=!0,t.id!==void 0&&(globalThis.clearTimeout(t.id),t.id=void 0))}var Eh=new WeakMap;function _h({clearTimeout:t,setTimeout:e}={}){return(r,{value:n,signal:o}={})=>{if(o?.aborted)return Promise.reject(o.reason);let s,i,a,u=t??clearTimeout,l=()=>{u(s),a(o.reason)},f=()=>{o&&o.removeEventListener("abort",l)},h=new Promise((p,x)=>{i=()=>{f(),p(n)},a=x,s=(e??setTimeout)(i,r)});return o&&o.addEventListener("abort",l,{once:!0}),Eh.set(h,()=>{u(s),s=null,i()}),h}}var vh=_h({setTimeout:lc,clearTimeout:hc}),ws=vh;var Sh=1024*64,fr=class extends me{needsDrain;queue;capacity;delay;log;chunkSize;constructor(e){super(),this.needsDrain=!1,this.queue=new ue({concurrency:1}),this.capacity=e.capacity??5,this.delay=e.delay??0,this.log=e.log,this.chunkSize=e.chunkSize??Sh,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(Ch(e)){let r=new N(e.data);for(;r.byteLength>0;){let n=Math.min(this.chunkSize,r.byteLength),o=r.sublist(0,n);r.consume(o.byteLength);let s=new de(o);this.queue.add(async i=>{this.delay>0&&await O(ws(this.delay),i.signal),this.dispatchEvent(i.evt)},{evt:s})}}else this.queue.add(async r=>{this.delay>0&&await O(ws(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 Ch(t){return t?.data instanceof Uint8Array||nt(t?.data)}var dc=0,wn=class extends Xt{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 de(e));return{sentBytes:e.byteLength,canSendMore:r}}sendReset(){this.local.send(new Event("reset"))}async sendClose(e){return this.local.needsDrain&&await U(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 Es(t={}){let e=`${dc++}`,r=`${dc++}`,n=ur().forComponent(`libp2p:mock-maconn:outbound:${e}`),o=ur().forComponent(`libp2p:mock-maconn:inbound:${r}`),s=new fr({...t,log:n}),i=new fr({...t,log:o});return[new wn({...t.outbound,id:r,direction:"outbound",local:s,remote:i,remoteAddr:t?.outbound?.remoteAddr??Me(`/ip4/127.0.0.1/tcp/${r}`),log:n}),new wn({...t.inbound,id:e,direction:"inbound",local:i,remote:s,remoteAddr:t?.inbound?.remoteAddr??Me(`/ip4/127.0.0.1/tcp/${e}`),log:o})]}var _s=class extends ue{has(e){return this.find(e)!=null}find(e){return this.queue.find(r=>e.equals(r.options.peerId))}};var vs=class extends ue{constructor(e={}){super({...e,sort:(r,n)=>r.options.priority>n.options.priority?-1:r.options.priority<n.options.priority?1:0})}};var Ss=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 En}consume(e,r=1,n={}){let o=this.getKey(e),s=this._getKeySecDuration(n),i=this.memoryStorage.incrby(o,r,s);if(i.remainingPoints=Math.max(this.points-i.consumedPoints,0),i.consumedPoints>this.points)throw this.blockDuration>0&&i.consumedPoints<=this.points+r&&(i=this.memoryStorage.set(o,i.consumedPoints,this.blockDuration)),new qt("Rate limit exceeded",i);return i}penalty(e,r=1,n={}){let o=this.getKey(e),s=this._getKeySecDuration(n),i=this.memoryStorage.incrby(o,r,s);return i.remainingPoints=Math.max(this.points-i.consumedPoints,0),i}reward(e,r=1,n={}){let o=this.getKey(e),s=this._getKeySecDuration(n),i=this.memoryStorage.incrby(o,-r,s);return i.remainingPoints=Math.max(this.points-i.consumedPoints,0),i}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)}},En=class{storage;constructor(){this.storage=new Map}incrby(e,r,n){let o=this.storage.get(e);if(o!=null){let s=o.expiresAt!=null?o.expiresAt.getTime()-new Date().getTime():-1;return o.expiresAt==null||s>0?(o.value+=r,{remainingPoints:0,msBeforeNext:s,consumedPoints:o.value,isFirstInDuration:!1}):this.set(e,r,n)}return this.set(e,r,n)}set(e,r,n){let o=n*1e3,s=this.storage.get(e);s!=null&&clearTimeout(s.timeoutId);let i={value:r,expiresAt:o>0?new Date(Date.now()+o):void 0};return this.storage.set(e,i),o>0&&(i.timeoutId=setTimeout(()=>{this.storage.delete(e)},o),i.timeoutId.unref!=null&&i.timeoutId.unref()),{remainingPoints:0,msBeforeNext:o===0?-1:o,consumedPoints:i.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 Ih(t,e,r){let n,o,s=!1;function i(){let l={signal:o.signal},f;r?.timeout!=null&&(f=Hr([o.signal,AbortSignal.timeout(r.timeout)]),l.signal=f),s=!0,Promise.resolve().then(async()=>{await t(l)}).catch(()=>{}).finally(()=>{f!=null&&(f.aborted?f.clear():f.addEventListener("abort",()=>{f.clear()},{once:!0})),s=!1,!o.signal.aborted&&(n=setTimeout(i,e))})}let a=_t(i,r?.debounce??100),u=!1;return{setInterval:l=>{e!==l&&(e=l,n!=null&&(clearTimeout(n),n=setTimeout(i,e)))},setTimeout:l=>{r??={},r.timeout=l},run:()=>{s||(clearTimeout(n),a())},start:()=>{u||(u=!0,o=new AbortController,o.signal,r?.runImmediately===!0?queueMicrotask(()=>{i()}):n=setTimeout(i,e))},stop:()=>{clearTimeout(n),o?.abort(),u=!1}}}async function mc(t={}){let[e,r]=Es({...t,outbound:t.outboundConnection,inbound:t.inboundConnection}),n=bn({streamOptions:t.outbound}).createStreamMuxer(e),o=bn({streamOptions:t.inbound}).createStreamMuxer(r),[s,i]=await Promise.all([U(o,"stream").then(a=>a.detail),n.createStream({...t.outbound,protocol:t.protocol})]);return[i,s]}async function Lh(t={}){let[e,r]=await mc(t);return es(r),e}function Th(t){let{name:e,metrics:r}=t,n=[];return r?.registerMetric(e,{calculate:()=>n.length}),n}var Cs=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 Ah(t){let{name:e,metrics:r}=t,n;return r!=null?n=new Cs({name:e,metrics:r}):n=new Map,n}return _c(Dh);})();
12
+ ${e}[Error list was empty]`,r.trim()}return fc(t,e)}H.formatters.e=t=>t==null?"undefined":hc(t);function _h(t){let e=()=>{};return e.enabled=!1,e.color="",e.diff=0,e.log=()=>{},e.namespace=t,e.destroy=()=>!0,e.extend=()=>e,e.useColors=()=>!1,e}function lr(t){return{forComponent(e){return dc(e,t)}}}function dc(t,e){let r=_h(`${t}:trace`);return H.enabled(`${t}:trace`)&&H.names.map(n=>n.toString()).find(n=>n.includes(":trace"))!=null&&(r=H(`${t}:trace`,e)),Object.assign(H(t,e),{error:H(`${t}:error`,e),trace:r,newScope:n=>dc(`${t}:${n}`,e)})}function lc(t){if(t!=null&&(t=t.trim(),t.length!==0))return t}var vh=0,_s=class extends et{local;remote;constructor(e){let r=`${vh++}`;super({...e,id:r,log:lr().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 be(e));return{sentBytes:e.byteLength,canSendMore:r}}sendReset(){this.local.send(new Event("reset"))}async sendCloseWrite(e){return M(new Promise((r,n)=>{this.local.send(new Event("closeWrite")),this.local.onIdle().then(r,n)}),e?.signal)}async sendCloseRead(e){return M(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 mc=Symbol.for("sindresorhus/unlimited-timeout#brand");function pc(t,e,...r){if(typeof t!="function")throw new TypeError("Expected callback to be a function");e??=0,e=Number(e);let n=!1,o={[mc]:!0,id:void 0,cleared:!1,ref(){return n=!1,o.id?.ref?.(),o},unref(){return n=!0,o.id?.unref?.(),o}};if(e===Number.POSITIVE_INFINITY||e>Number.MAX_SAFE_INTEGER)return o;(!Number.isFinite(e)||e<0)&&(e=0);let s=performance.now()+e,i=a=>{o.cleared||(a<=2147483647?(o.id=globalThis.setTimeout(()=>{o.cleared||t(...r)},a),n&&o.id?.unref?.()):(o.id=globalThis.setTimeout(()=>{let u=performance.now(),l=Math.max(0,s-u);i(l)},2147483647),n&&o.id?.unref?.()))};return i(e),o}function gc(t){!t||typeof t!="object"||!t[mc]||(t.cleared=!0,t.id!==void 0&&(globalThis.clearTimeout(t.id),t.id=void 0))}var Sh=new WeakMap;function Ch({clearTimeout:t,setTimeout:e}={}){return(r,{value:n,signal:o}={})=>{if(o?.aborted)return Promise.reject(o.reason);let s,i,a,u=t??clearTimeout,l=()=>{u(s),a(o.reason)},f=()=>{o&&o.removeEventListener("abort",l)},h=new Promise((p,x)=>{i=()=>{f(),p(n)},a=x,s=(e??setTimeout)(i,r)});return o&&o.addEventListener("abort",l,{once:!0}),Sh.set(h,()=>{u(s),s=null,i()}),h}}var Ih=Ch({setTimeout:pc,clearTimeout:gc}),vs=Ih;var Lh=1024*64,hr=class extends ye{needsDrain;queue;capacity;delay;log;chunkSize;constructor(e){super(),this.needsDrain=!1,this.queue=new de({concurrency:1}),this.capacity=e.capacity??5,this.delay=e.delay??0,this.log=e.log,this.chunkSize=e.chunkSize??Lh,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(Th(e)){let r=new k(e.data);for(;r.byteLength>0;){let n=Math.min(this.chunkSize,r.byteLength),o=r.sublist(0,n);r.consume(o.byteLength);let s=new be(o);this.queue.add(async i=>{this.delay>0&&await M(vs(this.delay),i.signal),this.dispatchEvent(i.evt)},{evt:s})}}else this.queue.add(async r=>{this.delay>0&&await M(vs(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 Th(t){return t?.data instanceof Uint8Array||st(t?.data)}var bc=0,vn=class extends Jt{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 be(e));return{sentBytes:e.byteLength,canSendMore:r}}sendReset(){this.local.send(new Event("reset"))}async sendClose(e){return this.local.needsDrain&&await F(this.local,"drain",{signal:e?.signal}),M(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 Ss(t={}){let e=`${bc++}`,r=`${bc++}`,n=lr().forComponent(`libp2p:mock-maconn:outbound:${e}`),o=lr().forComponent(`libp2p:mock-maconn:inbound:${r}`),s=new hr({...t,log:n}),i=new hr({...t,log:o});return[new vn({...t.outbound,id:r,direction:"outbound",local:s,remote:i,remoteAddr:t?.outbound?.remoteAddr??Re(`/ip4/127.0.0.1/tcp/${r}`),log:n}),new vn({...t.inbound,id:e,direction:"inbound",local:i,remote:s,remoteAddr:t?.inbound?.remoteAddr??Re(`/ip4/127.0.0.1/tcp/${e}`),log:o})]}var Cs=class extends de{has(e){return this.find(e)!=null}find(e){return this.queue.find(r=>e.equals(r.options.peerId))}};var Is=class extends de{constructor(e={}){super({...e,sort:(r,n)=>r.options.priority>n.options.priority?-1:r.options.priority<n.options.priority?1:0})}};var Ls=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 Sn}consume(e,r=1,n={}){let o=this.getKey(e),s=this._getKeySecDuration(n),i=this.memoryStorage.incrby(o,r,s);if(i.remainingPoints=Math.max(this.points-i.consumedPoints,0),i.consumedPoints>this.points)throw this.blockDuration>0&&i.consumedPoints<=this.points+r&&(i=this.memoryStorage.set(o,i.consumedPoints,this.blockDuration)),new Ht("Rate limit exceeded",i);return i}penalty(e,r=1,n={}){let o=this.getKey(e),s=this._getKeySecDuration(n),i=this.memoryStorage.incrby(o,r,s);return i.remainingPoints=Math.max(this.points-i.consumedPoints,0),i}reward(e,r=1,n={}){let o=this.getKey(e),s=this._getKeySecDuration(n),i=this.memoryStorage.incrby(o,-r,s);return i.remainingPoints=Math.max(this.points-i.consumedPoints,0),i}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)}},Sn=class{storage;constructor(){this.storage=new Map}incrby(e,r,n){let o=this.storage.get(e);if(o!=null){let s=o.expiresAt!=null?o.expiresAt.getTime()-new Date().getTime():-1;return o.expiresAt==null||s>0?(o.value+=r,{remainingPoints:0,msBeforeNext:s,consumedPoints:o.value,isFirstInDuration:!1}):this.set(e,r,n)}return this.set(e,r,n)}set(e,r,n){let o=n*1e3,s=this.storage.get(e);s!=null&&clearTimeout(s.timeoutId);let i={value:r,expiresAt:o>0?new Date(Date.now()+o):void 0};return this.storage.set(e,i),o>0&&(i.timeoutId=setTimeout(()=>{this.storage.delete(e)},o),i.timeoutId.unref!=null&&i.timeoutId.unref()),{remainingPoints:0,msBeforeNext:o===0?-1:o,consumedPoints:i.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 Ah(t,e,r){let n,o,s=!1;function i(){let l={signal:o.signal},f;r?.timeout!=null&&(f=Kr([o.signal,AbortSignal.timeout(r.timeout)]),l.signal=f),s=!0,Promise.resolve().then(async()=>{await t(l)}).catch(()=>{}).finally(()=>{f!=null&&(f.aborted?f.clear():f.addEventListener("abort",()=>{f.clear()},{once:!0})),s=!1,!o.signal.aborted&&(n=setTimeout(i,e))})}let a=St(i,r?.debounce??100),u=!1;return{setInterval:l=>{e!==l&&(e=l,n!=null&&(clearTimeout(n),n=setTimeout(i,e)))},setTimeout:l=>{r??={},r.timeout=l},run:()=>{s||(clearTimeout(n),a())},start:()=>{u||(u=!0,o=new AbortController,o.signal,r?.runImmediately===!0?queueMicrotask(()=>{i()}):n=setTimeout(i,e))},stop:()=>{clearTimeout(n),o?.abort(),u=!1}}}async function yc(t={}){let[e,r]=Ss({...t,outbound:t.outboundConnection,inbound:t.inboundConnection}),n=wn({streamOptions:t.outbound}).createStreamMuxer(e),o=wn({streamOptions:t.inbound}).createStreamMuxer(r),[s,i]=await Promise.all([F(o,"stream").then(a=>a.detail),n.createStream({...t.outbound,protocol:t.protocol})]);return[i,s]}async function Dh(t={}){let[e,r]=await yc(t);return ns(r),e}function kh(t){let{name:e,metrics:r}=t,n=[];return r?.registerMetric(e,{calculate:()=>n.length}),n}var Ts=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 Ph(t){let{name:e,metrics:r}=t,n;return r!=null?n=new Ts({name:e,metrics:r}):n=new Map,n}return Cc(Bh);})();
13
13
  return Libp2PUtils}));
14
14
  //# sourceMappingURL=index.min.js.map