@libp2p/autonat 1.1.5 → 2.0.0-18dd3cb26
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 +30 -1
- package/dist/src/autonat.d.ts.map +1 -1
- package/dist/src/autonat.js +8 -6
- package/dist/src/autonat.js.map +1 -1
- package/dist/src/pb/index.d.ts +5 -5
- package/dist/src/pb/index.d.ts.map +1 -1
- package/dist/src/pb/index.js +51 -29
- package/dist/src/pb/index.js.map +1 -1
- package/package.json +8 -7
- package/src/autonat.ts +8 -6
- package/src/pb/index.ts +52 -30
- package/dist/typedoc-urls.json +0 -8
package/dist/index.min.js
CHANGED
|
@@ -1,3 +1,32 @@
|
|
|
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 An=Object.create;var Ut=Object.defineProperty;var In=Object.getOwnPropertyDescriptor;var Sn=Object.getOwnPropertyNames;var vn=Object.getPrototypeOf,Ln=Object.prototype.hasOwnProperty;var Rn=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),N=(r,t)=>{for(var e in t)Ut(r,e,{get:t[e],enumerable:!0})},gr=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Sn(t))!Ln.call(r,o)&&o!==e&&Ut(r,o,{get:()=>t[o],enumerable:!(n=In(t,o))||n.enumerable});return r};var Tn=(r,t,e)=>(e=r!=null?An(vn(r)):{},gr(t||!r||!r.__esModule?Ut(e,"default",{value:r,enumerable:!0}):e,r)),Dn=r=>gr(Ut({},"__esModule",{value:!0}),r);var Gr=Rn(Lt=>{(function(){var r,t,e,n,o,i,c,u;u=function(f){var s,l,a,h;return s=(f&255<<24)>>>24,l=(f&255<<16)>>>16,a=(f&65280)>>>8,h=f&255,[s,l,a,h].join(".")},c=function(f){var s,l,a,h,p,d;for(s=[],a=h=0;h<=3&&f.length!==0;a=++h){if(a>0){if(f[0]!==".")throw new Error("Invalid IP");f=f.substring(1)}d=t(f),p=d[0],l=d[1],f=f.substring(l),s.push(p)}if(f.length!==0)throw new Error("Invalid IP");switch(s.length){case 1:if(s[0]>4294967295)throw new Error("Invalid IP");return s[0]>>>0;case 2:if(s[0]>255||s[1]>16777215)throw new Error("Invalid IP");return(s[0]<<24|s[1])>>>0;case 3:if(s[0]>255||s[1]>255||s[2]>65535)throw new Error("Invalid IP");return(s[0]<<24|s[1]<<16|s[2])>>>0;case 4:if(s[0]>255||s[1]>255||s[2]>255||s[3]>255)throw new Error("Invalid IP");return(s[0]<<24|s[1]<<16|s[2]<<8|s[3])>>>0;default:throw new Error("Invalid IP")}},e=function(f){return f.charCodeAt(0)},n=e("0"),i=e("a"),o=e("A"),t=function(f){var s,l,a,h,p;for(h=0,s=10,l="9",a=0,f.length>1&&f[a]==="0"&&(f[a+1]==="x"||f[a+1]==="X"?(a+=2,s=16):"0"<=f[a+1]&&f[a+1]<="9"&&(a++,s=8,l="7")),p=a;a<f.length;){if("0"<=f[a]&&f[a]<=l)h=h*s+(e(f[a])-n)>>>0;else if(s===16)if("a"<=f[a]&&f[a]<="f")h=h*s+(10+e(f[a])-i)>>>0;else if("A"<=f[a]&&f[a]<="F")h=h*s+(10+e(f[a])-o)>>>0;else break;else break;if(h>4294967295)throw new Error("too large");a++}if(a===p)throw new Error("empty octet");return[h,a]},r=function(){function f(s,l){var a,h,p,d;if(typeof s!="string")throw new Error("Missing `net' parameter");if(l||(d=s.split("/",2),s=d[0],l=d[1]),l||(l=32),typeof l=="string"&&l.indexOf(".")>-1){try{this.maskLong=c(l)}catch(m){throw a=m,new Error("Invalid mask: "+l)}for(h=p=32;p>=0;h=--p)if(this.maskLong===4294967295<<32-h>>>0){this.bitmask=h;break}}else if(l||l===0)this.bitmask=parseInt(l,10),this.maskLong=0,this.bitmask>0&&(this.maskLong=4294967295<<32-this.bitmask>>>0);else throw new Error("Invalid mask: empty");try{this.netLong=(c(s)&this.maskLong)>>>0}catch(m){throw a=m,new Error("Invalid net address: "+s)}if(!(this.bitmask<=32))throw new Error("Invalid mask for ip4: "+l);this.size=Math.pow(2,32-this.bitmask),this.base=u(this.netLong),this.mask=u(this.maskLong),this.hostmask=u(~this.maskLong),this.first=this.bitmask<=30?u(this.netLong+1):this.base,this.last=this.bitmask<=30?u(this.netLong+this.size-2):u(this.netLong+this.size-1),this.broadcast=this.bitmask<=30?u(this.netLong+this.size-1):void 0}return f.prototype.contains=function(s){return typeof s=="string"&&(s.indexOf("/")>0||s.split(".").length!==4)&&(s=new f(s)),s instanceof f?this.contains(s.base)&&this.contains(s.broadcast||s.last):(c(s)&this.maskLong)>>>0===(this.netLong&this.maskLong)>>>0},f.prototype.next=function(s){return s==null&&(s=1),new f(u(this.netLong+this.size*s),this.mask)},f.prototype.forEach=function(s){var l,a,h;for(h=c(this.first),a=c(this.last),l=0;h<=a;)s(u(h),h,l),l++,h++},f.prototype.toString=function(){return this.base+"/"+this.bitmask},f}(),Lt.ip2long=c,Lt.long2ip=u,Lt.Netmask=r}).call(Lt)});var qi={};N(qi,{autoNAT:()=>Gi});var ne=Symbol.for("@libp2p/peer-id");var W=class extends Error{code;props;constructor(t,e,n){super(t),this.code=e,this.name=n?.name??"CodeError",this.props=n??{}}};var oe="ERR_TIMEOUT";var ie=(r,...t)=>{try{[...t]}catch{}};var le={};N(le,{base58btc:()=>S,base58flickr:()=>kn});var Qi=new Uint8Array(0);function br(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function M(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")}function wr(r){return new TextEncoder().encode(r)}function yr(r){return new TextDecoder().decode(r)}function Fn(r,t){if(r.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),n=0;n<e.length;n++)e[n]=255;for(var o=0;o<r.length;o++){var i=r.charAt(o),c=i.charCodeAt(0);if(e[c]!==255)throw new TypeError(i+" is ambiguous");e[c]=o}var u=r.length,f=r.charAt(0),s=Math.log(u)/Math.log(256),l=Math.log(256)/Math.log(u);function a(d){if(d instanceof Uint8Array||(ArrayBuffer.isView(d)?d=new Uint8Array(d.buffer,d.byteOffset,d.byteLength):Array.isArray(d)&&(d=Uint8Array.from(d))),!(d instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(d.length===0)return"";for(var m=0,g=0,E=0,D=d.length;E!==D&&d[E]===0;)E++,m++;for(var I=(D-E)*l+1>>>0,F=new Uint8Array(I);E!==D;){for(var _=d[E],q=0,O=I-1;(_!==0||q<g)&&O!==-1;O--,q++)_+=256*F[O]>>>0,F[O]=_%u>>>0,_=_/u>>>0;if(_!==0)throw new Error("Non-zero carry");g=q,E++}for(var B=I-g;B!==I&&F[B]===0;)B++;for(var Nt=f.repeat(m);B<I;++B)Nt+=r.charAt(F[B]);return Nt}function h(d){if(typeof d!="string")throw new TypeError("Expected String");if(d.length===0)return new Uint8Array;var m=0;if(d[m]!==" "){for(var g=0,E=0;d[m]===f;)g++,m++;for(var D=(d.length-m)*s+1>>>0,I=new Uint8Array(D);d[m];){var F=e[d.charCodeAt(m)];if(F===255)return;for(var _=0,q=D-1;(F!==0||_<E)&&q!==-1;q--,_++)F+=u*I[q]>>>0,I[q]=F%256>>>0,F=F/256>>>0;if(F!==0)throw new Error("Non-zero carry");E=_,m++}if(d[m]!==" "){for(var O=D-E;O!==D&&I[O]===0;)O++;for(var B=new Uint8Array(g+(D-O)),Nt=g;O!==D;)B[Nt++]=I[O++];return B}}}function p(d){var m=h(d);if(m)return m;throw new Error(`Non-${t} character`)}return{encode:a,decodeUnsafe:h,decode:p}}var Nn=Fn,Un=Nn,Er=Un;var se=class{name;prefix;baseEncode;constructor(t,e,n){this.name=t,this.prefix=e,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},ae=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,e,n){if(this.name=t,this.prefix=e,e.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=e.codePointAt(0),this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return Ar(this,t)}},ce=class{decoders;constructor(t){this.decoders=t}or(t){return Ar(this,t)}decode(t){let e=t[0],n=this.decoders[e];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Ar(r,t){return new ce({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var ue=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,e,n,o){this.name=t,this.prefix=e,this.baseEncode=n,this.baseDecode=o,this.encoder=new se(t,e,n),this.decoder=new ae(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function ot({name:r,prefix:t,encode:e,decode:n}){return new ue(r,t,e,n)}function H({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=Er(e,r);return ot({prefix:t,name:r,encode:n,decode:i=>M(o(i))})}function _n(r,t,e,n){let o={};for(let l=0;l<t.length;++l)o[t[l]]=l;let i=r.length;for(;r[i-1]==="=";)--i;let c=new Uint8Array(i*e/8|0),u=0,f=0,s=0;for(let l=0;l<i;++l){let a=o[r[l]];if(a===void 0)throw new SyntaxError(`Non-${n} character`);f=f<<e|a,u+=e,u>=8&&(u-=8,c[s++]=255&f>>u)}if(u>=e||255&f<<8-u)throw new SyntaxError("Unexpected end of data");return c}function Pn(r,t,e){let n=t[t.length-1]==="=",o=(1<<e)-1,i="",c=0,u=0;for(let f=0;f<r.length;++f)for(u=u<<8|r[f],c+=8;c>e;)c-=e,i+=t[o&u>>c];if(c!==0&&(i+=t[o&u<<e-c]),n)for(;i.length*e&7;)i+="=";return i}function x({name:r,prefix:t,bitsPerChar:e,alphabet:n}){return ot({prefix:t,name:r,encode(o){return Pn(o,n,e)},decode(o){return _n(o,n,e,r)}})}var S=H({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),kn=H({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var he={};N(he,{base10:()=>On});var On=H({prefix:"9",name:"base10",alphabet:"0123456789"});var fe={};N(fe,{base16:()=>Cn,base16upper:()=>Bn});var Cn=x({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Bn=x({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var de={};N(de,{base2:()=>Mn});var Mn=x({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var pe={};N(pe,{base256emoji:()=>qn});var Ir=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),Vn=Ir.reduce((r,t,e)=>(r[e]=t,r),[]),zn=Ir.reduce((r,t,e)=>(r[t.codePointAt(0)]=e,r),[]);function $n(r){return r.reduce((t,e)=>(t+=Vn[e],t),"")}function Gn(r){let t=[];for(let e of r){let n=zn[e.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${e}`);t.push(n)}return new Uint8Array(t)}var qn=ot({prefix:"\u{1F680}",name:"base256emoji",encode:$n,decode:Gn});var me={};N(me,{base32:()=>V,base32hex:()=>Kn,base32hexpad:()=>Wn,base32hexpadupper:()=>Jn,base32hexupper:()=>Qn,base32pad:()=>jn,base32padupper:()=>Xn,base32upper:()=>Hn,base32z:()=>Zn});var V=x({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Hn=x({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),jn=x({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Xn=x({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Kn=x({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Qn=x({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Wn=x({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Jn=x({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Zn=x({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var ge={};N(ge,{base36:()=>Yn,base36upper:()=>to});var Yn=H({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),to=H({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var be={};N(be,{base64:()=>eo,base64pad:()=>ro,base64url:()=>no,base64urlpad:()=>oo});var eo=x({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),ro=x({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),no=x({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),oo=x({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var we={};N(we,{base8:()=>io});var io=x({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var ye={};N(ye,{identity:()=>so});var so=ot({prefix:"\0",name:"identity",encode:r=>yr(r),decode:r=>wr(r)});var hs=new TextEncoder,fs=new TextDecoder;var Ee={};N(Ee,{identity:()=>xt});var uo=Lr,Sr=128,lo=127,ho=~lo,fo=Math.pow(2,31);function Lr(r,t,e){t=t||[],e=e||0;for(var n=e;r>=fo;)t[e++]=r&255|Sr,r/=128;for(;r&ho;)t[e++]=r&255|Sr,r>>>=7;return t[e]=r|0,Lr.bytes=e-n+1,t}var po=xe,mo=128,vr=127;function xe(r,n){var e=0,n=n||0,o=0,i=n,c,u=r.length;do{if(i>=u)throw xe.bytes=0,new RangeError("Could not decode varint");c=r[i++],e+=o<28?(c&vr)<<o:(c&vr)*Math.pow(2,o),o+=7}while(c>=mo);return xe.bytes=i-n,e}var go=Math.pow(2,7),bo=Math.pow(2,14),wo=Math.pow(2,21),yo=Math.pow(2,28),xo=Math.pow(2,35),Eo=Math.pow(2,42),Ao=Math.pow(2,49),Io=Math.pow(2,56),So=Math.pow(2,63),vo=function(r){return r<go?1:r<bo?2:r<wo?3:r<yo?4:r<xo?5:r<Eo?6:r<Ao?7:r<Io?8:r<So?9:10},Lo={encode:uo,decode:po,encodingLength:vo},Ro=Lo,wt=Ro;function yt(r,t=0){return[wt.decode(r,t),wt.decode.bytes]}function it(r,t,e=0){return wt.encode(r,t,e),t}function st(r){return wt.encodingLength(r)}function j(r,t){let e=t.byteLength,n=st(r),o=n+st(e),i=new Uint8Array(o+e);return it(r,i,0),it(e,i,n),i.set(t,o),new at(r,e,t,i)}function J(r){let t=M(r),[e,n]=yt(t),[o,i]=yt(t.subarray(n)),c=t.subarray(n+i);if(c.byteLength!==o)throw new Error("Incorrect length");return new at(e,o,c,t)}function Rr(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&br(r.bytes,e.bytes)}}var at=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=n,this.bytes=o}};var Tr=0,To="identity",Dr=M;function Do(r){return j(Tr,Dr(r))}var xt={code:Tr,name:To,encode:Dr,digest:Do};var Se={};N(Se,{sha256:()=>Pt,sha512:()=>Fo});function Ie({name:r,code:t,encode:e}){return new Ae(r,t,e)}var Ae=class{name;code;encode;constructor(t,e,n){this.name=t,this.code=e,this.encode=n}digest(t){if(t instanceof Uint8Array){let e=this.encode(t);return e instanceof Uint8Array?j(this.code,e):e.then(n=>j(this.code,n))}else throw Error("Unknown type, must be binary type")}};function Nr(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var Pt=Ie({name:"sha2-256",code:18,encode:Nr("SHA-256")}),Fo=Ie({name:"sha2-512",code:19,encode:Nr("SHA-512")});function Ur(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return Uo(e,ve(r),t??S.encoder);default:return _o(e,ve(r),t??V.encoder)}}var _r=new WeakMap;function ve(r){let t=_r.get(r);if(t==null){let e=new Map;return _r.set(r,e),e}return t}var P=class r{code;version;multihash;bytes;"/";constructor(t,e,n,o){this.code=e,this.version=t,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:e}=this;if(t!==Et)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==Po)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(e)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:t,digest:e}=this.multihash,n=j(t,e);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return r.equals(this,t)}static equals(t,e){let n=e;return n!=null&&t.code===n.code&&t.version===n.version&&Rr(t.multihash,n.multihash)}toString(t){return Ur(this,t)}toJSON(){return{"/":Ur(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let e=t;if(e instanceof r)return e;if(e["/"]!=null&&e["/"]===e.bytes||e.asCID===e){let{version:n,code:o,multihash:i,bytes:c}=e;return new r(n,o,i,c??Pr(n,o,i.bytes))}else if(e[ko]===!0){let{version:n,multihash:o,code:i}=e,c=J(o);return r.create(n,i,c)}else return null}static create(t,e,n){if(typeof e!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(e!==Et)throw new Error(`Version 0 CID must use dag-pb (code: ${Et}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=Pr(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,Et,t)}static createV1(t,e){return r.create(1,t,e)}static decode(t){let[e,n]=r.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return e}static decodeFirst(t){let e=r.inspectBytes(t),n=e.size-e.multihashSize,o=M(t.subarray(n,n+e.multihashSize));if(o.byteLength!==e.multihashSize)throw new Error("Incorrect length");let i=o.subarray(e.multihashSize-e.digestSize),c=new at(e.multihashCode,e.digestSize,i,o);return[e.version===0?r.createV0(c):r.createV1(e.codec,c),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[a,h]=yt(t.subarray(e));return e+=h,a},o=n(),i=Et;if(o===18?(o=0,e=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let c=e,u=n(),f=n(),s=e+f,l=s-c;return{version:o,codec:i,multihashCode:u,digestSize:f,multihashSize:l,size:s}}static parse(t,e){let[n,o]=No(t,e),i=r.decode(o);if(i.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return ve(i).set(n,t),i}};function No(r,t){switch(r[0]){case"Q":{let e=t??S;return[S.prefix,e.decode(`${S.prefix}${r}`)]}case S.prefix:{let e=t??S;return[S.prefix,e.decode(r)]}case V.prefix:{let e=t??V;return[V.prefix,e.decode(r)]}default:{if(t==null)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[r[0],t.decode(r)]}}}function Uo(r,t,e){let{prefix:n}=e;if(n!==S.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let o=t.get(n);if(o==null){let i=e.encode(r).slice(1);return t.set(n,i),i}else return o}function _o(r,t,e){let{prefix:n}=e,o=t.get(n);if(o==null){let i=e.encode(r);return t.set(n,i),i}else return o}var Et=112,Po=18;function Pr(r,t,e){let n=st(r),o=n+st(t),i=new Uint8Array(o+e.byteLength);return it(r,i,0),it(t,i,n),i.set(e,o),i}var ko=Symbol.for("@ipld/js-cid/CID");var X={...ye,...de,...we,...he,...fe,...me,...ge,...le,...be,...pe},_s={...Se,...Ee};function Y(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function z(r=0){return new Uint8Array(r)}function L(r=0){return new Uint8Array(r)}function Or(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var kr=Or("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Le=Or("ascii","a",r=>{let t="a";for(let e=0;e<r.length;e++)t+=String.fromCharCode(r[e]);return t},r=>{r=r.substring(1);let t=L(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),Oo={utf8:kr,"utf-8":kr,hex:X.base16,latin1:Le,ascii:Le,binary:Le,...X},kt=Oo;function tt(r,t="utf8"){let e=kt[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function v(r,t="utf8"){let e=kt[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var Br=Symbol.for("nodejs.util.inspect.custom"),Cr=Object.values(X).map(r=>r.decoder).reduce((r,t)=>r.or(t),X.identity.decoder),Mr=114,Vr=36,zr=37,At=class{type;multihash;privateKey;publicKey;string;constructor(t){this.type=t.type,this.multihash=t.multihash,this.privateKey=t.privateKey,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[ne]=!0;toString(){return this.string==null&&(this.string=S.encode(this.multihash.bytes).slice(1)),this.string}toCID(){return P.createV1(Mr,this.multihash)}toBytes(){return this.multihash.bytes}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return Y(this.multihash.bytes,t);if(typeof t=="string")return Co(t).equals(this);if(t?.multihash?.bytes!=null)return Y(this.multihash.bytes,t.multihash.bytes);throw new Error("not valid Id")}[Br](){return`PeerId(${this.toString()})`}},It=class extends At{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},St=class extends At{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.multihash.digest}},vt=class extends At{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.multihash.digest}},Re=2336,Te=class{type="url";multihash;privateKey;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=xt.digest(tt(this.url))}[Br](){return`PeerId(${this.url})`}[ne]=!0;toString(){return this.toCID().toString()}toCID(){return P.createV1(Re,this.multihash)}toBytes(){return this.toCID().bytes}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=v(t)),t.toString()===this.toString())}};function Co(r,t){if(t=t??Cr,r.charAt(0)==="1"||r.charAt(0)==="Q"){let e=J(S.decode(`z${r}`));return r.startsWith("12D")?new St({multihash:e}):r.startsWith("16U")?new vt({multihash:e}):new It({multihash:e})}return De(Cr.decode(r))}function De(r){try{let t=J(r);if(t.code===xt.code){if(t.digest.length===Vr)return new St({multihash:t});if(t.digest.length===zr)return new vt({multihash:t})}if(t.code===Pt.code)return new It({multihash:t})}catch{return Bo(P.decode(r))}throw new Error("Supplied PeerID CID is invalid")}function Bo(r){if(r?.multihash==null||r.version==null||r.version===1&&r.code!==Mr&&r.code!==Re)throw new Error("Supplied PeerID CID is invalid");if(r.code===Re){let e=v(r.multihash.digest);return new Te(new URL(e))}let t=r.multihash;if(t.code===Pt.code)return new It({multihash:r.multihash});if(t.code===xt.code){if(t.digest.length===Vr)return new St({multihash:r.multihash});if(t.digest.length===zr)return new vt({multihash:r.multihash})}throw new Error("Supplied PeerID CID is invalid")}var Ot=class{index=0;input="";new(t){return this.index=0,this.input=t,this}readAtomically(t){let e=this.index,n=t();return n===void 0&&(this.index=e),n}parseWith(t){let e=t();if(this.index===this.input.length)return e}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(t){return this.readAtomically(()=>{let e=this.readChar();if(e===t)return e})}readSeparator(t,e,n){return this.readAtomically(()=>{if(!(e>0&&this.readGivenChar(t)===void 0))return n()})}readNumber(t,e,n,o){return this.readAtomically(()=>{let i=0,c=0,u=this.peekChar();if(u===void 0)return;let f=u==="0",s=2**(8*o)-1;for(;;){let l=this.readAtomically(()=>{let a=this.readChar();if(a===void 0)return;let h=Number.parseInt(a,t);if(!Number.isNaN(h))return h});if(l===void 0)break;if(i*=t,i+=l,i>s||(c+=1,e!==void 0&&c>e))return}if(c!==0)return!n&&f&&c>1?void 0:i})}readIPv4Addr(){return this.readAtomically(()=>{let t=new Uint8Array(4);for(let e=0;e<t.length;e++){let n=this.readSeparator(".",e,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;t[e]=n}return t})}readIPv6Addr(){let t=e=>{for(let n=0;n<e.length/2;n++){let o=n*2;if(n<e.length-3){let c=this.readSeparator(":",n,()=>this.readIPv4Addr());if(c!==void 0)return e[o]=c[0],e[o+1]=c[1],e[o+2]=c[2],e[o+3]=c[3],[o+4,!0]}let i=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(i===void 0)return[o,!1];e[o]=i>>8,e[o+1]=i&255}return[e.length,!1]};return this.readAtomically(()=>{let e=new Uint8Array(16),[n,o]=t(e);if(n===16)return e;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let i=new Uint8Array(14),c=16-(n+2),[u]=t(i.subarray(0,c));return e.set(i.subarray(0,u),16-u),e})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var $r=45,Mo=15,ct=new Ot;function Fe(r){if(!(r.length>Mo))return ct.new(r).parseWith(()=>ct.readIPv4Addr())}function Ne(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>$r))return ct.new(r).parseWith(()=>ct.readIPv6Addr())}function Ct(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>$r))return ct.new(r).parseWith(()=>ct.readIPAddr())}function Bt(r){return!!Fe(r)}function Mt(r){return!!Ne(r)}function Vt(r){return!!Ct(r)}var qr=Tn(Gr(),1),Vo=["0.0.0.0/8","10.0.0.0/8","100.64.0.0/10","127.0.0.0/8","169.254.0.0/16","172.16.0.0/12","192.0.0.0/24","192.0.0.0/29","192.0.0.8/32","192.0.0.9/32","192.0.0.10/32","192.0.0.170/32","192.0.0.171/32","192.0.2.0/24","192.31.196.0/24","192.52.193.0/24","192.88.99.0/24","192.168.0.0/16","192.175.48.0/24","198.18.0.0/15","198.51.100.0/24","203.0.113.0/24","240.0.0.0/4","255.255.255.255/32"],zo=Vo.map(r=>new qr.Netmask(r));function Ue(r){for(let t of zo)if(t.contains(r))return!0;return!1}function $o(r){return/^::ffff:([0-9a-fA-F]{1,4}):([0-9a-fA-F]{1,4})$/.test(r)}function Go(r){let t=r.split(":");if(t.length<2)return!1;let e=t[t.length-1].padStart(4,"0"),n=t[t.length-2].padStart(4,"0"),o=`${parseInt(n.substring(0,2),16)}.${parseInt(n.substring(2),16)}.${parseInt(e.substring(0,2),16)}.${parseInt(e.substring(2),16)}`;return Ue(o)}function qo(r){return/^::ffff:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(r)}function Ho(r){let t=r.split(":"),e=t[t.length-1];return Ue(e)}function jo(r){return/^::$/.test(r)||/^::1$/.test(r)||/^64:ff9b::([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(r)||/^100::([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2001::([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2001:2[0-9a-fA-F]:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2001:db8:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2002:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^f[c-d]([0-9a-fA-F]{2,2}):/i.test(r)||/^fe[8-9a-bA-B][0-9a-fA-F]:/i.test(r)||/^ff([0-9a-fA-F]{2,2}):/i.test(r)}function _e(r){return Bt(r)?Ue(r):$o(r)?Go(r):qo(r)?Ho(r):Mt(r)?jo(r):void 0}var Xo=Math.pow(2,7),Ko=Math.pow(2,14),Qo=Math.pow(2,21),Pe=Math.pow(2,28),ke=Math.pow(2,35),Oe=Math.pow(2,42),Ce=Math.pow(2,49),w=128,R=127;function A(r){if(r<Xo)return 1;if(r<Ko)return 2;if(r<Qo)return 3;if(r<Pe)return 4;if(r<ke)return 5;if(r<Oe)return 6;if(r<Ce)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Be(r,t,e=0){switch(A(r)){case 8:t[e++]=r&255|w,r/=128;case 7:t[e++]=r&255|w,r/=128;case 6:t[e++]=r&255|w,r/=128;case 5:t[e++]=r&255|w,r/=128;case 4:t[e++]=r&255|w,r>>>=7;case 3:t[e++]=r&255|w,r>>>=7;case 2:t[e++]=r&255|w,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function Wo(r,t,e=0){switch(A(r)){case 8:t.set(e++,r&255|w),r/=128;case 7:t.set(e++,r&255|w),r/=128;case 6:t.set(e++,r&255|w),r/=128;case 5:t.set(e++,r&255|w),r/=128;case 4:t.set(e++,r&255|w),r>>>=7;case 3:t.set(e++,r&255|w),r>>>=7;case 2:t.set(e++,r&255|w),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function Me(r,t){let e=r[t],n=0;if(n+=e&R,e<w||(e=r[t+1],n+=(e&R)<<7,e<w)||(e=r[t+2],n+=(e&R)<<14,e<w)||(e=r[t+3],n+=(e&R)<<21,e<w)||(e=r[t+4],n+=(e&R)*Pe,e<w)||(e=r[t+5],n+=(e&R)*ke,e<w)||(e=r[t+6],n+=(e&R)*Oe,e<w)||(e=r[t+7],n+=(e&R)*Ce,e<w))return n;throw new RangeError("Could not decode varint")}function Jo(r,t){let e=r.get(t),n=0;if(n+=e&R,e<w||(e=r.get(t+1),n+=(e&R)<<7,e<w)||(e=r.get(t+2),n+=(e&R)<<14,e<w)||(e=r.get(t+3),n+=(e&R)<<21,e<w)||(e=r.get(t+4),n+=(e&R)*Pe,e<w)||(e=r.get(t+5),n+=(e&R)*ke,e<w)||(e=r.get(t+6),n+=(e&R)*Oe,e<w)||(e=r.get(t+7),n+=(e&R)*Ce,e<w))return n;throw new RangeError("Could not decode varint")}function K(r,t,e=0){return t==null&&(t=L(A(r))),t instanceof Uint8Array?Be(r,t,e):Wo(r,t,e)}function $(r,t=0){return r instanceof Uint8Array?Me(r,t):Jo(r,t)}function k(r,t){t==null&&(t=r.reduce((o,i)=>o+i.length,0));let e=L(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return e}var xa=parseInt("0xFFFF",16),Ea=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);var Xr=Bt,ri=Mt,Ve=function(r){let t=0;if(r=r.toString().trim(),Xr(r)){let e=new Uint8Array(t+4);return r.split(/\./g).forEach(n=>{e[t++]=parseInt(n,10)&255}),e}if(ri(r)){let e=r.split(":",8),n;for(n=0;n<e.length;n++){let i=Xr(e[n]),c;i&&(c=Ve(e[n]),e[n]=v(c.slice(0,2),"base16")),c!=null&&++n<8&&e.splice(n,0,v(c.slice(2,4),"base16"))}if(e[0]==="")for(;e.length<8;)e.unshift("0");else if(e[e.length-1]==="")for(;e.length<8;)e.push("0");else if(e.length<8){for(n=0;n<e.length&&e[n]!=="";n++);let i=[n,1];for(n=9-e.length;n>0;n--)i.push("0");e.splice.apply(e,i)}let o=new Uint8Array(t+16);for(n=0;n<e.length;n++){let i=parseInt(e[n],16);o[t++]=i>>8&255,o[t++]=i&255}return o}throw new Error("invalid ip address")},Kr=function(r,t=0,e){t=~~t,e=e??r.length-t;let n=new DataView(r.buffer);if(e===4){let o=[];for(let i=0;i<e;i++)o.push(r[t+i]);return o.join(".")}if(e===16){let o=[];for(let i=0;i<e;i+=2)o.push(n.getUint16(t+i).toString(16));return o.join(":").replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}return""};var ut={},ze={},oi=[[4,32,"ip4"],[6,16,"tcp"],[33,16,"dccp"],[41,128,"ip6"],[42,-1,"ip6zone"],[43,8,"ipcidr"],[53,-1,"dns",!0],[54,-1,"dns4",!0],[55,-1,"dns6",!0],[56,-1,"dnsaddr",!0],[132,16,"sctp"],[273,16,"udp"],[275,0,"p2p-webrtc-star"],[276,0,"p2p-webrtc-direct"],[277,0,"p2p-stardust"],[280,0,"webrtc-direct"],[281,0,"webrtc"],[290,0,"p2p-circuit"],[301,0,"udt"],[302,0,"utp"],[400,-1,"unix",!1,!0],[421,-1,"ipfs"],[421,-1,"p2p"],[443,0,"https"],[444,96,"onion"],[445,296,"onion3"],[446,-1,"garlic64"],[448,0,"tls"],[449,-1,"sni"],[460,0,"quic"],[461,0,"quic-v1"],[465,0,"webtransport"],[466,-1,"certhash"],[477,0,"ws"],[478,0,"wss"],[479,0,"p2p-websocket-star"],[480,0,"http"],[481,-1,"http-path"],[777,-1,"memory"]];oi.forEach(r=>{let t=ii(...r);ze[t.code]=t,ut[t.name]=t});function ii(r,t,e,n,o){return{code:r,size:t,name:e,resolvable:!!n,path:!!o}}function y(r){if(typeof r=="number"){if(ze[r]!=null)return ze[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(ut[r]!=null)return ut[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var rc=y("ip4"),nc=y("ip6"),oc=y("ipcidr");function He(r,t){switch(y(r).code){case 4:case 41:return ai(t);case 42:return qe(t);case 6:case 273:case 33:case 132:return Jr(t).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return qe(t);case 421:return hi(t);case 444:return Wr(t);case 445:return Wr(t);case 466:return li(t);case 481:return globalThis.encodeURIComponent(qe(t));default:return v(t,"base16")}}function je(r,t){switch(y(r).code){case 4:return Qr(t);case 41:return Qr(t);case 42:return Ge(t);case 6:case 273:case 33:case 132:return Xe(parseInt(t,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return Ge(t);case 421:return ci(t);case 444:return fi(t);case 445:return di(t);case 466:return ui(t);case 481:return Ge(globalThis.decodeURIComponent(t));default:return tt(t,"base16")}}var $e=Object.values(X).map(r=>r.decoder),si=function(){let r=$e[0].or($e[1]);return $e.slice(2).forEach(t=>r=r.or(t)),r}();function Qr(r){if(!Vt(r))throw new Error("invalid ip address");return Ve(r)}function ai(r){let t=Kr(r,0,r.length);if(t==null)throw new Error("ipBuff is required");if(!Vt(t))throw new Error("invalid ip address");return t}function Xe(r){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,r),new Uint8Array(t)}function Jr(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function Ge(r){let t=tt(r),e=Uint8Array.from(K(t.length));return k([e,t],e.length+t.length)}function qe(r){let t=$(r);if(r=r.slice(A(t)),r.length!==t)throw new Error("inconsistent lengths");return v(r)}function ci(r){let t;r[0]==="Q"||r[0]==="1"?t=J(S.decode(`z${r}`)).bytes:t=P.parse(r).multihash.bytes;let e=Uint8Array.from(K(t.length));return k([e,t],e.length+t.length)}function ui(r){let t=si.decode(r),e=Uint8Array.from(K(t.length));return k([e,t],e.length+t.length)}function li(r){let t=$(r),e=r.slice(A(t));if(e.length!==t)throw new Error("inconsistent lengths");return"u"+v(e,"base64url")}function hi(r){let t=$(r),e=r.slice(A(t));if(e.length!==t)throw new Error("inconsistent lengths");return v(e,"base58btc")}function fi(r){let t=r.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==16)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion address.`);let e=V.decode("b"+t[0]),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=Xe(n);return k([e,o],e.length+o.length)}function di(r){let t=r.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==56)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion3 address.`);let e=V.decode(`b${t[0]}`),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=Xe(n);return k([e,o],e.length+o.length)}function Wr(r){let t=r.slice(0,r.length-2),e=r.slice(r.length-2),n=v(t,"base32"),o=Jr(e);return`${n}:${o}`}function Zr(r){r=Ke(r);let t=[],e=[],n=null,o=r.split("/").slice(1);if(o.length===1&&o[0]==="")return{bytes:new Uint8Array,string:"/",tuples:[],stringTuples:[],path:null};for(let i=0;i<o.length;i++){let c=o[i],u=y(c);if(u.size===0){t.push([u.code]),e.push([u.code]);continue}if(i++,i>=o.length)throw tn("invalid address: "+r);if(u.path===!0){n=Ke(o.slice(i).join("/")),t.push([u.code,je(u.code,n)]),e.push([u.code,n]);break}let f=je(u.code,o[i]);t.push([u.code,f]),e.push([u.code,He(u.code,f)])}return{string:Yr(e),bytes:We(t),tuples:t,stringTuples:e,path:n}}function Qe(r){let t=[],e=[],n=null,o=0;for(;o<r.length;){let i=$(r,o),c=A(i),u=y(i),f=pi(u,r.slice(o+c));if(f===0){t.push([i]),e.push([i]),o+=c;continue}let s=r.slice(o+c,o+c+f);if(o+=f+c,o>r.length)throw tn("Invalid address Uint8Array: "+v(r,"base16"));t.push([i,s]);let l=He(i,s);if(e.push([i,l]),u.path===!0){n=l;break}}return{bytes:Uint8Array.from(r),string:Yr(e),tuples:t,stringTuples:e,path:n}}function Yr(r){let t=[];return r.map(e=>{let n=y(e[0]);return t.push(n.name),e.length>1&&e[1]!=null&&t.push(e[1]),null}),Ke(t.join("/"))}function We(r){return k(r.map(t=>{let e=y(t[0]),n=Uint8Array.from(K(e.code));return t.length>1&&t[1]!=null&&(n=k([n,t[1]])),n}))}function pi(r,t){if(r.size>0)return r.size/8;if(r.size===0)return 0;{let e=$(t instanceof Uint8Array?t:Uint8Array.from(t));return e+A(e)}}function Ke(r){return"/"+r.trim().split("/").filter(t=>t).join("/")}function tn(r){return new Error("Error parsing address: "+r)}var mi=Symbol.for("nodejs.util.inspect.custom"),Je=Symbol.for("@multiformats/js-multiaddr/multiaddr"),gi=[y("dns").code,y("dns4").code,y("dns6").code,y("dnsaddr").code],$t=class r{bytes;#e;#t;#r;#n;[Je]=!0;constructor(t){t==null&&(t="");let e;if(t instanceof Uint8Array)e=Qe(t);else if(typeof t=="string"){if(t.length>0&&t.charAt(0)!=="/")throw new Error(`multiaddr "${t}" must start with a "/"`);e=Zr(t)}else if(rn(t))e=Qe(t.bytes);else throw new Error("addr must be a string, Buffer, or another Multiaddr");this.bytes=e.bytes,this.#e=e.string,this.#t=e.tuples,this.#r=e.stringTuples,this.#n=e.path}toString(){return this.#e}toJSON(){return this.toString()}toOptions(){let t,e,n,o,i="",c=y("tcp"),u=y("udp"),f=y("ip4"),s=y("ip6"),l=y("dns6"),a=y("ip6zone");for(let[p,d]of this.stringTuples())p===a.code&&(i=`%${d??""}`),gi.includes(p)&&(e=c.name,o=443,n=`${d??""}${i}`,t=p===l.code?6:4),(p===c.code||p===u.code)&&(e=y(p).name,o=parseInt(d??"")),(p===f.code||p===s.code)&&(e=y(p).name,n=`${d??""}${i}`,t=p===s.code?6:4);if(t==null||e==null||n==null||o==null)throw new Error('multiaddr must have a valid format: "/{ip4, ip6, dns4, dns6, dnsaddr}/{address}/{tcp, udp}/{port}".');return{family:t,host:n,transport:e,port:o}}protos(){return this.#t.map(([t])=>Object.assign({},y(t)))}protoCodes(){return this.#t.map(([t])=>t)}protoNames(){return this.#t.map(([t])=>y(t).name)}tuples(){return this.#t}stringTuples(){return this.#r}encapsulate(t){return t=new r(t),new r(this.toString()+t.toString())}decapsulate(t){let e=t.toString(),n=this.toString(),o=n.lastIndexOf(e);if(o<0)throw new Error(`Address ${this.toString()} does not contain subaddress: ${t.toString()}`);return new r(n.slice(0,o))}decapsulateCode(t){let e=this.tuples();for(let n=e.length-1;n>=0;n--)if(e[n][0]===t)return new r(We(e.slice(0,n)));return this}getPeerId(){try{let t=[];this.stringTuples().forEach(([n,o])=>{n===ut.p2p.code&&t.push([n,o]),n===ut["p2p-circuit"].code&&(t=[])});let e=t.pop();if(e?.[1]!=null){let n=e[1];return n[0]==="Q"||n[0]==="1"?v(S.decode(`z${n}`),"base58btc"):v(P.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){return this.#n}equals(t){return Y(this.bytes,t.bytes)}async resolve(t){let e=this.protos().find(i=>i.resolvable);if(e==null)return[this];let n=en.get(e.name);if(n==null)throw new W(`no available resolver for ${e.name}`,"ERR_NO_AVAILABLE_RESOLVER");return(await n(this,t)).map(i=>lt(i))}nodeAddress(){let t=this.toOptions();if(t.transport!=="tcp"&&t.transport!=="udp")throw new Error(`multiaddr must have a valid format - no protocol with name: "${t.transport}". Must have a valid transport protocol: "{tcp, udp}"`);return{family:t.family,address:t.host,port:t.port}}isThinWaistAddress(t){let e=(t??this).protos();return!(e.length!==2||e[0].code!==4&&e[0].code!==41||e[1].code!==6&&e[1].code!==273)}[mi](){return`Multiaddr(${this.#e})`}};var en=new Map;function rn(r){return!!r?.[Je]}function lt(r){return new $t(r)}function bi(r){return r[Symbol.asyncIterator]!=null}function wi(r){if(bi(r))return(async()=>{for await(let t of r)return t})();for(let t of r)return t}var Ze=wi;var on=Symbol.for("@achingbrain/uint8arraylist");function nn(r,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let e=0;for(let n of r){let o=e+n.byteLength;if(t<o)return{buf:n,index:t-e};e=o}throw new RangeError("index is out of bounds")}function Gt(r){return!!r?.[on]}var ht=class r{bufs;length;[on]=!0;constructor(...t){this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let e=0;for(let n of t)if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.push(n);else if(Gt(n))e+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}prepend(...t){this.prependAll(t)}prependAll(t){let e=0;for(let n of t.reverse())if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.unshift(n);else if(Gt(n))e+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}get(t){let e=nn(this.bufs,t);return e.buf[e.index]}set(t,e){let n=nn(this.bufs,t);n.buf[n.index]=e}write(t,e=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(e+n,t[n]);else if(Gt(t))for(let n=0;n<t.length;n++)this.set(e+n,t.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,e){let{bufs:n,length:o}=this._subList(t,e);return k(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:k(n,o)}sublist(t,e){let{bufs:n,length:o}=this._subList(t,e),i=new r;return i.length=o,i.bufs=[...n],i}_subList(t,e){if(t=t??0,e=e??this.length,t<0&&(t=this.length+t),e<0&&(e=this.length+e),t<0||e>this.length)throw new RangeError("index is out of bounds");if(t===e)return{bufs:[],length:0};if(t===0&&e===this.length)return{bufs:this.bufs,length:this.length};let n=[],o=0;for(let i=0;i<this.bufs.length;i++){let c=this.bufs[i],u=o,f=u+c.byteLength;if(o=f,t>=f)continue;let s=t>=u&&t<f,l=e>u&&e<=f;if(s&&l){if(t===u&&e===f){n.push(c);break}let a=t-u;n.push(c.subarray(a,a+(e-t)));break}if(s){if(t===0){n.push(c);continue}n.push(c.subarray(t-u));continue}if(l){if(e===f){n.push(c);break}n.push(c.subarray(0,e-u));break}n.push(c)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!Gt(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(e=Number(e??0),isNaN(e)&&(e=0),e<0&&(e=this.length+e),e<0&&(e=0),t.length===0)return e>this.length?this.length:e;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let i=256,c=new Int32Array(i);for(let a=0;a<i;a++)c[a]=-1;for(let a=0;a<o;a++)c[n[a]]=a;let u=c,f=this.byteLength-n.byteLength,s=n.byteLength-1,l;for(let a=e;a<=f;a+=l){l=0;for(let h=s;h>=0;h--){let p=this.get(a+h);if(n[h]!==p){l=Math.max(1,h-u[p]);break}}if(l===0)return a}return-1}getInt8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getInt8(0)}setInt8(t,e){let n=L(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,e),this.write(n,t)}getInt16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,e)}setInt16(t,e,n){let o=z(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,e,n),this.write(o,t)}getInt32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,e)}setInt32(t,e,n){let o=z(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,e,n),this.write(o,t)}getBigInt64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,e)}setBigInt64(t,e,n){let o=z(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,e,n),this.write(o,t)}getUint8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getUint8(0)}setUint8(t,e){let n=L(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,e),this.write(n,t)}getUint16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,e)}setUint16(t,e,n){let o=z(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,e,n),this.write(o,t)}getUint32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,e)}setUint32(t,e,n){let o=z(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,e,n),this.write(o,t)}getBigUint64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,e)}setBigUint64(t,e,n){let o=z(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,e,n),this.write(o,t)}getFloat32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,e)}setFloat32(t,e,n){let o=z(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,e,n),this.write(o,t)}getFloat64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,e)}setFloat64(t,e,n){let o=z(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,e,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof r)||t.bufs.length!==this.bufs.length)return!1;for(let e=0;e<this.bufs.length;e++)if(!Y(this.bufs[e],t.bufs[e]))return!1;return!0}static fromUint8Arrays(t,e){let n=new r;return n.bufs=t,e==null&&(e=t.reduce((o,i)=>o+i.byteLength,0)),n.length=e,n}};function qt(r){return r[Symbol.asyncIterator]!=null}var Ht=r=>{let t=A(r),e=L(t);return K(r,e),Ht.bytes=t,e};Ht.bytes=0;function Rt(r,t){t=t??{};let e=t.lengthEncoder??Ht;function*n(o){let i=e(o.byteLength);i instanceof Uint8Array?yield i:yield*i,o instanceof Uint8Array?yield o:yield*o}return qt(r)?async function*(){for await(let o of r)yield*n(o)}():function*(){for(let o of r)yield*n(o)}()}Rt.single=(r,t)=>{t=t??{};let e=t.lengthEncoder??Ht;return new ht(e(r.byteLength),r)};var jt=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},Xt=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},Kt=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"},Tt=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};var yi=8,xi=1024*1024*4,et;(function(r){r[r.LENGTH=0]="LENGTH",r[r.DATA=1]="DATA"})(et||(et={}));var Ye=r=>{let t=$(r);return Ye.bytes=A(t),t};Ye.bytes=0;function ft(r,t){let e=new ht,n=et.LENGTH,o=-1,i=t?.lengthDecoder??Ye,c=t?.maxLengthLength??yi,u=t?.maxDataLength??xi;function*f(){for(;e.byteLength>0;){if(n===et.LENGTH)try{if(o=i(e),o<0)throw new jt("Invalid message length");if(o>u)throw new Xt("Message length too long");let s=i.bytes;e.consume(s),t?.onLength!=null&&t.onLength(o),n=et.DATA}catch(s){if(s instanceof RangeError){if(e.byteLength>c)throw new Kt("Message length length too long");break}throw s}if(n===et.DATA){if(e.byteLength<o)break;let s=e.sublist(0,o);e.consume(o),t?.onData!=null&&t.onData(s),yield s,n=et.LENGTH}}}return qt(r)?async function*(){for await(let s of r)e.append(s),yield*f();if(e.byteLength>0)throw new Tt("Unexpected end of input")}():function*(){for(let s of r)e.append(s),yield*f();if(e.byteLength>0)throw new Tt("Unexpected end of input")}()}ft.fromReader=(r,t)=>{let e=1,n=async function*(){for(;;)try{let{done:i,value:c}=await r.next(e);if(i===!0)return;c!=null&&(yield c)}catch(i){if(i.code==="ERR_UNDER_READ")return{done:!0,value:null};throw i}finally{e=1}}();return ft(n,{...t??{},onLength:i=>{e=i}})};function Ai(r){let[t,e]=r[Symbol.asyncIterator]!=null?[r[Symbol.asyncIterator](),Symbol.asyncIterator]:[r[Symbol.iterator](),Symbol.iterator],n=[];return{peek:()=>t.next(),push:o=>{n.push(o)},next:()=>n.length>0?{done:!1,value:n.shift()}:t.next(),[e](){return this}}}var sn=Ai;function Ii(r){return r[Symbol.asyncIterator]!=null}function Si(r,t){let e=0;if(Ii(r))return async function*(){for await(let f of r)yield t(f,e++)}();let n=sn(r),{value:o,done:i}=n.next();if(i===!0)return function*(){}();let c=t(o,e++);if(typeof c.then=="function")return async function*(){yield await c;for await(let f of n)yield t(f,e++)}();let u=t;return function*(){yield c;for(let f of n)yield u(f,e++)}()}var an=Si;function G(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var Qt=globalThis.CustomEvent??Event;async function*tr(r,t={}){let e=t.concurrency??1/0;e<1&&(e=1/0);let n=t.ordered==null?!1:t.ordered,o=new EventTarget,i=[],c=G(),u=G(),f=!1,s,l=!1;o.addEventListener("task-complete",()=>{u.resolve()}),Promise.resolve().then(async()=>{try{for await(let d of r){if(i.length===e&&(c=G(),await c.promise),l)break;let m={done:!1};i.push(m),d().then(g=>{m.done=!0,m.ok=!0,m.value=g,o.dispatchEvent(new Qt("task-complete"))},g=>{m.done=!0,m.err=g,o.dispatchEvent(new Qt("task-complete"))})}f=!0,o.dispatchEvent(new Qt("task-complete"))}catch(d){s=d,o.dispatchEvent(new Qt("task-complete"))}});function a(){return n?i[0]?.done:!!i.find(d=>d.done)}function*h(){for(;i.length>0&&i[0].done;){let d=i[0];if(i.shift(),d.ok)yield d.value;else throw l=!0,c.resolve(),d.err;c.resolve()}}function*p(){for(;a();)for(let d=0;d<i.length;d++)if(i[d].done){let m=i[d];if(i.splice(d,1),d--,m.ok)yield m.value;else throw l=!0,c.resolve(),m.err;c.resolve()}}for(;;){if(a()||(u=G(),await u.promise),s!=null)throw s;if(n?yield*h():yield*p(),f&&i.length===0)break}}var Wt=class{buffer;mask;top;btm;next;constructor(t){if(!(t>0)||t-1&t)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(t),this.mask=t-1,this.top=0,this.btm=0,this.next=null}push(t){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=t,this.top=this.top+1&this.mask,!0)}shift(){let t=this.buffer[this.btm];if(t!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,t}isEmpty(){return this.buffer[this.btm]===void 0}},dt=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new Wt(this.hwm),this.tail=this.head,this.size=0}calculateSize(t){return t?.byteLength!=null?t.byteLength:1}push(t){if(t?.value!=null&&(this.size+=this.calculateSize(t.value)),!this.head.push(t)){let e=this.head;this.head=e.next=new Wt(2*this.head.buffer.length),this.head.push(t)}}shift(){let t=this.tail.shift();if(t===void 0&&this.tail.next!=null){let e=this.tail.next;this.tail.next=null,this.tail=e,t=this.tail.shift()}return t?.value!=null&&(this.size-=this.calculateSize(t.value)),t}isEmpty(){return this.head.isEmpty()}};var er=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.code=e??"ABORT_ERR"}};function Jt(r={}){return vi(e=>{let n=e.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},r)}function vi(r,t){t=t??{};let e=t.onEnd,n=new dt,o,i,c,u=G(),f=async()=>{try{return n.isEmpty()?c?{done:!0}:await new Promise((g,E)=>{i=D=>{i=null,n.push(D);try{g(r(n))}catch(I){E(I)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{u.resolve(),u=G()})}},s=g=>i!=null?i(g):(n.push(g),o),l=g=>(n=new dt,i!=null?i({error:g}):(n.push({error:g}),o)),a=g=>{if(c)return o;if(t?.objectMode!==!0&&g?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return s({done:!1,value:g})},h=g=>c?o:(c=!0,g!=null?l(g):s({done:!0})),p=()=>(n=new dt,h(),{done:!0}),d=g=>(h(g),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:f,return:p,throw:d,push:a,end:h,get readableLength(){return n.size},onEmpty:async g=>{let E=g?.signal;if(E?.throwIfAborted(),n.isEmpty())return;let D,I;E!=null&&(D=new Promise((F,_)=>{I=()=>{_(new er)},E.addEventListener("abort",I)}));try{await Promise.race([u.promise,D])}finally{I!=null&&E!=null&&E?.removeEventListener("abort",I)}}},e==null)return o;let m=o;return o={[Symbol.asyncIterator](){return this},next(){return m.next()},throw(g){return m.throw(g),e!=null&&(e(g),e=void 0),{done:!0}},return(){return m.return(),e!=null&&(e(),e=void 0),{done:!0}},push:a,end(g){return m.end(g),e!=null&&(e(g),e=void 0),o},get readableLength(){return m.readableLength},onEmpty:g=>m.onEmpty(g)},o}function Li(r){return r[Symbol.asyncIterator]!=null}function Ri(...r){let t=[];for(let e of r)Li(e)||t.push(e);return t.length===r.length?function*(){for(let e of t)yield*e}():async function*(){let e=Jt({objectMode:!0});Promise.resolve().then(async()=>{try{await Promise.all(r.map(async n=>{for await(let o of n)e.push(o)})),e.end()}catch(n){e.end(n)}}),yield*e}()}var cn=Ri;function nr(r,...t){if(r==null)throw new Error("Empty pipeline");if(rr(r)){let n=r;r=()=>n.source}else if(ln(r)||un(r)){let n=r;r=()=>n}let e=[r,...t];if(e.length>1&&rr(e[e.length-1])&&(e[e.length-1]=e[e.length-1].sink),e.length>2)for(let n=1;n<e.length-1;n++)rr(e[n])&&(e[n]=Di(e[n]));return Ti(...e)}var Ti=(...r)=>{let t;for(;r.length>0;)t=r.shift()(t);return t},un=r=>r?.[Symbol.asyncIterator]!=null,ln=r=>r?.[Symbol.iterator]!=null,rr=r=>r==null?!1:r.sink!=null&&r.source!=null,Di=r=>t=>{let e=r.sink(t);if(e?.then!=null){let n=Jt({objectMode:!0});e.then(()=>{n.end()},c=>{n.end(c)});let o,i=r.source;if(un(i))o=async function*(){yield*i,n.end()};else if(ln(i))o=function*(){yield*i,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return cn(n,o())}return r.source};var hn="libp2p",fn="autonat",dn="1.0.0";var or=new Float32Array([-0]),Q=new Uint8Array(or.buffer);function pn(r,t,e){or[0]=r,t[e]=Q[0],t[e+1]=Q[1],t[e+2]=Q[2],t[e+3]=Q[3]}function mn(r,t){return Q[0]=r[t],Q[1]=r[t+1],Q[2]=r[t+2],Q[3]=r[t+3],or[0]}var ir=new Float64Array([-0]),T=new Uint8Array(ir.buffer);function gn(r,t,e){ir[0]=r,t[e]=T[0],t[e+1]=T[1],t[e+2]=T[2],t[e+3]=T[3],t[e+4]=T[4],t[e+5]=T[5],t[e+6]=T[6],t[e+7]=T[7]}function bn(r,t){return T[0]=r[t],T[1]=r[t+1],T[2]=r[t+2],T[3]=r[t+3],T[4]=r[t+4],T[5]=r[t+5],T[6]=r[t+6],T[7]=r[t+7],ir[0]}var Fi=BigInt(Number.MAX_SAFE_INTEGER),Ni=BigInt(Number.MIN_SAFE_INTEGER),U=class r{lo;hi;constructor(t,e){this.lo=t|0,this.hi=e|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(e+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(BigInt(e)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,e=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?e===0?t<16384?t<128?1:2:t<2097152?3:4:e<16384?e<128?5:6:e<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return rt;if(t<Fi&&t>Ni)return this.fromNumber(Number(t));let e=t<0n;e&&(t=-t);let n=t>>32n,o=t-(n<<32n);return e&&(n=~n|0n,o=~o|0n,++o>wn&&(o=0n,++n>wn&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(t){if(t===0)return rt;let e=t<0;e&&(t=-t);let n=t>>>0,o=(t-n)/4294967296>>>0;return e&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new r(n,o)}static from(t){return typeof t=="number"?r.fromNumber(t):typeof t=="bigint"?r.fromBigInt(t):typeof t=="string"?r.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new r(t.low>>>0,t.high>>>0):rt}},rt=new U(0,0);rt.toBigInt=function(){return 0n};rt.zzEncode=rt.zzDecode=function(){return this};rt.length=function(){return 1};var wn=4294967296n;function yn(r){let t=0,e=0;for(let n=0;n<r.length;++n)e=r.charCodeAt(n),e<128?t+=1:e<2048?t+=2:(e&64512)===55296&&(r.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function xn(r,t,e){if(e-t<1)return"";let o,i=[],c=0,u;for(;t<e;)u=r[t++],u<128?i[c++]=u:u>191&&u<224?i[c++]=(u&31)<<6|r[t++]&63:u>239&&u<365?(u=((u&7)<<18|(r[t++]&63)<<12|(r[t++]&63)<<6|r[t++]&63)-65536,i[c++]=55296+(u>>10),i[c++]=56320+(u&1023)):i[c++]=(u&15)<<12|(r[t++]&63)<<6|r[t++]&63,c>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,i)),c=0);return o!=null?(c>0&&o.push(String.fromCharCode.apply(String,i.slice(0,c))),o.join("")):String.fromCharCode.apply(String,i.slice(0,c))}function sr(r,t,e){let n=e,o,i;for(let c=0;c<r.length;++c)o=r.charCodeAt(c),o<128?t[e++]=o:o<2048?(t[e++]=o>>6|192,t[e++]=o&63|128):(o&64512)===55296&&((i=r.charCodeAt(c+1))&64512)===56320?(o=65536+((o&1023)<<10)+(i&1023),++c,t[e++]=o>>18|240,t[e++]=o>>12&63|128,t[e++]=o>>6&63|128,t[e++]=o&63|128):(t[e++]=o>>12|224,t[e++]=o>>6&63|128,t[e++]=o&63|128);return e-n}function C(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function Zt(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var ar=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=t,this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,C(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw C(this,4);return Zt(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw C(this,4);return Zt(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw C(this,4);let t=mn(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw C(this,4);let t=bn(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),e=this.pos,n=this.pos+t;if(n>this.len)throw C(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return xn(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw C(this,t);this.pos+=t}else do if(this.pos>=this.len)throw C(this);while(this.buf[this.pos++]&128);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new U(0,0),e=0;if(this.len-this.pos>4){for(;e<4;++e)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;e=0}else{for(;e<3;++e){if(this.pos>=this.len)throw C(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<e*7)>>>0,t}if(this.len-this.pos>4){for(;e<5;++e)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;e<5;++e){if(this.pos>=this.len)throw C(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw C(this,8);let t=Zt(this.buf,this.pos+=4),e=Zt(this.buf,this.pos+=4);return new U(t,e)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=Me(this.buf,this.pos);return this.pos+=A(t),t}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function cr(r){return new ar(r instanceof Uint8Array?r:r.subarray())}function pt(r,t,e){let n=cr(r);return t.decode(n,void 0,e)}function ur(r){let t=r??8192,e=t>>>1,n,o=t;return function(c){if(c<1||c>e)return L(c);o+c>t&&(n=L(t),o=0);let u=n.subarray(o,o+=c);return o&7&&(o=(o|7)+1),u}}var nt=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function lr(){}var fr=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Ui=ur();function _i(r){return globalThis.Buffer!=null?L(r):Ui(r)}var Ft=class{len;head;tail;states;constructor(){this.len=0,this.head=new nt(lr,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new nt(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new dr((t=t>>>0)<128?1:t<16384?2:t<2097152?3:t<268435456?4:5,t)).len,this}int32(t){return t<0?this._push(Yt,10,U.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=U.fromBigInt(t);return this._push(Yt,e.length(),e)}uint64Number(t){return this._push(Be,A(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let e=U.fromBigInt(t).zzEncode();return this._push(Yt,e.length(),e)}sint64Number(t){let e=U.fromNumber(t).zzEncode();return this._push(Yt,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(hr,1,t?1:0)}fixed32(t){return this._push(Dt,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=U.fromBigInt(t);return this._push(Dt,4,e.lo)._push(Dt,4,e.hi)}fixed64Number(t){let e=U.fromNumber(t);return this._push(Dt,4,e.lo)._push(Dt,4,e.hi)}fixed64String(t){return this.fixed64(BigInt(t))}sfixed64(t){return this.fixed64(t)}sfixed64Number(t){return this.fixed64Number(t)}sfixed64String(t){return this.fixed64String(t)}float(t){return this._push(pn,4,t)}double(t){return this._push(gn,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(hr,1,0):this.uint32(e)._push(ki,e,t)}string(t){let e=yn(t);return e!==0?this.uint32(e)._push(sr,e,t):this._push(hr,1,0)}fork(){return this.states=new fr(this),this.head=this.tail=new nt(lr,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new nt(lr,0,0),this.len=0),this}ldelim(){let t=this.head,e=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=e,this.len+=n),this}finish(){let t=this.head.next,e=_i(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function hr(r,t,e){t[e]=r&255}function Pi(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var dr=class extends nt{next;constructor(t,e){super(Pi,t,e),this.next=void 0}};function Yt(r,t,e){for(;r.hi!==0;)t[e++]=r.lo&127|128,r.lo=(r.lo>>>7|r.hi<<25)>>>0,r.hi>>>=7;for(;r.lo>127;)t[e++]=r.lo&127|128,r.lo=r.lo>>>7;t[e++]=r.lo}function Dt(r,t,e){t[e]=r&255,t[e+1]=r>>>8&255,t[e+2]=r>>>16&255,t[e+3]=r>>>24}function ki(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(Ft.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(Oi,t,r),this},Ft.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(Ci,t,r),this});function Oi(r,t,e){t.set(r,e)}function Ci(r,t,e){r.length<40?sr(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(tt(r),e)}function pr(){return new Ft}function mt(r,t){let e=pr();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var gt;(function(r){r[r.VARINT=0]="VARINT",r[r.BIT64=1]="BIT64",r[r.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",r[r.START_GROUP=3]="START_GROUP",r[r.END_GROUP=4]="END_GROUP",r[r.BIT32=5]="BIT32"})(gt||(gt={}));function te(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function ee(r){function t(o){if(r[o.toString()]==null)throw new Error("Invalid enum value");return r[o]}let e=function(i,c){let u=t(i);c.int32(u)},n=function(i){let c=i.int32();return t(c)};return te("enum",gt.VARINT,e,n)}function bt(r,t){return te("message",gt.LENGTH_DELIMITED,r,t)}var b;(function(r){let t;(function(s){s.DIAL="DIAL",s.DIAL_RESPONSE="DIAL_RESPONSE"})(t=r.MessageType||(r.MessageType={}));let e;(function(s){s[s.DIAL=0]="DIAL",s[s.DIAL_RESPONSE=1]="DIAL_RESPONSE"})(e||(e={})),function(s){s.codec=()=>ee(e)}(t=r.MessageType||(r.MessageType={}));let n;(function(s){s.OK="OK",s.E_DIAL_ERROR="E_DIAL_ERROR",s.E_DIAL_REFUSED="E_DIAL_REFUSED",s.E_BAD_REQUEST="E_BAD_REQUEST",s.E_INTERNAL_ERROR="E_INTERNAL_ERROR"})(n=r.ResponseStatus||(r.ResponseStatus={}));let o;(function(s){s[s.OK=0]="OK",s[s.E_DIAL_ERROR=100]="E_DIAL_ERROR",s[s.E_DIAL_REFUSED=101]="E_DIAL_REFUSED",s[s.E_BAD_REQUEST=200]="E_BAD_REQUEST",s[s.E_INTERNAL_ERROR=300]="E_INTERNAL_ERROR"})(o||(o={})),function(s){s.codec=()=>ee(o)}(n=r.ResponseStatus||(r.ResponseStatus={}));let i;(function(s){let l;s.codec=()=>(l==null&&(l=bt((a,h,p={})=>{if(p.lengthDelimited!==!1&&h.fork(),a.id!=null&&(h.uint32(10),h.bytes(a.id)),a.addrs!=null)for(let d of a.addrs)h.uint32(18),h.bytes(d);p.lengthDelimited!==!1&&h.ldelim()},(a,h)=>{let p={addrs:[]},d=h==null?a.len:a.pos+h;for(;a.pos<d;){let m=a.uint32();switch(m>>>3){case 1:p.id=a.bytes();break;case 2:p.addrs.push(a.bytes());break;default:a.skipType(m&7);break}}return p})),l),s.encode=a=>mt(a,s.codec()),s.decode=a=>pt(a,s.codec())})(i=r.PeerInfo||(r.PeerInfo={}));let c;(function(s){let l;s.codec=()=>(l==null&&(l=bt((a,h,p={})=>{p.lengthDelimited!==!1&&h.fork(),a.peer!=null&&(h.uint32(10),r.PeerInfo.codec().encode(a.peer,h)),p.lengthDelimited!==!1&&h.ldelim()},(a,h)=>{let p={},d=h==null?a.len:a.pos+h;for(;a.pos<d;){let m=a.uint32();switch(m>>>3){case 1:p.peer=r.PeerInfo.codec().decode(a,a.uint32());break;default:a.skipType(m&7);break}}return p})),l),s.encode=a=>mt(a,s.codec()),s.decode=a=>pt(a,s.codec())})(c=r.Dial||(r.Dial={}));let u;(function(s){let l;s.codec=()=>(l==null&&(l=bt((a,h,p={})=>{p.lengthDelimited!==!1&&h.fork(),a.status!=null&&(h.uint32(8),r.ResponseStatus.codec().encode(a.status,h)),a.statusText!=null&&(h.uint32(18),h.string(a.statusText)),a.addr!=null&&(h.uint32(26),h.bytes(a.addr)),p.lengthDelimited!==!1&&h.ldelim()},(a,h)=>{let p={},d=h==null?a.len:a.pos+h;for(;a.pos<d;){let m=a.uint32();switch(m>>>3){case 1:p.status=r.ResponseStatus.codec().decode(a);break;case 2:p.statusText=a.string();break;case 3:p.addr=a.bytes();break;default:a.skipType(m&7);break}}return p})),l),s.encode=a=>mt(a,s.codec()),s.decode=a=>pt(a,s.codec())})(u=r.DialResponse||(r.DialResponse={}));let f;r.codec=()=>(f==null&&(f=bt((s,l,a={})=>{a.lengthDelimited!==!1&&l.fork(),s.type!=null&&(l.uint32(8),r.MessageType.codec().encode(s.type,l)),s.dial!=null&&(l.uint32(18),r.Dial.codec().encode(s.dial,l)),s.dialResponse!=null&&(l.uint32(26),r.DialResponse.codec().encode(s.dialResponse,l)),a.lengthDelimited!==!1&&l.ldelim()},(s,l)=>{let a={},h=l==null?s.len:s.pos+l;for(;s.pos<h;){let p=s.uint32();switch(p>>>3){case 1:a.type=r.MessageType.codec().decode(s);break;case 2:a.dial=r.Dial.codec().decode(s,s.uint32());break;case 3:a.dialResponse=r.DialResponse.codec().decode(s,s.uint32());break;default:s.skipType(p&7);break}}return a})),f),r.encode=s=>mt(s,r.codec()),r.decode=s=>pt(s,r.codec())})(b||(b={}));var mr=4,re=class{components;startupDelay;refreshInterval;protocol;timeout;maxInboundStreams;maxOutboundStreams;verifyAddressTimeout;started;log;constructor(t,e){this.components=t,this.log=t.logger.forComponent("libp2p:autonat"),this.started=!1,this.protocol=`/${e.protocolPrefix??hn}/${fn}/${dn}`,this.timeout=e.timeout??3e4,this.maxInboundStreams=e.maxInboundStreams??1,this.maxOutboundStreams=e.maxOutboundStreams??1,this.startupDelay=e.startupDelay??5e3,this.refreshInterval=e.refreshInterval??6e4,this._verifyExternalAddresses=this._verifyExternalAddresses.bind(this)}[Symbol.toStringTag]="@libp2p/autonat";isStarted(){return this.started}async start(){this.started||(await this.components.registrar.handle(this.protocol,t=>{this.handleIncomingAutonatStream(t).catch(e=>{this.log.error("error handling incoming autonat stream",e)})},{maxInboundStreams:this.maxInboundStreams,maxOutboundStreams:this.maxOutboundStreams}),this.verifyAddressTimeout=setTimeout(this._verifyExternalAddresses,this.startupDelay),this.started=!0)}async stop(){await this.components.registrar.unhandle(this.protocol),clearTimeout(this.verifyAddressTimeout),this.started=!1}async handleIncomingAutonatStream(t){let e=AbortSignal.timeout(this.timeout),n=()=>{t.stream.abort(new W("handleIncomingAutonatStream timeout",oe))};e.addEventListener("abort",n,{once:!0}),ie(1/0,e);try{let o=this;await nr(t.stream,i=>ft(i),async function*(i){let c=await Ze(i);if(c==null){o.log("no message received"),yield b.encode({type:b.MessageType.DIAL_RESPONSE,dialResponse:{status:b.ResponseStatus.E_BAD_REQUEST,statusText:"No message was sent"}});return}let u;try{u=b.decode(c)}catch(f){o.log.error("could not decode message",f),yield b.encode({type:b.MessageType.DIAL_RESPONSE,dialResponse:{status:b.ResponseStatus.E_BAD_REQUEST,statusText:"Could not decode message"}});return}yield b.encode(await o.handleAutonatMessage(u,t.connection,{signal:e}))},i=>Rt(i),t.stream)}catch(o){this.log.error("error handling incoming autonat stream",o)}finally{e.removeEventListener("abort",n)}}_verifyExternalAddresses(){this.verifyExternalAddresses().catch(t=>{this.log.error("error verifying external address",t)})}async handleAutonatMessage(t,e,n){let o=this.components.addressManager.getAddresses().map(a=>a.toOptions().host),i=t.dial;if(i==null)return this.log.error("dial was missing from message"),{type:b.MessageType.DIAL_RESPONSE,dialResponse:{status:b.ResponseStatus.E_BAD_REQUEST,statusText:"No Dial message found in message"}};let c,u=i.peer;if(u?.id==null)return this.log.error("PeerId missing from message"),{type:b.MessageType.DIAL_RESPONSE,dialResponse:{status:b.ResponseStatus.E_BAD_REQUEST,statusText:"missing peer info"}};try{c=De(u.id)}catch(a){return this.log.error("invalid PeerId",a),{type:b.MessageType.DIAL_RESPONSE,dialResponse:{status:b.ResponseStatus.E_BAD_REQUEST,statusText:"bad peer id"}}}if(this.log("incoming request from %p",c),!e.remotePeer.equals(c))return this.log("target peer %p did not equal sending peer %p",c,e.remotePeer),{type:b.MessageType.DIAL_RESPONSE,dialResponse:{status:b.ResponseStatus.E_BAD_REQUEST,statusText:"peer id mismatch"}};let f=u.addrs.map(a=>lt(a)).filter(a=>{let h=a.toOptions().host===e.remoteAddr.toOptions().host;return this.log.trace("request to dial %a was sent from %a is same host %s",a,e.remoteAddr,h),h}).filter(a=>{let h=a.toOptions().host,p=!(_e(h)??!1);return this.log.trace("host %s was public %s",h,p),p}).filter(a=>{let h=a.toOptions().host,p=!o.includes(h);return this.log.trace("host %s was not our host %s",h,p),p}).filter(a=>{let h=!!this.components.transportManager.dialTransportForMultiaddr(a);return this.log.trace("transport for %a is supported %s",a,h),h}).map(a=>(a.getPeerId()==null&&(a=a.encapsulate(`/p2p/${c.toString()}`)),a));if(f.length===0)return this.log("no valid multiaddrs for %p in message",c),{type:b.MessageType.DIAL_RESPONSE,dialResponse:{status:b.ResponseStatus.E_DIAL_REFUSED,statusText:"no dialable addresses"}};this.log("dial multiaddrs %s for peer %p",f.map(a=>a.toString()).join(", "),c);let s="",l=f[0];for await(let a of f){let h;l=a;try{if(h=await this.components.connectionManager.openConnection(a,n),!h.remoteAddr.equals(a))throw this.log.error("tried to dial %a but dialed %a",a,h.remoteAddr),new Error("Unexpected remote address");return this.log("Success %p",c),{type:b.MessageType.DIAL_RESPONSE,dialResponse:{status:b.ResponseStatus.OK,addr:h.remoteAddr.decapsulateCode(y("p2p").code).bytes}}}catch(p){this.log("could not dial %p",c,p),s=p.message}finally{h!=null&&await h.close()}}return{type:b.MessageType.DIAL_RESPONSE,dialResponse:{status:b.ResponseStatus.E_DIAL_ERROR,statusText:s,addr:l.bytes}}}async verifyExternalAddresses(){if(clearTimeout(this.verifyAddressTimeout),!this.isStarted())return;let t=this.components.addressManager,e=t.getObservedAddrs().filter(i=>{let c=i.toOptions();return!(_e(c.host)??!1)});if(e.length===0){this.log("no public addresses found, not requesting verification"),this.verifyAddressTimeout=setTimeout(this._verifyExternalAddresses,this.refreshInterval);return}let n=AbortSignal.timeout(this.timeout);ie(1/0,n);let o=this;try{this.log("verify multiaddrs %s",e.map(s=>s.toString()).join(", "));let i=b.encode({type:b.MessageType.DIAL,dial:{peer:{id:this.components.peerId.toBytes(),addrs:e.map(s=>s.bytes)}}}),c={},u=[],f=async s=>{let l=()=>{};try{this.log("asking %p to verify multiaddr",s.id);let a=await o.components.connectionManager.openConnection(s.id,{signal:n}),h=await a.newStream(this.protocol,{signal:n});l=()=>{h.abort(new W("verifyAddress timeout",oe))},n.addEventListener("abort",l,{once:!0});let p=await nr([i],m=>Rt(m),h,m=>ft(m),async m=>Ze(m));if(p==null){this.log("no response received from %p",a.remotePeer);return}let d=b.decode(p);if(d.type!==b.MessageType.DIAL_RESPONSE||d.dialResponse==null){this.log("invalid autonat response from %p",a.remotePeer);return}if(d.dialResponse.status===b.ResponseStatus.OK){let m=a.remoteAddr.toOptions(),g;if(m.family===4)g=m.host.split(".")[0];else if(m.family===6)g=m.host.split(":")[0];else{this.log('remote address "%s" was not IP4 or IP6?',m.host);return}if(u.includes(g)){this.log("already have response from network segment %d - %s",g,m.host);return}u.push(g)}return d.dialResponse}catch(a){this.log.error("error asking remote to verify multiaddr",a)}finally{n.removeEventListener("abort",l)}};for await(let s of tr(an(this.components.randomWalk.walk({signal:n}),l=>async()=>f(l)),{concurrency:mr}))try{if(s==null)continue;let l=s.addr==null?e[0]:lt(s.addr);if(this.log("autonat response for %a is %s",l,s.status),s.status===b.ResponseStatus.E_BAD_REQUEST||s.status===b.ResponseStatus.E_DIAL_REFUSED||s.addr==null&&e.length>1)continue;if(!e.some(h=>h.equals(l))){this.log("peer reported %a as %s but it was not in our observed address list",l,s.status);continue}let a=l.toString();if(c[a]==null&&(c[a]={success:0,failure:0}),s.status===b.ResponseStatus.OK?c[a].success++:s.status===b.ResponseStatus.E_DIAL_ERROR&&c[a].failure++,c[a].success===mr){this.log("%a is externally dialable",l),t.confirmObservedAddr(l);return}if(c[a].failure===mr){this.log("%a is not externally dialable",l),t.removeObservedAddr(l);return}}catch(l){this.log.error("could not verify external address",l)}}finally{this.verifyAddressTimeout=setTimeout(this._verifyExternalAddresses,this.refreshInterval)}}};function Gi(r={}){return t=>new re(t,r)}return Dn(qi);})();
|
|
2
|
+
"use strict";var Libp2PAutonat=(()=>{var Si=Object.create;var We=Object.defineProperty;var Ii=Object.getOwnPropertyDescriptor;var Bi=Object.getOwnPropertyNames;var Li=Object.getPrototypeOf,Ti=Object.prototype.hasOwnProperty;var Ri=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),ht=(r,t)=>{for(var e in t)We(r,e,{get:t[e],enumerable:!0})},Do=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Bi(t))!Ti.call(r,o)&&o!==e&&We(r,o,{get:()=>t[o],enumerable:!(n=Ii(t,o))||n.enumerable});return r};var _i=(r,t,e)=>(e=r!=null?Si(Li(r)):{},Do(t||!r||!r.__esModule?We(e,"default",{value:r,enumerable:!0}):e,r)),Di=r=>Do(We({},"__esModule",{value:!0}),r);var Gs=Ri(je=>{(function(){var r,t,e,n,o,s,i,u;u=function(f){var a,l,c,d;return a=(f&255<<24)>>>24,l=(f&255<<16)>>>16,c=(f&65280)>>>8,d=f&255,[a,l,c,d].join(".")},i=function(f){var a,l,c,d,y,m;for(a=[],c=d=0;d<=3&&f.length!==0;c=++d){if(c>0){if(f[0]!==".")throw new Error("Invalid IP");f=f.substring(1)}m=t(f),y=m[0],l=m[1],f=f.substring(l),a.push(y)}if(f.length!==0)throw new Error("Invalid IP");switch(a.length){case 1:if(a[0]>4294967295)throw new Error("Invalid IP");return a[0]>>>0;case 2:if(a[0]>255||a[1]>16777215)throw new Error("Invalid IP");return(a[0]<<24|a[1])>>>0;case 3:if(a[0]>255||a[1]>255||a[2]>65535)throw new Error("Invalid IP");return(a[0]<<24|a[1]<<16|a[2])>>>0;case 4:if(a[0]>255||a[1]>255||a[2]>255||a[3]>255)throw new Error("Invalid IP");return(a[0]<<24|a[1]<<16|a[2]<<8|a[3])>>>0;default:throw new Error("Invalid IP")}},e=function(f){return f.charCodeAt(0)},n=e("0"),s=e("a"),o=e("A"),t=function(f){var a,l,c,d,y;for(d=0,a=10,l="9",c=0,f.length>1&&f[c]==="0"&&(f[c+1]==="x"||f[c+1]==="X"?(c+=2,a=16):"0"<=f[c+1]&&f[c+1]<="9"&&(c++,a=8,l="7")),y=c;c<f.length;){if("0"<=f[c]&&f[c]<=l)d=d*a+(e(f[c])-n)>>>0;else if(a===16)if("a"<=f[c]&&f[c]<="f")d=d*a+(10+e(f[c])-s)>>>0;else if("A"<=f[c]&&f[c]<="F")d=d*a+(10+e(f[c])-o)>>>0;else break;else break;if(d>4294967295)throw new Error("too large");c++}if(c===y)throw new Error("empty octet");return[d,c]},r=function(){function f(a,l){var c,d,y,m;if(typeof a!="string")throw new Error("Missing `net' parameter");if(l||(m=a.split("/",2),a=m[0],l=m[1]),l||(l=32),typeof l=="string"&&l.indexOf(".")>-1){try{this.maskLong=i(l)}catch(p){throw c=p,new Error("Invalid mask: "+l)}for(d=y=32;y>=0;d=--y)if(this.maskLong===4294967295<<32-d>>>0){this.bitmask=d;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=(i(a)&this.maskLong)>>>0}catch(p){throw c=p,new Error("Invalid net address: "+a)}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(a){return typeof a=="string"&&(a.indexOf("/")>0||a.split(".").length!==4)&&(a=new f(a)),a instanceof f?this.contains(a.base)&&this.contains(a.broadcast||a.last):(i(a)&this.maskLong)>>>0===(this.netLong&this.maskLong)>>>0},f.prototype.next=function(a){return a==null&&(a=1),new f(u(this.netLong+this.size*a),this.mask)},f.prototype.forEach=function(a){var l,c,d;for(d=i(this.first),c=i(this.last),l=0;d<=c;)a(u(d),d,l),l++,d++},f.prototype.toString=function(){return this.base+"/"+this.bitmask},f}(),je.ip2long=i,je.long2ip=u,je.Netmask=r}).call(je)});var cf={};ht(cf,{autoNAT:()=>af});var zr=Symbol.for("@libp2p/peer-id");var De=class extends Error{static name="AbortError";constructor(t="The operation was aborted"){super(t),this.name="AbortError"}};var Ue=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},Qe=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var Je=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var Ne=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var Vr=(r,...t)=>{try{[...t]}catch{}};var Xr={};ht(Xr,{base58btc:()=>Y,base58flickr:()=>ki});var hf=new Uint8Array(0);function Uo(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 Bt(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 No(r){return new TextEncoder().encode(r)}function Po(r){return new TextDecoder().decode(r)}function Ui(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 s=r.charAt(o),i=s.charCodeAt(0);if(e[i]!==255)throw new TypeError(s+" is ambiguous");e[i]=o}var u=r.length,f=r.charAt(0),a=Math.log(u)/Math.log(256),l=Math.log(256)/Math.log(u);function c(m){if(m instanceof Uint8Array||(ArrayBuffer.isView(m)?m=new Uint8Array(m.buffer,m.byteOffset,m.byteLength):Array.isArray(m)&&(m=Uint8Array.from(m))),!(m instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(m.length===0)return"";for(var p=0,h=0,w=0,v=m.length;w!==v&&m[w]===0;)w++,p++;for(var b=(v-w)*l+1>>>0,S=new Uint8Array(b);w!==v;){for(var D=m[w],_=0,I=b-1;(D!==0||_<h)&&I!==-1;I--,_++)D+=256*S[I]>>>0,S[I]=D%u>>>0,D=D/u>>>0;if(D!==0)throw new Error("Non-zero carry");h=_,w++}for(var B=b-h;B!==b&&S[B]===0;)B++;for(var R=f.repeat(p);B<b;++B)R+=r.charAt(S[B]);return R}function d(m){if(typeof m!="string")throw new TypeError("Expected String");if(m.length===0)return new Uint8Array;var p=0;if(m[p]!==" "){for(var h=0,w=0;m[p]===f;)h++,p++;for(var v=(m.length-p)*a+1>>>0,b=new Uint8Array(v);m[p];){var S=e[m.charCodeAt(p)];if(S===255)return;for(var D=0,_=v-1;(S!==0||D<w)&&_!==-1;_--,D++)S+=u*b[_]>>>0,b[_]=S%256>>>0,S=S/256>>>0;if(S!==0)throw new Error("Non-zero carry");w=D,p++}if(m[p]!==" "){for(var I=v-w;I!==v&&b[I]===0;)I++;for(var B=new Uint8Array(h+(v-I)),R=h;I!==v;)B[R++]=b[I++];return B}}}function y(m){var p=d(m);if(p)return p;throw new Error(`Non-${t} character`)}return{encode:c,decodeUnsafe:d,decode:y}}var Ni=Ui,Pi=Ni,Co=Pi;var $r=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")}},Gr=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 ko(this,t)}},Zr=class{decoders;constructor(t){this.decoders=t}or(t){return ko(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 ko(r,t){return new Zr({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var jr=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 $r(t,e,n),this.decoder=new Gr(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function de({name:r,prefix:t,encode:e,decode:n}){return new jr(r,t,e,n)}function Kt({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=Co(e,r);return de({prefix:t,name:r,encode:n,decode:s=>Bt(o(s))})}function Oi(r,t,e,n){let o={};for(let l=0;l<t.length;++l)o[t[l]]=l;let s=r.length;for(;r[s-1]==="=";)--s;let i=new Uint8Array(s*e/8|0),u=0,f=0,a=0;for(let l=0;l<s;++l){let c=o[r[l]];if(c===void 0)throw new SyntaxError(`Non-${n} character`);f=f<<e|c,u+=e,u>=8&&(u-=8,i[a++]=255&f>>u)}if(u>=e||255&f<<8-u)throw new SyntaxError("Unexpected end of data");return i}function Ci(r,t,e){let n=t[t.length-1]==="=",o=(1<<e)-1,s="",i=0,u=0;for(let f=0;f<r.length;++f)for(u=u<<8|r[f],i+=8;i>e;)i-=e,s+=t[o&u>>i];if(i!==0&&(s+=t[o&u<<e-i]),n)for(;s.length*e&7;)s+="=";return s}function j({name:r,prefix:t,bitsPerChar:e,alphabet:n}){return de({prefix:t,name:r,encode(o){return Ci(o,n,e)},decode(o){return Oi(o,n,e,r)}})}var Y=Kt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),ki=Kt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Yr={};ht(Yr,{base32:()=>Lt,base32hex:()=>Ki,base32hexpad:()=>zi,base32hexpadupper:()=>Vi,base32hexupper:()=>qi,base32pad:()=>Mi,base32padupper:()=>Hi,base32upper:()=>Fi,base32z:()=>$i});var Lt=j({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Fi=j({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Mi=j({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Hi=j({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Ki=j({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),qi=j({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),zi=j({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Vi=j({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),$i=j({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Gi=Ho,Fo=128,Zi=127,ji=~Zi,Xi=Math.pow(2,31);function Ho(r,t,e){t=t||[],e=e||0;for(var n=e;r>=Xi;)t[e++]=r&255|Fo,r/=128;for(;r&ji;)t[e++]=r&255|Fo,r>>>=7;return t[e]=r|0,Ho.bytes=e-n+1,t}var Yi=Wr,Wi=128,Mo=127;function Wr(r,n){var e=0,n=n||0,o=0,s=n,i,u=r.length;do{if(s>=u)throw Wr.bytes=0,new RangeError("Could not decode varint");i=r[s++],e+=o<28?(i&Mo)<<o:(i&Mo)*Math.pow(2,o),o+=7}while(i>=Wi);return Wr.bytes=s-n,e}var Qi=Math.pow(2,7),Ji=Math.pow(2,14),ta=Math.pow(2,21),ea=Math.pow(2,28),ra=Math.pow(2,35),na=Math.pow(2,42),oa=Math.pow(2,49),sa=Math.pow(2,56),ia=Math.pow(2,63),aa=function(r){return r<Qi?1:r<Ji?2:r<ta?3:r<ea?4:r<ra?5:r<na?6:r<oa?7:r<sa?8:r<ia?9:10},ca={encode:Gi,decode:Yi,encodingLength:aa},ua=ca,Pe=ua;function Oe(r,t=0){return[Pe.decode(r,t),Pe.decode.bytes]}function he(r,t,e=0){return Pe.encode(r,t,e),t}function pe(r){return Pe.encodingLength(r)}function te(r,t){let e=t.byteLength,n=pe(r),o=n+pe(e),s=new Uint8Array(o+e);return he(r,s,0),he(e,s,n),s.set(t,o),new me(r,e,t,s)}function ee(r){let t=Bt(r),[e,n]=Oe(t),[o,s]=Oe(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new me(e,o,i,t)}function Ko(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&Uo(r.bytes,e.bytes)}}var me=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=n,this.bytes=o}};function qo(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return la(e,Qr(r),t??Y.encoder);default:return da(e,Qr(r),t??Lt.encoder)}}var zo=new WeakMap;function Qr(r){let t=zo.get(r);if(t==null){let e=new Map;return zo.set(r,e),e}return t}var lt=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!==Ce)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==ha)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=te(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&&Ko(t.multihash,n.multihash)}toString(t){return qo(this,t)}toJSON(){return{"/":qo(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:s,bytes:i}=e;return new r(n,o,s,i??Vo(n,o,s.bytes))}else if(e[pa]===!0){let{version:n,multihash:o,code:s}=e,i=ee(o);return r.create(n,s,i)}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!==Ce)throw new Error(`Version 0 CID must use dag-pb (code: ${Ce}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=Vo(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,Ce,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=Bt(t.subarray(n,n+e.multihashSize));if(o.byteLength!==e.multihashSize)throw new Error("Incorrect length");let s=o.subarray(e.multihashSize-e.digestSize),i=new me(e.multihashCode,e.digestSize,s,o);return[e.version===0?r.createV0(i):r.createV1(e.codec,i),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[c,d]=Oe(t.subarray(e));return e+=d,c},o=n(),s=Ce;if(o===18?(o=0,e=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=e,u=n(),f=n(),a=e+f,l=a-i;return{version:o,codec:s,multihashCode:u,digestSize:f,multihashSize:l,size:a}}static parse(t,e){let[n,o]=fa(t,e),s=r.decode(o);if(s.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Qr(s).set(n,t),s}};function fa(r,t){switch(r[0]){case"Q":{let e=t??Y;return[Y.prefix,e.decode(`${Y.prefix}${r}`)]}case Y.prefix:{let e=t??Y;return[Y.prefix,e.decode(r)]}case Lt.prefix:{let e=t??Lt;return[Lt.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 la(r,t,e){let{prefix:n}=e;if(n!==Y.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let o=t.get(n);if(o==null){let s=e.encode(r).slice(1);return t.set(n,s),s}else return o}function da(r,t,e){let{prefix:n}=e,o=t.get(n);if(o==null){let s=e.encode(r);return t.set(n,s),s}else return o}var Ce=112,ha=18;function Vo(r,t,e){let n=pe(r),o=n+pe(t),s=new Uint8Array(o+e.byteLength);return he(r,s,0),he(t,s,n),s.set(e,o),s}var pa=Symbol.for("@ipld/js-cid/CID");var Jr={};ht(Jr,{identity:()=>Tt});var $o=0,ma="identity",Go=Bt;function ga(r){return te($o,Go(r))}var Tt={code:$o,name:ma,encode:Go,digest:ga};function xt(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 Zo(r){if(!Number.isSafeInteger(r)||r<0)throw new Error(`positive integer expected, not ${r}`)}function ya(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function ge(r,...t){if(!ya(r))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(r.length))throw new Error(`Uint8Array expected of length ${t}, not of length=${r.length}`)}function jo(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");Zo(r.outputLen),Zo(r.blockLen)}function ye(r,t=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(t&&r.finished)throw new Error("Hash#digest() has already been called")}function Xo(r,t){ge(r);let e=t.outputLen;if(r.length<e)throw new Error(`digestInto() expects output buffer of length at least ${e}`)}var re=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;var er=r=>new DataView(r.buffer,r.byteOffset,r.byteLength),wt=(r,t)=>r<<32-t|r>>>t;var Pf=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function Yo(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function ke(r){return typeof r=="string"&&(r=Yo(r)),ge(r),r}function tn(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];ge(o),t+=o.length}let e=new Uint8Array(t);for(let n=0,o=0;n<r.length;n++){let s=r[n];e.set(s,o),o+=s.length}return e}var be=class{clone(){return this._cloneInto()}},Of={}.toString;function rr(r){let t=n=>r().update(ke(n)).digest(),e=r();return t.outputLen=e.outputLen,t.blockLen=e.blockLen,t.create=()=>r(),t}function nr(r=32){if(re&&typeof re.getRandomValues=="function")return re.getRandomValues(new Uint8Array(r));if(re&&typeof re.randomBytes=="function")return re.randomBytes(r);throw new Error("crypto.getRandomValues must be defined")}function ba(r,t,e,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(t,e,n);let o=BigInt(32),s=BigInt(4294967295),i=Number(e>>o&s),u=Number(e&s),f=n?4:0,a=n?0:4;r.setUint32(t+f,i,n),r.setUint32(t+a,u,n)}var Wo=(r,t,e)=>r&t^~r&e,Qo=(r,t,e)=>r&t^r&e^t&e,xe=class extends be{constructor(t,e,n,o){super(),this.blockLen=t,this.outputLen=e,this.padOffset=n,this.isLE=o,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=er(this.buffer)}update(t){ye(this);let{view:e,buffer:n,blockLen:o}=this;t=ke(t);let s=t.length;for(let i=0;i<s;){let u=Math.min(o-this.pos,s-i);if(u===o){let f=er(t);for(;o<=s-i;i+=o)this.process(f,i);continue}n.set(t.subarray(i,i+u),this.pos),this.pos+=u,i+=u,this.pos===o&&(this.process(e,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){ye(this),Xo(t,this),this.finished=!0;let{buffer:e,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;e[i++]=128,this.buffer.subarray(i).fill(0),this.padOffset>o-i&&(this.process(n,0),i=0);for(let c=i;c<o;c++)e[c]=0;ba(n,o-8,BigInt(this.length*8),s),this.process(n,0);let u=er(t),f=this.outputLen;if(f%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let a=f/4,l=this.get();if(a>l.length)throw new Error("_sha2: outputLen bigger than state");for(let c=0;c<a;c++)u.setUint32(4*c,l[c],s)}digest(){let{buffer:t,outputLen:e}=this;this.digestInto(t);let n=t.slice(0,e);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());let{blockLen:e,buffer:n,length:o,finished:s,destroyed:i,pos:u}=this;return t.length=o,t.pos=u,t.finished=s,t.destroyed=i,o%e&&t.buffer.set(n),t}};var or=BigInt(4294967295),en=BigInt(32);function Jo(r,t=!1){return t?{h:Number(r&or),l:Number(r>>en&or)}:{h:Number(r>>en&or)|0,l:Number(r&or)|0}}function xa(r,t=!1){let e=new Uint32Array(r.length),n=new Uint32Array(r.length);for(let o=0;o<r.length;o++){let{h:s,l:i}=Jo(r[o],t);[e[o],n[o]]=[s,i]}return[e,n]}var wa=(r,t)=>BigInt(r>>>0)<<en|BigInt(t>>>0),Ea=(r,t,e)=>r>>>e,va=(r,t,e)=>r<<32-e|t>>>e,Aa=(r,t,e)=>r>>>e|t<<32-e,Sa=(r,t,e)=>r<<32-e|t>>>e,Ia=(r,t,e)=>r<<64-e|t>>>e-32,Ba=(r,t,e)=>r>>>e-32|t<<64-e,La=(r,t)=>t,Ta=(r,t)=>r,Ra=(r,t,e)=>r<<e|t>>>32-e,_a=(r,t,e)=>t<<e|r>>>32-e,Da=(r,t,e)=>t<<e-32|r>>>64-e,Ua=(r,t,e)=>r<<e-32|t>>>64-e;function Na(r,t,e,n){let o=(t>>>0)+(n>>>0);return{h:r+e+(o/2**32|0)|0,l:o|0}}var Pa=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),Oa=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,Ca=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),ka=(r,t,e,n,o)=>t+e+n+o+(r/2**32|0)|0,Fa=(r,t,e,n,o)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(o>>>0),Ma=(r,t,e,n,o,s)=>t+e+n+o+s+(r/2**32|0)|0;var Ha={fromBig:Jo,split:xa,toBig:wa,shrSH:Ea,shrSL:va,rotrSH:Aa,rotrSL:Sa,rotrBH:Ia,rotrBL:Ba,rotr32H:La,rotr32L:Ta,rotlSH:Ra,rotlSL:_a,rotlBH:Da,rotlBL:Ua,add:Na,add3L:Pa,add3H:Oa,add4L:Ca,add4H:ka,add5H:Ma,add5L:Fa},P=Ha;var[Ka,qa]=P.split(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(r=>BigInt(r))),zt=new Uint32Array(80),Vt=new Uint32Array(80),rn=class extends xe{constructor(){super(128,64,16,!1),this.Ah=1779033703,this.Al=-205731576,this.Bh=-1150833019,this.Bl=-2067093701,this.Ch=1013904242,this.Cl=-23791573,this.Dh=-1521486534,this.Dl=1595750129,this.Eh=1359893119,this.El=-1377402159,this.Fh=-1694144372,this.Fl=725511199,this.Gh=528734635,this.Gl=-79577749,this.Hh=1541459225,this.Hl=327033209}get(){let{Ah:t,Al:e,Bh:n,Bl:o,Ch:s,Cl:i,Dh:u,Dl:f,Eh:a,El:l,Fh:c,Fl:d,Gh:y,Gl:m,Hh:p,Hl:h}=this;return[t,e,n,o,s,i,u,f,a,l,c,d,y,m,p,h]}set(t,e,n,o,s,i,u,f,a,l,c,d,y,m,p,h){this.Ah=t|0,this.Al=e|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=u|0,this.Dl=f|0,this.Eh=a|0,this.El=l|0,this.Fh=c|0,this.Fl=d|0,this.Gh=y|0,this.Gl=m|0,this.Hh=p|0,this.Hl=h|0}process(t,e){for(let b=0;b<16;b++,e+=4)zt[b]=t.getUint32(e),Vt[b]=t.getUint32(e+=4);for(let b=16;b<80;b++){let S=zt[b-15]|0,D=Vt[b-15]|0,_=P.rotrSH(S,D,1)^P.rotrSH(S,D,8)^P.shrSH(S,D,7),I=P.rotrSL(S,D,1)^P.rotrSL(S,D,8)^P.shrSL(S,D,7),B=zt[b-2]|0,R=Vt[b-2]|0,W=P.rotrSH(B,R,19)^P.rotrBH(B,R,61)^P.shrSH(B,R,6),H=P.rotrSL(B,R,19)^P.rotrBL(B,R,61)^P.shrSL(B,R,6),O=P.add4L(I,H,Vt[b-7],Vt[b-16]),Q=P.add4H(O,_,W,zt[b-7],zt[b-16]);zt[b]=Q|0,Vt[b]=O|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:u,Cl:f,Dh:a,Dl:l,Eh:c,El:d,Fh:y,Fl:m,Gh:p,Gl:h,Hh:w,Hl:v}=this;for(let b=0;b<80;b++){let S=P.rotrSH(c,d,14)^P.rotrSH(c,d,18)^P.rotrBH(c,d,41),D=P.rotrSL(c,d,14)^P.rotrSL(c,d,18)^P.rotrBL(c,d,41),_=c&y^~c&p,I=d&m^~d&h,B=P.add5L(v,D,I,qa[b],Vt[b]),R=P.add5H(B,w,S,_,Ka[b],zt[b]),W=B|0,H=P.rotrSH(n,o,28)^P.rotrBH(n,o,34)^P.rotrBH(n,o,39),O=P.rotrSL(n,o,28)^P.rotrBL(n,o,34)^P.rotrBL(n,o,39),Q=n&s^n&u^s&u,A=o&i^o&f^i&f;w=p|0,v=h|0,p=y|0,h=m|0,y=c|0,m=d|0,{h:c,l:d}=P.add(a|0,l|0,R|0,W|0),a=u|0,l=f|0,u=s|0,f=i|0,s=n|0,i=o|0;let L=P.add3L(W,O,A);n=P.add3H(L,R,H,Q),o=L|0}({h:n,l:o}=P.add(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=P.add(this.Bh|0,this.Bl|0,s|0,i|0),{h:u,l:f}=P.add(this.Ch|0,this.Cl|0,u|0,f|0),{h:a,l}=P.add(this.Dh|0,this.Dl|0,a|0,l|0),{h:c,l:d}=P.add(this.Eh|0,this.El|0,c|0,d|0),{h:y,l:m}=P.add(this.Fh|0,this.Fl|0,y|0,m|0),{h:p,l:h}=P.add(this.Gh|0,this.Gl|0,p|0,h|0),{h:w,l:v}=P.add(this.Hh|0,this.Hl|0,w|0,v|0),this.set(n,o,s,i,u,f,a,l,c,d,y,m,p,h,w,v)}roundClean(){zt.fill(0),Vt.fill(0)}destroy(){this.buffer.fill(0),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var ts=rr(()=>new rn);var ir={};ht(ir,{aInRange:()=>pt,abool:()=>Et,abytes:()=>we,bitGet:()=>ja,bitLen:()=>cn,bitMask:()=>Me,bitSet:()=>Xa,bytesToHex:()=>_t,bytesToNumberBE:()=>Dt,bytesToNumberLE:()=>Gt,concatBytes:()=>Ut,createHmacDrbg:()=>un,ensureBytes:()=>X,equalBytes:()=>Ga,hexToBytes:()=>oe,hexToNumber:()=>an,inRange:()=>Fe,isBytes:()=>$t,memoized:()=>ie,notImplemented:()=>Wa,numberToBytesBE:()=>Zt,numberToBytesLE:()=>se,numberToHexUnpadded:()=>ne,numberToVarBytesBE:()=>$a,utf8ToBytes:()=>Za,validateObject:()=>St});var sn=BigInt(0),sr=BigInt(1),za=BigInt(2);function $t(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function we(r){if(!$t(r))throw new Error("Uint8Array expected")}function Et(r,t){if(typeof t!="boolean")throw new Error(`${r} must be valid boolean, got "${t}".`)}var Va=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function _t(r){we(r);let t="";for(let e=0;e<r.length;e++)t+=Va[r[e]];return t}function ne(r){let t=r.toString(16);return t.length&1?`0${t}`:t}function an(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return BigInt(r===""?"0":`0x${r}`)}var Rt={_0:48,_9:57,_A:65,_F:70,_a:97,_f:102};function es(r){if(r>=Rt._0&&r<=Rt._9)return r-Rt._0;if(r>=Rt._A&&r<=Rt._F)return r-(Rt._A-10);if(r>=Rt._a&&r<=Rt._f)return r-(Rt._a-10)}function oe(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);let t=r.length,e=t/2;if(t%2)throw new Error("padded hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(e);for(let o=0,s=0;o<e;o++,s+=2){let i=es(r.charCodeAt(s)),u=es(r.charCodeAt(s+1));if(i===void 0||u===void 0){let f=r[s]+r[s+1];throw new Error('hex string expected, got non-hex character "'+f+'" at index '+s)}n[o]=i*16+u}return n}function Dt(r){return an(_t(r))}function Gt(r){return we(r),an(_t(Uint8Array.from(r).reverse()))}function Zt(r,t){return oe(r.toString(16).padStart(t*2,"0"))}function se(r,t){return Zt(r,t).reverse()}function $a(r){return oe(ne(r))}function X(r,t,e){let n;if(typeof t=="string")try{n=oe(t)}catch(s){throw new Error(`${r} must be valid hex string, got "${t}". Cause: ${s}`)}else if($t(t))n=Uint8Array.from(t);else throw new Error(`${r} must be hex string or Uint8Array`);let o=n.length;if(typeof e=="number"&&o!==e)throw new Error(`${r} expected ${e} bytes, got ${o}`);return n}function Ut(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];we(o),t+=o.length}let e=new Uint8Array(t);for(let n=0,o=0;n<r.length;n++){let s=r[n];e.set(s,o),o+=s.length}return e}function Ga(r,t){if(r.length!==t.length)return!1;let e=0;for(let n=0;n<r.length;n++)e|=r[n]^t[n];return e===0}function Za(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}var nn=r=>typeof r=="bigint"&&sn<=r;function Fe(r,t,e){return nn(r)&&nn(t)&&nn(e)&&t<=r&&r<e}function pt(r,t,e,n){if(!Fe(t,e,n))throw new Error(`expected valid ${r}: ${e} <= n < ${n}, got ${typeof t} ${t}`)}function cn(r){let t;for(t=0;r>sn;r>>=sr,t+=1);return t}function ja(r,t){return r>>BigInt(t)&sr}function Xa(r,t,e){return r|(e?sr:sn)<<BigInt(t)}var Me=r=>(za<<BigInt(r-1))-sr,on=r=>new Uint8Array(r),rs=r=>Uint8Array.from(r);function un(r,t,e){if(typeof r!="number"||r<2)throw new Error("hashLen must be a number");if(typeof t!="number"||t<2)throw new Error("qByteLen must be a number");if(typeof e!="function")throw new Error("hmacFn must be a function");let n=on(r),o=on(r),s=0,i=()=>{n.fill(1),o.fill(0),s=0},u=(...c)=>e(o,n,...c),f=(c=on())=>{o=u(rs([0]),c),n=u(),c.length!==0&&(o=u(rs([1]),c),n=u())},a=()=>{if(s++>=1e3)throw new Error("drbg: tried 1000 values");let c=0,d=[];for(;c<t;){n=u();let y=n.slice();d.push(y),c+=n.length}return Ut(...d)};return(c,d)=>{i(),f(c);let y;for(;!(y=d(a()));)f();return i(),y}}var Ya={bigint:r=>typeof r=="bigint",function:r=>typeof r=="function",boolean:r=>typeof r=="boolean",string:r=>typeof r=="string",stringOrUint8Array:r=>typeof r=="string"||$t(r),isSafeInteger:r=>Number.isSafeInteger(r),array:r=>Array.isArray(r),field:(r,t)=>t.Fp.isValid(r),hash:r=>typeof r=="function"&&Number.isSafeInteger(r.outputLen)};function St(r,t,e={}){let n=(o,s,i)=>{let u=Ya[s];if(typeof u!="function")throw new Error(`Invalid validator "${s}", expected function`);let f=r[o];if(!(i&&f===void 0)&&!u(f,r))throw new Error(`Invalid param ${String(o)}=${f} (${typeof f}), expected ${s}`)};for(let[o,s]of Object.entries(t))n(o,s,!1);for(let[o,s]of Object.entries(e))n(o,s,!0);return r}var Wa=()=>{throw new Error("not implemented")};function ie(r){let t=new WeakMap;return(e,...n)=>{let o=t.get(e);if(o!==void 0)return o;let s=r(e,...n);return t.set(e,s),s}}var tt=BigInt(0),G=BigInt(1),ae=BigInt(2),Qa=BigInt(3),fn=BigInt(4),ns=BigInt(5),os=BigInt(8),Ja=BigInt(9),tc=BigInt(16);function V(r,t){let e=r%t;return e>=tt?e:t+e}function ec(r,t,e){if(e<=tt||t<tt)throw new Error("Expected power/modulo > 0");if(e===G)return tt;let n=G;for(;t>tt;)t&G&&(n=n*r%e),r=r*r%e,t>>=G;return n}function Z(r,t,e){let n=r;for(;t-- >tt;)n*=n,n%=e;return n}function ar(r,t){if(r===tt||t<=tt)throw new Error(`invert: expected positive integers, got n=${r} mod=${t}`);let e=V(r,t),n=t,o=tt,s=G,i=G,u=tt;for(;e!==tt;){let a=n/e,l=n%e,c=o-i*a,d=s-u*a;n=e,e=l,o=i,s=u,i=c,u=d}if(n!==G)throw new Error("invert: does not exist");return V(o,t)}function rc(r){let t=(r-G)/ae,e,n,o;for(e=r-G,n=0;e%ae===tt;e/=ae,n++);for(o=ae;o<r&&ec(o,t,r)!==r-G;o++);if(n===1){let i=(r+G)/fn;return function(f,a){let l=f.pow(a,i);if(!f.eql(f.sqr(l),a))throw new Error("Cannot find square root");return l}}let s=(e+G)/ae;return function(u,f){if(u.pow(f,t)===u.neg(u.ONE))throw new Error("Cannot find square root");let a=n,l=u.pow(u.mul(u.ONE,o),e),c=u.pow(f,s),d=u.pow(f,e);for(;!u.eql(d,u.ONE);){if(u.eql(d,u.ZERO))return u.ZERO;let y=1;for(let p=u.sqr(d);y<a&&!u.eql(p,u.ONE);y++)p=u.sqr(p);let m=u.pow(l,G<<BigInt(a-y-1));l=u.sqr(m),c=u.mul(c,m),d=u.mul(d,l),a=y}return c}}function nc(r){if(r%fn===Qa){let t=(r+G)/fn;return function(n,o){let s=n.pow(o,t);if(!n.eql(n.sqr(s),o))throw new Error("Cannot find square root");return s}}if(r%os===ns){let t=(r-ns)/os;return function(n,o){let s=n.mul(o,ae),i=n.pow(s,t),u=n.mul(o,i),f=n.mul(n.mul(u,ae),i),a=n.mul(u,n.sub(f,n.ONE));if(!n.eql(n.sqr(a),o))throw new Error("Cannot find square root");return a}}return r%tc,rc(r)}var ss=(r,t)=>(V(r,t)&G)===G,oc=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function ln(r){let t={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},e=oc.reduce((n,o)=>(n[o]="function",n),t);return St(r,e)}function sc(r,t,e){if(e<tt)throw new Error("Expected power > 0");if(e===tt)return r.ONE;if(e===G)return t;let n=r.ONE,o=t;for(;e>tt;)e&G&&(n=r.mul(n,o)),o=r.sqr(o),e>>=G;return n}function ic(r,t){let e=new Array(t.length),n=t.reduce((s,i,u)=>r.is0(i)?s:(e[u]=s,r.mul(s,i)),r.ONE),o=r.inv(n);return t.reduceRight((s,i,u)=>r.is0(i)?s:(e[u]=r.mul(s,e[u]),r.mul(s,i)),o),e}function dn(r,t){let e=t!==void 0?t:r.toString(2).length,n=Math.ceil(e/8);return{nBitLength:e,nByteLength:n}}function jt(r,t,e=!1,n={}){if(r<=tt)throw new Error(`Expected Field ORDER > 0, got ${r}`);let{nBitLength:o,nByteLength:s}=dn(r,t);if(s>2048)throw new Error("Field lengths over 2048 bytes are not supported");let i=nc(r),u=Object.freeze({ORDER:r,BITS:o,BYTES:s,MASK:Me(o),ZERO:tt,ONE:G,create:f=>V(f,r),isValid:f=>{if(typeof f!="bigint")throw new Error(`Invalid field element: expected bigint, got ${typeof f}`);return tt<=f&&f<r},is0:f=>f===tt,isOdd:f=>(f&G)===G,neg:f=>V(-f,r),eql:(f,a)=>f===a,sqr:f=>V(f*f,r),add:(f,a)=>V(f+a,r),sub:(f,a)=>V(f-a,r),mul:(f,a)=>V(f*a,r),pow:(f,a)=>sc(u,f,a),div:(f,a)=>V(f*ar(a,r),r),sqrN:f=>f*f,addN:(f,a)=>f+a,subN:(f,a)=>f-a,mulN:(f,a)=>f*a,inv:f=>ar(f,r),sqrt:n.sqrt||(f=>i(u,f)),invertBatch:f=>ic(u,f),cmov:(f,a,l)=>l?a:f,toBytes:f=>e?se(f,s):Zt(f,s),fromBytes:f=>{if(f.length!==s)throw new Error(`Fp.fromBytes: expected ${s}, got ${f.length}`);return e?Gt(f):Dt(f)}});return Object.freeze(u)}function is(r){if(typeof r!="bigint")throw new Error("field order must be bigint");let t=r.toString(2).length;return Math.ceil(t/8)}function hn(r){let t=is(r);return t+Math.ceil(t/2)}function as(r,t,e=!1){let n=r.length,o=is(t),s=hn(t);if(n<16||n<s||n>1024)throw new Error(`expected ${s}-1024 bytes of input, got ${n}`);let i=e?Dt(r):Gt(r),u=V(i,t-G)+G;return e?se(u,o):Zt(u,o)}var cc=BigInt(0),pn=BigInt(1),mn=new WeakMap,cs=new WeakMap;function cr(r,t){let e=(s,i)=>{let u=i.negate();return s?u:i},n=s=>{if(!Number.isSafeInteger(s)||s<=0||s>t)throw new Error(`Wrong window size=${s}, should be [1..${t}]`)},o=s=>{n(s);let i=Math.ceil(t/s)+1,u=2**(s-1);return{windows:i,windowSize:u}};return{constTimeNegate:e,unsafeLadder(s,i){let u=r.ZERO,f=s;for(;i>cc;)i&pn&&(u=u.add(f)),f=f.double(),i>>=pn;return u},precomputeWindow(s,i){let{windows:u,windowSize:f}=o(i),a=[],l=s,c=l;for(let d=0;d<u;d++){c=l,a.push(c);for(let y=1;y<f;y++)c=c.add(l),a.push(c);l=c.double()}return a},wNAF(s,i,u){let{windows:f,windowSize:a}=o(s),l=r.ZERO,c=r.BASE,d=BigInt(2**s-1),y=2**s,m=BigInt(s);for(let p=0;p<f;p++){let h=p*a,w=Number(u&d);u>>=m,w>a&&(w-=y,u+=pn);let v=h,b=h+Math.abs(w)-1,S=p%2!==0,D=w<0;w===0?c=c.add(e(S,i[v])):l=l.add(e(D,i[b]))}return{p:l,f:c}},wNAFCached(s,i,u){let f=cs.get(s)||1,a=mn.get(s);return a||(a=this.precomputeWindow(s,f),f!==1&&mn.set(s,u(a))),this.wNAF(f,a,i)},setWindowSize(s,i){n(i),cs.set(s,i),mn.delete(s)}}}function ur(r,t,e,n){if(!Array.isArray(e)||!Array.isArray(n)||n.length!==e.length)throw new Error("arrays of points and scalars must have equal length");n.forEach((l,c)=>{if(!t.isValid(l))throw new Error(`wrong scalar at index ${c}`)}),e.forEach((l,c)=>{if(!(l instanceof r))throw new Error(`wrong point at index ${c}`)});let o=cn(BigInt(e.length)),s=o>12?o-3:o>4?o-2:o?2:1,i=(1<<s)-1,u=new Array(i+1).fill(r.ZERO),f=Math.floor((t.BITS-1)/s)*s,a=r.ZERO;for(let l=f;l>=0;l-=s){u.fill(r.ZERO);for(let d=0;d<n.length;d++){let y=n[d],m=Number(y>>BigInt(l)&BigInt(i));u[m]=u[m].add(e[d])}let c=r.ZERO;for(let d=u.length-1,y=r.ZERO;d>0;d--)y=y.add(u[d]),c=c.add(y);if(a=a.add(c),l!==0)for(let d=0;d<s;d++)a=a.double()}return a}function He(r){return ln(r.Fp),St(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...dn(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}var vt=BigInt(0),mt=BigInt(1),fr=BigInt(2),uc=BigInt(8),fc={zip215:!0};function lc(r){let t=He(r);return St(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...t})}function us(r){let t=lc(r),{Fp:e,n,prehash:o,hash:s,randomBytes:i,nByteLength:u,h:f}=t,a=fr<<BigInt(u*8)-mt,l=e.create,c=jt(t.n,t.nBitLength),d=t.uvRatio||((x,g)=>{try{return{isValid:!0,value:e.sqrt(x*e.inv(g))}}catch{return{isValid:!1,value:vt}}}),y=t.adjustScalarBytes||(x=>x),m=t.domain||((x,g,E)=>{if(Et("phflag",E),g.length||E)throw new Error("Contexts/pre-hash are not supported");return x});function p(x,g){pt("coordinate "+x,g,vt,a)}function h(x){if(!(x instanceof b))throw new Error("ExtendedPoint expected")}let w=ie((x,g)=>{let{ex:E,ey:T,ez:U}=x,N=x.is0();g==null&&(g=N?uc:e.inv(U));let C=l(E*g),F=l(T*g),k=l(U*g);if(N)return{x:vt,y:mt};if(k!==mt)throw new Error("invZ was invalid");return{x:C,y:F}}),v=ie(x=>{let{a:g,d:E}=t;if(x.is0())throw new Error("bad point: ZERO");let{ex:T,ey:U,ez:N,et:C}=x,F=l(T*T),k=l(U*U),z=l(N*N),$=l(z*z),et=l(F*g),rt=l(z*l(et+k)),it=l($+l(E*l(F*k)));if(rt!==it)throw new Error("bad point: equation left != right (1)");let ft=l(T*U),J=l(N*C);if(ft!==J)throw new Error("bad point: equation left != right (2)");return!0});class b{constructor(g,E,T,U){this.ex=g,this.ey=E,this.ez=T,this.et=U,p("x",g),p("y",E),p("z",T),p("t",U),Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(g){if(g instanceof b)throw new Error("extended point not allowed");let{x:E,y:T}=g||{};return p("x",E),p("y",T),new b(E,T,mt,l(E*T))}static normalizeZ(g){let E=e.invertBatch(g.map(T=>T.ez));return g.map((T,U)=>T.toAffine(E[U])).map(b.fromAffine)}static msm(g,E){return ur(b,c,g,E)}_setWindowSize(g){_.setWindowSize(this,g)}assertValidity(){v(this)}equals(g){h(g);let{ex:E,ey:T,ez:U}=this,{ex:N,ey:C,ez:F}=g,k=l(E*F),z=l(N*U),$=l(T*F),et=l(C*U);return k===z&&$===et}is0(){return this.equals(b.ZERO)}negate(){return new b(l(-this.ex),this.ey,this.ez,l(-this.et))}double(){let{a:g}=t,{ex:E,ey:T,ez:U}=this,N=l(E*E),C=l(T*T),F=l(fr*l(U*U)),k=l(g*N),z=E+T,$=l(l(z*z)-N-C),et=k+C,rt=et-F,it=k-C,ft=l($*rt),J=l(et*it),dt=l($*it),It=l(rt*et);return new b(ft,J,It,dt)}add(g){h(g);let{a:E,d:T}=t,{ex:U,ey:N,ez:C,et:F}=this,{ex:k,ey:z,ez:$,et}=g;if(E===BigInt(-1)){let So=l((N-U)*(z+k)),Io=l((N+U)*(z-k)),qr=l(Io-So);if(qr===vt)return this.double();let Bo=l(C*fr*et),Lo=l(F*fr*$),To=Lo+Bo,Ro=Io+So,_o=Lo-Bo,wi=l(To*qr),Ei=l(Ro*_o),vi=l(To*_o),Ai=l(qr*Ro);return new b(wi,Ei,Ai,vi)}let rt=l(U*k),it=l(N*z),ft=l(F*T*et),J=l(C*$),dt=l((U+N)*(k+z)-rt-it),It=J-ft,Re=J+ft,_e=l(it-E*rt),gi=l(dt*It),yi=l(Re*_e),bi=l(dt*_e),xi=l(It*Re);return new b(gi,yi,xi,bi)}subtract(g){return this.add(g.negate())}wNAF(g){return _.wNAFCached(this,g,b.normalizeZ)}multiply(g){let E=g;pt("scalar",E,mt,n);let{p:T,f:U}=this.wNAF(E);return b.normalizeZ([T,U])[0]}multiplyUnsafe(g){let E=g;return pt("scalar",E,vt,n),E===vt?D:this.equals(D)||E===mt?this:this.equals(S)?this.wNAF(E).p:_.unsafeLadder(this,E)}isSmallOrder(){return this.multiplyUnsafe(f).is0()}isTorsionFree(){return _.unsafeLadder(this,n).is0()}toAffine(g){return w(this,g)}clearCofactor(){let{h:g}=t;return g===mt?this:this.multiplyUnsafe(g)}static fromHex(g,E=!1){let{d:T,a:U}=t,N=e.BYTES;g=X("pointHex",g,N),Et("zip215",E);let C=g.slice(),F=g[N-1];C[N-1]=F&-129;let k=Gt(C),z=E?a:e.ORDER;pt("pointHex.y",k,vt,z);let $=l(k*k),et=l($-mt),rt=l(T*$-U),{isValid:it,value:ft}=d(et,rt);if(!it)throw new Error("Point.fromHex: invalid y coordinate");let J=(ft&mt)===mt,dt=(F&128)!==0;if(!E&&ft===vt&&dt)throw new Error("Point.fromHex: x=0 and x_0=1");return dt!==J&&(ft=l(-ft)),b.fromAffine({x:ft,y:k})}static fromPrivateKey(g){return R(g).point}toRawBytes(){let{x:g,y:E}=this.toAffine(),T=se(E,e.BYTES);return T[T.length-1]|=g&mt?128:0,T}toHex(){return _t(this.toRawBytes())}}b.BASE=new b(t.Gx,t.Gy,mt,l(t.Gx*t.Gy)),b.ZERO=new b(vt,mt,mt,vt);let{BASE:S,ZERO:D}=b,_=cr(b,u*8);function I(x){return V(x,n)}function B(x){return I(Gt(x))}function R(x){let g=u;x=X("private key",x,g);let E=X("hashed private key",s(x),2*g),T=y(E.slice(0,g)),U=E.slice(g,2*g),N=B(T),C=S.multiply(N),F=C.toRawBytes();return{head:T,prefix:U,scalar:N,point:C,pointBytes:F}}function W(x){return R(x).pointBytes}function H(x=new Uint8Array,...g){let E=Ut(...g);return B(s(m(E,X("context",x),!!o)))}function O(x,g,E={}){x=X("message",x),o&&(x=o(x));let{prefix:T,scalar:U,pointBytes:N}=R(g),C=H(E.context,T,x),F=S.multiply(C).toRawBytes(),k=H(E.context,F,N,x),z=I(C+k*U);pt("signature.s",z,vt,n);let $=Ut(F,se(z,e.BYTES));return X("result",$,u*2)}let Q=fc;function A(x,g,E,T=Q){let{context:U,zip215:N}=T,C=e.BYTES;x=X("signature",x,2*C),g=X("message",g),N!==void 0&&Et("zip215",N),o&&(g=o(g));let F=Gt(x.slice(C,2*C)),k,z,$;try{k=b.fromHex(E,N),z=b.fromHex(x.slice(0,C),N),$=S.multiplyUnsafe(F)}catch{return!1}if(!N&&k.isSmallOrder())return!1;let et=H(U,z.toRawBytes(),k.toRawBytes(),g);return z.add(k.multiplyUnsafe(et)).subtract($).clearCofactor().equals(b.ZERO)}return S._setWindowSize(8),{CURVE:t,getPublicKey:W,sign:O,verify:A,ExtendedPoint:b,utils:{getExtendedPublicKey:R,randomPrivateKey:()=>i(e.BYTES),precompute(x=8,g=b.BASE){return g._setWindowSize(x),g.multiply(BigInt(3)),g}}}}var gn=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),fs=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),ol=BigInt(0),dc=BigInt(1),ls=BigInt(2),sl=BigInt(3),hc=BigInt(5),pc=BigInt(8);function mc(r){let t=BigInt(10),e=BigInt(20),n=BigInt(40),o=BigInt(80),s=gn,u=r*r%s*r%s,f=Z(u,ls,s)*u%s,a=Z(f,dc,s)*r%s,l=Z(a,hc,s)*a%s,c=Z(l,t,s)*l%s,d=Z(c,e,s)*c%s,y=Z(d,n,s)*d%s,m=Z(y,o,s)*y%s,p=Z(m,o,s)*y%s,h=Z(p,t,s)*l%s;return{pow_p_5_8:Z(h,ls,s)*r%s,b2:u}}function gc(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function yc(r,t){let e=gn,n=V(t*t*t,e),o=V(n*n*t,e),s=mc(r*o).pow_p_5_8,i=V(r*n*s,e),u=V(t*i*i,e),f=i,a=V(i*fs,e),l=u===r,c=u===V(-r,e),d=u===V(-r*fs,e);return l&&(i=f),(c||d)&&(i=a),ss(i,e)&&(i=V(-i,e)),{isValid:l||c,value:i}}var bc=jt(gn,void 0,!0),xc={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:bc,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:pc,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:ts,randomBytes:nr,adjustScalarBytes:gc,uvRatio:yc},ds=us(xc);var lr=32;function hs(r,t,e){return ds.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}var dr=class{type="Ed25519";raw;constructor(t){this.raw=yn(t,lr)}toMultihash(){return Tt.digest(hr(this))}toCID(){return lt.createV1(114,this.toMultihash())}toString(){return Y.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:xt(this.raw,t.raw)}verify(t,e){return hs(this.raw,e,t)}};function ms(r){return r=yn(r,lr),new dr(r)}function yn(r,t){if(r=Uint8Array.from(r??[]),r.length!==t)throw new Ue(`Key must be a Uint8Array of length ${t}, got ${r.length}`);return r}function Nt(r=0){return new Uint8Array(r)}function at(r=0){return new Uint8Array(r)}var Ec=Math.pow(2,7),vc=Math.pow(2,14),Ac=Math.pow(2,21),bn=Math.pow(2,28),xn=Math.pow(2,35),wn=Math.pow(2,42),En=Math.pow(2,49),K=128,ct=127;function nt(r){if(r<Ec)return 1;if(r<vc)return 2;if(r<Ac)return 3;if(r<bn)return 4;if(r<xn)return 5;if(r<wn)return 6;if(r<En)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function vn(r,t,e=0){switch(nt(r)){case 8:t[e++]=r&255|K,r/=128;case 7:t[e++]=r&255|K,r/=128;case 6:t[e++]=r&255|K,r/=128;case 5:t[e++]=r&255|K,r/=128;case 4:t[e++]=r&255|K,r>>>=7;case 3:t[e++]=r&255|K,r>>>=7;case 2:t[e++]=r&255|K,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function Sc(r,t,e=0){switch(nt(r)){case 8:t.set(e++,r&255|K),r/=128;case 7:t.set(e++,r&255|K),r/=128;case 6:t.set(e++,r&255|K),r/=128;case 5:t.set(e++,r&255|K),r/=128;case 4:t.set(e++,r&255|K),r>>>=7;case 3:t.set(e++,r&255|K),r>>>=7;case 2:t.set(e++,r&255|K),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function An(r,t){let e=r[t],n=0;if(n+=e&ct,e<K||(e=r[t+1],n+=(e&ct)<<7,e<K)||(e=r[t+2],n+=(e&ct)<<14,e<K)||(e=r[t+3],n+=(e&ct)<<21,e<K)||(e=r[t+4],n+=(e&ct)*bn,e<K)||(e=r[t+5],n+=(e&ct)*xn,e<K)||(e=r[t+6],n+=(e&ct)*wn,e<K)||(e=r[t+7],n+=(e&ct)*En,e<K))return n;throw new RangeError("Could not decode varint")}function Ic(r,t){let e=r.get(t),n=0;if(n+=e&ct,e<K||(e=r.get(t+1),n+=(e&ct)<<7,e<K)||(e=r.get(t+2),n+=(e&ct)<<14,e<K)||(e=r.get(t+3),n+=(e&ct)<<21,e<K)||(e=r.get(t+4),n+=(e&ct)*bn,e<K)||(e=r.get(t+5),n+=(e&ct)*xn,e<K)||(e=r.get(t+6),n+=(e&ct)*wn,e<K)||(e=r.get(t+7),n+=(e&ct)*En,e<K))return n;throw new RangeError("Could not decode varint")}function Xt(r,t,e=0){return t==null&&(t=at(nt(r))),t instanceof Uint8Array?vn(r,t,e):Sc(r,t,e)}function Pt(r,t=0){return r instanceof Uint8Array?An(r,t):Ic(r,t)}var Sn=new Float32Array([-0]),Yt=new Uint8Array(Sn.buffer);function gs(r,t,e){Sn[0]=r,t[e]=Yt[0],t[e+1]=Yt[1],t[e+2]=Yt[2],t[e+3]=Yt[3]}function ys(r,t){return Yt[0]=r[t],Yt[1]=r[t+1],Yt[2]=r[t+2],Yt[3]=r[t+3],Sn[0]}var In=new Float64Array([-0]),ut=new Uint8Array(In.buffer);function bs(r,t,e){In[0]=r,t[e]=ut[0],t[e+1]=ut[1],t[e+2]=ut[2],t[e+3]=ut[3],t[e+4]=ut[4],t[e+5]=ut[5],t[e+6]=ut[6],t[e+7]=ut[7]}function xs(r,t){return ut[0]=r[t],ut[1]=r[t+1],ut[2]=r[t+2],ut[3]=r[t+3],ut[4]=r[t+4],ut[5]=r[t+5],ut[6]=r[t+6],ut[7]=r[t+7],In[0]}var Bc=BigInt(Number.MAX_SAFE_INTEGER),Lc=BigInt(Number.MIN_SAFE_INTEGER),gt=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 ce;if(t<Bc&&t>Lc)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>ws&&(o=0n,++n>ws&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(t){if(t===0)return ce;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):ce}},ce=new gt(0,0);ce.toBigInt=function(){return 0n};ce.zzEncode=ce.zzDecode=function(){return this};ce.length=function(){return 1};var ws=4294967296n;function Es(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 vs(r,t,e){if(e-t<1)return"";let o,s=[],i=0,u;for(;t<e;)u=r[t++],u<128?s[i++]=u:u>191&&u<224?s[i++]=(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,s[i++]=55296+(u>>10),s[i++]=56320+(u&1023)):s[i++]=(u&15)<<12|(r[t++]&63)<<6|r[t++]&63,i>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,s)),i=0);return o!=null?(i>0&&o.push(String.fromCharCode.apply(String,s.slice(0,i))),o.join("")):String.fromCharCode.apply(String,s.slice(0,i))}function Bn(r,t,e){let n=e,o,s;for(let i=0;i<r.length;++i)o=r.charCodeAt(i),o<128?t[e++]=o:o<2048?(t[e++]=o>>6|192,t[e++]=o&63|128):(o&64512)===55296&&((s=r.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,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 At(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function mr(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var Ln=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,At(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 At(this,4);return mr(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw At(this,4);return mr(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw At(this,4);let t=ys(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw At(this,4);let t=xs(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 At(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return vs(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw At(this,t);this.pos+=t}else do if(this.pos>=this.len)throw At(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 gt(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 At(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 At(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 At(this,8);let t=mr(this.buf,this.pos+=4),e=mr(this.buf,this.pos+=4);return new gt(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=An(this.buf,this.pos);return this.pos+=nt(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 Tn(r){return new Ln(r instanceof Uint8Array?r:r.subarray())}function Ot(r,t,e){let n=Tn(r);return t.decode(n,void 0,e)}var Rn={};ht(Rn,{base10:()=>Tc});var Tc=Kt({prefix:"9",name:"base10",alphabet:"0123456789"});var _n={};ht(_n,{base16:()=>Rc,base16upper:()=>_c});var Rc=j({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),_c=j({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Dn={};ht(Dn,{base2:()=>Dc});var Dc=j({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Un={};ht(Un,{base256emoji:()=>Cc});var Ss=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}"),Uc=Ss.reduce((r,t,e)=>(r[e]=t,r),[]),Nc=Ss.reduce((r,t,e)=>(r[t.codePointAt(0)]=e,r),[]);function Pc(r){return r.reduce((t,e)=>(t+=Uc[e],t),"")}function Oc(r){let t=[];for(let e of r){let n=Nc[e.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${e}`);t.push(n)}return new Uint8Array(t)}var Cc=de({prefix:"\u{1F680}",name:"base256emoji",encode:Pc,decode:Oc});var Nn={};ht(Nn,{base36:()=>kc,base36upper:()=>Fc});var kc=Kt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Fc=Kt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Pn={};ht(Pn,{base64:()=>Mc,base64pad:()=>Hc,base64url:()=>Kc,base64urlpad:()=>qc});var Mc=j({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Hc=j({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Kc=j({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),qc=j({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var On={};ht(On,{base8:()=>zc});var zc=j({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Cn={};ht(Cn,{identity:()=>Vc});var Vc=de({prefix:"\0",name:"identity",encode:r=>Po(r),decode:r=>No(r)});var ql=new TextEncoder,zl=new TextDecoder;var Mn={};ht(Mn,{sha256:()=>Ke,sha512:()=>Zc});function Fn({name:r,code:t,encode:e}){return new kn(r,t,e)}var kn=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?te(this.code,e):e.then(n=>te(this.code,n))}else throw Error("Unknown type, must be binary type")}};function Bs(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var Ke=Fn({name:"sha2-256",code:18,encode:Bs("SHA-256")}),Zc=Fn({name:"sha2-512",code:19,encode:Bs("SHA-512")});var qe={...Cn,...Dn,...On,...Rn,..._n,...Yr,...Nn,...Xr,...Pn,...Un},ed={...Mn,...Jr};function Ts(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var Ls=Ts("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Hn=Ts("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=at(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),jc={utf8:Ls,"utf-8":Ls,hex:qe.base16,latin1:Hn,ascii:Hn,binary:Hn,...qe},gr=jc;function Wt(r,t="utf8"){let e=gr[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function Kn(r){let t=r??8192,e=t>>>1,n,o=t;return function(i){if(i<1||i>e)return at(i);o+i>t&&(n=at(t),o=0);let u=n.subarray(o,o+=i);return o&7&&(o=(o|7)+1),u}}var ue=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function qn(){}var Vn=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Xc=Kn();function Yc(r){return globalThis.Buffer!=null?at(r):Xc(r)}var Ve=class{len;head;tail;states;constructor(){this.len=0,this.head=new ue(qn,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new ue(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new $n((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(yr,10,gt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=gt.fromBigInt(t);return this._push(yr,e.length(),e)}uint64Number(t){return this._push(vn,nt(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=gt.fromBigInt(t).zzEncode();return this._push(yr,e.length(),e)}sint64Number(t){let e=gt.fromNumber(t).zzEncode();return this._push(yr,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(zn,1,t?1:0)}fixed32(t){return this._push(ze,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=gt.fromBigInt(t);return this._push(ze,4,e.lo)._push(ze,4,e.hi)}fixed64Number(t){let e=gt.fromNumber(t);return this._push(ze,4,e.lo)._push(ze,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(gs,4,t)}double(t){return this._push(bs,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(zn,1,0):this.uint32(e)._push(Qc,e,t)}string(t){let e=Es(t);return e!==0?this.uint32(e)._push(Bn,e,t):this._push(zn,1,0)}fork(){return this.states=new Vn(this),this.head=this.tail=new ue(qn,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 ue(qn,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=Yc(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function zn(r,t,e){t[e]=r&255}function Wc(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var $n=class extends ue{next;constructor(t,e){super(Wc,t,e),this.next=void 0}};function yr(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 ze(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 Qc(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(Ve.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(Jc,t,r),this},Ve.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(tu,t,r),this});function Jc(r,t,e){t.set(r,e)}function tu(r,t,e){r.length<40?Bn(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(Wt(r),e)}function Gn(){return new Ve}function Ct(r,t){let e=Gn();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var Ee;(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"})(Ee||(Ee={}));function br(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function ve(r){function t(o){if(r[o.toString()]==null)throw new Error("Invalid enum value");return r[o]}let e=function(s,i){let u=t(s);i.int32(u)},n=function(s){let i=s.int32();return t(i)};return br("enum",Ee.VARINT,e,n)}function kt(r,t){return br("message",Ee.LENGTH_DELIMITED,r,t)}var xr=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var bt;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1"})(bt||(bt={}));var Zn;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1"})(Zn||(Zn={}));(function(r){r.codec=()=>ve(Zn)})(bt||(bt={}));var $e;(function(r){let t;r.codec=()=>(t==null&&(t=kt((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),bt.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let u=e.uint32();switch(u>>>3){case 1:{s.Type=bt.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(u&7);break}}}return s})),t),r.encode=e=>Ct(e,r.codec()),r.decode=(e,n)=>Ot(e,r.codec(),n)})($e||($e={}));var jn;(function(r){let t;r.codec=()=>(t==null&&(t=kt((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),bt.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let u=e.uint32();switch(u>>>3){case 1:{s.Type=bt.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(u&7);break}}}return s})),t),r.encode=e=>Ct(e,r.codec()),r.decode=(e,n)=>Ot(e,r.codec(),n)})(jn||(jn={}));var ru=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Qt=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Jt=new Uint32Array(64),Xn=class extends xe{constructor(){super(64,32,8,!1),this.A=Qt[0]|0,this.B=Qt[1]|0,this.C=Qt[2]|0,this.D=Qt[3]|0,this.E=Qt[4]|0,this.F=Qt[5]|0,this.G=Qt[6]|0,this.H=Qt[7]|0}get(){let{A:t,B:e,C:n,D:o,E:s,F:i,G:u,H:f}=this;return[t,e,n,o,s,i,u,f]}set(t,e,n,o,s,i,u,f){this.A=t|0,this.B=e|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=u|0,this.H=f|0}process(t,e){for(let c=0;c<16;c++,e+=4)Jt[c]=t.getUint32(e,!1);for(let c=16;c<64;c++){let d=Jt[c-15],y=Jt[c-2],m=wt(d,7)^wt(d,18)^d>>>3,p=wt(y,17)^wt(y,19)^y>>>10;Jt[c]=p+Jt[c-7]+m+Jt[c-16]|0}let{A:n,B:o,C:s,D:i,E:u,F:f,G:a,H:l}=this;for(let c=0;c<64;c++){let d=wt(u,6)^wt(u,11)^wt(u,25),y=l+d+Wo(u,f,a)+ru[c]+Jt[c]|0,p=(wt(n,2)^wt(n,13)^wt(n,22))+Qo(n,o,s)|0;l=a,a=f,f=u,u=i+y|0,i=s,s=o,o=n,n=y+p|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,u=u+this.E|0,f=f+this.F|0,a=a+this.G|0,l=l+this.H|0,this.set(n,o,s,i,u,f,a,l)}roundClean(){Jt.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var Rs=rr(()=>new Xn);function ot(r,t="utf8"){let e=gr[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var Ge=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}};var wr=class extends be{constructor(t,e){super(),this.finished=!1,this.destroyed=!1,jo(t);let n=ke(e);if(this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let o=this.blockLen,s=new Uint8Array(o);s.set(n.length>o?t.create().update(n).digest():n);for(let i=0;i<s.length;i++)s[i]^=54;this.iHash.update(s),this.oHash=t.create();for(let i=0;i<s.length;i++)s[i]^=106;this.oHash.update(s),s.fill(0)}update(t){return ye(this),this.iHash.update(t),this}digestInto(t){ye(this),ge(t,this.outputLen),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}));let{oHash:e,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:u}=this;return t=t,t.finished=o,t.destroyed=s,t.blockLen=i,t.outputLen=u,t.oHash=e._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Yn=(r,t,e)=>new wr(r,t).update(e).digest();Yn.create=(r,t)=>new wr(r,t);function _s(r){r.lowS!==void 0&&Et("lowS",r.lowS),r.prehash!==void 0&&Et("prehash",r.prehash)}function nu(r){let t=He(r);St(t,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});let{endo:e,Fp:n,a:o}=t;if(e){if(!n.eql(o,n.ZERO))throw new Error("Endomorphism can only be defined for Koblitz curves that have a=0");if(typeof e!="object"||typeof e.beta!="bigint"||typeof e.splitScalar!="function")throw new Error("Expected endomorphism with beta: bigint and splitScalar: function")}return Object.freeze({...t})}var{bytesToNumberBE:ou,hexToBytes:su}=ir,Ft={Err:class extends Error{constructor(t=""){super(t)}},_tlv:{encode:(r,t)=>{let{Err:e}=Ft;if(r<0||r>256)throw new e("tlv.encode: wrong tag");if(t.length&1)throw new e("tlv.encode: unpadded data");let n=t.length/2,o=ne(n);if(o.length/2&128)throw new e("tlv.encode: long form length too big");let s=n>127?ne(o.length/2|128):"";return`${ne(r)}${s}${o}${t}`},decode(r,t){let{Err:e}=Ft,n=0;if(r<0||r>256)throw new e("tlv.encode: wrong tag");if(t.length<2||t[n++]!==r)throw new e("tlv.decode: wrong tlv");let o=t[n++],s=!!(o&128),i=0;if(!s)i=o;else{let f=o&127;if(!f)throw new e("tlv.decode(long): indefinite length not supported");if(f>4)throw new e("tlv.decode(long): byte length is too big");let a=t.subarray(n,n+f);if(a.length!==f)throw new e("tlv.decode: length bytes not complete");if(a[0]===0)throw new e("tlv.decode(long): zero leftmost byte");for(let l of a)i=i<<8|l;if(n+=f,i<128)throw new e("tlv.decode(long): not minimal encoding")}let u=t.subarray(n,n+i);if(u.length!==i)throw new e("tlv.decode: wrong value length");return{v:u,l:t.subarray(n+i)}}},_int:{encode(r){let{Err:t}=Ft;if(r<Mt)throw new t("integer: negative integers are not allowed");let e=ne(r);if(Number.parseInt(e[0],16)&8&&(e="00"+e),e.length&1)throw new t("unexpected assertion");return e},decode(r){let{Err:t}=Ft;if(r[0]&128)throw new t("Invalid signature integer: negative");if(r[0]===0&&!(r[1]&128))throw new t("Invalid signature integer: unnecessary leading zero");return ou(r)}},toSig(r){let{Err:t,_int:e,_tlv:n}=Ft,o=typeof r=="string"?su(r):r;we(o);let{v:s,l:i}=n.decode(48,o);if(i.length)throw new t("Invalid signature: left bytes after parsing");let{v:u,l:f}=n.decode(2,s),{v:a,l}=n.decode(2,f);if(l.length)throw new t("Invalid signature: left bytes after parsing");return{r:e.decode(u),s:e.decode(a)}},hexFromSig(r){let{_tlv:t,_int:e}=Ft,n=`${t.encode(2,e.encode(r.r))}${t.encode(2,e.encode(r.s))}`;return t.encode(48,n)}},Mt=BigInt(0),st=BigInt(1),Vd=BigInt(2),Ds=BigInt(3),$d=BigInt(4);function iu(r){let t=nu(r),{Fp:e}=t,n=jt(t.n,t.nBitLength),o=t.toBytes||((p,h,w)=>{let v=h.toAffine();return Ut(Uint8Array.from([4]),e.toBytes(v.x),e.toBytes(v.y))}),s=t.fromBytes||(p=>{let h=p.subarray(1),w=e.fromBytes(h.subarray(0,e.BYTES)),v=e.fromBytes(h.subarray(e.BYTES,2*e.BYTES));return{x:w,y:v}});function i(p){let{a:h,b:w}=t,v=e.sqr(p),b=e.mul(v,p);return e.add(e.add(b,e.mul(p,h)),w)}if(!e.eql(e.sqr(t.Gy),i(t.Gx)))throw new Error("bad generator point: equation left != right");function u(p){return Fe(p,st,t.n)}function f(p){let{allowedPrivateKeyLengths:h,nByteLength:w,wrapPrivateKey:v,n:b}=t;if(h&&typeof p!="bigint"){if($t(p)&&(p=_t(p)),typeof p!="string"||!h.includes(p.length))throw new Error("Invalid key");p=p.padStart(w*2,"0")}let S;try{S=typeof p=="bigint"?p:Dt(X("private key",p,w))}catch{throw new Error(`private key must be ${w} bytes, hex or bigint, not ${typeof p}`)}return v&&(S=V(S,b)),pt("private key",S,st,b),S}function a(p){if(!(p instanceof d))throw new Error("ProjectivePoint expected")}let l=ie((p,h)=>{let{px:w,py:v,pz:b}=p;if(e.eql(b,e.ONE))return{x:w,y:v};let S=p.is0();h==null&&(h=S?e.ONE:e.inv(b));let D=e.mul(w,h),_=e.mul(v,h),I=e.mul(b,h);if(S)return{x:e.ZERO,y:e.ZERO};if(!e.eql(I,e.ONE))throw new Error("invZ was invalid");return{x:D,y:_}}),c=ie(p=>{if(p.is0()){if(t.allowInfinityPoint&&!e.is0(p.py))return;throw new Error("bad point: ZERO")}let{x:h,y:w}=p.toAffine();if(!e.isValid(h)||!e.isValid(w))throw new Error("bad point: x or y not FE");let v=e.sqr(w),b=i(h);if(!e.eql(v,b))throw new Error("bad point: equation left != right");if(!p.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});class d{constructor(h,w,v){if(this.px=h,this.py=w,this.pz=v,h==null||!e.isValid(h))throw new Error("x required");if(w==null||!e.isValid(w))throw new Error("y required");if(v==null||!e.isValid(v))throw new Error("z required");Object.freeze(this)}static fromAffine(h){let{x:w,y:v}=h||{};if(!h||!e.isValid(w)||!e.isValid(v))throw new Error("invalid affine point");if(h instanceof d)throw new Error("projective point not allowed");let b=S=>e.eql(S,e.ZERO);return b(w)&&b(v)?d.ZERO:new d(w,v,e.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(h){let w=e.invertBatch(h.map(v=>v.pz));return h.map((v,b)=>v.toAffine(w[b])).map(d.fromAffine)}static fromHex(h){let w=d.fromAffine(s(X("pointHex",h)));return w.assertValidity(),w}static fromPrivateKey(h){return d.BASE.multiply(f(h))}static msm(h,w){return ur(d,n,h,w)}_setWindowSize(h){m.setWindowSize(this,h)}assertValidity(){c(this)}hasEvenY(){let{y:h}=this.toAffine();if(e.isOdd)return!e.isOdd(h);throw new Error("Field doesn't support isOdd")}equals(h){a(h);let{px:w,py:v,pz:b}=this,{px:S,py:D,pz:_}=h,I=e.eql(e.mul(w,_),e.mul(S,b)),B=e.eql(e.mul(v,_),e.mul(D,b));return I&&B}negate(){return new d(this.px,e.neg(this.py),this.pz)}double(){let{a:h,b:w}=t,v=e.mul(w,Ds),{px:b,py:S,pz:D}=this,_=e.ZERO,I=e.ZERO,B=e.ZERO,R=e.mul(b,b),W=e.mul(S,S),H=e.mul(D,D),O=e.mul(b,S);return O=e.add(O,O),B=e.mul(b,D),B=e.add(B,B),_=e.mul(h,B),I=e.mul(v,H),I=e.add(_,I),_=e.sub(W,I),I=e.add(W,I),I=e.mul(_,I),_=e.mul(O,_),B=e.mul(v,B),H=e.mul(h,H),O=e.sub(R,H),O=e.mul(h,O),O=e.add(O,B),B=e.add(R,R),R=e.add(B,R),R=e.add(R,H),R=e.mul(R,O),I=e.add(I,R),H=e.mul(S,D),H=e.add(H,H),R=e.mul(H,O),_=e.sub(_,R),B=e.mul(H,W),B=e.add(B,B),B=e.add(B,B),new d(_,I,B)}add(h){a(h);let{px:w,py:v,pz:b}=this,{px:S,py:D,pz:_}=h,I=e.ZERO,B=e.ZERO,R=e.ZERO,W=t.a,H=e.mul(t.b,Ds),O=e.mul(w,S),Q=e.mul(v,D),A=e.mul(b,_),L=e.add(w,v),x=e.add(S,D);L=e.mul(L,x),x=e.add(O,Q),L=e.sub(L,x),x=e.add(w,b);let g=e.add(S,_);return x=e.mul(x,g),g=e.add(O,A),x=e.sub(x,g),g=e.add(v,b),I=e.add(D,_),g=e.mul(g,I),I=e.add(Q,A),g=e.sub(g,I),R=e.mul(W,x),I=e.mul(H,A),R=e.add(I,R),I=e.sub(Q,R),R=e.add(Q,R),B=e.mul(I,R),Q=e.add(O,O),Q=e.add(Q,O),A=e.mul(W,A),x=e.mul(H,x),Q=e.add(Q,A),A=e.sub(O,A),A=e.mul(W,A),x=e.add(x,A),O=e.mul(Q,x),B=e.add(B,O),O=e.mul(g,x),I=e.mul(L,I),I=e.sub(I,O),O=e.mul(L,Q),R=e.mul(g,R),R=e.add(R,O),new d(I,B,R)}subtract(h){return this.add(h.negate())}is0(){return this.equals(d.ZERO)}wNAF(h){return m.wNAFCached(this,h,d.normalizeZ)}multiplyUnsafe(h){pt("scalar",h,Mt,t.n);let w=d.ZERO;if(h===Mt)return w;if(h===st)return this;let{endo:v}=t;if(!v)return m.unsafeLadder(this,h);let{k1neg:b,k1:S,k2neg:D,k2:_}=v.splitScalar(h),I=w,B=w,R=this;for(;S>Mt||_>Mt;)S&st&&(I=I.add(R)),_&st&&(B=B.add(R)),R=R.double(),S>>=st,_>>=st;return b&&(I=I.negate()),D&&(B=B.negate()),B=new d(e.mul(B.px,v.beta),B.py,B.pz),I.add(B)}multiply(h){let{endo:w,n:v}=t;pt("scalar",h,st,v);let b,S;if(w){let{k1neg:D,k1:_,k2neg:I,k2:B}=w.splitScalar(h),{p:R,f:W}=this.wNAF(_),{p:H,f:O}=this.wNAF(B);R=m.constTimeNegate(D,R),H=m.constTimeNegate(I,H),H=new d(e.mul(H.px,w.beta),H.py,H.pz),b=R.add(H),S=W.add(O)}else{let{p:D,f:_}=this.wNAF(h);b=D,S=_}return d.normalizeZ([b,S])[0]}multiplyAndAddUnsafe(h,w,v){let b=d.BASE,S=(_,I)=>I===Mt||I===st||!_.equals(b)?_.multiplyUnsafe(I):_.multiply(I),D=S(this,w).add(S(h,v));return D.is0()?void 0:D}toAffine(h){return l(this,h)}isTorsionFree(){let{h,isTorsionFree:w}=t;if(h===st)return!0;if(w)return w(d,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h,clearCofactor:w}=t;return h===st?this:w?w(d,this):this.multiplyUnsafe(t.h)}toRawBytes(h=!0){return Et("isCompressed",h),this.assertValidity(),o(d,this,h)}toHex(h=!0){return Et("isCompressed",h),_t(this.toRawBytes(h))}}d.BASE=new d(t.Gx,t.Gy,e.ONE),d.ZERO=new d(e.ZERO,e.ONE,e.ZERO);let y=t.nBitLength,m=cr(d,t.endo?Math.ceil(y/2):y);return{CURVE:t,ProjectivePoint:d,normPrivateKeyToScalar:f,weierstrassEquation:i,isWithinCurveOrder:u}}function au(r){let t=He(r);return St(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}function Us(r){let t=au(r),{Fp:e,n}=t,o=e.BYTES+1,s=2*e.BYTES+1;function i(A){return V(A,n)}function u(A){return ar(A,n)}let{ProjectivePoint:f,normPrivateKeyToScalar:a,weierstrassEquation:l,isWithinCurveOrder:c}=iu({...t,toBytes(A,L,x){let g=L.toAffine(),E=e.toBytes(g.x),T=Ut;return Et("isCompressed",x),x?T(Uint8Array.from([L.hasEvenY()?2:3]),E):T(Uint8Array.from([4]),E,e.toBytes(g.y))},fromBytes(A){let L=A.length,x=A[0],g=A.subarray(1);if(L===o&&(x===2||x===3)){let E=Dt(g);if(!Fe(E,st,e.ORDER))throw new Error("Point is not on curve");let T=l(E),U;try{U=e.sqrt(T)}catch(F){let k=F instanceof Error?": "+F.message:"";throw new Error("Point is not on curve"+k)}let N=(U&st)===st;return(x&1)===1!==N&&(U=e.neg(U)),{x:E,y:U}}else if(L===s&&x===4){let E=e.fromBytes(g.subarray(0,e.BYTES)),T=e.fromBytes(g.subarray(e.BYTES,2*e.BYTES));return{x:E,y:T}}else throw new Error(`Point of length ${L} was invalid. Expected ${o} compressed bytes or ${s} uncompressed bytes`)}}),d=A=>_t(Zt(A,t.nByteLength));function y(A){let L=n>>st;return A>L}function m(A){return y(A)?i(-A):A}let p=(A,L,x)=>Dt(A.slice(L,x));class h{constructor(L,x,g){this.r=L,this.s=x,this.recovery=g,this.assertValidity()}static fromCompact(L){let x=t.nByteLength;return L=X("compactSignature",L,x*2),new h(p(L,0,x),p(L,x,2*x))}static fromDER(L){let{r:x,s:g}=Ft.toSig(X("DER",L));return new h(x,g)}assertValidity(){pt("r",this.r,st,n),pt("s",this.s,st,n)}addRecoveryBit(L){return new h(this.r,this.s,L)}recoverPublicKey(L){let{r:x,s:g,recovery:E}=this,T=_(X("msgHash",L));if(E==null||![0,1,2,3].includes(E))throw new Error("recovery id invalid");let U=E===2||E===3?x+t.n:x;if(U>=e.ORDER)throw new Error("recovery id 2 or 3 invalid");let N=E&1?"03":"02",C=f.fromHex(N+d(U)),F=u(U),k=i(-T*F),z=i(g*F),$=f.BASE.multiplyAndAddUnsafe(C,k,z);if(!$)throw new Error("point at infinify");return $.assertValidity(),$}hasHighS(){return y(this.s)}normalizeS(){return this.hasHighS()?new h(this.r,i(-this.s),this.recovery):this}toDERRawBytes(){return oe(this.toDERHex())}toDERHex(){return Ft.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return oe(this.toCompactHex())}toCompactHex(){return d(this.r)+d(this.s)}}let w={isValidPrivateKey(A){try{return a(A),!0}catch{return!1}},normPrivateKeyToScalar:a,randomPrivateKey:()=>{let A=hn(t.n);return as(t.randomBytes(A),t.n)},precompute(A=8,L=f.BASE){return L._setWindowSize(A),L.multiply(BigInt(3)),L}};function v(A,L=!0){return f.fromPrivateKey(A).toRawBytes(L)}function b(A){let L=$t(A),x=typeof A=="string",g=(L||x)&&A.length;return L?g===o||g===s:x?g===2*o||g===2*s:A instanceof f}function S(A,L,x=!0){if(b(A))throw new Error("first arg must be private key");if(!b(L))throw new Error("second arg must be public key");return f.fromHex(L).multiply(a(A)).toRawBytes(x)}let D=t.bits2int||function(A){let L=Dt(A),x=A.length*8-t.nBitLength;return x>0?L>>BigInt(x):L},_=t.bits2int_modN||function(A){return i(D(A))},I=Me(t.nBitLength);function B(A){return pt(`num < 2^${t.nBitLength}`,A,Mt,I),Zt(A,t.nByteLength)}function R(A,L,x=W){if(["recovered","canonical"].some(rt=>rt in x))throw new Error("sign() legacy options not supported");let{hash:g,randomBytes:E}=t,{lowS:T,prehash:U,extraEntropy:N}=x;T==null&&(T=!0),A=X("msgHash",A),_s(x),U&&(A=X("prehashed msgHash",g(A)));let C=_(A),F=a(L),k=[B(F),B(C)];if(N!=null&&N!==!1){let rt=N===!0?E(e.BYTES):N;k.push(X("extraEntropy",rt))}let z=Ut(...k),$=C;function et(rt){let it=D(rt);if(!c(it))return;let ft=u(it),J=f.BASE.multiply(it).toAffine(),dt=i(J.x);if(dt===Mt)return;let It=i(ft*i($+dt*F));if(It===Mt)return;let Re=(J.x===dt?0:2)|Number(J.y&st),_e=It;return T&&y(It)&&(_e=m(It),Re^=1),new h(dt,_e,Re)}return{seed:z,k2sig:et}}let W={lowS:t.lowS,prehash:!1},H={lowS:t.lowS,prehash:!1};function O(A,L,x=W){let{seed:g,k2sig:E}=R(A,L,x),T=t;return un(T.hash.outputLen,T.nByteLength,T.hmac)(g,E)}f.BASE._setWindowSize(8);function Q(A,L,x,g=H){let E=A;if(L=X("msgHash",L),x=X("publicKey",x),"strict"in g)throw new Error("options.strict was renamed to lowS");_s(g);let{lowS:T,prehash:U}=g,N,C;try{if(typeof E=="string"||$t(E))try{N=h.fromDER(E)}catch(J){if(!(J instanceof Ft.Err))throw J;N=h.fromCompact(E)}else if(typeof E=="object"&&typeof E.r=="bigint"&&typeof E.s=="bigint"){let{r:J,s:dt}=E;N=new h(J,dt)}else throw new Error("PARSE");C=f.fromHex(x)}catch(J){if(J.message==="PARSE")throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(T&&N.hasHighS())return!1;U&&(L=t.hash(L));let{r:F,s:k}=N,z=_(L),$=u(k),et=i(z*$),rt=i(F*$),it=f.BASE.multiplyAndAddUnsafe(C,et,rt)?.toAffine();return it?i(it.x)===F:!1}return{CURVE:t,getPublicKey:v,getSharedSecret:S,sign:O,verify:Q,ProjectivePoint:f,Signature:h,utils:w}}function cu(r){return{hash:r,hmac:(t,...e)=>Yn(r,t,tn(...e)),randomBytes:nr}}function Ns(r,t){let e=n=>Us({...r,...cu(n)});return Object.freeze({...e(t),create:e})}var Cs=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),Ps=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),uu=BigInt(1),Wn=BigInt(2),Os=(r,t)=>(r+t/Wn)/t;function fu(r){let t=Cs,e=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),u=BigInt(44),f=BigInt(88),a=r*r*r%t,l=a*a*r%t,c=Z(l,e,t)*l%t,d=Z(c,e,t)*l%t,y=Z(d,Wn,t)*a%t,m=Z(y,o,t)*y%t,p=Z(m,s,t)*m%t,h=Z(p,u,t)*p%t,w=Z(h,f,t)*h%t,v=Z(w,u,t)*p%t,b=Z(v,e,t)*l%t,S=Z(b,i,t)*m%t,D=Z(S,n,t)*a%t,_=Z(D,Wn,t);if(!Qn.eql(Qn.sqr(_),r))throw new Error("Cannot find square root");return _}var Qn=jt(Cs,void 0,void 0,{sqrt:fu}),fe=Ns({a:BigInt(0),b:BigInt(7),Fp:Qn,n:Ps,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let t=Ps,e=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-uu*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),s=e,i=BigInt("0x100000000000000000000000000000000"),u=Os(s*r,t),f=Os(-n*r,t),a=V(r-u*e-f*o,t),l=V(-u*n-f*s,t),c=a>i,d=l>i;if(c&&(a=t-a),d&&(l=t-l),a>i||l>i)throw new Error("splitScalar: Endomorphism failed, k="+r);return{k1neg:c,k1:a,k2neg:d,k2:l}}}},Rs),th=BigInt(0);var eh=fe.ProjectivePoint;function yt(r,t){t==null&&(t=r.reduce((o,s)=>o+s.length,0));let e=at(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return e}function ks(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function Fs(r,t,e){let n=Ke.digest(e instanceof Uint8Array?e:e.subarray());if(ks(n))return n.then(({digest:o})=>fe.verify(t,o,r)).catch(o=>{throw new Ge(String(o))});try{return fe.verify(t,n.digest,r)}catch(o){throw new Ge(String(o))}}var Er=class{type="secp256k1";raw;_key;constructor(t){this._key=Hs(t),this.raw=Ms(this._key)}toMultihash(){return Tt.digest(hr(this))}toCID(){return lt.createV1(114,this.toMultihash())}toString(){return Y.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:xt(this.raw,t.raw)}verify(t,e){return Fs(this._key,e,t)}};function Ks(r){return new Er(r)}function Ms(r){return fe.ProjectivePoint.fromHex(r).toRawBytes(!0)}function Hs(r){try{return fe.ProjectivePoint.fromHex(r),r}catch(t){throw new Qe(String(t))}}function qs(r){let{Type:t,Data:e}=$e.decode(r.digest),n=e??new Uint8Array;switch(t){case bt.Ed25519:return ms(n);case bt.secp256k1:return Ks(n);default:throw new Ne}}function hr(r){return $e.encode({Type:bt[r.type],Data:r.raw})}var zs=Symbol.for("nodejs.util.inspect.custom"),lu=114,Ze=class{type;multihash;publicKey;string;constructor(t){this.type=t.type,this.multihash=t.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[zr]=!0;toString(){return this.string==null&&(this.string=Y.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return lt.createV1(lu,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return xt(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return xt(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[zs](){return`PeerId(${this.toString()})`}},vr=class extends Ze{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},Ar=class extends Ze{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},Sr=class extends Ze{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},du=2336,Ir=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=Tt.digest(Wt(this.url))}[zs](){return`PeerId(${this.url})`}[zr]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return lt.createV1(du,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=ot(t)),t.toString()===this.toString())}};function Vs(r){if(pu(r))return new vr({multihash:r});if(hu(r))try{let t=qs(r);if(t.type==="Ed25519")return new Ar({multihash:r,publicKey:t});if(t.type==="secp256k1")return new Sr({multihash:r,publicKey:t})}catch{let e=ot(r.digest);return new Ir(new URL(e))}throw new Je("Supplied PeerID Multihash is invalid")}function hu(r){return r.code===Tt.code}function pu(r){return r.code===Ke.code}var Br=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 s=0,i=0,u=this.peekChar();if(u===void 0)return;let f=u==="0",a=2**(8*o)-1;for(;;){let l=this.readAtomically(()=>{let c=this.readChar();if(c===void 0)return;let d=Number.parseInt(c,t);if(!Number.isNaN(d))return d});if(l===void 0)break;if(s*=t,s+=l,s>a||(i+=1,e!==void 0&&i>e))return}if(i!==0)return!n&&f&&i>1?void 0:s})}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 i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return e[o]=i[0],e[o+1]=i[1],e[o+2]=i[2],e[o+3]=i[3],[o+4,!0]}let s=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(s===void 0)return[o,!1];e[o]=s>>8,e[o+1]=s&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 s=new Uint8Array(14),i=16-(n+2),[u]=t(s.subarray(0,i));return e.set(s.subarray(0,u),16-u),e})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var $s=45,mu=15,Ae=new Br;function Jn(r){if(!(r.length>mu))return Ae.new(r).parseWith(()=>Ae.readIPv4Addr())}function to(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>$s))return Ae.new(r).parseWith(()=>Ae.readIPv6Addr())}function Lr(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>$s))return Ae.new(r).parseWith(()=>Ae.readIPAddr())}function Tr(r){return!!Jn(r)}function Rr(r){return!!to(r)}function _r(r){return!!Lr(r)}var Zs=_i(Gs(),1),gu=["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"],yu=gu.map(r=>new Zs.Netmask(r));function eo(r){for(let t of yu)if(t.contains(r))return!0;return!1}function bu(r){return/^::ffff:([0-9a-fA-F]{1,4}):([0-9a-fA-F]{1,4})$/.test(r)}function xu(r){let t=r.split(":");if(t.length<2)return!1;let e=t[t.length-1].padStart(4,"0"),n=t[t.length-2].padStart(4,"0"),o=`${parseInt(n.substring(0,2),16)}.${parseInt(n.substring(2),16)}.${parseInt(e.substring(0,2),16)}.${parseInt(e.substring(2),16)}`;return eo(o)}function wu(r){return/^::ffff:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(r)}function Eu(r){let t=r.split(":"),e=t[t.length-1];return eo(e)}function vu(r){return/^::$/.test(r)||/^::1$/.test(r)||/^64:ff9b::([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(r)||/^100::([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2001::([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2001:2[0-9a-fA-F]:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2001:db8:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2002:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^f[c-d]([0-9a-fA-F]{2,2}):/i.test(r)||/^fe[8-9a-bA-B][0-9a-fA-F]:/i.test(r)||/^ff([0-9a-fA-F]{2,2}):/i.test(r)}function ro(r){return Tr(r)?eo(r):bu(r)?xu(r):wu(r)?Eu(r):Rr(r)?vu(r):void 0}var E0=parseInt("0xFFFF",16),v0=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);var Ys=Tr,Lu=Rr,no=function(r){let t=0;if(r=r.toString().trim(),Ys(r)){let e=new Uint8Array(t+4);return r.split(/\./g).forEach(n=>{e[t++]=parseInt(n,10)&255}),e}if(Lu(r)){let e=r.split(":",8),n;for(n=0;n<e.length;n++){let s=Ys(e[n]),i;s&&(i=no(e[n]),e[n]=ot(i.slice(0,2),"base16")),i!=null&&++n<8&&e.splice(n,0,ot(i.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 s=[n,1];for(n=9-e.length;n>0;n--)s.push("0");e.splice.apply(e,s)}let o=new Uint8Array(t+16);for(n=0;n<e.length;n++){let s=parseInt(e[n],16);o[t++]=s>>8&255,o[t++]=s&255}return o}throw new Error("invalid ip address")},Ws=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 s=0;s<e;s++)o.push(r[t+s]);return o.join(".")}if(e===16){let o=[];for(let s=0;s<e;s+=2)o.push(n.getUint16(t+s).toString(16));return o.join(":").replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}return""};var Se={},oo={},Ru=[[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"]];Ru.forEach(r=>{let t=_u(...r);oo[t.code]=t,Se[t.name]=t});function _u(r,t,e,n,o){return{code:r,size:t,name:e,resolvable:!!n,path:!!o}}function q(r){if(typeof r=="number"){if(oo[r]!=null)return oo[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(Se[r]!=null)return Se[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var np=q("ip4"),op=q("ip6"),sp=q("ipcidr");function co(r,t){switch(q(r).code){case 4:case 41:return Uu(t);case 42:return ao(t);case 6:case 273:case 33:case 132:return ti(t).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return ao(t);case 421:return Cu(t);case 444:return Js(t);case 445:return Js(t);case 466:return Ou(t);case 481:return globalThis.encodeURIComponent(ao(t));default:return ot(t,"base16")}}function uo(r,t){switch(q(r).code){case 4:return Qs(t);case 41:return Qs(t);case 42:return io(t);case 6:case 273:case 33:case 132:return fo(parseInt(t,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return io(t);case 421:return Nu(t);case 444:return ku(t);case 445:return Fu(t);case 466:return Pu(t);case 481:return io(globalThis.decodeURIComponent(t));default:return Wt(t,"base16")}}var so=Object.values(qe).map(r=>r.decoder),Du=function(){let r=so[0].or(so[1]);return so.slice(2).forEach(t=>r=r.or(t)),r}();function Qs(r){if(!_r(r))throw new Error("invalid ip address");return no(r)}function Uu(r){let t=Ws(r,0,r.length);if(t==null)throw new Error("ipBuff is required");if(!_r(t))throw new Error("invalid ip address");return t}function fo(r){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,r),new Uint8Array(t)}function ti(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function io(r){let t=Wt(r),e=Uint8Array.from(Xt(t.length));return yt([e,t],e.length+t.length)}function ao(r){let t=Pt(r);if(r=r.slice(nt(t)),r.length!==t)throw new Error("inconsistent lengths");return ot(r)}function Nu(r){let t;r[0]==="Q"||r[0]==="1"?t=ee(Y.decode(`z${r}`)).bytes:t=lt.parse(r).multihash.bytes;let e=Uint8Array.from(Xt(t.length));return yt([e,t],e.length+t.length)}function Pu(r){let t=Du.decode(r),e=Uint8Array.from(Xt(t.length));return yt([e,t],e.length+t.length)}function Ou(r){let t=Pt(r),e=r.slice(nt(t));if(e.length!==t)throw new Error("inconsistent lengths");return"u"+ot(e,"base64url")}function Cu(r){let t=Pt(r),e=r.slice(nt(t));if(e.length!==t)throw new Error("inconsistent lengths");return ot(e,"base58btc")}function ku(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=Lt.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=fo(n);return yt([e,o],e.length+o.length)}function Fu(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=Lt.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=fo(n);return yt([e,o],e.length+o.length)}function Js(r){let t=r.slice(0,r.length-2),e=r.slice(r.length-2),n=ot(t,"base32"),o=ti(e);return`${n}:${o}`}function ei(r){r=lo(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 s=0;s<o.length;s++){let i=o[s],u=q(i);if(u.size===0){t.push([u.code]),e.push([u.code]);continue}if(s++,s>=o.length)throw ni("invalid address: "+r);if(u.path===!0){n=lo(o.slice(s).join("/")),t.push([u.code,uo(u.code,n)]),e.push([u.code,n]);break}let f=uo(u.code,o[s]);t.push([u.code,f]),e.push([u.code,co(u.code,f)])}return{string:ri(e),bytes:po(t),tuples:t,stringTuples:e,path:n}}function ho(r){let t=[],e=[],n=null,o=0;for(;o<r.length;){let s=Pt(r,o),i=nt(s),u=q(s),f=Mu(u,r.slice(o+i));if(f===0){t.push([s]),e.push([s]),o+=i;continue}let a=r.slice(o+i,o+i+f);if(o+=f+i,o>r.length)throw ni("Invalid address Uint8Array: "+ot(r,"base16"));t.push([s,a]);let l=co(s,a);if(e.push([s,l]),u.path===!0){n=l;break}}return{bytes:Uint8Array.from(r),string:ri(e),tuples:t,stringTuples:e,path:n}}function ri(r){let t=[];return r.map(e=>{let n=q(e[0]);return t.push(n.name),e.length>1&&e[1]!=null&&t.push(e[1]),null}),lo(t.join("/"))}function po(r){return yt(r.map(t=>{let e=q(t[0]),n=Uint8Array.from(Xt(e.code));return t.length>1&&t[1]!=null&&(n=yt([n,t[1]])),n}))}function Mu(r,t){if(r.size>0)return r.size/8;if(r.size===0)return 0;{let e=Pt(t instanceof Uint8Array?t:Uint8Array.from(t));return e+nt(e)}}function lo(r){return"/"+r.trim().split("/").filter(t=>t).join("/")}function ni(r){return new Error("Error parsing address: "+r)}var Hu=Symbol.for("nodejs.util.inspect.custom"),go=Symbol.for("@multiformats/js-multiaddr/multiaddr"),Ku=[q("dns").code,q("dns4").code,q("dns6").code,q("dnsaddr").code],mo=class extends Error{constructor(t="No available resolver"){super(t),this.name="NoAvailableResolverError"}},Dr=class r{bytes;#e;#t;#r;#n;[go]=!0;constructor(t){t==null&&(t="");let e;if(t instanceof Uint8Array)e=ho(t);else if(typeof t=="string"){if(t.length>0&&t.charAt(0)!=="/")throw new Error(`multiaddr "${t}" must start with a "/"`);e=ei(t)}else if(si(t))e=ho(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,s="",i=q("tcp"),u=q("udp"),f=q("ip4"),a=q("ip6"),l=q("dns6"),c=q("ip6zone");for(let[y,m]of this.stringTuples())y===c.code&&(s=`%${m??""}`),Ku.includes(y)&&(e=i.name,o=443,n=`${m??""}${s}`,t=y===l.code?6:4),(y===i.code||y===u.code)&&(e=q(y).name,o=parseInt(m??"")),(y===f.code||y===a.code)&&(e=q(y).name,n=`${m??""}${s}`,t=y===a.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({},q(t)))}protoCodes(){return this.#t.map(([t])=>t)}protoNames(){return this.#t.map(([t])=>q(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(po(e.slice(0,n)));return this}getPeerId(){try{let t=[];this.stringTuples().forEach(([n,o])=>{n===Se.p2p.code&&t.push([n,o]),n===Se["p2p-circuit"].code&&(t=[])});let e=t.pop();if(e?.[1]!=null){let n=e[1];return n[0]==="Q"||n[0]==="1"?ot(Y.decode(`z${n}`),"base58btc"):ot(lt.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){return this.#n}equals(t){return xt(this.bytes,t.bytes)}async resolve(t){let e=this.protos().find(s=>s.resolvable);if(e==null)return[this];let n=oi.get(e.name);if(n==null)throw new mo(`no available resolver for ${e.name}`);return(await n(this,t)).map(s=>Ie(s))}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)}[Hu](){return`Multiaddr(${this.#e})`}};var oi=new Map;function si(r){return!!r?.[go]}function Ie(r){return new Dr(r)}function qu(r){return r[Symbol.asyncIterator]!=null}function zu(r){if(qu(r))return(async()=>{for await(let t of r)return t})();for(let t of r)return t}var yo=zu;var ai=Symbol.for("@achingbrain/uint8arraylist");function ii(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 Ur(r){return!!r?.[ai]}var Be=class r{bufs;length;[ai]=!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(Ur(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(Ur(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=ii(this.bufs,t);return e.buf[e.index]}set(t,e){let n=ii(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(Ur(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 yt(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:yt(n,o)}sublist(t,e){let{bufs:n,length:o}=this._subList(t,e),s=new r;return s.length=o,s.bufs=[...n],s}_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 s=0;s<this.bufs.length;s++){let i=this.bufs[s],u=o,f=u+i.byteLength;if(o=f,t>=f)continue;let a=t>=u&&t<f,l=e>u&&e<=f;if(a&&l){if(t===u&&e===f){n.push(i);break}let c=t-u;n.push(i.subarray(c,c+(e-t)));break}if(a){if(t===0){n.push(i);continue}n.push(i.subarray(t-u));continue}if(l){if(e===f){n.push(i);break}n.push(i.subarray(0,e-u));break}n.push(i)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!Ur(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 s=256,i=new Int32Array(s);for(let c=0;c<s;c++)i[c]=-1;for(let c=0;c<o;c++)i[n[c]]=c;let u=i,f=this.byteLength-n.byteLength,a=n.byteLength-1,l;for(let c=e;c<=f;c+=l){l=0;for(let d=a;d>=0;d--){let y=this.get(c+d);if(n[d]!==y){l=Math.max(1,d-u[y]);break}}if(l===0)return c}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=at(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=Nt(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=Nt(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=Nt(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=at(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=Nt(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=Nt(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=Nt(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=Nt(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=Nt(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(!xt(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,s)=>o+s.byteLength,0)),n.length=e,n}};function Nr(r){return r[Symbol.asyncIterator]!=null}var Pr=r=>{let t=nt(r),e=at(t);return Xt(r,e),Pr.bytes=t,e};Pr.bytes=0;function Xe(r,t){t=t??{};let e=t.lengthEncoder??Pr;function*n(o){let s=e(o.byteLength);s instanceof Uint8Array?yield s:yield*s,o instanceof Uint8Array?yield o:yield*o}return Nr(r)?async function*(){for await(let o of r)yield*n(o)}():function*(){for(let o of r)yield*n(o)}()}Xe.single=(r,t)=>{t=t??{};let e=t.lengthEncoder??Pr;return new Be(e(r.byteLength),r)};var Or=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},Cr=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},kr=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"},Ye=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};var Vu=8,$u=1024*1024*4,le;(function(r){r[r.LENGTH=0]="LENGTH",r[r.DATA=1]="DATA"})(le||(le={}));var bo=r=>{let t=Pt(r);return bo.bytes=nt(t),t};bo.bytes=0;function Le(r,t){let e=new Be,n=le.LENGTH,o=-1,s=t?.lengthDecoder??bo,i=t?.maxLengthLength??Vu,u=t?.maxDataLength??$u;function*f(){for(;e.byteLength>0;){if(n===le.LENGTH)try{if(o=s(e),o<0)throw new Or("Invalid message length");if(o>u)throw new Cr("Message length too long");let a=s.bytes;e.consume(a),t?.onLength!=null&&t.onLength(o),n=le.DATA}catch(a){if(a instanceof RangeError){if(e.byteLength>i)throw new kr("Message length length too long");break}throw a}if(n===le.DATA){if(e.byteLength<o)break;let a=e.sublist(0,o);e.consume(o),t?.onData!=null&&t.onData(a),yield a,n=le.LENGTH}}}return Nr(r)?async function*(){for await(let a of r)e.append(a),yield*f();if(e.byteLength>0)throw new Ye("Unexpected end of input")}():function*(){for(let a of r)e.append(a),yield*f();if(e.byteLength>0)throw new Ye("Unexpected end of input")}()}Le.fromReader=(r,t)=>{let e=1,n=async function*(){for(;;)try{let{done:s,value:i}=await r.next(e);if(s===!0)return;i!=null&&(yield i)}catch(s){if(s.code==="ERR_UNDER_READ")return{done:!0,value:null};throw s}finally{e=1}}();return Le(n,{...t??{},onLength:s=>{e=s}})};function Zu(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 ci=Zu;function ju(r){return r[Symbol.asyncIterator]!=null}function Xu(r,t){let e=0;if(ju(r))return async function*(){for await(let f of r)yield t(f,e++)}();let n=ci(r),{value:o,done:s}=n.next();if(s===!0)return function*(){}();let i=t(o,e++);if(typeof i.then=="function")return async function*(){yield await i;for await(let f of n)yield t(f,e++)}();let u=t;return function*(){yield i;for(let f of n)yield u(f,e++)}()}var ui=Xu;function Ht(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var Fr=globalThis.CustomEvent??Event;async function*xo(r,t={}){let e=t.concurrency??1/0;e<1&&(e=1/0);let n=t.ordered==null?!1:t.ordered,o=new EventTarget,s=[],i=Ht(),u=Ht(),f=!1,a,l=!1;o.addEventListener("task-complete",()=>{u.resolve()}),Promise.resolve().then(async()=>{try{for await(let m of r){if(s.length===e&&(i=Ht(),await i.promise),l)break;let p={done:!1};s.push(p),m().then(h=>{p.done=!0,p.ok=!0,p.value=h,o.dispatchEvent(new Fr("task-complete"))},h=>{p.done=!0,p.err=h,o.dispatchEvent(new Fr("task-complete"))})}f=!0,o.dispatchEvent(new Fr("task-complete"))}catch(m){a=m,o.dispatchEvent(new Fr("task-complete"))}});function c(){return n?s[0]?.done:!!s.find(m=>m.done)}function*d(){for(;s.length>0&&s[0].done;){let m=s[0];if(s.shift(),m.ok)yield m.value;else throw l=!0,i.resolve(),m.err;i.resolve()}}function*y(){for(;c();)for(let m=0;m<s.length;m++)if(s[m].done){let p=s[m];if(s.splice(m,1),m--,p.ok)yield p.value;else throw l=!0,i.resolve(),p.err;i.resolve()}}for(;;){if(c()||(u=Ht(),await u.promise),a!=null)throw a;if(n?yield*d():yield*y(),f&&s.length===0)break}}var Mr=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}},Te=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new Mr(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 Mr(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 wo=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.code=e??"ABORT_ERR"}};function Hr(r={}){return Yu(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 Yu(r,t){t=t??{};let e=t.onEnd,n=new Te,o,s,i,u=Ht(),f=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((h,w)=>{s=v=>{s=null,n.push(v);try{h(r(n))}catch(b){w(b)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{u.resolve(),u=Ht()})}},a=h=>s!=null?s(h):(n.push(h),o),l=h=>(n=new Te,s!=null?s({error:h}):(n.push({error:h}),o)),c=h=>{if(i)return o;if(t?.objectMode!==!0&&h?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return a({done:!1,value:h})},d=h=>i?o:(i=!0,h!=null?l(h):a({done:!0})),y=()=>(n=new Te,d(),{done:!0}),m=h=>(d(h),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:f,return:y,throw:m,push:c,end:d,get readableLength(){return n.size},onEmpty:async h=>{let w=h?.signal;if(w?.throwIfAborted(),n.isEmpty())return;let v,b;w!=null&&(v=new Promise((S,D)=>{b=()=>{D(new wo)},w.addEventListener("abort",b)}));try{await Promise.race([u.promise,v])}finally{b!=null&&w!=null&&w?.removeEventListener("abort",b)}}},e==null)return o;let p=o;return o={[Symbol.asyncIterator](){return this},next(){return p.next()},throw(h){return p.throw(h),e!=null&&(e(h),e=void 0),{done:!0}},return(){return p.return(),e!=null&&(e(),e=void 0),{done:!0}},push:c,end(h){return p.end(h),e!=null&&(e(h),e=void 0),o},get readableLength(){return p.readableLength},onEmpty:h=>p.onEmpty(h)},o}function Wu(r){return r[Symbol.asyncIterator]!=null}function Qu(...r){let t=[];for(let e of r)Wu(e)||t.push(e);return t.length===r.length?function*(){for(let e of t)yield*e}():async function*(){let e=Hr({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 fi=Qu;function vo(r,...t){if(r==null)throw new Error("Empty pipeline");if(Eo(r)){let n=r;r=()=>n.source}else if(di(r)||li(r)){let n=r;r=()=>n}let e=[r,...t];if(e.length>1&&Eo(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++)Eo(e[n])&&(e[n]=tf(e[n]));return Ju(...e)}var Ju=(...r)=>{let t;for(;r.length>0;)t=r.shift()(t);return t},li=r=>r?.[Symbol.asyncIterator]!=null,di=r=>r?.[Symbol.iterator]!=null,Eo=r=>r==null?!1:r.sink!=null&&r.source!=null,tf=r=>t=>{let e=r.sink(t);if(e?.then!=null){let n=Hr({objectMode:!0});e.then(()=>{n.end()},i=>{n.end(i)});let o,s=r.source;if(li(s))o=async function*(){yield*s,n.end()};else if(di(s))o=function*(){yield*s,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return fi(n,o())}return r.source};var hi="libp2p",pi="autonat",mi="1.0.0";var M;(function(r){let t;(function(a){a.DIAL="DIAL",a.DIAL_RESPONSE="DIAL_RESPONSE"})(t=r.MessageType||(r.MessageType={}));let e;(function(a){a[a.DIAL=0]="DIAL",a[a.DIAL_RESPONSE=1]="DIAL_RESPONSE"})(e||(e={})),function(a){a.codec=()=>ve(e)}(t=r.MessageType||(r.MessageType={}));let n;(function(a){a.OK="OK",a.E_DIAL_ERROR="E_DIAL_ERROR",a.E_DIAL_REFUSED="E_DIAL_REFUSED",a.E_BAD_REQUEST="E_BAD_REQUEST",a.E_INTERNAL_ERROR="E_INTERNAL_ERROR"})(n=r.ResponseStatus||(r.ResponseStatus={}));let o;(function(a){a[a.OK=0]="OK",a[a.E_DIAL_ERROR=100]="E_DIAL_ERROR",a[a.E_DIAL_REFUSED=101]="E_DIAL_REFUSED",a[a.E_BAD_REQUEST=200]="E_BAD_REQUEST",a[a.E_INTERNAL_ERROR=300]="E_INTERNAL_ERROR"})(o||(o={})),function(a){a.codec=()=>ve(o)}(n=r.ResponseStatus||(r.ResponseStatus={}));let s;(function(a){let l;a.codec=()=>(l==null&&(l=kt((c,d,y={})=>{if(y.lengthDelimited!==!1&&d.fork(),c.id!=null&&(d.uint32(10),d.bytes(c.id)),c.addrs!=null)for(let m of c.addrs)d.uint32(18),d.bytes(m);y.lengthDelimited!==!1&&d.ldelim()},(c,d,y={})=>{let m={addrs:[]},p=d==null?c.len:c.pos+d;for(;c.pos<p;){let h=c.uint32();switch(h>>>3){case 1:{m.id=c.bytes();break}case 2:{if(y.limits?.addrs!=null&&m.addrs.length===y.limits.addrs)throw new xr('Decode error - map field "addrs" had too many elements');m.addrs.push(c.bytes());break}default:{c.skipType(h&7);break}}}return m})),l),a.encode=c=>Ct(c,a.codec()),a.decode=(c,d)=>Ot(c,a.codec(),d)})(s=r.PeerInfo||(r.PeerInfo={}));let i;(function(a){let l;a.codec=()=>(l==null&&(l=kt((c,d,y={})=>{y.lengthDelimited!==!1&&d.fork(),c.peer!=null&&(d.uint32(10),r.PeerInfo.codec().encode(c.peer,d)),y.lengthDelimited!==!1&&d.ldelim()},(c,d,y={})=>{let m={},p=d==null?c.len:c.pos+d;for(;c.pos<p;){let h=c.uint32();switch(h>>>3){case 1:{m.peer=r.PeerInfo.codec().decode(c,c.uint32(),{limits:y.limits?.peer});break}default:{c.skipType(h&7);break}}}return m})),l),a.encode=c=>Ct(c,a.codec()),a.decode=(c,d)=>Ot(c,a.codec(),d)})(i=r.Dial||(r.Dial={}));let u;(function(a){let l;a.codec=()=>(l==null&&(l=kt((c,d,y={})=>{y.lengthDelimited!==!1&&d.fork(),c.status!=null&&(d.uint32(8),r.ResponseStatus.codec().encode(c.status,d)),c.statusText!=null&&(d.uint32(18),d.string(c.statusText)),c.addr!=null&&(d.uint32(26),d.bytes(c.addr)),y.lengthDelimited!==!1&&d.ldelim()},(c,d,y={})=>{let m={},p=d==null?c.len:c.pos+d;for(;c.pos<p;){let h=c.uint32();switch(h>>>3){case 1:{m.status=r.ResponseStatus.codec().decode(c);break}case 2:{m.statusText=c.string();break}case 3:{m.addr=c.bytes();break}default:{c.skipType(h&7);break}}}return m})),l),a.encode=c=>Ct(c,a.codec()),a.decode=(c,d)=>Ot(c,a.codec(),d)})(u=r.DialResponse||(r.DialResponse={}));let f;r.codec=()=>(f==null&&(f=kt((a,l,c={})=>{c.lengthDelimited!==!1&&l.fork(),a.type!=null&&(l.uint32(8),r.MessageType.codec().encode(a.type,l)),a.dial!=null&&(l.uint32(18),r.Dial.codec().encode(a.dial,l)),a.dialResponse!=null&&(l.uint32(26),r.DialResponse.codec().encode(a.dialResponse,l)),c.lengthDelimited!==!1&&l.ldelim()},(a,l,c={})=>{let d={},y=l==null?a.len:a.pos+l;for(;a.pos<y;){let m=a.uint32();switch(m>>>3){case 1:{d.type=r.MessageType.codec().decode(a);break}case 2:{d.dial=r.Dial.codec().decode(a,a.uint32(),{limits:c.limits?.dial});break}case 3:{d.dialResponse=r.DialResponse.codec().decode(a,a.uint32(),{limits:c.limits?.dialResponse});break}default:{a.skipType(m&7);break}}}return d})),f),r.encode=a=>Ct(a,r.codec()),r.decode=(a,l)=>Ot(a,r.codec(),l)})(M||(M={}));var Ao=4,Kr=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??hi}/${pi}/${mi}`,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 De)};e.addEventListener("abort",n,{once:!0}),Vr(1/0,e);try{let o=this;await vo(t.stream,s=>Le(s),async function*(s){let i=await yo(s);if(i==null){o.log("no message received"),yield M.encode({type:M.MessageType.DIAL_RESPONSE,dialResponse:{status:M.ResponseStatus.E_BAD_REQUEST,statusText:"No message was sent"}});return}let u;try{u=M.decode(i)}catch(f){o.log.error("could not decode message",f),yield M.encode({type:M.MessageType.DIAL_RESPONSE,dialResponse:{status:M.ResponseStatus.E_BAD_REQUEST,statusText:"Could not decode message"}});return}yield M.encode(await o.handleAutonatMessage(u,t.connection,{signal:e}))},s=>Xe(s),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(c=>c.toOptions().host),s=t.dial;if(s==null)return this.log.error("dial was missing from message"),{type:M.MessageType.DIAL_RESPONSE,dialResponse:{status:M.ResponseStatus.E_BAD_REQUEST,statusText:"No Dial message found in message"}};let i,u=s.peer;if(u?.id==null)return this.log.error("PeerId missing from message"),{type:M.MessageType.DIAL_RESPONSE,dialResponse:{status:M.ResponseStatus.E_BAD_REQUEST,statusText:"missing peer info"}};try{let c=ee(u.id);i=Vs(c)}catch(c){return this.log.error("invalid PeerId",c),{type:M.MessageType.DIAL_RESPONSE,dialResponse:{status:M.ResponseStatus.E_BAD_REQUEST,statusText:"bad peer id"}}}if(this.log("incoming request from %p",i),!e.remotePeer.equals(i))return this.log("target peer %p did not equal sending peer %p",i,e.remotePeer),{type:M.MessageType.DIAL_RESPONSE,dialResponse:{status:M.ResponseStatus.E_BAD_REQUEST,statusText:"peer id mismatch"}};let f=u.addrs.map(c=>Ie(c)).filter(c=>{let d=c.toOptions().host===e.remoteAddr.toOptions().host;return this.log.trace("request to dial %a was sent from %a is same host %s",c,e.remoteAddr,d),d}).filter(c=>{let d=c.toOptions().host,y=!(ro(d)??!1);return this.log.trace("host %s was public %s",d,y),y}).filter(c=>{let d=c.toOptions().host,y=!o.includes(d);return this.log.trace("host %s was not our host %s",d,y),y}).filter(c=>{let d=!!this.components.transportManager.dialTransportForMultiaddr(c);return this.log.trace("transport for %a is supported %s",c,d),d}).map(c=>(c.getPeerId()==null&&(c=c.encapsulate(`/p2p/${i.toString()}`)),c));if(f.length===0)return this.log("no valid multiaddrs for %p in message",i),{type:M.MessageType.DIAL_RESPONSE,dialResponse:{status:M.ResponseStatus.E_DIAL_REFUSED,statusText:"no dialable addresses"}};this.log("dial multiaddrs %s for peer %p",f.map(c=>c.toString()).join(", "),i);let a="",l=f[0];for await(let c of f){let d;l=c;try{if(d=await this.components.connectionManager.openConnection(c,n),!d.remoteAddr.equals(c))throw this.log.error("tried to dial %a but dialed %a",c,d.remoteAddr),new Error("Unexpected remote address");return this.log("Success %p",i),{type:M.MessageType.DIAL_RESPONSE,dialResponse:{status:M.ResponseStatus.OK,addr:d.remoteAddr.decapsulateCode(q("p2p").code).bytes}}}catch(y){this.log("could not dial %p",i,y),a=y.message}finally{d!=null&&await d.close()}}return{type:M.MessageType.DIAL_RESPONSE,dialResponse:{status:M.ResponseStatus.E_DIAL_ERROR,statusText:a,addr:l.bytes}}}async verifyExternalAddresses(){if(clearTimeout(this.verifyAddressTimeout),!this.isStarted())return;let t=this.components.addressManager,e=t.getObservedAddrs().filter(s=>{let i=s.toOptions();return!(ro(i.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);Vr(1/0,n);let o=this;try{this.log("verify multiaddrs %s",e.map(a=>a.toString()).join(", "));let s=M.encode({type:M.MessageType.DIAL,dial:{peer:{id:this.components.peerId.toMultihash().bytes,addrs:e.map(a=>a.bytes)}}}),i={},u=[],f=async a=>{let l=()=>{};try{this.log("asking %p to verify multiaddr",a.id);let c=await o.components.connectionManager.openConnection(a.id,{signal:n}),d=await c.newStream(this.protocol,{signal:n});l=()=>{d.abort(new De)},n.addEventListener("abort",l,{once:!0});let y=await vo([s],p=>Xe(p),d,p=>Le(p),async p=>yo(p));if(y==null){this.log("no response received from %p",c.remotePeer);return}let m=M.decode(y);if(m.type!==M.MessageType.DIAL_RESPONSE||m.dialResponse==null){this.log("invalid autonat response from %p",c.remotePeer);return}if(m.dialResponse.status===M.ResponseStatus.OK){let p=c.remoteAddr.toOptions(),h;if(p.family===4)h=p.host.split(".")[0];else if(p.family===6)h=p.host.split(":")[0];else{this.log('remote address "%s" was not IP4 or IP6?',p.host);return}if(u.includes(h)){this.log("already have response from network segment %d - %s",h,p.host);return}u.push(h)}return m.dialResponse}catch(c){this.log.error("error asking remote to verify multiaddr",c)}finally{n.removeEventListener("abort",l)}};for await(let a of xo(ui(this.components.randomWalk.walk({signal:n}),l=>async()=>f(l)),{concurrency:Ao}))try{if(a==null)continue;let l=a.addr==null?e[0]:Ie(a.addr);if(this.log("autonat response for %a is %s",l,a.status),a.status===M.ResponseStatus.E_BAD_REQUEST||a.status===M.ResponseStatus.E_DIAL_REFUSED||a.addr==null&&e.length>1)continue;if(!e.some(d=>d.equals(l))){this.log("peer reported %a as %s but it was not in our observed address list",l,a.status);continue}let c=l.toString();if(i[c]==null&&(i[c]={success:0,failure:0}),a.status===M.ResponseStatus.OK?i[c].success++:a.status===M.ResponseStatus.E_DIAL_ERROR&&i[c].failure++,i[c].success===Ao){this.log("%a is externally dialable",l),t.confirmObservedAddr(l);return}if(i[c].failure===Ao){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 af(r={}){return t=>new Kr(t,r)}return Di(cf);})();
|
|
3
|
+
/*! Bundled license information:
|
|
4
|
+
|
|
5
|
+
@noble/hashes/esm/utils.js:
|
|
6
|
+
(*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
7
|
+
|
|
8
|
+
@noble/curves/esm/abstract/utils.js:
|
|
9
|
+
(*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
10
|
+
|
|
11
|
+
@noble/curves/esm/abstract/modular.js:
|
|
12
|
+
(*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
13
|
+
|
|
14
|
+
@noble/curves/esm/abstract/curve.js:
|
|
15
|
+
(*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
16
|
+
|
|
17
|
+
@noble/curves/esm/abstract/edwards.js:
|
|
18
|
+
(*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
19
|
+
|
|
20
|
+
@noble/curves/esm/ed25519.js:
|
|
21
|
+
(*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
22
|
+
|
|
23
|
+
@noble/curves/esm/abstract/weierstrass.js:
|
|
24
|
+
(*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
25
|
+
|
|
26
|
+
@noble/curves/esm/_shortw_utils.js:
|
|
27
|
+
(*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
28
|
+
|
|
29
|
+
@noble/curves/esm/secp256k1.js:
|
|
30
|
+
(*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
31
|
+
*/
|
|
3
32
|
return Libp2PAutonat}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"autonat.d.ts","sourceRoot":"","sources":["../../src/autonat.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"autonat.d.ts","sourceRoot":"","sources":["../../src/autonat.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AACvE,OAAO,KAAK,EAAwC,SAAS,EAAgB,MAAM,mBAAmB,CAAA;AACtG,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAA;AAOpE,qBAAa,cAAe,YAAW,SAAS;IAC9C,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAmB;IAC9C,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAQ;IACrC,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAQ;IACxC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAQ;IACjC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAQ;IAChC,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAQ;IAC1C,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAQ;IAC3C,OAAO,CAAC,oBAAoB,CAAC,CAA+B;IAC5D,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAQ;gBAEf,UAAU,EAAE,iBAAiB,EAAE,IAAI,EAAE,kBAAkB;IAapE,QAAQ,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,qBAAoB;IAEjD,SAAS,IAAK,OAAO;IAIf,KAAK,IAAK,OAAO,CAAC,IAAI,CAAC;IAoBvB,IAAI,IAAK,OAAO,CAAC,IAAI,CAAC;IAO5B;;OAEG;IACG,2BAA2B,CAAE,IAAI,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC;IAmE3E,wBAAwB,IAAK,IAAI;YAOnB,oBAAoB;IAoKlC;;OAEG;IACG,uBAAuB,IAAK,OAAO,CAAC,IAAI,CAAC;CAyLhD"}
|
package/dist/src/autonat.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { AbortError, setMaxListeners } from '@libp2p/interface';
|
|
2
|
+
import { peerIdFromMultihash } from '@libp2p/peer-id';
|
|
3
3
|
import { isPrivateIp } from '@libp2p/utils/private-ip';
|
|
4
4
|
import { multiaddr, protocols } from '@multiformats/multiaddr';
|
|
5
5
|
import first from 'it-first';
|
|
@@ -7,6 +7,7 @@ import * as lp from 'it-length-prefixed';
|
|
|
7
7
|
import map from 'it-map';
|
|
8
8
|
import parallel from 'it-parallel';
|
|
9
9
|
import { pipe } from 'it-pipe';
|
|
10
|
+
import * as Digest from 'multiformats/hashes/digest';
|
|
10
11
|
import { MAX_INBOUND_STREAMS, MAX_OUTBOUND_STREAMS, PROTOCOL_NAME, PROTOCOL_PREFIX, PROTOCOL_VERSION, REFRESH_INTERVAL, STARTUP_DELAY, TIMEOUT } from './constants.js';
|
|
11
12
|
import { Message } from './pb/index.js';
|
|
12
13
|
// if more than 3 peers manage to dial us on what we believe to be our external
|
|
@@ -67,7 +68,7 @@ export class AutoNATService {
|
|
|
67
68
|
async handleIncomingAutonatStream(data) {
|
|
68
69
|
const signal = AbortSignal.timeout(this.timeout);
|
|
69
70
|
const onAbort = () => {
|
|
70
|
-
data.stream.abort(new
|
|
71
|
+
data.stream.abort(new AbortError());
|
|
71
72
|
};
|
|
72
73
|
signal.addEventListener('abort', onAbort, { once: true });
|
|
73
74
|
// this controller may be used while dialing lots of peers so prevent MaxListenersExceededWarning
|
|
@@ -148,7 +149,8 @@ export class AutoNATService {
|
|
|
148
149
|
};
|
|
149
150
|
}
|
|
150
151
|
try {
|
|
151
|
-
|
|
152
|
+
const digest = Digest.decode(peer.id);
|
|
153
|
+
peerId = peerIdFromMultihash(digest);
|
|
152
154
|
}
|
|
153
155
|
catch (err) {
|
|
154
156
|
this.log.error('invalid PeerId', err);
|
|
@@ -290,7 +292,7 @@ export class AutoNATService {
|
|
|
290
292
|
type: Message.MessageType.DIAL,
|
|
291
293
|
dial: {
|
|
292
294
|
peer: {
|
|
293
|
-
id: this.components.peerId.
|
|
295
|
+
id: this.components.peerId.toMultihash().bytes,
|
|
294
296
|
addrs: multiaddrs.map(map => map.bytes)
|
|
295
297
|
}
|
|
296
298
|
}
|
|
@@ -307,7 +309,7 @@ export class AutoNATService {
|
|
|
307
309
|
const stream = await connection.newStream(this.protocol, {
|
|
308
310
|
signal
|
|
309
311
|
});
|
|
310
|
-
onAbort = () => { stream.abort(new
|
|
312
|
+
onAbort = () => { stream.abort(new AbortError()); };
|
|
311
313
|
signal.addEventListener('abort', onAbort, { once: true });
|
|
312
314
|
const buf = await pipe([request], (source) => lp.encode(source), stream, (source) => lp.decode(source), async (stream) => first(stream));
|
|
313
315
|
if (buf == null) {
|