🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

@libp2p/tcp

Package Overview
Dependencies
Maintainers
6
Versions
769
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@libp2p/tcp - npm Package Compare versions

Comparing version

to
10.1.13-8e87be9e6

2

dist/index.min.js
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PTcp = factory()}(typeof self !== 'undefined' ? self : this, function () {
"use strict";var Libp2PTcp=(()=>{var Jr=Object.create;var ye=Object.defineProperty;var Xr=Object.getOwnPropertyDescriptor;var Kr=Object.getOwnPropertyNames;var Yr=Object.getPrototypeOf,Zr=Object.prototype.hasOwnProperty;var F=(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 k=(r,e)=>{for(var t in e)ye(r,t,{get:e[t],enumerable:!0})},jt=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Kr(e))!Zr.call(r,o)&&o!==t&&ye(r,o,{get:()=>e[o],enumerable:!(n=Xr(e,o))||n.enumerable});return r};var Z=(r,e,t)=>(t=r!=null?Jr(Yr(r)):{},jt(e||!r||!r.__esModule?ye(t,"default",{value:r,enumerable:!0}):t,r)),en=r=>jt(ye({},"__esModule",{value:!0}),r);var ts={};k(ts,{tcp:()=>es});var Qr=Z(F("net"),1);var qt=Symbol.for("@libp2p/transport");var Wt;(function(r){r[r.FATAL_ALL=0]="FATAL_ALL",r[r.NO_FATAL=1]="NO_FATAL"})(Wt||(Wt={}));var ve=class extends Error{static name="AbortError";constructor(e="The operation was aborted"){super(e),this.name="AbortError"}};var B=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}};var ee=class extends Error{static name="TimeoutError";constructor(e="Timed out"){super(e),this.name="TimeoutError"}},Ee=class extends Error{static name="NotStartedError";constructor(e="Not started"){super(e),this.name="NotStartedError"}},Ie=class extends Error{static name="AlreadyStartedError";constructor(e="Already started"){super(e),this.name="AlreadyStartedError"}};var Gt=F("node:events"),Ae=(r,...e)=>{try{(0,Gt.setMaxListeners)(r,...e)}catch{}};var Te=class extends EventTarget{#e=new Map;constructor(){super(),Ae(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 Ht=Symbol.for("@libp2p/service-capabilities"),as=Symbol.for("@libp2p/service-dependencies");var S=F("node:net");function Ce(r){return!!(0,S.isIP)(r)}var Je={};k(Je,{base58btc:()=>P,base58flickr:()=>an});var Us=new Uint8Array(0);function Qt(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 O(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 Jt(r){return new TextEncoder().encode(r)}function Xt(r){return new TextDecoder().decode(r)}function tn(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 c=r.length,l=r.charAt(0),d=Math.log(c)/Math.log(256),m=Math.log(256)/Math.log(c);function f(u){if(u instanceof Uint8Array||(ArrayBuffer.isView(u)?u=new Uint8Array(u.buffer,u.byteOffset,u.byteLength):Array.isArray(u)&&(u=Uint8Array.from(u))),!(u instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(u.length===0)return"";for(var T=0,N=0,x=0,b=u.length;x!==b&&u[x]===0;)x++,T++;for(var M=(b-x)*m+1>>>0,$=new Uint8Array(M);x!==b;){for(var z=u[x],H=0,V=M-1;(z!==0||H<N)&&V!==-1;V--,H++)z+=256*$[V]>>>0,$[V]=z%c>>>0,z=z/c>>>0;if(z!==0)throw new Error("Non-zero carry");N=H,x++}for(var j=M-N;j!==M&&$[j]===0;)j++;for(var be=l.repeat(T);j<M;++j)be+=r.charAt($[j]);return be}function v(u){if(typeof u!="string")throw new TypeError("Expected String");if(u.length===0)return new Uint8Array;var T=0;if(u[T]!==" "){for(var N=0,x=0;u[T]===l;)N++,T++;for(var b=(u.length-T)*d+1>>>0,M=new Uint8Array(b);u[T];){var $=t[u.charCodeAt(T)];if($===255)return;for(var z=0,H=b-1;($!==0||z<x)&&H!==-1;H--,z++)$+=c*M[H]>>>0,M[H]=$%256>>>0,$=$/256>>>0;if($!==0)throw new Error("Non-zero carry");x=z,T++}if(u[T]!==" "){for(var V=b-x;V!==b&&M[V]===0;)V++;for(var j=new Uint8Array(N+(b-V)),be=N;V!==b;)j[be++]=M[V++];return j}}}function a(u){var T=v(u);if(T)return T;throw new Error(`Non-${e} character`)}return{encode:f,decodeUnsafe:v,decode:a}}var rn=tn,nn=rn,Yt=nn;var qe=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")}},Ge=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 Zt(this,e)}},He=class{decoders;constructor(e){this.decoders=e}or(e){return Zt(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 Zt(r,e){return new He({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var Qe=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 qe(e,t,n),this.decoder=new Ge(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function te({name:r,prefix:e,encode:t,decode:n}){return new Qe(r,e,t,n)}function Q({name:r,prefix:e,alphabet:t}){let{encode:n,decode:o}=Yt(t,r);return te({prefix:e,name:r,encode:n,decode:s=>O(o(s))})}function on(r,e,t,n){let o=r.length;for(;r[o-1]==="=";)--o;let s=new Uint8Array(o*t/8|0),i=0,c=0,l=0;for(let d=0;d<o;++d){let m=e[r[d]];if(m===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<t|m,i+=t,i>=8&&(i-=8,s[l++]=255&c>>i)}if(i>=t||(255&c<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function sn(r,e,t){let n=e[e.length-1]==="=",o=(1<<t)-1,s="",i=0,c=0;for(let l=0;l<r.length;++l)for(c=c<<8|r[l],i+=8;i>t;)i-=t,s+=e[o&c>>i];if(i!==0&&(s+=e[o&c<<t-i]),n)for(;(s.length*t&7)!==0;)s+="=";return s}function cn(r){let e={};for(let t=0;t<r.length;++t)e[r[t]]=t;return e}function A({name:r,prefix:e,bitsPerChar:t,alphabet:n}){let o=cn(n);return te({prefix:e,name:r,encode(s){return sn(s,n,t)},decode(s){return on(s,o,t,r)}})}var P=Q({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),an=Q({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Ke={};k(Ke,{base64:()=>ln,base64pad:()=>un,base64url:()=>Xe,base64urlpad:()=>dn});var ln=A({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),un=A({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Xe=A({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),dn=A({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var pn=r=>r.toString().split("/").slice(1),re=r=>({match:e=>e.length<1?!1:r(e[0])?e.slice(1):!1,pattern:"fn"}),p=r=>({match:e=>re(t=>t===r).match(e),pattern:r}),X=()=>({match:r=>re(e=>typeof e=="string").match(r),pattern:"{string}"}),ne=()=>({match:r=>re(e=>!isNaN(parseInt(e))).match(r),pattern:"{number}"}),y=()=>({match:r=>{if(r.length<2||r[0]!=="p2p"&&r[0]!=="ipfs")return!1;if(r[1].startsWith("Q")||r[1].startsWith("1"))try{P.decode(`z${r[1]}`)}catch{return!1}else return!1;return r.slice(2)},pattern:"/p2p/{peerid}"}),pe=()=>({match:r=>{if(r.length<2||r[0]!=="certhash")return!1;try{Xe.decode(r[1])}catch{return!1}return r.slice(2)},pattern:"/certhash/{certhash}"}),g=r=>({match:e=>{let t=r.match(e);return t===!1?e:t},pattern:`optional(${r.pattern})`}),L=(...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},pattern:`or(${r.map(e=>e.pattern).join(", ")})`}),h=(...r)=>({match:e=>{for(let t of r){let n=t.match(e);if(n===!1)return!1;e=n}return e},pattern:`and(${r.map(e=>e.pattern).join(", ")})`});function I(...r){function e(o){let s=pn(o);for(let i of r){let c=i.match(s);if(c===!1)return!1;s=c}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 fn=y(),Ws=I(fn),Pe=h(p("dns4"),X()),Le=h(p("dns6"),X()),De=h(p("dnsaddr"),X()),Ze=h(p("dns"),X()),qs=I(Pe,g(y())),Gs=I(Le,g(y())),Hs=I(De,g(y())),Qs=I(L(Ze,De,Pe,Le),g(y())),er=h(p("ip4"),re(S.isIPv4)),tr=h(p("ip6"),re(S.isIPv6)),et=L(er,tr),W=L(et,Ze,Pe,Le,De),Js=I(L(et,h(L(Ze,De,Pe,Le),g(y())))),Xs=I(er),Ks=I(tr),Ys=I(et),tt=h(W,p("tcp"),ne()),fe=h(W,p("udp"),ne()),rr=I(h(tt,g(y()))),Zs=I(fe),rt=h(fe,p("quic"),g(y())),Ne=h(fe,p("quic-v1"),g(y())),hn=L(rt,Ne),ei=I(rt),ti=I(Ne),Ye=L(W,tt,fe,rt,Ne),nr=L(h(Ye,p("ws"),g(y()))),ri=I(nr),or=L(h(Ye,p("wss"),g(y())),h(Ye,p("tls"),g(h(p("sni"),X())),p("ws"),g(y()))),ni=I(or),sr=h(fe,p("webrtc-direct"),g(pe()),g(pe()),g(y())),oi=I(sr),ir=h(Ne,p("webtransport"),g(pe()),g(pe()),g(y())),si=I(ir),Se=L(nr,or,h(tt,g(y())),h(hn,g(y())),h(W,g(y())),sr,ir,y()),ii=I(Se),mn=h(Se,p("p2p-circuit"),y()),ci=I(mn),xn=L(h(Se,p("p2p-circuit"),p("webrtc"),g(y())),h(Se,p("webrtc"),g(y())),h(p("webrtc"),g(y()))),ai=I(xn),gn=L(h(W,p("tcp"),ne(),p("http"),g(y())),h(W,p("http"),g(y()))),li=I(gn),wn=L(h(W,p("tcp"),L(h(p("443"),p("http")),h(ne(),p("https")),h(ne(),p("tls"),p("http"))),g(y())),h(W,p("tls"),p("http"),g(y())),h(W,p("https"),g(y()))),ui=I(wn),bn=L(h(p("memory"),X(),g(y()))),di=I(bn);var Ue=class extends Event{type;detail;constructor(e,t){super(e),this.type=e,this.detail=t}};var Hr=Z(F("net"),1);var Vr=Z(F("node:os"),1);var cr=F("node:buffer");function oe(r){return new Uint8Array(r.buffer,r.byteOffset,r.byteLength)}function Me(r=0){return oe(cr.Buffer.allocUnsafe(r))}var yn=Math.pow(2,7),vn=Math.pow(2,14),En=Math.pow(2,21),nt=Math.pow(2,28),ot=Math.pow(2,35),st=Math.pow(2,42),it=Math.pow(2,49),w=128,D=127;function R(r){if(r<yn)return 1;if(r<vn)return 2;if(r<En)return 3;if(r<nt)return 4;if(r<ot)return 5;if(r<st)return 6;if(r<it)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function In(r,e,t=0){switch(R(r)){case 8:e[t++]=r&255|w,r/=128;case 7:e[t++]=r&255|w,r/=128;case 6:e[t++]=r&255|w,r/=128;case 5:e[t++]=r&255|w,r/=128;case 4:e[t++]=r&255|w,r>>>=7;case 3:e[t++]=r&255|w,r>>>=7;case 2:e[t++]=r&255|w,r>>>=7;case 1:{e[t++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return e}function An(r,e,t=0){switch(R(r)){case 8:e.set(t++,r&255|w),r/=128;case 7:e.set(t++,r&255|w),r/=128;case 6:e.set(t++,r&255|w),r/=128;case 5:e.set(t++,r&255|w),r/=128;case 4:e.set(t++,r&255|w),r>>>=7;case 3:e.set(t++,r&255|w),r>>>=7;case 2:e.set(t++,r&255|w),r>>>=7;case 1:{e.set(t++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return e}function Tn(r,e){let t=r[e],n=0;if(n+=t&D,t<w||(t=r[e+1],n+=(t&D)<<7,t<w)||(t=r[e+2],n+=(t&D)<<14,t<w)||(t=r[e+3],n+=(t&D)<<21,t<w)||(t=r[e+4],n+=(t&D)*nt,t<w)||(t=r[e+5],n+=(t&D)*ot,t<w)||(t=r[e+6],n+=(t&D)*st,t<w)||(t=r[e+7],n+=(t&D)*it,t<w))return n;throw new RangeError("Could not decode varint")}function Cn(r,e){let t=r.get(e),n=0;if(n+=t&D,t<w||(t=r.get(e+1),n+=(t&D)<<7,t<w)||(t=r.get(e+2),n+=(t&D)<<14,t<w)||(t=r.get(e+3),n+=(t&D)<<21,t<w)||(t=r.get(e+4),n+=(t&D)*nt,t<w)||(t=r.get(e+5),n+=(t&D)*ot,t<w)||(t=r.get(e+6),n+=(t&D)*st,t<w)||(t=r.get(e+7),n+=(t&D)*it,t<w))return n;throw new RangeError("Could not decode varint")}function se(r,e,t=0){return e==null&&(e=Me(R(r))),e instanceof Uint8Array?In(r,e,t):An(r,e,t)}function K(r,e=0){return r instanceof Uint8Array?Tn(r,e):Cn(r,e)}var lr=F("node:buffer");function q(r,e){return oe(lr.Buffer.concat(r,e))}var Ir=F("node:buffer");var ct={};k(ct,{base10:()=>Sn});var Sn=Q({prefix:"9",name:"base10",alphabet:"0123456789"});var at={};k(at,{base16:()=>Pn,base16upper:()=>Ln});var Pn=A({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Ln=A({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var lt={};k(lt,{base2:()=>Dn});var Dn=A({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var ut={};k(ut,{base256emoji:()=>$n});var ur=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}"),Nn=ur.reduce((r,e,t)=>(r[t]=e,r),[]),Un=ur.reduce((r,e,t)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return r[n]=t,r},[]);function Mn(r){return r.reduce((e,t)=>(e+=Nn[t],e),"")}function kn(r){let e=[];for(let t of r){let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);let o=Un[n];if(o==null)throw new Error(`Non-base256emoji character: ${t}`);e.push(o)}return new Uint8Array(e)}var $n=te({prefix:"\u{1F680}",name:"base256emoji",encode:Mn,decode:kn});var dt={};k(dt,{base32:()=>G,base32hex:()=>_n,base32hexpad:()=>Bn,base32hexpadupper:()=>Rn,base32hexupper:()=>zn,base32pad:()=>On,base32padupper:()=>Vn,base32upper:()=>Fn,base32z:()=>jn});var G=A({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Fn=A({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),On=A({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Vn=A({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),_n=A({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),zn=A({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Bn=A({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Rn=A({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),jn=A({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var pt={};k(pt,{base36:()=>he,base36upper:()=>Wn});var he=Q({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Wn=Q({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var ft={};k(ft,{base8:()=>qn});var qn=A({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var ht={};k(ht,{identity:()=>Gn});var Gn=te({prefix:"\0",name:"identity",encode:r=>Xt(r),decode:r=>Jt(r)});var Li=new TextEncoder,Di=new TextDecoder;var xt={};k(xt,{identity:()=>xo});var Jn=fr,dr=128,Xn=127,Kn=~Xn,Yn=Math.pow(2,31);function fr(r,e,t){e=e||[],t=t||0;for(var n=t;r>=Yn;)e[t++]=r&255|dr,r/=128;for(;r&Kn;)e[t++]=r&255|dr,r>>>=7;return e[t]=r|0,fr.bytes=t-n+1,e}var Zn=mt,eo=128,pr=127;function mt(r,n){var t=0,n=n||0,o=0,s=n,i,c=r.length;do{if(s>=c)throw mt.bytes=0,new RangeError("Could not decode varint");i=r[s++],t+=o<28?(i&pr)<<o:(i&pr)*Math.pow(2,o),o+=7}while(i>=eo);return mt.bytes=s-n,t}var to=Math.pow(2,7),ro=Math.pow(2,14),no=Math.pow(2,21),oo=Math.pow(2,28),so=Math.pow(2,35),io=Math.pow(2,42),co=Math.pow(2,49),ao=Math.pow(2,56),lo=Math.pow(2,63),uo=function(r){return r<to?1:r<ro?2:r<no?3:r<oo?4:r<so?5:r<io?6:r<co?7:r<ao?8:r<lo?9:10},po={encode:Jn,decode:Zn,encodingLength:uo},fo=po,me=fo;function xe(r,e=0){return[me.decode(r,e),me.decode.bytes]}function ie(r,e,t=0){return me.encode(r,e,t),e}function ce(r){return me.encodingLength(r)}function Y(r,e){let t=e.byteLength,n=ce(r),o=n+ce(t),s=new Uint8Array(o+t);return ie(r,s,0),ie(t,s,n),s.set(e,o),new ae(r,t,e,s)}function $e(r){let e=O(r),[t,n]=xe(e),[o,s]=xe(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new ae(t,o,i,e)}function hr(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&Qt(r.bytes,t.bytes)}}var ae=class{code;size;digest;bytes;constructor(e,t,n,o){this.code=e,this.size=t,this.digest=n,this.bytes=o}};var mr=0,ho="identity",xr=O;function mo(r){return Y(mr,xr(r))}var xo={code:mr,name:ho,encode:xr,digest:mo};var yt={};k(yt,{sha256:()=>go,sha512:()=>wo});var bt=Z(F("crypto"),1);function wt({name:r,code:e,encode:t}){return new gt(r,e,t)}var gt=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?Y(this.code,t):t.then(n=>Y(this.code,n))}else throw Error("Unknown type, must be binary type")}};var go=wt({name:"sha2-256",code:18,encode:r=>O(bt.default.createHash("sha256").update(r).digest())}),wo=wt({name:"sha2-512",code:19,encode:r=>O(bt.default.createHash("sha512").update(r).digest())});function wr(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return yo(t,vt(r),e??P.encoder);default:return vo(t,vt(r),e??G.encoder)}}var br=new WeakMap;function vt(r){let e=br.get(r);if(e==null){let t=new Map;return br.set(r,t),t}return e}var J=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!==ge)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==Eo)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=Y(e,t);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(e){return r.equals(this,e)}static equals(e,t){let n=t;return n!=null&&e.code===n.code&&e.version===n.version&&hr(e.multihash,n.multihash)}toString(e){return wr(this,e)}toJSON(){return{"/":wr(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??yr(n,o,s.bytes))}else if(t[Io]===!0){let{version:n,multihash:o,code:s}=t,i=$e(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!==ge)throw new Error(`Version 0 CID must use dag-pb (code: ${ge}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let o=yr(e,t,n.bytes);return new r(e,t,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,ge,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=O(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 ae(t.multihashCode,t.digestSize,s,o);return[t.version===0?r.createV0(i):r.createV1(t.codec,i),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[f,v]=xe(e.subarray(t));return t+=v,f},o=n(),s=ge;if(o===18?(o=0,t=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=t,c=n(),l=n(),d=t+l,m=d-i;return{version:o,codec:s,multihashCode:c,digestSize:l,multihashSize:m,size:d}}static parse(e,t){let[n,o]=bo(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 vt(s).set(n,e),s}};function bo(r,e){switch(r[0]){case"Q":{let t=e??P;return[P.prefix,t.decode(`${P.prefix}${r}`)]}case P.prefix:{let t=e??P;return[P.prefix,t.decode(r)]}case G.prefix:{let t=e??G;return[G.prefix,t.decode(r)]}case he.prefix:{let t=e??he;return[he.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 yo(r,e,t){let{prefix:n}=t;if(n!==P.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 vo(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 ge=112,Eo=18;function yr(r,e,t){let n=ce(r),o=n+ce(e),s=new Uint8Array(o+t.byteLength);return ie(r,s,0),ie(e,s,n),s.set(t,o),s}var Io=Symbol.for("@ipld/js-cid/CID");var we={...ht,...lt,...ft,...ct,...at,...dt,...pt,...Je,...Ke,...ut},Zi={...yt,...xt};function Er(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var vr=Er("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Et=Er("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=Me(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),Ao={utf8:vr,"utf-8":vr,hex:we.base16,latin1:Et,ascii:Et,binary:Et,...we},Fe=Ao;function U(r,e="utf8"){let t=Fe[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return e==="utf8"||e==="utf-8"?Ir.Buffer.from(r.buffer,r.byteOffset,r.byteLength).toString("utf8"):t.encoder.encode(r).substring(1)}var Oe=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,c=this.peekChar();if(c===void 0)return;let l=c==="0",d=2**(8*o)-1;for(;;){let m=this.readAtomically(()=>{let f=this.readChar();if(f===void 0)return;let v=Number.parseInt(f,e);if(!Number.isNaN(v))return v});if(m===void 0)break;if(s*=e,s+=m,s>d||(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),[c]=e(s.subarray(0,i));return t.set(s.subarray(0,c),16-c),t})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var ac=new Oe;var xc=parseInt("0xFFFF",16),gc=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);var Cr=F("node:buffer");function Ve(r,e="utf8"){let t=Fe[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return e==="utf8"||e==="utf-8"?oe(Cr.Buffer.from(r,"utf-8")):t.decoder.decode(`${t.prefix}${r}`)}var Sr=S.isIPv4,Do=S.isIPv6,It=function(r){let e=0;if(r=r.toString().trim(),Sr(r)){let t=new Uint8Array(e+4);return r.split(/\./g).forEach(n=>{t[e++]=parseInt(n,10)&255}),t}if(Do(r)){let t=r.split(":",8),n;for(n=0;n<t.length;n++){let s=Sr(t[n]),i;s&&(i=It(t[n]),t[n]=U(i.slice(0,2),"base16")),i!=null&&++n<8&&t.splice(n,0,U(i.slice(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++){let s=parseInt(t[n],16);o[e++]=s>>8&255,o[e++]=s&255}return o}throw new Error("invalid ip address")},Pr=function(r,e=0,t){e=~~e,t=t??r.length-e;let n=new DataView(r.buffer);if(t===4){let o=[];for(let s=0;s<t;s++)o.push(r[e+s]);return o.join(".")}if(t===16){let o=[];for(let s=0;s<t;s+=2)o.push(n.getUint16(e+s).toString(16));return o.join(":").replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}return""};var ue={},At={},Uo=[[4,32,"ip4"],[6,16,"tcp"],[33,16,"dccp"],[41,128,"ip6"],[42,-1,"ip6zone"],[43,8,"ipcidr"],[53,-1,"dns",!0],[54,-1,"dns4",!0],[55,-1,"dns6",!0],[56,-1,"dnsaddr",!0],[132,16,"sctp"],[273,16,"udp"],[275,0,"p2p-webrtc-star"],[276,0,"p2p-webrtc-direct"],[277,0,"p2p-stardust"],[280,0,"webrtc-direct"],[281,0,"webrtc"],[290,0,"p2p-circuit"],[301,0,"udt"],[302,0,"utp"],[400,-1,"unix",!1,!0],[421,-1,"ipfs"],[421,-1,"p2p"],[443,0,"https"],[444,96,"onion"],[445,296,"onion3"],[446,-1,"garlic64"],[448,0,"tls"],[449,-1,"sni"],[460,0,"quic"],[461,0,"quic-v1"],[465,0,"webtransport"],[466,-1,"certhash"],[477,0,"ws"],[478,0,"wss"],[479,0,"p2p-websocket-star"],[480,0,"http"],[481,-1,"http-path"],[777,-1,"memory"]];Uo.forEach(r=>{let e=Mo(...r);At[e.code]=e,ue[e.name]=e});function Mo(r,e,t,n,o){return{code:r,size:e,name:t,resolvable:!!n,path:!!o}}function E(r){if(typeof r=="number"){if(At[r]!=null)return At[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(ue[r]!=null)return ue[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var na=E("ip4"),oa=E("ip6"),sa=E("ipcidr");function Pt(r,e){switch(E(r).code){case 4:case 41:return $o(e);case 42:return St(e);case 43:return U(e,"base10");case 6:case 273:case 33:case 132:return Nr(e).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return St(e);case 421:return _o(e);case 444:return Dr(e);case 445:return Dr(e);case 466:return Vo(e);case 481:return globalThis.encodeURIComponent(St(e));default:return U(e,"base16")}}function Lt(r,e){switch(E(r).code){case 4:return Lr(e);case 41:return Lr(e);case 42:return Ct(e);case 43:return Ve(e,"base10");case 6:case 273:case 33:case 132:return Dt(parseInt(e,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return Ct(e);case 421:return Fo(e);case 444:return zo(e);case 445:return Bo(e);case 466:return Oo(e);case 481:return Ct(globalThis.decodeURIComponent(e));default:return Ve(e,"base16")}}var Tt=Object.values(we).map(r=>r.decoder),ko=function(){let r=Tt[0].or(Tt[1]);return Tt.slice(2).forEach(e=>r=r.or(e)),r}();function Lr(r){if(!Ce(r))throw new Error("invalid ip address");return It(r)}function $o(r){let e=Pr(r,0,r.length);if(e==null)throw new Error("ipBuff is required");if(!Ce(e))throw new Error("invalid ip address");return e}function Dt(r){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,r),new Uint8Array(e)}function Nr(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function Ct(r){let e=Ve(r),t=Uint8Array.from(se(e.length));return q([t,e],t.length+e.length)}function St(r){let e=K(r);if(r=r.slice(R(e)),r.length!==e)throw new Error("inconsistent lengths");return U(r)}function Fo(r){let e;r[0]==="Q"||r[0]==="1"?e=$e(P.decode(`z${r}`)).bytes:e=J.parse(r).multihash.bytes;let t=Uint8Array.from(se(e.length));return q([t,e],t.length+e.length)}function Oo(r){let e=ko.decode(r),t=Uint8Array.from(se(e.length));return q([t,e],t.length+e.length)}function Vo(r){let e=K(r),t=r.slice(R(e));if(t.length!==e)throw new Error("inconsistent lengths");return"u"+U(t,"base64url")}function _o(r){let e=K(r),t=r.slice(R(e));if(t.length!==e)throw new Error("inconsistent lengths");return U(t,"base58btc")}function zo(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=G.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=Dt(n);return q([t,o],t.length+o.length)}function Bo(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=G.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=Dt(n);return q([t,o],t.length+o.length)}function Dr(r){let e=r.slice(0,r.length-2),t=r.slice(r.length-2),n=U(e,"base32"),o=Nr(t);return`${n}:${o}`}function Ur(r){r=Nt(r);let e=[],t=[],n=null,o=r.split("/").slice(1);if(o.length===1&&o[0]==="")return{bytes:new Uint8Array,string:"/",tuples:[],stringTuples:[],path:null};for(let s=0;s<o.length;s++){let i=o[s],c=E(i);if(c.size===0){e.push([c.code]),t.push([c.code]);continue}if(s++,s>=o.length)throw new _e("invalid address: "+r);if(c.path===!0){n=Nt(o.slice(s).join("/")),e.push([c.code,Lt(c.code,n)]),t.push([c.code,n]);break}let l=Lt(c.code,o[s]);e.push([c.code,l]),t.push([c.code,Pt(c.code,l)])}return{string:Mr(t),bytes:ze(e),tuples:e,stringTuples:t,path:n}}function Ut(r){let e=[],t=[],n=null,o=0;for(;o<r.length;){let s=K(r,o),i=R(s),c=E(s),l=Ro(c,r.slice(o+i));if(l===0){e.push([s]),t.push([s]),o+=i;continue}let d=r.slice(o+i,o+i+l);if(o+=l+i,o>r.length)throw new _e("Invalid address Uint8Array: "+U(r,"base16"));e.push([s,d]);let m=Pt(s,d);if(t.push([s,m]),c.path===!0){n=m;break}}return{bytes:Uint8Array.from(r),string:Mr(t),tuples:e,stringTuples:t,path:n}}function Mr(r){let e=[];return r.map(t=>{let n=E(t[0]);return e.push(n.name),t.length>1&&t[1]!=null&&e.push(t[1]),null}),Nt(e.join("/"))}function ze(r){return q(r.map(e=>{let t=E(e[0]),n=Uint8Array.from(se(t.code));return e.length>1&&e[1]!=null&&(n=q([n,e[1]])),n}))}function Ro(r,e){if(r.size>0)return r.size/8;if(r.size===0)return 0;{let t=K(e instanceof Uint8Array?e:Uint8Array.from(e));return t+R(t)}}function Nt(r){return"/"+r.trim().split("/").filter(e=>e).join("/")}var _e=class extends Error{static name="ParseError";name="ParseError";constructor(e){super(`Error parsing address: ${e}`)}};function kr(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}var jo=Symbol.for("nodejs.util.inspect.custom"),kt=Symbol.for("@multiformats/js-multiaddr/multiaddr"),Wo=[E("dns").code,E("dns4").code,E("dns6").code,E("dnsaddr").code],Mt=class extends Error{constructor(e="No available resolver"){super(e),this.name="NoAvailableResolverError"}},Be=class r{bytes;#e;#t;#r;#n;[kt]=!0;constructor(e){e==null&&(e="");let t;if(e instanceof Uint8Array)t=Ut(e);else if(typeof e=="string"){if(e.length>0&&e.charAt(0)!=="/")throw new Error(`multiaddr "${e}" must start with a "/"`);t=Ur(e)}else if(Fr(e))t=Ut(e.bytes);else throw new Error("addr must be a string, Buffer, or another Multiaddr");this.bytes=t.bytes,this.#e=t.string,this.#t=t.tuples,this.#r=t.stringTuples,this.#n=t.path}toString(){return this.#e}toJSON(){return this.toString()}toOptions(){let e,t,n,o,s="",i=E("tcp"),c=E("udp"),l=E("ip4"),d=E("ip6"),m=E("dns6"),f=E("ip6zone");for(let[a,u]of this.stringTuples())a===f.code&&(s=`%${u??""}`),Wo.includes(a)&&(t=i.name==="tcp"?"tcp":"udp",o=443,n=`${u??""}${s}`,e=a===m.code?6:4),(a===i.code||a===c.code)&&(t=E(a).name==="tcp"?"tcp":"udp",o=parseInt(u??"")),(a===l.code||a===d.code)&&(t=E(a).name==="tcp"?"tcp":"udp",n=`${u??""}${s}`,e=a===d.code?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}}protos(){return this.#t.map(([e])=>Object.assign({},E(e)))}protoCodes(){return this.#t.map(([e])=>e)}protoNames(){return this.#t.map(([e])=>E(e).name)}tuples(){return this.#t.map(([e,t])=>t==null?[e]:[e,t])}stringTuples(){return this.#r.map(([e,t])=>t==null?[e]:[e,t])}encapsulate(e){return e=new r(e),new r(this.toString()+e.toString())}decapsulate(e){let t=e.toString(),n=this.toString(),o=n.lastIndexOf(t);if(o<0)throw new Error(`Address ${this.toString()} does not contain subaddress: ${e.toString()}`);return new r(n.slice(0,o))}decapsulateCode(e){let t=this.tuples();for(let n=t.length-1;n>=0;n--)if(t[n][0]===e)return new r(ze(t.slice(0,n)));return this}getPeerId(){try{let e=[];this.stringTuples().forEach(([n,o])=>{n===ue.p2p.code&&e.push([n,o]),n===ue["p2p-circuit"].code&&(e=[])});let t=e.pop();if(t?.[1]!=null){let n=t[1];return n[0]==="Q"||n[0]==="1"?U(P.decode(`z${n}`),"base58btc"):U(J.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){return this.#n}equals(e){return kr(this.bytes,e.bytes)}async resolve(e){let t=this.protos().find(s=>s.resolvable);if(t==null)return[this];let n=$r.get(t.name);if(n==null)throw new Mt(`no available resolver for ${t.name}`);return(await n(this,e)).map(s=>_(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(e){let t=(e??this).protos();return!(t.length!==2||t[0].code!==4&&t[0].code!==41||t[1].code!==6&&t[1].code!==273)}[jo](){return`Multiaddr(${this.#e})`}};var $r=new Map;function Fr(r){return!!r?.[kt]}function _(r){return new Be(r)}function Or(r){return!!(r.startsWith("169.254.")||r.toLowerCase().startsWith("fe80"))}var qo={4:"IPv4",6:"IPv6"};function Go(r){return["0.0.0.0","::"].includes(r)}function Ho(r){let e=[],t=Vr.default.networkInterfaces();for(let[,n]of Object.entries(t))if(n!=null)for(let o of n)Or(o.address)||o.family===qo[r]&&e.push(o.address);return e}function _r(r,e){if(r==null)return[];let t=r.toOptions();if(Go(t.host)){let n=[];for(let o of Ho(t.family))n.push(_(`/ip${t.family}/${o}/${t.transport}/${e??t.port}`));return n}return[_(`/ip${t.family}/${t.host}/${t.transport}/${e??t.port}`)]}var $t=class extends Error{constructor(e){super(e),this.name="TimeoutError"}},Ft=class extends Error{constructor(e){super(),this.name="AbortError",this.message=e}},zr=r=>globalThis.DOMException===void 0?new Ft(r):new DOMException(r),Br=r=>{let e=r.reason===void 0?zr("This operation was aborted."):r.reason;return e instanceof Error?e:zr(e)};function Ot(r,e){let{milliseconds:t,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout}}=e,i,c,d=new Promise((m,f)=>{if(typeof t!="number"||Math.sign(t)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${t}\``);if(e.signal){let{signal:a}=e;a.aborted&&f(Br(a)),c=()=>{f(Br(a))},a.addEventListener("abort",c,{once:!0})}if(t===Number.POSITIVE_INFINITY){r.then(m,f);return}let v=new $t;i=s.setTimeout.call(void 0,()=>{if(n){try{m(n())}catch(a){f(a)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?m():o instanceof Error?f(o):(v.message=o??`Promise timed out after ${t} milliseconds`,f(v))},t),(async()=>{try{m(await r)}catch(a){f(a)}})()}).finally(()=>{d.clear(),c&&e.signal&&e.signal.removeEventListener("abort",c)});return d.clear=()=>{s.clearTimeout.call(void 0,i),i=void 0},d}var Qo=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 Jo(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 c=[e].flat(),l=[],{addListener:d,removeListener:m}=Qo(r),f=(...a)=>{let u=t.multiArgs?a:a[0];t.filter&&!t.filter(u)||(l.push(u),t.count===l.length&&(n(),s(l)))},v=a=>{n(),i(a)};n=()=>{for(let a of c)m(a,f);for(let a of t.rejectionEvents)m(a,v)};for(let a of c)d(a,f);for(let a of t.rejectionEvents)d(a,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=Ot(o,{milliseconds:t.timeout});return s.cancel=n,s}return o}function Vt(r,e,t){typeof t=="function"&&(t={filter:t}),t={...t,count:1,resolveImmediately:!1};let n=Jo(r,e,t),o=n.then(s=>s[0]);return o.cancel=n.cancel,o}function Rr(r,e){if(typeof r!="string")throw new B(`invalid ip provided: ${r}`);if(typeof e=="string"&&(e=parseInt(e)),isNaN(e))throw new B(`invalid port provided: ${e}`);if((0,S.isIPv4)(r))return _(`/ip4/${r}/tcp/${e}`);if((0,S.isIPv6)(r))return _(`/ip6/${r}/tcp/${e}`);throw new B(`invalid ip:port for creating a multiaddr: ${r}:${e}`)}function _t(){let r={};return r.promise=new Promise((e,t)=>{r.resolve=e,r.reject=t}),r}var zt=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 Bt(r,e,t,n){let o=new zt(n?.errorMessage,n?.errorCode);return t?.aborted===!0?Promise.reject(o):new Promise((s,i)=>{function c(){t?.removeEventListener("abort",m),r.removeEventListener(e,l),n?.errorEvent!=null&&r.removeEventListener(n.errorEvent,d)}let l=f=>{try{if(n?.filter?.(f)===!1)return}catch(v){c(),i(v);return}c(),s(f)},d=f=>{c(),i(f.detail)},m=()=>{c(),i(o)};t?.addEventListener("abort",m),r.addEventListener(e,l),n?.errorEvent!=null&&r.addEventListener(n.errorEvent,d)})}function jr(r){if(Ko(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(Xo(r))return r;throw new Error("unknown stream")}function Xo(r){return r[Symbol.asyncIterator]!=null}function Ko(r){return typeof r?.getReader=="function"}function Wr(r){return async e=>{let t=async()=>{Yo(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,c=!1,l=()=>{c=!0,i?.()},d,m=!1,f=()=>{m=!0,d?.()},v,a=()=>{v?.()},u=async()=>new Promise((x,b)=>{i=v=x,o=b,r.once("drain",a)}),T=async()=>(await t(),new Promise((x,b)=>{if(c||m||n!=null){x();return}d=i=x,o=b})),N=()=>{r.removeListener("error",s),r.removeListener("close",l),r.removeListener("finish",f),r.removeListener("drain",a)};r.once("error",s),r.once("close",l),r.once("finish",f);try{for await(let x of e){if(!r.writable||r.destroyed||n!=null)break;r.write(x)||await u()}}catch(x){n==null&&r.destroy(x),n=x}try{if(r.writable&&r.end(),await T(),n!=null)throw n}finally{N()}}}function Yo(r){return r.return!=null}function Rt(r){return{sink:Wr(r),source:jr(r)}}var qr=Z(F("os"),1),Gr=Z(F("path"),1);function de(r,e={}){let t=r.getPath();if(t!=null)return qr.default.platform()==="win32"?{path:Gr.default.join("\\\\.\\pipe\\",t)}:{path:t};let n=r.toOptions();return{...e,...n,ipv6Only:n.family===6}}var Re=(r,e)=>{let t,n=e.logger.forComponent("libp2p:tcp:socket"),o=e.direction,s=e.metrics,i=e.metricPrefix??"",c=e.socketInactivityTimeout??12e4,l=e.socketCloseTimeout??500,d=!1,m=!1;e.listeningAddr?.getPath()!=null&&(e.remoteAddr=e.listeningAddr),e.remoteAddr?.getPath()!=null&&(e.localAddr=e.remoteAddr),r.on("error",x=>{m=!0,d||(n.error("%s socket error - %e",o,x),s?.increment({[`${i}error`]:!0})),r.destroy(),N.timeline.close=Date.now()});let f;if(e.remoteAddr!=null)f=e.remoteAddr;else{if(r.remoteAddress==null||r.remotePort==null)throw new B("Could not determine remote address or port");f=Rr(r.remoteAddress,r.remotePort)}let v=de(f),a=v.path??`${v.host??""}:${v.port??""}`,{sink:u,source:T}=Rt(r);r.setTimeout(c),r.once("timeout",()=>{d=!0,n("%s %s socket read timeout",o,a),s?.increment({[`${i}timeout`]:!0}),r.destroy(new ee),N.timeline.close=Date.now()}),r.once("close",()=>{!d&&!m&&(n("%s %s socket close",o,a),s?.increment({[`${i}close`]:!0})),r.destroy(),N.timeline.close=Date.now()}),r.once("end",()=>{n("%s %s socket end",o,a),s?.increment({[`${i}end`]:!0})});let N={async sink(x){try{await u(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,a,b)}r.end()},source:T,remoteAddr:f,timeline:{open:Date.now()},async close(x={}){if(r.closed){n("the %s %s socket is already closed",o,a);return}if(r.destroyed){n("the %s %s socket is already destroyed",o,a);return}if(t!=null)return t.promise;try{t=_t(),r.end();let b=Zo(r),M=x.signal??AbortSignal.timeout(l);r.writableLength>0&&(n("%s %s draining socket",o,a),await Bt(b,"drain",M,{errorEvent:"error"}),n("%s %s socket drained",o,a)),await Promise.all([Bt(b,"close",M,{errorEvent:"error"}),r.destroy()])}catch(b){this.abort(b)}finally{t.resolve()}},abort:x=>{n("%s %s socket abort due to error - %e",o,a,x),r.destroy(),N.timeline.close=Date.now()},log:n};return N};function Zo(r){return{addEventListener:(t,n)=>{r.addListener(t,n)},removeEventListener:(t,n)=>{r.removeListener(t,n)}}}var C;(function(r){r[r.INACTIVE=0]="INACTIVE",r[r.ACTIVE=1]="ACTIVE",r[r.PAUSED=2]="PAUSED"})(C||(C={}));var je=class extends Te{context;server;sockets=new Set;status={code:C.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,Ae(1/0,this.shutdownController.signal),this.log=e.logger.forComponent("libp2p:tcp:listener"),this.addr="unknown",this.server=Hr.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 B("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]:C.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!==C.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!==C.ACTIVE)throw e.destroy(),new Ee("Server is not listening yet");let t;try{t=Re(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===C.INACTIVE)return[];let e=this.server.address();return e==null?[]:typeof e=="string"?[_(`/unix/${e}`)]:_r(this.status.listeningAddr,e.port)}updateAnnounceAddrs(){}async listen(e){if(this.status.code===C.ACTIVE||this.status.code===C.PAUSED)throw new Ie("server is already listening");try{this.status={code:C.ACTIVE,listeningAddr:e,netConfig:de(e,this.context)},await this.resume()}catch(t){throw this.status={code:C.INACTIVE},t}}async close(){let e=[];this.server.listening&&e.push(Vt(this.server,"close")),this.pause(!0),this.shutdownController.abort(),this.sockets.forEach(t=>{t.readable&&(e.push(Vt(t,"close")),t.destroy())}),await Promise.all(e)}async resume(){if(this.server.listening||this.status.code===C.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:C.ACTIVE},this.log("listening on %s",this.server.address())}pause(e=!1){if(!this.server.listening&&this.status.code===C.PAUSED&&e){this.status={code:C.INACTIVE};return}!this.server.listening||this.status.code!==C.ACTIVE||(this.log("closing server on %s",this.server.address()),this.status=e?{code:C.INACTIVE}:{...this.status,code:C.PAUSED},this.server.close())}};var We=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"})})}[qt]=!0;[Symbol.toStringTag]="@libp2p/tcp";[Ht]=["@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=Re(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 Ue("tcp:open-connection"));let n;return new Promise((o,s)=>{let i=Date.now(),c=de(e,{...this.opts.dialOpts??{},...t});this.log("dialing %a",e),n=Qr.default.connect(c);let l=a=>{this.log.error("dial to %a errored - %e",e,a);let u=c.path??`${c.host??""}:${c.port}`;a.message=`connection error ${u}: ${a.message}`,this.metrics?.events.increment({error:!0}),v(a)},d=()=>{this.log("connection timeout %a",e),this.metrics?.events.increment({timeout:!0});let a=new ee(`Connection timeout after ${Date.now()-i}ms`);n.emit("error",a)},m=()=>{this.log("connection opened %a",e),this.metrics?.events.increment({connect:!0}),v()},f=()=>{this.log("connection aborted %a",e),this.metrics?.events.increment({abort:!0}),v(new ve)},v=a=>{if(n.removeListener("error",l),n.removeListener("timeout",d),n.removeListener("connect",m),t.signal!=null&&t.signal.removeEventListener("abort",f),a!=null){s(a);return}o(n)};n.on("error",l),n.on("timeout",d),n.on("connect",m),t.signal.addEventListener("abort",f)}).catch(o=>{throw n?.destroy(),o})}createListener(e){return new je({...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=>rr.exactMatch(t)||t.toString().startsWith("/unix/"))}dialFilter(e){return this.listenFilter(e)}};function es(r={}){return e=>new We(e,r)}return en(ts);})();
"use strict";var Libp2PTcp=(()=>{var Jr=Object.create;var ye=Object.defineProperty;var Xr=Object.getOwnPropertyDescriptor;var Kr=Object.getOwnPropertyNames;var Yr=Object.getPrototypeOf,Zr=Object.prototype.hasOwnProperty;var F=(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 k=(r,e)=>{for(var t in e)ye(r,t,{get:e[t],enumerable:!0})},jt=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Kr(e))!Zr.call(r,o)&&o!==t&&ye(r,o,{get:()=>e[o],enumerable:!(n=Xr(e,o))||n.enumerable});return r};var Z=(r,e,t)=>(t=r!=null?Jr(Yr(r)):{},jt(e||!r||!r.__esModule?ye(t,"default",{value:r,enumerable:!0}):t,r)),en=r=>jt(ye({},"__esModule",{value:!0}),r);var ts={};k(ts,{tcp:()=>es});var Qr=Z(F("net"),1);var qt=Symbol.for("@libp2p/transport");var Wt;(function(r){r[r.FATAL_ALL=0]="FATAL_ALL",r[r.NO_FATAL=1]="NO_FATAL"})(Wt||(Wt={}));var ve=class extends Error{static name="AbortError";constructor(e="The operation was aborted"){super(e),this.name="AbortError"}};var B=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}};var ee=class extends Error{static name="TimeoutError";constructor(e="Timed out"){super(e),this.name="TimeoutError"}},Ee=class extends Error{static name="NotStartedError";constructor(e="Not started"){super(e),this.name="NotStartedError"}},Ie=class extends Error{static name="AlreadyStartedError";constructor(e="Already started"){super(e),this.name="AlreadyStartedError"}};var Gt=F("node:events"),Ae=(r,...e)=>{try{(0,Gt.setMaxListeners)(r,...e)}catch{}};var Te=class extends EventTarget{#e=new Map;constructor(){super(),Ae(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 Ht=Symbol.for("@libp2p/service-capabilities"),as=Symbol.for("@libp2p/service-dependencies");var S=F("node:net");function Ce(r){return!!(0,S.isIP)(r)}var Je={};k(Je,{base58btc:()=>P,base58flickr:()=>an});var Ns=new Uint8Array(0);function Qt(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 O(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 Jt(r){return new TextEncoder().encode(r)}function Xt(r){return new TextDecoder().decode(r)}function tn(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 c=r.length,l=r.charAt(0),d=Math.log(c)/Math.log(256),m=Math.log(256)/Math.log(c);function f(u){if(u instanceof Uint8Array||(ArrayBuffer.isView(u)?u=new Uint8Array(u.buffer,u.byteOffset,u.byteLength):Array.isArray(u)&&(u=Uint8Array.from(u))),!(u instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(u.length===0)return"";for(var T=0,N=0,x=0,b=u.length;x!==b&&u[x]===0;)x++,T++;for(var M=(b-x)*m+1>>>0,$=new Uint8Array(M);x!==b;){for(var z=u[x],H=0,V=M-1;(z!==0||H<N)&&V!==-1;V--,H++)z+=256*$[V]>>>0,$[V]=z%c>>>0,z=z/c>>>0;if(z!==0)throw new Error("Non-zero carry");N=H,x++}for(var j=M-N;j!==M&&$[j]===0;)j++;for(var be=l.repeat(T);j<M;++j)be+=r.charAt($[j]);return be}function v(u){if(typeof u!="string")throw new TypeError("Expected String");if(u.length===0)return new Uint8Array;var T=0;if(u[T]!==" "){for(var N=0,x=0;u[T]===l;)N++,T++;for(var b=(u.length-T)*d+1>>>0,M=new Uint8Array(b);u[T];){var $=t[u.charCodeAt(T)];if($===255)return;for(var z=0,H=b-1;($!==0||z<x)&&H!==-1;H--,z++)$+=c*M[H]>>>0,M[H]=$%256>>>0,$=$/256>>>0;if($!==0)throw new Error("Non-zero carry");x=z,T++}if(u[T]!==" "){for(var V=b-x;V!==b&&M[V]===0;)V++;for(var j=new Uint8Array(N+(b-V)),be=N;V!==b;)j[be++]=M[V++];return j}}}function a(u){var T=v(u);if(T)return T;throw new Error(`Non-${e} character`)}return{encode:f,decodeUnsafe:v,decode:a}}var rn=tn,nn=rn,Yt=nn;var qe=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")}},Ge=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 Zt(this,e)}},He=class{decoders;constructor(e){this.decoders=e}or(e){return Zt(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 Zt(r,e){return new He({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var Qe=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 qe(e,t,n),this.decoder=new Ge(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function te({name:r,prefix:e,encode:t,decode:n}){return new Qe(r,e,t,n)}function Q({name:r,prefix:e,alphabet:t}){let{encode:n,decode:o}=Yt(t,r);return te({prefix:e,name:r,encode:n,decode:s=>O(o(s))})}function on(r,e,t,n){let o=r.length;for(;r[o-1]==="=";)--o;let s=new Uint8Array(o*t/8|0),i=0,c=0,l=0;for(let d=0;d<o;++d){let m=e[r[d]];if(m===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<t|m,i+=t,i>=8&&(i-=8,s[l++]=255&c>>i)}if(i>=t||(255&c<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function sn(r,e,t){let n=e[e.length-1]==="=",o=(1<<t)-1,s="",i=0,c=0;for(let l=0;l<r.length;++l)for(c=c<<8|r[l],i+=8;i>t;)i-=t,s+=e[o&c>>i];if(i!==0&&(s+=e[o&c<<t-i]),n)for(;(s.length*t&7)!==0;)s+="=";return s}function cn(r){let e={};for(let t=0;t<r.length;++t)e[r[t]]=t;return e}function A({name:r,prefix:e,bitsPerChar:t,alphabet:n}){let o=cn(n);return te({prefix:e,name:r,encode(s){return sn(s,n,t)},decode(s){return on(s,o,t,r)}})}var P=Q({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),an=Q({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Ke={};k(Ke,{base64:()=>ln,base64pad:()=>un,base64url:()=>Xe,base64urlpad:()=>dn});var ln=A({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),un=A({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Xe=A({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),dn=A({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var pn=r=>r.toString().split("/").slice(1),re=r=>({match:e=>e.length<1?!1:r(e[0])?e.slice(1):!1,pattern:"fn"}),p=r=>({match:e=>re(t=>t===r).match(e),pattern:r}),X=()=>({match:r=>re(e=>typeof e=="string").match(r),pattern:"{string}"}),ne=()=>({match:r=>re(e=>!isNaN(parseInt(e))).match(r),pattern:"{number}"}),y=()=>({match:r=>{if(r.length<2||r[0]!=="p2p"&&r[0]!=="ipfs")return!1;if(r[1].startsWith("Q")||r[1].startsWith("1"))try{P.decode(`z${r[1]}`)}catch{return!1}else return!1;return r.slice(2)},pattern:"/p2p/{peerid}"}),pe=()=>({match:r=>{if(r.length<2||r[0]!=="certhash")return!1;try{Xe.decode(r[1])}catch{return!1}return r.slice(2)},pattern:"/certhash/{certhash}"}),g=r=>({match:e=>{let t=r.match(e);return t===!1?e:t},pattern:`optional(${r.pattern})`}),L=(...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},pattern:`or(${r.map(e=>e.pattern).join(", ")})`}),h=(...r)=>({match:e=>{for(let t of r){let n=t.match(e);if(n===!1)return!1;e=n}return e},pattern:`and(${r.map(e=>e.pattern).join(", ")})`});function I(...r){function e(o){let s=pn(o);for(let i of r){let c=i.match(s);if(c===!1)return!1;s=c}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 fn=y(),js=I(fn),Pe=h(p("dns4"),X()),Le=h(p("dns6"),X()),De=h(p("dnsaddr"),X()),Ze=h(p("dns"),X()),Ws=I(Pe,g(y())),qs=I(Le,g(y())),Gs=I(De,g(y())),Hs=I(L(Ze,De,Pe,Le),g(y())),er=h(p("ip4"),re(S.isIPv4)),tr=h(p("ip6"),re(S.isIPv6)),et=L(er,tr),W=L(et,Ze,Pe,Le,De),Qs=I(L(et,h(L(Ze,De,Pe,Le),g(y())))),Js=I(er),Xs=I(tr),Ks=I(et),tt=h(W,p("tcp"),ne()),fe=h(W,p("udp"),ne()),rr=I(h(tt,g(y()))),Ys=I(fe),rt=h(fe,p("quic"),g(y())),Ne=h(fe,p("quic-v1"),g(y())),hn=L(rt,Ne),Zs=I(rt),ei=I(Ne),Ye=L(W,tt,fe,rt,Ne),nr=L(h(Ye,p("ws"),g(y()))),ti=I(nr),or=L(h(Ye,p("wss"),g(y())),h(Ye,p("tls"),g(h(p("sni"),X())),p("ws"),g(y()))),ri=I(or),sr=h(fe,p("webrtc-direct"),g(pe()),g(pe()),g(y())),ni=I(sr),ir=h(Ne,p("webtransport"),g(pe()),g(pe()),g(y())),oi=I(ir),Se=L(nr,or,h(tt,g(y())),h(hn,g(y())),h(W,g(y())),sr,ir,y()),si=I(Se),mn=h(Se,p("p2p-circuit"),y()),ii=I(mn),xn=L(h(Se,p("p2p-circuit"),p("webrtc"),g(y())),h(Se,p("webrtc"),g(y())),h(p("webrtc"),g(y()))),ci=I(xn),gn=L(h(W,p("tcp"),ne(),p("http"),g(y())),h(W,p("http"),g(y()))),ai=I(gn),wn=L(h(W,p("tcp"),L(h(p("443"),p("http")),h(ne(),p("https")),h(ne(),p("tls"),p("http"))),g(y())),h(W,p("tls"),p("http"),g(y())),h(W,p("https"),g(y()))),li=I(wn),bn=L(h(p("memory"),X(),g(y()))),ui=I(bn);var Ue=class extends Event{type;detail;constructor(e,t){super(e),this.type=e,this.detail=t}};var Hr=Z(F("net"),1);var Vr=Z(F("node:os"),1);var cr=F("node:buffer");function oe(r){return new Uint8Array(r.buffer,r.byteOffset,r.byteLength)}function Me(r=0){return oe(cr.Buffer.allocUnsafe(r))}var yn=Math.pow(2,7),vn=Math.pow(2,14),En=Math.pow(2,21),nt=Math.pow(2,28),ot=Math.pow(2,35),st=Math.pow(2,42),it=Math.pow(2,49),w=128,D=127;function R(r){if(r<yn)return 1;if(r<vn)return 2;if(r<En)return 3;if(r<nt)return 4;if(r<ot)return 5;if(r<st)return 6;if(r<it)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function In(r,e,t=0){switch(R(r)){case 8:e[t++]=r&255|w,r/=128;case 7:e[t++]=r&255|w,r/=128;case 6:e[t++]=r&255|w,r/=128;case 5:e[t++]=r&255|w,r/=128;case 4:e[t++]=r&255|w,r>>>=7;case 3:e[t++]=r&255|w,r>>>=7;case 2:e[t++]=r&255|w,r>>>=7;case 1:{e[t++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return e}function An(r,e,t=0){switch(R(r)){case 8:e.set(t++,r&255|w),r/=128;case 7:e.set(t++,r&255|w),r/=128;case 6:e.set(t++,r&255|w),r/=128;case 5:e.set(t++,r&255|w),r/=128;case 4:e.set(t++,r&255|w),r>>>=7;case 3:e.set(t++,r&255|w),r>>>=7;case 2:e.set(t++,r&255|w),r>>>=7;case 1:{e.set(t++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return e}function Tn(r,e){let t=r[e],n=0;if(n+=t&D,t<w||(t=r[e+1],n+=(t&D)<<7,t<w)||(t=r[e+2],n+=(t&D)<<14,t<w)||(t=r[e+3],n+=(t&D)<<21,t<w)||(t=r[e+4],n+=(t&D)*nt,t<w)||(t=r[e+5],n+=(t&D)*ot,t<w)||(t=r[e+6],n+=(t&D)*st,t<w)||(t=r[e+7],n+=(t&D)*it,t<w))return n;throw new RangeError("Could not decode varint")}function Cn(r,e){let t=r.get(e),n=0;if(n+=t&D,t<w||(t=r.get(e+1),n+=(t&D)<<7,t<w)||(t=r.get(e+2),n+=(t&D)<<14,t<w)||(t=r.get(e+3),n+=(t&D)<<21,t<w)||(t=r.get(e+4),n+=(t&D)*nt,t<w)||(t=r.get(e+5),n+=(t&D)*ot,t<w)||(t=r.get(e+6),n+=(t&D)*st,t<w)||(t=r.get(e+7),n+=(t&D)*it,t<w))return n;throw new RangeError("Could not decode varint")}function se(r,e,t=0){return e==null&&(e=Me(R(r))),e instanceof Uint8Array?In(r,e,t):An(r,e,t)}function K(r,e=0){return r instanceof Uint8Array?Tn(r,e):Cn(r,e)}var lr=F("node:buffer");function q(r,e){return oe(lr.Buffer.concat(r,e))}var Ir=F("node:buffer");var ct={};k(ct,{base10:()=>Sn});var Sn=Q({prefix:"9",name:"base10",alphabet:"0123456789"});var at={};k(at,{base16:()=>Pn,base16upper:()=>Ln});var Pn=A({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Ln=A({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var lt={};k(lt,{base2:()=>Dn});var Dn=A({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var ut={};k(ut,{base256emoji:()=>$n});var ur=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}"),Nn=ur.reduce((r,e,t)=>(r[t]=e,r),[]),Un=ur.reduce((r,e,t)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return r[n]=t,r},[]);function Mn(r){return r.reduce((e,t)=>(e+=Nn[t],e),"")}function kn(r){let e=[];for(let t of r){let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);let o=Un[n];if(o==null)throw new Error(`Non-base256emoji character: ${t}`);e.push(o)}return new Uint8Array(e)}var $n=te({prefix:"\u{1F680}",name:"base256emoji",encode:Mn,decode:kn});var dt={};k(dt,{base32:()=>G,base32hex:()=>_n,base32hexpad:()=>Bn,base32hexpadupper:()=>Rn,base32hexupper:()=>zn,base32pad:()=>On,base32padupper:()=>Vn,base32upper:()=>Fn,base32z:()=>jn});var G=A({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Fn=A({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),On=A({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Vn=A({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),_n=A({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),zn=A({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Bn=A({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Rn=A({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),jn=A({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var pt={};k(pt,{base36:()=>he,base36upper:()=>Wn});var he=Q({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Wn=Q({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var ft={};k(ft,{base8:()=>qn});var qn=A({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var ht={};k(ht,{identity:()=>Gn});var Gn=te({prefix:"\0",name:"identity",encode:r=>Xt(r),decode:r=>Jt(r)});var Pi=new TextEncoder,Li=new TextDecoder;var xt={};k(xt,{identity:()=>xo});var Jn=fr,dr=128,Xn=127,Kn=~Xn,Yn=Math.pow(2,31);function fr(r,e,t){e=e||[],t=t||0;for(var n=t;r>=Yn;)e[t++]=r&255|dr,r/=128;for(;r&Kn;)e[t++]=r&255|dr,r>>>=7;return e[t]=r|0,fr.bytes=t-n+1,e}var Zn=mt,eo=128,pr=127;function mt(r,n){var t=0,n=n||0,o=0,s=n,i,c=r.length;do{if(s>=c)throw mt.bytes=0,new RangeError("Could not decode varint");i=r[s++],t+=o<28?(i&pr)<<o:(i&pr)*Math.pow(2,o),o+=7}while(i>=eo);return mt.bytes=s-n,t}var to=Math.pow(2,7),ro=Math.pow(2,14),no=Math.pow(2,21),oo=Math.pow(2,28),so=Math.pow(2,35),io=Math.pow(2,42),co=Math.pow(2,49),ao=Math.pow(2,56),lo=Math.pow(2,63),uo=function(r){return r<to?1:r<ro?2:r<no?3:r<oo?4:r<so?5:r<io?6:r<co?7:r<ao?8:r<lo?9:10},po={encode:Jn,decode:Zn,encodingLength:uo},fo=po,me=fo;function xe(r,e=0){return[me.decode(r,e),me.decode.bytes]}function ie(r,e,t=0){return me.encode(r,e,t),e}function ce(r){return me.encodingLength(r)}function Y(r,e){let t=e.byteLength,n=ce(r),o=n+ce(t),s=new Uint8Array(o+t);return ie(r,s,0),ie(t,s,n),s.set(e,o),new ae(r,t,e,s)}function $e(r){let e=O(r),[t,n]=xe(e),[o,s]=xe(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new ae(t,o,i,e)}function hr(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&Qt(r.bytes,t.bytes)}}var ae=class{code;size;digest;bytes;constructor(e,t,n,o){this.code=e,this.size=t,this.digest=n,this.bytes=o}};var mr=0,ho="identity",xr=O;function mo(r){return Y(mr,xr(r))}var xo={code:mr,name:ho,encode:xr,digest:mo};var yt={};k(yt,{sha256:()=>go,sha512:()=>wo});var bt=Z(F("crypto"),1);function wt({name:r,code:e,encode:t}){return new gt(r,e,t)}var gt=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?Y(this.code,t):t.then(n=>Y(this.code,n))}else throw Error("Unknown type, must be binary type")}};var go=wt({name:"sha2-256",code:18,encode:r=>O(bt.default.createHash("sha256").update(r).digest())}),wo=wt({name:"sha2-512",code:19,encode:r=>O(bt.default.createHash("sha512").update(r).digest())});function wr(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return yo(t,vt(r),e??P.encoder);default:return vo(t,vt(r),e??G.encoder)}}var br=new WeakMap;function vt(r){let e=br.get(r);if(e==null){let t=new Map;return br.set(r,t),t}return e}var J=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!==ge)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==Eo)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=Y(e,t);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(e){return r.equals(this,e)}static equals(e,t){let n=t;return n!=null&&e.code===n.code&&e.version===n.version&&hr(e.multihash,n.multihash)}toString(e){return wr(this,e)}toJSON(){return{"/":wr(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??yr(n,o,s.bytes))}else if(t[Io]===!0){let{version:n,multihash:o,code:s}=t,i=$e(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!==ge)throw new Error(`Version 0 CID must use dag-pb (code: ${ge}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let o=yr(e,t,n.bytes);return new r(e,t,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,ge,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=O(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 ae(t.multihashCode,t.digestSize,s,o);return[t.version===0?r.createV0(i):r.createV1(t.codec,i),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[f,v]=xe(e.subarray(t));return t+=v,f},o=n(),s=ge;if(o===18?(o=0,t=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=t,c=n(),l=n(),d=t+l,m=d-i;return{version:o,codec:s,multihashCode:c,digestSize:l,multihashSize:m,size:d}}static parse(e,t){let[n,o]=bo(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 vt(s).set(n,e),s}};function bo(r,e){switch(r[0]){case"Q":{let t=e??P;return[P.prefix,t.decode(`${P.prefix}${r}`)]}case P.prefix:{let t=e??P;return[P.prefix,t.decode(r)]}case G.prefix:{let t=e??G;return[G.prefix,t.decode(r)]}case he.prefix:{let t=e??he;return[he.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 yo(r,e,t){let{prefix:n}=t;if(n!==P.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 vo(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 ge=112,Eo=18;function yr(r,e,t){let n=ce(r),o=n+ce(e),s=new Uint8Array(o+t.byteLength);return ie(r,s,0),ie(e,s,n),s.set(t,o),s}var Io=Symbol.for("@ipld/js-cid/CID");var we={...ht,...lt,...ft,...ct,...at,...dt,...pt,...Je,...Ke,...ut},Yi={...yt,...xt};function Er(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var vr=Er("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Et=Er("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=Me(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),Ao={utf8:vr,"utf-8":vr,hex:we.base16,latin1:Et,ascii:Et,binary:Et,...we},Fe=Ao;function U(r,e="utf8"){let t=Fe[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return e==="utf8"||e==="utf-8"?Ir.Buffer.from(r.buffer,r.byteOffset,r.byteLength).toString("utf8"):t.encoder.encode(r).substring(1)}var Oe=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,c=this.peekChar();if(c===void 0)return;let l=c==="0",d=2**(8*o)-1;for(;;){let m=this.readAtomically(()=>{let f=this.readChar();if(f===void 0)return;let v=Number.parseInt(f,e);if(!Number.isNaN(v))return v});if(m===void 0)break;if(s*=e,s+=m,s>d||(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),[c]=e(s.subarray(0,i));return t.set(s.subarray(0,c),16-c),t})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var cc=new Oe;var mc=parseInt("0xFFFF",16),xc=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);var Cr=F("node:buffer");function Ve(r,e="utf8"){let t=Fe[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return e==="utf8"||e==="utf-8"?oe(Cr.Buffer.from(r,"utf-8")):t.decoder.decode(`${t.prefix}${r}`)}var Sr=S.isIPv4,Do=S.isIPv6,It=function(r){let e=0;if(r=r.toString().trim(),Sr(r)){let t=new Uint8Array(e+4);return r.split(/\./g).forEach(n=>{t[e++]=parseInt(n,10)&255}),t}if(Do(r)){let t=r.split(":",8),n;for(n=0;n<t.length;n++){let s=Sr(t[n]),i;s&&(i=It(t[n]),t[n]=U(i.slice(0,2),"base16")),i!=null&&++n<8&&t.splice(n,0,U(i.slice(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++){let s=parseInt(t[n],16);o[e++]=s>>8&255,o[e++]=s&255}return o}throw new Error("invalid ip address")},Pr=function(r,e=0,t){e=~~e,t=t??r.length-e;let n=new DataView(r.buffer);if(t===4){let o=[];for(let s=0;s<t;s++)o.push(r[e+s]);return o.join(".")}if(t===16){let o=[];for(let s=0;s<t;s+=2)o.push(n.getUint16(e+s).toString(16));return o.join(":").replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}return""};var ue={},At={},Uo=[[4,32,"ip4"],[6,16,"tcp"],[33,16,"dccp"],[41,128,"ip6"],[42,-1,"ip6zone"],[43,8,"ipcidr"],[53,-1,"dns",!0],[54,-1,"dns4",!0],[55,-1,"dns6",!0],[56,-1,"dnsaddr",!0],[132,16,"sctp"],[273,16,"udp"],[275,0,"p2p-webrtc-star"],[276,0,"p2p-webrtc-direct"],[277,0,"p2p-stardust"],[280,0,"webrtc-direct"],[281,0,"webrtc"],[290,0,"p2p-circuit"],[301,0,"udt"],[302,0,"utp"],[400,-1,"unix",!1,!0],[421,-1,"ipfs"],[421,-1,"p2p"],[443,0,"https"],[444,96,"onion"],[445,296,"onion3"],[446,-1,"garlic64"],[448,0,"tls"],[449,-1,"sni"],[460,0,"quic"],[461,0,"quic-v1"],[465,0,"webtransport"],[466,-1,"certhash"],[477,0,"ws"],[478,0,"wss"],[479,0,"p2p-websocket-star"],[480,0,"http"],[481,-1,"http-path"],[777,-1,"memory"]];Uo.forEach(r=>{let e=Mo(...r);At[e.code]=e,ue[e.name]=e});function Mo(r,e,t,n,o){return{code:r,size:e,name:t,resolvable:!!n,path:!!o}}function E(r){if(typeof r=="number"){if(At[r]!=null)return At[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(ue[r]!=null)return ue[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var ra=E("ip4"),na=E("ip6"),oa=E("ipcidr");function Pt(r,e){switch(E(r).code){case 4:case 41:return $o(e);case 42:return St(e);case 43:return U(e,"base10");case 6:case 273:case 33:case 132:return Nr(e).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return St(e);case 421:return _o(e);case 444:return Dr(e);case 445:return Dr(e);case 466:return Vo(e);case 481:return globalThis.encodeURIComponent(St(e));default:return U(e,"base16")}}function Lt(r,e){switch(E(r).code){case 4:return Lr(e);case 41:return Lr(e);case 42:return Ct(e);case 43:return Ve(e,"base10");case 6:case 273:case 33:case 132:return Dt(parseInt(e,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return Ct(e);case 421:return Fo(e);case 444:return zo(e);case 445:return Bo(e);case 466:return Oo(e);case 481:return Ct(globalThis.decodeURIComponent(e));default:return Ve(e,"base16")}}var Tt=Object.values(we).map(r=>r.decoder),ko=function(){let r=Tt[0].or(Tt[1]);return Tt.slice(2).forEach(e=>r=r.or(e)),r}();function Lr(r){if(!Ce(r))throw new Error("invalid ip address");return It(r)}function $o(r){let e=Pr(r,0,r.length);if(e==null)throw new Error("ipBuff is required");if(!Ce(e))throw new Error("invalid ip address");return e}function Dt(r){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,r),new Uint8Array(e)}function Nr(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function Ct(r){let e=Ve(r),t=Uint8Array.from(se(e.length));return q([t,e],t.length+e.length)}function St(r){let e=K(r);if(r=r.slice(R(e)),r.length!==e)throw new Error("inconsistent lengths");return U(r)}function Fo(r){let e;r[0]==="Q"||r[0]==="1"?e=$e(P.decode(`z${r}`)).bytes:e=J.parse(r).multihash.bytes;let t=Uint8Array.from(se(e.length));return q([t,e],t.length+e.length)}function Oo(r){let e=ko.decode(r),t=Uint8Array.from(se(e.length));return q([t,e],t.length+e.length)}function Vo(r){let e=K(r),t=r.slice(R(e));if(t.length!==e)throw new Error("inconsistent lengths");return"u"+U(t,"base64url")}function _o(r){let e=K(r),t=r.slice(R(e));if(t.length!==e)throw new Error("inconsistent lengths");return U(t,"base58btc")}function zo(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=G.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=Dt(n);return q([t,o],t.length+o.length)}function Bo(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=G.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=Dt(n);return q([t,o],t.length+o.length)}function Dr(r){let e=r.slice(0,r.length-2),t=r.slice(r.length-2),n=U(e,"base32"),o=Nr(t);return`${n}:${o}`}function Ur(r){r=Nt(r);let e=[],t=[],n=null,o=r.split("/").slice(1);if(o.length===1&&o[0]==="")return{bytes:new Uint8Array,string:"/",tuples:[],stringTuples:[],path:null};for(let s=0;s<o.length;s++){let i=o[s],c=E(i);if(c.size===0){e.push([c.code]),t.push([c.code]);continue}if(s++,s>=o.length)throw new _e("invalid address: "+r);if(c.path===!0){n=Nt(o.slice(s).join("/")),e.push([c.code,Lt(c.code,n)]),t.push([c.code,n]);break}let l=Lt(c.code,o[s]);e.push([c.code,l]),t.push([c.code,Pt(c.code,l)])}return{string:Mr(t),bytes:ze(e),tuples:e,stringTuples:t,path:n}}function Ut(r){let e=[],t=[],n=null,o=0;for(;o<r.length;){let s=K(r,o),i=R(s),c=E(s),l=Ro(c,r.slice(o+i));if(l===0){e.push([s]),t.push([s]),o+=i;continue}let d=r.slice(o+i,o+i+l);if(o+=l+i,o>r.length)throw new _e("Invalid address Uint8Array: "+U(r,"base16"));e.push([s,d]);let m=Pt(s,d);if(t.push([s,m]),c.path===!0){n=m;break}}return{bytes:Uint8Array.from(r),string:Mr(t),tuples:e,stringTuples:t,path:n}}function Mr(r){let e=[];return r.map(t=>{let n=E(t[0]);return e.push(n.name),t.length>1&&t[1]!=null&&e.push(t[1]),null}),Nt(e.join("/"))}function ze(r){return q(r.map(e=>{let t=E(e[0]),n=Uint8Array.from(se(t.code));return e.length>1&&e[1]!=null&&(n=q([n,e[1]])),n}))}function Ro(r,e){if(r.size>0)return r.size/8;if(r.size===0)return 0;{let t=K(e instanceof Uint8Array?e:Uint8Array.from(e));return t+R(t)}}function Nt(r){return"/"+r.trim().split("/").filter(e=>e).join("/")}var _e=class extends Error{static name="ParseError";name="ParseError";constructor(e){super(`Error parsing address: ${e}`)}};function kr(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}var jo=Symbol.for("nodejs.util.inspect.custom"),kt=Symbol.for("@multiformats/js-multiaddr/multiaddr"),Wo=[E("dns").code,E("dns4").code,E("dns6").code,E("dnsaddr").code],Mt=class extends Error{constructor(e="No available resolver"){super(e),this.name="NoAvailableResolverError"}},Be=class r{bytes;#e;#t;#r;#n;[kt]=!0;constructor(e){e==null&&(e="");let t;if(e instanceof Uint8Array)t=Ut(e);else if(typeof e=="string"){if(e.length>0&&e.charAt(0)!=="/")throw new Error(`multiaddr "${e}" must start with a "/"`);t=Ur(e)}else if(Fr(e))t=Ut(e.bytes);else throw new Error("addr must be a string, Buffer, or another Multiaddr");this.bytes=t.bytes,this.#e=t.string,this.#t=t.tuples,this.#r=t.stringTuples,this.#n=t.path}toString(){return this.#e}toJSON(){return this.toString()}toOptions(){let e,t,n,o,s="",i=E("tcp"),c=E("udp"),l=E("ip4"),d=E("ip6"),m=E("dns6"),f=E("ip6zone");for(let[a,u]of this.stringTuples())a===f.code&&(s=`%${u??""}`),Wo.includes(a)&&(t=i.name==="tcp"?"tcp":"udp",o=443,n=`${u??""}${s}`,e=a===m.code?6:4),(a===i.code||a===c.code)&&(t=E(a).name==="tcp"?"tcp":"udp",o=parseInt(u??"")),(a===l.code||a===d.code)&&(t=E(a).name==="tcp"?"tcp":"udp",n=`${u??""}${s}`,e=a===d.code?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}}protos(){return this.#t.map(([e])=>Object.assign({},E(e)))}protoCodes(){return this.#t.map(([e])=>e)}protoNames(){return this.#t.map(([e])=>E(e).name)}tuples(){return this.#t.map(([e,t])=>t==null?[e]:[e,t])}stringTuples(){return this.#r.map(([e,t])=>t==null?[e]:[e,t])}encapsulate(e){return e=new r(e),new r(this.toString()+e.toString())}decapsulate(e){let t=e.toString(),n=this.toString(),o=n.lastIndexOf(t);if(o<0)throw new Error(`Address ${this.toString()} does not contain subaddress: ${e.toString()}`);return new r(n.slice(0,o))}decapsulateCode(e){let t=this.tuples();for(let n=t.length-1;n>=0;n--)if(t[n][0]===e)return new r(ze(t.slice(0,n)));return this}getPeerId(){try{let e=[];this.stringTuples().forEach(([n,o])=>{n===ue.p2p.code&&e.push([n,o]),n===ue["p2p-circuit"].code&&(e=[])});let t=e.pop();if(t?.[1]!=null){let n=t[1];return n[0]==="Q"||n[0]==="1"?U(P.decode(`z${n}`),"base58btc"):U(J.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){return this.#n}equals(e){return kr(this.bytes,e.bytes)}async resolve(e){let t=this.protos().find(s=>s.resolvable);if(t==null)return[this];let n=$r.get(t.name);if(n==null)throw new Mt(`no available resolver for ${t.name}`);return(await n(this,e)).map(s=>_(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(e){let t=(e??this).protos();return!(t.length!==2||t[0].code!==4&&t[0].code!==41||t[1].code!==6&&t[1].code!==273)}[jo](){return`Multiaddr(${this.#e})`}};var $r=new Map;function Fr(r){return!!r?.[kt]}function _(r){return new Be(r)}function Or(r){return!!(r.startsWith("169.254.")||r.toLowerCase().startsWith("fe80"))}var qo={4:"IPv4",6:"IPv6"};function Go(r){return["0.0.0.0","::"].includes(r)}function Ho(r){let e=[],t=Vr.default.networkInterfaces();for(let[,n]of Object.entries(t))if(n!=null)for(let o of n)Or(o.address)||o.family===qo[r]&&e.push(o.address);return e}function _r(r,e){if(r==null)return[];let t=r.toOptions();if(Go(t.host)){let n=[];for(let o of Ho(t.family))n.push(_(`/ip${t.family}/${o}/${t.transport}/${e??t.port}`));return n}return[_(`/ip${t.family}/${t.host}/${t.transport}/${e??t.port}`)]}var $t=class extends Error{constructor(e){super(e),this.name="TimeoutError"}},Ft=class extends Error{constructor(e){super(),this.name="AbortError",this.message=e}},zr=r=>globalThis.DOMException===void 0?new Ft(r):new DOMException(r),Br=r=>{let e=r.reason===void 0?zr("This operation was aborted."):r.reason;return e instanceof Error?e:zr(e)};function Ot(r,e){let{milliseconds:t,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout}}=e,i,c,d=new Promise((m,f)=>{if(typeof t!="number"||Math.sign(t)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${t}\``);if(e.signal){let{signal:a}=e;a.aborted&&f(Br(a)),c=()=>{f(Br(a))},a.addEventListener("abort",c,{once:!0})}if(t===Number.POSITIVE_INFINITY){r.then(m,f);return}let v=new $t;i=s.setTimeout.call(void 0,()=>{if(n){try{m(n())}catch(a){f(a)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?m():o instanceof Error?f(o):(v.message=o??`Promise timed out after ${t} milliseconds`,f(v))},t),(async()=>{try{m(await r)}catch(a){f(a)}})()}).finally(()=>{d.clear(),c&&e.signal&&e.signal.removeEventListener("abort",c)});return d.clear=()=>{s.clearTimeout.call(void 0,i),i=void 0},d}var Qo=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 Jo(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 c=[e].flat(),l=[],{addListener:d,removeListener:m}=Qo(r),f=(...a)=>{let u=t.multiArgs?a:a[0];t.filter&&!t.filter(u)||(l.push(u),t.count===l.length&&(n(),s(l)))},v=a=>{n(),i(a)};n=()=>{for(let a of c)m(a,f);for(let a of t.rejectionEvents)m(a,v)};for(let a of c)d(a,f);for(let a of t.rejectionEvents)d(a,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=Ot(o,{milliseconds:t.timeout});return s.cancel=n,s}return o}function Vt(r,e,t){typeof t=="function"&&(t={filter:t}),t={...t,count:1,resolveImmediately:!1};let n=Jo(r,e,t),o=n.then(s=>s[0]);return o.cancel=n.cancel,o}function Rr(r,e){if(typeof r!="string")throw new B(`invalid ip provided: ${r}`);if(typeof e=="string"&&(e=parseInt(e)),isNaN(e))throw new B(`invalid port provided: ${e}`);if((0,S.isIPv4)(r))return _(`/ip4/${r}/tcp/${e}`);if((0,S.isIPv6)(r))return _(`/ip6/${r}/tcp/${e}`);throw new B(`invalid ip:port for creating a multiaddr: ${r}:${e}`)}function _t(){let r={};return r.promise=new Promise((e,t)=>{r.resolve=e,r.reject=t}),r}var zt=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 Bt(r,e,t,n){let o=new zt(n?.errorMessage,n?.errorCode);return t?.aborted===!0?Promise.reject(o):new Promise((s,i)=>{function c(){t?.removeEventListener("abort",m),r.removeEventListener(e,l),n?.errorEvent!=null&&r.removeEventListener(n.errorEvent,d)}let l=f=>{try{if(n?.filter?.(f)===!1)return}catch(v){c(),i(v);return}c(),s(f)},d=f=>{c(),i(f.detail)},m=()=>{c(),i(o)};t?.addEventListener("abort",m),r.addEventListener(e,l),n?.errorEvent!=null&&r.addEventListener(n.errorEvent,d)})}function jr(r){if(Ko(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(Xo(r))return r;throw new Error("unknown stream")}function Xo(r){return r[Symbol.asyncIterator]!=null}function Ko(r){return typeof r?.getReader=="function"}function Wr(r){return async e=>{let t=async()=>{Yo(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,c=!1,l=()=>{c=!0,i?.()},d,m=!1,f=()=>{m=!0,d?.()},v,a=()=>{v?.()},u=async()=>new Promise((x,b)=>{i=v=x,o=b,r.once("drain",a)}),T=async()=>(await t(),new Promise((x,b)=>{if(c||m||n!=null){x();return}d=i=x,o=b})),N=()=>{r.removeListener("error",s),r.removeListener("close",l),r.removeListener("finish",f),r.removeListener("drain",a)};r.once("error",s),r.once("close",l),r.once("finish",f);try{for await(let x of e){if(!r.writable||r.destroyed||n!=null)break;r.write(x)||await u()}}catch(x){n==null&&r.destroy(x),n=x}try{if(r.writable&&r.end(),await T(),n!=null)throw n}finally{N()}}}function Yo(r){return r.return!=null}function Rt(r){return{sink:Wr(r),source:jr(r)}}var qr=Z(F("os"),1),Gr=Z(F("path"),1);function de(r,e={}){let t=r.getPath();if(t!=null)return qr.default.platform()==="win32"?{path:Gr.default.join("\\\\.\\pipe\\",t)}:{path:t};let n=r.toOptions();return{...e,...n,ipv6Only:n.family===6}}var Re=(r,e)=>{let t,n=e.logger.forComponent("libp2p:tcp:socket"),o=e.direction,s=e.metrics,i=e.metricPrefix??"",c=e.socketInactivityTimeout??12e4,l=e.socketCloseTimeout??500,d=!1,m=!1;e.listeningAddr?.getPath()!=null&&(e.remoteAddr=e.listeningAddr),e.remoteAddr?.getPath()!=null&&(e.localAddr=e.remoteAddr),r.on("error",x=>{m=!0,d||(n.error("%s socket error - %e",o,x),s?.increment({[`${i}error`]:!0})),r.destroy(),N.timeline.close=Date.now()});let f;if(e.remoteAddr!=null)f=e.remoteAddr;else{if(r.remoteAddress==null||r.remotePort==null)throw new B("Could not determine remote address or port");f=Rr(r.remoteAddress,r.remotePort)}let v=de(f),a=v.path??`${v.host??""}:${v.port??""}`,{sink:u,source:T}=Rt(r);r.setTimeout(c),r.once("timeout",()=>{d=!0,n("%s %s socket read timeout",o,a),s?.increment({[`${i}timeout`]:!0}),r.destroy(new ee),N.timeline.close=Date.now()}),r.once("close",()=>{!d&&!m&&(n("%s %s socket close",o,a),s?.increment({[`${i}close`]:!0})),r.destroy(),N.timeline.close=Date.now()}),r.once("end",()=>{n("%s %s socket end",o,a),s?.increment({[`${i}end`]:!0})});let N={async sink(x){try{await u(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,a,b)}r.end()},source:T,remoteAddr:f,timeline:{open:Date.now()},async close(x={}){if(r.closed){n("the %s %s socket is already closed",o,a);return}if(r.destroyed){n("the %s %s socket is already destroyed",o,a);return}if(t!=null)return t.promise;try{t=_t(),r.end();let b=Zo(r),M=x.signal??AbortSignal.timeout(l);r.writableLength>0&&(n("%s %s draining socket",o,a),await Bt(b,"drain",M,{errorEvent:"error"}),n("%s %s socket drained",o,a)),await Promise.all([Bt(b,"close",M,{errorEvent:"error"}),r.destroy()])}catch(b){this.abort(b)}finally{t.resolve()}},abort:x=>{n("%s %s socket abort due to error - %e",o,a,x),r.destroy(),N.timeline.close=Date.now()},log:n};return N};function Zo(r){return{addEventListener:(t,n)=>{r.addListener(t,n)},removeEventListener:(t,n)=>{r.removeListener(t,n)}}}var C;(function(r){r[r.INACTIVE=0]="INACTIVE",r[r.ACTIVE=1]="ACTIVE",r[r.PAUSED=2]="PAUSED"})(C||(C={}));var je=class extends Te{context;server;sockets=new Set;status={code:C.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,Ae(1/0,this.shutdownController.signal),this.log=e.logger.forComponent("libp2p:tcp:listener"),this.addr="unknown",this.server=Hr.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 B("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]:C.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!==C.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!==C.ACTIVE)throw e.destroy(),new Ee("Server is not listening yet");let t;try{t=Re(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===C.INACTIVE)return[];let e=this.server.address();return e==null?[]:typeof e=="string"?[_(`/unix/${e}`)]:_r(this.status.listeningAddr,e.port)}updateAnnounceAddrs(){}async listen(e){if(this.status.code===C.ACTIVE||this.status.code===C.PAUSED)throw new Ie("server is already listening");try{this.status={code:C.ACTIVE,listeningAddr:e,netConfig:de(e,this.context)},await this.resume()}catch(t){throw this.status={code:C.INACTIVE},t}}async close(){let e=[];this.server.listening&&e.push(Vt(this.server,"close")),this.pause(!0),this.shutdownController.abort(),this.sockets.forEach(t=>{t.readable&&(e.push(Vt(t,"close")),t.destroy())}),await Promise.all(e)}async resume(){if(this.server.listening||this.status.code===C.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:C.ACTIVE},this.log("listening on %s",this.server.address())}pause(e=!1){if(!this.server.listening&&this.status.code===C.PAUSED&&e){this.status={code:C.INACTIVE};return}!this.server.listening||this.status.code!==C.ACTIVE||(this.log("closing server on %s",this.server.address()),this.status=e?{code:C.INACTIVE}:{...this.status,code:C.PAUSED},this.server.close())}};var We=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"})})}[qt]=!0;[Symbol.toStringTag]="@libp2p/tcp";[Ht]=["@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=Re(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 Ue("tcp:open-connection"));let n;return new Promise((o,s)=>{let i=Date.now(),c=de(e,{...this.opts.dialOpts??{},...t});this.log("dialing %a",e),n=Qr.default.connect(c);let l=a=>{this.log.error("dial to %a errored - %e",e,a);let u=c.path??`${c.host??""}:${c.port}`;a.message=`connection error ${u}: ${a.message}`,this.metrics?.events.increment({error:!0}),v(a)},d=()=>{this.log("connection timeout %a",e),this.metrics?.events.increment({timeout:!0});let a=new ee(`Connection timeout after ${Date.now()-i}ms`);n.emit("error",a)},m=()=>{this.log("connection opened %a",e),this.metrics?.events.increment({connect:!0}),v()},f=()=>{this.log("connection aborted %a",e),this.metrics?.events.increment({abort:!0}),v(new ve)},v=a=>{if(n.removeListener("error",l),n.removeListener("timeout",d),n.removeListener("connect",m),t.signal!=null&&t.signal.removeEventListener("abort",f),a!=null){s(a);return}o(n)};n.on("error",l),n.on("timeout",d),n.on("connect",m),t.signal.addEventListener("abort",f)}).catch(o=>{throw n?.destroy(),o})}createListener(e){return new je({...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=>rr.exactMatch(t)||t.toString().startsWith("/unix/"))}dialFilter(e){return this.listenFilter(e)}};function es(r={}){return e=>new We(e,r)}return en(ts);})();
return Libp2PTcp}));
//# sourceMappingURL=index.min.js.map

