@libp2p/tcp 9.0.16-ab466004b → 9.0.16-e1798aa26

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 Lr=Object.create;var xe=Object.defineProperty;var Or=Object.getOwnPropertyDescriptor;var Vr=Object.getOwnPropertyNames;var Fr=Object.getPrototypeOf,$r=Object.prototype.hasOwnProperty;var H=(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 ee=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),R=(r,e)=>{for(var t in e)xe(r,t,{get:e[t],enumerable:!0})},Tt=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Vr(e))!$r.call(r,o)&&o!==t&&xe(r,o,{get:()=>e[o],enumerable:!(n=Or(e,o))||n.enumerable});return r};var te=(r,e,t)=>(t=r!=null?Lr(Fr(r)):{},Tt(e||!r||!r.__esModule?xe(t,"default",{value:r,enumerable:!0}):t,r)),zr=r=>Tt(xe({},"__esModule",{value:!0}),r);var Ne=ee((Nc,Ar)=>{Ar.exports=r=>{if(r[Symbol.asyncIterator])return r;if(r.getReader)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()}}();throw new Error("unknown stream")}});var Sr=ee((Dc,Ir)=>{Ir.exports=function(e){if(e){if(typeof e[Symbol.iterator]=="function")return e[Symbol.iterator]();if(typeof e[Symbol.asyncIterator]=="function")return e[Symbol.asyncIterator]();if(typeof e.next=="function")return e}throw new Error("argument is not an iterator or iterable")}});var Et=ee((Mc,Cr)=>{var Uo=Sr();Cr.exports=r=>async e=>{e=Uo(e);let t=m=>{typeof m.return=="function"&&m.return()},n=null,o=null,s=m=>{n=m,o&&o(m),t(e)},i=null,a=!1,p=()=>{a=!0,i&&i()},f=null,g=!1,E=()=>{g=!0,f&&f()},x=null,u=()=>{x&&x()},d=()=>new Promise((m,C)=>{i=x=m,o=C,r.once("drain",u)}),b=()=>(t(e),new Promise((m,C)=>{if(a||g||n)return m();f=i=m,o=C})),U=()=>{r.removeListener("error",s),r.removeListener("close",p),r.removeListener("finish",E),r.removeListener("drain",u)};r.once("error",s),r.once("close",p),r.once("finish",E);try{for await(let m of e){if(!r.writable||r.destroyed||n)break;r.write(m)===!1&&await d()}}catch(m){n||r.destroy(),n=m}try{if(r.writable&&r.end(),await b(),n)throw n}finally{U()}}});var At=ee((Uc,Tr)=>{var _o=Et(),ko=Ne();Tr.exports=r=>({sink:_o(r),source:ko(r)})});var Rr=ee((_c,Pr)=>{var Lo=At();Pr.exports=r=>async function*(e){let t=Lo(r),n;if(t.sink(e).catch(o=>{n=o}),yield*t.source,n)throw n}});var Nr=ee((kc,ue)=>{ue.exports=Ne();ue.exports.source=Ne();ue.exports.sink=Et();ue.exports.transform=Rr();ue.exports.duplex=At()});var qo={};R(qo,{tcp:()=>Bo});var kr=te(H("net"),1);var Rt=Symbol.for("@libp2p/transport");var Pt;(function(r){r[r.FATAL_ALL=0]="FATAL_ALL",r[r.NO_FATAL=1]="NO_FATAL"})(Pt||(Pt={}));var re=class r extends Error{code;type;constructor(e="The operation was aborted"){super(e),this.code=r.code,this.type=r.type}static code="ABORT_ERR";static type="aborted"},A=class extends Error{code;props;constructor(e,t,n){super(e),this.code=t,this.name=n?.name??"CodeError",this.props=n??{}}};var Nt=H("events"),Dt=(r,...e)=>{try{(0,Nt.setMaxListeners)(r,...e)}catch{}};var be=class extends EventTarget{#e=new Map;constructor(){super(),Dt(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 Br(e,t))}},Ue=class extends Event{detail;constructor(e,t){super(e,t),this.detail=t?.detail}},Br=globalThis.CustomEvent??Ue;var Ve={};R(Ve,{base58btc:()=>T,base58flickr:()=>Xr});var Qo=new Uint8Array(0);function Mt(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}function D(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")}function Ut(r){return new TextEncoder().encode(r)}function _t(r){return new TextDecoder().decode(r)}function qr(r,e){if(r.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),n=0;n<t.length;n++)t[n]=255;for(var o=0;o<r.length;o++){var s=r.charAt(o),i=s.charCodeAt(0);if(t[i]!==255)throw new TypeError(s+" is ambiguous");t[i]=o}var a=r.length,p=r.charAt(0),f=Math.log(a)/Math.log(256),g=Math.log(256)/Math.log(a);function E(d){if(d instanceof Uint8Array||(ArrayBuffer.isView(d)?d=new Uint8Array(d.buffer,d.byteOffset,d.byteLength):Array.isArray(d)&&(d=Uint8Array.from(d))),!(d instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(d.length===0)return"";for(var b=0,U=0,m=0,C=d.length;m!==C&&d[m]===0;)m++,b++;for(var k=(C-m)*g+1>>>0,N=new Uint8Array(k);m!==C;){for(var L=d[m],B=0,_=k-1;(L!==0||B<U)&&_!==-1;_--,B++)L+=256*N[_]>>>0,N[_]=L%a>>>0,L=L/a>>>0;if(L!==0)throw new Error("Non-zero carry");U=B,m++}for(var V=k-U;V!==k&&N[V]===0;)V++;for(var we=p.repeat(b);V<k;++V)we+=r.charAt(N[V]);return we}function x(d){if(typeof d!="string")throw new TypeError("Expected String");if(d.length===0)return new Uint8Array;var b=0;if(d[b]!==" "){for(var U=0,m=0;d[b]===p;)U++,b++;for(var C=(d.length-b)*f+1>>>0,k=new Uint8Array(C);d[b];){var N=t[d.charCodeAt(b)];if(N===255)return;for(var L=0,B=C-1;(N!==0||L<m)&&B!==-1;B--,L++)N+=a*k[B]>>>0,k[B]=N%256>>>0,N=N/256>>>0;if(N!==0)throw new Error("Non-zero carry");m=L,b++}if(d[b]!==" "){for(var _=C-m;_!==C&&k[_]===0;)_++;for(var V=new Uint8Array(U+(C-_)),we=U;_!==C;)V[we++]=k[_++];return V}}}function u(d){var b=x(d);if(b)return b;throw new Error(`Non-${e} character`)}return{encode:E,decodeUnsafe:x,decode:u}}var jr=qr,Gr=jr,Lt=Gr;var _e=class{name;prefix;baseEncode;constructor(e,t,n){this.name=e,this.prefix=t,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},ke=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,t,n){if(this.name=e,this.prefix=t,t.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=t.codePointAt(0),this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return Ot(this,e)}},Le=class{decoders;constructor(e){this.decoders=e}or(e){return Ot(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 Ot(r,e){return new Le({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var Oe=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,t,n,o){this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=o,this.encoder=new _e(e,t,n),this.decoder=new ke(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function ne({name:r,prefix:e,encode:t,decode:n}){return new Oe(r,e,t,n)}function q({name:r,prefix:e,alphabet:t}){let{encode:n,decode:o}=Lt(t,r);return ne({prefix:e,name:r,encode:n,decode:s=>D(o(s))})}function Wr(r,e,t,n){let o={};for(let g=0;g<e.length;++g)o[e[g]]=g;let s=r.length;for(;r[s-1]==="=";)--s;let i=new Uint8Array(s*t/8|0),a=0,p=0,f=0;for(let g=0;g<s;++g){let E=o[r[g]];if(E===void 0)throw new SyntaxError(`Non-${n} character`);p=p<<t|E,a+=t,a>=8&&(a-=8,i[f++]=255&p>>a)}if(a>=t||255&p<<8-a)throw new SyntaxError("Unexpected end of data");return i}function Hr(r,e,t){let n=e[e.length-1]==="=",o=(1<<t)-1,s="",i=0,a=0;for(let p=0;p<r.length;++p)for(a=a<<8|r[p],i+=8;i>t;)i-=t,s+=e[o&a>>i];if(i!==0&&(s+=e[o&a<<t-i]),n)for(;s.length*t&7;)s+="=";return s}function y({name:r,prefix:e,bitsPerChar:t,alphabet:n}){return ne({prefix:e,name:r,encode(o){return Hr(o,n,t)},decode(o){return Wr(o,n,t,r)}})}var T=q({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Xr=q({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Fe={};R(Fe,{base32:()=>F,base32hex:()=>Yr,base32hexpad:()=>en,base32hexpadupper:()=>tn,base32hexupper:()=>Zr,base32pad:()=>Qr,base32padupper:()=>Kr,base32upper:()=>Jr,base32z:()=>rn});var F=y({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Jr=y({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Qr=y({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Kr=y({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Yr=y({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Zr=y({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),en=y({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),tn=y({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),rn=y({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var nn=$t,Vt=128,on=127,sn=~on,cn=Math.pow(2,31);function $t(r,e,t){e=e||[],t=t||0;for(var n=t;r>=cn;)e[t++]=r&255|Vt,r/=128;for(;r&sn;)e[t++]=r&255|Vt,r>>>=7;return e[t]=r|0,$t.bytes=t-n+1,e}var an=$e,ln=128,Ft=127;function $e(r,n){var t=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw $e.bytes=0,new RangeError("Could not decode varint");i=r[s++],t+=o<28?(i&Ft)<<o:(i&Ft)*Math.pow(2,o),o+=7}while(i>=ln);return $e.bytes=s-n,t}var dn=Math.pow(2,7),un=Math.pow(2,14),pn=Math.pow(2,21),fn=Math.pow(2,28),hn=Math.pow(2,35),mn=Math.pow(2,42),gn=Math.pow(2,49),wn=Math.pow(2,56),xn=Math.pow(2,63),bn=function(r){return r<dn?1:r<un?2:r<pn?3:r<fn?4:r<hn?5:r<mn?6:r<gn?7:r<wn?8:r<xn?9:10},yn={encode:nn,decode:an,encodingLength:bn},vn=yn,fe=vn;function he(r,e=0){return[fe.decode(r,e),fe.decode.bytes]}function oe(r,e,t=0){return fe.encode(r,e,t),e}function se(r){return fe.encodingLength(r)}function X(r,e){let t=e.byteLength,n=se(r),o=n+se(t),s=new Uint8Array(o+t);return oe(r,s,0),oe(t,s,n),s.set(e,o),new ie(r,t,e,s)}function ve(r){let e=D(r),[t,n]=he(e),[o,s]=he(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new ie(t,o,i,e)}function zt(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&Mt(r.bytes,t.bytes)}}var ie=class{code;size;digest;bytes;constructor(e,t,n,o){this.code=e,this.size=t,this.digest=n,this.bytes=o}};function Bt(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return An(t,ze(r),e??T.encoder);default:return In(t,ze(r),e??F.encoder)}}var qt=new WeakMap;function ze(r){let e=qt.get(r);if(e==null){let t=new Map;return qt.set(r,t),t}return e}var j=class r{code;version;multihash;bytes;"/";constructor(e,t,n,o){this.code=t,this.version=e,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:t}=this;if(e!==me)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==Sn)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(t)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:e,digest:t}=this.multihash,n=X(e,t);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(e){return r.equals(this,e)}static equals(e,t){let n=t;return n!=null&&e.code===n.code&&e.version===n.version&&zt(e.multihash,n.multihash)}toString(e){return Bt(this,e)}toJSON(){return{"/":Bt(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??jt(n,o,s.bytes))}else if(t[Cn]===!0){let{version:n,multihash:o,code:s}=t,i=ve(o);return r.create(n,s,i)}else return null}static create(e,t,n){if(typeof t!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(t!==me)throw new Error(`Version 0 CID must use dag-pb (code: ${me}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let o=jt(e,t,n.bytes);return new r(e,t,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,me,e)}static createV1(e,t){return r.create(1,e,t)}static decode(e){let[t,n]=r.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return t}static decodeFirst(e){let t=r.inspectBytes(e),n=t.size-t.multihashSize,o=D(e.subarray(n,n+t.multihashSize));if(o.byteLength!==t.multihashSize)throw new Error("Incorrect length");let s=o.subarray(t.multihashSize-t.digestSize),i=new ie(t.multihashCode,t.digestSize,s,o);return[t.version===0?r.createV0(i):r.createV1(t.codec,i),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[E,x]=he(e.subarray(t));return t+=x,E},o=n(),s=me;if(o===18?(o=0,t=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=t,a=n(),p=n(),f=t+p,g=f-i;return{version:o,codec:s,multihashCode:a,digestSize:p,multihashSize:g,size:f}}static parse(e,t){let[n,o]=En(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 ze(s).set(n,e),s}};function En(r,e){switch(r[0]){case"Q":{let t=e??T;return[T.prefix,t.decode(`${T.prefix}${r}`)]}case T.prefix:{let t=e??T;return[T.prefix,t.decode(r)]}case F.prefix:{let t=e??F;return[F.prefix,t.decode(r)]}default:{if(e==null)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[r[0],e.decode(r)]}}}function An(r,e,t){let{prefix:n}=t;if(n!==T.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let o=e.get(n);if(o==null){let s=t.encode(r).slice(1);return e.set(n,s),s}else return o}function In(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 me=112,Sn=18;function jt(r,e,t){let n=se(r),o=n+se(e),s=new Uint8Array(o+t.byteLength);return oe(r,s,0),oe(e,s,n),s.set(t,o),s}var Cn=Symbol.for("@ipld/js-cid/CID");function Gt(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 Be={};R(Be,{base10:()=>Tn});var Tn=q({prefix:"9",name:"base10",alphabet:"0123456789"});var qe={};R(qe,{base16:()=>Pn,base16upper:()=>Rn});var Pn=y({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Rn=y({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var je={};R(je,{base2:()=>Nn});var Nn=y({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Ge={};R(Ge,{base256emoji:()=>kn});var Wt=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}"),Dn=Wt.reduce((r,e,t)=>(r[t]=e,r),[]),Mn=Wt.reduce((r,e,t)=>(r[e.codePointAt(0)]=t,r),[]);function Un(r){return r.reduce((e,t)=>(e+=Dn[t],e),"")}function _n(r){let e=[];for(let t of r){let n=Mn[t.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${t}`);e.push(n)}return new Uint8Array(e)}var kn=ne({prefix:"\u{1F680}",name:"base256emoji",encode:Un,decode:_n});var We={};R(We,{base36:()=>Ln,base36upper:()=>On});var Ln=q({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),On=q({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var He={};R(He,{base64:()=>Vn,base64pad:()=>Fn,base64url:()=>$n,base64urlpad:()=>zn});var Vn=y({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Fn=y({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),$n=y({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),zn=y({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Xe={};R(Xe,{base8:()=>Bn});var Bn=y({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Je={};R(Je,{identity:()=>qn});var qn=ne({prefix:"\0",name:"identity",encode:r=>_t(r),decode:r=>Ut(r)});var vs=new TextEncoder,Es=new TextDecoder;var Qe={};R(Qe,{identity:()=>Xn});var Ht=0,Wn="identity",Xt=D;function Hn(r){return X(Ht,Xt(r))}var Xn={code:Ht,name:Wn,encode:Xt,digest:Hn};var et={};R(et,{sha256:()=>Jn,sha512:()=>Qn});var Ze=te(H("crypto"),1);function Ye({name:r,code:e,encode:t}){return new Ke(r,e,t)}var Ke=class{name;code;encode;constructor(e,t,n){this.name=e,this.code=t,this.encode=n}digest(e){if(e instanceof Uint8Array){let t=this.encode(e);return t instanceof Uint8Array?X(this.code,t):t.then(n=>X(this.code,n))}else throw Error("Unknown type, must be binary type")}};var Jn=Ye({name:"sha2-256",code:18,encode:r=>D(Ze.default.createHash("sha256").update(r).digest())}),Qn=Ye({name:"sha2-512",code:19,encode:r=>D(Ze.default.createHash("sha512").update(r).digest())});var ge={...Je,...je,...Xe,...Be,...qe,...Fe,...We,...Ve,...He,...Ge},Ls={...et,...Qe};function J(r){return globalThis.Buffer!=null?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):r}function ae(r=0){return globalThis.Buffer?.allocUnsafe!=null?J(globalThis.Buffer.allocUnsafe(r)):new Uint8Array(r)}function Kt(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var Qt=Kt("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),tt=Kt("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}),Kn={utf8:Qt,"utf-8":Qt,hex:ge.base16,latin1:tt,ascii:tt,binary:tt,...ge},Ee=Kn;function P(r,e="utf8"){let t=Ee[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return(e==="utf8"||e==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?globalThis.Buffer.from(r.buffer,r.byteOffset,r.byteLength).toString("utf8"):t.encoder.encode(r).substring(1)}var Yn=Math.pow(2,7),Zn=Math.pow(2,14),eo=Math.pow(2,21),rt=Math.pow(2,28),nt=Math.pow(2,35),ot=Math.pow(2,42),st=Math.pow(2,49),h=128,S=127;function O(r){if(r<Yn)return 1;if(r<Zn)return 2;if(r<eo)return 3;if(r<rt)return 4;if(r<nt)return 5;if(r<ot)return 6;if(r<st)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function to(r,e,t=0){switch(O(r)){case 8:e[t++]=r&255|h,r/=128;case 7:e[t++]=r&255|h,r/=128;case 6:e[t++]=r&255|h,r/=128;case 5:e[t++]=r&255|h,r/=128;case 4:e[t++]=r&255|h,r>>>=7;case 3:e[t++]=r&255|h,r>>>=7;case 2:e[t++]=r&255|h,r>>>=7;case 1:{e[t++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return e}function ro(r,e,t=0){switch(O(r)){case 8:e.set(t++,r&255|h),r/=128;case 7:e.set(t++,r&255|h),r/=128;case 6:e.set(t++,r&255|h),r/=128;case 5:e.set(t++,r&255|h),r/=128;case 4:e.set(t++,r&255|h),r>>>=7;case 3:e.set(t++,r&255|h),r>>>=7;case 2:e.set(t++,r&255|h),r>>>=7;case 1:{e.set(t++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return e}function no(r,e){let t=r[e],n=0;if(n+=t&S,t<h||(t=r[e+1],n+=(t&S)<<7,t<h)||(t=r[e+2],n+=(t&S)<<14,t<h)||(t=r[e+3],n+=(t&S)<<21,t<h)||(t=r[e+4],n+=(t&S)*rt,t<h)||(t=r[e+5],n+=(t&S)*nt,t<h)||(t=r[e+6],n+=(t&S)*ot,t<h)||(t=r[e+7],n+=(t&S)*st,t<h))return n;throw new RangeError("Could not decode varint")}function oo(r,e){let t=r.get(e),n=0;if(n+=t&S,t<h||(t=r.get(e+1),n+=(t&S)<<7,t<h)||(t=r.get(e+2),n+=(t&S)<<14,t<h)||(t=r.get(e+3),n+=(t&S)<<21,t<h)||(t=r.get(e+4),n+=(t&S)*rt,t<h)||(t=r.get(e+5),n+=(t&S)*nt,t<h)||(t=r.get(e+6),n+=(t&S)*ot,t<h)||(t=r.get(e+7),n+=(t&S)*st,t<h))return n;throw new RangeError("Could not decode varint")}function le(r,e,t=0){return e==null&&(e=ae(O(r))),e instanceof Uint8Array?to(r,e,t):ro(r,e,t)}function Q(r,e=0){return r instanceof Uint8Array?no(r,e):oo(r,e)}function $(r,e){if(globalThis.Buffer!=null)return J(globalThis.Buffer.concat(r,e));e==null&&(e=r.reduce((o,s)=>o+s.length,0));let t=ae(e),n=0;for(let o of r)t.set(o,n),n+=o.length;return J(t)}var Ae=class{index=0;input="";new(e){return this.index=0,this.input=e,this}readAtomically(e){let t=this.index,n=e();return n===void 0&&(this.index=t),n}parseWith(e){let t=e();if(this.index===this.input.length)return t}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(e){return this.readAtomically(()=>{let t=this.readChar();if(t===e)return t})}readSeparator(e,t,n){return this.readAtomically(()=>{if(!(t>0&&this.readGivenChar(e)===void 0))return n()})}readNumber(e,t,n,o){return this.readAtomically(()=>{let s=0,i=0,a=this.peekChar();if(a===void 0)return;let p=a==="0",f=2**(8*o)-1;for(;;){let g=this.readAtomically(()=>{let E=this.readChar();if(E===void 0)return;let x=Number.parseInt(E,e);if(!Number.isNaN(x))return x});if(g===void 0)break;if(s*=e,s+=g,s>f||(i+=1,t!==void 0&&i>t))return}if(i!==0)return!n&&p&&i>1?void 0:s})}readIPv4Addr(){return this.readAtomically(()=>{let e=new Uint8Array(4);for(let t=0;t<e.length;t++){let n=this.readSeparator(".",t,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;e[t]=n}return e})}readIPv6Addr(){let e=t=>{for(let n=0;n<t.length/2;n++){let o=n*2;if(n<t.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return t[o]=i[0],t[o+1]=i[1],t[o+2]=i[2],t[o+3]=i[3],[o+4,!0]}let s=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(s===void 0)return[o,!1];t[o]=s>>8,t[o+1]=s&255}return[t.length,!1]};return this.readAtomically(()=>{let t=new Uint8Array(16),[n,o]=e(t);if(n===16)return t;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let s=new Uint8Array(14),i=16-(n+2),[a]=e(s.subarray(0,i));return t.set(s.subarray(0,a),16-a),t})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var Ys=new Ae;var ii=parseInt("0xFFFF",16),ci=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function it(r,e="utf8"){let t=Ee[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return(e==="utf8"||e==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?J(globalThis.Buffer.from(r,"utf-8")):t.decoder.decode(`${t.prefix}${r}`)}var M=H("node:net");function Ie(r){return!!(0,M.isIP)(r)}var tr=M.isIPv4,uo=M.isIPv6,ct=function(r){let e=0;if(r=r.toString().trim(),tr(r)){let t=new Uint8Array(e+4);return r.split(/\./g).forEach(n=>{t[e++]=parseInt(n,10)&255}),t}if(uo(r)){let t=r.split(":",8),n;for(n=0;n<t.length;n++){let s=tr(t[n]),i;s&&(i=ct(t[n]),t[n]=P(i.slice(0,2),"base16")),i!=null&&++n<8&&t.splice(n,0,P(i.slice(2,4),"base16"))}if(t[0]==="")for(;t.length<8;)t.unshift("0");else if(t[t.length-1]==="")for(;t.length<8;)t.push("0");else if(t.length<8){for(n=0;n<t.length&&t[n]!=="";n++);let s=[n,1];for(n=9-t.length;n>0;n--)s.push("0");t.splice.apply(t,s)}let o=new Uint8Array(e+16);for(n=0;n<t.length;n++){let s=parseInt(t[n],16);o[e++]=s>>8&255,o[e++]=s&255}return o}throw new Error("invalid ip address")},rr=function(r,e=0,t){e=~~e,t=t??r.length-e;let n=new DataView(r.buffer);if(t===4){let o=[];for(let s=0;s<t;s++)o.push(r[e+s]);return o.join(".")}if(t===16){let o=[];for(let s=0;s<t;s+=2)o.push(n.getUint16(e+s).toString(16));return o.join(":").replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}return""};var de={},at={},fo=[[4,32,"ip4"],[6,16,"tcp"],[33,16,"dccp"],[41,128,"ip6"],[42,-1,"ip6zone"],[43,8,"ipcidr"],[53,-1,"dns",!0],[54,-1,"dns4",!0],[55,-1,"dns6",!0],[56,-1,"dnsaddr",!0],[132,16,"sctp"],[273,16,"udp"],[275,0,"p2p-webrtc-star"],[276,0,"p2p-webrtc-direct"],[277,0,"p2p-stardust"],[280,0,"webrtc-direct"],[281,0,"webrtc"],[290,0,"p2p-circuit"],[301,0,"udt"],[302,0,"utp"],[400,-1,"unix",!1,!0],[421,-1,"ipfs"],[421,-1,"p2p"],[443,0,"https"],[444,96,"onion"],[445,296,"onion3"],[446,-1,"garlic64"],[448,0,"tls"],[449,-1,"sni"],[460,0,"quic"],[461,0,"quic-v1"],[465,0,"webtransport"],[466,-1,"certhash"],[477,0,"ws"],[478,0,"wss"],[479,0,"p2p-websocket-star"],[480,0,"http"],[777,-1,"memory"]];fo.forEach(r=>{let e=ho(...r);at[e.code]=e,de[e.name]=e});function ho(r,e,t,n,o){return{code:r,size:e,name:t,resolvable:!!n,path:!!o}}function w(r){if(typeof r=="number"){if(at[r]!=null)return at[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(de[r]!=null)return de[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var Xi=w("ip4"),Ji=w("ip6"),Qi=w("ipcidr");function dt(r,e){switch(w(r).code){case 4:case 41:return go(e);case 42:return sr(e);case 6:case 273:case 33:case 132:return cr(e).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return sr(e);case 421:return yo(e);case 444:return ir(e);case 445:return ir(e);case 466:return bo(e);default:return P(e,"base16")}}function ut(r,e){switch(w(r).code){case 4:return nr(e);case 41:return nr(e);case 42:return or(e);case 6:case 273:case 33:case 132:return pt(parseInt(e,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return or(e);case 421:return wo(e);case 444:return vo(e);case 445:return Eo(e);case 466:return xo(e);default:return it(e,"base16")}}var lt=Object.values(ge).map(r=>r.decoder),mo=function(){let r=lt[0].or(lt[1]);return lt.slice(2).forEach(e=>r=r.or(e)),r}();function nr(r){if(!Ie(r))throw new Error("invalid ip address");return ct(r)}function go(r){let e=rr(r,0,r.length);if(e==null)throw new Error("ipBuff is required");if(!Ie(e))throw new Error("invalid ip address");return e}function pt(r){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,r),new Uint8Array(e)}function cr(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function or(r){let e=it(r),t=Uint8Array.from(le(e.length));return $([t,e],t.length+e.length)}function sr(r){let e=Q(r);if(r=r.slice(O(e)),r.length!==e)throw new Error("inconsistent lengths");return P(r)}function wo(r){let e;r[0]==="Q"||r[0]==="1"?e=ve(T.decode(`z${r}`)).bytes:e=j.parse(r).multihash.bytes;let t=Uint8Array.from(le(e.length));return $([t,e],t.length+e.length)}function xo(r){let e=mo.decode(r),t=Uint8Array.from(le(e.length));return $([t,e],t.length+e.length)}function bo(r){let e=Q(r),t=r.slice(O(e));if(t.length!==e)throw new Error("inconsistent lengths");return"u"+P(t,"base64url")}function yo(r){let e=Q(r),t=r.slice(O(e));if(t.length!==e)throw new Error("inconsistent lengths");return P(t,"base58btc")}function vo(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=F.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=pt(n);return $([t,o],t.length+o.length)}function Eo(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=F.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=pt(n);return $([t,o],t.length+o.length)}function ir(r){let e=r.slice(0,r.length-2),t=r.slice(r.length-2),n=P(e,"base32"),o=cr(t);return`${n}:${o}`}function ar(r){r=ft(r);let e=[],t=[],n=null,o=r.split("/").slice(1);if(o.length===1&&o[0]==="")return{bytes:new Uint8Array,string:"/",tuples:[],stringTuples:[],path:null};for(let s=0;s<o.length;s++){let i=o[s],a=w(i);if(a.size===0){e.push([a.code]),t.push([a.code]);continue}if(s++,s>=o.length)throw dr("invalid address: "+r);if(a.path===!0){n=ft(o.slice(s).join("/")),e.push([a.code,ut(a.code,n)]),t.push([a.code,n]);break}let p=ut(a.code,o[s]);e.push([a.code,p]),t.push([a.code,dt(a.code,p)])}return{string:lr(t),bytes:mt(e),tuples:e,stringTuples:t,path:n}}function ht(r){let e=[],t=[],n=null,o=0;for(;o<r.length;){let s=Q(r,o),i=O(s),a=w(s),p=Ao(a,r.slice(o+i));if(p===0){e.push([s]),t.push([s]),o+=i;continue}let f=r.slice(o+i,o+i+p);if(o+=p+i,o>r.length)throw dr("Invalid address Uint8Array: "+P(r,"base16"));e.push([s,f]);let g=dt(s,f);if(t.push([s,g]),a.path===!0){n=g;break}}return{bytes:Uint8Array.from(r),string:lr(t),tuples:e,stringTuples:t,path:n}}function lr(r){let e=[];return r.map(t=>{let n=w(t[0]);return e.push(n.name),t.length>1&&t[1]!=null&&e.push(t[1]),null}),ft(e.join("/"))}function mt(r){return $(r.map(e=>{let t=w(e[0]),n=Uint8Array.from(le(t.code));return e.length>1&&e[1]!=null&&(n=$([n,e[1]])),n}))}function Ao(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+O(t)}}function ft(r){return"/"+r.trim().split("/").filter(e=>e).join("/")}function dr(r){return new Error("Error parsing address: "+r)}var Io=Symbol.for("nodejs.util.inspect.custom"),gt=Symbol.for("@multiformats/js-multiaddr/multiaddr"),So=[w("dns").code,w("dns4").code,w("dns6").code,w("dnsaddr").code],Se=class r{bytes;#e;#t;#r;#n;[gt]=!0;constructor(e){e==null&&(e="");let t;if(e instanceof Uint8Array)t=ht(e);else if(typeof e=="string"){if(e.length>0&&e.charAt(0)!=="/")throw new Error(`multiaddr "${e}" must start with a "/"`);t=ar(e)}else if(pr(e))t=ht(e.bytes);else throw new Error("addr must be a string, Buffer, or another Multiaddr");this.bytes=t.bytes,this.#e=t.string,this.#t=t.tuples,this.#r=t.stringTuples,this.#n=t.path}toString(){return this.#e}toJSON(){return this.toString()}toOptions(){let e,t,n,o,s="",i=w("tcp"),a=w("udp"),p=w("ip4"),f=w("ip6"),g=w("dns6"),E=w("ip6zone");for(let[u,d]of this.stringTuples())u===E.code&&(s=`%${d??""}`),So.includes(u)&&(t=i.name,o=443,n=`${d??""}${s}`,e=u===g.code?6:4),(u===i.code||u===a.code)&&(t=w(u).name,o=parseInt(d??"")),(u===p.code||u===f.code)&&(t=w(u).name,n=`${d??""}${s}`,e=u===f.code?6:4);if(e==null||t==null||n==null||o==null)throw new Error('multiaddr must have a valid format: "/{ip4, ip6, dns4, dns6, dnsaddr}/{address}/{tcp, udp}/{port}".');return{family:e,host:n,transport:t,port:o}}protos(){return this.#t.map(([e])=>Object.assign({},w(e)))}protoCodes(){return this.#t.map(([e])=>e)}protoNames(){return this.#t.map(([e])=>w(e).name)}tuples(){return this.#t}stringTuples(){return this.#r}encapsulate(e){return e=new r(e),new r(this.toString()+e.toString())}decapsulate(e){let t=e.toString(),n=this.toString(),o=n.lastIndexOf(t);if(o<0)throw new Error(`Address ${this.toString()} does not contain subaddress: ${e.toString()}`);return new r(n.slice(0,o))}decapsulateCode(e){let t=this.tuples();for(let n=t.length-1;n>=0;n--)if(t[n][0]===e)return new r(mt(t.slice(0,n)));return this}getPeerId(){try{let e=[];this.stringTuples().forEach(([n,o])=>{n===de.p2p.code&&e.push([n,o]),n===de["p2p-circuit"].code&&(e=[])});let t=e.pop();if(t?.[1]!=null){let n=t[1];return n[0]==="Q"||n[0]==="1"?P(T.decode(`z${n}`),"base58btc"):P(j.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){return this.#n}equals(e){return Gt(this.bytes,e.bytes)}async resolve(e){let t=this.protos().find(s=>s.resolvable);if(t==null)return[this];let n=ur.get(t.name);if(n==null)throw new A(`no available resolver for ${t.name}`,"ERR_NO_AVAILABLE_RESOLVER");return(await n(this,e)).map(s=>new r(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)}[Io](){return`Multiaddr(${this.#e})`}};var ur=new Map;function pr(r){return!!r?.[gt]}function z(r){return new Se(r)}var Co=c("dns4"),To=c("dns6"),Po=c("dnsaddr"),Y=v(c("dns"),Po,Co,To),Pe=v(c("ip4"),c("ip6")),W=v(l(Pe,c("tcp")),l(Y,c("tcp"))),Re=l(Pe,c("udp")),Ro=l(Re,c("utp")),No=l(Re,c("quic")),Do=l(Re,c("quic-v1")),wt=v(l(W,c("ws")),l(Y,c("ws"))),Ce=v(l(wt,c("p2p")),wt),xt=v(l(W,c("wss")),l(Y,c("wss")),l(W,c("tls"),c("ws")),l(Y,c("tls"),c("ws"))),Te=v(l(xt,c("p2p")),xt),bt=v(l(W,c("http")),l(Pe,c("http")),l(Y,c("http"))),yt=v(l(W,c("https")),l(Pe,c("https")),l(Y,c("https"))),fr=l(Re,c("webrtc-direct"),c("certhash")),gr=v(l(fr,c("p2p")),fr),hr=l(Do,c("webtransport"),c("certhash"),c("certhash")),wr=v(l(hr,c("p2p")),hr),xr=v(l(Ce,c("p2p-webrtc-star"),c("p2p")),l(Te,c("p2p-webrtc-star"),c("p2p")),l(Ce,c("p2p-webrtc-star")),l(Te,c("p2p-webrtc-star"))),Ec=v(l(Ce,c("p2p-websocket-star"),c("p2p")),l(Te,c("p2p-websocket-star"),c("p2p")),l(Ce,c("p2p-websocket-star")),l(Te,c("p2p-websocket-star"))),br=v(l(bt,c("p2p-webrtc-direct"),c("p2p")),l(yt,c("p2p-webrtc-direct"),c("p2p")),l(bt,c("p2p-webrtc-direct")),l(yt,c("p2p-webrtc-direct"))),Z=v(wt,xt,bt,yt,xr,br,W,Ro,No,Y,gr,wr),Ac=v(l(Z,c("p2p-stardust"),c("p2p")),l(Z,c("p2p-stardust"))),G=v(l(Z,c("p2p")),xr,br,gr,wr,c("p2p")),mr=v(l(G,c("p2p-circuit"),G),l(G,c("p2p-circuit")),l(c("p2p-circuit"),G),l(Z,c("p2p-circuit")),l(c("p2p-circuit"),Z),c("p2p-circuit")),yr=()=>v(l(mr,yr),mr),K=yr(),Ic=v(l(K,G,K),l(G,K),l(K,G),K,G);var Sc=v(l(K,c("webrtc"),c("p2p")),l(K,c("webrtc")),l(Z,c("webrtc"),c("p2p")),l(Z,c("webrtc")),c("webrtc"));function vr(r){function e(t){let n;try{n=z(t)}catch{return!1}let o=r(n.protoNames());return o===null?!1:o===!0||o===!1?o:o.length===0}return e}function l(...r){function e(t){if(t.length<r.length)return null;let n=t;return r.some(o=>(n=typeof o=="function"?o().partialMatch(t):o.partialMatch(t),Array.isArray(n)&&(t=n),n===null)),n}return{toString:function(){return"{ "+r.join(" ")+" }"},input:r,matches:vr(e),partialMatch:e}}function v(...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:vr(e),partialMatch:e}}function c(r){let e=r;function t(o){let s;try{s=z(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 _r=te(H("net"),1);var vt={ERR_INVALID_IP_PARAMETER:"ERR_INVALID_IP_PARAMETER",ERR_INVALID_PORT_PARAMETER:"ERR_INVALID_PORT_PARAMETER",ERR_INVALID_IP:"ERR_INVALID_IP"};function Er(r,e){if(typeof r!="string")throw new A(`invalid ip provided: ${r}`,vt.ERR_INVALID_IP_PARAMETER);if(typeof e=="string"&&(e=parseInt(e)),isNaN(e))throw new A(`invalid port provided: ${e}`,vt.ERR_INVALID_PORT_PARAMETER);if((0,M.isIPv4)(r))return z(`/ip4/${r}/tcp/${e}`);if((0,M.isIPv6)(r))return z(`/ip6/${r}/tcp/${e}`);throw new A(`invalid ip:port for creating a multiaddr: ${r}:${e}`,vt.ERR_INVALID_IP)}var Mr=te(Nr(),1);var It=te(H("os"),1),Dr=te(H("path"),1);var Oo={ip4:"IPv4",ip6:"IPv6"};function pe(r,e={}){let t=r.getPath();return t!=null?It.default.platform()==="win32"?{path:Dr.default.join("\\\\.\\pipe\\",t)}:{path:t}:{...e,...r.toOptions()}}function St(r,e,t){let n=o=>z(`/${r}/${o}/tcp/${t}`);return(Vo(e)?$o(Oo[r]):[e]).map(n)}function Vo(r){return["0.0.0.0","::"].includes(r)}var Fo=It.default.networkInterfaces();function $o(r){let e=[];for(let[,t]of Object.entries(Fo))if(t!=null)for(let n of t)n.family===r&&e.push(n.address);return e}var De=(r,e)=>{let t=e.logger.forComponent("libp2p:tcp:socket"),n=e.metrics,o=e.metricPrefix??"",s=e.socketInactivityTimeout??3e5,i=e.socketCloseTimeout??500;e.listeningAddr?.getPath()!=null&&(e.remoteAddr=e.listeningAddr),e.remoteAddr?.getPath()!=null&&(e.localAddr=e.remoteAddr);let a;if(e.remoteAddr!=null)a=e.remoteAddr;else{if(r.remoteAddress==null||r.remotePort==null)throw new A("Could not determine remote address or port","ERR_NO_REMOTE_ADDRESS");a=Er(r.remoteAddress,r.remotePort)}let p=pe(a),f=p.path??`${p.host??""}:${p.port??""}`,{sink:g,source:E}=Mr.default.duplex(r);r.setTimeout(s,()=>{t("%s socket read timeout",f),n?.increment({[`${o}timeout`]:!0});let u;r.readable&&(u=new A("Socket read timeout","ERR_SOCKET_READ_TIMEOUT")),r.destroy(u)}),r.once("close",()=>{t("%s socket close",f),n?.increment({[`${o}close`]:!0}),x.timeline.close==null&&(x.timeline.close=Date.now())}),r.once("end",()=>{t("%s socket end",f),n?.increment({[`${o}end`]:!0})});let x={async sink(u){try{await g(async function*(){for await(let d of u)d instanceof Uint8Array?yield d:yield d.subarray()}())}catch(d){d.type!=="aborted"&&t.error("%s error in sink",f,d)}r.end()},source:E,remoteAddr:a,timeline:{open:Date.now()},async close(u={}){if(r.destroyed){t("%s socket was already destroyed when trying to close",f);return}if(u.signal==null){let b=AbortSignal.timeout(i);u={...u,signal:b}}let d=()=>{r.destroy(new A("Destroying socket after timeout","ERR_CLOSE_TIMEOUT"))};u.signal?.addEventListener("abort",d);try{t("%s closing socket",f),await new Promise((b,U)=>{r.once("close",()=>{t("%s socket closed",f),b()}),r.once("error",m=>{t("%s socket error",f,m),x.timeline.close==null&&(x.timeline.close=Date.now()),U(m)}),r.setTimeout(i),r.end(),r.writableLength>0?r.once("drain",()=>{t("%s socket drained",f),r.destroy()}):r.destroy()})}catch(b){this.abort(b)}finally{u.signal?.removeEventListener("abort",d)}},abort:u=>{t("%s socket abort due to error",f,u),r.destroy(u),x.timeline.close==null&&(x.timeline.close=Date.now())},log:t};return x};async function Ur(r,e){try{await r.close()}catch(t){e.log.error("an error occurred closing the connection",t),r.abort(t)}}var I;(function(r){r[r.INACTIVE=0]="INACTIVE",r[r.ACTIVE=1]="ACTIVE",r[r.PAUSED=2]="PAUSED"})(I||(I={}));var Me=class extends be{context;server;connections=new Set;status={code:I.INACTIVE};metrics;addr;log;constructor(e){if(super(),this.context=e,e.keepAlive=e.keepAlive??!0,e.noDelay=e.noDelay??!0,this.log=e.logger.forComponent("libp2p:tcp:listener"),this.addr="unknown",this.server=_r.default.createServer(e,this.onSocket.bind(this)),e.maxConnections!==void 0&&(this.server.maxConnections=e.maxConnections),e.closeServerOnMaxConnections!=null&&e.closeServerOnMaxConnections.closeAbove<e.closeServerOnMaxConnections.listenBelow)throw new A("closeAbove must be >= listenBelow","ERR_CONNECTION_LIMITS");this.server.on("listening",()=>{if(e.metrics!=null){let t=this.server.address();t==null?this.addr="unknown":typeof t=="string"?this.addr=t:this.addr=`${t.address}:${t.port}`,e.metrics?.registerMetricGroup("libp2p_tcp_inbound_connections_total",{label:"address",help:"Current active connections in TCP listener",calculate:()=>({[this.addr]:this.connections.size})}),this.metrics={status:e.metrics.registerMetricGroup("libp2p_tcp_listener_status_info",{label:"address",help:"Current status of the TCP listener socket"}),errors:e.metrics.registerMetricGroup("libp2p_tcp_listener_errors_total",{label:"address",help:"Total count of TCP listener errors by type"}),events:e.metrics.registerMetricGroup("libp2p_tcp_listener_events_total",{label:"address",help:"Total count of TCP listener events by type"})},this.metrics?.status.update({[this.addr]:I.ACTIVE})}this.safeDispatchEvent("listening")}).on("error",t=>{this.metrics?.errors.increment({[`${this.addr} listen_error`]:!0}),this.safeDispatchEvent("error",{detail:t})}).on("close",()=>{this.metrics?.status.update({[this.addr]:this.status.code}),this.status.code!==I.PAUSED&&this.safeDispatchEvent("close")})}onSocket(e){if(this.status.code!==I.ACTIVE)throw new A("Server is is not listening yet","ERR_SERVER_NOT_RUNNING");e.on("error",n=>{this.log("socket error",n),this.metrics?.events.increment({[`${this.addr} error`]:!0})});let t;try{t=De(e,{listeningAddr:this.status.listeningAddr,socketInactivityTimeout:this.context.socketInactivityTimeout,socketCloseTimeout:this.context.socketCloseTimeout,metrics:this.metrics?.events,metricPrefix:`${this.addr} `,logger:this.context.logger})}catch(n){this.log.error("inbound connection failed",n),this.metrics?.errors.increment({[`${this.addr} inbound_to_connection`]:!0});return}this.log("new inbound connection %s",t.remoteAddr);try{this.context.upgrader.upgradeInbound(t).then(n=>{this.log("inbound connection upgraded %s",t.remoteAddr),this.connections.add(t),e.once("close",()=>{this.connections.delete(t),this.context.closeServerOnMaxConnections!=null&&this.connections.size<this.context.closeServerOnMaxConnections.listenBelow&&this.resume().catch(o=>{this.log.error("error attempting to listen server once connection count under limit",o),this.context.closeServerOnMaxConnections?.onListenError?.(o)})}),this.context.handler!=null&&this.context.handler(n),this.context.closeServerOnMaxConnections!=null&&this.connections.size>=this.context.closeServerOnMaxConnections.closeAbove&&this.pause(!1).catch(o=>{this.log.error("error attempting to close server once connection count over limit",o)}),this.safeDispatchEvent("connection",{detail:n})}).catch(async n=>{this.log.error("inbound connection failed",n),this.metrics?.errors.increment({[`${this.addr} inbound_upgrade`]:!0}),await Ur(t,{log:this.log})}).catch(n=>{this.log.error("closing inbound connection failed",n)})}catch(n){this.log.error("inbound connection failed",n),Ur(t,{log:this.log}).catch(o=>{this.log.error("closing inbound connection failed",o),this.metrics?.errors.increment({[`${this.addr} inbound_closing_failed`]:!0})})}}getAddrs(){if(this.status.code===I.INACTIVE)return[];let e=[],t=this.server.address(),{listeningAddr:n,peerId:o}=this.status;if(t==null)return[];if(typeof t=="string")e=[n];else try{n.toString().startsWith("/ip4")?e=e.concat(St("ip4",t.address,t.port)):t.family==="IPv6"&&(e=e.concat(St("ip6",t.address,t.port)))}catch(s){this.log.error("could not turn %s:%s into multiaddr",t.address,t.port,s)}return e.map(s=>o!=null?s.encapsulate(`/p2p/${o}`):s)}async listen(e){if(this.status.code===I.ACTIVE||this.status.code===I.PAUSED)throw new A("server is already listening","ERR_SERVER_ALREADY_LISTENING");let t=e.getPeerId(),n=t==null?e.decapsulateCode(421):e,{backlog:o}=this.context;try{this.status={code:I.ACTIVE,listeningAddr:n,peerId:t,netConfig:pe(n,{backlog:o})},await this.resume()}catch(s){throw this.status={code:I.INACTIVE},s}}async close(){let e=new A("Listener is closing","ERR_LISTENER_CLOSING");this.connections.forEach(t=>{t.abort(e)}),await this.pause(!0)}async resume(){if(this.server.listening||this.status.code===I.INACTIVE)return;let e=this.status.netConfig;await new Promise((t,n)=>{this.server.once("error",n),this.server.listen(e,t)}),this.status={...this.status,code:I.ACTIVE},this.log("listening on %s",this.server.address())}async pause(e){if(!this.server.listening&&this.status.code===I.PAUSED&&e){this.status={code:I.INACTIVE};return}!this.server.listening||this.status.code!==I.ACTIVE||(this.log("closing server on %s",this.server.address()),this.status=e?{code:I.INACTIVE}:{...this.status,code:I.PAUSED},await new Promise((t,n)=>{this.server.close(o=>{if(o!=null){n(o);return}t()})}))}};var Ct=class{opts;metrics;components;log;constructor(e,t={}){this.log=e.logger.forComponent("libp2p:tcp"),this.opts=t,this.components=e,e.metrics!=null&&(this.metrics={dialerEvents:e.metrics.registerCounterGroup("libp2p_tcp_dialer_events_total",{label:"event",help:"Total count of TCP dialer events by type"})})}[Rt]=!0;[Symbol.toStringTag]="@libp2p/tcp";async dial(e,t){t.keepAlive=t.keepAlive??!0,t.noDelay=t.noDelay??!0;let n=await this._connect(e,t);n.on("error",a=>{this.log("socket error",a)});let o=De(n,{remoteAddr:e,socketInactivityTimeout:this.opts.outboundSocketInactivityTimeout,socketCloseTimeout:this.opts.socketCloseTimeout,metrics:this.metrics?.dialerEvents,logger:this.components.logger}),s=()=>{o.close().catch(a=>{this.log.error("Error closing maConn after abort",a)})};t.signal?.addEventListener("abort",s,{once:!0}),this.log("new outbound connection %s",o.remoteAddr);let i=await t.upgrader.upgradeOutbound(o);if(this.log("outbound connection %s upgraded",o.remoteAddr),t.signal?.removeEventListener("abort",s),t.signal?.aborted===!0)throw i.close().catch(a=>{this.log.error("Error closing conn after abort",a)}),new re;return i}async _connect(e,t){if(t.signal?.aborted===!0)throw new re;return new Promise((n,o)=>{let s=Date.now(),i=pe(e,{...this.opts.dialOpts??{},...t});this.log("dialing %a",e);let a=kr.default.connect(i),p=u=>{let d=i.path??`${i.host??""}:${i.port}`;u.message=`connection error ${d}: ${u.message}`,this.metrics?.dialerEvents.increment({error:!0}),x(u)},f=()=>{this.log("connection timeout %a",e),this.metrics?.dialerEvents.increment({timeout:!0});let u=new A(`connection timeout after ${Date.now()-s}ms`,"ERR_CONNECT_TIMEOUT");a.emit("error",u)},g=()=>{this.log("connection opened %a",e),this.metrics?.dialerEvents.increment({connect:!0}),x()},E=()=>{this.log("connection aborted %a",e),this.metrics?.dialerEvents.increment({abort:!0}),a.destroy(),x(new re)},x=u=>{if(a.removeListener("error",p),a.removeListener("timeout",f),a.removeListener("connect",g),t.signal!=null&&t.signal.removeEventListener("abort",E),u!=null){o(u);return}n(a)};a.on("error",p),a.on("timeout",f),a.on("connect",g),t.signal!=null&&t.signal.addEventListener("abort",E)})}createListener(e){return new Me({...this.opts.listenOpts??{},...e,maxConnections:this.opts.maxConnections,backlog:this.opts.backlog,closeServerOnMaxConnections:this.opts.closeServerOnMaxConnections,socketInactivityTimeout:this.opts.inboundSocketInactivityTimeout,socketCloseTimeout:this.opts.socketCloseTimeout,metrics:this.components.metrics,logger:this.components.logger})}filter(e){return e=Array.isArray(e)?e:[e],e.filter(t=>t.protoCodes().includes(290)?!1:t.protoCodes().includes(400)?!0:W.matches(t.decapsulateCode(421)))}};function Bo(r={}){return e=>new Ct(e,r)}return zr(qo);})();
2
+ "use strict";var Libp2PTcp=(()=>{var Lr=Object.create;var xe=Object.defineProperty;var Or=Object.getOwnPropertyDescriptor;var Vr=Object.getOwnPropertyNames;var Fr=Object.getPrototypeOf,$r=Object.prototype.hasOwnProperty;var H=(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 ee=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),R=(r,e)=>{for(var t in e)xe(r,t,{get:e[t],enumerable:!0})},Tt=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Vr(e))!$r.call(r,o)&&o!==t&&xe(r,o,{get:()=>e[o],enumerable:!(n=Or(e,o))||n.enumerable});return r};var te=(r,e,t)=>(t=r!=null?Lr(Fr(r)):{},Tt(e||!r||!r.__esModule?xe(t,"default",{value:r,enumerable:!0}):t,r)),zr=r=>Tt(xe({},"__esModule",{value:!0}),r);var Ne=ee((Nc,Ar)=>{Ar.exports=r=>{if(r[Symbol.asyncIterator])return r;if(r.getReader)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()}}();throw new Error("unknown stream")}});var Sr=ee((Dc,Ir)=>{Ir.exports=function(e){if(e){if(typeof e[Symbol.iterator]=="function")return e[Symbol.iterator]();if(typeof e[Symbol.asyncIterator]=="function")return e[Symbol.asyncIterator]();if(typeof e.next=="function")return e}throw new Error("argument is not an iterator or iterable")}});var Et=ee((Mc,Cr)=>{var Uo=Sr();Cr.exports=r=>async e=>{e=Uo(e);let t=m=>{typeof m.return=="function"&&m.return()},n=null,o=null,s=m=>{n=m,o&&o(m),t(e)},i=null,a=!1,p=()=>{a=!0,i&&i()},f=null,g=!1,E=()=>{g=!0,f&&f()},x=null,d=()=>{x&&x()},u=()=>new Promise((m,C)=>{i=x=m,o=C,r.once("drain",d)}),b=()=>(t(e),new Promise((m,C)=>{if(a||g||n)return m();f=i=m,o=C})),U=()=>{r.removeListener("error",s),r.removeListener("close",p),r.removeListener("finish",E),r.removeListener("drain",d)};r.once("error",s),r.once("close",p),r.once("finish",E);try{for await(let m of e){if(!r.writable||r.destroyed||n)break;r.write(m)===!1&&await u()}}catch(m){n||r.destroy(),n=m}try{if(r.writable&&r.end(),await b(),n)throw n}finally{U()}}});var At=ee((Uc,Tr)=>{var _o=Et(),ko=Ne();Tr.exports=r=>({sink:_o(r),source:ko(r)})});var Rr=ee((_c,Pr)=>{var Lo=At();Pr.exports=r=>async function*(e){let t=Lo(r),n;if(t.sink(e).catch(o=>{n=o}),yield*t.source,n)throw n}});var Nr=ee((kc,de)=>{de.exports=Ne();de.exports.source=Ne();de.exports.sink=Et();de.exports.transform=Rr();de.exports.duplex=At()});var qo={};R(qo,{tcp:()=>Bo});var kr=te(H("net"),1);var Rt=Symbol.for("@libp2p/transport");var Pt;(function(r){r[r.FATAL_ALL=0]="FATAL_ALL",r[r.NO_FATAL=1]="NO_FATAL"})(Pt||(Pt={}));var re=class r extends Error{code;type;constructor(e="The operation was aborted"){super(e),this.code=r.code,this.type=r.type}static code="ABORT_ERR";static type="aborted"},A=class extends Error{code;props;constructor(e,t,n){super(e),this.code=t,this.name=n?.name??"CodeError",this.props=n??{}}};var Nt=H("events"),Dt=(r,...e)=>{try{(0,Nt.setMaxListeners)(r,...e)}catch{}};var be=class extends EventTarget{#e=new Map;constructor(){super(),Dt(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 Br(e,t))}},Ue=class extends Event{detail;constructor(e,t){super(e,t),this.detail=t?.detail}},Br=globalThis.CustomEvent??Ue;var Ve={};R(Ve,{base58btc:()=>T,base58flickr:()=>Xr});var Qo=new Uint8Array(0);function Mt(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}function D(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")}function Ut(r){return new TextEncoder().encode(r)}function _t(r){return new TextDecoder().decode(r)}function qr(r,e){if(r.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),n=0;n<t.length;n++)t[n]=255;for(var o=0;o<r.length;o++){var s=r.charAt(o),i=s.charCodeAt(0);if(t[i]!==255)throw new TypeError(s+" is ambiguous");t[i]=o}var a=r.length,p=r.charAt(0),f=Math.log(a)/Math.log(256),g=Math.log(256)/Math.log(a);function E(u){if(u instanceof Uint8Array||(ArrayBuffer.isView(u)?u=new Uint8Array(u.buffer,u.byteOffset,u.byteLength):Array.isArray(u)&&(u=Uint8Array.from(u))),!(u instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(u.length===0)return"";for(var b=0,U=0,m=0,C=u.length;m!==C&&u[m]===0;)m++,b++;for(var L=(C-m)*g+1>>>0,N=new Uint8Array(L);m!==C;){for(var O=u[m],B=0,_=L-1;(O!==0||B<U)&&_!==-1;_--,B++)O+=256*N[_]>>>0,N[_]=O%a>>>0,O=O/a>>>0;if(O!==0)throw new Error("Non-zero carry");U=B,m++}for(var F=L-U;F!==L&&N[F]===0;)F++;for(var we=p.repeat(b);F<L;++F)we+=r.charAt(N[F]);return we}function x(u){if(typeof u!="string")throw new TypeError("Expected String");if(u.length===0)return new Uint8Array;var b=0;if(u[b]!==" "){for(var U=0,m=0;u[b]===p;)U++,b++;for(var C=(u.length-b)*f+1>>>0,L=new Uint8Array(C);u[b];){var N=t[u.charCodeAt(b)];if(N===255)return;for(var O=0,B=C-1;(N!==0||O<m)&&B!==-1;B--,O++)N+=a*L[B]>>>0,L[B]=N%256>>>0,N=N/256>>>0;if(N!==0)throw new Error("Non-zero carry");m=O,b++}if(u[b]!==" "){for(var _=C-m;_!==C&&L[_]===0;)_++;for(var F=new Uint8Array(U+(C-_)),we=U;_!==C;)F[we++]=L[_++];return F}}}function d(u){var b=x(u);if(b)return b;throw new Error(`Non-${e} character`)}return{encode:E,decodeUnsafe:x,decode:d}}var jr=qr,Gr=jr,Lt=Gr;var _e=class{name;prefix;baseEncode;constructor(e,t,n){this.name=e,this.prefix=t,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},ke=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,t,n){if(this.name=e,this.prefix=t,t.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=t.codePointAt(0),this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return Ot(this,e)}},Le=class{decoders;constructor(e){this.decoders=e}or(e){return Ot(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 Ot(r,e){return new Le({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var Oe=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,t,n,o){this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=o,this.encoder=new _e(e,t,n),this.decoder=new ke(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function ne({name:r,prefix:e,encode:t,decode:n}){return new Oe(r,e,t,n)}function q({name:r,prefix:e,alphabet:t}){let{encode:n,decode:o}=Lt(t,r);return ne({prefix:e,name:r,encode:n,decode:s=>D(o(s))})}function Wr(r,e,t,n){let o={};for(let g=0;g<e.length;++g)o[e[g]]=g;let s=r.length;for(;r[s-1]==="=";)--s;let i=new Uint8Array(s*t/8|0),a=0,p=0,f=0;for(let g=0;g<s;++g){let E=o[r[g]];if(E===void 0)throw new SyntaxError(`Non-${n} character`);p=p<<t|E,a+=t,a>=8&&(a-=8,i[f++]=255&p>>a)}if(a>=t||255&p<<8-a)throw new SyntaxError("Unexpected end of data");return i}function Hr(r,e,t){let n=e[e.length-1]==="=",o=(1<<t)-1,s="",i=0,a=0;for(let p=0;p<r.length;++p)for(a=a<<8|r[p],i+=8;i>t;)i-=t,s+=e[o&a>>i];if(i!==0&&(s+=e[o&a<<t-i]),n)for(;s.length*t&7;)s+="=";return s}function y({name:r,prefix:e,bitsPerChar:t,alphabet:n}){return ne({prefix:e,name:r,encode(o){return Hr(o,n,t)},decode(o){return Wr(o,n,t,r)}})}var T=q({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Xr=q({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Fe={};R(Fe,{base32:()=>$,base32hex:()=>Yr,base32hexpad:()=>en,base32hexpadupper:()=>tn,base32hexupper:()=>Zr,base32pad:()=>Qr,base32padupper:()=>Kr,base32upper:()=>Jr,base32z:()=>rn});var $=y({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Jr=y({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Qr=y({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Kr=y({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Yr=y({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Zr=y({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),en=y({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),tn=y({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),rn=y({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var nn=$t,Vt=128,on=127,sn=~on,cn=Math.pow(2,31);function $t(r,e,t){e=e||[],t=t||0;for(var n=t;r>=cn;)e[t++]=r&255|Vt,r/=128;for(;r&sn;)e[t++]=r&255|Vt,r>>>=7;return e[t]=r|0,$t.bytes=t-n+1,e}var an=$e,ln=128,Ft=127;function $e(r,n){var t=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw $e.bytes=0,new RangeError("Could not decode varint");i=r[s++],t+=o<28?(i&Ft)<<o:(i&Ft)*Math.pow(2,o),o+=7}while(i>=ln);return $e.bytes=s-n,t}var un=Math.pow(2,7),dn=Math.pow(2,14),pn=Math.pow(2,21),fn=Math.pow(2,28),hn=Math.pow(2,35),mn=Math.pow(2,42),gn=Math.pow(2,49),wn=Math.pow(2,56),xn=Math.pow(2,63),bn=function(r){return r<un?1:r<dn?2:r<pn?3:r<fn?4:r<hn?5:r<mn?6:r<gn?7:r<wn?8:r<xn?9:10},yn={encode:nn,decode:an,encodingLength:bn},vn=yn,fe=vn;function he(r,e=0){return[fe.decode(r,e),fe.decode.bytes]}function oe(r,e,t=0){return fe.encode(r,e,t),e}function se(r){return fe.encodingLength(r)}function X(r,e){let t=e.byteLength,n=se(r),o=n+se(t),s=new Uint8Array(o+t);return oe(r,s,0),oe(t,s,n),s.set(e,o),new ie(r,t,e,s)}function ve(r){let e=D(r),[t,n]=he(e),[o,s]=he(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new ie(t,o,i,e)}function zt(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&Mt(r.bytes,t.bytes)}}var ie=class{code;size;digest;bytes;constructor(e,t,n,o){this.code=e,this.size=t,this.digest=n,this.bytes=o}};function Bt(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return An(t,ze(r),e??T.encoder);default:return In(t,ze(r),e??$.encoder)}}var qt=new WeakMap;function ze(r){let e=qt.get(r);if(e==null){let t=new Map;return qt.set(r,t),t}return e}var j=class r{code;version;multihash;bytes;"/";constructor(e,t,n,o){this.code=t,this.version=e,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:t}=this;if(e!==me)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==Sn)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(t)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:e,digest:t}=this.multihash,n=X(e,t);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(e){return r.equals(this,e)}static equals(e,t){let n=t;return n!=null&&e.code===n.code&&e.version===n.version&&zt(e.multihash,n.multihash)}toString(e){return Bt(this,e)}toJSON(){return{"/":Bt(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??jt(n,o,s.bytes))}else if(t[Cn]===!0){let{version:n,multihash:o,code:s}=t,i=ve(o);return r.create(n,s,i)}else return null}static create(e,t,n){if(typeof t!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(t!==me)throw new Error(`Version 0 CID must use dag-pb (code: ${me}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let o=jt(e,t,n.bytes);return new r(e,t,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,me,e)}static createV1(e,t){return r.create(1,e,t)}static decode(e){let[t,n]=r.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return t}static decodeFirst(e){let t=r.inspectBytes(e),n=t.size-t.multihashSize,o=D(e.subarray(n,n+t.multihashSize));if(o.byteLength!==t.multihashSize)throw new Error("Incorrect length");let s=o.subarray(t.multihashSize-t.digestSize),i=new ie(t.multihashCode,t.digestSize,s,o);return[t.version===0?r.createV0(i):r.createV1(t.codec,i),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[E,x]=he(e.subarray(t));return t+=x,E},o=n(),s=me;if(o===18?(o=0,t=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=t,a=n(),p=n(),f=t+p,g=f-i;return{version:o,codec:s,multihashCode:a,digestSize:p,multihashSize:g,size:f}}static parse(e,t){let[n,o]=En(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 ze(s).set(n,e),s}};function En(r,e){switch(r[0]){case"Q":{let t=e??T;return[T.prefix,t.decode(`${T.prefix}${r}`)]}case T.prefix:{let t=e??T;return[T.prefix,t.decode(r)]}case $.prefix:{let t=e??$;return[$.prefix,t.decode(r)]}default:{if(e==null)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[r[0],e.decode(r)]}}}function An(r,e,t){let{prefix:n}=t;if(n!==T.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let o=e.get(n);if(o==null){let s=t.encode(r).slice(1);return e.set(n,s),s}else return o}function In(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 me=112,Sn=18;function jt(r,e,t){let n=se(r),o=n+se(e),s=new Uint8Array(o+t.byteLength);return oe(r,s,0),oe(e,s,n),s.set(t,o),s}var Cn=Symbol.for("@ipld/js-cid/CID");function Gt(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 Be={};R(Be,{base10:()=>Tn});var Tn=q({prefix:"9",name:"base10",alphabet:"0123456789"});var qe={};R(qe,{base16:()=>Pn,base16upper:()=>Rn});var Pn=y({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Rn=y({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var je={};R(je,{base2:()=>Nn});var Nn=y({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Ge={};R(Ge,{base256emoji:()=>kn});var Wt=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}"),Dn=Wt.reduce((r,e,t)=>(r[t]=e,r),[]),Mn=Wt.reduce((r,e,t)=>(r[e.codePointAt(0)]=t,r),[]);function Un(r){return r.reduce((e,t)=>(e+=Dn[t],e),"")}function _n(r){let e=[];for(let t of r){let n=Mn[t.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${t}`);e.push(n)}return new Uint8Array(e)}var kn=ne({prefix:"\u{1F680}",name:"base256emoji",encode:Un,decode:_n});var We={};R(We,{base36:()=>Ln,base36upper:()=>On});var Ln=q({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),On=q({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var He={};R(He,{base64:()=>Vn,base64pad:()=>Fn,base64url:()=>$n,base64urlpad:()=>zn});var Vn=y({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Fn=y({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),$n=y({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),zn=y({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Xe={};R(Xe,{base8:()=>Bn});var Bn=y({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Je={};R(Je,{identity:()=>qn});var qn=ne({prefix:"\0",name:"identity",encode:r=>_t(r),decode:r=>Ut(r)});var vs=new TextEncoder,Es=new TextDecoder;var Qe={};R(Qe,{identity:()=>Xn});var Ht=0,Wn="identity",Xt=D;function Hn(r){return X(Ht,Xt(r))}var Xn={code:Ht,name:Wn,encode:Xt,digest:Hn};var et={};R(et,{sha256:()=>Jn,sha512:()=>Qn});var Ze=te(H("crypto"),1);function Ye({name:r,code:e,encode:t}){return new Ke(r,e,t)}var Ke=class{name;code;encode;constructor(e,t,n){this.name=e,this.code=t,this.encode=n}digest(e){if(e instanceof Uint8Array){let t=this.encode(e);return t instanceof Uint8Array?X(this.code,t):t.then(n=>X(this.code,n))}else throw Error("Unknown type, must be binary type")}};var Jn=Ye({name:"sha2-256",code:18,encode:r=>D(Ze.default.createHash("sha256").update(r).digest())}),Qn=Ye({name:"sha2-512",code:19,encode:r=>D(Ze.default.createHash("sha512").update(r).digest())});var ge={...Je,...je,...Xe,...Be,...qe,...Fe,...We,...Ve,...He,...Ge},Ls={...et,...Qe};function J(r){return globalThis.Buffer!=null?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):r}function ae(r=0){return globalThis.Buffer?.allocUnsafe!=null?J(globalThis.Buffer.allocUnsafe(r)):new Uint8Array(r)}function Kt(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var Qt=Kt("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),tt=Kt("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}),Kn={utf8:Qt,"utf-8":Qt,hex:ge.base16,latin1:tt,ascii:tt,binary:tt,...ge},Ee=Kn;function P(r,e="utf8"){let t=Ee[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return(e==="utf8"||e==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?globalThis.Buffer.from(r.buffer,r.byteOffset,r.byteLength).toString("utf8"):t.encoder.encode(r).substring(1)}var Yn=Math.pow(2,7),Zn=Math.pow(2,14),eo=Math.pow(2,21),rt=Math.pow(2,28),nt=Math.pow(2,35),ot=Math.pow(2,42),st=Math.pow(2,49),h=128,S=127;function V(r){if(r<Yn)return 1;if(r<Zn)return 2;if(r<eo)return 3;if(r<rt)return 4;if(r<nt)return 5;if(r<ot)return 6;if(r<st)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function to(r,e,t=0){switch(V(r)){case 8:e[t++]=r&255|h,r/=128;case 7:e[t++]=r&255|h,r/=128;case 6:e[t++]=r&255|h,r/=128;case 5:e[t++]=r&255|h,r/=128;case 4:e[t++]=r&255|h,r>>>=7;case 3:e[t++]=r&255|h,r>>>=7;case 2:e[t++]=r&255|h,r>>>=7;case 1:{e[t++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return e}function ro(r,e,t=0){switch(V(r)){case 8:e.set(t++,r&255|h),r/=128;case 7:e.set(t++,r&255|h),r/=128;case 6:e.set(t++,r&255|h),r/=128;case 5:e.set(t++,r&255|h),r/=128;case 4:e.set(t++,r&255|h),r>>>=7;case 3:e.set(t++,r&255|h),r>>>=7;case 2:e.set(t++,r&255|h),r>>>=7;case 1:{e.set(t++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return e}function no(r,e){let t=r[e],n=0;if(n+=t&S,t<h||(t=r[e+1],n+=(t&S)<<7,t<h)||(t=r[e+2],n+=(t&S)<<14,t<h)||(t=r[e+3],n+=(t&S)<<21,t<h)||(t=r[e+4],n+=(t&S)*rt,t<h)||(t=r[e+5],n+=(t&S)*nt,t<h)||(t=r[e+6],n+=(t&S)*ot,t<h)||(t=r[e+7],n+=(t&S)*st,t<h))return n;throw new RangeError("Could not decode varint")}function oo(r,e){let t=r.get(e),n=0;if(n+=t&S,t<h||(t=r.get(e+1),n+=(t&S)<<7,t<h)||(t=r.get(e+2),n+=(t&S)<<14,t<h)||(t=r.get(e+3),n+=(t&S)<<21,t<h)||(t=r.get(e+4),n+=(t&S)*rt,t<h)||(t=r.get(e+5),n+=(t&S)*nt,t<h)||(t=r.get(e+6),n+=(t&S)*ot,t<h)||(t=r.get(e+7),n+=(t&S)*st,t<h))return n;throw new RangeError("Could not decode varint")}function le(r,e,t=0){return e==null&&(e=ae(V(r))),e instanceof Uint8Array?to(r,e,t):ro(r,e,t)}function Q(r,e=0){return r instanceof Uint8Array?no(r,e):oo(r,e)}function z(r,e){if(globalThis.Buffer!=null)return J(globalThis.Buffer.concat(r,e));e==null&&(e=r.reduce((o,s)=>o+s.length,0));let t=ae(e),n=0;for(let o of r)t.set(o,n),n+=o.length;return J(t)}var Ae=class{index=0;input="";new(e){return this.index=0,this.input=e,this}readAtomically(e){let t=this.index,n=e();return n===void 0&&(this.index=t),n}parseWith(e){let t=e();if(this.index===this.input.length)return t}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(e){return this.readAtomically(()=>{let t=this.readChar();if(t===e)return t})}readSeparator(e,t,n){return this.readAtomically(()=>{if(!(t>0&&this.readGivenChar(e)===void 0))return n()})}readNumber(e,t,n,o){return this.readAtomically(()=>{let s=0,i=0,a=this.peekChar();if(a===void 0)return;let p=a==="0",f=2**(8*o)-1;for(;;){let g=this.readAtomically(()=>{let E=this.readChar();if(E===void 0)return;let x=Number.parseInt(E,e);if(!Number.isNaN(x))return x});if(g===void 0)break;if(s*=e,s+=g,s>f||(i+=1,t!==void 0&&i>t))return}if(i!==0)return!n&&p&&i>1?void 0:s})}readIPv4Addr(){return this.readAtomically(()=>{let e=new Uint8Array(4);for(let t=0;t<e.length;t++){let n=this.readSeparator(".",t,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;e[t]=n}return e})}readIPv6Addr(){let e=t=>{for(let n=0;n<t.length/2;n++){let o=n*2;if(n<t.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return t[o]=i[0],t[o+1]=i[1],t[o+2]=i[2],t[o+3]=i[3],[o+4,!0]}let s=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(s===void 0)return[o,!1];t[o]=s>>8,t[o+1]=s&255}return[t.length,!1]};return this.readAtomically(()=>{let t=new Uint8Array(16),[n,o]=e(t);if(n===16)return t;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let s=new Uint8Array(14),i=16-(n+2),[a]=e(s.subarray(0,i));return t.set(s.subarray(0,a),16-a),t})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var Ys=new Ae;var ii=parseInt("0xFFFF",16),ci=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function it(r,e="utf8"){let t=Ee[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return(e==="utf8"||e==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?J(globalThis.Buffer.from(r,"utf-8")):t.decoder.decode(`${t.prefix}${r}`)}var M=H("node:net");function Ie(r){return!!(0,M.isIP)(r)}var tr=M.isIPv4,uo=M.isIPv6,ct=function(r){let e=0;if(r=r.toString().trim(),tr(r)){let t=new Uint8Array(e+4);return r.split(/\./g).forEach(n=>{t[e++]=parseInt(n,10)&255}),t}if(uo(r)){let t=r.split(":",8),n;for(n=0;n<t.length;n++){let s=tr(t[n]),i;s&&(i=ct(t[n]),t[n]=P(i.slice(0,2),"base16")),i!=null&&++n<8&&t.splice(n,0,P(i.slice(2,4),"base16"))}if(t[0]==="")for(;t.length<8;)t.unshift("0");else if(t[t.length-1]==="")for(;t.length<8;)t.push("0");else if(t.length<8){for(n=0;n<t.length&&t[n]!=="";n++);let s=[n,1];for(n=9-t.length;n>0;n--)s.push("0");t.splice.apply(t,s)}let o=new Uint8Array(e+16);for(n=0;n<t.length;n++){let s=parseInt(t[n],16);o[e++]=s>>8&255,o[e++]=s&255}return o}throw new Error("invalid ip address")},rr=function(r,e=0,t){e=~~e,t=t??r.length-e;let n=new DataView(r.buffer);if(t===4){let o=[];for(let s=0;s<t;s++)o.push(r[e+s]);return o.join(".")}if(t===16){let o=[];for(let s=0;s<t;s+=2)o.push(n.getUint16(e+s).toString(16));return o.join(":").replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}return""};var ue={},at={},fo=[[4,32,"ip4"],[6,16,"tcp"],[33,16,"dccp"],[41,128,"ip6"],[42,-1,"ip6zone"],[43,8,"ipcidr"],[53,-1,"dns",!0],[54,-1,"dns4",!0],[55,-1,"dns6",!0],[56,-1,"dnsaddr",!0],[132,16,"sctp"],[273,16,"udp"],[275,0,"p2p-webrtc-star"],[276,0,"p2p-webrtc-direct"],[277,0,"p2p-stardust"],[280,0,"webrtc-direct"],[281,0,"webrtc"],[290,0,"p2p-circuit"],[301,0,"udt"],[302,0,"utp"],[400,-1,"unix",!1,!0],[421,-1,"ipfs"],[421,-1,"p2p"],[443,0,"https"],[444,96,"onion"],[445,296,"onion3"],[446,-1,"garlic64"],[448,0,"tls"],[449,-1,"sni"],[460,0,"quic"],[461,0,"quic-v1"],[465,0,"webtransport"],[466,-1,"certhash"],[477,0,"ws"],[478,0,"wss"],[479,0,"p2p-websocket-star"],[480,0,"http"],[777,-1,"memory"]];fo.forEach(r=>{let e=ho(...r);at[e.code]=e,ue[e.name]=e});function ho(r,e,t,n,o){return{code:r,size:e,name:t,resolvable:!!n,path:!!o}}function w(r){if(typeof r=="number"){if(at[r]!=null)return at[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(ue[r]!=null)return ue[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var Xi=w("ip4"),Ji=w("ip6"),Qi=w("ipcidr");function ut(r,e){switch(w(r).code){case 4:case 41:return go(e);case 42:return sr(e);case 6:case 273:case 33:case 132:return cr(e).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return sr(e);case 421:return yo(e);case 444:return ir(e);case 445:return ir(e);case 466:return bo(e);default:return P(e,"base16")}}function dt(r,e){switch(w(r).code){case 4:return nr(e);case 41:return nr(e);case 42:return or(e);case 6:case 273:case 33:case 132:return pt(parseInt(e,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return or(e);case 421:return wo(e);case 444:return vo(e);case 445:return Eo(e);case 466:return xo(e);default:return it(e,"base16")}}var lt=Object.values(ge).map(r=>r.decoder),mo=function(){let r=lt[0].or(lt[1]);return lt.slice(2).forEach(e=>r=r.or(e)),r}();function nr(r){if(!Ie(r))throw new Error("invalid ip address");return ct(r)}function go(r){let e=rr(r,0,r.length);if(e==null)throw new Error("ipBuff is required");if(!Ie(e))throw new Error("invalid ip address");return e}function pt(r){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,r),new Uint8Array(e)}function cr(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function or(r){let e=it(r),t=Uint8Array.from(le(e.length));return z([t,e],t.length+e.length)}function sr(r){let e=Q(r);if(r=r.slice(V(e)),r.length!==e)throw new Error("inconsistent lengths");return P(r)}function wo(r){let e;r[0]==="Q"||r[0]==="1"?e=ve(T.decode(`z${r}`)).bytes:e=j.parse(r).multihash.bytes;let t=Uint8Array.from(le(e.length));return z([t,e],t.length+e.length)}function xo(r){let e=mo.decode(r),t=Uint8Array.from(le(e.length));return z([t,e],t.length+e.length)}function bo(r){let e=Q(r),t=r.slice(V(e));if(t.length!==e)throw new Error("inconsistent lengths");return"u"+P(t,"base64url")}function yo(r){let e=Q(r),t=r.slice(V(e));if(t.length!==e)throw new Error("inconsistent lengths");return P(t,"base58btc")}function vo(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=pt(n);return z([t,o],t.length+o.length)}function Eo(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=pt(n);return z([t,o],t.length+o.length)}function ir(r){let e=r.slice(0,r.length-2),t=r.slice(r.length-2),n=P(e,"base32"),o=cr(t);return`${n}:${o}`}function ar(r){r=ft(r);let e=[],t=[],n=null,o=r.split("/").slice(1);if(o.length===1&&o[0]==="")return{bytes:new Uint8Array,string:"/",tuples:[],stringTuples:[],path:null};for(let s=0;s<o.length;s++){let i=o[s],a=w(i);if(a.size===0){e.push([a.code]),t.push([a.code]);continue}if(s++,s>=o.length)throw ur("invalid address: "+r);if(a.path===!0){n=ft(o.slice(s).join("/")),e.push([a.code,dt(a.code,n)]),t.push([a.code,n]);break}let p=dt(a.code,o[s]);e.push([a.code,p]),t.push([a.code,ut(a.code,p)])}return{string:lr(t),bytes:mt(e),tuples:e,stringTuples:t,path:n}}function ht(r){let e=[],t=[],n=null,o=0;for(;o<r.length;){let s=Q(r,o),i=V(s),a=w(s),p=Ao(a,r.slice(o+i));if(p===0){e.push([s]),t.push([s]),o+=i;continue}let f=r.slice(o+i,o+i+p);if(o+=p+i,o>r.length)throw ur("Invalid address Uint8Array: "+P(r,"base16"));e.push([s,f]);let g=ut(s,f);if(t.push([s,g]),a.path===!0){n=g;break}}return{bytes:Uint8Array.from(r),string:lr(t),tuples:e,stringTuples:t,path:n}}function lr(r){let e=[];return r.map(t=>{let n=w(t[0]);return e.push(n.name),t.length>1&&t[1]!=null&&e.push(t[1]),null}),ft(e.join("/"))}function mt(r){return z(r.map(e=>{let t=w(e[0]),n=Uint8Array.from(le(t.code));return e.length>1&&e[1]!=null&&(n=z([n,e[1]])),n}))}function Ao(r,e){if(r.size>0)return r.size/8;if(r.size===0)return 0;{let t=Q(e instanceof Uint8Array?e:Uint8Array.from(e));return t+V(t)}}function ft(r){return"/"+r.trim().split("/").filter(e=>e).join("/")}function ur(r){return new Error("Error parsing address: "+r)}var Io=Symbol.for("nodejs.util.inspect.custom"),gt=Symbol.for("@multiformats/js-multiaddr/multiaddr"),So=[w("dns").code,w("dns4").code,w("dns6").code,w("dnsaddr").code],Se=class r{bytes;#e;#t;#r;#n;[gt]=!0;constructor(e){e==null&&(e="");let t;if(e instanceof Uint8Array)t=ht(e);else if(typeof e=="string"){if(e.length>0&&e.charAt(0)!=="/")throw new Error(`multiaddr "${e}" must start with a "/"`);t=ar(e)}else if(pr(e))t=ht(e.bytes);else throw new Error("addr must be a string, Buffer, or another Multiaddr");this.bytes=t.bytes,this.#e=t.string,this.#t=t.tuples,this.#r=t.stringTuples,this.#n=t.path}toString(){return this.#e}toJSON(){return this.toString()}toOptions(){let e,t,n,o,s="",i=w("tcp"),a=w("udp"),p=w("ip4"),f=w("ip6"),g=w("dns6"),E=w("ip6zone");for(let[d,u]of this.stringTuples())d===E.code&&(s=`%${u??""}`),So.includes(d)&&(t=i.name,o=443,n=`${u??""}${s}`,e=d===g.code?6:4),(d===i.code||d===a.code)&&(t=w(d).name,o=parseInt(u??"")),(d===p.code||d===f.code)&&(t=w(d).name,n=`${u??""}${s}`,e=d===f.code?6:4);if(e==null||t==null||n==null||o==null)throw new Error('multiaddr must have a valid format: "/{ip4, ip6, dns4, dns6, dnsaddr}/{address}/{tcp, udp}/{port}".');return{family:e,host:n,transport:t,port:o}}protos(){return this.#t.map(([e])=>Object.assign({},w(e)))}protoCodes(){return this.#t.map(([e])=>e)}protoNames(){return this.#t.map(([e])=>w(e).name)}tuples(){return this.#t}stringTuples(){return this.#r}encapsulate(e){return e=new r(e),new r(this.toString()+e.toString())}decapsulate(e){let t=e.toString(),n=this.toString(),o=n.lastIndexOf(t);if(o<0)throw new Error(`Address ${this.toString()} does not contain subaddress: ${e.toString()}`);return new r(n.slice(0,o))}decapsulateCode(e){let t=this.tuples();for(let n=t.length-1;n>=0;n--)if(t[n][0]===e)return new r(mt(t.slice(0,n)));return this}getPeerId(){try{let e=[];this.stringTuples().forEach(([n,o])=>{n===ue.p2p.code&&e.push([n,o]),n===ue["p2p-circuit"].code&&(e=[])});let t=e.pop();if(t?.[1]!=null){let n=t[1];return n[0]==="Q"||n[0]==="1"?P(T.decode(`z${n}`),"base58btc"):P(j.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){return this.#n}equals(e){return Gt(this.bytes,e.bytes)}async resolve(e){let t=this.protos().find(s=>s.resolvable);if(t==null)return[this];let n=dr.get(t.name);if(n==null)throw new A(`no available resolver for ${t.name}`,"ERR_NO_AVAILABLE_RESOLVER");return(await n(this,e)).map(s=>k(s))}nodeAddress(){let e=this.toOptions();if(e.transport!=="tcp"&&e.transport!=="udp")throw new Error(`multiaddr must have a valid format - no protocol with name: "${e.transport}". Must have a valid transport protocol: "{tcp, udp}"`);return{family:e.family,address:e.host,port:e.port}}isThinWaistAddress(e){let t=(e??this).protos();return!(t.length!==2||t[0].code!==4&&t[0].code!==41||t[1].code!==6&&t[1].code!==273)}[Io](){return`Multiaddr(${this.#e})`}};var dr=new Map;function pr(r){return!!r?.[gt]}function k(r){return new Se(r)}var Co=c("dns4"),To=c("dns6"),Po=c("dnsaddr"),Y=v(c("dns"),Po,Co,To),Pe=v(c("ip4"),c("ip6")),W=v(l(Pe,c("tcp")),l(Y,c("tcp"))),Re=l(Pe,c("udp")),Ro=l(Re,c("utp")),No=l(Re,c("quic")),Do=l(Re,c("quic-v1")),wt=v(l(W,c("ws")),l(Y,c("ws"))),Ce=v(l(wt,c("p2p")),wt),xt=v(l(W,c("wss")),l(Y,c("wss")),l(W,c("tls"),c("ws")),l(Y,c("tls"),c("ws"))),Te=v(l(xt,c("p2p")),xt),bt=v(l(W,c("http")),l(Pe,c("http")),l(Y,c("http"))),yt=v(l(W,c("https")),l(Pe,c("https")),l(Y,c("https"))),fr=l(Re,c("webrtc-direct"),c("certhash")),gr=v(l(fr,c("p2p")),fr),hr=l(Do,c("webtransport"),c("certhash"),c("certhash")),wr=v(l(hr,c("p2p")),hr),xr=v(l(Ce,c("p2p-webrtc-star"),c("p2p")),l(Te,c("p2p-webrtc-star"),c("p2p")),l(Ce,c("p2p-webrtc-star")),l(Te,c("p2p-webrtc-star"))),Ec=v(l(Ce,c("p2p-websocket-star"),c("p2p")),l(Te,c("p2p-websocket-star"),c("p2p")),l(Ce,c("p2p-websocket-star")),l(Te,c("p2p-websocket-star"))),br=v(l(bt,c("p2p-webrtc-direct"),c("p2p")),l(yt,c("p2p-webrtc-direct"),c("p2p")),l(bt,c("p2p-webrtc-direct")),l(yt,c("p2p-webrtc-direct"))),Z=v(wt,xt,bt,yt,xr,br,W,Ro,No,Y,gr,wr),Ac=v(l(Z,c("p2p-stardust"),c("p2p")),l(Z,c("p2p-stardust"))),G=v(l(Z,c("p2p")),xr,br,gr,wr,c("p2p")),mr=v(l(G,c("p2p-circuit"),G),l(G,c("p2p-circuit")),l(c("p2p-circuit"),G),l(Z,c("p2p-circuit")),l(c("p2p-circuit"),Z),c("p2p-circuit")),yr=()=>v(l(mr,yr),mr),K=yr(),Ic=v(l(K,G,K),l(G,K),l(K,G),K,G);var Sc=v(l(K,c("webrtc"),c("p2p")),l(K,c("webrtc")),l(Z,c("webrtc"),c("p2p")),l(Z,c("webrtc")),c("webrtc"));function vr(r){function e(t){let n;try{n=k(t)}catch{return!1}let o=r(n.protoNames());return o===null?!1:o===!0||o===!1?o:o.length===0}return e}function l(...r){function e(t){if(t.length<r.length)return null;let n=t;return r.some(o=>(n=typeof o=="function"?o().partialMatch(t):o.partialMatch(t),Array.isArray(n)&&(t=n),n===null)),n}return{toString:function(){return"{ "+r.join(" ")+" }"},input:r,matches:vr(e),partialMatch:e}}function v(...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:vr(e),partialMatch:e}}function c(r){let e=r;function t(o){let s;try{s=k(o)}catch{return!1}let i=s.protoNames();return i.length===1&&i[0]===e}function n(o){return o.length===0?null:o[0]===e?o.slice(1):null}return{toString:function(){return e},matches:t,partialMatch:n}}var _r=te(H("net"),1);var vt={ERR_INVALID_IP_PARAMETER:"ERR_INVALID_IP_PARAMETER",ERR_INVALID_PORT_PARAMETER:"ERR_INVALID_PORT_PARAMETER",ERR_INVALID_IP:"ERR_INVALID_IP"};function Er(r,e){if(typeof r!="string")throw new A(`invalid ip provided: ${r}`,vt.ERR_INVALID_IP_PARAMETER);if(typeof e=="string"&&(e=parseInt(e)),isNaN(e))throw new A(`invalid port provided: ${e}`,vt.ERR_INVALID_PORT_PARAMETER);if((0,M.isIPv4)(r))return k(`/ip4/${r}/tcp/${e}`);if((0,M.isIPv6)(r))return k(`/ip6/${r}/tcp/${e}`);throw new A(`invalid ip:port for creating a multiaddr: ${r}:${e}`,vt.ERR_INVALID_IP)}var Mr=te(Nr(),1);var It=te(H("os"),1),Dr=te(H("path"),1);var Oo={ip4:"IPv4",ip6:"IPv6"};function pe(r,e={}){let t=r.getPath();return t!=null?It.default.platform()==="win32"?{path:Dr.default.join("\\\\.\\pipe\\",t)}:{path:t}:{...e,...r.toOptions()}}function St(r,e,t){let n=o=>k(`/${r}/${o}/tcp/${t}`);return(Vo(e)?$o(Oo[r]):[e]).map(n)}function Vo(r){return["0.0.0.0","::"].includes(r)}var Fo=It.default.networkInterfaces();function $o(r){let e=[];for(let[,t]of Object.entries(Fo))if(t!=null)for(let n of t)n.family===r&&e.push(n.address);return e}var De=(r,e)=>{let t=e.logger.forComponent("libp2p:tcp:socket"),n=e.metrics,o=e.metricPrefix??"",s=e.socketInactivityTimeout??3e5,i=e.socketCloseTimeout??500;e.listeningAddr?.getPath()!=null&&(e.remoteAddr=e.listeningAddr),e.remoteAddr?.getPath()!=null&&(e.localAddr=e.remoteAddr);let a;if(e.remoteAddr!=null)a=e.remoteAddr;else{if(r.remoteAddress==null||r.remotePort==null)throw new A("Could not determine remote address or port","ERR_NO_REMOTE_ADDRESS");a=Er(r.remoteAddress,r.remotePort)}let p=pe(a),f=p.path??`${p.host??""}:${p.port??""}`,{sink:g,source:E}=Mr.default.duplex(r);r.setTimeout(s,()=>{t("%s socket read timeout",f),n?.increment({[`${o}timeout`]:!0});let d;r.readable&&(d=new A("Socket read timeout","ERR_SOCKET_READ_TIMEOUT")),r.destroy(d)}),r.once("close",()=>{t("%s socket close",f),n?.increment({[`${o}close`]:!0}),x.timeline.close==null&&(x.timeline.close=Date.now())}),r.once("end",()=>{t("%s socket end",f),n?.increment({[`${o}end`]:!0})});let x={async sink(d){try{await g(async function*(){for await(let u of d)u instanceof Uint8Array?yield u:yield u.subarray()}())}catch(u){u.type!=="aborted"&&t.error("%s error in sink",f,u)}r.end()},source:E,remoteAddr:a,timeline:{open:Date.now()},async close(d={}){if(r.destroyed){t("%s socket was already destroyed when trying to close",f);return}if(d.signal==null){let b=AbortSignal.timeout(i);d={...d,signal:b}}let u=()=>{r.destroy(new A("Destroying socket after timeout","ERR_CLOSE_TIMEOUT"))};d.signal?.addEventListener("abort",u);try{t("%s closing socket",f),await new Promise((b,U)=>{r.once("close",()=>{t("%s socket closed",f),b()}),r.once("error",m=>{t("%s socket error",f,m),x.timeline.close==null&&(x.timeline.close=Date.now()),U(m)}),r.setTimeout(i),r.end(),r.writableLength>0?r.once("drain",()=>{t("%s socket drained",f),r.destroy()}):r.destroy()})}catch(b){this.abort(b)}finally{d.signal?.removeEventListener("abort",u)}},abort:d=>{t("%s socket abort due to error",f,d),r.destroy(d),x.timeline.close==null&&(x.timeline.close=Date.now())},log:t};return x};async function Ur(r,e){try{await r.close()}catch(t){e.log.error("an error occurred closing the connection",t),r.abort(t)}}var I;(function(r){r[r.INACTIVE=0]="INACTIVE",r[r.ACTIVE=1]="ACTIVE",r[r.PAUSED=2]="PAUSED"})(I||(I={}));var Me=class extends be{context;server;connections=new Set;status={code:I.INACTIVE};metrics;addr;log;constructor(e){if(super(),this.context=e,e.keepAlive=e.keepAlive??!0,e.noDelay=e.noDelay??!0,this.log=e.logger.forComponent("libp2p:tcp:listener"),this.addr="unknown",this.server=_r.default.createServer(e,this.onSocket.bind(this)),e.maxConnections!==void 0&&(this.server.maxConnections=e.maxConnections),e.closeServerOnMaxConnections!=null&&e.closeServerOnMaxConnections.closeAbove<e.closeServerOnMaxConnections.listenBelow)throw new A("closeAbove must be >= listenBelow","ERR_CONNECTION_LIMITS");this.server.on("listening",()=>{if(e.metrics!=null){let t=this.server.address();t==null?this.addr="unknown":typeof t=="string"?this.addr=t:this.addr=`${t.address}:${t.port}`,e.metrics?.registerMetricGroup("libp2p_tcp_inbound_connections_total",{label:"address",help:"Current active connections in TCP listener",calculate:()=>({[this.addr]:this.connections.size})}),this.metrics={status:e.metrics.registerMetricGroup("libp2p_tcp_listener_status_info",{label:"address",help:"Current status of the TCP listener socket"}),errors:e.metrics.registerMetricGroup("libp2p_tcp_listener_errors_total",{label:"address",help:"Total count of TCP listener errors by type"}),events:e.metrics.registerMetricGroup("libp2p_tcp_listener_events_total",{label:"address",help:"Total count of TCP listener events by type"})},this.metrics?.status.update({[this.addr]:I.ACTIVE})}this.safeDispatchEvent("listening")}).on("error",t=>{this.metrics?.errors.increment({[`${this.addr} listen_error`]:!0}),this.safeDispatchEvent("error",{detail:t})}).on("close",()=>{this.metrics?.status.update({[this.addr]:this.status.code}),this.status.code!==I.PAUSED&&this.safeDispatchEvent("close")})}onSocket(e){if(this.status.code!==I.ACTIVE)throw new A("Server is is not listening yet","ERR_SERVER_NOT_RUNNING");e.on("error",n=>{this.log("socket error",n),this.metrics?.events.increment({[`${this.addr} error`]:!0})});let t;try{t=De(e,{listeningAddr:this.status.listeningAddr,socketInactivityTimeout:this.context.socketInactivityTimeout,socketCloseTimeout:this.context.socketCloseTimeout,metrics:this.metrics?.events,metricPrefix:`${this.addr} `,logger:this.context.logger})}catch(n){this.log.error("inbound connection failed",n),this.metrics?.errors.increment({[`${this.addr} inbound_to_connection`]:!0});return}this.log("new inbound connection %s",t.remoteAddr);try{this.context.upgrader.upgradeInbound(t).then(n=>{this.log("inbound connection upgraded %s",t.remoteAddr),this.connections.add(t),e.once("close",()=>{this.connections.delete(t),this.context.closeServerOnMaxConnections!=null&&this.connections.size<this.context.closeServerOnMaxConnections.listenBelow&&this.resume().catch(o=>{this.log.error("error attempting to listen server once connection count under limit",o),this.context.closeServerOnMaxConnections?.onListenError?.(o)})}),this.context.handler!=null&&this.context.handler(n),this.context.closeServerOnMaxConnections!=null&&this.connections.size>=this.context.closeServerOnMaxConnections.closeAbove&&this.pause(!1).catch(o=>{this.log.error("error attempting to close server once connection count over limit",o)}),this.safeDispatchEvent("connection",{detail:n})}).catch(async n=>{this.log.error("inbound connection failed",n),this.metrics?.errors.increment({[`${this.addr} inbound_upgrade`]:!0}),await Ur(t,{log:this.log})}).catch(n=>{this.log.error("closing inbound connection failed",n)})}catch(n){this.log.error("inbound connection failed",n),Ur(t,{log:this.log}).catch(o=>{this.log.error("closing inbound connection failed",o),this.metrics?.errors.increment({[`${this.addr} inbound_closing_failed`]:!0})})}}getAddrs(){if(this.status.code===I.INACTIVE)return[];let e=[],t=this.server.address(),{listeningAddr:n,peerId:o}=this.status;if(t==null)return[];if(typeof t=="string")e=[n];else try{n.toString().startsWith("/ip4")?e=e.concat(St("ip4",t.address,t.port)):t.family==="IPv6"&&(e=e.concat(St("ip6",t.address,t.port)))}catch(s){this.log.error("could not turn %s:%s into multiaddr",t.address,t.port,s)}return e.map(s=>o!=null?s.encapsulate(`/p2p/${o}`):s)}async listen(e){if(this.status.code===I.ACTIVE||this.status.code===I.PAUSED)throw new A("server is already listening","ERR_SERVER_ALREADY_LISTENING");let t=e.getPeerId(),n=t==null?e.decapsulateCode(421):e,{backlog:o}=this.context;try{this.status={code:I.ACTIVE,listeningAddr:n,peerId:t,netConfig:pe(n,{backlog:o})},await this.resume()}catch(s){throw this.status={code:I.INACTIVE},s}}async close(){let e=new A("Listener is closing","ERR_LISTENER_CLOSING");this.connections.forEach(t=>{t.abort(e)}),await this.pause(!0)}async resume(){if(this.server.listening||this.status.code===I.INACTIVE)return;let e=this.status.netConfig;await new Promise((t,n)=>{this.server.once("error",n),this.server.listen(e,t)}),this.status={...this.status,code:I.ACTIVE},this.log("listening on %s",this.server.address())}async pause(e){if(!this.server.listening&&this.status.code===I.PAUSED&&e){this.status={code:I.INACTIVE};return}!this.server.listening||this.status.code!==I.ACTIVE||(this.log("closing server on %s",this.server.address()),this.status=e?{code:I.INACTIVE}:{...this.status,code:I.PAUSED},await new Promise((t,n)=>{this.server.close(o=>{if(o!=null){n(o);return}t()})}))}};var Ct=class{opts;metrics;components;log;constructor(e,t={}){this.log=e.logger.forComponent("libp2p:tcp"),this.opts=t,this.components=e,e.metrics!=null&&(this.metrics={dialerEvents:e.metrics.registerCounterGroup("libp2p_tcp_dialer_events_total",{label:"event",help:"Total count of TCP dialer events by type"})})}[Rt]=!0;[Symbol.toStringTag]="@libp2p/tcp";async dial(e,t){t.keepAlive=t.keepAlive??!0,t.noDelay=t.noDelay??!0;let n=await this._connect(e,t);n.on("error",a=>{this.log("socket error",a)});let o=De(n,{remoteAddr:e,socketInactivityTimeout:this.opts.outboundSocketInactivityTimeout,socketCloseTimeout:this.opts.socketCloseTimeout,metrics:this.metrics?.dialerEvents,logger:this.components.logger}),s=()=>{o.close().catch(a=>{this.log.error("Error closing maConn after abort",a)})};t.signal?.addEventListener("abort",s,{once:!0}),this.log("new outbound connection %s",o.remoteAddr);let i=await t.upgrader.upgradeOutbound(o);if(this.log("outbound connection %s upgraded",o.remoteAddr),t.signal?.removeEventListener("abort",s),t.signal?.aborted===!0)throw i.close().catch(a=>{this.log.error("Error closing conn after abort",a)}),new re;return i}async _connect(e,t){if(t.signal?.aborted===!0)throw new re;return new Promise((n,o)=>{let s=Date.now(),i=pe(e,{...this.opts.dialOpts??{},...t});this.log("dialing %a",e);let a=kr.default.connect(i),p=d=>{let u=i.path??`${i.host??""}:${i.port}`;d.message=`connection error ${u}: ${d.message}`,this.metrics?.dialerEvents.increment({error:!0}),x(d)},f=()=>{this.log("connection timeout %a",e),this.metrics?.dialerEvents.increment({timeout:!0});let d=new A(`connection timeout after ${Date.now()-s}ms`,"ERR_CONNECT_TIMEOUT");a.emit("error",d)},g=()=>{this.log("connection opened %a",e),this.metrics?.dialerEvents.increment({connect:!0}),x()},E=()=>{this.log("connection aborted %a",e),this.metrics?.dialerEvents.increment({abort:!0}),a.destroy(),x(new re)},x=d=>{if(a.removeListener("error",p),a.removeListener("timeout",f),a.removeListener("connect",g),t.signal!=null&&t.signal.removeEventListener("abort",E),d!=null){o(d);return}n(a)};a.on("error",p),a.on("timeout",f),a.on("connect",g),t.signal!=null&&t.signal.addEventListener("abort",E)})}createListener(e){return new Me({...this.opts.listenOpts??{},...e,maxConnections:this.opts.maxConnections,backlog:this.opts.backlog,closeServerOnMaxConnections:this.opts.closeServerOnMaxConnections,socketInactivityTimeout:this.opts.inboundSocketInactivityTimeout,socketCloseTimeout:this.opts.socketCloseTimeout,metrics:this.components.metrics,logger:this.components.logger})}filter(e){return e=Array.isArray(e)?e:[e],e.filter(t=>t.protoCodes().includes(290)?!1:t.protoCodes().includes(400)?!0:W.matches(t.decapsulateCode(421)))}};function Bo(r={}){return e=>new Ct(e,r)}return zr(qo);})();
3
3
  return Libp2PTcp}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@libp2p/tcp",
