@libp2p/dcutr 1.0.9-3e47d88fd → 1.0.9-72f0e09f7

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,14 +1,3 @@
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 Vn=Object.create;var Ut=Object.defineProperty;var zn=Object.getOwnPropertyDescriptor;var _n=Object.getOwnPropertyNames;var jn=Object.getPrototypeOf,Gn=Object.prototype.hasOwnProperty;var mr=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),$=(r,t)=>{for(var e in t)Ut(r,e,{get:t[e],enumerable:!0})},gr=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of _n(t))!Gn.call(r,i)&&i!==e&&Ut(r,i,{get:()=>t[i],enumerable:!(n=zn(t,i))||n.enumerable});return r};var wr=(r,t,e)=>(e=r!=null?Vn(jn(r)):{},gr(t||!r||!r.__esModule?Ut(e,"default",{value:r,enumerable:!0}):e,r)),Wn=r=>gr(Ut({},"__esModule",{value:!0}),r);var Nn=mr(Rt=>{(function(){var r,t,e,n,i,o,a,u;u=function(l){var d,b,w,p;return d=(l&255<<24)>>>24,b=(l&255<<16)>>>16,w=(l&65280)>>>8,p=l&255,[d,b,w,p].join(".")},a=function(l){var d,b,w,p,s,c;for(d=[],w=p=0;p<=3&&l.length!==0;w=++p){if(w>0){if(l[0]!==".")throw new Error("Invalid IP");l=l.substring(1)}c=t(l),s=c[0],b=c[1],l=l.substring(b),d.push(s)}if(l.length!==0)throw new Error("Invalid IP");switch(d.length){case 1:if(d[0]>4294967295)throw new Error("Invalid IP");return d[0]>>>0;case 2:if(d[0]>255||d[1]>16777215)throw new Error("Invalid IP");return(d[0]<<24|d[1])>>>0;case 3:if(d[0]>255||d[1]>255||d[2]>65535)throw new Error("Invalid IP");return(d[0]<<24|d[1]<<16|d[2])>>>0;case 4:if(d[0]>255||d[1]>255||d[2]>255||d[3]>255)throw new Error("Invalid IP");return(d[0]<<24|d[1]<<16|d[2]<<8|d[3])>>>0;default:throw new Error("Invalid IP")}},e=function(l){return l.charCodeAt(0)},n=e("0"),o=e("a"),i=e("A"),t=function(l){var d,b,w,p,s;for(p=0,d=10,b="9",w=0,l.length>1&&l[w]==="0"&&(l[w+1]==="x"||l[w+1]==="X"?(w+=2,d=16):"0"<=l[w+1]&&l[w+1]<="9"&&(w++,d=8,b="7")),s=w;w<l.length;){if("0"<=l[w]&&l[w]<=b)p=p*d+(e(l[w])-n)>>>0;else if(d===16)if("a"<=l[w]&&l[w]<="f")p=p*d+(10+e(l[w])-o)>>>0;else if("A"<=l[w]&&l[w]<="F")p=p*d+(10+e(l[w])-i)>>>0;else break;else break;if(p>4294967295)throw new Error("too large");w++}if(w===s)throw new Error("empty octet");return[p,w]},r=function(){function l(d,b){var w,p,s,c;if(typeof d!="string")throw new Error("Missing `net' parameter");if(b||(c=d.split("/",2),d=c[0],b=c[1]),b||(b=32),typeof b=="string"&&b.indexOf(".")>-1){try{this.maskLong=a(b)}catch(f){throw w=f,new Error("Invalid mask: "+b)}for(p=s=32;s>=0;p=--s)if(this.maskLong===4294967295<<32-p>>>0){this.bitmask=p;break}}else if(b||b===0)this.bitmask=parseInt(b,10),this.maskLong=0,this.bitmask>0&&(this.maskLong=4294967295<<32-this.bitmask>>>0);else throw new Error("Invalid mask: empty");try{this.netLong=(a(d)&this.maskLong)>>>0}catch(f){throw w=f,new Error("Invalid net address: "+d)}if(!(this.bitmask<=32))throw new Error("Invalid mask for ip4: "+b);this.size=Math.pow(2,32-this.bitmask),this.base=u(this.netLong),this.mask=u(this.maskLong),this.hostmask=u(~this.maskLong),this.first=this.bitmask<=30?u(this.netLong+1):this.base,this.last=this.bitmask<=30?u(this.netLong+this.size-2):u(this.netLong+this.size-1),this.broadcast=this.bitmask<=30?u(this.netLong+this.size-1):void 0}return l.prototype.contains=function(d){return typeof d=="string"&&(d.indexOf("/")>0||d.split(".").length!==4)&&(d=new l(d)),d instanceof l?this.contains(d.base)&&this.contains(d.broadcast||d.last):(a(d)&this.maskLong)>>>0===(this.netLong&this.maskLong)>>>0},l.prototype.next=function(d){return d==null&&(d=1),new l(u(this.netLong+this.size*d),this.mask)},l.prototype.forEach=function(d){var b,w,p;for(p=a(this.first),w=a(this.last),b=0;p<=w;)d(u(p),p,b),b++,p++},l.prototype.toString=function(){return this.base+"/"+this.bitmask},l}(),Rt.ip2long=a,Rt.long2ip=u,Rt.Netmask=r}).call(Rt)});var Cn=mr((Rn,ee)=>{(function(r){"use strict";let t="(0?\\d+|0x[a-f0-9]+)",e={fourOctet:new RegExp(`^${t}\\.${t}\\.${t}\\.${t}$`,"i"),threeOctet:new RegExp(`^${t}\\.${t}\\.${t}$`,"i"),twoOctet:new RegExp(`^${t}\\.${t}$`,"i"),longValue:new RegExp(`^${t}$`,"i")},n=new RegExp("^0[0-7]+$","i"),i=new RegExp("^0x[a-f0-9]+$","i"),o="%[0-9a-z]{1,}",a="(?:[0-9a-f]+::?)+",u={zoneIndex:new RegExp(o,"i"),native:new RegExp(`^(::)?(${a})?([0-9a-f]+)?(::)?(${o})?$`,"i"),deprecatedTransitional:new RegExp(`^(?:::)(${t}\\.${t}\\.${t}\\.${t}(${o})?)$`,"i"),transitional:new RegExp(`^((?:${a})|(?:::)(?:${a})?)${t}\\.${t}\\.${t}\\.${t}(${o})?$`,"i")};function l(s,c){if(s.indexOf("::")!==s.lastIndexOf("::"))return null;let f=0,h=-1,m=(s.match(u.zoneIndex)||[])[0],g,x;for(m&&(m=m.substring(1),s=s.replace(/%.+$/,""));(h=s.indexOf(":",h+1))>=0;)f++;if(s.substr(0,2)==="::"&&f--,s.substr(-2,2)==="::"&&f--,f>c)return null;for(x=c-f,g=":";x--;)g+="0:";return s=s.replace("::",g),s[0]===":"&&(s=s.slice(1)),s[s.length-1]===":"&&(s=s.slice(0,-1)),c=function(){let D=s.split(":"),T=[];for(let k=0;k<D.length;k++)T.push(parseInt(D[k],16));return T}(),{parts:c,zoneId:m}}function d(s,c,f,h){if(s.length!==c.length)throw new Error("ipaddr: cannot match CIDR for objects with different lengths");let m=0,g;for(;h>0;){if(g=f-h,g<0&&(g=0),s[m]>>g!==c[m]>>g)return!1;h-=f,m+=1}return!0}function b(s){if(i.test(s))return parseInt(s,16);if(s[0]==="0"&&!isNaN(parseInt(s[1],10))){if(n.test(s))return parseInt(s,8);throw new Error(`ipaddr: cannot parse ${s} as octal`)}return parseInt(s,10)}function w(s,c){for(;s.length<c;)s=`0${s}`;return s}let p={};p.IPv4=function(){function s(c){if(c.length!==4)throw new Error("ipaddr: ipv4 octet count should be 4");let f,h;for(f=0;f<c.length;f++)if(h=c[f],!(0<=h&&h<=255))throw new Error("ipaddr: ipv4 octet should fit in 8 bits");this.octets=c}return s.prototype.SpecialRanges={unspecified:[[new s([0,0,0,0]),8]],broadcast:[[new s([255,255,255,255]),32]],multicast:[[new s([224,0,0,0]),4]],linkLocal:[[new s([169,254,0,0]),16]],loopback:[[new s([127,0,0,0]),8]],carrierGradeNat:[[new s([100,64,0,0]),10]],private:[[new s([10,0,0,0]),8],[new s([172,16,0,0]),12],[new s([192,168,0,0]),16]],reserved:[[new s([192,0,0,0]),24],[new s([192,0,2,0]),24],[new s([192,88,99,0]),24],[new s([198,18,0,0]),15],[new s([198,51,100,0]),24],[new s([203,0,113,0]),24],[new s([240,0,0,0]),4]]},s.prototype.kind=function(){return"ipv4"},s.prototype.match=function(c,f){let h;if(f===void 0&&(h=c,c=h[0],f=h[1]),c.kind()!=="ipv4")throw new Error("ipaddr: cannot match ipv4 address with non-ipv4 one");return d(this.octets,c.octets,8,f)},s.prototype.prefixLengthFromSubnetMask=function(){let c=0,f=!1,h={0:8,128:7,192:6,224:5,240:4,248:3,252:2,254:1,255:0},m,g,x;for(m=3;m>=0;m-=1)if(g=this.octets[m],g in h){if(x=h[g],f&&x!==0)return null;x!==8&&(f=!0),c+=x}else return null;return 32-c},s.prototype.range=function(){return p.subnetMatch(this,this.SpecialRanges)},s.prototype.toByteArray=function(){return this.octets.slice(0)},s.prototype.toIPv4MappedAddress=function(){return p.IPv6.parse(`::ffff:${this.toString()}`)},s.prototype.toNormalizedString=function(){return this.toString()},s.prototype.toString=function(){return this.octets.join(".")},s}(),p.IPv4.broadcastAddressFromCIDR=function(s){try{let c=this.parseCIDR(s),f=c[0].toByteArray(),h=this.subnetMaskFromPrefixLength(c[1]).toByteArray(),m=[],g=0;for(;g<4;)m.push(parseInt(f[g],10)|parseInt(h[g],10)^255),g++;return new this(m)}catch{throw new Error("ipaddr: the address does not have IPv4 CIDR format")}},p.IPv4.isIPv4=function(s){return this.parser(s)!==null},p.IPv4.isValid=function(s){try{return new this(this.parser(s)),!0}catch{return!1}},p.IPv4.isValidFourPartDecimal=function(s){return!!(p.IPv4.isValid(s)&&s.match(/^(0|[1-9]\d*)(\.(0|[1-9]\d*)){3}$/))},p.IPv4.networkAddressFromCIDR=function(s){let c,f,h,m,g;try{for(c=this.parseCIDR(s),h=c[0].toByteArray(),g=this.subnetMaskFromPrefixLength(c[1]).toByteArray(),m=[],f=0;f<4;)m.push(parseInt(h[f],10)&parseInt(g[f],10)),f++;return new this(m)}catch{throw new Error("ipaddr: the address does not have IPv4 CIDR format")}},p.IPv4.parse=function(s){let c=this.parser(s);if(c===null)throw new Error("ipaddr: string is not formatted like an IPv4 Address");return new this(c)},p.IPv4.parseCIDR=function(s){let c;if(c=s.match(/^(.+)\/(\d+)$/)){let f=parseInt(c[2]);if(f>=0&&f<=32){let h=[this.parse(c[1]),f];return Object.defineProperty(h,"toString",{value:function(){return this.join("/")}}),h}}throw new Error("ipaddr: string is not formatted like an IPv4 CIDR range")},p.IPv4.parser=function(s){let c,f,h;if(c=s.match(e.fourOctet))return function(){let m=c.slice(1,6),g=[];for(let x=0;x<m.length;x++)f=m[x],g.push(b(f));return g}();if(c=s.match(e.longValue)){if(h=b(c[1]),h>4294967295||h<0)throw new Error("ipaddr: address outside defined range");return function(){let m=[],g;for(g=0;g<=24;g+=8)m.push(h>>g&255);return m}().reverse()}else return(c=s.match(e.twoOctet))?function(){let m=c.slice(1,4),g=[];if(h=b(m[1]),h>16777215||h<0)throw new Error("ipaddr: address outside defined range");return g.push(b(m[0])),g.push(h>>16&255),g.push(h>>8&255),g.push(h&255),g}():(c=s.match(e.threeOctet))?function(){let m=c.slice(1,5),g=[];if(h=b(m[2]),h>65535||h<0)throw new Error("ipaddr: address outside defined range");return g.push(b(m[0])),g.push(b(m[1])),g.push(h>>8&255),g.push(h&255),g}():null},p.IPv4.subnetMaskFromPrefixLength=function(s){if(s=parseInt(s),s<0||s>32)throw new Error("ipaddr: invalid IPv4 prefix length");let c=[0,0,0,0],f=0,h=Math.floor(s/8);for(;f<h;)c[f]=255,f++;return h<4&&(c[h]=Math.pow(2,s%8)-1<<8-s%8),new this(c)},p.IPv6=function(){function s(c,f){let h,m;if(c.length===16)for(this.parts=[],h=0;h<=14;h+=2)this.parts.push(c[h]<<8|c[h+1]);else if(c.length===8)this.parts=c;else throw new Error("ipaddr: ipv6 part count should be 8 or 16");for(h=0;h<this.parts.length;h++)if(m=this.parts[h],!(0<=m&&m<=65535))throw new Error("ipaddr: ipv6 part should fit in 16 bits");f&&(this.zoneId=f)}return s.prototype.SpecialRanges={unspecified:[new s([0,0,0,0,0,0,0,0]),128],linkLocal:[new s([65152,0,0,0,0,0,0,0]),10],multicast:[new s([65280,0,0,0,0,0,0,0]),8],loopback:[new s([0,0,0,0,0,0,0,1]),128],uniqueLocal:[new s([64512,0,0,0,0,0,0,0]),7],ipv4Mapped:[new s([0,0,0,0,0,65535,0,0]),96],rfc6145:[new s([0,0,0,0,65535,0,0,0]),96],rfc6052:[new s([100,65435,0,0,0,0,0,0]),96],"6to4":[new s([8194,0,0,0,0,0,0,0]),16],teredo:[new s([8193,0,0,0,0,0,0,0]),32],reserved:[[new s([8193,3512,0,0,0,0,0,0]),32]],benchmarking:[new s([8193,2,0,0,0,0,0,0]),48],amt:[new s([8193,3,0,0,0,0,0,0]),32],as112v6:[new s([8193,4,274,0,0,0,0,0]),48],deprecated:[new s([8193,16,0,0,0,0,0,0]),28],orchid2:[new s([8193,32,0,0,0,0,0,0]),28]},s.prototype.isIPv4MappedAddress=function(){return this.range()==="ipv4Mapped"},s.prototype.kind=function(){return"ipv6"},s.prototype.match=function(c,f){let h;if(f===void 0&&(h=c,c=h[0],f=h[1]),c.kind()!=="ipv6")throw new Error("ipaddr: cannot match ipv6 address with non-ipv6 one");return d(this.parts,c.parts,16,f)},s.prototype.prefixLengthFromSubnetMask=function(){let c=0,f=!1,h={0:16,32768:15,49152:14,57344:13,61440:12,63488:11,64512:10,65024:9,65280:8,65408:7,65472:6,65504:5,65520:4,65528:3,65532:2,65534:1,65535:0},m,g;for(let x=7;x>=0;x-=1)if(m=this.parts[x],m in h){if(g=h[m],f&&g!==0)return null;g!==16&&(f=!0),c+=g}else return null;return 128-c},s.prototype.range=function(){return p.subnetMatch(this,this.SpecialRanges)},s.prototype.toByteArray=function(){let c,f=[],h=this.parts;for(let m=0;m<h.length;m++)c=h[m],f.push(c>>8),f.push(c&255);return f},s.prototype.toFixedLengthString=function(){let c=function(){let h=[];for(let m=0;m<this.parts.length;m++)h.push(w(this.parts[m].toString(16),4));return h}.call(this).join(":"),f="";return this.zoneId&&(f=`%${this.zoneId}`),c+f},s.prototype.toIPv4Address=function(){if(!this.isIPv4MappedAddress())throw new Error("ipaddr: trying to convert a generic ipv6 address to ipv4");let c=this.parts.slice(-2),f=c[0],h=c[1];return new p.IPv4([f>>8,f&255,h>>8,h&255])},s.prototype.toNormalizedString=function(){let c=function(){let h=[];for(let m=0;m<this.parts.length;m++)h.push(this.parts[m].toString(16));return h}.call(this).join(":"),f="";return this.zoneId&&(f=`%${this.zoneId}`),c+f},s.prototype.toRFC5952String=function(){let c=/((^|:)(0(:|$)){2,})/g,f=this.toNormalizedString(),h=0,m=-1,g;for(;g=c.exec(f);)g[0].length>m&&(h=g.index,m=g[0].length);return m<0?f:`${f.substring(0,h)}::${f.substring(h+m)}`},s.prototype.toString=function(){return this.toRFC5952String()},s}(),p.IPv6.broadcastAddressFromCIDR=function(s){try{let c=this.parseCIDR(s),f=c[0].toByteArray(),h=this.subnetMaskFromPrefixLength(c[1]).toByteArray(),m=[],g=0;for(;g<16;)m.push(parseInt(f[g],10)|parseInt(h[g],10)^255),g++;return new this(m)}catch(c){throw new Error(`ipaddr: the address does not have IPv6 CIDR format (${c})`)}},p.IPv6.isIPv6=function(s){return this.parser(s)!==null},p.IPv6.isValid=function(s){if(typeof s=="string"&&s.indexOf(":")===-1)return!1;try{let c=this.parser(s);return new this(c.parts,c.zoneId),!0}catch{return!1}},p.IPv6.networkAddressFromCIDR=function(s){let c,f,h,m,g;try{for(c=this.parseCIDR(s),h=c[0].toByteArray(),g=this.subnetMaskFromPrefixLength(c[1]).toByteArray(),m=[],f=0;f<16;)m.push(parseInt(h[f],10)&parseInt(g[f],10)),f++;return new this(m)}catch(x){throw new Error(`ipaddr: the address does not have IPv6 CIDR format (${x})`)}},p.IPv6.parse=function(s){let c=this.parser(s);if(c.parts===null)throw new Error("ipaddr: string is not formatted like an IPv6 Address");return new this(c.parts,c.zoneId)},p.IPv6.parseCIDR=function(s){let c,f,h;if((f=s.match(/^(.+)\/(\d+)$/))&&(c=parseInt(f[2]),c>=0&&c<=128))return h=[this.parse(f[1]),c],Object.defineProperty(h,"toString",{value:function(){return this.join("/")}}),h;throw new Error("ipaddr: string is not formatted like an IPv6 CIDR range")},p.IPv6.parser=function(s){let c,f,h,m,g,x;if(h=s.match(u.deprecatedTransitional))return this.parser(`::ffff:${h[1]}`);if(u.native.test(s))return l(s,8);if((h=s.match(u.transitional))&&(x=h[6]||"",c=l(h[1].slice(0,-1)+x,6),c.parts)){for(g=[parseInt(h[2]),parseInt(h[3]),parseInt(h[4]),parseInt(h[5])],f=0;f<g.length;f++)if(m=g[f],!(0<=m&&m<=255))return null;return c.parts.push(g[0]<<8|g[1]),c.parts.push(g[2]<<8|g[3]),{parts:c.parts,zoneId:c.zoneId}}return null},p.IPv6.subnetMaskFromPrefixLength=function(s){if(s=parseInt(s),s<0||s>128)throw new Error("ipaddr: invalid IPv6 prefix length");let c=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],f=0,h=Math.floor(s/8);for(;f<h;)c[f]=255,f++;return h<16&&(c[h]=Math.pow(2,s%8)-1<<8-s%8),new this(c)},p.fromByteArray=function(s){let c=s.length;if(c===4)return new p.IPv4(s);if(c===16)return new p.IPv6(s);throw new Error("ipaddr: the binary input is neither an IPv6 nor IPv4 address")},p.isValid=function(s){return p.IPv6.isValid(s)||p.IPv4.isValid(s)},p.parse=function(s){if(p.IPv6.isValid(s))return p.IPv6.parse(s);if(p.IPv4.isValid(s))return p.IPv4.parse(s);throw new Error("ipaddr: the address has neither IPv6 nor IPv4 format")},p.parseCIDR=function(s){try{return p.IPv6.parseCIDR(s)}catch{try{return p.IPv4.parseCIDR(s)}catch{throw new Error("ipaddr: the address has neither IPv6 nor IPv4 CIDR format")}}},p.process=function(s){let c=this.parse(s);return c.kind()==="ipv6"&&c.isIPv4MappedAddress()?c.toIPv4Address():c},p.subnetMatch=function(s,c,f){let h,m,g,x;f==null&&(f="unicast");for(m in c)if(Object.prototype.hasOwnProperty.call(c,m)){for(g=c[m],g[0]&&!(g[0]instanceof Array)&&(g=[g]),h=0;h<g.length;h++)if(x=g[h],s.kind()===x[0].kind()&&s.match.apply(s,x))return m}return f},typeof ee<"u"&&ee.exports?ee.exports=p:r.ipaddr=p})(Rn)});var Ho={};$(Ho,{dcutr:()=>Ko,multicodec:()=>xt});var z=class extends Error{code;props;constructor(t,e,n){super(t),this.code=e,this.name=n?.name??"CodeError",this.props=n??{}}};var ot="ERR_INVALID_MESSAGE";var ce={};$(ce,{base58btc:()=>F,base58flickr:()=>Kn});var es=new Uint8Array(0);function br(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function 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 xr(r){return new TextEncoder().encode(r)}function yr(r){return new TextDecoder().decode(r)}function qn(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 i=0;i<r.length;i++){var o=r.charAt(i),a=o.charCodeAt(0);if(e[a]!==255)throw new TypeError(o+" is ambiguous");e[a]=i}var u=r.length,l=r.charAt(0),d=Math.log(u)/Math.log(256),b=Math.log(256)/Math.log(u);function w(c){if(c instanceof Uint8Array||(ArrayBuffer.isView(c)?c=new Uint8Array(c.buffer,c.byteOffset,c.byteLength):Array.isArray(c)&&(c=Uint8Array.from(c))),!(c instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(c.length===0)return"";for(var f=0,h=0,m=0,g=c.length;m!==g&&c[m]===0;)m++,f++;for(var x=(g-m)*b+1>>>0,D=new Uint8Array(x);m!==g;){for(var T=c[m],k=0,V=x-1;(T!==0||k<h)&&V!==-1;V--,k++)T+=256*D[V]>>>0,D[V]=T%u>>>0,T=T/u>>>0;if(T!==0)throw new Error("Non-zero carry");h=k,m++}for(var X=x-h;X!==x&&D[X]===0;)X++;for(var Ct=l.repeat(f);X<x;++X)Ct+=r.charAt(D[X]);return Ct}function p(c){if(typeof c!="string")throw new TypeError("Expected String");if(c.length===0)return new Uint8Array;var f=0;if(c[f]!==" "){for(var h=0,m=0;c[f]===l;)h++,f++;for(var g=(c.length-f)*d+1>>>0,x=new Uint8Array(g);c[f];){var D=e[c.charCodeAt(f)];if(D===255)return;for(var T=0,k=g-1;(D!==0||T<m)&&k!==-1;k--,T++)D+=u*x[k]>>>0,x[k]=D%256>>>0,D=D/256>>>0;if(D!==0)throw new Error("Non-zero carry");m=T,f++}if(c[f]!==" "){for(var V=g-m;V!==g&&x[V]===0;)V++;for(var X=new Uint8Array(h+(g-V)),Ct=h;V!==g;)X[Ct++]=x[V++];return X}}}function s(c){var f=p(c);if(f)return f;throw new Error(`Non-${t} character`)}return{encode:w,decodeUnsafe:p,decode:s}}var Xn=qn,Qn=Xn,vr=Qn;var ie=class{name;prefix;baseEncode;constructor(t,e,n){this.name=t,this.prefix=e,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},oe=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,e,n){if(this.name=t,this.prefix=e,e.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=e.codePointAt(0),this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return Ar(this,t)}},se=class{decoders;constructor(t){this.decoders=t}or(t){return Ar(this,t)}decode(t){let e=t[0],n=this.decoders[e];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Ar(r,t){return new se({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var ae=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,e,n,i){this.name=t,this.prefix=e,this.baseEncode=n,this.baseDecode=i,this.encoder=new ie(t,e,n),this.decoder=new oe(t,e,i)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function ut({name:r,prefix:t,encode:e,decode:n}){return new ae(r,t,e,n)}function Y({name:r,prefix:t,alphabet:e}){let{encode:n,decode:i}=vr(e,r);return ut({prefix:t,name:r,encode:n,decode:o=>Q(i(o))})}function Jn(r,t,e,n){let i={};for(let b=0;b<t.length;++b)i[t[b]]=b;let o=r.length;for(;r[o-1]==="=";)--o;let a=new Uint8Array(o*e/8|0),u=0,l=0,d=0;for(let b=0;b<o;++b){let w=i[r[b]];if(w===void 0)throw new SyntaxError(`Non-${n} character`);l=l<<e|w,u+=e,u>=8&&(u-=8,a[d++]=255&l>>u)}if(u>=e||255&l<<8-u)throw new SyntaxError("Unexpected end of data");return a}function Zn(r,t,e){let n=t[t.length-1]==="=",i=(1<<e)-1,o="",a=0,u=0;for(let l=0;l<r.length;++l)for(u=u<<8|r[l],a+=8;a>e;)a-=e,o+=t[i&u>>a];if(a!==0&&(o+=t[i&u<<e-a]),n)for(;o.length*e&7;)o+="=";return o}function v({name:r,prefix:t,bitsPerChar:e,alphabet:n}){return ut({prefix:t,name:r,encode(i){return Zn(i,n,e)},decode(i){return Jn(i,n,e,r)}})}var F=Y({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Kn=Y({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var ue={};$(ue,{base32:()=>J,base32hex:()=>ei,base32hexpad:()=>ni,base32hexpadupper:()=>ii,base32hexupper:()=>ri,base32pad:()=>Yn,base32padupper:()=>ti,base32upper:()=>Hn,base32z:()=>oi});var J=v({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Hn=v({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Yn=v({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),ti=v({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),ei=v({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),ri=v({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),ni=v({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),ii=v({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),oi=v({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var si=Pr,Er=128,ai=127,ci=~ai,ui=Math.pow(2,31);function Pr(r,t,e){t=t||[],e=e||0;for(var n=e;r>=ui;)t[e++]=r&255|Er,r/=128;for(;r&ci;)t[e++]=r&255|Er,r>>>=7;return t[e]=r|0,Pr.bytes=e-n+1,t}var hi=he,fi=128,Sr=127;function he(r,n){var e=0,n=n||0,i=0,o=n,a,u=r.length;do{if(o>=u)throw he.bytes=0,new RangeError("Could not decode varint");a=r[o++],e+=i<28?(a&Sr)<<i:(a&Sr)*Math.pow(2,i),i+=7}while(a>=fi);return he.bytes=o-n,e}var li=Math.pow(2,7),di=Math.pow(2,14),pi=Math.pow(2,21),mi=Math.pow(2,28),gi=Math.pow(2,35),wi=Math.pow(2,42),bi=Math.pow(2,49),xi=Math.pow(2,56),yi=Math.pow(2,63),Ii=function(r){return r<li?1:r<di?2:r<pi?3:r<mi?4:r<gi?5:r<wi?6:r<bi?7:r<xi?8:r<yi?9:10},vi={encode:si,decode:hi,encodingLength:Ii},Ai=vi,yt=Ai;function It(r,t=0){return[yt.decode(r,t),yt.decode.bytes]}function ht(r,t,e=0){return yt.encode(r,t,e),t}function ft(r){return yt.encodingLength(r)}function st(r,t){let e=t.byteLength,n=ft(r),i=n+ft(e),o=new Uint8Array(i+e);return ht(r,o,0),ht(e,o,n),o.set(t,i),new lt(r,e,t,o)}function $t(r){let t=Q(r),[e,n]=It(t),[i,o]=It(t.subarray(n)),a=t.subarray(n+o);if(a.byteLength!==i)throw new Error("Incorrect length");return new lt(e,i,a,t)}function Fr(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&br(r.bytes,e.bytes)}}var lt=class{code;size;digest;bytes;constructor(t,e,n,i){this.code=t,this.size=e,this.digest=n,this.bytes=i}};function Nr(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return Si(e,fe(r),t??F.encoder);default:return Pi(e,fe(r),t??J.encoder)}}var Lr=new WeakMap;function fe(r){let t=Lr.get(r);if(t==null){let e=new Map;return Lr.set(r,e),e}return t}var tt=class r{code;version;multihash;bytes;"/";constructor(t,e,n,i){this.code=e,this.version=t,this.multihash=n,this.bytes=i,this["/"]=i}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!==Fi)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&&Fr(t.multihash,n.multihash)}toString(t){return Nr(this,t)}toJSON(){return{"/":Nr(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let e=t;if(e instanceof r)return e;if(e["/"]!=null&&e["/"]===e.bytes||e.asCID===e){let{version:n,code:i,multihash:o,bytes:a}=e;return new r(n,i,o,a??Dr(n,i,o.bytes))}else if(e[Ni]===!0){let{version:n,multihash:i,code:o}=e,a=$t(i);return r.create(n,o,a)}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 i=Dr(t,e,n.bytes);return new r(t,e,n,i)}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,i=Q(t.subarray(n,n+e.multihashSize));if(i.byteLength!==e.multihashSize)throw new Error("Incorrect length");let o=i.subarray(e.multihashSize-e.digestSize),a=new lt(e.multihashCode,e.digestSize,o,i);return[e.version===0?r.createV0(a):r.createV1(e.codec,a),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[w,p]=It(t.subarray(e));return e+=p,w},i=n(),o=vt;if(i===18?(i=0,e=0):o=n(),i!==0&&i!==1)throw new RangeError(`Invalid CID version ${i}`);let a=e,u=n(),l=n(),d=e+l,b=d-a;return{version:i,codec:o,multihashCode:u,digestSize:l,multihashSize:b,size:d}}static parse(t,e){let[n,i]=Ei(t,e),o=r.decode(i);if(o.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return fe(o).set(n,t),o}};function Ei(r,t){switch(r[0]){case"Q":{let e=t??F;return[F.prefix,e.decode(`${F.prefix}${r}`)]}case F.prefix:{let e=t??F;return[F.prefix,e.decode(r)]}case J.prefix:{let e=t??J;return[J.prefix,e.decode(r)]}default:{if(t==null)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[r[0],t.decode(r)]}}}function Si(r,t,e){let{prefix:n}=e;if(n!==F.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let i=t.get(n);if(i==null){let o=e.encode(r).slice(1);return t.set(n,o),o}else return i}function Pi(r,t,e){let{prefix:n}=e,i=t.get(n);if(i==null){let o=e.encode(r);return t.set(n,o),o}else return i}var vt=112,Fi=18;function Dr(r,t,e){let n=ft(r),i=n+ft(t),o=new Uint8Array(i+e.byteLength);return ht(r,o,0),ht(t,o,n),o.set(e,i),o}var Ni=Symbol.for("@ipld/js-cid/CID");function kt(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}var le={};$(le,{base10:()=>Li});var Li=Y({prefix:"9",name:"base10",alphabet:"0123456789"});var de={};$(de,{base16:()=>Di,base16upper:()=>Ri});var Di=v({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Ri=v({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var pe={};$(pe,{base2:()=>Ci});var Ci=v({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var me={};$(me,{base256emoji:()=>Mi});var Rr=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}"),Ui=Rr.reduce((r,t,e)=>(r[e]=t,r),[]),Ti=Rr.reduce((r,t,e)=>(r[t.codePointAt(0)]=e,r),[]);function $i(r){return r.reduce((t,e)=>(t+=Ui[e],t),"")}function ki(r){let t=[];for(let e of r){let n=Ti[e.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${e}`);t.push(n)}return new Uint8Array(t)}var Mi=ut({prefix:"\u{1F680}",name:"base256emoji",encode:$i,decode:ki});var ge={};$(ge,{base36:()=>Bi,base36upper:()=>Oi});var Bi=Y({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Oi=Y({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var be={};$(be,{base64:()=>Vi,base64pad:()=>zi,base64url:()=>we,base64urlpad:()=>_i});var Vi=v({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),zi=v({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),we=v({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),_i=v({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var xe={};$(xe,{base8:()=>ji});var ji=v({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var ye={};$(ye,{identity:()=>Gi});var Gi=ut({prefix:"\0",name:"identity",encode:r=>yr(r),decode:r=>xr(r)});var Ps=new TextEncoder,Fs=new TextDecoder;var Ie={};$(Ie,{identity:()=>Ji});var Cr=0,Xi="identity",Ur=Q;function Qi(r){return st(Cr,Ur(r))}var Ji={code:Cr,name:Xi,encode:Ur,digest:Qi};var Ee={};$(Ee,{sha256:()=>Zi,sha512:()=>Ki});function Ae({name:r,code:t,encode:e}){return new ve(r,t,e)}var ve=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 $r(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var Zi=Ae({name:"sha2-256",code:18,encode:$r("SHA-256")}),Ki=Ae({name:"sha2-512",code:19,encode:$r("SHA-512")});var At={...ye,...pe,...xe,...le,...de,...ue,...ge,...ce,...be,...me},Vs={...Ee,...Ie};function et(r){return globalThis.Buffer!=null?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):r}function Z(r=0){return globalThis.Buffer?.alloc!=null?et(globalThis.Buffer.alloc(r)):new Uint8Array(r)}function R(r=0){return globalThis.Buffer?.allocUnsafe!=null?et(globalThis.Buffer.allocUnsafe(r)):new Uint8Array(r)}function Mr(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var kr=Mr("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Se=Mr("ascii","a",r=>{let t="a";for(let e=0;e<r.length;e++)t+=String.fromCharCode(r[e]);return t},r=>{r=r.substring(1);let t=R(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),Hi={utf8:kr,"utf-8":kr,hex:At.base16,latin1:Se,ascii:Se,binary:Se,...At},Mt=Hi;function C(r,t="utf8"){let e=Mt[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return(t==="utf8"||t==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?globalThis.Buffer.from(r.buffer,r.byteOffset,r.byteLength).toString("utf8"):e.encoder.encode(r).substring(1)}var Yi=Math.pow(2,7),to=Math.pow(2,14),eo=Math.pow(2,21),Pe=Math.pow(2,28),Fe=Math.pow(2,35),Ne=Math.pow(2,42),Le=Math.pow(2,49),y=128,N=127;function M(r){if(r<Yi)return 1;if(r<to)return 2;if(r<eo)return 3;if(r<Pe)return 4;if(r<Fe)return 5;if(r<Ne)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 ro(r,t,e=0){switch(M(r)){case 8:t[e++]=r&255|y,r/=128;case 7:t[e++]=r&255|y,r/=128;case 6:t[e++]=r&255|y,r/=128;case 5:t[e++]=r&255|y,r/=128;case 4:t[e++]=r&255|y,r>>>=7;case 3:t[e++]=r&255|y,r>>>=7;case 2:t[e++]=r&255|y,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function no(r,t,e=0){switch(M(r)){case 8:t.set(e++,r&255|y),r/=128;case 7:t.set(e++,r&255|y),r/=128;case 6:t.set(e++,r&255|y),r/=128;case 5:t.set(e++,r&255|y),r/=128;case 4:t.set(e++,r&255|y),r>>>=7;case 3:t.set(e++,r&255|y),r>>>=7;case 2:t.set(e++,r&255|y),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function io(r,t){let e=r[t],n=0;if(n+=e&N,e<y||(e=r[t+1],n+=(e&N)<<7,e<y)||(e=r[t+2],n+=(e&N)<<14,e<y)||(e=r[t+3],n+=(e&N)<<21,e<y)||(e=r[t+4],n+=(e&N)*Pe,e<y)||(e=r[t+5],n+=(e&N)*Fe,e<y)||(e=r[t+6],n+=(e&N)*Ne,e<y)||(e=r[t+7],n+=(e&N)*Le,e<y))return n;throw new RangeError("Could not decode varint")}function oo(r,t){let e=r.get(t),n=0;if(n+=e&N,e<y||(e=r.get(t+1),n+=(e&N)<<7,e<y)||(e=r.get(t+2),n+=(e&N)<<14,e<y)||(e=r.get(t+3),n+=(e&N)<<21,e<y)||(e=r.get(t+4),n+=(e&N)*Pe,e<y)||(e=r.get(t+5),n+=(e&N)*Fe,e<y)||(e=r.get(t+6),n+=(e&N)*Ne,e<y)||(e=r.get(t+7),n+=(e&N)*Le,e<y))return n;throw new RangeError("Could not decode varint")}function rt(r,t,e=0){return t==null&&(t=R(M(r))),t instanceof Uint8Array?ro(r,t,e):no(r,t,e)}function K(r,t=0){return r instanceof Uint8Array?io(r,t):oo(r,t)}function B(r,t){if(globalThis.Buffer!=null)return et(globalThis.Buffer.concat(r,t));t==null&&(t=r.reduce((i,o)=>i+o.length,0));let e=R(t),n=0;for(let i of r)e.set(i,n),n+=i.length;return et(e)}var Bt=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,i){return this.readAtomically(()=>{let o=0,a=0,u=this.peekChar();if(u===void 0)return;let l=u==="0",d=2**(8*i)-1;for(;;){let b=this.readAtomically(()=>{let w=this.readChar();if(w===void 0)return;let p=Number.parseInt(w,t);if(!Number.isNaN(p))return p});if(b===void 0)break;if(o*=t,o+=b,o>d||(a+=1,e!==void 0&&a>e))return}if(a!==0)return!n&&l&&a>1?void 0:o})}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 i=n*2;if(n<e.length-3){let a=this.readSeparator(":",n,()=>this.readIPv4Addr());if(a!==void 0)return e[i]=a[0],e[i+1]=a[1],e[i+2]=a[2],e[i+3]=a[3],[i+4,!0]}let o=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(o===void 0)return[i,!1];e[i]=o>>8,e[i+1]=o&255}return[e.length,!1]};return this.readAtomically(()=>{let e=new Uint8Array(16),[n,i]=t(e);if(n===16)return e;if(i||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let o=new Uint8Array(14),a=16-(n+2),[u]=t(o.subarray(0,a));return e.set(o.subarray(0,u),16-u),e})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var Br=45,so=15,pt=new Bt;function Re(r){if(!(r.length>so))return pt.new(r).parseWith(()=>pt.readIPv4Addr())}function Ce(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>Br))return pt.new(r).parseWith(()=>pt.readIPv6Addr())}function Ot(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>Br))return pt.new(r).parseWith(()=>pt.readIPAddr())}var ua=parseInt("0xFFFF",16),ha=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function Et(r,t="utf8"){let e=Mt[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return(t==="utf8"||t==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?et(globalThis.Buffer.from(r,"utf-8")):e.decoder.decode(`${e.prefix}${r}`)}function Vt(r){return!!Re(r)}function zt(r){return!!Ce(r)}function mt(r){return!!Ot(r)}var zr=Vt,fo=zt,Ue=function(r){let t=0;if(r=r.toString().trim(),zr(r)){let e=new Uint8Array(t+4);return r.split(/\./g).forEach(n=>{e[t++]=parseInt(n,10)&255}),e}if(fo(r)){let e=r.split(":",8),n;for(n=0;n<e.length;n++){let o=zr(e[n]),a;o&&(a=Ue(e[n]),e[n]=C(a.slice(0,2),"base16")),a!=null&&++n<8&&e.splice(n,0,C(a.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 o=[n,1];for(n=9-e.length;n>0;n--)o.push("0");e.splice.apply(e,o)}let i=new Uint8Array(t+16);for(n=0;n<e.length;n++){let o=parseInt(e[n],16);i[t++]=o>>8&255,i[t++]=o&255}return i}throw new Error("invalid ip address")},_r=function(r,t=0,e){t=~~t,e=e??r.length-t;let n=new DataView(r.buffer);if(e===4){let i=[];for(let o=0;o<e;o++)i.push(r[t+o]);return i.join(".")}if(e===16){let i=[];for(let o=0;o<e;o+=2)i.push(n.getUint16(t+o).toString(16));return i.join(":").replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}return""};var gt={},Te={},po=[[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"],[777,-1,"memory"]];po.forEach(r=>{let t=mo(...r);Te[t.code]=t,gt[t.name]=t});function mo(r,t,e,n,i){return{code:r,size:t,name:e,resolvable:!!n,path:!!i}}function I(r){if(typeof r=="number"){if(Te[r]!=null)return Te[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(gt[r]!=null)return gt[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var Za=I("ip4"),Ka=I("ip6"),Ha=I("ipcidr");function ke(r,t){switch(I(r).code){case 4:case 41:return wo(t);case 42:return Wr(t);case 6:case 273:case 33:case 132:return Xr(t).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return Wr(t);case 421:return Io(t);case 444:return qr(t);case 445:return qr(t);case 466:return yo(t);default:return C(t,"base16")}}function Me(r,t){switch(I(r).code){case 4:return jr(t);case 41:return jr(t);case 42:return Gr(t);case 6:case 273:case 33:case 132:return Be(parseInt(t,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return Gr(t);case 421:return bo(t);case 444:return vo(t);case 445:return Ao(t);case 466:return xo(t);default:return Et(t,"base16")}}var $e=Object.values(At).map(r=>r.decoder),go=function(){let r=$e[0].or($e[1]);return $e.slice(2).forEach(t=>r=r.or(t)),r}();function jr(r){if(!mt(r))throw new Error("invalid ip address");return Ue(r)}function wo(r){let t=_r(r,0,r.length);if(t==null)throw new Error("ipBuff is required");if(!mt(t))throw new Error("invalid ip address");return t}function Be(r){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,r),new Uint8Array(t)}function Xr(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function Gr(r){let t=Et(r),e=Uint8Array.from(rt(t.length));return B([e,t],e.length+t.length)}function Wr(r){let t=K(r);if(r=r.slice(M(t)),r.length!==t)throw new Error("inconsistent lengths");return C(r)}function bo(r){let t;r[0]==="Q"||r[0]==="1"?t=$t(F.decode(`z${r}`)).bytes:t=tt.parse(r).multihash.bytes;let e=Uint8Array.from(rt(t.length));return B([e,t],e.length+t.length)}function xo(r){let t=go.decode(r),e=Uint8Array.from(rt(t.length));return B([e,t],e.length+t.length)}function yo(r){let t=K(r),e=r.slice(M(t));if(e.length!==t)throw new Error("inconsistent lengths");return"u"+C(e,"base64url")}function Io(r){let t=K(r),e=r.slice(M(t));if(e.length!==t)throw new Error("inconsistent lengths");return C(e,"base58btc")}function vo(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=J.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 i=Be(n);return B([e,i],e.length+i.length)}function Ao(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=J.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 i=Be(n);return B([e,i],e.length+i.length)}function qr(r){let t=r.slice(0,r.length-2),e=r.slice(r.length-2),n=C(t,"base32"),i=Xr(e);return`${n}:${i}`}function Qr(r){r=Oe(r);let t=[],e=[],n=null,i=r.split("/").slice(1);if(i.length===1&&i[0]==="")return{bytes:new Uint8Array,string:"/",tuples:[],stringTuples:[],path:null};for(let o=0;o<i.length;o++){let a=i[o],u=I(a);if(u.size===0){t.push([u.code]),e.push([u.code]);continue}if(o++,o>=i.length)throw Zr("invalid address: "+r);if(u.path===!0){n=Oe(i.slice(o).join("/")),t.push([u.code,Me(u.code,n)]),e.push([u.code,n]);break}let l=Me(u.code,i[o]);t.push([u.code,l]),e.push([u.code,ke(u.code,l)])}return{string:Jr(e),bytes:ze(t),tuples:t,stringTuples:e,path:n}}function Ve(r){let t=[],e=[],n=null,i=0;for(;i<r.length;){let o=K(r,i),a=M(o),u=I(o),l=Eo(u,r.slice(i+a));if(l===0){t.push([o]),e.push([o]),i+=a;continue}let d=r.slice(i+a,i+a+l);if(i+=l+a,i>r.length)throw Zr("Invalid address Uint8Array: "+C(r,"base16"));t.push([o,d]);let b=ke(o,d);if(e.push([o,b]),u.path===!0){n=b;break}}return{bytes:Uint8Array.from(r),string:Jr(e),tuples:t,stringTuples:e,path:n}}function Jr(r){let t=[];return r.map(e=>{let n=I(e[0]);return t.push(n.name),e.length>1&&e[1]!=null&&t.push(e[1]),null}),Oe(t.join("/"))}function ze(r){return B(r.map(t=>{let e=I(t[0]),n=Uint8Array.from(rt(e.code));return t.length>1&&t[1]!=null&&(n=B([n,t[1]])),n}))}function Eo(r,t){if(r.size>0)return r.size/8;if(r.size===0)return 0;{let e=K(t instanceof Uint8Array?t:Uint8Array.from(t));return e+M(e)}}function Oe(r){return"/"+r.trim().split("/").filter(t=>t).join("/")}function Zr(r){return new Error("Error parsing address: "+r)}var So=Symbol.for("nodejs.util.inspect.custom"),_e=Symbol.for("@multiformats/js-multiaddr/multiaddr"),Po=[I("dns").code,I("dns4").code,I("dns6").code,I("dnsaddr").code],_t=class r{bytes;#e;#t;#r;#n;[_e]=!0;constructor(t){t==null&&(t="");let e;if(t instanceof Uint8Array)e=Ve(t);else if(typeof t=="string"){if(t.length>0&&t.charAt(0)!=="/")throw new Error(`multiaddr "${t}" must start with a "/"`);e=Qr(t)}else if(Hr(t))e=Ve(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,i,o="",a=I("tcp"),u=I("udp"),l=I("ip4"),d=I("ip6"),b=I("dns6"),w=I("ip6zone");for(let[s,c]of this.stringTuples())s===w.code&&(o=`%${c??""}`),Po.includes(s)&&(e=a.name,i=443,n=`${c??""}${o}`,t=s===b.code?6:4),(s===a.code||s===u.code)&&(e=I(s).name,i=parseInt(c??"")),(s===l.code||s===d.code)&&(e=I(s).name,n=`${c??""}${o}`,t=s===d.code?6:4);if(t==null||e==null||n==null||i==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:i}}protos(){return this.#t.map(([t])=>Object.assign({},I(t)))}protoCodes(){return this.#t.map(([t])=>t)}protoNames(){return this.#t.map(([t])=>I(t).name)}tuples(){return this.#t}stringTuples(){return this.#r}encapsulate(t){return t=new r(t),new r(this.toString()+t.toString())}decapsulate(t){let e=t.toString(),n=this.toString(),i=n.lastIndexOf(e);if(i<0)throw new Error(`Address ${this.toString()} does not contain subaddress: ${t.toString()}`);return new r(n.slice(0,i))}decapsulateCode(t){let e=this.tuples();for(let n=e.length-1;n>=0;n--)if(e[n][0]===t)return new r(ze(e.slice(0,n)));return this}getPeerId(){try{let t=[];this.stringTuples().forEach(([n,i])=>{n===gt.p2p.code&&t.push([n,i]),n===gt["p2p-circuit"].code&&(t=[])});let e=t.pop();if(e?.[1]!=null){let n=e[1];return n[0]==="Q"||n[0]==="1"?C(F.decode(`z${n}`),"base58btc"):C(tt.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){return this.#n}equals(t){return kt(this.bytes,t.bytes)}async resolve(t){let e=this.protos().find(o=>o.resolvable);if(e==null)return[this];let n=Kr.get(e.name);if(n==null)throw new z(`no available resolver for ${e.name}`,"ERR_NO_AVAILABLE_RESOLVER");return(await n(this,t)).map(o=>new r(o))}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)}[So](){return`Multiaddr(${this.#e})`}};var Kr=new Map;function Hr(r){return!!r?.[_e]}function je(r){return new _t(r)}var Yr=()=>{let r=new Error("Delay aborted");return r.name="AbortError",r},Fo=new WeakMap;function No({clearTimeout:r,setTimeout:t}={}){return(e,{value:n,signal:i}={})=>{if(i?.aborted)return Promise.reject(Yr());let o,a,u,l=r??clearTimeout,d=()=>{l(o),u(Yr())},b=()=>{i&&i.removeEventListener("abort",d)},w=new Promise((p,s)=>{a=()=>{b(),p(n)},u=s,o=(t??setTimeout)(a,e)});return i&&i.addEventListener("abort",d,{once:!0}),Fo.set(w,()=>{l(o),o=null,a()}),w}}var Lo=No(),tn=Lo;var rn=Symbol.for("@achingbrain/uint8arraylist");function en(r,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let e=0;for(let n of r){let i=e+n.byteLength;if(t<i)return{buf:n,index:t-e};e=i}throw new RangeError("index is out of bounds")}function jt(r){return!!r?.[rn]}var H=class r{bufs;length;[rn]=!0;constructor(...t){this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let e=0;for(let n of t)if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.push(n);else if(jt(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(jt(n))e+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}get(t){let e=en(this.bufs,t);return e.buf[e.index]}set(t,e){let n=en(this.bufs,t);n.buf[n.index]=e}write(t,e=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(e+n,t[n]);else if(jt(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:i}=this._subList(t,e);return B(n,i)}subarray(t,e){let{bufs:n,length:i}=this._subList(t,e);return n.length===1?n[0]:B(n,i)}sublist(t,e){let{bufs:n,length:i}=this._subList(t,e),o=new r;return o.length=i,o.bufs=[...n],o}_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=[],i=0;for(let o=0;o<this.bufs.length;o++){let a=this.bufs[o],u=i,l=u+a.byteLength;if(i=l,t>=l)continue;let d=t>=u&&t<l,b=e>u&&e<=l;if(d&&b){if(t===u&&e===l){n.push(a);break}let w=t-u;n.push(a.subarray(w,w+(e-t)));break}if(d){if(t===0){n.push(a);continue}n.push(a.subarray(t-u));continue}if(b){if(e===l){n.push(a);break}n.push(a.subarray(0,e-u));break}n.push(a)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!jt(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 i=n.byteLength;if(i===0)throw new TypeError("search must be at least 1 byte long");let o=256,a=new Int32Array(o);for(let w=0;w<o;w++)a[w]=-1;for(let w=0;w<i;w++)a[n[w]]=w;let u=a,l=this.byteLength-n.byteLength,d=n.byteLength-1,b;for(let w=e;w<=l;w+=b){b=0;for(let p=d;p>=0;p--){let s=this.get(w+p);if(n[p]!==s){b=Math.max(1,p-u[s]);break}}if(b===0)return w}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=R(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 i=Z(2);new DataView(i.buffer,i.byteOffset,i.byteLength).setInt16(0,e,n),this.write(i,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 i=Z(4);new DataView(i.buffer,i.byteOffset,i.byteLength).setInt32(0,e,n),this.write(i,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 i=Z(8);new DataView(i.buffer,i.byteOffset,i.byteLength).setBigInt64(0,e,n),this.write(i,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=R(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 i=Z(2);new DataView(i.buffer,i.byteOffset,i.byteLength).setUint16(0,e,n),this.write(i,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 i=Z(4);new DataView(i.buffer,i.byteOffset,i.byteLength).setUint32(0,e,n),this.write(i,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 i=Z(8);new DataView(i.buffer,i.byteOffset,i.byteLength).setBigUint64(0,e,n),this.write(i,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 i=Z(4);new DataView(i.buffer,i.byteOffset,i.byteLength).setFloat32(0,e,n),this.write(i,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 i=Z(8);new DataView(i.buffer,i.byteOffset,i.byteLength).setFloat64(0,e,n),this.write(i,t)}equals(t){if(t==null||!(t instanceof r)||t.bufs.length!==this.bufs.length)return!1;for(let e=0;e<this.bufs.length;e++)if(!kt(this.bufs[e],t.bufs[e]))return!1;return!0}static fromUint8Arrays(t,e){let n=new r;return n.bufs=t,e==null&&(e=t.reduce((i,o)=>i+o.byteLength,0)),n.length=e,n}};function wt(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var Gt=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.name="AbortError",this.code=e??"ABORT_ERR"}};async function nn(r,t,e){if(t==null)return r;if(t.aborted)return Promise.reject(new Gt(e?.errorMessage,e?.errorCode));let n,i=new Gt(e?.errorMessage,e?.errorCode);try{return await Promise.race([r,new Promise((o,a)=>{n=()=>{a(i)},t.addEventListener("abort",n)})])}finally{n!=null&&t.removeEventListener("abort",n)}}var Ge=class{needNext;haveNext;ended;nextResult;constructor(){this.ended=!1,this.needNext=wt(),this.haveNext=wt()}[Symbol.asyncIterator](){return this}async next(){if(this.nextResult==null&&await this.haveNext.promise,this.nextResult==null)throw new Error("Have next but next was undefined");let t=this.nextResult;return this.nextResult=void 0,this.needNext.resolve(),this.needNext=wt(),t}async throw(t){return this.ended=!0,t!=null&&this.haveNext.reject(t),{done:!0,value:void 0}}async return(){let t={done:!0,value:void 0};return await this._push(void 0),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 new Error("Cannot push value onto an ended pushable");this.nextResult!=null&&await this.needNext.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 nn(this.needNext.promise,e?.signal,e)}};function on(){return new Ge}var Wt=class extends Error{code;constructor(t,e){super(t),this.code=e}},We=class extends Wt{type;constructor(t){super(t,"ABORT_ERR"),this.type="aborted"}};function sn(r,t){let e=on();r.sink(e).catch(async a=>{await e.end(a)}),r.sink=async a=>{for await(let u of a)await e.push(u);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 i=new H;return{read:async(a,u)=>{u?.signal?.throwIfAborted();let l,d=new Promise((b,w)=>{l=()=>{w(new We("Read aborted"))},u?.signal?.addEventListener("abort",l)});try{if(a==null){let{done:w,value:p}=await Promise.race([n.next(),d]);return w===!0?new H:p}for(;i.byteLength<a;){let{value:w,done:p}=await Promise.race([n.next(),d]);if(p===!0)throw new Wt("unexpected end of input","ERR_UNEXPECTED_EOF");i.append(w)}let b=i.sublist(0,a);return i.consume(a),b}finally{l!=null&&u?.signal?.removeEventListener("abort",l)}},write:async(a,u)=>{u?.signal?.throwIfAborted(),a instanceof Uint8Array?await e.push(a,u):await e.push(a.subarray(),u)},unwrap:()=>{if(i.byteLength>0){let a=r.source;r.source=async function*(){t?.yieldBytes===!1?yield i:yield*i,yield*a}()}return r}}}var qt=class extends Error{code;constructor(t,e){super(t),this.code=e}};function an(r,t={}){let e=sn(r,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=M(t.maxDataLength));let n=t?.lengthDecoder??K,i=t?.lengthEncoder??rt;return{read:async a=>{let u=-1,l=new H;for(;;){l.append(await e.read(1,a));try{u=n(l)}catch(d){if(d instanceof RangeError)continue;throw d}if(t?.maxLengthLength!=null&&l.byteLength>t.maxLengthLength)throw new qt("message length length too long","ERR_MSG_LENGTH_TOO_LONG");if(u>-1)break}if(t?.maxDataLength!=null&&u>t.maxDataLength)throw new qt("message length too long","ERR_MSG_DATA_TOO_LONG");return e.read(u,a)},write:async(a,u)=>{await e.write(new H(i(a.byteLength),a),u)},writeV:async(a,u)=>{let l=new H(...a.flatMap(d=>[i(d.byteLength),d]));await e.write(l,u)},unwrap:()=>e.unwrap()}}function qe(r,t){let e=an(r,t),n={read:async(i,o)=>{let a=await e.read(o);return i.decode(a)},write:async(i,o,a)=>{await e.write(o.encode(i),a)},writeV:async(i,o,a)=>{await e.writeV(i.map(u=>o.encode(u)),a)},pb:i=>({read:async o=>n.read(i,o),write:async(o,a)=>n.write(o,i,a),writeV:async(o,a)=>n.writeV(o,i,a),unwrap:()=>n}),unwrap:()=>e.unwrap()};return n}var Xe=new Float32Array([-0]),nt=new Uint8Array(Xe.buffer);function cn(r,t,e){Xe[0]=r,t[e]=nt[0],t[e+1]=nt[1],t[e+2]=nt[2],t[e+3]=nt[3]}function un(r,t){return nt[0]=r[t],nt[1]=r[t+1],nt[2]=r[t+2],nt[3]=r[t+3],Xe[0]}var Qe=new Float64Array([-0]),L=new Uint8Array(Qe.buffer);function hn(r,t,e){Qe[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 fn(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],Qe[0]}var Do=BigInt(Number.MAX_SAFE_INTEGER),Ro=BigInt(Number.MIN_SAFE_INTEGER),U=class r{lo;hi;constructor(t,e){this.lo=t|0,this.hi=e|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(e+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(BigInt(e)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,e=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?e===0?t<16384?t<128?1:2:t<2097152?3:4:e<16384?e<128?5:6:e<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return at;if(t<Do&&t>Ro)return this.fromNumber(Number(t));let e=t<0n;e&&(t=-t);let n=t>>32n,i=t-(n<<32n);return e&&(n=~n|0n,i=~i|0n,++i>ln&&(i=0n,++n>ln&&(n=0n))),new r(Number(i),Number(n))}static fromNumber(t){if(t===0)return at;let e=t<0;e&&(t=-t);let n=t>>>0,i=(t-n)/4294967296>>>0;return e&&(i=~i>>>0,n=~n>>>0,++n>4294967295&&(n=0,++i>4294967295&&(i=0))),new r(n,i)}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):at}},at=new U(0,0);at.toBigInt=function(){return 0n};at.zzEncode=at.zzDecode=function(){return this};at.length=function(){return 1};var ln=4294967296n;function dn(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 pn(r,t,e){if(e-t<1)return"";let i,o=[],a=0,u;for(;t<e;)u=r[t++],u<128?o[a++]=u:u>191&&u<224?o[a++]=(u&31)<<6|r[t++]&63:u>239&&u<365?(u=((u&7)<<18|(r[t++]&63)<<12|(r[t++]&63)<<6|r[t++]&63)-65536,o[a++]=55296+(u>>10),o[a++]=56320+(u&1023)):o[a++]=(u&15)<<12|(r[t++]&63)<<6|r[t++]&63,a>8191&&((i??(i=[])).push(String.fromCharCode.apply(String,o)),a=0);return i!=null?(a>0&&i.push(String.fromCharCode.apply(String,o.slice(0,a))),i.join("")):String.fromCharCode.apply(String,o.slice(0,a))}function Je(r,t,e){let n=e,i,o;for(let a=0;a<r.length;++a)i=r.charCodeAt(a),i<128?t[e++]=i:i<2048?(t[e++]=i>>6|192,t[e++]=i&63|128):(i&64512)===55296&&((o=r.charCodeAt(a+1))&64512)===56320?(i=65536+((i&1023)<<10)+(o&1023),++a,t[e++]=i>>18|240,t[e++]=i>>12&63|128,t[e++]=i>>6&63|128,t[e++]=i&63|128):(t[e++]=i>>12|224,t[e++]=i>>6&63|128,t[e++]=i&63|128);return e-n}function _(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function Xt(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var Ze=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=t,this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,_(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 _(this,4);return Xt(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw _(this,4);return Xt(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw _(this,4);let t=un(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw _(this,4);let t=fn(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 _(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return pn(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw _(this,t);this.pos+=t}else do if(this.pos>=this.len)throw _(this);while(this.buf[this.pos++]&128);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new U(0,0),e=0;if(this.len-this.pos>4){for(;e<4;++e)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;e=0}else{for(;e<3;++e){if(this.pos>=this.len)throw _(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 _(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 _(this,8);let t=Xt(this.buf,this.pos+=4),e=Xt(this.buf,this.pos+=4);return new U(t,e)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){return this.readLongVarint().toNumber(!0)}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function Ke(r){return new Ze(r instanceof Uint8Array?r:r.subarray())}function He(r,t){let e=Ke(r);return t.decode(e)}function Ye(r){let t=r??8192,e=t>>>1,n,i=t;return function(a){if(a<1||a>e)return R(a);i+a>t&&(n=R(t),i=0);let u=n.subarray(i,i+=a);return i&7&&(i=(i|7)+1),u}}var ct=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function tr(){}var rr=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Co=Ye();function Uo(r){return globalThis.Buffer!=null?R(r):Co(r)}var Ft=class{len;head;tail;states;constructor(){this.len=0,this.head=new ct(tr,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new ct(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new nr((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(St,10,U.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=U.fromBigInt(t);return this._push(St,e.length(),e)}uint64Number(t){let e=U.fromNumber(t);return this._push(St,e.length(),e)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let e=U.fromBigInt(t).zzEncode();return this._push(St,e.length(),e)}sint64Number(t){let e=U.fromNumber(t).zzEncode();return this._push(St,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(er,1,t?1:0)}fixed32(t){return this._push(Pt,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=U.fromBigInt(t);return this._push(Pt,4,e.lo)._push(Pt,4,e.hi)}fixed64Number(t){let e=U.fromNumber(t);return this._push(Pt,4,e.lo)._push(Pt,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(cn,4,t)}double(t){return this._push(hn,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(er,1,0):this.uint32(e)._push($o,e,t)}string(t){let e=dn(t);return e!==0?this.uint32(e)._push(Je,e,t):this._push(er,1,0)}fork(){return this.states=new rr(this),this.head=this.tail=new ct(tr,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 ct(tr,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=Uo(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function er(r,t,e){t[e]=r&255}function To(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var nr=class extends ct{next;constructor(t,e){super(To,t,e),this.next=void 0}};function St(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 Pt(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 $o(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(Ft.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(ko,t,r),this},Ft.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(Mo,t,r),this});function ko(r,t,e){t.set(r,e)}function Mo(r,t,e){r.length<40?Je(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(Et(r),e)}function ir(){return new Ft}function or(r,t){let e=ir();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 Qt(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function sr(r){function t(i){if(r[i.toString()]==null)throw new Error("Invalid enum value");return r[i]}let e=function(o,a){let u=t(o);a.int32(u)},n=function(o){let a=o.int32();return t(a)};return Qt("enum",bt.VARINT,e,n)}function ar(r,t){return Qt("message",bt.LENGTH_DELIMITED,r,t)}var j;(function(r){let t;(function(i){i.UNUSED="UNUSED",i.CONNECT="CONNECT",i.SYNC="SYNC"})(t=r.Type||(r.Type={}));let e;(function(i){i[i.UNUSED=0]="UNUSED",i[i.CONNECT=100]="CONNECT",i[i.SYNC=300]="SYNC"})(e||(e={})),function(i){i.codec=()=>sr(e)}(t=r.Type||(r.Type={}));let n;r.codec=()=>(n==null&&(n=ar((i,o,a={})=>{if(a.lengthDelimited!==!1&&o.fork(),i.type!=null&&(o.uint32(8),r.Type.codec().encode(i.type,o)),i.observedAddresses!=null)for(let u of i.observedAddresses)o.uint32(18),o.bytes(u);a.lengthDelimited!==!1&&o.ldelim()},(i,o)=>{let a={observedAddresses:[]},u=o==null?i.len:i.pos+o;for(;i.pos<u;){let l=i.uint32();switch(l>>>3){case 1:a.type=r.Type.codec().decode(i);break;case 2:a.observedAddresses.push(i.bytes());break;default:i.skipType(l&7);break}}return a})),n),r.encode=i=>or(i,r.codec()),r.decode=i=>He(i,r.codec())})(j||(j={}));var Bo=r=>r.toString().split("/").slice(1),Nt=r=>({match:t=>t.length<1?!1:r(t[0])?t.slice(1):!1,pattern:"fn"}),A=r=>({match:t=>Nt(e=>e===r).match(t),pattern:r}),Kt=()=>({match:r=>Nt(t=>typeof t=="string").match(r),pattern:"{string}"}),gn=()=>({match:r=>Nt(t=>!isNaN(parseInt(t))).match(r),pattern:"{number}"}),O=()=>({match:r=>{if(r.length<2||r[0]!=="p2p"&&r[0]!=="ipfs")return!1;if(r[1].startsWith("Q")||r[1].startsWith("1"))try{F.decode(`z${r[1]}`)}catch{return!1}else return!1;return r.slice(2)},pattern:"/p2p/{peerid}"}),Jt=()=>({match:r=>{if(r.length<2||r[0]!=="certhash")return!1;try{we.decode(r[1])}catch{return!1}return r.slice(2)},pattern:"/certhash/{certhash}"}),W=r=>({match:t=>{let e=r.match(t);return e===!1?t:e},pattern:`optional(${r.pattern})`}),q=(...r)=>({match:t=>{let e;for(let n of r){let i=n.match(t);i!==!1&&(e==null||i.length<e.length)&&(e=i)}return e??!1},pattern:`or(${r.map(t=>t.pattern).join(", ")})`}),E=(...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 P(...r){function t(i){let o=Bo(i);for(let a of r){let u=a.match(o);if(u===!1)return!1;o=u}return o}function e(i){return t(i)!==!1}function n(i){let o=t(i);return o===!1?!1:o.length===0}return{matches:e,exactMatch:n}}var ur=E(A("dns4"),Kt()),hr=E(A("dns6"),Kt()),fr=E(A("dnsaddr"),Kt()),wn=E(A("dns"),Kt()),Au=P(ur),Eu=P(hr),Su=P(fr),bn=P(q(wn,fr,ur,hr)),xn=E(A("ip4"),Nt(Vt)),yn=E(A("ip6"),Nt(zt)),In=q(xn,yn),Lt=q(In,wn,ur,hr,fr),Pu=P(Lt),Fu=P(xn),Nu=P(yn),vn=P(In),Ht=E(Lt,A("tcp"),gn()),Dt=E(Lt,A("udp"),gn()),Oo=q(Ht,Dt),Lu=P(Ht),Du=P(Dt),lr=E(Dt,A("quic")),Yt=E(Dt,A("quic-v1")),Vo=q(lr,Yt),Ru=P(lr),Cu=P(Yt),cr=q(Lt,Ht,Dt,lr,Yt),An=q(E(cr,A("ws"),W(O()))),Uu=P(An),En=q(E(cr,A("wss"),W(O())),E(cr,A("tls"),A("ws"),W(O()))),Tu=P(En),Sn=E(Oo,A("webrtc-direct"),Jt(),W(Jt()),W(O())),$u=P(Sn),Pn=E(Yt,A("webtransport"),Jt(),Jt(),W(O())),ku=P(Pn),Zt=q(An,En,E(Ht,W(O())),E(Vo,W(O())),E(Lt,W(O())),Sn,Pn,O()),Mu=P(Zt),zo=E(Zt,A("p2p-circuit"),O()),Fn=P(zo),_o=q(E(Zt,A("p2p-circuit"),A("webrtc"),O()),E(Zt,A("webrtc"),W(O())),A("webrtc")),Bu=P(_o);var Tn=wr(Nn(),1);var Ln="[a-fA-F\\d:]",it=r=>r&&r.includeBoundaries?`(?:(?<=\\s|^)(?=${Ln})|(?<=${Ln})(?=\\s|$))`:"",G="(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}",S="[a-fA-F\\d]{1,4}",te=`
3
- (?:
4
- (?:${S}:){7}(?:${S}|:)| // 1:2:3:4:5:6:7:: 1:2:3:4:5:6:7:8
5
- (?:${S}:){6}(?:${G}|:${S}|:)| // 1:2:3:4:5:6:: 1:2:3:4:5:6::8 1:2:3:4:5:6::8 1:2:3:4:5:6::1.2.3.4
6
- (?:${S}:){5}(?::${G}|(?::${S}){1,2}|:)| // 1:2:3:4:5:: 1:2:3:4:5::7:8 1:2:3:4:5::8 1:2:3:4:5::7:1.2.3.4
7
- (?:${S}:){4}(?:(?::${S}){0,1}:${G}|(?::${S}){1,3}|:)| // 1:2:3:4:: 1:2:3:4::6:7:8 1:2:3:4::8 1:2:3:4::6:7:1.2.3.4
8
- (?:${S}:){3}(?:(?::${S}){0,2}:${G}|(?::${S}){1,4}|:)| // 1:2:3:: 1:2:3::5:6:7:8 1:2:3::8 1:2:3::5:6:7:1.2.3.4
9
- (?:${S}:){2}(?:(?::${S}){0,3}:${G}|(?::${S}){1,5}|:)| // 1:2:: 1:2::4:5:6:7:8 1:2::8 1:2::4:5:6:7:1.2.3.4
10
- (?:${S}:){1}(?:(?::${S}){0,4}:${G}|(?::${S}){1,6}|:)| // 1:: 1::3:4:5:6:7:8 1::8 1::3:4:5:6:7:1.2.3.4
11
- (?::(?:(?::${S}){0,5}:${G}|(?::${S}){1,7}|:)) // ::2:3:4:5:6:7:8 ::2:3:4:5:6:7:8 ::8 ::1.2.3.4
12
- )(?:%[0-9a-zA-Z]{1,})? // %eth0 %1
13
- `.replace(/\s*\/\/.*$/gm,"").replace(/\n/g,"").trim(),jo=new RegExp(`(?:^${G}$)|(?:^${te}$)`),Go=new RegExp(`^${G}$`),Wo=new RegExp(`^${te}$`),dr=r=>r&&r.exact?jo:new RegExp(`(?:${it(r)}${G}${it(r)})|(?:${it(r)}${te}${it(r)})`,"g");dr.v4=r=>r&&r.exact?Go:new RegExp(`${it(r)}${G}${it(r)}`,"g");dr.v6=r=>r&&r.exact?Wo:new RegExp(`${it(r)}${te}${it(r)}`,"g");var Dn=dr;var $n=wr(Cn(),1),{isValid:qo,parse:Xo}=$n.default,Qo=["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"],Jo=Qo.map(r=>new Tn.Netmask(r));function Zo(r){for(let t of Jo)if(t.contains(r))return!0;return!1}function Un(r){return/^::$/.test(r)||/^::1$/.test(r)||/^::f{4}:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(r)||/^::f{4}:0.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(r)||/^64:ff9b::([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(r)||/^100::([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2001::([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2001:2[0-9a-fA-F]:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2001:db8:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2002:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^f[c-d]([0-9a-fA-F]{2,2}):/i.test(r)||/^fe[8-9a-bA-B][0-9a-fA-F]:/i.test(r)||/^ff([0-9a-fA-F]{2,2}):/i.test(r)}var kn=r=>{if(qo(r)){let t=Xo(r);if(t.kind()==="ipv4")return Zo(t.toNormalizedString());if(t.kind()==="ipv6")return Un(r)}else if(mt(r)&&Dn.v6().test(r))return Un(r)};var Mn=kn;function pr(r,t){return Fn.matches(r)||t.transportForMultiaddr(r)==null?!1:bn.matches(r)?!0:vn.matches(r)?Mn(r.toOptions().host)===!1:!1}var Bn=1024*4,On=100,re={timeout:5e3,retries:3,maxInboundStreams:1,maxOutboundStreams:1},ne=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??re.timeout,this.retries=e.retries??re.retries,this.maxInboundStreams=e.maxInboundStreams??re.maxInboundStreams,this.maxOutboundStreams=e.maxOutboundStreams??re.maxOutboundStreams}isStarted(){return this.started}async start(){this.started||(this.topologyId=await this.registrar.register(xt,{notifyOnTransient:!0,onConnect:(t,e)=>{e.transient&&e.direction==="inbound"&&this.upgradeInbound(e).catch(n=>{this.log.error("error during outgoing DCUtR attempt",n)})}}),await this.registrar.handle(xt,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,runOnTransientConnection:!0}),this.started=!0)}async stop(){await this.registrar.unhandle(xt),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 i={signal:AbortSignal.timeout(this.timeout)};try{e=await t.newStream([xt],{signal:i.signal,runOnTransientConnection:!0});let o=qe(e,{maxDataLength:Bn}).pb(j);this.log("B sending connect to %p",t.remotePeer);let a=Date.now();await o.write({type:j.Type.CONNECT,observedAddresses:this.addressManager.getAddresses().map(w=>w.bytes)},i),this.log("B receiving connect from %p",t.remotePeer);let u=await o.read(i);if(u.type!==j.Type.CONNECT)throw this.log("A sent wrong message type"),new z("DCUtR message type was incorrect",ot);let l=this.getDialableMultiaddrs(u.observedAddresses);if(l.length===0)throw this.log("A did not have any dialable multiaddrs"),new z("DCUtR connect message had no multiaddrs",ot);let d=Date.now()-a;this.log("A sending sync, rtt %dms",d),await o.write({type:j.Type.SYNC,observedAddresses:[]},i),this.log("A waiting for half RTT"),await tn(d/2),this.log("B dialing",l);let b=await this.connectionManager.openConnection(l,{signal:i.signal,priority:On});this.log("DCUtR to %p succeeded to address %a, closing relayed connection",t.remotePeer,b.remoteAddr),await t.close(i);break}catch(o){if(this.log.error("error while attempting DCUtR on attempt %d of %d",n+1,this.retries,o),e?.abort(o),n===this.retries)throw o}finally{e!=null&&await e.close(i)}}}async attemptUnilateralConnectionUpgrade(t){let n=(await this.peerStore.get(t.remotePeer)).addresses.map(i=>{let o=i.multiaddr;return o.getPeerId()==null?o.encapsulate(`/p2p/${t.remotePeer}`):o}).filter(i=>pr(i,this.transportManager));if(n.length>0){let i=AbortSignal.timeout(this.timeout);try{this.log("attempting unilateral connection upgrade to %a",n);let o=await this.connectionManager.openConnection(n,{signal:i,force:!0});if(o.transient)throw new Error("Could not open a new, non-transient, connection");return this.log("unilateral connection upgrade to %p succeeded via %a, closing relayed connection",t.remotePeer,o.remoteAddr),await t.close({signal:i}),!0}catch(o){this.log.error("unilateral connection upgrade to %p on addresses %a failed",t.remotePeer,n,o)}}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 i=qe(t,{maxDataLength:Bn}).pb(j);this.log("A receiving connect");let o=await i.read(n);if(o.type!==j.Type.CONNECT)throw this.log("B sent wrong message type"),new z("DCUtR message type was incorrect",ot);if(o.observedAddresses.length===0)throw this.log("B sent no multiaddrs"),new z("DCUtR connect message had no multiaddrs",ot);let a=this.getDialableMultiaddrs(o.observedAddresses);if(a.length===0)throw this.log("B had no dialable multiaddrs"),new z("DCUtR connect message had no dialable multiaddrs",ot);if(this.log("A sending connect"),await i.write({type:j.Type.CONNECT,observedAddresses:this.addressManager.getAddresses().map(d=>d.bytes)}),this.log("A receiving sync"),(await i.read(n)).type!==j.Type.SYNC)throw new z("DCUtR message type was incorrect",ot);this.log("A dialing",a);let l=await this.connectionManager.openConnection(a,{signal:n.signal,priority:On,force:!0});this.log("DCUtR to %p succeeded via %a, closing relayed connection",e.remotePeer,l.remoteAddr),await e.close(n)}catch(i){this.log.error("incoming DCUtR from %p failed",e.remotePeer,i),t.abort(i)}finally{await t.close(n)}}getDialableMultiaddrs(t){let e=[];for(let n of t)if(!(n==null||n.length===0))try{let i=je(n);if(!pr(i,this.transportManager))continue;e.push(i)}catch{}return e}};var xt="/libp2p/dcutr";function Ko(r={}){return t=>new ne(t,r)}return Wn(Ho);})();
2
+ "use strict";var Libp2PDcutr=(()=>{var vn=Object.create;var Tt=Object.defineProperty;var Nn=Object.getOwnPropertyDescriptor;var Fn=Object.getOwnPropertyNames;var Ln=Object.getPrototypeOf,Un=Object.prototype.hasOwnProperty;var Dn=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),L=(r,t)=>{for(var e in t)Tt(r,e,{get:t[e],enumerable:!0})},hr=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Fn(t))!Un.call(r,i)&&i!==e&&Tt(r,i,{get:()=>t[i],enumerable:!(n=Nn(t,i))||n.enumerable});return r};var Tn=(r,t,e)=>(e=r!=null?vn(Ln(r)):{},hr(t||!r||!r.__esModule?Tt(e,"default",{value:r,enumerable:!0}):e,r)),Cn=r=>hr(Tt({},"__esModule",{value:!0}),r);var cn=Dn(Nt=>{(function(){var r,t,e,n,i,o,s,a;a=function(c){var h,f,u,l;return h=(c&255<<24)>>>24,f=(c&255<<16)>>>16,u=(c&65280)>>>8,l=c&255,[h,f,u,l].join(".")},s=function(c){var h,f,u,l,m,d;for(h=[],u=l=0;l<=3&&c.length!==0;u=++l){if(u>0){if(c[0]!==".")throw new Error("Invalid IP");c=c.substring(1)}d=t(c),m=d[0],f=d[1],c=c.substring(f),h.push(m)}if(c.length!==0)throw new Error("Invalid IP");switch(h.length){case 1:if(h[0]>4294967295)throw new Error("Invalid IP");return h[0]>>>0;case 2:if(h[0]>255||h[1]>16777215)throw new Error("Invalid IP");return(h[0]<<24|h[1])>>>0;case 3:if(h[0]>255||h[1]>255||h[2]>65535)throw new Error("Invalid IP");return(h[0]<<24|h[1]<<16|h[2])>>>0;case 4:if(h[0]>255||h[1]>255||h[2]>255||h[3]>255)throw new Error("Invalid IP");return(h[0]<<24|h[1]<<16|h[2]<<8|h[3])>>>0;default:throw new Error("Invalid IP")}},e=function(c){return c.charCodeAt(0)},n=e("0"),o=e("a"),i=e("A"),t=function(c){var h,f,u,l,m;for(l=0,h=10,f="9",u=0,c.length>1&&c[u]==="0"&&(c[u+1]==="x"||c[u+1]==="X"?(u+=2,h=16):"0"<=c[u+1]&&c[u+1]<="9"&&(u++,h=8,f="7")),m=u;u<c.length;){if("0"<=c[u]&&c[u]<=f)l=l*h+(e(c[u])-n)>>>0;else if(h===16)if("a"<=c[u]&&c[u]<="f")l=l*h+(10+e(c[u])-o)>>>0;else if("A"<=c[u]&&c[u]<="F")l=l*h+(10+e(c[u])-i)>>>0;else break;else break;if(l>4294967295)throw new Error("too large");u++}if(u===m)throw new Error("empty octet");return[l,u]},r=function(){function c(h,f){var u,l,m,d;if(typeof h!="string")throw new Error("Missing `net' parameter");if(f||(d=h.split("/",2),h=d[0],f=d[1]),f||(f=32),typeof f=="string"&&f.indexOf(".")>-1){try{this.maskLong=s(f)}catch(A){throw u=A,new Error("Invalid mask: "+f)}for(l=m=32;m>=0;l=--m)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=(s(h)&this.maskLong)>>>0}catch(A){throw u=A,new Error("Invalid net address: "+h)}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 c.prototype.contains=function(h){return typeof h=="string"&&(h.indexOf("/")>0||h.split(".").length!==4)&&(h=new c(h)),h instanceof c?this.contains(h.base)&&this.contains(h.broadcast||h.last):(s(h)&this.maskLong)>>>0===(this.netLong&this.maskLong)>>>0},c.prototype.next=function(h){return h==null&&(h=1),new c(a(this.netLong+this.size*h),this.mask)},c.prototype.forEach=function(h){var f,u,l;for(l=s(this.first),u=s(this.last),f=0;l<=u;)h(a(l),l,f),f++,l++},c.prototype.toString=function(){return this.base+"/"+this.bitmask},c}(),Nt.ip2long=s,Nt.long2ip=a,Nt.Netmask=r}).call(Nt)});var Bo={};L(Bo,{dcutr:()=>Ro,multicodec:()=>wt});var B=class extends Error{code;props;constructor(t,e,n){super(t),this.code=e,this.name=n?.name??"CodeError",this.props=n??{}}};var rt="ERR_INVALID_MESSAGE";var ne={};L(ne,{base58btc:()=>I,base58flickr:()=>Vn});var Vo=new Uint8Array(0);function ur(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function G(r){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 fr(r){return new TextEncoder().encode(r)}function lr(r){return new TextDecoder().decode(r)}function Pn(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 i=0;i<r.length;i++){var o=r.charAt(i),s=o.charCodeAt(0);if(e[s]!==255)throw new TypeError(o+" is ambiguous");e[s]=i}var a=r.length,c=r.charAt(0),h=Math.log(a)/Math.log(256),f=Math.log(256)/Math.log(a);function u(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,P=0,V=d.length;P!==V&&d[P]===0;)P++,A++;for(var O=(V-P)*f+1>>>0,U=new Uint8Array(O);P!==V;){for(var _=d[P],J=0,R=O-1;(_!==0||J<et)&&R!==-1;R--,J++)_+=256*U[R]>>>0,U[R]=_%a>>>0,_=_/a>>>0;if(_!==0)throw new Error("Non-zero carry");et=J,P++}for(var j=O-et;j!==O&&U[j]===0;)j++;for(var Dt=c.repeat(A);j<O;++j)Dt+=r.charAt(U[j]);return Dt}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,P=0;d[A]===c;)et++,A++;for(var V=(d.length-A)*h+1>>>0,O=new Uint8Array(V);d[A];){var U=e[d.charCodeAt(A)];if(U===255)return;for(var _=0,J=V-1;(U!==0||_<P)&&J!==-1;J--,_++)U+=a*O[J]>>>0,O[J]=U%256>>>0,U=U/256>>>0;if(U!==0)throw new Error("Non-zero carry");P=_,A++}if(d[A]!==" "){for(var R=V-P;R!==V&&O[R]===0;)R++;for(var j=new Uint8Array(et+(V-R)),Dt=et;R!==V;)j[Dt++]=O[R++];return j}}}function m(d){var A=l(d);if(A)return A;throw new Error(`Non-${t} character`)}return{encode:u,decodeUnsafe:l,decode:m}}var Rn=Pn,Bn=Rn,pr=Bn;var Yt=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")}},te=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,e,n){if(this.name=t,this.prefix=e,e.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=e.codePointAt(0),this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return mr(this,t)}},ee=class{decoders;constructor(t){this.decoders=t}or(t){return mr(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 mr(r,t){return new ee({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var re=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,e,n,i){this.name=t,this.prefix=e,this.baseEncode=n,this.baseDecode=i,this.encoder=new Yt(t,e,n),this.decoder=new te(t,e,i)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function st({name:r,prefix:t,encode:e,decode:n}){return new re(r,t,e,n)}function K({name:r,prefix:t,alphabet:e}){let{encode:n,decode:i}=pr(e,r);return st({prefix:t,name:r,encode:n,decode:o=>G(i(o))})}function kn(r,t,e,n){let i={};for(let f=0;f<t.length;++f)i[t[f]]=f;let o=r.length;for(;r[o-1]==="=";)--o;let s=new Uint8Array(o*e/8|0),a=0,c=0,h=0;for(let f=0;f<o;++f){let u=i[r[f]];if(u===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<e|u,a+=e,a>=8&&(a-=8,s[h++]=255&c>>a)}if(a>=e||255&c<<8-a)throw new SyntaxError("Unexpected end of data");return s}function Mn(r,t,e){let n=t[t.length-1]==="=",i=(1<<e)-1,o="",s=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],s+=8;s>e;)s-=e,o+=t[i&a>>s];if(s!==0&&(o+=t[i&a<<e-s]),n)for(;o.length*e&7;)o+="=";return o}function w({name:r,prefix:t,bitsPerChar:e,alphabet:n}){return st({prefix:t,name:r,encode(i){return Mn(i,n,e)},decode(i){return kn(i,n,e,r)}})}var I=K({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Vn=K({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var ie={};L(ie,{base32:()=>W,base32hex:()=>$n,base32hexpad:()=>Gn,base32hexpadupper:()=>Wn,base32hexupper:()=>jn,base32pad:()=>_n,base32padupper:()=>zn,base32upper:()=>On,base32z:()=>qn});var W=w({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),On=w({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),_n=w({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),zn=w({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),$n=w({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),jn=w({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Gn=w({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Wn=w({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),qn=w({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Xn=br,gr=128,Qn=127,Jn=~Qn,Kn=Math.pow(2,31);function br(r,t,e){t=t||[],e=e||0;for(var n=e;r>=Kn;)t[e++]=r&255|gr,r/=128;for(;r&Jn;)t[e++]=r&255|gr,r>>>=7;return t[e]=r|0,br.bytes=e-n+1,t}var Zn=oe,Hn=128,wr=127;function oe(r,n){var e=0,n=n||0,i=0,o=n,s,a=r.length;do{if(o>=a)throw oe.bytes=0,new RangeError("Could not decode varint");s=r[o++],e+=i<28?(s&wr)<<i:(s&wr)*Math.pow(2,i),i+=7}while(s>=Hn);return oe.bytes=o-n,e}var Yn=Math.pow(2,7),ti=Math.pow(2,14),ei=Math.pow(2,21),ri=Math.pow(2,28),ni=Math.pow(2,35),ii=Math.pow(2,42),oi=Math.pow(2,49),si=Math.pow(2,56),ai=Math.pow(2,63),ci=function(r){return r<Yn?1:r<ti?2:r<ei?3:r<ri?4:r<ni?5:r<ii?6:r<oi?7:r<si?8:r<ai?9:10},hi={encode:Xn,decode:Zn,encodingLength:ci},ui=hi,bt=ui;function xt(r,t=0){return[bt.decode(r,t),bt.decode.bytes]}function at(r,t,e=0){return bt.encode(r,t,e),t}function ct(r){return bt.encodingLength(r)}function nt(r,t){let e=t.byteLength,n=ct(r),i=n+ct(e),o=new Uint8Array(i+e);return at(r,o,0),at(e,o,n),o.set(t,i),new ht(r,e,t,o)}function Pt(r){let t=G(r),[e,n]=xt(t),[i,o]=xt(t.subarray(n)),s=t.subarray(n+o);if(s.byteLength!==i)throw new Error("Incorrect length");return new ht(e,i,s,t)}function xr(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&ur(r.bytes,e.bytes)}}var ht=class{code;size;digest;bytes;constructor(t,e,n,i){this.code=t,this.size=e,this.digest=n,this.bytes=i}};function yr(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return li(e,se(r),t??I.encoder);default:return di(e,se(r),t??W.encoder)}}var Ar=new WeakMap;function se(r){let t=Ar.get(r);if(t==null){let e=new Map;return Ar.set(r,e),e}return t}var Z=class r{code;version;multihash;bytes;"/";constructor(t,e,n,i){this.code=e,this.version=t,this.multihash=n,this.bytes=i,this["/"]=i}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!==yt)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==pi)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=nt(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&&xr(t.multihash,n.multihash)}toString(t){return yr(this,t)}toJSON(){return{"/":yr(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:i,multihash:o,bytes:s}=e;return new r(n,i,o,s??Ir(n,i,o.bytes))}else if(e[mi]===!0){let{version:n,multihash:i,code:o}=e,s=Pt(i);return r.create(n,o,s)}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!==yt)throw new Error(`Version 0 CID must use dag-pb (code: ${yt}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let i=Ir(t,e,n.bytes);return new r(t,e,n,i)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,yt,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,i=G(t.subarray(n,n+e.multihashSize));if(i.byteLength!==e.multihashSize)throw new Error("Incorrect length");let o=i.subarray(e.multihashSize-e.digestSize),s=new ht(e.multihashCode,e.digestSize,o,i);return[e.version===0?r.createV0(s):r.createV1(e.codec,s),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[u,l]=xt(t.subarray(e));return e+=l,u},i=n(),o=yt;if(i===18?(i=0,e=0):o=n(),i!==0&&i!==1)throw new RangeError(`Invalid CID version ${i}`);let s=e,a=n(),c=n(),h=e+c,f=h-s;return{version:i,codec:o,multihashCode:a,digestSize:c,multihashSize:f,size:h}}static parse(t,e){let[n,i]=fi(t,e),o=r.decode(i);if(o.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return se(o).set(n,t),o}};function fi(r,t){switch(r[0]){case"Q":{let e=t??I;return[I.prefix,e.decode(`${I.prefix}${r}`)]}case I.prefix:{let e=t??I;return[I.prefix,e.decode(r)]}case W.prefix:{let e=t??W;return[W.prefix,e.decode(r)]}default:{if(t==null)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[r[0],t.decode(r)]}}}function li(r,t,e){let{prefix:n}=e;if(n!==I.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let i=t.get(n);if(i==null){let o=e.encode(r).slice(1);return t.set(n,o),o}else return i}function di(r,t,e){let{prefix:n}=e,i=t.get(n);if(i==null){let o=e.encode(r);return t.set(n,o),o}else return i}var yt=112,pi=18;function Ir(r,t,e){let n=ct(r),i=n+ct(t),o=new Uint8Array(i+e.byteLength);return at(r,o,0),at(t,o,n),o.set(e,i),o}var mi=Symbol.for("@ipld/js-cid/CID");function Rt(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 ae={};L(ae,{base10:()=>gi});var gi=K({prefix:"9",name:"base10",alphabet:"0123456789"});var ce={};L(ce,{base16:()=>wi,base16upper:()=>bi});var wi=w({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),bi=w({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var he={};L(he,{base2:()=>xi});var xi=w({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var ue={};L(ue,{base256emoji:()=>Si});var Er=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),yi=Er.reduce((r,t,e)=>(r[e]=t,r),[]),Ai=Er.reduce((r,t,e)=>(r[t.codePointAt(0)]=e,r),[]);function Ii(r){return r.reduce((t,e)=>(t+=yi[e],t),"")}function Ei(r){let t=[];for(let e of r){let n=Ai[e.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${e}`);t.push(n)}return new Uint8Array(t)}var Si=st({prefix:"\u{1F680}",name:"base256emoji",encode:Ii,decode:Ei});var fe={};L(fe,{base36:()=>vi,base36upper:()=>Ni});var vi=K({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Ni=K({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var de={};L(de,{base64:()=>Fi,base64pad:()=>Li,base64url:()=>le,base64urlpad:()=>Ui});var Fi=w({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Li=w({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),le=w({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Ui=w({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var pe={};L(pe,{base8:()=>Di});var Di=w({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var me={};L(me,{identity:()=>Ti});var Ti=st({prefix:"\0",name:"identity",encode:r=>lr(r),decode:r=>fr(r)});var hs=new TextEncoder,us=new TextDecoder;var ge={};L(ge,{identity:()=>ki});var Sr=0,Ri="identity",vr=G;function Bi(r){return nt(Sr,vr(r))}var ki={code:Sr,name:Ri,encode:vr,digest:Bi};var xe={};L(xe,{sha256:()=>Mi,sha512:()=>Vi});function be({name:r,code:t,encode:e}){return new we(r,t,e)}var we=class{name;code;encode;constructor(t,e,n){this.name=t,this.code=e,this.encode=n}digest(t){if(t instanceof Uint8Array){let e=this.encode(t);return e instanceof Uint8Array?nt(this.code,e):e.then(n=>nt(this.code,n))}else throw Error("Unknown type, must be binary type")}};function Fr(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var Mi=be({name:"sha2-256",code:18,encode:Fr("SHA-256")}),Vi=be({name:"sha2-512",code:19,encode:Fr("SHA-512")});var At={...me,...he,...pe,...ae,...ce,...ie,...fe,...ne,...de,...ue},Es={...xe,...ge};function H(r){return globalThis.Buffer!=null?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):r}function q(r=0){return globalThis.Buffer?.alloc!=null?H(globalThis.Buffer.alloc(r)):new Uint8Array(r)}function v(r=0){return globalThis.Buffer?.allocUnsafe!=null?H(globalThis.Buffer.allocUnsafe(r)):new Uint8Array(r)}function Ur(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var Lr=Ur("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),ye=Ur("ascii","a",r=>{let t="a";for(let e=0;e<r.length;e++)t+=String.fromCharCode(r[e]);return t},r=>{r=r.substring(1);let t=v(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),Oi={utf8:Lr,"utf-8":Lr,hex:At.base16,latin1:ye,ascii:ye,binary:ye,...At},Bt=Oi;function N(r,t="utf8"){let e=Bt[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return(t==="utf8"||t==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?globalThis.Buffer.from(r.buffer,r.byteOffset,r.byteLength).toString("utf8"):e.encoder.encode(r).substring(1)}var _i=Math.pow(2,7),zi=Math.pow(2,14),$i=Math.pow(2,21),Ae=Math.pow(2,28),Ie=Math.pow(2,35),Ee=Math.pow(2,42),Se=Math.pow(2,49),p=128,E=127;function D(r){if(r<_i)return 1;if(r<zi)return 2;if(r<$i)return 3;if(r<Ae)return 4;if(r<Ie)return 5;if(r<Ee)return 6;if(r<Se)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function ji(r,t,e=0){switch(D(r)){case 8:t[e++]=r&255|p,r/=128;case 7:t[e++]=r&255|p,r/=128;case 6:t[e++]=r&255|p,r/=128;case 5:t[e++]=r&255|p,r/=128;case 4:t[e++]=r&255|p,r>>>=7;case 3:t[e++]=r&255|p,r>>>=7;case 2:t[e++]=r&255|p,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function Gi(r,t,e=0){switch(D(r)){case 8:t.set(e++,r&255|p),r/=128;case 7:t.set(e++,r&255|p),r/=128;case 6:t.set(e++,r&255|p),r/=128;case 5:t.set(e++,r&255|p),r/=128;case 4:t.set(e++,r&255|p),r>>>=7;case 3:t.set(e++,r&255|p),r>>>=7;case 2:t.set(e++,r&255|p),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function Wi(r,t){let e=r[t],n=0;if(n+=e&E,e<p||(e=r[t+1],n+=(e&E)<<7,e<p)||(e=r[t+2],n+=(e&E)<<14,e<p)||(e=r[t+3],n+=(e&E)<<21,e<p)||(e=r[t+4],n+=(e&E)*Ae,e<p)||(e=r[t+5],n+=(e&E)*Ie,e<p)||(e=r[t+6],n+=(e&E)*Ee,e<p)||(e=r[t+7],n+=(e&E)*Se,e<p))return n;throw new RangeError("Could not decode varint")}function qi(r,t){let e=r.get(t),n=0;if(n+=e&E,e<p||(e=r.get(t+1),n+=(e&E)<<7,e<p)||(e=r.get(t+2),n+=(e&E)<<14,e<p)||(e=r.get(t+3),n+=(e&E)<<21,e<p)||(e=r.get(t+4),n+=(e&E)*Ae,e<p)||(e=r.get(t+5),n+=(e&E)*Ie,e<p)||(e=r.get(t+6),n+=(e&E)*Ee,e<p)||(e=r.get(t+7),n+=(e&E)*Se,e<p))return n;throw new RangeError("Could not decode varint")}function Y(r,t,e=0){return t==null&&(t=v(D(r))),t instanceof Uint8Array?ji(r,t,e):Gi(r,t,e)}function X(r,t=0){return r instanceof Uint8Array?Wi(r,t):qi(r,t)}function T(r,t){if(globalThis.Buffer!=null)return H(globalThis.Buffer.concat(r,t));t==null&&(t=r.reduce((i,o)=>i+o.length,0));let e=v(t),n=0;for(let i of r)e.set(i,n),n+=i.length;return H(e)}var kt=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,i){return this.readAtomically(()=>{let o=0,s=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",h=2**(8*i)-1;for(;;){let f=this.readAtomically(()=>{let u=this.readChar();if(u===void 0)return;let l=Number.parseInt(u,t);if(!Number.isNaN(l))return l});if(f===void 0)break;if(o*=t,o+=f,o>h||(s+=1,e!==void 0&&s>e))return}if(s!==0)return!n&&c&&s>1?void 0:o})}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 i=n*2;if(n<e.length-3){let s=this.readSeparator(":",n,()=>this.readIPv4Addr());if(s!==void 0)return e[i]=s[0],e[i+1]=s[1],e[i+2]=s[2],e[i+3]=s[3],[i+4,!0]}let o=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(o===void 0)return[i,!1];e[i]=o>>8,e[i+1]=o&255}return[e.length,!1]};return this.readAtomically(()=>{let e=new Uint8Array(16),[n,i]=t(e);if(n===16)return e;if(i||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let o=new Uint8Array(14),s=16-(n+2),[a]=t(o.subarray(0,s));return e.set(o.subarray(0,a),16-a),e})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var Dr=45,Xi=15,ft=new kt;function Ne(r){if(!(r.length>Xi))return ft.new(r).parseWith(()=>ft.readIPv4Addr())}function Fe(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>Dr))return ft.new(r).parseWith(()=>ft.readIPv6Addr())}function Mt(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>Dr))return ft.new(r).parseWith(()=>ft.readIPAddr())}var qs=parseInt("0xFFFF",16),Xs=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function It(r,t="utf8"){let e=Bt[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return(t==="utf8"||t==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?H(globalThis.Buffer.from(r,"utf-8")):e.decoder.decode(`${e.prefix}${r}`)}function lt(r){return!!Ne(r)}function dt(r){return!!Fe(r)}function Vt(r){return!!Mt(r)}var Pr=lt,Hi=dt,Le=function(r){let t=0;if(r=r.toString().trim(),Pr(r)){let e=new Uint8Array(t+4);return r.split(/\./g).forEach(n=>{e[t++]=parseInt(n,10)&255}),e}if(Hi(r)){let e=r.split(":",8),n;for(n=0;n<e.length;n++){let o=Pr(e[n]),s;o&&(s=Le(e[n]),e[n]=N(s.slice(0,2),"base16")),s!=null&&++n<8&&e.splice(n,0,N(s.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 o=[n,1];for(n=9-e.length;n>0;n--)o.push("0");e.splice.apply(e,o)}let i=new Uint8Array(t+16);for(n=0;n<e.length;n++){let o=parseInt(e[n],16);i[t++]=o>>8&255,i[t++]=o&255}return i}throw new Error("invalid ip address")},Rr=function(r,t=0,e){t=~~t,e=e??r.length-t;let n=new DataView(r.buffer);if(e===4){let i=[];for(let o=0;o<e;o++)i.push(r[t+o]);return i.join(".")}if(e===16){let i=[];for(let o=0;o<e;o+=2)i.push(n.getUint16(t+o).toString(16));return i.join(":").replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}return""};var pt={},Ue={},to=[[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"],[777,-1,"memory"]];to.forEach(r=>{let t=eo(...r);Ue[t.code]=t,pt[t.name]=t});function eo(r,t,e,n,i){return{code:r,size:t,name:e,resolvable:!!n,path:!!i}}function g(r){if(typeof r=="number"){if(Ue[r]!=null)return Ue[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(pt[r]!=null)return pt[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var Pa=g("ip4"),Ra=g("ip6"),Ba=g("ipcidr");function Te(r,t){switch(g(r).code){case 4:case 41:return no(t);case 42:return Mr(t);case 6:case 273:case 33:case 132:return Or(t).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return Mr(t);case 421:return ao(t);case 444:return Vr(t);case 445:return Vr(t);case 466:return so(t);default:return N(t,"base16")}}function Ce(r,t){switch(g(r).code){case 4:return Br(t);case 41:return Br(t);case 42:return kr(t);case 6:case 273:case 33:case 132:return Pe(parseInt(t,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return kr(t);case 421:return io(t);case 444:return co(t);case 445:return ho(t);case 466:return oo(t);default:return It(t,"base16")}}var De=Object.values(At).map(r=>r.decoder),ro=function(){let r=De[0].or(De[1]);return De.slice(2).forEach(t=>r=r.or(t)),r}();function Br(r){if(!Vt(r))throw new Error("invalid ip address");return Le(r)}function no(r){let t=Rr(r,0,r.length);if(t==null)throw new Error("ipBuff is required");if(!Vt(t))throw new Error("invalid ip address");return t}function Pe(r){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,r),new Uint8Array(t)}function Or(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function kr(r){let t=It(r),e=Uint8Array.from(Y(t.length));return T([e,t],e.length+t.length)}function Mr(r){let t=X(r);if(r=r.slice(D(t)),r.length!==t)throw new Error("inconsistent lengths");return N(r)}function io(r){let t;r[0]==="Q"||r[0]==="1"?t=Pt(I.decode(`z${r}`)).bytes:t=Z.parse(r).multihash.bytes;let e=Uint8Array.from(Y(t.length));return T([e,t],e.length+t.length)}function oo(r){let t=ro.decode(r),e=Uint8Array.from(Y(t.length));return T([e,t],e.length+t.length)}function so(r){let t=X(r),e=r.slice(D(t));if(e.length!==t)throw new Error("inconsistent lengths");return"u"+N(e,"base64url")}function ao(r){let t=X(r),e=r.slice(D(t));if(e.length!==t)throw new Error("inconsistent lengths");return N(e,"base58btc")}function co(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.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 i=Pe(n);return T([e,i],e.length+i.length)}function ho(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=W.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 i=Pe(n);return T([e,i],e.length+i.length)}function Vr(r){let t=r.slice(0,r.length-2),e=r.slice(r.length-2),n=N(t,"base32"),i=Or(e);return`${n}:${i}`}function _r(r){r=Re(r);let t=[],e=[],n=null,i=r.split("/").slice(1);if(i.length===1&&i[0]==="")return{bytes:new Uint8Array,string:"/",tuples:[],stringTuples:[],path:null};for(let o=0;o<i.length;o++){let s=i[o],a=g(s);if(a.size===0){t.push([a.code]),e.push([a.code]);continue}if(o++,o>=i.length)throw $r("invalid address: "+r);if(a.path===!0){n=Re(i.slice(o).join("/")),t.push([a.code,Ce(a.code,n)]),e.push([a.code,n]);break}let c=Ce(a.code,i[o]);t.push([a.code,c]),e.push([a.code,Te(a.code,c)])}return{string:zr(e),bytes:ke(t),tuples:t,stringTuples:e,path:n}}function Be(r){let t=[],e=[],n=null,i=0;for(;i<r.length;){let o=X(r,i),s=D(o),a=g(o),c=uo(a,r.slice(i+s));if(c===0){t.push([o]),e.push([o]),i+=s;continue}let h=r.slice(i+s,i+s+c);if(i+=c+s,i>r.length)throw $r("Invalid address Uint8Array: "+N(r,"base16"));t.push([o,h]);let f=Te(o,h);if(e.push([o,f]),a.path===!0){n=f;break}}return{bytes:Uint8Array.from(r),string:zr(e),tuples:t,stringTuples:e,path:n}}function zr(r){let t=[];return r.map(e=>{let n=g(e[0]);return t.push(n.name),e.length>1&&e[1]!=null&&t.push(e[1]),null}),Re(t.join("/"))}function ke(r){return T(r.map(t=>{let e=g(t[0]),n=Uint8Array.from(Y(e.code));return t.length>1&&t[1]!=null&&(n=T([n,t[1]])),n}))}function uo(r,t){if(r.size>0)return r.size/8;if(r.size===0)return 0;{let e=X(t instanceof Uint8Array?t:Uint8Array.from(t));return e+D(e)}}function Re(r){return"/"+r.trim().split("/").filter(t=>t).join("/")}function $r(r){return new Error("Error parsing address: "+r)}var fo=Symbol.for("nodejs.util.inspect.custom"),Me=Symbol.for("@multiformats/js-multiaddr/multiaddr"),lo=[g("dns").code,g("dns4").code,g("dns6").code,g("dnsaddr").code],Ot=class r{bytes;#e;#t;#r;#n;[Me]=!0;constructor(t){t==null&&(t="");let e;if(t instanceof Uint8Array)e=Be(t);else if(typeof t=="string"){if(t.length>0&&t.charAt(0)!=="/")throw new Error(`multiaddr "${t}" must start with a "/"`);e=_r(t)}else if(Gr(t))e=Be(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,i,o="",s=g("tcp"),a=g("udp"),c=g("ip4"),h=g("ip6"),f=g("dns6"),u=g("ip6zone");for(let[m,d]of this.stringTuples())m===u.code&&(o=`%${d??""}`),lo.includes(m)&&(e=s.name,i=443,n=`${d??""}${o}`,t=m===f.code?6:4),(m===s.code||m===a.code)&&(e=g(m).name,i=parseInt(d??"")),(m===c.code||m===h.code)&&(e=g(m).name,n=`${d??""}${o}`,t=m===h.code?6:4);if(t==null||e==null||n==null||i==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:i}}protos(){return this.#t.map(([t])=>Object.assign({},g(t)))}protoCodes(){return this.#t.map(([t])=>t)}protoNames(){return this.#t.map(([t])=>g(t).name)}tuples(){return this.#t}stringTuples(){return this.#r}encapsulate(t){return t=new r(t),new r(this.toString()+t.toString())}decapsulate(t){let e=t.toString(),n=this.toString(),i=n.lastIndexOf(e);if(i<0)throw new Error(`Address ${this.toString()} does not contain subaddress: ${t.toString()}`);return new r(n.slice(0,i))}decapsulateCode(t){let e=this.tuples();for(let n=e.length-1;n>=0;n--)if(e[n][0]===t)return new r(ke(e.slice(0,n)));return this}getPeerId(){try{let t=[];this.stringTuples().forEach(([n,i])=>{n===pt.p2p.code&&t.push([n,i]),n===pt["p2p-circuit"].code&&(t=[])});let e=t.pop();if(e?.[1]!=null){let n=e[1];return n[0]==="Q"||n[0]==="1"?N(I.decode(`z${n}`),"base58btc"):N(Z.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){return this.#n}equals(t){return Rt(this.bytes,t.bytes)}async resolve(t){let e=this.protos().find(o=>o.resolvable);if(e==null)return[this];let n=jr.get(e.name);if(n==null)throw new B(`no available resolver for ${e.name}`,"ERR_NO_AVAILABLE_RESOLVER");return(await n(this,t)).map(o=>new r(o))}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)}[fo](){return`Multiaddr(${this.#e})`}};var jr=new Map;function Gr(r){return!!r?.[Me]}function Ve(r){return new Ot(r)}var Wr=()=>{let r=new Error("Delay aborted");return r.name="AbortError",r},po=new WeakMap;function mo({clearTimeout:r,setTimeout:t}={}){return(e,{value:n,signal:i}={})=>{if(i?.aborted)return Promise.reject(Wr());let o,s,a,c=r??clearTimeout,h=()=>{c(o),a(Wr())},f=()=>{i&&i.removeEventListener("abort",h)},u=new Promise((l,m)=>{s=()=>{f(),l(n)},a=m,o=(t??setTimeout)(s,e)});return i&&i.addEventListener("abort",h,{once:!0}),po.set(u,()=>{c(o),o=null,s()}),u}}var go=mo(),qr=go;var Qr=Symbol.for("@achingbrain/uint8arraylist");function Xr(r,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let e=0;for(let n of r){let i=e+n.byteLength;if(t<i)return{buf:n,index:t-e};e=i}throw new RangeError("index is out of bounds")}function _t(r){return!!r?.[Qr]}var Q=class r{bufs;length;[Qr]=!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(_t(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(_t(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=Xr(this.bufs,t);return e.buf[e.index]}set(t,e){let n=Xr(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(_t(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:i}=this._subList(t,e);return T(n,i)}subarray(t,e){let{bufs:n,length:i}=this._subList(t,e);return n.length===1?n[0]:T(n,i)}sublist(t,e){let{bufs:n,length:i}=this._subList(t,e),o=new r;return o.length=i,o.bufs=[...n],o}_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=[],i=0;for(let o=0;o<this.bufs.length;o++){let s=this.bufs[o],a=i,c=a+s.byteLength;if(i=c,t>=c)continue;let h=t>=a&&t<c,f=e>a&&e<=c;if(h&&f){if(t===a&&e===c){n.push(s);break}let u=t-a;n.push(s.subarray(u,u+(e-t)));break}if(h){if(t===0){n.push(s);continue}n.push(s.subarray(t-a));continue}if(f){if(e===c){n.push(s);break}n.push(s.subarray(0,e-a));break}n.push(s)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!_t(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 i=n.byteLength;if(i===0)throw new TypeError("search must be at least 1 byte long");let o=256,s=new Int32Array(o);for(let u=0;u<o;u++)s[u]=-1;for(let u=0;u<i;u++)s[n[u]]=u;let a=s,c=this.byteLength-n.byteLength,h=n.byteLength-1,f;for(let u=e;u<=c;u+=f){f=0;for(let l=h;l>=0;l--){let m=this.get(u+l);if(n[l]!==m){f=Math.max(1,l-a[m]);break}}if(f===0)return u}return-1}getInt8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getInt8(0)}setInt8(t,e){let n=v(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,e),this.write(n,t)}getInt16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,e)}setInt16(t,e,n){let i=q(2);new DataView(i.buffer,i.byteOffset,i.byteLength).setInt16(0,e,n),this.write(i,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 i=q(4);new DataView(i.buffer,i.byteOffset,i.byteLength).setInt32(0,e,n),this.write(i,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 i=q(8);new DataView(i.buffer,i.byteOffset,i.byteLength).setBigInt64(0,e,n),this.write(i,t)}getUint8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getUint8(0)}setUint8(t,e){let n=v(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,e),this.write(n,t)}getUint16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,e)}setUint16(t,e,n){let i=q(2);new DataView(i.buffer,i.byteOffset,i.byteLength).setUint16(0,e,n),this.write(i,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 i=q(4);new DataView(i.buffer,i.byteOffset,i.byteLength).setUint32(0,e,n),this.write(i,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 i=q(8);new DataView(i.buffer,i.byteOffset,i.byteLength).setBigUint64(0,e,n),this.write(i,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 i=q(4);new DataView(i.buffer,i.byteOffset,i.byteLength).setFloat32(0,e,n),this.write(i,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 i=q(8);new DataView(i.buffer,i.byteOffset,i.byteLength).setFloat64(0,e,n),this.write(i,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(!Rt(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((i,o)=>i+o.byteLength,0)),n.length=e,n}};function mt(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var zt=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.name="AbortError",this.code=e??"ABORT_ERR"}};async function Jr(r,t,e){if(t==null)return r;if(t.aborted)return Promise.reject(new zt(e?.errorMessage,e?.errorCode));let n,i=new zt(e?.errorMessage,e?.errorCode);try{return await Promise.race([r,new Promise((o,s)=>{n=()=>{s(i)},t.addEventListener("abort",n)})])}finally{n!=null&&t.removeEventListener("abort",n)}}var Oe=class{needNext;haveNext;ended;nextResult;constructor(){this.ended=!1,this.needNext=mt(),this.haveNext=mt()}[Symbol.asyncIterator](){return this}async next(){if(this.nextResult==null&&await this.haveNext.promise,this.nextResult==null)throw new Error("Have next but next was undefined");let t=this.nextResult;return this.nextResult=void 0,this.needNext.resolve(),this.needNext=mt(),t}async throw(t){return this.ended=!0,t!=null&&this.haveNext.reject(t),{done:!0,value:void 0}}async return(){let t={done:!0,value:void 0};return await this._push(void 0),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 new Error("Cannot push value onto an ended pushable");this.nextResult!=null&&await this.needNext.promise,t!=null?this.nextResult={done:!1,value:t}:(this.ended=!0,this.nextResult={done:!0,value:void 0}),this.haveNext.resolve(),this.haveNext=mt(),await Jr(this.needNext.promise,e?.signal,e)}};function Kr(){return new Oe}var $t=class extends Error{code;constructor(t,e){super(t),this.code=e}},_e=class extends $t{type;constructor(t){super(t,"ABORT_ERR"),this.type="aborted"}};function Zr(r,t){let e=Kr();r.sink(e).catch(async s=>{await e.end(s)}),r.sink=async s=>{for await(let a of s)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 i=new Q;return{read:async(s,a)=>{a?.signal?.throwIfAborted();let c,h=new Promise((f,u)=>{c=()=>{u(new _e("Read aborted"))},a?.signal?.addEventListener("abort",c)});try{if(s==null){let{done:u,value:l}=await Promise.race([n.next(),h]);return u===!0?new Q:l}for(;i.byteLength<s;){let{value:u,done:l}=await Promise.race([n.next(),h]);if(l===!0)throw new $t("unexpected end of input","ERR_UNEXPECTED_EOF");i.append(u)}let f=i.sublist(0,s);return i.consume(s),f}finally{c!=null&&a?.signal?.removeEventListener("abort",c)}},write:async(s,a)=>{a?.signal?.throwIfAborted(),s instanceof Uint8Array?await e.push(s,a):await e.push(s.subarray(),a)},unwrap:()=>{if(i.byteLength>0){let s=r.source;r.source=async function*(){t?.yieldBytes===!1?yield i:yield*i,yield*s}()}return r}}}var jt=class extends Error{code;constructor(t,e){super(t),this.code=e}};function Hr(r,t={}){let e=Zr(r,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=D(t.maxDataLength));let n=t?.lengthDecoder??X,i=t?.lengthEncoder??Y;return{read:async s=>{let a=-1,c=new Q;for(;;){c.append(await e.read(1,s));try{a=n(c)}catch(h){if(h instanceof RangeError)continue;throw h}if(t?.maxLengthLength!=null&&c.byteLength>t.maxLengthLength)throw new jt("message length length too long","ERR_MSG_LENGTH_TOO_LONG");if(a>-1)break}if(t?.maxDataLength!=null&&a>t.maxDataLength)throw new jt("message length too long","ERR_MSG_DATA_TOO_LONG");return e.read(a,s)},write:async(s,a)=>{await e.write(new Q(i(s.byteLength),s),a)},writeV:async(s,a)=>{let c=new Q(...s.flatMap(h=>[i(h.byteLength),h]));await e.write(c,a)},unwrap:()=>e.unwrap()}}function ze(r,t){let e=Hr(r,t),n={read:async(i,o)=>{let s=await e.read(o);return i.decode(s)},write:async(i,o,s)=>{await e.write(o.encode(i),s)},writeV:async(i,o,s)=>{await e.writeV(i.map(a=>o.encode(a)),s)},pb:i=>({read:async o=>n.read(i,o),write:async(o,s)=>n.write(o,i,s),writeV:async(o,s)=>n.writeV(o,i,s),unwrap:()=>n}),unwrap:()=>e.unwrap()};return n}var $e=new Float32Array([-0]),tt=new Uint8Array($e.buffer);function Yr(r,t,e){$e[0]=r,t[e]=tt[0],t[e+1]=tt[1],t[e+2]=tt[2],t[e+3]=tt[3]}function tn(r,t){return tt[0]=r[t],tt[1]=r[t+1],tt[2]=r[t+2],tt[3]=r[t+3],$e[0]}var je=new Float64Array([-0]),S=new Uint8Array(je.buffer);function en(r,t,e){je[0]=r,t[e]=S[0],t[e+1]=S[1],t[e+2]=S[2],t[e+3]=S[3],t[e+4]=S[4],t[e+5]=S[5],t[e+6]=S[6],t[e+7]=S[7]}function rn(r,t){return S[0]=r[t],S[1]=r[t+1],S[2]=r[t+2],S[3]=r[t+3],S[4]=r[t+4],S[5]=r[t+5],S[6]=r[t+6],S[7]=r[t+7],je[0]}var wo=BigInt(Number.MAX_SAFE_INTEGER),bo=BigInt(Number.MIN_SAFE_INTEGER),F=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 it;if(t<wo&&t>bo)return this.fromNumber(Number(t));let e=t<0n;e&&(t=-t);let n=t>>32n,i=t-(n<<32n);return e&&(n=~n|0n,i=~i|0n,++i>nn&&(i=0n,++n>nn&&(n=0n))),new r(Number(i),Number(n))}static fromNumber(t){if(t===0)return it;let e=t<0;e&&(t=-t);let n=t>>>0,i=(t-n)/4294967296>>>0;return e&&(i=~i>>>0,n=~n>>>0,++n>4294967295&&(n=0,++i>4294967295&&(i=0))),new r(n,i)}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):it}},it=new F(0,0);it.toBigInt=function(){return 0n};it.zzEncode=it.zzDecode=function(){return this};it.length=function(){return 1};var nn=4294967296n;function on(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 sn(r,t,e){if(e-t<1)return"";let i,o=[],s=0,a;for(;t<e;)a=r[t++],a<128?o[s++]=a:a>191&&a<224?o[s++]=(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,o[s++]=55296+(a>>10),o[s++]=56320+(a&1023)):o[s++]=(a&15)<<12|(r[t++]&63)<<6|r[t++]&63,s>8191&&((i??(i=[])).push(String.fromCharCode.apply(String,o)),s=0);return i!=null?(s>0&&i.push(String.fromCharCode.apply(String,o.slice(0,s))),i.join("")):String.fromCharCode.apply(String,o.slice(0,s))}function Ge(r,t,e){let n=e,i,o;for(let s=0;s<r.length;++s)i=r.charCodeAt(s),i<128?t[e++]=i:i<2048?(t[e++]=i>>6|192,t[e++]=i&63|128):(i&64512)===55296&&((o=r.charCodeAt(s+1))&64512)===56320?(i=65536+((i&1023)<<10)+(o&1023),++s,t[e++]=i>>18|240,t[e++]=i>>12&63|128,t[e++]=i>>6&63|128,t[e++]=i&63|128):(t[e++]=i>>12|224,t[e++]=i>>6&63|128,t[e++]=i&63|128);return e-n}function k(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function Gt(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var We=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=t,this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,k(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw k(this,4);return Gt(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw k(this,4);return Gt(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw k(this,4);let t=tn(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw k(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 k(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return sn(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw k(this,t);this.pos+=t}else do if(this.pos>=this.len)throw k(this);while(this.buf[this.pos++]&128);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 F(0,0),e=0;if(this.len-this.pos>4){for(;e<4;++e)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;e=0}else{for(;e<3;++e){if(this.pos>=this.len)throw k(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<e*7)>>>0,t}if(this.len-this.pos>4){for(;e<5;++e)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;e<5;++e){if(this.pos>=this.len)throw k(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw k(this,8);let t=Gt(this.buf,this.pos+=4),e=Gt(this.buf,this.pos+=4);return new F(t,e)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){return this.readLongVarint().toNumber(!0)}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 qe(r){return new We(r instanceof Uint8Array?r:r.subarray())}function Xe(r,t){let e=qe(r);return t.decode(e)}function Qe(r){let t=r??8192,e=t>>>1,n,i=t;return function(s){if(s<1||s>e)return v(s);i+s>t&&(n=v(t),i=0);let a=n.subarray(i,i+=s);return i&7&&(i=(i|7)+1),a}}var ot=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function Je(){}var Ze=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},xo=Qe();function yo(r){return globalThis.Buffer!=null?v(r):xo(r)}var vt=class{len;head;tail;states;constructor(){this.len=0,this.head=new ot(Je,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new ot(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new He((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(Et,10,F.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=F.fromBigInt(t);return this._push(Et,e.length(),e)}uint64Number(t){let e=F.fromNumber(t);return this._push(Et,e.length(),e)}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=F.fromBigInt(t).zzEncode();return this._push(Et,e.length(),e)}sint64Number(t){let e=F.fromNumber(t).zzEncode();return this._push(Et,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Ke,1,t?1:0)}fixed32(t){return this._push(St,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=F.fromBigInt(t);return this._push(St,4,e.lo)._push(St,4,e.hi)}fixed64Number(t){let e=F.fromNumber(t);return this._push(St,4,e.lo)._push(St,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(Yr,4,t)}double(t){return this._push(en,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(Ke,1,0):this.uint32(e)._push(Io,e,t)}string(t){let e=on(t);return e!==0?this.uint32(e)._push(Ge,e,t):this._push(Ke,1,0)}fork(){return this.states=new Ze(this),this.head=this.tail=new ot(Je,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 ot(Je,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=yo(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function Ke(r,t,e){t[e]=r&255}function Ao(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var He=class extends ot{next;constructor(t,e){super(Ao,t,e),this.next=void 0}};function Et(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 St(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 Io(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(vt.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(Eo,t,r),this},vt.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(So,t,r),this});function Eo(r,t,e){t.set(r,e)}function So(r,t,e){r.length<40?Ge(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(It(r),e)}function Ye(){return new vt}function tr(r,t){let e=Ye();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var gt;(function(r){r[r.VARINT=0]="VARINT",r[r.BIT64=1]="BIT64",r[r.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",r[r.START_GROUP=3]="START_GROUP",r[r.END_GROUP=4]="END_GROUP",r[r.BIT32=5]="BIT32"})(gt||(gt={}));function Wt(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function er(r){function t(i){if(r[i.toString()]==null)throw new Error("Invalid enum value");return r[i]}let e=function(o,s){let a=t(o);s.int32(a)},n=function(o){let s=o.int32();return t(s)};return Wt("enum",gt.VARINT,e,n)}function rr(r,t){return Wt("message",gt.LENGTH_DELIMITED,r,t)}var M;(function(r){let t;(function(i){i.UNUSED="UNUSED",i.CONNECT="CONNECT",i.SYNC="SYNC"})(t=r.Type||(r.Type={}));let e;(function(i){i[i.UNUSED=0]="UNUSED",i[i.CONNECT=100]="CONNECT",i[i.SYNC=300]="SYNC"})(e||(e={})),function(i){i.codec=()=>er(e)}(t=r.Type||(r.Type={}));let n;r.codec=()=>(n==null&&(n=rr((i,o,s={})=>{if(s.lengthDelimited!==!1&&o.fork(),i.type!=null&&(o.uint32(8),r.Type.codec().encode(i.type,o)),i.observedAddresses!=null)for(let a of i.observedAddresses)o.uint32(18),o.bytes(a);s.lengthDelimited!==!1&&o.ldelim()},(i,o)=>{let s={observedAddresses:[]},a=o==null?i.len:i.pos+o;for(;i.pos<a;){let c=i.uint32();switch(c>>>3){case 1:s.type=r.Type.codec().decode(i);break;case 2:s.observedAddresses.push(i.bytes());break;default:i.skipType(c&7);break}}return s})),n),r.encode=i=>tr(i,r.codec()),r.decode=i=>Xe(i,r.codec())})(M||(M={}));var hn=Tn(cn(),1),vo=["0.0.0.0/8","10.0.0.0/8","100.64.0.0/10","127.0.0.0/8","169.254.0.0/16","172.16.0.0/12","192.0.0.0/24","192.0.0.0/29","192.0.0.8/32","192.0.0.9/32","192.0.0.10/32","192.0.0.170/32","192.0.0.171/32","192.0.2.0/24","192.31.196.0/24","192.52.193.0/24","192.88.99.0/24","192.168.0.0/16","192.175.48.0/24","198.18.0.0/15","198.51.100.0/24","203.0.113.0/24","240.0.0.0/4","255.255.255.255/32"],No=vo.map(r=>new hn.Netmask(r));function Fo(r){for(let t of No)if(t.contains(r))return!0;return!1}function Lo(r){return/^::$/.test(r)||/^::1$/.test(r)||/^::f{4}:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(r)||/^::f{4}:0.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(r)||/^64:ff9b::([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(r)||/^100::([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2001::([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2001:2[0-9a-fA-F]:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2001:db8:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2002:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^f[c-d]([0-9a-fA-F]{2,2}):/i.test(r)||/^fe[8-9a-bA-B][0-9a-fA-F]:/i.test(r)||/^ff([0-9a-fA-F]{2,2}):/i.test(r)}function un(r){return lt(r)?Fo(r):dt(r)?Lo(r):void 0}var Uo=r=>r.toString().split("/").slice(1),Ft=r=>({match:t=>t.length<1?!1:r(t[0])?t.slice(1):!1,pattern:"fn"}),b=r=>({match:t=>Ft(e=>e===r).match(t),pattern:r}),Qt=()=>({match:r=>Ft(t=>typeof t=="string").match(r),pattern:"{string}"}),fn=()=>({match:r=>Ft(t=>!isNaN(parseInt(t))).match(r),pattern:"{number}"}),C=()=>({match:r=>{if(r.length<2||r[0]!=="p2p"&&r[0]!=="ipfs")return!1;if(r[1].startsWith("Q")||r[1].startsWith("1"))try{I.decode(`z${r[1]}`)}catch{return!1}else return!1;return r.slice(2)},pattern:"/p2p/{peerid}"}),qt=()=>({match:r=>{if(r.length<2||r[0]!=="certhash")return!1;try{le.decode(r[1])}catch{return!1}return r.slice(2)},pattern:"/certhash/{certhash}"}),z=r=>({match:t=>{let e=r.match(t);return e===!1?t:e},pattern:`optional(${r.pattern})`}),$=(...r)=>({match:t=>{let e;for(let n of r){let i=n.match(t);i!==!1&&(e==null||i.length<e.length)&&(e=i)}return e??!1},pattern:`or(${r.map(t=>t.pattern).join(", ")})`}),x=(...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 y(...r){function t(i){let o=Uo(i);for(let s of r){let a=s.match(o);if(a===!1)return!1;o=a}return o}function e(i){return t(i)!==!1}function n(i){let o=t(i);return o===!1?!1:o.length===0}return{matches:e,exactMatch:n}}var ir=x(b("dns4"),Qt()),or=x(b("dns6"),Qt()),sr=x(b("dnsaddr"),Qt()),ln=x(b("dns"),Qt()),hh=y(ir),uh=y(or),fh=y(sr),dn=y($(ln,sr,ir,or)),pn=x(b("ip4"),Ft(lt)),mn=x(b("ip6"),Ft(dt)),gn=$(pn,mn),Lt=$(gn,ln,ir,or,sr),lh=y(Lt),dh=y(pn),ph=y(mn),wn=y(gn),Jt=x(Lt,b("tcp"),fn()),Ut=x(Lt,b("udp"),fn()),Do=$(Jt,Ut),mh=y(Jt),gh=y(Ut),ar=x(Ut,b("quic")),Kt=x(Ut,b("quic-v1")),To=$(ar,Kt),wh=y(ar),bh=y(Kt),nr=$(Lt,Jt,Ut,ar,Kt),bn=$(x(nr,b("ws"),z(C()))),xh=y(bn),xn=$(x(nr,b("wss"),z(C())),x(nr,b("tls"),b("ws"),z(C()))),yh=y(xn),yn=x(Do,b("webrtc-direct"),qt(),z(qt()),z(C())),Ah=y(yn),An=x(Kt,b("webtransport"),qt(),qt(),z(C())),Ih=y(An),Xt=$(bn,xn,x(Jt,z(C())),x(To,z(C())),x(Lt,z(C())),yn,An,C()),Eh=y(Xt),Co=x(Xt,b("p2p-circuit"),C()),In=y(Co),Po=$(x(Xt,b("p2p-circuit"),b("webrtc"),C()),x(Xt,b("webrtc"),z(C())),b("webrtc")),Sh=y(Po);function cr(r,t){return In.matches(r)||t.transportForMultiaddr(r)==null?!1:dn.matches(r)?!0:wn.matches(r)?un(r.toOptions().host)===!1:!1}var En=1024*4,Sn=100,Zt={timeout:5e3,retries:3,maxInboundStreams:1,maxOutboundStreams:1},Ht=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??Zt.timeout,this.retries=e.retries??Zt.retries,this.maxInboundStreams=e.maxInboundStreams??Zt.maxInboundStreams,this.maxOutboundStreams=e.maxOutboundStreams??Zt.maxOutboundStreams}isStarted(){return this.started}async start(){this.started||(this.topologyId=await this.registrar.register(wt,{notifyOnTransient:!0,onConnect:(t,e)=>{e.transient&&e.direction==="inbound"&&this.upgradeInbound(e).catch(n=>{this.log.error("error during outgoing DCUtR attempt",n)})}}),await this.registrar.handle(wt,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,runOnTransientConnection:!0}),this.started=!0)}async stop(){await this.registrar.unhandle(wt),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 i={signal:AbortSignal.timeout(this.timeout)};try{e=await t.newStream([wt],{signal:i.signal,runOnTransientConnection:!0});let o=ze(e,{maxDataLength:En}).pb(M);this.log("B sending connect to %p",t.remotePeer);let s=Date.now();await o.write({type:M.Type.CONNECT,observedAddresses:this.addressManager.getAddresses().map(u=>u.bytes)},i),this.log("B receiving connect from %p",t.remotePeer);let a=await o.read(i);if(a.type!==M.Type.CONNECT)throw this.log("A sent wrong message type"),new B("DCUtR message type was incorrect",rt);let c=this.getDialableMultiaddrs(a.observedAddresses);if(c.length===0)throw this.log("A did not have any dialable multiaddrs"),new B("DCUtR connect message had no multiaddrs",rt);let h=Date.now()-s;this.log("A sending sync, rtt %dms",h),await o.write({type:M.Type.SYNC,observedAddresses:[]},i),this.log("A waiting for half RTT"),await qr(h/2),this.log("B dialing",c);let f=await this.connectionManager.openConnection(c,{signal:i.signal,priority:Sn});this.log("DCUtR to %p succeeded to address %a, closing relayed connection",t.remotePeer,f.remoteAddr),await t.close(i);break}catch(o){if(this.log.error("error while attempting DCUtR on attempt %d of %d",n+1,this.retries,o),e?.abort(o),n===this.retries)throw o}finally{e!=null&&await e.close(i)}}}async attemptUnilateralConnectionUpgrade(t){let n=(await this.peerStore.get(t.remotePeer)).addresses.map(i=>{let o=i.multiaddr;return o.getPeerId()==null?o.encapsulate(`/p2p/${t.remotePeer}`):o}).filter(i=>cr(i,this.transportManager));if(n.length>0){let i=AbortSignal.timeout(this.timeout);try{this.log("attempting unilateral connection upgrade to %a",n);let o=await this.connectionManager.openConnection(n,{signal:i,force:!0});if(o.transient)throw new Error("Could not open a new, non-transient, connection");return this.log("unilateral connection upgrade to %p succeeded via %a, closing relayed connection",t.remotePeer,o.remoteAddr),await t.close({signal:i}),!0}catch(o){this.log.error("unilateral connection upgrade to %p on addresses %a failed",t.remotePeer,n,o)}}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 i=ze(t,{maxDataLength:En}).pb(M);this.log("A receiving connect");let o=await i.read(n);if(o.type!==M.Type.CONNECT)throw this.log("B sent wrong message type"),new B("DCUtR message type was incorrect",rt);if(o.observedAddresses.length===0)throw this.log("B sent no multiaddrs"),new B("DCUtR connect message had no multiaddrs",rt);let s=this.getDialableMultiaddrs(o.observedAddresses);if(s.length===0)throw this.log("B had no dialable multiaddrs"),new B("DCUtR connect message had no dialable multiaddrs",rt);if(this.log("A sending connect"),await i.write({type:M.Type.CONNECT,observedAddresses:this.addressManager.getAddresses().map(h=>h.bytes)}),this.log("A receiving sync"),(await i.read(n)).type!==M.Type.SYNC)throw new B("DCUtR message type was incorrect",rt);this.log("A dialing",s);let c=await this.connectionManager.openConnection(s,{signal:n.signal,priority:Sn,force:!0});this.log("DCUtR to %p succeeded via %a, closing relayed connection",e.remotePeer,c.remoteAddr),await e.close(n)}catch(i){this.log.error("incoming DCUtR from %p failed",e.remotePeer,i),t.abort(i)}finally{await t.close(n)}}getDialableMultiaddrs(t){let e=[];for(let n of t)if(!(n==null||n.length===0))try{let i=Ve(n);if(!cr(i,this.transportManager))continue;e.push(i)}catch{}return e}};var wt="/libp2p/dcutr";function Ro(r={}){return t=>new Ht(t,r)}return Cn(Bo);})();
14
3
  return Libp2PDcutr}));
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAGxD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAA;AAElE;;;GAGG;AACH,wBAAgB,mBAAmB,CAAE,EAAE,EAAE,SAAS,EAAE,gBAAgB,EAAE,gBAAgB,GAAG,OAAO,CAuB/F"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAExD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAA;AAElE;;;GAGG;AACH,wBAAgB,mBAAmB,CAAE,EAAE,EAAE,SAAS,EAAE,gBAAgB,EAAE,gBAAgB,GAAG,OAAO,CAuB/F"}
package/dist/src/utils.js CHANGED
@@ -1,6 +1,6 @@
1
+ import { isPrivateIp } from '@libp2p/utils/private-ip';
1
2
  import {} from '@multiformats/multiaddr';
2
3
  import { Circuit, IP, DNS } from '@multiformats/multiaddr-matcher';
3
- import isPrivate from 'private-ip';
4
4
  /**
5
5
  * Returns true if the passed multiaddr is public, not relayed and we have a
6
6
  * transport that can dial it
@@ -22,6 +22,6 @@ export function isPublicAndDialable(ma, transportManager) {
22
22
  if (!IP.matches(ma)) {
23
23
  return false;
24
24
  }
25
- return isPrivate(ma.toOptions().host) === false;
25
+ return isPrivateIp(ma.toOptions().host) === false;
26
26
  }
27
27
  //# sourceMappingURL=utils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,MAAM,yBAAyB,CAAA;AACxD,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,GAAG,EAAE,MAAM,iCAAiC,CAAA;AAClE,OAAO,SAAS,MAAM,YAAY,CAAA;AAGlC;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CAAE,EAAa,EAAE,gBAAkC;IACpF,uBAAuB;IACvB,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE,CAAC;QACxB,OAAO,KAAK,CAAA;IACd,CAAC;IAED,MAAM,SAAS,GAAG,gBAAgB,CAAC,qBAAqB,CAAC,EAAE,CAAC,CAAA;IAE5D,IAAI,SAAS,IAAI,IAAI,EAAE,CAAC;QACtB,OAAO,KAAK,CAAA;IACd,CAAC;IAED,qCAAqC;IACrC,IAAI,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE,CAAC;QACpB,OAAO,IAAI,CAAA;IACb,CAAC;IAED,0CAA0C;IAC1C,IAAI,CAAC,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE,CAAC;QACpB,OAAO,KAAK,CAAA;IACd,CAAC;IAED,OAAO,SAAS,CAAC,EAAE,CAAC,SAAS,EAAE,CAAC,IAAI,CAAC,KAAK,KAAK,CAAA;AACjD,CAAC"}
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAA;AACtD,OAAO,EAAkB,MAAM,yBAAyB,CAAA;AACxD,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,GAAG,EAAE,MAAM,iCAAiC,CAAA;AAGlE;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CAAE,EAAa,EAAE,gBAAkC;IACpF,uBAAuB;IACvB,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE,CAAC;QACxB,OAAO,KAAK,CAAA;IACd,CAAC;IAED,MAAM,SAAS,GAAG,gBAAgB,CAAC,qBAAqB,CAAC,EAAE,CAAC,CAAA;IAE5D,IAAI,SAAS,IAAI,IAAI,EAAE,CAAC;QACtB,OAAO,KAAK,CAAA;IACd,CAAC;IAED,qCAAqC;IACrC,IAAI,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE,CAAC;QACpB,OAAO,IAAI,CAAA;IACb,CAAC;IAED,0CAA0C;IAC1C,IAAI,CAAC,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE,CAAC;QACpB,OAAO,KAAK,CAAA;IACd,CAAC;IAED,OAAO,WAAW,CAAC,EAAE,CAAC,SAAS,EAAE,CAAC,IAAI,CAAC,KAAK,KAAK,CAAA;AACnD,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@libp2p/dcutr",
3
- "version": "1.0.9-3e47d88fd",
3
+ "version": "1.0.9-72f0e09f7",
4
4
  "description": "Implementation of the DCUtR Protocol",
5
5
  "license": "Apache-2.0 OR MIT",
6
6
  "homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/protocol-dcutr#readme",
@@ -51,13 +51,13 @@
51
51
  "dep-check": "aegir dep-check"
52
52
  },
53
53
  "dependencies": {
54
- "@libp2p/interface": "1.1.2-3e47d88fd",
55
- "@libp2p/interface-internal": "1.0.7-3e47d88fd",
54
+ "@libp2p/interface": "1.1.2-72f0e09f7",
55
+ "@libp2p/interface-internal": "1.0.7-72f0e09f7",
56
+ "@libp2p/utils": "5.2.2-72f0e09f7",
56
57
  "@multiformats/multiaddr": "^12.1.10",
57
58
  "@multiformats/multiaddr-matcher": "^1.1.0",
58
59
  "delay": "^6.0.0",
59
60
  "it-protobuf-stream": "^1.1.1",
60
- "private-ip": "^3.0.1",
61
61
  "protons-runtime": "^5.0.0",
62
62
  "uint8arraylist": "^2.4.7"
63
63
  },
package/src/utils.ts CHANGED
@@ -1,6 +1,6 @@
1
+ import { isPrivateIp } from '@libp2p/utils/private-ip'
1
2
  import { type Multiaddr } from '@multiformats/multiaddr'
2
3
  import { Circuit, IP, DNS } from '@multiformats/multiaddr-matcher'
3
- import isPrivate from 'private-ip'
4
4
  import type { TransportManager } from '@libp2p/interface-internal'
5
5
 
6
6
  /**
@@ -29,5 +29,5 @@ export function isPublicAndDialable (ma: Multiaddr, transportManager: TransportM
29
29
  return false
30
30
  }
31
31
 
32
- return isPrivate(ma.toOptions().host) === false
32
+ return isPrivateIp(ma.toOptions().host) === false
33
33
  }