@libp2p/tcp 9.1.5-e211b46cc → 9.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.min.js +1 -1
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +1 -161
- package/dist/src/index.js.map +1 -1
- package/dist/src/tcp.browser.d.ts +47 -0
- package/dist/src/tcp.browser.d.ts.map +1 -0
- package/dist/src/tcp.browser.js +56 -0
- package/dist/src/tcp.browser.js.map +1 -0
- package/dist/src/tcp.d.ts +61 -0
- package/dist/src/tcp.d.ts.map +1 -0
- package/dist/src/tcp.js +190 -0
- package/dist/src/tcp.js.map +1 -0
- package/dist/typedoc-urls.json +18 -0
- package/package.json +14 -6
- package/src/index.ts +4 -200
- package/src/tcp.browser.ts +68 -0
- package/src/tcp.ts +230 -0
package/dist/index.min.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PTcp = factory()}(typeof self !== 'undefined' ? self : this, function () {
|
|
2
|
-
"use strict";var Libp2PTcp=(()=>{var Nr=Object.create;var me=Object.defineProperty;var Dr=Object.getOwnPropertyDescriptor;var Mr=Object.getOwnPropertyNames;var _r=Object.getPrototypeOf,Ur=Object.prototype.hasOwnProperty;var L=(r=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(r,{get:(e,t)=>(typeof require<"u"?require:e)[t]}):r)(function(r){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+r+'" is not supported')});var N=(r,e)=>{for(var t in e)me(r,t,{get:e[t],enumerable:!0})},Ct=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Mr(e))!Ur.call(r,o)&&o!==t&&me(r,o,{get:()=>e[o],enumerable:!(n=Dr(e,o))||n.enumerable});return r};var ae=(r,e,t)=>(t=r!=null?Nr(_r(r)):{},Ct(e||!r||!r.__esModule?me(t,"default",{value:r,enumerable:!0}):t,r)),Lr=r=>Ct(me({},"__esModule",{value:!0}),r);var ko={};N(ko,{tcp:()=>Lo});var Rr=ae(L("net"),1);var Tt=Symbol.for("@libp2p/transport");var St;(function(r){r[r.FATAL_ALL=0]="FATAL_ALL",r[r.NO_FATAL=1]="NO_FATAL"})(St||(St={}));var le=class r extends Error{code;type;constructor(e="The operation was aborted"){super(e),this.name="AbortError",this.code=r.code,this.type=r.type}static code="ABORT_ERR";static type="aborted"},A=class extends Error{code;props;constructor(e,t,n){super(e),this.code=t,this.name=n?.name??"CodeError",this.props=n??{}}};var Pt=L("events"),Rt=(r,...e)=>{try{(0,Pt.setMaxListeners)(r,...e)}catch{}};var ge=class extends EventTarget{#e=new Map;constructor(){super(),Rt(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:i})=>i!==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 kr(e,t))}},kr=globalThis.CustomEvent;var Nt=Symbol.for("@libp2p/service-capabilities"),jo=Symbol.for("@libp2p/service-dependencies");var Le={};N(Le,{base58btc:()=>P,base58flickr:()=>Br});var fi=new Uint8Array(0);function Dt(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 Mt(r){return new TextEncoder().encode(r)}function _t(r){return new TextDecoder().decode(r)}function Or(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 i=r.charAt(o),s=i.charCodeAt(0);if(t[s]!==255)throw new TypeError(i+" is ambiguous");t[s]=o}var a=r.length,p=r.charAt(0),w=Math.log(a)/Math.log(256),u=Math.log(256)/Math.log(a);function E(d){if(d instanceof Uint8Array||(ArrayBuffer.isView(d)?d=new Uint8Array(d.buffer,d.byteOffset,d.byteLength):Array.isArray(d)&&(d=Uint8Array.from(d))),!(d instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(d.length===0)return"";for(var g=0,T=0,x=0,v=d.length;x!==v&&d[x]===0;)x++,g++;for(var O=(v-x)*u+1>>>0,D=new Uint8Array(O);x!==v;){for(var F=d[x],j=0,U=O-1;(F!==0||j<T)&&U!==-1;U--,j++)F+=256*D[U]>>>0,D[U]=F%a>>>0,F=F/a>>>0;if(F!==0)throw new Error("Non-zero carry");T=j,x++}for(var $=O-T;$!==O&&D[$]===0;)$++;for(var he=p.repeat(g);$<O;++$)he+=r.charAt(D[$]);return he}function C(d){if(typeof d!="string")throw new TypeError("Expected String");if(d.length===0)return new Uint8Array;var g=0;if(d[g]!==" "){for(var T=0,x=0;d[g]===p;)T++,g++;for(var v=(d.length-g)*w+1>>>0,O=new Uint8Array(v);d[g];){var D=t[d.charCodeAt(g)];if(D===255)return;for(var F=0,j=v-1;(D!==0||F<x)&&j!==-1;j--,F++)D+=a*O[j]>>>0,O[j]=D%256>>>0,D=D/256>>>0;if(D!==0)throw new Error("Non-zero carry");x=F,g++}if(d[g]!==" "){for(var U=v-x;U!==v&&O[U]===0;)U++;for(var $=new Uint8Array(T+(v-U)),he=T;U!==v;)$[he++]=O[U++];return $}}}function f(d){var g=C(d);if(g)return g;throw new Error(`Non-${e} character`)}return{encode:E,decodeUnsafe:C,decode:f}}var Fr=Or,Vr=Fr,Lt=Vr;var De=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")}},Me=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,t,n){if(this.name=e,this.prefix=t,t.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=t.codePointAt(0),this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return kt(this,e)}},_e=class{decoders;constructor(e){this.decoders=e}or(e){return kt(this,e)}decode(e){let t=e[0],n=this.decoders[t];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function kt(r,e){return new _e({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var Ue=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 De(e,t,n),this.decoder=new Me(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function Z({name:r,prefix:e,encode:t,decode:n}){return new Ue(r,e,t,n)}function q({name:r,prefix:e,alphabet:t}){let{encode:n,decode:o}=Lt(t,r);return Z({prefix:e,name:r,encode:n,decode:i=>M(o(i))})}function $r(r,e,t,n){let o={};for(let u=0;u<e.length;++u)o[e[u]]=u;let i=r.length;for(;r[i-1]==="=";)--i;let s=new Uint8Array(i*t/8|0),a=0,p=0,w=0;for(let u=0;u<i;++u){let E=o[r[u]];if(E===void 0)throw new SyntaxError(`Non-${n} character`);p=p<<t|E,a+=t,a>=8&&(a-=8,s[w++]=255&p>>a)}if(a>=t||255&p<<8-a)throw new SyntaxError("Unexpected end of data");return s}function zr(r,e,t){let n=e[e.length-1]==="=",o=(1<<t)-1,i="",s=0,a=0;for(let p=0;p<r.length;++p)for(a=a<<8|r[p],s+=8;s>t;)s-=t,i+=e[o&a>>s];if(s!==0&&(i+=e[o&a<<t-s]),n)for(;i.length*t&7;)i+="=";return i}function b({name:r,prefix:e,bitsPerChar:t,alphabet:n}){return Z({prefix:e,name:r,encode(o){return zr(o,n,t)},decode(o){return $r(o,n,t,r)}})}var P=q({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Br=q({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var ke={};N(ke,{base32:()=>z,base32hex:()=>Wr,base32hexpad:()=>Xr,base32hexpadupper:()=>Jr,base32hexupper:()=>Hr,base32pad:()=>qr,base32padupper:()=>Gr,base32upper:()=>jr,base32z:()=>Qr});var z=b({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),jr=b({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),qr=b({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Gr=b({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Wr=b({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Hr=b({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Xr=b({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Jr=b({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Qr=b({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Kr=Vt,Ot=128,Yr=127,Zr=~Yr,en=Math.pow(2,31);function Vt(r,e,t){e=e||[],t=t||0;for(var n=t;r>=en;)e[t++]=r&255|Ot,r/=128;for(;r&Zr;)e[t++]=r&255|Ot,r>>>=7;return e[t]=r|0,Vt.bytes=t-n+1,e}var tn=Oe,rn=128,Ft=127;function Oe(r,n){var t=0,n=n||0,o=0,i=n,s,a=r.length;do{if(i>=a)throw Oe.bytes=0,new RangeError("Could not decode varint");s=r[i++],t+=o<28?(s&Ft)<<o:(s&Ft)*Math.pow(2,o),o+=7}while(s>=rn);return Oe.bytes=i-n,t}var nn=Math.pow(2,7),on=Math.pow(2,14),sn=Math.pow(2,21),cn=Math.pow(2,28),an=Math.pow(2,35),ln=Math.pow(2,42),dn=Math.pow(2,49),un=Math.pow(2,56),pn=Math.pow(2,63),fn=function(r){return r<nn?1:r<on?2:r<sn?3:r<cn?4:r<an?5:r<ln?6:r<dn?7:r<un?8:r<pn?9:10},hn={encode:Kr,decode:tn,encodingLength:fn},mn=hn,de=mn;function ue(r,e=0){return[de.decode(r,e),de.decode.bytes]}function ee(r,e,t=0){return de.encode(r,e,t),e}function te(r){return de.encodingLength(r)}function X(r,e){let t=e.byteLength,n=te(r),o=n+te(t),i=new Uint8Array(o+t);return ee(r,i,0),ee(t,i,n),i.set(e,o),new re(r,t,e,i)}function we(r){let e=M(r),[t,n]=ue(e),[o,i]=ue(e.subarray(n)),s=e.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new re(t,o,s,e)}function $t(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&Dt(r.bytes,t.bytes)}}var re=class{code;size;digest;bytes;constructor(e,t,n,o){this.code=e,this.size=t,this.digest=n,this.bytes=o}};function zt(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return xn(t,Fe(r),e??P.encoder);default:return wn(t,Fe(r),e??z.encoder)}}var Bt=new WeakMap;function Fe(r){let e=Bt.get(r);if(e==null){let t=new Map;return Bt.set(r,t),t}return e}var G=class r{code;version;multihash;bytes;"/";constructor(e,t,n,o){this.code=t,this.version=e,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:t}=this;if(e!==pe)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==bn)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(t)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:e,digest:t}=this.multihash,n=X(e,t);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(e){return r.equals(this,e)}static equals(e,t){let n=t;return n!=null&&e.code===n.code&&e.version===n.version&&$t(e.multihash,n.multihash)}toString(e){return zt(this,e)}toJSON(){return{"/":zt(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let t=e;if(t instanceof r)return t;if(t["/"]!=null&&t["/"]===t.bytes||t.asCID===t){let{version:n,code:o,multihash:i,bytes:s}=t;return new r(n,o,i,s??jt(n,o,i.bytes))}else if(t[yn]===!0){let{version:n,multihash:o,code:i}=t,s=we(o);return r.create(n,i,s)}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!==pe)throw new Error(`Version 0 CID must use dag-pb (code: ${pe}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let o=jt(e,t,n.bytes);return new r(e,t,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,pe,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 i=o.subarray(t.multihashSize-t.digestSize),s=new re(t.multihashCode,t.digestSize,i,o);return[t.version===0?r.createV0(s):r.createV1(t.codec,s),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[E,C]=ue(e.subarray(t));return t+=C,E},o=n(),i=pe;if(o===18?(o=0,t=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let s=t,a=n(),p=n(),w=t+p,u=w-s;return{version:o,codec:i,multihashCode:a,digestSize:p,multihashSize:u,size:w}}static parse(e,t){let[n,o]=gn(e,t),i=r.decode(o);if(i.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Fe(i).set(n,e),i}};function gn(r,e){switch(r[0]){case"Q":{let t=e??P;return[P.prefix,t.decode(`${P.prefix}${r}`)]}case P.prefix:{let t=e??P;return[P.prefix,t.decode(r)]}case z.prefix:{let t=e??z;return[z.prefix,t.decode(r)]}default:{if(e==null)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[r[0],e.decode(r)]}}}function xn(r,e,t){let{prefix:n}=t;if(n!==P.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let o=e.get(n);if(o==null){let i=t.encode(r).slice(1);return e.set(n,i),i}else return o}function wn(r,e,t){let{prefix:n}=t,o=e.get(n);if(o==null){let i=t.encode(r);return e.set(n,i),i}else return o}var pe=112,bn=18;function jt(r,e,t){let n=te(r),o=n+te(e),i=new Uint8Array(o+t.byteLength);return ee(r,i,0),ee(e,i,n),i.set(t,o),i}var yn=Symbol.for("@ipld/js-cid/CID");function qt(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 Yt=L("node:buffer");var Ve={};N(Ve,{base10:()=>vn});var vn=q({prefix:"9",name:"base10",alphabet:"0123456789"});var $e={};N($e,{base16:()=>En,base16upper:()=>An});var En=b({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),An=b({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var ze={};N(ze,{base2:()=>In});var In=b({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Be={};N(Be,{base256emoji:()=>Rn});var Gt=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}"),Cn=Gt.reduce((r,e,t)=>(r[t]=e,r),[]),Sn=Gt.reduce((r,e,t)=>(r[e.codePointAt(0)]=t,r),[]);function Tn(r){return r.reduce((e,t)=>(e+=Cn[t],e),"")}function Pn(r){let e=[];for(let t of r){let n=Sn[t.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${t}`);e.push(n)}return new Uint8Array(e)}var Rn=Z({prefix:"\u{1F680}",name:"base256emoji",encode:Tn,decode:Pn});var je={};N(je,{base36:()=>Nn,base36upper:()=>Dn});var Nn=q({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Dn=q({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var qe={};N(qe,{base64:()=>Mn,base64pad:()=>_n,base64url:()=>Un,base64urlpad:()=>Ln});var Mn=b({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),_n=b({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Un=b({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Ln=b({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Ge={};N(Ge,{base8:()=>kn});var kn=b({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var We={};N(We,{identity:()=>On});var On=Z({prefix:"\0",name:"identity",encode:r=>_t(r),decode:r=>Mt(r)});var Fi=new TextEncoder,Vi=new TextDecoder;var He={};N(He,{identity:()=>Bn});var Wt=0,$n="identity",Ht=M;function zn(r){return X(Wt,Ht(r))}var Bn={code:Wt,name:$n,encode:Ht,digest:zn};var Ke={};N(Ke,{sha256:()=>jn,sha512:()=>qn});var Qe=ae(L("crypto"),1);function Je({name:r,code:e,encode:t}){return new Xe(r,e,t)}var Xe=class{name;code;encode;constructor(e,t,n){this.name=e,this.code=t,this.encode=n}digest(e){if(e instanceof Uint8Array){let t=this.encode(e);return t instanceof Uint8Array?X(this.code,t):t.then(n=>X(this.code,n))}else throw Error("Unknown type, must be binary type")}};var jn=Je({name:"sha2-256",code:18,encode:r=>M(Qe.default.createHash("sha256").update(r).digest())}),qn=Je({name:"sha2-512",code:19,encode:r=>M(Qe.default.createHash("sha512").update(r).digest())});var fe={...We,...ze,...Ge,...Ve,...$e,...ke,...je,...Le,...qe,...Be},Zi={...Ke,...He};var Jt=L("node:buffer");function oe(r){return new Uint8Array(r.buffer,r.byteOffset,r.byteLength)}function be(r=0){return oe(Jt.Buffer.allocUnsafe(r))}function Kt(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var Qt=Kt("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Ye=Kt("ascii","a",r=>{let e="a";for(let t=0;t<r.length;t++)e+=String.fromCharCode(r[t]);return e},r=>{r=r.substring(1);let e=be(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),Gn={utf8:Qt,"utf-8":Qt,hex:fe.base16,latin1:Ye,ascii:Ye,binary:Ye,...fe},ye=Gn;function R(r,e="utf8"){let t=ye[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return e==="utf8"||e==="utf-8"?Yt.Buffer.from(r.buffer,r.byteOffset,r.byteLength).toString("utf8"):t.encoder.encode(r).substring(1)}var Wn=Math.pow(2,7),Hn=Math.pow(2,14),Xn=Math.pow(2,21),Ze=Math.pow(2,28),et=Math.pow(2,35),tt=Math.pow(2,42),rt=Math.pow(2,49),h=128,S=127;function V(r){if(r<Wn)return 1;if(r<Hn)return 2;if(r<Xn)return 3;if(r<Ze)return 4;if(r<et)return 5;if(r<tt)return 6;if(r<rt)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Jn(r,e,t=0){switch(V(r)){case 8:e[t++]=r&255|h,r/=128;case 7:e[t++]=r&255|h,r/=128;case 6:e[t++]=r&255|h,r/=128;case 5:e[t++]=r&255|h,r/=128;case 4:e[t++]=r&255|h,r>>>=7;case 3:e[t++]=r&255|h,r>>>=7;case 2:e[t++]=r&255|h,r>>>=7;case 1:{e[t++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return e}function Qn(r,e,t=0){switch(V(r)){case 8:e.set(t++,r&255|h),r/=128;case 7:e.set(t++,r&255|h),r/=128;case 6:e.set(t++,r&255|h),r/=128;case 5:e.set(t++,r&255|h),r/=128;case 4:e.set(t++,r&255|h),r>>>=7;case 3:e.set(t++,r&255|h),r>>>=7;case 2:e.set(t++,r&255|h),r>>>=7;case 1:{e.set(t++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return e}function Kn(r,e){let t=r[e],n=0;if(n+=t&S,t<h||(t=r[e+1],n+=(t&S)<<7,t<h)||(t=r[e+2],n+=(t&S)<<14,t<h)||(t=r[e+3],n+=(t&S)<<21,t<h)||(t=r[e+4],n+=(t&S)*Ze,t<h)||(t=r[e+5],n+=(t&S)*et,t<h)||(t=r[e+6],n+=(t&S)*tt,t<h)||(t=r[e+7],n+=(t&S)*rt,t<h))return n;throw new RangeError("Could not decode varint")}function Yn(r,e){let t=r.get(e),n=0;if(n+=t&S,t<h||(t=r.get(e+1),n+=(t&S)<<7,t<h)||(t=r.get(e+2),n+=(t&S)<<14,t<h)||(t=r.get(e+3),n+=(t&S)<<21,t<h)||(t=r.get(e+4),n+=(t&S)*Ze,t<h)||(t=r.get(e+5),n+=(t&S)*et,t<h)||(t=r.get(e+6),n+=(t&S)*tt,t<h)||(t=r.get(e+7),n+=(t&S)*rt,t<h))return n;throw new RangeError("Could not decode varint")}function ie(r,e,t=0){return e==null&&(e=be(V(r))),e instanceof Uint8Array?Jn(r,e,t):Qn(r,e,t)}function J(r,e=0){return r instanceof Uint8Array?Kn(r,e):Yn(r,e)}var er=L("node:buffer");function B(r,e){return oe(er.Buffer.concat(r,e))}var ve=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 i=0,s=0,a=this.peekChar();if(a===void 0)return;let p=a==="0",w=2**(8*o)-1;for(;;){let u=this.readAtomically(()=>{let E=this.readChar();if(E===void 0)return;let C=Number.parseInt(E,e);if(!Number.isNaN(C))return C});if(u===void 0)break;if(i*=e,i+=u,i>w||(s+=1,t!==void 0&&s>t))return}if(s!==0)return!n&&p&&s>1?void 0:i})}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 s=this.readSeparator(":",n,()=>this.readIPv4Addr());if(s!==void 0)return t[o]=s[0],t[o+1]=s[1],t[o+2]=s[2],t[o+3]=s[3],[o+4,!0]}let i=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(i===void 0)return[o,!1];t[o]=i>>8,t[o+1]=i&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 i=new Uint8Array(14),s=16-(n+2),[a]=e(i.subarray(0,s));return t.set(i.subarray(0,a),16-a),t})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var hs=new ve;var Es=parseInt("0xFFFF",16),As=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);var nr=L("node:buffer");function nt(r,e="utf8"){let t=ye[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return e==="utf8"||e==="utf-8"?oe(nr.Buffer.from(r,"utf-8")):t.decoder.decode(`${t.prefix}${r}`)}var _=L("node:net");function Ee(r){return!!(0,_.isIP)(r)}var or=_.isIPv4,oo=_.isIPv6,ot=function(r){let e=0;if(r=r.toString().trim(),or(r)){let t=new Uint8Array(e+4);return r.split(/\./g).forEach(n=>{t[e++]=parseInt(n,10)&255}),t}if(oo(r)){let t=r.split(":",8),n;for(n=0;n<t.length;n++){let i=or(t[n]),s;i&&(s=ot(t[n]),t[n]=R(s.slice(0,2),"base16")),s!=null&&++n<8&&t.splice(n,0,R(s.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 i=[n,1];for(n=9-t.length;n>0;n--)i.push("0");t.splice.apply(t,i)}let o=new Uint8Array(e+16);for(n=0;n<t.length;n++){let i=parseInt(t[n],16);o[e++]=i>>8&255,o[e++]=i&255}return o}throw new Error("invalid ip address")},ir=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 i=0;i<t;i++)o.push(r[e+i]);return o.join(".")}if(t===16){let o=[];for(let i=0;i<t;i+=2)o.push(n.getUint16(e+i).toString(16));return o.join(":").replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}return""};var se={},it={},so=[[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"]];so.forEach(r=>{let e=co(...r);it[e.code]=e,se[e.name]=e});function co(r,e,t,n,o){return{code:r,size:e,name:t,resolvable:!!n,path:!!o}}function m(r){if(typeof r=="number"){if(it[r]!=null)return it[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(se[r]!=null)return se[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var dc=m("ip4"),uc=m("ip6"),pc=m("ipcidr");function lt(r,e){switch(m(r).code){case 4:case 41:return lo(e);case 42:return at(e);case 6:case 273:case 33:case 132:return ar(e).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return at(e);case 421:return ho(e);case 444:return cr(e);case 445:return cr(e);case 466:return fo(e);case 481:return globalThis.encodeURIComponent(at(e));default:return R(e,"base16")}}function dt(r,e){switch(m(r).code){case 4:return sr(e);case 41:return sr(e);case 42:return ct(e);case 6:case 273:case 33:case 132:return ut(parseInt(e,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return ct(e);case 421:return uo(e);case 444:return mo(e);case 445:return go(e);case 466:return po(e);case 481:return ct(globalThis.decodeURIComponent(e));default:return nt(e,"base16")}}var st=Object.values(fe).map(r=>r.decoder),ao=function(){let r=st[0].or(st[1]);return st.slice(2).forEach(e=>r=r.or(e)),r}();function sr(r){if(!Ee(r))throw new Error("invalid ip address");return ot(r)}function lo(r){let e=ir(r,0,r.length);if(e==null)throw new Error("ipBuff is required");if(!Ee(e))throw new Error("invalid ip address");return e}function ut(r){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,r),new Uint8Array(e)}function ar(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function ct(r){let e=nt(r),t=Uint8Array.from(ie(e.length));return B([t,e],t.length+e.length)}function at(r){let e=J(r);if(r=r.slice(V(e)),r.length!==e)throw new Error("inconsistent lengths");return R(r)}function uo(r){let e;r[0]==="Q"||r[0]==="1"?e=we(P.decode(`z${r}`)).bytes:e=G.parse(r).multihash.bytes;let t=Uint8Array.from(ie(e.length));return B([t,e],t.length+e.length)}function po(r){let e=ao.decode(r),t=Uint8Array.from(ie(e.length));return B([t,e],t.length+e.length)}function fo(r){let e=J(r),t=r.slice(V(e));if(t.length!==e)throw new Error("inconsistent lengths");return"u"+R(t,"base64url")}function ho(r){let e=J(r),t=r.slice(V(e));if(t.length!==e)throw new Error("inconsistent lengths");return R(t,"base58btc")}function mo(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=z.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=ut(n);return B([t,o],t.length+o.length)}function go(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=z.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=ut(n);return B([t,o],t.length+o.length)}function cr(r){let e=r.slice(0,r.length-2),t=r.slice(r.length-2),n=R(e,"base32"),o=ar(t);return`${n}:${o}`}function lr(r){r=pt(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 i=0;i<o.length;i++){let s=o[i],a=m(s);if(a.size===0){e.push([a.code]),t.push([a.code]);continue}if(i++,i>=o.length)throw ur("invalid address: "+r);if(a.path===!0){n=pt(o.slice(i).join("/")),e.push([a.code,dt(a.code,n)]),t.push([a.code,n]);break}let p=dt(a.code,o[i]);e.push([a.code,p]),t.push([a.code,lt(a.code,p)])}return{string:dr(t),bytes:ht(e),tuples:e,stringTuples:t,path:n}}function ft(r){let e=[],t=[],n=null,o=0;for(;o<r.length;){let i=J(r,o),s=V(i),a=m(i),p=xo(a,r.slice(o+s));if(p===0){e.push([i]),t.push([i]),o+=s;continue}let w=r.slice(o+s,o+s+p);if(o+=p+s,o>r.length)throw ur("Invalid address Uint8Array: "+R(r,"base16"));e.push([i,w]);let u=lt(i,w);if(t.push([i,u]),a.path===!0){n=u;break}}return{bytes:Uint8Array.from(r),string:dr(t),tuples:e,stringTuples:t,path:n}}function dr(r){let e=[];return r.map(t=>{let n=m(t[0]);return e.push(n.name),t.length>1&&t[1]!=null&&e.push(t[1]),null}),pt(e.join("/"))}function ht(r){return B(r.map(e=>{let t=m(e[0]),n=Uint8Array.from(ie(t.code));return e.length>1&&e[1]!=null&&(n=B([n,e[1]])),n}))}function xo(r,e){if(r.size>0)return r.size/8;if(r.size===0)return 0;{let t=J(e instanceof Uint8Array?e:Uint8Array.from(e));return t+V(t)}}function pt(r){return"/"+r.trim().split("/").filter(e=>e).join("/")}function ur(r){return new Error("Error parsing address: "+r)}var wo=Symbol.for("nodejs.util.inspect.custom"),mt=Symbol.for("@multiformats/js-multiaddr/multiaddr"),bo=[m("dns").code,m("dns4").code,m("dns6").code,m("dnsaddr").code],Ae=class r{bytes;#e;#t;#r;#n;[mt]=!0;constructor(e){e==null&&(e="");let t;if(e instanceof Uint8Array)t=ft(e);else if(typeof e=="string"){if(e.length>0&&e.charAt(0)!=="/")throw new Error(`multiaddr "${e}" must start with a "/"`);t=lr(e)}else if(fr(e))t=ft(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,i="",s=m("tcp"),a=m("udp"),p=m("ip4"),w=m("ip6"),u=m("dns6"),E=m("ip6zone");for(let[f,d]of this.stringTuples())f===E.code&&(i=`%${d??""}`),bo.includes(f)&&(t=s.name,o=443,n=`${d??""}${i}`,e=f===u.code?6:4),(f===s.code||f===a.code)&&(t=m(f).name,o=parseInt(d??"")),(f===p.code||f===w.code)&&(t=m(f).name,n=`${d??""}${i}`,e=f===w.code?6:4);if(e==null||t==null||n==null||o==null)throw new Error('multiaddr must have a valid format: "/{ip4, ip6, dns4, dns6, dnsaddr}/{address}/{tcp, udp}/{port}".');return{family:e,host:n,transport:t,port:o}}protos(){return this.#t.map(([e])=>Object.assign({},m(e)))}protoCodes(){return this.#t.map(([e])=>e)}protoNames(){return this.#t.map(([e])=>m(e).name)}tuples(){return this.#t}stringTuples(){return this.#r}encapsulate(e){return e=new r(e),new r(this.toString()+e.toString())}decapsulate(e){let t=e.toString(),n=this.toString(),o=n.lastIndexOf(t);if(o<0)throw new Error(`Address ${this.toString()} does not contain subaddress: ${e.toString()}`);return new r(n.slice(0,o))}decapsulateCode(e){let t=this.tuples();for(let n=t.length-1;n>=0;n--)if(t[n][0]===e)return new r(ht(t.slice(0,n)));return this}getPeerId(){try{let e=[];this.stringTuples().forEach(([n,o])=>{n===se.p2p.code&&e.push([n,o]),n===se["p2p-circuit"].code&&(e=[])});let t=e.pop();if(t?.[1]!=null){let n=t[1];return n[0]==="Q"||n[0]==="1"?R(P.decode(`z${n}`),"base58btc"):R(G.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){return this.#n}equals(e){return qt(this.bytes,e.bytes)}async resolve(e){let t=this.protos().find(i=>i.resolvable);if(t==null)return[this];let n=pr.get(t.name);if(n==null)throw new A(`no available resolver for ${t.name}`,"ERR_NO_AVAILABLE_RESOLVER");return(await n(this,e)).map(i=>k(i))}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)}[wo](){return`Multiaddr(${this.#e})`}};var pr=new Map;function fr(r){return!!r?.[mt]}function k(r){return new Ae(r)}var yo=c("dns4"),vo=c("dns6"),Eo=c("dnsaddr"),K=y(c("dns"),Eo,yo,vo),Se=y(c("ip4"),c("ip6")),H=y(l(Se,c("tcp")),l(K,c("tcp"))),Te=l(Se,c("udp")),Ao=l(Te,c("utp")),Io=l(Te,c("quic")),Co=l(Te,c("quic-v1")),gt=y(l(H,c("ws")),l(K,c("ws"))),Ie=y(l(gt,c("p2p")),gt),xt=y(l(H,c("wss")),l(K,c("wss")),l(H,c("tls"),c("ws")),l(K,c("tls"),c("ws"))),Ce=y(l(xt,c("p2p")),xt),wt=y(l(H,c("http")),l(Se,c("http")),l(K,c("http"))),bt=y(l(H,c("https")),l(Se,c("https")),l(K,c("https"))),hr=l(Te,c("webrtc-direct"),c("certhash")),xr=y(l(hr,c("p2p")),hr),mr=l(Co,c("webtransport"),c("certhash"),c("certhash")),wr=y(l(mr,c("p2p")),mr),br=y(l(Ie,c("p2p-webrtc-star"),c("p2p")),l(Ce,c("p2p-webrtc-star"),c("p2p")),l(Ie,c("p2p-webrtc-star")),l(Ce,c("p2p-webrtc-star"))),Fc=y(l(Ie,c("p2p-websocket-star"),c("p2p")),l(Ce,c("p2p-websocket-star"),c("p2p")),l(Ie,c("p2p-websocket-star")),l(Ce,c("p2p-websocket-star"))),yr=y(l(wt,c("p2p-webrtc-direct"),c("p2p")),l(bt,c("p2p-webrtc-direct"),c("p2p")),l(wt,c("p2p-webrtc-direct")),l(bt,c("p2p-webrtc-direct"))),Y=y(gt,xt,wt,bt,br,yr,H,Ao,Io,K,xr,wr),Vc=y(l(Y,c("p2p-stardust"),c("p2p")),l(Y,c("p2p-stardust"))),W=y(l(Y,c("p2p")),br,yr,xr,wr,c("p2p")),gr=y(l(W,c("p2p-circuit"),W),l(W,c("p2p-circuit")),l(c("p2p-circuit"),W),l(Y,c("p2p-circuit")),l(c("p2p-circuit"),Y),c("p2p-circuit")),vr=()=>y(l(gr,vr),gr),Q=vr(),$c=y(l(Q,W,Q),l(W,Q),l(Q,W),Q,W);var zc=y(l(Q,c("webrtc"),c("p2p")),l(Q,c("webrtc")),l(Y,c("webrtc"),c("p2p")),l(Y,c("webrtc")),c("webrtc"));function Er(r){function e(t){let n;try{n=k(t)}catch{return!1}let o=r(n.protoNames());return o===null?!1:o===!0||o===!1?o:o.length===0}return e}function l(...r){function e(t){if(t.length<r.length)return null;let n=t;return r.some(o=>(n=typeof o=="function"?o().partialMatch(t):o.partialMatch(t),Array.isArray(n)&&(t=n),n===null)),n}return{toString:function(){return"{ "+r.join(" ")+" }"},input:r,matches:Er(e),partialMatch:e}}function y(...r){function e(n){let o=null;return r.some(i=>{let s=typeof i=="function"?i().partialMatch(n):i.partialMatch(n);return s!=null?(o=s,!0):!1}),o}return{toString:function(){return"{ "+r.join(" ")+" }"},input:r,matches:Er(e),partialMatch:e}}function c(r){let e=r;function t(o){let i;try{i=k(o)}catch{return!1}let s=i.protoNames();return s.length===1&&s[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 Pe=class extends Event{type;detail;constructor(e,t){super(e),this.type=e,this.detail=t}};var Pr=ae(L("net"),1);var yt={ERR_INVALID_IP_PARAMETER:"ERR_INVALID_IP_PARAMETER",ERR_INVALID_PORT_PARAMETER:"ERR_INVALID_PORT_PARAMETER",ERR_INVALID_IP:"ERR_INVALID_IP"};function Ar(r,e){if(typeof r!="string")throw new A(`invalid ip provided: ${r}`,yt.ERR_INVALID_IP_PARAMETER);if(typeof e=="string"&&(e=parseInt(e)),isNaN(e))throw new A(`invalid port provided: ${e}`,yt.ERR_INVALID_PORT_PARAMETER);if((0,_.isIPv4)(r))return k(`/ip4/${r}/tcp/${e}`);if((0,_.isIPv6)(r))return k(`/ip6/${r}/tcp/${e}`);throw new A(`invalid ip:port for creating a multiaddr: ${r}:${e}`,yt.ERR_INVALID_IP)}function Ir(r){if(Po(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(To(r))return r;throw new Error("unknown stream")}function To(r){return r[Symbol.asyncIterator]!=null}function Po(r){return typeof r?.getReader=="function"}function Cr(r){return async e=>{let t=async()=>{Ro(e)&&await e.return(void 0)},n,o,i=x=>{n=x,t().catch(v=>{v=new AggregateError([n,v],"The Writable emitted an error, additionally an error occurred while ending the Source")}).finally(()=>{o?.(x)})},s,a=!1,p=()=>{a=!0,s?.()},w,u=!1,E=()=>{u=!0,w?.()},C,f=()=>{C?.()},d=async()=>new Promise((x,v)=>{s=C=x,o=v,r.once("drain",f)}),g=async()=>(await t(),new Promise((x,v)=>{if(a||u||n!=null){x();return}w=s=x,o=v})),T=()=>{r.removeListener("error",i),r.removeListener("close",p),r.removeListener("finish",E),r.removeListener("drain",f)};r.once("error",i),r.once("close",p),r.once("finish",E);try{for await(let x of e){if(!r.writable||r.destroyed||n!=null)break;r.write(x)||await d()}}catch(x){n==null&&r.destroy(x),n=x}try{if(r.writable&&r.end(),await g(),n!=null)throw n}finally{T()}}}function Ro(r){return r.return!=null}function vt(r){return{sink:Cr(r),source:Ir(r)}}var Et=ae(L("os"),1),Sr=ae(L("path"),1);var No={ip4:"IPv4",ip6:"IPv6"};function ce(r,e={}){let t=r.getPath();return t!=null?Et.default.platform()==="win32"?{path:Sr.default.join("\\\\.\\pipe\\",t)}:{path:t}:{...e,...r.toOptions()}}function At(r,e,t){let n=o=>k(`/${r}/${o}/tcp/${t}`);return(Do(e)?_o(No[r]):[e]).map(n)}function Do(r){return["0.0.0.0","::"].includes(r)}var Mo=Et.default.networkInterfaces();function _o(r){let e=[];for(let[,t]of Object.entries(Mo))if(t!=null)for(let n of t)n.family===r&&e.push(n.address);return e}var Re=(r,e)=>{let t=null,n=e.logger.forComponent("libp2p:tcp:socket"),o=e.metrics,i=e.metricPrefix??"",s=e.socketInactivityTimeout??3e5,a=e.socketCloseTimeout??500;e.listeningAddr?.getPath()!=null&&(e.remoteAddr=e.listeningAddr),e.remoteAddr?.getPath()!=null&&(e.localAddr=e.remoteAddr);let p;if(e.remoteAddr!=null)p=e.remoteAddr;else{if(r.remoteAddress==null||r.remotePort==null)throw new A("Could not determine remote address or port","ERR_NO_REMOTE_ADDRESS");p=Ar(r.remoteAddress,r.remotePort)}let w=ce(p),u=w.path??`${w.host??""}:${w.port??""}`,{sink:E,source:C}=vt(r);r.setTimeout(s,()=>{n("%s socket read timeout",u),o?.increment({[`${i}timeout`]:!0});let d;r.readable&&(d=new A("Socket read timeout","ERR_SOCKET_READ_TIMEOUT")),r.destroy(d)}),r.once("close",()=>{n("%s socket close",u),o?.increment({[`${i}close`]:!0}),f.timeline.close==null&&(f.timeline.close=Date.now())}),r.once("end",()=>{n("%s socket end",u),o?.increment({[`${i}end`]:!0})});let f={async sink(d){try{await E(async function*(){for await(let g of d)g instanceof Uint8Array?yield g:yield g.subarray()}())}catch(g){g.type!=="aborted"&&n.error("%s error in sink",u,g)}r.end()},source:C,remoteAddr:p,timeline:{open:Date.now()},async close(d={}){if(r.destroyed){n("The %s socket is destroyed",u);return}if(t!=null)return n("The %s socket is closed or closing",u),t;if(d.signal==null){let T=AbortSignal.timeout(a);d={...d,signal:T}}let g=()=>{r.destroy(new A("Destroying socket after timeout","ERR_CLOSE_TIMEOUT"))};d.signal?.addEventListener("abort",g);try{n("%s closing socket",u),t=new Promise((T,x)=>{r.once("close",()=>{n("%s socket closed",u),T()}),r.once("error",v=>{n("%s socket error",u,v),f.timeline.close==null&&(f.timeline.close=Date.now()),r.destroyed||x(v)}),r.setTimeout(a),r.end(),r.writableLength>0?r.once("drain",()=>{n("%s socket drained",u),r.destroy()}):r.destroy()}),await t}catch(T){this.abort(T)}finally{d.signal?.removeEventListener("abort",g)}},abort:d=>{n("%s socket abort due to error",u,d),r.destroyed||r.destroy(d),f.timeline.close==null&&(f.timeline.close=Date.now())},log:n};return f};async function Tr(r,e){try{await r.close()}catch(t){e.log.error("an error occurred closing the connection",t),r.abort(t)}}var I;(function(r){r[r.INACTIVE=0]="INACTIVE",r[r.ACTIVE=1]="ACTIVE",r[r.PAUSED=2]="PAUSED"})(I||(I={}));var Ne=class extends ge{context;server;connections=new Set;status={code:I.INACTIVE};metrics;addr;log;constructor(e){if(super(),this.context=e,e.keepAlive=e.keepAlive??!0,e.noDelay=e.noDelay??!0,this.log=e.logger.forComponent("libp2p:tcp:listener"),this.addr="unknown",this.server=Pr.default.createServer(e,this.onSocket.bind(this)),e.maxConnections!==void 0&&(this.server.maxConnections=e.maxConnections),e.closeServerOnMaxConnections!=null&&e.closeServerOnMaxConnections.closeAbove<e.closeServerOnMaxConnections.listenBelow)throw new A("closeAbove must be >= listenBelow","ERR_CONNECTION_LIMITS");this.server.on("listening",()=>{if(e.metrics!=null){let t=this.server.address();t==null?this.addr="unknown":typeof t=="string"?this.addr=t:this.addr=`${t.address}:${t.port}`,e.metrics?.registerMetricGroup("libp2p_tcp_inbound_connections_total",{label:"address",help:"Current active connections in TCP listener",calculate:()=>({[this.addr]:this.connections.size})}),this.metrics={status:e.metrics.registerMetricGroup("libp2p_tcp_listener_status_info",{label:"address",help:"Current status of the TCP listener socket"}),errors:e.metrics.registerMetricGroup("libp2p_tcp_listener_errors_total",{label:"address",help:"Total count of TCP listener errors by type"}),events:e.metrics.registerMetricGroup("libp2p_tcp_listener_events_total",{label:"address",help:"Total count of TCP listener events by type"})},this.metrics?.status.update({[this.addr]:I.ACTIVE})}this.safeDispatchEvent("listening")}).on("error",t=>{this.metrics?.errors.increment({[`${this.addr} listen_error`]:!0}),this.safeDispatchEvent("error",{detail:t})}).on("close",()=>{this.metrics?.status.update({[this.addr]:this.status.code}),this.status.code!==I.PAUSED&&this.safeDispatchEvent("close")})}onSocket(e){if(this.status.code!==I.ACTIVE)throw new A("Server is not listening yet","ERR_SERVER_NOT_RUNNING");e.on("error",n=>{this.log("socket error",n),this.metrics?.events.increment({[`${this.addr} error`]:!0})});let t;try{t=Re(e,{listeningAddr:this.status.listeningAddr,socketInactivityTimeout:this.context.socketInactivityTimeout,socketCloseTimeout:this.context.socketCloseTimeout,metrics:this.metrics?.events,metricPrefix:`${this.addr} `,logger:this.context.logger})}catch(n){this.log.error("inbound connection failed",n),this.metrics?.errors.increment({[`${this.addr} inbound_to_connection`]:!0});return}this.log("new inbound connection %s",t.remoteAddr);try{this.context.upgrader.upgradeInbound(t).then(n=>{this.log("inbound connection upgraded %s",t.remoteAddr),this.connections.add(t),e.once("close",()=>{this.connections.delete(t),this.context.closeServerOnMaxConnections!=null&&this.connections.size<this.context.closeServerOnMaxConnections.listenBelow&&this.resume().catch(o=>{this.log.error("error attempting to listen server once connection count under limit",o),this.context.closeServerOnMaxConnections?.onListenError?.(o)})}),this.context.handler!=null&&this.context.handler(n),this.context.closeServerOnMaxConnections!=null&&this.connections.size>=this.context.closeServerOnMaxConnections.closeAbove&&this.pause(!1).catch(o=>{this.log.error("error attempting to close server once connection count over limit",o)}),this.safeDispatchEvent("connection",{detail:n})}).catch(async n=>{this.log.error("inbound connection failed",n),this.metrics?.errors.increment({[`${this.addr} inbound_upgrade`]:!0}),await Tr(t,{log:this.log})}).catch(n=>{this.log.error("closing inbound connection failed",n)})}catch(n){this.log.error("inbound connection failed",n),Tr(t,{log:this.log}).catch(o=>{this.log.error("closing inbound connection failed",o),this.metrics?.errors.increment({[`${this.addr} inbound_closing_failed`]:!0})})}}getAddrs(){if(this.status.code===I.INACTIVE)return[];let e=[],t=this.server.address(),{listeningAddr:n,peerId:o}=this.status;if(t==null)return[];if(typeof t=="string")e=[n];else try{n.toString().startsWith("/ip4")?e=e.concat(At("ip4",t.address,t.port)):t.family==="IPv6"&&(e=e.concat(At("ip6",t.address,t.port)))}catch(i){this.log.error("could not turn %s:%s into multiaddr",t.address,t.port,i)}return e.map(i=>o!=null?i.encapsulate(`/p2p/${o}`):i)}async listen(e){if(this.status.code===I.ACTIVE||this.status.code===I.PAUSED)throw new A("server is already listening","ERR_SERVER_ALREADY_LISTENING");let t=e.getPeerId(),n=t==null?e.decapsulateCode(421):e,{backlog:o}=this.context;try{this.status={code:I.ACTIVE,listeningAddr:n,peerId:t,netConfig:ce(n,{backlog:o})},await this.resume()}catch(i){throw this.status={code:I.INACTIVE},i}}async close(){let e=new A("Listener is closing","ERR_LISTENER_CLOSING");this.connections.forEach(t=>{t.abort(e)}),await this.pause(!0)}async resume(){if(this.server.listening||this.status.code===I.INACTIVE)return;let e=this.status.netConfig;await new Promise((t,n)=>{this.server.once("error",n),this.server.listen(e,t)}),this.status={...this.status,code:I.ACTIVE},this.log("listening on %s",this.server.address())}async pause(e){if(!this.server.listening&&this.status.code===I.PAUSED&&e){this.status={code:I.INACTIVE};return}!this.server.listening||this.status.code!==I.ACTIVE||(this.log("closing server on %s",this.server.address()),this.status=e?{code:I.INACTIVE}:{...this.status,code:I.PAUSED},await new Promise((t,n)=>{this.server.close(o=>{if(o!=null){n(o);return}t()})}))}};var It=class{opts;metrics;components;log;constructor(e,t={}){this.log=e.logger.forComponent("libp2p:tcp"),this.opts=t,this.components=e,e.metrics!=null&&(this.metrics={dialerEvents:e.metrics.registerCounterGroup("libp2p_tcp_dialer_events_total",{label:"event",help:"Total count of TCP dialer events by type"})})}[Tt]=!0;[Symbol.toStringTag]="@libp2p/tcp";[Nt]=["@libp2p/transport"];async dial(e,t){t.keepAlive=t.keepAlive??!0,t.noDelay=t.noDelay??!0;let n=await this._connect(e,t);n.on("error",a=>{this.log("socket error",a)});let o=Re(n,{remoteAddr:e,socketInactivityTimeout:this.opts.outboundSocketInactivityTimeout,socketCloseTimeout:this.opts.socketCloseTimeout,metrics:this.metrics?.dialerEvents,logger:this.components.logger}),i=()=>{o.close().catch(a=>{this.log.error("Error closing maConn after abort",a)})};t.signal?.addEventListener("abort",i,{once:!0}),this.log("new outbound connection %s",o.remoteAddr);let s=await t.upgrader.upgradeOutbound(o);if(this.log("outbound connection %s upgraded",o.remoteAddr),t.signal?.removeEventListener("abort",i),t.signal?.aborted===!0)throw s.close().catch(a=>{this.log.error("Error closing conn after abort",a)}),new le;return s}async _connect(e,t){return t.signal?.throwIfAborted(),t.onProgress?.(new Pe("tcp:open-connection")),new Promise((n,o)=>{let i=Date.now(),s=ce(e,{...this.opts.dialOpts??{},...t});this.log("dialing %a",e);let a=Rr.default.connect(s),p=f=>{let d=s.path??`${s.host??""}:${s.port}`;f.message=`connection error ${d}: ${f.message}`,this.metrics?.dialerEvents.increment({error:!0}),C(f)},w=()=>{this.log("connection timeout %a",e),this.metrics?.dialerEvents.increment({timeout:!0});let f=new A(`connection timeout after ${Date.now()-i}ms`,"ERR_CONNECT_TIMEOUT");a.emit("error",f)},u=()=>{this.log("connection opened %a",e),this.metrics?.dialerEvents.increment({connect:!0}),C()},E=()=>{this.log("connection aborted %a",e),this.metrics?.dialerEvents.increment({abort:!0}),a.destroy(),C(new le)},C=f=>{if(a.removeListener("error",p),a.removeListener("timeout",w),a.removeListener("connect",u),t.signal!=null&&t.signal.removeEventListener("abort",E),f!=null){o(f);return}n(a)};a.on("error",p),a.on("timeout",w),a.on("connect",u),t.signal!=null&&t.signal.addEventListener("abort",E)})}createListener(e){return new Ne({...this.opts.listenOpts??{},...e,maxConnections:this.opts.maxConnections,backlog:this.opts.backlog,closeServerOnMaxConnections:this.opts.closeServerOnMaxConnections,socketInactivityTimeout:this.opts.inboundSocketInactivityTimeout,socketCloseTimeout:this.opts.socketCloseTimeout,metrics:this.components.metrics,logger:this.components.logger})}listenFilter(e){return e=Array.isArray(e)?e:[e],e.filter(t=>t.protoCodes().includes(290)?!1:t.protoCodes().includes(400)?!0:H.matches(t.decapsulateCode(421)))}dialFilter(e){return this.listenFilter(e)}};function Lo(r={}){return e=>new It(e,r)}return Lr(ko);})();
|
|
2
|
+
"use strict";var Libp2PTcp=(()=>{var Nr=Object.create;var me=Object.defineProperty;var Dr=Object.getOwnPropertyDescriptor;var Mr=Object.getOwnPropertyNames;var _r=Object.getPrototypeOf,Ur=Object.prototype.hasOwnProperty;var L=(r=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(r,{get:(e,t)=>(typeof require<"u"?require:e)[t]}):r)(function(r){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+r+'" is not supported')});var N=(r,e)=>{for(var t in e)me(r,t,{get:e[t],enumerable:!0})},Ct=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Mr(e))!Ur.call(r,o)&&o!==t&&me(r,o,{get:()=>e[o],enumerable:!(n=Dr(e,o))||n.enumerable});return r};var ae=(r,e,t)=>(t=r!=null?Nr(_r(r)):{},Ct(e||!r||!r.__esModule?me(t,"default",{value:r,enumerable:!0}):t,r)),Lr=r=>Ct(me({},"__esModule",{value:!0}),r);var ko={};N(ko,{tcp:()=>Lo});var Rr=ae(L("net"),1);var Tt=Symbol.for("@libp2p/transport");var St;(function(r){r[r.FATAL_ALL=0]="FATAL_ALL",r[r.NO_FATAL=1]="NO_FATAL"})(St||(St={}));var le=class r extends Error{code;type;constructor(e="The operation was aborted"){super(e),this.name="AbortError",this.code=r.code,this.type=r.type}static code="ABORT_ERR";static type="aborted"},A=class extends Error{code;props;constructor(e,t,n){super(e),this.code=t,this.name=n?.name??"CodeError",this.props=n??{}}};var Pt=L("events"),Rt=(r,...e)=>{try{(0,Pt.setMaxListeners)(r,...e)}catch{}};var ge=class extends EventTarget{#e=new Map;constructor(){super(),Rt(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:i})=>i!==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 kr(e,t))}},kr=globalThis.CustomEvent;var Nt=Symbol.for("@libp2p/service-capabilities"),jo=Symbol.for("@libp2p/service-dependencies");var ke={};N(ke,{base58btc:()=>P,base58flickr:()=>Br});var fi=new Uint8Array(0);function Dt(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 Mt(r){return new TextEncoder().encode(r)}function _t(r){return new TextDecoder().decode(r)}function Or(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 i=r.charAt(o),s=i.charCodeAt(0);if(t[s]!==255)throw new TypeError(i+" is ambiguous");t[s]=o}var a=r.length,p=r.charAt(0),w=Math.log(a)/Math.log(256),u=Math.log(256)/Math.log(a);function E(d){if(d instanceof Uint8Array||(ArrayBuffer.isView(d)?d=new Uint8Array(d.buffer,d.byteOffset,d.byteLength):Array.isArray(d)&&(d=Uint8Array.from(d))),!(d instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(d.length===0)return"";for(var g=0,T=0,x=0,v=d.length;x!==v&&d[x]===0;)x++,g++;for(var O=(v-x)*u+1>>>0,D=new Uint8Array(O);x!==v;){for(var F=d[x],j=0,U=O-1;(F!==0||j<T)&&U!==-1;U--,j++)F+=256*D[U]>>>0,D[U]=F%a>>>0,F=F/a>>>0;if(F!==0)throw new Error("Non-zero carry");T=j,x++}for(var $=O-T;$!==O&&D[$]===0;)$++;for(var he=p.repeat(g);$<O;++$)he+=r.charAt(D[$]);return he}function C(d){if(typeof d!="string")throw new TypeError("Expected String");if(d.length===0)return new Uint8Array;var g=0;if(d[g]!==" "){for(var T=0,x=0;d[g]===p;)T++,g++;for(var v=(d.length-g)*w+1>>>0,O=new Uint8Array(v);d[g];){var D=t[d.charCodeAt(g)];if(D===255)return;for(var F=0,j=v-1;(D!==0||F<x)&&j!==-1;j--,F++)D+=a*O[j]>>>0,O[j]=D%256>>>0,D=D/256>>>0;if(D!==0)throw new Error("Non-zero carry");x=F,g++}if(d[g]!==" "){for(var U=v-x;U!==v&&O[U]===0;)U++;for(var $=new Uint8Array(T+(v-U)),he=T;U!==v;)$[he++]=O[U++];return $}}}function f(d){var g=C(d);if(g)return g;throw new Error(`Non-${e} character`)}return{encode:E,decodeUnsafe:C,decode:f}}var Fr=Or,Vr=Fr,Lt=Vr;var Me=class{name;prefix;baseEncode;constructor(e,t,n){this.name=e,this.prefix=t,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},_e=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,t,n){if(this.name=e,this.prefix=t,t.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=t.codePointAt(0),this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return kt(this,e)}},Ue=class{decoders;constructor(e){this.decoders=e}or(e){return kt(this,e)}decode(e){let t=e[0],n=this.decoders[t];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function kt(r,e){return new Ue({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var Le=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 Me(e,t,n),this.decoder=new _e(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function Z({name:r,prefix:e,encode:t,decode:n}){return new Le(r,e,t,n)}function q({name:r,prefix:e,alphabet:t}){let{encode:n,decode:o}=Lt(t,r);return Z({prefix:e,name:r,encode:n,decode:i=>M(o(i))})}function $r(r,e,t,n){let o={};for(let u=0;u<e.length;++u)o[e[u]]=u;let i=r.length;for(;r[i-1]==="=";)--i;let s=new Uint8Array(i*t/8|0),a=0,p=0,w=0;for(let u=0;u<i;++u){let E=o[r[u]];if(E===void 0)throw new SyntaxError(`Non-${n} character`);p=p<<t|E,a+=t,a>=8&&(a-=8,s[w++]=255&p>>a)}if(a>=t||255&p<<8-a)throw new SyntaxError("Unexpected end of data");return s}function zr(r,e,t){let n=e[e.length-1]==="=",o=(1<<t)-1,i="",s=0,a=0;for(let p=0;p<r.length;++p)for(a=a<<8|r[p],s+=8;s>t;)s-=t,i+=e[o&a>>s];if(s!==0&&(i+=e[o&a<<t-s]),n)for(;i.length*t&7;)i+="=";return i}function b({name:r,prefix:e,bitsPerChar:t,alphabet:n}){return Z({prefix:e,name:r,encode(o){return zr(o,n,t)},decode(o){return $r(o,n,t,r)}})}var P=q({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Br=q({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Oe={};N(Oe,{base32:()=>z,base32hex:()=>Wr,base32hexpad:()=>Xr,base32hexpadupper:()=>Jr,base32hexupper:()=>Hr,base32pad:()=>qr,base32padupper:()=>Gr,base32upper:()=>jr,base32z:()=>Qr});var z=b({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),jr=b({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),qr=b({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Gr=b({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Wr=b({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Hr=b({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Xr=b({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Jr=b({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Qr=b({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Kr=Vt,Ot=128,Yr=127,Zr=~Yr,en=Math.pow(2,31);function Vt(r,e,t){e=e||[],t=t||0;for(var n=t;r>=en;)e[t++]=r&255|Ot,r/=128;for(;r&Zr;)e[t++]=r&255|Ot,r>>>=7;return e[t]=r|0,Vt.bytes=t-n+1,e}var tn=Fe,rn=128,Ft=127;function Fe(r,n){var t=0,n=n||0,o=0,i=n,s,a=r.length;do{if(i>=a)throw Fe.bytes=0,new RangeError("Could not decode varint");s=r[i++],t+=o<28?(s&Ft)<<o:(s&Ft)*Math.pow(2,o),o+=7}while(s>=rn);return Fe.bytes=i-n,t}var nn=Math.pow(2,7),on=Math.pow(2,14),sn=Math.pow(2,21),cn=Math.pow(2,28),an=Math.pow(2,35),ln=Math.pow(2,42),dn=Math.pow(2,49),un=Math.pow(2,56),pn=Math.pow(2,63),fn=function(r){return r<nn?1:r<on?2:r<sn?3:r<cn?4:r<an?5:r<ln?6:r<dn?7:r<un?8:r<pn?9:10},hn={encode:Kr,decode:tn,encodingLength:fn},mn=hn,de=mn;function ue(r,e=0){return[de.decode(r,e),de.decode.bytes]}function ee(r,e,t=0){return de.encode(r,e,t),e}function te(r){return de.encodingLength(r)}function X(r,e){let t=e.byteLength,n=te(r),o=n+te(t),i=new Uint8Array(o+t);return ee(r,i,0),ee(t,i,n),i.set(e,o),new re(r,t,e,i)}function we(r){let e=M(r),[t,n]=ue(e),[o,i]=ue(e.subarray(n)),s=e.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new re(t,o,s,e)}function $t(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&Dt(r.bytes,t.bytes)}}var re=class{code;size;digest;bytes;constructor(e,t,n,o){this.code=e,this.size=t,this.digest=n,this.bytes=o}};function zt(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return xn(t,Ve(r),e??P.encoder);default:return wn(t,Ve(r),e??z.encoder)}}var Bt=new WeakMap;function Ve(r){let e=Bt.get(r);if(e==null){let t=new Map;return Bt.set(r,t),t}return e}var G=class r{code;version;multihash;bytes;"/";constructor(e,t,n,o){this.code=t,this.version=e,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:t}=this;if(e!==pe)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==bn)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(t)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:e,digest:t}=this.multihash,n=X(e,t);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(e){return r.equals(this,e)}static equals(e,t){let n=t;return n!=null&&e.code===n.code&&e.version===n.version&&$t(e.multihash,n.multihash)}toString(e){return zt(this,e)}toJSON(){return{"/":zt(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let t=e;if(t instanceof r)return t;if(t["/"]!=null&&t["/"]===t.bytes||t.asCID===t){let{version:n,code:o,multihash:i,bytes:s}=t;return new r(n,o,i,s??jt(n,o,i.bytes))}else if(t[yn]===!0){let{version:n,multihash:o,code:i}=t,s=we(o);return r.create(n,i,s)}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!==pe)throw new Error(`Version 0 CID must use dag-pb (code: ${pe}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let o=jt(e,t,n.bytes);return new r(e,t,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,pe,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 i=o.subarray(t.multihashSize-t.digestSize),s=new re(t.multihashCode,t.digestSize,i,o);return[t.version===0?r.createV0(s):r.createV1(t.codec,s),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[E,C]=ue(e.subarray(t));return t+=C,E},o=n(),i=pe;if(o===18?(o=0,t=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let s=t,a=n(),p=n(),w=t+p,u=w-s;return{version:o,codec:i,multihashCode:a,digestSize:p,multihashSize:u,size:w}}static parse(e,t){let[n,o]=gn(e,t),i=r.decode(o);if(i.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Ve(i).set(n,e),i}};function gn(r,e){switch(r[0]){case"Q":{let t=e??P;return[P.prefix,t.decode(`${P.prefix}${r}`)]}case P.prefix:{let t=e??P;return[P.prefix,t.decode(r)]}case z.prefix:{let t=e??z;return[z.prefix,t.decode(r)]}default:{if(e==null)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[r[0],e.decode(r)]}}}function xn(r,e,t){let{prefix:n}=t;if(n!==P.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let o=e.get(n);if(o==null){let i=t.encode(r).slice(1);return e.set(n,i),i}else return o}function wn(r,e,t){let{prefix:n}=t,o=e.get(n);if(o==null){let i=t.encode(r);return e.set(n,i),i}else return o}var pe=112,bn=18;function jt(r,e,t){let n=te(r),o=n+te(e),i=new Uint8Array(o+t.byteLength);return ee(r,i,0),ee(e,i,n),i.set(t,o),i}var yn=Symbol.for("@ipld/js-cid/CID");function qt(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 Yt=L("node:buffer");var $e={};N($e,{base10:()=>vn});var vn=q({prefix:"9",name:"base10",alphabet:"0123456789"});var ze={};N(ze,{base16:()=>En,base16upper:()=>An});var En=b({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),An=b({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Be={};N(Be,{base2:()=>In});var In=b({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var je={};N(je,{base256emoji:()=>Rn});var Gt=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}"),Cn=Gt.reduce((r,e,t)=>(r[t]=e,r),[]),Sn=Gt.reduce((r,e,t)=>(r[e.codePointAt(0)]=t,r),[]);function Tn(r){return r.reduce((e,t)=>(e+=Cn[t],e),"")}function Pn(r){let e=[];for(let t of r){let n=Sn[t.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${t}`);e.push(n)}return new Uint8Array(e)}var Rn=Z({prefix:"\u{1F680}",name:"base256emoji",encode:Tn,decode:Pn});var qe={};N(qe,{base36:()=>Nn,base36upper:()=>Dn});var Nn=q({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Dn=q({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Ge={};N(Ge,{base64:()=>Mn,base64pad:()=>_n,base64url:()=>Un,base64urlpad:()=>Ln});var Mn=b({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),_n=b({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Un=b({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Ln=b({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var We={};N(We,{base8:()=>kn});var kn=b({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var He={};N(He,{identity:()=>On});var On=Z({prefix:"\0",name:"identity",encode:r=>_t(r),decode:r=>Mt(r)});var Fi=new TextEncoder,Vi=new TextDecoder;var Xe={};N(Xe,{identity:()=>Bn});var Wt=0,$n="identity",Ht=M;function zn(r){return X(Wt,Ht(r))}var Bn={code:Wt,name:$n,encode:Ht,digest:zn};var Ye={};N(Ye,{sha256:()=>jn,sha512:()=>qn});var Ke=ae(L("crypto"),1);function Qe({name:r,code:e,encode:t}){return new Je(r,e,t)}var Je=class{name;code;encode;constructor(e,t,n){this.name=e,this.code=t,this.encode=n}digest(e){if(e instanceof Uint8Array){let t=this.encode(e);return t instanceof Uint8Array?X(this.code,t):t.then(n=>X(this.code,n))}else throw Error("Unknown type, must be binary type")}};var jn=Qe({name:"sha2-256",code:18,encode:r=>M(Ke.default.createHash("sha256").update(r).digest())}),qn=Qe({name:"sha2-512",code:19,encode:r=>M(Ke.default.createHash("sha512").update(r).digest())});var fe={...He,...Be,...We,...$e,...ze,...Oe,...qe,...ke,...Ge,...je},Zi={...Ye,...Xe};var Jt=L("node:buffer");function oe(r){return new Uint8Array(r.buffer,r.byteOffset,r.byteLength)}function be(r=0){return oe(Jt.Buffer.allocUnsafe(r))}function Kt(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var Qt=Kt("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Ze=Kt("ascii","a",r=>{let e="a";for(let t=0;t<r.length;t++)e+=String.fromCharCode(r[t]);return e},r=>{r=r.substring(1);let e=be(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),Gn={utf8:Qt,"utf-8":Qt,hex:fe.base16,latin1:Ze,ascii:Ze,binary:Ze,...fe},ye=Gn;function R(r,e="utf8"){let t=ye[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return e==="utf8"||e==="utf-8"?Yt.Buffer.from(r.buffer,r.byteOffset,r.byteLength).toString("utf8"):t.encoder.encode(r).substring(1)}var Wn=Math.pow(2,7),Hn=Math.pow(2,14),Xn=Math.pow(2,21),et=Math.pow(2,28),tt=Math.pow(2,35),rt=Math.pow(2,42),nt=Math.pow(2,49),h=128,S=127;function V(r){if(r<Wn)return 1;if(r<Hn)return 2;if(r<Xn)return 3;if(r<et)return 4;if(r<tt)return 5;if(r<rt)return 6;if(r<nt)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Jn(r,e,t=0){switch(V(r)){case 8:e[t++]=r&255|h,r/=128;case 7:e[t++]=r&255|h,r/=128;case 6:e[t++]=r&255|h,r/=128;case 5:e[t++]=r&255|h,r/=128;case 4:e[t++]=r&255|h,r>>>=7;case 3:e[t++]=r&255|h,r>>>=7;case 2:e[t++]=r&255|h,r>>>=7;case 1:{e[t++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return e}function Qn(r,e,t=0){switch(V(r)){case 8:e.set(t++,r&255|h),r/=128;case 7:e.set(t++,r&255|h),r/=128;case 6:e.set(t++,r&255|h),r/=128;case 5:e.set(t++,r&255|h),r/=128;case 4:e.set(t++,r&255|h),r>>>=7;case 3:e.set(t++,r&255|h),r>>>=7;case 2:e.set(t++,r&255|h),r>>>=7;case 1:{e.set(t++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return e}function Kn(r,e){let t=r[e],n=0;if(n+=t&S,t<h||(t=r[e+1],n+=(t&S)<<7,t<h)||(t=r[e+2],n+=(t&S)<<14,t<h)||(t=r[e+3],n+=(t&S)<<21,t<h)||(t=r[e+4],n+=(t&S)*et,t<h)||(t=r[e+5],n+=(t&S)*tt,t<h)||(t=r[e+6],n+=(t&S)*rt,t<h)||(t=r[e+7],n+=(t&S)*nt,t<h))return n;throw new RangeError("Could not decode varint")}function Yn(r,e){let t=r.get(e),n=0;if(n+=t&S,t<h||(t=r.get(e+1),n+=(t&S)<<7,t<h)||(t=r.get(e+2),n+=(t&S)<<14,t<h)||(t=r.get(e+3),n+=(t&S)<<21,t<h)||(t=r.get(e+4),n+=(t&S)*et,t<h)||(t=r.get(e+5),n+=(t&S)*tt,t<h)||(t=r.get(e+6),n+=(t&S)*rt,t<h)||(t=r.get(e+7),n+=(t&S)*nt,t<h))return n;throw new RangeError("Could not decode varint")}function ie(r,e,t=0){return e==null&&(e=be(V(r))),e instanceof Uint8Array?Jn(r,e,t):Qn(r,e,t)}function J(r,e=0){return r instanceof Uint8Array?Kn(r,e):Yn(r,e)}var er=L("node:buffer");function B(r,e){return oe(er.Buffer.concat(r,e))}var ve=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 i=0,s=0,a=this.peekChar();if(a===void 0)return;let p=a==="0",w=2**(8*o)-1;for(;;){let u=this.readAtomically(()=>{let E=this.readChar();if(E===void 0)return;let C=Number.parseInt(E,e);if(!Number.isNaN(C))return C});if(u===void 0)break;if(i*=e,i+=u,i>w||(s+=1,t!==void 0&&s>t))return}if(s!==0)return!n&&p&&s>1?void 0:i})}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 s=this.readSeparator(":",n,()=>this.readIPv4Addr());if(s!==void 0)return t[o]=s[0],t[o+1]=s[1],t[o+2]=s[2],t[o+3]=s[3],[o+4,!0]}let i=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(i===void 0)return[o,!1];t[o]=i>>8,t[o+1]=i&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 i=new Uint8Array(14),s=16-(n+2),[a]=e(i.subarray(0,s));return t.set(i.subarray(0,a),16-a),t})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var hs=new ve;var Es=parseInt("0xFFFF",16),As=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);var nr=L("node:buffer");function ot(r,e="utf8"){let t=ye[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return e==="utf8"||e==="utf-8"?oe(nr.Buffer.from(r,"utf-8")):t.decoder.decode(`${t.prefix}${r}`)}var _=L("node:net");function Ee(r){return!!(0,_.isIP)(r)}var or=_.isIPv4,oo=_.isIPv6,it=function(r){let e=0;if(r=r.toString().trim(),or(r)){let t=new Uint8Array(e+4);return r.split(/\./g).forEach(n=>{t[e++]=parseInt(n,10)&255}),t}if(oo(r)){let t=r.split(":",8),n;for(n=0;n<t.length;n++){let i=or(t[n]),s;i&&(s=it(t[n]),t[n]=R(s.slice(0,2),"base16")),s!=null&&++n<8&&t.splice(n,0,R(s.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 i=[n,1];for(n=9-t.length;n>0;n--)i.push("0");t.splice.apply(t,i)}let o=new Uint8Array(e+16);for(n=0;n<t.length;n++){let i=parseInt(t[n],16);o[e++]=i>>8&255,o[e++]=i&255}return o}throw new Error("invalid ip address")},ir=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 i=0;i<t;i++)o.push(r[e+i]);return o.join(".")}if(t===16){let o=[];for(let i=0;i<t;i+=2)o.push(n.getUint16(e+i).toString(16));return o.join(":").replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}return""};var se={},st={},so=[[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"]];so.forEach(r=>{let e=co(...r);st[e.code]=e,se[e.name]=e});function co(r,e,t,n,o){return{code:r,size:e,name:t,resolvable:!!n,path:!!o}}function m(r){if(typeof r=="number"){if(st[r]!=null)return st[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(se[r]!=null)return se[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var dc=m("ip4"),uc=m("ip6"),pc=m("ipcidr");function dt(r,e){switch(m(r).code){case 4:case 41:return lo(e);case 42:return lt(e);case 6:case 273:case 33:case 132:return ar(e).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return lt(e);case 421:return ho(e);case 444:return cr(e);case 445:return cr(e);case 466:return fo(e);case 481:return globalThis.encodeURIComponent(lt(e));default:return R(e,"base16")}}function ut(r,e){switch(m(r).code){case 4:return sr(e);case 41:return sr(e);case 42:return at(e);case 6:case 273:case 33:case 132:return pt(parseInt(e,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return at(e);case 421:return uo(e);case 444:return mo(e);case 445:return go(e);case 466:return po(e);case 481:return at(globalThis.decodeURIComponent(e));default:return ot(e,"base16")}}var ct=Object.values(fe).map(r=>r.decoder),ao=function(){let r=ct[0].or(ct[1]);return ct.slice(2).forEach(e=>r=r.or(e)),r}();function sr(r){if(!Ee(r))throw new Error("invalid ip address");return it(r)}function lo(r){let e=ir(r,0,r.length);if(e==null)throw new Error("ipBuff is required");if(!Ee(e))throw new Error("invalid ip address");return e}function pt(r){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,r),new Uint8Array(e)}function ar(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function at(r){let e=ot(r),t=Uint8Array.from(ie(e.length));return B([t,e],t.length+e.length)}function lt(r){let e=J(r);if(r=r.slice(V(e)),r.length!==e)throw new Error("inconsistent lengths");return R(r)}function uo(r){let e;r[0]==="Q"||r[0]==="1"?e=we(P.decode(`z${r}`)).bytes:e=G.parse(r).multihash.bytes;let t=Uint8Array.from(ie(e.length));return B([t,e],t.length+e.length)}function po(r){let e=ao.decode(r),t=Uint8Array.from(ie(e.length));return B([t,e],t.length+e.length)}function fo(r){let e=J(r),t=r.slice(V(e));if(t.length!==e)throw new Error("inconsistent lengths");return"u"+R(t,"base64url")}function ho(r){let e=J(r),t=r.slice(V(e));if(t.length!==e)throw new Error("inconsistent lengths");return R(t,"base58btc")}function mo(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=z.decode("b"+e[0]),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=pt(n);return B([t,o],t.length+o.length)}function go(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=z.decode(`b${e[0]}`),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=pt(n);return B([t,o],t.length+o.length)}function cr(r){let e=r.slice(0,r.length-2),t=r.slice(r.length-2),n=R(e,"base32"),o=ar(t);return`${n}:${o}`}function lr(r){r=ft(r);let e=[],t=[],n=null,o=r.split("/").slice(1);if(o.length===1&&o[0]==="")return{bytes:new Uint8Array,string:"/",tuples:[],stringTuples:[],path:null};for(let i=0;i<o.length;i++){let s=o[i],a=m(s);if(a.size===0){e.push([a.code]),t.push([a.code]);continue}if(i++,i>=o.length)throw ur("invalid address: "+r);if(a.path===!0){n=ft(o.slice(i).join("/")),e.push([a.code,ut(a.code,n)]),t.push([a.code,n]);break}let p=ut(a.code,o[i]);e.push([a.code,p]),t.push([a.code,dt(a.code,p)])}return{string:dr(t),bytes:mt(e),tuples:e,stringTuples:t,path:n}}function ht(r){let e=[],t=[],n=null,o=0;for(;o<r.length;){let i=J(r,o),s=V(i),a=m(i),p=xo(a,r.slice(o+s));if(p===0){e.push([i]),t.push([i]),o+=s;continue}let w=r.slice(o+s,o+s+p);if(o+=p+s,o>r.length)throw ur("Invalid address Uint8Array: "+R(r,"base16"));e.push([i,w]);let u=dt(i,w);if(t.push([i,u]),a.path===!0){n=u;break}}return{bytes:Uint8Array.from(r),string:dr(t),tuples:e,stringTuples:t,path:n}}function dr(r){let e=[];return r.map(t=>{let n=m(t[0]);return e.push(n.name),t.length>1&&t[1]!=null&&e.push(t[1]),null}),ft(e.join("/"))}function mt(r){return B(r.map(e=>{let t=m(e[0]),n=Uint8Array.from(ie(t.code));return e.length>1&&e[1]!=null&&(n=B([n,e[1]])),n}))}function xo(r,e){if(r.size>0)return r.size/8;if(r.size===0)return 0;{let t=J(e instanceof Uint8Array?e:Uint8Array.from(e));return t+V(t)}}function ft(r){return"/"+r.trim().split("/").filter(e=>e).join("/")}function ur(r){return new Error("Error parsing address: "+r)}var wo=Symbol.for("nodejs.util.inspect.custom"),gt=Symbol.for("@multiformats/js-multiaddr/multiaddr"),bo=[m("dns").code,m("dns4").code,m("dns6").code,m("dnsaddr").code],Ae=class r{bytes;#e;#t;#r;#n;[gt]=!0;constructor(e){e==null&&(e="");let t;if(e instanceof Uint8Array)t=ht(e);else if(typeof e=="string"){if(e.length>0&&e.charAt(0)!=="/")throw new Error(`multiaddr "${e}" must start with a "/"`);t=lr(e)}else if(fr(e))t=ht(e.bytes);else throw new Error("addr must be a string, Buffer, or another Multiaddr");this.bytes=t.bytes,this.#e=t.string,this.#t=t.tuples,this.#r=t.stringTuples,this.#n=t.path}toString(){return this.#e}toJSON(){return this.toString()}toOptions(){let e,t,n,o,i="",s=m("tcp"),a=m("udp"),p=m("ip4"),w=m("ip6"),u=m("dns6"),E=m("ip6zone");for(let[f,d]of this.stringTuples())f===E.code&&(i=`%${d??""}`),bo.includes(f)&&(t=s.name,o=443,n=`${d??""}${i}`,e=f===u.code?6:4),(f===s.code||f===a.code)&&(t=m(f).name,o=parseInt(d??"")),(f===p.code||f===w.code)&&(t=m(f).name,n=`${d??""}${i}`,e=f===w.code?6:4);if(e==null||t==null||n==null||o==null)throw new Error('multiaddr must have a valid format: "/{ip4, ip6, dns4, dns6, dnsaddr}/{address}/{tcp, udp}/{port}".');return{family:e,host:n,transport:t,port:o}}protos(){return this.#t.map(([e])=>Object.assign({},m(e)))}protoCodes(){return this.#t.map(([e])=>e)}protoNames(){return this.#t.map(([e])=>m(e).name)}tuples(){return this.#t}stringTuples(){return this.#r}encapsulate(e){return e=new r(e),new r(this.toString()+e.toString())}decapsulate(e){let t=e.toString(),n=this.toString(),o=n.lastIndexOf(t);if(o<0)throw new Error(`Address ${this.toString()} does not contain subaddress: ${e.toString()}`);return new r(n.slice(0,o))}decapsulateCode(e){let t=this.tuples();for(let n=t.length-1;n>=0;n--)if(t[n][0]===e)return new r(mt(t.slice(0,n)));return this}getPeerId(){try{let e=[];this.stringTuples().forEach(([n,o])=>{n===se.p2p.code&&e.push([n,o]),n===se["p2p-circuit"].code&&(e=[])});let t=e.pop();if(t?.[1]!=null){let n=t[1];return n[0]==="Q"||n[0]==="1"?R(P.decode(`z${n}`),"base58btc"):R(G.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){return this.#n}equals(e){return qt(this.bytes,e.bytes)}async resolve(e){let t=this.protos().find(i=>i.resolvable);if(t==null)return[this];let n=pr.get(t.name);if(n==null)throw new A(`no available resolver for ${t.name}`,"ERR_NO_AVAILABLE_RESOLVER");return(await n(this,e)).map(i=>k(i))}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)}[wo](){return`Multiaddr(${this.#e})`}};var pr=new Map;function fr(r){return!!r?.[gt]}function k(r){return new Ae(r)}var yo=c("dns4"),vo=c("dns6"),Eo=c("dnsaddr"),K=y(c("dns"),Eo,yo,vo),Se=y(c("ip4"),c("ip6")),H=y(l(Se,c("tcp")),l(K,c("tcp"))),Te=l(Se,c("udp")),Ao=l(Te,c("utp")),Io=l(Te,c("quic")),Co=l(Te,c("quic-v1")),xt=y(l(H,c("ws")),l(K,c("ws"))),Ie=y(l(xt,c("p2p")),xt),wt=y(l(H,c("wss")),l(K,c("wss")),l(H,c("tls"),c("ws")),l(K,c("tls"),c("ws"))),Ce=y(l(wt,c("p2p")),wt),bt=y(l(H,c("http")),l(Se,c("http")),l(K,c("http"))),yt=y(l(H,c("https")),l(Se,c("https")),l(K,c("https"))),hr=l(Te,c("webrtc-direct"),c("certhash")),xr=y(l(hr,c("p2p")),hr),mr=l(Co,c("webtransport"),c("certhash"),c("certhash")),wr=y(l(mr,c("p2p")),mr),br=y(l(Ie,c("p2p-webrtc-star"),c("p2p")),l(Ce,c("p2p-webrtc-star"),c("p2p")),l(Ie,c("p2p-webrtc-star")),l(Ce,c("p2p-webrtc-star"))),Fc=y(l(Ie,c("p2p-websocket-star"),c("p2p")),l(Ce,c("p2p-websocket-star"),c("p2p")),l(Ie,c("p2p-websocket-star")),l(Ce,c("p2p-websocket-star"))),yr=y(l(bt,c("p2p-webrtc-direct"),c("p2p")),l(yt,c("p2p-webrtc-direct"),c("p2p")),l(bt,c("p2p-webrtc-direct")),l(yt,c("p2p-webrtc-direct"))),Y=y(xt,wt,bt,yt,br,yr,H,Ao,Io,K,xr,wr),Vc=y(l(Y,c("p2p-stardust"),c("p2p")),l(Y,c("p2p-stardust"))),W=y(l(Y,c("p2p")),br,yr,xr,wr,c("p2p")),gr=y(l(W,c("p2p-circuit"),W),l(W,c("p2p-circuit")),l(c("p2p-circuit"),W),l(Y,c("p2p-circuit")),l(c("p2p-circuit"),Y),c("p2p-circuit")),vr=()=>y(l(gr,vr),gr),Q=vr(),$c=y(l(Q,W,Q),l(W,Q),l(Q,W),Q,W);var zc=y(l(Q,c("webrtc"),c("p2p")),l(Q,c("webrtc")),l(Y,c("webrtc"),c("p2p")),l(Y,c("webrtc")),c("webrtc"));function Er(r){function e(t){let n;try{n=k(t)}catch{return!1}let o=r(n.protoNames());return o===null?!1:o===!0||o===!1?o:o.length===0}return e}function l(...r){function e(t){if(t.length<r.length)return null;let n=t;return r.some(o=>(n=typeof o=="function"?o().partialMatch(t):o.partialMatch(t),Array.isArray(n)&&(t=n),n===null)),n}return{toString:function(){return"{ "+r.join(" ")+" }"},input:r,matches:Er(e),partialMatch:e}}function y(...r){function e(n){let o=null;return r.some(i=>{let s=typeof i=="function"?i().partialMatch(n):i.partialMatch(n);return s!=null?(o=s,!0):!1}),o}return{toString:function(){return"{ "+r.join(" ")+" }"},input:r,matches:Er(e),partialMatch:e}}function c(r){let e=r;function t(o){let i;try{i=k(o)}catch{return!1}let s=i.protoNames();return s.length===1&&s[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 Pe=class extends Event{type;detail;constructor(e,t){super(e),this.type=e,this.detail=t}};var Pr=ae(L("net"),1);var vt={ERR_INVALID_IP_PARAMETER:"ERR_INVALID_IP_PARAMETER",ERR_INVALID_PORT_PARAMETER:"ERR_INVALID_PORT_PARAMETER",ERR_INVALID_IP:"ERR_INVALID_IP"};function Ar(r,e){if(typeof r!="string")throw new A(`invalid ip provided: ${r}`,vt.ERR_INVALID_IP_PARAMETER);if(typeof e=="string"&&(e=parseInt(e)),isNaN(e))throw new A(`invalid port provided: ${e}`,vt.ERR_INVALID_PORT_PARAMETER);if((0,_.isIPv4)(r))return k(`/ip4/${r}/tcp/${e}`);if((0,_.isIPv6)(r))return k(`/ip6/${r}/tcp/${e}`);throw new A(`invalid ip:port for creating a multiaddr: ${r}:${e}`,vt.ERR_INVALID_IP)}function Ir(r){if(Po(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(To(r))return r;throw new Error("unknown stream")}function To(r){return r[Symbol.asyncIterator]!=null}function Po(r){return typeof r?.getReader=="function"}function Cr(r){return async e=>{let t=async()=>{Ro(e)&&await e.return(void 0)},n,o,i=x=>{n=x,t().catch(v=>{v=new AggregateError([n,v],"The Writable emitted an error, additionally an error occurred while ending the Source")}).finally(()=>{o?.(x)})},s,a=!1,p=()=>{a=!0,s?.()},w,u=!1,E=()=>{u=!0,w?.()},C,f=()=>{C?.()},d=async()=>new Promise((x,v)=>{s=C=x,o=v,r.once("drain",f)}),g=async()=>(await t(),new Promise((x,v)=>{if(a||u||n!=null){x();return}w=s=x,o=v})),T=()=>{r.removeListener("error",i),r.removeListener("close",p),r.removeListener("finish",E),r.removeListener("drain",f)};r.once("error",i),r.once("close",p),r.once("finish",E);try{for await(let x of e){if(!r.writable||r.destroyed||n!=null)break;r.write(x)||await d()}}catch(x){n==null&&r.destroy(x),n=x}try{if(r.writable&&r.end(),await g(),n!=null)throw n}finally{T()}}}function Ro(r){return r.return!=null}function Et(r){return{sink:Cr(r),source:Ir(r)}}var At=ae(L("os"),1),Sr=ae(L("path"),1);var No={ip4:"IPv4",ip6:"IPv6"};function ce(r,e={}){let t=r.getPath();return t!=null?At.default.platform()==="win32"?{path:Sr.default.join("\\\\.\\pipe\\",t)}:{path:t}:{...e,...r.toOptions()}}function It(r,e,t){let n=o=>k(`/${r}/${o}/tcp/${t}`);return(Do(e)?_o(No[r]):[e]).map(n)}function Do(r){return["0.0.0.0","::"].includes(r)}var Mo=At.default.networkInterfaces();function _o(r){let e=[];for(let[,t]of Object.entries(Mo))if(t!=null)for(let n of t)n.family===r&&e.push(n.address);return e}var Re=(r,e)=>{let t=null,n=e.logger.forComponent("libp2p:tcp:socket"),o=e.metrics,i=e.metricPrefix??"",s=e.socketInactivityTimeout??3e5,a=e.socketCloseTimeout??500;e.listeningAddr?.getPath()!=null&&(e.remoteAddr=e.listeningAddr),e.remoteAddr?.getPath()!=null&&(e.localAddr=e.remoteAddr);let p;if(e.remoteAddr!=null)p=e.remoteAddr;else{if(r.remoteAddress==null||r.remotePort==null)throw new A("Could not determine remote address or port","ERR_NO_REMOTE_ADDRESS");p=Ar(r.remoteAddress,r.remotePort)}let w=ce(p),u=w.path??`${w.host??""}:${w.port??""}`,{sink:E,source:C}=Et(r);r.setTimeout(s,()=>{n("%s socket read timeout",u),o?.increment({[`${i}timeout`]:!0});let d;r.readable&&(d=new A("Socket read timeout","ERR_SOCKET_READ_TIMEOUT")),r.destroy(d)}),r.once("close",()=>{n("%s socket close",u),o?.increment({[`${i}close`]:!0}),f.timeline.close==null&&(f.timeline.close=Date.now())}),r.once("end",()=>{n("%s socket end",u),o?.increment({[`${i}end`]:!0})});let f={async sink(d){try{await E(async function*(){for await(let g of d)g instanceof Uint8Array?yield g:yield g.subarray()}())}catch(g){g.type!=="aborted"&&n.error("%s error in sink",u,g)}r.end()},source:C,remoteAddr:p,timeline:{open:Date.now()},async close(d={}){if(r.destroyed){n("The %s socket is destroyed",u);return}if(t!=null)return n("The %s socket is closed or closing",u),t;if(d.signal==null){let T=AbortSignal.timeout(a);d={...d,signal:T}}let g=()=>{r.destroy(new A("Destroying socket after timeout","ERR_CLOSE_TIMEOUT"))};d.signal?.addEventListener("abort",g);try{n("%s closing socket",u),t=new Promise((T,x)=>{r.once("close",()=>{n("%s socket closed",u),T()}),r.once("error",v=>{n("%s socket error",u,v),f.timeline.close==null&&(f.timeline.close=Date.now()),r.destroyed||x(v)}),r.setTimeout(a),r.end(),r.writableLength>0?r.once("drain",()=>{n("%s socket drained",u),r.destroy()}):r.destroy()}),await t}catch(T){this.abort(T)}finally{d.signal?.removeEventListener("abort",g)}},abort:d=>{n("%s socket abort due to error",u,d),r.destroyed||r.destroy(d),f.timeline.close==null&&(f.timeline.close=Date.now())},log:n};return f};async function Tr(r,e){try{await r.close()}catch(t){e.log.error("an error occurred closing the connection",t),r.abort(t)}}var I;(function(r){r[r.INACTIVE=0]="INACTIVE",r[r.ACTIVE=1]="ACTIVE",r[r.PAUSED=2]="PAUSED"})(I||(I={}));var Ne=class extends ge{context;server;connections=new Set;status={code:I.INACTIVE};metrics;addr;log;constructor(e){if(super(),this.context=e,e.keepAlive=e.keepAlive??!0,e.noDelay=e.noDelay??!0,this.log=e.logger.forComponent("libp2p:tcp:listener"),this.addr="unknown",this.server=Pr.default.createServer(e,this.onSocket.bind(this)),e.maxConnections!==void 0&&(this.server.maxConnections=e.maxConnections),e.closeServerOnMaxConnections!=null&&e.closeServerOnMaxConnections.closeAbove<e.closeServerOnMaxConnections.listenBelow)throw new A("closeAbove must be >= listenBelow","ERR_CONNECTION_LIMITS");this.server.on("listening",()=>{if(e.metrics!=null){let t=this.server.address();t==null?this.addr="unknown":typeof t=="string"?this.addr=t:this.addr=`${t.address}:${t.port}`,e.metrics?.registerMetricGroup("libp2p_tcp_inbound_connections_total",{label:"address",help:"Current active connections in TCP listener",calculate:()=>({[this.addr]:this.connections.size})}),this.metrics={status:e.metrics.registerMetricGroup("libp2p_tcp_listener_status_info",{label:"address",help:"Current status of the TCP listener socket"}),errors:e.metrics.registerMetricGroup("libp2p_tcp_listener_errors_total",{label:"address",help:"Total count of TCP listener errors by type"}),events:e.metrics.registerMetricGroup("libp2p_tcp_listener_events_total",{label:"address",help:"Total count of TCP listener events by type"})},this.metrics?.status.update({[this.addr]:I.ACTIVE})}this.safeDispatchEvent("listening")}).on("error",t=>{this.metrics?.errors.increment({[`${this.addr} listen_error`]:!0}),this.safeDispatchEvent("error",{detail:t})}).on("close",()=>{this.metrics?.status.update({[this.addr]:this.status.code}),this.status.code!==I.PAUSED&&this.safeDispatchEvent("close")})}onSocket(e){if(this.status.code!==I.ACTIVE)throw new A("Server is not listening yet","ERR_SERVER_NOT_RUNNING");e.on("error",n=>{this.log("socket error",n),this.metrics?.events.increment({[`${this.addr} error`]:!0})});let t;try{t=Re(e,{listeningAddr:this.status.listeningAddr,socketInactivityTimeout:this.context.socketInactivityTimeout,socketCloseTimeout:this.context.socketCloseTimeout,metrics:this.metrics?.events,metricPrefix:`${this.addr} `,logger:this.context.logger})}catch(n){this.log.error("inbound connection failed",n),this.metrics?.errors.increment({[`${this.addr} inbound_to_connection`]:!0});return}this.log("new inbound connection %s",t.remoteAddr);try{this.context.upgrader.upgradeInbound(t).then(n=>{this.log("inbound connection upgraded %s",t.remoteAddr),this.connections.add(t),e.once("close",()=>{this.connections.delete(t),this.context.closeServerOnMaxConnections!=null&&this.connections.size<this.context.closeServerOnMaxConnections.listenBelow&&this.resume().catch(o=>{this.log.error("error attempting to listen server once connection count under limit",o),this.context.closeServerOnMaxConnections?.onListenError?.(o)})}),this.context.handler!=null&&this.context.handler(n),this.context.closeServerOnMaxConnections!=null&&this.connections.size>=this.context.closeServerOnMaxConnections.closeAbove&&this.pause(!1).catch(o=>{this.log.error("error attempting to close server once connection count over limit",o)}),this.safeDispatchEvent("connection",{detail:n})}).catch(async n=>{this.log.error("inbound connection failed",n),this.metrics?.errors.increment({[`${this.addr} inbound_upgrade`]:!0}),await Tr(t,{log:this.log})}).catch(n=>{this.log.error("closing inbound connection failed",n)})}catch(n){this.log.error("inbound connection failed",n),Tr(t,{log:this.log}).catch(o=>{this.log.error("closing inbound connection failed",o),this.metrics?.errors.increment({[`${this.addr} inbound_closing_failed`]:!0})})}}getAddrs(){if(this.status.code===I.INACTIVE)return[];let e=[],t=this.server.address(),{listeningAddr:n,peerId:o}=this.status;if(t==null)return[];if(typeof t=="string")e=[n];else try{n.toString().startsWith("/ip4")?e=e.concat(It("ip4",t.address,t.port)):t.family==="IPv6"&&(e=e.concat(It("ip6",t.address,t.port)))}catch(i){this.log.error("could not turn %s:%s into multiaddr",t.address,t.port,i)}return e.map(i=>o!=null?i.encapsulate(`/p2p/${o}`):i)}async listen(e){if(this.status.code===I.ACTIVE||this.status.code===I.PAUSED)throw new A("server is already listening","ERR_SERVER_ALREADY_LISTENING");let t=e.getPeerId(),n=t==null?e.decapsulateCode(421):e,{backlog:o}=this.context;try{this.status={code:I.ACTIVE,listeningAddr:n,peerId:t,netConfig:ce(n,{backlog:o})},await this.resume()}catch(i){throw this.status={code:I.INACTIVE},i}}async close(){let e=new A("Listener is closing","ERR_LISTENER_CLOSING");this.connections.forEach(t=>{t.abort(e)}),await this.pause(!0)}async resume(){if(this.server.listening||this.status.code===I.INACTIVE)return;let e=this.status.netConfig;await new Promise((t,n)=>{this.server.once("error",n),this.server.listen(e,t)}),this.status={...this.status,code:I.ACTIVE},this.log("listening on %s",this.server.address())}async pause(e){if(!this.server.listening&&this.status.code===I.PAUSED&&e){this.status={code:I.INACTIVE};return}!this.server.listening||this.status.code!==I.ACTIVE||(this.log("closing server on %s",this.server.address()),this.status=e?{code:I.INACTIVE}:{...this.status,code:I.PAUSED},await new Promise((t,n)=>{this.server.close(o=>{if(o!=null){n(o);return}t()})}))}};var De=class{opts;metrics;components;log;constructor(e,t={}){this.log=e.logger.forComponent("libp2p:tcp"),this.opts=t,this.components=e,e.metrics!=null&&(this.metrics={dialerEvents:e.metrics.registerCounterGroup("libp2p_tcp_dialer_events_total",{label:"event",help:"Total count of TCP dialer events by type"})})}[Tt]=!0;[Symbol.toStringTag]="@libp2p/tcp";[Nt]=["@libp2p/transport"];async dial(e,t){t.keepAlive=t.keepAlive??!0,t.noDelay=t.noDelay??!0;let n=await this._connect(e,t);n.on("error",a=>{this.log("socket error",a)});let o=Re(n,{remoteAddr:e,socketInactivityTimeout:this.opts.outboundSocketInactivityTimeout,socketCloseTimeout:this.opts.socketCloseTimeout,metrics:this.metrics?.dialerEvents,logger:this.components.logger}),i=()=>{o.close().catch(a=>{this.log.error("Error closing maConn after abort",a)})};t.signal?.addEventListener("abort",i,{once:!0}),this.log("new outbound connection %s",o.remoteAddr);let s=await t.upgrader.upgradeOutbound(o);if(this.log("outbound connection %s upgraded",o.remoteAddr),t.signal?.removeEventListener("abort",i),t.signal?.aborted===!0)throw s.close().catch(a=>{this.log.error("Error closing conn after abort",a)}),new le;return s}async _connect(e,t){return t.signal?.throwIfAborted(),t.onProgress?.(new Pe("tcp:open-connection")),new Promise((n,o)=>{let i=Date.now(),s=ce(e,{...this.opts.dialOpts??{},...t});this.log("dialing %a",e);let a=Rr.default.connect(s),p=f=>{let d=s.path??`${s.host??""}:${s.port}`;f.message=`connection error ${d}: ${f.message}`,this.metrics?.dialerEvents.increment({error:!0}),C(f)},w=()=>{this.log("connection timeout %a",e),this.metrics?.dialerEvents.increment({timeout:!0});let f=new A(`connection timeout after ${Date.now()-i}ms`,"ERR_CONNECT_TIMEOUT");a.emit("error",f)},u=()=>{this.log("connection opened %a",e),this.metrics?.dialerEvents.increment({connect:!0}),C()},E=()=>{this.log("connection aborted %a",e),this.metrics?.dialerEvents.increment({abort:!0}),a.destroy(),C(new le)},C=f=>{if(a.removeListener("error",p),a.removeListener("timeout",w),a.removeListener("connect",u),t.signal!=null&&t.signal.removeEventListener("abort",E),f!=null){o(f);return}n(a)};a.on("error",p),a.on("timeout",w),a.on("connect",u),t.signal!=null&&t.signal.addEventListener("abort",E)})}createListener(e){return new Ne({...this.opts.listenOpts??{},...e,maxConnections:this.opts.maxConnections,backlog:this.opts.backlog,closeServerOnMaxConnections:this.opts.closeServerOnMaxConnections,socketInactivityTimeout:this.opts.inboundSocketInactivityTimeout,socketCloseTimeout:this.opts.socketCloseTimeout,metrics:this.components.metrics,logger:this.components.logger})}listenFilter(e){return e=Array.isArray(e)?e:[e],e.filter(t=>t.protoCodes().includes(290)?!1:t.protoCodes().includes(400)?!0:H.matches(t.decapsulateCode(421)))}dialFilter(e){return this.listenFilter(e)}};function Lo(r={}){return e=>new De(e,r)}return Lr(ko);})();
|
|
3
3
|
return Libp2PTcp}));
|
package/dist/src/index.d.ts
CHANGED
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
* // use connection...
|
|
27
27
|
* ```
|
|
28
28
|
*/
|
|
29
|
-
import {
|
|
29
|
+
import type { CloseServerOnMaxConnectionsOpts } from './listener.js';
|
|
30
30
|
import type { ComponentLogger, CounterGroup, Metrics, CreateListenerOptions, DialTransportOptions, Transport, OutboundConnectionUpgradeEvents } from '@libp2p/interface';
|
|
31
31
|
import type { AbortOptions } from '@multiformats/multiaddr';
|
|
32
32
|
import type { ProgressEvent } from 'progress-events';
|
package/dist/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAGH,OAAO,KAAK,EAAE,+BAA+B,EAAE,MAAM,eAAe,CAAA;AACpE,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,OAAO,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,SAAS,EAAE,+BAA+B,EAAE,MAAM,mBAAmB,CAAA;AACxK,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAA;AAC3D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAEpD,MAAM,WAAW,UAAU;IACzB;;OAEG;IACH,8BAA8B,CAAC,EAAE,MAAM,CAAA;IAEvC;;OAEG;IACH,+BAA+B,CAAC,EAAE,MAAM,CAAA;IAExC;;OAEG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAE3B;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAA;IAEvB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;IAEhB;;;OAGG;IACH,2BAA2B,CAAC,EAAE,+BAA+B,CAAA;IAE7D;;OAEG;IACH,QAAQ,CAAC,EAAE,gBAAgB,CAAA;IAE3B;;OAEG;IACH,UAAU,CAAC,EAAE,gBAAgB,CAAA;CAC9B;AAED;;GAEG;AACH,MAAM,WAAW,gBAAiB,SAAQ,YAAY;IACpD;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;IAEjB;;OAEG;IACH,SAAS,CAAC,EAAE,OAAO,CAAA;IAEnB;;OAEG;IACH,qBAAqB,CAAC,EAAE,MAAM,CAAA;IAE9B;;OAEG;IACH,aAAa,CAAC,EAAE,OAAO,CAAA;CACxB;AAED,MAAM,MAAM,aAAa,GACvB,+BAA+B,GAC/B,aAAa,CAAC,qBAAqB,CAAC,CAAA;AAEtC,MAAM,WAAW,cAAe,SAAQ,oBAAoB,CAAC,aAAa,CAAC,EAAE,gBAAgB;CAE5F;AAED,MAAM,WAAW,wBAAyB,SAAQ,qBAAqB,EAAE,gBAAgB;CAExF;AAED,MAAM,WAAW,aAAa;IAC5B,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,MAAM,EAAE,eAAe,CAAA;CACxB;AAED,MAAM,WAAW,UAAU;IACzB,YAAY,EAAE,YAAY,CAAA;CAC3B;AAED,wBAAgB,GAAG,CAAE,IAAI,GAAE,UAAe,GAAG,CAAC,UAAU,EAAE,aAAa,KAAK,SAAS,CAIpF"}
|
package/dist/src/index.js
CHANGED
|
@@ -26,167 +26,7 @@
|
|
|
26
26
|
* // use connection...
|
|
27
27
|
* ```
|
|
28
28
|
*/
|
|
29
|
-
import
|
|
30
|
-
import { AbortError, CodeError, serviceCapabilities, transportSymbol } from '@libp2p/interface';
|
|
31
|
-
import * as mafmt from '@multiformats/mafmt';
|
|
32
|
-
import { CustomProgressEvent } from 'progress-events';
|
|
33
|
-
import { CODE_CIRCUIT, CODE_P2P, CODE_UNIX } from './constants.js';
|
|
34
|
-
import { TCPListener } from './listener.js';
|
|
35
|
-
import { toMultiaddrConnection } from './socket-to-conn.js';
|
|
36
|
-
import { multiaddrToNetConfig } from './utils.js';
|
|
37
|
-
class TCP {
|
|
38
|
-
opts;
|
|
39
|
-
metrics;
|
|
40
|
-
components;
|
|
41
|
-
log;
|
|
42
|
-
constructor(components, options = {}) {
|
|
43
|
-
this.log = components.logger.forComponent('libp2p:tcp');
|
|
44
|
-
this.opts = options;
|
|
45
|
-
this.components = components;
|
|
46
|
-
if (components.metrics != null) {
|
|
47
|
-
this.metrics = {
|
|
48
|
-
dialerEvents: components.metrics.registerCounterGroup('libp2p_tcp_dialer_events_total', {
|
|
49
|
-
label: 'event',
|
|
50
|
-
help: 'Total count of TCP dialer events by type'
|
|
51
|
-
})
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
[transportSymbol] = true;
|
|
56
|
-
[Symbol.toStringTag] = '@libp2p/tcp';
|
|
57
|
-
[serviceCapabilities] = [
|
|
58
|
-
'@libp2p/transport'
|
|
59
|
-
];
|
|
60
|
-
async dial(ma, options) {
|
|
61
|
-
options.keepAlive = options.keepAlive ?? true;
|
|
62
|
-
options.noDelay = options.noDelay ?? true;
|
|
63
|
-
// options.signal destroys the socket before 'connect' event
|
|
64
|
-
const socket = await this._connect(ma, options);
|
|
65
|
-
// Avoid uncaught errors caused by unstable connections
|
|
66
|
-
socket.on('error', err => {
|
|
67
|
-
this.log('socket error', err);
|
|
68
|
-
});
|
|
69
|
-
const maConn = toMultiaddrConnection(socket, {
|
|
70
|
-
remoteAddr: ma,
|
|
71
|
-
socketInactivityTimeout: this.opts.outboundSocketInactivityTimeout,
|
|
72
|
-
socketCloseTimeout: this.opts.socketCloseTimeout,
|
|
73
|
-
metrics: this.metrics?.dialerEvents,
|
|
74
|
-
logger: this.components.logger
|
|
75
|
-
});
|
|
76
|
-
const onAbort = () => {
|
|
77
|
-
maConn.close().catch(err => {
|
|
78
|
-
this.log.error('Error closing maConn after abort', err);
|
|
79
|
-
});
|
|
80
|
-
};
|
|
81
|
-
options.signal?.addEventListener('abort', onAbort, { once: true });
|
|
82
|
-
this.log('new outbound connection %s', maConn.remoteAddr);
|
|
83
|
-
const conn = await options.upgrader.upgradeOutbound(maConn);
|
|
84
|
-
this.log('outbound connection %s upgraded', maConn.remoteAddr);
|
|
85
|
-
options.signal?.removeEventListener('abort', onAbort);
|
|
86
|
-
if (options.signal?.aborted === true) {
|
|
87
|
-
conn.close().catch(err => {
|
|
88
|
-
this.log.error('Error closing conn after abort', err);
|
|
89
|
-
});
|
|
90
|
-
throw new AbortError();
|
|
91
|
-
}
|
|
92
|
-
return conn;
|
|
93
|
-
}
|
|
94
|
-
async _connect(ma, options) {
|
|
95
|
-
options.signal?.throwIfAborted();
|
|
96
|
-
options.onProgress?.(new CustomProgressEvent('tcp:open-connection'));
|
|
97
|
-
return new Promise((resolve, reject) => {
|
|
98
|
-
const start = Date.now();
|
|
99
|
-
const cOpts = multiaddrToNetConfig(ma, {
|
|
100
|
-
...(this.opts.dialOpts ?? {}),
|
|
101
|
-
...options
|
|
102
|
-
});
|
|
103
|
-
this.log('dialing %a', ma);
|
|
104
|
-
const rawSocket = net.connect(cOpts);
|
|
105
|
-
const onError = (err) => {
|
|
106
|
-
const cOptsStr = cOpts.path ?? `${cOpts.host ?? ''}:${cOpts.port}`;
|
|
107
|
-
err.message = `connection error ${cOptsStr}: ${err.message}`;
|
|
108
|
-
this.metrics?.dialerEvents.increment({ error: true });
|
|
109
|
-
done(err);
|
|
110
|
-
};
|
|
111
|
-
const onTimeout = () => {
|
|
112
|
-
this.log('connection timeout %a', ma);
|
|
113
|
-
this.metrics?.dialerEvents.increment({ timeout: true });
|
|
114
|
-
const err = new CodeError(`connection timeout after ${Date.now() - start}ms`, 'ERR_CONNECT_TIMEOUT');
|
|
115
|
-
// Note: this will result in onError() being called
|
|
116
|
-
rawSocket.emit('error', err);
|
|
117
|
-
};
|
|
118
|
-
const onConnect = () => {
|
|
119
|
-
this.log('connection opened %a', ma);
|
|
120
|
-
this.metrics?.dialerEvents.increment({ connect: true });
|
|
121
|
-
done();
|
|
122
|
-
};
|
|
123
|
-
const onAbort = () => {
|
|
124
|
-
this.log('connection aborted %a', ma);
|
|
125
|
-
this.metrics?.dialerEvents.increment({ abort: true });
|
|
126
|
-
rawSocket.destroy();
|
|
127
|
-
done(new AbortError());
|
|
128
|
-
};
|
|
129
|
-
const done = (err) => {
|
|
130
|
-
rawSocket.removeListener('error', onError);
|
|
131
|
-
rawSocket.removeListener('timeout', onTimeout);
|
|
132
|
-
rawSocket.removeListener('connect', onConnect);
|
|
133
|
-
if (options.signal != null) {
|
|
134
|
-
options.signal.removeEventListener('abort', onAbort);
|
|
135
|
-
}
|
|
136
|
-
if (err != null) {
|
|
137
|
-
reject(err);
|
|
138
|
-
return;
|
|
139
|
-
}
|
|
140
|
-
resolve(rawSocket);
|
|
141
|
-
};
|
|
142
|
-
rawSocket.on('error', onError);
|
|
143
|
-
rawSocket.on('timeout', onTimeout);
|
|
144
|
-
rawSocket.on('connect', onConnect);
|
|
145
|
-
if (options.signal != null) {
|
|
146
|
-
options.signal.addEventListener('abort', onAbort);
|
|
147
|
-
}
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
/**
|
|
151
|
-
* Creates a TCP listener. The provided `handler` function will be called
|
|
152
|
-
* anytime a new incoming Connection has been successfully upgraded via
|
|
153
|
-
* `upgrader.upgradeInbound`.
|
|
154
|
-
*/
|
|
155
|
-
createListener(options) {
|
|
156
|
-
return new TCPListener({
|
|
157
|
-
...(this.opts.listenOpts ?? {}),
|
|
158
|
-
...options,
|
|
159
|
-
maxConnections: this.opts.maxConnections,
|
|
160
|
-
backlog: this.opts.backlog,
|
|
161
|
-
closeServerOnMaxConnections: this.opts.closeServerOnMaxConnections,
|
|
162
|
-
socketInactivityTimeout: this.opts.inboundSocketInactivityTimeout,
|
|
163
|
-
socketCloseTimeout: this.opts.socketCloseTimeout,
|
|
164
|
-
metrics: this.components.metrics,
|
|
165
|
-
logger: this.components.logger
|
|
166
|
-
});
|
|
167
|
-
}
|
|
168
|
-
/**
|
|
169
|
-
* Takes a list of `Multiaddr`s and returns only valid TCP addresses
|
|
170
|
-
*/
|
|
171
|
-
listenFilter(multiaddrs) {
|
|
172
|
-
multiaddrs = Array.isArray(multiaddrs) ? multiaddrs : [multiaddrs];
|
|
173
|
-
return multiaddrs.filter(ma => {
|
|
174
|
-
if (ma.protoCodes().includes(CODE_CIRCUIT)) {
|
|
175
|
-
return false;
|
|
176
|
-
}
|
|
177
|
-
if (ma.protoCodes().includes(CODE_UNIX)) {
|
|
178
|
-
return true;
|
|
179
|
-
}
|
|
180
|
-
return mafmt.TCP.matches(ma.decapsulateCode(CODE_P2P));
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
|
-
/**
|
|
184
|
-
* Filter check for all Multiaddrs that this transport can dial
|
|
185
|
-
*/
|
|
186
|
-
dialFilter(multiaddrs) {
|
|
187
|
-
return this.listenFilter(multiaddrs);
|
|
188
|
-
}
|
|
189
|
-
}
|
|
29
|
+
import { TCP } from './tcp.js';
|
|
190
30
|
export function tcp(init = {}) {
|
|
191
31
|
return (components) => {
|
|
192
32
|
return new TCP(components, init);
|
package/dist/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAiG9B,MAAM,UAAU,GAAG,CAAE,OAAmB,EAAE;IACxC,OAAO,CAAC,UAAyB,EAAE,EAAE;QACnC,OAAO,IAAI,GAAG,CAAC,UAAU,EAAE,IAAI,CAAC,CAAA;IAClC,CAAC,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @packageDocumentation
|
|
3
|
+
*
|
|
4
|
+
* A [libp2p transport](https://docs.libp2p.io/concepts/transports/overview/) based on the TCP networking stack.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
*
|
|
8
|
+
* ```TypeScript
|
|
9
|
+
* import { createLibp2p } from 'libp2p'
|
|
10
|
+
* import { tcp } from '@libp2p/tcp'
|
|
11
|
+
* import { multiaddr } from '@multiformats/multiaddr'
|
|
12
|
+
*
|
|
13
|
+
* const node = await createLibp2p({
|
|
14
|
+
* transports: [
|
|
15
|
+
* tcp()
|
|
16
|
+
* ]
|
|
17
|
+
* })
|
|
18
|
+
*
|
|
19
|
+
* const ma = multiaddr('/ip4/123.123.123.123/tcp/1234')
|
|
20
|
+
*
|
|
21
|
+
* // dial a TCP connection, timing out after 10 seconds
|
|
22
|
+
* const connection = await node.dial(ma, {
|
|
23
|
+
* signal: AbortSignal.timeout(10_000)
|
|
24
|
+
* })
|
|
25
|
+
*
|
|
26
|
+
* // use connection...
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
import { serviceCapabilities, transportSymbol } from '@libp2p/interface';
|
|
30
|
+
import type { TCPDialEvents } from './index.js';
|
|
31
|
+
import type { Connection, Transport, Listener } from '@libp2p/interface';
|
|
32
|
+
import type { Multiaddr } from '@multiformats/multiaddr';
|
|
33
|
+
export declare class TCP implements Transport<TCPDialEvents> {
|
|
34
|
+
private readonly opts;
|
|
35
|
+
private readonly metrics?;
|
|
36
|
+
private readonly components;
|
|
37
|
+
private readonly log;
|
|
38
|
+
constructor();
|
|
39
|
+
readonly [transportSymbol] = true;
|
|
40
|
+
readonly [Symbol.toStringTag] = "@libp2p/tcp";
|
|
41
|
+
readonly [serviceCapabilities]: string[];
|
|
42
|
+
dial(): Promise<Connection>;
|
|
43
|
+
createListener(): Listener;
|
|
44
|
+
listenFilter(): Multiaddr[];
|
|
45
|
+
dialFilter(): Multiaddr[];
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=tcp.browser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tcp.browser.d.ts","sourceRoot":"","sources":["../../src/tcp.browser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACxE,OAAO,KAAK,EAAiB,aAAa,EAA0B,MAAM,YAAY,CAAA;AACtF,OAAO,KAAK,EAAU,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAChF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAExD,qBAAa,GAAI,YAAW,SAAS,CAAC,aAAa,CAAC;IAClD,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAY;IACjC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAY;IACrC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAe;IAC1C,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAQ;;IAM5B,QAAQ,CAAC,CAAC,eAAe,CAAC,QAAO;IAEjC,QAAQ,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,iBAAgB;IAE7C,QAAQ,CAAC,CAAC,mBAAmB,CAAC,EAAE,MAAM,EAAE,CAEvC;IAEK,IAAI,IAAK,OAAO,CAAC,UAAU,CAAC;IAIlC,cAAc,IAAK,QAAQ;IAI3B,YAAY,IAAK,SAAS,EAAE;IAI5B,UAAU,IAAK,SAAS,EAAE;CAG3B"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @packageDocumentation
|
|
3
|
+
*
|
|
4
|
+
* A [libp2p transport](https://docs.libp2p.io/concepts/transports/overview/) based on the TCP networking stack.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
*
|
|
8
|
+
* ```TypeScript
|
|
9
|
+
* import { createLibp2p } from 'libp2p'
|
|
10
|
+
* import { tcp } from '@libp2p/tcp'
|
|
11
|
+
* import { multiaddr } from '@multiformats/multiaddr'
|
|
12
|
+
*
|
|
13
|
+
* const node = await createLibp2p({
|
|
14
|
+
* transports: [
|
|
15
|
+
* tcp()
|
|
16
|
+
* ]
|
|
17
|
+
* })
|
|
18
|
+
*
|
|
19
|
+
* const ma = multiaddr('/ip4/123.123.123.123/tcp/1234')
|
|
20
|
+
*
|
|
21
|
+
* // dial a TCP connection, timing out after 10 seconds
|
|
22
|
+
* const connection = await node.dial(ma, {
|
|
23
|
+
* signal: AbortSignal.timeout(10_000)
|
|
24
|
+
* })
|
|
25
|
+
*
|
|
26
|
+
* // use connection...
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
import { serviceCapabilities, transportSymbol } from '@libp2p/interface';
|
|
30
|
+
export class TCP {
|
|
31
|
+
opts;
|
|
32
|
+
metrics;
|
|
33
|
+
components;
|
|
34
|
+
log;
|
|
35
|
+
constructor() {
|
|
36
|
+
throw new Error('TCP connections are not possible in browsers');
|
|
37
|
+
}
|
|
38
|
+
[transportSymbol] = true;
|
|
39
|
+
[Symbol.toStringTag] = '@libp2p/tcp';
|
|
40
|
+
[serviceCapabilities] = [
|
|
41
|
+
'@libp2p/transport'
|
|
42
|
+
];
|
|
43
|
+
async dial() {
|
|
44
|
+
throw new Error('TCP connections are not possible in browsers');
|
|
45
|
+
}
|
|
46
|
+
createListener() {
|
|
47
|
+
throw new Error('TCP connections are not possible in browsers');
|
|
48
|
+
}
|
|
49
|
+
listenFilter() {
|
|
50
|
+
return [];
|
|
51
|
+
}
|
|
52
|
+
dialFilter() {
|
|
53
|
+
return [];
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=tcp.browser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tcp.browser.js","sourceRoot":"","sources":["../../src/tcp.browser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAKxE,MAAM,OAAO,GAAG;IACG,IAAI,CAAY;IAChB,OAAO,CAAa;IACpB,UAAU,CAAe;IACzB,GAAG,CAAQ;IAE5B;QACE,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAA;IACjE,CAAC;IAEQ,CAAC,eAAe,CAAC,GAAG,IAAI,CAAA;IAExB,CAAC,MAAM,CAAC,WAAW,CAAC,GAAG,aAAa,CAAA;IAEpC,CAAC,mBAAmB,CAAC,GAAa;QACzC,mBAAmB;KACpB,CAAA;IAED,KAAK,CAAC,IAAI;QACR,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAA;IACjE,CAAC;IAED,cAAc;QACZ,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAA;IACjE,CAAC;IAED,YAAY;QACV,OAAO,EAAE,CAAA;IACX,CAAC;IAED,UAAU;QACR,OAAO,EAAE,CAAA;IACX,CAAC;CACF"}
|