3
- "version": "9.0.16-ab466004b",
3
+ "version": "9.0.16-e1798aa26",
4
4
  "description": "A TCP transport for libp2p",
5
5
  "license": "Apache-2.0 OR MIT",
6
6
  "homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/transport-tcp#readme",
@@ -56,16 +56,16 @@
56
56
  "test:electron-main": "aegir test -t electron-main"
57
57
  },
58
58
  "dependencies": {
59
- "@libp2p/interface": "1.1.4-ab466004b",
60
- "@libp2p/utils": "5.2.6-ab466004b",
59
+ "@libp2p/interface": "1.1.4-e1798aa26",
60
+ "@libp2p/utils": "5.2.6-e1798aa26",
61
61
  "@multiformats/mafmt": "^12.1.6",
62
62
  "@multiformats/multiaddr": "^12.1.14",
63
63
  "@types/sinon": "^17.0.3",
64
64
  "stream-to-it": "^0.2.4"
65
65
  },
66
66
  "devDependencies": {
67
- "@libp2p/interface-compliance-tests": "5.3.2-ab466004b",
68
- "@libp2p/logger": "4.0.7-ab466004b",
67
+ "@libp2p/interface-compliance-tests": "5.3.2-e1798aa26",
68
+ "@libp2p/logger": "4.0.7-e1798aa26",
69
69
  "aegir": "^42.2.4",
70
70
  "it-all": "^3.0.4",
71
71
  "it-pipe": "^3.0.1",