@libp2p/utils 7.0.15 → 7.0.17

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.
Files changed (64) hide show
  1. package/dist/index.min.js +4 -9
  2. package/dist/index.min.js.map +4 -4
  3. package/dist/src/abstract-stream.d.ts +2 -2
  4. package/dist/src/abstract-stream.js +1 -1
  5. package/dist/src/adaptive-timeout.js +1 -1
  6. package/dist/src/errors.d.ts +1 -1
  7. package/dist/src/filters/bloom-filter.d.ts +1 -1
  8. package/dist/src/filters/bloom-filter.js +1 -1
  9. package/dist/src/filters/bucket.d.ts +1 -1
  10. package/dist/src/filters/bucket.js +2 -2
  11. package/dist/src/filters/cuckoo-filter.d.ts +2 -2
  12. package/dist/src/filters/cuckoo-filter.js +4 -4
  13. package/dist/src/filters/fingerprint.d.ts +1 -1
  14. package/dist/src/filters/index.d.ts +6 -6
  15. package/dist/src/filters/index.js +3 -3
  16. package/dist/src/filters/scalable-cuckoo-filter.d.ts +2 -2
  17. package/dist/src/filters/scalable-cuckoo-filter.js +3 -3
  18. package/dist/src/get-thin-waist-addresses.js +1 -1
  19. package/dist/src/index.d.ts +31 -31
  20. package/dist/src/index.js +31 -31
  21. package/dist/src/message-queue.js +1 -1
  22. package/dist/src/mock-muxer.js +1 -1
  23. package/dist/src/multiaddr/index.d.ts +5 -5
  24. package/dist/src/multiaddr/index.js +5 -5
  25. package/dist/src/peer-queue.d.ts +2 -2
  26. package/dist/src/peer-queue.js +1 -1
  27. package/dist/src/priority-queue.d.ts +2 -2
  28. package/dist/src/priority-queue.js +1 -1
  29. package/dist/src/queue/index.d.ts +5 -4
  30. package/dist/src/queue/index.d.ts.map +1 -1
  31. package/dist/src/queue/index.js +4 -3
  32. package/dist/src/queue/index.js.map +1 -1
  33. package/dist/src/queue/job.d.ts +5 -4
  34. package/dist/src/queue/job.d.ts.map +1 -1
  35. package/dist/src/queue/job.js +10 -5
  36. package/dist/src/queue/job.js.map +1 -1
  37. package/dist/src/queue/recipient.d.ts +5 -2
  38. package/dist/src/queue/recipient.d.ts.map +1 -1
  39. package/dist/src/queue/recipient.js +4 -2
  40. package/dist/src/queue/recipient.js.map +1 -1
  41. package/dist/src/rate-limiter.js +1 -1
  42. package/dist/src/stream-utils.js +1 -1
  43. package/package.json +9 -7
  44. package/src/abstract-stream.ts +2 -2
  45. package/src/adaptive-timeout.ts +1 -1
  46. package/src/errors.ts +1 -1
  47. package/src/filters/bloom-filter.ts +2 -2
  48. package/src/filters/bucket.ts +2 -2
  49. package/src/filters/cuckoo-filter.ts +6 -6
  50. package/src/filters/fingerprint.ts +1 -1
  51. package/src/filters/index.ts +6 -6
  52. package/src/filters/scalable-cuckoo-filter.ts +6 -6
  53. package/src/get-thin-waist-addresses.ts +1 -1
  54. package/src/index.ts +31 -31
  55. package/src/message-queue.ts +1 -1
  56. package/src/mock-muxer.ts +1 -1
  57. package/src/multiaddr/index.ts +5 -5
  58. package/src/peer-queue.ts +2 -2
  59. package/src/priority-queue.ts +2 -2
  60. package/src/queue/index.ts +10 -6
  61. package/src/queue/job.ts +13 -7
  62. package/src/queue/recipient.ts +7 -3
  63. package/src/rate-limiter.ts +1 -1
  64. package/src/stream-utils.ts +1 -1
