@libp2p/tcp 10.1.18-cf9aab5c8 → 10.1.19-a02cb0461
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +4 -4
- package/dist/src/index.d.ts +0 -4
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/listener.d.ts +3 -4
- package/dist/src/listener.d.ts.map +1 -1
- package/dist/src/listener.js +14 -12
- package/dist/src/listener.js.map +1 -1
- package/dist/src/socket-to-conn.d.ts +5 -12
- package/dist/src/socket-to-conn.d.ts.map +1 -1
- package/dist/src/socket-to-conn.js +98 -173
- package/dist/src/socket-to-conn.js.map +1 -1
- package/dist/src/tcp.d.ts.map +1 -1
- package/dist/src/tcp.js +9 -9
- package/dist/src/tcp.js.map +1 -1
- package/package.json +11 -11
- package/src/index.ts +0 -5
- package/src/listener.ts +16 -15
- package/src/socket-to-conn.ts +114 -200
- package/src/tcp.ts +9 -9
package/dist/index.min.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PTcp = factory()}(typeof self !== 'undefined' ? self : this, function () {
|
|
2
|
-
"use strict";var Libp2PTcp=(()=>{var Tn=Object.create;var ke=Object.defineProperty;var Dn=Object.getOwnPropertyDescriptor;var Pn=Object.getOwnPropertyNames;var Sn=Object.getPrototypeOf,An=Object.prototype.hasOwnProperty;var k=(r=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(r,{get:(e,t)=>(typeof require<"u"?require:e)[t]}):r)(function(r){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+r+'" is not supported')});var N=(r,e)=>{for(var t in e)ke(r,t,{get:e[t],enumerable:!0})},fr=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Pn(e))!An.call(r,o)&&o!==t&&ke(r,o,{get:()=>e[o],enumerable:!(n=Dn(e,o))||n.enumerable});return r};var oe=(r,e,t)=>(t=r!=null?Tn(Sn(r)):{},fr(e||!r||!r.__esModule?ke(t,"default",{value:r,enumerable:!0}):t,r)),On=r=>fr(ke({},"__esModule",{value:!0}),r);var $s={};N($s,{tcp:()=>Rs});var In=oe(k("net"),1);var mr=Symbol.for("@libp2p/transport");var pr;(function(r){r[r.FATAL_ALL=0]="FATAL_ALL",r[r.NO_FATAL=1]="NO_FATAL"})(pr||(pr={}));var Be=class extends Error{static name="AbortError";constructor(e="The operation was aborted"){super(e),this.name="AbortError"}};var H=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}};var se=class extends Error{static name="TimeoutError";constructor(e="Timed out"){super(e),this.name="TimeoutError"}},Re=class extends Error{static name="NotStartedError";constructor(e="Not started"){super(e),this.name="NotStartedError"}},$e=class extends Error{static name="AlreadyStartedError";constructor(e="Already started"){super(e),this.name="AlreadyStartedError"}};var hr=k("node:events"),ze=(r,...e)=>{try{(0,hr.setMaxListeners)(r,...e)}catch{}};var Ve=class extends EventTarget{#e=new Map;constructor(){super(),ze(1/0,this)}listenerCount(e){let t=this.#e.get(e);return t==null?0:t.length}addEventListener(e,t,n){super.addEventListener(e,t,n);let o=this.#e.get(e);o==null&&(o=[],this.#e.set(e,o)),o.push({callback:t,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(e,t,n){super.removeEventListener(e.toString(),t??null,n);let o=this.#e.get(e);o!=null&&(o=o.filter(({callback:s})=>s!==t),this.#e.set(e,o))}dispatchEvent(e){let t=super.dispatchEvent(e),n=this.#e.get(e.type);return n==null||(n=n.filter(({once:o})=>!o),this.#e.set(e.type,n)),t}safeDispatchEvent(e,t={}){return this.dispatchEvent(new CustomEvent(e,t))}};var xr=Symbol.for("@libp2p/service-capabilities"),Gs=Symbol.for("@libp2p/service-dependencies");var Rr=k("node:buffer");var ut={};N(ut,{base10:()=>Bn});var mi=new Uint8Array(0);function gr(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}function B(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")}function Er(r){return new TextEncoder().encode(r)}function br(r){return new TextDecoder().decode(r)}function _n(r,e){if(r.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),n=0;n<t.length;n++)t[n]=255;for(var o=0;o<r.length;o++){var s=r.charAt(o),i=s.charCodeAt(0);if(t[i]!==255)throw new TypeError(s+" is ambiguous");t[i]=o}var a=r.length,c=r.charAt(0),u=Math.log(a)/Math.log(256),d=Math.log(256)/Math.log(a);function x(h){if(h instanceof Uint8Array||(ArrayBuffer.isView(h)?h=new Uint8Array(h.buffer,h.byteOffset,h.byteLength):Array.isArray(h)&&(h=Uint8Array.from(h))),!(h instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(h.length===0)return"";for(var E=0,S=0,m=0,T=h.length;m!==T&&h[m]===0;)m++,E++;for(var F=(T-m)*d+1>>>0,M=new Uint8Array(F);m!==T;){for(var W=h[m],Q=0,z=F-1;(W!==0||Q<S)&&z!==-1;z--,Q++)W+=256*M[z]>>>0,M[z]=W%a>>>0,W=W/a>>>0;if(W!==0)throw new Error("Non-zero carry");S=Q,m++}for(var G=F-S;G!==F&&M[G]===0;)G++;for(var Me=c.repeat(E);G<F;++G)Me+=r.charAt(M[G]);return Me}function p(h){if(typeof h!="string")throw new TypeError("Expected String");if(h.length===0)return new Uint8Array;var E=0;if(h[E]!==" "){for(var S=0,m=0;h[E]===c;)S++,E++;for(var T=(h.length-E)*u+1>>>0,F=new Uint8Array(T);h[E];){var M=t[h.charCodeAt(E)];if(M===255)return;for(var W=0,Q=T-1;(M!==0||W<m)&&Q!==-1;Q--,W++)M+=a*F[Q]>>>0,F[Q]=M%256>>>0,M=M/256>>>0;if(M!==0)throw new Error("Non-zero carry");m=W,E++}if(h[E]!==" "){for(var z=T-m;z!==T&&F[z]===0;)z++;for(var G=new Uint8Array(S+(T-z)),Me=S;z!==T;)G[Me++]=F[z++];return G}}}function f(h){var E=p(h);if(E)return E;throw new Error(`Non-${e} character`)}return{encode:x,decodeUnsafe:p,decode:f}}var Nn=_n,Ln=Nn,yr=Ln;var it=class{name;prefix;baseEncode;constructor(e,t,n){this.name=e,this.prefix=t,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},at=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,t,n){this.name=e,this.prefix=t;let o=t.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 wr(this,e)}},ct=class{decoders;constructor(e){this.decoders=e}or(e){return wr(this,e)}decode(e){let t=e[0],n=this.decoders[t];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 wr(r,e){return new ct({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var lt=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,t,n,o){this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=o,this.encoder=new it(e,t,n),this.decoder=new at(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function ie({name:r,prefix:e,encode:t,decode:n}){return new lt(r,e,t,n)}function X({name:r,prefix:e,alphabet:t}){let{encode:n,decode:o}=yr(t,r);return ie({prefix:e,name:r,encode:n,decode:s=>B(o(s))})}function Un(r,e,t,n){let o=r.length;for(;r[o-1]==="=";)--o;let s=new Uint8Array(o*t/8|0),i=0,a=0,c=0;for(let u=0;u<o;++u){let d=e[r[u]];if(d===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<t|d,i+=t,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=t||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function Mn(r,e,t){let n=e[e.length-1]==="=",o=(1<<t)-1,s="",i=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],i+=8;i>t;)i-=t,s+=e[o&a>>i];if(i!==0&&(s+=e[o&a<<t-i]),n)for(;(s.length*t&7)!==0;)s+="=";return s}function kn(r){let e={};for(let t=0;t<r.length;++t)e[r[t]]=t;return e}function I({name:r,prefix:e,bitsPerChar:t,alphabet:n}){let o=kn(n);return ie({prefix:e,name:r,encode(s){return Mn(s,n,t)},decode(s){return Un(s,o,t,r)}})}var Bn=X({prefix:"9",name:"base10",alphabet:"0123456789"});var dt={};N(dt,{base16:()=>Rn,base16upper:()=>$n});var Rn=I({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),$n=I({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var ft={};N(ft,{base2:()=>zn});var zn=I({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var pt={};N(pt,{base256emoji:()=>jn});var Cr=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}"),Vn=Cr.reduce((r,e,t)=>(r[t]=e,r),[]),Fn=Cr.reduce((r,e,t)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return r[n]=t,r},[]);function Wn(r){return r.reduce((e,t)=>(e+=Vn[t],e),"")}function Hn(r){let e=[];for(let t of r){let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);let o=Fn[n];if(o==null)throw new Error(`Non-base256emoji character: ${t}`);e.push(o)}return new Uint8Array(e)}var jn=ie({prefix:"\u{1F680}",name:"base256emoji",encode:Wn,decode:Hn});var mt={};N(mt,{base32:()=>J,base32hex:()=>Xn,base32hexpad:()=>Kn,base32hexpadupper:()=>Yn,base32hexupper:()=>Jn,base32pad:()=>qn,base32padupper:()=>Qn,base32upper:()=>Gn,base32z:()=>Zn});var J=I({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Gn=I({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),qn=I({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Qn=I({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Xn=I({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Jn=I({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Kn=I({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Yn=I({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Zn=I({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var ht={};N(ht,{base36:()=>ve,base36upper:()=>eo});var ve=X({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),eo=X({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var xt={};N(xt,{base58btc:()=>R,base58flickr:()=>to});var R=X({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),to=X({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Et={};N(Et,{base64:()=>ro,base64pad:()=>no,base64url:()=>gt,base64urlpad:()=>oo});var ro=I({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),no=I({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),gt=I({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),oo=I({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var bt={};N(bt,{base8:()=>so});var so=I({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var vt={};N(vt,{identity:()=>io});var io=ie({prefix:"\0",name:"identity",encode:r=>br(r),decode:r=>Er(r)});var Oi=new TextEncoder,_i=new TextDecoder;var wt={};N(wt,{identity:()=>Oo});var lo=Dr,Ir=128,uo=127,fo=~uo,po=Math.pow(2,31);function Dr(r,e,t){e=e||[],t=t||0;for(var n=t;r>=po;)e[t++]=r&255|Ir,r/=128;for(;r&fo;)e[t++]=r&255|Ir,r>>>=7;return e[t]=r|0,Dr.bytes=t-n+1,e}var mo=yt,ho=128,Tr=127;function yt(r,n){var t=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw yt.bytes=0,new RangeError("Could not decode varint");i=r[s++],t+=o<28?(i&Tr)<<o:(i&Tr)*Math.pow(2,o),o+=7}while(i>=ho);return yt.bytes=s-n,t}var xo=Math.pow(2,7),go=Math.pow(2,14),Eo=Math.pow(2,21),bo=Math.pow(2,28),vo=Math.pow(2,35),yo=Math.pow(2,42),wo=Math.pow(2,49),Co=Math.pow(2,56),Io=Math.pow(2,63),To=function(r){return r<xo?1:r<go?2:r<Eo?3:r<bo?4:r<vo?5:r<yo?6:r<wo?7:r<Co?8:r<Io?9:10},Do={encode:lo,decode:mo,encodingLength:To},Po=Do,ye=Po;function we(r,e=0){return[ye.decode(r,e),ye.decode.bytes]}function ae(r,e,t=0){return ye.encode(r,e,t),e}function ce(r){return ye.encodingLength(r)}function Z(r,e){let t=e.byteLength,n=ce(r),o=n+ce(t),s=new Uint8Array(o+t);return ae(r,s,0),ae(t,s,n),s.set(e,o),new le(r,t,e,s)}function Pr(r){let e=B(r),[t,n]=we(e),[o,s]=we(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new le(t,o,i,e)}function Sr(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&gr(r.bytes,t.bytes)}}var le=class{code;size;digest;bytes;constructor(e,t,n,o){this.code=e,this.size=t,this.digest=n,this.bytes=o}};var Ar=0,So="identity",Or=B;function Ao(r){return Z(Ar,Or(r))}var Oo={code:Ar,name:So,encode:Or,digest:Ao};var Dt={};N(Dt,{sha256:()=>_o,sha512:()=>No});var Tt=oe(k("crypto"),1);function It({name:r,code:e,encode:t}){return new Ct(r,e,t)}var Ct=class{name;code;encode;constructor(e,t,n){this.name=e,this.code=t,this.encode=n}digest(e){if(e instanceof Uint8Array){let t=this.encode(e);return t instanceof Uint8Array?Z(this.code,t):t.then(n=>Z(this.code,n))}else throw Error("Unknown type, must be binary type")}};var _o=It({name:"sha2-256",code:18,encode:r=>B(Tt.default.createHash("sha256").update(r).digest())}),No=It({name:"sha2-512",code:19,encode:r=>B(Tt.default.createHash("sha512").update(r).digest())});function Nr(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return Uo(t,Pt(r),e??R.encoder);default:return Mo(t,Pt(r),e??J.encoder)}}var Lr=new WeakMap;function Pt(r){let e=Lr.get(r);if(e==null){let t=new Map;return Lr.set(r,t),t}return e}var K=class r{code;version;multihash;bytes;"/";constructor(e,t,n,o){this.code=t,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:t}=this;if(e!==Ie)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==ko)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(t)}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:t}=this.multihash,n=Z(e,t);return r.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 r.equals(this,e)}static equals(e,t){let n=t;return n!=null&&e.code===n.code&&e.version===n.version&&Sr(e.multihash,n.multihash)}toString(e){return Nr(this,e)}toJSON(){return{"/":Nr(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 t=e;if(t instanceof r)return t;if(t["/"]!=null&&t["/"]===t.bytes||t.asCID===t){let{version:n,code:o,multihash:s,bytes:i}=t;return new r(n,o,s,i??Ur(n,o,s.bytes))}else if(t[Bo]===!0){let{version:n,multihash:o,code:s}=t,i=Pr(o);return r.create(n,s,i)}else return null}static create(e,t,n){if(typeof t!="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(t!==Ie)throw new Error(`Version 0 CID must use dag-pb (code: ${Ie}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let o=Ur(e,t,n.bytes);return new r(e,t,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,Ie,e)}static createV1(e,t){return r.create(1,e,t)}static decode(e){let[t,n]=r.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return t}static decodeFirst(e){let t=r.inspectBytes(e),n=t.size-t.multihashSize,o=B(e.subarray(n,n+t.multihashSize));if(o.byteLength!==t.multihashSize)throw new Error("Incorrect length");let s=o.subarray(t.multihashSize-t.digestSize),i=new le(t.multihashCode,t.digestSize,s,o);return[t.version===0?r.createV0(i):r.createV1(t.codec,i),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[x,p]=we(e.subarray(t));return t+=p,x},o=n(),s=Ie;if(o===18?(o=0,t=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=t,a=n(),c=n(),u=t+c,d=u-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:d,size:u}}static parse(e,t){let[n,o]=Lo(e,t),s=r.decode(o);if(s.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Pt(s).set(n,e),s}};function Lo(r,e){switch(r[0]){case"Q":{let t=e??R;return[R.prefix,t.decode(`${R.prefix}${r}`)]}case R.prefix:{let t=e??R;return[R.prefix,t.decode(r)]}case J.prefix:{let t=e??J;return[J.prefix,t.decode(r)]}case ve.prefix:{let t=e??ve;return[ve.prefix,t.decode(r)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],e.decode(r)]}}}function Uo(r,e,t){let{prefix:n}=t;if(n!==R.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let o=e.get(n);if(o==null){let s=t.encode(r).slice(1);return e.set(n,s),s}else return o}function Mo(r,e,t){let{prefix:n}=t,o=e.get(n);if(o==null){let s=t.encode(r);return e.set(n,s),s}else return o}var Ie=112,ko=18;function Ur(r,e,t){let n=ce(r),o=n+ce(e),s=new Uint8Array(o+t.byteLength);return ae(r,s,0),ae(e,s,n),s.set(t,o),s}var Bo=Symbol.for("@ipld/js-cid/CID");var Te={...vt,...ft,...bt,...ut,...dt,...mt,...ht,...xt,...Et,...pt},ea={...Dt,...wt};var Mr=k("node:buffer");function ue(r){return new Uint8Array(r.buffer,r.byteOffset,r.byteLength)}function St(r=0){return ue(Mr.Buffer.allocUnsafe(r))}function Br(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var kr=Br("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),At=Br("ascii","a",r=>{let e="a";for(let t=0;t<r.length;t++)e+=String.fromCharCode(r[t]);return e},r=>{r=r.substring(1);let e=St(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),Ro={utf8:kr,"utf-8":kr,hex:Te.base16,latin1:At,ascii:At,binary:At,...Te},We=Ro;function $(r,e="utf8"){let t=We[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return e==="utf8"||e==="utf-8"?Rr.Buffer.from(r.buffer,r.byteOffset,r.byteLength).toString("utf8"):t.encoder.encode(r).substring(1)}var A=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},q=class extends Error{static name="ValidationError";name="ValidationError"},De=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},He=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};function $r(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}var zr=k("node:buffer");function Y(r,e="utf8"){let t=We[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return e==="utf8"||e==="utf-8"?ue(zr.Buffer.from(r,"utf-8")):t.decoder.decode(`${t.prefix}${r}`)}var $o=Math.pow(2,7),zo=Math.pow(2,14),Vo=Math.pow(2,21),Ot=Math.pow(2,28),_t=Math.pow(2,35),Nt=Math.pow(2,42),Lt=Math.pow(2,49),C=128,O=127;function de(r){if(r<$o)return 1;if(r<zo)return 2;if(r<Vo)return 3;if(r<Ot)return 4;if(r<_t)return 5;if(r<Nt)return 6;if(r<Lt)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Ut(r,e,t=0){switch(de(r)){case 8:e[t++]=r&255|C,r/=128;case 7:e[t++]=r&255|C,r/=128;case 6:e[t++]=r&255|C,r/=128;case 5:e[t++]=r&255|C,r/=128;case 4:e[t++]=r&255|C,r>>>=7;case 3:e[t++]=r&255|C,r>>>=7;case 2:e[t++]=r&255|C,r>>>=7;case 1:{e[t++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return e}function Fo(r,e){let t=r[e],n=0;if(n+=t&O,t<C||(t=r[e+1],n+=(t&O)<<7,t<C)||(t=r[e+2],n+=(t&O)<<14,t<C)||(t=r[e+3],n+=(t&O)<<21,t<C)||(t=r[e+4],n+=(t&O)*Ot,t<C)||(t=r[e+5],n+=(t&O)*_t,t<C)||(t=r[e+6],n+=(t&O)*Nt,t<C)||(t=r[e+7],n+=(t&O)*Lt,t<C))return n;throw new RangeError("Could not decode varint")}function Wo(r,e){let t=r.get(e),n=0;if(n+=t&O,t<C||(t=r.get(e+1),n+=(t&O)<<7,t<C)||(t=r.get(e+2),n+=(t&O)<<14,t<C)||(t=r.get(e+3),n+=(t&O)<<21,t<C)||(t=r.get(e+4),n+=(t&O)*Ot,t<C)||(t=r.get(e+5),n+=(t&O)*_t,t<C)||(t=r.get(e+6),n+=(t&O)*Nt,t<C)||(t=r.get(e+7),n+=(t&O)*Lt,t<C))return n;throw new RangeError("Could not decode varint")}function Mt(r,e=0){return r instanceof Uint8Array?Fo(r,e):Wo(r,e)}var Vr=k("node:buffer");function Pe(r,e){return ue(Vr.Buffer.concat(r,e))}var L=k("node:net");function Bt(r){return e=>$(e,r)}function Rt(r){return e=>Y(e,r)}function fe(r){return new DataView(r.buffer).getUint16(r.byteOffset).toString()}function ee(r){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,typeof r=="string"?parseInt(r):r),new Uint8Array(e)}function Fr(r){let e=r.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 t=Y(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=ee(n);return Pe([t,o],t.length+o.length)}function Wr(r){let e=r.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 t=J.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=ee(n);return Pe([t,o],t.length+o.length)}function $t(r){let e=r.subarray(0,r.length-2),t=r.subarray(r.length-2),n=$(e,"base32"),o=fe(t);return`${n}:${o}`}var zt=function(r){r=r.toString().trim();let e=new Uint8Array(4);return r.split(/\./g).forEach((t,n)=>{let o=parseInt(t,10);if(isNaN(o)||o<0||o>255)throw new A("Invalid byte value in IP address");e[n]=o}),e},Hr=function(r){let e=0;r=r.toString().trim();let t=r.split(":",8),n;for(n=0;n<t.length;n++){let s=(0,L.isIPv4)(t[n]),i;s&&(i=zt(t[n]),t[n]=$(i.subarray(0,2),"base16")),i!=null&&++n<8&&t.splice(n,0,$(i.subarray(2,4),"base16"))}if(t[0]==="")for(;t.length<8;)t.unshift("0");else if(t[t.length-1]==="")for(;t.length<8;)t.push("0");else if(t.length<8){for(n=0;n<t.length&&t[n]!=="";n++);let s=[n,1];for(n=9-t.length;n>0;n--)s.push("0");t.splice.apply(t,s)}let o=new Uint8Array(e+16);for(n=0;n<t.length;n++){t[n]===""&&(t[n]="0");let s=parseInt(t[n],16);if(isNaN(s)||s<0||s>65535)throw new A("Invalid byte value in IP address");o[e++]=s>>8&255,o[e++]=s&255}return o},jr=function(r){if(r.byteLength!==4)throw new A("IPv4 address was incorrect length");let e=[];for(let t=0;t<r.byteLength;t++)e.push(r[t]);return e.join(".")},Gr=function(r){if(r.byteLength!==16)throw new A("IPv6 address was incorrect length");let e=[];for(let n=0;n<r.byteLength;n+=2){let o=r[n],s=r[n+1],i=`${o.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}`;e.push(i)}let t=e.join(":");try{let n=new URL(`http://[${t}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new A(`Invalid IPv6 address "${t}"`)}};function qr(r){try{let e=new URL(`http://[${r}]`);return e.hostname.substring(1,e.hostname.length-1)}catch{throw new A(`Invalid IPv6 address "${r}"`)}}var kt=Object.values(Te).map(r=>r.decoder),jo=function(){let r=kt[0].or(kt[1]);return kt.slice(2).forEach(e=>r=r.or(e)),r}();function Qr(r){return jo.decode(r)}function Xr(r){return e=>r.encoder.encode(e)}function Go(r){if(parseInt(r).toString()!==r)throw new q("Value must be an integer")}function qo(r){if(r<0)throw new q("Value must be a positive integer, or zero")}function Qo(r){return e=>{if(e>r)throw new q(`Value must be smaller than or equal to ${r}`)}}function Xo(...r){return e=>{for(let t of r)t(e)}}var Se=Xo(Go,qo,Qo(65535));var D=-1,Vt=class{protocolsByCode=new Map;protocolsByName=new Map;getProtocol(e){let t;if(typeof e=="string"?t=this.protocolsByName.get(e):t=this.protocolsByCode.get(e),t==null)throw new He(`Protocol ${e} was unknown`);return t}addProtocol(e){this.protocolsByCode.set(e.code,e),this.protocolsByName.set(e.name,e),e.aliases?.forEach(t=>{this.protocolsByName.set(t,e)})}removeProtocol(e){let t=this.protocolsByCode.get(e);t!=null&&(this.protocolsByCode.delete(t.code),this.protocolsByName.delete(t.name),t.aliases?.forEach(n=>{this.protocolsByName.delete(n)}))}},U=new Vt,us=[{code:4,name:"ip4",size:32,valueToBytes:zt,bytesToValue:jr,validate:r=>{if(!(0,L.isIPv4)(r))throw new q(`Invalid IPv4 address "${r}"`)}},{code:6,name:"tcp",size:16,valueToBytes:ee,bytesToValue:fe,validate:Se},{code:273,name:"udp",size:16,valueToBytes:ee,bytesToValue:fe,validate:Se},{code:33,name:"dccp",size:16,valueToBytes:ee,bytesToValue:fe,validate:Se},{code:41,name:"ip6",size:128,valueToBytes:Hr,bytesToValue:Gr,stringToValue:qr,validate:r=>{if(!(0,L.isIPv6)(r))throw new q(`Invalid IPv6 address "${r}"`)}},{code:42,name:"ip6zone",size:D},{code:43,name:"ipcidr",size:8,bytesToValue:Bt("base10"),valueToBytes:Rt("base10")},{code:53,name:"dns",size:D,resolvable:!0},{code:54,name:"dns4",size:D,resolvable:!0},{code:55,name:"dns6",size:D,resolvable:!0},{code:56,name:"dnsaddr",size:D,resolvable:!0},{code:132,name:"sctp",size:16,valueToBytes:ee,bytesToValue:fe,validate:Se},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:D,path:!0,stringToValue:r=>decodeURIComponent(r),valueToString:r=>encodeURIComponent(r)},{code:421,name:"p2p",aliases:["ipfs"],size:D,bytesToValue:Bt("base58btc"),valueToBytes:r=>r.startsWith("Q")||r.startsWith("1")?Rt("base58btc")(r):K.parse(r).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:$t,valueToBytes:Fr},{code:445,name:"onion3",size:296,bytesToValue:$t,valueToBytes:Wr},{code:446,name:"garlic64",size:D},{code:447,name:"garlic32",size:D},{code:448,name:"tls"},{code:449,name:"sni",size:D},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:D,bytesToValue:Xr(gt),valueToBytes:Qr},{code:480,name:"http"},{code:481,name:"http-path",size:D,stringToValue:r=>`/${decodeURIComponent(r)}`,valueToString:r=>encodeURIComponent(r.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:D}];us.forEach(r=>{U.addProtocol(r)});function Jr(r){let e=[],t=0;for(;t<r.length;){let n=Mt(r,t),o=U.getProtocol(n),s=de(n),i=ds(o,r,t+s),a=0;i>0&&o.size===D&&(a=de(i));let c=s+a+i,u={code:n,name:o.name,bytes:r.subarray(t,t+c)};if(i>0){let d=t+s+a,x=r.subarray(d,d+i);u.value=o.bytesToValue?.(x)??$(x)}e.push(u),t+=c}return e}function Kr(r){let e=0,t=[];for(let n of r){if(n.bytes==null){let o=U.getProtocol(n.code),s=de(n.code),i,a=0,c=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??Y(n.value),a=i.byteLength,o.size===D&&(c=de(a)));let u=new Uint8Array(s+c+a),d=0;Ut(n.code,u,d),d+=s,i!=null&&(o.size===D&&(Ut(a,u,d),d+=c),u.set(i,d)),n.bytes=u}t.push(n.bytes),e+=n.bytes.byteLength}return Pe(t,e)}function Yr(r){if(r.charAt(0)!=="/")throw new A('String multiaddr must start with "/"');let e=[],t="protocol",n="",o="";for(let s=1;s<r.length;s++){let i=r.charAt(s);i!=="/"&&(t==="protocol"?o+=r.charAt(s):n+=r.charAt(s));let a=s===r.length-1;if(i==="/"||a){let c=U.getProtocol(o);if(t==="protocol"){if(c.size==null||c.size===0){e.push({code:c.code,name:c.name}),n="",o="",t="protocol";continue}else if(a)throw new A(`Component ${o} was missing value`);t="value"}else if(t==="value"){let u={code:c.code,name:c.name};if(c.size!=null&&c.size!==0){if(n==="")throw new A(`Component ${o} was missing value`);u.value=c.stringToValue?.(n)??n}e.push(u),n="",o="",t="protocol"}}}if(o!==""&&n!=="")throw new A("Incomplete multiaddr");return e}function Zr(r){return`/${r.flatMap(e=>{if(e.value==null)return e.name;let t=U.getProtocol(e.code);if(t==null)throw new A(`Unknown protocol code ${e.code}`);return[e.name,t.valueToString?.(e.value)??e.value]}).join("/")}`}function ds(r,e,t){return r.size==null||r.size===0?0:r.size>0?r.size/8:Mt(e,t)}var fs=Symbol.for("nodejs.util.inspect.custom"),Kt=Symbol.for("@multiformats/multiaddr"),ps=[53,54,55,56],Jt=class extends Error{constructor(e="No available resolver"){super(e),this.name="NoAvailableResolverError"}};function ms(r){if(r==null&&(r="/"),tn(r))return r.getComponents();if(r instanceof Uint8Array)return Jr(r);if(typeof r=="string")return r=r.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),r===""&&(r="/"),Yr(r);if(Array.isArray(r))return r;throw new A("Must be a string, Uint8Array, Component[], or another Multiaddr")}var Qe=class r{[Kt]=!0;#e;#t;#r;constructor(e="/",t={}){this.#e=ms(e),t.validate!==!1&&hs(this)}get bytes(){return this.#r==null&&(this.#r=Kr(this.#e)),this.#r}toString(){return this.#t==null&&(this.#t=Zr(this.#e)),this.#t}toJSON(){return this.toString()}toOptions(){let e,t,n,o,s="";for(let{code:a,name:c,value:u}of this.#e)a===42&&(s=`%${u??""}`),ps.includes(a)&&(t="tcp",o=443,n=`${u??""}${s}`,e=a===55?6:4),(a===6||a===273)&&(t=c==="tcp"?"tcp":"udp",o=parseInt(u??"")),(a===4||a===41)&&(t="tcp",n=`${u??""}${s}`,e=a===41?6:4);if(e==null||t==null||n==null||o==null)throw new Error('multiaddr must have a valid format: "/{ip4, ip6, dns4, dns6, dnsaddr}/{address}/{tcp, udp}/{port}".');return{family:e,host:n,transport:t,port:o}}getComponents(){return[...this.#e]}protos(){return this.#e.map(({code:e,value:t})=>{let n=U.getProtocol(e);return{code:e,size:n.size??0,name:n.name,resolvable:!!n.resolvable,path:!!n.path}})}protoCodes(){return this.#e.map(({code:e})=>e)}protoNames(){return this.#e.map(({name:e})=>e)}tuples(){return this.#e.map(({code:e,value:t})=>{if(t==null)return[e];let n=U.getProtocol(e),o=[e];return t!=null&&o.push(n.valueToBytes?.(t)??Y(t)),o})}stringTuples(){return this.#e.map(({code:e,value:t})=>t==null?[e]:[e,t])}encapsulate(e){let t=new r(e);return new r([...this.#e,...t.getComponents()],{validate:!1})}decapsulate(e){let t=e.toString(),n=this.toString(),o=n.lastIndexOf(t);if(o<0)throw new De(`Address ${this.toString()} does not contain subaddress: ${e.toString()}`);return new r(n.slice(0,o),{validate:!1})}decapsulateCode(e){let t;for(let n=this.#e.length-1;n>-1;n--)if(this.#e[n].code===e){t=n;break}return new r(this.#e.slice(0,t),{validate:!1})}getPeerId(){try{let e=[];this.#e.forEach(({code:n,value:o})=>{n===421&&e.push([n,o]),n===290&&(e=[])});let t=e.pop();if(t?.[1]!=null){let n=t[1];return n[0]==="Q"||n[0]==="1"?$(R.decode(`z${n}`),"base58btc"):$(K.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){for(let e of this.#e)if(U.getProtocol(e.code).path)return e.value??null;return null}equals(e){return $r(this.bytes,e.bytes)}async resolve(e){let t=this.protos().find(s=>s.resolvable);if(t==null)return[this];let n=en.get(t.name);if(n==null)throw new Jt(`no available resolver for ${t.name}`);return(await n(this,e)).map(s=>V(s))}nodeAddress(){let e=this.toOptions();if(e.transport!=="tcp"&&e.transport!=="udp")throw new Error(`multiaddr must have a valid format - no protocol with name: "${e.transport}". Must have a valid transport protocol: "{tcp, udp}"`);return{family:e.family,address:e.host,port:e.port}}isThinWaistAddress(){return!(this.#e.length!==2||this.#e[0].code!==4&&this.#e[0].code!==41||this.#e[1].code!==6&&this.#e[1].code!==273)}[fs](){return`Multiaddr(${this.toString()})`}};function hs(r){r.getComponents().forEach(e=>{let t=U.getProtocol(e.code);e.value!=null&&t.validate?.(e.value)})}var Xe=class{index=0;input="";new(e){return this.index=0,this.input=e,this}readAtomically(e){let t=this.index,n=e();return n===void 0&&(this.index=t),n}parseWith(e){let t=e();if(this.index===this.input.length)return t}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 t=this.readChar();if(t===e)return t})}readSeparator(e,t,n){return this.readAtomically(()=>{if(!(t>0&&this.readGivenChar(e)===void 0))return n()})}readNumber(e,t,n,o){return this.readAtomically(()=>{let s=0,i=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",u=2**(8*o)-1;for(;;){let d=this.readAtomically(()=>{let x=this.readChar();if(x===void 0)return;let p=Number.parseInt(x,e);if(!Number.isNaN(p))return p});if(d===void 0)break;if(s*=e,s+=d,s>u||(i+=1,t!==void 0&&i>t))return}if(i!==0)return!n&&c&&i>1?void 0:s})}readIPv4Addr(){return this.readAtomically(()=>{let e=new Uint8Array(4);for(let t=0;t<e.length;t++){let n=this.readSeparator(".",t,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;e[t]=n}return e})}readIPv6Addr(){let e=t=>{for(let n=0;n<t.length/2;n++){let o=n*2;if(n<t.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return t[o]=i[0],t[o+1]=i[1],t[o+2]=i[2],t[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];t[o]=s>>8,t[o+1]=s&255}return[t.length,!1]};return this.readAtomically(()=>{let t=new Uint8Array(16),[n,o]=e(t);if(n===16)return t;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 t.set(s.subarray(0,a),16-a),t})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var nc=new Xe;var dc=parseInt("0xFFFF",16),fc=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);var en=new Map;function tn(r){return!!r?.[Kt]}function V(r){return new Qe(r)}var w=r=>({match:e=>{let t=e[0];return t==null||t.code!==r||t.value!=null?!1:e.slice(1)}}),l=(r,e)=>({match:t=>{let n=t[0];return n?.code!==r||n.value==null||e!=null&&n.value!==e?!1:t.slice(1)}}),g=r=>({match:e=>{let t=r.match(e);return t===!1?e:t}}),_=(...r)=>({match:e=>{let t;for(let n of r){let o=n.match(e);o!==!1&&(t==null||o.length<t.length)&&(t=o)}return t??!1}}),v=(...r)=>({match:e=>{for(let t of r){let n=t.match(e);if(n===!1)return!1;e=n}return e}});function y(...r){function e(o){if(o==null)return!1;let s=o.getComponents();for(let i of r){let a=i.match(s);if(a===!1)return!1;s=a}return s}function t(o){return e(o)!==!1}function n(o){let s=e(o);return s===!1?!1:s.length===0}return{matchers:r,matches:t,exactMatch:n}}var ys=l(421),rl=y(ys),Ke=l(54),Ye=l(55),Ze=l(56),Zt=l(53),nl=y(Ke,g(l(421))),ol=y(Ye,g(l(421))),sl=y(Ze,g(l(421))),il=y(_(Zt,Ze,Ke,Ye),g(l(421))),on=v(l(4),g(l(43))),sn=v(g(l(42)),l(41),g(l(43))),er=_(on,sn),ne=_(er,Zt,Ke,Ye,Ze),al=y(_(er,v(_(Zt,Ze,Ke,Ye),g(l(421))))),cl=y(on),ll=y(sn),ul=y(er),tr=v(ne,l(6)),Ue=v(ne,l(273)),an=y(v(tr,g(l(421)))),dl=y(Ue),rr=v(Ue,w(460),g(l(421))),et=v(Ue,w(461),g(l(421))),ws=_(rr,et),fl=y(rr),pl=y(et),Yt=_(ne,tr,Ue,rr,et),cn=_(v(Yt,w(477),g(l(421)))),ml=y(cn),ln=_(v(Yt,w(478),g(l(421))),v(Yt,w(448),g(l(449)),w(477),g(l(421)))),hl=y(ln),un=v(Ue,w(280),g(l(466)),g(l(466)),g(l(421))),xl=y(un),dn=v(et,w(465),g(l(466)),g(l(466)),g(l(421))),gl=y(dn),Je=_(cn,ln,v(tr,g(l(421))),v(ws,g(l(421))),v(ne,g(l(421))),un,dn,l(421)),El=y(Je),Cs=v(Je,w(290),l(421)),bl=y(Cs),Is=_(v(Je,w(290),w(281),g(l(421))),v(Je,w(281),g(l(421))),v(w(281),g(l(421)))),vl=y(Is),Ts=_(v(ne,l(6),w(480),g(l(421))),v(ne,w(480),g(l(421)))),yl=y(Ts),Ds=v(ne,_(v(l(6,"443"),w(480)),v(l(6),w(443)),v(l(6),w(448),w(480)),v(w(448),w(480)),w(448),w(443)),g(l(421))),wl=y(Ds),Ps=_(v(l(777),g(l(421)))),Cl=y(Ps),Ss=_(v(l(400),g(l(421)))),Il=y(Ss);var tt=class extends Event{type;detail;constructor(e,t){super(e),this.type=e,this.detail=t}};var Cn=oe(k("net"),1);var pn=oe(k("node:os"),1);function fn(r){return!!(r.startsWith("169.254.")||r.toLowerCase().startsWith("fe80"))}var As={4:"IPv4",6:"IPv6"};function Os(r){return["0.0.0.0","::"].includes(r)}function _s(r){let e=[],t=pn.default.networkInterfaces();for(let[,n]of Object.entries(t))if(n!=null)for(let o of n)fn(o.address)||o.family===As[r]&&e.push(o.address);return e}function mn(r,e){if(r==null)return[];let t=r.toOptions();if(Os(t.host)){let n=[];for(let o of _s(t.family))n.push(V(`/ip${t.family}/${o}/${t.transport}/${e??t.port}`));return n}return[V(`/ip${t.family}/${t.host}/${t.transport}/${e??t.port}`)]}var nr=class extends Error{constructor(e){super(e),this.name="TimeoutError"}},or=class extends Error{constructor(e){super(),this.name="AbortError",this.message=e}},hn=r=>globalThis.DOMException===void 0?new or(r):new DOMException(r),xn=r=>{let e=r.reason===void 0?hn("This operation was aborted."):r.reason;return e instanceof Error?e:hn(e)};function sr(r,e){let{milliseconds:t,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout}}=e,i,a,u=new Promise((d,x)=>{if(typeof t!="number"||Math.sign(t)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${t}\``);if(e.signal){let{signal:f}=e;f.aborted&&x(xn(f)),a=()=>{x(xn(f))},f.addEventListener("abort",a,{once:!0})}if(t===Number.POSITIVE_INFINITY){r.then(d,x);return}let p=new nr;i=s.setTimeout.call(void 0,()=>{if(n){try{d(n())}catch(f){x(f)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?d():o instanceof Error?x(o):(p.message=o??`Promise timed out after ${t} milliseconds`,x(p))},t),(async()=>{try{d(await r)}catch(f){x(f)}})()}).finally(()=>{u.clear(),a&&e.signal&&e.signal.removeEventListener("abort",a)});return u.clear=()=>{s.clearTimeout.call(void 0,i),i=void 0},u}var Ns=r=>{let e=r.addEventListener||r.on||r.addListener,t=r.removeEventListener||r.off||r.removeListener;if(!e||!t)throw new TypeError("Emitter is not compatible");return{addListener:e.bind(r),removeListener:t.bind(r)}};function Ls(r,e,t){let n,o=new Promise((s,i)=>{if(t={rejectionEvents:["error"],multiArgs:!1,resolveImmediately:!1,...t},!(t.count>=0&&(t.count===Number.POSITIVE_INFINITY||Number.isInteger(t.count))))throw new TypeError("The `count` option should be at least 0 or more");t.signal?.throwIfAborted();let a=[e].flat(),c=[],{addListener:u,removeListener:d}=Ns(r),x=(...f)=>{let h=t.multiArgs?f:f[0];t.filter&&!t.filter(h)||(c.push(h),t.count===c.length&&(n(),s(c)))},p=f=>{n(),i(f)};n=()=>{for(let f of a)d(f,x);for(let f of t.rejectionEvents)d(f,p)};for(let f of a)u(f,x);for(let f of t.rejectionEvents)u(f,p);t.signal&&t.signal.addEventListener("abort",()=>{p(t.signal.reason)},{once:!0}),t.resolveImmediately&&s(c)});if(o.cancel=n,typeof t.timeout=="number"){let s=sr(o,{milliseconds:t.timeout});return s.cancel=n,s}return o}function ir(r,e,t){typeof t=="function"&&(t={filter:t}),t={...t,count:1,resolveImmediately:!1};let n=Ls(r,e,t),o=n.then(s=>s[0]);return o.cancel=n.cancel,o}function gn(r,e){if(typeof r!="string")throw new H(`invalid ip provided: ${r}`);if(typeof e=="string"&&(e=parseInt(e)),isNaN(e))throw new H(`invalid port provided: ${e}`);if((0,L.isIPv4)(r))return V(`/ip4/${r}/tcp/${e}`);if((0,L.isIPv6)(r))return V(`/ip6/${r}/tcp/${e}`);throw new H(`invalid ip:port for creating a multiaddr: ${r}:${e}`)}function ar(){let r={};return r.promise=new Promise((e,t)=>{r.resolve=e,r.reject=t}),r}var rt=class extends Error{static name="AbortError";name="AbortError";constructor(e="The operation was aborted",...t){super(e,...t)}};async function ur(r,e,t,n){let o=new rt(n?.errorMessage);n?.errorCode!=null&&(o.code=n.errorCode);let s=n?.errorEvent??"error";return t?.aborted===!0?Promise.reject(o):new Promise((i,a)=>{function c(){lr(t,"abort",x),lr(r,e,u),lr(r,s,d)}let u=p=>{try{if(n?.filter?.(p)===!1)return}catch(f){c(),a(f);return}c(),i(p)},d=p=>{if(c(),p instanceof Error){a(p);return}a(p.detail??n?.error??new Error(`The "${n?.errorEvent}" event was emitted but the event had no '.detail' field. Pass an 'error' option to race-event to change this message.`))},x=()=>{c(),a(o)};cr(t,"abort",x),cr(r,e,u),cr(r,s,d)})}function cr(r,e,t){r!=null&&(En(r)?r.addEventListener(e,t):r.addListener(e,t))}function lr(r,e,t){r!=null&&(En(r)?r.removeEventListener(e,t):r.removeListener(e,t))}function En(r){return typeof r.addEventListener=="function"&&typeof r.removeEventListener=="function"}function bn(r){if(Ms(r))return async function*(){let e=r.getReader();try{for(;;){let{done:t,value:n}=await e.read();if(t)return;yield n}}finally{e.releaseLock()}}();if(Us(r))return r;throw new Error("unknown stream")}function Us(r){return r[Symbol.asyncIterator]!=null}function Ms(r){return typeof r?.getReader=="function"}function vn(r){return async e=>{let t=async()=>{ks(e)&&await e.return(void 0)},n,o,s=m=>{n=m,t().catch(T=>{T=new AggregateError([n,T],"The Writable emitted an error, additionally an error occurred while ending the Source")}).finally(()=>{o?.(m)})},i,a=!1,c=()=>{a=!0,i?.()},u,d=!1,x=()=>{d=!0,u?.()},p,f=()=>{p?.()},h=async()=>new Promise((m,T)=>{i=p=m,o=T,r.once("drain",f)}),E=async()=>(await t(),new Promise((m,T)=>{if(a||d||n!=null){m();return}u=i=m,o=T})),S=()=>{r.removeListener("error",s),r.removeListener("close",c),r.removeListener("finish",x),r.removeListener("drain",f)};r.once("error",s),r.once("close",c),r.once("finish",x);try{for await(let m of e){if(!r.writable||r.destroyed||n!=null)break;r.write(m)||await h()}}catch(m){n==null&&r.destroy(m),n=m}try{if(r.writable&&r.end(),await E(),n!=null)throw n}finally{S()}}}function ks(r){return r.return!=null}function dr(r){return{sink:vn(r),source:bn(r)}}var yn=oe(k("os"),1),wn=oe(k("path"),1);function be(r,e={}){let t=r.getPath();if(t!=null)return yn.default.platform()==="win32"?{path:wn.default.join("\\\\.\\pipe\\",t)}:{path:t};let n=r.toOptions();return{...e,...n,ipv6Only:n.family===6}}var nt=(r,e)=>{let t,n=e.direction,o=e.metrics,s=e.metricPrefix??"",i=e.socketInactivityTimeout??12e4,a=e.socketCloseTimeout??500,c=!1,u=!1;e.listeningAddr?.getPath()!=null&&(e.remoteAddr=e.listeningAddr),e.remoteAddr?.getPath()!=null&&(e.localAddr=e.remoteAddr),r.on("error",S=>{u=!0,c||(E.log.error("%s socket error - %e",n,S),o?.increment({[`${s}error`]:!0})),r.destroy(),E.timeline.close=Date.now()});let d;if(e.remoteAddr!=null)d=e.remoteAddr;else{if(r.remoteAddress==null||r.remotePort==null)throw new H("Could not determine remote address or port");d=gn(r.remoteAddress,r.remotePort)}let x=be(d),p=x.path??`${x.host??""}:${x.port??""}`,{sink:f,source:h}=dr(r);r.setTimeout(i),r.once("timeout",()=>{c=!0,E.log("%s %s socket read timeout",n,p),o?.increment({[`${s}timeout`]:!0}),r.destroy(new se),E.timeline.close=Date.now()}),r.once("close",()=>{!c&&!u&&(E.log("%s %s socket close",n,p),o?.increment({[`${s}close`]:!0})),r.destroy(),E.timeline.close=Date.now()}),r.once("end",()=>{E.log("%s %s socket end",n,p),o?.increment({[`${s}end`]:!0})});let E={async sink(S){try{await f(async function*(){for await(let m of S)m instanceof Uint8Array?yield m:yield m.subarray()}())}catch(m){m.type!=="aborted"&&E.log.error("%s %s error in sink - %e",n,p,m)}r.end()},source:h,remoteAddr:d,timeline:{open:Date.now()},async close(S={}){if(r.closed){E.log("the %s %s socket is already closed",n,p);return}if(r.destroyed){E.log("the %s %s socket is already destroyed",n,p);return}if(t!=null)return t.promise;try{t=ar(),r.end();let m=Bs(r),T=S.signal??AbortSignal.timeout(a);r.writableLength>0&&(E.log("%s %s draining socket",n,p),await ur(m,"drain",T,{errorEvent:"error"}),E.log("%s %s socket drained",n,p)),await Promise.all([ur(m,"close",T,{errorEvent:"error"}),r.destroy()])}catch(m){this.abort(m)}finally{t.resolve()}},abort:S=>{E.log("%s %s socket abort due to error - %e",n,p,S),r.destroy(),E.timeline.close=Date.now()},log:e.logger.forComponent("libp2p:tcp:connection")};return E};function Bs(r){return{addEventListener:(t,n)=>{r.addListener(t,n)},removeEventListener:(t,n)=>{r.removeListener(t,n)}}}var P;(function(r){r[r.INACTIVE=0]="INACTIVE",r[r.ACTIVE=1]="ACTIVE",r[r.PAUSED=2]="PAUSED"})(P||(P={}));var ot=class extends Ve{context;server;sockets=new Set;status={code:P.INACTIVE};metrics;addr;log;shutdownController;constructor(e){if(super(),this.context=e,e.keepAlive=e.keepAlive??!0,e.noDelay=e.noDelay??!0,this.shutdownController=new AbortController,ze(1/0,this.shutdownController.signal),this.log=e.logger.forComponent("libp2p:tcp:listener"),this.addr="unknown",this.server=Cn.default.createServer(e,this.onSocket.bind(this)),e.maxConnections!==void 0&&(this.server.maxConnections=e.maxConnections),e.closeServerOnMaxConnections!=null&&e.closeServerOnMaxConnections.closeAbove<e.closeServerOnMaxConnections.listenBelow)throw new H("closeAbove must be >= listenBelow");e.metrics?.registerMetricGroup("libp2p_tcp_inbound_connections_total",{label:"address",help:"Current active connections in TCP listener",calculate:()=>({[this.addr]:this.sockets.size})}),this.metrics={status:e.metrics?.registerMetricGroup("libp2p_tcp_listener_status_info",{label:"address",help:"Current status of the TCP listener socket"}),errors:e.metrics?.registerMetricGroup("libp2p_tcp_listener_errors_total",{label:"address",help:"Total count of TCP listener errors by type"}),events:e.metrics?.registerMetricGroup("libp2p_tcp_listener_events_total",{label:"address",help:"Total count of TCP listener events by type"})},this.server.on("listening",()=>{let t=this.server.address();t==null?this.addr="unknown":typeof t=="string"?this.addr=t:this.addr=`${t.address}:${t.port}`,this.metrics.status?.update({[this.addr]:P.ACTIVE}),this.safeDispatchEvent("listening")}).on("error",t=>{this.metrics.errors?.increment({[`${this.addr} listen_error`]:!0}),this.safeDispatchEvent("error",{detail:t})}).on("close",()=>{this.metrics.status?.update({[this.addr]:this.status.code}),this.status.code!==P.PAUSED&&this.safeDispatchEvent("close")}).on("drop",()=>{this.metrics.events?.increment({[`${this.addr} drop`]:!0})})}onSocket(e){if(this.metrics.events?.increment({[`${this.addr} connection`]:!0}),this.status.code!==P.ACTIVE)throw e.destroy(),new Re("Server is not listening yet");let t;try{t=nt(e,{listeningAddr:this.status.listeningAddr,socketInactivityTimeout:this.context.socketInactivityTimeout,socketCloseTimeout:this.context.socketCloseTimeout,metrics:this.metrics?.events,metricPrefix:`${this.addr} `,logger:this.context.logger,direction:"inbound"})}catch(n){this.log.error("inbound connection failed",n),this.metrics.errors?.increment({[`${this.addr} inbound_to_connection`]:!0}),e.destroy();return}this.log("new inbound connection %s",t.remoteAddr),this.sockets.add(e),this.context.upgrader.upgradeInbound(t,{signal:this.shutdownController.signal}).then(()=>{this.log("inbound connection upgraded %s",t.remoteAddr),e.once("close",()=>{this.sockets.delete(e),this.context.closeServerOnMaxConnections!=null&&this.sockets.size<this.context.closeServerOnMaxConnections.listenBelow&&this.resume().catch(n=>{this.log.error("error attempting to listen server once connection count under limit",n),this.context.closeServerOnMaxConnections?.onListenError?.(n)})}),this.context.closeServerOnMaxConnections!=null&&this.sockets.size>=this.context.closeServerOnMaxConnections.closeAbove&&this.pause()}).catch(async n=>{this.log.error("inbound connection upgrade failed",n),this.metrics.errors?.increment({[`${this.addr} inbound_upgrade`]:!0}),this.sockets.delete(e),t.abort(n)})}getAddrs(){if(this.status.code===P.INACTIVE)return[];let e=this.server.address();return e==null?[]:typeof e=="string"?[V(`/unix/${encodeURIComponent(e)}`)]:mn(this.status.listeningAddr,e.port)}updateAnnounceAddrs(){}async listen(e){if(this.status.code===P.ACTIVE||this.status.code===P.PAUSED)throw new $e("server is already listening");try{this.status={code:P.ACTIVE,listeningAddr:e,netConfig:be(e,this.context)},await this.resume()}catch(t){throw this.status={code:P.INACTIVE},t}}async close(){let e=[];this.server.listening&&e.push(ir(this.server,"close")),this.pause(!0),this.shutdownController.abort(),this.sockets.forEach(t=>{t.readable&&(e.push(ir(t,"close")),t.destroy())}),await Promise.all(e)}async resume(){if(this.server.listening||this.status.code===P.INACTIVE)return;let e=this.status.netConfig;await new Promise((t,n)=>{this.server.once("error",n),this.server.listen(e,t)}),this.status={...this.status,code:P.ACTIVE},this.log("listening on %s",this.server.address())}pause(e=!1){if(!this.server.listening&&this.status.code===P.PAUSED&&e){this.status={code:P.INACTIVE};return}!this.server.listening||this.status.code!==P.ACTIVE||(this.log("closing server on %s",this.server.address()),this.status=e?{code:P.INACTIVE}:{...this.status,code:P.PAUSED},this.server.close())}};var st=class{opts;metrics;components;log;constructor(e,t={}){this.log=e.logger.forComponent("libp2p:tcp"),this.opts=t,this.components=e,e.metrics!=null&&(this.metrics={events:e.metrics.registerCounterGroup("libp2p_tcp_dialer_events_total",{label:"event",help:"Total count of TCP dialer events by type"}),errors:e.metrics.registerCounterGroup("libp2p_tcp_dialer_errors_total",{label:"event",help:"Total count of TCP dialer events by type"})})}[mr]=!0;[Symbol.toStringTag]="@libp2p/tcp";[xr]=["@libp2p/transport"];async dial(e,t){t.keepAlive=t.keepAlive??!0,t.noDelay=t.noDelay??!0;let n=await this._connect(e,t),o;try{o=nt(n,{remoteAddr:e,socketInactivityTimeout:this.opts.outboundSocketInactivityTimeout,socketCloseTimeout:this.opts.socketCloseTimeout,metrics:this.metrics?.events,logger:this.components.logger,direction:"outbound"})}catch(s){throw this.metrics?.errors.increment({outbound_to_connection:!0}),n.destroy(s),s}try{return this.log("new outbound connection %s",o.remoteAddr),await t.upgrader.upgradeOutbound(o,t)}catch(s){throw this.metrics?.errors.increment({outbound_upgrade:!0}),this.log.error("error upgrading outbound connection",s),o.abort(s),s}}async _connect(e,t){t.signal.throwIfAborted(),t.onProgress?.(new tt("tcp:open-connection"));let n;return new Promise((o,s)=>{let i=Date.now(),a=be(e,{...this.opts.dialOpts??{},...t});this.log("dialing %a",e),n=In.default.connect(a);let c=f=>{this.log.error("dial to %a errored - %e",e,f);let h=a.path??`${a.host??""}:${a.port}`;f.message=`connection error ${h}: ${f.message}`,this.metrics?.events.increment({error:!0}),p(f)},u=()=>{this.log("connection timeout %a",e),this.metrics?.events.increment({timeout:!0});let f=new se(`Connection timeout after ${Date.now()-i}ms`);n.emit("error",f)},d=()=>{this.log("connection opened %a",e),this.metrics?.events.increment({connect:!0}),p()},x=()=>{this.log("connection aborted %a",e),this.metrics?.events.increment({abort:!0}),p(new Be)},p=f=>{if(n.removeListener("error",c),n.removeListener("timeout",u),n.removeListener("connect",d),t.signal!=null&&t.signal.removeEventListener("abort",x),f!=null){s(f);return}o(n)};n.on("error",c),n.on("timeout",u),n.on("connect",d),t.signal.addEventListener("abort",x)}).catch(o=>{throw n?.destroy(),o})}createListener(e){return new ot({...this.opts.listenOpts??{},...e,maxConnections:this.opts.maxConnections,backlog:this.opts.backlog,closeServerOnMaxConnections:this.opts.closeServerOnMaxConnections,socketInactivityTimeout:this.opts.inboundSocketInactivityTimeout,socketCloseTimeout:this.opts.socketCloseTimeout,metrics:this.components.metrics,logger:this.components.logger})}listenFilter(e){return e.filter(t=>an.exactMatch(t)||t.toString().startsWith("/unix/"))}dialFilter(e){return this.listenFilter(e)}};function Rs(r={}){return e=>new st(e,r)}return On($s);})();
|
|
2
|
+
"use strict";var Libp2PTcp=(()=>{var Mn=Object.create;var qe=Object.defineProperty;var Vn=Object.getOwnPropertyDescriptor;var $n=Object.getOwnPropertyNames;var zn=Object.getPrototypeOf,Fn=Object.prototype.hasOwnProperty;var M=(r=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(r,{get:(e,t)=>(typeof require<"u"?require:e)[t]}):r)(function(r){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+r+'" is not supported')});var N=(r,e)=>{for(var t in e)qe(r,t,{get:e[t],enumerable:!0})},Ir=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of $n(e))!Fn.call(r,o)&&o!==t&&qe(r,o,{get:()=>e[o],enumerable:!(n=Vn(e,o))||n.enumerable});return r};var ce=(r,e,t)=>(t=r!=null?Mn(zn(r)):{},Ir(e||!r||!r.__esModule?qe(t,"default",{value:r,enumerable:!0}):t,r)),Wn=r=>Ir(qe({},"__esModule",{value:!0}),r);var Ks={};N(Ks,{tcp:()=>Js});var kn=ce(M("net"),1);var je=class extends Error{static name="AbortError";constructor(e="The operation was aborted"){super(e),this.name="AbortError"}};var q=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}};var He=class extends Error{static name="StreamResetError";constructor(e="The stream has been reset"){super(e),this.name="StreamResetError"}};var re=class extends Error{static name="StreamStateError";constructor(e="The stream is in an invalid state"){super(e),this.name="StreamStateError"}},Ae=class extends Error{static name="StreamBufferError";constructor(e="The stream buffer was full"){super(e),this.name="StreamBufferError"}};var ue=class extends Error{static name="TimeoutError";constructor(e="Timed out"){super(e),this.name="TimeoutError"}},Ge=class extends Error{static name="NotStartedError";constructor(e="Not started"){super(e),this.name="NotStartedError"}},Qe=class extends Error{static name="AlreadyStartedError";constructor(e="Already started"){super(e),this.name="AlreadyStartedError"}};var Xe=class extends Event{data;constructor(e,t){super("message",t),this.data=e}},le=class extends Event{error;local;constructor(e,t,n){super("close",n),this.error=t,this.local=e}},Je=class extends le{constructor(e,t){super(!0,e,t)}},Ke=class extends le{constructor(e,t){super(!1,e,t)}};var Tr=Symbol.for("@libp2p/transport");var Dr;(function(r){r[r.FATAL_ALL=0]="FATAL_ALL",r[r.NO_FATAL=1]="NO_FATAL"})(Dr||(Dr={}));var Ar=M("node:events"),Ye=(r,...e)=>{try{(0,Ar.setMaxListeners)(r,...e)}catch{}};var fe=class extends EventTarget{#e=new Map;constructor(){super(),Ye(1/0,this)}listenerCount(e){let t=this.#e.get(e);return t==null?0:t.length}addEventListener(e,t,n){super.addEventListener(e,t,n);let o=this.#e.get(e);o==null&&(o=[],this.#e.set(e,o)),o.push({callback:t,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(e,t,n){super.removeEventListener(e.toString(),t??null,n);let o=this.#e.get(e);o!=null&&(o=o.filter(({callback:s})=>s!==t),this.#e.set(e,o))}dispatchEvent(e){let t=super.dispatchEvent(e),n=this.#e.get(e.type);return n==null||(n=n.filter(({once:o})=>!o),this.#e.set(e.type,n)),t}safeDispatchEvent(e,t={}){return this.dispatchEvent(new CustomEvent(e,t))}};var Pr=Symbol.for("@libp2p/service-capabilities"),si=Symbol.for("@libp2p/service-dependencies");var Kr=M("node:buffer");var Tt={};N(Tt,{base10:()=>Jn});var Oi=new Uint8Array(0);function Lr(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}function V(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")}function _r(r){return new TextEncoder().encode(r)}function Or(r){return new TextDecoder().decode(r)}function qn(r,e){if(r.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),n=0;n<t.length;n++)t[n]=255;for(var o=0;o<r.length;o++){var s=r.charAt(o),i=s.charCodeAt(0);if(t[i]!==255)throw new TypeError(s+" is ambiguous");t[i]=o}var a=r.length,c=r.charAt(0),l=Math.log(a)/Math.log(256),h=Math.log(256)/Math.log(a);function f(g){if(g instanceof Uint8Array||(ArrayBuffer.isView(g)?g=new Uint8Array(g.buffer,g.byteOffset,g.byteLength):Array.isArray(g)&&(g=Uint8Array.from(g))),!(g instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(g.length===0)return"";for(var S=0,p=0,I=0,O=g.length;I!==O&&g[I]===0;)I++,S++;for(var A=(O-I)*h+1>>>0,B=new Uint8Array(A);I!==O;){for(var k=g[I],X=0,F=A-1;(k!==0||X<p)&&F!==-1;F--,X++)k+=256*B[F]>>>0,B[F]=k%a>>>0,k=k/a>>>0;if(k!==0)throw new Error("Non-zero carry");p=X,I++}for(var H=A-p;H!==A&&B[H]===0;)H++;for(var We=c.repeat(S);H<A;++H)We+=r.charAt(B[H]);return We}function x(g){if(typeof g!="string")throw new TypeError("Expected String");if(g.length===0)return new Uint8Array;var S=0;if(g[S]!==" "){for(var p=0,I=0;g[S]===c;)p++,S++;for(var O=(g.length-S)*l+1>>>0,A=new Uint8Array(O);g[S];){var B=t[g.charCodeAt(S)];if(B===255)return;for(var k=0,X=O-1;(B!==0||k<I)&&X!==-1;X--,k++)B+=a*A[X]>>>0,A[X]=B%256>>>0,B=B/256>>>0;if(B!==0)throw new Error("Non-zero carry");I=k,S++}if(g[S]!==" "){for(var F=O-I;F!==O&&A[F]===0;)F++;for(var H=new Uint8Array(p+(O-F)),We=p;F!==O;)H[We++]=A[F++];return H}}}function d(g){var S=x(g);if(S)return S;throw new Error(`Non-${e} character`)}return{encode:f,decodeUnsafe:x,decode:d}}var jn=qn,Hn=jn,Nr=Hn;var Ct=class{name;prefix;baseEncode;constructor(e,t,n){this.name=e,this.prefix=t,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},St=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,t,n){this.name=e,this.prefix=t;let o=t.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 Ur(this,e)}},It=class{decoders;constructor(e){this.decoders=e}or(e){return Ur(this,e)}decode(e){let t=e[0],n=this.decoders[t];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 Ur(r,e){return new It({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var Dt=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,t,n,o){this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=o,this.encoder=new Ct(e,t,n),this.decoder=new St(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function he({name:r,prefix:e,encode:t,decode:n}){return new Dt(r,e,t,n)}function J({name:r,prefix:e,alphabet:t}){let{encode:n,decode:o}=Nr(t,r);return he({prefix:e,name:r,encode:n,decode:s=>V(o(s))})}function Gn(r,e,t,n){let o=r.length;for(;r[o-1]==="=";)--o;let s=new Uint8Array(o*t/8|0),i=0,a=0,c=0;for(let l=0;l<o;++l){let h=e[r[l]];if(h===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<t|h,i+=t,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=t||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function Qn(r,e,t){let n=e[e.length-1]==="=",o=(1<<t)-1,s="",i=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],i+=8;i>t;)i-=t,s+=e[o&a>>i];if(i!==0&&(s+=e[o&a<<t-i]),n)for(;(s.length*t&7)!==0;)s+="=";return s}function Xn(r){let e={};for(let t=0;t<r.length;++t)e[r[t]]=t;return e}function C({name:r,prefix:e,bitsPerChar:t,alphabet:n}){let o=Xn(n);return he({prefix:e,name:r,encode(s){return Qn(s,n,t)},decode(s){return Gn(s,o,t,r)}})}var Jn=J({prefix:"9",name:"base10",alphabet:"0123456789"});var At={};N(At,{base16:()=>Kn,base16upper:()=>Yn});var Kn=C({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Yn=C({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Pt={};N(Pt,{base2:()=>Zn});var Zn=C({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Lt={};N(Lt,{base256emoji:()=>oo});var Rr=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}"),eo=Rr.reduce((r,e,t)=>(r[t]=e,r),[]),to=Rr.reduce((r,e,t)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return r[n]=t,r},[]);function ro(r){return r.reduce((e,t)=>(e+=eo[t],e),"")}function no(r){let e=[];for(let t of r){let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);let o=to[n];if(o==null)throw new Error(`Non-base256emoji character: ${t}`);e.push(o)}return new Uint8Array(e)}var oo=he({prefix:"\u{1F680}",name:"base256emoji",encode:ro,decode:no});var _t={};N(_t,{base32:()=>K,base32hex:()=>co,base32hexpad:()=>lo,base32hexpadupper:()=>fo,base32hexupper:()=>uo,base32pad:()=>io,base32padupper:()=>ao,base32upper:()=>so,base32z:()=>ho});var K=C({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),so=C({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),io=C({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),ao=C({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),co=C({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),uo=C({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),lo=C({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),fo=C({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),ho=C({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Ot={};N(Ot,{base36:()=>Pe,base36upper:()=>po});var Pe=J({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),po=J({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Bt={};N(Bt,{base58btc:()=>$,base58flickr:()=>mo});var $=J({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),mo=J({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Ut={};N(Ut,{base64:()=>go,base64pad:()=>bo,base64url:()=>Nt,base64urlpad:()=>wo});var go=C({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),bo=C({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Nt=C({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),wo=C({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Rt={};N(Rt,{base8:()=>xo});var xo=C({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var kt={};N(kt,{identity:()=>yo});var yo=he({prefix:"\0",name:"identity",encode:r=>Or(r),decode:r=>_r(r)});var Qi=new TextEncoder,Xi=new TextDecoder;var Vt={};N(Vt,{identity:()=>Wo});var Co=Vr,kr=128,So=127,Io=~So,Do=Math.pow(2,31);function Vr(r,e,t){e=e||[],t=t||0;for(var n=t;r>=Do;)e[t++]=r&255|kr,r/=128;for(;r&Io;)e[t++]=r&255|kr,r>>>=7;return e[t]=r|0,Vr.bytes=t-n+1,e}var To=Mt,Ao=128,Mr=127;function Mt(r,n){var t=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw Mt.bytes=0,new RangeError("Could not decode varint");i=r[s++],t+=o<28?(i&Mr)<<o:(i&Mr)*Math.pow(2,o),o+=7}while(i>=Ao);return Mt.bytes=s-n,t}var Po=Math.pow(2,7),Lo=Math.pow(2,14),_o=Math.pow(2,21),Oo=Math.pow(2,28),Bo=Math.pow(2,35),No=Math.pow(2,42),Uo=Math.pow(2,49),Ro=Math.pow(2,56),ko=Math.pow(2,63),Mo=function(r){return r<Po?1:r<Lo?2:r<_o?3:r<Oo?4:r<Bo?5:r<No?6:r<Uo?7:r<Ro?8:r<ko?9:10},Vo={encode:Co,decode:To,encodingLength:Mo},$o=Vo,Le=$o;function _e(r,e=0){return[Le.decode(r,e),Le.decode.bytes]}function de(r,e,t=0){return Le.encode(r,e,t),e}function pe(r){return Le.encodingLength(r)}function ge(r,e){let t=e.byteLength,n=pe(r),o=n+pe(t),s=new Uint8Array(o+t);return de(r,s,0),de(t,s,n),s.set(e,o),new me(r,t,e,s)}function $r(r){let e=V(r),[t,n]=_e(e),[o,s]=_e(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new me(t,o,i,e)}function zr(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&Lr(r.bytes,t.bytes)}}var me=class{code;size;digest;bytes;constructor(e,t,n,o){this.code=e,this.size=t,this.digest=n,this.bytes=o}};var Fr=0,zo="identity",Wr=V;function Fo(r,e){if(e?.truncate!=null&&e.truncate!==r.byteLength){if(e.truncate<0||e.truncate>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,e.truncate)}return ge(Fr,Wr(r))}var Wo={code:Fr,name:zo,encode:Wr,digest:Fo};var Wt={};N(Wt,{sha256:()=>jo,sha512:()=>Ho});var Ft=ce(M("crypto"),1);var qo=20;function zt({name:r,code:e,encode:t,minDigestLength:n,maxDigestLength:o}){return new $t(r,e,t,n,o)}var $t=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,t,n,o,s){this.name=e,this.code=t,this.encode=n,this.minDigestLength=o??qo,this.maxDigestLength=s}digest(e,t){if(t?.truncate!=null){if(t.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&t.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?qr(n,this.code,t?.truncate):n.then(o=>qr(o,this.code,t?.truncate))}else throw Error("Unknown type, must be binary type")}};function qr(r,e,t){if(t!=null&&t!==r.byteLength){if(t>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,t)}return ge(e,r)}var jo=zt({name:"sha2-256",code:18,encode:r=>V(Ft.default.createHash("sha256").update(r).digest())}),Ho=zt({name:"sha2-512",code:19,encode:r=>V(Ft.default.createHash("sha512").update(r).digest())});function Hr(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return Qo(t,qt(r),e??$.encoder);default:return Xo(t,qt(r),e??K.encoder)}}var Gr=new WeakMap;function qt(r){let e=Gr.get(r);if(e==null){let t=new Map;return Gr.set(r,t),t}return e}var Y=class r{code;version;multihash;bytes;"/";constructor(e,t,n,o){this.code=t,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:t}=this;if(e!==Be)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==Jo)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(t)}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:t}=this.multihash,n=ge(e,t);return r.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 r.equals(this,e)}static equals(e,t){let n=t;return n!=null&&e.code===n.code&&e.version===n.version&&zr(e.multihash,n.multihash)}toString(e){return Hr(this,e)}toJSON(){return{"/":Hr(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 t=e;if(t instanceof r)return t;if(t["/"]!=null&&t["/"]===t.bytes||t.asCID===t){let{version:n,code:o,multihash:s,bytes:i}=t;return new r(n,o,s,i??Qr(n,o,s.bytes))}else if(t[Ko]===!0){let{version:n,multihash:o,code:s}=t,i=$r(o);return r.create(n,s,i)}else return null}static create(e,t,n){if(typeof t!="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(t!==Be)throw new Error(`Version 0 CID must use dag-pb (code: ${Be}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let o=Qr(e,t,n.bytes);return new r(e,t,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,Be,e)}static createV1(e,t){return r.create(1,e,t)}static decode(e){let[t,n]=r.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return t}static decodeFirst(e){let t=r.inspectBytes(e),n=t.size-t.multihashSize,o=V(e.subarray(n,n+t.multihashSize));if(o.byteLength!==t.multihashSize)throw new Error("Incorrect length");let s=o.subarray(t.multihashSize-t.digestSize),i=new me(t.multihashCode,t.digestSize,s,o);return[t.version===0?r.createV0(i):r.createV1(t.codec,i),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[f,x]=_e(e.subarray(t));return t+=x,f},o=n(),s=Be;if(o===18?(o=0,t=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=t,a=n(),c=n(),l=t+c,h=l-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:h,size:l}}static parse(e,t){let[n,o]=Go(e,t),s=r.decode(o);if(s.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return qt(s).set(n,e),s}};function Go(r,e){switch(r[0]){case"Q":{let t=e??$;return[$.prefix,t.decode(`${$.prefix}${r}`)]}case $.prefix:{let t=e??$;return[$.prefix,t.decode(r)]}case K.prefix:{let t=e??K;return[K.prefix,t.decode(r)]}case Pe.prefix:{let t=e??Pe;return[Pe.prefix,t.decode(r)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],e.decode(r)]}}}function Qo(r,e,t){let{prefix:n}=t;if(n!==$.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let o=e.get(n);if(o==null){let s=t.encode(r).slice(1);return e.set(n,s),s}else return o}function Xo(r,e,t){let{prefix:n}=t,o=e.get(n);if(o==null){let s=t.encode(r);return e.set(n,s),s}else return o}var Be=112,Jo=18;function Qr(r,e,t){let n=pe(r),o=n+pe(e),s=new Uint8Array(o+t.byteLength);return de(r,s,0),de(e,s,n),s.set(t,o),s}var Ko=Symbol.for("@ipld/js-cid/CID");var Ne={...kt,...Pt,...Rt,...Tt,...At,..._t,...Ot,...Bt,...Ut,...Lt},wa={...Wt,...Vt};var jt=M("node:buffer");function ne(r){return new Uint8Array(r.buffer,r.byteOffset,r.byteLength)}function G(r=0){return ne(jt.Buffer.alloc(r))}function be(r=0){return ne(jt.Buffer.allocUnsafe(r))}function Jr(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var Xr=Jr("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Ht=Jr("ascii","a",r=>{let e="a";for(let t=0;t<r.length;t++)e+=String.fromCharCode(r[t]);return e},r=>{r=r.substring(1);let e=be(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),Yo={utf8:Xr,"utf-8":Xr,hex:Ne.base16,latin1:Ht,ascii:Ht,binary:Ht,...Ne},et=Yo;function z(r,e="utf8"){let t=et[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return e==="utf8"||e==="utf-8"?Kr.Buffer.from(r.buffer,r.byteOffset,r.byteLength).toString("utf8"):t.encoder.encode(r).substring(1)}var P=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},Q=class extends Error{static name="ValidationError";name="ValidationError"},Ue=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},tt=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};function rt(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}var Yr=M("node:buffer");function Z(r,e="utf8"){let t=et[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return e==="utf8"||e==="utf-8"?ne(Yr.Buffer.from(r,"utf-8")):t.decoder.decode(`${t.prefix}${r}`)}var Zo=Math.pow(2,7),es=Math.pow(2,14),ts=Math.pow(2,21),Gt=Math.pow(2,28),Qt=Math.pow(2,35),Xt=Math.pow(2,42),Jt=Math.pow(2,49),v=128,L=127;function we(r){if(r<Zo)return 1;if(r<es)return 2;if(r<ts)return 3;if(r<Gt)return 4;if(r<Qt)return 5;if(r<Xt)return 6;if(r<Jt)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Kt(r,e,t=0){switch(we(r)){case 8:e[t++]=r&255|v,r/=128;case 7:e[t++]=r&255|v,r/=128;case 6:e[t++]=r&255|v,r/=128;case 5:e[t++]=r&255|v,r/=128;case 4:e[t++]=r&255|v,r>>>=7;case 3:e[t++]=r&255|v,r>>>=7;case 2:e[t++]=r&255|v,r>>>=7;case 1:{e[t++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return e}function rs(r,e){let t=r[e],n=0;if(n+=t&L,t<v||(t=r[e+1],n+=(t&L)<<7,t<v)||(t=r[e+2],n+=(t&L)<<14,t<v)||(t=r[e+3],n+=(t&L)<<21,t<v)||(t=r[e+4],n+=(t&L)*Gt,t<v)||(t=r[e+5],n+=(t&L)*Qt,t<v)||(t=r[e+6],n+=(t&L)*Xt,t<v)||(t=r[e+7],n+=(t&L)*Jt,t<v))return n;throw new RangeError("Could not decode varint")}function ns(r,e){let t=r.get(e),n=0;if(n+=t&L,t<v||(t=r.get(e+1),n+=(t&L)<<7,t<v)||(t=r.get(e+2),n+=(t&L)<<14,t<v)||(t=r.get(e+3),n+=(t&L)<<21,t<v)||(t=r.get(e+4),n+=(t&L)*Gt,t<v)||(t=r.get(e+5),n+=(t&L)*Qt,t<v)||(t=r.get(e+6),n+=(t&L)*Xt,t<v)||(t=r.get(e+7),n+=(t&L)*Jt,t<v))return n;throw new RangeError("Could not decode varint")}function Yt(r,e=0){return r instanceof Uint8Array?rs(r,e):ns(r,e)}var Zr=M("node:buffer");function ee(r,e){return ne(Zr.Buffer.concat(r,e))}var U=M("node:net");function er(r){return e=>z(e,r)}function tr(r){return e=>Z(e,r)}function xe(r){return new DataView(r.buffer).getUint16(r.byteOffset).toString()}function oe(r){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,typeof r=="string"?parseInt(r):r),new Uint8Array(e)}function en(r){let e=r.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 t=Z(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=oe(n);return ee([t,o],t.length+o.length)}function tn(r){let e=r.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 t=K.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=oe(n);return ee([t,o],t.length+o.length)}function rr(r){let e=r.subarray(0,r.length-2),t=r.subarray(r.length-2),n=z(e,"base32"),o=xe(t);return`${n}:${o}`}var nr=function(r){r=r.toString().trim();let e=new Uint8Array(4);return r.split(/\./g).forEach((t,n)=>{let o=parseInt(t,10);if(isNaN(o)||o<0||o>255)throw new P("Invalid byte value in IP address");e[n]=o}),e},rn=function(r){let e=0;r=r.toString().trim();let t=r.split(":",8),n;for(n=0;n<t.length;n++){let s=(0,U.isIPv4)(t[n]),i;s&&(i=nr(t[n]),t[n]=z(i.subarray(0,2),"base16")),i!=null&&++n<8&&t.splice(n,0,z(i.subarray(2,4),"base16"))}if(t[0]==="")for(;t.length<8;)t.unshift("0");else if(t[t.length-1]==="")for(;t.length<8;)t.push("0");else if(t.length<8){for(n=0;n<t.length&&t[n]!=="";n++);let s=[n,1];for(n=9-t.length;n>0;n--)s.push("0");t.splice.apply(t,s)}let o=new Uint8Array(e+16);for(n=0;n<t.length;n++){t[n]===""&&(t[n]="0");let s=parseInt(t[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},nn=function(r){if(r.byteLength!==4)throw new P("IPv4 address was incorrect length");let e=[];for(let t=0;t<r.byteLength;t++)e.push(r[t]);return e.join(".")},on=function(r){if(r.byteLength!==16)throw new P("IPv6 address was incorrect length");let e=[];for(let n=0;n<r.byteLength;n+=2){let o=r[n],s=r[n+1],i=`${o.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}`;e.push(i)}let t=e.join(":");try{let n=new URL(`http://[${t}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new P(`Invalid IPv6 address "${t}"`)}};function sn(r){try{let e=new URL(`http://[${r}]`);return e.hostname.substring(1,e.hostname.length-1)}catch{throw new P(`Invalid IPv6 address "${r}"`)}}var Zt=Object.values(Ne).map(r=>r.decoder),ss=(function(){let r=Zt[0].or(Zt[1]);return Zt.slice(2).forEach(e=>r=r.or(e)),r})();function an(r){return ss.decode(r)}function cn(r){return e=>r.encoder.encode(e)}function is(r){if(parseInt(r).toString()!==r)throw new Q("Value must be an integer")}function as(r){if(r<0)throw new Q("Value must be a positive integer, or zero")}function cs(r){return e=>{if(e>r)throw new Q(`Value must be smaller than or equal to ${r}`)}}function us(...r){return e=>{for(let t of r)t(e)}}var Re=us(is,as,cs(65535));var D=-1,or=class{protocolsByCode=new Map;protocolsByName=new Map;getProtocol(e){let t;if(typeof e=="string"?t=this.protocolsByName.get(e):t=this.protocolsByCode.get(e),t==null)throw new tt(`Protocol ${e} was unknown`);return t}addProtocol(e){this.protocolsByCode.set(e.code,e),this.protocolsByName.set(e.name,e),e.aliases?.forEach(t=>{this.protocolsByName.set(t,e)})}removeProtocol(e){let t=this.protocolsByCode.get(e);t!=null&&(this.protocolsByCode.delete(t.code),this.protocolsByName.delete(t.name),t.aliases?.forEach(n=>{this.protocolsByName.delete(n)}))}},R=new or,Ss=[{code:4,name:"ip4",size:32,valueToBytes:nr,bytesToValue:nn,validate:r=>{if(!(0,U.isIPv4)(r))throw new Q(`Invalid IPv4 address "${r}"`)}},{code:6,name:"tcp",size:16,valueToBytes:oe,bytesToValue:xe,validate:Re},{code:273,name:"udp",size:16,valueToBytes:oe,bytesToValue:xe,validate:Re},{code:33,name:"dccp",size:16,valueToBytes:oe,bytesToValue:xe,validate:Re},{code:41,name:"ip6",size:128,valueToBytes:rn,bytesToValue:on,stringToValue:sn,validate:r=>{if(!(0,U.isIPv6)(r))throw new Q(`Invalid IPv6 address "${r}"`)}},{code:42,name:"ip6zone",size:D},{code:43,name:"ipcidr",size:8,bytesToValue:er("base10"),valueToBytes:tr("base10")},{code:53,name:"dns",size:D,resolvable:!0},{code:54,name:"dns4",size:D,resolvable:!0},{code:55,name:"dns6",size:D,resolvable:!0},{code:56,name:"dnsaddr",size:D,resolvable:!0},{code:132,name:"sctp",size:16,valueToBytes:oe,bytesToValue:xe,validate:Re},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:D,path:!0,stringToValue:r=>decodeURIComponent(r),valueToString:r=>encodeURIComponent(r)},{code:421,name:"p2p",aliases:["ipfs"],size:D,bytesToValue:er("base58btc"),valueToBytes:r=>r.startsWith("Q")||r.startsWith("1")?tr("base58btc")(r):Y.parse(r).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:rr,valueToBytes:en},{code:445,name:"onion3",size:296,bytesToValue:rr,valueToBytes:tn},{code:446,name:"garlic64",size:D},{code:447,name:"garlic32",size:D},{code:448,name:"tls"},{code:449,name:"sni",size:D},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:D,bytesToValue:cn(Nt),valueToBytes:an},{code:480,name:"http"},{code:481,name:"http-path",size:D,stringToValue:r=>`/${decodeURIComponent(r)}`,valueToString:r=>encodeURIComponent(r.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:D}];Ss.forEach(r=>{R.addProtocol(r)});function un(r){let e=[],t=0;for(;t<r.length;){let n=Yt(r,t),o=R.getProtocol(n),s=we(n),i=Is(o,r,t+s),a=0;i>0&&o.size===D&&(a=we(i));let c=s+a+i,l={code:n,name:o.name,bytes:r.subarray(t,t+c)};if(i>0){let h=t+s+a,f=r.subarray(h,h+i);l.value=o.bytesToValue?.(f)??z(f)}e.push(l),t+=c}return e}function ln(r){let e=0,t=[];for(let n of r){if(n.bytes==null){let o=R.getProtocol(n.code),s=we(n.code),i,a=0,c=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??Z(n.value),a=i.byteLength,o.size===D&&(c=we(a)));let l=new Uint8Array(s+c+a),h=0;Kt(n.code,l,h),h+=s,i!=null&&(o.size===D&&(Kt(a,l,h),h+=c),l.set(i,h)),n.bytes=l}t.push(n.bytes),e+=n.bytes.byteLength}return ee(t,e)}function fn(r){if(r.charAt(0)!=="/")throw new P('String multiaddr must start with "/"');let e=[],t="protocol",n="",o="";for(let s=1;s<r.length;s++){let i=r.charAt(s);i!=="/"&&(t==="protocol"?o+=r.charAt(s):n+=r.charAt(s));let a=s===r.length-1;if(i==="/"||a){let c=R.getProtocol(o);if(t==="protocol"){if(c.size==null||c.size===0){e.push({code:c.code,name:c.name}),n="",o="",t="protocol";continue}else if(a)throw new P(`Component ${o} was missing value`);t="value"}else if(t==="value"){let l={code:c.code,name:c.name};if(c.size!=null&&c.size!==0){if(n==="")throw new P(`Component ${o} was missing value`);l.value=c.stringToValue?.(n)??n}e.push(l),n="",o="",t="protocol"}}}if(o!==""&&n!=="")throw new P("Incomplete multiaddr");return e}function hn(r){return`/${r.flatMap(e=>{if(e.value==null)return e.name;let t=R.getProtocol(e.code);if(t==null)throw new P(`Unknown protocol code ${e.code}`);return[e.name,t.valueToString?.(e.value)??e.value]}).join("/")}`}function Is(r,e,t){return r.size==null||r.size===0?0:r.size>0?r.size/8:Yt(e,t)}var Ds=Symbol.for("nodejs.util.inspect.custom"),pr=Symbol.for("@multiformats/multiaddr"),Ts=[53,54,55,56],dr=class extends Error{constructor(e="No available resolver"){super(e),this.name="NoAvailableResolverError"}};function As(r){if(r==null&&(r="/"),pn(r))return r.getComponents();if(r instanceof Uint8Array)return un(r);if(typeof r=="string")return r=r.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),r===""&&(r="/"),fn(r);if(Array.isArray(r))return r;throw new P("Must be a string, Uint8Array, Component[], or another Multiaddr")}var it=class r{[pr]=!0;#e;#t;#r;constructor(e="/",t={}){this.#e=As(e),t.validate!==!1&&Ps(this)}get bytes(){return this.#r==null&&(this.#r=ln(this.#e)),this.#r}toString(){return this.#t==null&&(this.#t=hn(this.#e)),this.#t}toJSON(){return this.toString()}toOptions(){let e,t,n,o,s="";for(let{code:a,name:c,value:l}of this.#e)a===42&&(s=`%${l??""}`),Ts.includes(a)&&(t="tcp",o=443,n=`${l??""}${s}`,e=a===55?6:4),(a===6||a===273)&&(t=c==="tcp"?"tcp":"udp",o=parseInt(l??"")),(a===4||a===41)&&(t="tcp",n=`${l??""}${s}`,e=a===41?6:4);if(e==null||t==null||n==null||o==null)throw new Error('multiaddr must have a valid format: "/{ip4, ip6, dns4, dns6, dnsaddr}/{address}/{tcp, udp}/{port}".');return{family:e,host:n,transport:t,port:o}}getComponents(){return[...this.#e]}protos(){return this.#e.map(({code:e,value:t})=>{let n=R.getProtocol(e);return{code:e,size:n.size??0,name:n.name,resolvable:!!n.resolvable,path:!!n.path}})}protoCodes(){return this.#e.map(({code:e})=>e)}protoNames(){return this.#e.map(({name:e})=>e)}tuples(){return this.#e.map(({code:e,value:t})=>{if(t==null)return[e];let n=R.getProtocol(e),o=[e];return t!=null&&o.push(n.valueToBytes?.(t)??Z(t)),o})}stringTuples(){return this.#e.map(({code:e,value:t})=>t==null?[e]:[e,t])}encapsulate(e){let t=new r(e);return new r([...this.#e,...t.getComponents()],{validate:!1})}decapsulate(e){let t=e.toString(),n=this.toString(),o=n.lastIndexOf(t);if(o<0)throw new Ue(`Address ${this.toString()} does not contain subaddress: ${e.toString()}`);return new r(n.slice(0,o),{validate:!1})}decapsulateCode(e){let t;for(let n=this.#e.length-1;n>-1;n--)if(this.#e[n].code===e){t=n;break}return new r(this.#e.slice(0,t),{validate:!1})}getPeerId(){try{let e=[];this.#e.forEach(({code:n,value:o})=>{n===421&&e.push([n,o]),n===290&&(e=[])});let t=e.pop();if(t?.[1]!=null){let n=t[1];return n[0]==="Q"||n[0]==="1"?z($.decode(`z${n}`),"base58btc"):z(Y.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){for(let e of this.#e)if(R.getProtocol(e.code).path)return e.value??null;return null}equals(e){return rt(this.bytes,e.bytes)}async resolve(e){let t=this.protos().find(s=>s.resolvable);if(t==null)return[this];let n=dn.get(t.name);if(n==null)throw new dr(`no available resolver for ${t.name}`);return(await n(this,e)).map(s=>W(s))}nodeAddress(){let e=this.toOptions();if(e.transport!=="tcp"&&e.transport!=="udp")throw new Error(`multiaddr must have a valid format - no protocol with name: "${e.transport}". Must have a valid transport protocol: "{tcp, udp}"`);return{family:e.family,address:e.host,port:e.port}}isThinWaistAddress(){return!(this.#e.length!==2||this.#e[0].code!==4&&this.#e[0].code!==41||this.#e[1].code!==6&&this.#e[1].code!==273)}[Ds](){return`Multiaddr(${this.toString()})`}};function Ps(r){r.getComponents().forEach(e=>{let t=R.getProtocol(e.code);e.value!=null&&t.validate?.(e.value)})}var at=class{index=0;input="";new(e){return this.index=0,this.input=e,this}readAtomically(e){let t=this.index,n=e();return n===void 0&&(this.index=t),n}parseWith(e){let t=e();if(this.index===this.input.length)return t}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 t=this.readChar();if(t===e)return t})}readSeparator(e,t,n){return this.readAtomically(()=>{if(!(t>0&&this.readGivenChar(e)===void 0))return n()})}readNumber(e,t,n,o){return this.readAtomically(()=>{let s=0,i=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",l=2**(8*o)-1;for(;;){let h=this.readAtomically(()=>{let f=this.readChar();if(f===void 0)return;let x=Number.parseInt(f,e);if(!Number.isNaN(x))return x});if(h===void 0)break;if(s*=e,s+=h,s>l||(i+=1,t!==void 0&&i>t))return}if(i!==0)return!n&&c&&i>1?void 0:s})}readIPv4Addr(){return this.readAtomically(()=>{let e=new Uint8Array(4);for(let t=0;t<e.length;t++){let n=this.readSeparator(".",t,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;e[t]=n}return e})}readIPv6Addr(){let e=t=>{for(let n=0;n<t.length/2;n++){let o=n*2;if(n<t.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return t[o]=i[0],t[o+1]=i[1],t[o+2]=i[2],t[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];t[o]=s>>8,t[o+1]=s&255}return[t.length,!1]};return this.readAtomically(()=>{let t=new Uint8Array(16),[n,o]=e(t);if(n===16)return t;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 t.set(s.subarray(0,a),16-a),t})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var Ec=new at;var Pc=parseInt("0xFFFF",16),Lc=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);var dn=new Map;function pn(r){return!!r?.[pr]}function W(r){return new it(r)}var E=r=>({match:e=>{let t=e[0];return t==null||t.code!==r||t.value!=null?!1:e.slice(1)}}),u=(r,e)=>({match:t=>{let n=t[0];return n?.code!==r||n.value==null||e!=null&&n.value!==e?!1:t.slice(1)}}),m=r=>({match:e=>{let t=r.match(e);return t===!1?e:t}}),_=(...r)=>({match:e=>{let t;for(let n of r){let o=n.match(e);o!==!1&&(t==null||o.length<t.length)&&(t=o)}return t??!1}}),w=(...r)=>({match:e=>{for(let t of r){let n=t.match(e);if(n===!1)return!1;e=n}return e}});function y(...r){function e(o){if(o==null)return!1;let s=o.getComponents();for(let i of r){let a=i.match(s);if(a===!1)return!1;s=a}return s}function t(o){return e(o)!==!1}function n(o){let s=e(o);return s===!1?!1:s.length===0}return{matchers:r,matches:t,exactMatch:n}}var Us=u(421),yu=y(Us),ut=u(54),lt=u(55),ft=u(56),gr=u(53),Eu=y(ut,m(u(421))),vu=y(lt,m(u(421))),Cu=y(ft,m(u(421))),Su=y(_(gr,ft,ut,lt),m(u(421))),bn=w(u(4),m(u(43))),wn=w(m(u(42)),u(41),m(u(43))),br=_(bn,wn),ae=_(br,gr,ut,lt,ft),Iu=y(_(br,w(_(gr,ft,ut,lt),m(u(421))))),Du=y(bn),Tu=y(wn),Au=y(br),wr=w(ae,u(6)),Fe=w(ae,u(273)),xn=y(w(wr,m(u(421)))),Pu=y(Fe),xr=w(Fe,E(460),m(u(421))),ht=w(Fe,E(461),m(u(421))),Rs=_(xr,ht),Lu=y(xr),_u=y(ht),mr=_(ae,wr,Fe,xr,ht),yn=_(w(mr,E(477),m(u(421)))),Ou=y(yn),En=_(w(mr,E(478),m(u(421))),w(mr,E(448),m(u(449)),E(477),m(u(421)))),Bu=y(En),vn=w(Fe,E(280),m(u(466)),m(u(466)),m(u(421))),Nu=y(vn),Cn=w(ht,E(465),m(u(466)),m(u(466)),m(u(421))),Uu=y(Cn),ct=_(yn,En,w(wr,m(u(421))),w(Rs,m(u(421))),w(ae,m(u(421))),vn,Cn,u(421)),Ru=y(ct),ks=w(ct,E(290),u(421)),ku=y(ks),Ms=_(w(ct,E(290),E(281),m(u(421))),w(ct,E(281),m(u(421))),w(E(281),m(u(421)))),Mu=y(Ms),Vs=_(w(ae,u(6),E(480),m(u(421))),w(ae,E(480),m(u(421)))),Vu=y(Vs),$s=w(ae,_(w(u(6,"443"),E(480)),w(u(6),E(443)),w(u(6),E(448),E(480)),w(E(448),E(480)),E(448),E(443)),m(u(421))),$u=y($s),zs=_(w(u(777),m(u(421)))),zu=y(zs),Fs=_(w(u(400),m(u(421)))),Sn=y(Fs);var dt=class extends Event{type;detail;constructor(e,t){super(e),this.type=e,this.detail=t}};var Rn=ce(M("node:net"),1);var Dn=Symbol.for("@achingbrain/uint8arraylist");function In(r,e){if(e==null||e<0)throw new RangeError("index is out of bounds");let t=0;for(let n of r){let o=t+n.byteLength;if(e<o)return{buf:n,index:e-t};t=o}throw new RangeError("index is out of bounds")}function pt(r){return!!r?.[Dn]}var De=class r{bufs;length;[Dn]=!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 t=0;for(let n of e)if(n instanceof Uint8Array)t+=n.byteLength,this.bufs.push(n);else if(pt(n))t+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=t}prepend(...e){this.prependAll(e)}prependAll(e){let t=0;for(let n of e.reverse())if(n instanceof Uint8Array)t+=n.byteLength,this.bufs.unshift(n);else if(pt(n))t+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=t}get(e){let t=In(this.bufs,e);return t.buf[t.index]}set(e,t){let n=In(this.bufs,e);n.buf[n.index]=t}write(e,t=0){if(e instanceof Uint8Array)for(let n=0;n<e.length;n++)this.set(t+n,e[n]);else if(pt(e))for(let n=0;n<e.length;n++)this.set(t+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,t){let{bufs:n,length:o}=this._subList(e,t);return ee(n,o)}subarray(e,t){let{bufs:n,length:o}=this._subList(e,t);return n.length===1?n[0]:ee(n,o)}sublist(e,t){let{bufs:n,length:o}=this._subList(e,t),s=new r;return s.length=o,s.bufs=[...n],s}_subList(e,t){if(e=e??0,t=t??this.length,e<0&&(e=this.length+e),t<0&&(t=this.length+t),e<0||t>this.length)throw new RangeError("index is out of bounds");if(e===t)return{bufs:[],length:0};if(e===0&&t===this.length)return{bufs:this.bufs,length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],a=o,c=a+i.byteLength;if(o=c,e>=c)continue;let l=e>=a&&e<c,h=t>a&&t<=c;if(l&&h){if(e===a&&t===c){n.push(i);break}let f=e-a;n.push(i.subarray(f,f+(t-e)));break}if(l){if(e===0){n.push(i);continue}n.push(i.subarray(e-a));continue}if(h){if(t===c){n.push(i);break}n.push(i.subarray(0,t-a));break}n.push(i)}return{bufs:n,length:t-e}}indexOf(e,t=0){if(!pt(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(t=Number(t??0),isNaN(t)&&(t=0),t<0&&(t=this.length+t),t<0&&(t=0),e.length===0)return t>this.length?this.length:t;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 f=0;f<s;f++)i[f]=-1;for(let f=0;f<o;f++)i[n[f]]=f;let a=i,c=this.byteLength-n.byteLength,l=n.byteLength-1,h;for(let f=t;f<=c;f+=h){h=0;for(let x=l;x>=0;x--){let d=this.get(f+x);if(n[x]!==d){h=Math.max(1,x-a[d]);break}}if(h===0)return f}return-1}getInt8(e){let t=this.subarray(e,e+1);return new DataView(t.buffer,t.byteOffset,t.byteLength).getInt8(0)}setInt8(e,t){let n=be(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,t),this.write(n,e)}getInt16(e,t){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,t)}setInt16(e,t,n){let o=G(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,t,n),this.write(o,e)}getInt32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,t)}setInt32(e,t,n){let o=G(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,t,n),this.write(o,e)}getBigInt64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,t)}setBigInt64(e,t,n){let o=G(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,t,n),this.write(o,e)}getUint8(e){let t=this.subarray(e,e+1);return new DataView(t.buffer,t.byteOffset,t.byteLength).getUint8(0)}setUint8(e,t){let n=be(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,t),this.write(n,e)}getUint16(e,t){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,t)}setUint16(e,t,n){let o=G(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,t,n),this.write(o,e)}getUint32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,t)}setUint32(e,t,n){let o=G(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,t,n),this.write(o,e)}getBigUint64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,t)}setBigUint64(e,t,n){let o=G(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,t,n),this.write(o,e)}getFloat32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,t)}setFloat32(e,t,n){let o=G(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,t,n),this.write(o,e)}getFloat64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,t)}setFloat64(e,t,n){let o=G(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,t,n),this.write(o,e)}equals(e){if(e==null||!(e instanceof r)||e.bufs.length!==this.bufs.length)return!1;for(let t=0;t<this.bufs.length;t++)if(!rt(this.bufs[t],e.bufs[t]))return!1;return!0}static fromUint8Arrays(e,t){let n=new r;return n.bufs=e,t==null&&(t=e.reduce((o,s)=>o+s.byteLength,0)),n.length=t,n}};function mt(){let r={};return r.promise=new Promise((e,t)=>{r.resolve=e,r.reject=t}),r}var gt=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}},Te=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new gt(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 t=this.head;this.head=t.next=new gt(2*this.head.buffer.length),this.head.push(e)}}shift(){let e=this.tail.shift();if(e===void 0&&this.tail.next!=null){let t=this.tail.next;this.tail.next=null,this.tail=t,e=this.tail.shift()}return e?.value!=null&&(this.size-=this.calculateSize(e.value)),e}isEmpty(){return this.head.isEmpty()}};var yr=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.code=t??"ABORT_ERR"}};function Tn(r={}){return Ws(t=>{let n=t.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},r)}function Ws(r,e){e=e??{};let t=e.onEnd,n=new Te,o,s,i,a=mt(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((p,I)=>{s=O=>{s=null,n.push(O);try{p(r(n))}catch(A){I(A)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=mt()})}},l=p=>s!=null?s(p):(n.push(p),o),h=p=>(n=new Te,s!=null?s({error:p}):(n.push({error:p}),o)),f=p=>{if(i)return o;if(e?.objectMode!==!0&&p?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return l({done:!1,value:p})},x=p=>i?o:(i=!0,p!=null?h(p):l({done:!0})),d=()=>(n=new Te,x(),{done:!0}),g=p=>(x(p),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:d,throw:g,push:f,end:x,get readableLength(){return n.size},onEmpty:async p=>{let I=p?.signal;if(I?.throwIfAborted(),n.isEmpty())return;let O,A;I!=null&&(O=new Promise((B,k)=>{A=()=>{k(new yr)},I.addEventListener("abort",A)}));try{await Promise.race([a.promise,O])}finally{A!=null&&I!=null&&I?.removeEventListener("abort",A)}}},t==null)return o;let S=o;return o={[Symbol.asyncIterator](){return this},next(){return S.next()},throw(p){return S.throw(p),t!=null&&(t(p),t=void 0),{done:!0}},return(){return S.return(),t!=null&&(t(),t=void 0),{done:!0}},push:f,end(p){return S.end(p),t!=null&&(t(p),t=void 0),o},get readableLength(){return S.readableLength},onEmpty:p=>S.onEmpty(p)},o}var Er=class extends Error{constructor(e){super(e),this.name="TimeoutError"}},vr=class extends Error{constructor(e){super(),this.name="AbortError",this.message=e}},An=r=>globalThis.DOMException===void 0?new vr(r):new DOMException(r),Pn=r=>{let e=r.reason===void 0?An("This operation was aborted."):r.reason;return e instanceof Error?e:An(e)};function Cr(r,e){let{milliseconds:t,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout}}=e,i,a,l=new Promise((h,f)=>{if(typeof t!="number"||Math.sign(t)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${t}\``);if(e.signal){let{signal:d}=e;d.aborted&&f(Pn(d)),a=()=>{f(Pn(d))},d.addEventListener("abort",a,{once:!0})}if(t===Number.POSITIVE_INFINITY){r.then(h,f);return}let x=new Er;i=s.setTimeout.call(void 0,()=>{if(n){try{h(n())}catch(d){f(d)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?h():o instanceof Error?f(o):(x.message=o??`Promise timed out after ${t} milliseconds`,f(x))},t),(async()=>{try{h(await r)}catch(d){f(d)}})()}).finally(()=>{l.clear(),a&&e.signal&&e.signal.removeEventListener("abort",a)});return l.clear=()=>{s.clearTimeout.call(void 0,i),i=void 0},l}var qs=r=>{let e=r.addEventListener||r.on||r.addListener,t=r.removeEventListener||r.off||r.removeListener;if(!e||!t)throw new TypeError("Emitter is not compatible");return{addListener:e.bind(r),removeListener:t.bind(r)}};function js(r,e,t){let n,o=new Promise((s,i)=>{if(t={rejectionEvents:["error"],multiArgs:!1,resolveImmediately:!1,...t},!(t.count>=0&&(t.count===Number.POSITIVE_INFINITY||Number.isInteger(t.count))))throw new TypeError("The `count` option should be at least 0 or more");t.signal?.throwIfAborted();let a=[e].flat(),c=[],{addListener:l,removeListener:h}=qs(r),f=(...d)=>{let g=t.multiArgs?d:d[0];t.filter&&!t.filter(g)||(c.push(g),t.count===c.length&&(n(),s(c)))},x=d=>{n(),i(d)};n=()=>{for(let d of a)h(d,f);for(let d of t.rejectionEvents)h(d,x)};for(let d of a)l(d,f);for(let d of t.rejectionEvents)l(d,x);t.signal&&t.signal.addEventListener("abort",()=>{x(t.signal.reason)},{once:!0}),t.resolveImmediately&&s(c)});if(o.cancel=n,typeof t.timeout=="number"){let s=Cr(o,{milliseconds:t.timeout});return s.cancel=n,s}return o}function te(r,e,t){typeof t=="function"&&(t={filter:t}),t={...t,count:1,resolveImmediately:!1};let n=js(r,e,t),o=n.then(s=>s[0]);return o.cancel=n.cancel,o}var Hs=Math.pow(2,20)*4,bt=class extends fe{status;timeline;inactivityTimeout;maxReadBufferLength;maxWriteBufferLength;log;direction;maxMessageSize;readStatus;writeStatus;remoteReadStatus;remoteWriteStatus;writableNeedsDrain;readBuffer;writeBuffer;sendingData;constructor(e){super(),this.status="open",this.log=e.log,this.direction=e.direction??"outbound",this.inactivityTimeout=e.inactivityTimeout??12e4,this.maxReadBufferLength=e.maxReadBufferLength??Hs,this.maxWriteBufferLength=e.maxWriteBufferLength,this.maxMessageSize=e.maxMessageSize,this.readBuffer=new De,this.writeBuffer=new De,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 t=()=>{this.log.trace("drain event received, continue sending data"),this.writableNeedsDrain=!1,this.processSendQueue()};this.addEventListener("drain",t)}async*[Symbol.asyncIterator](){if(this.readStatus!=="readable"&&this.readStatus!=="paused")return;let e=Tn(),t=s=>{e.push(s.data)};this.addEventListener("message",t);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",t),this.removeEventListener("close",n),this.removeEventListener("remoteCloseWrite",o)}}isReadable(){return this.status==="open"}send(e){if(this.writeStatus==="closed"||this.writeStatus==="closing")throw new re(`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(t){this.log("failed to send reset to remote - %e",t)}this.dispatchEvent(new Je(e))}}pause(){if(this.readStatus==="closed"||this.readStatus==="closing")throw new re("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 re("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 re(`Cannot push data onto a stream that is ${this.readStatus}`);if(e.byteLength!==0){if(this.readBuffer.append(e),this.readStatus==="paused"||this.listenerCount("message")===0){this.checkReadBufferLength();return}setTimeout(()=>{this.dispatchReadBuffer()},0)}}onData(e){if(e.byteLength!==0){if(this.readStatus==="closing"||this.readStatus==="closed"){this.log("ignoring data - read status %s",this.readStatus);return}this.readBuffer.append(e),this.dispatchReadBuffer()}}addEventListener(...e){super.addEventListener.apply(this,e),e[0]==="message"&&this.readBuffer.byteLength>0&&queueMicrotask(()=>{this.dispatchReadBuffer()})}onRemoteReset(){this.log("remote reset"),this.status="reset",this.writeStatus="closed",this.remoteWriteStatus="closed",this.remoteReadStatus="closed",this.timeline.close=Date.now(),this.readBuffer.byteLength===0&&(this.readStatus="closed");let e=new He;this.dispatchEvent(new Ke(e))}onTransportClosed(e){this.log("transport closed"),this.readStatus==="readable"&&this.readBuffer.byteLength===0&&(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 le))}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,t=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 De(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,t,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 Xe(e))}finally{this.remoteWriteStatus==="closed"&&(this.readStatus="closed"),this.checkReadBufferLength()}}checkReadBufferLength(){this.readBuffer.byteLength>this.maxReadBufferLength&&this.abort(new Ae(`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 Ae(`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 wt=class extends bt{remoteAddr;metricPrefix;metrics;constructor(e){super(e),this.metricPrefix=e.metricPrefix??"",this.metrics=e.metrics,this.remoteAddr=e.remoteAddr,this.addEventListener("close",t=>{this.metrics?.increment({[`${this.metricPrefix}end`]:!0}),t.error!=null?t.local?this.metrics?.increment({[`${this.metricPrefix}abort`]:!0}):this.metrics?.increment({[`${this.metricPrefix}reset`]:!0}):t.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 te(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 te(this,"drain",{...e,rejectionEvents:["close"]})),await this.sendClose(e),this.onTransportClosed())}};var _n=ce(M("node:os"),1);function Ln(r){return!!(r.startsWith("169.254.")||r.toLowerCase().startsWith("fe80"))}var Gs={4:"IPv4",6:"IPv6"};function Qs(r){return["0.0.0.0","::"].includes(r)}function Xs(r){let e=[],t=_n.default.networkInterfaces();for(let[,n]of Object.entries(t))if(n!=null)for(let o of n)Ln(o.address)||o.family===Gs[r]&&e.push(o.address);return e}function On(r,e){if(r==null)return[];let t=r.toOptions();if(Qs(t.host)){let n=[];for(let o of Xs(t.family))n.push(W(`/ip${t.family}/${o}/${t.transport}/${e??t.port}`));return n}return[W(`/ip${t.family}/${t.host}/${t.transport}/${e??t.port}`)]}function Bn(r,e){if(typeof r!="string")throw new q(`invalid ip provided: ${r}`);if(typeof e=="string"&&(e=parseInt(e)),isNaN(e))throw new q(`invalid port provided: ${e}`);if((0,U.isIPv4)(r))return W(`/ip4/${r}/tcp/${e}`);if((0,U.isIPv6)(r))return W(`/ip6/${r}/tcp/${e}`);throw new q(`invalid ip:port for creating a multiaddr: ${r}:${e}`)}var Sr=class extends wt{socket;constructor(e){let t=e.remoteAddr;if(e.localAddr!=null&&Sn.matches(e.localAddr))t=e.localAddr;else if(t==null){if(e.socket.remoteAddress==null||e.socket.remotePort==null)throw new q("Could not determine remote address or port");t=Bn(e.socket.remoteAddress,e.socket.remotePort)}super({...e,remoteAddr:t}),this.socket=e.socket,this.socket.on("data",n=>{this.onData(n)}),this.socket.on("error",n=>{this.log("tcp error",t,n),this.abort(n)}),this.socket.setTimeout(e.inactivityTimeout??120*1e3),this.socket.once("timeout",()=>{this.log("tcp timeout",t),this.abort(new ue)}),this.socket.once("end",()=>{this.log("tcp end",t),this.onTransportClosed()}),this.socket.once("close",n=>{if(this.log("tcp close",t),n){this.abort(new Error("TCP transmission error"));return}this.onTransportClosed()}),this.socket.on("drain",()=>{this.log("tcp drain"),this.safeDispatchEvent("drain")})}sendData(e){let t=0,n=!0;for(let o of e)if(t+=o.byteLength,n=this.socket.write(o),!n)break;return{sentBytes:t,canSendMore:n}}async sendClose(e){this.socket.destroyed||(this.socket.destroySoon(),await te(this.socket,"close",e))}sendReset(){this.socket.resetAndDestroy()}sendPause(){this.socket.pause()}sendResume(){this.socket.resume()}},xt=r=>new Sr(r);var Nn=ce(M("os"),1),Un=ce(M("path"),1);function yt(r,e={}){let t=r.getPath();if(t!=null)return Nn.default.platform()==="win32"?{path:Un.default.join("\\\\.\\pipe\\",t)}:{path:t};let n=r.toOptions();return{...e,...n,ipv6Only:n.family===6}}var T;(function(r){r[r.INACTIVE=0]="INACTIVE",r[r.ACTIVE=1]="ACTIVE",r[r.PAUSED=2]="PAUSED"})(T||(T={}));var Et=class extends fe{context;server;sockets=new Set;status={code:T.INACTIVE};metrics;addr;log;shutdownController;constructor(e){if(super(),this.context=e,e.keepAlive=e.keepAlive??!0,e.noDelay=e.noDelay??!0,e.allowHalfOpen=e.allowHalfOpen??!1,this.shutdownController=new AbortController,Ye(1/0,this.shutdownController.signal),this.log=e.logger.forComponent("libp2p:tcp:listener"),this.addr="unknown",this.server=Rn.default.createServer(e,this.onSocket.bind(this)),e.maxConnections!==void 0&&(this.server.maxConnections=e.maxConnections),e.closeServerOnMaxConnections!=null&&e.closeServerOnMaxConnections.closeAbove<e.closeServerOnMaxConnections.listenBelow)throw new q("closeAbove must be >= listenBelow");e.metrics?.registerMetricGroup("libp2p_tcp_inbound_connections_total",{label:"address",help:"Current active connections in TCP listener",calculate:()=>({[this.addr]:this.sockets.size})}),this.metrics={status:e.metrics?.registerMetricGroup("libp2p_tcp_listener_status_info",{label:"address",help:"Current status of the TCP listener socket"}),errors:e.metrics?.registerMetricGroup("libp2p_tcp_listener_errors_total",{label:"address",help:"Total count of TCP listener errors by type"}),events:e.metrics?.registerMetricGroup("libp2p_tcp_listener_events_total",{label:"address",help:"Total count of TCP listener events by type"})},this.server.on("listening",()=>{let t=this.server.address();t==null?this.addr="unknown":typeof t=="string"?this.addr=t:this.addr=`${t.address}:${t.port}`,this.metrics.status?.update({[this.addr]:T.ACTIVE}),this.safeDispatchEvent("listening")}).on("error",t=>{this.metrics.errors?.increment({[`${this.addr} listen_error`]:!0}),this.safeDispatchEvent("error",{detail:t})}).on("close",()=>{this.metrics.status?.update({[this.addr]:this.status.code}),this.status.code!==T.PAUSED&&this.safeDispatchEvent("close")}).on("drop",()=>{this.metrics.events?.increment({[`${this.addr} drop`]:!0})})}onSocket(e){if(this.metrics.events?.increment({[`${this.addr} connection`]:!0}),this.status.code!==T.ACTIVE)throw e.destroy(),new Ge("Server is not listening yet");let t;try{t=xt({socket:e,inactivityTimeout:this.context.inactivityTimeout,metrics:this.metrics?.events,metricPrefix:`${this.addr} `,direction:"inbound",localAddr:this.status.listeningAddr,log:this.context.logger.forComponent("libp2p:tcp:connection")})}catch(n){this.log.error("inbound connection failed",n),this.metrics.errors?.increment({[`${this.addr} inbound_to_connection`]:!0}),e.destroy();return}this.log("new inbound connection %s",t.remoteAddr),this.sockets.add(e),this.context.upgrader.upgradeInbound(t,{signal:this.shutdownController.signal}).then(()=>{this.log("inbound connection upgraded %s",t.remoteAddr),e.once("close",()=>{this.sockets.delete(e),this.context.closeServerOnMaxConnections!=null&&this.sockets.size<this.context.closeServerOnMaxConnections.listenBelow&&this.resume().catch(n=>{this.log.error("error attempting to listen server once connection count under limit",n),this.context.closeServerOnMaxConnections?.onListenError?.(n)})}),this.context.closeServerOnMaxConnections!=null&&this.sockets.size>=this.context.closeServerOnMaxConnections.closeAbove&&(this.log("pausing incoming connections as limit is exceeded - %d/%d",this.sockets.size,this.context.closeServerOnMaxConnections.closeAbove),this.pause())}).catch(async n=>{this.log.error("inbound connection upgrade failed",n),this.metrics.errors?.increment({[`${this.addr} inbound_upgrade`]:!0}),this.sockets.delete(e),t.abort(n)})}getAddrs(){if(this.status.code===T.INACTIVE)return[];let e=this.server.address();return e==null?[]:typeof e=="string"?[W(`/unix/${encodeURIComponent(e)}`)]:On(this.status.listeningAddr,e.port)}updateAnnounceAddrs(){}async listen(e){if(this.status.code===T.ACTIVE||this.status.code===T.PAUSED)throw new Qe("server is already listening");try{this.status={code:T.ACTIVE,listeningAddr:e,netConfig:yt(e,this.context)},await this.resume()}catch(t){throw this.status={code:T.INACTIVE},t}}async close(e){let t=[];this.server.listening&&t.push(te(this.server,"close",e)),this.pause(!0),this.shutdownController.abort(),this.sockets.forEach(n=>{n.readable&&(t.push(te(n,"close",e)),n.destroy())}),await Promise.all(t)}async resume(){if(this.server.listening||this.status.code===T.INACTIVE)return;let e=this.status.netConfig;await new Promise((t,n)=>{this.server.once("error",n),this.server.listen(e,t)}),this.status={...this.status,code:T.ACTIVE},this.log("listening on %s",this.server.address())}pause(e=!1){if(!this.server.listening&&this.status.code===T.PAUSED&&e){this.status={code:T.INACTIVE};return}!this.server.listening||this.status.code!==T.ACTIVE||(this.log("%s server on %s",e?"closing":"pausing",this.server.address()),this.status=e?{code:T.INACTIVE}:{...this.status,code:T.PAUSED},this.server.close())}};var vt=class{opts;metrics;components;log;constructor(e,t={}){this.log=e.logger.forComponent("libp2p:tcp"),this.opts=t,this.components=e,e.metrics!=null&&(this.metrics={events:e.metrics.registerCounterGroup("libp2p_tcp_dialer_events_total",{label:"event",help:"Total count of TCP dialer events by type"}),errors:e.metrics.registerCounterGroup("libp2p_tcp_dialer_errors_total",{label:"event",help:"Total count of TCP dialer events by type"})})}[Tr]=!0;[Symbol.toStringTag]="@libp2p/tcp";[Pr]=["@libp2p/transport"];async dial(e,t){t.keepAlive=t.keepAlive??!0,t.noDelay=t.noDelay??!0,t.allowHalfOpen=t.allowHalfOpen??!1;let n=await this._connect(e,t),o;try{o=xt({socket:n,inactivityTimeout:this.opts.outboundSocketInactivityTimeout,metrics:this.metrics?.events,direction:"outbound",remoteAddr:e,log:this.log.newScope("connection")})}catch(s){throw this.metrics?.errors.increment({outbound_to_connection:!0}),n.destroy(s),s}try{return this.log("new outbound connection %s",o.remoteAddr),await t.upgrader.upgradeOutbound(o,t)}catch(s){throw this.metrics?.errors.increment({outbound_upgrade:!0}),this.log.error("error upgrading outbound connection",s),o.abort(s),s}}async _connect(e,t){t.signal.throwIfAborted(),t.onProgress?.(new dt("tcp:open-connection"));let n;return new Promise((o,s)=>{let i=Date.now(),a=yt(e,{...this.opts.dialOpts??{},...t});this.log("dialing %a with opts %o",e,a),n=kn.default.connect(a);let c=d=>{this.log.error("dial to %a errored - %e",e,d);let g=a.path??`${a.host??""}:${a.port}`;d.message=`connection error ${g}: ${d.message}`,this.metrics?.events.increment({error:!0}),x(d)},l=()=>{this.log("connection timeout %a",e),this.metrics?.events.increment({timeout:!0});let d=new ue(`Connection timeout after ${Date.now()-i}ms`);n.emit("error",d)},h=()=>{this.log("connection opened %a",e),this.metrics?.events.increment({connect:!0}),x()},f=()=>{this.log("connection aborted %a",e),this.metrics?.events.increment({abort:!0}),x(new je)},x=d=>{if(n.removeListener("error",c),n.removeListener("timeout",l),n.removeListener("connect",h),t.signal!=null&&t.signal.removeEventListener("abort",f),d!=null){s(d);return}o(n)};n.on("error",c),n.on("timeout",l),n.on("connect",h),t.signal.addEventListener("abort",f)}).catch(o=>{throw n?.destroy(),o})}createListener(e){return new Et({...this.opts.listenOpts??{},...e,maxConnections:this.opts.maxConnections,backlog:this.opts.backlog,closeServerOnMaxConnections:this.opts.closeServerOnMaxConnections,inactivityTimeout:this.opts.inboundSocketInactivityTimeout,metrics:this.components.metrics,logger:this.components.logger})}listenFilter(e){return e.filter(t=>xn.exactMatch(t)||t.toString().startsWith("/unix/"))}dialFilter(e){return this.listenFilter(e)}};function Js(r={}){return e=>new vt(e,r)}return Wn(Ks);})();
|
|
3
3
|
return Libp2PTcp}));
|
|
4
4
|
//# sourceMappingURL=index.min.js.map
|