@libp2p/tcp
Advanced tools
Comparing version 10.1.2 to 10.1.3-e1f868f03
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PTcp = factory()}(typeof self !== 'undefined' ? self : this, function () { | ||
"use strict";var Libp2PTcp=(()=>{var Rr=Object.create;var xe=Object.defineProperty;var jr=Object.getOwnPropertyDescriptor;var qr=Object.getOwnPropertyNames;var Wr=Object.getPrototypeOf,Gr=Object.prototype.hasOwnProperty;var F=(r=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(r,{get:(e,t)=>(typeof require<"u"?require:e)[t]}):r)(function(r){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+r+'" is not supported')});var D=(r,e)=>{for(var t in e)xe(r,t,{get:e[t],enumerable:!0})},Vt=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of qr(e))!Gr.call(r,o)&&o!==t&&xe(r,o,{get:()=>e[o],enumerable:!(n=jr(e,o))||n.enumerable});return r};var le=(r,e,t)=>(t=r!=null?Rr(Wr(r)):{},Vt(e||!r||!r.__esModule?xe(t,"default",{value:r,enumerable:!0}):t,r)),Hr=r=>Vt(xe({},"__esModule",{value:!0}),r);var Qo={};D(Qo,{tcp:()=>Jo});var _r=le(F("net"),1);var Bt=Symbol.for("@libp2p/transport");var zt;(function(r){r[r.FATAL_ALL=0]="FATAL_ALL",r[r.NO_FATAL=1]="NO_FATAL"})(zt||(zt={}));var ge=class extends Error{static name="AbortError";constructor(e="The operation was aborted"){super(e),this.name="AbortError"}};var V=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}};var Z=class extends Error{static name="TimeoutError";constructor(e="Timed out"){super(e),this.name="TimeoutError"}},we=class extends Error{static name="NotStartedError";constructor(e="Not started"){super(e),this.name="NotStartedError"}},be=class extends Error{static name="AlreadyStartedError";constructor(e="Already started"){super(e),this.name="AlreadyStartedError"}};var _t=F("node:events"),ve=(r,...e)=>{try{(0,_t.setMaxListeners)(r,...e)}catch{}};var ye=class extends EventTarget{#e=new Map;constructor(){super(),ve(1/0,this)}listenerCount(e){let t=this.#e.get(e);return t==null?0:t.length}addEventListener(e,t,n){super.addEventListener(e,t,n);let o=this.#e.get(e);o==null&&(o=[],this.#e.set(e,o)),o.push({callback:t,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(e,t,n){super.removeEventListener(e.toString(),t??null,n);let o=this.#e.get(e);o!=null&&(o=o.filter(({callback:s})=>s!==t),this.#e.set(e,o))}dispatchEvent(e){let t=super.dispatchEvent(e),n=this.#e.get(e.type);return n==null||(n=n.filter(({once:o})=>!o),this.#e.set(e.type,n)),t}safeDispatchEvent(e,t={}){return this.dispatchEvent(new CustomEvent(e,t))}};var Rt=Symbol.for("@libp2p/service-capabilities"),rs=Symbol.for("@libp2p/service-dependencies");var jt=F("node:buffer");function ee(r){return new Uint8Array(r.buffer,r.byteOffset,r.byteLength)}function Ee(r=0){return ee(jt.Buffer.allocUnsafe(r))}var Jr=Math.pow(2,7),Qr=Math.pow(2,14),Xr=Math.pow(2,21),Be=Math.pow(2,28),_e=Math.pow(2,35),Re=Math.pow(2,42),je=Math.pow(2,49),g=128,C=127;function z(r){if(r<Jr)return 1;if(r<Qr)return 2;if(r<Xr)return 3;if(r<Be)return 4;if(r<_e)return 5;if(r<Re)return 6;if(r<je)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Kr(r,e,t=0){switch(z(r)){case 8:e[t++]=r&255|g,r/=128;case 7:e[t++]=r&255|g,r/=128;case 6:e[t++]=r&255|g,r/=128;case 5:e[t++]=r&255|g,r/=128;case 4:e[t++]=r&255|g,r>>>=7;case 3:e[t++]=r&255|g,r>>>=7;case 2:e[t++]=r&255|g,r>>>=7;case 1:{e[t++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return e}function Yr(r,e,t=0){switch(z(r)){case 8:e.set(t++,r&255|g),r/=128;case 7:e.set(t++,r&255|g),r/=128;case 6:e.set(t++,r&255|g),r/=128;case 5:e.set(t++,r&255|g),r/=128;case 4:e.set(t++,r&255|g),r>>>=7;case 3:e.set(t++,r&255|g),r>>>=7;case 2:e.set(t++,r&255|g),r>>>=7;case 1:{e.set(t++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return e}function Zr(r,e){let t=r[e],n=0;if(n+=t&C,t<g||(t=r[e+1],n+=(t&C)<<7,t<g)||(t=r[e+2],n+=(t&C)<<14,t<g)||(t=r[e+3],n+=(t&C)<<21,t<g)||(t=r[e+4],n+=(t&C)*Be,t<g)||(t=r[e+5],n+=(t&C)*_e,t<g)||(t=r[e+6],n+=(t&C)*Re,t<g)||(t=r[e+7],n+=(t&C)*je,t<g))return n;throw new RangeError("Could not decode varint")}function en(r,e){let t=r.get(e),n=0;if(n+=t&C,t<g||(t=r.get(e+1),n+=(t&C)<<7,t<g)||(t=r.get(e+2),n+=(t&C)<<14,t<g)||(t=r.get(e+3),n+=(t&C)<<21,t<g)||(t=r.get(e+4),n+=(t&C)*Be,t<g)||(t=r.get(e+5),n+=(t&C)*_e,t<g)||(t=r.get(e+6),n+=(t&C)*Re,t<g)||(t=r.get(e+7),n+=(t&C)*je,t<g))return n;throw new RangeError("Could not decode varint")}function te(r,e,t=0){return e==null&&(e=Ee(z(r))),e instanceof Uint8Array?Kr(r,e,t):Yr(r,e,t)}function J(r,e=0){return r instanceof Uint8Array?Zr(r,e):en(r,e)}var Wt=F("node:buffer");function _(r,e){return ee(Wt.Buffer.concat(r,e))}var dr=F("node:buffer");var Je={};D(Je,{base10:()=>cn});var Ms=new Uint8Array(0);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}function k(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")}function Ht(r){return new TextEncoder().encode(r)}function Jt(r){return new TextDecoder().decode(r)}function tn(r,e){if(r.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),n=0;n<t.length;n++)t[n]=255;for(var o=0;o<r.length;o++){var s=r.charAt(o),i=s.charCodeAt(0);if(t[i]!==255)throw new TypeError(s+" is ambiguous");t[i]=o}var a=r.length,d=r.charAt(0),m=Math.log(a)/Math.log(256),p=Math.log(256)/Math.log(a);function h(f){if(f instanceof Uint8Array||(ArrayBuffer.isView(f)?f=new Uint8Array(f.buffer,f.byteOffset,f.byteLength):Array.isArray(f)&&(f=Uint8Array.from(f))),!(f instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(f.length===0)return"";for(var I=0,T=0,x=0,w=f.length;x!==w&&f[x]===0;)x++,I++;for(var L=(w-x)*p+1>>>0,M=new Uint8Array(L);x!==w;){for(var O=f[x],j=0,N=L-1;(O!==0||j<T)&&N!==-1;N--,j++)O+=256*M[N]>>>0,M[N]=O%a>>>0,O=O/a>>>0;if(O!==0)throw new Error("Non-zero carry");T=j,x++}for(var B=L-T;B!==L&&M[B]===0;)B++;for(var me=d.repeat(I);B<L;++B)me+=r.charAt(M[B]);return me}function b(f){if(typeof f!="string")throw new TypeError("Expected String");if(f.length===0)return new Uint8Array;var I=0;if(f[I]!==" "){for(var T=0,x=0;f[I]===d;)T++,I++;for(var w=(f.length-I)*m+1>>>0,L=new Uint8Array(w);f[I];){var M=t[f.charCodeAt(I)];if(M===255)return;for(var O=0,j=w-1;(M!==0||O<x)&&j!==-1;j--,O++)M+=a*L[j]>>>0,L[j]=M%256>>>0,M=M/256>>>0;if(M!==0)throw new Error("Non-zero carry");x=O,I++}if(f[I]!==" "){for(var N=w-x;N!==w&&L[N]===0;)N++;for(var B=new Uint8Array(T+(w-N)),me=T;N!==w;)B[me++]=L[N++];return B}}}function l(f){var I=b(f);if(I)return I;throw new Error(`Non-${e} character`)}return{encode:h,decodeUnsafe:b,decode:l}}var rn=tn,nn=rn,Xt=nn;var qe=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")}},We=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,t,n){this.name=e,this.prefix=t;let o=t.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return Kt(this,e)}},Ge=class{decoders;constructor(e){this.decoders=e}or(e){return Kt(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 Kt(r,e){return new Ge({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var He=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 qe(e,t,n),this.decoder=new We(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function re({name:r,prefix:e,encode:t,decode:n}){return new He(r,e,t,n)}function q({name:r,prefix:e,alphabet:t}){let{encode:n,decode:o}=Xt(t,r);return re({prefix:e,name:r,encode:n,decode:s=>k(o(s))})}function on(r,e,t,n){let o={};for(let p=0;p<e.length;++p)o[e[p]]=p;let s=r.length;for(;r[s-1]==="=";)--s;let i=new Uint8Array(s*t/8|0),a=0,d=0,m=0;for(let p=0;p<s;++p){let h=o[r[p]];if(h===void 0)throw new SyntaxError(`Non-${n} character`);d=d<<t|h,a+=t,a>=8&&(a-=8,i[m++]=255&d>>a)}if(a>=t||255&d<<8-a)throw new SyntaxError("Unexpected end of data");return i}function sn(r,e,t){let n=e[e.length-1]==="=",o=(1<<t)-1,s="",i=0,a=0;for(let d=0;d<r.length;++d)for(a=a<<8|r[d],i+=8;i>t;)i-=t,s+=e[o&a>>i];if(i!==0&&(s+=e[o&a<<t-i]),n)for(;s.length*t&7;)s+="=";return s}function y({name:r,prefix:e,bitsPerChar:t,alphabet:n}){return re({prefix:e,name:r,encode(o){return sn(o,n,t)},decode(o){return on(o,n,t,r)}})}var cn=q({prefix:"9",name:"base10",alphabet:"0123456789"});var Qe={};D(Qe,{base16:()=>an,base16upper:()=>ln});var an=y({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),ln=y({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Xe={};D(Xe,{base2:()=>un});var un=y({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Ke={};D(Ke,{base256emoji:()=>mn});var Yt=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=Yt.reduce((r,e,t)=>(r[t]=e,r),[]),pn=Yt.reduce((r,e,t)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return r[n]=t,r},[]);function fn(r){return r.reduce((e,t)=>(e+=dn[t],e),"")}function hn(r){let e=[];for(let t of r){let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);let o=pn[n];if(o==null)throw new Error(`Non-base256emoji character: ${t}`);e.push(o)}return new Uint8Array(e)}var mn=re({prefix:"\u{1F680}",name:"base256emoji",encode:fn,decode:hn});var Ye={};D(Ye,{base32:()=>R,base32hex:()=>bn,base32hexpad:()=>yn,base32hexpadupper:()=>En,base32hexupper:()=>vn,base32pad:()=>gn,base32padupper:()=>wn,base32upper:()=>xn,base32z:()=>In});var R=y({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),xn=y({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),gn=y({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),wn=y({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),bn=y({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),vn=y({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),yn=y({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),En=y({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),In=y({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Ze={};D(Ze,{base36:()=>ue,base36upper:()=>An});var ue=q({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),An=q({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var et={};D(et,{base58btc:()=>P,base58flickr:()=>Cn});var P=q({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Cn=q({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var tt={};D(tt,{base64:()=>Tn,base64pad:()=>Sn,base64url:()=>Pn,base64urlpad:()=>Ln});var Tn=y({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Sn=y({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Pn=y({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Ln=y({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var rt={};D(rt,{base8:()=>Dn});var Dn=y({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var nt={};D(nt,{identity:()=>Mn});var Mn=re({prefix:"\0",name:"identity",encode:r=>Jt(r),decode:r=>Ht(r)});var Hs=new TextEncoder,Js=new TextDecoder;var st={};D(st,{identity:()=>eo});var Nn=tr,Zt=128,Fn=127,$n=~Fn,On=Math.pow(2,31);function tr(r,e,t){e=e||[],t=t||0;for(var n=t;r>=On;)e[t++]=r&255|Zt,r/=128;for(;r&$n;)e[t++]=r&255|Zt,r>>>=7;return e[t]=r|0,tr.bytes=t-n+1,e}var Vn=ot,zn=128,er=127;function ot(r,n){var t=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw ot.bytes=0,new RangeError("Could not decode varint");i=r[s++],t+=o<28?(i&er)<<o:(i&er)*Math.pow(2,o),o+=7}while(i>=zn);return ot.bytes=s-n,t}var Bn=Math.pow(2,7),_n=Math.pow(2,14),Rn=Math.pow(2,21),jn=Math.pow(2,28),qn=Math.pow(2,35),Wn=Math.pow(2,42),Gn=Math.pow(2,49),Hn=Math.pow(2,56),Jn=Math.pow(2,63),Qn=function(r){return r<Bn?1:r<_n?2:r<Rn?3:r<jn?4:r<qn?5:r<Wn?6:r<Gn?7:r<Hn?8:r<Jn?9:10},Xn={encode:Nn,decode:Vn,encodingLength:Qn},Kn=Xn,de=Kn;function pe(r,e=0){return[de.decode(r,e),de.decode.bytes]}function ne(r,e,t=0){return de.encode(r,e,t),e}function oe(r){return de.encodingLength(r)}function Q(r,e){let t=e.byteLength,n=oe(r),o=n+oe(t),s=new Uint8Array(o+t);return ne(r,s,0),ne(t,s,n),s.set(e,o),new se(r,t,e,s)}function Ae(r){let e=k(r),[t,n]=pe(e),[o,s]=pe(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new se(t,o,i,e)}function rr(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&Gt(r.bytes,t.bytes)}}var se=class{code;size;digest;bytes;constructor(e,t,n,o){this.code=e,this.size=t,this.digest=n,this.bytes=o}};var nr=0,Yn="identity",or=k;function Zn(r){return Q(nr,or(r))}var eo={code:nr,name:Yn,encode:or,digest:Zn};var lt={};D(lt,{sha256:()=>to,sha512:()=>ro});var at=le(F("crypto"),1);function ct({name:r,code:e,encode:t}){return new it(r,e,t)}var it=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?Q(this.code,t):t.then(n=>Q(this.code,n))}else throw Error("Unknown type, must be binary type")}};var to=ct({name:"sha2-256",code:18,encode:r=>k(at.default.createHash("sha256").update(r).digest())}),ro=ct({name:"sha2-512",code:19,encode:r=>k(at.default.createHash("sha512").update(r).digest())});function ir(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return oo(t,ut(r),e??P.encoder);default:return so(t,ut(r),e??R.encoder)}}var cr=new WeakMap;function ut(r){let e=cr.get(r);if(e==null){let t=new Map;return cr.set(r,t),t}return e}var W=class r{code;version;multihash;bytes;"/";constructor(e,t,n,o){this.code=t,this.version=e,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:t}=this;if(e!==fe)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==io)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=Q(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&&rr(e.multihash,n.multihash)}toString(e){return ir(this,e)}toJSON(){return{"/":ir(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??ar(n,o,s.bytes))}else if(t[co]===!0){let{version:n,multihash:o,code:s}=t,i=Ae(o);return r.create(n,s,i)}else return null}static create(e,t,n){if(typeof t!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(t!==fe)throw new Error(`Version 0 CID must use dag-pb (code: ${fe}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let o=ar(e,t,n.bytes);return new r(e,t,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,fe,e)}static createV1(e,t){return r.create(1,e,t)}static decode(e){let[t,n]=r.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return t}static decodeFirst(e){let t=r.inspectBytes(e),n=t.size-t.multihashSize,o=k(e.subarray(n,n+t.multihashSize));if(o.byteLength!==t.multihashSize)throw new Error("Incorrect length");let s=o.subarray(t.multihashSize-t.digestSize),i=new se(t.multihashCode,t.digestSize,s,o);return[t.version===0?r.createV0(i):r.createV1(t.codec,i),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[h,b]=pe(e.subarray(t));return t+=b,h},o=n(),s=fe;if(o===18?(o=0,t=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=t,a=n(),d=n(),m=t+d,p=m-i;return{version:o,codec:s,multihashCode:a,digestSize:d,multihashSize:p,size:m}}static parse(e,t){let[n,o]=no(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 ut(s).set(n,e),s}};function no(r,e){switch(r[0]){case"Q":{let t=e??P;return[P.prefix,t.decode(`${P.prefix}${r}`)]}case P.prefix:{let t=e??P;return[P.prefix,t.decode(r)]}case R.prefix:{let t=e??R;return[R.prefix,t.decode(r)]}case ue.prefix:{let t=e??ue;return[ue.prefix,t.decode(r)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],e.decode(r)]}}}function oo(r,e,t){let{prefix:n}=t;if(n!==P.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let o=e.get(n);if(o==null){let s=t.encode(r).slice(1);return e.set(n,s),s}else return o}function so(r,e,t){let{prefix:n}=t,o=e.get(n);if(o==null){let s=t.encode(r);return e.set(n,s),s}else return o}var fe=112,io=18;function ar(r,e,t){let n=oe(r),o=n+oe(e),s=new Uint8Array(o+t.byteLength);return ne(r,s,0),ne(e,s,n),s.set(t,o),s}var co=Symbol.for("@ipld/js-cid/CID");var he={...nt,...Xe,...rt,...Je,...Qe,...Ye,...Ze,...et,...tt,...Ke},gi={...lt,...st};function ur(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var lr=ur("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),dt=ur("ascii","a",r=>{let e="a";for(let t=0;t<r.length;t++)e+=String.fromCharCode(r[t]);return e},r=>{r=r.substring(1);let e=Ee(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),ao={utf8:lr,"utf-8":lr,hex:he.base16,latin1:dt,ascii:dt,binary:dt,...he},Ce=ao;function S(r,e="utf8"){let t=Ce[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return e==="utf8"||e==="utf-8"?dr.Buffer.from(r.buffer,r.byteOffset,r.byteLength).toString("utf8"):t.encoder.encode(r).substring(1)}var Te=class{index=0;input="";new(e){return this.index=0,this.input=e,this}readAtomically(e){let t=this.index,n=e();return n===void 0&&(this.index=t),n}parseWith(e){let t=e();if(this.index===this.input.length)return t}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(e){return this.readAtomically(()=>{let t=this.readChar();if(t===e)return t})}readSeparator(e,t,n){return this.readAtomically(()=>{if(!(t>0&&this.readGivenChar(e)===void 0))return n()})}readNumber(e,t,n,o){return this.readAtomically(()=>{let s=0,i=0,a=this.peekChar();if(a===void 0)return;let d=a==="0",m=2**(8*o)-1;for(;;){let p=this.readAtomically(()=>{let h=this.readChar();if(h===void 0)return;let b=Number.parseInt(h,e);if(!Number.isNaN(b))return b});if(p===void 0)break;if(s*=e,s+=p,s>m||(i+=1,t!==void 0&&i>t))return}if(i!==0)return!n&&d&&i>1?void 0:s})}readIPv4Addr(){return this.readAtomically(()=>{let e=new Uint8Array(4);for(let t=0;t<e.length;t++){let n=this.readSeparator(".",t,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;e[t]=n}return e})}readIPv6Addr(){let e=t=>{for(let n=0;n<t.length/2;n++){let o=n*2;if(n<t.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return t[o]=i[0],t[o+1]=i[1],t[o+2]=i[2],t[o+3]=i[3],[o+4,!0]}let s=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(s===void 0)return[o,!1];t[o]=s>>8,t[o+1]=s&255}return[t.length,!1]};return this.readAtomically(()=>{let t=new Uint8Array(16),[n,o]=e(t);if(n===16)return t;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let s=new Uint8Array(14),i=16-(n+2),[a]=e(s.subarray(0,i));return t.set(s.subarray(0,a),16-a),t})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var Ti=new Te;var Ni=parseInt("0xFFFF",16),Fi=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);var hr=F("node:buffer");function Se(r,e="utf8"){let t=Ce[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return e==="utf8"||e==="utf-8"?ee(hr.Buffer.from(r,"utf-8")):t.decoder.decode(`${t.prefix}${r}`)}var U=F("node:net");function Pe(r){return!!(0,U.isIP)(r)}var mr=U.isIPv4,mo=U.isIPv6,pt=function(r){let e=0;if(r=r.toString().trim(),mr(r)){let t=new Uint8Array(e+4);return r.split(/\./g).forEach(n=>{t[e++]=parseInt(n,10)&255}),t}if(mo(r)){let t=r.split(":",8),n;for(n=0;n<t.length;n++){let s=mr(t[n]),i;s&&(i=pt(t[n]),t[n]=S(i.slice(0,2),"base16")),i!=null&&++n<8&&t.splice(n,0,S(i.slice(2,4),"base16"))}if(t[0]==="")for(;t.length<8;)t.unshift("0");else if(t[t.length-1]==="")for(;t.length<8;)t.push("0");else if(t.length<8){for(n=0;n<t.length&&t[n]!=="";n++);let s=[n,1];for(n=9-t.length;n>0;n--)s.push("0");t.splice.apply(t,s)}let o=new Uint8Array(e+16);for(n=0;n<t.length;n++){let s=parseInt(t[n],16);o[e++]=s>>8&255,o[e++]=s&255}return o}throw new Error("invalid ip address")},xr=function(r,e=0,t){e=~~e,t=t??r.length-e;let n=new DataView(r.buffer);if(t===4){let o=[];for(let s=0;s<t;s++)o.push(r[e+s]);return o.join(".")}if(t===16){let o=[];for(let s=0;s<t;s+=2)o.push(n.getUint16(e+s).toString(16));return o.join(":").replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}return""};var ce={},ft={},go=[[4,32,"ip4"],[6,16,"tcp"],[33,16,"dccp"],[41,128,"ip6"],[42,-1,"ip6zone"],[43,8,"ipcidr"],[53,-1,"dns",!0],[54,-1,"dns4",!0],[55,-1,"dns6",!0],[56,-1,"dnsaddr",!0],[132,16,"sctp"],[273,16,"udp"],[275,0,"p2p-webrtc-star"],[276,0,"p2p-webrtc-direct"],[277,0,"p2p-stardust"],[280,0,"webrtc-direct"],[281,0,"webrtc"],[290,0,"p2p-circuit"],[301,0,"udt"],[302,0,"utp"],[400,-1,"unix",!1,!0],[421,-1,"ipfs"],[421,-1,"p2p"],[443,0,"https"],[444,96,"onion"],[445,296,"onion3"],[446,-1,"garlic64"],[448,0,"tls"],[449,-1,"sni"],[460,0,"quic"],[461,0,"quic-v1"],[465,0,"webtransport"],[466,-1,"certhash"],[477,0,"ws"],[478,0,"wss"],[479,0,"p2p-websocket-star"],[480,0,"http"],[481,-1,"http-path"],[777,-1,"memory"]];go.forEach(r=>{let e=wo(...r);ft[e.code]=e,ce[e.name]=e});function wo(r,e,t,n,o){return{code:r,size:e,name:t,resolvable:!!n,path:!!o}}function v(r){if(typeof r=="number"){if(ft[r]!=null)return ft[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(ce[r]!=null)return ce[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var Ec=v("ip4"),Ic=v("ip6"),Ac=v("ipcidr");function gt(r,e){switch(v(r).code){case 4:case 41:return vo(e);case 42:return xt(e);case 43:return S(e,"base10");case 6:case 273:case 33:case 132:return br(e).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return xt(e);case 421:return Ao(e);case 444:return wr(e);case 445:return wr(e);case 466:return Io(e);case 481:return globalThis.encodeURIComponent(xt(e));default:return S(e,"base16")}}function wt(r,e){switch(v(r).code){case 4:return gr(e);case 41:return gr(e);case 42:return mt(e);case 43:return Se(e,"base10");case 6:case 273:case 33:case 132:return bt(parseInt(e,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return mt(e);case 421:return yo(e);case 444:return Co(e);case 445:return To(e);case 466:return Eo(e);case 481:return mt(globalThis.decodeURIComponent(e));default:return Se(e,"base16")}}var ht=Object.values(he).map(r=>r.decoder),bo=function(){let r=ht[0].or(ht[1]);return ht.slice(2).forEach(e=>r=r.or(e)),r}();function gr(r){if(!Pe(r))throw new Error("invalid ip address");return pt(r)}function vo(r){let e=xr(r,0,r.length);if(e==null)throw new Error("ipBuff is required");if(!Pe(e))throw new Error("invalid ip address");return e}function bt(r){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,r),new Uint8Array(e)}function br(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function mt(r){let e=Se(r),t=Uint8Array.from(te(e.length));return _([t,e],t.length+e.length)}function xt(r){let e=J(r);if(r=r.slice(z(e)),r.length!==e)throw new Error("inconsistent lengths");return S(r)}function yo(r){let e;r[0]==="Q"||r[0]==="1"?e=Ae(P.decode(`z${r}`)).bytes:e=W.parse(r).multihash.bytes;let t=Uint8Array.from(te(e.length));return _([t,e],t.length+e.length)}function Eo(r){let e=bo.decode(r),t=Uint8Array.from(te(e.length));return _([t,e],t.length+e.length)}function Io(r){let e=J(r),t=r.slice(z(e));if(t.length!==e)throw new Error("inconsistent lengths");return"u"+S(t,"base64url")}function Ao(r){let e=J(r),t=r.slice(z(e));if(t.length!==e)throw new Error("inconsistent lengths");return S(t,"base58btc")}function Co(r){let e=r.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==16)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion address.`);let t=R.decode("b"+e[0]),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=bt(n);return _([t,o],t.length+o.length)}function To(r){let e=r.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==56)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion3 address.`);let t=R.decode(`b${e[0]}`),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=bt(n);return _([t,o],t.length+o.length)}function wr(r){let e=r.slice(0,r.length-2),t=r.slice(r.length-2),n=S(e,"base32"),o=br(t);return`${n}:${o}`}function vr(r){r=vt(r);let e=[],t=[],n=null,o=r.split("/").slice(1);if(o.length===1&&o[0]==="")return{bytes:new Uint8Array,string:"/",tuples:[],stringTuples:[],path:null};for(let s=0;s<o.length;s++){let i=o[s],a=v(i);if(a.size===0){e.push([a.code]),t.push([a.code]);continue}if(s++,s>=o.length)throw new Le("invalid address: "+r);if(a.path===!0){n=vt(o.slice(s).join("/")),e.push([a.code,wt(a.code,n)]),t.push([a.code,n]);break}let d=wt(a.code,o[s]);e.push([a.code,d]),t.push([a.code,gt(a.code,d)])}return{string:yr(t),bytes:De(e),tuples:e,stringTuples:t,path:n}}function yt(r){let e=[],t=[],n=null,o=0;for(;o<r.length;){let s=J(r,o),i=z(s),a=v(s),d=So(a,r.slice(o+i));if(d===0){e.push([s]),t.push([s]),o+=i;continue}let m=r.slice(o+i,o+i+d);if(o+=d+i,o>r.length)throw new Le("Invalid address Uint8Array: "+S(r,"base16"));e.push([s,m]);let p=gt(s,m);if(t.push([s,p]),a.path===!0){n=p;break}}return{bytes:Uint8Array.from(r),string:yr(t),tuples:e,stringTuples:t,path:n}}function yr(r){let e=[];return r.map(t=>{let n=v(t[0]);return e.push(n.name),t.length>1&&t[1]!=null&&e.push(t[1]),null}),vt(e.join("/"))}function De(r){return _(r.map(e=>{let t=v(e[0]),n=Uint8Array.from(te(t.code));return e.length>1&&e[1]!=null&&(n=_([n,e[1]])),n}))}function So(r,e){if(r.size>0)return r.size/8;if(r.size===0)return 0;{let t=J(e instanceof Uint8Array?e:Uint8Array.from(e));return t+z(t)}}function vt(r){return"/"+r.trim().split("/").filter(e=>e).join("/")}var Le=class extends Error{static name="ParseError";name="ParseError";constructor(e){super(`Error parsing address: ${e}`)}};function Er(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 Po=Symbol.for("nodejs.util.inspect.custom"),It=Symbol.for("@multiformats/js-multiaddr/multiaddr"),Lo=[v("dns").code,v("dns4").code,v("dns6").code,v("dnsaddr").code],Et=class extends Error{constructor(e="No available resolver"){super(e),this.name="NoAvailableResolverError"}},Me=class r{bytes;#e;#t;#r;#n;[It]=!0;constructor(e){e==null&&(e="");let t;if(e instanceof Uint8Array)t=yt(e);else if(typeof e=="string"){if(e.length>0&&e.charAt(0)!=="/")throw new Error(`multiaddr "${e}" must start with a "/"`);t=vr(e)}else if(Ar(e))t=yt(e.bytes);else throw new Error("addr must be a string, Buffer, or another Multiaddr");this.bytes=t.bytes,this.#e=t.string,this.#t=t.tuples,this.#r=t.stringTuples,this.#n=t.path}toString(){return this.#e}toJSON(){return this.toString()}toOptions(){let e,t,n,o,s="",i=v("tcp"),a=v("udp"),d=v("ip4"),m=v("ip6"),p=v("dns6"),h=v("ip6zone");for(let[l,f]of this.stringTuples())l===h.code&&(s=`%${f??""}`),Lo.includes(l)&&(t=i.name==="tcp"?"tcp":"udp",o=443,n=`${f??""}${s}`,e=l===p.code?6:4),(l===i.code||l===a.code)&&(t=v(l).name==="tcp"?"tcp":"udp",o=parseInt(f??"")),(l===d.code||l===m.code)&&(t=v(l).name==="tcp"?"tcp":"udp",n=`${f??""}${s}`,e=l===m.code?6:4);if(e==null||t==null||n==null||o==null)throw new Error('multiaddr must have a valid format: "/{ip4, ip6, dns4, dns6, dnsaddr}/{address}/{tcp, udp}/{port}".');return{family:e,host:n,transport:t,port:o}}protos(){return this.#t.map(([e])=>Object.assign({},v(e)))}protoCodes(){return this.#t.map(([e])=>e)}protoNames(){return this.#t.map(([e])=>v(e).name)}tuples(){return this.#t.map(([e,t])=>t==null?[e]:[e,t])}stringTuples(){return this.#r.map(([e,t])=>t==null?[e]:[e,t])}encapsulate(e){return e=new r(e),new r(this.toString()+e.toString())}decapsulate(e){let t=e.toString(),n=this.toString(),o=n.lastIndexOf(t);if(o<0)throw new Error(`Address ${this.toString()} does not contain subaddress: ${e.toString()}`);return new r(n.slice(0,o))}decapsulateCode(e){let t=this.tuples();for(let n=t.length-1;n>=0;n--)if(t[n][0]===e)return new r(De(t.slice(0,n)));return this}getPeerId(){try{let e=[];this.stringTuples().forEach(([n,o])=>{n===ce.p2p.code&&e.push([n,o]),n===ce["p2p-circuit"].code&&(e=[])});let t=e.pop();if(t?.[1]!=null){let n=t[1];return n[0]==="Q"||n[0]==="1"?S(P.decode(`z${n}`),"base58btc"):S(W.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){return this.#n}equals(e){return Er(this.bytes,e.bytes)}async resolve(e){let t=this.protos().find(s=>s.resolvable);if(t==null)return[this];let n=Ir.get(t.name);if(n==null)throw new Et(`no available resolver for ${t.name}`);return(await n(this,e)).map(s=>$(s))}nodeAddress(){let e=this.toOptions();if(e.transport!=="tcp"&&e.transport!=="udp")throw new Error(`multiaddr must have a valid format - no protocol with name: "${e.transport}". Must have a valid transport protocol: "{tcp, udp}"`);return{family:e.family,address:e.host,port:e.port}}isThinWaistAddress(e){let t=(e??this).protos();return!(t.length!==2||t[0].code!==4&&t[0].code!==41||t[1].code!==6&&t[1].code!==273)}[Po](){return`Multiaddr(${this.#e})`}};var Ir=new Map;function Ar(r){return!!r?.[It]}function $(r){return new Me(r)}var Do=c("dns4"),Mo=c("dns6"),ko=c("dnsaddr"),K=E(c("dns"),ko,Do,Mo),Ne=E(c("ip4"),c("ip6")),H=E(u(Ne,c("tcp")),u(K,c("tcp"))),Fe=u(Ne,c("udp")),Uo=u(Fe,c("utp")),No=u(Fe,c("quic")),Fo=u(Fe,c("quic-v1")),At=E(u(H,c("ws")),u(K,c("ws"))),ke=E(u(At,c("p2p")),At),Ct=E(u(H,c("wss")),u(K,c("wss")),u(H,c("tls"),c("ws")),u(K,c("tls"),c("ws"))),Ue=E(u(Ct,c("p2p")),Ct),Tt=E(u(H,c("http")),u(Ne,c("http")),u(K,c("http"))),St=E(u(H,c("https")),u(Ne,c("https")),u(K,c("https"))),Cr=u(Fe,c("webrtc-direct"),c("certhash")),Pr=E(u(Cr,c("p2p")),Cr),Tr=u(Fo,c("webtransport"),c("certhash"),c("certhash")),Lr=E(u(Tr,c("p2p")),Tr),Dr=E(u(ke,c("p2p-webrtc-star"),c("p2p")),u(Ue,c("p2p-webrtc-star"),c("p2p")),u(ke,c("p2p-webrtc-star")),u(Ue,c("p2p-webrtc-star"))),Yc=E(u(ke,c("p2p-websocket-star"),c("p2p")),u(Ue,c("p2p-websocket-star"),c("p2p")),u(ke,c("p2p-websocket-star")),u(Ue,c("p2p-websocket-star"))),Mr=E(u(Tt,c("p2p-webrtc-direct"),c("p2p")),u(St,c("p2p-webrtc-direct"),c("p2p")),u(Tt,c("p2p-webrtc-direct")),u(St,c("p2p-webrtc-direct"))),Y=E(At,Ct,Tt,St,Dr,Mr,H,Uo,No,K,Pr,Lr),Zc=E(u(Y,c("p2p-stardust"),c("p2p")),u(Y,c("p2p-stardust"))),G=E(u(Y,c("p2p")),Dr,Mr,Pr,Lr,c("p2p")),Sr=E(u(G,c("p2p-circuit"),G),u(G,c("p2p-circuit")),u(c("p2p-circuit"),G),u(Y,c("p2p-circuit")),u(c("p2p-circuit"),Y),c("p2p-circuit")),kr=()=>E(u(Sr,kr),Sr),X=kr(),ea=E(u(X,G,X),u(G,X),u(X,G),X,G);var ta=E(u(X,c("webrtc"),c("p2p")),u(X,c("webrtc")),u(Y,c("webrtc"),c("p2p")),u(Y,c("webrtc")),c("webrtc"));function Ur(r){function e(t){let n;try{n=$(t)}catch{return!1}let o=r(n.protoNames());return o===null?!1:o===!0||o===!1?o:o.length===0}return e}function u(...r){function e(t){if(t.length<r.length)return null;let n=t;return r.some(o=>(n=typeof o=="function"?o().partialMatch(t):o.partialMatch(t),Array.isArray(n)&&(t=n),n===null)),n}return{toString:function(){return"{ "+r.join(" ")+" }"},input:r,matches:Ur(e),partialMatch:e}}function E(...r){function e(n){let o=null;return r.some(s=>{let i=typeof s=="function"?s().partialMatch(n):s.partialMatch(n);return i!=null?(o=i,!0):!1}),o}return{toString:function(){return"{ "+r.join(" ")+" }"},input:r,matches:Ur(e),partialMatch:e}}function c(r){let e=r;function t(o){let s;try{s=$(o)}catch{return!1}let i=s.protoNames();return i.length===1&&i[0]===e}function n(o){return o.length===0?null:o[0]===e?o.slice(1):null}return{toString:function(){return e},matches:t,partialMatch:n}}var $e=class extends Event{type;detail;constructor(e,t){super(e),this.type=e,this.detail=t}};var Br=le(F("net"),1);var Pt=class extends Error{constructor(e){super(e),this.name="TimeoutError"}},Lt=class extends Error{constructor(e){super(),this.name="AbortError",this.message=e}},Nr=r=>globalThis.DOMException===void 0?new Lt(r):new DOMException(r),Fr=r=>{let e=r.reason===void 0?Nr("This operation was aborted."):r.reason;return e instanceof Error?e:Nr(e)};function Dt(r,e){let{milliseconds:t,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout}}=e,i,a,m=new Promise((p,h)=>{if(typeof t!="number"||Math.sign(t)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${t}\``);if(e.signal){let{signal:l}=e;l.aborted&&h(Fr(l)),a=()=>{h(Fr(l))},l.addEventListener("abort",a,{once:!0})}if(t===Number.POSITIVE_INFINITY){r.then(p,h);return}let b=new Pt;i=s.setTimeout.call(void 0,()=>{if(n){try{p(n())}catch(l){h(l)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?p():o instanceof Error?h(o):(b.message=o??`Promise timed out after ${t} milliseconds`,h(b))},t),(async()=>{try{p(await r)}catch(l){h(l)}})()}).finally(()=>{m.clear(),a&&e.signal&&e.signal.removeEventListener("abort",a)});return m.clear=()=>{s.clearTimeout.call(void 0,i),i=void 0},m}var Oo=r=>{let e=r.addEventListener||r.on||r.addListener,t=r.removeEventListener||r.off||r.removeListener;if(!e||!t)throw new TypeError("Emitter is not compatible");return{addListener:e.bind(r),removeListener:t.bind(r)}};function Vo(r,e,t){let n,o=new Promise((s,i)=>{if(t={rejectionEvents:["error"],multiArgs:!1,resolveImmediately:!1,...t},!(t.count>=0&&(t.count===Number.POSITIVE_INFINITY||Number.isInteger(t.count))))throw new TypeError("The `count` option should be at least 0 or more");t.signal?.throwIfAborted();let a=[e].flat(),d=[],{addListener:m,removeListener:p}=Oo(r),h=(...l)=>{let f=t.multiArgs?l:l[0];t.filter&&!t.filter(f)||(d.push(f),t.count===d.length&&(n(),s(d)))},b=l=>{n(),i(l)};n=()=>{for(let l of a)p(l,h);for(let l of t.rejectionEvents)p(l,b)};for(let l of a)m(l,h);for(let l of t.rejectionEvents)m(l,b);t.signal&&t.signal.addEventListener("abort",()=>{b(t.signal.reason)},{once:!0}),t.resolveImmediately&&s(d)});if(o.cancel=n,typeof t.timeout=="number"){let s=Dt(o,{milliseconds:t.timeout});return s.cancel=n,s}return o}function Mt(r,e,t){typeof t=="function"&&(t={filter:t}),t={...t,count:1,resolveImmediately:!1};let n=Vo(r,e,t),o=n.then(s=>s[0]);return o.cancel=n.cancel,o}function $r(r,e){if(typeof r!="string")throw new V(`invalid ip provided: ${r}`);if(typeof e=="string"&&(e=parseInt(e)),isNaN(e))throw new V(`invalid port provided: ${e}`);if((0,U.isIPv4)(r))return $(`/ip4/${r}/tcp/${e}`);if((0,U.isIPv6)(r))return $(`/ip6/${r}/tcp/${e}`);throw new V(`invalid ip:port for creating a multiaddr: ${r}:${e}`)}function kt(){let r={};return r.promise=new Promise((e,t)=>{r.resolve=e,r.reject=t}),r}var Ut=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.name="AbortError",this.code=t??"ABORT_ERR"}};async function Nt(r,e,t,n){let o=new Ut(n?.errorMessage,n?.errorCode);return t?.aborted===!0?Promise.reject(o):new Promise((s,i)=>{function a(){t?.removeEventListener("abort",p),r.removeEventListener(e,d),n?.errorEvent!=null&&r.removeEventListener(n.errorEvent,m)}let d=h=>{try{if(n?.filter?.(h)===!1)return}catch(b){a(),i(b);return}a(),s(h)},m=h=>{a(),i(h.detail)},p=()=>{a(),i(o)};t?.addEventListener("abort",p),r.addEventListener(e,d),n?.errorEvent!=null&&r.addEventListener(n.errorEvent,m)})}function Or(r){if(Bo(r))return async function*(){let e=r.getReader();try{for(;;){let{done:t,value:n}=await e.read();if(t)return;yield n}}finally{e.releaseLock()}}();if(zo(r))return r;throw new Error("unknown stream")}function zo(r){return r[Symbol.asyncIterator]!=null}function Bo(r){return typeof r?.getReader=="function"}function Vr(r){return async e=>{let t=async()=>{_o(e)&&await e.return(void 0)},n,o,s=x=>{n=x,t().catch(w=>{w=new AggregateError([n,w],"The Writable emitted an error, additionally an error occurred while ending the Source")}).finally(()=>{o?.(x)})},i,a=!1,d=()=>{a=!0,i?.()},m,p=!1,h=()=>{p=!0,m?.()},b,l=()=>{b?.()},f=async()=>new Promise((x,w)=>{i=b=x,o=w,r.once("drain",l)}),I=async()=>(await t(),new Promise((x,w)=>{if(a||p||n!=null){x();return}m=i=x,o=w})),T=()=>{r.removeListener("error",s),r.removeListener("close",d),r.removeListener("finish",h),r.removeListener("drain",l)};r.once("error",s),r.once("close",d),r.once("finish",h);try{for await(let x of e){if(!r.writable||r.destroyed||n!=null)break;r.write(x)||await f()}}catch(x){n==null&&r.destroy(x),n=x}try{if(r.writable&&r.end(),await I(),n!=null)throw n}finally{T()}}}function _o(r){return r.return!=null}function Ft(r){return{sink:Vr(r),source:Or(r)}}var $t=le(F("os"),1),zr=le(F("path"),1);var Ro={ip4:"IPv4",ip6:"IPv6"};function ae(r,e={}){let t=r.getPath();return t!=null?$t.default.platform()==="win32"?{path:zr.default.join("\\\\.\\pipe\\",t)}:{path:t}:{...e,...r.toOptions()}}function Ot(r,e,t){let n=o=>$(`/${r}/${o}/tcp/${t}`);return(jo(e)?Wo(Ro[r]):[e]).map(n)}function jo(r){return["0.0.0.0","::"].includes(r)}var qo=$t.default.networkInterfaces();function Wo(r){let e=[];for(let[,t]of Object.entries(qo))if(t!=null)for(let n of t)n.family===r&&e.push(n.address);return e}var Oe=(r,e)=>{let t,n=e.logger.forComponent("libp2p:tcp:socket"),o=e.direction,s=e.metrics,i=e.metricPrefix??"",a=e.socketInactivityTimeout??12e4,d=e.socketCloseTimeout??500,m=!1,p=!1;e.listeningAddr?.getPath()!=null&&(e.remoteAddr=e.listeningAddr),e.remoteAddr?.getPath()!=null&&(e.localAddr=e.remoteAddr),r.on("error",x=>{p=!0,m||(n.error("%s socket error - %e",o,x),s?.increment({[`${i}error`]:!0})),r.destroy(),T.timeline.close=Date.now()});let h;if(e.remoteAddr!=null)h=e.remoteAddr;else{if(r.remoteAddress==null||r.remotePort==null)throw new V("Could not determine remote address or port");h=$r(r.remoteAddress,r.remotePort)}let b=ae(h),l=b.path??`${b.host??""}:${b.port??""}`,{sink:f,source:I}=Ft(r);r.setTimeout(a),r.once("timeout",()=>{m=!0,n("%s %s socket read timeout",o,l),s?.increment({[`${i}timeout`]:!0}),r.destroy(new Z),T.timeline.close=Date.now()}),r.once("close",()=>{!m&&!p&&(n("%s %s socket close",o,l),s?.increment({[`${i}close`]:!0})),r.destroy(),T.timeline.close=Date.now()}),r.once("end",()=>{n("%s %s socket end",o,l),s?.increment({[`${i}end`]:!0})});let T={async sink(x){try{await f(async function*(){for await(let w of x)w instanceof Uint8Array?yield w:yield w.subarray()}())}catch(w){w.type!=="aborted"&&n.error("%s %s error in sink - %e",o,l,w)}r.end()},source:I,remoteAddr:h,timeline:{open:Date.now()},async close(x={}){if(r.closed){n("the %s %s socket is already closed",o,l);return}if(r.destroyed){n("the %s %s socket is already destroyed",o,l);return}if(t!=null)return t.promise;try{t=kt(),r.end();let w=Go(r),L=x.signal??AbortSignal.timeout(d);r.writableLength>0&&(n("%s %s draining socket",o,l),await Nt(w,"drain",L,{errorEvent:"error"}),n("%s %s socket drained",o,l)),await Promise.all([Nt(w,"close",L,{errorEvent:"error"}),r.destroy()])}catch(w){this.abort(w)}finally{t.resolve()}},abort:x=>{n("%s %s socket abort due to error - %e",o,l,x),r.destroy(),T.timeline.close=Date.now()},log:n};return T};function Go(r){return{addEventListener:(t,n)=>{r.addListener(t,n)},removeEventListener:(t,n)=>{r.removeListener(t,n)}}}var A;(function(r){r[r.INACTIVE=0]="INACTIVE",r[r.ACTIVE=1]="ACTIVE",r[r.PAUSED=2]="PAUSED"})(A||(A={}));var Ve=class extends ye{context;server;sockets=new Set;status={code:A.INACTIVE};metrics;addr;log;shutdownController;constructor(e){if(super(),this.context=e,e.keepAlive=e.keepAlive??!0,e.noDelay=e.noDelay??!0,this.shutdownController=new AbortController,ve(1/0,this.shutdownController.signal),this.log=e.logger.forComponent("libp2p:tcp:listener"),this.addr="unknown",this.server=Br.default.createServer(e,this.onSocket.bind(this)),e.maxConnections!==void 0&&(this.server.maxConnections=e.maxConnections),e.closeServerOnMaxConnections!=null&&e.closeServerOnMaxConnections.closeAbove<e.closeServerOnMaxConnections.listenBelow)throw new V("closeAbove must be >= listenBelow");this.server.on("listening",()=>{if(e.metrics!=null){let t=this.server.address();t==null?this.addr="unknown":typeof t=="string"?this.addr=t:this.addr=`${t.address}:${t.port}`,e.metrics?.registerMetricGroup("libp2p_tcp_inbound_connections_total",{label:"address",help:"Current active connections in TCP listener",calculate:()=>({[this.addr]:this.sockets.size})}),this.metrics={status:e.metrics.registerMetricGroup("libp2p_tcp_listener_status_info",{label:"address",help:"Current status of the TCP listener socket"}),errors:e.metrics.registerMetricGroup("libp2p_tcp_listener_errors_total",{label:"address",help:"Total count of TCP listener errors by type"}),events:e.metrics.registerMetricGroup("libp2p_tcp_listener_events_total",{label:"address",help:"Total count of TCP listener events by type"})},this.metrics?.status.update({[this.addr]:A.ACTIVE})}this.safeDispatchEvent("listening")}).on("error",t=>{this.metrics?.errors.increment({[`${this.addr} listen_error`]:!0}),this.safeDispatchEvent("error",{detail:t})}).on("close",()=>{this.metrics?.status.update({[this.addr]:this.status.code}),this.status.code!==A.PAUSED&&this.safeDispatchEvent("close")}).on("drop",()=>{this.metrics?.events.increment({[`${this.addr} drop`]:!0})})}onSocket(e){if(this.metrics?.events.increment({[`${this.addr} connection`]:!0}),this.status.code!==A.ACTIVE)throw e.destroy(),new we("Server is not listening yet");let t;try{t=Oe(e,{listeningAddr:this.status.listeningAddr,socketInactivityTimeout:this.context.socketInactivityTimeout,socketCloseTimeout:this.context.socketCloseTimeout,metrics:this.metrics?.events,metricPrefix:`${this.addr} `,logger:this.context.logger,direction:"inbound"})}catch(n){this.log.error("inbound connection failed",n),this.metrics?.errors.increment({[`${this.addr} inbound_to_connection`]:!0}),e.destroy();return}this.log("new inbound connection %s",t.remoteAddr),this.sockets.add(e),this.context.upgrader.upgradeInbound(t,{signal:this.shutdownController.signal}).then(()=>{this.log("inbound connection upgraded %s",t.remoteAddr),e.once("close",()=>{this.sockets.delete(e),this.context.closeServerOnMaxConnections!=null&&this.sockets.size<this.context.closeServerOnMaxConnections.listenBelow&&this.resume().catch(n=>{this.log.error("error attempting to listen server once connection count under limit",n),this.context.closeServerOnMaxConnections?.onListenError?.(n)})}),this.context.closeServerOnMaxConnections!=null&&this.sockets.size>=this.context.closeServerOnMaxConnections.closeAbove&&this.pause()}).catch(async n=>{this.log.error("inbound connection upgrade failed",n),this.metrics?.errors.increment({[`${this.addr} inbound_upgrade`]:!0}),this.sockets.delete(e),t.abort(n)})}getAddrs(){if(this.status.code===A.INACTIVE)return[];let e=[],t=this.server.address(),{listeningAddr:n,peerId:o}=this.status;if(t==null)return[];if(typeof t=="string")e=[n];else try{n.toString().startsWith("/ip4")?e=e.concat(Ot("ip4",t.address,t.port)):t.family==="IPv6"&&(e=e.concat(Ot("ip6",t.address,t.port)))}catch(s){this.log.error("could not turn %s:%s into multiaddr",t.address,t.port,s)}return e.map(s=>o!=null?s.encapsulate(`/p2p/${o}`):s)}updateAnnounceAddrs(){}async listen(e){if(this.status.code===A.ACTIVE||this.status.code===A.PAUSED)throw new be("server is already listening");let t=e.getPeerId(),n=t==null?e.decapsulateCode(421):e,{backlog:o}=this.context;try{this.status={code:A.ACTIVE,listeningAddr:n,peerId:t,netConfig:ae(n,{backlog:o})},await this.resume()}catch(s){throw this.status={code:A.INACTIVE},s}}async close(){let e=[];this.server.listening&&e.push(Mt(this.server,"close")),this.pause(!0),this.shutdownController.abort(),this.sockets.forEach(t=>{t.readable&&(e.push(Mt(t,"close")),t.destroy())}),await Promise.all(e)}async resume(){if(this.server.listening||this.status.code===A.INACTIVE)return;let e=this.status.netConfig;await new Promise((t,n)=>{this.server.once("error",n),this.server.listen(e,t)}),this.status={...this.status,code:A.ACTIVE},this.log("listening on %s",this.server.address())}pause(e=!1){if(!this.server.listening&&this.status.code===A.PAUSED&&e){this.status={code:A.INACTIVE};return}!this.server.listening||this.status.code!==A.ACTIVE||(this.log("closing server on %s",this.server.address()),this.status=e?{code:A.INACTIVE}:{...this.status,code:A.PAUSED},this.server.close())}};var ze=class{opts;metrics;components;log;constructor(e,t={}){this.log=e.logger.forComponent("libp2p:tcp"),this.opts=t,this.components=e,e.metrics!=null&&(this.metrics={events:e.metrics.registerCounterGroup("libp2p_tcp_dialer_events_total",{label:"event",help:"Total count of TCP dialer events by type"}),errors:e.metrics.registerCounterGroup("libp2p_tcp_dialer_errors_total",{label:"event",help:"Total count of TCP dialer events by type"})})}[Bt]=!0;[Symbol.toStringTag]="@libp2p/tcp";[Rt]=["@libp2p/transport"];async dial(e,t){t.keepAlive=t.keepAlive??!0,t.noDelay=t.noDelay??!0;let n=await this._connect(e,t),o;try{o=Oe(n,{remoteAddr:e,socketInactivityTimeout:this.opts.outboundSocketInactivityTimeout,socketCloseTimeout:this.opts.socketCloseTimeout,metrics:this.metrics?.events,logger:this.components.logger,direction:"outbound"})}catch(s){throw this.metrics?.errors.increment({outbound_to_connection:!0}),n.destroy(s),s}try{return this.log("new outbound connection %s",o.remoteAddr),await t.upgrader.upgradeOutbound(o,t)}catch(s){throw this.metrics?.errors.increment({outbound_upgrade:!0}),this.log.error("error upgrading outbound connection",s),o.abort(s),s}}async _connect(e,t){t.signal?.throwIfAborted(),t.onProgress?.(new $e("tcp:open-connection"));let n;return new Promise((o,s)=>{let i=Date.now(),a=ae(e,{...this.opts.dialOpts??{},...t});this.log("dialing %a",e),n=_r.default.connect(a);let d=l=>{this.log.error("dial to %a errored - %e",e,l);let f=a.path??`${a.host??""}:${a.port}`;l.message=`connection error ${f}: ${l.message}`,this.metrics?.events.increment({error:!0}),b(l)},m=()=>{this.log("connection timeout %a",e),this.metrics?.events.increment({timeout:!0});let l=new Z(`Connection timeout after ${Date.now()-i}ms`);n.emit("error",l)},p=()=>{this.log("connection opened %a",e),this.metrics?.events.increment({connect:!0}),b()},h=()=>{this.log("connection aborted %a",e),this.metrics?.events.increment({abort:!0}),b(new ge)},b=l=>{if(n.removeListener("error",d),n.removeListener("timeout",m),n.removeListener("connect",p),t.signal!=null&&t.signal.removeEventListener("abort",h),l!=null){s(l);return}o(n)};n.on("error",d),n.on("timeout",m),n.on("connect",p),t.signal!=null&&t.signal.addEventListener("abort",h)}).catch(o=>{throw n?.destroy(),o})}createListener(e){return new Ve({...this.opts.listenOpts??{},...e,maxConnections:this.opts.maxConnections,backlog:this.opts.backlog,closeServerOnMaxConnections:this.opts.closeServerOnMaxConnections,socketInactivityTimeout:this.opts.inboundSocketInactivityTimeout,socketCloseTimeout:this.opts.socketCloseTimeout,metrics:this.components.metrics,logger:this.components.logger})}listenFilter(e){return e=Array.isArray(e)?e:[e],e.filter(t=>t.protoCodes().includes(290)?!1:t.protoCodes().includes(400)?!0:H.matches(t.decapsulateCode(421)))}dialFilter(e){return this.listenFilter(e)}};function Jo(r={}){return e=>new ze(e,r)}return Hr(Qo);})(); | ||
"use strict";var Libp2PTcp=(()=>{var Rr=Object.create;var xe=Object.defineProperty;var jr=Object.getOwnPropertyDescriptor;var qr=Object.getOwnPropertyNames;var Wr=Object.getPrototypeOf,Gr=Object.prototype.hasOwnProperty;var F=(r=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(r,{get:(e,t)=>(typeof require<"u"?require:e)[t]}):r)(function(r){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+r+'" is not supported')});var D=(r,e)=>{for(var t in e)xe(r,t,{get:e[t],enumerable:!0})},Vt=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of qr(e))!Gr.call(r,o)&&o!==t&&xe(r,o,{get:()=>e[o],enumerable:!(n=jr(e,o))||n.enumerable});return r};var le=(r,e,t)=>(t=r!=null?Rr(Wr(r)):{},Vt(e||!r||!r.__esModule?xe(t,"default",{value:r,enumerable:!0}):t,r)),Hr=r=>Vt(xe({},"__esModule",{value:!0}),r);var Qo={};D(Qo,{tcp:()=>Jo});var _r=le(F("net"),1);var Bt=Symbol.for("@libp2p/transport");var zt;(function(r){r[r.FATAL_ALL=0]="FATAL_ALL",r[r.NO_FATAL=1]="NO_FATAL"})(zt||(zt={}));var ge=class extends Error{static name="AbortError";constructor(e="The operation was aborted"){super(e),this.name="AbortError"}};var V=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}};var Z=class extends Error{static name="TimeoutError";constructor(e="Timed out"){super(e),this.name="TimeoutError"}},we=class extends Error{static name="NotStartedError";constructor(e="Not started"){super(e),this.name="NotStartedError"}},be=class extends Error{static name="AlreadyStartedError";constructor(e="Already started"){super(e),this.name="AlreadyStartedError"}};var _t=F("node:events"),ve=(r,...e)=>{try{(0,_t.setMaxListeners)(r,...e)}catch{}};var ye=class extends EventTarget{#e=new Map;constructor(){super(),ve(1/0,this)}listenerCount(e){let t=this.#e.get(e);return t==null?0:t.length}addEventListener(e,t,n){super.addEventListener(e,t,n);let o=this.#e.get(e);o==null&&(o=[],this.#e.set(e,o)),o.push({callback:t,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(e,t,n){super.removeEventListener(e.toString(),t??null,n);let o=this.#e.get(e);o!=null&&(o=o.filter(({callback:s})=>s!==t),this.#e.set(e,o))}dispatchEvent(e){let t=super.dispatchEvent(e),n=this.#e.get(e.type);return n==null||(n=n.filter(({once:o})=>!o),this.#e.set(e.type,n)),t}safeDispatchEvent(e,t={}){return this.dispatchEvent(new CustomEvent(e,t))}};var Rt=Symbol.for("@libp2p/service-capabilities"),rs=Symbol.for("@libp2p/service-dependencies");var jt=F("node:buffer");function ee(r){return new Uint8Array(r.buffer,r.byteOffset,r.byteLength)}function Ee(r=0){return ee(jt.Buffer.allocUnsafe(r))}var Jr=Math.pow(2,7),Qr=Math.pow(2,14),Xr=Math.pow(2,21),Be=Math.pow(2,28),_e=Math.pow(2,35),Re=Math.pow(2,42),je=Math.pow(2,49),g=128,C=127;function z(r){if(r<Jr)return 1;if(r<Qr)return 2;if(r<Xr)return 3;if(r<Be)return 4;if(r<_e)return 5;if(r<Re)return 6;if(r<je)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Kr(r,e,t=0){switch(z(r)){case 8:e[t++]=r&255|g,r/=128;case 7:e[t++]=r&255|g,r/=128;case 6:e[t++]=r&255|g,r/=128;case 5:e[t++]=r&255|g,r/=128;case 4:e[t++]=r&255|g,r>>>=7;case 3:e[t++]=r&255|g,r>>>=7;case 2:e[t++]=r&255|g,r>>>=7;case 1:{e[t++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return e}function Yr(r,e,t=0){switch(z(r)){case 8:e.set(t++,r&255|g),r/=128;case 7:e.set(t++,r&255|g),r/=128;case 6:e.set(t++,r&255|g),r/=128;case 5:e.set(t++,r&255|g),r/=128;case 4:e.set(t++,r&255|g),r>>>=7;case 3:e.set(t++,r&255|g),r>>>=7;case 2:e.set(t++,r&255|g),r>>>=7;case 1:{e.set(t++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return e}function Zr(r,e){let t=r[e],n=0;if(n+=t&C,t<g||(t=r[e+1],n+=(t&C)<<7,t<g)||(t=r[e+2],n+=(t&C)<<14,t<g)||(t=r[e+3],n+=(t&C)<<21,t<g)||(t=r[e+4],n+=(t&C)*Be,t<g)||(t=r[e+5],n+=(t&C)*_e,t<g)||(t=r[e+6],n+=(t&C)*Re,t<g)||(t=r[e+7],n+=(t&C)*je,t<g))return n;throw new RangeError("Could not decode varint")}function en(r,e){let t=r.get(e),n=0;if(n+=t&C,t<g||(t=r.get(e+1),n+=(t&C)<<7,t<g)||(t=r.get(e+2),n+=(t&C)<<14,t<g)||(t=r.get(e+3),n+=(t&C)<<21,t<g)||(t=r.get(e+4),n+=(t&C)*Be,t<g)||(t=r.get(e+5),n+=(t&C)*_e,t<g)||(t=r.get(e+6),n+=(t&C)*Re,t<g)||(t=r.get(e+7),n+=(t&C)*je,t<g))return n;throw new RangeError("Could not decode varint")}function te(r,e,t=0){return e==null&&(e=Ee(z(r))),e instanceof Uint8Array?Kr(r,e,t):Yr(r,e,t)}function J(r,e=0){return r instanceof Uint8Array?Zr(r,e):en(r,e)}var Wt=F("node:buffer");function _(r,e){return ee(Wt.Buffer.concat(r,e))}var dr=F("node:buffer");var Je={};D(Je,{base10:()=>cn});var Ms=new Uint8Array(0);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}function k(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")}function Ht(r){return new TextEncoder().encode(r)}function Jt(r){return new TextDecoder().decode(r)}function tn(r,e){if(r.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),n=0;n<t.length;n++)t[n]=255;for(var o=0;o<r.length;o++){var s=r.charAt(o),i=s.charCodeAt(0);if(t[i]!==255)throw new TypeError(s+" is ambiguous");t[i]=o}var a=r.length,d=r.charAt(0),m=Math.log(a)/Math.log(256),p=Math.log(256)/Math.log(a);function h(f){if(f instanceof Uint8Array||(ArrayBuffer.isView(f)?f=new Uint8Array(f.buffer,f.byteOffset,f.byteLength):Array.isArray(f)&&(f=Uint8Array.from(f))),!(f instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(f.length===0)return"";for(var I=0,T=0,x=0,w=f.length;x!==w&&f[x]===0;)x++,I++;for(var L=(w-x)*p+1>>>0,M=new Uint8Array(L);x!==w;){for(var O=f[x],j=0,N=L-1;(O!==0||j<T)&&N!==-1;N--,j++)O+=256*M[N]>>>0,M[N]=O%a>>>0,O=O/a>>>0;if(O!==0)throw new Error("Non-zero carry");T=j,x++}for(var B=L-T;B!==L&&M[B]===0;)B++;for(var me=d.repeat(I);B<L;++B)me+=r.charAt(M[B]);return me}function b(f){if(typeof f!="string")throw new TypeError("Expected String");if(f.length===0)return new Uint8Array;var I=0;if(f[I]!==" "){for(var T=0,x=0;f[I]===d;)T++,I++;for(var w=(f.length-I)*m+1>>>0,L=new Uint8Array(w);f[I];){var M=t[f.charCodeAt(I)];if(M===255)return;for(var O=0,j=w-1;(M!==0||O<x)&&j!==-1;j--,O++)M+=a*L[j]>>>0,L[j]=M%256>>>0,M=M/256>>>0;if(M!==0)throw new Error("Non-zero carry");x=O,I++}if(f[I]!==" "){for(var N=w-x;N!==w&&L[N]===0;)N++;for(var B=new Uint8Array(T+(w-N)),me=T;N!==w;)B[me++]=L[N++];return B}}}function l(f){var I=b(f);if(I)return I;throw new Error(`Non-${e} character`)}return{encode:h,decodeUnsafe:b,decode:l}}var rn=tn,nn=rn,Xt=nn;var qe=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")}},We=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,t,n){this.name=e,this.prefix=t;let o=t.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return Kt(this,e)}},Ge=class{decoders;constructor(e){this.decoders=e}or(e){return Kt(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 Kt(r,e){return new Ge({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var He=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 qe(e,t,n),this.decoder=new We(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function re({name:r,prefix:e,encode:t,decode:n}){return new He(r,e,t,n)}function q({name:r,prefix:e,alphabet:t}){let{encode:n,decode:o}=Xt(t,r);return re({prefix:e,name:r,encode:n,decode:s=>k(o(s))})}function on(r,e,t,n){let o={};for(let p=0;p<e.length;++p)o[e[p]]=p;let s=r.length;for(;r[s-1]==="=";)--s;let i=new Uint8Array(s*t/8|0),a=0,d=0,m=0;for(let p=0;p<s;++p){let h=o[r[p]];if(h===void 0)throw new SyntaxError(`Non-${n} character`);d=d<<t|h,a+=t,a>=8&&(a-=8,i[m++]=255&d>>a)}if(a>=t||(255&d<<8-a)!==0)throw new SyntaxError("Unexpected end of data");return i}function sn(r,e,t){let n=e[e.length-1]==="=",o=(1<<t)-1,s="",i=0,a=0;for(let d=0;d<r.length;++d)for(a=a<<8|r[d],i+=8;i>t;)i-=t,s+=e[o&a>>i];if(i!==0&&(s+=e[o&a<<t-i]),n)for(;(s.length*t&7)!==0;)s+="=";return s}function y({name:r,prefix:e,bitsPerChar:t,alphabet:n}){return re({prefix:e,name:r,encode(o){return sn(o,n,t)},decode(o){return on(o,n,t,r)}})}var cn=q({prefix:"9",name:"base10",alphabet:"0123456789"});var Qe={};D(Qe,{base16:()=>an,base16upper:()=>ln});var an=y({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),ln=y({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Xe={};D(Xe,{base2:()=>un});var un=y({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Ke={};D(Ke,{base256emoji:()=>mn});var Yt=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=Yt.reduce((r,e,t)=>(r[t]=e,r),[]),pn=Yt.reduce((r,e,t)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return r[n]=t,r},[]);function fn(r){return r.reduce((e,t)=>(e+=dn[t],e),"")}function hn(r){let e=[];for(let t of r){let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);let o=pn[n];if(o==null)throw new Error(`Non-base256emoji character: ${t}`);e.push(o)}return new Uint8Array(e)}var mn=re({prefix:"\u{1F680}",name:"base256emoji",encode:fn,decode:hn});var Ye={};D(Ye,{base32:()=>R,base32hex:()=>bn,base32hexpad:()=>yn,base32hexpadupper:()=>En,base32hexupper:()=>vn,base32pad:()=>gn,base32padupper:()=>wn,base32upper:()=>xn,base32z:()=>In});var R=y({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),xn=y({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),gn=y({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),wn=y({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),bn=y({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),vn=y({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),yn=y({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),En=y({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),In=y({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Ze={};D(Ze,{base36:()=>ue,base36upper:()=>An});var ue=q({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),An=q({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var et={};D(et,{base58btc:()=>P,base58flickr:()=>Cn});var P=q({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Cn=q({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var tt={};D(tt,{base64:()=>Tn,base64pad:()=>Sn,base64url:()=>Pn,base64urlpad:()=>Ln});var Tn=y({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Sn=y({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Pn=y({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Ln=y({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var rt={};D(rt,{base8:()=>Dn});var Dn=y({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var nt={};D(nt,{identity:()=>Mn});var Mn=re({prefix:"\0",name:"identity",encode:r=>Jt(r),decode:r=>Ht(r)});var Hs=new TextEncoder,Js=new TextDecoder;var st={};D(st,{identity:()=>eo});var Nn=tr,Zt=128,Fn=127,$n=~Fn,On=Math.pow(2,31);function tr(r,e,t){e=e||[],t=t||0;for(var n=t;r>=On;)e[t++]=r&255|Zt,r/=128;for(;r&$n;)e[t++]=r&255|Zt,r>>>=7;return e[t]=r|0,tr.bytes=t-n+1,e}var Vn=ot,zn=128,er=127;function ot(r,n){var t=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw ot.bytes=0,new RangeError("Could not decode varint");i=r[s++],t+=o<28?(i&er)<<o:(i&er)*Math.pow(2,o),o+=7}while(i>=zn);return ot.bytes=s-n,t}var Bn=Math.pow(2,7),_n=Math.pow(2,14),Rn=Math.pow(2,21),jn=Math.pow(2,28),qn=Math.pow(2,35),Wn=Math.pow(2,42),Gn=Math.pow(2,49),Hn=Math.pow(2,56),Jn=Math.pow(2,63),Qn=function(r){return r<Bn?1:r<_n?2:r<Rn?3:r<jn?4:r<qn?5:r<Wn?6:r<Gn?7:r<Hn?8:r<Jn?9:10},Xn={encode:Nn,decode:Vn,encodingLength:Qn},Kn=Xn,de=Kn;function pe(r,e=0){return[de.decode(r,e),de.decode.bytes]}function ne(r,e,t=0){return de.encode(r,e,t),e}function oe(r){return de.encodingLength(r)}function Q(r,e){let t=e.byteLength,n=oe(r),o=n+oe(t),s=new Uint8Array(o+t);return ne(r,s,0),ne(t,s,n),s.set(e,o),new se(r,t,e,s)}function Ae(r){let e=k(r),[t,n]=pe(e),[o,s]=pe(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new se(t,o,i,e)}function rr(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&Gt(r.bytes,t.bytes)}}var se=class{code;size;digest;bytes;constructor(e,t,n,o){this.code=e,this.size=t,this.digest=n,this.bytes=o}};var nr=0,Yn="identity",or=k;function Zn(r){return Q(nr,or(r))}var eo={code:nr,name:Yn,encode:or,digest:Zn};var lt={};D(lt,{sha256:()=>to,sha512:()=>ro});var at=le(F("crypto"),1);function ct({name:r,code:e,encode:t}){return new it(r,e,t)}var it=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?Q(this.code,t):t.then(n=>Q(this.code,n))}else throw Error("Unknown type, must be binary type")}};var to=ct({name:"sha2-256",code:18,encode:r=>k(at.default.createHash("sha256").update(r).digest())}),ro=ct({name:"sha2-512",code:19,encode:r=>k(at.default.createHash("sha512").update(r).digest())});function ir(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return oo(t,ut(r),e??P.encoder);default:return so(t,ut(r),e??R.encoder)}}var cr=new WeakMap;function ut(r){let e=cr.get(r);if(e==null){let t=new Map;return cr.set(r,t),t}return e}var W=class r{code;version;multihash;bytes;"/";constructor(e,t,n,o){this.code=t,this.version=e,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:t}=this;if(e!==fe)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==io)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=Q(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&&rr(e.multihash,n.multihash)}toString(e){return ir(this,e)}toJSON(){return{"/":ir(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??ar(n,o,s.bytes))}else if(t[co]===!0){let{version:n,multihash:o,code:s}=t,i=Ae(o);return r.create(n,s,i)}else return null}static create(e,t,n){if(typeof t!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(t!==fe)throw new Error(`Version 0 CID must use dag-pb (code: ${fe}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let o=ar(e,t,n.bytes);return new r(e,t,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,fe,e)}static createV1(e,t){return r.create(1,e,t)}static decode(e){let[t,n]=r.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return t}static decodeFirst(e){let t=r.inspectBytes(e),n=t.size-t.multihashSize,o=k(e.subarray(n,n+t.multihashSize));if(o.byteLength!==t.multihashSize)throw new Error("Incorrect length");let s=o.subarray(t.multihashSize-t.digestSize),i=new se(t.multihashCode,t.digestSize,s,o);return[t.version===0?r.createV0(i):r.createV1(t.codec,i),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[h,b]=pe(e.subarray(t));return t+=b,h},o=n(),s=fe;if(o===18?(o=0,t=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=t,a=n(),d=n(),m=t+d,p=m-i;return{version:o,codec:s,multihashCode:a,digestSize:d,multihashSize:p,size:m}}static parse(e,t){let[n,o]=no(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 ut(s).set(n,e),s}};function no(r,e){switch(r[0]){case"Q":{let t=e??P;return[P.prefix,t.decode(`${P.prefix}${r}`)]}case P.prefix:{let t=e??P;return[P.prefix,t.decode(r)]}case R.prefix:{let t=e??R;return[R.prefix,t.decode(r)]}case ue.prefix:{let t=e??ue;return[ue.prefix,t.decode(r)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],e.decode(r)]}}}function oo(r,e,t){let{prefix:n}=t;if(n!==P.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let o=e.get(n);if(o==null){let s=t.encode(r).slice(1);return e.set(n,s),s}else return o}function so(r,e,t){let{prefix:n}=t,o=e.get(n);if(o==null){let s=t.encode(r);return e.set(n,s),s}else return o}var fe=112,io=18;function ar(r,e,t){let n=oe(r),o=n+oe(e),s=new Uint8Array(o+t.byteLength);return ne(r,s,0),ne(e,s,n),s.set(t,o),s}var co=Symbol.for("@ipld/js-cid/CID");var he={...nt,...Xe,...rt,...Je,...Qe,...Ye,...Ze,...et,...tt,...Ke},gi={...lt,...st};function ur(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var lr=ur("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),dt=ur("ascii","a",r=>{let e="a";for(let t=0;t<r.length;t++)e+=String.fromCharCode(r[t]);return e},r=>{r=r.substring(1);let e=Ee(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),ao={utf8:lr,"utf-8":lr,hex:he.base16,latin1:dt,ascii:dt,binary:dt,...he},Ce=ao;function S(r,e="utf8"){let t=Ce[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return e==="utf8"||e==="utf-8"?dr.Buffer.from(r.buffer,r.byteOffset,r.byteLength).toString("utf8"):t.encoder.encode(r).substring(1)}var Te=class{index=0;input="";new(e){return this.index=0,this.input=e,this}readAtomically(e){let t=this.index,n=e();return n===void 0&&(this.index=t),n}parseWith(e){let t=e();if(this.index===this.input.length)return t}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(e){return this.readAtomically(()=>{let t=this.readChar();if(t===e)return t})}readSeparator(e,t,n){return this.readAtomically(()=>{if(!(t>0&&this.readGivenChar(e)===void 0))return n()})}readNumber(e,t,n,o){return this.readAtomically(()=>{let s=0,i=0,a=this.peekChar();if(a===void 0)return;let d=a==="0",m=2**(8*o)-1;for(;;){let p=this.readAtomically(()=>{let h=this.readChar();if(h===void 0)return;let b=Number.parseInt(h,e);if(!Number.isNaN(b))return b});if(p===void 0)break;if(s*=e,s+=p,s>m||(i+=1,t!==void 0&&i>t))return}if(i!==0)return!n&&d&&i>1?void 0:s})}readIPv4Addr(){return this.readAtomically(()=>{let e=new Uint8Array(4);for(let t=0;t<e.length;t++){let n=this.readSeparator(".",t,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;e[t]=n}return e})}readIPv6Addr(){let e=t=>{for(let n=0;n<t.length/2;n++){let o=n*2;if(n<t.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return t[o]=i[0],t[o+1]=i[1],t[o+2]=i[2],t[o+3]=i[3],[o+4,!0]}let s=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(s===void 0)return[o,!1];t[o]=s>>8,t[o+1]=s&255}return[t.length,!1]};return this.readAtomically(()=>{let t=new Uint8Array(16),[n,o]=e(t);if(n===16)return t;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let s=new Uint8Array(14),i=16-(n+2),[a]=e(s.subarray(0,i));return t.set(s.subarray(0,a),16-a),t})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var Ti=new Te;var Ni=parseInt("0xFFFF",16),Fi=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);var hr=F("node:buffer");function Se(r,e="utf8"){let t=Ce[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return e==="utf8"||e==="utf-8"?ee(hr.Buffer.from(r,"utf-8")):t.decoder.decode(`${t.prefix}${r}`)}var U=F("node:net");function Pe(r){return!!(0,U.isIP)(r)}var mr=U.isIPv4,mo=U.isIPv6,pt=function(r){let e=0;if(r=r.toString().trim(),mr(r)){let t=new Uint8Array(e+4);return r.split(/\./g).forEach(n=>{t[e++]=parseInt(n,10)&255}),t}if(mo(r)){let t=r.split(":",8),n;for(n=0;n<t.length;n++){let s=mr(t[n]),i;s&&(i=pt(t[n]),t[n]=S(i.slice(0,2),"base16")),i!=null&&++n<8&&t.splice(n,0,S(i.slice(2,4),"base16"))}if(t[0]==="")for(;t.length<8;)t.unshift("0");else if(t[t.length-1]==="")for(;t.length<8;)t.push("0");else if(t.length<8){for(n=0;n<t.length&&t[n]!=="";n++);let s=[n,1];for(n=9-t.length;n>0;n--)s.push("0");t.splice.apply(t,s)}let o=new Uint8Array(e+16);for(n=0;n<t.length;n++){let s=parseInt(t[n],16);o[e++]=s>>8&255,o[e++]=s&255}return o}throw new Error("invalid ip address")},xr=function(r,e=0,t){e=~~e,t=t??r.length-e;let n=new DataView(r.buffer);if(t===4){let o=[];for(let s=0;s<t;s++)o.push(r[e+s]);return o.join(".")}if(t===16){let o=[];for(let s=0;s<t;s+=2)o.push(n.getUint16(e+s).toString(16));return o.join(":").replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}return""};var ce={},ft={},go=[[4,32,"ip4"],[6,16,"tcp"],[33,16,"dccp"],[41,128,"ip6"],[42,-1,"ip6zone"],[43,8,"ipcidr"],[53,-1,"dns",!0],[54,-1,"dns4",!0],[55,-1,"dns6",!0],[56,-1,"dnsaddr",!0],[132,16,"sctp"],[273,16,"udp"],[275,0,"p2p-webrtc-star"],[276,0,"p2p-webrtc-direct"],[277,0,"p2p-stardust"],[280,0,"webrtc-direct"],[281,0,"webrtc"],[290,0,"p2p-circuit"],[301,0,"udt"],[302,0,"utp"],[400,-1,"unix",!1,!0],[421,-1,"ipfs"],[421,-1,"p2p"],[443,0,"https"],[444,96,"onion"],[445,296,"onion3"],[446,-1,"garlic64"],[448,0,"tls"],[449,-1,"sni"],[460,0,"quic"],[461,0,"quic-v1"],[465,0,"webtransport"],[466,-1,"certhash"],[477,0,"ws"],[478,0,"wss"],[479,0,"p2p-websocket-star"],[480,0,"http"],[481,-1,"http-path"],[777,-1,"memory"]];go.forEach(r=>{let e=wo(...r);ft[e.code]=e,ce[e.name]=e});function wo(r,e,t,n,o){return{code:r,size:e,name:t,resolvable:!!n,path:!!o}}function v(r){if(typeof r=="number"){if(ft[r]!=null)return ft[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(ce[r]!=null)return ce[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var Ec=v("ip4"),Ic=v("ip6"),Ac=v("ipcidr");function gt(r,e){switch(v(r).code){case 4:case 41:return vo(e);case 42:return xt(e);case 43:return S(e,"base10");case 6:case 273:case 33:case 132:return br(e).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return xt(e);case 421:return Ao(e);case 444:return wr(e);case 445:return wr(e);case 466:return Io(e);case 481:return globalThis.encodeURIComponent(xt(e));default:return S(e,"base16")}}function wt(r,e){switch(v(r).code){case 4:return gr(e);case 41:return gr(e);case 42:return mt(e);case 43:return Se(e,"base10");case 6:case 273:case 33:case 132:return bt(parseInt(e,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return mt(e);case 421:return yo(e);case 444:return Co(e);case 445:return To(e);case 466:return Eo(e);case 481:return mt(globalThis.decodeURIComponent(e));default:return Se(e,"base16")}}var ht=Object.values(he).map(r=>r.decoder),bo=function(){let r=ht[0].or(ht[1]);return ht.slice(2).forEach(e=>r=r.or(e)),r}();function gr(r){if(!Pe(r))throw new Error("invalid ip address");return pt(r)}function vo(r){let e=xr(r,0,r.length);if(e==null)throw new Error("ipBuff is required");if(!Pe(e))throw new Error("invalid ip address");return e}function bt(r){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,r),new Uint8Array(e)}function br(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function mt(r){let e=Se(r),t=Uint8Array.from(te(e.length));return _([t,e],t.length+e.length)}function xt(r){let e=J(r);if(r=r.slice(z(e)),r.length!==e)throw new Error("inconsistent lengths");return S(r)}function yo(r){let e;r[0]==="Q"||r[0]==="1"?e=Ae(P.decode(`z${r}`)).bytes:e=W.parse(r).multihash.bytes;let t=Uint8Array.from(te(e.length));return _([t,e],t.length+e.length)}function Eo(r){let e=bo.decode(r),t=Uint8Array.from(te(e.length));return _([t,e],t.length+e.length)}function Io(r){let e=J(r),t=r.slice(z(e));if(t.length!==e)throw new Error("inconsistent lengths");return"u"+S(t,"base64url")}function Ao(r){let e=J(r),t=r.slice(z(e));if(t.length!==e)throw new Error("inconsistent lengths");return S(t,"base58btc")}function Co(r){let e=r.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==16)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion address.`);let t=R.decode("b"+e[0]),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=bt(n);return _([t,o],t.length+o.length)}function To(r){let e=r.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==56)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion3 address.`);let t=R.decode(`b${e[0]}`),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=bt(n);return _([t,o],t.length+o.length)}function wr(r){let e=r.slice(0,r.length-2),t=r.slice(r.length-2),n=S(e,"base32"),o=br(t);return`${n}:${o}`}function vr(r){r=vt(r);let e=[],t=[],n=null,o=r.split("/").slice(1);if(o.length===1&&o[0]==="")return{bytes:new Uint8Array,string:"/",tuples:[],stringTuples:[],path:null};for(let s=0;s<o.length;s++){let i=o[s],a=v(i);if(a.size===0){e.push([a.code]),t.push([a.code]);continue}if(s++,s>=o.length)throw new Le("invalid address: "+r);if(a.path===!0){n=vt(o.slice(s).join("/")),e.push([a.code,wt(a.code,n)]),t.push([a.code,n]);break}let d=wt(a.code,o[s]);e.push([a.code,d]),t.push([a.code,gt(a.code,d)])}return{string:yr(t),bytes:De(e),tuples:e,stringTuples:t,path:n}}function yt(r){let e=[],t=[],n=null,o=0;for(;o<r.length;){let s=J(r,o),i=z(s),a=v(s),d=So(a,r.slice(o+i));if(d===0){e.push([s]),t.push([s]),o+=i;continue}let m=r.slice(o+i,o+i+d);if(o+=d+i,o>r.length)throw new Le("Invalid address Uint8Array: "+S(r,"base16"));e.push([s,m]);let p=gt(s,m);if(t.push([s,p]),a.path===!0){n=p;break}}return{bytes:Uint8Array.from(r),string:yr(t),tuples:e,stringTuples:t,path:n}}function yr(r){let e=[];return r.map(t=>{let n=v(t[0]);return e.push(n.name),t.length>1&&t[1]!=null&&e.push(t[1]),null}),vt(e.join("/"))}function De(r){return _(r.map(e=>{let t=v(e[0]),n=Uint8Array.from(te(t.code));return e.length>1&&e[1]!=null&&(n=_([n,e[1]])),n}))}function So(r,e){if(r.size>0)return r.size/8;if(r.size===0)return 0;{let t=J(e instanceof Uint8Array?e:Uint8Array.from(e));return t+z(t)}}function vt(r){return"/"+r.trim().split("/").filter(e=>e).join("/")}var Le=class extends Error{static name="ParseError";name="ParseError";constructor(e){super(`Error parsing address: ${e}`)}};function Er(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 Po=Symbol.for("nodejs.util.inspect.custom"),It=Symbol.for("@multiformats/js-multiaddr/multiaddr"),Lo=[v("dns").code,v("dns4").code,v("dns6").code,v("dnsaddr").code],Et=class extends Error{constructor(e="No available resolver"){super(e),this.name="NoAvailableResolverError"}},Me=class r{bytes;#e;#t;#r;#n;[It]=!0;constructor(e){e==null&&(e="");let t;if(e instanceof Uint8Array)t=yt(e);else if(typeof e=="string"){if(e.length>0&&e.charAt(0)!=="/")throw new Error(`multiaddr "${e}" must start with a "/"`);t=vr(e)}else if(Ar(e))t=yt(e.bytes);else throw new Error("addr must be a string, Buffer, or another Multiaddr");this.bytes=t.bytes,this.#e=t.string,this.#t=t.tuples,this.#r=t.stringTuples,this.#n=t.path}toString(){return this.#e}toJSON(){return this.toString()}toOptions(){let e,t,n,o,s="",i=v("tcp"),a=v("udp"),d=v("ip4"),m=v("ip6"),p=v("dns6"),h=v("ip6zone");for(let[l,f]of this.stringTuples())l===h.code&&(s=`%${f??""}`),Lo.includes(l)&&(t=i.name==="tcp"?"tcp":"udp",o=443,n=`${f??""}${s}`,e=l===p.code?6:4),(l===i.code||l===a.code)&&(t=v(l).name==="tcp"?"tcp":"udp",o=parseInt(f??"")),(l===d.code||l===m.code)&&(t=v(l).name==="tcp"?"tcp":"udp",n=`${f??""}${s}`,e=l===m.code?6:4);if(e==null||t==null||n==null||o==null)throw new Error('multiaddr must have a valid format: "/{ip4, ip6, dns4, dns6, dnsaddr}/{address}/{tcp, udp}/{port}".');return{family:e,host:n,transport:t,port:o}}protos(){return this.#t.map(([e])=>Object.assign({},v(e)))}protoCodes(){return this.#t.map(([e])=>e)}protoNames(){return this.#t.map(([e])=>v(e).name)}tuples(){return this.#t.map(([e,t])=>t==null?[e]:[e,t])}stringTuples(){return this.#r.map(([e,t])=>t==null?[e]:[e,t])}encapsulate(e){return e=new r(e),new r(this.toString()+e.toString())}decapsulate(e){let t=e.toString(),n=this.toString(),o=n.lastIndexOf(t);if(o<0)throw new Error(`Address ${this.toString()} does not contain subaddress: ${e.toString()}`);return new r(n.slice(0,o))}decapsulateCode(e){let t=this.tuples();for(let n=t.length-1;n>=0;n--)if(t[n][0]===e)return new r(De(t.slice(0,n)));return this}getPeerId(){try{let e=[];this.stringTuples().forEach(([n,o])=>{n===ce.p2p.code&&e.push([n,o]),n===ce["p2p-circuit"].code&&(e=[])});let t=e.pop();if(t?.[1]!=null){let n=t[1];return n[0]==="Q"||n[0]==="1"?S(P.decode(`z${n}`),"base58btc"):S(W.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){return this.#n}equals(e){return Er(this.bytes,e.bytes)}async resolve(e){let t=this.protos().find(s=>s.resolvable);if(t==null)return[this];let n=Ir.get(t.name);if(n==null)throw new Et(`no available resolver for ${t.name}`);return(await n(this,e)).map(s=>$(s))}nodeAddress(){let e=this.toOptions();if(e.transport!=="tcp"&&e.transport!=="udp")throw new Error(`multiaddr must have a valid format - no protocol with name: "${e.transport}". Must have a valid transport protocol: "{tcp, udp}"`);return{family:e.family,address:e.host,port:e.port}}isThinWaistAddress(e){let t=(e??this).protos();return!(t.length!==2||t[0].code!==4&&t[0].code!==41||t[1].code!==6&&t[1].code!==273)}[Po](){return`Multiaddr(${this.#e})`}};var Ir=new Map;function Ar(r){return!!r?.[It]}function $(r){return new Me(r)}var Do=c("dns4"),Mo=c("dns6"),ko=c("dnsaddr"),K=E(c("dns"),ko,Do,Mo),Ne=E(c("ip4"),c("ip6")),H=E(u(Ne,c("tcp")),u(K,c("tcp"))),Fe=u(Ne,c("udp")),Uo=u(Fe,c("utp")),No=u(Fe,c("quic")),Fo=u(Fe,c("quic-v1")),At=E(u(H,c("ws")),u(K,c("ws"))),ke=E(u(At,c("p2p")),At),Ct=E(u(H,c("wss")),u(K,c("wss")),u(H,c("tls"),c("ws")),u(K,c("tls"),c("ws"))),Ue=E(u(Ct,c("p2p")),Ct),Tt=E(u(H,c("http")),u(Ne,c("http")),u(K,c("http"))),St=E(u(H,c("https")),u(Ne,c("https")),u(K,c("https"))),Cr=u(Fe,c("webrtc-direct"),c("certhash")),Pr=E(u(Cr,c("p2p")),Cr),Tr=u(Fo,c("webtransport"),c("certhash"),c("certhash")),Lr=E(u(Tr,c("p2p")),Tr),Dr=E(u(ke,c("p2p-webrtc-star"),c("p2p")),u(Ue,c("p2p-webrtc-star"),c("p2p")),u(ke,c("p2p-webrtc-star")),u(Ue,c("p2p-webrtc-star"))),Yc=E(u(ke,c("p2p-websocket-star"),c("p2p")),u(Ue,c("p2p-websocket-star"),c("p2p")),u(ke,c("p2p-websocket-star")),u(Ue,c("p2p-websocket-star"))),Mr=E(u(Tt,c("p2p-webrtc-direct"),c("p2p")),u(St,c("p2p-webrtc-direct"),c("p2p")),u(Tt,c("p2p-webrtc-direct")),u(St,c("p2p-webrtc-direct"))),Y=E(At,Ct,Tt,St,Dr,Mr,H,Uo,No,K,Pr,Lr),Zc=E(u(Y,c("p2p-stardust"),c("p2p")),u(Y,c("p2p-stardust"))),G=E(u(Y,c("p2p")),Dr,Mr,Pr,Lr,c("p2p")),Sr=E(u(G,c("p2p-circuit"),G),u(G,c("p2p-circuit")),u(c("p2p-circuit"),G),u(Y,c("p2p-circuit")),u(c("p2p-circuit"),Y),c("p2p-circuit")),kr=()=>E(u(Sr,kr),Sr),X=kr(),ea=E(u(X,G,X),u(G,X),u(X,G),X,G);var ta=E(u(X,c("webrtc"),c("p2p")),u(X,c("webrtc")),u(Y,c("webrtc"),c("p2p")),u(Y,c("webrtc")),c("webrtc"));function Ur(r){function e(t){let n;try{n=$(t)}catch{return!1}let o=r(n.protoNames());return o===null?!1:o===!0||o===!1?o:o.length===0}return e}function u(...r){function e(t){if(t.length<r.length)return null;let n=t;return r.some(o=>(n=typeof o=="function"?o().partialMatch(t):o.partialMatch(t),Array.isArray(n)&&(t=n),n===null)),n}return{toString:function(){return"{ "+r.join(" ")+" }"},input:r,matches:Ur(e),partialMatch:e}}function E(...r){function e(n){let o=null;return r.some(s=>{let i=typeof s=="function"?s().partialMatch(n):s.partialMatch(n);return i!=null?(o=i,!0):!1}),o}return{toString:function(){return"{ "+r.join(" ")+" }"},input:r,matches:Ur(e),partialMatch:e}}function c(r){let e=r;function t(o){let s;try{s=$(o)}catch{return!1}let i=s.protoNames();return i.length===1&&i[0]===e}function n(o){return o.length===0?null:o[0]===e?o.slice(1):null}return{toString:function(){return e},matches:t,partialMatch:n}}var $e=class extends Event{type;detail;constructor(e,t){super(e),this.type=e,this.detail=t}};var Br=le(F("net"),1);var Pt=class extends Error{constructor(e){super(e),this.name="TimeoutError"}},Lt=class extends Error{constructor(e){super(),this.name="AbortError",this.message=e}},Nr=r=>globalThis.DOMException===void 0?new Lt(r):new DOMException(r),Fr=r=>{let e=r.reason===void 0?Nr("This operation was aborted."):r.reason;return e instanceof Error?e:Nr(e)};function Dt(r,e){let{milliseconds:t,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout}}=e,i,a,m=new Promise((p,h)=>{if(typeof t!="number"||Math.sign(t)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${t}\``);if(e.signal){let{signal:l}=e;l.aborted&&h(Fr(l)),a=()=>{h(Fr(l))},l.addEventListener("abort",a,{once:!0})}if(t===Number.POSITIVE_INFINITY){r.then(p,h);return}let b=new Pt;i=s.setTimeout.call(void 0,()=>{if(n){try{p(n())}catch(l){h(l)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?p():o instanceof Error?h(o):(b.message=o??`Promise timed out after ${t} milliseconds`,h(b))},t),(async()=>{try{p(await r)}catch(l){h(l)}})()}).finally(()=>{m.clear(),a&&e.signal&&e.signal.removeEventListener("abort",a)});return m.clear=()=>{s.clearTimeout.call(void 0,i),i=void 0},m}var Oo=r=>{let e=r.addEventListener||r.on||r.addListener,t=r.removeEventListener||r.off||r.removeListener;if(!e||!t)throw new TypeError("Emitter is not compatible");return{addListener:e.bind(r),removeListener:t.bind(r)}};function Vo(r,e,t){let n,o=new Promise((s,i)=>{if(t={rejectionEvents:["error"],multiArgs:!1,resolveImmediately:!1,...t},!(t.count>=0&&(t.count===Number.POSITIVE_INFINITY||Number.isInteger(t.count))))throw new TypeError("The `count` option should be at least 0 or more");t.signal?.throwIfAborted();let a=[e].flat(),d=[],{addListener:m,removeListener:p}=Oo(r),h=(...l)=>{let f=t.multiArgs?l:l[0];t.filter&&!t.filter(f)||(d.push(f),t.count===d.length&&(n(),s(d)))},b=l=>{n(),i(l)};n=()=>{for(let l of a)p(l,h);for(let l of t.rejectionEvents)p(l,b)};for(let l of a)m(l,h);for(let l of t.rejectionEvents)m(l,b);t.signal&&t.signal.addEventListener("abort",()=>{b(t.signal.reason)},{once:!0}),t.resolveImmediately&&s(d)});if(o.cancel=n,typeof t.timeout=="number"){let s=Dt(o,{milliseconds:t.timeout});return s.cancel=n,s}return o}function Mt(r,e,t){typeof t=="function"&&(t={filter:t}),t={...t,count:1,resolveImmediately:!1};let n=Vo(r,e,t),o=n.then(s=>s[0]);return o.cancel=n.cancel,o}function $r(r,e){if(typeof r!="string")throw new V(`invalid ip provided: ${r}`);if(typeof e=="string"&&(e=parseInt(e)),isNaN(e))throw new V(`invalid port provided: ${e}`);if((0,U.isIPv4)(r))return $(`/ip4/${r}/tcp/${e}`);if((0,U.isIPv6)(r))return $(`/ip6/${r}/tcp/${e}`);throw new V(`invalid ip:port for creating a multiaddr: ${r}:${e}`)}function kt(){let r={};return r.promise=new Promise((e,t)=>{r.resolve=e,r.reject=t}),r}var Ut=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.name="AbortError",this.code=t??"ABORT_ERR"}};async function Nt(r,e,t,n){let o=new Ut(n?.errorMessage,n?.errorCode);return t?.aborted===!0?Promise.reject(o):new Promise((s,i)=>{function a(){t?.removeEventListener("abort",p),r.removeEventListener(e,d),n?.errorEvent!=null&&r.removeEventListener(n.errorEvent,m)}let d=h=>{try{if(n?.filter?.(h)===!1)return}catch(b){a(),i(b);return}a(),s(h)},m=h=>{a(),i(h.detail)},p=()=>{a(),i(o)};t?.addEventListener("abort",p),r.addEventListener(e,d),n?.errorEvent!=null&&r.addEventListener(n.errorEvent,m)})}function Or(r){if(Bo(r))return async function*(){let e=r.getReader();try{for(;;){let{done:t,value:n}=await e.read();if(t)return;yield n}}finally{e.releaseLock()}}();if(zo(r))return r;throw new Error("unknown stream")}function zo(r){return r[Symbol.asyncIterator]!=null}function Bo(r){return typeof r?.getReader=="function"}function Vr(r){return async e=>{let t=async()=>{_o(e)&&await e.return(void 0)},n,o,s=x=>{n=x,t().catch(w=>{w=new AggregateError([n,w],"The Writable emitted an error, additionally an error occurred while ending the Source")}).finally(()=>{o?.(x)})},i,a=!1,d=()=>{a=!0,i?.()},m,p=!1,h=()=>{p=!0,m?.()},b,l=()=>{b?.()},f=async()=>new Promise((x,w)=>{i=b=x,o=w,r.once("drain",l)}),I=async()=>(await t(),new Promise((x,w)=>{if(a||p||n!=null){x();return}m=i=x,o=w})),T=()=>{r.removeListener("error",s),r.removeListener("close",d),r.removeListener("finish",h),r.removeListener("drain",l)};r.once("error",s),r.once("close",d),r.once("finish",h);try{for await(let x of e){if(!r.writable||r.destroyed||n!=null)break;r.write(x)||await f()}}catch(x){n==null&&r.destroy(x),n=x}try{if(r.writable&&r.end(),await I(),n!=null)throw n}finally{T()}}}function _o(r){return r.return!=null}function Ft(r){return{sink:Vr(r),source:Or(r)}}var $t=le(F("os"),1),zr=le(F("path"),1);var Ro={ip4:"IPv4",ip6:"IPv6"};function ae(r,e={}){let t=r.getPath();return t!=null?$t.default.platform()==="win32"?{path:zr.default.join("\\\\.\\pipe\\",t)}:{path:t}:{...e,...r.toOptions()}}function Ot(r,e,t){let n=o=>$(`/${r}/${o}/tcp/${t}`);return(jo(e)?Wo(Ro[r]):[e]).map(n)}function jo(r){return["0.0.0.0","::"].includes(r)}var qo=$t.default.networkInterfaces();function Wo(r){let e=[];for(let[,t]of Object.entries(qo))if(t!=null)for(let n of t)n.family===r&&e.push(n.address);return e}var Oe=(r,e)=>{let t,n=e.logger.forComponent("libp2p:tcp:socket"),o=e.direction,s=e.metrics,i=e.metricPrefix??"",a=e.socketInactivityTimeout??12e4,d=e.socketCloseTimeout??500,m=!1,p=!1;e.listeningAddr?.getPath()!=null&&(e.remoteAddr=e.listeningAddr),e.remoteAddr?.getPath()!=null&&(e.localAddr=e.remoteAddr),r.on("error",x=>{p=!0,m||(n.error("%s socket error - %e",o,x),s?.increment({[`${i}error`]:!0})),r.destroy(),T.timeline.close=Date.now()});let h;if(e.remoteAddr!=null)h=e.remoteAddr;else{if(r.remoteAddress==null||r.remotePort==null)throw new V("Could not determine remote address or port");h=$r(r.remoteAddress,r.remotePort)}let b=ae(h),l=b.path??`${b.host??""}:${b.port??""}`,{sink:f,source:I}=Ft(r);r.setTimeout(a),r.once("timeout",()=>{m=!0,n("%s %s socket read timeout",o,l),s?.increment({[`${i}timeout`]:!0}),r.destroy(new Z),T.timeline.close=Date.now()}),r.once("close",()=>{!m&&!p&&(n("%s %s socket close",o,l),s?.increment({[`${i}close`]:!0})),r.destroy(),T.timeline.close=Date.now()}),r.once("end",()=>{n("%s %s socket end",o,l),s?.increment({[`${i}end`]:!0})});let T={async sink(x){try{await f(async function*(){for await(let w of x)w instanceof Uint8Array?yield w:yield w.subarray()}())}catch(w){w.type!=="aborted"&&n.error("%s %s error in sink - %e",o,l,w)}r.end()},source:I,remoteAddr:h,timeline:{open:Date.now()},async close(x={}){if(r.closed){n("the %s %s socket is already closed",o,l);return}if(r.destroyed){n("the %s %s socket is already destroyed",o,l);return}if(t!=null)return t.promise;try{t=kt(),r.end();let w=Go(r),L=x.signal??AbortSignal.timeout(d);r.writableLength>0&&(n("%s %s draining socket",o,l),await Nt(w,"drain",L,{errorEvent:"error"}),n("%s %s socket drained",o,l)),await Promise.all([Nt(w,"close",L,{errorEvent:"error"}),r.destroy()])}catch(w){this.abort(w)}finally{t.resolve()}},abort:x=>{n("%s %s socket abort due to error - %e",o,l,x),r.destroy(),T.timeline.close=Date.now()},log:n};return T};function Go(r){return{addEventListener:(t,n)=>{r.addListener(t,n)},removeEventListener:(t,n)=>{r.removeListener(t,n)}}}var A;(function(r){r[r.INACTIVE=0]="INACTIVE",r[r.ACTIVE=1]="ACTIVE",r[r.PAUSED=2]="PAUSED"})(A||(A={}));var Ve=class extends ye{context;server;sockets=new Set;status={code:A.INACTIVE};metrics;addr;log;shutdownController;constructor(e){if(super(),this.context=e,e.keepAlive=e.keepAlive??!0,e.noDelay=e.noDelay??!0,this.shutdownController=new AbortController,ve(1/0,this.shutdownController.signal),this.log=e.logger.forComponent("libp2p:tcp:listener"),this.addr="unknown",this.server=Br.default.createServer(e,this.onSocket.bind(this)),e.maxConnections!==void 0&&(this.server.maxConnections=e.maxConnections),e.closeServerOnMaxConnections!=null&&e.closeServerOnMaxConnections.closeAbove<e.closeServerOnMaxConnections.listenBelow)throw new V("closeAbove must be >= listenBelow");this.server.on("listening",()=>{if(e.metrics!=null){let t=this.server.address();t==null?this.addr="unknown":typeof t=="string"?this.addr=t:this.addr=`${t.address}:${t.port}`,e.metrics?.registerMetricGroup("libp2p_tcp_inbound_connections_total",{label:"address",help:"Current active connections in TCP listener",calculate:()=>({[this.addr]:this.sockets.size})}),this.metrics={status:e.metrics.registerMetricGroup("libp2p_tcp_listener_status_info",{label:"address",help:"Current status of the TCP listener socket"}),errors:e.metrics.registerMetricGroup("libp2p_tcp_listener_errors_total",{label:"address",help:"Total count of TCP listener errors by type"}),events:e.metrics.registerMetricGroup("libp2p_tcp_listener_events_total",{label:"address",help:"Total count of TCP listener events by type"})},this.metrics?.status.update({[this.addr]:A.ACTIVE})}this.safeDispatchEvent("listening")}).on("error",t=>{this.metrics?.errors.increment({[`${this.addr} listen_error`]:!0}),this.safeDispatchEvent("error",{detail:t})}).on("close",()=>{this.metrics?.status.update({[this.addr]:this.status.code}),this.status.code!==A.PAUSED&&this.safeDispatchEvent("close")}).on("drop",()=>{this.metrics?.events.increment({[`${this.addr} drop`]:!0})})}onSocket(e){if(this.metrics?.events.increment({[`${this.addr} connection`]:!0}),this.status.code!==A.ACTIVE)throw e.destroy(),new we("Server is not listening yet");let t;try{t=Oe(e,{listeningAddr:this.status.listeningAddr,socketInactivityTimeout:this.context.socketInactivityTimeout,socketCloseTimeout:this.context.socketCloseTimeout,metrics:this.metrics?.events,metricPrefix:`${this.addr} `,logger:this.context.logger,direction:"inbound"})}catch(n){this.log.error("inbound connection failed",n),this.metrics?.errors.increment({[`${this.addr} inbound_to_connection`]:!0}),e.destroy();return}this.log("new inbound connection %s",t.remoteAddr),this.sockets.add(e),this.context.upgrader.upgradeInbound(t,{signal:this.shutdownController.signal}).then(()=>{this.log("inbound connection upgraded %s",t.remoteAddr),e.once("close",()=>{this.sockets.delete(e),this.context.closeServerOnMaxConnections!=null&&this.sockets.size<this.context.closeServerOnMaxConnections.listenBelow&&this.resume().catch(n=>{this.log.error("error attempting to listen server once connection count under limit",n),this.context.closeServerOnMaxConnections?.onListenError?.(n)})}),this.context.closeServerOnMaxConnections!=null&&this.sockets.size>=this.context.closeServerOnMaxConnections.closeAbove&&this.pause()}).catch(async n=>{this.log.error("inbound connection upgrade failed",n),this.metrics?.errors.increment({[`${this.addr} inbound_upgrade`]:!0}),this.sockets.delete(e),t.abort(n)})}getAddrs(){if(this.status.code===A.INACTIVE)return[];let e=[],t=this.server.address(),{listeningAddr:n,peerId:o}=this.status;if(t==null)return[];if(typeof t=="string")e=[n];else try{n.toString().startsWith("/ip4")?e=e.concat(Ot("ip4",t.address,t.port)):t.family==="IPv6"&&(e=e.concat(Ot("ip6",t.address,t.port)))}catch(s){this.log.error("could not turn %s:%s into multiaddr",t.address,t.port,s)}return e.map(s=>o!=null?s.encapsulate(`/p2p/${o}`):s)}updateAnnounceAddrs(){}async listen(e){if(this.status.code===A.ACTIVE||this.status.code===A.PAUSED)throw new be("server is already listening");let t=e.getPeerId(),n=t==null?e.decapsulateCode(421):e,{backlog:o}=this.context;try{this.status={code:A.ACTIVE,listeningAddr:n,peerId:t,netConfig:ae(n,{backlog:o})},await this.resume()}catch(s){throw this.status={code:A.INACTIVE},s}}async close(){let e=[];this.server.listening&&e.push(Mt(this.server,"close")),this.pause(!0),this.shutdownController.abort(),this.sockets.forEach(t=>{t.readable&&(e.push(Mt(t,"close")),t.destroy())}),await Promise.all(e)}async resume(){if(this.server.listening||this.status.code===A.INACTIVE)return;let e=this.status.netConfig;await new Promise((t,n)=>{this.server.once("error",n),this.server.listen(e,t)}),this.status={...this.status,code:A.ACTIVE},this.log("listening on %s",this.server.address())}pause(e=!1){if(!this.server.listening&&this.status.code===A.PAUSED&&e){this.status={code:A.INACTIVE};return}!this.server.listening||this.status.code!==A.ACTIVE||(this.log("closing server on %s",this.server.address()),this.status=e?{code:A.INACTIVE}:{...this.status,code:A.PAUSED},this.server.close())}};var ze=class{opts;metrics;components;log;constructor(e,t={}){this.log=e.logger.forComponent("libp2p:tcp"),this.opts=t,this.components=e,e.metrics!=null&&(this.metrics={events:e.metrics.registerCounterGroup("libp2p_tcp_dialer_events_total",{label:"event",help:"Total count of TCP dialer events by type"}),errors:e.metrics.registerCounterGroup("libp2p_tcp_dialer_errors_total",{label:"event",help:"Total count of TCP dialer events by type"})})}[Bt]=!0;[Symbol.toStringTag]="@libp2p/tcp";[Rt]=["@libp2p/transport"];async dial(e,t){t.keepAlive=t.keepAlive??!0,t.noDelay=t.noDelay??!0;let n=await this._connect(e,t),o;try{o=Oe(n,{remoteAddr:e,socketInactivityTimeout:this.opts.outboundSocketInactivityTimeout,socketCloseTimeout:this.opts.socketCloseTimeout,metrics:this.metrics?.events,logger:this.components.logger,direction:"outbound"})}catch(s){throw this.metrics?.errors.increment({outbound_to_connection:!0}),n.destroy(s),s}try{return this.log("new outbound connection %s",o.remoteAddr),await t.upgrader.upgradeOutbound(o,t)}catch(s){throw this.metrics?.errors.increment({outbound_upgrade:!0}),this.log.error("error upgrading outbound connection",s),o.abort(s),s}}async _connect(e,t){t.signal.throwIfAborted(),t.onProgress?.(new $e("tcp:open-connection"));let n;return new Promise((o,s)=>{let i=Date.now(),a=ae(e,{...this.opts.dialOpts??{},...t});this.log("dialing %a",e),n=_r.default.connect(a);let d=l=>{this.log.error("dial to %a errored - %e",e,l);let f=a.path??`${a.host??""}:${a.port}`;l.message=`connection error ${f}: ${l.message}`,this.metrics?.events.increment({error:!0}),b(l)},m=()=>{this.log("connection timeout %a",e),this.metrics?.events.increment({timeout:!0});let l=new Z(`Connection timeout after ${Date.now()-i}ms`);n.emit("error",l)},p=()=>{this.log("connection opened %a",e),this.metrics?.events.increment({connect:!0}),b()},h=()=>{this.log("connection aborted %a",e),this.metrics?.events.increment({abort:!0}),b(new ge)},b=l=>{if(n.removeListener("error",d),n.removeListener("timeout",m),n.removeListener("connect",p),t.signal!=null&&t.signal.removeEventListener("abort",h),l!=null){s(l);return}o(n)};n.on("error",d),n.on("timeout",m),n.on("connect",p),t.signal.addEventListener("abort",h)}).catch(o=>{throw n?.destroy(),o})}createListener(e){return new Ve({...this.opts.listenOpts??{},...e,maxConnections:this.opts.maxConnections,backlog:this.opts.backlog,closeServerOnMaxConnections:this.opts.closeServerOnMaxConnections,socketInactivityTimeout:this.opts.inboundSocketInactivityTimeout,socketCloseTimeout:this.opts.socketCloseTimeout,metrics:this.components.metrics,logger:this.components.logger})}listenFilter(e){return e=Array.isArray(e)?e:[e],e.filter(t=>t.protoCodes().includes(290)?!1:t.protoCodes().includes(400)?!0:H.matches(t.decapsulateCode(421)))}dialFilter(e){return this.listenFilter(e)}};function Jo(r={}){return e=>new ze(e,r)}return Hr(Qo);})(); | ||
return Libp2PTcp})); |
@@ -31,3 +31,2 @@ /** | ||
import type { ComponentLogger, CounterGroup, Metrics, CreateListenerOptions, DialTransportOptions, Transport, OutboundConnectionUpgradeEvents } from '@libp2p/interface'; | ||
import type { AbortOptions } from '@multiformats/multiaddr'; | ||
import type { ProgressEvent } from 'progress-events'; | ||
@@ -75,3 +74,3 @@ export type { CloseServerOnMaxConnectionsOpts }; | ||
*/ | ||
export interface TCPSocketOptions extends AbortOptions { | ||
export interface TCPSocketOptions { | ||
/** | ||
@@ -78,0 +77,0 @@ * @see https://nodejs.org/api/net.html#socketconnectoptions-connectlistener |
@@ -20,3 +20,3 @@ import { InvalidParametersError, TimeoutError } from '@libp2p/interface'; | ||
const closeTimeout = options.socketCloseTimeout ?? CLOSE_TIMEOUT; | ||
let timedout = false; | ||
let timedOut = false; | ||
let errored = false; | ||
@@ -33,3 +33,3 @@ // Check if we are connected on a unix path | ||
errored = true; | ||
if (!timedout) { | ||
if (!timedOut) { | ||
log.error('%s socket error - %e', direction, err); | ||
@@ -60,3 +60,3 @@ metrics?.increment({ [`${metricPrefix}error`]: true }); | ||
socket.once('timeout', () => { | ||
timedout = true; | ||
timedOut = true; | ||
log('%s %s socket read timeout', direction, lOptsStr); | ||
@@ -71,3 +71,3 @@ metrics?.increment({ [`${metricPrefix}timeout`]: true }); | ||
// record metric for clean exit | ||
if (!timedout && !errored) { | ||
if (!timedOut && !errored) { | ||
log('%s %s socket close', direction, lOptsStr); | ||
@@ -74,0 +74,0 @@ metrics?.increment({ [`${metricPrefix}close`]: true }); |
@@ -97,3 +97,3 @@ /** | ||
async _connect(ma, options) { | ||
options.signal?.throwIfAborted(); | ||
options.signal.throwIfAborted(); | ||
options.onProgress?.(new CustomProgressEvent('tcp:open-connection')); | ||
@@ -149,5 +149,3 @@ let rawSocket; | ||
rawSocket.on('connect', onConnect); | ||
if (options.signal != null) { | ||
options.signal.addEventListener('abort', onAbort); | ||
} | ||
options.signal.addEventListener('abort', onAbort); | ||
}) | ||
@@ -154,0 +152,0 @@ .catch(err => { |
{ | ||
"name": "@libp2p/tcp", | ||
"version": "10.1.2", | ||
"version": "10.1.3-e1f868f03", | ||
"description": "A TCP transport for libp2p", | ||
@@ -63,4 +63,4 @@ "license": "Apache-2.0 OR MIT", | ||
"dependencies": { | ||
"@libp2p/interface": "^2.6.0", | ||
"@libp2p/utils": "^6.5.4", | ||
"@libp2p/interface": "2.6.1-e1f868f03", | ||
"@libp2p/utils": "6.5.5-e1f868f03", | ||
"@multiformats/mafmt": "^12.1.6", | ||
@@ -76,4 +76,4 @@ "@multiformats/multiaddr": "^12.3.3", | ||
"devDependencies": { | ||
"@libp2p/logger": "^5.1.9", | ||
"aegir": "^45.0.5", | ||
"@libp2p/logger": "5.1.10-e1f868f03", | ||
"aegir": "^45.1.1", | ||
"p-wait-for": "^5.0.2", | ||
@@ -80,0 +80,0 @@ "sinon": "^19.0.2", |
@@ -33,3 +33,2 @@ /** | ||
import type { ComponentLogger, CounterGroup, Metrics, CreateListenerOptions, DialTransportOptions, Transport, OutboundConnectionUpgradeEvents } from '@libp2p/interface' | ||
import type { AbortOptions } from '@multiformats/multiaddr' | ||
import type { ProgressEvent } from 'progress-events' | ||
@@ -87,3 +86,3 @@ | ||
*/ | ||
export interface TCPSocketOptions extends AbortOptions { | ||
export interface TCPSocketOptions { | ||
/** | ||
@@ -90,0 +89,0 @@ * @see https://nodejs.org/api/net.html#socketconnectoptions-connectlistener |
@@ -37,3 +37,3 @@ import { InvalidParametersError, TimeoutError } from '@libp2p/interface' | ||
const closeTimeout = options.socketCloseTimeout ?? CLOSE_TIMEOUT | ||
let timedout = false | ||
let timedOut = false | ||
let errored = false | ||
@@ -54,3 +54,3 @@ | ||
if (!timedout) { | ||
if (!timedOut) { | ||
log.error('%s socket error - %e', direction, err) | ||
@@ -87,3 +87,3 @@ metrics?.increment({ [`${metricPrefix}error`]: true }) | ||
socket.once('timeout', () => { | ||
timedout = true | ||
timedOut = true | ||
log('%s %s socket read timeout', direction, lOptsStr) | ||
@@ -100,3 +100,3 @@ metrics?.increment({ [`${metricPrefix}timeout`]: true }) | ||
// record metric for clean exit | ||
if (!timedout && !errored) { | ||
if (!timedOut && !errored) { | ||
log('%s %s socket close', direction, lOptsStr) | ||
@@ -103,0 +103,0 @@ metrics?.increment({ [`${metricPrefix}close`]: true }) |
@@ -112,3 +112,3 @@ /** | ||
async _connect (ma: Multiaddr, options: TCPDialOptions): Promise<Socket> { | ||
options.signal?.throwIfAborted() | ||
options.signal.throwIfAborted() | ||
options.onProgress?.(new CustomProgressEvent('tcp:open-connection')) | ||
@@ -177,5 +177,3 @@ | ||
if (options.signal != null) { | ||
options.signal.addEventListener('abort', onAbort) | ||
} | ||
options.signal.addEventListener('abort', onAbort) | ||
}) | ||
@@ -182,0 +180,0 @@ .catch(err => { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
163549
38
2142
2
+ Added@libp2p/crypto@5.0.13-e1f868f03(transitive)
+ Added@libp2p/interface@2.6.1-e1f868f03(transitive)
+ Added@libp2p/logger@5.1.10-e1f868f03(transitive)
+ Added@libp2p/utils@6.5.5-e1f868f03(transitive)
- Removed@libp2p/crypto@5.0.13(transitive)
- Removed@libp2p/interface@2.6.1(transitive)
- Removed@libp2p/logger@5.1.10(transitive)
- Removed@libp2p/utils@6.5.5(transitive)