@libp2p/tcp 11.0.20-29797a5bb → 11.0.20-5b8813abc
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/package.json +6 -6
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 Wn=Object.create;var Ne=Object.defineProperty;var jn=Object.getOwnPropertyDescriptor;var qn=Object.getOwnPropertyNames;var Hn=Object.getPrototypeOf,Qn=Object.prototype.hasOwnProperty;var B=(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 R=(r,e)=>{for(var t in e)Ne(r,t,{get:e[t],enumerable:!0})},Lr=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of qn(e))!Qn.call(r,o)&&o!==t&&Ne(r,o,{get:()=>e[o],enumerable:!(n=jn(e,o))||n.enumerable});return r};var re=(r,e,t)=>(t=r!=null?Wn(Hn(r)):{},Lr(e||!r||!r.__esModule?Ne(t,"default",{value:r,enumerable:!0}):t,r)),Gn=r=>Lr(Ne({},"__esModule",{value:!0}),r);var Zs={};R(Zs,{tcp:()=>Ys});var Fn=re(B("net"),1);var Re=class extends Error{static name="AbortError";constructor(e="The operation was aborted"){super(e),this.name="AbortError"}};var U=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}};var Me=class extends Error{static name="StreamResetError";constructor(e="The stream has been reset"){super(e),this.name="StreamResetError"}};var G=class extends Error{static name="StreamStateError";constructor(e="The stream is in an invalid state"){super(e),this.name="StreamStateError"}},Ee=class extends Error{static name="StreamBufferError";constructor(e="The stream buffer was full"){super(e),this.name="StreamBufferError"}};var ne=class extends Error{static name="TimeoutError";constructor(e="Timed out"){super(e),this.name="TimeoutError"}},Ve=class extends Error{static name="NotStartedError";constructor(e="Not started"){super(e),this.name="NotStartedError"}},ke=class extends Error{static name="AlreadyStartedError";constructor(e="Already started"){super(e),this.name="AlreadyStartedError"}};var ze=class extends Event{data;constructor(e,t){super("message",t),this.data=e}},oe=class extends Event{error;local;constructor(e,t,n){super("close",n),this.error=t,this.local=e}},$e=class extends oe{constructor(e,t){super(!0,e,t)}},Fe=class extends oe{constructor(e,t){super(!1,e,t)}};var Pr=Symbol.for("@libp2p/transport");var Ar;(function(r){r[r.FATAL_ALL=0]="FATAL_ALL",r[r.NO_FATAL=1]="NO_FATAL"})(Ar||(Ar={}));var Or=B("node:events"),We=(r,...e)=>{try{(0,Or.setMaxListeners)(r,...e)}catch{}};function Xn(r){return typeof r?.handleEvent=="function"}function Jn(r){return(r!==!0&&r!==!1&&r?.once)??!1}var se=class extends EventTarget{#e=new Map;constructor(){super(),We(1/0,this)}listenerCount(e){let t=this.#e.get(e);return t==null?0:t.length}addEventListener(e,t,n){let o=Jn(n);super.addEventListener(e,i=>{if(o){let a=this.#e.get(i.type);a!=null&&(a=a.filter(({callback:c})=>c!==t),this.#e.set(i.type,a))}Xn(t)?t.handleEvent(i):t(i)},n);let s=this.#e.get(e);s==null&&(s=[],this.#e.set(e,s)),s.push({callback:t,once:o})}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))}safeDispatchEvent(e,t={}){return this.dispatchEvent(new CustomEvent(e,t))}};var _r=Symbol.for("@libp2p/service-capabilities");function Br(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 Kn=Math.pow(2,7),Yn=Math.pow(2,14),Zn=Math.pow(2,21),Et=Math.pow(2,28),vt=Math.pow(2,35),Ct=Math.pow(2,42),St=Math.pow(2,49),C=128,P=127;function ie(r){if(r<Kn)return 1;if(r<Yn)return 2;if(r<Zn)return 3;if(r<Et)return 4;if(r<vt)return 5;if(r<Ct)return 6;if(r<St)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Dt(r,e,t=0){switch(ie(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 eo(r,e){let t=r[e],n=0;if(n+=t&P,t<C||(t=r[e+1],n+=(t&P)<<7,t<C)||(t=r[e+2],n+=(t&P)<<14,t<C)||(t=r[e+3],n+=(t&P)<<21,t<C)||(t=r[e+4],n+=(t&P)*Et,t<C)||(t=r[e+5],n+=(t&P)*vt,t<C)||(t=r[e+6],n+=(t&P)*Ct,t<C)||(t=r[e+7],n+=(t&P)*St,t<C))return n;throw new RangeError("Could not decode varint")}function to(r,e){let t=r.get(e),n=0;if(n+=t&P,t<C||(t=r.get(e+1),n+=(t&P)<<7,t<C)||(t=r.get(e+2),n+=(t&P)<<14,t<C)||(t=r.get(e+3),n+=(t&P)<<21,t<C)||(t=r.get(e+4),n+=(t&P)*Et,t<C)||(t=r.get(e+5),n+=(t&P)*vt,t<C)||(t=r.get(e+6),n+=(t&P)*Ct,t<C)||(t=r.get(e+7),n+=(t&P)*St,t<C))return n;throw new RangeError("Could not decode varint")}function Tt(r,e=0){return r instanceof Uint8Array?eo(r,e):to(r,e)}var Ur=B("node:buffer");function ae(r){return new Uint8Array(r.buffer,r.byteOffset,r.byteLength)}function ve(r,e){return ae(Ur.Buffer.concat(r,e))}var on=B("node:buffer");var Ot={};R(Ot,{base10:()=>uo});var Fi=new Uint8Array(0);function Nr(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 k(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 Rr(r){return new TextEncoder().encode(r)}function Mr(r){return new TextDecoder().decode(r)}function no(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),p=Math.log(a)/Math.log(256),f=Math.log(256)/Math.log(a);function l(m){if(m instanceof Uint8Array||(ArrayBuffer.isView(m)?m=new Uint8Array(m.buffer,m.byteOffset,m.byteLength):Array.isArray(m)&&(m=Uint8Array.from(m))),!(m instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(m.length===0)return"";for(var v=0,b=0,D=0,_=m.length;D!==_&&m[D]===0;)D++,v++;for(var L=(_-D)*f+1>>>0,N=new Uint8Array(L);D!==_;){for(var V=m[D],Q=0,z=L-1;(V!==0||Q<b)&&z!==-1;z--,Q++)V+=256*N[z]>>>0,N[z]=V%a>>>0,V=V/a>>>0;if(V!==0)throw new Error("Non-zero carry");b=Q,D++}for(var F=L-b;F!==L&&N[F]===0;)F++;for(var Ue=c.repeat(v);F<L;++F)Ue+=r.charAt(N[F]);return Ue}function w(m){if(typeof m!="string")throw new TypeError("Expected String");if(m.length===0)return new Uint8Array;var v=0;if(m[v]!==" "){for(var b=0,D=0;m[v]===c;)b++,v++;for(var _=(m.length-v)*p+1>>>0,L=new Uint8Array(_);m[v];){var N=t[m.charCodeAt(v)];if(N===255)return;for(var V=0,Q=_-1;(N!==0||V<D)&&Q!==-1;Q--,V++)N+=a*L[Q]>>>0,L[Q]=N%256>>>0,N=N/256>>>0;if(N!==0)throw new Error("Non-zero carry");D=V,v++}if(m[v]!==" "){for(var z=_-D;z!==_&&L[z]===0;)z++;for(var F=new Uint8Array(b+(_-z)),Ue=b;z!==_;)F[Ue++]=L[z++];return F}}}function d(m){var v=w(m);if(v)return v;throw new Error(`Non-${e} character`)}return{encode:l,decodeUnsafe:w,decode:d}}var oo=no,so=oo,kr=so;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")}},Lt=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 zr(this,e)}},At=class{decoders;constructor(e){this.decoders=e}or(e){return zr(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 zr(r,e){return new At({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var Pt=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 Lt(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function ce({name:r,prefix:e,encode:t,decode:n}){return new Pt(r,e,t,n)}function X({name:r,prefix:e,alphabet:t}){let{encode:n,decode:o}=kr(t,r);return ce({prefix:e,name:r,encode:n,decode:s=>k(o(s))})}function io(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 p=0;p<o;++p){let f=e[r[p]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<t|f,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 ao(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 co(r){let e={};for(let t=0;t<r.length;++t)e[r[t]]=t;return e}function S({name:r,prefix:e,bitsPerChar:t,alphabet:n}){let o=co(n);return ce({prefix:e,name:r,encode(s){return ao(s,n,t)},decode(s){return io(s,o,t,r)}})}var uo=X({prefix:"9",name:"base10",alphabet:"0123456789"});var _t={};R(_t,{base16:()=>lo,base16upper:()=>ho});var lo=S({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),ho=S({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Bt={};R(Bt,{base2:()=>fo});var fo=S({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Ut={};R(Ut,{base256emoji:()=>wo});var $r=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}"),po=$r.reduce((r,e,t)=>(r[t]=e,r),[]),mo=$r.reduce((r,e,t)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return r[n]=t,r},[]);function bo(r){return r.reduce((e,t)=>(e+=po[t],e),"")}function go(r){let e=[];for(let t of r){let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);let o=mo[n];if(o==null)throw new Error(`Non-base256emoji character: ${t}`);e.push(o)}return new Uint8Array(e)}var wo=ce({prefix:"\u{1F680}",name:"base256emoji",encode:bo,decode:go});var Nt={};R(Nt,{base32:()=>J,base32hex:()=>vo,base32hexpad:()=>So,base32hexpadupper:()=>Do,base32hexupper:()=>Co,base32pad:()=>yo,base32padupper:()=>Eo,base32upper:()=>xo,base32z:()=>To});var J=S({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),xo=S({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),yo=S({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Eo=S({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),vo=S({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Co=S({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),So=S({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Do=S({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),To=S({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Rt={};R(Rt,{base36:()=>Ce,base36upper:()=>Io});var Ce=X({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Io=X({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Mt={};R(Mt,{base58btc:()=>$,base58flickr:()=>Lo});var $=X({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Lo=X({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var kt={};R(kt,{base64:()=>Ao,base64pad:()=>Po,base64url:()=>Vt,base64urlpad:()=>Oo});var Ao=S({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Po=S({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Vt=S({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Oo=S({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var zt={};R(zt,{base8:()=>_o});var _o=S({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var $t={};R($t,{identity:()=>Bo});var Bo=ce({prefix:"\0",name:"identity",encode:r=>Mr(r),decode:r=>Rr(r)});var oa=new TextEncoder,sa=new TextDecoder;var Wt={};R(Wt,{identity:()=>rs});var Ro=jr,Fr=128,Mo=127,Vo=~Mo,ko=Math.pow(2,31);function jr(r,e,t){e=e||[],t=t||0;for(var n=t;r>=ko;)e[t++]=r&255|Fr,r/=128;for(;r&Vo;)e[t++]=r&255|Fr,r>>>=7;return e[t]=r|0,jr.bytes=t-n+1,e}var zo=Ft,$o=128,Wr=127;function Ft(r,n){var t=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw Ft.bytes=0,new RangeError("Could not decode varint");i=r[s++],t+=o<28?(i&Wr)<<o:(i&Wr)*Math.pow(2,o),o+=7}while(i>=$o);return Ft.bytes=s-n,t}var Fo=Math.pow(2,7),Wo=Math.pow(2,14),jo=Math.pow(2,21),qo=Math.pow(2,28),Ho=Math.pow(2,35),Qo=Math.pow(2,42),Go=Math.pow(2,49),Xo=Math.pow(2,56),Jo=Math.pow(2,63),Ko=function(r){return r<Fo?1:r<Wo?2:r<jo?3:r<qo?4:r<Ho?5:r<Qo?6:r<Go?7:r<Xo?8:r<Jo?9:10},Yo={encode:Ro,decode:zo,encodingLength:Ko},Zo=Yo,Se=Zo;function De(r,e=0){return[Se.decode(r,e),Se.decode.bytes]}function ue(r,e,t=0){return Se.encode(r,e,t),e}function le(r){return Se.encodingLength(r)}function fe(r,e){let t=e.byteLength,n=le(r),o=n+le(t),s=new Uint8Array(o+t);return ue(r,s,0),ue(t,s,n),s.set(e,o),new he(r,t,e,s)}function qr(r){let e=k(r),[t,n]=De(e),[o,s]=De(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new he(t,o,i,e)}function Hr(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&Nr(r.bytes,t.bytes)}}var he=class{code;size;digest;bytes;constructor(e,t,n,o){this.code=e,this.size=t,this.digest=n,this.bytes=o}};var Qr=0,es="identity",Gr=k;function ts(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 fe(Qr,Gr(r))}var rs={code:Qr,name:es,encode:Gr,digest:ts};var Qt={};R(Qt,{sha256:()=>os,sha512:()=>ss});var Ht=re(B("crypto"),1);var ns=20;function qt({name:r,code:e,encode:t,minDigestLength:n,maxDigestLength:o}){return new jt(r,e,t,n,o)}var jt=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,t,n,o,s){this.name=e,this.code=t,this.encode=n,this.minDigestLength=o??ns,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?Xr(n,this.code,t?.truncate):n.then(o=>Xr(o,this.code,t?.truncate))}else throw Error("Unknown type, must be binary type")}};function Xr(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 fe(e,r)}var os=qt({name:"sha2-256",code:18,encode:r=>k(Ht.default.createHash("sha256").update(r).digest())}),ss=qt({name:"sha2-512",code:19,encode:r=>k(Ht.default.createHash("sha512").update(r).digest())});function Kr(r,e){let{bytes:t,version:n}=r;return n===0?as(t,Gt(r),e??$.encoder):cs(t,Gt(r),e??J.encoder)}var Yr=new WeakMap;function Gt(r){let e=Yr.get(r);if(e==null){let t=new Map;return Yr.set(r,t),t}return e}var de=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!==us)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=fe(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&&Hr(e.multihash,n.multihash)}toString(e){return Kr(this,e)}toJSON(){return{"/":Kr(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??Zr(n,o,s.bytes))}else if(t[ls]===!0){let{version:n,multihash:o,code:s}=t,i=qr(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=Zr(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=k(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 he(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[l,w]=De(e.subarray(t));return t+=w,l},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(),p=t+c,f=p-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:f,size:p}}static parse(e,t){let[n,o]=is(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 Gt(s).set(n,e),s}};function is(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 J.prefix:{let t=e??J;return[J.prefix,t.decode(r)]}case Ce.prefix:{let t=e??Ce;return[Ce.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 as(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 cs(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,us=18;function Zr(r,e,t){let n=le(r),o=n+le(e),s=new Uint8Array(o+t.byteLength);return ue(r,s,0),ue(e,s,n),s.set(t,o),s}var ls=Symbol.for("@ipld/js-cid/CID");var Le={...$t,...Bt,...zt,...Ot,..._t,...Nt,...Rt,...Mt,...kt,...Ut},La={...Qt,...Wt};var en=B("node:buffer");function tn(r=0){return ae(en.Buffer.allocUnsafe(r))}function nn(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var rn=nn("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Xt=nn("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=tn(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),hs={utf8:rn,"utf-8":rn,hex:Le.base16,latin1:Xt,ascii:Xt,binary:Xt,...Le},qe=hs;function Ae(r,e="utf8"){let t=qe[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return e==="utf8"||e==="utf-8"?ae(on.Buffer.from(r,"utf-8")):t.decoder.decode(`${t.prefix}${r}`)}var sn=B("node:buffer");function Y(r,e="utf8"){let t=qe[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return e==="utf8"||e==="utf-8"?sn.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"},W=class extends Error{static name="ValidationError";name="ValidationError"},He=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},Qe=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};var M=B("node:net");function Kt(r){return e=>Y(e,r)}function Yt(r){return e=>Ae(e,r)}function pe(r){return new DataView(r.buffer).getUint16(r.byteOffset).toString()}function Z(r){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,typeof r=="string"?parseInt(r):r),new Uint8Array(e)}function an(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=Ae(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=Z(n);return ve([t,o],t.length+o.length)}function cn(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=Z(n);return ve([t,o],t.length+o.length)}function Zt(r){let e=r.subarray(0,r.length-2),t=r.subarray(r.length-2),n=Y(e,"base32"),o=pe(t);return`${n}:${o}`}var er=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},un=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,M.isIPv4)(t[n]),i;s&&(i=er(t[n]),t[n]=Y(i.subarray(0,2),"base16")),i!=null&&++n<8&&t.splice(n,0,Y(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},ln=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(".")},hn=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 fn(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 Jt=Object.values(Le).map(r=>r.decoder),fs=(function(){let r=Jt[0].or(Jt[1]);return Jt.slice(2).forEach(e=>r=r.or(e)),r})();function dn(r){return fs.decode(r)}function pn(r){return e=>r.encoder.encode(e)}function ds(r){if(parseInt(r).toString()!==r)throw new W("Value must be an integer")}function ps(r){if(r<0)throw new W("Value must be a positive integer, or zero")}function ms(r){return e=>{if(e>r)throw new W(`Value must be smaller than or equal to ${r}`)}}function bs(...r){return e=>{for(let t of r)t(e)}}var Pe=bs(ds,ps,ms(65535));var T=-1,tr=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 Qe(`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)}))}},q=new tr,Ps=[{code:4,name:"ip4",size:32,valueToBytes:er,bytesToValue:ln,validate:r=>{if(!(0,M.isIPv4)(r))throw new W(`Invalid IPv4 address "${r}"`)}},{code:6,name:"tcp",size:16,valueToBytes:Z,bytesToValue:pe,validate:Pe},{code:273,name:"udp",size:16,valueToBytes:Z,bytesToValue:pe,validate:Pe},{code:33,name:"dccp",size:16,valueToBytes:Z,bytesToValue:pe,validate:Pe},{code:41,name:"ip6",size:128,valueToBytes:un,bytesToValue:hn,stringToValue:fn,validate:r=>{if(!(0,M.isIPv6)(r))throw new W(`Invalid IPv6 address "${r}"`)}},{code:42,name:"ip6zone",size:T},{code:43,name:"ipcidr",size:8,bytesToValue:Kt("base10"),valueToBytes:Yt("base10")},{code:53,name:"dns",size:T},{code:54,name:"dns4",size:T},{code:55,name:"dns6",size:T},{code:56,name:"dnsaddr",size:T},{code:132,name:"sctp",size:16,valueToBytes:Z,bytesToValue:pe,validate:Pe},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:T,stringToValue:r=>decodeURIComponent(r),valueToString:r=>encodeURIComponent(r)},{code:421,name:"p2p",aliases:["ipfs"],size:T,bytesToValue:Kt("base58btc"),valueToBytes:r=>r.startsWith("Q")||r.startsWith("1")?Yt("base58btc")(r):de.parse(r).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:Zt,valueToBytes:an},{code:445,name:"onion3",size:296,bytesToValue:Zt,valueToBytes:cn},{code:446,name:"garlic64",size:T},{code:447,name:"garlic32",size:T},{code:448,name:"tls"},{code:449,name:"sni",size:T},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:T,bytesToValue:pn(Vt),valueToBytes:dn},{code:480,name:"http"},{code:481,name:"http-path",size:T,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:T}];Ps.forEach(r=>{q.addProtocol(r)});function mn(r){let e=[],t=0;for(;t<r.length;){let n=Tt(r,t),o=q.getProtocol(n),s=ie(n),i=Os(o,r,t+s),a=0;i>0&&o.size===T&&(a=ie(i));let c=s+a+i,p={code:n,name:o.name,bytes:r.subarray(t,t+c)};if(i>0){let f=t+s+a,l=r.subarray(f,f+i);p.value=o.bytesToValue?.(l)??Y(l)}e.push(p),t+=c}return e}function bn(r){let e=0,t=[];for(let n of r){if(n.bytes==null){let o=q.getProtocol(n.code),s=ie(n.code),i,a=0,c=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??Ae(n.value),a=i.byteLength,o.size===T&&(c=ie(a)));let p=new Uint8Array(s+c+a),f=0;Dt(n.code,p,f),f+=s,i!=null&&(o.size===T&&(Dt(a,p,f),f+=c),p.set(i,f)),n.bytes=p}t.push(n.bytes),e+=n.bytes.byteLength}return ve(t,e)}function gn(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=q.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 p={code:c.code,name:c.name};if(c.size!=null&&c.size!==0){if(n==="")throw new A(`Component ${o} was missing value`);p.value=c.stringToValue?.(n)??n}e.push(p),n="",o="",t="protocol"}}}if(o!==""&&n!=="")throw new A("Incomplete multiaddr");return e}function wn(r){return`/${r.flatMap(e=>{if(e.value==null)return e.name;let t=q.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 Os(r,e,t){return r.size==null||r.size===0?0:r.size>0?r.size/8:Tt(e,t)}var _s=Symbol.for("nodejs.util.inspect.custom"),pr=Symbol.for("@multiformats/multiaddr");function Bs(r){if(r==null&&(r="/"),xn(r))return r.getComponents();if(r instanceof Uint8Array)return mn(r);if(typeof r=="string")return r=r.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),r===""&&(r="/"),gn(r);if(Array.isArray(r))return r;throw new A("Must be a string, Uint8Array, Component[], or another Multiaddr")}var rt=class r{[pr]=!0;#e;#t;#r;constructor(e="/",t={}){this.#e=Bs(e),t.validate!==!1&&Us(this)}get bytes(){return this.#r==null&&(this.#r=bn(this.#e)),this.#r}toString(){return this.#t==null&&(this.#t=wn(this.#e)),this.#t}toJSON(){return this.toString()}getComponents(){return[...this.#e.map(e=>({...e}))]}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 He(`Address ${this.toString()} does not contain subaddress: ${t}`);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})}equals(e){return Br(this.bytes,e.bytes)}[_s](){return`Multiaddr(${this.toString()})`}};function Us(r){r.getComponents().forEach(e=>{let t=q.getProtocol(e.code);e.value!=null&&t.validate?.(e.value)})}function xn(r){return!!r?.[pr]}function te(r){return new rt(r)}var y=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)}}),yn=r=>({match:e=>r.match(e)===!1?e:!1}),h=r=>({match:e=>{let t=r.match(e);return t===!1?e:t}}),O=(...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}}),g=(...r)=>({match:e=>{for(let t of r){let n=t.match(e);if(n===!1)return!1;e=n}return e}});function E(...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 Ns=u(421),Tc=E(Ns),ot=u(54),st=u(55),it=u(56),br=u(53),Ic=E(ot,h(u(421))),Lc=E(st,h(u(421))),Ac=E(it,h(u(421))),Pc=E(O(br,it,ot,st),h(u(421))),En=g(u(4),h(u(43))),vn=g(h(u(42)),u(41),h(u(43))),gr=O(En,vn),we=O(gr,br,ot,st,it),Oc=E(O(gr,g(O(br,it,ot,st),h(u(421))))),_c=E(En),Bc=E(vn),Uc=E(gr),wr=g(we,u(6)),_e=g(we,u(273)),Cn=E(g(wr,h(u(421)))),Nc=E(_e),xr=g(_e,y(460),h(u(421))),at=g(_e,y(461),h(u(421))),Rs=O(xr,at),Rc=E(xr),Mc=E(at),mr=O(we,wr,_e,xr,at),Sn=O(g(mr,y(477),h(u(421)))),Vc=E(Sn),Dn=O(g(mr,y(478),h(u(421))),g(mr,y(448),h(u(449)),y(477),h(u(421)))),kc=E(Dn),Tn=g(_e,y(280),h(u(466)),h(u(466)),h(u(421))),zc=E(Tn),In=g(at,y(465),h(u(466)),h(u(466)),h(u(421))),$c=E(In),nt=O(Sn,Dn,g(wr,h(u(421))),g(Rs,h(u(421))),g(we,h(u(421))),Tn,In,u(421)),Fc=E(nt),Ms=g(h(nt),y(290),yn(y(281)),h(u(421))),Wc=E(Ms),Vs=O(g(nt,y(290),y(281),h(u(421))),g(nt,y(281),h(u(421))),g(y(281),h(u(421)))),jc=E(Vs),ks=g(we,O(g(u(6,"80")),g(u(6),y(480)),y(480)),h(u(481)),h(u(421))),qc=E(ks),zs=g(we,O(g(u(6,"443")),g(u(6,"443"),y(480)),g(u(6),y(443)),g(u(6),y(448),y(480)),g(y(448),y(480)),y(448),y(443)),h(u(481)),h(u(421))),Hc=E(zs),$s=O(g(u(777),h(u(421)))),Qc=E($s),Fs=O(g(u(400),h(u(421)))),ct=E(Fs);var ut=class extends Event{type;detail;constructor(e,t){super(e),this.type=e,this.detail=t}};var $n=re(B("node:net"),1);var yr=B("node:buffer");function Be(r){return new Uint8Array(r.buffer,r.byteOffset,r.byteLength)}function H(r=0){return Be(yr.Buffer.alloc(r))}function Er(r=0){return Be(yr.Buffer.allocUnsafe(r))}var Ln=B("node:buffer");function vr(r,e){return Be(Ln.Buffer.concat(r,e))}function An(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 On=Symbol.for("@achingbrain/uint8arraylist");function Pn(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 lt(r){return!!r?.[On]}var xe=class r{bufs;length;[On]=!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(lt(n)){t+=n.byteLength;for(let o of n.bufs)this.bufs.push(o)}else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=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(lt(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=Pn(this.bufs,e);return t.buf[t.index]}set(e,t){let n=Pn(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(lt(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 vr(n,o)}subarray(e,t){let{bufs:n,length:o}=this._subList(e,t);return n.length===1?n[0]:vr(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 p=e>=a&&e<c,f=t>a&&t<=c;if(p&&f){if(e===a&&t===c){n.push(i);break}let l=e-a;n.push(i.subarray(l,l+(t-e)));break}if(p){if(e===0){n.push(i);continue}n.push(i.subarray(e-a));continue}if(f){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(!lt(e)&&!(e instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=e instanceof Uint8Array?e:e.subarray();if(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 l=0;l<s;l++)i[l]=-1;for(let l=0;l<o;l++)i[n[l]]=l;let a=i,c=this.byteLength-n.byteLength,p=n.byteLength-1,f;for(let l=t;l<=c;l+=f){f=0;for(let w=p;w>=0;w--){let d=this.get(l+w);if(n[w]!==d){f=Math.max(1,w-a[d]);break}}if(f===0)return l}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=Er(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=H(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=H(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=H(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=Er(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=H(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=H(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=H(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=H(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=H(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(!An(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 Ws(r){let e=r.getComponents(),t={},n=0;return e[n]?.name==="ip6zone"&&(t.zone=`${e[n].value}`,n++),e[n]?.name==="ip4"||e[n]?.name==="ip6"||e[n]?.name==="dns"||e[n]?.name==="dns4"||e[n]?.name==="dns6"?(t.type=e[n].name,t.host=e[n].value,n++):e[n]?.name==="dnsaddr"&&(t.type=e[n].name,t.host=`_dnsaddr.${e[n].value}`,n++),(e[n]?.name==="tcp"||e[n]?.name==="udp")&&(t.protocol=e[n].name==="tcp"?"tcp":"udp",t.port=parseInt(`${e[n].value}`),n++),e[n]?.name==="ipcidr"&&(t.type==="ip4"?t.cidr=parseInt(`${e[n].value}`):t.type==="ip6"&&(t.cidr=`${e[n].value}`),n++),t.type==null||t.host==null?null:(e[n]?.name==="tls"&&e[n+1]?.name==="sni"&&(t.sni=e[n+1].value,n+=2),t)}function ht(r){let e=Ws(r);if(e==null)throw new U(`Multiaddr ${r} was not an IPv4, IPv6, DNS, DNS4, DNS6 or DNSADDR address`);return e}function ft(){let r={};return r.promise=new Promise((e,t)=>{r.resolve=e,r.reject=t}),r}var dt=class{buffer;mask;top;btm;next;constructor(e){if(!(e>0)||(e-1&e)!==0)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(e),this.mask=e-1,this.top=0,this.btm=0,this.next=null}push(e){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=e,this.top=this.top+1&this.mask,!0)}shift(){let e=this.buffer[this.btm];if(e!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,e}isEmpty(){return this.buffer[this.btm]===void 0}},ye=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new dt(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 dt(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 Cr=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.code=t??"ABORT_ERR"}};function _n(r={}){return js(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 js(r,e){e=e??{};let t=e.onEnd,n=new ye,o,s,i,a=ft(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((b,D)=>{s=_=>{s=null,n.push(_);try{b(r(n))}catch(L){D(L)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=ft()})}},p=b=>s!=null?s(b):(n.push(b),o),f=b=>(n=new ye,s!=null?s({error:b}):(n.push({error:b}),o)),l=b=>{if(i)return o;if(e?.objectMode!==!0&&b?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return p({done:!1,value:b})},w=b=>i?o:(i=!0,b!=null?f(b):p({done:!0})),d=()=>(n=new ye,w(),{done:!0}),m=b=>(w(b),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:d,throw:m,push:l,end:w,get readableLength(){return n.size},onEmpty:async b=>{let D=b?.signal;if(D?.throwIfAborted(),n.isEmpty())return;let _,L;D!=null&&(_=new Promise((N,V)=>{L=()=>{V(new Cr)},D.addEventListener("abort",L)}));try{await Promise.race([a.promise,_])}finally{L!=null&&D!=null&&D?.removeEventListener("abort",L)}}},t==null)return o;let v=o;return o={[Symbol.asyncIterator](){return this},next(){return v.next()},throw(b){return v.throw(b),t!=null&&(t(b),t=void 0),{done:!0}},return(){return v.return(),t!=null&&(t(),t=void 0),{done:!0}},push:l,end(b){return v.end(b),t!=null&&(t(b),t=void 0),o},get readableLength(){return v.readableLength},onEmpty:b=>v.onEmpty(b)},o}var Sr=class r extends Error{name="TimeoutError";constructor(e,t){super(e,t),Error.captureStackTrace?.(this,r)}},Bn=r=>r.reason??new DOMException("This operation was aborted.","AbortError");function Dr(r,e){let{milliseconds:t,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout},signal:i}=e,a,c,f=new Promise((l,w)=>{if(typeof t!="number"||Math.sign(t)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${t}\``);if(i?.aborted){w(Bn(i));return}if(i&&(c=()=>{w(Bn(i))},i.addEventListener("abort",c,{once:!0})),r.then(l,w),t===Number.POSITIVE_INFINITY)return;let d=new Sr;a=s.setTimeout.call(void 0,()=>{if(n){try{l(n())}catch(m){w(m)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?l():o instanceof Error?w(o):(d.message=o??`Promise timed out after ${t} milliseconds`,w(d))},t)}).finally(()=>{f.clear(),c&&i&&i.removeEventListener("abort",c)});return f.clear=()=>{s.clearTimeout.call(void 0,a),a=void 0},f}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 Hs(r,e,t){let n,o=new Promise((s,i)=>{if(t={rejectionEvents:["error"],multiArgs:!1,rejectionMultiArgs:!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:p,removeListener:f}=qs(r),l=async(...d)=>{let m=t.multiArgs?d:d[0];if(t.filter)try{if(!await t.filter(m))return}catch(v){n(),i(v);return}c.push(m),t.count===c.length&&(n(),s(c))},w=(...d)=>{n(),i(t.rejectionMultiArgs?d:d[0])};n=()=>{for(let d of a)f(d,l);for(let d of t.rejectionEvents)a.includes(d)||f(d,w)};for(let d of a)p(d,l);for(let d of t.rejectionEvents)a.includes(d)||p(d,w);t.signal&&t.signal.addEventListener("abort",()=>{w(t.signal.reason)},{once:!0}),t.resolveImmediately&&s(c)});if(o.cancel=n,typeof t.timeout=="number"){let s=Dr(o,{milliseconds:t.timeout});return s.cancel=()=>{n(),s.clear()},s}return o}function K(r,e,t){typeof t=="function"&&(t={filter:t}),t={...t,count:1,resolveImmediately:!1};let n=Hs(r,e,t),o=n.then(s=>s[0]);return o.cancel=n.cancel,o}var pt=class extends Error{static name="StreamClosedError";name="StreamClosedError"};function Qs(r){return r.reason}async function Un(r,e,t){if(e==null)return r;let n=t?.translateError??Qs;if(e.aborted)return r.catch(()=>{}),Promise.reject(n(e));let o;try{return await Promise.race([r,new Promise((s,i)=>{o=()=>{i(n(e))},e.addEventListener("abort",o)})])}finally{o!=null&&e.removeEventListener("abort",o)}}var Gs=Math.pow(2,20)*4,mt=class extends se{status;timeline;inactivityTimeout;maxReadBufferLength;maxWriteBufferLength;log;direction;maxMessageSize;readStatus;writeStatus;remoteReadStatus;remoteWriteStatus;writableNeedsDrain;readBuffer;writeBuffer;sendingData;onDrainPromise;constructor(e){super(),this.status="open",this.log=e.log,this.direction=e.direction??"outbound",this.inactivityTimeout=e.inactivityTimeout??12e4,this.maxReadBufferLength=e.maxReadBufferLength??Gs,this.maxWriteBufferLength=e.maxWriteBufferLength,this.maxMessageSize=e.maxMessageSize,this.readBuffer=new xe,this.writeBuffer=new xe,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.writableNeedsDrain&&(this.log.trace("drain event received, continue sending data"),this.writableNeedsDrain=!1,queueMicrotask(()=>{try{this.processSendQueue()}catch(o){this.log.error("processSendQueue threw - %e",o)}})),this.onDrainPromise?.resolve()};this.addEventListener("drain",t);let n=o=>{this.onDrainPromise?.reject(o.error??new pt)};this.addEventListener("close",n)}get readBufferLength(){return this.readBuffer.byteLength}get writeBufferLength(){return this.writeBuffer.byteLength}async onDrain(e){return this.writableNeedsDrain!==!0?Promise.resolve():(this.onDrainPromise==null&&(this.onDrainPromise=Promise.withResolvers()),Un(this.onDrainPromise.promise,e?.signal))}async*[Symbol.asyncIterator](){if(this.readStatus!=="readable"&&this.readStatus!=="paused")return;let e=_n(),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 G(`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 $e(e))}}pause(){if(this.readStatus==="closed"||this.readStatus==="closing")throw new G("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 G("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 G(`Cannot push data onto a stream that is ${this.readStatus}`);if(e.byteLength!==0){if(this.readBuffer.append(e),this.readStatus==="paused"||this.listenerCount("message")===0){this.checkReadBufferLength();return}setTimeout(()=>{this.dispatchReadBuffer()},0)}}unshift(e){if(this.readStatus==="closed"||this.readStatus==="closing")throw new G(`Cannot push data onto a stream that is ${this.readStatus}`);if(e.byteLength!==0){if(this.readBuffer.prepend(e),this.readStatus==="paused"||this.listenerCount("message")===0){this.checkReadBufferLength();return}setTimeout(()=>{this.dispatchReadBuffer()},0)}}onData(e){if(e.byteLength!==0){if(this.readStatus==="closing"||this.readStatus==="closed"){this.log("ignoring data - read status %s",this.readStatus);return}this.readBuffer.append(e),this.dispatchReadBuffer()}}addEventListener(...e){super.addEventListener.apply(this,e),e[0]==="message"&&this.readBuffer.byteLength>0&&queueMicrotask(()=>{this.dispatchReadBuffer()})}onRemoteReset(){this.log("remote reset"),this.status="reset",this.writeStatus="closed",this.remoteWriteStatus="closed",this.remoteReadStatus="closed",this.timeline.close=Date.now(),this.readBuffer.byteLength===0&&(this.readStatus="closed");let e=new Me;this.dispatchEvent(new Fe(e))}onTransportClosed(e){this.log("transport closed"),this.readStatus==="readable"&&this.readBuffer.byteLength===0&&(this.log("close readable end after transport closed and read buffer is empty"),this.readStatus="closed"),this.remoteReadStatus!=="closed"&&(this.remoteReadStatus="closed"),this.remoteWriteStatus!=="closed"&&(this.remoteWriteStatus="closed"),this.writeStatus!=="closed"&&(this.writeStatus="closed"),e!=null?this.abort(e):(this.status==="open"||this.status==="closing")&&(this.timeline.close=Date.now(),this.status="closed",this.writeStatus="closed",this.remoteWriteStatus="closed",this.remoteReadStatus="closed",this.dispatchEvent(new oe))}onRemoteCloseWrite(){this.remoteWriteStatus!=="closed"&&(this.log.trace("on remote close write"),this.remoteWriteStatus="closed",this.safeDispatchEvent("remoteCloseWrite"),this.writeStatus==="closed"&&this.onTransportClosed())}onRemoteCloseRead(){this.log.trace("on remote close read"),this.remoteReadStatus="closed",this.writeBuffer.byteLength>0&&(this.writeBuffer.consume(this.writeBuffer.byteLength),this.safeDispatchEvent("idle"))}processSendQueue(){if(this.writableNeedsDrain)return this.log.trace("not processing send queue as drain is required"),this.checkWriteBufferLength(),!1;if(this.writeBuffer.byteLength===0)return this.log.trace("not processing send queue as no bytes to send"),!0;if(this.sendingData)return this.log.trace("not processing send queue as already sending data"),!0;if(this.writeStatus!=="writable"&&this.writeStatus!=="closing")return this.log.trace("not processing send queue as stream is %s",this.writeStatus),!1;this.sendingData=!0,this.log.trace("processing send queue with %d queued bytes",this.writeBuffer.byteLength);try{let e=!0,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 xe(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 ze(e))}finally{this.readBuffer.byteLength===0&&this.remoteWriteStatus==="closed"&&(this.log("close readable end after dispatching read buffer and remote writable end is closed"),this.readStatus="closed"),this.checkReadBufferLength()}}checkReadBufferLength(){this.readBuffer.byteLength>this.maxReadBufferLength&&this.abort(new Ee(`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 Ee(`Write buffer length of ${this.writeBuffer.byteLength} exceeded limit of ${this.maxWriteBufferLength}, write status is ${this.writeStatus}`))}onMuxerNeedsDrain(){this.writableNeedsDrain=!0}onMuxerDrain(){this.safeDispatchEvent("drain")}};var bt=class extends mt{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 K(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 K(this,"drain",{...e,rejectionEvents:["close"]})),await this.sendClose(e),this.onTransportClosed())}};var Rn=re(B("node:os"),1);function Nn(r){return!!(r.startsWith("169.254.")||r.toLowerCase().startsWith("fe80"))}function Tr(r,e,t){let n=[r.type,t??r.host];if(r.protocol!=null){let o=e??r.port;o!=null&&n.push(r.protocol,o)}return r.type==="ip6"&&r.zone!=null&&n.unshift("ip6zone",r.zone),r.cidr!=null&&n.push("ipcidr",r.cidr),te(`/${n.join("/")}`)}var Xs={4:"IPv4",6:"IPv6"};function Js(r){return["0.0.0.0","::"].includes(r)}function Ks(r){let e=[],t=Rn.default.networkInterfaces();for(let[,n]of Object.entries(t))if(n!=null)for(let o of n)Nn(o.address)||o.family===Xs[r]&&e.push(o.address);return e}function Mn(r,e){if(r==null)return[];let t=ht(r);return(t.type==="ip4"||t.type==="ip6")&&Js(t.host)?Ks(t.type==="ip4"?4:6).map(n=>Tr(t,e,n)):[Tr(t,e)]}function Vn(r,e){if(typeof r!="string")throw new U(`invalid ip provided: ${r}`);if(typeof e=="string"&&(e=parseInt(e)),isNaN(e))throw new U(`invalid port provided: ${e}`);if((0,M.isIPv4)(r))return te(`/ip4/${r}/tcp/${e}`);if((0,M.isIPv6)(r))return te(`/ip6/${r}/tcp/${e}`);throw new U(`invalid ip:port for creating a multiaddr: ${r}:${e}`)}var Ir=class extends bt{socket;constructor(e){let t=e.remoteAddr;if(e.localAddr!=null&&ct.matches(e.localAddr))t=e.localAddr;else if(t==null){if(e.socket.remoteAddress==null||e.socket.remotePort==null)throw new U("Could not determine remote address or port");t=Vn(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 ne)}),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 K(this.socket,"close",e))}sendReset(){this.socket.resetAndDestroy()}sendPause(){this.socket.pause()}sendResume(){this.socket.resume()}},gt=r=>new Ir(r);var kn=re(B("os"),1),zn=re(B("path"),1);function wt(r,e={}){if(ct.exactMatch(r)){let s=r.getComponents().find(i=>i.code===400)?.value;if(s==null)throw new U(`Multiaddr ${r} was not a Unix address`);return kn.default.platform()==="win32"?{path:zn.default.join("\\\\.\\pipe\\",s)}:{path:s}}let t=ht(r),n=t.host,o=t.port;return{host:n,port:o,ipv6Only:t.type==="ip6",...e}}var I;(function(r){r[r.INACTIVE=0]="INACTIVE",r[r.ACTIVE=1]="ACTIVE",r[r.PAUSED=2]="PAUSED"})(I||(I={}));var xt=class extends se{context;server;sockets=new Set;status={code:I.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,We(1/0,this.shutdownController.signal),this.log=e.logger.forComponent("libp2p:tcp:listener"),this.addr="unknown",this.server=$n.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 U("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]:I.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!==I.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!==I.ACTIVE)throw e.destroy(),new Ve("Server is not listening yet");let t;try{t=gt({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 - %e",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 - %e",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 - %e",n),this.metrics.errors?.increment({[`${this.addr} inbound_upgrade`]:!0}),this.sockets.delete(e),t.abort(n)})}getAddrs(){if(this.status.code===I.INACTIVE)return[];let e=this.server.address();return e==null?[]:typeof e=="string"?[te(`/unix/${encodeURIComponent(e)}`)]:Mn(this.status.listeningAddr,e.port)}updateAnnounceAddrs(){}async listen(e){if(this.status.code===I.ACTIVE||this.status.code===I.PAUSED)throw new ke("server is already listening");try{this.status={code:I.ACTIVE,listeningAddr:e,netConfig:wt(e,this.context)},await this.resume()}catch(t){throw this.status={code:I.INACTIVE},t}}async close(e){let t=[];this.server.listening&&t.push(K(this.server,"close",e)),this.pause(!0),this.shutdownController.abort(),this.sockets.forEach(n=>{n.readable&&(t.push(K(n,"close",e)),n.destroy())}),await Promise.all(t)}async resume(){if(this.server.listening||this.status.code===I.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:I.ACTIVE},this.log("listening on %s",this.server.address())}pause(e=!1){if(!this.server.listening&&this.status.code===I.PAUSED&&e){this.status={code:I.INACTIVE};return}!this.server.listening||this.status.code!==I.ACTIVE||(this.log("%s server on %s",e?"closing":"pausing",this.server.address()),this.status=e?{code:I.INACTIVE}:{...this.status,code:I.PAUSED},this.server.close())}};var yt=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"})})}[Pr]=!0;[Symbol.toStringTag]="@libp2p/tcp";[_r]=["@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=gt({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 - %e",s),o.abort(s),s}}async _connect(e,t){t.signal.throwIfAborted(),t.onProgress?.(new ut("tcp:open-connection"));let n;return new Promise((o,s)=>{let i=Date.now(),a=wt(e,{...this.opts.dialOpts??{},...t});this.log("dialing %a with opts %o",e,a),n=Fn.default.connect(a);let c=d=>{this.log.error("dial to %a errored - %e",e,d);let m=a.path??`${a.host??""}:${a.port}`;d.message=`connection error ${m}: ${d.message}`,this.metrics?.events.increment({error:!0}),w(d)},p=()=>{this.log("connection timeout %a",e),this.metrics?.events.increment({timeout:!0});let d=new ne(`Connection timeout after ${Date.now()-i}ms`);n.emit("error",d)},f=()=>{this.log("connection opened %a",e),this.metrics?.events.increment({connect:!0}),w()},l=()=>{this.log("connection aborted %a",e),this.metrics?.events.increment({abort:!0}),w(new Re)},w=d=>{if(n.removeListener("error",c),n.removeListener("timeout",p),n.removeListener("connect",f),t.signal!=null&&t.signal.removeEventListener("abort",l),d!=null){s(d);return}o(n)};n.on("error",c),n.on("timeout",p),n.on("connect",f),t.signal.addEventListener("abort",l)}).catch(o=>{throw n?.destroy(),o})}createListener(e){return new xt({...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=>Cn.exactMatch(t)||t.toString().startsWith("/unix/"))}dialFilter(e){return this.listenFilter(e)}};function Ys(r={}){return e=>new yt(e,r)}return Gn(Zs);})();
|
|
2
|
+
"use strict";var Libp2PTcp=(()=>{var qn=Object.create;var Me=Object.defineProperty;var Hn=Object.getOwnPropertyDescriptor;var Qn=Object.getOwnPropertyNames;var Gn=Object.getPrototypeOf,Xn=Object.prototype.hasOwnProperty;var B=(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 R=(r,e)=>{for(var t in e)Me(r,t,{get:e[t],enumerable:!0})},_r=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Qn(e))!Xn.call(r,o)&&o!==t&&Me(r,o,{get:()=>e[o],enumerable:!(n=Hn(e,o))||n.enumerable});return r};var oe=(r,e,t)=>(t=r!=null?qn(Gn(r)):{},_r(e||!r||!r.__esModule?Me(t,"default",{value:r,enumerable:!0}):t,r)),Jn=r=>_r(Me({},"__esModule",{value:!0}),r);var ni={};R(ni,{tcp:()=>ri});var jn=oe(B("net"),1);var Ve=class extends Error{static name="AbortError";constructor(e="The operation was aborted"){super(e),this.name="AbortError"}};var U=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}};var ke=class extends Error{static name="StreamResetError";constructor(e="The stream has been reset"){super(e),this.name="StreamResetError"}};var G=class extends Error{static name="StreamStateError";constructor(e="The stream is in an invalid state"){super(e),this.name="StreamStateError"}},Se=class extends Error{static name="StreamBufferError";constructor(e="The stream buffer was full"){super(e),this.name="StreamBufferError"}};var se=class extends Error{static name="TimeoutError";constructor(e="Timed out"){super(e),this.name="TimeoutError"}},ze=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 Fe=class extends Event{data;constructor(e,t){super("message",t),this.data=e}},ie=class extends Event{error;local;constructor(e,t,n){super("close",n),this.error=t,this.local=e}},We=class extends ie{constructor(e,t){super(!0,e,t)}},je=class extends ie{constructor(e,t){super(!1,e,t)}};var Ur=Symbol.for("@libp2p/transport");var Br;(function(r){r[r.FATAL_ALL=0]="FATAL_ALL",r[r.NO_FATAL=1]="NO_FATAL"})(Br||(Br={}));var Nr=B("node:events"),qe=(r,...e)=>{try{(0,Nr.setMaxListeners)(r,...e)}catch{}};function Kn(r){return typeof r?.handleEvent=="function"}function Yn(r){return(r!==!0&&r!==!1&&r?.once)??!1}var ae=class extends EventTarget{#e=new Map;constructor(){super(),qe(1/0,this)}listenerCount(e){let t=this.#e.get(e);return t==null?0:t.length}addEventListener(e,t,n){let o=Yn(n);super.addEventListener(e,i=>{if(o){let a=this.#e.get(i.type);a!=null&&(a=a.filter(({callback:c})=>c!==t),this.#e.set(i.type,a))}Kn(t)?t.handleEvent(i):t(i)},n);let s=this.#e.get(e);s==null&&(s=[],this.#e.set(e,s)),s.push({callback:t,once:o})}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))}safeDispatchEvent(e,t={}){return this.dispatchEvent(new CustomEvent(e,t))}};var Rr=Symbol.for("@libp2p/service-capabilities");function Ct(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 Mr=B("node:buffer");function Z(r){if(r.buffer instanceof ArrayBuffer)return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);let e=r.slice();return new Uint8Array(e.buffer,0,e.byteLength)}function De(r=0){return Z(Mr.Buffer.allocUnsafe(r))}var Zn=Math.pow(2,7),eo=Math.pow(2,14),to=Math.pow(2,21),St=Math.pow(2,28),Dt=Math.pow(2,35),Tt=Math.pow(2,42),It=Math.pow(2,49),C=128,P=127;function ce(r){if(r<Zn)return 1;if(r<eo)return 2;if(r<to)return 3;if(r<St)return 4;if(r<Dt)return 5;if(r<Tt)return 6;if(r<It)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function At(r,e,t=0){switch(ce(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 ro(r,e){let t=r[e],n=0;if(n+=t&P,t<C||(t=r[e+1],n+=(t&P)<<7,t<C)||(t=r[e+2],n+=(t&P)<<14,t<C)||(t=r[e+3],n+=(t&P)<<21,t<C)||(t=r[e+4],n+=(t&P)*St,t<C)||(t=r[e+5],n+=(t&P)*Dt,t<C)||(t=r[e+6],n+=(t&P)*Tt,t<C)||(t=r[e+7],n+=(t&P)*It,t<C))return n;throw new RangeError("Could not decode varint")}function no(r,e){let t=r.get(e),n=0;if(n+=t&P,t<C||(t=r.get(e+1),n+=(t&P)<<7,t<C)||(t=r.get(e+2),n+=(t&P)<<14,t<C)||(t=r.get(e+3),n+=(t&P)<<21,t<C)||(t=r.get(e+4),n+=(t&P)*St,t<C)||(t=r.get(e+5),n+=(t&P)*Dt,t<C)||(t=r.get(e+6),n+=(t&P)*Tt,t<C)||(t=r.get(e+7),n+=(t&P)*It,t<C))return n;throw new RangeError("Could not decode varint")}function Lt(r,e=0){return r instanceof Uint8Array?ro(r,e):no(r,e)}function so(r){return r.buffer instanceof ArrayBuffer}function Pt(r){return so(r)?r:r.slice()}var Vr=B("node:buffer");function ue(r,e){return Z(Vr.Buffer.concat(r,e))}var an=B("node:buffer");var Nt={};R(Nt,{base10:()=>po});var Xi=new Uint8Array(0);function kr(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 k(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return ee(r);if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return ee(new Uint8Array(r.buffer,r.byteOffset,r.byteLength));throw new Error("Unknown type, must be binary type")}function zr(r){return new TextEncoder().encode(r)}function $r(r){return new TextDecoder().decode(r)}function io(r){return r?.buffer instanceof ArrayBuffer}function ee(r){return io(r)?r:r.slice()}function ao(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),p=Math.log(a)/Math.log(256),h=Math.log(256)/Math.log(a);function l(m){if(m instanceof Uint8Array||(ArrayBuffer.isView(m)?m=new Uint8Array(m.buffer,m.byteOffset,m.byteLength):Array.isArray(m)&&(m=Uint8Array.from(m))),!(m instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(m.length===0)return"";for(var v=0,b=0,D=0,_=m.length;D!==_&&m[D]===0;)D++,v++;for(var A=(_-D)*h+1>>>0,N=new Uint8Array(A);D!==_;){for(var V=m[D],Q=0,z=A-1;(V!==0||Q<b)&&z!==-1;z--,Q++)V+=256*N[z]>>>0,N[z]=V%a>>>0,V=V/a>>>0;if(V!==0)throw new Error("Non-zero carry");b=Q,D++}for(var F=A-b;F!==A&&N[F]===0;)F++;for(var Re=c.repeat(v);F<A;++F)Re+=r.charAt(N[F]);return Re}function w(m){if(typeof m!="string")throw new TypeError("Expected String");if(m.length===0)return new Uint8Array;var v=0;if(m[v]!==" "){for(var b=0,D=0;m[v]===c;)b++,v++;for(var _=(m.length-v)*p+1>>>0,A=new Uint8Array(_);m[v];){var N=t[m.charCodeAt(v)];if(N===255)return;for(var V=0,Q=_-1;(N!==0||V<D)&&Q!==-1;Q--,V++)N+=a*A[Q]>>>0,A[Q]=N%256>>>0,N=N/256>>>0;if(N!==0)throw new Error("Non-zero carry");D=V,v++}if(m[v]!==" "){for(var z=_-D;z!==_&&A[z]===0;)z++;for(var F=new Uint8Array(b+(_-z)),Re=b;z!==_;)F[Re++]=A[z++];return F}}}function d(m){var v=w(m);if(v)return v;throw new Error(`Non-${e} character`)}return{encode:l,decodeUnsafe:w,decode:d}}var co=ao,uo=co,Wr=uo;var Ot=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")}},_t=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 jr(this,e)}},Bt=class{decoders;constructor(e){this.decoders=e}or(e){return jr(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 jr(r,e){return new Bt({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var Ut=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 Ot(e,t,n),this.decoder=new _t(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function le({name:r,prefix:e,encode:t,decode:n}){return new Ut(r,e,t,n)}function X({name:r,prefix:e,alphabet:t}){let{encode:n,decode:o}=Wr(t,r);return le({prefix:e,name:r,encode:n,decode:s=>k(o(s))})}function lo(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 p=0;p<o;++p){let h=e[r[p]];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 fo(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 ho(r){let e={};for(let t=0;t<r.length;++t)e[r[t]]=t;return e}function S({name:r,prefix:e,bitsPerChar:t,alphabet:n}){let o=ho(n);return le({prefix:e,name:r,encode(s){return fo(s,n,t)},decode(s){return lo(s,o,t,r)}})}var po=X({prefix:"9",name:"base10",alphabet:"0123456789"});var Rt={};R(Rt,{base16:()=>mo,base16upper:()=>bo});var mo=S({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),bo=S({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Mt={};R(Mt,{base2:()=>go});var go=S({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Vt={};R(Vt,{base256emoji:()=>vo});var qr=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}"),wo=qr.reduce((r,e,t)=>(r[t]=e,r),[]),yo=qr.reduce((r,e,t)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return r[n]=t,r},[]);function xo(r){return r.reduce((e,t)=>(e+=wo[t],e),"")}function Eo(r){let e=[];for(let t of r){let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);let o=yo[n];if(o==null)throw new Error(`Non-base256emoji character: ${t}`);e.push(o)}return new Uint8Array(e)}var vo=le({prefix:"\u{1F680}",name:"base256emoji",encode:xo,decode:Eo});var kt={};R(kt,{base32:()=>J,base32hex:()=>To,base32hexpad:()=>Ao,base32hexpadupper:()=>Lo,base32hexupper:()=>Io,base32pad:()=>So,base32padupper:()=>Do,base32upper:()=>Co,base32z:()=>Po});var J=S({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Co=S({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),So=S({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Do=S({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),To=S({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Io=S({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Ao=S({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Lo=S({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Po=S({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var zt={};R(zt,{base36:()=>Te,base36upper:()=>Oo});var Te=X({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Oo=X({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var $t={};R($t,{base58btc:()=>$,base58flickr:()=>_o});var $=X({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),_o=X({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Wt={};R(Wt,{base64:()=>Bo,base64pad:()=>Uo,base64url:()=>Ft,base64urlpad:()=>No});var Bo=S({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Uo=S({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Ft=S({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),No=S({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var jt={};R(jt,{base8:()=>Ro});var Ro=S({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var qt={};R(qt,{identity:()=>Mo});var Mo=le({prefix:"\0",name:"identity",encode:r=>$r(r),decode:r=>zr(r)});var fa=new TextEncoder,ha=new TextDecoder;var Qt={};R(Qt,{identity:()=>is});var zo=Gr,Hr=128,$o=127,Fo=~$o,Wo=Math.pow(2,31);function Gr(r,e,t){e=e||[],t=t||0;for(var n=t;r>=Wo;)e[t++]=r&255|Hr,r/=128;for(;r&Fo;)e[t++]=r&255|Hr,r>>>=7;return e[t]=r|0,Gr.bytes=t-n+1,e}var jo=Ht,qo=128,Qr=127;function Ht(r,n){var t=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw Ht.bytes=0,new RangeError("Could not decode varint");i=r[s++],t+=o<28?(i&Qr)<<o:(i&Qr)*Math.pow(2,o),o+=7}while(i>=qo);return Ht.bytes=s-n,t}var Ho=Math.pow(2,7),Qo=Math.pow(2,14),Go=Math.pow(2,21),Xo=Math.pow(2,28),Jo=Math.pow(2,35),Ko=Math.pow(2,42),Yo=Math.pow(2,49),Zo=Math.pow(2,56),es=Math.pow(2,63),ts=function(r){return r<Ho?1:r<Qo?2:r<Go?3:r<Xo?4:r<Jo?5:r<Ko?6:r<Yo?7:r<Zo?8:r<es?9:10},rs={encode:zo,decode:jo,encodingLength:ts},ns=rs,Ie=ns;function Ae(r,e=0){return[Ie.decode(r,e),Ie.decode.bytes]}function fe(r,e,t=0){return Ie.encode(r,e,t),e}function he(r){return Ie.encodingLength(r)}function pe(r,e){let t=e.byteLength,n=he(r),o=n+he(t),s=new Uint8Array(o+t);return fe(r,s,0),fe(t,s,n),s.set(e,o),new de(r,t,e,s)}function Xr(r){let e=k(r),[t,n]=Ae(e),[o,s]=Ae(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new de(t,o,i,e)}function Jr(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&kr(r.bytes,t.bytes)}}var de=class{code;size;digest;bytes;constructor(e,t,n,o){this.code=e,this.size=t,this.digest=ee(n),this.bytes=ee(o)}};var Kr=0,os="identity",Yr=k;function ss(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 pe(Kr,Yr(r))}var is={code:Kr,name:os,encode:Yr,digest:ss};var Kt={};R(Kt,{sha256:()=>cs,sha512:()=>us});var Jt=oe(B("node:crypto"),1);var as=20;function Xt({name:r,code:e,encode:t,minDigestLength:n,maxDigestLength:o}){return new Gt(r,e,t,n,o)}var Gt=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,t,n,o,s){this.name=e,this.code=t,this.encode=n,this.minDigestLength=o??as,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?Zr(n,this.code,t?.truncate):n.then(o=>Zr(o,this.code,t?.truncate))}else throw Error("Unknown type, must be binary type")}};function Zr(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 pe(e,r)}var cs=Xt({name:"sha2-256",code:18,encode:r=>k(Jt.default.createHash("sha256").update(r).digest())}),us=Xt({name:"sha2-512",code:19,encode:r=>k(Jt.default.createHash("sha512").update(r).digest())});function tn(r,e){let{bytes:t,version:n}=r;return n===0?fs(t,Yt(r),e??$.encoder):hs(t,Yt(r),e??J.encoder)}var rn=new WeakMap;function Yt(r){let e=rn.get(r);if(e==null){let t=new Map;return rn.set(r,t),t}return e}var me=class r{code;version;multihash;bytes;"/";constructor(e,t,n,o){this.code=t,this.version=e,this.multihash=n,this.bytes=ee(o),this["/"]=this.bytes}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:t}=this;if(e!==Pe)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==ds)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=pe(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&&Jr(e.multihash,n.multihash)}toString(e){return tn(this,e)}toJSON(){return{"/":tn(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??nn(n,o,s.bytes))}else if(t[ps]===!0){let{version:n,multihash:o,code:s}=t,i=Xr(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!==Pe)throw new Error(`Version 0 CID must use dag-pb (code: ${Pe}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let o=nn(e,t,n.bytes);return new r(e,t,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,Pe,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=k(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 de(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[l,w]=Ae(e.subarray(t));return t+=w,l},o=n(),s=Pe;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(),p=t+c,h=p-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:h,size:p}}static parse(e,t){let[n,o]=ls(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 Yt(s).set(n,e),s}};function ls(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 J.prefix:{let t=e??J;return[J.prefix,t.decode(r)]}case Te.prefix:{let t=e??Te;return[Te.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 fs(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 hs(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 Pe=112,ds=18;function nn(r,e,t){let n=he(r),o=n+he(e),s=new Uint8Array(o+t.byteLength);return fe(r,s,0),fe(e,s,n),s.set(t,o),s}var ps=Symbol.for("@ipld/js-cid/CID");var Oe={...qt,...Mt,...jt,...Nt,...Rt,...kt,...zt,...$t,...Wt,...Vt},Na={...Kt,...Qt};function sn(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var on=sn("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Zt=sn("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=De(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),ms={utf8:on,"utf-8":on,hex:Oe.base16,latin1:Zt,ascii:Zt,binary:Zt,...Oe},Qe=ms;function be(r,e="utf8"){let t=Qe[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return e==="utf8"||e==="utf-8"?Z(an.Buffer.from(r,"utf-8")):t.decoder.decode(`${t.prefix}${r}`)}var cn=B("node:buffer");function K(r,e="utf8"){let t=Qe[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return e==="utf8"||e==="utf-8"?cn.Buffer.from(r.buffer,r.byteOffset,r.byteLength).toString("utf8"):t.encoder.encode(r).substring(1)}var L=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},W=class extends Error{static name="ValidationError";name="ValidationError"},Ge=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},Xe=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};var M=B("node:net");function tr(r){return e=>K(e,r)}function rr(r){return e=>be(e,r)}function ge(r){return new DataView(r.buffer).getUint16(r.byteOffset).toString()}function te(r){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,typeof r=="string"?parseInt(r):r),new Uint8Array(e)}function un(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=be(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=te(n);return ue([t,o],t.length+o.length)}function ln(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=te(n);return ue([t,o],t.length+o.length)}function nr(r){let e=r.subarray(0,r.length-2),t=r.subarray(r.length-2),n=K(e,"base32"),o=ge(t);return`${n}:${o}`}var or=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 L("Invalid byte value in IP address");e[n]=o}),e},fn=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,M.isIPv4)(t[n]),i;s&&(i=or(t[n]),t[n]=K(i.subarray(0,2),"base16")),i!=null&&++n<8&&t.splice(n,0,K(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 L("Invalid byte value in IP address");o[e++]=s>>8&255,o[e++]=s&255}return o},hn=function(r){if(r.byteLength!==4)throw new L("IPv4 address was incorrect length");let e=[];for(let t=0;t<r.byteLength;t++)e.push(r[t]);return e.join(".")},dn=function(r){if(r.byteLength!==16)throw new L("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 L(`Invalid IPv6 address "${t}"`)}};function pn(r){try{let e=new URL(`http://[${r}]`);return e.hostname.substring(1,e.hostname.length-1)}catch{throw new L(`Invalid IPv6 address "${r}"`)}}var er=Object.values(Oe).map(r=>r.decoder),bs=(function(){let r=er[0].or(er[1]);return er.slice(2).forEach(e=>r=r.or(e)),r})();function mn(r){return bs.decode(r)}function bn(r){return e=>r.encoder.encode(e)}function gs(r){if(parseInt(r).toString()!==r)throw new W("Value must be an integer")}function ws(r){if(r<0)throw new W("Value must be a positive integer, or zero")}function ys(r){return e=>{if(e>r)throw new W(`Value must be smaller than or equal to ${r}`)}}function xs(...r){return e=>{for(let t of r)t(e)}}var _e=xs(gs,ws,ys(65535));var T=-1,sr=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 Xe(`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)}))}},q=new sr,Us=[{code:4,name:"ip4",size:32,valueToBytes:or,bytesToValue:hn,validate:r=>{if(!(0,M.isIPv4)(r))throw new W(`Invalid IPv4 address "${r}"`)}},{code:6,name:"tcp",size:16,valueToBytes:te,bytesToValue:ge,validate:_e},{code:273,name:"udp",size:16,valueToBytes:te,bytesToValue:ge,validate:_e},{code:33,name:"dccp",size:16,valueToBytes:te,bytesToValue:ge,validate:_e},{code:41,name:"ip6",size:128,valueToBytes:fn,bytesToValue:dn,stringToValue:pn,validate:r=>{if(!(0,M.isIPv6)(r))throw new W(`Invalid IPv6 address "${r}"`)}},{code:42,name:"ip6zone",size:T},{code:43,name:"ipcidr",size:8,bytesToValue:tr("base10"),valueToBytes:rr("base10")},{code:53,name:"dns",size:T},{code:54,name:"dns4",size:T},{code:55,name:"dns6",size:T},{code:56,name:"dnsaddr",size:T},{code:132,name:"sctp",size:16,valueToBytes:te,bytesToValue:ge,validate:_e},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:T,stringToValue:r=>decodeURIComponent(r),valueToString:r=>encodeURIComponent(r)},{code:421,name:"p2p",aliases:["ipfs"],size:T,bytesToValue:tr("base58btc"),valueToBytes:r=>r.startsWith("Q")||r.startsWith("1")?rr("base58btc")(r):me.parse(r).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:nr,valueToBytes:un},{code:445,name:"onion3",size:296,bytesToValue:nr,valueToBytes:ln},{code:446,name:"garlic64",size:T},{code:447,name:"garlic32",size:T},{code:448,name:"tls"},{code:449,name:"sni",size:T},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:T,bytesToValue:bn(Ft),valueToBytes:mn},{code:480,name:"http"},{code:481,name:"http-path",size:T,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:T}];Us.forEach(r=>{q.addProtocol(r)});function gn(r){let e=[],t=0;for(;t<r.length;){let n=Lt(r,t),o=q.getProtocol(n),s=ce(n),i=Ns(o,r,t+s),a=0;i>0&&o.size===T&&(a=ce(i));let c=s+a+i,p={code:n,name:o.name,bytes:Pt(r.subarray(t,t+c))};if(i>0){let h=t+s+a,l=r.subarray(h,h+i);p.value=o.bytesToValue?.(l)??K(l)}e.push(p),t+=c}return e}function wn(r){let e=0,t=[];for(let n of r){if(n.bytes==null){let o=q.getProtocol(n.code),s=ce(n.code),i,a=0,c=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??be(n.value),a=i.byteLength,o.size===T&&(c=ce(a)));let p=new Uint8Array(s+c+a),h=0;At(n.code,p,h),h+=s,i!=null&&(o.size===T&&(At(a,p,h),h+=c),p.set(i,h)),n.bytes=p}t.push(n.bytes),e+=n.bytes.byteLength}return ue(t,e)}function yn(r){if(r.charAt(0)!=="/")throw new L('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=q.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 L(`Component ${o} was missing value`);t="value"}else if(t==="value"){let p={code:c.code,name:c.name};if(c.size!=null&&c.size!==0){if(n==="")throw new L(`Component ${o} was missing value`);p.value=c.stringToValue?.(n)??n}e.push(p),n="",o="",t="protocol"}}}if(o!==""&&n!=="")throw new L("Incomplete multiaddr");return e}function xn(r){return`/${r.flatMap(e=>{if(e.value==null)return e.name;let t=q.getProtocol(e.code);if(t==null)throw new L(`Unknown protocol code ${e.code}`);return[e.name,t.valueToString?.(e.value)??e.value]}).join("/")}`}function Ns(r,e,t){return r.size==null||r.size===0?0:r.size>0?r.size/8:Lt(e,t)}var Rs=Symbol.for("nodejs.util.inspect.custom"),wr=Symbol.for("@multiformats/multiaddr");function Ms(r){if(r==null&&(r="/"),En(r))return r.getComponents();if(r instanceof Uint8Array)return gn(r);if(typeof r=="string")return r=r.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),r===""&&(r="/"),yn(r);if(Array.isArray(r))return r;throw new L("Must be a string, Uint8Array, Component[], or another Multiaddr")}var ot=class r{[wr]=!0;#e;#t;#r;constructor(e="/",t={}){this.#e=Ms(e),t.validate!==!1&&Vs(this)}get bytes(){return this.#r==null&&(this.#r=wn(this.#e)),this.#r}toString(){return this.#t==null&&(this.#t=xn(this.#e)),this.#t}toJSON(){return this.toString()}getComponents(){return[...this.#e.map(e=>({...e}))]}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 Ge(`Address ${this.toString()} does not contain subaddress: ${t}`);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})}equals(e){return Ct(this.bytes,e.bytes)}[Rs](){return`Multiaddr(${this.toString()})`}};function Vs(r){r.getComponents().forEach(e=>{let t=q.getProtocol(e.code);e.value!=null&&t.validate?.(e.value)})}function En(r){return!!r?.[wr]}function ne(r){return new ot(r)}var x=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)}}),vn=r=>({match:e=>r.match(e)===!1?e:!1}),f=r=>({match:e=>{let t=r.match(e);return t===!1?e:t}}),O=(...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}}),g=(...r)=>({match:e=>{for(let t of r){let n=t.match(e);if(n===!1)return!1;e=n}return e}});function E(...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 ks=u(421),Hc=E(ks),it=u(54),at=u(55),ct=u(56),xr=u(53),Qc=E(it,f(u(421))),Gc=E(at,f(u(421))),Xc=E(ct,f(u(421))),Jc=E(O(xr,ct,it,at),f(u(421))),Cn=g(u(4),f(u(43))),Sn=g(f(u(42)),u(41),f(u(43))),Er=O(Cn,Sn),Ee=O(Er,xr,it,at,ct),Kc=E(O(Er,g(O(xr,ct,it,at),f(u(421))))),Yc=E(Cn),Zc=E(Sn),eu=E(Er),vr=g(Ee,u(6)),Ue=g(Ee,u(273)),Dn=E(g(vr,f(u(421)))),tu=E(Ue),Cr=g(Ue,x(460),f(u(421))),ut=g(Ue,x(461),f(u(421))),zs=O(Cr,ut),ru=E(Cr),nu=E(ut),yr=O(Ee,vr,Ue,Cr,ut),Tn=O(g(yr,x(477),f(u(421)))),ou=E(Tn),In=O(g(yr,x(478),f(u(421))),g(yr,x(448),f(u(449)),x(477),f(u(421)))),su=E(In),An=g(Ue,x(280),f(u(466)),f(u(466)),f(u(421))),iu=E(An),Ln=g(ut,x(465),f(u(466)),f(u(466)),f(u(421))),au=E(Ln),st=O(Tn,In,g(vr,f(u(421))),g(zs,f(u(421))),g(Ee,f(u(421))),An,Ln,u(421)),cu=E(st),$s=g(f(st),x(290),vn(x(281)),f(u(421))),uu=E($s),Fs=O(g(st,x(290),x(281),f(u(421))),g(st,x(281),f(u(421))),g(x(281),f(u(421)))),lu=E(Fs),Ws=g(Ee,O(g(u(6,"80")),g(u(6),x(480)),x(480)),f(u(481)),f(u(421))),fu=E(Ws),js=g(Ee,O(g(u(6,"443")),g(u(6,"443"),x(480)),g(u(6),x(443)),g(u(6),x(448),x(480)),g(x(448),x(480)),x(448),x(443)),f(u(481)),f(u(421))),hu=E(js),qs=O(g(u(777),f(u(421)))),du=E(qs),Hs=O(g(u(400),f(u(421)))),lt=E(Hs);var ft=class extends Event{type;detail;constructor(e,t){super(e),this.type=e,this.detail=t}};var Wn=oe(B("node:net"),1);var Sr=B("node:buffer");function Ne(r){return new Uint8Array(r.buffer,r.byteOffset,r.byteLength)}function H(r=0){return Ne(Sr.Buffer.alloc(r))}function Dr(r=0){return Ne(Sr.Buffer.allocUnsafe(r))}var Pn=B("node:buffer");function Tr(r,e){return Ne(Pn.Buffer.concat(r,e))}function On(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 Bn=Symbol.for("@achingbrain/uint8arraylist");function _n(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 ht(r){return!!r?.[Bn]}var ve=class r{bufs;length;[Bn]=!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(ht(n)){t+=n.byteLength;for(let o of n.bufs)this.bufs.push(o)}else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=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(ht(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=_n(this.bufs,e);return t.buf[t.index]}set(e,t){let n=_n(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(ht(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 Tr(n,o)}subarray(e,t){let{bufs:n,length:o}=this._subList(e,t);return n.length===1?n[0]:Tr(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 p=e>=a&&e<c,h=t>a&&t<=c;if(p&&h){if(e===a&&t===c){n.push(i);break}let l=e-a;n.push(i.subarray(l,l+(t-e)));break}if(p){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(!ht(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 l=0;l<s;l++)i[l]=-1;for(let l=0;l<o;l++)i[n[l]]=l;let a=i,c=this.byteLength-n.byteLength,p=n.byteLength-1,h;for(let l=t;l<=c;l+=h){h=0;for(let w=p;w>=0;w--){let d=this.get(l+w);if(n[w]!==d){h=Math.max(1,w-a[d]);break}}if(h===0)return l}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=Dr(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=H(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=H(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=H(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=Dr(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=H(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=H(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=H(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=H(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=H(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(!On(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 Qs(r){let e=r.getComponents(),t={},n=0;return e[n]?.name==="ip6zone"&&(t.zone=`${e[n].value}`,n++),e[n]?.name==="ip4"||e[n]?.name==="ip6"||e[n]?.name==="dns"||e[n]?.name==="dns4"||e[n]?.name==="dns6"?(t.type=e[n].name,t.host=e[n].value,n++):e[n]?.name==="dnsaddr"&&(t.type=e[n].name,t.host=`_dnsaddr.${e[n].value}`,n++),(e[n]?.name==="tcp"||e[n]?.name==="udp")&&(t.protocol=e[n].name==="tcp"?"tcp":"udp",t.port=parseInt(`${e[n].value}`),n++),e[n]?.name==="ipcidr"&&(t.type==="ip4"?t.cidr=parseInt(`${e[n].value}`):t.type==="ip6"&&(t.cidr=`${e[n].value}`),n++),t.type==null||t.host==null?null:(e[n]?.name==="tls"&&e[n+1]?.name==="sni"&&(t.sni=e[n+1].value,n+=2),t)}function dt(r){let e=Qs(r);if(e==null)throw new U(`Multiaddr ${r} was not an IPv4, IPv6, DNS, DNS4, DNS6 or DNSADDR address`);return e}function pt(){let r={};return r.promise=new Promise((e,t)=>{r.resolve=e,r.reject=t}),r}var mt=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}},Ce=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new mt(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 mt(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 Ir=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.code=t??"ABORT_ERR"}};function Un(r={}){return Gs(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 Gs(r,e){e=e??{};let t=e.onEnd,n=new Ce,o,s,i,a=pt(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((b,D)=>{s=_=>{s=null,n.push(_);try{b(r(n))}catch(A){D(A)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=pt()})}},p=b=>s!=null?s(b):(n.push(b),o),h=b=>(n=new Ce,s!=null?s({error:b}):(n.push({error:b}),o)),l=b=>{if(i)return o;if(e?.objectMode!==!0&&b?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return p({done:!1,value:b})},w=b=>i?o:(i=!0,b!=null?h(b):p({done:!0})),d=()=>(n=new Ce,w(),{done:!0}),m=b=>(w(b),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:d,throw:m,push:l,end:w,get readableLength(){return n.size},onEmpty:async b=>{let D=b?.signal;if(D?.throwIfAborted(),n.isEmpty())return;let _,A;D!=null&&(_=new Promise((N,V)=>{A=()=>{V(new Ir)},D.addEventListener("abort",A)}));try{await Promise.race([a.promise,_])}finally{A!=null&&D!=null&&D?.removeEventListener("abort",A)}}},t==null)return o;let v=o;return o={[Symbol.asyncIterator](){return this},next(){return v.next()},throw(b){return v.throw(b),t!=null&&(t(b),t=void 0),{done:!0}},return(){return v.return(),t!=null&&(t(),t=void 0),{done:!0}},push:l,end(b){return v.end(b),t!=null&&(t(b),t=void 0),o},get readableLength(){return v.readableLength},onEmpty:b=>v.onEmpty(b)},o}var Ar=class r extends Error{name="TimeoutError";constructor(e,t){super(e,t),Error.captureStackTrace?.(this,r)}},Nn=r=>r.reason??new DOMException("This operation was aborted.","AbortError");function Lr(r,e){let{milliseconds:t,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout},signal:i}=e,a,c,h=new Promise((l,w)=>{if(typeof t!="number"||Math.sign(t)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${t}\``);if(i?.aborted){w(Nn(i));return}if(i&&(c=()=>{w(Nn(i))},i.addEventListener("abort",c,{once:!0})),r.then(l,w),t===Number.POSITIVE_INFINITY)return;let d=new Ar;a=s.setTimeout.call(void 0,()=>{if(n){try{l(n())}catch(m){w(m)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?l():o instanceof Error?w(o):(d.message=o??`Promise timed out after ${t} milliseconds`,w(d))},t)}).finally(()=>{h.clear(),c&&i&&i.removeEventListener("abort",c)});return h.clear=()=>{s.clearTimeout.call(void 0,a),a=void 0},h}var Xs=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,rejectionMultiArgs:!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:p,removeListener:h}=Xs(r),l=async(...d)=>{let m=t.multiArgs?d:d[0];if(t.filter)try{if(!await t.filter(m))return}catch(v){n(),i(v);return}c.push(m),t.count===c.length&&(n(),s(c))},w=(...d)=>{n(),i(t.rejectionMultiArgs?d:d[0])};n=()=>{for(let d of a)h(d,l);for(let d of t.rejectionEvents)a.includes(d)||h(d,w)};for(let d of a)p(d,l);for(let d of t.rejectionEvents)a.includes(d)||p(d,w);t.signal&&t.signal.addEventListener("abort",()=>{w(t.signal.reason)},{once:!0}),t.resolveImmediately&&s(c)});if(o.cancel=n,typeof t.timeout=="number"){let s=Lr(o,{milliseconds:t.timeout});return s.cancel=()=>{n(),s.clear()},s}return o}function Y(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 bt=class extends Error{static name="StreamClosedError";name="StreamClosedError"};function Ks(r){return r.reason}async function Rn(r,e,t){if(e==null)return r;let n=t?.translateError??Ks;if(e.aborted)return r.catch(()=>{}),Promise.reject(n(e));let o;try{return await Promise.race([r,new Promise((s,i)=>{o=()=>{i(n(e))},e.addEventListener("abort",o)})])}finally{o!=null&&e.removeEventListener("abort",o)}}var Ys=Math.pow(2,20)*4,gt=class extends ae{status;timeline;inactivityTimeout;maxReadBufferLength;maxWriteBufferLength;log;direction;maxMessageSize;readStatus;writeStatus;remoteReadStatus;remoteWriteStatus;writableNeedsDrain;readBuffer;writeBuffer;sendingData;onDrainPromise;constructor(e){super(),this.status="open",this.log=e.log,this.direction=e.direction??"outbound",this.inactivityTimeout=e.inactivityTimeout??12e4,this.maxReadBufferLength=e.maxReadBufferLength??Ys,this.maxWriteBufferLength=e.maxWriteBufferLength,this.maxMessageSize=e.maxMessageSize,this.readBuffer=new ve,this.writeBuffer=new ve,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.writableNeedsDrain&&(this.log.trace("drain event received, continue sending data"),this.writableNeedsDrain=!1,queueMicrotask(()=>{try{this.processSendQueue()}catch(o){this.log.error("processSendQueue threw - %e",o)}})),this.onDrainPromise?.resolve()};this.addEventListener("drain",t);let n=o=>{this.onDrainPromise?.reject(o.error??new bt)};this.addEventListener("close",n)}get readBufferLength(){return this.readBuffer.byteLength}get writeBufferLength(){return this.writeBuffer.byteLength}async onDrain(e){return this.writableNeedsDrain!==!0?Promise.resolve():(this.onDrainPromise==null&&(this.onDrainPromise=Promise.withResolvers()),Rn(this.onDrainPromise.promise,e?.signal))}async*[Symbol.asyncIterator](){if(this.readStatus!=="readable"&&this.readStatus!=="paused")return;let e=Un(),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 G(`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 We(e))}}pause(){if(this.readStatus==="closed"||this.readStatus==="closing")throw new G("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 G("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 G(`Cannot push data onto a stream that is ${this.readStatus}`);if(e.byteLength!==0){if(this.readBuffer.append(e),this.readStatus==="paused"||this.listenerCount("message")===0){this.checkReadBufferLength();return}setTimeout(()=>{this.dispatchReadBuffer()},0)}}unshift(e){if(this.readStatus==="closed"||this.readStatus==="closing")throw new G(`Cannot push data onto a stream that is ${this.readStatus}`);if(e.byteLength!==0){if(this.readBuffer.prepend(e),this.readStatus==="paused"||this.listenerCount("message")===0){this.checkReadBufferLength();return}setTimeout(()=>{this.dispatchReadBuffer()},0)}}onData(e){if(e.byteLength!==0){if(this.readStatus==="closing"||this.readStatus==="closed"){this.log("ignoring data - read status %s",this.readStatus);return}this.readBuffer.append(e),this.dispatchReadBuffer()}}addEventListener(...e){super.addEventListener.apply(this,e),e[0]==="message"&&this.readBuffer.byteLength>0&&queueMicrotask(()=>{this.dispatchReadBuffer()})}onRemoteReset(){this.log("remote reset"),this.status="reset",this.writeStatus="closed",this.remoteWriteStatus="closed",this.remoteReadStatus="closed",this.timeline.close=Date.now(),this.readBuffer.byteLength===0&&(this.readStatus="closed");let e=new ke;this.dispatchEvent(new je(e))}onTransportClosed(e){this.log("transport closed"),this.readStatus==="readable"&&this.readBuffer.byteLength===0&&(this.log("close readable end after transport closed and read buffer is empty"),this.readStatus="closed"),this.remoteReadStatus!=="closed"&&(this.remoteReadStatus="closed"),this.remoteWriteStatus!=="closed"&&(this.remoteWriteStatus="closed"),this.writeStatus!=="closed"&&(this.writeStatus="closed"),e!=null?this.abort(e):(this.status==="open"||this.status==="closing")&&(this.timeline.close=Date.now(),this.status="closed",this.writeStatus="closed",this.remoteWriteStatus="closed",this.remoteReadStatus="closed",this.dispatchEvent(new ie))}onRemoteCloseWrite(){this.remoteWriteStatus!=="closed"&&(this.log.trace("on remote close write"),this.remoteWriteStatus="closed",this.safeDispatchEvent("remoteCloseWrite"),this.writeStatus==="closed"&&this.onTransportClosed())}onRemoteCloseRead(){this.log.trace("on remote close read"),this.remoteReadStatus="closed",this.writeBuffer.byteLength>0&&(this.writeBuffer.consume(this.writeBuffer.byteLength),this.safeDispatchEvent("idle"))}processSendQueue(){if(this.writableNeedsDrain)return this.log.trace("not processing send queue as drain is required"),this.checkWriteBufferLength(),!1;if(this.writeBuffer.byteLength===0)return this.log.trace("not processing send queue as no bytes to send"),!0;if(this.sendingData)return this.log.trace("not processing send queue as already sending data"),!0;if(this.writeStatus!=="writable"&&this.writeStatus!=="closing")return this.log.trace("not processing send queue as stream is %s",this.writeStatus),!1;this.sendingData=!0,this.log.trace("processing send queue with %d queued bytes",this.writeBuffer.byteLength);try{let e=!0,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 ve(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 Fe(e))}finally{this.readBuffer.byteLength===0&&this.remoteWriteStatus==="closed"&&(this.log("close readable end after dispatching read buffer and remote writable end is closed"),this.readStatus="closed"),this.checkReadBufferLength()}}checkReadBufferLength(){this.readBuffer.byteLength>this.maxReadBufferLength&&this.abort(new Se(`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 Se(`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 gt{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 Y(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 Y(this,"drain",{...e,rejectionEvents:["close"]})),await this.sendClose(e),this.onTransportClosed())}};var Vn=oe(B("node:os"),1);function Mn(r){return!!(r.startsWith("169.254.")||r.toLowerCase().startsWith("fe80"))}function Pr(r,e,t){let n=[r.type,t??r.host];if(r.protocol!=null){let o=e??r.port;o!=null&&n.push(r.protocol,o)}return r.type==="ip6"&&r.zone!=null&&n.unshift("ip6zone",r.zone),r.cidr!=null&&n.push("ipcidr",r.cidr),ne(`/${n.join("/")}`)}var Zs={4:"IPv4",6:"IPv6"};function ei(r){return["0.0.0.0","::"].includes(r)}function ti(r){let e=[],t=Vn.default.networkInterfaces();for(let[,n]of Object.entries(t))if(n!=null)for(let o of n)Mn(o.address)||o.family===Zs[r]&&e.push(o.address);return e}function kn(r,e){if(r==null)return[];let t=dt(r);return(t.type==="ip4"||t.type==="ip6")&&ei(t.host)?ti(t.type==="ip4"?4:6).map(n=>Pr(t,e,n)):[Pr(t,e)]}function zn(r,e){if(typeof r!="string")throw new U(`invalid ip provided: ${r}`);if(typeof e=="string"&&(e=parseInt(e)),isNaN(e))throw new U(`invalid port provided: ${e}`);if((0,M.isIPv4)(r))return ne(`/ip4/${r}/tcp/${e}`);if((0,M.isIPv6)(r))return ne(`/ip6/${r}/tcp/${e}`);throw new U(`invalid ip:port for creating a multiaddr: ${r}:${e}`)}var Or=class extends wt{socket;constructor(e){let t=e.remoteAddr;if(e.localAddr!=null&<.matches(e.localAddr))t=e.localAddr;else if(t==null){if(e.socket.remoteAddress==null||e.socket.remotePort==null)throw new U("Could not determine remote address or port");t=zn(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 se)}),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 Y(this.socket,"close",e))}sendReset(){this.socket.resetAndDestroy()}sendPause(){this.socket.pause()}sendResume(){this.socket.resume()}},yt=r=>new Or(r);var $n=oe(B("os"),1),Fn=oe(B("path"),1);function xt(r,e={}){if(lt.exactMatch(r)){let s=r.getComponents().find(i=>i.code===400)?.value;if(s==null)throw new U(`Multiaddr ${r} was not a Unix address`);return $n.default.platform()==="win32"?{path:Fn.default.join("\\\\.\\pipe\\",s)}:{path:s}}let t=dt(r),n=t.host,o=t.port;return{host:n,port:o,ipv6Only:t.type==="ip6",...e}}var I;(function(r){r[r.INACTIVE=0]="INACTIVE",r[r.ACTIVE=1]="ACTIVE",r[r.PAUSED=2]="PAUSED"})(I||(I={}));var Et=class extends ae{context;server;sockets=new Set;status={code:I.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,qe(1/0,this.shutdownController.signal),this.log=e.logger.forComponent("libp2p:tcp:listener"),this.addr="unknown",this.server=Wn.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 U("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]:I.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!==I.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!==I.ACTIVE)throw e.destroy(),new ze("Server is not listening yet");let t;try{t=yt({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 - %e",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 - %e",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 - %e",n),this.metrics.errors?.increment({[`${this.addr} inbound_upgrade`]:!0}),this.sockets.delete(e),t.abort(n)})}getAddrs(){if(this.status.code===I.INACTIVE)return[];let e=this.server.address();return e==null?[]:typeof e=="string"?[ne(`/unix/${encodeURIComponent(e)}`)]:kn(this.status.listeningAddr,e.port)}updateAnnounceAddrs(){}async listen(e){if(this.status.code===I.ACTIVE||this.status.code===I.PAUSED)throw new $e("server is already listening");try{this.status={code:I.ACTIVE,listeningAddr:e,netConfig:xt(e,this.context)},await this.resume()}catch(t){throw this.status={code:I.INACTIVE},t}}async close(e){let t=[];this.server.listening&&t.push(Y(this.server,"close",e)),this.pause(!0),this.shutdownController.abort(),this.sockets.forEach(n=>{n.readable&&(t.push(Y(n,"close",e)),n.destroy())}),await Promise.all(t)}async resume(){if(this.server.listening||this.status.code===I.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:I.ACTIVE},this.log("listening on %s",this.server.address())}pause(e=!1){if(!this.server.listening&&this.status.code===I.PAUSED&&e){this.status={code:I.INACTIVE};return}!this.server.listening||this.status.code!==I.ACTIVE||(this.log("%s server on %s",e?"closing":"pausing",this.server.address()),this.status=e?{code:I.INACTIVE}:{...this.status,code:I.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"})})}[Ur]=!0;[Symbol.toStringTag]="@libp2p/tcp";[Rr]=["@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=yt({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 - %e",s),o.abort(s),s}}async _connect(e,t){t.signal.throwIfAborted(),t.onProgress?.(new ft("tcp:open-connection"));let n;return new Promise((o,s)=>{let i=Date.now(),a=xt(e,{...this.opts.dialOpts??{},...t});this.log("dialing %a with opts %o",e,a),n=jn.default.connect(a);let c=d=>{this.log.error("dial to %a errored - %e",e,d);let m=a.path??`${a.host??""}:${a.port}`;d.message=`connection error ${m}: ${d.message}`,this.metrics?.events.increment({error:!0}),w(d)},p=()=>{this.log("connection timeout %a",e),this.metrics?.events.increment({timeout:!0});let d=new se(`Connection timeout after ${Date.now()-i}ms`);n.emit("error",d)},h=()=>{this.log("connection opened %a",e),this.metrics?.events.increment({connect:!0}),w()},l=()=>{this.log("connection aborted %a",e),this.metrics?.events.increment({abort:!0}),w(new Ve)},w=d=>{if(n.removeListener("error",c),n.removeListener("timeout",p),n.removeListener("connect",h),t.signal!=null&&t.signal.removeEventListener("abort",l),d!=null){s(d);return}o(n)};n.on("error",c),n.on("timeout",p),n.on("connect",h),t.signal.addEventListener("abort",l)}).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=>Dn.exactMatch(t)||t.toString().startsWith("/unix/"))}dialFilter(e){return this.listenFilter(e)}};function ri(r={}){return e=>new vt(e,r)}return Jn(ni);})();
|
|
3
3
|
return Libp2PTcp}));
|
|
4
4
|
//# sourceMappingURL=index.min.js.map
|