Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@libp2p/tcp

Package Overview
Dependencies
Maintainers
0
Versions
585
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@libp2p/tcp - npm Package Compare versions

Comparing version 10.0.10 to 10.0.11-432955390

2

dist/index.min.js
(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})},Ot=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of qr(e))!Gr.call(r,o)&&o!==t&&xe(r,o,{get:()=>e[o],enumerable:!(n=jr(e,o))||n.enumerable});return r};var le=(r,e,t)=>(t=r!=null?Rr(Wr(r)):{},Ot(e||!r||!r.__esModule?xe(t,"default",{value:r,enumerable:!0}):t,r)),Hr=r=>Ot(xe({},"__esModule",{value:!0}),r);var Qo={};D(Qo,{tcp:()=>Jo});var _r=le(F("net"),1);var zt=Symbol.for("@libp2p/transport");var Vt;(function(r){r[r.FATAL_ALL=0]="FATAL_ALL",r[r.NO_FATAL=1]="NO_FATAL"})(Vt||(Vt={}));var ge=class extends Error{static name="AbortError";constructor(e="The operation was aborted"){super(e),this.name="AbortError"}};var V=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}};var Z=class extends Error{static name="TimeoutError";constructor(e="Timed out"){super(e),this.name="TimeoutError"}},we=class extends Error{static name="NotStartedError";constructor(e="Not started"){super(e),this.name="NotStartedError"}},be=class extends Error{static name="AlreadyStartedError";constructor(e="Already started"){super(e),this.name="AlreadyStartedError"}};var Bt=F("events"),ve=(r,...e)=>{try{(0,Bt.setMaxListeners)(r,...e)}catch{}};var ye=class extends EventTarget{#e=new Map;constructor(){super(),ve(1/0,this)}listenerCount(e){let t=this.#e.get(e);return t==null?0:t.length}addEventListener(e,t,n){super.addEventListener(e,t,n);let o=this.#e.get(e);o==null&&(o=[],this.#e.set(e,o)),o.push({callback:t,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(e,t,n){super.removeEventListener(e.toString(),t??null,n);let o=this.#e.get(e);o!=null&&(o=o.filter(({callback:s})=>s!==t),this.#e.set(e,o))}dispatchEvent(e){let t=super.dispatchEvent(e),n=this.#e.get(e.type);return n==null||(n=n.filter(({once:o})=>!o),this.#e.set(e.type,n)),t}safeDispatchEvent(e,t={}){return this.dispatchEvent(new CustomEvent(e,t))}};var _t=Symbol.for("@libp2p/service-capabilities"),rs=Symbol.for("@libp2p/service-dependencies");var _e={};D(_e,{base58btc:()=>S,base58flickr:()=>Zr});var Ts=new Uint8Array(0);function Rt(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}function M(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")}function jt(r){return new TextEncoder().encode(r)}function qt(r){return new TextDecoder().decode(r)}function Jr(r,e){if(r.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),n=0;n<t.length;n++)t[n]=255;for(var o=0;o<r.length;o++){var s=r.charAt(o),i=s.charCodeAt(0);if(t[i]!==255)throw new TypeError(s+" is ambiguous");t[i]=o}var a=r.length,d=r.charAt(0),h=Math.log(a)/Math.log(256),p=Math.log(256)/Math.log(a);function x(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,g=0,b=f.length;g!==b&&f[g]===0;)g++,I++;for(var L=(b-g)*p+1>>>0,k=new Uint8Array(L);g!==b;){for(var O=f[g],j=0,U=L-1;(O!==0||j<T)&&U!==-1;U--,j++)O+=256*k[U]>>>0,k[U]=O%a>>>0,O=O/a>>>0;if(O!==0)throw new Error("Non-zero carry");T=j,g++}for(var B=L-T;B!==L&&k[B]===0;)B++;for(var me=d.repeat(I);B<L;++B)me+=r.charAt(k[B]);return me}function m(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,g=0;f[I]===d;)T++,I++;for(var b=(f.length-I)*h+1>>>0,L=new Uint8Array(b);f[I];){var k=t[f.charCodeAt(I)];if(k===255)return;for(var O=0,j=b-1;(k!==0||O<g)&&j!==-1;j--,O++)k+=a*L[j]>>>0,L[j]=k%256>>>0,k=k/256>>>0;if(k!==0)throw new Error("Non-zero carry");g=O,I++}if(f[I]!==" "){for(var U=b-g;U!==b&&L[U]===0;)U++;for(var B=new Uint8Array(T+(b-U)),me=T;U!==b;)B[me++]=L[U++];return B}}}function u(f){var I=m(f);if(I)return I;throw new Error(`Non-${e} character`)}return{encode:x,decodeUnsafe:m,decode:u}}var Qr=Jr,Xr=Qr,Gt=Xr;var Oe=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")}},Ve=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,t,n){this.name=e,this.prefix=t;let o=t.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return Ht(this,e)}},ze=class{decoders;constructor(e){this.decoders=e}or(e){return Ht(this,e)}decode(e){let t=e[0],n=this.decoders[t];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Ht(r,e){return new ze({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var Be=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 Oe(e,t,n),this.decoder=new Ve(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function ee({name:r,prefix:e,encode:t,decode:n}){return new Be(r,e,t,n)}function q({name:r,prefix:e,alphabet:t}){let{encode:n,decode:o}=Gt(t,r);return ee({prefix:e,name:r,encode:n,decode:s=>M(o(s))})}function Kr(r,e,t,n){let o={};for(let p=0;p<e.length;++p)o[e[p]]=p;let s=r.length;for(;r[s-1]==="=";)--s;let i=new Uint8Array(s*t/8|0),a=0,d=0,h=0;for(let p=0;p<s;++p){let x=o[r[p]];if(x===void 0)throw new SyntaxError(`Non-${n} character`);d=d<<t|x,a+=t,a>=8&&(a-=8,i[h++]=255&d>>a)}if(a>=t||255&d<<8-a)throw new SyntaxError("Unexpected end of data");return i}function Yr(r,e,t){let n=e[e.length-1]==="=",o=(1<<t)-1,s="",i=0,a=0;for(let d=0;d<r.length;++d)for(a=a<<8|r[d],i+=8;i>t;)i-=t,s+=e[o&a>>i];if(i!==0&&(s+=e[o&a<<t-i]),n)for(;s.length*t&7;)s+="=";return s}function y({name:r,prefix:e,bitsPerChar:t,alphabet:n}){return ee({prefix:e,name:r,encode(o){return Yr(o,n,t)},decode(o){return Kr(o,n,t,r)}})}var S=q({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Zr=q({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Re={};D(Re,{base32:()=>_,base32hex:()=>nn,base32hexpad:()=>sn,base32hexpadupper:()=>cn,base32hexupper:()=>on,base32pad:()=>tn,base32padupper:()=>rn,base32upper:()=>en,base32z:()=>an});var _=y({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),en=y({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),tn=y({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),rn=y({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),nn=y({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),on=y({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),sn=y({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),cn=y({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),an=y({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var je={};D(je,{base36:()=>ue,base36upper:()=>ln});var ue=q({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),ln=q({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var un=Xt,Jt=128,dn=127,pn=~dn,fn=Math.pow(2,31);function Xt(r,e,t){e=e||[],t=t||0;for(var n=t;r>=fn;)e[t++]=r&255|Jt,r/=128;for(;r&pn;)e[t++]=r&255|Jt,r>>>=7;return e[t]=r|0,Xt.bytes=t-n+1,e}var hn=qe,mn=128,Qt=127;function qe(r,n){var t=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw qe.bytes=0,new RangeError("Could not decode varint");i=r[s++],t+=o<28?(i&Qt)<<o:(i&Qt)*Math.pow(2,o),o+=7}while(i>=mn);return qe.bytes=s-n,t}var xn=Math.pow(2,7),gn=Math.pow(2,14),wn=Math.pow(2,21),bn=Math.pow(2,28),vn=Math.pow(2,35),yn=Math.pow(2,42),En=Math.pow(2,49),In=Math.pow(2,56),An=Math.pow(2,63),Cn=function(r){return r<xn?1:r<gn?2:r<wn?3:r<bn?4:r<vn?5:r<yn?6:r<En?7:r<In?8:r<An?9:10},Tn={encode:un,decode:hn,encodingLength:Cn},Sn=Tn,de=Sn;function pe(r,e=0){return[de.decode(r,e),de.decode.bytes]}function te(r,e,t=0){return de.encode(r,e,t),e}function re(r){return de.encodingLength(r)}function J(r,e){let t=e.byteLength,n=re(r),o=n+re(t),s=new Uint8Array(o+t);return te(r,s,0),te(t,s,n),s.set(e,o),new ne(r,t,e,s)}function Ie(r){let e=M(r),[t,n]=pe(e),[o,s]=pe(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new ne(t,o,i,e)}function Kt(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&Rt(r.bytes,t.bytes)}}var ne=class{code;size;digest;bytes;constructor(e,t,n,o){this.code=e,this.size=t,this.digest=n,this.bytes=o}};function Yt(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return Ln(t,We(r),e??S.encoder);default:return Dn(t,We(r),e??_.encoder)}}var Zt=new WeakMap;function We(r){let e=Zt.get(r);if(e==null){let t=new Map;return Zt.set(r,t),t}return e}var W=class r{code;version;multihash;bytes;"/";constructor(e,t,n,o){this.code=t,this.version=e,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:t}=this;if(e!==fe)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==kn)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(t)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:e,digest:t}=this.multihash,n=J(e,t);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(e){return r.equals(this,e)}static equals(e,t){let n=t;return n!=null&&e.code===n.code&&e.version===n.version&&Kt(e.multihash,n.multihash)}toString(e){return Yt(this,e)}toJSON(){return{"/":Yt(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let t=e;if(t instanceof r)return t;if(t["/"]!=null&&t["/"]===t.bytes||t.asCID===t){let{version:n,code:o,multihash:s,bytes:i}=t;return new r(n,o,s,i??er(n,o,s.bytes))}else if(t[Mn]===!0){let{version:n,multihash:o,code:s}=t,i=Ie(o);return r.create(n,s,i)}else return null}static create(e,t,n){if(typeof t!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(t!==fe)throw new Error(`Version 0 CID must use dag-pb (code: ${fe}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let o=er(e,t,n.bytes);return new r(e,t,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,fe,e)}static createV1(e,t){return r.create(1,e,t)}static decode(e){let[t,n]=r.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return t}static decodeFirst(e){let t=r.inspectBytes(e),n=t.size-t.multihashSize,o=M(e.subarray(n,n+t.multihashSize));if(o.byteLength!==t.multihashSize)throw new Error("Incorrect length");let s=o.subarray(t.multihashSize-t.digestSize),i=new ne(t.multihashCode,t.digestSize,s,o);return[t.version===0?r.createV0(i):r.createV1(t.codec,i),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[x,m]=pe(e.subarray(t));return t+=m,x},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(),h=t+d,p=h-i;return{version:o,codec:s,multihashCode:a,digestSize:d,multihashSize:p,size:h}}static parse(e,t){let[n,o]=Pn(e,t),s=r.decode(o);if(s.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return We(s).set(n,e),s}};function Pn(r,e){switch(r[0]){case"Q":{let t=e??S;return[S.prefix,t.decode(`${S.prefix}${r}`)]}case S.prefix:{let t=e??S;return[S.prefix,t.decode(r)]}case _.prefix:{let t=e??_;return[_.prefix,t.decode(r)]}case ue.prefix:{let t=e??ue;return[ue.prefix,t.decode(r)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],e.decode(r)]}}}function Ln(r,e,t){let{prefix:n}=t;if(n!==S.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let o=e.get(n);if(o==null){let s=t.encode(r).slice(1);return e.set(n,s),s}else return o}function Dn(r,e,t){let{prefix:n}=t,o=e.get(n);if(o==null){let s=t.encode(r);return e.set(n,s),s}else return o}var fe=112,kn=18;function er(r,e,t){let n=re(r),o=n+re(e),s=new Uint8Array(o+t.byteLength);return te(r,s,0),te(e,s,n),s.set(t,o),s}var Mn=Symbol.for("@ipld/js-cid/CID");function tr(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}var lr=F("node:buffer");var Ge={};D(Ge,{base10:()=>Nn});var Nn=q({prefix:"9",name:"base10",alphabet:"0123456789"});var He={};D(He,{base16:()=>Un,base16upper:()=>Fn});var Un=y({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Fn=y({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Je={};D(Je,{base2:()=>$n});var $n=y({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Qe={};D(Qe,{base256emoji:()=>_n});var rr=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),On=rr.reduce((r,e,t)=>(r[t]=e,r),[]),Vn=rr.reduce((r,e,t)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return r[n]=t,r},[]);function zn(r){return r.reduce((e,t)=>(e+=On[t],e),"")}function Bn(r){let e=[];for(let t of r){let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);let o=Vn[n];if(o==null)throw new Error(`Non-base256emoji character: ${t}`);e.push(o)}return new Uint8Array(e)}var _n=ee({prefix:"\u{1F680}",name:"base256emoji",encode:zn,decode:Bn});var Xe={};D(Xe,{base64:()=>Rn,base64pad:()=>jn,base64url:()=>qn,base64urlpad:()=>Wn});var Rn=y({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),jn=y({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),qn=y({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Wn=y({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Ke={};D(Ke,{base8:()=>Gn});var Gn=y({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Ye={};D(Ye,{identity:()=>Hn});var Hn=ee({prefix:"\0",name:"identity",encode:r=>qt(r),decode:r=>jt(r)});var Ys=new TextEncoder,Zs=new TextDecoder;var Ze={};D(Ze,{identity:()=>Yn});var nr=0,Xn="identity",or=M;function Kn(r){return J(nr,or(r))}var Yn={code:nr,name:Xn,encode:or,digest:Kn};var nt={};D(nt,{sha256:()=>Zn,sha512:()=>eo});var rt=le(F("crypto"),1);function tt({name:r,code:e,encode:t}){return new et(r,e,t)}var et=class{name;code;encode;constructor(e,t,n){this.name=e,this.code=t,this.encode=n}digest(e){if(e instanceof Uint8Array){let t=this.encode(e);return t instanceof Uint8Array?J(this.code,t):t.then(n=>J(this.code,n))}else throw Error("Unknown type, must be binary type")}};var Zn=tt({name:"sha2-256",code:18,encode:r=>M(rt.default.createHash("sha256").update(r).digest())}),eo=tt({name:"sha2-512",code:19,encode:r=>M(rt.default.createHash("sha512").update(r).digest())});var he={...Ye,...Je,...Ke,...Ge,...He,...Re,...je,..._e,...Xe,...Qe},fi={...nt,...Ze};var ir=F("node:buffer");function se(r){return new Uint8Array(r.buffer,r.byteOffset,r.byteLength)}function Ae(r=0){return se(ir.Buffer.allocUnsafe(r))}function ar(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var cr=ar("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),ot=ar("ascii","a",r=>{let e="a";for(let t=0;t<r.length;t++)e+=String.fromCharCode(r[t]);return e},r=>{r=r.substring(1);let e=Ae(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),to={utf8:cr,"utf-8":cr,hex:he.base16,latin1:ot,ascii:ot,binary:ot,...he},Ce=to;function P(r,e="utf8"){let t=Ce[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return e==="utf8"||e==="utf-8"?lr.Buffer.from(r.buffer,r.byteOffset,r.byteLength).toString("utf8"):t.encoder.encode(r).substring(1)}var ro=Math.pow(2,7),no=Math.pow(2,14),oo=Math.pow(2,21),st=Math.pow(2,28),it=Math.pow(2,35),ct=Math.pow(2,42),at=Math.pow(2,49),w=128,C=127;function z(r){if(r<ro)return 1;if(r<no)return 2;if(r<oo)return 3;if(r<st)return 4;if(r<it)return 5;if(r<ct)return 6;if(r<at)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function so(r,e,t=0){switch(z(r)){case 8:e[t++]=r&255|w,r/=128;case 7:e[t++]=r&255|w,r/=128;case 6:e[t++]=r&255|w,r/=128;case 5:e[t++]=r&255|w,r/=128;case 4:e[t++]=r&255|w,r>>>=7;case 3:e[t++]=r&255|w,r>>>=7;case 2:e[t++]=r&255|w,r>>>=7;case 1:{e[t++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return e}function io(r,e,t=0){switch(z(r)){case 8:e.set(t++,r&255|w),r/=128;case 7:e.set(t++,r&255|w),r/=128;case 6:e.set(t++,r&255|w),r/=128;case 5:e.set(t++,r&255|w),r/=128;case 4:e.set(t++,r&255|w),r>>>=7;case 3:e.set(t++,r&255|w),r>>>=7;case 2:e.set(t++,r&255|w),r>>>=7;case 1:{e.set(t++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return e}function co(r,e){let t=r[e],n=0;if(n+=t&C,t<w||(t=r[e+1],n+=(t&C)<<7,t<w)||(t=r[e+2],n+=(t&C)<<14,t<w)||(t=r[e+3],n+=(t&C)<<21,t<w)||(t=r[e+4],n+=(t&C)*st,t<w)||(t=r[e+5],n+=(t&C)*it,t<w)||(t=r[e+6],n+=(t&C)*ct,t<w)||(t=r[e+7],n+=(t&C)*at,t<w))return n;throw new RangeError("Could not decode varint")}function ao(r,e){let t=r.get(e),n=0;if(n+=t&C,t<w||(t=r.get(e+1),n+=(t&C)<<7,t<w)||(t=r.get(e+2),n+=(t&C)<<14,t<w)||(t=r.get(e+3),n+=(t&C)<<21,t<w)||(t=r.get(e+4),n+=(t&C)*st,t<w)||(t=r.get(e+5),n+=(t&C)*it,t<w)||(t=r.get(e+6),n+=(t&C)*ct,t<w)||(t=r.get(e+7),n+=(t&C)*at,t<w))return n;throw new RangeError("Could not decode varint")}function ie(r,e,t=0){return e==null&&(e=Ae(z(r))),e instanceof Uint8Array?so(r,e,t):io(r,e,t)}function Q(r,e=0){return r instanceof Uint8Array?co(r,e):ao(r,e)}var dr=F("node:buffer");function R(r,e){return se(dr.Buffer.concat(r,e))}var Te=class{index=0;input="";new(e){return this.index=0,this.input=e,this}readAtomically(e){let t=this.index,n=e();return n===void 0&&(this.index=t),n}parseWith(e){let t=e();if(this.index===this.input.length)return t}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(e){return this.readAtomically(()=>{let t=this.readChar();if(t===e)return t})}readSeparator(e,t,n){return this.readAtomically(()=>{if(!(t>0&&this.readGivenChar(e)===void 0))return n()})}readNumber(e,t,n,o){return this.readAtomically(()=>{let s=0,i=0,a=this.peekChar();if(a===void 0)return;let d=a==="0",h=2**(8*o)-1;for(;;){let p=this.readAtomically(()=>{let x=this.readChar();if(x===void 0)return;let m=Number.parseInt(x,e);if(!Number.isNaN(m))return m});if(p===void 0)break;if(s*=e,s+=p,s>h||(i+=1,t!==void 0&&i>t))return}if(i!==0)return!n&&d&&i>1?void 0:s})}readIPv4Addr(){return this.readAtomically(()=>{let e=new Uint8Array(4);for(let t=0;t<e.length;t++){let n=this.readSeparator(".",t,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;e[t]=n}return e})}readIPv6Addr(){let e=t=>{for(let n=0;n<t.length/2;n++){let o=n*2;if(n<t.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return t[o]=i[0],t[o+1]=i[1],t[o+2]=i[2],t[o+3]=i[3],[o+4,!0]}let s=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(s===void 0)return[o,!1];t[o]=s>>8,t[o+1]=s&255}return[t.length,!1]};return this.readAtomically(()=>{let t=new Uint8Array(16),[n,o]=e(t);if(n===16)return t;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let s=new Uint8Array(14),i=16-(n+2),[a]=e(s.subarray(0,i));return t.set(s.subarray(0,a),16-a),t})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var Pi=new Te;var $i=parseInt("0xFFFF",16),Oi=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);var hr=F("node:buffer");function lt(r,e="utf8"){let t=Ce[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return e==="utf8"||e==="utf-8"?se(hr.Buffer.from(r,"utf-8")):t.decoder.decode(`${t.prefix}${r}`)}var N=F("node:net");function Se(r){return!!(0,N.isIP)(r)}var mr=N.isIPv4,mo=N.isIPv6,ut=function(r){let e=0;if(r=r.toString().trim(),mr(r)){let t=new Uint8Array(e+4);return r.split(/\./g).forEach(n=>{t[e++]=parseInt(n,10)&255}),t}if(mo(r)){let t=r.split(":",8),n;for(n=0;n<t.length;n++){let s=mr(t[n]),i;s&&(i=ut(t[n]),t[n]=P(i.slice(0,2),"base16")),i!=null&&++n<8&&t.splice(n,0,P(i.slice(2,4),"base16"))}if(t[0]==="")for(;t.length<8;)t.unshift("0");else if(t[t.length-1]==="")for(;t.length<8;)t.push("0");else if(t.length<8){for(n=0;n<t.length&&t[n]!=="";n++);let s=[n,1];for(n=9-t.length;n>0;n--)s.push("0");t.splice.apply(t,s)}let o=new Uint8Array(e+16);for(n=0;n<t.length;n++){let s=parseInt(t[n],16);o[e++]=s>>8&255,o[e++]=s&255}return o}throw new Error("invalid ip address")},xr=function(r,e=0,t){e=~~e,t=t??r.length-e;let n=new DataView(r.buffer);if(t===4){let o=[];for(let s=0;s<t;s++)o.push(r[e+s]);return o.join(".")}if(t===16){let o=[];for(let s=0;s<t;s+=2)o.push(n.getUint16(e+s).toString(16));return o.join(":").replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}return""};var ce={},dt={},go=[[4,32,"ip4"],[6,16,"tcp"],[33,16,"dccp"],[41,128,"ip6"],[42,-1,"ip6zone"],[43,8,"ipcidr"],[53,-1,"dns",!0],[54,-1,"dns4",!0],[55,-1,"dns6",!0],[56,-1,"dnsaddr",!0],[132,16,"sctp"],[273,16,"udp"],[275,0,"p2p-webrtc-star"],[276,0,"p2p-webrtc-direct"],[277,0,"p2p-stardust"],[280,0,"webrtc-direct"],[281,0,"webrtc"],[290,0,"p2p-circuit"],[301,0,"udt"],[302,0,"utp"],[400,-1,"unix",!1,!0],[421,-1,"ipfs"],[421,-1,"p2p"],[443,0,"https"],[444,96,"onion"],[445,296,"onion3"],[446,-1,"garlic64"],[448,0,"tls"],[449,-1,"sni"],[460,0,"quic"],[461,0,"quic-v1"],[465,0,"webtransport"],[466,-1,"certhash"],[477,0,"ws"],[478,0,"wss"],[479,0,"p2p-websocket-star"],[480,0,"http"],[481,-1,"http-path"],[777,-1,"memory"]];go.forEach(r=>{let e=wo(...r);dt[e.code]=e,ce[e.name]=e});function wo(r,e,t,n,o){return{code:r,size:e,name:t,resolvable:!!n,path:!!o}}function v(r){if(typeof r=="number"){if(dt[r]!=null)return dt[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(ce[r]!=null)return ce[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var Ac=v("ip4"),Cc=v("ip6"),Tc=v("ipcidr");function mt(r,e){switch(v(r).code){case 4:case 41:return vo(e);case 42:return ht(e);case 6:case 273:case 33:case 132:return br(e).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return ht(e);case 421:return Ao(e);case 444:return wr(e);case 445:return wr(e);case 466:return Io(e);case 481:return globalThis.encodeURIComponent(ht(e));default:return P(e,"base16")}}function xt(r,e){switch(v(r).code){case 4:return gr(e);case 41:return gr(e);case 42:return ft(e);case 6:case 273:case 33:case 132:return gt(parseInt(e,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return ft(e);case 421:return yo(e);case 444:return Co(e);case 445:return To(e);case 466:return Eo(e);case 481:return ft(globalThis.decodeURIComponent(e));default:return lt(e,"base16")}}var pt=Object.values(he).map(r=>r.decoder),bo=function(){let r=pt[0].or(pt[1]);return pt.slice(2).forEach(e=>r=r.or(e)),r}();function gr(r){if(!Se(r))throw new Error("invalid ip address");return ut(r)}function vo(r){let e=xr(r,0,r.length);if(e==null)throw new Error("ipBuff is required");if(!Se(e))throw new Error("invalid ip address");return e}function gt(r){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,r),new Uint8Array(e)}function br(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function ft(r){let e=lt(r),t=Uint8Array.from(ie(e.length));return R([t,e],t.length+e.length)}function ht(r){let e=Q(r);if(r=r.slice(z(e)),r.length!==e)throw new Error("inconsistent lengths");return P(r)}function yo(r){let e;r[0]==="Q"||r[0]==="1"?e=Ie(S.decode(`z${r}`)).bytes:e=W.parse(r).multihash.bytes;let t=Uint8Array.from(ie(e.length));return R([t,e],t.length+e.length)}function Eo(r){let e=bo.decode(r),t=Uint8Array.from(ie(e.length));return R([t,e],t.length+e.length)}function Io(r){let e=Q(r),t=r.slice(z(e));if(t.length!==e)throw new Error("inconsistent lengths");return"u"+P(t,"base64url")}function Ao(r){let e=Q(r),t=r.slice(z(e));if(t.length!==e)throw new Error("inconsistent lengths");return P(t,"base58btc")}function Co(r){let e=r.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==16)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion address.`);let t=_.decode("b"+e[0]),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=gt(n);return R([t,o],t.length+o.length)}function To(r){let e=r.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==56)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion3 address.`);let t=_.decode(`b${e[0]}`),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=gt(n);return R([t,o],t.length+o.length)}function wr(r){let e=r.slice(0,r.length-2),t=r.slice(r.length-2),n=P(e,"base32"),o=br(t);return`${n}:${o}`}function vr(r){r=wt(r);let e=[],t=[],n=null,o=r.split("/").slice(1);if(o.length===1&&o[0]==="")return{bytes:new Uint8Array,string:"/",tuples:[],stringTuples:[],path:null};for(let s=0;s<o.length;s++){let i=o[s],a=v(i);if(a.size===0){e.push([a.code]),t.push([a.code]);continue}if(s++,s>=o.length)throw Er("invalid address: "+r);if(a.path===!0){n=wt(o.slice(s).join("/")),e.push([a.code,xt(a.code,n)]),t.push([a.code,n]);break}let d=xt(a.code,o[s]);e.push([a.code,d]),t.push([a.code,mt(a.code,d)])}return{string:yr(t),bytes:vt(e),tuples:e,stringTuples:t,path:n}}function bt(r){let e=[],t=[],n=null,o=0;for(;o<r.length;){let s=Q(r,o),i=z(s),a=v(s),d=So(a,r.slice(o+i));if(d===0){e.push([s]),t.push([s]),o+=i;continue}let h=r.slice(o+i,o+i+d);if(o+=d+i,o>r.length)throw Er("Invalid address Uint8Array: "+P(r,"base16"));e.push([s,h]);let p=mt(s,h);if(t.push([s,p]),a.path===!0){n=p;break}}return{bytes:Uint8Array.from(r),string:yr(t),tuples:e,stringTuples:t,path:n}}function yr(r){let e=[];return r.map(t=>{let n=v(t[0]);return e.push(n.name),t.length>1&&t[1]!=null&&e.push(t[1]),null}),wt(e.join("/"))}function vt(r){return R(r.map(e=>{let t=v(e[0]),n=Uint8Array.from(ie(t.code));return e.length>1&&e[1]!=null&&(n=R([n,e[1]])),n}))}function So(r,e){if(r.size>0)return r.size/8;if(r.size===0)return 0;{let t=Q(e instanceof Uint8Array?e:Uint8Array.from(e));return t+z(t)}}function wt(r){return"/"+r.trim().split("/").filter(e=>e).join("/")}function Er(r){return new Error("Error parsing address: "+r)}var Po=Symbol.for("nodejs.util.inspect.custom"),Et=Symbol.for("@multiformats/js-multiaddr/multiaddr"),Lo=[v("dns").code,v("dns4").code,v("dns6").code,v("dnsaddr").code],yt=class extends Error{constructor(e="No available resolver"){super(e),this.name="NoAvailableResolverError"}},Pe=class r{bytes;#e;#t;#r;#n;[Et]=!0;constructor(e){e==null&&(e="");let t;if(e instanceof Uint8Array)t=bt(e);else if(typeof e=="string"){if(e.length>0&&e.charAt(0)!=="/")throw new Error(`multiaddr "${e}" must start with a "/"`);t=vr(e)}else if(Ar(e))t=bt(e.bytes);else throw new Error("addr must be a string, Buffer, or another Multiaddr");this.bytes=t.bytes,this.#e=t.string,this.#t=t.tuples,this.#r=t.stringTuples,this.#n=t.path}toString(){return this.#e}toJSON(){return this.toString()}toOptions(){let e,t,n,o,s="",i=v("tcp"),a=v("udp"),d=v("ip4"),h=v("ip6"),p=v("dns6"),x=v("ip6zone");for(let[u,f]of this.stringTuples())u===x.code&&(s=`%${f??""}`),Lo.includes(u)&&(t=i.name,o=443,n=`${f??""}${s}`,e=u===p.code?6:4),(u===i.code||u===a.code)&&(t=v(u).name,o=parseInt(f??"")),(u===d.code||u===h.code)&&(t=v(u).name,n=`${f??""}${s}`,e=u===h.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}stringTuples(){return this.#r}encapsulate(e){return e=new r(e),new r(this.toString()+e.toString())}decapsulate(e){let t=e.toString(),n=this.toString(),o=n.lastIndexOf(t);if(o<0)throw new Error(`Address ${this.toString()} does not contain subaddress: ${e.toString()}`);return new r(n.slice(0,o))}decapsulateCode(e){let t=this.tuples();for(let n=t.length-1;n>=0;n--)if(t[n][0]===e)return new r(vt(t.slice(0,n)));return this}getPeerId(){try{let e=[];this.stringTuples().forEach(([n,o])=>{n===ce.p2p.code&&e.push([n,o]),n===ce["p2p-circuit"].code&&(e=[])});let t=e.pop();if(t?.[1]!=null){let n=t[1];return n[0]==="Q"||n[0]==="1"?P(S.decode(`z${n}`),"base58btc"):P(W.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){return this.#n}equals(e){return tr(this.bytes,e.bytes)}async resolve(e){let t=this.protos().find(s=>s.resolvable);if(t==null)return[this];let n=Ir.get(t.name);if(n==null)throw new yt(`no available resolver for ${t.name}`);return(await n(this,e)).map(s=>$(s))}nodeAddress(){let e=this.toOptions();if(e.transport!=="tcp"&&e.transport!=="udp")throw new Error(`multiaddr must have a valid format - no protocol with name: "${e.transport}". Must have a valid transport protocol: "{tcp, udp}"`);return{family:e.family,address:e.host,port:e.port}}isThinWaistAddress(e){let t=(e??this).protos();return!(t.length!==2||t[0].code!==4&&t[0].code!==41||t[1].code!==6&&t[1].code!==273)}[Po](){return`Multiaddr(${this.#e})`}};var Ir=new Map;function Ar(r){return!!r?.[Et]}function $(r){return new Pe(r)}var Do=c("dns4"),ko=c("dns6"),Mo=c("dnsaddr"),K=E(c("dns"),Mo,Do,ko),ke=E(c("ip4"),c("ip6")),H=E(l(ke,c("tcp")),l(K,c("tcp"))),Me=l(ke,c("udp")),No=l(Me,c("utp")),Uo=l(Me,c("quic")),Fo=l(Me,c("quic-v1")),It=E(l(H,c("ws")),l(K,c("ws"))),Le=E(l(It,c("p2p")),It),At=E(l(H,c("wss")),l(K,c("wss")),l(H,c("tls"),c("ws")),l(K,c("tls"),c("ws"))),De=E(l(At,c("p2p")),At),Ct=E(l(H,c("http")),l(ke,c("http")),l(K,c("http"))),Tt=E(l(H,c("https")),l(ke,c("https")),l(K,c("https"))),Cr=l(Me,c("webrtc-direct"),c("certhash")),Pr=E(l(Cr,c("p2p")),Cr),Tr=l(Fo,c("webtransport"),c("certhash"),c("certhash")),Lr=E(l(Tr,c("p2p")),Tr),Dr=E(l(Le,c("p2p-webrtc-star"),c("p2p")),l(De,c("p2p-webrtc-star"),c("p2p")),l(Le,c("p2p-webrtc-star")),l(De,c("p2p-webrtc-star"))),Kc=E(l(Le,c("p2p-websocket-star"),c("p2p")),l(De,c("p2p-websocket-star"),c("p2p")),l(Le,c("p2p-websocket-star")),l(De,c("p2p-websocket-star"))),kr=E(l(Ct,c("p2p-webrtc-direct"),c("p2p")),l(Tt,c("p2p-webrtc-direct"),c("p2p")),l(Ct,c("p2p-webrtc-direct")),l(Tt,c("p2p-webrtc-direct"))),Y=E(It,At,Ct,Tt,Dr,kr,H,No,Uo,K,Pr,Lr),Yc=E(l(Y,c("p2p-stardust"),c("p2p")),l(Y,c("p2p-stardust"))),G=E(l(Y,c("p2p")),Dr,kr,Pr,Lr,c("p2p")),Sr=E(l(G,c("p2p-circuit"),G),l(G,c("p2p-circuit")),l(c("p2p-circuit"),G),l(Y,c("p2p-circuit")),l(c("p2p-circuit"),Y),c("p2p-circuit")),Mr=()=>E(l(Sr,Mr),Sr),X=Mr(),Zc=E(l(X,G,X),l(G,X),l(X,G),X,G);var ea=E(l(X,c("webrtc"),c("p2p")),l(X,c("webrtc")),l(Y,c("webrtc"),c("p2p")),l(Y,c("webrtc")),c("webrtc"));function Nr(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 l(...r){function e(t){if(t.length<r.length)return null;let n=t;return r.some(o=>(n=typeof o=="function"?o().partialMatch(t):o.partialMatch(t),Array.isArray(n)&&(t=n),n===null)),n}return{toString:function(){return"{ "+r.join(" ")+" }"},input:r,matches:Nr(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:Nr(e),partialMatch:e}}function c(r){let e=r;function t(o){let s;try{s=$(o)}catch{return!1}let i=s.protoNames();return i.length===1&&i[0]===e}function n(o){return o.length===0?null:o[0]===e?o.slice(1):null}return{toString:function(){return e},matches:t,partialMatch:n}}var Ne=class extends Event{type;detail;constructor(e,t){super(e),this.type=e,this.detail=t}};var Br=le(F("net"),1);var St=class extends Error{constructor(e){super(e),this.name="TimeoutError"}},Pt=class extends Error{constructor(e){super(),this.name="AbortError",this.message=e}},Ur=r=>globalThis.DOMException===void 0?new Pt(r):new DOMException(r),Fr=r=>{let e=r.reason===void 0?Ur("This operation was aborted."):r.reason;return e instanceof Error?e:Ur(e)};function Lt(r,e){let{milliseconds:t,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout}}=e,i,d=new Promise((h,p)=>{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:m}=e;m.aborted&&p(Fr(m));let u=()=>{p(Fr(m))};m.addEventListener("abort",u,{once:!0}),r.finally(()=>{m.removeEventListener("abort",u)})}if(t===Number.POSITIVE_INFINITY){r.then(h,p);return}let x=new St;i=s.setTimeout.call(void 0,()=>{if(n){try{h(n())}catch(m){p(m)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?h():o instanceof Error?p(o):(x.message=o??`Promise timed out after ${t} milliseconds`,p(x))},t),(async()=>{try{h(await r)}catch(m){p(m)}})()}).finally(()=>{d.clear()});return d.clear=()=>{s.clearTimeout.call(void 0,i),i=void 0},d}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:h,removeListener:p}=Oo(r),x=(...u)=>{let f=t.multiArgs?u:u[0];t.filter&&!t.filter(f)||(d.push(f),t.count===d.length&&(n(),s(d)))},m=u=>{n(),i(u)};n=()=>{for(let u of a)p(u,x);for(let u of t.rejectionEvents)p(u,m)};for(let u of a)h(u,x);for(let u of t.rejectionEvents)h(u,m);t.signal&&t.signal.addEventListener("abort",()=>{m(t.signal.reason)},{once:!0}),t.resolveImmediately&&s(d)});if(o.cancel=n,typeof t.timeout=="number"){let s=Lt(o,{milliseconds:t.timeout});return s.cancel=n,s}return o}function Dt(r,e,t){typeof t=="function"&&(t={filter:t}),t={...t,count:1,resolveImmediately:!1};let n=Vo(r,e,t),o=n.then(s=>s[0]);return o.cancel=n.cancel,o}function $r(r,e){if(typeof r!="string")throw new V(`invalid ip provided: ${r}`);if(typeof e=="string"&&(e=parseInt(e)),isNaN(e))throw new V(`invalid port provided: ${e}`);if((0,N.isIPv4)(r))return $(`/ip4/${r}/tcp/${e}`);if((0,N.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 Mt=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 Mt(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,h)}let d=x=>{try{if(n?.filter?.(x)===!1)return}catch(m){a(),i(m);return}a(),s(x)},h=x=>{a(),i(x.detail)},p=()=>{a(),i(o)};t?.addEventListener("abort",p),r.addEventListener(e,d),n?.errorEvent!=null&&r.addEventListener(n.errorEvent,h)})}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=g=>{n=g,t().catch(b=>{b=new AggregateError([n,b],"The Writable emitted an error, additionally an error occurred while ending the Source")}).finally(()=>{o?.(g)})},i,a=!1,d=()=>{a=!0,i?.()},h,p=!1,x=()=>{p=!0,h?.()},m,u=()=>{m?.()},f=async()=>new Promise((g,b)=>{i=m=g,o=b,r.once("drain",u)}),I=async()=>(await t(),new Promise((g,b)=>{if(a||p||n!=null){g();return}h=i=g,o=b})),T=()=>{r.removeListener("error",s),r.removeListener("close",d),r.removeListener("finish",x),r.removeListener("drain",u)};r.once("error",s),r.once("close",d),r.once("finish",x);try{for await(let g of e){if(!r.writable||r.destroyed||n!=null)break;r.write(g)||await f()}}catch(g){n==null&&r.destroy(g),n=g}try{if(r.writable&&r.end(),await I(),n!=null)throw n}finally{T()}}}function _o(r){return r.return!=null}function Ut(r){return{sink:Vr(r),source:Or(r)}}var Ft=le(F("os"),1),zr=le(F("path"),1);var Ro={ip4:"IPv4",ip6:"IPv6"};function ae(r,e={}){let t=r.getPath();return t!=null?Ft.default.platform()==="win32"?{path:zr.default.join("\\\\.\\pipe\\",t)}:{path:t}:{...e,...r.toOptions()}}function $t(r,e,t){let n=o=>$(`/${r}/${o}/tcp/${t}`);return(jo(e)?Wo(Ro[r]):[e]).map(n)}function jo(r){return["0.0.0.0","::"].includes(r)}var qo=Ft.default.networkInterfaces();function Wo(r){let e=[];for(let[,t]of Object.entries(qo))if(t!=null)for(let n of t)n.family===r&&e.push(n.address);return e}var Ue=(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,h=!1,p=!1;e.listeningAddr?.getPath()!=null&&(e.remoteAddr=e.listeningAddr),e.remoteAddr?.getPath()!=null&&(e.localAddr=e.remoteAddr),r.on("error",g=>{p=!0,h||(n.error("%s socket error - %e",o,g),s?.increment({[`${i}error`]:!0})),r.destroy(),T.timeline.close=Date.now()});let x;if(e.remoteAddr!=null)x=e.remoteAddr;else{if(r.remoteAddress==null||r.remotePort==null)throw new V("Could not determine remote address or port");x=$r(r.remoteAddress,r.remotePort)}let m=ae(x),u=m.path??`${m.host??""}:${m.port??""}`,{sink:f,source:I}=Ut(r);r.setTimeout(a),r.once("timeout",()=>{h=!0,n("%s %s socket read timeout",o,u),s?.increment({[`${i}timeout`]:!0}),r.destroy(new Z),T.timeline.close=Date.now()}),r.once("close",()=>{!h&&!p&&(n("%s %s socket close",o,u),s?.increment({[`${i}close`]:!0})),r.destroy(),T.timeline.close=Date.now()}),r.once("end",()=>{n("%s %s socket end",o,u),s?.increment({[`${i}end`]:!0})});let T={async sink(g){try{await f(async function*(){for await(let b of g)b instanceof Uint8Array?yield b:yield b.subarray()}())}catch(b){b.type!=="aborted"&&n.error("%s %s error in sink - %e",o,u,b)}r.end()},source:I,remoteAddr:x,timeline:{open:Date.now()},async close(g={}){if(r.closed){n("the %s %s socket is already closed",o,u);return}if(r.destroyed){n("the %s %s socket is already destroyed",o,u);return}if(t!=null)return t.promise;try{t=kt(),r.end();let b=Go(r),L=g.signal??AbortSignal.timeout(d);r.writableLength>0&&(n("%s %s draining socket",o,u),await Nt(b,"drain",L,{errorEvent:"error"}),n("%s %s socket drained",o,u)),await Promise.all([Nt(b,"close",L,{errorEvent:"error"}),r.destroy()])}catch(b){this.abort(b)}finally{t.resolve()}},abort:g=>{n("%s %s socket abort due to error - %e",o,u,g),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 Fe=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=Ue(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(n=>{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(o=>{this.log.error("error attempting to listen server once connection count under limit",o),this.context.closeServerOnMaxConnections?.onListenError?.(o)})}),this.context.handler!=null&&this.context.handler(n),this.context.closeServerOnMaxConnections!=null&&this.sockets.size>=this.context.closeServerOnMaxConnections.closeAbove&&this.pause(),this.safeDispatchEvent("connection",{detail:n})}).catch(async n=>{this.log.error("inbound connection upgrade failed",n),this.metrics?.errors.increment({[`${this.addr} inbound_upgrade`]:!0}),this.sockets.delete(e),t.abort(n)})}getAddrs(){if(this.status.code===A.INACTIVE)return[];let e=[],t=this.server.address(),{listeningAddr:n,peerId:o}=this.status;if(t==null)return[];if(typeof t=="string")e=[n];else try{n.toString().startsWith("/ip4")?e=e.concat($t("ip4",t.address,t.port)):t.family==="IPv6"&&(e=e.concat($t("ip6",t.address,t.port)))}catch(s){this.log.error("could not turn %s:%s into multiaddr",t.address,t.port,s)}return e.map(s=>o!=null?s.encapsulate(`/p2p/${o}`):s)}async listen(e){if(this.status.code===A.ACTIVE||this.status.code===A.PAUSED)throw new be("server is already listening");let t=e.getPeerId(),n=t==null?e.decapsulateCode(421):e,{backlog:o}=this.context;try{this.status={code:A.ACTIVE,listeningAddr:n,peerId:t,netConfig:ae(n,{backlog:o})},await this.resume()}catch(s){throw this.status={code:A.INACTIVE},s}}async close(){let e=[];this.server.listening&&e.push(Dt(this.server,"close")),this.pause(!0),this.shutdownController.abort(),this.sockets.forEach(t=>{t.readable&&(e.push(Dt(t,"close")),t.destroy())}),await Promise.all(e)}async resume(){if(this.server.listening||this.status.code===A.INACTIVE)return;let e=this.status.netConfig;await new Promise((t,n)=>{this.server.once("error",n),this.server.listen(e,t)}),this.status={...this.status,code:A.ACTIVE},this.log("listening on %s",this.server.address())}pause(e=!1){if(!this.server.listening&&this.status.code===A.PAUSED&&e){this.status={code:A.INACTIVE};return}!this.server.listening||this.status.code!==A.ACTIVE||(this.log("closing server on %s",this.server.address()),this.status=e?{code:A.INACTIVE}:{...this.status,code:A.PAUSED},this.server.close())}};var $e=class{opts;metrics;components;log;constructor(e,t={}){this.log=e.logger.forComponent("libp2p:tcp"),this.opts=t,this.components=e,e.metrics!=null&&(this.metrics={events:e.metrics.registerCounterGroup("libp2p_tcp_dialer_events_total",{label:"event",help:"Total count of TCP dialer events by type"}),errors:e.metrics.registerCounterGroup("libp2p_tcp_dialer_errors_total",{label:"event",help:"Total count of TCP dialer events by type"})})}[zt]=!0;[Symbol.toStringTag]="@libp2p/tcp";[_t]=["@libp2p/transport"];async dial(e,t){t.keepAlive=t.keepAlive??!0,t.noDelay=t.noDelay??!0;let n=await this._connect(e,t),o;try{o=Ue(n,{remoteAddr:e,socketInactivityTimeout:this.opts.outboundSocketInactivityTimeout,socketCloseTimeout:this.opts.socketCloseTimeout,metrics:this.metrics?.events,logger:this.components.logger,direction:"outbound"})}catch(s){throw this.metrics?.errors.increment({outbound_to_connection:!0}),n.destroy(s),s}try{return this.log("new outbound connection %s",o.remoteAddr),await t.upgrader.upgradeOutbound(o,t)}catch(s){throw this.metrics?.errors.increment({outbound_upgrade:!0}),this.log.error("error upgrading outbound connection",s),o.abort(s),s}}async _connect(e,t){t.signal?.throwIfAborted(),t.onProgress?.(new Ne("tcp:open-connection"));let n;return new Promise((o,s)=>{let i=Date.now(),a=ae(e,{...this.opts.dialOpts??{},...t});this.log("dialing %a",e),n=_r.default.connect(a);let d=u=>{this.log.error("dial to %a errored - %e",e,u);let f=a.path??`${a.host??""}:${a.port}`;u.message=`connection error ${f}: ${u.message}`,this.metrics?.events.increment({error:!0}),m(u)},h=()=>{this.log("connection timeout %a",e),this.metrics?.events.increment({timeout:!0});let u=new Z(`Connection timeout after ${Date.now()-i}ms`);n.emit("error",u)},p=()=>{this.log("connection opened %a",e),this.metrics?.events.increment({connect:!0}),m()},x=()=>{this.log("connection aborted %a",e),this.metrics?.events.increment({abort:!0}),m(new ge)},m=u=>{if(n.removeListener("error",d),n.removeListener("timeout",h),n.removeListener("connect",p),t.signal!=null&&t.signal.removeEventListener("abort",x),u!=null){s(u);return}o(n)};n.on("error",d),n.on("timeout",h),n.on("connect",p),t.signal!=null&&t.signal.addEventListener("abort",x)}).catch(o=>{throw n?.destroy(),o})}createListener(e){return new Fe({...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 $e(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})},Ot=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of qr(e))!Gr.call(r,o)&&o!==t&&xe(r,o,{get:()=>e[o],enumerable:!(n=jr(e,o))||n.enumerable});return r};var le=(r,e,t)=>(t=r!=null?Rr(Wr(r)):{},Ot(e||!r||!r.__esModule?xe(t,"default",{value:r,enumerable:!0}):t,r)),Hr=r=>Ot(xe({},"__esModule",{value:!0}),r);var Qo={};D(Qo,{tcp:()=>Jo});var _r=le(F("net"),1);var zt=Symbol.for("@libp2p/transport");var Vt;(function(r){r[r.FATAL_ALL=0]="FATAL_ALL",r[r.NO_FATAL=1]="NO_FATAL"})(Vt||(Vt={}));var ge=class extends Error{static name="AbortError";constructor(e="The operation was aborted"){super(e),this.name="AbortError"}};var V=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}};var Z=class extends Error{static name="TimeoutError";constructor(e="Timed out"){super(e),this.name="TimeoutError"}},we=class extends Error{static name="NotStartedError";constructor(e="Not started"){super(e),this.name="NotStartedError"}},be=class extends Error{static name="AlreadyStartedError";constructor(e="Already started"){super(e),this.name="AlreadyStartedError"}};var Bt=F("events"),ve=(r,...e)=>{try{(0,Bt.setMaxListeners)(r,...e)}catch{}};var ye=class extends EventTarget{#e=new Map;constructor(){super(),ve(1/0,this)}listenerCount(e){let t=this.#e.get(e);return t==null?0:t.length}addEventListener(e,t,n){super.addEventListener(e,t,n);let o=this.#e.get(e);o==null&&(o=[],this.#e.set(e,o)),o.push({callback:t,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(e,t,n){super.removeEventListener(e.toString(),t??null,n);let o=this.#e.get(e);o!=null&&(o=o.filter(({callback:s})=>s!==t),this.#e.set(e,o))}dispatchEvent(e){let t=super.dispatchEvent(e),n=this.#e.get(e.type);return n==null||(n=n.filter(({once:o})=>!o),this.#e.set(e.type,n)),t}safeDispatchEvent(e,t={}){return this.dispatchEvent(new CustomEvent(e,t))}};var _t=Symbol.for("@libp2p/service-capabilities"),rs=Symbol.for("@libp2p/service-dependencies");var _e={};D(_e,{base58btc:()=>S,base58flickr:()=>Zr});var Ts=new Uint8Array(0);function Rt(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}function M(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")}function jt(r){return new TextEncoder().encode(r)}function qt(r){return new TextDecoder().decode(r)}function Jr(r,e){if(r.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),n=0;n<t.length;n++)t[n]=255;for(var o=0;o<r.length;o++){var s=r.charAt(o),i=s.charCodeAt(0);if(t[i]!==255)throw new TypeError(s+" is ambiguous");t[i]=o}var a=r.length,d=r.charAt(0),h=Math.log(a)/Math.log(256),p=Math.log(256)/Math.log(a);function x(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,g=0,b=f.length;g!==b&&f[g]===0;)g++,I++;for(var L=(b-g)*p+1>>>0,k=new Uint8Array(L);g!==b;){for(var O=f[g],j=0,U=L-1;(O!==0||j<T)&&U!==-1;U--,j++)O+=256*k[U]>>>0,k[U]=O%a>>>0,O=O/a>>>0;if(O!==0)throw new Error("Non-zero carry");T=j,g++}for(var B=L-T;B!==L&&k[B]===0;)B++;for(var me=d.repeat(I);B<L;++B)me+=r.charAt(k[B]);return me}function m(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,g=0;f[I]===d;)T++,I++;for(var b=(f.length-I)*h+1>>>0,L=new Uint8Array(b);f[I];){var k=t[f.charCodeAt(I)];if(k===255)return;for(var O=0,j=b-1;(k!==0||O<g)&&j!==-1;j--,O++)k+=a*L[j]>>>0,L[j]=k%256>>>0,k=k/256>>>0;if(k!==0)throw new Error("Non-zero carry");g=O,I++}if(f[I]!==" "){for(var U=b-g;U!==b&&L[U]===0;)U++;for(var B=new Uint8Array(T+(b-U)),me=T;U!==b;)B[me++]=L[U++];return B}}}function u(f){var I=m(f);if(I)return I;throw new Error(`Non-${e} character`)}return{encode:x,decodeUnsafe:m,decode:u}}var Qr=Jr,Xr=Qr,Gt=Xr;var Oe=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")}},Ve=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,t,n){this.name=e,this.prefix=t;let o=t.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return Ht(this,e)}},ze=class{decoders;constructor(e){this.decoders=e}or(e){return Ht(this,e)}decode(e){let t=e[0],n=this.decoders[t];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Ht(r,e){return new ze({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var Be=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 Oe(e,t,n),this.decoder=new Ve(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function ee({name:r,prefix:e,encode:t,decode:n}){return new Be(r,e,t,n)}function q({name:r,prefix:e,alphabet:t}){let{encode:n,decode:o}=Gt(t,r);return ee({prefix:e,name:r,encode:n,decode:s=>M(o(s))})}function Kr(r,e,t,n){let o={};for(let p=0;p<e.length;++p)o[e[p]]=p;let s=r.length;for(;r[s-1]==="=";)--s;let i=new Uint8Array(s*t/8|0),a=0,d=0,h=0;for(let p=0;p<s;++p){let x=o[r[p]];if(x===void 0)throw new SyntaxError(`Non-${n} character`);d=d<<t|x,a+=t,a>=8&&(a-=8,i[h++]=255&d>>a)}if(a>=t||255&d<<8-a)throw new SyntaxError("Unexpected end of data");return i}function Yr(r,e,t){let n=e[e.length-1]==="=",o=(1<<t)-1,s="",i=0,a=0;for(let d=0;d<r.length;++d)for(a=a<<8|r[d],i+=8;i>t;)i-=t,s+=e[o&a>>i];if(i!==0&&(s+=e[o&a<<t-i]),n)for(;s.length*t&7;)s+="=";return s}function y({name:r,prefix:e,bitsPerChar:t,alphabet:n}){return ee({prefix:e,name:r,encode(o){return Yr(o,n,t)},decode(o){return Kr(o,n,t,r)}})}var S=q({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Zr=q({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Re={};D(Re,{base32:()=>_,base32hex:()=>nn,base32hexpad:()=>sn,base32hexpadupper:()=>cn,base32hexupper:()=>on,base32pad:()=>tn,base32padupper:()=>rn,base32upper:()=>en,base32z:()=>an});var _=y({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),en=y({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),tn=y({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),rn=y({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),nn=y({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),on=y({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),sn=y({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),cn=y({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),an=y({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var je={};D(je,{base36:()=>ue,base36upper:()=>ln});var ue=q({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),ln=q({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var un=Xt,Jt=128,dn=127,pn=~dn,fn=Math.pow(2,31);function Xt(r,e,t){e=e||[],t=t||0;for(var n=t;r>=fn;)e[t++]=r&255|Jt,r/=128;for(;r&pn;)e[t++]=r&255|Jt,r>>>=7;return e[t]=r|0,Xt.bytes=t-n+1,e}var hn=qe,mn=128,Qt=127;function qe(r,n){var t=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw qe.bytes=0,new RangeError("Could not decode varint");i=r[s++],t+=o<28?(i&Qt)<<o:(i&Qt)*Math.pow(2,o),o+=7}while(i>=mn);return qe.bytes=s-n,t}var xn=Math.pow(2,7),gn=Math.pow(2,14),wn=Math.pow(2,21),bn=Math.pow(2,28),vn=Math.pow(2,35),yn=Math.pow(2,42),En=Math.pow(2,49),In=Math.pow(2,56),An=Math.pow(2,63),Cn=function(r){return r<xn?1:r<gn?2:r<wn?3:r<bn?4:r<vn?5:r<yn?6:r<En?7:r<In?8:r<An?9:10},Tn={encode:un,decode:hn,encodingLength:Cn},Sn=Tn,de=Sn;function pe(r,e=0){return[de.decode(r,e),de.decode.bytes]}function te(r,e,t=0){return de.encode(r,e,t),e}function re(r){return de.encodingLength(r)}function J(r,e){let t=e.byteLength,n=re(r),o=n+re(t),s=new Uint8Array(o+t);return te(r,s,0),te(t,s,n),s.set(e,o),new ne(r,t,e,s)}function Ie(r){let e=M(r),[t,n]=pe(e),[o,s]=pe(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new ne(t,o,i,e)}function Kt(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&Rt(r.bytes,t.bytes)}}var ne=class{code;size;digest;bytes;constructor(e,t,n,o){this.code=e,this.size=t,this.digest=n,this.bytes=o}};function Yt(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return Ln(t,We(r),e??S.encoder);default:return Dn(t,We(r),e??_.encoder)}}var Zt=new WeakMap;function We(r){let e=Zt.get(r);if(e==null){let t=new Map;return Zt.set(r,t),t}return e}var W=class r{code;version;multihash;bytes;"/";constructor(e,t,n,o){this.code=t,this.version=e,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:t}=this;if(e!==fe)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==kn)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(t)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:e,digest:t}=this.multihash,n=J(e,t);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(e){return r.equals(this,e)}static equals(e,t){let n=t;return n!=null&&e.code===n.code&&e.version===n.version&&Kt(e.multihash,n.multihash)}toString(e){return Yt(this,e)}toJSON(){return{"/":Yt(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let t=e;if(t instanceof r)return t;if(t["/"]!=null&&t["/"]===t.bytes||t.asCID===t){let{version:n,code:o,multihash:s,bytes:i}=t;return new r(n,o,s,i??er(n,o,s.bytes))}else if(t[Mn]===!0){let{version:n,multihash:o,code:s}=t,i=Ie(o);return r.create(n,s,i)}else return null}static create(e,t,n){if(typeof t!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(t!==fe)throw new Error(`Version 0 CID must use dag-pb (code: ${fe}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let o=er(e,t,n.bytes);return new r(e,t,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,fe,e)}static createV1(e,t){return r.create(1,e,t)}static decode(e){let[t,n]=r.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return t}static decodeFirst(e){let t=r.inspectBytes(e),n=t.size-t.multihashSize,o=M(e.subarray(n,n+t.multihashSize));if(o.byteLength!==t.multihashSize)throw new Error("Incorrect length");let s=o.subarray(t.multihashSize-t.digestSize),i=new ne(t.multihashCode,t.digestSize,s,o);return[t.version===0?r.createV0(i):r.createV1(t.codec,i),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[x,m]=pe(e.subarray(t));return t+=m,x},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(),h=t+d,p=h-i;return{version:o,codec:s,multihashCode:a,digestSize:d,multihashSize:p,size:h}}static parse(e,t){let[n,o]=Pn(e,t),s=r.decode(o);if(s.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return We(s).set(n,e),s}};function Pn(r,e){switch(r[0]){case"Q":{let t=e??S;return[S.prefix,t.decode(`${S.prefix}${r}`)]}case S.prefix:{let t=e??S;return[S.prefix,t.decode(r)]}case _.prefix:{let t=e??_;return[_.prefix,t.decode(r)]}case ue.prefix:{let t=e??ue;return[ue.prefix,t.decode(r)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],e.decode(r)]}}}function Ln(r,e,t){let{prefix:n}=t;if(n!==S.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let o=e.get(n);if(o==null){let s=t.encode(r).slice(1);return e.set(n,s),s}else return o}function Dn(r,e,t){let{prefix:n}=t,o=e.get(n);if(o==null){let s=t.encode(r);return e.set(n,s),s}else return o}var fe=112,kn=18;function er(r,e,t){let n=re(r),o=n+re(e),s=new Uint8Array(o+t.byteLength);return te(r,s,0),te(e,s,n),s.set(t,o),s}var Mn=Symbol.for("@ipld/js-cid/CID");function tr(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}var lr=F("node:buffer");var Ge={};D(Ge,{base10:()=>Nn});var Nn=q({prefix:"9",name:"base10",alphabet:"0123456789"});var He={};D(He,{base16:()=>Un,base16upper:()=>Fn});var Un=y({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Fn=y({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Je={};D(Je,{base2:()=>$n});var $n=y({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Qe={};D(Qe,{base256emoji:()=>_n});var rr=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),On=rr.reduce((r,e,t)=>(r[t]=e,r),[]),Vn=rr.reduce((r,e,t)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return r[n]=t,r},[]);function zn(r){return r.reduce((e,t)=>(e+=On[t],e),"")}function Bn(r){let e=[];for(let t of r){let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);let o=Vn[n];if(o==null)throw new Error(`Non-base256emoji character: ${t}`);e.push(o)}return new Uint8Array(e)}var _n=ee({prefix:"\u{1F680}",name:"base256emoji",encode:zn,decode:Bn});var Xe={};D(Xe,{base64:()=>Rn,base64pad:()=>jn,base64url:()=>qn,base64urlpad:()=>Wn});var Rn=y({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),jn=y({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),qn=y({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Wn=y({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Ke={};D(Ke,{base8:()=>Gn});var Gn=y({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Ye={};D(Ye,{identity:()=>Hn});var Hn=ee({prefix:"\0",name:"identity",encode:r=>qt(r),decode:r=>jt(r)});var Ys=new TextEncoder,Zs=new TextDecoder;var Ze={};D(Ze,{identity:()=>Yn});var nr=0,Xn="identity",or=M;function Kn(r){return J(nr,or(r))}var Yn={code:nr,name:Xn,encode:or,digest:Kn};var nt={};D(nt,{sha256:()=>Zn,sha512:()=>eo});var rt=le(F("crypto"),1);function tt({name:r,code:e,encode:t}){return new et(r,e,t)}var et=class{name;code;encode;constructor(e,t,n){this.name=e,this.code=t,this.encode=n}digest(e){if(e instanceof Uint8Array){let t=this.encode(e);return t instanceof Uint8Array?J(this.code,t):t.then(n=>J(this.code,n))}else throw Error("Unknown type, must be binary type")}};var Zn=tt({name:"sha2-256",code:18,encode:r=>M(rt.default.createHash("sha256").update(r).digest())}),eo=tt({name:"sha2-512",code:19,encode:r=>M(rt.default.createHash("sha512").update(r).digest())});var he={...Ye,...Je,...Ke,...Ge,...He,...Re,...je,..._e,...Xe,...Qe},fi={...nt,...Ze};var ir=F("node:buffer");function se(r){return new Uint8Array(r.buffer,r.byteOffset,r.byteLength)}function Ae(r=0){return se(ir.Buffer.allocUnsafe(r))}function ar(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var cr=ar("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),ot=ar("ascii","a",r=>{let e="a";for(let t=0;t<r.length;t++)e+=String.fromCharCode(r[t]);return e},r=>{r=r.substring(1);let e=Ae(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),to={utf8:cr,"utf-8":cr,hex:he.base16,latin1:ot,ascii:ot,binary:ot,...he},Ce=to;function P(r,e="utf8"){let t=Ce[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return e==="utf8"||e==="utf-8"?lr.Buffer.from(r.buffer,r.byteOffset,r.byteLength).toString("utf8"):t.encoder.encode(r).substring(1)}var ro=Math.pow(2,7),no=Math.pow(2,14),oo=Math.pow(2,21),st=Math.pow(2,28),it=Math.pow(2,35),ct=Math.pow(2,42),at=Math.pow(2,49),w=128,C=127;function z(r){if(r<ro)return 1;if(r<no)return 2;if(r<oo)return 3;if(r<st)return 4;if(r<it)return 5;if(r<ct)return 6;if(r<at)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function so(r,e,t=0){switch(z(r)){case 8:e[t++]=r&255|w,r/=128;case 7:e[t++]=r&255|w,r/=128;case 6:e[t++]=r&255|w,r/=128;case 5:e[t++]=r&255|w,r/=128;case 4:e[t++]=r&255|w,r>>>=7;case 3:e[t++]=r&255|w,r>>>=7;case 2:e[t++]=r&255|w,r>>>=7;case 1:{e[t++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return e}function io(r,e,t=0){switch(z(r)){case 8:e.set(t++,r&255|w),r/=128;case 7:e.set(t++,r&255|w),r/=128;case 6:e.set(t++,r&255|w),r/=128;case 5:e.set(t++,r&255|w),r/=128;case 4:e.set(t++,r&255|w),r>>>=7;case 3:e.set(t++,r&255|w),r>>>=7;case 2:e.set(t++,r&255|w),r>>>=7;case 1:{e.set(t++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return e}function co(r,e){let t=r[e],n=0;if(n+=t&C,t<w||(t=r[e+1],n+=(t&C)<<7,t<w)||(t=r[e+2],n+=(t&C)<<14,t<w)||(t=r[e+3],n+=(t&C)<<21,t<w)||(t=r[e+4],n+=(t&C)*st,t<w)||(t=r[e+5],n+=(t&C)*it,t<w)||(t=r[e+6],n+=(t&C)*ct,t<w)||(t=r[e+7],n+=(t&C)*at,t<w))return n;throw new RangeError("Could not decode varint")}function ao(r,e){let t=r.get(e),n=0;if(n+=t&C,t<w||(t=r.get(e+1),n+=(t&C)<<7,t<w)||(t=r.get(e+2),n+=(t&C)<<14,t<w)||(t=r.get(e+3),n+=(t&C)<<21,t<w)||(t=r.get(e+4),n+=(t&C)*st,t<w)||(t=r.get(e+5),n+=(t&C)*it,t<w)||(t=r.get(e+6),n+=(t&C)*ct,t<w)||(t=r.get(e+7),n+=(t&C)*at,t<w))return n;throw new RangeError("Could not decode varint")}function ie(r,e,t=0){return e==null&&(e=Ae(z(r))),e instanceof Uint8Array?so(r,e,t):io(r,e,t)}function Q(r,e=0){return r instanceof Uint8Array?co(r,e):ao(r,e)}var dr=F("node:buffer");function R(r,e){return se(dr.Buffer.concat(r,e))}var Te=class{index=0;input="";new(e){return this.index=0,this.input=e,this}readAtomically(e){let t=this.index,n=e();return n===void 0&&(this.index=t),n}parseWith(e){let t=e();if(this.index===this.input.length)return t}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(e){return this.readAtomically(()=>{let t=this.readChar();if(t===e)return t})}readSeparator(e,t,n){return this.readAtomically(()=>{if(!(t>0&&this.readGivenChar(e)===void 0))return n()})}readNumber(e,t,n,o){return this.readAtomically(()=>{let s=0,i=0,a=this.peekChar();if(a===void 0)return;let d=a==="0",h=2**(8*o)-1;for(;;){let p=this.readAtomically(()=>{let x=this.readChar();if(x===void 0)return;let m=Number.parseInt(x,e);if(!Number.isNaN(m))return m});if(p===void 0)break;if(s*=e,s+=p,s>h||(i+=1,t!==void 0&&i>t))return}if(i!==0)return!n&&d&&i>1?void 0:s})}readIPv4Addr(){return this.readAtomically(()=>{let e=new Uint8Array(4);for(let t=0;t<e.length;t++){let n=this.readSeparator(".",t,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;e[t]=n}return e})}readIPv6Addr(){let e=t=>{for(let n=0;n<t.length/2;n++){let o=n*2;if(n<t.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return t[o]=i[0],t[o+1]=i[1],t[o+2]=i[2],t[o+3]=i[3],[o+4,!0]}let s=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(s===void 0)return[o,!1];t[o]=s>>8,t[o+1]=s&255}return[t.length,!1]};return this.readAtomically(()=>{let t=new Uint8Array(16),[n,o]=e(t);if(n===16)return t;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let s=new Uint8Array(14),i=16-(n+2),[a]=e(s.subarray(0,i));return t.set(s.subarray(0,a),16-a),t})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var Pi=new Te;var $i=parseInt("0xFFFF",16),Oi=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);var hr=F("node:buffer");function lt(r,e="utf8"){let t=Ce[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return e==="utf8"||e==="utf-8"?se(hr.Buffer.from(r,"utf-8")):t.decoder.decode(`${t.prefix}${r}`)}var N=F("node:net");function Se(r){return!!(0,N.isIP)(r)}var mr=N.isIPv4,mo=N.isIPv6,ut=function(r){let e=0;if(r=r.toString().trim(),mr(r)){let t=new Uint8Array(e+4);return r.split(/\./g).forEach(n=>{t[e++]=parseInt(n,10)&255}),t}if(mo(r)){let t=r.split(":",8),n;for(n=0;n<t.length;n++){let s=mr(t[n]),i;s&&(i=ut(t[n]),t[n]=P(i.slice(0,2),"base16")),i!=null&&++n<8&&t.splice(n,0,P(i.slice(2,4),"base16"))}if(t[0]==="")for(;t.length<8;)t.unshift("0");else if(t[t.length-1]==="")for(;t.length<8;)t.push("0");else if(t.length<8){for(n=0;n<t.length&&t[n]!=="";n++);let s=[n,1];for(n=9-t.length;n>0;n--)s.push("0");t.splice.apply(t,s)}let o=new Uint8Array(e+16);for(n=0;n<t.length;n++){let s=parseInt(t[n],16);o[e++]=s>>8&255,o[e++]=s&255}return o}throw new Error("invalid ip address")},xr=function(r,e=0,t){e=~~e,t=t??r.length-e;let n=new DataView(r.buffer);if(t===4){let o=[];for(let s=0;s<t;s++)o.push(r[e+s]);return o.join(".")}if(t===16){let o=[];for(let s=0;s<t;s+=2)o.push(n.getUint16(e+s).toString(16));return o.join(":").replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}return""};var ce={},dt={},go=[[4,32,"ip4"],[6,16,"tcp"],[33,16,"dccp"],[41,128,"ip6"],[42,-1,"ip6zone"],[43,8,"ipcidr"],[53,-1,"dns",!0],[54,-1,"dns4",!0],[55,-1,"dns6",!0],[56,-1,"dnsaddr",!0],[132,16,"sctp"],[273,16,"udp"],[275,0,"p2p-webrtc-star"],[276,0,"p2p-webrtc-direct"],[277,0,"p2p-stardust"],[280,0,"webrtc-direct"],[281,0,"webrtc"],[290,0,"p2p-circuit"],[301,0,"udt"],[302,0,"utp"],[400,-1,"unix",!1,!0],[421,-1,"ipfs"],[421,-1,"p2p"],[443,0,"https"],[444,96,"onion"],[445,296,"onion3"],[446,-1,"garlic64"],[448,0,"tls"],[449,-1,"sni"],[460,0,"quic"],[461,0,"quic-v1"],[465,0,"webtransport"],[466,-1,"certhash"],[477,0,"ws"],[478,0,"wss"],[479,0,"p2p-websocket-star"],[480,0,"http"],[481,-1,"http-path"],[777,-1,"memory"]];go.forEach(r=>{let e=wo(...r);dt[e.code]=e,ce[e.name]=e});function wo(r,e,t,n,o){return{code:r,size:e,name:t,resolvable:!!n,path:!!o}}function v(r){if(typeof r=="number"){if(dt[r]!=null)return dt[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(ce[r]!=null)return ce[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var Ac=v("ip4"),Cc=v("ip6"),Tc=v("ipcidr");function mt(r,e){switch(v(r).code){case 4:case 41:return vo(e);case 42:return ht(e);case 6:case 273:case 33:case 132:return br(e).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return ht(e);case 421:return Ao(e);case 444:return wr(e);case 445:return wr(e);case 466:return Io(e);case 481:return globalThis.encodeURIComponent(ht(e));default:return P(e,"base16")}}function xt(r,e){switch(v(r).code){case 4:return gr(e);case 41:return gr(e);case 42:return ft(e);case 6:case 273:case 33:case 132:return gt(parseInt(e,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return ft(e);case 421:return yo(e);case 444:return Co(e);case 445:return To(e);case 466:return Eo(e);case 481:return ft(globalThis.decodeURIComponent(e));default:return lt(e,"base16")}}var pt=Object.values(he).map(r=>r.decoder),bo=function(){let r=pt[0].or(pt[1]);return pt.slice(2).forEach(e=>r=r.or(e)),r}();function gr(r){if(!Se(r))throw new Error("invalid ip address");return ut(r)}function vo(r){let e=xr(r,0,r.length);if(e==null)throw new Error("ipBuff is required");if(!Se(e))throw new Error("invalid ip address");return e}function gt(r){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,r),new Uint8Array(e)}function br(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function ft(r){let e=lt(r),t=Uint8Array.from(ie(e.length));return R([t,e],t.length+e.length)}function ht(r){let e=Q(r);if(r=r.slice(z(e)),r.length!==e)throw new Error("inconsistent lengths");return P(r)}function yo(r){let e;r[0]==="Q"||r[0]==="1"?e=Ie(S.decode(`z${r}`)).bytes:e=W.parse(r).multihash.bytes;let t=Uint8Array.from(ie(e.length));return R([t,e],t.length+e.length)}function Eo(r){let e=bo.decode(r),t=Uint8Array.from(ie(e.length));return R([t,e],t.length+e.length)}function Io(r){let e=Q(r),t=r.slice(z(e));if(t.length!==e)throw new Error("inconsistent lengths");return"u"+P(t,"base64url")}function Ao(r){let e=Q(r),t=r.slice(z(e));if(t.length!==e)throw new Error("inconsistent lengths");return P(t,"base58btc")}function Co(r){let e=r.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==16)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion address.`);let t=_.decode("b"+e[0]),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=gt(n);return R([t,o],t.length+o.length)}function To(r){let e=r.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==56)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion3 address.`);let t=_.decode(`b${e[0]}`),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=gt(n);return R([t,o],t.length+o.length)}function wr(r){let e=r.slice(0,r.length-2),t=r.slice(r.length-2),n=P(e,"base32"),o=br(t);return`${n}:${o}`}function vr(r){r=wt(r);let e=[],t=[],n=null,o=r.split("/").slice(1);if(o.length===1&&o[0]==="")return{bytes:new Uint8Array,string:"/",tuples:[],stringTuples:[],path:null};for(let s=0;s<o.length;s++){let i=o[s],a=v(i);if(a.size===0){e.push([a.code]),t.push([a.code]);continue}if(s++,s>=o.length)throw Er("invalid address: "+r);if(a.path===!0){n=wt(o.slice(s).join("/")),e.push([a.code,xt(a.code,n)]),t.push([a.code,n]);break}let d=xt(a.code,o[s]);e.push([a.code,d]),t.push([a.code,mt(a.code,d)])}return{string:yr(t),bytes:vt(e),tuples:e,stringTuples:t,path:n}}function bt(r){let e=[],t=[],n=null,o=0;for(;o<r.length;){let s=Q(r,o),i=z(s),a=v(s),d=So(a,r.slice(o+i));if(d===0){e.push([s]),t.push([s]),o+=i;continue}let h=r.slice(o+i,o+i+d);if(o+=d+i,o>r.length)throw Er("Invalid address Uint8Array: "+P(r,"base16"));e.push([s,h]);let p=mt(s,h);if(t.push([s,p]),a.path===!0){n=p;break}}return{bytes:Uint8Array.from(r),string:yr(t),tuples:e,stringTuples:t,path:n}}function yr(r){let e=[];return r.map(t=>{let n=v(t[0]);return e.push(n.name),t.length>1&&t[1]!=null&&e.push(t[1]),null}),wt(e.join("/"))}function vt(r){return R(r.map(e=>{let t=v(e[0]),n=Uint8Array.from(ie(t.code));return e.length>1&&e[1]!=null&&(n=R([n,e[1]])),n}))}function So(r,e){if(r.size>0)return r.size/8;if(r.size===0)return 0;{let t=Q(e instanceof Uint8Array?e:Uint8Array.from(e));return t+z(t)}}function wt(r){return"/"+r.trim().split("/").filter(e=>e).join("/")}function Er(r){return new Error("Error parsing address: "+r)}var Po=Symbol.for("nodejs.util.inspect.custom"),Et=Symbol.for("@multiformats/js-multiaddr/multiaddr"),Lo=[v("dns").code,v("dns4").code,v("dns6").code,v("dnsaddr").code],yt=class extends Error{constructor(e="No available resolver"){super(e),this.name="NoAvailableResolverError"}},Pe=class r{bytes;#e;#t;#r;#n;[Et]=!0;constructor(e){e==null&&(e="");let t;if(e instanceof Uint8Array)t=bt(e);else if(typeof e=="string"){if(e.length>0&&e.charAt(0)!=="/")throw new Error(`multiaddr "${e}" must start with a "/"`);t=vr(e)}else if(Ar(e))t=bt(e.bytes);else throw new Error("addr must be a string, Buffer, or another Multiaddr");this.bytes=t.bytes,this.#e=t.string,this.#t=t.tuples,this.#r=t.stringTuples,this.#n=t.path}toString(){return this.#e}toJSON(){return this.toString()}toOptions(){let e,t,n,o,s="",i=v("tcp"),a=v("udp"),d=v("ip4"),h=v("ip6"),p=v("dns6"),x=v("ip6zone");for(let[u,f]of this.stringTuples())u===x.code&&(s=`%${f??""}`),Lo.includes(u)&&(t=i.name,o=443,n=`${f??""}${s}`,e=u===p.code?6:4),(u===i.code||u===a.code)&&(t=v(u).name,o=parseInt(f??"")),(u===d.code||u===h.code)&&(t=v(u).name,n=`${f??""}${s}`,e=u===h.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}stringTuples(){return this.#r}encapsulate(e){return e=new r(e),new r(this.toString()+e.toString())}decapsulate(e){let t=e.toString(),n=this.toString(),o=n.lastIndexOf(t);if(o<0)throw new Error(`Address ${this.toString()} does not contain subaddress: ${e.toString()}`);return new r(n.slice(0,o))}decapsulateCode(e){let t=this.tuples();for(let n=t.length-1;n>=0;n--)if(t[n][0]===e)return new r(vt(t.slice(0,n)));return this}getPeerId(){try{let e=[];this.stringTuples().forEach(([n,o])=>{n===ce.p2p.code&&e.push([n,o]),n===ce["p2p-circuit"].code&&(e=[])});let t=e.pop();if(t?.[1]!=null){let n=t[1];return n[0]==="Q"||n[0]==="1"?P(S.decode(`z${n}`),"base58btc"):P(W.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){return this.#n}equals(e){return tr(this.bytes,e.bytes)}async resolve(e){let t=this.protos().find(s=>s.resolvable);if(t==null)return[this];let n=Ir.get(t.name);if(n==null)throw new yt(`no available resolver for ${t.name}`);return(await n(this,e)).map(s=>$(s))}nodeAddress(){let e=this.toOptions();if(e.transport!=="tcp"&&e.transport!=="udp")throw new Error(`multiaddr must have a valid format - no protocol with name: "${e.transport}". Must have a valid transport protocol: "{tcp, udp}"`);return{family:e.family,address:e.host,port:e.port}}isThinWaistAddress(e){let t=(e??this).protos();return!(t.length!==2||t[0].code!==4&&t[0].code!==41||t[1].code!==6&&t[1].code!==273)}[Po](){return`Multiaddr(${this.#e})`}};var Ir=new Map;function Ar(r){return!!r?.[Et]}function $(r){return new Pe(r)}var Do=c("dns4"),ko=c("dns6"),Mo=c("dnsaddr"),K=E(c("dns"),Mo,Do,ko),ke=E(c("ip4"),c("ip6")),H=E(l(ke,c("tcp")),l(K,c("tcp"))),Me=l(ke,c("udp")),No=l(Me,c("utp")),Uo=l(Me,c("quic")),Fo=l(Me,c("quic-v1")),It=E(l(H,c("ws")),l(K,c("ws"))),Le=E(l(It,c("p2p")),It),At=E(l(H,c("wss")),l(K,c("wss")),l(H,c("tls"),c("ws")),l(K,c("tls"),c("ws"))),De=E(l(At,c("p2p")),At),Ct=E(l(H,c("http")),l(ke,c("http")),l(K,c("http"))),Tt=E(l(H,c("https")),l(ke,c("https")),l(K,c("https"))),Cr=l(Me,c("webrtc-direct"),c("certhash")),Pr=E(l(Cr,c("p2p")),Cr),Tr=l(Fo,c("webtransport"),c("certhash"),c("certhash")),Lr=E(l(Tr,c("p2p")),Tr),Dr=E(l(Le,c("p2p-webrtc-star"),c("p2p")),l(De,c("p2p-webrtc-star"),c("p2p")),l(Le,c("p2p-webrtc-star")),l(De,c("p2p-webrtc-star"))),Kc=E(l(Le,c("p2p-websocket-star"),c("p2p")),l(De,c("p2p-websocket-star"),c("p2p")),l(Le,c("p2p-websocket-star")),l(De,c("p2p-websocket-star"))),kr=E(l(Ct,c("p2p-webrtc-direct"),c("p2p")),l(Tt,c("p2p-webrtc-direct"),c("p2p")),l(Ct,c("p2p-webrtc-direct")),l(Tt,c("p2p-webrtc-direct"))),Y=E(It,At,Ct,Tt,Dr,kr,H,No,Uo,K,Pr,Lr),Yc=E(l(Y,c("p2p-stardust"),c("p2p")),l(Y,c("p2p-stardust"))),G=E(l(Y,c("p2p")),Dr,kr,Pr,Lr,c("p2p")),Sr=E(l(G,c("p2p-circuit"),G),l(G,c("p2p-circuit")),l(c("p2p-circuit"),G),l(Y,c("p2p-circuit")),l(c("p2p-circuit"),Y),c("p2p-circuit")),Mr=()=>E(l(Sr,Mr),Sr),X=Mr(),Zc=E(l(X,G,X),l(G,X),l(X,G),X,G);var ea=E(l(X,c("webrtc"),c("p2p")),l(X,c("webrtc")),l(Y,c("webrtc"),c("p2p")),l(Y,c("webrtc")),c("webrtc"));function Nr(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 l(...r){function e(t){if(t.length<r.length)return null;let n=t;return r.some(o=>(n=typeof o=="function"?o().partialMatch(t):o.partialMatch(t),Array.isArray(n)&&(t=n),n===null)),n}return{toString:function(){return"{ "+r.join(" ")+" }"},input:r,matches:Nr(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:Nr(e),partialMatch:e}}function c(r){let e=r;function t(o){let s;try{s=$(o)}catch{return!1}let i=s.protoNames();return i.length===1&&i[0]===e}function n(o){return o.length===0?null:o[0]===e?o.slice(1):null}return{toString:function(){return e},matches:t,partialMatch:n}}var Ne=class extends Event{type;detail;constructor(e,t){super(e),this.type=e,this.detail=t}};var Br=le(F("net"),1);var St=class extends Error{constructor(e){super(e),this.name="TimeoutError"}},Pt=class extends Error{constructor(e){super(),this.name="AbortError",this.message=e}},Ur=r=>globalThis.DOMException===void 0?new Pt(r):new DOMException(r),Fr=r=>{let e=r.reason===void 0?Ur("This operation was aborted."):r.reason;return e instanceof Error?e:Ur(e)};function Lt(r,e){let{milliseconds:t,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout}}=e,i,d=new Promise((h,p)=>{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:m}=e;m.aborted&&p(Fr(m));let u=()=>{p(Fr(m))};m.addEventListener("abort",u,{once:!0}),r.finally(()=>{m.removeEventListener("abort",u)})}if(t===Number.POSITIVE_INFINITY){r.then(h,p);return}let x=new St;i=s.setTimeout.call(void 0,()=>{if(n){try{h(n())}catch(m){p(m)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?h():o instanceof Error?p(o):(x.message=o??`Promise timed out after ${t} milliseconds`,p(x))},t),(async()=>{try{h(await r)}catch(m){p(m)}})()}).finally(()=>{d.clear()});return d.clear=()=>{s.clearTimeout.call(void 0,i),i=void 0},d}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:h,removeListener:p}=Oo(r),x=(...u)=>{let f=t.multiArgs?u:u[0];t.filter&&!t.filter(f)||(d.push(f),t.count===d.length&&(n(),s(d)))},m=u=>{n(),i(u)};n=()=>{for(let u of a)p(u,x);for(let u of t.rejectionEvents)p(u,m)};for(let u of a)h(u,x);for(let u of t.rejectionEvents)h(u,m);t.signal&&t.signal.addEventListener("abort",()=>{m(t.signal.reason)},{once:!0}),t.resolveImmediately&&s(d)});if(o.cancel=n,typeof t.timeout=="number"){let s=Lt(o,{milliseconds:t.timeout});return s.cancel=n,s}return o}function Dt(r,e,t){typeof t=="function"&&(t={filter:t}),t={...t,count:1,resolveImmediately:!1};let n=Vo(r,e,t),o=n.then(s=>s[0]);return o.cancel=n.cancel,o}function $r(r,e){if(typeof r!="string")throw new V(`invalid ip provided: ${r}`);if(typeof e=="string"&&(e=parseInt(e)),isNaN(e))throw new V(`invalid port provided: ${e}`);if((0,N.isIPv4)(r))return $(`/ip4/${r}/tcp/${e}`);if((0,N.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 Mt=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 Mt(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,h)}let d=x=>{try{if(n?.filter?.(x)===!1)return}catch(m){a(),i(m);return}a(),s(x)},h=x=>{a(),i(x.detail)},p=()=>{a(),i(o)};t?.addEventListener("abort",p),r.addEventListener(e,d),n?.errorEvent!=null&&r.addEventListener(n.errorEvent,h)})}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=g=>{n=g,t().catch(b=>{b=new AggregateError([n,b],"The Writable emitted an error, additionally an error occurred while ending the Source")}).finally(()=>{o?.(g)})},i,a=!1,d=()=>{a=!0,i?.()},h,p=!1,x=()=>{p=!0,h?.()},m,u=()=>{m?.()},f=async()=>new Promise((g,b)=>{i=m=g,o=b,r.once("drain",u)}),I=async()=>(await t(),new Promise((g,b)=>{if(a||p||n!=null){g();return}h=i=g,o=b})),T=()=>{r.removeListener("error",s),r.removeListener("close",d),r.removeListener("finish",x),r.removeListener("drain",u)};r.once("error",s),r.once("close",d),r.once("finish",x);try{for await(let g of e){if(!r.writable||r.destroyed||n!=null)break;r.write(g)||await f()}}catch(g){n==null&&r.destroy(g),n=g}try{if(r.writable&&r.end(),await I(),n!=null)throw n}finally{T()}}}function _o(r){return r.return!=null}function Ut(r){return{sink:Vr(r),source:Or(r)}}var Ft=le(F("os"),1),zr=le(F("path"),1);var Ro={ip4:"IPv4",ip6:"IPv6"};function ae(r,e={}){let t=r.getPath();return t!=null?Ft.default.platform()==="win32"?{path:zr.default.join("\\\\.\\pipe\\",t)}:{path:t}:{...e,...r.toOptions()}}function $t(r,e,t){let n=o=>$(`/${r}/${o}/tcp/${t}`);return(jo(e)?Wo(Ro[r]):[e]).map(n)}function jo(r){return["0.0.0.0","::"].includes(r)}var qo=Ft.default.networkInterfaces();function Wo(r){let e=[];for(let[,t]of Object.entries(qo))if(t!=null)for(let n of t)n.family===r&&e.push(n.address);return e}var Ue=(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,h=!1,p=!1;e.listeningAddr?.getPath()!=null&&(e.remoteAddr=e.listeningAddr),e.remoteAddr?.getPath()!=null&&(e.localAddr=e.remoteAddr),r.on("error",g=>{p=!0,h||(n.error("%s socket error - %e",o,g),s?.increment({[`${i}error`]:!0})),r.destroy(),T.timeline.close=Date.now()});let x;if(e.remoteAddr!=null)x=e.remoteAddr;else{if(r.remoteAddress==null||r.remotePort==null)throw new V("Could not determine remote address or port");x=$r(r.remoteAddress,r.remotePort)}let m=ae(x),u=m.path??`${m.host??""}:${m.port??""}`,{sink:f,source:I}=Ut(r);r.setTimeout(a),r.once("timeout",()=>{h=!0,n("%s %s socket read timeout",o,u),s?.increment({[`${i}timeout`]:!0}),r.destroy(new Z),T.timeline.close=Date.now()}),r.once("close",()=>{!h&&!p&&(n("%s %s socket close",o,u),s?.increment({[`${i}close`]:!0})),r.destroy(),T.timeline.close=Date.now()}),r.once("end",()=>{n("%s %s socket end",o,u),s?.increment({[`${i}end`]:!0})});let T={async sink(g){try{await f(async function*(){for await(let b of g)b instanceof Uint8Array?yield b:yield b.subarray()}())}catch(b){b.type!=="aborted"&&n.error("%s %s error in sink - %e",o,u,b)}r.end()},source:I,remoteAddr:x,timeline:{open:Date.now()},async close(g={}){if(r.closed){n("the %s %s socket is already closed",o,u);return}if(r.destroyed){n("the %s %s socket is already destroyed",o,u);return}if(t!=null)return t.promise;try{t=kt(),r.end();let b=Go(r),L=g.signal??AbortSignal.timeout(d);r.writableLength>0&&(n("%s %s draining socket",o,u),await Nt(b,"drain",L,{errorEvent:"error"}),n("%s %s socket drained",o,u)),await Promise.all([Nt(b,"close",L,{errorEvent:"error"}),r.destroy()])}catch(b){this.abort(b)}finally{t.resolve()}},abort:g=>{n("%s %s socket abort due to error - %e",o,u,g),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 Fe=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=Ue(e,{listeningAddr:this.status.listeningAddr,socketInactivityTimeout:this.context.socketInactivityTimeout,socketCloseTimeout:this.context.socketCloseTimeout,metrics:this.metrics?.events,metricPrefix:`${this.addr} `,logger:this.context.logger,direction:"inbound"})}catch(n){this.log.error("inbound connection failed",n),this.metrics?.errors.increment({[`${this.addr} inbound_to_connection`]:!0}),e.destroy();return}this.log("new inbound connection %s",t.remoteAddr),this.sockets.add(e),this.context.upgrader.upgradeInbound(t,{signal:this.shutdownController.signal}).then(()=>{this.log("inbound connection upgraded %s",t.remoteAddr),e.once("close",()=>{this.sockets.delete(e),this.context.closeServerOnMaxConnections!=null&&this.sockets.size<this.context.closeServerOnMaxConnections.listenBelow&&this.resume().catch(n=>{this.log.error("error attempting to listen server once connection count under limit",n),this.context.closeServerOnMaxConnections?.onListenError?.(n)})}),this.context.closeServerOnMaxConnections!=null&&this.sockets.size>=this.context.closeServerOnMaxConnections.closeAbove&&this.pause()}).catch(async n=>{this.log.error("inbound connection upgrade failed",n),this.metrics?.errors.increment({[`${this.addr} inbound_upgrade`]:!0}),this.sockets.delete(e),t.abort(n)})}getAddrs(){if(this.status.code===A.INACTIVE)return[];let e=[],t=this.server.address(),{listeningAddr:n,peerId:o}=this.status;if(t==null)return[];if(typeof t=="string")e=[n];else try{n.toString().startsWith("/ip4")?e=e.concat($t("ip4",t.address,t.port)):t.family==="IPv6"&&(e=e.concat($t("ip6",t.address,t.port)))}catch(s){this.log.error("could not turn %s:%s into multiaddr",t.address,t.port,s)}return e.map(s=>o!=null?s.encapsulate(`/p2p/${o}`):s)}async listen(e){if(this.status.code===A.ACTIVE||this.status.code===A.PAUSED)throw new be("server is already listening");let t=e.getPeerId(),n=t==null?e.decapsulateCode(421):e,{backlog:o}=this.context;try{this.status={code:A.ACTIVE,listeningAddr:n,peerId:t,netConfig:ae(n,{backlog:o})},await this.resume()}catch(s){throw this.status={code:A.INACTIVE},s}}async close(){let e=[];this.server.listening&&e.push(Dt(this.server,"close")),this.pause(!0),this.shutdownController.abort(),this.sockets.forEach(t=>{t.readable&&(e.push(Dt(t,"close")),t.destroy())}),await Promise.all(e)}async resume(){if(this.server.listening||this.status.code===A.INACTIVE)return;let e=this.status.netConfig;await new Promise((t,n)=>{this.server.once("error",n),this.server.listen(e,t)}),this.status={...this.status,code:A.ACTIVE},this.log("listening on %s",this.server.address())}pause(e=!1){if(!this.server.listening&&this.status.code===A.PAUSED&&e){this.status={code:A.INACTIVE};return}!this.server.listening||this.status.code!==A.ACTIVE||(this.log("closing server on %s",this.server.address()),this.status=e?{code:A.INACTIVE}:{...this.status,code:A.PAUSED},this.server.close())}};var $e=class{opts;metrics;components;log;constructor(e,t={}){this.log=e.logger.forComponent("libp2p:tcp"),this.opts=t,this.components=e,e.metrics!=null&&(this.metrics={events:e.metrics.registerCounterGroup("libp2p_tcp_dialer_events_total",{label:"event",help:"Total count of TCP dialer events by type"}),errors:e.metrics.registerCounterGroup("libp2p_tcp_dialer_errors_total",{label:"event",help:"Total count of TCP dialer events by type"})})}[zt]=!0;[Symbol.toStringTag]="@libp2p/tcp";[_t]=["@libp2p/transport"];async dial(e,t){t.keepAlive=t.keepAlive??!0,t.noDelay=t.noDelay??!0;let n=await this._connect(e,t),o;try{o=Ue(n,{remoteAddr:e,socketInactivityTimeout:this.opts.outboundSocketInactivityTimeout,socketCloseTimeout:this.opts.socketCloseTimeout,metrics:this.metrics?.events,logger:this.components.logger,direction:"outbound"})}catch(s){throw this.metrics?.errors.increment({outbound_to_connection:!0}),n.destroy(s),s}try{return this.log("new outbound connection %s",o.remoteAddr),await t.upgrader.upgradeOutbound(o,t)}catch(s){throw this.metrics?.errors.increment({outbound_upgrade:!0}),this.log.error("error upgrading outbound connection",s),o.abort(s),s}}async _connect(e,t){t.signal?.throwIfAborted(),t.onProgress?.(new Ne("tcp:open-connection"));let n;return new Promise((o,s)=>{let i=Date.now(),a=ae(e,{...this.opts.dialOpts??{},...t});this.log("dialing %a",e),n=_r.default.connect(a);let d=u=>{this.log.error("dial to %a errored - %e",e,u);let f=a.path??`${a.host??""}:${a.port}`;u.message=`connection error ${f}: ${u.message}`,this.metrics?.events.increment({error:!0}),m(u)},h=()=>{this.log("connection timeout %a",e),this.metrics?.events.increment({timeout:!0});let u=new Z(`Connection timeout after ${Date.now()-i}ms`);n.emit("error",u)},p=()=>{this.log("connection opened %a",e),this.metrics?.events.increment({connect:!0}),m()},x=()=>{this.log("connection aborted %a",e),this.metrics?.events.increment({abort:!0}),m(new ge)},m=u=>{if(n.removeListener("error",d),n.removeListener("timeout",h),n.removeListener("connect",p),t.signal!=null&&t.signal.removeEventListener("abort",x),u!=null){s(u);return}o(n)};n.on("error",d),n.on("timeout",h),n.on("connect",p),t.signal!=null&&t.signal.addEventListener("abort",x)}).catch(o=>{throw n?.destroy(),o})}createListener(e){return new Fe({...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 $e(e,r)}return Hr(Qo);})();
return Libp2PTcp}));
import { TypedEventEmitter } from '@libp2p/interface';
import type { TCPCreateListenerOptions } from './index.js';
import type { ComponentLogger, Connection, CounterGroup, MetricGroup, Metrics, Listener, ListenerEvents, Upgrader } from '@libp2p/interface';
import type { ComponentLogger, CounterGroup, MetricGroup, Metrics, Listener, ListenerEvents, Upgrader } from '@libp2p/interface';
import type { Multiaddr } from '@multiformats/multiaddr';

