@libp2p/tcp 10.1.17 → 10.1.18

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