@libp2p/tcp 10.0.17 → 10.0.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.min.js CHANGED
@@ -1,3 +1,3 @@
1
1
  (function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PTcp = factory()}(typeof self !== 'undefined' ? self : this, function () {
2
- "use strict";var Libp2PTcp=(()=>{var Rr=Object.create;var xe=Object.defineProperty;var jr=Object.getOwnPropertyDescriptor;var qr=Object.getOwnPropertyNames;var Wr=Object.getPrototypeOf,Gr=Object.prototype.hasOwnProperty;var F=(r=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(r,{get:(e,t)=>(typeof require<"u"?require:e)[t]}):r)(function(r){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+r+'" is not supported')});var D=(r,e)=>{for(var t in e)xe(r,t,{get:e[t],enumerable:!0})},Ot=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of qr(e))!Gr.call(r,o)&&o!==t&&xe(r,o,{get:()=>e[o],enumerable:!(n=jr(e,o))||n.enumerable});return r};var le=(r,e,t)=>(t=r!=null?Rr(Wr(r)):{},Ot(e||!r||!r.__esModule?xe(t,"default",{value:r,enumerable:!0}):t,r)),Hr=r=>Ot(xe({},"__esModule",{value:!0}),r);var Qo={};D(Qo,{tcp:()=>Jo});var _r=le(F("net"),1);var zt=Symbol.for("@libp2p/transport");var Vt;(function(r){r[r.FATAL_ALL=0]="FATAL_ALL",r[r.NO_FATAL=1]="NO_FATAL"})(Vt||(Vt={}));var ge=class extends Error{static name="AbortError";constructor(e="The operation was aborted"){super(e),this.name="AbortError"}};var V=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}};var Z=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 Bt=F("events"),ve=(r,...e)=>{try{(0,Bt.setMaxListeners)(r,...e)}catch{}};var ye=class extends EventTarget{#e=new Map;constructor(){super(),ve(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 _t=Symbol.for("@libp2p/service-capabilities"),rs=Symbol.for("@libp2p/service-dependencies");var Re={};D(Re,{base58btc:()=>P,base58flickr:()=>Zr});var Ts=new Uint8Array(0);function Rt(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 k(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")}function jt(r){return new TextEncoder().encode(r)}function qt(r){return new TextDecoder().decode(r)}function Jr(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,d=r.charAt(0),m=Math.log(a)/Math.log(256),p=Math.log(256)/Math.log(a);function h(f){if(f instanceof Uint8Array||(ArrayBuffer.isView(f)?f=new Uint8Array(f.buffer,f.byteOffset,f.byteLength):Array.isArray(f)&&(f=Uint8Array.from(f))),!(f instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(f.length===0)return"";for(var I=0,T=0,x=0,w=f.length;x!==w&&f[x]===0;)x++,I++;for(var L=(w-x)*p+1>>>0,M=new Uint8Array(L);x!==w;){for(var O=f[x],j=0,N=L-1;(O!==0||j<T)&&N!==-1;N--,j++)O+=256*M[N]>>>0,M[N]=O%a>>>0,O=O/a>>>0;if(O!==0)throw new Error("Non-zero carry");T=j,x++}for(var B=L-T;B!==L&&M[B]===0;)B++;for(var me=d.repeat(I);B<L;++B)me+=r.charAt(M[B]);return me}function b(f){if(typeof f!="string")throw new TypeError("Expected String");if(f.length===0)return new Uint8Array;var I=0;if(f[I]!==" "){for(var T=0,x=0;f[I]===d;)T++,I++;for(var w=(f.length-I)*m+1>>>0,L=new Uint8Array(w);f[I];){var M=t[f.charCodeAt(I)];if(M===255)return;for(var O=0,j=w-1;(M!==0||O<x)&&j!==-1;j--,O++)M+=a*L[j]>>>0,L[j]=M%256>>>0,M=M/256>>>0;if(M!==0)throw new Error("Non-zero carry");x=O,I++}if(f[I]!==" "){for(var N=w-x;N!==w&&L[N]===0;)N++;for(var B=new Uint8Array(T+(w-N)),me=T;N!==w;)B[me++]=L[N++];return B}}}function l(f){var I=b(f);if(I)return I;throw new Error(`Non-${e} character`)}return{encode:h,decodeUnsafe:b,decode:l}}var Qr=Jr,Xr=Qr,Gt=Xr;var Ve=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")}},ze=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 Ht(this,e)}},Be=class{decoders;constructor(e){this.decoders=e}or(e){return Ht(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 Ht(r,e){return new Be({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var _e=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 Ve(e,t,n),this.decoder=new ze(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function ee({name:r,prefix:e,encode:t,decode:n}){return new _e(r,e,t,n)}function q({name:r,prefix:e,alphabet:t}){let{encode:n,decode:o}=Gt(t,r);return ee({prefix:e,name:r,encode:n,decode:s=>k(o(s))})}function Kr(r,e,t,n){let o={};for(let p=0;p<e.length;++p)o[e[p]]=p;let s=r.length;for(;r[s-1]==="=";)--s;let i=new Uint8Array(s*t/8|0),a=0,d=0,m=0;for(let p=0;p<s;++p){let h=o[r[p]];if(h===void 0)throw new SyntaxError(`Non-${n} character`);d=d<<t|h,a+=t,a>=8&&(a-=8,i[m++]=255&d>>a)}if(a>=t||255&d<<8-a)throw new SyntaxError("Unexpected end of data");return i}function Yr(r,e,t){let n=e[e.length-1]==="=",o=(1<<t)-1,s="",i=0,a=0;for(let d=0;d<r.length;++d)for(a=a<<8|r[d],i+=8;i>t;)i-=t,s+=e[o&a>>i];if(i!==0&&(s+=e[o&a<<t-i]),n)for(;s.length*t&7;)s+="=";return s}function y({name:r,prefix:e,bitsPerChar:t,alphabet:n}){return ee({prefix:e,name:r,encode(o){return Yr(o,n,t)},decode(o){return Kr(o,n,t,r)}})}var P=q({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Zr=q({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var je={};D(je,{base32:()=>_,base32hex:()=>nn,base32hexpad:()=>sn,base32hexpadupper:()=>cn,base32hexupper:()=>on,base32pad:()=>tn,base32padupper:()=>rn,base32upper:()=>en,base32z:()=>an});var _=y({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),en=y({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),tn=y({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),rn=y({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),nn=y({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),on=y({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),sn=y({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),cn=y({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),an=y({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var qe={};D(qe,{base36:()=>ue,base36upper:()=>ln});var ue=q({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),ln=q({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var un=Xt,Jt=128,dn=127,pn=~dn,fn=Math.pow(2,31);function Xt(r,e,t){e=e||[],t=t||0;for(var n=t;r>=fn;)e[t++]=r&255|Jt,r/=128;for(;r&pn;)e[t++]=r&255|Jt,r>>>=7;return e[t]=r|0,Xt.bytes=t-n+1,e}var hn=We,mn=128,Qt=127;function We(r,n){var t=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw We.bytes=0,new RangeError("Could not decode varint");i=r[s++],t+=o<28?(i&Qt)<<o:(i&Qt)*Math.pow(2,o),o+=7}while(i>=mn);return We.bytes=s-n,t}var xn=Math.pow(2,7),gn=Math.pow(2,14),wn=Math.pow(2,21),bn=Math.pow(2,28),vn=Math.pow(2,35),yn=Math.pow(2,42),En=Math.pow(2,49),In=Math.pow(2,56),An=Math.pow(2,63),Cn=function(r){return r<xn?1:r<gn?2:r<wn?3:r<bn?4:r<vn?5:r<yn?6:r<En?7:r<In?8:r<An?9:10},Tn={encode:un,decode:hn,encodingLength:Cn},Sn=Tn,de=Sn;function pe(r,e=0){return[de.decode(r,e),de.decode.bytes]}function te(r,e,t=0){return de.encode(r,e,t),e}function re(r){return de.encodingLength(r)}function J(r,e){let t=e.byteLength,n=re(r),o=n+re(t),s=new Uint8Array(o+t);return te(r,s,0),te(t,s,n),s.set(e,o),new ne(r,t,e,s)}function Ie(r){let e=k(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 ne(t,o,i,e)}function Kt(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&Rt(r.bytes,t.bytes)}}var ne=class{code;size;digest;bytes;constructor(e,t,n,o){this.code=e,this.size=t,this.digest=n,this.bytes=o}};function Yt(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return Ln(t,Ge(r),e??P.encoder);default:return Dn(t,Ge(r),e??_.encoder)}}var Zt=new WeakMap;function Ge(r){let e=Zt.get(r);if(e==null){let t=new Map;return Zt.set(r,t),t}return e}var W=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!==Mn)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=J(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&&Kt(e.multihash,n.multihash)}toString(e){return Yt(this,e)}toJSON(){return{"/":Yt(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??er(n,o,s.bytes))}else if(t[kn]===!0){let{version:n,multihash:o,code:s}=t,i=Ie(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=er(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=k(e.subarray(n,n+t.multihashSize));if(o.byteLength!==t.multihashSize)throw new Error("Incorrect length");let s=o.subarray(t.multihashSize-t.digestSize),i=new ne(t.multihashCode,t.digestSize,s,o);return[t.version===0?r.createV0(i):r.createV1(t.codec,i),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[h,b]=pe(e.subarray(t));return t+=b,h},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(),d=n(),m=t+d,p=m-i;return{version:o,codec:s,multihashCode:a,digestSize:d,multihashSize:p,size:m}}static parse(e,t){let[n,o]=Pn(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 Ge(s).set(n,e),s}};function Pn(r,e){switch(r[0]){case"Q":{let t=e??P;return[P.prefix,t.decode(`${P.prefix}${r}`)]}case P.prefix:{let t=e??P;return[P.prefix,t.decode(r)]}case _.prefix:{let t=e??_;return[_.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 Ln(r,e,t){let{prefix:n}=t;if(n!==P.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let o=e.get(n);if(o==null){let s=t.encode(r).slice(1);return e.set(n,s),s}else return o}function Dn(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,Mn=18;function er(r,e,t){let n=re(r),o=n+re(e),s=new Uint8Array(o+t.byteLength);return te(r,s,0),te(e,s,n),s.set(t,o),s}var kn=Symbol.for("@ipld/js-cid/CID");function tr(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 lr=F("node:buffer");var He={};D(He,{base10:()=>Un});var Un=q({prefix:"9",name:"base10",alphabet:"0123456789"});var Je={};D(Je,{base16:()=>Nn,base16upper:()=>Fn});var Nn=y({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Fn=y({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Qe={};D(Qe,{base2:()=>$n});var $n=y({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Xe={};D(Xe,{base256emoji:()=>_n});var rr=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}"),On=rr.reduce((r,e,t)=>(r[t]=e,r),[]),Vn=rr.reduce((r,e,t)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return r[n]=t,r},[]);function zn(r){return r.reduce((e,t)=>(e+=On[t],e),"")}function Bn(r){let e=[];for(let t of r){let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);let o=Vn[n];if(o==null)throw new Error(`Non-base256emoji character: ${t}`);e.push(o)}return new Uint8Array(e)}var _n=ee({prefix:"\u{1F680}",name:"base256emoji",encode:zn,decode:Bn});var Ke={};D(Ke,{base64:()=>Rn,base64pad:()=>jn,base64url:()=>qn,base64urlpad:()=>Wn});var Rn=y({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),jn=y({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),qn=y({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Wn=y({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Ye={};D(Ye,{base8:()=>Gn});var Gn=y({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Ze={};D(Ze,{identity:()=>Hn});var Hn=ee({prefix:"\0",name:"identity",encode:r=>qt(r),decode:r=>jt(r)});var Ys=new TextEncoder,Zs=new TextDecoder;var et={};D(et,{identity:()=>Yn});var nr=0,Xn="identity",or=k;function Kn(r){return J(nr,or(r))}var Yn={code:nr,name:Xn,encode:or,digest:Kn};var ot={};D(ot,{sha256:()=>Zn,sha512:()=>eo});var nt=le(F("crypto"),1);function rt({name:r,code:e,encode:t}){return new tt(r,e,t)}var tt=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?J(this.code,t):t.then(n=>J(this.code,n))}else throw Error("Unknown type, must be binary type")}};var Zn=rt({name:"sha2-256",code:18,encode:r=>k(nt.default.createHash("sha256").update(r).digest())}),eo=rt({name:"sha2-512",code:19,encode:r=>k(nt.default.createHash("sha512").update(r).digest())});var he={...Ze,...Qe,...Ye,...He,...Je,...je,...qe,...Re,...Ke,...Xe},fi={...ot,...et};var ir=F("node:buffer");function se(r){return new Uint8Array(r.buffer,r.byteOffset,r.byteLength)}function Ae(r=0){return se(ir.Buffer.allocUnsafe(r))}function ar(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var cr=ar("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),st=ar("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}),to={utf8:cr,"utf-8":cr,hex:he.base16,latin1:st,ascii:st,binary:st,...he},Ce=to;function S(r,e="utf8"){let t=Ce[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return e==="utf8"||e==="utf-8"?lr.Buffer.from(r.buffer,r.byteOffset,r.byteLength).toString("utf8"):t.encoder.encode(r).substring(1)}var ro=Math.pow(2,7),no=Math.pow(2,14),oo=Math.pow(2,21),it=Math.pow(2,28),ct=Math.pow(2,35),at=Math.pow(2,42),lt=Math.pow(2,49),g=128,C=127;function z(r){if(r<ro)return 1;if(r<no)return 2;if(r<oo)return 3;if(r<it)return 4;if(r<ct)return 5;if(r<at)return 6;if(r<lt)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function so(r,e,t=0){switch(z(r)){case 8:e[t++]=r&255|g,r/=128;case 7:e[t++]=r&255|g,r/=128;case 6:e[t++]=r&255|g,r/=128;case 5:e[t++]=r&255|g,r/=128;case 4:e[t++]=r&255|g,r>>>=7;case 3:e[t++]=r&255|g,r>>>=7;case 2:e[t++]=r&255|g,r>>>=7;case 1:{e[t++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return e}function io(r,e,t=0){switch(z(r)){case 8:e.set(t++,r&255|g),r/=128;case 7:e.set(t++,r&255|g),r/=128;case 6:e.set(t++,r&255|g),r/=128;case 5:e.set(t++,r&255|g),r/=128;case 4:e.set(t++,r&255|g),r>>>=7;case 3:e.set(t++,r&255|g),r>>>=7;case 2:e.set(t++,r&255|g),r>>>=7;case 1:{e.set(t++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return e}function co(r,e){let t=r[e],n=0;if(n+=t&C,t<g||(t=r[e+1],n+=(t&C)<<7,t<g)||(t=r[e+2],n+=(t&C)<<14,t<g)||(t=r[e+3],n+=(t&C)<<21,t<g)||(t=r[e+4],n+=(t&C)*it,t<g)||(t=r[e+5],n+=(t&C)*ct,t<g)||(t=r[e+6],n+=(t&C)*at,t<g)||(t=r[e+7],n+=(t&C)*lt,t<g))return n;throw new RangeError("Could not decode varint")}function ao(r,e){let t=r.get(e),n=0;if(n+=t&C,t<g||(t=r.get(e+1),n+=(t&C)<<7,t<g)||(t=r.get(e+2),n+=(t&C)<<14,t<g)||(t=r.get(e+3),n+=(t&C)<<21,t<g)||(t=r.get(e+4),n+=(t&C)*it,t<g)||(t=r.get(e+5),n+=(t&C)*ct,t<g)||(t=r.get(e+6),n+=(t&C)*at,t<g)||(t=r.get(e+7),n+=(t&C)*lt,t<g))return n;throw new RangeError("Could not decode varint")}function ie(r,e,t=0){return e==null&&(e=Ae(z(r))),e instanceof Uint8Array?so(r,e,t):io(r,e,t)}function Q(r,e=0){return r instanceof Uint8Array?co(r,e):ao(r,e)}var dr=F("node:buffer");function R(r,e){return se(dr.Buffer.concat(r,e))}var Te=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 d=a==="0",m=2**(8*o)-1;for(;;){let p=this.readAtomically(()=>{let h=this.readChar();if(h===void 0)return;let b=Number.parseInt(h,e);if(!Number.isNaN(b))return b});if(p===void 0)break;if(s*=e,s+=p,s>m||(i+=1,t!==void 0&&i>t))return}if(i!==0)return!n&&d&&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 Pi=new Te;var $i=parseInt("0xFFFF",16),Oi=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);var hr=F("node:buffer");function Se(r,e="utf8"){let t=Ce[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return e==="utf8"||e==="utf-8"?se(hr.Buffer.from(r,"utf-8")):t.decoder.decode(`${t.prefix}${r}`)}var U=F("node:net");function Pe(r){return!!(0,U.isIP)(r)}var mr=U.isIPv4,mo=U.isIPv6,ut=function(r){let e=0;if(r=r.toString().trim(),mr(r)){let t=new Uint8Array(e+4);return r.split(/\./g).forEach(n=>{t[e++]=parseInt(n,10)&255}),t}if(mo(r)){let t=r.split(":",8),n;for(n=0;n<t.length;n++){let s=mr(t[n]),i;s&&(i=ut(t[n]),t[n]=S(i.slice(0,2),"base16")),i!=null&&++n<8&&t.splice(n,0,S(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")},xr=function(r,e=0,t){e=~~e,t=t??r.length-e;let n=new DataView(r.buffer);if(t===4){let o=[];for(let s=0;s<t;s++)o.push(r[e+s]);return o.join(".")}if(t===16){let o=[];for(let s=0;s<t;s+=2)o.push(n.getUint16(e+s).toString(16));return o.join(":").replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}return""};var ce={},dt={},go=[[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"]];go.forEach(r=>{let e=wo(...r);dt[e.code]=e,ce[e.name]=e});function wo(r,e,t,n,o){return{code:r,size:e,name:t,resolvable:!!n,path:!!o}}function v(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(ce[r]!=null)return ce[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var Ac=v("ip4"),Cc=v("ip6"),Tc=v("ipcidr");function mt(r,e){switch(v(r).code){case 4:case 41:return vo(e);case 42:return ht(e);case 43:return S(e,"base10");case 6:case 273:case 33:case 132:return br(e).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return ht(e);case 421:return Ao(e);case 444:return wr(e);case 445:return wr(e);case 466:return Io(e);case 481:return globalThis.encodeURIComponent(ht(e));default:return S(e,"base16")}}function xt(r,e){switch(v(r).code){case 4:return gr(e);case 41:return gr(e);case 42:return ft(e);case 43:return Se(e,"base10");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 ft(e);case 421:return yo(e);case 444:return Co(e);case 445:return To(e);case 466:return Eo(e);case 481:return ft(globalThis.decodeURIComponent(e));default:return Se(e,"base16")}}var pt=Object.values(he).map(r=>r.decoder),bo=function(){let r=pt[0].or(pt[1]);return pt.slice(2).forEach(e=>r=r.or(e)),r}();function gr(r){if(!Pe(r))throw new Error("invalid ip address");return ut(r)}function vo(r){let e=xr(r,0,r.length);if(e==null)throw new Error("ipBuff is required");if(!Pe(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 br(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function ft(r){let e=Se(r),t=Uint8Array.from(ie(e.length));return R([t,e],t.length+e.length)}function ht(r){let e=Q(r);if(r=r.slice(z(e)),r.length!==e)throw new Error("inconsistent lengths");return S(r)}function yo(r){let e;r[0]==="Q"||r[0]==="1"?e=Ie(P.decode(`z${r}`)).bytes:e=W.parse(r).multihash.bytes;let t=Uint8Array.from(ie(e.length));return R([t,e],t.length+e.length)}function Eo(r){let e=bo.decode(r),t=Uint8Array.from(ie(e.length));return R([t,e],t.length+e.length)}function Io(r){let e=Q(r),t=r.slice(z(e));if(t.length!==e)throw new Error("inconsistent lengths");return"u"+S(t,"base64url")}function Ao(r){let e=Q(r),t=r.slice(z(e));if(t.length!==e)throw new Error("inconsistent lengths");return S(t,"base58btc")}function Co(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=_.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 R([t,o],t.length+o.length)}function To(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=_.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 R([t,o],t.length+o.length)}function wr(r){let e=r.slice(0,r.length-2),t=r.slice(r.length-2),n=S(e,"base32"),o=br(t);return`${n}:${o}`}function vr(r){r=wt(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=v(i);if(a.size===0){e.push([a.code]),t.push([a.code]);continue}if(s++,s>=o.length)throw Er("invalid address: "+r);if(a.path===!0){n=wt(o.slice(s).join("/")),e.push([a.code,xt(a.code,n)]),t.push([a.code,n]);break}let d=xt(a.code,o[s]);e.push([a.code,d]),t.push([a.code,mt(a.code,d)])}return{string:yr(t),bytes:vt(e),tuples:e,stringTuples:t,path:n}}function bt(r){let e=[],t=[],n=null,o=0;for(;o<r.length;){let s=Q(r,o),i=z(s),a=v(s),d=So(a,r.slice(o+i));if(d===0){e.push([s]),t.push([s]),o+=i;continue}let m=r.slice(o+i,o+i+d);if(o+=d+i,o>r.length)throw Er("Invalid address Uint8Array: "+S(r,"base16"));e.push([s,m]);let p=mt(s,m);if(t.push([s,p]),a.path===!0){n=p;break}}return{bytes:Uint8Array.from(r),string:yr(t),tuples:e,stringTuples:t,path:n}}function yr(r){let e=[];return r.map(t=>{let n=v(t[0]);return e.push(n.name),t.length>1&&t[1]!=null&&e.push(t[1]),null}),wt(e.join("/"))}function vt(r){return R(r.map(e=>{let t=v(e[0]),n=Uint8Array.from(ie(t.code));return e.length>1&&e[1]!=null&&(n=R([n,e[1]])),n}))}function So(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+z(t)}}function wt(r){return"/"+r.trim().split("/").filter(e=>e).join("/")}function Er(r){return new Error("Error parsing address: "+r)}var Po=Symbol.for("nodejs.util.inspect.custom"),Et=Symbol.for("@multiformats/js-multiaddr/multiaddr"),Lo=[v("dns").code,v("dns4").code,v("dns6").code,v("dnsaddr").code],yt=class extends Error{constructor(e="No available resolver"){super(e),this.name="NoAvailableResolverError"}},Le=class r{bytes;#e;#t;#r;#n;[Et]=!0;constructor(e){e==null&&(e="");let t;if(e instanceof Uint8Array)t=bt(e);else if(typeof e=="string"){if(e.length>0&&e.charAt(0)!=="/")throw new Error(`multiaddr "${e}" must start with a "/"`);t=vr(e)}else if(Ar(e))t=bt(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=v("tcp"),a=v("udp"),d=v("ip4"),m=v("ip6"),p=v("dns6"),h=v("ip6zone");for(let[l,f]of this.stringTuples())l===h.code&&(s=`%${f??""}`),Lo.includes(l)&&(t=i.name,o=443,n=`${f??""}${s}`,e=l===p.code?6:4),(l===i.code||l===a.code)&&(t=v(l).name,o=parseInt(f??"")),(l===d.code||l===m.code)&&(t=v(l).name,n=`${f??""}${s}`,e=l===m.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({},v(e)))}protoCodes(){return this.#t.map(([e])=>e)}protoNames(){return this.#t.map(([e])=>v(e).name)}tuples(){return this.#t.map(([e,t])=>t==null?[e]:[e,t])}stringTuples(){return this.#r.map(([e,t])=>t==null?[e]:[e,t])}encapsulate(e){return e=new r(e),new r(this.toString()+e.toString())}decapsulate(e){let t=e.toString(),n=this.toString(),o=n.lastIndexOf(t);if(o<0)throw new Error(`Address ${this.toString()} does not contain subaddress: ${e.toString()}`);return new r(n.slice(0,o))}decapsulateCode(e){let t=this.tuples();for(let n=t.length-1;n>=0;n--)if(t[n][0]===e)return new r(vt(t.slice(0,n)));return this}getPeerId(){try{let e=[];this.stringTuples().forEach(([n,o])=>{n===ce.p2p.code&&e.push([n,o]),n===ce["p2p-circuit"].code&&(e=[])});let t=e.pop();if(t?.[1]!=null){let n=t[1];return n[0]==="Q"||n[0]==="1"?S(P.decode(`z${n}`),"base58btc"):S(W.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){return this.#n}equals(e){return tr(this.bytes,e.bytes)}async resolve(e){let t=this.protos().find(s=>s.resolvable);if(t==null)return[this];let n=Ir.get(t.name);if(n==null)throw new yt(`no available resolver for ${t.name}`);return(await n(this,e)).map(s=>$(s))}nodeAddress(){let e=this.toOptions();if(e.transport!=="tcp"&&e.transport!=="udp")throw new Error(`multiaddr must have a valid format - no protocol with name: "${e.transport}". Must have a valid transport protocol: "{tcp, udp}"`);return{family:e.family,address:e.host,port:e.port}}isThinWaistAddress(e){let t=(e??this).protos();return!(t.length!==2||t[0].code!==4&&t[0].code!==41||t[1].code!==6&&t[1].code!==273)}[Po](){return`Multiaddr(${this.#e})`}};var Ir=new Map;function Ar(r){return!!r?.[Et]}function $(r){return new Le(r)}var Do=c("dns4"),Mo=c("dns6"),ko=c("dnsaddr"),K=E(c("dns"),ko,Do,Mo),ke=E(c("ip4"),c("ip6")),H=E(u(ke,c("tcp")),u(K,c("tcp"))),Ue=u(ke,c("udp")),Uo=u(Ue,c("utp")),No=u(Ue,c("quic")),Fo=u(Ue,c("quic-v1")),It=E(u(H,c("ws")),u(K,c("ws"))),De=E(u(It,c("p2p")),It),At=E(u(H,c("wss")),u(K,c("wss")),u(H,c("tls"),c("ws")),u(K,c("tls"),c("ws"))),Me=E(u(At,c("p2p")),At),Ct=E(u(H,c("http")),u(ke,c("http")),u(K,c("http"))),Tt=E(u(H,c("https")),u(ke,c("https")),u(K,c("https"))),Cr=u(Ue,c("webrtc-direct"),c("certhash")),Pr=E(u(Cr,c("p2p")),Cr),Tr=u(Fo,c("webtransport"),c("certhash"),c("certhash")),Lr=E(u(Tr,c("p2p")),Tr),Dr=E(u(De,c("p2p-webrtc-star"),c("p2p")),u(Me,c("p2p-webrtc-star"),c("p2p")),u(De,c("p2p-webrtc-star")),u(Me,c("p2p-webrtc-star"))),Kc=E(u(De,c("p2p-websocket-star"),c("p2p")),u(Me,c("p2p-websocket-star"),c("p2p")),u(De,c("p2p-websocket-star")),u(Me,c("p2p-websocket-star"))),Mr=E(u(Ct,c("p2p-webrtc-direct"),c("p2p")),u(Tt,c("p2p-webrtc-direct"),c("p2p")),u(Ct,c("p2p-webrtc-direct")),u(Tt,c("p2p-webrtc-direct"))),Y=E(It,At,Ct,Tt,Dr,Mr,H,Uo,No,K,Pr,Lr),Yc=E(u(Y,c("p2p-stardust"),c("p2p")),u(Y,c("p2p-stardust"))),G=E(u(Y,c("p2p")),Dr,Mr,Pr,Lr,c("p2p")),Sr=E(u(G,c("p2p-circuit"),G),u(G,c("p2p-circuit")),u(c("p2p-circuit"),G),u(Y,c("p2p-circuit")),u(c("p2p-circuit"),Y),c("p2p-circuit")),kr=()=>E(u(Sr,kr),Sr),X=kr(),Zc=E(u(X,G,X),u(G,X),u(X,G),X,G);var ea=E(u(X,c("webrtc"),c("p2p")),u(X,c("webrtc")),u(Y,c("webrtc"),c("p2p")),u(Y,c("webrtc")),c("webrtc"));function Ur(r){function e(t){let n;try{n=$(t)}catch{return!1}let o=r(n.protoNames());return o===null?!1:o===!0||o===!1?o:o.length===0}return e}function u(...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:Ur(e),partialMatch:e}}function E(...r){function e(n){let o=null;return r.some(s=>{let i=typeof s=="function"?s().partialMatch(n):s.partialMatch(n);return i!=null?(o=i,!0):!1}),o}return{toString:function(){return"{ "+r.join(" ")+" }"},input:r,matches:Ur(e),partialMatch:e}}function c(r){let e=r;function t(o){let s;try{s=$(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 Ne=class extends Event{type;detail;constructor(e,t){super(e),this.type=e,this.detail=t}};var Br=le(F("net"),1);var St=class extends Error{constructor(e){super(e),this.name="TimeoutError"}},Pt=class extends Error{constructor(e){super(),this.name="AbortError",this.message=e}},Nr=r=>globalThis.DOMException===void 0?new Pt(r):new DOMException(r),Fr=r=>{let e=r.reason===void 0?Nr("This operation was aborted."):r.reason;return e instanceof Error?e:Nr(e)};function Lt(r,e){let{milliseconds:t,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout}}=e,i,a,m=new Promise((p,h)=>{if(typeof t!="number"||Math.sign(t)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${t}\``);if(e.signal){let{signal:l}=e;l.aborted&&h(Fr(l)),a=()=>{h(Fr(l))},l.addEventListener("abort",a,{once:!0})}if(t===Number.POSITIVE_INFINITY){r.then(p,h);return}let b=new St;i=s.setTimeout.call(void 0,()=>{if(n){try{p(n())}catch(l){h(l)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?p():o instanceof Error?h(o):(b.message=o??`Promise timed out after ${t} milliseconds`,h(b))},t),(async()=>{try{p(await r)}catch(l){h(l)}})()}).finally(()=>{m.clear(),a&&e.signal&&e.signal.removeEventListener("abort",a)});return m.clear=()=>{s.clearTimeout.call(void 0,i),i=void 0},m}var Oo=r=>{let e=r.addEventListener||r.on||r.addListener,t=r.removeEventListener||r.off||r.removeListener;if(!e||!t)throw new TypeError("Emitter is not compatible");return{addListener:e.bind(r),removeListener:t.bind(r)}};function Vo(r,e,t){let n,o=new Promise((s,i)=>{if(t={rejectionEvents:["error"],multiArgs:!1,resolveImmediately:!1,...t},!(t.count>=0&&(t.count===Number.POSITIVE_INFINITY||Number.isInteger(t.count))))throw new TypeError("The `count` option should be at least 0 or more");t.signal?.throwIfAborted();let a=[e].flat(),d=[],{addListener:m,removeListener:p}=Oo(r),h=(...l)=>{let f=t.multiArgs?l:l[0];t.filter&&!t.filter(f)||(d.push(f),t.count===d.length&&(n(),s(d)))},b=l=>{n(),i(l)};n=()=>{for(let l of a)p(l,h);for(let l of t.rejectionEvents)p(l,b)};for(let l of a)m(l,h);for(let l of t.rejectionEvents)m(l,b);t.signal&&t.signal.addEventListener("abort",()=>{b(t.signal.reason)},{once:!0}),t.resolveImmediately&&s(d)});if(o.cancel=n,typeof t.timeout=="number"){let s=Lt(o,{milliseconds:t.timeout});return s.cancel=n,s}return o}function Dt(r,e,t){typeof t=="function"&&(t={filter:t}),t={...t,count:1,resolveImmediately:!1};let n=Vo(r,e,t),o=n.then(s=>s[0]);return o.cancel=n.cancel,o}function $r(r,e){if(typeof r!="string")throw new V(`invalid ip provided: ${r}`);if(typeof e=="string"&&(e=parseInt(e)),isNaN(e))throw new V(`invalid port provided: ${e}`);if((0,U.isIPv4)(r))return $(`/ip4/${r}/tcp/${e}`);if((0,U.isIPv6)(r))return $(`/ip6/${r}/tcp/${e}`);throw new V(`invalid ip:port for creating a multiaddr: ${r}:${e}`)}function Mt(){let r={};return r.promise=new Promise((e,t)=>{r.resolve=e,r.reject=t}),r}var kt=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.name="AbortError",this.code=t??"ABORT_ERR"}};async function Ut(r,e,t,n){let o=new kt(n?.errorMessage,n?.errorCode);return t?.aborted===!0?Promise.reject(o):new Promise((s,i)=>{function a(){t?.removeEventListener("abort",p),r.removeEventListener(e,d),n?.errorEvent!=null&&r.removeEventListener(n.errorEvent,m)}let d=h=>{try{if(n?.filter?.(h)===!1)return}catch(b){a(),i(b);return}a(),s(h)},m=h=>{a(),i(h.detail)},p=()=>{a(),i(o)};t?.addEventListener("abort",p),r.addEventListener(e,d),n?.errorEvent!=null&&r.addEventListener(n.errorEvent,m)})}function Or(r){if(Bo(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(zo(r))return r;throw new Error("unknown stream")}function zo(r){return r[Symbol.asyncIterator]!=null}function Bo(r){return typeof r?.getReader=="function"}function Vr(r){return async e=>{let t=async()=>{_o(e)&&await e.return(void 0)},n,o,s=x=>{n=x,t().catch(w=>{w=new AggregateError([n,w],"The Writable emitted an error, additionally an error occurred while ending the Source")}).finally(()=>{o?.(x)})},i,a=!1,d=()=>{a=!0,i?.()},m,p=!1,h=()=>{p=!0,m?.()},b,l=()=>{b?.()},f=async()=>new Promise((x,w)=>{i=b=x,o=w,r.once("drain",l)}),I=async()=>(await t(),new Promise((x,w)=>{if(a||p||n!=null){x();return}m=i=x,o=w})),T=()=>{r.removeListener("error",s),r.removeListener("close",d),r.removeListener("finish",h),r.removeListener("drain",l)};r.once("error",s),r.once("close",d),r.once("finish",h);try{for await(let x of e){if(!r.writable||r.destroyed||n!=null)break;r.write(x)||await f()}}catch(x){n==null&&r.destroy(x),n=x}try{if(r.writable&&r.end(),await I(),n!=null)throw n}finally{T()}}}function _o(r){return r.return!=null}function Nt(r){return{sink:Vr(r),source:Or(r)}}var Ft=le(F("os"),1),zr=le(F("path"),1);var Ro={ip4:"IPv4",ip6:"IPv6"};function ae(r,e={}){let t=r.getPath();return t!=null?Ft.default.platform()==="win32"?{path:zr.default.join("\\\\.\\pipe\\",t)}:{path:t}:{...e,...r.toOptions()}}function $t(r,e,t){let n=o=>$(`/${r}/${o}/tcp/${t}`);return(jo(e)?Wo(Ro[r]):[e]).map(n)}function jo(r){return["0.0.0.0","::"].includes(r)}var qo=Ft.default.networkInterfaces();function Wo(r){let e=[];for(let[,t]of Object.entries(qo))if(t!=null)for(let n of t)n.family===r&&e.push(n.address);return e}var Fe=(r,e)=>{let t,n=e.logger.forComponent("libp2p:tcp:socket"),o=e.direction,s=e.metrics,i=e.metricPrefix??"",a=e.socketInactivityTimeout??12e4,d=e.socketCloseTimeout??500,m=!1,p=!1;e.listeningAddr?.getPath()!=null&&(e.remoteAddr=e.listeningAddr),e.remoteAddr?.getPath()!=null&&(e.localAddr=e.remoteAddr),r.on("error",x=>{p=!0,m||(n.error("%s socket error - %e",o,x),s?.increment({[`${i}error`]:!0})),r.destroy(),T.timeline.close=Date.now()});let h;if(e.remoteAddr!=null)h=e.remoteAddr;else{if(r.remoteAddress==null||r.remotePort==null)throw new V("Could not determine remote address or port");h=$r(r.remoteAddress,r.remotePort)}let b=ae(h),l=b.path??`${b.host??""}:${b.port??""}`,{sink:f,source:I}=Nt(r);r.setTimeout(a),r.once("timeout",()=>{m=!0,n("%s %s socket read timeout",o,l),s?.increment({[`${i}timeout`]:!0}),r.destroy(new Z),T.timeline.close=Date.now()}),r.once("close",()=>{!m&&!p&&(n("%s %s socket close",o,l),s?.increment({[`${i}close`]:!0})),r.destroy(),T.timeline.close=Date.now()}),r.once("end",()=>{n("%s %s socket end",o,l),s?.increment({[`${i}end`]:!0})});let T={async sink(x){try{await f(async function*(){for await(let w of x)w instanceof Uint8Array?yield w:yield w.subarray()}())}catch(w){w.type!=="aborted"&&n.error("%s %s error in sink - %e",o,l,w)}r.end()},source:I,remoteAddr:h,timeline:{open:Date.now()},async close(x={}){if(r.closed){n("the %s %s socket is already closed",o,l);return}if(r.destroyed){n("the %s %s socket is already destroyed",o,l);return}if(t!=null)return t.promise;try{t=Mt(),r.end();let w=Go(r),L=x.signal??AbortSignal.timeout(d);r.writableLength>0&&(n("%s %s draining socket",o,l),await Ut(w,"drain",L,{errorEvent:"error"}),n("%s %s socket drained",o,l)),await Promise.all([Ut(w,"close",L,{errorEvent:"error"}),r.destroy()])}catch(w){this.abort(w)}finally{t.resolve()}},abort:x=>{n("%s %s socket abort due to error - %e",o,l,x),r.destroy(),T.timeline.close=Date.now()},log:n};return T};function Go(r){return{addEventListener:(t,n)=>{r.addListener(t,n)},removeEventListener:(t,n)=>{r.removeListener(t,n)}}}var A;(function(r){r[r.INACTIVE=0]="INACTIVE",r[r.ACTIVE=1]="ACTIVE",r[r.PAUSED=2]="PAUSED"})(A||(A={}));var $e=class extends ye{context;server;sockets=new Set;status={code:A.INACTIVE};metrics;addr;log;shutdownController;constructor(e){if(super(),this.context=e,e.keepAlive=e.keepAlive??!0,e.noDelay=e.noDelay??!0,this.shutdownController=new AbortController,ve(1/0,this.shutdownController.signal),this.log=e.logger.forComponent("libp2p:tcp:listener"),this.addr="unknown",this.server=Br.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 V("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.sockets.size})}),this.metrics={status:e.metrics.registerMetricGroup("libp2p_tcp_listener_status_info",{label:"address",help:"Current status of the TCP listener socket"}),errors:e.metrics.registerMetricGroup("libp2p_tcp_listener_errors_total",{label:"address",help:"Total count of TCP listener errors by type"}),events:e.metrics.registerMetricGroup("libp2p_tcp_listener_events_total",{label:"address",help:"Total count of TCP listener events by type"})},this.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")}).on("drop",()=>{this.metrics?.events.increment({[`${this.addr} drop`]:!0})})}onSocket(e){if(this.metrics?.events.increment({[`${this.addr} connection`]:!0}),this.status.code!==A.ACTIVE)throw e.destroy(),new we("Server is not listening yet");let t;try{t=Fe(e,{listeningAddr:this.status.listeningAddr,socketInactivityTimeout:this.context.socketInactivityTimeout,socketCloseTimeout:this.context.socketCloseTimeout,metrics:this.metrics?.events,metricPrefix:`${this.addr} `,logger:this.context.logger,direction:"inbound"})}catch(n){this.log.error("inbound connection failed",n),this.metrics?.errors.increment({[`${this.addr} inbound_to_connection`]:!0}),e.destroy();return}this.log("new inbound connection %s",t.remoteAddr),this.sockets.add(e),this.context.upgrader.upgradeInbound(t,{signal:this.shutdownController.signal}).then(()=>{this.log("inbound connection upgraded %s",t.remoteAddr),e.once("close",()=>{this.sockets.delete(e),this.context.closeServerOnMaxConnections!=null&&this.sockets.size<this.context.closeServerOnMaxConnections.listenBelow&&this.resume().catch(n=>{this.log.error("error attempting to listen server once connection count under limit",n),this.context.closeServerOnMaxConnections?.onListenError?.(n)})}),this.context.closeServerOnMaxConnections!=null&&this.sockets.size>=this.context.closeServerOnMaxConnections.closeAbove&&this.pause()}).catch(async n=>{this.log.error("inbound connection upgrade failed",n),this.metrics?.errors.increment({[`${this.addr} inbound_upgrade`]:!0}),this.sockets.delete(e),t.abort(n)})}getAddrs(){if(this.status.code===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($t("ip4",t.address,t.port)):t.family==="IPv6"&&(e=e.concat($t("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:ae(n,{backlog:o})},await this.resume()}catch(s){throw this.status={code:A.INACTIVE},s}}async close(){let e=[];this.server.listening&&e.push(Dt(this.server,"close")),this.pause(!0),this.shutdownController.abort(),this.sockets.forEach(t=>{t.readable&&(e.push(Dt(t,"close")),t.destroy())}),await Promise.all(e)}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())}pause(e=!1){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},this.server.close())}};var Oe=class{opts;metrics;components;log;constructor(e,t={}){this.log=e.logger.forComponent("libp2p:tcp"),this.opts=t,this.components=e,e.metrics!=null&&(this.metrics={events:e.metrics.registerCounterGroup("libp2p_tcp_dialer_events_total",{label:"event",help:"Total count of TCP dialer events by type"}),errors:e.metrics.registerCounterGroup("libp2p_tcp_dialer_errors_total",{label:"event",help:"Total count of TCP dialer events by type"})})}[zt]=!0;[Symbol.toStringTag]="@libp2p/tcp";[_t]=["@libp2p/transport"];async dial(e,t){t.keepAlive=t.keepAlive??!0,t.noDelay=t.noDelay??!0;let n=await this._connect(e,t),o;try{o=Fe(n,{remoteAddr:e,socketInactivityTimeout:this.opts.outboundSocketInactivityTimeout,socketCloseTimeout:this.opts.socketCloseTimeout,metrics:this.metrics?.events,logger:this.components.logger,direction:"outbound"})}catch(s){throw this.metrics?.errors.increment({outbound_to_connection:!0}),n.destroy(s),s}try{return this.log("new outbound connection %s",o.remoteAddr),await t.upgrader.upgradeOutbound(o,t)}catch(s){throw this.metrics?.errors.increment({outbound_upgrade:!0}),this.log.error("error upgrading outbound connection",s),o.abort(s),s}}async _connect(e,t){t.signal?.throwIfAborted(),t.onProgress?.(new Ne("tcp:open-connection"));let n;return new Promise((o,s)=>{let i=Date.now(),a=ae(e,{...this.opts.dialOpts??{},...t});this.log("dialing %a",e),n=_r.default.connect(a);let d=l=>{this.log.error("dial to %a errored - %e",e,l);let f=a.path??`${a.host??""}:${a.port}`;l.message=`connection error ${f}: ${l.message}`,this.metrics?.events.increment({error:!0}),b(l)},m=()=>{this.log("connection timeout %a",e),this.metrics?.events.increment({timeout:!0});let l=new Z(`Connection timeout after ${Date.now()-i}ms`);n.emit("error",l)},p=()=>{this.log("connection opened %a",e),this.metrics?.events.increment({connect:!0}),b()},h=()=>{this.log("connection aborted %a",e),this.metrics?.events.increment({abort:!0}),b(new ge)},b=l=>{if(n.removeListener("error",d),n.removeListener("timeout",m),n.removeListener("connect",p),t.signal!=null&&t.signal.removeEventListener("abort",h),l!=null){s(l);return}o(n)};n.on("error",d),n.on("timeout",m),n.on("connect",p),t.signal!=null&&t.signal.addEventListener("abort",h)}).catch(o=>{throw n?.destroy(),o})}createListener(e){return new $e({...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:H.matches(t.decapsulateCode(421)))}dialFilter(e){return this.listenFilter(e)}};function Jo(r={}){return e=>new Oe(e,r)}return Hr(Qo);})();
2
+ "use strict";var Libp2PTcp=(()=>{var Rr=Object.create;var xe=Object.defineProperty;var jr=Object.getOwnPropertyDescriptor;var qr=Object.getOwnPropertyNames;var Wr=Object.getPrototypeOf,Gr=Object.prototype.hasOwnProperty;var F=(r=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(r,{get:(e,t)=>(typeof require<"u"?require:e)[t]}):r)(function(r){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+r+'" is not supported')});var D=(r,e)=>{for(var t in e)xe(r,t,{get:e[t],enumerable:!0})},Vt=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of qr(e))!Gr.call(r,o)&&o!==t&&xe(r,o,{get:()=>e[o],enumerable:!(n=jr(e,o))||n.enumerable});return r};var le=(r,e,t)=>(t=r!=null?Rr(Wr(r)):{},Vt(e||!r||!r.__esModule?xe(t,"default",{value:r,enumerable:!0}):t,r)),Hr=r=>Vt(xe({},"__esModule",{value:!0}),r);var Qo={};D(Qo,{tcp:()=>Jo});var _r=le(F("net"),1);var Bt=Symbol.for("@libp2p/transport");var zt;(function(r){r[r.FATAL_ALL=0]="FATAL_ALL",r[r.NO_FATAL=1]="NO_FATAL"})(zt||(zt={}));var ge=class extends Error{static name="AbortError";constructor(e="The operation was aborted"){super(e),this.name="AbortError"}};var V=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}};var Z=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 _t=F("node:events"),ve=(r,...e)=>{try{(0,_t.setMaxListeners)(r,...e)}catch{}};var ye=class extends EventTarget{#e=new Map;constructor(){super(),ve(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 Rt=Symbol.for("@libp2p/service-capabilities"),rs=Symbol.for("@libp2p/service-dependencies");var je={};D(je,{base58btc:()=>P,base58flickr:()=>Zr});var Cs=new Uint8Array(0);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}function k(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 qt(r){return new TextEncoder().encode(r)}function Wt(r){return new TextDecoder().decode(r)}function Jr(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,d=r.charAt(0),m=Math.log(a)/Math.log(256),p=Math.log(256)/Math.log(a);function h(f){if(f instanceof Uint8Array||(ArrayBuffer.isView(f)?f=new Uint8Array(f.buffer,f.byteOffset,f.byteLength):Array.isArray(f)&&(f=Uint8Array.from(f))),!(f instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(f.length===0)return"";for(var I=0,T=0,x=0,w=f.length;x!==w&&f[x]===0;)x++,I++;for(var L=(w-x)*p+1>>>0,M=new Uint8Array(L);x!==w;){for(var O=f[x],j=0,N=L-1;(O!==0||j<T)&&N!==-1;N--,j++)O+=256*M[N]>>>0,M[N]=O%a>>>0,O=O/a>>>0;if(O!==0)throw new Error("Non-zero carry");T=j,x++}for(var B=L-T;B!==L&&M[B]===0;)B++;for(var me=d.repeat(I);B<L;++B)me+=r.charAt(M[B]);return me}function b(f){if(typeof f!="string")throw new TypeError("Expected String");if(f.length===0)return new Uint8Array;var I=0;if(f[I]!==" "){for(var T=0,x=0;f[I]===d;)T++,I++;for(var w=(f.length-I)*m+1>>>0,L=new Uint8Array(w);f[I];){var M=t[f.charCodeAt(I)];if(M===255)return;for(var O=0,j=w-1;(M!==0||O<x)&&j!==-1;j--,O++)M+=a*L[j]>>>0,L[j]=M%256>>>0,M=M/256>>>0;if(M!==0)throw new Error("Non-zero carry");x=O,I++}if(f[I]!==" "){for(var N=w-x;N!==w&&L[N]===0;)N++;for(var B=new Uint8Array(T+(w-N)),me=T;N!==w;)B[me++]=L[N++];return B}}}function l(f){var I=b(f);if(I)return I;throw new Error(`Non-${e} character`)}return{encode:h,decodeUnsafe:b,decode:l}}var Qr=Jr,Xr=Qr,Ht=Xr;var ze=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")}},Be=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 Jt(this,e)}},_e=class{decoders;constructor(e){this.decoders=e}or(e){return Jt(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 Jt(r,e){return new _e({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var Re=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 ze(e,t,n),this.decoder=new Be(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function ee({name:r,prefix:e,encode:t,decode:n}){return new Re(r,e,t,n)}function q({name:r,prefix:e,alphabet:t}){let{encode:n,decode:o}=Ht(t,r);return ee({prefix:e,name:r,encode:n,decode:s=>k(o(s))})}function Kr(r,e,t,n){let o={};for(let p=0;p<e.length;++p)o[e[p]]=p;let s=r.length;for(;r[s-1]==="=";)--s;let i=new Uint8Array(s*t/8|0),a=0,d=0,m=0;for(let p=0;p<s;++p){let h=o[r[p]];if(h===void 0)throw new SyntaxError(`Non-${n} character`);d=d<<t|h,a+=t,a>=8&&(a-=8,i[m++]=255&d>>a)}if(a>=t||255&d<<8-a)throw new SyntaxError("Unexpected end of data");return i}function Yr(r,e,t){let n=e[e.length-1]==="=",o=(1<<t)-1,s="",i=0,a=0;for(let d=0;d<r.length;++d)for(a=a<<8|r[d],i+=8;i>t;)i-=t,s+=e[o&a>>i];if(i!==0&&(s+=e[o&a<<t-i]),n)for(;s.length*t&7;)s+="=";return s}function y({name:r,prefix:e,bitsPerChar:t,alphabet:n}){return ee({prefix:e,name:r,encode(o){return Yr(o,n,t)},decode(o){return Kr(o,n,t,r)}})}var P=q({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Zr=q({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var qe={};D(qe,{base32:()=>_,base32hex:()=>nn,base32hexpad:()=>sn,base32hexpadupper:()=>cn,base32hexupper:()=>on,base32pad:()=>tn,base32padupper:()=>rn,base32upper:()=>en,base32z:()=>an});var _=y({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),en=y({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),tn=y({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),rn=y({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),nn=y({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),on=y({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),sn=y({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),cn=y({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),an=y({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var We={};D(We,{base36:()=>ue,base36upper:()=>ln});var ue=q({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),ln=q({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var un=Kt,Qt=128,dn=127,pn=~dn,fn=Math.pow(2,31);function Kt(r,e,t){e=e||[],t=t||0;for(var n=t;r>=fn;)e[t++]=r&255|Qt,r/=128;for(;r&pn;)e[t++]=r&255|Qt,r>>>=7;return e[t]=r|0,Kt.bytes=t-n+1,e}var hn=Ge,mn=128,Xt=127;function Ge(r,n){var t=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw Ge.bytes=0,new RangeError("Could not decode varint");i=r[s++],t+=o<28?(i&Xt)<<o:(i&Xt)*Math.pow(2,o),o+=7}while(i>=mn);return Ge.bytes=s-n,t}var xn=Math.pow(2,7),gn=Math.pow(2,14),wn=Math.pow(2,21),bn=Math.pow(2,28),vn=Math.pow(2,35),yn=Math.pow(2,42),En=Math.pow(2,49),In=Math.pow(2,56),An=Math.pow(2,63),Cn=function(r){return r<xn?1:r<gn?2:r<wn?3:r<bn?4:r<vn?5:r<yn?6:r<En?7:r<In?8:r<An?9:10},Tn={encode:un,decode:hn,encodingLength:Cn},Sn=Tn,de=Sn;function pe(r,e=0){return[de.decode(r,e),de.decode.bytes]}function te(r,e,t=0){return de.encode(r,e,t),e}function re(r){return de.encodingLength(r)}function J(r,e){let t=e.byteLength,n=re(r),o=n+re(t),s=new Uint8Array(o+t);return te(r,s,0),te(t,s,n),s.set(e,o),new ne(r,t,e,s)}function Ie(r){let e=k(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 ne(t,o,i,e)}function Yt(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&jt(r.bytes,t.bytes)}}var ne=class{code;size;digest;bytes;constructor(e,t,n,o){this.code=e,this.size=t,this.digest=n,this.bytes=o}};function Zt(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return Ln(t,He(r),e??P.encoder);default:return Dn(t,He(r),e??_.encoder)}}var er=new WeakMap;function He(r){let e=er.get(r);if(e==null){let t=new Map;return er.set(r,t),t}return e}var W=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!==Mn)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=J(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&&Yt(e.multihash,n.multihash)}toString(e){return Zt(this,e)}toJSON(){return{"/":Zt(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??tr(n,o,s.bytes))}else if(t[kn]===!0){let{version:n,multihash:o,code:s}=t,i=Ie(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=tr(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=k(e.subarray(n,n+t.multihashSize));if(o.byteLength!==t.multihashSize)throw new Error("Incorrect length");let s=o.subarray(t.multihashSize-t.digestSize),i=new ne(t.multihashCode,t.digestSize,s,o);return[t.version===0?r.createV0(i):r.createV1(t.codec,i),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[h,b]=pe(e.subarray(t));return t+=b,h},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(),d=n(),m=t+d,p=m-i;return{version:o,codec:s,multihashCode:a,digestSize:d,multihashSize:p,size:m}}static parse(e,t){let[n,o]=Pn(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 He(s).set(n,e),s}};function Pn(r,e){switch(r[0]){case"Q":{let t=e??P;return[P.prefix,t.decode(`${P.prefix}${r}`)]}case P.prefix:{let t=e??P;return[P.prefix,t.decode(r)]}case _.prefix:{let t=e??_;return[_.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 Ln(r,e,t){let{prefix:n}=t;if(n!==P.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let o=e.get(n);if(o==null){let s=t.encode(r).slice(1);return e.set(n,s),s}else return o}function Dn(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,Mn=18;function tr(r,e,t){let n=re(r),o=n+re(e),s=new Uint8Array(o+t.byteLength);return te(r,s,0),te(e,s,n),s.set(t,o),s}var kn=Symbol.for("@ipld/js-cid/CID");function rr(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}var ur=F("node:buffer");var Je={};D(Je,{base10:()=>Un});var Un=q({prefix:"9",name:"base10",alphabet:"0123456789"});var Qe={};D(Qe,{base16:()=>Nn,base16upper:()=>Fn});var Nn=y({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Fn=y({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Xe={};D(Xe,{base2:()=>$n});var $n=y({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Ke={};D(Ke,{base256emoji:()=>_n});var nr=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}"),On=nr.reduce((r,e,t)=>(r[t]=e,r),[]),Vn=nr.reduce((r,e,t)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return r[n]=t,r},[]);function zn(r){return r.reduce((e,t)=>(e+=On[t],e),"")}function Bn(r){let e=[];for(let t of r){let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);let o=Vn[n];if(o==null)throw new Error(`Non-base256emoji character: ${t}`);e.push(o)}return new Uint8Array(e)}var _n=ee({prefix:"\u{1F680}",name:"base256emoji",encode:zn,decode:Bn});var Ye={};D(Ye,{base64:()=>Rn,base64pad:()=>jn,base64url:()=>qn,base64urlpad:()=>Wn});var Rn=y({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),jn=y({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),qn=y({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Wn=y({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Ze={};D(Ze,{base8:()=>Gn});var Gn=y({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var et={};D(et,{identity:()=>Hn});var Hn=ee({prefix:"\0",name:"identity",encode:r=>Wt(r),decode:r=>qt(r)});var Ks=new TextEncoder,Ys=new TextDecoder;var tt={};D(tt,{identity:()=>Yn});var or=0,Xn="identity",sr=k;function Kn(r){return J(or,sr(r))}var Yn={code:or,name:Xn,encode:sr,digest:Kn};var st={};D(st,{sha256:()=>Zn,sha512:()=>eo});var ot=le(F("crypto"),1);function nt({name:r,code:e,encode:t}){return new rt(r,e,t)}var rt=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?J(this.code,t):t.then(n=>J(this.code,n))}else throw Error("Unknown type, must be binary type")}};var Zn=nt({name:"sha2-256",code:18,encode:r=>k(ot.default.createHash("sha256").update(r).digest())}),eo=nt({name:"sha2-512",code:19,encode:r=>k(ot.default.createHash("sha512").update(r).digest())});var he={...et,...Xe,...Ze,...Je,...Qe,...qe,...We,...je,...Ye,...Ke},pi={...st,...tt};var cr=F("node:buffer");function se(r){return new Uint8Array(r.buffer,r.byteOffset,r.byteLength)}function Ae(r=0){return se(cr.Buffer.allocUnsafe(r))}function lr(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var ar=lr("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),it=lr("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}),to={utf8:ar,"utf-8":ar,hex:he.base16,latin1:it,ascii:it,binary:it,...he},Ce=to;function S(r,e="utf8"){let t=Ce[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return e==="utf8"||e==="utf-8"?ur.Buffer.from(r.buffer,r.byteOffset,r.byteLength).toString("utf8"):t.encoder.encode(r).substring(1)}var ro=Math.pow(2,7),no=Math.pow(2,14),oo=Math.pow(2,21),ct=Math.pow(2,28),at=Math.pow(2,35),lt=Math.pow(2,42),ut=Math.pow(2,49),g=128,C=127;function z(r){if(r<ro)return 1;if(r<no)return 2;if(r<oo)return 3;if(r<ct)return 4;if(r<at)return 5;if(r<lt)return 6;if(r<ut)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function so(r,e,t=0){switch(z(r)){case 8:e[t++]=r&255|g,r/=128;case 7:e[t++]=r&255|g,r/=128;case 6:e[t++]=r&255|g,r/=128;case 5:e[t++]=r&255|g,r/=128;case 4:e[t++]=r&255|g,r>>>=7;case 3:e[t++]=r&255|g,r>>>=7;case 2:e[t++]=r&255|g,r>>>=7;case 1:{e[t++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return e}function io(r,e,t=0){switch(z(r)){case 8:e.set(t++,r&255|g),r/=128;case 7:e.set(t++,r&255|g),r/=128;case 6:e.set(t++,r&255|g),r/=128;case 5:e.set(t++,r&255|g),r/=128;case 4:e.set(t++,r&255|g),r>>>=7;case 3:e.set(t++,r&255|g),r>>>=7;case 2:e.set(t++,r&255|g),r>>>=7;case 1:{e.set(t++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return e}function co(r,e){let t=r[e],n=0;if(n+=t&C,t<g||(t=r[e+1],n+=(t&C)<<7,t<g)||(t=r[e+2],n+=(t&C)<<14,t<g)||(t=r[e+3],n+=(t&C)<<21,t<g)||(t=r[e+4],n+=(t&C)*ct,t<g)||(t=r[e+5],n+=(t&C)*at,t<g)||(t=r[e+6],n+=(t&C)*lt,t<g)||(t=r[e+7],n+=(t&C)*ut,t<g))return n;throw new RangeError("Could not decode varint")}function ao(r,e){let t=r.get(e),n=0;if(n+=t&C,t<g||(t=r.get(e+1),n+=(t&C)<<7,t<g)||(t=r.get(e+2),n+=(t&C)<<14,t<g)||(t=r.get(e+3),n+=(t&C)<<21,t<g)||(t=r.get(e+4),n+=(t&C)*ct,t<g)||(t=r.get(e+5),n+=(t&C)*at,t<g)||(t=r.get(e+6),n+=(t&C)*lt,t<g)||(t=r.get(e+7),n+=(t&C)*ut,t<g))return n;throw new RangeError("Could not decode varint")}function ie(r,e,t=0){return e==null&&(e=Ae(z(r))),e instanceof Uint8Array?so(r,e,t):io(r,e,t)}function Q(r,e=0){return r instanceof Uint8Array?co(r,e):ao(r,e)}var pr=F("node:buffer");function R(r,e){return se(pr.Buffer.concat(r,e))}var Te=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 d=a==="0",m=2**(8*o)-1;for(;;){let p=this.readAtomically(()=>{let h=this.readChar();if(h===void 0)return;let b=Number.parseInt(h,e);if(!Number.isNaN(b))return b});if(p===void 0)break;if(s*=e,s+=p,s>m||(i+=1,t!==void 0&&i>t))return}if(i!==0)return!n&&d&&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 Si=new Te;var Fi=parseInt("0xFFFF",16),$i=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);var mr=F("node:buffer");function Se(r,e="utf8"){let t=Ce[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return e==="utf8"||e==="utf-8"?se(mr.Buffer.from(r,"utf-8")):t.decoder.decode(`${t.prefix}${r}`)}var U=F("node:net");function Pe(r){return!!(0,U.isIP)(r)}var xr=U.isIPv4,mo=U.isIPv6,dt=function(r){let e=0;if(r=r.toString().trim(),xr(r)){let t=new Uint8Array(e+4);return r.split(/\./g).forEach(n=>{t[e++]=parseInt(n,10)&255}),t}if(mo(r)){let t=r.split(":",8),n;for(n=0;n<t.length;n++){let s=xr(t[n]),i;s&&(i=dt(t[n]),t[n]=S(i.slice(0,2),"base16")),i!=null&&++n<8&&t.splice(n,0,S(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")},gr=function(r,e=0,t){e=~~e,t=t??r.length-e;let n=new DataView(r.buffer);if(t===4){let o=[];for(let s=0;s<t;s++)o.push(r[e+s]);return o.join(".")}if(t===16){let o=[];for(let s=0;s<t;s+=2)o.push(n.getUint16(e+s).toString(16));return o.join(":").replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}return""};var ce={},pt={},go=[[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"]];go.forEach(r=>{let e=wo(...r);pt[e.code]=e,ce[e.name]=e});function wo(r,e,t,n,o){return{code:r,size:e,name:t,resolvable:!!n,path:!!o}}function v(r){if(typeof r=="number"){if(pt[r]!=null)return pt[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(ce[r]!=null)return ce[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var Ic=v("ip4"),Ac=v("ip6"),Cc=v("ipcidr");function xt(r,e){switch(v(r).code){case 4:case 41:return vo(e);case 42:return mt(e);case 43:return S(e,"base10");case 6:case 273:case 33:case 132:return vr(e).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return mt(e);case 421:return Ao(e);case 444:return br(e);case 445:return br(e);case 466:return Io(e);case 481:return globalThis.encodeURIComponent(mt(e));default:return S(e,"base16")}}function gt(r,e){switch(v(r).code){case 4:return wr(e);case 41:return wr(e);case 42:return ht(e);case 43:return Se(e,"base10");case 6:case 273:case 33:case 132:return wt(parseInt(e,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return ht(e);case 421:return yo(e);case 444:return Co(e);case 445:return To(e);case 466:return Eo(e);case 481:return ht(globalThis.decodeURIComponent(e));default:return Se(e,"base16")}}var ft=Object.values(he).map(r=>r.decoder),bo=function(){let r=ft[0].or(ft[1]);return ft.slice(2).forEach(e=>r=r.or(e)),r}();function wr(r){if(!Pe(r))throw new Error("invalid ip address");return dt(r)}function vo(r){let e=gr(r,0,r.length);if(e==null)throw new Error("ipBuff is required");if(!Pe(e))throw new Error("invalid ip address");return e}function wt(r){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,r),new Uint8Array(e)}function vr(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function ht(r){let e=Se(r),t=Uint8Array.from(ie(e.length));return R([t,e],t.length+e.length)}function mt(r){let e=Q(r);if(r=r.slice(z(e)),r.length!==e)throw new Error("inconsistent lengths");return S(r)}function yo(r){let e;r[0]==="Q"||r[0]==="1"?e=Ie(P.decode(`z${r}`)).bytes:e=W.parse(r).multihash.bytes;let t=Uint8Array.from(ie(e.length));return R([t,e],t.length+e.length)}function Eo(r){let e=bo.decode(r),t=Uint8Array.from(ie(e.length));return R([t,e],t.length+e.length)}function Io(r){let e=Q(r),t=r.slice(z(e));if(t.length!==e)throw new Error("inconsistent lengths");return"u"+S(t,"base64url")}function Ao(r){let e=Q(r),t=r.slice(z(e));if(t.length!==e)throw new Error("inconsistent lengths");return S(t,"base58btc")}function Co(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=_.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=wt(n);return R([t,o],t.length+o.length)}function To(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=_.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=wt(n);return R([t,o],t.length+o.length)}function br(r){let e=r.slice(0,r.length-2),t=r.slice(r.length-2),n=S(e,"base32"),o=vr(t);return`${n}:${o}`}function yr(r){r=bt(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=v(i);if(a.size===0){e.push([a.code]),t.push([a.code]);continue}if(s++,s>=o.length)throw new Le("invalid address: "+r);if(a.path===!0){n=bt(o.slice(s).join("/")),e.push([a.code,gt(a.code,n)]),t.push([a.code,n]);break}let d=gt(a.code,o[s]);e.push([a.code,d]),t.push([a.code,xt(a.code,d)])}return{string:Er(t),bytes:yt(e),tuples:e,stringTuples:t,path:n}}function vt(r){let e=[],t=[],n=null,o=0;for(;o<r.length;){let s=Q(r,o),i=z(s),a=v(s),d=So(a,r.slice(o+i));if(d===0){e.push([s]),t.push([s]),o+=i;continue}let m=r.slice(o+i,o+i+d);if(o+=d+i,o>r.length)throw new Le("Invalid address Uint8Array: "+S(r,"base16"));e.push([s,m]);let p=xt(s,m);if(t.push([s,p]),a.path===!0){n=p;break}}return{bytes:Uint8Array.from(r),string:Er(t),tuples:e,stringTuples:t,path:n}}function Er(r){let e=[];return r.map(t=>{let n=v(t[0]);return e.push(n.name),t.length>1&&t[1]!=null&&e.push(t[1]),null}),bt(e.join("/"))}function yt(r){return R(r.map(e=>{let t=v(e[0]),n=Uint8Array.from(ie(t.code));return e.length>1&&e[1]!=null&&(n=R([n,e[1]])),n}))}function So(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+z(t)}}function bt(r){return"/"+r.trim().split("/").filter(e=>e).join("/")}var Le=class extends Error{static name="ParseError";name="ParseError";constructor(e){super(`Error parsing address: ${e}`)}};var Po=Symbol.for("nodejs.util.inspect.custom"),It=Symbol.for("@multiformats/js-multiaddr/multiaddr"),Lo=[v("dns").code,v("dns4").code,v("dns6").code,v("dnsaddr").code],Et=class extends Error{constructor(e="No available resolver"){super(e),this.name="NoAvailableResolverError"}},De=class r{bytes;#e;#t;#r;#n;[It]=!0;constructor(e){e==null&&(e="");let t;if(e instanceof Uint8Array)t=vt(e);else if(typeof e=="string"){if(e.length>0&&e.charAt(0)!=="/")throw new Error(`multiaddr "${e}" must start with a "/"`);t=yr(e)}else if(Ar(e))t=vt(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=v("tcp"),a=v("udp"),d=v("ip4"),m=v("ip6"),p=v("dns6"),h=v("ip6zone");for(let[l,f]of this.stringTuples())l===h.code&&(s=`%${f??""}`),Lo.includes(l)&&(t=i.name==="tcp"?"tcp":"udp",o=443,n=`${f??""}${s}`,e=l===p.code?6:4),(l===i.code||l===a.code)&&(t=v(l).name==="tcp"?"tcp":"udp",o=parseInt(f??"")),(l===d.code||l===m.code)&&(t=v(l).name==="tcp"?"tcp":"udp",n=`${f??""}${s}`,e=l===m.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({},v(e)))}protoCodes(){return this.#t.map(([e])=>e)}protoNames(){return this.#t.map(([e])=>v(e).name)}tuples(){return this.#t.map(([e,t])=>t==null?[e]:[e,t])}stringTuples(){return this.#r.map(([e,t])=>t==null?[e]:[e,t])}encapsulate(e){return e=new r(e),new r(this.toString()+e.toString())}decapsulate(e){let t=e.toString(),n=this.toString(),o=n.lastIndexOf(t);if(o<0)throw new Error(`Address ${this.toString()} does not contain subaddress: ${e.toString()}`);return new r(n.slice(0,o))}decapsulateCode(e){let t=this.tuples();for(let n=t.length-1;n>=0;n--)if(t[n][0]===e)return new r(yt(t.slice(0,n)));return this}getPeerId(){try{let e=[];this.stringTuples().forEach(([n,o])=>{n===ce.p2p.code&&e.push([n,o]),n===ce["p2p-circuit"].code&&(e=[])});let t=e.pop();if(t?.[1]!=null){let n=t[1];return n[0]==="Q"||n[0]==="1"?S(P.decode(`z${n}`),"base58btc"):S(W.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){return this.#n}equals(e){return rr(this.bytes,e.bytes)}async resolve(e){let t=this.protos().find(s=>s.resolvable);if(t==null)return[this];let n=Ir.get(t.name);if(n==null)throw new Et(`no available resolver for ${t.name}`);return(await n(this,e)).map(s=>$(s))}nodeAddress(){let e=this.toOptions();if(e.transport!=="tcp"&&e.transport!=="udp")throw new Error(`multiaddr must have a valid format - no protocol with name: "${e.transport}". Must have a valid transport protocol: "{tcp, udp}"`);return{family:e.family,address:e.host,port:e.port}}isThinWaistAddress(e){let t=(e??this).protos();return!(t.length!==2||t[0].code!==4&&t[0].code!==41||t[1].code!==6&&t[1].code!==273)}[Po](){return`Multiaddr(${this.#e})`}};var Ir=new Map;function Ar(r){return!!r?.[It]}function $(r){return new De(r)}var Do=c("dns4"),Mo=c("dns6"),ko=c("dnsaddr"),K=E(c("dns"),ko,Do,Mo),Ue=E(c("ip4"),c("ip6")),H=E(u(Ue,c("tcp")),u(K,c("tcp"))),Ne=u(Ue,c("udp")),Uo=u(Ne,c("utp")),No=u(Ne,c("quic")),Fo=u(Ne,c("quic-v1")),At=E(u(H,c("ws")),u(K,c("ws"))),Me=E(u(At,c("p2p")),At),Ct=E(u(H,c("wss")),u(K,c("wss")),u(H,c("tls"),c("ws")),u(K,c("tls"),c("ws"))),ke=E(u(Ct,c("p2p")),Ct),Tt=E(u(H,c("http")),u(Ue,c("http")),u(K,c("http"))),St=E(u(H,c("https")),u(Ue,c("https")),u(K,c("https"))),Cr=u(Ne,c("webrtc-direct"),c("certhash")),Pr=E(u(Cr,c("p2p")),Cr),Tr=u(Fo,c("webtransport"),c("certhash"),c("certhash")),Lr=E(u(Tr,c("p2p")),Tr),Dr=E(u(Me,c("p2p-webrtc-star"),c("p2p")),u(ke,c("p2p-webrtc-star"),c("p2p")),u(Me,c("p2p-webrtc-star")),u(ke,c("p2p-webrtc-star"))),Xc=E(u(Me,c("p2p-websocket-star"),c("p2p")),u(ke,c("p2p-websocket-star"),c("p2p")),u(Me,c("p2p-websocket-star")),u(ke,c("p2p-websocket-star"))),Mr=E(u(Tt,c("p2p-webrtc-direct"),c("p2p")),u(St,c("p2p-webrtc-direct"),c("p2p")),u(Tt,c("p2p-webrtc-direct")),u(St,c("p2p-webrtc-direct"))),Y=E(At,Ct,Tt,St,Dr,Mr,H,Uo,No,K,Pr,Lr),Kc=E(u(Y,c("p2p-stardust"),c("p2p")),u(Y,c("p2p-stardust"))),G=E(u(Y,c("p2p")),Dr,Mr,Pr,Lr,c("p2p")),Sr=E(u(G,c("p2p-circuit"),G),u(G,c("p2p-circuit")),u(c("p2p-circuit"),G),u(Y,c("p2p-circuit")),u(c("p2p-circuit"),Y),c("p2p-circuit")),kr=()=>E(u(Sr,kr),Sr),X=kr(),Yc=E(u(X,G,X),u(G,X),u(X,G),X,G);var Zc=E(u(X,c("webrtc"),c("p2p")),u(X,c("webrtc")),u(Y,c("webrtc"),c("p2p")),u(Y,c("webrtc")),c("webrtc"));function Ur(r){function e(t){let n;try{n=$(t)}catch{return!1}let o=r(n.protoNames());return o===null?!1:o===!0||o===!1?o:o.length===0}return e}function u(...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:Ur(e),partialMatch:e}}function E(...r){function e(n){let o=null;return r.some(s=>{let i=typeof s=="function"?s().partialMatch(n):s.partialMatch(n);return i!=null?(o=i,!0):!1}),o}return{toString:function(){return"{ "+r.join(" ")+" }"},input:r,matches:Ur(e),partialMatch:e}}function c(r){let e=r;function t(o){let s;try{s=$(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 Fe=class extends Event{type;detail;constructor(e,t){super(e),this.type=e,this.detail=t}};var Br=le(F("net"),1);var Pt=class extends Error{constructor(e){super(e),this.name="TimeoutError"}},Lt=class extends Error{constructor(e){super(),this.name="AbortError",this.message=e}},Nr=r=>globalThis.DOMException===void 0?new Lt(r):new DOMException(r),Fr=r=>{let e=r.reason===void 0?Nr("This operation was aborted."):r.reason;return e instanceof Error?e:Nr(e)};function Dt(r,e){let{milliseconds:t,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout}}=e,i,a,m=new Promise((p,h)=>{if(typeof t!="number"||Math.sign(t)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${t}\``);if(e.signal){let{signal:l}=e;l.aborted&&h(Fr(l)),a=()=>{h(Fr(l))},l.addEventListener("abort",a,{once:!0})}if(t===Number.POSITIVE_INFINITY){r.then(p,h);return}let b=new Pt;i=s.setTimeout.call(void 0,()=>{if(n){try{p(n())}catch(l){h(l)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?p():o instanceof Error?h(o):(b.message=o??`Promise timed out after ${t} milliseconds`,h(b))},t),(async()=>{try{p(await r)}catch(l){h(l)}})()}).finally(()=>{m.clear(),a&&e.signal&&e.signal.removeEventListener("abort",a)});return m.clear=()=>{s.clearTimeout.call(void 0,i),i=void 0},m}var Oo=r=>{let e=r.addEventListener||r.on||r.addListener,t=r.removeEventListener||r.off||r.removeListener;if(!e||!t)throw new TypeError("Emitter is not compatible");return{addListener:e.bind(r),removeListener:t.bind(r)}};function Vo(r,e,t){let n,o=new Promise((s,i)=>{if(t={rejectionEvents:["error"],multiArgs:!1,resolveImmediately:!1,...t},!(t.count>=0&&(t.count===Number.POSITIVE_INFINITY||Number.isInteger(t.count))))throw new TypeError("The `count` option should be at least 0 or more");t.signal?.throwIfAborted();let a=[e].flat(),d=[],{addListener:m,removeListener:p}=Oo(r),h=(...l)=>{let f=t.multiArgs?l:l[0];t.filter&&!t.filter(f)||(d.push(f),t.count===d.length&&(n(),s(d)))},b=l=>{n(),i(l)};n=()=>{for(let l of a)p(l,h);for(let l of t.rejectionEvents)p(l,b)};for(let l of a)m(l,h);for(let l of t.rejectionEvents)m(l,b);t.signal&&t.signal.addEventListener("abort",()=>{b(t.signal.reason)},{once:!0}),t.resolveImmediately&&s(d)});if(o.cancel=n,typeof t.timeout=="number"){let s=Dt(o,{milliseconds:t.timeout});return s.cancel=n,s}return o}function Mt(r,e,t){typeof t=="function"&&(t={filter:t}),t={...t,count:1,resolveImmediately:!1};let n=Vo(r,e,t),o=n.then(s=>s[0]);return o.cancel=n.cancel,o}function $r(r,e){if(typeof r!="string")throw new V(`invalid ip provided: ${r}`);if(typeof e=="string"&&(e=parseInt(e)),isNaN(e))throw new V(`invalid port provided: ${e}`);if((0,U.isIPv4)(r))return $(`/ip4/${r}/tcp/${e}`);if((0,U.isIPv6)(r))return $(`/ip6/${r}/tcp/${e}`);throw new V(`invalid ip:port for creating a multiaddr: ${r}:${e}`)}function kt(){let r={};return r.promise=new Promise((e,t)=>{r.resolve=e,r.reject=t}),r}var Ut=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.name="AbortError",this.code=t??"ABORT_ERR"}};async function Nt(r,e,t,n){let o=new Ut(n?.errorMessage,n?.errorCode);return t?.aborted===!0?Promise.reject(o):new Promise((s,i)=>{function a(){t?.removeEventListener("abort",p),r.removeEventListener(e,d),n?.errorEvent!=null&&r.removeEventListener(n.errorEvent,m)}let d=h=>{try{if(n?.filter?.(h)===!1)return}catch(b){a(),i(b);return}a(),s(h)},m=h=>{a(),i(h.detail)},p=()=>{a(),i(o)};t?.addEventListener("abort",p),r.addEventListener(e,d),n?.errorEvent!=null&&r.addEventListener(n.errorEvent,m)})}function Or(r){if(Bo(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(zo(r))return r;throw new Error("unknown stream")}function zo(r){return r[Symbol.asyncIterator]!=null}function Bo(r){return typeof r?.getReader=="function"}function Vr(r){return async e=>{let t=async()=>{_o(e)&&await e.return(void 0)},n,o,s=x=>{n=x,t().catch(w=>{w=new AggregateError([n,w],"The Writable emitted an error, additionally an error occurred while ending the Source")}).finally(()=>{o?.(x)})},i,a=!1,d=()=>{a=!0,i?.()},m,p=!1,h=()=>{p=!0,m?.()},b,l=()=>{b?.()},f=async()=>new Promise((x,w)=>{i=b=x,o=w,r.once("drain",l)}),I=async()=>(await t(),new Promise((x,w)=>{if(a||p||n!=null){x();return}m=i=x,o=w})),T=()=>{r.removeListener("error",s),r.removeListener("close",d),r.removeListener("finish",h),r.removeListener("drain",l)};r.once("error",s),r.once("close",d),r.once("finish",h);try{for await(let x of e){if(!r.writable||r.destroyed||n!=null)break;r.write(x)||await f()}}catch(x){n==null&&r.destroy(x),n=x}try{if(r.writable&&r.end(),await I(),n!=null)throw n}finally{T()}}}function _o(r){return r.return!=null}function Ft(r){return{sink:Vr(r),source:Or(r)}}var $t=le(F("os"),1),zr=le(F("path"),1);var Ro={ip4:"IPv4",ip6:"IPv6"};function ae(r,e={}){let t=r.getPath();return t!=null?$t.default.platform()==="win32"?{path:zr.default.join("\\\\.\\pipe\\",t)}:{path:t}:{...e,...r.toOptions()}}function Ot(r,e,t){let n=o=>$(`/${r}/${o}/tcp/${t}`);return(jo(e)?Wo(Ro[r]):[e]).map(n)}function jo(r){return["0.0.0.0","::"].includes(r)}var qo=$t.default.networkInterfaces();function Wo(r){let e=[];for(let[,t]of Object.entries(qo))if(t!=null)for(let n of t)n.family===r&&e.push(n.address);return e}var $e=(r,e)=>{let t,n=e.logger.forComponent("libp2p:tcp:socket"),o=e.direction,s=e.metrics,i=e.metricPrefix??"",a=e.socketInactivityTimeout??12e4,d=e.socketCloseTimeout??500,m=!1,p=!1;e.listeningAddr?.getPath()!=null&&(e.remoteAddr=e.listeningAddr),e.remoteAddr?.getPath()!=null&&(e.localAddr=e.remoteAddr),r.on("error",x=>{p=!0,m||(n.error("%s socket error - %e",o,x),s?.increment({[`${i}error`]:!0})),r.destroy(),T.timeline.close=Date.now()});let h;if(e.remoteAddr!=null)h=e.remoteAddr;else{if(r.remoteAddress==null||r.remotePort==null)throw new V("Could not determine remote address or port");h=$r(r.remoteAddress,r.remotePort)}let b=ae(h),l=b.path??`${b.host??""}:${b.port??""}`,{sink:f,source:I}=Ft(r);r.setTimeout(a),r.once("timeout",()=>{m=!0,n("%s %s socket read timeout",o,l),s?.increment({[`${i}timeout`]:!0}),r.destroy(new Z),T.timeline.close=Date.now()}),r.once("close",()=>{!m&&!p&&(n("%s %s socket close",o,l),s?.increment({[`${i}close`]:!0})),r.destroy(),T.timeline.close=Date.now()}),r.once("end",()=>{n("%s %s socket end",o,l),s?.increment({[`${i}end`]:!0})});let T={async sink(x){try{await f(async function*(){for await(let w of x)w instanceof Uint8Array?yield w:yield w.subarray()}())}catch(w){w.type!=="aborted"&&n.error("%s %s error in sink - %e",o,l,w)}r.end()},source:I,remoteAddr:h,timeline:{open:Date.now()},async close(x={}){if(r.closed){n("the %s %s socket is already closed",o,l);return}if(r.destroyed){n("the %s %s socket is already destroyed",o,l);return}if(t!=null)return t.promise;try{t=kt(),r.end();let w=Go(r),L=x.signal??AbortSignal.timeout(d);r.writableLength>0&&(n("%s %s draining socket",o,l),await Nt(w,"drain",L,{errorEvent:"error"}),n("%s %s socket drained",o,l)),await Promise.all([Nt(w,"close",L,{errorEvent:"error"}),r.destroy()])}catch(w){this.abort(w)}finally{t.resolve()}},abort:x=>{n("%s %s socket abort due to error - %e",o,l,x),r.destroy(),T.timeline.close=Date.now()},log:n};return T};function Go(r){return{addEventListener:(t,n)=>{r.addListener(t,n)},removeEventListener:(t,n)=>{r.removeListener(t,n)}}}var A;(function(r){r[r.INACTIVE=0]="INACTIVE",r[r.ACTIVE=1]="ACTIVE",r[r.PAUSED=2]="PAUSED"})(A||(A={}));var Oe=class extends ye{context;server;sockets=new Set;status={code:A.INACTIVE};metrics;addr;log;shutdownController;constructor(e){if(super(),this.context=e,e.keepAlive=e.keepAlive??!0,e.noDelay=e.noDelay??!0,this.shutdownController=new AbortController,ve(1/0,this.shutdownController.signal),this.log=e.logger.forComponent("libp2p:tcp:listener"),this.addr="unknown",this.server=Br.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 V("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.sockets.size})}),this.metrics={status:e.metrics.registerMetricGroup("libp2p_tcp_listener_status_info",{label:"address",help:"Current status of the TCP listener socket"}),errors:e.metrics.registerMetricGroup("libp2p_tcp_listener_errors_total",{label:"address",help:"Total count of TCP listener errors by type"}),events:e.metrics.registerMetricGroup("libp2p_tcp_listener_events_total",{label:"address",help:"Total count of TCP listener events by type"})},this.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")}).on("drop",()=>{this.metrics?.events.increment({[`${this.addr} drop`]:!0})})}onSocket(e){if(this.metrics?.events.increment({[`${this.addr} connection`]:!0}),this.status.code!==A.ACTIVE)throw e.destroy(),new we("Server is not listening yet");let t;try{t=$e(e,{listeningAddr:this.status.listeningAddr,socketInactivityTimeout:this.context.socketInactivityTimeout,socketCloseTimeout:this.context.socketCloseTimeout,metrics:this.metrics?.events,metricPrefix:`${this.addr} `,logger:this.context.logger,direction:"inbound"})}catch(n){this.log.error("inbound connection failed",n),this.metrics?.errors.increment({[`${this.addr} inbound_to_connection`]:!0}),e.destroy();return}this.log("new inbound connection %s",t.remoteAddr),this.sockets.add(e),this.context.upgrader.upgradeInbound(t,{signal:this.shutdownController.signal}).then(()=>{this.log("inbound connection upgraded %s",t.remoteAddr),e.once("close",()=>{this.sockets.delete(e),this.context.closeServerOnMaxConnections!=null&&this.sockets.size<this.context.closeServerOnMaxConnections.listenBelow&&this.resume().catch(n=>{this.log.error("error attempting to listen server once connection count under limit",n),this.context.closeServerOnMaxConnections?.onListenError?.(n)})}),this.context.closeServerOnMaxConnections!=null&&this.sockets.size>=this.context.closeServerOnMaxConnections.closeAbove&&this.pause()}).catch(async n=>{this.log.error("inbound connection upgrade failed",n),this.metrics?.errors.increment({[`${this.addr} inbound_upgrade`]:!0}),this.sockets.delete(e),t.abort(n)})}getAddrs(){if(this.status.code===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(Ot("ip4",t.address,t.port)):t.family==="IPv6"&&(e=e.concat(Ot("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:ae(n,{backlog:o})},await this.resume()}catch(s){throw this.status={code:A.INACTIVE},s}}async close(){let e=[];this.server.listening&&e.push(Mt(this.server,"close")),this.pause(!0),this.shutdownController.abort(),this.sockets.forEach(t=>{t.readable&&(e.push(Mt(t,"close")),t.destroy())}),await Promise.all(e)}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())}pause(e=!1){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},this.server.close())}};var Ve=class{opts;metrics;components;log;constructor(e,t={}){this.log=e.logger.forComponent("libp2p:tcp"),this.opts=t,this.components=e,e.metrics!=null&&(this.metrics={events:e.metrics.registerCounterGroup("libp2p_tcp_dialer_events_total",{label:"event",help:"Total count of TCP dialer events by type"}),errors:e.metrics.registerCounterGroup("libp2p_tcp_dialer_errors_total",{label:"event",help:"Total count of TCP dialer events by type"})})}[Bt]=!0;[Symbol.toStringTag]="@libp2p/tcp";[Rt]=["@libp2p/transport"];async dial(e,t){t.keepAlive=t.keepAlive??!0,t.noDelay=t.noDelay??!0;let n=await this._connect(e,t),o;try{o=$e(n,{remoteAddr:e,socketInactivityTimeout:this.opts.outboundSocketInactivityTimeout,socketCloseTimeout:this.opts.socketCloseTimeout,metrics:this.metrics?.events,logger:this.components.logger,direction:"outbound"})}catch(s){throw this.metrics?.errors.increment({outbound_to_connection:!0}),n.destroy(s),s}try{return this.log("new outbound connection %s",o.remoteAddr),await t.upgrader.upgradeOutbound(o,t)}catch(s){throw this.metrics?.errors.increment({outbound_upgrade:!0}),this.log.error("error upgrading outbound connection",s),o.abort(s),s}}async _connect(e,t){t.signal?.throwIfAborted(),t.onProgress?.(new Fe("tcp:open-connection"));let n;return new Promise((o,s)=>{let i=Date.now(),a=ae(e,{...this.opts.dialOpts??{},...t});this.log("dialing %a",e),n=_r.default.connect(a);let d=l=>{this.log.error("dial to %a errored - %e",e,l);let f=a.path??`${a.host??""}:${a.port}`;l.message=`connection error ${f}: ${l.message}`,this.metrics?.events.increment({error:!0}),b(l)},m=()=>{this.log("connection timeout %a",e),this.metrics?.events.increment({timeout:!0});let l=new Z(`Connection timeout after ${Date.now()-i}ms`);n.emit("error",l)},p=()=>{this.log("connection opened %a",e),this.metrics?.events.increment({connect:!0}),b()},h=()=>{this.log("connection aborted %a",e),this.metrics?.events.increment({abort:!0}),b(new ge)},b=l=>{if(n.removeListener("error",d),n.removeListener("timeout",m),n.removeListener("connect",p),t.signal!=null&&t.signal.removeEventListener("abort",h),l!=null){s(l);return}o(n)};n.on("error",d),n.on("timeout",m),n.on("connect",p),t.signal!=null&&t.signal.addEventListener("abort",h)}).catch(o=>{throw n?.destroy(),o})}createListener(e){return new Oe({...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:H.matches(t.decapsulateCode(421)))}dialFilter(e){return this.listenFilter(e)}};function Jo(r={}){return e=>new Ve(e,r)}return Hr(Qo);})();
3
3
  return Libp2PTcp}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@libp2p/tcp",
3
- "version": "10.0.17",
3
+ "version": "10.0.18",
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.4.1",
64
- "@libp2p/utils": "^6.5.0",
63
+ "@libp2p/interface": "^2.5.0",
64
+ "@libp2p/utils": "^6.5.1",
65
65
  "@multiformats/mafmt": "^12.1.6",
66
66
  "@multiformats/multiaddr": "^12.3.3",
67
67
  "@types/sinon": "^17.0.3",
@@ -72,7 +72,7 @@
72
72
  "stream-to-it": "^1.0.1"
73
73
  },
74
74
  "devDependencies": {
75
- "@libp2p/logger": "^5.1.7",
75
+ "@libp2p/logger": "^5.1.8",
76
76
  "aegir": "^45.0.5",
77
77
  "p-wait-for": "^5.0.2",
78
78
  "sinon": "^19.0.2",