@libp2p/autonat 1.1.4 → 1.1.5
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/package.json +7 -7
package/dist/index.min.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PAutonat = factory()}(typeof self !== 'undefined' ? self : this, function () {
|
|
2
|
-
"use strict";var Libp2PAutonat=(()=>{var Sn=Object.create;var Ut=Object.defineProperty;var vn=Object.getOwnPropertyDescriptor;var Ln=Object.getOwnPropertyNames;var Rn=Object.getPrototypeOf,Tn=Object.prototype.hasOwnProperty;var dr=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),N=(r,t)=>{for(var e in t)Ut(r,e,{get:t[e],enumerable:!0})},pr=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Ln(t))!Tn.call(r,o)&&o!==e&&Ut(r,o,{get:()=>t[o],enumerable:!(n=vn(t,o))||n.enumerable});return r};var mr=(r,t,e)=>(e=r!=null?Sn(Rn(r)):{},pr(t||!r||!r.__esModule?Ut(e,"default",{value:r,enumerable:!0}):e,r)),Dn=r=>pr(Ut({},"__esModule",{value:!0}),r);var $r=dr(Rt=>{(function(){var r,t,e,n,o,i,c,u;u=function(f){var s,l,a,h;return s=(f&255<<24)>>>24,l=(f&255<<16)>>>16,a=(f&65280)>>>8,h=f&255,[s,l,a,h].join(".")},c=function(f){var s,l,a,h,p,d;for(s=[],a=h=0;h<=3&&f.length!==0;a=++h){if(a>0){if(f[0]!==".")throw new Error("Invalid IP");f=f.substring(1)}d=t(f),p=d[0],l=d[1],f=f.substring(l),s.push(p)}if(f.length!==0)throw new Error("Invalid IP");switch(s.length){case 1:if(s[0]>4294967295)throw new Error("Invalid IP");return s[0]>>>0;case 2:if(s[0]>255||s[1]>16777215)throw new Error("Invalid IP");return(s[0]<<24|s[1])>>>0;case 3:if(s[0]>255||s[1]>255||s[2]>65535)throw new Error("Invalid IP");return(s[0]<<24|s[1]<<16|s[2])>>>0;case 4:if(s[0]>255||s[1]>255||s[2]>255||s[3]>255)throw new Error("Invalid IP");return(s[0]<<24|s[1]<<16|s[2]<<8|s[3])>>>0;default:throw new Error("Invalid IP")}},e=function(f){return f.charCodeAt(0)},n=e("0"),i=e("a"),o=e("A"),t=function(f){var s,l,a,h,p;for(h=0,s=10,l="9",a=0,f.length>1&&f[a]==="0"&&(f[a+1]==="x"||f[a+1]==="X"?(a+=2,s=16):"0"<=f[a+1]&&f[a+1]<="9"&&(a++,s=8,l="7")),p=a;a<f.length;){if("0"<=f[a]&&f[a]<=l)h=h*s+(e(f[a])-n)>>>0;else if(s===16)if("a"<=f[a]&&f[a]<="f")h=h*s+(10+e(f[a])-i)>>>0;else if("A"<=f[a]&&f[a]<="F")h=h*s+(10+e(f[a])-o)>>>0;else break;else break;if(h>4294967295)throw new Error("too large");a++}if(a===p)throw new Error("empty octet");return[h,a]},r=function(){function f(s,l){var a,h,p,d;if(typeof s!="string")throw new Error("Missing `net' parameter");if(l||(d=s.split("/",2),s=d[0],l=d[1]),l||(l=32),typeof l=="string"&&l.indexOf(".")>-1){try{this.maskLong=c(l)}catch(m){throw a=m,new Error("Invalid mask: "+l)}for(h=p=32;p>=0;h=--p)if(this.maskLong===4294967295<<32-h>>>0){this.bitmask=h;break}}else if(l||l===0)this.bitmask=parseInt(l,10),this.maskLong=0,this.bitmask>0&&(this.maskLong=4294967295<<32-this.bitmask>>>0);else throw new Error("Invalid mask: empty");try{this.netLong=(c(s)&this.maskLong)>>>0}catch(m){throw a=m,new Error("Invalid net address: "+s)}if(!(this.bitmask<=32))throw new Error("Invalid mask for ip4: "+l);this.size=Math.pow(2,32-this.bitmask),this.base=u(this.netLong),this.mask=u(this.maskLong),this.hostmask=u(~this.maskLong),this.first=this.bitmask<=30?u(this.netLong+1):this.base,this.last=this.bitmask<=30?u(this.netLong+this.size-2):u(this.netLong+this.size-1),this.broadcast=this.bitmask<=30?u(this.netLong+this.size-1):void 0}return f.prototype.contains=function(s){return typeof s=="string"&&(s.indexOf("/")>0||s.split(".").length!==4)&&(s=new f(s)),s instanceof f?this.contains(s.base)&&this.contains(s.broadcast||s.last):(c(s)&this.maskLong)>>>0===(this.netLong&this.maskLong)>>>0},f.prototype.next=function(s){return s==null&&(s=1),new f(u(this.netLong+this.size*s),this.mask)},f.prototype.forEach=function(s){var l,a,h;for(h=c(this.first),a=c(this.last),l=0;h<=a;)s(u(h),h,l),l++,h++},f.prototype.toString=function(){return this.base+"/"+this.bitmask},f}(),Rt.ip2long=c,Rt.long2ip=u,Rt.Netmask=r}).call(Rt)});var an=dr((Vc,sn)=>{"use strict";function on(r,t){for(let e in t)Object.defineProperty(r,e,{value:t[e],enumerable:!0,configurable:!0});return r}function wi(r,t,e){if(!r||typeof r=="string")throw new TypeError("Please pass an Error to err-code");e||(e={}),typeof t=="object"&&(e=t,t=""),t&&(e.code=t);try{return on(r,e)}catch{e.message=r.message,e.stack=r.stack;let o=function(){};return o.prototype=Object.create(Object.getPrototypeOf(r)),on(new o,e)}}sn.exports=wi});var ji={};N(ji,{autoNAT:()=>qi});var te=Symbol.for("@libp2p/peer-id");var W=class extends Error{code;props;constructor(t,e,n){super(t),this.code=e,this.name=n?.name??"CodeError",this.props=n??{}}};var ee="ERR_TIMEOUT";var re=(r,...t)=>{try{[...t]}catch{}};var ae={};N(ae,{base58btc:()=>S,base58flickr:()=>kn});var Wi=new Uint8Array(0);function gr(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])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 yr(r){return new TextEncoder().encode(r)}function br(r){return new TextDecoder().decode(r)}function Fn(r,t){if(r.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),n=0;n<e.length;n++)e[n]=255;for(var o=0;o<r.length;o++){var i=r.charAt(o),c=i.charCodeAt(0);if(e[c]!==255)throw new TypeError(i+" is ambiguous");e[c]=o}var u=r.length,f=r.charAt(0),s=Math.log(u)/Math.log(256),l=Math.log(256)/Math.log(u);function a(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 m=0,g=0,E=0,D=d.length;E!==D&&d[E]===0;)E++,m++;for(var I=(D-E)*l+1>>>0,F=new Uint8Array(I);E!==D;){for(var _=d[E],q=0,O=I-1;(_!==0||q<g)&&O!==-1;O--,q++)_+=256*F[O]>>>0,F[O]=_%u>>>0,_=_/u>>>0;if(_!==0)throw new Error("Non-zero carry");g=q,E++}for(var B=I-g;B!==I&&F[B]===0;)B++;for(var Nt=f.repeat(m);B<I;++B)Nt+=r.charAt(F[B]);return Nt}function h(d){if(typeof d!="string")throw new TypeError("Expected String");if(d.length===0)return new Uint8Array;var m=0;if(d[m]!==" "){for(var g=0,E=0;d[m]===f;)g++,m++;for(var D=(d.length-m)*s+1>>>0,I=new Uint8Array(D);d[m];){var F=e[d.charCodeAt(m)];if(F===255)return;for(var _=0,q=D-1;(F!==0||_<E)&&q!==-1;q--,_++)F+=u*I[q]>>>0,I[q]=F%256>>>0,F=F/256>>>0;if(F!==0)throw new Error("Non-zero carry");E=_,m++}if(d[m]!==" "){for(var O=D-E;O!==D&&I[O]===0;)O++;for(var B=new Uint8Array(g+(D-O)),Nt=g;O!==D;)B[Nt++]=I[O++];return B}}}function p(d){var m=h(d);if(m)return m;throw new Error(`Non-${t} character`)}return{encode:a,decodeUnsafe:h,decode:p}}var Nn=Fn,Un=Nn,xr=Un;var ne=class{name;prefix;baseEncode;constructor(t,e,n){this.name=t,this.prefix=e,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},oe=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,e,n){if(this.name=t,this.prefix=e,e.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=e.codePointAt(0),this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return Er(this,t)}},ie=class{decoders;constructor(t){this.decoders=t}or(t){return Er(this,t)}decode(t){let e=t[0],n=this.decoders[e];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Er(r,t){return new ie({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var se=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,e,n,o){this.name=t,this.prefix=e,this.baseEncode=n,this.baseDecode=o,this.encoder=new ne(t,e,n),this.decoder=new oe(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function ot({name:r,prefix:t,encode:e,decode:n}){return new se(r,t,e,n)}function j({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=xr(e,r);return ot({prefix:t,name:r,encode:n,decode:i=>M(o(i))})}function _n(r,t,e,n){let o={};for(let l=0;l<t.length;++l)o[t[l]]=l;let i=r.length;for(;r[i-1]==="=";)--i;let c=new Uint8Array(i*e/8|0),u=0,f=0,s=0;for(let l=0;l<i;++l){let a=o[r[l]];if(a===void 0)throw new SyntaxError(`Non-${n} character`);f=f<<e|a,u+=e,u>=8&&(u-=8,c[s++]=255&f>>u)}if(u>=e||255&f<<8-u)throw new SyntaxError("Unexpected end of data");return c}function Pn(r,t,e){let n=t[t.length-1]==="=",o=(1<<e)-1,i="",c=0,u=0;for(let f=0;f<r.length;++f)for(u=u<<8|r[f],c+=8;c>e;)c-=e,i+=t[o&u>>c];if(c!==0&&(i+=t[o&u<<e-c]),n)for(;i.length*e&7;)i+="=";return i}function x({name:r,prefix:t,bitsPerChar:e,alphabet:n}){return ot({prefix:t,name:r,encode(o){return Pn(o,n,e)},decode(o){return _n(o,n,e,r)}})}var S=j({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),kn=j({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var ce={};N(ce,{base10:()=>On});var On=j({prefix:"9",name:"base10",alphabet:"0123456789"});var ue={};N(ue,{base16:()=>Cn,base16upper:()=>Bn});var Cn=x({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Bn=x({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var le={};N(le,{base2:()=>Mn});var Mn=x({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var he={};N(he,{base256emoji:()=>qn});var Ar=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}"),Vn=Ar.reduce((r,t,e)=>(r[e]=t,r),[]),zn=Ar.reduce((r,t,e)=>(r[t.codePointAt(0)]=e,r),[]);function $n(r){return r.reduce((t,e)=>(t+=Vn[e],t),"")}function Gn(r){let t=[];for(let e of r){let n=zn[e.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${e}`);t.push(n)}return new Uint8Array(t)}var qn=ot({prefix:"\u{1F680}",name:"base256emoji",encode:$n,decode:Gn});var fe={};N(fe,{base32:()=>V,base32hex:()=>Kn,base32hexpad:()=>Wn,base32hexpadupper:()=>Jn,base32hexupper:()=>Qn,base32pad:()=>Hn,base32padupper:()=>Xn,base32upper:()=>jn,base32z:()=>Zn});var V=x({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),jn=x({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Hn=x({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Xn=x({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Kn=x({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Qn=x({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Wn=x({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Jn=x({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Zn=x({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var de={};N(de,{base36:()=>Yn,base36upper:()=>to});var Yn=j({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),to=j({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var pe={};N(pe,{base64:()=>eo,base64pad:()=>ro,base64url:()=>no,base64urlpad:()=>oo});var eo=x({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),ro=x({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),no=x({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),oo=x({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var me={};N(me,{base8:()=>io});var io=x({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var ge={};N(ge,{identity:()=>so});var so=ot({prefix:"\0",name:"identity",encode:r=>br(r),decode:r=>yr(r)});var fs=new TextEncoder,ds=new TextDecoder;var be={};N(be,{identity:()=>Et});var uo=vr,Ir=128,lo=127,ho=~lo,fo=Math.pow(2,31);function vr(r,t,e){t=t||[],e=e||0;for(var n=e;r>=fo;)t[e++]=r&255|Ir,r/=128;for(;r&ho;)t[e++]=r&255|Ir,r>>>=7;return t[e]=r|0,vr.bytes=e-n+1,t}var po=ye,mo=128,Sr=127;function ye(r,n){var e=0,n=n||0,o=0,i=n,c,u=r.length;do{if(i>=u)throw ye.bytes=0,new RangeError("Could not decode varint");c=r[i++],e+=o<28?(c&Sr)<<o:(c&Sr)*Math.pow(2,o),o+=7}while(c>=mo);return ye.bytes=i-n,e}var go=Math.pow(2,7),yo=Math.pow(2,14),bo=Math.pow(2,21),wo=Math.pow(2,28),xo=Math.pow(2,35),Eo=Math.pow(2,42),Ao=Math.pow(2,49),Io=Math.pow(2,56),So=Math.pow(2,63),vo=function(r){return r<go?1:r<yo?2:r<bo?3:r<wo?4:r<xo?5:r<Eo?6:r<Ao?7:r<Io?8:r<So?9:10},Lo={encode:uo,decode:po,encodingLength:vo},Ro=Lo,wt=Ro;function xt(r,t=0){return[wt.decode(r,t),wt.decode.bytes]}function it(r,t,e=0){return wt.encode(r,t,e),t}function st(r){return wt.encodingLength(r)}function H(r,t){let e=t.byteLength,n=st(r),o=n+st(e),i=new Uint8Array(o+e);return it(r,i,0),it(e,i,n),i.set(t,o),new at(r,e,t,i)}function J(r){let t=M(r),[e,n]=xt(t),[o,i]=xt(t.subarray(n)),c=t.subarray(n+i);if(c.byteLength!==o)throw new Error("Incorrect length");return new at(e,o,c,t)}function Lr(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&gr(r.bytes,e.bytes)}}var at=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=n,this.bytes=o}};var Rr=0,To="identity",Tr=M;function Do(r){return H(Rr,Tr(r))}var Et={code:Rr,name:To,encode:Tr,digest:Do};var Ee={};N(Ee,{sha256:()=>Pt,sha512:()=>Fo});function xe({name:r,code:t,encode:e}){return new we(r,t,e)}var we=class{name;code;encode;constructor(t,e,n){this.name=t,this.code=e,this.encode=n}digest(t){if(t instanceof Uint8Array){let e=this.encode(t);return e instanceof Uint8Array?H(this.code,e):e.then(n=>H(this.code,n))}else throw Error("Unknown type, must be binary type")}};function Fr(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var Pt=xe({name:"sha2-256",code:18,encode:Fr("SHA-256")}),Fo=xe({name:"sha2-512",code:19,encode:Fr("SHA-512")});function Nr(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return Uo(e,Ae(r),t??S.encoder);default:return _o(e,Ae(r),t??V.encoder)}}var Ur=new WeakMap;function Ae(r){let t=Ur.get(r);if(t==null){let e=new Map;return Ur.set(r,e),e}return t}var P=class r{code;version;multihash;bytes;"/";constructor(t,e,n,o){this.code=e,this.version=t,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:t,multihash:e}=this;if(t!==At)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==Po)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(e)}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:t,digest:e}=this.multihash,n=H(t,e);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(t){return r.equals(this,t)}static equals(t,e){let n=e;return n!=null&&t.code===n.code&&t.version===n.version&&Lr(t.multihash,n.multihash)}toString(t){return Nr(this,t)}toJSON(){return{"/":Nr(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let e=t;if(e instanceof r)return e;if(e["/"]!=null&&e["/"]===e.bytes||e.asCID===e){let{version:n,code:o,multihash:i,bytes:c}=e;return new r(n,o,i,c??_r(n,o,i.bytes))}else if(e[ko]===!0){let{version:n,multihash:o,code:i}=e,c=J(o);return r.create(n,i,c)}else return null}static create(t,e,n){if(typeof e!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(e!==At)throw new Error(`Version 0 CID must use dag-pb (code: ${At}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=_r(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,At,t)}static createV1(t,e){return r.create(1,t,e)}static decode(t){let[e,n]=r.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return e}static decodeFirst(t){let e=r.inspectBytes(t),n=e.size-e.multihashSize,o=M(t.subarray(n,n+e.multihashSize));if(o.byteLength!==e.multihashSize)throw new Error("Incorrect length");let i=o.subarray(e.multihashSize-e.digestSize),c=new at(e.multihashCode,e.digestSize,i,o);return[e.version===0?r.createV0(c):r.createV1(e.codec,c),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[a,h]=xt(t.subarray(e));return e+=h,a},o=n(),i=At;if(o===18?(o=0,e=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let c=e,u=n(),f=n(),s=e+f,l=s-c;return{version:o,codec:i,multihashCode:u,digestSize:f,multihashSize:l,size:s}}static parse(t,e){let[n,o]=No(t,e),i=r.decode(o);if(i.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Ae(i).set(n,t),i}};function No(r,t){switch(r[0]){case"Q":{let e=t??S;return[S.prefix,e.decode(`${S.prefix}${r}`)]}case S.prefix:{let e=t??S;return[S.prefix,e.decode(r)]}case V.prefix:{let e=t??V;return[V.prefix,e.decode(r)]}default:{if(t==null)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[r[0],t.decode(r)]}}}function Uo(r,t,e){let{prefix:n}=e;if(n!==S.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let o=t.get(n);if(o==null){let i=e.encode(r).slice(1);return t.set(n,i),i}else return o}function _o(r,t,e){let{prefix:n}=e,o=t.get(n);if(o==null){let i=e.encode(r);return t.set(n,i),i}else return o}var At=112,Po=18;function _r(r,t,e){let n=st(r),o=n+st(t),i=new Uint8Array(o+e.byteLength);return it(r,i,0),it(t,i,n),i.set(e,o),i}var ko=Symbol.for("@ipld/js-cid/CID");var X={...ge,...le,...me,...ce,...ue,...fe,...de,...ae,...pe,...he},Ps={...Ee,...be};function Y(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function z(r=0){return new Uint8Array(r)}function L(r=0){return new Uint8Array(r)}function kr(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var Pr=kr("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Ie=kr("ascii","a",r=>{let t="a";for(let e=0;e<r.length;e++)t+=String.fromCharCode(r[e]);return t},r=>{r=r.substring(1);let t=L(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),Oo={utf8:Pr,"utf-8":Pr,hex:X.base16,latin1:Ie,ascii:Ie,binary:Ie,...X},kt=Oo;function tt(r,t="utf8"){let e=kt[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function v(r,t="utf8"){let e=kt[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var Cr=Symbol.for("nodejs.util.inspect.custom"),Or=Object.values(X).map(r=>r.decoder).reduce((r,t)=>r.or(t),X.identity.decoder),Br=114,Mr=36,Vr=37,It=class{type;multihash;privateKey;publicKey;string;constructor(t){this.type=t.type,this.multihash=t.multihash,this.privateKey=t.privateKey,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[te]=!0;toString(){return this.string==null&&(this.string=S.encode(this.multihash.bytes).slice(1)),this.string}toCID(){return P.createV1(Br,this.multihash)}toBytes(){return this.multihash.bytes}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return Y(this.multihash.bytes,t);if(typeof t=="string")return Co(t).equals(this);if(t?.multihash?.bytes!=null)return Y(this.multihash.bytes,t.multihash.bytes);throw new Error("not valid Id")}[Cr](){return`PeerId(${this.toString()})`}},St=class extends It{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},vt=class extends It{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.multihash.digest}},Lt=class extends It{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.multihash.digest}},Se=2336,ve=class{type="url";multihash;privateKey;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=Et.digest(tt(this.url))}[Cr](){return`PeerId(${this.url})`}[te]=!0;toString(){return this.toCID().toString()}toCID(){return P.createV1(Se,this.multihash)}toBytes(){return this.toCID().bytes}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=v(t)),t.toString()===this.toString())}};function Co(r,t){if(t=t??Or,r.charAt(0)==="1"||r.charAt(0)==="Q"){let e=J(S.decode(`z${r}`));return r.startsWith("12D")?new vt({multihash:e}):r.startsWith("16U")?new Lt({multihash:e}):new St({multihash:e})}return Le(Or.decode(r))}function Le(r){try{let t=J(r);if(t.code===Et.code){if(t.digest.length===Mr)return new vt({multihash:t});if(t.digest.length===Vr)return new Lt({multihash:t})}if(t.code===Pt.code)return new St({multihash:t})}catch{return Bo(P.decode(r))}throw new Error("Supplied PeerID CID is invalid")}function Bo(r){if(r?.multihash==null||r.version==null||r.version===1&&r.code!==Br&&r.code!==Se)throw new Error("Supplied PeerID CID is invalid");if(r.code===Se){let e=v(r.multihash.digest);return new ve(new URL(e))}let t=r.multihash;if(t.code===Pt.code)return new St({multihash:r.multihash});if(t.code===Et.code){if(t.digest.length===Mr)return new vt({multihash:r.multihash});if(t.digest.length===Vr)return new Lt({multihash:r.multihash})}throw new Error("Supplied PeerID CID is invalid")}var Ot=class{index=0;input="";new(t){return this.index=0,this.input=t,this}readAtomically(t){let e=this.index,n=t();return n===void 0&&(this.index=e),n}parseWith(t){let e=t();if(this.index===this.input.length)return e}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(t){return this.readAtomically(()=>{let e=this.readChar();if(e===t)return e})}readSeparator(t,e,n){return this.readAtomically(()=>{if(!(e>0&&this.readGivenChar(t)===void 0))return n()})}readNumber(t,e,n,o){return this.readAtomically(()=>{let i=0,c=0,u=this.peekChar();if(u===void 0)return;let f=u==="0",s=2**(8*o)-1;for(;;){let l=this.readAtomically(()=>{let a=this.readChar();if(a===void 0)return;let h=Number.parseInt(a,t);if(!Number.isNaN(h))return h});if(l===void 0)break;if(i*=t,i+=l,i>s||(c+=1,e!==void 0&&c>e))return}if(c!==0)return!n&&f&&c>1?void 0:i})}readIPv4Addr(){return this.readAtomically(()=>{let t=new Uint8Array(4);for(let e=0;e<t.length;e++){let n=this.readSeparator(".",e,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;t[e]=n}return t})}readIPv6Addr(){let t=e=>{for(let n=0;n<e.length/2;n++){let o=n*2;if(n<e.length-3){let c=this.readSeparator(":",n,()=>this.readIPv4Addr());if(c!==void 0)return e[o]=c[0],e[o+1]=c[1],e[o+2]=c[2],e[o+3]=c[3],[o+4,!0]}let i=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(i===void 0)return[o,!1];e[o]=i>>8,e[o+1]=i&255}return[e.length,!1]};return this.readAtomically(()=>{let e=new Uint8Array(16),[n,o]=t(e);if(n===16)return e;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let i=new Uint8Array(14),c=16-(n+2),[u]=t(i.subarray(0,c));return e.set(i.subarray(0,u),16-u),e})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var zr=45,Mo=15,ct=new Ot;function Re(r){if(!(r.length>Mo))return ct.new(r).parseWith(()=>ct.readIPv4Addr())}function Te(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>zr))return ct.new(r).parseWith(()=>ct.readIPv6Addr())}function Ct(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>zr))return ct.new(r).parseWith(()=>ct.readIPAddr())}function Bt(r){return!!Re(r)}function Mt(r){return!!Te(r)}function Vt(r){return!!Ct(r)}var Gr=mr($r(),1),Vo=["0.0.0.0/8","10.0.0.0/8","100.64.0.0/10","127.0.0.0/8","169.254.0.0/16","172.16.0.0/12","192.0.0.0/24","192.0.0.0/29","192.0.0.8/32","192.0.0.9/32","192.0.0.10/32","192.0.0.170/32","192.0.0.171/32","192.0.2.0/24","192.31.196.0/24","192.52.193.0/24","192.88.99.0/24","192.168.0.0/16","192.175.48.0/24","198.18.0.0/15","198.51.100.0/24","203.0.113.0/24","240.0.0.0/4","255.255.255.255/32"],zo=Vo.map(r=>new Gr.Netmask(r));function De(r){for(let t of zo)if(t.contains(r))return!0;return!1}function $o(r){return/^::ffff:([0-9a-fA-F]{1,4}):([0-9a-fA-F]{1,4})$/.test(r)}function Go(r){let t=r.split(":");if(t.length<2)return!1;let e=t[t.length-1].padStart(4,"0"),n=t[t.length-2].padStart(4,"0"),o=`${parseInt(n.substring(0,2),16)}.${parseInt(n.substring(2),16)}.${parseInt(e.substring(0,2),16)}.${parseInt(e.substring(2),16)}`;return De(o)}function qo(r){return/^::ffff:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(r)}function jo(r){let t=r.split(":"),e=t[t.length-1];return De(e)}function Ho(r){return/^::$/.test(r)||/^::1$/.test(r)||/^64:ff9b::([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(r)||/^100::([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2001::([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2001:2[0-9a-fA-F]:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2001:db8:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2002:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^f[c-d]([0-9a-fA-F]{2,2}):/i.test(r)||/^fe[8-9a-bA-B][0-9a-fA-F]:/i.test(r)||/^ff([0-9a-fA-F]{2,2}):/i.test(r)}function Fe(r){return Bt(r)?De(r):$o(r)?Go(r):qo(r)?jo(r):Mt(r)?Ho(r):void 0}var Xo=Math.pow(2,7),Ko=Math.pow(2,14),Qo=Math.pow(2,21),Ne=Math.pow(2,28),Ue=Math.pow(2,35),_e=Math.pow(2,42),Pe=Math.pow(2,49),b=128,R=127;function A(r){if(r<Xo)return 1;if(r<Ko)return 2;if(r<Qo)return 3;if(r<Ne)return 4;if(r<Ue)return 5;if(r<_e)return 6;if(r<Pe)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function ke(r,t,e=0){switch(A(r)){case 8:t[e++]=r&255|b,r/=128;case 7:t[e++]=r&255|b,r/=128;case 6:t[e++]=r&255|b,r/=128;case 5:t[e++]=r&255|b,r/=128;case 4:t[e++]=r&255|b,r>>>=7;case 3:t[e++]=r&255|b,r>>>=7;case 2:t[e++]=r&255|b,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function Wo(r,t,e=0){switch(A(r)){case 8:t.set(e++,r&255|b),r/=128;case 7:t.set(e++,r&255|b),r/=128;case 6:t.set(e++,r&255|b),r/=128;case 5:t.set(e++,r&255|b),r/=128;case 4:t.set(e++,r&255|b),r>>>=7;case 3:t.set(e++,r&255|b),r>>>=7;case 2:t.set(e++,r&255|b),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function Oe(r,t){let e=r[t],n=0;if(n+=e&R,e<b||(e=r[t+1],n+=(e&R)<<7,e<b)||(e=r[t+2],n+=(e&R)<<14,e<b)||(e=r[t+3],n+=(e&R)<<21,e<b)||(e=r[t+4],n+=(e&R)*Ne,e<b)||(e=r[t+5],n+=(e&R)*Ue,e<b)||(e=r[t+6],n+=(e&R)*_e,e<b)||(e=r[t+7],n+=(e&R)*Pe,e<b))return n;throw new RangeError("Could not decode varint")}function Jo(r,t){let e=r.get(t),n=0;if(n+=e&R,e<b||(e=r.get(t+1),n+=(e&R)<<7,e<b)||(e=r.get(t+2),n+=(e&R)<<14,e<b)||(e=r.get(t+3),n+=(e&R)<<21,e<b)||(e=r.get(t+4),n+=(e&R)*Ne,e<b)||(e=r.get(t+5),n+=(e&R)*Ue,e<b)||(e=r.get(t+6),n+=(e&R)*_e,e<b)||(e=r.get(t+7),n+=(e&R)*Pe,e<b))return n;throw new RangeError("Could not decode varint")}function K(r,t,e=0){return t==null&&(t=L(A(r))),t instanceof Uint8Array?ke(r,t,e):Wo(r,t,e)}function $(r,t=0){return r instanceof Uint8Array?Oe(r,t):Jo(r,t)}function k(r,t){t==null&&(t=r.reduce((o,i)=>o+i.length,0));let e=L(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return e}var Ea=parseInt("0xFFFF",16),Aa=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);var Hr=Bt,ri=Mt,Ce=function(r){let t=0;if(r=r.toString().trim(),Hr(r)){let e=new Uint8Array(t+4);return r.split(/\./g).forEach(n=>{e[t++]=parseInt(n,10)&255}),e}if(ri(r)){let e=r.split(":",8),n;for(n=0;n<e.length;n++){let i=Hr(e[n]),c;i&&(c=Ce(e[n]),e[n]=v(c.slice(0,2),"base16")),c!=null&&++n<8&&e.splice(n,0,v(c.slice(2,4),"base16"))}if(e[0]==="")for(;e.length<8;)e.unshift("0");else if(e[e.length-1]==="")for(;e.length<8;)e.push("0");else if(e.length<8){for(n=0;n<e.length&&e[n]!=="";n++);let i=[n,1];for(n=9-e.length;n>0;n--)i.push("0");e.splice.apply(e,i)}let o=new Uint8Array(t+16);for(n=0;n<e.length;n++){let i=parseInt(e[n],16);o[t++]=i>>8&255,o[t++]=i&255}return o}throw new Error("invalid ip address")},Xr=function(r,t=0,e){t=~~t,e=e??r.length-t;let n=new DataView(r.buffer);if(e===4){let o=[];for(let i=0;i<e;i++)o.push(r[t+i]);return o.join(".")}if(e===16){let o=[];for(let i=0;i<e;i+=2)o.push(n.getUint16(t+i).toString(16));return o.join(":").replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}return""};var ut={},Be={},oi=[[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"]];oi.forEach(r=>{let t=ii(...r);Be[t.code]=t,ut[t.name]=t});function ii(r,t,e,n,o){return{code:r,size:t,name:e,resolvable:!!n,path:!!o}}function w(r){if(typeof r=="number"){if(Be[r]!=null)return Be[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(ut[r]!=null)return ut[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var nc=w("ip4"),oc=w("ip6"),ic=w("ipcidr");function $e(r,t){switch(w(r).code){case 4:case 41:return ai(t);case 42:return ze(t);case 6:case 273:case 33:case 132:return Wr(t).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return ze(t);case 421:return hi(t);case 444:return Qr(t);case 445:return Qr(t);case 466:return li(t);case 481:return globalThis.encodeURIComponent(ze(t));default:return v(t,"base16")}}function Ge(r,t){switch(w(r).code){case 4:return Kr(t);case 41:return Kr(t);case 42:return Ve(t);case 6:case 273:case 33:case 132:return qe(parseInt(t,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return Ve(t);case 421:return ci(t);case 444:return fi(t);case 445:return di(t);case 466:return ui(t);case 481:return Ve(globalThis.decodeURIComponent(t));default:return tt(t,"base16")}}var Me=Object.values(X).map(r=>r.decoder),si=function(){let r=Me[0].or(Me[1]);return Me.slice(2).forEach(t=>r=r.or(t)),r}();function Kr(r){if(!Vt(r))throw new Error("invalid ip address");return Ce(r)}function ai(r){let t=Xr(r,0,r.length);if(t==null)throw new Error("ipBuff is required");if(!Vt(t))throw new Error("invalid ip address");return t}function qe(r){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,r),new Uint8Array(t)}function Wr(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function Ve(r){let t=tt(r),e=Uint8Array.from(K(t.length));return k([e,t],e.length+t.length)}function ze(r){let t=$(r);if(r=r.slice(A(t)),r.length!==t)throw new Error("inconsistent lengths");return v(r)}function ci(r){let t;r[0]==="Q"||r[0]==="1"?t=J(S.decode(`z${r}`)).bytes:t=P.parse(r).multihash.bytes;let e=Uint8Array.from(K(t.length));return k([e,t],e.length+t.length)}function ui(r){let t=si.decode(r),e=Uint8Array.from(K(t.length));return k([e,t],e.length+t.length)}function li(r){let t=$(r),e=r.slice(A(t));if(e.length!==t)throw new Error("inconsistent lengths");return"u"+v(e,"base64url")}function hi(r){let t=$(r),e=r.slice(A(t));if(e.length!==t)throw new Error("inconsistent lengths");return v(e,"base58btc")}function fi(r){let t=r.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==16)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion address.`);let e=V.decode("b"+t[0]),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=qe(n);return k([e,o],e.length+o.length)}function di(r){let t=r.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==56)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion3 address.`);let e=V.decode(`b${t[0]}`),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=qe(n);return k([e,o],e.length+o.length)}function Qr(r){let t=r.slice(0,r.length-2),e=r.slice(r.length-2),n=v(t,"base32"),o=Wr(e);return`${n}:${o}`}function Jr(r){r=je(r);let t=[],e=[],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 c=o[i],u=w(c);if(u.size===0){t.push([u.code]),e.push([u.code]);continue}if(i++,i>=o.length)throw Yr("invalid address: "+r);if(u.path===!0){n=je(o.slice(i).join("/")),t.push([u.code,Ge(u.code,n)]),e.push([u.code,n]);break}let f=Ge(u.code,o[i]);t.push([u.code,f]),e.push([u.code,$e(u.code,f)])}return{string:Zr(e),bytes:Xe(t),tuples:t,stringTuples:e,path:n}}function He(r){let t=[],e=[],n=null,o=0;for(;o<r.length;){let i=$(r,o),c=A(i),u=w(i),f=pi(u,r.slice(o+c));if(f===0){t.push([i]),e.push([i]),o+=c;continue}let s=r.slice(o+c,o+c+f);if(o+=f+c,o>r.length)throw Yr("Invalid address Uint8Array: "+v(r,"base16"));t.push([i,s]);let l=$e(i,s);if(e.push([i,l]),u.path===!0){n=l;break}}return{bytes:Uint8Array.from(r),string:Zr(e),tuples:t,stringTuples:e,path:n}}function Zr(r){let t=[];return r.map(e=>{let n=w(e[0]);return t.push(n.name),e.length>1&&e[1]!=null&&t.push(e[1]),null}),je(t.join("/"))}function Xe(r){return k(r.map(t=>{let e=w(t[0]),n=Uint8Array.from(K(e.code));return t.length>1&&t[1]!=null&&(n=k([n,t[1]])),n}))}function pi(r,t){if(r.size>0)return r.size/8;if(r.size===0)return 0;{let e=$(t instanceof Uint8Array?t:Uint8Array.from(t));return e+A(e)}}function je(r){return"/"+r.trim().split("/").filter(t=>t).join("/")}function Yr(r){return new Error("Error parsing address: "+r)}var mi=Symbol.for("nodejs.util.inspect.custom"),Ke=Symbol.for("@multiformats/js-multiaddr/multiaddr"),gi=[w("dns").code,w("dns4").code,w("dns6").code,w("dnsaddr").code],$t=class r{bytes;#e;#t;#r;#n;[Ke]=!0;constructor(t){t==null&&(t="");let e;if(t instanceof Uint8Array)e=He(t);else if(typeof t=="string"){if(t.length>0&&t.charAt(0)!=="/")throw new Error(`multiaddr "${t}" must start with a "/"`);e=Jr(t)}else if(en(t))e=He(t.bytes);else throw new Error("addr must be a string, Buffer, or another Multiaddr");this.bytes=e.bytes,this.#e=e.string,this.#t=e.tuples,this.#r=e.stringTuples,this.#n=e.path}toString(){return this.#e}toJSON(){return this.toString()}toOptions(){let t,e,n,o,i="",c=w("tcp"),u=w("udp"),f=w("ip4"),s=w("ip6"),l=w("dns6"),a=w("ip6zone");for(let[p,d]of this.stringTuples())p===a.code&&(i=`%${d??""}`),gi.includes(p)&&(e=c.name,o=443,n=`${d??""}${i}`,t=p===l.code?6:4),(p===c.code||p===u.code)&&(e=w(p).name,o=parseInt(d??"")),(p===f.code||p===s.code)&&(e=w(p).name,n=`${d??""}${i}`,t=p===s.code?6:4);if(t==null||e==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:t,host:n,transport:e,port:o}}protos(){return this.#t.map(([t])=>Object.assign({},w(t)))}protoCodes(){return this.#t.map(([t])=>t)}protoNames(){return this.#t.map(([t])=>w(t).name)}tuples(){return this.#t}stringTuples(){return this.#r}encapsulate(t){return t=new r(t),new r(this.toString()+t.toString())}decapsulate(t){let e=t.toString(),n=this.toString(),o=n.lastIndexOf(e);if(o<0)throw new Error(`Address ${this.toString()} does not contain subaddress: ${t.toString()}`);return new r(n.slice(0,o))}decapsulateCode(t){let e=this.tuples();for(let n=e.length-1;n>=0;n--)if(e[n][0]===t)return new r(Xe(e.slice(0,n)));return this}getPeerId(){try{let t=[];this.stringTuples().forEach(([n,o])=>{n===ut.p2p.code&&t.push([n,o]),n===ut["p2p-circuit"].code&&(t=[])});let e=t.pop();if(e?.[1]!=null){let n=e[1];return n[0]==="Q"||n[0]==="1"?v(S.decode(`z${n}`),"base58btc"):v(P.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){return this.#n}equals(t){return Y(this.bytes,t.bytes)}async resolve(t){let e=this.protos().find(i=>i.resolvable);if(e==null)return[this];let n=tn.get(e.name);if(n==null)throw new W(`no available resolver for ${e.name}`,"ERR_NO_AVAILABLE_RESOLVER");return(await n(this,t)).map(i=>lt(i))}nodeAddress(){let t=this.toOptions();if(t.transport!=="tcp"&&t.transport!=="udp")throw new Error(`multiaddr must have a valid format - no protocol with name: "${t.transport}". Must have a valid transport protocol: "{tcp, udp}"`);return{family:t.family,address:t.host,port:t.port}}isThinWaistAddress(t){let e=(t??this).protos();return!(e.length!==2||e[0].code!==4&&e[0].code!==41||e[1].code!==6&&e[1].code!==273)}[mi](){return`Multiaddr(${this.#e})`}};var tn=new Map;function en(r){return!!r?.[Ke]}function lt(r){return new $t(r)}function yi(r){return r[Symbol.asyncIterator]!=null}function bi(r){if(yi(r))return(async()=>{for await(let t of r)return t})();for(let t of r)return t}var Qe=bi;var nn=Symbol.for("@achingbrain/uint8arraylist");function rn(r,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let e=0;for(let n of r){let o=e+n.byteLength;if(t<o)return{buf:n,index:t-e};e=o}throw new RangeError("index is out of bounds")}function Gt(r){return!!r?.[nn]}var ht=class r{bufs;length;[nn]=!0;constructor(...t){this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let e=0;for(let n of t)if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.push(n);else if(Gt(n))e+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}prepend(...t){this.prependAll(t)}prependAll(t){let e=0;for(let n of t.reverse())if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.unshift(n);else if(Gt(n))e+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}get(t){let e=rn(this.bufs,t);return e.buf[e.index]}set(t,e){let n=rn(this.bufs,t);n.buf[n.index]=e}write(t,e=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(e+n,t[n]);else if(Gt(t))for(let n=0;n<t.length;n++)this.set(e+n,t.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,e){let{bufs:n,length:o}=this._subList(t,e);return k(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:k(n,o)}sublist(t,e){let{bufs:n,length:o}=this._subList(t,e),i=new r;return i.length=o,i.bufs=[...n],i}_subList(t,e){if(t=t??0,e=e??this.length,t<0&&(t=this.length+t),e<0&&(e=this.length+e),t<0||e>this.length)throw new RangeError("index is out of bounds");if(t===e)return{bufs:[],length:0};if(t===0&&e===this.length)return{bufs:this.bufs,length:this.length};let n=[],o=0;for(let i=0;i<this.bufs.length;i++){let c=this.bufs[i],u=o,f=u+c.byteLength;if(o=f,t>=f)continue;let s=t>=u&&t<f,l=e>u&&e<=f;if(s&&l){if(t===u&&e===f){n.push(c);break}let a=t-u;n.push(c.subarray(a,a+(e-t)));break}if(s){if(t===0){n.push(c);continue}n.push(c.subarray(t-u));continue}if(l){if(e===f){n.push(c);break}n.push(c.subarray(0,e-u));break}n.push(c)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!Gt(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(e=Number(e??0),isNaN(e)&&(e=0),e<0&&(e=this.length+e),e<0&&(e=0),t.length===0)return e>this.length?this.length:e;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let i=256,c=new Int32Array(i);for(let a=0;a<i;a++)c[a]=-1;for(let a=0;a<o;a++)c[n[a]]=a;let u=c,f=this.byteLength-n.byteLength,s=n.byteLength-1,l;for(let a=e;a<=f;a+=l){l=0;for(let h=s;h>=0;h--){let p=this.get(a+h);if(n[h]!==p){l=Math.max(1,h-u[p]);break}}if(l===0)return a}return-1}getInt8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getInt8(0)}setInt8(t,e){let n=L(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,e),this.write(n,t)}getInt16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,e)}setInt16(t,e,n){let o=z(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,e,n),this.write(o,t)}getInt32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,e)}setInt32(t,e,n){let o=z(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,e,n),this.write(o,t)}getBigInt64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,e)}setBigInt64(t,e,n){let o=z(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,e,n),this.write(o,t)}getUint8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getUint8(0)}setUint8(t,e){let n=L(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,e),this.write(n,t)}getUint16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,e)}setUint16(t,e,n){let o=z(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,e,n),this.write(o,t)}getUint32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,e)}setUint32(t,e,n){let o=z(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,e,n),this.write(o,t)}getBigUint64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,e)}setBigUint64(t,e,n){let o=z(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,e,n),this.write(o,t)}getFloat32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,e)}setFloat32(t,e,n){let o=z(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,e,n),this.write(o,t)}getFloat64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,e)}setFloat64(t,e,n){let o=z(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,e,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof r)||t.bufs.length!==this.bufs.length)return!1;for(let e=0;e<this.bufs.length;e++)if(!Y(this.bufs[e],t.bufs[e]))return!1;return!0}static fromUint8Arrays(t,e){let n=new r;return n.bufs=t,e==null&&(e=t.reduce((o,i)=>o+i.byteLength,0)),n.length=e,n}};function qt(r){return r[Symbol.asyncIterator]!=null}var jt=r=>{let t=A(r),e=L(t);return K(r,e),jt.bytes=t,e};jt.bytes=0;function Tt(r,t){t=t??{};let e=t.lengthEncoder??jt;function*n(o){let i=e(o.byteLength);i instanceof Uint8Array?yield i:yield*i,o instanceof Uint8Array?yield o:yield*o}return qt(r)?async function*(){for await(let o of r)yield*n(o)}():function*(){for(let o of r)yield*n(o)}()}Tt.single=(r,t)=>{t=t??{};let e=t.lengthEncoder??jt;return new ht(e(r.byteLength),r)};var ft=mr(an(),1);var xi=8,Ei=1024*1024*4,et;(function(r){r[r.LENGTH=0]="LENGTH",r[r.DATA=1]="DATA"})(et||(et={}));var We=r=>{let t=$(r);return We.bytes=A(t),t};We.bytes=0;function dt(r,t){let e=new ht,n=et.LENGTH,o=-1,i=t?.lengthDecoder??We,c=t?.maxLengthLength??xi,u=t?.maxDataLength??Ei;function*f(){for(;e.byteLength>0;){if(n===et.LENGTH)try{if(o=i(e),o<0)throw(0,ft.default)(new Error("invalid message length"),"ERR_INVALID_MSG_LENGTH");if(o>u)throw(0,ft.default)(new Error("message length too long"),"ERR_MSG_DATA_TOO_LONG");let s=i.bytes;e.consume(s),t?.onLength!=null&&t.onLength(o),n=et.DATA}catch(s){if(s instanceof RangeError){if(e.byteLength>c)throw(0,ft.default)(new Error("message length length too long"),"ERR_MSG_LENGTH_TOO_LONG");break}throw s}if(n===et.DATA){if(e.byteLength<o)break;let s=e.sublist(0,o);e.consume(o),t?.onData!=null&&t.onData(s),yield s,n=et.LENGTH}}}return qt(r)?async function*(){for await(let s of r)e.append(s),yield*f();if(e.byteLength>0)throw(0,ft.default)(new Error("unexpected end of input"),"ERR_UNEXPECTED_EOF")}():function*(){for(let s of r)e.append(s),yield*f();if(e.byteLength>0)throw(0,ft.default)(new Error("unexpected end of input"),"ERR_UNEXPECTED_EOF")}()}dt.fromReader=(r,t)=>{let e=1,n=async function*(){for(;;)try{let{done:i,value:c}=await r.next(e);if(i===!0)return;c!=null&&(yield c)}catch(i){if(i.code==="ERR_UNDER_READ")return{done:!0,value:null};throw i}finally{e=1}}();return dt(n,{...t??{},onLength:i=>{e=i}})};function Ii(r){let[t,e]=r[Symbol.asyncIterator]!=null?[r[Symbol.asyncIterator](),Symbol.asyncIterator]:[r[Symbol.iterator](),Symbol.iterator],n=[];return{peek:()=>t.next(),push:o=>{n.push(o)},next:()=>n.length>0?{done:!1,value:n.shift()}:t.next(),[e](){return this}}}var cn=Ii;function Si(r){return r[Symbol.asyncIterator]!=null}function vi(r,t){let e=0;if(Si(r))return async function*(){for await(let f of r)yield t(f,e++)}();let n=cn(r),{value:o,done:i}=n.next();if(i===!0)return function*(){}();let c=t(o,e++);if(typeof c.then=="function")return async function*(){yield await c;for await(let f of n)yield t(f,e++)}();let u=t;return function*(){yield c;for(let f of n)yield u(f,e++)}()}var un=vi;function G(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var Ht=globalThis.CustomEvent??Event;async function*Je(r,t={}){let e=t.concurrency??1/0;e<1&&(e=1/0);let n=t.ordered==null?!1:t.ordered,o=new EventTarget,i=[],c=G(),u=G(),f=!1,s,l=!1;o.addEventListener("task-complete",()=>{u.resolve()}),Promise.resolve().then(async()=>{try{for await(let d of r){if(i.length===e&&(c=G(),await c.promise),l)break;let m={done:!1};i.push(m),d().then(g=>{m.done=!0,m.ok=!0,m.value=g,o.dispatchEvent(new Ht("task-complete"))},g=>{m.done=!0,m.err=g,o.dispatchEvent(new Ht("task-complete"))})}f=!0,o.dispatchEvent(new Ht("task-complete"))}catch(d){s=d,o.dispatchEvent(new Ht("task-complete"))}});function a(){return n?i[0]?.done:!!i.find(d=>d.done)}function*h(){for(;i.length>0&&i[0].done;){let d=i[0];if(i.shift(),d.ok)yield d.value;else throw l=!0,c.resolve(),d.err;c.resolve()}}function*p(){for(;a();)for(let d=0;d<i.length;d++)if(i[d].done){let m=i[d];if(i.splice(d,1),d--,m.ok)yield m.value;else throw l=!0,c.resolve(),m.err;c.resolve()}}for(;;){if(a()||(u=G(),await u.promise),s!=null)throw s;if(n?yield*h():yield*p(),f&&i.length===0)break}}var Xt=class{buffer;mask;top;btm;next;constructor(t){if(!(t>0)||t-1&t)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(t),this.mask=t-1,this.top=0,this.btm=0,this.next=null}push(t){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=t,this.top=this.top+1&this.mask,!0)}shift(){let t=this.buffer[this.btm];if(t!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,t}isEmpty(){return this.buffer[this.btm]===void 0}},pt=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new Xt(this.hwm),this.tail=this.head,this.size=0}calculateSize(t){return t?.byteLength!=null?t.byteLength:1}push(t){if(t?.value!=null&&(this.size+=this.calculateSize(t.value)),!this.head.push(t)){let e=this.head;this.head=e.next=new Xt(2*this.head.buffer.length),this.head.push(t)}}shift(){let t=this.tail.shift();if(t===void 0&&this.tail.next!=null){let e=this.tail.next;this.tail.next=null,this.tail=e,t=this.tail.shift()}return t?.value!=null&&(this.size-=this.calculateSize(t.value)),t}isEmpty(){return this.head.isEmpty()}};var Ze=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.code=e??"ABORT_ERR"}};function Kt(r={}){return Li(e=>{let n=e.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},r)}function Li(r,t){t=t??{};let e=t.onEnd,n=new pt,o,i,c,u=G(),f=async()=>{try{return n.isEmpty()?c?{done:!0}:await new Promise((g,E)=>{i=D=>{i=null,n.push(D);try{g(r(n))}catch(I){E(I)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{u.resolve(),u=G()})}},s=g=>i!=null?i(g):(n.push(g),o),l=g=>(n=new pt,i!=null?i({error:g}):(n.push({error:g}),o)),a=g=>{if(c)return o;if(t?.objectMode!==!0&&g?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return s({done:!1,value:g})},h=g=>c?o:(c=!0,g!=null?l(g):s({done:!0})),p=()=>(n=new pt,h(),{done:!0}),d=g=>(h(g),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:f,return:p,throw:d,push:a,end:h,get readableLength(){return n.size},onEmpty:async g=>{let E=g?.signal;if(E?.throwIfAborted(),n.isEmpty())return;let D,I;E!=null&&(D=new Promise((F,_)=>{I=()=>{_(new Ze)},E.addEventListener("abort",I)}));try{await Promise.race([u.promise,D])}finally{I!=null&&E!=null&&E?.removeEventListener("abort",I)}}},e==null)return o;let m=o;return o={[Symbol.asyncIterator](){return this},next(){return m.next()},throw(g){return m.throw(g),e!=null&&(e(g),e=void 0),{done:!0}},return(){return m.return(),e!=null&&(e(),e=void 0),{done:!0}},push:a,end(g){return m.end(g),e!=null&&(e(g),e=void 0),o},get readableLength(){return m.readableLength},onEmpty:g=>m.onEmpty(g)},o}function Ri(r){return r[Symbol.asyncIterator]!=null}function Ti(...r){let t=[];for(let e of r)Ri(e)||t.push(e);return t.length===r.length?function*(){for(let e of t)yield*e}():async function*(){let e=Kt({objectMode:!0});Promise.resolve().then(async()=>{try{await Promise.all(r.map(async n=>{for await(let o of n)e.push(o)})),e.end()}catch(n){e.end(n)}}),yield*e}()}var ln=Ti;function tr(r,...t){if(r==null)throw new Error("Empty pipeline");if(Ye(r)){let n=r;r=()=>n.source}else if(fn(r)||hn(r)){let n=r;r=()=>n}let e=[r,...t];if(e.length>1&&Ye(e[e.length-1])&&(e[e.length-1]=e[e.length-1].sink),e.length>2)for(let n=1;n<e.length-1;n++)Ye(e[n])&&(e[n]=Fi(e[n]));return Di(...e)}var Di=(...r)=>{let t;for(;r.length>0;)t=r.shift()(t);return t},hn=r=>r?.[Symbol.asyncIterator]!=null,fn=r=>r?.[Symbol.iterator]!=null,Ye=r=>r==null?!1:r.sink!=null&&r.source!=null,Fi=r=>t=>{let e=r.sink(t);if(e?.then!=null){let n=Kt({objectMode:!0});e.then(()=>{n.end()},c=>{n.end(c)});let o,i=r.source;if(hn(i))o=async function*(){yield*i,n.end()};else if(fn(i))o=function*(){yield*i,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return ln(n,o())}return r.source};var dn="libp2p",pn="autonat",mn="1.0.0";var er=new Float32Array([-0]),Q=new Uint8Array(er.buffer);function gn(r,t,e){er[0]=r,t[e]=Q[0],t[e+1]=Q[1],t[e+2]=Q[2],t[e+3]=Q[3]}function yn(r,t){return Q[0]=r[t],Q[1]=r[t+1],Q[2]=r[t+2],Q[3]=r[t+3],er[0]}var rr=new Float64Array([-0]),T=new Uint8Array(rr.buffer);function bn(r,t,e){rr[0]=r,t[e]=T[0],t[e+1]=T[1],t[e+2]=T[2],t[e+3]=T[3],t[e+4]=T[4],t[e+5]=T[5],t[e+6]=T[6],t[e+7]=T[7]}function wn(r,t){return T[0]=r[t],T[1]=r[t+1],T[2]=r[t+2],T[3]=r[t+3],T[4]=r[t+4],T[5]=r[t+5],T[6]=r[t+6],T[7]=r[t+7],rr[0]}var Ni=BigInt(Number.MAX_SAFE_INTEGER),Ui=BigInt(Number.MIN_SAFE_INTEGER),U=class r{lo;hi;constructor(t,e){this.lo=t|0,this.hi=e|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(e+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(BigInt(e)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,e=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?e===0?t<16384?t<128?1:2:t<2097152?3:4:e<16384?e<128?5:6:e<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return rt;if(t<Ni&&t>Ui)return this.fromNumber(Number(t));let e=t<0n;e&&(t=-t);let n=t>>32n,o=t-(n<<32n);return e&&(n=~n|0n,o=~o|0n,++o>xn&&(o=0n,++n>xn&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(t){if(t===0)return rt;let e=t<0;e&&(t=-t);let n=t>>>0,o=(t-n)/4294967296>>>0;return e&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new r(n,o)}static from(t){return typeof t=="number"?r.fromNumber(t):typeof t=="bigint"?r.fromBigInt(t):typeof t=="string"?r.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new r(t.low>>>0,t.high>>>0):rt}},rt=new U(0,0);rt.toBigInt=function(){return 0n};rt.zzEncode=rt.zzDecode=function(){return this};rt.length=function(){return 1};var xn=4294967296n;function En(r){let t=0,e=0;for(let n=0;n<r.length;++n)e=r.charCodeAt(n),e<128?t+=1:e<2048?t+=2:(e&64512)===55296&&(r.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function An(r,t,e){if(e-t<1)return"";let o,i=[],c=0,u;for(;t<e;)u=r[t++],u<128?i[c++]=u:u>191&&u<224?i[c++]=(u&31)<<6|r[t++]&63:u>239&&u<365?(u=((u&7)<<18|(r[t++]&63)<<12|(r[t++]&63)<<6|r[t++]&63)-65536,i[c++]=55296+(u>>10),i[c++]=56320+(u&1023)):i[c++]=(u&15)<<12|(r[t++]&63)<<6|r[t++]&63,c>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,i)),c=0);return o!=null?(c>0&&o.push(String.fromCharCode.apply(String,i.slice(0,c))),o.join("")):String.fromCharCode.apply(String,i.slice(0,c))}function nr(r,t,e){let n=e,o,i;for(let c=0;c<r.length;++c)o=r.charCodeAt(c),o<128?t[e++]=o:o<2048?(t[e++]=o>>6|192,t[e++]=o&63|128):(o&64512)===55296&&((i=r.charCodeAt(c+1))&64512)===56320?(o=65536+((o&1023)<<10)+(i&1023),++c,t[e++]=o>>18|240,t[e++]=o>>12&63|128,t[e++]=o>>6&63|128,t[e++]=o&63|128):(t[e++]=o>>12|224,t[e++]=o>>6&63|128,t[e++]=o&63|128);return e-n}function C(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function Qt(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var or=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=t,this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,C(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw C(this,4);return Qt(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw C(this,4);return Qt(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw C(this,4);let t=yn(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw C(this,4);let t=wn(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),e=this.pos,n=this.pos+t;if(n>this.len)throw C(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return An(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw C(this,t);this.pos+=t}else do if(this.pos>=this.len)throw C(this);while(this.buf[this.pos++]&128);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new U(0,0),e=0;if(this.len-this.pos>4){for(;e<4;++e)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;e=0}else{for(;e<3;++e){if(this.pos>=this.len)throw C(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<e*7)>>>0,t}if(this.len-this.pos>4){for(;e<5;++e)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;e<5;++e){if(this.pos>=this.len)throw C(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw C(this,8);let t=Qt(this.buf,this.pos+=4),e=Qt(this.buf,this.pos+=4);return new U(t,e)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=Oe(this.buf,this.pos);return this.pos+=A(t),t}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function ir(r){return new or(r instanceof Uint8Array?r:r.subarray())}function mt(r,t,e){let n=ir(r);return t.decode(n,void 0,e)}function sr(r){let t=r??8192,e=t>>>1,n,o=t;return function(c){if(c<1||c>e)return L(c);o+c>t&&(n=L(t),o=0);let u=n.subarray(o,o+=c);return o&7&&(o=(o|7)+1),u}}var nt=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function ar(){}var ur=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},_i=sr();function Pi(r){return globalThis.Buffer!=null?L(r):_i(r)}var Ft=class{len;head;tail;states;constructor(){this.len=0,this.head=new nt(ar,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new nt(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new lr((t=t>>>0)<128?1:t<16384?2:t<2097152?3:t<268435456?4:5,t)).len,this}int32(t){return t<0?this._push(Wt,10,U.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=U.fromBigInt(t);return this._push(Wt,e.length(),e)}uint64Number(t){return this._push(ke,A(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let e=U.fromBigInt(t).zzEncode();return this._push(Wt,e.length(),e)}sint64Number(t){let e=U.fromNumber(t).zzEncode();return this._push(Wt,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(cr,1,t?1:0)}fixed32(t){return this._push(Dt,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=U.fromBigInt(t);return this._push(Dt,4,e.lo)._push(Dt,4,e.hi)}fixed64Number(t){let e=U.fromNumber(t);return this._push(Dt,4,e.lo)._push(Dt,4,e.hi)}fixed64String(t){return this.fixed64(BigInt(t))}sfixed64(t){return this.fixed64(t)}sfixed64Number(t){return this.fixed64Number(t)}sfixed64String(t){return this.fixed64String(t)}float(t){return this._push(gn,4,t)}double(t){return this._push(bn,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(cr,1,0):this.uint32(e)._push(Oi,e,t)}string(t){let e=En(t);return e!==0?this.uint32(e)._push(nr,e,t):this._push(cr,1,0)}fork(){return this.states=new ur(this),this.head=this.tail=new nt(ar,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new nt(ar,0,0),this.len=0),this}ldelim(){let t=this.head,e=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=e,this.len+=n),this}finish(){let t=this.head.next,e=Pi(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function cr(r,t,e){t[e]=r&255}function ki(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var lr=class extends nt{next;constructor(t,e){super(ki,t,e),this.next=void 0}};function Wt(r,t,e){for(;r.hi!==0;)t[e++]=r.lo&127|128,r.lo=(r.lo>>>7|r.hi<<25)>>>0,r.hi>>>=7;for(;r.lo>127;)t[e++]=r.lo&127|128,r.lo=r.lo>>>7;t[e++]=r.lo}function Dt(r,t,e){t[e]=r&255,t[e+1]=r>>>8&255,t[e+2]=r>>>16&255,t[e+3]=r>>>24}function Oi(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(Ft.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(Ci,t,r),this},Ft.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(Bi,t,r),this});function Ci(r,t,e){t.set(r,e)}function Bi(r,t,e){r.length<40?nr(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(tt(r),e)}function hr(){return new Ft}function gt(r,t){let e=hr();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var yt;(function(r){r[r.VARINT=0]="VARINT",r[r.BIT64=1]="BIT64",r[r.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",r[r.START_GROUP=3]="START_GROUP",r[r.END_GROUP=4]="END_GROUP",r[r.BIT32=5]="BIT32"})(yt||(yt={}));function Jt(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function Zt(r){function t(o){if(r[o.toString()]==null)throw new Error("Invalid enum value");return r[o]}let e=function(i,c){let u=t(i);c.int32(u)},n=function(i){let c=i.int32();return t(c)};return Jt("enum",yt.VARINT,e,n)}function bt(r,t){return Jt("message",yt.LENGTH_DELIMITED,r,t)}var y;(function(r){let t;(function(s){s.DIAL="DIAL",s.DIAL_RESPONSE="DIAL_RESPONSE"})(t=r.MessageType||(r.MessageType={}));let e;(function(s){s[s.DIAL=0]="DIAL",s[s.DIAL_RESPONSE=1]="DIAL_RESPONSE"})(e||(e={})),function(s){s.codec=()=>Zt(e)}(t=r.MessageType||(r.MessageType={}));let n;(function(s){s.OK="OK",s.E_DIAL_ERROR="E_DIAL_ERROR",s.E_DIAL_REFUSED="E_DIAL_REFUSED",s.E_BAD_REQUEST="E_BAD_REQUEST",s.E_INTERNAL_ERROR="E_INTERNAL_ERROR"})(n=r.ResponseStatus||(r.ResponseStatus={}));let o;(function(s){s[s.OK=0]="OK",s[s.E_DIAL_ERROR=100]="E_DIAL_ERROR",s[s.E_DIAL_REFUSED=101]="E_DIAL_REFUSED",s[s.E_BAD_REQUEST=200]="E_BAD_REQUEST",s[s.E_INTERNAL_ERROR=300]="E_INTERNAL_ERROR"})(o||(o={})),function(s){s.codec=()=>Zt(o)}(n=r.ResponseStatus||(r.ResponseStatus={}));let i;(function(s){let l;s.codec=()=>(l==null&&(l=bt((a,h,p={})=>{if(p.lengthDelimited!==!1&&h.fork(),a.id!=null&&(h.uint32(10),h.bytes(a.id)),a.addrs!=null)for(let d of a.addrs)h.uint32(18),h.bytes(d);p.lengthDelimited!==!1&&h.ldelim()},(a,h)=>{let p={addrs:[]},d=h==null?a.len:a.pos+h;for(;a.pos<d;){let m=a.uint32();switch(m>>>3){case 1:p.id=a.bytes();break;case 2:p.addrs.push(a.bytes());break;default:a.skipType(m&7);break}}return p})),l),s.encode=a=>gt(a,s.codec()),s.decode=a=>mt(a,s.codec())})(i=r.PeerInfo||(r.PeerInfo={}));let c;(function(s){let l;s.codec=()=>(l==null&&(l=bt((a,h,p={})=>{p.lengthDelimited!==!1&&h.fork(),a.peer!=null&&(h.uint32(10),r.PeerInfo.codec().encode(a.peer,h)),p.lengthDelimited!==!1&&h.ldelim()},(a,h)=>{let p={},d=h==null?a.len:a.pos+h;for(;a.pos<d;){let m=a.uint32();switch(m>>>3){case 1:p.peer=r.PeerInfo.codec().decode(a,a.uint32());break;default:a.skipType(m&7);break}}return p})),l),s.encode=a=>gt(a,s.codec()),s.decode=a=>mt(a,s.codec())})(c=r.Dial||(r.Dial={}));let u;(function(s){let l;s.codec=()=>(l==null&&(l=bt((a,h,p={})=>{p.lengthDelimited!==!1&&h.fork(),a.status!=null&&(h.uint32(8),r.ResponseStatus.codec().encode(a.status,h)),a.statusText!=null&&(h.uint32(18),h.string(a.statusText)),a.addr!=null&&(h.uint32(26),h.bytes(a.addr)),p.lengthDelimited!==!1&&h.ldelim()},(a,h)=>{let p={},d=h==null?a.len:a.pos+h;for(;a.pos<d;){let m=a.uint32();switch(m>>>3){case 1:p.status=r.ResponseStatus.codec().decode(a);break;case 2:p.statusText=a.string();break;case 3:p.addr=a.bytes();break;default:a.skipType(m&7);break}}return p})),l),s.encode=a=>gt(a,s.codec()),s.decode=a=>mt(a,s.codec())})(u=r.DialResponse||(r.DialResponse={}));let f;r.codec=()=>(f==null&&(f=bt((s,l,a={})=>{a.lengthDelimited!==!1&&l.fork(),s.type!=null&&(l.uint32(8),r.MessageType.codec().encode(s.type,l)),s.dial!=null&&(l.uint32(18),r.Dial.codec().encode(s.dial,l)),s.dialResponse!=null&&(l.uint32(26),r.DialResponse.codec().encode(s.dialResponse,l)),a.lengthDelimited!==!1&&l.ldelim()},(s,l)=>{let a={},h=l==null?s.len:s.pos+l;for(;s.pos<h;){let p=s.uint32();switch(p>>>3){case 1:a.type=r.MessageType.codec().decode(s);break;case 2:a.dial=r.Dial.codec().decode(s,s.uint32());break;case 3:a.dialResponse=r.DialResponse.codec().decode(s,s.uint32());break;default:s.skipType(p&7);break}}return a})),f),r.encode=s=>gt(s,r.codec()),r.decode=s=>mt(s,r.codec())})(y||(y={}));var fr=4,Yt=class{components;startupDelay;refreshInterval;protocol;timeout;maxInboundStreams;maxOutboundStreams;verifyAddressTimeout;started;log;constructor(t,e){this.components=t,this.log=t.logger.forComponent("libp2p:autonat"),this.started=!1,this.protocol=`/${e.protocolPrefix??dn}/${pn}/${mn}`,this.timeout=e.timeout??3e4,this.maxInboundStreams=e.maxInboundStreams??1,this.maxOutboundStreams=e.maxOutboundStreams??1,this.startupDelay=e.startupDelay??5e3,this.refreshInterval=e.refreshInterval??6e4,this._verifyExternalAddresses=this._verifyExternalAddresses.bind(this)}[Symbol.toStringTag]="@libp2p/autonat";isStarted(){return this.started}async start(){this.started||(await this.components.registrar.handle(this.protocol,t=>{this.handleIncomingAutonatStream(t).catch(e=>{this.log.error("error handling incoming autonat stream",e)})},{maxInboundStreams:this.maxInboundStreams,maxOutboundStreams:this.maxOutboundStreams}),this.verifyAddressTimeout=setTimeout(this._verifyExternalAddresses,this.startupDelay),this.started=!0)}async stop(){await this.components.registrar.unhandle(this.protocol),clearTimeout(this.verifyAddressTimeout),this.started=!1}async handleIncomingAutonatStream(t){let e=AbortSignal.timeout(this.timeout),n=()=>{t.stream.abort(new W("handleIncomingAutonatStream timeout",ee))};e.addEventListener("abort",n,{once:!0}),re(1/0,e);try{let o=this;await tr(t.stream,i=>dt(i),async function*(i){let c=await Qe(i);if(c==null){o.log("no message received"),yield y.encode({type:y.MessageType.DIAL_RESPONSE,dialResponse:{status:y.ResponseStatus.E_BAD_REQUEST,statusText:"No message was sent"}});return}let u;try{u=y.decode(c)}catch(f){o.log.error("could not decode message",f),yield y.encode({type:y.MessageType.DIAL_RESPONSE,dialResponse:{status:y.ResponseStatus.E_BAD_REQUEST,statusText:"Could not decode message"}});return}yield y.encode(await o.handleAutonatMessage(u,t.connection,{signal:e}))},i=>Tt(i),t.stream)}catch(o){this.log.error("error handling incoming autonat stream",o)}finally{e.removeEventListener("abort",n)}}_verifyExternalAddresses(){this.verifyExternalAddresses().catch(t=>{this.log.error("error verifying external address",t)})}async handleAutonatMessage(t,e,n){let o=this.components.addressManager.getAddresses().map(a=>a.toOptions().host),i=t.dial;if(i==null)return this.log.error("dial was missing from message"),{type:y.MessageType.DIAL_RESPONSE,dialResponse:{status:y.ResponseStatus.E_BAD_REQUEST,statusText:"No Dial message found in message"}};let c,u=i.peer;if(u?.id==null)return this.log.error("PeerId missing from message"),{type:y.MessageType.DIAL_RESPONSE,dialResponse:{status:y.ResponseStatus.E_BAD_REQUEST,statusText:"missing peer info"}};try{c=Le(u.id)}catch(a){return this.log.error("invalid PeerId",a),{type:y.MessageType.DIAL_RESPONSE,dialResponse:{status:y.ResponseStatus.E_BAD_REQUEST,statusText:"bad peer id"}}}if(this.log("incoming request from %p",c),!e.remotePeer.equals(c))return this.log("target peer %p did not equal sending peer %p",c,e.remotePeer),{type:y.MessageType.DIAL_RESPONSE,dialResponse:{status:y.ResponseStatus.E_BAD_REQUEST,statusText:"peer id mismatch"}};let f=u.addrs.map(a=>lt(a)).filter(a=>{let h=a.toOptions().host===e.remoteAddr.toOptions().host;return this.log.trace("request to dial %a was sent from %a is same host %s",a,e.remoteAddr,h),h}).filter(a=>{let h=a.toOptions().host,p=!(Fe(h)??!1);return this.log.trace("host %s was public %s",h,p),p}).filter(a=>{let h=a.toOptions().host,p=!o.includes(h);return this.log.trace("host %s was not our host %s",h,p),p}).filter(a=>{let h=!!this.components.transportManager.dialTransportForMultiaddr(a);return this.log.trace("transport for %a is supported %s",a,h),h}).map(a=>(a.getPeerId()==null&&(a=a.encapsulate(`/p2p/${c.toString()}`)),a));if(f.length===0)return this.log("no valid multiaddrs for %p in message",c),{type:y.MessageType.DIAL_RESPONSE,dialResponse:{status:y.ResponseStatus.E_DIAL_REFUSED,statusText:"no dialable addresses"}};this.log("dial multiaddrs %s for peer %p",f.map(a=>a.toString()).join(", "),c);let s="",l=f[0];for await(let a of f){let h;l=a;try{if(h=await this.components.connectionManager.openConnection(a,n),!h.remoteAddr.equals(a))throw this.log.error("tried to dial %a but dialed %a",a,h.remoteAddr),new Error("Unexpected remote address");return this.log("Success %p",c),{type:y.MessageType.DIAL_RESPONSE,dialResponse:{status:y.ResponseStatus.OK,addr:h.remoteAddr.decapsulateCode(w("p2p").code).bytes}}}catch(p){this.log("could not dial %p",c,p),s=p.message}finally{h!=null&&await h.close()}}return{type:y.MessageType.DIAL_RESPONSE,dialResponse:{status:y.ResponseStatus.E_DIAL_ERROR,statusText:s,addr:l.bytes}}}async verifyExternalAddresses(){if(clearTimeout(this.verifyAddressTimeout),!this.isStarted())return;let t=this.components.addressManager,e=t.getObservedAddrs().filter(i=>{let c=i.toOptions();return!(Fe(c.host)??!1)});if(e.length===0){this.log("no public addresses found, not requesting verification"),this.verifyAddressTimeout=setTimeout(this._verifyExternalAddresses,this.refreshInterval);return}let n=AbortSignal.timeout(this.timeout);re(1/0,n);let o=this;try{this.log("verify multiaddrs %s",e.map(s=>s.toString()).join(", "));let i=y.encode({type:y.MessageType.DIAL,dial:{peer:{id:this.components.peerId.toBytes(),addrs:e.map(s=>s.bytes)}}}),c={},u=[],f=async s=>{let l=()=>{};try{this.log("asking %p to verify multiaddr",s.id);let a=await o.components.connectionManager.openConnection(s.id,{signal:n}),h=await a.newStream(this.protocol,{signal:n});l=()=>{h.abort(new W("verifyAddress timeout",ee))},n.addEventListener("abort",l,{once:!0});let p=await tr([i],m=>Tt(m),h,m=>dt(m),async m=>Qe(m));if(p==null){this.log("no response received from %p",a.remotePeer);return}let d=y.decode(p);if(d.type!==y.MessageType.DIAL_RESPONSE||d.dialResponse==null){this.log("invalid autonat response from %p",a.remotePeer);return}if(d.dialResponse.status===y.ResponseStatus.OK){let m=a.remoteAddr.toOptions(),g;if(m.family===4)g=m.host.split(".")[0];else if(m.family===6)g=m.host.split(":")[0];else{this.log('remote address "%s" was not IP4 or IP6?',m.host);return}if(u.includes(g)){this.log("already have response from network segment %d - %s",g,m.host);return}u.push(g)}return d.dialResponse}catch(a){this.log.error("error asking remote to verify multiaddr",a)}finally{n.removeEventListener("abort",l)}};for await(let s of Je(un(this.components.randomWalk.walk({signal:n}),l=>async()=>f(l)),{concurrency:fr}))try{if(s==null)continue;let l=s.addr==null?e[0]:lt(s.addr);if(this.log("autonat response for %a is %s",l,s.status),s.status===y.ResponseStatus.E_BAD_REQUEST||s.status===y.ResponseStatus.E_DIAL_REFUSED||s.addr==null&&e.length>1)continue;if(!e.some(h=>h.equals(l))){this.log("peer reported %a as %s but it was not in our observed address list",l,s.status);continue}let a=l.toString();if(c[a]==null&&(c[a]={success:0,failure:0}),s.status===y.ResponseStatus.OK?c[a].success++:s.status===y.ResponseStatus.E_DIAL_ERROR&&c[a].failure++,c[a].success===fr){this.log("%a is externally dialable",l),t.confirmObservedAddr(l);return}if(c[a].failure===fr){this.log("%a is not externally dialable",l),t.removeObservedAddr(l);return}}catch(l){this.log.error("could not verify external address",l)}}finally{this.verifyAddressTimeout=setTimeout(this._verifyExternalAddresses,this.refreshInterval)}}};function qi(r={}){return t=>new Yt(t,r)}return Dn(ji);})();
|
|
2
|
+
"use strict";var Libp2PAutonat=(()=>{var An=Object.create;var Ut=Object.defineProperty;var In=Object.getOwnPropertyDescriptor;var Sn=Object.getOwnPropertyNames;var vn=Object.getPrototypeOf,Ln=Object.prototype.hasOwnProperty;var Rn=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),N=(r,t)=>{for(var e in t)Ut(r,e,{get:t[e],enumerable:!0})},gr=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Sn(t))!Ln.call(r,o)&&o!==e&&Ut(r,o,{get:()=>t[o],enumerable:!(n=In(t,o))||n.enumerable});return r};var Tn=(r,t,e)=>(e=r!=null?An(vn(r)):{},gr(t||!r||!r.__esModule?Ut(e,"default",{value:r,enumerable:!0}):e,r)),Dn=r=>gr(Ut({},"__esModule",{value:!0}),r);var Gr=Rn(Lt=>{(function(){var r,t,e,n,o,i,c,u;u=function(f){var s,l,a,h;return s=(f&255<<24)>>>24,l=(f&255<<16)>>>16,a=(f&65280)>>>8,h=f&255,[s,l,a,h].join(".")},c=function(f){var s,l,a,h,p,d;for(s=[],a=h=0;h<=3&&f.length!==0;a=++h){if(a>0){if(f[0]!==".")throw new Error("Invalid IP");f=f.substring(1)}d=t(f),p=d[0],l=d[1],f=f.substring(l),s.push(p)}if(f.length!==0)throw new Error("Invalid IP");switch(s.length){case 1:if(s[0]>4294967295)throw new Error("Invalid IP");return s[0]>>>0;case 2:if(s[0]>255||s[1]>16777215)throw new Error("Invalid IP");return(s[0]<<24|s[1])>>>0;case 3:if(s[0]>255||s[1]>255||s[2]>65535)throw new Error("Invalid IP");return(s[0]<<24|s[1]<<16|s[2])>>>0;case 4:if(s[0]>255||s[1]>255||s[2]>255||s[3]>255)throw new Error("Invalid IP");return(s[0]<<24|s[1]<<16|s[2]<<8|s[3])>>>0;default:throw new Error("Invalid IP")}},e=function(f){return f.charCodeAt(0)},n=e("0"),i=e("a"),o=e("A"),t=function(f){var s,l,a,h,p;for(h=0,s=10,l="9",a=0,f.length>1&&f[a]==="0"&&(f[a+1]==="x"||f[a+1]==="X"?(a+=2,s=16):"0"<=f[a+1]&&f[a+1]<="9"&&(a++,s=8,l="7")),p=a;a<f.length;){if("0"<=f[a]&&f[a]<=l)h=h*s+(e(f[a])-n)>>>0;else if(s===16)if("a"<=f[a]&&f[a]<="f")h=h*s+(10+e(f[a])-i)>>>0;else if("A"<=f[a]&&f[a]<="F")h=h*s+(10+e(f[a])-o)>>>0;else break;else break;if(h>4294967295)throw new Error("too large");a++}if(a===p)throw new Error("empty octet");return[h,a]},r=function(){function f(s,l){var a,h,p,d;if(typeof s!="string")throw new Error("Missing `net' parameter");if(l||(d=s.split("/",2),s=d[0],l=d[1]),l||(l=32),typeof l=="string"&&l.indexOf(".")>-1){try{this.maskLong=c(l)}catch(m){throw a=m,new Error("Invalid mask: "+l)}for(h=p=32;p>=0;h=--p)if(this.maskLong===4294967295<<32-h>>>0){this.bitmask=h;break}}else if(l||l===0)this.bitmask=parseInt(l,10),this.maskLong=0,this.bitmask>0&&(this.maskLong=4294967295<<32-this.bitmask>>>0);else throw new Error("Invalid mask: empty");try{this.netLong=(c(s)&this.maskLong)>>>0}catch(m){throw a=m,new Error("Invalid net address: "+s)}if(!(this.bitmask<=32))throw new Error("Invalid mask for ip4: "+l);this.size=Math.pow(2,32-this.bitmask),this.base=u(this.netLong),this.mask=u(this.maskLong),this.hostmask=u(~this.maskLong),this.first=this.bitmask<=30?u(this.netLong+1):this.base,this.last=this.bitmask<=30?u(this.netLong+this.size-2):u(this.netLong+this.size-1),this.broadcast=this.bitmask<=30?u(this.netLong+this.size-1):void 0}return f.prototype.contains=function(s){return typeof s=="string"&&(s.indexOf("/")>0||s.split(".").length!==4)&&(s=new f(s)),s instanceof f?this.contains(s.base)&&this.contains(s.broadcast||s.last):(c(s)&this.maskLong)>>>0===(this.netLong&this.maskLong)>>>0},f.prototype.next=function(s){return s==null&&(s=1),new f(u(this.netLong+this.size*s),this.mask)},f.prototype.forEach=function(s){var l,a,h;for(h=c(this.first),a=c(this.last),l=0;h<=a;)s(u(h),h,l),l++,h++},f.prototype.toString=function(){return this.base+"/"+this.bitmask},f}(),Lt.ip2long=c,Lt.long2ip=u,Lt.Netmask=r}).call(Lt)});var qi={};N(qi,{autoNAT:()=>Gi});var ne=Symbol.for("@libp2p/peer-id");var W=class extends Error{code;props;constructor(t,e,n){super(t),this.code=e,this.name=n?.name??"CodeError",this.props=n??{}}};var oe="ERR_TIMEOUT";var ie=(r,...t)=>{try{[...t]}catch{}};var le={};N(le,{base58btc:()=>S,base58flickr:()=>kn});var Qi=new Uint8Array(0);function br(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])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 wr(r){return new TextEncoder().encode(r)}function yr(r){return new TextDecoder().decode(r)}function Fn(r,t){if(r.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),n=0;n<e.length;n++)e[n]=255;for(var o=0;o<r.length;o++){var i=r.charAt(o),c=i.charCodeAt(0);if(e[c]!==255)throw new TypeError(i+" is ambiguous");e[c]=o}var u=r.length,f=r.charAt(0),s=Math.log(u)/Math.log(256),l=Math.log(256)/Math.log(u);function a(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 m=0,g=0,E=0,D=d.length;E!==D&&d[E]===0;)E++,m++;for(var I=(D-E)*l+1>>>0,F=new Uint8Array(I);E!==D;){for(var _=d[E],q=0,O=I-1;(_!==0||q<g)&&O!==-1;O--,q++)_+=256*F[O]>>>0,F[O]=_%u>>>0,_=_/u>>>0;if(_!==0)throw new Error("Non-zero carry");g=q,E++}for(var B=I-g;B!==I&&F[B]===0;)B++;for(var Nt=f.repeat(m);B<I;++B)Nt+=r.charAt(F[B]);return Nt}function h(d){if(typeof d!="string")throw new TypeError("Expected String");if(d.length===0)return new Uint8Array;var m=0;if(d[m]!==" "){for(var g=0,E=0;d[m]===f;)g++,m++;for(var D=(d.length-m)*s+1>>>0,I=new Uint8Array(D);d[m];){var F=e[d.charCodeAt(m)];if(F===255)return;for(var _=0,q=D-1;(F!==0||_<E)&&q!==-1;q--,_++)F+=u*I[q]>>>0,I[q]=F%256>>>0,F=F/256>>>0;if(F!==0)throw new Error("Non-zero carry");E=_,m++}if(d[m]!==" "){for(var O=D-E;O!==D&&I[O]===0;)O++;for(var B=new Uint8Array(g+(D-O)),Nt=g;O!==D;)B[Nt++]=I[O++];return B}}}function p(d){var m=h(d);if(m)return m;throw new Error(`Non-${t} character`)}return{encode:a,decodeUnsafe:h,decode:p}}var Nn=Fn,Un=Nn,Er=Un;var se=class{name;prefix;baseEncode;constructor(t,e,n){this.name=t,this.prefix=e,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},ae=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,e,n){if(this.name=t,this.prefix=e,e.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=e.codePointAt(0),this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return Ar(this,t)}},ce=class{decoders;constructor(t){this.decoders=t}or(t){return Ar(this,t)}decode(t){let e=t[0],n=this.decoders[e];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Ar(r,t){return new ce({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var ue=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,e,n,o){this.name=t,this.prefix=e,this.baseEncode=n,this.baseDecode=o,this.encoder=new se(t,e,n),this.decoder=new ae(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function ot({name:r,prefix:t,encode:e,decode:n}){return new ue(r,t,e,n)}function H({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=Er(e,r);return ot({prefix:t,name:r,encode:n,decode:i=>M(o(i))})}function _n(r,t,e,n){let o={};for(let l=0;l<t.length;++l)o[t[l]]=l;let i=r.length;for(;r[i-1]==="=";)--i;let c=new Uint8Array(i*e/8|0),u=0,f=0,s=0;for(let l=0;l<i;++l){let a=o[r[l]];if(a===void 0)throw new SyntaxError(`Non-${n} character`);f=f<<e|a,u+=e,u>=8&&(u-=8,c[s++]=255&f>>u)}if(u>=e||255&f<<8-u)throw new SyntaxError("Unexpected end of data");return c}function Pn(r,t,e){let n=t[t.length-1]==="=",o=(1<<e)-1,i="",c=0,u=0;for(let f=0;f<r.length;++f)for(u=u<<8|r[f],c+=8;c>e;)c-=e,i+=t[o&u>>c];if(c!==0&&(i+=t[o&u<<e-c]),n)for(;i.length*e&7;)i+="=";return i}function x({name:r,prefix:t,bitsPerChar:e,alphabet:n}){return ot({prefix:t,name:r,encode(o){return Pn(o,n,e)},decode(o){return _n(o,n,e,r)}})}var S=H({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),kn=H({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var he={};N(he,{base10:()=>On});var On=H({prefix:"9",name:"base10",alphabet:"0123456789"});var fe={};N(fe,{base16:()=>Cn,base16upper:()=>Bn});var Cn=x({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Bn=x({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var de={};N(de,{base2:()=>Mn});var Mn=x({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var pe={};N(pe,{base256emoji:()=>qn});var Ir=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}"),Vn=Ir.reduce((r,t,e)=>(r[e]=t,r),[]),zn=Ir.reduce((r,t,e)=>(r[t.codePointAt(0)]=e,r),[]);function $n(r){return r.reduce((t,e)=>(t+=Vn[e],t),"")}function Gn(r){let t=[];for(let e of r){let n=zn[e.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${e}`);t.push(n)}return new Uint8Array(t)}var qn=ot({prefix:"\u{1F680}",name:"base256emoji",encode:$n,decode:Gn});var me={};N(me,{base32:()=>V,base32hex:()=>Kn,base32hexpad:()=>Wn,base32hexpadupper:()=>Jn,base32hexupper:()=>Qn,base32pad:()=>jn,base32padupper:()=>Xn,base32upper:()=>Hn,base32z:()=>Zn});var V=x({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Hn=x({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),jn=x({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Xn=x({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Kn=x({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Qn=x({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Wn=x({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Jn=x({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Zn=x({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var ge={};N(ge,{base36:()=>Yn,base36upper:()=>to});var Yn=H({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),to=H({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var be={};N(be,{base64:()=>eo,base64pad:()=>ro,base64url:()=>no,base64urlpad:()=>oo});var eo=x({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),ro=x({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),no=x({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),oo=x({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var we={};N(we,{base8:()=>io});var io=x({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var ye={};N(ye,{identity:()=>so});var so=ot({prefix:"\0",name:"identity",encode:r=>yr(r),decode:r=>wr(r)});var hs=new TextEncoder,fs=new TextDecoder;var Ee={};N(Ee,{identity:()=>xt});var uo=Lr,Sr=128,lo=127,ho=~lo,fo=Math.pow(2,31);function Lr(r,t,e){t=t||[],e=e||0;for(var n=e;r>=fo;)t[e++]=r&255|Sr,r/=128;for(;r&ho;)t[e++]=r&255|Sr,r>>>=7;return t[e]=r|0,Lr.bytes=e-n+1,t}var po=xe,mo=128,vr=127;function xe(r,n){var e=0,n=n||0,o=0,i=n,c,u=r.length;do{if(i>=u)throw xe.bytes=0,new RangeError("Could not decode varint");c=r[i++],e+=o<28?(c&vr)<<o:(c&vr)*Math.pow(2,o),o+=7}while(c>=mo);return xe.bytes=i-n,e}var go=Math.pow(2,7),bo=Math.pow(2,14),wo=Math.pow(2,21),yo=Math.pow(2,28),xo=Math.pow(2,35),Eo=Math.pow(2,42),Ao=Math.pow(2,49),Io=Math.pow(2,56),So=Math.pow(2,63),vo=function(r){return r<go?1:r<bo?2:r<wo?3:r<yo?4:r<xo?5:r<Eo?6:r<Ao?7:r<Io?8:r<So?9:10},Lo={encode:uo,decode:po,encodingLength:vo},Ro=Lo,wt=Ro;function yt(r,t=0){return[wt.decode(r,t),wt.decode.bytes]}function it(r,t,e=0){return wt.encode(r,t,e),t}function st(r){return wt.encodingLength(r)}function j(r,t){let e=t.byteLength,n=st(r),o=n+st(e),i=new Uint8Array(o+e);return it(r,i,0),it(e,i,n),i.set(t,o),new at(r,e,t,i)}function J(r){let t=M(r),[e,n]=yt(t),[o,i]=yt(t.subarray(n)),c=t.subarray(n+i);if(c.byteLength!==o)throw new Error("Incorrect length");return new at(e,o,c,t)}function Rr(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&br(r.bytes,e.bytes)}}var at=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=n,this.bytes=o}};var Tr=0,To="identity",Dr=M;function Do(r){return j(Tr,Dr(r))}var xt={code:Tr,name:To,encode:Dr,digest:Do};var Se={};N(Se,{sha256:()=>Pt,sha512:()=>Fo});function Ie({name:r,code:t,encode:e}){return new Ae(r,t,e)}var Ae=class{name;code;encode;constructor(t,e,n){this.name=t,this.code=e,this.encode=n}digest(t){if(t instanceof Uint8Array){let e=this.encode(t);return e instanceof Uint8Array?j(this.code,e):e.then(n=>j(this.code,n))}else throw Error("Unknown type, must be binary type")}};function Nr(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var Pt=Ie({name:"sha2-256",code:18,encode:Nr("SHA-256")}),Fo=Ie({name:"sha2-512",code:19,encode:Nr("SHA-512")});function Ur(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return Uo(e,ve(r),t??S.encoder);default:return _o(e,ve(r),t??V.encoder)}}var _r=new WeakMap;function ve(r){let t=_r.get(r);if(t==null){let e=new Map;return _r.set(r,e),e}return t}var P=class r{code;version;multihash;bytes;"/";constructor(t,e,n,o){this.code=e,this.version=t,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:t,multihash:e}=this;if(t!==Et)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==Po)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(e)}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:t,digest:e}=this.multihash,n=j(t,e);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(t){return r.equals(this,t)}static equals(t,e){let n=e;return n!=null&&t.code===n.code&&t.version===n.version&&Rr(t.multihash,n.multihash)}toString(t){return Ur(this,t)}toJSON(){return{"/":Ur(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let e=t;if(e instanceof r)return e;if(e["/"]!=null&&e["/"]===e.bytes||e.asCID===e){let{version:n,code:o,multihash:i,bytes:c}=e;return new r(n,o,i,c??Pr(n,o,i.bytes))}else if(e[ko]===!0){let{version:n,multihash:o,code:i}=e,c=J(o);return r.create(n,i,c)}else return null}static create(t,e,n){if(typeof e!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(e!==Et)throw new Error(`Version 0 CID must use dag-pb (code: ${Et}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=Pr(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,Et,t)}static createV1(t,e){return r.create(1,t,e)}static decode(t){let[e,n]=r.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return e}static decodeFirst(t){let e=r.inspectBytes(t),n=e.size-e.multihashSize,o=M(t.subarray(n,n+e.multihashSize));if(o.byteLength!==e.multihashSize)throw new Error("Incorrect length");let i=o.subarray(e.multihashSize-e.digestSize),c=new at(e.multihashCode,e.digestSize,i,o);return[e.version===0?r.createV0(c):r.createV1(e.codec,c),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[a,h]=yt(t.subarray(e));return e+=h,a},o=n(),i=Et;if(o===18?(o=0,e=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let c=e,u=n(),f=n(),s=e+f,l=s-c;return{version:o,codec:i,multihashCode:u,digestSize:f,multihashSize:l,size:s}}static parse(t,e){let[n,o]=No(t,e),i=r.decode(o);if(i.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return ve(i).set(n,t),i}};function No(r,t){switch(r[0]){case"Q":{let e=t??S;return[S.prefix,e.decode(`${S.prefix}${r}`)]}case S.prefix:{let e=t??S;return[S.prefix,e.decode(r)]}case V.prefix:{let e=t??V;return[V.prefix,e.decode(r)]}default:{if(t==null)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[r[0],t.decode(r)]}}}function Uo(r,t,e){let{prefix:n}=e;if(n!==S.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let o=t.get(n);if(o==null){let i=e.encode(r).slice(1);return t.set(n,i),i}else return o}function _o(r,t,e){let{prefix:n}=e,o=t.get(n);if(o==null){let i=e.encode(r);return t.set(n,i),i}else return o}var Et=112,Po=18;function Pr(r,t,e){let n=st(r),o=n+st(t),i=new Uint8Array(o+e.byteLength);return it(r,i,0),it(t,i,n),i.set(e,o),i}var ko=Symbol.for("@ipld/js-cid/CID");var X={...ye,...de,...we,...he,...fe,...me,...ge,...le,...be,...pe},_s={...Se,...Ee};function Y(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function z(r=0){return new Uint8Array(r)}function L(r=0){return new Uint8Array(r)}function Or(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var kr=Or("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Le=Or("ascii","a",r=>{let t="a";for(let e=0;e<r.length;e++)t+=String.fromCharCode(r[e]);return t},r=>{r=r.substring(1);let t=L(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),Oo={utf8:kr,"utf-8":kr,hex:X.base16,latin1:Le,ascii:Le,binary:Le,...X},kt=Oo;function tt(r,t="utf8"){let e=kt[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function v(r,t="utf8"){let e=kt[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var Br=Symbol.for("nodejs.util.inspect.custom"),Cr=Object.values(X).map(r=>r.decoder).reduce((r,t)=>r.or(t),X.identity.decoder),Mr=114,Vr=36,zr=37,At=class{type;multihash;privateKey;publicKey;string;constructor(t){this.type=t.type,this.multihash=t.multihash,this.privateKey=t.privateKey,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[ne]=!0;toString(){return this.string==null&&(this.string=S.encode(this.multihash.bytes).slice(1)),this.string}toCID(){return P.createV1(Mr,this.multihash)}toBytes(){return this.multihash.bytes}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return Y(this.multihash.bytes,t);if(typeof t=="string")return Co(t).equals(this);if(t?.multihash?.bytes!=null)return Y(this.multihash.bytes,t.multihash.bytes);throw new Error("not valid Id")}[Br](){return`PeerId(${this.toString()})`}},It=class extends At{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},St=class extends At{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.multihash.digest}},vt=class extends At{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.multihash.digest}},Re=2336,Te=class{type="url";multihash;privateKey;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=xt.digest(tt(this.url))}[Br](){return`PeerId(${this.url})`}[ne]=!0;toString(){return this.toCID().toString()}toCID(){return P.createV1(Re,this.multihash)}toBytes(){return this.toCID().bytes}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=v(t)),t.toString()===this.toString())}};function Co(r,t){if(t=t??Cr,r.charAt(0)==="1"||r.charAt(0)==="Q"){let e=J(S.decode(`z${r}`));return r.startsWith("12D")?new St({multihash:e}):r.startsWith("16U")?new vt({multihash:e}):new It({multihash:e})}return De(Cr.decode(r))}function De(r){try{let t=J(r);if(t.code===xt.code){if(t.digest.length===Vr)return new St({multihash:t});if(t.digest.length===zr)return new vt({multihash:t})}if(t.code===Pt.code)return new It({multihash:t})}catch{return Bo(P.decode(r))}throw new Error("Supplied PeerID CID is invalid")}function Bo(r){if(r?.multihash==null||r.version==null||r.version===1&&r.code!==Mr&&r.code!==Re)throw new Error("Supplied PeerID CID is invalid");if(r.code===Re){let e=v(r.multihash.digest);return new Te(new URL(e))}let t=r.multihash;if(t.code===Pt.code)return new It({multihash:r.multihash});if(t.code===xt.code){if(t.digest.length===Vr)return new St({multihash:r.multihash});if(t.digest.length===zr)return new vt({multihash:r.multihash})}throw new Error("Supplied PeerID CID is invalid")}var Ot=class{index=0;input="";new(t){return this.index=0,this.input=t,this}readAtomically(t){let e=this.index,n=t();return n===void 0&&(this.index=e),n}parseWith(t){let e=t();if(this.index===this.input.length)return e}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(t){return this.readAtomically(()=>{let e=this.readChar();if(e===t)return e})}readSeparator(t,e,n){return this.readAtomically(()=>{if(!(e>0&&this.readGivenChar(t)===void 0))return n()})}readNumber(t,e,n,o){return this.readAtomically(()=>{let i=0,c=0,u=this.peekChar();if(u===void 0)return;let f=u==="0",s=2**(8*o)-1;for(;;){let l=this.readAtomically(()=>{let a=this.readChar();if(a===void 0)return;let h=Number.parseInt(a,t);if(!Number.isNaN(h))return h});if(l===void 0)break;if(i*=t,i+=l,i>s||(c+=1,e!==void 0&&c>e))return}if(c!==0)return!n&&f&&c>1?void 0:i})}readIPv4Addr(){return this.readAtomically(()=>{let t=new Uint8Array(4);for(let e=0;e<t.length;e++){let n=this.readSeparator(".",e,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;t[e]=n}return t})}readIPv6Addr(){let t=e=>{for(let n=0;n<e.length/2;n++){let o=n*2;if(n<e.length-3){let c=this.readSeparator(":",n,()=>this.readIPv4Addr());if(c!==void 0)return e[o]=c[0],e[o+1]=c[1],e[o+2]=c[2],e[o+3]=c[3],[o+4,!0]}let i=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(i===void 0)return[o,!1];e[o]=i>>8,e[o+1]=i&255}return[e.length,!1]};return this.readAtomically(()=>{let e=new Uint8Array(16),[n,o]=t(e);if(n===16)return e;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let i=new Uint8Array(14),c=16-(n+2),[u]=t(i.subarray(0,c));return e.set(i.subarray(0,u),16-u),e})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var $r=45,Mo=15,ct=new Ot;function Fe(r){if(!(r.length>Mo))return ct.new(r).parseWith(()=>ct.readIPv4Addr())}function Ne(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>$r))return ct.new(r).parseWith(()=>ct.readIPv6Addr())}function Ct(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>$r))return ct.new(r).parseWith(()=>ct.readIPAddr())}function Bt(r){return!!Fe(r)}function Mt(r){return!!Ne(r)}function Vt(r){return!!Ct(r)}var qr=Tn(Gr(),1),Vo=["0.0.0.0/8","10.0.0.0/8","100.64.0.0/10","127.0.0.0/8","169.254.0.0/16","172.16.0.0/12","192.0.0.0/24","192.0.0.0/29","192.0.0.8/32","192.0.0.9/32","192.0.0.10/32","192.0.0.170/32","192.0.0.171/32","192.0.2.0/24","192.31.196.0/24","192.52.193.0/24","192.88.99.0/24","192.168.0.0/16","192.175.48.0/24","198.18.0.0/15","198.51.100.0/24","203.0.113.0/24","240.0.0.0/4","255.255.255.255/32"],zo=Vo.map(r=>new qr.Netmask(r));function Ue(r){for(let t of zo)if(t.contains(r))return!0;return!1}function $o(r){return/^::ffff:([0-9a-fA-F]{1,4}):([0-9a-fA-F]{1,4})$/.test(r)}function Go(r){let t=r.split(":");if(t.length<2)return!1;let e=t[t.length-1].padStart(4,"0"),n=t[t.length-2].padStart(4,"0"),o=`${parseInt(n.substring(0,2),16)}.${parseInt(n.substring(2),16)}.${parseInt(e.substring(0,2),16)}.${parseInt(e.substring(2),16)}`;return Ue(o)}function qo(r){return/^::ffff:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(r)}function Ho(r){let t=r.split(":"),e=t[t.length-1];return Ue(e)}function jo(r){return/^::$/.test(r)||/^::1$/.test(r)||/^64:ff9b::([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(r)||/^100::([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2001::([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2001:2[0-9a-fA-F]:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2001:db8:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2002:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^f[c-d]([0-9a-fA-F]{2,2}):/i.test(r)||/^fe[8-9a-bA-B][0-9a-fA-F]:/i.test(r)||/^ff([0-9a-fA-F]{2,2}):/i.test(r)}function _e(r){return Bt(r)?Ue(r):$o(r)?Go(r):qo(r)?Ho(r):Mt(r)?jo(r):void 0}var Xo=Math.pow(2,7),Ko=Math.pow(2,14),Qo=Math.pow(2,21),Pe=Math.pow(2,28),ke=Math.pow(2,35),Oe=Math.pow(2,42),Ce=Math.pow(2,49),w=128,R=127;function A(r){if(r<Xo)return 1;if(r<Ko)return 2;if(r<Qo)return 3;if(r<Pe)return 4;if(r<ke)return 5;if(r<Oe)return 6;if(r<Ce)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Be(r,t,e=0){switch(A(r)){case 8:t[e++]=r&255|w,r/=128;case 7:t[e++]=r&255|w,r/=128;case 6:t[e++]=r&255|w,r/=128;case 5:t[e++]=r&255|w,r/=128;case 4:t[e++]=r&255|w,r>>>=7;case 3:t[e++]=r&255|w,r>>>=7;case 2:t[e++]=r&255|w,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function Wo(r,t,e=0){switch(A(r)){case 8:t.set(e++,r&255|w),r/=128;case 7:t.set(e++,r&255|w),r/=128;case 6:t.set(e++,r&255|w),r/=128;case 5:t.set(e++,r&255|w),r/=128;case 4:t.set(e++,r&255|w),r>>>=7;case 3:t.set(e++,r&255|w),r>>>=7;case 2:t.set(e++,r&255|w),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function Me(r,t){let e=r[t],n=0;if(n+=e&R,e<w||(e=r[t+1],n+=(e&R)<<7,e<w)||(e=r[t+2],n+=(e&R)<<14,e<w)||(e=r[t+3],n+=(e&R)<<21,e<w)||(e=r[t+4],n+=(e&R)*Pe,e<w)||(e=r[t+5],n+=(e&R)*ke,e<w)||(e=r[t+6],n+=(e&R)*Oe,e<w)||(e=r[t+7],n+=(e&R)*Ce,e<w))return n;throw new RangeError("Could not decode varint")}function Jo(r,t){let e=r.get(t),n=0;if(n+=e&R,e<w||(e=r.get(t+1),n+=(e&R)<<7,e<w)||(e=r.get(t+2),n+=(e&R)<<14,e<w)||(e=r.get(t+3),n+=(e&R)<<21,e<w)||(e=r.get(t+4),n+=(e&R)*Pe,e<w)||(e=r.get(t+5),n+=(e&R)*ke,e<w)||(e=r.get(t+6),n+=(e&R)*Oe,e<w)||(e=r.get(t+7),n+=(e&R)*Ce,e<w))return n;throw new RangeError("Could not decode varint")}function K(r,t,e=0){return t==null&&(t=L(A(r))),t instanceof Uint8Array?Be(r,t,e):Wo(r,t,e)}function $(r,t=0){return r instanceof Uint8Array?Me(r,t):Jo(r,t)}function k(r,t){t==null&&(t=r.reduce((o,i)=>o+i.length,0));let e=L(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return e}var xa=parseInt("0xFFFF",16),Ea=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);var Xr=Bt,ri=Mt,Ve=function(r){let t=0;if(r=r.toString().trim(),Xr(r)){let e=new Uint8Array(t+4);return r.split(/\./g).forEach(n=>{e[t++]=parseInt(n,10)&255}),e}if(ri(r)){let e=r.split(":",8),n;for(n=0;n<e.length;n++){let i=Xr(e[n]),c;i&&(c=Ve(e[n]),e[n]=v(c.slice(0,2),"base16")),c!=null&&++n<8&&e.splice(n,0,v(c.slice(2,4),"base16"))}if(e[0]==="")for(;e.length<8;)e.unshift("0");else if(e[e.length-1]==="")for(;e.length<8;)e.push("0");else if(e.length<8){for(n=0;n<e.length&&e[n]!=="";n++);let i=[n,1];for(n=9-e.length;n>0;n--)i.push("0");e.splice.apply(e,i)}let o=new Uint8Array(t+16);for(n=0;n<e.length;n++){let i=parseInt(e[n],16);o[t++]=i>>8&255,o[t++]=i&255}return o}throw new Error("invalid ip address")},Kr=function(r,t=0,e){t=~~t,e=e??r.length-t;let n=new DataView(r.buffer);if(e===4){let o=[];for(let i=0;i<e;i++)o.push(r[t+i]);return o.join(".")}if(e===16){let o=[];for(let i=0;i<e;i+=2)o.push(n.getUint16(t+i).toString(16));return o.join(":").replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}return""};var ut={},ze={},oi=[[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"]];oi.forEach(r=>{let t=ii(...r);ze[t.code]=t,ut[t.name]=t});function ii(r,t,e,n,o){return{code:r,size:t,name:e,resolvable:!!n,path:!!o}}function y(r){if(typeof r=="number"){if(ze[r]!=null)return ze[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(ut[r]!=null)return ut[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var rc=y("ip4"),nc=y("ip6"),oc=y("ipcidr");function He(r,t){switch(y(r).code){case 4:case 41:return ai(t);case 42:return qe(t);case 6:case 273:case 33:case 132:return Jr(t).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return qe(t);case 421:return hi(t);case 444:return Wr(t);case 445:return Wr(t);case 466:return li(t);case 481:return globalThis.encodeURIComponent(qe(t));default:return v(t,"base16")}}function je(r,t){switch(y(r).code){case 4:return Qr(t);case 41:return Qr(t);case 42:return Ge(t);case 6:case 273:case 33:case 132:return Xe(parseInt(t,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return Ge(t);case 421:return ci(t);case 444:return fi(t);case 445:return di(t);case 466:return ui(t);case 481:return Ge(globalThis.decodeURIComponent(t));default:return tt(t,"base16")}}var $e=Object.values(X).map(r=>r.decoder),si=function(){let r=$e[0].or($e[1]);return $e.slice(2).forEach(t=>r=r.or(t)),r}();function Qr(r){if(!Vt(r))throw new Error("invalid ip address");return Ve(r)}function ai(r){let t=Kr(r,0,r.length);if(t==null)throw new Error("ipBuff is required");if(!Vt(t))throw new Error("invalid ip address");return t}function Xe(r){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,r),new Uint8Array(t)}function Jr(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function Ge(r){let t=tt(r),e=Uint8Array.from(K(t.length));return k([e,t],e.length+t.length)}function qe(r){let t=$(r);if(r=r.slice(A(t)),r.length!==t)throw new Error("inconsistent lengths");return v(r)}function ci(r){let t;r[0]==="Q"||r[0]==="1"?t=J(S.decode(`z${r}`)).bytes:t=P.parse(r).multihash.bytes;let e=Uint8Array.from(K(t.length));return k([e,t],e.length+t.length)}function ui(r){let t=si.decode(r),e=Uint8Array.from(K(t.length));return k([e,t],e.length+t.length)}function li(r){let t=$(r),e=r.slice(A(t));if(e.length!==t)throw new Error("inconsistent lengths");return"u"+v(e,"base64url")}function hi(r){let t=$(r),e=r.slice(A(t));if(e.length!==t)throw new Error("inconsistent lengths");return v(e,"base58btc")}function fi(r){let t=r.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==16)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion address.`);let e=V.decode("b"+t[0]),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=Xe(n);return k([e,o],e.length+o.length)}function di(r){let t=r.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==56)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion3 address.`);let e=V.decode(`b${t[0]}`),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=Xe(n);return k([e,o],e.length+o.length)}function Wr(r){let t=r.slice(0,r.length-2),e=r.slice(r.length-2),n=v(t,"base32"),o=Jr(e);return`${n}:${o}`}function Zr(r){r=Ke(r);let t=[],e=[],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 c=o[i],u=y(c);if(u.size===0){t.push([u.code]),e.push([u.code]);continue}if(i++,i>=o.length)throw tn("invalid address: "+r);if(u.path===!0){n=Ke(o.slice(i).join("/")),t.push([u.code,je(u.code,n)]),e.push([u.code,n]);break}let f=je(u.code,o[i]);t.push([u.code,f]),e.push([u.code,He(u.code,f)])}return{string:Yr(e),bytes:We(t),tuples:t,stringTuples:e,path:n}}function Qe(r){let t=[],e=[],n=null,o=0;for(;o<r.length;){let i=$(r,o),c=A(i),u=y(i),f=pi(u,r.slice(o+c));if(f===0){t.push([i]),e.push([i]),o+=c;continue}let s=r.slice(o+c,o+c+f);if(o+=f+c,o>r.length)throw tn("Invalid address Uint8Array: "+v(r,"base16"));t.push([i,s]);let l=He(i,s);if(e.push([i,l]),u.path===!0){n=l;break}}return{bytes:Uint8Array.from(r),string:Yr(e),tuples:t,stringTuples:e,path:n}}function Yr(r){let t=[];return r.map(e=>{let n=y(e[0]);return t.push(n.name),e.length>1&&e[1]!=null&&t.push(e[1]),null}),Ke(t.join("/"))}function We(r){return k(r.map(t=>{let e=y(t[0]),n=Uint8Array.from(K(e.code));return t.length>1&&t[1]!=null&&(n=k([n,t[1]])),n}))}function pi(r,t){if(r.size>0)return r.size/8;if(r.size===0)return 0;{let e=$(t instanceof Uint8Array?t:Uint8Array.from(t));return e+A(e)}}function Ke(r){return"/"+r.trim().split("/").filter(t=>t).join("/")}function tn(r){return new Error("Error parsing address: "+r)}var mi=Symbol.for("nodejs.util.inspect.custom"),Je=Symbol.for("@multiformats/js-multiaddr/multiaddr"),gi=[y("dns").code,y("dns4").code,y("dns6").code,y("dnsaddr").code],$t=class r{bytes;#e;#t;#r;#n;[Je]=!0;constructor(t){t==null&&(t="");let e;if(t instanceof Uint8Array)e=Qe(t);else if(typeof t=="string"){if(t.length>0&&t.charAt(0)!=="/")throw new Error(`multiaddr "${t}" must start with a "/"`);e=Zr(t)}else if(rn(t))e=Qe(t.bytes);else throw new Error("addr must be a string, Buffer, or another Multiaddr");this.bytes=e.bytes,this.#e=e.string,this.#t=e.tuples,this.#r=e.stringTuples,this.#n=e.path}toString(){return this.#e}toJSON(){return this.toString()}toOptions(){let t,e,n,o,i="",c=y("tcp"),u=y("udp"),f=y("ip4"),s=y("ip6"),l=y("dns6"),a=y("ip6zone");for(let[p,d]of this.stringTuples())p===a.code&&(i=`%${d??""}`),gi.includes(p)&&(e=c.name,o=443,n=`${d??""}${i}`,t=p===l.code?6:4),(p===c.code||p===u.code)&&(e=y(p).name,o=parseInt(d??"")),(p===f.code||p===s.code)&&(e=y(p).name,n=`${d??""}${i}`,t=p===s.code?6:4);if(t==null||e==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:t,host:n,transport:e,port:o}}protos(){return this.#t.map(([t])=>Object.assign({},y(t)))}protoCodes(){return this.#t.map(([t])=>t)}protoNames(){return this.#t.map(([t])=>y(t).name)}tuples(){return this.#t}stringTuples(){return this.#r}encapsulate(t){return t=new r(t),new r(this.toString()+t.toString())}decapsulate(t){let e=t.toString(),n=this.toString(),o=n.lastIndexOf(e);if(o<0)throw new Error(`Address ${this.toString()} does not contain subaddress: ${t.toString()}`);return new r(n.slice(0,o))}decapsulateCode(t){let e=this.tuples();for(let n=e.length-1;n>=0;n--)if(e[n][0]===t)return new r(We(e.slice(0,n)));return this}getPeerId(){try{let t=[];this.stringTuples().forEach(([n,o])=>{n===ut.p2p.code&&t.push([n,o]),n===ut["p2p-circuit"].code&&(t=[])});let e=t.pop();if(e?.[1]!=null){let n=e[1];return n[0]==="Q"||n[0]==="1"?v(S.decode(`z${n}`),"base58btc"):v(P.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){return this.#n}equals(t){return Y(this.bytes,t.bytes)}async resolve(t){let e=this.protos().find(i=>i.resolvable);if(e==null)return[this];let n=en.get(e.name);if(n==null)throw new W(`no available resolver for ${e.name}`,"ERR_NO_AVAILABLE_RESOLVER");return(await n(this,t)).map(i=>lt(i))}nodeAddress(){let t=this.toOptions();if(t.transport!=="tcp"&&t.transport!=="udp")throw new Error(`multiaddr must have a valid format - no protocol with name: "${t.transport}". Must have a valid transport protocol: "{tcp, udp}"`);return{family:t.family,address:t.host,port:t.port}}isThinWaistAddress(t){let e=(t??this).protos();return!(e.length!==2||e[0].code!==4&&e[0].code!==41||e[1].code!==6&&e[1].code!==273)}[mi](){return`Multiaddr(${this.#e})`}};var en=new Map;function rn(r){return!!r?.[Je]}function lt(r){return new $t(r)}function bi(r){return r[Symbol.asyncIterator]!=null}function wi(r){if(bi(r))return(async()=>{for await(let t of r)return t})();for(let t of r)return t}var Ze=wi;var on=Symbol.for("@achingbrain/uint8arraylist");function nn(r,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let e=0;for(let n of r){let o=e+n.byteLength;if(t<o)return{buf:n,index:t-e};e=o}throw new RangeError("index is out of bounds")}function Gt(r){return!!r?.[on]}var ht=class r{bufs;length;[on]=!0;constructor(...t){this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let e=0;for(let n of t)if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.push(n);else if(Gt(n))e+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}prepend(...t){this.prependAll(t)}prependAll(t){let e=0;for(let n of t.reverse())if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.unshift(n);else if(Gt(n))e+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}get(t){let e=nn(this.bufs,t);return e.buf[e.index]}set(t,e){let n=nn(this.bufs,t);n.buf[n.index]=e}write(t,e=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(e+n,t[n]);else if(Gt(t))for(let n=0;n<t.length;n++)this.set(e+n,t.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,e){let{bufs:n,length:o}=this._subList(t,e);return k(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:k(n,o)}sublist(t,e){let{bufs:n,length:o}=this._subList(t,e),i=new r;return i.length=o,i.bufs=[...n],i}_subList(t,e){if(t=t??0,e=e??this.length,t<0&&(t=this.length+t),e<0&&(e=this.length+e),t<0||e>this.length)throw new RangeError("index is out of bounds");if(t===e)return{bufs:[],length:0};if(t===0&&e===this.length)return{bufs:this.bufs,length:this.length};let n=[],o=0;for(let i=0;i<this.bufs.length;i++){let c=this.bufs[i],u=o,f=u+c.byteLength;if(o=f,t>=f)continue;let s=t>=u&&t<f,l=e>u&&e<=f;if(s&&l){if(t===u&&e===f){n.push(c);break}let a=t-u;n.push(c.subarray(a,a+(e-t)));break}if(s){if(t===0){n.push(c);continue}n.push(c.subarray(t-u));continue}if(l){if(e===f){n.push(c);break}n.push(c.subarray(0,e-u));break}n.push(c)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!Gt(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(e=Number(e??0),isNaN(e)&&(e=0),e<0&&(e=this.length+e),e<0&&(e=0),t.length===0)return e>this.length?this.length:e;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let i=256,c=new Int32Array(i);for(let a=0;a<i;a++)c[a]=-1;for(let a=0;a<o;a++)c[n[a]]=a;let u=c,f=this.byteLength-n.byteLength,s=n.byteLength-1,l;for(let a=e;a<=f;a+=l){l=0;for(let h=s;h>=0;h--){let p=this.get(a+h);if(n[h]!==p){l=Math.max(1,h-u[p]);break}}if(l===0)return a}return-1}getInt8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getInt8(0)}setInt8(t,e){let n=L(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,e),this.write(n,t)}getInt16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,e)}setInt16(t,e,n){let o=z(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,e,n),this.write(o,t)}getInt32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,e)}setInt32(t,e,n){let o=z(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,e,n),this.write(o,t)}getBigInt64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,e)}setBigInt64(t,e,n){let o=z(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,e,n),this.write(o,t)}getUint8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getUint8(0)}setUint8(t,e){let n=L(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,e),this.write(n,t)}getUint16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,e)}setUint16(t,e,n){let o=z(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,e,n),this.write(o,t)}getUint32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,e)}setUint32(t,e,n){let o=z(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,e,n),this.write(o,t)}getBigUint64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,e)}setBigUint64(t,e,n){let o=z(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,e,n),this.write(o,t)}getFloat32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,e)}setFloat32(t,e,n){let o=z(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,e,n),this.write(o,t)}getFloat64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,e)}setFloat64(t,e,n){let o=z(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,e,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof r)||t.bufs.length!==this.bufs.length)return!1;for(let e=0;e<this.bufs.length;e++)if(!Y(this.bufs[e],t.bufs[e]))return!1;return!0}static fromUint8Arrays(t,e){let n=new r;return n.bufs=t,e==null&&(e=t.reduce((o,i)=>o+i.byteLength,0)),n.length=e,n}};function qt(r){return r[Symbol.asyncIterator]!=null}var Ht=r=>{let t=A(r),e=L(t);return K(r,e),Ht.bytes=t,e};Ht.bytes=0;function Rt(r,t){t=t??{};let e=t.lengthEncoder??Ht;function*n(o){let i=e(o.byteLength);i instanceof Uint8Array?yield i:yield*i,o instanceof Uint8Array?yield o:yield*o}return qt(r)?async function*(){for await(let o of r)yield*n(o)}():function*(){for(let o of r)yield*n(o)}()}Rt.single=(r,t)=>{t=t??{};let e=t.lengthEncoder??Ht;return new ht(e(r.byteLength),r)};var jt=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},Xt=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},Kt=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"},Tt=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};var yi=8,xi=1024*1024*4,et;(function(r){r[r.LENGTH=0]="LENGTH",r[r.DATA=1]="DATA"})(et||(et={}));var Ye=r=>{let t=$(r);return Ye.bytes=A(t),t};Ye.bytes=0;function ft(r,t){let e=new ht,n=et.LENGTH,o=-1,i=t?.lengthDecoder??Ye,c=t?.maxLengthLength??yi,u=t?.maxDataLength??xi;function*f(){for(;e.byteLength>0;){if(n===et.LENGTH)try{if(o=i(e),o<0)throw new jt("Invalid message length");if(o>u)throw new Xt("Message length too long");let s=i.bytes;e.consume(s),t?.onLength!=null&&t.onLength(o),n=et.DATA}catch(s){if(s instanceof RangeError){if(e.byteLength>c)throw new Kt("Message length length too long");break}throw s}if(n===et.DATA){if(e.byteLength<o)break;let s=e.sublist(0,o);e.consume(o),t?.onData!=null&&t.onData(s),yield s,n=et.LENGTH}}}return qt(r)?async function*(){for await(let s of r)e.append(s),yield*f();if(e.byteLength>0)throw new Tt("Unexpected end of input")}():function*(){for(let s of r)e.append(s),yield*f();if(e.byteLength>0)throw new Tt("Unexpected end of input")}()}ft.fromReader=(r,t)=>{let e=1,n=async function*(){for(;;)try{let{done:i,value:c}=await r.next(e);if(i===!0)return;c!=null&&(yield c)}catch(i){if(i.code==="ERR_UNDER_READ")return{done:!0,value:null};throw i}finally{e=1}}();return ft(n,{...t??{},onLength:i=>{e=i}})};function Ai(r){let[t,e]=r[Symbol.asyncIterator]!=null?[r[Symbol.asyncIterator](),Symbol.asyncIterator]:[r[Symbol.iterator](),Symbol.iterator],n=[];return{peek:()=>t.next(),push:o=>{n.push(o)},next:()=>n.length>0?{done:!1,value:n.shift()}:t.next(),[e](){return this}}}var sn=Ai;function Ii(r){return r[Symbol.asyncIterator]!=null}function Si(r,t){let e=0;if(Ii(r))return async function*(){for await(let f of r)yield t(f,e++)}();let n=sn(r),{value:o,done:i}=n.next();if(i===!0)return function*(){}();let c=t(o,e++);if(typeof c.then=="function")return async function*(){yield await c;for await(let f of n)yield t(f,e++)}();let u=t;return function*(){yield c;for(let f of n)yield u(f,e++)}()}var an=Si;function G(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var Qt=globalThis.CustomEvent??Event;async function*tr(r,t={}){let e=t.concurrency??1/0;e<1&&(e=1/0);let n=t.ordered==null?!1:t.ordered,o=new EventTarget,i=[],c=G(),u=G(),f=!1,s,l=!1;o.addEventListener("task-complete",()=>{u.resolve()}),Promise.resolve().then(async()=>{try{for await(let d of r){if(i.length===e&&(c=G(),await c.promise),l)break;let m={done:!1};i.push(m),d().then(g=>{m.done=!0,m.ok=!0,m.value=g,o.dispatchEvent(new Qt("task-complete"))},g=>{m.done=!0,m.err=g,o.dispatchEvent(new Qt("task-complete"))})}f=!0,o.dispatchEvent(new Qt("task-complete"))}catch(d){s=d,o.dispatchEvent(new Qt("task-complete"))}});function a(){return n?i[0]?.done:!!i.find(d=>d.done)}function*h(){for(;i.length>0&&i[0].done;){let d=i[0];if(i.shift(),d.ok)yield d.value;else throw l=!0,c.resolve(),d.err;c.resolve()}}function*p(){for(;a();)for(let d=0;d<i.length;d++)if(i[d].done){let m=i[d];if(i.splice(d,1),d--,m.ok)yield m.value;else throw l=!0,c.resolve(),m.err;c.resolve()}}for(;;){if(a()||(u=G(),await u.promise),s!=null)throw s;if(n?yield*h():yield*p(),f&&i.length===0)break}}var Wt=class{buffer;mask;top;btm;next;constructor(t){if(!(t>0)||t-1&t)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(t),this.mask=t-1,this.top=0,this.btm=0,this.next=null}push(t){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=t,this.top=this.top+1&this.mask,!0)}shift(){let t=this.buffer[this.btm];if(t!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,t}isEmpty(){return this.buffer[this.btm]===void 0}},dt=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new Wt(this.hwm),this.tail=this.head,this.size=0}calculateSize(t){return t?.byteLength!=null?t.byteLength:1}push(t){if(t?.value!=null&&(this.size+=this.calculateSize(t.value)),!this.head.push(t)){let e=this.head;this.head=e.next=new Wt(2*this.head.buffer.length),this.head.push(t)}}shift(){let t=this.tail.shift();if(t===void 0&&this.tail.next!=null){let e=this.tail.next;this.tail.next=null,this.tail=e,t=this.tail.shift()}return t?.value!=null&&(this.size-=this.calculateSize(t.value)),t}isEmpty(){return this.head.isEmpty()}};var er=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.code=e??"ABORT_ERR"}};function Jt(r={}){return vi(e=>{let n=e.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},r)}function vi(r,t){t=t??{};let e=t.onEnd,n=new dt,o,i,c,u=G(),f=async()=>{try{return n.isEmpty()?c?{done:!0}:await new Promise((g,E)=>{i=D=>{i=null,n.push(D);try{g(r(n))}catch(I){E(I)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{u.resolve(),u=G()})}},s=g=>i!=null?i(g):(n.push(g),o),l=g=>(n=new dt,i!=null?i({error:g}):(n.push({error:g}),o)),a=g=>{if(c)return o;if(t?.objectMode!==!0&&g?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return s({done:!1,value:g})},h=g=>c?o:(c=!0,g!=null?l(g):s({done:!0})),p=()=>(n=new dt,h(),{done:!0}),d=g=>(h(g),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:f,return:p,throw:d,push:a,end:h,get readableLength(){return n.size},onEmpty:async g=>{let E=g?.signal;if(E?.throwIfAborted(),n.isEmpty())return;let D,I;E!=null&&(D=new Promise((F,_)=>{I=()=>{_(new er)},E.addEventListener("abort",I)}));try{await Promise.race([u.promise,D])}finally{I!=null&&E!=null&&E?.removeEventListener("abort",I)}}},e==null)return o;let m=o;return o={[Symbol.asyncIterator](){return this},next(){return m.next()},throw(g){return m.throw(g),e!=null&&(e(g),e=void 0),{done:!0}},return(){return m.return(),e!=null&&(e(),e=void 0),{done:!0}},push:a,end(g){return m.end(g),e!=null&&(e(g),e=void 0),o},get readableLength(){return m.readableLength},onEmpty:g=>m.onEmpty(g)},o}function Li(r){return r[Symbol.asyncIterator]!=null}function Ri(...r){let t=[];for(let e of r)Li(e)||t.push(e);return t.length===r.length?function*(){for(let e of t)yield*e}():async function*(){let e=Jt({objectMode:!0});Promise.resolve().then(async()=>{try{await Promise.all(r.map(async n=>{for await(let o of n)e.push(o)})),e.end()}catch(n){e.end(n)}}),yield*e}()}var cn=Ri;function nr(r,...t){if(r==null)throw new Error("Empty pipeline");if(rr(r)){let n=r;r=()=>n.source}else if(ln(r)||un(r)){let n=r;r=()=>n}let e=[r,...t];if(e.length>1&&rr(e[e.length-1])&&(e[e.length-1]=e[e.length-1].sink),e.length>2)for(let n=1;n<e.length-1;n++)rr(e[n])&&(e[n]=Di(e[n]));return Ti(...e)}var Ti=(...r)=>{let t;for(;r.length>0;)t=r.shift()(t);return t},un=r=>r?.[Symbol.asyncIterator]!=null,ln=r=>r?.[Symbol.iterator]!=null,rr=r=>r==null?!1:r.sink!=null&&r.source!=null,Di=r=>t=>{let e=r.sink(t);if(e?.then!=null){let n=Jt({objectMode:!0});e.then(()=>{n.end()},c=>{n.end(c)});let o,i=r.source;if(un(i))o=async function*(){yield*i,n.end()};else if(ln(i))o=function*(){yield*i,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return cn(n,o())}return r.source};var hn="libp2p",fn="autonat",dn="1.0.0";var or=new Float32Array([-0]),Q=new Uint8Array(or.buffer);function pn(r,t,e){or[0]=r,t[e]=Q[0],t[e+1]=Q[1],t[e+2]=Q[2],t[e+3]=Q[3]}function mn(r,t){return Q[0]=r[t],Q[1]=r[t+1],Q[2]=r[t+2],Q[3]=r[t+3],or[0]}var ir=new Float64Array([-0]),T=new Uint8Array(ir.buffer);function gn(r,t,e){ir[0]=r,t[e]=T[0],t[e+1]=T[1],t[e+2]=T[2],t[e+3]=T[3],t[e+4]=T[4],t[e+5]=T[5],t[e+6]=T[6],t[e+7]=T[7]}function bn(r,t){return T[0]=r[t],T[1]=r[t+1],T[2]=r[t+2],T[3]=r[t+3],T[4]=r[t+4],T[5]=r[t+5],T[6]=r[t+6],T[7]=r[t+7],ir[0]}var Fi=BigInt(Number.MAX_SAFE_INTEGER),Ni=BigInt(Number.MIN_SAFE_INTEGER),U=class r{lo;hi;constructor(t,e){this.lo=t|0,this.hi=e|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(e+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(BigInt(e)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,e=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?e===0?t<16384?t<128?1:2:t<2097152?3:4:e<16384?e<128?5:6:e<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return rt;if(t<Fi&&t>Ni)return this.fromNumber(Number(t));let e=t<0n;e&&(t=-t);let n=t>>32n,o=t-(n<<32n);return e&&(n=~n|0n,o=~o|0n,++o>wn&&(o=0n,++n>wn&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(t){if(t===0)return rt;let e=t<0;e&&(t=-t);let n=t>>>0,o=(t-n)/4294967296>>>0;return e&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new r(n,o)}static from(t){return typeof t=="number"?r.fromNumber(t):typeof t=="bigint"?r.fromBigInt(t):typeof t=="string"?r.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new r(t.low>>>0,t.high>>>0):rt}},rt=new U(0,0);rt.toBigInt=function(){return 0n};rt.zzEncode=rt.zzDecode=function(){return this};rt.length=function(){return 1};var wn=4294967296n;function yn(r){let t=0,e=0;for(let n=0;n<r.length;++n)e=r.charCodeAt(n),e<128?t+=1:e<2048?t+=2:(e&64512)===55296&&(r.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function xn(r,t,e){if(e-t<1)return"";let o,i=[],c=0,u;for(;t<e;)u=r[t++],u<128?i[c++]=u:u>191&&u<224?i[c++]=(u&31)<<6|r[t++]&63:u>239&&u<365?(u=((u&7)<<18|(r[t++]&63)<<12|(r[t++]&63)<<6|r[t++]&63)-65536,i[c++]=55296+(u>>10),i[c++]=56320+(u&1023)):i[c++]=(u&15)<<12|(r[t++]&63)<<6|r[t++]&63,c>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,i)),c=0);return o!=null?(c>0&&o.push(String.fromCharCode.apply(String,i.slice(0,c))),o.join("")):String.fromCharCode.apply(String,i.slice(0,c))}function sr(r,t,e){let n=e,o,i;for(let c=0;c<r.length;++c)o=r.charCodeAt(c),o<128?t[e++]=o:o<2048?(t[e++]=o>>6|192,t[e++]=o&63|128):(o&64512)===55296&&((i=r.charCodeAt(c+1))&64512)===56320?(o=65536+((o&1023)<<10)+(i&1023),++c,t[e++]=o>>18|240,t[e++]=o>>12&63|128,t[e++]=o>>6&63|128,t[e++]=o&63|128):(t[e++]=o>>12|224,t[e++]=o>>6&63|128,t[e++]=o&63|128);return e-n}function C(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function Zt(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var ar=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=t,this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,C(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw C(this,4);return Zt(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw C(this,4);return Zt(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw C(this,4);let t=mn(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw C(this,4);let t=bn(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),e=this.pos,n=this.pos+t;if(n>this.len)throw C(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return xn(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw C(this,t);this.pos+=t}else do if(this.pos>=this.len)throw C(this);while(this.buf[this.pos++]&128);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new U(0,0),e=0;if(this.len-this.pos>4){for(;e<4;++e)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;e=0}else{for(;e<3;++e){if(this.pos>=this.len)throw C(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<e*7)>>>0,t}if(this.len-this.pos>4){for(;e<5;++e)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;e<5;++e){if(this.pos>=this.len)throw C(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw C(this,8);let t=Zt(this.buf,this.pos+=4),e=Zt(this.buf,this.pos+=4);return new U(t,e)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=Me(this.buf,this.pos);return this.pos+=A(t),t}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function cr(r){return new ar(r instanceof Uint8Array?r:r.subarray())}function pt(r,t,e){let n=cr(r);return t.decode(n,void 0,e)}function ur(r){let t=r??8192,e=t>>>1,n,o=t;return function(c){if(c<1||c>e)return L(c);o+c>t&&(n=L(t),o=0);let u=n.subarray(o,o+=c);return o&7&&(o=(o|7)+1),u}}var nt=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function lr(){}var fr=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Ui=ur();function _i(r){return globalThis.Buffer!=null?L(r):Ui(r)}var Ft=class{len;head;tail;states;constructor(){this.len=0,this.head=new nt(lr,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new nt(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new dr((t=t>>>0)<128?1:t<16384?2:t<2097152?3:t<268435456?4:5,t)).len,this}int32(t){return t<0?this._push(Yt,10,U.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=U.fromBigInt(t);return this._push(Yt,e.length(),e)}uint64Number(t){return this._push(Be,A(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let e=U.fromBigInt(t).zzEncode();return this._push(Yt,e.length(),e)}sint64Number(t){let e=U.fromNumber(t).zzEncode();return this._push(Yt,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(hr,1,t?1:0)}fixed32(t){return this._push(Dt,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=U.fromBigInt(t);return this._push(Dt,4,e.lo)._push(Dt,4,e.hi)}fixed64Number(t){let e=U.fromNumber(t);return this._push(Dt,4,e.lo)._push(Dt,4,e.hi)}fixed64String(t){return this.fixed64(BigInt(t))}sfixed64(t){return this.fixed64(t)}sfixed64Number(t){return this.fixed64Number(t)}sfixed64String(t){return this.fixed64String(t)}float(t){return this._push(pn,4,t)}double(t){return this._push(gn,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(hr,1,0):this.uint32(e)._push(ki,e,t)}string(t){let e=yn(t);return e!==0?this.uint32(e)._push(sr,e,t):this._push(hr,1,0)}fork(){return this.states=new fr(this),this.head=this.tail=new nt(lr,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new nt(lr,0,0),this.len=0),this}ldelim(){let t=this.head,e=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=e,this.len+=n),this}finish(){let t=this.head.next,e=_i(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function hr(r,t,e){t[e]=r&255}function Pi(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var dr=class extends nt{next;constructor(t,e){super(Pi,t,e),this.next=void 0}};function Yt(r,t,e){for(;r.hi!==0;)t[e++]=r.lo&127|128,r.lo=(r.lo>>>7|r.hi<<25)>>>0,r.hi>>>=7;for(;r.lo>127;)t[e++]=r.lo&127|128,r.lo=r.lo>>>7;t[e++]=r.lo}function Dt(r,t,e){t[e]=r&255,t[e+1]=r>>>8&255,t[e+2]=r>>>16&255,t[e+3]=r>>>24}function ki(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(Ft.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(Oi,t,r),this},Ft.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(Ci,t,r),this});function Oi(r,t,e){t.set(r,e)}function Ci(r,t,e){r.length<40?sr(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(tt(r),e)}function pr(){return new Ft}function mt(r,t){let e=pr();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var gt;(function(r){r[r.VARINT=0]="VARINT",r[r.BIT64=1]="BIT64",r[r.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",r[r.START_GROUP=3]="START_GROUP",r[r.END_GROUP=4]="END_GROUP",r[r.BIT32=5]="BIT32"})(gt||(gt={}));function te(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function ee(r){function t(o){if(r[o.toString()]==null)throw new Error("Invalid enum value");return r[o]}let e=function(i,c){let u=t(i);c.int32(u)},n=function(i){let c=i.int32();return t(c)};return te("enum",gt.VARINT,e,n)}function bt(r,t){return te("message",gt.LENGTH_DELIMITED,r,t)}var b;(function(r){let t;(function(s){s.DIAL="DIAL",s.DIAL_RESPONSE="DIAL_RESPONSE"})(t=r.MessageType||(r.MessageType={}));let e;(function(s){s[s.DIAL=0]="DIAL",s[s.DIAL_RESPONSE=1]="DIAL_RESPONSE"})(e||(e={})),function(s){s.codec=()=>ee(e)}(t=r.MessageType||(r.MessageType={}));let n;(function(s){s.OK="OK",s.E_DIAL_ERROR="E_DIAL_ERROR",s.E_DIAL_REFUSED="E_DIAL_REFUSED",s.E_BAD_REQUEST="E_BAD_REQUEST",s.E_INTERNAL_ERROR="E_INTERNAL_ERROR"})(n=r.ResponseStatus||(r.ResponseStatus={}));let o;(function(s){s[s.OK=0]="OK",s[s.E_DIAL_ERROR=100]="E_DIAL_ERROR",s[s.E_DIAL_REFUSED=101]="E_DIAL_REFUSED",s[s.E_BAD_REQUEST=200]="E_BAD_REQUEST",s[s.E_INTERNAL_ERROR=300]="E_INTERNAL_ERROR"})(o||(o={})),function(s){s.codec=()=>ee(o)}(n=r.ResponseStatus||(r.ResponseStatus={}));let i;(function(s){let l;s.codec=()=>(l==null&&(l=bt((a,h,p={})=>{if(p.lengthDelimited!==!1&&h.fork(),a.id!=null&&(h.uint32(10),h.bytes(a.id)),a.addrs!=null)for(let d of a.addrs)h.uint32(18),h.bytes(d);p.lengthDelimited!==!1&&h.ldelim()},(a,h)=>{let p={addrs:[]},d=h==null?a.len:a.pos+h;for(;a.pos<d;){let m=a.uint32();switch(m>>>3){case 1:p.id=a.bytes();break;case 2:p.addrs.push(a.bytes());break;default:a.skipType(m&7);break}}return p})),l),s.encode=a=>mt(a,s.codec()),s.decode=a=>pt(a,s.codec())})(i=r.PeerInfo||(r.PeerInfo={}));let c;(function(s){let l;s.codec=()=>(l==null&&(l=bt((a,h,p={})=>{p.lengthDelimited!==!1&&h.fork(),a.peer!=null&&(h.uint32(10),r.PeerInfo.codec().encode(a.peer,h)),p.lengthDelimited!==!1&&h.ldelim()},(a,h)=>{let p={},d=h==null?a.len:a.pos+h;for(;a.pos<d;){let m=a.uint32();switch(m>>>3){case 1:p.peer=r.PeerInfo.codec().decode(a,a.uint32());break;default:a.skipType(m&7);break}}return p})),l),s.encode=a=>mt(a,s.codec()),s.decode=a=>pt(a,s.codec())})(c=r.Dial||(r.Dial={}));let u;(function(s){let l;s.codec=()=>(l==null&&(l=bt((a,h,p={})=>{p.lengthDelimited!==!1&&h.fork(),a.status!=null&&(h.uint32(8),r.ResponseStatus.codec().encode(a.status,h)),a.statusText!=null&&(h.uint32(18),h.string(a.statusText)),a.addr!=null&&(h.uint32(26),h.bytes(a.addr)),p.lengthDelimited!==!1&&h.ldelim()},(a,h)=>{let p={},d=h==null?a.len:a.pos+h;for(;a.pos<d;){let m=a.uint32();switch(m>>>3){case 1:p.status=r.ResponseStatus.codec().decode(a);break;case 2:p.statusText=a.string();break;case 3:p.addr=a.bytes();break;default:a.skipType(m&7);break}}return p})),l),s.encode=a=>mt(a,s.codec()),s.decode=a=>pt(a,s.codec())})(u=r.DialResponse||(r.DialResponse={}));let f;r.codec=()=>(f==null&&(f=bt((s,l,a={})=>{a.lengthDelimited!==!1&&l.fork(),s.type!=null&&(l.uint32(8),r.MessageType.codec().encode(s.type,l)),s.dial!=null&&(l.uint32(18),r.Dial.codec().encode(s.dial,l)),s.dialResponse!=null&&(l.uint32(26),r.DialResponse.codec().encode(s.dialResponse,l)),a.lengthDelimited!==!1&&l.ldelim()},(s,l)=>{let a={},h=l==null?s.len:s.pos+l;for(;s.pos<h;){let p=s.uint32();switch(p>>>3){case 1:a.type=r.MessageType.codec().decode(s);break;case 2:a.dial=r.Dial.codec().decode(s,s.uint32());break;case 3:a.dialResponse=r.DialResponse.codec().decode(s,s.uint32());break;default:s.skipType(p&7);break}}return a})),f),r.encode=s=>mt(s,r.codec()),r.decode=s=>pt(s,r.codec())})(b||(b={}));var mr=4,re=class{components;startupDelay;refreshInterval;protocol;timeout;maxInboundStreams;maxOutboundStreams;verifyAddressTimeout;started;log;constructor(t,e){this.components=t,this.log=t.logger.forComponent("libp2p:autonat"),this.started=!1,this.protocol=`/${e.protocolPrefix??hn}/${fn}/${dn}`,this.timeout=e.timeout??3e4,this.maxInboundStreams=e.maxInboundStreams??1,this.maxOutboundStreams=e.maxOutboundStreams??1,this.startupDelay=e.startupDelay??5e3,this.refreshInterval=e.refreshInterval??6e4,this._verifyExternalAddresses=this._verifyExternalAddresses.bind(this)}[Symbol.toStringTag]="@libp2p/autonat";isStarted(){return this.started}async start(){this.started||(await this.components.registrar.handle(this.protocol,t=>{this.handleIncomingAutonatStream(t).catch(e=>{this.log.error("error handling incoming autonat stream",e)})},{maxInboundStreams:this.maxInboundStreams,maxOutboundStreams:this.maxOutboundStreams}),this.verifyAddressTimeout=setTimeout(this._verifyExternalAddresses,this.startupDelay),this.started=!0)}async stop(){await this.components.registrar.unhandle(this.protocol),clearTimeout(this.verifyAddressTimeout),this.started=!1}async handleIncomingAutonatStream(t){let e=AbortSignal.timeout(this.timeout),n=()=>{t.stream.abort(new W("handleIncomingAutonatStream timeout",oe))};e.addEventListener("abort",n,{once:!0}),ie(1/0,e);try{let o=this;await nr(t.stream,i=>ft(i),async function*(i){let c=await Ze(i);if(c==null){o.log("no message received"),yield b.encode({type:b.MessageType.DIAL_RESPONSE,dialResponse:{status:b.ResponseStatus.E_BAD_REQUEST,statusText:"No message was sent"}});return}let u;try{u=b.decode(c)}catch(f){o.log.error("could not decode message",f),yield b.encode({type:b.MessageType.DIAL_RESPONSE,dialResponse:{status:b.ResponseStatus.E_BAD_REQUEST,statusText:"Could not decode message"}});return}yield b.encode(await o.handleAutonatMessage(u,t.connection,{signal:e}))},i=>Rt(i),t.stream)}catch(o){this.log.error("error handling incoming autonat stream",o)}finally{e.removeEventListener("abort",n)}}_verifyExternalAddresses(){this.verifyExternalAddresses().catch(t=>{this.log.error("error verifying external address",t)})}async handleAutonatMessage(t,e,n){let o=this.components.addressManager.getAddresses().map(a=>a.toOptions().host),i=t.dial;if(i==null)return this.log.error("dial was missing from message"),{type:b.MessageType.DIAL_RESPONSE,dialResponse:{status:b.ResponseStatus.E_BAD_REQUEST,statusText:"No Dial message found in message"}};let c,u=i.peer;if(u?.id==null)return this.log.error("PeerId missing from message"),{type:b.MessageType.DIAL_RESPONSE,dialResponse:{status:b.ResponseStatus.E_BAD_REQUEST,statusText:"missing peer info"}};try{c=De(u.id)}catch(a){return this.log.error("invalid PeerId",a),{type:b.MessageType.DIAL_RESPONSE,dialResponse:{status:b.ResponseStatus.E_BAD_REQUEST,statusText:"bad peer id"}}}if(this.log("incoming request from %p",c),!e.remotePeer.equals(c))return this.log("target peer %p did not equal sending peer %p",c,e.remotePeer),{type:b.MessageType.DIAL_RESPONSE,dialResponse:{status:b.ResponseStatus.E_BAD_REQUEST,statusText:"peer id mismatch"}};let f=u.addrs.map(a=>lt(a)).filter(a=>{let h=a.toOptions().host===e.remoteAddr.toOptions().host;return this.log.trace("request to dial %a was sent from %a is same host %s",a,e.remoteAddr,h),h}).filter(a=>{let h=a.toOptions().host,p=!(_e(h)??!1);return this.log.trace("host %s was public %s",h,p),p}).filter(a=>{let h=a.toOptions().host,p=!o.includes(h);return this.log.trace("host %s was not our host %s",h,p),p}).filter(a=>{let h=!!this.components.transportManager.dialTransportForMultiaddr(a);return this.log.trace("transport for %a is supported %s",a,h),h}).map(a=>(a.getPeerId()==null&&(a=a.encapsulate(`/p2p/${c.toString()}`)),a));if(f.length===0)return this.log("no valid multiaddrs for %p in message",c),{type:b.MessageType.DIAL_RESPONSE,dialResponse:{status:b.ResponseStatus.E_DIAL_REFUSED,statusText:"no dialable addresses"}};this.log("dial multiaddrs %s for peer %p",f.map(a=>a.toString()).join(", "),c);let s="",l=f[0];for await(let a of f){let h;l=a;try{if(h=await this.components.connectionManager.openConnection(a,n),!h.remoteAddr.equals(a))throw this.log.error("tried to dial %a but dialed %a",a,h.remoteAddr),new Error("Unexpected remote address");return this.log("Success %p",c),{type:b.MessageType.DIAL_RESPONSE,dialResponse:{status:b.ResponseStatus.OK,addr:h.remoteAddr.decapsulateCode(y("p2p").code).bytes}}}catch(p){this.log("could not dial %p",c,p),s=p.message}finally{h!=null&&await h.close()}}return{type:b.MessageType.DIAL_RESPONSE,dialResponse:{status:b.ResponseStatus.E_DIAL_ERROR,statusText:s,addr:l.bytes}}}async verifyExternalAddresses(){if(clearTimeout(this.verifyAddressTimeout),!this.isStarted())return;let t=this.components.addressManager,e=t.getObservedAddrs().filter(i=>{let c=i.toOptions();return!(_e(c.host)??!1)});if(e.length===0){this.log("no public addresses found, not requesting verification"),this.verifyAddressTimeout=setTimeout(this._verifyExternalAddresses,this.refreshInterval);return}let n=AbortSignal.timeout(this.timeout);ie(1/0,n);let o=this;try{this.log("verify multiaddrs %s",e.map(s=>s.toString()).join(", "));let i=b.encode({type:b.MessageType.DIAL,dial:{peer:{id:this.components.peerId.toBytes(),addrs:e.map(s=>s.bytes)}}}),c={},u=[],f=async s=>{let l=()=>{};try{this.log("asking %p to verify multiaddr",s.id);let a=await o.components.connectionManager.openConnection(s.id,{signal:n}),h=await a.newStream(this.protocol,{signal:n});l=()=>{h.abort(new W("verifyAddress timeout",oe))},n.addEventListener("abort",l,{once:!0});let p=await nr([i],m=>Rt(m),h,m=>ft(m),async m=>Ze(m));if(p==null){this.log("no response received from %p",a.remotePeer);return}let d=b.decode(p);if(d.type!==b.MessageType.DIAL_RESPONSE||d.dialResponse==null){this.log("invalid autonat response from %p",a.remotePeer);return}if(d.dialResponse.status===b.ResponseStatus.OK){let m=a.remoteAddr.toOptions(),g;if(m.family===4)g=m.host.split(".")[0];else if(m.family===6)g=m.host.split(":")[0];else{this.log('remote address "%s" was not IP4 or IP6?',m.host);return}if(u.includes(g)){this.log("already have response from network segment %d - %s",g,m.host);return}u.push(g)}return d.dialResponse}catch(a){this.log.error("error asking remote to verify multiaddr",a)}finally{n.removeEventListener("abort",l)}};for await(let s of tr(an(this.components.randomWalk.walk({signal:n}),l=>async()=>f(l)),{concurrency:mr}))try{if(s==null)continue;let l=s.addr==null?e[0]:lt(s.addr);if(this.log("autonat response for %a is %s",l,s.status),s.status===b.ResponseStatus.E_BAD_REQUEST||s.status===b.ResponseStatus.E_DIAL_REFUSED||s.addr==null&&e.length>1)continue;if(!e.some(h=>h.equals(l))){this.log("peer reported %a as %s but it was not in our observed address list",l,s.status);continue}let a=l.toString();if(c[a]==null&&(c[a]={success:0,failure:0}),s.status===b.ResponseStatus.OK?c[a].success++:s.status===b.ResponseStatus.E_DIAL_ERROR&&c[a].failure++,c[a].success===mr){this.log("%a is externally dialable",l),t.confirmObservedAddr(l);return}if(c[a].failure===mr){this.log("%a is not externally dialable",l),t.removeObservedAddr(l);return}}catch(l){this.log.error("could not verify external address",l)}}finally{this.verifyAddressTimeout=setTimeout(this._verifyExternalAddresses,this.refreshInterval)}}};function Gi(r={}){return t=>new re(t,r)}return Dn(qi);})();
|
|
3
3
|
return Libp2PAutonat}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libp2p/autonat",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.5",
|
|
4
4
|
"description": "Implementation of Autonat Protocol",
|
|
5
5
|
"license": "Apache-2.0 OR MIT",
|
|
6
6
|
"homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/protocol-autonat#readme",
|
|
@@ -52,10 +52,10 @@
|
|
|
52
52
|
"doc-check": "aegir doc-check"
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@libp2p/interface": "^1.
|
|
56
|
-
"@libp2p/interface-internal": "^1.3.
|
|
57
|
-
"@libp2p/peer-id": "^4.2.
|
|
58
|
-
"@libp2p/utils": "^5.4.
|
|
55
|
+
"@libp2p/interface": "^1.7.0",
|
|
56
|
+
"@libp2p/interface-internal": "^1.3.4",
|
|
57
|
+
"@libp2p/peer-id": "^4.2.4",
|
|
58
|
+
"@libp2p/utils": "^5.4.9",
|
|
59
59
|
"@multiformats/multiaddr": "^12.2.3",
|
|
60
60
|
"it-first": "^3.0.6",
|
|
61
61
|
"it-length-prefixed": "^9.0.4",
|
|
@@ -66,8 +66,8 @@
|
|
|
66
66
|
"uint8arraylist": "^2.4.8"
|
|
67
67
|
},
|
|
68
68
|
"devDependencies": {
|
|
69
|
-
"@libp2p/logger": "^4.0.
|
|
70
|
-
"@libp2p/peer-id-factory": "^4.2.
|
|
69
|
+
"@libp2p/logger": "^4.0.20",
|
|
70
|
+
"@libp2p/peer-id-factory": "^4.2.4",
|
|
71
71
|
"aegir": "^44.0.1",
|
|
72
72
|
"it-all": "^3.0.6",
|
|
73
73
|
"it-pushable": "^3.2.3",
|