@@ -1,2 +0,2 @@

import { TypedEventEmitter } from '@libp2p/interface';
import { TypedEventEmitter } from 'main-event';
import type { CloseServerOnMaxConnectionsOpts, TCPCreateListenerOptions } from './index.js';

@@ -3,0 +3,0 @@ import type { ComponentLogger, Metrics, Listener, ListenerEvents, Upgrader } from '@libp2p/interface';

import net from 'net';
import { AlreadyStartedError, InvalidParametersError, NotStartedError, TypedEventEmitter, setMaxListeners } from '@libp2p/interface';
import { AlreadyStartedError, InvalidParametersError, NotStartedError } from '@libp2p/interface';
import { getThinWaistAddresses } from '@libp2p/utils/get-thin-waist-addresses';
import { multiaddr } from '@multiformats/multiaddr';
import { TypedEventEmitter, setMaxListeners } from 'main-event';
import { pEvent } from 'p-event';

@@ -6,0 +7,0 @@ import { toMultiaddrConnection } from './socket-to-conn.js';

{
"name": "@libp2p/tcp",
"version": "10.1.13-6a3ae02f5",
"version": "10.1.13-8e87be9e6",
"description": "A TCP transport for libp2p",

@@ -56,7 +56,8 @@ "license": "Apache-2.0 OR MIT",

"dependencies": {
"@libp2p/interface": "2.10.2-6a3ae02f5",
"@libp2p/utils": "6.6.5-6a3ae02f5",
"@libp2p/interface": "2.10.2-8e87be9e6",
"@libp2p/utils": "6.6.5-8e87be9e6",
"@multiformats/multiaddr": "^12.4.0",
"@multiformats/multiaddr-matcher": "^1.7.2",
"@types/sinon": "^17.0.4",
"main-event": "^1.0.1",
"p-defer": "^4.0.1",

@@ -69,3 +70,3 @@ "p-event": "^6.0.1",

"devDependencies": {
"@libp2p/logger": "5.1.18-6a3ae02f5",
"@libp2p/logger": "5.1.18-8e87be9e6",
"aegir": "^47.0.14",

@@ -72,0 +73,0 @@ "p-wait-for": "^5.0.2",

import net from 'net'
import { AlreadyStartedError, InvalidParametersError, NotStartedError, TypedEventEmitter, setMaxListeners } from '@libp2p/interface'
import { AlreadyStartedError, InvalidParametersError, NotStartedError } from '@libp2p/interface'
import { getThinWaistAddresses } from '@libp2p/utils/get-thin-waist-addresses'
import { multiaddr } from '@multiformats/multiaddr'
import { TypedEventEmitter, setMaxListeners } from 'main-event'
import { pEvent } from 'p-event'

@@ -6,0 +7,0 @@ import { toMultiaddrConnection } from './socket-to-conn.js'

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet