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