@@ -20,3 +20,2 @@ export interface CloseServerOnMaxConnectionsOpts {

interface Context extends TCPCreateListenerOptions {
handler?(conn: Connection): void;
upgrader: Upgrader;

@@ -23,0 +22,0 @@ socketInactivityTimeout?: number;

@@ -145,3 +145,3 @@ import net from 'net';

})
.then((conn) => {
.then(() => {
this.log('inbound connection upgraded %s', maConn.remoteAddr);

@@ -164,5 +164,2 @@ socket.once('close', () => {

});
if (this.context.handler != null) {
this.context.handler(conn);
}
if (this.context.closeServerOnMaxConnections != null &&

@@ -172,3 +169,2 @@ this.sockets.size >= this.context.closeServerOnMaxConnections.closeAbove) {

}
this.safeDispatchEvent('connection', { detail: conn });
})

@@ -175,0 +171,0 @@ .catch(async (err) => {

@@ -1,29 +0,1 @@

/**
* @packageDocumentation
*
* A [libp2p transport](https://docs.libp2p.io/concepts/transports/overview/) based on the TCP networking stack.
*
* @example
*
* ```TypeScript
* import { createLibp2p } from 'libp2p'
* import { tcp } from '@libp2p/tcp'
* import { multiaddr } from '@multiformats/multiaddr'
*
* const node = await createLibp2p({
* transports: [
* tcp()
* ]
* })
*
* const ma = multiaddr('/ip4/123.123.123.123/tcp/1234')
*
* // dial a TCP connection, timing out after 10 seconds
* const connection = await node.dial(ma, {
* signal: AbortSignal.timeout(10_000)
* })
*
* // use connection...
* ```
*/
import { serviceCapabilities, transportSymbol } from '@libp2p/interface';

@@ -30,0 +2,0 @@ import type { TCPDialEvents } from './index.js';

@@ -1,29 +0,1 @@

/**
* @packageDocumentation
*
* A [libp2p transport](https://docs.libp2p.io/concepts/transports/overview/) based on the TCP networking stack.
*
* @example
*
* ```TypeScript
* import { createLibp2p } from 'libp2p'
* import { tcp } from '@libp2p/tcp'
* import { multiaddr } from '@multiformats/multiaddr'
*
* const node = await createLibp2p({
* transports: [
* tcp()
* ]
* })
*
* const ma = multiaddr('/ip4/123.123.123.123/tcp/1234')
*
* // dial a TCP connection, timing out after 10 seconds
* const connection = await node.dial(ma, {
* signal: AbortSignal.timeout(10_000)
* })
*
* // use connection...
* ```
*/
import { serviceCapabilities, transportSymbol } from '@libp2p/interface';

@@ -30,0 +2,0 @@ export class TCP {

{
"name": "@libp2p/tcp",
"version": "10.0.10",
"version": "10.0.11-432955390",
"description": "A TCP transport for libp2p",

@@ -63,4 +63,4 @@ "license": "Apache-2.0 OR MIT",

"dependencies": {
"@libp2p/interface": "^2.1.3",
"@libp2p/utils": "^6.1.2",
"@libp2p/interface": "2.2.0-432955390",
"@libp2p/utils": "6.1.3-432955390",
"@multiformats/mafmt": "^12.1.6",

@@ -76,9 +76,7 @@ "@multiformats/multiaddr": "^12.2.3",

"devDependencies": {
"@libp2p/interface-compliance-tests": "^6.1.7",
"@libp2p/logger": "^5.1.2",
"@libp2p/logger": "5.1.3-432955390",
"aegir": "^44.0.1",
"it-all": "^3.0.6",
"it-pipe": "^3.0.1",
"p-wait-for": "^5.0.2",
"sinon": "^18.0.0",
"uint8arrays": "^5.1.0",
"sinon-ts": "^2.0.0",
"wherearewe": "^2.0.1"

@@ -85,0 +83,0 @@ },

@@ -12,3 +12,3 @@ import net from 'net'

import type { TCPCreateListenerOptions } from './index.js'
import type { ComponentLogger, Logger, MultiaddrConnection, Connection, CounterGroup, MetricGroup, Metrics, Listener, ListenerEvents, Upgrader } from '@libp2p/interface'
import type { ComponentLogger, Logger, MultiaddrConnection, CounterGroup, MetricGroup, Metrics, Listener, ListenerEvents, Upgrader } from '@libp2p/interface'
import type { Multiaddr } from '@multiformats/multiaddr'

@@ -34,3 +34,2 @@

interface Context extends TCPCreateListenerOptions {
handler?(conn: Connection): void
upgrader: Upgrader

@@ -210,3 +209,3 @@ socketInactivityTimeout?: number

})
.then((conn) => {
.then(() => {
this.log('inbound connection upgraded %s', maConn.remoteAddr)

@@ -234,6 +233,2 @@

if (this.context.handler != null) {
this.context.handler(conn)
}
if (

@@ -245,4 +240,2 @@ this.context.closeServerOnMaxConnections != null &&

}
this.safeDispatchEvent('connection', { detail: conn })
})

@@ -249,0 +242,0 @@ .catch(async err => {

@@ -1,30 +0,1 @@

/**
* @packageDocumentation
*
* A [libp2p transport](https://docs.libp2p.io/concepts/transports/overview/) based on the TCP networking stack.
*
* @example
*
* ```TypeScript
* import { createLibp2p } from 'libp2p'
* import { tcp } from '@libp2p/tcp'
* import { multiaddr } from '@multiformats/multiaddr'
*
* const node = await createLibp2p({
* transports: [
* tcp()
* ]
* })
*
* const ma = multiaddr('/ip4/123.123.123.123/tcp/1234')
*
* // dial a TCP connection, timing out after 10 seconds
* const connection = await node.dial(ma, {
* signal: AbortSignal.timeout(10_000)
* })
*
* // use connection...
* ```
*/
import { serviceCapabilities, transportSymbol } from '@libp2p/interface'

@@ -31,0 +2,0 @@ import type { TCPComponents, TCPDialEvents, TCPMetrics, TCPOptions } from './index.js'

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc