@libp2p/utils 7.4.4 → 7.4.5-3c9142a7c

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 Tc=Object.create;var gr=Object.defineProperty;var Dc=Object.getOwnPropertyDescriptor;var kc=Object.getOwnPropertyNames;var Bc=Object.getPrototypeOf,Pc=Object.prototype.hasOwnProperty;var Bn=(t,e)=>()=>{try{return e||t((e={exports:{}}).exports,e),e.exports}catch(r){throw e=0,r}},J=(t,e)=>{for(var r in e)gr(t,r,{get:e[r],enumerable:!0})},Us=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of kc(e))!Pc.call(t,o)&&o!==r&&gr(t,o,{get:()=>e[o],enumerable:!(n=Dc(e,o))||n.enumerable});return t};var Mc=(t,e,r)=>(r=t!=null?Tc(Bc(t)):{},Us(e||!t||!t.__esModule?gr(r,"default",{value:t,enumerable:!0}):r,t)),Fc=t=>Us(gr({},"__esModule",{value:!0}),t);var ho=Bn(wt=>{"use strict";Object.defineProperty(wt,"__esModule",{value:!0});wt.Netmask4Impl=void 0;wt.ip2long=xt;wt.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 uf=48,ff=97,lf=65;function hf(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)-uf)>>>0;else if(r===16)if("a"<=t[o]&&t[o]<="f")e=e*r+(10+t.charCodeAt(o)-ff)>>>0;else if("A"<=t[o]&&t[o]<="F")e=e*r+(10+t.charCodeAt(o)-lf)>>>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 xt(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]=hf(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 lo=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=xt(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=(xt(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):(xt(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=xt(this.first),n=xt(this.last),o=0;for(;r<=n;)e(xe(r),r,o),o++,r++}toString(){return this.base+"/"+this.bitmask}};wt.Netmask4Impl=lo});var vi=Bn(Et=>{"use strict";Object.defineProperty(Et,"__esModule",{value:!0});Et.Netmask6Impl=void 0;Et.ip6bigint=po;Et.bigint2ip6=Ze;var df=ho(),mo=(1n<<128n)-1n;function po(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,df.ip2long)(n),s=t.substring(0,r+1)+"0:0";return _i(s)&~0xffffffffn|BigInt(o)}return _i(t)}function _i(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 Ze(t){if(t<0n||t>mo)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 go=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=mo>>BigInt(128-this.bitmask)<<BigInt(128-this.bitmask);try{this.netBigint=po(e)&this.maskBigint}catch{throw new Error("Invalid IPv6 net address: "+e)}this.size=Number(1n<<BigInt(128-this.bitmask)),this.base=Ze(this.netBigint),this.mask=Ze(this.maskBigint),this.hostmask=Ze(~this.maskBigint&mo),this.first=this.base,this.last=Ze(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):(po(e)&this.maskBigint)===this.netBigint}next(e=1){let r=1n<<BigInt(128-this.bitmask);return new t(Ze(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(Ze(r),Number(r),s),s++,r++}toString(){return this.base+"/"+this.bitmask}};Et.Netmask6Impl=go});var Si=Bn(Ue=>{"use strict";Object.defineProperty(Ue,"__esModule",{value:!0});Ue.long2ip=Ue.ip2long=Ue.Netmask=void 0;var Tr=ho();Object.defineProperty(Ue,"ip2long",{enumerable:!0,get:function(){return Tr.ip2long}});Object.defineProperty(Ue,"long2ip",{enumerable:!0,get:function(){return Tr.long2ip}});var mf=vi(),yo=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 mf.Netmask6Impl(e,r):this._impl=new Tr.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 Tr.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=yo});var Xh={};J(Xh,{AbstractMessageStream:()=>tt,AbstractMultiaddrConnection:()=>tr,AbstractStream:()=>rt,AbstractStreamMuxer:()=>rr,AdaptiveTimeout:()=>as,BloomFilter:()=>qt,CuckooFilter:()=>Pe,DEFAULT_FAILURE_MULTIPLIER:()=>ea,DEFAULT_INTERVAL:()=>na,DEFAULT_MAX_TIMEOUT:()=>ra,DEFAULT_MIN_TIMEOUT:()=>ta,DEFAULT_TIMEOUT_MULTIPLIER:()=>Yi,InvalidDataLengthError:()=>Yr,InvalidDataLengthLengthError:()=>en,InvalidMessageLengthError:()=>Tt,LengthPrefixedDecoder:()=>hs,MaxEarlyStreamsError:()=>Yt,MemoryStorage:()=>kn,MockStream:()=>Ds,MovingAverage:()=>nt,PeerQueue:()=>Ps,PriorityQueue:()=>Ms,Queue:()=>de,QueueFullError:()=>Zt,RateLimitError:()=>Jt,RateLimiter:()=>Fs,ScalableCuckooFilter:()=>Wt,StreamClosedError:()=>er,UnexpectedEOFError:()=>$e,UnwrappedError:()=>nr,byteStream:()=>la,circuitRelayAddressesLast:()=>Xi,createBloomFilter:()=>li,createCuckooFilter:()=>hi,createScalableCuckooFilter:()=>di,debounce:()=>At,defaultMultiaddrSorter:()=>il,echo:()=>ls,echoStream:()=>Gh,getNetConfig:()=>le,getThinWaistAddresses:()=>xl,ipPortToMultiaddr:()=>El,isAsyncGenerator:()=>_l,isGenerator:()=>vl,isGlobalUnicast:()=>sf,isGlobalUnicastIp:()=>wl,isLinkLocal:()=>af,isLinkLocalIp:()=>Rl,isLoopback:()=>Ar,isNetworkAddress:()=>cf,isPrivate:()=>Dr,isPrivateIp:()=>xo,isPromise:()=>is,loopbackAddressLast:()=>Hi,lpStream:()=>ha,messageStreamToDuplex:()=>da,mockMuxer:()=>Ln,multiaddrConnectionPair:()=>Bs,pbStream:()=>Ml,pipe:()=>Nl,publicAddressesFirst:()=>Qi,reliableTransportsFirst:()=>Gi,repeatingTask:()=>Wh,streamPair:()=>Ac,trackedList:()=>Hh,trackedMap:()=>Qh,tryGetNetConfig:()=>vr});function H(t=0){return new Uint8Array(t)}function Z(t=0){return new Uint8Array(t)}function Nc(t){return t?.buffer instanceof ArrayBuffer}function Pn(t){if(Nc(t))return t;let e=t.slice();return new Uint8Array(e.buffer,0,e.byteLength)}function Ce(t,e){e==null&&(e=t.reduce((o,s)=>o+s.length,0));let r=Z(e),n=0;for(let o of t)r.set(o,n),n+=o.length;return Pn(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 Rs=Symbol.for("@achingbrain/uint8arraylist");function Os(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 ut(t){return!!t?.[Rs]}var P=class t{bufs;length;[Rs]=!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(ut(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(ut(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=Os(this.bufs,e);return r.buf[r.index]}set(e,r){let n=Os(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(ut(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 Ce(n,o)}subarray(e,r){let{bufs:n,length:o}=this._subList(e,r);return n.length===1?n[0]:Ce(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 h=e>=a&&e<u,f=r>a&&r<=u;if(h&&f){if(e===a&&r===u){n.push(i);break}let l=e-a;n.push(i.subarray(l,l+(r-e)));break}if(h){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(!ut(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 l=0;l<s;l++)i[l]=-1;for(let l=0;l<o;l++)i[n[l]]=l;let a=i,u=this.byteLength-n.byteLength,h=n.byteLength-1,f;for(let l=r;l<=u;l+=f){f=0;for(let p=h;p>=0;p--){let E=this.get(l+p);if(n[p]!==E){f=Math.max(1,p-a[E]);break}}if(f===0)return l}return-1}getInt8(e){let r=this.subarray(e,e+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(e,r){let n=Z(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,r),this.write(n,e)}getInt16(e,r){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,r)}setInt16(e,r,n){let o=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=Z(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,r),this.write(n,e)}getUint16(e,r){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,r)}setUint16(e,r,n){let o=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(!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 On={};J(On,{base10:()=>qc});var ad=new Uint8Array(0);function zs(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 se(t){if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return Ge(t);if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return Ge(new Uint8Array(t.buffer,t.byteOffset,t.byteLength));throw new Error("Unknown type, must be binary type")}function Vs(t){let e=new Uint8Array(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}var $s=4096;function js(t){let e=t.length;if(e<=$s)return String.fromCharCode.apply(String,t);let r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.subarray(n,n+=$s));return r}function Uc(t){return t?.buffer instanceof ArrayBuffer}function Ge(t){return Uc(t)?t:t.slice()}function Oc(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),h=i.toUpperCase().charCodeAt(0);u!==a&&(n[u]=s),h!==a&&(n[h]=s)}}var f=t.length,l=t.charAt(0),p=Math.log(f)/Math.log(256),E=Math.log(256)/Math.log(f);function ne(b){if(b instanceof Uint8Array||(ArrayBuffer.isView(b)?b=new Uint8Array(b.buffer,b.byteOffset,b.byteLength):Array.isArray(b)&&(b=Uint8Array.from(b))),!(b instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(b.length===0)return"";for(var C=0,D=0,T=0,B=b.length;T!==B&&b[T]===0;)T++,C++;for(var X=(B-T)*E+1>>>0,V=new Uint8Array(X);T!==B;){for(var oe=b[T],ue=0,K=X-1;(oe!==0||ue<D)&&K!==-1;K--,ue++)oe+=256*V[K]>>>0,V[K]=oe%f>>>0,oe=oe/f>>>0;if(oe!==0)throw new Error("Non-zero carry");D=ue,T++}for(var Se=X-D;Se!==X&&V[Se]===0;)Se++;for(var pr=l.repeat(C);Se<X;++Se)pr+=t.charAt(V[Se]);return pr}function G(b){if(typeof b!="string")throw new TypeError("Expected String");if(b.length===0)return new Uint8Array;var C=0;if(b[C]!==" "){for(var D=0,T=0;b[C]===l;)D++,C++;for(var B=(b.length-C)*p+1>>>0,X=new Uint8Array(B);b[C];){var V=n[b.charCodeAt(C)];if(V===255)return;for(var oe=0,ue=B-1;(V!==0||oe<T)&&ue!==-1;ue--,oe++)V+=f*X[ue]>>>0,X[ue]=V%256>>>0,V=V/256>>>0;if(V!==0)throw new Error("Non-zero carry");T=oe,C++}if(b[C]!==" "){for(var K=B-T;K!==B&&X[K]===0;)K++;for(var Se=new Uint8Array(D+(B-K)),pr=D;K!==B;)Se[pr++]=X[K++];return Se}}}function x(b){var C=G(b);if(C)return C;throw new Error(`Non-${e} character`)}return{encode:ne,decodeUnsafe:G,decode:x}}var Rc=Oc,$c=Rc,Ws=$c;var Mn=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")}},Fn=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 Gs(this,e)}},Nn=class{decoders;constructor(e){this.decoders=e}or(e){return Gs(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 Gs(t,e){return new Nn({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var Un=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 Mn(e,r,n),this.decoder=new Fn(e,r,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function ft({name:t,prefix:e,encode:r,decode:n}){return new Un(t,e,r,n)}function ke({name:t,prefix:e,alphabet:r,caseInsensitive:n=!1}){let{encode:o,decode:s}=Ws(r,t,n);return ft({prefix:e,name:t,encode:o,decode:i=>se(s(i))})}function zc(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 h=0;h<o;++h){let f=e[t[h]];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 Vc(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 jc(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 k({name:t,prefix:e,bitsPerChar:r,alphabet:n,caseInsensitive:o=!1}){let s=jc(n,o);return ft({prefix:e,name:t,encode(i){return Vc(i,n,r)},decode(i){return zc(i,s,r,t)}})}var qc=ke({prefix:"9",name:"base10",alphabet:"0123456789"});var Rn={};J(Rn,{base16:()=>Wc,base16upper:()=>Gc});var Wc=k({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4,caseInsensitive:!0}),Gc=k({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4,caseInsensitive:!0});var $n={};J($n,{base2:()=>Hc});var Hc=k({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var zn={};J(zn,{base256emoji:()=>Zc});var Hs=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}"),Qc=Hs.reduce((t,e,r)=>(t[r]=e,t),[]),Xc=Hs.reduce((t,e,r)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return t[n]=r,t},[]);function Kc(t){return t.reduce((e,r)=>(e+=Qc[r],e),"")}function Jc(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=Xc[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(o)}return new Uint8Array(e)}var Zc=ft({prefix:"\u{1F680}",name:"base256emoji",encode:Kc,decode:Jc});var Vn={};J(Vn,{base32:()=>pe,base32hex:()=>ru,base32hexpad:()=>ou,base32hexpadupper:()=>su,base32hexupper:()=>nu,base32pad:()=>eu,base32padupper:()=>tu,base32upper:()=>Yc,base32z:()=>iu});var pe=k({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5,caseInsensitive:!0}),Yc=k({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5,caseInsensitive:!0}),eu=k({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5,caseInsensitive:!0}),tu=k({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5,caseInsensitive:!0}),ru=k({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5,caseInsensitive:!0}),nu=k({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5,caseInsensitive:!0}),ou=k({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5,caseInsensitive:!0}),su=k({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5,caseInsensitive:!0}),iu=k({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var jn={};J(jn,{base36:()=>Ot,base36upper:()=>au});var Ot=ke({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz",caseInsensitive:!0}),au=ke({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",caseInsensitive:!0});var qn={};J(qn,{base58btc:()=>ie,base58flickr:()=>cu});var ie=ke({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),cu=ke({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Hn={};J(Hn,{base64:()=>Wn,base64pad:()=>uu,base64url:()=>Gn,base64urlpad:()=>fu});var Wn=k({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),uu=k({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Gn=k({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),fu=k({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Qn={};J(Qn,{base8:()=>lu});var lu=k({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Xn={};J(Xn,{identity:()=>hu});var hu=ft({prefix:"\0",name:"identity",encode:t=>js(se(t)),decode:t=>se(Vs(t))});var vd=new TextEncoder,Sd=new TextDecoder;var Jn={};J(Jn,{identity:()=>Fu});var pu=Ks,Qs=128,gu=127,yu=~gu,bu=Math.pow(2,31);function Ks(t,e,r){e=e||[],r=r||0;for(var n=r;t>=bu;)e[r++]=t&255|Qs,t/=128;for(;t&yu;)e[r++]=t&255|Qs,t>>>=7;return e[r]=t|0,Ks.bytes=r-n+1,e}var xu=Kn,wu=128,Xs=127;function Kn(t,n){var r=0,n=n||0,o=0,s=n,i,a=t.length;do{if(s>=a)throw Kn.bytes=0,new RangeError("Could not decode varint");i=t[s++],r+=o<28?(i&Xs)<<o:(i&Xs)*Math.pow(2,o),o+=7}while(i>=wu);return Kn.bytes=s-n,r}var Eu=Math.pow(2,7),_u=Math.pow(2,14),vu=Math.pow(2,21),Su=Math.pow(2,28),Cu=Math.pow(2,35),Iu=Math.pow(2,42),Lu=Math.pow(2,49),Au=Math.pow(2,56),Tu=Math.pow(2,63),Du=function(t){return t<Eu?1:t<_u?2:t<vu?3:t<Su?4:t<Cu?5:t<Iu?6:t<Lu?7:t<Au?8:t<Tu?9:10},ku={encode:pu,decode:xu,encodingLength:Du},Bu=ku,Rt=Bu;function $t(t,e=0){let r=Rt.decode(t,e),n=Rt.decode.bytes;if(n>9)throw new RangeError("Invalid varint: too long");if(n>1&&t[e+n-1]===0)throw new RangeError("Invalid varint: not minimally encoded");return[r,n]}function lt(t,e,r=0){return Rt.encode(t,e,r),e}function ht(t){return Rt.encodingLength(t)}function mt(t,e){let r=e.byteLength,n=ht(t),o=n+ht(r),s=new Uint8Array(o+r);return lt(t,s,0),lt(r,s,n),s.set(e,o),new dt(t,r,e,s)}function Js(t){let e=se(t),[r,n]=$t(e),[o,s]=$t(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new dt(r,o,i,e)}function Zs(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&zs(t.bytes,r.bytes)}}var dt=class{code;size;digest;bytes;constructor(e,r,n,o){this.code=e,this.size=r,this.digest=Ge(n),this.bytes=Ge(o)}};var Ys=0,Pu="identity",ei=se;function Mu(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 mt(Ys,ei(t))}var Fu={code:Ys,name:Pu,encode:ei,digest:Mu};var eo={};J(eo,{sha256:()=>Uu,sha512:()=>Ou});var Nu=20;function Yn({name:t,code:e,encode:r,minDigestLength:n,maxDigestLength:o}){return new Zn(t,e,r,n,o)}var Zn=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,r,n,o,s){this.name=e,this.code=r,this.encode=n,this.minDigestLength=o??Nu,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?ti(n,this.code,r?.truncate):n.then(o=>ti(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function ti(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 mt(e,t)}function ni(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}var Uu=Yn({name:"sha2-256",code:18,encode:ni("SHA-256")}),Ou=Yn({name:"sha2-512",code:19,encode:ni("SHA-512")});function oi(t,e){let{bytes:r,version:n}=t;return n===0?$u(r,to(t),e??ie.encoder):zu(r,to(t),e??pe.encoder)}var si=new WeakMap;function to(t){let e=si.get(t);if(e==null){let r=new Map;return si.set(t,r),r}return e}var pt=class t{code;version;multihash;bytes;"/";constructor(e,r,n,o){this.code=r,this.version=e,this.multihash=n,this.bytes=Ge(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!==Vt)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Vu)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=mt(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&&Zs(e.multihash,n.multihash)}toString(e){return oi(this,e)}toJSON(){return{"/":oi(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??ii(n,o,s.bytes))}else if(r[ju]===!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!==Vt)throw new Error(`Version 0 CID must use dag-pb (code: ${Vt}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let o=ii(e,r,n.bytes);return new t(e,r,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,Vt,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=se(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 dt(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[l,p]=$t(e.subarray(r));return r+=p,l},o=n(),s=Vt;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(),h=r+u,f=h-i;return{version:o,codec:s,multihashCode:a,digestSize:u,multihashSize:f,size:h}}static parse(e,r){let[n,o]=Ru(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 to(s).set(n,e),s}};function Ru(t,e){switch(t[0]){case"Q":{let r=e??ie;return[ie.prefix,r.decode(`${ie.prefix}${t}`)]}case ie.prefix:{let r=e??ie;return[ie.prefix,r.decode(t)]}case pe.prefix:{let r=e??pe;return[pe.prefix,r.decode(t)]}case Ot.prefix:{let r=e??Ot;return[Ot.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 $u(t,e,r){let{prefix:n}=r;if(n!==ie.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 zu(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 Vt=112,Vu=18;function ii(t,e,r){let n=ht(t),o=n+ht(e),s=new Uint8Array(o+r.byteLength);return lt(t,s,0),lt(e,s,n),s.set(r,o),s}var ju=Symbol.for("@ipld/js-cid/CID");var jt={...Xn,...$n,...Qn,...On,...Rn,...Vn,...jn,...qn,...Hn,...zn},Gd={...eo,...Jn};function ci(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var ai=ci("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),ro=ci("ascii","a",t=>{let e="a";for(let r=0;r<t.length;r++)e+=String.fromCharCode(t[r]);return e},t=>{t=t.substring(1);let e=Z(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),qu={utf8:ai,"utf-8":ai,hex:jt.base16,latin1:ro,ascii:ro,binary:ro,...jt},br=qu;function M(t,e="utf8"){let r=br[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}var no={32:16777619n,64:1099511628211n,128:309485009821345068724781371n,256:374144419156711147060143317175368453031918731002211n,512:35835915874844867368919076489095108449946327955754392558399825615420669938882575126094039892345713852759n,1024:5016456510113118655434598811035278955030765345404790744303017523831112055108147451509157692220295382716162651878526895249385292291816524375083746691371804094271873160484737966720260389217684476157468082573n},ui={32:2166136261n,64:14695981039346656037n,128:144066263297769815596495629667062367629n,256:100029257958052580907070968620625704837092796014241193945225284501741471925557n,512:9659303129496669498009435400716310466090418745672637896108374329434462657994582932197716438449813051892206539805784495328239340083876191928701583869517785n,1024:14197795064947621068722070641403218320880622795441933960878474914617582723252296732303717722150864096521202355549365628174669108571814760471015076148029755969804077320157692458563003215304957150157403644460363550505412711285966361610267868082893823963790439336411086884584107735010676915n},fi=new globalThis.TextEncoder;function Wu(t,e){let r=no[e],n=ui[e];for(let o=0;o<t.length;o++)n^=BigInt(t[o]),n=BigInt.asUintN(e,n*r);return n}function Gu(t,e,r){if(r.length===0)throw new Error("The `utf8Buffer` option must have a length greater than zero");let n=no[e],o=ui[e],s=t;for(;s.length>0;){let i=fi.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 oo(t,{size:e=32,utf8Buffer:r}={}){if(!no[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 Gu(t,e,r);t=fi.encode(t)}return Wu(t,e)}var Be={hash:t=>Number(oo(t,{size:32})),hashV:(t,e)=>Hu(Be.hash(t,e))};function Hu(t){let e=t.toString(16);return e.length%2===1&&(e=`0${e}`),M(e,"base16")}var Qu=Math.LN2*Math.LN2,qt=class{seeds;bits;buffer;constructor(e={}){e.seeds!=null?this.seeds=e.seeds:this.seeds=Ku(e.hashes??8),this.bits=e.bits??1024,this.buffer=H(Math.ceil(this.bits/8))}add(e){typeof e=="string"&&(e=M(e));for(let r=0;r<this.seeds.length;r++){let o=Be.hash(e,this.seeds[r])%this.bits;this.setbit(o)}}has(e){typeof e=="string"&&(e=M(e));for(let r=0;r<this.seeds.length;r++){let o=Be.hash(e,this.seeds[r])%this.bits;if(!this.getbit(o))return!1}return!0}clear(){this.buffer.fill(0)}setbit(e){let r=Math.floor(e/8),n=e%8,o=this.buffer[r];o|=1<<n,this.buffer[r]=o}getbit(e){let r=Math.floor(e/8),n=e%8;return(this.buffer[r]&1<<n)!==0}};function li(t,e=.005){let r=Xu(t,e);return new qt(r)}function Xu(t,e=.005){let r=Math.round(-1*t*Math.log(e)/Qu),n=Math.round(r/t*Math.LN2);return{bits:r,hashes:n}}function Ku(t){let e,r,n=[];for(let o=0;o<t;o++)for(e=new P(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 so=64,fe=class{fp;h;seed;constructor(e,r,n,o=2){if(o>so)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?We(this.fp,e.fp):!1}};function He(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 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=He(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 Ju=500,Pe=class{bucketSize;filterSize;fingerprintSize;buckets;count;hash;seed;constructor(e){this.filterSize=e.filterSize,this.bucketSize=e.bucketSize??4,this.fingerprintSize=e.fingerprintSize??2,this.count=0,this.buckets=[],this.hash=e.hash??Be,this.seed=e.seed??He(0,Math.pow(2,10))}add(e){typeof e=="string"&&(e=M(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 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[He(0,s.length-1)];this.buckets[i]==null&&(this.buckets[i]=new Qe(this.bucketSize));for(let a=0;a<Ju;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=M(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=M(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}},Zu={1:.5,2:.84,4:.95,8:.98};function Yu(t=.001){return t>.002?2:t>1e-5?4:8}function io(t,e=.001){let r=Yu(e),n=Zu[r],o=Math.round(t/n),s=Math.min(Math.ceil(Math.log2(1/e)+Math.log2(2*r)),so);return{filterSize:o,bucketSize:r,fingerprintSize:s}}function hi(t,e=.005){let r=io(t,e);return new Pe(r)}var Wt=class{filterSize;bucketSize;fingerprintSize;scale;filterSeries;hash;seed;constructor(e){this.bucketSize=e.bucketSize??4,this.filterSize=e.filterSize??(1<<18)/this.bucketSize,this.fingerprintSize=e.fingerprintSize??2,this.scale=e.scale??2,this.hash=e.hash??Be,this.seed=e.seed??He(0,Math.pow(2,10)),this.filterSeries=[new Pe({filterSize:this.filterSize,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed})]}add(e){if(typeof e=="string"&&(e=M(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 Pe({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=M(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=M(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 di(t,e=.001,r){return new Wt({...io(t,e),...r??{}})}var ge=class extends Error{static name="AbortError";constructor(e="The operation was aborted"){super(e),this.name="AbortError"}};var ae=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}};var xr=class extends Error{static name="MuxerClosedError";constructor(e="The muxer is closed"){super(e),this.name="MuxerClosedError"}},wr=class extends Error{static name="StreamResetError";constructor(e="The stream has been reset"){super(e),this.name="StreamResetError"}};var Me=class extends Error{static name="StreamStateError";constructor(e="The stream is in an invalid state"){super(e),this.name="StreamStateError"}},Xe=class extends Error{static name="StreamBufferError";constructor(e="The stream buffer was full"){super(e),this.name="StreamBufferError"}};var ye=class extends Event{data;constructor(e,r){super("message",r),this.data=e}},gt=class extends Event{error;local;constructor(e,r,n){super("close",n),this.error=r,this.local=e}},Er=class extends gt{constructor(e,r){super(!0,e,r)}},_r=class extends gt{constructor(e,r){super(!1,e,r)}};function ef(t){return typeof t?.handleEvent=="function"}function tf(t){return t===!0||t===!1}function rf(t){return tf(t)?t:t?.capture??!1}function ao(t){let e={capture:rf(t),once:!!t?.once};return t?.passive!=null&&(e.passive=t?.passive),t?.signal!=null&&(e.signal=t?.signal),e}function mi(t,e){return ao(t).capture===ao(e).capture}var be=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=ao(n);if(o?.signal?.aborted===!0)return;let s=h=>{o.once&&this.removeEventListener(e,r,o),ef(r)?r.handleEvent(h):r(h)},i=this.#e.get(e);if(i==null&&(i=[],this.#e.set(e,i)),i.some(h=>h.callback!==r?!1:mi(h.options,o)))return;super.addEventListener(e,s,o);let u=()=>{this.removeEventListener(e,r,o)};o.signal?.addEventListener("abort",u),i.push({callback:r,wrapper:s,options:o,onAbort:u})}removeEventListener(e,r,n){let o=this.#e.get(e);if(o==null){super.removeEventListener(e,r??null,n);return}this.#e.set(e,o.filter(s=>s.callback===r&&mi(s.options,n)?(super.removeEventListener(e,s.wrapper,n),s.options?.signal?.removeEventListener("abort",s.onAbort),!1):!0))}safeDispatchEvent(e,r={}){return this.dispatchEvent(new CustomEvent(e,r))}};function vr(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=vr(t);if(e==null)throw new ae(`Multiaddr ${t} was not an IPv4, IPv6, DNS, DNS4, DNS6 or DNSADDR address`);return e}var Sr=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",h=2**(8*o)-1;for(;;){let f=this.readAtomically(()=>{let l=this.readChar();if(l===void 0)return;let p=Number.parseInt(l,e);if(!Number.isNaN(p))return p});if(f===void 0)break;if(s*=e,s+=f,s>h||(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 pi=45,nf=15,yt=new Sr;function Cr(t){if(!(t.length>nf))return yt.new(t).parseWith(()=>yt.readIPv4Addr())}function Ir(t){if(t.includes("%")&&(t=t.split("%")[0]),!(t.length>pi))return yt.new(t).parseWith(()=>yt.readIPv6Addr())}function bt(t,e=!1){if(t.includes("%")&&(t=t.split("%")[0]),t.length>pi)return;let r=yt.new(t).parseWith(()=>yt.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 gi(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 yi(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 co(t){switch(t.length){case Ke:return t.join(".");case Je:{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 bi(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 xi(t){let e="0x";for(let r of t)e+=(r>>4).toString(16)+(r&15).toString(16);return e}var Ke=4,Je=16,Vm=parseInt("0xFFFF",16),of=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function Gt(t,e){e.length===Je&&t.length===Ke&&gi(e,0,11)&&(e=e.slice(12)),e.length===Ke&&t.length===Je&&yi(t,of,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 wi(t,e){if(typeof e=="string"&&(e=bt(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 uo(t){let[e,r]=t.split("/");if(!e||!r)throw new Error("Failed to parse given CIDR: "+t);let n=Ke,o=Cr(e);if(o==null&&(n=Je,o=Ir(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=fo(s,8*n);return{network:Gt(o,i),mask:i}}function fo(t,e){if(e!==8*Ke&&e!==8*Je)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 Ht=class{constructor(e,r){if(r==null)({network:this.network,mask:this.mask}=uo(e));else{let n=bt(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=bt(r);if(s==null)throw new Error("Failed to parse mask");this.mask=s}else this.mask=fo(o,8*n.length);this.network=Gt(n,this.mask)}}contains(e){return wi({network:this.network,mask:this.mask},e)}toString(){let e=bi(this.mask),r=e!==-1?String(e):xi(this.mask);return co(this.network)+"/"+r}};function Lr(t,e){return new Ht(t).contains(e)}function sf(t){try{let e=le(t);return e.type==="ip6"?Lr("2000::/3",e.host):!1}catch{return!1}}function af(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 Ei(t){if(typeof t!="string"||!/^[0-9a-fA-FxX.:]+$/.test(t))return!1;let e=t.includes(":")?`[${t}]`:t,r;try{r=new URL(`http://${e}`)}catch{return!1}if(r.href!==`http://${r.hostname}/`)return!1;let n=r.hostname;if(n.startsWith("["))return n==="[::1]";let o=n.split(".");return o.length===4&&o[0]==="127"&&o.every(s=>/^\d{1,3}$/.test(s))}function Ar(t){try{let e=le(t);switch(e.type){case"ip4":case"ip6":return Ei(e.host);default:return!1}}catch{return!1}}function cf(t){return vr(t)!==null}function Fe(t){return!!Cr(t)}function Ne(t){return!!Ir(t)}var Ci=Mc(Si(),1),pf=["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"],gf=pf.map(t=>new Ci.Netmask(t));function bo(t){for(let e of gf)if(e.contains(t))return!0;return!1}function yf(t){return/^::ffff:([0-9a-fA-F]{1,4}):([0-9a-fA-F]{1,4})$/.test(t)}function bf(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 bo(o)}function xf(t){return/^::ffff:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(t)}function wf(t){let e=t.split(":"),r=e[e.length-1];return bo(r)}function Ef(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 xo(t){if(Fe(t))return bo(t);if(yf(t))return bf(t);if(xf(t))return wf(t);if(Ne(t))return Ef(t)}function Dr(t){try{let e=le(t);switch(e.type){case"ip4":case"ip6":return xo(e.host)??!1;default:return e.host==="localhost"}}catch{return!1}}var _f=Math.pow(2,7),vf=Math.pow(2,14),Sf=Math.pow(2,21),wo=Math.pow(2,28),Eo=Math.pow(2,35),_o=Math.pow(2,42),vo=Math.pow(2,49),S=128,j=127;function q(t){if(t<_f)return 1;if(t<vf)return 2;if(t<Sf)return 3;if(t<wo)return 4;if(t<Eo)return 5;if(t<_o)return 6;if(t<vo)return 7;if(Number.MAX_SAFE_INTEGER!=null&&t>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function kr(t,e,r=0){switch(q(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 Cf(t,e,r=0){switch(q(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 If(t,e){let r=t[e],n=0;if(n+=r&j,r<S||(r=t[e+1],n+=(r&j)<<7,r<S)||(r=t[e+2],n+=(r&j)<<14,r<S)||(r=t[e+3],n+=(r&j)<<21,r<S)||(r=t[e+4],n+=(r&j)*wo,r<S)||(r=t[e+5],n+=(r&j)*Eo,r<S)||(r=t[e+6],n+=(r&j)*_o,r<S)||(r=t[e+7],n+=(r&j)*vo,r<S))return n;throw new RangeError("Could not decode varint")}function Lf(t,e){let r=t.get(e),n=0;if(n+=r&j,r<S||(r=t.get(e+1),n+=(r&j)<<7,r<S)||(r=t.get(e+2),n+=(r&j)<<14,r<S)||(r=t.get(e+3),n+=(r&j)<<21,r<S)||(r=t.get(e+4),n+=(r&j)*wo,r<S)||(r=t.get(e+5),n+=(r&j)*Eo,r<S)||(r=t.get(e+6),n+=(r&j)*_o,r<S)||(r=t.get(e+7),n+=(r&j)*vo,r<S))return n;throw new RangeError("Could not decode varint")}function Br(t,e,r=0){return e==null&&(e=Z(q(t))),e instanceof Uint8Array?kr(t,e,r):Cf(t,e,r)}function Ie(t,e=0){return t instanceof Uint8Array?If(t,e):Lf(t,e)}function Af(t){return t.buffer instanceof ArrayBuffer}function So(t){return Af(t)?t:t.slice()}function Oe(t,e="utf8"){let r=br[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"},Le=class extends Error{static name="ValidationError";name="ValidationError"},Pr=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},Mr=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};function Io(t){return e=>Oe(e,t)}function Lo(t){return e=>M(e,t)}function _t(t){return new DataView(t.buffer).getUint16(t.byteOffset).toString()}function Ye(t){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,typeof t=="string"?parseInt(t):t),new Uint8Array(e)}function Ii(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=M(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=Ye(n);return Ce([r,o],r.length+o.length)}function Li(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=pe.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=Ye(n);return Ce([r,o],r.length+o.length)}function Ao(t){let e=t.subarray(0,t.length-2),r=t.subarray(t.length-2),n=Oe(e,"base32"),o=_t(r);return`${n}:${o}`}var To=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},Ai=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=To(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 z("Invalid byte value in IP address");o[e++]=s>>8&255,o[e++]=s&255}return o},Ti=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(".")},Di=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 ki(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 Co=Object.values(jt).map(t=>t.decoder),Tf=(function(){let t=Co[0].or(Co[1]);return Co.slice(2).forEach(e=>t=t.or(e)),t})();function Bi(t){return Tf.decode(t)}function Pi(t){return e=>t.encoder.encode(e)}function Df(t){if(parseInt(t).toString()!==t)throw new Le("Value must be an integer")}function kf(t){if(t<0)throw new Le("Value must be a positive integer, or zero")}function Bf(t){return e=>{if(e>t)throw new Le(`Value must be smaller than or equal to ${t}`)}}function Pf(...t){return e=>{for(let r of t)r(e)}}var Xt=Pf(Df,kf,Bf(65535));var U=-1,Do=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 Mr(`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)}))}},Te=new Do,Hf=[{code:4,name:"ip4",size:32,valueToBytes:To,bytesToValue:Ti,validate:t=>{if(!Fe(t))throw new Le(`Invalid IPv4 address "${t}"`)}},{code:6,name:"tcp",size:16,valueToBytes:Ye,bytesToValue:_t,validate:Xt},{code:273,name:"udp",size:16,valueToBytes:Ye,bytesToValue:_t,validate:Xt},{code:33,name:"dccp",size:16,valueToBytes:Ye,bytesToValue:_t,validate:Xt},{code:41,name:"ip6",size:128,valueToBytes:Ai,bytesToValue:Di,stringToValue:ki,validate:t=>{if(!Ne(t))throw new Le(`Invalid IPv6 address "${t}"`)}},{code:42,name:"ip6zone",size:U},{code:43,name:"ipcidr",size:8,bytesToValue:Io("base10"),valueToBytes:Lo("base10")},{code:53,name:"dns",size:U},{code:54,name:"dns4",size:U},{code:55,name:"dns6",size:U},{code:56,name:"dnsaddr",size:U},{code:132,name:"sctp",size:16,valueToBytes:Ye,bytesToValue:_t,validate:Xt},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:U,stringToValue:t=>decodeURIComponent(t),valueToString:t=>encodeURIComponent(t)},{code:421,name:"p2p",aliases:["ipfs"],size:U,bytesToValue:Io("base58btc"),valueToBytes:t=>t.startsWith("Q")||t.startsWith("1")?Lo("base58btc")(t):pt.parse(t).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:Ao,valueToBytes:Ii},{code:445,name:"onion3",size:296,bytesToValue:Ao,valueToBytes:Li},{code:446,name:"garlic64",size:U},{code:447,name:"garlic32",size:U},{code:448,name:"tls"},{code:449,name:"sni",size:U},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:U,bytesToValue:Pi(Gn),valueToBytes:Bi},{code:480,name:"http"},{code:481,name:"http-path",size:U,stringToValue:t=>`/${decodeURIComponent(t)}`,valueToString:t=>encodeURIComponent(t.substring(1))},{code:443,name:"https"},{code:477,name:"ws"},{code:478,name:"wss"},{code:479,name:"p2p-websocket-star"},{code:277,name:"p2p-stardust"},{code:275,name:"p2p-webrtc-star"},{code:276,name:"p2p-webrtc-direct"},{code:280,name:"webrtc-direct"},{code:281,name:"webrtc"},{code:290,name:"p2p-circuit"},{code:777,name:"memory",size:U}];Hf.forEach(t=>{Te.addProtocol(t)});function Mi(t){let e=[],r=0;for(;r<t.length;){let n=Ie(t,r),o=Te.getProtocol(n),s=q(n),i=Qf(o,t,r+s),a=0;i>0&&o.size===U&&(a=q(i));let u=s+a+i,h={code:n,name:o.name,bytes:So(t.subarray(r,r+u))};if(i>0){let f=r+s+a,l=t.subarray(f,f+i);h.value=o.bytesToValue?.(l)??Oe(l)}e.push(h),r+=u}return e}function Fi(t){let e=0,r=[];for(let n of t){if(n.bytes==null){let o=Te.getProtocol(n.code),s=q(n.code),i,a=0,u=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??M(n.value),a=i.byteLength,o.size===U&&(u=q(a)));let h=new Uint8Array(s+u+a),f=0;kr(n.code,h,f),f+=s,i!=null&&(o.size===U&&(kr(a,h,f),f+=u),h.set(i,f)),n.bytes=h}r.push(n.bytes),e+=n.bytes.byteLength}return Ce(r,e)}function Ni(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=Te.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 h={code:u.code,name:u.name};if(u.size!=null&&u.size!==0){if(n==="")throw new z(`Component ${o} was missing value`);h.value=u.stringToValue?.(n)??n}e.push(h),n="",o="",r="protocol"}}}if(o!==""&&n!=="")throw new z("Incomplete multiaddr");return e}function Ui(t){return`/${t.flatMap(e=>{if(e.value==null)return e.name;let r=Te.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 Qf(t,e,r){return t.size==null||t.size===0?0:t.size>0?t.size/8:Ie(e,r)}var Xf=Symbol.for("nodejs.util.inspect.custom"),qo=Symbol.for("@multiformats/multiaddr");function Kf(t){if(t==null&&(t="/"),Oi(t))return t.getComponents();if(t instanceof Uint8Array)return Mi(t);if(typeof t=="string")return t=t.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),t===""&&(t="/"),Ni(t);if(Array.isArray(t))return t;throw new z("Must be a string, Uint8Array, Component[], or another Multiaddr")}var jr=class t{[qo]=!0;#e;#t;#r;constructor(e="/",r={}){this.#e=Kf(e),r.validate!==!1&&Jf(this)}get bytes(){return this.#r==null&&(this.#r=Fi(this.#e)),this.#r}toString(){return this.#t==null&&(this.#t=Ui(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 Pr(`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)}[Xf](){return`Multiaddr(${this.toString()})`}};function Jf(t){t.getComponents().forEach(e=>{let r=Te.getProtocol(e.code);e.value!=null&&r.validate?.(e.value)})}function Oi(t){return!!t?.[qo]}function Re(t){return new jr(t)}var L=t=>({match:e=>{let r=e[0];return r==null||r.code!==t||r.value!=null?!1:e.slice(1)}}),y=(t,e)=>({match:r=>{let n=r[0];return n?.code!==t||n.value==null||e!=null&&n.value!==e?!1:r.slice(1)}}),Ri=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}}),_=(...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 Zf=y(421),Fg=A(Zf),Wr=y(54),Gr=y(55),Hr=y(56),Go=y(53),Ng=A(Wr,w(y(421))),Ug=A(Gr,w(y(421))),Og=A(Hr,w(y(421))),Rg=A(W(Go,Hr,Wr,Gr),w(y(421))),$i=_(y(4),w(y(43))),zi=_(w(y(42)),y(41),w(y(43))),Ho=W($i,zi),It=W(Ho,Go,Wr,Gr,Hr),$g=A(W(Ho,_(W(Go,Hr,Wr,Gr),w(y(421))))),zg=A($i),Vg=A(zi),jg=A(Ho),Qo=_(It,y(6)),Kt=_(It,y(273)),Xo=A(_(Qo,w(y(421)))),qg=A(Kt),Ko=_(Kt,L(460),w(y(421))),Qr=_(Kt,L(461),w(y(421))),Yf=W(Ko,Qr),Wg=A(Ko),Gg=A(Qr),Wo=W(It,Qo,Kt,Ko,Qr),Vi=W(_(Wo,L(477),w(y(421)))),Jo=A(Vi),ji=W(_(Wo,L(478),w(y(421))),_(Wo,L(448),w(y(449)),L(477),w(y(421)))),Zo=A(ji),qi=_(Kt,L(280),w(y(466)),w(y(466)),w(y(421))),Yo=A(qi),Wi=_(Qr,L(465),w(y(466)),w(y(466)),w(y(421))),es=A(Wi),qr=W(Vi,ji,_(Qo,w(y(421))),_(Yf,w(y(421))),_(It,w(y(421))),qi,Wi,y(421)),Hg=A(qr),el=_(w(qr),L(290),Ri(L(281)),w(y(421))),ts=A(el),tl=W(_(qr,L(290),L(281),w(y(421))),_(qr,L(281),w(y(421))),_(L(281),w(y(421)))),rs=A(tl),rl=_(It,W(_(y(6,"80")),_(y(6),L(480)),L(480)),w(y(481)),w(y(421))),Qg=A(rl),nl=_(It,W(_(y(6,"443")),_(y(6,"443"),L(480)),_(y(6),L(443)),_(y(6),L(448),L(480)),_(L(448),L(480)),L(448),L(443)),w(y(481)),w(y(421))),Xg=A(nl),ol=W(_(y(777),w(y(421)))),Kg=A(ol),sl=W(_(y(400),w(y(421)))),Jg=A(sl);function Gi(t,e){let r=Xo.exactMatch(t),n=Xo.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=Jo.exactMatch(t),a=Jo.exactMatch(e);if(i&&!a)return-1;if(!i&&a)return 1;let u=rs.exactMatch(t),h=rs.exactMatch(e);if(u&&!h)return-1;if(!u&&h)return 1;let f=Yo.exactMatch(t),l=Yo.exactMatch(e);if(f&&!l)return-1;if(!f&&l)return 1;let p=es.exactMatch(t),E=es.exactMatch(e);return p&&!E?-1:!p&&E?1:0}function Hi(t,e){let r=Ar(t),n=Ar(e);return r&&!n?1:!r&&n?-1:0}function Qi(t,e){let r=Dr(t),n=Dr(e);return r&&!n?1:!r&&n?-1:0}function Xi(t,e){let r=ts.exactMatch(t),n=ts.exactMatch(e);return r&&!n?1:!r&&n?-1:0}function il(t){return t.sort((e,r)=>Hi(e,r)||Qi(e,r)||Xi(e,r)||Gi(e,r))}function he(){let t={};return t.promise=new Promise((e,r)=>{t.resolve=e,t.reject=r}),t}var Xr=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}},Lt=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new Xr(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 Xr(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 ns=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 al(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 al(t,e){e=e??{};let r=e.onEnd,n=new Lt,o,s,i,a=he(),u=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((x,b)=>{s=C=>{s=null,n.push(C);try{x(t(n))}catch(D){b(D)}return o}}):t(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=he()})}},h=x=>s!=null?s(x):(n.push(x),o),f=x=>(n=new Lt,s!=null?s({error:x}):(n.push({error:x}),o)),l=x=>{if(i)return o;if(e?.objectMode!==!0&&x?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return h({done:!1,value:x})},p=x=>i?o:(i=!0,x!=null?f(x):h({done:!0})),E=()=>(n=new Lt,p(),{done:!0}),ne=x=>(p(x),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:u,return:E,throw:ne,push:l,end:p,get readableLength(){return n.size},onEmpty:async x=>{let b=x?.signal;if(b?.throwIfAborted(),n.isEmpty())return;let C,D;b!=null&&(C=new Promise((T,B)=>{D=()=>{B(new ns)},b.addEventListener("abort",D)}));try{await Promise.race([a.promise,C])}finally{D!=null&&b!=null&&b?.removeEventListener("abort",D)}}},r==null)return o;let G=o;return o={[Symbol.asyncIterator](){return this},next(){return G.next()},throw(x){return G.throw(x),r!=null&&(r(x),r=void 0),{done:!0}},return(){return G.return(),r!=null&&(r(),r=void 0),{done:!0}},push:l,end(x){return G.end(x),r!=null&&(r(x),r=void 0),o},get readableLength(){return G.readableLength},onEmpty:x=>G.onEmpty(x)},o}var os=class t extends Error{name="TimeoutError";constructor(e,r){super(e,r),Error.captureStackTrace?.(this,t)}},Ki=t=>t.reason??new DOMException("This operation was aborted.","AbortError");function ss(t,e){let{milliseconds:r,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout},signal:i}=e,a,u,f=new Promise((l,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(Ki(i)),t.then(l,p);return}if(i&&(u=()=>{p(Ki(i))},i.addEventListener("abort",u,{once:!0})),t.then(l,p),r===Number.POSITIVE_INFINITY)return;let E=new os;a=s.setTimeout.call(void 0,()=>{if(n){try{l(n())}catch(ne){p(ne)}return}typeof t.cancel=="function"&&t.cancel(),o===!1?l():o instanceof Error?p(o):(E.message=o??`Promise timed out after ${r} milliseconds`,p(E))},r)}).finally(()=>{f.clear(),u&&i&&i.removeEventListener("abort",u)});return f.clear=()=>{s.clearTimeout.call(void 0,a),a=void 0},f}var Ji=t=>typeof t=="function"?{filter:t}:{...t},cl=t=>t===1/0||Number.isSafeInteger(t)&&t>=0,ul=[["addEventListener","removeEventListener"],["on","off"],["addListener","removeListener"]],fl=t=>{for(let[e,r]of ul){let n=t?.[e],o=t?.[r];if(typeof n=="function"&&typeof o=="function")return{addListener:n.bind(t),removeListener:o.bind(t)}}throw new TypeError("Emitter is not compatible")},ll=t=>{let e=new Map;for(let[r,n]of t)for(let o of Array.isArray(r)?r:[r])e.has(o)||e.set(o,n);return e},hl=({addListener:t,removeListener:e,handlers:r,signal:n,abortHandler:o,isDone:s})=>{n?.addEventListener("abort",o,{once:!0});for(let[i,a]of r)if(t(i,a),s()){e(i,a);return}},dl=({removeListener:t,handlers:e,signal:r,abortHandler:n})=>{for(let[o,s]of e)t(o,s);r?.removeEventListener("abort",n)},ml=(t,e,r)=>{let n=Promise.resolve();return(o,s)=>{n=n.then(async()=>{if(e())return;let i;try{i=t?await t(o):!0}catch(a){e()||r(a);return}e()||s(i)})}};function pl(t,e,r){let n=()=>{},o=!1,s,i=new Promise((a,u)=>{r=Ji(r);let{filter:h}=r;if(!cl(r.count))throw new TypeError("The `count` option should be at least 0 or more");if(typeof r.timeout=="number"&&!(r.timeout>0))throw new TypeError(`Expected the \`timeout\` option to be a positive number, got \`${r.timeout}\``);r.signal?.throwIfAborted();let{addListener:f,removeListener:l}=fl(t);if(r.count===0){a([]);return}let p=[],E=T=>{n(),u(T)},ne=ml(h,()=>o,E),G=T=>{p.push(T),r.count===p.length&&(n(),a(p))},x=(...T)=>{if(o)return;let B=r.multiArgs?T:T[0];if(!h){G(B);return}ne(B,X=>{X&&G(B)})},b=(...T)=>{E(r.rejectionMultiArgs?T:T[0])},C=()=>{E(r.signal.reason)},D={addListener:f,removeListener:l,handlers:ll([[e,x],[r.rejectionEvents??["error"],b]]),signal:r.signal,abortHandler:C,isDone:()=>o};n=()=>{o=!0,clearTimeout(s),dl(D)},hl(D),!(o||!r.resolveImmediately)&&(Number.isFinite(r.timeout)&&(s=setTimeout(n,r.timeout)),a(p))});if(i.cancel=n,typeof r.timeout=="number"&&r.timeout>0&&!r.resolveImmediately){let a=ss(i,{milliseconds:r.timeout});return a.cancel=()=>{n(),a.clear()},a}return i}function O(t,e,r){let n=pl(t,e,{...Ji(r),count:1,resolveImmediately:!1}),o=n.then(s=>s[0]);return o.cancel=n.cancel,o}function At(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 Jt=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}},Zt=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"},Yt=class extends Error{static name="MaxEarlyStreamsError";name="MaxEarlyStreamsError"},er=class extends Error{static name="StreamClosedError";name="StreamClosedError"};function gl(t){return t.reason}function R(t,e,r){if(e==null||t==null)return t;let n=r?.translateError??gl;if(e.aborted)return t.catch(()=>{}),Promise.reject(n(e));let o;return Promise.race([t,new Promise((s,i)=>{o=()=>{i(n(e))},e.addEventListener("abort",o)})]).finally(()=>{o!=null&&e.removeEventListener("abort",o)})}var Kr=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 ge)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function yl(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var Zi=new WeakMap,Jr=class{id;fn;options;recipients;status;timeline;controller;dispatchingProgress;constructor(e,r){this.id=yl(),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 ge),this.cleanup())}async join(e){let r=new Kr(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 R(this.fn({...this.options??{},signal:this.controller.signal,onProgress:r=>{if(this.recipients.length!==0&&!this.dispatchingProgress){if(typeof r=="object"&&r!==null){let n=Zi.get(r);if(n==null&&(n=new WeakSet,Zi.set(r,n)),n.has(this))return;n.add(this)}this.dispatchingProgress=!0;try{this.recipients.forEach(n=>{n.onProgress?.(r)})}finally{this.dispatchingProgress=!1}}}}),this.controller.signal);this.recipients.forEach(r=>{r.deferred.resolve(e)}),this.status="complete"}catch(e){this.recipients.forEach(r=>{r.deferred.reject(e)}),this.status="errored"}finally{this.timeline.finished=Date.now(),this.cleanup()}}cleanup(){this.recipients.forEach(e=>{e.deferred.reject(e.signal?.reason??new ge),e.cleanup(),e.signal?.removeEventListener("abort",this.onAbort)}),this.recipients.splice(0,this.recipients.length)}};var de=class extends be{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=At(this.emitEmpty.bind(this),1),this.emitIdle=At(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 Zt;let n=new Jr(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 ge)}),this.clear()}async onEmpty(e){this.size!==0&&await O(this,"empty",e)}async onSizeLessThan(e,r){this.size<e||await O(this,"next",{...r,filter:()=>this.size<e})}async onIdle(e){this.pending===0&&this.size===0||await O(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 ge("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 bl=Math.pow(2,20)*4,tt=class extends be{status;timeline;inactivityTimeout;maxReadBufferLength;maxWriteBufferLength;log;direction;maxMessageSize;readStatus;writeStatus;remoteReadStatus;remoteWriteStatus;writableNeedsDrain;readBuffer;writeBuffer;sendingData;#e=!1;#t;#r=new Set;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??bl,this.maxWriteBufferLength=e.maxWriteBufferLength,this.maxMessageSize=e.maxMessageSize,this.readBuffer=new P,this.writeBuffer=new P,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 er)};this.addEventListener("close",n)}get readBufferLength(){return this.readBuffer.byteLength}get readableEnded(){return this.#e}get writeBufferLength(){return this.writeBuffer.byteLength}async onDrain(e){return this.writableNeedsDrain!==!0?Promise.resolve():(this.onDrainPromise==null&&(this.onDrainPromise=Promise.withResolvers()),R(this.onDrainPromise.promise,e?.signal))}async*[Symbol.asyncIterator](){let e=we(),r,n=s=>{e.push(s.data)};this.addEventListener("message",n);let o=()=>{this.#r.delete(o),this.removeEventListener("message",n),r=this.#t,e.end()};this.#r.add(o),this.readableDone()&&o();try{if(yield*e,r!=null)throw r}finally{this.removeEventListener("message",n),this.#r.delete(o)}}readableDone(){return this.readBuffer.byteLength===0&&(this.remoteWriteStatus==="closed"||this.readStatus==="closing"||this.readStatus==="closed")}isReadable(){return this.status==="open"}send(e){if(this.writeStatus==="closed"||this.writeStatus==="closing")throw new Me(`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.readBuffer.byteLength>0&&(this.#t??=e,this.readBuffer.consume(this.readBuffer.byteLength),this.readStatus="closed",this.maybeDispatchEnd());return}this.log.error("abort with error - %e",e),this.status="aborted",this.#t=e,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(),this.maybeDispatchEnd();try{this.sendReset(e)}catch(r){this.log.error("failed to send reset to remote - %e",r)}this.dispatchEvent(new Er(e))}pause(){if(this.readStatus==="closed"||this.readStatus==="closing")throw new Me("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 Me("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 Me(`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 Me(`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(){if(this.status==="aborted"||this.status==="reset"||this.status==="closed")return;this.log("remote reset");let e=new wr;this.#t=e,this.status="reset",this.writeStatus="closed",this.remoteWriteStatus="closed",this.remoteReadStatus="closed",this.timeline.close=Date.now(),this.readBuffer.byteLength===0&&(this.readStatus="closed",this.maybeDispatchEnd()),this.dispatchEvent(new _r(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.maybeDispatchEnd(),this.dispatchEvent(new gt))}onRemoteCloseWrite(){this.remoteWriteStatus!=="closed"&&(this.log.trace("on remote close write"),this.remoteWriteStatus="closed",this.safeDispatchEvent("remoteCloseWrite"),this.maybeDispatchEnd(),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 P(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}}maybeDispatchEnd(){this.readableDone()&&(this.#r.forEach(e=>{e()}),!this.#e&&(this.#e=!0,this.safeDispatchEvent("end")))}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 ye(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.maybeDispatchEnd()),this.checkReadBufferLength()}}checkReadBufferLength(){this.readBuffer.byteLength>this.maxReadBufferLength&&this.abort(new Xe(`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 Xe(`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 tr=class extends tt{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 O(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 O(this,"drain",{...e,rejectionEvents:["close"]})),await this.sendClose(e),this.onTransportClosed())}};function is(t){return t==null?!1:typeof t.then=="function"&&typeof t.catch=="function"&&typeof t.finally=="function"}var rr=class extends be{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 R(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 xr;let r=this.onCreateStream({...this.streamOptions,...e});return is(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 Yt(`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 rt=class extends tt{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 O(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 O(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){if(!(this.readStatus==="closing"||this.readStatus==="closed")){this.readBuffer.byteLength>0&&this.readBuffer.consume(this.readBuffer.byteLength),this.readStatus="closing",this.maybeDispatchEnd();try{await this.sendCloseRead(e)}catch(r){throw this.log.error("failed to close readable end - %e",r),r}finally{this.readStatus="closed"}this.log("closed readable end gracefully")}}};function Zr(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 nt=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 Yi=1.2,ea=2,ta=5e3,ra=6e4,na=5e3,as=class{success;failure;next;metric;timeoutMultiplier;failureMultiplier;minTimeout;maxTimeout;constructor(e={}){let r=e.interval??na;this.success=new nt(r),this.failure=new nt(r),this.next=new nt(r),this.failureMultiplier=e.failureMultiplier??ea,this.timeoutMultiplier=e.timeoutMultiplier??Yi,this.minTimeout=e.minTimeout??ta,this.maxTimeout=e.maxTimeout??ra,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=Zr([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 oa(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 xl(t,e){if(t==null)return[];let r=le(t);return[oa(r,e)]}function wl(t){return Ne(t)?Lr("2000::/3",t):!1}function El(t,e){if(typeof t!="string")throw new ae(`invalid ip provided: ${t}`);if(typeof e=="string"&&(e=parseInt(e)),isNaN(e))throw new ae(`invalid port provided: ${e}`);if(Fe(t))return Re(`/ip4/${t}/tcp/${e}`);if(Ne(t))return Re(`/ip6/${t}/tcp/${e}`);throw new ae(`invalid ip:port for creating a multiaddr: ${t}:${e}`)}function _l(t){return t==null||typeof t?.[Symbol.asyncIterator]!="function"?!1:typeof t.next=="function"}function vl(t){return t==null||typeof t?.[Symbol.iterator]!="function"?!1:typeof t.next=="function"}var cs=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 R(this.readNext.promise,r?.signal,r)}};function sa(){return new cs}function ia(t){return t[Symbol.asyncIterator]!=null}async function Sl(t,e,r){try{await Promise.all(t.map(async n=>{for(;;){let{value:o,done:s}=await n.next();if(s===!0)break;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*Cl(t){let e=new AbortController,r=sa(),n=t.map(o=>ia(o)?o[Symbol.asyncIterator]():o[Symbol.iterator]());Sl(n,r,e.signal).catch(()=>{});try{yield*r}finally{e.abort();for(let o of n)try{Promise.resolve(o.return?.()).catch(()=>{})}catch{}}}function*Il(t){for(let e of t)yield*e}function Ll(...t){let e=[];for(let r of t)ia(r)||e.push(r);return e.length===t.length?Il(e):Cl(t)}var aa=Ll;function ca(t,...e){if(t==null)throw new Error("Empty pipeline");if(us(t)){let n=t;t=()=>n.source}else if(fa(t)||ua(t)){let n=t;t=()=>n}let r=[t,...e];if(r.length>1&&us(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++)us(r[n])&&(r[n]=Tl(r[n]));return Al(...r)}var Al=(...t)=>{let e;for(;t.length>0;)e=t.shift()(e);return e},ua=t=>t?.[Symbol.asyncIterator]!=null,fa=t=>t?.[Symbol.iterator]!=null,us=t=>t==null?!1:t.sink!=null&&t.source!=null,Tl=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(ua(s))o=async function*(){yield*s,n.end()};else if(fa(s))o=function*(){yield*s,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return aa(n,o())}return t.source};var Dl=4194304,nr=class extends Error{static name="UnwrappedError";name="UnwrappedError"},Tt=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},Yr=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},en=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function kl(t){return typeof t?.closeRead=="function"}function Bl(t){return typeof t?.close=="function"}function fs(t){return kl(t)?t.remoteWriteStatus!=="writable"&&t.readBufferLength===0:Bl(t)?t.status!=="open":!1}function Pl(t){return t?.addEventListener!=null&&t?.removeEventListener!=null&&t?.send!=null&&t?.push!=null&&t?.log!=null}function la(t,e){let r=e?.maxBufferSize??Dl,n=new P,o,s=!1,i;if(!Pl(t))throw new ae("Argument should be a Stream or a Multiaddr");let a=l=>{if(!s&&i==null){if(n.append(l.data),n.byteLength>r){let p=n.byteLength;n.consume(p);let E=new Xe(`Read buffer overflow - ${p} > ${r}`);i=E,o?.reject(E),queueMicrotask(()=>{t.abort(E)});return}o?.resolve()}};t.addEventListener("message",a);let u=l=>{l.error!=null?o?.reject(l.error):o?.resolve()};t.addEventListener("close",u);let h=()=>{o?.resolve()};t.addEventListener("remoteCloseWrite",h);let f={readBuffer:n,async read(l){if(s===!0)throw new nr("Stream was unwrapped");if(i!=null)throw i;if(fs(t)){if(n.byteLength===0&&l?.bytes==null)return null;if(l?.bytes!=null&&n.byteLength<l.bytes)throw t.log.error("closed after reading %d/%d bytes",n.byteLength,l.bytes),new $e(`Unexpected EOF - stream closed after reading ${n.byteLength}/${l.bytes} bytes`)}let p=l?.bytes??1;for(o=Promise.withResolvers();;){if(n.byteLength>=p){o.resolve();break}if(await R(o.promise,l?.signal),fs(t)){if(n.byteLength===0&&l?.bytes==null)return null;break}o=Promise.withResolvers()}let E=l?.bytes??n.byteLength;if(n.byteLength<E){if(fs(t))throw t.log.error("closed while reading %d/%d bytes",n.byteLength,E),new $e(`Unexpected EOF - stream closed while reading ${n.byteLength}/${E} bytes`);return f.read(l)}let ne=n.sublist(0,E);return n.consume(E),ne},async write(l,p){if(s===!0)throw new nr("Stream was unwrapped");t.send(l)||await O(t,"drain",{signal:p?.signal,rejectionEvents:["close"]})},unwrap(){return s||(s=!0,t.removeEventListener("message",a),t.removeEventListener("close",u),t.removeEventListener("remoteCloseWrite",h),n.byteLength>0&&(t.log("stream unwrapped with %d unread bytes",n.byteLength),t.unshift(n),n.consume(n.byteLength))),t}};return f}function ha(t,e={}){let r=la(t,e);e.maxDataLength!=null&&e.maxLengthLength==null&&(e.maxLengthLength=q(e.maxDataLength));let n=e?.lengthDecoder??Ie,o=e?.lengthEncoder??Br;return{async read(i){let a=-1,u=new P;for(;;){let f=await r.read({...i,bytes:1});if(f==null)break;u.append(f);try{a=n(u)}catch(l){if(l instanceof RangeError)continue;throw l}if(a<0)throw new Tt("Invalid message length");if(e?.maxLengthLength!=null&&u.byteLength>e.maxLengthLength)throw new en(`Message length length too long - ${u.byteLength} > ${e.maxLengthLength}`);if(a>-1)break}if(e?.maxDataLength!=null&&a>e.maxDataLength)throw new Yr(`Message length too long - ${a} > ${e.maxDataLength}`);let h=await r.read({...i,bytes:a});if(h==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(h.byteLength!==a)throw t.log.error("read %d/%d bytes before the stream closed",h.byteLength,a),new $e(`Unexpected EOF - read ${h.byteLength}/${a} bytes before the stream closed`);return h},async write(i,a){await r.write(new P(o(i.byteLength),i),a)},async writeV(i,a){let u=new P(...i.flatMap(h=>[o(h.byteLength),h]));await r.write(u,a)},unwrap(){return r.unwrap()}}}function Ml(t,e){let r=ha(t,e),n={read:async(o,s)=>{let i=await r.read(s);return o.decode(i,s)},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 ls(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 O(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 Fl(t){return t?.addEventListener!=null}function da(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:h,value:f}=await Promise.race([u.next(),r.promise]);if(t.writeStatus==="closing"||t.writeStatus==="closed"||(f!=null&&(t.send(f)||await Promise.race([O(t,"drain",{rejectionEvents:["close"]})])),h===!0))break}await t.close()}}}function Nl(...t){let e=t.map(r=>Fl(r)?da(r):r);return ca(...e)}var Ul=1024*1024*4,Ol=1024*1024*4,hs=class{buffer;maxBufferSize;lengthDecoder;maxDataLength;encodingLength;constructor(e={}){this.buffer=new P,this.maxBufferSize=e.maxBufferSize??Ul,this.maxDataLength=e.maxDataLength??Ol,this.lengthDecoder=e.lengthDecoder??Ie,this.encodingLength=e.encodingLength??q}*decode(e){if(this.buffer.append(e),this.buffer.byteLength>this.maxBufferSize)throw new ae(`Buffer length limit exceeded - ${this.buffer.byteLength}/${this.maxBufferSize}`);for(;;){let r;try{r=this.lengthDecoder(this.buffer)}catch(s){if(s instanceof RangeError)break;throw s}if(r<0||r>this.maxDataLength)throw new Tt("Invalid message length");let n=this.encodingLength(r),o=n+r;if(this.buffer.byteLength>=o){let s=this.buffer.sublist(n,o);this.buffer.consume(o),s.byteLength>0&&(yield s)}else break}}};function Rl(t){return!!(t.startsWith("169.254.")||t.toLowerCase().startsWith("fe80"))}var $l=["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 ds(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=zl(t);return r||"Object"}function zl(t){let e=Object.prototype.toString.call(t).slice(8,-1);if($l.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 or=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",Vl=new TextEncoder;function tn(t){return or&&globalThis.Buffer.isBuffer(t)}function sr(t){return t instanceof Uint8Array?tn(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):t:Uint8Array.from(t)}var jl=24,ql=200,rn=or?t=>t.length>=jl?globalThis.Buffer.from(t):ma(t):t=>t.length>=ql?Vl.encode(t):ma(t),Ee=t=>Uint8Array.from(t),pa=or?(t,e,r)=>tn(t)?new Uint8Array(t.subarray(e,r)):t.slice(e,r):(t,e,r)=>t.slice(e,r),ga=or?(t,e)=>(t=t.map(r=>r instanceof Uint8Array?r:globalThis.Buffer.from(r)),sr(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},ms=or?t=>globalThis.Buffer.allocUnsafe(t):t=>new Uint8Array(t);function Dt(t,e){if(tn(t)&&tn(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 ma(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 Wl=256,ir=class{constructor(e=Wl){this.chunkSize=e,this.cursor=0,this.maxCursor=-1,this.chunks=[],this._initReuseChunk=null}reset(){this.cursor=0,this.maxCursor=-1,this.chunks.length&&(this.chunks=[]),this._initReuseChunk!==null&&(this.chunks.push(this._initReuseChunk),this.maxCursor=this._initReuseChunk.length-1)}pushByte(e){let r=this.chunks[this.chunks.length-1];this.cursor>this.maxCursor&&(r=ms(this.chunkSize),this.chunks.push(r),this.maxCursor+=r.length,this._initReuseChunk===null&&(this._initReuseChunk=r));let n=r.length-(this.maxCursor-this.cursor)-1;r[n]=e,this.cursor++}push(e){let r=this.chunks[this.chunks.length-1];if(this.cursor+e.length<=this.maxCursor+1){let o=r.length-(this.maxCursor-this.cursor)-1;r.set(e,o)}else{if(r){let o=r.length-(this.maxCursor-this.cursor)-1;o<r.length&&(this.chunks[this.chunks.length-1]=r.subarray(0,o),this.maxCursor=this.cursor-1)}e.length<64&&e.length<this.chunkSize?(r=ms(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=pa(n,0,this.cursor)}else r=ga(this.chunks,this.cursor);return e&&this.reset(),r}},nn=class{constructor(e){this.dest=e,this.cursor=0,this.chunks=[e]}reset(){this.cursor=0}pushByte(e){if(this.cursor>=this.dest.length)throw new Error("write out of bounds, destination buffer is too small");this.dest[this.cursor++]=e}push(e){if(this.cursor+e.length>this.dest.length)throw new Error("write out of bounds, destination buffer is too small");this.dest.set(e,this.cursor),this.cursor+=e.length}toBytes(e=!1){let r=this.dest.subarray(0,this.cursor);return e&&this.reset(),r}};var g="CBOR decode error:",on="CBOR encode error:",ar=[];ar[23]=1;ar[24]=2;ar[25]=3;ar[26]=5;ar[27]=9;function De(t,e,r){if(t.length-e<r)throw new Error(`${g} not enough data for type`)}var $=[24,256,65536,4294967296,BigInt("18446744073709551616")];function Y(t,e,r){De(t,e,1);let n=t[e];if(r.strict===!0&&n<$[0])throw new Error(`${g} integer encoded in more bytes than necessary (strict decode)`);return n}function ee(t,e,r){De(t,e,2);let n=t[e]<<8|t[e+1];if(r.strict===!0&&n<$[1])throw new Error(`${g} integer encoded in more bytes than necessary (strict decode)`);return n}function te(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<$[2])throw new Error(`${g} integer encoded in more bytes than necessary (strict decode)`);return n}function re(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<$[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 ya(t,e,r,n){return new m(c.uint,Y(t,e+1,n),2)}function ba(t,e,r,n){return new m(c.uint,ee(t,e+1,n),3)}function xa(t,e,r,n){return new m(c.uint,te(t,e+1,n),5)}function wa(t,e,r,n){return new m(c.uint,re(t,e+1,n),9)}function _e(t,e){return F(t,0,e.value)}function F(t,e,r){if(r<$[0]){let n=Number(r);t.pushByte(e|n)}else if(r<$[1]){let n=Number(r);t.push([e|24,n])}else if(r<$[2]){let n=Number(r);t.push([e|25,n>>>8,n&255])}else if(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<$[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`)}}_e.encodedSize=function(e){return F.encodedSize(e.value)};F.encodedSize=function(e){return e<$[0]?1:e<$[1]?2:e<$[2]?3:e<$[3]?5:9};_e.compareTokens=function(e,r){return e.value<r.value?-1:e.value>r.value?1:0};function Ea(t,e,r,n){return new m(c.negint,-1-Y(t,e+1,n),2)}function _a(t,e,r,n){return new m(c.negint,-1-ee(t,e+1,n),3)}function va(t,e,r,n){return new m(c.negint,-1-te(t,e+1,n),5)}var ps=BigInt(-1),Sa=BigInt(1);function Ca(t,e,r,n){let o=re(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,ps-BigInt(o),9)}function sn(t,e){let r=e.value,n=typeof r=="bigint"?r*ps-Sa:r*-1-1;F(t,e.type.majorEncoded,n)}sn.encodedSize=function(e){let r=e.value,n=typeof r=="bigint"?r*ps-Sa:r*-1-1;return n<$[0]?1:n<$[1]?2:n<$[2]?3:n<$[3]?5:9};sn.compareTokens=function(e,r){return e.value<r.value?1:e.value>r.value?-1:0};function cr(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 Ia(t,e,r,n){return cr(t,e,1,r)}function La(t,e,r,n){return cr(t,e,2,Y(t,e+1,n))}function Aa(t,e,r,n){return cr(t,e,3,ee(t,e+1,n))}function Ta(t,e,r,n){return cr(t,e,5,te(t,e+1,n))}function Da(t,e,r,n){let o=re(t,e+1,n);if(typeof o=="bigint")throw new Error(`${g} 64-bit integer bytes lengths not supported`);return cr(t,e,9,o)}function an(t){return t.encodedBytes===void 0&&(t.encodedBytes=c.equals(t.type,c.string)?rn(t.value):t.value),t.encodedBytes}function kt(t,e){let r=an(e);F(t,e.type.majorEncoded,r.length),t.push(r)}kt.encodedSize=function(e){let r=an(e);return F.encodedSize(r.length)+r.length};kt.compareTokens=function(e,r){return Hl(an(e),an(r))};function Hl(t,e){return t.length<e.length?-1:t.length>e.length?1:Dt(t,e)}var ka=new TextDecoder,Xl=32;function Kl(t,e,r){if(r-e<Xl){let o="";for(let s=e;s<r;s++){let i=t[s];if(i&128)return ka.decode(t.subarray(e,r));o+=String.fromCharCode(i)}return o}return ka.decode(t.subarray(e,r))}function ur(t,e,r,n,o){let s=r+n;De(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 ur(t,e,1,r,n)}function Pa(t,e,r,n){return ur(t,e,2,Y(t,e+1,n),n)}function Ma(t,e,r,n){return ur(t,e,3,ee(t,e+1,n),n)}function Fa(t,e,r,n){return ur(t,e,5,te(t,e+1,n),n)}function Na(t,e,r,n){let o=re(t,e+1,n);if(typeof o=="bigint")throw new Error(`${g} 64-bit integer string lengths not supported`);return ur(t,e,9,o,n)}var Ua=kt;function Bt(t,e,r,n){return new m(c.array,n,r)}function Oa(t,e,r,n){return Bt(t,e,1,r)}function Ra(t,e,r,n){return Bt(t,e,2,Y(t,e+1,n))}function $a(t,e,r,n){return Bt(t,e,3,ee(t,e+1,n))}function za(t,e,r,n){return Bt(t,e,5,te(t,e+1,n))}function Va(t,e,r,n){let o=re(t,e+1,n);if(typeof o=="bigint")throw new Error(`${g} 64-bit integer array lengths not supported`);return Bt(t,e,9,o)}function ja(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${g} indefinite length items not allowed`);return Bt(t,e,1,1/0)}function cn(t,e){F(t,c.array.majorEncoded,e.value)}cn.compareTokens=_e.compareTokens;cn.encodedSize=function(e){return F.encodedSize(e.value)};function Pt(t,e,r,n){return new m(c.map,n,r)}function qa(t,e,r,n){return Pt(t,e,1,r)}function Wa(t,e,r,n){return Pt(t,e,2,Y(t,e+1,n))}function Ga(t,e,r,n){return Pt(t,e,3,ee(t,e+1,n))}function Ha(t,e,r,n){return Pt(t,e,5,te(t,e+1,n))}function Qa(t,e,r,n){let o=re(t,e+1,n);if(typeof o=="bigint")throw new Error(`${g} 64-bit integer map lengths not supported`);return Pt(t,e,9,o)}function Xa(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${g} indefinite length items not allowed`);return Pt(t,e,1,1/0)}function un(t,e){F(t,c.map.majorEncoded,e.value)}un.compareTokens=_e.compareTokens;un.encodedSize=function(e){return F.encodedSize(e.value)};function Ka(t,e,r,n){return new m(c.tag,r,1)}function Ja(t,e,r,n){return new m(c.tag,Y(t,e+1,n),2)}function Za(t,e,r,n){return new m(c.tag,ee(t,e+1,n),3)}function Ya(t,e,r,n){return new m(c.tag,te(t,e+1,n),5)}function ec(t,e,r,n){return new m(c.tag,re(t,e+1,n),9)}function fn(t,e){F(t,c.tag.majorEncoded,e.value)}fn.compareTokens=_e.compareTokens;fn.encodedSize=function(e){return F.encodedSize(e.value)};var ln=20,hn=21,dn=22,mn=23;function rc(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 nc(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 gs(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 oc(t,e,r,n){return gs(pn(t,e+1),3,n)}function sc(t,e,r,n){return gs(gn(t,e+1),5,n)}function ic(t,e,r,n){return gs(uc(t,e+1),9,n)}function fr(t,e,r){let n=e.value;if(n===!1)t.pushByte(c.float.majorEncoded|ln);else if(n===!0)t.pushByte(c.float.majorEncoded|hn);else if(n===null)t.pushByte(c.float.majorEncoded|dn);else if(n===void 0)t.pushByte(c.float.majorEncoded|mn);else{let o,s=!1;(!r||r.float64!==!0)&&(ys(n),o=pn(N,1),n===o||Number.isNaN(n)?(N[0]=249,t.push(N.slice(0,3)),s=!0):(bs(n),o=gn(N,1),n===o&&(N[0]=250,t.push(N.slice(0,5)),s=!0))),s||(cc(n),o=uc(N,1),N[0]=251,t.push(N.slice(0,9)))}}fr.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){ys(n);let o=pn(N,1);if(n===o||Number.isNaN(n))return 3;if(bs(n),o=gn(N,1),n===o)return 5}return 9};var ac=new ArrayBuffer(9),ce=new DataView(ac,1),N=new Uint8Array(ac,0);function ys(t){if(t===1/0)ce.setUint16(0,31744,!1);else if(t===-1/0)ce.setUint16(0,64512,!1);else if(Number.isNaN(t))ce.setUint16(0,32256,!1);else{ce.setFloat32(0,t);let e=ce.getUint32(0),r=(e&2139095040)>>23,n=e&8388607;if(r===255)ce.setUint16(0,31744,!1);else if(r===0)ce.setUint16(0,(e&2147483648)>>16|n>>13,!1);else{let o=r-127;o<-24?ce.setUint16(0,0):o<-14?ce.setUint16(0,(e&2147483648)>>16|1<<24+o,!1):ce.setUint16(0,(e&2147483648)>>16|o+15<<10|n>>13,!1)}}}function pn(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 bs(t){ce.setFloat32(0,t,!1)}function gn(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 cc(t){ce.setFloat64(0,t,!1)}function uc(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)}function th(t,e){let r=t.value;if(r===!1)return Uint8Array.of(c.float.majorEncoded|ln);if(r===!0)return Uint8Array.of(c.float.majorEncoded|hn);if(r===null)return Uint8Array.of(c.float.majorEncoded|dn);if(r===void 0)return Uint8Array.of(c.float.majorEncoded|mn);if(!e){if(ys(r),r===pn(N,1)||Number.isNaN(r))return N[0]=249,N.slice(0,3);if(bs(r),r===gn(N,1))return N[0]=250,N.slice(0,5)}return cc(r),N[0]=251,N.slice(0,9)}function tc(t,e){let r=t,n=e?.float64===!0,o=n?r._keyBytesFloat64:r._keyBytes;if(o!==void 0)return o;let s=th(t,n);return n?r._keyBytesFloat64=s:r._keyBytes=s,s}fr.compareTokens=function(e,r,n){let o=tc(e,n),s=tc(r,n);return o.length!==s.length?o.length<s.length?-1:1:Dt(o,s)};function v(t,e,r){throw new Error(`${g} encountered invalid minor (${r}) for major ${t[e]>>>5}`)}function yn(t){return()=>{throw new Error(`${g} ${t}`)}}var d=[];for(let t=0;t<=23;t++)d[t]=v;d[24]=ya;d[25]=ba;d[26]=xa;d[27]=wa;d[28]=v;d[29]=v;d[30]=v;d[31]=v;for(let t=32;t<=55;t++)d[t]=v;d[56]=Ea;d[57]=_a;d[58]=va;d[59]=Ca;d[60]=v;d[61]=v;d[62]=v;d[63]=v;for(let t=64;t<=87;t++)d[t]=Ia;d[88]=La;d[89]=Aa;d[90]=Ta;d[91]=Da;d[92]=v;d[93]=v;d[94]=v;d[95]=yn("indefinite length bytes/strings are not supported");for(let t=96;t<=119;t++)d[t]=Ba;d[120]=Pa;d[121]=Ma;d[122]=Fa;d[123]=Na;d[124]=v;d[125]=v;d[126]=v;d[127]=yn("indefinite length bytes/strings are not supported");for(let t=128;t<=151;t++)d[t]=Oa;d[152]=Ra;d[153]=$a;d[154]=za;d[155]=Va;d[156]=v;d[157]=v;d[158]=v;d[159]=ja;for(let t=160;t<=183;t++)d[t]=qa;d[184]=Wa;d[185]=Ga;d[186]=Ha;d[187]=Qa;d[188]=v;d[189]=v;d[190]=v;d[191]=Xa;for(let t=192;t<=215;t++)d[t]=Ka;d[216]=Ja;d[217]=Za;d[218]=Ya;d[219]=ec;d[220]=v;d[221]=v;d[222]=v;d[223]=v;for(let t=224;t<=243;t++)d[t]=yn("simple values are not supported");d[244]=v;d[245]=v;d[246]=v;d[247]=rc;d[248]=yn("simple values are not supported");d[249]=oc;d[250]=sc;d[251]=ic;d[252]=v;d[253]=v;d[254]=v;d[255]=nc;var me=[];for(let t=0;t<24;t++)me[t]=new m(c.uint,t,1);for(let t=-1;t>=-24;t--)me[31-t]=new m(c.negint,t,1);me[64]=new m(c.bytes,new Uint8Array(0),1);me[96]=new m(c.string,"",1);me[128]=new m(c.array,0,1);me[160]=new m(c.map,0,1);me[244]=new m(c.false,!1,1);me[245]=new m(c.true,!0,1);me[246]=new m(c.null,null,1);function xs(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 nh={float64:!1,mapSorter:Es,quickEncodeToken:xs},mc=Object.freeze({mapSorter:ih,quickEncodeToken:xs});function oh(){let t=[];return t[c.uint.major]=_e,t[c.negint.major]=sn,t[c.bytes.major]=kt,t[c.string.major]=Ua,t[c.array.major]=cn,t[c.map.major]=un,t[c.tag.major]=fn,t[c.float.major]=fr,t}var it=oh(),bn=new ir,Ft=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(`${on} 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)},ve={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=Ft.createCheck(n,t);let o=[],s=0;for(let i of t)o[s++]=st(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=Ft.createCheck(n,t);let u=!o&&r.ignoreUndefinedProperties,h=0;for(let f of s){let l=o?t.get(f):t[f];u&&l===void 0||(a[h++]=[st(f,r,n),st(l,r,n)])}h<i&&(a.length=h)}return a?.length?(sh(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),st(t.value,r,n)]}};ve.Map=ve.Object;ve.Buffer=ve.Uint8Array;for(let t of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))ve[`${t}Array`]=ve.DataView;function st(t,e={},r){let n=ds(t),o=e&&e.typeEncoders&&e.typeEncoders[n]||ve[n];if(typeof o=="function"){let i=o(t,n,e,r);if(i!=null)return i}let s=ve[n];if(!s)throw new Error(`${on} unsupported type: ${n}`);return s(t,n,e,r)}function sh(t,e){let r=e.mapSorter;r&&t.sort((n,o)=>r(n,o,e))}function Es(t,e,r){let n=Array.isArray(t[0])?t[0][0]:t[0],o=Array.isArray(e[0])?e[0][0]:e[0];if(n.type.major!==o.type.major)return n.type.compare(o.type);let s=n.type.major,i=it[s].compareTokens(n,o,r);return i===0&&console.warn("WARNING: complex key types used, CBOR key sorting guarantees are gone"),i}function ih(t,e){if(t[0]instanceof m&&e[0]instanceof m){let r=t[0],n=e[0];return r._keyBytes||(r._keyBytes=fc(r.value)),n._keyBytes||(n._keyBytes=fc(n.value)),Dt(r._keyBytes,n._keyBytes)}throw new Error("rfc8949MapSorter: complex key types are not supported yet")}function fc(t){return pc(t,it,mc)}function Mt(t,e,r,n){if(Array.isArray(e))for(let o of e)Mt(t,o,r,n);else r[e.type.major](t,e,n)}var lc=c.uint.majorEncoded,hc=c.negint.majorEncoded,ah=c.bytes.majorEncoded,ch=c.string.majorEncoded,dc=c.array.majorEncoded,ws=c.map.majorEncoded,uh=c.float.majorEncoded|ln,fh=c.float.majorEncoded|hn,lh=c.float.majorEncoded|dn,hh=c.float.majorEncoded|mn,dh=BigInt(-1),mh=BigInt(1);function Ve(t,e,r){r<24?t.pushByte(e|Number(r)):F(t,e,r)}function ph(t){return t.addBreakTokens!==!0}function gh(t,e,r,n,o){let s=r==="Map",i=s?e.keys():Object.keys(e),a=s?e.size:i.length;if(!a){t.pushByte(ws);return}o=Ft.createCheck(o,e);let u=!s&&n.ignoreUndefinedProperties,h=new Array(a),f=0;for(let l of i){let p=s?e.get(l):e[l];u&&p===void 0||(h[f++]=[st(l,n,o),p])}if(f===0){t.pushByte(ws);return}f<a&&(h.length=f),h.sort((l,p)=>Es(l,p,n)),Ve(t,ws,f);for(let[l,p]of h)Mt(t,l,it,n),_s(t,p,n,o)}function _s(t,e,r,n){let o=ds(e),s=r.typeEncoders&&r.typeEncoders[o];if(s){let i=s(e,o,r,n);if(i!=null){Mt(t,i,it,r);return}}switch(o){case"null":t.pushByte(lh);return;case"undefined":t.pushByte(hh);return;case"boolean":t.pushByte(e?fh:uh);return;case"number":!Number.isInteger(e)||!Number.isSafeInteger(e)?fr(t,new m(c.float,e),r):e>=0?Ve(t,lc,e):Ve(t,hc,e*-1-1);return;case"bigint":e>=BigInt(0)?Ve(t,lc,e):Ve(t,hc,e*dh-mh);return;case"string":{let i=rn(e);Ve(t,ch,i.length),t.push(i);return}case"Uint8Array":Ve(t,ah,e.length),t.push(e);return;case"Array":if(!e.length){t.pushByte(dc);return}n=Ft.createCheck(n,e),Ve(t,dc,e.length);for(let i of e)_s(t,i,r,n);return;case"Object":case"Map":if(r.mapSorter===Es)gh(t,e,o,r,n);else{let i=ve.Object(e,o,r,n);Mt(t,i,it,r)}return;default:{let i=ve[o];if(!i)throw new Error(`${on} unsupported type: ${o}`);let a=i(e,o,r,n);Mt(t,a,it,r)}}}function pc(t,e,r,n){let o=n instanceof Uint8Array,s=o?new nn(n):bn,i=st(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 h=u.encodedSize(i,r);if(o||(s=new ir(h)),u(s,i,r),s.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${i} was wrong`);return o?s.toBytes():sr(s.chunks[0])}}return s.reset(),Mt(s,i,e,r),s.toBytes(!0)}function vs(t,e){return e=Object.assign({},nh,e),ph(e)?(bn.reset(),_s(bn,t,e,void 0),bn.toBytes(!0)):pc(t,it,e)}var yh={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},xn=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=me[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}},je=Symbol.for("DONE"),Nt=Symbol.for("BREAK");function bh(t,e,r){let n=[];for(let o=0;o<t.value;o++){let s=qe(e,r);if(s===Nt){if(t.value===1/0)break;throw new Error(`${g} got unexpected break to lengthed array`)}if(s===je)throw new Error(`${g} found array but not enough entries (got ${o}, expected ${t.value})`);n[o]=s}return n}function xh(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=qe(e,r);if(u===Nt){if(t.value===1/0)break;throw new Error(`${g} got unexpected break to lengthed map`)}if(u===je)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 h=qe(e,r);if(h===je)throw new Error(`${g} found map but not enough entries (got ${a} [no value], expected ${t.value})`);n?i.set(u,h):u==="__proto__"?Object.defineProperty(s,u,{value:h,configurable:!0,enumerable:!0,writable:!0}):s[u]=h}return n?i:s}function*wh(t,e,r){for(let n=0;n<t.value;n++){let o=qe(e,r);if(o===Nt){if(t.value===1/0)break;throw new Error(`${g} got unexpected break to lengthed map`)}if(o===je)throw new Error(`${g} found map but not enough entries (got ${n} [no key], expected ${t.value})`);let s=qe(e,r);if(s===je)throw new Error(`${g} found map but not enough entries (got ${n} [no value], expected ${t.value})`);yield[o,s]}}function Eh(t,e){let r=function(){if(r._called)throw new Error(`${g} tag decode() may only be called once`);r._called=!0;let n=qe(t,e);if(n===je)throw new Error(`${g} tag content missing`);if(n===Nt)throw new Error(`${g} got unexpected break in tag content`);return n};return r.entries=function(){if(r._called)throw new Error(`${g} tag decode() may only be called once`);r._called=!0;let n=t.next();if(!c.equals(n.type,c.map))throw new Error(`${g} entries() requires map content, got ${n.type.name}`);let o=[];for(let s of wh(n,t,e))o.push(s);return o},r._called=!1,r}function qe(t,e){if(t.done())return je;let r=t.next();if(c.equals(r.type,c.break))return Nt;if(r.type.terminal)return r.value;if(c.equals(r.type,c.array))return bh(r,t,e);if(c.equals(r.type,c.map))return xh(r,t,e);if(c.equals(r.type,c.tag)){if(e.tags&&typeof e.tags[r.value]=="function"){let n=Eh(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 gc(t,e){if(!(t instanceof Uint8Array))throw new Error(`${g} data to decode must be a Uint8Array`);e=Object.assign({},yh,e);let r=sr(t),n=e.tokenizer||new xn(r,e),o=qe(n,e);if(o===je)throw new Error(`${g} did not find any content to decode`);if(o===Nt)throw new Error(`${g} got unexpected break`);return[o,t.subarray(n.pos())]}function Ss(t,e){let[r,n]=gc(t,e);if(n.length>0)throw new Error(`${g} too many terminals, data makes no sense`);return r}var wn=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(wn.prototype,Symbol.toStringTag,{value:"Tagged"});var En=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},Ut=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},_n=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"},lr=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};function vn(t){return t[Symbol.asyncIterator]!=null}function yc(t,e){if(t.byteLength>e)throw new Ut("Message length too long")}var Cn=t=>{let e=q(t),r=Z(e);return Br(t,r),Cn.bytes=e,r};Cn.bytes=0;function In(t,e){e=e??{};let r=e.lengthEncoder??Cn,n=e?.maxDataLength??4194304;function*o(s){yc(s,n);let i=r(s.byteLength);i instanceof Uint8Array?yield i:yield*i,s instanceof Uint8Array?yield s:yield*s}return vn(t)?(async function*(){for await(let s of t)yield*o(s)})():(function*(){for(let s of t)yield*o(s)})()}In.single=(t,e)=>{e=e??{};let r=e.lengthEncoder??Cn,n=e?.maxDataLength??4194304;return yc(t,n),new P(r(t.byteLength),t)};var at;(function(t){t[t.LENGTH=0]="LENGTH",t[t.DATA=1]="DATA"})(at||(at={}));var Cs=t=>{let e=Ie(t);return Cs.bytes=q(e),e};Cs.bytes=0;function hr(t,e){let r=new P,n=at.LENGTH,o=-1,s=e?.lengthDecoder??Cs,i=e?.maxLengthLength??8,a=e?.maxDataLength??4194304;function*u(){for(;r.byteLength>0;){if(n===at.LENGTH)try{if(o=s(r),o<0)throw new En("Invalid message length");if(o>a)throw new Ut("Message length too long");let h=s.bytes;r.consume(h),e?.onLength!=null&&e.onLength(o),n=at.DATA}catch(h){if(h instanceof RangeError){if(r.byteLength>i)throw new _n("Message length length too long");break}throw h}if(n===at.DATA){if(r.byteLength<o)break;let h=r.sublist(0,o);r.consume(o),e?.onData!=null&&e.onData(h),yield h,n=at.LENGTH}}}return vn(t)?(async function*(){for await(let h of t)r.append(h),yield*u();if(r.byteLength>0)throw new lr("Unexpected end of input")})():(function*(){for(let h of t)r.append(h),yield*u();if(r.byteLength>0)throw new lr("Unexpected end of input")})()}hr.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 hr(n,{...e??{},onLength:s=>{r=s}})};var Is=class extends rt{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()}},bc=30,Ls=class extends rr{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)+bc,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 hr(this.input,{maxDataLength:this.maxMessageSize}))this.onMessage(Ss(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=vs(e),n=In.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 Is({...this.streamOptions,...n,id:e,direction:r,log:this.log.newScope(`stream:${r}:${e}`),sendMessage:this.sendMessage,encoding:this.encoding,maxMessageSize:this.maxMessageSize-bc,protocol:""})}},As=class{protocol="/mock-muxer/1.0.0";init;constructor(e){this.init=e}createStreamMuxer(e){return new Ls(e,{...this.init})}};function Ln(t={}){return new As(t)}function An(t,e){if(typeof t=="string")return Ch(t);if(typeof t=="number")return Ah(t,e);throw new Error(`Value provided to ms() must be a string or number. value=${JSON.stringify(t)}`)}function Ch(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 Ih(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?ct(t,e,315576e5,"year"):e>=26298e5?ct(t,e,26298e5,"month"):e>=6048e5?ct(t,e,6048e5,"week"):e>=864e5?ct(t,e,864e5,"day"):e>=36e5?ct(t,e,36e5,"hour"):e>=6e4?ct(t,e,6e4,"minute"):e>=1e3?ct(t,e,1e3,"second"):`${t} ms`}function Ah(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):Ih(t)}function ct(t,e,r,n){let o=e>=r*1.5;return`${Math.round(t/r)} ${n}${o?"s":""}`}function Ts(t){r.debug=r,r.default=r,r.coerce=u,r.disable=s,r.enable=o,r.enabled=i,r.humanize=An,r.destroy=h,Object.keys(t).forEach(f=>{r[f]=t[f]}),r.names=[],r.skips=[],r.formatters={};function e(f){let l=0;for(let p=0;p<f.length;p++)l=(l<<5)-l+f.charCodeAt(p),l|=0;return r.colors[Math.abs(l)%r.colors.length]}r.selectColor=e;function r(f,l){let p,E=null,ne,G;function x(...b){if(!x.enabled)return;let C=x,D=Number(new Date),T=D-(p||D);C.diff=T,C.prev=p,C.curr=D,p=D,b[0]=r.coerce(b[0]),typeof b[0]!="string"&&b.unshift("%O");let B=0;b[0]=b[0].replace(/%([a-zA-Z%])/g,(V,oe)=>{if(V==="%%")return"%";B++;let ue=r.formatters[oe];if(typeof ue=="function"){let K=b[B];V=ue.call(C,K),b.splice(B,1),B--}return V}),r.formatArgs.call(C,b),l?.onLog!=null&&l.onLog(...b),(C.log||r.log).apply(C,b)}return x.namespace=f,x.useColors=r.useColors(),x.color=r.selectColor(f),x.extend=n,x.destroy=r.destroy,Object.defineProperty(x,"enabled",{enumerable:!0,configurable:!1,get:()=>E!==null?E:(ne!==r.namespaces&&(ne=r.namespaces,G=r.enabled(f)),G),set:b=>{E=b}}),typeof r.init=="function"&&r.init(x),x}function n(f,l){let p=r(this.namespace+(typeof l>"u"?":":l)+f);return p.log=this.log,p}function o(f){r.save(f),r.namespaces=f,r.names=[],r.skips=[];let l,p=(typeof f=="string"?f:"").split(/[\s,]+/),E=p.length;for(l=0;l<E;l++)p[l]&&(f=p[l].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(l=>"-"+l)].join(",");return r.enable(""),f}function i(f){if(f[f.length-1]==="*")return!0;let l,p;for(l=0,p=r.skips.length;l<p;l++)if(r.skips[l].test(f))return!1;for(l=0,p=r.names.length;l<p;l++)if(r.names[l].test(f))return!0;return!1}function a(f){return f.toString().substring(2,f.toString().length-2).replace(/\.\*\?$/,"*")}function u(f){return f instanceof Error?f.stack??f.message:f}function h(){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 Tn=Fh(),Th=["#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 Dh(){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 kh(t){if(t[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+t[0]+(this.useColors?"%c ":" ")+"+"+An(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 Bh=console.debug??console.log??(()=>{});function Ph(t){try{t?Tn?.setItem("debug",t):Tn?.removeItem("debug")}catch{}}function Mh(){let t;try{t=Tn?.getItem("debug")}catch{}return!t&&typeof globalThis.process<"u"&&"env"in globalThis.process&&(t=globalThis.process.env.DEBUG),t}function Fh(){try{return localStorage}catch{}}function Nh(t){t.j=function(e){try{return JSON.stringify(e)}catch(r){return"[UnexpectedJSONParseError]: "+r.message}}}var xc=Ts({formatArgs:kh,save:Ph,load:Mh,useColors:Dh,setupFormatters:Nh,colors:Th,storage:Tn,log:Bh});var Q=xc;Q.formatters.b=t=>t==null?"undefined":ie.baseEncode(t);Q.formatters.t=t=>t==null?"undefined":pe.baseEncode(t);Q.formatters.m=t=>t==null?"undefined":Wn.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 wc(t,e=""){let r=Ec(t.message),n=Ec(t.stack);return r!=null&&n!=null?n.includes(r)?`${n.split(`
2
+ "use strict";var Libp2PUtils=(()=>{var kc=Object.create;var gr=Object.defineProperty;var Bc=Object.getOwnPropertyDescriptor;var Pc=Object.getOwnPropertyNames;var Mc=Object.getPrototypeOf,Fc=Object.prototype.hasOwnProperty;var Mn=(t,e)=>()=>{try{return e||t((e={exports:{}}).exports,e),e.exports}catch(r){throw e=0,r}},Z=(t,e)=>{for(var r in e)gr(t,r,{get:e[r],enumerable:!0})},Os=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Pc(e))!Fc.call(t,o)&&o!==r&&gr(t,o,{get:()=>e[o],enumerable:!(n=Bc(e,o))||n.enumerable});return t};var Nc=(t,e,r)=>(r=t!=null?kc(Mc(t)):{},Os(e||!t||!t.__esModule?gr(r,"default",{value:t,enumerable:!0}):r,t)),Uc=t=>Os(gr({},"__esModule",{value:!0}),t);var po=Mn(_t=>{"use strict";Object.defineProperty(_t,"__esModule",{value:!0});_t.Netmask4Impl=void 0;_t.ip2long=Et;_t.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 lf=48,hf=97,df=65;function mf(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)-lf)>>>0;else if(r===16)if("a"<=t[o]&&t[o]<="f")e=e*r+(10+t.charCodeAt(o)-hf)>>>0;else if("A"<=t[o]&&t[o]<="F")e=e*r+(10+t.charCodeAt(o)-df)>>>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 Et(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]=mf(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 mo=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=Et(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=(Et(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):(Et(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=Et(this.first),n=Et(this.last),o=0;for(;r<=n;)e(xe(r),r,o),o++,r++}toString(){return this.base+"/"+this.bitmask}};_t.Netmask4Impl=mo});var Si=Mn(vt=>{"use strict";Object.defineProperty(vt,"__esModule",{value:!0});vt.Netmask6Impl=void 0;vt.ip6bigint=yo;vt.bigint2ip6=Ye;var pf=po(),go=(1n<<128n)-1n;function yo(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,pf.ip2long)(n),s=t.substring(0,r+1)+"0:0";return vi(s)&~0xffffffffn|BigInt(o)}return vi(t)}function vi(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 Ye(t){if(t<0n||t>go)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 bo=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=go>>BigInt(128-this.bitmask)<<BigInt(128-this.bitmask);try{this.netBigint=yo(e)&this.maskBigint}catch{throw new Error("Invalid IPv6 net address: "+e)}this.size=Number(1n<<BigInt(128-this.bitmask)),this.base=Ye(this.netBigint),this.mask=Ye(this.maskBigint),this.hostmask=Ye(~this.maskBigint&go),this.first=this.base,this.last=Ye(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):(yo(e)&this.maskBigint)===this.netBigint}next(e=1){let r=1n<<BigInt(128-this.bitmask);return new t(Ye(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(Ye(r),Number(r),s),s++,r++}toString(){return this.base+"/"+this.bitmask}};vt.Netmask6Impl=bo});var Ci=Mn(Ue=>{"use strict";Object.defineProperty(Ue,"__esModule",{value:!0});Ue.long2ip=Ue.ip2long=Ue.Netmask=void 0;var Tr=po();Object.defineProperty(Ue,"ip2long",{enumerable:!0,get:function(){return Tr.ip2long}});Object.defineProperty(Ue,"long2ip",{enumerable:!0,get:function(){return Tr.long2ip}});var gf=Si(),wo=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 gf.Netmask6Impl(e,r):this._impl=new Tr.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 Tr.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=wo});var td={};Z(td,{AbstractMessageStream:()=>rt,AbstractMultiaddrConnection:()=>nr,AbstractStream:()=>nt,AbstractStreamMuxer:()=>or,AdaptiveTimeout:()=>us,BloomFilter:()=>Gt,CuckooFilter:()=>Pe,DEFAULT_FAILURE_MULTIPLIER:()=>ea,DEFAULT_INTERVAL:()=>na,DEFAULT_MAX_TIMEOUT:()=>ra,DEFAULT_MIN_TIMEOUT:()=>ta,DEFAULT_TIMEOUT_MULTIPLIER:()=>Yi,InvalidDataLengthError:()=>Yr,InvalidDataLengthLengthError:()=>en,InvalidMessageLengthError:()=>kt,LengthPrefixedDecoder:()=>ms,MaxEarlyStreamsError:()=>tr,MemoryStorage:()=>Pn,MockStream:()=>ks,MovingAverage:()=>ot,PeerQueue:()=>Ms,PriorityQueue:()=>Fs,Queue:()=>de,QueueFullError:()=>er,RateLimitError:()=>Yt,RateLimiter:()=>Ns,ScalableCuckooFilter:()=>Ht,StreamClosedError:()=>rr,UnexpectedEOFError:()=>$e,UnwrappedError:()=>sr,byteStream:()=>la,circuitRelayAddressesLast:()=>Ki,createBloomFilter:()=>hi,createCuckooFilter:()=>di,createScalableCuckooFilter:()=>mi,debounce:()=>Dt,defaultMultiaddrSorter:()=>cl,echo:()=>ds,echoStream:()=>Zh,getNetConfig:()=>le,getThinWaistAddresses:()=>Sl,ipPortToMultiaddr:()=>Il,isAsyncGenerator:()=>Ll,isGenerator:()=>Al,isGlobalUnicast:()=>cf,isGlobalUnicastIp:()=>Cl,isLinkLocal:()=>uf,isLinkLocalIp:()=>ql,isLoopback:()=>Ar,isNetworkAddress:()=>ff,isPrivate:()=>Dr,isPrivateIp:()=>Eo,isPromise:()=>cs,loopbackAddressLast:()=>Qi,lpStream:()=>ha,messageStreamToDuplex:()=>da,mockMuxer:()=>Tn,multiaddrConnectionPair:()=>Ps,pbStream:()=>Rl,pipe:()=>zl,publicAddressesFirst:()=>Xi,reliableTransportsFirst:()=>Hi,repeatingTask:()=>Jh,streamPair:()=>Tc,trackedList:()=>Yh,trackedMap:()=>ed,tryGetNetConfig:()=>vr});function H(t=0){return new Uint8Array(t)}function Y(t=0){return new Uint8Array(t)}function Oc(t){return t?.buffer instanceof ArrayBuffer}function Fn(t){if(Oc(t))return t;let e=t.slice();return new Uint8Array(e.buffer,0,e.byteLength)}function Ce(t,e){e==null&&(e=t.reduce((o,s)=>o+s.length,0));let r=Y(e),n=0;for(let o of t)r.set(o,n),n+=o.length;return Fn(r)}function Ge(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 $s=Symbol.for("@achingbrain/uint8arraylist");function Rs(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 lt(t){return!!t?.[$s]}var P=class t{bufs;length;[$s]=!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(lt(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(lt(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=Rs(this.bufs,e);return r.buf[r.index]}set(e,r){let n=Rs(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(lt(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 Ce(n,o)}subarray(e,r){let{bufs:n,length:o}=this._subList(e,r);return n.length===1?n[0]:Ce(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(!lt(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=Y(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=Y(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(!Ge(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 $n={};Z($n,{base10:()=>Gc});var dd=new Uint8Array(0);function Vs(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 oe(t){if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return He(t);if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return He(new Uint8Array(t.buffer,t.byteOffset,t.byteLength));throw new Error("Unknown type, must be binary type")}function js(t){let e=new Uint8Array(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}var zs=4096;function qs(t){let e=t.length;if(e<=zs)return String.fromCharCode.apply(String,t);let r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.subarray(n,n+=zs));return r}function Rc(t){return t?.buffer instanceof ArrayBuffer}function He(t){return Rc(t)?t:t.slice()}function $c(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 X(b){if(b instanceof Uint8Array||(ArrayBuffer.isView(b)?b=new Uint8Array(b.buffer,b.byteOffset,b.byteLength):Array.isArray(b)&&(b=Uint8Array.from(b))),!(b instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(b.length===0)return"";for(var C=0,D=0,T=0,B=b.length;T!==B&&b[T]===0;)T++,C++;for(var K=(B-T)*x+1>>>0,ce=new Uint8Array(K);T!==B;){for(var j=b[T],pe=0,ue=K-1;(j!==0||pe<D)&&ue!==-1;ue--,pe++)j+=256*ce[ue]>>>0,ce[ue]=j%f>>>0,j=j/f>>>0;if(j!==0)throw new Error("Non-zero carry");D=pe,T++}for(var J=K-D;J!==K&&ce[J]===0;)J++;for(var Rt=h.repeat(C);J<K;++J)Rt+=t.charAt(ce[J]);return Rt}function M(b){if(typeof b!="string")throw new TypeError("Expected String");if(b.length===0)return new Uint8Array;var C=0;if(b[C]!==" "){for(var D=0,T=0;b[C]===h;)D++,C++;for(var B=(b.length-C)*p+1>>>0,K=new Uint8Array(B);b[C];){var ce=b.charCodeAt(C);if(ce>255)return;var j=n[ce];if(j===255)return;for(var pe=0,ue=B-1;(j!==0||pe<T)&&ue!==-1;ue--,pe++)j+=f*K[ue]>>>0,K[ue]=j%256>>>0,j=j/256>>>0;if(j!==0)throw new Error("Non-zero carry");T=pe,C++}if(b[C]!==" "){for(var J=B-T;J!==B&&K[J]===0;)J++;for(var Rt=new Uint8Array(D+(B-J)),Dc=D;J!==B;)Rt[Dc++]=K[J++];return Rt}}}function w(b){var C=M(b);if(C)return C;throw new Error(`Non-${e} character`)}return{encode:X,decodeUnsafe:M,decode:w}}var zc=$c,Vc=zc,Gs=Vc;var Nn=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")}},Un=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 Hs(this,e)}},On=class{decoders;constructor(e){this.decoders=e}or(e){return Hs(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 Hs(t,e){return new On({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var Rn=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 Nn(e,r,n),this.decoder=new Un(e,r,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function ht({name:t,prefix:e,encode:r,decode:n}){return new Rn(t,e,r,n)}function ke({name:t,prefix:e,alphabet:r,caseInsensitive:n=!1}){let{encode:o,decode:s}=Gs(r,t,n);return ht({prefix:e,name:t,encode:o,decode:i=>oe(s(i))})}function jc(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 qc(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 Wc(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 k({name:t,prefix:e,bitsPerChar:r,alphabet:n,caseInsensitive:o=!1}){let s=Wc(n,o);return ht({prefix:e,name:t,encode(i){return qc(i,n,r)},decode(i){return jc(i,s,r,t)}})}var Gc=ke({prefix:"9",name:"base10",alphabet:"0123456789"});var zn={};Z(zn,{base16:()=>Hc,base16upper:()=>Qc});var Hc=k({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4,caseInsensitive:!0}),Qc=k({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4,caseInsensitive:!0});var Vn={};Z(Vn,{base2:()=>Xc});var Xc=k({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var jn={};Z(jn,{base256emoji:()=>eu});var Qs=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}"),Kc=Qs.reduce((t,e,r)=>(t[r]=e,t),[]),Jc=Qs.reduce((t,e,r)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return t[n]=r,t},[]);function Zc(t){return t.reduce((e,r)=>(e+=Kc[r],e),"")}function Yc(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=Jc[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(o)}return new Uint8Array(e)}var eu=ht({prefix:"\u{1F680}",name:"base256emoji",encode:Zc,decode:Yc});var qn={};Z(qn,{base32:()=>ge,base32hex:()=>ou,base32hexpad:()=>iu,base32hexpadupper:()=>au,base32hexupper:()=>su,base32pad:()=>ru,base32padupper:()=>nu,base32upper:()=>tu,base32z:()=>cu});var ge=k({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5,caseInsensitive:!0}),tu=k({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5,caseInsensitive:!0}),ru=k({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5,caseInsensitive:!0}),nu=k({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5,caseInsensitive:!0}),ou=k({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5,caseInsensitive:!0}),su=k({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5,caseInsensitive:!0}),iu=k({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5,caseInsensitive:!0}),au=k({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5,caseInsensitive:!0}),cu=k({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Wn={};Z(Wn,{base36:()=>$t,base36upper:()=>uu});var $t=ke({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz",caseInsensitive:!0}),uu=ke({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",caseInsensitive:!0});var Gn={};Z(Gn,{base58btc:()=>se,base58flickr:()=>fu});var se=ke({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),fu=ke({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Xn={};Z(Xn,{base64:()=>Hn,base64pad:()=>lu,base64url:()=>Qn,base64urlpad:()=>hu});var Hn=k({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),lu=k({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Qn=k({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),hu=k({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Kn={};Z(Kn,{base8:()=>du});var du=k({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Jn={};Z(Jn,{identity:()=>mu});var mu=ht({prefix:"\0",name:"identity",encode:t=>qs(oe(t)),decode:t=>oe(js(t))});var Td=new TextEncoder,Dd=new TextDecoder;var Yn={};Z(Yn,{identity:()=>Uu});var yu=Js,Xs=128,bu=127,wu=~bu,xu=Math.pow(2,31);function Js(t,e,r){e=e||[],r=r||0;for(var n=r;t>=xu;)e[r++]=t&255|Xs,t/=128;for(;t&wu;)e[r++]=t&255|Xs,t>>>=7;return e[r]=t|0,Js.bytes=r-n+1,e}var Eu=Zn,_u=128,Ks=127;function Zn(t,n){var r=0,n=n||0,o=0,s=n,i,a=t.length;do{if(s>=a)throw Zn.bytes=0,new RangeError("Could not decode varint");i=t[s++],r+=o<28?(i&Ks)<<o:(i&Ks)*Math.pow(2,o),o+=7}while(i>=_u);return Zn.bytes=s-n,r}var vu=Math.pow(2,7),Su=Math.pow(2,14),Cu=Math.pow(2,21),Iu=Math.pow(2,28),Lu=Math.pow(2,35),Au=Math.pow(2,42),Tu=Math.pow(2,49),Du=Math.pow(2,56),ku=Math.pow(2,63),Bu=function(t){return t<vu?1:t<Su?2:t<Cu?3:t<Iu?4:t<Lu?5:t<Au?6:t<Tu?7:t<Du?8:t<ku?9:10},Pu={encode:yu,decode:Eu,encodingLength:Bu},Mu=Pu,zt=Mu;function Vt(t,e=0){let r=zt.decode(t,e),n=zt.decode.bytes;if(n>9)throw new RangeError("Invalid varint: too long");if(n>1&&t[e+n-1]===0)throw new RangeError("Invalid varint: not minimally encoded");return[r,n]}function dt(t,e,r=0){return zt.encode(t,e,r),e}function mt(t){return zt.encodingLength(t)}function gt(t,e){let r=e.byteLength,n=mt(t),o=n+mt(r),s=new Uint8Array(o+r);return dt(t,s,0),dt(r,s,n),s.set(e,o),new pt(t,r,e,s)}function Zs(t){let e=oe(t),[r,n]=Vt(e),[o,s]=Vt(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new pt(r,o,i,e)}function Ys(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&Vs(t.bytes,r.bytes)}}var pt=class{code;size;digest;bytes;constructor(e,r,n,o){this.code=e,this.size=r,this.digest=He(n),this.bytes=He(o)}};var ei=0,Fu="identity",ti=oe;function Nu(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 gt(ei,ti(t))}var Uu={code:ei,name:Fu,encode:ti,digest:Nu};var ro={};Z(ro,{sha256:()=>Ru,sha512:()=>$u});var Ou=20;function to({name:t,code:e,encode:r,minDigestLength:n,maxDigestLength:o}){return new eo(t,e,r,n,o)}var eo=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,r,n,o,s){this.name=e,this.code=r,this.encode=n,this.minDigestLength=o??Ou,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?ri(n,this.code,r?.truncate):n.then(o=>ri(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function ri(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 gt(e,t)}function oi(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}var Ru=to({name:"sha2-256",code:18,encode:oi("SHA-256")}),$u=to({name:"sha2-512",code:19,encode:oi("SHA-512")});function si(t,e){let{bytes:r,version:n}=t;return n===0?Vu(r,no(t),e??se.encoder):ju(r,no(t),e??ge.encoder)}var ii=new WeakMap;function no(t){let e=ii.get(t);if(e==null){let r=new Map;return ii.set(t,r),r}return e}var yt=class t{code;version;multihash;bytes;"/";constructor(e,r,n,o){this.code=r,this.version=e,this.multihash=n,this.bytes=He(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!==qt)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==qu)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=gt(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&&Ys(e.multihash,n.multihash)}toString(e){return si(this,e)}toJSON(){return{"/":si(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??ai(n,o,s.bytes))}else if(r[Wu]===!0){let{version:n,multihash:o,code:s}=r,i=Zs(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!==qt)throw new Error(`Version 0 CID must use dag-pb (code: ${qt}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let o=ai(e,r,n.bytes);return new t(e,r,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,qt,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=oe(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 pt(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]=Vt(e.subarray(r));return r+=p,h},o=n(),s=qt;if(o===18)o=0,r=0;else if(o===1)s=n();else throw o===0?new RangeError("Invalid CID version, v0 is always implicit"):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]=zu(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 no(s).set(n,e),s}};function zu(t,e){switch(t[0]){case"Q":{let r=e??se;return[se.prefix,r.decode(`${se.prefix}${t}`)]}case se.prefix:{let r=e??se;return[se.prefix,r.decode(t)]}case ge.prefix:{let r=e??ge;return[ge.prefix,r.decode(t)]}case $t.prefix:{let r=e??$t;return[$t.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 Vu(t,e,r){let{prefix:n}=r;if(n!==se.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 ju(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 qt=112,qu=18;function ai(t,e,r){let n=mt(t),o=n+mt(e),s=new Uint8Array(o+r.byteLength);return dt(t,s,0),dt(e,s,n),s.set(r,o),s}var Wu=Symbol.for("@ipld/js-cid/CID");var Wt={...Jn,...Vn,...Kn,...$n,...zn,...qn,...Wn,...Gn,...Xn,...jn},Zd={...ro,...Yn};function ui(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var ci=ui("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),oo=ui("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=Y(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),Gu={utf8:ci,"utf-8":ci,hex:Wt.base16,latin1:oo,ascii:oo,binary:oo,...Wt},br=Gu;function F(t,e="utf8"){let r=br[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}var so={32:16777619n,64:1099511628211n,128:309485009821345068724781371n,256:374144419156711147060143317175368453031918731002211n,512:35835915874844867368919076489095108449946327955754392558399825615420669938882575126094039892345713852759n,1024:5016456510113118655434598811035278955030765345404790744303017523831112055108147451509157692220295382716162651878526895249385292291816524375083746691371804094271873160484737966720260389217684476157468082573n},fi={32:2166136261n,64:14695981039346656037n,128:144066263297769815596495629667062367629n,256:100029257958052580907070968620625704837092796014241193945225284501741471925557n,512:9659303129496669498009435400716310466090418745672637896108374329434462657994582932197716438449813051892206539805784495328239340083876191928701583869517785n,1024:14197795064947621068722070641403218320880622795441933960878474914617582723252296732303717722150864096521202355549365628174669108571814760471015076148029755969804077320157692458563003215304957150157403644460363550505412711285966361610267868082893823963790439336411086884584107735010676915n},li=new globalThis.TextEncoder;function Hu(t,e){let r=so[e],n=fi[e];for(let o=0;o<t.length;o++)n^=BigInt(t[o]),n=BigInt.asUintN(e,n*r);return n}function Qu(t,e,r){if(r.length===0)throw new Error("The `utf8Buffer` option must have a length greater than zero");let n=so[e],o=fi[e],s=t;for(;s.length>0;){let i=li.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 io(t,{size:e=32,utf8Buffer:r}={}){if(!so[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 Qu(t,e,r);t=li.encode(t)}return Hu(t,e)}var Be={hash:t=>Number(io(t,{size:32})),hashV:(t,e)=>Xu(Be.hash(t,e))};function Xu(t){let e=t.toString(16);return e.length%2===1&&(e=`0${e}`),F(e,"base16")}var Ku=Math.LN2*Math.LN2,Gt=class{seeds;bits;buffer;constructor(e={}){e.seeds!=null?this.seeds=e.seeds:this.seeds=Zu(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=Be.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=Be.hash(e,this.seeds[r])%this.bits;if(!this.getbit(o))return!1}return!0}clear(){this.buffer.fill(0)}setbit(e){let r=Math.floor(e/8),n=e%8,o=this.buffer[r];o|=1<<n,this.buffer[r]=o}getbit(e){let r=Math.floor(e/8),n=e%8;return(this.buffer[r]&1<<n)!==0}};function hi(t,e=.005){let r=Ju(t,e);return new Gt(r)}function Ju(t,e=.005){let r=Math.round(-1*t*Math.log(e)/Ku),n=Math.round(r/t*Math.LN2);return{bits:r,hashes:n}}function Zu(t){let e,r,n=[];for(let o=0;o<t;o++)for(e=new P(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 ao=64,fe=class{fp;h;seed;constructor(e,r,n,o=2){if(o>ao)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?Ge(this.fp,e.fp):!1}};function Qe(t,e){return Math.floor(Math.random()*(e-t))+t}var Xe=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=Qe(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 Yu=500,Pe=class{bucketSize;filterSize;fingerprintSize;buckets;count;hash;seed;constructor(e){this.filterSize=e.filterSize,this.bucketSize=e.bucketSize??4,this.fingerprintSize=e.fingerprintSize??2,this.count=0,this.buckets=[],this.hash=e.hash??Be,this.seed=e.seed??Qe(0,Math.pow(2,10))}add(e){typeof e=="string"&&(e=F(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 Xe(this.bucketSize)),this.buckets[o]==null&&(this.buckets[o]=new Xe(this.bucketSize)),this.buckets[n].add(r)||this.buckets[o].add(r))return this.count++,!0;let s=[n,o],i=s[Qe(0,s.length-1)];this.buckets[i]==null&&(this.buckets[i]=new Xe(this.bucketSize));for(let a=0;a<Yu;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 Xe(this.bucketSize)),this.buckets[i].add(u)))return this.count++,!0}return!1}has(e){typeof e=="string"&&(e=F(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=F(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}},ef={1:.5,2:.84,4:.95,8:.98};function tf(t=.001){return t>.002?2:t>1e-5?4:8}function co(t,e=.001){let r=tf(e),n=ef[r],o=Math.round(t/n),s=Math.min(Math.ceil(Math.log2(1/e)+Math.log2(2*r)),ao);return{filterSize:o,bucketSize:r,fingerprintSize:s}}function di(t,e=.005){let r=co(t,e);return new Pe(r)}var Ht=class{filterSize;bucketSize;fingerprintSize;scale;filterSeries;hash;seed;constructor(e){this.bucketSize=e.bucketSize??4,this.filterSize=e.filterSize??(1<<18)/this.bucketSize,this.fingerprintSize=e.fingerprintSize??2,this.scale=e.scale??2,this.hash=e.hash??Be,this.seed=e.seed??Qe(0,Math.pow(2,10)),this.filterSeries=[new Pe({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 Pe({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 mi(t,e=.001,r){return new Ht({...co(t,e),...r??{}})}var ye=class extends Error{static name="AbortError";constructor(e="The operation was aborted"){super(e),this.name="AbortError"}};var ie=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}};var wr=class extends Error{static name="MuxerClosedError";constructor(e="The muxer is closed"){super(e),this.name="MuxerClosedError"}},xr=class extends Error{static name="StreamResetError";constructor(e="The stream has been reset"){super(e),this.name="StreamResetError"}};var Me=class extends Error{static name="StreamStateError";constructor(e="The stream is in an invalid state"){super(e),this.name="StreamStateError"}},Ke=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}},bt=class extends Event{error;local;constructor(e,r,n){super("close",n),this.error=r,this.local=e}},Er=class extends bt{constructor(e,r){super(!0,e,r)}},_r=class extends bt{constructor(e,r){super(!1,e,r)}};function rf(t){return typeof t?.handleEvent=="function"}function nf(t){return t===!0||t===!1}function of(t){return nf(t)?t:t?.capture??!1}function uo(t){let e={capture:of(t),once:!!t?.once};return t?.passive!=null&&(e.passive=t?.passive),t?.signal!=null&&(e.signal=t?.signal),e}function pi(t,e){return uo(t).capture===uo(e).capture}var we=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=uo(n);if(o?.signal?.aborted===!0)return;let s=l=>{o.once&&this.removeEventListener(e,r,o),rf(r)?r.handleEvent(l):r(l)},i=this.#e.get(e);if(i==null&&(i=[],this.#e.set(e,i)),i.some(l=>l.callback!==r?!1:pi(l.options,o)))return;super.addEventListener(e,s,o);let u=()=>{this.removeEventListener(e,r,o)};o.signal?.addEventListener("abort",u),i.push({callback:r,wrapper:s,options:o,onAbort:u})}removeEventListener(e,r,n){let o=this.#e.get(e);if(o==null){super.removeEventListener(e,r??null,n);return}this.#e.set(e,o.filter(s=>s.callback===r&&pi(s.options,n)?(super.removeEventListener(e,s.wrapper,n),s.options?.signal?.removeEventListener("abort",s.onAbort),!1):!0))}safeDispatchEvent(e,r={}){return this.dispatchEvent(new CustomEvent(e,r))}};function vr(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=vr(t);if(e==null)throw new ie(`Multiaddr ${t} was not an IPv4, IPv6, DNS, DNS4, DNS6 or DNSADDR address`);return e}var Sr=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 gi=45,sf=15,wt=new Sr;function Cr(t){if(!(t.length>sf))return wt.new(t).parseWith(()=>wt.readIPv4Addr())}function Ir(t){if(t.includes("%")&&(t=t.split("%")[0]),!(t.length>gi))return wt.new(t).parseWith(()=>wt.readIPv6Addr())}function xt(t,e=!1){if(t.includes("%")&&(t=t.split("%")[0]),t.length>gi)return;let r=wt.new(t).parseWith(()=>wt.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 yi(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 bi(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 fo(t){switch(t.length){case Je:return t.join(".");case Ze:{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 wi(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 xi(t){let e="0x";for(let r of t)e+=(r>>4).toString(16)+(r&15).toString(16);return e}var Je=4,Ze=16,Qm=parseInt("0xFFFF",16),af=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function Qt(t,e){e.length===Ze&&t.length===Je&&yi(e,0,11)&&(e=e.slice(12)),e.length===Je&&t.length===Ze&&bi(t,af,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 Ei(t,e){if(typeof e=="string"&&(e=xt(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 lo(t){let[e,r]=t.split("/");if(!e||!r)throw new Error("Failed to parse given CIDR: "+t);let n=Je,o=Cr(e);if(o==null&&(n=Ze,o=Ir(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=ho(s,8*n);return{network:Qt(o,i),mask:i}}function ho(t,e){if(e!==8*Je&&e!==8*Ze)throw new Error("Invalid CIDR mask");if(t<0||t>e)throw new Error("Invalid CIDR mask");let r=e/8,n=new Uint8Array(r);for(let o=0;o<r;o++){if(t>=8){n[o]=255,t-=8;continue}n[o]=255-(255>>t),t=0}return n}var Xt=class{constructor(e,r){if(r==null)({network:this.network,mask:this.mask}=lo(e));else{let n=xt(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=xt(r);if(s==null)throw new Error("Failed to parse mask");this.mask=s}else this.mask=ho(o,8*n.length);this.network=Qt(n,this.mask)}}contains(e){return Ei({network:this.network,mask:this.mask},e)}toString(){let e=wi(this.mask),r=e!==-1?String(e):xi(this.mask);return fo(this.network)+"/"+r}};function Lr(t,e){return new Xt(t).contains(e)}function cf(t){try{let e=le(t);return e.type==="ip6"?Lr("2000::/3",e.host):!1}catch{return!1}}function uf(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 _i(t){if(typeof t!="string"||!/^[0-9a-fA-FxX.:]+$/.test(t))return!1;let e=t.includes(":")?`[${t}]`:t,r;try{r=new URL(`http://${e}`)}catch{return!1}if(r.href!==`http://${r.hostname}/`)return!1;let n=r.hostname;if(n.startsWith("["))return n==="[::1]";let o=n.split(".");return o.length===4&&o[0]==="127"&&o.every(s=>/^\d{1,3}$/.test(s))}function Ar(t){try{let e=le(t);switch(e.type){case"ip4":case"ip6":return _i(e.host);default:return!1}}catch{return!1}}function ff(t){return vr(t)!==null}function Fe(t){return!!Cr(t)}function Ne(t){return!!Ir(t)}var Ii=Nc(Ci(),1),yf=["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"],bf=yf.map(t=>new Ii.Netmask(t));function xo(t){for(let e of bf)if(e.contains(t))return!0;return!1}function wf(t){return/^::ffff:([0-9a-fA-F]{1,4}):([0-9a-fA-F]{1,4})$/.test(t)}function xf(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 xo(o)}function Ef(t){return/^::ffff:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(t)}function _f(t){let e=t.split(":"),r=e[e.length-1];return xo(r)}function vf(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 Eo(t){if(Fe(t))return xo(t);if(wf(t))return xf(t);if(Ef(t))return _f(t);if(Ne(t))return vf(t)}function Dr(t){try{let e=le(t);switch(e.type){case"ip4":case"ip6":return Eo(e.host)??!1;default:return e.host==="localhost"}}catch{return!1}}var Sf=Math.pow(2,7),Cf=Math.pow(2,14),If=Math.pow(2,21),_o=Math.pow(2,28),vo=Math.pow(2,35),So=Math.pow(2,42),Co=Math.pow(2,49),S=128,q=127;function W(t){if(t<Sf)return 1;if(t<Cf)return 2;if(t<If)return 3;if(t<_o)return 4;if(t<vo)return 5;if(t<So)return 6;if(t<Co)return 7;if(Number.MAX_SAFE_INTEGER!=null&&t>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function kr(t,e,r=0){switch(W(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 Lf(t,e,r=0){switch(W(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 Af(t,e){let r=t[e],n=0;if(n+=r&q,r<S||(r=t[e+1],n+=(r&q)<<7,r<S)||(r=t[e+2],n+=(r&q)<<14,r<S)||(r=t[e+3],n+=(r&q)<<21,r<S)||(r=t[e+4],n+=(r&q)*_o,r<S)||(r=t[e+5],n+=(r&q)*vo,r<S)||(r=t[e+6],n+=(r&q)*So,r<S)||(r=t[e+7],n+=(r&q)*Co,r<S))return n;throw new RangeError("Could not decode varint")}function Tf(t,e){let r=t.get(e),n=0;if(n+=r&q,r<S||(r=t.get(e+1),n+=(r&q)<<7,r<S)||(r=t.get(e+2),n+=(r&q)<<14,r<S)||(r=t.get(e+3),n+=(r&q)<<21,r<S)||(r=t.get(e+4),n+=(r&q)*_o,r<S)||(r=t.get(e+5),n+=(r&q)*vo,r<S)||(r=t.get(e+6),n+=(r&q)*So,r<S)||(r=t.get(e+7),n+=(r&q)*Co,r<S))return n;throw new RangeError("Could not decode varint")}function Br(t,e,r=0){return e==null&&(e=Y(W(t))),e instanceof Uint8Array?kr(t,e,r):Lf(t,e,r)}function Ie(t,e=0){return t instanceof Uint8Array?Af(t,e):Tf(t,e)}function Df(t){return t.buffer instanceof ArrayBuffer}function Io(t){return Df(t)?t:t.slice()}function Oe(t,e="utf8"){let r=br[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.encoder.encode(t).substring(1)}var V=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},Le=class extends Error{static name="ValidationError";name="ValidationError"},Pr=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},Mr=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};function Ao(t){return e=>Oe(e,t)}function To(t){return e=>F(e,t)}function St(t){return new DataView(t.buffer).getUint16(t.byteOffset).toString()}function et(t){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,typeof t=="string"?parseInt(t):t),new Uint8Array(e)}function Li(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=et(n);return Ce([r,o],r.length+o.length)}function Ai(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=et(n);return Ce([r,o],r.length+o.length)}function Do(t){let e=t.subarray(0,t.length-2),r=t.subarray(t.length-2),n=Oe(e,"base32"),o=St(r);return`${n}:${o}`}var ko=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 V("Invalid byte value in IP address");e[n]=o}),e},Ti=function(t){let e=0;t=t.toString().trim();let r=t.split(":",8),n;for(n=0;n<r.length;n++){let s=Fe(r[n]),i;s&&(i=ko(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 V("Invalid byte value in IP address");o[e++]=s>>8&255,o[e++]=s&255}return o},Di=function(t){if(t.byteLength!==4)throw new V("IPv4 address was incorrect length");let e=[];for(let r=0;r<t.byteLength;r++)e.push(t[r]);return e.join(".")},ki=function(t){if(t.byteLength!==16)throw new V("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 V(`Invalid IPv6 address "${r}"`)}};function Bi(t){try{let e=new URL(`http://[${t}]`);return e.hostname.substring(1,e.hostname.length-1)}catch{throw new V(`Invalid IPv6 address "${t}"`)}}var Lo=Object.values(Wt).map(t=>t.decoder),kf=(function(){let t=Lo[0].or(Lo[1]);return Lo.slice(2).forEach(e=>t=t.or(e)),t})();function Pi(t){return kf.decode(t)}function Mi(t){return e=>t.encoder.encode(e)}function Bf(t){if(parseInt(t).toString()!==t)throw new Le("Value must be an integer")}function Pf(t){if(t<0)throw new Le("Value must be a positive integer, or zero")}function Mf(t){return e=>{if(e>t)throw new Le(`Value must be smaller than or equal to ${t}`)}}function Ff(...t){return e=>{for(let r of t)r(e)}}var Jt=Ff(Bf,Pf,Mf(65535));var O=-1,Bo=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 Mr(`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)}))}},Te=new Bo,Xf=[{code:4,name:"ip4",size:32,valueToBytes:ko,bytesToValue:Di,validate:t=>{if(!Fe(t))throw new Le(`Invalid IPv4 address "${t}"`)}},{code:6,name:"tcp",size:16,valueToBytes:et,bytesToValue:St,validate:Jt},{code:273,name:"udp",size:16,valueToBytes:et,bytesToValue:St,validate:Jt},{code:33,name:"dccp",size:16,valueToBytes:et,bytesToValue:St,validate:Jt},{code:41,name:"ip6",size:128,valueToBytes:Ti,bytesToValue:ki,stringToValue:Bi,validate:t=>{if(!Ne(t))throw new Le(`Invalid IPv6 address "${t}"`)}},{code:42,name:"ip6zone",size:O},{code:43,name:"ipcidr",size:8,bytesToValue:Ao("base10"),valueToBytes:To("base10")},{code:53,name:"dns",size:O},{code:54,name:"dns4",size:O},{code:55,name:"dns6",size:O},{code:56,name:"dnsaddr",size:O},{code:132,name:"sctp",size:16,valueToBytes:et,bytesToValue:St,validate:Jt},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:O,stringToValue:t=>decodeURIComponent(t),valueToString:t=>encodeURIComponent(t)},{code:421,name:"p2p",aliases:["ipfs"],size:O,bytesToValue:Ao("base58btc"),valueToBytes:t=>t.startsWith("Q")||t.startsWith("1")?To("base58btc")(t):yt.parse(t).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:Do,valueToBytes:Li},{code:445,name:"onion3",size:296,bytesToValue:Do,valueToBytes:Ai},{code:446,name:"garlic64",size:O},{code:447,name:"garlic32",size:O},{code:448,name:"tls"},{code:449,name:"sni",size:O},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:O,bytesToValue:Mi(Qn),valueToBytes:Pi},{code:480,name:"http"},{code:481,name:"http-path",size:O,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:O}];Xf.forEach(t=>{Te.addProtocol(t)});function Fi(t){let e=[],r=0;for(;r<t.length;){let n=Ie(t,r),o=Te.getProtocol(n),s=W(n),i=Kf(o,t,r+s),a=0;i>0&&o.size===O&&(a=W(i));let u=s+a+i,l={code:n,name:o.name,bytes:Io(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 Ni(t){let e=0,r=[];for(let n of t){if(n.bytes==null){let o=Te.getProtocol(n.code),s=W(n.code),i,a=0,u=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??F(n.value),a=i.byteLength,o.size===O&&(u=W(a)));let l=new Uint8Array(s+u+a),f=0;kr(n.code,l,f),f+=s,i!=null&&(o.size===O&&(kr(a,l,f),f+=u),l.set(i,f)),n.bytes=l}r.push(n.bytes),e+=n.bytes.byteLength}return Ce(r,e)}function Ui(t){if(t.charAt(0)!=="/")throw new V('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=Te.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 V(`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 V(`Component ${o} was missing value`);l.value=u.stringToValue?.(n)??n}e.push(l),n="",o="",r="protocol"}}}if(o!==""&&n!=="")throw new V("Incomplete multiaddr");return e}function Oi(t){return`/${t.flatMap(e=>{if(e.value==null)return e.name;let r=Te.getProtocol(e.code);if(r==null)throw new V(`Unknown protocol code ${e.code}`);return[e.name,r.valueToString?.(e.value)??e.value]}).join("/")}`}function Kf(t,e,r){return t.size==null||t.size===0?0:t.size>0?t.size/8:Ie(e,r)}var Jf=Symbol.for("nodejs.util.inspect.custom"),Go=Symbol.for("@multiformats/multiaddr");function Zf(t){if(t==null&&(t="/"),Ri(t))return t.getComponents();if(t instanceof Uint8Array)return Fi(t);if(typeof t=="string")return t=t.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),t===""&&(t="/"),Ui(t);if(Array.isArray(t))return t;throw new V("Must be a string, Uint8Array, Component[], or another Multiaddr")}var jr=class t{[Go]=!0;#e;#t;#r;constructor(e="/",r={}){this.#e=Zf(e),r.validate!==!1&&Yf(this)}get bytes(){return this.#r==null&&(this.#r=Ni(this.#e)),this.#r}toString(){return this.#t==null&&(this.#t=Oi(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 Pr(`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 Ge(this.bytes,e.bytes)}[Jf](){return`Multiaddr(${this.toString()})`}};function Yf(t){t.getComponents().forEach(e=>{let r=Te.getProtocol(e.code);e.value!=null&&r.validate?.(e.value)})}function Ri(t){return!!t?.[Go]}function Re(t){return new jr(t)}var L=t=>({match:e=>{let r=e[0];return r==null||r.code!==t||r.value!=null?!1:e.slice(1)}}),y=(t,e)=>({match:r=>{let n=r[0];return n?.code!==t||n.value==null||e!=null&&n.value!==e?!1:r.slice(1)}}),$i=t=>({match:e=>t.match(e)===!1?e:!1}),E=t=>({match:e=>{let r=t.match(e);return r===!1?e:r}}),G=(...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 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 el=y(421),zg=A(el),Wr=y(54),Gr=y(55),Hr=y(56),Qo=y(53),Vg=A(Wr,E(y(421))),jg=A(Gr,E(y(421))),qg=A(Hr,E(y(421))),Wg=A(G(Qo,Hr,Wr,Gr),E(y(421))),zi=_(y(4),E(y(43))),Vi=_(E(y(42)),y(41),E(y(43))),Xo=G(zi,Vi),At=G(Xo,Qo,Wr,Gr,Hr),Gg=A(G(Xo,_(G(Qo,Hr,Wr,Gr),E(y(421))))),Hg=A(zi),Qg=A(Vi),Xg=A(Xo),Ko=_(At,y(6)),Zt=_(At,y(273)),Jo=A(_(Ko,E(y(421)))),Kg=A(Zt),Zo=_(Zt,L(460),E(y(421))),Qr=_(Zt,L(461),E(y(421))),tl=G(Zo,Qr),Jg=A(Zo),Zg=A(Qr),Ho=G(At,Ko,Zt,Zo,Qr),ji=G(_(Ho,L(477),E(y(421)))),Yo=A(ji),qi=G(_(Ho,L(478),E(y(421))),_(Ho,L(448),E(y(449)),L(477),E(y(421)))),es=A(qi),Wi=_(Zt,L(280),E(y(466)),E(y(466)),E(y(421))),ts=A(Wi),Gi=_(Qr,L(465),E(y(466)),E(y(466)),E(y(421))),rs=A(Gi),qr=G(ji,qi,_(Ko,E(y(421))),_(tl,E(y(421))),_(At,E(y(421))),Wi,Gi,y(421)),Yg=A(qr),rl=_(E(qr),L(290),$i(L(281)),E(y(421))),ns=A(rl),nl=G(_(qr,L(290),L(281),E(y(421))),_(qr,L(281),E(y(421))),_(L(281),E(y(421)))),os=A(nl),ol=_(At,G(_(y(6,"80")),_(y(6),L(480)),L(480)),E(y(481)),E(y(421))),e0=A(ol),sl=_(At,G(_(y(6,"443")),_(y(6,"443"),L(480)),_(y(6),L(443)),_(y(6),L(448),L(480)),_(L(448),L(480)),L(448),L(443)),E(y(481)),E(y(421))),t0=A(sl),il=G(_(y(777),E(y(421)))),r0=A(il),al=G(_(y(400),E(y(421)))),n0=A(al);function Hi(t,e){let r=Jo.exactMatch(t),n=Jo.exactMatch(e);if(r&&!n)return-1;if(!r&&n)return 1;let o=es.exactMatch(t),s=es.exactMatch(e);if(o&&!s)return-1;if(!o&&s)return 1;let i=Yo.exactMatch(t),a=Yo.exactMatch(e);if(i&&!a)return-1;if(!i&&a)return 1;let u=os.exactMatch(t),l=os.exactMatch(e);if(u&&!l)return-1;if(!u&&l)return 1;let f=ts.exactMatch(t),h=ts.exactMatch(e);if(f&&!h)return-1;if(!f&&h)return 1;let p=rs.exactMatch(t),x=rs.exactMatch(e);return p&&!x?-1:!p&&x?1:0}function Qi(t,e){let r=Ar(t),n=Ar(e);return r&&!n?1:!r&&n?-1:0}function Xi(t,e){let r=Dr(t),n=Dr(e);return r&&!n?1:!r&&n?-1:0}function Ki(t,e){let r=ns.exactMatch(t),n=ns.exactMatch(e);return r&&!n?1:!r&&n?-1:0}function cl(t){return t.sort((e,r)=>Qi(e,r)||Xi(e,r)||Ki(e,r)||Hi(e,r))}function he(){let t={};return t.promise=new Promise((e,r)=>{t.resolve=e,t.reject=r}),t}var Xr=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}},Tt=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new Xr(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 Xr(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 ss=class extends Error{type;code;constructor(e,r){super(e??"The operation was aborted"),this.type="aborted",this.code=r??"ABORT_ERR"}};function Ee(t={}){return ul(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 ul(t,e){e=e??{};let r=e.onEnd,n=new Tt,o,s,i,a=he(),u=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((w,b)=>{s=C=>{s=null,n.push(C);try{w(t(n))}catch(D){b(D)}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 Tt,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 Tt,p(),{done:!0}),X=w=>(p(w),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:u,return:x,throw:X,push:h,end:p,get readableLength(){return n.size},onEmpty:async w=>{let b=w?.signal;if(b?.throwIfAborted(),n.isEmpty())return;let C,D;b!=null&&(C=new Promise((T,B)=>{D=()=>{B(new ss)},b.addEventListener("abort",D)}));try{await Promise.race([a.promise,C])}finally{D!=null&&b!=null&&b?.removeEventListener("abort",D)}}},r==null)return o;let M=o;return o={[Symbol.asyncIterator](){return this},next(){return M.next()},throw(w){return M.throw(w),r!=null&&(r(w),r=void 0),{done:!0}},return(){return M.return(),r!=null&&(r(),r=void 0),{done:!0}},push:h,end(w){return M.end(w),r!=null&&(r(w),r=void 0),o},get readableLength(){return M.readableLength},onEmpty:w=>M.onEmpty(w)},o}var is=class t extends Error{name="TimeoutError";constructor(e,r){super(e,r),Error.captureStackTrace?.(this,t)}},fl=t=>"reason"in t?t.reason:new DOMException("This operation was aborted.","AbortError"),ll=2**31-1,hl=(t,e)=>{if(typeof t!="number"||Math.sign(t)!==1)return new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${t}\``);if(typeof e?.setTimeout!="function"||typeof e?.clearTimeout!="function")return new TypeError("Expected `customTimers` to have a `setTimeout` and a `clearTimeout` function")};function as(t,e){let{milliseconds:r,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout},signal:i}=e,a,u,l=()=>{try{t.cancel?.()}catch{}},h=new Promise((p,x)=>{let X=()=>{x(fl(i)),l()},M=hl(r,s);try{M?x(M):i?.aborted?X():i&&(u=X,i.addEventListener("abort",u,{once:!0}))}finally{t.then(p,x)}if(M||i?.aborted||r>ll)return;let w=n||o===!1||o instanceof Error?void 0:new is(o??`Promise timed out after ${r} milliseconds`);a=s.setTimeout.call(void 0,()=>{if(n)try{p(n())}catch(b){x(b)}else o===!1?p():x(o instanceof Error?o:w);l()},r)}).finally(()=>{try{h.clear()}catch{}try{u&&i.removeEventListener("abort",u)}catch{}});return h.clear=()=>{a!==void 0&&(s.clearTimeout.call(void 0,a),a=void 0)},h}var Ji=t=>typeof t=="function"?{filter:t}:{...t},dl=t=>t===1/0||Number.isSafeInteger(t)&&t>=0,ml=[["addEventListener","removeEventListener"],["on","off"],["addListener","removeListener"]],pl=t=>{for(let[e,r]of ml){let n=t?.[e],o=t?.[r];if(typeof n=="function"&&typeof o=="function")return{addListener:n.bind(t),removeListener:o.bind(t)}}throw new TypeError("Emitter is not compatible")},gl=t=>{let e=new Map;for(let[r,n]of t)for(let o of Array.isArray(r)?r:[r])e.has(o)||e.set(o,n);return e},yl=({addListener:t,removeListener:e,handlers:r,signal:n,abortHandler:o,isDone:s})=>{n?.addEventListener("abort",o,{once:!0});for(let[i,a]of r)if(t(i,a),s()){e(i,a);return}},bl=({removeListener:t,handlers:e,signal:r,abortHandler:n})=>{for(let[o,s]of e)t(o,s);r?.removeEventListener("abort",n)},wl=(t,e,r)=>{let n=Promise.resolve();return(o,s)=>{n=n.then(async()=>{if(e())return;let i;try{i=t?await t(o):!0}catch(a){e()||r(a);return}e()||s(i)})}};function xl(t,e,r){let n=()=>{},o=!1,s,i=new Promise((a,u)=>{r=Ji(r);let{filter:l}=r;if(!dl(r.count))throw new TypeError("The `count` option should be at least 0 or more");if(typeof r.timeout=="number"&&!(r.timeout>0))throw new TypeError(`Expected the \`timeout\` option to be a positive number, got \`${r.timeout}\``);r.signal?.throwIfAborted();let{addListener:f,removeListener:h}=pl(t);if(r.count===0){a([]);return}let p=[],x=T=>{n(),u(T)},X=wl(l,()=>o,x),M=T=>{p.push(T),r.count===p.length&&(n(),a(p))},w=(...T)=>{if(o)return;let B=r.multiArgs?T:T[0];if(!l){M(B);return}X(B,K=>{K&&M(B)})},b=(...T)=>{x(r.rejectionMultiArgs?T:T[0])},C=()=>{x(r.signal.reason)},D={addListener:f,removeListener:h,handlers:gl([[e,w],[r.rejectionEvents??["error"],b]]),signal:r.signal,abortHandler:C,isDone:()=>o};n=()=>{o=!0,clearTimeout(s),bl(D)},yl(D),!(o||!r.resolveImmediately)&&(Number.isFinite(r.timeout)&&r.timeout<=2**31-1&&(s=setTimeout(n,r.timeout)),a(p))});if(i.cancel=n,typeof r.timeout=="number"&&r.timeout>0&&!r.resolveImmediately){let a=as(i,{milliseconds:r.timeout});return a.cancel=()=>{n(),a.clear()},a}return i}function R(t,e,r){let n=xl(t,e,{...Ji(r),count:1,resolveImmediately:!1}),o=n.then(s=>s[0]);return o.cancel=n.cancel,o}function Dt(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 Yt=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}},er=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"},tr=class extends Error{static name="MaxEarlyStreamsError";name="MaxEarlyStreamsError"},rr=class extends Error{static name="StreamClosedError";name="StreamClosedError"};function El(t){return t.reason}function $(t,e,r){if(e==null||t==null)return t;let n=r?.translateError??El;if(e.aborted)return t.catch(()=>{}),Promise.reject(n(e));let o;return Promise.race([t,new Promise((s,i)=>{o=()=>{i(n(e))},e.addEventListener("abort",o)})]).finally(()=>{o!=null&&e.removeEventListener("abort",o)})}var Kr=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 ye)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function _l(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var Zi=new WeakMap,Jr=class{id;fn;options;recipients;status;timeline;controller;dispatchingProgress;constructor(e,r){this.id=_l(),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 ye),this.cleanup())}async join(e){let r=new Kr(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 $(this.fn({...this.options??{},signal:this.controller.signal,onProgress:r=>{if(this.recipients.length!==0&&!this.dispatchingProgress){if(typeof r=="object"&&r!==null){let n=Zi.get(r);if(n==null&&(n=new WeakSet,Zi.set(r,n)),n.has(this))return;n.add(this)}this.dispatchingProgress=!0;try{this.recipients.forEach(n=>{n.onProgress?.(r)})}finally{this.dispatchingProgress=!1}}}}),this.controller.signal);this.recipients.forEach(r=>{r.deferred.resolve(e)}),this.status="complete"}catch(e){this.recipients.forEach(r=>{r.deferred.reject(e)}),this.status="errored"}finally{this.timeline.finished=Date.now(),this.cleanup()}}cleanup(){this.recipients.forEach(e=>{e.deferred.reject(e.signal?.reason??new ye),e.cleanup(),e.signal?.removeEventListener("abort",this.onAbort)}),this.recipients.splice(0,this.recipients.length)}};var de=class extends we{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=Dt(this.emitEmpty.bind(this),1),this.emitIdle=Dt(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 er;let n=new Jr(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 ye)}),this.clear()}async onEmpty(e){this.size!==0&&await R(this,"empty",e)}async onSizeLessThan(e,r){this.size<e||await R(this,"next",{...r,filter:()=>this.size<e})}async onIdle(e){this.pending===0&&this.size===0||await R(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=Ee({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 ye("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 vl=Math.pow(2,20)*4,rt=class extends we{status;timeline;inactivityTimeout;maxReadBufferLength;maxWriteBufferLength;log;direction;maxMessageSize;readStatus;writeStatus;remoteReadStatus;remoteWriteStatus;writableNeedsDrain;readBuffer;writeBuffer;sendingData;#e=!1;#t;#r=new Set;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??vl,this.maxWriteBufferLength=e.maxWriteBufferLength,this.maxMessageSize=e.maxMessageSize,this.readBuffer=new P,this.writeBuffer=new P,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 rr)};this.addEventListener("close",n)}get readBufferLength(){return this.readBuffer.byteLength}get readableEnded(){return this.#e}get writeBufferLength(){return this.writeBuffer.byteLength}async onDrain(e){return this.writableNeedsDrain!==!0?Promise.resolve():(this.onDrainPromise==null&&(this.onDrainPromise=Promise.withResolvers()),$(this.onDrainPromise.promise,e?.signal))}async*[Symbol.asyncIterator](){let e=Ee(),r,n=s=>{e.push(s.data)};this.addEventListener("message",n);let o=()=>{this.#r.delete(o),this.removeEventListener("message",n),r=this.#t,e.end()};this.#r.add(o),this.readableDone()&&o();try{if(yield*e,r!=null)throw r}finally{this.removeEventListener("message",n),this.#r.delete(o)}}readableDone(){return this.readBuffer.byteLength===0&&(this.remoteWriteStatus==="closed"||this.readStatus==="closing"||this.readStatus==="closed")}isReadable(){return this.status==="open"}send(e){if(this.writeStatus==="closed"||this.writeStatus==="closing")throw new Me(`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.readBuffer.byteLength>0&&(this.#t??=e,this.readBuffer.consume(this.readBuffer.byteLength),this.readStatus="closed",this.maybeDispatchEnd());return}this.log.error("abort with error - %e",e),this.status="aborted",this.#t=e,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(),this.maybeDispatchEnd();try{this.sendReset(e)}catch(r){this.log.error("failed to send reset to remote - %e",r)}this.dispatchEvent(new Er(e))}pause(){if(this.readStatus==="closed"||this.readStatus==="closing")throw new Me("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 Me("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 Me(`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 Me(`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(){if(this.status==="aborted"||this.status==="reset"||this.status==="closed")return;this.log("remote reset");let e=new xr;this.#t=e,this.status="reset",this.writeStatus="closed",this.remoteWriteStatus="closed",this.remoteReadStatus="closed",this.timeline.close=Date.now(),this.readBuffer.byteLength===0&&(this.readStatus="closed",this.maybeDispatchEnd()),this.dispatchEvent(new _r(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.maybeDispatchEnd(),this.dispatchEvent(new bt))}onRemoteCloseWrite(){this.remoteWriteStatus!=="closed"&&(this.log.trace("on remote close write"),this.remoteWriteStatus="closed",this.safeDispatchEvent("remoteCloseWrite"),this.maybeDispatchEnd(),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 P(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}}maybeDispatchEnd(){this.readableDone()&&(this.#r.forEach(e=>{e()}),!this.#e&&(this.#e=!0,this.safeDispatchEvent("end")))}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.maybeDispatchEnd()),this.checkReadBufferLength()}}checkReadBufferLength(){this.readBuffer.byteLength>this.maxReadBufferLength&&this.abort(new Ke(`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 Ke(`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 nr=class extends rt{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 R(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 R(this,"drain",{...e,rejectionEvents:["close"]})),await this.sendClose(e),this.onTransportClosed())}};function cs(t){return t==null?!1:typeof t.then=="function"&&typeof t.catch=="function"&&typeof t.finally=="function"}var or=class extends we{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 $(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 wr;let r=this.onCreateStream({...this.streamOptions,...e});return cs(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 tr(`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 nt=class extends rt{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 R(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 R(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){if(!(this.readStatus==="closing"||this.readStatus==="closed")){this.readBuffer.byteLength>0&&this.readBuffer.consume(this.readBuffer.byteLength),this.readStatus="closing",this.maybeDispatchEnd();try{await this.sendCloseRead(e)}catch(r){throw this.log.error("failed to close readable end - %e",r),r}finally{this.readStatus="closed"}this.log("closed readable end gracefully")}}};function Zr(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 ot=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 Yi=1.2,ea=2,ta=5e3,ra=6e4,na=5e3,us=class{success;failure;next;metric;timeoutMultiplier;failureMultiplier;minTimeout;maxTimeout;constructor(e={}){let r=e.interval??na;this.success=new ot(r),this.failure=new ot(r),this.next=new ot(r),this.failureMultiplier=e.failureMultiplier??ea,this.timeoutMultiplier=e.timeoutMultiplier??Yi,this.minTimeout=e.minTimeout??ta,this.maxTimeout=e.maxTimeout??ra,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=Zr([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 oa(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 Sl(t,e){if(t==null)return[];let r=le(t);return[oa(r,e)]}function Cl(t){return Ne(t)?Lr("2000::/3",t):!1}function Il(t,e){if(typeof t!="string")throw new ie(`invalid ip provided: ${t}`);if(typeof e=="string"&&(e=parseInt(e)),isNaN(e))throw new ie(`invalid port provided: ${e}`);if(Fe(t))return Re(`/ip4/${t}/tcp/${e}`);if(Ne(t))return Re(`/ip6/${t}/tcp/${e}`);throw new ie(`invalid ip:port for creating a multiaddr: ${t}:${e}`)}function Ll(t){return t==null||typeof t?.[Symbol.asyncIterator]!="function"?!1:typeof t.next=="function"}function Al(t){return t==null||typeof t?.[Symbol.iterator]!="function"?!1:typeof t.next=="function"}var fs=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 $(this.readNext.promise,r?.signal,r)}};function sa(){return new fs}function ia(t){return t[Symbol.asyncIterator]!=null}async function Tl(t,e,r){try{await Promise.all(t.map(async n=>{for(;;){let{value:o,done:s}=await n.next();if(s===!0)break;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*Dl(t){let e=new AbortController,r=sa(),n=t.map(o=>ia(o)?o[Symbol.asyncIterator]():o[Symbol.iterator]());Tl(n,r,e.signal).catch(()=>{});try{yield*r}finally{e.abort();for(let o of n)try{Promise.resolve(o.return?.()).catch(()=>{})}catch{}}}function*kl(t){for(let e of t)yield*e}function Bl(...t){let e=[];for(let r of t)ia(r)||e.push(r);return e.length===t.length?kl(e):Dl(t)}var aa=Bl;function ca(t,...e){if(t==null)throw new Error("Empty pipeline");if(ls(t)){let n=t;t=()=>n.source}else if(fa(t)||ua(t)){let n=t;t=()=>n}let r=[t,...e];if(r.length>1&&ls(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++)ls(r[n])&&(r[n]=Ml(r[n]));return Pl(...r)}var Pl=(...t)=>{let e;for(;t.length>0;)e=t.shift()(e);return e},ua=t=>t?.[Symbol.asyncIterator]!=null,fa=t=>t?.[Symbol.iterator]!=null,ls=t=>t==null?!1:t.sink!=null&&t.source!=null,Ml=t=>e=>{let r=t.sink(e);if(r?.then!=null){let n=Ee({objectMode:!0});r.then(()=>{n.end()},i=>{n.end(i)});let o,s=t.source;if(ua(s))o=async function*(){yield*s,n.end()};else if(fa(s))o=function*(){yield*s,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return aa(n,o())}return t.source};var Fl=4194304,sr=class extends Error{static name="UnwrappedError";name="UnwrappedError"},kt=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},Yr=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},en=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function Nl(t){return typeof t?.closeRead=="function"}function Ul(t){return typeof t?.close=="function"}function hs(t){return Nl(t)?t.remoteWriteStatus!=="writable"&&t.readBufferLength===0:Ul(t)?t.status!=="open":!1}function Ol(t){return t?.addEventListener!=null&&t?.removeEventListener!=null&&t?.send!=null&&t?.push!=null&&t?.log!=null}function la(t,e){let r=e?.maxBufferSize??Fl,n=new P,o,s=!1,i;if(!Ol(t))throw new ie("Argument should be a Stream or a Multiaddr");let a=h=>{if(!s&&i==null){if(n.append(h.data),n.byteLength>r){let p=n.byteLength;n.consume(p);let x=new Ke(`Read buffer overflow - ${p} > ${r}`);i=x,o?.reject(x),queueMicrotask(()=>{t.abort(x)});return}o?.resolve()}};t.addEventListener("message",a);let u=h=>{h.error!=null?o?.reject(h.error):o?.resolve()};t.addEventListener("close",u);let l=()=>{o?.resolve()};t.addEventListener("remoteCloseWrite",l);let f={readBuffer:n,async read(h){if(s===!0)throw new sr("Stream was unwrapped");if(i!=null)throw i;if(hs(t)){if(n.byteLength===0&&h?.bytes==null)return null;if(h?.bytes!=null&&n.byteLength<h.bytes)throw t.log.error("closed after reading %d/%d bytes",n.byteLength,h.bytes),new $e(`Unexpected EOF - stream closed after reading ${n.byteLength}/${h.bytes} bytes`)}let p=h?.bytes??1;for(o=Promise.withResolvers();;){if(n.byteLength>=p){o.resolve();break}if(await $(o.promise,h?.signal),hs(t)){if(n.byteLength===0&&h?.bytes==null)return null;break}o=Promise.withResolvers()}let x=h?.bytes??n.byteLength;if(n.byteLength<x){if(hs(t))throw t.log.error("closed while reading %d/%d bytes",n.byteLength,x),new $e(`Unexpected EOF - stream closed while reading ${n.byteLength}/${x} bytes`);return f.read(h)}let X=n.sublist(0,x);return n.consume(x),X},async write(h,p){if(s===!0)throw new sr("Stream was unwrapped");t.send(h)||await R(t,"drain",{signal:p?.signal,rejectionEvents:["close"]})},unwrap(){return s||(s=!0,t.removeEventListener("message",a),t.removeEventListener("close",u),t.removeEventListener("remoteCloseWrite",l),n.byteLength>0&&(t.log("stream unwrapped with %d unread bytes",n.byteLength),t.unshift(n),n.consume(n.byteLength))),t}};return f}function ha(t,e={}){let r=la(t,e);e.maxDataLength!=null&&e.maxLengthLength==null&&(e.maxLengthLength=W(e.maxDataLength));let n=e?.lengthDecoder??Ie,o=e?.lengthEncoder??Br;return{async read(i){let a=-1,u=new P;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 kt("Invalid message length");if(e?.maxLengthLength!=null&&u.byteLength>e.maxLengthLength)throw new en(`Message length length too long - ${u.byteLength} > ${e.maxLengthLength}`);if(a>-1)break}if(e?.maxDataLength!=null&&a>e.maxDataLength)throw new Yr(`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 P(o(i.byteLength),i),a)},async writeV(i,a){let u=new P(...i.flatMap(l=>[o(l.byteLength),l]));await r.write(u,a)},unwrap(){return r.unwrap()}}}function Rl(t,e){let r=ha(t,e),n={read:async(o,s)=>{let i=await r.read(s);return o.decode(i,s)},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 ds(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 R(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 $l(t){return t?.addEventListener!=null}function da(t){let e=Ee(),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([R(t,"drain",{rejectionEvents:["close"]})])),l===!0))break}await t.close()}}}function zl(...t){let e=t.map(r=>$l(r)?da(r):r);return ca(...e)}var Vl=1024*1024*4,jl=1024*1024*4,ms=class{buffer;maxBufferSize;lengthDecoder;maxDataLength;encodingLength;constructor(e={}){this.buffer=new P,this.maxBufferSize=e.maxBufferSize??Vl,this.maxDataLength=e.maxDataLength??jl,this.lengthDecoder=e.lengthDecoder??Ie,this.encodingLength=e.encodingLength??W}*decode(e){if(this.buffer.append(e),this.buffer.byteLength>this.maxBufferSize)throw new ie(`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 kt("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 ql(t){return!!(t.startsWith("169.254.")||t.toLowerCase().startsWith("fe80"))}var Wl=["Object","Uint8Array","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 ps(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=Gl(t);return r||"Object"}function Gl(t){let e=Object.prototype.toString.call(t).slice(8,-1);if(Wl.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 ir=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",Hl=new TextEncoder;function tn(t){return ir&&globalThis.Buffer.isBuffer(t)}function ar(t){return t instanceof Uint8Array?tn(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):t:Uint8Array.from(t)}var Ql=24,Xl=200,rn=ir?t=>t.length>=Ql?globalThis.Buffer.from(t):ma(t):t=>t.length>=Xl?Hl.encode(t):ma(t),_e=t=>Uint8Array.from(t),pa=ir?(t,e,r)=>tn(t)?new Uint8Array(t.subarray(e,r)):t.slice(e,r):(t,e,r)=>t.slice(e,r),ga=ir?(t,e)=>(t=t.map(r=>r instanceof Uint8Array?r:globalThis.Buffer.from(r)),ar(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},gs=ir?t=>globalThis.Buffer.allocUnsafe(t):t=>new Uint8Array(t);function Bt(t,e){if(tn(t)&&tn(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 ma(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 Kl=256,st=class{constructor(e=Kl){this.chunkSize=e,this.cursor=0,this.maxCursor=-1,this.chunks=[],this._initReuseChunk=null}reset(){this.cursor=0,this.maxCursor=-1,this.chunks.length&&(this.chunks=[]),this._initReuseChunk!==null&&(this.chunks.push(this._initReuseChunk),this.maxCursor=this._initReuseChunk.length-1)}pushByte(e){let r=this.chunks[this.chunks.length-1];this.cursor>this.maxCursor&&(r=gs(this.chunkSize),this.chunks.push(r),this.maxCursor+=r.length,this._initReuseChunk===null&&(this._initReuseChunk=r));let n=r.length-(this.maxCursor-this.cursor)-1;r[n]=e,this.cursor++}push(e){let r=this.chunks[this.chunks.length-1];if(this.cursor+e.length<=this.maxCursor+1){let o=r.length-(this.maxCursor-this.cursor)-1;r.set(e,o)}else{if(r){let o=r.length-(this.maxCursor-this.cursor)-1;o<r.length&&(this.chunks[this.chunks.length-1]=r.subarray(0,o),this.maxCursor=this.cursor-1)}e.length<64&&e.length<this.chunkSize?(r=gs(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=pa(n,0,this.cursor)}else r=ga(this.chunks,this.cursor);return e&&this.reset(),r}},nn=class{constructor(e){this.dest=e,this.cursor=0,this.chunks=[e]}reset(){this.cursor=0}pushByte(e){if(this.cursor>=this.dest.length)throw new Error("write out of bounds, destination buffer is too small");this.dest[this.cursor++]=e}push(e){if(this.cursor+e.length>this.dest.length)throw new Error("write out of bounds, destination buffer is too small");this.dest.set(e,this.cursor),this.cursor+=e.length}toBytes(e=!1){let r=this.dest.subarray(0,this.cursor);return e&&this.reset(),r}};var g="CBOR decode error:",on="CBOR encode error:",cr=[];cr[23]=1;cr[24]=2;cr[25]=3;cr[26]=5;cr[27]=9;function De(t,e,r){if(t.length-e<r)throw new Error(`${g} not enough data for type`)}var z=[24,256,65536,4294967296,BigInt("18446744073709551616")];function ee(t,e,r){De(t,e,1);let n=t[e];if(r.strict===!0&&n<z[0])throw new Error(`${g} integer encoded in more bytes than necessary (strict decode)`);return n}function te(t,e,r){De(t,e,2);let n=t[e]<<8|t[e+1];if(r.strict===!0&&n<z[1])throw new Error(`${g} integer encoded in more bytes than necessary (strict decode)`);return n}function re(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<z[2])throw new Error(`${g} integer encoded in more bytes than necessary (strict decode)`);return n}function ne(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<z[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 ya(t,e,r,n){return new m(c.uint,ee(t,e+1,n),2)}function ba(t,e,r,n){return new m(c.uint,te(t,e+1,n),3)}function wa(t,e,r,n){return new m(c.uint,re(t,e+1,n),5)}function xa(t,e,r,n){return new m(c.uint,ne(t,e+1,n),9)}function ve(t,e){return N(t,0,e.value)}function N(t,e,r){if(r<z[0]){let n=Number(r);t.pushByte(e|n)}else if(r<z[1]){let n=Number(r);t.push([e|24,n])}else if(r<z[2]){let n=Number(r);t.push([e|25,n>>>8,n&255])}else if(r<z[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<z[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`)}}ve.encodedSize=function(e){return N.encodedSize(e.value)};N.encodedSize=function(e){return e<z[0]?1:e<z[1]?2:e<z[2]?3:e<z[3]?5:9};ve.compareTokens=function(e,r){return e.value<r.value?-1:e.value>r.value?1:0};function Ea(t,e,r,n){return new m(c.negint,-1-ee(t,e+1,n),2)}function _a(t,e,r,n){return new m(c.negint,-1-te(t,e+1,n),3)}function va(t,e,r,n){return new m(c.negint,-1-re(t,e+1,n),5)}var ys=BigInt(-1),Sa=BigInt(1);function Ca(t,e,r,n){let o=ne(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,ys-BigInt(o),9)}function sn(t,e){let r=e.value,n=typeof r=="bigint"?r*ys-Sa:r*-1-1;N(t,e.type.majorEncoded,n)}sn.encodedSize=function(e){let r=e.value,n=typeof r=="bigint"?r*ys-Sa:r*-1-1;return n<z[0]?1:n<z[1]?2:n<z[2]?3:n<z[3]?5:9};sn.compareTokens=function(e,r){return e.value<r.value?1:e.value>r.value?-1:0};function ur(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 Ia(t,e,r,n){return ur(t,e,1,r)}function La(t,e,r,n){return ur(t,e,2,ee(t,e+1,n))}function Aa(t,e,r,n){return ur(t,e,3,te(t,e+1,n))}function Ta(t,e,r,n){return ur(t,e,5,re(t,e+1,n))}function Da(t,e,r,n){let o=ne(t,e+1,n);if(typeof o=="bigint")throw new Error(`${g} 64-bit integer bytes lengths not supported`);return ur(t,e,9,o)}function an(t){return t.encodedBytes===void 0&&(t.encodedBytes=c.equals(t.type,c.string)?rn(t.value):t.value),t.encodedBytes}function Pt(t,e){let r=an(e);N(t,e.type.majorEncoded,r.length),t.push(r)}Pt.encodedSize=function(e){let r=an(e);return N.encodedSize(r.length)+r.length};Pt.compareTokens=function(e,r){return Zl(an(e),an(r))};function Zl(t,e){return t.length<e.length?-1:t.length>e.length?1:Bt(t,e)}var ka=new TextDecoder("utf-8",{ignoreBOM:!0}),eh=new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0}),th=32;function rh(t,e,r,n){if(r-e<th){let s="";for(let i=e;i<r;i++){let a=t[i];if(a&128)return n.strictUtf8===!0?Ba(t,e,r):ka.decode(t.subarray(e,r));s+=String.fromCharCode(a)}return s}return n.strictUtf8===!0?Ba(t,e,r):ka.decode(t.subarray(e,r))}function Ba(t,e,r){try{return eh.decode(t.subarray(e,r))}catch{throw new Error(`${g} invalid UTF-8 in text string`)}}function fr(t,e,r,n,o){let s=r+n;De(t,e,s);let i=new m(c.string,rh(t,e+r,e+s,o),s);return o.retainStringBytes===!0&&(i.byteValue=t.slice(e+r,e+s)),i}function Pa(t,e,r,n){return fr(t,e,1,r,n)}function Ma(t,e,r,n){return fr(t,e,2,ee(t,e+1,n),n)}function Fa(t,e,r,n){return fr(t,e,3,te(t,e+1,n),n)}function Na(t,e,r,n){return fr(t,e,5,re(t,e+1,n),n)}function Ua(t,e,r,n){let o=ne(t,e+1,n);if(typeof o=="bigint")throw new Error(`${g} 64-bit integer string lengths not supported`);return fr(t,e,9,o,n)}var Oa=Pt;function Mt(t,e,r,n){return new m(c.array,n,r)}function Ra(t,e,r,n){return Mt(t,e,1,r)}function $a(t,e,r,n){return Mt(t,e,2,ee(t,e+1,n))}function za(t,e,r,n){return Mt(t,e,3,te(t,e+1,n))}function Va(t,e,r,n){return Mt(t,e,5,re(t,e+1,n))}function ja(t,e,r,n){let o=ne(t,e+1,n);if(typeof o=="bigint")throw new Error(`${g} 64-bit integer array lengths not supported`);return Mt(t,e,9,o)}function qa(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${g} indefinite length items not allowed`);return Mt(t,e,1,1/0)}function cn(t,e){N(t,c.array.majorEncoded,e.value)}cn.compareTokens=ve.compareTokens;cn.encodedSize=function(e){return N.encodedSize(e.value)};function Ft(t,e,r,n){return new m(c.map,n,r)}function Wa(t,e,r,n){return Ft(t,e,1,r)}function Ga(t,e,r,n){return Ft(t,e,2,ee(t,e+1,n))}function Ha(t,e,r,n){return Ft(t,e,3,te(t,e+1,n))}function Qa(t,e,r,n){return Ft(t,e,5,re(t,e+1,n))}function Xa(t,e,r,n){let o=ne(t,e+1,n);if(typeof o=="bigint")throw new Error(`${g} 64-bit integer map lengths not supported`);return Ft(t,e,9,o)}function Ka(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${g} indefinite length items not allowed`);return Ft(t,e,1,1/0)}function un(t,e){N(t,c.map.majorEncoded,e.value)}un.compareTokens=ve.compareTokens;un.encodedSize=function(e){return N.encodedSize(e.value)};function Ja(t,e,r,n){return new m(c.tag,r,1)}function Za(t,e,r,n){return new m(c.tag,ee(t,e+1,n),2)}function Ya(t,e,r,n){return new m(c.tag,te(t,e+1,n),3)}function ec(t,e,r,n){return new m(c.tag,re(t,e+1,n),5)}function tc(t,e,r,n){return new m(c.tag,ne(t,e+1,n),9)}function fn(t,e){N(t,c.tag.majorEncoded,e.value)}fn.compareTokens=ve.compareTokens;fn.encodedSize=function(e){return N.encodedSize(e.value)};var ln=20,hn=21,dn=22,mn=23;function nc(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 oc(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 bs(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 sc(t,e,r,n){return bs(pn(t,e+1),3,n)}function ic(t,e,r,n){return bs(gn(t,e+1),5,n)}function ac(t,e,r,n){return bs(fc(t,e+1),9,n)}function lr(t,e,r){let n=e.value;if(n===!1)t.pushByte(c.float.majorEncoded|ln);else if(n===!0)t.pushByte(c.float.majorEncoded|hn);else if(n===null)t.pushByte(c.float.majorEncoded|dn);else if(n===void 0)t.pushByte(c.float.majorEncoded|mn);else{let o,s=!1;(!r||r.float64!==!0)&&(ws(n),o=pn(U,1),n===o||Number.isNaN(n)?(U[0]=249,t.push(U.slice(0,3)),s=!0):(xs(n),o=gn(U,1),n===o&&(U[0]=250,t.push(U.slice(0,5)),s=!0))),s||(uc(n),o=fc(U,1),U[0]=251,t.push(U.slice(0,9)))}}lr.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){ws(n);let o=pn(U,1);if(n===o||Number.isNaN(n))return 3;if(xs(n),o=gn(U,1),n===o)return 5}return 9};var cc=new ArrayBuffer(9),ae=new DataView(cc,1),U=new Uint8Array(cc,0);function ws(t){if(t===1/0)ae.setUint16(0,31744,!1);else if(t===-1/0)ae.setUint16(0,64512,!1);else if(Number.isNaN(t))ae.setUint16(0,32256,!1);else{ae.setFloat32(0,t);let e=ae.getUint32(0),r=(e&2139095040)>>23,n=e&8388607;if(r===255)ae.setUint16(0,31744,!1);else if(r===0)ae.setUint16(0,(e&2147483648)>>16|n>>13,!1);else{let o=r-127;o<-24?ae.setUint16(0,0):o<-14?ae.setUint16(0,(e&2147483648)>>16|1<<24+o,!1):ae.setUint16(0,(e&2147483648)>>16|o+15<<10|n>>13,!1)}}}function pn(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 xs(t){ae.setFloat32(0,t,!1)}function gn(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 uc(t){ae.setFloat64(0,t,!1)}function fc(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)}function ah(t,e){let r=t.value;if(r===!1)return Uint8Array.of(c.float.majorEncoded|ln);if(r===!0)return Uint8Array.of(c.float.majorEncoded|hn);if(r===null)return Uint8Array.of(c.float.majorEncoded|dn);if(r===void 0)return Uint8Array.of(c.float.majorEncoded|mn);if(!e){if(ws(r),r===pn(U,1)||Number.isNaN(r))return U[0]=249,U.slice(0,3);if(xs(r),r===gn(U,1))return U[0]=250,U.slice(0,5)}return uc(r),U[0]=251,U.slice(0,9)}function rc(t,e){let r=t,n=e?.float64===!0,o=n?r._keyBytesFloat64:r._keyBytes;if(o!==void 0)return o;let s=ah(t,n);return n?r._keyBytesFloat64=s:r._keyBytes=s,s}lr.compareTokens=function(e,r,n){let o=rc(e,n),s=rc(r,n);return o.length!==s.length?o.length<s.length?-1:1:Bt(o,s)};function v(t,e,r){throw new Error(`${g} encountered invalid minor (${r}) for major ${t[e]>>>5}`)}function yn(t){return()=>{throw new Error(`${g} ${t}`)}}var d=[];for(let t=0;t<=23;t++)d[t]=v;d[24]=ya;d[25]=ba;d[26]=wa;d[27]=xa;d[28]=v;d[29]=v;d[30]=v;d[31]=v;for(let t=32;t<=55;t++)d[t]=v;d[56]=Ea;d[57]=_a;d[58]=va;d[59]=Ca;d[60]=v;d[61]=v;d[62]=v;d[63]=v;for(let t=64;t<=87;t++)d[t]=Ia;d[88]=La;d[89]=Aa;d[90]=Ta;d[91]=Da;d[92]=v;d[93]=v;d[94]=v;d[95]=yn("indefinite length bytes/strings are not supported");for(let t=96;t<=119;t++)d[t]=Pa;d[120]=Ma;d[121]=Fa;d[122]=Na;d[123]=Ua;d[124]=v;d[125]=v;d[126]=v;d[127]=yn("indefinite length bytes/strings are not supported");for(let t=128;t<=151;t++)d[t]=Ra;d[152]=$a;d[153]=za;d[154]=Va;d[155]=ja;d[156]=v;d[157]=v;d[158]=v;d[159]=qa;for(let t=160;t<=183;t++)d[t]=Wa;d[184]=Ga;d[185]=Ha;d[186]=Qa;d[187]=Xa;d[188]=v;d[189]=v;d[190]=v;d[191]=Ka;for(let t=192;t<=215;t++)d[t]=Ja;d[216]=Za;d[217]=Ya;d[218]=ec;d[219]=tc;d[220]=v;d[221]=v;d[222]=v;d[223]=v;for(let t=224;t<=243;t++)d[t]=yn("simple values are not supported");d[244]=v;d[245]=v;d[246]=v;d[247]=nc;d[248]=yn("simple values are not supported");d[249]=sc;d[250]=ic;d[251]=ac;d[252]=v;d[253]=v;d[254]=v;d[255]=oc;var me=[];for(let t=0;t<24;t++)me[t]=new m(c.uint,t,1);for(let t=-1;t>=-24;t--)me[31-t]=new m(c.negint,t,1);me[64]=new m(c.bytes,new Uint8Array(0),1);me[96]=new m(c.string,"",1);me[128]=new m(c.array,0,1);me[160]=new m(c.map,0,1);me[244]=new m(c.false,!1,1);me[245]=new m(c.true,!0,1);me[246]=new m(c.null,null,1);function Es(t){switch(t.type){case c.false:return _e([244]);case c.true:return _e([245]);case c.null:return _e([246]);case c.bytes:return t.value.length?void 0:_e([64]);case c.string:return t.value===""?_e([96]):void 0;case c.array:return t.value===0?_e([128]):void 0;case c.map:return t.value===0?_e([160]):void 0;case c.uint:return t.value<24?_e([Number(t.value)]):void 0;case c.negint:if(t.value>=-24)return _e([31-Number(t.value)])}}var uh={float64:!1,mapSorter:vs,quickEncodeToken:Es},pc=Object.freeze({mapSorter:hh,quickEncodeToken:Es});function fh(){let t=[];return t[c.uint.major]=ve,t[c.negint.major]=sn,t[c.bytes.major]=Pt,t[c.string.major]=Oa,t[c.array.major]=cn,t[c.map.major]=un,t[c.tag.major]=fn,t[c.float.major]=lr,t}var ct=fh(),bn=new st,wn=!1,Ut=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(`${on} 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)},Se={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=Ut.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=Ut.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?(lh(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)]}};Se.Map=Se.Object;Se.Buffer=Se.Uint8Array;for(let t of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))Se[`${t}Array`]=Se.DataView;function at(t,e={},r){let n=ps(t),o=e&&e.typeEncoders&&e.typeEncoders[n]||Se[n];if(typeof o=="function"){let i=o(t,n,e,r);if(i!=null)return i}let s=Se[n];if(!s)throw new Error(`${on} unsupported type: ${n}`);return s(t,n,e,r)}function lh(t,e){let r=e.mapSorter;r&&t.sort((n,o)=>r(n,o,e))}function vs(t,e,r){let n=Array.isArray(t[0])?t[0][0]:t[0],o=Array.isArray(e[0])?e[0][0]:e[0];if(n.type.major!==o.type.major)return n.type.compare(o.type);let s=n.type.major,i=ct[s].compareTokens(n,o,r);return i===0&&console.warn("WARNING: complex key types used, CBOR key sorting guarantees are gone"),i}function hh(t,e){if(t[0]instanceof m&&e[0]instanceof m){let r=t[0],n=e[0];return r._keyBytes||(r._keyBytes=lc(r.value)),n._keyBytes||(n._keyBytes=lc(n.value)),Bt(r._keyBytes,n._keyBytes)}throw new Error("rfc8949MapSorter: complex key types are not supported yet")}function lc(t){return gc(t,ct,pc)}function Nt(t,e,r,n){if(Array.isArray(e))for(let o of e)Nt(t,o,r,n);else r[e.type.major](t,e,n)}var hc=c.uint.majorEncoded,dc=c.negint.majorEncoded,dh=c.bytes.majorEncoded,mh=c.string.majorEncoded,mc=c.array.majorEncoded,_s=c.map.majorEncoded,ph=c.float.majorEncoded|ln,gh=c.float.majorEncoded|hn,yh=c.float.majorEncoded|dn,bh=c.float.majorEncoded|mn,wh=BigInt(-1),xh=BigInt(1);function Ve(t,e,r){r<24?t.pushByte(e|Number(r)):N(t,e,r)}function Eh(t){return t.addBreakTokens!==!0}function _h(t,e,r,n,o){let s=r==="Map",i=s?e.keys():Object.keys(e),a=s?e.size:i.length;if(!a){t.pushByte(_s);return}o=Ut.createCheck(o,e);let u=!s&&n.ignoreUndefinedProperties,l=new Array(a),f=0;for(let h of i){let p=s?e.get(h):e[h];u&&p===void 0||(l[f++]=[at(h,n,o),p])}if(f===0){t.pushByte(_s);return}f<a&&(l.length=f),l.sort((h,p)=>vs(h,p,n)),Ve(t,_s,f);for(let[h,p]of l)Nt(t,h,ct,n),xn(t,p,n,o)}function xn(t,e,r,n){let o=ps(e),s=r.typeEncoders&&r.typeEncoders[o];if(s){let i=s(e,o,r,n);if(i!=null){Nt(t,i,ct,r);return}}switch(o){case"null":t.pushByte(yh);return;case"undefined":t.pushByte(bh);return;case"boolean":t.pushByte(e?gh:ph);return;case"number":!Number.isInteger(e)||!Number.isSafeInteger(e)?lr(t,new m(c.float,e),r):e>=0?Ve(t,hc,e):Ve(t,dc,e*-1-1);return;case"bigint":e>=BigInt(0)?Ve(t,hc,e):Ve(t,dc,e*wh-xh);return;case"string":{let i=rn(e);Ve(t,mh,i.length),t.push(i);return}case"Uint8Array":Ve(t,dh,e.length),t.push(e);return;case"Array":if(!e.length){t.pushByte(mc);return}n=Ut.createCheck(n,e),Ve(t,mc,e.length);for(let i of e)xn(t,i,r,n);return;case"Object":case"Map":if(r.mapSorter===vs)_h(t,e,o,r,n);else{let i=Se.Object(e,o,r,n);Nt(t,i,ct,r)}return;default:{let i=Se[o];if(!i)throw new Error(`${on} unsupported type: ${o}`);let a=i(e,o,r,n);Nt(t,a,ct,r)}}}function gc(t,e,r,n){let o=n instanceof Uint8Array,s=o?new nn(n):wn?new st:bn,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 st(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():ar(s.chunks[0])}}return s.reset(),Nt(s,i,e,r),s.toBytes(!0)}function Ss(t,e){if(e=Object.assign({},uh,e),Eh(e)){if(wn){let r=new st;return xn(r,t,e,void 0),r.toBytes()}wn=!0;try{return bn.reset(),xn(bn,t,e,void 0),bn.toBytes(!0)}finally{wn=!1}}return gc(t,ct,e)}var vh={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},En=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=me[e];if(r===void 0){let n=d[e];if(!n)throw e===void 0?new Error(`${g} not enough data`):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}},je=Symbol.for("DONE"),qe=Symbol.for("BREAK");function Sh(t,e,r){let n=[];for(let o=0;o<t.value;o++){let s=We(e,r);if(s===qe){if(t.value===1/0)break;throw new Error(`${g} got unexpected break to lengthed array`)}if(s===je)throw new Error(`${g} found array but not enough entries (got ${o}, expected ${t.value})`);n[o]=s}return n}function Ch(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=We(e,r);if(u===qe){if(t.value===1/0)break;throw new Error(`${g} got unexpected break to lengthed map`)}if(u===je)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=We(e,r);if(l===je)throw new Error(`${g} found map but not enough entries (got ${a} [no value], expected ${t.value})`);if(l===qe)throw new Error(`${g} got unexpected break to map value`);n?i.set(u,l):u==="__proto__"?Object.defineProperty(s,u,{value:l,configurable:!0,enumerable:!0,writable:!0}):s[u]=l}return n?i:s}function*Ih(t,e,r){for(let n=0;n<t.value;n++){let o=We(e,r);if(o===qe){if(t.value===1/0)break;throw new Error(`${g} got unexpected break to lengthed map`)}if(o===je)throw new Error(`${g} found map but not enough entries (got ${n} [no key], expected ${t.value})`);let s=We(e,r);if(s===je)throw new Error(`${g} found map but not enough entries (got ${n} [no value], expected ${t.value})`);if(s===qe)throw new Error(`${g} got unexpected break to map value`);yield[o,s]}}function Lh(t,e){let r=function(){if(r._called)throw new Error(`${g} tag decode() may only be called once`);r._called=!0;let n=We(t,e);if(n===je)throw new Error(`${g} tag content missing`);if(n===qe)throw new Error(`${g} got unexpected break in tag content`);return n};return r.entries=function(){if(r._called)throw new Error(`${g} tag decode() may only be called once`);if(r._called=!0,t.done())throw new Error(`${g} tag content missing`);let n=t.next();if(!c.equals(n.type,c.map))throw new Error(`${g} entries() requires map content, got ${n.type.name}`);let o=[];for(let s of Ih(n,t,e))o.push(s);return o},r._called=!1,r}function We(t,e){if(t.done())return je;let r=t.next();if(c.equals(r.type,c.break))return qe;if(r.type.terminal)return r.value;if(c.equals(r.type,c.array))return Sh(r,t,e);if(c.equals(r.type,c.map))return Ch(r,t,e);if(c.equals(r.type,c.tag)){if(e.tags&&typeof e.tags[r.value]=="function"){let n=Lh(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 yc(t,e){if(!(t instanceof Uint8Array))throw new Error(`${g} data to decode must be a Uint8Array`);e=Object.assign({},vh,e);let r=ar(t),n=e.tokenizer||new En(r,e),o=We(n,e);if(o===je)throw new Error(`${g} did not find any content to decode`);if(o===qe)throw new Error(`${g} got unexpected break`);return[o,t.subarray(n.pos())]}function Cs(t,e){let[r,n]=yc(t,e);if(n.length>0)throw new Error(`${g} too many terminals, data makes no sense`);return r}var _n=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(_n.prototype,Symbol.toStringTag,{value:"Tagged"});var vn=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},Ot=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},Sn=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"},hr=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};function Cn(t){return t[Symbol.asyncIterator]!=null}function bc(t,e){if(t.byteLength>e)throw new Ot("Message length too long")}var Ln=t=>{let e=W(t),r=Y(e);return Br(t,r),Ln.bytes=e,r};Ln.bytes=0;function An(t,e){e=e??{};let r=e.lengthEncoder??Ln,n=e?.maxDataLength??4194304;function*o(s){bc(s,n);let i=r(s.byteLength);i instanceof Uint8Array?yield i:yield*i,s instanceof Uint8Array?yield s:yield*s}return Cn(t)?(async function*(){for await(let s of t)yield*o(s)})():(function*(){for(let s of t)yield*o(s)})()}An.single=(t,e)=>{e=e??{};let r=e.lengthEncoder??Ln,n=e?.maxDataLength??4194304;return bc(t,n),new P(r(t.byteLength),t)};var ut;(function(t){t[t.LENGTH=0]="LENGTH",t[t.DATA=1]="DATA"})(ut||(ut={}));var Is=t=>{let e=Ie(t);return Is.bytes=W(e),e};Is.bytes=0;function dr(t,e){let r=new P,n=ut.LENGTH,o=-1,s=e?.lengthDecoder??Is,i=e?.maxLengthLength??8,a=e?.maxDataLength??4194304;function*u(){for(;r.byteLength>0;){if(n===ut.LENGTH)try{if(o=s(r),o<0)throw new vn("Invalid message length");if(o>a)throw new Ot("Message length too long");let l=s.bytes;r.consume(l),e?.onLength!=null&&e.onLength(o),n=ut.DATA}catch(l){if(l instanceof RangeError){if(r.byteLength>i)throw new Sn("Message length length too long");break}throw l}if(n===ut.DATA){if(r.byteLength<o)break;let l=r.sublist(0,o);r.consume(o),e?.onData!=null&&e.onData(l),yield l,n=ut.LENGTH}}}return Cn(t)?(async function*(){for await(let l of t)r.append(l),yield*u();if(r.byteLength>0)throw new hr("Unexpected end of input")})():(function*(){for(let l of t)r.append(l),yield*u();if(r.byteLength>0)throw new hr("Unexpected end of input")})()}dr.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 dr(n,{...e??{},onLength:s=>{r=s}})};var Ls=class extends nt{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()}},wc=30,As=class extends or{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)+wc,this.encoding=r.encoding??"base64",this.input=Ee(),this.sendMessage=this.sendMessage.bind(this),this.nextStreamId=this.maConn.direction==="outbound"?0:1,Promise.resolve().then(async()=>{for await(let n of dr(this.input,{maxDataLength:this.maxMessageSize}))this.onMessage(Cs(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=Ss(e),n=An.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 Ls({...this.streamOptions,...n,id:e,direction:r,log:this.log.newScope(`stream:${r}:${e}`),sendMessage:this.sendMessage,encoding:this.encoding,maxMessageSize:this.maxMessageSize-wc,protocol:""})}},Ts=class{protocol="/mock-muxer/1.0.0";init;constructor(e){this.init=e}createStreamMuxer(e){return new As(e,{...this.init})}};function Tn(t={}){return new Ts(t)}function Dn(t,e){if(typeof t=="string")return kh(t);if(typeof t=="number")return Mh(t,e);throw new Error(`Value provided to ms() must be a string or number. value=${JSON.stringify(t)}`)}function kh(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 Bh(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 Ph(t){let e=Math.abs(t);return e>=315576e5?ft(t,e,315576e5,"year"):e>=26298e5?ft(t,e,26298e5,"month"):e>=6048e5?ft(t,e,6048e5,"week"):e>=864e5?ft(t,e,864e5,"day"):e>=36e5?ft(t,e,36e5,"hour"):e>=6e4?ft(t,e,6e4,"minute"):e>=1e3?ft(t,e,1e3,"second"):`${t} ms`}function Mh(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?Ph(t):Bh(t)}function ft(t,e,r,n){let o=e>=r*1.5;return`${Math.round(t/r)} ${n}${o?"s":""}`}function Ds(t){r.debug=r,r.default=r,r.coerce=u,r.disable=s,r.enable=o,r.enabled=i,r.humanize=Dn,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,X,M;function w(...b){if(!w.enabled)return;let C=w,D=Number(new Date),T=D-(p||D);C.diff=T,C.prev=p,C.curr=D,p=D,b[0]=r.coerce(b[0]),typeof b[0]!="string"&&b.unshift("%O");let B=0;b[0]=b[0].replace(/%([a-zA-Z%])/g,(ce,j)=>{if(ce==="%%")return"%";B++;let pe=r.formatters[j];if(typeof pe=="function"){let ue=b[B];ce=pe.call(C,ue),b.splice(B,1),B--}return ce}),r.formatArgs.call(C,b),h?.onLog!=null&&h.onLog(...b),(C.log||r.log).apply(C,b)}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:(X!==r.namespaces&&(X=r.namespaces,M=r.enabled(f)),M),set:b=>{x=b}}),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 kn=zh(),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 Nh(){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 Uh(t){if(t[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+t[0]+(this.useColors?"%c ":" ")+"+"+Dn(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 Oh=console.debug??console.log??(()=>{});function Rh(t){try{t?kn?.setItem("debug",t):kn?.removeItem("debug")}catch{}}function $h(){let t;try{t=kn?.getItem("debug")}catch{}return!t&&typeof globalThis.process<"u"&&"env"in globalThis.process&&(t=globalThis.process.env.DEBUG),t}function zh(){try{return localStorage}catch{}}function Vh(t){t.j=function(e){try{return JSON.stringify(e)}catch(r){return"[UnexpectedJSONParseError]: "+r.message}}}var xc=Ds({formatArgs:Uh,save:Rh,load:$h,useColors:Nh,setupFormatters:Vh,colors:Fh,storage:kn,log:Oh});var Q=xc;Q.formatters.b=t=>t==null?"undefined":se.baseEncode(t);Q.formatters.t=t=>t==null?"undefined":ge.baseEncode(t);Q.formatters.m=t=>t==null?"undefined":Hn.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 Ec(t,e=""){let r=_c(t.message),n=_c(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 Uh(t){return t instanceof AggregateError||t?.name==="AggregateError"&&Array.isArray(t.errors)}function _c(t,e=""){if(Uh(t)){let r=wc(t,e);return t.errors.length>0?(e=`${e} `,r+=`
10
- ${e}${t.errors.map(n=>`${_c(n,`${e}`)}`).join(`
9
+ ${e}`)}`:r!=null?`${r}`:`${t.toString()}`}function jh(t){return t instanceof AggregateError||t?.name==="AggregateError"&&Array.isArray(t.errors)}function vc(t,e=""){if(jh(t)){let r=Ec(t,e);return t.errors.length>0?(e=`${e} `,r+=`
10
+ ${e}${t.errors.map(n=>`${vc(n,`${e}`)}`).join(`
11
11
  ${e}`)}`):r+=`
12
- ${e}[Error list was empty]`,r.trim()}return wc(t,e)}Q.formatters.e=t=>t==null?"undefined":_c(t);function Oh(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 dr(t){return{forComponent(e){return vc(e,t)}}}function vc(t,e){let r=Oh(`${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=>vc(`${t}:${n}`,e)})}function Ec(t){if(t!=null&&(t=t.trim(),t.length!==0))return t}var Rh=0,Ds=class extends rt{local;remote;constructor(e){let r=`${Rh++}`;super({...e,id:r,log:dr().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 ye(e));return{sentBytes:e.byteLength,canSendMore:r}}sendReset(){this.local.send(new Event("reset"))}async sendCloseWrite(e){return R(new Promise((r,n)=>{this.local.send(new Event("closeWrite")),this.local.onIdle().then(r,n)}),e?.signal)}async sendCloseRead(e){return R(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 Sc=Symbol.for("sindresorhus/unlimited-timeout#brand");function Cc(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={[Sc]:!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(),h=Math.max(0,s-u);i(h)},2147483647),n&&o.id?.unref?.()))};return i(e),o}function Ic(t){!t||typeof t!="object"||!t[Sc]||(t.cleared=!0,t.id!==void 0&&(globalThis.clearTimeout(t.id),t.id=void 0))}var $h=new WeakMap;function zh({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,h=()=>{u(s),a(o.reason)},f=()=>{o&&o.removeEventListener("abort",h)},l=new Promise((p,E)=>{i=()=>{f(),p(n)},a=E,s=(e??setTimeout)(i,r)});return o&&o.addEventListener("abort",h,{once:!0}),$h.set(l,()=>{u(s),s=null,i()}),l}}var Vh=zh({setTimeout:Cc,clearTimeout:Ic}),ks=Vh;var jh=1024*64,mr=class extends be{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??jh,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(qh(e)){let r=new P(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 ye(o);this.queue.add(async i=>{this.delay>0&&await R(ks(this.delay),i.signal),this.dispatchEvent(i.evt)},{evt:s})}}else this.queue.add(async r=>{this.delay>0&&await R(ks(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 qh(t){return t?.data instanceof Uint8Array||ut(t?.data)}var Lc=0,Dn=class extends tr{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 ye(e));return{sentBytes:e.byteLength,canSendMore:r}}sendReset(){this.local.send(new Event("reset"))}async sendClose(e){return this.local.needsDrain&&await O(this.local,"drain",{signal:e?.signal}),R(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 Bs(t={}){let e=`${Lc++}`,r=`${Lc++}`,n=dr().forComponent(`libp2p:mock-maconn:outbound:${e}`),o=dr().forComponent(`libp2p:mock-maconn:inbound:${r}`),s=new mr({...t,log:n}),i=new mr({...t,log:o});return[new Dn({...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 Dn({...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 Ps=class extends de{has(e){return this.find(e)!=null}find(e){return this.queue.find(r=>e.equals(r.options.peerId))}};var Ms=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 Fs=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 kn}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 Jt("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)}},kn=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 Wh(t,e,r){let n,o,s=!1;function i(){let h={signal:o.signal},f;r?.timeout!=null&&(f=Zr([o.signal,AbortSignal.timeout(r.timeout)]),h.signal=f),s=!0,Promise.resolve().then(async()=>{await t(h)}).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=At(i,r?.debounce??100),u=!1;return{setInterval:h=>{e!==h&&(e=h,n!=null&&(clearTimeout(n),n=setTimeout(i,e)))},setTimeout:h=>{r??={},r.timeout=h},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 Ac(t={}){let[e,r]=Bs({...t,outbound:t.outboundConnection,inbound:t.inboundConnection}),n=Ln({streamOptions:t.outbound}).createStreamMuxer(e),o=Ln({streamOptions:t.inbound}).createStreamMuxer(r),[s,i]=await Promise.all([O(o,"stream").then(a=>a.detail),n.createStream({...t.outbound,protocol:t.protocol})]);return[i,s]}async function Gh(t={}){let[e,r]=await Ac(t);return ls(r),e}function Hh(t){let{name:e,metrics:r}=t,n=[];return r?.registerMetric(e,{calculate:()=>n.length}),n}var Ns=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 Qh(t){let{name:e,metrics:r}=t,n;return r!=null?n=new Ns({name:e,metrics:r}):n=new Map,n}return Fc(Xh);})();
12
+ ${e}[Error list was empty]`,r.trim()}return Ec(t,e)}Q.formatters.e=t=>t==null?"undefined":vc(t);function qh(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 mr(t){return{forComponent(e){return Sc(e,t)}}}function Sc(t,e){let r=qh(`${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=>Sc(`${t}:${n}`,e)})}function _c(t){if(t!=null&&(t=t.trim(),t.length!==0))return t}var Wh=0,ks=class extends nt{local;remote;constructor(e){let r=`${Wh++}`;super({...e,id:r,log:mr().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 $(new Promise((r,n)=>{this.local.send(new Event("closeWrite")),this.local.onIdle().then(r,n)}),e?.signal)}async sendCloseRead(e){return $(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 Cc=Symbol.for("sindresorhus/unlimited-timeout#brand");function Ic(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={[Cc]:!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 Lc(t){!t||typeof t!="object"||!t[Cc]||(t.cleared=!0,t.id!==void 0&&(globalThis.clearTimeout(t.id),t.id=void 0))}var Gh=new WeakMap;function Hh({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}),Gh.set(h,()=>{u(s),s=null,i()}),h}}var Qh=Hh({setTimeout:Ic,clearTimeout:Lc}),Bs=Qh;var Xh=1024*64,pr=class extends we{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??Xh,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(Kh(e)){let r=new P(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 $(Bs(this.delay),i.signal),this.dispatchEvent(i.evt)},{evt:s})}}else this.queue.add(async r=>{this.delay>0&&await $(Bs(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 Kh(t){return t?.data instanceof Uint8Array||lt(t?.data)}var Ac=0,Bn=class extends nr{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 R(this.local,"drain",{signal:e?.signal}),$(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 Ps(t={}){let e=`${Ac++}`,r=`${Ac++}`,n=mr().forComponent(`libp2p:mock-maconn:outbound:${e}`),o=mr().forComponent(`libp2p:mock-maconn:inbound:${r}`),s=new pr({...t,log:n}),i=new pr({...t,log:o});return[new Bn({...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 Bn({...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 Ms=class extends de{has(e){return this.find(e)!=null}find(e){return this.queue.find(r=>e.equals(r.options.peerId))}};var Fs=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 Ns=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 Pn}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 Yt("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)}},Pn=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 Jh(t,e,r){let n,o,s=!1;function i(){let l={signal:o.signal},f;r?.timeout!=null&&(f=Zr([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=Dt(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 Tc(t={}){let[e,r]=Ps({...t,outbound:t.outboundConnection,inbound:t.inboundConnection}),n=Tn({streamOptions:t.outbound}).createStreamMuxer(e),o=Tn({streamOptions:t.inbound}).createStreamMuxer(r),[s,i]=await Promise.all([R(o,"stream").then(a=>a.detail),n.createStream({...t.outbound,protocol:t.protocol})]);return[i,s]}async function Zh(t={}){let[e,r]=await Tc(t);return ds(r),e}function Yh(t){let{name:e,metrics:r}=t,n=[];return r?.registerMetric(e,{calculate:()=>n.length}),n}var Us=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 ed(t){let{name:e,metrics:r}=t,n;return r!=null?n=new Us({name:e,metrics:r}):n=new Map,n}return Uc(td);})();
13
13
  return Libp2PUtils}));
14
14
  //# sourceMappingURL=index.min.js.map