@libp2p/tcp 9.0.19 → 9.0.20-31c78f4ed
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.min.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
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 Rr=Object.create;var me=Object.defineProperty;var Nr=Object.getOwnPropertyDescriptor;var Dr=Object.getOwnPropertyNames;var Mr=Object.getPrototypeOf,_r=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 R=(r,e)=>{for(var t in e)me(r,t,{get:e[t],enumerable:!0})},At=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Dr(e))!_r.call(r,o)&&o!==t&&me(r,o,{get:()=>e[o],enumerable:!(n=Nr(e,o))||n.enumerable});return r};var de=(r,e,t)=>(t=r!=null?Rr(Mr(r)):{},At(e||!r||!r.__esModule?me(t,"default",{value:r,enumerable:!0}):t,r)),Ur=r=>At(me({},"__esModule",{value:!0}),r);var ko={};R(ko,{tcp:()=>Uo});var Pr=de(k("net"),1);var Ct=Symbol.for("@libp2p/transport");var It;(function(r){r[r.FATAL_ALL=0]="FATAL_ALL",r[r.NO_FATAL=1]="NO_FATAL"})(It||(It={}));var Z=class r extends Error{code;type;constructor(e="The operation was aborted"){super(e),this.name="AbortError",this.code=r.code,this.type=r.type}static code="ABORT_ERR";static type="aborted"},A=class extends Error{code;props;constructor(e,t,n){super(e),this.code=t,this.name=n?.name??"CodeError",this.props=n??{}}};var St=k("events"),Tt=(r,...e)=>{try{(0,St.setMaxListeners)(r,...e)}catch{}};var ge=class extends EventTarget{#e=new Map;constructor(){super(),Tt(1/0,this)}listenerCount(e){let t=this.#e.get(e);return t==null?0:t.length}addEventListener(e,t,n){super.addEventListener(e,t,n);let o=this.#e.get(e);o==null&&(o=[],this.#e.set(e,o)),o.push({callback:t,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(e,t,n){super.removeEventListener(e.toString(),t??null,n);let o=this.#e.get(e);o!=null&&(o=o.filter(({callback:s})=>s!==t),this.#e.set(e,o))}dispatchEvent(e){let t=super.dispatchEvent(e),n=this.#e.get(e.type);return n==null||(n=n.filter(({once:o})=>!o),this.#e.set(e.type,n)),t}safeDispatchEvent(e,t={}){return this.dispatchEvent(new kr(e,t))}},Ne=class extends Event{detail;constructor(e,t){super(e,t),this.detail=t?.detail}},kr=globalThis.CustomEvent??Ne;var ke={};R(ke,{base58btc:()=>T,base58flickr:()=>zr});var Bo=new Uint8Array(0);function Pt(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 D(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")}function Rt(r){return new TextEncoder().encode(r)}function Nt(r){return new TextDecoder().decode(r)}function Lr(r,e){if(r.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),n=0;n<t.length;n++)t[n]=255;for(var o=0;o<r.length;o++){var s=r.charAt(o),i=s.charCodeAt(0);if(t[i]!==255)throw new TypeError(s+" is ambiguous");t[i]=o}var a=r.length,p=r.charAt(0),f=Math.log(a)/Math.log(256),m=Math.log(256)/Math.log(a);function v(l){if(l instanceof Uint8Array||(ArrayBuffer.isView(l)?l=new Uint8Array(l.buffer,l.byteOffset,l.byteLength):Array.isArray(l)&&(l=Uint8Array.from(l))),!(l instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(l.length===0)return"";for(var b=0,_=0,g=0,C=l.length;g!==C&&l[g]===0;)g++,b++;for(var O=(C-g)*m+1>>>0,N=new Uint8Array(O);g!==C;){for(var V=l[g],j=0,U=O-1;(V!==0||j<_)&&U!==-1;U--,j++)V+=256*N[U]>>>0,N[U]=V%a>>>0,V=V/a>>>0;if(V!==0)throw new Error("Non-zero carry");_=j,g++}for(var $=O-_;$!==O&&N[$]===0;)$++;for(var he=p.repeat(b);$<O;++$)he+=r.charAt(N[$]);return he}function x(l){if(typeof l!="string")throw new TypeError("Expected String");if(l.length===0)return new Uint8Array;var b=0;if(l[b]!==" "){for(var _=0,g=0;l[b]===p;)_++,b++;for(var C=(l.length-b)*f+1>>>0,O=new Uint8Array(C);l[b];){var N=t[l.charCodeAt(b)];if(N===255)return;for(var V=0,j=C-1;(N!==0||V<g)&&j!==-1;j--,V++)N+=a*O[j]>>>0,O[j]=N%256>>>0,N=N/256>>>0;if(N!==0)throw new Error("Non-zero carry");g=V,b++}if(l[b]!==" "){for(var U=C-g;U!==C&&O[U]===0;)U++;for(var $=new Uint8Array(_+(C-U)),he=_;U!==C;)$[he++]=O[U++];return $}}}function u(l){var b=x(l);if(b)return b;throw new Error(`Non-${e} character`)}return{encode:v,decodeUnsafe:x,decode:u}}var Or=Lr,Vr=Or,Mt=Vr;var De=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")}},Me=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,t,n){if(this.name=e,this.prefix=t,t.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=t.codePointAt(0),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 _t(this,e)}},_e=class{decoders;constructor(e){this.decoders=e}or(e){return _t(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 _t(r,e){return new _e({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var Ue=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 De(e,t,n),this.decoder=new Me(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function ee({name:r,prefix:e,encode:t,decode:n}){return new Ue(r,e,t,n)}function q({name:r,prefix:e,alphabet:t}){let{encode:n,decode:o}=Mt(t,r);return ee({prefix:e,name:r,encode:n,decode:s=>D(o(s))})}function Fr(r,e,t,n){let o={};for(let m=0;m<e.length;++m)o[e[m]]=m;let s=r.length;for(;r[s-1]==="=";)--s;let i=new Uint8Array(s*t/8|0),a=0,p=0,f=0;for(let m=0;m<s;++m){let v=o[r[m]];if(v===void 0)throw new SyntaxError(`Non-${n} character`);p=p<<t|v,a+=t,a>=8&&(a-=8,i[f++]=255&p>>a)}if(a>=t||255&p<<8-a)throw new SyntaxError("Unexpected end of data");return i}function $r(r,e,t){let n=e[e.length-1]==="=",o=(1<<t)-1,s="",i=0,a=0;for(let p=0;p<r.length;++p)for(a=a<<8|r[p],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;)s+="=";return s}function y({name:r,prefix:e,bitsPerChar:t,alphabet:n}){return ee({prefix:e,name:r,encode(o){return $r(o,n,t)},decode(o){return Fr(o,n,t,r)}})}var T=q({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),zr=q({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Le={};R(Le,{base32:()=>z,base32hex:()=>Gr,base32hexpad:()=>Hr,base32hexpadupper:()=>Xr,base32hexupper:()=>Wr,base32pad:()=>jr,base32padupper:()=>qr,base32upper:()=>Br,base32z:()=>Jr});var z=y({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Br=y({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),jr=y({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),qr=y({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Gr=y({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Wr=y({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Hr=y({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Xr=y({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Jr=y({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Qr=Lt,Ut=128,Kr=127,Yr=~Kr,Zr=Math.pow(2,31);function Lt(r,e,t){e=e||[],t=t||0;for(var n=t;r>=Zr;)e[t++]=r&255|Ut,r/=128;for(;r&Yr;)e[t++]=r&255|Ut,r>>>=7;return e[t]=r|0,Lt.bytes=t-n+1,e}var en=Oe,tn=128,kt=127;function Oe(r,n){var t=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw Oe.bytes=0,new RangeError("Could not decode varint");i=r[s++],t+=o<28?(i&kt)<<o:(i&kt)*Math.pow(2,o),o+=7}while(i>=tn);return Oe.bytes=s-n,t}var rn=Math.pow(2,7),nn=Math.pow(2,14),on=Math.pow(2,21),sn=Math.pow(2,28),cn=Math.pow(2,35),an=Math.pow(2,42),dn=Math.pow(2,49),ln=Math.pow(2,56),un=Math.pow(2,63),pn=function(r){return r<rn?1:r<nn?2:r<on?3:r<sn?4:r<cn?5:r<an?6:r<dn?7:r<ln?8:r<un?9:10},fn={encode:Qr,decode:en,encodingLength:pn},hn=fn,le=hn;function ue(r,e=0){return[le.decode(r,e),le.decode.bytes]}function te(r,e,t=0){return le.encode(r,e,t),e}function re(r){return le.encodingLength(r)}function X(r,e){let t=e.byteLength,n=re(r),o=n+re(t),s=new Uint8Array(o+t);return te(r,s,0),te(t,s,n),s.set(e,o),new ne(r,t,e,s)}function xe(r){let e=D(r),[t,n]=ue(e),[o,s]=ue(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new ne(t,o,i,e)}function Ot(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&Pt(r.bytes,t.bytes)}}var ne=class{code;size;digest;bytes;constructor(e,t,n,o){this.code=e,this.size=t,this.digest=n,this.bytes=o}};function Vt(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return gn(t,Ve(r),e??T.encoder);default:return wn(t,Ve(r),e??z.encoder)}}var Ft=new WeakMap;function Ve(r){let e=Ft.get(r);if(e==null){let t=new Map;return Ft.set(r,t),t}return e}var G=class r{code;version;multihash;bytes;"/";constructor(e,t,n,o){this.code=t,this.version=e,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:t}=this;if(e!==pe)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==xn)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=X(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&&Ot(e.multihash,n.multihash)}toString(e){return Vt(this,e)}toJSON(){return{"/":Vt(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??$t(n,o,s.bytes))}else if(t[bn]===!0){let{version:n,multihash:o,code:s}=t,i=xe(o);return r.create(n,s,i)}else return null}static create(e,t,n){if(typeof t!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(t!==pe)throw new Error(`Version 0 CID must use dag-pb (code: ${pe}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let o=$t(e,t,n.bytes);return new r(e,t,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,pe,e)}static createV1(e,t){return r.create(1,e,t)}static decode(e){let[t,n]=r.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return t}static decodeFirst(e){let t=r.inspectBytes(e),n=t.size-t.multihashSize,o=D(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 ne(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[v,x]=ue(e.subarray(t));return t+=x,v},o=n(),s=pe;if(o===18?(o=0,t=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=t,a=n(),p=n(),f=t+p,m=f-i;return{version:o,codec:s,multihashCode:a,digestSize:p,multihashSize:m,size:f}}static parse(e,t){let[n,o]=mn(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 Ve(s).set(n,e),s}};function mn(r,e){switch(r[0]){case"Q":{let t=e??T;return[T.prefix,t.decode(`${T.prefix}${r}`)]}case T.prefix:{let t=e??T;return[T.prefix,t.decode(r)]}case z.prefix:{let t=e??z;return[z.prefix,t.decode(r)]}default:{if(e==null)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[r[0],e.decode(r)]}}}function gn(r,e,t){let{prefix:n}=t;if(n!==T.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 wn(r,e,t){let{prefix:n}=t,o=e.get(n);if(o==null){let s=t.encode(r);return e.set(n,s),s}else return o}var pe=112,xn=18;function $t(r,e,t){let n=re(r),o=n+re(e),s=new Uint8Array(o+t.byteLength);return te(r,s,0),te(e,s,n),s.set(t,o),s}var bn=Symbol.for("@ipld/js-cid/CID");function zt(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 Jt=k("node:buffer");var Fe={};R(Fe,{base10:()=>yn});var yn=q({prefix:"9",name:"base10",alphabet:"0123456789"});var $e={};R($e,{base16:()=>En,base16upper:()=>vn});var En=y({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),vn=y({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var ze={};R(ze,{base2:()=>An});var An=y({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Be={};R(Be,{base256emoji:()=>Pn});var Bt=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}"),In=Bt.reduce((r,e,t)=>(r[t]=e,r),[]),Cn=Bt.reduce((r,e,t)=>(r[e.codePointAt(0)]=t,r),[]);function Sn(r){return r.reduce((e,t)=>(e+=In[t],e),"")}function Tn(r){let e=[];for(let t of r){let n=Cn[t.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${t}`);e.push(n)}return new Uint8Array(e)}var Pn=ee({prefix:"\u{1F680}",name:"base256emoji",encode:Sn,decode:Tn});var je={};R(je,{base36:()=>Rn,base36upper:()=>Nn});var Rn=q({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Nn=q({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var qe={};R(qe,{base64:()=>Dn,base64pad:()=>Mn,base64url:()=>_n,base64urlpad:()=>Un});var Dn=y({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Mn=y({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),_n=y({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Un=y({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Ge={};R(Ge,{base8:()=>kn});var kn=y({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var We={};R(We,{identity:()=>Ln});var Ln=ee({prefix:"\0",name:"identity",encode:r=>Nt(r),decode:r=>Rt(r)});var fs=new TextEncoder,hs=new TextDecoder;var He={};R(He,{identity:()=>zn});var jt=0,Fn="identity",qt=D;function $n(r){return X(jt,qt(r))}var zn={code:jt,name:Fn,encode:qt,digest:$n};var Ke={};R(Ke,{sha256:()=>Bn,sha512:()=>jn});var Qe=de(k("crypto"),1);function Je({name:r,code:e,encode:t}){return new Xe(r,e,t)}var Xe=class{name;code;encode;constructor(e,t,n){this.name=e,this.code=t,this.encode=n}digest(e){if(e instanceof Uint8Array){let t=this.encode(e);return t instanceof Uint8Array?X(this.code,t):t.then(n=>X(this.code,n))}else throw Error("Unknown type, must be binary type")}};var Bn=Je({name:"sha2-256",code:18,encode:r=>D(Qe.default.createHash("sha256").update(r).digest())}),jn=Je({name:"sha2-512",code:19,encode:r=>D(Qe.default.createHash("sha512").update(r).digest())});var fe={...We,...ze,...Ge,...Fe,...$e,...Le,...je,...ke,...qe,...Be},Ps={...Ke,...He};var Wt=k("node:buffer");function se(r){return new Uint8Array(r.buffer,r.byteOffset,r.byteLength)}function be(r=0){return se(Wt.Buffer.allocUnsafe(r))}function Xt(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var Ht=Xt("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Ye=Xt("ascii","a",r=>{let e="a";for(let t=0;t<r.length;t++)e+=String.fromCharCode(r[t]);return e},r=>{r=r.substring(1);let e=be(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),qn={utf8:Ht,"utf-8":Ht,hex:fe.base16,latin1:Ye,ascii:Ye,binary:Ye,...fe},ye=qn;function P(r,e="utf8"){let t=ye[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return e==="utf8"||e==="utf-8"?Jt.Buffer.from(r.buffer,r.byteOffset,r.byteLength).toString("utf8"):t.encoder.encode(r).substring(1)}var Gn=Math.pow(2,7),Wn=Math.pow(2,14),Hn=Math.pow(2,21),Ze=Math.pow(2,28),et=Math.pow(2,35),tt=Math.pow(2,42),rt=Math.pow(2,49),h=128,S=127;function F(r){if(r<Gn)return 1;if(r<Wn)return 2;if(r<Hn)return 3;if(r<Ze)return 4;if(r<et)return 5;if(r<tt)return 6;if(r<rt)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Xn(r,e,t=0){switch(F(r)){case 8:e[t++]=r&255|h,r/=128;case 7:e[t++]=r&255|h,r/=128;case 6:e[t++]=r&255|h,r/=128;case 5:e[t++]=r&255|h,r/=128;case 4:e[t++]=r&255|h,r>>>=7;case 3:e[t++]=r&255|h,r>>>=7;case 2:e[t++]=r&255|h,r>>>=7;case 1:{e[t++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return e}function Jn(r,e,t=0){switch(F(r)){case 8:e.set(t++,r&255|h),r/=128;case 7:e.set(t++,r&255|h),r/=128;case 6:e.set(t++,r&255|h),r/=128;case 5:e.set(t++,r&255|h),r/=128;case 4:e.set(t++,r&255|h),r>>>=7;case 3:e.set(t++,r&255|h),r>>>=7;case 2:e.set(t++,r&255|h),r>>>=7;case 1:{e.set(t++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return e}function Qn(r,e){let t=r[e],n=0;if(n+=t&S,t<h||(t=r[e+1],n+=(t&S)<<7,t<h)||(t=r[e+2],n+=(t&S)<<14,t<h)||(t=r[e+3],n+=(t&S)<<21,t<h)||(t=r[e+4],n+=(t&S)*Ze,t<h)||(t=r[e+5],n+=(t&S)*et,t<h)||(t=r[e+6],n+=(t&S)*tt,t<h)||(t=r[e+7],n+=(t&S)*rt,t<h))return n;throw new RangeError("Could not decode varint")}function Kn(r,e){let t=r.get(e),n=0;if(n+=t&S,t<h||(t=r.get(e+1),n+=(t&S)<<7,t<h)||(t=r.get(e+2),n+=(t&S)<<14,t<h)||(t=r.get(e+3),n+=(t&S)<<21,t<h)||(t=r.get(e+4),n+=(t&S)*Ze,t<h)||(t=r.get(e+5),n+=(t&S)*et,t<h)||(t=r.get(e+6),n+=(t&S)*tt,t<h)||(t=r.get(e+7),n+=(t&S)*rt,t<h))return n;throw new RangeError("Could not decode varint")}function ie(r,e,t=0){return e==null&&(e=be(F(r))),e instanceof Uint8Array?Xn(r,e,t):Jn(r,e,t)}function J(r,e=0){return r instanceof Uint8Array?Qn(r,e):Kn(r,e)}var Kt=k("node:buffer");function B(r,e){return se(Kt.Buffer.concat(r,e))}var Ee=class{index=0;input="";new(e){return this.index=0,this.input=e,this}readAtomically(e){let t=this.index,n=e();return n===void 0&&(this.index=t),n}parseWith(e){let t=e();if(this.index===this.input.length)return t}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(e){return this.readAtomically(()=>{let t=this.readChar();if(t===e)return t})}readSeparator(e,t,n){return this.readAtomically(()=>{if(!(t>0&&this.readGivenChar(e)===void 0))return n()})}readNumber(e,t,n,o){return this.readAtomically(()=>{let s=0,i=0,a=this.peekChar();if(a===void 0)return;let p=a==="0",f=2**(8*o)-1;for(;;){let m=this.readAtomically(()=>{let v=this.readChar();if(v===void 0)return;let x=Number.parseInt(v,e);if(!Number.isNaN(x))return x});if(m===void 0)break;if(s*=e,s+=m,s>f||(i+=1,t!==void 0&&i>t))return}if(i!==0)return!n&&p&&i>1?void 0:s})}readIPv4Addr(){return this.readAtomically(()=>{let e=new Uint8Array(4);for(let t=0;t<e.length;t++){let n=this.readSeparator(".",t,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;e[t]=n}return e})}readIPv6Addr(){let e=t=>{for(let n=0;n<t.length/2;n++){let o=n*2;if(n<t.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return t[o]=i[0],t[o+1]=i[1],t[o+2]=i[2],t[o+3]=i[3],[o+4,!0]}let s=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(s===void 0)return[o,!1];t[o]=s>>8,t[o+1]=s&255}return[t.length,!1]};return this.readAtomically(()=>{let t=new Uint8Array(16),[n,o]=e(t);if(n===16)return t;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let s=new Uint8Array(14),i=16-(n+2),[a]=e(s.subarray(0,i));return t.set(s.subarray(0,a),16-a),t})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var js=new Ee;var Ks=parseInt("0xFFFF",16),Ys=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);var er=k("node:buffer");function nt(r,e="utf8"){let t=ye[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return e==="utf8"||e==="utf-8"?se(er.Buffer.from(r,"utf-8")):t.decoder.decode(`${t.prefix}${r}`)}var M=k("node:net");function ve(r){return!!(0,M.isIP)(r)}var tr=M.isIPv4,no=M.isIPv6,ot=function(r){let e=0;if(r=r.toString().trim(),tr(r)){let t=new Uint8Array(e+4);return r.split(/\./g).forEach(n=>{t[e++]=parseInt(n,10)&255}),t}if(no(r)){let t=r.split(":",8),n;for(n=0;n<t.length;n++){let s=tr(t[n]),i;s&&(i=ot(t[n]),t[n]=P(i.slice(0,2),"base16")),i!=null&&++n<8&&t.splice(n,0,P(i.slice(2,4),"base16"))}if(t[0]==="")for(;t.length<8;)t.unshift("0");else if(t[t.length-1]==="")for(;t.length<8;)t.push("0");else if(t.length<8){for(n=0;n<t.length&&t[n]!=="";n++);let s=[n,1];for(n=9-t.length;n>0;n--)s.push("0");t.splice.apply(t,s)}let o=new Uint8Array(e+16);for(n=0;n<t.length;n++){let s=parseInt(t[n],16);o[e++]=s>>8&255,o[e++]=s&255}return o}throw new Error("invalid ip address")},rr=function(r,e=0,t){e=~~e,t=t??r.length-e;let n=new DataView(r.buffer);if(t===4){let o=[];for(let s=0;s<t;s++)o.push(r[e+s]);return o.join(".")}if(t===16){let o=[];for(let s=0;s<t;s+=2)o.push(n.getUint16(e+s).toString(16));return o.join(":").replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}return""};var ce={},st={},so=[[4,32,"ip4"],[6,16,"tcp"],[33,16,"dccp"],[41,128,"ip6"],[42,-1,"ip6zone"],[43,8,"ipcidr"],[53,-1,"dns",!0],[54,-1,"dns4",!0],[55,-1,"dns6",!0],[56,-1,"dnsaddr",!0],[132,16,"sctp"],[273,16,"udp"],[275,0,"p2p-webrtc-star"],[276,0,"p2p-webrtc-direct"],[277,0,"p2p-stardust"],[280,0,"webrtc-direct"],[281,0,"webrtc"],[290,0,"p2p-circuit"],[301,0,"udt"],[302,0,"utp"],[400,-1,"unix",!1,!0],[421,-1,"ipfs"],[421,-1,"p2p"],[443,0,"https"],[444,96,"onion"],[445,296,"onion3"],[446,-1,"garlic64"],[448,0,"tls"],[449,-1,"sni"],[460,0,"quic"],[461,0,"quic-v1"],[465,0,"webtransport"],[466,-1,"certhash"],[477,0,"ws"],[478,0,"wss"],[479,0,"p2p-websocket-star"],[480,0,"http"],[777,-1,"memory"]];so.forEach(r=>{let e=io(...r);st[e.code]=e,ce[e.name]=e});function io(r,e,t,n,o){return{code:r,size:e,name:t,resolvable:!!n,path:!!o}}function w(r){if(typeof r=="number"){if(st[r]!=null)return st[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(ce[r]!=null)return ce[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var Fi=w("ip4"),$i=w("ip6"),zi=w("ipcidr");function ct(r,e){switch(w(r).code){case 4:case 41:return ao(e);case 42:return sr(e);case 6:case 273:case 33:case 132:return cr(e).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return sr(e);case 421:return fo(e);case 444:return ir(e);case 445:return ir(e);case 466:return po(e);default:return P(e,"base16")}}function at(r,e){switch(w(r).code){case 4:return nr(e);case 41:return nr(e);case 42:return or(e);case 6:case 273:case 33:case 132:return dt(parseInt(e,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return or(e);case 421:return lo(e);case 444:return ho(e);case 445:return mo(e);case 466:return uo(e);default:return nt(e,"base16")}}var it=Object.values(fe).map(r=>r.decoder),co=function(){let r=it[0].or(it[1]);return it.slice(2).forEach(e=>r=r.or(e)),r}();function nr(r){if(!ve(r))throw new Error("invalid ip address");return ot(r)}function ao(r){let e=rr(r,0,r.length);if(e==null)throw new Error("ipBuff is required");if(!ve(e))throw new Error("invalid ip address");return e}function dt(r){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,r),new Uint8Array(e)}function cr(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function or(r){let e=nt(r),t=Uint8Array.from(ie(e.length));return B([t,e],t.length+e.length)}function sr(r){let e=J(r);if(r=r.slice(F(e)),r.length!==e)throw new Error("inconsistent lengths");return P(r)}function lo(r){let e;r[0]==="Q"||r[0]==="1"?e=xe(T.decode(`z${r}`)).bytes:e=G.parse(r).multihash.bytes;let t=Uint8Array.from(ie(e.length));return B([t,e],t.length+e.length)}function uo(r){let e=co.decode(r),t=Uint8Array.from(ie(e.length));return B([t,e],t.length+e.length)}function po(r){let e=J(r),t=r.slice(F(e));if(t.length!==e)throw new Error("inconsistent lengths");return"u"+P(t,"base64url")}function fo(r){let e=J(r),t=r.slice(F(e));if(t.length!==e)throw new Error("inconsistent lengths");return P(t,"base58btc")}function ho(r){let e=r.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==16)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion address.`);let t=z.decode("b"+e[0]),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=dt(n);return B([t,o],t.length+o.length)}function mo(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=z.decode(`b${e[0]}`),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=dt(n);return B([t,o],t.length+o.length)}function ir(r){let e=r.slice(0,r.length-2),t=r.slice(r.length-2),n=P(e,"base32"),o=cr(t);return`${n}:${o}`}function ar(r){r=lt(r);let e=[],t=[],n=null,o=r.split("/").slice(1);if(o.length===1&&o[0]==="")return{bytes:new Uint8Array,string:"/",tuples:[],stringTuples:[],path:null};for(let s=0;s<o.length;s++){let i=o[s],a=w(i);if(a.size===0){e.push([a.code]),t.push([a.code]);continue}if(s++,s>=o.length)throw lr("invalid address: "+r);if(a.path===!0){n=lt(o.slice(s).join("/")),e.push([a.code,at(a.code,n)]),t.push([a.code,n]);break}let p=at(a.code,o[s]);e.push([a.code,p]),t.push([a.code,ct(a.code,p)])}return{string:dr(t),bytes:pt(e),tuples:e,stringTuples:t,path:n}}function ut(r){let e=[],t=[],n=null,o=0;for(;o<r.length;){let s=J(r,o),i=F(s),a=w(s),p=go(a,r.slice(o+i));if(p===0){e.push([s]),t.push([s]),o+=i;continue}let f=r.slice(o+i,o+i+p);if(o+=p+i,o>r.length)throw lr("Invalid address Uint8Array: "+P(r,"base16"));e.push([s,f]);let m=ct(s,f);if(t.push([s,m]),a.path===!0){n=m;break}}return{bytes:Uint8Array.from(r),string:dr(t),tuples:e,stringTuples:t,path:n}}function dr(r){let e=[];return r.map(t=>{let n=w(t[0]);return e.push(n.name),t.length>1&&t[1]!=null&&e.push(t[1]),null}),lt(e.join("/"))}function pt(r){return B(r.map(e=>{let t=w(e[0]),n=Uint8Array.from(ie(t.code));return e.length>1&&e[1]!=null&&(n=B([n,e[1]])),n}))}function go(r,e){if(r.size>0)return r.size/8;if(r.size===0)return 0;{let t=J(e instanceof Uint8Array?e:Uint8Array.from(e));return t+F(t)}}function lt(r){return"/"+r.trim().split("/").filter(e=>e).join("/")}function lr(r){return new Error("Error parsing address: "+r)}var wo=Symbol.for("nodejs.util.inspect.custom"),ft=Symbol.for("@multiformats/js-multiaddr/multiaddr"),xo=[w("dns").code,w("dns4").code,w("dns6").code,w("dnsaddr").code],Ae=class r{bytes;#e;#t;#r;#n;[ft]=!0;constructor(e){e==null&&(e="");let t;if(e instanceof Uint8Array)t=ut(e);else if(typeof e=="string"){if(e.length>0&&e.charAt(0)!=="/")throw new Error(`multiaddr "${e}" must start with a "/"`);t=ar(e)}else if(pr(e))t=ut(e.bytes);else throw new Error("addr must be a string, Buffer, or another Multiaddr");this.bytes=t.bytes,this.#e=t.string,this.#t=t.tuples,this.#r=t.stringTuples,this.#n=t.path}toString(){return this.#e}toJSON(){return this.toString()}toOptions(){let e,t,n,o,s="",i=w("tcp"),a=w("udp"),p=w("ip4"),f=w("ip6"),m=w("dns6"),v=w("ip6zone");for(let[u,l]of this.stringTuples())u===v.code&&(s=`%${l??""}`),xo.includes(u)&&(t=i.name,o=443,n=`${l??""}${s}`,e=u===m.code?6:4),(u===i.code||u===a.code)&&(t=w(u).name,o=parseInt(l??"")),(u===p.code||u===f.code)&&(t=w(u).name,n=`${l??""}${s}`,e=u===f.code?6:4);if(e==null||t==null||n==null||o==null)throw new Error('multiaddr must have a valid format: "/{ip4, ip6, dns4, dns6, dnsaddr}/{address}/{tcp, udp}/{port}".');return{family:e,host:n,transport:t,port:o}}protos(){return this.#t.map(([e])=>Object.assign({},w(e)))}protoCodes(){return this.#t.map(([e])=>e)}protoNames(){return this.#t.map(([e])=>w(e).name)}tuples(){return this.#t}stringTuples(){return this.#r}encapsulate(e){return e=new r(e),new r(this.toString()+e.toString())}decapsulate(e){let t=e.toString(),n=this.toString(),o=n.lastIndexOf(t);if(o<0)throw new Error(`Address ${this.toString()} does not contain subaddress: ${e.toString()}`);return new r(n.slice(0,o))}decapsulateCode(e){let t=this.tuples();for(let n=t.length-1;n>=0;n--)if(t[n][0]===e)return new r(pt(t.slice(0,n)));return this}getPeerId(){try{let e=[];this.stringTuples().forEach(([n,o])=>{n===ce.p2p.code&&e.push([n,o]),n===ce["p2p-circuit"].code&&(e=[])});let t=e.pop();if(t?.[1]!=null){let n=t[1];return n[0]==="Q"||n[0]==="1"?P(T.decode(`z${n}`),"base58btc"):P(G.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){return this.#n}equals(e){return zt(this.bytes,e.bytes)}async resolve(e){let t=this.protos().find(s=>s.resolvable);if(t==null)return[this];let n=ur.get(t.name);if(n==null)throw new A(`no available resolver for ${t.name}`,"ERR_NO_AVAILABLE_RESOLVER");return(await n(this,e)).map(s=>L(s))}nodeAddress(){let e=this.toOptions();if(e.transport!=="tcp"&&e.transport!=="udp")throw new Error(`multiaddr must have a valid format - no protocol with name: "${e.transport}". Must have a valid transport protocol: "{tcp, udp}"`);return{family:e.family,address:e.host,port:e.port}}isThinWaistAddress(e){let t=(e??this).protos();return!(t.length!==2||t[0].code!==4&&t[0].code!==41||t[1].code!==6&&t[1].code!==273)}[wo](){return`Multiaddr(${this.#e})`}};var ur=new Map;function pr(r){return!!r?.[ft]}function L(r){return new Ae(r)}var bo=c("dns4"),yo=c("dns6"),Eo=c("dnsaddr"),K=E(c("dns"),Eo,bo,yo),Se=E(c("ip4"),c("ip6")),H=E(d(Se,c("tcp")),d(K,c("tcp"))),Te=d(Se,c("udp")),vo=d(Te,c("utp")),Ao=d(Te,c("quic")),Io=d(Te,c("quic-v1")),ht=E(d(H,c("ws")),d(K,c("ws"))),Ie=E(d(ht,c("p2p")),ht),mt=E(d(H,c("wss")),d(K,c("wss")),d(H,c("tls"),c("ws")),d(K,c("tls"),c("ws"))),Ce=E(d(mt,c("p2p")),mt),gt=E(d(H,c("http")),d(Se,c("http")),d(K,c("http"))),wt=E(d(H,c("https")),d(Se,c("https")),d(K,c("https"))),fr=d(Te,c("webrtc-direct"),c("certhash")),gr=E(d(fr,c("p2p")),fr),hr=d(Io,c("webtransport"),c("certhash"),c("certhash")),wr=E(d(hr,c("p2p")),hr),xr=E(d(Ie,c("p2p-webrtc-star"),c("p2p")),d(Ce,c("p2p-webrtc-star"),c("p2p")),d(Ie,c("p2p-webrtc-star")),d(Ce,c("p2p-webrtc-star"))),fc=E(d(Ie,c("p2p-websocket-star"),c("p2p")),d(Ce,c("p2p-websocket-star"),c("p2p")),d(Ie,c("p2p-websocket-star")),d(Ce,c("p2p-websocket-star"))),br=E(d(gt,c("p2p-webrtc-direct"),c("p2p")),d(wt,c("p2p-webrtc-direct"),c("p2p")),d(gt,c("p2p-webrtc-direct")),d(wt,c("p2p-webrtc-direct"))),Y=E(ht,mt,gt,wt,xr,br,H,vo,Ao,K,gr,wr),hc=E(d(Y,c("p2p-stardust"),c("p2p")),d(Y,c("p2p-stardust"))),W=E(d(Y,c("p2p")),xr,br,gr,wr,c("p2p")),mr=E(d(W,c("p2p-circuit"),W),d(W,c("p2p-circuit")),d(c("p2p-circuit"),W),d(Y,c("p2p-circuit")),d(c("p2p-circuit"),Y),c("p2p-circuit")),yr=()=>E(d(mr,yr),mr),Q=yr(),mc=E(d(Q,W,Q),d(W,Q),d(Q,W),Q,W);var gc=E(d(Q,c("webrtc"),c("p2p")),d(Q,c("webrtc")),d(Y,c("webrtc"),c("p2p")),d(Y,c("webrtc")),c("webrtc"));function Er(r){function e(t){let n;try{n=L(t)}catch{return!1}let o=r(n.protoNames());return o===null?!1:o===!0||o===!1?o:o.length===0}return e}function d(...r){function e(t){if(t.length<r.length)return null;let n=t;return r.some(o=>(n=typeof o=="function"?o().partialMatch(t):o.partialMatch(t),Array.isArray(n)&&(t=n),n===null)),n}return{toString:function(){return"{ "+r.join(" ")+" }"},input:r,matches:Er(e),partialMatch:e}}function E(...r){function e(n){let o=null;return r.some(s=>{let i=typeof s=="function"?s().partialMatch(n):s.partialMatch(n);return i!=null?(o=i,!0):!1}),o}return{toString:function(){return"{ "+r.join(" ")+" }"},input:r,matches:Er(e),partialMatch:e}}function c(r){let e=r;function t(o){let s;try{s=L(o)}catch{return!1}let i=s.protoNames();return i.length===1&&i[0]===e}function n(o){return o.length===0?null:o[0]===e?o.slice(1):null}return{toString:function(){return e},matches:t,partialMatch:n}}var Tr=de(k("net"),1);var xt={ERR_INVALID_IP_PARAMETER:"ERR_INVALID_IP_PARAMETER",ERR_INVALID_PORT_PARAMETER:"ERR_INVALID_PORT_PARAMETER",ERR_INVALID_IP:"ERR_INVALID_IP"};function vr(r,e){if(typeof r!="string")throw new A(`invalid ip provided: ${r}`,xt.ERR_INVALID_IP_PARAMETER);if(typeof e=="string"&&(e=parseInt(e)),isNaN(e))throw new A(`invalid port provided: ${e}`,xt.ERR_INVALID_PORT_PARAMETER);if((0,M.isIPv4)(r))return L(`/ip4/${r}/tcp/${e}`);if((0,M.isIPv6)(r))return L(`/ip6/${r}/tcp/${e}`);throw new A(`invalid ip:port for creating a multiaddr: ${r}:${e}`,xt.ERR_INVALID_IP)}function Ar(r){if(To(r))return async function*(){let e=r.getReader();try{for(;;){let{done:t,value:n}=await e.read();if(t)return;yield n}}finally{e.releaseLock()}}();if(So(r))return r;throw new Error("unknown stream")}function So(r){return r[Symbol.asyncIterator]!=null}function To(r){return typeof r?.getReader=="function"}function Ir(r){return async e=>{let t=async()=>{Po(e)&&await e.return(void 0)},n,o,s=g=>{n=g,t().catch(C=>{C=new AggregateError([n,C],"The Writable emitted an error, additionally an error occurred while ending the Source")}).finally(()=>{o?.(g)})},i,a=!1,p=()=>{a=!0,i?.()},f,m=!1,v=()=>{m=!0,f?.()},x,u=()=>{x?.()},l=async()=>new Promise((g,C)=>{i=x=g,o=C,r.once("drain",u)}),b=async()=>(await t(),new Promise((g,C)=>{if(a||m||n!=null){g();return}f=i=g,o=C})),_=()=>{r.removeListener("error",s),r.removeListener("close",p),r.removeListener("finish",v),r.removeListener("drain",u)};r.once("error",s),r.once("close",p),r.once("finish",v);try{for await(let g of e){if(!r.writable||r.destroyed||n!=null)break;r.write(g)||await l()}}catch(g){n==null&&r.destroy(g),n=g}try{if(r.writable&&r.end(),await b(),n!=null)throw n}finally{_()}}}function Po(r){return r.return!=null}function bt(r){return{sink:Ir(r),source:Ar(r)}}var yt=de(k("os"),1),Cr=de(k("path"),1);var Ro={ip4:"IPv4",ip6:"IPv6"};function ae(r,e={}){let t=r.getPath();return t!=null?yt.default.platform()==="win32"?{path:Cr.default.join("\\\\.\\pipe\\",t)}:{path:t}:{...e,...r.toOptions()}}function Et(r,e,t){let n=o=>L(`/${r}/${o}/tcp/${t}`);return(No(e)?Mo(Ro[r]):[e]).map(n)}function No(r){return["0.0.0.0","::"].includes(r)}var Do=yt.default.networkInterfaces();function Mo(r){let e=[];for(let[,t]of Object.entries(Do))if(t!=null)for(let n of t)n.family===r&&e.push(n.address);return e}var Pe=(r,e)=>{let t=e.logger.forComponent("libp2p:tcp:socket"),n=e.metrics,o=e.metricPrefix??"",s=e.socketInactivityTimeout??3e5,i=e.socketCloseTimeout??500;e.listeningAddr?.getPath()!=null&&(e.remoteAddr=e.listeningAddr),e.remoteAddr?.getPath()!=null&&(e.localAddr=e.remoteAddr);let a;if(e.remoteAddr!=null)a=e.remoteAddr;else{if(r.remoteAddress==null||r.remotePort==null)throw new A("Could not determine remote address or port","ERR_NO_REMOTE_ADDRESS");a=vr(r.remoteAddress,r.remotePort)}let p=ae(a),f=p.path??`${p.host??""}:${p.port??""}`,{sink:m,source:v}=bt(r);r.setTimeout(s,()=>{t("%s socket read timeout",f),n?.increment({[`${o}timeout`]:!0});let u;r.readable&&(u=new A("Socket read timeout","ERR_SOCKET_READ_TIMEOUT")),r.destroy(u)}),r.once("close",()=>{t("%s socket close",f),n?.increment({[`${o}close`]:!0}),x.timeline.close==null&&(x.timeline.close=Date.now())}),r.once("end",()=>{t("%s socket end",f),n?.increment({[`${o}end`]:!0})});let x={async sink(u){try{await m(async function*(){for await(let l of u)l instanceof Uint8Array?yield l:yield l.subarray()}())}catch(l){l.type!=="aborted"&&t.error("%s error in sink",f,l)}r.end()},source:v,remoteAddr:a,timeline:{open:Date.now()},async close(u={}){if(r.destroyed){t("%s socket was already destroyed when trying to close",f);return}if(u.signal==null){let b=AbortSignal.timeout(i);u={...u,signal:b}}let l=()=>{r.destroy(new A("Destroying socket after timeout","ERR_CLOSE_TIMEOUT"))};u.signal?.addEventListener("abort",l);try{t("%s closing socket",f),await new Promise((b,_)=>{r.once("close",()=>{t("%s socket closed",f),b()}),r.once("error",g=>{t("%s socket error",f,g),x.timeline.close==null&&(x.timeline.close=Date.now()),_(g)}),r.setTimeout(i),r.end(),r.writableLength>0?r.once("drain",()=>{t("%s socket drained",f),r.destroy()}):r.destroy()})}catch(b){this.abort(b)}finally{u.signal?.removeEventListener("abort",l)}},abort:u=>{t("%s socket abort due to error",f,u),r.destroy(u),x.timeline.close==null&&(x.timeline.close=Date.now())},log:t};return x};async function Sr(r,e){try{await r.close()}catch(t){e.log.error("an error occurred closing the connection",t),r.abort(t)}}var I;(function(r){r[r.INACTIVE=0]="INACTIVE",r[r.ACTIVE=1]="ACTIVE",r[r.PAUSED=2]="PAUSED"})(I||(I={}));var Re=class extends ge{context;server;connections=new Set;status={code:I.INACTIVE};metrics;addr;log;constructor(e){if(super(),this.context=e,e.keepAlive=e.keepAlive??!0,e.noDelay=e.noDelay??!0,this.log=e.logger.forComponent("libp2p:tcp:listener"),this.addr="unknown",this.server=Tr.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 A("closeAbove must be >= listenBelow","ERR_CONNECTION_LIMITS");this.server.on("listening",()=>{if(e.metrics!=null){let t=this.server.address();t==null?this.addr="unknown":typeof t=="string"?this.addr=t:this.addr=`${t.address}:${t.port}`,e.metrics?.registerMetricGroup("libp2p_tcp_inbound_connections_total",{label:"address",help:"Current active connections in TCP listener",calculate:()=>({[this.addr]:this.connections.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.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")})}onSocket(e){if(this.status.code!==I.ACTIVE)throw new A("Server is not listening yet","ERR_SERVER_NOT_RUNNING");e.on("error",n=>{this.log("socket error",n),this.metrics?.events.increment({[`${this.addr} error`]:!0})});let t;try{t=Pe(e,{listeningAddr:this.status.listeningAddr,socketInactivityTimeout:this.context.socketInactivityTimeout,socketCloseTimeout:this.context.socketCloseTimeout,metrics:this.metrics?.events,metricPrefix:`${this.addr} `,logger:this.context.logger})}catch(n){this.log.error("inbound connection failed",n),this.metrics?.errors.increment({[`${this.addr} inbound_to_connection`]:!0});return}this.log("new inbound connection %s",t.remoteAddr);try{this.context.upgrader.upgradeInbound(t).then(n=>{this.log("inbound connection upgraded %s",t.remoteAddr),this.connections.add(t),e.once("close",()=>{this.connections.delete(t),this.context.closeServerOnMaxConnections!=null&&this.connections.size<this.context.closeServerOnMaxConnections.listenBelow&&this.resume().catch(o=>{this.log.error("error attempting to listen server once connection count under limit",o),this.context.closeServerOnMaxConnections?.onListenError?.(o)})}),this.context.handler!=null&&this.context.handler(n),this.context.closeServerOnMaxConnections!=null&&this.connections.size>=this.context.closeServerOnMaxConnections.closeAbove&&this.pause(!1).catch(o=>{this.log.error("error attempting to close server once connection count over limit",o)}),this.safeDispatchEvent("connection",{detail:n})}).catch(async n=>{this.log.error("inbound connection failed",n),this.metrics?.errors.increment({[`${this.addr} inbound_upgrade`]:!0}),await Sr(t,{log:this.log})}).catch(n=>{this.log.error("closing inbound connection failed",n)})}catch(n){this.log.error("inbound connection failed",n),Sr(t,{log:this.log}).catch(o=>{this.log.error("closing inbound connection failed",o),this.metrics?.errors.increment({[`${this.addr} inbound_closing_failed`]:!0})})}}getAddrs(){if(this.status.code===I.INACTIVE)return[];let e=[],t=this.server.address(),{listeningAddr:n,peerId:o}=this.status;if(t==null)return[];if(typeof t=="string")e=[n];else try{n.toString().startsWith("/ip4")?e=e.concat(Et("ip4",t.address,t.port)):t.family==="IPv6"&&(e=e.concat(Et("ip6",t.address,t.port)))}catch(s){this.log.error("could not turn %s:%s into multiaddr",t.address,t.port,s)}return e.map(s=>o!=null?s.encapsulate(`/p2p/${o}`):s)}async listen(e){if(this.status.code===I.ACTIVE||this.status.code===I.PAUSED)throw new A("server is already listening","ERR_SERVER_ALREADY_LISTENING");let t=e.getPeerId(),n=t==null?e.decapsulateCode(421):e,{backlog:o}=this.context;try{this.status={code:I.ACTIVE,listeningAddr:n,peerId:t,netConfig:ae(n,{backlog:o})},await this.resume()}catch(s){throw this.status={code:I.INACTIVE},s}}async close(){let e=new A("Listener is closing","ERR_LISTENER_CLOSING");this.connections.forEach(t=>{t.abort(e)}),await this.pause(!0)}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())}async pause(e){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("closing server on %s",this.server.address()),this.status=e?{code:I.INACTIVE}:{...this.status,code:I.PAUSED},await new Promise((t,n)=>{this.server.close(o=>{if(o!=null){n(o);return}t()})}))}};var vt=class{opts;metrics;components;log;constructor(e,t={}){this.log=e.logger.forComponent("libp2p:tcp"),this.opts=t,this.components=e,e.metrics!=null&&(this.metrics={dialerEvents:e.metrics.registerCounterGroup("libp2p_tcp_dialer_events_total",{label:"event",help:"Total count of TCP dialer events by type"})})}[Ct]=!0;[Symbol.toStringTag]="@libp2p/tcp";async dial(e,t){t.keepAlive=t.keepAlive??!0,t.noDelay=t.noDelay??!0;let n=await this._connect(e,t);n.on("error",a=>{this.log("socket error",a)});let o=Pe(n,{remoteAddr:e,socketInactivityTimeout:this.opts.outboundSocketInactivityTimeout,socketCloseTimeout:this.opts.socketCloseTimeout,metrics:this.metrics?.dialerEvents,logger:this.components.logger}),s=()=>{o.close().catch(a=>{this.log.error("Error closing maConn after abort",a)})};t.signal?.addEventListener("abort",s,{once:!0}),this.log("new outbound connection %s",o.remoteAddr);let i=await t.upgrader.upgradeOutbound(o);if(this.log("outbound connection %s upgraded",o.remoteAddr),t.signal?.removeEventListener("abort",s),t.signal?.aborted===!0)throw i.close().catch(a=>{this.log.error("Error closing conn after abort",a)}),new Z;return i}async _connect(e,t){if(t.signal?.aborted===!0)throw new Z;return new Promise((n,o)=>{let s=Date.now(),i=ae(e,{...this.opts.dialOpts??{},...t});this.log("dialing %a",e);let a=Pr.default.connect(i),p=u=>{let l=i.path??`${i.host??""}:${i.port}`;u.message=`connection error ${l}: ${u.message}`,this.metrics?.dialerEvents.increment({error:!0}),x(u)},f=()=>{this.log("connection timeout %a",e),this.metrics?.dialerEvents.increment({timeout:!0});let u=new A(`connection timeout after ${Date.now()-s}ms`,"ERR_CONNECT_TIMEOUT");a.emit("error",u)},m=()=>{this.log("connection opened %a",e),this.metrics?.dialerEvents.increment({connect:!0}),x()},v=()=>{this.log("connection aborted %a",e),this.metrics?.dialerEvents.increment({abort:!0}),a.destroy(),x(new Z)},x=u=>{if(a.removeListener("error",p),a.removeListener("timeout",f),a.removeListener("connect",m),t.signal!=null&&t.signal.removeEventListener("abort",v),u!=null){o(u);return}n(a)};a.on("error",p),a.on("timeout",f),a.on("connect",m),t.signal!=null&&t.signal.addEventListener("abort",v)})}createListener(e){return new Re({...this.opts.listenOpts??{},...e,maxConnections:this.opts.maxConnections,backlog:this.opts.backlog,closeServerOnMaxConnections:this.opts.closeServerOnMaxConnections,socketInactivityTimeout:this.opts.inboundSocketInactivityTimeout,socketCloseTimeout:this.opts.socketCloseTimeout,metrics:this.components.metrics,logger:this.components.logger})}filter(e){return e=Array.isArray(e)?e:[e],e.filter(t=>t.protoCodes().includes(290)?!1:t.protoCodes().includes(400)?!0:H.matches(t.decapsulateCode(421)))}};function Uo(r={}){return e=>new vt(e,r)}return Ur(ko);})();
|
|
2
|
+
"use strict";var Libp2PTcp=(()=>{var Rr=Object.create;var me=Object.defineProperty;var Nr=Object.getOwnPropertyDescriptor;var Dr=Object.getOwnPropertyNames;var Mr=Object.getPrototypeOf,_r=Object.prototype.hasOwnProperty;var L=(r=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(r,{get:(e,t)=>(typeof require<"u"?require:e)[t]}):r)(function(r){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+r+'" is not supported')});var N=(r,e)=>{for(var t in e)me(r,t,{get:e[t],enumerable:!0})},At=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Dr(e))!_r.call(r,o)&&o!==t&&me(r,o,{get:()=>e[o],enumerable:!(n=Nr(e,o))||n.enumerable});return r};var de=(r,e,t)=>(t=r!=null?Rr(Mr(r)):{},At(e||!r||!r.__esModule?me(t,"default",{value:r,enumerable:!0}):t,r)),Ur=r=>At(me({},"__esModule",{value:!0}),r);var Lo={};N(Lo,{tcp:()=>Uo});var Pr=de(L("net"),1);var Ct=Symbol.for("@libp2p/transport");var It;(function(r){r[r.FATAL_ALL=0]="FATAL_ALL",r[r.NO_FATAL=1]="NO_FATAL"})(It||(It={}));var Z=class r extends Error{code;type;constructor(e="The operation was aborted"){super(e),this.name="AbortError",this.code=r.code,this.type=r.type}static code="ABORT_ERR";static type="aborted"},A=class extends Error{code;props;constructor(e,t,n){super(e),this.code=t,this.name=n?.name??"CodeError",this.props=n??{}}};var St=L("events"),Tt=(r,...e)=>{try{(0,St.setMaxListeners)(r,...e)}catch{}};var ge=class extends EventTarget{#e=new Map;constructor(){super(),Tt(1/0,this)}listenerCount(e){let t=this.#e.get(e);return t==null?0:t.length}addEventListener(e,t,n){super.addEventListener(e,t,n);let o=this.#e.get(e);o==null&&(o=[],this.#e.set(e,o)),o.push({callback:t,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(e,t,n){super.removeEventListener(e.toString(),t??null,n);let o=this.#e.get(e);o!=null&&(o=o.filter(({callback:s})=>s!==t),this.#e.set(e,o))}dispatchEvent(e){let t=super.dispatchEvent(e),n=this.#e.get(e.type);return n==null||(n=n.filter(({once:o})=>!o),this.#e.set(e.type,n)),t}safeDispatchEvent(e,t={}){return this.dispatchEvent(new Lr(e,t))}},Ne=class extends Event{detail;constructor(e,t){super(e,t),this.detail=t?.detail}},Lr=globalThis.CustomEvent??Ne;var Le={};N(Le,{base58btc:()=>P,base58flickr:()=>zr});var Bo=new Uint8Array(0);function Pt(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 M(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")}function Rt(r){return new TextEncoder().encode(r)}function Nt(r){return new TextDecoder().decode(r)}function kr(r,e){if(r.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),n=0;n<t.length;n++)t[n]=255;for(var o=0;o<r.length;o++){var s=r.charAt(o),i=s.charCodeAt(0);if(t[i]!==255)throw new TypeError(s+" is ambiguous");t[i]=o}var a=r.length,p=r.charAt(0),x=Math.log(a)/Math.log(256),u=Math.log(256)/Math.log(a);function v(l){if(l instanceof Uint8Array||(ArrayBuffer.isView(l)?l=new Uint8Array(l.buffer,l.byteOffset,l.byteLength):Array.isArray(l)&&(l=Uint8Array.from(l))),!(l instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(l.length===0)return"";for(var g=0,T=0,w=0,E=l.length;w!==E&&l[w]===0;)w++,g++;for(var O=(E-w)*u+1>>>0,D=new Uint8Array(O);w!==E;){for(var V=l[w],j=0,U=O-1;(V!==0||j<T)&&U!==-1;U--,j++)V+=256*D[U]>>>0,D[U]=V%a>>>0,V=V/a>>>0;if(V!==0)throw new Error("Non-zero carry");T=j,w++}for(var $=O-T;$!==O&&D[$]===0;)$++;for(var he=p.repeat(g);$<O;++$)he+=r.charAt(D[$]);return he}function C(l){if(typeof l!="string")throw new TypeError("Expected String");if(l.length===0)return new Uint8Array;var g=0;if(l[g]!==" "){for(var T=0,w=0;l[g]===p;)T++,g++;for(var E=(l.length-g)*x+1>>>0,O=new Uint8Array(E);l[g];){var D=t[l.charCodeAt(g)];if(D===255)return;for(var V=0,j=E-1;(D!==0||V<w)&&j!==-1;j--,V++)D+=a*O[j]>>>0,O[j]=D%256>>>0,D=D/256>>>0;if(D!==0)throw new Error("Non-zero carry");w=V,g++}if(l[g]!==" "){for(var U=E-w;U!==E&&O[U]===0;)U++;for(var $=new Uint8Array(T+(E-U)),he=T;U!==E;)$[he++]=O[U++];return $}}}function f(l){var g=C(l);if(g)return g;throw new Error(`Non-${e} character`)}return{encode:v,decodeUnsafe:C,decode:f}}var Or=kr,Vr=Or,Mt=Vr;var De=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")}},Me=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,t,n){if(this.name=e,this.prefix=t,t.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=t.codePointAt(0),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 _t(this,e)}},_e=class{decoders;constructor(e){this.decoders=e}or(e){return _t(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 _t(r,e){return new _e({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var Ue=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 De(e,t,n),this.decoder=new Me(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function ee({name:r,prefix:e,encode:t,decode:n}){return new Ue(r,e,t,n)}function q({name:r,prefix:e,alphabet:t}){let{encode:n,decode:o}=Mt(t,r);return ee({prefix:e,name:r,encode:n,decode:s=>M(o(s))})}function Fr(r,e,t,n){let o={};for(let u=0;u<e.length;++u)o[e[u]]=u;let s=r.length;for(;r[s-1]==="=";)--s;let i=new Uint8Array(s*t/8|0),a=0,p=0,x=0;for(let u=0;u<s;++u){let v=o[r[u]];if(v===void 0)throw new SyntaxError(`Non-${n} character`);p=p<<t|v,a+=t,a>=8&&(a-=8,i[x++]=255&p>>a)}if(a>=t||255&p<<8-a)throw new SyntaxError("Unexpected end of data");return i}function $r(r,e,t){let n=e[e.length-1]==="=",o=(1<<t)-1,s="",i=0,a=0;for(let p=0;p<r.length;++p)for(a=a<<8|r[p],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;)s+="=";return s}function b({name:r,prefix:e,bitsPerChar:t,alphabet:n}){return ee({prefix:e,name:r,encode(o){return $r(o,n,t)},decode(o){return Fr(o,n,t,r)}})}var P=q({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),zr=q({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var ke={};N(ke,{base32:()=>z,base32hex:()=>Gr,base32hexpad:()=>Hr,base32hexpadupper:()=>Xr,base32hexupper:()=>Wr,base32pad:()=>jr,base32padupper:()=>qr,base32upper:()=>Br,base32z:()=>Jr});var z=b({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Br=b({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),jr=b({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),qr=b({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Gr=b({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Wr=b({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Hr=b({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Xr=b({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Jr=b({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Qr=kt,Ut=128,Kr=127,Yr=~Kr,Zr=Math.pow(2,31);function kt(r,e,t){e=e||[],t=t||0;for(var n=t;r>=Zr;)e[t++]=r&255|Ut,r/=128;for(;r&Yr;)e[t++]=r&255|Ut,r>>>=7;return e[t]=r|0,kt.bytes=t-n+1,e}var en=Oe,tn=128,Lt=127;function Oe(r,n){var t=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw Oe.bytes=0,new RangeError("Could not decode varint");i=r[s++],t+=o<28?(i&Lt)<<o:(i&Lt)*Math.pow(2,o),o+=7}while(i>=tn);return Oe.bytes=s-n,t}var rn=Math.pow(2,7),nn=Math.pow(2,14),on=Math.pow(2,21),sn=Math.pow(2,28),cn=Math.pow(2,35),an=Math.pow(2,42),dn=Math.pow(2,49),ln=Math.pow(2,56),un=Math.pow(2,63),pn=function(r){return r<rn?1:r<nn?2:r<on?3:r<sn?4:r<cn?5:r<an?6:r<dn?7:r<ln?8:r<un?9:10},fn={encode:Qr,decode:en,encodingLength:pn},hn=fn,le=hn;function ue(r,e=0){return[le.decode(r,e),le.decode.bytes]}function te(r,e,t=0){return le.encode(r,e,t),e}function re(r){return le.encodingLength(r)}function X(r,e){let t=e.byteLength,n=re(r),o=n+re(t),s=new Uint8Array(o+t);return te(r,s,0),te(t,s,n),s.set(e,o),new ne(r,t,e,s)}function xe(r){let e=M(r),[t,n]=ue(e),[o,s]=ue(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new ne(t,o,i,e)}function Ot(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&Pt(r.bytes,t.bytes)}}var ne=class{code;size;digest;bytes;constructor(e,t,n,o){this.code=e,this.size=t,this.digest=n,this.bytes=o}};function Vt(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return gn(t,Ve(r),e??P.encoder);default:return wn(t,Ve(r),e??z.encoder)}}var Ft=new WeakMap;function Ve(r){let e=Ft.get(r);if(e==null){let t=new Map;return Ft.set(r,t),t}return e}var G=class r{code;version;multihash;bytes;"/";constructor(e,t,n,o){this.code=t,this.version=e,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:t}=this;if(e!==pe)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==xn)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=X(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&&Ot(e.multihash,n.multihash)}toString(e){return Vt(this,e)}toJSON(){return{"/":Vt(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??$t(n,o,s.bytes))}else if(t[bn]===!0){let{version:n,multihash:o,code:s}=t,i=xe(o);return r.create(n,s,i)}else return null}static create(e,t,n){if(typeof t!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(t!==pe)throw new Error(`Version 0 CID must use dag-pb (code: ${pe}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let o=$t(e,t,n.bytes);return new r(e,t,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,pe,e)}static createV1(e,t){return r.create(1,e,t)}static decode(e){let[t,n]=r.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return t}static decodeFirst(e){let t=r.inspectBytes(e),n=t.size-t.multihashSize,o=M(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 ne(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[v,C]=ue(e.subarray(t));return t+=C,v},o=n(),s=pe;if(o===18?(o=0,t=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=t,a=n(),p=n(),x=t+p,u=x-i;return{version:o,codec:s,multihashCode:a,digestSize:p,multihashSize:u,size:x}}static parse(e,t){let[n,o]=mn(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 Ve(s).set(n,e),s}};function mn(r,e){switch(r[0]){case"Q":{let t=e??P;return[P.prefix,t.decode(`${P.prefix}${r}`)]}case P.prefix:{let t=e??P;return[P.prefix,t.decode(r)]}case z.prefix:{let t=e??z;return[z.prefix,t.decode(r)]}default:{if(e==null)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[r[0],e.decode(r)]}}}function gn(r,e,t){let{prefix:n}=t;if(n!==P.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let o=e.get(n);if(o==null){let s=t.encode(r).slice(1);return e.set(n,s),s}else return o}function wn(r,e,t){let{prefix:n}=t,o=e.get(n);if(o==null){let s=t.encode(r);return e.set(n,s),s}else return o}var pe=112,xn=18;function $t(r,e,t){let n=re(r),o=n+re(e),s=new Uint8Array(o+t.byteLength);return te(r,s,0),te(e,s,n),s.set(t,o),s}var bn=Symbol.for("@ipld/js-cid/CID");function zt(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 Jt=L("node:buffer");var Fe={};N(Fe,{base10:()=>yn});var yn=q({prefix:"9",name:"base10",alphabet:"0123456789"});var $e={};N($e,{base16:()=>En,base16upper:()=>vn});var En=b({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),vn=b({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var ze={};N(ze,{base2:()=>An});var An=b({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Be={};N(Be,{base256emoji:()=>Pn});var Bt=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}"),In=Bt.reduce((r,e,t)=>(r[t]=e,r),[]),Cn=Bt.reduce((r,e,t)=>(r[e.codePointAt(0)]=t,r),[]);function Sn(r){return r.reduce((e,t)=>(e+=In[t],e),"")}function Tn(r){let e=[];for(let t of r){let n=Cn[t.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${t}`);e.push(n)}return new Uint8Array(e)}var Pn=ee({prefix:"\u{1F680}",name:"base256emoji",encode:Sn,decode:Tn});var je={};N(je,{base36:()=>Rn,base36upper:()=>Nn});var Rn=q({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Nn=q({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var qe={};N(qe,{base64:()=>Dn,base64pad:()=>Mn,base64url:()=>_n,base64urlpad:()=>Un});var Dn=b({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Mn=b({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),_n=b({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Un=b({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Ge={};N(Ge,{base8:()=>Ln});var Ln=b({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var We={};N(We,{identity:()=>kn});var kn=ee({prefix:"\0",name:"identity",encode:r=>Nt(r),decode:r=>Rt(r)});var fs=new TextEncoder,hs=new TextDecoder;var He={};N(He,{identity:()=>zn});var jt=0,Fn="identity",qt=M;function $n(r){return X(jt,qt(r))}var zn={code:jt,name:Fn,encode:qt,digest:$n};var Ke={};N(Ke,{sha256:()=>Bn,sha512:()=>jn});var Qe=de(L("crypto"),1);function Je({name:r,code:e,encode:t}){return new Xe(r,e,t)}var Xe=class{name;code;encode;constructor(e,t,n){this.name=e,this.code=t,this.encode=n}digest(e){if(e instanceof Uint8Array){let t=this.encode(e);return t instanceof Uint8Array?X(this.code,t):t.then(n=>X(this.code,n))}else throw Error("Unknown type, must be binary type")}};var Bn=Je({name:"sha2-256",code:18,encode:r=>M(Qe.default.createHash("sha256").update(r).digest())}),jn=Je({name:"sha2-512",code:19,encode:r=>M(Qe.default.createHash("sha512").update(r).digest())});var fe={...We,...ze,...Ge,...Fe,...$e,...ke,...je,...Le,...qe,...Be},Ps={...Ke,...He};var Wt=L("node:buffer");function se(r){return new Uint8Array(r.buffer,r.byteOffset,r.byteLength)}function be(r=0){return se(Wt.Buffer.allocUnsafe(r))}function Xt(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var Ht=Xt("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Ye=Xt("ascii","a",r=>{let e="a";for(let t=0;t<r.length;t++)e+=String.fromCharCode(r[t]);return e},r=>{r=r.substring(1);let e=be(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),qn={utf8:Ht,"utf-8":Ht,hex:fe.base16,latin1:Ye,ascii:Ye,binary:Ye,...fe},ye=qn;function R(r,e="utf8"){let t=ye[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return e==="utf8"||e==="utf-8"?Jt.Buffer.from(r.buffer,r.byteOffset,r.byteLength).toString("utf8"):t.encoder.encode(r).substring(1)}var Gn=Math.pow(2,7),Wn=Math.pow(2,14),Hn=Math.pow(2,21),Ze=Math.pow(2,28),et=Math.pow(2,35),tt=Math.pow(2,42),rt=Math.pow(2,49),h=128,S=127;function F(r){if(r<Gn)return 1;if(r<Wn)return 2;if(r<Hn)return 3;if(r<Ze)return 4;if(r<et)return 5;if(r<tt)return 6;if(r<rt)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Xn(r,e,t=0){switch(F(r)){case 8:e[t++]=r&255|h,r/=128;case 7:e[t++]=r&255|h,r/=128;case 6:e[t++]=r&255|h,r/=128;case 5:e[t++]=r&255|h,r/=128;case 4:e[t++]=r&255|h,r>>>=7;case 3:e[t++]=r&255|h,r>>>=7;case 2:e[t++]=r&255|h,r>>>=7;case 1:{e[t++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return e}function Jn(r,e,t=0){switch(F(r)){case 8:e.set(t++,r&255|h),r/=128;case 7:e.set(t++,r&255|h),r/=128;case 6:e.set(t++,r&255|h),r/=128;case 5:e.set(t++,r&255|h),r/=128;case 4:e.set(t++,r&255|h),r>>>=7;case 3:e.set(t++,r&255|h),r>>>=7;case 2:e.set(t++,r&255|h),r>>>=7;case 1:{e.set(t++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return e}function Qn(r,e){let t=r[e],n=0;if(n+=t&S,t<h||(t=r[e+1],n+=(t&S)<<7,t<h)||(t=r[e+2],n+=(t&S)<<14,t<h)||(t=r[e+3],n+=(t&S)<<21,t<h)||(t=r[e+4],n+=(t&S)*Ze,t<h)||(t=r[e+5],n+=(t&S)*et,t<h)||(t=r[e+6],n+=(t&S)*tt,t<h)||(t=r[e+7],n+=(t&S)*rt,t<h))return n;throw new RangeError("Could not decode varint")}function Kn(r,e){let t=r.get(e),n=0;if(n+=t&S,t<h||(t=r.get(e+1),n+=(t&S)<<7,t<h)||(t=r.get(e+2),n+=(t&S)<<14,t<h)||(t=r.get(e+3),n+=(t&S)<<21,t<h)||(t=r.get(e+4),n+=(t&S)*Ze,t<h)||(t=r.get(e+5),n+=(t&S)*et,t<h)||(t=r.get(e+6),n+=(t&S)*tt,t<h)||(t=r.get(e+7),n+=(t&S)*rt,t<h))return n;throw new RangeError("Could not decode varint")}function ie(r,e,t=0){return e==null&&(e=be(F(r))),e instanceof Uint8Array?Xn(r,e,t):Jn(r,e,t)}function J(r,e=0){return r instanceof Uint8Array?Qn(r,e):Kn(r,e)}var Kt=L("node:buffer");function B(r,e){return se(Kt.Buffer.concat(r,e))}var Ee=class{index=0;input="";new(e){return this.index=0,this.input=e,this}readAtomically(e){let t=this.index,n=e();return n===void 0&&(this.index=t),n}parseWith(e){let t=e();if(this.index===this.input.length)return t}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(e){return this.readAtomically(()=>{let t=this.readChar();if(t===e)return t})}readSeparator(e,t,n){return this.readAtomically(()=>{if(!(t>0&&this.readGivenChar(e)===void 0))return n()})}readNumber(e,t,n,o){return this.readAtomically(()=>{let s=0,i=0,a=this.peekChar();if(a===void 0)return;let p=a==="0",x=2**(8*o)-1;for(;;){let u=this.readAtomically(()=>{let v=this.readChar();if(v===void 0)return;let C=Number.parseInt(v,e);if(!Number.isNaN(C))return C});if(u===void 0)break;if(s*=e,s+=u,s>x||(i+=1,t!==void 0&&i>t))return}if(i!==0)return!n&&p&&i>1?void 0:s})}readIPv4Addr(){return this.readAtomically(()=>{let e=new Uint8Array(4);for(let t=0;t<e.length;t++){let n=this.readSeparator(".",t,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;e[t]=n}return e})}readIPv6Addr(){let e=t=>{for(let n=0;n<t.length/2;n++){let o=n*2;if(n<t.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return t[o]=i[0],t[o+1]=i[1],t[o+2]=i[2],t[o+3]=i[3],[o+4,!0]}let s=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(s===void 0)return[o,!1];t[o]=s>>8,t[o+1]=s&255}return[t.length,!1]};return this.readAtomically(()=>{let t=new Uint8Array(16),[n,o]=e(t);if(n===16)return t;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let s=new Uint8Array(14),i=16-(n+2),[a]=e(s.subarray(0,i));return t.set(s.subarray(0,a),16-a),t})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var js=new Ee;var Ks=parseInt("0xFFFF",16),Ys=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);var er=L("node:buffer");function nt(r,e="utf8"){let t=ye[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return e==="utf8"||e==="utf-8"?se(er.Buffer.from(r,"utf-8")):t.decoder.decode(`${t.prefix}${r}`)}var _=L("node:net");function ve(r){return!!(0,_.isIP)(r)}var tr=_.isIPv4,no=_.isIPv6,ot=function(r){let e=0;if(r=r.toString().trim(),tr(r)){let t=new Uint8Array(e+4);return r.split(/\./g).forEach(n=>{t[e++]=parseInt(n,10)&255}),t}if(no(r)){let t=r.split(":",8),n;for(n=0;n<t.length;n++){let s=tr(t[n]),i;s&&(i=ot(t[n]),t[n]=R(i.slice(0,2),"base16")),i!=null&&++n<8&&t.splice(n,0,R(i.slice(2,4),"base16"))}if(t[0]==="")for(;t.length<8;)t.unshift("0");else if(t[t.length-1]==="")for(;t.length<8;)t.push("0");else if(t.length<8){for(n=0;n<t.length&&t[n]!=="";n++);let s=[n,1];for(n=9-t.length;n>0;n--)s.push("0");t.splice.apply(t,s)}let o=new Uint8Array(e+16);for(n=0;n<t.length;n++){let s=parseInt(t[n],16);o[e++]=s>>8&255,o[e++]=s&255}return o}throw new Error("invalid ip address")},rr=function(r,e=0,t){e=~~e,t=t??r.length-e;let n=new DataView(r.buffer);if(t===4){let o=[];for(let s=0;s<t;s++)o.push(r[e+s]);return o.join(".")}if(t===16){let o=[];for(let s=0;s<t;s+=2)o.push(n.getUint16(e+s).toString(16));return o.join(":").replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}return""};var ce={},st={},so=[[4,32,"ip4"],[6,16,"tcp"],[33,16,"dccp"],[41,128,"ip6"],[42,-1,"ip6zone"],[43,8,"ipcidr"],[53,-1,"dns",!0],[54,-1,"dns4",!0],[55,-1,"dns6",!0],[56,-1,"dnsaddr",!0],[132,16,"sctp"],[273,16,"udp"],[275,0,"p2p-webrtc-star"],[276,0,"p2p-webrtc-direct"],[277,0,"p2p-stardust"],[280,0,"webrtc-direct"],[281,0,"webrtc"],[290,0,"p2p-circuit"],[301,0,"udt"],[302,0,"utp"],[400,-1,"unix",!1,!0],[421,-1,"ipfs"],[421,-1,"p2p"],[443,0,"https"],[444,96,"onion"],[445,296,"onion3"],[446,-1,"garlic64"],[448,0,"tls"],[449,-1,"sni"],[460,0,"quic"],[461,0,"quic-v1"],[465,0,"webtransport"],[466,-1,"certhash"],[477,0,"ws"],[478,0,"wss"],[479,0,"p2p-websocket-star"],[480,0,"http"],[777,-1,"memory"]];so.forEach(r=>{let e=io(...r);st[e.code]=e,ce[e.name]=e});function io(r,e,t,n,o){return{code:r,size:e,name:t,resolvable:!!n,path:!!o}}function m(r){if(typeof r=="number"){if(st[r]!=null)return st[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(ce[r]!=null)return ce[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var Fi=m("ip4"),$i=m("ip6"),zi=m("ipcidr");function ct(r,e){switch(m(r).code){case 4:case 41:return ao(e);case 42:return sr(e);case 6:case 273:case 33:case 132:return cr(e).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return sr(e);case 421:return fo(e);case 444:return ir(e);case 445:return ir(e);case 466:return po(e);default:return R(e,"base16")}}function at(r,e){switch(m(r).code){case 4:return nr(e);case 41:return nr(e);case 42:return or(e);case 6:case 273:case 33:case 132:return dt(parseInt(e,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return or(e);case 421:return lo(e);case 444:return ho(e);case 445:return mo(e);case 466:return uo(e);default:return nt(e,"base16")}}var it=Object.values(fe).map(r=>r.decoder),co=function(){let r=it[0].or(it[1]);return it.slice(2).forEach(e=>r=r.or(e)),r}();function nr(r){if(!ve(r))throw new Error("invalid ip address");return ot(r)}function ao(r){let e=rr(r,0,r.length);if(e==null)throw new Error("ipBuff is required");if(!ve(e))throw new Error("invalid ip address");return e}function dt(r){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,r),new Uint8Array(e)}function cr(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function or(r){let e=nt(r),t=Uint8Array.from(ie(e.length));return B([t,e],t.length+e.length)}function sr(r){let e=J(r);if(r=r.slice(F(e)),r.length!==e)throw new Error("inconsistent lengths");return R(r)}function lo(r){let e;r[0]==="Q"||r[0]==="1"?e=xe(P.decode(`z${r}`)).bytes:e=G.parse(r).multihash.bytes;let t=Uint8Array.from(ie(e.length));return B([t,e],t.length+e.length)}function uo(r){let e=co.decode(r),t=Uint8Array.from(ie(e.length));return B([t,e],t.length+e.length)}function po(r){let e=J(r),t=r.slice(F(e));if(t.length!==e)throw new Error("inconsistent lengths");return"u"+R(t,"base64url")}function fo(r){let e=J(r),t=r.slice(F(e));if(t.length!==e)throw new Error("inconsistent lengths");return R(t,"base58btc")}function ho(r){let e=r.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==16)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion address.`);let t=z.decode("b"+e[0]),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=dt(n);return B([t,o],t.length+o.length)}function mo(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=z.decode(`b${e[0]}`),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=dt(n);return B([t,o],t.length+o.length)}function ir(r){let e=r.slice(0,r.length-2),t=r.slice(r.length-2),n=R(e,"base32"),o=cr(t);return`${n}:${o}`}function ar(r){r=lt(r);let e=[],t=[],n=null,o=r.split("/").slice(1);if(o.length===1&&o[0]==="")return{bytes:new Uint8Array,string:"/",tuples:[],stringTuples:[],path:null};for(let s=0;s<o.length;s++){let i=o[s],a=m(i);if(a.size===0){e.push([a.code]),t.push([a.code]);continue}if(s++,s>=o.length)throw lr("invalid address: "+r);if(a.path===!0){n=lt(o.slice(s).join("/")),e.push([a.code,at(a.code,n)]),t.push([a.code,n]);break}let p=at(a.code,o[s]);e.push([a.code,p]),t.push([a.code,ct(a.code,p)])}return{string:dr(t),bytes:pt(e),tuples:e,stringTuples:t,path:n}}function ut(r){let e=[],t=[],n=null,o=0;for(;o<r.length;){let s=J(r,o),i=F(s),a=m(s),p=go(a,r.slice(o+i));if(p===0){e.push([s]),t.push([s]),o+=i;continue}let x=r.slice(o+i,o+i+p);if(o+=p+i,o>r.length)throw lr("Invalid address Uint8Array: "+R(r,"base16"));e.push([s,x]);let u=ct(s,x);if(t.push([s,u]),a.path===!0){n=u;break}}return{bytes:Uint8Array.from(r),string:dr(t),tuples:e,stringTuples:t,path:n}}function dr(r){let e=[];return r.map(t=>{let n=m(t[0]);return e.push(n.name),t.length>1&&t[1]!=null&&e.push(t[1]),null}),lt(e.join("/"))}function pt(r){return B(r.map(e=>{let t=m(e[0]),n=Uint8Array.from(ie(t.code));return e.length>1&&e[1]!=null&&(n=B([n,e[1]])),n}))}function go(r,e){if(r.size>0)return r.size/8;if(r.size===0)return 0;{let t=J(e instanceof Uint8Array?e:Uint8Array.from(e));return t+F(t)}}function lt(r){return"/"+r.trim().split("/").filter(e=>e).join("/")}function lr(r){return new Error("Error parsing address: "+r)}var wo=Symbol.for("nodejs.util.inspect.custom"),ft=Symbol.for("@multiformats/js-multiaddr/multiaddr"),xo=[m("dns").code,m("dns4").code,m("dns6").code,m("dnsaddr").code],Ae=class r{bytes;#e;#t;#r;#n;[ft]=!0;constructor(e){e==null&&(e="");let t;if(e instanceof Uint8Array)t=ut(e);else if(typeof e=="string"){if(e.length>0&&e.charAt(0)!=="/")throw new Error(`multiaddr "${e}" must start with a "/"`);t=ar(e)}else if(pr(e))t=ut(e.bytes);else throw new Error("addr must be a string, Buffer, or another Multiaddr");this.bytes=t.bytes,this.#e=t.string,this.#t=t.tuples,this.#r=t.stringTuples,this.#n=t.path}toString(){return this.#e}toJSON(){return this.toString()}toOptions(){let e,t,n,o,s="",i=m("tcp"),a=m("udp"),p=m("ip4"),x=m("ip6"),u=m("dns6"),v=m("ip6zone");for(let[f,l]of this.stringTuples())f===v.code&&(s=`%${l??""}`),xo.includes(f)&&(t=i.name,o=443,n=`${l??""}${s}`,e=f===u.code?6:4),(f===i.code||f===a.code)&&(t=m(f).name,o=parseInt(l??"")),(f===p.code||f===x.code)&&(t=m(f).name,n=`${l??""}${s}`,e=f===x.code?6:4);if(e==null||t==null||n==null||o==null)throw new Error('multiaddr must have a valid format: "/{ip4, ip6, dns4, dns6, dnsaddr}/{address}/{tcp, udp}/{port}".');return{family:e,host:n,transport:t,port:o}}protos(){return this.#t.map(([e])=>Object.assign({},m(e)))}protoCodes(){return this.#t.map(([e])=>e)}protoNames(){return this.#t.map(([e])=>m(e).name)}tuples(){return this.#t}stringTuples(){return this.#r}encapsulate(e){return e=new r(e),new r(this.toString()+e.toString())}decapsulate(e){let t=e.toString(),n=this.toString(),o=n.lastIndexOf(t);if(o<0)throw new Error(`Address ${this.toString()} does not contain subaddress: ${e.toString()}`);return new r(n.slice(0,o))}decapsulateCode(e){let t=this.tuples();for(let n=t.length-1;n>=0;n--)if(t[n][0]===e)return new r(pt(t.slice(0,n)));return this}getPeerId(){try{let e=[];this.stringTuples().forEach(([n,o])=>{n===ce.p2p.code&&e.push([n,o]),n===ce["p2p-circuit"].code&&(e=[])});let t=e.pop();if(t?.[1]!=null){let n=t[1];return n[0]==="Q"||n[0]==="1"?R(P.decode(`z${n}`),"base58btc"):R(G.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){return this.#n}equals(e){return zt(this.bytes,e.bytes)}async resolve(e){let t=this.protos().find(s=>s.resolvable);if(t==null)return[this];let n=ur.get(t.name);if(n==null)throw new A(`no available resolver for ${t.name}`,"ERR_NO_AVAILABLE_RESOLVER");return(await n(this,e)).map(s=>k(s))}nodeAddress(){let e=this.toOptions();if(e.transport!=="tcp"&&e.transport!=="udp")throw new Error(`multiaddr must have a valid format - no protocol with name: "${e.transport}". Must have a valid transport protocol: "{tcp, udp}"`);return{family:e.family,address:e.host,port:e.port}}isThinWaistAddress(e){let t=(e??this).protos();return!(t.length!==2||t[0].code!==4&&t[0].code!==41||t[1].code!==6&&t[1].code!==273)}[wo](){return`Multiaddr(${this.#e})`}};var ur=new Map;function pr(r){return!!r?.[ft]}function k(r){return new Ae(r)}var bo=c("dns4"),yo=c("dns6"),Eo=c("dnsaddr"),K=y(c("dns"),Eo,bo,yo),Se=y(c("ip4"),c("ip6")),H=y(d(Se,c("tcp")),d(K,c("tcp"))),Te=d(Se,c("udp")),vo=d(Te,c("utp")),Ao=d(Te,c("quic")),Io=d(Te,c("quic-v1")),ht=y(d(H,c("ws")),d(K,c("ws"))),Ie=y(d(ht,c("p2p")),ht),mt=y(d(H,c("wss")),d(K,c("wss")),d(H,c("tls"),c("ws")),d(K,c("tls"),c("ws"))),Ce=y(d(mt,c("p2p")),mt),gt=y(d(H,c("http")),d(Se,c("http")),d(K,c("http"))),wt=y(d(H,c("https")),d(Se,c("https")),d(K,c("https"))),fr=d(Te,c("webrtc-direct"),c("certhash")),gr=y(d(fr,c("p2p")),fr),hr=d(Io,c("webtransport"),c("certhash"),c("certhash")),wr=y(d(hr,c("p2p")),hr),xr=y(d(Ie,c("p2p-webrtc-star"),c("p2p")),d(Ce,c("p2p-webrtc-star"),c("p2p")),d(Ie,c("p2p-webrtc-star")),d(Ce,c("p2p-webrtc-star"))),fc=y(d(Ie,c("p2p-websocket-star"),c("p2p")),d(Ce,c("p2p-websocket-star"),c("p2p")),d(Ie,c("p2p-websocket-star")),d(Ce,c("p2p-websocket-star"))),br=y(d(gt,c("p2p-webrtc-direct"),c("p2p")),d(wt,c("p2p-webrtc-direct"),c("p2p")),d(gt,c("p2p-webrtc-direct")),d(wt,c("p2p-webrtc-direct"))),Y=y(ht,mt,gt,wt,xr,br,H,vo,Ao,K,gr,wr),hc=y(d(Y,c("p2p-stardust"),c("p2p")),d(Y,c("p2p-stardust"))),W=y(d(Y,c("p2p")),xr,br,gr,wr,c("p2p")),mr=y(d(W,c("p2p-circuit"),W),d(W,c("p2p-circuit")),d(c("p2p-circuit"),W),d(Y,c("p2p-circuit")),d(c("p2p-circuit"),Y),c("p2p-circuit")),yr=()=>y(d(mr,yr),mr),Q=yr(),mc=y(d(Q,W,Q),d(W,Q),d(Q,W),Q,W);var gc=y(d(Q,c("webrtc"),c("p2p")),d(Q,c("webrtc")),d(Y,c("webrtc"),c("p2p")),d(Y,c("webrtc")),c("webrtc"));function Er(r){function e(t){let n;try{n=k(t)}catch{return!1}let o=r(n.protoNames());return o===null?!1:o===!0||o===!1?o:o.length===0}return e}function d(...r){function e(t){if(t.length<r.length)return null;let n=t;return r.some(o=>(n=typeof o=="function"?o().partialMatch(t):o.partialMatch(t),Array.isArray(n)&&(t=n),n===null)),n}return{toString:function(){return"{ "+r.join(" ")+" }"},input:r,matches:Er(e),partialMatch:e}}function y(...r){function e(n){let o=null;return r.some(s=>{let i=typeof s=="function"?s().partialMatch(n):s.partialMatch(n);return i!=null?(o=i,!0):!1}),o}return{toString:function(){return"{ "+r.join(" ")+" }"},input:r,matches:Er(e),partialMatch:e}}function c(r){let e=r;function t(o){let s;try{s=k(o)}catch{return!1}let i=s.protoNames();return i.length===1&&i[0]===e}function n(o){return o.length===0?null:o[0]===e?o.slice(1):null}return{toString:function(){return e},matches:t,partialMatch:n}}var Tr=de(L("net"),1);var xt={ERR_INVALID_IP_PARAMETER:"ERR_INVALID_IP_PARAMETER",ERR_INVALID_PORT_PARAMETER:"ERR_INVALID_PORT_PARAMETER",ERR_INVALID_IP:"ERR_INVALID_IP"};function vr(r,e){if(typeof r!="string")throw new A(`invalid ip provided: ${r}`,xt.ERR_INVALID_IP_PARAMETER);if(typeof e=="string"&&(e=parseInt(e)),isNaN(e))throw new A(`invalid port provided: ${e}`,xt.ERR_INVALID_PORT_PARAMETER);if((0,_.isIPv4)(r))return k(`/ip4/${r}/tcp/${e}`);if((0,_.isIPv6)(r))return k(`/ip6/${r}/tcp/${e}`);throw new A(`invalid ip:port for creating a multiaddr: ${r}:${e}`,xt.ERR_INVALID_IP)}function Ar(r){if(To(r))return async function*(){let e=r.getReader();try{for(;;){let{done:t,value:n}=await e.read();if(t)return;yield n}}finally{e.releaseLock()}}();if(So(r))return r;throw new Error("unknown stream")}function So(r){return r[Symbol.asyncIterator]!=null}function To(r){return typeof r?.getReader=="function"}function Ir(r){return async e=>{let t=async()=>{Po(e)&&await e.return(void 0)},n,o,s=w=>{n=w,t().catch(E=>{E=new AggregateError([n,E],"The Writable emitted an error, additionally an error occurred while ending the Source")}).finally(()=>{o?.(w)})},i,a=!1,p=()=>{a=!0,i?.()},x,u=!1,v=()=>{u=!0,x?.()},C,f=()=>{C?.()},l=async()=>new Promise((w,E)=>{i=C=w,o=E,r.once("drain",f)}),g=async()=>(await t(),new Promise((w,E)=>{if(a||u||n!=null){w();return}x=i=w,o=E})),T=()=>{r.removeListener("error",s),r.removeListener("close",p),r.removeListener("finish",v),r.removeListener("drain",f)};r.once("error",s),r.once("close",p),r.once("finish",v);try{for await(let w of e){if(!r.writable||r.destroyed||n!=null)break;r.write(w)||await l()}}catch(w){n==null&&r.destroy(w),n=w}try{if(r.writable&&r.end(),await g(),n!=null)throw n}finally{T()}}}function Po(r){return r.return!=null}function bt(r){return{sink:Ir(r),source:Ar(r)}}var yt=de(L("os"),1),Cr=de(L("path"),1);var Ro={ip4:"IPv4",ip6:"IPv6"};function ae(r,e={}){let t=r.getPath();return t!=null?yt.default.platform()==="win32"?{path:Cr.default.join("\\\\.\\pipe\\",t)}:{path:t}:{...e,...r.toOptions()}}function Et(r,e,t){let n=o=>k(`/${r}/${o}/tcp/${t}`);return(No(e)?Mo(Ro[r]):[e]).map(n)}function No(r){return["0.0.0.0","::"].includes(r)}var Do=yt.default.networkInterfaces();function Mo(r){let e=[];for(let[,t]of Object.entries(Do))if(t!=null)for(let n of t)n.family===r&&e.push(n.address);return e}var Pe=(r,e)=>{let t="open",n=e.logger.forComponent("libp2p:tcp:socket"),o=e.metrics,s=e.metricPrefix??"",i=e.socketInactivityTimeout??3e5,a=e.socketCloseTimeout??500;e.listeningAddr?.getPath()!=null&&(e.remoteAddr=e.listeningAddr),e.remoteAddr?.getPath()!=null&&(e.localAddr=e.remoteAddr);let p;if(e.remoteAddr!=null)p=e.remoteAddr;else{if(r.remoteAddress==null||r.remotePort==null)throw new A("Could not determine remote address or port","ERR_NO_REMOTE_ADDRESS");p=vr(r.remoteAddress,r.remotePort)}let x=ae(p),u=x.path??`${x.host??""}:${x.port??""}`,{sink:v,source:C}=bt(r);r.setTimeout(i,()=>{n("%s socket read timeout",u),o?.increment({[`${s}timeout`]:!0});let l;r.readable&&(l=new A("Socket read timeout","ERR_SOCKET_READ_TIMEOUT")),r.destroy(l)}),r.once("close",()=>{n("%s socket close",u),o?.increment({[`${s}close`]:!0}),f.timeline.close==null&&(f.timeline.close=Date.now())}),r.once("end",()=>{n("%s socket end",u),o?.increment({[`${s}end`]:!0})});let f={async sink(l){try{await v(async function*(){for await(let g of l)g instanceof Uint8Array?yield g:yield g.subarray()}())}catch(g){g.type!=="aborted"&&n.error("%s error in sink",u,g)}r.end()},source:C,remoteAddr:p,timeline:{open:Date.now()},async close(l={}){if(t==="closed"||t==="closing"||r.destroyed){n("The %s socket is either closed, closing, or already destroyed",u);return}if(t="closing",l.signal==null){let T=AbortSignal.timeout(a);l={...l,signal:T}}let g=()=>{r.destroy(new A("Destroying socket after timeout","ERR_CLOSE_TIMEOUT"))};l.signal?.addEventListener("abort",g);try{n("%s closing socket",u),await new Promise((T,w)=>{r.once("close",()=>{n("%s socket closed",u),t="closed",T()}),r.once("error",E=>{n("%s socket error",u,E),f.timeline.close==null&&(f.timeline.close=Date.now()),t="closed",w(E)}),r.setTimeout(a),r.end(),r.writableLength>0?r.once("drain",()=>{n("%s socket drained",u),r.destroy()}):r.destroy()})}catch(T){this.abort(T)}finally{l.signal?.removeEventListener("abort",g)}},abort:l=>{n("%s socket abort due to error",u,l),r.destroyed||r.destroy(l),f.timeline.close==null&&(f.timeline.close=Date.now())},log:n};return f};async function Sr(r,e){try{await r.close()}catch(t){e.log.error("an error occurred closing the connection",t),r.abort(t)}}var I;(function(r){r[r.INACTIVE=0]="INACTIVE",r[r.ACTIVE=1]="ACTIVE",r[r.PAUSED=2]="PAUSED"})(I||(I={}));var Re=class extends ge{context;server;connections=new Set;status={code:I.INACTIVE};metrics;addr;log;constructor(e){if(super(),this.context=e,e.keepAlive=e.keepAlive??!0,e.noDelay=e.noDelay??!0,this.log=e.logger.forComponent("libp2p:tcp:listener"),this.addr="unknown",this.server=Tr.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 A("closeAbove must be >= listenBelow","ERR_CONNECTION_LIMITS");this.server.on("listening",()=>{if(e.metrics!=null){let t=this.server.address();t==null?this.addr="unknown":typeof t=="string"?this.addr=t:this.addr=`${t.address}:${t.port}`,e.metrics?.registerMetricGroup("libp2p_tcp_inbound_connections_total",{label:"address",help:"Current active connections in TCP listener",calculate:()=>({[this.addr]:this.connections.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.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")})}onSocket(e){if(this.status.code!==I.ACTIVE)throw new A("Server is not listening yet","ERR_SERVER_NOT_RUNNING");e.on("error",n=>{this.log("socket error",n),this.metrics?.events.increment({[`${this.addr} error`]:!0})});let t;try{t=Pe(e,{listeningAddr:this.status.listeningAddr,socketInactivityTimeout:this.context.socketInactivityTimeout,socketCloseTimeout:this.context.socketCloseTimeout,metrics:this.metrics?.events,metricPrefix:`${this.addr} `,logger:this.context.logger})}catch(n){this.log.error("inbound connection failed",n),this.metrics?.errors.increment({[`${this.addr} inbound_to_connection`]:!0});return}this.log("new inbound connection %s",t.remoteAddr);try{this.context.upgrader.upgradeInbound(t).then(n=>{this.log("inbound connection upgraded %s",t.remoteAddr),this.connections.add(t),e.once("close",()=>{this.connections.delete(t),this.context.closeServerOnMaxConnections!=null&&this.connections.size<this.context.closeServerOnMaxConnections.listenBelow&&this.resume().catch(o=>{this.log.error("error attempting to listen server once connection count under limit",o),this.context.closeServerOnMaxConnections?.onListenError?.(o)})}),this.context.handler!=null&&this.context.handler(n),this.context.closeServerOnMaxConnections!=null&&this.connections.size>=this.context.closeServerOnMaxConnections.closeAbove&&this.pause(!1).catch(o=>{this.log.error("error attempting to close server once connection count over limit",o)}),this.safeDispatchEvent("connection",{detail:n})}).catch(async n=>{this.log.error("inbound connection failed",n),this.metrics?.errors.increment({[`${this.addr} inbound_upgrade`]:!0}),await Sr(t,{log:this.log})}).catch(n=>{this.log.error("closing inbound connection failed",n)})}catch(n){this.log.error("inbound connection failed",n),Sr(t,{log:this.log}).catch(o=>{this.log.error("closing inbound connection failed",o),this.metrics?.errors.increment({[`${this.addr} inbound_closing_failed`]:!0})})}}getAddrs(){if(this.status.code===I.INACTIVE)return[];let e=[],t=this.server.address(),{listeningAddr:n,peerId:o}=this.status;if(t==null)return[];if(typeof t=="string")e=[n];else try{n.toString().startsWith("/ip4")?e=e.concat(Et("ip4",t.address,t.port)):t.family==="IPv6"&&(e=e.concat(Et("ip6",t.address,t.port)))}catch(s){this.log.error("could not turn %s:%s into multiaddr",t.address,t.port,s)}return e.map(s=>o!=null?s.encapsulate(`/p2p/${o}`):s)}async listen(e){if(this.status.code===I.ACTIVE||this.status.code===I.PAUSED)throw new A("server is already listening","ERR_SERVER_ALREADY_LISTENING");let t=e.getPeerId(),n=t==null?e.decapsulateCode(421):e,{backlog:o}=this.context;try{this.status={code:I.ACTIVE,listeningAddr:n,peerId:t,netConfig:ae(n,{backlog:o})},await this.resume()}catch(s){throw this.status={code:I.INACTIVE},s}}async close(){let e=new A("Listener is closing","ERR_LISTENER_CLOSING");this.connections.forEach(t=>{t.abort(e)}),await this.pause(!0)}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())}async pause(e){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("closing server on %s",this.server.address()),this.status=e?{code:I.INACTIVE}:{...this.status,code:I.PAUSED},await new Promise((t,n)=>{this.server.close(o=>{if(o!=null){n(o);return}t()})}))}};var vt=class{opts;metrics;components;log;constructor(e,t={}){this.log=e.logger.forComponent("libp2p:tcp"),this.opts=t,this.components=e,e.metrics!=null&&(this.metrics={dialerEvents:e.metrics.registerCounterGroup("libp2p_tcp_dialer_events_total",{label:"event",help:"Total count of TCP dialer events by type"})})}[Ct]=!0;[Symbol.toStringTag]="@libp2p/tcp";async dial(e,t){t.keepAlive=t.keepAlive??!0,t.noDelay=t.noDelay??!0;let n=await this._connect(e,t);n.on("error",a=>{this.log("socket error",a)});let o=Pe(n,{remoteAddr:e,socketInactivityTimeout:this.opts.outboundSocketInactivityTimeout,socketCloseTimeout:this.opts.socketCloseTimeout,metrics:this.metrics?.dialerEvents,logger:this.components.logger}),s=()=>{o.close().catch(a=>{this.log.error("Error closing maConn after abort",a)})};t.signal?.addEventListener("abort",s,{once:!0}),this.log("new outbound connection %s",o.remoteAddr);let i=await t.upgrader.upgradeOutbound(o);if(this.log("outbound connection %s upgraded",o.remoteAddr),t.signal?.removeEventListener("abort",s),t.signal?.aborted===!0)throw i.close().catch(a=>{this.log.error("Error closing conn after abort",a)}),new Z;return i}async _connect(e,t){if(t.signal?.aborted===!0)throw new Z;return new Promise((n,o)=>{let s=Date.now(),i=ae(e,{...this.opts.dialOpts??{},...t});this.log("dialing %a",e);let a=Pr.default.connect(i),p=f=>{let l=i.path??`${i.host??""}:${i.port}`;f.message=`connection error ${l}: ${f.message}`,this.metrics?.dialerEvents.increment({error:!0}),C(f)},x=()=>{this.log("connection timeout %a",e),this.metrics?.dialerEvents.increment({timeout:!0});let f=new A(`connection timeout after ${Date.now()-s}ms`,"ERR_CONNECT_TIMEOUT");a.emit("error",f)},u=()=>{this.log("connection opened %a",e),this.metrics?.dialerEvents.increment({connect:!0}),C()},v=()=>{this.log("connection aborted %a",e),this.metrics?.dialerEvents.increment({abort:!0}),a.destroy(),C(new Z)},C=f=>{if(a.removeListener("error",p),a.removeListener("timeout",x),a.removeListener("connect",u),t.signal!=null&&t.signal.removeEventListener("abort",v),f!=null){o(f);return}n(a)};a.on("error",p),a.on("timeout",x),a.on("connect",u),t.signal!=null&&t.signal.addEventListener("abort",v)})}createListener(e){return new Re({...this.opts.listenOpts??{},...e,maxConnections:this.opts.maxConnections,backlog:this.opts.backlog,closeServerOnMaxConnections:this.opts.closeServerOnMaxConnections,socketInactivityTimeout:this.opts.inboundSocketInactivityTimeout,socketCloseTimeout:this.opts.socketCloseTimeout,metrics:this.components.metrics,logger:this.components.logger})}filter(e){return e=Array.isArray(e)?e:[e],e.filter(t=>t.protoCodes().includes(290)?!1:t.protoCodes().includes(400)?!0:H.matches(t.decapsulateCode(421)))}};function Uo(r={}){return e=>new vt(e,r)}return Ur(Lo);})();
|
|
3
3
|
return Libp2PTcp}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"socket-to-conn.d.ts","sourceRoot":"","sources":["../../src/socket-to-conn.ts"],"names":[],"mappings":";AAKA,OAAO,KAAK,EAAE,eAAe,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAC3F,OAAO,KAAK,EAAgB,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACtE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,KAAK,CAAA;AAEjC,UAAU,mBAAmB;IAC3B,aAAa,CAAC,EAAE,SAAS,CAAA;IACzB,UAAU,CAAC,EAAE,SAAS,CAAA;IACtB,SAAS,CAAC,EAAE,SAAS,CAAA;IACrB,uBAAuB,CAAC,EAAE,MAAM,CAAA;IAChC,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAC3B,OAAO,CAAC,EAAE,YAAY,CAAA;IACtB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,MAAM,EAAE,eAAe,CAAA;CACxB;AAED;;;GAGG;AACH,eAAO,MAAM,qBAAqB,WAAY,MAAM,WAAW,mBAAmB,KAAG,
|
|
1
|
+
{"version":3,"file":"socket-to-conn.d.ts","sourceRoot":"","sources":["../../src/socket-to-conn.ts"],"names":[],"mappings":";AAKA,OAAO,KAAK,EAAE,eAAe,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAC3F,OAAO,KAAK,EAAgB,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACtE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,KAAK,CAAA;AAEjC,UAAU,mBAAmB;IAC3B,aAAa,CAAC,EAAE,SAAS,CAAA;IACzB,UAAU,CAAC,EAAE,SAAS,CAAA;IACtB,SAAS,CAAC,EAAE,SAAS,CAAA;IACrB,uBAAuB,CAAC,EAAE,MAAM,CAAA;IAChC,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAC3B,OAAO,CAAC,EAAE,YAAY,CAAA;IACtB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,MAAM,EAAE,eAAe,CAAA;CACxB;AAED;;;GAGG;AACH,eAAO,MAAM,qBAAqB,WAAY,MAAM,WAAW,mBAAmB,KAAG,mBA+LpF,CAAA"}
|
|
@@ -8,6 +8,7 @@ import { multiaddrToNetConfig } from './utils.js';
|
|
|
8
8
|
* https://github.com/libp2p/interface-transport#multiaddrconnection
|
|
9
9
|
*/
|
|
10
10
|
export const toMultiaddrConnection = (socket, options) => {
|
|
11
|
+
let status = 'open';
|
|
11
12
|
const log = options.logger.forComponent('libp2p:tcp:socket');
|
|
12
13
|
const metrics = options.metrics;
|
|
13
14
|
const metricPrefix = options.metricPrefix ?? '';
|
|
@@ -96,10 +97,11 @@ export const toMultiaddrConnection = (socket, options) => {
|
|
|
96
97
|
remoteAddr,
|
|
97
98
|
timeline: { open: Date.now() },
|
|
98
99
|
async close(options = {}) {
|
|
99
|
-
if (socket.destroyed) {
|
|
100
|
-
log('%s socket
|
|
100
|
+
if (status === 'closed' || status === 'closing' || socket.destroyed) {
|
|
101
|
+
log('The %s socket is either closed, closing, or already destroyed', lOptsStr);
|
|
101
102
|
return;
|
|
102
103
|
}
|
|
104
|
+
status = 'closing';
|
|
103
105
|
if (options.signal == null) {
|
|
104
106
|
const signal = AbortSignal.timeout(closeTimeout);
|
|
105
107
|
options = {
|
|
@@ -117,6 +119,7 @@ export const toMultiaddrConnection = (socket, options) => {
|
|
|
117
119
|
socket.once('close', () => {
|
|
118
120
|
// socket completely closed
|
|
119
121
|
log('%s socket closed', lOptsStr);
|
|
122
|
+
status = 'closed';
|
|
120
123
|
resolve();
|
|
121
124
|
});
|
|
122
125
|
socket.once('error', (err) => {
|
|
@@ -125,6 +128,7 @@ export const toMultiaddrConnection = (socket, options) => {
|
|
|
125
128
|
if (maConn.timeline.close == null) {
|
|
126
129
|
maConn.timeline.close = Date.now();
|
|
127
130
|
}
|
|
131
|
+
status = 'closed';
|
|
128
132
|
reject(err);
|
|
129
133
|
});
|
|
130
134
|
// shorten inactivity timeout
|
|
@@ -154,7 +158,10 @@ export const toMultiaddrConnection = (socket, options) => {
|
|
|
154
158
|
},
|
|
155
159
|
abort: (err) => {
|
|
156
160
|
log('%s socket abort due to error', lOptsStr, err);
|
|
157
|
-
socket
|
|
161
|
+
// the abortSignalListener may already destroyed the socket with an error
|
|
162
|
+
if (!socket.destroyed) {
|
|
163
|
+
socket.destroy(err);
|
|
164
|
+
}
|
|
158
165
|
if (maConn.timeline.close == null) {
|
|
159
166
|
maConn.timeline.close = Date.now();
|
|
160
167
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"socket-to-conn.js","sourceRoot":"","sources":["../../src/socket-to-conn.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAC7C,OAAO,EAAE,iBAAiB,IAAI,WAAW,E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,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,IAAI,IAAI,EAAE,CAAC;gBAClC,MAAM,CAAC,QAAQ,CAAC,KAAK,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;YACpC,CAAC;QACH,CAAC;QAED,GAAG;KACJ,CAAA;IAED,OAAO,MAAM,CAAA;AACf,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libp2p/tcp",
|
|
3
|
-
"version": "9.0.
|
|
3
|
+
"version": "9.0.20-31c78f4ed",
|
|
4
4
|
"description": "A TCP transport for libp2p",
|
|
5
5
|
"license": "Apache-2.0 OR MIT",
|
|
6
6
|
"homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/transport-tcp#readme",
|
|
@@ -56,16 +56,16 @@
|
|
|
56
56
|
"test:electron-main": "aegir test -t electron-main"
|
|
57
57
|
},
|
|
58
58
|
"dependencies": {
|
|
59
|
-
"@libp2p/interface": "
|
|
60
|
-
"@libp2p/utils": "
|
|
59
|
+
"@libp2p/interface": "1.2.0-31c78f4ed",
|
|
60
|
+
"@libp2p/utils": "5.3.0-31c78f4ed",
|
|
61
61
|
"@multiformats/mafmt": "^12.1.6",
|
|
62
62
|
"@multiformats/multiaddr": "^12.2.1",
|
|
63
63
|
"@types/sinon": "^17.0.3",
|
|
64
64
|
"stream-to-it": "^1.0.0"
|
|
65
65
|
},
|
|
66
66
|
"devDependencies": {
|
|
67
|
-
"@libp2p/interface-compliance-tests": "
|
|
68
|
-
"@libp2p/logger": "
|
|
67
|
+
"@libp2p/interface-compliance-tests": "5.4.0-31c78f4ed",
|
|
68
|
+
"@libp2p/logger": "4.0.10-31c78f4ed",
|
|
69
69
|
"aegir": "^42.2.5",
|
|
70
70
|
"it-all": "^3.0.4",
|
|
71
71
|
"it-pipe": "^3.0.1",
|
package/src/socket-to-conn.ts
CHANGED
|
@@ -23,6 +23,7 @@ interface ToConnectionOptions {
|
|
|
23
23
|
* https://github.com/libp2p/interface-transport#multiaddrconnection
|
|
24
24
|
*/
|
|
25
25
|
export const toMultiaddrConnection = (socket: Socket, options: ToConnectionOptions): MultiaddrConnection => {
|
|
26
|
+
let status: 'open' | 'closing' | 'closed' = 'open'
|
|
26
27
|
const log = options.logger.forComponent('libp2p:tcp:socket')
|
|
27
28
|
const metrics = options.metrics
|
|
28
29
|
const metricPrefix = options.metricPrefix ?? ''
|
|
@@ -126,10 +127,11 @@ export const toMultiaddrConnection = (socket: Socket, options: ToConnectionOptio
|
|
|
126
127
|
timeline: { open: Date.now() },
|
|
127
128
|
|
|
128
129
|
async close (options: AbortOptions = {}) {
|
|
129
|
-
if (socket.destroyed) {
|
|
130
|
-
log('%s socket
|
|
130
|
+
if (status === 'closed' || status === 'closing' || socket.destroyed) {
|
|
131
|
+
log('The %s socket is either closed, closing, or already destroyed', lOptsStr)
|
|
131
132
|
return
|
|
132
133
|
}
|
|
134
|
+
status = 'closing'
|
|
133
135
|
|
|
134
136
|
if (options.signal == null) {
|
|
135
137
|
const signal = AbortSignal.timeout(closeTimeout)
|
|
@@ -153,6 +155,7 @@ export const toMultiaddrConnection = (socket: Socket, options: ToConnectionOptio
|
|
|
153
155
|
// socket completely closed
|
|
154
156
|
log('%s socket closed', lOptsStr)
|
|
155
157
|
|
|
158
|
+
status = 'closed'
|
|
156
159
|
resolve()
|
|
157
160
|
})
|
|
158
161
|
socket.once('error', (err: Error) => {
|
|
@@ -163,6 +166,7 @@ export const toMultiaddrConnection = (socket: Socket, options: ToConnectionOptio
|
|
|
163
166
|
maConn.timeline.close = Date.now()
|
|
164
167
|
}
|
|
165
168
|
|
|
169
|
+
status = 'closed'
|
|
166
170
|
reject(err)
|
|
167
171
|
})
|
|
168
172
|
|
|
@@ -195,7 +199,10 @@ export const toMultiaddrConnection = (socket: Socket, options: ToConnectionOptio
|
|
|
195
199
|
abort: (err: Error) => {
|
|
196
200
|
log('%s socket abort due to error', lOptsStr, err)
|
|
197
201
|
|
|
198
|
-
socket
|
|
202
|
+
// the abortSignalListener may already destroyed the socket with an error
|
|
203
|
+
if (!socket.destroyed) {
|
|
204
|
+
socket.destroy(err)
|
|
205
|
+
}
|
|
199
206
|
|
|
200
207
|
if (maConn.timeline.close == null) {
|
|
201
208
|
maConn.timeline.close = Date.now()
|
package/dist/typedoc-urls.json
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"TCPComponents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_tcp.TCPComponents.html",
|
|
3
|
-
".:TCPComponents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_tcp.TCPComponents.html",
|
|
4
|
-
"TCPCreateListenerOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_tcp.TCPCreateListenerOptions.html",
|
|
5
|
-
".:TCPCreateListenerOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_tcp.TCPCreateListenerOptions.html",
|
|
6
|
-
"TCPDialOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_tcp.TCPDialOptions.html",
|
|
7
|
-
".:TCPDialOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_tcp.TCPDialOptions.html",
|
|
8
|
-
"TCPMetrics": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_tcp.TCPMetrics.html",
|
|
9
|
-
".:TCPMetrics": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_tcp.TCPMetrics.html",
|
|
10
|
-
"TCPOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_tcp.TCPOptions.html",
|
|
11
|
-
".:TCPOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_tcp.TCPOptions.html",
|
|
12
|
-
"TCPSocketOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_tcp.TCPSocketOptions.html",
|
|
13
|
-
".:TCPSocketOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_tcp.TCPSocketOptions.html",
|
|
14
|
-
"tcp": "https://libp2p.github.io/js-libp2p/functions/_libp2p_tcp.tcp.html",
|
|
15
|
-
".:tcp": "https://libp2p.github.io/js-libp2p/functions/_libp2p_tcp.tcp.html"
|
|
16
|
-
}
|