@libp2p/dcutr 2.0.37 → 2.0.38-a02cb0461
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +4 -4
- package/dist/src/dcutr.d.ts.map +1 -1
- package/dist/src/dcutr.js +43 -55
- package/dist/src/dcutr.js.map +1 -1
- package/dist/src/utils.js +1 -1
- package/dist/src/utils.js.map +1 -1
- package/package.json +10 -11
- package/src/dcutr.ts +47 -56
- package/src/utils.ts +1 -1
- package/dist/typedoc-urls.json +0 -10
package/dist/index.min.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PDcutr = factory()}(typeof self !== 'undefined' ? self : this, function () {
|
|
2
|
-
"use strict";var Libp2PDcutr=(()=>{var no=Object.create;var Jt=Object.defineProperty;var oo=Object.getOwnPropertyDescriptor;var so=Object.getOwnPropertyNames;var io=Object.getPrototypeOf,ao=Object.prototype.hasOwnProperty;var co=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),_=(r,t)=>{for(var e in t)Jt(r,e,{get:t[e],enumerable:!0})},zr=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of so(t))!ao.call(r,o)&&o!==e&&Jt(r,o,{get:()=>t[o],enumerable:!(n=oo(t,o))||n.enumerable});return r};var uo=(r,t,e)=>(e=r!=null?no(io(r)):{},zr(t||!r||!r.__esModule?Jt(e,"default",{value:r,enumerable:!0}):e,r)),ho=r=>zr(Jt({},"__esModule",{value:!0}),r);var Zn=co(Xt=>{(function(){var r,t,e,n,o,s,i,a;a=function(u){var c,l,h,d;return c=(u&255<<24)>>>24,l=(u&255<<16)>>>16,h=(u&65280)>>>8,d=u&255,[c,l,h,d].join(".")},i=function(u){var c,l,h,d,v,p;for(c=[],h=d=0;d<=3&&u.length!==0;h=++d){if(h>0){if(u[0]!==".")throw new Error("Invalid IP");u=u.substring(1)}p=t(u),v=p[0],l=p[1],u=u.substring(l),c.push(v)}if(u.length!==0)throw new Error("Invalid IP");switch(c.length){case 1:if(c[0]>4294967295)throw new Error("Invalid IP");return c[0]>>>0;case 2:if(c[0]>255||c[1]>16777215)throw new Error("Invalid IP");return(c[0]<<24|c[1])>>>0;case 3:if(c[0]>255||c[1]>255||c[2]>65535)throw new Error("Invalid IP");return(c[0]<<24|c[1]<<16|c[2])>>>0;case 4:if(c[0]>255||c[1]>255||c[2]>255||c[3]>255)throw new Error("Invalid IP");return(c[0]<<24|c[1]<<16|c[2]<<8|c[3])>>>0;default:throw new Error("Invalid IP")}},e=function(u){return u.charCodeAt(0)},n=e("0"),s=e("a"),o=e("A"),t=function(u){var c,l,h,d,v;for(d=0,c=10,l="9",h=0,u.length>1&&u[h]==="0"&&(u[h+1]==="x"||u[h+1]==="X"?(h+=2,c=16):"0"<=u[h+1]&&u[h+1]<="9"&&(h++,c=8,l="7")),v=h;h<u.length;){if("0"<=u[h]&&u[h]<=l)d=d*c+(e(u[h])-n)>>>0;else if(c===16)if("a"<=u[h]&&u[h]<="f")d=d*c+(10+e(u[h])-s)>>>0;else if("A"<=u[h]&&u[h]<="F")d=d*c+(10+e(u[h])-o)>>>0;else break;else break;if(d>4294967295)throw new Error("too large");h++}if(h===v)throw new Error("empty octet");return[d,h]},r=function(){function u(c,l){var h,d,v,p;if(typeof c!="string")throw new Error("Missing `net' parameter");if(l||(p=c.split("/",2),c=p[0],l=p[1]),l||(l=32),typeof l=="string"&&l.indexOf(".")>-1){try{this.maskLong=i(l)}catch(I){throw h=I,new Error("Invalid mask: "+l)}for(d=v=32;v>=0;d=--v)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(c)&this.maskLong)>>>0}catch(I){throw h=I,new Error("Invalid net address: "+c)}if(!(this.bitmask<=32))throw new Error("Invalid mask for ip4: "+l);this.size=Math.pow(2,32-this.bitmask),this.base=a(this.netLong),this.mask=a(this.maskLong),this.hostmask=a(~this.maskLong),this.first=this.bitmask<=30?a(this.netLong+1):this.base,this.last=this.bitmask<=30?a(this.netLong+this.size-2):a(this.netLong+this.size-1),this.broadcast=this.bitmask<=30?a(this.netLong+this.size-1):void 0}return u.prototype.contains=function(c){return typeof c=="string"&&(c.indexOf("/")>0||c.split(".").length!==4)&&(c=new u(c)),c instanceof u?this.contains(c.base)&&this.contains(c.broadcast||c.last):(i(c)&this.maskLong)>>>0===(this.netLong&this.maskLong)>>>0},u.prototype.next=function(c){return c==null&&(c=1),new u(a(this.netLong+this.size*c),this.mask)},u.prototype.forEach=function(c){var l,h,d;for(d=i(this.first),h=i(this.last),l=0;d<=h;)c(a(d),d,l),l++,d++},u.prototype.toString=function(){return this.base+"/"+this.bitmask},u}(),Xt.ip2long=i,Xt.long2ip=a,Xt.Netmask=r}).call(Xt)});var Ti={};_(Ti,{dcutr:()=>Ai,multicodec:()=>At});var H=class extends Error{static name="InvalidMessageError";constructor(t="Invalid message"){super(t),this.name="InvalidMessageError"}};var _i=Symbol.for("@libp2p/service-capabilities"),Vr=Symbol.for("@libp2p/service-dependencies");var Pe={};_(Pe,{base10:()=>bo});var Yi=new Uint8Array(0);function $r(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 X(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 Gr(r){return new TextDecoder().decode(r)}function lo(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 a=r.length,u=r.charAt(0),c=Math.log(a)/Math.log(256),l=Math.log(256)/Math.log(a);function h(p){if(p instanceof Uint8Array||(ArrayBuffer.isView(p)?p=new Uint8Array(p.buffer,p.byteOffset,p.byteLength):Array.isArray(p)&&(p=Uint8Array.from(p))),!(p instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(p.length===0)return"";for(var I=0,ot=0,B=0,V=p.length;B!==V&&p[B]===0;)B++,I++;for(var $=(V-B)*l+1>>>0,U=new Uint8Array($);B!==V;){for(var W=p[B],K=0,M=$-1;(W!==0||K<ot)&&M!==-1;M--,K++)W+=256*U[M]>>>0,U[M]=W%a>>>0,W=W/a>>>0;if(W!==0)throw new Error("Non-zero carry");ot=K,B++}for(var q=$-ot;q!==$&&U[q]===0;)q++;for(var Qt=u.repeat(I);q<$;++q)Qt+=r.charAt(U[q]);return Qt}function d(p){if(typeof p!="string")throw new TypeError("Expected String");if(p.length===0)return new Uint8Array;var I=0;if(p[I]!==" "){for(var ot=0,B=0;p[I]===u;)ot++,I++;for(var V=(p.length-I)*c+1>>>0,$=new Uint8Array(V);p[I];){var U=e[p.charCodeAt(I)];if(U===255)return;for(var W=0,K=V-1;(U!==0||W<B)&&K!==-1;K--,W++)U+=a*$[K]>>>0,$[K]=U%256>>>0,U=U/256>>>0;if(U!==0)throw new Error("Non-zero carry");B=W,I++}if(p[I]!==" "){for(var M=V-B;M!==V&&$[M]===0;)M++;for(var q=new Uint8Array(ot+(V-M)),Qt=ot;M!==V;)q[Qt++]=$[M++];return q}}}function v(p){var I=d(p);if(I)return I;throw new Error(`Non-${t} character`)}return{encode:h,decodeUnsafe:d,decode:v}}var fo=lo,po=fo,qr=po;var ve=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")}},Se=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,e,n){this.name=t,this.prefix=e;let o=e.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,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 Hr(this,t)}},Ae=class{decoders;constructor(t){this.decoders=t}or(t){return Hr(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 Hr(r,t){return new Ae({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var Te=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 ve(t,e,n),this.decoder=new Se(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function ft({name:r,prefix:t,encode:e,decode:n}){return new Te(r,t,e,n)}function Z({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=qr(e,r);return ft({prefix:t,name:r,encode:n,decode:s=>X(o(s))})}function mo(r,t,e,n){let o=r.length;for(;r[o-1]==="=";)--o;let s=new Uint8Array(o*e/8|0),i=0,a=0,u=0;for(let c=0;c<o;++c){let l=t[r[c]];if(l===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<e|l,i+=e,i>=8&&(i-=8,s[u++]=255&a>>i)}if(i>=e||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function go(r,t,e){let n=t[t.length-1]==="=",o=(1<<e)-1,s="",i=0,a=0;for(let u=0;u<r.length;++u)for(a=a<<8|r[u],i+=8;i>e;)i-=e,s+=t[o&a>>i];if(i!==0&&(s+=t[o&a<<e-i]),n)for(;(s.length*e&7)!==0;)s+="=";return s}function xo(r){let t={};for(let e=0;e<r.length;++e)t[r[e]]=e;return t}function E({name:r,prefix:t,bitsPerChar:e,alphabet:n}){let o=xo(n);return ft({prefix:t,name:r,encode(s){return go(s,n,e)},decode(s){return mo(s,o,e,r)}})}var bo=Z({prefix:"9",name:"base10",alphabet:"0123456789"});var Ne={};_(Ne,{base16:()=>wo,base16upper:()=>yo});var wo=E({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),yo=E({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var _e={};_(_e,{base2:()=>Eo});var Eo=E({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Oe={};_(Oe,{base256emoji:()=>So});var Xr=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}"),Io=Xr.reduce((r,t,e)=>(r[e]=t,r),[]),Co=Xr.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function Do(r){return r.reduce((t,e)=>(t+=Io[e],t),"")}function vo(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let o=Co[n];if(o==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(o)}return new Uint8Array(t)}var So=ft({prefix:"\u{1F680}",name:"base256emoji",encode:Do,decode:vo});var Le={};_(Le,{base32:()=>Y,base32hex:()=>No,base32hexpad:()=>Oo,base32hexpadupper:()=>Lo,base32hexupper:()=>_o,base32pad:()=>To,base32padupper:()=>Po,base32upper:()=>Ao,base32z:()=>Uo});var Y=E({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Ao=E({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),To=E({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Po=E({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),No=E({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),_o=E({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Oo=E({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Lo=E({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Uo=E({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Ue={};_(Ue,{base36:()=>Tt,base36upper:()=>Fo});var Tt=Z({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Fo=Z({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Fe={};_(Fe,{base58btc:()=>F,base58flickr:()=>Ro});var F=Z({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Ro=Z({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Be={};_(Be,{base64:()=>Bo,base64pad:()=>Mo,base64url:()=>Re,base64urlpad:()=>ko});var Bo=E({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Mo=E({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Re=E({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),ko=E({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Me={};_(Me,{base8:()=>zo});var zo=E({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var ke={};_(ke,{identity:()=>Vo});var Vo=ft({prefix:"\0",name:"identity",encode:r=>Gr(r),decode:r=>Wr(r)});var ma=new TextEncoder,ga=new TextDecoder;var Ve={};_(Ve,{identity:()=>hs});var Go=Kr,Qr=128,jo=127,qo=~jo,Ho=Math.pow(2,31);function Kr(r,t,e){t=t||[],e=e||0;for(var n=e;r>=Ho;)t[e++]=r&255|Qr,r/=128;for(;r&qo;)t[e++]=r&255|Qr,r>>>=7;return t[e]=r|0,Kr.bytes=e-n+1,t}var Xo=ze,Qo=128,Jr=127;function ze(r,n){var e=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw ze.bytes=0,new RangeError("Could not decode varint");i=r[s++],e+=o<28?(i&Jr)<<o:(i&Jr)*Math.pow(2,o),o+=7}while(i>=Qo);return ze.bytes=s-n,e}var Jo=Math.pow(2,7),Ko=Math.pow(2,14),Zo=Math.pow(2,21),Yo=Math.pow(2,28),ts=Math.pow(2,35),es=Math.pow(2,42),rs=Math.pow(2,49),ns=Math.pow(2,56),os=Math.pow(2,63),ss=function(r){return r<Jo?1:r<Ko?2:r<Zo?3:r<Yo?4:r<ts?5:r<es?6:r<rs?7:r<ns?8:r<os?9:10},is={encode:Go,decode:Xo,encodingLength:ss},as=is,Pt=as;function Nt(r,t=0){return[Pt.decode(r,t),Pt.decode.bytes]}function dt(r,t,e=0){return Pt.encode(r,t,e),t}function pt(r){return Pt.encodingLength(r)}function st(r,t){let e=t.byteLength,n=pt(r),o=n+pt(e),s=new Uint8Array(o+e);return dt(r,s,0),dt(e,s,n),s.set(t,o),new mt(r,e,t,s)}function Zr(r){let t=X(r),[e,n]=Nt(t),[o,s]=Nt(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new mt(e,o,i,t)}function Yr(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&$r(r.bytes,e.bytes)}}var mt=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=n,this.bytes=o}};var tn=0,cs="identity",en=X;function us(r){return st(tn,en(r))}var hs={code:tn,name:cs,encode:en,digest:us};var Ge={};_(Ge,{sha256:()=>ls,sha512:()=>fs});function We({name:r,code:t,encode:e}){return new $e(r,t,e)}var $e=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?st(this.code,e):e.then(n=>st(this.code,n))}else throw Error("Unknown type, must be binary type")}};function nn(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var ls=We({name:"sha2-256",code:18,encode:nn("SHA-256")}),fs=We({name:"sha2-512",code:19,encode:nn("SHA-512")});function on(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return ps(e,je(r),t??F.encoder);default:return ms(e,je(r),t??Y.encoder)}}var sn=new WeakMap;function je(r){let t=sn.get(r);if(t==null){let e=new Map;return sn.set(r,e),e}return t}var tt=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!==Ot)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==gs)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=st(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&&Yr(t.multihash,n.multihash)}toString(t){return on(this,t)}toJSON(){return{"/":on(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??an(n,o,s.bytes))}else if(e[xs]===!0){let{version:n,multihash:o,code:s}=e,i=Zr(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!==Ot)throw new Error(`Version 0 CID must use dag-pb (code: ${Ot}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=an(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,Ot,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=X(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 mt(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[h,d]=Nt(t.subarray(e));return e+=d,h},o=n(),s=Ot;if(o===18?(o=0,e=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=e,a=n(),u=n(),c=e+u,l=c-i;return{version:o,codec:s,multihashCode:a,digestSize:u,multihashSize:l,size:c}}static parse(t,e){let[n,o]=ds(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 je(s).set(n,t),s}};function ds(r,t){switch(r[0]){case"Q":{let e=t??F;return[F.prefix,e.decode(`${F.prefix}${r}`)]}case F.prefix:{let e=t??F;return[F.prefix,e.decode(r)]}case Y.prefix:{let e=t??Y;return[Y.prefix,e.decode(r)]}case Tt.prefix:{let e=t??Tt;return[Tt.prefix,e.decode(r)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],t.decode(r)]}}}function ps(r,t,e){let{prefix:n}=e;if(n!==F.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 ms(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 Ot=112,gs=18;function an(r,t,e){let n=pt(r),o=n+pt(t),s=new Uint8Array(o+e.byteLength);return dt(r,s,0),dt(t,s,n),s.set(e,o),s}var xs=Symbol.for("@ipld/js-cid/CID");var Lt={...ke,..._e,...Me,...Pe,...Ne,...Le,...Ue,...Fe,...Be,...Oe},Ma={...Ge,...Ve};function Q(r=0){return new Uint8Array(r)}function P(r=0){return new Uint8Array(r)}function un(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var cn=un("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),qe=un("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=P(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),bs={utf8:cn,"utf-8":cn,hex:Lt.base16,latin1:qe,ascii:qe,binary:qe,...Lt},Zt=bs;function R(r,t="utf8"){let e=Zt[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var D=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},J=class extends Error{static name="ValidationError";name="ValidationError"},Ut=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},Yt=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};function te(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 G(r,t="utf8"){let e=Zt[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}var ws=Math.pow(2,7),ys=Math.pow(2,14),Es=Math.pow(2,21),He=Math.pow(2,28),Xe=Math.pow(2,35),Qe=Math.pow(2,42),Je=Math.pow(2,49),x=128,S=127;function N(r){if(r<ws)return 1;if(r<ys)return 2;if(r<Es)return 3;if(r<He)return 4;if(r<Xe)return 5;if(r<Qe)return 6;if(r<Je)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function gt(r,t,e=0){switch(N(r)){case 8:t[e++]=r&255|x,r/=128;case 7:t[e++]=r&255|x,r/=128;case 6:t[e++]=r&255|x,r/=128;case 5:t[e++]=r&255|x,r/=128;case 4:t[e++]=r&255|x,r>>>=7;case 3:t[e++]=r&255|x,r>>>=7;case 2:t[e++]=r&255|x,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function Is(r,t,e=0){switch(N(r)){case 8:t.set(e++,r&255|x),r/=128;case 7:t.set(e++,r&255|x),r/=128;case 6:t.set(e++,r&255|x),r/=128;case 5:t.set(e++,r&255|x),r/=128;case 4:t.set(e++,r&255|x),r>>>=7;case 3:t.set(e++,r&255|x),r>>>=7;case 2:t.set(e++,r&255|x),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function Ke(r,t){let e=r[t],n=0;if(n+=e&S,e<x||(e=r[t+1],n+=(e&S)<<7,e<x)||(e=r[t+2],n+=(e&S)<<14,e<x)||(e=r[t+3],n+=(e&S)<<21,e<x)||(e=r[t+4],n+=(e&S)*He,e<x)||(e=r[t+5],n+=(e&S)*Xe,e<x)||(e=r[t+6],n+=(e&S)*Qe,e<x)||(e=r[t+7],n+=(e&S)*Je,e<x))return n;throw new RangeError("Could not decode varint")}function Cs(r,t){let e=r.get(t),n=0;if(n+=e&S,e<x||(e=r.get(t+1),n+=(e&S)<<7,e<x)||(e=r.get(t+2),n+=(e&S)<<14,e<x)||(e=r.get(t+3),n+=(e&S)<<21,e<x)||(e=r.get(t+4),n+=(e&S)*He,e<x)||(e=r.get(t+5),n+=(e&S)*Xe,e<x)||(e=r.get(t+6),n+=(e&S)*Qe,e<x)||(e=r.get(t+7),n+=(e&S)*Je,e<x))return n;throw new RangeError("Could not decode varint")}function hn(r,t,e=0){return t==null&&(t=P(N(r))),t instanceof Uint8Array?gt(r,t,e):Is(r,t,e)}function Ft(r,t=0){return r instanceof Uint8Array?Ke(r,t):Cs(r,t)}function et(r,t){t==null&&(t=r.reduce((o,s)=>o+s.length,0));let e=P(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return e}var ee=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,a=this.peekChar();if(a===void 0)return;let u=a==="0",c=2**(8*o)-1;for(;;){let l=this.readAtomically(()=>{let h=this.readChar();if(h===void 0)return;let d=Number.parseInt(h,t);if(!Number.isNaN(d))return d});if(l===void 0)break;if(s*=t,s+=l,s>c||(i+=1,e!==void 0&&i>e))return}if(i!==0)return!n&&u&&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),[a]=t(s.subarray(0,i));return e.set(s.subarray(0,a),16-a),e})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var Ds=45,vs=15,re=new ee;function Ze(r){if(!(r.length>vs))return re.new(r).parseWith(()=>re.readIPv4Addr())}function Ye(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>Ds))return re.new(r).parseWith(()=>re.readIPv6Addr())}function xt(r){return!!Ze(r)}function ne(r){return!!Ye(r)}function er(r){return t=>R(t,r)}function rr(r){return t=>G(t,r)}function bt(r){return new DataView(r.buffer).getUint16(r.byteOffset).toString()}function it(r){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,typeof r=="string"?parseInt(r):r),new Uint8Array(t)}function dn(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=G(t[0],"base32"),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=it(n);return et([e,o],e.length+o.length)}function pn(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=Y.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=it(n);return et([e,o],e.length+o.length)}function nr(r){let t=r.subarray(0,r.length-2),e=r.subarray(r.length-2),n=R(t,"base32"),o=bt(e);return`${n}:${o}`}var or=function(r){r=r.toString().trim();let t=new Uint8Array(4);return r.split(/\./g).forEach((e,n)=>{let o=parseInt(e,10);if(isNaN(o)||o<0||o>255)throw new D("Invalid byte value in IP address");t[n]=o}),t},mn=function(r){let t=0;r=r.toString().trim();let e=r.split(":",8),n;for(n=0;n<e.length;n++){let s=xt(e[n]),i;s&&(i=or(e[n]),e[n]=R(i.subarray(0,2),"base16")),i!=null&&++n<8&&e.splice(n,0,R(i.subarray(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++){e[n]===""&&(e[n]="0");let s=parseInt(e[n],16);if(isNaN(s)||s<0||s>65535)throw new D("Invalid byte value in IP address");o[t++]=s>>8&255,o[t++]=s&255}return o},gn=function(r){if(r.byteLength!==4)throw new D("IPv4 address was incorrect length");let t=[];for(let e=0;e<r.byteLength;e++)t.push(r[e]);return t.join(".")},xn=function(r){if(r.byteLength!==16)throw new D("IPv6 address was incorrect length");let t=[];for(let n=0;n<r.byteLength;n+=2){let o=r[n],s=r[n+1],i=`${o.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}`;t.push(i)}let e=t.join(":");try{let n=new URL(`http://[${e}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new D(`Invalid IPv6 address "${e}"`)}};function bn(r){try{let t=new URL(`http://[${r}]`);return t.hostname.substring(1,t.hostname.length-1)}catch{throw new D(`Invalid IPv6 address "${r}"`)}}var tr=Object.values(Lt).map(r=>r.decoder),Ss=function(){let r=tr[0].or(tr[1]);return tr.slice(2).forEach(t=>r=r.or(t)),r}();function wn(r){return Ss.decode(r)}function yn(r){return t=>r.encoder.encode(t)}function As(r){if(parseInt(r).toString()!==r)throw new J("Value must be an integer")}function Ts(r){if(r<0)throw new J("Value must be a positive integer, or zero")}function Ps(r){return t=>{if(t>r)throw new J(`Value must be smaller than or equal to ${r}`)}}function Ns(...r){return t=>{for(let e of r)e(t)}}var Rt=Ns(As,Ts,Ps(65535));var C=-1,sr=class{protocolsByCode=new Map;protocolsByName=new Map;getProtocol(t){let e;if(typeof t=="string"?e=this.protocolsByName.get(t):e=this.protocolsByCode.get(t),e==null)throw new Yt(`Protocol ${t} was unknown`);return e}addProtocol(t){this.protocolsByCode.set(t.code,t),this.protocolsByName.set(t.name,t),t.aliases?.forEach(e=>{this.protocolsByName.set(e,t)})}removeProtocol(t){let e=this.protocolsByCode.get(t);e!=null&&(this.protocolsByCode.delete(e.code),this.protocolsByName.delete(e.name),e.aliases?.forEach(n=>{this.protocolsByName.delete(n)}))}},O=new sr,js=[{code:4,name:"ip4",size:32,valueToBytes:or,bytesToValue:gn,validate:r=>{if(!xt(r))throw new J(`Invalid IPv4 address "${r}"`)}},{code:6,name:"tcp",size:16,valueToBytes:it,bytesToValue:bt,validate:Rt},{code:273,name:"udp",size:16,valueToBytes:it,bytesToValue:bt,validate:Rt},{code:33,name:"dccp",size:16,valueToBytes:it,bytesToValue:bt,validate:Rt},{code:41,name:"ip6",size:128,valueToBytes:mn,bytesToValue:xn,stringToValue:bn,validate:r=>{if(!ne(r))throw new J(`Invalid IPv6 address "${r}"`)}},{code:42,name:"ip6zone",size:C},{code:43,name:"ipcidr",size:8,bytesToValue:er("base10"),valueToBytes:rr("base10")},{code:53,name:"dns",size:C,resolvable:!0},{code:54,name:"dns4",size:C,resolvable:!0},{code:55,name:"dns6",size:C,resolvable:!0},{code:56,name:"dnsaddr",size:C,resolvable:!0},{code:132,name:"sctp",size:16,valueToBytes:it,bytesToValue:bt,validate:Rt},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:C,path:!0,stringToValue:r=>decodeURIComponent(r),valueToString:r=>encodeURIComponent(r)},{code:421,name:"p2p",aliases:["ipfs"],size:C,bytesToValue:er("base58btc"),valueToBytes:r=>r.startsWith("Q")||r.startsWith("1")?rr("base58btc")(r):tt.parse(r).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:nr,valueToBytes:dn},{code:445,name:"onion3",size:296,bytesToValue:nr,valueToBytes:pn},{code:446,name:"garlic64",size:C},{code:447,name:"garlic32",size:C},{code:448,name:"tls"},{code:449,name:"sni",size:C},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:C,bytesToValue:yn(Re),valueToBytes:wn},{code:480,name:"http"},{code:481,name:"http-path",size:C,stringToValue:r=>`/${decodeURIComponent(r)}`,valueToString:r=>encodeURIComponent(r.substring(1))},{code:443,name:"https"},{code:477,name:"ws"},{code:478,name:"wss"},{code:479,name:"p2p-websocket-star"},{code:277,name:"p2p-stardust"},{code:275,name:"p2p-webrtc-star"},{code:276,name:"p2p-webrtc-direct"},{code:280,name:"webrtc-direct"},{code:281,name:"webrtc"},{code:290,name:"p2p-circuit"},{code:777,name:"memory",size:C}];js.forEach(r=>{O.addProtocol(r)});function En(r){let t=[],e=0;for(;e<r.length;){let n=Ft(r,e),o=O.getProtocol(n),s=N(n),i=qs(o,r,e+s),a=0;i>0&&o.size===C&&(a=N(i));let u=s+a+i,c={code:n,name:o.name,bytes:r.subarray(e,e+u)};if(i>0){let l=e+s+a,h=r.subarray(l,l+i);c.value=o.bytesToValue?.(h)??R(h)}t.push(c),e+=u}return t}function In(r){let t=0,e=[];for(let n of r){if(n.bytes==null){let o=O.getProtocol(n.code),s=N(n.code),i,a=0,u=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??G(n.value),a=i.byteLength,o.size===C&&(u=N(a)));let c=new Uint8Array(s+u+a),l=0;gt(n.code,c,l),l+=s,i!=null&&(o.size===C&&(gt(a,c,l),l+=u),c.set(i,l)),n.bytes=c}e.push(n.bytes),t+=n.bytes.byteLength}return et(e,t)}function Cn(r){if(r.charAt(0)!=="/")throw new D('String multiaddr must start with "/"');let t=[],e="protocol",n="",o="";for(let s=1;s<r.length;s++){let i=r.charAt(s);i!=="/"&&(e==="protocol"?o+=r.charAt(s):n+=r.charAt(s));let a=s===r.length-1;if(i==="/"||a){let u=O.getProtocol(o);if(e==="protocol"){if(u.size==null||u.size===0){t.push({code:u.code,name:u.name}),n="",o="",e="protocol";continue}else if(a)throw new D(`Component ${o} was missing value`);e="value"}else if(e==="value"){let c={code:u.code,name:u.name};if(u.size!=null&&u.size!==0){if(n==="")throw new D(`Component ${o} was missing value`);c.value=u.stringToValue?.(n)??n}t.push(c),n="",o="",e="protocol"}}}if(o!==""&&n!=="")throw new D("Incomplete multiaddr");return t}function Dn(r){return`/${r.flatMap(t=>{if(t.value==null)return t.name;let e=O.getProtocol(t.code);if(e==null)throw new D(`Unknown protocol code ${t.code}`);return[t.name,e.valueToString?.(t.value)??t.value]}).join("/")}`}function qs(r,t,e){return r.size==null||r.size===0?0:r.size>0?r.size/8:Ft(t,e)}var Hs=Symbol.for("nodejs.util.inspect.custom"),mr=Symbol.for("@multiformats/multiaddr"),Xs=[53,54,55,56],pr=class extends Error{constructor(t="No available resolver"){super(t),this.name="NoAvailableResolverError"}};function Qs(r){if(r==null&&(r="/"),Sn(r))return r.getComponents();if(r instanceof Uint8Array)return En(r);if(typeof r=="string")return r=r.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),r===""&&(r="/"),Cn(r);if(Array.isArray(r))return r;throw new D("Must be a string, Uint8Array, Component[], or another Multiaddr")}var ae=class r{[mr]=!0;#t;#e;#r;constructor(t="/",e={}){this.#t=Qs(t),e.validate!==!1&&Js(this)}get bytes(){return this.#r==null&&(this.#r=In(this.#t)),this.#r}toString(){return this.#e==null&&(this.#e=Dn(this.#t)),this.#e}toJSON(){return this.toString()}toOptions(){let t,e,n,o,s="";for(let{code:a,name:u,value:c}of this.#t)a===42&&(s=`%${c??""}`),Xs.includes(a)&&(e="tcp",o=443,n=`${c??""}${s}`,t=a===55?6:4),(a===6||a===273)&&(e=u==="tcp"?"tcp":"udp",o=parseInt(c??"")),(a===4||a===41)&&(e="tcp",n=`${c??""}${s}`,t=a===41?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}}getComponents(){return[...this.#t]}protos(){return this.#t.map(({code:t,value:e})=>{let n=O.getProtocol(t);return{code:t,size:n.size??0,name:n.name,resolvable:!!n.resolvable,path:!!n.path}})}protoCodes(){return this.#t.map(({code:t})=>t)}protoNames(){return this.#t.map(({name:t})=>t)}tuples(){return this.#t.map(({code:t,value:e})=>{if(e==null)return[t];let n=O.getProtocol(t),o=[t];return e!=null&&o.push(n.valueToBytes?.(e)??G(e)),o})}stringTuples(){return this.#t.map(({code:t,value:e})=>e==null?[t]:[t,e])}encapsulate(t){let e=new r(t);return new r([...this.#t,...e.getComponents()],{validate:!1})}decapsulate(t){let e=t.toString(),n=this.toString(),o=n.lastIndexOf(e);if(o<0)throw new Ut(`Address ${this.toString()} does not contain subaddress: ${t.toString()}`);return new r(n.slice(0,o),{validate:!1})}decapsulateCode(t){let e;for(let n=this.#t.length-1;n>-1;n--)if(this.#t[n].code===t){e=n;break}return new r(this.#t.slice(0,e),{validate:!1})}getPeerId(){try{let t=[];this.#t.forEach(({code:n,value:o})=>{n===421&&t.push([n,o]),n===290&&(t=[])});let e=t.pop();if(e?.[1]!=null){let n=e[1];return n[0]==="Q"||n[0]==="1"?R(F.decode(`z${n}`),"base58btc"):R(tt.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){for(let t of this.#t)if(O.getProtocol(t.code).path)return t.value??null;return null}equals(t){return te(this.bytes,t.bytes)}async resolve(t){let e=this.protos().find(s=>s.resolvable);if(e==null)return[this];let n=vn.get(e.name);if(n==null)throw new pr(`no available resolver for ${e.name}`);return(await n(this,t)).map(s=>$t(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(){return!(this.#t.length!==2||this.#t[0].code!==4&&this.#t[0].code!==41||this.#t[1].code!==6&&this.#t[1].code!==273)}[Hs](){return`Multiaddr(${this.toString()})`}};function Js(r){r.getComponents().forEach(t=>{let e=O.getProtocol(t.code);t.value!=null&&e.validate?.(t.value)})}var Qc=parseInt("0xFFFF",16),Jc=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);var vn=new Map;function Sn(r){return!!r?.[mr]}function $t(r){return new ae(r)}var y=r=>({match:t=>{let e=t[0];return e==null||e.code!==r||e.value!=null?!1:t.slice(1)}}),f=(r,t)=>({match:e=>{let n=e[0];return n?.code!==r||n.value==null||t!=null&&n.value!==t?!1:e.slice(1)}}),m=r=>({match:t=>{let e=r.match(t);return e===!1?t:e}}),A=(...r)=>({match:t=>{let e;for(let n of r){let o=n.match(t);o!==!1&&(e==null||o.length<e.length)&&(e=o)}return e??!1}}),b=(...r)=>({match:t=>{for(let e of r){let n=e.match(t);if(n===!1)return!1;t=n}return t}});function w(...r){function t(o){let s=o.getComponents();for(let i of r){let a=i.match(s);if(a===!1)return!1;s=a}return s}function e(o){return t(o)!==!1}function n(o){let s=t(o);return s===!1?!1:s.length===0}return{matchers:r,matches:e,exactMatch:n}}var ei=f(421),Mu=w(ei),ue=f(54),he=f(55),le=f(56),xr=f(53),ku=w(ue,m(f(421))),zu=w(he,m(f(421))),Vu=w(le,m(f(421))),Pn=w(A(xr,le,ue,he),m(f(421))),Nn=b(f(4),m(f(43))),_n=b(m(f(42)),f(41),m(f(43))),br=A(Nn,_n),ut=A(br,xr,ue,he,le),$u=w(A(br,b(A(xr,le,ue,he),m(f(421))))),Wu=w(Nn),Gu=w(_n),On=w(br),wr=b(ut,f(6)),Wt=b(ut,f(273)),ju=w(b(wr,m(f(421)))),qu=w(Wt),yr=b(Wt,y(460),m(f(421))),fe=b(Wt,y(461),m(f(421))),ri=A(yr,fe),Hu=w(yr),Xu=w(fe),gr=A(ut,wr,Wt,yr,fe),Ln=A(b(gr,y(477),m(f(421)))),Qu=w(Ln),Un=A(b(gr,y(478),m(f(421))),b(gr,y(448),m(f(449)),y(477),m(f(421)))),Ju=w(Un),Fn=b(Wt,y(280),m(f(466)),m(f(466)),m(f(421))),Ku=w(Fn),Rn=b(fe,y(465),m(f(466)),m(f(466)),m(f(421))),Zu=w(Rn),ce=A(Ln,Un,b(wr,m(f(421))),b(ri,m(f(421))),b(ut,m(f(421))),Fn,Rn,f(421)),Yu=w(ce),ni=b(ce,y(290),f(421)),Gt=w(ni),oi=A(b(ce,y(290),y(281),m(f(421))),b(ce,y(281),m(f(421))),b(y(281),m(f(421)))),th=w(oi),si=A(b(ut,f(6),y(480),m(f(421))),b(ut,y(480),m(f(421)))),eh=w(si),ii=b(ut,A(b(f(6,"443"),y(480)),b(f(6),y(443)),b(f(6),y(448),y(480)),b(y(448),y(480)),y(448),y(443)),m(f(421))),rh=w(ii),ai=A(b(f(777),m(f(421)))),nh=w(ai),ci=A(b(f(400),m(f(421)))),oh=w(ci);var Bn=()=>{let r=new Error("Delay aborted");return r.name="AbortError",r},ui=new WeakMap;function hi({clearTimeout:r,setTimeout:t}={}){return(e,{value:n,signal:o}={})=>{if(o?.aborted)return Promise.reject(Bn());let s,i,a,u=r??clearTimeout,c=()=>{u(s),a(Bn())},l=()=>{o&&o.removeEventListener("abort",c)},h=new Promise((d,v)=>{i=()=>{l(),d(n)},a=v,s=(t??setTimeout)(i,e)});return o&&o.addEventListener("abort",c,{once:!0}),ui.set(h,()=>{u(s),s=null,i()}),h}}var li=hi(),Mn=li;function vt(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var de=class extends Error{type;code;constructor(t,e,n){super(t??"The operation was aborted"),this.type="aborted",this.name=n??"AbortError",this.code=e??"ABORT_ERR"}};async function jt(r,t,e){if(t==null)return r;if(t.aborted)return r.catch(()=>{}),Promise.reject(new de(e?.errorMessage,e?.errorCode,e?.errorName));let n,o=new de(e?.errorMessage,e?.errorCode,e?.errorName);try{return await Promise.race([r,new Promise((s,i)=>{n=()=>{i(o)},t.addEventListener("abort",n)})])}finally{n!=null&&t.removeEventListener("abort",n)}}var Er=class{readNext;haveNext;ended;nextResult;error;constructor(){this.ended=!1,this.readNext=vt(),this.haveNext=vt()}[Symbol.asyncIterator](){return this}async next(){if(this.nextResult==null&&await this.haveNext.promise,this.nextResult==null)throw new Error("HaveNext promise resolved but nextResult was undefined");let t=this.nextResult;return this.nextResult=void 0,this.readNext.resolve(),this.readNext=vt(),t}async throw(t){return this.ended=!0,this.error=t,t!=null&&(this.haveNext.promise.catch(()=>{}),this.haveNext.reject(t)),{done:!0,value:void 0}}async return(){let t={done:!0,value:void 0};return this.ended=!0,this.nextResult=t,this.haveNext.resolve(),t}async push(t,e){await this._push(t,e)}async end(t,e){t!=null?await this.throw(t):await this._push(void 0,e)}async _push(t,e){if(t!=null&&this.ended)throw this.error??new Error("Cannot push value onto an ended pushable");for(;this.nextResult!=null;)await this.readNext.promise;t!=null?this.nextResult={done:!1,value:t}:(this.ended=!0,this.nextResult={done:!0,value:void 0}),this.haveNext.resolve(),this.haveNext=vt(),await jt(this.readNext.promise,e?.signal,e)}};function kn(){return new Er}var Vn=Symbol.for("@achingbrain/uint8arraylist");function zn(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 pe(r){return!!r?.[Vn]}var rt=class r{bufs;length;[Vn]=!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(pe(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(pe(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=zn(this.bufs,t);return e.buf[e.index]}set(t,e){let n=zn(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(pe(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 et(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:et(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],a=o,u=a+i.byteLength;if(o=u,t>=u)continue;let c=t>=a&&t<u,l=e>a&&e<=u;if(c&&l){if(t===a&&e===u){n.push(i);break}let h=t-a;n.push(i.subarray(h,h+(e-t)));break}if(c){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(l){if(e===u){n.push(i);break}n.push(i.subarray(0,e-a));break}n.push(i)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!pe(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 h=0;h<s;h++)i[h]=-1;for(let h=0;h<o;h++)i[n[h]]=h;let a=i,u=this.byteLength-n.byteLength,c=n.byteLength-1,l;for(let h=e;h<=u;h+=l){l=0;for(let d=c;d>=0;d--){let v=this.get(h+d);if(n[d]!==v){l=Math.max(1,d-a[v]);break}}if(l===0)return h}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=P(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=Q(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=Q(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=Q(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=P(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=Q(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=Q(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=Q(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=Q(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=Q(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(!te(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}};var me=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};function $n(r,t){let e=kn();r.sink(e).catch(async i=>{await e.end(i)}),r.sink=async i=>{for await(let a of i)await e.push(a);await e.end()};let n=r.source;r.source[Symbol.iterator]!=null?n=r.source[Symbol.iterator]():r.source[Symbol.asyncIterator]!=null&&(n=r.source[Symbol.asyncIterator]());let o=new rt;return{read:async i=>{if(i?.signal?.throwIfAborted(),i?.bytes==null){let{done:u,value:c}=await jt(n.next(),i?.signal);return u===!0?null:c}for(;o.byteLength<i.bytes;){let{value:u,done:c}=await jt(n.next(),i?.signal);if(c===!0)throw new me("unexpected end of input");o.append(u)}let a=o.sublist(0,i.bytes);return o.consume(i.bytes),a},write:async(i,a)=>{a?.signal?.throwIfAborted(),i instanceof Uint8Array?await e.push(i,a):await e.push(i.subarray(),a)},unwrap:()=>{if(o.byteLength>0){let i=r.source;r.source=async function*(){t?.yieldBytes===!1?yield o:yield*o,yield*i}()}return r}}}var ge=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},xe=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},be=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function Wn(r,t={}){let e=$n(r,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=N(t.maxDataLength));let n=t?.lengthDecoder??Ft,o=t?.lengthEncoder??hn;return{read:async i=>{let a=-1,u=new rt;for(;;){u.append(await e.read({...i,bytes:1}));try{a=n(u)}catch(c){if(c instanceof RangeError)continue;throw c}if(a<0)throw new ge("Invalid message length");if(t?.maxLengthLength!=null&&u.byteLength>t.maxLengthLength)throw new be("message length length too long");if(a>-1)break}if(t?.maxDataLength!=null&&a>t.maxDataLength)throw new xe("message length too long");return e.read({...i,bytes:a})},write:async(i,a)=>{await e.write(new rt(o(i.byteLength),i),a)},writeV:async(i,a)=>{let u=new rt(...i.flatMap(c=>[o(c.byteLength),c]));await e.write(u,a)},unwrap:()=>e.unwrap()}}function Ir(r,t){let e=Wn(r,t),n={read:async(o,s)=>{let i=await e.read(s);return o.decode(i)},write:async(o,s,i)=>{await e.write(s.encode(o),i)},writeV:async(o,s,i)=>{await e.writeV(o.map(a=>s.encode(a)),i)},pb:o=>({read:async s=>n.read(o,s),write:async(s,i)=>n.write(s,o,i),writeV:async(s,i)=>n.writeV(s,o,i),unwrap:()=>n}),unwrap:()=>e.unwrap()};return n}var Cr=new Float32Array([-0]),nt=new Uint8Array(Cr.buffer);function Gn(r,t,e){Cr[0]=r,t[e]=nt[0],t[e+1]=nt[1],t[e+2]=nt[2],t[e+3]=nt[3]}function jn(r,t){return nt[0]=r[t],nt[1]=r[t+1],nt[2]=r[t+2],nt[3]=r[t+3],Cr[0]}var Dr=new Float64Array([-0]),T=new Uint8Array(Dr.buffer);function qn(r,t,e){Dr[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 Hn(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],Dr[0]}var fi=BigInt(Number.MAX_SAFE_INTEGER),di=BigInt(Number.MIN_SAFE_INTEGER),L=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 ht;if(t<fi&&t>di)return this.fromNumber(Number(t));let e=t<0n;e&&(t=-t);let n=t>>32n,o=t-(n<<32n);return e&&(n=~n|0n,o=~o|0n,++o>Xn&&(o=0n,++n>Xn&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(t){if(t===0)return ht;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):ht}},ht=new L(0,0);ht.toBigInt=function(){return 0n};ht.zzEncode=ht.zzDecode=function(){return this};ht.length=function(){return 1};var Xn=4294967296n;function Qn(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 Jn(r,t,e){if(e-t<1)return"";let o,s=[],i=0,a;for(;t<e;)a=r[t++],a<128?s[i++]=a:a>191&&a<224?s[i++]=(a&31)<<6|r[t++]&63:a>239&&a<365?(a=((a&7)<<18|(r[t++]&63)<<12|(r[t++]&63)<<6|r[t++]&63)-65536,s[i++]=55296+(a>>10),s[i++]=56320+(a&1023)):s[i++]=(a&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 vr(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 k(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function we(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var Sr=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,k(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 k(this,4);return we(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw k(this,4);return we(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw k(this,4);let t=jn(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw k(this,4);let t=Hn(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 k(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return Jn(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw k(this,t);this.pos+=t}else do if(this.pos>=this.len)throw k(this);while((this.buf[this.pos++]&128)!==0);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 L(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 k(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 k(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 k(this,8);let t=we(this.buf,this.pos+=4),e=we(this.buf,this.pos+=4);return new L(t,e)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=Ke(this.buf,this.pos);return this.pos+=N(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 Ar(r){return new Sr(r instanceof Uint8Array?r:r.subarray())}function Tr(r,t,e){let n=Ar(r);return t.decode(n,void 0,e)}function Pr(r){let t=r??8192,e=t>>>1,n,o=t;return function(i){if(i<1||i>e)return P(i);o+i>t&&(n=P(t),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var lt=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function Nr(){}var Or=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},pi=Pr();function mi(r){return globalThis.Buffer!=null?P(r):pi(r)}var Ht=class{len;head;tail;states;constructor(){this.len=0,this.head=new lt(Nr,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new lt(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Lr((t=t>>>0)<128?1:t<16384?2:t<2097152?3:t<268435456?4:5,t)).len,this}int32(t){return t<0?this._push(ye,10,L.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=L.fromBigInt(t);return this._push(ye,e.length(),e)}uint64Number(t){return this._push(gt,N(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=L.fromBigInt(t).zzEncode();return this._push(ye,e.length(),e)}sint64Number(t){let e=L.fromNumber(t).zzEncode();return this._push(ye,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(_r,1,t?1:0)}fixed32(t){return this._push(qt,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=L.fromBigInt(t);return this._push(qt,4,e.lo)._push(qt,4,e.hi)}fixed64Number(t){let e=L.fromNumber(t);return this._push(qt,4,e.lo)._push(qt,4,e.hi)}fixed64String(t){return this.fixed64(BigInt(t))}sfixed64(t){return this.fixed64(t)}sfixed64Number(t){return this.fixed64Number(t)}sfixed64String(t){return this.fixed64String(t)}float(t){return this._push(Gn,4,t)}double(t){return this._push(qn,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(_r,1,0):this.uint32(e)._push(xi,e,t)}string(t){let e=Qn(t);return e!==0?this.uint32(e)._push(vr,e,t):this._push(_r,1,0)}fork(){return this.states=new Or(this),this.head=this.tail=new lt(Nr,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new lt(Nr,0,0),this.len=0),this}ldelim(){let t=this.head,e=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=e,this.len+=n),this}finish(){let t=this.head.next,e=mi(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function _r(r,t,e){t[e]=r&255}function gi(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var Lr=class extends lt{next;constructor(t,e){super(gi,t,e),this.next=void 0}};function ye(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 qt(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 xi(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(Ht.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(bi,t,r),this},Ht.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(wi,t,r),this});function bi(r,t,e){t.set(r,e)}function wi(r,t,e){r.length<40?vr(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(G(r),e)}function Ur(){return new Ht}function Fr(r,t){let e=Ur();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var St;(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"})(St||(St={}));function Ee(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function Rr(r){function t(o){if(r[o.toString()]==null)throw new Error("Invalid enum value");return r[o]}let e=function(s,i){let a=t(s);i.int32(a)},n=function(s){let i=s.int32();return t(i)};return Ee("enum",St.VARINT,e,n)}function Br(r,t){return Ee("message",St.LENGTH_DELIMITED,r,t)}var Ie=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var z;(function(r){let t;(function(o){o.UNUSED="UNUSED",o.CONNECT="CONNECT",o.SYNC="SYNC"})(t=r.Type||(r.Type={}));let e;(function(o){o[o.UNUSED=0]="UNUSED",o[o.CONNECT=100]="CONNECT",o[o.SYNC=300]="SYNC"})(e||(e={})),function(o){o.codec=()=>Rr(e)}(t=r.Type||(r.Type={}));let n;r.codec=()=>(n==null&&(n=Br((o,s,i={})=>{if(i.lengthDelimited!==!1&&s.fork(),o.type!=null&&(s.uint32(8),r.Type.codec().encode(o.type,s)),o.observedAddresses!=null)for(let a of o.observedAddresses)s.uint32(18),s.bytes(a);i.lengthDelimited!==!1&&s.ldelim()},(o,s,i={})=>{let a={observedAddresses:[]},u=s==null?o.len:o.pos+s;for(;o.pos<u;){let c=o.uint32();switch(c>>>3){case 1:{a.type=r.Type.codec().decode(o);break}case 2:{if(i.limits?.observedAddresses!=null&&a.observedAddresses.length===i.limits.observedAddresses)throw new Ie('Decode error - map field "observedAddresses" had too many elements');a.observedAddresses.push(o.bytes());break}default:{o.skipType(c&7);break}}}return a})),n),r.encode=o=>Fr(o,r.codec()),r.decode=(o,s)=>Tr(o,r.codec(),s)})(z||(z={}));var Yn=uo(Zn(),1),yi=["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"],Ei=yi.map(r=>new Yn.Netmask(r));function Mr(r){for(let t of Ei)if(t.contains(r))return!0;return!1}function Ii(r){return/^::ffff:([0-9a-fA-F]{1,4}):([0-9a-fA-F]{1,4})$/.test(r)}function Ci(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 Mr(o)}function Di(r){return/^::ffff:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(r)}function vi(r){let t=r.split(":"),e=t[t.length-1];return Mr(e)}function Si(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 to(r){if(xt(r))return Mr(r);if(Ii(r))return Ci(r);if(Di(r))return vi(r);if(ne(r))return Si(r)}function kr(r,t){return Gt.matches(r)||t.dialTransportForMultiaddr(r)==null?!1:Pn.matches(r)?!0:On.matches(r)?to(r.toOptions().host)===!1:!1}var eo=1024*4,ro=100,Ce={timeout:5e3,retries:3,maxInboundStreams:1,maxOutboundStreams:1},De=class{started;timeout;retries;maxInboundStreams;maxOutboundStreams;peerStore;registrar;connectionManager;addressManager;transportManager;topologyId;log;constructor(t,e){this.log=t.logger.forComponent("libp2p:dcutr"),this.started=!1,this.peerStore=t.peerStore,this.registrar=t.registrar,this.addressManager=t.addressManager,this.connectionManager=t.connectionManager,this.transportManager=t.transportManager,this.timeout=e.timeout??Ce.timeout,this.retries=e.retries??Ce.retries,this.maxInboundStreams=e.maxInboundStreams??Ce.maxInboundStreams,this.maxOutboundStreams=e.maxOutboundStreams??Ce.maxOutboundStreams}[Symbol.toStringTag]="@libp2p/dcutr";[Vr]=["@libp2p/identify"];isStarted(){return this.started}async start(){this.started||(this.topologyId=await this.registrar.register(At,{notifyOnLimitedConnection:!0,onConnect:(t,e)=>{Gt.exactMatch(e.remoteAddr)&&e.direction==="inbound"&&this.upgradeInbound(e).catch(n=>{this.log.error("error during outgoing DCUtR attempt",n)})}}),await this.registrar.handle(At,t=>{this.handleIncomingUpgrade(t.stream,t.connection).catch(e=>{this.log.error("error during incoming DCUtR attempt",e),t.stream.abort(e)})},{maxInboundStreams:this.maxInboundStreams,maxOutboundStreams:this.maxOutboundStreams,runOnLimitedConnection:!0}),this.started=!0)}async stop(){await this.registrar.unhandle(At),this.topologyId!=null&&this.registrar.unregister(this.topologyId),this.started=!1}async upgradeInbound(t){if(await this.attemptUnilateralConnectionUpgrade(t))return;let e;for(let n=0;n<this.retries;n++){let o={signal:AbortSignal.timeout(this.timeout)};try{e=await t.newStream([At],{signal:o.signal,runOnLimitedConnection:!0});let s=Ir(e,{maxDataLength:eo}).pb(z);this.log("B sending connect to %p",t.remotePeer);let i=Date.now();await s.write({type:z.Type.CONNECT,observedAddresses:this.addressManager.getAddresses().map(h=>h.bytes)},o),this.log("B receiving connect from %p",t.remotePeer);let a=await s.read(o);if(a.type!==z.Type.CONNECT)throw this.log("A sent wrong message type"),new H("DCUtR message type was incorrect");let u=this.getDialableMultiaddrs(a.observedAddresses);if(u.length===0)throw this.log("A did not have any dialable multiaddrs"),new H("DCUtR connect message had no multiaddrs");let c=Date.now()-i;this.log("A sending sync, rtt %dms",c),await s.write({type:z.Type.SYNC,observedAddresses:[]},o),this.log("A waiting for half RTT"),await Mn(c/2),this.log("B dialing",u);let l=await this.connectionManager.openConnection(u,{signal:o.signal,priority:ro,force:!0,initiator:!1});this.log("DCUtR to %p succeeded to address %a, closing relayed connection",t.remotePeer,l.remoteAddr),await t.close(o);break}catch(s){if(this.log.error("error while attempting DCUtR on attempt %d of %d",n+1,this.retries,s),e?.abort(s),n===this.retries)throw s}finally{e!=null&&await e.close(o)}}}async attemptUnilateralConnectionUpgrade(t){let n=(await this.peerStore.get(t.remotePeer)).addresses.map(o=>{let s=o.multiaddr;return s.getPeerId()==null?s.encapsulate(`/p2p/${t.remotePeer}`):s}).filter(o=>kr(o,this.transportManager));if(n.length>0){let o=AbortSignal.timeout(this.timeout);try{this.log("attempting unilateral connection upgrade to %a",n);let s=await this.connectionManager.openConnection(n,{signal:o,force:!0});if(Gt.exactMatch(s.remoteAddr))throw new Error("Could not open a new, non-limited, connection");return this.log("unilateral connection upgrade to %p succeeded via %a, closing relayed connection",t.remotePeer,s.remoteAddr),await t.close({signal:o}),!0}catch(s){this.log.error("unilateral connection upgrade to %p on addresses %a failed",t.remotePeer,n,s)}}else this.log("peer %p has no public addresses, not attempting unilateral connection upgrade",t.remotePeer);return!1}async handleIncomingUpgrade(t,e){let n={signal:AbortSignal.timeout(this.timeout)};try{let o=Ir(t,{maxDataLength:eo}).pb(z);this.log("A receiving connect");let s=await o.read(n);if(s.type!==z.Type.CONNECT)throw this.log("B sent wrong message type"),new H("DCUtR message type was incorrect");if(s.observedAddresses.length===0)throw this.log("B sent no multiaddrs"),new H("DCUtR connect message had no multiaddrs");let i=this.getDialableMultiaddrs(s.observedAddresses);if(i.length===0)throw this.log("B had no dialable multiaddrs"),new H("DCUtR connect message had no dialable multiaddrs");if(this.log("A sending connect"),await o.write({type:z.Type.CONNECT,observedAddresses:this.addressManager.getAddresses().map(c=>c.bytes)}),this.log("A receiving sync"),(await o.read(n)).type!==z.Type.SYNC)throw new H("DCUtR message type was incorrect");this.log("A dialing",i);let u=await this.connectionManager.openConnection(i,{signal:n.signal,priority:ro,force:!0});this.log("DCUtR to %p succeeded via %a, closing relayed connection",e.remotePeer,u.remoteAddr),await e.close(n)}catch(o){this.log.error("incoming DCUtR from %p failed",e.remotePeer,o),t.abort(o)}finally{await t.close(n)}}getDialableMultiaddrs(t){let e=[];for(let n of t)if(!(n==null||n.length===0))try{let o=$t(n);if(!kr(o,this.transportManager))continue;e.push(o)}catch{}return e}};var At="/libp2p/dcutr";function Ai(r={}){return t=>new De(t,r)}return ho(Ti);})();
|
|
2
|
+
"use strict";var Libp2PDcutr=(()=>{var ao=Object.create;var Qt=Object.defineProperty;var co=Object.getOwnPropertyDescriptor;var uo=Object.getOwnPropertyNames;var lo=Object.getPrototypeOf,ho=Object.prototype.hasOwnProperty;var fo=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),N=(r,t)=>{for(var e in t)Qt(r,e,{get:t[e],enumerable:!0})},$r=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of uo(t))!ho.call(r,o)&&o!==e&&Qt(r,o,{get:()=>t[o],enumerable:!(n=co(t,o))||n.enumerable});return r};var po=(r,t,e)=>(e=r!=null?ao(lo(r)):{},$r(t||!r||!r.__esModule?Qt(e,"default",{value:r,enumerable:!0}):e,r)),mo=r=>$r(Qt({},"__esModule",{value:!0}),r);var $n=fo(jt=>{(function(){var r,t,e,n,o,s,i,a;a=function(u){var c,h,l,f;return c=(u&255<<24)>>>24,h=(u&255<<16)>>>16,l=(u&65280)>>>8,f=u&255,[c,h,l,f].join(".")},i=function(u){var c,h,l,f,p,m;for(c=[],l=f=0;f<=3&&u.length!==0;l=++f){if(l>0){if(u[0]!==".")throw new Error("Invalid IP");u=u.substring(1)}m=t(u),p=m[0],h=m[1],u=u.substring(h),c.push(p)}if(u.length!==0)throw new Error("Invalid IP");switch(c.length){case 1:if(c[0]>4294967295)throw new Error("Invalid IP");return c[0]>>>0;case 2:if(c[0]>255||c[1]>16777215)throw new Error("Invalid IP");return(c[0]<<24|c[1])>>>0;case 3:if(c[0]>255||c[1]>255||c[2]>65535)throw new Error("Invalid IP");return(c[0]<<24|c[1]<<16|c[2])>>>0;case 4:if(c[0]>255||c[1]>255||c[2]>255||c[3]>255)throw new Error("Invalid IP");return(c[0]<<24|c[1]<<16|c[2]<<8|c[3])>>>0;default:throw new Error("Invalid IP")}},e=function(u){return u.charCodeAt(0)},n=e("0"),s=e("a"),o=e("A"),t=function(u){var c,h,l,f,p;for(f=0,c=10,h="9",l=0,u.length>1&&u[l]==="0"&&(u[l+1]==="x"||u[l+1]==="X"?(l+=2,c=16):"0"<=u[l+1]&&u[l+1]<="9"&&(l++,c=8,h="7")),p=l;l<u.length;){if("0"<=u[l]&&u[l]<=h)f=f*c+(e(u[l])-n)>>>0;else if(c===16)if("a"<=u[l]&&u[l]<="f")f=f*c+(10+e(u[l])-s)>>>0;else if("A"<=u[l]&&u[l]<="F")f=f*c+(10+e(u[l])-o)>>>0;else break;else break;if(f>4294967295)throw new Error("too large");l++}if(l===p)throw new Error("empty octet");return[f,l]},r=(function(){function u(c,h){var l,f,p,m;if(typeof c!="string")throw new Error("Missing `net' parameter");if(h||(m=c.split("/",2),c=m[0],h=m[1]),h||(h=32),typeof h=="string"&&h.indexOf(".")>-1){try{this.maskLong=i(h)}catch(I){throw l=I,new Error("Invalid mask: "+h)}for(f=p=32;p>=0;f=--p)if(this.maskLong===4294967295<<32-f>>>0){this.bitmask=f;break}}else if(h||h===0)this.bitmask=parseInt(h,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(c)&this.maskLong)>>>0}catch(I){throw l=I,new Error("Invalid net address: "+c)}if(!(this.bitmask<=32))throw new Error("Invalid mask for ip4: "+h);this.size=Math.pow(2,32-this.bitmask),this.base=a(this.netLong),this.mask=a(this.maskLong),this.hostmask=a(~this.maskLong),this.first=this.bitmask<=30?a(this.netLong+1):this.base,this.last=this.bitmask<=30?a(this.netLong+this.size-2):a(this.netLong+this.size-1),this.broadcast=this.bitmask<=30?a(this.netLong+this.size-1):void 0}return u.prototype.contains=function(c){return typeof c=="string"&&(c.indexOf("/")>0||c.split(".").length!==4)&&(c=new u(c)),c instanceof u?this.contains(c.base)&&this.contains(c.broadcast||c.last):(i(c)&this.maskLong)>>>0===(this.netLong&this.maskLong)>>>0},u.prototype.next=function(c){return c==null&&(c=1),new u(a(this.netLong+this.size*c),this.mask)},u.prototype.forEach=function(c){var h,l,f;for(f=i(this.first),l=i(this.last),h=0;f<=l;)c(a(f),f,h),h++,f++},u.prototype.toString=function(){return this.base+"/"+this.bitmask},u})(),jt.ip2long=i,jt.long2ip=a,jt.Netmask=r}).call(jt)});var Wi={};N(Wi,{dcutr:()=>$i,multicodec:()=>At});var Jt=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}};var H=class extends Error{static name="InvalidMessageError";constructor(t="Invalid message"){super(t),this.name="InvalidMessageError"}};var qi=Symbol.for("@libp2p/service-capabilities"),Wr=Symbol.for("@libp2p/service-dependencies");var Se={};N(Se,{base58btc:()=>U,base58flickr:()=>vo});var wa=new Uint8Array(0);function Gr(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function X(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 jr(r){return new TextEncoder().encode(r)}function qr(r){return new TextDecoder().decode(r)}function go(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 a=r.length,u=r.charAt(0),c=Math.log(a)/Math.log(256),h=Math.log(256)/Math.log(a);function l(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 I=0,nt=0,B=0,V=m.length;B!==V&&m[B]===0;)B++,I++;for(var $=(V-B)*h+1>>>0,F=new Uint8Array($);B!==V;){for(var W=m[B],Z=0,M=$-1;(W!==0||Z<nt)&&M!==-1;M--,Z++)W+=256*F[M]>>>0,F[M]=W%a>>>0,W=W/a>>>0;if(W!==0)throw new Error("Non-zero carry");nt=Z,B++}for(var q=$-nt;q!==$&&F[q]===0;)q++;for(var Xt=u.repeat(I);q<$;++q)Xt+=r.charAt(F[q]);return Xt}function f(m){if(typeof m!="string")throw new TypeError("Expected String");if(m.length===0)return new Uint8Array;var I=0;if(m[I]!==" "){for(var nt=0,B=0;m[I]===u;)nt++,I++;for(var V=(m.length-I)*c+1>>>0,$=new Uint8Array(V);m[I];){var F=e[m.charCodeAt(I)];if(F===255)return;for(var W=0,Z=V-1;(F!==0||W<B)&&Z!==-1;Z--,W++)F+=a*$[Z]>>>0,$[Z]=F%256>>>0,F=F/256>>>0;if(F!==0)throw new Error("Non-zero carry");B=W,I++}if(m[I]!==" "){for(var M=V-B;M!==V&&$[M]===0;)M++;for(var q=new Uint8Array(nt+(V-M)),Xt=nt;M!==V;)q[Xt++]=$[M++];return q}}}function p(m){var I=f(m);if(I)return I;throw new Error(`Non-${t} character`)}return{encode:l,decodeUnsafe:f,decode:p}}var xo=go,bo=xo,Xr=bo;var Ee=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")}},ve=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,e,n){this.name=t,this.prefix=e;let o=e.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,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 Qr(this,t)}},Ie=class{decoders;constructor(t){this.decoders=t}or(t){return Qr(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 Qr(r,t){return new Ie({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var Ce=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 Ee(t,e,n),this.decoder=new ve(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function ft({name:r,prefix:t,encode:e,decode:n}){return new Ce(r,t,e,n)}function K({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=Xr(e,r);return ft({prefix:t,name:r,encode:n,decode:s=>X(o(s))})}function wo(r,t,e,n){let o=r.length;for(;r[o-1]==="=";)--o;let s=new Uint8Array(o*e/8|0),i=0,a=0,u=0;for(let c=0;c<o;++c){let h=t[r[c]];if(h===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<e|h,i+=e,i>=8&&(i-=8,s[u++]=255&a>>i)}if(i>=e||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function yo(r,t,e){let n=t[t.length-1]==="=",o=(1<<e)-1,s="",i=0,a=0;for(let u=0;u<r.length;++u)for(a=a<<8|r[u],i+=8;i>e;)i-=e,s+=t[o&a>>i];if(i!==0&&(s+=t[o&a<<e-i]),n)for(;(s.length*e&7)!==0;)s+="=";return s}function Eo(r){let t={};for(let e=0;e<r.length;++e)t[r[e]]=e;return t}function v({name:r,prefix:t,bitsPerChar:e,alphabet:n}){let o=Eo(n);return ft({prefix:t,name:r,encode(s){return yo(s,n,e)},decode(s){return wo(s,o,e,r)}})}var U=K({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),vo=K({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var De={};N(De,{base32:()=>Y,base32hex:()=>Do,base32hexpad:()=>To,base32hexpadupper:()=>Lo,base32hexupper:()=>Ao,base32pad:()=>Co,base32padupper:()=>So,base32upper:()=>Io,base32z:()=>Po});var Y=v({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Io=v({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Co=v({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),So=v({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Do=v({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Ao=v({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),To=v({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Lo=v({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Po=v({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Ae={};N(Ae,{base36:()=>Tt,base36upper:()=>No});var Tt=K({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),No=K({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var _o=Kr,Jr=128,Oo=127,Fo=~Oo,Uo=Math.pow(2,31);function Kr(r,t,e){t=t||[],e=e||0;for(var n=e;r>=Uo;)t[e++]=r&255|Jr,r/=128;for(;r&Fo;)t[e++]=r&255|Jr,r>>>=7;return t[e]=r|0,Kr.bytes=e-n+1,t}var Ro=Te,Bo=128,Zr=127;function Te(r,n){var e=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw Te.bytes=0,new RangeError("Could not decode varint");i=r[s++],e+=o<28?(i&Zr)<<o:(i&Zr)*Math.pow(2,o),o+=7}while(i>=Bo);return Te.bytes=s-n,e}var Mo=Math.pow(2,7),ko=Math.pow(2,14),zo=Math.pow(2,21),Vo=Math.pow(2,28),$o=Math.pow(2,35),Wo=Math.pow(2,42),Go=Math.pow(2,49),jo=Math.pow(2,56),qo=Math.pow(2,63),Ho=function(r){return r<Mo?1:r<ko?2:r<zo?3:r<Vo?4:r<$o?5:r<Wo?6:r<Go?7:r<jo?8:r<qo?9:10},Xo={encode:_o,decode:Ro,encodingLength:Ho},Qo=Xo,Lt=Qo;function Pt(r,t=0){return[Lt.decode(r,t),Lt.decode.bytes]}function dt(r,t,e=0){return Lt.encode(r,t,e),t}function pt(r){return Lt.encodingLength(r)}function gt(r,t){let e=t.byteLength,n=pt(r),o=n+pt(e),s=new Uint8Array(o+e);return dt(r,s,0),dt(e,s,n),s.set(t,o),new mt(r,e,t,s)}function Yr(r){let t=X(r),[e,n]=Pt(t),[o,s]=Pt(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new mt(e,o,i,t)}function tn(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&Gr(r.bytes,e.bytes)}}var mt=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=n,this.bytes=o}};function en(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return Zo(e,Le(r),t??U.encoder);default:return Ko(e,Le(r),t??Y.encoder)}}var rn=new WeakMap;function Le(r){let t=rn.get(r);if(t==null){let e=new Map;return rn.set(r,e),e}return t}var tt=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!==_t)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==Yo)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=gt(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&&tn(t.multihash,n.multihash)}toString(t){return en(this,t)}toJSON(){return{"/":en(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??nn(n,o,s.bytes))}else if(e[ts]===!0){let{version:n,multihash:o,code:s}=e,i=Yr(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!==_t)throw new Error(`Version 0 CID must use dag-pb (code: ${_t}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=nn(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,_t,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=X(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 mt(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[l,f]=Pt(t.subarray(e));return e+=f,l},o=n(),s=_t;if(o===18?(o=0,e=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=e,a=n(),u=n(),c=e+u,h=c-i;return{version:o,codec:s,multihashCode:a,digestSize:u,multihashSize:h,size:c}}static parse(t,e){let[n,o]=Jo(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 Le(s).set(n,t),s}};function Jo(r,t){switch(r[0]){case"Q":{let e=t??U;return[U.prefix,e.decode(`${U.prefix}${r}`)]}case U.prefix:{let e=t??U;return[U.prefix,e.decode(r)]}case Y.prefix:{let e=t??Y;return[Y.prefix,e.decode(r)]}case Tt.prefix:{let e=t??Tt;return[Tt.prefix,e.decode(r)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],t.decode(r)]}}}function Zo(r,t,e){let{prefix:n}=e;if(n!==U.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 Ko(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 _t=112,Yo=18;function nn(r,t,e){let n=pt(r),o=n+pt(t),s=new Uint8Array(o+e.byteLength);return dt(r,s,0),dt(t,s,n),s.set(e,o),s}var ts=Symbol.for("@ipld/js-cid/CID");var Pe={};N(Pe,{identity:()=>ns});var on=0,es="identity",sn=X;function rs(r,t){if(t?.truncate!=null&&t.truncate!==r.byteLength){if(t.truncate<0||t.truncate>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,t.truncate)}return gt(on,sn(r))}var ns={code:on,name:es,encode:sn,digest:rs};function Kt(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 Q(r=0){return new Uint8Array(r)}function L(r=0){return new Uint8Array(r)}function et(r,t){t==null&&(t=r.reduce((o,s)=>o+s.length,0));let e=L(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return e}var cn=Symbol.for("@achingbrain/uint8arraylist");function an(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 Yt(r){return!!r?.[cn]}var ot=class r{bufs;length;[cn]=!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(Yt(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(Yt(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=an(this.bufs,t);return e.buf[e.index]}set(t,e){let n=an(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(Yt(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 et(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:et(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],a=o,u=a+i.byteLength;if(o=u,t>=u)continue;let c=t>=a&&t<u,h=e>a&&e<=u;if(c&&h){if(t===a&&e===u){n.push(i);break}let l=t-a;n.push(i.subarray(l,l+(e-t)));break}if(c){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(h){if(e===u){n.push(i);break}n.push(i.subarray(0,e-a));break}n.push(i)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!Yt(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 l=0;l<s;l++)i[l]=-1;for(let l=0;l<o;l++)i[n[l]]=l;let a=i,u=this.byteLength-n.byteLength,c=n.byteLength-1,h;for(let l=e;l<=u;l+=h){h=0;for(let f=c;f>=0;f--){let p=this.get(l+f);if(n[f]!==p){h=Math.max(1,f-a[p]);break}}if(h===0)return l}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=Q(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=Q(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=Q(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=Q(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=Q(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=Q(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=Q(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=Q(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(!Kt(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}};var Ne={};N(Ne,{base10:()=>os});var os=K({prefix:"9",name:"base10",alphabet:"0123456789"});var _e={};N(_e,{base16:()=>ss,base16upper:()=>is});var ss=v({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),is=v({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Oe={};N(Oe,{base2:()=>as});var as=v({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Fe={};N(Fe,{base256emoji:()=>fs});var un=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}"),cs=un.reduce((r,t,e)=>(r[e]=t,r),[]),us=un.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function ls(r){return r.reduce((t,e)=>(t+=cs[e],t),"")}function hs(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let o=us[n];if(o==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(o)}return new Uint8Array(t)}var fs=ft({prefix:"\u{1F680}",name:"base256emoji",encode:ls,decode:hs});var Re={};N(Re,{base64:()=>ds,base64pad:()=>ps,base64url:()=>Ue,base64urlpad:()=>ms});var ds=v({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),ps=v({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Ue=v({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),ms=v({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Be={};N(Be,{base8:()=>gs});var gs=v({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Me={};N(Me,{identity:()=>xs});var xs=ft({prefix:"\0",name:"identity",encode:r=>qr(r),decode:r=>jr(r)});var rc=new TextEncoder,nc=new TextDecoder;var Ve={};N(Ve,{sha256:()=>Es,sha512:()=>vs});var ys=20;function ze({name:r,code:t,encode:e,minDigestLength:n,maxDigestLength:o}){return new ke(r,t,e,n,o)}var ke=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,e,n,o,s){this.name=t,this.code=e,this.encode=n,this.minDigestLength=o??ys,this.maxDigestLength=s}digest(t,e){if(e?.truncate!=null){if(e.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&e.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(t instanceof Uint8Array){let n=this.encode(t);return n instanceof Uint8Array?ln(n,this.code,e?.truncate):n.then(o=>ln(o,this.code,e?.truncate))}else throw Error("Unknown type, must be binary type")}};function ln(r,t,e){if(e!=null&&e!==r.byteLength){if(e>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,e)}return gt(t,r)}function fn(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var Es=ze({name:"sha2-256",code:18,encode:fn("SHA-256")}),vs=ze({name:"sha2-512",code:19,encode:fn("SHA-512")});var Ot={...Me,...Oe,...Be,...Ne,..._e,...De,...Ae,...Se,...Re,...Fe},mc={...Ve,...Pe};function pn(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var dn=pn("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),$e=pn("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}),Is={utf8:dn,"utf-8":dn,hex:Ot.base16,latin1:$e,ascii:$e,binary:$e,...Ot},te=Is;function G(r,t="utf8"){let e=te[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function R(r,t="utf8"){let e=te[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var Cs=Math.pow(2,7),Ss=Math.pow(2,14),Ds=Math.pow(2,21),We=Math.pow(2,28),Ge=Math.pow(2,35),je=Math.pow(2,42),qe=Math.pow(2,49),b=128,D=127;function P(r){if(r<Cs)return 1;if(r<Ss)return 2;if(r<Ds)return 3;if(r<We)return 4;if(r<Ge)return 5;if(r<je)return 6;if(r<qe)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function xt(r,t,e=0){switch(P(r)){case 8:t[e++]=r&255|b,r/=128;case 7:t[e++]=r&255|b,r/=128;case 6:t[e++]=r&255|b,r/=128;case 5:t[e++]=r&255|b,r/=128;case 4:t[e++]=r&255|b,r>>>=7;case 3:t[e++]=r&255|b,r>>>=7;case 2:t[e++]=r&255|b,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function As(r,t,e=0){switch(P(r)){case 8:t.set(e++,r&255|b),r/=128;case 7:t.set(e++,r&255|b),r/=128;case 6:t.set(e++,r&255|b),r/=128;case 5:t.set(e++,r&255|b),r/=128;case 4:t.set(e++,r&255|b),r>>>=7;case 3:t.set(e++,r&255|b),r>>>=7;case 2:t.set(e++,r&255|b),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function He(r,t){let e=r[t],n=0;if(n+=e&D,e<b||(e=r[t+1],n+=(e&D)<<7,e<b)||(e=r[t+2],n+=(e&D)<<14,e<b)||(e=r[t+3],n+=(e&D)<<21,e<b)||(e=r[t+4],n+=(e&D)*We,e<b)||(e=r[t+5],n+=(e&D)*Ge,e<b)||(e=r[t+6],n+=(e&D)*je,e<b)||(e=r[t+7],n+=(e&D)*qe,e<b))return n;throw new RangeError("Could not decode varint")}function Ts(r,t){let e=r.get(t),n=0;if(n+=e&D,e<b||(e=r.get(t+1),n+=(e&D)<<7,e<b)||(e=r.get(t+2),n+=(e&D)<<14,e<b)||(e=r.get(t+3),n+=(e&D)<<21,e<b)||(e=r.get(t+4),n+=(e&D)*We,e<b)||(e=r.get(t+5),n+=(e&D)*Ge,e<b)||(e=r.get(t+6),n+=(e&D)*je,e<b)||(e=r.get(t+7),n+=(e&D)*qe,e<b))return n;throw new RangeError("Could not decode varint")}function mn(r,t,e=0){return t==null&&(t=L(P(r))),t instanceof Uint8Array?xt(r,t,e):As(r,t,e)}function Ft(r,t=0){return r instanceof Uint8Array?He(r,t):Ts(r,t)}var Xe=new Float32Array([-0]),rt=new Uint8Array(Xe.buffer);function xn(r,t,e){Xe[0]=r,t[e]=rt[0],t[e+1]=rt[1],t[e+2]=rt[2],t[e+3]=rt[3]}function bn(r,t){return rt[0]=r[t],rt[1]=r[t+1],rt[2]=r[t+2],rt[3]=r[t+3],Xe[0]}var Qe=new Float64Array([-0]),A=new Uint8Array(Qe.buffer);function wn(r,t,e){Qe[0]=r,t[e]=A[0],t[e+1]=A[1],t[e+2]=A[2],t[e+3]=A[3],t[e+4]=A[4],t[e+5]=A[5],t[e+6]=A[6],t[e+7]=A[7]}function yn(r,t){return A[0]=r[t],A[1]=r[t+1],A[2]=r[t+2],A[3]=r[t+3],A[4]=r[t+4],A[5]=r[t+5],A[6]=r[t+6],A[7]=r[t+7],Qe[0]}var Ls=BigInt(Number.MAX_SAFE_INTEGER),Ps=BigInt(Number.MIN_SAFE_INTEGER),_=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 st;if(t<Ls&&t>Ps)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>En&&(o=0n,++n>En&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(t){if(t===0)return st;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):st}},st=new _(0,0);st.toBigInt=function(){return 0n};st.zzEncode=st.zzDecode=function(){return this};st.length=function(){return 1};var En=4294967296n;function vn(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 In(r,t,e){if(e-t<1)return"";let o,s=[],i=0,a;for(;t<e;)a=r[t++],a<128?s[i++]=a:a>191&&a<224?s[i++]=(a&31)<<6|r[t++]&63:a>239&&a<365?(a=((a&7)<<18|(r[t++]&63)<<12|(r[t++]&63)<<6|r[t++]&63)-65536,s[i++]=55296+(a>>10),s[i++]=56320+(a&1023)):s[i++]=(a&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 Je(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 k(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function ee(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var Ze=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,k(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 k(this,4);return ee(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw k(this,4);return ee(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw k(this,4);let t=bn(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw k(this,4);let t=yn(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 k(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return In(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw k(this,t);this.pos+=t}else do if(this.pos>=this.len)throw k(this);while((this.buf[this.pos++]&128)!==0);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 _(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 k(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 k(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 k(this,8);let t=ee(this.buf,this.pos+=4),e=ee(this.buf,this.pos+=4);return new _(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=He(this.buf,this.pos);return this.pos+=P(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 Ke(r){return new Ze(r instanceof Uint8Array?r:r.subarray())}function Ye(r,t,e){let n=Ke(r);return t.decode(n,void 0,e)}function tr(r){let t=r??8192,e=t>>>1,n,o=t;return function(i){if(i<1||i>e)return L(i);o+i>t&&(n=L(t),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var it=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function er(){}var nr=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Ns=tr();function _s(r){return globalThis.Buffer!=null?L(r):Ns(r)}var Rt=class{len;head;tail;states;constructor(){this.len=0,this.head=new it(er,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new it(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new or((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(re,10,_.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=_.fromBigInt(t);return this._push(re,e.length(),e)}uint64Number(t){return this._push(xt,P(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=_.fromBigInt(t).zzEncode();return this._push(re,e.length(),e)}sint64Number(t){let e=_.fromNumber(t).zzEncode();return this._push(re,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(rr,1,t?1:0)}fixed32(t){return this._push(Ut,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=_.fromBigInt(t);return this._push(Ut,4,e.lo)._push(Ut,4,e.hi)}fixed64Number(t){let e=_.fromNumber(t);return this._push(Ut,4,e.lo)._push(Ut,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(xn,4,t)}double(t){return this._push(wn,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(rr,1,0):this.uint32(e)._push(Fs,e,t)}string(t){let e=vn(t);return e!==0?this.uint32(e)._push(Je,e,t):this._push(rr,1,0)}fork(){return this.states=new nr(this),this.head=this.tail=new it(er,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 it(er,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=_s(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function rr(r,t,e){t[e]=r&255}function Os(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var or=class extends it{next;constructor(t,e){super(Os,t,e),this.next=void 0}};function re(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 Ut(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 Fs(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(Rt.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(Us,t,r),this},Rt.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(Rs,t,r),this});function Us(r,t,e){t.set(r,e)}function Rs(r,t,e){r.length<40?Je(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(G(r),e)}function sr(){return new Rt}function ir(r,t){let e=sr();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var bt;(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"})(bt||(bt={}));function ne(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function ar(r){function t(o){if(r[o.toString()]==null)throw new Error("Invalid enum value");return r[o]}let e=function(s,i){let a=t(s);i.int32(a)},n=function(s){let i=s.int32();return t(i)};return ne("enum",bt.VARINT,e,n)}function cr(r,t){return ne("message",bt.LENGTH_DELIMITED,r,t)}var oe=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var se=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,a=this.peekChar();if(a===void 0)return;let u=a==="0",c=2**(8*o)-1;for(;;){let h=this.readAtomically(()=>{let l=this.readChar();if(l===void 0)return;let f=Number.parseInt(l,t);if(!Number.isNaN(f))return f});if(h===void 0)break;if(s*=t,s+=h,s>c||(i+=1,e!==void 0&&i>e))return}if(i!==0)return!n&&u&&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),[a]=t(s.subarray(0,i));return e.set(s.subarray(0,a),16-a),e})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var Bs=45,Ms=15,ie=new se;function ur(r){if(!(r.length>Ms))return ie.new(r).parseWith(()=>ie.readIPv4Addr())}function lr(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>Bs))return ie.new(r).parseWith(()=>ie.readIPv6Addr())}var hu=parseInt("0xFFFF",16),fu=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);var S=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},J=class extends Error{static name="ValidationError";name="ValidationError"},Bt=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},ae=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};function wt(r){return!!ur(r)}function ce(r){return!!lr(r)}function fr(r){return t=>R(t,r)}function dr(r){return t=>G(t,r)}function yt(r){return new DataView(r.buffer).getUint16(r.byteOffset).toString()}function at(r){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,typeof r=="string"?parseInt(r):r),new Uint8Array(t)}function Tn(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=G(t[0],"base32"),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=at(n);return et([e,o],e.length+o.length)}function Ln(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=Y.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=at(n);return et([e,o],e.length+o.length)}function pr(r){let t=r.subarray(0,r.length-2),e=r.subarray(r.length-2),n=R(t,"base32"),o=yt(e);return`${n}:${o}`}var mr=function(r){r=r.toString().trim();let t=new Uint8Array(4);return r.split(/\./g).forEach((e,n)=>{let o=parseInt(e,10);if(isNaN(o)||o<0||o>255)throw new S("Invalid byte value in IP address");t[n]=o}),t},Pn=function(r){let t=0;r=r.toString().trim();let e=r.split(":",8),n;for(n=0;n<e.length;n++){let s=wt(e[n]),i;s&&(i=mr(e[n]),e[n]=R(i.subarray(0,2),"base16")),i!=null&&++n<8&&e.splice(n,0,R(i.subarray(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++){e[n]===""&&(e[n]="0");let s=parseInt(e[n],16);if(isNaN(s)||s<0||s>65535)throw new S("Invalid byte value in IP address");o[t++]=s>>8&255,o[t++]=s&255}return o},Nn=function(r){if(r.byteLength!==4)throw new S("IPv4 address was incorrect length");let t=[];for(let e=0;e<r.byteLength;e++)t.push(r[e]);return t.join(".")},_n=function(r){if(r.byteLength!==16)throw new S("IPv6 address was incorrect length");let t=[];for(let n=0;n<r.byteLength;n+=2){let o=r[n],s=r[n+1],i=`${o.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}`;t.push(i)}let e=t.join(":");try{let n=new URL(`http://[${e}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new S(`Invalid IPv6 address "${e}"`)}};function On(r){try{let t=new URL(`http://[${r}]`);return t.hostname.substring(1,t.hostname.length-1)}catch{throw new S(`Invalid IPv6 address "${r}"`)}}var hr=Object.values(Ot).map(r=>r.decoder),Ws=(function(){let r=hr[0].or(hr[1]);return hr.slice(2).forEach(t=>r=r.or(t)),r})();function Fn(r){return Ws.decode(r)}function Un(r){return t=>r.encoder.encode(t)}function Gs(r){if(parseInt(r).toString()!==r)throw new J("Value must be an integer")}function js(r){if(r<0)throw new J("Value must be a positive integer, or zero")}function qs(r){return t=>{if(t>r)throw new J(`Value must be smaller than or equal to ${r}`)}}function Hs(...r){return t=>{for(let e of r)e(t)}}var Mt=Hs(Gs,js,qs(65535));var C=-1,gr=class{protocolsByCode=new Map;protocolsByName=new Map;getProtocol(t){let e;if(typeof t=="string"?e=this.protocolsByName.get(t):e=this.protocolsByCode.get(t),e==null)throw new ae(`Protocol ${t} was unknown`);return e}addProtocol(t){this.protocolsByCode.set(t.code,t),this.protocolsByName.set(t.name,t),t.aliases?.forEach(e=>{this.protocolsByName.set(e,t)})}removeProtocol(t){let e=this.protocolsByCode.get(t);e!=null&&(this.protocolsByCode.delete(e.code),this.protocolsByName.delete(e.name),e.aliases?.forEach(n=>{this.protocolsByName.delete(n)}))}},O=new gr,ci=[{code:4,name:"ip4",size:32,valueToBytes:mr,bytesToValue:Nn,validate:r=>{if(!wt(r))throw new J(`Invalid IPv4 address "${r}"`)}},{code:6,name:"tcp",size:16,valueToBytes:at,bytesToValue:yt,validate:Mt},{code:273,name:"udp",size:16,valueToBytes:at,bytesToValue:yt,validate:Mt},{code:33,name:"dccp",size:16,valueToBytes:at,bytesToValue:yt,validate:Mt},{code:41,name:"ip6",size:128,valueToBytes:Pn,bytesToValue:_n,stringToValue:On,validate:r=>{if(!ce(r))throw new J(`Invalid IPv6 address "${r}"`)}},{code:42,name:"ip6zone",size:C},{code:43,name:"ipcidr",size:8,bytesToValue:fr("base10"),valueToBytes:dr("base10")},{code:53,name:"dns",size:C,resolvable:!0},{code:54,name:"dns4",size:C,resolvable:!0},{code:55,name:"dns6",size:C,resolvable:!0},{code:56,name:"dnsaddr",size:C,resolvable:!0},{code:132,name:"sctp",size:16,valueToBytes:at,bytesToValue:yt,validate:Mt},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:C,path:!0,stringToValue:r=>decodeURIComponent(r),valueToString:r=>encodeURIComponent(r)},{code:421,name:"p2p",aliases:["ipfs"],size:C,bytesToValue:fr("base58btc"),valueToBytes:r=>r.startsWith("Q")||r.startsWith("1")?dr("base58btc")(r):tt.parse(r).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:pr,valueToBytes:Tn},{code:445,name:"onion3",size:296,bytesToValue:pr,valueToBytes:Ln},{code:446,name:"garlic64",size:C},{code:447,name:"garlic32",size:C},{code:448,name:"tls"},{code:449,name:"sni",size:C},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:C,bytesToValue:Un(Ue),valueToBytes:Fn},{code:480,name:"http"},{code:481,name:"http-path",size:C,stringToValue:r=>`/${decodeURIComponent(r)}`,valueToString:r=>encodeURIComponent(r.substring(1))},{code:443,name:"https"},{code:477,name:"ws"},{code:478,name:"wss"},{code:479,name:"p2p-websocket-star"},{code:277,name:"p2p-stardust"},{code:275,name:"p2p-webrtc-star"},{code:276,name:"p2p-webrtc-direct"},{code:280,name:"webrtc-direct"},{code:281,name:"webrtc"},{code:290,name:"p2p-circuit"},{code:777,name:"memory",size:C}];ci.forEach(r=>{O.addProtocol(r)});function Rn(r){let t=[],e=0;for(;e<r.length;){let n=Ft(r,e),o=O.getProtocol(n),s=P(n),i=ui(o,r,e+s),a=0;i>0&&o.size===C&&(a=P(i));let u=s+a+i,c={code:n,name:o.name,bytes:r.subarray(e,e+u)};if(i>0){let h=e+s+a,l=r.subarray(h,h+i);c.value=o.bytesToValue?.(l)??R(l)}t.push(c),e+=u}return t}function Bn(r){let t=0,e=[];for(let n of r){if(n.bytes==null){let o=O.getProtocol(n.code),s=P(n.code),i,a=0,u=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??G(n.value),a=i.byteLength,o.size===C&&(u=P(a)));let c=new Uint8Array(s+u+a),h=0;xt(n.code,c,h),h+=s,i!=null&&(o.size===C&&(xt(a,c,h),h+=u),c.set(i,h)),n.bytes=c}e.push(n.bytes),t+=n.bytes.byteLength}return et(e,t)}function Mn(r){if(r.charAt(0)!=="/")throw new S('String multiaddr must start with "/"');let t=[],e="protocol",n="",o="";for(let s=1;s<r.length;s++){let i=r.charAt(s);i!=="/"&&(e==="protocol"?o+=r.charAt(s):n+=r.charAt(s));let a=s===r.length-1;if(i==="/"||a){let u=O.getProtocol(o);if(e==="protocol"){if(u.size==null||u.size===0){t.push({code:u.code,name:u.name}),n="",o="",e="protocol";continue}else if(a)throw new S(`Component ${o} was missing value`);e="value"}else if(e==="value"){let c={code:u.code,name:u.name};if(u.size!=null&&u.size!==0){if(n==="")throw new S(`Component ${o} was missing value`);c.value=u.stringToValue?.(n)??n}t.push(c),n="",o="",e="protocol"}}}if(o!==""&&n!=="")throw new S("Incomplete multiaddr");return t}function kn(r){return`/${r.flatMap(t=>{if(t.value==null)return t.name;let e=O.getProtocol(t.code);if(e==null)throw new S(`Unknown protocol code ${t.code}`);return[t.name,e.valueToString?.(t.value)??t.value]}).join("/")}`}function ui(r,t,e){return r.size==null||r.size===0?0:r.size>0?r.size/8:Ft(t,e)}var li=Symbol.for("nodejs.util.inspect.custom"),Dr=Symbol.for("@multiformats/multiaddr"),hi=[53,54,55,56],Sr=class extends Error{constructor(t="No available resolver"){super(t),this.name="NoAvailableResolverError"}};function fi(r){if(r==null&&(r="/"),Vn(r))return r.getComponents();if(r instanceof Uint8Array)return Rn(r);if(typeof r=="string")return r=r.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),r===""&&(r="/"),Mn(r);if(Array.isArray(r))return r;throw new S("Must be a string, Uint8Array, Component[], or another Multiaddr")}var fe=class r{[Dr]=!0;#t;#e;#r;constructor(t="/",e={}){this.#t=fi(t),e.validate!==!1&&di(this)}get bytes(){return this.#r==null&&(this.#r=Bn(this.#t)),this.#r}toString(){return this.#e==null&&(this.#e=kn(this.#t)),this.#e}toJSON(){return this.toString()}toOptions(){let t,e,n,o,s="";for(let{code:a,name:u,value:c}of this.#t)a===42&&(s=`%${c??""}`),hi.includes(a)&&(e="tcp",o=443,n=`${c??""}${s}`,t=a===55?6:4),(a===6||a===273)&&(e=u==="tcp"?"tcp":"udp",o=parseInt(c??"")),(a===4||a===41)&&(e="tcp",n=`${c??""}${s}`,t=a===41?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}}getComponents(){return[...this.#t]}protos(){return this.#t.map(({code:t,value:e})=>{let n=O.getProtocol(t);return{code:t,size:n.size??0,name:n.name,resolvable:!!n.resolvable,path:!!n.path}})}protoCodes(){return this.#t.map(({code:t})=>t)}protoNames(){return this.#t.map(({name:t})=>t)}tuples(){return this.#t.map(({code:t,value:e})=>{if(e==null)return[t];let n=O.getProtocol(t),o=[t];return e!=null&&o.push(n.valueToBytes?.(e)??G(e)),o})}stringTuples(){return this.#t.map(({code:t,value:e})=>e==null?[t]:[t,e])}encapsulate(t){let e=new r(t);return new r([...this.#t,...e.getComponents()],{validate:!1})}decapsulate(t){let e=t.toString(),n=this.toString(),o=n.lastIndexOf(e);if(o<0)throw new Bt(`Address ${this.toString()} does not contain subaddress: ${t.toString()}`);return new r(n.slice(0,o),{validate:!1})}decapsulateCode(t){let e;for(let n=this.#t.length-1;n>-1;n--)if(this.#t[n].code===t){e=n;break}return new r(this.#t.slice(0,e),{validate:!1})}getPeerId(){try{let t=[];this.#t.forEach(({code:n,value:o})=>{n===421&&t.push([n,o]),n===290&&(t=[])});let e=t.pop();if(e?.[1]!=null){let n=e[1];return n[0]==="Q"||n[0]==="1"?R(U.decode(`z${n}`),"base58btc"):R(tt.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){for(let t of this.#t)if(O.getProtocol(t.code).path)return t.value??null;return null}equals(t){return Kt(this.bytes,t.bytes)}async resolve(t){let e=this.protos().find(s=>s.resolvable);if(e==null)return[this];let n=zn.get(e.name);if(n==null)throw new Sr(`no available resolver for ${e.name}`);return(await n(this,t)).map(s=>Gt(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(){return!(this.#t.length!==2||this.#t[0].code!==4&&this.#t[0].code!==41||this.#t[1].code!==6&&this.#t[1].code!==273)}[li](){return`Multiaddr(${this.toString()})`}};function di(r){r.getComponents().forEach(t=>{let e=O.getProtocol(t.code);t.value!=null&&e.validate?.(t.value)})}var zn=new Map;function Vn(r){return!!r?.[Dr]}function Gt(r){return new fe(r)}var Wn=po($n(),1),pi=["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"],mi=pi.map(r=>new Wn.Netmask(r));function Ar(r){for(let t of mi)if(t.contains(r))return!0;return!1}function gi(r){return/^::ffff:([0-9a-fA-F]{1,4}):([0-9a-fA-F]{1,4})$/.test(r)}function xi(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 Ar(o)}function bi(r){return/^::ffff:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(r)}function wi(r){let t=r.split(":"),e=t[t.length-1];return Ar(e)}function yi(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 Gn(r){if(wt(r))return Ar(r);if(gi(r))return xi(r);if(bi(r))return wi(r);if(ce(r))return yi(r)}var Tr=class extends Error{constructor(t){super(t),this.name="TimeoutError"}},Lr=class extends Error{constructor(t){super(),this.name="AbortError",this.message=t}},jn=r=>globalThis.DOMException===void 0?new Lr(r):new DOMException(r),qn=r=>{let t=r.reason===void 0?jn("This operation was aborted."):r.reason;return t instanceof Error?t:jn(t)};function Pr(r,t){let{milliseconds:e,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout}}=t,i,a,c=new Promise((h,l)=>{if(typeof e!="number"||Math.sign(e)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${e}\``);if(t.signal){let{signal:p}=t;p.aborted&&l(qn(p)),a=()=>{l(qn(p))},p.addEventListener("abort",a,{once:!0})}if(e===Number.POSITIVE_INFINITY){r.then(h,l);return}let f=new Tr;i=s.setTimeout.call(void 0,()=>{if(n){try{h(n())}catch(p){l(p)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?h():o instanceof Error?l(o):(f.message=o??`Promise timed out after ${e} milliseconds`,l(f))},e),(async()=>{try{h(await r)}catch(p){l(p)}})()}).finally(()=>{c.clear(),a&&t.signal&&t.signal.removeEventListener("abort",a)});return c.clear=()=>{s.clearTimeout.call(void 0,i),i=void 0},c}var Ei=r=>{let t=r.addEventListener||r.on||r.addListener,e=r.removeEventListener||r.off||r.removeListener;if(!t||!e)throw new TypeError("Emitter is not compatible");return{addListener:t.bind(r),removeListener:e.bind(r)}};function vi(r,t,e){let n,o=new Promise((s,i)=>{if(e={rejectionEvents:["error"],multiArgs:!1,resolveImmediately:!1,...e},!(e.count>=0&&(e.count===Number.POSITIVE_INFINITY||Number.isInteger(e.count))))throw new TypeError("The `count` option should be at least 0 or more");e.signal?.throwIfAborted();let a=[t].flat(),u=[],{addListener:c,removeListener:h}=Ei(r),l=(...p)=>{let m=e.multiArgs?p:p[0];e.filter&&!e.filter(m)||(u.push(m),e.count===u.length&&(n(),s(u)))},f=p=>{n(),i(p)};n=()=>{for(let p of a)h(p,l);for(let p of e.rejectionEvents)h(p,f)};for(let p of a)c(p,l);for(let p of e.rejectionEvents)c(p,f);e.signal&&e.signal.addEventListener("abort",()=>{f(e.signal.reason)},{once:!0}),e.resolveImmediately&&s(u)});if(o.cancel=n,typeof e.timeout=="number"){let s=Pr(o,{milliseconds:e.timeout});return s.cancel=n,s}return o}function Hn(r,t,e){typeof e=="function"&&(e={filter:e}),e={...e,count:1,resolveImmediately:!1};let n=vi(r,t,e),o=n.then(s=>s[0]);return o.cancel=n.cancel,o}var lt=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"};function Ii(r){return r.reason}async function Xn(r,t,e){if(t==null)return r;let n=e?.translateError??Ii;if(t.aborted)return r.catch(()=>{}),Promise.reject(n(t));let o;try{return await Promise.race([r,new Promise((s,i)=>{o=()=>{i(n(t))},t.addEventListener("abort",o)})])}finally{o!=null&&t.removeEventListener("abort",o)}}var Si=4194304,de=class extends Error{static name="UnwrappedError";name="UnwrappedError"},_r=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},Or=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},Fr=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function Di(r){return typeof r?.closeRead=="function"}function Ai(r){return typeof r?.close=="function"}function Nr(r){return Di(r)?r.readStatus==="closing"||r.readStatus==="closed":Ai(r)?r.status!=="open":!1}function Ti(r){return r?.addEventListener!=null&&r?.removeEventListener!=null&&r?.send!=null&&r?.push!=null&&r?.log!=null}function Li(r,t){let e=t?.maxBufferSize??Si,n=new ot,o=Promise.withResolvers(),s=!1;if(!Ti(r))throw new Jt("Argument should be a Stream or a Multiaddr");let i=h=>{if(t?.stopPropagation,n.append(h.data),n.byteLength>e){let l=n.byteLength;n.consume(n.byteLength),o.reject(new Error(`Read buffer overflow - ${l} > ${e}`))}o.resolve()};r.addEventListener("message",i);let a=h=>{h.error!=null?o.reject(h.error):o.resolve()};r.addEventListener("close",a);let u=()=>{o.resolve()};r.addEventListener("remoteCloseWrite",u);let c={readBuffer:n,async read(h){if(s===!0)throw new de("Stream was unwrapped");if(Nr(r)){if(h?.bytes==null)return null;if(n.byteLength<h.bytes)throw new lt(`Unexpected EOF - stream closed after reading ${n.byteLength}/${h.bytes} bytes`)}let l=h?.bytes??1;for(;;){if(n.byteLength>=l){o.resolve();break}if(await Xn(o.promise,h?.signal),Nr(r)){if(n.byteLength===0&&h?.bytes==null)return null;break}o=Promise.withResolvers()}let f=h?.bytes??n.byteLength;if(n.byteLength<f){if(Nr(r))throw new lt(`Unexpected EOF - stream closed while reading ${n.byteLength}/${f} bytes`);return c.read(h)}let p=n.sublist(0,f);return n.consume(f),p},async write(h,l){if(s===!0)throw new de("Stream was unwrapped");r.send(h)||await Hn(r,"drain",{signal:l?.signal,rejectionEvents:["close"]})},unwrap(){return s||(s=!0,r.removeEventListener("message",i),r.removeEventListener("close",a),r.removeEventListener("remoteCloseWrite",u),n.byteLength>0&&(r.log("stream unwrapped with %d unread bytes",n.byteLength),r.push(n))),r}};return c}function Pi(r,t={}){let e=Li(r,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=P(t.maxDataLength));let n=t?.lengthDecoder??Ft,o=t?.lengthEncoder??mn;return{async read(i){let a=-1,u=new ot;for(;;){let h=await e.read({...i,bytes:1});if(h==null)break;u.append(h);try{a=n(u)}catch(l){if(l instanceof RangeError)continue;throw l}if(a<0)throw new _r("Invalid message length");if(t?.maxLengthLength!=null&&u.byteLength>t.maxLengthLength)throw new Fr(`Message length length too long - ${u.byteLength} > ${t.maxLengthLength}`);if(a>-1)break}if(t?.maxDataLength!=null&&a>t.maxDataLength)throw new Or(`Message length too long - ${a} > ${t.maxDataLength}`);let c=await e.read({...i,bytes:a});if(c==null)throw new lt(`Unexpected EOF - tried to read ${a} bytes but the stream closed`);if(c.byteLength!==a)throw new lt(`Unexpected EOF - read ${c.byteLength}/${a} bytes before the stream closed`);return c},async write(i,a){await e.write(new ot(o(i.byteLength),i),a)},async writeV(i,a){let u=new ot(...i.flatMap(c=>[o(c.byteLength),c]));await e.write(u,a)},unwrap(){return e.unwrap()}}}function Ur(r,t){let e=Pi(r,t),n={read:async(o,s)=>{let i=await e.read(s);return o.decode(i)},write:async(o,s,i)=>{await e.write(s.encode(o),i)},writeV:async(o,s,i)=>{await e.writeV(o.map(a=>s.encode(a)),i)},pb:o=>({read:async s=>n.read(o,s),write:async(s,i)=>n.write(s,o,i),writeV:async(s,i)=>n.writeV(s,o,i),unwrap:()=>n}),unwrap:()=>e.unwrap()};return n}var Qn=()=>{let r=new Error("Delay aborted");return r.name="AbortError",r},Ni=new WeakMap;function _i({clearTimeout:r,setTimeout:t}={}){return(e,{value:n,signal:o}={})=>{if(o?.aborted)return Promise.reject(Qn());let s,i,a,u=r??clearTimeout,c=()=>{u(s),a(Qn())},h=()=>{o&&o.removeEventListener("abort",c)},l=new Promise((f,p)=>{i=()=>{h(),f(n)},a=p,s=(t??setTimeout)(i,e)});return o&&o.addEventListener("abort",c,{once:!0}),Ni.set(l,()=>{u(s),s=null,i()}),l}}var Oi=_i(),Jn=Oi;var E=r=>({match:t=>{let e=t[0];return e==null||e.code!==r||e.value!=null?!1:t.slice(1)}}),d=(r,t)=>({match:e=>{let n=e[0];return n?.code!==r||n.value==null||t!=null&&n.value!==t?!1:e.slice(1)}}),g=r=>({match:t=>{let e=r.match(t);return e===!1?t:e}}),T=(...r)=>({match:t=>{let e;for(let n of r){let o=n.match(t);o!==!1&&(e==null||o.length<e.length)&&(e=o)}return e??!1}}),w=(...r)=>({match:t=>{for(let e of r){let n=e.match(t);if(n===!1)return!1;t=n}return t}});function y(...r){function t(o){if(o==null)return!1;let s=o.getComponents();for(let i of r){let a=i.match(s);if(a===!1)return!1;s=a}return s}function e(o){return t(o)!==!1}function n(o){let s=t(o);return s===!1?!1:s.length===0}return{matchers:r,matches:e,exactMatch:n}}var Fi=d(421),yh=y(Fi),me=d(54),ge=d(55),xe=d(56),Br=d(53),Eh=y(me,g(d(421))),vh=y(ge,g(d(421))),Ih=y(xe,g(d(421))),Zn=y(T(Br,xe,me,ge),g(d(421))),Kn=w(d(4),g(d(43))),Yn=w(g(d(42)),d(41),g(d(43))),Mr=T(Kn,Yn),ht=T(Mr,Br,me,ge,xe),Ch=y(T(Mr,w(T(Br,xe,me,ge),g(d(421))))),Sh=y(Kn),Dh=y(Yn),to=y(Mr),kr=w(ht,d(6)),qt=w(ht,d(273)),Ah=y(w(kr,g(d(421)))),Th=y(qt),zr=w(qt,E(460),g(d(421))),be=w(qt,E(461),g(d(421))),Ui=T(zr,be),Lh=y(zr),Ph=y(be),Rr=T(ht,kr,qt,zr,be),eo=T(w(Rr,E(477),g(d(421)))),Nh=y(eo),ro=T(w(Rr,E(478),g(d(421))),w(Rr,E(448),g(d(449)),E(477),g(d(421)))),_h=y(ro),no=w(qt,E(280),g(d(466)),g(d(466)),g(d(421))),Oh=y(no),oo=w(be,E(465),g(d(466)),g(d(466)),g(d(421))),Fh=y(oo),pe=T(eo,ro,w(kr,g(d(421))),w(Ui,g(d(421))),w(ht,g(d(421))),no,oo,d(421)),Uh=y(pe),Ri=w(pe,E(290),d(421)),Ht=y(Ri),Bi=T(w(pe,E(290),E(281),g(d(421))),w(pe,E(281),g(d(421))),w(E(281),g(d(421)))),Rh=y(Bi),Mi=T(w(ht,d(6),E(480),g(d(421))),w(ht,E(480),g(d(421)))),Bh=y(Mi),ki=w(ht,T(w(d(6,"443"),E(480)),w(d(6),E(443)),w(d(6),E(448),E(480)),w(E(448),E(480)),E(448),E(443)),g(d(421))),Mh=y(ki),zi=T(w(d(777),g(d(421)))),kh=y(zi),Vi=T(w(d(400),g(d(421)))),zh=y(Vi);var z;(function(r){let t;(function(o){o.UNUSED="UNUSED",o.CONNECT="CONNECT",o.SYNC="SYNC"})(t=r.Type||(r.Type={}));let e;(function(o){o[o.UNUSED=0]="UNUSED",o[o.CONNECT=100]="CONNECT",o[o.SYNC=300]="SYNC"})(e||(e={})),(function(o){o.codec=()=>ar(e)})(t=r.Type||(r.Type={}));let n;r.codec=()=>(n==null&&(n=cr((o,s,i={})=>{if(i.lengthDelimited!==!1&&s.fork(),o.type!=null&&(s.uint32(8),r.Type.codec().encode(o.type,s)),o.observedAddresses!=null)for(let a of o.observedAddresses)s.uint32(18),s.bytes(a);i.lengthDelimited!==!1&&s.ldelim()},(o,s,i={})=>{let a={observedAddresses:[]},u=s==null?o.len:o.pos+s;for(;o.pos<u;){let c=o.uint32();switch(c>>>3){case 1:{a.type=r.Type.codec().decode(o);break}case 2:{if(i.limits?.observedAddresses!=null&&a.observedAddresses.length===i.limits.observedAddresses)throw new oe('Decode error - map field "observedAddresses" had too many elements');a.observedAddresses.push(o.bytes());break}default:{o.skipType(c&7);break}}}return a})),n),r.encode=o=>ir(o,r.codec()),r.decode=(o,s)=>Ye(o,r.codec(),s)})(z||(z={}));function Vr(r,t){return Ht.matches(r)||t.dialTransportForMultiaddr(r)==null?!1:Zn.matches(r)?!0:to.matches(r)?Gn(r.toOptions().host)===!1:!1}var so=1024*4,io=100,we={timeout:5e3,retries:3,maxInboundStreams:1,maxOutboundStreams:1},ye=class{started;timeout;retries;maxInboundStreams;maxOutboundStreams;peerStore;registrar;connectionManager;addressManager;transportManager;topologyId;log;constructor(t,e){this.log=t.logger.forComponent("libp2p:dcutr"),this.started=!1,this.peerStore=t.peerStore,this.registrar=t.registrar,this.addressManager=t.addressManager,this.connectionManager=t.connectionManager,this.transportManager=t.transportManager,this.timeout=e.timeout??we.timeout,this.retries=e.retries??we.retries,this.maxInboundStreams=e.maxInboundStreams??we.maxInboundStreams,this.maxOutboundStreams=e.maxOutboundStreams??we.maxOutboundStreams,this.handleIncomingUpgrade=this.handleIncomingUpgrade.bind(this)}[Symbol.toStringTag]="@libp2p/dcutr";[Wr]=["@libp2p/identify"];isStarted(){return this.started}async start(){this.started||(this.topologyId=await this.registrar.register(At,{notifyOnLimitedConnection:!0,onConnect:(t,e)=>{Ht.exactMatch(e.remoteAddr)&&e.direction==="inbound"&&this.upgradeInbound(e).catch(n=>{this.log.error("error during outgoing DCUtR attempt",n)})}}),await this.registrar.handle(At,this.handleIncomingUpgrade,{maxInboundStreams:this.maxInboundStreams,maxOutboundStreams:this.maxOutboundStreams,runOnLimitedConnection:!0}),this.started=!0)}async stop(){await this.registrar.unhandle(At),this.topologyId!=null&&this.registrar.unregister(this.topologyId),this.started=!1}async upgradeInbound(t){if(await this.attemptUnilateralConnectionUpgrade(t))return;let e;for(let n=0;n<this.retries;n++){let o={signal:AbortSignal.timeout(this.timeout)};try{e=await t.newStream([At],{signal:o.signal,runOnLimitedConnection:!0});let s=Ur(e,{maxDataLength:so}).pb(z);this.log("B sending connect to %p",t.remotePeer);let i=Date.now();await s.write({type:z.Type.CONNECT,observedAddresses:this.addressManager.getAddresses().map(l=>l.bytes)},o),this.log("B receiving connect from %p",t.remotePeer);let a=await s.read(o);if(a.type!==z.Type.CONNECT)throw this.log("A sent wrong message type"),new H("DCUtR message type was incorrect");let u=this.getDialableMultiaddrs(a.observedAddresses);if(u.length===0)throw this.log("A did not have any dialable multiaddrs"),new H("DCUtR connect message had no multiaddrs");let c=Date.now()-i;this.log("A sending sync, rtt %dms",c),await s.write({type:z.Type.SYNC,observedAddresses:[]},o),this.log("A waiting for half RTT"),await Jn(c/2),this.log("B dialing",u);let h=await this.connectionManager.openConnection(u,{signal:o.signal,priority:io,force:!0,initiator:!1});this.log("DCUtR to %p succeeded to address %a, closing relayed connection",t.remotePeer,h.remoteAddr),await t.close(o);break}catch(s){if(this.log.error("error while attempting DCUtR on attempt %d of %d",n+1,this.retries,s),e?.abort(s),n===this.retries)throw s}finally{e!=null&&await e.close(o)}}}async attemptUnilateralConnectionUpgrade(t){let n=(await this.peerStore.get(t.remotePeer)).addresses.map(o=>{let s=o.multiaddr;return s.getPeerId()==null?s.encapsulate(`/p2p/${t.remotePeer}`):s}).filter(o=>Vr(o,this.transportManager));if(n.length>0){let o=AbortSignal.timeout(this.timeout);try{this.log("attempting unilateral connection upgrade to %a",n);let s=await this.connectionManager.openConnection(n,{signal:o,force:!0});if(Ht.exactMatch(s.remoteAddr))throw new Error("Could not open a new, non-limited, connection");return this.log("unilateral connection upgrade to %p succeeded via %a, closing relayed connection",t.remotePeer,s.remoteAddr),await t.close({signal:o}),!0}catch(s){this.log.error("unilateral connection upgrade to %p on addresses %a failed",t.remotePeer,n,s)}}else this.log("peer %p has no public addresses, not attempting unilateral connection upgrade",t.remotePeer);return!1}async handleIncomingUpgrade(t,e){let n={signal:AbortSignal.timeout(this.timeout)},o=Ur(t,{maxDataLength:so}).pb(z);this.log("A receiving connect");let s=await o.read(n);if(s.type!==z.Type.CONNECT)throw this.log("B sent wrong message type"),new H("DCUtR message type was incorrect");if(s.observedAddresses.length===0)throw this.log("B sent no multiaddrs"),new H("DCUtR connect message had no multiaddrs");let i=this.getDialableMultiaddrs(s.observedAddresses);if(i.length===0)throw this.log("B had no dialable multiaddrs"),new H("DCUtR connect message had no dialable multiaddrs");if(this.log("A sending connect"),await o.write({type:z.Type.CONNECT,observedAddresses:this.addressManager.getAddresses().map(c=>c.bytes)}),this.log("A receiving sync"),(await o.read(n)).type!==z.Type.SYNC)throw new H("DCUtR message type was incorrect");this.log("A dialing",i);let u=await this.connectionManager.openConnection(i,{signal:n.signal,priority:io,force:!0});this.log("DCUtR to %p succeeded via %a, closing relayed connection",e.remotePeer,u.remoteAddr),await e.close(n),await t.close(n)}getDialableMultiaddrs(t){let e=[];for(let n of t)if(!(n==null||n.length===0))try{let o=Gt(n);if(!Vr(o,this.transportManager))continue;e.push(o)}catch{}return e}};var At="/libp2p/dcutr";function $i(r={}){return t=>new ye(t,r)}return mo(Wi);})();
|
|
3
3
|
return Libp2PDcutr}));
|
|
4
4
|
//# sourceMappingURL=index.min.js.map
|