@libp2p/tcp 11.0.26-d5534174d → 11.0.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +3 -3
- package/dist/src/socket-to-conn.d.ts.map +1 -1
- package/dist/src/socket-to-conn.js +17 -0
- package/dist/src/socket-to-conn.js.map +1 -1
- package/dist/typedoc-urls.json +20 -0
- package/package.json +4 -4
- package/src/socket-to-conn.ts +19 -0
package/dist/index.min.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PTcp = factory()}(typeof self !== 'undefined' ? self : this, function () {
|
|
2
|
-
"use strict";var Libp2PTcp=(()=>{var qn=Object.create;var ze=Object.defineProperty;var Hn=Object.getOwnPropertyDescriptor;var Qn=Object.getOwnPropertyNames;var Gn=Object.getPrototypeOf,Xn=Object.prototype.hasOwnProperty;var k=(r=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(r,{get:(e,t)=>(typeof require<"u"?require:e)[t]}):r)(function(r){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+r+'" is not supported')});var B=(r,e)=>{for(var t in e)ze(r,t,{get:e[t],enumerable:!0})},Br=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Qn(e))!Xn.call(r,o)&&o!==t&&ze(r,o,{get:()=>e[o],enumerable:!(n=Hn(e,o))||n.enumerable});return r};var ue=(r,e,t)=>(t=r!=null?qn(Gn(r)):{},Br(e||!r||!r.__esModule?ze(t,"default",{value:r,enumerable:!0}):t,r)),Jn=r=>Br(ze({},"__esModule",{value:!0}),r);var oi={};B(oi,{tcp:()=>ni});var jn=ue(k("net"),1);var $e=class extends Error{static name="AbortError";constructor(e="The operation was aborted"){super(e),this.name="AbortError"}};var _=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}};var Fe=class extends Error{static name="StreamResetError";constructor(e="The stream has been reset"){super(e),this.name="StreamResetError"}};var Y=class extends Error{static name="StreamStateError";constructor(e="The stream is in an invalid state"){super(e),this.name="StreamStateError"}},Le=class extends Error{static name="StreamBufferError";constructor(e="The stream buffer was full"){super(e),this.name="StreamBufferError"}};var le=class extends Error{static name="TimeoutError";constructor(e="Timed out"){super(e),this.name="TimeoutError"}},We=class extends Error{static name="NotStartedError";constructor(e="Not started"){super(e),this.name="NotStartedError"}},je=class extends Error{static name="AlreadyStartedError";constructor(e="Already started"){super(e),this.name="AlreadyStartedError"}};var qe=class extends Event{data;constructor(e,t){super("message",t),this.data=e}},fe=class extends Event{error;local;constructor(e,t,n){super("close",n),this.error=t,this.local=e}},He=class extends fe{constructor(e,t){super(!0,e,t)}},Qe=class extends fe{constructor(e,t){super(!1,e,t)}};var Ur=Symbol.for("@libp2p/transport");var Nr;(function(r){r[r.FATAL_ALL=0]="FATAL_ALL",r[r.NO_FATAL=1]="NO_FATAL"})(Nr||(Nr={}));var Rr=k("node:events"),Ge=(r,...e)=>{try{(0,Rr.setMaxListeners)(r,...e)}catch{}};function Kn(r){return typeof r?.handleEvent=="function"}function Yn(r){return r===!0||r===!1}function Zn(r){return Yn(r)?r:r?.capture??!1}function It(r){let e={capture:Zn(r),once:!!r?.once};return r?.passive!=null&&(e.passive=r?.passive),r?.signal!=null&&(e.signal=r?.signal),e}function Mr(r,e){return It(r).capture===It(e).capture}var he=class extends EventTarget{#e=new Map;constructor(){super(),Ge(1/0,this)}listenerCount(e){let t=this.#e.get(e);return t==null?0:t.length}addEventListener(e,t,n){let o=It(n);if(o?.signal?.aborted===!0)return;let s=l=>{o.once&&this.removeEventListener(e,t,o),Kn(t)?t.handleEvent(l):t(l)},i=this.#e.get(e);if(i==null&&(i=[],this.#e.set(e,i)),i.some(l=>l.callback!==t?!1:Mr(l.options,o)))return;super.addEventListener(e,s,o);let c=()=>{this.removeEventListener(e,t,o)};o.signal?.addEventListener("abort",c),i.push({callback:t,wrapper:s,options:o,onAbort:c})}removeEventListener(e,t,n){let o=this.#e.get(e);if(o==null){super.removeEventListener(e,t??null,n);return}this.#e.set(e,o.filter(s=>s.callback===t&&Mr(s.options,n)?(super.removeEventListener(e,s.wrapper,n),s.options?.signal?.removeEventListener("abort",s.onAbort),!1):!0))}safeDispatchEvent(e,t={}){return this.dispatchEvent(new CustomEvent(e,t))}};var kr=Symbol.for("@libp2p/service-capabilities");function Ae(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 Tt=k("node:buffer");function Z(r){if(r.buffer instanceof ArrayBuffer)return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);let e=r.slice();return new Uint8Array(e.buffer,0,e.byteLength)}function j(r=0){return Z(Tt.Buffer.alloc(r))}function ee(r=0){return Z(Tt.Buffer.allocUnsafe(r))}var eo=Math.pow(2,7),to=Math.pow(2,14),ro=Math.pow(2,21),Lt=Math.pow(2,28),At=Math.pow(2,35),Pt=Math.pow(2,42),Ot=Math.pow(2,49),v=128,L=127;function de(r){if(r<eo)return 1;if(r<to)return 2;if(r<ro)return 3;if(r<Lt)return 4;if(r<At)return 5;if(r<Pt)return 6;if(r<Ot)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function _t(r,e,t=0){switch(de(r)){case 8:e[t++]=r&255|v,r/=128;case 7:e[t++]=r&255|v,r/=128;case 6:e[t++]=r&255|v,r/=128;case 5:e[t++]=r&255|v,r/=128;case 4:e[t++]=r&255|v,r>>>=7;case 3:e[t++]=r&255|v,r>>>=7;case 2:e[t++]=r&255|v,r>>>=7;case 1:{e[t++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return e}function no(r,e){let t=r[e],n=0;if(n+=t&L,t<v||(t=r[e+1],n+=(t&L)<<7,t<v)||(t=r[e+2],n+=(t&L)<<14,t<v)||(t=r[e+3],n+=(t&L)<<21,t<v)||(t=r[e+4],n+=(t&L)*Lt,t<v)||(t=r[e+5],n+=(t&L)*At,t<v)||(t=r[e+6],n+=(t&L)*Pt,t<v)||(t=r[e+7],n+=(t&L)*Ot,t<v))return n;throw new RangeError("Could not decode varint")}function oo(r,e){let t=r.get(e),n=0;if(n+=t&L,t<v||(t=r.get(e+1),n+=(t&L)<<7,t<v)||(t=r.get(e+2),n+=(t&L)<<14,t<v)||(t=r.get(e+3),n+=(t&L)<<21,t<v)||(t=r.get(e+4),n+=(t&L)*Lt,t<v)||(t=r.get(e+5),n+=(t&L)*At,t<v)||(t=r.get(e+6),n+=(t&L)*Pt,t<v)||(t=r.get(e+7),n+=(t&L)*Ot,t<v))return n;throw new RangeError("Could not decode varint")}function Bt(r,e=0){return r instanceof Uint8Array?no(r,e):oo(r,e)}function io(r){return r.buffer instanceof ArrayBuffer}function Nt(r){return io(r)?r:r.slice()}var Vr=k("node:buffer");function Q(r,e){return Z(Vr.Buffer.concat(r,e))}var un=k("node:buffer");var Vt={};B(Vt,{base10:()=>mo});var Ji=new Uint8Array(0);function $r(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}function P(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return se(r);if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return se(new Uint8Array(r.buffer,r.byteOffset,r.byteLength));throw new Error("Unknown type, must be binary type")}function Fr(r){let e=new Uint8Array(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}var zr=4096;function Wr(r){let e=r.length;if(e<=zr)return String.fromCharCode.apply(String,r);let t="",n=0;for(;n<e;)t+=String.fromCharCode.apply(String,r.subarray(n,n+=zr));return t}function ao(r){return r?.buffer instanceof ArrayBuffer}function se(r){return ao(r)?r:r.slice()}function co(r,e,t){if(r.length>=255)throw new TypeError("Alphabet too long");for(var n=new Uint8Array(256),o=0;o<n.length;o++)n[o]=255;for(var s=0;s<r.length;s++){var i=r.charAt(s),a=i.charCodeAt(0);if(n[a]!==255)throw new TypeError(i+" is ambiguous");if(n[a]=s,t){var c=i.toLowerCase().charCodeAt(0),l=i.toUpperCase().charCodeAt(0);c!==a&&(n[c]=s),l!==a&&(n[l]=s)}}var f=r.length,h=r.charAt(0),b=Math.log(f)/Math.log(256),p=Math.log(256)/Math.log(f);function $(m){if(m instanceof Uint8Array||(ArrayBuffer.isView(m)?m=new Uint8Array(m.buffer,m.byteOffset,m.byteLength):Array.isArray(m)&&(m=Uint8Array.from(m))),!(m instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(m.length===0)return"";for(var S=0,O=0,U=0,R=m.length;U!==R&&m[U]===0;)U++,S++;for(var F=(R-U)*p+1>>>0,M=new Uint8Array(F);U!==R;){for(var W=m[U],K=0,z=F-1;(W!==0||K<O)&&z!==-1;z--,K++)W+=256*M[z]>>>0,M[z]=W%f>>>0,W=W/f>>>0;if(W!==0)throw new Error("Non-zero carry");O=K,U++}for(var H=F-O;H!==F&&M[H]===0;)H++;for(var Ve=h.repeat(S);H<F;++H)Ve+=r.charAt(M[H]);return Ve}function V(m){if(typeof m!="string")throw new TypeError("Expected String");if(m.length===0)return new Uint8Array;var S=0;if(m[S]!==" "){for(var O=0,U=0;m[S]===h;)O++,S++;for(var R=(m.length-S)*b+1>>>0,F=new Uint8Array(R);m[S];){var M=n[m.charCodeAt(S)];if(M===255)return;for(var W=0,K=R-1;(M!==0||W<U)&&K!==-1;K--,W++)M+=f*F[K]>>>0,F[K]=M%256>>>0,M=M/256>>>0;if(M!==0)throw new Error("Non-zero carry");U=W,S++}if(m[S]!==" "){for(var z=R-U;z!==R&&F[z]===0;)z++;for(var H=new Uint8Array(O+(R-z)),Ve=O;z!==R;)H[Ve++]=F[z++];return H}}}function y(m){var S=V(m);if(S)return S;throw new Error(`Non-${e} character`)}return{encode:$,decodeUnsafe:V,decode:y}}var uo=co,lo=uo,qr=lo;var Ut=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")}},Rt=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 Hr(this,e)}},Mt=class{decoders;constructor(e){this.decoders=e}or(e){return Hr(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 Hr(r,e){return new Mt({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var kt=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 Ut(e,t,n),this.decoder=new Rt(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function pe({name:r,prefix:e,encode:t,decode:n}){return new kt(r,e,t,n)}function te({name:r,prefix:e,alphabet:t,caseInsensitive:n=!1}){let{encode:o,decode:s}=qr(t,r,n);return pe({prefix:e,name:r,encode:o,decode:i=>P(s(i))})}function fo(r,e,t,n){let o=r.length;for(;r[o-1]==="=";)--o;let s=new Uint8Array(o*t/8|0),i=0,a=0,c=0;for(let l=0;l<o;++l){let f=e[r[l]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<t|f,i+=t,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=t||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function ho(r,e,t){let n=e[e.length-1]==="=",o=(1<<t)-1,s="",i=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],i+=8;i>t;)i-=t,s+=e[o&a>>i];if(i!==0&&(s+=e[o&a<<t-i]),n)for(;(s.length*t&7)!==0;)s+="=";return s}function po(r,e){let t={};for(let n=0;n<r.length;++n)if(t[r[n]]=n,e){let o=r[n].toLowerCase(),s=r[n].toUpperCase();o!==r[n]&&(t[o]=n),s!==r[n]&&(t[s]=n)}return t}function C({name:r,prefix:e,bitsPerChar:t,alphabet:n,caseInsensitive:o=!1}){let s=po(n,o);return pe({prefix:e,name:r,encode(i){return ho(i,n,t)},decode(i){return fo(i,s,t,r)}})}var mo=te({prefix:"9",name:"base10",alphabet:"0123456789"});var zt={};B(zt,{base16:()=>go,base16upper:()=>bo});var go=C({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4,caseInsensitive:!0}),bo=C({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4,caseInsensitive:!0});var $t={};B($t,{base2:()=>wo});var wo=C({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Ft={};B(Ft,{base256emoji:()=>Co});var Qr=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),yo=Qr.reduce((r,e,t)=>(r[t]=e,r),[]),xo=Qr.reduce((r,e,t)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return r[n]=t,r},[]);function Eo(r){return r.reduce((e,t)=>(e+=yo[t],e),"")}function vo(r){let e=[];for(let t of r){let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);let o=xo[n];if(o==null)throw new Error(`Non-base256emoji character: ${t}`);e.push(o)}return new Uint8Array(e)}var Co=pe({prefix:"\u{1F680}",name:"base256emoji",encode:Eo,decode:vo});var Wt={};B(Wt,{base32:()=>re,base32hex:()=>To,base32hexpad:()=>Ao,base32hexpadupper:()=>Po,base32hexupper:()=>Lo,base32pad:()=>Do,base32padupper:()=>Io,base32upper:()=>So,base32z:()=>Oo});var re=C({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5,caseInsensitive:!0}),So=C({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5,caseInsensitive:!0}),Do=C({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5,caseInsensitive:!0}),Io=C({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5,caseInsensitive:!0}),To=C({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5,caseInsensitive:!0}),Lo=C({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5,caseInsensitive:!0}),Ao=C({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5,caseInsensitive:!0}),Po=C({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5,caseInsensitive:!0}),Oo=C({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var jt={};B(jt,{base36:()=>Pe,base36upper:()=>_o});var Pe=te({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz",caseInsensitive:!0}),_o=te({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",caseInsensitive:!0});var qt={};B(qt,{base58btc:()=>q,base58flickr:()=>Bo});var q=te({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Bo=te({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Qt={};B(Qt,{base64:()=>No,base64pad:()=>Uo,base64url:()=>Ht,base64urlpad:()=>Ro});var No=C({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Uo=C({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Ht=C({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Ro=C({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Gt={};B(Gt,{base8:()=>Mo});var Mo=C({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Xt={};B(Xt,{identity:()=>ko});var ko=pe({prefix:"\0",name:"identity",encode:r=>Wr(P(r)),decode:r=>P(Fr(r))});var ha=new TextEncoder,da=new TextDecoder;var Kt={};B(Kt,{identity:()=>as});var $o=Jr,Gr=128,Fo=127,Wo=~Fo,jo=Math.pow(2,31);function Jr(r,e,t){e=e||[],t=t||0;for(var n=t;r>=jo;)e[t++]=r&255|Gr,r/=128;for(;r&Wo;)e[t++]=r&255|Gr,r>>>=7;return e[t]=r|0,Jr.bytes=t-n+1,e}var qo=Jt,Ho=128,Xr=127;function Jt(r,n){var t=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw Jt.bytes=0,new RangeError("Could not decode varint");i=r[s++],t+=o<28?(i&Xr)<<o:(i&Xr)*Math.pow(2,o),o+=7}while(i>=Ho);return Jt.bytes=s-n,t}var Qo=Math.pow(2,7),Go=Math.pow(2,14),Xo=Math.pow(2,21),Jo=Math.pow(2,28),Ko=Math.pow(2,35),Yo=Math.pow(2,42),Zo=Math.pow(2,49),es=Math.pow(2,56),ts=Math.pow(2,63),rs=function(r){return r<Qo?1:r<Go?2:r<Xo?3:r<Jo?4:r<Ko?5:r<Yo?6:r<Zo?7:r<es?8:r<ts?9:10},ns={encode:$o,decode:qo,encodingLength:rs},os=ns,Oe=os;function _e(r,e=0){let t=Oe.decode(r,e),n=Oe.decode.bytes;if(n>9)throw new RangeError("Invalid varint: too long");if(n>1&&r[e+n-1]===0)throw new RangeError("Invalid varint: not minimally encoded");return[t,n]}function me(r,e,t=0){return Oe.encode(r,e,t),e}function ge(r){return Oe.encodingLength(r)}function we(r,e){let t=e.byteLength,n=ge(r),o=n+ge(t),s=new Uint8Array(o+t);return me(r,s,0),me(t,s,n),s.set(e,o),new be(r,t,e,s)}function Kr(r){let e=P(r),[t,n]=_e(e),[o,s]=_e(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new be(t,o,i,e)}function Yr(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&$r(r.bytes,t.bytes)}}var be=class{code;size;digest;bytes;constructor(e,t,n,o){this.code=e,this.size=t,this.digest=se(n),this.bytes=se(o)}};var Zr=0,ss="identity",en=P;function is(r,e){if(e?.truncate!=null&&e.truncate!==r.byteLength){if(e.truncate<0||e.truncate>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,e.truncate)}return we(Zr,en(r))}var as={code:Zr,name:ss,encode:en,digest:is};var tr={};B(tr,{sha256:()=>us,sha512:()=>ls});var er=ue(k("node:crypto"),1);var cs=20;function Zt({name:r,code:e,encode:t,minDigestLength:n,maxDigestLength:o}){return new Yt(r,e,t,n,o)}var Yt=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,t,n,o,s){this.name=e,this.code=t,this.encode=n,this.minDigestLength=o??cs,this.maxDigestLength=s}digest(e,t){if(t?.truncate!=null){if(t.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&t.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(e instanceof Uint8Array){let n=this.encode(e);return n instanceof Uint8Array?tn(n,this.code,t?.truncate):n.then(o=>tn(o,this.code,t?.truncate))}else throw Error("Unknown type, must be binary type")}};function tn(r,e,t){if(t!=null&&t!==r.byteLength){if(t>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,t)}return we(e,r)}var us=Zt({name:"sha2-256",code:18,encode:r=>P(er.default.createHash("sha256").update(r).digest())}),ls=Zt({name:"sha2-512",code:19,encode:r=>P(er.default.createHash("sha512").update(r).digest())});function nn(r,e){let{bytes:t,version:n}=r;return n===0?hs(t,rr(r),e??q.encoder):ds(t,rr(r),e??re.encoder)}var on=new WeakMap;function rr(r){let e=on.get(r);if(e==null){let t=new Map;return on.set(r,t),t}return e}var ye=class r{code;version;multihash;bytes;"/";constructor(e,t,n,o){this.code=t,this.version=e,this.multihash=n,this.bytes=se(o),this["/"]=this.bytes}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:t}=this;if(e!==Ne)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==ps)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=we(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&&Yr(e.multihash,n.multihash)}toString(e){return nn(this,e)}toJSON(){return{"/":nn(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??sn(n,o,s.bytes))}else if(t[ms]===!0){let{version:n,multihash:o,code:s}=t,i=Kr(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!==Ne)throw new Error(`Version 0 CID must use dag-pb (code: ${Ne}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let o=sn(e,t,n.bytes);return new r(e,t,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,Ne,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=P(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 be(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[h,b]=_e(e.subarray(t));return t+=b,h},o=n(),s=Ne;if(o===18?(o=0,t=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=t,a=n(),c=n(),l=t+c,f=l-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:f,size:l}}static parse(e,t){let[n,o]=fs(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 rr(s).set(n,e),s}};function fs(r,e){switch(r[0]){case"Q":{let t=e??q;return[q.prefix,t.decode(`${q.prefix}${r}`)]}case q.prefix:{let t=e??q;return[q.prefix,t.decode(r)]}case re.prefix:{let t=e??re;return[re.prefix,t.decode(r)]}case Pe.prefix:{let t=e??Pe;return[Pe.prefix,t.decode(r)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],e.decode(r)]}}}function hs(r,e,t){let{prefix:n}=t;if(n!==q.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 ds(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 Ne=112,ps=18;function sn(r,e,t){let n=ge(r),o=n+ge(e),s=new Uint8Array(o+t.byteLength);return me(r,s,0),me(e,s,n),s.set(t,o),s}var ms=Symbol.for("@ipld/js-cid/CID");var Ue={...Xt,...$t,...Gt,...Vt,...zt,...Wt,...jt,...qt,...Qt,...Ft},Ra={...tr,...Kt};function cn(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var an=cn("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),nr=cn("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=ee(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),gs={utf8:an,"utf-8":an,hex:Ue.base16,latin1:nr,ascii:nr,binary:nr,...Ue},Je=gs;function xe(r,e="utf8"){let t=Je[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return e==="utf8"||e==="utf-8"?Z(un.Buffer.from(r,"utf-8")):t.decoder.decode(`${t.prefix}${r}`)}var ln=k("node:buffer");function ne(r,e="utf8"){let t=Je[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return e==="utf8"||e==="utf-8"?ln.Buffer.from(r.buffer,r.byteOffset,r.byteLength).toString("utf8"):t.encoder.encode(r).substring(1)}var T=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},G=class extends Error{static name="ValidationError";name="ValidationError"},Ke=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},Ye=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};var N=k("node:net");function sr(r){return e=>ne(e,r)}function ir(r){return e=>xe(e,r)}function Ee(r){return new DataView(r.buffer).getUint16(r.byteOffset).toString()}function ie(r){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,typeof r=="string"?parseInt(r):r),new Uint8Array(e)}function fn(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=xe(e[0],"base32"),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=ie(n);return Q([t,o],t.length+o.length)}function hn(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=re.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=ie(n);return Q([t,o],t.length+o.length)}function ar(r){let e=r.subarray(0,r.length-2),t=r.subarray(r.length-2),n=ne(e,"base32"),o=Ee(t);return`${n}:${o}`}var cr=function(r){r=r.toString().trim();let e=new Uint8Array(4);return r.split(/\./g).forEach((t,n)=>{let o=parseInt(t,10);if(isNaN(o)||o<0||o>255)throw new T("Invalid byte value in IP address");e[n]=o}),e},dn=function(r){let e=0;r=r.toString().trim();let t=r.split(":",8),n;for(n=0;n<t.length;n++){let s=(0,N.isIPv4)(t[n]),i;s&&(i=cr(t[n]),t[n]=ne(i.subarray(0,2),"base16")),i!=null&&++n<8&&t.splice(n,0,ne(i.subarray(2,4),"base16"))}if(t[0]==="")for(;t.length<8;)t.unshift("0");else if(t[t.length-1]==="")for(;t.length<8;)t.push("0");else if(t.length<8){for(n=0;n<t.length&&t[n]!=="";n++);let s=[n,1];for(n=9-t.length;n>0;n--)s.push("0");t.splice.apply(t,s)}let o=new Uint8Array(e+16);for(n=0;n<t.length;n++){t[n]===""&&(t[n]="0");let s=parseInt(t[n],16);if(isNaN(s)||s<0||s>65535)throw new T("Invalid byte value in IP address");o[e++]=s>>8&255,o[e++]=s&255}return o},pn=function(r){if(r.byteLength!==4)throw new T("IPv4 address was incorrect length");let e=[];for(let t=0;t<r.byteLength;t++)e.push(r[t]);return e.join(".")},mn=function(r){if(r.byteLength!==16)throw new T("IPv6 address was incorrect length");let e=[];for(let n=0;n<r.byteLength;n+=2){let o=r[n],s=r[n+1],i=`${o.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}`;e.push(i)}let t=e.join(":");try{let n=new URL(`http://[${t}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new T(`Invalid IPv6 address "${t}"`)}};function gn(r){try{let e=new URL(`http://[${r}]`);return e.hostname.substring(1,e.hostname.length-1)}catch{throw new T(`Invalid IPv6 address "${r}"`)}}var or=Object.values(Ue).map(r=>r.decoder),bs=(function(){let r=or[0].or(or[1]);return or.slice(2).forEach(e=>r=r.or(e)),r})();function bn(r){return bs.decode(r)}function wn(r){return e=>r.encoder.encode(e)}function ws(r){if(parseInt(r).toString()!==r)throw new G("Value must be an integer")}function ys(r){if(r<0)throw new G("Value must be a positive integer, or zero")}function xs(r){return e=>{if(e>r)throw new G(`Value must be smaller than or equal to ${r}`)}}function Es(...r){return e=>{for(let t of r)t(e)}}var Re=Es(ws,ys,xs(65535));var D=-1,ur=class{protocolsByCode=new Map;protocolsByName=new Map;getProtocol(e){let t;if(typeof e=="string"?t=this.protocolsByName.get(e):t=this.protocolsByCode.get(e),t==null)throw new Ye(`Protocol ${e} was unknown`);return t}addProtocol(e){this.protocolsByCode.set(e.code,e),this.protocolsByName.set(e.name,e),e.aliases?.forEach(t=>{this.protocolsByName.set(t,e)})}removeProtocol(e){let t=this.protocolsByCode.get(e);t!=null&&(this.protocolsByCode.delete(t.code),this.protocolsByName.delete(t.name),t.aliases?.forEach(n=>{this.protocolsByName.delete(n)}))}},J=new ur,Us=[{code:4,name:"ip4",size:32,valueToBytes:cr,bytesToValue:pn,validate:r=>{if(!(0,N.isIPv4)(r))throw new G(`Invalid IPv4 address "${r}"`)}},{code:6,name:"tcp",size:16,valueToBytes:ie,bytesToValue:Ee,validate:Re},{code:273,name:"udp",size:16,valueToBytes:ie,bytesToValue:Ee,validate:Re},{code:33,name:"dccp",size:16,valueToBytes:ie,bytesToValue:Ee,validate:Re},{code:41,name:"ip6",size:128,valueToBytes:dn,bytesToValue:mn,stringToValue:gn,validate:r=>{if(!(0,N.isIPv6)(r))throw new G(`Invalid IPv6 address "${r}"`)}},{code:42,name:"ip6zone",size:D},{code:43,name:"ipcidr",size:8,bytesToValue:sr("base10"),valueToBytes:ir("base10")},{code:53,name:"dns",size:D},{code:54,name:"dns4",size:D},{code:55,name:"dns6",size:D},{code:56,name:"dnsaddr",size:D},{code:132,name:"sctp",size:16,valueToBytes:ie,bytesToValue:Ee,validate:Re},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:D,stringToValue:r=>decodeURIComponent(r),valueToString:r=>encodeURIComponent(r)},{code:421,name:"p2p",aliases:["ipfs"],size:D,bytesToValue:sr("base58btc"),valueToBytes:r=>r.startsWith("Q")||r.startsWith("1")?ir("base58btc")(r):ye.parse(r).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:ar,valueToBytes:fn},{code:445,name:"onion3",size:296,bytesToValue:ar,valueToBytes:hn},{code:446,name:"garlic64",size:D},{code:447,name:"garlic32",size:D},{code:448,name:"tls"},{code:449,name:"sni",size:D},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:D,bytesToValue:wn(Ht),valueToBytes:bn},{code:480,name:"http"},{code:481,name:"http-path",size:D,stringToValue:r=>`/${decodeURIComponent(r)}`,valueToString:r=>encodeURIComponent(r.substring(1))},{code:443,name:"https"},{code:477,name:"ws"},{code:478,name:"wss"},{code:479,name:"p2p-websocket-star"},{code:277,name:"p2p-stardust"},{code:275,name:"p2p-webrtc-star"},{code:276,name:"p2p-webrtc-direct"},{code:280,name:"webrtc-direct"},{code:281,name:"webrtc"},{code:290,name:"p2p-circuit"},{code:777,name:"memory",size:D}];Us.forEach(r=>{J.addProtocol(r)});function yn(r){let e=[],t=0;for(;t<r.length;){let n=Bt(r,t),o=J.getProtocol(n),s=de(n),i=Rs(o,r,t+s),a=0;i>0&&o.size===D&&(a=de(i));let c=s+a+i,l={code:n,name:o.name,bytes:Nt(r.subarray(t,t+c))};if(i>0){let f=t+s+a,h=r.subarray(f,f+i);l.value=o.bytesToValue?.(h)??ne(h)}e.push(l),t+=c}return e}function xn(r){let e=0,t=[];for(let n of r){if(n.bytes==null){let o=J.getProtocol(n.code),s=de(n.code),i,a=0,c=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??xe(n.value),a=i.byteLength,o.size===D&&(c=de(a)));let l=new Uint8Array(s+c+a),f=0;_t(n.code,l,f),f+=s,i!=null&&(o.size===D&&(_t(a,l,f),f+=c),l.set(i,f)),n.bytes=l}t.push(n.bytes),e+=n.bytes.byteLength}return Q(t,e)}function En(r){if(r.charAt(0)!=="/")throw new T('String multiaddr must start with "/"');let e=[],t="protocol",n="",o="";for(let s=1;s<r.length;s++){let i=r.charAt(s);i!=="/"&&(t==="protocol"?o+=r.charAt(s):n+=r.charAt(s));let a=s===r.length-1;if(i==="/"||a){let c=J.getProtocol(o);if(t==="protocol"){if(c.size==null||c.size===0){e.push({code:c.code,name:c.name}),n="",o="",t="protocol";continue}else if(a)throw new T(`Component ${o} was missing value`);t="value"}else if(t==="value"){let l={code:c.code,name:c.name};if(c.size!=null&&c.size!==0){if(n==="")throw new T(`Component ${o} was missing value`);l.value=c.stringToValue?.(n)??n}e.push(l),n="",o="",t="protocol"}}}if(o!==""&&n!=="")throw new T("Incomplete multiaddr");return e}function vn(r){return`/${r.flatMap(e=>{if(e.value==null)return e.name;let t=J.getProtocol(e.code);if(t==null)throw new T(`Unknown protocol code ${e.code}`);return[e.name,t.valueToString?.(e.value)??e.value]}).join("/")}`}function Rs(r,e,t){return r.size==null||r.size===0?0:r.size>0?r.size/8:Bt(e,t)}var Ms=Symbol.for("nodejs.util.inspect.custom"),vr=Symbol.for("@multiformats/multiaddr");function ks(r){if(r==null&&(r="/"),Cn(r))return r.getComponents();if(r instanceof Uint8Array)return yn(r);if(typeof r=="string")return r=r.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),r===""&&(r="/"),En(r);if(Array.isArray(r))return r;throw new T("Must be a string, Uint8Array, Component[], or another Multiaddr")}var at=class r{[vr]=!0;#e;#t;#r;constructor(e="/",t={}){this.#e=ks(e),t.validate!==!1&&Vs(this)}get bytes(){return this.#r==null&&(this.#r=xn(this.#e)),this.#r}toString(){return this.#t==null&&(this.#t=vn(this.#e)),this.#t}toJSON(){return this.toString()}getComponents(){return[...this.#e.map(e=>({...e}))]}encapsulate(e){let t=new r(e);return new r([...this.#e,...t.getComponents()],{validate:!1})}decapsulate(e){let t=e.toString(),n=this.toString(),o=n.lastIndexOf(t);if(o<0)throw new Ke(`Address ${this.toString()} does not contain subaddress: ${t}`);return new r(n.slice(0,o),{validate:!1})}decapsulateCode(e){let t;for(let n=this.#e.length-1;n>-1;n--)if(this.#e[n].code===e){t=n;break}return new r(this.#e.slice(0,t),{validate:!1})}equals(e){return Ae(this.bytes,e.bytes)}[Ms](){return`Multiaddr(${this.toString()})`}};function Vs(r){r.getComponents().forEach(e=>{let t=J.getProtocol(e.code);e.value!=null&&t.validate?.(e.value)})}function Cn(r){return!!r?.[vr]}function ce(r){return new at(r)}var x=r=>({match:e=>{let t=e[0];return t==null||t.code!==r||t.value!=null?!1:e.slice(1)}}),u=(r,e)=>({match:t=>{let n=t[0];return n?.code!==r||n.value==null||e!=null&&n.value!==e?!1:t.slice(1)}}),Sn=r=>({match:e=>r.match(e)===!1?e:!1}),d=r=>({match:e=>{let t=r.match(e);return t===!1?e:t}}),A=(...r)=>({match:e=>{let t;for(let n of r){let o=n.match(e);o!==!1&&(t==null||o.length<t.length)&&(t=o)}return t??!1}}),g=(...r)=>({match:e=>{for(let t of r){let n=t.match(e);if(n===!1)return!1;e=n}return e}});function E(...r){function e(o){if(o==null)return!1;let s=o.getComponents();for(let i of r){let a=i.match(s);if(a===!1)return!1;s=a}return s}function t(o){return e(o)!==!1}function n(o){let s=e(o);return s===!1?!1:s.length===0}return{matchers:r,matches:t,exactMatch:n}}var zs=u(421),Hc=E(zs),ut=u(54),lt=u(55),ft=u(56),Sr=u(53),Qc=E(ut,d(u(421))),Gc=E(lt,d(u(421))),Xc=E(ft,d(u(421))),Jc=E(A(Sr,ft,ut,lt),d(u(421))),Dn=g(u(4),d(u(43))),In=g(d(u(42)),u(41),d(u(43))),Dr=A(Dn,In),De=A(Dr,Sr,ut,lt,ft),Kc=E(A(Dr,g(A(Sr,ft,ut,lt),d(u(421))))),Yc=E(Dn),Zc=E(In),eu=E(Dr),Ir=g(De,u(6)),ke=g(De,u(273)),Tn=E(g(Ir,d(u(421)))),tu=E(ke),Tr=g(ke,x(460),d(u(421))),ht=g(ke,x(461),d(u(421))),$s=A(Tr,ht),ru=E(Tr),nu=E(ht),Cr=A(De,Ir,ke,Tr,ht),Ln=A(g(Cr,x(477),d(u(421)))),ou=E(Ln),An=A(g(Cr,x(478),d(u(421))),g(Cr,x(448),d(u(449)),x(477),d(u(421)))),su=E(An),Pn=g(ke,x(280),d(u(466)),d(u(466)),d(u(421))),iu=E(Pn),On=g(ht,x(465),d(u(466)),d(u(466)),d(u(421))),au=E(On),ct=A(Ln,An,g(Ir,d(u(421))),g($s,d(u(421))),g(De,d(u(421))),Pn,On,u(421)),cu=E(ct),Fs=g(d(ct),x(290),Sn(x(281)),d(u(421))),uu=E(Fs),Ws=A(g(ct,x(290),x(281),d(u(421))),g(ct,x(281),d(u(421))),g(x(281),d(u(421)))),lu=E(Ws),js=g(De,A(g(u(6,"80")),g(u(6),x(480)),x(480)),d(u(481)),d(u(421))),fu=E(js),qs=g(De,A(g(u(6,"443")),g(u(6,"443"),x(480)),g(u(6),x(443)),g(u(6),x(448),x(480)),g(x(448),x(480)),x(448),x(443)),d(u(481)),d(u(421))),hu=E(qs),Hs=A(g(u(777),d(u(421)))),du=E(Hs),Qs=A(g(u(400),d(u(421)))),dt=E(Qs);var pt=class extends Event{type;detail;constructor(e,t){super(e),this.type=e,this.detail=t}};var Wn=ue(k("node:net"),1);var Bn=Symbol.for("@achingbrain/uint8arraylist");function _n(r,e){if(e==null||e<0)throw new RangeError("index is out of bounds");let t=0;for(let n of r){let o=t+n.byteLength;if(e<o)return{buf:n,index:e-t};t=o}throw new RangeError("index is out of bounds")}function mt(r){return!!r?.[Bn]}var Ie=class r{bufs;length;[Bn]=!0;constructor(...e){this.bufs=[],this.length=0,e.length>0&&this.appendAll(e)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...e){this.appendAll(e)}appendAll(e){let t=0;for(let n of e)if(n instanceof Uint8Array)t+=n.byteLength,this.bufs.push(n);else if(mt(n)){t+=n.byteLength;for(let o of n.bufs)this.bufs.push(o)}else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=t}prepend(...e){this.prependAll(e)}prependAll(e){let t=0;for(let n of e.reverse())if(n instanceof Uint8Array)t+=n.byteLength,this.bufs.unshift(n);else if(mt(n))t+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=t}get(e){let t=_n(this.bufs,e);return t.buf[t.index]}set(e,t){let n=_n(this.bufs,e);n.buf[n.index]=t}write(e,t=0){if(e instanceof Uint8Array)for(let n=0;n<e.length;n++)this.set(t+n,e[n]);else if(mt(e))for(let n=0;n<e.length;n++)this.set(t+n,e.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(e){if(e=Math.trunc(e),!(Number.isNaN(e)||e<=0)){if(e===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(e>=this.bufs[0].byteLength)e-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(e),this.length-=e;break}}}slice(e,t){let{bufs:n,length:o}=this._subList(e,t);return Q(n,o)}subarray(e,t){let{bufs:n,length:o}=this._subList(e,t);return n.length===1?n[0]:Q(n,o)}sublist(e,t){let{bufs:n,length:o}=this._subList(e,t),s=new r;return s.length=o,s.bufs=n,s}_subList(e,t){if(e=e??0,t=t??this.length,e<0&&(e=this.length+e),t<0&&(t=this.length+t),e<0||t>this.length)throw new RangeError("index is out of bounds");if(e===t)return{bufs:[],length:0};if(e===0&&t===this.length)return{bufs:[...this.bufs],length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],a=o,c=a+i.byteLength;if(o=c,e>=c)continue;let l=e>=a&&e<c,f=t>a&&t<=c;if(l&&f){if(e===a&&t===c){n.push(i);break}let h=e-a;n.push(i.subarray(h,h+(t-e)));break}if(l){if(e===0){n.push(i);continue}n.push(i.subarray(e-a));continue}if(f){if(t===c){n.push(i);break}n.push(i.subarray(0,t-a));break}n.push(i)}return{bufs:n,length:t-e}}indexOf(e,t=0){if(!mt(e)&&!(e instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=e instanceof Uint8Array?e:e.subarray();if(t=Number(t??0),isNaN(t)&&(t=0),t<0&&(t=this.length+t),t<0&&(t=0),e.length===0)return t>this.length?this.length:t;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let h=0;h<s;h++)i[h]=-1;for(let h=0;h<o;h++)i[n[h]]=h;let a=i,c=this.byteLength-n.byteLength,l=n.byteLength-1,f;for(let h=t;h<=c;h+=f){f=0;for(let b=l;b>=0;b--){let p=this.get(h+b);if(n[b]!==p){f=Math.max(1,b-a[p]);break}}if(f===0)return h}return-1}getInt8(e){let t=this.subarray(e,e+1);return new DataView(t.buffer,t.byteOffset,t.byteLength).getInt8(0)}setInt8(e,t){let n=ee(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,t),this.write(n,e)}getInt16(e,t){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,t)}setInt16(e,t,n){let o=j(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,t,n),this.write(o,e)}getInt32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,t)}setInt32(e,t,n){let o=j(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,t,n),this.write(o,e)}getBigInt64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,t)}setBigInt64(e,t,n){let o=j(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,t,n),this.write(o,e)}getUint8(e){let t=this.subarray(e,e+1);return new DataView(t.buffer,t.byteOffset,t.byteLength).getUint8(0)}setUint8(e,t){let n=ee(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,t),this.write(n,e)}getUint16(e,t){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,t)}setUint16(e,t,n){let o=j(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,t,n),this.write(o,e)}getUint32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,t)}setUint32(e,t,n){let o=j(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,t,n),this.write(o,e)}getBigUint64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,t)}setBigUint64(e,t,n){let o=j(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,t,n),this.write(o,e)}getFloat32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,t)}setFloat32(e,t,n){let o=j(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,t,n),this.write(o,e)}getFloat64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,t)}setFloat64(e,t,n){let o=j(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,t,n),this.write(o,e)}equals(e){if(e==null||!(e instanceof r)||e.bufs.length!==this.bufs.length)return!1;for(let t=0;t<this.bufs.length;t++)if(!Ae(this.bufs[t],e.bufs[t]))return!1;return!0}static fromUint8Arrays(e,t){let n=new r;return n.bufs=e,t==null&&(t=e.reduce((o,s)=>o+s.byteLength,0)),n.length=t,n}};function Gs(r){let e=r.getComponents(),t={},n=0;return e[n]?.name==="ip6zone"&&(t.zone=`${e[n].value}`,n++),e[n]?.name==="ip4"||e[n]?.name==="ip6"||e[n]?.name==="dns"||e[n]?.name==="dns4"||e[n]?.name==="dns6"?(t.type=e[n].name,t.host=e[n].value,n++):e[n]?.name==="dnsaddr"&&(t.type=e[n].name,t.host=`_dnsaddr.${e[n].value}`,n++),(e[n]?.name==="tcp"||e[n]?.name==="udp")&&(t.protocol=e[n].name==="tcp"?"tcp":"udp",t.port=parseInt(`${e[n].value}`),n++),e[n]?.name==="ipcidr"&&(t.type==="ip4"?t.cidr=parseInt(`${e[n].value}`):t.type==="ip6"&&(t.cidr=`${e[n].value}`),n++),t.type==null||t.host==null?null:(e[n]?.name==="tls"&&e[n+1]?.name==="sni"&&(t.sni=e[n+1].value,n+=2),t)}function gt(r){let e=Gs(r);if(e==null)throw new _(`Multiaddr ${r} was not an IPv4, IPv6, DNS, DNS4, DNS6 or DNSADDR address`);return e}function bt(){let r={};return r.promise=new Promise((e,t)=>{r.resolve=e,r.reject=t}),r}var wt=class{buffer;mask;top;btm;next;constructor(e){if(!(e>0)||(e-1&e)!==0)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(e),this.mask=e-1,this.top=0,this.btm=0,this.next=null}push(e){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=e,this.top=this.top+1&this.mask,!0)}shift(){let e=this.buffer[this.btm];if(e!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,e}isEmpty(){return this.buffer[this.btm]===void 0}},Te=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new wt(this.hwm),this.tail=this.head,this.size=0}calculateSize(e){return e?.byteLength!=null?e.byteLength:1}push(e){if(e?.value!=null&&(this.size+=this.calculateSize(e.value)),!this.head.push(e)){let t=this.head;this.head=t.next=new wt(2*this.head.buffer.length),this.head.push(e)}}shift(){let e=this.tail.shift();if(e===void 0&&this.tail.next!=null){let t=this.tail.next;this.tail.next=null,this.tail=t,e=this.tail.shift()}return e?.value!=null&&(this.size-=this.calculateSize(e.value)),e}isEmpty(){return this.head.isEmpty()}};var Lr=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.code=t??"ABORT_ERR"}};function Nn(r={}){return Xs(t=>{let n=t.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},r)}function Xs(r,e){e=e??{};let t=e.onEnd,n=new Te,o,s,i,a=bt(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((y,m)=>{s=S=>{s=null,n.push(S);try{y(r(n))}catch(O){m(O)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=bt()})}},l=y=>s!=null?s(y):(n.push(y),o),f=y=>(n=new Te,s!=null?s({error:y}):(n.push({error:y}),o)),h=y=>{if(i)return o;if(e?.objectMode!==!0&&y?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return l({done:!1,value:y})},b=y=>i?o:(i=!0,y!=null?f(y):l({done:!0})),p=()=>(n=new Te,b(),{done:!0}),$=y=>(b(y),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:p,throw:$,push:h,end:b,get readableLength(){return n.size},onEmpty:async y=>{let m=y?.signal;if(m?.throwIfAborted(),n.isEmpty())return;let S,O;m!=null&&(S=new Promise((U,R)=>{O=()=>{R(new Lr)},m.addEventListener("abort",O)}));try{await Promise.race([a.promise,S])}finally{O!=null&&m!=null&&m?.removeEventListener("abort",O)}}},t==null)return o;let V=o;return o={[Symbol.asyncIterator](){return this},next(){return V.next()},throw(y){return V.throw(y),t!=null&&(t(y),t=void 0),{done:!0}},return(){return V.return(),t!=null&&(t(),t=void 0),{done:!0}},push:h,end(y){return V.end(y),t!=null&&(t(y),t=void 0),o},get readableLength(){return V.readableLength},onEmpty:y=>V.onEmpty(y)},o}var Ar=class r extends Error{name="TimeoutError";constructor(e,t){super(e,t),Error.captureStackTrace?.(this,r)}},Un=r=>r.reason??new DOMException("This operation was aborted.","AbortError");function Pr(r,e){let{milliseconds:t,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout},signal:i}=e,a,c,f=new Promise((h,b)=>{if(typeof t!="number"||Math.sign(t)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${t}\``);if(i?.aborted){b(Un(i));return}if(i&&(c=()=>{b(Un(i))},i.addEventListener("abort",c,{once:!0})),r.then(h,b),t===Number.POSITIVE_INFINITY)return;let p=new Ar;a=s.setTimeout.call(void 0,()=>{if(n){try{h(n())}catch($){b($)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?h():o instanceof Error?b(o):(p.message=o??`Promise timed out after ${t} milliseconds`,b(p))},t)}).finally(()=>{f.clear(),c&&i&&i.removeEventListener("abort",c)});return f.clear=()=>{s.clearTimeout.call(void 0,a),a=void 0},f}var Js=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 Ks(r,e,t){let n,o=new Promise((s,i)=>{if(t={rejectionEvents:["error"],multiArgs:!1,rejectionMultiArgs:!1,resolveImmediately:!1,...t},!(t.count>=0&&(t.count===Number.POSITIVE_INFINITY||Number.isInteger(t.count))))throw new TypeError("The `count` option should be at least 0 or more");t.signal?.throwIfAborted();let a=[e].flat(),c=[],{addListener:l,removeListener:f}=Js(r),h=async(...p)=>{let $=t.multiArgs?p:p[0];if(t.filter)try{if(!await t.filter($))return}catch(V){n(),i(V);return}c.push($),t.count===c.length&&(n(),s(c))},b=(...p)=>{n(),i(t.rejectionMultiArgs?p:p[0])};n=()=>{for(let p of a)f(p,h);for(let p of t.rejectionEvents)a.includes(p)||f(p,b)};for(let p of a)l(p,h);for(let p of t.rejectionEvents)a.includes(p)||l(p,b);t.signal&&t.signal.addEventListener("abort",()=>{b(t.signal.reason)},{once:!0}),t.resolveImmediately&&s(c)});if(o.cancel=n,typeof t.timeout=="number"){let s=Pr(o,{milliseconds:t.timeout});return s.cancel=()=>{n(),s.clear()},s}return o}function oe(r,e,t){typeof t=="function"&&(t={filter:t}),t={...t,count:1,resolveImmediately:!1};let n=Ks(r,e,t),o=n.then(s=>s[0]);return o.cancel=n.cancel,o}var yt=class extends Error{static name="StreamClosedError";name="StreamClosedError"};function Ys(r){return r.reason}async function Rn(r,e,t){if(e==null)return r;let n=t?.translateError??Ys;if(e.aborted)return r.catch(()=>{}),Promise.reject(n(e));let o;try{return await Promise.race([r,new Promise((s,i)=>{o=()=>{i(n(e))},e.addEventListener("abort",o)})])}finally{o!=null&&e.removeEventListener("abort",o)}}var Zs=Math.pow(2,20)*4,xt=class extends he{status;timeline;inactivityTimeout;maxReadBufferLength;maxWriteBufferLength;log;direction;maxMessageSize;readStatus;writeStatus;remoteReadStatus;remoteWriteStatus;writableNeedsDrain;readBuffer;writeBuffer;sendingData;onDrainPromise;constructor(e){super(),this.status="open",this.log=e.log,this.direction=e.direction??"outbound",this.inactivityTimeout=e.inactivityTimeout??12e4,this.maxReadBufferLength=e.maxReadBufferLength??Zs,this.maxWriteBufferLength=e.maxWriteBufferLength,this.maxMessageSize=e.maxMessageSize,this.readBuffer=new Ie,this.writeBuffer=new Ie,this.readStatus="readable",this.remoteReadStatus="readable",this.writeStatus="writable",this.remoteWriteStatus="writable",this.sendingData=!1,this.writableNeedsDrain=!1,this.timeline={open:Date.now()},this.processSendQueue=this.processSendQueue.bind(this);let t=()=>{this.writableNeedsDrain&&(this.log.trace("drain event received, continue sending data"),this.writableNeedsDrain=!1,queueMicrotask(()=>{try{this.processSendQueue()}catch(o){this.log.error("processSendQueue threw - %e",o)}})),this.onDrainPromise?.resolve()};this.addEventListener("drain",t);let n=o=>{this.onDrainPromise?.reject(o.error??new yt)};this.addEventListener("close",n)}get readBufferLength(){return this.readBuffer.byteLength}get writeBufferLength(){return this.writeBuffer.byteLength}async onDrain(e){return this.writableNeedsDrain!==!0?Promise.resolve():(this.onDrainPromise==null&&(this.onDrainPromise=Promise.withResolvers()),Rn(this.onDrainPromise.promise,e?.signal))}async*[Symbol.asyncIterator](){if(this.readStatus!=="readable"&&this.readStatus!=="paused")return;let e=Nn(),t=s=>{e.push(s.data)};this.addEventListener("message",t);let n=s=>{e.end(s.error)};this.addEventListener("close",n);let o=()=>{e.end()};this.addEventListener("remoteCloseWrite",o);try{yield*e}finally{this.removeEventListener("message",t),this.removeEventListener("close",n),this.removeEventListener("remoteCloseWrite",o)}}isReadable(){return this.status==="open"}send(e){if(this.writeStatus==="closed"||this.writeStatus==="closing")throw new Y(`Cannot write to a stream that is ${this.writeStatus}`);return this.log.trace("append %d bytes to write buffer",e.byteLength),this.writeBuffer.append(e),this.processSendQueue()}abort(e){if(!(this.status==="aborted"||this.status==="reset"||this.status==="closed")){this.log.error("abort with error - %e",e),this.status="aborted",this.readBuffer.byteLength>0&&this.readBuffer.consume(this.readBuffer.byteLength),this.writeBuffer.byteLength>0&&(this.writeBuffer.consume(this.writeBuffer.byteLength),this.safeDispatchEvent("idle")),this.writeStatus="closed",this.remoteWriteStatus="closed",this.readStatus="closed",this.remoteReadStatus="closed",this.timeline.close=Date.now();try{this.sendReset(e)}catch(t){this.log("failed to send reset to remote - %e",t)}this.dispatchEvent(new He(e))}}pause(){if(this.readStatus==="closed"||this.readStatus==="closing")throw new Y("Cannot pause a stream that is closing/closed");this.readStatus!=="paused"&&(this.readStatus="paused",this.sendPause())}resume(){if(this.readStatus==="closed"||this.readStatus==="closing")throw new Y("Cannot resume a stream that is closing/closed");this.readStatus!=="readable"&&(this.readStatus="readable",this.dispatchReadBuffer(),this.sendResume())}push(e){if(this.readStatus==="closed"||this.readStatus==="closing")throw new Y(`Cannot push data onto a stream that is ${this.readStatus}`);if(e.byteLength!==0){if(this.readBuffer.append(e),this.readStatus==="paused"||this.listenerCount("message")===0){this.checkReadBufferLength();return}setTimeout(()=>{this.dispatchReadBuffer()},0)}}unshift(e){if(this.readStatus==="closed"||this.readStatus==="closing")throw new Y(`Cannot push data onto a stream that is ${this.readStatus}`);if(e.byteLength!==0){if(this.readBuffer.prepend(e),this.readStatus==="paused"||this.listenerCount("message")===0){this.checkReadBufferLength();return}setTimeout(()=>{this.dispatchReadBuffer()},0)}}onData(e){if(e.byteLength!==0){if(this.readStatus==="closing"||this.readStatus==="closed"){this.log("ignoring data - read status %s",this.readStatus);return}this.readBuffer.append(e),this.dispatchReadBuffer()}}addEventListener(...e){super.addEventListener.apply(this,e),e[0]==="message"&&this.readBuffer.byteLength>0&&queueMicrotask(()=>{this.dispatchReadBuffer()})}onRemoteReset(){this.log("remote reset"),this.status="reset",this.writeStatus="closed",this.remoteWriteStatus="closed",this.remoteReadStatus="closed",this.timeline.close=Date.now(),this.readBuffer.byteLength===0&&(this.readStatus="closed");let e=new Fe;this.dispatchEvent(new Qe(e))}onTransportClosed(e){this.log("transport closed"),this.readStatus==="readable"&&this.readBuffer.byteLength===0&&(this.log("close readable end after transport closed and read buffer is empty"),this.readStatus="closed"),this.remoteReadStatus!=="closed"&&(this.remoteReadStatus="closed"),this.remoteWriteStatus!=="closed"&&(this.remoteWriteStatus="closed"),this.writeStatus!=="closed"&&(this.writeStatus="closed"),e!=null?this.abort(e):(this.status==="open"||this.status==="closing")&&(this.timeline.close=Date.now(),this.status="closed",this.writeStatus="closed",this.remoteWriteStatus="closed",this.remoteReadStatus="closed",this.dispatchEvent(new fe))}onRemoteCloseWrite(){this.remoteWriteStatus!=="closed"&&(this.log.trace("on remote close write"),this.remoteWriteStatus="closed",this.safeDispatchEvent("remoteCloseWrite"),this.writeStatus==="closed"&&this.onTransportClosed())}onRemoteCloseRead(){this.log.trace("on remote close read"),this.remoteReadStatus="closed",this.writeBuffer.byteLength>0&&(this.writeBuffer.consume(this.writeBuffer.byteLength),this.safeDispatchEvent("idle"))}processSendQueue(){if(this.writableNeedsDrain)return this.log.trace("not processing send queue as drain is required"),this.checkWriteBufferLength(),!1;if(this.writeBuffer.byteLength===0)return this.log.trace("not processing send queue as no bytes to send"),!0;if(this.sendingData)return this.log.trace("not processing send queue as already sending data"),!0;if(this.writeStatus!=="writable"&&this.writeStatus!=="closing")return this.log.trace("not processing send queue as stream is %s",this.writeStatus),!1;this.sendingData=!0,this.log.trace("processing send queue with %d queued bytes",this.writeBuffer.byteLength);try{let e=!0,t=this.writeBuffer.byteLength,n=0;for(;this.writeBuffer.byteLength>0;){let o=Math.min(this.maxMessageSize??this.writeBuffer.byteLength,this.writeBuffer.byteLength);if(o===0){e=!1;break}let s=this.writeBuffer.sublist(0,o),i=new Ie(s);this.writeBuffer.consume(s.byteLength);let a;try{a=this.sendData(s)}catch(c){throw this.writeBuffer.prepend(i),this.abort(c),c}if(e=a.canSendMore,n+=a.sentBytes,a.sentBytes!==i.byteLength&&(i.consume(a.sentBytes),this.writeBuffer.prepend(i)),!e)break}return e||(this.log.trace("sent %d/%d bytes, pausing sending because underlying stream is full, %d bytes left in the write buffer",n,t,this.writeBuffer.byteLength),this.writableNeedsDrain=!0,this.checkWriteBufferLength()),this.writeBuffer.byteLength===0&&this.safeDispatchEvent("idle"),e}finally{this.sendingData=!1}}dispatchReadBuffer(){try{if(this.listenerCount("message")===0){this.log.trace("not dispatching pause buffer as there are no listeners for the message event");return}if(this.readBuffer.byteLength===0){this.log.trace("not dispatching pause buffer as there is no data to dispatch");return}if(this.readStatus==="paused"){this.log.trace("not dispatching pause buffer we are paused");return}if(this.readStatus==="closing"||this.readStatus==="closed"){this.log("dropping %d bytes because the readable end is %s",this.readBuffer.byteLength,this.readStatus),this.readBuffer.consume(this.readBuffer.byteLength);return}let e=this.readBuffer.sublist();this.readBuffer.consume(e.byteLength),this.dispatchEvent(new qe(e))}finally{this.readBuffer.byteLength===0&&this.remoteWriteStatus==="closed"&&(this.log("close readable end after dispatching read buffer and remote writable end is closed"),this.readStatus="closed"),this.checkReadBufferLength()}}checkReadBufferLength(){this.readBuffer.byteLength>this.maxReadBufferLength&&this.abort(new Le(`Read buffer length of ${this.readBuffer.byteLength} exceeded limit of ${this.maxReadBufferLength}, read status is ${this.readStatus}`))}checkWriteBufferLength(){this.maxWriteBufferLength!=null&&this.writeBuffer.byteLength>this.maxWriteBufferLength&&this.abort(new Le(`Write buffer length of ${this.writeBuffer.byteLength} exceeded limit of ${this.maxWriteBufferLength}, write status is ${this.writeStatus}`))}onMuxerNeedsDrain(){this.writableNeedsDrain=!0}onMuxerDrain(){this.safeDispatchEvent("drain")}};var Et=class extends xt{remoteAddr;metricPrefix;metrics;constructor(e){super(e),this.metricPrefix=e.metricPrefix??"",this.metrics=e.metrics,this.remoteAddr=e.remoteAddr,this.addEventListener("close",t=>{this.metrics?.increment({[`${this.metricPrefix}end`]:!0}),t.error!=null?t.local?this.metrics?.increment({[`${this.metricPrefix}abort`]:!0}):this.metrics?.increment({[`${this.metricPrefix}reset`]:!0}):t.local?this.metrics?.increment({[`${this.metricPrefix}_local_close`]:!0}):this.metrics?.increment({[`${this.metricPrefix}_remote_close`]:!0})})}async close(e){this.status==="open"&&(this.status="closing",this.writeStatus="closing",this.remoteWriteStatus="closing",this.remoteReadStatus="closing",(this.sendingData||this.writeBuffer.byteLength>0)&&(this.log("waiting for write queue to become idle before closing writable end of stream, %d unsent bytes",this.writeBuffer.byteLength),await oe(this,"idle",{...e,rejectionEvents:["close"]})),this.writableNeedsDrain&&(this.log("waiting for write queue to drain before closing writable end of stream, %d unsent bytes",this.writeBuffer.byteLength),await oe(this,"drain",{...e,rejectionEvents:["close"]})),await this.sendClose(e),this.onTransportClosed())}};var kn=ue(k("node:os"),1);function Mn(r){return!!(r.startsWith("169.254.")||r.toLowerCase().startsWith("fe80"))}function Or(r,e,t){let n=[r.type,t??r.host];if(r.protocol!=null){let o=e??r.port;o!=null&&n.push(r.protocol,o)}return r.type==="ip6"&&r.zone!=null&&n.unshift("ip6zone",r.zone),r.cidr!=null&&n.push("ipcidr",r.cidr),ce(`/${n.join("/")}`)}var ei={4:"IPv4",6:"IPv6"};function ti(r){return["0.0.0.0","::"].includes(r)}function ri(r){let e=[],t=kn.default.networkInterfaces();for(let[,n]of Object.entries(t))if(n!=null)for(let o of n)Mn(o.address)||o.family===ei[r]&&e.push(o.address);return e}function Vn(r,e){if(r==null)return[];let t=gt(r);return(t.type==="ip4"||t.type==="ip6")&&ti(t.host)?ri(t.type==="ip4"?4:6).map(n=>Or(t,e,n)):[Or(t,e)]}function zn(r,e){if(typeof r!="string")throw new _(`invalid ip provided: ${r}`);if(typeof e=="string"&&(e=parseInt(e)),isNaN(e))throw new _(`invalid port provided: ${e}`);if((0,N.isIPv4)(r))return ce(`/ip4/${r}/tcp/${e}`);if((0,N.isIPv6)(r))return ce(`/ip6/${r}/tcp/${e}`);throw new _(`invalid ip:port for creating a multiaddr: ${r}:${e}`)}var _r=class extends Et{socket;constructor(e){let t=e.remoteAddr;if(e.localAddr!=null&&dt.matches(e.localAddr))t=e.localAddr;else if(t==null){if(e.socket.remoteAddress==null||e.socket.remotePort==null)throw new _("Could not determine remote address or port");t=zn(e.socket.remoteAddress,e.socket.remotePort)}super({...e,remoteAddr:t}),this.socket=e.socket,this.socket.on("data",n=>{this.onData(n)}),this.socket.on("error",n=>{this.log("tcp error",t,n),this.abort(n)}),this.socket.setTimeout(e.inactivityTimeout??120*1e3),this.socket.once("timeout",()=>{this.log("tcp timeout",t),this.abort(new le)}),this.socket.once("end",()=>{this.log("tcp end",t),this.onTransportClosed()}),this.socket.once("close",n=>{if(this.log("tcp close",t),n){this.abort(new Error("TCP transmission error"));return}this.onTransportClosed()}),this.socket.on("drain",()=>{this.log("tcp drain"),this.safeDispatchEvent("drain")})}sendData(e){let t=0,n=!0;for(let o of e)if(t+=o.byteLength,n=this.socket.write(o),!n)break;return{sentBytes:t,canSendMore:n}}async sendClose(e){this.socket.destroyed||(this.socket.destroySoon(),await oe(this.socket,"close",e))}sendReset(){this.socket.resetAndDestroy()}sendPause(){this.socket.pause()}sendResume(){this.socket.resume()}},vt=r=>new _r(r);var $n=ue(k("os"),1),Fn=ue(k("path"),1);function Ct(r,e={}){if(dt.exactMatch(r)){let s=r.getComponents().find(i=>i.code===400)?.value;if(s==null)throw new _(`Multiaddr ${r} was not a Unix address`);return $n.default.platform()==="win32"?{path:Fn.default.join("\\\\.\\pipe\\",s)}:{path:s}}let t=gt(r),n=t.host,o=t.port;return{host:n,port:o,ipv6Only:t.type==="ip6",...e}}var I;(function(r){r[r.INACTIVE=0]="INACTIVE",r[r.ACTIVE=1]="ACTIVE",r[r.PAUSED=2]="PAUSED"})(I||(I={}));var St=class extends he{context;server;sockets=new Set;status={code:I.INACTIVE};metrics;addr;log;shutdownController;constructor(e){if(super(),this.context=e,e.keepAlive=e.keepAlive??!0,e.noDelay=e.noDelay??!0,e.allowHalfOpen=e.allowHalfOpen??!1,this.shutdownController=new AbortController,Ge(1/0,this.shutdownController.signal),this.log=e.logger.forComponent("libp2p:tcp:listener"),this.addr="unknown",this.server=Wn.default.createServer(e,this.onSocket.bind(this)),e.maxConnections!==void 0&&(this.server.maxConnections=e.maxConnections),e.closeServerOnMaxConnections!=null&&e.closeServerOnMaxConnections.closeAbove<e.closeServerOnMaxConnections.listenBelow)throw new _("closeAbove must be >= listenBelow");e.metrics?.registerMetricGroup("libp2p_tcp_inbound_connections_total",{label:"address",help:"Current active connections in TCP listener",calculate:()=>({[this.addr]:this.sockets.size})}),this.metrics={status:e.metrics?.registerMetricGroup("libp2p_tcp_listener_status_info",{label:"address",help:"Current status of the TCP listener socket"}),errors:e.metrics?.registerMetricGroup("libp2p_tcp_listener_errors_total",{label:"address",help:"Total count of TCP listener errors by type"}),events:e.metrics?.registerMetricGroup("libp2p_tcp_listener_events_total",{label:"address",help:"Total count of TCP listener events by type"})},this.server.on("listening",()=>{let t=this.server.address();t==null?this.addr="unknown":typeof t=="string"?this.addr=t:this.addr=`${t.address}:${t.port}`,this.metrics.status?.update({[this.addr]:I.ACTIVE}),this.safeDispatchEvent("listening")}).on("error",t=>{this.metrics.errors?.increment({[`${this.addr} listen_error`]:!0}),this.safeDispatchEvent("error",{detail:t})}).on("close",()=>{this.metrics.status?.update({[this.addr]:this.status.code}),this.status.code!==I.PAUSED&&this.safeDispatchEvent("close")}).on("drop",()=>{this.metrics.events?.increment({[`${this.addr} drop`]:!0})})}onSocket(e){if(this.metrics.events?.increment({[`${this.addr} connection`]:!0}),this.status.code!==I.ACTIVE)throw e.destroy(),new We("Server is not listening yet");let t;try{t=vt({socket:e,inactivityTimeout:this.context.inactivityTimeout,metrics:this.metrics?.events,metricPrefix:`${this.addr} `,direction:"inbound",localAddr:this.status.listeningAddr,log:this.context.logger.forComponent("libp2p:tcp:connection")})}catch(n){this.log.error("inbound connection failed - %e",n),this.metrics.errors?.increment({[`${this.addr} inbound_to_connection`]:!0}),e.destroy();return}this.log("new inbound connection %s",t.remoteAddr),this.sockets.add(e),this.context.upgrader.upgradeInbound(t,{signal:this.shutdownController.signal}).then(()=>{this.log("inbound connection upgraded %s",t.remoteAddr),e.once("close",()=>{this.sockets.delete(e),this.context.closeServerOnMaxConnections!=null&&this.sockets.size<this.context.closeServerOnMaxConnections.listenBelow&&this.resume().catch(n=>{this.log.error("error attempting to listen server once connection count under limit - %e",n),this.context.closeServerOnMaxConnections?.onListenError?.(n)})}),this.context.closeServerOnMaxConnections!=null&&this.sockets.size>=this.context.closeServerOnMaxConnections.closeAbove&&(this.log("pausing incoming connections as limit is exceeded - %d/%d",this.sockets.size,this.context.closeServerOnMaxConnections.closeAbove),this.pause())}).catch(async n=>{this.log.error("inbound connection upgrade failed - %e",n),this.metrics.errors?.increment({[`${this.addr} inbound_upgrade`]:!0}),this.sockets.delete(e),t.abort(n)})}getAddrs(){if(this.status.code===I.INACTIVE)return[];let e=this.server.address();return e==null?[]:typeof e=="string"?[ce(`/unix/${encodeURIComponent(e)}`)]:Vn(this.status.listeningAddr,e.port)}updateAnnounceAddrs(){}async listen(e){if(this.status.code===I.ACTIVE||this.status.code===I.PAUSED)throw new je("server is already listening");try{this.status={code:I.ACTIVE,listeningAddr:e,netConfig:Ct(e,this.context)},await this.resume()}catch(t){throw this.status={code:I.INACTIVE},t}}async close(e){let t=[];this.server.listening&&t.push(oe(this.server,"close",e)),this.pause(!0),this.shutdownController.abort(),this.sockets.forEach(n=>{n.readable&&(t.push(oe(n,"close",e)),n.destroy())}),await Promise.all(t)}async resume(){if(this.server.listening||this.status.code===I.INACTIVE)return;let e=this.status.netConfig;await new Promise((t,n)=>{this.server.once("error",n),this.server.listen(e,t)}),this.status={...this.status,code:I.ACTIVE},this.log("listening on %s",this.server.address())}pause(e=!1){if(!this.server.listening&&this.status.code===I.PAUSED&&e){this.status={code:I.INACTIVE};return}!this.server.listening||this.status.code!==I.ACTIVE||(this.log("%s server on %s",e?"closing":"pausing",this.server.address()),this.status=e?{code:I.INACTIVE}:{...this.status,code:I.PAUSED},this.server.close())}};var Dt=class{opts;metrics;components;log;constructor(e,t={}){this.log=e.logger.forComponent("libp2p:tcp"),this.opts=t,this.components=e,e.metrics!=null&&(this.metrics={events:e.metrics.registerCounterGroup("libp2p_tcp_dialer_events_total",{label:"event",help:"Total count of TCP dialer events by type"}),errors:e.metrics.registerCounterGroup("libp2p_tcp_dialer_errors_total",{label:"event",help:"Total count of TCP dialer events by type"})})}[Ur]=!0;[Symbol.toStringTag]="@libp2p/tcp";[kr]=["@libp2p/transport"];async dial(e,t){t.keepAlive=t.keepAlive??!0,t.noDelay=t.noDelay??!0,t.allowHalfOpen=t.allowHalfOpen??!1;let n=await this._connect(e,t),o;try{o=vt({socket:n,inactivityTimeout:this.opts.outboundSocketInactivityTimeout,metrics:this.metrics?.events,direction:"outbound",remoteAddr:e,log:this.log.newScope("connection")})}catch(s){throw this.metrics?.errors.increment({outbound_to_connection:!0}),n.destroy(s),s}try{return this.log("new outbound connection %s",o.remoteAddr),await t.upgrader.upgradeOutbound(o,t)}catch(s){throw this.metrics?.errors.increment({outbound_upgrade:!0}),this.log.error("error upgrading outbound connection - %e",s),o.abort(s),s}}async _connect(e,t){t.signal.throwIfAborted(),t.onProgress?.(new pt("tcp:open-connection"));let n;return new Promise((o,s)=>{let i=Date.now(),a=Ct(e,{...this.opts.dialOpts??{},...t});this.log("dialing %a with opts %o",e,a),n=jn.default.connect(a);let c=p=>{this.log.error("dial to %a errored - %e",e,p);let $=a.path??`${a.host??""}:${a.port}`;p.message=`connection error ${$}: ${p.message}`,this.metrics?.events.increment({error:!0}),b(p)},l=()=>{this.log("connection timeout %a",e),this.metrics?.events.increment({timeout:!0});let p=new le(`Connection timeout after ${Date.now()-i}ms`);n.emit("error",p)},f=()=>{this.log("connection opened %a",e),this.metrics?.events.increment({connect:!0}),b()},h=()=>{this.log("connection aborted %a",e),this.metrics?.events.increment({abort:!0}),b(new $e)},b=p=>{if(n.removeListener("error",c),n.removeListener("timeout",l),n.removeListener("connect",f),t.signal!=null&&t.signal.removeEventListener("abort",h),p!=null){s(p);return}o(n)};n.on("error",c),n.on("timeout",l),n.on("connect",f),t.signal.addEventListener("abort",h)}).catch(o=>{throw n?.destroy(),o})}createListener(e){return new St({...this.opts.listenOpts??{},...e,maxConnections:this.opts.maxConnections,backlog:this.opts.backlog,closeServerOnMaxConnections:this.opts.closeServerOnMaxConnections,inactivityTimeout:this.opts.inboundSocketInactivityTimeout,metrics:this.components.metrics,logger:this.components.logger})}listenFilter(e){return e.filter(t=>Tn.exactMatch(t)||t.toString().startsWith("/unix/"))}dialFilter(e){return this.listenFilter(e)}};function ni(r={}){return e=>new Dt(e,r)}return Jn(oi);})();
|
|
2
|
+
"use strict";var Libp2PTcp=(()=>{var qn=Object.create;var $e=Object.defineProperty;var Hn=Object.getOwnPropertyDescriptor;var Qn=Object.getOwnPropertyNames;var Gn=Object.getPrototypeOf,Xn=Object.prototype.hasOwnProperty;var k=(r=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(r,{get:(e,t)=>(typeof require<"u"?require:e)[t]}):r)(function(r){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+r+'" is not supported')});var B=(r,e)=>{for(var t in e)$e(r,t,{get:e[t],enumerable:!0})},Br=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of Qn(e))!Xn.call(r,s)&&s!==t&&$e(r,s,{get:()=>e[s],enumerable:!(n=Hn(e,s))||n.enumerable});return r};var ue=(r,e,t)=>(t=r!=null?qn(Gn(r)):{},Br(e||!r||!r.__esModule?$e(t,"default",{value:r,enumerable:!0}):t,r)),Jn=r=>Br($e({},"__esModule",{value:!0}),r);var si={};B(si,{tcp:()=>ni});var jn=ue(k("net"),1);var Fe=class extends Error{static name="AbortError";constructor(e="The operation was aborted"){super(e),this.name="AbortError"}};var _=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}};var We=class extends Error{static name="StreamResetError";constructor(e="The stream has been reset"){super(e),this.name="StreamResetError"}};var Y=class extends Error{static name="StreamStateError";constructor(e="The stream is in an invalid state"){super(e),this.name="StreamStateError"}},Le=class extends Error{static name="StreamBufferError";constructor(e="The stream buffer was full"){super(e),this.name="StreamBufferError"}};var le=class extends Error{static name="TimeoutError";constructor(e="Timed out"){super(e),this.name="TimeoutError"}},je=class extends Error{static name="NotStartedError";constructor(e="Not started"){super(e),this.name="NotStartedError"}},qe=class extends Error{static name="AlreadyStartedError";constructor(e="Already started"){super(e),this.name="AlreadyStartedError"}};var He=class extends Event{data;constructor(e,t){super("message",t),this.data=e}},fe=class extends Event{error;local;constructor(e,t,n){super("close",n),this.error=t,this.local=e}},Qe=class extends fe{constructor(e,t){super(!0,e,t)}},Ge=class extends fe{constructor(e,t){super(!1,e,t)}};var Ur=Symbol.for("@libp2p/transport");var Nr;(function(r){r[r.FATAL_ALL=0]="FATAL_ALL",r[r.NO_FATAL=1]="NO_FATAL"})(Nr||(Nr={}));var Mr=k("node:events"),Xe=(r,...e)=>{try{(0,Mr.setMaxListeners)(r,...e)}catch{}};function Kn(r){return typeof r?.handleEvent=="function"}function Yn(r){return r===!0||r===!1}function Zn(r){return Yn(r)?r:r?.capture??!1}function It(r){let e={capture:Zn(r),once:!!r?.once};return r?.passive!=null&&(e.passive=r?.passive),r?.signal!=null&&(e.signal=r?.signal),e}function Rr(r,e){return It(r).capture===It(e).capture}var he=class extends EventTarget{#e=new Map;constructor(){super(),Xe(1/0,this)}listenerCount(e){let t=this.#e.get(e);return t==null?0:t.length}addEventListener(e,t,n){let s=It(n);if(s?.signal?.aborted===!0)return;let o=l=>{s.once&&this.removeEventListener(e,t,s),Kn(t)?t.handleEvent(l):t(l)},i=this.#e.get(e);if(i==null&&(i=[],this.#e.set(e,i)),i.some(l=>l.callback!==t?!1:Rr(l.options,s)))return;super.addEventListener(e,o,s);let c=()=>{this.removeEventListener(e,t,s)};s.signal?.addEventListener("abort",c),i.push({callback:t,wrapper:o,options:s,onAbort:c})}removeEventListener(e,t,n){let s=this.#e.get(e);if(s==null){super.removeEventListener(e,t??null,n);return}this.#e.set(e,s.filter(o=>o.callback===t&&Rr(o.options,n)?(super.removeEventListener(e,o.wrapper,n),o.options?.signal?.removeEventListener("abort",o.onAbort),!1):!0))}safeDispatchEvent(e,t={}){return this.dispatchEvent(new CustomEvent(e,t))}};var kr=Symbol.for("@libp2p/service-capabilities");function Ae(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 Tt=k("node:buffer");function Z(r){if(r.buffer instanceof ArrayBuffer)return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);let e=r.slice();return new Uint8Array(e.buffer,0,e.byteLength)}function j(r=0){return Z(Tt.Buffer.alloc(r))}function ee(r=0){return Z(Tt.Buffer.allocUnsafe(r))}var es=Math.pow(2,7),ts=Math.pow(2,14),rs=Math.pow(2,21),Lt=Math.pow(2,28),At=Math.pow(2,35),Pt=Math.pow(2,42),Ot=Math.pow(2,49),v=128,L=127;function de(r){if(r<es)return 1;if(r<ts)return 2;if(r<rs)return 3;if(r<Lt)return 4;if(r<At)return 5;if(r<Pt)return 6;if(r<Ot)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function _t(r,e,t=0){switch(de(r)){case 8:e[t++]=r&255|v,r/=128;case 7:e[t++]=r&255|v,r/=128;case 6:e[t++]=r&255|v,r/=128;case 5:e[t++]=r&255|v,r/=128;case 4:e[t++]=r&255|v,r>>>=7;case 3:e[t++]=r&255|v,r>>>=7;case 2:e[t++]=r&255|v,r>>>=7;case 1:{e[t++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return e}function ns(r,e){let t=r[e],n=0;if(n+=t&L,t<v||(t=r[e+1],n+=(t&L)<<7,t<v)||(t=r[e+2],n+=(t&L)<<14,t<v)||(t=r[e+3],n+=(t&L)<<21,t<v)||(t=r[e+4],n+=(t&L)*Lt,t<v)||(t=r[e+5],n+=(t&L)*At,t<v)||(t=r[e+6],n+=(t&L)*Pt,t<v)||(t=r[e+7],n+=(t&L)*Ot,t<v))return n;throw new RangeError("Could not decode varint")}function ss(r,e){let t=r.get(e),n=0;if(n+=t&L,t<v||(t=r.get(e+1),n+=(t&L)<<7,t<v)||(t=r.get(e+2),n+=(t&L)<<14,t<v)||(t=r.get(e+3),n+=(t&L)<<21,t<v)||(t=r.get(e+4),n+=(t&L)*Lt,t<v)||(t=r.get(e+5),n+=(t&L)*At,t<v)||(t=r.get(e+6),n+=(t&L)*Pt,t<v)||(t=r.get(e+7),n+=(t&L)*Ot,t<v))return n;throw new RangeError("Could not decode varint")}function Bt(r,e=0){return r instanceof Uint8Array?ns(r,e):ss(r,e)}function is(r){return r.buffer instanceof ArrayBuffer}function Nt(r){return is(r)?r:r.slice()}var Vr=k("node:buffer");function Q(r,e){return Z(Vr.Buffer.concat(r,e))}var un=k("node:buffer");var Vt={};B(Vt,{base10:()=>ps});var Ji=new Uint8Array(0);function $r(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}function P(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return oe(r);if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return oe(new Uint8Array(r.buffer,r.byteOffset,r.byteLength));throw new Error("Unknown type, must be binary type")}function Fr(r){let e=new Uint8Array(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}var zr=4096;function Wr(r){let e=r.length;if(e<=zr)return String.fromCharCode.apply(String,r);let t="",n=0;for(;n<e;)t+=String.fromCharCode.apply(String,r.subarray(n,n+=zr));return t}function as(r){return r?.buffer instanceof ArrayBuffer}function oe(r){return as(r)?r:r.slice()}function cs(r,e,t){if(r.length>=255)throw new TypeError("Alphabet too long");for(var n=new Uint8Array(256),s=0;s<n.length;s++)n[s]=255;for(var o=0;o<r.length;o++){var i=r.charAt(o),a=i.charCodeAt(0);if(n[a]!==255)throw new TypeError(i+" is ambiguous");if(n[a]=o,t){var c=i.toLowerCase().charCodeAt(0),l=i.toUpperCase().charCodeAt(0);c!==a&&(n[c]=o),l!==a&&(n[l]=o)}}var f=r.length,h=r.charAt(0),b=Math.log(f)/Math.log(256),p=Math.log(256)/Math.log(f);function $(m){if(m instanceof Uint8Array||(ArrayBuffer.isView(m)?m=new Uint8Array(m.buffer,m.byteOffset,m.byteLength):Array.isArray(m)&&(m=Uint8Array.from(m))),!(m instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(m.length===0)return"";for(var S=0,O=0,U=0,M=m.length;U!==M&&m[U]===0;)U++,S++;for(var F=(M-U)*p+1>>>0,R=new Uint8Array(F);U!==M;){for(var W=m[U],K=0,z=F-1;(W!==0||K<O)&&z!==-1;z--,K++)W+=256*R[z]>>>0,R[z]=W%f>>>0,W=W/f>>>0;if(W!==0)throw new Error("Non-zero carry");O=K,U++}for(var H=F-O;H!==F&&R[H]===0;)H++;for(var ze=h.repeat(S);H<F;++H)ze+=r.charAt(R[H]);return ze}function V(m){if(typeof m!="string")throw new TypeError("Expected String");if(m.length===0)return new Uint8Array;var S=0;if(m[S]!==" "){for(var O=0,U=0;m[S]===h;)O++,S++;for(var M=(m.length-S)*b+1>>>0,F=new Uint8Array(M);m[S];){var R=n[m.charCodeAt(S)];if(R===255)return;for(var W=0,K=M-1;(R!==0||W<U)&&K!==-1;K--,W++)R+=f*F[K]>>>0,F[K]=R%256>>>0,R=R/256>>>0;if(R!==0)throw new Error("Non-zero carry");U=W,S++}if(m[S]!==" "){for(var z=M-U;z!==M&&F[z]===0;)z++;for(var H=new Uint8Array(O+(M-z)),ze=O;z!==M;)H[ze++]=F[z++];return H}}}function y(m){var S=V(m);if(S)return S;throw new Error(`Non-${e} character`)}return{encode:$,decodeUnsafe:V,decode:y}}var us=cs,ls=us,qr=ls;var Ut=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")}},Mt=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,t,n){this.name=e,this.prefix=t;let s=t.codePointAt(0);if(s===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=s,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 Hr(this,e)}},Rt=class{decoders;constructor(e){this.decoders=e}or(e){return Hr(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 Hr(r,e){return new Rt({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var kt=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,t,n,s){this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=s,this.encoder=new Ut(e,t,n),this.decoder=new Mt(e,t,s)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function pe({name:r,prefix:e,encode:t,decode:n}){return new kt(r,e,t,n)}function te({name:r,prefix:e,alphabet:t,caseInsensitive:n=!1}){let{encode:s,decode:o}=qr(t,r,n);return pe({prefix:e,name:r,encode:s,decode:i=>P(o(i))})}function fs(r,e,t,n){let s=r.length;for(;r[s-1]==="=";)--s;let o=new Uint8Array(s*t/8|0),i=0,a=0,c=0;for(let l=0;l<s;++l){let f=e[r[l]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<t|f,i+=t,i>=8&&(i-=8,o[c++]=255&a>>i)}if(i>=t||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return o}function hs(r,e,t){let n=e[e.length-1]==="=",s=(1<<t)-1,o="",i=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],i+=8;i>t;)i-=t,o+=e[s&a>>i];if(i!==0&&(o+=e[s&a<<t-i]),n)for(;(o.length*t&7)!==0;)o+="=";return o}function ds(r,e){let t={};for(let n=0;n<r.length;++n)if(t[r[n]]=n,e){let s=r[n].toLowerCase(),o=r[n].toUpperCase();s!==r[n]&&(t[s]=n),o!==r[n]&&(t[o]=n)}return t}function C({name:r,prefix:e,bitsPerChar:t,alphabet:n,caseInsensitive:s=!1}){let o=ds(n,s);return pe({prefix:e,name:r,encode(i){return hs(i,n,t)},decode(i){return fs(i,o,t,r)}})}var ps=te({prefix:"9",name:"base10",alphabet:"0123456789"});var zt={};B(zt,{base16:()=>ms,base16upper:()=>gs});var ms=C({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4,caseInsensitive:!0}),gs=C({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4,caseInsensitive:!0});var $t={};B($t,{base2:()=>bs});var bs=C({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Ft={};B(Ft,{base256emoji:()=>vs});var Qr=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),ws=Qr.reduce((r,e,t)=>(r[t]=e,r),[]),ys=Qr.reduce((r,e,t)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return r[n]=t,r},[]);function xs(r){return r.reduce((e,t)=>(e+=ws[t],e),"")}function Es(r){let e=[];for(let t of r){let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);let s=ys[n];if(s==null)throw new Error(`Non-base256emoji character: ${t}`);e.push(s)}return new Uint8Array(e)}var vs=pe({prefix:"\u{1F680}",name:"base256emoji",encode:xs,decode:Es});var Wt={};B(Wt,{base32:()=>re,base32hex:()=>Is,base32hexpad:()=>Ls,base32hexpadupper:()=>As,base32hexupper:()=>Ts,base32pad:()=>Ss,base32padupper:()=>Ds,base32upper:()=>Cs,base32z:()=>Ps});var re=C({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5,caseInsensitive:!0}),Cs=C({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5,caseInsensitive:!0}),Ss=C({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5,caseInsensitive:!0}),Ds=C({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5,caseInsensitive:!0}),Is=C({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5,caseInsensitive:!0}),Ts=C({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5,caseInsensitive:!0}),Ls=C({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5,caseInsensitive:!0}),As=C({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5,caseInsensitive:!0}),Ps=C({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var jt={};B(jt,{base36:()=>Pe,base36upper:()=>Os});var Pe=te({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz",caseInsensitive:!0}),Os=te({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",caseInsensitive:!0});var qt={};B(qt,{base58btc:()=>q,base58flickr:()=>_s});var q=te({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),_s=te({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Qt={};B(Qt,{base64:()=>Bs,base64pad:()=>Ns,base64url:()=>Ht,base64urlpad:()=>Us});var Bs=C({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Ns=C({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Ht=C({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Us=C({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Gt={};B(Gt,{base8:()=>Ms});var Ms=C({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Xt={};B(Xt,{identity:()=>Rs});var Rs=pe({prefix:"\0",name:"identity",encode:r=>Wr(P(r)),decode:r=>P(Fr(r))});var ha=new TextEncoder,da=new TextDecoder;var Kt={};B(Kt,{identity:()=>io});var zs=Jr,Gr=128,$s=127,Fs=~$s,Ws=Math.pow(2,31);function Jr(r,e,t){e=e||[],t=t||0;for(var n=t;r>=Ws;)e[t++]=r&255|Gr,r/=128;for(;r&Fs;)e[t++]=r&255|Gr,r>>>=7;return e[t]=r|0,Jr.bytes=t-n+1,e}var js=Jt,qs=128,Xr=127;function Jt(r,n){var t=0,n=n||0,s=0,o=n,i,a=r.length;do{if(o>=a)throw Jt.bytes=0,new RangeError("Could not decode varint");i=r[o++],t+=s<28?(i&Xr)<<s:(i&Xr)*Math.pow(2,s),s+=7}while(i>=qs);return Jt.bytes=o-n,t}var Hs=Math.pow(2,7),Qs=Math.pow(2,14),Gs=Math.pow(2,21),Xs=Math.pow(2,28),Js=Math.pow(2,35),Ks=Math.pow(2,42),Ys=Math.pow(2,49),Zs=Math.pow(2,56),eo=Math.pow(2,63),to=function(r){return r<Hs?1:r<Qs?2:r<Gs?3:r<Xs?4:r<Js?5:r<Ks?6:r<Ys?7:r<Zs?8:r<eo?9:10},ro={encode:zs,decode:js,encodingLength:to},no=ro,Oe=no;function _e(r,e=0){let t=Oe.decode(r,e),n=Oe.decode.bytes;if(n>9)throw new RangeError("Invalid varint: too long");if(n>1&&r[e+n-1]===0)throw new RangeError("Invalid varint: not minimally encoded");return[t,n]}function me(r,e,t=0){return Oe.encode(r,e,t),e}function ge(r){return Oe.encodingLength(r)}function we(r,e){let t=e.byteLength,n=ge(r),s=n+ge(t),o=new Uint8Array(s+t);return me(r,o,0),me(t,o,n),o.set(e,s),new be(r,t,e,o)}function Kr(r){let e=P(r),[t,n]=_e(e),[s,o]=_e(e.subarray(n)),i=e.subarray(n+o);if(i.byteLength!==s)throw new Error("Incorrect length");return new be(t,s,i,e)}function Yr(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&$r(r.bytes,t.bytes)}}var be=class{code;size;digest;bytes;constructor(e,t,n,s){this.code=e,this.size=t,this.digest=oe(n),this.bytes=oe(s)}};var Zr=0,so="identity",en=P;function oo(r,e){if(e?.truncate!=null&&e.truncate!==r.byteLength){if(e.truncate<0||e.truncate>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,e.truncate)}return we(Zr,en(r))}var io={code:Zr,name:so,encode:en,digest:oo};var tr={};B(tr,{sha256:()=>co,sha512:()=>uo});var er=ue(k("node:crypto"),1);var ao=20;function Zt({name:r,code:e,encode:t,minDigestLength:n,maxDigestLength:s}){return new Yt(r,e,t,n,s)}var Yt=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,t,n,s,o){this.name=e,this.code=t,this.encode=n,this.minDigestLength=s??ao,this.maxDigestLength=o}digest(e,t){if(t?.truncate!=null){if(t.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&t.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(e instanceof Uint8Array){let n=this.encode(e);return n instanceof Uint8Array?tn(n,this.code,t?.truncate):n.then(s=>tn(s,this.code,t?.truncate))}else throw Error("Unknown type, must be binary type")}};function tn(r,e,t){if(t!=null&&t!==r.byteLength){if(t>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,t)}return we(e,r)}var co=Zt({name:"sha2-256",code:18,encode:r=>P(er.default.createHash("sha256").update(r).digest())}),uo=Zt({name:"sha2-512",code:19,encode:r=>P(er.default.createHash("sha512").update(r).digest())});function nn(r,e){let{bytes:t,version:n}=r;return n===0?fo(t,rr(r),e??q.encoder):ho(t,rr(r),e??re.encoder)}var sn=new WeakMap;function rr(r){let e=sn.get(r);if(e==null){let t=new Map;return sn.set(r,t),t}return e}var ye=class r{code;version;multihash;bytes;"/";constructor(e,t,n,s){this.code=t,this.version=e,this.multihash=n,this.bytes=oe(s),this["/"]=this.bytes}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:t}=this;if(e!==Ne)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==po)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=we(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&&Yr(e.multihash,n.multihash)}toString(e){return nn(this,e)}toJSON(){return{"/":nn(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:s,multihash:o,bytes:i}=t;return new r(n,s,o,i??on(n,s,o.bytes))}else if(t[mo]===!0){let{version:n,multihash:s,code:o}=t,i=Kr(s);return r.create(n,o,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!==Ne)throw new Error(`Version 0 CID must use dag-pb (code: ${Ne}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let s=on(e,t,n.bytes);return new r(e,t,n,s)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,Ne,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,s=P(e.subarray(n,n+t.multihashSize));if(s.byteLength!==t.multihashSize)throw new Error("Incorrect length");let o=s.subarray(t.multihashSize-t.digestSize),i=new be(t.multihashCode,t.digestSize,o,s);return[t.version===0?r.createV0(i):r.createV1(t.codec,i),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[h,b]=_e(e.subarray(t));return t+=b,h},s=n(),o=Ne;if(s===18?(s=0,t=0):o=n(),s!==0&&s!==1)throw new RangeError(`Invalid CID version ${s}`);let i=t,a=n(),c=n(),l=t+c,f=l-i;return{version:s,codec:o,multihashCode:a,digestSize:c,multihashSize:f,size:l}}static parse(e,t){let[n,s]=lo(e,t),o=r.decode(s);if(o.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return rr(o).set(n,e),o}};function lo(r,e){switch(r[0]){case"Q":{let t=e??q;return[q.prefix,t.decode(`${q.prefix}${r}`)]}case q.prefix:{let t=e??q;return[q.prefix,t.decode(r)]}case re.prefix:{let t=e??re;return[re.prefix,t.decode(r)]}case Pe.prefix:{let t=e??Pe;return[Pe.prefix,t.decode(r)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],e.decode(r)]}}}function fo(r,e,t){let{prefix:n}=t;if(n!==q.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let s=e.get(n);if(s==null){let o=t.encode(r).slice(1);return e.set(n,o),o}else return s}function ho(r,e,t){let{prefix:n}=t,s=e.get(n);if(s==null){let o=t.encode(r);return e.set(n,o),o}else return s}var Ne=112,po=18;function on(r,e,t){let n=ge(r),s=n+ge(e),o=new Uint8Array(s+t.byteLength);return me(r,o,0),me(e,o,n),o.set(t,s),o}var mo=Symbol.for("@ipld/js-cid/CID");var Ue={...Xt,...$t,...Gt,...Vt,...zt,...Wt,...jt,...qt,...Qt,...Ft},Ma={...tr,...Kt};function cn(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var an=cn("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),nr=cn("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=ee(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),go={utf8:an,"utf-8":an,hex:Ue.base16,latin1:nr,ascii:nr,binary:nr,...Ue},Ke=go;function xe(r,e="utf8"){let t=Ke[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return e==="utf8"||e==="utf-8"?Z(un.Buffer.from(r,"utf-8")):t.decoder.decode(`${t.prefix}${r}`)}var ln=k("node:buffer");function ne(r,e="utf8"){let t=Ke[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return e==="utf8"||e==="utf-8"?ln.Buffer.from(r.buffer,r.byteOffset,r.byteLength).toString("utf8"):t.encoder.encode(r).substring(1)}var T=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},G=class extends Error{static name="ValidationError";name="ValidationError"},Ye=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},Ze=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};var N=k("node:net");function or(r){return e=>ne(e,r)}function ir(r){return e=>xe(e,r)}function Ee(r){return new DataView(r.buffer).getUint16(r.byteOffset).toString()}function ie(r){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,typeof r=="string"?parseInt(r):r),new Uint8Array(e)}function fn(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=xe(e[0],"base32"),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let s=ie(n);return Q([t,s],t.length+s.length)}function hn(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=re.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 s=ie(n);return Q([t,s],t.length+s.length)}function ar(r){let e=r.subarray(0,r.length-2),t=r.subarray(r.length-2),n=ne(e,"base32"),s=Ee(t);return`${n}:${s}`}var cr=function(r){r=r.toString().trim();let e=new Uint8Array(4);return r.split(/\./g).forEach((t,n)=>{let s=parseInt(t,10);if(isNaN(s)||s<0||s>255)throw new T("Invalid byte value in IP address");e[n]=s}),e},dn=function(r){let e=0;r=r.toString().trim();let t=r.split(":",8),n;for(n=0;n<t.length;n++){let o=(0,N.isIPv4)(t[n]),i;o&&(i=cr(t[n]),t[n]=ne(i.subarray(0,2),"base16")),i!=null&&++n<8&&t.splice(n,0,ne(i.subarray(2,4),"base16"))}if(t[0]==="")for(;t.length<8;)t.unshift("0");else if(t[t.length-1]==="")for(;t.length<8;)t.push("0");else if(t.length<8){for(n=0;n<t.length&&t[n]!=="";n++);let o=[n,1];for(n=9-t.length;n>0;n--)o.push("0");t.splice.apply(t,o)}let s=new Uint8Array(e+16);for(n=0;n<t.length;n++){t[n]===""&&(t[n]="0");let o=parseInt(t[n],16);if(isNaN(o)||o<0||o>65535)throw new T("Invalid byte value in IP address");s[e++]=o>>8&255,s[e++]=o&255}return s},pn=function(r){if(r.byteLength!==4)throw new T("IPv4 address was incorrect length");let e=[];for(let t=0;t<r.byteLength;t++)e.push(r[t]);return e.join(".")},mn=function(r){if(r.byteLength!==16)throw new T("IPv6 address was incorrect length");let e=[];for(let n=0;n<r.byteLength;n+=2){let s=r[n],o=r[n+1],i=`${s.toString(16).padStart(2,"0")}${o.toString(16).padStart(2,"0")}`;e.push(i)}let t=e.join(":");try{let n=new URL(`http://[${t}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new T(`Invalid IPv6 address "${t}"`)}};function gn(r){try{let e=new URL(`http://[${r}]`);return e.hostname.substring(1,e.hostname.length-1)}catch{throw new T(`Invalid IPv6 address "${r}"`)}}var sr=Object.values(Ue).map(r=>r.decoder),bo=(function(){let r=sr[0].or(sr[1]);return sr.slice(2).forEach(e=>r=r.or(e)),r})();function bn(r){return bo.decode(r)}function wn(r){return e=>r.encoder.encode(e)}function wo(r){if(parseInt(r).toString()!==r)throw new G("Value must be an integer")}function yo(r){if(r<0)throw new G("Value must be a positive integer, or zero")}function xo(r){return e=>{if(e>r)throw new G(`Value must be smaller than or equal to ${r}`)}}function Eo(...r){return e=>{for(let t of r)t(e)}}var Me=Eo(wo,yo,xo(65535));var D=-1,ur=class{protocolsByCode=new Map;protocolsByName=new Map;getProtocol(e){let t;if(typeof e=="string"?t=this.protocolsByName.get(e):t=this.protocolsByCode.get(e),t==null)throw new Ze(`Protocol ${e} was unknown`);return t}addProtocol(e){this.protocolsByCode.set(e.code,e),this.protocolsByName.set(e.name,e),e.aliases?.forEach(t=>{this.protocolsByName.set(t,e)})}removeProtocol(e){let t=this.protocolsByCode.get(e);t!=null&&(this.protocolsByCode.delete(t.code),this.protocolsByName.delete(t.name),t.aliases?.forEach(n=>{this.protocolsByName.delete(n)}))}},J=new ur,Uo=[{code:4,name:"ip4",size:32,valueToBytes:cr,bytesToValue:pn,validate:r=>{if(!(0,N.isIPv4)(r))throw new G(`Invalid IPv4 address "${r}"`)}},{code:6,name:"tcp",size:16,valueToBytes:ie,bytesToValue:Ee,validate:Me},{code:273,name:"udp",size:16,valueToBytes:ie,bytesToValue:Ee,validate:Me},{code:33,name:"dccp",size:16,valueToBytes:ie,bytesToValue:Ee,validate:Me},{code:41,name:"ip6",size:128,valueToBytes:dn,bytesToValue:mn,stringToValue:gn,validate:r=>{if(!(0,N.isIPv6)(r))throw new G(`Invalid IPv6 address "${r}"`)}},{code:42,name:"ip6zone",size:D},{code:43,name:"ipcidr",size:8,bytesToValue:or("base10"),valueToBytes:ir("base10")},{code:53,name:"dns",size:D},{code:54,name:"dns4",size:D},{code:55,name:"dns6",size:D},{code:56,name:"dnsaddr",size:D},{code:132,name:"sctp",size:16,valueToBytes:ie,bytesToValue:Ee,validate:Me},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:D,stringToValue:r=>decodeURIComponent(r),valueToString:r=>encodeURIComponent(r)},{code:421,name:"p2p",aliases:["ipfs"],size:D,bytesToValue:or("base58btc"),valueToBytes:r=>r.startsWith("Q")||r.startsWith("1")?ir("base58btc")(r):ye.parse(r).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:ar,valueToBytes:fn},{code:445,name:"onion3",size:296,bytesToValue:ar,valueToBytes:hn},{code:446,name:"garlic64",size:D},{code:447,name:"garlic32",size:D},{code:448,name:"tls"},{code:449,name:"sni",size:D},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:D,bytesToValue:wn(Ht),valueToBytes:bn},{code:480,name:"http"},{code:481,name:"http-path",size:D,stringToValue:r=>`/${decodeURIComponent(r)}`,valueToString:r=>encodeURIComponent(r.substring(1))},{code:443,name:"https"},{code:477,name:"ws"},{code:478,name:"wss"},{code:479,name:"p2p-websocket-star"},{code:277,name:"p2p-stardust"},{code:275,name:"p2p-webrtc-star"},{code:276,name:"p2p-webrtc-direct"},{code:280,name:"webrtc-direct"},{code:281,name:"webrtc"},{code:290,name:"p2p-circuit"},{code:777,name:"memory",size:D}];Uo.forEach(r=>{J.addProtocol(r)});function yn(r){let e=[],t=0;for(;t<r.length;){let n=Bt(r,t),s=J.getProtocol(n),o=de(n),i=Mo(s,r,t+o),a=0;i>0&&s.size===D&&(a=de(i));let c=o+a+i,l={code:n,name:s.name,bytes:Nt(r.subarray(t,t+c))};if(i>0){let f=t+o+a,h=r.subarray(f,f+i);l.value=s.bytesToValue?.(h)??ne(h)}e.push(l),t+=c}return e}function xn(r){let e=0,t=[];for(let n of r){if(n.bytes==null){let s=J.getProtocol(n.code),o=de(n.code),i,a=0,c=0;n.value!=null&&(i=s.valueToBytes?.(n.value)??xe(n.value),a=i.byteLength,s.size===D&&(c=de(a)));let l=new Uint8Array(o+c+a),f=0;_t(n.code,l,f),f+=o,i!=null&&(s.size===D&&(_t(a,l,f),f+=c),l.set(i,f)),n.bytes=l}t.push(n.bytes),e+=n.bytes.byteLength}return Q(t,e)}function En(r){if(r.charAt(0)!=="/")throw new T('String multiaddr must start with "/"');let e=[],t="protocol",n="",s="";for(let o=1;o<r.length;o++){let i=r.charAt(o);i!=="/"&&(t==="protocol"?s+=r.charAt(o):n+=r.charAt(o));let a=o===r.length-1;if(i==="/"||a){let c=J.getProtocol(s);if(t==="protocol"){if(c.size==null||c.size===0){e.push({code:c.code,name:c.name}),n="",s="",t="protocol";continue}else if(a)throw new T(`Component ${s} was missing value`);t="value"}else if(t==="value"){let l={code:c.code,name:c.name};if(c.size!=null&&c.size!==0){if(n==="")throw new T(`Component ${s} was missing value`);l.value=c.stringToValue?.(n)??n}e.push(l),n="",s="",t="protocol"}}}if(s!==""&&n!=="")throw new T("Incomplete multiaddr");return e}function vn(r){return`/${r.flatMap(e=>{if(e.value==null)return e.name;let t=J.getProtocol(e.code);if(t==null)throw new T(`Unknown protocol code ${e.code}`);return[e.name,t.valueToString?.(e.value)??e.value]}).join("/")}`}function Mo(r,e,t){return r.size==null||r.size===0?0:r.size>0?r.size/8:Bt(e,t)}var Ro=Symbol.for("nodejs.util.inspect.custom"),vr=Symbol.for("@multiformats/multiaddr");function ko(r){if(r==null&&(r="/"),Cn(r))return r.getComponents();if(r instanceof Uint8Array)return yn(r);if(typeof r=="string")return r=r.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),r===""&&(r="/"),En(r);if(Array.isArray(r))return r;throw new T("Must be a string, Uint8Array, Component[], or another Multiaddr")}var ct=class r{[vr]=!0;#e;#t;#r;constructor(e="/",t={}){this.#e=ko(e),t.validate!==!1&&Vo(this)}get bytes(){return this.#r==null&&(this.#r=xn(this.#e)),this.#r}toString(){return this.#t==null&&(this.#t=vn(this.#e)),this.#t}toJSON(){return this.toString()}getComponents(){return[...this.#e.map(e=>({...e}))]}encapsulate(e){let t=new r(e);return new r([...this.#e,...t.getComponents()],{validate:!1})}decapsulate(e){let t=e.toString(),n=this.toString(),s=n.lastIndexOf(t);if(s<0)throw new Ye(`Address ${this.toString()} does not contain subaddress: ${t}`);return new r(n.slice(0,s),{validate:!1})}decapsulateCode(e){let t;for(let n=this.#e.length-1;n>-1;n--)if(this.#e[n].code===e){t=n;break}return new r(this.#e.slice(0,t),{validate:!1})}equals(e){return Ae(this.bytes,e.bytes)}[Ro](){return`Multiaddr(${this.toString()})`}};function Vo(r){r.getComponents().forEach(e=>{let t=J.getProtocol(e.code);e.value!=null&&t.validate?.(e.value)})}function Cn(r){return!!r?.[vr]}function ce(r){return new ct(r)}var x=r=>({match:e=>{let t=e[0];return t==null||t.code!==r||t.value!=null?!1:e.slice(1)}}),u=(r,e)=>({match:t=>{let n=t[0];return n?.code!==r||n.value==null||e!=null&&n.value!==e?!1:t.slice(1)}}),Sn=r=>({match:e=>r.match(e)===!1?e:!1}),d=r=>({match:e=>{let t=r.match(e);return t===!1?e:t}}),A=(...r)=>({match:e=>{let t;for(let n of r){let s=n.match(e);s!==!1&&(t==null||s.length<t.length)&&(t=s)}return t??!1}}),g=(...r)=>({match:e=>{for(let t of r){let n=t.match(e);if(n===!1)return!1;e=n}return e}});function E(...r){function e(s){if(s==null)return!1;let o=s.getComponents();for(let i of r){let a=i.match(o);if(a===!1)return!1;o=a}return o}function t(s){return e(s)!==!1}function n(s){let o=e(s);return o===!1?!1:o.length===0}return{matchers:r,matches:t,exactMatch:n}}var zo=u(421),Hc=E(zo),lt=u(54),ft=u(55),ht=u(56),Sr=u(53),Qc=E(lt,d(u(421))),Gc=E(ft,d(u(421))),Xc=E(ht,d(u(421))),Jc=E(A(Sr,ht,lt,ft),d(u(421))),Dn=g(u(4),d(u(43))),In=g(d(u(42)),u(41),d(u(43))),Dr=A(Dn,In),De=A(Dr,Sr,lt,ft,ht),Kc=E(A(Dr,g(A(Sr,ht,lt,ft),d(u(421))))),Yc=E(Dn),Zc=E(In),eu=E(Dr),Ir=g(De,u(6)),ke=g(De,u(273)),Tn=E(g(Ir,d(u(421)))),tu=E(ke),Tr=g(ke,x(460),d(u(421))),dt=g(ke,x(461),d(u(421))),$o=A(Tr,dt),ru=E(Tr),nu=E(dt),Cr=A(De,Ir,ke,Tr,dt),Ln=A(g(Cr,x(477),d(u(421)))),su=E(Ln),An=A(g(Cr,x(478),d(u(421))),g(Cr,x(448),d(u(449)),x(477),d(u(421)))),ou=E(An),Pn=g(ke,x(280),d(u(466)),d(u(466)),d(u(421))),iu=E(Pn),On=g(dt,x(465),d(u(466)),d(u(466)),d(u(421))),au=E(On),ut=A(Ln,An,g(Ir,d(u(421))),g($o,d(u(421))),g(De,d(u(421))),Pn,On,u(421)),cu=E(ut),Fo=g(d(ut),x(290),Sn(x(281)),d(u(421))),uu=E(Fo),Wo=A(g(ut,x(290),x(281),d(u(421))),g(ut,x(281),d(u(421))),g(x(281),d(u(421)))),lu=E(Wo),jo=g(De,A(g(u(6,"80")),g(u(6),x(480)),x(480)),d(u(481)),d(u(421))),fu=E(jo),qo=g(De,A(g(u(6,"443")),g(u(6,"443"),x(480)),g(u(6),x(443)),g(u(6),x(448),x(480)),g(x(448),x(480)),x(448),x(443)),d(u(481)),d(u(421))),hu=E(qo),Ho=A(g(u(777),d(u(421)))),du=E(Ho),Qo=A(g(u(400),d(u(421)))),Ve=E(Qo);var pt=class extends Event{type;detail;constructor(e,t){super(e),this.type=e,this.detail=t}};var Wn=ue(k("node:net"),1);var Bn=Symbol.for("@achingbrain/uint8arraylist");function _n(r,e){if(e==null||e<0)throw new RangeError("index is out of bounds");let t=0;for(let n of r){let s=t+n.byteLength;if(e<s)return{buf:n,index:e-t};t=s}throw new RangeError("index is out of bounds")}function mt(r){return!!r?.[Bn]}var Ie=class r{bufs;length;[Bn]=!0;constructor(...e){this.bufs=[],this.length=0,e.length>0&&this.appendAll(e)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...e){this.appendAll(e)}appendAll(e){let t=0;for(let n of e)if(n instanceof Uint8Array)t+=n.byteLength,this.bufs.push(n);else if(mt(n)){t+=n.byteLength;for(let s of n.bufs)this.bufs.push(s)}else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=t}prepend(...e){this.prependAll(e)}prependAll(e){let t=0;for(let n of e.reverse())if(n instanceof Uint8Array)t+=n.byteLength,this.bufs.unshift(n);else if(mt(n))t+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=t}get(e){let t=_n(this.bufs,e);return t.buf[t.index]}set(e,t){let n=_n(this.bufs,e);n.buf[n.index]=t}write(e,t=0){if(e instanceof Uint8Array)for(let n=0;n<e.length;n++)this.set(t+n,e[n]);else if(mt(e))for(let n=0;n<e.length;n++)this.set(t+n,e.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(e){if(e=Math.trunc(e),!(Number.isNaN(e)||e<=0)){if(e===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(e>=this.bufs[0].byteLength)e-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(e),this.length-=e;break}}}slice(e,t){let{bufs:n,length:s}=this._subList(e,t);return Q(n,s)}subarray(e,t){let{bufs:n,length:s}=this._subList(e,t);return n.length===1?n[0]:Q(n,s)}sublist(e,t){let{bufs:n,length:s}=this._subList(e,t),o=new r;return o.length=s,o.bufs=n,o}_subList(e,t){if(e=e??0,t=t??this.length,e<0&&(e=this.length+e),t<0&&(t=this.length+t),e<0||t>this.length)throw new RangeError("index is out of bounds");if(e===t)return{bufs:[],length:0};if(e===0&&t===this.length)return{bufs:[...this.bufs],length:this.length};let n=[],s=0;for(let o=0;o<this.bufs.length;o++){let i=this.bufs[o],a=s,c=a+i.byteLength;if(s=c,e>=c)continue;let l=e>=a&&e<c,f=t>a&&t<=c;if(l&&f){if(e===a&&t===c){n.push(i);break}let h=e-a;n.push(i.subarray(h,h+(t-e)));break}if(l){if(e===0){n.push(i);continue}n.push(i.subarray(e-a));continue}if(f){if(t===c){n.push(i);break}n.push(i.subarray(0,t-a));break}n.push(i)}return{bufs:n,length:t-e}}indexOf(e,t=0){if(!mt(e)&&!(e instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=e instanceof Uint8Array?e:e.subarray();if(t=Number(t??0),isNaN(t)&&(t=0),t<0&&(t=this.length+t),t<0&&(t=0),e.length===0)return t>this.length?this.length:t;let s=n.byteLength;if(s===0)throw new TypeError("search must be at least 1 byte long");let o=256,i=new Int32Array(o);for(let h=0;h<o;h++)i[h]=-1;for(let h=0;h<s;h++)i[n[h]]=h;let a=i,c=this.byteLength-n.byteLength,l=n.byteLength-1,f;for(let h=t;h<=c;h+=f){f=0;for(let b=l;b>=0;b--){let p=this.get(h+b);if(n[b]!==p){f=Math.max(1,b-a[p]);break}}if(f===0)return h}return-1}getInt8(e){let t=this.subarray(e,e+1);return new DataView(t.buffer,t.byteOffset,t.byteLength).getInt8(0)}setInt8(e,t){let n=ee(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,t),this.write(n,e)}getInt16(e,t){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,t)}setInt16(e,t,n){let s=j(2);new DataView(s.buffer,s.byteOffset,s.byteLength).setInt16(0,t,n),this.write(s,e)}getInt32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,t)}setInt32(e,t,n){let s=j(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setInt32(0,t,n),this.write(s,e)}getBigInt64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,t)}setBigInt64(e,t,n){let s=j(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setBigInt64(0,t,n),this.write(s,e)}getUint8(e){let t=this.subarray(e,e+1);return new DataView(t.buffer,t.byteOffset,t.byteLength).getUint8(0)}setUint8(e,t){let n=ee(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,t),this.write(n,e)}getUint16(e,t){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,t)}setUint16(e,t,n){let s=j(2);new DataView(s.buffer,s.byteOffset,s.byteLength).setUint16(0,t,n),this.write(s,e)}getUint32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,t)}setUint32(e,t,n){let s=j(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setUint32(0,t,n),this.write(s,e)}getBigUint64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,t)}setBigUint64(e,t,n){let s=j(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setBigUint64(0,t,n),this.write(s,e)}getFloat32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,t)}setFloat32(e,t,n){let s=j(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setFloat32(0,t,n),this.write(s,e)}getFloat64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,t)}setFloat64(e,t,n){let s=j(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setFloat64(0,t,n),this.write(s,e)}equals(e){if(e==null||!(e instanceof r)||e.bufs.length!==this.bufs.length)return!1;for(let t=0;t<this.bufs.length;t++)if(!Ae(this.bufs[t],e.bufs[t]))return!1;return!0}static fromUint8Arrays(e,t){let n=new r;return n.bufs=e,t==null&&(t=e.reduce((s,o)=>s+o.byteLength,0)),n.length=t,n}};function Go(r){let e=r.getComponents(),t={},n=0;return e[n]?.name==="ip6zone"&&(t.zone=`${e[n].value}`,n++),e[n]?.name==="ip4"||e[n]?.name==="ip6"||e[n]?.name==="dns"||e[n]?.name==="dns4"||e[n]?.name==="dns6"?(t.type=e[n].name,t.host=e[n].value,n++):e[n]?.name==="dnsaddr"&&(t.type=e[n].name,t.host=`_dnsaddr.${e[n].value}`,n++),(e[n]?.name==="tcp"||e[n]?.name==="udp")&&(t.protocol=e[n].name==="tcp"?"tcp":"udp",t.port=parseInt(`${e[n].value}`),n++),e[n]?.name==="ipcidr"&&(t.type==="ip4"?t.cidr=parseInt(`${e[n].value}`):t.type==="ip6"&&(t.cidr=`${e[n].value}`),n++),t.type==null||t.host==null?null:(e[n]?.name==="tls"&&e[n+1]?.name==="sni"&&(t.sni=e[n+1].value,n+=2),t)}function gt(r){let e=Go(r);if(e==null)throw new _(`Multiaddr ${r} was not an IPv4, IPv6, DNS, DNS4, DNS6 or DNSADDR address`);return e}function bt(){let r={};return r.promise=new Promise((e,t)=>{r.resolve=e,r.reject=t}),r}var wt=class{buffer;mask;top;btm;next;constructor(e){if(!(e>0)||(e-1&e)!==0)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(e),this.mask=e-1,this.top=0,this.btm=0,this.next=null}push(e){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=e,this.top=this.top+1&this.mask,!0)}shift(){let e=this.buffer[this.btm];if(e!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,e}isEmpty(){return this.buffer[this.btm]===void 0}},Te=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new wt(this.hwm),this.tail=this.head,this.size=0}calculateSize(e){return e?.byteLength!=null?e.byteLength:1}push(e){if(e?.value!=null&&(this.size+=this.calculateSize(e.value)),!this.head.push(e)){let t=this.head;this.head=t.next=new wt(2*this.head.buffer.length),this.head.push(e)}}shift(){let e=this.tail.shift();if(e===void 0&&this.tail.next!=null){let t=this.tail.next;this.tail.next=null,this.tail=t,e=this.tail.shift()}return e?.value!=null&&(this.size-=this.calculateSize(e.value)),e}isEmpty(){return this.head.isEmpty()}};var Lr=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.code=t??"ABORT_ERR"}};function Nn(r={}){return Xo(t=>{let n=t.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},r)}function Xo(r,e){e=e??{};let t=e.onEnd,n=new Te,s,o,i,a=bt(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((y,m)=>{o=S=>{o=null,n.push(S);try{y(r(n))}catch(O){m(O)}return s}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=bt()})}},l=y=>o!=null?o(y):(n.push(y),s),f=y=>(n=new Te,o!=null?o({error:y}):(n.push({error:y}),s)),h=y=>{if(i)return s;if(e?.objectMode!==!0&&y?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return l({done:!1,value:y})},b=y=>i?s:(i=!0,y!=null?f(y):l({done:!0})),p=()=>(n=new Te,b(),{done:!0}),$=y=>(b(y),{done:!0});if(s={[Symbol.asyncIterator](){return this},next:c,return:p,throw:$,push:h,end:b,get readableLength(){return n.size},onEmpty:async y=>{let m=y?.signal;if(m?.throwIfAborted(),n.isEmpty())return;let S,O;m!=null&&(S=new Promise((U,M)=>{O=()=>{M(new Lr)},m.addEventListener("abort",O)}));try{await Promise.race([a.promise,S])}finally{O!=null&&m!=null&&m?.removeEventListener("abort",O)}}},t==null)return s;let V=s;return s={[Symbol.asyncIterator](){return this},next(){return V.next()},throw(y){return V.throw(y),t!=null&&(t(y),t=void 0),{done:!0}},return(){return V.return(),t!=null&&(t(),t=void 0),{done:!0}},push:h,end(y){return V.end(y),t!=null&&(t(y),t=void 0),s},get readableLength(){return V.readableLength},onEmpty:y=>V.onEmpty(y)},s}var Ar=class r extends Error{name="TimeoutError";constructor(e,t){super(e,t),Error.captureStackTrace?.(this,r)}},Un=r=>r.reason??new DOMException("This operation was aborted.","AbortError");function Pr(r,e){let{milliseconds:t,fallback:n,message:s,customTimers:o={setTimeout,clearTimeout},signal:i}=e,a,c,f=new Promise((h,b)=>{if(typeof t!="number"||Math.sign(t)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${t}\``);if(i?.aborted){b(Un(i));return}if(i&&(c=()=>{b(Un(i))},i.addEventListener("abort",c,{once:!0})),r.then(h,b),t===Number.POSITIVE_INFINITY)return;let p=new Ar;a=o.setTimeout.call(void 0,()=>{if(n){try{h(n())}catch($){b($)}return}typeof r.cancel=="function"&&r.cancel(),s===!1?h():s instanceof Error?b(s):(p.message=s??`Promise timed out after ${t} milliseconds`,b(p))},t)}).finally(()=>{f.clear(),c&&i&&i.removeEventListener("abort",c)});return f.clear=()=>{o.clearTimeout.call(void 0,a),a=void 0},f}var Jo=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 Ko(r,e,t){let n,s=new Promise((o,i)=>{if(t={rejectionEvents:["error"],multiArgs:!1,rejectionMultiArgs:!1,resolveImmediately:!1,...t},!(t.count>=0&&(t.count===Number.POSITIVE_INFINITY||Number.isInteger(t.count))))throw new TypeError("The `count` option should be at least 0 or more");t.signal?.throwIfAborted();let a=[e].flat(),c=[],{addListener:l,removeListener:f}=Jo(r),h=async(...p)=>{let $=t.multiArgs?p:p[0];if(t.filter)try{if(!await t.filter($))return}catch(V){n(),i(V);return}c.push($),t.count===c.length&&(n(),o(c))},b=(...p)=>{n(),i(t.rejectionMultiArgs?p:p[0])};n=()=>{for(let p of a)f(p,h);for(let p of t.rejectionEvents)a.includes(p)||f(p,b)};for(let p of a)l(p,h);for(let p of t.rejectionEvents)a.includes(p)||l(p,b);t.signal&&t.signal.addEventListener("abort",()=>{b(t.signal.reason)},{once:!0}),t.resolveImmediately&&o(c)});if(s.cancel=n,typeof t.timeout=="number"){let o=Pr(s,{milliseconds:t.timeout});return o.cancel=()=>{n(),o.clear()},o}return s}function se(r,e,t){typeof t=="function"&&(t={filter:t}),t={...t,count:1,resolveImmediately:!1};let n=Ko(r,e,t),s=n.then(o=>o[0]);return s.cancel=n.cancel,s}var yt=class extends Error{static name="StreamClosedError";name="StreamClosedError"};function Yo(r){return r.reason}function Mn(r,e,t){if(e==null||r==null)return r;let n=t?.translateError??Yo;if(e.aborted)return r.catch(()=>{}),Promise.reject(n(e));let s;return Promise.race([r,new Promise((o,i)=>{s=()=>{i(n(e))},e.addEventListener("abort",s)})]).finally(()=>{s!=null&&e.removeEventListener("abort",s)})}var Zo=Math.pow(2,20)*4,xt=class extends he{status;timeline;inactivityTimeout;maxReadBufferLength;maxWriteBufferLength;log;direction;maxMessageSize;readStatus;writeStatus;remoteReadStatus;remoteWriteStatus;writableNeedsDrain;readBuffer;writeBuffer;sendingData;#e=!1;onDrainPromise;constructor(e){super(),this.status="open",this.log=e.log,this.direction=e.direction??"outbound",this.inactivityTimeout=e.inactivityTimeout??12e4,this.maxReadBufferLength=e.maxReadBufferLength??Zo,this.maxWriteBufferLength=e.maxWriteBufferLength,this.maxMessageSize=e.maxMessageSize,this.readBuffer=new Ie,this.writeBuffer=new Ie,this.readStatus="readable",this.remoteReadStatus="readable",this.writeStatus="writable",this.remoteWriteStatus="writable",this.sendingData=!1,this.writableNeedsDrain=!1,this.timeline={open:Date.now()},this.processSendQueue=this.processSendQueue.bind(this);let t=()=>{this.writableNeedsDrain&&(this.log.trace("drain event received, continue sending data"),this.writableNeedsDrain=!1,queueMicrotask(()=>{try{this.processSendQueue()}catch(s){this.log.error("processSendQueue threw - %e",s)}})),this.onDrainPromise?.resolve()};this.addEventListener("drain",t);let n=s=>{this.onDrainPromise?.reject(s.error??new yt)};this.addEventListener("close",n)}get readBufferLength(){return this.readBuffer.byteLength}get readableEnded(){return this.#e}get writeBufferLength(){return this.writeBuffer.byteLength}async onDrain(e){return this.writableNeedsDrain!==!0?Promise.resolve():(this.onDrainPromise==null&&(this.onDrainPromise=Promise.withResolvers()),Mn(this.onDrainPromise.promise,e?.signal))}async*[Symbol.asyncIterator](){if(this.readStatus!=="readable"&&this.readStatus!=="paused")return;let e=Nn(),t=o=>{e.push(o.data)};this.addEventListener("message",t);let n=o=>{e.end(o.error)};this.addEventListener("close",n);let s=()=>{e.end()};this.addEventListener("remoteCloseWrite",s);try{yield*e}finally{this.removeEventListener("message",t),this.removeEventListener("close",n),this.removeEventListener("remoteCloseWrite",s)}}isReadable(){return this.status==="open"}send(e){if(this.writeStatus==="closed"||this.writeStatus==="closing")throw new Y(`Cannot write to a stream that is ${this.writeStatus}`);return this.log.trace("append %d bytes to write buffer",e.byteLength),this.writeBuffer.append(e),this.processSendQueue()}abort(e){if(!(this.status==="aborted"||this.status==="reset"||this.status==="closed")){this.log.error("abort with error - %e",e),this.status="aborted",this.readBuffer.byteLength>0&&this.readBuffer.consume(this.readBuffer.byteLength),this.writeBuffer.byteLength>0&&(this.writeBuffer.consume(this.writeBuffer.byteLength),this.safeDispatchEvent("idle")),this.writeStatus="closed",this.remoteWriteStatus="closed",this.readStatus="closed",this.remoteReadStatus="closed",this.timeline.close=Date.now(),this.maybeDispatchEnd();try{this.sendReset(e)}catch(t){this.log.error("failed to send reset to remote - %e",t)}this.dispatchEvent(new Qe(e))}}pause(){if(this.readStatus==="closed"||this.readStatus==="closing")throw new Y("Cannot pause a stream that is closing/closed");this.readStatus!=="paused"&&(this.readStatus="paused",this.sendPause())}resume(){if(this.readStatus==="closed"||this.readStatus==="closing")throw new Y("Cannot resume a stream that is closing/closed");this.readStatus!=="readable"&&(this.readStatus="readable",this.dispatchReadBuffer(),this.sendResume())}push(e){if(this.readStatus==="closed"||this.readStatus==="closing")throw new Y(`Cannot push data onto a stream that is ${this.readStatus}`);if(e.byteLength!==0){if(this.readBuffer.append(e),this.readStatus==="paused"||this.listenerCount("message")===0){this.checkReadBufferLength();return}setTimeout(()=>{this.dispatchReadBuffer()},0)}}unshift(e){if(this.readStatus==="closed"||this.readStatus==="closing")throw new Y(`Cannot push data onto a stream that is ${this.readStatus}`);if(e.byteLength!==0){if(this.readBuffer.prepend(e),this.readStatus==="paused"||this.listenerCount("message")===0){this.checkReadBufferLength();return}setTimeout(()=>{this.dispatchReadBuffer()},0)}}onData(e){if(e.byteLength!==0){if(this.readStatus==="closing"||this.readStatus==="closed"){this.log("ignoring data - read status %s",this.readStatus);return}this.readBuffer.append(e),this.dispatchReadBuffer()}}addEventListener(...e){super.addEventListener.apply(this,e),e[0]==="message"&&this.readBuffer.byteLength>0&&queueMicrotask(()=>{this.dispatchReadBuffer()})}onRemoteReset(){this.log("remote reset"),this.status="reset",this.writeStatus="closed",this.remoteWriteStatus="closed",this.remoteReadStatus="closed",this.timeline.close=Date.now(),this.readBuffer.byteLength===0&&(this.readStatus="closed",this.maybeDispatchEnd()),this.dispatchEvent(new Ge(new We))}onTransportClosed(e){this.log("transport closed"),this.readStatus==="readable"&&this.readBuffer.byteLength===0&&(this.log("close readable end after transport closed and read buffer is empty"),this.readStatus="closed"),this.remoteReadStatus!=="closed"&&(this.remoteReadStatus="closed"),this.remoteWriteStatus!=="closed"&&(this.remoteWriteStatus="closed"),this.writeStatus!=="closed"&&(this.writeStatus="closed"),e!=null?this.abort(e):(this.status==="open"||this.status==="closing")&&(this.timeline.close=Date.now(),this.status="closed",this.maybeDispatchEnd(),this.dispatchEvent(new fe))}onRemoteCloseWrite(){this.remoteWriteStatus!=="closed"&&(this.log.trace("on remote close write"),this.remoteWriteStatus="closed",this.safeDispatchEvent("remoteCloseWrite"),this.maybeDispatchEnd(),this.writeStatus==="closed"&&this.onTransportClosed())}onRemoteCloseRead(){this.log.trace("on remote close read"),this.remoteReadStatus="closed",this.writeBuffer.byteLength>0&&(this.writeBuffer.consume(this.writeBuffer.byteLength),this.safeDispatchEvent("idle"))}processSendQueue(){if(this.writableNeedsDrain)return this.log.trace("not processing send queue as drain is required"),this.checkWriteBufferLength(),!1;if(this.writeBuffer.byteLength===0)return this.log.trace("not processing send queue as no bytes to send"),!0;if(this.sendingData)return this.log.trace("not processing send queue as already sending data"),!0;if(this.writeStatus!=="writable"&&this.writeStatus!=="closing")return this.log.trace("not processing send queue as stream is %s",this.writeStatus),!1;this.sendingData=!0,this.log.trace("processing send queue with %d queued bytes",this.writeBuffer.byteLength);try{let e=!0,t=this.writeBuffer.byteLength,n=0;for(;this.writeBuffer.byteLength>0;){let s=Math.min(this.maxMessageSize??this.writeBuffer.byteLength,this.writeBuffer.byteLength);if(s===0){e=!1;break}let o=this.writeBuffer.sublist(0,s),i=new Ie(o);this.writeBuffer.consume(o.byteLength);let a;try{a=this.sendData(o)}catch(c){throw this.writeBuffer.prepend(i),this.abort(c),c}if(e=a.canSendMore,n+=a.sentBytes,a.sentBytes!==i.byteLength&&(i.consume(a.sentBytes),this.writeBuffer.prepend(i)),!e)break}return e||(this.log.trace("sent %d/%d bytes, pausing sending because underlying stream is full, %d bytes left in the write buffer",n,t,this.writeBuffer.byteLength),this.writableNeedsDrain=!0,this.checkWriteBufferLength()),this.writeBuffer.byteLength===0&&this.safeDispatchEvent("idle"),e}finally{this.sendingData=!1}}maybeDispatchEnd(){this.#e||this.readBuffer.byteLength>0||this.remoteWriteStatus!=="closed"&&this.readStatus!=="closed"||(this.#e=!0,this.safeDispatchEvent("end"))}dispatchReadBuffer(){try{if(this.listenerCount("message")===0){this.log.trace("not dispatching pause buffer as there are no listeners for the message event");return}if(this.readBuffer.byteLength===0){this.log.trace("not dispatching pause buffer as there is no data to dispatch");return}if(this.readStatus==="paused"){this.log.trace("not dispatching pause buffer we are paused");return}if(this.readStatus==="closing"||this.readStatus==="closed"){this.log("dropping %d bytes because the readable end is %s",this.readBuffer.byteLength,this.readStatus),this.readBuffer.consume(this.readBuffer.byteLength);return}let e=this.readBuffer.sublist();this.readBuffer.consume(e.byteLength),this.dispatchEvent(new He(e))}finally{this.readBuffer.byteLength===0&&this.remoteWriteStatus==="closed"&&(this.log("close readable end after dispatching read buffer and remote writable end is closed"),this.readStatus="closed",this.maybeDispatchEnd()),this.checkReadBufferLength()}}checkReadBufferLength(){this.readBuffer.byteLength>this.maxReadBufferLength&&this.abort(new Le(`Read buffer length of ${this.readBuffer.byteLength} exceeded limit of ${this.maxReadBufferLength}, read status is ${this.readStatus}`))}checkWriteBufferLength(){this.maxWriteBufferLength!=null&&this.writeBuffer.byteLength>this.maxWriteBufferLength&&this.abort(new Le(`Write buffer length of ${this.writeBuffer.byteLength} exceeded limit of ${this.maxWriteBufferLength}, write status is ${this.writeStatus}`))}onMuxerNeedsDrain(){this.writableNeedsDrain=!0}onMuxerDrain(){this.safeDispatchEvent("drain")}};var Et=class extends xt{remoteAddr;metricPrefix;metrics;constructor(e){super(e),this.metricPrefix=e.metricPrefix??"",this.metrics=e.metrics,this.remoteAddr=e.remoteAddr,this.addEventListener("close",t=>{this.metrics?.increment({[`${this.metricPrefix}end`]:!0}),t.error!=null?t.local?this.metrics?.increment({[`${this.metricPrefix}abort`]:!0}):this.metrics?.increment({[`${this.metricPrefix}reset`]:!0}):t.local?this.metrics?.increment({[`${this.metricPrefix}_local_close`]:!0}):this.metrics?.increment({[`${this.metricPrefix}_remote_close`]:!0})})}async close(e){this.status==="open"&&(this.status="closing",this.writeStatus="closing",this.remoteWriteStatus="closing",this.remoteReadStatus="closing",(this.sendingData||this.writeBuffer.byteLength>0)&&(this.log("waiting for write queue to become idle before closing writable end of stream, %d unsent bytes",this.writeBuffer.byteLength),await se(this,"idle",{...e,rejectionEvents:["close"]})),this.writableNeedsDrain&&(this.log("waiting for write queue to drain before closing writable end of stream, %d unsent bytes",this.writeBuffer.byteLength),await se(this,"drain",{...e,rejectionEvents:["close"]})),await this.sendClose(e),this.onTransportClosed())}};var kn=ue(k("node:os"),1);function Rn(r){return!!(r.startsWith("169.254.")||r.toLowerCase().startsWith("fe80"))}function Or(r,e,t){let n=[r.type,t??r.host];if(r.protocol!=null){let s=e??r.port;s!=null&&n.push(r.protocol,s)}return r.type==="ip6"&&r.zone!=null&&n.unshift("ip6zone",r.zone),r.cidr!=null&&n.push("ipcidr",r.cidr),ce(`/${n.join("/")}`)}var ei={4:"IPv4",6:"IPv6"};function ti(r){return["0.0.0.0","::"].includes(r)}function ri(r){let e=[],t=kn.default.networkInterfaces();for(let[,n]of Object.entries(t))if(n!=null)for(let s of n)Rn(s.address)||s.family===ei[r]&&e.push(s.address);return e}function Vn(r,e){if(r==null)return[];let t=gt(r);return(t.type==="ip4"||t.type==="ip6")&&ti(t.host)?ri(t.type==="ip4"?4:6).map(n=>Or(t,e,n)):[Or(t,e)]}function zn(r,e){if(typeof r!="string")throw new _(`invalid ip provided: ${r}`);if(typeof e=="string"&&(e=parseInt(e)),isNaN(e))throw new _(`invalid port provided: ${e}`);if((0,N.isIPv4)(r))return ce(`/ip4/${r}/tcp/${e}`);if((0,N.isIPv6)(r))return ce(`/ip6/${r}/tcp/${e}`);throw new _(`invalid ip:port for creating a multiaddr: ${r}:${e}`)}var _r=class extends Et{socket;constructor(e){let t=e.remoteAddr;if(e.localAddr!=null&&Ve.matches(e.localAddr))t=e.localAddr;else if(t==null){if(e.socket.remoteAddress==null||e.socket.remotePort==null)throw new _("Could not determine remote address or port");t=zn(e.socket.remoteAddress,e.socket.remotePort)}super({...e,remoteAddr:t}),this.socket=e.socket,this.socket.on("data",n=>{this.onData(n)}),this.socket.on("error",n=>{this.log("tcp error",t,n),this.abort(n)}),this.socket.setTimeout(e.inactivityTimeout??120*1e3),this.socket.once("timeout",()=>{this.log("tcp timeout",t),this.abort(new le)}),this.socket.once("end",()=>{this.log("tcp end",t),this.onTransportClosed()}),this.socket.once("close",n=>{if(this.log("tcp close",t),n){this.abort(new Error("TCP transmission error"));return}this.onTransportClosed()}),this.socket.on("drain",()=>{this.log("tcp drain"),this.safeDispatchEvent("drain")})}sendData(e){let t=0,n=!0;for(let s of e)if(t+=s.byteLength,n=this.socket.write(s),!n)break;return{sentBytes:t,canSendMore:n}}async sendClose(e){this.socket.destroyed||(this.socket.destroySoon(),await se(this.socket,"close",e))}sendReset(){if(this.socket.writableEnded){this.socket.destroy();return}if(Ve.matches(this.remoteAddr)){this.socket.destroy();return}this.socket.resetAndDestroy()}sendPause(){this.socket.pause()}sendResume(){this.socket.resume()}},vt=r=>new _r(r);var $n=ue(k("os"),1),Fn=ue(k("path"),1);function Ct(r,e={}){if(Ve.exactMatch(r)){let o=r.getComponents().find(i=>i.code===400)?.value;if(o==null)throw new _(`Multiaddr ${r} was not a Unix address`);return $n.default.platform()==="win32"?{path:Fn.default.join("\\\\.\\pipe\\",o)}:{path:o}}let t=gt(r),n=t.host,s=t.port;return{host:n,port:s,ipv6Only:t.type==="ip6",...e}}var I;(function(r){r[r.INACTIVE=0]="INACTIVE",r[r.ACTIVE=1]="ACTIVE",r[r.PAUSED=2]="PAUSED"})(I||(I={}));var St=class extends he{context;server;sockets=new Set;status={code:I.INACTIVE};metrics;addr;log;shutdownController;constructor(e){if(super(),this.context=e,e.keepAlive=e.keepAlive??!0,e.noDelay=e.noDelay??!0,e.allowHalfOpen=e.allowHalfOpen??!1,this.shutdownController=new AbortController,Xe(1/0,this.shutdownController.signal),this.log=e.logger.forComponent("libp2p:tcp:listener"),this.addr="unknown",this.server=Wn.default.createServer(e,this.onSocket.bind(this)),e.maxConnections!==void 0&&(this.server.maxConnections=e.maxConnections),e.closeServerOnMaxConnections!=null&&e.closeServerOnMaxConnections.closeAbove<e.closeServerOnMaxConnections.listenBelow)throw new _("closeAbove must be >= listenBelow");e.metrics?.registerMetricGroup("libp2p_tcp_inbound_connections_total",{label:"address",help:"Current active connections in TCP listener",calculate:()=>({[this.addr]:this.sockets.size})}),this.metrics={status:e.metrics?.registerMetricGroup("libp2p_tcp_listener_status_info",{label:"address",help:"Current status of the TCP listener socket"}),errors:e.metrics?.registerMetricGroup("libp2p_tcp_listener_errors_total",{label:"address",help:"Total count of TCP listener errors by type"}),events:e.metrics?.registerMetricGroup("libp2p_tcp_listener_events_total",{label:"address",help:"Total count of TCP listener events by type"})},this.server.on("listening",()=>{let t=this.server.address();t==null?this.addr="unknown":typeof t=="string"?this.addr=t:this.addr=`${t.address}:${t.port}`,this.metrics.status?.update({[this.addr]:I.ACTIVE}),this.safeDispatchEvent("listening")}).on("error",t=>{this.metrics.errors?.increment({[`${this.addr} listen_error`]:!0}),this.safeDispatchEvent("error",{detail:t})}).on("close",()=>{this.metrics.status?.update({[this.addr]:this.status.code}),this.status.code!==I.PAUSED&&this.safeDispatchEvent("close")}).on("drop",()=>{this.metrics.events?.increment({[`${this.addr} drop`]:!0})})}onSocket(e){if(this.metrics.events?.increment({[`${this.addr} connection`]:!0}),this.status.code!==I.ACTIVE)throw e.destroy(),new je("Server is not listening yet");let t;try{t=vt({socket:e,inactivityTimeout:this.context.inactivityTimeout,metrics:this.metrics?.events,metricPrefix:`${this.addr} `,direction:"inbound",localAddr:this.status.listeningAddr,log:this.context.logger.forComponent("libp2p:tcp:connection")})}catch(n){this.log.error("inbound connection failed - %e",n),this.metrics.errors?.increment({[`${this.addr} inbound_to_connection`]:!0}),e.destroy();return}this.log("new inbound connection %s",t.remoteAddr),this.sockets.add(e),this.context.upgrader.upgradeInbound(t,{signal:this.shutdownController.signal}).then(()=>{this.log("inbound connection upgraded %s",t.remoteAddr),e.once("close",()=>{this.sockets.delete(e),this.context.closeServerOnMaxConnections!=null&&this.sockets.size<this.context.closeServerOnMaxConnections.listenBelow&&this.resume().catch(n=>{this.log.error("error attempting to listen server once connection count under limit - %e",n),this.context.closeServerOnMaxConnections?.onListenError?.(n)})}),this.context.closeServerOnMaxConnections!=null&&this.sockets.size>=this.context.closeServerOnMaxConnections.closeAbove&&(this.log("pausing incoming connections as limit is exceeded - %d/%d",this.sockets.size,this.context.closeServerOnMaxConnections.closeAbove),this.pause())}).catch(async n=>{this.log.error("inbound connection upgrade failed - %e",n),this.metrics.errors?.increment({[`${this.addr} inbound_upgrade`]:!0}),this.sockets.delete(e),t.abort(n)})}getAddrs(){if(this.status.code===I.INACTIVE)return[];let e=this.server.address();return e==null?[]:typeof e=="string"?[ce(`/unix/${encodeURIComponent(e)}`)]:Vn(this.status.listeningAddr,e.port)}updateAnnounceAddrs(){}async listen(e){if(this.status.code===I.ACTIVE||this.status.code===I.PAUSED)throw new qe("server is already listening");try{this.status={code:I.ACTIVE,listeningAddr:e,netConfig:Ct(e,this.context)},await this.resume()}catch(t){throw this.status={code:I.INACTIVE},t}}async close(e){let t=[];this.server.listening&&t.push(se(this.server,"close",e)),this.pause(!0),this.shutdownController.abort(),this.sockets.forEach(n=>{n.readable&&(t.push(se(n,"close",e)),n.destroy())}),await Promise.all(t)}async resume(){if(this.server.listening||this.status.code===I.INACTIVE)return;let e=this.status.netConfig;await new Promise((t,n)=>{this.server.once("error",n),this.server.listen(e,t)}),this.status={...this.status,code:I.ACTIVE},this.log("listening on %s",this.server.address())}pause(e=!1){if(!this.server.listening&&this.status.code===I.PAUSED&&e){this.status={code:I.INACTIVE};return}!this.server.listening||this.status.code!==I.ACTIVE||(this.log("%s server on %s",e?"closing":"pausing",this.server.address()),this.status=e?{code:I.INACTIVE}:{...this.status,code:I.PAUSED},this.server.close())}};var Dt=class{opts;metrics;components;log;constructor(e,t={}){this.log=e.logger.forComponent("libp2p:tcp"),this.opts=t,this.components=e,e.metrics!=null&&(this.metrics={events:e.metrics.registerCounterGroup("libp2p_tcp_dialer_events_total",{label:"event",help:"Total count of TCP dialer events by type"}),errors:e.metrics.registerCounterGroup("libp2p_tcp_dialer_errors_total",{label:"event",help:"Total count of TCP dialer events by type"})})}[Ur]=!0;[Symbol.toStringTag]="@libp2p/tcp";[kr]=["@libp2p/transport"];async dial(e,t){t.keepAlive=t.keepAlive??!0,t.noDelay=t.noDelay??!0,t.allowHalfOpen=t.allowHalfOpen??!1;let n=await this._connect(e,t),s;try{s=vt({socket:n,inactivityTimeout:this.opts.outboundSocketInactivityTimeout,metrics:this.metrics?.events,direction:"outbound",remoteAddr:e,log:this.log.newScope("connection")})}catch(o){throw this.metrics?.errors.increment({outbound_to_connection:!0}),n.destroy(o),o}try{return this.log("new outbound connection %s",s.remoteAddr),await t.upgrader.upgradeOutbound(s,t)}catch(o){throw this.metrics?.errors.increment({outbound_upgrade:!0}),this.log.error("error upgrading outbound connection - %e",o),s.abort(o),o}}async _connect(e,t){t.signal.throwIfAborted(),t.onProgress?.(new pt("tcp:open-connection"));let n;return new Promise((s,o)=>{let i=Date.now(),a=Ct(e,{...this.opts.dialOpts??{},...t});this.log("dialing %a with opts %o",e,a),n=jn.default.connect(a);let c=p=>{this.log.error("dial to %a errored - %e",e,p);let $=a.path??`${a.host??""}:${a.port}`;p.message=`connection error ${$}: ${p.message}`,this.metrics?.events.increment({error:!0}),b(p)},l=()=>{this.log("connection timeout %a",e),this.metrics?.events.increment({timeout:!0});let p=new le(`Connection timeout after ${Date.now()-i}ms`);n.emit("error",p)},f=()=>{this.log("connection opened %a",e),this.metrics?.events.increment({connect:!0}),b()},h=()=>{this.log("connection aborted %a",e),this.metrics?.events.increment({abort:!0}),b(new Fe)},b=p=>{if(n.removeListener("error",c),n.removeListener("timeout",l),n.removeListener("connect",f),t.signal!=null&&t.signal.removeEventListener("abort",h),p!=null){o(p);return}s(n)};n.on("error",c),n.on("timeout",l),n.on("connect",f),t.signal.addEventListener("abort",h)}).catch(s=>{throw n?.destroy(),s})}createListener(e){return new St({...this.opts.listenOpts??{},...e,maxConnections:this.opts.maxConnections,backlog:this.opts.backlog,closeServerOnMaxConnections:this.opts.closeServerOnMaxConnections,inactivityTimeout:this.opts.inboundSocketInactivityTimeout,metrics:this.components.metrics,logger:this.components.logger})}listenFilter(e){return e.filter(t=>Tn.exactMatch(t)||t.toString().startsWith("/unix/"))}dialFilter(e){return this.listenFilter(e)}};function ni(r={}){return e=>new Dt(e,r)}return Jn(si);})();
|
|
3
3
|
return Libp2PTcp}));
|
|
4
4
|
//# sourceMappingURL=index.min.js.map
|