@libp2p/dcutr 3.0.8 → 3.0.9-28c2b65f4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.min.js +1 -1
- package/package.json +4 -4
- package/dist/typedoc-urls.json +0 -10
package/dist/index.min.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PDcutr = factory()}(typeof self !== 'undefined' ? self : this, function () {
|
|
2
|
-
"use strict";var Libp2PDcutr=(()=>{var ao=Object.create;var Ve=Object.defineProperty;var co=Object.getOwnPropertyDescriptor;var uo=Object.getOwnPropertyNames;var lo=Object.getPrototypeOf,ho=Object.prototype.hasOwnProperty;var fo=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),_=(r,e)=>{for(var t in e)Ve(r,t,{get:e[t],enumerable:!0})},Vr=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of uo(e))!ho.call(r,o)&&o!==t&&Ve(r,o,{get:()=>e[o],enumerable:!(n=co(e,o))||n.enumerable});return r};var po=(r,e,t)=>(t=r!=null?ao(lo(r)):{},Vr(e||!r||!r.__esModule?Ve(t,"default",{value:r,enumerable:!0}):t,r)),mo=r=>Vr(Ve({},"__esModule",{value:!0}),r);var Sn=fo(Ue=>{(function(){var r,e,t,n,o,s,i,a;a=function(u){var c,h,l,f;return c=(u&255<<24)>>>24,h=(u&255<<16)>>>16,l=(u&65280)>>>8,f=u&255,[c,h,l,f].join(".")},i=function(u){var c,h,l,f,p,m;for(c=[],l=f=0;f<=3&&u.length!==0;l=++f){if(l>0){if(u[0]!==".")throw new Error("Invalid IP");u=u.substring(1)}m=e(u),p=m[0],h=m[1],u=u.substring(h),c.push(p)}if(u.length!==0)throw new Error("Invalid IP");switch(c.length){case 1:if(c[0]>4294967295)throw new Error("Invalid IP");return c[0]>>>0;case 2:if(c[0]>255||c[1]>16777215)throw new Error("Invalid IP");return(c[0]<<24|c[1])>>>0;case 3:if(c[0]>255||c[1]>255||c[2]>65535)throw new Error("Invalid IP");return(c[0]<<24|c[1]<<16|c[2])>>>0;case 4:if(c[0]>255||c[1]>255||c[2]>255||c[3]>255)throw new Error("Invalid IP");return(c[0]<<24|c[1]<<16|c[2]<<8|c[3])>>>0;default:throw new Error("Invalid IP")}},t=function(u){return u.charCodeAt(0)},n=t("0"),s=t("a"),o=t("A"),e=function(u){var c,h,l,f,p;for(f=0,c=10,h="9",l=0,u.length>1&&u[l]==="0"&&(u[l+1]==="x"||u[l+1]==="X"?(l+=2,c=16):"0"<=u[l+1]&&u[l+1]<="9"&&(l++,c=8,h="7")),p=l;l<u.length;){if("0"<=u[l]&&u[l]<=h)f=f*c+(t(u[l])-n)>>>0;else if(c===16)if("a"<=u[l]&&u[l]<="f")f=f*c+(10+t(u[l])-s)>>>0;else if("A"<=u[l]&&u[l]<="F")f=f*c+(10+t(u[l])-o)>>>0;else break;else break;if(f>4294967295)throw new Error("too large");l++}if(l===p)throw new Error("empty octet");return[f,l]},r=(function(){function u(c,h){var l,f,p,m;if(typeof c!="string")throw new Error("Missing `net' parameter");if(h||(m=c.split("/",2),c=m[0],h=m[1]),h||(h=32),typeof h=="string"&&h.indexOf(".")>-1){try{this.maskLong=i(h)}catch(v){throw l=v,new Error("Invalid mask: "+h)}for(f=p=32;p>=0;f=--p)if(this.maskLong===4294967295<<32-f>>>0){this.bitmask=f;break}}else if(h||h===0)this.bitmask=parseInt(h,10),this.maskLong=0,this.bitmask>0&&(this.maskLong=4294967295<<32-this.bitmask>>>0);else throw new Error("Invalid mask: empty");try{this.netLong=(i(c)&this.maskLong)>>>0}catch(v){throw l=v,new Error("Invalid net address: "+c)}if(!(this.bitmask<=32))throw new Error("Invalid mask for ip4: "+h);this.size=Math.pow(2,32-this.bitmask),this.base=a(this.netLong),this.mask=a(this.maskLong),this.hostmask=a(~this.maskLong),this.first=this.bitmask<=30?a(this.netLong+1):this.base,this.last=this.bitmask<=30?a(this.netLong+this.size-2):a(this.netLong+this.size-1),this.broadcast=this.bitmask<=30?a(this.netLong+this.size-1):void 0}return u.prototype.contains=function(c){return typeof c=="string"&&(c.indexOf("/")>0||c.split(".").length!==4)&&(c=new u(c)),c instanceof u?this.contains(c.base)&&this.contains(c.broadcast||c.last):(i(c)&this.maskLong)>>>0===(this.netLong&this.maskLong)>>>0},u.prototype.next=function(c){return c==null&&(c=1),new u(a(this.netLong+this.size*c),this.mask)},u.prototype.forEach=function(c){var h,l,f;for(f=i(this.first),l=i(this.last),h=0;f<=l;)c(a(f),f,h),h++,f++},u.prototype.toString=function(){return this.base+"/"+this.bitmask},u})(),Ue.ip2long=i,Ue.long2ip=a,Ue.Netmask=r}).call(Ue)});var Bi={};_(Bi,{dcutr:()=>Mi,multicodec:()=>Ce});var le=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}};var W=class extends Error{static name="InvalidMessageError";constructor(e="Invalid message"){super(e),this.name="InvalidMessageError"}};var ki=Symbol.for("@libp2p/service-capabilities"),zr=Symbol.for("@libp2p/service-dependencies");var gt={};_(gt,{base58btc:()=>k,base58flickr:()=>Io});var da=new Uint8Array(0);function kr(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])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 $r(r){return new TextEncoder().encode(r)}function Wr(r){return new TextDecoder().decode(r)}function go(r,e){if(r.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),n=0;n<t.length;n++)t[n]=255;for(var o=0;o<r.length;o++){var s=r.charAt(o),i=s.charCodeAt(0);if(t[i]!==255)throw new TypeError(s+" is ambiguous");t[i]=o}var a=r.length,u=r.charAt(0),c=Math.log(a)/Math.log(256),h=Math.log(256)/Math.log(a);function l(m){if(m instanceof Uint8Array||(ArrayBuffer.isView(m)?m=new Uint8Array(m.buffer,m.byteOffset,m.byteLength):Array.isArray(m)&&(m=Uint8Array.from(m))),!(m instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(m.length===0)return"";for(var v=0,Y=0,U=0,B=m.length;U!==B&&m[U]===0;)U++,v++;for(var V=(B-U)*h+1>>>0,O=new Uint8Array(V);U!==B;){for(var z=m[U],X=0,F=V-1;(z!==0||X<Y)&&F!==-1;F--,X++)z+=256*O[F]>>>0,O[F]=z%a>>>0,z=z/a>>>0;if(z!==0)throw new Error("Non-zero carry");Y=X,U++}for(var $=V-Y;$!==V&&O[$]===0;)$++;for(var Be=u.repeat(v);$<V;++$)Be+=r.charAt(O[$]);return Be}function f(m){if(typeof m!="string")throw new TypeError("Expected String");if(m.length===0)return new Uint8Array;var v=0;if(m[v]!==" "){for(var Y=0,U=0;m[v]===u;)Y++,v++;for(var B=(m.length-v)*c+1>>>0,V=new Uint8Array(B);m[v];){var O=t[m.charCodeAt(v)];if(O===255)return;for(var z=0,X=B-1;(O!==0||z<U)&&X!==-1;X--,z++)O+=a*V[X]>>>0,V[X]=O%256>>>0,O=O/256>>>0;if(O!==0)throw new Error("Non-zero carry");U=z,v++}if(m[v]!==" "){for(var F=B-U;F!==B&&V[F]===0;)F++;for(var $=new Uint8Array(Y+(B-F)),Be=Y;F!==B;)$[Be++]=V[F++];return $}}}function p(m){var v=f(m);if(v)return v;throw new Error(`Non-${e} character`)}return{encode:l,decodeUnsafe:f,decode:p}}var bo=go,xo=bo,jr=xo;var ft=class{name;prefix;baseEncode;constructor(e,t,n){this.name=e,this.prefix=t,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},dt=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,t,n){this.name=e,this.prefix=t;let o=t.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return qr(this,e)}},pt=class{decoders;constructor(e){this.decoders=e}or(e){return qr(this,e)}decode(e){let t=e[0],n=this.decoders[t];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function qr(r,e){return new pt({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var mt=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,t,n,o){this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=o,this.encoder=new ft(e,t,n),this.decoder=new dt(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function he({name:r,prefix:e,encode:t,decode:n}){return new mt(r,e,t,n)}function Q({name:r,prefix:e,alphabet:t}){let{encode:n,decode:o}=jr(t,r);return he({prefix:e,name:r,encode:n,decode:s=>G(o(s))})}function wo(r,e,t,n){let o=r.length;for(;r[o-1]==="=";)--o;let s=new Uint8Array(o*t/8|0),i=0,a=0,u=0;for(let c=0;c<o;++c){let h=e[r[c]];if(h===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<t|h,i+=t,i>=8&&(i-=8,s[u++]=255&a>>i)}if(i>=t||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function yo(r,e,t){let n=e[e.length-1]==="=",o=(1<<t)-1,s="",i=0,a=0;for(let u=0;u<r.length;++u)for(a=a<<8|r[u],i+=8;i>t;)i-=t,s+=e[o&a>>i];if(i!==0&&(s+=e[o&a<<t-i]),n)for(;(s.length*t&7)!==0;)s+="=";return s}function Eo(r){let e={};for(let t=0;t<r.length;++t)e[r[t]]=t;return e}function I({name:r,prefix:e,bitsPerChar:t,alphabet:n}){let o=Eo(n);return he({prefix:e,name:r,encode(s){return yo(s,n,t)},decode(s){return wo(s,o,t,r)}})}var k=Q({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Io=Q({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var bt={};_(bt,{base32:()=>J,base32hex:()=>Do,base32hexpad:()=>Ao,base32hexpadupper:()=>Lo,base32hexupper:()=>To,base32pad:()=>Co,base32padupper:()=>So,base32upper:()=>vo,base32z:()=>No});var J=I({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),vo=I({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Co=I({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),So=I({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Do=I({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),To=I({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Ao=I({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Lo=I({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),No=I({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var xt={};_(xt,{base36:()=>Se,base36upper:()=>_o});var Se=Q({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),_o=Q({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Po=Qr,Hr=128,Oo=127,Uo=~Oo,Fo=Math.pow(2,31);function Qr(r,e,t){e=e||[],t=t||0;for(var n=t;r>=Fo;)e[t++]=r&255|Hr,r/=128;for(;r&Uo;)e[t++]=r&255|Hr,r>>>=7;return e[t]=r|0,Qr.bytes=t-n+1,e}var Ro=wt,Mo=128,Xr=127;function wt(r,n){var t=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw wt.bytes=0,new RangeError("Could not decode varint");i=r[s++],t+=o<28?(i&Xr)<<o:(i&Xr)*Math.pow(2,o),o+=7}while(i>=Mo);return wt.bytes=s-n,t}var Bo=Math.pow(2,7),Vo=Math.pow(2,14),zo=Math.pow(2,21),ko=Math.pow(2,28),$o=Math.pow(2,35),Wo=Math.pow(2,42),Go=Math.pow(2,49),jo=Math.pow(2,56),qo=Math.pow(2,63),Ho=function(r){return r<Bo?1:r<Vo?2:r<zo?3:r<ko?4:r<$o?5:r<Wo?6:r<Go?7:r<jo?8:r<qo?9:10},Xo={encode:Po,decode:Ro,encodingLength:Ho},Qo=Xo,De=Qo;function Te(r,e=0){return[De.decode(r,e),De.decode.bytes]}function fe(r,e,t=0){return De.encode(r,e,t),e}function de(r){return De.encodingLength(r)}function me(r,e){let t=e.byteLength,n=de(r),o=n+de(t),s=new Uint8Array(o+t);return fe(r,s,0),fe(t,s,n),s.set(e,o),new pe(r,t,e,s)}function Jr(r){let e=G(r),[t,n]=Te(e),[o,s]=Te(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new pe(t,o,i,e)}function Kr(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&kr(r.bytes,t.bytes)}}var pe=class{code;size;digest;bytes;constructor(e,t,n,o){this.code=e,this.size=t,this.digest=n,this.bytes=o}};function Zr(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return Ko(t,yt(r),e??k.encoder);default:return Zo(t,yt(r),e??J.encoder)}}var Yr=new WeakMap;function yt(r){let e=Yr.get(r);if(e==null){let t=new Map;return Yr.set(r,t),t}return e}var ge=class r{code;version;multihash;bytes;"/";constructor(e,t,n,o){this.code=t,this.version=e,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:e,multihash:t}=this;if(e!==Le)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==Yo)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(t)}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:e,digest:t}=this.multihash,n=me(e,t);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(e){return r.equals(this,e)}static equals(e,t){let n=t;return n!=null&&e.code===n.code&&e.version===n.version&&Kr(e.multihash,n.multihash)}toString(e){return Zr(this,e)}toJSON(){return{"/":Zr(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let t=e;if(t instanceof r)return t;if(t["/"]!=null&&t["/"]===t.bytes||t.asCID===t){let{version:n,code:o,multihash:s,bytes:i}=t;return new r(n,o,s,i??en(n,o,s.bytes))}else if(t[es]===!0){let{version:n,multihash:o,code:s}=t,i=Jr(o);return r.create(n,s,i)}else return null}static create(e,t,n){if(typeof t!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(t!==Le)throw new Error(`Version 0 CID must use dag-pb (code: ${Le}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let o=en(e,t,n.bytes);return new r(e,t,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,Le,e)}static createV1(e,t){return r.create(1,e,t)}static decode(e){let[t,n]=r.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return t}static decodeFirst(e){let t=r.inspectBytes(e),n=t.size-t.multihashSize,o=G(e.subarray(n,n+t.multihashSize));if(o.byteLength!==t.multihashSize)throw new Error("Incorrect length");let s=o.subarray(t.multihashSize-t.digestSize),i=new pe(t.multihashCode,t.digestSize,s,o);return[t.version===0?r.createV0(i):r.createV1(t.codec,i),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[l,f]=Te(e.subarray(t));return t+=f,l},o=n(),s=Le;if(o===18?(o=0,t=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=t,a=n(),u=n(),c=t+u,h=c-i;return{version:o,codec:s,multihashCode:a,digestSize:u,multihashSize:h,size:c}}static parse(e,t){let[n,o]=Jo(e,t),s=r.decode(o);if(s.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return yt(s).set(n,e),s}};function Jo(r,e){switch(r[0]){case"Q":{let t=e??k;return[k.prefix,t.decode(`${k.prefix}${r}`)]}case k.prefix:{let t=e??k;return[k.prefix,t.decode(r)]}case J.prefix:{let t=e??J;return[J.prefix,t.decode(r)]}case Se.prefix:{let t=e??Se;return[Se.prefix,t.decode(r)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],e.decode(r)]}}}function Ko(r,e,t){let{prefix:n}=t;if(n!==k.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let o=e.get(n);if(o==null){let s=t.encode(r).slice(1);return e.set(n,s),s}else return o}function Zo(r,e,t){let{prefix:n}=t,o=e.get(n);if(o==null){let s=t.encode(r);return e.set(n,s),s}else return o}var Le=112,Yo=18;function en(r,e,t){let n=de(r),o=n+de(e),s=new Uint8Array(o+t.byteLength);return fe(r,s,0),fe(e,s,n),s.set(t,o),s}var es=Symbol.for("@ipld/js-cid/CID");var Et={};_(Et,{identity:()=>ns});var tn=0,ts="identity",rn=G;function rs(r,e){if(e?.truncate!=null&&e.truncate!==r.byteLength){if(e.truncate<0||e.truncate>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,e.truncate)}return me(tn,rn(r))}var ns={code:tn,name:ts,encode:rn,digest:rs};function ke(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}function j(r=0){return new Uint8Array(r)}function L(r=0){return new Uint8Array(r)}function K(r,e){e==null&&(e=r.reduce((o,s)=>o+s.length,0));let t=L(e),n=0;for(let o of r)t.set(o,n),n+=o.length;return t}var on=Symbol.for("@achingbrain/uint8arraylist");function nn(r,e){if(e==null||e<0)throw new RangeError("index is out of bounds");let t=0;for(let n of r){let o=t+n.byteLength;if(e<o)return{buf:n,index:e-t};t=o}throw new RangeError("index is out of bounds")}function $e(r){return!!r?.[on]}var ee=class r{bufs;length;[on]=!0;constructor(...e){this.bufs=[],this.length=0,e.length>0&&this.appendAll(e)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...e){this.appendAll(e)}appendAll(e){let t=0;for(let n of e)if(n instanceof Uint8Array)t+=n.byteLength,this.bufs.push(n);else if($e(n))t+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=t}prepend(...e){this.prependAll(e)}prependAll(e){let t=0;for(let n of e.reverse())if(n instanceof Uint8Array)t+=n.byteLength,this.bufs.unshift(n);else if($e(n))t+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=t}get(e){let t=nn(this.bufs,e);return t.buf[t.index]}set(e,t){let n=nn(this.bufs,e);n.buf[n.index]=t}write(e,t=0){if(e instanceof Uint8Array)for(let n=0;n<e.length;n++)this.set(t+n,e[n]);else if($e(e))for(let n=0;n<e.length;n++)this.set(t+n,e.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(e){if(e=Math.trunc(e),!(Number.isNaN(e)||e<=0)){if(e===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(e>=this.bufs[0].byteLength)e-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(e),this.length-=e;break}}}slice(e,t){let{bufs:n,length:o}=this._subList(e,t);return K(n,o)}subarray(e,t){let{bufs:n,length:o}=this._subList(e,t);return n.length===1?n[0]:K(n,o)}sublist(e,t){let{bufs:n,length:o}=this._subList(e,t),s=new r;return s.length=o,s.bufs=[...n],s}_subList(e,t){if(e=e??0,t=t??this.length,e<0&&(e=this.length+e),t<0&&(t=this.length+t),e<0||t>this.length)throw new RangeError("index is out of bounds");if(e===t)return{bufs:[],length:0};if(e===0&&t===this.length)return{bufs:this.bufs,length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],a=o,u=a+i.byteLength;if(o=u,e>=u)continue;let c=e>=a&&e<u,h=t>a&&t<=u;if(c&&h){if(e===a&&t===u){n.push(i);break}let l=e-a;n.push(i.subarray(l,l+(t-e)));break}if(c){if(e===0){n.push(i);continue}n.push(i.subarray(e-a));continue}if(h){if(t===u){n.push(i);break}n.push(i.subarray(0,t-a));break}n.push(i)}return{bufs:n,length:t-e}}indexOf(e,t=0){if(!$e(e)&&!(e instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=e instanceof Uint8Array?e:e.subarray();if(t=Number(t??0),isNaN(t)&&(t=0),t<0&&(t=this.length+t),t<0&&(t=0),e.length===0)return t>this.length?this.length:t;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let l=0;l<s;l++)i[l]=-1;for(let l=0;l<o;l++)i[n[l]]=l;let a=i,u=this.byteLength-n.byteLength,c=n.byteLength-1,h;for(let l=t;l<=u;l+=h){h=0;for(let f=c;f>=0;f--){let p=this.get(l+f);if(n[f]!==p){h=Math.max(1,f-a[p]);break}}if(h===0)return l}return-1}getInt8(e){let t=this.subarray(e,e+1);return new DataView(t.buffer,t.byteOffset,t.byteLength).getInt8(0)}setInt8(e,t){let n=L(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,t),this.write(n,e)}getInt16(e,t){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,t)}setInt16(e,t,n){let o=j(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,t,n),this.write(o,e)}getInt32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,t)}setInt32(e,t,n){let o=j(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,t,n),this.write(o,e)}getBigInt64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,t)}setBigInt64(e,t,n){let o=j(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,t,n),this.write(o,e)}getUint8(e){let t=this.subarray(e,e+1);return new DataView(t.buffer,t.byteOffset,t.byteLength).getUint8(0)}setUint8(e,t){let n=L(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,t),this.write(n,e)}getUint16(e,t){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,t)}setUint16(e,t,n){let o=j(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,t,n),this.write(o,e)}getUint32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,t)}setUint32(e,t,n){let o=j(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,t,n),this.write(o,e)}getBigUint64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,t)}setBigUint64(e,t,n){let o=j(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,t,n),this.write(o,e)}getFloat32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,t)}setFloat32(e,t,n){let o=j(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,t,n),this.write(o,e)}getFloat64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,t)}setFloat64(e,t,n){let o=j(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,t,n),this.write(o,e)}equals(e){if(e==null||!(e instanceof r)||e.bufs.length!==this.bufs.length)return!1;for(let t=0;t<this.bufs.length;t++)if(!ke(this.bufs[t],e.bufs[t]))return!1;return!0}static fromUint8Arrays(e,t){let n=new r;return n.bufs=e,t==null&&(t=e.reduce((o,s)=>o+s.byteLength,0)),n.length=t,n}};var It={};_(It,{base10:()=>os});var os=Q({prefix:"9",name:"base10",alphabet:"0123456789"});var vt={};_(vt,{base16:()=>ss,base16upper:()=>is});var ss=I({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),is=I({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Ct={};_(Ct,{base2:()=>as});var as=I({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var St={};_(St,{base256emoji:()=>fs});var sn=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),cs=sn.reduce((r,e,t)=>(r[t]=e,r),[]),us=sn.reduce((r,e,t)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return r[n]=t,r},[]);function ls(r){return r.reduce((e,t)=>(e+=cs[t],e),"")}function hs(r){let e=[];for(let t of r){let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);let o=us[n];if(o==null)throw new Error(`Non-base256emoji character: ${t}`);e.push(o)}return new Uint8Array(e)}var fs=he({prefix:"\u{1F680}",name:"base256emoji",encode:ls,decode:hs});var Tt={};_(Tt,{base64:()=>ds,base64pad:()=>ps,base64url:()=>Dt,base64urlpad:()=>ms});var ds=I({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),ps=I({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Dt=I({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),ms=I({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var At={};_(At,{base8:()=>gs});var gs=I({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Lt={};_(Lt,{identity:()=>bs});var bs=he({prefix:"\0",name:"identity",encode:r=>Wr(r),decode:r=>$r(r)});var Ja=new TextEncoder,Ka=new TextDecoder;var Pt={};_(Pt,{sha256:()=>Es,sha512:()=>Is});var ys=20;function _t({name:r,code:e,encode:t,minDigestLength:n,maxDigestLength:o}){return new Nt(r,e,t,n,o)}var Nt=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,t,n,o,s){this.name=e,this.code=t,this.encode=n,this.minDigestLength=o??ys,this.maxDigestLength=s}digest(e,t){if(t?.truncate!=null){if(t.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&t.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(e instanceof Uint8Array){let n=this.encode(e);return n instanceof Uint8Array?an(n,this.code,t?.truncate):n.then(o=>an(o,this.code,t?.truncate))}else throw Error("Unknown type, must be binary type")}};function an(r,e,t){if(t!=null&&t!==r.byteLength){if(t>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,t)}return me(e,r)}function un(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var Es=_t({name:"sha2-256",code:18,encode:un("SHA-256")}),Is=_t({name:"sha2-512",code:19,encode:un("SHA-512")});var Ne={...Lt,...Ct,...At,...It,...vt,...bt,...xt,...gt,...Tt,...St},uc={...Pt,...Et};function hn(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var ln=hn("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Ot=hn("ascii","a",r=>{let e="a";for(let t=0;t<r.length;t++)e+=String.fromCharCode(r[t]);return e},r=>{r=r.substring(1);let e=L(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),vs={utf8:ln,"utf-8":ln,hex:Ne.base16,latin1:Ot,ascii:Ot,binary:Ot,...Ne},We=vs;function te(r,e="utf8"){let t=We[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.decoder.decode(`${t.prefix}${r}`)}function re(r,e="utf8"){let t=We[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.encoder.encode(r).substring(1)}var Cs=Math.pow(2,7),Ss=Math.pow(2,14),Ds=Math.pow(2,21),Ut=Math.pow(2,28),Ft=Math.pow(2,35),Rt=Math.pow(2,42),Mt=Math.pow(2,49),x=128,D=127;function N(r){if(r<Cs)return 1;if(r<Ss)return 2;if(r<Ds)return 3;if(r<Ut)return 4;if(r<Ft)return 5;if(r<Rt)return 6;if(r<Mt)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function be(r,e,t=0){switch(N(r)){case 8:e[t++]=r&255|x,r/=128;case 7:e[t++]=r&255|x,r/=128;case 6:e[t++]=r&255|x,r/=128;case 5:e[t++]=r&255|x,r/=128;case 4:e[t++]=r&255|x,r>>>=7;case 3:e[t++]=r&255|x,r>>>=7;case 2:e[t++]=r&255|x,r>>>=7;case 1:{e[t++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return e}function Ts(r,e,t=0){switch(N(r)){case 8:e.set(t++,r&255|x),r/=128;case 7:e.set(t++,r&255|x),r/=128;case 6:e.set(t++,r&255|x),r/=128;case 5:e.set(t++,r&255|x),r/=128;case 4:e.set(t++,r&255|x),r>>>=7;case 3:e.set(t++,r&255|x),r>>>=7;case 2:e.set(t++,r&255|x),r>>>=7;case 1:{e.set(t++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return e}function Bt(r,e){let t=r[e],n=0;if(n+=t&D,t<x||(t=r[e+1],n+=(t&D)<<7,t<x)||(t=r[e+2],n+=(t&D)<<14,t<x)||(t=r[e+3],n+=(t&D)<<21,t<x)||(t=r[e+4],n+=(t&D)*Ut,t<x)||(t=r[e+5],n+=(t&D)*Ft,t<x)||(t=r[e+6],n+=(t&D)*Rt,t<x)||(t=r[e+7],n+=(t&D)*Mt,t<x))return n;throw new RangeError("Could not decode varint")}function As(r,e){let t=r.get(e),n=0;if(n+=t&D,t<x||(t=r.get(e+1),n+=(t&D)<<7,t<x)||(t=r.get(e+2),n+=(t&D)<<14,t<x)||(t=r.get(e+3),n+=(t&D)<<21,t<x)||(t=r.get(e+4),n+=(t&D)*Ut,t<x)||(t=r.get(e+5),n+=(t&D)*Ft,t<x)||(t=r.get(e+6),n+=(t&D)*Rt,t<x)||(t=r.get(e+7),n+=(t&D)*Mt,t<x))return n;throw new RangeError("Could not decode varint")}function fn(r,e,t=0){return e==null&&(e=L(N(r))),e instanceof Uint8Array?be(r,e,t):Ts(r,e,t)}function _e(r,e=0){return r instanceof Uint8Array?Bt(r,e):As(r,e)}var Vt=new Float32Array([-0]),Z=new Uint8Array(Vt.buffer);function pn(r,e,t){Vt[0]=r,e[t]=Z[0],e[t+1]=Z[1],e[t+2]=Z[2],e[t+3]=Z[3]}function mn(r,e){return Z[0]=r[e],Z[1]=r[e+1],Z[2]=r[e+2],Z[3]=r[e+3],Vt[0]}var zt=new Float64Array([-0]),T=new Uint8Array(zt.buffer);function gn(r,e,t){zt[0]=r,e[t]=T[0],e[t+1]=T[1],e[t+2]=T[2],e[t+3]=T[3],e[t+4]=T[4],e[t+5]=T[5],e[t+6]=T[6],e[t+7]=T[7]}function bn(r,e){return T[0]=r[e],T[1]=r[e+1],T[2]=r[e+2],T[3]=r[e+3],T[4]=r[e+4],T[5]=r[e+5],T[6]=r[e+6],T[7]=r[e+7],zt[0]}var Ls=BigInt(Number.MAX_SAFE_INTEGER),Ns=BigInt(Number.MIN_SAFE_INTEGER),P=class r{lo;hi;constructor(e,t){this.lo=e|0,this.hi=t|0}toNumber(e=!1){if(!e&&this.hi>>>31>0){let t=~this.lo+1>>>0,n=~this.hi>>>0;return t===0&&(n=n+1>>>0),-(t+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(e=!1){if(e)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let t=~this.lo+1>>>0,n=~this.hi>>>0;return t===0&&(n=n+1>>>0),-(BigInt(t)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(e=!1){return this.toBigInt(e).toString()}zzEncode(){let e=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^e)>>>0,this.lo=(this.lo<<1^e)>>>0,this}zzDecode(){let e=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^e)>>>0,this.hi=(this.hi>>>1^e)>>>0,this}length(){let e=this.lo,t=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?t===0?e<16384?e<128?1:2:e<2097152?3:4:t<16384?t<128?5:6:t<2097152?7:8:n<128?9:10}static fromBigInt(e){if(e===0n)return ne;if(e<Ls&&e>Ns)return this.fromNumber(Number(e));let t=e<0n;t&&(e=-e);let n=e>>32n,o=e-(n<<32n);return t&&(n=~n|0n,o=~o|0n,++o>xn&&(o=0n,++n>xn&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(e){if(e===0)return ne;let t=e<0;t&&(e=-e);let n=e>>>0,o=(e-n)/4294967296>>>0;return t&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new r(n,o)}static from(e){return typeof e=="number"?r.fromNumber(e):typeof e=="bigint"?r.fromBigInt(e):typeof e=="string"?r.fromBigInt(BigInt(e)):e.low!=null||e.high!=null?new r(e.low>>>0,e.high>>>0):ne}},ne=new P(0,0);ne.toBigInt=function(){return 0n};ne.zzEncode=ne.zzDecode=function(){return this};ne.length=function(){return 1};var xn=4294967296n;function wn(r){let e=0,t=0;for(let n=0;n<r.length;++n)t=r.charCodeAt(n),t<128?e+=1:t<2048?e+=2:(t&64512)===55296&&(r.charCodeAt(n+1)&64512)===56320?(++n,e+=4):e+=3;return e}function yn(r,e,t){if(t-e<1)return"";let o,s=[],i=0,a;for(;e<t;)a=r[e++],a<128?s[i++]=a:a>191&&a<224?s[i++]=(a&31)<<6|r[e++]&63:a>239&&a<365?(a=((a&7)<<18|(r[e++]&63)<<12|(r[e++]&63)<<6|r[e++]&63)-65536,s[i++]=55296+(a>>10),s[i++]=56320+(a&1023)):s[i++]=(a&15)<<12|(r[e++]&63)<<6|r[e++]&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 kt(r,e,t){let n=t,o,s;for(let i=0;i<r.length;++i)o=r.charCodeAt(i),o<128?e[t++]=o:o<2048?(e[t++]=o>>6|192,e[t++]=o&63|128):(o&64512)===55296&&((s=r.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,e[t++]=o>>18|240,e[t++]=o>>12&63|128,e[t++]=o>>6&63|128,e[t++]=o&63|128):(e[t++]=o>>12|224,e[t++]=o>>6&63|128,e[t++]=o&63|128);return t-n}function R(r,e){return RangeError(`index out of range: ${r.pos} + ${e??1} > ${r.len}`)}function Ge(r,e){return(r[e-4]|r[e-3]<<8|r[e-2]<<16|r[e-1]<<24)>>>0}var $t=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(e){this.buf=e,this.pos=0,this.len=e.length}uint32(){let e=4294967295;if(e=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(e=(e|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return e;if((this.pos+=5)>this.len)throw this.pos=this.len,R(this,10);return e}int32(){return this.uint32()|0}sint32(){let e=this.uint32();return e>>>1^-(e&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw R(this,4);return Ge(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw R(this,4);return Ge(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw R(this,4);let e=mn(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw R(this,4);let e=bn(this.buf,this.pos);return this.pos+=8,e}bytes(){let e=this.uint32(),t=this.pos,n=this.pos+e;if(n>this.len)throw R(this,e);return this.pos+=e,t===n?new Uint8Array(0):this.buf.subarray(t,n)}string(){let e=this.bytes();return yn(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw R(this,e);this.pos+=e}else do if(this.pos>=this.len)throw R(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(e){switch(e){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(e=this.uint32()&7)!==4;)this.skipType(e);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${e} at offset ${this.pos}`)}return this}readLongVarint(){let e=new P(0,0),t=0;if(this.len-this.pos>4){for(;t<4;++t)if(e.lo=(e.lo|(this.buf[this.pos]&127)<<t*7)>>>0,this.buf[this.pos++]<128)return e;if(e.lo=(e.lo|(this.buf[this.pos]&127)<<28)>>>0,e.hi=(e.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return e;t=0}else{for(;t<3;++t){if(this.pos>=this.len)throw R(this);if(e.lo=(e.lo|(this.buf[this.pos]&127)<<t*7)>>>0,this.buf[this.pos++]<128)return e}return e.lo=(e.lo|(this.buf[this.pos++]&127)<<t*7)>>>0,e}if(this.len-this.pos>4){for(;t<5;++t)if(e.hi=(e.hi|(this.buf[this.pos]&127)<<t*7+3)>>>0,this.buf[this.pos++]<128)return e}else for(;t<5;++t){if(this.pos>=this.len)throw R(this);if(e.hi=(e.hi|(this.buf[this.pos]&127)<<t*7+3)>>>0,this.buf[this.pos++]<128)return e}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw R(this,8);let e=Ge(this.buf,this.pos+=4),t=Ge(this.buf,this.pos+=4);return new P(e,t)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let e=Bt(this.buf,this.pos);return this.pos+=N(e),e}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 Wt(r){return new $t(r instanceof Uint8Array?r:r.subarray())}function Gt(r,e,t){let n=Wt(r);return e.decode(n,void 0,t)}function jt(r){let e=r??8192,t=e>>>1,n,o=e;return function(i){if(i<1||i>t)return L(i);o+i>e&&(n=L(e),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var oe=class{fn;len;next;val;constructor(e,t,n){this.fn=e,this.len=t,this.next=void 0,this.val=n}};function qt(){}var Xt=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},_s=jt();function Ps(r){return globalThis.Buffer!=null?L(r):_s(r)}var Oe=class{len;head;tail;states;constructor(){this.len=0,this.head=new oe(qt,0,0),this.tail=this.head,this.states=null}_push(e,t,n){return this.tail=this.tail.next=new oe(e,t,n),this.len+=t,this}uint32(e){return this.len+=(this.tail=this.tail.next=new Qt((e=e>>>0)<128?1:e<16384?2:e<2097152?3:e<268435456?4:5,e)).len,this}int32(e){return e<0?this._push(je,10,P.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let t=P.fromBigInt(e);return this._push(je,t.length(),t)}uint64Number(e){return this._push(be,N(e),e)}uint64String(e){return this.uint64(BigInt(e))}int64(e){return this.uint64(e)}int64Number(e){return this.uint64Number(e)}int64String(e){return this.uint64String(e)}sint64(e){let t=P.fromBigInt(e).zzEncode();return this._push(je,t.length(),t)}sint64Number(e){let t=P.fromNumber(e).zzEncode();return this._push(je,t.length(),t)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(Ht,1,e?1:0)}fixed32(e){return this._push(Pe,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let t=P.fromBigInt(e);return this._push(Pe,4,t.lo)._push(Pe,4,t.hi)}fixed64Number(e){let t=P.fromNumber(e);return this._push(Pe,4,t.lo)._push(Pe,4,t.hi)}fixed64String(e){return this.fixed64(BigInt(e))}sfixed64(e){return this.fixed64(e)}sfixed64Number(e){return this.fixed64Number(e)}sfixed64String(e){return this.fixed64String(e)}float(e){return this._push(pn,4,e)}double(e){return this._push(gn,8,e)}bytes(e){let t=e.length>>>0;return t===0?this._push(Ht,1,0):this.uint32(t)._push(Us,t,e)}string(e){let t=wn(e);return t!==0?this.uint32(t)._push(kt,t,e):this._push(Ht,1,0)}fork(){return this.states=new Xt(this),this.head=this.tail=new oe(qt,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 oe(qt,0,0),this.len=0),this}ldelim(){let e=this.head,t=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=e.next,this.tail=t,this.len+=n),this}finish(){let e=this.head.next,t=Ps(this.len),n=0;for(;e!=null;)e.fn(e.val,t,n),n+=e.len,e=e.next;return t}};function Ht(r,e,t){e[t]=r&255}function Os(r,e,t){for(;r>127;)e[t++]=r&127|128,r>>>=7;e[t]=r}var Qt=class extends oe{next;constructor(e,t){super(Os,e,t),this.next=void 0}};function je(r,e,t){for(;r.hi!==0;)e[t++]=r.lo&127|128,r.lo=(r.lo>>>7|r.hi<<25)>>>0,r.hi>>>=7;for(;r.lo>127;)e[t++]=r.lo&127|128,r.lo=r.lo>>>7;e[t++]=r.lo}function Pe(r,e,t){e[t]=r&255,e[t+1]=r>>>8&255,e[t+2]=r>>>16&255,e[t+3]=r>>>24}function Us(r,e,t){e.set(r,t)}globalThis.Buffer!=null&&(Oe.prototype.bytes=function(r){let e=r.length>>>0;return this.uint32(e),e>0&&this._push(Fs,e,r),this},Oe.prototype.string=function(r){let e=globalThis.Buffer.byteLength(r);return this.uint32(e),e>0&&this._push(Rs,e,r),this});function Fs(r,e,t){e.set(r,t)}function Rs(r,e,t){r.length<40?kt(r,e,t):e.utf8Write!=null?e.utf8Write(r,t):e.set(te(r),t)}function Jt(){return new Oe}function Kt(r,e){let t=Jt();return e.encode(r,t,{lengthDelimited:!1}),t.finish()}var xe;(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"})(xe||(xe={}));function qe(r,e,t,n){return{name:r,type:e,encode:t,decode:n}}function Zt(r){function e(o){if(r[o.toString()]==null)throw new Error("Invalid enum value");return r[o]}let t=function(s,i){let a=e(s);i.int32(a)},n=function(s){let i=s.int32();return e(i)};return qe("enum",xe.VARINT,t,n)}function Yt(r,e){return qe("message",xe.LENGTH_DELIMITED,r,e)}var He=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};function In(r){let e=r.getComponents(),t={},n=0;if(e[n]?.name==="ip6zone"&&(t.zone=`${e[n].value}`,n++),e[n].name==="ip4"||e[n].name==="ip6"||e[n].name==="dns"||e[n].name==="dns4"||e[n].name==="dns6"?(t.type=e[n].name,t.host=e[n].value,n++):e[n].name==="dnsaddr"&&(t.type=e[n].name,t.host=`_dnsaddr.${e[n].value}`,n++),(e[n]?.name==="tcp"||e[n]?.name==="udp")&&(t.protocol=e[n].name==="tcp"?"tcp":"udp",t.port=parseInt(`${e[n].value}`),n++),e[n]?.name==="ipcidr"&&(t.type==="ip4"?t.cidr=parseInt(`${e[n].value}`):t.type==="ip6"&&(t.cidr=`${e[n].value}`),n++),t.type==null||t.host==null)throw new le(`Multiaddr ${r} was not an IPv4, IPv6, DNS, DNS4, DNS6 or DNSADDR address`);return e[n]?.name==="tls"&&e[n+1]?.name==="sni"&&(t.sni=e[n+1].value,n+=2),t}var Xe=class{index=0;input="";new(e){return this.index=0,this.input=e,this}readAtomically(e){let t=this.index,n=e();return n===void 0&&(this.index=t),n}parseWith(e){let t=e();if(this.index===this.input.length)return t}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(e){return this.readAtomically(()=>{let t=this.readChar();if(t===e)return t})}readSeparator(e,t,n){return this.readAtomically(()=>{if(!(t>0&&this.readGivenChar(e)===void 0))return n()})}readNumber(e,t,n,o){return this.readAtomically(()=>{let s=0,i=0,a=this.peekChar();if(a===void 0)return;let u=a==="0",c=2**(8*o)-1;for(;;){let h=this.readAtomically(()=>{let l=this.readChar();if(l===void 0)return;let f=Number.parseInt(l,e);if(!Number.isNaN(f))return f});if(h===void 0)break;if(s*=e,s+=h,s>c||(i+=1,t!==void 0&&i>t))return}if(i!==0)return!n&&u&&i>1?void 0:s})}readIPv4Addr(){return this.readAtomically(()=>{let e=new Uint8Array(4);for(let t=0;t<e.length;t++){let n=this.readSeparator(".",t,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;e[t]=n}return e})}readIPv6Addr(){let e=t=>{for(let n=0;n<t.length/2;n++){let o=n*2;if(n<t.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return t[o]=i[0],t[o+1]=i[1],t[o+2]=i[2],t[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];t[o]=s>>8,t[o+1]=s&255}return[t.length,!1]};return this.readAtomically(()=>{let t=new Uint8Array(16),[n,o]=e(t);if(n===16)return t;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let s=new Uint8Array(14),i=16-(n+2),[a]=e(s.subarray(0,i));return t.set(s.subarray(0,a),16-a),t})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var Ms=45,Bs=15,Qe=new Xe;function vn(r){if(!(r.length>Bs))return Qe.new(r).parseWith(()=>Qe.readIPv4Addr())}function Cn(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>Ms))return Qe.new(r).parseWith(()=>Qe.readIPv6Addr())}function we(r){return!!vn(r)}function Je(r){return!!Cn(r)}var Dn=po(Sn(),1),Vs=["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"],zs=Vs.map(r=>new Dn.Netmask(r));function er(r){for(let e of zs)if(e.contains(r))return!0;return!1}function ks(r){return/^::ffff:([0-9a-fA-F]{1,4}):([0-9a-fA-F]{1,4})$/.test(r)}function $s(r){let e=r.split(":");if(e.length<2)return!1;let t=e[e.length-1].padStart(4,"0"),n=e[e.length-2].padStart(4,"0"),o=`${parseInt(n.substring(0,2),16)}.${parseInt(n.substring(2),16)}.${parseInt(t.substring(0,2),16)}.${parseInt(t.substring(2),16)}`;return er(o)}function Ws(r){return/^::ffff:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(r)}function Gs(r){let e=r.split(":"),t=e[e.length-1];return er(t)}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 Tn(r){if(we(r))return er(r);if(ks(r))return $s(r);if(Ws(r))return Gs(r);if(Je(r))return js(r)}function An(r){try{let e=In(r);switch(e.type){case"ip4":case"ip6":return Tn(e.host)??!1;default:return e.host==="localhost"}}catch{return!1}}var tr=class extends Error{constructor(e){super(e),this.name="TimeoutError"}},rr=class extends Error{constructor(e){super(),this.name="AbortError",this.message=e}},Ln=r=>globalThis.DOMException===void 0?new rr(r):new DOMException(r),Nn=r=>{let e=r.reason===void 0?Ln("This operation was aborted."):r.reason;return e instanceof Error?e:Ln(e)};function nr(r,e){let{milliseconds:t,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout}}=e,i,a,c=new Promise((h,l)=>{if(typeof t!="number"||Math.sign(t)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${t}\``);if(e.signal){let{signal:p}=e;p.aborted&&l(Nn(p)),a=()=>{l(Nn(p))},p.addEventListener("abort",a,{once:!0})}if(t===Number.POSITIVE_INFINITY){r.then(h,l);return}let f=new tr;i=s.setTimeout.call(void 0,()=>{if(n){try{h(n())}catch(p){l(p)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?h():o instanceof Error?l(o):(f.message=o??`Promise timed out after ${t} milliseconds`,l(f))},t),(async()=>{try{h(await r)}catch(p){l(p)}})()}).finally(()=>{c.clear(),a&&e.signal&&e.signal.removeEventListener("abort",a)});return c.clear=()=>{s.clearTimeout.call(void 0,i),i=void 0},c}var qs=r=>{let e=r.addEventListener||r.on||r.addListener,t=r.removeEventListener||r.off||r.removeListener;if(!e||!t)throw new TypeError("Emitter is not compatible");return{addListener:e.bind(r),removeListener:t.bind(r)}};function Hs(r,e,t){let n,o=new Promise((s,i)=>{if(t={rejectionEvents:["error"],multiArgs:!1,rejectionMultiArgs:!1,resolveImmediately:!1,...t},!(t.count>=0&&(t.count===Number.POSITIVE_INFINITY||Number.isInteger(t.count))))throw new TypeError("The `count` option should be at least 0 or more");t.signal?.throwIfAborted();let a=[e].flat(),u=[],{addListener:c,removeListener:h}=qs(r),l=async(...p)=>{let m=t.multiArgs?p:p[0];if(t.filter)try{if(!await t.filter(m))return}catch(v){n(),i(v);return}u.push(m),t.count===u.length&&(n(),s(u))},f=(...p)=>{n(),i(t.rejectionMultiArgs?p:p[0])};n=()=>{for(let p of a)h(p,l);for(let p of t.rejectionEvents)a.includes(p)||h(p,f)};for(let p of a)c(p,l);for(let p of t.rejectionEvents)a.includes(p)||c(p,f);t.signal&&t.signal.addEventListener("abort",()=>{f(t.signal.reason)},{once:!0}),t.resolveImmediately&&s(u)});if(o.cancel=n,typeof t.timeout=="number"){let s=nr(o,{milliseconds:t.timeout});return s.cancel=()=>{n(),s.clear()},s}return o}function _n(r,e,t){typeof t=="function"&&(t={filter:t}),t={...t,count:1,resolveImmediately:!1};let n=Hs(r,e,t),o=n.then(s=>s[0]);return o.cancel=n.cancel,o}var se=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"};function Xs(r){return r.reason}async function Pn(r,e,t){if(e==null)return r;let n=t?.translateError??Xs;if(e.aborted)return r.catch(()=>{}),Promise.reject(n(e));let o;try{return await Promise.race([r,new Promise((s,i)=>{o=()=>{i(n(e))},e.addEventListener("abort",o)})])}finally{o!=null&&e.removeEventListener("abort",o)}}var S=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},q=class extends Error{static name="ValidationError";name="ValidationError"},Ke=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},Ze=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};function sr(r){return e=>re(e,r)}function ir(r){return e=>te(e,r)}function ye(r){return new DataView(r.buffer).getUint16(r.byteOffset).toString()}function ie(r){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,typeof r=="string"?parseInt(r):r),new Uint8Array(e)}function On(r){let e=r.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==16)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion address.`);let t=te(e[0],"base32"),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=ie(n);return K([t,o],t.length+o.length)}function Un(r){let e=r.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==56)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion3 address.`);let t=J.decode(`b${e[0]}`),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=ie(n);return K([t,o],t.length+o.length)}function ar(r){let e=r.subarray(0,r.length-2),t=r.subarray(r.length-2),n=re(e,"base32"),o=ye(t);return`${n}:${o}`}var cr=function(r){r=r.toString().trim();let e=new Uint8Array(4);return r.split(/\./g).forEach((t,n)=>{let o=parseInt(t,10);if(isNaN(o)||o<0||o>255)throw new S("Invalid byte value in IP address");e[n]=o}),e},Fn=function(r){let e=0;r=r.toString().trim();let t=r.split(":",8),n;for(n=0;n<t.length;n++){let s=we(t[n]),i;s&&(i=cr(t[n]),t[n]=re(i.subarray(0,2),"base16")),i!=null&&++n<8&&t.splice(n,0,re(i.subarray(2,4),"base16"))}if(t[0]==="")for(;t.length<8;)t.unshift("0");else if(t[t.length-1]==="")for(;t.length<8;)t.push("0");else if(t.length<8){for(n=0;n<t.length&&t[n]!=="";n++);let s=[n,1];for(n=9-t.length;n>0;n--)s.push("0");t.splice.apply(t,s)}let o=new Uint8Array(e+16);for(n=0;n<t.length;n++){t[n]===""&&(t[n]="0");let s=parseInt(t[n],16);if(isNaN(s)||s<0||s>65535)throw new S("Invalid byte value in IP address");o[e++]=s>>8&255,o[e++]=s&255}return o},Rn=function(r){if(r.byteLength!==4)throw new S("IPv4 address was incorrect length");let e=[];for(let t=0;t<r.byteLength;t++)e.push(r[t]);return e.join(".")},Mn=function(r){if(r.byteLength!==16)throw new S("IPv6 address was incorrect length");let e=[];for(let n=0;n<r.byteLength;n+=2){let o=r[n],s=r[n+1],i=`${o.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}`;e.push(i)}let t=e.join(":");try{let n=new URL(`http://[${t}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new S(`Invalid IPv6 address "${t}"`)}};function Bn(r){try{let e=new URL(`http://[${r}]`);return e.hostname.substring(1,e.hostname.length-1)}catch{throw new S(`Invalid IPv6 address "${r}"`)}}var or=Object.values(Ne).map(r=>r.decoder),Qs=(function(){let r=or[0].or(or[1]);return or.slice(2).forEach(e=>r=r.or(e)),r})();function Vn(r){return Qs.decode(r)}function zn(r){return e=>r.encoder.encode(e)}function Js(r){if(parseInt(r).toString()!==r)throw new q("Value must be an integer")}function Ks(r){if(r<0)throw new q("Value must be a positive integer, or zero")}function Zs(r){return e=>{if(e>r)throw new q(`Value must be smaller than or equal to ${r}`)}}function Ys(...r){return e=>{for(let t of r)t(e)}}var Fe=Ys(Js,Ks,Zs(65535));var C=-1,ur=class{protocolsByCode=new Map;protocolsByName=new Map;getProtocol(e){let t;if(typeof e=="string"?t=this.protocolsByName.get(e):t=this.protocolsByCode.get(e),t==null)throw new Ze(`Protocol ${e} was unknown`);return t}addProtocol(e){this.protocolsByCode.set(e.code,e),this.protocolsByName.set(e.name,e),e.aliases?.forEach(t=>{this.protocolsByName.set(t,e)})}removeProtocol(e){let t=this.protocolsByCode.get(e);t!=null&&(this.protocolsByCode.delete(t.code),this.protocolsByName.delete(t.name),t.aliases?.forEach(n=>{this.protocolsByName.delete(n)}))}},H=new ur,pi=[{code:4,name:"ip4",size:32,valueToBytes:cr,bytesToValue:Rn,validate:r=>{if(!we(r))throw new q(`Invalid IPv4 address "${r}"`)}},{code:6,name:"tcp",size:16,valueToBytes:ie,bytesToValue:ye,validate:Fe},{code:273,name:"udp",size:16,valueToBytes:ie,bytesToValue:ye,validate:Fe},{code:33,name:"dccp",size:16,valueToBytes:ie,bytesToValue:ye,validate:Fe},{code:41,name:"ip6",size:128,valueToBytes:Fn,bytesToValue:Mn,stringToValue:Bn,validate:r=>{if(!Je(r))throw new q(`Invalid IPv6 address "${r}"`)}},{code:42,name:"ip6zone",size:C},{code:43,name:"ipcidr",size:8,bytesToValue:sr("base10"),valueToBytes:ir("base10")},{code:53,name:"dns",size:C},{code:54,name:"dns4",size:C},{code:55,name:"dns6",size:C},{code:56,name:"dnsaddr",size:C},{code:132,name:"sctp",size:16,valueToBytes:ie,bytesToValue:ye,validate:Fe},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:C,stringToValue:r=>decodeURIComponent(r),valueToString:r=>encodeURIComponent(r)},{code:421,name:"p2p",aliases:["ipfs"],size:C,bytesToValue:sr("base58btc"),valueToBytes:r=>r.startsWith("Q")||r.startsWith("1")?ir("base58btc")(r):ge.parse(r).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:ar,valueToBytes:On},{code:445,name:"onion3",size:296,bytesToValue:ar,valueToBytes:Un},{code:446,name:"garlic64",size:C},{code:447,name:"garlic32",size:C},{code:448,name:"tls"},{code:449,name:"sni",size:C},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:C,bytesToValue:zn(Dt),valueToBytes:Vn},{code:480,name:"http"},{code:481,name:"http-path",size:C,stringToValue:r=>`/${decodeURIComponent(r)}`,valueToString:r=>encodeURIComponent(r.substring(1))},{code:443,name:"https"},{code:477,name:"ws"},{code:478,name:"wss"},{code:479,name:"p2p-websocket-star"},{code:277,name:"p2p-stardust"},{code:275,name:"p2p-webrtc-star"},{code:276,name:"p2p-webrtc-direct"},{code:280,name:"webrtc-direct"},{code:281,name:"webrtc"},{code:290,name:"p2p-circuit"},{code:777,name:"memory",size:C}];pi.forEach(r=>{H.addProtocol(r)});function kn(r){let e=[],t=0;for(;t<r.length;){let n=_e(r,t),o=H.getProtocol(n),s=N(n),i=mi(o,r,t+s),a=0;i>0&&o.size===C&&(a=N(i));let u=s+a+i,c={code:n,name:o.name,bytes:r.subarray(t,t+u)};if(i>0){let h=t+s+a,l=r.subarray(h,h+i);c.value=o.bytesToValue?.(l)??re(l)}e.push(c),t+=u}return e}function $n(r){let e=0,t=[];for(let n of r){if(n.bytes==null){let o=H.getProtocol(n.code),s=N(n.code),i,a=0,u=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??te(n.value),a=i.byteLength,o.size===C&&(u=N(a)));let c=new Uint8Array(s+u+a),h=0;be(n.code,c,h),h+=s,i!=null&&(o.size===C&&(be(a,c,h),h+=u),c.set(i,h)),n.bytes=c}t.push(n.bytes),e+=n.bytes.byteLength}return K(t,e)}function Wn(r){if(r.charAt(0)!=="/")throw new S('String multiaddr must start with "/"');let e=[],t="protocol",n="",o="";for(let s=1;s<r.length;s++){let i=r.charAt(s);i!=="/"&&(t==="protocol"?o+=r.charAt(s):n+=r.charAt(s));let a=s===r.length-1;if(i==="/"||a){let u=H.getProtocol(o);if(t==="protocol"){if(u.size==null||u.size===0){e.push({code:u.code,name:u.name}),n="",o="",t="protocol";continue}else if(a)throw new S(`Component ${o} was missing value`);t="value"}else if(t==="value"){let c={code:u.code,name:u.name};if(u.size!=null&&u.size!==0){if(n==="")throw new S(`Component ${o} was missing value`);c.value=u.stringToValue?.(n)??n}e.push(c),n="",o="",t="protocol"}}}if(o!==""&&n!=="")throw new S("Incomplete multiaddr");return e}function Gn(r){return`/${r.flatMap(e=>{if(e.value==null)return e.name;let t=H.getProtocol(e.code);if(t==null)throw new S(`Unknown protocol code ${e.code}`);return[e.name,t.valueToString?.(e.value)??e.value]}).join("/")}`}function mi(r,e,t){return r.size==null||r.size===0?0:r.size>0?r.size/8:_e(e,t)}var gi=Symbol.for("nodejs.util.inspect.custom"),Dr=Symbol.for("@multiformats/multiaddr");function bi(r){if(r==null&&(r="/"),jn(r))return r.getComponents();if(r instanceof Uint8Array)return kn(r);if(typeof r=="string")return r=r.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),r===""&&(r="/"),Wn(r);if(Array.isArray(r))return r;throw new S("Must be a string, Uint8Array, Component[], or another Multiaddr")}var nt=class r{[Dr]=!0;#e;#t;#r;constructor(e="/",t={}){this.#e=bi(e),t.validate!==!1&&xi(this)}get bytes(){return this.#r==null&&(this.#r=$n(this.#e)),this.#r}toString(){return this.#t==null&&(this.#t=Gn(this.#e)),this.#t}toJSON(){return this.toString()}getComponents(){return[...this.#e.map(e=>({...e}))]}encapsulate(e){let t=new r(e);return new r([...this.#e,...t.getComponents()],{validate:!1})}decapsulate(e){let t=e.toString(),n=this.toString(),o=n.lastIndexOf(t);if(o<0)throw new Ke(`Address ${this.toString()} does not contain subaddress: ${t}`);return new r(n.slice(0,o),{validate:!1})}decapsulateCode(e){let t;for(let n=this.#e.length-1;n>-1;n--)if(this.#e[n].code===e){t=n;break}return new r(this.#e.slice(0,t),{validate:!1})}equals(e){return ke(this.bytes,e.bytes)}[gi](){return`Multiaddr(${this.toString()})`}};function xi(r){r.getComponents().forEach(e=>{let t=H.getProtocol(e.code);e.value!=null&&t.validate?.(e.value)})}function jn(r){return!!r?.[Dr]}function Tr(r){return new nt(r)}var yi=4194304,ot=class extends Error{static name="UnwrappedError";name="UnwrappedError"},Lr=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},Nr=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},_r=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function Ei(r){return typeof r?.closeRead=="function"}function Ii(r){return typeof r?.close=="function"}function Ar(r){return Ei(r)?r.remoteWriteStatus!=="writable"&&r.readBufferLength===0:Ii(r)?r.status!=="open":!1}function vi(r){return r?.addEventListener!=null&&r?.removeEventListener!=null&&r?.send!=null&&r?.push!=null&&r?.log!=null}function Ci(r,e){let t=e?.maxBufferSize??yi,n=new ee,o,s=!1;if(!vi(r))throw new le("Argument should be a Stream or a Multiaddr");let i=h=>{if(n.append(h.data),n.byteLength>t){let l=n.byteLength;n.consume(n.byteLength),o?.reject(new Error(`Read buffer overflow - ${l} > ${t}`))}o?.resolve()};r.addEventListener("message",i);let a=h=>{h.error!=null?o?.reject(h.error):o?.resolve()};r.addEventListener("close",a);let u=()=>{o?.resolve()};r.addEventListener("remoteCloseWrite",u);let c={readBuffer:n,async read(h){if(s===!0)throw new ot("Stream was unwrapped");if(Ar(r)){if(h?.bytes==null)return null;if(n.byteLength<h.bytes)throw r.log.error("closed after reading %d/%d bytes",n.byteLength,h.bytes),new se(`Unexpected EOF - stream closed after reading ${n.byteLength}/${h.bytes} bytes`)}let l=h?.bytes??1;for(o=Promise.withResolvers();;){if(n.byteLength>=l){o.resolve();break}if(await Pn(o.promise,h?.signal),Ar(r)){if(n.byteLength===0&&h?.bytes==null)return null;break}o=Promise.withResolvers()}let f=h?.bytes??n.byteLength;if(n.byteLength<f){if(Ar(r))throw r.log.error("closed while reading %d/%d bytes",n.byteLength,f),new se(`Unexpected EOF - stream closed while reading ${n.byteLength}/${f} bytes`);return c.read(h)}let p=n.sublist(0,f);return n.consume(f),p},async write(h,l){if(s===!0)throw new ot("Stream was unwrapped");r.send(h)||await _n(r,"drain",{signal:l?.signal,rejectionEvents:["close"]})},unwrap(){return s||(s=!0,r.removeEventListener("message",i),r.removeEventListener("close",a),r.removeEventListener("remoteCloseWrite",u),n.byteLength>0&&(r.log("stream unwrapped with %d unread bytes",n.byteLength),r.push(n))),r}};return c}function Si(r,e={}){let t=Ci(r,e);e.maxDataLength!=null&&e.maxLengthLength==null&&(e.maxLengthLength=N(e.maxDataLength));let n=e?.lengthDecoder??_e,o=e?.lengthEncoder??fn;return{async read(i){let a=-1,u=new ee;for(;;){let h=await t.read({...i,bytes:1});if(h==null)break;u.append(h);try{a=n(u)}catch(l){if(l instanceof RangeError)continue;throw l}if(a<0)throw new Lr("Invalid message length");if(e?.maxLengthLength!=null&&u.byteLength>e.maxLengthLength)throw new _r(`Message length length too long - ${u.byteLength} > ${e.maxLengthLength}`);if(a>-1)break}if(e?.maxDataLength!=null&&a>e.maxDataLength)throw new Nr(`Message length too long - ${a} > ${e.maxDataLength}`);let c=await t.read({...i,bytes:a});if(c==null)throw r.log.error("tried to read %d bytes but the stream closed",a),new se(`Unexpected EOF - tried to read ${a} bytes but the stream closed`);if(c.byteLength!==a)throw r.log.error("read %d/%d bytes before the stream closed",c.byteLength,a),new se(`Unexpected EOF - read ${c.byteLength}/${a} bytes before the stream closed`);return c},async write(i,a){await t.write(new ee(o(i.byteLength),i),a)},async writeV(i,a){let u=new ee(...i.flatMap(c=>[o(c.byteLength),c]));await t.write(u,a)},unwrap(){return t.unwrap()}}}function Pr(r,e){let t=Si(r,e),n={read:async(o,s)=>{let i=await t.read(s);return o.decode(i)},write:async(o,s,i)=>{await t.write(s.encode(o),i)},writeV:async(o,s,i)=>{await t.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:()=>t.unwrap()};return n}var qn=Symbol.for("sindresorhus/unlimited-timeout#brand");function Hn(r,e,...t){if(typeof r!="function")throw new TypeError("Expected callback to be a function");e??=0,e=Number(e);let n=!1,o={[qn]:!0,id:void 0,cleared:!1,ref(){return n=!1,o.id?.ref?.(),o},unref(){return n=!0,o.id?.unref?.(),o}};if(e===Number.POSITIVE_INFINITY||e>Number.MAX_SAFE_INTEGER)return o;(!Number.isFinite(e)||e<0)&&(e=0);let s=performance.now()+e,i=a=>{o.cleared||(a<=2147483647?(o.id=globalThis.setTimeout(()=>{o.cleared||r(...t)},a),n&&o.id?.unref?.()):(o.id=globalThis.setTimeout(()=>{let u=performance.now(),c=Math.max(0,s-u);i(c)},2147483647),n&&o.id?.unref?.()))};return i(e),o}function Xn(r){!r||typeof r!="object"||!r[qn]||(r.cleared=!0,r.id!==void 0&&(globalThis.clearTimeout(r.id),r.id=void 0))}var Di=new WeakMap;function Ti({clearTimeout:r,setTimeout:e}={}){return(t,{value:n,signal:o}={})=>{if(o?.aborted)return Promise.reject(o.reason);let s,i,a,u=r??clearTimeout,c=()=>{u(s),a(o.reason)},h=()=>{o&&o.removeEventListener("abort",c)},l=new Promise((f,p)=>{i=()=>{h(),f(n)},a=p,s=(e??setTimeout)(i,t)});return o&&o.addEventListener("abort",c,{once:!0}),Di.set(l,()=>{u(s),s=null,i()}),l}}var Ai=Ti({setTimeout:Hn,clearTimeout:Xn}),Qn=Ai;var y=r=>({match:e=>{let t=e[0];return t==null||t.code!==r||t.value!=null?!1:e.slice(1)}}),d=(r,e)=>({match:t=>{let n=t[0];return n?.code!==r||n.value==null||e!=null&&n.value!==e?!1:t.slice(1)}}),Jn=r=>({match:e=>r.match(e)===!1?e:!1}),g=r=>({match:e=>{let t=r.match(e);return t===!1?e:t}}),A=(...r)=>({match:e=>{let t;for(let n of r){let o=n.match(e);o!==!1&&(t==null||o.length<t.length)&&(t=o)}return t??!1}}),w=(...r)=>({match:e=>{for(let t of r){let n=t.match(e);if(n===!1)return!1;e=n}return e}});function E(...r){function e(o){if(o==null)return!1;let s=o.getComponents();for(let i of r){let a=i.match(s);if(a===!1)return!1;s=a}return s}function t(o){return e(o)!==!1}function n(o){let s=e(o);return s===!1?!1:s.length===0}return{matchers:r,matches:t,exactMatch:n}}var Li=d(421),Ll=E(Li),it=d(54),at=d(55),ct=d(56),Ur=d(53),Nl=E(it,g(d(421))),_l=E(at,g(d(421))),Pl=E(ct,g(d(421))),Kn=E(A(Ur,ct,it,at),g(d(421))),Zn=w(d(4),g(d(43))),Yn=w(g(d(42)),d(41),g(d(43))),Fr=A(Zn,Yn),ue=A(Fr,Ur,it,at,ct),Ol=E(A(Fr,w(A(Ur,ct,it,at),g(d(421))))),Ul=E(Zn),Fl=E(Yn),eo=E(Fr),Rr=w(ue,d(6)),Re=w(ue,d(273)),Rl=E(w(Rr,g(d(421)))),Ml=E(Re),Mr=w(Re,y(460),g(d(421))),ut=w(Re,y(461),g(d(421))),Ni=A(Mr,ut),Bl=E(Mr),Vl=E(ut),Or=A(ue,Rr,Re,Mr,ut),to=A(w(Or,y(477),g(d(421)))),zl=E(to),ro=A(w(Or,y(478),g(d(421))),w(Or,y(448),g(d(449)),y(477),g(d(421)))),kl=E(ro),no=w(Re,y(280),g(d(466)),g(d(466)),g(d(421))),$l=E(no),oo=w(ut,y(465),g(d(466)),g(d(466)),g(d(421))),Wl=E(oo),st=A(to,ro,w(Rr,g(d(421))),w(Ni,g(d(421))),w(ue,g(d(421))),no,oo,d(421)),Gl=E(st),_i=w(g(st),y(290),Jn(y(281)),g(d(421))),Me=E(_i),Pi=A(w(st,y(290),y(281),g(d(421))),w(st,y(281),g(d(421))),w(y(281),g(d(421)))),jl=E(Pi),Oi=A(w(ue,d(6),y(480),g(d(421))),w(ue,y(480),g(d(421)))),ql=E(Oi),Ui=w(ue,A(w(d(6,"443"),y(480)),w(d(6),y(443)),w(d(6),y(448),y(480)),w(y(448),y(480)),y(448),y(443)),g(d(421))),Hl=E(Ui),Fi=A(w(d(777),g(d(421)))),Xl=E(Fi),Ri=A(w(d(400),g(d(421)))),Ql=E(Ri);var M;(function(r){let e;(function(o){o.UNUSED="UNUSED",o.CONNECT="CONNECT",o.SYNC="SYNC"})(e=r.Type||(r.Type={}));let t;(function(o){o[o.UNUSED=0]="UNUSED",o[o.CONNECT=100]="CONNECT",o[o.SYNC=300]="SYNC"})(t||(t={})),(function(o){o.codec=()=>Zt(t)})(e=r.Type||(r.Type={}));let n;r.codec=()=>(n==null&&(n=Yt((o,s,i={})=>{if(i.lengthDelimited!==!1&&s.fork(),o.type!=null&&(s.uint32(8),r.Type.codec().encode(o.type,s)),o.observedAddresses!=null)for(let a of o.observedAddresses)s.uint32(18),s.bytes(a);i.lengthDelimited!==!1&&s.ldelim()},(o,s,i={})=>{let a={observedAddresses:[]},u=s==null?o.len:o.pos+s;for(;o.pos<u;){let c=o.uint32();switch(c>>>3){case 1:{a.type=r.Type.codec().decode(o);break}case 2:{if(i.limits?.observedAddresses!=null&&a.observedAddresses.length===i.limits.observedAddresses)throw new He('Decode error - map field "observedAddresses" had too many elements');a.observedAddresses.push(o.bytes());break}default:{o.skipType(c&7);break}}}return a})),n),r.encode=o=>Kt(o,r.codec()),r.decode=(o,s)=>Gt(o,r.codec(),s)})(M||(M={}));function Br(r,e){return Me.matches(r)||e.dialTransportForMultiaddr(r)==null?!1:Kn.matches(r)?!0:eo.matches(r)?!An(r):!1}var so=1024*4,io=100,lt={timeout:5e3,retries:3,maxInboundStreams:1,maxOutboundStreams:1},ht=class{started;timeout;retries;maxInboundStreams;maxOutboundStreams;peerStore;registrar;connectionManager;addressManager;transportManager;topologyId;log;constructor(e,t){this.log=e.logger.forComponent("libp2p:dcutr"),this.started=!1,this.peerStore=e.peerStore,this.registrar=e.registrar,this.addressManager=e.addressManager,this.connectionManager=e.connectionManager,this.transportManager=e.transportManager,this.timeout=t.timeout??lt.timeout,this.retries=t.retries??lt.retries,this.maxInboundStreams=t.maxInboundStreams??lt.maxInboundStreams,this.maxOutboundStreams=t.maxOutboundStreams??lt.maxOutboundStreams,this.handleIncomingUpgrade=this.handleIncomingUpgrade.bind(this)}[Symbol.toStringTag]="@libp2p/dcutr";[zr]=["@libp2p/identify"];isStarted(){return this.started}async start(){this.started||(this.topologyId=await this.registrar.register(Ce,{notifyOnLimitedConnection:!0,onConnect:(e,t)=>{Me.exactMatch(t.remoteAddr)&&t.direction==="inbound"&&this.upgradeInbound(t).catch(n=>{this.log.error("error during outgoing DCUtR attempt - %e",n)})}}),await this.registrar.handle(Ce,this.handleIncomingUpgrade,{maxInboundStreams:this.maxInboundStreams,maxOutboundStreams:this.maxOutboundStreams,runOnLimitedConnection:!0}),this.started=!0)}async stop(){await this.registrar.unhandle(Ce),this.topologyId!=null&&this.registrar.unregister(this.topologyId),this.started=!1}async upgradeInbound(e){if(await this.attemptUnilateralConnectionUpgrade(e))return;let t;for(let n=0;n<this.retries;n++){let o={signal:AbortSignal.timeout(this.timeout)};try{t=await e.newStream([Ce],{signal:o.signal,runOnLimitedConnection:!0});let s=Pr(t,{maxDataLength:so}).pb(M);this.log("B sending connect to %p",e.remotePeer);let i=Date.now();await s.write({type:M.Type.CONNECT,observedAddresses:this.addressManager.getAddresses().map(l=>l.bytes)},o),this.log("B receiving connect from %p",e.remotePeer);let a=await s.read(o);if(a.type!==M.Type.CONNECT)throw this.log("A sent wrong message type"),new W("DCUtR message type was incorrect");let u=this.getDialableMultiaddrs(a.observedAddresses);if(u.length===0)throw this.log("A did not have any dialable multiaddrs"),new W("DCUtR connect message had no multiaddrs");let c=Date.now()-i;this.log("A sending sync, rtt %dms",c),await s.write({type:M.Type.SYNC,observedAddresses:[]},o),this.log("A waiting for half RTT"),await Qn(c/2),this.log("B dialing",u);let h=await this.connectionManager.openConnection(u,{signal:o.signal,priority:io,force:!0,initiator:!1});this.log("DCUtR to %p succeeded to address %a, closing relayed connection",e.remotePeer,h.remoteAddr),await e.close(o);break}catch(s){if(this.log.error("error while attempting DCUtR on attempt %d of %d - %e",n+1,this.retries,s),t?.abort(s),n===this.retries)throw s}finally{t!=null&&await t.close(o)}}}async attemptUnilateralConnectionUpgrade(e){let n=(await this.peerStore.get(e.remotePeer)).addresses.map(o=>{let s=o.multiaddr;return s.getComponents().find(i=>i.code===421)?.value==null?s.encapsulate(`/p2p/${e.remotePeer}`):s}).filter(o=>Br(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(Me.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",e.remotePeer,s.remoteAddr),await e.close({signal:o}),!0}catch(s){this.log.error("unilateral connection upgrade to %p on addresses %a failed - %e",e.remotePeer,n,s)}}else this.log("peer %p has no public addresses, not attempting unilateral connection upgrade",e.remotePeer);return!1}async handleIncomingUpgrade(e,t){let n={signal:AbortSignal.timeout(this.timeout)},o=Pr(e,{maxDataLength:so}).pb(M);this.log("A receiving connect");let s=await o.read(n);if(s.type!==M.Type.CONNECT)throw this.log("B sent wrong message type"),new W("DCUtR message type was incorrect");if(s.observedAddresses.length===0)throw this.log("B sent no multiaddrs"),new W("DCUtR connect message had no multiaddrs");let i=this.getDialableMultiaddrs(s.observedAddresses);if(i.length===0)throw this.log("B had no dialable multiaddrs in %o",s.observedAddresses.map(c=>Tr(c))),new W("DCUtR connect message had no dialable multiaddrs");if(this.log("A sending connect"),await o.write({type:M.Type.CONNECT,observedAddresses:this.addressManager.getAddresses().map(c=>c.bytes)}),this.log("A receiving sync"),(await o.read(n)).type!==M.Type.SYNC)throw new W("DCUtR message type was incorrect");this.log("A dialing",i);let u=await this.connectionManager.openConnection(i,{signal:n.signal,priority:io,force:!0});this.log("DCUtR to %p succeeded via %a, closing relayed connection",t.remotePeer,u.remoteAddr),await t.close(n),await e.close(n)}getDialableMultiaddrs(e){let t=[];for(let n of e)if(!(n==null||n.length===0))try{let o=Tr(n);if(!Br(o,this.transportManager))continue;t.push(o)}catch{}return t}};var Ce="/libp2p/dcutr";function Mi(r={}){return e=>new ht(e,r)}return mo(Bi);})();
|
|
2
|
+
"use strict";var Libp2PDcutr=(()=>{var ao=Object.create;var Ve=Object.defineProperty;var co=Object.getOwnPropertyDescriptor;var uo=Object.getOwnPropertyNames;var lo=Object.getPrototypeOf,ho=Object.prototype.hasOwnProperty;var fo=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),_=(r,e)=>{for(var t in e)Ve(r,t,{get:e[t],enumerable:!0})},zr=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of uo(e))!ho.call(r,o)&&o!==t&&Ve(r,o,{get:()=>e[o],enumerable:!(n=co(e,o))||n.enumerable});return r};var po=(r,e,t)=>(t=r!=null?ao(lo(r)):{},zr(e||!r||!r.__esModule?Ve(t,"default",{value:r,enumerable:!0}):t,r)),mo=r=>zr(Ve({},"__esModule",{value:!0}),r);var Dn=fo(Ue=>{(function(){var r,e,t,n,o,s,i,a;a=function(u){var c,h,l,f;return c=(u&255<<24)>>>24,h=(u&255<<16)>>>16,l=(u&65280)>>>8,f=u&255,[c,h,l,f].join(".")},i=function(u){var c,h,l,f,p,m;for(c=[],l=f=0;f<=3&&u.length!==0;l=++f){if(l>0){if(u[0]!==".")throw new Error("Invalid IP");u=u.substring(1)}m=e(u),p=m[0],h=m[1],u=u.substring(h),c.push(p)}if(u.length!==0)throw new Error("Invalid IP");switch(c.length){case 1:if(c[0]>4294967295)throw new Error("Invalid IP");return c[0]>>>0;case 2:if(c[0]>255||c[1]>16777215)throw new Error("Invalid IP");return(c[0]<<24|c[1])>>>0;case 3:if(c[0]>255||c[1]>255||c[2]>65535)throw new Error("Invalid IP");return(c[0]<<24|c[1]<<16|c[2])>>>0;case 4:if(c[0]>255||c[1]>255||c[2]>255||c[3]>255)throw new Error("Invalid IP");return(c[0]<<24|c[1]<<16|c[2]<<8|c[3])>>>0;default:throw new Error("Invalid IP")}},t=function(u){return u.charCodeAt(0)},n=t("0"),s=t("a"),o=t("A"),e=function(u){var c,h,l,f,p;for(f=0,c=10,h="9",l=0,u.length>1&&u[l]==="0"&&(u[l+1]==="x"||u[l+1]==="X"?(l+=2,c=16):"0"<=u[l+1]&&u[l+1]<="9"&&(l++,c=8,h="7")),p=l;l<u.length;){if("0"<=u[l]&&u[l]<=h)f=f*c+(t(u[l])-n)>>>0;else if(c===16)if("a"<=u[l]&&u[l]<="f")f=f*c+(10+t(u[l])-s)>>>0;else if("A"<=u[l]&&u[l]<="F")f=f*c+(10+t(u[l])-o)>>>0;else break;else break;if(f>4294967295)throw new Error("too large");l++}if(l===p)throw new Error("empty octet");return[f,l]},r=(function(){function u(c,h){var l,f,p,m;if(typeof c!="string")throw new Error("Missing `net' parameter");if(h||(m=c.split("/",2),c=m[0],h=m[1]),h||(h=32),typeof h=="string"&&h.indexOf(".")>-1){try{this.maskLong=i(h)}catch(v){throw l=v,new Error("Invalid mask: "+h)}for(f=p=32;p>=0;f=--p)if(this.maskLong===4294967295<<32-f>>>0){this.bitmask=f;break}}else if(h||h===0)this.bitmask=parseInt(h,10),this.maskLong=0,this.bitmask>0&&(this.maskLong=4294967295<<32-this.bitmask>>>0);else throw new Error("Invalid mask: empty");try{this.netLong=(i(c)&this.maskLong)>>>0}catch(v){throw l=v,new Error("Invalid net address: "+c)}if(!(this.bitmask<=32))throw new Error("Invalid mask for ip4: "+h);this.size=Math.pow(2,32-this.bitmask),this.base=a(this.netLong),this.mask=a(this.maskLong),this.hostmask=a(~this.maskLong),this.first=this.bitmask<=30?a(this.netLong+1):this.base,this.last=this.bitmask<=30?a(this.netLong+this.size-2):a(this.netLong+this.size-1),this.broadcast=this.bitmask<=30?a(this.netLong+this.size-1):void 0}return u.prototype.contains=function(c){return typeof c=="string"&&(c.indexOf("/")>0||c.split(".").length!==4)&&(c=new u(c)),c instanceof u?this.contains(c.base)&&this.contains(c.broadcast||c.last):(i(c)&this.maskLong)>>>0===(this.netLong&this.maskLong)>>>0},u.prototype.next=function(c){return c==null&&(c=1),new u(a(this.netLong+this.size*c),this.mask)},u.prototype.forEach=function(c){var h,l,f;for(f=i(this.first),l=i(this.last),h=0;f<=l;)c(a(f),f,h),h++,f++},u.prototype.toString=function(){return this.base+"/"+this.bitmask},u})(),Ue.ip2long=i,Ue.long2ip=a,Ue.Netmask=r}).call(Ue)});var Bi={};_(Bi,{dcutr:()=>Mi,multicodec:()=>Ce});var le=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}};var W=class extends Error{static name="InvalidMessageError";constructor(e="Invalid message"){super(e),this.name="InvalidMessageError"}};var ki=Symbol.for("@libp2p/service-capabilities"),kr=Symbol.for("@libp2p/service-dependencies");var gt={};_(gt,{base58btc:()=>k,base58flickr:()=>Io});var da=new Uint8Array(0);function $r(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])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 Wr(r){return new TextEncoder().encode(r)}function Gr(r){return new TextDecoder().decode(r)}function go(r,e){if(r.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),n=0;n<t.length;n++)t[n]=255;for(var o=0;o<r.length;o++){var s=r.charAt(o),i=s.charCodeAt(0);if(t[i]!==255)throw new TypeError(s+" is ambiguous");t[i]=o}var a=r.length,u=r.charAt(0),c=Math.log(a)/Math.log(256),h=Math.log(256)/Math.log(a);function l(m){if(m instanceof Uint8Array||(ArrayBuffer.isView(m)?m=new Uint8Array(m.buffer,m.byteOffset,m.byteLength):Array.isArray(m)&&(m=Uint8Array.from(m))),!(m instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(m.length===0)return"";for(var v=0,Y=0,U=0,B=m.length;U!==B&&m[U]===0;)U++,v++;for(var V=(B-U)*h+1>>>0,O=new Uint8Array(V);U!==B;){for(var z=m[U],X=0,F=V-1;(z!==0||X<Y)&&F!==-1;F--,X++)z+=256*O[F]>>>0,O[F]=z%a>>>0,z=z/a>>>0;if(z!==0)throw new Error("Non-zero carry");Y=X,U++}for(var $=V-Y;$!==V&&O[$]===0;)$++;for(var Be=u.repeat(v);$<V;++$)Be+=r.charAt(O[$]);return Be}function f(m){if(typeof m!="string")throw new TypeError("Expected String");if(m.length===0)return new Uint8Array;var v=0;if(m[v]!==" "){for(var Y=0,U=0;m[v]===u;)Y++,v++;for(var B=(m.length-v)*c+1>>>0,V=new Uint8Array(B);m[v];){var O=t[m.charCodeAt(v)];if(O===255)return;for(var z=0,X=B-1;(O!==0||z<U)&&X!==-1;X--,z++)O+=a*V[X]>>>0,V[X]=O%256>>>0,O=O/256>>>0;if(O!==0)throw new Error("Non-zero carry");U=z,v++}if(m[v]!==" "){for(var F=B-U;F!==B&&V[F]===0;)F++;for(var $=new Uint8Array(Y+(B-F)),Be=Y;F!==B;)$[Be++]=V[F++];return $}}}function p(m){var v=f(m);if(v)return v;throw new Error(`Non-${e} character`)}return{encode:l,decodeUnsafe:f,decode:p}}var bo=go,xo=bo,qr=xo;var ft=class{name;prefix;baseEncode;constructor(e,t,n){this.name=e,this.prefix=t,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},dt=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,t,n){this.name=e,this.prefix=t;let o=t.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return Hr(this,e)}},pt=class{decoders;constructor(e){this.decoders=e}or(e){return Hr(this,e)}decode(e){let t=e[0],n=this.decoders[t];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Hr(r,e){return new pt({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var mt=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,t,n,o){this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=o,this.encoder=new ft(e,t,n),this.decoder=new dt(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function he({name:r,prefix:e,encode:t,decode:n}){return new mt(r,e,t,n)}function Q({name:r,prefix:e,alphabet:t}){let{encode:n,decode:o}=qr(t,r);return he({prefix:e,name:r,encode:n,decode:s=>G(o(s))})}function wo(r,e,t,n){let o=r.length;for(;r[o-1]==="=";)--o;let s=new Uint8Array(o*t/8|0),i=0,a=0,u=0;for(let c=0;c<o;++c){let h=e[r[c]];if(h===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<t|h,i+=t,i>=8&&(i-=8,s[u++]=255&a>>i)}if(i>=t||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function yo(r,e,t){let n=e[e.length-1]==="=",o=(1<<t)-1,s="",i=0,a=0;for(let u=0;u<r.length;++u)for(a=a<<8|r[u],i+=8;i>t;)i-=t,s+=e[o&a>>i];if(i!==0&&(s+=e[o&a<<t-i]),n)for(;(s.length*t&7)!==0;)s+="=";return s}function Eo(r){let e={};for(let t=0;t<r.length;++t)e[r[t]]=t;return e}function I({name:r,prefix:e,bitsPerChar:t,alphabet:n}){let o=Eo(n);return he({prefix:e,name:r,encode(s){return yo(s,n,t)},decode(s){return wo(s,o,t,r)}})}var k=Q({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Io=Q({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var bt={};_(bt,{base32:()=>J,base32hex:()=>Do,base32hexpad:()=>Ao,base32hexpadupper:()=>Lo,base32hexupper:()=>To,base32pad:()=>Co,base32padupper:()=>So,base32upper:()=>vo,base32z:()=>No});var J=I({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),vo=I({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Co=I({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),So=I({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Do=I({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),To=I({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Ao=I({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Lo=I({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),No=I({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var xt={};_(xt,{base36:()=>Se,base36upper:()=>_o});var Se=Q({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),_o=Q({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Po=Jr,Xr=128,Oo=127,Uo=~Oo,Fo=Math.pow(2,31);function Jr(r,e,t){e=e||[],t=t||0;for(var n=t;r>=Fo;)e[t++]=r&255|Xr,r/=128;for(;r&Uo;)e[t++]=r&255|Xr,r>>>=7;return e[t]=r|0,Jr.bytes=t-n+1,e}var Ro=wt,Mo=128,Qr=127;function wt(r,n){var t=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw wt.bytes=0,new RangeError("Could not decode varint");i=r[s++],t+=o<28?(i&Qr)<<o:(i&Qr)*Math.pow(2,o),o+=7}while(i>=Mo);return wt.bytes=s-n,t}var Bo=Math.pow(2,7),Vo=Math.pow(2,14),zo=Math.pow(2,21),ko=Math.pow(2,28),$o=Math.pow(2,35),Wo=Math.pow(2,42),Go=Math.pow(2,49),jo=Math.pow(2,56),qo=Math.pow(2,63),Ho=function(r){return r<Bo?1:r<Vo?2:r<zo?3:r<ko?4:r<$o?5:r<Wo?6:r<Go?7:r<jo?8:r<qo?9:10},Xo={encode:Po,decode:Ro,encodingLength:Ho},Qo=Xo,De=Qo;function Te(r,e=0){return[De.decode(r,e),De.decode.bytes]}function fe(r,e,t=0){return De.encode(r,e,t),e}function de(r){return De.encodingLength(r)}function me(r,e){let t=e.byteLength,n=de(r),o=n+de(t),s=new Uint8Array(o+t);return fe(r,s,0),fe(t,s,n),s.set(e,o),new pe(r,t,e,s)}function Kr(r){let e=G(r),[t,n]=Te(e),[o,s]=Te(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new pe(t,o,i,e)}function Zr(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&$r(r.bytes,t.bytes)}}var pe=class{code;size;digest;bytes;constructor(e,t,n,o){this.code=e,this.size=t,this.digest=n,this.bytes=o}};function Yr(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return Ko(t,yt(r),e??k.encoder);default:return Zo(t,yt(r),e??J.encoder)}}var en=new WeakMap;function yt(r){let e=en.get(r);if(e==null){let t=new Map;return en.set(r,t),t}return e}var ge=class r{code;version;multihash;bytes;"/";constructor(e,t,n,o){this.code=t,this.version=e,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:e,multihash:t}=this;if(e!==Le)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==Yo)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(t)}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:e,digest:t}=this.multihash,n=me(e,t);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(e){return r.equals(this,e)}static equals(e,t){let n=t;return n!=null&&e.code===n.code&&e.version===n.version&&Zr(e.multihash,n.multihash)}toString(e){return Yr(this,e)}toJSON(){return{"/":Yr(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let t=e;if(t instanceof r)return t;if(t["/"]!=null&&t["/"]===t.bytes||t.asCID===t){let{version:n,code:o,multihash:s,bytes:i}=t;return new r(n,o,s,i??tn(n,o,s.bytes))}else if(t[es]===!0){let{version:n,multihash:o,code:s}=t,i=Kr(o);return r.create(n,s,i)}else return null}static create(e,t,n){if(typeof t!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(t!==Le)throw new Error(`Version 0 CID must use dag-pb (code: ${Le}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let o=tn(e,t,n.bytes);return new r(e,t,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,Le,e)}static createV1(e,t){return r.create(1,e,t)}static decode(e){let[t,n]=r.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return t}static decodeFirst(e){let t=r.inspectBytes(e),n=t.size-t.multihashSize,o=G(e.subarray(n,n+t.multihashSize));if(o.byteLength!==t.multihashSize)throw new Error("Incorrect length");let s=o.subarray(t.multihashSize-t.digestSize),i=new pe(t.multihashCode,t.digestSize,s,o);return[t.version===0?r.createV0(i):r.createV1(t.codec,i),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[l,f]=Te(e.subarray(t));return t+=f,l},o=n(),s=Le;if(o===18?(o=0,t=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=t,a=n(),u=n(),c=t+u,h=c-i;return{version:o,codec:s,multihashCode:a,digestSize:u,multihashSize:h,size:c}}static parse(e,t){let[n,o]=Jo(e,t),s=r.decode(o);if(s.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return yt(s).set(n,e),s}};function Jo(r,e){switch(r[0]){case"Q":{let t=e??k;return[k.prefix,t.decode(`${k.prefix}${r}`)]}case k.prefix:{let t=e??k;return[k.prefix,t.decode(r)]}case J.prefix:{let t=e??J;return[J.prefix,t.decode(r)]}case Se.prefix:{let t=e??Se;return[Se.prefix,t.decode(r)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],e.decode(r)]}}}function Ko(r,e,t){let{prefix:n}=t;if(n!==k.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let o=e.get(n);if(o==null){let s=t.encode(r).slice(1);return e.set(n,s),s}else return o}function Zo(r,e,t){let{prefix:n}=t,o=e.get(n);if(o==null){let s=t.encode(r);return e.set(n,s),s}else return o}var Le=112,Yo=18;function tn(r,e,t){let n=de(r),o=n+de(e),s=new Uint8Array(o+t.byteLength);return fe(r,s,0),fe(e,s,n),s.set(t,o),s}var es=Symbol.for("@ipld/js-cid/CID");var Et={};_(Et,{identity:()=>ns});var rn=0,ts="identity",nn=G;function rs(r,e){if(e?.truncate!=null&&e.truncate!==r.byteLength){if(e.truncate<0||e.truncate>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,e.truncate)}return me(rn,nn(r))}var ns={code:rn,name:ts,encode:nn,digest:rs};function ke(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}function j(r=0){return new Uint8Array(r)}function L(r=0){return new Uint8Array(r)}function K(r,e){e==null&&(e=r.reduce((o,s)=>o+s.length,0));let t=L(e),n=0;for(let o of r)t.set(o,n),n+=o.length;return t}var sn=Symbol.for("@achingbrain/uint8arraylist");function on(r,e){if(e==null||e<0)throw new RangeError("index is out of bounds");let t=0;for(let n of r){let o=t+n.byteLength;if(e<o)return{buf:n,index:e-t};t=o}throw new RangeError("index is out of bounds")}function $e(r){return!!r?.[sn]}var ee=class r{bufs;length;[sn]=!0;constructor(...e){this.bufs=[],this.length=0,e.length>0&&this.appendAll(e)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...e){this.appendAll(e)}appendAll(e){let t=0;for(let n of e)if(n instanceof Uint8Array)t+=n.byteLength,this.bufs.push(n);else if($e(n))t+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=t}prepend(...e){this.prependAll(e)}prependAll(e){let t=0;for(let n of e.reverse())if(n instanceof Uint8Array)t+=n.byteLength,this.bufs.unshift(n);else if($e(n))t+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=t}get(e){let t=on(this.bufs,e);return t.buf[t.index]}set(e,t){let n=on(this.bufs,e);n.buf[n.index]=t}write(e,t=0){if(e instanceof Uint8Array)for(let n=0;n<e.length;n++)this.set(t+n,e[n]);else if($e(e))for(let n=0;n<e.length;n++)this.set(t+n,e.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(e){if(e=Math.trunc(e),!(Number.isNaN(e)||e<=0)){if(e===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(e>=this.bufs[0].byteLength)e-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(e),this.length-=e;break}}}slice(e,t){let{bufs:n,length:o}=this._subList(e,t);return K(n,o)}subarray(e,t){let{bufs:n,length:o}=this._subList(e,t);return n.length===1?n[0]:K(n,o)}sublist(e,t){let{bufs:n,length:o}=this._subList(e,t),s=new r;return s.length=o,s.bufs=[...n],s}_subList(e,t){if(e=e??0,t=t??this.length,e<0&&(e=this.length+e),t<0&&(t=this.length+t),e<0||t>this.length)throw new RangeError("index is out of bounds");if(e===t)return{bufs:[],length:0};if(e===0&&t===this.length)return{bufs:this.bufs,length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],a=o,u=a+i.byteLength;if(o=u,e>=u)continue;let c=e>=a&&e<u,h=t>a&&t<=u;if(c&&h){if(e===a&&t===u){n.push(i);break}let l=e-a;n.push(i.subarray(l,l+(t-e)));break}if(c){if(e===0){n.push(i);continue}n.push(i.subarray(e-a));continue}if(h){if(t===u){n.push(i);break}n.push(i.subarray(0,t-a));break}n.push(i)}return{bufs:n,length:t-e}}indexOf(e,t=0){if(!$e(e)&&!(e instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=e instanceof Uint8Array?e:e.subarray();if(t=Number(t??0),isNaN(t)&&(t=0),t<0&&(t=this.length+t),t<0&&(t=0),e.length===0)return t>this.length?this.length:t;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let l=0;l<s;l++)i[l]=-1;for(let l=0;l<o;l++)i[n[l]]=l;let a=i,u=this.byteLength-n.byteLength,c=n.byteLength-1,h;for(let l=t;l<=u;l+=h){h=0;for(let f=c;f>=0;f--){let p=this.get(l+f);if(n[f]!==p){h=Math.max(1,f-a[p]);break}}if(h===0)return l}return-1}getInt8(e){let t=this.subarray(e,e+1);return new DataView(t.buffer,t.byteOffset,t.byteLength).getInt8(0)}setInt8(e,t){let n=L(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,t),this.write(n,e)}getInt16(e,t){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,t)}setInt16(e,t,n){let o=j(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,t,n),this.write(o,e)}getInt32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,t)}setInt32(e,t,n){let o=j(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,t,n),this.write(o,e)}getBigInt64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,t)}setBigInt64(e,t,n){let o=j(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,t,n),this.write(o,e)}getUint8(e){let t=this.subarray(e,e+1);return new DataView(t.buffer,t.byteOffset,t.byteLength).getUint8(0)}setUint8(e,t){let n=L(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,t),this.write(n,e)}getUint16(e,t){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,t)}setUint16(e,t,n){let o=j(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,t,n),this.write(o,e)}getUint32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,t)}setUint32(e,t,n){let o=j(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,t,n),this.write(o,e)}getBigUint64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,t)}setBigUint64(e,t,n){let o=j(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,t,n),this.write(o,e)}getFloat32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,t)}setFloat32(e,t,n){let o=j(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,t,n),this.write(o,e)}getFloat64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,t)}setFloat64(e,t,n){let o=j(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,t,n),this.write(o,e)}equals(e){if(e==null||!(e instanceof r)||e.bufs.length!==this.bufs.length)return!1;for(let t=0;t<this.bufs.length;t++)if(!ke(this.bufs[t],e.bufs[t]))return!1;return!0}static fromUint8Arrays(e,t){let n=new r;return n.bufs=e,t==null&&(t=e.reduce((o,s)=>o+s.byteLength,0)),n.length=t,n}};var It={};_(It,{base10:()=>os});var os=Q({prefix:"9",name:"base10",alphabet:"0123456789"});var vt={};_(vt,{base16:()=>ss,base16upper:()=>is});var ss=I({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),is=I({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Ct={};_(Ct,{base2:()=>as});var as=I({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var St={};_(St,{base256emoji:()=>fs});var an=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),cs=an.reduce((r,e,t)=>(r[t]=e,r),[]),us=an.reduce((r,e,t)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return r[n]=t,r},[]);function ls(r){return r.reduce((e,t)=>(e+=cs[t],e),"")}function hs(r){let e=[];for(let t of r){let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);let o=us[n];if(o==null)throw new Error(`Non-base256emoji character: ${t}`);e.push(o)}return new Uint8Array(e)}var fs=he({prefix:"\u{1F680}",name:"base256emoji",encode:ls,decode:hs});var Tt={};_(Tt,{base64:()=>ds,base64pad:()=>ps,base64url:()=>Dt,base64urlpad:()=>ms});var ds=I({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),ps=I({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Dt=I({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),ms=I({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var At={};_(At,{base8:()=>gs});var gs=I({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Lt={};_(Lt,{identity:()=>bs});var bs=he({prefix:"\0",name:"identity",encode:r=>Gr(r),decode:r=>Wr(r)});var Ja=new TextEncoder,Ka=new TextDecoder;var Pt={};_(Pt,{sha256:()=>Es,sha512:()=>Is});var ys=20;function _t({name:r,code:e,encode:t,minDigestLength:n,maxDigestLength:o}){return new Nt(r,e,t,n,o)}var Nt=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,t,n,o,s){this.name=e,this.code=t,this.encode=n,this.minDigestLength=o??ys,this.maxDigestLength=s}digest(e,t){if(t?.truncate!=null){if(t.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&t.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(e instanceof Uint8Array){let n=this.encode(e);return n instanceof Uint8Array?cn(n,this.code,t?.truncate):n.then(o=>cn(o,this.code,t?.truncate))}else throw Error("Unknown type, must be binary type")}};function cn(r,e,t){if(t!=null&&t!==r.byteLength){if(t>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,t)}return me(e,r)}function ln(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var Es=_t({name:"sha2-256",code:18,encode:ln("SHA-256")}),Is=_t({name:"sha2-512",code:19,encode:ln("SHA-512")});var Ne={...Lt,...Ct,...At,...It,...vt,...bt,...xt,...gt,...Tt,...St},uc={...Pt,...Et};function fn(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var hn=fn("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Ot=fn("ascii","a",r=>{let e="a";for(let t=0;t<r.length;t++)e+=String.fromCharCode(r[t]);return e},r=>{r=r.substring(1);let e=L(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),vs={utf8:hn,"utf-8":hn,hex:Ne.base16,latin1:Ot,ascii:Ot,binary:Ot,...Ne},We=vs;function te(r,e="utf8"){let t=We[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.decoder.decode(`${t.prefix}${r}`)}function re(r,e="utf8"){let t=We[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.encoder.encode(r).substring(1)}var Cs=Math.pow(2,7),Ss=Math.pow(2,14),Ds=Math.pow(2,21),Ut=Math.pow(2,28),Ft=Math.pow(2,35),Rt=Math.pow(2,42),Mt=Math.pow(2,49),x=128,D=127;function N(r){if(r<Cs)return 1;if(r<Ss)return 2;if(r<Ds)return 3;if(r<Ut)return 4;if(r<Ft)return 5;if(r<Rt)return 6;if(r<Mt)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function be(r,e,t=0){switch(N(r)){case 8:e[t++]=r&255|x,r/=128;case 7:e[t++]=r&255|x,r/=128;case 6:e[t++]=r&255|x,r/=128;case 5:e[t++]=r&255|x,r/=128;case 4:e[t++]=r&255|x,r>>>=7;case 3:e[t++]=r&255|x,r>>>=7;case 2:e[t++]=r&255|x,r>>>=7;case 1:{e[t++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return e}function Ts(r,e,t=0){switch(N(r)){case 8:e.set(t++,r&255|x),r/=128;case 7:e.set(t++,r&255|x),r/=128;case 6:e.set(t++,r&255|x),r/=128;case 5:e.set(t++,r&255|x),r/=128;case 4:e.set(t++,r&255|x),r>>>=7;case 3:e.set(t++,r&255|x),r>>>=7;case 2:e.set(t++,r&255|x),r>>>=7;case 1:{e.set(t++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return e}function Bt(r,e){let t=r[e],n=0;if(n+=t&D,t<x||(t=r[e+1],n+=(t&D)<<7,t<x)||(t=r[e+2],n+=(t&D)<<14,t<x)||(t=r[e+3],n+=(t&D)<<21,t<x)||(t=r[e+4],n+=(t&D)*Ut,t<x)||(t=r[e+5],n+=(t&D)*Ft,t<x)||(t=r[e+6],n+=(t&D)*Rt,t<x)||(t=r[e+7],n+=(t&D)*Mt,t<x))return n;throw new RangeError("Could not decode varint")}function As(r,e){let t=r.get(e),n=0;if(n+=t&D,t<x||(t=r.get(e+1),n+=(t&D)<<7,t<x)||(t=r.get(e+2),n+=(t&D)<<14,t<x)||(t=r.get(e+3),n+=(t&D)<<21,t<x)||(t=r.get(e+4),n+=(t&D)*Ut,t<x)||(t=r.get(e+5),n+=(t&D)*Ft,t<x)||(t=r.get(e+6),n+=(t&D)*Rt,t<x)||(t=r.get(e+7),n+=(t&D)*Mt,t<x))return n;throw new RangeError("Could not decode varint")}function dn(r,e,t=0){return e==null&&(e=L(N(r))),e instanceof Uint8Array?be(r,e,t):Ts(r,e,t)}function _e(r,e=0){return r instanceof Uint8Array?Bt(r,e):As(r,e)}var Vt=new Float32Array([-0]),Z=new Uint8Array(Vt.buffer);function mn(r,e,t){Vt[0]=r,e[t]=Z[0],e[t+1]=Z[1],e[t+2]=Z[2],e[t+3]=Z[3]}function gn(r,e){return Z[0]=r[e],Z[1]=r[e+1],Z[2]=r[e+2],Z[3]=r[e+3],Vt[0]}var zt=new Float64Array([-0]),T=new Uint8Array(zt.buffer);function bn(r,e,t){zt[0]=r,e[t]=T[0],e[t+1]=T[1],e[t+2]=T[2],e[t+3]=T[3],e[t+4]=T[4],e[t+5]=T[5],e[t+6]=T[6],e[t+7]=T[7]}function xn(r,e){return T[0]=r[e],T[1]=r[e+1],T[2]=r[e+2],T[3]=r[e+3],T[4]=r[e+4],T[5]=r[e+5],T[6]=r[e+6],T[7]=r[e+7],zt[0]}var Ls=BigInt(Number.MAX_SAFE_INTEGER),Ns=BigInt(Number.MIN_SAFE_INTEGER),P=class r{lo;hi;constructor(e,t){this.lo=e|0,this.hi=t|0}toNumber(e=!1){if(!e&&this.hi>>>31>0){let t=~this.lo+1>>>0,n=~this.hi>>>0;return t===0&&(n=n+1>>>0),-(t+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(e=!1){if(e)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let t=~this.lo+1>>>0,n=~this.hi>>>0;return t===0&&(n=n+1>>>0),-(BigInt(t)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(e=!1){return this.toBigInt(e).toString()}zzEncode(){let e=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^e)>>>0,this.lo=(this.lo<<1^e)>>>0,this}zzDecode(){let e=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^e)>>>0,this.hi=(this.hi>>>1^e)>>>0,this}length(){let e=this.lo,t=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?t===0?e<16384?e<128?1:2:e<2097152?3:4:t<16384?t<128?5:6:t<2097152?7:8:n<128?9:10}static fromBigInt(e){if(e===0n)return ne;if(e<Ls&&e>Ns)return this.fromNumber(Number(e));let t=e<0n;t&&(e=-e);let n=e>>32n,o=e-(n<<32n);return t&&(n=~n|0n,o=~o|0n,++o>wn&&(o=0n,++n>wn&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(e){if(e===0)return ne;let t=e<0;t&&(e=-e);let n=e>>>0,o=(e-n)/4294967296>>>0;return t&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new r(n,o)}static from(e){return typeof e=="number"?r.fromNumber(e):typeof e=="bigint"?r.fromBigInt(e):typeof e=="string"?r.fromBigInt(BigInt(e)):e.low!=null||e.high!=null?new r(e.low>>>0,e.high>>>0):ne}},ne=new P(0,0);ne.toBigInt=function(){return 0n};ne.zzEncode=ne.zzDecode=function(){return this};ne.length=function(){return 1};var wn=4294967296n;function yn(r){let e=0,t=0;for(let n=0;n<r.length;++n)t=r.charCodeAt(n),t<128?e+=1:t<2048?e+=2:(t&64512)===55296&&(r.charCodeAt(n+1)&64512)===56320?(++n,e+=4):e+=3;return e}function En(r,e,t){if(t-e<1)return"";let o,s=[],i=0,a;for(;e<t;)a=r[e++],a<128?s[i++]=a:a>191&&a<224?s[i++]=(a&31)<<6|r[e++]&63:a>239&&a<365?(a=((a&7)<<18|(r[e++]&63)<<12|(r[e++]&63)<<6|r[e++]&63)-65536,s[i++]=55296+(a>>10),s[i++]=56320+(a&1023)):s[i++]=(a&15)<<12|(r[e++]&63)<<6|r[e++]&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 kt(r,e,t){let n=t,o,s;for(let i=0;i<r.length;++i)o=r.charCodeAt(i),o<128?e[t++]=o:o<2048?(e[t++]=o>>6|192,e[t++]=o&63|128):(o&64512)===55296&&((s=r.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,e[t++]=o>>18|240,e[t++]=o>>12&63|128,e[t++]=o>>6&63|128,e[t++]=o&63|128):(e[t++]=o>>12|224,e[t++]=o>>6&63|128,e[t++]=o&63|128);return t-n}function R(r,e){return RangeError(`index out of range: ${r.pos} + ${e??1} > ${r.len}`)}function Ge(r,e){return(r[e-4]|r[e-3]<<8|r[e-2]<<16|r[e-1]<<24)>>>0}var $t=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(e){this.buf=e,this.pos=0,this.len=e.length}uint32(){let e=4294967295;if(e=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(e=(e|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return e;if((this.pos+=5)>this.len)throw this.pos=this.len,R(this,10);return e}int32(){return this.uint32()|0}sint32(){let e=this.uint32();return e>>>1^-(e&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw R(this,4);return Ge(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw R(this,4);return Ge(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw R(this,4);let e=gn(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw R(this,4);let e=xn(this.buf,this.pos);return this.pos+=8,e}bytes(){let e=this.uint32(),t=this.pos,n=this.pos+e;if(n>this.len)throw R(this,e);return this.pos+=e,t===n?new Uint8Array(0):this.buf.subarray(t,n)}string(){let e=this.bytes();return En(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw R(this,e);this.pos+=e}else do if(this.pos>=this.len)throw R(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(e){switch(e){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(e=this.uint32()&7)!==4;)this.skipType(e);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${e} at offset ${this.pos}`)}return this}readLongVarint(){let e=new P(0,0),t=0;if(this.len-this.pos>4){for(;t<4;++t)if(e.lo=(e.lo|(this.buf[this.pos]&127)<<t*7)>>>0,this.buf[this.pos++]<128)return e;if(e.lo=(e.lo|(this.buf[this.pos]&127)<<28)>>>0,e.hi=(e.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return e;t=0}else{for(;t<3;++t){if(this.pos>=this.len)throw R(this);if(e.lo=(e.lo|(this.buf[this.pos]&127)<<t*7)>>>0,this.buf[this.pos++]<128)return e}return e.lo=(e.lo|(this.buf[this.pos++]&127)<<t*7)>>>0,e}if(this.len-this.pos>4){for(;t<5;++t)if(e.hi=(e.hi|(this.buf[this.pos]&127)<<t*7+3)>>>0,this.buf[this.pos++]<128)return e}else for(;t<5;++t){if(this.pos>=this.len)throw R(this);if(e.hi=(e.hi|(this.buf[this.pos]&127)<<t*7+3)>>>0,this.buf[this.pos++]<128)return e}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw R(this,8);let e=Ge(this.buf,this.pos+=4),t=Ge(this.buf,this.pos+=4);return new P(e,t)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let e=Bt(this.buf,this.pos);return this.pos+=N(e),e}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 Wt(r){return new $t(r instanceof Uint8Array?r:r.subarray())}function Gt(r,e,t){let n=Wt(r);return e.decode(n,void 0,t)}function jt(r){let e=r??8192,t=e>>>1,n,o=e;return function(i){if(i<1||i>t)return L(i);o+i>e&&(n=L(e),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var oe=class{fn;len;next;val;constructor(e,t,n){this.fn=e,this.len=t,this.next=void 0,this.val=n}};function qt(){}var Xt=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},_s=jt();function Ps(r){return globalThis.Buffer!=null?L(r):_s(r)}var Oe=class{len;head;tail;states;constructor(){this.len=0,this.head=new oe(qt,0,0),this.tail=this.head,this.states=null}_push(e,t,n){return this.tail=this.tail.next=new oe(e,t,n),this.len+=t,this}uint32(e){return this.len+=(this.tail=this.tail.next=new Qt((e=e>>>0)<128?1:e<16384?2:e<2097152?3:e<268435456?4:5,e)).len,this}int32(e){return e<0?this._push(je,10,P.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let t=P.fromBigInt(e);return this._push(je,t.length(),t)}uint64Number(e){return this._push(be,N(e),e)}uint64String(e){return this.uint64(BigInt(e))}int64(e){return this.uint64(e)}int64Number(e){return this.uint64Number(e)}int64String(e){return this.uint64String(e)}sint64(e){let t=P.fromBigInt(e).zzEncode();return this._push(je,t.length(),t)}sint64Number(e){let t=P.fromNumber(e).zzEncode();return this._push(je,t.length(),t)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(Ht,1,e?1:0)}fixed32(e){return this._push(Pe,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let t=P.fromBigInt(e);return this._push(Pe,4,t.lo)._push(Pe,4,t.hi)}fixed64Number(e){let t=P.fromNumber(e);return this._push(Pe,4,t.lo)._push(Pe,4,t.hi)}fixed64String(e){return this.fixed64(BigInt(e))}sfixed64(e){return this.fixed64(e)}sfixed64Number(e){return this.fixed64Number(e)}sfixed64String(e){return this.fixed64String(e)}float(e){return this._push(mn,4,e)}double(e){return this._push(bn,8,e)}bytes(e){let t=e.length>>>0;return t===0?this._push(Ht,1,0):this.uint32(t)._push(Us,t,e)}string(e){let t=yn(e);return t!==0?this.uint32(t)._push(kt,t,e):this._push(Ht,1,0)}fork(){return this.states=new Xt(this),this.head=this.tail=new oe(qt,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 oe(qt,0,0),this.len=0),this}ldelim(){let e=this.head,t=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=e.next,this.tail=t,this.len+=n),this}finish(){let e=this.head.next,t=Ps(this.len),n=0;for(;e!=null;)e.fn(e.val,t,n),n+=e.len,e=e.next;return t}};function Ht(r,e,t){e[t]=r&255}function Os(r,e,t){for(;r>127;)e[t++]=r&127|128,r>>>=7;e[t]=r}var Qt=class extends oe{next;constructor(e,t){super(Os,e,t),this.next=void 0}};function je(r,e,t){for(;r.hi!==0;)e[t++]=r.lo&127|128,r.lo=(r.lo>>>7|r.hi<<25)>>>0,r.hi>>>=7;for(;r.lo>127;)e[t++]=r.lo&127|128,r.lo=r.lo>>>7;e[t++]=r.lo}function Pe(r,e,t){e[t]=r&255,e[t+1]=r>>>8&255,e[t+2]=r>>>16&255,e[t+3]=r>>>24}function Us(r,e,t){e.set(r,t)}globalThis.Buffer!=null&&(Oe.prototype.bytes=function(r){let e=r.length>>>0;return this.uint32(e),e>0&&this._push(Fs,e,r),this},Oe.prototype.string=function(r){let e=globalThis.Buffer.byteLength(r);return this.uint32(e),e>0&&this._push(Rs,e,r),this});function Fs(r,e,t){e.set(r,t)}function Rs(r,e,t){r.length<40?kt(r,e,t):e.utf8Write!=null?e.utf8Write(r,t):e.set(te(r),t)}function Jt(){return new Oe}function Kt(r,e){let t=Jt();return e.encode(r,t,{lengthDelimited:!1}),t.finish()}var xe;(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"})(xe||(xe={}));function qe(r,e,t,n){return{name:r,type:e,encode:t,decode:n}}function Zt(r){function e(o){if(r[o.toString()]==null)throw new Error("Invalid enum value");return r[o]}let t=function(s,i){let a=e(s);i.int32(a)},n=function(s){let i=s.int32();return e(i)};return qe("enum",xe.VARINT,t,n)}function Yt(r,e){return qe("message",xe.LENGTH_DELIMITED,r,e)}var He=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};function vn(r){let e=r.getComponents(),t={},n=0;if(e[n]?.name==="ip6zone"&&(t.zone=`${e[n].value}`,n++),e[n].name==="ip4"||e[n].name==="ip6"||e[n].name==="dns"||e[n].name==="dns4"||e[n].name==="dns6"?(t.type=e[n].name,t.host=e[n].value,n++):e[n].name==="dnsaddr"&&(t.type=e[n].name,t.host=`_dnsaddr.${e[n].value}`,n++),(e[n]?.name==="tcp"||e[n]?.name==="udp")&&(t.protocol=e[n].name==="tcp"?"tcp":"udp",t.port=parseInt(`${e[n].value}`),n++),e[n]?.name==="ipcidr"&&(t.type==="ip4"?t.cidr=parseInt(`${e[n].value}`):t.type==="ip6"&&(t.cidr=`${e[n].value}`),n++),t.type==null||t.host==null)throw new le(`Multiaddr ${r} was not an IPv4, IPv6, DNS, DNS4, DNS6 or DNSADDR address`);return e[n]?.name==="tls"&&e[n+1]?.name==="sni"&&(t.sni=e[n+1].value,n+=2),t}var Xe=class{index=0;input="";new(e){return this.index=0,this.input=e,this}readAtomically(e){let t=this.index,n=e();return n===void 0&&(this.index=t),n}parseWith(e){let t=e();if(this.index===this.input.length)return t}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(e){return this.readAtomically(()=>{let t=this.readChar();if(t===e)return t})}readSeparator(e,t,n){return this.readAtomically(()=>{if(!(t>0&&this.readGivenChar(e)===void 0))return n()})}readNumber(e,t,n,o){return this.readAtomically(()=>{let s=0,i=0,a=this.peekChar();if(a===void 0)return;let u=a==="0",c=2**(8*o)-1;for(;;){let h=this.readAtomically(()=>{let l=this.readChar();if(l===void 0)return;let f=Number.parseInt(l,e);if(!Number.isNaN(f))return f});if(h===void 0)break;if(s*=e,s+=h,s>c||(i+=1,t!==void 0&&i>t))return}if(i!==0)return!n&&u&&i>1?void 0:s})}readIPv4Addr(){return this.readAtomically(()=>{let e=new Uint8Array(4);for(let t=0;t<e.length;t++){let n=this.readSeparator(".",t,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;e[t]=n}return e})}readIPv6Addr(){let e=t=>{for(let n=0;n<t.length/2;n++){let o=n*2;if(n<t.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return t[o]=i[0],t[o+1]=i[1],t[o+2]=i[2],t[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];t[o]=s>>8,t[o+1]=s&255}return[t.length,!1]};return this.readAtomically(()=>{let t=new Uint8Array(16),[n,o]=e(t);if(n===16)return t;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let s=new Uint8Array(14),i=16-(n+2),[a]=e(s.subarray(0,i));return t.set(s.subarray(0,a),16-a),t})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var Ms=45,Bs=15,Qe=new Xe;function Cn(r){if(!(r.length>Bs))return Qe.new(r).parseWith(()=>Qe.readIPv4Addr())}function Sn(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>Ms))return Qe.new(r).parseWith(()=>Qe.readIPv6Addr())}function we(r){return!!Cn(r)}function Je(r){return!!Sn(r)}var Tn=po(Dn(),1),Vs=["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"],zs=Vs.map(r=>new Tn.Netmask(r));function er(r){for(let e of zs)if(e.contains(r))return!0;return!1}function ks(r){return/^::ffff:([0-9a-fA-F]{1,4}):([0-9a-fA-F]{1,4})$/.test(r)}function $s(r){let e=r.split(":");if(e.length<2)return!1;let t=e[e.length-1].padStart(4,"0"),n=e[e.length-2].padStart(4,"0"),o=`${parseInt(n.substring(0,2),16)}.${parseInt(n.substring(2),16)}.${parseInt(t.substring(0,2),16)}.${parseInt(t.substring(2),16)}`;return er(o)}function Ws(r){return/^::ffff:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(r)}function Gs(r){let e=r.split(":"),t=e[e.length-1];return er(t)}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 An(r){if(we(r))return er(r);if(ks(r))return $s(r);if(Ws(r))return Gs(r);if(Je(r))return js(r)}function Ln(r){try{let e=vn(r);switch(e.type){case"ip4":case"ip6":return An(e.host)??!1;default:return e.host==="localhost"}}catch{return!1}}var tr=class extends Error{constructor(e){super(e),this.name="TimeoutError"}},rr=class extends Error{constructor(e){super(),this.name="AbortError",this.message=e}},Nn=r=>globalThis.DOMException===void 0?new rr(r):new DOMException(r),_n=r=>{let e=r.reason===void 0?Nn("This operation was aborted."):r.reason;return e instanceof Error?e:Nn(e)};function nr(r,e){let{milliseconds:t,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout}}=e,i,a,c=new Promise((h,l)=>{if(typeof t!="number"||Math.sign(t)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${t}\``);if(e.signal){let{signal:p}=e;p.aborted&&l(_n(p)),a=()=>{l(_n(p))},p.addEventListener("abort",a,{once:!0})}if(t===Number.POSITIVE_INFINITY){r.then(h,l);return}let f=new tr;i=s.setTimeout.call(void 0,()=>{if(n){try{h(n())}catch(p){l(p)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?h():o instanceof Error?l(o):(f.message=o??`Promise timed out after ${t} milliseconds`,l(f))},t),(async()=>{try{h(await r)}catch(p){l(p)}})()}).finally(()=>{c.clear(),a&&e.signal&&e.signal.removeEventListener("abort",a)});return c.clear=()=>{s.clearTimeout.call(void 0,i),i=void 0},c}var qs=r=>{let e=r.addEventListener||r.on||r.addListener,t=r.removeEventListener||r.off||r.removeListener;if(!e||!t)throw new TypeError("Emitter is not compatible");return{addListener:e.bind(r),removeListener:t.bind(r)}};function Hs(r,e,t){let n,o=new Promise((s,i)=>{if(t={rejectionEvents:["error"],multiArgs:!1,rejectionMultiArgs:!1,resolveImmediately:!1,...t},!(t.count>=0&&(t.count===Number.POSITIVE_INFINITY||Number.isInteger(t.count))))throw new TypeError("The `count` option should be at least 0 or more");t.signal?.throwIfAborted();let a=[e].flat(),u=[],{addListener:c,removeListener:h}=qs(r),l=async(...p)=>{let m=t.multiArgs?p:p[0];if(t.filter)try{if(!await t.filter(m))return}catch(v){n(),i(v);return}u.push(m),t.count===u.length&&(n(),s(u))},f=(...p)=>{n(),i(t.rejectionMultiArgs?p:p[0])};n=()=>{for(let p of a)h(p,l);for(let p of t.rejectionEvents)a.includes(p)||h(p,f)};for(let p of a)c(p,l);for(let p of t.rejectionEvents)a.includes(p)||c(p,f);t.signal&&t.signal.addEventListener("abort",()=>{f(t.signal.reason)},{once:!0}),t.resolveImmediately&&s(u)});if(o.cancel=n,typeof t.timeout=="number"){let s=nr(o,{milliseconds:t.timeout});return s.cancel=()=>{n(),s.clear()},s}return o}function Pn(r,e,t){typeof t=="function"&&(t={filter:t}),t={...t,count:1,resolveImmediately:!1};let n=Hs(r,e,t),o=n.then(s=>s[0]);return o.cancel=n.cancel,o}var se=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"};function Xs(r){return r.reason}async function or(r,e,t){if(e==null)return r;let n=t?.translateError??Xs;if(e.aborted)return r.catch(()=>{}),Promise.reject(n(e));let o;try{return await Promise.race([r,new Promise((s,i)=>{o=()=>{i(n(e))},e.addEventListener("abort",o)})])}finally{o!=null&&e.removeEventListener("abort",o)}}var S=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},q=class extends Error{static name="ValidationError";name="ValidationError"},Ke=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},Ze=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};function ir(r){return e=>re(e,r)}function ar(r){return e=>te(e,r)}function ye(r){return new DataView(r.buffer).getUint16(r.byteOffset).toString()}function ie(r){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,typeof r=="string"?parseInt(r):r),new Uint8Array(e)}function On(r){let e=r.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==16)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion address.`);let t=te(e[0],"base32"),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=ie(n);return K([t,o],t.length+o.length)}function Un(r){let e=r.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==56)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion3 address.`);let t=J.decode(`b${e[0]}`),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=ie(n);return K([t,o],t.length+o.length)}function cr(r){let e=r.subarray(0,r.length-2),t=r.subarray(r.length-2),n=re(e,"base32"),o=ye(t);return`${n}:${o}`}var ur=function(r){r=r.toString().trim();let e=new Uint8Array(4);return r.split(/\./g).forEach((t,n)=>{let o=parseInt(t,10);if(isNaN(o)||o<0||o>255)throw new S("Invalid byte value in IP address");e[n]=o}),e},Fn=function(r){let e=0;r=r.toString().trim();let t=r.split(":",8),n;for(n=0;n<t.length;n++){let s=we(t[n]),i;s&&(i=ur(t[n]),t[n]=re(i.subarray(0,2),"base16")),i!=null&&++n<8&&t.splice(n,0,re(i.subarray(2,4),"base16"))}if(t[0]==="")for(;t.length<8;)t.unshift("0");else if(t[t.length-1]==="")for(;t.length<8;)t.push("0");else if(t.length<8){for(n=0;n<t.length&&t[n]!=="";n++);let s=[n,1];for(n=9-t.length;n>0;n--)s.push("0");t.splice.apply(t,s)}let o=new Uint8Array(e+16);for(n=0;n<t.length;n++){t[n]===""&&(t[n]="0");let s=parseInt(t[n],16);if(isNaN(s)||s<0||s>65535)throw new S("Invalid byte value in IP address");o[e++]=s>>8&255,o[e++]=s&255}return o},Rn=function(r){if(r.byteLength!==4)throw new S("IPv4 address was incorrect length");let e=[];for(let t=0;t<r.byteLength;t++)e.push(r[t]);return e.join(".")},Mn=function(r){if(r.byteLength!==16)throw new S("IPv6 address was incorrect length");let e=[];for(let n=0;n<r.byteLength;n+=2){let o=r[n],s=r[n+1],i=`${o.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}`;e.push(i)}let t=e.join(":");try{let n=new URL(`http://[${t}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new S(`Invalid IPv6 address "${t}"`)}};function Bn(r){try{let e=new URL(`http://[${r}]`);return e.hostname.substring(1,e.hostname.length-1)}catch{throw new S(`Invalid IPv6 address "${r}"`)}}var sr=Object.values(Ne).map(r=>r.decoder),Qs=(function(){let r=sr[0].or(sr[1]);return sr.slice(2).forEach(e=>r=r.or(e)),r})();function Vn(r){return Qs.decode(r)}function zn(r){return e=>r.encoder.encode(e)}function Js(r){if(parseInt(r).toString()!==r)throw new q("Value must be an integer")}function Ks(r){if(r<0)throw new q("Value must be a positive integer, or zero")}function Zs(r){return e=>{if(e>r)throw new q(`Value must be smaller than or equal to ${r}`)}}function Ys(...r){return e=>{for(let t of r)t(e)}}var Fe=Ys(Js,Ks,Zs(65535));var C=-1,lr=class{protocolsByCode=new Map;protocolsByName=new Map;getProtocol(e){let t;if(typeof e=="string"?t=this.protocolsByName.get(e):t=this.protocolsByCode.get(e),t==null)throw new Ze(`Protocol ${e} was unknown`);return t}addProtocol(e){this.protocolsByCode.set(e.code,e),this.protocolsByName.set(e.name,e),e.aliases?.forEach(t=>{this.protocolsByName.set(t,e)})}removeProtocol(e){let t=this.protocolsByCode.get(e);t!=null&&(this.protocolsByCode.delete(t.code),this.protocolsByName.delete(t.name),t.aliases?.forEach(n=>{this.protocolsByName.delete(n)}))}},H=new lr,pi=[{code:4,name:"ip4",size:32,valueToBytes:ur,bytesToValue:Rn,validate:r=>{if(!we(r))throw new q(`Invalid IPv4 address "${r}"`)}},{code:6,name:"tcp",size:16,valueToBytes:ie,bytesToValue:ye,validate:Fe},{code:273,name:"udp",size:16,valueToBytes:ie,bytesToValue:ye,validate:Fe},{code:33,name:"dccp",size:16,valueToBytes:ie,bytesToValue:ye,validate:Fe},{code:41,name:"ip6",size:128,valueToBytes:Fn,bytesToValue:Mn,stringToValue:Bn,validate:r=>{if(!Je(r))throw new q(`Invalid IPv6 address "${r}"`)}},{code:42,name:"ip6zone",size:C},{code:43,name:"ipcidr",size:8,bytesToValue:ir("base10"),valueToBytes:ar("base10")},{code:53,name:"dns",size:C},{code:54,name:"dns4",size:C},{code:55,name:"dns6",size:C},{code:56,name:"dnsaddr",size:C},{code:132,name:"sctp",size:16,valueToBytes:ie,bytesToValue:ye,validate:Fe},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:C,stringToValue:r=>decodeURIComponent(r),valueToString:r=>encodeURIComponent(r)},{code:421,name:"p2p",aliases:["ipfs"],size:C,bytesToValue:ir("base58btc"),valueToBytes:r=>r.startsWith("Q")||r.startsWith("1")?ar("base58btc")(r):ge.parse(r).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:cr,valueToBytes:On},{code:445,name:"onion3",size:296,bytesToValue:cr,valueToBytes:Un},{code:446,name:"garlic64",size:C},{code:447,name:"garlic32",size:C},{code:448,name:"tls"},{code:449,name:"sni",size:C},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:C,bytesToValue:zn(Dt),valueToBytes:Vn},{code:480,name:"http"},{code:481,name:"http-path",size:C,stringToValue:r=>`/${decodeURIComponent(r)}`,valueToString:r=>encodeURIComponent(r.substring(1))},{code:443,name:"https"},{code:477,name:"ws"},{code:478,name:"wss"},{code:479,name:"p2p-websocket-star"},{code:277,name:"p2p-stardust"},{code:275,name:"p2p-webrtc-star"},{code:276,name:"p2p-webrtc-direct"},{code:280,name:"webrtc-direct"},{code:281,name:"webrtc"},{code:290,name:"p2p-circuit"},{code:777,name:"memory",size:C}];pi.forEach(r=>{H.addProtocol(r)});function kn(r){let e=[],t=0;for(;t<r.length;){let n=_e(r,t),o=H.getProtocol(n),s=N(n),i=mi(o,r,t+s),a=0;i>0&&o.size===C&&(a=N(i));let u=s+a+i,c={code:n,name:o.name,bytes:r.subarray(t,t+u)};if(i>0){let h=t+s+a,l=r.subarray(h,h+i);c.value=o.bytesToValue?.(l)??re(l)}e.push(c),t+=u}return e}function $n(r){let e=0,t=[];for(let n of r){if(n.bytes==null){let o=H.getProtocol(n.code),s=N(n.code),i,a=0,u=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??te(n.value),a=i.byteLength,o.size===C&&(u=N(a)));let c=new Uint8Array(s+u+a),h=0;be(n.code,c,h),h+=s,i!=null&&(o.size===C&&(be(a,c,h),h+=u),c.set(i,h)),n.bytes=c}t.push(n.bytes),e+=n.bytes.byteLength}return K(t,e)}function Wn(r){if(r.charAt(0)!=="/")throw new S('String multiaddr must start with "/"');let e=[],t="protocol",n="",o="";for(let s=1;s<r.length;s++){let i=r.charAt(s);i!=="/"&&(t==="protocol"?o+=r.charAt(s):n+=r.charAt(s));let a=s===r.length-1;if(i==="/"||a){let u=H.getProtocol(o);if(t==="protocol"){if(u.size==null||u.size===0){e.push({code:u.code,name:u.name}),n="",o="",t="protocol";continue}else if(a)throw new S(`Component ${o} was missing value`);t="value"}else if(t==="value"){let c={code:u.code,name:u.name};if(u.size!=null&&u.size!==0){if(n==="")throw new S(`Component ${o} was missing value`);c.value=u.stringToValue?.(n)??n}e.push(c),n="",o="",t="protocol"}}}if(o!==""&&n!=="")throw new S("Incomplete multiaddr");return e}function Gn(r){return`/${r.flatMap(e=>{if(e.value==null)return e.name;let t=H.getProtocol(e.code);if(t==null)throw new S(`Unknown protocol code ${e.code}`);return[e.name,t.valueToString?.(e.value)??e.value]}).join("/")}`}function mi(r,e,t){return r.size==null||r.size===0?0:r.size>0?r.size/8:_e(e,t)}var gi=Symbol.for("nodejs.util.inspect.custom"),Tr=Symbol.for("@multiformats/multiaddr");function bi(r){if(r==null&&(r="/"),jn(r))return r.getComponents();if(r instanceof Uint8Array)return kn(r);if(typeof r=="string")return r=r.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),r===""&&(r="/"),Wn(r);if(Array.isArray(r))return r;throw new S("Must be a string, Uint8Array, Component[], or another Multiaddr")}var nt=class r{[Tr]=!0;#e;#t;#r;constructor(e="/",t={}){this.#e=bi(e),t.validate!==!1&&xi(this)}get bytes(){return this.#r==null&&(this.#r=$n(this.#e)),this.#r}toString(){return this.#t==null&&(this.#t=Gn(this.#e)),this.#t}toJSON(){return this.toString()}getComponents(){return[...this.#e.map(e=>({...e}))]}encapsulate(e){let t=new r(e);return new r([...this.#e,...t.getComponents()],{validate:!1})}decapsulate(e){let t=e.toString(),n=this.toString(),o=n.lastIndexOf(t);if(o<0)throw new Ke(`Address ${this.toString()} does not contain subaddress: ${t}`);return new r(n.slice(0,o),{validate:!1})}decapsulateCode(e){let t;for(let n=this.#e.length-1;n>-1;n--)if(this.#e[n].code===e){t=n;break}return new r(this.#e.slice(0,t),{validate:!1})}equals(e){return ke(this.bytes,e.bytes)}[gi](){return`Multiaddr(${this.toString()})`}};function xi(r){r.getComponents().forEach(e=>{let t=H.getProtocol(e.code);e.value!=null&&t.validate?.(e.value)})}function jn(r){return!!r?.[Tr]}function Ar(r){return new nt(r)}var yi=4194304,ot=class extends Error{static name="UnwrappedError";name="UnwrappedError"},Nr=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},_r=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},Pr=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function Ei(r){return typeof r?.closeRead=="function"}function Ii(r){return typeof r?.close=="function"}function Lr(r){return Ei(r)?r.remoteWriteStatus!=="writable"&&r.readBufferLength===0:Ii(r)?r.status!=="open":!1}function vi(r){return r?.addEventListener!=null&&r?.removeEventListener!=null&&r?.send!=null&&r?.push!=null&&r?.log!=null}function Ci(r,e){let t=e?.maxBufferSize??yi,n=new ee,o,s=!1;if(!vi(r))throw new le("Argument should be a Stream or a Multiaddr");let i=h=>{if(n.append(h.data),n.byteLength>t){let l=n.byteLength;n.consume(n.byteLength),o?.reject(new Error(`Read buffer overflow - ${l} > ${t}`))}o?.resolve()};r.addEventListener("message",i);let a=h=>{h.error!=null?o?.reject(h.error):o?.resolve()};r.addEventListener("close",a);let u=()=>{o?.resolve()};r.addEventListener("remoteCloseWrite",u);let c={readBuffer:n,async read(h){if(s===!0)throw new ot("Stream was unwrapped");if(Lr(r)){if(h?.bytes==null)return null;if(n.byteLength<h.bytes)throw r.log.error("closed after reading %d/%d bytes",n.byteLength,h.bytes),new se(`Unexpected EOF - stream closed after reading ${n.byteLength}/${h.bytes} bytes`)}let l=h?.bytes??1;for(o=Promise.withResolvers();;){if(n.byteLength>=l){o.resolve();break}if(await or(o.promise,h?.signal),Lr(r)){if(n.byteLength===0&&h?.bytes==null)return null;break}o=Promise.withResolvers()}let f=h?.bytes??n.byteLength;if(n.byteLength<f){if(Lr(r))throw r.log.error("closed while reading %d/%d bytes",n.byteLength,f),new se(`Unexpected EOF - stream closed while reading ${n.byteLength}/${f} bytes`);return c.read(h)}let p=n.sublist(0,f);return n.consume(f),p},async write(h,l){if(s===!0)throw new ot("Stream was unwrapped");r.send(h)||await Pn(r,"drain",{signal:l?.signal,rejectionEvents:["close"]})},unwrap(){return s||(s=!0,r.removeEventListener("message",i),r.removeEventListener("close",a),r.removeEventListener("remoteCloseWrite",u),n.byteLength>0&&(r.log("stream unwrapped with %d unread bytes",n.byteLength),r.push(n))),r}};return c}function Si(r,e={}){let t=Ci(r,e);e.maxDataLength!=null&&e.maxLengthLength==null&&(e.maxLengthLength=N(e.maxDataLength));let n=e?.lengthDecoder??_e,o=e?.lengthEncoder??dn;return{async read(i){let a=-1,u=new ee;for(;;){let h=await t.read({...i,bytes:1});if(h==null)break;u.append(h);try{a=n(u)}catch(l){if(l instanceof RangeError)continue;throw l}if(a<0)throw new Nr("Invalid message length");if(e?.maxLengthLength!=null&&u.byteLength>e.maxLengthLength)throw new Pr(`Message length length too long - ${u.byteLength} > ${e.maxLengthLength}`);if(a>-1)break}if(e?.maxDataLength!=null&&a>e.maxDataLength)throw new _r(`Message length too long - ${a} > ${e.maxDataLength}`);let c=await t.read({...i,bytes:a});if(c==null)throw r.log.error("tried to read %d bytes but the stream closed",a),new se(`Unexpected EOF - tried to read ${a} bytes but the stream closed`);if(c.byteLength!==a)throw r.log.error("read %d/%d bytes before the stream closed",c.byteLength,a),new se(`Unexpected EOF - read ${c.byteLength}/${a} bytes before the stream closed`);return c},async write(i,a){await t.write(new ee(o(i.byteLength),i),a)},async writeV(i,a){let u=new ee(...i.flatMap(c=>[o(c.byteLength),c]));await t.write(u,a)},unwrap(){return t.unwrap()}}}function Or(r,e){let t=Si(r,e),n={read:async(o,s)=>{let i=await t.read(s);return o.decode(i)},write:async(o,s,i)=>{await t.write(s.encode(o),i)},writeV:async(o,s,i)=>{await t.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:()=>t.unwrap()};return n}var qn=Symbol.for("sindresorhus/unlimited-timeout#brand");function Hn(r,e,...t){if(typeof r!="function")throw new TypeError("Expected callback to be a function");e??=0,e=Number(e);let n=!1,o={[qn]:!0,id:void 0,cleared:!1,ref(){return n=!1,o.id?.ref?.(),o},unref(){return n=!0,o.id?.unref?.(),o}};if(e===Number.POSITIVE_INFINITY||e>Number.MAX_SAFE_INTEGER)return o;(!Number.isFinite(e)||e<0)&&(e=0);let s=performance.now()+e,i=a=>{o.cleared||(a<=2147483647?(o.id=globalThis.setTimeout(()=>{o.cleared||r(...t)},a),n&&o.id?.unref?.()):(o.id=globalThis.setTimeout(()=>{let u=performance.now(),c=Math.max(0,s-u);i(c)},2147483647),n&&o.id?.unref?.()))};return i(e),o}function Xn(r){!r||typeof r!="object"||!r[qn]||(r.cleared=!0,r.id!==void 0&&(globalThis.clearTimeout(r.id),r.id=void 0))}var Di=new WeakMap;function Ti({clearTimeout:r,setTimeout:e}={}){return(t,{value:n,signal:o}={})=>{if(o?.aborted)return Promise.reject(o.reason);let s,i,a,u=r??clearTimeout,c=()=>{u(s),a(o.reason)},h=()=>{o&&o.removeEventListener("abort",c)},l=new Promise((f,p)=>{i=()=>{h(),f(n)},a=p,s=(e??setTimeout)(i,t)});return o&&o.addEventListener("abort",c,{once:!0}),Di.set(l,()=>{u(s),s=null,i()}),l}}var Ai=Ti({setTimeout:Hn,clearTimeout:Xn}),Qn=Ai;var y=r=>({match:e=>{let t=e[0];return t==null||t.code!==r||t.value!=null?!1:e.slice(1)}}),d=(r,e)=>({match:t=>{let n=t[0];return n?.code!==r||n.value==null||e!=null&&n.value!==e?!1:t.slice(1)}}),Jn=r=>({match:e=>r.match(e)===!1?e:!1}),g=r=>({match:e=>{let t=r.match(e);return t===!1?e:t}}),A=(...r)=>({match:e=>{let t;for(let n of r){let o=n.match(e);o!==!1&&(t==null||o.length<t.length)&&(t=o)}return t??!1}}),w=(...r)=>({match:e=>{for(let t of r){let n=t.match(e);if(n===!1)return!1;e=n}return e}});function E(...r){function e(o){if(o==null)return!1;let s=o.getComponents();for(let i of r){let a=i.match(s);if(a===!1)return!1;s=a}return s}function t(o){return e(o)!==!1}function n(o){let s=e(o);return s===!1?!1:s.length===0}return{matchers:r,matches:t,exactMatch:n}}var Li=d(421),Tl=E(Li),it=d(54),at=d(55),ct=d(56),Fr=d(53),Al=E(it,g(d(421))),Ll=E(at,g(d(421))),Nl=E(ct,g(d(421))),Kn=E(A(Fr,ct,it,at),g(d(421))),Zn=w(d(4),g(d(43))),Yn=w(g(d(42)),d(41),g(d(43))),Rr=A(Zn,Yn),ue=A(Rr,Fr,it,at,ct),_l=E(A(Rr,w(A(Fr,ct,it,at),g(d(421))))),Pl=E(Zn),Ol=E(Yn),eo=E(Rr),Mr=w(ue,d(6)),Re=w(ue,d(273)),Ul=E(w(Mr,g(d(421)))),Fl=E(Re),Br=w(Re,y(460),g(d(421))),ut=w(Re,y(461),g(d(421))),Ni=A(Br,ut),Rl=E(Br),Ml=E(ut),Ur=A(ue,Mr,Re,Br,ut),to=A(w(Ur,y(477),g(d(421)))),Bl=E(to),ro=A(w(Ur,y(478),g(d(421))),w(Ur,y(448),g(d(449)),y(477),g(d(421)))),Vl=E(ro),no=w(Re,y(280),g(d(466)),g(d(466)),g(d(421))),zl=E(no),oo=w(ut,y(465),g(d(466)),g(d(466)),g(d(421))),kl=E(oo),st=A(to,ro,w(Mr,g(d(421))),w(Ni,g(d(421))),w(ue,g(d(421))),no,oo,d(421)),$l=E(st),_i=w(g(st),y(290),Jn(y(281)),g(d(421))),Me=E(_i),Pi=A(w(st,y(290),y(281),g(d(421))),w(st,y(281),g(d(421))),w(y(281),g(d(421)))),Wl=E(Pi),Oi=A(w(ue,d(6),y(480),g(d(421))),w(ue,y(480),g(d(421)))),Gl=E(Oi),Ui=w(ue,A(w(d(6,"443"),y(480)),w(d(6),y(443)),w(d(6),y(448),y(480)),w(y(448),y(480)),y(448),y(443)),g(d(421))),jl=E(Ui),Fi=A(w(d(777),g(d(421)))),ql=E(Fi),Ri=A(w(d(400),g(d(421)))),Hl=E(Ri);var M;(function(r){let e;(function(o){o.UNUSED="UNUSED",o.CONNECT="CONNECT",o.SYNC="SYNC"})(e=r.Type||(r.Type={}));let t;(function(o){o[o.UNUSED=0]="UNUSED",o[o.CONNECT=100]="CONNECT",o[o.SYNC=300]="SYNC"})(t||(t={})),(function(o){o.codec=()=>Zt(t)})(e=r.Type||(r.Type={}));let n;r.codec=()=>(n==null&&(n=Yt((o,s,i={})=>{if(i.lengthDelimited!==!1&&s.fork(),o.type!=null&&(s.uint32(8),r.Type.codec().encode(o.type,s)),o.observedAddresses!=null)for(let a of o.observedAddresses)s.uint32(18),s.bytes(a);i.lengthDelimited!==!1&&s.ldelim()},(o,s,i={})=>{let a={observedAddresses:[]},u=s==null?o.len:o.pos+s;for(;o.pos<u;){let c=o.uint32();switch(c>>>3){case 1:{a.type=r.Type.codec().decode(o);break}case 2:{if(i.limits?.observedAddresses!=null&&a.observedAddresses.length===i.limits.observedAddresses)throw new He('Decode error - map field "observedAddresses" had too many elements');a.observedAddresses.push(o.bytes());break}default:{o.skipType(c&7);break}}}return a})),n),r.encode=o=>Kt(o,r.codec()),r.decode=(o,s)=>Gt(o,r.codec(),s)})(M||(M={}));function Vr(r,e){return Me.matches(r)||e.dialTransportForMultiaddr(r)==null?!1:Kn.matches(r)?!0:eo.matches(r)?!Ln(r):!1}var so=1024*4,io=100,lt={timeout:5e3,retries:3,maxInboundStreams:1,maxOutboundStreams:1},ht=class{started;timeout;retries;maxInboundStreams;maxOutboundStreams;peerStore;registrar;connectionManager;addressManager;transportManager;topologyId;log;constructor(e,t){this.log=e.logger.forComponent("libp2p:dcutr"),this.started=!1,this.peerStore=e.peerStore,this.registrar=e.registrar,this.addressManager=e.addressManager,this.connectionManager=e.connectionManager,this.transportManager=e.transportManager,this.timeout=t.timeout??lt.timeout,this.retries=t.retries??lt.retries,this.maxInboundStreams=t.maxInboundStreams??lt.maxInboundStreams,this.maxOutboundStreams=t.maxOutboundStreams??lt.maxOutboundStreams,this.handleIncomingUpgrade=this.handleIncomingUpgrade.bind(this)}[Symbol.toStringTag]="@libp2p/dcutr";[kr]=["@libp2p/identify"];isStarted(){return this.started}async start(){this.started||(this.topologyId=await this.registrar.register(Ce,{notifyOnLimitedConnection:!0,onConnect:(e,t)=>{Me.exactMatch(t.remoteAddr)&&t.direction==="inbound"&&this.upgradeInbound(t).catch(n=>{this.log.error("error during outgoing DCUtR attempt - %e",n)})}}),await this.registrar.handle(Ce,this.handleIncomingUpgrade,{maxInboundStreams:this.maxInboundStreams,maxOutboundStreams:this.maxOutboundStreams,runOnLimitedConnection:!0}),this.started=!0)}async stop(){await this.registrar.unhandle(Ce),this.topologyId!=null&&this.registrar.unregister(this.topologyId),this.started=!1}async upgradeInbound(e){if(await this.attemptUnilateralConnectionUpgrade(e))return;let t;for(let n=0;n<this.retries;n++){let o={signal:AbortSignal.timeout(this.timeout)};try{t=await e.newStream([Ce],{signal:o.signal,runOnLimitedConnection:!0});let s=Or(t,{maxDataLength:so}).pb(M);this.log("B sending connect to %p",e.remotePeer);let i=Date.now();await s.write({type:M.Type.CONNECT,observedAddresses:this.addressManager.getAddresses().map(l=>l.bytes)},o),this.log("B receiving connect from %p",e.remotePeer);let a=await s.read(o);if(a.type!==M.Type.CONNECT)throw this.log("A sent wrong message type"),new W("DCUtR message type was incorrect");let u=this.getDialableMultiaddrs(a.observedAddresses);if(u.length===0)throw this.log("A did not have any dialable multiaddrs"),new W("DCUtR connect message had no multiaddrs");let c=Date.now()-i;this.log("A sending sync, rtt %dms",c),await s.write({type:M.Type.SYNC,observedAddresses:[]},o),this.log("A waiting for half RTT"),await Qn(c/2),this.log("B dialing",u);let h=await this.connectionManager.openConnection(u,{signal:o.signal,priority:io,force:!0,initiator:!1});this.log("DCUtR to %p succeeded to address %a, closing relayed connection",e.remotePeer,h.remoteAddr),await e.close(o);break}catch(s){if(this.log.error("error while attempting DCUtR on attempt %d of %d - %e",n+1,this.retries,s),t?.abort(s),n===this.retries)throw s}finally{t!=null&&await t.close(o)}}}async attemptUnilateralConnectionUpgrade(e){let n=(await this.peerStore.get(e.remotePeer)).addresses.map(o=>{let s=o.multiaddr;return s.getComponents().find(i=>i.code===421)?.value==null?s.encapsulate(`/p2p/${e.remotePeer}`):s}).filter(o=>Vr(o,this.transportManager));if(n.length>0){let o=AbortSignal.timeout(this.timeout);try{this.log("attempting unilateral connection upgrade to %a",n);let s=await this.connectionManager.openConnection(n,{signal:o,force:!0});if(Me.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",e.remotePeer,s.remoteAddr),await e.close({signal:o}),!0}catch(s){this.log.error("unilateral connection upgrade to %p on addresses %a failed - %e",e.remotePeer,n,s)}}else this.log("peer %p has no public addresses, not attempting unilateral connection upgrade",e.remotePeer);return!1}async handleIncomingUpgrade(e,t){let n={signal:AbortSignal.timeout(this.timeout)},o=Or(e,{maxDataLength:so}).pb(M);this.log("A receiving connect");let s=await o.read(n);if(s.type!==M.Type.CONNECT)throw this.log("B sent wrong message type"),new W("DCUtR message type was incorrect");if(s.observedAddresses.length===0)throw this.log("B sent no multiaddrs"),new W("DCUtR connect message had no multiaddrs");let i=this.getDialableMultiaddrs(s.observedAddresses);if(i.length===0)throw this.log("B had no dialable multiaddrs in %o",s.observedAddresses.map(c=>Ar(c))),new W("DCUtR connect message had no dialable multiaddrs");if(this.log("A sending connect"),await o.write({type:M.Type.CONNECT,observedAddresses:this.addressManager.getAddresses().map(c=>c.bytes)}),this.log("A receiving sync"),(await o.read(n)).type!==M.Type.SYNC)throw new W("DCUtR message type was incorrect");this.log("A dialing",i);let u=await this.connectionManager.openConnection(i,{signal:n.signal,priority:io,force:!0});this.log("DCUtR to %p succeeded via %a, closing relayed connection",t.remotePeer,u.remoteAddr),await t.close(n),await e.close(n)}getDialableMultiaddrs(e){let t=[];for(let n of e)if(!(n==null||n.length===0))try{let o=Ar(n);if(!Vr(o,this.transportManager))continue;t.push(o)}catch{}return t}};var Ce="/libp2p/dcutr";function Mi(r={}){return e=>new ht(e,r)}return mo(Bi);})();
|
|
3
3
|
return Libp2PDcutr}));
|
|
4
4
|
//# sourceMappingURL=index.min.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libp2p/dcutr",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.9-28c2b65f4",
|
|
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",
|
|
@@ -45,9 +45,9 @@
|
|
|
45
45
|
"doc-check": "aegir doc-check"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@libp2p/interface": "
|
|
49
|
-
"@libp2p/interface-internal": "
|
|
50
|
-
"@libp2p/utils": "
|
|
48
|
+
"@libp2p/interface": "3.1.0-28c2b65f4",
|
|
49
|
+
"@libp2p/interface-internal": "3.0.9-28c2b65f4",
|
|
50
|
+
"@libp2p/utils": "7.0.9-28c2b65f4",
|
|
51
51
|
"@multiformats/multiaddr": "^13.0.1",
|
|
52
52
|
"@multiformats/multiaddr-matcher": "^3.0.1",
|
|
53
53
|
"delay": "^7.0.0",
|
package/dist/typedoc-urls.json
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"DCUtRServiceComponents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_dcutr.DCUtRServiceComponents.html",
|
|
3
|
-
".:DCUtRServiceComponents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_dcutr.DCUtRServiceComponents.html",
|
|
4
|
-
"DCUtRServiceInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_dcutr.DCUtRServiceInit.html",
|
|
5
|
-
".:DCUtRServiceInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_dcutr.DCUtRServiceInit.html",
|
|
6
|
-
"multicodec": "https://libp2p.github.io/js-libp2p/variables/_libp2p_dcutr.multicodec.html",
|
|
7
|
-
".:multicodec": "https://libp2p.github.io/js-libp2p/variables/_libp2p_dcutr.multicodec.html",
|
|
8
|
-
"dcutr": "https://libp2p.github.io/js-libp2p/functions/_libp2p_dcutr.dcutr.html",
|
|
9
|
-
".:dcutr": "https://libp2p.github.io/js-libp2p/functions/_libp2p_dcutr.dcutr.html"
|
|
10
|
-
}
|