@libp2p/dcutr 2.0.32 → 2.0.33-6c42ea64a

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.min.js CHANGED
@@ -1,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 Cn=Object.create;var kt=Object.defineProperty;var Tn=Object.getOwnPropertyDescriptor;var Pn=Object.getOwnPropertyNames;var Mn=Object.getPrototypeOf,kn=Object.prototype.hasOwnProperty;var Rn=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),C=(r,t)=>{for(var e in t)kt(r,e,{get:t[e],enumerable:!0})},Ir=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Pn(t))!kn.call(r,o)&&o!==e&&kt(r,o,{get:()=>t[o],enumerable:!(n=Tn(t,o))||n.enumerable});return r};var Bn=(r,t,e)=>(e=r!=null?Cn(Mn(r)):{},Ir(t||!r||!r.__esModule?kt(e,"default",{value:r,enumerable:!0}):e,r)),Vn=r=>Ir(kt({},"__esModule",{value:!0}),r);var Nn=Rn(Pt=>{(function(){var r,t,e,n,o,s,i,a;a=function(u){var c,f,h,l;return c=(u&255<<24)>>>24,f=(u&255<<16)>>>16,h=(u&65280)>>>8,l=u&255,[c,f,h,l].join(".")},i=function(u){var c,f,h,l,b,d;for(c=[],h=l=0;l<=3&&u.length!==0;h=++l){if(h>0){if(u[0]!==".")throw new Error("Invalid IP");u=u.substring(1)}d=t(u),b=d[0],f=d[1],u=u.substring(f),c.push(b)}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,f,h,l,b;for(l=0,c=10,f="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,f="7")),b=h;h<u.length;){if("0"<=u[h]&&u[h]<=f)l=l*c+(e(u[h])-n)>>>0;else if(c===16)if("a"<=u[h]&&u[h]<="f")l=l*c+(10+e(u[h])-s)>>>0;else if("A"<=u[h]&&u[h]<="F")l=l*c+(10+e(u[h])-o)>>>0;else break;else break;if(l>4294967295)throw new Error("too large");h++}if(h===b)throw new Error("empty octet");return[l,h]},r=function(){function u(c,f){var h,l,b,d;if(typeof c!="string")throw new Error("Missing `net' parameter");if(f||(d=c.split("/",2),c=d[0],f=d[1]),f||(f=32),typeof f=="string"&&f.indexOf(".")>-1){try{this.maskLong=i(f)}catch(A){throw h=A,new Error("Invalid mask: "+f)}for(l=b=32;b>=0;l=--b)if(this.maskLong===4294967295<<32-l>>>0){this.bitmask=l;break}}else if(f||f===0)this.bitmask=parseInt(f,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(A){throw h=A,new Error("Invalid net address: "+c)}if(!(this.bitmask<=32))throw new Error("Invalid mask for ip4: "+f);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 f,h,l;for(l=i(this.first),h=i(this.last),f=0;l<=h;)c(a(l),l,f),f++,l++},u.prototype.toString=function(){return this.base+"/"+this.bitmask},u}(),Pt.ip2long=i,Pt.long2ip=a,Pt.Netmask=r}).call(Pt)});var Ws={};C(Ws,{dcutr:()=>Gs,multicodec:()=>yt});var j=class extends Error{static name="InvalidMessageError";constructor(t="Invalid message"){super(t),this.name="InvalidMessageError"}};var Qs=Symbol.for("@libp2p/service-capabilities"),Ar=Symbol.for("@libp2p/service-dependencies");function G(r=0){return new Uint8Array(r)}function D(r=0){return new Uint8Array(r)}var _n=Math.pow(2,7),On=Math.pow(2,14),zn=Math.pow(2,21),ue=Math.pow(2,28),he=Math.pow(2,35),fe=Math.pow(2,42),le=Math.pow(2,49),w=128,v=127;function S(r){if(r<_n)return 1;if(r<On)return 2;if(r<zn)return 3;if(r<ue)return 4;if(r<he)return 5;if(r<fe)return 6;if(r<le)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function de(r,t,e=0){switch(S(r)){case 8:t[e++]=r&255|w,r/=128;case 7:t[e++]=r&255|w,r/=128;case 6:t[e++]=r&255|w,r/=128;case 5:t[e++]=r&255|w,r/=128;case 4:t[e++]=r&255|w,r>>>=7;case 3:t[e++]=r&255|w,r>>>=7;case 2:t[e++]=r&255|w,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function $n(r,t,e=0){switch(S(r)){case 8:t.set(e++,r&255|w),r/=128;case 7:t.set(e++,r&255|w),r/=128;case 6:t.set(e++,r&255|w),r/=128;case 5:t.set(e++,r&255|w),r/=128;case 4:t.set(e++,r&255|w),r>>>=7;case 3:t.set(e++,r&255|w),r>>>=7;case 2:t.set(e++,r&255|w),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function pe(r,t){let e=r[t],n=0;if(n+=e&v,e<w||(e=r[t+1],n+=(e&v)<<7,e<w)||(e=r[t+2],n+=(e&v)<<14,e<w)||(e=r[t+3],n+=(e&v)<<21,e<w)||(e=r[t+4],n+=(e&v)*ue,e<w)||(e=r[t+5],n+=(e&v)*he,e<w)||(e=r[t+6],n+=(e&v)*fe,e<w)||(e=r[t+7],n+=(e&v)*le,e<w))return n;throw new RangeError("Could not decode varint")}function jn(r,t){let e=r.get(t),n=0;if(n+=e&v,e<w||(e=r.get(t+1),n+=(e&v)<<7,e<w)||(e=r.get(t+2),n+=(e&v)<<14,e<w)||(e=r.get(t+3),n+=(e&v)<<21,e<w)||(e=r.get(t+4),n+=(e&v)*ue,e<w)||(e=r.get(t+5),n+=(e&v)*he,e<w)||(e=r.get(t+6),n+=(e&v)*fe,e<w)||(e=r.get(t+7),n+=(e&v)*le,e<w))return n;throw new RangeError("Could not decode varint")}function H(r,t,e=0){return t==null&&(t=D(S(r))),t instanceof Uint8Array?de(r,t,e):$n(r,t,e)}function W(r,t=0){return r instanceof Uint8Array?pe(r,t):jn(r,t)}function M(r,t){t==null&&(t=r.reduce((o,s)=>o+s.length,0));let e=D(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return e}var ye={};C(ye,{base10:()=>Hn});var vi=new Uint8Array(0);function vr(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){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 Sr(r){return new TextEncoder().encode(r)}function Nr(r){return new TextDecoder().decode(r)}function Gn(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),f=Math.log(256)/Math.log(a);function h(d){if(d instanceof Uint8Array||(ArrayBuffer.isView(d)?d=new Uint8Array(d.buffer,d.byteOffset,d.byteLength):Array.isArray(d)&&(d=Uint8Array.from(d))),!(d instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(d.length===0)return"";for(var A=0,et=0,k=0,_=d.length;k!==_&&d[k]===0;)k++,A++;for(var O=(_-k)*f+1>>>0,P=new Uint8Array(O);k!==_;){for(var z=d[k],J=0,R=O-1;(z!==0||J<et)&&R!==-1;R--,J++)z+=256*P[R]>>>0,P[R]=z%a>>>0,z=z/a>>>0;if(z!==0)throw new Error("Non-zero carry");et=J,k++}for(var $=O-et;$!==O&&P[$]===0;)$++;for(var Mt=u.repeat(A);$<O;++$)Mt+=r.charAt(P[$]);return Mt}function l(d){if(typeof d!="string")throw new TypeError("Expected String");if(d.length===0)return new Uint8Array;var A=0;if(d[A]!==" "){for(var et=0,k=0;d[A]===u;)et++,A++;for(var _=(d.length-A)*c+1>>>0,O=new Uint8Array(_);d[A];){var P=e[d.charCodeAt(A)];if(P===255)return;for(var z=0,J=_-1;(P!==0||z<k)&&J!==-1;J--,z++)P+=a*O[J]>>>0,O[J]=P%256>>>0,P=P/256>>>0;if(P!==0)throw new Error("Non-zero carry");k=z,A++}if(d[A]!==" "){for(var R=_-k;R!==_&&O[R]===0;)R++;for(var $=new Uint8Array(et+(_-R)),Mt=et;R!==_;)$[Mt++]=O[R++];return $}}}function b(d){var A=l(d);if(A)return A;throw new Error(`Non-${t} character`)}return{encode:h,decodeUnsafe:l,decode:b}}var Wn=Gn,qn=Wn,Lr=qn;var ge=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")}},we=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 Ur(this,t)}},xe=class{decoders;constructor(t){this.decoders=t}or(t){return Ur(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 Ur(r,t){return new xe({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var be=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 ge(t,e,n),this.decoder=new we(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function it({name:r,prefix:t,encode:e,decode:n}){return new be(r,t,e,n)}function K({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=Lr(e,r);return it({prefix:t,name:r,encode:n,decode:s=>q(o(s))})}function Xn(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 f=t[r[c]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<e|f,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 Qn(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 Jn(r){let t={};for(let e=0;e<r.length;++e)t[r[e]]=e;return t}function I({name:r,prefix:t,bitsPerChar:e,alphabet:n}){let o=Jn(n);return it({prefix:t,name:r,encode(s){return Qn(s,n,e)},decode(s){return Xn(s,o,e,r)}})}var Hn=K({prefix:"9",name:"base10",alphabet:"0123456789"});var Ee={};C(Ee,{base16:()=>Kn,base16upper:()=>Zn});var Kn=I({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Zn=I({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Ie={};C(Ie,{base2:()=>Yn});var Yn=I({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Ae={};C(Ae,{base256emoji:()=>oo});var Dr=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}"),to=Dr.reduce((r,t,e)=>(r[e]=t,r),[]),eo=Dr.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function ro(r){return r.reduce((t,e)=>(t+=to[e],t),"")}function no(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let o=eo[n];if(o==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(o)}return new Uint8Array(t)}var oo=it({prefix:"\u{1F680}",name:"base256emoji",encode:ro,decode:no});var ve={};C(ve,{base32:()=>X,base32hex:()=>co,base32hexpad:()=>ho,base32hexpadupper:()=>fo,base32hexupper:()=>uo,base32pad:()=>io,base32padupper:()=>ao,base32upper:()=>so,base32z:()=>lo});var X=I({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),so=I({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),io=I({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),ao=I({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),co=I({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),uo=I({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),ho=I({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),fo=I({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),lo=I({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Se={};C(Se,{base36:()=>Et,base36upper:()=>po});var Et=K({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),po=K({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Ne={};C(Ne,{base58btc:()=>N,base58flickr:()=>mo});var N=K({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),mo=K({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Le={};C(Le,{base64:()=>go,base64pad:()=>wo,base64url:()=>Fe,base64urlpad:()=>xo});var go=I({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),wo=I({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Fe=I({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),xo=I({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Ue={};C(Ue,{base8:()=>bo});var bo=I({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var De={};C(De,{identity:()=>yo});var yo=it({prefix:"\0",name:"identity",encode:r=>Nr(r),decode:r=>Sr(r)});var Oi=new TextEncoder,zi=new TextDecoder;var Te={};C(Te,{identity:()=>jo});var Ao=Pr,Cr=128,vo=127,So=~vo,No=Math.pow(2,31);function Pr(r,t,e){t=t||[],e=e||0;for(var n=e;r>=No;)t[e++]=r&255|Cr,r/=128;for(;r&So;)t[e++]=r&255|Cr,r>>>=7;return t[e]=r|0,Pr.bytes=e-n+1,t}var Fo=Ce,Lo=128,Tr=127;function Ce(r,n){var e=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw Ce.bytes=0,new RangeError("Could not decode varint");i=r[s++],e+=o<28?(i&Tr)<<o:(i&Tr)*Math.pow(2,o),o+=7}while(i>=Lo);return Ce.bytes=s-n,e}var Uo=Math.pow(2,7),Do=Math.pow(2,14),Co=Math.pow(2,21),To=Math.pow(2,28),Po=Math.pow(2,35),Mo=Math.pow(2,42),ko=Math.pow(2,49),Ro=Math.pow(2,56),Bo=Math.pow(2,63),Vo=function(r){return r<Uo?1:r<Do?2:r<Co?3:r<To?4:r<Po?5:r<Mo?6:r<ko?7:r<Ro?8:r<Bo?9:10},_o={encode:Ao,decode:Fo,encodingLength:Vo},Oo=_o,It=Oo;function At(r,t=0){return[It.decode(r,t),It.decode.bytes]}function at(r,t,e=0){return It.encode(r,t,e),t}function ct(r){return It.encodingLength(r)}function rt(r,t){let e=t.byteLength,n=ct(r),o=n+ct(e),s=new Uint8Array(o+e);return at(r,s,0),at(e,s,n),s.set(t,o),new ut(r,e,t,s)}function Bt(r){let t=q(r),[e,n]=At(t),[o,s]=At(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new ut(e,o,i,t)}function Mr(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&vr(r.bytes,e.bytes)}}var ut=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=n,this.bytes=o}};var kr=0,zo="identity",Rr=q;function $o(r){return rt(kr,Rr(r))}var jo={code:kr,name:zo,encode:Rr,digest:$o};var ke={};C(ke,{sha256:()=>Go,sha512:()=>Wo});function Me({name:r,code:t,encode:e}){return new Pe(r,t,e)}var Pe=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?rt(this.code,e):e.then(n=>rt(this.code,n))}else throw Error("Unknown type, must be binary type")}};function Vr(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var Go=Me({name:"sha2-256",code:18,encode:Vr("SHA-256")}),Wo=Me({name:"sha2-512",code:19,encode:Vr("SHA-512")});function _r(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return Xo(e,Re(r),t??N.encoder);default:return Qo(e,Re(r),t??X.encoder)}}var Or=new WeakMap;function Re(r){let t=Or.get(r);if(t==null){let e=new Map;return Or.set(r,e),e}return t}var Z=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!==vt)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==Jo)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=rt(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&&Mr(t.multihash,n.multihash)}toString(t){return _r(this,t)}toJSON(){return{"/":_r(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??zr(n,o,s.bytes))}else if(e[Ho]===!0){let{version:n,multihash:o,code:s}=e,i=Bt(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!==vt)throw new Error(`Version 0 CID must use dag-pb (code: ${vt}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=zr(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,vt,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=q(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 ut(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,l]=At(t.subarray(e));return e+=l,h},o=n(),s=vt;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,f=c-i;return{version:o,codec:s,multihashCode:a,digestSize:u,multihashSize:f,size:c}}static parse(t,e){let[n,o]=qo(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 Re(s).set(n,t),s}};function qo(r,t){switch(r[0]){case"Q":{let e=t??N;return[N.prefix,e.decode(`${N.prefix}${r}`)]}case N.prefix:{let e=t??N;return[N.prefix,e.decode(r)]}case X.prefix:{let e=t??X;return[X.prefix,e.decode(r)]}case Et.prefix:{let e=t??Et;return[Et.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 Xo(r,t,e){let{prefix:n}=e;if(n!==N.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 Qo(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 vt=112,Jo=18;function zr(r,t,e){let n=ct(r),o=n+ct(t),s=new Uint8Array(o+e.byteLength);return at(r,s,0),at(t,s,n),s.set(e,o),s}var Ho=Symbol.for("@ipld/js-cid/CID");var St={...De,...Ie,...Ue,...ye,...Ee,...ve,...Se,...Ne,...Le,...Ae},ua={...ke,...Te};function jr(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var $r=jr("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Be=jr("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=D(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),Ko={utf8:$r,"utf-8":$r,hex:St.base16,latin1:Be,ascii:Be,binary:Be,...St},Vt=Ko;function U(r,t="utf8"){let e=Vt[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var _t=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 f=this.readAtomically(()=>{let h=this.readChar();if(h===void 0)return;let l=Number.parseInt(h,t);if(!Number.isNaN(l))return l});if(f===void 0)break;if(s*=t,s+=f,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 Gr=45,Zo=15,ft=new _t;function Ve(r){if(!(r.length>Zo))return ft.new(r).parseWith(()=>ft.readIPv4Addr())}function _e(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>Gr))return ft.new(r).parseWith(()=>ft.readIPv6Addr())}function Ot(r,t=!1){if(r.includes("%")&&(r=r.split("%")[0]),r.length>Gr)return;let e=ft.new(r).parseWith(()=>ft.readIPAddr());if(e)return t&&e.length===4?Uint8Array.from([0,0,0,0,0,0,0,0,0,0,255,255,e[0],e[1],e[2],e[3]]):e}var Sa=parseInt("0xFFFF",16),Na=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function lt(r,t="utf8"){let e=Vt[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function dt(r){return!!Ve(r)}function pt(r){return!!_e(r)}function zt(r){return!!Ot(r)}var Xr=dt,ns=pt,Oe=function(r){let t=0;if(r=r.toString().trim(),Xr(r)){let e=new Uint8Array(t+4);return r.split(/\./g).forEach(n=>{e[t++]=parseInt(n,10)&255}),e}if(ns(r)){let e=r.split(":",8),n;for(n=0;n<e.length;n++){let s=Xr(e[n]),i;s&&(i=Oe(e[n]),e[n]=U(i.slice(0,2),"base16")),i!=null&&++n<8&&e.splice(n,0,U(i.slice(2,4),"base16"))}if(e[0]==="")for(;e.length<8;)e.unshift("0");else if(e[e.length-1]==="")for(;e.length<8;)e.push("0");else if(e.length<8){for(n=0;n<e.length&&e[n]!=="";n++);let s=[n,1];for(n=9-e.length;n>0;n--)s.push("0");e.splice.apply(e,s)}let o=new Uint8Array(t+16);for(n=0;n<e.length;n++){let s=parseInt(e[n],16);o[t++]=s>>8&255,o[t++]=s&255}return o}throw new Error("invalid ip address")},Qr=function(r,t=0,e){t=~~t,e=e??r.length-t;let n=new DataView(r.buffer);if(e===4){let o=[];for(let s=0;s<e;s++)o.push(r[t+s]);return o.join(".")}if(e===16){let o=[];for(let s=0;s<e;s+=2)o.push(n.getUint16(t+s).toString(16));return o.join(":").replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}return""};var mt={},ze={},ss=[[4,32,"ip4"],[6,16,"tcp"],[33,16,"dccp"],[41,128,"ip6"],[42,-1,"ip6zone"],[43,8,"ipcidr"],[53,-1,"dns",!0],[54,-1,"dns4",!0],[55,-1,"dns6",!0],[56,-1,"dnsaddr",!0],[132,16,"sctp"],[273,16,"udp"],[275,0,"p2p-webrtc-star"],[276,0,"p2p-webrtc-direct"],[277,0,"p2p-stardust"],[280,0,"webrtc-direct"],[281,0,"webrtc"],[290,0,"p2p-circuit"],[301,0,"udt"],[302,0,"utp"],[400,-1,"unix",!1,!0],[421,-1,"ipfs"],[421,-1,"p2p"],[443,0,"https"],[444,96,"onion"],[445,296,"onion3"],[446,-1,"garlic64"],[448,0,"tls"],[449,-1,"sni"],[460,0,"quic"],[461,0,"quic-v1"],[465,0,"webtransport"],[466,-1,"certhash"],[477,0,"ws"],[478,0,"wss"],[479,0,"p2p-websocket-star"],[480,0,"http"],[481,-1,"http-path"],[777,-1,"memory"]];ss.forEach(r=>{let t=is(...r);ze[t.code]=t,mt[t.name]=t});function is(r,t,e,n,o){return{code:r,size:t,name:e,resolvable:!!n,path:!!o}}function y(r){if(typeof r=="number"){if(ze[r]!=null)return ze[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(mt[r]!=null)return mt[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var fc=y("ip4"),lc=y("ip6"),dc=y("ipcidr");function We(r,t){switch(y(r).code){case 4:case 41:return cs(t);case 42:return Ge(t);case 43:return U(t,"base10");case 6:case 273:case 33:case 132:return Kr(t).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return Ge(t);case 421:return ls(t);case 444:return Hr(t);case 445:return Hr(t);case 466:return fs(t);case 481:return globalThis.encodeURIComponent(Ge(t));default:return U(t,"base16")}}function qe(r,t){switch(y(r).code){case 4:return Jr(t);case 41:return Jr(t);case 42:return je(t);case 43:return lt(t,"base10");case 6:case 273:case 33:case 132:return Xe(parseInt(t,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return je(t);case 421:return us(t);case 444:return ds(t);case 445:return ps(t);case 466:return hs(t);case 481:return je(globalThis.decodeURIComponent(t));default:return lt(t,"base16")}}var $e=Object.values(St).map(r=>r.decoder),as=function(){let r=$e[0].or($e[1]);return $e.slice(2).forEach(t=>r=r.or(t)),r}();function Jr(r){if(!zt(r))throw new Error("invalid ip address");return Oe(r)}function cs(r){let t=Qr(r,0,r.length);if(t==null)throw new Error("ipBuff is required");if(!zt(t))throw new Error("invalid ip address");return t}function Xe(r){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,r),new Uint8Array(t)}function Kr(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function je(r){let t=lt(r),e=Uint8Array.from(H(t.length));return M([e,t],e.length+t.length)}function Ge(r){let t=W(r);if(r=r.slice(S(t)),r.length!==t)throw new Error("inconsistent lengths");return U(r)}function us(r){let t;r[0]==="Q"||r[0]==="1"?t=Bt(N.decode(`z${r}`)).bytes:t=Z.parse(r).multihash.bytes;let e=Uint8Array.from(H(t.length));return M([e,t],e.length+t.length)}function hs(r){let t=as.decode(r),e=Uint8Array.from(H(t.length));return M([e,t],e.length+t.length)}function fs(r){let t=W(r),e=r.slice(S(t));if(e.length!==t)throw new Error("inconsistent lengths");return"u"+U(e,"base64url")}function ls(r){let t=W(r),e=r.slice(S(t));if(e.length!==t)throw new Error("inconsistent lengths");return U(e,"base58btc")}function ds(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=X.decode("b"+t[0]),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=Xe(n);return M([e,o],e.length+o.length)}function ps(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=X.decode(`b${t[0]}`),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=Xe(n);return M([e,o],e.length+o.length)}function Hr(r){let t=r.slice(0,r.length-2),e=r.slice(r.length-2),n=U(t,"base32"),o=Kr(e);return`${n}:${o}`}function Zr(r){r=Qe(r);let t=[],e=[],n=null,o=r.split("/").slice(1);if(o.length===1&&o[0]==="")return{bytes:new Uint8Array,string:"/",tuples:[],stringTuples:[],path:null};for(let s=0;s<o.length;s++){let i=o[s],a=y(i);if(a.size===0){t.push([a.code]),e.push([a.code]);continue}if(s++,s>=o.length)throw new $t("invalid address: "+r);if(a.path===!0){n=Qe(o.slice(s).join("/")),t.push([a.code,qe(a.code,n)]),e.push([a.code,n]);break}let u=qe(a.code,o[s]);t.push([a.code,u]),e.push([a.code,We(a.code,u)])}return{string:Yr(e),bytes:jt(t),tuples:t,stringTuples:e,path:n}}function Je(r){let t=[],e=[],n=null,o=0;for(;o<r.length;){let s=W(r,o),i=S(s),a=y(s),u=ms(a,r.slice(o+i));if(u===0){t.push([s]),e.push([s]),o+=i;continue}let c=r.slice(o+i,o+i+u);if(o+=u+i,o>r.length)throw new $t("Invalid address Uint8Array: "+U(r,"base16"));t.push([s,c]);let f=We(s,c);if(e.push([s,f]),a.path===!0){n=f;break}}return{bytes:Uint8Array.from(r),string:Yr(e),tuples:t,stringTuples:e,path:n}}function Yr(r){let t=[];return r.map(e=>{let n=y(e[0]);return t.push(n.name),e.length>1&&e[1]!=null&&t.push(e[1]),null}),Qe(t.join("/"))}function jt(r){return M(r.map(t=>{let e=y(t[0]),n=Uint8Array.from(H(e.code));return t.length>1&&t[1]!=null&&(n=M([n,t[1]])),n}))}function ms(r,t){if(r.size>0)return r.size/8;if(r.size===0)return 0;{let e=W(t instanceof Uint8Array?t:Uint8Array.from(t));return e+S(e)}}function Qe(r){return"/"+r.trim().split("/").filter(t=>t).join("/")}var $t=class extends Error{static name="ParseError";name="ParseError";constructor(t){super(`Error parsing address: ${t}`)}};function Gt(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}var gs=Symbol.for("nodejs.util.inspect.custom"),Ke=Symbol.for("@multiformats/js-multiaddr/multiaddr"),ws=[y("dns").code,y("dns4").code,y("dns6").code,y("dnsaddr").code],He=class extends Error{constructor(t="No available resolver"){super(t),this.name="NoAvailableResolverError"}},Wt=class r{bytes;#e;#t;#r;#n;[Ke]=!0;constructor(t){t==null&&(t="");let e;if(t instanceof Uint8Array)e=Je(t);else if(typeof t=="string"){if(t.length>0&&t.charAt(0)!=="/")throw new Error(`multiaddr "${t}" must start with a "/"`);e=Zr(t)}else if(en(t))e=Je(t.bytes);else throw new Error("addr must be a string, Buffer, or another Multiaddr");this.bytes=e.bytes,this.#e=e.string,this.#t=e.tuples,this.#r=e.stringTuples,this.#n=e.path}toString(){return this.#e}toJSON(){return this.toString()}toOptions(){let t,e,n,o,s="",i=y("tcp"),a=y("udp"),u=y("ip4"),c=y("ip6"),f=y("dns6"),h=y("ip6zone");for(let[b,d]of this.stringTuples())b===h.code&&(s=`%${d??""}`),ws.includes(b)&&(e=i.name==="tcp"?"tcp":"udp",o=443,n=`${d??""}${s}`,t=b===f.code?6:4),(b===i.code||b===a.code)&&(e=y(b).name==="tcp"?"tcp":"udp",o=parseInt(d??"")),(b===u.code||b===c.code)&&(e=y(b).name==="tcp"?"tcp":"udp",n=`${d??""}${s}`,t=b===c.code?6:4);if(t==null||e==null||n==null||o==null)throw new Error('multiaddr must have a valid format: "/{ip4, ip6, dns4, dns6, dnsaddr}/{address}/{tcp, udp}/{port}".');return{family:t,host:n,transport:e,port:o}}protos(){return this.#t.map(([t])=>Object.assign({},y(t)))}protoCodes(){return this.#t.map(([t])=>t)}protoNames(){return this.#t.map(([t])=>y(t).name)}tuples(){return this.#t.map(([t,e])=>e==null?[t]:[t,e])}stringTuples(){return this.#r.map(([t,e])=>e==null?[t]:[t,e])}encapsulate(t){return t=new r(t),new r(this.toString()+t.toString())}decapsulate(t){let e=t.toString(),n=this.toString(),o=n.lastIndexOf(e);if(o<0)throw new Error(`Address ${this.toString()} does not contain subaddress: ${t.toString()}`);return new r(n.slice(0,o))}decapsulateCode(t){let e=this.tuples();for(let n=e.length-1;n>=0;n--)if(e[n][0]===t)return new r(jt(e.slice(0,n)));return this}getPeerId(){try{let t=[];this.stringTuples().forEach(([n,o])=>{n===mt.p2p.code&&t.push([n,o]),n===mt["p2p-circuit"].code&&(t=[])});let e=t.pop();if(e?.[1]!=null){let n=e[1];return n[0]==="Q"||n[0]==="1"?U(N.decode(`z${n}`),"base58btc"):U(Z.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){return this.#n}equals(t){return Gt(this.bytes,t.bytes)}async resolve(t){let e=this.protos().find(s=>s.resolvable);if(e==null)return[this];let n=tn.get(e.name);if(n==null)throw new He(`no available resolver for ${e.name}`);return(await n(this,t)).map(s=>Nt(s))}nodeAddress(){let t=this.toOptions();if(t.transport!=="tcp"&&t.transport!=="udp")throw new Error(`multiaddr must have a valid format - no protocol with name: "${t.transport}". Must have a valid transport protocol: "{tcp, udp}"`);return{family:t.family,address:t.host,port:t.port}}isThinWaistAddress(t){let e=(t??this).protos();return!(e.length!==2||e[0].code!==4&&e[0].code!==41||e[1].code!==6&&e[1].code!==273)}[gs](){return`Multiaddr(${this.#e})`}};var tn=new Map;function en(r){return!!r?.[Ke]}function Nt(r){return new Wt(r)}var xs=r=>r.toString().split("/").slice(1),gt=r=>({match:t=>t.length<1?!1:r(t[0])?t.slice(1):!1,pattern:"fn"}),p=r=>({match:t=>gt(e=>e===r).match(t),pattern:r}),nt=()=>({match:r=>gt(t=>typeof t=="string").match(r),pattern:"{string}"}),wt=()=>({match:r=>gt(t=>!isNaN(parseInt(t))).match(r),pattern:"{number}"}),x=()=>({match:r=>{if(r.length<2||r[0]!=="p2p"&&r[0]!=="ipfs")return!1;if(r[1].startsWith("Q")||r[1].startsWith("1"))try{N.decode(`z${r[1]}`)}catch{return!1}else return!1;return r.slice(2)},pattern:"/p2p/{peerid}"}),Ft=()=>({match:r=>{if(r.length<2||r[0]!=="certhash")return!1;try{Fe.decode(r[1])}catch{return!1}return r.slice(2)},pattern:"/certhash/{certhash}"}),g=r=>({match:t=>{let e=r.match(t);return e===!1?t:e},pattern:`optional(${r.pattern})`}),F=(...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},pattern:`or(${r.map(t=>t.pattern).join(", ")})`}),m=(...r)=>({match:t=>{for(let e of r){let n=e.match(t);if(n===!1)return!1;t=n}return t},pattern:`and(${r.map(t=>t.pattern).join(", ")})`});function E(...r){function t(o){let s=xs(o);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 bs=x(),Wc=E(bs),Xt=m(p("dns4"),nt()),Qt=m(p("dns6"),nt()),Jt=m(p("dnsaddr"),nt()),Ye=m(p("dns"),nt()),qc=E(Xt,g(x())),Xc=E(Qt,g(x())),Qc=E(Jt,g(x())),rn=E(F(Ye,Jt,Xt,Qt),g(x())),nn=m(p("ip4"),gt(dt)),on=m(p("ip6"),gt(pt)),tr=F(nn,on),Q=F(tr,Ye,Xt,Qt,Jt),Jc=E(F(tr,m(F(Ye,Jt,Xt,Qt),g(x())))),Hc=E(nn),Kc=E(on),sn=E(tr),er=m(Q,p("tcp"),wt()),Lt=m(Q,p("udp"),wt()),Zc=E(m(er,g(x()))),Yc=E(Lt),rr=m(Lt,p("quic"),g(x())),Ht=m(Lt,p("quic-v1"),g(x())),ys=F(rr,Ht),tu=E(rr),eu=E(Ht),Ze=F(Q,er,Lt,rr,Ht),an=F(m(Ze,p("ws"),g(x()))),ru=E(an),cn=F(m(Ze,p("wss"),g(x())),m(Ze,p("tls"),g(m(p("sni"),nt())),p("ws"),g(x()))),nu=E(cn),un=m(Lt,p("webrtc-direct"),g(Ft()),g(Ft()),g(x())),ou=E(un),hn=m(Ht,p("webtransport"),g(Ft()),g(Ft()),g(x())),su=E(hn),qt=F(an,cn,m(er,g(x())),m(ys,g(x())),m(Q,g(x())),un,hn,x()),iu=E(qt),Es=m(qt,p("p2p-circuit"),x()),Ut=E(Es),Is=F(m(qt,p("p2p-circuit"),p("webrtc"),g(x())),m(qt,p("webrtc"),g(x())),m(p("webrtc"),g(x()))),au=E(Is),As=F(m(Q,p("tcp"),wt(),p("http"),g(x())),m(Q,p("http"),g(x()))),cu=E(As),vs=F(m(Q,p("tcp"),F(m(p("443"),p("http")),m(wt(),p("https")),m(wt(),p("tls"),p("http"))),g(x())),m(Q,p("tls"),p("http"),g(x())),m(Q,p("https"),g(x()))),uu=E(vs),Ss=F(m(p("memory"),nt(),g(x()))),hu=E(Ss);var fn=()=>{let r=new Error("Delay aborted");return r.name="AbortError",r},Ns=new WeakMap;function Fs({clearTimeout:r,setTimeout:t}={}){return(e,{value:n,signal:o}={})=>{if(o?.aborted)return Promise.reject(fn());let s,i,a,u=r??clearTimeout,c=()=>{u(s),a(fn())},f=()=>{o&&o.removeEventListener("abort",c)},h=new Promise((l,b)=>{i=()=>{f(),l(n)},a=b,s=(t??setTimeout)(i,e)});return o&&o.addEventListener("abort",c,{once:!0}),Ns.set(h,()=>{u(s),s=null,i()}),h}}var Ls=Fs(),ln=Ls;function xt(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var Kt=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 Dt(r,t,e){if(t==null)return r;if(t.aborted)return r.catch(()=>{}),Promise.reject(new Kt(e?.errorMessage,e?.errorCode,e?.errorName));let n,o=new Kt(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 nr=class{readNext;haveNext;ended;nextResult;error;constructor(){this.ended=!1,this.readNext=xt(),this.haveNext=xt()}[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=xt(),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=xt(),await Dt(this.readNext.promise,e?.signal,e)}};function dn(){return new nr}var mn=Symbol.for("@achingbrain/uint8arraylist");function pn(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 Zt(r){return!!r?.[mn]}var Y=class r{bufs;length;[mn]=!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(Zt(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(Zt(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=pn(this.bufs,t);return e.buf[e.index]}set(t,e){let n=pn(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(Zt(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 M(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:M(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,f=e>a&&e<=u;if(c&&f){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(f){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(!Zt(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,f;for(let h=e;h<=u;h+=f){f=0;for(let l=c;l>=0;l--){let b=this.get(h+l);if(n[l]!==b){f=Math.max(1,l-a[b]);break}}if(f===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=D(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=G(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=G(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=G(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=D(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=G(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=G(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=G(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=G(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=G(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(!Gt(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 Yt=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};function gn(r,t){let e=dn();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 Y;return{read:async i=>{if(i?.signal?.throwIfAborted(),i?.bytes==null){let{done:u,value:c}=await Dt(n.next(),i?.signal);return u===!0?null:c}for(;o.byteLength<i.bytes;){let{value:u,done:c}=await Dt(n.next(),i?.signal);if(c===!0)throw new Yt("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 te=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},ee=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},re=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function wn(r,t={}){let e=gn(r,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=S(t.maxDataLength));let n=t?.lengthDecoder??W,o=t?.lengthEncoder??H;return{read:async i=>{let a=-1,u=new Y;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 te("Invalid message length");if(t?.maxLengthLength!=null&&u.byteLength>t.maxLengthLength)throw new re("message length length too long");if(a>-1)break}if(t?.maxDataLength!=null&&a>t.maxDataLength)throw new ee("message length too long");return e.read({...i,bytes:a})},write:async(i,a)=>{await e.write(new Y(o(i.byteLength),i),a)},writeV:async(i,a)=>{let u=new Y(...i.flatMap(c=>[o(c.byteLength),c]));await e.write(u,a)},unwrap:()=>e.unwrap()}}function or(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 sr=new Float32Array([-0]),tt=new Uint8Array(sr.buffer);function xn(r,t,e){sr[0]=r,t[e]=tt[0],t[e+1]=tt[1],t[e+2]=tt[2],t[e+3]=tt[3]}function bn(r,t){return tt[0]=r[t],tt[1]=r[t+1],tt[2]=r[t+2],tt[3]=r[t+3],sr[0]}var ir=new Float64Array([-0]),L=new Uint8Array(ir.buffer);function yn(r,t,e){ir[0]=r,t[e]=L[0],t[e+1]=L[1],t[e+2]=L[2],t[e+3]=L[3],t[e+4]=L[4],t[e+5]=L[5],t[e+6]=L[6],t[e+7]=L[7]}function En(r,t){return L[0]=r[t],L[1]=r[t+1],L[2]=r[t+2],L[3]=r[t+3],L[4]=r[t+4],L[5]=r[t+5],L[6]=r[t+6],L[7]=r[t+7],ir[0]}var Us=BigInt(Number.MAX_SAFE_INTEGER),Ds=BigInt(Number.MIN_SAFE_INTEGER),T=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 ot;if(t<Us&&t>Ds)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>In&&(o=0n,++n>In&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(t){if(t===0)return ot;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):ot}},ot=new T(0,0);ot.toBigInt=function(){return 0n};ot.zzEncode=ot.zzDecode=function(){return this};ot.length=function(){return 1};var In=4294967296n;function An(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 vn(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 ar(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 B(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function ne(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var cr=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,B(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 B(this,4);return ne(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw B(this,4);return ne(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw B(this,4);let t=bn(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw B(this,4);let t=En(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 B(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return vn(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw B(this,t);this.pos+=t}else do if(this.pos>=this.len)throw B(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 T(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 B(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 B(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 B(this,8);let t=ne(this.buf,this.pos+=4),e=ne(this.buf,this.pos+=4);return new T(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=pe(this.buf,this.pos);return this.pos+=S(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 ur(r){return new cr(r instanceof Uint8Array?r:r.subarray())}function hr(r,t,e){let n=ur(r);return t.decode(n,void 0,e)}function fr(r){let t=r??8192,e=t>>>1,n,o=t;return function(i){if(i<1||i>e)return D(i);o+i>t&&(n=D(t),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var st=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function lr(){}var pr=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Cs=fr();function Ts(r){return globalThis.Buffer!=null?D(r):Cs(r)}var Tt=class{len;head;tail;states;constructor(){this.len=0,this.head=new st(lr,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new st(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new mr((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(oe,10,T.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=T.fromBigInt(t);return this._push(oe,e.length(),e)}uint64Number(t){return this._push(de,S(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=T.fromBigInt(t).zzEncode();return this._push(oe,e.length(),e)}sint64Number(t){let e=T.fromNumber(t).zzEncode();return this._push(oe,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(dr,1,t?1:0)}fixed32(t){return this._push(Ct,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=T.fromBigInt(t);return this._push(Ct,4,e.lo)._push(Ct,4,e.hi)}fixed64Number(t){let e=T.fromNumber(t);return this._push(Ct,4,e.lo)._push(Ct,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(yn,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(dr,1,0):this.uint32(e)._push(Ms,e,t)}string(t){let e=An(t);return e!==0?this.uint32(e)._push(ar,e,t):this._push(dr,1,0)}fork(){return this.states=new pr(this),this.head=this.tail=new st(lr,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new st(lr,0,0),this.len=0),this}ldelim(){let t=this.head,e=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=e,this.len+=n),this}finish(){let t=this.head.next,e=Ts(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function dr(r,t,e){t[e]=r&255}function Ps(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var mr=class extends st{next;constructor(t,e){super(Ps,t,e),this.next=void 0}};function oe(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 Ct(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 Ms(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(Tt.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(ks,t,r),this},Tt.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(Rs,t,r),this});function ks(r,t,e){t.set(r,e)}function Rs(r,t,e){r.length<40?ar(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(lt(r),e)}function gr(){return new Tt}function wr(r,t){let e=gr();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 se(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function xr(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 se("enum",bt.VARINT,e,n)}function br(r,t){return se("message",bt.LENGTH_DELIMITED,r,t)}var ie=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var V;(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=()=>xr(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=>wr(o,r.codec()),r.decode=(o,s)=>hr(o,r.codec(),s)})(V||(V={}));var Fn=Bn(Nn(),1),Bs=["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"],Vs=Bs.map(r=>new Fn.Netmask(r));function yr(r){for(let t of Vs)if(t.contains(r))return!0;return!1}function _s(r){return/^::ffff:([0-9a-fA-F]{1,4}):([0-9a-fA-F]{1,4})$/.test(r)}function Os(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 yr(o)}function zs(r){return/^::ffff:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(r)}function $s(r){let t=r.split(":"),e=t[t.length-1];return yr(e)}function js(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 Ln(r){return dt(r)?yr(r):_s(r)?Os(r):zs(r)?$s(r):pt(r)?js(r):void 0}function Er(r,t){return Ut.matches(r)||t.dialTransportForMultiaddr(r)==null?!1:rn.matches(r)?!0:sn.matches(r)?Ln(r.toOptions().host)===!1:!1}var Un=1024*4,Dn=100,ae={timeout:5e3,retries:3,maxInboundStreams:1,maxOutboundStreams:1},ce=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??ae.timeout,this.retries=e.retries??ae.retries,this.maxInboundStreams=e.maxInboundStreams??ae.maxInboundStreams,this.maxOutboundStreams=e.maxOutboundStreams??ae.maxOutboundStreams}[Symbol.toStringTag]="@libp2p/dcutr";[Ar]=["@libp2p/identify"];isStarted(){return this.started}async start(){this.started||(this.topologyId=await this.registrar.register(yt,{notifyOnLimitedConnection:!0,onConnect:(t,e)=>{Ut.exactMatch(e.remoteAddr)&&e.direction==="inbound"&&this.upgradeInbound(e).catch(n=>{this.log.error("error during outgoing DCUtR attempt",n)})}}),await this.registrar.handle(yt,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(yt),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([yt],{signal:o.signal,runOnLimitedConnection:!0});let s=or(e,{maxDataLength:Un}).pb(V);this.log("B sending connect to %p",t.remotePeer);let i=Date.now();await s.write({type:V.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!==V.Type.CONNECT)throw this.log("A sent wrong message type"),new j("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 j("DCUtR connect message had no multiaddrs");let c=Date.now()-i;this.log("A sending sync, rtt %dms",c),await s.write({type:V.Type.SYNC,observedAddresses:[]},o),this.log("A waiting for half RTT"),await ln(c/2),this.log("B dialing",u);let f=await this.connectionManager.openConnection(u,{signal:o.signal,priority:Dn,force:!0,initiator:!1});this.log("DCUtR to %p succeeded to address %a, closing relayed connection",t.remotePeer,f.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=>Er(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(Ut.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=or(t,{maxDataLength:Un}).pb(V);this.log("A receiving connect");let s=await o.read(n);if(s.type!==V.Type.CONNECT)throw this.log("B sent wrong message type"),new j("DCUtR message type was incorrect");if(s.observedAddresses.length===0)throw this.log("B sent no multiaddrs"),new j("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 j("DCUtR connect message had no dialable multiaddrs");if(this.log("A sending connect"),await o.write({type:V.Type.CONNECT,observedAddresses:this.addressManager.getAddresses().map(c=>c.bytes)}),this.log("A receiving sync"),(await o.read(n)).type!==V.Type.SYNC)throw new j("DCUtR message type was incorrect");this.log("A dialing",i);let u=await this.connectionManager.openConnection(i,{signal:n.signal,priority:Dn,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=Nt(n);if(!Er(o,this.transportManager))continue;e.push(o)}catch{}return e}};var yt="/libp2p/dcutr";function Gs(r={}){return t=>new ce(t,r)}return Vn(Ws);})();
2
+ "use strict";var Libp2PDcutr=(()=>{var qn=Object.create;var $t=Object.defineProperty;var Hn=Object.getOwnPropertyDescriptor;var Xn=Object.getOwnPropertyNames;var Qn=Object.getPrototypeOf,Jn=Object.prototype.hasOwnProperty;var Kn=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),L=(r,t)=>{for(var e in t)$t(r,e,{get:t[e],enumerable:!0})},Nr=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Xn(t))!Jn.call(r,o)&&o!==e&&$t(r,o,{get:()=>t[o],enumerable:!(n=Hn(t,o))||n.enumerable});return r};var Zn=(r,t,e)=>(e=r!=null?qn(Qn(r)):{},Nr(t||!r||!r.__esModule?$t(e,"default",{value:r,enumerable:!0}):e,r)),Yn=r=>Nr($t({},"__esModule",{value:!0}),r);var Vn=Kn(zt=>{(function(){var r,t,e,n,o,s,i,a;a=function(u){var c,l,h,f;return c=(u&255<<24)>>>24,l=(u&255<<16)>>>16,h=(u&65280)>>>8,f=u&255,[c,l,h,f].join(".")},i=function(u){var c,l,h,f,v,m;for(c=[],h=f=0;f<=3&&u.length!==0;h=++f){if(h>0){if(u[0]!==".")throw new Error("Invalid IP");u=u.substring(1)}m=t(u),v=m[0],l=m[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,f,v;for(f=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)f=f*c+(e(u[h])-n)>>>0;else if(c===16)if("a"<=u[h]&&u[h]<="f")f=f*c+(10+e(u[h])-s)>>>0;else if("A"<=u[h]&&u[h]<="F")f=f*c+(10+e(u[h])-o)>>>0;else break;else break;if(f>4294967295)throw new Error("too large");h++}if(h===v)throw new Error("empty octet");return[f,h]},r=function(){function u(c,l){var h,f,v,m;if(typeof c!="string")throw new Error("Missing `net' parameter");if(l||(m=c.split("/",2),c=m[0],l=m[1]),l||(l=32),typeof l=="string"&&l.indexOf(".")>-1){try{this.maskLong=i(l)}catch(E){throw h=E,new Error("Invalid mask: "+l)}for(f=v=32;v>=0;f=--v)if(this.maskLong===4294967295<<32-f>>>0){this.bitmask=f;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(E){throw h=E,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,f;for(f=i(this.first),h=i(this.last),l=0;f<=h;)c(a(f),f,l),l++,f++},u.prototype.toString=function(){return this.base+"/"+this.bitmask},u}(),zt.ip2long=i,zt.long2ip=a,zt.Netmask=r}).call(zt)});var _i={};L(_i,{dcutr:()=>Li,multicodec:()=>Et});var j=class extends Error{static name="InvalidMessageError";constructor(t="Invalid message"){super(t),this.name="InvalidMessageError"}};var Ui=Symbol.for("@libp2p/service-capabilities"),Pr=Symbol.for("@libp2p/service-dependencies");var Ee={};L(Ee,{base10:()=>io});var na=new Uint8Array(0);function Lr(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){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 _r(r){return new TextEncoder().encode(r)}function Or(r){return new TextDecoder().decode(r)}function to(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(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 E=0,ot=0,R=0,z=m.length;R!==z&&m[R]===0;)R++,E++;for(var V=(z-R)*l+1>>>0,F=new Uint8Array(V);R!==z;){for(var $=m[R],J=0,B=V-1;($!==0||J<ot)&&B!==-1;B--,J++)$+=256*F[B]>>>0,F[B]=$%a>>>0,$=$/a>>>0;if($!==0)throw new Error("Non-zero carry");ot=J,R++}for(var G=V-ot;G!==V&&F[G]===0;)G++;for(var Vt=u.repeat(E);G<V;++G)Vt+=r.charAt(F[G]);return Vt}function f(m){if(typeof m!="string")throw new TypeError("Expected String");if(m.length===0)return new Uint8Array;var E=0;if(m[E]!==" "){for(var ot=0,R=0;m[E]===u;)ot++,E++;for(var z=(m.length-E)*c+1>>>0,V=new Uint8Array(z);m[E];){var F=e[m.charCodeAt(E)];if(F===255)return;for(var $=0,J=z-1;(F!==0||$<R)&&J!==-1;J--,$++)F+=a*V[J]>>>0,V[J]=F%256>>>0,F=F/256>>>0;if(F!==0)throw new Error("Non-zero carry");R=$,E++}if(m[E]!==" "){for(var B=z-R;B!==z&&V[B]===0;)B++;for(var G=new Uint8Array(ot+(z-B)),Vt=ot;B!==z;)G[Vt++]=V[B++];return G}}}function v(m){var E=f(m);if(E)return E;throw new Error(`Non-${t} character`)}return{encode:h,decodeUnsafe:f,decode:v}}var eo=to,ro=eo,Ur=ro;var xe=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")}},be=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 Rr(this,t)}},we=class{decoders;constructor(t){this.decoders=t}or(t){return Rr(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 Rr(r,t){return new we({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var ye=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 xe(t,e,n),this.decoder=new be(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function ht({name:r,prefix:t,encode:e,decode:n}){return new ye(r,t,e,n)}function K({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=Ur(e,r);return ht({prefix:t,name:r,encode:n,decode:s=>q(o(s))})}function no(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 oo(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 so(r){let t={};for(let e=0;e<r.length;++e)t[r[e]]=e;return t}function y({name:r,prefix:t,bitsPerChar:e,alphabet:n}){let o=so(n);return ht({prefix:t,name:r,encode(s){return oo(s,n,e)},decode(s){return no(s,o,e,r)}})}var io=K({prefix:"9",name:"base10",alphabet:"0123456789"});var Ie={};L(Ie,{base16:()=>ao,base16upper:()=>co});var ao=y({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),co=y({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Ce={};L(Ce,{base2:()=>uo});var uo=y({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var ve={};L(ve,{base256emoji:()=>mo});var Br=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),ho=Br.reduce((r,t,e)=>(r[e]=t,r),[]),lo=Br.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function fo(r){return r.reduce((t,e)=>(t+=ho[e],t),"")}function po(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let o=lo[n];if(o==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(o)}return new Uint8Array(t)}var mo=ht({prefix:"\u{1F680}",name:"base256emoji",encode:fo,decode:po});var Se={};L(Se,{base32:()=>Z,base32hex:()=>wo,base32hexpad:()=>Eo,base32hexpadupper:()=>Io,base32hexupper:()=>yo,base32pad:()=>xo,base32padupper:()=>bo,base32upper:()=>go,base32z:()=>Co});var Z=y({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),go=y({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),xo=y({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),bo=y({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),wo=y({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),yo=y({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Eo=y({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Io=y({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Co=y({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var De={};L(De,{base36:()=>It,base36upper:()=>vo});var It=K({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),vo=K({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Ae={};L(Ae,{base58btc:()=>T,base58flickr:()=>So});var T=K({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),So=K({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Te={};L(Te,{base64:()=>Do,base64pad:()=>Ao,base64url:()=>Ct,base64urlpad:()=>To});var Do=y({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Ao=y({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Ct=y({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),To=y({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Ne={};L(Ne,{base8:()=>No});var No=y({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Pe={};L(Pe,{identity:()=>Po});var Po=ht({prefix:"\0",name:"identity",encode:r=>Or(r),decode:r=>_r(r)});var wa=new TextEncoder,ya=new TextDecoder;var _e={};L(_e,{identity:()=>Yo});var Oo=zr,Mr=128,Fo=127,Uo=~Fo,Ro=Math.pow(2,31);function zr(r,t,e){t=t||[],e=e||0;for(var n=e;r>=Ro;)t[e++]=r&255|Mr,r/=128;for(;r&Uo;)t[e++]=r&255|Mr,r>>>=7;return t[e]=r|0,zr.bytes=e-n+1,t}var Bo=Le,Mo=128,kr=127;function Le(r,n){var e=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw Le.bytes=0,new RangeError("Could not decode varint");i=r[s++],e+=o<28?(i&kr)<<o:(i&kr)*Math.pow(2,o),o+=7}while(i>=Mo);return Le.bytes=s-n,e}var ko=Math.pow(2,7),zo=Math.pow(2,14),Vo=Math.pow(2,21),$o=Math.pow(2,28),Wo=Math.pow(2,35),Go=Math.pow(2,42),jo=Math.pow(2,49),qo=Math.pow(2,56),Ho=Math.pow(2,63),Xo=function(r){return r<ko?1:r<zo?2:r<Vo?3:r<$o?4:r<Wo?5:r<Go?6:r<jo?7:r<qo?8:r<Ho?9:10},Qo={encode:Oo,decode:Bo,encodingLength:Xo},Jo=Qo,vt=Jo;function St(r,t=0){return[vt.decode(r,t),vt.decode.bytes]}function lt(r,t,e=0){return vt.encode(r,t,e),t}function ft(r){return vt.encodingLength(r)}function st(r,t){let e=t.byteLength,n=ft(r),o=n+ft(e),s=new Uint8Array(o+e);return lt(r,s,0),lt(e,s,n),s.set(t,o),new dt(r,e,t,s)}function Vr(r){let t=q(r),[e,n]=St(t),[o,s]=St(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new dt(e,o,i,t)}function $r(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&Lr(r.bytes,e.bytes)}}var dt=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=n,this.bytes=o}};var Wr=0,Ko="identity",Gr=q;function Zo(r){return st(Wr,Gr(r))}var Yo={code:Wr,name:Ko,encode:Gr,digest:Zo};var Ue={};L(Ue,{sha256:()=>ts,sha512:()=>es});function Fe({name:r,code:t,encode:e}){return new Oe(r,t,e)}var Oe=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 qr(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var ts=Fe({name:"sha2-256",code:18,encode:qr("SHA-256")}),es=Fe({name:"sha2-512",code:19,encode:qr("SHA-512")});function Hr(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return ns(e,Re(r),t??T.encoder);default:return os(e,Re(r),t??Z.encoder)}}var Xr=new WeakMap;function Re(r){let t=Xr.get(r);if(t==null){let e=new Map;return Xr.set(r,e),e}return t}var Y=class r{code;version;multihash;bytes;"/";constructor(t,e,n,o){this.code=e,this.version=t,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:e}=this;if(t!==At)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==ss)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&&$r(t.multihash,n.multihash)}toString(t){return Hr(this,t)}toJSON(){return{"/":Hr(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??Qr(n,o,s.bytes))}else if(e[is]===!0){let{version:n,multihash:o,code:s}=e,i=Vr(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!==At)throw new Error(`Version 0 CID must use dag-pb (code: ${At}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=Qr(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,At,t)}static createV1(t,e){return r.create(1,t,e)}static decode(t){let[e,n]=r.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return e}static decodeFirst(t){let e=r.inspectBytes(t),n=e.size-e.multihashSize,o=q(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 dt(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,f]=St(t.subarray(e));return e+=f,h},o=n(),s=At;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]=rs(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 Re(s).set(n,t),s}};function rs(r,t){switch(r[0]){case"Q":{let e=t??T;return[T.prefix,e.decode(`${T.prefix}${r}`)]}case T.prefix:{let e=t??T;return[T.prefix,e.decode(r)]}case Z.prefix:{let e=t??Z;return[Z.prefix,e.decode(r)]}case It.prefix:{let e=t??It;return[It.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 ns(r,t,e){let{prefix:n}=e;if(n!==T.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 os(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 At=112,ss=18;function Qr(r,t,e){let n=ft(r),o=n+ft(t),s=new Uint8Array(o+e.byteLength);return lt(r,s,0),lt(t,s,n),s.set(e,o),s}var is=Symbol.for("@ipld/js-cid/CID");var Tt={...Pe,...Ce,...Ne,...Ee,...Ie,...Se,...De,...Ae,...Te,...ve},$a={...Ue,..._e};function H(r=0){return new Uint8Array(r)}function N(r=0){return new Uint8Array(r)}function Kr(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var Jr=Kr("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Be=Kr("ascii","a",r=>{let t="a";for(let e=0;e<r.length;e++)t+=String.fromCharCode(r[e]);return t},r=>{r=r.substring(1);let t=N(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),as={utf8:Jr,"utf-8":Jr,hex:Tt.base16,latin1:Be,ascii:Be,binary:Be,...Tt},Gt=as;function U(r,t="utf8"){let e=Gt[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var I=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},X=class extends Error{static name="ValidationError";name="ValidationError"},Nt=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},jt=class extends Error{static name="InvalidProtocolError";name="InvalidProtocolError"};function qt(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 W(r,t="utf8"){let e=Gt[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}var cs=Math.pow(2,7),us=Math.pow(2,14),hs=Math.pow(2,21),Me=Math.pow(2,28),ke=Math.pow(2,35),ze=Math.pow(2,42),Ve=Math.pow(2,49),x=128,S=127;function P(r){if(r<cs)return 1;if(r<us)return 2;if(r<hs)return 3;if(r<Me)return 4;if(r<ke)return 5;if(r<ze)return 6;if(r<Ve)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function pt(r,t,e=0){switch(P(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 ls(r,t,e=0){switch(P(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 $e(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)*Me,e<x)||(e=r[t+5],n+=(e&S)*ke,e<x)||(e=r[t+6],n+=(e&S)*ze,e<x)||(e=r[t+7],n+=(e&S)*Ve,e<x))return n;throw new RangeError("Could not decode varint")}function fs(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)*Me,e<x)||(e=r.get(t+5),n+=(e&S)*ke,e<x)||(e=r.get(t+6),n+=(e&S)*ze,e<x)||(e=r.get(t+7),n+=(e&S)*Ve,e<x))return n;throw new RangeError("Could not decode varint")}function Zr(r,t,e=0){return t==null&&(t=N(P(r))),t instanceof Uint8Array?pt(r,t,e):ls(r,t,e)}function Pt(r,t=0){return r instanceof Uint8Array?$e(r,t):fs(r,t)}function tt(r,t){t==null&&(t=r.reduce((o,s)=>o+s.length,0));let e=N(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return e}var Ht=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 f=Number.parseInt(h,t);if(!Number.isNaN(f))return f});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,ps=15,Xt=new Ht;function We(r){if(!(r.length>ps))return Xt.new(r).parseWith(()=>Xt.readIPv4Addr())}function Ge(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>ds))return Xt.new(r).parseWith(()=>Xt.readIPv6Addr())}function et(r){return!!We(r)}function mt(r){return!!Ge(r)}function qe(r){return t=>U(t,r)}function He(r){return t=>W(t,r)}function gt(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 en(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=W(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 tt([e,o],e.length+o.length)}function rn(r){let t=r.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==56)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion3 address.`);let e=Z.decode(`b${t[0]}`),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=it(n);return tt([e,o],e.length+o.length)}function Xe(r){let t=r.subarray(0,r.length-2),e=r.subarray(r.length-2),n=U(t,"base32"),o=gt(e);return`${n}:${o}`}var Qe=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 I("Invalid byte value in IP address");t[n]=o}),t},nn=function(r){let t=0;r=r.toString().trim();let e=r.split(":",8),n;for(n=0;n<e.length;n++){let s=et(e[n]),i;s&&(i=Qe(e[n]),e[n]=U(i.subarray(0,2),"base16")),i!=null&&++n<8&&e.splice(n,0,U(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 I("Invalid byte value in IP address");o[t++]=s>>8&255,o[t++]=s&255}return o},on=function(r){if(r.byteLength!==4)throw new I("IPv4 address was incorrect length");let t=[];for(let e=0;e<r.byteLength;e++)t.push(r[e]);return t.join(".")},sn=function(r){if(r.byteLength!==16)throw new I("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 I(`Invalid IPv6 address "${e}"`)}};function an(r){try{let t=new URL(`http://[${r}]`);return t.hostname.substring(1,t.hostname.length-1)}catch{throw new I(`Invalid IPv6 address "${r}"`)}}var je=Object.values(Tt).map(r=>r.decoder),ms=function(){let r=je[0].or(je[1]);return je.slice(2).forEach(t=>r=r.or(t)),r}();function cn(r){return ms.decode(r)}function un(r){return t=>r.encoder.encode(t)}function gs(r){if(parseInt(r).toString()!==r)throw new X("Value must be an integer")}function xs(r){if(r<0)throw new X("Value must be a positive integer, or zero")}function bs(r){return t=>{if(t>r)throw new X(`Value must be smaller than or equal to ${r}`)}}function ws(...r){return t=>{for(let e of r)e(t)}}var Lt=ws(gs,xs,bs(65535));var C=-1,Je=class{protocolsByCode=new Map;protocolsByName=new Map;getCodec(t){let e;if(typeof t=="string"?e=this.protocolsByName.get(t):e=this.protocolsByCode.get(t),e==null)throw new jt(`Protocol ${t} was unknown`);return e}addCodec(t,e,n){this.protocolsByCode.set(t,e),this.protocolsByName.set(e.name,e),n?.forEach(o=>{this.protocolsByName.set(o,e)})}deleteCodec(t){let e=this.getCodec(t);e!=null&&(this.protocolsByCode.delete(e.code),this.protocolsByName.delete(e.name),e.aliases?.forEach(n=>{this.protocolsByName.delete(n)}))}},_=new Je,Qs=[{code:4,name:"ip4",size:32,valueToBytes:Qe,bytesToValue:on,validate:r=>{if(!et(r))throw new X(`Invalid IPv4 address "${r}"`)}},{code:6,name:"tcp",size:16,valueToBytes:it,bytesToValue:gt,validate:Lt},{code:273,name:"udp",size:16,valueToBytes:it,bytesToValue:gt,validate:Lt},{code:33,name:"dccp",size:16,valueToBytes:it,bytesToValue:gt,validate:Lt},{code:41,name:"ip6",size:128,valueToBytes:nn,bytesToValue:sn,stringToValue:an,validate:r=>{if(!mt(r))throw new X(`Invalid IPv6 address "${r}"`)}},{code:42,name:"ip6zone",size:C},{code:43,name:"ipcidr",size:8,bytesToValue:qe("base10"),valueToBytes:He("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:gt,validate:Lt},{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:qe("base58btc"),valueToBytes:r=>r.startsWith("Q")||r.startsWith("1")?He("base58btc")(r):Y.parse(r).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:Xe,valueToBytes:en},{code:445,name:"onion3",size:296,bytesToValue:Xe,valueToBytes:rn},{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(Ct),valueToBytes:cn},{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}];Qs.forEach(r=>{_.addCodec(r.code,r,r.aliases)});function hn(r){let t=[],e=0;for(;e<r.length;){let n=Pt(r,e),o=_.getCodec(n),s=P(n),i=Js(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 l=e+s+a,h=r.subarray(l,l+i);c.value=o.bytesToValue?.(h)??U(h)}t.push(c),e+=u}return t}function ln(r){let t=0,e=[];for(let n of r){if(n.bytes==null){let o=_.getCodec(n.code),s=P(n.code),i,a=0,u=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??W(n.value),a=i.byteLength,o.size===C&&(u=P(a)));let c=new Uint8Array(s+u+a),l=0;pt(n.code,c,l),l+=s,i!=null&&(o.size===C&&(pt(a,c,l),l+=u),c.set(i,l)),n.bytes=c}e.push(n.bytes),t+=n.bytes.byteLength}return tt(e,t)}function fn(r){if(r.charAt(0)!=="/")throw new I('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=_.getCodec(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 I(`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 I(`Component ${o} was missing value`);c.value=u.stringToValue?.(n)??n}t.push(c),n="",o="",e="protocol"}}}if(o!==""&&n!=="")throw new I("Incomplete multiaddr");return t}function dn(r){return`/${r.flatMap(t=>{if(t.value==null)return t.name;let e=_.getCodec(t.code);if(e==null)throw new I(`Unknown protocol code ${t.code}`);return[t.name,e.valueToString?.(t.value)??t.value]}).join("/")}`}function Js(r,t,e){return r.size==null||r.size===0?0:r.size>0?r.size/8:Pt(t,e)}var Ks=Symbol.for("nodejs.util.inspect.custom"),or=Symbol.for("@multiformats/multiaddr"),Zs=[53,54,55,56],nr=class extends Error{constructor(t="No available resolver"){super(t),this.name="NoAvailableResolverError"}};function Ys(r){if(r==null&&(r="/"),mn(r))return r.getComponents();if(r instanceof Uint8Array)return hn(r);if(typeof r=="string")return r=r.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),r===""&&(r="/"),fn(r);if(Array.isArray(r))return r;throw new I("Must be a string, Uint8Array, Component[], or another Multiaddr")}var Yt=class r{[or]=!0;#t;#e;#r;constructor(t="/",e={}){this.#t=Ys(t),e.validate!==!1&&ti(this)}get bytes(){return this.#r==null&&(this.#r=ln(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??""}`),Zs.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=_.getCodec(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=_.getCodec(t),o=[t];return e!=null&&o.push(n.valueToBytes?.(e)??W(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 Nt(`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"?U(T.decode(`z${n}`),"base58btc"):U(Y.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){for(let t of this.#t)if(_.getCodec(t.code).path)return t.value??null;return null}equals(t){return qt(this.bytes,t.bytes)}async resolve(t){let e=this.protos().find(s=>s.resolvable);if(e==null)return[this];let n=pn.get(e.name);if(n==null)throw new nr(`no available resolver for ${e.name}`);return(await n(this,t)).map(s=>Ot(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)}[Ks](){return`Multiaddr(${this.toString()})`}};function ti(r){r.getComponents().forEach(t=>{let e=_.getCodec(t.code);t.value!=null&&e.validate?.(t.value)})}var Yc=parseInt("0xFFFF",16),tu=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);var pn=new Map;function mn(r){return!!r?.[or]}function Ot(r){return new Yt(r)}var si=r=>r.toString().split("/").slice(1),xt=r=>({match:t=>t.length<1?!1:r(t[0])?t.slice(1):!1,pattern:"fn"}),d=r=>({match:t=>xt(e=>e===r).match(t),pattern:r}),at=()=>({match:r=>xt(t=>typeof t=="string").match(r),pattern:"{string}"}),bt=()=>({match:r=>xt(t=>!isNaN(parseInt(t))).match(r),pattern:"{number}"}),b=()=>({match:r=>{if(r.length<2||r[0]!=="p2p"&&r[0]!=="ipfs")return!1;if(r[1].startsWith("Q")||r[1].startsWith("1"))try{T.decode(`z${r[1]}`)}catch{return!1}else return!1;return r.slice(2)},pattern:"/p2p/{peerid}"}),Ft=()=>({match:r=>{if(r.length<2||r[0]!=="certhash")return!1;try{Ct.decode(r[1])}catch{return!1}return r.slice(2)},pattern:"/certhash/{certhash}"}),g=r=>({match:t=>{let e=r.match(t);return e===!1?t:e},pattern:`optional(${r.pattern})`}),D=(...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},pattern:`or(${r.map(t=>t.pattern).join(", ")})`}),p=(...r)=>({match:t=>{for(let e of r){let n=e.match(t);if(n===!1)return!1;t=n}return t},pattern:`and(${r.map(t=>t.pattern).join(", ")})`});function w(...r){function t(o){let s=si(o);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 ii=b(),Gu=w(ii),ee=p(d("dns4"),at()),re=p(d("dns6"),at()),ne=p(d("dnsaddr"),at()),ir=p(d("dns"),at()),ju=w(ee,g(b())),qu=w(re,g(b())),Hu=w(ne,g(b())),bn=w(D(ir,ne,ee,re),g(b())),wn=p(d("ip4"),xt(et)),yn=p(d("ip6"),xt(mt)),ar=D(wn,yn),Q=D(ar,ir,ee,re,ne),Xu=w(D(ar,p(D(ir,ne,ee,re),g(b())))),Qu=w(wn),Ju=w(yn),En=w(ar),cr=p(Q,d("tcp"),bt()),Ut=p(Q,d("udp"),bt()),Ku=w(p(cr,g(b()))),Zu=w(Ut),ur=p(Ut,d("quic"),g(b())),oe=p(Ut,d("quic-v1"),g(b())),ai=D(ur,oe),Yu=w(ur),th=w(oe),sr=D(Q,cr,Ut,ur,oe),In=D(p(sr,d("ws"),g(b()))),eh=w(In),Cn=D(p(sr,d("wss"),g(b())),p(sr,d("tls"),g(p(d("sni"),at())),d("ws"),g(b()))),rh=w(Cn),vn=p(Ut,d("webrtc-direct"),g(Ft()),g(Ft()),g(b())),nh=w(vn),Sn=p(oe,d("webtransport"),g(Ft()),g(Ft()),g(b())),oh=w(Sn),te=D(In,Cn,p(cr,g(b())),p(ai,g(b())),p(Q,g(b())),vn,Sn,b()),sh=w(te),ci=p(te,d("p2p-circuit"),b()),Rt=w(ci),ui=D(p(te,d("p2p-circuit"),d("webrtc"),g(b())),p(te,d("webrtc"),g(b())),p(d("webrtc"),g(b()))),ih=w(ui),hi=D(p(Q,d("tcp"),bt(),d("http"),g(b())),p(Q,d("http"),g(b()))),ah=w(hi),li=D(p(Q,d("tcp"),D(p(d("443"),d("http")),p(bt(),d("https")),p(bt(),d("tls"),d("http"))),g(b())),p(Q,d("tls"),d("http"),g(b())),p(Q,d("https"),g(b()))),ch=w(li),fi=D(p(d("memory"),at(),g(b()))),uh=w(fi);var Dn=()=>{let r=new Error("Delay aborted");return r.name="AbortError",r},di=new WeakMap;function pi({clearTimeout:r,setTimeout:t}={}){return(e,{value:n,signal:o}={})=>{if(o?.aborted)return Promise.reject(Dn());let s,i,a,u=r??clearTimeout,c=()=>{u(s),a(Dn())},l=()=>{o&&o.removeEventListener("abort",c)},h=new Promise((f,v)=>{i=()=>{l(),f(n)},a=v,s=(t??setTimeout)(i,e)});return o&&o.addEventListener("abort",c,{once:!0}),di.set(h,()=>{u(s),s=null,i()}),h}}var mi=pi(),An=mi;function wt(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var se=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 Bt(r,t,e){if(t==null)return r;if(t.aborted)return r.catch(()=>{}),Promise.reject(new se(e?.errorMessage,e?.errorCode,e?.errorName));let n,o=new se(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 hr=class{readNext;haveNext;ended;nextResult;error;constructor(){this.ended=!1,this.readNext=wt(),this.haveNext=wt()}[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=wt(),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=wt(),await Bt(this.readNext.promise,e?.signal,e)}};function Tn(){return new hr}var Pn=Symbol.for("@achingbrain/uint8arraylist");function Nn(r,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let e=0;for(let n of r){let o=e+n.byteLength;if(t<o)return{buf:n,index:t-e};e=o}throw new RangeError("index is out of bounds")}function ie(r){return!!r?.[Pn]}var rt=class r{bufs;length;[Pn]=!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(ie(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(ie(n))e+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}get(t){let e=Nn(this.bufs,t);return e.buf[e.index]}set(t,e){let n=Nn(this.bufs,t);n.buf[n.index]=e}write(t,e=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(e+n,t[n]);else if(ie(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 tt(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:tt(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(!ie(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 f=c;f>=0;f--){let v=this.get(h+f);if(n[f]!==v){l=Math.max(1,f-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=N(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=H(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=H(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=H(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=N(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=H(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=H(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=H(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=H(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=H(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(!qt(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 ae=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};function Ln(r,t){let e=Tn();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 Bt(n.next(),i?.signal);return u===!0?null:c}for(;o.byteLength<i.bytes;){let{value:u,done:c}=await Bt(n.next(),i?.signal);if(c===!0)throw new ae("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 ce=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},ue=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},he=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function _n(r,t={}){let e=Ln(r,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=P(t.maxDataLength));let n=t?.lengthDecoder??Pt,o=t?.lengthEncoder??Zr;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 ce("Invalid message length");if(t?.maxLengthLength!=null&&u.byteLength>t.maxLengthLength)throw new he("message length length too long");if(a>-1)break}if(t?.maxDataLength!=null&&a>t.maxDataLength)throw new ue("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 lr(r,t){let e=_n(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 fr=new Float32Array([-0]),nt=new Uint8Array(fr.buffer);function On(r,t,e){fr[0]=r,t[e]=nt[0],t[e+1]=nt[1],t[e+2]=nt[2],t[e+3]=nt[3]}function Fn(r,t){return nt[0]=r[t],nt[1]=r[t+1],nt[2]=r[t+2],nt[3]=r[t+3],fr[0]}var dr=new Float64Array([-0]),A=new Uint8Array(dr.buffer);function Un(r,t,e){dr[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 Rn(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],dr[0]}var gi=BigInt(Number.MAX_SAFE_INTEGER),xi=BigInt(Number.MIN_SAFE_INTEGER),O=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 ct;if(t<gi&&t>xi)return this.fromNumber(Number(t));let e=t<0n;e&&(t=-t);let n=t>>32n,o=t-(n<<32n);return e&&(n=~n|0n,o=~o|0n,++o>Bn&&(o=0n,++n>Bn&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(t){if(t===0)return ct;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):ct}},ct=new O(0,0);ct.toBigInt=function(){return 0n};ct.zzEncode=ct.zzDecode=function(){return this};ct.length=function(){return 1};var Bn=4294967296n;function Mn(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 kn(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 pr(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 M(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function le(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var mr=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,M(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 M(this,4);return le(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw M(this,4);return le(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw M(this,4);let t=Fn(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw M(this,4);let t=Rn(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 M(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return kn(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw M(this,t);this.pos+=t}else do if(this.pos>=this.len)throw M(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 O(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 M(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 M(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 M(this,8);let t=le(this.buf,this.pos+=4),e=le(this.buf,this.pos+=4);return new O(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=$e(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 gr(r){return new mr(r instanceof Uint8Array?r:r.subarray())}function xr(r,t,e){let n=gr(r);return t.decode(n,void 0,e)}function br(r){let t=r??8192,e=t>>>1,n,o=t;return function(i){if(i<1||i>e)return N(i);o+i>t&&(n=N(t),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var ut=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function wr(){}var Er=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},bi=br();function wi(r){return globalThis.Buffer!=null?N(r):bi(r)}var kt=class{len;head;tail;states;constructor(){this.len=0,this.head=new ut(wr,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new ut(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Ir((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(fe,10,O.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=O.fromBigInt(t);return this._push(fe,e.length(),e)}uint64Number(t){return this._push(pt,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=O.fromBigInt(t).zzEncode();return this._push(fe,e.length(),e)}sint64Number(t){let e=O.fromNumber(t).zzEncode();return this._push(fe,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(yr,1,t?1:0)}fixed32(t){return this._push(Mt,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=O.fromBigInt(t);return this._push(Mt,4,e.lo)._push(Mt,4,e.hi)}fixed64Number(t){let e=O.fromNumber(t);return this._push(Mt,4,e.lo)._push(Mt,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(On,4,t)}double(t){return this._push(Un,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(yr,1,0):this.uint32(e)._push(Ei,e,t)}string(t){let e=Mn(t);return e!==0?this.uint32(e)._push(pr,e,t):this._push(yr,1,0)}fork(){return this.states=new Er(this),this.head=this.tail=new ut(wr,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 ut(wr,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=wi(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function yr(r,t,e){t[e]=r&255}function yi(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var Ir=class extends ut{next;constructor(t,e){super(yi,t,e),this.next=void 0}};function fe(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 Mt(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 Ei(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(kt.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(Ii,t,r),this},kt.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(Ci,t,r),this});function Ii(r,t,e){t.set(r,e)}function Ci(r,t,e){r.length<40?pr(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(W(r),e)}function Cr(){return new kt}function vr(r,t){let e=Cr();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var yt;(function(r){r[r.VARINT=0]="VARINT",r[r.BIT64=1]="BIT64",r[r.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",r[r.START_GROUP=3]="START_GROUP",r[r.END_GROUP=4]="END_GROUP",r[r.BIT32=5]="BIT32"})(yt||(yt={}));function de(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function Sr(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 de("enum",yt.VARINT,e,n)}function Dr(r,t){return de("message",yt.LENGTH_DELIMITED,r,t)}var pe=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var k;(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=()=>Sr(e)}(t=r.Type||(r.Type={}));let n;r.codec=()=>(n==null&&(n=Dr((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 pe('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=>vr(o,r.codec()),r.decode=(o,s)=>xr(o,r.codec(),s)})(k||(k={}));var $n=Zn(Vn(),1),vi=["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"],Si=vi.map(r=>new $n.Netmask(r));function Ar(r){for(let t of Si)if(t.contains(r))return!0;return!1}function Di(r){return/^::ffff:([0-9a-fA-F]{1,4}):([0-9a-fA-F]{1,4})$/.test(r)}function Ai(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 Ti(r){return/^::ffff:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(r)}function Ni(r){let t=r.split(":"),e=t[t.length-1];return Ar(e)}function Pi(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 Wn(r){if(et(r))return Ar(r);if(Di(r))return Ai(r);if(Ti(r))return Ni(r);if(mt(r))return Pi(r)}function Tr(r,t){return Rt.matches(r)||t.dialTransportForMultiaddr(r)==null?!1:bn.matches(r)?!0:En.matches(r)?Wn(r.toOptions().host)===!1:!1}var Gn=1024*4,jn=100,me={timeout:5e3,retries:3,maxInboundStreams:1,maxOutboundStreams:1},ge=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??me.timeout,this.retries=e.retries??me.retries,this.maxInboundStreams=e.maxInboundStreams??me.maxInboundStreams,this.maxOutboundStreams=e.maxOutboundStreams??me.maxOutboundStreams}[Symbol.toStringTag]="@libp2p/dcutr";[Pr]=["@libp2p/identify"];isStarted(){return this.started}async start(){this.started||(this.topologyId=await this.registrar.register(Et,{notifyOnLimitedConnection:!0,onConnect:(t,e)=>{Rt.exactMatch(e.remoteAddr)&&e.direction==="inbound"&&this.upgradeInbound(e).catch(n=>{this.log.error("error during outgoing DCUtR attempt",n)})}}),await this.registrar.handle(Et,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(Et),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([Et],{signal:o.signal,runOnLimitedConnection:!0});let s=lr(e,{maxDataLength:Gn}).pb(k);this.log("B sending connect to %p",t.remotePeer);let i=Date.now();await s.write({type:k.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!==k.Type.CONNECT)throw this.log("A sent wrong message type"),new j("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 j("DCUtR connect message had no multiaddrs");let c=Date.now()-i;this.log("A sending sync, rtt %dms",c),await s.write({type:k.Type.SYNC,observedAddresses:[]},o),this.log("A waiting for half RTT"),await An(c/2),this.log("B dialing",u);let l=await this.connectionManager.openConnection(u,{signal:o.signal,priority:jn,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=>Tr(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(Rt.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=lr(t,{maxDataLength:Gn}).pb(k);this.log("A receiving connect");let s=await o.read(n);if(s.type!==k.Type.CONNECT)throw this.log("B sent wrong message type"),new j("DCUtR message type was incorrect");if(s.observedAddresses.length===0)throw this.log("B sent no multiaddrs"),new j("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 j("DCUtR connect message had no dialable multiaddrs");if(this.log("A sending connect"),await o.write({type:k.Type.CONNECT,observedAddresses:this.addressManager.getAddresses().map(c=>c.bytes)}),this.log("A receiving sync"),(await o.read(n)).type!==k.Type.SYNC)throw new j("DCUtR message type was incorrect");this.log("A dialing",i);let u=await this.connectionManager.openConnection(i,{signal:n.signal,priority:jn,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=Ot(n);if(!Tr(o,this.transportManager))continue;e.push(o)}catch{}return e}};var Et="/libp2p/dcutr";function Li(r={}){return t=>new ge(t,r)}return Yn(_i);})();
3
3
  return Libp2PDcutr}));
4
4
  //# sourceMappingURL=index.min.js.map