@libp2p/dcutr 2.0.17 → 2.0.18

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