@libp2p/autonat 1.1.0 → 1.1.1-151bc46fb

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.min.js CHANGED
@@ -1,3 +1,3 @@
1
1
  (function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PAutonat = factory()}(typeof self !== 'undefined' ? self : this, function () {
2
- "use strict";var Libp2PAutonat=(()=>{var xn=Object.create;var Nt=Object.defineProperty;var En=Object.getOwnPropertyDescriptor;var An=Object.getOwnPropertyNames;var In=Object.getPrototypeOf,Sn=Object.prototype.hasOwnProperty;var ur=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),N=(r,t)=>{for(var e in t)Nt(r,e,{get:t[e],enumerable:!0})},lr=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of An(t))!Sn.call(r,o)&&o!==e&&Nt(r,o,{get:()=>t[o],enumerable:!(n=En(t,o))||n.enumerable});return r};var hr=(r,t,e)=>(e=r!=null?xn(In(r)):{},lr(t||!r||!r.__esModule?Nt(e,"default",{value:r,enumerable:!0}):e,r)),vn=r=>lr(Nt({},"__esModule",{value:!0}),r);var Or=ur(vt=>{(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}(),vt.ip2long=c,vt.long2ip=u,vt.Netmask=r}).call(vt)});var rn=ur((Uc,en)=>{"use strict";function tn(r,t){for(let e in t)Object.defineProperty(r,e,{value:t[e],enumerable:!0,configurable:!0});return r}function di(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 tn(r,e)}catch{e.message=r.message,e.stack=r.stack;let o=function(){};return o.prototype=Object.create(Object.getPrototypeOf(r)),tn(new o,e)}}en.exports=di});var Mi={};N(Mi,{autoNAT:()=>Bi});var fr=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 te="ERR_TIMEOUT";var ee=(r,...t)=>{try{[...t]}catch{}};var se={};N(se,{base58btc:()=>S,base58flickr:()=>Nn});var qi=new Uint8Array(0);function dr(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 pr(r){return new TextEncoder().encode(r)}function mr(r){return new TextDecoder().decode(r)}function Ln(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,T=d.length;E!==T&&d[E]===0;)E++,m++;for(var I=(T-E)*l+1>>>0,F=new Uint8Array(I);E!==T;){for(var _=d[E],q=0,P=I-1;(_!==0||q<g)&&P!==-1;P--,q++)_+=256*F[P]>>>0,F[P]=_%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 Ft=f.repeat(m);B<I;++B)Ft+=r.charAt(F[B]);return Ft}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 T=(d.length-m)*s+1>>>0,I=new Uint8Array(T);d[m];){var F=e[d.charCodeAt(m)];if(F===255)return;for(var _=0,q=T-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 P=T-E;P!==T&&I[P]===0;)P++;for(var B=new Uint8Array(g+(T-P)),Ft=g;P!==T;)B[Ft++]=I[P++];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 Rn=Ln,Tn=Rn,wr=Tn;var re=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")}},ne=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 yr(this,t)}},oe=class{decoders;constructor(t){this.decoders=t}or(t){return yr(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 yr(r,t){return new oe({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var ie=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 re(t,e,n),this.decoder=new ne(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function nt({name:r,prefix:t,encode:e,decode:n}){return new ie(r,t,e,n)}function j({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=wr(e,r);return nt({prefix:t,name:r,encode:n,decode:i=>M(o(i))})}function Dn(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 Fn(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 nt({prefix:t,name:r,encode(o){return Fn(o,n,e)},decode(o){return Dn(o,n,e,r)}})}var S=j({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Nn=j({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var ae={};N(ae,{base10:()=>Un});var Un=j({prefix:"9",name:"base10",alphabet:"0123456789"});var ce={};N(ce,{base16:()=>_n,base16upper:()=>kn});var _n=x({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),kn=x({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var ue={};N(ue,{base2:()=>Pn});var Pn=x({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var le={};N(le,{base256emoji:()=>zn});var br=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),On=br.reduce((r,t,e)=>(r[e]=t,r),[]),Cn=br.reduce((r,t,e)=>(r[t.codePointAt(0)]=e,r),[]);function Bn(r){return r.reduce((t,e)=>(t+=On[e],t),"")}function Mn(r){let t=[];for(let e of r){let n=Cn[e.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${e}`);t.push(n)}return new Uint8Array(t)}var zn=nt({prefix:"\u{1F680}",name:"base256emoji",encode:Bn,decode:Mn});var he={};N(he,{base32:()=>z,base32hex:()=>qn,base32hexpad:()=>Hn,base32hexpadupper:()=>Xn,base32hexupper:()=>jn,base32pad:()=>$n,base32padupper:()=>Gn,base32upper:()=>Vn,base32z:()=>Kn});var z=x({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Vn=x({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),$n=x({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Gn=x({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),qn=x({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),jn=x({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Hn=x({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Xn=x({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Kn=x({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var fe={};N(fe,{base36:()=>Qn,base36upper:()=>Wn});var Qn=j({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Wn=j({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var de={};N(de,{base64:()=>Jn,base64pad:()=>Zn,base64url:()=>Yn,base64urlpad:()=>to});var Jn=x({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Zn=x({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Yn=x({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),to=x({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var pe={};N(pe,{base8:()=>eo});var eo=x({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var me={};N(me,{identity:()=>ro});var ro=nt({prefix:"\0",name:"identity",encode:r=>mr(r),decode:r=>pr(r)});var ss=new TextEncoder,as=new TextDecoder;var we={};N(we,{identity:()=>_t});var io=Ar,xr=128,so=127,ao=~so,co=Math.pow(2,31);function Ar(r,t,e){t=t||[],e=e||0;for(var n=e;r>=co;)t[e++]=r&255|xr,r/=128;for(;r&ao;)t[e++]=r&255|xr,r>>>=7;return t[e]=r|0,Ar.bytes=e-n+1,t}var uo=ge,lo=128,Er=127;function ge(r,n){var e=0,n=n||0,o=0,i=n,c,u=r.length;do{if(i>=u)throw ge.bytes=0,new RangeError("Could not decode varint");c=r[i++],e+=o<28?(c&Er)<<o:(c&Er)*Math.pow(2,o),o+=7}while(c>=lo);return ge.bytes=i-n,e}var ho=Math.pow(2,7),fo=Math.pow(2,14),po=Math.pow(2,21),mo=Math.pow(2,28),go=Math.pow(2,35),wo=Math.pow(2,42),yo=Math.pow(2,49),bo=Math.pow(2,56),xo=Math.pow(2,63),Eo=function(r){return r<ho?1:r<fo?2:r<po?3:r<mo?4:r<go?5:r<wo?6:r<yo?7:r<bo?8:r<xo?9:10},Ao={encode:io,decode:uo,encodingLength:Eo},Io=Ao,yt=Io;function bt(r,t=0){return[yt.decode(r,t),yt.decode.bytes]}function ot(r,t,e=0){return yt.encode(r,t,e),t}function it(r){return yt.encodingLength(r)}function H(r,t){let e=t.byteLength,n=it(r),o=n+it(e),i=new Uint8Array(o+e);return ot(r,i,0),ot(e,i,n),i.set(t,o),new st(r,e,t,i)}function J(r){let t=M(r),[e,n]=bt(t),[o,i]=bt(t.subarray(n)),c=t.subarray(n+i);if(c.byteLength!==o)throw new Error("Incorrect length");return new st(e,o,c,t)}function Ir(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&dr(r.bytes,e.bytes)}}var st=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=n,this.bytes=o}};var Sr=0,So="identity",vr=M;function vo(r){return H(Sr,vr(r))}var _t={code:Sr,name:So,encode:vr,digest:vo};var xe={};N(xe,{sha256:()=>kt,sha512:()=>Lo});function be({name:r,code:t,encode:e}){return new ye(r,t,e)}var ye=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 Rr(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var kt=be({name:"sha2-256",code:18,encode:Rr("SHA-256")}),Lo=be({name:"sha2-512",code:19,encode:Rr("SHA-512")});function Tr(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return To(e,Ee(r),t??S.encoder);default:return Do(e,Ee(r),t??z.encoder)}}var Dr=new WeakMap;function Ee(r){let t=Dr.get(r);if(t==null){let e=new Map;return Dr.set(r,e),e}return t}var O=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!==xt)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==Fo)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&&Ir(t.multihash,n.multihash)}toString(t){return Tr(this,t)}toJSON(){return{"/":Tr(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??Fr(n,o,i.bytes))}else if(e[No]===!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!==xt)throw new Error(`Version 0 CID must use dag-pb (code: ${xt}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=Fr(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,xt,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 st(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]=bt(t.subarray(e));return e+=h,a},o=n(),i=xt;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]=Ro(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 Ee(i).set(n,t),i}};function Ro(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 z.prefix:{let e=t??z;return[z.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 To(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 Do(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 xt=112,Fo=18;function Fr(r,t,e){let n=it(r),o=n+it(t),i=new Uint8Array(o+e.byteLength);return ot(r,i,0),ot(t,i,n),i.set(e,o),i}var No=Symbol.for("@ipld/js-cid/CID");var X={...me,...ue,...pe,...ae,...ce,...he,...fe,...se,...de,...le},Ts={...xe,...we};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}var Uo=Symbol.for("nodejs.util.inspect.custom"),Nr=Object.values(X).map(r=>r.decoder).reduce((r,t)=>r.or(t),X.identity.decoder),Ur=114,_r=36,kr=37,Et=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()})`}[fr]=!0;toString(){return this.string==null&&(this.string=S.encode(this.multihash.bytes).slice(1)),this.string}toCID(){return O.createV1(Ur,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 _o(t).equals(this);if(t?.multihash?.bytes!=null)return Y(this.multihash.bytes,t.multihash.bytes);throw new Error("not valid Id")}[Uo](){return`PeerId(${this.toString()})`}},At=class extends Et{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},It=class extends Et{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.multihash.digest}},St=class extends Et{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.multihash.digest}};function _o(r,t){if(t=t??Nr,r.charAt(0)==="1"||r.charAt(0)==="Q"){let e=J(S.decode(`z${r}`));return r.startsWith("12D")?new It({multihash:e}):r.startsWith("16U")?new St({multihash:e}):new At({multihash:e})}return Ae(Nr.decode(r))}function Ae(r){try{let t=J(r);if(t.code===_t.code){if(t.digest.length===_r)return new It({multihash:t});if(t.digest.length===kr)return new St({multihash:t})}if(t.code===kt.code)return new At({multihash:t})}catch{return ko(O.decode(r))}throw new Error("Supplied PeerID CID is invalid")}function ko(r){if(r==null||r.multihash==null||r.version==null||r.version===1&&r.code!==Ur)throw new Error("Supplied PeerID CID is invalid");let t=r.multihash;if(t.code===kt.code)return new At({multihash:r.multihash});if(t.code===_t.code){if(t.digest.length===_r)return new It({multihash:r.multihash});if(t.digest.length===kr)return new St({multihash:r.multihash})}throw new Error("Supplied PeerID CID is invalid")}var Pt=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 Pr=45,Po=15,at=new Pt;function Ie(r){if(!(r.length>Po))return at.new(r).parseWith(()=>at.readIPv4Addr())}function Se(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>Pr))return at.new(r).parseWith(()=>at.readIPv6Addr())}function Ot(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>Pr))return at.new(r).parseWith(()=>at.readIPAddr())}function Ct(r){return!!Ie(r)}function Bt(r){return!!Se(r)}function Mt(r){return!!Ot(r)}var Cr=hr(Or(),1),Oo=["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"],Co=Oo.map(r=>new Cr.Netmask(r));function Bo(r){for(let t of Co)if(t.contains(r))return!0;return!1}function Mo(r){return/^::$/.test(r)||/^::1$/.test(r)||/^::f{4}:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(r)||/^::f{4}:0.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.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 ve(r){return Ct(r)?Bo(r):Bt(r)?Mo(r):void 0}function V(r=0){return new Uint8Array(r)}function v(r=0){return new Uint8Array(r)}function Mr(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var Br=Mr("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Le=Mr("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=v(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),zo={utf8:Br,"utf-8":Br,hex:X.base16,latin1:Le,ascii:Le,binary:Le,...X},zt=zo;function D(r,t="utf8"){let e=zt[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var Vo=Math.pow(2,7),$o=Math.pow(2,14),Go=Math.pow(2,21),Re=Math.pow(2,28),Te=Math.pow(2,35),De=Math.pow(2,42),Fe=Math.pow(2,49),y=128,L=127;function A(r){if(r<Vo)return 1;if(r<$o)return 2;if(r<Go)return 3;if(r<Re)return 4;if(r<Te)return 5;if(r<De)return 6;if(r<Fe)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Ne(r,t,e=0){switch(A(r)){case 8:t[e++]=r&255|y,r/=128;case 7:t[e++]=r&255|y,r/=128;case 6:t[e++]=r&255|y,r/=128;case 5:t[e++]=r&255|y,r/=128;case 4:t[e++]=r&255|y,r>>>=7;case 3:t[e++]=r&255|y,r>>>=7;case 2:t[e++]=r&255|y,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function qo(r,t,e=0){switch(A(r)){case 8:t.set(e++,r&255|y),r/=128;case 7:t.set(e++,r&255|y),r/=128;case 6:t.set(e++,r&255|y),r/=128;case 5:t.set(e++,r&255|y),r/=128;case 4:t.set(e++,r&255|y),r>>>=7;case 3:t.set(e++,r&255|y),r>>>=7;case 2:t.set(e++,r&255|y),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function Ue(r,t){let e=r[t],n=0;if(n+=e&L,e<y||(e=r[t+1],n+=(e&L)<<7,e<y)||(e=r[t+2],n+=(e&L)<<14,e<y)||(e=r[t+3],n+=(e&L)<<21,e<y)||(e=r[t+4],n+=(e&L)*Re,e<y)||(e=r[t+5],n+=(e&L)*Te,e<y)||(e=r[t+6],n+=(e&L)*De,e<y)||(e=r[t+7],n+=(e&L)*Fe,e<y))return n;throw new RangeError("Could not decode varint")}function jo(r,t){let e=r.get(t),n=0;if(n+=e&L,e<y||(e=r.get(t+1),n+=(e&L)<<7,e<y)||(e=r.get(t+2),n+=(e&L)<<14,e<y)||(e=r.get(t+3),n+=(e&L)<<21,e<y)||(e=r.get(t+4),n+=(e&L)*Re,e<y)||(e=r.get(t+5),n+=(e&L)*Te,e<y)||(e=r.get(t+6),n+=(e&L)*De,e<y)||(e=r.get(t+7),n+=(e&L)*Fe,e<y))return n;throw new RangeError("Could not decode varint")}function K(r,t,e=0){return t==null&&(t=v(A(r))),t instanceof Uint8Array?Ne(r,t,e):qo(r,t,e)}function $(r,t=0){return r instanceof Uint8Array?Ue(r,t):jo(r,t)}function k(r,t){t==null&&(t=r.reduce((o,i)=>o+i.length,0));let e=v(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return e}var ha=parseInt("0xFFFF",16),fa=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function Lt(r,t="utf8"){let e=zt[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}var $r=Ct,Wo=Bt,_e=function(r){let t=0;if(r=r.toString().trim(),$r(r)){let e=new Uint8Array(t+4);return r.split(/\./g).forEach(n=>{e[t++]=parseInt(n,10)&255}),e}if(Wo(r)){let e=r.split(":",8),n;for(n=0;n<e.length;n++){let i=$r(e[n]),c;i&&(c=_e(e[n]),e[n]=D(c.slice(0,2),"base16")),c!=null&&++n<8&&e.splice(n,0,D(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")},Gr=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 ct={},ke={},Zo=[[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"]];Zo.forEach(r=>{let t=Yo(...r);ke[t.code]=t,ct[t.name]=t});function Yo(r,t,e,n,o){return{code:r,size:t,name:e,resolvable:!!n,path:!!o}}function b(r){if(typeof r=="number"){if(ke[r]!=null)return ke[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(ct[r]!=null)return ct[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var Qa=b("ip4"),Wa=b("ip6"),Ja=b("ipcidr");function Be(r,t){switch(b(r).code){case 4:case 41:return ei(t);case 42:return Ce(t);case 6:case 273:case 33:case 132:return Hr(t).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return Ce(t);case 421:return ii(t);case 444:return jr(t);case 445:return jr(t);case 466:return oi(t);case 481:return globalThis.encodeURIComponent(Ce(t));default:return D(t,"base16")}}function Me(r,t){switch(b(r).code){case 4:return qr(t);case 41:return qr(t);case 42:return Oe(t);case 6:case 273:case 33:case 132:return ze(parseInt(t,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return Oe(t);case 421:return ri(t);case 444:return si(t);case 445:return ai(t);case 466:return ni(t);case 481:return Oe(globalThis.decodeURIComponent(t));default:return Lt(t,"base16")}}var Pe=Object.values(X).map(r=>r.decoder),ti=function(){let r=Pe[0].or(Pe[1]);return Pe.slice(2).forEach(t=>r=r.or(t)),r}();function qr(r){if(!Mt(r))throw new Error("invalid ip address");return _e(r)}function ei(r){let t=Gr(r,0,r.length);if(t==null)throw new Error("ipBuff is required");if(!Mt(t))throw new Error("invalid ip address");return t}function ze(r){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,r),new Uint8Array(t)}function Hr(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function Oe(r){let t=Lt(r),e=Uint8Array.from(K(t.length));return k([e,t],e.length+t.length)}function Ce(r){let t=$(r);if(r=r.slice(A(t)),r.length!==t)throw new Error("inconsistent lengths");return D(r)}function ri(r){let t;r[0]==="Q"||r[0]==="1"?t=J(S.decode(`z${r}`)).bytes:t=O.parse(r).multihash.bytes;let e=Uint8Array.from(K(t.length));return k([e,t],e.length+t.length)}function ni(r){let t=ti.decode(r),e=Uint8Array.from(K(t.length));return k([e,t],e.length+t.length)}function oi(r){let t=$(r),e=r.slice(A(t));if(e.length!==t)throw new Error("inconsistent lengths");return"u"+D(e,"base64url")}function ii(r){let t=$(r),e=r.slice(A(t));if(e.length!==t)throw new Error("inconsistent lengths");return D(e,"base58btc")}function si(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=z.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=ze(n);return k([e,o],e.length+o.length)}function ai(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=z.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=ze(n);return k([e,o],e.length+o.length)}function jr(r){let t=r.slice(0,r.length-2),e=r.slice(r.length-2),n=D(t,"base32"),o=Hr(e);return`${n}:${o}`}function Xr(r){r=Ve(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=b(c);if(u.size===0){t.push([u.code]),e.push([u.code]);continue}if(i++,i>=o.length)throw Qr("invalid address: "+r);if(u.path===!0){n=Ve(o.slice(i).join("/")),t.push([u.code,Me(u.code,n)]),e.push([u.code,n]);break}let f=Me(u.code,o[i]);t.push([u.code,f]),e.push([u.code,Be(u.code,f)])}return{string:Kr(e),bytes:Ge(t),tuples:t,stringTuples:e,path:n}}function $e(r){let t=[],e=[],n=null,o=0;for(;o<r.length;){let i=$(r,o),c=A(i),u=b(i),f=ci(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 Qr("Invalid address Uint8Array: "+D(r,"base16"));t.push([i,s]);let l=Be(i,s);if(e.push([i,l]),u.path===!0){n=l;break}}return{bytes:Uint8Array.from(r),string:Kr(e),tuples:t,stringTuples:e,path:n}}function Kr(r){let t=[];return r.map(e=>{let n=b(e[0]);return t.push(n.name),e.length>1&&e[1]!=null&&t.push(e[1]),null}),Ve(t.join("/"))}function Ge(r){return k(r.map(t=>{let e=b(t[0]),n=Uint8Array.from(K(e.code));return t.length>1&&t[1]!=null&&(n=k([n,t[1]])),n}))}function ci(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 Ve(r){return"/"+r.trim().split("/").filter(t=>t).join("/")}function Qr(r){return new Error("Error parsing address: "+r)}var ui=Symbol.for("nodejs.util.inspect.custom"),qe=Symbol.for("@multiformats/js-multiaddr/multiaddr"),li=[b("dns").code,b("dns4").code,b("dns6").code,b("dnsaddr").code],$t=class r{bytes;#e;#t;#r;#n;[qe]=!0;constructor(t){t==null&&(t="");let e;if(t instanceof Uint8Array)e=$e(t);else if(typeof t=="string"){if(t.length>0&&t.charAt(0)!=="/")throw new Error(`multiaddr "${t}" must start with a "/"`);e=Xr(t)}else if(Jr(t))e=$e(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=b("tcp"),u=b("udp"),f=b("ip4"),s=b("ip6"),l=b("dns6"),a=b("ip6zone");for(let[p,d]of this.stringTuples())p===a.code&&(i=`%${d??""}`),li.includes(p)&&(e=c.name,o=443,n=`${d??""}${i}`,t=p===l.code?6:4),(p===c.code||p===u.code)&&(e=b(p).name,o=parseInt(d??"")),(p===f.code||p===s.code)&&(e=b(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({},b(t)))}protoCodes(){return this.#t.map(([t])=>t)}protoNames(){return this.#t.map(([t])=>b(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(Ge(e.slice(0,n)));return this}getPeerId(){try{let t=[];this.stringTuples().forEach(([n,o])=>{n===ct.p2p.code&&t.push([n,o]),n===ct["p2p-circuit"].code&&(t=[])});let e=t.pop();if(e?.[1]!=null){let n=e[1];return n[0]==="Q"||n[0]==="1"?D(S.decode(`z${n}`),"base58btc"):D(O.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=Wr.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=>ut(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)}[ui](){return`Multiaddr(${this.#e})`}};var Wr=new Map;function Jr(r){return!!r?.[qe]}function ut(r){return new $t(r)}function hi(r){return r[Symbol.asyncIterator]!=null}function fi(r){if(hi(r))return(async()=>{for await(let t of r)return t})();for(let t of r)return t}var je=fi;var Yr=Symbol.for("@achingbrain/uint8arraylist");function Zr(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?.[Yr]}var lt=class r{bufs;length;[Yr]=!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=Zr(this.bufs,t);return e.buf[e.index]}set(t,e){let n=Zr(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=v(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=V(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=V(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=V(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=v(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=V(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=V(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=V(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=V(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=V(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=v(t);return K(r,e),jt.bytes=t,e};jt.bytes=0;function Rt(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)}()}Rt.single=(r,t)=>{t=t??{};let e=t.lengthEncoder??jt;return new lt(e(r.byteLength),r)};var ht=hr(rn(),1);var pi=8,mi=1024*1024*4,tt;(function(r){r[r.LENGTH=0]="LENGTH",r[r.DATA=1]="DATA"})(tt||(tt={}));var He=r=>{let t=$(r);return He.bytes=A(t),t};He.bytes=0;function ft(r,t){let e=new lt,n=tt.LENGTH,o=-1,i=t?.lengthDecoder??He,c=t?.maxLengthLength??pi,u=t?.maxDataLength??mi;function*f(){for(;e.byteLength>0;){if(n===tt.LENGTH)try{if(o=i(e),o<0)throw(0,ht.default)(new Error("invalid message length"),"ERR_INVALID_MSG_LENGTH");if(o>u)throw(0,ht.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=tt.DATA}catch(s){if(s instanceof RangeError){if(e.byteLength>c)throw(0,ht.default)(new Error("message length length too long"),"ERR_MSG_LENGTH_TOO_LONG");break}throw s}if(n===tt.DATA){if(e.byteLength<o)break;let s=e.sublist(0,o);e.consume(o),t?.onData!=null&&t.onData(s),yield s,n=tt.LENGTH}}}return qt(r)?async function*(){for await(let s of r)e.append(s),yield*f();if(e.byteLength>0)throw(0,ht.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,ht.default)(new Error("unexpected end of input"),"ERR_UNEXPECTED_EOF")}()}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 wi(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 nn=wi;function yi(r){return r[Symbol.asyncIterator]!=null}function bi(r,t){let e=0;if(yi(r))return async function*(){for await(let f of r)yield t(f,e++)}();let n=nn(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 on=bi;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*Xe(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}},dt=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 Ke=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 xi(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 xi(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=T=>{i=null,n.push(T);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 T,I;E!=null&&(T=new Promise((F,_)=>{I=()=>{_(new Ke)},E.addEventListener("abort",I)}));try{await Promise.race([u.promise,T])}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 Ei(r){return r[Symbol.asyncIterator]!=null}function Ai(...r){let t=[];for(let e of r)Ei(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 sn=Ai;function We(r,...t){if(r==null)throw new Error("Empty pipeline");if(Qe(r)){let n=r;r=()=>n.source}else if(cn(r)||an(r)){let n=r;r=()=>n}let e=[r,...t];if(e.length>1&&Qe(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++)Qe(e[n])&&(e[n]=Si(e[n]));return Ii(...e)}var Ii=(...r)=>{let t;for(;r.length>0;)t=r.shift()(t);return t},an=r=>r?.[Symbol.asyncIterator]!=null,cn=r=>r?.[Symbol.iterator]!=null,Qe=r=>r==null?!1:r.sink!=null&&r.source!=null,Si=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(an(i))o=async function*(){yield*i,n.end()};else if(cn(i))o=function*(){yield*i,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return sn(n,o())}return r.source};var un="libp2p",ln="autonat",hn="1.0.0";var Je=new Float32Array([-0]),Q=new Uint8Array(Je.buffer);function fn(r,t,e){Je[0]=r,t[e]=Q[0],t[e+1]=Q[1],t[e+2]=Q[2],t[e+3]=Q[3]}function dn(r,t){return Q[0]=r[t],Q[1]=r[t+1],Q[2]=r[t+2],Q[3]=r[t+3],Je[0]}var Ze=new Float64Array([-0]),R=new Uint8Array(Ze.buffer);function pn(r,t,e){Ze[0]=r,t[e]=R[0],t[e+1]=R[1],t[e+2]=R[2],t[e+3]=R[3],t[e+4]=R[4],t[e+5]=R[5],t[e+6]=R[6],t[e+7]=R[7]}function mn(r,t){return R[0]=r[t],R[1]=r[t+1],R[2]=r[t+2],R[3]=r[t+3],R[4]=r[t+4],R[5]=r[t+5],R[6]=r[t+6],R[7]=r[t+7],Ze[0]}var vi=BigInt(Number.MAX_SAFE_INTEGER),Li=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 et;if(t<vi&&t>Li)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>gn&&(o=0n,++n>gn&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(t){if(t===0)return et;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):et}},et=new U(0,0);et.toBigInt=function(){return 0n};et.zzEncode=et.zzDecode=function(){return this};et.length=function(){return 1};var gn=4294967296n;function wn(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 yn(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 Ye(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 tr=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=dn(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw C(this,4);let t=mn(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 yn(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=Ue(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 er(r){return new tr(r instanceof Uint8Array?r:r.subarray())}function pt(r,t,e){let n=er(r);return t.decode(n,void 0,e)}function rr(r){let t=r??8192,e=t>>>1,n,o=t;return function(c){if(c<1||c>e)return v(c);o+c>t&&(n=v(t),o=0);let u=n.subarray(o,o+=c);return o&7&&(o=(o|7)+1),u}}var rt=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function nr(){}var ir=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Ri=rr();function Ti(r){return globalThis.Buffer!=null?v(r):Ri(r)}var Dt=class{len;head;tail;states;constructor(){this.len=0,this.head=new rt(nr,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new rt(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new sr((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(Ne,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(or,1,t?1:0)}fixed32(t){return this._push(Tt,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=U.fromBigInt(t);return this._push(Tt,4,e.lo)._push(Tt,4,e.hi)}fixed64Number(t){let e=U.fromNumber(t);return this._push(Tt,4,e.lo)._push(Tt,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(fn,4,t)}double(t){return this._push(pn,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(or,1,0):this.uint32(e)._push(Fi,e,t)}string(t){let e=wn(t);return e!==0?this.uint32(e)._push(Ye,e,t):this._push(or,1,0)}fork(){return this.states=new ir(this),this.head=this.tail=new rt(nr,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 rt(nr,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=Ti(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function or(r,t,e){t[e]=r&255}function Di(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var sr=class extends rt{next;constructor(t,e){super(Di,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 Tt(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 Fi(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(Dt.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(Ni,t,r),this},Dt.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(Ui,t,r),this});function Ni(r,t,e){t.set(r,e)}function Ui(r,t,e){r.length<40?Ye(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(Lt(r),e)}function ar(){return new Dt}function mt(r,t){let e=ar();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 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",gt.VARINT,e,n)}function wt(r,t){return Jt("message",gt.LENGTH_DELIMITED,r,t)}var w;(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=wt((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=wt((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=wt((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=wt((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())})(w||(w={}));var cr=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??un}/${ln}/${hn}`,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",te))};e.addEventListener("abort",n,{once:!0}),ee(1/0,e);try{let o=this;await We(t.stream,i=>ft(i),async function*(i){let c=await je(i);if(c==null){o.log("no message received"),yield w.encode({type:w.MessageType.DIAL_RESPONSE,dialResponse:{status:w.ResponseStatus.E_BAD_REQUEST,statusText:"No message was sent"}});return}let u;try{u=w.decode(c)}catch(f){o.log.error("could not decode message",f),yield w.encode({type:w.MessageType.DIAL_RESPONSE,dialResponse:{status:w.ResponseStatus.E_BAD_REQUEST,statusText:"Could not decode message"}});return}yield w.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:w.MessageType.DIAL_RESPONSE,dialResponse:{status:w.ResponseStatus.E_BAD_REQUEST,statusText:"No Dial message found in message"}};let c,u=i.peer;if(u==null||u.id==null)return this.log.error("PeerId missing from message"),{type:w.MessageType.DIAL_RESPONSE,dialResponse:{status:w.ResponseStatus.E_BAD_REQUEST,statusText:"missing peer info"}};try{c=Ae(u.id)}catch(a){return this.log.error("invalid PeerId",a),{type:w.MessageType.DIAL_RESPONSE,dialResponse:{status:w.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:w.MessageType.DIAL_RESPONSE,dialResponse:{status:w.ResponseStatus.E_BAD_REQUEST,statusText:"peer id mismatch"}};let f=u.addrs.map(a=>ut(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=!(ve(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:w.MessageType.DIAL_RESPONSE,dialResponse:{status:w.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:w.MessageType.DIAL_RESPONSE,dialResponse:{status:w.ResponseStatus.OK,addr:h.remoteAddr.decapsulateCode(b("p2p").code).bytes}}}catch(p){this.log("could not dial %p",c,p),s=p.message}finally{h!=null&&await h.close()}}return{type:w.MessageType.DIAL_RESPONSE,dialResponse:{status:w.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!(ve(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);ee(1/0,n);let o=this;try{this.log("verify multiaddrs %s",e.map(s=>s.toString()).join(", "));let i=w.encode({type:w.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",te))},n.addEventListener("abort",l,{once:!0});let p=await We([i],m=>Rt(m),h,m=>ft(m),async m=>je(m));if(p==null){this.log("no response received from %p",a.remotePeer);return}let d=w.decode(p);if(d.type!==w.MessageType.DIAL_RESPONSE||d.dialResponse==null){this.log("invalid autonat response from %p",a.remotePeer);return}if(d.dialResponse.status===w.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 Xe(on(this.components.randomWalk.walk({signal:n}),l=>async()=>f(l)),{concurrency:cr}))try{if(s==null)continue;let l=s.addr==null?e[0]:ut(s.addr);if(this.log("autonat response for %a is %s",l,s.status),s.status===w.ResponseStatus.E_BAD_REQUEST||s.status===w.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===w.ResponseStatus.OK?c[a].success++:s.status===w.ResponseStatus.E_DIAL_ERROR&&c[a].failure++,c[a].success===cr){this.log("%a is externally dialable",l),t.confirmObservedAddr(l);return}if(c[a].failure===cr){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 Bi(r={}){return t=>new Yt(t,r)}return vn(Mi);})();
2
+ "use strict";var Libp2PAutonat=(()=>{var In=Object.create;var Ut=Object.defineProperty;var Sn=Object.getOwnPropertyDescriptor;var vn=Object.getOwnPropertyNames;var Ln=Object.getPrototypeOf,Rn=Object.prototype.hasOwnProperty;var fr=(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})},dr=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of vn(t))!Rn.call(r,o)&&o!==e&&Ut(r,o,{get:()=>t[o],enumerable:!(n=Sn(t,o))||n.enumerable});return r};var pr=(r,t,e)=>(e=r!=null?In(Ln(r)):{},dr(t||!r||!r.__esModule?Ut(e,"default",{value:r,enumerable:!0}):e,r)),Tn=r=>dr(Ut({},"__esModule",{value:!0}),r);var zr=fr(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 sn=fr((Oc,on)=>{"use strict";function nn(r,t){for(let e in t)Object.defineProperty(r,e,{value:t[e],enumerable:!0,configurable:!0});return r}function mi(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 nn(r,e)}catch{e.message=r.message,e.stack=r.stack;let o=function(){};return o.prototype=Object.create(Object.getPrototypeOf(r)),nn(new o,e)}}on.exports=mi});var zi={};N(zi,{autoNAT:()=>Vi});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:()=>Pn});var Hi=new Uint8Array(0);function mr(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 gr(r){return new TextEncoder().encode(r)}function yr(r){return new TextDecoder().decode(r)}function Dn(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 Fn=Dn,Nn=Fn,br=Nn;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 xr(this,t)}},ie=class{decoders;constructor(t){this.decoders=t}or(t){return xr(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 xr(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}=br(e,r);return ot({prefix:t,name:r,encode:n,decode:i=>M(o(i))})}function Un(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 _n(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 _n(o,n,e)},decode(o){return Un(o,n,e,r)}})}var S=j({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Pn=j({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var ce={};N(ce,{base10:()=>kn});var kn=j({prefix:"9",name:"base10",alphabet:"0123456789"});var ue={};N(ue,{base16:()=>On,base16upper:()=>Cn});var On=x({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Cn=x({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var le={};N(le,{base2:()=>Bn});var Bn=x({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var he={};N(he,{base256emoji:()=>Gn});var Er=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}"),Mn=Er.reduce((r,t,e)=>(r[e]=t,r),[]),Vn=Er.reduce((r,t,e)=>(r[t.codePointAt(0)]=e,r),[]);function zn(r){return r.reduce((t,e)=>(t+=Mn[e],t),"")}function $n(r){let t=[];for(let e of r){let n=Vn[e.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${e}`);t.push(n)}return new Uint8Array(t)}var Gn=ot({prefix:"\u{1F680}",name:"base256emoji",encode:zn,decode:$n});var fe={};N(fe,{base32:()=>V,base32hex:()=>Xn,base32hexpad:()=>Qn,base32hexpadupper:()=>Wn,base32hexupper:()=>Kn,base32pad:()=>jn,base32padupper:()=>Hn,base32upper:()=>qn,base32z:()=>Jn});var V=x({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),qn=x({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),jn=x({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Hn=x({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Xn=x({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Kn=x({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Qn=x({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Wn=x({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Jn=x({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var de={};N(de,{base36:()=>Zn,base36upper:()=>Yn});var Zn=j({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Yn=j({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var pe={};N(pe,{base64:()=>to,base64pad:()=>eo,base64url:()=>ro,base64urlpad:()=>no});var to=x({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),eo=x({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),ro=x({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),no=x({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var me={};N(me,{base8:()=>oo});var oo=x({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var ge={};N(ge,{identity:()=>io});var io=ot({prefix:"\0",name:"identity",encode:r=>yr(r),decode:r=>gr(r)});var cs=new TextEncoder,us=new TextDecoder;var we={};N(we,{identity:()=>Et});var co=Sr,Ar=128,uo=127,lo=~uo,ho=Math.pow(2,31);function Sr(r,t,e){t=t||[],e=e||0;for(var n=e;r>=ho;)t[e++]=r&255|Ar,r/=128;for(;r&lo;)t[e++]=r&255|Ar,r>>>=7;return t[e]=r|0,Sr.bytes=e-n+1,t}var fo=ye,po=128,Ir=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&Ir)<<o:(c&Ir)*Math.pow(2,o),o+=7}while(c>=po);return ye.bytes=i-n,e}var mo=Math.pow(2,7),go=Math.pow(2,14),yo=Math.pow(2,21),wo=Math.pow(2,28),bo=Math.pow(2,35),xo=Math.pow(2,42),Eo=Math.pow(2,49),Ao=Math.pow(2,56),Io=Math.pow(2,63),So=function(r){return r<mo?1:r<go?2:r<yo?3:r<wo?4:r<bo?5:r<xo?6:r<Eo?7:r<Ao?8:r<Io?9:10},vo={encode:co,decode:fo,encodingLength:So},Lo=vo,bt=Lo;function xt(r,t=0){return[bt.decode(r,t),bt.decode.bytes]}function it(r,t,e=0){return bt.encode(r,t,e),t}function st(r){return bt.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 vr(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&mr(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 Lr=0,Ro="identity",Rr=M;function To(r){return H(Lr,Rr(r))}var Et={code:Lr,name:Ro,encode:Rr,digest:To};var Ee={};N(Ee,{sha256:()=>Pt,sha512:()=>Do});function xe({name:r,code:t,encode:e}){return new be(r,t,e)}var be=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 Dr(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var Pt=xe({name:"sha2-256",code:18,encode:Dr("SHA-256")}),Do=xe({name:"sha2-512",code:19,encode:Dr("SHA-512")});function Fr(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return No(e,Ae(r),t??S.encoder);default:return Uo(e,Ae(r),t??V.encoder)}}var Nr=new WeakMap;function Ae(r){let t=Nr.get(r);if(t==null){let e=new Map;return Nr.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!==_o)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&&vr(t.multihash,n.multihash)}toString(t){return Fr(this,t)}toJSON(){return{"/":Fr(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??Ur(n,o,i.bytes))}else if(e[Po]===!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=Ur(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]=Fo(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 Fo(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 No(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 Uo(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,_o=18;function Ur(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 Po=Symbol.for("@ipld/js-cid/CID");var X={...ge,...le,...me,...ce,...ue,...fe,...de,...ae,...pe,...he},Fs={...Ee,...we};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 Pr(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var _r=Pr("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Ie=Pr("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}),ko={utf8:_r,"utf-8":_r,hex:X.base16,latin1:Ie,ascii:Ie,binary:Ie,...X},kt=ko;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 Or=Symbol.for("nodejs.util.inspect.custom"),kr=Object.values(X).map(r=>r.decoder).reduce((r,t)=>r.or(t),X.identity.decoder),Cr=114,Br=36,Mr=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(Cr,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 Oo(t).equals(this);if(t?.multihash?.bytes!=null)return Y(this.multihash.bytes,t.multihash.bytes);throw new Error("not valid Id")}[Or](){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))}[Or](){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 Oo(r,t){if(t=t??kr,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(kr.decode(r))}function Le(r){try{let t=J(r);if(t.code===Et.code){if(t.digest.length===Br)return new vt({multihash:t});if(t.digest.length===Mr)return new Lt({multihash:t})}if(t.code===Pt.code)return new St({multihash:t})}catch{return Co(P.decode(r))}throw new Error("Supplied PeerID CID is invalid")}function Co(r){if(r==null||r.multihash==null||r.version==null||r.version===1&&r.code!==Cr&&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===Br)return new vt({multihash:r.multihash});if(t.digest.length===Mr)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 Vr=45,Bo=15,ct=new Ot;function Re(r){if(!(r.length>Bo))return ct.new(r).parseWith(()=>ct.readIPv4Addr())}function Te(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>Vr))return ct.new(r).parseWith(()=>ct.readIPv6Addr())}function Ct(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>Vr))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 $r=pr(zr(),1),Mo=["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"],Vo=Mo.map(r=>new $r.Netmask(r));function zo(r){for(let t of Vo)if(t.contains(r))return!0;return!1}function $o(r){return/^::$/.test(r)||/^::1$/.test(r)||/^::f{4}:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(r)||/^::f{4}:0.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.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 De(r){return Bt(r)?zo(r):Mt(r)?$o(r):void 0}var Go=Math.pow(2,7),qo=Math.pow(2,14),jo=Math.pow(2,21),Fe=Math.pow(2,28),Ne=Math.pow(2,35),Ue=Math.pow(2,42),_e=Math.pow(2,49),w=128,R=127;function A(r){if(r<Go)return 1;if(r<qo)return 2;if(r<jo)return 3;if(r<Fe)return 4;if(r<Ne)return 5;if(r<Ue)return 6;if(r<_e)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Pe(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 Ho(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 ke(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)*Fe,e<w)||(e=r[t+5],n+=(e&R)*Ne,e<w)||(e=r[t+6],n+=(e&R)*Ue,e<w)||(e=r[t+7],n+=(e&R)*_e,e<w))return n;throw new RangeError("Could not decode varint")}function Xo(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)*Fe,e<w)||(e=r.get(t+5),n+=(e&R)*Ne,e<w)||(e=r.get(t+6),n+=(e&R)*Ue,e<w)||(e=r.get(t+7),n+=(e&R)*_e,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?Pe(r,t,e):Ho(r,t,e)}function $(r,t=0){return r instanceof Uint8Array?ke(r,t):Xo(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 ya=parseInt("0xFFFF",16),wa=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);var jr=Bt,Zo=Mt,Oe=function(r){let t=0;if(r=r.toString().trim(),jr(r)){let e=new Uint8Array(t+4);return r.split(/\./g).forEach(n=>{e[t++]=parseInt(n,10)&255}),e}if(Zo(r)){let e=r.split(":",8),n;for(n=0;n<e.length;n++){let i=jr(e[n]),c;i&&(c=Oe(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")},Hr=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={},Ce={},ti=[[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"]];ti.forEach(r=>{let t=ei(...r);Ce[t.code]=t,ut[t.name]=t});function ei(r,t,e,n,o){return{code:r,size:t,name:e,resolvable:!!n,path:!!o}}function b(r){if(typeof r=="number"){if(Ce[r]!=null)return Ce[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 Ya=b("ip4"),tc=b("ip6"),ec=b("ipcidr");function ze(r,t){switch(b(r).code){case 4:case 41:return ni(t);case 42:return Ve(t);case 6:case 273:case 33:case 132:return Qr(t).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return Ve(t);case 421:return ai(t);case 444:return Kr(t);case 445:return Kr(t);case 466:return si(t);case 481:return globalThis.encodeURIComponent(Ve(t));default:return v(t,"base16")}}function $e(r,t){switch(b(r).code){case 4:return Xr(t);case 41:return Xr(t);case 42:return Me(t);case 6:case 273:case 33:case 132:return Ge(parseInt(t,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return Me(t);case 421:return oi(t);case 444:return ci(t);case 445:return ui(t);case 466:return ii(t);case 481:return Me(globalThis.decodeURIComponent(t));default:return tt(t,"base16")}}var Be=Object.values(X).map(r=>r.decoder),ri=function(){let r=Be[0].or(Be[1]);return Be.slice(2).forEach(t=>r=r.or(t)),r}();function Xr(r){if(!Vt(r))throw new Error("invalid ip address");return Oe(r)}function ni(r){let t=Hr(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 Ge(r){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,r),new Uint8Array(t)}function Qr(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function Me(r){let t=tt(r),e=Uint8Array.from(K(t.length));return k([e,t],e.length+t.length)}function Ve(r){let t=$(r);if(r=r.slice(A(t)),r.length!==t)throw new Error("inconsistent lengths");return v(r)}function oi(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 ii(r){let t=ri.decode(r),e=Uint8Array.from(K(t.length));return k([e,t],e.length+t.length)}function si(r){let t=$(r),e=r.slice(A(t));if(e.length!==t)throw new Error("inconsistent lengths");return"u"+v(e,"base64url")}function ai(r){let t=$(r),e=r.slice(A(t));if(e.length!==t)throw new Error("inconsistent lengths");return v(e,"base58btc")}function ci(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=Ge(n);return k([e,o],e.length+o.length)}function ui(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=Ge(n);return k([e,o],e.length+o.length)}function Kr(r){let t=r.slice(0,r.length-2),e=r.slice(r.length-2),n=v(t,"base32"),o=Qr(e);return`${n}:${o}`}function Wr(r){r=qe(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=b(c);if(u.size===0){t.push([u.code]),e.push([u.code]);continue}if(i++,i>=o.length)throw Zr("invalid address: "+r);if(u.path===!0){n=qe(o.slice(i).join("/")),t.push([u.code,$e(u.code,n)]),e.push([u.code,n]);break}let f=$e(u.code,o[i]);t.push([u.code,f]),e.push([u.code,ze(u.code,f)])}return{string:Jr(e),bytes:He(t),tuples:t,stringTuples:e,path:n}}function je(r){let t=[],e=[],n=null,o=0;for(;o<r.length;){let i=$(r,o),c=A(i),u=b(i),f=li(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 Zr("Invalid address Uint8Array: "+v(r,"base16"));t.push([i,s]);let l=ze(i,s);if(e.push([i,l]),u.path===!0){n=l;break}}return{bytes:Uint8Array.from(r),string:Jr(e),tuples:t,stringTuples:e,path:n}}function Jr(r){let t=[];return r.map(e=>{let n=b(e[0]);return t.push(n.name),e.length>1&&e[1]!=null&&t.push(e[1]),null}),qe(t.join("/"))}function He(r){return k(r.map(t=>{let e=b(t[0]),n=Uint8Array.from(K(e.code));return t.length>1&&t[1]!=null&&(n=k([n,t[1]])),n}))}function li(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 qe(r){return"/"+r.trim().split("/").filter(t=>t).join("/")}function Zr(r){return new Error("Error parsing address: "+r)}var hi=Symbol.for("nodejs.util.inspect.custom"),Xe=Symbol.for("@multiformats/js-multiaddr/multiaddr"),fi=[b("dns").code,b("dns4").code,b("dns6").code,b("dnsaddr").code],$t=class r{bytes;#e;#t;#r;#n;[Xe]=!0;constructor(t){t==null&&(t="");let e;if(t instanceof Uint8Array)e=je(t);else if(typeof t=="string"){if(t.length>0&&t.charAt(0)!=="/")throw new Error(`multiaddr "${t}" must start with a "/"`);e=Wr(t)}else if(tn(t))e=je(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=b("tcp"),u=b("udp"),f=b("ip4"),s=b("ip6"),l=b("dns6"),a=b("ip6zone");for(let[p,d]of this.stringTuples())p===a.code&&(i=`%${d??""}`),fi.includes(p)&&(e=c.name,o=443,n=`${d??""}${i}`,t=p===l.code?6:4),(p===c.code||p===u.code)&&(e=b(p).name,o=parseInt(d??"")),(p===f.code||p===s.code)&&(e=b(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({},b(t)))}protoCodes(){return this.#t.map(([t])=>t)}protoNames(){return this.#t.map(([t])=>b(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(He(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=Yr.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)}[hi](){return`Multiaddr(${this.#e})`}};var Yr=new Map;function tn(r){return!!r?.[Xe]}function lt(r){return new $t(r)}function di(r){return r[Symbol.asyncIterator]!=null}function pi(r){if(di(r))return(async()=>{for await(let t of r)return t})();for(let t of r)return t}var Ke=pi;var rn=Symbol.for("@achingbrain/uint8arraylist");function en(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?.[rn]}var ht=class r{bufs;length;[rn]=!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=en(this.bufs,t);return e.buf[e.index]}set(t,e){let n=en(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=pr(sn(),1);var gi=8,yi=1024*1024*4,et;(function(r){r[r.LENGTH=0]="LENGTH",r[r.DATA=1]="DATA"})(et||(et={}));var Qe=r=>{let t=$(r);return Qe.bytes=A(t),t};Qe.bytes=0;function dt(r,t){let e=new ht,n=et.LENGTH,o=-1,i=t?.lengthDecoder??Qe,c=t?.maxLengthLength??gi,u=t?.maxDataLength??yi;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 bi(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 an=bi;function xi(r){return r[Symbol.asyncIterator]!=null}function Ei(r,t){let e=0;if(xi(r))return async function*(){for await(let f of r)yield t(f,e++)}();let n=an(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 cn=Ei;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*We(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 Je=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 Ai(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 Ai(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 Je)},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 Ii(r){return r[Symbol.asyncIterator]!=null}function Si(...r){let t=[];for(let e of r)Ii(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 un=Si;function Ye(r,...t){if(r==null)throw new Error("Empty pipeline");if(Ze(r)){let n=r;r=()=>n.source}else if(hn(r)||ln(r)){let n=r;r=()=>n}let e=[r,...t];if(e.length>1&&Ze(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++)Ze(e[n])&&(e[n]=Li(e[n]));return vi(...e)}var vi=(...r)=>{let t;for(;r.length>0;)t=r.shift()(t);return t},ln=r=>r?.[Symbol.asyncIterator]!=null,hn=r=>r?.[Symbol.iterator]!=null,Ze=r=>r==null?!1:r.sink!=null&&r.source!=null,Li=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(ln(i))o=async function*(){yield*i,n.end()};else if(hn(i))o=function*(){yield*i,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return un(n,o())}return r.source};var fn="libp2p",dn="autonat",pn="1.0.0";var tr=new Float32Array([-0]),Q=new Uint8Array(tr.buffer);function mn(r,t,e){tr[0]=r,t[e]=Q[0],t[e+1]=Q[1],t[e+2]=Q[2],t[e+3]=Q[3]}function gn(r,t){return Q[0]=r[t],Q[1]=r[t+1],Q[2]=r[t+2],Q[3]=r[t+3],tr[0]}var er=new Float64Array([-0]),T=new Uint8Array(er.buffer);function yn(r,t,e){er[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],er[0]}var Ri=BigInt(Number.MAX_SAFE_INTEGER),Ti=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<Ri&&t>Ti)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>bn&&(o=0n,++n>bn&&(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 bn=4294967296n;function xn(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 En(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 rr(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 nr=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=gn(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 En(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=ke(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 or(r){return new nr(r instanceof Uint8Array?r:r.subarray())}function mt(r,t,e){let n=or(r);return t.decode(n,void 0,e)}function ir(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 sr(){}var cr=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Di=ir();function Fi(r){return globalThis.Buffer!=null?L(r):Di(r)}var Ft=class{len;head;tail;states;constructor(){this.len=0,this.head=new nt(sr,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 ur((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(Pe,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(ar,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(mn,4,t)}double(t){return this._push(yn,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(ar,1,0):this.uint32(e)._push(Ui,e,t)}string(t){let e=xn(t);return e!==0?this.uint32(e)._push(rr,e,t):this._push(ar,1,0)}fork(){return this.states=new cr(this),this.head=this.tail=new nt(sr,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(sr,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=Fi(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function ar(r,t,e){t[e]=r&255}function Ni(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var ur=class extends nt{next;constructor(t,e){super(Ni,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 Ui(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(_i,t,r),this},Ft.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(Pi,t,r),this});function _i(r,t,e){t.set(r,e)}function Pi(r,t,e){r.length<40?rr(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(tt(r),e)}function lr(){return new Ft}function gt(r,t){let e=lr();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 wt(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=wt((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=wt((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=wt((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=wt((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 hr=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??fn}/${dn}/${pn}`,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 Ye(t.stream,i=>dt(i),async function*(i){let c=await Ke(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==null||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=!(De(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(b("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!(De(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 Ye([i],m=>Tt(m),h,m=>dt(m),async m=>Ke(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 We(cn(this.components.randomWalk.walk({signal:n}),l=>async()=>f(l)),{concurrency:hr}))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===hr){this.log("%a is externally dialable",l),t.confirmObservedAddr(l);return}if(c[a].failure===hr){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 Vi(r={}){return t=>new Yt(t,r)}return Tn(zi);})();
3
3
  return Libp2PAutonat}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@libp2p/autonat",
3
- "version": "1.1.0",
3
+ "version": "1.1.1-151bc46fb",
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.5.0",
56
- "@libp2p/interface-internal": "^1.2.4",
57
- "@libp2p/peer-id": "^4.1.4",
58
- "@libp2p/utils": "^5.4.4",
55
+ "@libp2p/interface": "1.6.0-151bc46fb",
56
+ "@libp2p/interface-internal": "1.3.0-151bc46fb",
57
+ "@libp2p/peer-id": "4.2.0-151bc46fb",
58
+ "@libp2p/utils": "5.4.5-151bc46fb",
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.15",
70
- "@libp2p/peer-id-factory": "^4.1.4",
69
+ "@libp2p/logger": "4.0.16-151bc46fb",
70
+ "@libp2p/peer-id-factory": "4.2.0-151bc46fb",
71
71
  "aegir": "^43.0.1",
72
72
  "it-all": "^3.0.6",
73
73
  "it-pushable": "^3.2.3",
@@ -1,8 +0,0 @@
1
- {
2
- "AutoNATComponents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_autonat.AutoNATComponents.html",
3
- ".:AutoNATComponents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_autonat.AutoNATComponents.html",
4
- "AutoNATServiceInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_autonat.AutoNATServiceInit.html",
5
- ".:AutoNATServiceInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_autonat.AutoNATServiceInit.html",
6
- "autoNAT": "https://libp2p.github.io/js-libp2p/functions/_libp2p_autonat.autoNAT.html",
7
- ".:autoNAT": "https://libp2p.github.io/js-libp2p/functions/_libp2p_autonat.autoNAT.html"
8
- }