@libp2p/dcutr 0.0.0

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/LICENSE ADDED
@@ -0,0 +1,4 @@
1
+ This project is dual licensed under MIT and Apache-2.0.
2
+
3
+ MIT: https://www.opensource.org/licenses/mit
4
+ Apache-2.0: https://www.apache.org/licenses/license-2.0
package/README.md ADDED
@@ -0,0 +1,90 @@
1
+ [![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/)
2
+ [![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io)
3
+ [![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p)
4
+ [![CI](https://img.shields.io/github/actions/workflow/status/libp2p/js-libp2p/main.yml?branch=master\&style=flat-square)](https://github.com/libp2p/js-libp2p/actions/workflows/main.yml?query=branch%3Amaster)
5
+
6
+ > Implementation of the DCUtR Protocol
7
+
8
+ # About
9
+
10
+ Direct Connection Upgrade through Relay (DCUtR) is a protocol that allows two
11
+ nodes to connect to each other who would otherwise be prevented doing so due
12
+ to being behind NATed connections or firewalls.
13
+
14
+ The protocol involves making a relayed connection between the two peers and
15
+ using the relay to synchronise connection timings so that they dial each other
16
+ at precisely the same moment.
17
+
18
+ ## Example
19
+
20
+ ```ts
21
+ import { createLibp2p } from 'libp2p'
22
+ import { circuitRelayTransport } from 'libp2p/circuit-relay'
23
+ import { tcp } from '@libp2p/tcp'
24
+ import { identify } from '@libp2p/identify'
25
+ import { dcutr } from '@libp2p/dcutr'
26
+
27
+ const node = await createLibp2p({
28
+ transports: [
29
+ circuitRelayTransport(),
30
+ tcp()
31
+ ],
32
+ services: {
33
+ identify: identify(),
34
+ dcutr: dcutr()
35
+ }
36
+ })
37
+
38
+ // QmTarget is a peer that is behind a NAT, supports TCP and has a relay
39
+ // reservation
40
+ await node.dial('/ip4/.../p2p/QmRelay/p2p-circuit/p2p/QmTarget')
41
+
42
+ // after a while the connection should automatically get upgraded to a
43
+ // direct connection (e.g. non-transient)
44
+ while (true) {
45
+ const connections = node.getConnections()
46
+
47
+ if (connections.find(conn => conn.transient === false)) {
48
+ console.info('have direct connection')
49
+ break
50
+ } else {
51
+ console.info('have relayed connection')
52
+
53
+ // wait a few seconds to see if it's succeeded yet
54
+ await new Promise((resolve) => {
55
+ setTimeout(() => resolve(), 5000)
56
+ })
57
+ }
58
+ }
59
+ ```
60
+
61
+ # Install
62
+
63
+ ```console
64
+ $ npm i @libp2p/dcutr
65
+ ```
66
+
67
+ ## Browser `<script>` tag
68
+
69
+ Loading this module through a script tag will make it's exports available as `Libp2pDcutr` in the global namespace.
70
+
71
+ ```html
72
+ <script src="https://unpkg.com/@libp2p/dcutr/dist/index.min.js"></script>
73
+ ```
74
+
75
+ > Implementation of Autonat Protocol
76
+
77
+ # API Docs
78
+
79
+ - <https://libp2p.github.io/js-libp2p/modules/_libp2p_dcutr.html>
80
+
81
+ # License
82
+
83
+ Licensed under either of
84
+
85
+ - Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)
86
+ - MIT ([LICENSE-MIT](LICENSE-MIT) / <http://opensource.org/licenses/MIT>)
87
+
88
+ # Contribution
89
+
90
+ Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
@@ -0,0 +1,14 @@
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 po=Object.create;var Gt=Object.defineProperty;var mo=Object.getOwnPropertyDescriptor;var go=Object.getOwnPropertyNames;var wo=Object.getPrototypeOf,bo=Object.prototype.hasOwnProperty;var mt=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),O=(r,t)=>{for(var e in t)Gt(r,e,{get:t[e],enumerable:!0})},kr=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of go(t))!bo.call(r,o)&&o!==e&&Gt(r,o,{get:()=>t[o],enumerable:!(n=mo(t,o))||n.enumerable});return r};var Wt=(r,t,e)=>(e=r!=null?po(wo(r)):{},kr(t||!r||!r.__esModule?Gt(e,"default",{value:r,enumerable:!0}):e,r)),yo=r=>kr(Gt({},"__esModule",{value:!0}),r);var Mr=mt((Ws,$r)=>{var gt=1e3,wt=gt*60,bt=wt*60,ct=bt*24,xo=ct*7,Io=ct*365.25;$r.exports=function(r,t){t=t||{};var e=typeof r;if(e==="string"&&r.length>0)return Ao(r);if(e==="number"&&isFinite(r))return t.long?vo(r):Eo(r);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(r))};function Ao(r){if(r=String(r),!(r.length>100)){var t=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(r);if(t){var e=parseFloat(t[1]),n=(t[2]||"ms").toLowerCase();switch(n){case"years":case"year":case"yrs":case"yr":case"y":return e*Io;case"weeks":case"week":case"w":return e*xo;case"days":case"day":case"d":return e*ct;case"hours":case"hour":case"hrs":case"hr":case"h":return e*bt;case"minutes":case"minute":case"mins":case"min":case"m":return e*wt;case"seconds":case"second":case"secs":case"sec":case"s":return e*gt;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return e;default:return}}}}function Eo(r){var t=Math.abs(r);return t>=ct?Math.round(r/ct)+"d":t>=bt?Math.round(r/bt)+"h":t>=wt?Math.round(r/wt)+"m":t>=gt?Math.round(r/gt)+"s":r+"ms"}function vo(r){var t=Math.abs(r);return t>=ct?qt(r,t,ct,"day"):t>=bt?qt(r,t,bt,"hour"):t>=wt?qt(r,t,wt,"minute"):t>=gt?qt(r,t,gt,"second"):r+" ms"}function qt(r,t,e,n){var o=t>=e*1.5;return Math.round(r/e)+" "+n+(o?"s":"")}});var Or=mt((qs,Br)=>{function Co(r){e.debug=e,e.default=e,e.coerce=g,e.disable=i,e.enable=o,e.enabled=c,e.humanize=Mr(),e.destroy=p,Object.keys(r).forEach(l=>{e[l]=r[l]}),e.names=[],e.skips=[],e.formatters={};function t(l){let m=0;for(let d=0;d<l.length;d++)m=(m<<5)-m+l.charCodeAt(d),m|=0;return e.colors[Math.abs(m)%e.colors.length]}e.selectColor=t;function e(l){let m,d=null,s,a;function f(...u){if(!f.enabled)return;let w=f,b=Number(new Date),y=b-(m||b);w.diff=y,w.prev=m,w.curr=b,m=b,u[0]=e.coerce(u[0]),typeof u[0]!="string"&&u.unshift("%O");let v=0;u[0]=u[0].replace(/%([a-zA-Z%])/g,(N,B)=>{if(N==="%%")return"%";v++;let V=e.formatters[B];if(typeof V=="function"){let pt=u[v];N=V.call(w,pt),u.splice(v,1),v--}return N}),e.formatArgs.call(w,u),(w.log||e.log).apply(w,u)}return f.namespace=l,f.useColors=e.useColors(),f.color=e.selectColor(l),f.extend=n,f.destroy=e.destroy,Object.defineProperty(f,"enabled",{enumerable:!0,configurable:!1,get:()=>d!==null?d:(s!==e.namespaces&&(s=e.namespaces,a=e.enabled(l)),a),set:u=>{d=u}}),typeof e.init=="function"&&e.init(f),f}function n(l,m){let d=e(this.namespace+(typeof m>"u"?":":m)+l);return d.log=this.log,d}function o(l){e.save(l),e.namespaces=l,e.names=[],e.skips=[];let m,d=(typeof l=="string"?l:"").split(/[\s,]+/),s=d.length;for(m=0;m<s;m++)d[m]&&(l=d[m].replace(/\*/g,".*?"),l[0]==="-"?e.skips.push(new RegExp("^"+l.slice(1)+"$")):e.names.push(new RegExp("^"+l+"$")))}function i(){let l=[...e.names.map(h),...e.skips.map(h).map(m=>"-"+m)].join(",");return e.enable(""),l}function c(l){if(l[l.length-1]==="*")return!0;let m,d;for(m=0,d=e.skips.length;m<d;m++)if(e.skips[m].test(l))return!1;for(m=0,d=e.names.length;m<d;m++)if(e.names[m].test(l))return!0;return!1}function h(l){return l.toString().substring(2,l.toString().length-2).replace(/\.\*\?$/,"*")}function g(l){return l instanceof Error?l.stack||l.message:l}function p(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")}return e.enable(e.load()),e}Br.exports=Co});var zr=mt((z,Xt)=>{z.formatArgs=So;z.save=Lo;z.load=Po;z.useColors=Fo;z.storage=Do();z.destroy=(()=>{let r=!1;return()=>{r||(r=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})();z.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"];function Fo(){return typeof window<"u"&&window.process&&(window.process.type==="renderer"||window.process.__nwjs)?!0:typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)?!1:typeof document<"u"&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||typeof window<"u"&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)}function So(r){if(r[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+r[0]+(this.useColors?"%c ":" ")+"+"+Xt.exports.humanize(this.diff),!this.useColors)return;let t="color: "+this.color;r.splice(1,0,t,"color: inherit");let e=0,n=0;r[0].replace(/%[a-zA-Z%]/g,o=>{o!=="%%"&&(e++,o==="%c"&&(n=e))}),r.splice(n,0,t)}z.log=console.debug||console.log||(()=>{});function Lo(r){try{r?z.storage.setItem("debug",r):z.storage.removeItem("debug")}catch{}}function Po(){let r;try{r=z.storage.getItem("debug")}catch{}return!r&&typeof process<"u"&&"env"in process&&(r=process.env.DEBUG),r}function Do(){try{return localStorage}catch{}}Xt.exports=Or()(z);var{formatters:No}=Xt.exports;No.j=function(r){try{return JSON.stringify(r)}catch(t){return"[UnexpectedJSONParseError]: "+t.message}}});var Rn=mt((ku,Nn)=>{"use strict";function Dn(r,t){for(let e in t)Object.defineProperty(r,e,{value:t[e],enumerable:!0,configurable:!0});return r}function gs(r,t,e){if(!r||typeof r=="string")throw new TypeError("Please pass an Error to err-code");e||(e={}),typeof t=="object"&&(e=t,t=""),t&&(e.code=t);try{return Dn(r,e)}catch{e.message=r.message,e.stack=r.stack;let o=function(){};return o.prototype=Object.create(Object.getPrototypeOf(r)),Dn(new o,e)}}Nn.exports=gs});var eo=mt(jt=>{(function(){var r,t,e,n,o,i,c,h;h=function(g){var p,l,m,d;return p=(g&255<<24)>>>24,l=(g&255<<16)>>>16,m=(g&65280)>>>8,d=g&255,[p,l,m,d].join(".")},c=function(g){var p,l,m,d,s,a;for(p=[],m=d=0;d<=3&&g.length!==0;m=++d){if(m>0){if(g[0]!==".")throw new Error("Invalid IP");g=g.substring(1)}a=t(g),s=a[0],l=a[1],g=g.substring(l),p.push(s)}if(g.length!==0)throw new Error("Invalid IP");switch(p.length){case 1:if(p[0]>4294967295)throw new Error("Invalid IP");return p[0]>>>0;case 2:if(p[0]>255||p[1]>16777215)throw new Error("Invalid IP");return(p[0]<<24|p[1])>>>0;case 3:if(p[0]>255||p[1]>255||p[2]>65535)throw new Error("Invalid IP");return(p[0]<<24|p[1]<<16|p[2])>>>0;case 4:if(p[0]>255||p[1]>255||p[2]>255||p[3]>255)throw new Error("Invalid IP");return(p[0]<<24|p[1]<<16|p[2]<<8|p[3])>>>0;default:throw new Error("Invalid IP")}},e=function(g){return g.charCodeAt(0)},n=e("0"),i=e("a"),o=e("A"),t=function(g){var p,l,m,d,s;for(d=0,p=10,l="9",m=0,g.length>1&&g[m]==="0"&&(g[m+1]==="x"||g[m+1]==="X"?(m+=2,p=16):"0"<=g[m+1]&&g[m+1]<="9"&&(m++,p=8,l="7")),s=m;m<g.length;){if("0"<=g[m]&&g[m]<=l)d=d*p+(e(g[m])-n)>>>0;else if(p===16)if("a"<=g[m]&&g[m]<="f")d=d*p+(10+e(g[m])-i)>>>0;else if("A"<=g[m]&&g[m]<="F")d=d*p+(10+e(g[m])-o)>>>0;else break;else break;if(d>4294967295)throw new Error("too large");m++}if(m===s)throw new Error("empty octet");return[d,m]},r=function(){function g(p,l){var m,d,s,a;if(typeof p!="string")throw new Error("Missing `net' parameter");if(l||(a=p.split("/",2),p=a[0],l=a[1]),l||(l=32),typeof l=="string"&&l.indexOf(".")>-1){try{this.maskLong=c(l)}catch(f){throw m=f,new Error("Invalid mask: "+l)}for(d=s=32;s>=0;d=--s)if(this.maskLong===4294967295<<32-d>>>0){this.bitmask=d;break}}else if(l||l===0)this.bitmask=parseInt(l,10),this.maskLong=0,this.bitmask>0&&(this.maskLong=4294967295<<32-this.bitmask>>>0);else throw new Error("Invalid mask: empty");try{this.netLong=(c(p)&this.maskLong)>>>0}catch(f){throw m=f,new Error("Invalid net address: "+p)}if(!(this.bitmask<=32))throw new Error("Invalid mask for ip4: "+l);this.size=Math.pow(2,32-this.bitmask),this.base=h(this.netLong),this.mask=h(this.maskLong),this.hostmask=h(~this.maskLong),this.first=this.bitmask<=30?h(this.netLong+1):this.base,this.last=this.bitmask<=30?h(this.netLong+this.size-2):h(this.netLong+this.size-1),this.broadcast=this.bitmask<=30?h(this.netLong+this.size-1):void 0}return g.prototype.contains=function(p){return typeof p=="string"&&(p.indexOf("/")>0||p.split(".").length!==4)&&(p=new g(p)),p instanceof g?this.contains(p.base)&&this.contains(p.broadcast||p.last):(c(p)&this.maskLong)>>>0===(this.netLong&this.maskLong)>>>0},g.prototype.next=function(p){return p==null&&(p=1),new g(h(this.netLong+this.size*p),this.mask)},g.prototype.forEach=function(p){var l,m,d;for(d=c(this.first),m=c(this.last),l=0;d<=m;)p(h(d),d,l),l++,d++},g.prototype.toString=function(){return this.base+"/"+this.bitmask},g}(),jt.ip2long=c,jt.long2ip=h,jt.Netmask=r}).call(jt)});var io=mt((oo,ye)=>{(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"),o=new RegExp("^0x[a-f0-9]+$","i"),i="%[0-9a-z]{1,}",c="(?:[0-9a-f]+::?)+",h={zoneIndex:new RegExp(i,"i"),native:new RegExp(`^(::)?(${c})?([0-9a-f]+)?(::)?(${i})?$`,"i"),deprecatedTransitional:new RegExp(`^(?:::)(${t}\\.${t}\\.${t}\\.${t}(${i})?)$`,"i"),transitional:new RegExp(`^((?:${c})|(?:::)(?:${c})?)${t}\\.${t}\\.${t}\\.${t}(${i})?$`,"i")};function g(s,a){if(s.indexOf("::")!==s.lastIndexOf("::"))return null;let f=0,u=-1,w=(s.match(h.zoneIndex)||[])[0],b,y;for(w&&(w=w.substring(1),s=s.replace(/%.+$/,""));(u=s.indexOf(":",u+1))>=0;)f++;if(s.substr(0,2)==="::"&&f--,s.substr(-2,2)==="::"&&f--,f>a)return null;for(y=a-f,b=":";y--;)b+="0:";return s=s.replace("::",b),s[0]===":"&&(s=s.slice(1)),s[s.length-1]===":"&&(s=s.slice(0,-1)),a=function(){let v=s.split(":"),D=[];for(let N=0;N<v.length;N++)D.push(parseInt(v[N],16));return D}(),{parts:a,zoneId:w}}function p(s,a,f,u){if(s.length!==a.length)throw new Error("ipaddr: cannot match CIDR for objects with different lengths");let w=0,b;for(;u>0;){if(b=f-u,b<0&&(b=0),s[w]>>b!==a[w]>>b)return!1;u-=f,w+=1}return!0}function l(s){if(o.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 m(s,a){for(;s.length<a;)s=`0${s}`;return s}let d={};d.IPv4=function(){function s(a){if(a.length!==4)throw new Error("ipaddr: ipv4 octet count should be 4");let f,u;for(f=0;f<a.length;f++)if(u=a[f],!(0<=u&&u<=255))throw new Error("ipaddr: ipv4 octet should fit in 8 bits");this.octets=a}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(a,f){let u;if(f===void 0&&(u=a,a=u[0],f=u[1]),a.kind()!=="ipv4")throw new Error("ipaddr: cannot match ipv4 address with non-ipv4 one");return p(this.octets,a.octets,8,f)},s.prototype.prefixLengthFromSubnetMask=function(){let a=0,f=!1,u={0:8,128:7,192:6,224:5,240:4,248:3,252:2,254:1,255:0},w,b,y;for(w=3;w>=0;w-=1)if(b=this.octets[w],b in u){if(y=u[b],f&&y!==0)return null;y!==8&&(f=!0),a+=y}else return null;return 32-a},s.prototype.range=function(){return d.subnetMatch(this,this.SpecialRanges)},s.prototype.toByteArray=function(){return this.octets.slice(0)},s.prototype.toIPv4MappedAddress=function(){return d.IPv6.parse(`::ffff:${this.toString()}`)},s.prototype.toNormalizedString=function(){return this.toString()},s.prototype.toString=function(){return this.octets.join(".")},s}(),d.IPv4.broadcastAddressFromCIDR=function(s){try{let a=this.parseCIDR(s),f=a[0].toByteArray(),u=this.subnetMaskFromPrefixLength(a[1]).toByteArray(),w=[],b=0;for(;b<4;)w.push(parseInt(f[b],10)|parseInt(u[b],10)^255),b++;return new this(w)}catch{throw new Error("ipaddr: the address does not have IPv4 CIDR format")}},d.IPv4.isIPv4=function(s){return this.parser(s)!==null},d.IPv4.isValid=function(s){try{return new this(this.parser(s)),!0}catch{return!1}},d.IPv4.isValidFourPartDecimal=function(s){return!!(d.IPv4.isValid(s)&&s.match(/^(0|[1-9]\d*)(\.(0|[1-9]\d*)){3}$/))},d.IPv4.networkAddressFromCIDR=function(s){let a,f,u,w,b;try{for(a=this.parseCIDR(s),u=a[0].toByteArray(),b=this.subnetMaskFromPrefixLength(a[1]).toByteArray(),w=[],f=0;f<4;)w.push(parseInt(u[f],10)&parseInt(b[f],10)),f++;return new this(w)}catch{throw new Error("ipaddr: the address does not have IPv4 CIDR format")}},d.IPv4.parse=function(s){let a=this.parser(s);if(a===null)throw new Error("ipaddr: string is not formatted like an IPv4 Address");return new this(a)},d.IPv4.parseCIDR=function(s){let a;if(a=s.match(/^(.+)\/(\d+)$/)){let f=parseInt(a[2]);if(f>=0&&f<=32){let u=[this.parse(a[1]),f];return Object.defineProperty(u,"toString",{value:function(){return this.join("/")}}),u}}throw new Error("ipaddr: string is not formatted like an IPv4 CIDR range")},d.IPv4.parser=function(s){let a,f,u;if(a=s.match(e.fourOctet))return function(){let w=a.slice(1,6),b=[];for(let y=0;y<w.length;y++)f=w[y],b.push(l(f));return b}();if(a=s.match(e.longValue)){if(u=l(a[1]),u>4294967295||u<0)throw new Error("ipaddr: address outside defined range");return function(){let w=[],b;for(b=0;b<=24;b+=8)w.push(u>>b&255);return w}().reverse()}else return(a=s.match(e.twoOctet))?function(){let w=a.slice(1,4),b=[];if(u=l(w[1]),u>16777215||u<0)throw new Error("ipaddr: address outside defined range");return b.push(l(w[0])),b.push(u>>16&255),b.push(u>>8&255),b.push(u&255),b}():(a=s.match(e.threeOctet))?function(){let w=a.slice(1,5),b=[];if(u=l(w[2]),u>65535||u<0)throw new Error("ipaddr: address outside defined range");return b.push(l(w[0])),b.push(l(w[1])),b.push(u>>8&255),b.push(u&255),b}():null},d.IPv4.subnetMaskFromPrefixLength=function(s){if(s=parseInt(s),s<0||s>32)throw new Error("ipaddr: invalid IPv4 prefix length");let a=[0,0,0,0],f=0,u=Math.floor(s/8);for(;f<u;)a[f]=255,f++;return u<4&&(a[u]=Math.pow(2,s%8)-1<<8-s%8),new this(a)},d.IPv6=function(){function s(a,f){let u,w;if(a.length===16)for(this.parts=[],u=0;u<=14;u+=2)this.parts.push(a[u]<<8|a[u+1]);else if(a.length===8)this.parts=a;else throw new Error("ipaddr: ipv6 part count should be 8 or 16");for(u=0;u<this.parts.length;u++)if(w=this.parts[u],!(0<=w&&w<=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(a,f){let u;if(f===void 0&&(u=a,a=u[0],f=u[1]),a.kind()!=="ipv6")throw new Error("ipaddr: cannot match ipv6 address with non-ipv6 one");return p(this.parts,a.parts,16,f)},s.prototype.prefixLengthFromSubnetMask=function(){let a=0,f=!1,u={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},w,b;for(let y=7;y>=0;y-=1)if(w=this.parts[y],w in u){if(b=u[w],f&&b!==0)return null;b!==16&&(f=!0),a+=b}else return null;return 128-a},s.prototype.range=function(){return d.subnetMatch(this,this.SpecialRanges)},s.prototype.toByteArray=function(){let a,f=[],u=this.parts;for(let w=0;w<u.length;w++)a=u[w],f.push(a>>8),f.push(a&255);return f},s.prototype.toFixedLengthString=function(){let a=function(){let u=[];for(let w=0;w<this.parts.length;w++)u.push(m(this.parts[w].toString(16),4));return u}.call(this).join(":"),f="";return this.zoneId&&(f=`%${this.zoneId}`),a+f},s.prototype.toIPv4Address=function(){if(!this.isIPv4MappedAddress())throw new Error("ipaddr: trying to convert a generic ipv6 address to ipv4");let a=this.parts.slice(-2),f=a[0],u=a[1];return new d.IPv4([f>>8,f&255,u>>8,u&255])},s.prototype.toNormalizedString=function(){let a=function(){let u=[];for(let w=0;w<this.parts.length;w++)u.push(this.parts[w].toString(16));return u}.call(this).join(":"),f="";return this.zoneId&&(f=`%${this.zoneId}`),a+f},s.prototype.toRFC5952String=function(){let a=/((^|:)(0(:|$)){2,})/g,f=this.toNormalizedString(),u=0,w=-1,b;for(;b=a.exec(f);)b[0].length>w&&(u=b.index,w=b[0].length);return w<0?f:`${f.substring(0,u)}::${f.substring(u+w)}`},s.prototype.toString=function(){return this.toRFC5952String()},s}(),d.IPv6.broadcastAddressFromCIDR=function(s){try{let a=this.parseCIDR(s),f=a[0].toByteArray(),u=this.subnetMaskFromPrefixLength(a[1]).toByteArray(),w=[],b=0;for(;b<16;)w.push(parseInt(f[b],10)|parseInt(u[b],10)^255),b++;return new this(w)}catch(a){throw new Error(`ipaddr: the address does not have IPv6 CIDR format (${a})`)}},d.IPv6.isIPv6=function(s){return this.parser(s)!==null},d.IPv6.isValid=function(s){if(typeof s=="string"&&s.indexOf(":")===-1)return!1;try{let a=this.parser(s);return new this(a.parts,a.zoneId),!0}catch{return!1}},d.IPv6.networkAddressFromCIDR=function(s){let a,f,u,w,b;try{for(a=this.parseCIDR(s),u=a[0].toByteArray(),b=this.subnetMaskFromPrefixLength(a[1]).toByteArray(),w=[],f=0;f<16;)w.push(parseInt(u[f],10)&parseInt(b[f],10)),f++;return new this(w)}catch(y){throw new Error(`ipaddr: the address does not have IPv6 CIDR format (${y})`)}},d.IPv6.parse=function(s){let a=this.parser(s);if(a.parts===null)throw new Error("ipaddr: string is not formatted like an IPv6 Address");return new this(a.parts,a.zoneId)},d.IPv6.parseCIDR=function(s){let a,f,u;if((f=s.match(/^(.+)\/(\d+)$/))&&(a=parseInt(f[2]),a>=0&&a<=128))return u=[this.parse(f[1]),a],Object.defineProperty(u,"toString",{value:function(){return this.join("/")}}),u;throw new Error("ipaddr: string is not formatted like an IPv6 CIDR range")},d.IPv6.parser=function(s){let a,f,u,w,b,y;if(u=s.match(h.deprecatedTransitional))return this.parser(`::ffff:${u[1]}`);if(h.native.test(s))return g(s,8);if((u=s.match(h.transitional))&&(y=u[6]||"",a=g(u[1].slice(0,-1)+y,6),a.parts)){for(b=[parseInt(u[2]),parseInt(u[3]),parseInt(u[4]),parseInt(u[5])],f=0;f<b.length;f++)if(w=b[f],!(0<=w&&w<=255))return null;return a.parts.push(b[0]<<8|b[1]),a.parts.push(b[2]<<8|b[3]),{parts:a.parts,zoneId:a.zoneId}}return null},d.IPv6.subnetMaskFromPrefixLength=function(s){if(s=parseInt(s),s<0||s>128)throw new Error("ipaddr: invalid IPv6 prefix length");let a=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],f=0,u=Math.floor(s/8);for(;f<u;)a[f]=255,f++;return u<16&&(a[u]=Math.pow(2,s%8)-1<<8-s%8),new this(a)},d.fromByteArray=function(s){let a=s.length;if(a===4)return new d.IPv4(s);if(a===16)return new d.IPv6(s);throw new Error("ipaddr: the binary input is neither an IPv6 nor IPv4 address")},d.isValid=function(s){return d.IPv6.isValid(s)||d.IPv4.isValid(s)},d.parse=function(s){if(d.IPv6.isValid(s))return d.IPv6.parse(s);if(d.IPv4.isValid(s))return d.IPv4.parse(s);throw new Error("ipaddr: the address has neither IPv6 nor IPv4 format")},d.parseCIDR=function(s){try{return d.IPv6.parseCIDR(s)}catch{try{return d.IPv4.parseCIDR(s)}catch{throw new Error("ipaddr: the address has neither IPv6 nor IPv4 CIDR format")}}},d.process=function(s){let a=this.parse(s);return a.kind()==="ipv6"&&a.isIPv4MappedAddress()?a.toIPv4Address():a},d.subnetMatch=function(s,a,f){let u,w,b,y;f==null&&(f="unicast");for(w in a)if(Object.prototype.hasOwnProperty.call(a,w)){for(b=a[w],b[0]&&!(b[0]instanceof Array)&&(b=[b]),u=0;u<b.length;u++)if(y=b[u],s.kind()===y[0].kind()&&s.match.apply(s,y))return w}return f},typeof ye<"u"&&ye.exports?ye.exports=d:r.ipaddr=d})(oo)});var Vs={};O(Vs,{dcutrService:()=>_s,multicodec:()=>Dt});var W=class extends Error{code;props;constructor(t,e,n){super(t),this.code=e,this.name=n?.name??"CodeError",this.props=n??{}}};var at="ERR_INVALID_MESSAGE";var _=Wt(zr(),1);var Fe={};O(Fe,{base32:()=>q,base32hex:()=>zo,base32hexpad:()=>Vo,base32hexpadupper:()=>jo,base32hexupper:()=>_o,base32pad:()=>Bo,base32padupper:()=>Oo,base32upper:()=>Mo,base32z:()=>Go});function Ro(r,t){if(r.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),n=0;n<e.length;n++)e[n]=255;for(var o=0;o<r.length;o++){var i=r.charAt(o),c=i.charCodeAt(0);if(e[c]!==255)throw new TypeError(i+" is ambiguous");e[c]=o}var h=r.length,g=r.charAt(0),p=Math.log(h)/Math.log(256),l=Math.log(256)/Math.log(h);function m(a){if(a instanceof Uint8Array||(ArrayBuffer.isView(a)?a=new Uint8Array(a.buffer,a.byteOffset,a.byteLength):Array.isArray(a)&&(a=Uint8Array.from(a))),!(a instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(a.length===0)return"";for(var f=0,u=0,w=0,b=a.length;w!==b&&a[w]===0;)w++,f++;for(var y=(b-w)*l+1>>>0,v=new Uint8Array(y);w!==b;){for(var D=a[w],N=0,B=y-1;(D!==0||N<u)&&B!==-1;B--,N++)D+=256*v[B]>>>0,v[B]=D%h>>>0,D=D/h>>>0;if(D!==0)throw new Error("Non-zero carry");u=N,w++}for(var V=y-u;V!==y&&v[V]===0;)V++;for(var pt=g.repeat(f);V<y;++V)pt+=r.charAt(v[V]);return pt}function d(a){if(typeof a!="string")throw new TypeError("Expected String");if(a.length===0)return new Uint8Array;var f=0;if(a[f]!==" "){for(var u=0,w=0;a[f]===g;)u++,f++;for(var b=(a.length-f)*p+1>>>0,y=new Uint8Array(b);a[f];){var v=e[a.charCodeAt(f)];if(v===255)return;for(var D=0,N=b-1;(v!==0||D<w)&&N!==-1;N--,D++)v+=h*y[N]>>>0,y[N]=v%256>>>0,v=v/256>>>0;if(v!==0)throw new Error("Non-zero carry");w=D,f++}if(a[f]!==" "){for(var B=b-w;B!==b&&y[B]===0;)B++;for(var V=new Uint8Array(u+(b-B)),pt=u;B!==b;)V[pt++]=y[B++];return V}}}function s(a){var f=d(a);if(f)return f;throw new Error(`Non-${t} character`)}return{encode:m,decodeUnsafe:d,decode:s}}var To=Ro,Uo=To,_r=Uo;var Js=new Uint8Array(0);var Vr=(r,t)=>{if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0},tt=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")};var jr=r=>new TextEncoder().encode(r),Gr=r=>new TextDecoder().decode(r);var Ae=class{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")}},Ee=class{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 qr(this,t)}},ve=class{constructor(t){this.decoders=t}or(t){return qr(this,t)}decode(t){let e=t[0],n=this.decoders[e];if(n)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}},qr=(r,t)=>new ve({...r.decoders||{[r.prefix]:r},...t.decoders||{[t.prefix]:t}}),Ce=class{constructor(t,e,n,o){this.name=t,this.prefix=e,this.baseEncode=n,this.baseDecode=o,this.encoder=new Ae(t,e,n),this.decoder=new Ee(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}},yt=({name:r,prefix:t,encode:e,decode:n})=>new Ce(r,t,e,n),rt=({prefix:r,name:t,alphabet:e})=>{let{encode:n,decode:o}=_r(e,t);return yt({prefix:r,name:t,encode:n,decode:i=>tt(o(i))})},ko=(r,t,e,n)=>{let o={};for(let l=0;l<t.length;++l)o[t[l]]=l;let i=r.length;for(;r[i-1]==="=";)--i;let c=new Uint8Array(i*e/8|0),h=0,g=0,p=0;for(let l=0;l<i;++l){let m=o[r[l]];if(m===void 0)throw new SyntaxError(`Non-${n} character`);g=g<<e|m,h+=e,h>=8&&(h-=8,c[p++]=255&g>>h)}if(h>=e||255&g<<8-h)throw new SyntaxError("Unexpected end of data");return c},$o=(r,t,e)=>{let n=t[t.length-1]==="=",o=(1<<e)-1,i="",c=0,h=0;for(let g=0;g<r.length;++g)for(h=h<<8|r[g],c+=8;c>e;)c-=e,i+=t[o&h>>c];if(c&&(i+=t[o&h<<e-c]),n)for(;i.length*e&7;)i+="=";return i},E=({name:r,prefix:t,bitsPerChar:e,alphabet:n})=>yt({prefix:t,name:r,encode(o){return $o(o,n,e)},decode(o){return ko(o,n,e,r)}});var q=E({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Mo=E({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Bo=E({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Oo=E({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),zo=E({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),_o=E({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Vo=E({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),jo=E({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Go=E({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Se={};O(Se,{base58btc:()=>P,base58flickr:()=>Wo});var P=rt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Wo=rt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var De={};O(De,{base64:()=>Le,base64pad:()=>qo,base64url:()=>Pe,base64urlpad:()=>Xo});var Le=E({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),qo=E({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Pe=E({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Xo=E({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});_.default.formatters.b=r=>r==null?"undefined":P.baseEncode(r);_.default.formatters.t=r=>r==null?"undefined":q.baseEncode(r);_.default.formatters.m=r=>r==null?"undefined":Le.baseEncode(r);_.default.formatters.p=r=>r==null?"undefined":r.toString();_.default.formatters.c=r=>r==null?"undefined":r.toString();_.default.formatters.k=r=>r==null?"undefined":r.toString();_.default.formatters.a=r=>r==null?"undefined":r.toString();function Jo(r){let t=()=>{};return t.enabled=!1,t.color="",t.diff=0,t.log=()=>{},t.namespace=r,t.destroy=()=>!0,t.extend=()=>t,t}function Xr(r){let t=Jo(`${r}:trace`);return _.default.enabled(`${r}:trace`)&&_.default.names.map(e=>e.toString()).find(e=>e.includes(":trace"))!=null&&(t=(0,_.default)(`${r}:trace`)),Object.assign((0,_.default)(r),{error:(0,_.default)(`${r}:error`),trace:t})}var Ho=Qr,Jr=128,Qo=127,Zo=~Qo,Ko=Math.pow(2,31);function Qr(r,t,e){t=t||[],e=e||0;for(var n=e;r>=Ko;)t[e++]=r&255|Jr,r/=128;for(;r&Zo;)t[e++]=r&255|Jr,r>>>=7;return t[e]=r|0,Qr.bytes=e-n+1,t}var Yo=Ne,ti=128,Hr=127;function Ne(r,n){var e=0,n=n||0,o=0,i=n,c,h=r.length;do{if(i>=h)throw Ne.bytes=0,new RangeError("Could not decode varint");c=r[i++],e+=o<28?(c&Hr)<<o:(c&Hr)*Math.pow(2,o),o+=7}while(c>=ti);return Ne.bytes=i-n,e}var ei=Math.pow(2,7),ri=Math.pow(2,14),ni=Math.pow(2,21),oi=Math.pow(2,28),ii=Math.pow(2,35),si=Math.pow(2,42),ai=Math.pow(2,49),ci=Math.pow(2,56),ui=Math.pow(2,63),fi=function(r){return r<ei?1:r<ri?2:r<ni?3:r<oi?4:r<ii?5:r<si?6:r<ai?7:r<ci?8:r<ui?9:10},hi={encode:Ho,decode:Yo,encodingLength:fi},li=hi,Nt=li;var Rt=(r,t=0)=>[Nt.decode(r,t),Nt.decode.bytes],xt=(r,t,e=0)=>(Nt.encode(r,t,e),t),It=r=>Nt.encodingLength(r);var ut=(r,t)=>{let e=t.byteLength,n=It(r),o=n+It(e),i=new Uint8Array(o+e);return xt(r,i,0),xt(e,i,n),i.set(t,o),new At(r,e,t,i)},Ht=r=>{let t=tt(r),[e,n]=Rt(t),[o,i]=Rt(t.subarray(n)),c=t.subarray(n+i);if(c.byteLength!==o)throw new Error("Incorrect length");return new At(e,o,c,t)},Zr=(r,t)=>{if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&Vr(r.bytes,e.bytes)}},At=class{constructor(t,e,n,o){this.code=t,this.size=e,this.digest=n,this.bytes=o}};var Kr=(r,t)=>{let{bytes:e,version:n}=r;switch(n){case 0:return pi(e,Re(r),t||P.encoder);default:return mi(e,Re(r),t||q.encoder)}};var Yr=new WeakMap,Re=r=>{let t=Yr.get(r);if(t==null){let e=new Map;return Yr.set(r,e),e}return t},nt=class r{constructor(t,e,n,o){this.code=e,this.version=t,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:e}=this;if(t!==Tt)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==gi)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=ut(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&&t.code===n.code&&t.version===n.version&&Zr(t.multihash,n.multihash)}toString(t){return Kr(this,t)}toJSON(){return{"/":Kr(this)}}link(){return this}get[Symbol.toStringTag](){return"CID"}[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let e=t;if(e instanceof r)return e;if(e["/"]!=null&&e["/"]===e.bytes||e.asCID===e){let{version:n,code:o,multihash:i,bytes:c}=e;return new r(n,o,i,c||tn(n,o,i.bytes))}else if(e[wi]===!0){let{version:n,multihash:o,code:i}=e,c=Ht(o);return r.create(n,i,c)}else return null}static create(t,e,n){if(typeof e!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(e!==Tt)throw new Error(`Version 0 CID must use dag-pb (code: ${Tt}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=tn(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,Tt,t)}static createV1(t,e){return r.create(1,t,e)}static decode(t){let[e,n]=r.decodeFirst(t);if(n.length)throw new Error("Incorrect length");return e}static decodeFirst(t){let e=r.inspectBytes(t),n=e.size-e.multihashSize,o=tt(t.subarray(n,n+e.multihashSize));if(o.byteLength!==e.multihashSize)throw new Error("Incorrect length");let i=o.subarray(e.multihashSize-e.digestSize),c=new At(e.multihashCode,e.digestSize,i,o);return[e.version===0?r.createV0(c):r.createV1(e.codec,c),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[m,d]=Rt(t.subarray(e));return e+=d,m},o=n(),i=Tt;if(o===18?(o=0,e=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let c=e,h=n(),g=n(),p=e+g,l=p-c;return{version:o,codec:i,multihashCode:h,digestSize:g,multihashSize:l,size:p}}static parse(t,e){let[n,o]=di(t,e),i=r.decode(o);if(i.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Re(i).set(n,t),i}},di=(r,t)=>{switch(r[0]){case"Q":{let e=t||P;return[P.prefix,e.decode(`${P.prefix}${r}`)]}case P.prefix:{let e=t||P;return[P.prefix,e.decode(r)]}case q.prefix:{let e=t||q;return[q.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)]}}},pi=(r,t,e)=>{let{prefix:n}=e;if(n!==P.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let o=t.get(n);if(o==null){let i=e.encode(r).slice(1);return t.set(n,i),i}else return o},mi=(r,t,e)=>{let{prefix:n}=e,o=t.get(n);if(o==null){let i=e.encode(r);return t.set(n,i),i}else return o},Tt=112,gi=18,tn=(r,t,e)=>{let n=It(r),o=n+It(t),i=new Uint8Array(o+e.byteLength);return xt(r,i,0),xt(t,i,n),i.set(e,o),i},wi=Symbol.for("@ipld/js-cid/CID");function Qt(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}var Te={};O(Te,{base10:()=>bi});var bi=rt({prefix:"9",name:"base10",alphabet:"0123456789"});var Ue={};O(Ue,{base16:()=>yi,base16upper:()=>xi});var yi=E({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),xi=E({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var ke={};O(ke,{base2:()=>Ii});var Ii=E({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var $e={};O($e,{base256emoji:()=>Fi});var en=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}"),Ai=en.reduce((r,t,e)=>(r[e]=t,r),[]),Ei=en.reduce((r,t,e)=>(r[t.codePointAt(0)]=e,r),[]);function vi(r){return r.reduce((t,e)=>(t+=Ai[e],t),"")}function Ci(r){let t=[];for(let e of r){let n=Ei[e.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${e}`);t.push(n)}return new Uint8Array(t)}var Fi=yt({prefix:"\u{1F680}",name:"base256emoji",encode:vi,decode:Ci});var Me={};O(Me,{base36:()=>Si,base36upper:()=>Li});var Si=rt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Li=rt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Be={};O(Be,{base8:()=>Pi});var Pi=E({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Oe={};O(Oe,{identity:()=>Di});var Di=yt({prefix:"\0",name:"identity",encode:r=>Gr(r),decode:r=>jr(r)});var Ca=new TextEncoder,Fa=new TextDecoder;var ze={};O(ze,{identity:()=>ki});var rn=0,Ti="identity",nn=tt,Ui=r=>ut(rn,nn(r)),ki={code:rn,name:Ti,encode:nn,digest:Ui};var je={};O(je,{sha256:()=>$i,sha512:()=>Mi});var Ve=({name:r,code:t,encode:e})=>new _e(r,t,e),_e=class{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?ut(this.code,e):e.then(n=>ut(this.code,n))}else throw Error("Unknown type, must be binary type")}};var sn=r=>async t=>new Uint8Array(await crypto.subtle.digest(r,t)),$i=Ve({name:"sha2-256",code:18,encode:sn("SHA-256")}),Mi=Ve({name:"sha2-512",code:19,encode:sn("SHA-512")});var Ut={...Oe,...ke,...Be,...Te,...Ue,...Fe,...Me,...Se,...De,...$e},Ua={...je,...ze};function ft(r){return globalThis.Buffer!=null?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):r}function et(r=0){return globalThis.Buffer?.alloc!=null?ft(globalThis.Buffer.alloc(r)):new Uint8Array(r)}function R(r=0){return globalThis.Buffer?.allocUnsafe!=null?ft(globalThis.Buffer.allocUnsafe(r)):new Uint8Array(r)}function cn(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var an=cn("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Ge=cn("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}),Bi={utf8:an,"utf-8":an,hex:Ut.base16,latin1:Ge,ascii:Ge,binary:Ge,...Ut},Zt=Bi;function k(r,t="utf8"){let e=Zt[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 Oi=Math.pow(2,7),zi=Math.pow(2,14),_i=Math.pow(2,21),We=Math.pow(2,28),qe=Math.pow(2,35),Xe=Math.pow(2,42),Je=Math.pow(2,49),x=128,T=127;function $(r){if(r<Oi)return 1;if(r<zi)return 2;if(r<_i)return 3;if(r<We)return 4;if(r<qe)return 5;if(r<Xe)return 6;if(r<Je)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Vi(r,t,e=0){switch($(r)){case 8:t[e++]=r&255|x,r/=128;case 7:t[e++]=r&255|x,r/=128;case 6:t[e++]=r&255|x,r/=128;case 5:t[e++]=r&255|x,r/=128;case 4:t[e++]=r&255|x,r>>>=7;case 3:t[e++]=r&255|x,r>>>=7;case 2:t[e++]=r&255|x,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function ji(r,t,e=0){switch($(r)){case 8:t.set(e++,r&255|x),r/=128;case 7:t.set(e++,r&255|x),r/=128;case 6:t.set(e++,r&255|x),r/=128;case 5:t.set(e++,r&255|x),r/=128;case 4:t.set(e++,r&255|x),r>>>=7;case 3:t.set(e++,r&255|x),r>>>=7;case 2:t.set(e++,r&255|x),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function Gi(r,t){let e=r[t],n=0;if(n+=e&T,e<x||(e=r[t+1],n+=(e&T)<<7,e<x)||(e=r[t+2],n+=(e&T)<<14,e<x)||(e=r[t+3],n+=(e&T)<<21,e<x)||(e=r[t+4],n+=(e&T)*We,e<x)||(e=r[t+5],n+=(e&T)*qe,e<x)||(e=r[t+6],n+=(e&T)*Xe,e<x)||(e=r[t+7],n+=(e&T)*Je,e<x))return n;throw new RangeError("Could not decode varint")}function Wi(r,t){let e=r.get(t),n=0;if(n+=e&T,e<x||(e=r.get(t+1),n+=(e&T)<<7,e<x)||(e=r.get(t+2),n+=(e&T)<<14,e<x)||(e=r.get(t+3),n+=(e&T)<<21,e<x)||(e=r.get(t+4),n+=(e&T)*We,e<x)||(e=r.get(t+5),n+=(e&T)*qe,e<x)||(e=r.get(t+6),n+=(e&T)*Xe,e<x)||(e=r.get(t+7),n+=(e&T)*Je,e<x))return n;throw new RangeError("Could not decode varint")}function ot(r,t,e=0){return t==null&&(t=R($(r))),t instanceof Uint8Array?Vi(r,t,e):ji(r,t,e)}function X(r,t=0){return r instanceof Uint8Array?Gi(r,t):Wi(r,t)}function j(r,t){t==null&&(t=r.reduce((o,i)=>o+i.length,0));let e=R(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return ft(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,o){return this.readAtomically(()=>{let i=0,c=0,h=this.peekChar();if(h===void 0)return;let g=h==="0",p=2**(8*o)-1;for(;;){let l=this.readAtomically(()=>{let m=this.readChar();if(m===void 0)return;let d=Number.parseInt(m,t);if(!Number.isNaN(d))return d});if(l===void 0)break;if(i*=t,i+=l,i>p||(c+=1,e!==void 0&&c>e))return}if(c!==0)return!n&&g&&c>1?void 0:i})}readIPv4Addr(){return this.readAtomically(()=>{let t=new Uint8Array(4);for(let e=0;e<t.length;e++){let n=this.readSeparator(".",e,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;t[e]=n}return t})}readIPv6Addr(){let t=e=>{for(let n=0;n<e.length/2;n++){let o=n*2;if(n<e.length-3){let c=this.readSeparator(":",n,()=>this.readIPv4Addr());if(c!==void 0)return e[o]=c[0],e[o+1]=c[1],e[o+2]=c[2],e[o+3]=c[3],[o+4,!0]}let i=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(i===void 0)return[o,!1];e[o]=i>>8,e[o+1]=i&255}return[e.length,!1]};return this.readAtomically(()=>{let e=new Uint8Array(16),[n,o]=t(e);if(n===16)return e;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let i=new Uint8Array(14),c=16-(n+2),[h]=t(i.subarray(0,c));return e.set(i.subarray(0,h),16-h),e})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var un=45,qi=15,vt=new Kt;function He(r){if(!(r.length>qi))return vt.new(r).parseWith(()=>vt.readIPv4Addr())}function Qe(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>un))return vt.new(r).parseWith(()=>vt.readIPv6Addr())}function Yt(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>un))return vt.new(r).parseWith(()=>vt.readIPAddr())}var nc=parseInt("0xFFFF",16),oc=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function $t(r,t="utf8"){let e=Zt[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return(t==="utf8"||t==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?ft(globalThis.Buffer.from(r,"utf-8")):e.decoder.decode(`${e.prefix}${r}`)}function te(r){return!!He(r)}function ee(r){return!!Qe(r)}function Ct(r){return!!Yt(r)}var ln=te,Zi=ee,Ze=function(r){let t=0;if(r=r.toString().trim(),ln(r)){let e=new Uint8Array(t+4);return r.split(/\./g).forEach(n=>{e[t++]=parseInt(n,10)&255}),e}if(Zi(r)){let e=r.split(":",8),n;for(n=0;n<e.length;n++){let i=ln(e[n]),c;i&&(c=Ze(e[n]),e[n]=k(c.slice(0,2),"base16")),c!=null&&++n<8&&e.splice(n,0,k(c.slice(2,4),"base16"))}if(e[0]==="")for(;e.length<8;)e.unshift("0");else if(e[e.length-1]==="")for(;e.length<8;)e.push("0");else if(e.length<8){for(n=0;n<e.length&&e[n]!=="";n++);let i=[n,1];for(n=9-e.length;n>0;n--)i.push("0");e.splice.apply(e,i)}let o=new Uint8Array(t+16);for(n=0;n<e.length;n++){let i=parseInt(e[n],16);o[t++]=i>>8&255,o[t++]=i&255}return o}throw new Error("invalid ip address")},dn=function(r,t=0,e){t=~~t,e=e??r.length-t;let n=new DataView(r.buffer);if(e===4){let o=[];for(let i=0;i<e;i++)o.push(r[t+i]);return o.join(".")}if(e===16){let o=[];for(let i=0;i<e;i+=2)o.push(n.getUint16(t+i).toString(16));return o.join(":").replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}return""};var Ft={},Ke={},Yi=[[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"]];Yi.forEach(r=>{let t=ts(...r);Ke[t.code]=t,Ft[t.name]=t});function ts(r,t,e,n,o){return{code:r,size:t,name:e,resolvable:!!n,path:!!o}}function I(r){if(typeof r=="number"){if(Ke[r]!=null)return Ke[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(Ft[r]!=null)return Ft[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var Gc=I("ip4"),Wc=I("ip6"),qc=I("ipcidr");function tr(r,t){switch(I(r).code){case 4:case 41:return rs(t);case 42:return gn(t);case 6:case 273:case 33:case 132:return bn(t).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return gn(t);case 421:return ss(t);case 444:return wn(t);case 445:return wn(t);case 466:return is(t);default:return k(t,"base16")}}function er(r,t){switch(I(r).code){case 4:return pn(t);case 41:return pn(t);case 42:return mn(t);case 6:case 273:case 33:case 132:return rr(parseInt(t,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return mn(t);case 421:return ns(t);case 444:return as(t);case 445:return cs(t);case 466:return os(t);default:return $t(t,"base16")}}var Ye=Object.values(Ut).map(r=>r.decoder),es=function(){let r=Ye[0].or(Ye[1]);return Ye.slice(2).forEach(t=>r=r.or(t)),r}();function pn(r){if(!Ct(r))throw new Error("invalid ip address");return Ze(r)}function rs(r){let t=dn(r,0,r.length);if(t==null)throw new Error("ipBuff is required");if(!Ct(t))throw new Error("invalid ip address");return t}function rr(r){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,r),new Uint8Array(t)}function bn(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function mn(r){let t=$t(r),e=Uint8Array.from(ot(t.length));return j([e,t],e.length+t.length)}function gn(r){let t=X(r);if(r=r.slice($(t)),r.length!==t)throw new Error("inconsistent lengths");return k(r)}function ns(r){let t;r[0]==="Q"||r[0]==="1"?t=Ht(P.decode(`z${r}`)).bytes:t=nt.parse(r).multihash.bytes;let e=Uint8Array.from(ot(t.length));return j([e,t],e.length+t.length)}function os(r){let t=es.decode(r),e=Uint8Array.from(ot(t.length));return j([e,t],e.length+t.length)}function is(r){let t=X(r),e=r.slice($(t));if(e.length!==t)throw new Error("inconsistent lengths");return"u"+k(e,"base64url")}function ss(r){let t=X(r),e=r.slice($(t));if(e.length!==t)throw new Error("inconsistent lengths");return k(e,"base58btc")}function as(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=q.decode("b"+t[0]),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=rr(n);return j([e,o],e.length+o.length)}function cs(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=q.decode(`b${t[0]}`),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=rr(n);return j([e,o],e.length+o.length)}function wn(r){let t=r.slice(0,r.length-2),e=r.slice(r.length-2),n=k(t,"base32"),o=bn(e);return`${n}:${o}`}function yn(r){r=nr(r);let t=[],e=[],n=null,o=r.split("/").slice(1);if(o.length===1&&o[0]==="")return{bytes:new Uint8Array,string:"/",tuples:[],stringTuples:[],path:null};for(let i=0;i<o.length;i++){let c=o[i],h=I(c);if(h.size===0){t.push([h.code]),e.push([h.code]);continue}if(i++,i>=o.length)throw In("invalid address: "+r);if(h.path===!0){n=nr(o.slice(i).join("/")),t.push([h.code,er(h.code,n)]),e.push([h.code,n]);break}let g=er(h.code,o[i]);t.push([h.code,g]),e.push([h.code,tr(h.code,g)])}return{string:xn(e),bytes:ir(t),tuples:t,stringTuples:e,path:n}}function or(r){let t=[],e=[],n=null,o=0;for(;o<r.length;){let i=X(r,o),c=$(i),h=I(i),g=us(h,r.slice(o+c));if(g===0){t.push([i]),e.push([i]),o+=c;continue}let p=r.slice(o+c,o+c+g);if(o+=g+c,o>r.length)throw In("Invalid address Uint8Array: "+k(r,"base16"));t.push([i,p]);let l=tr(i,p);if(e.push([i,l]),h.path===!0){n=l;break}}return{bytes:Uint8Array.from(r),string:xn(e),tuples:t,stringTuples:e,path:n}}function xn(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}),nr(t.join("/"))}function ir(r){return j(r.map(t=>{let e=I(t[0]),n=Uint8Array.from(ot(e.code));return t.length>1&&t[1]!=null&&(n=j([n,t[1]])),n}))}function us(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+$(e)}}function nr(r){return"/"+r.trim().split("/").filter(t=>t).join("/")}function In(r){return new Error("Error parsing address: "+r)}var fs=Symbol.for("nodejs.util.inspect.custom"),sr=Symbol.for("@multiformats/js-multiaddr/multiaddr"),hs=[I("dns").code,I("dns4").code,I("dns6").code,I("dnsaddr").code],re=class r{bytes;#e;#t;#r;#n;[sr]=!0;constructor(t){t==null&&(t="");let e;if(t instanceof Uint8Array)e=or(t);else if(typeof t=="string"){if(t.length>0&&t.charAt(0)!=="/")throw new Error(`multiaddr "${t}" must start with a "/"`);e=yn(t)}else if(En(t))e=or(t.bytes);else throw new Error("addr must be a string, Buffer, or another Multiaddr");this.bytes=e.bytes,this.#e=e.string,this.#t=e.tuples,this.#r=e.stringTuples,this.#n=e.path}toString(){return this.#e}toJSON(){return this.toString()}toOptions(){let t,e,n,o,i="",c=I("tcp"),h=I("udp"),g=I("ip4"),p=I("ip6"),l=I("dns6"),m=I("ip6zone");for(let[s,a]of this.stringTuples())s===m.code&&(i=`%${a??""}`),hs.includes(s)&&(e=c.name,o=443,n=`${a??""}${i}`,t=s===l.code?6:4),(s===c.code||s===h.code)&&(e=I(s).name,o=parseInt(a??"")),(s===g.code||s===p.code)&&(e=I(s).name,n=`${a??""}${i}`,t=s===p.code?6:4);if(t==null||e==null||n==null||o==null)throw new Error('multiaddr must have a valid format: "/{ip4, ip6, dns4, dns6, dnsaddr}/{address}/{tcp, udp}/{port}".');return{family:t,host:n,transport:e,port:o}}protos(){return this.#t.map(([t])=>Object.assign({},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(),o=n.lastIndexOf(e);if(o<0)throw new Error(`Address ${this.toString()} does not contain subaddress: ${t.toString()}`);return new r(n.slice(0,o))}decapsulateCode(t){let e=this.tuples();for(let n=e.length-1;n>=0;n--)if(e[n][0]===t)return new r(ir(e.slice(0,n)));return this}getPeerId(){try{let t=[];this.stringTuples().forEach(([n,o])=>{n===Ft.p2p.code&&t.push([n,o]),n===Ft["p2p-circuit"].code&&(t=[])});let e=t.pop();if(e?.[1]!=null){let n=e[1];return n[0]==="Q"||n[0]==="1"?k(P.decode(`z${n}`),"base58btc"):k(nt.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){return this.#n}equals(t){return Qt(this.bytes,t.bytes)}async resolve(t){let e=this.protos().find(i=>i.resolvable);if(e==null)return[this];let n=An.get(e.name);if(n==null)throw new W(`no available resolver for ${e.name}`,"ERR_NO_AVAILABLE_RESOLVER");return(await n(this,t)).map(i=>new r(i))}nodeAddress(){let t=this.toOptions();if(t.transport!=="tcp"&&t.transport!=="udp")throw new Error(`multiaddr must have a valid format - no protocol with name: "${t.transport}". Must have a valid transport protocol: "{tcp, udp}"`);return{family:t.family,address:t.host,port:t.port}}isThinWaistAddress(t){let e=(t??this).protos();return!(e.length!==2||e[0].code!==4&&e[0].code!==41||e[1].code!==6&&e[1].code!==273)}[fs](){return`Multiaddr(${this.#e})`}};var An=new Map;function En(r){return!!r?.[sr]}function ar(r){return new re(r)}var vn=()=>{let r=new Error("Delay aborted");return r.name="AbortError",r},ls=new WeakMap;function ds({clearTimeout:r,setTimeout:t}={}){return(e,{value:n,signal:o}={})=>{if(o?.aborted)return Promise.reject(vn());let i,c,h,g=r??clearTimeout,p=()=>{g(i),h(vn())},l=()=>{o&&o.removeEventListener("abort",p)},m=new Promise((d,s)=>{c=()=>{l(),d(n)},h=s,i=(t??setTimeout)(c,e)});return o&&o.addEventListener("abort",p,{once:!0}),ls.set(m,()=>{g(i),i=null,c()}),m}}var ps=ds(),Cn=ps;function ne(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var oe=class{buffer;mask;top;btm;next;constructor(t){if(!(t>0)||t-1&t)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(t),this.mask=t-1,this.top=0,this.btm=0,this.next=null}push(t){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=t,this.top=this.top+1&this.mask,!0)}shift(){let t=this.buffer[this.btm];if(t!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,t}isEmpty(){return this.buffer[this.btm]===void 0}},St=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new oe(this.hwm),this.tail=this.head,this.size=0}calculateSize(t){return t?.byteLength!=null?t.byteLength:1}push(t){if(t?.value!=null&&(this.size+=this.calculateSize(t.value)),!this.head.push(t)){let e=this.head;this.head=e.next=new oe(2*this.head.buffer.length),this.head.push(t)}}shift(){let t=this.tail.shift();if(t===void 0&&this.tail.next!=null){let e=this.tail.next;this.tail.next=null,this.tail=e,t=this.tail.shift()}return t?.value!=null&&(this.size-=this.calculateSize(t.value)),t}isEmpty(){return this.head.isEmpty()}};var cr=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.code=e??"ABORT_ERR"}};function Fn(r={}){return ms(e=>{let n=e.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},r)}function ms(r,t){t=t??{};let e=t.onEnd,n=new St,o,i,c,h=ne(),g=async()=>{try{return n.isEmpty()?c?{done:!0}:await new Promise((u,w)=>{i=b=>{i=null,n.push(b);try{u(r(n))}catch(y){w(y)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{h.resolve(),h=ne()})}},p=u=>i!=null?i(u):(n.push(u),o),l=u=>(n=new St,i!=null?i({error:u}):(n.push({error:u}),o)),m=u=>{if(c)return o;if(t?.objectMode!==!0&&u?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return p({done:!1,value:u})},d=u=>c?o:(c=!0,u!=null?l(u):p({done:!0})),s=()=>(n=new St,d(),{done:!0}),a=u=>(d(u),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:g,return:s,throw:a,push:m,end:d,get readableLength(){return n.size},onEmpty:async u=>{let w=u?.signal;if(w?.throwIfAborted(),n.isEmpty())return;let b,y;w!=null&&(b=new Promise((v,D)=>{y=()=>{D(new cr)},w.addEventListener("abort",y)}));try{await Promise.race([h.promise,b])}finally{y!=null&&w!=null&&w?.removeEventListener("abort",y)}}},e==null)return o;let f=o;return o={[Symbol.asyncIterator](){return this},next(){return f.next()},throw(u){return f.throw(u),e!=null&&(e(u),e=void 0),{done:!0}},return(){return f.return(),e!=null&&(e(),e=void 0),{done:!0}},push:m,end(u){return f.end(u),e!=null&&(e(u),e=void 0),o},get readableLength(){return f.readableLength}},o}var Ln=Symbol.for("@achingbrain/uint8arraylist");function Sn(r,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let e=0;for(let n of r){let o=e+n.byteLength;if(t<o)return{buf:n,index:t-e};e=o}throw new RangeError("index is out of bounds")}function ie(r){return!!r?.[Ln]}var J=class r{constructor(...t){Object.defineProperty(this,Ln,{value:!0}),this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let e=0;for(let n of t)if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.push(n);else if(ie(n))e+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}prepend(...t){this.prependAll(t)}prependAll(t){let e=0;for(let n of t.reverse())if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.unshift(n);else if(ie(n))e+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}get(t){let e=Sn(this.bufs,t);return e.buf[e.index]}set(t,e){let n=Sn(this.bufs,t);n.buf[n.index]=e}write(t,e=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(e+n,t[n]);else if(ie(t))for(let n=0;n<t.length;n++)this.set(e+n,t.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,e){let{bufs:n,length:o}=this._subList(t,e);return j(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:j(n,o)}sublist(t,e){let{bufs:n,length:o}=this._subList(t,e),i=new r;return i.length=o,i.bufs=n,i}_subList(t,e){if(t=t??0,e=e??this.length,t<0&&(t=this.length+t),e<0&&(e=this.length+e),t<0||e>this.length)throw new RangeError("index is out of bounds");if(t===e)return{bufs:[],length:0};if(t===0&&e===this.length)return{bufs:[...this.bufs],length:this.length};let n=[],o=0;for(let i=0;i<this.bufs.length;i++){let c=this.bufs[i],h=o,g=h+c.byteLength;if(o=g,t>=g)continue;let p=t>=h&&t<g,l=e>h&&e<=g;if(p&&l){if(t===h&&e===g){n.push(c);break}let m=t-h;n.push(c.subarray(m,m+(e-t)));break}if(p){if(t===0){n.push(c);continue}n.push(c.subarray(t-h));continue}if(l){if(e===g){n.push(c);break}n.push(c.subarray(0,e-h));break}n.push(c)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!ie(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(e=Number(e??0),isNaN(e)&&(e=0),e<0&&(e=this.length+e),e<0&&(e=0),t.length===0)return e>this.length?this.length:e;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let i=256,c=new Int32Array(i);for(let m=0;m<i;m++)c[m]=-1;for(let m=0;m<o;m++)c[n[m]]=m;let h=c,g=this.byteLength-n.byteLength,p=n.byteLength-1,l;for(let m=e;m<=g;m+=l){l=0;for(let d=p;d>=0;d--){let s=this.get(m+d);if(n[d]!==s){l=Math.max(1,d-h[s]);break}}if(l===0)return m}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 o=et(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,e,n),this.write(o,t)}getInt32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,e)}setInt32(t,e,n){let o=et(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,e,n),this.write(o,t)}getBigInt64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,e)}setBigInt64(t,e,n){let o=et(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,e,n),this.write(o,t)}getUint8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getUint8(0)}setUint8(t,e){let n=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 o=et(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,e,n),this.write(o,t)}getUint32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,e)}setUint32(t,e,n){let o=et(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,e,n),this.write(o,t)}getBigUint64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,e)}setBigUint64(t,e,n){let o=et(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,e,n),this.write(o,t)}getFloat32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,e)}setFloat32(t,e,n){let o=et(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,e,n),this.write(o,t)}getFloat64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,e)}setFloat64(t,e,n){let o=et(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,e,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof r)||t.bufs.length!==this.bufs.length)return!1;for(let e=0;e<this.bufs.length;e++)if(!Qt(this.bufs[e],t.bufs[e]))return!1;return!0}static fromUint8Arrays(t,e){let n=new r;return n.bufs=t,e==null&&(e=t.reduce((o,i)=>o+i.byteLength,0)),n.length=e,n}};var se=class extends Error{code;constructor(t,e){super(t),this.code=e}},ur=class extends se{type;constructor(t){super(t,"ABORT_ERR"),this.type="aborted"}};function Pn(r){let t=Fn();r.sink(t).catch(i=>{t.end(i)}),r.sink=async i=>{for await(let c of i)t.push(c);t.end()};let e=r.source;r.source[Symbol.iterator]!=null?e=r.source[Symbol.iterator]():r.source[Symbol.asyncIterator]!=null&&(e=r.source[Symbol.asyncIterator]());let n=new J;return{read:async(i,c)=>{c?.signal?.throwIfAborted();let h,g=new Promise((p,l)=>{h=()=>{l(new ur("Read aborted"))},c?.signal?.addEventListener("abort",h)});try{if(i==null){let{done:l,value:m}=await Promise.race([e.next(),g]);return l===!0?new J:m}for(;n.byteLength<i;){let{value:l,done:m}=await Promise.race([e.next(),g]);if(m===!0)throw new se("unexpected end of input","ERR_UNEXPECTED_EOF");n.append(l)}let p=n.sublist(0,i);return n.consume(i),p}finally{h!=null&&c?.signal?.removeEventListener("abort",h)}},write:async(i,c)=>{c?.signal?.throwIfAborted(),i instanceof Uint8Array?t.push(i):t.push(i.subarray()),await t.onEmpty(c)},unwrap:()=>{let i=r.source;return r.source=async function*(){yield*n,yield*i}(),r}}}function ae(r){return r[Symbol.asyncIterator]!=null}var ce=r=>{let t=$(r),e=R(t);return ot(r,e),ce.bytes=t,e};ce.bytes=0;function ue(r,t){t=t??{};let e=t.lengthEncoder??ce;function*n(o){let i=e(o.byteLength);i instanceof Uint8Array?yield i:yield*i,o instanceof Uint8Array?yield o:yield*o}return ae(r)?async function*(){for await(let o of r)yield*n(o)}():function*(){for(let o of r)yield*n(o)}()}ue.single=(r,t)=>{t=t??{};let e=t.lengthEncoder??ce;return new J(e(r.byteLength),r)};var Lt=Wt(Rn(),1);var ws=8,bs=1024*1024*4,ht;(function(r){r[r.LENGTH=0]="LENGTH",r[r.DATA=1]="DATA"})(ht||(ht={}));var hr=r=>{let t=X(r);return hr.bytes=$(t),t};hr.bytes=0;function fr(r,t){let e=new J,n=ht.LENGTH,o=-1,i=t?.lengthDecoder??hr,c=t?.maxLengthLength??ws,h=t?.maxDataLength??bs;function*g(){for(;e.byteLength>0;){if(n===ht.LENGTH)try{if(o=i(e),o<0)throw(0,Lt.default)(new Error("invalid message length"),"ERR_INVALID_MSG_LENGTH");if(o>h)throw(0,Lt.default)(new Error("message length too long"),"ERR_MSG_DATA_TOO_LONG");let p=i.bytes;e.consume(p),t?.onLength!=null&&t.onLength(o),n=ht.DATA}catch(p){if(p instanceof RangeError){if(e.byteLength>c)throw(0,Lt.default)(new Error("message length length too long"),"ERR_MSG_LENGTH_TOO_LONG");break}throw p}if(n===ht.DATA){if(e.byteLength<o)break;let p=e.sublist(0,o);e.consume(o),t?.onData!=null&&t.onData(p),yield p,n=ht.LENGTH}}}return ae(r)?async function*(){for await(let p of r)e.append(p),yield*g();if(e.byteLength>0)throw(0,Lt.default)(new Error("unexpected end of input"),"ERR_UNEXPECTED_EOF")}():function*(){for(let p of r)e.append(p),yield*g();if(e.byteLength>0)throw(0,Lt.default)(new Error("unexpected end of input"),"ERR_UNEXPECTED_EOF")}()}fr.fromReader=(r,t)=>{let e=1,n=async function*(){for(;;)try{let{done:i,value:c}=await r.next(e);if(i===!0)return;c!=null&&(yield c)}catch(i){if(i.code==="ERR_UNDER_READ")return{done:!0,value:null};throw i}finally{e=1}}();return fr(n,{...t??{},onLength:i=>{e=i}})};var fe=class extends Error{code;constructor(t,e){super(t),this.code=e}},Tn=r=>X(r);Tn.bytes=0;function Un(r,t){let e=Pn(r);return{read:async o=>{let i=-1,c=new J,h=t?.lengthDecoder??Tn;for(;;){c.append(await e.read(1,o));try{i=h(c)}catch(g){if(g instanceof RangeError)continue;throw g}if(i>-1)break;if(t?.maxLengthLength!=null&&c.byteLength>t.maxLengthLength)throw new fe("message length length too long","ERR_MSG_LENGTH_TOO_LONG")}if(t?.maxDataLength!=null&&i>t.maxDataLength)throw new fe("message length too long","ERR_MSG_DATA_TOO_LONG");return e.read(i,o)},write:async(o,i)=>{await e.write(ue.single(o,t),i)},unwrap:()=>e.unwrap()}}function lr(r,t){let e=Un(r,t),n={read:async(o,i)=>{let c=await e.read(i);return o.decode(c)},write:async(o,i,c)=>{await e.write(i.encode(o),c)},pb:o=>({read:async i=>n.read(o,i),write:async(i,c)=>n.write(i,o,c),unwrap:()=>n}),unwrap:()=>e.unwrap()};return n}var dr=new Float32Array([-0]),it=new Uint8Array(dr.buffer);function kn(r,t,e){dr[0]=r,t[e]=it[0],t[e+1]=it[1],t[e+2]=it[2],t[e+3]=it[3]}function $n(r,t){return it[0]=r[t],it[1]=r[t+1],it[2]=r[t+2],it[3]=r[t+3],dr[0]}var pr=new Float64Array([-0]),U=new Uint8Array(pr.buffer);function Mn(r,t,e){pr[0]=r,t[e]=U[0],t[e+1]=U[1],t[e+2]=U[2],t[e+3]=U[3],t[e+4]=U[4],t[e+5]=U[5],t[e+6]=U[6],t[e+7]=U[7]}function Bn(r,t){return U[0]=r[t],U[1]=r[t+1],U[2]=r[t+2],U[3]=r[t+3],U[4]=r[t+4],U[5]=r[t+5],U[6]=r[t+6],U[7]=r[t+7],pr[0]}var xs=BigInt(Number.MAX_SAFE_INTEGER),Is=BigInt(Number.MIN_SAFE_INTEGER),M=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 lt;if(t<xs&&t>Is)return this.fromNumber(Number(t));let e=t<0n;e&&(t=-t);let n=t>>32n,o=t-(n<<32n);return e&&(n=~n|0n,o=~o|0n,++o>On&&(o=0n,++n>On&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(t){if(t===0)return lt;let e=t<0;e&&(t=-t);let n=t>>>0,o=(t-n)/4294967296>>>0;return e&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new r(n,o)}static from(t){return typeof t=="number"?r.fromNumber(t):typeof t=="bigint"?r.fromBigInt(t):typeof t=="string"?r.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new r(t.low>>>0,t.high>>>0):lt}},lt=new M(0,0);lt.toBigInt=function(){return 0n};lt.zzEncode=lt.zzDecode=function(){return this};lt.length=function(){return 1};var On=4294967296n;function zn(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 _n(r,t,e){if(e-t<1)return"";let o,i=[],c=0,h;for(;t<e;)h=r[t++],h<128?i[c++]=h:h>191&&h<224?i[c++]=(h&31)<<6|r[t++]&63:h>239&&h<365?(h=((h&7)<<18|(r[t++]&63)<<12|(r[t++]&63)<<6|r[t++]&63)-65536,i[c++]=55296+(h>>10),i[c++]=56320+(h&1023)):i[c++]=(h&15)<<12|(r[t++]&63)<<6|r[t++]&63,c>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,i)),c=0);return o!=null?(c>0&&o.push(String.fromCharCode.apply(String,i.slice(0,c))),o.join("")):String.fromCharCode.apply(String,i.slice(0,c))}function mr(r,t,e){let n=e,o,i;for(let c=0;c<r.length;++c)o=r.charCodeAt(c),o<128?t[e++]=o:o<2048?(t[e++]=o>>6|192,t[e++]=o&63|128):(o&64512)===55296&&((i=r.charCodeAt(c+1))&64512)===56320?(o=65536+((o&1023)<<10)+(i&1023),++c,t[e++]=o>>18|240,t[e++]=o>>12&63|128,t[e++]=o>>6&63|128,t[e++]=o&63|128):(t[e++]=o>>12|224,t[e++]=o>>6&63|128,t[e++]=o&63|128);return e-n}function H(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function he(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var gr=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,H(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 H(this,4);return he(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw H(this,4);return he(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw H(this,4);let t=$n(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw H(this,4);let t=Bn(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),e=this.pos,n=this.pos+t;if(n>this.len)throw H(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return _n(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw H(this,t);this.pos+=t}else do if(this.pos>=this.len)throw H(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 M(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 H(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 H(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 H(this,8);let t=he(this.buf,this.pos+=4),e=he(this.buf,this.pos+=4);return new M(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 wr(r){return new gr(r instanceof Uint8Array?r:r.subarray())}function br(r,t){let e=wr(r);return t.decode(e)}function yr(r){let t=r??8192,e=t>>>1,n,o=t;return function(c){if(c<1||c>e)return R(c);o+c>t&&(n=R(t),o=0);let h=n.subarray(o,o+=c);return o&7&&(o=(o|7)+1),h}}var dt=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function xr(){}var Ar=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},As=yr();function Es(r){return globalThis.Buffer!=null?R(r):As(r)}var Ot=class{len;head;tail;states;constructor(){this.len=0,this.head=new dt(xr,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new dt(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Er((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(Mt,10,M.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=M.fromBigInt(t);return this._push(Mt,e.length(),e)}uint64Number(t){let e=M.fromNumber(t);return this._push(Mt,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=M.fromBigInt(t).zzEncode();return this._push(Mt,e.length(),e)}sint64Number(t){let e=M.fromNumber(t).zzEncode();return this._push(Mt,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Ir,1,t?1:0)}fixed32(t){return this._push(Bt,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=M.fromBigInt(t);return this._push(Bt,4,e.lo)._push(Bt,4,e.hi)}fixed64Number(t){let e=M.fromNumber(t);return this._push(Bt,4,e.lo)._push(Bt,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(kn,4,t)}double(t){return this._push(Mn,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(Ir,1,0):this.uint32(e)._push(Cs,e,t)}string(t){let e=zn(t);return e!==0?this.uint32(e)._push(mr,e,t):this._push(Ir,1,0)}fork(){return this.states=new Ar(this),this.head=this.tail=new dt(xr,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 dt(xr,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=Es(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function Ir(r,t,e){t[e]=r&255}function vs(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var Er=class extends dt{next;constructor(t,e){super(vs,t,e),this.next=void 0}};function Mt(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 Bt(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 Cs(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(Ot.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(Fs,t,r),this},Ot.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(Ss,t,r),this});function Fs(r,t,e){t.set(r,e)}function Ss(r,t,e){r.length<40?mr(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set($t(r),e)}function vr(){return new Ot}function Cr(r,t){let e=vr();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var Pt;(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"})(Pt||(Pt={}));function le(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function Fr(r){function t(o){if(r[o.toString()]==null)throw new Error("Invalid enum value");return r[o]}let e=function(i,c){let h=t(i);c.int32(h)},n=function(i){let c=i.int32();return t(c)};return le("enum",Pt.VARINT,e,n)}function Sr(r,t){return le("message",Pt.LENGTH_DELIMITED,r,t)}var Q;(function(r){let t;(function(o){o.UNUSED="UNUSED",o.CONNECT="CONNECT",o.SYNC="SYNC"})(t=r.Type||(r.Type={}));let e;(function(o){o[o.UNUSED=0]="UNUSED",o[o.CONNECT=100]="CONNECT",o[o.SYNC=300]="SYNC"})(e||(e={})),function(o){o.codec=()=>Fr(e)}(t=r.Type||(r.Type={}));let n;r.codec=()=>(n==null&&(n=Sr((o,i,c={})=>{if(c.lengthDelimited!==!1&&i.fork(),o.type!=null&&(i.uint32(8),r.Type.codec().encode(o.type,i)),o.observedAddresses!=null)for(let h of o.observedAddresses)i.uint32(18),i.bytes(h);c.lengthDelimited!==!1&&i.ldelim()},(o,i)=>{let c={observedAddresses:[]},h=i==null?o.len:o.pos+i;for(;o.pos<h;){let g=o.uint32();switch(g>>>3){case 1:c.type=r.Type.codec().decode(o);break;case 2:c.observedAddresses.push(o.bytes());break;default:o.skipType(g&7);break}}return c})),n),r.encode=o=>Cr(o,r.codec()),r.decode=o=>br(o,r.codec())})(Q||(Q={}));var Ls=r=>r.toString().split("/").slice(1),zt=r=>({match:t=>t.length<1?!1:r(t[0])?t.slice(1):!1,pattern:"fn"}),C=r=>({match:t=>zt(e=>e===r).match(t),pattern:r}),me=()=>({match:r=>zt(t=>typeof t=="string").match(r),pattern:"{string}"}),jn=()=>({match:r=>zt(t=>!isNaN(parseInt(t))).match(r),pattern:"{number}"}),G=()=>({match:r=>{if(r.length<2||r[0]!=="p2p"&&r[0]!=="ipfs")return!1;if(r[1].startsWith("Q")||r[1].startsWith("1"))try{P.decode(`z${r[1]}`)}catch{return!1}else return!1;return r.slice(2)},pattern:"/p2p/{peerid}"}),de=()=>({match:r=>{if(r.length<2||r[0]!=="certhash")return!1;try{Pe.decode(r[1])}catch{return!1}return r.slice(2)},pattern:"/certhash/{certhash}"}),K=r=>({match:t=>{let e=r.match(t);return e===!1?t:e},pattern:`optional(${r.pattern})`}),Y=(...r)=>({match:t=>{let e;for(let n of r){let o=n.match(t);o!==!1&&(e==null||o.length<e.length)&&(e=o)}return e??!1},pattern:`or(${r.map(t=>t.pattern).join(", ")})`}),F=(...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 L(...r){function t(o){let i=Ls(o);for(let c of r){let h=c.match(i);if(h===!1)return!1;i=h}return i}function e(o){return t(o)!==!1}function n(o){let i=t(o);return i===!1?!1:i.length===0}return{matches:e,exactMatch:n}}var Pr=F(C("dns4"),me()),Dr=F(C("dns6"),me()),Nr=F(C("dnsaddr"),me()),Gn=F(C("dns"),me()),Lf=L(Pr),Pf=L(Dr),Df=L(Nr),Wn=L(Y(Gn,Nr,Pr,Dr)),qn=F(C("ip4"),zt(te)),Xn=F(C("ip6"),zt(ee)),Jn=Y(qn,Xn),_t=Y(Jn,Gn,Pr,Dr,Nr),Nf=L(_t),Rf=L(qn),Tf=L(Xn),Hn=L(Jn),ge=F(_t,C("tcp"),jn()),Vt=F(_t,C("udp"),jn()),Ps=Y(ge,Vt),Uf=L(ge),kf=L(Vt),Rr=F(Vt,C("quic")),we=F(Vt,C("quic-v1")),Ds=Y(Rr,we),$f=L(Rr),Mf=L(we),Lr=Y(_t,ge,Vt,Rr,we),Qn=Y(F(Lr,C("ws"),K(G()))),Bf=L(Qn),Zn=Y(F(Lr,C("wss"),K(G())),F(Lr,C("tls"),C("ws"),K(G()))),Of=L(Zn),Kn=F(Ps,C("webrtc-direct"),de(),K(de()),K(G())),zf=L(Kn),Yn=F(we,C("webtransport"),de(),de(),K(G())),_f=L(Yn),pe=Y(Qn,Zn,F(ge,K(G())),F(Ds,K(G())),F(_t,K(G())),Kn,Yn,G()),Vf=L(pe),Ns=F(pe,C("p2p-circuit"),G()),to=L(Ns),Rs=Y(F(pe,C("p2p-circuit"),C("webrtc"),G()),F(pe,C("webrtc"),K(G())),C("webrtc")),jf=L(Rs);var ao=Wt(eo(),1);var ro="[a-fA-F\\d:]",st=r=>r&&r.includeBoundaries?`(?:(?<=\\s|^)(?=${ro})|(?<=${ro})(?=\\s|$))`:"",Z="(?: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}",be=`
3
+ (?:
4
+ (?:${S}:){7}(?:${S}|:)| // 1:2:3:4:5:6:7:: 1:2:3:4:5:6:7:8
5
+ (?:${S}:){6}(?:${Z}|:${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}(?::${Z}|(?::${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}:${Z}|(?::${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}:${Z}|(?::${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}:${Z}|(?::${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}:${Z}|(?::${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}:${Z}|(?::${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(),Ts=new RegExp(`(?:^${Z}$)|(?:^${be}$)`),Us=new RegExp(`^${Z}$`),ks=new RegExp(`^${be}$`),Tr=r=>r&&r.exact?Ts:new RegExp(`(?:${st(r)}${Z}${st(r)})|(?:${st(r)}${be}${st(r)})`,"g");Tr.v4=r=>r&&r.exact?Us:new RegExp(`${st(r)}${Z}${st(r)}`,"g");Tr.v6=r=>r&&r.exact?ks:new RegExp(`${st(r)}${be}${st(r)}`,"g");var no=Tr;var co=Wt(io(),1),{isValid:$s,parse:Ms}=co.default,Bs=["0.0.0.0/8","10.0.0.0/8","100.64.0.0/10","127.0.0.0/8","169.254.0.0/16","172.16.0.0/12","192.0.0.0/24","192.0.0.0/29","192.0.0.8/32","192.0.0.9/32","192.0.0.10/32","192.0.0.170/32","192.0.0.171/32","192.0.2.0/24","192.31.196.0/24","192.52.193.0/24","192.88.99.0/24","192.168.0.0/16","192.175.48.0/24","198.18.0.0/15","198.51.100.0/24","203.0.113.0/24","240.0.0.0/4","255.255.255.255/32"],Os=Bs.map(r=>new ao.Netmask(r));function zs(r){for(let t of Os)if(t.contains(r))return!0;return!1}function so(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 uo=r=>{if($s(r)){let t=Ms(r);if(t.kind()==="ipv4")return zs(t.toNormalizedString());if(t.kind()==="ipv6")return so(r)}else if(Ct(r)&&no.v6().test(r))return so(r)};var fo=uo;function Ur(r,t){return to.matches(r)||t.transportForMultiaddr(r)==null?!1:Wn.matches(r)?!0:Hn.matches(r)?fo(r.toOptions().host)===!1:!1}var A=Xr("libp2p:dcutr"),ho=1024*4,lo=100,xe={timeout:5e3,retries:3,maxInboundStreams:1,maxOutboundStreams:1},Ie=class{started;timeout;retries;maxInboundStreams;maxOutboundStreams;peerStore;registrar;connectionManager;addressManager;transportManager;topologyId;constructor(t,e){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??xe.timeout,this.retries=e.retries??xe.retries,this.maxInboundStreams=e.maxInboundStreams??xe.maxInboundStreams,this.maxOutboundStreams=e.maxOutboundStreams??xe.maxOutboundStreams}isStarted(){return this.started}async start(){this.started||(this.topologyId=await this.registrar.register(Dt,{notifyOnTransient:!0,onConnect:(t,e)=>{e.transient&&e.direction==="inbound"&&this.upgradeInbound(e).catch(n=>{A.error("error during outgoing DCUtR attempt",n)})}}),await this.registrar.handle(Dt,t=>{this.handleIncomingUpgrade(t.stream,t.connection).catch(e=>{A.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(Dt),this.topologyId!=null&&this.registrar.unregister(this.topologyId),this.started=!1}async upgradeInbound(t){if(await this.attemptUnilateralConnectionUpgrade(t))return;let e;for(let n=0;n<this.retries;n++){let o={signal:AbortSignal.timeout(this.timeout)};try{e=await t.newStream([Dt],{signal:o.signal,runOnTransientConnection:!0});let i=lr(e,{maxDataLength:ho}).pb(Q);A("B sending connect to %p",t.remotePeer);let c=Date.now();await i.write({type:Q.Type.CONNECT,observedAddresses:this.addressManager.getAddresses().map(m=>m.bytes)},o),A("B receiving connect from %p",t.remotePeer);let h=await i.read(o);if(h.type!==Q.Type.CONNECT)throw A("A sent wrong message type"),new W("DCUtR message type was incorrect",at);let g=this.getDialableMultiaddrs(h.observedAddresses);if(g.length===0)throw A("A did not have any dialable multiaddrs"),new W("DCUtR connect message had no multiaddrs",at);let p=Date.now()-c;A("A sending sync, rtt %dms",p),await i.write({type:Q.Type.SYNC,observedAddresses:[]},o),A("A waiting for half RTT"),await Cn(p/2),A("B dialing",g);let l=await this.connectionManager.openConnection(g,{signal:o.signal,priority:lo});A("DCUtR to %p succeeded to address %a, closing relayed connection",t.remotePeer,l.remoteAddr),await t.close(o);break}catch(i){if(A.error("error while attempting DCUtR on attempt %d of %d",n+1,this.retries,i),e?.abort(i),n===this.retries)throw i}finally{e!=null&&await e.close(o)}}}async attemptUnilateralConnectionUpgrade(t){let n=(await this.peerStore.get(t.remotePeer)).addresses.map(o=>{let i=o.multiaddr;return i.getPeerId()==null?i.encapsulate(`/p2p/${t.remotePeer}`):i}).filter(o=>Ur(o,this.transportManager));if(n.length>0){let o=AbortSignal.timeout(this.timeout);try{A("attempting unilateral connection upgrade to %a",n);let i=await this.connectionManager.openConnection(n,{signal:o,force:!0});if(i.transient)throw new Error("Could not open a new, non-transient, connection");return A("unilateral connection upgrade to %p succeeded via %a, closing relayed connection",t.remotePeer,i.remoteAddr),await t.close({signal:o}),!0}catch(i){A.error("unilateral connection upgrade to %p on addresses %a failed",t.remotePeer,n,i)}}else A("peer %p has no public addresses, not attempting unilateral connection upgrade",t.remotePeer);return!1}async handleIncomingUpgrade(t,e){let n={signal:AbortSignal.timeout(this.timeout)};try{let o=lr(t,{maxDataLength:ho}).pb(Q);A("A receiving connect");let i=await o.read(n);if(i.type!==Q.Type.CONNECT)throw A("B sent wrong message type"),new W("DCUtR message type was incorrect",at);if(i.observedAddresses.length===0)throw A("B sent no multiaddrs"),new W("DCUtR connect message had no multiaddrs",at);let c=this.getDialableMultiaddrs(i.observedAddresses);if(c.length===0)throw A("B had no dialable multiaddrs"),new W("DCUtR connect message had no dialable multiaddrs",at);if(A("A sending connect"),await o.write({type:Q.Type.CONNECT,observedAddresses:this.addressManager.getAddresses().map(p=>p.bytes)}),A("A receiving sync"),(await o.read(n)).type!==Q.Type.SYNC)throw new W("DCUtR message type was incorrect",at);A("A dialing",c);let g=await this.connectionManager.openConnection(c,{signal:n.signal,priority:lo,force:!0});A("DCUtR to %p succeeded via %a, closing relayed connection",e.remotePeer,g.remoteAddr),await e.close(n)}catch(o){A.error("incoming DCUtR from %p failed",e.remotePeer,o),t.abort(o)}finally{await t.close(n)}}getDialableMultiaddrs(t){let e=[];for(let n of t)if(!(n==null||n.length===0))try{let o=ar(n);if(!Ur(o,this.transportManager))continue;e.push(o)}catch{}return e}};var Dt="/libp2p/dcutr";function _s(r={}){return t=>new Ie(t,r)}return yo(Vs);})();
14
+ return Libp2PDcutr}));
@@ -0,0 +1,43 @@
1
+ import { type Multiaddr } from '@multiformats/multiaddr';
2
+ import type { DCUtRServiceComponents, DCUtRServiceInit } from './index.js';
3
+ import type { Connection, Stream } from '@libp2p/interface/connection';
4
+ import type { Startable } from '@libp2p/interface/startable';
5
+ export declare class DefaultDCUtRService implements Startable {
6
+ private started;
7
+ private readonly timeout;
8
+ private readonly retries;
9
+ private readonly maxInboundStreams;
10
+ private readonly maxOutboundStreams;
11
+ private readonly peerStore;
12
+ private readonly registrar;
13
+ private readonly connectionManager;
14
+ private readonly addressManager;
15
+ private readonly transportManager;
16
+ private topologyId?;
17
+ constructor(components: DCUtRServiceComponents, init: DCUtRServiceInit);
18
+ isStarted(): boolean;
19
+ start(): Promise<void>;
20
+ stop(): Promise<void>;
21
+ /**
22
+ * Perform the inbound connection upgrade as B
23
+ *
24
+ * @see https://github.com/libp2p/specs/blob/master/relay/DCUtR.md#the-protocol
25
+ */
26
+ upgradeInbound(relayedConnection: Connection): Promise<void>;
27
+ /**
28
+ * This is performed when A has dialed B via a relay but A also has a public
29
+ * address that B can dial directly
30
+ */
31
+ attemptUnilateralConnectionUpgrade(relayedConnection: Connection): Promise<boolean>;
32
+ /**
33
+ * Perform the connection upgrade as A
34
+ *
35
+ * @see https://github.com/libp2p/specs/blob/master/relay/DCUtR.md#the-protocol
36
+ */
37
+ handleIncomingUpgrade(stream: Stream, relayedConnection: Connection): Promise<void>;
38
+ /**
39
+ * Takes the `addr` and converts it to a Multiaddr if possible
40
+ */
41
+ getDialableMultiaddrs(addrs: Array<Uint8Array | string | null | undefined>): Multiaddr[];
42
+ }
43
+ //# sourceMappingURL=dcutr.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dcutr.d.ts","sourceRoot":"","sources":["../../src/dcutr.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,SAAS,EAAa,MAAM,yBAAyB,CAAA;AAMnE,OAAO,KAAK,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAC1E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAA;AAEtE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAA;AAsB5D,qBAAa,mBAAoB,YAAW,SAAS;IACnD,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAQ;IAChC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAQ;IAChC,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAQ;IAC1C,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAQ;IAC3C,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAW;IACrC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAW;IACrC,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAmB;IACrD,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAgB;IAC/C,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAkB;IACnD,OAAO,CAAC,UAAU,CAAC,CAAQ;gBAEd,UAAU,EAAE,sBAAsB,EAAE,IAAI,EAAE,gBAAgB;IAcvE,SAAS,IAAK,OAAO;IAIf,KAAK,IAAK,OAAO,CAAC,IAAI,CAAC;IAyCvB,IAAI,IAAK,OAAO,CAAC,IAAI,CAAC;IAU5B;;;;OAIG;IACG,cAAc,CAAE,iBAAiB,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAkGnE;;;OAGG;IACG,kCAAkC,CAAE,iBAAiB,EAAE,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC;IA0D1F;;;;OAIG;IACG,qBAAqB,CAAE,MAAM,EAAE,MAAM,EAAE,iBAAiB,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAmE1F;;OAEG;IACH,qBAAqB,CAAE,KAAK,EAAE,KAAK,CAAC,UAAU,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,GAAG,SAAS,EAAE;CAqB1F"}