@libp2p/dcutr 3.0.21-a34745c01 → 3.0.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.min.js CHANGED
@@ -1,4 +1,4 @@
1
1
  (function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PDcutr = factory()}(typeof self !== 'undefined' ? self : this, function () {
2
- "use strict";var Libp2PDcutr=(()=>{var Hs=Object.create;var ht=Object.defineProperty;var Qs=Object.getOwnPropertyDescriptor;var Js=Object.getOwnPropertyNames;var Ys=Object.getPrototypeOf,Ks=Object.prototype.hasOwnProperty;var zt=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),v=(r,e)=>{for(var t in e)ht(r,t,{get:e[t],enumerable:!0})},eo=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Js(e))!Ks.call(r,o)&&o!==t&&ht(r,o,{get:()=>e[o],enumerable:!(n=Qs(e,o))||n.enumerable});return r};var Zs=(r,e,t)=>(t=r!=null?Hs(Ys(r)):{},eo(e||!r||!r.__esModule?ht(t,"default",{value:r,enumerable:!0}):t,r)),ei=r=>eo(ht({},"__esModule",{value:!0}),r);var nn=zt(Be=>{"use strict";Object.defineProperty(Be,"__esModule",{value:!0});Be.Netmask4Impl=void 0;Be.ip2long=Fe;Be.long2ip=X;function X(r){let e=(r&-16777216)>>>24,t=(r&255<<16)>>>16,n=(r&65280)>>>8,o=r&255;return[e,t,n,o].join(".")}var Rc=48,kc=97,zc=65;function Vc(r){let e=0,t=10,n="9",o=0;r.length>1&&r[o]==="0"&&(r[o+1]==="x"||r[o+1]==="X"?(o+=2,t=16):"0"<=r[o+1]&&r[o+1]<="9"&&(o++,t=8,n="7"));let s=o;for(;o<r.length;){if("0"<=r[o]&&r[o]<=n)e=e*t+(r.charCodeAt(o)-Rc)>>>0;else if(t===16)if("a"<=r[o]&&r[o]<="f")e=e*t+(10+r.charCodeAt(o)-kc)>>>0;else if("A"<=r[o]&&r[o]<="F")e=e*t+(10+r.charCodeAt(o)-zc)>>>0;else break;else break;if(e>4294967295)throw new Error("too large");o++}if(o===s)throw new Error("empty octet");return[e,o]}function Fe(r){let e=[];for(let t=0;t<=3&&r.length!==0;t++){if(t>0){if(r[0]!==".")throw new Error("Invalid IP");r=r.substring(1)}let[n,o]=Vc(r);r=r.substring(o),e.push(n)}if(r.length!==0)throw new Error("Invalid IP");switch(e.length){case 1:if(e[0]>4294967295)throw new Error("Invalid IP");return e[0]>>>0;case 2:if(e[0]>255||e[1]>16777215)throw new Error("Invalid IP");return(e[0]<<24|e[1])>>>0;case 3:if(e[0]>255||e[1]>255||e[2]>65535)throw new Error("Invalid IP");return(e[0]<<24|e[1]<<16|e[2])>>>0;case 4:if(e[0]>255||e[1]>255||e[2]>255||e[3]>255)throw new Error("Invalid IP");return(e[0]<<24|e[1]<<16|e[2]<<8|e[3])>>>0;default:throw new Error("Invalid IP")}}var rn=class r{constructor(e,t){if(typeof e!="string")throw new Error("Missing `net' parameter");let n=t;if(!n){let o=e.split("/",2);e=o[0],n=o[1]}if(n||(n=32),typeof n=="string"&&n.indexOf(".")>-1){try{this.maskLong=Fe(n)}catch{throw new Error("Invalid mask: "+n)}this.bitmask=NaN;for(let o=32;o>=0;o--)if(this.maskLong===4294967295<<32-o>>>0){this.bitmask=o;break}}else if(n||n===0)this.bitmask=parseInt(n,10),this.maskLong=0,this.bitmask>0&&(this.maskLong=4294967295<<32-this.bitmask>>>0);else throw new Error("Invalid mask: empty");try{this.netLong=(Fe(e)&this.maskLong)>>>0}catch{throw new Error("Invalid net address: "+e)}if(!(this.bitmask<=32))throw new Error("Invalid mask for ip4: "+n);this.size=Math.pow(2,32-this.bitmask),this.base=X(this.netLong),this.mask=X(this.maskLong),this.hostmask=X(~this.maskLong),this.first=this.bitmask<=30?X(this.netLong+1):this.base,this.last=this.bitmask<=30?X(this.netLong+this.size-2):X(this.netLong+this.size-1),this.broadcast=this.bitmask<=30?X(this.netLong+this.size-1):void 0}contains(e){return typeof e=="string"&&(e.indexOf("/")>0||e.split(".").length!==4)&&(e=new r(e)),e instanceof r?this.contains(e.base)&&this.contains(e.broadcast||e.last):(Fe(e)&this.maskLong)>>>0===(this.netLong&this.maskLong)>>>0}next(e=1){return new r(X(this.netLong+this.size*e),this.mask)}forEach(e){let t=Fe(this.first),n=Fe(this.last),o=0;for(;t<=n;)e(X(t),t,o),o++,t++}toString(){return this.base+"/"+this.bitmask}};Be.Netmask4Impl=rn});var ds=zt(Me=>{"use strict";Object.defineProperty(Me,"__esModule",{value:!0});Me.Netmask6Impl=void 0;Me.ip6bigint=sn;Me.bigint2ip6=me;var $c=nn(),on=(1n<<128n)-1n;function sn(r){let e=r.indexOf("%");e!==-1&&(r=r.substring(0,e));let t=r.lastIndexOf(":");if(t!==-1&&r.indexOf(".",t)!==-1){let n=r.substring(t+1),o=(0,$c.ip2long)(n),s=r.substring(0,t+1)+"0:0";return ls(s)&~0xffffffffn|BigInt(o)}return ls(r)}function ls(r){let e=r.indexOf("::"),t;if(e!==-1){let o=r.substring(0,e),s=r.substring(e+2),i=o===""?[]:o.split(":"),a=s===""?[]:s.split(":"),c=8-i.length-a.length;if(c<0)throw new Error("Invalid IPv6: too many groups");t=[...i,...Array(c).fill("0"),...a]}else t=r.split(":");if(t.length!==8)throw new Error("Invalid IPv6: expected 8 groups, got "+t.length);let n=0n;for(let o=0;o<8;o++){let s=t[o];if(s.length===0||s.length>4)throw new Error('Invalid IPv6: bad group "'+s+'"');let i=parseInt(s,16);if(isNaN(i)||i<0||i>65535)throw new Error('Invalid IPv6: bad group "'+s+'"');n=n<<16n|BigInt(i)}return n}function me(r){if(r<0n||r>on)throw new Error("Invalid IPv6 address value");let e=[];for(let i=0;i<8;i++)e.unshift(Number(r&0xffffn)),r>>=16n;let t=-1,n=0,o=-1,s=0;for(let i=0;i<8;i++)e[i]===0?o===-1?(o=i,s=1):s++:(s>n&&s>=2&&(t=o,n=s),o=-1,s=0);if(s>n&&s>=2&&(t=o,n=s),t!==-1&&t+n===8&&t>0)return e.slice(0,t).map(a=>a.toString(16)).join(":")+"::";if(t===0)return"::"+e.slice(n).map(a=>a.toString(16)).join(":");if(t>0){let i=e.slice(0,t).map(c=>c.toString(16)),a=e.slice(t+n).map(c=>c.toString(16));return i.join(":")+"::"+a.join(":")}else return e.map(i=>i.toString(16)).join(":")}var an=class r{constructor(e,t){if(typeof e!="string")throw new Error("Missing `net' parameter");let n=t;if(n==null){let o=e.indexOf("/");o!==-1?(n=parseInt(e.substring(o+1),10),e=e.substring(0,o)):n=128}if(isNaN(n)||n<0||n>128)throw new Error("Invalid mask for IPv6: "+n);this.bitmask=n,this.bitmask===0?this.maskBigint=0n:this.maskBigint=on>>BigInt(128-this.bitmask)<<BigInt(128-this.bitmask);try{this.netBigint=sn(e)&this.maskBigint}catch{throw new Error("Invalid IPv6 net address: "+e)}this.size=Number(1n<<BigInt(128-this.bitmask)),this.base=me(this.netBigint),this.mask=me(this.maskBigint),this.hostmask=me(~this.maskBigint&on),this.first=this.base,this.last=me(this.netBigint+(1n<<BigInt(128-this.bitmask))-1n),this.broadcast=void 0}contains(e){return typeof e=="string"&&e.indexOf("/")>0&&(e=new r(e)),e instanceof r?this.contains(e.base)&&this.contains(e.last):(sn(e)&this.maskBigint)===this.netBigint}next(e=1){let t=1n<<BigInt(128-this.bitmask);return new r(me(this.netBigint+t*BigInt(e)),this.bitmask)}forEach(e){let t=this.netBigint,n=1n<<BigInt(128-this.bitmask),o=this.netBigint+n-1n,s=0;for(;t<=o;)e(me(t),Number(t),s),s++,t++}toString(){return this.base+"/"+this.bitmask}};Me.Netmask6Impl=an});var ps=zt(ce=>{"use strict";Object.defineProperty(ce,"__esModule",{value:!0});ce.long2ip=ce.ip2long=ce.Netmask=void 0;var It=nn();Object.defineProperty(ce,"ip2long",{enumerable:!0,get:function(){return It.ip2long}});Object.defineProperty(ce,"long2ip",{enumerable:!0,get:function(){return It.long2ip}});var Wc=ds(),cn=class r{constructor(e,t){if(typeof e!="string")throw new Error("Missing `net' parameter");(e.indexOf("/")!==-1?e.substring(0,e.indexOf("/")):e).indexOf(":")!==-1?this._impl=new Wc.Netmask6Impl(e,t):this._impl=new It.Netmask4Impl(e,t),this.base=this._impl.base,this.mask=this._impl.mask,this.hostmask=this._impl.hostmask,this.bitmask=this._impl.bitmask,this.size=this._impl.size,this.first=this._impl.first,this.last=this._impl.last,this.broadcast=this._impl.broadcast,this._impl instanceof It.Netmask4Impl?(this.maskLong=this._impl.maskLong,this.netLong=this._impl.netLong):(this.maskLong=0,this.netLong=0)}contains(e){return typeof e=="string"&&(e.indexOf("/")>0?e=new r(e):e.indexOf(":")===-1&&e.split(".").length!==4&&(e=new r(e))),e instanceof r?this.contains(e.base)&&this.contains(e.broadcast||e.last):this._impl.contains(e)}next(e=1){let t=this._impl.next(e);return new r(t.base,t.bitmask)}forEach(e){this._impl.forEach(e)}toString(){return this._impl.toString()}};ce.Netmask=cn});var Hu={};v(Hu,{dcutr:()=>Xu,multicodec:()=>je});var we=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}};var Q=class extends Error{static name="InvalidMessageError";constructor(e="Invalid message"){super(e),this.name="InvalidMessageError"}};var to=Symbol.for("@libp2p/service-dependencies");function ti(r){return r.buffer instanceof ArrayBuffer}function Vt(r){return ti(r)?r:r.slice()}var qt={};v(qt,{base58btc:()=>G,base58flickr:()=>ui});var Ih=new Uint8Array(0);function ro(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){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return ue(r);if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return ue(new Uint8Array(r.buffer,r.byteOffset,r.byteLength));throw new Error("Unknown type, must be binary type")}function no(r){return new TextEncoder().encode(r)}function oo(r){return new TextDecoder().decode(r)}function ri(r){return r?.buffer instanceof ArrayBuffer}function ue(r){return ri(r)?r:r.slice()}function ni(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,c=r.charAt(0),h=Math.log(a)/Math.log(256),u=Math.log(256)/Math.log(a);function f(l){if(l instanceof Uint8Array||(ArrayBuffer.isView(l)?l=new Uint8Array(l.buffer,l.byteOffset,l.byteLength):Array.isArray(l)&&(l=Uint8Array.from(l))),!(l instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(l.length===0)return"";for(var x=0,V=0,A=0,N=l.length;A!==N&&l[A]===0;)A++,x++;for(var P=(N-A)*u+1>>>0,E=new Uint8Array(P);A!==N;){for(var O=l[A],F=0,S=P-1;(O!==0||F<V)&&S!==-1;S--,F++)O+=256*E[S]>>>0,E[S]=O%a>>>0,O=O/a>>>0;if(O!==0)throw new Error("Non-zero carry");V=F,A++}for(var U=P-V;U!==P&&E[U]===0;)U++;for(var H=c.repeat(x);U<P;++U)H+=r.charAt(E[U]);return H}function p(l){if(typeof l!="string")throw new TypeError("Expected String");if(l.length===0)return new Uint8Array;var x=0;if(l[x]!==" "){for(var V=0,A=0;l[x]===c;)V++,x++;for(var N=(l.length-x)*h+1>>>0,P=new Uint8Array(N);l[x];){var E=t[l.charCodeAt(x)];if(E===255)return;for(var O=0,F=N-1;(E!==0||O<A)&&F!==-1;F--,O++)E+=a*P[F]>>>0,P[F]=E%256>>>0,E=E/256>>>0;if(E!==0)throw new Error("Non-zero carry");A=O,x++}if(l[x]!==" "){for(var S=N-A;S!==N&&P[S]===0;)S++;for(var U=new Uint8Array(V+(N-S)),H=V;S!==N;)U[H++]=P[S++];return U}}}function g(l){var x=p(l);if(x)return x;throw new Error(`Non-${e} character`)}return{encode:f,decodeUnsafe:p,decode:g}}var oi=ni,si=oi,io=si;var $t=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")}},Wt=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 ao(this,e)}},jt=class{decoders;constructor(e){this.decoders=e}or(e){return ao(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 ao(r,e){return new jt({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var Gt=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 $t(e,t,n),this.decoder=new Wt(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function ye({name:r,prefix:e,encode:t,decode:n}){return new Gt(r,e,t,n)}function ne({name:r,prefix:e,alphabet:t}){let{encode:n,decode:o}=io(t,r);return ye({prefix:e,name:r,encode:n,decode:s=>J(o(s))})}function ii(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,c=0;for(let h=0;h<o;++h){let u=e[r[h]];if(u===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<t|u,i+=t,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=t||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function ai(r,e,t){let n=e[e.length-1]==="=",o=(1<<t)-1,s="",i=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],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 ci(r){let e={};for(let t=0;t<r.length;++t)e[r[t]]=t;return e}function T({name:r,prefix:e,bitsPerChar:t,alphabet:n}){let o=ci(n);return ye({prefix:e,name:r,encode(s){return ai(s,n,t)},decode(s){return ii(s,o,t,r)}})}var G=ne({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),ui=ne({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Xt={};v(Xt,{base32:()=>oe,base32hex:()=>di,base32hexpad:()=>mi,base32hexpadupper:()=>gi,base32hexupper:()=>pi,base32pad:()=>fi,base32padupper:()=>li,base32upper:()=>hi,base32z:()=>bi});var oe=T({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),hi=T({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),fi=T({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),li=T({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),di=T({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),pi=T({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),mi=T({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),gi=T({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),bi=T({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Ht={};v(Ht,{base36:()=>Ge,base36upper:()=>xi});var Ge=ne({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),xi=ne({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var wi=ho,co=128,yi=127,Ei=~yi,vi=Math.pow(2,31);function ho(r,e,t){e=e||[],t=t||0;for(var n=t;r>=vi;)e[t++]=r&255|co,r/=128;for(;r&Ei;)e[t++]=r&255|co,r>>>=7;return e[t]=r|0,ho.bytes=t-n+1,e}var Ii=Qt,Ci=128,uo=127;function Qt(r,n){var t=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw Qt.bytes=0,new RangeError("Could not decode varint");i=r[s++],t+=o<28?(i&uo)<<o:(i&uo)*Math.pow(2,o),o+=7}while(i>=Ci);return Qt.bytes=s-n,t}var Ai=Math.pow(2,7),Si=Math.pow(2,14),Di=Math.pow(2,21),Ti=Math.pow(2,28),Li=Math.pow(2,35),Ni=Math.pow(2,42),Pi=Math.pow(2,49),Oi=Math.pow(2,56),Ui=Math.pow(2,63),_i=function(r){return r<Ai?1:r<Si?2:r<Di?3:r<Ti?4:r<Li?5:r<Ni?6:r<Pi?7:r<Oi?8:r<Ui?9:10},Fi={encode:wi,decode:Ii,encodingLength:_i},Bi=Fi,qe=Bi;function Xe(r,e=0){return[qe.decode(r,e),qe.decode.bytes]}function Ee(r,e,t=0){return qe.encode(r,e,t),e}function ve(r){return qe.encodingLength(r)}function Ce(r,e){let t=e.byteLength,n=ve(r),o=n+ve(t),s=new Uint8Array(o+t);return Ee(r,s,0),Ee(t,s,n),s.set(e,o),new Ie(r,t,e,s)}function fo(r){let e=J(r),[t,n]=Xe(e),[o,s]=Xe(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Ie(t,o,i,e)}function lo(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&ro(r.bytes,t.bytes)}}var Ie=class{code;size;digest;bytes;constructor(e,t,n,o){this.code=e,this.size=t,this.digest=ue(n),this.bytes=ue(o)}};function po(r,e){let{bytes:t,version:n}=r;return n===0?Ri(t,Jt(r),e??G.encoder):ki(t,Jt(r),e??oe.encoder)}var mo=new WeakMap;function Jt(r){let e=mo.get(r);if(e==null){let t=new Map;return mo.set(r,t),t}return e}var Ae=class r{code;version;multihash;bytes;"/";constructor(e,t,n,o){this.code=t,this.version=e,this.multihash=n,this.bytes=ue(o),this["/"]=this.bytes}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!==Qe)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==zi)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=Ce(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&&lo(e.multihash,n.multihash)}toString(e){return po(this,e)}toJSON(){return{"/":po(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??go(n,o,s.bytes))}else if(t[Vi]===!0){let{version:n,multihash:o,code:s}=t,i=fo(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!==Qe)throw new Error(`Version 0 CID must use dag-pb (code: ${Qe}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let o=go(e,t,n.bytes);return new r(e,t,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,Qe,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=J(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 Ie(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[f,p]=Xe(e.subarray(t));return t+=p,f},o=n(),s=Qe;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(),c=n(),h=t+c,u=h-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:u,size:h}}static parse(e,t){let[n,o]=Mi(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 Jt(s).set(n,e),s}};function Mi(r,e){switch(r[0]){case"Q":{let t=e??G;return[G.prefix,t.decode(`${G.prefix}${r}`)]}case G.prefix:{let t=e??G;return[G.prefix,t.decode(r)]}case oe.prefix:{let t=e??oe;return[oe.prefix,t.decode(r)]}case Ge.prefix:{let t=e??Ge;return[Ge.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 Ri(r,e,t){let{prefix:n}=t;if(n!==G.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 ki(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 Qe=112,zi=18;function go(r,e,t){let n=ve(r),o=n+ve(e),s=new Uint8Array(o+t.byteLength);return Ee(r,s,0),Ee(e,s,n),s.set(t,o),s}var Vi=Symbol.for("@ipld/js-cid/CID");var Yt={};v(Yt,{identity:()=>ji});var bo=0,$i="identity",xo=J;function Wi(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 Ce(bo,xo(r))}var ji={code:bo,name:$i,encode:xo,digest:Wi};function Kt(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 Y(r=0){return new Uint8Array(r)}function Je(r=0){return new Uint8Array(r)}function Zt(r,e){e==null&&(e=r.reduce((o,s)=>o+s.length,0));let t=Je(e),n=0;for(let o of r)t.set(o,n),n+=o.length;return t}function wo(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}var Eo=Symbol.for("@achingbrain/uint8arraylist");function yo(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 lt(r){return!!r?.[Eo]}var he=class r{bufs;length;[Eo]=!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(lt(n)){t+=n.byteLength;for(let o of n.bufs)this.bufs.push(o)}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(lt(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=yo(this.bufs,e);return t.buf[t.index]}set(e,t){let n=yo(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(lt(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 Zt(n,o)}subarray(e,t){let{bufs:n,length:o}=this._subList(e,t);return n.length===1?n[0]:Zt(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,c=a+i.byteLength;if(o=c,e>=c)continue;let h=e>=a&&e<c,u=t>a&&t<=c;if(h&&u){if(e===a&&t===c){n.push(i);break}let f=e-a;n.push(i.subarray(f,f+(t-e)));break}if(h){if(e===0){n.push(i);continue}n.push(i.subarray(e-a));continue}if(u){if(t===c){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(!lt(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 f=0;f<s;f++)i[f]=-1;for(let f=0;f<o;f++)i[n[f]]=f;let a=i,c=this.byteLength-n.byteLength,h=n.byteLength-1,u;for(let f=t;f<=c;f+=u){u=0;for(let p=h;p>=0;p--){let g=this.get(f+p);if(n[p]!==g){u=Math.max(1,p-a[g]);break}}if(u===0)return f}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=Je(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=Y(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=Y(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=Y(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=Je(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=Y(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=Y(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=Y(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=Y(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=Y(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(!wo(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 er={};v(er,{base10:()=>Gi});var Gi=ne({prefix:"9",name:"base10",alphabet:"0123456789"});var tr={};v(tr,{base16:()=>qi,base16upper:()=>Xi});var qi=T({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Xi=T({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var rr={};v(rr,{base2:()=>Hi});var Hi=T({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var nr={};v(nr,{base256emoji:()=>Zi});var vo=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}"),Qi=vo.reduce((r,e,t)=>(r[t]=e,r),[]),Ji=vo.reduce((r,e,t)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return r[n]=t,r},[]);function Yi(r){return r.reduce((e,t)=>(e+=Qi[t],e),"")}function Ki(r){let e=[];for(let t of r){let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);let o=Ji[n];if(o==null)throw new Error(`Non-base256emoji character: ${t}`);e.push(o)}return new Uint8Array(e)}var Zi=ye({prefix:"\u{1F680}",name:"base256emoji",encode:Yi,decode:Ki});var sr={};v(sr,{base64:()=>ea,base64pad:()=>ta,base64url:()=>or,base64urlpad:()=>ra});var ea=T({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),ta=T({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),or=T({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),ra=T({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var ir={};v(ir,{base8:()=>na});var na=T({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var ar={};v(ar,{identity:()=>oa});var oa=ye({prefix:"\0",name:"identity",encode:r=>oo(r),decode:r=>no(r)});var cf=new TextEncoder,uf=new TextDecoder;var hr={};v(hr,{sha256:()=>ca,sha512:()=>ua});var aa=20;function ur({name:r,code:e,encode:t,minDigestLength:n,maxDigestLength:o}){return new cr(r,e,t,n,o)}var cr=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,t,n,o,s){this.name=e,this.code=t,this.encode=n,this.minDigestLength=o??aa,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?Io(n,this.code,t?.truncate):n.then(o=>Io(o,this.code,t?.truncate))}else throw Error("Unknown type, must be binary type")}};function Io(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 Ce(e,r)}function Ao(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var ca=ur({name:"sha2-256",code:18,encode:Ao("SHA-256")}),ua=ur({name:"sha2-512",code:19,encode:Ao("SHA-512")});var Ye={...ar,...rr,...ir,...er,...tr,...Xt,...Ht,...qt,...sr,...nr},Ef={...hr,...Yt};function fe(r=0){return new Uint8Array(r)}function Do(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var So=Do("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),fr=Do("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=fe(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),ha={utf8:So,"utf-8":So,hex:Ye.base16,latin1:fr,ascii:fr,binary:fr,...Ye},dt=ha;function Se(r,e="utf8"){let t=dt[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.decoder.decode(`${t.prefix}${r}`)}function se(r,e="utf8"){let t=dt[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.encoder.encode(r).substring(1)}function fa(r){return r?.buffer instanceof ArrayBuffer}function lr(r){if(fa(r))return r;let e=r.slice();return new Uint8Array(e.buffer,0,e.byteLength)}function De(r,e){e==null&&(e=r.reduce((o,s)=>o+s.length,0));let t=fe(e),n=0;for(let o of r)t.set(o,n),n+=o.length;return lr(t)}function To(r=0){return new Uint8Array(r)}var la=Math.pow(2,7),da=Math.pow(2,14),pa=Math.pow(2,21),dr=Math.pow(2,28),pr=Math.pow(2,35),mr=Math.pow(2,42),gr=Math.pow(2,49),w=128,M=127;function K(r){if(r<la)return 1;if(r<da)return 2;if(r<pa)return 3;if(r<dr)return 4;if(r<pr)return 5;if(r<mr)return 6;if(r<gr)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function br(r,e,t=0){switch(K(r)){case 8:e[t++]=r&255|w,r/=128;case 7:e[t++]=r&255|w,r/=128;case 6:e[t++]=r&255|w,r/=128;case 5:e[t++]=r&255|w,r/=128;case 4:e[t++]=r&255|w,r>>>=7;case 3:e[t++]=r&255|w,r>>>=7;case 2:e[t++]=r&255|w,r>>>=7;case 1:{e[t++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return e}function ma(r,e,t=0){switch(K(r)){case 8:e.set(t++,r&255|w),r/=128;case 7:e.set(t++,r&255|w),r/=128;case 6:e.set(t++,r&255|w),r/=128;case 5:e.set(t++,r&255|w),r/=128;case 4:e.set(t++,r&255|w),r>>>=7;case 3:e.set(t++,r&255|w),r>>>=7;case 2:e.set(t++,r&255|w),r>>>=7;case 1:{e.set(t++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return e}function xr(r,e){let t=r[e],n=0;if(n+=t&M,t<w||(t=r[e+1],n+=(t&M)<<7,t<w)||(t=r[e+2],n+=(t&M)<<14,t<w)||(t=r[e+3],n+=(t&M)<<21,t<w)||(t=r[e+4],n+=(t&M)*dr,t<w)||(t=r[e+5],n+=(t&M)*pr,t<w)||(t=r[e+6],n+=(t&M)*mr,t<w)||(t=r[e+7],n+=(t&M)*gr,t<w))return n;throw new RangeError("Could not decode varint")}function ga(r,e){let t=r.get(e),n=0;if(n+=t&M,t<w||(t=r.get(e+1),n+=(t&M)<<7,t<w)||(t=r.get(e+2),n+=(t&M)<<14,t<w)||(t=r.get(e+3),n+=(t&M)<<21,t<w)||(t=r.get(e+4),n+=(t&M)*dr,t<w)||(t=r.get(e+5),n+=(t&M)*pr,t<w)||(t=r.get(e+6),n+=(t&M)*mr,t<w)||(t=r.get(e+7),n+=(t&M)*gr,t<w))return n;throw new RangeError("Could not decode varint")}function Lo(r,e,t=0){return e==null&&(e=To(K(r))),e instanceof Uint8Array?br(r,e,t):ma(r,e,t)}function No(r,e=0){return r instanceof Uint8Array?xr(r,e):ga(r,e)}var wr=new Float32Array([-0]),ie=new Uint8Array(wr.buffer);function Po(r,e,t){wr[0]=r,e[t]=ie[0],e[t+1]=ie[1],e[t+2]=ie[2],e[t+3]=ie[3]}function Oo(r,e){return ie[0]=r[e],ie[1]=r[e+1],ie[2]=r[e+2],ie[3]=r[e+3],wr[0]}var yr=new Float64Array([-0]),R=new Uint8Array(yr.buffer);function Uo(r,e,t){yr[0]=r,e[t]=R[0],e[t+1]=R[1],e[t+2]=R[2],e[t+3]=R[3],e[t+4]=R[4],e[t+5]=R[5],e[t+6]=R[6],e[t+7]=R[7]}function _o(r,e){return R[0]=r[e],R[1]=r[e+1],R[2]=r[e+2],R[3]=r[e+3],R[4]=r[e+4],R[5]=r[e+5],R[6]=r[e+6],R[7]=r[e+7],yr[0]}var xa=BigInt(Number.MAX_SAFE_INTEGER),wa=BigInt(Number.MIN_SAFE_INTEGER),$=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 le;if(e<xa&&e>wa)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>Fo&&(o=0n,++n>Fo&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(e){if(e===0)return le;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):le}},le=new $(0,0);le.toBigInt=function(){return 0n};le.zzEncode=le.zzDecode=function(){return this};le.length=function(){return 1};var Fo=4294967296n;function Bo(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 Mo(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 Er(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 W(r,e){return RangeError(`index out of range: ${r.pos} + ${e??1} > ${r.len}`)}function pt(r,e){return(r[e-4]|r[e-3]<<8|r[e-2]<<16|r[e-1]<<24)>>>0}var vr=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,W(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 W(this,4);return pt(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw W(this,4);return pt(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw W(this,4);let e=Oo(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw W(this,4);let e=_o(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 W(this,e);return this.pos+=e,t===n?new Uint8Array(0):this.buf.subarray(t,n)}string(){let e=this.bytes();return Mo(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw W(this,e);this.pos+=e}else do if(this.pos>=this.len)throw W(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 $(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 W(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 W(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 W(this,8);let e=pt(this.buf,this.pos+=4),t=pt(this.buf,this.pos+=4);return new $(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=xr(this.buf,this.pos);return this.pos+=K(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 Ke(r){return new vr(r instanceof Uint8Array?r:r.subarray())}function Ir(r,e,t){let n=Ke(r);return e.decode(n,void 0,t)}function de(r=0){return new Uint8Array(r)}var Tr={};v(Tr,{base10:()=>Sa});var qf=new Uint8Array(0);function ko(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 Z(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 zo(r){return new TextEncoder().encode(r)}function Vo(r){return new TextDecoder().decode(r)}function ya(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,c=r.charAt(0),h=Math.log(a)/Math.log(256),u=Math.log(256)/Math.log(a);function f(l){if(l instanceof Uint8Array||(ArrayBuffer.isView(l)?l=new Uint8Array(l.buffer,l.byteOffset,l.byteLength):Array.isArray(l)&&(l=Uint8Array.from(l))),!(l instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(l.length===0)return"";for(var x=0,V=0,A=0,N=l.length;A!==N&&l[A]===0;)A++,x++;for(var P=(N-A)*u+1>>>0,E=new Uint8Array(P);A!==N;){for(var O=l[A],F=0,S=P-1;(O!==0||F<V)&&S!==-1;S--,F++)O+=256*E[S]>>>0,E[S]=O%a>>>0,O=O/a>>>0;if(O!==0)throw new Error("Non-zero carry");V=F,A++}for(var U=P-V;U!==P&&E[U]===0;)U++;for(var H=c.repeat(x);U<P;++U)H+=r.charAt(E[U]);return H}function p(l){if(typeof l!="string")throw new TypeError("Expected String");if(l.length===0)return new Uint8Array;var x=0;if(l[x]!==" "){for(var V=0,A=0;l[x]===c;)V++,x++;for(var N=(l.length-x)*h+1>>>0,P=new Uint8Array(N);l[x];){var E=t[l.charCodeAt(x)];if(E===255)return;for(var O=0,F=N-1;(E!==0||O<A)&&F!==-1;F--,O++)E+=a*P[F]>>>0,P[F]=E%256>>>0,E=E/256>>>0;if(E!==0)throw new Error("Non-zero carry");A=O,x++}if(l[x]!==" "){for(var S=N-A;S!==N&&P[S]===0;)S++;for(var U=new Uint8Array(V+(N-S)),H=V;S!==N;)U[H++]=P[S++];return U}}}function g(l){var x=p(l);if(x)return x;throw new Error(`Non-${e} character`)}return{encode:f,decodeUnsafe:p,decode:g}}var Ea=ya,va=Ea,Wo=va;var Cr=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")}},Ar=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 jo(this,e)}},Sr=class{decoders;constructor(e){this.decoders=e}or(e){return jo(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 jo(r,e){return new Sr({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var Dr=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 Cr(e,t,n),this.decoder=new Ar(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function Te({name:r,prefix:e,encode:t,decode:n}){return new Dr(r,e,t,n)}function ae({name:r,prefix:e,alphabet:t}){let{encode:n,decode:o}=Wo(t,r);return Te({prefix:e,name:r,encode:n,decode:s=>Z(o(s))})}function Ia(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,c=0;for(let h=0;h<o;++h){let u=e[r[h]];if(u===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<t|u,i+=t,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=t||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function Ca(r,e,t){let n=e[e.length-1]==="=",o=(1<<t)-1,s="",i=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],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 Aa(r){let e={};for(let t=0;t<r.length;++t)e[r[t]]=t;return e}function L({name:r,prefix:e,bitsPerChar:t,alphabet:n}){let o=Aa(n);return Te({prefix:e,name:r,encode(s){return Ca(s,n,t)},decode(s){return Ia(s,o,t,r)}})}var Sa=ae({prefix:"9",name:"base10",alphabet:"0123456789"});var Lr={};v(Lr,{base16:()=>Da,base16upper:()=>Ta});var Da=L({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Ta=L({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Nr={};v(Nr,{base2:()=>La});var La=L({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Pr={};v(Pr,{base256emoji:()=>_a});var Go=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}"),Na=Go.reduce((r,e,t)=>(r[t]=e,r),[]),Pa=Go.reduce((r,e,t)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return r[n]=t,r},[]);function Oa(r){return r.reduce((e,t)=>(e+=Na[t],e),"")}function Ua(r){let e=[];for(let t of r){let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);let o=Pa[n];if(o==null)throw new Error(`Non-base256emoji character: ${t}`);e.push(o)}return new Uint8Array(e)}var _a=Te({prefix:"\u{1F680}",name:"base256emoji",encode:Oa,decode:Ua});var Or={};v(Or,{base32:()=>Le,base32hex:()=>Ra,base32hexpad:()=>za,base32hexpadupper:()=>Va,base32hexupper:()=>ka,base32pad:()=>Ba,base32padupper:()=>Ma,base32upper:()=>Fa,base32z:()=>$a});var Le=L({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Fa=L({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Ba=L({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Ma=L({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Ra=L({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),ka=L({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),za=L({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Va=L({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),$a=L({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Ur={};v(Ur,{base36:()=>Ze,base36upper:()=>Wa});var Ze=ae({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Wa=ae({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var _r={};v(_r,{base58btc:()=>q,base58flickr:()=>ja});var q=ae({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),ja=ae({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Fr={};v(Fr,{base64:()=>Ga,base64pad:()=>qa,base64url:()=>Xa,base64urlpad:()=>Ha});var Ga=L({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),qa=L({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Xa=L({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Ha=L({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Br={};v(Br,{base8:()=>Qa});var Qa=L({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Mr={};v(Mr,{identity:()=>Ja});var Ja=Te({prefix:"\0",name:"identity",encode:r=>Vo(r),decode:r=>zo(r)});var cl=new TextEncoder,ul=new TextDecoder;var kr={};v(kr,{identity:()=>wc});var Za=Ho,qo=128,ec=127,tc=~ec,rc=Math.pow(2,31);function Ho(r,e,t){e=e||[],t=t||0;for(var n=t;r>=rc;)e[t++]=r&255|qo,r/=128;for(;r&tc;)e[t++]=r&255|qo,r>>>=7;return e[t]=r|0,Ho.bytes=t-n+1,e}var nc=Rr,oc=128,Xo=127;function Rr(r,n){var t=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw Rr.bytes=0,new RangeError("Could not decode varint");i=r[s++],t+=o<28?(i&Xo)<<o:(i&Xo)*Math.pow(2,o),o+=7}while(i>=oc);return Rr.bytes=s-n,t}var sc=Math.pow(2,7),ic=Math.pow(2,14),ac=Math.pow(2,21),cc=Math.pow(2,28),uc=Math.pow(2,35),hc=Math.pow(2,42),fc=Math.pow(2,49),lc=Math.pow(2,56),dc=Math.pow(2,63),pc=function(r){return r<sc?1:r<ic?2:r<ac?3:r<cc?4:r<uc?5:r<hc?6:r<fc?7:r<lc?8:r<dc?9:10},mc={encode:Za,decode:nc,encodingLength:pc},gc=mc,et=gc;function tt(r,e=0){return[et.decode(r,e),et.decode.bytes]}function Ne(r,e,t=0){return et.encode(r,e,t),e}function Pe(r){return et.encodingLength(r)}function Ue(r,e){let t=e.byteLength,n=Pe(r),o=n+Pe(t),s=new Uint8Array(o+t);return Ne(r,s,0),Ne(t,s,n),s.set(e,o),new Oe(r,t,e,s)}function Qo(r){let e=Z(r),[t,n]=tt(e),[o,s]=tt(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Oe(t,o,i,e)}function Jo(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&ko(r.bytes,t.bytes)}}var Oe=class{code;size;digest;bytes;constructor(e,t,n,o){this.code=e,this.size=t,this.digest=n,this.bytes=o}};var Yo=0,bc="identity",Ko=Z;function xc(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 Ue(Yo,Ko(r))}var wc={code:Yo,name:bc,encode:Ko,digest:xc};var $r={};v($r,{sha256:()=>Ec,sha512:()=>vc});var yc=20;function Vr({name:r,code:e,encode:t,minDigestLength:n,maxDigestLength:o}){return new zr(r,e,t,n,o)}var zr=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,t,n,o,s){this.name=e,this.code=t,this.encode=n,this.minDigestLength=o??yc,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?Zo(n,this.code,t?.truncate):n.then(o=>Zo(o,this.code,t?.truncate))}else throw Error("Unknown type, must be binary type")}};function Zo(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 Ue(e,r)}function ts(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var Ec=Vr({name:"sha2-256",code:18,encode:ts("SHA-256")}),vc=Vr({name:"sha2-512",code:19,encode:ts("SHA-512")});function rs(r,e){let{bytes:t,version:n}=r;return n===0?Cc(t,Wr(r),e??q.encoder):Ac(t,Wr(r),e??Le.encoder)}var ns=new WeakMap;function Wr(r){let e=ns.get(r);if(e==null){let t=new Map;return ns.set(r,t),t}return e}var gt=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!==nt)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==Sc)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=Ue(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&&Jo(e.multihash,n.multihash)}toString(e){return rs(this,e)}toJSON(){return{"/":rs(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??os(n,o,s.bytes))}else if(t[Dc]===!0){let{version:n,multihash:o,code:s}=t,i=Qo(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!==nt)throw new Error(`Version 0 CID must use dag-pb (code: ${nt}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let o=os(e,t,n.bytes);return new r(e,t,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,nt,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=Z(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 Oe(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[f,p]=tt(e.subarray(t));return t+=p,f},o=n(),s=nt;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(),c=n(),h=t+c,u=h-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:u,size:h}}static parse(e,t){let[n,o]=Ic(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 Wr(s).set(n,e),s}};function Ic(r,e){switch(r[0]){case"Q":{let t=e??q;return[q.prefix,t.decode(`${q.prefix}${r}`)]}case q.prefix:{let t=e??q;return[q.prefix,t.decode(r)]}case Le.prefix:{let t=e??Le;return[Le.prefix,t.decode(r)]}case Ze.prefix:{let t=e??Ze;return[Ze.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 Cc(r,e,t){let{prefix:n}=t;if(n!==q.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 Ac(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 nt=112,Sc=18;function os(r,e,t){let n=Pe(r),o=n+Pe(e),s=new Uint8Array(o+t.byteLength);return Ne(r,s,0),Ne(e,s,n),s.set(t,o),s}var Dc=Symbol.for("@ipld/js-cid/CID");var jr={...Mr,...Nr,...Br,...Tr,...Lr,...Or,...Ur,..._r,...Fr,...Pr},Pl={...$r,...kr};function is(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var ss=is("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Gr=is("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=de(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),Tc={utf8:ss,"utf-8":ss,hex:jr.base16,latin1:Gr,ascii:Gr,binary:Gr,...jr},as=Tc;function cs(r,e="utf8"){let t=as[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.decoder.decode(`${t.prefix}${r}`)}function qr(r){let e=r??8192,t=e>>>1,n,o=e;return function(i){if(i<1||i>t)return de(i);o+i>e&&(n=de(e),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var pe=class{fn;len;next;val;constructor(e,t,n){this.fn=e,this.len=t,this.next=void 0,this.val=n}};function Xr(){}var Qr=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},Lc=qr();function Nc(r){return globalThis.Buffer!=null?de(r):Lc(r)}var st=class{len;head;tail;states;constructor(){this.len=0,this.head=new pe(Xr,0,0),this.tail=this.head,this.states=null}_push(e,t,n){return this.tail=this.tail.next=new pe(e,t,n),this.len+=t,this}uint32(e){return this.len+=(this.tail=this.tail.next=new Jr((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(bt,10,$.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let t=$.fromBigInt(e);return this._push(bt,t.length(),t)}uint64Number(e){return this._push(br,K(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=$.fromBigInt(e).zzEncode();return this._push(bt,t.length(),t)}sint64Number(e){let t=$.fromNumber(e).zzEncode();return this._push(bt,t.length(),t)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(Hr,1,e?1:0)}fixed32(e){return this._push(ot,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let t=$.fromBigInt(e);return this._push(ot,4,t.lo)._push(ot,4,t.hi)}fixed64Number(e){let t=$.fromNumber(e);return this._push(ot,4,t.lo)._push(ot,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(Po,4,e)}double(e){return this._push(Uo,8,e)}bytes(e){let t=e.length>>>0;return t===0?this._push(Hr,1,0):this.uint32(t)._push(Oc,t,e)}string(e){let t=Bo(e);return t!==0?this.uint32(t)._push(Er,t,e):this._push(Hr,1,0)}fork(){return this.states=new Qr(this),this.head=this.tail=new pe(Xr,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new pe(Xr,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=Nc(this.len),n=0;for(;e!=null;)e.fn(e.val,t,n),n+=e.len,e=e.next;return t}};function Hr(r,e,t){e[t]=r&255}function Pc(r,e,t){for(;r>127;)e[t++]=r&127|128,r>>>=7;e[t]=r}var Jr=class extends pe{next;constructor(e,t){super(Pc,e,t),this.next=void 0}};function bt(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 ot(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 Oc(r,e,t){e.set(r,t)}globalThis.Buffer!=null&&(st.prototype.bytes=function(r){let e=r.length>>>0;return this.uint32(e),e>0&&this._push(Uc,e,r),this},st.prototype.string=function(r){let e=globalThis.Buffer.byteLength(r);return this.uint32(e),e>0&&this._push(_c,e,r),this});function Uc(r,e,t){e.set(r,t)}function _c(r,e,t){r.length<40?Er(r,e,t):e.utf8Write!=null?e.utf8Write(r,t):e.set(cs(r),t)}function Yr(){return new st}function Kr(r,e){let t=Yr();return e.encode(r,t,{lengthDelimited:!1}),t.finish()}function*Zr(r,e,t){let n=Ke(r);yield*e.stream(n,void 0,"$",t)}var xt={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function wt(r,e,t,n,o){return{name:r,type:e,encode:t,decode:n,stream:o}}function en(r){function e(s){if(r[s.toString()]==null)throw new Error("Invalid enum value");return r[s]}let t=function(i,a){let c=e(i);a.int32(c)},n=function(i){let a=i.int32();return e(a)},o=function*(i){let a=i.int32();yield e(a)};return wt("enum",xt.VARINT,t,n,o)}function tn(r,e,t){return wt("message",xt.LENGTH_DELIMITED,r,e,t)}var it=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};function Fc(r){let e=r.getComponents(),t={},n=0;return 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?null:(e[n]?.name==="tls"&&e[n+1]?.name==="sni"&&(t.sni=e[n+1].value,n+=2),t)}function us(r){let e=Fc(r);if(e==null)throw new we(`Multiaddr ${r} was not an IPv4, IPv6, DNS, DNS4, DNS6 or DNSADDR address`);return e}var yt=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 c=a==="0",h=2**(8*o)-1;for(;;){let u=this.readAtomically(()=>{let f=this.readChar();if(f===void 0)return;let p=Number.parseInt(f,e);if(!Number.isNaN(p))return p});if(u===void 0)break;if(s*=e,s+=u,s>h||(i+=1,t!==void 0&&i>t))return}if(i!==0)return!n&&c&&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 Bc=45,Mc=15,Et=new yt;function hs(r){if(!(r.length>Mc))return Et.new(r).parseWith(()=>Et.readIPv4Addr())}function fs(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>Bc))return Et.new(r).parseWith(()=>Et.readIPv6Addr())}function _e(r){return!!hs(r)}function vt(r){return!!fs(r)}var ms=Zs(ps(),1),jc=["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"],Gc=jc.map(r=>new ms.Netmask(r));function un(r){for(let e of Gc)if(e.contains(r))return!0;return!1}function qc(r){return/^::ffff:([0-9a-fA-F]{1,4}):([0-9a-fA-F]{1,4})$/.test(r)}function Xc(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 un(o)}function Hc(r){return/^::ffff:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(r)}function Qc(r){let e=r.split(":"),t=e[e.length-1];return un(t)}function Jc(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 gs(r){if(_e(r))return un(r);if(qc(r))return Xc(r);if(Hc(r))return Qc(r);if(vt(r))return Jc(r)}function bs(r){try{let e=us(r);switch(e.type){case"ip4":case"ip6":return gs(e.host)??!1;default:return e.host==="localhost"}}catch{return!1}}var Yc=Math.pow(2,7),Kc=Math.pow(2,14),Zc=Math.pow(2,21),hn=Math.pow(2,28),fn=Math.pow(2,35),ln=Math.pow(2,42),dn=Math.pow(2,49),D=128,k=127;function Re(r){if(r<Yc)return 1;if(r<Kc)return 2;if(r<Zc)return 3;if(r<hn)return 4;if(r<fn)return 5;if(r<ln)return 6;if(r<dn)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function pn(r,e,t=0){switch(Re(r)){case 8:e[t++]=r&255|D,r/=128;case 7:e[t++]=r&255|D,r/=128;case 6:e[t++]=r&255|D,r/=128;case 5:e[t++]=r&255|D,r/=128;case 4:e[t++]=r&255|D,r>>>=7;case 3:e[t++]=r&255|D,r>>>=7;case 2:e[t++]=r&255|D,r>>>=7;case 1:{e[t++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return e}function eu(r,e){let t=r[e],n=0;if(n+=t&k,t<D||(t=r[e+1],n+=(t&k)<<7,t<D)||(t=r[e+2],n+=(t&k)<<14,t<D)||(t=r[e+3],n+=(t&k)<<21,t<D)||(t=r[e+4],n+=(t&k)*hn,t<D)||(t=r[e+5],n+=(t&k)*fn,t<D)||(t=r[e+6],n+=(t&k)*ln,t<D)||(t=r[e+7],n+=(t&k)*dn,t<D))return n;throw new RangeError("Could not decode varint")}function tu(r,e){let t=r.get(e),n=0;if(n+=t&k,t<D||(t=r.get(e+1),n+=(t&k)<<7,t<D)||(t=r.get(e+2),n+=(t&k)<<14,t<D)||(t=r.get(e+3),n+=(t&k)<<21,t<D)||(t=r.get(e+4),n+=(t&k)*hn,t<D)||(t=r.get(e+5),n+=(t&k)*fn,t<D)||(t=r.get(e+6),n+=(t&k)*ln,t<D)||(t=r.get(e+7),n+=(t&k)*dn,t<D))return n;throw new RangeError("Could not decode varint")}function mn(r,e=0){return r instanceof Uint8Array?eu(r,e):tu(r,e)}var B=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},ee=class extends Error{static name="ValidationError";name="ValidationError"},Ct=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},At=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};function bn(r){return e=>se(e,r)}function xn(r){return e=>Se(e,r)}function ke(r){return new DataView(r.buffer).getUint16(r.byteOffset).toString()}function ge(r){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,typeof r=="string"?parseInt(r):r),new Uint8Array(e)}function xs(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=Se(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=ge(n);return De([t,o],t.length+o.length)}function ws(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=oe.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=ge(n);return De([t,o],t.length+o.length)}function wn(r){let e=r.subarray(0,r.length-2),t=r.subarray(r.length-2),n=se(e,"base32"),o=ke(t);return`${n}:${o}`}var yn=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 B("Invalid byte value in IP address");e[n]=o}),e},ys=function(r){let e=0;r=r.toString().trim();let t=r.split(":",8),n;for(n=0;n<t.length;n++){let s=_e(t[n]),i;s&&(i=yn(t[n]),t[n]=se(i.subarray(0,2),"base16")),i!=null&&++n<8&&t.splice(n,0,se(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 B("Invalid byte value in IP address");o[e++]=s>>8&255,o[e++]=s&255}return o},Es=function(r){if(r.byteLength!==4)throw new B("IPv4 address was incorrect length");let e=[];for(let t=0;t<r.byteLength;t++)e.push(r[t]);return e.join(".")},vs=function(r){if(r.byteLength!==16)throw new B("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 B(`Invalid IPv6 address "${t}"`)}};function Is(r){try{let e=new URL(`http://[${r}]`);return e.hostname.substring(1,e.hostname.length-1)}catch{throw new B(`Invalid IPv6 address "${r}"`)}}var gn=Object.values(Ye).map(r=>r.decoder),nu=(function(){let r=gn[0].or(gn[1]);return gn.slice(2).forEach(e=>r=r.or(e)),r})();function Cs(r){return nu.decode(r)}function As(r){return e=>r.encoder.encode(e)}function ou(r){if(parseInt(r).toString()!==r)throw new ee("Value must be an integer")}function su(r){if(r<0)throw new ee("Value must be a positive integer, or zero")}function iu(r){return e=>{if(e>r)throw new ee(`Value must be smaller than or equal to ${r}`)}}function au(...r){return e=>{for(let t of r)t(e)}}var at=au(ou,su,iu(65535));var _=-1,En=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 At(`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)}))}},re=new En,Eu=[{code:4,name:"ip4",size:32,valueToBytes:yn,bytesToValue:Es,validate:r=>{if(!_e(r))throw new ee(`Invalid IPv4 address "${r}"`)}},{code:6,name:"tcp",size:16,valueToBytes:ge,bytesToValue:ke,validate:at},{code:273,name:"udp",size:16,valueToBytes:ge,bytesToValue:ke,validate:at},{code:33,name:"dccp",size:16,valueToBytes:ge,bytesToValue:ke,validate:at},{code:41,name:"ip6",size:128,valueToBytes:ys,bytesToValue:vs,stringToValue:Is,validate:r=>{if(!vt(r))throw new ee(`Invalid IPv6 address "${r}"`)}},{code:42,name:"ip6zone",size:_},{code:43,name:"ipcidr",size:8,bytesToValue:bn("base10"),valueToBytes:xn("base10")},{code:53,name:"dns",size:_},{code:54,name:"dns4",size:_},{code:55,name:"dns6",size:_},{code:56,name:"dnsaddr",size:_},{code:132,name:"sctp",size:16,valueToBytes:ge,bytesToValue:ke,validate:at},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:_,stringToValue:r=>decodeURIComponent(r),valueToString:r=>encodeURIComponent(r)},{code:421,name:"p2p",aliases:["ipfs"],size:_,bytesToValue:bn("base58btc"),valueToBytes:r=>r.startsWith("Q")||r.startsWith("1")?xn("base58btc")(r):Ae.parse(r).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:wn,valueToBytes:xs},{code:445,name:"onion3",size:296,bytesToValue:wn,valueToBytes:ws},{code:446,name:"garlic64",size:_},{code:447,name:"garlic32",size:_},{code:448,name:"tls"},{code:449,name:"sni",size:_},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:_,bytesToValue:As(or),valueToBytes:Cs},{code:480,name:"http"},{code:481,name:"http-path",size:_,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:_}];Eu.forEach(r=>{re.addProtocol(r)});function Ss(r){let e=[],t=0;for(;t<r.length;){let n=mn(r,t),o=re.getProtocol(n),s=Re(n),i=vu(o,r,t+s),a=0;i>0&&o.size===_&&(a=Re(i));let c=s+a+i,h={code:n,name:o.name,bytes:Vt(r.subarray(t,t+c))};if(i>0){let u=t+s+a,f=r.subarray(u,u+i);h.value=o.bytesToValue?.(f)??se(f)}e.push(h),t+=c}return e}function Ds(r){let e=0,t=[];for(let n of r){if(n.bytes==null){let o=re.getProtocol(n.code),s=Re(n.code),i,a=0,c=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??Se(n.value),a=i.byteLength,o.size===_&&(c=Re(a)));let h=new Uint8Array(s+c+a),u=0;pn(n.code,h,u),u+=s,i!=null&&(o.size===_&&(pn(a,h,u),u+=c),h.set(i,u)),n.bytes=h}t.push(n.bytes),e+=n.bytes.byteLength}return De(t,e)}function Ts(r){if(r.charAt(0)!=="/")throw new B('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 c=re.getProtocol(o);if(t==="protocol"){if(c.size==null||c.size===0){e.push({code:c.code,name:c.name}),n="",o="",t="protocol";continue}else if(a)throw new B(`Component ${o} was missing value`);t="value"}else if(t==="value"){let h={code:c.code,name:c.name};if(c.size!=null&&c.size!==0){if(n==="")throw new B(`Component ${o} was missing value`);h.value=c.stringToValue?.(n)??n}e.push(h),n="",o="",t="protocol"}}}if(o!==""&&n!=="")throw new B("Incomplete multiaddr");return e}function Ls(r){return`/${r.flatMap(e=>{if(e.value==null)return e.name;let t=re.getProtocol(e.code);if(t==null)throw new B(`Unknown protocol code ${e.code}`);return[e.name,t.valueToString?.(e.value)??e.value]}).join("/")}`}function vu(r,e,t){return r.size==null||r.size===0?0:r.size>0?r.size/8:mn(e,t)}var Iu=Symbol.for("nodejs.util.inspect.custom"),Rn=Symbol.for("@multiformats/multiaddr");function Cu(r){if(r==null&&(r="/"),Ns(r))return r.getComponents();if(r instanceof Uint8Array)return Ss(r);if(typeof r=="string")return r=r.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),r===""&&(r="/"),Ts(r);if(Array.isArray(r))return r;throw new B("Must be a string, Uint8Array, Component[], or another Multiaddr")}var Pt=class r{[Rn]=!0;#e;#t;#r;constructor(e="/",t={}){this.#e=Cu(e),t.validate!==!1&&Au(this)}get bytes(){return this.#r==null&&(this.#r=Ds(this.#e)),this.#r}toString(){return this.#t==null&&(this.#t=Ls(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 Ct(`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 Kt(this.bytes,e.bytes)}[Iu](){return`Multiaddr(${this.toString()})`}};function Au(r){r.getComponents().forEach(e=>{let t=re.getProtocol(e.code);e.value!=null&&t.validate?.(e.value)})}function Ns(r){return!!r?.[Rn]}function kn(r){return new Pt(r)}var I=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)}}),Ps=r=>({match:e=>r.match(e)===!1?e:!1}),m=r=>({match:e=>{let t=r.match(e);return t===!1?e:t}}),z=(...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}}),b=(...r)=>({match:e=>{for(let t of r){let n=t.match(e);if(n===!1)return!1;e=n}return e}});function C(...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 Su=d(421),Op=C(Su),Ut=d(54),_t=d(55),Ft=d(56),Vn=d(53),Up=C(Ut,m(d(421))),_p=C(_t,m(d(421))),Fp=C(Ft,m(d(421))),Os=C(z(Vn,Ft,Ut,_t),m(d(421))),Us=b(d(4),m(d(43))),_s=b(m(d(42)),d(41),m(d(43))),$n=z(Us,_s),We=z($n,Vn,Ut,_t,Ft),Bp=C(z($n,b(z(Vn,Ft,Ut,_t),m(d(421))))),Mp=C(Us),Rp=C(_s),Fs=C($n),Wn=b(We,d(6)),ct=b(We,d(273)),kp=C(b(Wn,m(d(421)))),zp=C(ct),jn=b(ct,I(460),m(d(421))),Bt=b(ct,I(461),m(d(421))),Du=z(jn,Bt),Vp=C(jn),$p=C(Bt),zn=z(We,Wn,ct,jn,Bt),Bs=z(b(zn,I(477),m(d(421)))),Wp=C(Bs),Ms=z(b(zn,I(478),m(d(421))),b(zn,I(448),m(d(449)),I(477),m(d(421)))),jp=C(Ms),Rs=b(ct,I(280),m(d(466)),m(d(466)),m(d(421))),Gp=C(Rs),ks=b(Bt,I(465),m(d(466)),m(d(466)),m(d(421))),qp=C(ks),Ot=z(Bs,Ms,b(Wn,m(d(421))),b(Du,m(d(421))),b(We,m(d(421))),Rs,ks,d(421)),Xp=C(Ot),Tu=b(m(Ot),I(290),Ps(I(281)),m(d(421))),ut=C(Tu),Lu=z(b(Ot,I(290),I(281),m(d(421))),b(Ot,I(281),m(d(421))),b(I(281),m(d(421)))),Hp=C(Lu),Nu=b(We,z(b(d(6,"80")),b(d(6),I(480)),I(480)),m(d(481)),m(d(421))),Qp=C(Nu),Pu=b(We,z(b(d(6,"443")),b(d(6,"443"),I(480)),b(d(6),I(443)),b(d(6),I(448),I(480)),b(I(448),I(480)),I(448),I(443)),m(d(481)),m(d(421))),Jp=C(Pu),Ou=z(b(d(777),m(d(421)))),Yp=C(Ou),Uu=z(b(d(400),m(d(421)))),Kp=C(Uu);var Gn=class r extends Error{name="TimeoutError";constructor(e,t){super(e,t),Error.captureStackTrace?.(this,r)}},zs=r=>r.reason??new DOMException("This operation was aborted.","AbortError");function qn(r,e){let{milliseconds:t,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout},signal:i}=e,a,c,u=new Promise((f,p)=>{if(typeof t!="number"||Math.sign(t)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${t}\``);if(i?.aborted){p(zs(i));return}if(i&&(c=()=>{p(zs(i))},i.addEventListener("abort",c,{once:!0})),r.then(f,p),t===Number.POSITIVE_INFINITY)return;let g=new Gn;a=s.setTimeout.call(void 0,()=>{if(n){try{f(n())}catch(l){p(l)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?f():o instanceof Error?p(o):(g.message=o??`Promise timed out after ${t} milliseconds`,p(g))},t)}).finally(()=>{u.clear(),c&&i&&i.removeEventListener("abort",c)});return u.clear=()=>{s.clearTimeout.call(void 0,a),a=void 0},u}var _u=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 Fu(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(),c=[],{addListener:h,removeListener:u}=_u(r),f=async(...g)=>{let l=t.multiArgs?g:g[0];if(t.filter)try{if(!await t.filter(l))return}catch(x){n(),i(x);return}c.push(l),t.count===c.length&&(n(),s(c))},p=(...g)=>{n(),i(t.rejectionMultiArgs?g:g[0])};n=()=>{for(let g of a)u(g,f);for(let g of t.rejectionEvents)a.includes(g)||u(g,p)};for(let g of a)h(g,f);for(let g of t.rejectionEvents)a.includes(g)||h(g,p);t.signal&&t.signal.addEventListener("abort",()=>{p(t.signal.reason)},{once:!0}),t.resolveImmediately&&s(c)});if(o.cancel=n,typeof t.timeout=="number"){let s=qn(o,{milliseconds:t.timeout});return s.cancel=()=>{n(),s.clear()},s}return o}function Vs(r,e,t){typeof t=="function"&&(t={filter:t}),t={...t,count:1,resolveImmediately:!1};let n=Fu(r,e,t),o=n.then(s=>s[0]);return o.cancel=n.cancel,o}var xe=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"};function Bu(r){return r.reason}async function Xn(r,e,t){if(e==null)return r;let n=t?.translateError??Bu;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 Ru=4194304,Mt=class extends Error{static name="UnwrappedError";name="UnwrappedError"},Qn=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},Jn=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},Yn=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function ku(r){return typeof r?.closeRead=="function"}function zu(r){return typeof r?.close=="function"}function Hn(r){return ku(r)?r.remoteWriteStatus!=="writable"&&r.readBufferLength===0:zu(r)?r.status!=="open":!1}function Vu(r){return r?.addEventListener!=null&&r?.removeEventListener!=null&&r?.send!=null&&r?.push!=null&&r?.log!=null}function $u(r,e){let t=e?.maxBufferSize??Ru,n=new he,o,s=!1;if(!Vu(r))throw new we("Argument should be a Stream or a Multiaddr");let i=u=>{if(n.append(u.data),n.byteLength>t){let f=n.byteLength;n.consume(n.byteLength),o?.reject(new Error(`Read buffer overflow - ${f} > ${t}`))}o?.resolve()};r.addEventListener("message",i);let a=u=>{u.error!=null?o?.reject(u.error):o?.resolve()};r.addEventListener("close",a);let c=()=>{o?.resolve()};r.addEventListener("remoteCloseWrite",c);let h={readBuffer:n,async read(u){if(s===!0)throw new Mt("Stream was unwrapped");if(Hn(r)){if(n.byteLength===0&&u?.bytes==null)return null;if(u?.bytes!=null&&n.byteLength<u.bytes)throw r.log.error("closed after reading %d/%d bytes",n.byteLength,u.bytes),new xe(`Unexpected EOF - stream closed after reading ${n.byteLength}/${u.bytes} bytes`)}let f=u?.bytes??1;for(o=Promise.withResolvers();;){if(n.byteLength>=f){o.resolve();break}if(await Xn(o.promise,u?.signal),Hn(r)){if(n.byteLength===0&&u?.bytes==null)return null;break}o=Promise.withResolvers()}let p=u?.bytes??n.byteLength;if(n.byteLength<p){if(Hn(r))throw r.log.error("closed while reading %d/%d bytes",n.byteLength,p),new xe(`Unexpected EOF - stream closed while reading ${n.byteLength}/${p} bytes`);return h.read(u)}let g=n.sublist(0,p);return n.consume(p),g},async write(u,f){if(s===!0)throw new Mt("Stream was unwrapped");r.send(u)||await Vs(r,"drain",{signal:f?.signal,rejectionEvents:["close"]})},unwrap(){return s||(s=!0,r.removeEventListener("message",i),r.removeEventListener("close",a),r.removeEventListener("remoteCloseWrite",c),n.byteLength>0&&(r.log("stream unwrapped with %d unread bytes",n.byteLength),r.unshift(n))),r}};return h}function Wu(r,e={}){let t=$u(r,e);e.maxDataLength!=null&&e.maxLengthLength==null&&(e.maxLengthLength=K(e.maxDataLength));let n=e?.lengthDecoder??No,o=e?.lengthEncoder??Lo;return{async read(i){let a=-1,c=new he;for(;;){let u=await t.read({...i,bytes:1});if(u==null)break;c.append(u);try{a=n(c)}catch(f){if(f instanceof RangeError)continue;throw f}if(a<0)throw new Qn("Invalid message length");if(e?.maxLengthLength!=null&&c.byteLength>e.maxLengthLength)throw new Yn(`Message length length too long - ${c.byteLength} > ${e.maxLengthLength}`);if(a>-1)break}if(e?.maxDataLength!=null&&a>e.maxDataLength)throw new Jn(`Message length too long - ${a} > ${e.maxDataLength}`);let h=await t.read({...i,bytes:a});if(h==null)throw r.log.error("tried to read %d bytes but the stream closed",a),new xe(`Unexpected EOF - tried to read ${a} bytes but the stream closed`);if(h.byteLength!==a)throw r.log.error("read %d/%d bytes before the stream closed",h.byteLength,a),new xe(`Unexpected EOF - read ${h.byteLength}/${a} bytes before the stream closed`);return h},async write(i,a){await t.write(new he(o(i.byteLength),i),a)},async writeV(i,a){let c=new he(...i.flatMap(h=>[o(h.byteLength),h]));await t.write(c,a)},unwrap(){return t.unwrap()}}}function Kn(r,e){let t=Wu(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 $s=Symbol.for("sindresorhus/unlimited-timeout#brand");function Ws(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={[$s]:!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 c=performance.now(),h=Math.max(0,s-c);i(h)},2147483647),n&&o.id?.unref?.()))};return i(e),o}function js(r){!r||typeof r!="object"||!r[$s]||(r.cleared=!0,r.id!==void 0&&(globalThis.clearTimeout(r.id),r.id=void 0))}var ju=new WeakMap;function Gu({clearTimeout:r,setTimeout:e}={}){return(t,{value:n,signal:o}={})=>{if(o?.aborted)return Promise.reject(o.reason);let s,i,a,c=r??clearTimeout,h=()=>{c(s),a(o.reason)},u=()=>{o&&o.removeEventListener("abort",h)},f=new Promise((p,g)=>{i=()=>{u(),p(n)},a=g,s=(e??setTimeout)(i,t)});return o&&o.addEventListener("abort",h,{once:!0}),ju.set(f,()=>{c(s),s=null,i()}),f}}var qu=Gu({setTimeout:Ws,clearTimeout:js}),Gs=qu;var j;(function(r){let e;(function(a){a.UNUSED="UNUSED",a.CONNECT="CONNECT",a.SYNC="SYNC"})(e=r.Type||(r.Type={}));let t;(function(a){a[a.UNUSED=0]="UNUSED",a[a.CONNECT=100]="CONNECT",a[a.SYNC=300]="SYNC"})(t||(t={})),(function(a){a.codec=()=>en(t)})(e=r.Type||(r.Type={}));let n;r.codec=()=>(n==null&&(n=tn((a,c,h={})=>{if(h.lengthDelimited!==!1&&c.fork(),a.type!=null&&(c.uint32(8),r.Type.codec().encode(a.type,c)),a.observedAddresses!=null&&a.observedAddresses.length>0)for(let u of a.observedAddresses)c.uint32(18),c.bytes(u);h.lengthDelimited!==!1&&c.ldelim()},(a,c,h={})=>{let u={observedAddresses:[]},f=c==null?a.len:a.pos+c;for(;a.pos<f;){let p=a.uint32();switch(p>>>3){case 1:{u.type=r.Type.codec().decode(a);break}case 2:{if(h.limits?.observedAddresses!=null&&u.observedAddresses.length===h.limits.observedAddresses)throw new it('Decode error - repeated field "observedAddresses" had too many elements');u.observedAddresses.push(a.bytes());break}default:{a.skipType(p&7);break}}}return u},function*(a,c,h,u={}){let f={observedAddresses:0},p=c==null?a.len:a.pos+c;for(;a.pos<p;){let g=a.uint32();switch(g>>>3){case 1:{yield{field:`${h}.type`,value:r.Type.codec().decode(a)};break}case 2:{if(u.limits?.observedAddresses!=null&&f.observedAddresses===u.limits.observedAddresses)throw new it('Streaming decode error - repeated field "observedAddresses" had too many elements');yield{field:`${h}.observedAddresses[]`,index:f.observedAddresses,value:a.bytes()},f.observedAddresses++;break}default:{a.skipType(g&7);break}}}})),n);function o(a){return Kr(a,r.codec())}r.encode=o;function s(a,c){return Ir(a,r.codec(),c)}r.decode=s;function i(a,c){return Zr(a,r.codec(),c)}r.stream=i})(j||(j={}));function Zn(r,e){return ut.matches(r)||e.dialTransportForMultiaddr(r)==null?!1:Os.matches(r)?!0:Fs.matches(r)?!bs(r):!1}var qs=1024*4,Xs=100,Rt={timeout:5e3,retries:3,maxInboundStreams:1,maxOutboundStreams:1},kt=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??Rt.timeout,this.retries=t.retries??Rt.retries,this.maxInboundStreams=t.maxInboundStreams??Rt.maxInboundStreams,this.maxOutboundStreams=t.maxOutboundStreams??Rt.maxOutboundStreams,this.handleIncomingUpgrade=this.handleIncomingUpgrade.bind(this)}[Symbol.toStringTag]="@libp2p/dcutr";[to]=["@libp2p/identify"];isStarted(){return this.started}async start(){this.started||(this.topologyId=await this.registrar.register(je,{notifyOnLimitedConnection:!0,onConnect:(e,t)=>{ut.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(je,this.handleIncomingUpgrade,{maxInboundStreams:this.maxInboundStreams,maxOutboundStreams:this.maxOutboundStreams,runOnLimitedConnection:!0}),this.started=!0)}async stop(){await this.registrar.unhandle(je),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([je],{signal:o.signal,runOnLimitedConnection:!0});let s=Kn(t,{maxDataLength:qs}).pb(j);this.log("B sending connect to %p",e.remotePeer);let i=Date.now();await s.write({type:j.Type.CONNECT,observedAddresses:this.addressManager.getAddresses().map(f=>f.bytes)},o),this.log("B receiving connect from %p",e.remotePeer);let a=await s.read(o);if(a.type!==j.Type.CONNECT)throw this.log("A sent wrong message type"),new Q("DCUtR message type was incorrect");let c=this.getDialableMultiaddrs(a.observedAddresses);if(c.length===0)throw this.log("A did not have any dialable multiaddrs"),new Q("DCUtR connect message had no multiaddrs");let h=Date.now()-i;this.log("A sending sync, rtt %dms",h),await s.write({type:j.Type.SYNC,observedAddresses:[]},o),this.log("A waiting for half RTT"),await Gs(h/2),this.log("B dialing",c);let u=await this.connectionManager.openConnection(c,{signal:o.signal,priority:Xs,force:!0,initiator:!1});this.log("DCUtR to %p succeeded to address %a, closing relayed connection",e.remotePeer,u.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=>Zn(o,this.transportManager));if(n.length>0){let o=AbortSignal.timeout(this.timeout);try{this.log("attempting unilateral connection upgrade to %a",n);let s=await this.connectionManager.openConnection(n,{signal:o,force:!0});if(ut.exactMatch(s.remoteAddr))throw new Error("Could not open a new, non-limited, connection");return this.log("unilateral connection upgrade to %p succeeded via %a, closing relayed connection",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=Kn(e,{maxDataLength:qs}).pb(j);this.log("A receiving connect");let s=await o.read(n);if(s.type!==j.Type.CONNECT)throw this.log("B sent wrong message type"),new Q("DCUtR message type was incorrect");if(s.observedAddresses.length===0)throw this.log("B sent no multiaddrs"),new Q("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(h=>kn(h))),new Q("DCUtR connect message had no dialable multiaddrs");if(this.log("A sending connect"),await o.write({type:j.Type.CONNECT,observedAddresses:this.addressManager.getAddresses().map(h=>h.bytes)}),this.log("A receiving sync"),(await o.read(n)).type!==j.Type.SYNC)throw new Q("DCUtR message type was incorrect");this.log("A dialing",i);let c=await this.connectionManager.openConnection(i,{signal:n.signal,priority:Xs,force:!0});this.log("DCUtR to %p succeeded via %a, closing relayed connection",t.remotePeer,c.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=kn(n);if(!Zn(o,this.transportManager))continue;t.push(o)}catch{}return t}};var je="/libp2p/dcutr";function Xu(r={}){return e=>new kt(e,r)}return ei(Hu);})();
2
+ "use strict";var Libp2PDcutr=(()=>{var Ao=Object.create;var He=Object.defineProperty;var Do=Object.getOwnPropertyDescriptor;var To=Object.getOwnPropertyNames;var Lo=Object.getPrototypeOf,No=Object.prototype.hasOwnProperty;var It=(r,e)=>()=>{try{return e||r((e={exports:{}}).exports,e),e.exports}catch(t){throw e=0,t}},_=(r,e)=>{for(var t in e)He(r,t,{get:e[t],enumerable:!0})},nn=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of To(e))!No.call(r,o)&&o!==t&&He(r,o,{get:()=>e[o],enumerable:!(n=Do(e,o))||n.enumerable});return r};var _o=(r,e,t)=>(t=r!=null?Ao(Lo(r)):{},nn(e||!r||!r.__esModule?He(t,"default",{value:r,enumerable:!0}):t,r)),Po=r=>nn(He({},"__esModule",{value:!0}),r);var Xt=It(Ie=>{"use strict";Object.defineProperty(Ie,"__esModule",{value:!0});Ie.Netmask4Impl=void 0;Ie.ip2long=Ee;Ie.long2ip=W;function W(r){let e=(r&-16777216)>>>24,t=(r&255<<16)>>>16,n=(r&65280)>>>8,o=r&255;return[e,t,n,o].join(".")}var qs=48,Xs=97,Hs=65;function Ys(r){let e=0,t=10,n="9",o=0;r.length>1&&r[o]==="0"&&(r[o+1]==="x"||r[o+1]==="X"?(o+=2,t=16):"0"<=r[o+1]&&r[o+1]<="9"&&(o++,t=8,n="7"));let s=o;for(;o<r.length;){if("0"<=r[o]&&r[o]<=n)e=e*t+(r.charCodeAt(o)-qs)>>>0;else if(t===16)if("a"<=r[o]&&r[o]<="f")e=e*t+(10+r.charCodeAt(o)-Xs)>>>0;else if("A"<=r[o]&&r[o]<="F")e=e*t+(10+r.charCodeAt(o)-Hs)>>>0;else break;else break;if(e>4294967295)throw new Error("too large");o++}if(o===s)throw new Error("empty octet");return[e,o]}function Ee(r){let e=[];for(let t=0;t<=3&&r.length!==0;t++){if(t>0){if(r[0]!==".")throw new Error("Invalid IP");r=r.substring(1)}let[n,o]=Ys(r);r=r.substring(o),e.push(n)}if(r.length!==0)throw new Error("Invalid IP");switch(e.length){case 1:if(e[0]>4294967295)throw new Error("Invalid IP");return e[0]>>>0;case 2:if(e[0]>255||e[1]>16777215)throw new Error("Invalid IP");return(e[0]<<24|e[1])>>>0;case 3:if(e[0]>255||e[1]>255||e[2]>65535)throw new Error("Invalid IP");return(e[0]<<24|e[1]<<16|e[2])>>>0;case 4:if(e[0]>255||e[1]>255||e[2]>255||e[3]>255)throw new Error("Invalid IP");return(e[0]<<24|e[1]<<16|e[2]<<8|e[3])>>>0;default:throw new Error("Invalid IP")}}var qt=class r{constructor(e,t){if(typeof e!="string")throw new Error("Missing `net' parameter");let n=t;if(!n){let o=e.split("/",2);e=o[0],n=o[1]}if(n||(n=32),typeof n=="string"&&n.indexOf(".")>-1){try{this.maskLong=Ee(n)}catch{throw new Error("Invalid mask: "+n)}this.bitmask=NaN;for(let o=32;o>=0;o--)if(this.maskLong===4294967295<<32-o>>>0){this.bitmask=o;break}}else if(n||n===0)this.bitmask=parseInt(n,10),this.maskLong=0,this.bitmask>0&&(this.maskLong=4294967295<<32-this.bitmask>>>0);else throw new Error("Invalid mask: empty");try{this.netLong=(Ee(e)&this.maskLong)>>>0}catch{throw new Error("Invalid net address: "+e)}if(!(this.bitmask<=32))throw new Error("Invalid mask for ip4: "+n);this.size=Math.pow(2,32-this.bitmask),this.base=W(this.netLong),this.mask=W(this.maskLong),this.hostmask=W(~this.maskLong),this.first=this.bitmask<=30?W(this.netLong+1):this.base,this.last=this.bitmask<=30?W(this.netLong+this.size-2):W(this.netLong+this.size-1),this.broadcast=this.bitmask<=30?W(this.netLong+this.size-1):void 0}contains(e){return typeof e=="string"&&(e.indexOf("/")>0||e.split(".").length!==4)&&(e=new r(e)),e instanceof r?this.contains(e.base)&&this.contains(e.broadcast||e.last):(Ee(e)&this.maskLong)>>>0===(this.netLong&this.maskLong)>>>0}next(e=1){return new r(W(this.netLong+this.size*e),this.mask)}forEach(e){let t=Ee(this.first),n=Ee(this.last),o=0;for(;t<=n;)e(W(t),t,o),o++,t++}toString(){return this.base+"/"+this.bitmask}};Ie.Netmask4Impl=qt});var Un=It(ve=>{"use strict";Object.defineProperty(ve,"__esModule",{value:!0});ve.Netmask6Impl=void 0;ve.ip6bigint=Yt;ve.bigint2ip6=ae;var Qs=Xt(),Ht=(1n<<128n)-1n;function Yt(r){let e=r.indexOf("%");e!==-1&&(r=r.substring(0,e));let t=r.lastIndexOf(":");if(t!==-1&&r.indexOf(".",t)!==-1){let n=r.substring(t+1),o=(0,Qs.ip2long)(n),s=r.substring(0,t+1)+"0:0";return On(s)&~0xffffffffn|BigInt(o)}return On(r)}function On(r){let e=r.indexOf("::"),t;if(e!==-1){let o=r.substring(0,e),s=r.substring(e+2),i=o===""?[]:o.split(":"),a=s===""?[]:s.split(":"),c=8-i.length-a.length;if(c<0)throw new Error("Invalid IPv6: too many groups");t=[...i,...Array(c).fill("0"),...a]}else t=r.split(":");if(t.length!==8)throw new Error("Invalid IPv6: expected 8 groups, got "+t.length);let n=0n;for(let o=0;o<8;o++){let s=t[o];if(s.length===0||s.length>4)throw new Error('Invalid IPv6: bad group "'+s+'"');let i=parseInt(s,16);if(isNaN(i)||i<0||i>65535)throw new Error('Invalid IPv6: bad group "'+s+'"');n=n<<16n|BigInt(i)}return n}function ae(r){if(r<0n||r>Ht)throw new Error("Invalid IPv6 address value");let e=[];for(let i=0;i<8;i++)e.unshift(Number(r&0xffffn)),r>>=16n;let t=-1,n=0,o=-1,s=0;for(let i=0;i<8;i++)e[i]===0?o===-1?(o=i,s=1):s++:(s>n&&s>=2&&(t=o,n=s),o=-1,s=0);if(s>n&&s>=2&&(t=o,n=s),t!==-1&&t+n===8&&t>0)return e.slice(0,t).map(a=>a.toString(16)).join(":")+"::";if(t===0)return"::"+e.slice(n).map(a=>a.toString(16)).join(":");if(t>0){let i=e.slice(0,t).map(c=>c.toString(16)),a=e.slice(t+n).map(c=>c.toString(16));return i.join(":")+"::"+a.join(":")}else return e.map(i=>i.toString(16)).join(":")}var Qt=class r{constructor(e,t){if(typeof e!="string")throw new Error("Missing `net' parameter");let n=t;if(n==null){let o=e.indexOf("/");o!==-1?(n=parseInt(e.substring(o+1),10),e=e.substring(0,o)):n=128}if(isNaN(n)||n<0||n>128)throw new Error("Invalid mask for IPv6: "+n);this.bitmask=n,this.bitmask===0?this.maskBigint=0n:this.maskBigint=Ht>>BigInt(128-this.bitmask)<<BigInt(128-this.bitmask);try{this.netBigint=Yt(e)&this.maskBigint}catch{throw new Error("Invalid IPv6 net address: "+e)}this.size=Number(1n<<BigInt(128-this.bitmask)),this.base=ae(this.netBigint),this.mask=ae(this.maskBigint),this.hostmask=ae(~this.maskBigint&Ht),this.first=this.base,this.last=ae(this.netBigint+(1n<<BigInt(128-this.bitmask))-1n),this.broadcast=void 0}contains(e){return typeof e=="string"&&e.indexOf("/")>0&&(e=new r(e)),e instanceof r?this.contains(e.base)&&this.contains(e.last):(Yt(e)&this.maskBigint)===this.netBigint}next(e=1){let t=1n<<BigInt(128-this.bitmask);return new r(ae(this.netBigint+t*BigInt(e)),this.bitmask)}forEach(e){let t=this.netBigint,n=1n<<BigInt(128-this.bitmask),o=this.netBigint+n-1n,s=0;for(;t<=o;)e(ae(t),Number(t),s),s++,t++}toString(){return this.base+"/"+this.bitmask}};ve.Netmask6Impl=Qt});var Bn=It(te=>{"use strict";Object.defineProperty(te,"__esModule",{value:!0});te.long2ip=te.ip2long=te.Netmask=void 0;var tt=Xt();Object.defineProperty(te,"ip2long",{enumerable:!0,get:function(){return tt.ip2long}});Object.defineProperty(te,"long2ip",{enumerable:!0,get:function(){return tt.long2ip}});var Js=Un(),Jt=class r{constructor(e,t){if(typeof e!="string")throw new Error("Missing `net' parameter");(e.indexOf("/")!==-1?e.substring(0,e.indexOf("/")):e).indexOf(":")!==-1?this._impl=new Js.Netmask6Impl(e,t):this._impl=new tt.Netmask4Impl(e,t),this.base=this._impl.base,this.mask=this._impl.mask,this.hostmask=this._impl.hostmask,this.bitmask=this._impl.bitmask,this.size=this._impl.size,this.first=this._impl.first,this.last=this._impl.last,this.broadcast=this._impl.broadcast,this._impl instanceof tt.Netmask4Impl?(this.maskLong=this._impl.maskLong,this.netLong=this._impl.netLong):(this.maskLong=0,this.netLong=0)}contains(e){return typeof e=="string"&&(e.indexOf("/")>0?e=new r(e):e.indexOf(":")===-1&&e.split(".").length!==4&&(e=new r(e))),e instanceof r?this.contains(e.base)&&this.contains(e.broadcast||e.last):this._impl.contains(e)}next(e=1){let t=this._impl.next(e);return new r(t.base,t.bitmask)}forEach(e){this._impl.forEach(e)}toString(){return this._impl.toString()}};te.Netmask=Jt});var la={};_(la,{dcutr:()=>ua,multicodec:()=>Ne});var de=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}};var G=class extends Error{static name="InvalidMessageError";constructor(e="Invalid message"){super(e),this.name="InvalidMessageError"}};var on=Symbol.for("@libp2p/service-dependencies");function V(r=0){return new Uint8Array(r)}function A(r=0){return new Uint8Array(r)}function Oo(r){return r?.buffer instanceof ArrayBuffer}function vt(r){if(Oo(r))return r;let e=r.slice();return new Uint8Array(e.buffer,0,e.byteLength)}function q(r,e){e==null&&(e=r.reduce((o,s)=>o+s.length,0));let t=A(e),n=0;for(let o of r)t.set(o,n),n+=o.length;return vt(t)}function _e(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}var an=Symbol.for("@achingbrain/uint8arraylist");function sn(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 Ye(r){return!!r?.[an]}var se=class r{bufs;length;[an]=!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(Ye(n)){t+=n.byteLength;for(let o of n.bufs)this.bufs.push(o)}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(Ye(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=sn(this.bufs,e);return t.buf[t.index]}set(e,t){let n=sn(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(Ye(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 q(n,o)}subarray(e,t){let{bufs:n,length:o}=this._subList(e,t);return n.length===1?n[0]:q(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,c=a+i.byteLength;if(o=c,e>=c)continue;let l=e>=a&&e<c,u=t>a&&t<=c;if(l&&u){if(e===a&&t===c){n.push(i);break}let f=e-a;n.push(i.subarray(f,f+(t-e)));break}if(l){if(e===0){n.push(i);continue}n.push(i.subarray(e-a));continue}if(u){if(t===c){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(!Ye(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 f=0;f<s;f++)i[f]=-1;for(let f=0;f<o;f++)i[n[f]]=f;let a=i,c=this.byteLength-n.byteLength,l=n.byteLength-1,u;for(let f=t;f<=c;f+=u){u=0;for(let d=l;d>=0;d--){let g=this.get(f+d);if(n[d]!==g){u=Math.max(1,d-a[g]);break}}if(u===0)return f}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=A(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=V(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=V(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=V(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=A(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=V(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=V(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=V(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=V(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=V(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(!_e(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 Tt={};_(Tt,{base10:()=>Vo});var Ha=new Uint8Array(0);function cn(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 X(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return ie(r);if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return ie(new Uint8Array(r.buffer,r.byteOffset,r.byteLength));throw new Error("Unknown type, must be binary type")}function un(r){return new TextEncoder().encode(r)}function ln(r){return new TextDecoder().decode(r)}function Uo(r){return r?.buffer instanceof ArrayBuffer}function ie(r){return Uo(r)?r:r.slice()}function Bo(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,c=r.charAt(0),l=Math.log(a)/Math.log(256),u=Math.log(256)/Math.log(a);function f(b){if(b instanceof Uint8Array||(ArrayBuffer.isView(b)?b=new Uint8Array(b.buffer,b.byteOffset,b.byteLength):Array.isArray(b)&&(b=Uint8Array.from(b))),!(b instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(b.length===0)return"";for(var S=0,oe=0,U=0,R=b.length;U!==R&&b[U]===0;)U++,S++;for(var k=(R-U)*u+1>>>0,O=new Uint8Array(k);U!==R;){for(var z=b[U],J=0,B=k-1;(z!==0||J<oe)&&B!==-1;B--,J++)z+=256*O[B]>>>0,O[B]=z%a>>>0,z=z/a>>>0;if(z!==0)throw new Error("Non-zero carry");oe=J,U++}for(var j=k-oe;j!==k&&O[j]===0;)j++;for(var Xe=c.repeat(S);j<k;++j)Xe+=r.charAt(O[j]);return Xe}function d(b){if(typeof b!="string")throw new TypeError("Expected String");if(b.length===0)return new Uint8Array;var S=0;if(b[S]!==" "){for(var oe=0,U=0;b[S]===c;)oe++,S++;for(var R=(b.length-S)*l+1>>>0,k=new Uint8Array(R);b[S];){var O=t[b.charCodeAt(S)];if(O===255)return;for(var z=0,J=R-1;(O!==0||z<U)&&J!==-1;J--,z++)O+=a*k[J]>>>0,k[J]=O%256>>>0,O=O/256>>>0;if(O!==0)throw new Error("Non-zero carry");U=z,S++}if(b[S]!==" "){for(var B=R-U;B!==R&&k[B]===0;)B++;for(var j=new Uint8Array(oe+(R-B)),Xe=oe;B!==R;)j[Xe++]=k[B++];return j}}}function g(b){var S=d(b);if(S)return S;throw new Error(`Non-${e} character`)}return{encode:f,decodeUnsafe:d,decode:g}}var Fo=Bo,Mo=Fo,hn=Mo;var Ct=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")}},St=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 dn(this,e)}},At=class{decoders;constructor(e){this.decoders=e}or(e){return dn(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 dn(r,e){return new At({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var Dt=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 Ct(e,t,n),this.decoder=new St(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function pe({name:r,prefix:e,encode:t,decode:n}){return new Dt(r,e,t,n)}function K({name:r,prefix:e,alphabet:t}){let{encode:n,decode:o}=hn(t,r);return pe({prefix:e,name:r,encode:n,decode:s=>X(o(s))})}function Ro(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,c=0;for(let l=0;l<o;++l){let u=e[r[l]];if(u===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<t|u,i+=t,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=t||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function ko(r,e,t){let n=e[e.length-1]==="=",o=(1<<t)-1,s="",i=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],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 zo(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=zo(n);return pe({prefix:e,name:r,encode(s){return ko(s,n,t)},decode(s){return Ro(s,o,t,r)}})}var Vo=K({prefix:"9",name:"base10",alphabet:"0123456789"});var Lt={};_(Lt,{base16:()=>$o,base16upper:()=>Wo});var $o=I({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Wo=I({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Nt={};_(Nt,{base2:()=>jo});var jo=I({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var _t={};_(_t,{base256emoji:()=>Yo});var pn=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}"),Go=pn.reduce((r,e,t)=>(r[t]=e,r),[]),qo=pn.reduce((r,e,t)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return r[n]=t,r},[]);function Xo(r){return r.reduce((e,t)=>(e+=Go[t],e),"")}function Ho(r){let e=[];for(let t of r){let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);let o=qo[n];if(o==null)throw new Error(`Non-base256emoji character: ${t}`);e.push(o)}return new Uint8Array(e)}var Yo=pe({prefix:"\u{1F680}",name:"base256emoji",encode:Xo,decode:Ho});var Pt={};_(Pt,{base32:()=>Z,base32hex:()=>Zo,base32hexpad:()=>ts,base32hexpadupper:()=>rs,base32hexupper:()=>es,base32pad:()=>Jo,base32padupper:()=>Ko,base32upper:()=>Qo,base32z:()=>ns});var Z=I({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Qo=I({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Jo=I({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Ko=I({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Zo=I({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),es=I({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),ts=I({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),rs=I({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),ns=I({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Ot={};_(Ot,{base36:()=>Pe,base36upper:()=>os});var Pe=K({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),os=K({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Ut={};_(Ut,{base58btc:()=>$,base58flickr:()=>ss});var $=K({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),ss=K({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Ft={};_(Ft,{base64:()=>is,base64pad:()=>as,base64url:()=>Bt,base64urlpad:()=>cs});var is=I({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),as=I({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Bt=I({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),cs=I({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Mt={};_(Mt,{base8:()=>us});var us=I({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Rt={};_(Rt,{identity:()=>ls});var ls=pe({prefix:"\0",name:"identity",encode:r=>ln(r),decode:r=>un(r)});var lc=new TextEncoder,fc=new TextDecoder;var zt={};_(zt,{identity:()=>Os});var ds=bn,mn=128,ps=127,ms=~ps,gs=Math.pow(2,31);function bn(r,e,t){e=e||[],t=t||0;for(var n=t;r>=gs;)e[t++]=r&255|mn,r/=128;for(;r&ms;)e[t++]=r&255|mn,r>>>=7;return e[t]=r|0,bn.bytes=t-n+1,e}var bs=kt,xs=128,gn=127;function kt(r,n){var t=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw kt.bytes=0,new RangeError("Could not decode varint");i=r[s++],t+=o<28?(i&gn)<<o:(i&gn)*Math.pow(2,o),o+=7}while(i>=xs);return kt.bytes=s-n,t}var ws=Math.pow(2,7),ys=Math.pow(2,14),Es=Math.pow(2,21),Is=Math.pow(2,28),vs=Math.pow(2,35),Cs=Math.pow(2,42),Ss=Math.pow(2,49),As=Math.pow(2,56),Ds=Math.pow(2,63),Ts=function(r){return r<ws?1:r<ys?2:r<Es?3:r<Is?4:r<vs?5:r<Cs?6:r<Ss?7:r<As?8:r<Ds?9:10},Ls={encode:ds,decode:bs,encodingLength:Ts},Ns=Ls,Oe=Ns;function Ue(r,e=0){return[Oe.decode(r,e),Oe.decode.bytes]}function me(r,e,t=0){return Oe.encode(r,e,t),e}function ge(r){return Oe.encodingLength(r)}function xe(r,e){let t=e.byteLength,n=ge(r),o=n+ge(t),s=new Uint8Array(o+t);return me(r,s,0),me(t,s,n),s.set(e,o),new be(r,t,e,s)}function xn(r){let e=X(r),[t,n]=Ue(e),[o,s]=Ue(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new be(t,o,i,e)}function wn(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&cn(r.bytes,t.bytes)}}var be=class{code;size;digest;bytes;constructor(e,t,n,o){this.code=e,this.size=t,this.digest=ie(n),this.bytes=ie(o)}};var yn=0,_s="identity",En=X;function Ps(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 xe(yn,En(r))}var Os={code:yn,name:_s,encode:En,digest:Ps};var Wt={};_(Wt,{sha256:()=>Bs,sha512:()=>Fs});var Us=20;function $t({name:r,code:e,encode:t,minDigestLength:n,maxDigestLength:o}){return new Vt(r,e,t,n,o)}var Vt=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,t,n,o,s){this.name=e,this.code=t,this.encode=n,this.minDigestLength=o??Us,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?In(n,this.code,t?.truncate):n.then(o=>In(o,this.code,t?.truncate))}else throw Error("Unknown type, must be binary type")}};function In(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 xe(e,r)}function Cn(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var Bs=$t({name:"sha2-256",code:18,encode:Cn("SHA-256")}),Fs=$t({name:"sha2-512",code:19,encode:Cn("SHA-512")});function Sn(r,e){let{bytes:t,version:n}=r;return n===0?Rs(t,jt(r),e??$.encoder):ks(t,jt(r),e??Z.encoder)}var An=new WeakMap;function jt(r){let e=An.get(r);if(e==null){let t=new Map;return An.set(r,t),t}return e}var we=class r{code;version;multihash;bytes;"/";constructor(e,t,n,o){this.code=t,this.version=e,this.multihash=n,this.bytes=ie(o),this["/"]=this.bytes}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!==Fe)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==zs)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=xe(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&&wn(e.multihash,n.multihash)}toString(e){return Sn(this,e)}toJSON(){return{"/":Sn(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??Dn(n,o,s.bytes))}else if(t[Vs]===!0){let{version:n,multihash:o,code:s}=t,i=xn(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!==Fe)throw new Error(`Version 0 CID must use dag-pb (code: ${Fe}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let o=Dn(e,t,n.bytes);return new r(e,t,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,Fe,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=X(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 be(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[f,d]=Ue(e.subarray(t));return t+=d,f},o=n(),s=Fe;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(),c=n(),l=t+c,u=l-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:u,size:l}}static parse(e,t){let[n,o]=Ms(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 jt(s).set(n,e),s}};function Ms(r,e){switch(r[0]){case"Q":{let t=e??$;return[$.prefix,t.decode(`${$.prefix}${r}`)]}case $.prefix:{let t=e??$;return[$.prefix,t.decode(r)]}case Z.prefix:{let t=e??Z;return[Z.prefix,t.decode(r)]}case Pe.prefix:{let t=e??Pe;return[Pe.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 Rs(r,e,t){let{prefix:n}=t;if(n!==$.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 ks(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 Fe=112,zs=18;function Dn(r,e,t){let n=ge(r),o=n+ge(e),s=new Uint8Array(o+t.byteLength);return me(r,s,0),me(e,s,n),s.set(t,o),s}var Vs=Symbol.for("@ipld/js-cid/CID");var Me={...Rt,...Nt,...Mt,...Tt,...Lt,...Pt,...Ot,...Ut,...Ft,..._t},Oc={...Wt,...zt};function Ln(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var Tn=Ln("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Gt=Ln("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=A(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),$s={utf8:Tn,"utf-8":Tn,hex:Me.base16,latin1:Gt,ascii:Gt,binary:Gt,...Me},Je=$s;function ee(r,e="utf8"){let t=Je[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.decoder.decode(`${t.prefix}${r}`)}function Ws(r){let e=r.getComponents(),t={},n=0;return 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?null:(e[n]?.name==="tls"&&e[n+1]?.name==="sni"&&(t.sni=e[n+1].value,n+=2),t)}function Nn(r){let e=Ws(r);if(e==null)throw new de(`Multiaddr ${r} was not an IPv4, IPv6, DNS, DNS4, DNS6 or DNSADDR address`);return e}var Ke=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 c=a==="0",l=2**(8*o)-1;for(;;){let u=this.readAtomically(()=>{let f=this.readChar();if(f===void 0)return;let d=Number.parseInt(f,e);if(!Number.isNaN(d))return d});if(u===void 0)break;if(s*=e,s+=u,s>l||(i+=1,t!==void 0&&i>t))return}if(i!==0)return!n&&c&&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 js=45,Gs=15,Ze=new Ke;function _n(r){if(!(r.length>Gs))return Ze.new(r).parseWith(()=>Ze.readIPv4Addr())}function Pn(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>js))return Ze.new(r).parseWith(()=>Ze.readIPv6Addr())}function ye(r){return!!_n(r)}function et(r){return!!Pn(r)}var Fn=_o(Bn(),1),Ks=["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=Ks.map(r=>new Fn.Netmask(r));function Kt(r){for(let e of Zs)if(e.contains(r))return!0;return!1}function ei(r){return/^::ffff:([0-9a-fA-F]{1,4}):([0-9a-fA-F]{1,4})$/.test(r)}function ti(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 Kt(o)}function ri(r){return/^::ffff:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(r)}function ni(r){let e=r.split(":"),t=e[e.length-1];return Kt(t)}function oi(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 Mn(r){if(ye(r))return Kt(r);if(ei(r))return ti(r);if(ri(r))return ni(r);if(et(r))return oi(r)}function Rn(r){try{let e=Nn(r);switch(e.type){case"ip4":case"ip6":return Mn(e.host)??!1;default:return e.host==="localhost"}}catch{return!1}}var si=Math.pow(2,7),ii=Math.pow(2,14),ai=Math.pow(2,21),Zt=Math.pow(2,28),er=Math.pow(2,35),tr=Math.pow(2,42),rr=Math.pow(2,49),x=128,D=127;function N(r){if(r<si)return 1;if(r<ii)return 2;if(r<ai)return 3;if(r<Zt)return 4;if(r<er)return 5;if(r<tr)return 6;if(r<rr)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Ce(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 ci(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 nr(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)*Zt,t<x)||(t=r[e+5],n+=(t&D)*er,t<x)||(t=r[e+6],n+=(t&D)*tr,t<x)||(t=r[e+7],n+=(t&D)*rr,t<x))return n;throw new RangeError("Could not decode varint")}function ui(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)*Zt,t<x)||(t=r.get(e+5),n+=(t&D)*er,t<x)||(t=r.get(e+6),n+=(t&D)*tr,t<x)||(t=r.get(e+7),n+=(t&D)*rr,t<x))return n;throw new RangeError("Could not decode varint")}function kn(r,e,t=0){return e==null&&(e=A(N(r))),e instanceof Uint8Array?Ce(r,e,t):ci(r,e,t)}function Re(r,e=0){return r instanceof Uint8Array?nr(r,e):ui(r,e)}function li(r){return r.buffer instanceof ArrayBuffer}function ke(r){return li(r)?r:r.slice()}function re(r,e="utf8"){let t=Je[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.encoder.encode(r).substring(1)}var C=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},H=class extends Error{static name="ValidationError";name="ValidationError"},rt=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},nt=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};function sr(r){return e=>re(e,r)}function ir(r){return e=>ee(e,r)}function Se(r){return new DataView(r.buffer).getUint16(r.byteOffset).toString()}function ce(r){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,typeof r=="string"?parseInt(r):r),new Uint8Array(e)}function Vn(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=ee(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=ce(n);return q([t,o],t.length+o.length)}function $n(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=Z.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=ce(n);return q([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=Se(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 C("Invalid byte value in IP address");e[n]=o}),e},Wn=function(r){let e=0;r=r.toString().trim();let t=r.split(":",8),n;for(n=0;n<t.length;n++){let s=ye(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 C("Invalid byte value in IP address");o[e++]=s>>8&255,o[e++]=s&255}return o},jn=function(r){if(r.byteLength!==4)throw new C("IPv4 address was incorrect length");let e=[];for(let t=0;t<r.byteLength;t++)e.push(r[t]);return e.join(".")},Gn=function(r){if(r.byteLength!==16)throw new C("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 C(`Invalid IPv6 address "${t}"`)}};function qn(r){try{let e=new URL(`http://[${r}]`);return e.hostname.substring(1,e.hostname.length-1)}catch{throw new C(`Invalid IPv6 address "${r}"`)}}var or=Object.values(Me).map(r=>r.decoder),fi=(function(){let r=or[0].or(or[1]);return or.slice(2).forEach(e=>r=r.or(e)),r})();function Xn(r){return fi.decode(r)}function Hn(r){return e=>r.encoder.encode(e)}function hi(r){if(parseInt(r).toString()!==r)throw new H("Value must be an integer")}function di(r){if(r<0)throw new H("Value must be a positive integer, or zero")}function pi(r){return e=>{if(e>r)throw new H(`Value must be smaller than or equal to ${r}`)}}function mi(...r){return e=>{for(let t of r)t(e)}}var ze=mi(hi,di,pi(65535));var v=-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 nt(`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)}))}},Q=new ur,Li=[{code:4,name:"ip4",size:32,valueToBytes:cr,bytesToValue:jn,validate:r=>{if(!ye(r))throw new H(`Invalid IPv4 address "${r}"`)}},{code:6,name:"tcp",size:16,valueToBytes:ce,bytesToValue:Se,validate:ze},{code:273,name:"udp",size:16,valueToBytes:ce,bytesToValue:Se,validate:ze},{code:33,name:"dccp",size:16,valueToBytes:ce,bytesToValue:Se,validate:ze},{code:41,name:"ip6",size:128,valueToBytes:Wn,bytesToValue:Gn,stringToValue:qn,validate:r=>{if(!et(r))throw new H(`Invalid IPv6 address "${r}"`)}},{code:42,name:"ip6zone",size:v},{code:43,name:"ipcidr",size:8,bytesToValue:sr("base10"),valueToBytes:ir("base10")},{code:53,name:"dns",size:v},{code:54,name:"dns4",size:v},{code:55,name:"dns6",size:v},{code:56,name:"dnsaddr",size:v},{code:132,name:"sctp",size:16,valueToBytes:ce,bytesToValue:Se,validate:ze},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:v,stringToValue:r=>decodeURIComponent(r),valueToString:r=>encodeURIComponent(r)},{code:421,name:"p2p",aliases:["ipfs"],size:v,bytesToValue:sr("base58btc"),valueToBytes:r=>r.startsWith("Q")||r.startsWith("1")?ir("base58btc")(r):we.parse(r).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:ar,valueToBytes:Vn},{code:445,name:"onion3",size:296,bytesToValue:ar,valueToBytes:$n},{code:446,name:"garlic64",size:v},{code:447,name:"garlic32",size:v},{code:448,name:"tls"},{code:449,name:"sni",size:v},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:v,bytesToValue:Hn(Bt),valueToBytes:Xn},{code:480,name:"http"},{code:481,name:"http-path",size:v,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:v}];Li.forEach(r=>{Q.addProtocol(r)});function Yn(r){let e=[],t=0;for(;t<r.length;){let n=Re(r,t),o=Q.getProtocol(n),s=N(n),i=Ni(o,r,t+s),a=0;i>0&&o.size===v&&(a=N(i));let c=s+a+i,l={code:n,name:o.name,bytes:ke(r.subarray(t,t+c))};if(i>0){let u=t+s+a,f=r.subarray(u,u+i);l.value=o.bytesToValue?.(f)??re(f)}e.push(l),t+=c}return e}function Qn(r){let e=0,t=[];for(let n of r){if(n.bytes==null){let o=Q.getProtocol(n.code),s=N(n.code),i,a=0,c=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??ee(n.value),a=i.byteLength,o.size===v&&(c=N(a)));let l=new Uint8Array(s+c+a),u=0;Ce(n.code,l,u),u+=s,i!=null&&(o.size===v&&(Ce(a,l,u),u+=c),l.set(i,u)),n.bytes=l}t.push(n.bytes),e+=n.bytes.byteLength}return q(t,e)}function Jn(r){if(r.charAt(0)!=="/")throw new C('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 c=Q.getProtocol(o);if(t==="protocol"){if(c.size==null||c.size===0){e.push({code:c.code,name:c.name}),n="",o="",t="protocol";continue}else if(a)throw new C(`Component ${o} was missing value`);t="value"}else if(t==="value"){let l={code:c.code,name:c.name};if(c.size!=null&&c.size!==0){if(n==="")throw new C(`Component ${o} was missing value`);l.value=c.stringToValue?.(n)??n}e.push(l),n="",o="",t="protocol"}}}if(o!==""&&n!=="")throw new C("Incomplete multiaddr");return e}function Kn(r){return`/${r.flatMap(e=>{if(e.value==null)return e.name;let t=Q.getProtocol(e.code);if(t==null)throw new C(`Unknown protocol code ${e.code}`);return[e.name,t.valueToString?.(e.value)??e.value]}).join("/")}`}function Ni(r,e,t){return r.size==null||r.size===0?0:r.size>0?r.size/8:Re(e,t)}var _i=Symbol.for("nodejs.util.inspect.custom"),Ar=Symbol.for("@multiformats/multiaddr");function Pi(r){if(r==null&&(r="/"),Zn(r))return r.getComponents();if(r instanceof Uint8Array)return Yn(r);if(typeof r=="string")return r=r.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),r===""&&(r="/"),Jn(r);if(Array.isArray(r))return r;throw new C("Must be a string, Uint8Array, Component[], or another Multiaddr")}var ut=class r{[Ar]=!0;#e;#t;#r;constructor(e="/",t={}){this.#e=Pi(e),t.validate!==!1&&Oi(this)}get bytes(){return this.#r==null&&(this.#r=Qn(this.#e)),this.#r}toString(){return this.#t==null&&(this.#t=Kn(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 rt(`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 _e(this.bytes,e.bytes)}[_i](){return`Multiaddr(${this.toString()})`}};function Oi(r){r.getComponents().forEach(e=>{let t=Q.getProtocol(e.code);e.value!=null&&t.validate?.(e.value)})}function Zn(r){return!!r?.[Ar]}function Dr(r){return new ut(r)}var y=r=>({match:e=>{let t=e[0];return t==null||t.code!==r||t.value!=null?!1:e.slice(1)}}),h=(r,e)=>({match:t=>{let n=t[0];return n?.code!==r||n.value==null||e!=null&&n.value!==e?!1:t.slice(1)}}),eo=r=>({match:e=>r.match(e)===!1?e:!1}),p=r=>({match:e=>{let t=r.match(e);return t===!1?e:t}}),T=(...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}}),m=(...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 Ui=h(421),ll=E(Ui),ft=h(54),ht=h(55),dt=h(56),Lr=h(53),fl=E(ft,p(h(421))),hl=E(ht,p(h(421))),dl=E(dt,p(h(421))),to=E(T(Lr,dt,ft,ht),p(h(421))),ro=m(h(4),p(h(43))),no=m(p(h(42)),h(41),p(h(43))),Nr=T(ro,no),Le=T(Nr,Lr,ft,ht,dt),pl=E(T(Nr,m(T(Lr,dt,ft,ht),p(h(421))))),ml=E(ro),gl=E(no),oo=E(Nr),_r=m(Le,h(6)),Ve=m(Le,h(273)),bl=E(m(_r,p(h(421)))),xl=E(Ve),Pr=m(Ve,y(460),p(h(421))),pt=m(Ve,y(461),p(h(421))),Bi=T(Pr,pt),wl=E(Pr),yl=E(pt),Tr=T(Le,_r,Ve,Pr,pt),so=T(m(Tr,y(477),p(h(421)))),El=E(so),io=T(m(Tr,y(478),p(h(421))),m(Tr,y(448),p(h(449)),y(477),p(h(421)))),Il=E(io),ao=m(Ve,y(280),p(h(466)),p(h(466)),p(h(421))),vl=E(ao),co=m(pt,y(465),p(h(466)),p(h(466)),p(h(421))),Cl=E(co),lt=T(so,io,m(_r,p(h(421))),m(Bi,p(h(421))),m(Le,p(h(421))),ao,co,h(421)),Sl=E(lt),Fi=m(p(lt),y(290),eo(y(281)),p(h(421))),$e=E(Fi),Mi=T(m(lt,y(290),y(281),p(h(421))),m(lt,y(281),p(h(421))),m(y(281),p(h(421)))),Al=E(Mi),Ri=m(Le,T(m(h(6,"80")),m(h(6),y(480)),y(480)),p(h(481)),p(h(421))),Dl=E(Ri),ki=m(Le,T(m(h(6,"443")),m(h(6,"443"),y(480)),m(h(6),y(443)),m(h(6),y(448),y(480)),m(y(448),y(480)),y(448),y(443)),p(h(481)),p(h(421))),Tl=E(ki),zi=T(m(h(777),p(h(421)))),Ll=E(zi),Vi=T(m(h(400),p(h(421)))),Nl=E(Vi);var Or=class r extends Error{name="TimeoutError";constructor(e,t){super(e,t),Error.captureStackTrace?.(this,r)}},uo=r=>r.reason??new DOMException("This operation was aborted.","AbortError");function Ur(r,e){let{milliseconds:t,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout},signal:i}=e,a,c,u=new Promise((f,d)=>{if(typeof t!="number"||Math.sign(t)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${t}\``);if(i?.aborted){d(uo(i));return}if(i&&(c=()=>{d(uo(i))},i.addEventListener("abort",c,{once:!0})),r.then(f,d),t===Number.POSITIVE_INFINITY)return;let g=new Or;a=s.setTimeout.call(void 0,()=>{if(n){try{f(n())}catch(b){d(b)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?f():o instanceof Error?d(o):(g.message=o??`Promise timed out after ${t} milliseconds`,d(g))},t)}).finally(()=>{u.clear(),c&&i&&i.removeEventListener("abort",c)});return u.clear=()=>{s.clearTimeout.call(void 0,a),a=void 0},u}var $i=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 Wi(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(),c=[],{addListener:l,removeListener:u}=$i(r),f=async(...g)=>{let b=t.multiArgs?g:g[0];if(t.filter)try{if(!await t.filter(b))return}catch(S){n(),i(S);return}c.push(b),t.count===c.length&&(n(),s(c))},d=(...g)=>{n(),i(t.rejectionMultiArgs?g:g[0])};n=()=>{for(let g of a)u(g,f);for(let g of t.rejectionEvents)a.includes(g)||u(g,d)};for(let g of a)l(g,f);for(let g of t.rejectionEvents)a.includes(g)||l(g,d);t.signal&&t.signal.addEventListener("abort",()=>{d(t.signal.reason)},{once:!0}),t.resolveImmediately&&s(c)});if(o.cancel=n,typeof t.timeout=="number"){let s=Ur(o,{milliseconds:t.timeout});return s.cancel=()=>{n(),s.clear()},s}return o}function lo(r,e,t){typeof t=="function"&&(t={filter:t}),t={...t,count:1,resolveImmediately:!1};let n=Wi(r,e,t),o=n.then(s=>s[0]);return o.cancel=n.cancel,o}var le=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"};function ji(r){return r.reason}async function Br(r,e,t){if(e==null)return r;let n=t?.translateError??ji;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 qi=4194304,mt=class extends Error{static name="UnwrappedError";name="UnwrappedError"},Mr=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},Rr=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},kr=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function Xi(r){return typeof r?.closeRead=="function"}function Hi(r){return typeof r?.close=="function"}function Fr(r){return Xi(r)?r.remoteWriteStatus!=="writable"&&r.readBufferLength===0:Hi(r)?r.status!=="open":!1}function Yi(r){return r?.addEventListener!=null&&r?.removeEventListener!=null&&r?.send!=null&&r?.push!=null&&r?.log!=null}function Qi(r,e){let t=e?.maxBufferSize??qi,n=new se,o,s=!1;if(!Yi(r))throw new de("Argument should be a Stream or a Multiaddr");let i=u=>{if(n.append(u.data),n.byteLength>t){let f=n.byteLength;n.consume(n.byteLength),o?.reject(new Error(`Read buffer overflow - ${f} > ${t}`))}o?.resolve()};r.addEventListener("message",i);let a=u=>{u.error!=null?o?.reject(u.error):o?.resolve()};r.addEventListener("close",a);let c=()=>{o?.resolve()};r.addEventListener("remoteCloseWrite",c);let l={readBuffer:n,async read(u){if(s===!0)throw new mt("Stream was unwrapped");if(Fr(r)){if(n.byteLength===0&&u?.bytes==null)return null;if(u?.bytes!=null&&n.byteLength<u.bytes)throw r.log.error("closed after reading %d/%d bytes",n.byteLength,u.bytes),new le(`Unexpected EOF - stream closed after reading ${n.byteLength}/${u.bytes} bytes`)}let f=u?.bytes??1;for(o=Promise.withResolvers();;){if(n.byteLength>=f){o.resolve();break}if(await Br(o.promise,u?.signal),Fr(r)){if(n.byteLength===0&&u?.bytes==null)return null;break}o=Promise.withResolvers()}let d=u?.bytes??n.byteLength;if(n.byteLength<d){if(Fr(r))throw r.log.error("closed while reading %d/%d bytes",n.byteLength,d),new le(`Unexpected EOF - stream closed while reading ${n.byteLength}/${d} bytes`);return l.read(u)}let g=n.sublist(0,d);return n.consume(d),g},async write(u,f){if(s===!0)throw new mt("Stream was unwrapped");r.send(u)||await lo(r,"drain",{signal:f?.signal,rejectionEvents:["close"]})},unwrap(){return s||(s=!0,r.removeEventListener("message",i),r.removeEventListener("close",a),r.removeEventListener("remoteCloseWrite",c),n.byteLength>0&&(r.log("stream unwrapped with %d unread bytes",n.byteLength),r.unshift(n))),r}};return l}function Ji(r,e={}){let t=Qi(r,e);e.maxDataLength!=null&&e.maxLengthLength==null&&(e.maxLengthLength=N(e.maxDataLength));let n=e?.lengthDecoder??Re,o=e?.lengthEncoder??kn;return{async read(i){let a=-1,c=new se;for(;;){let u=await t.read({...i,bytes:1});if(u==null)break;c.append(u);try{a=n(c)}catch(f){if(f instanceof RangeError)continue;throw f}if(a<0)throw new Mr("Invalid message length");if(e?.maxLengthLength!=null&&c.byteLength>e.maxLengthLength)throw new kr(`Message length length too long - ${c.byteLength} > ${e.maxLengthLength}`);if(a>-1)break}if(e?.maxDataLength!=null&&a>e.maxDataLength)throw new Rr(`Message length too long - ${a} > ${e.maxDataLength}`);let l=await t.read({...i,bytes:a});if(l==null)throw r.log.error("tried to read %d bytes but the stream closed",a),new le(`Unexpected EOF - tried to read ${a} bytes but the stream closed`);if(l.byteLength!==a)throw r.log.error("read %d/%d bytes before the stream closed",l.byteLength,a),new le(`Unexpected EOF - read ${l.byteLength}/${a} bytes before the stream closed`);return l},async write(i,a){await t.write(new se(o(i.byteLength),i),a)},async writeV(i,a){let c=new se(...i.flatMap(l=>[o(l.byteLength),l]));await t.write(c,a)},unwrap(){return t.unwrap()}}}function zr(r,e){let t=Ji(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 fo=Symbol.for("sindresorhus/unlimited-timeout#brand");function ho(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={[fo]:!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 c=performance.now(),l=Math.max(0,s-c);i(l)},2147483647),n&&o.id?.unref?.()))};return i(e),o}function po(r){!r||typeof r!="object"||!r[fo]||(r.cleared=!0,r.id!==void 0&&(globalThis.clearTimeout(r.id),r.id=void 0))}var Ki=new WeakMap;function Zi({clearTimeout:r,setTimeout:e}={}){return(t,{value:n,signal:o}={})=>{if(o?.aborted)return Promise.reject(o.reason);let s,i,a,c=r??clearTimeout,l=()=>{c(s),a(o.reason)},u=()=>{o&&o.removeEventListener("abort",l)},f=new Promise((d,g)=>{i=()=>{u(),d(n)},a=g,s=(e??setTimeout)(i,t)});return o&&o.addEventListener("abort",l,{once:!0}),Ki.set(f,()=>{c(s),s=null,i()}),f}}var ea=Zi({setTimeout:ho,clearTimeout:po}),mo=ea;var Vr=new Float32Array([-0]),ne=new Uint8Array(Vr.buffer);function go(r,e,t){Vr[0]=r,e[t]=ne[0],e[t+1]=ne[1],e[t+2]=ne[2],e[t+3]=ne[3]}function bo(r,e){return ne[0]=r[e],ne[1]=r[e+1],ne[2]=r[e+2],ne[3]=r[e+3],Vr[0]}var $r=new Float64Array([-0]),L=new Uint8Array($r.buffer);function xo(r,e,t){$r[0]=r,e[t]=L[0],e[t+1]=L[1],e[t+2]=L[2],e[t+3]=L[3],e[t+4]=L[4],e[t+5]=L[5],e[t+6]=L[6],e[t+7]=L[7]}function wo(r,e){return L[0]=r[e],L[1]=r[e+1],L[2]=r[e+2],L[3]=r[e+3],L[4]=r[e+4],L[5]=r[e+5],L[6]=r[e+6],L[7]=r[e+7],$r[0]}var ta=BigInt(Number.MAX_SAFE_INTEGER),ra=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 fe;if(e<ta&&e>ra)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>yo&&(o=0n,++n>yo&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(e){if(e===0)return fe;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):fe}},fe=new P(0,0);fe.toBigInt=function(){return 0n};fe.zzEncode=fe.zzDecode=function(){return this};fe.length=function(){return 1};var yo=4294967296n;function Eo(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 Io(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 Wr(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 F(r,e){return RangeError(`index out of range: ${r.pos} + ${e??1} > ${r.len}`)}function gt(r,e){return(r[e-4]|r[e-3]<<8|r[e-2]<<16|r[e-1]<<24)>>>0}var jr=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(e){this.buf=ke(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,F(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 F(this,4);return gt(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw F(this,4);return gt(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw F(this,4);let e=bo(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw F(this,4);let e=wo(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 F(this,e);return this.pos+=e,t===n?new Uint8Array(0):this.buf.subarray(t,n)}string(){let e=this.bytes();return Io(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw F(this,e);this.pos+=e}else do if(this.pos>=this.len)throw F(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 F(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 F(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 F(this,8);let e=gt(this.buf,this.pos+=4),t=gt(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=nr(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 We(r){return new jr(r instanceof Uint8Array?r:r.subarray())}function Gr(r,e,t){let n=We(r);return e.decode(n,void 0,t)}function qr(r){let e=r??8192,t=e>>>1,n,o=e;return function(i){if(i<1||i>t)return A(i);o+i>e&&(n=A(e),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var he=class{fn;len;next;val;constructor(e,t,n){this.fn=e,this.len=t,this.next=void 0,this.val=n}};function Xr(){}var Yr=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},na=qr();function oa(r){return globalThis.Buffer!=null?A(r):na(r)}var Ge=class{len;head;tail;states;constructor(){this.len=0,this.head=new he(Xr,0,0),this.tail=this.head,this.states=null}_push(e,t,n){return this.tail=this.tail.next=new he(e,t,n),this.len+=t,this}uint32(e){return this.len+=(this.tail=this.tail.next=new Qr((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(bt,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(bt,t.length(),t)}uint64Number(e){return this._push(Ce,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(bt,t.length(),t)}sint64Number(e){let t=P.fromNumber(e).zzEncode();return this._push(bt,t.length(),t)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(Hr,1,e?1:0)}fixed32(e){return this._push(je,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let t=P.fromBigInt(e);return this._push(je,4,t.lo)._push(je,4,t.hi)}fixed64Number(e){let t=P.fromNumber(e);return this._push(je,4,t.lo)._push(je,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(go,4,e)}double(e){return this._push(xo,8,e)}bytes(e){let t=e.length>>>0;return t===0?this._push(Hr,1,0):this.uint32(t)._push(ia,t,e)}string(e){let t=Eo(e);return t!==0?this.uint32(t)._push(Wr,t,e):this._push(Hr,1,0)}fork(){return this.states=new Yr(this),this.head=this.tail=new he(Xr,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new he(Xr,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=oa(this.len),n=0;for(;e!=null;)e.fn(e.val,t,n),n+=e.len,e=e.next;return t}};function Hr(r,e,t){e[t]=r&255}function sa(r,e,t){for(;r>127;)e[t++]=r&127|128,r>>>=7;e[t]=r}var Qr=class extends he{next;constructor(e,t){super(sa,e,t),this.next=void 0}};function bt(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 je(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 ia(r,e,t){e.set(r,t)}globalThis.Buffer!=null&&(Ge.prototype.bytes=function(r){let e=r.length>>>0;return this.uint32(e),e>0&&this._push(aa,e,r),this},Ge.prototype.string=function(r){let e=globalThis.Buffer.byteLength(r);return this.uint32(e),e>0&&this._push(ca,e,r),this});function aa(r,e,t){e.set(r,t)}function ca(r,e,t){r.length<40?Wr(r,e,t):e.utf8Write!=null?e.utf8Write(r,t):e.set(ee(r),t)}function Jr(){return new Ge}function Kr(r,e){let t=Jr();return e.encode(r,t,{lengthDelimited:!1}),t.finish()}function*Zr(r,e,t){let n=We(r);yield*e.stream(n,void 0,"$",t)}var xt={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function wt(r,e,t,n,o){return{name:r,type:e,encode:t,decode:n,stream:o}}function en(r){function e(s){if(r[s.toString()]==null)throw new Error("Invalid enum value");return r[s]}let t=function(i,a){let c=e(i);a.int32(c)},n=function(i){let a=i.int32();return e(a)},o=function*(i){let a=i.int32();yield e(a)};return wt("enum",xt.VARINT,t,n,o)}function tn(r,e,t){return wt("message",xt.LENGTH_DELIMITED,r,e,t)}var qe=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var M;(function(r){let e;(function(a){a.UNUSED="UNUSED",a.CONNECT="CONNECT",a.SYNC="SYNC"})(e=r.Type||(r.Type={}));let t;(function(a){a[a.UNUSED=0]="UNUSED",a[a.CONNECT=100]="CONNECT",a[a.SYNC=300]="SYNC"})(t||(t={})),(function(a){a.codec=()=>en(t)})(e=r.Type||(r.Type={}));let n;r.codec=()=>(n==null&&(n=tn((a,c,l={})=>{if(l.lengthDelimited!==!1&&c.fork(),a.type!=null&&(c.uint32(8),r.Type.codec().encode(a.type,c)),a.observedAddresses!=null&&a.observedAddresses.length>0)for(let u of a.observedAddresses)c.uint32(18),c.bytes(u);l.lengthDelimited!==!1&&c.ldelim()},(a,c,l={})=>{let u={observedAddresses:[]},f=c==null?a.len:a.pos+c;for(;a.pos<f;){let d=a.uint32();switch(d>>>3){case 1:{u.type=r.Type.codec().decode(a);break}case 2:{if(l.limits?.observedAddresses!=null&&u.observedAddresses.length===l.limits.observedAddresses)throw new qe('Decode error - repeated field "observedAddresses" had too many elements');u.observedAddresses.push(a.bytes());break}default:{a.skipType(d&7);break}}}return u},function*(a,c,l,u={}){let f={observedAddresses:0},d=c==null?a.len:a.pos+c;for(;a.pos<d;){let g=a.uint32();switch(g>>>3){case 1:{yield{field:`${l}.type`,value:r.Type.codec().decode(a)};break}case 2:{if(u.limits?.observedAddresses!=null&&f.observedAddresses===u.limits.observedAddresses)throw new qe('Streaming decode error - repeated field "observedAddresses" had too many elements');yield{field:`${l}.observedAddresses[]`,index:f.observedAddresses,value:a.bytes()},f.observedAddresses++;break}default:{a.skipType(g&7);break}}}})),n);function o(a){return Kr(a,r.codec())}r.encode=o;function s(a,c){return Gr(a,r.codec(),c)}r.decode=s;function i(a,c){return Zr(a,r.codec(),c)}r.stream=i})(M||(M={}));function rn(r,e){return $e.matches(r)||e.dialTransportForMultiaddr(r)==null?!1:to.matches(r)?!0:oo.matches(r)?!Rn(r):!1}var Co=1024*4,So=100,yt={timeout:5e3,retries:3,maxInboundStreams:1,maxOutboundStreams:1},Et=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??yt.timeout,this.retries=t.retries??yt.retries,this.maxInboundStreams=t.maxInboundStreams??yt.maxInboundStreams,this.maxOutboundStreams=t.maxOutboundStreams??yt.maxOutboundStreams,this.handleIncomingUpgrade=this.handleIncomingUpgrade.bind(this)}[Symbol.toStringTag]="@libp2p/dcutr";[on]=["@libp2p/identify"];isStarted(){return this.started}async start(){this.started||(this.topologyId=await this.registrar.register(Ne,{notifyOnLimitedConnection:!0,onConnect:(e,t)=>{$e.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(Ne,this.handleIncomingUpgrade,{maxInboundStreams:this.maxInboundStreams,maxOutboundStreams:this.maxOutboundStreams,runOnLimitedConnection:!0}),this.started=!0)}async stop(){await this.registrar.unhandle(Ne),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([Ne],{signal:o.signal,runOnLimitedConnection:!0});let s=zr(t,{maxDataLength:Co}).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(f=>f.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 G("DCUtR message type was incorrect");let c=this.getDialableMultiaddrs(a.observedAddresses);if(c.length===0)throw this.log("A did not have any dialable multiaddrs"),new G("DCUtR connect message had no multiaddrs");let l=Date.now()-i;this.log("A sending sync, rtt %dms",l),await s.write({type:M.Type.SYNC,observedAddresses:[]},o),this.log("A waiting for half RTT"),await mo(l/2),this.log("B dialing",c);let u=await this.connectionManager.openConnection(c,{signal:o.signal,priority:So,force:!0,initiator:!1});this.log("DCUtR to %p succeeded to address %a, closing relayed connection",e.remotePeer,u.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=>rn(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($e.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=zr(e,{maxDataLength:Co}).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 G("DCUtR message type was incorrect");if(s.observedAddresses.length===0)throw this.log("B sent no multiaddrs"),new G("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(l=>Dr(l))),new G("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(l=>l.bytes)}),this.log("A receiving sync"),(await o.read(n)).type!==M.Type.SYNC)throw new G("DCUtR message type was incorrect");this.log("A dialing",i);let c=await this.connectionManager.openConnection(i,{signal:n.signal,priority:So,force:!0});this.log("DCUtR to %p succeeded via %a, closing relayed connection",t.remotePeer,c.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=Dr(n);if(!rn(o,this.transportManager))continue;t.push(o)}catch{}return t}};var Ne="/libp2p/dcutr";function ua(r={}){return e=>new Et(e,r)}return Po(la);})();
3
3
  return Libp2PDcutr}));
4
4
  //# sourceMappingURL=index.min.js.map