package/dist/index.min.js CHANGED
@@ -1,19 +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 oa=Object.create;var Ht=Object.defineProperty;var sa=Object.getOwnPropertyDescriptor;var ia=Object.getOwnPropertyNames;var aa=Object.getPrototypeOf,ca=Object.prototype.hasOwnProperty;var jr=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),V=(t,e)=>{for(var r in e)Ht(t,r,{get:e[r],enumerable:!0})},Eo=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of ia(e))!ca.call(t,o)&&o!==r&&Ht(t,o,{get:()=>e[o],enumerable:!(n=sa(e,o))||n.enumerable});return t};var ua=(t,e,r)=>(r=t!=null?oa(aa(t)):{},Eo(e||!t||!t.__esModule?Ht(r,"default",{value:t,enumerable:!0}):r,t)),fa=t=>Eo(Ht({},"__esModule",{value:!0}),t);var Cn=jr(tt=>{"use strict";Object.defineProperty(tt,"__esModule",{value:!0});tt.Netmask4Impl=void 0;tt.ip2long=et;tt.long2ip=ce;function ce(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 Rc=48,$c=97,zc=65;function Vc(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)-Rc)>>>0;else if(r===16)if("a"<=t[o]&&t[o]<="f")e=e*r+(10+t.charCodeAt(o)-$c)>>>0;else if("A"<=t[o]&&t[o]<="F")e=e*r+(10+t.charCodeAt(o)-zc)>>>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]=Vc(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 In=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=ce(this.netLong),this.mask=ce(this.maskLong),this.hostmask=ce(~this.maskLong),this.first=this.bitmask<=30?ce(this.netLong+1):this.base,this.last=this.bitmask<=30?ce(this.netLong+this.size-2):ce(this.netLong+this.size-1),this.broadcast=this.bitmask<=30?ce(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(ce(this.netLong+this.size*e),this.mask)}forEach(e){let r=et(this.first),n=et(this.last),o=0;for(;r<=n;)e(ce(r),r,o),o++,r++}toString(){return this.base+"/"+this.bitmask}};tt.Netmask4Impl=In});var is=jr(rt=>{"use strict";Object.defineProperty(rt,"__esModule",{value:!0});rt.Netmask6Impl=void 0;rt.ip6bigint=An;rt.bigint2ip6=Ue;var jc=Cn(),Ln=(1n<<128n)-1n;function An(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,jc.ip2long)(n),s=t.substring(0,r+1)+"0:0";return ss(s)&~0xffffffffn|BigInt(o)}return ss(t)}function ss(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 Ue(t){if(t<0n||t>Ln)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 Tn=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=Ln>>BigInt(128-this.bitmask)<<BigInt(128-this.bitmask);try{this.netBigint=An(e)&this.maskBigint}catch{throw new Error("Invalid IPv6 net address: "+e)}this.size=Number(1n<<BigInt(128-this.bitmask)),this.base=Ue(this.netBigint),this.mask=Ue(this.maskBigint),this.hostmask=Ue(~this.maskBigint&Ln),this.first=this.base,this.last=Ue(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):(An(e)&this.maskBigint)===this.netBigint}next(e=1){let r=1n<<BigInt(128-this.bitmask);return new t(Ue(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(Ue(r),Number(r),s),s++,r++}toString(){return this.base+"/"+this.bitmask}};rt.Netmask6Impl=Tn});var as=jr(ar=>{"use strict";Object.defineProperty(ar,"__esModule",{value:!0});ar.Netmask=void 0;var qc=Cn(),Wc=is(),Dn=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 Wc.Netmask6Impl(e,r):this._impl=new qc.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}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()}};ar.Netmask=Dn});var Dl={};V(Dl,{AbstractMessageStream:()=>Me,AbstractMultiaddrConnection:()=>Tt,AbstractStream:()=>Pe,AbstractStreamMuxer:()=>Dt,AdaptiveTimeout:()=>Pn,BloomFilter:()=>Et,CuckooFilter:()=>_e,DEFAULT_FAILURE_MULTIPLIER:()=>ls,DEFAULT_INTERVAL:()=>ms,DEFAULT_MAX_TIMEOUT:()=>ds,DEFAULT_MIN_TIMEOUT:()=>hs,DEFAULT_TIMEOUT_MULTIPLIER:()=>fs,InvalidDataLengthError:()=>pr,InvalidDataLengthLengthError:()=>gr,InvalidMessageLengthError:()=>it,LengthPrefixedDecoder:()=>Qn,MaxEarlyStreamsError:()=>Lt,MemoryStorage:()=>Vr,MockStream:()=>mo,MovingAverage:()=>Oe,PeerQueue:()=>bo,PriorityQueue:()=>yo,Queue:()=>re,QueueFullError:()=>Ct,RateLimitError:()=>It,RateLimiter:()=>xo,ScalableCuckooFilter:()=>vt,StreamClosedError:()=>At,UnexpectedEOFError:()=>Ce,UnwrappedError:()=>Ft,byteStream:()=>Ps,createBloomFilter:()=>Qo,createCuckooFilter:()=>Ko,createScalableCuckooFilter:()=>Jo,debounce:()=>ot,echo:()=>Xn,echoStream:()=>Ll,getNetConfig:()=>q,getThinWaistAddresses:()=>Zu,ipPortToMultiaddr:()=>tf,isAsyncGenerator:()=>rf,isGenerator:()=>nf,isGlobalUnicast:()=>Uc,isGlobalUnicastIp:()=>ef,isLinkLocal:()=>Mc,isLinkLocalIp:()=>Ef,isLoopback:()=>Pc,isNetworkAddress:()=>Oc,isPrivate:()=>Zc,isPrivateIp:()=>Fn,isPromise:()=>Mn,lpStream:()=>Os,messageStreamToDuplex:()=>Rs,mockMuxer:()=>Or,multiaddrConnectionPair:()=>go,pbStream:()=>gf,pipe:()=>yf,repeatingTask:()=>Cl,streamPair:()=>ra,trackedList:()=>Al,trackedMap:()=>Tl});var de=class extends Error{static name="AbortError";constructor(e="The operation was aborted"){super(e),this.name="AbortError"}};var $=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}};var Xt=class extends Error{static name="MuxerClosedError";constructor(e="The muxer is closed"){super(e),this.name="MuxerClosedError"}},Qt=class extends Error{static name="StreamResetError";constructor(e="The stream has been reset"){super(e),this.name="StreamResetError"}};var xe=class extends Error{static name="StreamStateError";constructor(e="The stream is in an invalid state"){super(e),this.name="StreamStateError"}},dt=class extends Error{static name="StreamBufferError";constructor(e="The stream buffer was full"){super(e),this.name="StreamBufferError"}};var se=class extends Event{data;constructor(e,r){super("message",r),this.data=e}},je=class extends Event{error;local;constructor(e,r,n){super("close",n),this.error=r,this.local=e}},Kt=class extends je{constructor(e,r){super(!0,e,r)}},Jt=class extends je{constructor(e,r){super(!1,e,r)}};var ie=class extends EventTarget{#e=new Map;constructor(){super()}listenerCount(e){let r=this.#e.get(e);return r==null?0:r.length}addEventListener(e,r,n){super.addEventListener(e,r,n);let o=this.#e.get(e);o==null&&(o=[],this.#e.set(e,o)),o.push({callback:r,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(e,r,n){super.removeEventListener(e.toString(),r??null,n);let o=this.#e.get(e);o!=null&&(o=o.filter(({callback:s})=>s!==r),this.#e.set(e,o))}dispatchEvent(e){let r=super.dispatchEvent(e),n=this.#e.get(e.type);return n==null||(n=n.filter(({once:o})=>!o),this.#e.set(e.type,n)),r}safeDispatchEvent(e,r={}){return this.dispatchEvent(new CustomEvent(e,r))}};var Xr={};V(Xr,{base58btc:()=>Q,base58flickr:()=>ba});var Ul=new Uint8Array(0);function vo(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}function me(t){if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return t;if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);throw new Error("Unknown type, must be binary type")}function _o(t){return new TextEncoder().encode(t)}function So(t){return new TextDecoder().decode(t)}function la(t,e){if(t.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var o=0;o<t.length;o++){var s=t.charAt(o),i=s.charCodeAt(0);if(r[i]!==255)throw new TypeError(s+" is ambiguous");r[i]=o}var a=t.length,u=t.charAt(0),l=Math.log(a)/Math.log(256),f=Math.log(256)/Math.log(a);function h(x){if(x instanceof Uint8Array||(ArrayBuffer.isView(x)?x=new Uint8Array(x.buffer,x.byteOffset,x.byteLength):Array.isArray(x)&&(x=Uint8Array.from(x))),!(x instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(x.length===0)return"";for(var _=0,b=0,w=0,I=x.length;w!==I&&x[w]===0;)w++,_++;for(var C=(I-w)*f+1>>>0,O=new Uint8Array(C);w!==I;){for(var N=x[w],he=0,R=C-1;(N!==0||he<b)&&R!==-1;R--,he++)N+=256*O[R]>>>0,O[R]=N%a>>>0,N=N/a>>>0;if(N!==0)throw new Error("Non-zero carry");b=he,w++}for(var Y=C-b;Y!==C&&O[Y]===0;)Y++;for(var Te=u.repeat(_);Y<C;++Y)Te+=t.charAt(O[Y]);return Te}function p(x){if(typeof x!="string")throw new TypeError("Expected String");if(x.length===0)return new Uint8Array;var _=0;if(x[_]!==" "){for(var b=0,w=0;x[_]===u;)b++,_++;for(var I=(x.length-_)*l+1>>>0,C=new Uint8Array(I);x[_];){var O=r[x.charCodeAt(_)];if(O===255)return;for(var N=0,he=I-1;(O!==0||N<w)&&he!==-1;he--,N++)O+=a*C[he]>>>0,C[he]=O%256>>>0,O=O/256>>>0;if(O!==0)throw new Error("Non-zero carry");w=N,_++}if(x[_]!==" "){for(var R=I-w;R!==I&&C[R]===0;)R++;for(var Y=new Uint8Array(b+(I-R)),Te=b;R!==I;)Y[Te++]=C[R++];return Y}}}function y(x){var _=p(x);if(_)return _;throw new Error(`Non-${e} character`)}return{encode:h,decodeUnsafe:p,decode:y}}var ha=la,da=ha,Co=da;var qr=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")}},Wr=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,r,n){this.name=e,this.prefix=r;let o=r.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return Lo(this,e)}},Gr=class{decoders;constructor(e){this.decoders=e}or(e){return Lo(this,e)}decode(e){let r=e[0],n=this.decoders[r];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Lo(t,e){return new Gr({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var Hr=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 qr(e,r,n),this.decoder=new Wr(e,r,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function qe({name:t,prefix:e,encode:r,decode:n}){return new Hr(t,e,r,n)}function we({name:t,prefix:e,alphabet:r}){let{encode:n,decode:o}=Co(r,t);return qe({prefix:e,name:t,encode:n,decode:s=>me(o(s))})}function ma(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 pa(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 ga(t){let e={};for(let r=0;r<t.length;++r)e[t[r]]=r;return e}function L({name:t,prefix:e,bitsPerChar:r,alphabet:n}){let o=ga(n);return qe({prefix:e,name:t,encode(s){return pa(s,n,r)},decode(s){return ma(s,o,r,t)}})}var Q=we({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),ba=we({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Qr={};V(Qr,{base32:()=>ae,base32hex:()=>Ea,base32hexpad:()=>_a,base32hexpadupper:()=>Sa,base32hexupper:()=>va,base32pad:()=>xa,base32padupper:()=>wa,base32upper:()=>ya,base32z:()=>Ia});var ae=L({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),ya=L({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),xa=L({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),wa=L({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Ea=L({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),va=L({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),_a=L({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Sa=L({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Ia=L({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Kr={};V(Kr,{base36:()=>mt,base36upper:()=>Ca});var mt=we({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Ca=we({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var La=Do,Ao=128,Aa=127,Ta=~Aa,Da=Math.pow(2,31);function Do(t,e,r){e=e||[],r=r||0;for(var n=r;t>=Da;)e[r++]=t&255|Ao,t/=128;for(;t&Ta;)e[r++]=t&255|Ao,t>>>=7;return e[r]=t|0,Do.bytes=r-n+1,e}var ka=Jr,Fa=128,To=127;function Jr(t,n){var r=0,n=n||0,o=0,s=n,i,a=t.length;do{if(s>=a)throw Jr.bytes=0,new RangeError("Could not decode varint");i=t[s++],r+=o<28?(i&To)<<o:(i&To)*Math.pow(2,o),o+=7}while(i>=Fa);return Jr.bytes=s-n,r}var Ba=Math.pow(2,7),Na=Math.pow(2,14),Ua=Math.pow(2,21),Ma=Math.pow(2,28),Pa=Math.pow(2,35),Oa=Math.pow(2,42),Ra=Math.pow(2,49),$a=Math.pow(2,56),za=Math.pow(2,63),Va=function(t){return t<Ba?1:t<Na?2:t<Ua?3:t<Ma?4:t<Pa?5:t<Oa?6:t<Ra?7:t<$a?8:t<za?9:10},ja={encode:La,decode:ka,encodingLength:Va},qa=ja,pt=qa;function gt(t,e=0){return[pt.decode(t,e),pt.decode.bytes]}function We(t,e,r=0){return pt.encode(t,e,r),e}function Ge(t){return pt.encodingLength(t)}function Xe(t,e){let r=e.byteLength,n=Ge(t),o=n+Ge(r),s=new Uint8Array(o+r);return We(t,s,0),We(r,s,n),s.set(e,o),new He(t,r,e,s)}function ko(t){let e=me(t),[r,n]=gt(e),[o,s]=gt(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new He(r,o,i,e)}function Fo(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&vo(t.bytes,r.bytes)}}var He=class{code;size;digest;bytes;constructor(e,r,n,o){this.code=e,this.size=r,this.digest=n,this.bytes=o}};function Bo(t,e){let{bytes:r,version:n}=t;switch(n){case 0:return Ga(r,Yr(t),e??Q.encoder);default:return Ha(r,Yr(t),e??ae.encoder)}}var No=new WeakMap;function Yr(t){let e=No.get(t);if(e==null){let r=new Map;return No.set(t,r),r}return e}var Qe=class t{code;version;multihash;bytes;"/";constructor(e,r,n,o){this.code=r,this.version=e,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:r}=this;if(e!==yt)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Xa)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=Xe(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&&Fo(e.multihash,n.multihash)}toString(e){return Bo(this,e)}toJSON(){return{"/":Bo(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??Uo(n,o,s.bytes))}else if(r[Qa]===!0){let{version:n,multihash:o,code:s}=r,i=ko(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!==yt)throw new Error(`Version 0 CID must use dag-pb (code: ${yt}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let o=Uo(e,r,n.bytes);return new t(e,r,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,yt,e)}static createV1(e,r){return t.create(1,e,r)}static decode(e){let[r,n]=t.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(e){let r=t.inspectBytes(e),n=r.size-r.multihashSize,o=me(e.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let s=o.subarray(r.multihashSize-r.digestSize),i=new He(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]=gt(e.subarray(r));return r+=p,h},o=n(),s=yt;if(o===18?(o=0,r=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=r,a=n(),u=n(),l=r+u,f=l-i;return{version:o,codec:s,multihashCode:a,digestSize:u,multihashSize:f,size:l}}static parse(e,r){let[n,o]=Wa(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 Yr(s).set(n,e),s}};function Wa(t,e){switch(t[0]){case"Q":{let r=e??Q;return[Q.prefix,r.decode(`${Q.prefix}${t}`)]}case Q.prefix:{let r=e??Q;return[Q.prefix,r.decode(t)]}case ae.prefix:{let r=e??ae;return[ae.prefix,r.decode(t)]}case mt.prefix:{let r=e??mt;return[mt.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 Ga(t,e,r){let{prefix:n}=r;if(n!==Q.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=e.get(n);if(o==null){let s=r.encode(t).slice(1);return e.set(n,s),s}else return o}function Ha(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 yt=112,Xa=18;function Uo(t,e,r){let n=Ge(t),o=n+Ge(e),s=new Uint8Array(o+r.byteLength);return We(t,s,0),We(e,s,n),s.set(r,o),s}var Qa=Symbol.for("@ipld/js-cid/CID");var Zr={};V(Zr,{identity:()=>Ya});var Mo=0,Ka="identity",Po=me;function Ja(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 Xe(Mo,Po(t))}var Ya={code:Mo,name:Ka,encode:Po,digest:Ja};function Ke(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}function j(t=0){return new Uint8Array(t)}function Z(t=0){return new Uint8Array(t)}function Ee(t,e){e==null&&(e=t.reduce((o,s)=>o+s.length,0));let r=Z(e),n=0;for(let o of t)r.set(o,n),n+=o.length;return r}var Ro=Symbol.for("@achingbrain/uint8arraylist");function Oo(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 Je(t){return!!t?.[Ro]}var A=class t{bufs;length;[Ro]=!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(Je(n))r+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}prepend(...e){this.prependAll(e)}prependAll(e){let r=0;for(let n of e.reverse())if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.unshift(n);else if(Je(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=Oo(this.bufs,e);return r.buf[r.index]}set(e,r){let n=Oo(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(Je(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 Ee(n,o)}subarray(e,r){let{bufs:n,length:o}=this._subList(e,r);return n.length===1?n[0]:Ee(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(!Je(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 y=this.get(h+p);if(n[p]!==y){f=Math.max(1,p-a[y]);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=Z(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,r),this.write(n,e)}getInt16(e,r){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,r)}setInt16(e,r,n){let o=j(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,r,n),this.write(o,e)}getInt32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,r)}setInt32(e,r,n){let o=j(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,r,n),this.write(o,e)}getBigInt64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,r)}setBigInt64(e,r,n){let o=j(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,r,n),this.write(o,e)}getUint8(e){let r=this.subarray(e,e+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint8(0)}setUint8(e,r){let n=Z(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,r),this.write(n,e)}getUint16(e,r){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,r)}setUint16(e,r,n){let o=j(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,r,n),this.write(o,e)}getUint32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,r)}setUint32(e,r,n){let o=j(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,r,n),this.write(o,e)}getBigUint64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,r)}setBigUint64(e,r,n){let o=j(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,r,n),this.write(o,e)}getFloat32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,r)}setFloat32(e,r,n){let o=j(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,r,n),this.write(o,e)}getFloat64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,r)}setFloat64(e,r,n){let o=j(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,r,n),this.write(o,e)}equals(e){if(e==null||!(e instanceof t)||e.bufs.length!==this.bufs.length)return!1;for(let r=0;r<this.bufs.length;r++)if(!Ke(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 en={};V(en,{base10:()=>Za});var Za=we({prefix:"9",name:"base10",alphabet:"0123456789"});var tn={};V(tn,{base16:()=>ec,base16upper:()=>tc});var ec=L({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),tc=L({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var rn={};V(rn,{base2:()=>rc});var rc=L({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var nn={};V(nn,{base256emoji:()=>ac});var $o=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}"),nc=$o.reduce((t,e,r)=>(t[r]=e,t),[]),oc=$o.reduce((t,e,r)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return t[n]=r,t},[]);function sc(t){return t.reduce((e,r)=>(e+=nc[r],e),"")}function ic(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=oc[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(o)}return new Uint8Array(e)}var ac=qe({prefix:"\u{1F680}",name:"base256emoji",encode:sc,decode:ic});var an={};V(an,{base64:()=>on,base64pad:()=>cc,base64url:()=>sn,base64urlpad:()=>uc});var on=L({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),cc=L({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),sn=L({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),uc=L({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var cn={};V(cn,{base8:()=>fc});var fc=L({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var un={};V(un,{identity:()=>lc});var lc=qe({prefix:"\0",name:"identity",encode:t=>So(t),decode:t=>_o(t)});var yh=new TextEncoder,xh=new TextDecoder;var hn={};V(hn,{sha256:()=>pc,sha512:()=>gc});var mc=20;function ln({name:t,code:e,encode:r,minDigestLength:n,maxDigestLength:o}){return new fn(t,e,r,n,o)}var fn=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,r,n,o,s){this.name=e,this.code=r,this.encode=n,this.minDigestLength=o??mc,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?zo(n,this.code,r?.truncate):n.then(o=>zo(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function zo(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 Xe(e,t)}function jo(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}var pc=ln({name:"sha2-256",code:18,encode:jo("SHA-256")}),gc=ln({name:"sha2-512",code:19,encode:jo("SHA-512")});var xt={...un,...rn,...cn,...en,...tn,...Qr,...Kr,...Xr,...an,...nn},kh={...hn,...Zr};function Wo(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var qo=Wo("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),dn=Wo("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}),bc={utf8:qo,"utf-8":qo,hex:xt.base16,latin1:dn,ascii:dn,binary:dn,...xt},Zt=bc;function T(t,e="utf8"){let r=Zt[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}function De(t,e="utf8"){let r=Zt[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.encoder.encode(t).substring(1)}function Go(t=32){let e=typeof globalThis=="object"?globalThis.crypto:null;if(typeof e?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");return e.getRandomValues(new Uint8Array(t))}var yc=Math.pow(2,7),xc=Math.pow(2,14),wc=Math.pow(2,21),mn=Math.pow(2,28),pn=Math.pow(2,35),gn=Math.pow(2,42),bn=Math.pow(2,49),v=128,M=127;function P(t){if(t<yc)return 1;if(t<xc)return 2;if(t<wc)return 3;if(t<mn)return 4;if(t<pn)return 5;if(t<gn)return 6;if(t<bn)return 7;if(Number.MAX_SAFE_INTEGER!=null&&t>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function er(t,e,r=0){switch(P(t)){case 8:e[r++]=t&255|v,t/=128;case 7:e[r++]=t&255|v,t/=128;case 6:e[r++]=t&255|v,t/=128;case 5:e[r++]=t&255|v,t/=128;case 4:e[r++]=t&255|v,t>>>=7;case 3:e[r++]=t&255|v,t>>>=7;case 2:e[r++]=t&255|v,t>>>=7;case 1:{e[r++]=t&255,t>>>=7;break}default:throw new Error("unreachable")}return e}function Ec(t,e,r=0){switch(P(t)){case 8:e.set(r++,t&255|v),t/=128;case 7:e.set(r++,t&255|v),t/=128;case 6:e.set(r++,t&255|v),t/=128;case 5:e.set(r++,t&255|v),t/=128;case 4:e.set(r++,t&255|v),t>>>=7;case 3:e.set(r++,t&255|v),t>>>=7;case 2:e.set(r++,t&255|v),t>>>=7;case 1:{e.set(r++,t&255),t>>>=7;break}default:throw new Error("unreachable")}return e}function vc(t,e){let r=t[e],n=0;if(n+=r&M,r<v||(r=t[e+1],n+=(r&M)<<7,r<v)||(r=t[e+2],n+=(r&M)<<14,r<v)||(r=t[e+3],n+=(r&M)<<21,r<v)||(r=t[e+4],n+=(r&M)*mn,r<v)||(r=t[e+5],n+=(r&M)*pn,r<v)||(r=t[e+6],n+=(r&M)*gn,r<v)||(r=t[e+7],n+=(r&M)*bn,r<v))return n;throw new RangeError("Could not decode varint")}function _c(t,e){let r=t.get(e),n=0;if(n+=r&M,r<v||(r=t.get(e+1),n+=(r&M)<<7,r<v)||(r=t.get(e+2),n+=(r&M)<<14,r<v)||(r=t.get(e+3),n+=(r&M)<<21,r<v)||(r=t.get(e+4),n+=(r&M)*mn,r<v)||(r=t.get(e+5),n+=(r&M)*pn,r<v)||(r=t.get(e+6),n+=(r&M)*gn,r<v)||(r=t.get(e+7),n+=(r&M)*bn,r<v))return n;throw new RangeError("Could not decode varint")}function tr(t,e,r=0){return e==null&&(e=Z(P(t))),e instanceof Uint8Array?er(t,e,r):Ec(t,e,r)}function pe(t,e=0){return t instanceof Uint8Array?vc(t,e):_c(t,e)}function rr(t){if(isNaN(t)||t<=0)throw new $("random bytes length must be a Number bigger than 0");return Go(t)}var yn={32:16777619n,64:1099511628211n,128:309485009821345068724781371n,256:374144419156711147060143317175368453031918731002211n,512:35835915874844867368919076489095108449946327955754392558399825615420669938882575126094039892345713852759n,1024:5016456510113118655434598811035278955030765345404790744303017523831112055108147451509157692220295382716162651878526895249385292291816524375083746691371804094271873160484737966720260389217684476157468082573n},Ho={32:2166136261n,64:14695981039346656037n,128:144066263297769815596495629667062367629n,256:100029257958052580907070968620625704837092796014241193945225284501741471925557n,512:9659303129496669498009435400716310466090418745672637896108374329434462657994582932197716438449813051892206539805784495328239340083876191928701583869517785n,1024:14197795064947621068722070641403218320880622795441933960878474914617582723252296732303717722150864096521202355549365628174669108571814760471015076148029755969804077320157692458563003215304957150157403644460363550505412711285966361610267868082893823963790439336411086884584107735010676915n},Xo=new globalThis.TextEncoder;function Sc(t,e){let r=yn[e],n=Ho[e];for(let o=0;o<t.length;o++)n^=BigInt(t[o]),n=BigInt.asUintN(e,n*r);return n}function Ic(t,e,r){if(r.length===0)throw new Error("The `utf8Buffer` option must have a length greater than zero");let n=yn[e],o=Ho[e],s=t;for(;s.length>0;){let i=Xo.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 xn(t,{size:e=32,utf8Buffer:r}={}){if(!yn[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 Ic(t,e,r);t=Xo.encode(t)}return Sc(t,e)}var ve={hash:t=>Number(xn(t,{size:32})),hashV:(t,e)=>Cc(ve.hash(t,e))};function Cc(t){let e=t.toString(16);return e.length%2===1&&(e=`0${e}`),T(e,"base16")}var Lc=Math.LN2*Math.LN2,Et=class{seeds;bits;buffer;constructor(e={}){e.seeds!=null?this.seeds=e.seeds:this.seeds=Tc(e.hashes??8),this.bits=e.bits??1024,this.buffer=j(Math.ceil(this.bits/8))}add(e){typeof e=="string"&&(e=T(e));for(let r=0;r<this.seeds.length;r++){let o=ve.hash(e,this.seeds[r])%this.bits;this.setbit(o)}}has(e){typeof e=="string"&&(e=T(e));for(let r=0;r<this.seeds.length;r++){let o=ve.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 Qo(t,e=.005){let r=Ac(t,e);return new Et(r)}function Ac(t,e=.005){let r=Math.round(-1*t*Math.log(e)/Lc),n=Math.round(r/t*Math.LN2);return{bits:r,hashes:n}}function Tc(t){let e,r,n=[];for(let o=0;o<t;o++)for(e=new A(rr(4)),n[o]=e.getUint32(0,!0),r=0;r<o;r++)if(n[o]===n[r]){o--;break}return n}var wn=64,ee=class{fp;h;seed;constructor(e,r,n,o=2){if(o>wn)throw new TypeError("Invalid Fingerprint Size");let s=r.hashV(e,n),i=j(o);for(let a=0;a<i.length;a++)i[a]=s[a];i.length===0&&(i[0]=7),this.fp=i,this.h=r,this.seed=n}hash(){return this.h.hash(this.fp,this.seed)}equals(e){return e?.fp instanceof Uint8Array?Ke(this.fp,e.fp):!1}};function ke(t,e){return Math.floor(Math.random()*(e-t))+t}var Fe=class{contents;constructor(e){this.contents=new Array(e).fill(null)}has(e){if(!(e instanceof ee))throw new TypeError("Invalid Fingerprint");return this.contents.some(r=>e.equals(r))}add(e){if(!(e instanceof ee))throw new TypeError("Invalid Fingerprint");for(let r=0;r<this.contents.length;r++)if(this.contents[r]==null)return this.contents[r]=e,!0;return!0}swap(e){if(!(e instanceof ee))throw new TypeError("Invalid Fingerprint");let r=ke(0,this.contents.length-1),n=this.contents[r];return this.contents[r]=e,n}remove(e){if(!(e instanceof ee))throw new TypeError("Invalid Fingerprint");let r=this.contents.findIndex(n=>e.equals(n));return r>-1?(this.contents[r]=null,!0):!1}};var Dc=500,_e=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??ve,this.seed=e.seed??ke(0,Math.pow(2,10))}add(e){typeof e=="string"&&(e=T(e));let r=new ee(e,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(e,this.seed)%this.filterSize,o=(n^r.hash())%this.filterSize;if(this.buckets[n]==null&&(this.buckets[n]=new Fe(this.bucketSize)),this.buckets[o]==null&&(this.buckets[o]=new Fe(this.bucketSize)),this.buckets[n].add(r)||this.buckets[o].add(r))return this.count++,!0;let s=[n,o],i=s[ke(0,s.length-1)];this.buckets[i]==null&&(this.buckets[i]=new Fe(this.bucketSize));for(let a=0;a<Dc;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 Fe(this.bucketSize)),this.buckets[i].add(u)))return this.count++,!0}return!1}has(e){typeof e=="string"&&(e=T(e));let r=new ee(e,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(e,this.seed)%this.filterSize,o=this.buckets[n]?.has(r)??!1;if(o)return o;let s=(n^r.hash())%this.filterSize;return this.buckets[s]?.has(r)??!1}remove(e){typeof e=="string"&&(e=T(e));let r=new ee(e,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(e,this.seed)%this.filterSize,o=this.buckets[n]?.remove(r)??!1;if(o)return this.count--,o;let s=(n^r.hash())%this.filterSize,i=this.buckets[s]?.remove(r)??!1;return i&&this.count--,i}get reliable(){return Math.floor(100*(this.count/this.filterSize))<=90}},kc={1:.5,2:.84,4:.95,8:.98};function Fc(t=.001){return t>.002?2:t>1e-5?4:8}function En(t,e=.001){let r=Fc(e),n=kc[r],o=Math.round(t/n),s=Math.min(Math.ceil(Math.log2(1/e)+Math.log2(2*r)),wn);return{filterSize:o,bucketSize:r,fingerprintSize:s}}function Ko(t,e=.005){let r=En(t,e);return new _e(r)}var vt=class{filterSize;bucketSize;fingerprintSize;scale;filterSeries;hash;seed;constructor(e){this.bucketSize=e.bucketSize??4,this.filterSize=e.filterSize??(1<<18)/this.bucketSize,this.fingerprintSize=e.fingerprintSize??2,this.scale=e.scale??2,this.hash=e.hash??ve,this.seed=e.seed??ke(0,Math.pow(2,10)),this.filterSeries=[new _e({filterSize:this.filterSize,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed})]}add(e){if(typeof e=="string"&&(e=T(e)),this.has(e))return!0;let r=this.filterSeries.find(n=>n.reliable);if(r==null){let n=this.filterSize*Math.pow(this.scale,this.filterSeries.length);r=new _e({filterSize:n,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed}),this.filterSeries.push(r)}return r.add(e)}has(e){typeof e=="string"&&(e=T(e));for(let r=0;r<this.filterSeries.length;r++)if(this.filterSeries[r].has(e))return!0;return!1}remove(e){typeof e=="string"&&(e=T(e));for(let r=0;r<this.filterSeries.length;r++)if(this.filterSeries[r].remove(e))return!0;return!1}get count(){return this.filterSeries.reduce((e,r)=>e+r.count,0)}};function Jo(t,e=.001,r){return new vt({...En(t,e),...r??{}})}function q(t){let e=t.getComponents(),r={},n=0;if(e[n]?.name==="ip6zone"&&(r.zone=`${e[n].value}`,n++),e[n].name==="ip4"||e[n].name==="ip6"||e[n].name==="dns"||e[n].name==="dns4"||e[n].name==="dns6"?(r.type=e[n].name,r.host=e[n].value,n++):e[n].name==="dnsaddr"&&(r.type=e[n].name,r.host=`_dnsaddr.${e[n].value}`,n++),(e[n]?.name==="tcp"||e[n]?.name==="udp")&&(r.protocol=e[n].name==="tcp"?"tcp":"udp",r.port=parseInt(`${e[n].value}`),n++),e[n]?.name==="ipcidr"&&(r.type==="ip4"?r.cidr=parseInt(`${e[n].value}`):r.type==="ip6"&&(r.cidr=`${e[n].value}`),n++),r.type==null||r.host==null)throw new $(`Multiaddr ${t} was not an IPv4, IPv6, DNS, DNS4, DNS6 or DNSADDR address`);return e[n]?.name==="tls"&&e[n+1]?.name==="sni"&&(r.sni=e[n+1].value,n+=2),r}var nr=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 Yo=45,Bc=15,Ye=new nr;function or(t){if(!(t.length>Bc))return Ye.new(t).parseWith(()=>Ye.readIPv4Addr())}function sr(t){if(t.includes("%")&&(t=t.split("%")[0]),!(t.length>Yo))return Ye.new(t).parseWith(()=>Ye.readIPv6Addr())}function Ze(t,e=!1){if(t.includes("%")&&(t=t.split("%")[0]),t.length>Yo)return;let r=Ye.new(t).parseWith(()=>Ye.readIPAddr());if(r)return e&&r.length===4?Uint8Array.from([0,0,0,0,0,0,0,0,0,0,255,255,r[0],r[1],r[2],r[3]]):r}function Zo(t,e,r){let n=0;for(let o of t)if(!(n<e)){if(n>r)break;if(o!==255)return!1;n++}return!0}function es(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 vn(t){switch(t.length){case Be:return t.join(".");case Ne:{let e=[];for(let r=0;r<t.length;r++)r%2===0&&e.push(t[r].toString(16).padStart(2,"0")+t[r+1].toString(16).padStart(2,"0"));return e.join(":")}default:throw new Error("Invalid ip length")}}function ts(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 rs(t){let e="0x";for(let r of t)e+=(r>>4).toString(16)+(r&15).toString(16);return e}var Be=4,Ne=16,Nd=parseInt("0xFFFF",16),Nc=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function _t(t,e){e.length===Ne&&t.length===Be&&Zo(e,0,11)&&(e=e.slice(12)),e.length===Be&&t.length===Ne&&es(t,Nc,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 ns(t,e){if(typeof e=="string"&&(e=Ze(e)),e==null)throw new Error("Invalid ip");if(e.length!==t.network.length)return!1;for(let r=0;r<e.length;r++)if((t.network[r]&t.mask[r])!==(e[r]&t.mask[r]))return!1;return!0}function _n(t){let[e,r]=t.split("/");if(!e||!r)throw new Error("Failed to parse given CIDR: "+t);let n=Be,o=or(e);if(o==null&&(n=Ne,o=sr(e),o==null))throw new Error("Failed to parse given CIDR: "+t);let s=parseInt(r,10);if(Number.isNaN(s)||String(s).length!==r.length||s<0||s>n*8)throw new Error("Failed to parse given CIDR: "+t);let i=Sn(s,8*n);return{network:_t(o,i),mask:i}}function Sn(t,e){if(e!==8*Be&&e!==8*Ne)throw new Error("Invalid CIDR mask");if(t<0||t>e)throw new Error("Invalid CIDR mask");let r=e/8,n=new Uint8Array(r);for(let o=0;o<r;o++){if(t>=8){n[o]=255,t-=8;continue}n[o]=255-(255>>t),t=0}return n}var St=class{constructor(e,r){if(r==null)({network:this.network,mask:this.mask}=_n(e));else{let n=Ze(e);if(n==null)throw new Error("Failed to parse network");r=String(r);let o=parseInt(r,10);if(Number.isNaN(o)||String(o).length!==r.length||o<0||o>n.length*8){let s=Ze(r);if(s==null)throw new Error("Failed to parse mask");this.mask=s}else this.mask=Sn(o,8*n.length);this.network=_t(n,this.mask)}}contains(e){return ns({network:this.network,mask:this.mask},e)}toString(){let e=ts(this.mask),r=e!==-1?String(e):rs(this.mask);return vn(this.network)+"/"+r}};function ir(t,e){return new St(t).contains(e)}function Uc(t){try{let e=q(t);switch(e.type){case"ip6":return ir("2000::/3",e.host);default:return!1}}catch{return!1}}function Mc(t){try{let e=q(t);switch(e.type){case"ip4":return e.host.startsWith("169.254.");case"ip6":return e.host.toLowerCase().startsWith("fe80");default:return!1}}catch{return!1}}function os(t){return/^127\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/i.test(t)||/^::1$/.test(t)}function Pc(t){try{let e=q(t);switch(e.type){case"ip4":case"ip6":return os(e.host);default:return!1}}catch{return!1}}function Oc(t){try{return q(t),!0}catch{return!1}}function Se(t){return!!or(t)}function Ie(t){return!!sr(t)}var cs=ua(as(),1),Gc=["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"],Hc=Gc.map(t=>new cs.Netmask(t));function kn(t){for(let e of Hc)if(e.contains(t))return!0;return!1}function Xc(t){return/^::ffff:([0-9a-fA-F]{1,4}):([0-9a-fA-F]{1,4})$/.test(t)}function Qc(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 kn(o)}function Kc(t){return/^::ffff:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(t)}function Jc(t){let e=t.split(":"),r=e[e.length-1];return kn(r)}function Yc(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 Fn(t){if(Se(t))return kn(t);if(Xc(t))return Qc(t);if(Kc(t))return Jc(t);if(Ie(t))return Yc(t)}function Zc(t){try{let e=q(t);switch(e.type){case"ip4":case"ip6":return Fn(e.host)??!1;default:return e.host==="localhost"}}catch{return!1}}function te(){let t={};return t.promise=new Promise((e,r)=>{t.resolve=e,t.reject=r}),t}var cr=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}},nt=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new cr(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 cr(2*this.head.buffer.length),this.head.push(e)}}shift(){let e=this.tail.shift();if(e===void 0&&this.tail.next!=null){let r=this.tail.next;this.tail.next=null,this.tail=r,e=this.tail.shift()}return e?.value!=null&&(this.size-=this.calculateSize(e.value)),e}isEmpty(){return this.head.isEmpty()}};var Bn=class extends Error{type;code;constructor(e,r){super(e??"The operation was aborted"),this.type="aborted",this.code=r??"ABORT_ERR"}};function ue(t={}){return eu(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 eu(t,e){e=e??{};let r=e.onEnd,n=new nt,o,s,i,a=te(),u=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((b,w)=>{s=I=>{s=null,n.push(I);try{b(t(n))}catch(C){w(C)}return o}}):t(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=te()})}},l=b=>s!=null?s(b):(n.push(b),o),f=b=>(n=new nt,s!=null?s({error:b}):(n.push({error:b}),o)),h=b=>{if(i)return o;if(e?.objectMode!==!0&&b?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return l({done:!1,value:b})},p=b=>i?o:(i=!0,b!=null?f(b):l({done:!0})),y=()=>(n=new nt,p(),{done:!0}),x=b=>(p(b),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:u,return:y,throw:x,push:h,end:p,get readableLength(){return n.size},onEmpty:async b=>{let w=b?.signal;if(w?.throwIfAborted(),n.isEmpty())return;let I,C;w!=null&&(I=new Promise((O,N)=>{C=()=>{N(new Bn)},w.addEventListener("abort",C)}));try{await Promise.race([a.promise,I])}finally{C!=null&&w!=null&&w?.removeEventListener("abort",C)}}},r==null)return o;let _=o;return o={[Symbol.asyncIterator](){return this},next(){return _.next()},throw(b){return _.throw(b),r!=null&&(r(b),r=void 0),{done:!0}},return(){return _.return(),r!=null&&(r(),r=void 0),{done:!0}},push:h,end(b){return _.end(b),r!=null&&(r(b),r=void 0),o},get readableLength(){return _.readableLength},onEmpty:b=>_.onEmpty(b)},o}var Nn=class t extends Error{name="TimeoutError";constructor(e,r){super(e,r),Error.captureStackTrace?.(this,t)}},us=t=>t.reason??new DOMException("This operation was aborted.","AbortError");function Un(t,e){let{milliseconds:r,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout},signal:i}=e,a,u,f=new Promise((h,p)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(i?.aborted){p(us(i));return}if(i&&(u=()=>{p(us(i))},i.addEventListener("abort",u,{once:!0})),t.then(h,p),r===Number.POSITIVE_INFINITY)return;let y=new Nn;a=s.setTimeout.call(void 0,()=>{if(n){try{h(n())}catch(x){p(x)}return}typeof t.cancel=="function"&&t.cancel(),o===!1?h():o instanceof Error?p(o):(y.message=o??`Promise timed out after ${r} milliseconds`,p(y))},r)}).finally(()=>{f.clear(),u&&i&&i.removeEventListener("abort",u)});return f.clear=()=>{s.clearTimeout.call(void 0,a),a=void 0},f}var tu=t=>{let e=t.addEventListener||t.on||t.addListener,r=t.removeEventListener||t.off||t.removeListener;if(!e||!r)throw new TypeError("Emitter is not compatible");return{addListener:e.bind(t),removeListener:r.bind(t)}};function ru(t,e,r){let n,o=new Promise((s,i)=>{if(r={rejectionEvents:["error"],multiArgs:!1,rejectionMultiArgs:!1,resolveImmediately:!1,...r},!(r.count>=0&&(r.count===Number.POSITIVE_INFINITY||Number.isInteger(r.count))))throw new TypeError("The `count` option should be at least 0 or more");r.signal?.throwIfAborted();let a=[e].flat(),u=[],{addListener:l,removeListener:f}=tu(t),h=async(...y)=>{let x=r.multiArgs?y:y[0];if(r.filter)try{if(!await r.filter(x))return}catch(_){n(),i(_);return}u.push(x),r.count===u.length&&(n(),s(u))},p=(...y)=>{n(),i(r.rejectionMultiArgs?y:y[0])};n=()=>{for(let y of a)f(y,h);for(let y of r.rejectionEvents)a.includes(y)||f(y,p)};for(let y of a)l(y,h);for(let y of r.rejectionEvents)a.includes(y)||l(y,p);r.signal&&r.signal.addEventListener("abort",()=>{p(r.signal.reason)},{once:!0}),r.resolveImmediately&&s(u)});if(o.cancel=n,typeof r.timeout=="number"){let s=Un(o,{milliseconds:r.timeout});return s.cancel=()=>{n(),s.clear()},s}return o}function D(t,e,r){typeof r=="function"&&(r={filter:r}),r={...r,count:1,resolveImmediately:!1};let n=ru(t,e,r),o=n.then(s=>s[0]);return o.cancel=n.cancel,o}function ot(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 It=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}},Ct=class extends Error{static name="QueueFullError";constructor(e="The queue was full"){super(e),this.name="QueueFullError"}},Ce=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"},Lt=class extends Error{static name="MaxEarlyStreamsError";name="MaxEarlyStreamsError"},At=class extends Error{static name="StreamClosedError";name="StreamClosedError"};function nu(t){return t.reason}async function k(t,e,r){if(e==null)return t;let n=r?.translateError??nu;if(e.aborted)return t.catch(()=>{}),Promise.reject(n(e));let o;try{return await Promise.race([t,new Promise((s,i)=>{o=()=>{i(n(e))},e.addEventListener("abort",o)})])}finally{o!=null&&e.removeEventListener("abort",o)}}var ur=class{deferred;signal;constructor(e){this.signal=e,this.deferred=te(),this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(this.signal?.reason??new de)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function ou(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var fr=class{id;fn;options;recipients;status;timeline;controller;constructor(e,r){this.id=ou(),this.status="queued",this.fn=e,this.options=r,this.recipients=[],this.timeline={created:Date.now()},this.controller=new AbortController,this.controller.signal,this.onAbort=this.onAbort.bind(this)}abort(e){this.controller.abort(e)}onAbort(){this.recipients.reduce((r,n)=>r&&n.signal?.aborted===!0,!0)&&(this.controller.abort(new de),this.cleanup())}async join(e={}){let r=new ur(e.signal);return this.recipients.push(r),e.signal?.addEventListener("abort",this.onAbort),r.deferred.promise}async run(){this.status="running",this.timeline.started=Date.now();try{this.controller.signal.throwIfAborted();let e=await k(this.fn({...this.options??{},signal:this.controller.signal}),this.controller.signal);this.recipients.forEach(r=>{r.deferred.resolve(e)}),this.status="complete"}catch(e){this.recipients.forEach(r=>{r.deferred.reject(e)}),this.status="errored"}finally{this.timeline.finished=Date.now(),this.cleanup()}}cleanup(){this.recipients.forEach(e=>{e.cleanup(),e.signal?.removeEventListener("abort",this.onAbort)})}};var re=class extends ie{concurrency;maxSize;queue;pending;sort;paused;constructor(e={}){super(),this.concurrency=e.concurrency??Number.POSITIVE_INFINITY,this.maxSize=e.maxSize??Number.POSITIVE_INFINITY,this.pending=0,this.paused=!1,e.metricName!=null&&e.metrics?.registerMetricGroup(e.metricName,{calculate:()=>({size:this.queue.length,running:this.pending,queued:this.queue.length-this.pending})}),this.sort=e.sort,this.queue=[],this.emitEmpty=ot(this.emitEmpty.bind(this),1),this.emitIdle=ot(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 Ct;let n=new fr(e,r);return this.enqueue(n),this.safeDispatchEvent("add"),this.tryToStartAnother(),n.join(r).then(o=>(this.safeDispatchEvent("completed",{detail:o}),this.safeDispatchEvent("success",{detail:{job:n,result:o}}),o)).catch(o=>{if(n.status==="queued"){for(let s=0;s<this.queue.length;s++)if(this.queue[s]===n){this.queue.splice(s,1);break}}throw this.safeDispatchEvent("failure",{detail:{job:n,error:o}}),o})}clear(){this.queue.splice(0,this.queue.length)}abort(){this.queue.forEach(e=>{e.abort(new de)}),this.clear()}async onEmpty(e){this.size!==0&&await D(this,"empty",e)}async onSizeLessThan(e,r){this.size<e||await D(this,"next",{...r,filter:()=>this.size<e})}async onIdle(e){this.pending===0&&this.size===0||await D(this,"idle",e)}get size(){return this.queue.length}get queued(){return this.queue.length-this.pending}get running(){return this.pending}async*toGenerator(e){e?.signal?.throwIfAborted();let r=ue({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 de("Queue aborted"))};this.addEventListener("completed",o),this.addEventListener("failure",s),this.addEventListener("idle",i),e?.signal?.addEventListener("abort",a);try{yield*r}finally{this.removeEventListener("completed",o),this.removeEventListener("failure",s),this.removeEventListener("idle",i),e?.signal?.removeEventListener("abort",a),n()}}};var su=Math.pow(2,20)*4,Me=class extends ie{status;timeline;inactivityTimeout;maxReadBufferLength;maxWriteBufferLength;log;direction;maxMessageSize;readStatus;writeStatus;remoteReadStatus;remoteWriteStatus;writableNeedsDrain;readBuffer;writeBuffer;sendingData;onDrainPromise;constructor(e){super(),this.status="open",this.log=e.log,this.direction=e.direction??"outbound",this.inactivityTimeout=e.inactivityTimeout??12e4,this.maxReadBufferLength=e.maxReadBufferLength??su,this.maxWriteBufferLength=e.maxWriteBufferLength,this.maxMessageSize=e.maxMessageSize,this.readBuffer=new A,this.writeBuffer=new A,this.readStatus="readable",this.remoteReadStatus="readable",this.writeStatus="writable",this.remoteWriteStatus="writable",this.sendingData=!1,this.writableNeedsDrain=!1,this.timeline={open:Date.now()},this.processSendQueue=this.processSendQueue.bind(this);let r=()=>{this.writableNeedsDrain&&(this.log.trace("drain event received, continue sending data"),this.writableNeedsDrain=!1,this.processSendQueue()),this.onDrainPromise?.resolve()};this.addEventListener("drain",r);let n=o=>{this.onDrainPromise?.reject(o.error??new At)};this.addEventListener("close",n)}get readBufferLength(){return this.readBuffer.byteLength}get writeBufferLength(){return this.writeBuffer.byteLength}async onDrain(e){return this.writableNeedsDrain!==!0?Promise.resolve():(this.onDrainPromise==null&&(this.onDrainPromise=Promise.withResolvers()),k(this.onDrainPromise.promise,e?.signal))}async*[Symbol.asyncIterator](){if(this.readStatus!=="readable"&&this.readStatus!=="paused")return;let e=ue(),r=s=>{e.push(s.data)};this.addEventListener("message",r);let n=s=>{e.end(s.error)};this.addEventListener("close",n);let o=()=>{e.end()};this.addEventListener("remoteCloseWrite",o);try{yield*e}finally{this.removeEventListener("message",r),this.removeEventListener("close",n),this.removeEventListener("remoteCloseWrite",o)}}isReadable(){return this.status==="open"}send(e){if(this.writeStatus==="closed"||this.writeStatus==="closing")throw new xe(`Cannot write to a stream that is ${this.writeStatus}`);return this.log.trace("append %d bytes to write buffer",e.byteLength),this.writeBuffer.append(e),this.processSendQueue()}abort(e){if(!(this.status==="aborted"||this.status==="reset"||this.status==="closed")){this.log.error("abort with error - %e",e),this.status="aborted",this.readBuffer.byteLength>0&&this.readBuffer.consume(this.readBuffer.byteLength),this.writeBuffer.byteLength>0&&(this.writeBuffer.consume(this.writeBuffer.byteLength),this.safeDispatchEvent("idle")),this.writeStatus="closed",this.remoteWriteStatus="closed",this.readStatus="closed",this.remoteReadStatus="closed",this.timeline.close=Date.now();try{this.sendReset(e)}catch(r){this.log("failed to send reset to remote - %e",r)}this.dispatchEvent(new Kt(e))}}pause(){if(this.readStatus==="closed"||this.readStatus==="closing")throw new xe("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 xe("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 xe(`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 xe(`Cannot push data onto a stream that is ${this.readStatus}`);if(e.byteLength!==0){if(this.readBuffer.prepend(e),this.readStatus==="paused"||this.listenerCount("message")===0){this.checkReadBufferLength();return}setTimeout(()=>{this.dispatchReadBuffer()},0)}}onData(e){if(e.byteLength!==0){if(this.readStatus==="closing"||this.readStatus==="closed"){this.log("ignoring data - read status %s",this.readStatus);return}this.readBuffer.append(e),this.dispatchReadBuffer()}}addEventListener(...e){super.addEventListener.apply(this,e),e[0]==="message"&&this.readBuffer.byteLength>0&&queueMicrotask(()=>{this.dispatchReadBuffer()})}onRemoteReset(){this.log("remote reset"),this.status="reset",this.writeStatus="closed",this.remoteWriteStatus="closed",this.remoteReadStatus="closed",this.timeline.close=Date.now(),this.readBuffer.byteLength===0&&(this.readStatus="closed");let e=new Qt;this.dispatchEvent(new Jt(e))}onTransportClosed(e){this.log("transport closed"),this.readStatus==="readable"&&this.readBuffer.byteLength===0&&(this.log("close readable end after transport closed and read buffer is empty"),this.readStatus="closed"),this.remoteReadStatus!=="closed"&&(this.remoteReadStatus="closed"),this.remoteWriteStatus!=="closed"&&(this.remoteWriteStatus="closed"),this.writeStatus!=="closed"&&(this.writeStatus="closed"),e!=null?this.abort(e):(this.status==="open"||this.status==="closing")&&(this.timeline.close=Date.now(),this.status="closed",this.writeStatus="closed",this.remoteWriteStatus="closed",this.remoteReadStatus="closed",this.dispatchEvent(new je))}onRemoteCloseWrite(){this.remoteWriteStatus!=="closed"&&(this.log.trace("on remote close write"),this.remoteWriteStatus="closed",this.safeDispatchEvent("remoteCloseWrite"),this.writeStatus==="closed"&&this.onTransportClosed())}onRemoteCloseRead(){this.log.trace("on remote close read"),this.remoteReadStatus="closed",this.writeBuffer.byteLength>0&&(this.writeBuffer.consume(this.writeBuffer.byteLength),this.safeDispatchEvent("idle"))}processSendQueue(){if(this.writableNeedsDrain)return this.log.trace("not processing send queue as drain is required"),this.checkWriteBufferLength(),!1;if(this.writeBuffer.byteLength===0)return this.log.trace("not processing send queue as no bytes to send"),!0;if(this.sendingData)return this.log.trace("not processing send queue as already sending data"),!0;this.sendingData=!0,this.log.trace("processing send queue with %d queued bytes",this.writeBuffer.byteLength);try{let e=!0,r=this.writeBuffer.byteLength,n=0;for(;this.writeBuffer.byteLength>0;){let o=Math.min(this.maxMessageSize??this.writeBuffer.byteLength,this.writeBuffer.byteLength);if(o===0){e=!1;break}let s=this.writeBuffer.sublist(0,o),i=new A(s);this.writeBuffer.consume(s.byteLength);let a=this.sendData(s);if(e=a.canSendMore,n+=a.sentBytes,a.sentBytes!==i.byteLength&&(i.consume(a.sentBytes),this.writeBuffer.prepend(i)),!e)break}return e||(this.log.trace("sent %d/%d bytes, pausing sending because underlying stream is full, %d bytes left in the write buffer",n,r,this.writeBuffer.byteLength),this.writableNeedsDrain=!0,this.checkWriteBufferLength()),this.writeBuffer.byteLength===0&&this.safeDispatchEvent("idle"),e}finally{this.sendingData=!1}}dispatchReadBuffer(){try{if(this.listenerCount("message")===0){this.log.trace("not dispatching pause buffer as there are no listeners for the message event");return}if(this.readBuffer.byteLength===0){this.log.trace("not dispatching pause buffer as there is no data to dispatch");return}if(this.readStatus==="paused"){this.log.trace("not dispatching pause buffer we are paused");return}if(this.readStatus==="closing"||this.readStatus==="closed"){this.log("dropping %d bytes because the readable end is %s",this.readBuffer.byteLength,this.readStatus),this.readBuffer.consume(this.readBuffer.byteLength);return}let e=this.readBuffer.sublist();this.readBuffer.consume(e.byteLength),this.dispatchEvent(new se(e))}finally{this.readBuffer.byteLength===0&&this.remoteWriteStatus==="closed"&&(this.log("close readable end after dispatching read buffer and remote writable end is closed"),this.readStatus="closed"),this.checkReadBufferLength()}}checkReadBufferLength(){this.readBuffer.byteLength>this.maxReadBufferLength&&this.abort(new dt(`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 dt(`Write buffer length of ${this.writeBuffer.byteLength} exceeded limit of ${this.maxWriteBufferLength}, write status is ${this.writeStatus}`))}onMuxerNeedsDrain(){this.writableNeedsDrain=!0}onMuxerDrain(){this.safeDispatchEvent("drain")}};var Tt=class extends Me{remoteAddr;metricPrefix;metrics;constructor(e){super(e),this.metricPrefix=e.metricPrefix??"",this.metrics=e.metrics,this.remoteAddr=e.remoteAddr,this.addEventListener("close",r=>{this.metrics?.increment({[`${this.metricPrefix}end`]:!0}),r.error!=null?r.local?this.metrics?.increment({[`${this.metricPrefix}abort`]:!0}):this.metrics?.increment({[`${this.metricPrefix}reset`]:!0}):r.local?this.metrics?.increment({[`${this.metricPrefix}_local_close`]:!0}):this.metrics?.increment({[`${this.metricPrefix}_remote_close`]:!0})})}async close(e){this.status==="open"&&(this.status="closing",this.writeStatus="closing",this.remoteWriteStatus="closing",this.remoteReadStatus="closing",(this.sendingData||this.writeBuffer.byteLength>0)&&(this.log("waiting for write queue to become idle before closing writable end of stream, %d unsent bytes",this.writeBuffer.byteLength),await D(this,"idle",{...e,rejectionEvents:["close"]})),this.writableNeedsDrain&&(this.log("waiting for write queue to drain before closing writable end of stream, %d unsent bytes",this.writeBuffer.byteLength),await D(this,"drain",{...e,rejectionEvents:["close"]})),await this.sendClose(e),this.onTransportClosed())}};function Mn(t){return t==null?!1:typeof t.then=="function"&&typeof t.catch=="function"&&typeof t.finally=="function"}var Dt=class extends ie{streams;protocol;status;log;maConn;streamOptions;earlyStreams;maxEarlyStreams;metrics;constructor(e,r){super(),this.maConn=e,this.protocol=r.protocol,this.streams=[],this.earlyStreams=[],this.status="open",this.log=e.log.newScope(r.name),this.streamOptions=r.streamOptions,this.maxEarlyStreams=r.maxEarlyStreams??10,this.metrics=r.metrics;let n=i=>{try{this.onData(i.data)}catch(a){this.abort(a),this.maConn.abort(a)}};this.maConn.addEventListener("message",n);let o=()=>{this.log("underlying stream drained, signal %d streams to continue writing",this.streams.length),this.streams.forEach(i=>{i.onMuxerDrain()})};this.maConn.addEventListener("drain",o);let s=()=>{this.log("underlying stream closed with status %s and %d streams",this.status,this.streams.length),this.onTransportClosed()};this.maConn.addEventListener("close",s)}send(e){let r=this.maConn.send(e);return r===!1&&(this.log("underlying stream saturated, signal %d streams to pause writing",this.streams.length),this.streams.forEach(n=>{n.onMuxerNeedsDrain()})),r}async close(e){this.status==="closed"||this.status==="closing"||(this.status="closing",await k(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 Xt;let r=this.onCreateStream({...this.streamOptions,...e});return Mn(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 Lt(`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 Pe=class extends Me{id;protocol;constructor(e){super(e),this.id=e.id,this.protocol=e.protocol??""}async close(e){this.writeStatus==="closing"||this.writeStatus==="closed"||(this.writeStatus="closing",(this.sendingData||this.writeBuffer.byteLength>0)&&(this.log("waiting for write queue to become idle before closing writable end of stream, %d unsent bytes",this.writeBuffer.byteLength),await D(this,"idle",{...e,rejectionEvents:["close"]})),this.writableNeedsDrain&&(this.log("waiting for write queue to drain before closing writable end of stream, %d unsent bytes, sending %s",this.writeBuffer.byteLength,this.sendingData),await D(this,"drain",{...e,rejectionEvents:["close"]}),this.log("write queue drained, closing writable end of stream, %d unsent bytes, sending %s",this.writeBuffer.byteLength,this.sendingData)),await this.sendCloseWrite(e),this.writeStatus="closed",this.log("closed writable end gracefully"),this.remoteWriteStatus==="closed"&&this.onTransportClosed())}async closeRead(e){this.readStatus==="closing"||this.readStatus==="closed"||(this.readBuffer.byteLength>0&&this.readBuffer.consume(this.readBuffer.byteLength),this.readStatus="closing",await this.sendCloseRead(e),this.readStatus="closed",this.log("closed readable end gracefully"))}};function lr(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 Oe=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 fs=1.2,ls=2,hs=5e3,ds=6e4,ms=5e3,Pn=class{success;failure;next;metric;timeoutMultiplier;failureMultiplier;minTimeout;maxTimeout;constructor(e={}){let r=e.interval??ms;this.success=new Oe(r),this.failure=new Oe(r),this.next=new Oe(r),this.failureMultiplier=e.failureMultiplier??ls,this.timeoutMultiplier=e.timeoutMultiplier??fs,this.minTimeout=e.minTimeout??hs,this.maxTimeout=e.maxTimeout??ds,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=lr([e.signal,n]);return o.start=Date.now(),o.timeout=r,o}cleanUp(e){e.clear();let r=Date.now()-e.start;e.aborted?(this.failure.push(r),this.next.push(r*this.failureMultiplier),this.metric?.update({failureMovingAverage:this.failure.movingAverage,failureDeviation:this.failure.deviation,failureForecast:this.failure.forecast,failureVariance:this.failure.variance,failure:r})):(this.success.push(r),this.next.push(r),this.metric?.update({successMovingAverage:this.success.movingAverage,successDeviation:this.success.deviation,successForecast:this.success.forecast,successVariance:this.success.variance,success:r}))}};var U=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},ge=class extends Error{static name="ValidationError";name="ValidationError"},hr=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},dr=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};function Rn(t){return e=>De(e,t)}function $n(t){return e=>T(e,t)}function st(t){return new DataView(t.buffer).getUint16(t.byteOffset).toString()}function Re(t){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,typeof t=="string"?parseInt(t):t),new Uint8Array(e)}function ps(t){let e=t.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==16)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion address.`);let r=T(e[0],"base32"),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=Re(n);return Ee([r,o],r.length+o.length)}function gs(t){let e=t.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==56)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion3 address.`);let r=ae.decode(`b${e[0]}`),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=Re(n);return Ee([r,o],r.length+o.length)}function zn(t){let e=t.subarray(0,t.length-2),r=t.subarray(t.length-2),n=De(e,"base32"),o=st(r);return`${n}:${o}`}var Vn=function(t){t=t.toString().trim();let e=new Uint8Array(4);return t.split(/\./g).forEach((r,n)=>{let o=parseInt(r,10);if(isNaN(o)||o<0||o>255)throw new U("Invalid byte value in IP address");e[n]=o}),e},bs=function(t){let e=0;t=t.toString().trim();let r=t.split(":",8),n;for(n=0;n<r.length;n++){let s=Se(r[n]),i;s&&(i=Vn(r[n]),r[n]=De(i.subarray(0,2),"base16")),i!=null&&++n<8&&r.splice(n,0,De(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 U("Invalid byte value in IP address");o[e++]=s>>8&255,o[e++]=s&255}return o},ys=function(t){if(t.byteLength!==4)throw new U("IPv4 address was incorrect length");let e=[];for(let r=0;r<t.byteLength;r++)e.push(t[r]);return e.join(".")},xs=function(t){if(t.byteLength!==16)throw new U("IPv6 address was incorrect length");let e=[];for(let n=0;n<t.byteLength;n+=2){let o=t[n],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 U(`Invalid IPv6 address "${r}"`)}};function ws(t){try{let e=new URL(`http://[${t}]`);return e.hostname.substring(1,e.hostname.length-1)}catch{throw new U(`Invalid IPv6 address "${t}"`)}}var On=Object.values(xt).map(t=>t.decoder),iu=(function(){let t=On[0].or(On[1]);return On.slice(2).forEach(e=>t=t.or(e)),t})();function Es(t){return iu.decode(t)}function vs(t){return e=>t.encoder.encode(e)}function au(t){if(parseInt(t).toString()!==t)throw new ge("Value must be an integer")}function cu(t){if(t<0)throw new ge("Value must be a positive integer, or zero")}function uu(t){return e=>{if(e>t)throw new ge(`Value must be smaller than or equal to ${t}`)}}function fu(...t){return e=>{for(let r of t)r(e)}}var kt=fu(au,cu,uu(65535));var F=-1,jn=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 dr(`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)}))}},be=new jn,Xu=[{code:4,name:"ip4",size:32,valueToBytes:Vn,bytesToValue:ys,validate:t=>{if(!Se(t))throw new ge(`Invalid IPv4 address "${t}"`)}},{code:6,name:"tcp",size:16,valueToBytes:Re,bytesToValue:st,validate:kt},{code:273,name:"udp",size:16,valueToBytes:Re,bytesToValue:st,validate:kt},{code:33,name:"dccp",size:16,valueToBytes:Re,bytesToValue:st,validate:kt},{code:41,name:"ip6",size:128,valueToBytes:bs,bytesToValue:xs,stringToValue:ws,validate:t=>{if(!Ie(t))throw new ge(`Invalid IPv6 address "${t}"`)}},{code:42,name:"ip6zone",size:F},{code:43,name:"ipcidr",size:8,bytesToValue:Rn("base10"),valueToBytes:$n("base10")},{code:53,name:"dns",size:F},{code:54,name:"dns4",size:F},{code:55,name:"dns6",size:F},{code:56,name:"dnsaddr",size:F},{code:132,name:"sctp",size:16,valueToBytes:Re,bytesToValue:st,validate:kt},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:F,stringToValue:t=>decodeURIComponent(t),valueToString:t=>encodeURIComponent(t)},{code:421,name:"p2p",aliases:["ipfs"],size:F,bytesToValue:Rn("base58btc"),valueToBytes:t=>t.startsWith("Q")||t.startsWith("1")?$n("base58btc")(t):Qe.parse(t).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:zn,valueToBytes:ps},{code:445,name:"onion3",size:296,bytesToValue:zn,valueToBytes:gs},{code:446,name:"garlic64",size:F},{code:447,name:"garlic32",size:F},{code:448,name:"tls"},{code:449,name:"sni",size:F},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:F,bytesToValue:vs(sn),valueToBytes:Es},{code:480,name:"http"},{code:481,name:"http-path",size:F,stringToValue:t=>`/${decodeURIComponent(t)}`,valueToString:t=>encodeURIComponent(t.substring(1))},{code:443,name:"https"},{code:477,name:"ws"},{code:478,name:"wss"},{code:479,name:"p2p-websocket-star"},{code:277,name:"p2p-stardust"},{code:275,name:"p2p-webrtc-star"},{code:276,name:"p2p-webrtc-direct"},{code:280,name:"webrtc-direct"},{code:281,name:"webrtc"},{code:290,name:"p2p-circuit"},{code:777,name:"memory",size:F}];Xu.forEach(t=>{be.addProtocol(t)});function Cs(t){let e=[],r=0;for(;r<t.length;){let n=pe(t,r),o=be.getProtocol(n),s=P(n),i=Qu(o,t,r+s),a=0;i>0&&o.size===F&&(a=P(i));let u=s+a+i,l={code:n,name:o.name,bytes:t.subarray(r,r+u)};if(i>0){let f=r+s+a,h=t.subarray(f,f+i);l.value=o.bytesToValue?.(h)??De(h)}e.push(l),r+=u}return e}function Ls(t){let e=0,r=[];for(let n of t){if(n.bytes==null){let o=be.getProtocol(n.code),s=P(n.code),i,a=0,u=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??T(n.value),a=i.byteLength,o.size===F&&(u=P(a)));let l=new Uint8Array(s+u+a),f=0;er(n.code,l,f),f+=s,i!=null&&(o.size===F&&(er(a,l,f),f+=u),l.set(i,f)),n.bytes=l}r.push(n.bytes),e+=n.bytes.byteLength}return Ee(r,e)}function As(t){if(t.charAt(0)!=="/")throw new U('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=be.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 U(`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 U(`Component ${o} was missing value`);l.value=u.stringToValue?.(n)??n}e.push(l),n="",o="",r="protocol"}}}if(o!==""&&n!=="")throw new U("Incomplete multiaddr");return e}function Ts(t){return`/${t.flatMap(e=>{if(e.value==null)return e.name;let r=be.getProtocol(e.code);if(r==null)throw new U(`Unknown protocol code ${e.code}`);return[e.name,r.valueToString?.(e.value)??e.value]}).join("/")}`}function Qu(t,e,r){return t.size==null||t.size===0?0:t.size>0?t.size/8:pe(e,r)}var Ku=Symbol.for("nodejs.util.inspect.custom"),qn=Symbol.for("@multiformats/multiaddr");function Ju(t){if(t==null&&(t="/"),Ds(t))return t.getComponents();if(t instanceof Uint8Array)return Cs(t);if(typeof t=="string")return t=t.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),t===""&&(t="/"),As(t);if(Array.isArray(t))return t;throw new U("Must be a string, Uint8Array, Component[], or another Multiaddr")}var mr=class t{[qn]=!0;#e;#t;#r;constructor(e="/",r={}){this.#e=Ju(e),r.validate!==!1&&Yu(this)}get bytes(){return this.#r==null&&(this.#r=Ls(this.#e)),this.#r}toString(){return this.#t==null&&(this.#t=Ts(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 hr(`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 Ke(this.bytes,e.bytes)}[Ku](){return`Multiaddr(${this.toString()})`}};function Yu(t){t.getComponents().forEach(e=>{let r=be.getProtocol(e.code);e.value!=null&&r.validate?.(e.value)})}function Ds(t){return!!t?.[qn]}function Le(t){return new mr(t)}function ks(t,e,r){let n=[t.type,r??t.host];if(t.protocol!=null){let o=e??t.port;o!=null&&n.push(t.protocol,o)}return t.type==="ip6"&&t.zone!=null&&n.unshift("ip6zone",t.zone),t.cidr!=null&&n.push("ipcidr",t.cidr),Le(`/${n.join("/")}`)}function Zu(t,e){if(t==null)return[];let r=q(t);return[ks(r,e)]}function ef(t){return Ie(t)?ir("2000::/3",t):!1}function tf(t,e){if(typeof t!="string")throw new $(`invalid ip provided: ${t}`);if(typeof e=="string"&&(e=parseInt(e)),isNaN(e))throw new $(`invalid port provided: ${e}`);if(Se(t))return Le(`/ip4/${t}/tcp/${e}`);if(Ie(t))return Le(`/ip6/${t}/tcp/${e}`);throw new $(`invalid ip:port for creating a multiaddr: ${t}:${e}`)}function rf(t){return t==null||typeof t?.[Symbol.asyncIterator]!="function"?!1:typeof t.next=="function"}function nf(t){return t==null||typeof t?.[Symbol.iterator]!="function"?!1:typeof t.next=="function"}var Wn=class{readNext;haveNext;ended;nextResult;error;constructor(){this.ended=!1,this.readNext=te(),this.haveNext=te()}[Symbol.asyncIterator](){return this}async next(){if(this.nextResult==null&&await this.haveNext.promise,this.nextResult==null)throw new Error("HaveNext promise resolved but nextResult was undefined");let e=this.nextResult;return this.nextResult=void 0,this.readNext.resolve(),this.readNext=te(),e}async throw(e){return this.ended=!0,this.error=e,e!=null&&(this.haveNext.promise.catch(()=>{}),this.haveNext.reject(e)),{done:!0,value:void 0}}async return(){let e={done:!0,value:void 0};return this.ended=!0,this.nextResult=e,this.haveNext.resolve(),e}async push(e,r){await this._push(e,r)}async end(e,r){e!=null?await this.throw(e):await this._push(void 0,r)}async _push(e,r){if(e!=null&&this.ended)throw this.error??new Error("Cannot push value onto an ended pushable");for(;this.nextResult!=null;)await this.readNext.promise;e!=null?this.nextResult={done:!1,value:e}:(this.ended=!0,this.nextResult={done:!0,value:void 0}),this.haveNext.resolve(),this.haveNext=te(),await k(this.readNext.promise,r?.signal,r)}};function Fs(){return new Wn}function of(t){return t[Symbol.asyncIterator]!=null}async function sf(t,e,r){try{await Promise.all(t.map(async n=>{for await(let o of n)await e.push(o,{signal:r}),r.throwIfAborted()})),await e.end(void 0,{signal:r})}catch(n){await e.end(n,{signal:r}).catch(()=>{})}}async function*af(t){let e=new AbortController,r=Fs();sf(t,r,e.signal).catch(()=>{});try{yield*r}finally{e.abort()}}function*cf(t){for(let e of t)yield*e}function uf(...t){let e=[];for(let r of t)of(r)||e.push(r);return e.length===t.length?cf(e):af(t)}var Bs=uf;function Ns(t,...e){if(t==null)throw new Error("Empty pipeline");if(Gn(t)){let n=t;t=()=>n.source}else if(Ms(t)||Us(t)){let n=t;t=()=>n}let r=[t,...e];if(r.length>1&&Gn(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++)Gn(r[n])&&(r[n]=lf(r[n]));return ff(...r)}var ff=(...t)=>{let e;for(;t.length>0;)e=t.shift()(e);return e},Us=t=>t?.[Symbol.asyncIterator]!=null,Ms=t=>t?.[Symbol.iterator]!=null,Gn=t=>t==null?!1:t.sink!=null&&t.source!=null,lf=t=>e=>{let r=t.sink(e);if(r?.then!=null){let n=ue({objectMode:!0});r.then(()=>{n.end()},i=>{n.end(i)});let o,s=t.source;if(Us(s))o=async function*(){yield*s,n.end()};else if(Ms(s))o=function*(){yield*s,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return Bs(n,o())}return t.source};var hf=4194304,Ft=class extends Error{static name="UnwrappedError";name="UnwrappedError"},it=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},pr=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},gr=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function df(t){return typeof t?.closeRead=="function"}function mf(t){return typeof t?.close=="function"}function Hn(t){return df(t)?t.remoteWriteStatus!=="writable"&&t.readBufferLength===0:mf(t)?t.status!=="open":!1}function pf(t){return t?.addEventListener!=null&&t?.removeEventListener!=null&&t?.send!=null&&t?.push!=null&&t?.log!=null}function Ps(t,e){let r=e?.maxBufferSize??hf,n=new A,o,s=!1;if(!pf(t))throw new $("Argument should be a Stream or a Multiaddr");let i=f=>{if(n.append(f.data),n.byteLength>r){let h=n.byteLength;n.consume(n.byteLength),o?.reject(new Error(`Read buffer overflow - ${h} > ${r}`))}o?.resolve()};t.addEventListener("message",i);let a=f=>{f.error!=null?o?.reject(f.error):o?.resolve()};t.addEventListener("close",a);let u=()=>{o?.resolve()};t.addEventListener("remoteCloseWrite",u);let l={readBuffer:n,async read(f){if(s===!0)throw new Ft("Stream was unwrapped");if(Hn(t)){if(n.byteLength===0&&f?.bytes==null)return null;if(f?.bytes!=null&&n.byteLength<f.bytes)throw t.log.error("closed after reading %d/%d bytes",n.byteLength,f.bytes),new Ce(`Unexpected EOF - stream closed after reading ${n.byteLength}/${f.bytes} bytes`)}let h=f?.bytes??1;for(o=Promise.withResolvers();;){if(n.byteLength>=h){o.resolve();break}if(await k(o.promise,f?.signal),Hn(t)){if(n.byteLength===0&&f?.bytes==null)return null;break}o=Promise.withResolvers()}let p=f?.bytes??n.byteLength;if(n.byteLength<p){if(Hn(t))throw t.log.error("closed while reading %d/%d bytes",n.byteLength,p),new Ce(`Unexpected EOF - stream closed while reading ${n.byteLength}/${p} bytes`);return l.read(f)}let y=n.sublist(0,p);return n.consume(p),y},async write(f,h){if(s===!0)throw new Ft("Stream was unwrapped");t.send(f)||await D(t,"drain",{signal:h?.signal,rejectionEvents:["close"]})},unwrap(){return s||(s=!0,t.removeEventListener("message",i),t.removeEventListener("close",a),t.removeEventListener("remoteCloseWrite",u),n.byteLength>0&&(t.log("stream unwrapped with %d unread bytes",n.byteLength),t.push(n))),t}};return l}function Os(t,e={}){let r=Ps(t,e);e.maxDataLength!=null&&e.maxLengthLength==null&&(e.maxLengthLength=P(e.maxDataLength));let n=e?.lengthDecoder??pe,o=e?.lengthEncoder??tr;return{async read(i){let a=-1,u=new A;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 it("Invalid message length");if(e?.maxLengthLength!=null&&u.byteLength>e.maxLengthLength)throw new gr(`Message length length too long - ${u.byteLength} > ${e.maxLengthLength}`);if(a>-1)break}if(e?.maxDataLength!=null&&a>e.maxDataLength)throw new pr(`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 Ce(`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 Ce(`Unexpected EOF - read ${l.byteLength}/${a} bytes before the stream closed`);return l},async write(i,a){await r.write(new A(o(i.byteLength),i),a)},async writeV(i,a){let u=new A(...i.flatMap(l=>[o(l.byteLength),l]));await r.write(u,a)},unwrap(){return r.unwrap()}}}function gf(t,e){let r=Os(t,e),n={read:async(o,s)=>{let i=await r.read(s);return o.decode(i)},write:async(o,s,i)=>{await r.write(s.encode(o),i)},writeV:async(o,s,i)=>{await r.writeV(o.map(a=>s.encode(a)),i)},pb:o=>({read:async s=>n.read(o,s),write:async(s,i)=>n.write(s,o,i),writeV:async(s,i)=>n.writeV(s,o,i),unwrap:()=>n}),unwrap:()=>r.unwrap()};return n}async function Xn(t,e){let r=t.log.newScope("echo"),n=Date.now(),o=0;try{for await(let s of t)o+=s.byteLength,t.send(s)||(t.pause(),await D(t,"drain",{rejectionEvents:["close"],...e}),t.resume());r("echoed %d bytes in %dms",o,Date.now()-n),await t.close(e)}catch(s){t.abort(s)}}function bf(t){return t?.addEventListener!=null}function Rs(t){let e=ue(),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([D(t,"drain",{rejectionEvents:["close"]})])),l===!0))break}await t.close()}}}function yf(...t){let e=t.map(r=>bf(r)?Rs(r):r);return Ns(...e)}var xf=1024*1024*4,wf=1024*1024*4,Qn=class{buffer;maxBufferSize;lengthDecoder;maxDataLength;encodingLength;constructor(e={}){this.buffer=new A,this.maxBufferSize=e.maxBufferSize??xf,this.maxDataLength=e.maxDataLength??wf,this.lengthDecoder=e.lengthDecoder??pe,this.encodingLength=e.encodingLength??P}*decode(e){if(this.buffer.append(e),this.buffer.byteLength>this.maxBufferSize)throw new $(`Buffer length limit exceeded - ${this.buffer.byteLength}/${this.maxBufferSize}`);for(;;){let r;try{r=this.lengthDecoder(this.buffer)}catch(s){if(s instanceof RangeError)break;throw s}if(r<0||r>this.maxDataLength)throw new it("Invalid message length");let n=this.encodingLength(r),o=n+r;if(this.buffer.byteLength>=o){let s=this.buffer.sublist(n,o);this.buffer.consume(o),s.byteLength>0&&(yield s)}else break}}};function Ef(t){return!!(t.startsWith("169.254.")||t.toLowerCase().startsWith("fe80"))}var vf=["Object","RegExp","Date","Error","Map","Set","WeakMap","WeakSet","ArrayBuffer","SharedArrayBuffer","DataView","Promise","URL","HTMLElement","Int8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array"];function Kn(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=_f(t);return r||"Object"}function _f(t){let e=Object.prototype.toString.call(t).slice(8,-1);if(vf.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 Bt=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",Sf=new TextEncoder;function br(t){return Bt&&globalThis.Buffer.isBuffer(t)}function Nt(t){return t instanceof Uint8Array?br(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):t:Uint8Array.from(t)}var If=24,Cf=200,yr=Bt?t=>t.length>=If?globalThis.Buffer.from(t):$s(t):t=>t.length>=Cf?Sf.encode(t):$s(t),fe=t=>Uint8Array.from(t),zs=Bt?(t,e,r)=>br(t)?new Uint8Array(t.subarray(e,r)):t.slice(e,r):(t,e,r)=>t.slice(e,r),Vs=Bt?(t,e)=>(t=t.map(r=>r instanceof Uint8Array?r:globalThis.Buffer.from(r)),Nt(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},js=Bt?t=>globalThis.Buffer.allocUnsafe(t):t=>new Uint8Array(t);function xr(t,e){if(br(t)&&br(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 $s(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 Lf=256,Ut=class{constructor(e=Lf){this.chunkSize=e,this.cursor=0,this.maxCursor=-1,this.chunks=[],this._initReuseChunk=null}reset(){this.cursor=0,this.maxCursor=-1,this.chunks.length&&(this.chunks=[]),this._initReuseChunk!==null&&(this.chunks.push(this._initReuseChunk),this.maxCursor=this._initReuseChunk.length-1)}push(e){let r=this.chunks[this.chunks.length-1];if(this.cursor+e.length<=this.maxCursor+1){let o=r.length-(this.maxCursor-this.cursor)-1;r.set(e,o)}else{if(r){let o=r.length-(this.maxCursor-this.cursor)-1;o<r.length&&(this.chunks[this.chunks.length-1]=r.subarray(0,o),this.maxCursor=this.cursor-1)}e.length<64&&e.length<this.chunkSize?(r=js(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=zs(n,0,this.cursor)}else r=Vs(this.chunks,this.cursor);return e&&this.reset(),r}},wr=class{constructor(e){this.dest=e,this.cursor=0,this.chunks=[e]}reset(){this.cursor=0}push(e){if(this.cursor+e.length>this.dest.length)throw new Error("write out of bounds, destination buffer is too small");this.dest.set(e,this.cursor),this.cursor+=e.length}toBytes(e=!1){let r=this.dest.subarray(0,this.cursor);return e&&this.reset(),r}};var g="CBOR decode error:",Er="CBOR encode error:",Mt=[];Mt[23]=1;Mt[24]=2;Mt[25]=3;Mt[26]=5;Mt[27]=9;function ye(t,e,r){if(t.length-e<r)throw new Error(`${g} not enough data for type`)}var B=[24,256,65536,4294967296,BigInt("18446744073709551616")];function W(t,e,r){ye(t,e,1);let n=t[e];if(r.strict===!0&&n<B[0])throw new Error(`${g} integer encoded in more bytes than necessary (strict decode)`);return n}function G(t,e,r){ye(t,e,2);let n=t[e]<<8|t[e+1];if(r.strict===!0&&n<B[1])throw new Error(`${g} integer encoded in more bytes than necessary (strict decode)`);return n}function H(t,e,r){ye(t,e,4);let n=t[e]*16777216+(t[e+1]<<16)+(t[e+2]<<8)+t[e+3];if(r.strict===!0&&n<B[2])throw new Error(`${g} integer encoded in more bytes than necessary (strict decode)`);return n}function X(t,e,r){ye(t,e,8);let n=t[e]*16777216+(t[e+1]<<16)+(t[e+2]<<8)+t[e+3],o=t[e+4]*16777216+(t[e+5]<<16)+(t[e+6]<<8)+t[e+7],s=(BigInt(n)<<BigInt(32))+BigInt(o);if(r.strict===!0&&s<B[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 qs(t,e,r,n){return new m(c.uint,W(t,e+1,n),2)}function Ws(t,e,r,n){return new m(c.uint,G(t,e+1,n),3)}function Gs(t,e,r,n){return new m(c.uint,H(t,e+1,n),5)}function Hs(t,e,r,n){return new m(c.uint,X(t,e+1,n),9)}function K(t,e){return S(t,0,e.value)}function S(t,e,r){if(r<B[0]){let n=Number(r);t.push([e|n])}else if(r<B[1]){let n=Number(r);t.push([e|24,n])}else if(r<B[2]){let n=Number(r);t.push([e|25,n>>>8,n&255])}else if(r<B[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<B[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`)}}K.encodedSize=function(e){return S.encodedSize(e.value)};S.encodedSize=function(e){return e<B[0]?1:e<B[1]?2:e<B[2]?3:e<B[3]?5:9};K.compareTokens=function(e,r){return e.value<r.value?-1:e.value>r.value?1:0};function Xs(t,e,r,n){return new m(c.negint,-1-W(t,e+1,n),2)}function Qs(t,e,r,n){return new m(c.negint,-1-G(t,e+1,n),3)}function Ks(t,e,r,n){return new m(c.negint,-1-H(t,e+1,n),5)}var Jn=BigInt(-1),Js=BigInt(1);function Ys(t,e,r,n){let o=X(t,e+1,n);if(typeof o!="bigint"){let s=-1-o;if(s>=Number.MIN_SAFE_INTEGER)return new 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,Jn-BigInt(o),9)}function vr(t,e){let r=e.value,n=typeof r=="bigint"?r*Jn-Js:r*-1-1;S(t,e.type.majorEncoded,n)}vr.encodedSize=function(e){let r=e.value,n=typeof r=="bigint"?r*Jn-Js:r*-1-1;return n<B[0]?1:n<B[1]?2:n<B[2]?3:n<B[3]?5:9};vr.compareTokens=function(e,r){return e.value<r.value?1:e.value>r.value?-1:0};function Pt(t,e,r,n){ye(t,e,r+n);let o=t.slice(e+r,e+r+n);return new m(c.bytes,o,r+n)}function Zs(t,e,r,n){return Pt(t,e,1,r)}function ei(t,e,r,n){return Pt(t,e,2,W(t,e+1,n))}function ti(t,e,r,n){return Pt(t,e,3,G(t,e+1,n))}function ri(t,e,r,n){return Pt(t,e,5,H(t,e+1,n))}function ni(t,e,r,n){let o=X(t,e+1,n);if(typeof o=="bigint")throw new Error(`${g} 64-bit integer bytes lengths not supported`);return Pt(t,e,9,o)}function _r(t){return t.encodedBytes===void 0&&(t.encodedBytes=c.equals(t.type,c.string)?yr(t.value):t.value),t.encodedBytes}function at(t,e){let r=_r(e);S(t,e.type.majorEncoded,r.length),t.push(r)}at.encodedSize=function(e){let r=_r(e);return S.encodedSize(r.length)+r.length};at.compareTokens=function(e,r){return Tf(_r(e),_r(r))};function Tf(t,e){return t.length<e.length?-1:t.length>e.length?1:xr(t,e)}var oi=new TextDecoder,kf=32;function Ff(t,e,r){if(r-e<kf){let o="";for(let s=e;s<r;s++){let i=t[s];if(i&128)return oi.decode(t.subarray(e,r));o+=String.fromCharCode(i)}return o}return oi.decode(t.subarray(e,r))}function Ot(t,e,r,n,o){let s=r+n;ye(t,e,s);let i=new m(c.string,Ff(t,e+r,e+s),s);return o.retainStringBytes===!0&&(i.byteValue=t.slice(e+r,e+s)),i}function si(t,e,r,n){return Ot(t,e,1,r,n)}function ii(t,e,r,n){return Ot(t,e,2,W(t,e+1,n),n)}function ai(t,e,r,n){return Ot(t,e,3,G(t,e+1,n),n)}function ci(t,e,r,n){return Ot(t,e,5,H(t,e+1,n),n)}function ui(t,e,r,n){let o=X(t,e+1,n);if(typeof o=="bigint")throw new Error(`${g} 64-bit integer string lengths not supported`);return Ot(t,e,9,o,n)}var fi=at;function ct(t,e,r,n){return new m(c.array,n,r)}function li(t,e,r,n){return ct(t,e,1,r)}function hi(t,e,r,n){return ct(t,e,2,W(t,e+1,n))}function di(t,e,r,n){return ct(t,e,3,G(t,e+1,n))}function mi(t,e,r,n){return ct(t,e,5,H(t,e+1,n))}function pi(t,e,r,n){let o=X(t,e+1,n);if(typeof o=="bigint")throw new Error(`${g} 64-bit integer array lengths not supported`);return ct(t,e,9,o)}function gi(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${g} indefinite length items not allowed`);return ct(t,e,1,1/0)}function Sr(t,e){S(t,c.array.majorEncoded,e.value)}Sr.compareTokens=K.compareTokens;Sr.encodedSize=function(e){return S.encodedSize(e.value)};function ut(t,e,r,n){return new m(c.map,n,r)}function bi(t,e,r,n){return ut(t,e,1,r)}function yi(t,e,r,n){return ut(t,e,2,W(t,e+1,n))}function xi(t,e,r,n){return ut(t,e,3,G(t,e+1,n))}function wi(t,e,r,n){return ut(t,e,5,H(t,e+1,n))}function Ei(t,e,r,n){let o=X(t,e+1,n);if(typeof o=="bigint")throw new Error(`${g} 64-bit integer map lengths not supported`);return ut(t,e,9,o)}function vi(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${g} indefinite length items not allowed`);return ut(t,e,1,1/0)}function Ir(t,e){S(t,c.map.majorEncoded,e.value)}Ir.compareTokens=K.compareTokens;Ir.encodedSize=function(e){return S.encodedSize(e.value)};function _i(t,e,r,n){return new m(c.tag,r,1)}function Si(t,e,r,n){return new m(c.tag,W(t,e+1,n),2)}function Ii(t,e,r,n){return new m(c.tag,G(t,e+1,n),3)}function Ci(t,e,r,n){return new m(c.tag,H(t,e+1,n),5)}function Li(t,e,r,n){return new m(c.tag,X(t,e+1,n),9)}function Cr(t,e){S(t,c.tag.majorEncoded,e.value)}Cr.compareTokens=K.compareTokens;Cr.encodedSize=function(e){return S.encodedSize(e.value)};var Yn=20,Zn=21,eo=22,to=23;function Ai(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 Ti(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 ro(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 Di(t,e,r,n){return ro(no(t,e+1),3,n)}function ki(t,e,r,n){return ro(oo(t,e+1),5,n)}function Fi(t,e,r,n){return ro(Mi(t,e+1),9,n)}function Rt(t,e,r){let n=e.value;if(n===!1)t.push([c.float.majorEncoded|Yn]);else if(n===!0)t.push([c.float.majorEncoded|Zn]);else if(n===null)t.push([c.float.majorEncoded|eo]);else if(n===void 0)t.push([c.float.majorEncoded|to]);else{let o,s=!1;(!r||r.float64!==!0)&&(Ni(n),o=no(ne,1),n===o||Number.isNaN(n)?(ne[0]=249,t.push(ne.slice(0,3)),s=!0):(Ui(n),o=oo(ne,1),n===o&&(ne[0]=250,t.push(ne.slice(0,5)),s=!0))),s||(Pf(n),o=Mi(ne,1),ne[0]=251,t.push(ne.slice(0,9)))}}Rt.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){Ni(n);let o=no(ne,1);if(n===o||Number.isNaN(n))return 3;if(Ui(n),o=oo(ne,1),n===o)return 5}return 9};var Bi=new ArrayBuffer(9),J=new DataView(Bi,1),ne=new Uint8Array(Bi,0);function Ni(t){if(t===1/0)J.setUint16(0,31744,!1);else if(t===-1/0)J.setUint16(0,64512,!1);else if(Number.isNaN(t))J.setUint16(0,32256,!1);else{J.setFloat32(0,t);let e=J.getUint32(0),r=(e&2139095040)>>23,n=e&8388607;if(r===255)J.setUint16(0,31744,!1);else if(r===0)J.setUint16(0,(t&2147483648)>>16|n>>13,!1);else{let o=r-127;o<-24?J.setUint16(0,0):o<-14?J.setUint16(0,(e&2147483648)>>16|1<<24+o,!1):J.setUint16(0,(e&2147483648)>>16|o+15<<10|n>>13,!1)}}}function no(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 Ui(t){J.setFloat32(0,t,!1)}function oo(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 Pf(t){J.setFloat64(0,t,!1)}function Mi(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)}Rt.compareTokens=K.compareTokens;function E(t,e,r){throw new Error(`${g} encountered invalid minor (${r}) for major ${t[e]>>>5}`)}function Lr(t){return()=>{throw new Error(`${g} ${t}`)}}var d=[];for(let t=0;t<=23;t++)d[t]=E;d[24]=qs;d[25]=Ws;d[26]=Gs;d[27]=Hs;d[28]=E;d[29]=E;d[30]=E;d[31]=E;for(let t=32;t<=55;t++)d[t]=E;d[56]=Xs;d[57]=Qs;d[58]=Ks;d[59]=Ys;d[60]=E;d[61]=E;d[62]=E;d[63]=E;for(let t=64;t<=87;t++)d[t]=Zs;d[88]=ei;d[89]=ti;d[90]=ri;d[91]=ni;d[92]=E;d[93]=E;d[94]=E;d[95]=Lr("indefinite length bytes/strings are not supported");for(let t=96;t<=119;t++)d[t]=si;d[120]=ii;d[121]=ai;d[122]=ci;d[123]=ui;d[124]=E;d[125]=E;d[126]=E;d[127]=Lr("indefinite length bytes/strings are not supported");for(let t=128;t<=151;t++)d[t]=li;d[152]=hi;d[153]=di;d[154]=mi;d[155]=pi;d[156]=E;d[157]=E;d[158]=E;d[159]=gi;for(let t=160;t<=183;t++)d[t]=bi;d[184]=yi;d[185]=xi;d[186]=wi;d[187]=Ei;d[188]=E;d[189]=E;d[190]=E;d[191]=vi;for(let t=192;t<=215;t++)d[t]=_i;d[216]=Si;d[217]=Ii;d[218]=Ci;d[219]=Li;d[220]=E;d[221]=E;d[222]=E;d[223]=E;for(let t=224;t<=243;t++)d[t]=Lr("simple values are not supported");d[244]=E;d[245]=E;d[246]=E;d[247]=Ai;d[248]=Lr("simple values are not supported");d[249]=Di;d[250]=ki;d[251]=Fi;d[252]=E;d[253]=E;d[254]=E;d[255]=Ti;var oe=[];for(let t=0;t<24;t++)oe[t]=new m(c.uint,t,1);for(let t=-1;t>=-24;t--)oe[31-t]=new m(c.negint,t,1);oe[64]=new m(c.bytes,new Uint8Array(0),1);oe[96]=new m(c.string,"",1);oe[128]=new m(c.array,0,1);oe[160]=new m(c.map,0,1);oe[244]=new m(c.false,!1,1);oe[245]=new m(c.true,!0,1);oe[246]=new m(c.null,null,1);function so(t){switch(t.type){case c.false:return fe([244]);case c.true:return fe([245]);case c.null:return fe([246]);case c.bytes:return t.value.length?void 0:fe([64]);case c.string:return t.value===""?fe([96]):void 0;case c.array:return t.value===0?fe([128]):void 0;case c.map:return t.value===0?fe([160]):void 0;case c.uint:return t.value<24?fe([Number(t.value)]):void 0;case c.negint:if(t.value>=-24)return fe([31-Number(t.value)])}}var Rf={float64:!1,mapSorter:Vf,quickEncodeToken:so},zi=Object.freeze({float64:!0,mapSorter:jf,quickEncodeToken:so});function $f(){let t=[];return t[c.uint.major]=K,t[c.negint.major]=vr,t[c.bytes.major]=at,t[c.string.major]=fi,t[c.array.major]=Sr,t[c.map.major]=Ir,t[c.tag.major]=Cr,t[c.float.major]=Rt,t}var ft=$f(),Ar=new Ut,zt=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(`${Er} object contains circular references`);return new t(r,e)}},Ae={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)},le={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?Ae.true:Ae.false},null(t,e,r,n){return Ae.null},undefined(t,e,r,n){return Ae.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?[Ae.emptyArray,new m(c.break)]:Ae.emptyArray;n=zt.createCheck(n,t);let o=[],s=0;for(let i of t)o[s++]=Tr(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=zt.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++]=[Tr(f,r,n),Tr(h,r,n)])}l<i&&(a.length=l)}return a?.length?(zf(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?[Ae.emptyMap,new m(c.break)]:Ae.emptyMap}};le.Map=le.Object;le.Buffer=le.Uint8Array;for(let t of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))le[`${t}Array`]=le.DataView;function Tr(t,e={},r){let n=Kn(t),o=e&&e.typeEncoders&&e.typeEncoders[n]||le[n];if(typeof o=="function"){let i=o(t,n,e,r);if(i!=null)return i}let s=le[n];if(!s)throw new Error(`${Er} unsupported type: ${n}`);return s(t,n,e,r)}function zf(t,e){e.mapSorter&&t.sort(e.mapSorter)}function Vf(t,e){let r=Array.isArray(t[0])?t[0][0]:t[0],n=Array.isArray(e[0])?e[0][0]:e[0];if(r.type!==n.type)return r.type.compare(n.type);let o=r.type.major,s=ft[o].compareTokens(r,n);return s===0&&console.warn("WARNING: complex key types used, CBOR key sorting guarantees are gone"),s}function jf(t,e){if(t[0]instanceof m&&e[0]instanceof m){let r=t[0],n=e[0];return r._keyBytes||(r._keyBytes=Pi(r.value)),n._keyBytes||(n._keyBytes=Pi(n.value)),xr(r._keyBytes,n._keyBytes)}throw new Error("rfc8949MapSorter: complex key types are not supported yet")}function Pi(t){return ji(t,ft,zi)}function $t(t,e,r,n){if(Array.isArray(e))for(let o of e)$t(t,o,r,n);else r[e.type.major](t,e,n)}var Oi=c.uint.majorEncoded,Ri=c.negint.majorEncoded,qf=c.bytes.majorEncoded,Wf=c.string.majorEncoded,$i=c.array.majorEncoded,Gf=c.float.majorEncoded|Yn,Hf=c.float.majorEncoded|Zn,Xf=c.float.majorEncoded|eo,Qf=c.float.majorEncoded|to,Kf=BigInt(-1),Jf=BigInt(1);function Yf(t){return t.addBreakTokens!==!0}function Vi(t,e,r,n){let o=Kn(e),s=r.typeEncoders&&r.typeEncoders[o];if(s){let i=s(e,o,r,n);if(i!=null){$t(t,i,ft,r);return}}switch(o){case"null":t.push([Xf]);return;case"undefined":t.push([Qf]);return;case"boolean":t.push([e?Hf:Gf]);return;case"number":!Number.isInteger(e)||!Number.isSafeInteger(e)?Rt(t,new m(c.float,e),r):e>=0?S(t,Oi,e):S(t,Ri,e*-1-1);return;case"bigint":e>=BigInt(0)?S(t,Oi,e):S(t,Ri,e*Kf-Jf);return;case"string":{let i=yr(e);S(t,Wf,i.length),t.push(i);return}case"Uint8Array":S(t,qf,e.length),t.push(e);return;case"Array":if(!e.length){t.push([$i]);return}n=zt.createCheck(n,e),S(t,$i,e.length);for(let i of e)Vi(t,i,r,n);return;case"Object":case"Map":{let i=le.Object(e,o,r,n);$t(t,i,ft,r)}return;default:{let i=le[o];if(!i)throw new Error(`${Er} unsupported type: ${o}`);let a=i(e,o,r,n);$t(t,a,ft,r)}}}function ji(t,e,r,n){let o=n instanceof Uint8Array,s=o?new wr(n):Ar,i=Tr(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 Ut(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():Nt(s.chunks[0])}}return s.reset(),$t(s,i,e,r),s.toBytes(!0)}function io(t,e){return e=Object.assign({},Rf,e),Yf(e)?(Ar.reset(),Vi(Ar,t,e,void 0),Ar.toBytes(!0)):ji(t,ft,e)}var Zf={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},Dr=class{constructor(e,r={}){this._pos=0,this.data=e,this.options=r}pos(){return this._pos}done(){return this._pos>=this.data.length}next(){let e=this.data[this._pos],r=oe[e];if(r===void 0){let n=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}},Vt=Symbol.for("DONE"),kr=Symbol.for("BREAK");function el(t,e,r){let n=[];for(let o=0;o<t.value;o++){let s=lt(e,r);if(s===kr){if(t.value===1/0)break;throw new Error(`${g} got unexpected break to lengthed array`)}if(s===Vt)throw new Error(`${g} found array but not enough entries (got ${o}, expected ${t.value})`);n[o]=s}return n}function tl(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=lt(e,r);if(u===kr){if(t.value===1/0)break;throw new Error(`${g} got unexpected break to lengthed map`)}if(u===Vt)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=lt(e,r);if(l===Vt)throw new Error(`${g} found map but not enough entries (got ${a} [no value], expected ${t.value})`);n?i.set(u,l):s[u]=l}return n?i:s}function lt(t,e){if(t.done())return Vt;let r=t.next();if(c.equals(r.type,c.break))return kr;if(r.type.terminal)return r.value;if(c.equals(r.type,c.array))return el(r,t,e);if(c.equals(r.type,c.map))return tl(r,t,e);if(c.equals(r.type,c.tag)){if(e.tags&&typeof e.tags[r.value]=="function"){let n=lt(t,e);return e.tags[r.value](n)}throw new Error(`${g} tag not supported (${r.value})`)}throw new Error("unsupported")}function qi(t,e){if(!(t instanceof Uint8Array))throw new Error(`${g} data to decode must be a Uint8Array`);e=Object.assign({},Zf,e);let r=Nt(t),n=e.tokenizer||new Dr(r,e),o=lt(n,e);if(o===Vt)throw new Error(`${g} did not find any content to decode`);if(o===kr)throw new Error(`${g} got unexpected break`);return[o,t.subarray(n.pos())]}function ao(t,e){let[r,n]=qi(t,e);if(n.length>0)throw new Error(`${g} too many terminals, data makes no sense`);return r}var Fr=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},ht=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},Br=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"},jt=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};function Nr(t){return t[Symbol.asyncIterator]!=null}function Wi(t,e){if(t.byteLength>e)throw new ht("Message length too long")}var Mr=t=>{let e=P(t),r=Z(e);return tr(t,r),Mr.bytes=e,r};Mr.bytes=0;function Pr(t,e){e=e??{};let r=e.lengthEncoder??Mr,n=e?.maxDataLength??4194304;function*o(s){Wi(s,n);let i=r(s.byteLength);i instanceof Uint8Array?yield i:yield*i,s instanceof Uint8Array?yield s:yield*s}return Nr(t)?(async function*(){for await(let s of t)yield*o(s)})():(function*(){for(let s of t)yield*o(s)})()}Pr.single=(t,e)=>{e=e??{};let r=e.lengthEncoder??Mr,n=e?.maxDataLength??4194304;return Wi(t,n),new A(r(t.byteLength),t)};var ze;(function(t){t[t.LENGTH=0]="LENGTH",t[t.DATA=1]="DATA"})(ze||(ze={}));var co=t=>{let e=pe(t);return co.bytes=P(e),e};co.bytes=0;function qt(t,e){let r=new A,n=ze.LENGTH,o=-1,s=e?.lengthDecoder??co,i=e?.maxLengthLength??8,a=e?.maxDataLength??4194304;function*u(){for(;r.byteLength>0;){if(n===ze.LENGTH)try{if(o=s(r),o<0)throw new Fr("Invalid message length");if(o>a)throw new ht("Message length too long");let l=s.bytes;r.consume(l),e?.onLength!=null&&e.onLength(o),n=ze.DATA}catch(l){if(l instanceof RangeError){if(r.byteLength>i)throw new Br("Message length length too long");break}throw l}if(n===ze.DATA){if(r.byteLength<o)break;let l=r.sublist(0,o);r.consume(o),e?.onData!=null&&e.onData(l),yield l,n=ze.LENGTH}}}return Nr(t)?(async function*(){for await(let l of t)r.append(l),yield*u();if(r.byteLength>0)throw new jt("Unexpected end of input")})():(function*(){for(let l of t)r.append(l),yield*u();if(r.byteLength>0)throw new jt("Unexpected end of input")})()}qt.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 qt(n,{...e??{},onLength:s=>{r=s}})};var uo=class extends Pe{sendMessage;dataQueue;encoding;constructor(e){super(e),this.sendMessage=e.sendMessage,this.encoding=e.encoding,this.dataQueue=new re({concurrency:1}),this.direction==="outbound"&&this.sendMessage({id:this.id,type:"create",protocol:this.protocol})}sendData(e){let r=this.sendMessage({id:this.id,type:"data",chunk:e.subarray()});return{sentBytes:e.byteLength,canSendMore:r}}sendReset(){this.sendMessage({id:this.id,type:"reset"})}async sendCloseWrite(e){this.sendMessage({id:this.id,type:"closeWrite"}),e?.signal?.throwIfAborted()}async sendCloseRead(e){this.sendMessage({id:this.id,type:"closeRead"}),e?.signal?.throwIfAborted()}sendPause(){this.sendMessage({id:this.id,type:"pause"})}sendResume(){this.sendMessage({id:this.id,type:"resume"})}onRemotePaused(){this.dataQueue.pause()}onRemoteResumed(){this.dataQueue.resume()}},Gi=30,fo=class extends Dt{input;maxInputQueueSize;encoding;maxMessageSize;nextStreamId;constructor(e,r){super(e,{...r,protocol:"/mock-muxer/1.0.0",name:"mock-muxer"}),this.maxInputQueueSize=r.maxInputQueueSize??1024*1024*10,this.maxMessageSize=(r.maxMessageSize??1024*1024*4)+Gi,this.encoding=r.encoding??"base64",this.input=ue(),this.sendMessage=this.sendMessage.bind(this),this.nextStreamId=this.maConn.direction==="outbound"?0:1,Promise.resolve().then(async()=>{for await(let n of qt(this.input,{maxDataLength:this.maxMessageSize}))this.onMessage(ao(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=io(e),n=Pr.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 uo({...this.streamOptions,...n,id:e,direction:r,log:this.log.newScope(`stream:${r}:${e}`),sendMessage:this.sendMessage,encoding:this.encoding,maxMessageSize:this.maxMessageSize-Gi,protocol:""})}},lo=class{protocol="/mock-muxer/1.0.0";init;constructor(e){this.init=e}createStreamMuxer(e){return new fo(e,{...this.init})}};function Or(t={}){return new lo(t)}function sl(t,e){if(typeof t=="string")return il(t);if(typeof t=="number")return ul(t,e);throw Error(`Value provided to ms() must be a string or number. value=${JSON.stringify(t)}`)}var Rr=sl;function il(t){if(typeof t!="string"||t.length===0||t.length>100)throw Error(`Value provided to ms.parse() must be a string with length between 1 and 99. value=${JSON.stringify(t)}`);let e=/^(?<value>-?\d*\.?\d+) *(?<unit>milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|months?|mo|years?|yrs?|y)?$/i.exec(t);if(!e?.groups)return NaN;let{value:r,unit:n="ms"}=e.groups,o=parseFloat(r),s=n.toLowerCase();switch(s){case"years":case"year":case"yrs":case"yr":case"y":return o*315576e5;case"months":case"month":case"mo":return o*26298e5;case"weeks":case"week":case"w":return o*6048e5;case"days":case"day":case"d":return o*864e5;case"hours":case"hour":case"hrs":case"hr":case"h":return o*36e5;case"minutes":case"minute":case"mins":case"min":case"m":return o*6e4;case"seconds":case"second":case"secs":case"sec":case"s":return o*1e3;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return o;default:throw Error(`Unknown unit "${s}" provided to ms.parse(). value=${JSON.stringify(t)}`)}}function al(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 cl(t){let e=Math.abs(t);return e>=315576e5?Ve(t,e,315576e5,"year"):e>=26298e5?Ve(t,e,26298e5,"month"):e>=6048e5?Ve(t,e,6048e5,"week"):e>=864e5?Ve(t,e,864e5,"day"):e>=36e5?Ve(t,e,36e5,"hour"):e>=6e4?Ve(t,e,6e4,"minute"):e>=1e3?Ve(t,e,1e3,"second"):`${t} ms`}function ul(t,e){if(typeof t!="number"||!Number.isFinite(t))throw Error("Value provided to ms.format() must be of type number.");return e?.long?cl(t):al(t)}function Ve(t,e,r,n){let o=e>=r*1.5;return`${Math.round(t/r)} ${n}${o?"s":""}`}function ho(t){r.debug=r,r.default=r,r.coerce=u,r.disable=s,r.enable=o,r.enabled=i,r.humanize=Rr,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,y=null,x,_;function b(...w){if(!b.enabled)return;let I=b,C=Number(new Date),O=C-(p||C);I.diff=O,I.prev=p,I.curr=C,p=C,w[0]=r.coerce(w[0]),typeof w[0]!="string"&&w.unshift("%O");let N=0;w[0]=w[0].replace(/%([a-zA-Z%])/g,(R,Y)=>{if(R==="%%")return"%";N++;let Te=r.formatters[Y];if(typeof Te=="function"){let na=w[N];R=Te.call(I,na),w.splice(N,1),N--}return R}),r.formatArgs.call(I,w),h?.onLog!=null&&h.onLog(...w),(I.log||r.log).apply(I,w)}return b.namespace=f,b.useColors=r.useColors(),b.color=r.selectColor(f),b.extend=n,b.destroy=r.destroy,Object.defineProperty(b,"enabled",{enumerable:!0,configurable:!1,get:()=>y!==null?y:(x!==r.namespaces&&(x=r.namespaces,_=r.enabled(f)),_),set:w=>{y=w}}),typeof r.init=="function"&&r.init(b),b}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,]+/),y=p.length;for(h=0;h<y;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 $r=gl(),fl=["#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 ll(){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 hl(t){if(t[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+t[0]+(this.useColors?"%c ":" ")+"+"+Rr(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 dl=console.debug??console.log??(()=>{});function ml(t){try{t?$r?.setItem("debug",t):$r?.removeItem("debug")}catch{}}function pl(){let t;try{t=$r?.getItem("debug")}catch{}return!t&&typeof globalThis.process<"u"&&"env"in globalThis.process&&(t=globalThis.process.env.DEBUG),t}function gl(){try{return localStorage}catch{}}function bl(t){t.j=function(e){try{return JSON.stringify(e)}catch(r){return"[UnexpectedJSONParseError]: "+r.message}}}var Hi=ho({formatArgs:hl,save:ml,load:pl,useColors:ll,setupFormatters:bl,colors:fl,storage:$r,log:dl});var z=Hi;z.formatters.b=t=>t==null?"undefined":Q.baseEncode(t);z.formatters.t=t=>t==null?"undefined":ae.baseEncode(t);z.formatters.m=t=>t==null?"undefined":on.baseEncode(t);z.formatters.p=t=>t==null?"undefined":t.toString();z.formatters.c=t=>t==null?"undefined":t.toString();z.formatters.k=t=>t==null?"undefined":t.toString();z.formatters.a=t=>t==null?"undefined":t.toString();function Xi(t,e=""){let r=Qi(t.message),n=Qi(t.stack);return r!=null&&n!=null?n.includes(r)?`${n.split(`
2
+ "use strict";var Libp2PUtils=(()=>{var ia=Object.create;var Kt=Object.defineProperty;var aa=Object.getOwnPropertyDescriptor;var ca=Object.getOwnPropertyNames;var ua=Object.getPrototypeOf,fa=Object.prototype.hasOwnProperty;var Wr=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),V=(t,e)=>{for(var r in e)Kt(t,r,{get:e[r],enumerable:!0})},_o=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of ca(e))!fa.call(t,o)&&o!==r&&Kt(t,o,{get:()=>e[o],enumerable:!(n=aa(e,o))||n.enumerable});return t};var la=(t,e,r)=>(r=t!=null?ia(ua(t)):{},_o(e||!t||!t.__esModule?Kt(r,"default",{value:t,enumerable:!0}):r,t)),da=t=>_o(Kt({},"__esModule",{value:!0}),t);var An=Wr(ot=>{"use strict";Object.defineProperty(ot,"__esModule",{value:!0});ot.Netmask4Impl=void 0;ot.ip2long=nt;ot.long2ip=ce;function ce(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 qc=48,Wc=97,Gc=65;function Hc(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)-qc)>>>0;else if(r===16)if("a"<=t[o]&&t[o]<="f")e=e*r+(10+t.charCodeAt(o)-Wc)>>>0;else if("A"<=t[o]&&t[o]<="F")e=e*r+(10+t.charCodeAt(o)-Gc)>>>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 nt(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]=Hc(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 Cn=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=nt(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=(nt(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=ce(this.netLong),this.mask=ce(this.maskLong),this.hostmask=ce(~this.maskLong),this.first=this.bitmask<=30?ce(this.netLong+1):this.base,this.last=this.bitmask<=30?ce(this.netLong+this.size-2):ce(this.netLong+this.size-1),this.broadcast=this.bitmask<=30?ce(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):(nt(e)&this.maskLong)>>>0===(this.netLong&this.maskLong)>>>0}next(e=1){return new t(ce(this.netLong+this.size*e),this.mask)}forEach(e){let r=nt(this.first),n=nt(this.last),o=0;for(;r<=n;)e(ce(r),r,o),o++,r++}toString(){return this.base+"/"+this.bitmask}};ot.Netmask4Impl=Cn});var cs=Wr(st=>{"use strict";Object.defineProperty(st,"__esModule",{value:!0});st.Netmask6Impl=void 0;st.ip6bigint=Dn;st.bigint2ip6=Oe;var Xc=An(),Tn=(1n<<128n)-1n;function Dn(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,Xc.ip2long)(n),s=t.substring(0,r+1)+"0:0";return as(s)&~0xffffffffn|BigInt(o)}return as(t)}function as(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 Oe(t){if(t<0n||t>Tn)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 kn=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=Tn>>BigInt(128-this.bitmask)<<BigInt(128-this.bitmask);try{this.netBigint=Dn(e)&this.maskBigint}catch{throw new Error("Invalid IPv6 net address: "+e)}this.size=Number(1n<<BigInt(128-this.bitmask)),this.base=Oe(this.netBigint),this.mask=Oe(this.maskBigint),this.hostmask=Oe(~this.maskBigint&Tn),this.first=this.base,this.last=Oe(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):(Dn(e)&this.maskBigint)===this.netBigint}next(e=1){let r=1n<<BigInt(128-this.bitmask);return new t(Oe(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(Oe(r),Number(r),s),s++,r++}toString(){return this.base+"/"+this.bitmask}};st.Netmask6Impl=kn});var us=Wr(Le=>{"use strict";Object.defineProperty(Le,"__esModule",{value:!0});Le.long2ip=Le.ip2long=Le.Netmask=void 0;var fr=An();Object.defineProperty(Le,"ip2long",{enumerable:!0,get:function(){return fr.ip2long}});Object.defineProperty(Le,"long2ip",{enumerable:!0,get:function(){return fr.long2ip}});var Qc=cs(),Fn=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 Qc.Netmask6Impl(e,r):this._impl=new fr.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 fr.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()}};Le.Netmask=Fn});var Ul={};V(Ul,{AbstractMessageStream:()=>$e,AbstractMultiaddrConnection:()=>Bt,AbstractStream:()=>Re,AbstractStreamMuxer:()=>Nt,AdaptiveTimeout:()=>$n,BloomFilter:()=>It,CuckooFilter:()=>_e,DEFAULT_FAILURE_MULTIPLIER:()=>hs,DEFAULT_INTERVAL:()=>gs,DEFAULT_MAX_TIMEOUT:()=>ps,DEFAULT_MIN_TIMEOUT:()=>ms,DEFAULT_TIMEOUT_MULTIPLIER:()=>ds,InvalidDataLengthError:()=>yr,InvalidDataLengthLengthError:()=>wr,InvalidMessageLengthError:()=>ut,LengthPrefixedDecoder:()=>Jn,MaxEarlyStreamsError:()=>kt,MemoryStorage:()=>qr,MockStream:()=>go,MovingAverage:()=>ze,PeerQueue:()=>wo,PriorityQueue:()=>xo,Queue:()=>re,QueueFullError:()=>Dt,RateLimitError:()=>Tt,RateLimiter:()=>Eo,ScalableCuckooFilter:()=>Lt,StreamClosedError:()=>Ft,UnexpectedEOFError:()=>Ce,UnwrappedError:()=>Ut,byteStream:()=>$s,createBloomFilter:()=>Jo,createCuckooFilter:()=>Yo,createScalableCuckooFilter:()=>Zo,debounce:()=>at,echo:()=>Kn,echoStream:()=>Bl,getNetConfig:()=>q,getThinWaistAddresses:()=>nf,ipPortToMultiaddr:()=>sf,isAsyncGenerator:()=>af,isGenerator:()=>cf,isGlobalUnicast:()=>Rc,isGlobalUnicastIp:()=>of,isLinkLocal:()=>zc,isLinkLocalIp:()=>If,isLoopback:()=>Vc,isNetworkAddress:()=>jc,isPrivate:()=>nu,isPrivateIp:()=>Nn,isPromise:()=>On,lpStream:()=>Rs,messageStreamToDuplex:()=>zs,mockMuxer:()=>Rr,multiaddrConnectionPair:()=>yo,pbStream:()=>xf,pipe:()=>vf,repeatingTask:()=>Fl,streamPair:()=>oa,trackedList:()=>Nl,trackedMap:()=>Pl});var he=class extends Error{static name="AbortError";constructor(e="The operation was aborted"){super(e),this.name="AbortError"}};var R=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}};var Jt=class extends Error{static name="MuxerClosedError";constructor(e="The muxer is closed"){super(e),this.name="MuxerClosedError"}},Yt=class extends Error{static name="StreamResetError";constructor(e="The stream has been reset"){super(e),this.name="StreamResetError"}};var we=class extends Error{static name="StreamStateError";constructor(e="The stream is in an invalid state"){super(e),this.name="StreamStateError"}},bt=class extends Error{static name="StreamBufferError";constructor(e="The stream buffer was full"){super(e),this.name="StreamBufferError"}};var se=class extends Event{data;constructor(e,r){super("message",r),this.data=e}},Ge=class extends Event{error;local;constructor(e,r,n){super("close",n),this.error=r,this.local=e}},Zt=class extends Ge{constructor(e,r){super(!0,e,r)}},er=class extends Ge{constructor(e,r){super(!1,e,r)}};function ha(t){return typeof t?.handleEvent=="function"}function ma(t){return(t!==!0&&t!==!1&&t?.once)??!1}var ie=class extends EventTarget{#e=new Map;constructor(){super()}listenerCount(e){let r=this.#e.get(e);return r==null?0:r.length}addEventListener(e,r,n){let o=ma(n);super.addEventListener(e,i=>{if(o){let a=this.#e.get(i.type);a!=null&&(a=a.filter(({callback:u})=>u!==r),this.#e.set(i.type,a))}ha(r)?r.handleEvent(i):r(i)},n);let s=this.#e.get(e);s==null&&(s=[],this.#e.set(e,s)),s.push({callback:r,once:o})}removeEventListener(e,r,n){super.removeEventListener(e.toString(),r??null,n);let o=this.#e.get(e);o!=null&&(o=o.filter(({callback:s})=>s!==r),this.#e.set(e,o))}safeDispatchEvent(e,r={}){return this.dispatchEvent(new CustomEvent(e,r))}};var Kr={};V(Kr,{base58btc:()=>Q,base58flickr:()=>Ea});var zl=new Uint8Array(0);function So(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}function me(t){if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return t;if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);throw new Error("Unknown type, must be binary type")}function Io(t){return new TextEncoder().encode(t)}function Lo(t){return new TextDecoder().decode(t)}function pa(t,e){if(t.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var o=0;o<t.length;o++){var s=t.charAt(o),i=s.charCodeAt(0);if(r[i]!==255)throw new TypeError(s+" is ambiguous");r[i]=o}var a=t.length,u=t.charAt(0),l=Math.log(a)/Math.log(256),f=Math.log(256)/Math.log(a);function d(w){if(w instanceof Uint8Array||(ArrayBuffer.isView(w)?w=new Uint8Array(w.buffer,w.byteOffset,w.byteLength):Array.isArray(w)&&(w=Uint8Array.from(w))),!(w instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(w.length===0)return"";for(var _=0,b=0,x=0,I=w.length;x!==I&&w[x]===0;)x++,_++;for(var L=(I-x)*f+1>>>0,O=new Uint8Array(L);x!==I;){for(var N=w[x],de=0,$=L-1;(N!==0||de<b)&&$!==-1;$--,de++)N+=256*O[$]>>>0,O[$]=N%a>>>0,N=N/a>>>0;if(N!==0)throw new Error("Non-zero carry");b=de,x++}for(var Y=L-b;Y!==L&&O[Y]===0;)Y++;for(var Fe=u.repeat(_);Y<L;++Y)Fe+=t.charAt(O[Y]);return Fe}function p(w){if(typeof w!="string")throw new TypeError("Expected String");if(w.length===0)return new Uint8Array;var _=0;if(w[_]!==" "){for(var b=0,x=0;w[_]===u;)b++,_++;for(var I=(w.length-_)*l+1>>>0,L=new Uint8Array(I);w[_];){var O=r[w.charCodeAt(_)];if(O===255)return;for(var N=0,de=I-1;(O!==0||N<x)&&de!==-1;de--,N++)O+=a*L[de]>>>0,L[de]=O%256>>>0,O=O/256>>>0;if(O!==0)throw new Error("Non-zero carry");x=N,_++}if(w[_]!==" "){for(var $=I-x;$!==I&&L[$]===0;)$++;for(var Y=new Uint8Array(b+(I-$)),Fe=b;$!==I;)Y[Fe++]=L[$++];return Y}}}function y(w){var _=p(w);if(_)return _;throw new Error(`Non-${e} character`)}return{encode:d,decodeUnsafe:p,decode:y}}var ga=pa,ba=ga,Ao=ba;var Gr=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")}},Hr=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 To(this,e)}},Xr=class{decoders;constructor(e){this.decoders=e}or(e){return To(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 To(t,e){return new Xr({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var Qr=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 Gr(e,r,n),this.decoder=new Hr(e,r,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function He({name:t,prefix:e,encode:r,decode:n}){return new Qr(t,e,r,n)}function xe({name:t,prefix:e,alphabet:r}){let{encode:n,decode:o}=Ao(r,t);return He({prefix:e,name:t,encode:n,decode:s=>me(o(s))})}function ya(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 wa(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 xa(t){let e={};for(let r=0;r<t.length;++r)e[t[r]]=r;return e}function C({name:t,prefix:e,bitsPerChar:r,alphabet:n}){let o=xa(n);return He({prefix:e,name:t,encode(s){return wa(s,n,r)},decode(s){return ya(s,o,r,t)}})}var Q=xe({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Ea=xe({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Jr={};V(Jr,{base32:()=>ae,base32hex:()=>Ia,base32hexpad:()=>Ca,base32hexpadupper:()=>Aa,base32hexupper:()=>La,base32pad:()=>_a,base32padupper:()=>Sa,base32upper:()=>va,base32z:()=>Ta});var ae=C({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),va=C({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),_a=C({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Sa=C({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Ia=C({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),La=C({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Ca=C({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Aa=C({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Ta=C({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Yr={};V(Yr,{base36:()=>yt,base36upper:()=>Da});var yt=xe({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Da=xe({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var ka=Fo,Do=128,Fa=127,Ba=~Fa,Na=Math.pow(2,31);function Fo(t,e,r){e=e||[],r=r||0;for(var n=r;t>=Na;)e[r++]=t&255|Do,t/=128;for(;t&Ba;)e[r++]=t&255|Do,t>>>=7;return e[r]=t|0,Fo.bytes=r-n+1,e}var Pa=Zr,Ua=128,ko=127;function Zr(t,n){var r=0,n=n||0,o=0,s=n,i,a=t.length;do{if(s>=a)throw Zr.bytes=0,new RangeError("Could not decode varint");i=t[s++],r+=o<28?(i&ko)<<o:(i&ko)*Math.pow(2,o),o+=7}while(i>=Ua);return Zr.bytes=s-n,r}var Ma=Math.pow(2,7),Oa=Math.pow(2,14),$a=Math.pow(2,21),Ra=Math.pow(2,28),za=Math.pow(2,35),Va=Math.pow(2,42),ja=Math.pow(2,49),qa=Math.pow(2,56),Wa=Math.pow(2,63),Ga=function(t){return t<Ma?1:t<Oa?2:t<$a?3:t<Ra?4:t<za?5:t<Va?6:t<ja?7:t<qa?8:t<Wa?9:10},Ha={encode:ka,decode:Pa,encodingLength:Ga},Xa=Ha,wt=Xa;function xt(t,e=0){return[wt.decode(t,e),wt.decode.bytes]}function Xe(t,e,r=0){return wt.encode(t,e,r),e}function Qe(t){return wt.encodingLength(t)}function Je(t,e){let r=e.byteLength,n=Qe(t),o=n+Qe(r),s=new Uint8Array(o+r);return Xe(t,s,0),Xe(r,s,n),s.set(e,o),new Ke(t,r,e,s)}function Bo(t){let e=me(t),[r,n]=xt(e),[o,s]=xt(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Ke(r,o,i,e)}function No(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&So(t.bytes,r.bytes)}}var Ke=class{code;size;digest;bytes;constructor(e,r,n,o){this.code=e,this.size=r,this.digest=n,this.bytes=o}};function Po(t,e){let{bytes:r,version:n}=t;return n===0?Ka(r,en(t),e??Q.encoder):Ja(r,en(t),e??ae.encoder)}var Uo=new WeakMap;function en(t){let e=Uo.get(t);if(e==null){let r=new Map;return Uo.set(t,r),r}return e}var Ye=class t{code;version;multihash;bytes;"/";constructor(e,r,n,o){this.code=r,this.version=e,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:r}=this;if(e!==vt)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Ya)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=Je(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&&No(e.multihash,n.multihash)}toString(e){return Po(this,e)}toJSON(){return{"/":Po(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??Mo(n,o,s.bytes))}else if(r[Za]===!0){let{version:n,multihash:o,code:s}=r,i=Bo(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=Mo(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=me(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 Ke(r.multihashCode,r.digestSize,s,o);return[r.version===0?t.createV0(i):t.createV1(r.codec,i),e.subarray(r.size)]}static inspectBytes(e){let r=0,n=()=>{let[d,p]=xt(e.subarray(r));return r+=p,d},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(),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]=Qa(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 en(s).set(n,e),s}};function Qa(t,e){switch(t[0]){case"Q":{let r=e??Q;return[Q.prefix,r.decode(`${Q.prefix}${t}`)]}case Q.prefix:{let r=e??Q;return[Q.prefix,r.decode(t)]}case ae.prefix:{let r=e??ae;return[ae.prefix,r.decode(t)]}case yt.prefix:{let r=e??yt;return[yt.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 Ka(t,e,r){let{prefix:n}=r;if(n!==Q.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=e.get(n);if(o==null){let s=r.encode(t).slice(1);return e.set(n,s),s}else return o}function Ja(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,Ya=18;function Mo(t,e,r){let n=Qe(t),o=n+Qe(e),s=new Uint8Array(o+r.byteLength);return Xe(t,s,0),Xe(e,s,n),s.set(r,o),s}var Za=Symbol.for("@ipld/js-cid/CID");var tn={};V(tn,{identity:()=>rc});var Oo=0,ec="identity",$o=me;function tc(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 Je(Oo,$o(t))}var rc={code:Oo,name:ec,encode:$o,digest:tc};function Ze(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}function j(t=0){return new Uint8Array(t)}function Z(t=0){return new Uint8Array(t)}function Ee(t,e){e==null&&(e=t.reduce((o,s)=>o+s.length,0));let r=Z(e),n=0;for(let o of t)r.set(o,n),n+=o.length;return r}var zo=Symbol.for("@achingbrain/uint8arraylist");function Ro(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 et(t){return!!t?.[zo]}var A=class t{bufs;length;[zo]=!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(et(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(et(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=Ro(this.bufs,e);return r.buf[r.index]}set(e,r){let n=Ro(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(et(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 Ee(n,o)}subarray(e,r){let{bufs:n,length:o}=this._subList(e,r);return n.length===1?n[0]:Ee(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 d=e-a;n.push(i.subarray(d,d+(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(!et(e)&&!(e instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=e instanceof Uint8Array?e:e.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),e.length===0)return r>this.length?this.length:r;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let d=0;d<s;d++)i[d]=-1;for(let d=0;d<o;d++)i[n[d]]=d;let a=i,u=this.byteLength-n.byteLength,l=n.byteLength-1,f;for(let d=r;d<=u;d+=f){f=0;for(let p=l;p>=0;p--){let y=this.get(d+p);if(n[p]!==y){f=Math.max(1,p-a[y]);break}}if(f===0)return d}return-1}getInt8(e){let r=this.subarray(e,e+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(e,r){let n=Z(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,r),this.write(n,e)}getInt16(e,r){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,r)}setInt16(e,r,n){let o=j(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,r,n),this.write(o,e)}getInt32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,r)}setInt32(e,r,n){let o=j(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,r,n),this.write(o,e)}getBigInt64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,r)}setBigInt64(e,r,n){let o=j(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,r,n),this.write(o,e)}getUint8(e){let r=this.subarray(e,e+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint8(0)}setUint8(e,r){let n=Z(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,r),this.write(n,e)}getUint16(e,r){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,r)}setUint16(e,r,n){let o=j(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,r,n),this.write(o,e)}getUint32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,r)}setUint32(e,r,n){let o=j(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,r,n),this.write(o,e)}getBigUint64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,r)}setBigUint64(e,r,n){let o=j(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,r,n),this.write(o,e)}getFloat32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,r)}setFloat32(e,r,n){let o=j(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,r,n),this.write(o,e)}getFloat64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,r)}setFloat64(e,r,n){let o=j(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,r,n),this.write(o,e)}equals(e){if(e==null||!(e instanceof t)||e.bufs.length!==this.bufs.length)return!1;for(let r=0;r<this.bufs.length;r++)if(!Ze(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 rn={};V(rn,{base10:()=>nc});var nc=xe({prefix:"9",name:"base10",alphabet:"0123456789"});var nn={};V(nn,{base16:()=>oc,base16upper:()=>sc});var oc=C({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),sc=C({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var on={};V(on,{base2:()=>ic});var ic=C({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var sn={};V(sn,{base256emoji:()=>lc});var Vo=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}"),ac=Vo.reduce((t,e,r)=>(t[r]=e,t),[]),cc=Vo.reduce((t,e,r)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return t[n]=r,t},[]);function uc(t){return t.reduce((e,r)=>(e+=ac[r],e),"")}function fc(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=cc[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(o)}return new Uint8Array(e)}var lc=He({prefix:"\u{1F680}",name:"base256emoji",encode:uc,decode:fc});var un={};V(un,{base64:()=>an,base64pad:()=>dc,base64url:()=>cn,base64urlpad:()=>hc});var an=C({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),dc=C({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),cn=C({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),hc=C({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var fn={};V(fn,{base8:()=>mc});var mc=C({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var ln={};V(ln,{identity:()=>pc});var pc=He({prefix:"\0",name:"identity",encode:t=>Lo(t),decode:t=>Io(t)});var Sd=new TextEncoder,Id=new TextDecoder;var mn={};V(mn,{sha256:()=>wc,sha512:()=>xc});var yc=20;function hn({name:t,code:e,encode:r,minDigestLength:n,maxDigestLength:o}){return new dn(t,e,r,n,o)}var dn=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,r,n,o,s){this.name=e,this.code=r,this.encode=n,this.minDigestLength=o??yc,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?jo(n,this.code,r?.truncate):n.then(o=>jo(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function jo(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 Je(e,t)}function Wo(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}var wc=hn({name:"sha2-256",code:18,encode:Wo("SHA-256")}),xc=hn({name:"sha2-512",code:19,encode:Wo("SHA-512")});var _t={...ln,...on,...fn,...rn,...nn,...Jr,...Yr,...Kr,...un,...sn},Md={...mn,...tn};function Ho(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var Go=Ho("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),pn=Ho("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}),Ec={utf8:Go,"utf-8":Go,hex:_t.base16,latin1:pn,ascii:pn,binary:pn,..._t},rr=Ec;function T(t,e="utf8"){let r=rr[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}function Be(t,e="utf8"){let r=rr[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.encoder.encode(t).substring(1)}function vc(t,e=""){if(typeof t!="number"){let r=e&&`"${e}" `;throw new TypeError(`${r}expected number, got ${typeof t}`)}if(!Number.isSafeInteger(t)||t<0){let r=e&&`"${e}" `;throw new RangeError(`${r}expected integer >= 0, got ${t}`)}}function Xo(t=32){vc(t,"bytesLength");let e=typeof globalThis=="object"?globalThis.crypto:null;if(typeof e?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");if(t>65536)throw new RangeError(`"bytesLength" expected <= 65536, got ${t}`);return e.getRandomValues(new Uint8Array(t))}var _c=Math.pow(2,7),Sc=Math.pow(2,14),Ic=Math.pow(2,21),gn=Math.pow(2,28),bn=Math.pow(2,35),yn=Math.pow(2,42),wn=Math.pow(2,49),v=128,U=127;function M(t){if(t<_c)return 1;if(t<Sc)return 2;if(t<Ic)return 3;if(t<gn)return 4;if(t<bn)return 5;if(t<yn)return 6;if(t<wn)return 7;if(Number.MAX_SAFE_INTEGER!=null&&t>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function nr(t,e,r=0){switch(M(t)){case 8:e[r++]=t&255|v,t/=128;case 7:e[r++]=t&255|v,t/=128;case 6:e[r++]=t&255|v,t/=128;case 5:e[r++]=t&255|v,t/=128;case 4:e[r++]=t&255|v,t>>>=7;case 3:e[r++]=t&255|v,t>>>=7;case 2:e[r++]=t&255|v,t>>>=7;case 1:{e[r++]=t&255,t>>>=7;break}default:throw new Error("unreachable")}return e}function Lc(t,e,r=0){switch(M(t)){case 8:e.set(r++,t&255|v),t/=128;case 7:e.set(r++,t&255|v),t/=128;case 6:e.set(r++,t&255|v),t/=128;case 5:e.set(r++,t&255|v),t/=128;case 4:e.set(r++,t&255|v),t>>>=7;case 3:e.set(r++,t&255|v),t>>>=7;case 2:e.set(r++,t&255|v),t>>>=7;case 1:{e.set(r++,t&255),t>>>=7;break}default:throw new Error("unreachable")}return e}function Cc(t,e){let r=t[e],n=0;if(n+=r&U,r<v||(r=t[e+1],n+=(r&U)<<7,r<v)||(r=t[e+2],n+=(r&U)<<14,r<v)||(r=t[e+3],n+=(r&U)<<21,r<v)||(r=t[e+4],n+=(r&U)*gn,r<v)||(r=t[e+5],n+=(r&U)*bn,r<v)||(r=t[e+6],n+=(r&U)*yn,r<v)||(r=t[e+7],n+=(r&U)*wn,r<v))return n;throw new RangeError("Could not decode varint")}function Ac(t,e){let r=t.get(e),n=0;if(n+=r&U,r<v||(r=t.get(e+1),n+=(r&U)<<7,r<v)||(r=t.get(e+2),n+=(r&U)<<14,r<v)||(r=t.get(e+3),n+=(r&U)<<21,r<v)||(r=t.get(e+4),n+=(r&U)*gn,r<v)||(r=t.get(e+5),n+=(r&U)*bn,r<v)||(r=t.get(e+6),n+=(r&U)*yn,r<v)||(r=t.get(e+7),n+=(r&U)*wn,r<v))return n;throw new RangeError("Could not decode varint")}function or(t,e,r=0){return e==null&&(e=Z(M(t))),e instanceof Uint8Array?nr(t,e,r):Lc(t,e,r)}function pe(t,e=0){return t instanceof Uint8Array?Cc(t,e):Ac(t,e)}function sr(t){if(isNaN(t)||t<=0)throw new R("random bytes length must be a Number bigger than 0");return Xo(t)}var xn={32:16777619n,64:1099511628211n,128:309485009821345068724781371n,256:374144419156711147060143317175368453031918731002211n,512:35835915874844867368919076489095108449946327955754392558399825615420669938882575126094039892345713852759n,1024:5016456510113118655434598811035278955030765345404790744303017523831112055108147451509157692220295382716162651878526895249385292291816524375083746691371804094271873160484737966720260389217684476157468082573n},Qo={32:2166136261n,64:14695981039346656037n,128:144066263297769815596495629667062367629n,256:100029257958052580907070968620625704837092796014241193945225284501741471925557n,512:9659303129496669498009435400716310466090418745672637896108374329434462657994582932197716438449813051892206539805784495328239340083876191928701583869517785n,1024:14197795064947621068722070641403218320880622795441933960878474914617582723252296732303717722150864096521202355549365628174669108571814760471015076148029755969804077320157692458563003215304957150157403644460363550505412711285966361610267868082893823963790439336411086884584107735010676915n},Ko=new globalThis.TextEncoder;function Tc(t,e){let r=xn[e],n=Qo[e];for(let o=0;o<t.length;o++)n^=BigInt(t[o]),n=BigInt.asUintN(e,n*r);return n}function Dc(t,e,r){if(r.length===0)throw new Error("The `utf8Buffer` option must have a length greater than zero");let n=xn[e],o=Qo[e],s=t;for(;s.length>0;){let i=Ko.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 En(t,{size:e=32,utf8Buffer:r}={}){if(!xn[e])throw new Error("The `size` option must be one of 32, 64, 128, 256, 512, or 1024");if(typeof t=="string"){if(r)return Dc(t,e,r);t=Ko.encode(t)}return Tc(t,e)}var ve={hash:t=>Number(En(t,{size:32})),hashV:(t,e)=>kc(ve.hash(t,e))};function kc(t){let e=t.toString(16);return e.length%2===1&&(e=`0${e}`),T(e,"base16")}var Fc=Math.LN2*Math.LN2,It=class{seeds;bits;buffer;constructor(e={}){e.seeds!=null?this.seeds=e.seeds:this.seeds=Nc(e.hashes??8),this.bits=e.bits??1024,this.buffer=j(Math.ceil(this.bits/8))}add(e){typeof e=="string"&&(e=T(e));for(let r=0;r<this.seeds.length;r++){let o=ve.hash(e,this.seeds[r])%this.bits;this.setbit(o)}}has(e){typeof e=="string"&&(e=T(e));for(let r=0;r<this.seeds.length;r++){let o=ve.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 Jo(t,e=.005){let r=Bc(t,e);return new It(r)}function Bc(t,e=.005){let r=Math.round(-1*t*Math.log(e)/Fc),n=Math.round(r/t*Math.LN2);return{bits:r,hashes:n}}function Nc(t){let e,r,n=[];for(let o=0;o<t;o++)for(e=new A(sr(4)),n[o]=e.getUint32(0,!0),r=0;r<o;r++)if(n[o]===n[r]){o--;break}return n}var vn=64,ee=class{fp;h;seed;constructor(e,r,n,o=2){if(o>vn)throw new TypeError("Invalid Fingerprint Size");let s=r.hashV(e,n),i=j(o);for(let a=0;a<i.length;a++)i[a]=s[a];i.length===0&&(i[0]=7),this.fp=i,this.h=r,this.seed=n}hash(){return this.h.hash(this.fp,this.seed)}equals(e){return e?.fp instanceof Uint8Array?Ze(this.fp,e.fp):!1}};function Ne(t,e){return Math.floor(Math.random()*(e-t))+t}var Pe=class{contents;constructor(e){this.contents=new Array(e).fill(null)}has(e){if(!(e instanceof ee))throw new TypeError("Invalid Fingerprint");return this.contents.some(r=>e.equals(r))}add(e){if(!(e instanceof ee))throw new TypeError("Invalid Fingerprint");for(let r=0;r<this.contents.length;r++)if(this.contents[r]==null)return this.contents[r]=e,!0;return!0}swap(e){if(!(e instanceof ee))throw new TypeError("Invalid Fingerprint");let r=Ne(0,this.contents.length-1),n=this.contents[r];return this.contents[r]=e,n}remove(e){if(!(e instanceof ee))throw new TypeError("Invalid Fingerprint");let r=this.contents.findIndex(n=>e.equals(n));return r>-1?(this.contents[r]=null,!0):!1}};var Pc=500,_e=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??ve,this.seed=e.seed??Ne(0,Math.pow(2,10))}add(e){typeof e=="string"&&(e=T(e));let r=new ee(e,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(e,this.seed)%this.filterSize,o=(n^r.hash())%this.filterSize;if(this.buckets[n]==null&&(this.buckets[n]=new Pe(this.bucketSize)),this.buckets[o]==null&&(this.buckets[o]=new Pe(this.bucketSize)),this.buckets[n].add(r)||this.buckets[o].add(r))return this.count++,!0;let s=[n,o],i=s[Ne(0,s.length-1)];this.buckets[i]==null&&(this.buckets[i]=new Pe(this.bucketSize));for(let a=0;a<Pc;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 Pe(this.bucketSize)),this.buckets[i].add(u)))return this.count++,!0}return!1}has(e){typeof e=="string"&&(e=T(e));let r=new ee(e,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(e,this.seed)%this.filterSize,o=this.buckets[n]?.has(r)??!1;if(o)return o;let s=(n^r.hash())%this.filterSize;return this.buckets[s]?.has(r)??!1}remove(e){typeof e=="string"&&(e=T(e));let r=new ee(e,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(e,this.seed)%this.filterSize,o=this.buckets[n]?.remove(r)??!1;if(o)return this.count--,o;let s=(n^r.hash())%this.filterSize,i=this.buckets[s]?.remove(r)??!1;return i&&this.count--,i}get reliable(){return Math.floor(100*(this.count/this.filterSize))<=90}},Uc={1:.5,2:.84,4:.95,8:.98};function Mc(t=.001){return t>.002?2:t>1e-5?4:8}function _n(t,e=.001){let r=Mc(e),n=Uc[r],o=Math.round(t/n),s=Math.min(Math.ceil(Math.log2(1/e)+Math.log2(2*r)),vn);return{filterSize:o,bucketSize:r,fingerprintSize:s}}function Yo(t,e=.005){let r=_n(t,e);return new _e(r)}var Lt=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??ve,this.seed=e.seed??Ne(0,Math.pow(2,10)),this.filterSeries=[new _e({filterSize:this.filterSize,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed})]}add(e){if(typeof e=="string"&&(e=T(e)),this.has(e))return!0;let r=this.filterSeries.find(n=>n.reliable);if(r==null){let n=this.filterSize*Math.pow(this.scale,this.filterSeries.length);r=new _e({filterSize:n,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed}),this.filterSeries.push(r)}return r.add(e)}has(e){typeof e=="string"&&(e=T(e));for(let r=0;r<this.filterSeries.length;r++)if(this.filterSeries[r].has(e))return!0;return!1}remove(e){typeof e=="string"&&(e=T(e));for(let r=0;r<this.filterSeries.length;r++)if(this.filterSeries[r].remove(e))return!0;return!1}get count(){return this.filterSeries.reduce((e,r)=>e+r.count,0)}};function Zo(t,e=.001,r){return new Lt({..._n(t,e),...r??{}})}function q(t){let e=t.getComponents(),r={},n=0;if(e[n]?.name==="ip6zone"&&(r.zone=`${e[n].value}`,n++),e[n].name==="ip4"||e[n].name==="ip6"||e[n].name==="dns"||e[n].name==="dns4"||e[n].name==="dns6"?(r.type=e[n].name,r.host=e[n].value,n++):e[n].name==="dnsaddr"&&(r.type=e[n].name,r.host=`_dnsaddr.${e[n].value}`,n++),(e[n]?.name==="tcp"||e[n]?.name==="udp")&&(r.protocol=e[n].name==="tcp"?"tcp":"udp",r.port=parseInt(`${e[n].value}`),n++),e[n]?.name==="ipcidr"&&(r.type==="ip4"?r.cidr=parseInt(`${e[n].value}`):r.type==="ip6"&&(r.cidr=`${e[n].value}`),n++),r.type==null||r.host==null)throw new R(`Multiaddr ${t} was not an IPv4, IPv6, DNS, DNS4, DNS6 or DNSADDR address`);return e[n]?.name==="tls"&&e[n+1]?.name==="sni"&&(r.sni=e[n+1].value,n+=2),r}var ir=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 d=this.readChar();if(d===void 0)return;let p=Number.parseInt(d,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 es=45,Oc=15,tt=new ir;function ar(t){if(!(t.length>Oc))return tt.new(t).parseWith(()=>tt.readIPv4Addr())}function cr(t){if(t.includes("%")&&(t=t.split("%")[0]),!(t.length>es))return tt.new(t).parseWith(()=>tt.readIPv6Addr())}function rt(t,e=!1){if(t.includes("%")&&(t=t.split("%")[0]),t.length>es)return;let r=tt.new(t).parseWith(()=>tt.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 ts(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 rs(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 Sn(t){switch(t.length){case Ue:return t.join(".");case Me:{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 ns(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 os(t){let e="0x";for(let r of t)e+=(r>>4).toString(16)+(r&15).toString(16);return e}var Ue=4,Me=16,Rh=parseInt("0xFFFF",16),$c=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function Ct(t,e){e.length===Me&&t.length===Ue&&ts(e,0,11)&&(e=e.slice(12)),e.length===Ue&&t.length===Me&&rs(t,$c,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 ss(t,e){if(typeof e=="string"&&(e=rt(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 In(t){let[e,r]=t.split("/");if(!e||!r)throw new Error("Failed to parse given CIDR: "+t);let n=Ue,o=ar(e);if(o==null&&(n=Me,o=cr(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=Ln(s,8*n);return{network:Ct(o,i),mask:i}}function Ln(t,e){if(e!==8*Ue&&e!==8*Me)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 At=class{constructor(e,r){if(r==null)({network:this.network,mask:this.mask}=In(e));else{let n=rt(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=rt(r);if(s==null)throw new Error("Failed to parse mask");this.mask=s}else this.mask=Ln(o,8*n.length);this.network=Ct(n,this.mask)}}contains(e){return ss({network:this.network,mask:this.mask},e)}toString(){let e=ns(this.mask),r=e!==-1?String(e):os(this.mask);return Sn(this.network)+"/"+r}};function ur(t,e){return new At(t).contains(e)}function Rc(t){try{let e=q(t);return e.type==="ip6"?ur("2000::/3",e.host):!1}catch{return!1}}function zc(t){try{let e=q(t);switch(e.type){case"ip4":return e.host.startsWith("169.254.");case"ip6":return e.host.toLowerCase().startsWith("fe80");default:return!1}}catch{return!1}}function is(t){return/^127\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/i.test(t)||/^::1$/.test(t)}function Vc(t){try{let e=q(t);switch(e.type){case"ip4":case"ip6":return is(e.host);default:return!1}}catch{return!1}}function jc(t){try{return q(t),!0}catch{return!1}}function Se(t){return!!ar(t)}function Ie(t){return!!cr(t)}var fs=la(us(),1),Kc=["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"],Jc=Kc.map(t=>new fs.Netmask(t));function Bn(t){for(let e of Jc)if(e.contains(t))return!0;return!1}function Yc(t){return/^::ffff:([0-9a-fA-F]{1,4}):([0-9a-fA-F]{1,4})$/.test(t)}function Zc(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 Bn(o)}function eu(t){return/^::ffff:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(t)}function tu(t){let e=t.split(":"),r=e[e.length-1];return Bn(r)}function ru(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 Nn(t){if(Se(t))return Bn(t);if(Yc(t))return Zc(t);if(eu(t))return tu(t);if(Ie(t))return ru(t)}function nu(t){try{let e=q(t);switch(e.type){case"ip4":case"ip6":return Nn(e.host)??!1;default:return e.host==="localhost"}}catch{return!1}}function te(){let t={};return t.promise=new Promise((e,r)=>{t.resolve=e,t.reject=r}),t}var lr=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}},it=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new lr(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 lr(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 Pn=class extends Error{type;code;constructor(e,r){super(e??"The operation was aborted"),this.type="aborted",this.code=r??"ABORT_ERR"}};function ue(t={}){return ou(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 ou(t,e){e=e??{};let r=e.onEnd,n=new it,o,s,i,a=te(),u=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((b,x)=>{s=I=>{s=null,n.push(I);try{b(t(n))}catch(L){x(L)}return o}}):t(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=te()})}},l=b=>s!=null?s(b):(n.push(b),o),f=b=>(n=new it,s!=null?s({error:b}):(n.push({error:b}),o)),d=b=>{if(i)return o;if(e?.objectMode!==!0&&b?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return l({done:!1,value:b})},p=b=>i?o:(i=!0,b!=null?f(b):l({done:!0})),y=()=>(n=new it,p(),{done:!0}),w=b=>(p(b),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:u,return:y,throw:w,push:d,end:p,get readableLength(){return n.size},onEmpty:async b=>{let x=b?.signal;if(x?.throwIfAborted(),n.isEmpty())return;let I,L;x!=null&&(I=new Promise((O,N)=>{L=()=>{N(new Pn)},x.addEventListener("abort",L)}));try{await Promise.race([a.promise,I])}finally{L!=null&&x!=null&&x?.removeEventListener("abort",L)}}},r==null)return o;let _=o;return o={[Symbol.asyncIterator](){return this},next(){return _.next()},throw(b){return _.throw(b),r!=null&&(r(b),r=void 0),{done:!0}},return(){return _.return(),r!=null&&(r(),r=void 0),{done:!0}},push:d,end(b){return _.end(b),r!=null&&(r(b),r=void 0),o},get readableLength(){return _.readableLength},onEmpty:b=>_.onEmpty(b)},o}var Un=class t extends Error{name="TimeoutError";constructor(e,r){super(e,r),Error.captureStackTrace?.(this,t)}},ls=t=>t.reason??new DOMException("This operation was aborted.","AbortError");function Mn(t,e){let{milliseconds:r,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout},signal:i}=e,a,u,f=new Promise((d,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(ls(i));return}if(i&&(u=()=>{p(ls(i))},i.addEventListener("abort",u,{once:!0})),t.then(d,p),r===Number.POSITIVE_INFINITY)return;let y=new Un;a=s.setTimeout.call(void 0,()=>{if(n){try{d(n())}catch(w){p(w)}return}typeof t.cancel=="function"&&t.cancel(),o===!1?d():o instanceof Error?p(o):(y.message=o??`Promise timed out after ${r} milliseconds`,p(y))},r)}).finally(()=>{f.clear(),u&&i&&i.removeEventListener("abort",u)});return f.clear=()=>{s.clearTimeout.call(void 0,a),a=void 0},f}var su=t=>{let e=t.addEventListener||t.on||t.addListener,r=t.removeEventListener||t.off||t.removeListener;if(!e||!r)throw new TypeError("Emitter is not compatible");return{addListener:e.bind(t),removeListener:r.bind(t)}};function iu(t,e,r){let n,o=new Promise((s,i)=>{if(r={rejectionEvents:["error"],multiArgs:!1,rejectionMultiArgs:!1,resolveImmediately:!1,...r},!(r.count>=0&&(r.count===Number.POSITIVE_INFINITY||Number.isInteger(r.count))))throw new TypeError("The `count` option should be at least 0 or more");r.signal?.throwIfAborted();let a=[e].flat(),u=[],{addListener:l,removeListener:f}=su(t),d=async(...y)=>{let w=r.multiArgs?y:y[0];if(r.filter)try{if(!await r.filter(w))return}catch(_){n(),i(_);return}u.push(w),r.count===u.length&&(n(),s(u))},p=(...y)=>{n(),i(r.rejectionMultiArgs?y:y[0])};n=()=>{for(let y of a)f(y,d);for(let y of r.rejectionEvents)a.includes(y)||f(y,p)};for(let y of a)l(y,d);for(let y of r.rejectionEvents)a.includes(y)||l(y,p);r.signal&&r.signal.addEventListener("abort",()=>{p(r.signal.reason)},{once:!0}),r.resolveImmediately&&s(u)});if(o.cancel=n,typeof r.timeout=="number"){let s=Mn(o,{milliseconds:r.timeout});return s.cancel=()=>{n(),s.clear()},s}return o}function D(t,e,r){typeof r=="function"&&(r={filter:r}),r={...r,count:1,resolveImmediately:!1};let n=iu(t,e,r),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 Tt=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}},Dt=class extends Error{static name="QueueFullError";constructor(e="The queue was full"){super(e),this.name="QueueFullError"}},Ce=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"},kt=class extends Error{static name="MaxEarlyStreamsError";name="MaxEarlyStreamsError"},Ft=class extends Error{static name="StreamClosedError";name="StreamClosedError"};function au(t){return t.reason}async function k(t,e,r){if(e==null)return t;let n=r?.translateError??au;if(e.aborted)return t.catch(()=>{}),Promise.reject(n(e));let o;try{return await Promise.race([t,new Promise((s,i)=>{o=()=>{i(n(e))},e.addEventListener("abort",o)})])}finally{o!=null&&e.removeEventListener("abort",o)}}var dr=class{deferred;signal;onProgress;constructor(e){this.signal=e?.signal,this.onProgress=e?.onProgress,this.deferred=te(),this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(this.signal?.reason??new he)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function cu(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var hr=class{id;fn;options;recipients;status;timeline;controller;constructor(e,r){this.id=cu(),this.status="queued",this.fn=e,this.options=r,this.recipients=[],this.timeline={created:Date.now()},this.controller=new AbortController,this.controller.signal,this.onAbort=this.onAbort.bind(this)}abort(e){this.controller.abort(e)}onAbort(){this.recipients.reduce((r,n)=>r&&n.signal?.aborted===!0,!0)&&(this.controller.abort(new he),this.cleanup())}async join(e){let r=new dr(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 k(this.fn({...this.options??{},signal:this.controller.signal,onProgress:r=>{this.recipients.forEach(n=>{n.onProgress?.(r)})}}),this.controller.signal);this.recipients.forEach(r=>{r.deferred.resolve(e)}),this.status="complete"}catch(e){this.recipients.forEach(r=>{r.deferred.reject(e)}),this.status="errored"}finally{this.timeline.finished=Date.now(),this.cleanup()}}cleanup(){this.recipients.forEach(e=>{e.cleanup(),e.signal?.removeEventListener("abort",this.onAbort)})}};var re=class extends ie{concurrency;maxSize;queue;pending;sort;paused;constructor(e={}){super(),this.concurrency=e.concurrency??Number.POSITIVE_INFINITY,this.maxSize=e.maxSize??Number.POSITIVE_INFINITY,this.pending=0,this.paused=!1,e.metricName!=null&&e.metrics?.registerMetricGroup(e.metricName,{calculate:()=>({size:this.queue.length,running:this.pending,queued:this.queue.length-this.pending})}),this.sort=e.sort,this.queue=[],this.emitEmpty=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 Dt;let n=new hr(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 he)}),this.clear()}async onEmpty(e){this.size!==0&&await D(this,"empty",e)}async onSizeLessThan(e,r){this.size<e||await D(this,"next",{...r,filter:()=>this.size<e})}async onIdle(e){this.pending===0&&this.size===0||await D(this,"idle",e)}get size(){return this.queue.length}get queued(){return this.queue.length-this.pending}get running(){return this.pending}async*toGenerator(e){e?.signal?.throwIfAborted();let r=ue({objectMode:!0}),n=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 he("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 uu=Math.pow(2,20)*4,$e=class extends ie{status;timeline;inactivityTimeout;maxReadBufferLength;maxWriteBufferLength;log;direction;maxMessageSize;readStatus;writeStatus;remoteReadStatus;remoteWriteStatus;writableNeedsDrain;readBuffer;writeBuffer;sendingData;onDrainPromise;constructor(e){super(),this.status="open",this.log=e.log,this.direction=e.direction??"outbound",this.inactivityTimeout=e.inactivityTimeout??12e4,this.maxReadBufferLength=e.maxReadBufferLength??uu,this.maxWriteBufferLength=e.maxWriteBufferLength,this.maxMessageSize=e.maxMessageSize,this.readBuffer=new A,this.writeBuffer=new A,this.readStatus="readable",this.remoteReadStatus="readable",this.writeStatus="writable",this.remoteWriteStatus="writable",this.sendingData=!1,this.writableNeedsDrain=!1,this.timeline={open:Date.now()},this.processSendQueue=this.processSendQueue.bind(this);let r=()=>{this.writableNeedsDrain&&(this.log.trace("drain event received, continue sending data"),this.writableNeedsDrain=!1,this.processSendQueue()),this.onDrainPromise?.resolve()};this.addEventListener("drain",r);let n=o=>{this.onDrainPromise?.reject(o.error??new Ft)};this.addEventListener("close",n)}get readBufferLength(){return this.readBuffer.byteLength}get writeBufferLength(){return this.writeBuffer.byteLength}async onDrain(e){return this.writableNeedsDrain!==!0?Promise.resolve():(this.onDrainPromise==null&&(this.onDrainPromise=Promise.withResolvers()),k(this.onDrainPromise.promise,e?.signal))}async*[Symbol.asyncIterator](){if(this.readStatus!=="readable"&&this.readStatus!=="paused")return;let e=ue(),r=s=>{e.push(s.data)};this.addEventListener("message",r);let n=s=>{e.end(s.error)};this.addEventListener("close",n);let o=()=>{e.end()};this.addEventListener("remoteCloseWrite",o);try{yield*e}finally{this.removeEventListener("message",r),this.removeEventListener("close",n),this.removeEventListener("remoteCloseWrite",o)}}isReadable(){return this.status==="open"}send(e){if(this.writeStatus==="closed"||this.writeStatus==="closing")throw new we(`Cannot write to a stream that is ${this.writeStatus}`);return this.log.trace("append %d bytes to write buffer",e.byteLength),this.writeBuffer.append(e),this.processSendQueue()}abort(e){if(!(this.status==="aborted"||this.status==="reset"||this.status==="closed")){this.log.error("abort with error - %e",e),this.status="aborted",this.readBuffer.byteLength>0&&this.readBuffer.consume(this.readBuffer.byteLength),this.writeBuffer.byteLength>0&&(this.writeBuffer.consume(this.writeBuffer.byteLength),this.safeDispatchEvent("idle")),this.writeStatus="closed",this.remoteWriteStatus="closed",this.readStatus="closed",this.remoteReadStatus="closed",this.timeline.close=Date.now();try{this.sendReset(e)}catch(r){this.log("failed to send reset to remote - %e",r)}this.dispatchEvent(new Zt(e))}}pause(){if(this.readStatus==="closed"||this.readStatus==="closing")throw new we("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 we("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 we(`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 we(`Cannot push data onto a stream that is ${this.readStatus}`);if(e.byteLength!==0){if(this.readBuffer.prepend(e),this.readStatus==="paused"||this.listenerCount("message")===0){this.checkReadBufferLength();return}setTimeout(()=>{this.dispatchReadBuffer()},0)}}onData(e){if(e.byteLength!==0){if(this.readStatus==="closing"||this.readStatus==="closed"){this.log("ignoring data - read status %s",this.readStatus);return}this.readBuffer.append(e),this.dispatchReadBuffer()}}addEventListener(...e){super.addEventListener.apply(this,e),e[0]==="message"&&this.readBuffer.byteLength>0&&queueMicrotask(()=>{this.dispatchReadBuffer()})}onRemoteReset(){this.log("remote reset"),this.status="reset",this.writeStatus="closed",this.remoteWriteStatus="closed",this.remoteReadStatus="closed",this.timeline.close=Date.now(),this.readBuffer.byteLength===0&&(this.readStatus="closed");let e=new Yt;this.dispatchEvent(new er(e))}onTransportClosed(e){this.log("transport closed"),this.readStatus==="readable"&&this.readBuffer.byteLength===0&&(this.log("close readable end after transport closed and read buffer is empty"),this.readStatus="closed"),this.remoteReadStatus!=="closed"&&(this.remoteReadStatus="closed"),this.remoteWriteStatus!=="closed"&&(this.remoteWriteStatus="closed"),this.writeStatus!=="closed"&&(this.writeStatus="closed"),e!=null?this.abort(e):(this.status==="open"||this.status==="closing")&&(this.timeline.close=Date.now(),this.status="closed",this.writeStatus="closed",this.remoteWriteStatus="closed",this.remoteReadStatus="closed",this.dispatchEvent(new Ge))}onRemoteCloseWrite(){this.remoteWriteStatus!=="closed"&&(this.log.trace("on remote close write"),this.remoteWriteStatus="closed",this.safeDispatchEvent("remoteCloseWrite"),this.writeStatus==="closed"&&this.onTransportClosed())}onRemoteCloseRead(){this.log.trace("on remote close read"),this.remoteReadStatus="closed",this.writeBuffer.byteLength>0&&(this.writeBuffer.consume(this.writeBuffer.byteLength),this.safeDispatchEvent("idle"))}processSendQueue(){if(this.writableNeedsDrain)return this.log.trace("not processing send queue as drain is required"),this.checkWriteBufferLength(),!1;if(this.writeBuffer.byteLength===0)return this.log.trace("not processing send queue as no bytes to send"),!0;if(this.sendingData)return this.log.trace("not processing send queue as already sending data"),!0;this.sendingData=!0,this.log.trace("processing send queue with %d queued bytes",this.writeBuffer.byteLength);try{let e=!0,r=this.writeBuffer.byteLength,n=0;for(;this.writeBuffer.byteLength>0;){let o=Math.min(this.maxMessageSize??this.writeBuffer.byteLength,this.writeBuffer.byteLength);if(o===0){e=!1;break}let s=this.writeBuffer.sublist(0,o),i=new A(s);this.writeBuffer.consume(s.byteLength);let a=this.sendData(s);if(e=a.canSendMore,n+=a.sentBytes,a.sentBytes!==i.byteLength&&(i.consume(a.sentBytes),this.writeBuffer.prepend(i)),!e)break}return e||(this.log.trace("sent %d/%d bytes, pausing sending because underlying stream is full, %d bytes left in the write buffer",n,r,this.writeBuffer.byteLength),this.writableNeedsDrain=!0,this.checkWriteBufferLength()),this.writeBuffer.byteLength===0&&this.safeDispatchEvent("idle"),e}finally{this.sendingData=!1}}dispatchReadBuffer(){try{if(this.listenerCount("message")===0){this.log.trace("not dispatching pause buffer as there are no listeners for the message event");return}if(this.readBuffer.byteLength===0){this.log.trace("not dispatching pause buffer as there is no data to dispatch");return}if(this.readStatus==="paused"){this.log.trace("not dispatching pause buffer we are paused");return}if(this.readStatus==="closing"||this.readStatus==="closed"){this.log("dropping %d bytes because the readable end is %s",this.readBuffer.byteLength,this.readStatus),this.readBuffer.consume(this.readBuffer.byteLength);return}let e=this.readBuffer.sublist();this.readBuffer.consume(e.byteLength),this.dispatchEvent(new se(e))}finally{this.readBuffer.byteLength===0&&this.remoteWriteStatus==="closed"&&(this.log("close readable end after dispatching read buffer and remote writable end is closed"),this.readStatus="closed"),this.checkReadBufferLength()}}checkReadBufferLength(){this.readBuffer.byteLength>this.maxReadBufferLength&&this.abort(new bt(`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 bt(`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 Bt=class extends $e{remoteAddr;metricPrefix;metrics;constructor(e){super(e),this.metricPrefix=e.metricPrefix??"",this.metrics=e.metrics,this.remoteAddr=e.remoteAddr,this.addEventListener("close",r=>{this.metrics?.increment({[`${this.metricPrefix}end`]:!0}),r.error!=null?r.local?this.metrics?.increment({[`${this.metricPrefix}abort`]:!0}):this.metrics?.increment({[`${this.metricPrefix}reset`]:!0}):r.local?this.metrics?.increment({[`${this.metricPrefix}_local_close`]:!0}):this.metrics?.increment({[`${this.metricPrefix}_remote_close`]:!0})})}async close(e){this.status==="open"&&(this.status="closing",this.writeStatus="closing",this.remoteWriteStatus="closing",this.remoteReadStatus="closing",(this.sendingData||this.writeBuffer.byteLength>0)&&(this.log("waiting for write queue to become idle before closing writable end of stream, %d unsent bytes",this.writeBuffer.byteLength),await D(this,"idle",{...e,rejectionEvents:["close"]})),this.writableNeedsDrain&&(this.log("waiting for write queue to drain before closing writable end of stream, %d unsent bytes",this.writeBuffer.byteLength),await D(this,"drain",{...e,rejectionEvents:["close"]})),await this.sendClose(e),this.onTransportClosed())}};function On(t){return t==null?!1:typeof t.then=="function"&&typeof t.catch=="function"&&typeof t.finally=="function"}var Nt=class extends ie{streams;protocol;status;log;maConn;streamOptions;earlyStreams;maxEarlyStreams;metrics;constructor(e,r){super(),this.maConn=e,this.protocol=r.protocol,this.streams=[],this.earlyStreams=[],this.status="open",this.log=e.log.newScope(r.name),this.streamOptions=r.streamOptions,this.maxEarlyStreams=r.maxEarlyStreams??10,this.metrics=r.metrics;let n=i=>{try{this.onData(i.data)}catch(a){this.abort(a),this.maConn.abort(a)}};this.maConn.addEventListener("message",n);let o=()=>{this.log("underlying stream drained, signal %d streams to continue writing",this.streams.length),this.streams.forEach(i=>{i.onMuxerDrain()})};this.maConn.addEventListener("drain",o);let s=()=>{this.log("underlying stream closed with status %s and %d streams",this.status,this.streams.length),this.onTransportClosed()};this.maConn.addEventListener("close",s)}send(e){let r=this.maConn.send(e);return r===!1&&(this.log("underlying stream saturated, signal %d streams to pause writing",this.streams.length),this.streams.forEach(n=>{n.onMuxerNeedsDrain()})),r}async close(e){this.status==="closed"||this.status==="closing"||(this.status="closing",await k(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 Jt;let r=this.onCreateStream({...this.streamOptions,...e});return On(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 kt(`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 Re=class extends $e{id;protocol;constructor(e){super(e),this.id=e.id,this.protocol=e.protocol??""}async close(e){this.writeStatus==="closing"||this.writeStatus==="closed"||(this.writeStatus="closing",(this.sendingData||this.writeBuffer.byteLength>0)&&(this.log("waiting for write queue to become idle before closing writable end of stream, %d unsent bytes",this.writeBuffer.byteLength),await D(this,"idle",{...e,rejectionEvents:["close"]})),this.writableNeedsDrain&&(this.log("waiting for write queue to drain before closing writable end of stream, %d unsent bytes, sending %s",this.writeBuffer.byteLength,this.sendingData),await D(this,"drain",{...e,rejectionEvents:["close"]}),this.log("write queue drained, closing writable end of stream, %d unsent bytes, sending %s",this.writeBuffer.byteLength,this.sendingData)),await this.sendCloseWrite(e),this.writeStatus="closed",this.log("closed writable end gracefully"),this.remoteWriteStatus==="closed"&&this.onTransportClosed())}async closeRead(e){this.readStatus==="closing"||this.readStatus==="closed"||(this.readBuffer.byteLength>0&&this.readBuffer.consume(this.readBuffer.byteLength),this.readStatus="closing",await this.sendCloseRead(e),this.readStatus="closed",this.log("closed readable end gracefully"))}};function mr(t){let e=new globalThis.AbortController;function r(){let s=t.filter(i=>i?.aborted===!0).map(i=>i?.reason).pop();e.abort(s);for(let i of t)i?.removeEventListener!=null&&i.removeEventListener("abort",r)}for(let s of t){if(s?.aborted===!0){r();break}s?.addEventListener!=null&&s.addEventListener("abort",r)}function n(){for(let s of t)s?.removeEventListener!=null&&s.removeEventListener("abort",r)}let o=e.signal;return o.clear=n,o}var ze=class{movingAverage;variance;deviation;forecast;timeSpan;previousTime;constructor(e){this.timeSpan=e,this.movingAverage=0,this.variance=0,this.deviation=0,this.forecast=0}alpha(e,r){return 1-Math.exp(-(e-r)/this.timeSpan)}push(e,r=Date.now()){if(this.previousTime!=null){let n=this.alpha(r,this.previousTime),o=e-this.movingAverage,s=n*o;this.movingAverage=n*e+(1-n)*this.movingAverage,this.variance=(1-n)*(this.variance+o*s),this.deviation=Math.sqrt(this.variance),this.forecast=this.movingAverage+n*o}else this.movingAverage=e;this.previousTime=r}};var ds=1.2,hs=2,ms=5e3,ps=6e4,gs=5e3,$n=class{success;failure;next;metric;timeoutMultiplier;failureMultiplier;minTimeout;maxTimeout;constructor(e={}){let r=e.interval??gs;this.success=new ze(r),this.failure=new ze(r),this.next=new ze(r),this.failureMultiplier=e.failureMultiplier??hs,this.timeoutMultiplier=e.timeoutMultiplier??ds,this.minTimeout=e.minTimeout??ms,this.maxTimeout=e.maxTimeout??ps,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=mr([e.signal,n]);return o.start=Date.now(),o.timeout=r,o}cleanUp(e){e.clear();let r=Date.now()-e.start;e.aborted?(this.failure.push(r),this.next.push(r*this.failureMultiplier),this.metric?.update({failureMovingAverage:this.failure.movingAverage,failureDeviation:this.failure.deviation,failureForecast:this.failure.forecast,failureVariance:this.failure.variance,failure:r})):(this.success.push(r),this.next.push(r),this.metric?.update({successMovingAverage:this.success.movingAverage,successDeviation:this.success.deviation,successForecast:this.success.forecast,successVariance:this.success.variance,success:r}))}};var P=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},ge=class extends Error{static name="ValidationError";name="ValidationError"},pr=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},gr=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};function zn(t){return e=>Be(e,t)}function Vn(t){return e=>T(e,t)}function ct(t){return new DataView(t.buffer).getUint16(t.byteOffset).toString()}function Ve(t){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,typeof t=="string"?parseInt(t):t),new Uint8Array(e)}function bs(t){let e=t.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==16)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion address.`);let r=T(e[0],"base32"),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=Ve(n);return Ee([r,o],r.length+o.length)}function ys(t){let e=t.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==56)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion3 address.`);let r=ae.decode(`b${e[0]}`),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=Ve(n);return Ee([r,o],r.length+o.length)}function jn(t){let e=t.subarray(0,t.length-2),r=t.subarray(t.length-2),n=Be(e,"base32"),o=ct(r);return`${n}:${o}`}var qn=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 P("Invalid byte value in IP address");e[n]=o}),e},ws=function(t){let e=0;t=t.toString().trim();let r=t.split(":",8),n;for(n=0;n<r.length;n++){let s=Se(r[n]),i;s&&(i=qn(r[n]),r[n]=Be(i.subarray(0,2),"base16")),i!=null&&++n<8&&r.splice(n,0,Be(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 P("Invalid byte value in IP address");o[e++]=s>>8&255,o[e++]=s&255}return o},xs=function(t){if(t.byteLength!==4)throw new P("IPv4 address was incorrect length");let e=[];for(let r=0;r<t.byteLength;r++)e.push(t[r]);return e.join(".")},Es=function(t){if(t.byteLength!==16)throw new P("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 P(`Invalid IPv6 address "${r}"`)}};function vs(t){try{let e=new URL(`http://[${t}]`);return e.hostname.substring(1,e.hostname.length-1)}catch{throw new P(`Invalid IPv6 address "${t}"`)}}var Rn=Object.values(_t).map(t=>t.decoder),fu=(function(){let t=Rn[0].or(Rn[1]);return Rn.slice(2).forEach(e=>t=t.or(e)),t})();function _s(t){return fu.decode(t)}function Ss(t){return e=>t.encoder.encode(e)}function lu(t){if(parseInt(t).toString()!==t)throw new ge("Value must be an integer")}function du(t){if(t<0)throw new ge("Value must be a positive integer, or zero")}function hu(t){return e=>{if(e>t)throw new ge(`Value must be smaller than or equal to ${t}`)}}function mu(...t){return e=>{for(let r of t)r(e)}}var Pt=mu(lu,du,hu(65535));var F=-1,Wn=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 gr(`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)}))}},be=new Wn,Yu=[{code:4,name:"ip4",size:32,valueToBytes:qn,bytesToValue:xs,validate:t=>{if(!Se(t))throw new ge(`Invalid IPv4 address "${t}"`)}},{code:6,name:"tcp",size:16,valueToBytes:Ve,bytesToValue:ct,validate:Pt},{code:273,name:"udp",size:16,valueToBytes:Ve,bytesToValue:ct,validate:Pt},{code:33,name:"dccp",size:16,valueToBytes:Ve,bytesToValue:ct,validate:Pt},{code:41,name:"ip6",size:128,valueToBytes:ws,bytesToValue:Es,stringToValue:vs,validate:t=>{if(!Ie(t))throw new ge(`Invalid IPv6 address "${t}"`)}},{code:42,name:"ip6zone",size:F},{code:43,name:"ipcidr",size:8,bytesToValue:zn("base10"),valueToBytes:Vn("base10")},{code:53,name:"dns",size:F},{code:54,name:"dns4",size:F},{code:55,name:"dns6",size:F},{code:56,name:"dnsaddr",size:F},{code:132,name:"sctp",size:16,valueToBytes:Ve,bytesToValue:ct,validate:Pt},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:F,stringToValue:t=>decodeURIComponent(t),valueToString:t=>encodeURIComponent(t)},{code:421,name:"p2p",aliases:["ipfs"],size:F,bytesToValue:zn("base58btc"),valueToBytes:t=>t.startsWith("Q")||t.startsWith("1")?Vn("base58btc")(t):Ye.parse(t).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:jn,valueToBytes:bs},{code:445,name:"onion3",size:296,bytesToValue:jn,valueToBytes:ys},{code:446,name:"garlic64",size:F},{code:447,name:"garlic32",size:F},{code:448,name:"tls"},{code:449,name:"sni",size:F},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:F,bytesToValue:Ss(cn),valueToBytes:_s},{code:480,name:"http"},{code:481,name:"http-path",size:F,stringToValue:t=>`/${decodeURIComponent(t)}`,valueToString:t=>encodeURIComponent(t.substring(1))},{code:443,name:"https"},{code:477,name:"ws"},{code:478,name:"wss"},{code:479,name:"p2p-websocket-star"},{code:277,name:"p2p-stardust"},{code:275,name:"p2p-webrtc-star"},{code:276,name:"p2p-webrtc-direct"},{code:280,name:"webrtc-direct"},{code:281,name:"webrtc"},{code:290,name:"p2p-circuit"},{code:777,name:"memory",size:F}];Yu.forEach(t=>{be.addProtocol(t)});function As(t){let e=[],r=0;for(;r<t.length;){let n=pe(t,r),o=be.getProtocol(n),s=M(n),i=Zu(o,t,r+s),a=0;i>0&&o.size===F&&(a=M(i));let u=s+a+i,l={code:n,name:o.name,bytes:t.subarray(r,r+u)};if(i>0){let f=r+s+a,d=t.subarray(f,f+i);l.value=o.bytesToValue?.(d)??Be(d)}e.push(l),r+=u}return e}function Ts(t){let e=0,r=[];for(let n of t){if(n.bytes==null){let o=be.getProtocol(n.code),s=M(n.code),i,a=0,u=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??T(n.value),a=i.byteLength,o.size===F&&(u=M(a)));let l=new Uint8Array(s+u+a),f=0;nr(n.code,l,f),f+=s,i!=null&&(o.size===F&&(nr(a,l,f),f+=u),l.set(i,f)),n.bytes=l}r.push(n.bytes),e+=n.bytes.byteLength}return Ee(r,e)}function Ds(t){if(t.charAt(0)!=="/")throw new P('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=be.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 P(`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 P(`Component ${o} was missing value`);l.value=u.stringToValue?.(n)??n}e.push(l),n="",o="",r="protocol"}}}if(o!==""&&n!=="")throw new P("Incomplete multiaddr");return e}function ks(t){return`/${t.flatMap(e=>{if(e.value==null)return e.name;let r=be.getProtocol(e.code);if(r==null)throw new P(`Unknown protocol code ${e.code}`);return[e.name,r.valueToString?.(e.value)??e.value]}).join("/")}`}function Zu(t,e,r){return t.size==null||t.size===0?0:t.size>0?t.size/8:pe(e,r)}var ef=Symbol.for("nodejs.util.inspect.custom"),Gn=Symbol.for("@multiformats/multiaddr");function tf(t){if(t==null&&(t="/"),Fs(t))return t.getComponents();if(t instanceof Uint8Array)return As(t);if(typeof t=="string")return t=t.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),t===""&&(t="/"),Ds(t);if(Array.isArray(t))return t;throw new P("Must be a string, Uint8Array, Component[], or another Multiaddr")}var br=class t{[Gn]=!0;#e;#t;#r;constructor(e="/",r={}){this.#e=tf(e),r.validate!==!1&&rf(this)}get bytes(){return this.#r==null&&(this.#r=Ts(this.#e)),this.#r}toString(){return this.#t==null&&(this.#t=ks(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 Ze(this.bytes,e.bytes)}[ef](){return`Multiaddr(${this.toString()})`}};function rf(t){t.getComponents().forEach(e=>{let r=be.getProtocol(e.code);e.value!=null&&r.validate?.(e.value)})}function Fs(t){return!!t?.[Gn]}function Ae(t){return new br(t)}function Bs(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),Ae(`/${n.join("/")}`)}function nf(t,e){if(t==null)return[];let r=q(t);return[Bs(r,e)]}function of(t){return Ie(t)?ur("2000::/3",t):!1}function sf(t,e){if(typeof t!="string")throw new R(`invalid ip provided: ${t}`);if(typeof e=="string"&&(e=parseInt(e)),isNaN(e))throw new R(`invalid port provided: ${e}`);if(Se(t))return Ae(`/ip4/${t}/tcp/${e}`);if(Ie(t))return Ae(`/ip6/${t}/tcp/${e}`);throw new R(`invalid ip:port for creating a multiaddr: ${t}:${e}`)}function af(t){return t==null||typeof t?.[Symbol.asyncIterator]!="function"?!1:typeof t.next=="function"}function cf(t){return t==null||typeof t?.[Symbol.iterator]!="function"?!1:typeof t.next=="function"}var Hn=class{readNext;haveNext;ended;nextResult;error;constructor(){this.ended=!1,this.readNext=te(),this.haveNext=te()}[Symbol.asyncIterator](){return this}async next(){if(this.nextResult==null&&await this.haveNext.promise,this.nextResult==null)throw new Error("HaveNext promise resolved but nextResult was undefined");let e=this.nextResult;return this.nextResult=void 0,this.readNext.resolve(),this.readNext=te(),e}async throw(e){return this.ended=!0,this.error=e,e!=null&&(this.haveNext.promise.catch(()=>{}),this.haveNext.reject(e)),{done:!0,value:void 0}}async return(){let e={done:!0,value:void 0};return this.ended=!0,this.nextResult=e,this.haveNext.resolve(),e}async push(e,r){await this._push(e,r)}async end(e,r){e!=null?await this.throw(e):await this._push(void 0,r)}async _push(e,r){if(e!=null&&this.ended)throw this.error??new Error("Cannot push value onto an ended pushable");for(;this.nextResult!=null;)await this.readNext.promise;e!=null?this.nextResult={done:!1,value:e}:(this.ended=!0,this.nextResult={done:!0,value:void 0}),this.haveNext.resolve(),this.haveNext=te(),await k(this.readNext.promise,r?.signal,r)}};function Ns(){return new Hn}function uf(t){return t[Symbol.asyncIterator]!=null}async function ff(t,e,r){try{await Promise.all(t.map(async n=>{for await(let o of n)await e.push(o,{signal:r}),r.throwIfAborted()})),await e.end(void 0,{signal:r})}catch(n){await e.end(n,{signal:r}).catch(()=>{})}}async function*lf(t){let e=new AbortController,r=Ns();ff(t,r,e.signal).catch(()=>{});try{yield*r}finally{e.abort()}}function*df(t){for(let e of t)yield*e}function hf(...t){let e=[];for(let r of t)uf(r)||e.push(r);return e.length===t.length?df(e):lf(t)}var Ps=hf;function Us(t,...e){if(t==null)throw new Error("Empty pipeline");if(Xn(t)){let n=t;t=()=>n.source}else if(Os(t)||Ms(t)){let n=t;t=()=>n}let r=[t,...e];if(r.length>1&&Xn(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++)Xn(r[n])&&(r[n]=pf(r[n]));return mf(...r)}var mf=(...t)=>{let e;for(;t.length>0;)e=t.shift()(e);return e},Ms=t=>t?.[Symbol.asyncIterator]!=null,Os=t=>t?.[Symbol.iterator]!=null,Xn=t=>t==null?!1:t.sink!=null&&t.source!=null,pf=t=>e=>{let r=t.sink(e);if(r?.then!=null){let n=ue({objectMode:!0});r.then(()=>{n.end()},i=>{n.end(i)});let o,s=t.source;if(Ms(s))o=async function*(){yield*s,n.end()};else if(Os(s))o=function*(){yield*s,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return Ps(n,o())}return t.source};var gf=4194304,Ut=class extends Error{static name="UnwrappedError";name="UnwrappedError"},ut=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},yr=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},wr=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function bf(t){return typeof t?.closeRead=="function"}function yf(t){return typeof t?.close=="function"}function Qn(t){return bf(t)?t.remoteWriteStatus!=="writable"&&t.readBufferLength===0:yf(t)?t.status!=="open":!1}function wf(t){return t?.addEventListener!=null&&t?.removeEventListener!=null&&t?.send!=null&&t?.push!=null&&t?.log!=null}function $s(t,e){let r=e?.maxBufferSize??gf,n=new A,o,s=!1;if(!wf(t))throw new R("Argument should be a Stream or a Multiaddr");let i=f=>{if(n.append(f.data),n.byteLength>r){let d=n.byteLength;n.consume(n.byteLength),o?.reject(new Error(`Read buffer overflow - ${d} > ${r}`))}o?.resolve()};t.addEventListener("message",i);let a=f=>{f.error!=null?o?.reject(f.error):o?.resolve()};t.addEventListener("close",a);let u=()=>{o?.resolve()};t.addEventListener("remoteCloseWrite",u);let l={readBuffer:n,async read(f){if(s===!0)throw new Ut("Stream was unwrapped");if(Qn(t)){if(n.byteLength===0&&f?.bytes==null)return null;if(f?.bytes!=null&&n.byteLength<f.bytes)throw t.log.error("closed after reading %d/%d bytes",n.byteLength,f.bytes),new Ce(`Unexpected EOF - stream closed after reading ${n.byteLength}/${f.bytes} bytes`)}let d=f?.bytes??1;for(o=Promise.withResolvers();;){if(n.byteLength>=d){o.resolve();break}if(await k(o.promise,f?.signal),Qn(t)){if(n.byteLength===0&&f?.bytes==null)return null;break}o=Promise.withResolvers()}let p=f?.bytes??n.byteLength;if(n.byteLength<p){if(Qn(t))throw t.log.error("closed while reading %d/%d bytes",n.byteLength,p),new Ce(`Unexpected EOF - stream closed while reading ${n.byteLength}/${p} bytes`);return l.read(f)}let y=n.sublist(0,p);return n.consume(p),y},async write(f,d){if(s===!0)throw new Ut("Stream was unwrapped");t.send(f)||await D(t,"drain",{signal:d?.signal,rejectionEvents:["close"]})},unwrap(){return s||(s=!0,t.removeEventListener("message",i),t.removeEventListener("close",a),t.removeEventListener("remoteCloseWrite",u),n.byteLength>0&&(t.log("stream unwrapped with %d unread bytes",n.byteLength),t.push(n))),t}};return l}function Rs(t,e={}){let r=$s(t,e);e.maxDataLength!=null&&e.maxLengthLength==null&&(e.maxLengthLength=M(e.maxDataLength));let n=e?.lengthDecoder??pe,o=e?.lengthEncoder??or;return{async read(i){let a=-1,u=new A;for(;;){let f=await r.read({...i,bytes:1});if(f==null)break;u.append(f);try{a=n(u)}catch(d){if(d instanceof RangeError)continue;throw d}if(a<0)throw new ut("Invalid message length");if(e?.maxLengthLength!=null&&u.byteLength>e.maxLengthLength)throw new wr(`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 Ce(`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 Ce(`Unexpected EOF - read ${l.byteLength}/${a} bytes before the stream closed`);return l},async write(i,a){await r.write(new A(o(i.byteLength),i),a)},async writeV(i,a){let u=new A(...i.flatMap(l=>[o(l.byteLength),l]));await r.write(u,a)},unwrap(){return r.unwrap()}}}function xf(t,e){let r=Rs(t,e),n={read:async(o,s)=>{let i=await r.read(s);return o.decode(i)},write:async(o,s,i)=>{await r.write(s.encode(o),i)},writeV:async(o,s,i)=>{await r.writeV(o.map(a=>s.encode(a)),i)},pb:o=>({read:async s=>n.read(o,s),write:async(s,i)=>n.write(s,o,i),writeV:async(s,i)=>n.writeV(s,o,i),unwrap:()=>n}),unwrap:()=>r.unwrap()};return n}async function Kn(t,e){let r=t.log.newScope("echo"),n=Date.now(),o=0;try{for await(let s of t)o+=s.byteLength,t.send(s)||(t.pause(),await D(t,"drain",{rejectionEvents:["close"],...e}),t.resume());r("echoed %d bytes in %dms",o,Date.now()-n),await t.close(e)}catch(s){t.abort(s)}}function Ef(t){return t?.addEventListener!=null}function zs(t){let e=ue(),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([D(t,"drain",{rejectionEvents:["close"]})])),l===!0))break}await t.close()}}}function vf(...t){let e=t.map(r=>Ef(r)?zs(r):r);return Us(...e)}var _f=1024*1024*4,Sf=1024*1024*4,Jn=class{buffer;maxBufferSize;lengthDecoder;maxDataLength;encodingLength;constructor(e={}){this.buffer=new A,this.maxBufferSize=e.maxBufferSize??_f,this.maxDataLength=e.maxDataLength??Sf,this.lengthDecoder=e.lengthDecoder??pe,this.encodingLength=e.encodingLength??M}*decode(e){if(this.buffer.append(e),this.buffer.byteLength>this.maxBufferSize)throw new R(`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 ut("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 If(t){return!!(t.startsWith("169.254.")||t.toLowerCase().startsWith("fe80"))}var Lf=["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 Yn(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=Cf(t);return r||"Object"}function Cf(t){let e=Object.prototype.toString.call(t).slice(8,-1);if(Lf.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 Mt=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",Af=new TextEncoder;function xr(t){return Mt&&globalThis.Buffer.isBuffer(t)}function Ot(t){return t instanceof Uint8Array?xr(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):t:Uint8Array.from(t)}var Tf=24,Df=200,Er=Mt?t=>t.length>=Tf?globalThis.Buffer.from(t):Vs(t):t=>t.length>=Df?Af.encode(t):Vs(t),fe=t=>Uint8Array.from(t),js=Mt?(t,e,r)=>xr(t)?new Uint8Array(t.subarray(e,r)):t.slice(e,r):(t,e,r)=>t.slice(e,r),qs=Mt?(t,e)=>(t=t.map(r=>r instanceof Uint8Array?r:globalThis.Buffer.from(r)),Ot(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},Ws=Mt?t=>globalThis.Buffer.allocUnsafe(t):t=>new Uint8Array(t);function vr(t,e){if(xr(t)&&xr(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 Vs(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 kf=256,$t=class{constructor(e=kf){this.chunkSize=e,this.cursor=0,this.maxCursor=-1,this.chunks=[],this._initReuseChunk=null}reset(){this.cursor=0,this.maxCursor=-1,this.chunks.length&&(this.chunks=[]),this._initReuseChunk!==null&&(this.chunks.push(this._initReuseChunk),this.maxCursor=this._initReuseChunk.length-1)}push(e){let r=this.chunks[this.chunks.length-1];if(this.cursor+e.length<=this.maxCursor+1){let o=r.length-(this.maxCursor-this.cursor)-1;r.set(e,o)}else{if(r){let o=r.length-(this.maxCursor-this.cursor)-1;o<r.length&&(this.chunks[this.chunks.length-1]=r.subarray(0,o),this.maxCursor=this.cursor-1)}e.length<64&&e.length<this.chunkSize?(r=Ws(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=js(n,0,this.cursor)}else r=qs(this.chunks,this.cursor);return e&&this.reset(),r}},_r=class{constructor(e){this.dest=e,this.cursor=0,this.chunks=[e]}reset(){this.cursor=0}push(e){if(this.cursor+e.length>this.dest.length)throw new Error("write out of bounds, destination buffer is too small");this.dest.set(e,this.cursor),this.cursor+=e.length}toBytes(e=!1){let r=this.dest.subarray(0,this.cursor);return e&&this.reset(),r}};var g="CBOR decode error:",Sr="CBOR encode error:",Rt=[];Rt[23]=1;Rt[24]=2;Rt[25]=3;Rt[26]=5;Rt[27]=9;function ye(t,e,r){if(t.length-e<r)throw new Error(`${g} not enough data for type`)}var B=[24,256,65536,4294967296,BigInt("18446744073709551616")];function W(t,e,r){ye(t,e,1);let n=t[e];if(r.strict===!0&&n<B[0])throw new Error(`${g} integer encoded in more bytes than necessary (strict decode)`);return n}function G(t,e,r){ye(t,e,2);let n=t[e]<<8|t[e+1];if(r.strict===!0&&n<B[1])throw new Error(`${g} integer encoded in more bytes than necessary (strict decode)`);return n}function H(t,e,r){ye(t,e,4);let n=t[e]*16777216+(t[e+1]<<16)+(t[e+2]<<8)+t[e+3];if(r.strict===!0&&n<B[2])throw new Error(`${g} integer encoded in more bytes than necessary (strict decode)`);return n}function X(t,e,r){ye(t,e,8);let n=t[e]*16777216+(t[e+1]<<16)+(t[e+2]<<8)+t[e+3],o=t[e+4]*16777216+(t[e+5]<<16)+(t[e+6]<<8)+t[e+7],s=(BigInt(n)<<BigInt(32))+BigInt(o);if(r.strict===!0&&s<B[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 Gs(t,e,r,n){return new m(c.uint,W(t,e+1,n),2)}function Hs(t,e,r,n){return new m(c.uint,G(t,e+1,n),3)}function Xs(t,e,r,n){return new m(c.uint,H(t,e+1,n),5)}function Qs(t,e,r,n){return new m(c.uint,X(t,e+1,n),9)}function K(t,e){return S(t,0,e.value)}function S(t,e,r){if(r<B[0]){let n=Number(r);t.push([e|n])}else if(r<B[1]){let n=Number(r);t.push([e|24,n])}else if(r<B[2]){let n=Number(r);t.push([e|25,n>>>8,n&255])}else if(r<B[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<B[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`)}}K.encodedSize=function(e){return S.encodedSize(e.value)};S.encodedSize=function(e){return e<B[0]?1:e<B[1]?2:e<B[2]?3:e<B[3]?5:9};K.compareTokens=function(e,r){return e.value<r.value?-1:e.value>r.value?1:0};function Ks(t,e,r,n){return new m(c.negint,-1-W(t,e+1,n),2)}function Js(t,e,r,n){return new m(c.negint,-1-G(t,e+1,n),3)}function Ys(t,e,r,n){return new m(c.negint,-1-H(t,e+1,n),5)}var Zn=BigInt(-1),Zs=BigInt(1);function ei(t,e,r,n){let o=X(t,e+1,n);if(typeof o!="bigint"){let s=-1-o;if(s>=Number.MIN_SAFE_INTEGER)return new 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,Zn-BigInt(o),9)}function Ir(t,e){let r=e.value,n=typeof r=="bigint"?r*Zn-Zs:r*-1-1;S(t,e.type.majorEncoded,n)}Ir.encodedSize=function(e){let r=e.value,n=typeof r=="bigint"?r*Zn-Zs:r*-1-1;return n<B[0]?1:n<B[1]?2:n<B[2]?3:n<B[3]?5:9};Ir.compareTokens=function(e,r){return e.value<r.value?1:e.value>r.value?-1:0};function zt(t,e,r,n){ye(t,e,r+n);let o=t.slice(e+r,e+r+n);return new m(c.bytes,o,r+n)}function ti(t,e,r,n){return zt(t,e,1,r)}function ri(t,e,r,n){return zt(t,e,2,W(t,e+1,n))}function ni(t,e,r,n){return zt(t,e,3,G(t,e+1,n))}function oi(t,e,r,n){return zt(t,e,5,H(t,e+1,n))}function si(t,e,r,n){let o=X(t,e+1,n);if(typeof o=="bigint")throw new Error(`${g} 64-bit integer bytes lengths not supported`);return zt(t,e,9,o)}function Lr(t){return t.encodedBytes===void 0&&(t.encodedBytes=c.equals(t.type,c.string)?Er(t.value):t.value),t.encodedBytes}function ft(t,e){let r=Lr(e);S(t,e.type.majorEncoded,r.length),t.push(r)}ft.encodedSize=function(e){let r=Lr(e);return S.encodedSize(r.length)+r.length};ft.compareTokens=function(e,r){return Bf(Lr(e),Lr(r))};function Bf(t,e){return t.length<e.length?-1:t.length>e.length?1:vr(t,e)}var ii=new TextDecoder,Pf=32;function Uf(t,e,r){if(r-e<Pf){let o="";for(let s=e;s<r;s++){let i=t[s];if(i&128)return ii.decode(t.subarray(e,r));o+=String.fromCharCode(i)}return o}return ii.decode(t.subarray(e,r))}function Vt(t,e,r,n,o){let s=r+n;ye(t,e,s);let i=new m(c.string,Uf(t,e+r,e+s),s);return o.retainStringBytes===!0&&(i.byteValue=t.slice(e+r,e+s)),i}function ai(t,e,r,n){return Vt(t,e,1,r,n)}function ci(t,e,r,n){return Vt(t,e,2,W(t,e+1,n),n)}function ui(t,e,r,n){return Vt(t,e,3,G(t,e+1,n),n)}function fi(t,e,r,n){return Vt(t,e,5,H(t,e+1,n),n)}function li(t,e,r,n){let o=X(t,e+1,n);if(typeof o=="bigint")throw new Error(`${g} 64-bit integer string lengths not supported`);return Vt(t,e,9,o,n)}var di=ft;function lt(t,e,r,n){return new m(c.array,n,r)}function hi(t,e,r,n){return lt(t,e,1,r)}function mi(t,e,r,n){return lt(t,e,2,W(t,e+1,n))}function pi(t,e,r,n){return lt(t,e,3,G(t,e+1,n))}function gi(t,e,r,n){return lt(t,e,5,H(t,e+1,n))}function bi(t,e,r,n){let o=X(t,e+1,n);if(typeof o=="bigint")throw new Error(`${g} 64-bit integer array lengths not supported`);return lt(t,e,9,o)}function yi(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${g} indefinite length items not allowed`);return lt(t,e,1,1/0)}function Cr(t,e){S(t,c.array.majorEncoded,e.value)}Cr.compareTokens=K.compareTokens;Cr.encodedSize=function(e){return S.encodedSize(e.value)};function dt(t,e,r,n){return new m(c.map,n,r)}function wi(t,e,r,n){return dt(t,e,1,r)}function xi(t,e,r,n){return dt(t,e,2,W(t,e+1,n))}function Ei(t,e,r,n){return dt(t,e,3,G(t,e+1,n))}function vi(t,e,r,n){return dt(t,e,5,H(t,e+1,n))}function _i(t,e,r,n){let o=X(t,e+1,n);if(typeof o=="bigint")throw new Error(`${g} 64-bit integer map lengths not supported`);return dt(t,e,9,o)}function Si(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${g} indefinite length items not allowed`);return dt(t,e,1,1/0)}function Ar(t,e){S(t,c.map.majorEncoded,e.value)}Ar.compareTokens=K.compareTokens;Ar.encodedSize=function(e){return S.encodedSize(e.value)};function Ii(t,e,r,n){return new m(c.tag,r,1)}function Li(t,e,r,n){return new m(c.tag,W(t,e+1,n),2)}function Ci(t,e,r,n){return new m(c.tag,G(t,e+1,n),3)}function Ai(t,e,r,n){return new m(c.tag,H(t,e+1,n),5)}function Ti(t,e,r,n){return new m(c.tag,X(t,e+1,n),9)}function Tr(t,e){S(t,c.tag.majorEncoded,e.value)}Tr.compareTokens=K.compareTokens;Tr.encodedSize=function(e){return S.encodedSize(e.value)};var eo=20,to=21,ro=22,no=23;function Di(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 ki(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 oo(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 Fi(t,e,r,n){return oo(so(t,e+1),3,n)}function Bi(t,e,r,n){return oo(io(t,e+1),5,n)}function Ni(t,e,r,n){return oo(Oi(t,e+1),9,n)}function jt(t,e,r){let n=e.value;if(n===!1)t.push([c.float.majorEncoded|eo]);else if(n===!0)t.push([c.float.majorEncoded|to]);else if(n===null)t.push([c.float.majorEncoded|ro]);else if(n===void 0)t.push([c.float.majorEncoded|no]);else{let o,s=!1;(!r||r.float64!==!0)&&(Ui(n),o=so(ne,1),n===o||Number.isNaN(n)?(ne[0]=249,t.push(ne.slice(0,3)),s=!0):(Mi(n),o=io(ne,1),n===o&&(ne[0]=250,t.push(ne.slice(0,5)),s=!0))),s||(zf(n),o=Oi(ne,1),ne[0]=251,t.push(ne.slice(0,9)))}}jt.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){Ui(n);let o=so(ne,1);if(n===o||Number.isNaN(n))return 3;if(Mi(n),o=io(ne,1),n===o)return 5}return 9};var Pi=new ArrayBuffer(9),J=new DataView(Pi,1),ne=new Uint8Array(Pi,0);function Ui(t){if(t===1/0)J.setUint16(0,31744,!1);else if(t===-1/0)J.setUint16(0,64512,!1);else if(Number.isNaN(t))J.setUint16(0,32256,!1);else{J.setFloat32(0,t);let e=J.getUint32(0),r=(e&2139095040)>>23,n=e&8388607;if(r===255)J.setUint16(0,31744,!1);else if(r===0)J.setUint16(0,(e&2147483648)>>16|n>>13,!1);else{let o=r-127;o<-24?J.setUint16(0,0):o<-14?J.setUint16(0,(e&2147483648)>>16|1<<24+o,!1):J.setUint16(0,(e&2147483648)>>16|o+15<<10|n>>13,!1)}}}function so(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 Mi(t){J.setFloat32(0,t,!1)}function io(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 zf(t){J.setFloat64(0,t,!1)}function Oi(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)}jt.compareTokens=K.compareTokens;function E(t,e,r){throw new Error(`${g} encountered invalid minor (${r}) for major ${t[e]>>>5}`)}function Dr(t){return()=>{throw new Error(`${g} ${t}`)}}var h=[];for(let t=0;t<=23;t++)h[t]=E;h[24]=Gs;h[25]=Hs;h[26]=Xs;h[27]=Qs;h[28]=E;h[29]=E;h[30]=E;h[31]=E;for(let t=32;t<=55;t++)h[t]=E;h[56]=Ks;h[57]=Js;h[58]=Ys;h[59]=ei;h[60]=E;h[61]=E;h[62]=E;h[63]=E;for(let t=64;t<=87;t++)h[t]=ti;h[88]=ri;h[89]=ni;h[90]=oi;h[91]=si;h[92]=E;h[93]=E;h[94]=E;h[95]=Dr("indefinite length bytes/strings are not supported");for(let t=96;t<=119;t++)h[t]=ai;h[120]=ci;h[121]=ui;h[122]=fi;h[123]=li;h[124]=E;h[125]=E;h[126]=E;h[127]=Dr("indefinite length bytes/strings are not supported");for(let t=128;t<=151;t++)h[t]=hi;h[152]=mi;h[153]=pi;h[154]=gi;h[155]=bi;h[156]=E;h[157]=E;h[158]=E;h[159]=yi;for(let t=160;t<=183;t++)h[t]=wi;h[184]=xi;h[185]=Ei;h[186]=vi;h[187]=_i;h[188]=E;h[189]=E;h[190]=E;h[191]=Si;for(let t=192;t<=215;t++)h[t]=Ii;h[216]=Li;h[217]=Ci;h[218]=Ai;h[219]=Ti;h[220]=E;h[221]=E;h[222]=E;h[223]=E;for(let t=224;t<=243;t++)h[t]=Dr("simple values are not supported");h[244]=E;h[245]=E;h[246]=E;h[247]=Di;h[248]=Dr("simple values are not supported");h[249]=Fi;h[250]=Bi;h[251]=Ni;h[252]=E;h[253]=E;h[254]=E;h[255]=ki;var oe=[];for(let t=0;t<24;t++)oe[t]=new m(c.uint,t,1);for(let t=-1;t>=-24;t--)oe[31-t]=new m(c.negint,t,1);oe[64]=new m(c.bytes,new Uint8Array(0),1);oe[96]=new m(c.string,"",1);oe[128]=new m(c.array,0,1);oe[160]=new m(c.map,0,1);oe[244]=new m(c.false,!1,1);oe[245]=new m(c.true,!0,1);oe[246]=new m(c.null,null,1);function ao(t){switch(t.type){case c.false:return fe([244]);case c.true:return fe([245]);case c.null:return fe([246]);case c.bytes:return t.value.length?void 0:fe([64]);case c.string:return t.value===""?fe([96]):void 0;case c.array:return t.value===0?fe([128]):void 0;case c.map:return t.value===0?fe([160]):void 0;case c.uint:return t.value<24?fe([Number(t.value)]):void 0;case c.negint:if(t.value>=-24)return fe([31-Number(t.value)])}}var jf={float64:!1,mapSorter:Gf,quickEncodeToken:ao},ji=Object.freeze({float64:!0,mapSorter:Hf,quickEncodeToken:ao});function qf(){let t=[];return t[c.uint.major]=K,t[c.negint.major]=Ir,t[c.bytes.major]=ft,t[c.string.major]=di,t[c.array.major]=Cr,t[c.map.major]=Ar,t[c.tag.major]=Tr,t[c.float.major]=jt,t}var mt=qf(),kr=new $t,Wt=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(`${Sr} object contains circular references`);return new t(r,e)}},Te={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)},le={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?Te.true:Te.false},null(t,e,r,n){return Te.null},undefined(t,e,r,n){return Te.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?[Te.emptyArray,new m(c.break)]:Te.emptyArray;n=Wt.createCheck(n,t);let o=[],s=0;for(let i of t)o[s++]=ht(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=Wt.createCheck(n,t);let u=!o&&r.ignoreUndefinedProperties,l=0;for(let f of s){let d=o?t.get(f):t[f];u&&d===void 0||(a[l++]=[ht(f,r,n),ht(d,r,n)])}l<i&&(a.length=l)}return a?.length?(Wf(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?[Te.emptyMap,new m(c.break)]:Te.emptyMap},Tagged(t,e,r,n){return[new m(c.tag,t.tag),ht(t.value,r,n)]}};le.Map=le.Object;le.Buffer=le.Uint8Array;for(let t of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))le[`${t}Array`]=le.DataView;function ht(t,e={},r){let n=Yn(t),o=e&&e.typeEncoders&&e.typeEncoders[n]||le[n];if(typeof o=="function"){let i=o(t,n,e,r);if(i!=null)return i}let s=le[n];if(!s)throw new Error(`${Sr} unsupported type: ${n}`);return s(t,n,e,r)}function Wf(t,e){e.mapSorter&&t.sort(e.mapSorter)}function Gf(t,e){let r=Array.isArray(t[0])?t[0][0]:t[0],n=Array.isArray(e[0])?e[0][0]:e[0];if(r.type!==n.type)return r.type.compare(n.type);let o=r.type.major,s=mt[o].compareTokens(r,n);return s===0&&console.warn("WARNING: complex key types used, CBOR key sorting guarantees are gone"),s}function Hf(t,e){if(t[0]instanceof m&&e[0]instanceof m){let r=t[0],n=e[0];return r._keyBytes||(r._keyBytes=$i(r.value)),n._keyBytes||(n._keyBytes=$i(n.value)),vr(r._keyBytes,n._keyBytes)}throw new Error("rfc8949MapSorter: complex key types are not supported yet")}function $i(t){return Wi(t,mt,ji)}function qt(t,e,r,n){if(Array.isArray(e))for(let o of e)qt(t,o,r,n);else r[e.type.major](t,e,n)}var Ri=c.uint.majorEncoded,zi=c.negint.majorEncoded,Xf=c.bytes.majorEncoded,Qf=c.string.majorEncoded,Vi=c.array.majorEncoded,Kf=c.float.majorEncoded|eo,Jf=c.float.majorEncoded|to,Yf=c.float.majorEncoded|ro,Zf=c.float.majorEncoded|no,el=BigInt(-1),tl=BigInt(1);function rl(t){return t.addBreakTokens!==!0}function qi(t,e,r,n){let o=Yn(e),s=r.typeEncoders&&r.typeEncoders[o];if(s){let i=s(e,o,r,n);if(i!=null){qt(t,i,mt,r);return}}switch(o){case"null":t.push([Yf]);return;case"undefined":t.push([Zf]);return;case"boolean":t.push([e?Jf:Kf]);return;case"number":!Number.isInteger(e)||!Number.isSafeInteger(e)?jt(t,new m(c.float,e),r):e>=0?S(t,Ri,e):S(t,zi,e*-1-1);return;case"bigint":e>=BigInt(0)?S(t,Ri,e):S(t,zi,e*el-tl);return;case"string":{let i=Er(e);S(t,Qf,i.length),t.push(i);return}case"Uint8Array":S(t,Xf,e.length),t.push(e);return;case"Array":if(!e.length){t.push([Vi]);return}n=Wt.createCheck(n,e),S(t,Vi,e.length);for(let i of e)qi(t,i,r,n);return;case"Object":case"Map":{let i=le.Object(e,o,r,n);qt(t,i,mt,r)}return;default:{let i=le[o];if(!i)throw new Error(`${Sr} unsupported type: ${o}`);let a=i(e,o,r,n);qt(t,a,mt,r)}}}function Wi(t,e,r,n){let o=n instanceof Uint8Array,s=o?new _r(n):kr,i=ht(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 $t(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():Ot(s.chunks[0])}}return s.reset(),qt(s,i,e,r),s.toBytes(!0)}function co(t,e){return e=Object.assign({},jf,e),rl(e)?(kr.reset(),qi(kr,t,e,void 0),kr.toBytes(!0)):Wi(t,mt,e)}var nl={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},Fr=class{constructor(e,r={}){this._pos=0,this.data=e,this.options=r}pos(){return this._pos}done(){return this._pos>=this.data.length}next(){let e=this.data[this._pos],r=oe[e];if(r===void 0){let n=h[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}},De=Symbol.for("DONE"),pt=Symbol.for("BREAK");function ol(t,e,r){let n=[];for(let o=0;o<t.value;o++){let s=ke(e,r);if(s===pt){if(t.value===1/0)break;throw new Error(`${g} got unexpected break to lengthed array`)}if(s===De)throw new Error(`${g} found array but not enough entries (got ${o}, expected ${t.value})`);n[o]=s}return n}function sl(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=ke(e,r);if(u===pt){if(t.value===1/0)break;throw new Error(`${g} got unexpected break to lengthed map`)}if(u===De)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=ke(e,r);if(l===De)throw new Error(`${g} found map but not enough entries (got ${a} [no value], expected ${t.value})`);n?i.set(u,l):s[u]=l}return n?i:s}function*il(t,e,r){for(let n=0;n<t.value;n++){let o=ke(e,r);if(o===pt){if(t.value===1/0)break;throw new Error(`${g} got unexpected break to lengthed map`)}if(o===De)throw new Error(`${g} found map but not enough entries (got ${n} [no key], expected ${t.value})`);let s=ke(e,r);if(s===De)throw new Error(`${g} found map but not enough entries (got ${n} [no value], expected ${t.value})`);yield[o,s]}}function al(t,e){let r=!1,n=function(){if(r)throw new Error(`${g} tag decode() may only be called once`);r=!0;let o=ke(t,e);if(o===De)throw new Error(`${g} tag content missing`);if(o===pt)throw new Error(`${g} got unexpected break in tag content`);return o};return n.entries=function(){if(r)throw new Error(`${g} tag decode() may only be called once`);r=!0;let o=t.next();if(!c.equals(o.type,c.map))throw new Error(`${g} entries() requires map content, got ${o.type.name}`);let s=[];for(let i of il(o,t,e))s.push(i);return s},Object.defineProperty(n,"_called",{get(){return r},enumerable:!1}),n}function ke(t,e){if(t.done())return De;let r=t.next();if(c.equals(r.type,c.break))return pt;if(r.type.terminal)return r.value;if(c.equals(r.type,c.array))return ol(r,t,e);if(c.equals(r.type,c.map))return sl(r,t,e);if(c.equals(r.type,c.tag)){if(e.tags&&typeof e.tags[r.value]=="function"){let n=al(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 Gi(t,e){if(!(t instanceof Uint8Array))throw new Error(`${g} data to decode must be a Uint8Array`);e=Object.assign({},nl,e);let r=Ot(t),n=e.tokenizer||new Fr(r,e),o=ke(n,e);if(o===De)throw new Error(`${g} did not find any content to decode`);if(o===pt)throw new Error(`${g} got unexpected break`);return[o,t.subarray(n.pos())]}function uo(t,e){let[r,n]=Gi(t,e);if(n.length>0)throw new Error(`${g} too many terminals, data makes no sense`);return r}var Br=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(Br.prototype,Symbol.toStringTag,{value:"Tagged"});var Nr=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},gt=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},Pr=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"},Gt=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};function Ur(t){return t[Symbol.asyncIterator]!=null}function Hi(t,e){if(t.byteLength>e)throw new gt("Message length too long")}var Or=t=>{let e=M(t),r=Z(e);return or(t,r),Or.bytes=e,r};Or.bytes=0;function $r(t,e){e=e??{};let r=e.lengthEncoder??Or,n=e?.maxDataLength??4194304;function*o(s){Hi(s,n);let i=r(s.byteLength);i instanceof Uint8Array?yield i:yield*i,s instanceof Uint8Array?yield s:yield*s}return Ur(t)?(async function*(){for await(let s of t)yield*o(s)})():(function*(){for(let s of t)yield*o(s)})()}$r.single=(t,e)=>{e=e??{};let r=e.lengthEncoder??Or,n=e?.maxDataLength??4194304;return Hi(t,n),new A(r(t.byteLength),t)};var qe;(function(t){t[t.LENGTH=0]="LENGTH",t[t.DATA=1]="DATA"})(qe||(qe={}));var fo=t=>{let e=pe(t);return fo.bytes=M(e),e};fo.bytes=0;function Ht(t,e){let r=new A,n=qe.LENGTH,o=-1,s=e?.lengthDecoder??fo,i=e?.maxLengthLength??8,a=e?.maxDataLength??4194304;function*u(){for(;r.byteLength>0;){if(n===qe.LENGTH)try{if(o=s(r),o<0)throw new Nr("Invalid message length");if(o>a)throw new gt("Message length too long");let l=s.bytes;r.consume(l),e?.onLength!=null&&e.onLength(o),n=qe.DATA}catch(l){if(l instanceof RangeError){if(r.byteLength>i)throw new Pr("Message length length too long");break}throw l}if(n===qe.DATA){if(r.byteLength<o)break;let l=r.sublist(0,o);r.consume(o),e?.onData!=null&&e.onData(l),yield l,n=qe.LENGTH}}}return Ur(t)?(async function*(){for await(let l of t)r.append(l),yield*u();if(r.byteLength>0)throw new Gt("Unexpected end of input")})():(function*(){for(let l of t)r.append(l),yield*u();if(r.byteLength>0)throw new Gt("Unexpected end of input")})()}Ht.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 Ht(n,{...e??{},onLength:s=>{r=s}})};var lo=class extends Re{sendMessage;dataQueue;encoding;constructor(e){super(e),this.sendMessage=e.sendMessage,this.encoding=e.encoding,this.dataQueue=new re({concurrency:1}),this.direction==="outbound"&&this.sendMessage({id:this.id,type:"create",protocol:this.protocol})}sendData(e){let r=this.sendMessage({id:this.id,type:"data",chunk:e.subarray()});return{sentBytes:e.byteLength,canSendMore:r}}sendReset(){this.sendMessage({id:this.id,type:"reset"})}async sendCloseWrite(e){this.sendMessage({id:this.id,type:"closeWrite"}),e?.signal?.throwIfAborted()}async sendCloseRead(e){this.sendMessage({id:this.id,type:"closeRead"}),e?.signal?.throwIfAborted()}sendPause(){this.sendMessage({id:this.id,type:"pause"})}sendResume(){this.sendMessage({id:this.id,type:"resume"})}onRemotePaused(){this.dataQueue.pause()}onRemoteResumed(){this.dataQueue.resume()}},Xi=30,ho=class extends Nt{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)+Xi,this.encoding=r.encoding??"base64",this.input=ue(),this.sendMessage=this.sendMessage.bind(this),this.nextStreamId=this.maConn.direction==="outbound"?0:1,Promise.resolve().then(async()=>{for await(let n of Ht(this.input,{maxDataLength:this.maxMessageSize}))this.onMessage(uo(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=co(e),n=$r.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 lo({...this.streamOptions,...n,id:e,direction:r,log:this.log.newScope(`stream:${r}:${e}`),sendMessage:this.sendMessage,encoding:this.encoding,maxMessageSize:this.maxMessageSize-Xi,protocol:""})}},mo=class{protocol="/mock-muxer/1.0.0";init;constructor(e){this.init=e}createStreamMuxer(e){return new ho(e,{...this.init})}};function Rr(t={}){return new mo(t)}function ll(t,e){if(typeof t=="string")return dl(t);if(typeof t=="number")return pl(t,e);throw Error(`Value provided to ms() must be a string or number. value=${JSON.stringify(t)}`)}var zr=ll;function dl(t){if(typeof t!="string"||t.length===0||t.length>100)throw Error(`Value provided to ms.parse() must be a string with length between 1 and 99. value=${JSON.stringify(t)}`);let e=/^(?<value>-?\d*\.?\d+) *(?<unit>milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|months?|mo|years?|yrs?|y)?$/i.exec(t);if(!e?.groups)return NaN;let{value:r,unit:n="ms"}=e.groups,o=parseFloat(r),s=n.toLowerCase();switch(s){case"years":case"year":case"yrs":case"yr":case"y":return o*315576e5;case"months":case"month":case"mo":return o*26298e5;case"weeks":case"week":case"w":return o*6048e5;case"days":case"day":case"d":return o*864e5;case"hours":case"hour":case"hrs":case"hr":case"h":return o*36e5;case"minutes":case"minute":case"mins":case"min":case"m":return o*6e4;case"seconds":case"second":case"secs":case"sec":case"s":return o*1e3;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return o;default:throw Error(`Unknown unit "${s}" provided to ms.parse(). value=${JSON.stringify(t)}`)}}function hl(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 ml(t){let e=Math.abs(t);return e>=315576e5?We(t,e,315576e5,"year"):e>=26298e5?We(t,e,26298e5,"month"):e>=6048e5?We(t,e,6048e5,"week"):e>=864e5?We(t,e,864e5,"day"):e>=36e5?We(t,e,36e5,"hour"):e>=6e4?We(t,e,6e4,"minute"):e>=1e3?We(t,e,1e3,"second"):`${t} ms`}function pl(t,e){if(typeof t!="number"||!Number.isFinite(t))throw Error("Value provided to ms.format() must be of type number.");return e?.long?ml(t):hl(t)}function We(t,e,r,n){let o=e>=r*1.5;return`${Math.round(t/r)} ${n}${o?"s":""}`}function po(t){r.debug=r,r.default=r,r.coerce=u,r.disable=s,r.enable=o,r.enabled=i,r.humanize=zr,r.destroy=l,Object.keys(t).forEach(f=>{r[f]=t[f]}),r.names=[],r.skips=[],r.formatters={};function e(f){let d=0;for(let p=0;p<f.length;p++)d=(d<<5)-d+f.charCodeAt(p),d|=0;return r.colors[Math.abs(d)%r.colors.length]}r.selectColor=e;function r(f,d){let p,y=null,w,_;function b(...x){if(!b.enabled)return;let I=b,L=Number(new Date),O=L-(p||L);I.diff=O,I.prev=p,I.curr=L,p=L,x[0]=r.coerce(x[0]),typeof x[0]!="string"&&x.unshift("%O");let N=0;x[0]=x[0].replace(/%([a-zA-Z%])/g,($,Y)=>{if($==="%%")return"%";N++;let Fe=r.formatters[Y];if(typeof Fe=="function"){let sa=x[N];$=Fe.call(I,sa),x.splice(N,1),N--}return $}),r.formatArgs.call(I,x),d?.onLog!=null&&d.onLog(...x),(I.log||r.log).apply(I,x)}return b.namespace=f,b.useColors=r.useColors(),b.color=r.selectColor(f),b.extend=n,b.destroy=r.destroy,Object.defineProperty(b,"enabled",{enumerable:!0,configurable:!1,get:()=>y!==null?y:(w!==r.namespaces&&(w=r.namespaces,_=r.enabled(f)),_),set:x=>{y=x}}),typeof r.init=="function"&&r.init(b),b}function n(f,d){let p=r(this.namespace+(typeof d>"u"?":":d)+f);return p.log=this.log,p}function o(f){r.save(f),r.namespaces=f,r.names=[],r.skips=[];let d,p=(typeof f=="string"?f:"").split(/[\s,]+/),y=p.length;for(d=0;d<y;d++)p[d]&&(f=p[d].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(d=>"-"+d)].join(",");return r.enable(""),f}function i(f){if(f[f.length-1]==="*")return!0;let d,p;for(d=0,p=r.skips.length;d<p;d++)if(r.skips[d].test(f))return!1;for(d=0,p=r.names.length;d<p;d++)if(r.names[d].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 Vr=vl(),gl=["#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 bl(){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 yl(t){if(t[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+t[0]+(this.useColors?"%c ":" ")+"+"+zr(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 wl=console.debug??console.log??(()=>{});function xl(t){try{t?Vr?.setItem("debug",t):Vr?.removeItem("debug")}catch{}}function El(){let t;try{t=Vr?.getItem("debug")}catch{}return!t&&typeof globalThis.process<"u"&&"env"in globalThis.process&&(t=globalThis.process.env.DEBUG),t}function vl(){try{return localStorage}catch{}}function _l(t){t.j=function(e){try{return JSON.stringify(e)}catch(r){return"[UnexpectedJSONParseError]: "+r.message}}}var Qi=po({formatArgs:yl,save:xl,load:El,useColors:bl,setupFormatters:_l,colors:gl,storage:Vr,log:wl});var z=Qi;z.formatters.b=t=>t==null?"undefined":Q.baseEncode(t);z.formatters.t=t=>t==null?"undefined":ae.baseEncode(t);z.formatters.m=t=>t==null?"undefined":an.baseEncode(t);z.formatters.p=t=>t==null?"undefined":t.toString();z.formatters.c=t=>t==null?"undefined":t.toString();z.formatters.k=t=>t==null?"undefined":t.toString();z.formatters.a=t=>t==null?"undefined":t.toString();function Ki(t,e=""){let r=Ji(t.message),n=Ji(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 yl(t){return t instanceof AggregateError||t?.name==="AggregateError"&&Array.isArray(t.errors)}function Ki(t,e=""){if(yl(t)){let r=Xi(t,e);return t.errors.length>0?(e=`${e} `,r+=`
10
- ${e}${t.errors.map(n=>`${Ki(n,`${e}`)}`).join(`
9
+ ${e}`)}`:r!=null?`${r}`:`${t.toString()}`}function Sl(t){return t instanceof AggregateError||t?.name==="AggregateError"&&Array.isArray(t.errors)}function Yi(t,e=""){if(Sl(t)){let r=Ki(t,e);return t.errors.length>0?(e=`${e} `,r+=`
10
+ ${e}${t.errors.map(n=>`${Yi(n,`${e}`)}`).join(`
11
11
  ${e}`)}`):r+=`
12
- ${e}[Error list was empty]`,r.trim()}return Xi(t,e)}z.formatters.e=t=>t==null?"undefined":Ki(t);function xl(t){let e=()=>{};return e.enabled=!1,e.color="",e.diff=0,e.log=()=>{},e.namespace=t,e.destroy=()=>!0,e.extend=()=>e,e}function Wt(t){return{forComponent(e){return Ji(e,t)}}}function Ji(t,e){let r=xl(`${t}:trace`);return z.enabled(`${t}:trace`)&&z.names.map(n=>n.toString()).find(n=>n.includes(":trace"))!=null&&(r=z(`${t}:trace`,e)),Object.assign(z(t,e),{error:z(`${t}:error`,e),trace:r,newScope:n=>Ji(`${t}:${n}`,e)})}function Qi(t){if(t!=null&&(t=t.trim(),t.length!==0))return t}var wl=0,mo=class extends Pe{local;remote;constructor(e){let r=`${wl++}`;super({...e,id:r,log:Wt().forComponent(`libp2p:stream-pair:${e.direction}:${r}`)}),this.local=e.local,this.remote=e.remote,this.local.addEventListener("drain",()=>{this.safeDispatchEvent("drain")}),this.remote.addEventListener("message",n=>{this.onData(n.data)}),this.remote.addEventListener("reset",n=>{this.onRemoteReset()}),this.remote.addEventListener("closeWrite",n=>{this.onRemoteCloseWrite()})}sendData(e){let r=this.local.send(new se(e));return{sentBytes:e.byteLength,canSendMore:r}}sendReset(){this.local.send(new Event("reset"))}async sendCloseWrite(e){return k(new Promise((r,n)=>{this.local.send(new Event("closeWrite")),this.local.onIdle().then(r,n)}),e?.signal)}async sendCloseRead(e){return k(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 Yi=Symbol.for("sindresorhus/unlimited-timeout#brand");function Zi(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={[Yi]:!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 ea(t){!t||typeof t!="object"||!t[Yi]||(t.cleared=!0,t.id!==void 0&&(globalThis.clearTimeout(t.id),t.id=void 0))}var El=new WeakMap;function vl({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,y)=>{i=()=>{f(),p(n)},a=y,s=(e??setTimeout)(i,r)});return o&&o.addEventListener("abort",l,{once:!0}),El.set(h,()=>{u(s),s=null,i()}),h}}var _l=vl({setTimeout:Zi,clearTimeout:ea}),po=_l;var Sl=1024*64,Gt=class extends ie{needsDrain;queue;capacity;delay;log;chunkSize;constructor(e){super(),this.needsDrain=!1,this.queue=new re({concurrency:1}),this.capacity=e.capacity??5,this.delay=e.delay??0,this.log=e.log,this.chunkSize=e.chunkSize??Sl,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(Il(e)){let r=new A(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 se(o);this.queue.add(async i=>{this.delay>0&&await k(po(this.delay),i.signal),this.dispatchEvent(i.evt)},{evt:s})}}else this.queue.add(async r=>{this.delay>0&&await k(po(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 Il(t){return t?.data instanceof Uint8Array||Je(t?.data)}var ta=0,zr=class extends Tt{local;remote;constructor(e){super(e),this.local=e.local,this.remote=e.remote,this.local.addEventListener("drain",()=>{this.safeDispatchEvent("drain")}),this.remote.addEventListener("message",r=>{this.status==="open"&&this.onData(r.data)}),this.remote.addEventListener("reset",r=>{this.status==="open"&&this.onRemoteReset()}),this.remote.addEventListener("close",r=>{this.onTransportClosed()}),this.remote.addEventListener("pause",r=>{this.local.pause()}),this.remote.addEventListener("resume",r=>{this.local.resume()})}sendData(e){let r=this.local.send(new se(e));return{sentBytes:e.byteLength,canSendMore:r}}sendReset(){this.local.send(new Event("reset"))}async sendClose(e){return this.local.needsDrain&&await D(this.local,"drain",{signal:e?.signal}),k(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 go(t={}){let e=`${ta++}`,r=`${ta++}`,n=Wt().forComponent(`libp2p:mock-maconn:outbound:${e}`),o=Wt().forComponent(`libp2p:mock-maconn:inbound:${r}`),s=new Gt({...t,log:n}),i=new Gt({...t,log:o});return[new zr({...t.outbound,id:r,direction:"outbound",local:s,remote:i,remoteAddr:t?.outbound?.remoteAddr??Le(`/ip4/127.0.0.1/tcp/${r}`),log:n}),new zr({...t.inbound,id:e,direction:"inbound",local:i,remote:s,remoteAddr:t?.inbound?.remoteAddr??Le(`/ip4/127.0.0.1/tcp/${e}`),log:o})]}var bo=class extends re{has(e){return this.find(e)!=null}find(e){return this.queue.find(r=>e.equals(r.options.peerId))}};var yo=class extends re{constructor(e={}){super({...e,sort:(r,n)=>r.options.priority>n.options.priority?-1:r.options.priority<n.options.priority?1:0})}};var xo=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 Vr}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 It("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)}},Vr=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 Cl(t,e,r){let n,o,s=!1;function i(){let l={signal:o.signal},f;r?.timeout!=null&&(f=lr([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=ot(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 ra(t={}){let[e,r]=go({...t,outbound:t.outboundConnection,inbound:t.inboundConnection}),n=Or({streamOptions:t.outbound}).createStreamMuxer(e),o=Or({streamOptions:t.inbound}).createStreamMuxer(r),[s,i]=await Promise.all([D(o,"stream").then(a=>a.detail),n.createStream({...t.outbound,protocol:t.protocol})]);return[i,s]}async function Ll(t={}){let[e,r]=await ra(t);return Xn(r),e}function Al(t){let{name:e,metrics:r}=t,n=[];return r?.registerMetric(e,{calculate:()=>n.length}),n}var wo=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 Tl(t){let{name:e,metrics:r}=t,n;return r!=null?n=new wo({name:e,metrics:r}):n=new Map,n}return fa(Dl);})();
13
- /*! Bundled license information:
14
-
15
- @noble/hashes/utils.js:
16
- (*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
17
- */
12
+ ${e}[Error list was empty]`,r.trim()}return Ki(t,e)}z.formatters.e=t=>t==null?"undefined":Yi(t);function Il(t){let e=()=>{};return e.enabled=!1,e.color="",e.diff=0,e.log=()=>{},e.namespace=t,e.destroy=()=>!0,e.extend=()=>e,e}function Xt(t){return{forComponent(e){return Zi(e,t)}}}function Zi(t,e){let r=Il(`${t}:trace`);return z.enabled(`${t}:trace`)&&z.names.map(n=>n.toString()).find(n=>n.includes(":trace"))!=null&&(r=z(`${t}:trace`,e)),Object.assign(z(t,e),{error:z(`${t}:error`,e),trace:r,newScope:n=>Zi(`${t}:${n}`,e)})}function Ji(t){if(t!=null&&(t=t.trim(),t.length!==0))return t}var Ll=0,go=class extends Re{local;remote;constructor(e){let r=`${Ll++}`;super({...e,id:r,log:Xt().forComponent(`libp2p:stream-pair:${e.direction}:${r}`)}),this.local=e.local,this.remote=e.remote,this.local.addEventListener("drain",()=>{this.safeDispatchEvent("drain")}),this.remote.addEventListener("message",n=>{this.onData(n.data)}),this.remote.addEventListener("reset",n=>{this.onRemoteReset()}),this.remote.addEventListener("closeWrite",n=>{this.onRemoteCloseWrite()})}sendData(e){let r=this.local.send(new se(e));return{sentBytes:e.byteLength,canSendMore:r}}sendReset(){this.local.send(new Event("reset"))}async sendCloseWrite(e){return k(new Promise((r,n)=>{this.local.send(new Event("closeWrite")),this.local.onIdle().then(r,n)}),e?.signal)}async sendCloseRead(e){return k(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 ea=Symbol.for("sindresorhus/unlimited-timeout#brand");function ta(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={[ea]:!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 ra(t){!t||typeof t!="object"||!t[ea]||(t.cleared=!0,t.id!==void 0&&(globalThis.clearTimeout(t.id),t.id=void 0))}var Cl=new WeakMap;function Al({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)},d=new Promise((p,y)=>{i=()=>{f(),p(n)},a=y,s=(e??setTimeout)(i,r)});return o&&o.addEventListener("abort",l,{once:!0}),Cl.set(d,()=>{u(s),s=null,i()}),d}}var Tl=Al({setTimeout:ta,clearTimeout:ra}),bo=Tl;var Dl=1024*64,Qt=class extends ie{needsDrain;queue;capacity;delay;log;chunkSize;constructor(e){super(),this.needsDrain=!1,this.queue=new re({concurrency:1}),this.capacity=e.capacity??5,this.delay=e.delay??0,this.log=e.log,this.chunkSize=e.chunkSize??Dl,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(kl(e)){let r=new A(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 se(o);this.queue.add(async i=>{this.delay>0&&await k(bo(this.delay),i.signal),this.dispatchEvent(i.evt)},{evt:s})}}else this.queue.add(async r=>{this.delay>0&&await k(bo(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 kl(t){return t?.data instanceof Uint8Array||et(t?.data)}var na=0,jr=class extends Bt{local;remote;constructor(e){super(e),this.local=e.local,this.remote=e.remote,this.local.addEventListener("drain",()=>{this.safeDispatchEvent("drain")}),this.remote.addEventListener("message",r=>{this.status==="open"&&this.onData(r.data)}),this.remote.addEventListener("reset",r=>{this.status==="open"&&this.onRemoteReset()}),this.remote.addEventListener("close",r=>{this.onTransportClosed()}),this.remote.addEventListener("pause",r=>{this.local.pause()}),this.remote.addEventListener("resume",r=>{this.local.resume()})}sendData(e){let r=this.local.send(new se(e));return{sentBytes:e.byteLength,canSendMore:r}}sendReset(){this.local.send(new Event("reset"))}async sendClose(e){return this.local.needsDrain&&await D(this.local,"drain",{signal:e?.signal}),k(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 yo(t={}){let e=`${na++}`,r=`${na++}`,n=Xt().forComponent(`libp2p:mock-maconn:outbound:${e}`),o=Xt().forComponent(`libp2p:mock-maconn:inbound:${r}`),s=new Qt({...t,log:n}),i=new Qt({...t,log:o});return[new jr({...t.outbound,id:r,direction:"outbound",local:s,remote:i,remoteAddr:t?.outbound?.remoteAddr??Ae(`/ip4/127.0.0.1/tcp/${r}`),log:n}),new jr({...t.inbound,id:e,direction:"inbound",local:i,remote:s,remoteAddr:t?.inbound?.remoteAddr??Ae(`/ip4/127.0.0.1/tcp/${e}`),log:o})]}var wo=class extends re{has(e){return this.find(e)!=null}find(e){return this.queue.find(r=>e.equals(r.options.peerId))}};var xo=class extends re{constructor(e={}){super({...e,sort:(r,n)=>r.options.priority>n.options.priority?-1:r.options.priority<n.options.priority?1:0})}};var Eo=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 qr}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 Tt("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)}},qr=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 Fl(t,e,r){let n,o,s=!1;function i(){let l={signal:o.signal},f;r?.timeout!=null&&(f=mr([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=at(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 oa(t={}){let[e,r]=yo({...t,outbound:t.outboundConnection,inbound:t.inboundConnection}),n=Rr({streamOptions:t.outbound}).createStreamMuxer(e),o=Rr({streamOptions:t.inbound}).createStreamMuxer(r),[s,i]=await Promise.all([D(o,"stream").then(a=>a.detail),n.createStream({...t.outbound,protocol:t.protocol})]);return[i,s]}async function Bl(t={}){let[e,r]=await oa(t);return Kn(r),e}function Nl(t){let{name:e,metrics:r}=t,n=[];return r?.registerMetric(e,{calculate:()=>n.length}),n}var vo=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 Pl(t){let{name:e,metrics:r}=t,n;return r!=null?n=new vo({name:e,metrics:r}):n=new Map,n}return da(Ul);})();
18
13
  return Libp2PUtils}));
19
14
  //# sourceMappingURL=index.min.js.map