@libp2p/tcp 10.0.1 → 10.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.min.js +1 -1
- package/package.json +5 -5
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 Nr=Object.create;var ge=Object.defineProperty;var Lr=Object.getOwnPropertyDescriptor;var Fr=Object.getOwnPropertyNames;var $r=Object.getPrototypeOf,Or=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 k=(r,e)=>{for(var t in e)ge(r,t,{get:e[t],enumerable:!0})},Pt=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Fr(e))!Or.call(r,o)&&o!==t&&ge(r,o,{get:()=>e[o],enumerable:!(n=Lr(e,o))||n.enumerable});return r};var de=(r,e,t)=>(t=r!=null?Nr($r(r)):{},Pt(e||!r||!r.__esModule?ge(t,"default",{value:r,enumerable:!0}):t,r)),zr=r=>Pt(ge({},"__esModule",{value:!0}),r);var zo={};k(zo,{tcp:()=>Oo});var Mr=de(L("net"),1);var Ut=Symbol.for("@libp2p/transport");var kt;(function(r){r[r.FATAL_ALL=0]="FATAL_ALL",r[r.NO_FATAL=1]="NO_FATAL"})(kt||(kt={}));var _=class extends Error{static name="AbortError";constructor(e="The operation was aborted"){super(e),this.name="AbortError"}};var z=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}};var ee=class extends Error{static name="TimeoutError";constructor(e="Timed out"){super(e),this.name="TimeoutError"}},xe=class extends Error{static name="NotStartedError";constructor(e="Not started"){super(e),this.name="NotStartedError"}},we=class extends Error{static name="AlreadyStartedError";constructor(e="Already started"){super(e),this.name="AlreadyStartedError"}};var Dt=L("events"),Mt=(r,...e)=>{try{(0,Dt.setMaxListeners)(r,...e)}catch{}};var be=class extends EventTarget{#e=new Map;constructor(){super(),Mt(1/0,this)}listenerCount(e){let t=this.#e.get(e);return t==null?0:t.length}addEventListener(e,t,n){super.addEventListener(e,t,n);let o=this.#e.get(e);o==null&&(o=[],this.#e.set(e,o)),o.push({callback:t,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(e,t,n){super.removeEventListener(e.toString(),t??null,n);let o=this.#e.get(e);o!=null&&(o=o.filter(({callback:s})=>s!==t),this.#e.set(e,o))}dispatchEvent(e){let t=super.dispatchEvent(e),n=this.#e.get(e.type);return n==null||(n=n.filter(({once:o})=>!o),this.#e.set(e.type,n)),t}safeDispatchEvent(e,t={}){return this.dispatchEvent(new CustomEvent(e,t))}};var Nt=Symbol.for("@libp2p/service-capabilities"),Wo=Symbol.for("@libp2p/service-dependencies");var Ve={};k(Ve,{base58btc:()=>T,base58flickr:()=>qr});var ms=new Uint8Array(0);function Lt(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 Ft(r){return new TextEncoder().encode(r)}function $t(r){return new TextDecoder().decode(r)}function Vr(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),w=Math.log(a)/Math.log(256),u=Math.log(256)/Math.log(a);function E(d){if(d instanceof Uint8Array||(ArrayBuffer.isView(d)?d=new Uint8Array(d.buffer,d.byteOffset,d.byteLength):Array.isArray(d)&&(d=Uint8Array.from(d))),!(d instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(d.length===0)return"";for(var g=0,S=0,x=0,v=d.length;x!==v&&d[x]===0;)x++,g++;for(var $=(v-x)*u+1>>>0,U=new Uint8Array($);x!==v;){for(var O=d[x],q=0,N=$-1;(O!==0||q<S)&&N!==-1;N--,q++)O+=256*U[N]>>>0,U[N]=O%a>>>0,O=O/a>>>0;if(O!==0)throw new Error("Non-zero carry");S=q,x++}for(var B=$-S;B!==$&&U[B]===0;)B++;for(var me=p.repeat(g);B<$;++B)me+=r.charAt(U[B]);return me}function I(d){if(typeof d!="string")throw new TypeError("Expected String");if(d.length===0)return new Uint8Array;var g=0;if(d[g]!==" "){for(var S=0,x=0;d[g]===p;)S++,g++;for(var v=(d.length-g)*w+1>>>0,$=new Uint8Array(v);d[g];){var U=t[d.charCodeAt(g)];if(U===255)return;for(var O=0,q=v-1;(U!==0||O<x)&&q!==-1;q--,O++)U+=a*$[q]>>>0,$[q]=U%256>>>0,U=U/256>>>0;if(U!==0)throw new Error("Non-zero carry");x=O,g++}if(d[g]!==" "){for(var N=v-x;N!==v&&$[N]===0;)N++;for(var B=new Uint8Array(S+(v-N)),me=S;N!==v;)B[me++]=$[N++];return B}}}function f(d){var g=I(d);if(g)return g;throw new Error(`Non-${e} character`)}return{encode:E,decodeUnsafe:I,decode:f}}var Br=Vr,_r=Br,zt=_r;var Fe=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")}},$e=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 Vt(this,e)}},Oe=class{decoders;constructor(e){this.decoders=e}or(e){return Vt(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 Vt(r,e){return new Oe({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var ze=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 Fe(e,t,n),this.decoder=new $e(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function te({name:r,prefix:e,encode:t,decode:n}){return new ze(r,e,t,n)}function W({name:r,prefix:e,alphabet:t}){let{encode:n,decode:o}=zt(t,r);return te({prefix:e,name:r,encode:n,decode:s=>D(o(s))})}function Rr(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,w=0;for(let u=0;u<s;++u){let E=o[r[u]];if(E===void 0)throw new SyntaxError(`Non-${n} character`);p=p<<t|E,a+=t,a>=8&&(a-=8,i[w++]=255&p>>a)}if(a>=t||255&p<<8-a)throw new SyntaxError("Unexpected end of data");return i}function jr(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 te({prefix:e,name:r,encode(o){return jr(o,n,t)},decode(o){return Rr(o,n,t,r)}})}var T=W({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),qr=W({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Be={};k(Be,{base32:()=>R,base32hex:()=>Jr,base32hexpad:()=>Qr,base32hexpadupper:()=>Kr,base32hexupper:()=>Xr,base32pad:()=>Gr,base32padupper:()=>Hr,base32upper:()=>Wr,base32z:()=>Zr});var R=b({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Wr=b({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Gr=b({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Hr=b({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Jr=b({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Xr=b({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Qr=b({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Kr=b({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Zr=b({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Yr=Rt,Bt=128,en=127,tn=~en,rn=Math.pow(2,31);function Rt(r,e,t){e=e||[],t=t||0;for(var n=t;r>=rn;)e[t++]=r&255|Bt,r/=128;for(;r&tn;)e[t++]=r&255|Bt,r>>>=7;return e[t]=r|0,Rt.bytes=t-n+1,e}var nn=_e,on=128,_t=127;function _e(r,n){var t=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw _e.bytes=0,new RangeError("Could not decode varint");i=r[s++],t+=o<28?(i&_t)<<o:(i&_t)*Math.pow(2,o),o+=7}while(i>=on);return _e.bytes=s-n,t}var sn=Math.pow(2,7),cn=Math.pow(2,14),an=Math.pow(2,21),ln=Math.pow(2,28),dn=Math.pow(2,35),un=Math.pow(2,42),pn=Math.pow(2,49),fn=Math.pow(2,56),hn=Math.pow(2,63),mn=function(r){return r<sn?1:r<cn?2:r<an?3:r<ln?4:r<dn?5:r<un?6:r<pn?7:r<fn?8:r<hn?9:10},gn={encode:Yr,decode:nn,encodingLength:mn},xn=gn,ue=xn;function pe(r,e=0){return[ue.decode(r,e),ue.decode.bytes]}function re(r,e,t=0){return ue.encode(r,e,t),e}function ne(r){return ue.encodingLength(r)}function X(r,e){let t=e.byteLength,n=ne(r),o=n+ne(t),s=new Uint8Array(o+t);return re(r,s,0),re(t,s,n),s.set(e,o),new oe(r,t,e,s)}function ve(r){let e=D(r),[t,n]=pe(e),[o,s]=pe(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new oe(t,o,i,e)}function jt(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&Lt(r.bytes,t.bytes)}}var oe=class{code;size;digest;bytes;constructor(e,t,n,o){this.code=e,this.size=t,this.digest=n,this.bytes=o}};function qt(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return bn(t,Re(r),e??T.encoder);default:return yn(t,Re(r),e??R.encoder)}}var Wt=new WeakMap;function Re(r){let e=Wt.get(r);if(e==null){let t=new Map;return Wt.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!==fe)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==vn)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&&jt(e.multihash,n.multihash)}toString(e){return qt(this,e)}toJSON(){return{"/":qt(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??Gt(n,o,s.bytes))}else if(t[En]===!0){let{version:n,multihash:o,code:s}=t,i=ve(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!==fe)throw new Error(`Version 0 CID must use dag-pb (code: ${fe}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let o=Gt(e,t,n.bytes);return new r(e,t,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,fe,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 oe(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[E,I]=pe(e.subarray(t));return t+=I,E},o=n(),s=fe;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(),w=t+p,u=w-i;return{version:o,codec:s,multihashCode:a,digestSize:p,multihashSize:u,size:w}}static parse(e,t){let[n,o]=wn(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 Re(s).set(n,e),s}};function wn(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 R.prefix:{let t=e??R;return[R.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 bn(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 yn(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 fe=112,vn=18;function Gt(r,e,t){let n=ne(r),o=n+ne(e),s=new Uint8Array(o+t.byteLength);return re(r,s,0),re(e,s,n),s.set(t,o),s}var En=Symbol.for("@ipld/js-cid/CID");function Ht(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 tr=L("node:buffer");var je={};k(je,{base10:()=>An});var An=W({prefix:"9",name:"base10",alphabet:"0123456789"});var qe={};k(qe,{base16:()=>In,base16upper:()=>Cn});var In=b({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Cn=b({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var We={};k(We,{base2:()=>Sn});var Sn=b({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Ge={};k(Ge,{base256emoji:()=>Dn});var Jt=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}"),Tn=Jt.reduce((r,e,t)=>(r[t]=e,r),[]),Pn=Jt.reduce((r,e,t)=>(r[e.codePointAt(0)]=t,r),[]);function kn(r){return r.reduce((e,t)=>(e+=Tn[t],e),"")}function Un(r){let e=[];for(let t of r){let n=Pn[t.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${t}`);e.push(n)}return new Uint8Array(e)}var Dn=te({prefix:"\u{1F680}",name:"base256emoji",encode:kn,decode:Un});var He={};k(He,{base36:()=>Mn,base36upper:()=>Nn});var Mn=W({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Nn=W({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Je={};k(Je,{base64:()=>Ln,base64pad:()=>Fn,base64url:()=>$n,base64urlpad:()=>On});var Ln=b({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Fn=b({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),$n=b({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),On=b({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Xe={};k(Xe,{base8:()=>zn});var zn=b({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Qe={};k(Qe,{identity:()=>Vn});var Vn=te({prefix:"\0",name:"identity",encode:r=>$t(r),decode:r=>Ft(r)});var Bs=new TextEncoder,_s=new TextDecoder;var Ke={};k(Ke,{identity:()=>qn});var Xt=0,Rn="identity",Qt=D;function jn(r){return X(Xt,Qt(r))}var qn={code:Xt,name:Rn,encode:Qt,digest:jn};var tt={};k(tt,{sha256:()=>Wn,sha512:()=>Gn});var et=de(L("crypto"),1);function Ye({name:r,code:e,encode:t}){return new Ze(r,e,t)}var Ze=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 Wn=Ye({name:"sha2-256",code:18,encode:r=>D(et.default.createHash("sha256").update(r).digest())}),Gn=Ye({name:"sha2-512",code:19,encode:r=>D(et.default.createHash("sha512").update(r).digest())});var he={...Qe,...We,...Xe,...je,...qe,...Be,...He,...Ve,...Je,...Ge},ti={...tt,...Ke};var Zt=L("node:buffer");function ie(r){return new Uint8Array(r.buffer,r.byteOffset,r.byteLength)}function Ee(r=0){return ie(Zt.Buffer.allocUnsafe(r))}function er(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var Yt=er("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),rt=er("ascii","a",r=>{let e="a";for(let t=0;t<r.length;t++)e+=String.fromCharCode(r[t]);return e},r=>{r=r.substring(1);let e=Ee(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),Hn={utf8:Yt,"utf-8":Yt,hex:he.base16,latin1:rt,ascii:rt,binary:rt,...he},Ae=Hn;function P(r,e="utf8"){let t=Ae[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return e==="utf8"||e==="utf-8"?tr.Buffer.from(r.buffer,r.byteOffset,r.byteLength).toString("utf8"):t.encoder.encode(r).substring(1)}var Jn=Math.pow(2,7),Xn=Math.pow(2,14),Qn=Math.pow(2,21),nt=Math.pow(2,28),ot=Math.pow(2,35),st=Math.pow(2,42),it=Math.pow(2,49),h=128,C=127;function V(r){if(r<Jn)return 1;if(r<Xn)return 2;if(r<Qn)return 3;if(r<nt)return 4;if(r<ot)return 5;if(r<st)return 6;if(r<it)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Kn(r,e,t=0){switch(V(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 Zn(r,e,t=0){switch(V(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 Yn(r,e){let t=r[e],n=0;if(n+=t&C,t<h||(t=r[e+1],n+=(t&C)<<7,t<h)||(t=r[e+2],n+=(t&C)<<14,t<h)||(t=r[e+3],n+=(t&C)<<21,t<h)||(t=r[e+4],n+=(t&C)*nt,t<h)||(t=r[e+5],n+=(t&C)*ot,t<h)||(t=r[e+6],n+=(t&C)*st,t<h)||(t=r[e+7],n+=(t&C)*it,t<h))return n;throw new RangeError("Could not decode varint")}function eo(r,e){let t=r.get(e),n=0;if(n+=t&C,t<h||(t=r.get(e+1),n+=(t&C)<<7,t<h)||(t=r.get(e+2),n+=(t&C)<<14,t<h)||(t=r.get(e+3),n+=(t&C)<<21,t<h)||(t=r.get(e+4),n+=(t&C)*nt,t<h)||(t=r.get(e+5),n+=(t&C)*ot,t<h)||(t=r.get(e+6),n+=(t&C)*st,t<h)||(t=r.get(e+7),n+=(t&C)*it,t<h))return n;throw new RangeError("Could not decode varint")}function ce(r,e,t=0){return e==null&&(e=Ee(V(r))),e instanceof Uint8Array?Kn(r,e,t):Zn(r,e,t)}function Q(r,e=0){return r instanceof Uint8Array?Yn(r,e):eo(r,e)}var nr=L("node:buffer");function j(r,e){return ie(nr.Buffer.concat(r,e))}var Ie=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",w=2**(8*o)-1;for(;;){let u=this.readAtomically(()=>{let E=this.readChar();if(E===void 0)return;let I=Number.parseInt(E,e);if(!Number.isNaN(I))return I});if(u===void 0)break;if(s*=e,s+=u,s>w||(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 gi=new Ie;var Ii=parseInt("0xFFFF",16),Ci=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);var ir=L("node:buffer");function ct(r,e="utf8"){let t=Ae[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return e==="utf8"||e==="utf-8"?ie(ir.Buffer.from(r,"utf-8")):t.decoder.decode(`${t.prefix}${r}`)}var M=L("node:net");function Ce(r){return!!(0,M.isIP)(r)}var cr=M.isIPv4,io=M.isIPv6,at=function(r){let e=0;if(r=r.toString().trim(),cr(r)){let t=new Uint8Array(e+4);return r.split(/\./g).forEach(n=>{t[e++]=parseInt(n,10)&255}),t}if(io(r)){let t=r.split(":",8),n;for(n=0;n<t.length;n++){let s=cr(t[n]),i;s&&(i=at(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")},ar=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 ae={},lt={},ao=[[4,32,"ip4"],[6,16,"tcp"],[33,16,"dccp"],[41,128,"ip6"],[42,-1,"ip6zone"],[43,8,"ipcidr"],[53,-1,"dns",!0],[54,-1,"dns4",!0],[55,-1,"dns6",!0],[56,-1,"dnsaddr",!0],[132,16,"sctp"],[273,16,"udp"],[275,0,"p2p-webrtc-star"],[276,0,"p2p-webrtc-direct"],[277,0,"p2p-stardust"],[280,0,"webrtc-direct"],[281,0,"webrtc"],[290,0,"p2p-circuit"],[301,0,"udt"],[302,0,"utp"],[400,-1,"unix",!1,!0],[421,-1,"ipfs"],[421,-1,"p2p"],[443,0,"https"],[444,96,"onion"],[445,296,"onion3"],[446,-1,"garlic64"],[448,0,"tls"],[449,-1,"sni"],[460,0,"quic"],[461,0,"quic-v1"],[465,0,"webtransport"],[466,-1,"certhash"],[477,0,"ws"],[478,0,"wss"],[479,0,"p2p-websocket-star"],[480,0,"http"],[481,-1,"http-path"],[777,-1,"memory"]];ao.forEach(r=>{let e=lo(...r);lt[e.code]=e,ae[e.name]=e});function lo(r,e,t,n,o){return{code:r,size:e,name:t,resolvable:!!n,path:!!o}}function m(r){if(typeof r=="number"){if(lt[r]!=null)return lt[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(ae[r]!=null)return ae[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var pc=m("ip4"),fc=m("ip6"),hc=m("ipcidr");function ft(r,e){switch(m(r).code){case 4:case 41:return po(e);case 42:return pt(e);case 6:case 273:case 33:case 132:return ur(e).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return pt(e);case 421:return go(e);case 444:return dr(e);case 445:return dr(e);case 466:return mo(e);case 481:return globalThis.encodeURIComponent(pt(e));default:return P(e,"base16")}}function ht(r,e){switch(m(r).code){case 4:return lr(e);case 41:return lr(e);case 42:return ut(e);case 6:case 273:case 33:case 132:return mt(parseInt(e,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return ut(e);case 421:return fo(e);case 444:return xo(e);case 445:return wo(e);case 466:return ho(e);case 481:return ut(globalThis.decodeURIComponent(e));default:return ct(e,"base16")}}var dt=Object.values(he).map(r=>r.decoder),uo=function(){let r=dt[0].or(dt[1]);return dt.slice(2).forEach(e=>r=r.or(e)),r}();function lr(r){if(!Ce(r))throw new Error("invalid ip address");return at(r)}function po(r){let e=ar(r,0,r.length);if(e==null)throw new Error("ipBuff is required");if(!Ce(e))throw new Error("invalid ip address");return e}function mt(r){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,r),new Uint8Array(e)}function ur(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function ut(r){let e=ct(r),t=Uint8Array.from(ce(e.length));return j([t,e],t.length+e.length)}function pt(r){let e=Q(r);if(r=r.slice(V(e)),r.length!==e)throw new Error("inconsistent lengths");return P(r)}function fo(r){let e;r[0]==="Q"||r[0]==="1"?e=ve(T.decode(`z${r}`)).bytes:e=G.parse(r).multihash.bytes;let t=Uint8Array.from(ce(e.length));return j([t,e],t.length+e.length)}function ho(r){let e=uo.decode(r),t=Uint8Array.from(ce(e.length));return j([t,e],t.length+e.length)}function mo(r){let e=Q(r),t=r.slice(V(e));if(t.length!==e)throw new Error("inconsistent lengths");return"u"+P(t,"base64url")}function go(r){let e=Q(r),t=r.slice(V(e));if(t.length!==e)throw new Error("inconsistent lengths");return P(t,"base58btc")}function xo(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=R.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=mt(n);return j([t,o],t.length+o.length)}function wo(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=R.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=mt(n);return j([t,o],t.length+o.length)}function dr(r){let e=r.slice(0,r.length-2),t=r.slice(r.length-2),n=P(e,"base32"),o=ur(t);return`${n}:${o}`}function pr(r){r=gt(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 hr("invalid address: "+r);if(a.path===!0){n=gt(o.slice(s).join("/")),e.push([a.code,ht(a.code,n)]),t.push([a.code,n]);break}let p=ht(a.code,o[s]);e.push([a.code,p]),t.push([a.code,ft(a.code,p)])}return{string:fr(t),bytes:wt(e),tuples:e,stringTuples:t,path:n}}function xt(r){let e=[],t=[],n=null,o=0;for(;o<r.length;){let s=Q(r,o),i=V(s),a=m(s),p=bo(a,r.slice(o+i));if(p===0){e.push([s]),t.push([s]),o+=i;continue}let w=r.slice(o+i,o+i+p);if(o+=p+i,o>r.length)throw hr("Invalid address Uint8Array: "+P(r,"base16"));e.push([s,w]);let u=ft(s,w);if(t.push([s,u]),a.path===!0){n=u;break}}return{bytes:Uint8Array.from(r),string:fr(t),tuples:e,stringTuples:t,path:n}}function fr(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}),gt(e.join("/"))}function wt(r){return j(r.map(e=>{let t=m(e[0]),n=Uint8Array.from(ce(t.code));return e.length>1&&e[1]!=null&&(n=j([n,e[1]])),n}))}function bo(r,e){if(r.size>0)return r.size/8;if(r.size===0)return 0;{let t=Q(e instanceof Uint8Array?e:Uint8Array.from(e));return t+V(t)}}function gt(r){return"/"+r.trim().split("/").filter(e=>e).join("/")}function hr(r){return new Error("Error parsing address: "+r)}var yo=Symbol.for("nodejs.util.inspect.custom"),yt=Symbol.for("@multiformats/js-multiaddr/multiaddr"),vo=[m("dns").code,m("dns4").code,m("dns6").code,m("dnsaddr").code],bt=class extends Error{constructor(e="No available resolver"){super(e),this.name="NoAvailableResolverError"}},Se=class r{bytes;#e;#t;#r;#n;[yt]=!0;constructor(e){e==null&&(e="");let t;if(e instanceof Uint8Array)t=xt(e);else if(typeof e=="string"){if(e.length>0&&e.charAt(0)!=="/")throw new Error(`multiaddr "${e}" must start with a "/"`);t=pr(e)}else if(gr(e))t=xt(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"),w=m("ip6"),u=m("dns6"),E=m("ip6zone");for(let[f,d]of this.stringTuples())f===E.code&&(s=`%${d??""}`),vo.includes(f)&&(t=i.name,o=443,n=`${d??""}${s}`,e=f===u.code?6:4),(f===i.code||f===a.code)&&(t=m(f).name,o=parseInt(d??"")),(f===p.code||f===w.code)&&(t=m(f).name,n=`${d??""}${s}`,e=f===w.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(wt(t.slice(0,n)));return this}getPeerId(){try{let e=[];this.stringTuples().forEach(([n,o])=>{n===ae.p2p.code&&e.push([n,o]),n===ae["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 Ht(this.bytes,e.bytes)}async resolve(e){let t=this.protos().find(s=>s.resolvable);if(t==null)return[this];let n=mr.get(t.name);if(n==null)throw new bt(`no available resolver for ${t.name}`);return(await n(this,e)).map(s=>F(s))}nodeAddress(){let e=this.toOptions();if(e.transport!=="tcp"&&e.transport!=="udp")throw new Error(`multiaddr must have a valid format - no protocol with name: "${e.transport}". Must have a valid transport protocol: "{tcp, udp}"`);return{family:e.family,address:e.host,port:e.port}}isThinWaistAddress(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)}[yo](){return`Multiaddr(${this.#e})`}};var mr=new Map;function gr(r){return!!r?.[yt]}function F(r){return new Se(r)}var Eo=c("dns4"),Ao=c("dns6"),Io=c("dnsaddr"),Z=y(c("dns"),Io,Eo,Ao),ke=y(c("ip4"),c("ip6")),J=y(l(ke,c("tcp")),l(Z,c("tcp"))),Ue=l(ke,c("udp")),Co=l(Ue,c("utp")),So=l(Ue,c("quic")),To=l(Ue,c("quic-v1")),vt=y(l(J,c("ws")),l(Z,c("ws"))),Te=y(l(vt,c("p2p")),vt),Et=y(l(J,c("wss")),l(Z,c("wss")),l(J,c("tls"),c("ws")),l(Z,c("tls"),c("ws"))),Pe=y(l(Et,c("p2p")),Et),At=y(l(J,c("http")),l(ke,c("http")),l(Z,c("http"))),It=y(l(J,c("https")),l(ke,c("https")),l(Z,c("https"))),xr=l(Ue,c("webrtc-direct"),c("certhash")),yr=y(l(xr,c("p2p")),xr),wr=l(To,c("webtransport"),c("certhash"),c("certhash")),vr=y(l(wr,c("p2p")),wr),Er=y(l(Te,c("p2p-webrtc-star"),c("p2p")),l(Pe,c("p2p-webrtc-star"),c("p2p")),l(Te,c("p2p-webrtc-star")),l(Pe,c("p2p-webrtc-star"))),Vc=y(l(Te,c("p2p-websocket-star"),c("p2p")),l(Pe,c("p2p-websocket-star"),c("p2p")),l(Te,c("p2p-websocket-star")),l(Pe,c("p2p-websocket-star"))),Ar=y(l(At,c("p2p-webrtc-direct"),c("p2p")),l(It,c("p2p-webrtc-direct"),c("p2p")),l(At,c("p2p-webrtc-direct")),l(It,c("p2p-webrtc-direct"))),Y=y(vt,Et,At,It,Er,Ar,J,Co,So,Z,yr,vr),Bc=y(l(Y,c("p2p-stardust"),c("p2p")),l(Y,c("p2p-stardust"))),H=y(l(Y,c("p2p")),Er,Ar,yr,vr,c("p2p")),br=y(l(H,c("p2p-circuit"),H),l(H,c("p2p-circuit")),l(c("p2p-circuit"),H),l(Y,c("p2p-circuit")),l(c("p2p-circuit"),Y),c("p2p-circuit")),Ir=()=>y(l(br,Ir),br),K=Ir(),_c=y(l(K,H,K),l(H,K),l(K,H),K,H);var Rc=y(l(K,c("webrtc"),c("p2p")),l(K,c("webrtc")),l(Y,c("webrtc"),c("p2p")),l(Y,c("webrtc")),c("webrtc"));function Cr(r){function e(t){let n;try{n=F(t)}catch{return!1}let o=r(n.protoNames());return o===null?!1:o===!0||o===!1?o:o.length===0}return e}function l(...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:Cr(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:Cr(e),partialMatch:e}}function c(r){let e=r;function t(o){let s;try{s=F(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 De=class extends Event{type;detail;constructor(e,t){super(e),this.type=e,this.detail=t}};var Dr=de(L("net"),1);function Sr(r,e){if(typeof r!="string")throw new z(`invalid ip provided: ${r}`);if(typeof e=="string"&&(e=parseInt(e)),isNaN(e))throw new z(`invalid port provided: ${e}`);if((0,M.isIPv4)(r))return F(`/ip4/${r}/tcp/${e}`);if((0,M.isIPv6)(r))return F(`/ip6/${r}/tcp/${e}`);throw new z(`invalid ip:port for creating a multiaddr: ${r}:${e}`)}function Tr(r){if(Uo(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(ko(r))return r;throw new Error("unknown stream")}function ko(r){return r[Symbol.asyncIterator]!=null}function Uo(r){return typeof r?.getReader=="function"}function Pr(r){return async e=>{let t=async()=>{Do(e)&&await e.return(void 0)},n,o,s=x=>{n=x,t().catch(v=>{v=new AggregateError([n,v],"The Writable emitted an error, additionally an error occurred while ending the Source")}).finally(()=>{o?.(x)})},i,a=!1,p=()=>{a=!0,i?.()},w,u=!1,E=()=>{u=!0,w?.()},I,f=()=>{I?.()},d=async()=>new Promise((x,v)=>{i=I=x,o=v,r.once("drain",f)}),g=async()=>(await t(),new Promise((x,v)=>{if(a||u||n!=null){x();return}w=i=x,o=v})),S=()=>{r.removeListener("error",s),r.removeListener("close",p),r.removeListener("finish",E),r.removeListener("drain",f)};r.once("error",s),r.once("close",p),r.once("finish",E);try{for await(let x of e){if(!r.writable||r.destroyed||n!=null)break;r.write(x)||await d()}}catch(x){n==null&&r.destroy(x),n=x}try{if(r.writable&&r.end(),await g(),n!=null)throw n}finally{S()}}}function Do(r){return r.return!=null}function Ct(r){return{sink:Pr(r),source:Tr(r)}}var St=de(L("os"),1),kr=de(L("path"),1);var Mo={ip4:"IPv4",ip6:"IPv6"};function le(r,e={}){let t=r.getPath();return t!=null?St.default.platform()==="win32"?{path:kr.default.join("\\\\.\\pipe\\",t)}:{path:t}:{...e,...r.toOptions()}}function Tt(r,e,t){let n=o=>F(`/${r}/${o}/tcp/${t}`);return(No(e)?Fo(Mo[r]):[e]).map(n)}function No(r){return["0.0.0.0","::"].includes(r)}var Lo=St.default.networkInterfaces();function Fo(r){let e=[];for(let[,t]of Object.entries(Lo))if(t!=null)for(let n of t)n.family===r&&e.push(n.address);return e}var Me=(r,e)=>{let t=null,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 z("Could not determine remote address or port");p=Sr(r.remoteAddress,r.remotePort)}let w=le(p),u=w.path??`${w.host??""}:${w.port??""}`,{sink:E,source:I}=Ct(r);r.setTimeout(i,()=>{n("%s socket read timeout",u),o?.increment({[`${s}timeout`]:!0});let d;r.readable&&(d=new ee("Socket read timeout")),r.destroy(d)}),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(d){try{await E(async function*(){for await(let g of d)g instanceof Uint8Array?yield g:yield g.subarray()}())}catch(g){g.type!=="aborted"&&n.error("%s error in sink",u,g)}r.end()},source:I,remoteAddr:p,timeline:{open:Date.now()},async close(d={}){if(r.destroyed){n("The %s socket is destroyed",u);return}if(t!=null)return n("The %s socket is closed or closing",u),t;if(d.signal==null){let S=AbortSignal.timeout(a);d={...d,signal:S}}let g=()=>{r.destroy(new _("Destroying socket after timeout"))};d.signal?.addEventListener("abort",g);try{n("%s closing socket",u),t=new Promise((S,x)=>{r.once("close",()=>{n("%s socket closed",u),S()}),r.once("error",v=>{n("%s socket error",u,v),f.timeline.close==null&&(f.timeline.close=Date.now()),r.destroyed||x(v)}),r.setTimeout(a),r.end(),r.writableLength>0?r.once("drain",()=>{n("%s socket drained",u),r.destroy()}):r.destroy()}),await t}catch(S){this.abort(S)}finally{d.signal?.removeEventListener("abort",g)}},abort:d=>{n("%s socket abort due to error",u,d),r.destroyed||r.destroy(d),f.timeline.close==null&&(f.timeline.close=Date.now())},log:n};return f};async function Ur(r,e){try{await r.close()}catch(t){e.log.error("an error occurred closing the connection",t),r.abort(t)}}var A;(function(r){r[r.INACTIVE=0]="INACTIVE",r[r.ACTIVE=1]="ACTIVE",r[r.PAUSED=2]="PAUSED"})(A||(A={}));var Ne=class extends be{context;server;connections=new Set;status={code:A.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=Dr.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 z("closeAbove must be >= listenBelow");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]:A.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!==A.PAUSED&&this.safeDispatchEvent("close")})}onSocket(e){if(this.status.code!==A.ACTIVE)throw new xe("Server is not listening yet");e.on("error",n=>{this.log("socket error",n),this.metrics?.events.increment({[`${this.addr} error`]:!0})});let t;try{t=Me(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 Ur(t,{log:this.log})}).catch(n=>{this.log.error("closing inbound connection failed",n)})}catch(n){this.log.error("inbound connection failed",n),Ur(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===A.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(Tt("ip4",t.address,t.port)):t.family==="IPv6"&&(e=e.concat(Tt("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===A.ACTIVE||this.status.code===A.PAUSED)throw new we("server is already listening");let t=e.getPeerId(),n=t==null?e.decapsulateCode(421):e,{backlog:o}=this.context;try{this.status={code:A.ACTIVE,listeningAddr:n,peerId:t,netConfig:le(n,{backlog:o})},await this.resume()}catch(s){throw this.status={code:A.INACTIVE},s}}async close(){let e=new _("Listener is closing");this.connections.forEach(t=>{t.abort(e)}),await this.pause(!0)}async resume(){if(this.server.listening||this.status.code===A.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:A.ACTIVE},this.log("listening on %s",this.server.address())}async pause(e){if(!this.server.listening&&this.status.code===A.PAUSED&&e){this.status={code:A.INACTIVE};return}!this.server.listening||this.status.code!==A.ACTIVE||(this.log("closing server on %s",this.server.address()),this.status=e?{code:A.INACTIVE}:{...this.status,code:A.PAUSED},await new Promise((t,n)=>{this.server.close(o=>{if(o!=null){n(o);return}t()})}))}};var Le=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"})})}[Ut]=!0;[Symbol.toStringTag]="@libp2p/tcp";[Nt]=["@libp2p/transport"];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=Me(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 _;return i}async _connect(e,t){return t.signal?.throwIfAborted(),t.onProgress?.(new De("tcp:open-connection")),new Promise((n,o)=>{let s=Date.now(),i=le(e,{...this.opts.dialOpts??{},...t});this.log("dialing %a",e);let a=Mr.default.connect(i),p=f=>{let d=i.path??`${i.host??""}:${i.port}`;f.message=`connection error ${d}: ${f.message}`,this.metrics?.dialerEvents.increment({error:!0}),I(f)},w=()=>{this.log("connection timeout %a",e),this.metrics?.dialerEvents.increment({timeout:!0});let f=new ee(`connection timeout after ${Date.now()-s}ms`);a.emit("error",f)},u=()=>{this.log("connection opened %a",e),this.metrics?.dialerEvents.increment({connect:!0}),I()},E=()=>{this.log("connection aborted %a",e),this.metrics?.dialerEvents.increment({abort:!0}),a.destroy(),I(new _)},I=f=>{if(a.removeListener("error",p),a.removeListener("timeout",w),a.removeListener("connect",u),t.signal!=null&&t.signal.removeEventListener("abort",E),f!=null){o(f);return}n(a)};a.on("error",p),a.on("timeout",w),a.on("connect",u),t.signal!=null&&t.signal.addEventListener("abort",E)})}createListener(e){return new Ne({...this.opts.listenOpts??{},...e,maxConnections:this.opts.maxConnections,backlog:this.opts.backlog,closeServerOnMaxConnections:this.opts.closeServerOnMaxConnections,socketInactivityTimeout:this.opts.inboundSocketInactivityTimeout,socketCloseTimeout:this.opts.socketCloseTimeout,metrics:this.components.metrics,logger:this.components.logger})}listenFilter(e){return e=Array.isArray(e)?e:[e],e.filter(t=>t.protoCodes().includes(290)?!1:t.protoCodes().includes(400)?!0:J.matches(t.decapsulateCode(421)))}dialFilter(e){return this.listenFilter(e)}};function Oo(r={}){return e=>new Le(e,r)}return zr(zo);})();
|
|
2
|
+
"use strict";var Libp2PTcp=(()=>{var Lr=Object.create;var xe=Object.defineProperty;var Fr=Object.getOwnPropertyDescriptor;var $r=Object.getOwnPropertyNames;var Or=Object.getPrototypeOf,zr=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 k=(r,e)=>{for(var t in e)xe(r,t,{get:e[t],enumerable:!0})},kt=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of $r(e))!zr.call(r,o)&&o!==t&&xe(r,o,{get:()=>e[o],enumerable:!(n=Fr(e,o))||n.enumerable});return r};var de=(r,e,t)=>(t=r!=null?Lr(Or(r)):{},kt(e||!r||!r.__esModule?xe(t,"default",{value:r,enumerable:!0}):t,r)),Vr=r=>kt(xe({},"__esModule",{value:!0}),r);var zo={};k(zo,{tcp:()=>Oo});var Nr=de(L("net"),1);var Dt=Symbol.for("@libp2p/transport");var Ut;(function(r){r[r.FATAL_ALL=0]="FATAL_ALL",r[r.NO_FATAL=1]="NO_FATAL"})(Ut||(Ut={}));var _=class extends Error{static name="AbortError";constructor(e="The operation was aborted"){super(e),this.name="AbortError"}};var z=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}};var ee=class extends Error{static name="TimeoutError";constructor(e="Timed out"){super(e),this.name="TimeoutError"}},we=class extends Error{static name="NotStartedError";constructor(e="Not started"){super(e),this.name="NotStartedError"}},be=class extends Error{static name="AlreadyStartedError";constructor(e="Already started"){super(e),this.name="AlreadyStartedError"}};var Mt=L("events"),Nt=(r,...e)=>{try{(0,Mt.setMaxListeners)(r,...e)}catch{}};var ye=class extends EventTarget{#e=new Map;constructor(){super(),Nt(1/0,this)}listenerCount(e){let t=this.#e.get(e);return t==null?0:t.length}addEventListener(e,t,n){super.addEventListener(e,t,n);let o=this.#e.get(e);o==null&&(o=[],this.#e.set(e,o)),o.push({callback:t,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(e,t,n){super.removeEventListener(e.toString(),t??null,n);let o=this.#e.get(e);o!=null&&(o=o.filter(({callback:s})=>s!==t),this.#e.set(e,o))}dispatchEvent(e){let t=super.dispatchEvent(e),n=this.#e.get(e.type);return n==null||(n=n.filter(({once:o})=>!o),this.#e.set(e.type,n)),t}safeDispatchEvent(e,t={}){return this.dispatchEvent(new CustomEvent(e,t))}};var Lt=Symbol.for("@libp2p/service-capabilities"),Wo=Symbol.for("@libp2p/service-dependencies");var Be={};k(Be,{base58btc:()=>T,base58flickr:()=>Wr});var ms=new Uint8Array(0);function Ft(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 $t(r){return new TextEncoder().encode(r)}function Ot(r){return new TextDecoder().decode(r)}function Br(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),w=Math.log(a)/Math.log(256),u=Math.log(256)/Math.log(a);function E(d){if(d instanceof Uint8Array||(ArrayBuffer.isView(d)?d=new Uint8Array(d.buffer,d.byteOffset,d.byteLength):Array.isArray(d)&&(d=Uint8Array.from(d))),!(d instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(d.length===0)return"";for(var g=0,S=0,x=0,v=d.length;x!==v&&d[x]===0;)x++,g++;for(var $=(v-x)*u+1>>>0,U=new Uint8Array($);x!==v;){for(var O=d[x],q=0,N=$-1;(O!==0||q<S)&&N!==-1;N--,q++)O+=256*U[N]>>>0,U[N]=O%a>>>0,O=O/a>>>0;if(O!==0)throw new Error("Non-zero carry");S=q,x++}for(var B=$-S;B!==$&&U[B]===0;)B++;for(var ge=p.repeat(g);B<$;++B)ge+=r.charAt(U[B]);return ge}function I(d){if(typeof d!="string")throw new TypeError("Expected String");if(d.length===0)return new Uint8Array;var g=0;if(d[g]!==" "){for(var S=0,x=0;d[g]===p;)S++,g++;for(var v=(d.length-g)*w+1>>>0,$=new Uint8Array(v);d[g];){var U=t[d.charCodeAt(g)];if(U===255)return;for(var O=0,q=v-1;(U!==0||O<x)&&q!==-1;q--,O++)U+=a*$[q]>>>0,$[q]=U%256>>>0,U=U/256>>>0;if(U!==0)throw new Error("Non-zero carry");x=O,g++}if(d[g]!==" "){for(var N=v-x;N!==v&&$[N]===0;)N++;for(var B=new Uint8Array(S+(v-N)),ge=S;N!==v;)B[ge++]=$[N++];return B}}}function f(d){var g=I(d);if(g)return g;throw new Error(`Non-${e} character`)}return{encode:E,decodeUnsafe:I,decode:f}}var _r=Br,Rr=_r,Vt=Rr;var $e=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")}},Oe=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,t,n){this.name=e,this.prefix=t;let o=t.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return Bt(this,e)}},ze=class{decoders;constructor(e){this.decoders=e}or(e){return Bt(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 Bt(r,e){return new ze({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var Ve=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 $e(e,t,n),this.decoder=new Oe(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function te({name:r,prefix:e,encode:t,decode:n}){return new Ve(r,e,t,n)}function W({name:r,prefix:e,alphabet:t}){let{encode:n,decode:o}=Vt(t,r);return te({prefix:e,name:r,encode:n,decode:s=>D(o(s))})}function jr(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,w=0;for(let u=0;u<s;++u){let E=o[r[u]];if(E===void 0)throw new SyntaxError(`Non-${n} character`);p=p<<t|E,a+=t,a>=8&&(a-=8,i[w++]=255&p>>a)}if(a>=t||255&p<<8-a)throw new SyntaxError("Unexpected end of data");return i}function qr(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 te({prefix:e,name:r,encode(o){return qr(o,n,t)},decode(o){return jr(o,n,t,r)}})}var T=W({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Wr=W({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var _e={};k(_e,{base32:()=>R,base32hex:()=>Xr,base32hexpad:()=>Kr,base32hexpadupper:()=>Zr,base32hexupper:()=>Qr,base32pad:()=>Hr,base32padupper:()=>Jr,base32upper:()=>Gr,base32z:()=>Yr});var R=b({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Gr=b({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Hr=b({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Jr=b({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Xr=b({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Qr=b({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Kr=b({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Zr=b({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Yr=b({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Re={};k(Re,{base36:()=>ue,base36upper:()=>en});var ue=W({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),en=W({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var tn=jt,_t=128,rn=127,nn=~rn,on=Math.pow(2,31);function jt(r,e,t){e=e||[],t=t||0;for(var n=t;r>=on;)e[t++]=r&255|_t,r/=128;for(;r&nn;)e[t++]=r&255|_t,r>>>=7;return e[t]=r|0,jt.bytes=t-n+1,e}var sn=je,cn=128,Rt=127;function je(r,n){var t=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw je.bytes=0,new RangeError("Could not decode varint");i=r[s++],t+=o<28?(i&Rt)<<o:(i&Rt)*Math.pow(2,o),o+=7}while(i>=cn);return je.bytes=s-n,t}var an=Math.pow(2,7),ln=Math.pow(2,14),dn=Math.pow(2,21),un=Math.pow(2,28),pn=Math.pow(2,35),fn=Math.pow(2,42),hn=Math.pow(2,49),mn=Math.pow(2,56),gn=Math.pow(2,63),xn=function(r){return r<an?1:r<ln?2:r<dn?3:r<un?4:r<pn?5:r<fn?6:r<hn?7:r<mn?8:r<gn?9:10},wn={encode:tn,decode:sn,encodingLength:xn},bn=wn,pe=bn;function fe(r,e=0){return[pe.decode(r,e),pe.decode.bytes]}function re(r,e,t=0){return pe.encode(r,e,t),e}function ne(r){return pe.encodingLength(r)}function X(r,e){let t=e.byteLength,n=ne(r),o=n+ne(t),s=new Uint8Array(o+t);return re(r,s,0),re(t,s,n),s.set(e,o),new oe(r,t,e,s)}function Ee(r){let e=D(r),[t,n]=fe(e),[o,s]=fe(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new oe(t,o,i,e)}function qt(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&Ft(r.bytes,t.bytes)}}var oe=class{code;size;digest;bytes;constructor(e,t,n,o){this.code=e,this.size=t,this.digest=n,this.bytes=o}};function Wt(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return vn(t,qe(r),e??T.encoder);default:return En(t,qe(r),e??R.encoder)}}var Gt=new WeakMap;function qe(r){let e=Gt.get(r);if(e==null){let t=new Map;return Gt.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!==he)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==An)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&&qt(e.multihash,n.multihash)}toString(e){return Wt(this,e)}toJSON(){return{"/":Wt(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??Ht(n,o,s.bytes))}else if(t[In]===!0){let{version:n,multihash:o,code:s}=t,i=Ee(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!==he)throw new Error(`Version 0 CID must use dag-pb (code: ${he}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let o=Ht(e,t,n.bytes);return new r(e,t,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,he,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 oe(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[E,I]=fe(e.subarray(t));return t+=I,E},o=n(),s=he;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(),w=t+p,u=w-i;return{version:o,codec:s,multihashCode:a,digestSize:p,multihashSize:u,size:w}}static parse(e,t){let[n,o]=yn(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 qe(s).set(n,e),s}};function yn(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 R.prefix:{let t=e??R;return[R.prefix,t.decode(r)]}case ue.prefix:{let t=e??ue;return[ue.prefix,t.decode(r)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],e.decode(r)]}}}function vn(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 En(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 he=112,An=18;function Ht(r,e,t){let n=ne(r),o=n+ne(e),s=new Uint8Array(o+t.byteLength);return re(r,s,0),re(e,s,n),s.set(t,o),s}var In=Symbol.for("@ipld/js-cid/CID");function Jt(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 rr=L("node:buffer");var We={};k(We,{base10:()=>Cn});var Cn=W({prefix:"9",name:"base10",alphabet:"0123456789"});var Ge={};k(Ge,{base16:()=>Sn,base16upper:()=>Tn});var Sn=b({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Tn=b({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var He={};k(He,{base2:()=>Pn});var Pn=b({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Je={};k(Je,{base256emoji:()=>Nn});var Xt=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}"),kn=Xt.reduce((r,e,t)=>(r[t]=e,r),[]),Un=Xt.reduce((r,e,t)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return r[n]=t,r},[]);function Dn(r){return r.reduce((e,t)=>(e+=kn[t],e),"")}function Mn(r){let e=[];for(let t of r){let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);let o=Un[n];if(o==null)throw new Error(`Non-base256emoji character: ${t}`);e.push(o)}return new Uint8Array(e)}var Nn=te({prefix:"\u{1F680}",name:"base256emoji",encode:Dn,decode:Mn});var Xe={};k(Xe,{base64:()=>Ln,base64pad:()=>Fn,base64url:()=>$n,base64urlpad:()=>On});var Ln=b({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Fn=b({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),$n=b({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),On=b({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Qe={};k(Qe,{base8:()=>zn});var zn=b({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Ke={};k(Ke,{identity:()=>Vn});var Vn=te({prefix:"\0",name:"identity",encode:r=>Ot(r),decode:r=>$t(r)});var _s=new TextEncoder,Rs=new TextDecoder;var Ze={};k(Ze,{identity:()=>qn});var Qt=0,Rn="identity",Kt=D;function jn(r){return X(Qt,Kt(r))}var qn={code:Qt,name:Rn,encode:Kt,digest:jn};var rt={};k(rt,{sha256:()=>Wn,sha512:()=>Gn});var tt=de(L("crypto"),1);function et({name:r,code:e,encode:t}){return new Ye(r,e,t)}var Ye=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 Wn=et({name:"sha2-256",code:18,encode:r=>D(tt.default.createHash("sha256").update(r).digest())}),Gn=et({name:"sha2-512",code:19,encode:r=>D(tt.default.createHash("sha512").update(r).digest())});var me={...Ke,...He,...Qe,...We,...Ge,..._e,...Re,...Be,...Xe,...Je},ri={...rt,...Ze};var Yt=L("node:buffer");function ie(r){return new Uint8Array(r.buffer,r.byteOffset,r.byteLength)}function Ae(r=0){return ie(Yt.Buffer.allocUnsafe(r))}function tr(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var er=tr("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),nt=tr("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=Ae(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),Hn={utf8:er,"utf-8":er,hex:me.base16,latin1:nt,ascii:nt,binary:nt,...me},Ie=Hn;function P(r,e="utf8"){let t=Ie[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return e==="utf8"||e==="utf-8"?rr.Buffer.from(r.buffer,r.byteOffset,r.byteLength).toString("utf8"):t.encoder.encode(r).substring(1)}var Jn=Math.pow(2,7),Xn=Math.pow(2,14),Qn=Math.pow(2,21),ot=Math.pow(2,28),st=Math.pow(2,35),it=Math.pow(2,42),ct=Math.pow(2,49),h=128,C=127;function V(r){if(r<Jn)return 1;if(r<Xn)return 2;if(r<Qn)return 3;if(r<ot)return 4;if(r<st)return 5;if(r<it)return 6;if(r<ct)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Kn(r,e,t=0){switch(V(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 Zn(r,e,t=0){switch(V(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 Yn(r,e){let t=r[e],n=0;if(n+=t&C,t<h||(t=r[e+1],n+=(t&C)<<7,t<h)||(t=r[e+2],n+=(t&C)<<14,t<h)||(t=r[e+3],n+=(t&C)<<21,t<h)||(t=r[e+4],n+=(t&C)*ot,t<h)||(t=r[e+5],n+=(t&C)*st,t<h)||(t=r[e+6],n+=(t&C)*it,t<h)||(t=r[e+7],n+=(t&C)*ct,t<h))return n;throw new RangeError("Could not decode varint")}function eo(r,e){let t=r.get(e),n=0;if(n+=t&C,t<h||(t=r.get(e+1),n+=(t&C)<<7,t<h)||(t=r.get(e+2),n+=(t&C)<<14,t<h)||(t=r.get(e+3),n+=(t&C)<<21,t<h)||(t=r.get(e+4),n+=(t&C)*ot,t<h)||(t=r.get(e+5),n+=(t&C)*st,t<h)||(t=r.get(e+6),n+=(t&C)*it,t<h)||(t=r.get(e+7),n+=(t&C)*ct,t<h))return n;throw new RangeError("Could not decode varint")}function ce(r,e,t=0){return e==null&&(e=Ae(V(r))),e instanceof Uint8Array?Kn(r,e,t):Zn(r,e,t)}function Q(r,e=0){return r instanceof Uint8Array?Yn(r,e):eo(r,e)}var or=L("node:buffer");function j(r,e){return ie(or.Buffer.concat(r,e))}var Ce=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",w=2**(8*o)-1;for(;;){let u=this.readAtomically(()=>{let E=this.readChar();if(E===void 0)return;let I=Number.parseInt(E,e);if(!Number.isNaN(I))return I});if(u===void 0)break;if(s*=e,s+=u,s>w||(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 xi=new Ce;var Ci=parseInt("0xFFFF",16),Si=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);var cr=L("node:buffer");function at(r,e="utf8"){let t=Ie[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return e==="utf8"||e==="utf-8"?ie(cr.Buffer.from(r,"utf-8")):t.decoder.decode(`${t.prefix}${r}`)}var M=L("node:net");function Se(r){return!!(0,M.isIP)(r)}var ar=M.isIPv4,io=M.isIPv6,lt=function(r){let e=0;if(r=r.toString().trim(),ar(r)){let t=new Uint8Array(e+4);return r.split(/\./g).forEach(n=>{t[e++]=parseInt(n,10)&255}),t}if(io(r)){let t=r.split(":",8),n;for(n=0;n<t.length;n++){let s=ar(t[n]),i;s&&(i=lt(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")},lr=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 ae={},dt={},ao=[[4,32,"ip4"],[6,16,"tcp"],[33,16,"dccp"],[41,128,"ip6"],[42,-1,"ip6zone"],[43,8,"ipcidr"],[53,-1,"dns",!0],[54,-1,"dns4",!0],[55,-1,"dns6",!0],[56,-1,"dnsaddr",!0],[132,16,"sctp"],[273,16,"udp"],[275,0,"p2p-webrtc-star"],[276,0,"p2p-webrtc-direct"],[277,0,"p2p-stardust"],[280,0,"webrtc-direct"],[281,0,"webrtc"],[290,0,"p2p-circuit"],[301,0,"udt"],[302,0,"utp"],[400,-1,"unix",!1,!0],[421,-1,"ipfs"],[421,-1,"p2p"],[443,0,"https"],[444,96,"onion"],[445,296,"onion3"],[446,-1,"garlic64"],[448,0,"tls"],[449,-1,"sni"],[460,0,"quic"],[461,0,"quic-v1"],[465,0,"webtransport"],[466,-1,"certhash"],[477,0,"ws"],[478,0,"wss"],[479,0,"p2p-websocket-star"],[480,0,"http"],[481,-1,"http-path"],[777,-1,"memory"]];ao.forEach(r=>{let e=lo(...r);dt[e.code]=e,ae[e.name]=e});function lo(r,e,t,n,o){return{code:r,size:e,name:t,resolvable:!!n,path:!!o}}function m(r){if(typeof r=="number"){if(dt[r]!=null)return dt[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(ae[r]!=null)return ae[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var fc=m("ip4"),hc=m("ip6"),mc=m("ipcidr");function ht(r,e){switch(m(r).code){case 4:case 41:return po(e);case 42:return ft(e);case 6:case 273:case 33:case 132:return pr(e).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return ft(e);case 421:return go(e);case 444:return ur(e);case 445:return ur(e);case 466:return mo(e);case 481:return globalThis.encodeURIComponent(ft(e));default:return P(e,"base16")}}function mt(r,e){switch(m(r).code){case 4:return dr(e);case 41:return dr(e);case 42:return pt(e);case 6:case 273:case 33:case 132:return gt(parseInt(e,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return pt(e);case 421:return fo(e);case 444:return xo(e);case 445:return wo(e);case 466:return ho(e);case 481:return pt(globalThis.decodeURIComponent(e));default:return at(e,"base16")}}var ut=Object.values(me).map(r=>r.decoder),uo=function(){let r=ut[0].or(ut[1]);return ut.slice(2).forEach(e=>r=r.or(e)),r}();function dr(r){if(!Se(r))throw new Error("invalid ip address");return lt(r)}function po(r){let e=lr(r,0,r.length);if(e==null)throw new Error("ipBuff is required");if(!Se(e))throw new Error("invalid ip address");return e}function gt(r){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,r),new Uint8Array(e)}function pr(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function pt(r){let e=at(r),t=Uint8Array.from(ce(e.length));return j([t,e],t.length+e.length)}function ft(r){let e=Q(r);if(r=r.slice(V(e)),r.length!==e)throw new Error("inconsistent lengths");return P(r)}function fo(r){let e;r[0]==="Q"||r[0]==="1"?e=Ee(T.decode(`z${r}`)).bytes:e=G.parse(r).multihash.bytes;let t=Uint8Array.from(ce(e.length));return j([t,e],t.length+e.length)}function ho(r){let e=uo.decode(r),t=Uint8Array.from(ce(e.length));return j([t,e],t.length+e.length)}function mo(r){let e=Q(r),t=r.slice(V(e));if(t.length!==e)throw new Error("inconsistent lengths");return"u"+P(t,"base64url")}function go(r){let e=Q(r),t=r.slice(V(e));if(t.length!==e)throw new Error("inconsistent lengths");return P(t,"base58btc")}function xo(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=R.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=gt(n);return j([t,o],t.length+o.length)}function wo(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=R.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=gt(n);return j([t,o],t.length+o.length)}function ur(r){let e=r.slice(0,r.length-2),t=r.slice(r.length-2),n=P(e,"base32"),o=pr(t);return`${n}:${o}`}function fr(r){r=xt(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 mr("invalid address: "+r);if(a.path===!0){n=xt(o.slice(s).join("/")),e.push([a.code,mt(a.code,n)]),t.push([a.code,n]);break}let p=mt(a.code,o[s]);e.push([a.code,p]),t.push([a.code,ht(a.code,p)])}return{string:hr(t),bytes:bt(e),tuples:e,stringTuples:t,path:n}}function wt(r){let e=[],t=[],n=null,o=0;for(;o<r.length;){let s=Q(r,o),i=V(s),a=m(s),p=bo(a,r.slice(o+i));if(p===0){e.push([s]),t.push([s]),o+=i;continue}let w=r.slice(o+i,o+i+p);if(o+=p+i,o>r.length)throw mr("Invalid address Uint8Array: "+P(r,"base16"));e.push([s,w]);let u=ht(s,w);if(t.push([s,u]),a.path===!0){n=u;break}}return{bytes:Uint8Array.from(r),string:hr(t),tuples:e,stringTuples:t,path:n}}function hr(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}),xt(e.join("/"))}function bt(r){return j(r.map(e=>{let t=m(e[0]),n=Uint8Array.from(ce(t.code));return e.length>1&&e[1]!=null&&(n=j([n,e[1]])),n}))}function bo(r,e){if(r.size>0)return r.size/8;if(r.size===0)return 0;{let t=Q(e instanceof Uint8Array?e:Uint8Array.from(e));return t+V(t)}}function xt(r){return"/"+r.trim().split("/").filter(e=>e).join("/")}function mr(r){return new Error("Error parsing address: "+r)}var yo=Symbol.for("nodejs.util.inspect.custom"),vt=Symbol.for("@multiformats/js-multiaddr/multiaddr"),vo=[m("dns").code,m("dns4").code,m("dns6").code,m("dnsaddr").code],yt=class extends Error{constructor(e="No available resolver"){super(e),this.name="NoAvailableResolverError"}},Te=class r{bytes;#e;#t;#r;#n;[vt]=!0;constructor(e){e==null&&(e="");let t;if(e instanceof Uint8Array)t=wt(e);else if(typeof e=="string"){if(e.length>0&&e.charAt(0)!=="/")throw new Error(`multiaddr "${e}" must start with a "/"`);t=fr(e)}else if(xr(e))t=wt(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"),w=m("ip6"),u=m("dns6"),E=m("ip6zone");for(let[f,d]of this.stringTuples())f===E.code&&(s=`%${d??""}`),vo.includes(f)&&(t=i.name,o=443,n=`${d??""}${s}`,e=f===u.code?6:4),(f===i.code||f===a.code)&&(t=m(f).name,o=parseInt(d??"")),(f===p.code||f===w.code)&&(t=m(f).name,n=`${d??""}${s}`,e=f===w.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(bt(t.slice(0,n)));return this}getPeerId(){try{let e=[];this.stringTuples().forEach(([n,o])=>{n===ae.p2p.code&&e.push([n,o]),n===ae["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 Jt(this.bytes,e.bytes)}async resolve(e){let t=this.protos().find(s=>s.resolvable);if(t==null)return[this];let n=gr.get(t.name);if(n==null)throw new yt(`no available resolver for ${t.name}`);return(await n(this,e)).map(s=>F(s))}nodeAddress(){let e=this.toOptions();if(e.transport!=="tcp"&&e.transport!=="udp")throw new Error(`multiaddr must have a valid format - no protocol with name: "${e.transport}". Must have a valid transport protocol: "{tcp, udp}"`);return{family:e.family,address:e.host,port:e.port}}isThinWaistAddress(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)}[yo](){return`Multiaddr(${this.#e})`}};var gr=new Map;function xr(r){return!!r?.[vt]}function F(r){return new Te(r)}var Eo=c("dns4"),Ao=c("dns6"),Io=c("dnsaddr"),Z=y(c("dns"),Io,Eo,Ao),Ue=y(c("ip4"),c("ip6")),J=y(l(Ue,c("tcp")),l(Z,c("tcp"))),De=l(Ue,c("udp")),Co=l(De,c("utp")),So=l(De,c("quic")),To=l(De,c("quic-v1")),Et=y(l(J,c("ws")),l(Z,c("ws"))),Pe=y(l(Et,c("p2p")),Et),At=y(l(J,c("wss")),l(Z,c("wss")),l(J,c("tls"),c("ws")),l(Z,c("tls"),c("ws"))),ke=y(l(At,c("p2p")),At),It=y(l(J,c("http")),l(Ue,c("http")),l(Z,c("http"))),Ct=y(l(J,c("https")),l(Ue,c("https")),l(Z,c("https"))),wr=l(De,c("webrtc-direct"),c("certhash")),vr=y(l(wr,c("p2p")),wr),br=l(To,c("webtransport"),c("certhash"),c("certhash")),Er=y(l(br,c("p2p")),br),Ar=y(l(Pe,c("p2p-webrtc-star"),c("p2p")),l(ke,c("p2p-webrtc-star"),c("p2p")),l(Pe,c("p2p-webrtc-star")),l(ke,c("p2p-webrtc-star"))),Bc=y(l(Pe,c("p2p-websocket-star"),c("p2p")),l(ke,c("p2p-websocket-star"),c("p2p")),l(Pe,c("p2p-websocket-star")),l(ke,c("p2p-websocket-star"))),Ir=y(l(It,c("p2p-webrtc-direct"),c("p2p")),l(Ct,c("p2p-webrtc-direct"),c("p2p")),l(It,c("p2p-webrtc-direct")),l(Ct,c("p2p-webrtc-direct"))),Y=y(Et,At,It,Ct,Ar,Ir,J,Co,So,Z,vr,Er),_c=y(l(Y,c("p2p-stardust"),c("p2p")),l(Y,c("p2p-stardust"))),H=y(l(Y,c("p2p")),Ar,Ir,vr,Er,c("p2p")),yr=y(l(H,c("p2p-circuit"),H),l(H,c("p2p-circuit")),l(c("p2p-circuit"),H),l(Y,c("p2p-circuit")),l(c("p2p-circuit"),Y),c("p2p-circuit")),Cr=()=>y(l(yr,Cr),yr),K=Cr(),Rc=y(l(K,H,K),l(H,K),l(K,H),K,H);var jc=y(l(K,c("webrtc"),c("p2p")),l(K,c("webrtc")),l(Y,c("webrtc"),c("p2p")),l(Y,c("webrtc")),c("webrtc"));function Sr(r){function e(t){let n;try{n=F(t)}catch{return!1}let o=r(n.protoNames());return o===null?!1:o===!0||o===!1?o:o.length===0}return e}function l(...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:Sr(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:Sr(e),partialMatch:e}}function c(r){let e=r;function t(o){let s;try{s=F(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 Me=class extends Event{type;detail;constructor(e,t){super(e),this.type=e,this.detail=t}};var Mr=de(L("net"),1);function Tr(r,e){if(typeof r!="string")throw new z(`invalid ip provided: ${r}`);if(typeof e=="string"&&(e=parseInt(e)),isNaN(e))throw new z(`invalid port provided: ${e}`);if((0,M.isIPv4)(r))return F(`/ip4/${r}/tcp/${e}`);if((0,M.isIPv6)(r))return F(`/ip6/${r}/tcp/${e}`);throw new z(`invalid ip:port for creating a multiaddr: ${r}:${e}`)}function Pr(r){if(Uo(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(ko(r))return r;throw new Error("unknown stream")}function ko(r){return r[Symbol.asyncIterator]!=null}function Uo(r){return typeof r?.getReader=="function"}function kr(r){return async e=>{let t=async()=>{Do(e)&&await e.return(void 0)},n,o,s=x=>{n=x,t().catch(v=>{v=new AggregateError([n,v],"The Writable emitted an error, additionally an error occurred while ending the Source")}).finally(()=>{o?.(x)})},i,a=!1,p=()=>{a=!0,i?.()},w,u=!1,E=()=>{u=!0,w?.()},I,f=()=>{I?.()},d=async()=>new Promise((x,v)=>{i=I=x,o=v,r.once("drain",f)}),g=async()=>(await t(),new Promise((x,v)=>{if(a||u||n!=null){x();return}w=i=x,o=v})),S=()=>{r.removeListener("error",s),r.removeListener("close",p),r.removeListener("finish",E),r.removeListener("drain",f)};r.once("error",s),r.once("close",p),r.once("finish",E);try{for await(let x of e){if(!r.writable||r.destroyed||n!=null)break;r.write(x)||await d()}}catch(x){n==null&&r.destroy(x),n=x}try{if(r.writable&&r.end(),await g(),n!=null)throw n}finally{S()}}}function Do(r){return r.return!=null}function St(r){return{sink:kr(r),source:Pr(r)}}var Tt=de(L("os"),1),Ur=de(L("path"),1);var Mo={ip4:"IPv4",ip6:"IPv6"};function le(r,e={}){let t=r.getPath();return t!=null?Tt.default.platform()==="win32"?{path:Ur.default.join("\\\\.\\pipe\\",t)}:{path:t}:{...e,...r.toOptions()}}function Pt(r,e,t){let n=o=>F(`/${r}/${o}/tcp/${t}`);return(No(e)?Fo(Mo[r]):[e]).map(n)}function No(r){return["0.0.0.0","::"].includes(r)}var Lo=Tt.default.networkInterfaces();function Fo(r){let e=[];for(let[,t]of Object.entries(Lo))if(t!=null)for(let n of t)n.family===r&&e.push(n.address);return e}var Ne=(r,e)=>{let t=null,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 z("Could not determine remote address or port");p=Tr(r.remoteAddress,r.remotePort)}let w=le(p),u=w.path??`${w.host??""}:${w.port??""}`,{sink:E,source:I}=St(r);r.setTimeout(i,()=>{n("%s socket read timeout",u),o?.increment({[`${s}timeout`]:!0});let d;r.readable&&(d=new ee("Socket read timeout")),r.destroy(d)}),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(d){try{await E(async function*(){for await(let g of d)g instanceof Uint8Array?yield g:yield g.subarray()}())}catch(g){g.type!=="aborted"&&n.error("%s error in sink",u,g)}r.end()},source:I,remoteAddr:p,timeline:{open:Date.now()},async close(d={}){if(r.destroyed){n("The %s socket is destroyed",u);return}if(t!=null)return n("The %s socket is closed or closing",u),t;if(d.signal==null){let S=AbortSignal.timeout(a);d={...d,signal:S}}let g=()=>{r.destroy(new _("Destroying socket after timeout"))};d.signal?.addEventListener("abort",g);try{n("%s closing socket",u),t=new Promise((S,x)=>{r.once("close",()=>{n("%s socket closed",u),S()}),r.once("error",v=>{n("%s socket error",u,v),f.timeline.close==null&&(f.timeline.close=Date.now()),r.destroyed||x(v)}),r.setTimeout(a),r.end(),r.writableLength>0?r.once("drain",()=>{n("%s socket drained",u),r.destroy()}):r.destroy()}),await t}catch(S){this.abort(S)}finally{d.signal?.removeEventListener("abort",g)}},abort:d=>{n("%s socket abort due to error",u,d),r.destroyed||r.destroy(d),f.timeline.close==null&&(f.timeline.close=Date.now())},log:n};return f};async function Dr(r,e){try{await r.close()}catch(t){e.log.error("an error occurred closing the connection",t),r.abort(t)}}var A;(function(r){r[r.INACTIVE=0]="INACTIVE",r[r.ACTIVE=1]="ACTIVE",r[r.PAUSED=2]="PAUSED"})(A||(A={}));var Le=class extends ye{context;server;connections=new Set;status={code:A.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=Mr.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 z("closeAbove must be >= listenBelow");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]:A.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!==A.PAUSED&&this.safeDispatchEvent("close")})}onSocket(e){if(this.status.code!==A.ACTIVE)throw new we("Server is not listening yet");e.on("error",n=>{this.log("socket error",n),this.metrics?.events.increment({[`${this.addr} error`]:!0})});let t;try{t=Ne(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 Dr(t,{log:this.log})}).catch(n=>{this.log.error("closing inbound connection failed",n)})}catch(n){this.log.error("inbound connection failed",n),Dr(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===A.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(Pt("ip4",t.address,t.port)):t.family==="IPv6"&&(e=e.concat(Pt("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===A.ACTIVE||this.status.code===A.PAUSED)throw new be("server is already listening");let t=e.getPeerId(),n=t==null?e.decapsulateCode(421):e,{backlog:o}=this.context;try{this.status={code:A.ACTIVE,listeningAddr:n,peerId:t,netConfig:le(n,{backlog:o})},await this.resume()}catch(s){throw this.status={code:A.INACTIVE},s}}async close(){let e=new _("Listener is closing");this.connections.forEach(t=>{t.abort(e)}),await this.pause(!0)}async resume(){if(this.server.listening||this.status.code===A.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:A.ACTIVE},this.log("listening on %s",this.server.address())}async pause(e){if(!this.server.listening&&this.status.code===A.PAUSED&&e){this.status={code:A.INACTIVE};return}!this.server.listening||this.status.code!==A.ACTIVE||(this.log("closing server on %s",this.server.address()),this.status=e?{code:A.INACTIVE}:{...this.status,code:A.PAUSED},await new Promise((t,n)=>{this.server.close(o=>{if(o!=null){n(o);return}t()})}))}};var Fe=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"})})}[Dt]=!0;[Symbol.toStringTag]="@libp2p/tcp";[Lt]=["@libp2p/transport"];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=Ne(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 _;return i}async _connect(e,t){return t.signal?.throwIfAborted(),t.onProgress?.(new Me("tcp:open-connection")),new Promise((n,o)=>{let s=Date.now(),i=le(e,{...this.opts.dialOpts??{},...t});this.log("dialing %a",e);let a=Nr.default.connect(i),p=f=>{let d=i.path??`${i.host??""}:${i.port}`;f.message=`connection error ${d}: ${f.message}`,this.metrics?.dialerEvents.increment({error:!0}),I(f)},w=()=>{this.log("connection timeout %a",e),this.metrics?.dialerEvents.increment({timeout:!0});let f=new ee(`connection timeout after ${Date.now()-s}ms`);a.emit("error",f)},u=()=>{this.log("connection opened %a",e),this.metrics?.dialerEvents.increment({connect:!0}),I()},E=()=>{this.log("connection aborted %a",e),this.metrics?.dialerEvents.increment({abort:!0}),a.destroy(),I(new _)},I=f=>{if(a.removeListener("error",p),a.removeListener("timeout",w),a.removeListener("connect",u),t.signal!=null&&t.signal.removeEventListener("abort",E),f!=null){o(f);return}n(a)};a.on("error",p),a.on("timeout",w),a.on("connect",u),t.signal!=null&&t.signal.addEventListener("abort",E)})}createListener(e){return new Le({...this.opts.listenOpts??{},...e,maxConnections:this.opts.maxConnections,backlog:this.opts.backlog,closeServerOnMaxConnections:this.opts.closeServerOnMaxConnections,socketInactivityTimeout:this.opts.inboundSocketInactivityTimeout,socketCloseTimeout:this.opts.socketCloseTimeout,metrics:this.components.metrics,logger:this.components.logger})}listenFilter(e){return e=Array.isArray(e)?e:[e],e.filter(t=>t.protoCodes().includes(290)?!1:t.protoCodes().includes(400)?!0:J.matches(t.decapsulateCode(421)))}dialFilter(e){return this.listenFilter(e)}};function Oo(r={}){return e=>new Fe(e,r)}return Vr(zo);})();
|
|
3
3
|
return Libp2PTcp}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libp2p/tcp",
|
|
3
|
-
"version": "10.0.
|
|
3
|
+
"version": "10.0.2",
|
|
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",
|
|
@@ -60,8 +60,8 @@
|
|
|
60
60
|
"test:electron-main": "aegir test -t electron-main"
|
|
61
61
|
},
|
|
62
62
|
"dependencies": {
|
|
63
|
-
"@libp2p/interface": "^2.0
|
|
64
|
-
"@libp2p/utils": "^6.0.
|
|
63
|
+
"@libp2p/interface": "^2.1.0",
|
|
64
|
+
"@libp2p/utils": "^6.0.2",
|
|
65
65
|
"@multiformats/mafmt": "^12.1.6",
|
|
66
66
|
"@multiformats/multiaddr": "^12.2.3",
|
|
67
67
|
"@types/sinon": "^17.0.3",
|
|
@@ -69,8 +69,8 @@
|
|
|
69
69
|
"stream-to-it": "^1.0.1"
|
|
70
70
|
},
|
|
71
71
|
"devDependencies": {
|
|
72
|
-
"@libp2p/interface-compliance-tests": "^6.0
|
|
73
|
-
"@libp2p/logger": "^5.0.
|
|
72
|
+
"@libp2p/interface-compliance-tests": "^6.1.0",
|
|
73
|
+
"@libp2p/logger": "^5.0.2",
|
|
74
74
|
"aegir": "^44.0.1",
|
|
75
75
|
"it-all": "^3.0.6",
|
|
76
76
|
"it-pipe": "^3.0.1",
|