@libp2p/dcutr 3.0.32-3c9142a7c → 3.0.32-42064ed68
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +4 -4
- package/package.json +4 -4
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 Po=Object.create;var Je=Object.defineProperty;var Oo=Object.getOwnPropertyDescriptor;var Uo=Object.getOwnPropertyNames;var Bo=Object.getPrototypeOf,Fo=Object.prototype.hasOwnProperty;var At=(r,e)=>()=>{try{return e||r((e={exports:{}}).exports,e),e.exports}catch(t){throw e=0,t}},B=(r,e)=>{for(var t in e)Je(r,t,{get:e[t],enumerable:!0})},cn=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Uo(e))!Fo.call(r,o)&&o!==t&&Je(r,o,{get:()=>e[o],enumerable:!(n=Oo(e,o))||n.enumerable});return r};var Mo=(r,e,t)=>(t=r!=null?Po(Bo(r)):{},cn(e||!r||!r.__esModule?Je(t,"default",{value:r,enumerable:!0}):t,r)),Ro=r=>cn(Je({},"__esModule",{value:!0}),r);var Jt=At(Ce=>{"use strict";Object.defineProperty(Ce,"__esModule",{value:!0});Ce.Netmask4Impl=void 0;Ce.ip2long=Ie;Ce.long2ip=G;function G(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 Ks=48,Zs=97,ei=65;function ti(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)-Ks)>>>0;else if(t===16)if("a"<=r[o]&&r[o]<="f")e=e*t+(10+r.charCodeAt(o)-Zs)>>>0;else if("A"<=r[o]&&r[o]<="F")e=e*t+(10+r.charCodeAt(o)-ei)>>>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 Ie(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]=ti(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 Yt=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=Ie(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=(Ie(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=G(this.netLong),this.mask=G(this.maskLong),this.hostmask=G(~this.maskLong),this.first=this.bitmask<=30?G(this.netLong+1):this.base,this.last=this.bitmask<=30?G(this.netLong+this.size-2):G(this.netLong+this.size-1),this.broadcast=this.bitmask<=30?G(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):(Ie(e)&this.maskLong)>>>0===(this.netLong&this.maskLong)>>>0}next(e=1){return new r(G(this.netLong+this.size*e),this.mask)}forEach(e){let t=Ie(this.first),n=Ie(this.last),o=0;for(;t<=n;)e(G(t),t,o),o++,t++}toString(){return this.base+"/"+this.bitmask}};Ce.Netmask4Impl=Yt});var kn=At(Se=>{"use strict";Object.defineProperty(Se,"__esModule",{value:!0});Se.Netmask6Impl=void 0;Se.ip6bigint=Zt;Se.bigint2ip6=ue;var ri=Jt(),Kt=(1n<<128n)-1n;function Zt(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,ri.ip2long)(n),s=r.substring(0,t+1)+"0:0";return Rn(s)&~0xffffffffn|BigInt(o)}return Rn(r)}function Rn(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 ue(r){if(r<0n||r>Kt)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 er=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=Kt>>BigInt(128-this.bitmask)<<BigInt(128-this.bitmask);try{this.netBigint=Zt(e)&this.maskBigint}catch{throw new Error("Invalid IPv6 net address: "+e)}this.size=Number(1n<<BigInt(128-this.bitmask)),this.base=ue(this.netBigint),this.mask=ue(this.maskBigint),this.hostmask=ue(~this.maskBigint&Kt),this.first=this.base,this.last=ue(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):(Zt(e)&this.maskBigint)===this.netBigint}next(e=1){let t=1n<<BigInt(128-this.bitmask);return new r(ue(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(ue(t),Number(t),s),s++,t++}toString(){return this.base+"/"+this.bitmask}};Se.Netmask6Impl=er});var zn=At(re=>{"use strict";Object.defineProperty(re,"__esModule",{value:!0});re.long2ip=re.ip2long=re.Netmask=void 0;var st=Jt();Object.defineProperty(re,"ip2long",{enumerable:!0,get:function(){return st.ip2long}});Object.defineProperty(re,"long2ip",{enumerable:!0,get:function(){return st.long2ip}});var ni=kn(),tr=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 ni.Netmask6Impl(e,t):this._impl=new st.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 st.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()}};re.Netmask=tr});var Sa={};B(Sa,{dcutr:()=>Ca,multicodec:()=>Pe});var me=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}};var Ke=class extends Error{static name="StreamBufferError";constructor(e="The stream buffer was full"){super(e),this.name="StreamBufferError"}};var H=class extends Error{static name="InvalidMessageError";constructor(e="Invalid message"){super(e),this.name="InvalidMessageError"}};var un=Symbol.for("@libp2p/service-dependencies");function $(r=0){return new Uint8Array(r)}function D(r=0){return new Uint8Array(r)}function ko(r){return r?.buffer instanceof ArrayBuffer}function Dt(r){if(ko(r))return r;let e=r.slice();return new Uint8Array(e.buffer,0,e.byteLength)}function X(r,e){e==null&&(e=r.reduce((o,s)=>o+s.length,0));let t=D(e),n=0;for(let o of r)t.set(o,n),n+=o.length;return Dt(t)}function Be(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 fn=Symbol.for("@achingbrain/uint8arraylist");function ln(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 Ze(r){return!!r?.[fn]}var ae=class r{bufs;length;[fn]=!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(Ze(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(Ze(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=ln(this.bufs,e);return t.buf[t.index]}set(e,t){let n=ln(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(Ze(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 X(n,o)}subarray(e,t){let{bufs:n,length:o}=this._subList(e,t);return n.length===1?n[0]:X(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 u=e>=a&&e<c,f=t>a&&t<=c;if(u&&f){if(e===a&&t===c){n.push(i);break}let l=e-a;n.push(i.subarray(l,l+(t-e)));break}if(u){if(e===0){n.push(i);continue}n.push(i.subarray(e-a));continue}if(f){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(!Ze(e)&&!(e instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=e instanceof Uint8Array?e:e.subarray();if(t=Number(t??0),isNaN(t)&&(t=0),t<0&&(t=this.length+t),t<0&&(t=0),e.length===0)return t>this.length?this.length:t;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let l=0;l<s;l++)i[l]=-1;for(let l=0;l<o;l++)i[n[l]]=l;let a=i,c=this.byteLength-n.byteLength,u=n.byteLength-1,f;for(let l=t;l<=c;l+=f){f=0;for(let p=u;p>=0;p--){let x=this.get(l+p);if(n[p]!==x){f=Math.max(1,p-a[x]);break}}if(f===0)return l}return-1}getInt8(e){let t=this.subarray(e,e+1);return new DataView(t.buffer,t.byteOffset,t.byteLength).getInt8(0)}setInt8(e,t){let n=D(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=$(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=$(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=$(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=D(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=$(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=$(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=$(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=$(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=$(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(!Be(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 Pt={};B(Pt,{base10:()=>Ho});var uc=new Uint8Array(0);function dn(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 R(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return ce(r);if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return ce(new Uint8Array(r.buffer,r.byteOffset,r.byteLength));throw new Error("Unknown type, must be binary type")}function pn(r){let e=new Uint8Array(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}var hn=4096;function mn(r){let e=r.length;if(e<=hn)return String.fromCharCode.apply(String,r);let t="",n=0;for(;n<e;)t+=String.fromCharCode.apply(String,r.subarray(n,n+=hn));return t}function zo(r){return r?.buffer instanceof ArrayBuffer}function ce(r){return zo(r)?r:r.slice()}function Vo(r,e,t){if(r.length>=255)throw new TypeError("Alphabet too long");for(var n=new Uint8Array(256),o=0;o<n.length;o++)n[o]=255;for(var s=0;s<r.length;s++){var i=r.charAt(s),a=i.charCodeAt(0);if(n[a]!==255)throw new TypeError(i+" is ambiguous");if(n[a]=s,t){var c=i.toLowerCase().charCodeAt(0),u=i.toUpperCase().charCodeAt(0);c!==a&&(n[c]=s),u!==a&&(n[u]=s)}}var f=r.length,l=r.charAt(0),p=Math.log(f)/Math.log(256),x=Math.log(256)/Math.log(f);function K(w){if(w instanceof Uint8Array||(ArrayBuffer.isView(w)?w=new Uint8Array(w.buffer,w.byteOffset,w.byteLength):Array.isArray(w)&&(w=Uint8Array.from(w))),!(w instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(w.length===0)return"";for(var A=0,V=0,I=0,N=w.length;I!==N&&w[I]===0;)I++,A++;for(var M=(N-I)*x+1>>>0,se=new Uint8Array(M);I!==N;){for(var P=w[I],ie=0,q=M-1;(P!==0||ie<V)&&q!==-1;q--,ie++)P+=256*se[q]>>>0,se[q]=P%f>>>0,P=P/f>>>0;if(P!==0)throw new Error("Non-zero carry");V=ie,I++}for(var U=M-V;U!==M&&se[U]===0;)U++;for(var Ue=l.repeat(A);U<M;++U)Ue+=r.charAt(se[U]);return Ue}function j(w){if(typeof w!="string")throw new TypeError("Expected String");if(w.length===0)return new Uint8Array;var A=0;if(w[A]!==" "){for(var V=0,I=0;w[A]===l;)V++,A++;for(var N=(w.length-A)*p+1>>>0,M=new Uint8Array(N);w[A];){var se=w.charCodeAt(A);if(se>255)return;var P=n[se];if(P===255)return;for(var ie=0,q=N-1;(P!==0||ie<I)&&q!==-1;q--,ie++)P+=f*M[q]>>>0,M[q]=P%256>>>0,P=P/256>>>0;if(P!==0)throw new Error("Non-zero carry");I=ie,A++}if(w[A]!==" "){for(var U=N-I;U!==N&&M[U]===0;)U++;for(var Ue=new Uint8Array(V+(N-U)),No=V;U!==N;)Ue[No++]=M[U++];return Ue}}}function Oe(w){var A=j(w);if(A)return A;throw new Error(`Non-${e} character`)}return{encode:K,decodeUnsafe:j,decode:Oe}}var $o=Vo,Wo=$o,bn=Wo;var Tt=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")}},Lt=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 xn(this,e)}},_t=class{decoders;constructor(e){this.decoders=e}or(e){return xn(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 xn(r,e){return new _t({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var Nt=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 Tt(e,t,n),this.decoder=new Lt(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function ge({name:r,prefix:e,encode:t,decode:n}){return new Nt(r,e,t,n)}function Z({name:r,prefix:e,alphabet:t,caseInsensitive:n=!1}){let{encode:o,decode:s}=bn(t,r,n);return ge({prefix:e,name:r,encode:o,decode:i=>R(s(i))})}function Go(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 u=0;u<o;++u){let f=e[r[u]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<t|f,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 jo(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 qo(r,e){let t={};for(let n=0;n<r.length;++n)if(t[r[n]]=n,e){let o=r[n].toLowerCase(),s=r[n].toUpperCase();o!==r[n]&&(t[o]=n),s!==r[n]&&(t[s]=n)}return t}function v({name:r,prefix:e,bitsPerChar:t,alphabet:n,caseInsensitive:o=!1}){let s=qo(n,o);return ge({prefix:e,name:r,encode(i){return jo(i,n,t)},decode(i){return Go(i,s,t,r)}})}var Ho=Z({prefix:"9",name:"base10",alphabet:"0123456789"});var Ot={};B(Ot,{base16:()=>Xo,base16upper:()=>Qo});var Xo=v({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4,caseInsensitive:!0}),Qo=v({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4,caseInsensitive:!0});var Ut={};B(Ut,{base2:()=>Yo});var Yo=v({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Bt={};B(Bt,{base256emoji:()=>ts});var wn=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}"),Jo=wn.reduce((r,e,t)=>(r[t]=e,r),[]),Ko=wn.reduce((r,e,t)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return r[n]=t,r},[]);function Zo(r){return r.reduce((e,t)=>(e+=Jo[t],e),"")}function es(r){let e=[];for(let t of r){let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);let o=Ko[n];if(o==null)throw new Error(`Non-base256emoji character: ${t}`);e.push(o)}return new Uint8Array(e)}var ts=ge({prefix:"\u{1F680}",name:"base256emoji",encode:Zo,decode:es});var Ft={};B(Ft,{base32:()=>ee,base32hex:()=>ss,base32hexpad:()=>as,base32hexpadupper:()=>cs,base32hexupper:()=>is,base32pad:()=>ns,base32padupper:()=>os,base32upper:()=>rs,base32z:()=>us});var ee=v({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5,caseInsensitive:!0}),rs=v({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5,caseInsensitive:!0}),ns=v({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5,caseInsensitive:!0}),os=v({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5,caseInsensitive:!0}),ss=v({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5,caseInsensitive:!0}),is=v({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5,caseInsensitive:!0}),as=v({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5,caseInsensitive:!0}),cs=v({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5,caseInsensitive:!0}),us=v({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Mt={};B(Mt,{base36:()=>Fe,base36upper:()=>ls});var Fe=Z({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz",caseInsensitive:!0}),ls=Z({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",caseInsensitive:!0});var Rt={};B(Rt,{base58btc:()=>W,base58flickr:()=>fs});var W=Z({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),fs=Z({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var zt={};B(zt,{base64:()=>hs,base64pad:()=>ds,base64url:()=>kt,base64urlpad:()=>ps});var hs=v({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),ds=v({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),kt=v({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),ps=v({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Vt={};B(Vt,{base8:()=>ms});var ms=v({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var $t={};B($t,{identity:()=>gs});var gs=ge({prefix:"\0",name:"identity",encode:r=>mn(R(r)),decode:r=>R(pn(r))});var Sc=new TextEncoder,Ac=new TextDecoder;var Gt={};B(Gt,{identity:()=>ks});var ws=vn,yn=128,ys=127,Es=~ys,vs=Math.pow(2,31);function vn(r,e,t){e=e||[],t=t||0;for(var n=t;r>=vs;)e[t++]=r&255|yn,r/=128;for(;r&Es;)e[t++]=r&255|yn,r>>>=7;return e[t]=r|0,vn.bytes=t-n+1,e}var Is=Wt,Cs=128,En=127;function Wt(r,n){var t=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw Wt.bytes=0,new RangeError("Could not decode varint");i=r[s++],t+=o<28?(i&En)<<o:(i&En)*Math.pow(2,o),o+=7}while(i>=Cs);return Wt.bytes=s-n,t}var Ss=Math.pow(2,7),As=Math.pow(2,14),Ds=Math.pow(2,21),Ts=Math.pow(2,28),Ls=Math.pow(2,35),_s=Math.pow(2,42),Ns=Math.pow(2,49),Ps=Math.pow(2,56),Os=Math.pow(2,63),Us=function(r){return r<Ss?1:r<As?2:r<Ds?3:r<Ts?4:r<Ls?5:r<_s?6:r<Ns?7:r<Ps?8:r<Os?9:10},Bs={encode:ws,decode:Is,encodingLength:Us},Fs=Bs,Me=Fs;function Re(r,e=0){let t=Me.decode(r,e),n=Me.decode.bytes;if(n>9)throw new RangeError("Invalid varint: too long");if(n>1&&r[e+n-1]===0)throw new RangeError("Invalid varint: not minimally encoded");return[t,n]}function be(r,e,t=0){return Me.encode(r,e,t),e}function xe(r){return Me.encodingLength(r)}function ye(r,e){let t=e.byteLength,n=xe(r),o=n+xe(t),s=new Uint8Array(o+t);return be(r,s,0),be(t,s,n),s.set(e,o),new we(r,t,e,s)}function In(r){let e=R(r),[t,n]=Re(e),[o,s]=Re(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new we(t,o,i,e)}function Cn(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&dn(r.bytes,t.bytes)}}var we=class{code;size;digest;bytes;constructor(e,t,n,o){this.code=e,this.size=t,this.digest=ce(n),this.bytes=ce(o)}};var Sn=0,Ms="identity",An=R;function Rs(r,e){if(e?.truncate!=null&&e.truncate!==r.byteLength){if(e.truncate<0||e.truncate>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,e.truncate)}return ye(Sn,An(r))}var ks={code:Sn,name:Ms,encode:An,digest:Rs};var Ht={};B(Ht,{sha256:()=>Vs,sha512:()=>$s});var zs=20;function qt({name:r,code:e,encode:t,minDigestLength:n,maxDigestLength:o}){return new jt(r,e,t,n,o)}var jt=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,t,n,o,s){this.name=e,this.code=t,this.encode=n,this.minDigestLength=o??zs,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?Dn(n,this.code,t?.truncate):n.then(o=>Dn(o,this.code,t?.truncate))}else throw Error("Unknown type, must be binary type")}};function Dn(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 ye(e,r)}function Ln(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var Vs=qt({name:"sha2-256",code:18,encode:Ln("SHA-256")}),$s=qt({name:"sha2-512",code:19,encode:Ln("SHA-512")});function _n(r,e){let{bytes:t,version:n}=r;return n===0?Gs(t,Xt(r),e??W.encoder):js(t,Xt(r),e??ee.encoder)}var Nn=new WeakMap;function Xt(r){let e=Nn.get(r);if(e==null){let t=new Map;return Nn.set(r,t),t}return e}var Ee=class r{code;version;multihash;bytes;"/";constructor(e,t,n,o){this.code=t,this.version=e,this.multihash=n,this.bytes=ce(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!==ze)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==qs)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=ye(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&&Cn(e.multihash,n.multihash)}toString(e){return _n(this,e)}toJSON(){return{"/":_n(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??Pn(n,o,s.bytes))}else if(t[Hs]===!0){let{version:n,multihash:o,code:s}=t,i=In(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!==ze)throw new Error(`Version 0 CID must use dag-pb (code: ${ze}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let o=Pn(e,t,n.bytes);return new r(e,t,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,ze,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=R(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 we(t.multihashCode,t.digestSize,s,o);return[t.version===0?r.createV0(i):r.createV1(t.codec,i),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[l,p]=Re(e.subarray(t));return t+=p,l},o=n(),s=ze;if(o===18)o=0,t=0;else if(o===1)s=n();else throw o===0?new RangeError("Invalid CID version, v0 is always implicit"):new RangeError(`Invalid CID version ${o}`);let i=t,a=n(),c=n(),u=t+c,f=u-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:f,size:u}}static parse(e,t){let[n,o]=Ws(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 Xt(s).set(n,e),s}};function Ws(r,e){switch(r[0]){case"Q":{let t=e??W;return[W.prefix,t.decode(`${W.prefix}${r}`)]}case W.prefix:{let t=e??W;return[W.prefix,t.decode(r)]}case ee.prefix:{let t=e??ee;return[ee.prefix,t.decode(r)]}case Fe.prefix:{let t=e??Fe;return[Fe.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 Gs(r,e,t){let{prefix:n}=t;if(n!==W.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 js(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 ze=112,qs=18;function Pn(r,e,t){let n=xe(r),o=n+xe(e),s=new Uint8Array(o+t.byteLength);return be(r,s,0),be(e,s,n),s.set(t,o),s}var Hs=Symbol.for("@ipld/js-cid/CID");var Ve={...$t,...Ut,...Vt,...Pt,...Ot,...Ft,...Mt,...Rt,...zt,...Bt},Xc={...Ht,...Gt};function Un(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var On=Un("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Qt=Un("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=D(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),Xs={utf8:On,"utf-8":On,hex:Ve.base16,latin1:Qt,ascii:Qt,binary:Qt,...Ve},tt=Xs;function te(r,e="utf8"){let t=tt[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.decoder.decode(`${t.prefix}${r}`)}function Qs(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 Bn(r){let e=Qs(r);if(e==null)throw new me(`Multiaddr ${r} was not an IPv4, IPv6, DNS, DNS4, DNS6 or DNSADDR address`);return e}var rt=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",u=2**(8*o)-1;for(;;){let f=this.readAtomically(()=>{let l=this.readChar();if(l===void 0)return;let p=Number.parseInt(l,e);if(!Number.isNaN(p))return p});if(f===void 0)break;if(s*=e,s+=f,s>u||(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 Ys=45,Js=15,nt=new rt;function Fn(r){if(!(r.length>Js))return nt.new(r).parseWith(()=>nt.readIPv4Addr())}function Mn(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>Ys))return nt.new(r).parseWith(()=>nt.readIPv6Addr())}function ve(r){return!!Fn(r)}function ot(r){return!!Mn(r)}var Vn=Mo(zn(),1),oi=["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"],si=oi.map(r=>new Vn.Netmask(r));function rr(r){for(let e of si)if(e.contains(r))return!0;return!1}function ii(r){return/^::ffff:([0-9a-fA-F]{1,4}):([0-9a-fA-F]{1,4})$/.test(r)}function ai(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 rr(o)}function ci(r){return/^::ffff:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(r)}function ui(r){let e=r.split(":"),t=e[e.length-1];return rr(t)}function li(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 $n(r){if(ve(r))return rr(r);if(ii(r))return ai(r);if(ci(r))return ui(r);if(ot(r))return li(r)}function Wn(r){try{let e=Bn(r);switch(e.type){case"ip4":case"ip6":return $n(e.host)??!1;default:return e.host==="localhost"}}catch{return!1}}var fi=Math.pow(2,7),hi=Math.pow(2,14),di=Math.pow(2,21),nr=Math.pow(2,28),or=Math.pow(2,35),sr=Math.pow(2,42),ir=Math.pow(2,49),g=128,T=127;function O(r){if(r<fi)return 1;if(r<hi)return 2;if(r<di)return 3;if(r<nr)return 4;if(r<or)return 5;if(r<sr)return 6;if(r<ir)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Ae(r,e,t=0){switch(O(r)){case 8:e[t++]=r&255|g,r/=128;case 7:e[t++]=r&255|g,r/=128;case 6:e[t++]=r&255|g,r/=128;case 5:e[t++]=r&255|g,r/=128;case 4:e[t++]=r&255|g,r>>>=7;case 3:e[t++]=r&255|g,r>>>=7;case 2:e[t++]=r&255|g,r>>>=7;case 1:{e[t++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return e}function pi(r,e,t=0){switch(O(r)){case 8:e.set(t++,r&255|g),r/=128;case 7:e.set(t++,r&255|g),r/=128;case 6:e.set(t++,r&255|g),r/=128;case 5:e.set(t++,r&255|g),r/=128;case 4:e.set(t++,r&255|g),r>>>=7;case 3:e.set(t++,r&255|g),r>>>=7;case 2:e.set(t++,r&255|g),r>>>=7;case 1:{e.set(t++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return e}function ar(r,e){let t=r[e],n=0;if(n+=t&T,t<g||(t=r[e+1],n+=(t&T)<<7,t<g)||(t=r[e+2],n+=(t&T)<<14,t<g)||(t=r[e+3],n+=(t&T)<<21,t<g)||(t=r[e+4],n+=(t&T)*nr,t<g)||(t=r[e+5],n+=(t&T)*or,t<g)||(t=r[e+6],n+=(t&T)*sr,t<g)||(t=r[e+7],n+=(t&T)*ir,t<g))return n;throw new RangeError("Could not decode varint")}function mi(r,e){let t=r.get(e),n=0;if(n+=t&T,t<g||(t=r.get(e+1),n+=(t&T)<<7,t<g)||(t=r.get(e+2),n+=(t&T)<<14,t<g)||(t=r.get(e+3),n+=(t&T)<<21,t<g)||(t=r.get(e+4),n+=(t&T)*nr,t<g)||(t=r.get(e+5),n+=(t&T)*or,t<g)||(t=r.get(e+6),n+=(t&T)*sr,t<g)||(t=r.get(e+7),n+=(t&T)*ir,t<g))return n;throw new RangeError("Could not decode varint")}function Gn(r,e,t=0){return e==null&&(e=D(O(r))),e instanceof Uint8Array?Ae(r,e,t):pi(r,e,t)}function $e(r,e=0){return r instanceof Uint8Array?ar(r,e):mi(r,e)}function gi(r){return r.buffer instanceof ArrayBuffer}function We(r){return gi(r)?r:r.slice()}function ne(r,e="utf8"){let t=tt[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.encoder.encode(r).substring(1)}var S=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},Q=class extends Error{static name="ValidationError";name="ValidationError"},it=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},at=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};function ur(r){return e=>ne(e,r)}function lr(r){return e=>te(e,r)}function De(r){return new DataView(r.buffer).getUint16(r.byteOffset).toString()}function le(r){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,typeof r=="string"?parseInt(r):r),new Uint8Array(e)}function qn(r){let e=r.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==16)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion address.`);let t=te(e[0],"base32"),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=le(n);return X([t,o],t.length+o.length)}function Hn(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=ee.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=le(n);return X([t,o],t.length+o.length)}function fr(r){let e=r.subarray(0,r.length-2),t=r.subarray(r.length-2),n=ne(e,"base32"),o=De(t);return`${n}:${o}`}var hr=function(r){r=r.toString().trim();let e=new Uint8Array(4);return r.split(/\./g).forEach((t,n)=>{let o=parseInt(t,10);if(isNaN(o)||o<0||o>255)throw new S("Invalid byte value in IP address");e[n]=o}),e},Xn=function(r){let e=0;r=r.toString().trim();let t=r.split(":",8),n;for(n=0;n<t.length;n++){let s=ve(t[n]),i;s&&(i=hr(t[n]),t[n]=ne(i.subarray(0,2),"base16")),i!=null&&++n<8&&t.splice(n,0,ne(i.subarray(2,4),"base16"))}if(t[0]==="")for(;t.length<8;)t.unshift("0");else if(t[t.length-1]==="")for(;t.length<8;)t.push("0");else if(t.length<8){for(n=0;n<t.length&&t[n]!=="";n++);let s=[n,1];for(n=9-t.length;n>0;n--)s.push("0");t.splice.apply(t,s)}let o=new Uint8Array(e+16);for(n=0;n<t.length;n++){t[n]===""&&(t[n]="0");let s=parseInt(t[n],16);if(isNaN(s)||s<0||s>65535)throw new S("Invalid byte value in IP address");o[e++]=s>>8&255,o[e++]=s&255}return o},Qn=function(r){if(r.byteLength!==4)throw new S("IPv4 address was incorrect length");let e=[];for(let t=0;t<r.byteLength;t++)e.push(r[t]);return e.join(".")},Yn=function(r){if(r.byteLength!==16)throw new S("IPv6 address was incorrect length");let e=[];for(let n=0;n<r.byteLength;n+=2){let o=r[n],s=r[n+1],i=`${o.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}`;e.push(i)}let t=e.join(":");try{let n=new URL(`http://[${t}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new S(`Invalid IPv6 address "${t}"`)}};function Jn(r){try{let e=new URL(`http://[${r}]`);return e.hostname.substring(1,e.hostname.length-1)}catch{throw new S(`Invalid IPv6 address "${r}"`)}}var cr=Object.values(Ve).map(r=>r.decoder),bi=(function(){let r=cr[0].or(cr[1]);return cr.slice(2).forEach(e=>r=r.or(e)),r})();function Kn(r){return bi.decode(r)}function Zn(r){return e=>r.encoder.encode(e)}function xi(r){if(parseInt(r).toString()!==r)throw new Q("Value must be an integer")}function wi(r){if(r<0)throw new Q("Value must be a positive integer, or zero")}function yi(r){return e=>{if(e>r)throw new Q(`Value must be smaller than or equal to ${r}`)}}function Ei(...r){return e=>{for(let t of r)t(e)}}var Ge=Ei(xi,wi,yi(65535));var C=-1,dr=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)}))}},J=new dr,Bi=[{code:4,name:"ip4",size:32,valueToBytes:hr,bytesToValue:Qn,validate:r=>{if(!ve(r))throw new Q(`Invalid IPv4 address "${r}"`)}},{code:6,name:"tcp",size:16,valueToBytes:le,bytesToValue:De,validate:Ge},{code:273,name:"udp",size:16,valueToBytes:le,bytesToValue:De,validate:Ge},{code:33,name:"dccp",size:16,valueToBytes:le,bytesToValue:De,validate:Ge},{code:41,name:"ip6",size:128,valueToBytes:Xn,bytesToValue:Yn,stringToValue:Jn,validate:r=>{if(!ot(r))throw new Q(`Invalid IPv6 address "${r}"`)}},{code:42,name:"ip6zone",size:C},{code:43,name:"ipcidr",size:8,bytesToValue:ur("base10"),valueToBytes:lr("base10")},{code:53,name:"dns",size:C},{code:54,name:"dns4",size:C},{code:55,name:"dns6",size:C},{code:56,name:"dnsaddr",size:C},{code:132,name:"sctp",size:16,valueToBytes:le,bytesToValue:De,validate:Ge},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:C,stringToValue:r=>decodeURIComponent(r),valueToString:r=>encodeURIComponent(r)},{code:421,name:"p2p",aliases:["ipfs"],size:C,bytesToValue:ur("base58btc"),valueToBytes:r=>r.startsWith("Q")||r.startsWith("1")?lr("base58btc")(r):Ee.parse(r).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:fr,valueToBytes:qn},{code:445,name:"onion3",size:296,bytesToValue:fr,valueToBytes:Hn},{code:446,name:"garlic64",size:C},{code:447,name:"garlic32",size:C},{code:448,name:"tls"},{code:449,name:"sni",size:C},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:C,bytesToValue:Zn(kt),valueToBytes:Kn},{code:480,name:"http"},{code:481,name:"http-path",size:C,stringToValue:r=>`/${decodeURIComponent(r)}`,valueToString:r=>encodeURIComponent(r.substring(1))},{code:443,name:"https"},{code:477,name:"ws"},{code:478,name:"wss"},{code:479,name:"p2p-websocket-star"},{code:277,name:"p2p-stardust"},{code:275,name:"p2p-webrtc-star"},{code:276,name:"p2p-webrtc-direct"},{code:280,name:"webrtc-direct"},{code:281,name:"webrtc"},{code:290,name:"p2p-circuit"},{code:777,name:"memory",size:C}];Bi.forEach(r=>{J.addProtocol(r)});function eo(r){let e=[],t=0;for(;t<r.length;){let n=$e(r,t),o=J.getProtocol(n),s=O(n),i=Fi(o,r,t+s),a=0;i>0&&o.size===C&&(a=O(i));let c=s+a+i,u={code:n,name:o.name,bytes:We(r.subarray(t,t+c))};if(i>0){let f=t+s+a,l=r.subarray(f,f+i);u.value=o.bytesToValue?.(l)??ne(l)}e.push(u),t+=c}return e}function to(r){let e=0,t=[];for(let n of r){if(n.bytes==null){let o=J.getProtocol(n.code),s=O(n.code),i,a=0,c=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??te(n.value),a=i.byteLength,o.size===C&&(c=O(a)));let u=new Uint8Array(s+c+a),f=0;Ae(n.code,u,f),f+=s,i!=null&&(o.size===C&&(Ae(a,u,f),f+=c),u.set(i,f)),n.bytes=u}t.push(n.bytes),e+=n.bytes.byteLength}return X(t,e)}function ro(r){if(r.charAt(0)!=="/")throw new S('String multiaddr must start with "/"');let e=[],t="protocol",n="",o="";for(let s=1;s<r.length;s++){let i=r.charAt(s);i!=="/"&&(t==="protocol"?o+=r.charAt(s):n+=r.charAt(s));let a=s===r.length-1;if(i==="/"||a){let c=J.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 S(`Component ${o} was missing value`);t="value"}else if(t==="value"){let u={code:c.code,name:c.name};if(c.size!=null&&c.size!==0){if(n==="")throw new S(`Component ${o} was missing value`);u.value=c.stringToValue?.(n)??n}e.push(u),n="",o="",t="protocol"}}}if(o!==""&&n!=="")throw new S("Incomplete multiaddr");return e}function no(r){return`/${r.flatMap(e=>{if(e.value==null)return e.name;let t=J.getProtocol(e.code);if(t==null)throw new S(`Unknown protocol code ${e.code}`);return[e.name,t.valueToString?.(e.value)??e.value]}).join("/")}`}function Fi(r,e,t){return r.size==null||r.size===0?0:r.size>0?r.size/8:$e(e,t)}var Mi=Symbol.for("nodejs.util.inspect.custom"),_r=Symbol.for("@multiformats/multiaddr");function Ri(r){if(r==null&&(r="/"),oo(r))return r.getComponents();if(r instanceof Uint8Array)return eo(r);if(typeof r=="string")return r=r.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),r===""&&(r="/"),ro(r);if(Array.isArray(r))return r;throw new S("Must be a string, Uint8Array, Component[], or another Multiaddr")}var dt=class r{[_r]=!0;#e;#t;#r;constructor(e="/",t={}){this.#e=Ri(e),t.validate!==!1&&ki(this)}get bytes(){return this.#r==null&&(this.#r=to(this.#e)),this.#r}toString(){return this.#t==null&&(this.#t=no(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 it(`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 Be(this.bytes,e.bytes)}[Mi](){return`Multiaddr(${this.toString()})`}};function ki(r){r.getComponents().forEach(e=>{let t=J.getProtocol(e.code);e.value!=null&&t.validate?.(e.value)})}function oo(r){return!!r?.[_r]}function Nr(r){return new dt(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)}}),so=r=>({match:e=>r.match(e)===!1?e:!1}),d=r=>({match:e=>{let t=r.match(e);return t===!1?e:t}}),L=(...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 zi=h(421),Sl=E(zi),mt=h(54),gt=h(55),bt=h(56),Or=h(53),Al=E(mt,d(h(421))),Dl=E(gt,d(h(421))),Tl=E(bt,d(h(421))),io=E(L(Or,bt,mt,gt),d(h(421))),ao=m(h(4),d(h(43))),co=m(d(h(42)),h(41),d(h(43))),Ur=L(ao,co),Ne=L(Ur,Or,mt,gt,bt),Ll=E(L(Ur,m(L(Or,bt,mt,gt),d(h(421))))),_l=E(ao),Nl=E(co),uo=E(Ur),Br=m(Ne,h(6)),je=m(Ne,h(273)),Pl=E(m(Br,d(h(421)))),Ol=E(je),Fr=m(je,y(460),d(h(421))),xt=m(je,y(461),d(h(421))),Vi=L(Fr,xt),Ul=E(Fr),Bl=E(xt),Pr=L(Ne,Br,je,Fr,xt),lo=L(m(Pr,y(477),d(h(421)))),Fl=E(lo),fo=L(m(Pr,y(478),d(h(421))),m(Pr,y(448),d(h(449)),y(477),d(h(421)))),Ml=E(fo),ho=m(je,y(280),d(h(466)),d(h(466)),d(h(421))),Rl=E(ho),po=m(xt,y(465),d(h(466)),d(h(466)),d(h(421))),kl=E(po),pt=L(lo,fo,m(Br,d(h(421))),m(Vi,d(h(421))),m(Ne,d(h(421))),ho,po,h(421)),zl=E(pt),$i=m(d(pt),y(290),so(y(281)),d(h(421))),qe=E($i),Wi=L(m(pt,y(290),y(281),d(h(421))),m(pt,y(281),d(h(421))),m(y(281),d(h(421)))),Vl=E(Wi),Gi=m(Ne,L(m(h(6,"80")),m(h(6),y(480)),y(480)),d(h(481)),d(h(421))),$l=E(Gi),ji=m(Ne,L(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)),d(h(481)),d(h(421))),Wl=E(ji),qi=L(m(h(777),d(h(421)))),Gl=E(qi),Hi=L(m(h(400),d(h(421)))),jl=E(Hi);var Mr=class r extends Error{name="TimeoutError";constructor(e,t){super(e,t),Error.captureStackTrace?.(this,r)}},Xi=r=>"reason"in r?r.reason:new DOMException("This operation was aborted.","AbortError"),Qi=2**31-1,Yi=(r,e)=>{if(typeof r!="number"||Math.sign(r)!==1)return new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(typeof e?.setTimeout!="function"||typeof e?.clearTimeout!="function")return new TypeError("Expected `customTimers` to have a `setTimeout` and a `clearTimeout` function")};function Rr(r,e){let{milliseconds:t,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout},signal:i}=e,a,c,u=()=>{try{r.cancel?.()}catch{}},l=new Promise((p,x)=>{let K=()=>{x(Xi(i)),u()},j=Yi(t,s);try{j?x(j):i?.aborted?K():i&&(c=K,i.addEventListener("abort",c,{once:!0}))}finally{r.then(p,x)}if(j||i?.aborted||t>Qi)return;let Oe=n||o===!1||o instanceof Error?void 0:new Mr(o??`Promise timed out after ${t} milliseconds`);a=s.setTimeout.call(void 0,()=>{if(n)try{p(n())}catch(w){x(w)}else o===!1?p():x(o instanceof Error?o:Oe);u()},t)}).finally(()=>{try{l.clear()}catch{}try{c&&i.removeEventListener("abort",c)}catch{}});return l.clear=()=>{a!==void 0&&(s.clearTimeout.call(void 0,a),a=void 0)},l}var mo=r=>typeof r=="function"?{filter:r}:{...r},Ji=r=>r===1/0||Number.isSafeInteger(r)&&r>=0,Ki=[["addEventListener","removeEventListener"],["on","off"],["addListener","removeListener"]],Zi=r=>{for(let[e,t]of Ki){let n=r?.[e],o=r?.[t];if(typeof n=="function"&&typeof o=="function")return{addListener:n.bind(r),removeListener:o.bind(r)}}throw new TypeError("Emitter is not compatible")},ea=r=>{let e=new Map;for(let[t,n]of r)for(let o of Array.isArray(t)?t:[t])e.has(o)||e.set(o,n);return e},ta=({addListener:r,removeListener:e,handlers:t,signal:n,abortHandler:o,isDone:s})=>{n?.addEventListener("abort",o,{once:!0});for(let[i,a]of t)if(r(i,a),s()){e(i,a);return}},ra=({removeListener:r,handlers:e,signal:t,abortHandler:n})=>{for(let[o,s]of e)r(o,s);t?.removeEventListener("abort",n)},na=(r,e,t)=>{let n=Promise.resolve();return(o,s)=>{n=n.then(async()=>{if(e())return;let i;try{i=r?await r(o):!0}catch(a){e()||t(a);return}e()||s(i)})}};function oa(r,e,t){let n=()=>{},o=!1,s,i=new Promise((a,c)=>{t=mo(t);let{filter:u}=t;if(!Ji(t.count))throw new TypeError("The `count` option should be at least 0 or more");if(typeof t.timeout=="number"&&!(t.timeout>0))throw new TypeError(`Expected the \`timeout\` option to be a positive number, got \`${t.timeout}\``);t.signal?.throwIfAborted();let{addListener:f,removeListener:l}=Zi(r);if(t.count===0){a([]);return}let p=[],x=I=>{n(),c(I)},K=na(u,()=>o,x),j=I=>{p.push(I),t.count===p.length&&(n(),a(p))},Oe=(...I)=>{if(o)return;let N=t.multiArgs?I:I[0];if(!u){j(N);return}K(N,M=>{M&&j(N)})},w=(...I)=>{x(t.rejectionMultiArgs?I:I[0])},A=()=>{x(t.signal.reason)},V={addListener:f,removeListener:l,handlers:ea([[e,Oe],[t.rejectionEvents??["error"],w]]),signal:t.signal,abortHandler:A,isDone:()=>o};n=()=>{o=!0,clearTimeout(s),ra(V)},ta(V),!(o||!t.resolveImmediately)&&(Number.isFinite(t.timeout)&&t.timeout<=2**31-1&&(s=setTimeout(n,t.timeout)),a(p))});if(i.cancel=n,typeof t.timeout=="number"&&t.timeout>0&&!t.resolveImmediately){let a=Rr(i,{milliseconds:t.timeout});return a.cancel=()=>{n(),a.clear()},a}return i}function go(r,e,t){let n=oa(r,e,{...mo(t),count:1,resolveImmediately:!1}),o=n.then(s=>s[0]);return o.cancel=n.cancel,o}var he=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"};function sa(r){return r.reason}function kr(r,e,t){if(e==null||r==null)return r;let n=t?.translateError??sa;if(e.aborted)return r.catch(()=>{}),Promise.reject(n(e));let o;return Promise.race([r,new Promise((s,i)=>{o=()=>{i(n(e))},e.addEventListener("abort",o)})]).finally(()=>{o!=null&&e.removeEventListener("abort",o)})}var aa=4194304,wt=class extends Error{static name="UnwrappedError";name="UnwrappedError"},Vr=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},$r=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},Wr=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function ca(r){return typeof r?.closeRead=="function"}function ua(r){return typeof r?.close=="function"}function zr(r){return ca(r)?r.remoteWriteStatus!=="writable"&&r.readBufferLength===0:ua(r)?r.status!=="open":!1}function la(r){return r?.addEventListener!=null&&r?.removeEventListener!=null&&r?.send!=null&&r?.push!=null&&r?.log!=null}function fa(r,e){let t=e?.maxBufferSize??aa,n=new ae,o,s=!1,i;if(!la(r))throw new me("Argument should be a Stream or a Multiaddr");let a=l=>{if(!s&&i==null){if(n.append(l.data),n.byteLength>t){let p=n.byteLength;n.consume(p);let x=new Ke(`Read buffer overflow - ${p} > ${t}`);i=x,o?.reject(x),queueMicrotask(()=>{r.abort(x)});return}o?.resolve()}};r.addEventListener("message",a);let c=l=>{l.error!=null?o?.reject(l.error):o?.resolve()};r.addEventListener("close",c);let u=()=>{o?.resolve()};r.addEventListener("remoteCloseWrite",u);let f={readBuffer:n,async read(l){if(s===!0)throw new wt("Stream was unwrapped");if(i!=null)throw i;if(zr(r)){if(n.byteLength===0&&l?.bytes==null)return null;if(l?.bytes!=null&&n.byteLength<l.bytes)throw r.log.error("closed after reading %d/%d bytes",n.byteLength,l.bytes),new he(`Unexpected EOF - stream closed after reading ${n.byteLength}/${l.bytes} bytes`)}let p=l?.bytes??1;for(o=Promise.withResolvers();;){if(n.byteLength>=p){o.resolve();break}if(await kr(o.promise,l?.signal),zr(r)){if(n.byteLength===0&&l?.bytes==null)return null;break}o=Promise.withResolvers()}let x=l?.bytes??n.byteLength;if(n.byteLength<x){if(zr(r))throw r.log.error("closed while reading %d/%d bytes",n.byteLength,x),new he(`Unexpected EOF - stream closed while reading ${n.byteLength}/${x} bytes`);return f.read(l)}let K=n.sublist(0,x);return n.consume(x),K},async write(l,p){if(s===!0)throw new wt("Stream was unwrapped");r.send(l)||await go(r,"drain",{signal:p?.signal,rejectionEvents:["close"]})},unwrap(){return s||(s=!0,r.removeEventListener("message",a),r.removeEventListener("close",c),r.removeEventListener("remoteCloseWrite",u),n.byteLength>0&&(r.log("stream unwrapped with %d unread bytes",n.byteLength),r.unshift(n),n.consume(n.byteLength))),r}};return f}function ha(r,e={}){let t=fa(r,e);e.maxDataLength!=null&&e.maxLengthLength==null&&(e.maxLengthLength=O(e.maxDataLength));let n=e?.lengthDecoder??$e,o=e?.lengthEncoder??Gn;return{async read(i){let a=-1,c=new ae;for(;;){let f=await t.read({...i,bytes:1});if(f==null)break;c.append(f);try{a=n(c)}catch(l){if(l instanceof RangeError)continue;throw l}if(a<0)throw new Vr("Invalid message length");if(e?.maxLengthLength!=null&&c.byteLength>e.maxLengthLength)throw new Wr(`Message length length too long - ${c.byteLength} > ${e.maxLengthLength}`);if(a>-1)break}if(e?.maxDataLength!=null&&a>e.maxDataLength)throw new $r(`Message length too long - ${a} > ${e.maxDataLength}`);let u=await t.read({...i,bytes:a});if(u==null)throw r.log.error("tried to read %d bytes but the stream closed",a),new he(`Unexpected EOF - tried to read ${a} bytes but the stream closed`);if(u.byteLength!==a)throw r.log.error("read %d/%d bytes before the stream closed",u.byteLength,a),new he(`Unexpected EOF - read ${u.byteLength}/${a} bytes before the stream closed`);return u},async write(i,a){await t.write(new ae(o(i.byteLength),i),a)},async writeV(i,a){let c=new ae(...i.flatMap(u=>[o(u.byteLength),u]));await t.write(c,a)},unwrap(){return t.unwrap()}}}function Gr(r,e){let t=ha(r,e),n={read:async(o,s)=>{let i=await t.read(s);return o.decode(i,s)},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 bo=Symbol.for("sindresorhus/unlimited-timeout#brand");function xo(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={[bo]:!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(),u=Math.max(0,s-c);i(u)},2147483647),n&&o.id?.unref?.()))};return i(e),o}function wo(r){!r||typeof r!="object"||!r[bo]||(r.cleared=!0,r.id!==void 0&&(globalThis.clearTimeout(r.id),r.id=void 0))}var da=new WeakMap;function pa({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,u=()=>{c(s),a(o.reason)},f=()=>{o&&o.removeEventListener("abort",u)},l=new Promise((p,x)=>{i=()=>{f(),p(n)},a=x,s=(e??setTimeout)(i,t)});return o&&o.addEventListener("abort",u,{once:!0}),da.set(l,()=>{c(s),s=null,i()}),l}}var ma=pa({setTimeout:xo,clearTimeout:wo}),yo=ma;var jr=new Float32Array([-0]),oe=new Uint8Array(jr.buffer);function Eo(r,e,t){jr[0]=r,e[t]=oe[0],e[t+1]=oe[1],e[t+2]=oe[2],e[t+3]=oe[3]}function vo(r,e){return oe[0]=r[e],oe[1]=r[e+1],oe[2]=r[e+2],oe[3]=r[e+3],jr[0]}var qr=new Float64Array([-0]),_=new Uint8Array(qr.buffer);function Io(r,e,t){qr[0]=r,e[t]=_[0],e[t+1]=_[1],e[t+2]=_[2],e[t+3]=_[3],e[t+4]=_[4],e[t+5]=_[5],e[t+6]=_[6],e[t+7]=_[7]}function Co(r,e){return _[0]=r[e],_[1]=r[e+1],_[2]=r[e+2],_[3]=r[e+3],_[4]=r[e+4],_[5]=r[e+5],_[6]=r[e+6],_[7]=r[e+7],qr[0]}var ga=BigInt(Number.MAX_SAFE_INTEGER),ba=BigInt(Number.MIN_SAFE_INTEGER),F=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 de;if(e<ga&&e>ba)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>So&&(o=0n,++n>So&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(e){if(e===0)return de;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):de}},de=new F(0,0);de.toBigInt=function(){return 0n};de.zzEncode=de.zzDecode=function(){return this};de.length=function(){return 1};var So=4294967296n;function Ao(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 Do(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 Hr(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 k(r,e){return RangeError(`index out of range: ${r.pos} + ${e??1} > ${r.len}`)}function yt(r,e){return(r[e-4]|r[e-3]<<8|r[e-2]<<16|r[e-1]<<24)>>>0}var Xr=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(e){this.buf=We(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,k(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 k(this,4);return yt(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw k(this,4);return yt(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw k(this,4);let e=vo(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw k(this,4);let e=Co(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 k(this,e);return this.pos+=e,t===n?new Uint8Array(0):this.buf.subarray(t,n)}string(){let e=this.bytes();return Do(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw k(this,e);this.pos+=e}else do if(this.pos>=this.len)throw k(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 F(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 k(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 k(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 k(this,8);let e=yt(this.buf,this.pos+=4),t=yt(this.buf,this.pos+=4);return new F(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=ar(this.buf,this.pos);return this.pos+=O(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 He(r){return new Xr(r instanceof Uint8Array?r:r.subarray())}function Qr(r,e,t){let n=He(r);return e.decode(n,void 0,t)}function Yr(r){let e=r??8192,t=e>>>1,n,o=e;return function(i){if(i<1||i>t)return D(i);o+i>e&&(n=D(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 Jr(){}var Zr=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},xa=Yr();function wa(r){return globalThis.Buffer!=null?D(r):xa(r)}var Qe=class{len;head;tail;states;constructor(){this.len=0,this.head=new pe(Jr,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 en((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(Et,10,F.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let t=F.fromBigInt(e);return this._push(Et,t.length(),t)}uint64Number(e){return this._push(Ae,O(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=F.fromBigInt(e).zzEncode();return this._push(Et,t.length(),t)}sint64Number(e){let t=F.fromNumber(e).zzEncode();return this._push(Et,t.length(),t)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(Kr,1,e?1:0)}fixed32(e){return this._push(Xe,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let t=F.fromBigInt(e);return this._push(Xe,4,t.lo)._push(Xe,4,t.hi)}fixed64Number(e){let t=F.fromNumber(e);return this._push(Xe,4,t.lo)._push(Xe,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(Eo,4,e)}double(e){return this._push(Io,8,e)}bytes(e){let t=e.length>>>0;return t===0?this._push(Kr,1,0):this.uint32(t)._push(Ea,t,e)}string(e){let t=Ao(e);return t!==0?this.uint32(t)._push(Hr,t,e):this._push(Kr,1,0)}fork(){return this.states=new Zr(this),this.head=this.tail=new pe(Jr,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(Jr,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=wa(this.len),n=0;for(;e!=null;)e.fn(e.val,t,n),n+=e.len,e=e.next;return t}};function Kr(r,e,t){e[t]=r&255}function ya(r,e,t){for(;r>127;)e[t++]=r&127|128,r>>>=7;e[t]=r}var en=class extends pe{next;constructor(e,t){super(ya,e,t),this.next=void 0}};function Et(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 Xe(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 Ea(r,e,t){e.set(r,t)}globalThis.Buffer!=null&&(Qe.prototype.bytes=function(r){let e=r.length>>>0;return this.uint32(e),e>0&&this._push(va,e,r),this},Qe.prototype.string=function(r){let e=globalThis.Buffer.byteLength(r);return this.uint32(e),e>0&&this._push(Ia,e,r),this});function va(r,e,t){e.set(r,t)}function Ia(r,e,t){r.length<40?Hr(r,e,t):e.utf8Write!=null?e.utf8Write(r,t):e.set(te(r),t)}function tn(){return new Qe}function rn(r,e){let t=tn();return e.encode(r,t,{lengthDelimited:!1}),t.finish()}function*nn(r,e,t){let n=He(r);yield*e.stream(n,void 0,".",t)}var vt={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function It(r,e,t,n,o){return{name:r,type:e,encode:t,decode:n,stream:o}}function on(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,a){};return It("enum",vt.VARINT,t,n,o)}function sn(r,e,t){return It("message",vt.LENGTH_DELIMITED,r,e,t)}var Ye=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var z;(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=()=>on(t)})(e=r.Type||(r.Type={}));let n;r.codec=()=>(n==null&&(n=sn((a,c,u={})=>{if(u.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 f of a.observedAddresses)c.uint32(18),c.bytes(f);u.lengthDelimited!==!1&&c.ldelim()},(a,c,u={})=>{let f={observedAddresses:[]},l=c==null?a.len:a.pos+c;for(;a.pos<l;){let p=a.uint32();switch(p>>>3){case 1:{f.type=r.Type.codec().decode(a);break}case 2:{if(u.limits?.observedAddresses!=null&&f.observedAddresses.length===u.limits.observedAddresses)throw new Ye('Decode error - repeated field "observedAddresses" had too many elements');f.observedAddresses.push(a.bytes());break}default:{a.skipType(p&7);break}}}return f},function*(a,c,u,f={}){let l={observedAddresses:0},p=c==null?a.len:a.pos+c;for(;a.pos<p;){let x=a.uint32();switch(x>>>3){case 1:{yield{field:`${u}.type`,value:r.Type.codec().decode(a)};break}case 2:{if(f.limits?.observedAddresses!=null&&l.observedAddresses===f.limits.observedAddresses)throw new Ye('Streaming decode error - repeated field "observedAddresses" had too many elements');yield{field:`${u}.observedAddresses[]`,index:l.observedAddresses,value:a.bytes()},l.observedAddresses++;break}default:{a.skipType(x&7);break}}}})),n);function o(a){return rn(a,r.codec())}r.encode=o;function s(a,c){return Qr(a,r.codec(),c)}r.decode=s;function i(a,c){return nn(a,r.codec(),c)}r.stream=i})(z||(z={}));function an(r,e){return qe.matches(r)||e.dialTransportForMultiaddr(r)==null?!1:io.matches(r)?!0:uo.matches(r)?!Wn(r):!1}var Lo=1024*4,_o=100,Ct={timeout:5e3,retries:3,maxInboundStreams:1,maxOutboundStreams:1},St=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??Ct.timeout,this.retries=t.retries??Ct.retries,this.maxInboundStreams=t.maxInboundStreams??Ct.maxInboundStreams,this.maxOutboundStreams=t.maxOutboundStreams??Ct.maxOutboundStreams,this.handleIncomingUpgrade=this.handleIncomingUpgrade.bind(this)}[Symbol.toStringTag]="@libp2p/dcutr";[un]=["@libp2p/identify"];isStarted(){return this.started}async start(){this.started||(this.topologyId=await this.registrar.register(Pe,{notifyOnLimitedConnection:!0,onConnect:(e,t)=>{qe.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(Pe,this.handleIncomingUpgrade,{maxInboundStreams:this.maxInboundStreams,maxOutboundStreams:this.maxOutboundStreams,runOnLimitedConnection:!0}),this.started=!0)}async stop(){await this.registrar.unhandle(Pe),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([Pe],{signal:o.signal,runOnLimitedConnection:!0});let s=Gr(t,{maxDataLength:Lo}).pb(z);this.log("B sending connect to %p",e.remotePeer);let i=Date.now();await s.write({type:z.Type.CONNECT,observedAddresses:this.addressManager.getAddresses().map(l=>l.bytes)},o),this.log("B receiving connect from %p",e.remotePeer);let a=await s.read(o);if(a.type!==z.Type.CONNECT)throw this.log("A sent wrong message type"),new H("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 H("DCUtR connect message had no multiaddrs");let u=Date.now()-i;this.log("A sending sync, rtt %dms",u),await s.write({type:z.Type.SYNC,observedAddresses:[]},o),this.log("A waiting for half RTT"),await yo(u/2),this.log("B dialing",c);let f=await this.connectionManager.openConnection(c,{signal:o.signal,priority:_o,force:!0,initiator:!1});this.log("DCUtR to %p succeeded to address %a, closing relayed connection",e.remotePeer,f.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=>an(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(qe.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=Gr(e,{maxDataLength:Lo}).pb(z);this.log("A receiving connect");let s=await o.read(n);if(s.type!==z.Type.CONNECT)throw this.log("B sent wrong message type"),new H("DCUtR message type was incorrect");if(s.observedAddresses.length===0)throw this.log("B sent no multiaddrs"),new H("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(u=>Nr(u))),new H("DCUtR connect message had no dialable multiaddrs");if(this.log("A sending connect"),await o.write({type:z.Type.CONNECT,observedAddresses:this.addressManager.getAddresses().map(u=>u.bytes)}),this.log("A receiving sync"),(await o.read(n)).type!==z.Type.SYNC)throw new H("DCUtR message type was incorrect");this.log("A dialing",i);let c=await this.connectionManager.openConnection(i,{signal:n.signal,priority:_o,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=Nr(n);if(!an(o,this.transportManager))continue;t.push(o)}catch{}return t}};var Pe="/libp2p/dcutr";function Ca(r={}){return e=>new St(e,r)}return Ro(Sa);})();
|
|
2
|
+
"use strict";var Libp2PDcutr=(()=>{var Dt=Object.defineProperty;var Lo=Object.getOwnPropertyDescriptor;var Po=Object.getOwnPropertyNames;var No=Object.prototype.hasOwnProperty;var R=(r,e)=>{for(var t in e)Dt(r,t,{get:e[t],enumerable:!0})},_o=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Po(e))!No.call(r,o)&&o!==t&&Dt(r,o,{get:()=>e[o],enumerable:!(n=Lo(e,o))||n.enumerable});return r};var Oo=r=>_o(Dt({},"__esModule",{value:!0}),r);var aa={};R(aa,{dcutr:()=>sa,multicodec:()=>Ne});var me=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}};var Je=class extends Error{static name="StreamBufferError";constructor(e="The stream buffer was full"){super(e),this.name="StreamBufferError"}};var H=class extends Error{static name="InvalidMessageError";constructor(e="Invalid message"){super(e),this.name="InvalidMessageError"}};var sn=Symbol.for("@libp2p/service-dependencies");function $(r=0){return new Uint8Array(r)}function T(r=0){return new Uint8Array(r)}function Uo(r){return r?.buffer instanceof ArrayBuffer}function Tt(r){if(Uo(r))return r;let e=r.slice();return new Uint8Array(e.buffer,0,e.byteLength)}function j(r,e){e==null&&(e=r.reduce((o,i)=>o+i.length,0));let t=T(e),n=0;for(let o of r)t.set(o,n),n+=o.length;return Tt(t)}function Ue(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 cn=Symbol.for("@achingbrain/uint8arraylist");function an(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 Ze(r){return!!r?.[cn]}var se=class r{bufs;length;[cn]=!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(Ze(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(Ze(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=an(this.bufs,e);return t.buf[t.index]}set(e,t){let n=an(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(Ze(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 j(n,o)}subarray(e,t){let{bufs:n,length:o}=this._subList(e,t);return n.length===1?n[0]:j(n,o)}sublist(e,t){let{bufs:n,length:o}=this._subList(e,t),i=new r;return i.length=o,i.bufs=n,i}_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 i=0;i<this.bufs.length;i++){let s=this.bufs[i],a=o,c=a+s.byteLength;if(o=c,e>=c)continue;let u=e>=a&&e<c,f=t>a&&t<=c;if(u&&f){if(e===a&&t===c){n.push(s);break}let l=e-a;n.push(s.subarray(l,l+(t-e)));break}if(u){if(e===0){n.push(s);continue}n.push(s.subarray(e-a));continue}if(f){if(t===c){n.push(s);break}n.push(s.subarray(0,t-a));break}n.push(s)}return{bufs:n,length:t-e}}indexOf(e,t=0){if(!Ze(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 i=256,s=new Int32Array(i);for(let l=0;l<i;l++)s[l]=-1;for(let l=0;l<o;l++)s[n[l]]=l;let a=s,c=this.byteLength-n.byteLength,u=n.byteLength-1,f;for(let l=t;l<=c;l+=f){f=0;for(let p=u;p>=0;p--){let x=this.get(l+p);if(n[p]!==x){f=Math.max(1,p-a[x]);break}}if(f===0)return l}return-1}getInt8(e){let t=this.subarray(e,e+1);return new DataView(t.buffer,t.byteOffset,t.byteLength).getInt8(0)}setInt8(e,t){let n=T(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=$(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=$(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=$(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=T(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=$(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=$(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=$(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=$(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=$(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(!Ue(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,i)=>o+i.byteLength,0)),n.length=t,n}};var _t={};R(_t,{base10:()=>$o});var qa=new Uint8Array(0);function ln(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 F(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return ae(r);if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return ae(new Uint8Array(r.buffer,r.byteOffset,r.byteLength));throw new Error("Unknown type, must be binary type")}function fn(r){let e=new Uint8Array(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}var un=4096;function hn(r){let e=r.length;if(e<=un)return String.fromCharCode.apply(String,r);let t="",n=0;for(;n<e;)t+=String.fromCharCode.apply(String,r.subarray(n,n+=un));return t}function Ro(r){return r?.buffer instanceof ArrayBuffer}function ae(r){return Ro(r)?r:r.slice()}function Bo(r,e,t){if(r.length>=255)throw new TypeError("Alphabet too long");for(var n=new Uint8Array(256),o=0;o<n.length;o++)n[o]=255;for(var i=0;i<r.length;i++){var s=r.charAt(i),a=s.charCodeAt(0);if(n[a]!==255)throw new TypeError(s+" is ambiguous");if(n[a]=i,t){var c=s.toLowerCase().charCodeAt(0),u=s.toUpperCase().charCodeAt(0);c!==a&&(n[c]=i),u!==a&&(n[u]=i)}}var f=r.length,l=r.charAt(0),p=Math.log(f)/Math.log(256),x=Math.log(256)/Math.log(f);function J(w){if(w instanceof Uint8Array||(ArrayBuffer.isView(w)?w=new Uint8Array(w.buffer,w.byteOffset,w.byteLength):Array.isArray(w)&&(w=Uint8Array.from(w))),!(w instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(w.length===0)return"";for(var D=0,z=0,I=0,N=w.length;I!==N&&w[I]===0;)I++,D++;for(var M=(N-I)*x+1>>>0,oe=new Uint8Array(M);I!==N;){for(var _=w[I],ie=0,q=M-1;(_!==0||ie<z)&&q!==-1;q--,ie++)_+=256*oe[q]>>>0,oe[q]=_%f>>>0,_=_/f>>>0;if(_!==0)throw new Error("Non-zero carry");z=ie,I++}for(var U=M-z;U!==M&&oe[U]===0;)U++;for(var Oe=l.repeat(D);U<M;++U)Oe+=r.charAt(oe[U]);return Oe}function G(w){if(typeof w!="string")throw new TypeError("Expected String");if(w.length===0)return new Uint8Array;var D=0;if(w[D]!==" "){for(var z=0,I=0;w[D]===l;)z++,D++;for(var N=(w.length-D)*p+1>>>0,M=new Uint8Array(N);w[D];){var oe=w.charCodeAt(D);if(oe>255)return;var _=n[oe];if(_===255)return;for(var ie=0,q=N-1;(_!==0||ie<I)&&q!==-1;q--,ie++)_+=f*M[q]>>>0,M[q]=_%256>>>0,_=_/256>>>0;if(_!==0)throw new Error("Non-zero carry");I=ie,D++}if(w[D]!==" "){for(var U=N-I;U!==N&&M[U]===0;)U++;for(var Oe=new Uint8Array(z+(N-U)),Ao=z;U!==N;)Oe[Ao++]=M[U++];return Oe}}}function _e(w){var D=G(w);if(D)return D;throw new Error(`Non-${e} character`)}return{encode:J,decodeUnsafe:G,decode:_e}}var Mo=Bo,Fo=Mo,pn=Fo;var At=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")}},Lt=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 mn(this,e)}},Pt=class{decoders;constructor(e){this.decoders=e}or(e){return mn(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 mn(r,e){return new Pt({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var Nt=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 At(e,t,n),this.decoder=new Lt(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function ge({name:r,prefix:e,encode:t,decode:n}){return new Nt(r,e,t,n)}function Z({name:r,prefix:e,alphabet:t,caseInsensitive:n=!1}){let{encode:o,decode:i}=pn(t,r,n);return ge({prefix:e,name:r,encode:o,decode:s=>F(i(s))})}function ko(r,e,t,n){let o=r.length;for(;r[o-1]==="=";)--o;let i=new Uint8Array(o*t/8|0),s=0,a=0,c=0;for(let u=0;u<o;++u){let f=e[r[u]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<t|f,s+=t,s>=8&&(s-=8,i[c++]=255&a>>s)}if(s>=t||(255&a<<8-s)!==0)throw new SyntaxError("Unexpected end of data");return i}function Vo(r,e,t){let n=e[e.length-1]==="=",o=(1<<t)-1,i="",s=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],s+=8;s>t;)s-=t,i+=e[o&a>>s];if(s!==0&&(i+=e[o&a<<t-s]),n)for(;(i.length*t&7)!==0;)i+="=";return i}function zo(r,e){let t={};for(let n=0;n<r.length;++n)if(t[r[n]]=n,e){let o=r[n].toLowerCase(),i=r[n].toUpperCase();o!==r[n]&&(t[o]=n),i!==r[n]&&(t[i]=n)}return t}function v({name:r,prefix:e,bitsPerChar:t,alphabet:n,caseInsensitive:o=!1}){let i=zo(n,o);return ge({prefix:e,name:r,encode(s){return Vo(s,n,t)},decode(s){return ko(s,i,t,r)}})}var $o=Z({prefix:"9",name:"base10",alphabet:"0123456789"});var Ot={};R(Ot,{base16:()=>Wo,base16upper:()=>Go});var Wo=v({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4,caseInsensitive:!0}),Go=v({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4,caseInsensitive:!0});var Ut={};R(Ut,{base2:()=>qo});var qo=v({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Rt={};R(Rt,{base256emoji:()=>Yo});var gn=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}"),Ho=gn.reduce((r,e,t)=>(r[t]=e,r),[]),jo=gn.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+=Ho[t],e),"")}function Qo(r){let e=[];for(let t of r){let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);let o=jo[n];if(o==null)throw new Error(`Non-base256emoji character: ${t}`);e.push(o)}return new Uint8Array(e)}var Yo=ge({prefix:"\u{1F680}",name:"base256emoji",encode:Xo,decode:Qo});var Bt={};R(Bt,{base32:()=>K,base32hex:()=>ei,base32hexpad:()=>ri,base32hexpadupper:()=>ni,base32hexupper:()=>ti,base32pad:()=>Zo,base32padupper:()=>Ko,base32upper:()=>Jo,base32z:()=>oi});var K=v({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5,caseInsensitive:!0}),Jo=v({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5,caseInsensitive:!0}),Zo=v({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5,caseInsensitive:!0}),Ko=v({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5,caseInsensitive:!0}),ei=v({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5,caseInsensitive:!0}),ti=v({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5,caseInsensitive:!0}),ri=v({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5,caseInsensitive:!0}),ni=v({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5,caseInsensitive:!0}),oi=v({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Mt={};R(Mt,{base36:()=>Re,base36upper:()=>ii});var Re=Z({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz",caseInsensitive:!0}),ii=Z({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",caseInsensitive:!0});var Ft={};R(Ft,{base58btc:()=>W,base58flickr:()=>si});var W=Z({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),si=Z({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Vt={};R(Vt,{base64:()=>ai,base64pad:()=>ci,base64url:()=>kt,base64urlpad:()=>ui});var ai=v({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),ci=v({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),kt=v({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),ui=v({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var zt={};R(zt,{base8:()=>li});var li=v({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var $t={};R($t,{identity:()=>fi});var fi=ge({prefix:"\0",name:"identity",encode:r=>hn(F(r)),decode:r=>F(fn(r))});var ac=new TextEncoder,cc=new TextDecoder;var Gt={};R(Gt,{identity:()=>Ui});var pi=wn,bn=128,mi=127,gi=~mi,bi=Math.pow(2,31);function wn(r,e,t){e=e||[],t=t||0;for(var n=t;r>=bi;)e[t++]=r&255|bn,r/=128;for(;r&gi;)e[t++]=r&255|bn,r>>>=7;return e[t]=r|0,wn.bytes=t-n+1,e}var xi=Wt,wi=128,xn=127;function Wt(r,n){var t=0,n=n||0,o=0,i=n,s,a=r.length;do{if(i>=a)throw Wt.bytes=0,new RangeError("Could not decode varint");s=r[i++],t+=o<28?(s&xn)<<o:(s&xn)*Math.pow(2,o),o+=7}while(s>=wi);return Wt.bytes=i-n,t}var yi=Math.pow(2,7),Ei=Math.pow(2,14),vi=Math.pow(2,21),Ii=Math.pow(2,28),Ci=Math.pow(2,35),Si=Math.pow(2,42),Di=Math.pow(2,49),Ti=Math.pow(2,56),Ai=Math.pow(2,63),Li=function(r){return r<yi?1:r<Ei?2:r<vi?3:r<Ii?4:r<Ci?5:r<Si?6:r<Di?7:r<Ti?8:r<Ai?9:10},Pi={encode:pi,decode:xi,encodingLength:Li},Ni=Pi,Be=Ni;function Me(r,e=0){let t=Be.decode(r,e),n=Be.decode.bytes;if(n>9)throw new RangeError("Invalid varint: too long");if(n>1&&r[e+n-1]===0)throw new RangeError("Invalid varint: not minimally encoded");return[t,n]}function be(r,e,t=0){return Be.encode(r,e,t),e}function xe(r){return Be.encodingLength(r)}function ye(r,e){let t=e.byteLength,n=xe(r),o=n+xe(t),i=new Uint8Array(o+t);return be(r,i,0),be(t,i,n),i.set(e,o),new we(r,t,e,i)}function yn(r){let e=F(r),[t,n]=Me(e),[o,i]=Me(e.subarray(n)),s=e.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new we(t,o,s,e)}function En(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&ln(r.bytes,t.bytes)}}var we=class{code;size;digest;bytes;constructor(e,t,n,o){this.code=e,this.size=t,this.digest=ae(n),this.bytes=ae(o)}};var vn=0,_i="identity",In=F;function Oi(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 ye(vn,In(r))}var Ui={code:vn,name:_i,encode:In,digest:Oi};var jt={};R(jt,{sha256:()=>Bi,sha512:()=>Mi});var Ri=20;function Ht({name:r,code:e,encode:t,minDigestLength:n,maxDigestLength:o}){return new qt(r,e,t,n,o)}var qt=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,t,n,o,i){this.name=e,this.code=t,this.encode=n,this.minDigestLength=o??Ri,this.maxDigestLength=i}digest(e,t){if(t?.truncate!=null){if(t.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&t.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(e instanceof Uint8Array){let n=this.encode(e);return n instanceof Uint8Array?Cn(n,this.code,t?.truncate):n.then(o=>Cn(o,this.code,t?.truncate))}else throw Error("Unknown type, must be binary type")}};function Cn(r,e,t){if(t!=null&&t!==r.byteLength){if(t>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,t)}return ye(e,r)}function Dn(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var Bi=Ht({name:"sha2-256",code:18,encode:Dn("SHA-256")}),Mi=Ht({name:"sha2-512",code:19,encode:Dn("SHA-512")});function Tn(r,e){let{bytes:t,version:n}=r;return n===0?ki(t,Xt(r),e??W.encoder):Vi(t,Xt(r),e??K.encoder)}var An=new WeakMap;function Xt(r){let e=An.get(r);if(e==null){let t=new Map;return An.set(r,t),t}return e}var Ee=class r{code;version;multihash;bytes;"/";constructor(e,t,n,o){this.code=t,this.version=e,this.multihash=n,this.bytes=ae(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!==ke)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=ye(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&&En(e.multihash,n.multihash)}toString(e){return Tn(this,e)}toJSON(){return{"/":Tn(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:i,bytes:s}=t;return new r(n,o,i,s??Ln(n,o,i.bytes))}else if(t[$i]===!0){let{version:n,multihash:o,code:i}=t,s=yn(o);return r.create(n,i,s)}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!==ke)throw new Error(`Version 0 CID must use dag-pb (code: ${ke}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let o=Ln(e,t,n.bytes);return new r(e,t,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,ke,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=F(e.subarray(n,n+t.multihashSize));if(o.byteLength!==t.multihashSize)throw new Error("Incorrect length");let i=o.subarray(t.multihashSize-t.digestSize),s=new we(t.multihashCode,t.digestSize,i,o);return[t.version===0?r.createV0(s):r.createV1(t.codec,s),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[l,p]=Me(e.subarray(t));return t+=p,l},o=n(),i=ke;if(o===18)o=0,t=0;else if(o===1)i=n();else throw o===0?new RangeError("Invalid CID version, v0 is always implicit"):new RangeError(`Invalid CID version ${o}`);let s=t,a=n(),c=n(),u=t+c,f=u-s;return{version:o,codec:i,multihashCode:a,digestSize:c,multihashSize:f,size:u}}static parse(e,t){let[n,o]=Fi(e,t),i=r.decode(o);if(i.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Xt(i).set(n,e),i}};function Fi(r,e){switch(r[0]){case"Q":{let t=e??W;return[W.prefix,t.decode(`${W.prefix}${r}`)]}case W.prefix:{let t=e??W;return[W.prefix,t.decode(r)]}case K.prefix:{let t=e??K;return[K.prefix,t.decode(r)]}case Re.prefix:{let t=e??Re;return[Re.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 ki(r,e,t){let{prefix:n}=t;if(n!==W.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let o=e.get(n);if(o==null){let i=t.encode(r).slice(1);return e.set(n,i),i}else return o}function Vi(r,e,t){let{prefix:n}=t,o=e.get(n);if(o==null){let i=t.encode(r);return e.set(n,i),i}else return o}var ke=112,zi=18;function Ln(r,e,t){let n=xe(r),o=n+xe(e),i=new Uint8Array(o+t.byteLength);return be(r,i,0),be(e,i,n),i.set(t,o),i}var $i=Symbol.for("@ipld/js-cid/CID");var Ve={...$t,...Ut,...zt,..._t,...Ot,...Bt,...Mt,...Ft,...Vt,...Rt},Pc={...jt,...Gt};function Nn(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var Pn=Nn("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Qt=Nn("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=T(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),Wi={utf8:Pn,"utf-8":Pn,hex:Ve.base16,latin1:Qt,ascii:Qt,binary:Qt,...Ve},et=Wi;function ee(r,e="utf8"){let t=et[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.decoder.decode(`${t.prefix}${r}`)}function Gi(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 _n(r){let e=Gi(r);if(e==null)throw new me(`Multiaddr ${r} was not an IPv4, IPv6, DNS, DNS4, DNS6 or DNSADDR address`);return e}var tt=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 i=0,s=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",u=2**(8*o)-1;for(;;){let f=this.readAtomically(()=>{let l=this.readChar();if(l===void 0)return;let p=Number.parseInt(l,e);if(!Number.isNaN(p))return p});if(f===void 0)break;if(i*=e,i+=f,i>u||(s+=1,t!==void 0&&s>t))return}if(s!==0)return!n&&c&&s>1?void 0:i})}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 s=this.readSeparator(":",n,()=>this.readIPv4Addr());if(s!==void 0)return t[o]=s[0],t[o+1]=s[1],t[o+2]=s[2],t[o+3]=s[3],[o+4,!0]}let i=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(i===void 0)return[o,!1];t[o]=i>>8,t[o+1]=i&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 i=new Uint8Array(14),s=16-(n+2),[a]=e(i.subarray(0,s));return t.set(i.subarray(0,a),16-a),t})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var On=45,qi=15,ve=new tt;function rt(r){if(!(r.length>qi))return ve.new(r).parseWith(()=>ve.readIPv4Addr())}function nt(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>On))return ve.new(r).parseWith(()=>ve.readIPv6Addr())}function te(r,e=!1){if(r.includes("%")&&(r=r.split("%")[0]),r.length>On)return;let t=ve.new(r).parseWith(()=>ve.readIPAddr());if(t)return e&&t.length===4?Uint8Array.from([0,0,0,0,0,0,0,0,0,0,255,255,t[0],t[1],t[2],t[3]]):t}function Un(r,e,t){let n=0;for(let o of r)if(!(n<e)){if(n>t)break;if(o!==255)return!1;n++}return!0}function Yt(r,e,t,n){let o=0;for(let i of r)if(!(o<t)){if(o>n)break;if(i!==e[o])return!1;o++}return!0}function Jt(r){switch(r.length){case ce:return r.join(".");case ue:{let e=[];for(let t=0;t<r.length;t++)t%2===0&&e.push(r[t].toString(16).padStart(2,"0")+r[t+1].toString(16).padStart(2,"0"));return e.join(":")}default:throw new Error("Invalid ip length")}}function Rn(r){let e=0;for(let[t,n]of r.entries()){if(n===255){e+=8;continue}for(;(n&128)!=0;)e++,n=n<<1;if((n&128)!=0)return-1;for(let o=t+1;o<r.length;o++)if(r[o]!=0)return-1;break}return e}function Bn(r){let e="0x";for(let t of r)e+=(t>>4).toString(16)+(t&15).toString(16);return e}var ce=4,ue=16,Hc=parseInt("0xFFFF",16),Mn=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function ze(r,e){e.length===ue&&r.length===ce&&Un(e,0,11)&&(e=e.slice(12)),e.length===ce&&r.length===ue&&Yt(r,Mn,0,11)&&(r=r.slice(12));let t=r.length;if(t!=e.length)throw new Error("Failed to mask ip");let n=new Uint8Array(t);for(let o=0;o<t;o++)n[o]=r[o]&e[o];return n}function Fn(r,e){if(typeof e=="string"&&(e=te(e)),e==null)throw new Error("Invalid ip");if(e.length!==r.network.length)return!1;for(let t=0;t<e.length;t++)if((r.network[t]&r.mask[t])!==(e[t]&r.mask[t]))return!1;return!0}function Zt(r){if(!ot(r))throw new Error("Must have 0xffff prefix");return r.slice(12)}function ot(r){return Yt(r,Mn,0,11)}function Kt(r){let[e,t]=r.split("/");if(!e||!t)throw new Error("Failed to parse given CIDR: "+r);let n=ce,o=rt(e);if(o==null&&(n=ue,o=nt(e),o==null))throw new Error("Failed to parse given CIDR: "+r);let i=parseInt(t,10);if(Number.isNaN(i)||String(i).length!==t.length||i<0||i>n*8)throw new Error("Failed to parse given CIDR: "+r);let s=er(i,8*n);return{network:ze(o,s),mask:s}}function er(r,e){if(e!==8*ce&&e!==8*ue)throw new Error("Invalid CIDR mask");if(r<0||r>e)throw new Error("Invalid CIDR mask");let t=e/8,n=new Uint8Array(t);for(let o=0;o<t;o++){if(r>=8){n[o]=255,r-=8;continue}n[o]=255-(255>>r),r=0}return n}var Ie=class{constructor(e,t){if(t==null)({network:this.network,mask:this.mask}=Kt(e));else{let n=te(e);if(n==null)throw new Error("Failed to parse network");t=String(t);let o=parseInt(t,10);if(Number.isNaN(o)||String(o).length!==t.length||o<0||o>n.length*8){let i=te(t);if(i==null)throw new Error("Failed to parse mask");this.mask=i}else this.mask=er(o,8*n.length);this.network=ze(n,this.mask)}}contains(e){return Fn({network:this.network,mask:this.mask},e)}toString(){let e=Rn(this.mask),t=e!==-1?String(e):Bn(this.mask);return Jt(this.network)+"/"+t}};function Ce(r){return!!rt(r)}function it(r){return!!nt(r)}var Hi=["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","::/128","::1/128","64:ff9b::/96","100::/64","2001::/32","2001:20::/28","2001:db8::/32","2002::/16","fc00::/7","fe80::/10","ff00::/8"].map(r=>new Ie(r));function kn(r){if(!Ce(r)&&!it(r))return;let e=te(r);if(e==null)return;let t=e.length===16&&ot(e)?Zt(e):e;return Hi.some(n=>n.contains(t))}function Vn(r){try{let e=_n(r);switch(e.type){case"ip4":case"ip6":return kn(e.host)??!1;default:return e.host==="localhost"}}catch{return!1}}var ji=Math.pow(2,7),Xi=Math.pow(2,14),Qi=Math.pow(2,21),tr=Math.pow(2,28),rr=Math.pow(2,35),nr=Math.pow(2,42),or=Math.pow(2,49),g=128,A=127;function O(r){if(r<ji)return 1;if(r<Xi)return 2;if(r<Qi)return 3;if(r<tr)return 4;if(r<rr)return 5;if(r<nr)return 6;if(r<or)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Se(r,e,t=0){switch(O(r)){case 8:e[t++]=r&255|g,r/=128;case 7:e[t++]=r&255|g,r/=128;case 6:e[t++]=r&255|g,r/=128;case 5:e[t++]=r&255|g,r/=128;case 4:e[t++]=r&255|g,r>>>=7;case 3:e[t++]=r&255|g,r>>>=7;case 2:e[t++]=r&255|g,r>>>=7;case 1:{e[t++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return e}function Yi(r,e,t=0){switch(O(r)){case 8:e.set(t++,r&255|g),r/=128;case 7:e.set(t++,r&255|g),r/=128;case 6:e.set(t++,r&255|g),r/=128;case 5:e.set(t++,r&255|g),r/=128;case 4:e.set(t++,r&255|g),r>>>=7;case 3:e.set(t++,r&255|g),r>>>=7;case 2:e.set(t++,r&255|g),r>>>=7;case 1:{e.set(t++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return e}function ir(r,e){let t=r[e],n=0;if(n+=t&A,t<g||(t=r[e+1],n+=(t&A)<<7,t<g)||(t=r[e+2],n+=(t&A)<<14,t<g)||(t=r[e+3],n+=(t&A)<<21,t<g)||(t=r[e+4],n+=(t&A)*tr,t<g)||(t=r[e+5],n+=(t&A)*rr,t<g)||(t=r[e+6],n+=(t&A)*nr,t<g)||(t=r[e+7],n+=(t&A)*or,t<g))return n;throw new RangeError("Could not decode varint")}function Ji(r,e){let t=r.get(e),n=0;if(n+=t&A,t<g||(t=r.get(e+1),n+=(t&A)<<7,t<g)||(t=r.get(e+2),n+=(t&A)<<14,t<g)||(t=r.get(e+3),n+=(t&A)<<21,t<g)||(t=r.get(e+4),n+=(t&A)*tr,t<g)||(t=r.get(e+5),n+=(t&A)*rr,t<g)||(t=r.get(e+6),n+=(t&A)*nr,t<g)||(t=r.get(e+7),n+=(t&A)*or,t<g))return n;throw new RangeError("Could not decode varint")}function zn(r,e,t=0){return e==null&&(e=T(O(r))),e instanceof Uint8Array?Se(r,e,t):Yi(r,e,t)}function $e(r,e=0){return r instanceof Uint8Array?ir(r,e):Ji(r,e)}function Zi(r){return r.buffer instanceof ArrayBuffer}function We(r){return Zi(r)?r:r.slice()}function re(r,e="utf8"){let t=et[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.encoder.encode(r).substring(1)}var S=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},X=class extends Error{static name="ValidationError";name="ValidationError"},st=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},at=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};function ar(r){return e=>re(e,r)}function cr(r){return e=>ee(e,r)}function De(r){return new DataView(r.buffer).getUint16(r.byteOffset).toString()}function le(r){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,typeof r=="string"?parseInt(r):r),new Uint8Array(e)}function Wn(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=le(n);return j([t,o],t.length+o.length)}function Gn(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=K.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=le(n);return j([t,o],t.length+o.length)}function ur(r){let e=r.subarray(0,r.length-2),t=r.subarray(r.length-2),n=re(e,"base32"),o=De(t);return`${n}:${o}`}var lr=function(r){r=r.toString().trim();let e=new Uint8Array(4);return r.split(/\./g).forEach((t,n)=>{let o=parseInt(t,10);if(isNaN(o)||o<0||o>255)throw new S("Invalid byte value in IP address");e[n]=o}),e},qn=function(r){let e=0;r=r.toString().trim();let t=r.split(":",8),n;for(n=0;n<t.length;n++){let i=Ce(t[n]),s;i&&(s=lr(t[n]),t[n]=re(s.subarray(0,2),"base16")),s!=null&&++n<8&&t.splice(n,0,re(s.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 i=[n,1];for(n=9-t.length;n>0;n--)i.push("0");t.splice.apply(t,i)}let o=new Uint8Array(e+16);for(n=0;n<t.length;n++){t[n]===""&&(t[n]="0");let i=parseInt(t[n],16);if(isNaN(i)||i<0||i>65535)throw new S("Invalid byte value in IP address");o[e++]=i>>8&255,o[e++]=i&255}return o},Hn=function(r){if(r.byteLength!==4)throw new S("IPv4 address was incorrect length");let e=[];for(let t=0;t<r.byteLength;t++)e.push(r[t]);return e.join(".")},jn=function(r){if(r.byteLength!==16)throw new S("IPv6 address was incorrect length");let e=[];for(let n=0;n<r.byteLength;n+=2){let o=r[n],i=r[n+1],s=`${o.toString(16).padStart(2,"0")}${i.toString(16).padStart(2,"0")}`;e.push(s)}let t=e.join(":");try{let n=new URL(`http://[${t}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new S(`Invalid IPv6 address "${t}"`)}};function Xn(r){try{let e=new URL(`http://[${r}]`);return e.hostname.substring(1,e.hostname.length-1)}catch{throw new S(`Invalid IPv6 address "${r}"`)}}var sr=Object.values(Ve).map(r=>r.decoder),Ki=(function(){let r=sr[0].or(sr[1]);return sr.slice(2).forEach(e=>r=r.or(e)),r})();function Qn(r){return Ki.decode(r)}function Yn(r){return e=>r.encoder.encode(e)}function es(r){if(parseInt(r).toString()!==r)throw new X("Value must be an integer")}function ts(r){if(r<0)throw new X("Value must be a positive integer, or zero")}function rs(r){return e=>{if(e>r)throw new X(`Value must be smaller than or equal to ${r}`)}}function ns(...r){return e=>{for(let t of r)t(e)}}var Ge=ns(es,ts,rs(65535));var C=-1,fr=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)}))}},Y=new fr,bs=[{code:4,name:"ip4",size:32,valueToBytes:lr,bytesToValue:Hn,validate:r=>{if(!Ce(r))throw new X(`Invalid IPv4 address "${r}"`)}},{code:6,name:"tcp",size:16,valueToBytes:le,bytesToValue:De,validate:Ge},{code:273,name:"udp",size:16,valueToBytes:le,bytesToValue:De,validate:Ge},{code:33,name:"dccp",size:16,valueToBytes:le,bytesToValue:De,validate:Ge},{code:41,name:"ip6",size:128,valueToBytes:qn,bytesToValue:jn,stringToValue:Xn,validate:r=>{if(!it(r))throw new X(`Invalid IPv6 address "${r}"`)}},{code:42,name:"ip6zone",size:C},{code:43,name:"ipcidr",size:8,bytesToValue:ar("base10"),valueToBytes:cr("base10")},{code:53,name:"dns",size:C},{code:54,name:"dns4",size:C},{code:55,name:"dns6",size:C},{code:56,name:"dnsaddr",size:C},{code:132,name:"sctp",size:16,valueToBytes:le,bytesToValue:De,validate:Ge},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:C,stringToValue:r=>decodeURIComponent(r),valueToString:r=>encodeURIComponent(r)},{code:421,name:"p2p",aliases:["ipfs"],size:C,bytesToValue:ar("base58btc"),valueToBytes:r=>r.startsWith("Q")||r.startsWith("1")?cr("base58btc")(r):Ee.parse(r).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:ur,valueToBytes:Wn},{code:445,name:"onion3",size:296,bytesToValue:ur,valueToBytes:Gn},{code:446,name:"garlic64",size:C},{code:447,name:"garlic32",size:C},{code:448,name:"tls"},{code:449,name:"sni",size:C},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:C,bytesToValue:Yn(kt),valueToBytes:Qn},{code:480,name:"http"},{code:481,name:"http-path",size:C,stringToValue:r=>`/${decodeURIComponent(r)}`,valueToString:r=>encodeURIComponent(r.substring(1))},{code:443,name:"https"},{code:477,name:"ws"},{code:478,name:"wss"},{code:479,name:"p2p-websocket-star"},{code:277,name:"p2p-stardust"},{code:275,name:"p2p-webrtc-star"},{code:276,name:"p2p-webrtc-direct"},{code:280,name:"webrtc-direct"},{code:281,name:"webrtc"},{code:290,name:"p2p-circuit"},{code:777,name:"memory",size:C}];bs.forEach(r=>{Y.addProtocol(r)});function Jn(r){let e=[],t=0;for(;t<r.length;){let n=$e(r,t),o=Y.getProtocol(n),i=O(n),s=xs(o,r,t+i),a=0;s>0&&o.size===C&&(a=O(s));let c=i+a+s,u={code:n,name:o.name,bytes:We(r.subarray(t,t+c))};if(s>0){let f=t+i+a,l=r.subarray(f,f+s);u.value=o.bytesToValue?.(l)??re(l)}e.push(u),t+=c}return e}function Zn(r){let e=0,t=[];for(let n of r){if(n.bytes==null){let o=Y.getProtocol(n.code),i=O(n.code),s,a=0,c=0;n.value!=null&&(s=o.valueToBytes?.(n.value)??ee(n.value),a=s.byteLength,o.size===C&&(c=O(a)));let u=new Uint8Array(i+c+a),f=0;Se(n.code,u,f),f+=i,s!=null&&(o.size===C&&(Se(a,u,f),f+=c),u.set(s,f)),n.bytes=u}t.push(n.bytes),e+=n.bytes.byteLength}return j(t,e)}function Kn(r){if(r.charAt(0)!=="/")throw new S('String multiaddr must start with "/"');let e=[],t="protocol",n="",o="";for(let i=1;i<r.length;i++){let s=r.charAt(i);s!=="/"&&(t==="protocol"?o+=r.charAt(i):n+=r.charAt(i));let a=i===r.length-1;if(s==="/"||a){let c=Y.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 S(`Component ${o} was missing value`);t="value"}else if(t==="value"){let u={code:c.code,name:c.name};if(c.size!=null&&c.size!==0){if(n==="")throw new S(`Component ${o} was missing value`);u.value=c.stringToValue?.(n)??n}e.push(u),n="",o="",t="protocol"}}}if(o!==""&&n!=="")throw new S("Incomplete multiaddr");return e}function eo(r){return`/${r.flatMap(e=>{if(e.value==null)return e.name;let t=Y.getProtocol(e.code);if(t==null)throw new S(`Unknown protocol code ${e.code}`);return[e.name,t.valueToString?.(e.value)??e.value]}).join("/")}`}function xs(r,e,t){return r.size==null||r.size===0?0:r.size>0?r.size/8:$e(e,t)}var ws=Symbol.for("nodejs.util.inspect.custom"),Ar=Symbol.for("@multiformats/multiaddr");function ys(r){if(r==null&&(r="/"),to(r))return r.getComponents();if(r instanceof Uint8Array)return Jn(r);if(typeof r=="string")return r=r.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),r===""&&(r="/"),Kn(r);if(Array.isArray(r))return r;throw new S("Must be a string, Uint8Array, Component[], or another Multiaddr")}var dt=class r{[Ar]=!0;#e;#t;#r;constructor(e="/",t={}){this.#e=ys(e),t.validate!==!1&&Es(this)}get bytes(){return this.#r==null&&(this.#r=Zn(this.#e)),this.#r}toString(){return this.#t==null&&(this.#t=eo(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 st(`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 Ue(this.bytes,e.bytes)}[ws](){return`Multiaddr(${this.toString()})`}};function Es(r){r.getComponents().forEach(e=>{let t=Y.getProtocol(e.code);e.value!=null&&t.validate?.(e.value)})}function to(r){return!!r?.[Ar]}function Lr(r){return new dt(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)}}),ro=r=>({match:e=>r.match(e)===!1?e:!1}),d=r=>({match:e=>{let t=r.match(e);return t===!1?e:t}}),L=(...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 i=o.getComponents();for(let s of r){let a=s.match(i);if(a===!1)return!1;i=a}return i}function t(o){return e(o)!==!1}function n(o){let i=e(o);return i===!1?!1:i.length===0}return{matchers:r,matches:t,exactMatch:n}}var vs=h(421),Sl=E(vs),mt=h(54),gt=h(55),bt=h(56),Nr=h(53),Dl=E(mt,d(h(421))),Tl=E(gt,d(h(421))),Al=E(bt,d(h(421))),no=E(L(Nr,bt,mt,gt),d(h(421))),oo=m(h(4),d(h(43))),io=m(d(h(42)),h(41),d(h(43))),_r=L(oo,io),Pe=L(_r,Nr,mt,gt,bt),Ll=E(L(_r,m(L(Nr,bt,mt,gt),d(h(421))))),Pl=E(oo),Nl=E(io),so=E(_r),Or=m(Pe,h(6)),qe=m(Pe,h(273)),_l=E(m(Or,d(h(421)))),Ol=E(qe),Ur=m(qe,y(460),d(h(421))),xt=m(qe,y(461),d(h(421))),Is=L(Ur,xt),Ul=E(Ur),Rl=E(xt),Pr=L(Pe,Or,qe,Ur,xt),ao=L(m(Pr,y(477),d(h(421)))),Bl=E(ao),co=L(m(Pr,y(478),d(h(421))),m(Pr,y(448),d(h(449)),y(477),d(h(421)))),Ml=E(co),uo=m(qe,y(280),d(h(466)),d(h(466)),d(h(421))),Fl=E(uo),lo=m(xt,y(465),d(h(466)),d(h(466)),d(h(421))),kl=E(lo),pt=L(ao,co,m(Or,d(h(421))),m(Is,d(h(421))),m(Pe,d(h(421))),uo,lo,h(421)),Vl=E(pt),Cs=m(d(pt),y(290),ro(y(281)),d(h(421))),He=E(Cs),Ss=L(m(pt,y(290),y(281),d(h(421))),m(pt,y(281),d(h(421))),m(y(281),d(h(421)))),zl=E(Ss),Ds=m(Pe,L(m(h(6,"80")),m(h(6),y(480)),y(480)),d(h(481)),d(h(421))),$l=E(Ds),Ts=m(Pe,L(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)),d(h(481)),d(h(421))),Wl=E(Ts),As=L(m(h(777),d(h(421)))),Gl=E(As),Ls=L(m(h(400),d(h(421)))),ql=E(Ls);var Rr=class r extends Error{name="TimeoutError";constructor(e,t){super(e,t),Error.captureStackTrace?.(this,r)}},Ps=r=>"reason"in r?r.reason:new DOMException("This operation was aborted.","AbortError"),Ns=2**31-1,_s=(r,e)=>{if(typeof r!="number"||Math.sign(r)!==1)return new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(typeof e?.setTimeout!="function"||typeof e?.clearTimeout!="function")return new TypeError("Expected `customTimers` to have a `setTimeout` and a `clearTimeout` function")};function Br(r,e){let{milliseconds:t,fallback:n,message:o,customTimers:i={setTimeout,clearTimeout},signal:s}=e,a,c,u=()=>{try{r.cancel?.()}catch{}},l=new Promise((p,x)=>{let J=()=>{x(Ps(s)),u()},G=_s(t,i);try{G?x(G):s?.aborted?J():s&&(c=J,s.addEventListener("abort",c,{once:!0}))}finally{r.then(p,x)}if(G||s?.aborted||t>Ns)return;let _e=n||o===!1||o instanceof Error?void 0:new Rr(o??`Promise timed out after ${t} milliseconds`);a=i.setTimeout.call(void 0,()=>{if(n)try{p(n())}catch(w){x(w)}else o===!1?p():x(o instanceof Error?o:_e);u()},t)}).finally(()=>{try{l.clear()}catch{}try{c&&s.removeEventListener("abort",c)}catch{}});return l.clear=()=>{a!==void 0&&(i.clearTimeout.call(void 0,a),a=void 0)},l}var fo=r=>typeof r=="function"?{filter:r}:{...r},Os=r=>r===1/0||Number.isSafeInteger(r)&&r>=0,Us=[["addEventListener","removeEventListener"],["on","off"],["addListener","removeListener"]],Rs=r=>{for(let[e,t]of Us){let n=r?.[e],o=r?.[t];if(typeof n=="function"&&typeof o=="function")return{addListener:n.bind(r),removeListener:o.bind(r)}}throw new TypeError("Emitter is not compatible")},Bs=r=>{let e=new Map;for(let[t,n]of r)for(let o of Array.isArray(t)?t:[t])e.has(o)||e.set(o,n);return e},Ms=({addListener:r,removeListener:e,handlers:t,signal:n,abortHandler:o,isDone:i})=>{n?.addEventListener("abort",o,{once:!0});for(let[s,a]of t)if(r(s,a),i()){e(s,a);return}},Fs=({removeListener:r,handlers:e,signal:t,abortHandler:n})=>{for(let[o,i]of e)r(o,i);t?.removeEventListener("abort",n)},ks=(r,e,t)=>{let n=Promise.resolve();return(o,i)=>{n=n.then(async()=>{if(e())return;let s;try{s=r?await r(o):!0}catch(a){e()||t(a);return}e()||i(s)})}};function Vs(r,e,t){let n=()=>{},o=!1,i,s=new Promise((a,c)=>{t=fo(t);let{filter:u}=t;if(!Os(t.count))throw new TypeError("The `count` option should be at least 0 or more");if(typeof t.timeout=="number"&&!(t.timeout>0))throw new TypeError(`Expected the \`timeout\` option to be a positive number, got \`${t.timeout}\``);t.signal?.throwIfAborted();let{addListener:f,removeListener:l}=Rs(r);if(t.count===0){a([]);return}let p=[],x=I=>{n(),c(I)},J=ks(u,()=>o,x),G=I=>{p.push(I),t.count===p.length&&(n(),a(p))},_e=(...I)=>{if(o)return;let N=t.multiArgs?I:I[0];if(!u){G(N);return}J(N,M=>{M&&G(N)})},w=(...I)=>{x(t.rejectionMultiArgs?I:I[0])},D=()=>{x(t.signal.reason)},z={addListener:f,removeListener:l,handlers:Bs([[e,_e],[t.rejectionEvents??["error"],w]]),signal:t.signal,abortHandler:D,isDone:()=>o};n=()=>{o=!0,clearTimeout(i),Fs(z)},Ms(z),!(o||!t.resolveImmediately)&&(Number.isFinite(t.timeout)&&t.timeout<=2**31-1&&(i=setTimeout(n,t.timeout)),a(p))});if(s.cancel=n,typeof t.timeout=="number"&&t.timeout>0&&!t.resolveImmediately){let a=Br(s,{milliseconds:t.timeout});return a.cancel=()=>{n(),a.clear()},a}return s}function ho(r,e,t){let n=Vs(r,e,{...fo(t),count:1,resolveImmediately:!1}),o=n.then(i=>i[0]);return o.cancel=n.cancel,o}var he=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"};function zs(r){return r.reason}function Mr(r,e,t){if(e==null||r==null)return r;let n=t?.translateError??zs;if(e.aborted)return r.catch(()=>{}),Promise.reject(n(e));let o;return Promise.race([r,new Promise((i,s)=>{o=()=>{s(n(e))},e.addEventListener("abort",o)})]).finally(()=>{o!=null&&e.removeEventListener("abort",o)})}var Ws=4194304,wt=class extends Error{static name="UnwrappedError";name="UnwrappedError"},kr=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},Vr=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},zr=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function Gs(r){return typeof r?.closeRead=="function"}function qs(r){return typeof r?.close=="function"}function Fr(r){return Gs(r)?r.remoteWriteStatus!=="writable"&&r.readBufferLength===0:qs(r)?r.status!=="open":!1}function Hs(r){return r?.addEventListener!=null&&r?.removeEventListener!=null&&r?.send!=null&&r?.push!=null&&r?.log!=null}function js(r,e){let t=e?.maxBufferSize??Ws,n=new se,o,i=!1,s;if(!Hs(r))throw new me("Argument should be a Stream or a Multiaddr");let a=l=>{if(!i&&s==null){if(n.append(l.data),n.byteLength>t){let p=n.byteLength;n.consume(p);let x=new Je(`Read buffer overflow - ${p} > ${t}`);s=x,o?.reject(x),queueMicrotask(()=>{r.abort(x)});return}o?.resolve()}};r.addEventListener("message",a);let c=l=>{l.error!=null?o?.reject(l.error):o?.resolve()};r.addEventListener("close",c);let u=()=>{o?.resolve()};r.addEventListener("remoteCloseWrite",u);let f={readBuffer:n,async read(l){if(i===!0)throw new wt("Stream was unwrapped");if(s!=null)throw s;if(Fr(r)){if(n.byteLength===0&&l?.bytes==null)return null;if(l?.bytes!=null&&n.byteLength<l.bytes)throw r.log.error("closed after reading %d/%d bytes",n.byteLength,l.bytes),new he(`Unexpected EOF - stream closed after reading ${n.byteLength}/${l.bytes} bytes`)}let p=l?.bytes??1;for(o=Promise.withResolvers();;){if(n.byteLength>=p){o.resolve();break}if(await Mr(o.promise,l?.signal),Fr(r)){if(n.byteLength===0&&l?.bytes==null)return null;break}o=Promise.withResolvers()}let x=l?.bytes??n.byteLength;if(n.byteLength<x){if(Fr(r))throw r.log.error("closed while reading %d/%d bytes",n.byteLength,x),new he(`Unexpected EOF - stream closed while reading ${n.byteLength}/${x} bytes`);return f.read(l)}let J=n.sublist(0,x);return n.consume(x),J},async write(l,p){if(i===!0)throw new wt("Stream was unwrapped");r.send(l)||await ho(r,"drain",{signal:p?.signal,rejectionEvents:["close"]})},unwrap(){return i||(i=!0,r.removeEventListener("message",a),r.removeEventListener("close",c),r.removeEventListener("remoteCloseWrite",u),n.byteLength>0&&(r.log("stream unwrapped with %d unread bytes",n.byteLength),r.unshift(n),n.consume(n.byteLength))),r}};return f}function Xs(r,e={}){let t=js(r,e);e.maxDataLength!=null&&e.maxLengthLength==null&&(e.maxLengthLength=O(e.maxDataLength));let n=e?.lengthDecoder??$e,o=e?.lengthEncoder??zn;return{async read(s){let a=-1,c=new se;for(;;){let f=await t.read({...s,bytes:1});if(f==null)break;c.append(f);try{a=n(c)}catch(l){if(l instanceof RangeError)continue;throw l}if(a<0)throw new kr("Invalid message length");if(e?.maxLengthLength!=null&&c.byteLength>e.maxLengthLength)throw new zr(`Message length length too long - ${c.byteLength} > ${e.maxLengthLength}`);if(a>-1)break}if(e?.maxDataLength!=null&&a>e.maxDataLength)throw new Vr(`Message length too long - ${a} > ${e.maxDataLength}`);let u=await t.read({...s,bytes:a});if(u==null)throw r.log.error("tried to read %d bytes but the stream closed",a),new he(`Unexpected EOF - tried to read ${a} bytes but the stream closed`);if(u.byteLength!==a)throw r.log.error("read %d/%d bytes before the stream closed",u.byteLength,a),new he(`Unexpected EOF - read ${u.byteLength}/${a} bytes before the stream closed`);return u},async write(s,a){await t.write(new se(o(s.byteLength),s),a)},async writeV(s,a){let c=new se(...s.flatMap(u=>[o(u.byteLength),u]));await t.write(c,a)},unwrap(){return t.unwrap()}}}function $r(r,e){let t=Xs(r,e),n={read:async(o,i)=>{let s=await t.read(i);return o.decode(s,i)},write:async(o,i,s)=>{await t.write(i.encode(o),s)},writeV:async(o,i,s)=>{await t.writeV(o.map(a=>i.encode(a)),s)},pb:o=>({read:async i=>n.read(o,i),write:async(i,s)=>n.write(i,o,s),writeV:async(i,s)=>n.writeV(i,o,s),unwrap:()=>n}),unwrap:()=>t.unwrap()};return n}var po=Symbol.for("sindresorhus/unlimited-timeout#brand");function mo(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={[po]:!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 i=performance.now()+e,s=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(),u=Math.max(0,i-c);s(u)},2147483647),n&&o.id?.unref?.()))};return s(e),o}function go(r){!r||typeof r!="object"||!r[po]||(r.cleared=!0,r.id!==void 0&&(globalThis.clearTimeout(r.id),r.id=void 0))}var Qs=new WeakMap;function Ys({clearTimeout:r,setTimeout:e}={}){return(t,{value:n,signal:o}={})=>{if(o?.aborted)return Promise.reject(o.reason);let i,s,a,c=r??clearTimeout,u=()=>{c(i),a(o.reason)},f=()=>{o&&o.removeEventListener("abort",u)},l=new Promise((p,x)=>{s=()=>{f(),p(n)},a=x,i=(e??setTimeout)(s,t)});return o&&o.addEventListener("abort",u,{once:!0}),Qs.set(l,()=>{c(i),i=null,s()}),l}}var Js=Ys({setTimeout:mo,clearTimeout:go}),bo=Js;var Wr=new Float32Array([-0]),ne=new Uint8Array(Wr.buffer);function xo(r,e,t){Wr[0]=r,e[t]=ne[0],e[t+1]=ne[1],e[t+2]=ne[2],e[t+3]=ne[3]}function wo(r,e){return ne[0]=r[e],ne[1]=r[e+1],ne[2]=r[e+2],ne[3]=r[e+3],Wr[0]}var Gr=new Float64Array([-0]),P=new Uint8Array(Gr.buffer);function yo(r,e,t){Gr[0]=r,e[t]=P[0],e[t+1]=P[1],e[t+2]=P[2],e[t+3]=P[3],e[t+4]=P[4],e[t+5]=P[5],e[t+6]=P[6],e[t+7]=P[7]}function Eo(r,e){return P[0]=r[e],P[1]=r[e+1],P[2]=r[e+2],P[3]=r[e+3],P[4]=r[e+4],P[5]=r[e+5],P[6]=r[e+6],P[7]=r[e+7],Gr[0]}var Zs=BigInt(Number.MAX_SAFE_INTEGER),Ks=BigInt(Number.MIN_SAFE_INTEGER),B=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 de;if(e<Zs&&e>Ks)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>vo&&(o=0n,++n>vo&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(e){if(e===0)return de;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):de}},de=new B(0,0);de.toBigInt=function(){return 0n};de.zzEncode=de.zzDecode=function(){return this};de.length=function(){return 1};var vo=4294967296n;function Io(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 Co(r,e,t){if(t-e<1)return"";let o,i=[],s=0,a;for(;e<t;)a=r[e++],a<128?i[s++]=a:a>191&&a<224?i[s++]=(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,i[s++]=55296+(a>>10),i[s++]=56320+(a&1023)):i[s++]=(a&15)<<12|(r[e++]&63)<<6|r[e++]&63,s>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,i)),s=0);return o!=null?(s>0&&o.push(String.fromCharCode.apply(String,i.slice(0,s))),o.join("")):String.fromCharCode.apply(String,i.slice(0,s))}function qr(r,e,t){let n=t,o,i;for(let s=0;s<r.length;++s)o=r.charCodeAt(s),o<128?e[t++]=o:o<2048?(e[t++]=o>>6|192,e[t++]=o&63|128):(o&64512)===55296&&((i=r.charCodeAt(s+1))&64512)===56320?(o=65536+((o&1023)<<10)+(i&1023),++s,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 k(r,e){return RangeError(`index out of range: ${r.pos} + ${e??1} > ${r.len}`)}function yt(r,e){return(r[e-4]|r[e-3]<<8|r[e-2]<<16|r[e-1]<<24)>>>0}var Hr=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(e){this.buf=We(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,k(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 k(this,4);return yt(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw k(this,4);return yt(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw k(this,4);let e=wo(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw k(this,4);let e=Eo(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 k(this,e);return this.pos+=e,t===n?new Uint8Array(0):this.buf.subarray(t,n)}string(){let e=this.bytes();return Co(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw k(this,e);this.pos+=e}else do if(this.pos>=this.len)throw k(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 B(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 k(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 k(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 k(this,8);let e=yt(this.buf,this.pos+=4),t=yt(this.buf,this.pos+=4);return new B(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=ir(this.buf,this.pos);return this.pos+=O(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 je(r){return new Hr(r instanceof Uint8Array?r:r.subarray())}function jr(r,e,t){let n=je(r);return e.decode(n,void 0,t)}function Xr(r){let e=r??8192,t=e>>>1,n,o=e;return function(s){if(s<1||s>t)return T(s);o+s>e&&(n=T(e),o=0);let a=n.subarray(o,o+=s);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 Qr(){}var Jr=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},ea=Xr();function ta(r){return globalThis.Buffer!=null?T(r):ea(r)}var Qe=class{len;head;tail;states;constructor(){this.len=0,this.head=new pe(Qr,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 Zr((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(Et,10,B.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let t=B.fromBigInt(e);return this._push(Et,t.length(),t)}uint64Number(e){return this._push(Se,O(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=B.fromBigInt(e).zzEncode();return this._push(Et,t.length(),t)}sint64Number(e){let t=B.fromNumber(e).zzEncode();return this._push(Et,t.length(),t)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(Yr,1,e?1:0)}fixed32(e){return this._push(Xe,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let t=B.fromBigInt(e);return this._push(Xe,4,t.lo)._push(Xe,4,t.hi)}fixed64Number(e){let t=B.fromNumber(e);return this._push(Xe,4,t.lo)._push(Xe,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(xo,4,e)}double(e){return this._push(yo,8,e)}bytes(e){let t=e.length>>>0;return t===0?this._push(Yr,1,0):this.uint32(t)._push(na,t,e)}string(e){let t=Io(e);return t!==0?this.uint32(t)._push(qr,t,e):this._push(Yr,1,0)}fork(){return this.states=new Jr(this),this.head=this.tail=new pe(Qr,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(Qr,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=ta(this.len),n=0;for(;e!=null;)e.fn(e.val,t,n),n+=e.len,e=e.next;return t}};function Yr(r,e,t){e[t]=r&255}function ra(r,e,t){for(;r>127;)e[t++]=r&127|128,r>>>=7;e[t]=r}var Zr=class extends pe{next;constructor(e,t){super(ra,e,t),this.next=void 0}};function Et(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 Xe(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 na(r,e,t){e.set(r,t)}globalThis.Buffer!=null&&(Qe.prototype.bytes=function(r){let e=r.length>>>0;return this.uint32(e),e>0&&this._push(oa,e,r),this},Qe.prototype.string=function(r){let e=globalThis.Buffer.byteLength(r);return this.uint32(e),e>0&&this._push(ia,e,r),this});function oa(r,e,t){e.set(r,t)}function ia(r,e,t){r.length<40?qr(r,e,t):e.utf8Write!=null?e.utf8Write(r,t):e.set(ee(r),t)}function Kr(){return new Qe}function en(r,e){let t=Kr();return e.encode(r,t,{lengthDelimited:!1}),t.finish()}function*tn(r,e,t){let n=je(r);yield*e.stream(n,void 0,".",t)}var vt={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function It(r,e,t,n,o){return{name:r,type:e,encode:t,decode:n,stream:o}}function rn(r){function e(i){if(r[i.toString()]==null)throw new Error("Invalid enum value");return r[i]}let t=function(s,a){let c=e(s);a.int32(c)},n=function(s){let a=s.int32();return e(a)},o=function*(s,a){};return It("enum",vt.VARINT,t,n,o)}function nn(r,e,t){return It("message",vt.LENGTH_DELIMITED,r,e,t)}var Ye=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var V;(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=()=>rn(t)})(e=r.Type||(r.Type={}));let n;r.codec=()=>(n==null&&(n=nn((a,c,u={})=>{if(u.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 f of a.observedAddresses)c.uint32(18),c.bytes(f);u.lengthDelimited!==!1&&c.ldelim()},(a,c,u={})=>{let f={observedAddresses:[]},l=c==null?a.len:a.pos+c;for(;a.pos<l;){let p=a.uint32();switch(p>>>3){case 1:{f.type=r.Type.codec().decode(a);break}case 2:{if(u.limits?.observedAddresses!=null&&f.observedAddresses.length===u.limits.observedAddresses)throw new Ye('Decode error - repeated field "observedAddresses" had too many elements');f.observedAddresses.push(a.bytes());break}default:{a.skipType(p&7);break}}}return f},function*(a,c,u,f={}){let l={observedAddresses:0},p=c==null?a.len:a.pos+c;for(;a.pos<p;){let x=a.uint32();switch(x>>>3){case 1:{yield{field:`${u}.type`,value:r.Type.codec().decode(a)};break}case 2:{if(f.limits?.observedAddresses!=null&&l.observedAddresses===f.limits.observedAddresses)throw new Ye('Streaming decode error - repeated field "observedAddresses" had too many elements');yield{field:`${u}.observedAddresses[]`,index:l.observedAddresses,value:a.bytes()},l.observedAddresses++;break}default:{a.skipType(x&7);break}}}})),n);function o(a){return en(a,r.codec())}r.encode=o;function i(a,c){return jr(a,r.codec(),c)}r.decode=i;function s(a,c){return tn(a,r.codec(),c)}r.stream=s})(V||(V={}));function on(r,e){return He.matches(r)||e.dialTransportForMultiaddr(r)==null?!1:no.matches(r)?!0:so.matches(r)?!Vn(r):!1}var Do=1024*4,To=100,Ct={timeout:5e3,retries:3,maxInboundStreams:1,maxOutboundStreams:1},St=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??Ct.timeout,this.retries=t.retries??Ct.retries,this.maxInboundStreams=t.maxInboundStreams??Ct.maxInboundStreams,this.maxOutboundStreams=t.maxOutboundStreams??Ct.maxOutboundStreams,this.handleIncomingUpgrade=this.handleIncomingUpgrade.bind(this)}[Symbol.toStringTag]="@libp2p/dcutr";[sn]=["@libp2p/identify"];isStarted(){return this.started}async start(){this.started||(this.topologyId=await this.registrar.register(Ne,{notifyOnLimitedConnection:!0,onConnect:(e,t)=>{He.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 i=$r(t,{maxDataLength:Do}).pb(V);this.log("B sending connect to %p",e.remotePeer);let s=Date.now();await i.write({type:V.Type.CONNECT,observedAddresses:this.addressManager.getAddresses().map(l=>l.bytes)},o),this.log("B receiving connect from %p",e.remotePeer);let a=await i.read(o);if(a.type!==V.Type.CONNECT)throw this.log("A sent wrong message type"),new H("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 H("DCUtR connect message had no multiaddrs");let u=Date.now()-s;this.log("A sending sync, rtt %dms",u),await i.write({type:V.Type.SYNC,observedAddresses:[]},o),this.log("A waiting for half RTT"),await bo(u/2),this.log("B dialing",c);let f=await this.connectionManager.openConnection(c,{signal:o.signal,priority:To,force:!0,initiator:!1});this.log("DCUtR to %p succeeded to address %a, closing relayed connection",e.remotePeer,f.remoteAddr),await e.close(o);break}catch(i){if(this.log.error("error while attempting DCUtR on attempt %d of %d - %e",n+1,this.retries,i),t?.abort(i),n===this.retries)throw i}finally{t!=null&&await t.close(o)}}}async attemptUnilateralConnectionUpgrade(e){let n=(await this.peerStore.get(e.remotePeer)).addresses.map(o=>{let i=o.multiaddr;return i.getComponents().find(s=>s.code===421)?.value==null?i.encapsulate(`/p2p/${e.remotePeer}`):i}).filter(o=>on(o,this.transportManager));if(n.length>0){let o=AbortSignal.timeout(this.timeout);try{this.log("attempting unilateral connection upgrade to %a",n);let i=await this.connectionManager.openConnection(n,{signal:o,force:!0});if(He.exactMatch(i.remoteAddr))throw new Error("Could not open a new, non-limited, connection");return this.log("unilateral connection upgrade to %p succeeded via %a, closing relayed connection",e.remotePeer,i.remoteAddr),await e.close({signal:o}),!0}catch(i){this.log.error("unilateral connection upgrade to %p on addresses %a failed - %e",e.remotePeer,n,i)}}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=$r(e,{maxDataLength:Do}).pb(V);this.log("A receiving connect");let i=await o.read(n);if(i.type!==V.Type.CONNECT)throw this.log("B sent wrong message type"),new H("DCUtR message type was incorrect");if(i.observedAddresses.length===0)throw this.log("B sent no multiaddrs"),new H("DCUtR connect message had no multiaddrs");let s=this.getDialableMultiaddrs(i.observedAddresses);if(s.length===0)throw this.log("B had no dialable multiaddrs in %o",i.observedAddresses.map(u=>Lr(u))),new H("DCUtR connect message had no dialable multiaddrs");if(this.log("A sending connect"),await o.write({type:V.Type.CONNECT,observedAddresses:this.addressManager.getAddresses().map(u=>u.bytes)}),this.log("A receiving sync"),(await o.read(n)).type!==V.Type.SYNC)throw new H("DCUtR message type was incorrect");this.log("A dialing",s);let c=await this.connectionManager.openConnection(s,{signal:n.signal,priority:To,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=Lr(n);if(!on(o,this.transportManager))continue;t.push(o)}catch{}return t}};var Ne="/libp2p/dcutr";function sa(r={}){return e=>new St(e,r)}return Oo(aa);})();
|
|
3
3
|
return Libp2PDcutr}));
|
|
4
4
|
//# sourceMappingURL=index.min.js.map
|