@libp2p/daemon-client 10.0.43-0d3ca9f0c → 10.0.43-42064ed68

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.min.js CHANGED
@@ -1,19 +1,19 @@
1
1
  (function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PDaemonClient = factory()}(typeof self !== 'undefined' ? self : this, function () {
2
- "use strict";var Libp2PDaemonClient=(()=>{var vu=Object.create;var Qr=Object.defineProperty;var Su=Object.getOwnPropertyDescriptor;var Tu=Object.getOwnPropertyNames;var Au=Object.getPrototypeOf,Du=Object.prototype.hasOwnProperty;var ue=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(e,r)=>(typeof require<"u"?require:e)[r]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')});var Oe=(t,e)=>{for(var r in e)Qr(t,r,{get:e[r],enumerable:!0})},Ns=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of Tu(e))!Du.call(t,s)&&s!==r&&Qr(t,s,{get:()=>e[s],enumerable:!(n=Su(e,s))||n.enumerable});return t};var ke=(t,e,r)=>(r=t!=null?vu(Au(t)):{},Ns(e||!t||!t.__esModule?Qr(r,"default",{value:t,enumerable:!0}):r,t)),Iu=t=>Ns(Qr({},"__esModule",{value:!0}),t);var bh={};Oe(bh,{OperationFailedError:()=>V,createClient:()=>yh});var Oo=ue("node:buffer");function dt(t){if(t.buffer instanceof ArrayBuffer)return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);let e=t.slice();return new Uint8Array(e.buffer,0,e.byteLength)}function le(t=0){return dt(Oo.Buffer.alloc(t))}function Ce(t=0){return dt(Oo.Buffer.allocUnsafe(t))}var Cu=Math.pow(2,7),Bu=Math.pow(2,14),Lu=Math.pow(2,21),ko=Math.pow(2,28),_o=Math.pow(2,35),Po=Math.pow(2,42),Ro=Math.pow(2,49),U=128,xe=127;function Be(t){if(t<Cu)return 1;if(t<Bu)return 2;if(t<Lu)return 3;if(t<ko)return 4;if(t<_o)return 5;if(t<Po)return 6;if(t<Ro)return 7;if(Number.MAX_SAFE_INTEGER!=null&&t>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Ut(t,e,r=0){switch(Be(t)){case 8:e[r++]=t&255|U,t/=128;case 7:e[r++]=t&255|U,t/=128;case 6:e[r++]=t&255|U,t/=128;case 5:e[r++]=t&255|U,t/=128;case 4:e[r++]=t&255|U,t>>>=7;case 3:e[r++]=t&255|U,t>>>=7;case 2:e[r++]=t&255|U,t>>>=7;case 1:{e[r++]=t&255,t>>>=7;break}default:throw new Error("unreachable")}return e}function Ou(t,e,r=0){switch(Be(t)){case 8:e.set(r++,t&255|U),t/=128;case 7:e.set(r++,t&255|U),t/=128;case 6:e.set(r++,t&255|U),t/=128;case 5:e.set(r++,t&255|U),t/=128;case 4:e.set(r++,t&255|U),t>>>=7;case 3:e.set(r++,t&255|U),t>>>=7;case 2:e.set(r++,t&255|U),t>>>=7;case 1:{e.set(r++,t&255),t>>>=7;break}default:throw new Error("unreachable")}return e}function No(t,e){let r=t[e],n=0;if(n+=r&xe,r<U||(r=t[e+1],n+=(r&xe)<<7,r<U)||(r=t[e+2],n+=(r&xe)<<14,r<U)||(r=t[e+3],n+=(r&xe)<<21,r<U)||(r=t[e+4],n+=(r&xe)*ko,r<U)||(r=t[e+5],n+=(r&xe)*_o,r<U)||(r=t[e+6],n+=(r&xe)*Po,r<U)||(r=t[e+7],n+=(r&xe)*Ro,r<U))return n;throw new RangeError("Could not decode varint")}function ku(t,e){let r=t.get(e),n=0;if(n+=r&xe,r<U||(r=t.get(e+1),n+=(r&xe)<<7,r<U)||(r=t.get(e+2),n+=(r&xe)<<14,r<U)||(r=t.get(e+3),n+=(r&xe)<<21,r<U)||(r=t.get(e+4),n+=(r&xe)*ko,r<U)||(r=t.get(e+5),n+=(r&xe)*_o,r<U)||(r=t.get(e+6),n+=(r&xe)*Po,r<U)||(r=t.get(e+7),n+=(r&xe)*Ro,r<U))return n;throw new RangeError("Could not decode varint")}function Us(t,e,r=0){return e==null&&(e=Ce(Be(t))),e instanceof Uint8Array?Ut(t,e,r):Ou(t,e,r)}function fr(t,e=0){return t instanceof Uint8Array?No(t,e):ku(t,e)}function _u(t){return t.buffer instanceof ArrayBuffer}function ht(t){return _u(t)?t:t.slice()}var Uo=new Float32Array([-0]),pt=new Uint8Array(Uo.buffer);function Ms(t,e,r){Uo[0]=t,e[r]=pt[0],e[r+1]=pt[1],e[r+2]=pt[2],e[r+3]=pt[3]}function Ks(t,e){return pt[0]=t[e],pt[1]=t[e+1],pt[2]=t[e+2],pt[3]=t[e+3],Uo[0]}var Fo=new Float64Array([-0]),Ee=new Uint8Array(Fo.buffer);function $s(t,e,r){Fo[0]=t,e[r]=Ee[0],e[r+1]=Ee[1],e[r+2]=Ee[2],e[r+3]=Ee[3],e[r+4]=Ee[4],e[r+5]=Ee[5],e[r+6]=Ee[6],e[r+7]=Ee[7]}function Hs(t,e){return Ee[0]=t[e],Ee[1]=t[e+1],Ee[2]=t[e+2],Ee[3]=t[e+3],Ee[4]=t[e+4],Ee[5]=t[e+5],Ee[6]=t[e+6],Ee[7]=t[e+7],Fo[0]}var Pu=BigInt(Number.MAX_SAFE_INTEGER),Ru=BigInt(Number.MIN_SAFE_INTEGER),_e=class t{lo;hi;constructor(e,r){this.lo=e|0,this.hi=r|0}toNumber(e=!1){if(!e&&this.hi>>>31>0){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(r+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 r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(BigInt(r)+(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,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?e<16384?e<128?1:2:e<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(e){if(e===0n)return Tt;if(e<Pu&&e>Ru)return this.fromNumber(Number(e));let r=e<0n;r&&(e=-e);let n=e>>32n,s=e-(n<<32n);return r&&(n=~n|0n,s=~s|0n,++s>zs&&(s=0n,++n>zs&&(n=0n))),new t(Number(s),Number(n))}static fromNumber(e){if(e===0)return Tt;let r=e<0;r&&(e=-e);let n=e>>>0,s=(e-n)/4294967296>>>0;return r&&(s=~s>>>0,n=~n>>>0,++n>4294967295&&(n=0,++s>4294967295&&(s=0))),new t(n,s)}static from(e){return typeof e=="number"?t.fromNumber(e):typeof e=="bigint"?t.fromBigInt(e):typeof e=="string"?t.fromBigInt(BigInt(e)):e.low!=null||e.high!=null?new t(e.low>>>0,e.high>>>0):Tt}},Tt=new _e(0,0);Tt.toBigInt=function(){return 0n};Tt.zzEncode=Tt.zzDecode=function(){return this};Tt.length=function(){return 1};var zs=4294967296n;function Vs(t){let e=0,r=0;for(let n=0;n<t.length;++n)r=t.charCodeAt(n),r<128?e+=1:r<2048?e+=2:(r&64512)===55296&&(t.charCodeAt(n+1)&64512)===56320?(++n,e+=4):e+=3;return e}function Gs(t,e,r){if(r-e<1)return"";let s,o=[],c=0,i;for(;e<r;)i=t[e++],i<128?o[c++]=i:i>191&&i<224?o[c++]=(i&31)<<6|t[e++]&63:i>239&&i<365?(i=((i&7)<<18|(t[e++]&63)<<12|(t[e++]&63)<<6|t[e++]&63)-65536,o[c++]=55296+(i>>10),o[c++]=56320+(i&1023)):o[c++]=(i&15)<<12|(t[e++]&63)<<6|t[e++]&63,c>8191&&((s??(s=[])).push(String.fromCharCode.apply(String,o)),c=0);return s!=null?(c>0&&s.push(String.fromCharCode.apply(String,o.slice(0,c))),s.join("")):String.fromCharCode.apply(String,o.slice(0,c))}function Mo(t,e,r){let n=r,s,o;for(let c=0;c<t.length;++c)s=t.charCodeAt(c),s<128?e[r++]=s:s<2048?(e[r++]=s>>6|192,e[r++]=s&63|128):(s&64512)===55296&&((o=t.charCodeAt(c+1))&64512)===56320?(s=65536+((s&1023)<<10)+(o&1023),++c,e[r++]=s>>18|240,e[r++]=s>>12&63|128,e[r++]=s>>6&63|128,e[r++]=s&63|128):(e[r++]=s>>12|224,e[r++]=s>>6&63|128,e[r++]=s&63|128);return r-n}function Ve(t,e){return RangeError(`index out of range: ${t.pos} + ${e??1} > ${t.len}`)}function Jr(t,e){return(t[e-4]|t[e-3]<<8|t[e-2]<<16|t[e-1]<<24)>>>0}var Ko=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(e){this.buf=ht(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,Ve(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 Ve(this,4);return Jr(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Ve(this,4);return Jr(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Ve(this,4);let e=Ks(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw Ve(this,4);let e=Hs(this.buf,this.pos);return this.pos+=8,e}bytes(){let e=this.uint32(),r=this.pos,n=this.pos+e;if(n>this.len)throw Ve(this,e);return this.pos+=e,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let e=this.bytes();return Gs(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw Ve(this,e);this.pos+=e}else do if(this.pos>=this.len)throw Ve(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 _e(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(e.lo=(e.lo|(this.buf[this.pos]&127)<<r*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;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw Ve(this);if(e.lo=(e.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return e}return e.lo=(e.lo|(this.buf[this.pos++]&127)<<r*7)>>>0,e}if(this.len-this.pos>4){for(;r<5;++r)if(e.hi=(e.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return e}else for(;r<5;++r){if(this.pos>=this.len)throw Ve(this);if(e.hi=(e.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return e}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Ve(this,8);let e=Jr(this.buf,this.pos+=4),r=Jr(this.buf,this.pos+=4);return new _e(e,r)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let e=No(this.buf,this.pos);return this.pos+=Be(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 dr(t){return new Ko(t instanceof Uint8Array?t:t.subarray())}function J(t,e,r){let n=dr(t);return e.decode(n,void 0,r)}var pc=ue("node:buffer");var Go={};Oe(Go,{base10:()=>zu});var _h=new Uint8Array(0);function qs(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}function Se(t){if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return At(t);if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return At(new Uint8Array(t.buffer,t.byteOffset,t.byteLength));throw new Error("Unknown type, must be binary type")}function Zs(t){let e=new Uint8Array(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}var Ys=4096;function js(t){let e=t.length;if(e<=Ys)return String.fromCharCode.apply(String,t);let r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.subarray(n,n+=Ys));return r}function Nu(t){return t?.buffer instanceof ArrayBuffer}function At(t){return Nu(t)?t:t.slice()}function Uu(t,e,r){if(t.length>=255)throw new TypeError("Alphabet too long");for(var n=new Uint8Array(256),s=0;s<n.length;s++)n[s]=255;for(var o=0;o<t.length;o++){var c=t.charAt(o),i=c.charCodeAt(0);if(n[i]!==255)throw new TypeError(c+" is ambiguous");if(n[i]=o,r){var a=c.toLowerCase().charCodeAt(0),u=c.toUpperCase().charCodeAt(0);a!==i&&(n[a]=o),u!==i&&(n[u]=o)}}var l=t.length,f=t.charAt(0),d=Math.log(l)/Math.log(256),p=Math.log(256)/Math.log(l);function E(y){if(y instanceof Uint8Array||(ArrayBuffer.isView(y)?y=new Uint8Array(y.buffer,y.byteOffset,y.byteLength):Array.isArray(y)&&(y=Uint8Array.from(y))),!(y instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(y.length===0)return"";for(var T=0,P=0,_=0,F=y.length;_!==F&&y[_]===0;)_++,T++;for(var Q=(F-_)*p+1>>>0,G=new Uint8Array(Q);_!==F;){for(var pe=y[_],me=0,H=Q-1;(pe!==0||me<P)&&H!==-1;H--,me++)pe+=256*G[H]>>>0,G[H]=pe%l>>>0,pe=pe/l>>>0;if(pe!==0)throw new Error("Non-zero carry");P=me,_++}for(var Ie=Q-P;Ie!==Q&&G[Ie]===0;)Ie++;for(var Me=f.repeat(T);Ie<Q;++Ie)Me+=t.charAt(G[Ie]);return Me}function D(y){if(typeof y!="string")throw new TypeError("Expected String");if(y.length===0)return new Uint8Array;var T=0;if(y[T]!==" "){for(var P=0,_=0;y[T]===f;)P++,T++;for(var F=(y.length-T)*d+1>>>0,Q=new Uint8Array(F);y[T];){var G=n[y.charCodeAt(T)];if(G===255)return;for(var pe=0,me=F-1;(G!==0||pe<_)&&me!==-1;me--,pe++)G+=l*Q[me]>>>0,Q[me]=G%256>>>0,G=G/256>>>0;if(G!==0)throw new Error("Non-zero carry");_=pe,T++}if(y[T]!==" "){for(var H=F-_;H!==F&&Q[H]===0;)H++;for(var Ie=new Uint8Array(P+(F-H)),Me=P;H!==F;)Ie[Me++]=Q[H++];return Ie}}}function b(y){var T=D(y);if(T)return T;throw new Error(`Non-${e} character`)}return{encode:E,decodeUnsafe:D,decode:b}}var Fu=Uu,Mu=Fu,Qs=Mu;var $o=class{name;prefix;baseEncode;constructor(e,r,n){this.name=e,this.prefix=r,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},Ho=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,r,n){this.name=e,this.prefix=r;let s=r.codePointAt(0);if(s===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=s,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 Js(this,e)}},zo=class{decoders;constructor(e){this.decoders=e}or(e){return Js(this,e)}decode(e){let r=e[0],n=this.decoders[r];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 Js(t,e){return new zo({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var Vo=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,r,n,s){this.name=e,this.prefix=r,this.baseEncode=n,this.baseDecode=s,this.encoder=new $o(e,r,n),this.decoder=new Ho(e,r,s)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function Ft({name:t,prefix:e,encode:r,decode:n}){return new Vo(t,e,r,n)}function mt({name:t,prefix:e,alphabet:r,caseInsensitive:n=!1}){let{encode:s,decode:o}=Qs(r,t,n);return Ft({prefix:e,name:t,encode:s,decode:c=>Se(o(c))})}function Ku(t,e,r,n){let s=t.length;for(;t[s-1]==="=";)--s;let o=new Uint8Array(s*r/8|0),c=0,i=0,a=0;for(let u=0;u<s;++u){let l=e[t[u]];if(l===void 0)throw new SyntaxError(`Non-${n} character`);i=i<<r|l,c+=r,c>=8&&(c-=8,o[a++]=255&i>>c)}if(c>=r||(255&i<<8-c)!==0)throw new SyntaxError("Unexpected end of data");return o}function $u(t,e,r){let n=e[e.length-1]==="=",s=(1<<r)-1,o="",c=0,i=0;for(let a=0;a<t.length;++a)for(i=i<<8|t[a],c+=8;c>r;)c-=r,o+=e[s&i>>c];if(c!==0&&(o+=e[s&i<<r-c]),n)for(;(o.length*r&7)!==0;)o+="=";return o}function Hu(t,e){let r={};for(let n=0;n<t.length;++n)if(r[t[n]]=n,e){let s=t[n].toLowerCase(),o=t[n].toUpperCase();s!==t[n]&&(r[s]=n),o!==t[n]&&(r[o]=n)}return r}function ne({name:t,prefix:e,bitsPerChar:r,alphabet:n,caseInsensitive:s=!1}){let o=Hu(n,s);return Ft({prefix:e,name:t,encode(c){return $u(c,n,r)},decode(c){return Ku(c,o,r,t)}})}var zu=mt({prefix:"9",name:"base10",alphabet:"0123456789"});var Wo={};Oe(Wo,{base16:()=>Vu,base16upper:()=>Gu});var Vu=ne({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4,caseInsensitive:!0}),Gu=ne({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4,caseInsensitive:!0});var Yo={};Oe(Yo,{base2:()=>Wu});var Wu=ne({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var qo={};Oe(qo,{base256emoji:()=>Xu});var ec=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}"),Yu=ec.reduce((t,e,r)=>(t[r]=e,t),[]),qu=ec.reduce((t,e,r)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return t[n]=r,t},[]);function Zu(t){return t.reduce((e,r)=>(e+=Yu[r],e),"")}function ju(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let s=qu[n];if(s==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(s)}return new Uint8Array(e)}var Xu=Ft({prefix:"\u{1F680}",name:"base256emoji",encode:Zu,decode:ju});var Zo={};Oe(Zo,{base32:()=>je,base32hex:()=>tl,base32hexpad:()=>nl,base32hexpadupper:()=>ol,base32hexupper:()=>rl,base32pad:()=>Ju,base32padupper:()=>el,base32upper:()=>Qu,base32z:()=>il});var je=ne({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5,caseInsensitive:!0}),Qu=ne({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5,caseInsensitive:!0}),Ju=ne({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5,caseInsensitive:!0}),el=ne({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5,caseInsensitive:!0}),tl=ne({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5,caseInsensitive:!0}),rl=ne({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5,caseInsensitive:!0}),nl=ne({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5,caseInsensitive:!0}),ol=ne({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5,caseInsensitive:!0}),il=ne({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var jo={};Oe(jo,{base36:()=>hr,base36upper:()=>sl});var hr=mt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz",caseInsensitive:!0}),sl=mt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",caseInsensitive:!0});var Xo={};Oe(Xo,{base58btc:()=>ce,base58flickr:()=>cl});var ce=mt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),cl=mt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var ei={};Oe(ei,{base64:()=>Qo,base64pad:()=>al,base64url:()=>Jo,base64urlpad:()=>ul});var Qo=ne({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),al=ne({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Jo=ne({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),ul=ne({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var ti={};Oe(ti,{base8:()=>ll});var ll=ne({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var ri={};Oe(ri,{identity:()=>fl});var fl=Ft({prefix:"\0",name:"identity",encode:t=>js(Se(t)),decode:t=>Se(Zs(t))});var Zh=new TextEncoder,jh=new TextDecoder;var oi={};Oe(oi,{identity:()=>Ge});var pl=nc,tc=128,ml=127,yl=~ml,bl=Math.pow(2,31);function nc(t,e,r){e=e||[],r=r||0;for(var n=r;t>=bl;)e[r++]=t&255|tc,t/=128;for(;t&yl;)e[r++]=t&255|tc,t>>>=7;return e[r]=t|0,nc.bytes=r-n+1,e}var gl=ni,wl=128,rc=127;function ni(t,n){var r=0,n=n||0,s=0,o=n,c,i=t.length;do{if(o>=i)throw ni.bytes=0,new RangeError("Could not decode varint");c=t[o++],r+=s<28?(c&rc)<<s:(c&rc)*Math.pow(2,s),s+=7}while(c>=wl);return ni.bytes=o-n,r}var xl=Math.pow(2,7),El=Math.pow(2,14),vl=Math.pow(2,21),Sl=Math.pow(2,28),Tl=Math.pow(2,35),Al=Math.pow(2,42),Dl=Math.pow(2,49),Il=Math.pow(2,56),Cl=Math.pow(2,63),Bl=function(t){return t<xl?1:t<El?2:t<vl?3:t<Sl?4:t<Tl?5:t<Al?6:t<Dl?7:t<Il?8:t<Cl?9:10},Ll={encode:pl,decode:gl,encodingLength:Bl},Ol=Ll,pr=Ol;function mr(t,e=0){let r=pr.decode(t,e),n=pr.decode.bytes;if(n>9)throw new RangeError("Invalid varint: too long");if(n>1&&t[e+n-1]===0)throw new RangeError("Invalid varint: not minimally encoded");return[r,n]}function Mt(t,e,r=0){return pr.encode(t,e,r),e}function Kt(t){return pr.encodingLength(t)}function Ht(t,e){let r=e.byteLength,n=Kt(t),s=n+Kt(r),o=new Uint8Array(s+r);return Mt(t,o,0),Mt(r,o,n),o.set(e,s),new $t(t,r,e,o)}function $e(t){let e=Se(t),[r,n]=mr(e),[s,o]=mr(e.subarray(n)),c=e.subarray(n+o);if(c.byteLength!==s)throw new Error("Incorrect length");return new $t(r,s,c,e)}function oc(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&qs(t.bytes,r.bytes)}}var $t=class{code;size;digest;bytes;constructor(e,r,n,s){this.code=e,this.size=r,this.digest=At(n),this.bytes=At(s)}};var ic=0,kl="identity",sc=Se;function _l(t,e){if(e?.truncate!=null&&e.truncate!==t.byteLength){if(e.truncate<0||e.truncate>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,e.truncate)}return Ht(ic,sc(t))}var Ge={code:ic,name:kl,encode:sc,digest:_l};var ui={};Oe(ui,{sha256:()=>ai,sha512:()=>Rl});var ci=ke(ue("node:crypto"),1);var Pl=20;function si({name:t,code:e,encode:r,minDigestLength:n,maxDigestLength:s}){return new ii(t,e,r,n,s)}var ii=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,r,n,s,o){this.name=e,this.code=r,this.encode=n,this.minDigestLength=s??Pl,this.maxDigestLength=o}digest(e,r){if(r?.truncate!=null){if(r.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&r.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?cc(n,this.code,r?.truncate):n.then(s=>cc(s,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function cc(t,e,r){if(r!=null&&r!==t.byteLength){if(r>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,r)}return Ht(e,t)}var ai=si({name:"sha2-256",code:18,encode:t=>Se(ci.default.createHash("sha256").update(t).digest())}),Rl=si({name:"sha2-512",code:19,encode:t=>Se(ci.default.createHash("sha512").update(t).digest())});function uc(t,e){let{bytes:r,version:n}=t;return n===0?Ul(r,li(t),e??ce.encoder):Fl(r,li(t),e??je.encoder)}var lc=new WeakMap;function li(t){let e=lc.get(t);if(e==null){let r=new Map;return lc.set(t,r),r}return e}var fe=class t{code;version;multihash;bytes;"/";constructor(e,r,n,s){this.code=r,this.version=e,this.multihash=n,this.bytes=At(s),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:r}=this;if(e!==yr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Ml)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return t.createV0(r)}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:r}=this.multihash,n=Ht(e,r);return t.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 t.equals(this,e)}static equals(e,r){let n=r;return n!=null&&e.code===n.code&&e.version===n.version&&oc(e.multihash,n.multihash)}toString(e){return uc(this,e)}toJSON(){return{"/":uc(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 r=e;if(r instanceof t)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:s,multihash:o,bytes:c}=r;return new t(n,s,o,c??fc(n,s,o.bytes))}else if(r[Kl]===!0){let{version:n,multihash:s,code:o}=r,c=$e(s);return t.create(n,o,c)}else return null}static create(e,r,n){if(typeof r!="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(r!==yr)throw new Error(`Version 0 CID must use dag-pb (code: ${yr}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let s=fc(e,r,n.bytes);return new t(e,r,n,s)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,yr,e)}static createV1(e,r){return t.create(1,e,r)}static decode(e){let[r,n]=t.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(e){let r=t.inspectBytes(e),n=r.size-r.multihashSize,s=Se(e.subarray(n,n+r.multihashSize));if(s.byteLength!==r.multihashSize)throw new Error("Incorrect length");let o=s.subarray(r.multihashSize-r.digestSize),c=new $t(r.multihashCode,r.digestSize,o,s);return[r.version===0?t.createV0(c):t.createV1(r.codec,c),e.subarray(r.size)]}static inspectBytes(e){let r=0,n=()=>{let[f,d]=mr(e.subarray(r));return r+=d,f},s=n(),o=yr;if(s===18?(s=0,r=0):o=n(),s!==0&&s!==1)throw new RangeError(`Invalid CID version ${s}`);let c=r,i=n(),a=n(),u=r+a,l=u-c;return{version:s,codec:o,multihashCode:i,digestSize:a,multihashSize:l,size:u}}static parse(e,r){let[n,s]=Nl(e,r),o=t.decode(s);if(o.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return li(o).set(n,e),o}};function Nl(t,e){switch(t[0]){case"Q":{let r=e??ce;return[ce.prefix,r.decode(`${ce.prefix}${t}`)]}case ce.prefix:{let r=e??ce;return[ce.prefix,r.decode(t)]}case je.prefix:{let r=e??je;return[je.prefix,r.decode(t)]}case hr.prefix:{let r=e??hr;return[hr.prefix,r.decode(t)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[t[0],e.decode(t)]}}}function Ul(t,e,r){let{prefix:n}=r;if(n!==ce.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let s=e.get(n);if(s==null){let o=r.encode(t).slice(1);return e.set(n,o),o}else return s}function Fl(t,e,r){let{prefix:n}=r,s=e.get(n);if(s==null){let o=r.encode(t);return e.set(n,o),o}else return s}var yr=112,Ml=18;function fc(t,e,r){let n=Kt(t),s=n+Kt(e),o=new Uint8Array(s+r.byteLength);return Mt(t,o,0),Mt(e,o,n),o.set(r,s),o}var Kl=Symbol.for("@ipld/js-cid/CID");var br={...ri,...Yo,...ti,...Go,...Wo,...Zo,...jo,...Xo,...ei,...qo},wp={...ui,...oi};function hc(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var dc=hc("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),fi=hc("ascii","a",t=>{let e="a";for(let r=0;r<t.length;r++)e+=String.fromCharCode(t[r]);return e},t=>{t=t.substring(1);let e=Ce(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),$l={utf8:dc,"utf-8":dc,hex:br.base16,latin1:fi,ascii:fi,binary:fi,...br},tn=$l;function Te(t,e="utf8"){let r=tn[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return e==="utf8"||e==="utf-8"?dt(pc.Buffer.from(t,"utf-8")):r.decoder.decode(`${r.prefix}${t}`)}function di(t){let e=t??8192,r=e>>>1,n,s=e;return function(c){if(c<1||c>r)return Ce(c);s+c>e&&(n=Ce(e),s=0);let i=n.subarray(s,s+=c);return(s&7)!==0&&(s=(s|7)+1),i}}var Dt=class{fn;len;next;val;constructor(e,r,n){this.fn=e,this.len=r,this.next=void 0,this.val=n}};function hi(){}var mi=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},Hl=di();function zl(t){return globalThis.Buffer!=null?Ce(t):Hl(t)}var wr=class{len;head;tail;states;constructor(){this.len=0,this.head=new Dt(hi,0,0),this.tail=this.head,this.states=null}_push(e,r,n){return this.tail=this.tail.next=new Dt(e,r,n),this.len+=r,this}uint32(e){return this.len+=(this.tail=this.tail.next=new yi((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(rn,10,_e.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let r=_e.fromBigInt(e);return this._push(rn,r.length(),r)}uint64Number(e){return this._push(Ut,Be(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 r=_e.fromBigInt(e).zzEncode();return this._push(rn,r.length(),r)}sint64Number(e){let r=_e.fromNumber(e).zzEncode();return this._push(rn,r.length(),r)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(pi,1,e?1:0)}fixed32(e){return this._push(gr,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let r=_e.fromBigInt(e);return this._push(gr,4,r.lo)._push(gr,4,r.hi)}fixed64Number(e){let r=_e.fromNumber(e);return this._push(gr,4,r.lo)._push(gr,4,r.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(Ms,4,e)}double(e){return this._push($s,8,e)}bytes(e){let r=e.length>>>0;return r===0?this._push(pi,1,0):this.uint32(r)._push(Gl,r,e)}string(e){let r=Vs(e);return r!==0?this.uint32(r)._push(Mo,r,e):this._push(pi,1,0)}fork(){return this.states=new mi(this),this.head=this.tail=new Dt(hi,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 Dt(hi,0,0),this.len=0),this}ldelim(){let e=this.head,r=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=e.next,this.tail=r,this.len+=n),this}finish(){let e=this.head.next,r=zl(this.len),n=0;for(;e!=null;)e.fn(e.val,r,n),n+=e.len,e=e.next;return r}};function pi(t,e,r){e[r]=t&255}function Vl(t,e,r){for(;t>127;)e[r++]=t&127|128,t>>>=7;e[r]=t}var yi=class extends Dt{next;constructor(e,r){super(Vl,e,r),this.next=void 0}};function rn(t,e,r){for(;t.hi!==0;)e[r++]=t.lo&127|128,t.lo=(t.lo>>>7|t.hi<<25)>>>0,t.hi>>>=7;for(;t.lo>127;)e[r++]=t.lo&127|128,t.lo=t.lo>>>7;e[r++]=t.lo}function gr(t,e,r){e[r]=t&255,e[r+1]=t>>>8&255,e[r+2]=t>>>16&255,e[r+3]=t>>>24}function Gl(t,e,r){e.set(t,r)}globalThis.Buffer!=null&&(wr.prototype.bytes=function(t){let e=t.length>>>0;return this.uint32(e),e>0&&this._push(Wl,e,t),this},wr.prototype.string=function(t){let e=globalThis.Buffer.byteLength(t);return this.uint32(e),e>0&&this._push(Yl,e,t),this});function Wl(t,e,r){e.set(t,r)}function Yl(t,e,r){t.length<40?Mo(t,e,r):e.utf8Write!=null?e.utf8Write(t,r):e.set(Te(t),r)}function bi(){return new wr}function ee(t,e){let r=bi();return e.encode(t,r,{lengthDelimited:!1}),r.finish()}function*te(t,e,r){let n=dr(t);yield*e.stream(n,void 0,".",r)}var nn={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function on(t,e,r,n,s){return{name:t,type:e,encode:r,decode:n,stream:s}}function We(t){function e(o){if(t[o.toString()]==null)throw new Error("Invalid enum value");return t[o]}let r=function(c,i){let a=e(c);i.int32(a)},n=function(c){let i=c.int32();return e(i)},s=function*(c,i){};return on("enum",nn.VARINT,r,n,s)}function re(t,e,r){return on("message",nn.LENGTH_DELIMITED,t,e,r)}var W=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var z;(function(t){let e;(function(i){i.IDENTIFY="IDENTIFY",i.CONNECT="CONNECT",i.STREAM_OPEN="STREAM_OPEN",i.STREAM_HANDLER="STREAM_HANDLER",i.DHT="DHT",i.LIST_PEERS="LIST_PEERS",i.CONNMANAGER="CONNMANAGER",i.DISCONNECT="DISCONNECT",i.PUBSUB="PUBSUB",i.PEERSTORE="PEERSTORE"})(e=t.Type||(t.Type={}));let r;(function(i){i[i.IDENTIFY=0]="IDENTIFY",i[i.CONNECT=1]="CONNECT",i[i.STREAM_OPEN=2]="STREAM_OPEN",i[i.STREAM_HANDLER=3]="STREAM_HANDLER",i[i.DHT=4]="DHT",i[i.LIST_PEERS=5]="LIST_PEERS",i[i.CONNMANAGER=6]="CONNMANAGER",i[i.DISCONNECT=7]="DISCONNECT",i[i.PUBSUB=8]="PUBSUB",i[i.PEERSTORE=9]="PEERSTORE"})(r||(r={})),(function(i){i.codec=()=>We(r)})(e=t.Type||(t.Type={}));let n;t.codec=()=>(n==null&&(n=re((i,a,u={})=>{u.lengthDelimited!==!1&&a.fork(),i.type!=null&&(a.uint32(8),t.Type.codec().encode(i.type,a)),i.connect!=null&&(a.uint32(18),Er.codec().encode(i.connect,a)),i.streamOpen!=null&&(a.uint32(26),vr.codec().encode(i.streamOpen,a)),i.streamHandler!=null&&(a.uint32(34),Sr.codec().encode(i.streamHandler,a)),i.dht!=null&&(a.uint32(42),Pe.codec().encode(i.dht,a)),i.connManager!=null&&(a.uint32(50),Ar.codec().encode(i.connManager,a)),i.disconnect!=null&&(a.uint32(58),Dr.codec().encode(i.disconnect,a)),i.pubsub!=null&&(a.uint32(66),Xe.codec().encode(i.pubsub,a)),i.peerStore!=null&&(a.uint32(74),Cr.codec().encode(i.peerStore,a)),u.lengthDelimited!==!1&&a.ldelim()},(i,a,u={})=>{let l={},f=a==null?i.len:i.pos+a;for(;i.pos<f;){let d=i.uint32();switch(d>>>3){case 1:{l.type=t.Type.codec().decode(i);break}case 2:{l.connect=Er.codec().decode(i,i.uint32(),{limits:u.limits?.connect});break}case 3:{l.streamOpen=vr.codec().decode(i,i.uint32(),{limits:u.limits?.streamOpen});break}case 4:{l.streamHandler=Sr.codec().decode(i,i.uint32(),{limits:u.limits?.streamHandler});break}case 5:{l.dht=Pe.codec().decode(i,i.uint32(),{limits:u.limits?.dht});break}case 6:{l.connManager=Ar.codec().decode(i,i.uint32(),{limits:u.limits?.connManager});break}case 7:{l.disconnect=Dr.codec().decode(i,i.uint32(),{limits:u.limits?.disconnect});break}case 8:{l.pubsub=Xe.codec().decode(i,i.uint32(),{limits:u.limits?.pubsub});break}case 9:{l.peerStore=Cr.codec().decode(i,i.uint32(),{limits:u.limits?.peerStore});break}default:{i.skipType(d&7);break}}}return l},function*(i,a,u,l={}){let f=a==null?i.len:i.pos+a;for(;i.pos<f;){let d=i.uint32();switch(d>>>3){case 1:{yield{field:`${u}.type`,value:t.Type.codec().decode(i)};break}case 2:{yield*Er.codec().stream(i,i.uint32(),`${u}.connect`,{limits:l.limits?.connect});break}case 3:{yield*vr.codec().stream(i,i.uint32(),`${u}.streamOpen`,{limits:l.limits?.streamOpen});break}case 4:{yield*Sr.codec().stream(i,i.uint32(),`${u}.streamHandler`,{limits:l.limits?.streamHandler});break}case 5:{yield*Pe.codec().stream(i,i.uint32(),`${u}.dht`,{limits:l.limits?.dht});break}case 6:{yield*Ar.codec().stream(i,i.uint32(),`${u}.connManager`,{limits:l.limits?.connManager});break}case 7:{yield*Dr.codec().stream(i,i.uint32(),`${u}.disconnect`,{limits:l.limits?.disconnect});break}case 8:{yield*Xe.codec().stream(i,i.uint32(),`${u}.pubsub`,{limits:l.limits?.pubsub});break}case 9:{yield*Cr.codec().stream(i,i.uint32(),`${u}.peerStore`,{limits:l.limits?.peerStore});break}default:{i.skipType(d&7);break}}}})),n);function s(i){return ee(i,t.codec())}t.encode=s;function o(i,a){return J(i,t.codec(),a)}t.decode=o;function c(i,a){return te(i,t.codec(),a)}t.stream=c})(z||(z={}));var L;(function(t){let e;(function(i){i.OK="OK",i.ERROR="ERROR"})(e=t.Type||(t.Type={}));let r;(function(i){i[i.OK=0]="OK",i[i.ERROR=1]="ERROR"})(r||(r={})),(function(i){i.codec=()=>We(r)})(e=t.Type||(t.Type={}));let n;t.codec=()=>(n==null&&(n=re((i,a,u={})=>{if(u.lengthDelimited!==!1&&a.fork(),i.type!=null&&(a.uint32(8),t.Type.codec().encode(i.type,a)),i.error!=null&&(a.uint32(18),Tr.codec().encode(i.error,a)),i.streamInfo!=null&&(a.uint32(26),It.codec().encode(i.streamInfo,a)),i.identify!=null&&(a.uint32(34),xr.codec().encode(i.identify,a)),i.dht!=null&&(a.uint32(42),He.codec().encode(i.dht,a)),i.peers!=null&&i.peers.length>0)for(let l of i.peers)a.uint32(50),Ye.codec().encode(l,a);i.pubsub!=null&&(a.uint32(58),Ir.codec().encode(i.pubsub,a)),i.peerStore!=null&&(a.uint32(66),Br.codec().encode(i.peerStore,a)),u.lengthDelimited!==!1&&a.ldelim()},(i,a,u={})=>{let l={peers:[]},f=a==null?i.len:i.pos+a;for(;i.pos<f;){let d=i.uint32();switch(d>>>3){case 1:{l.type=t.Type.codec().decode(i);break}case 2:{l.error=Tr.codec().decode(i,i.uint32(),{limits:u.limits?.error});break}case 3:{l.streamInfo=It.codec().decode(i,i.uint32(),{limits:u.limits?.streamInfo});break}case 4:{l.identify=xr.codec().decode(i,i.uint32(),{limits:u.limits?.identify});break}case 5:{l.dht=He.codec().decode(i,i.uint32(),{limits:u.limits?.dht});break}case 6:{if(u.limits?.peers!=null&&l.peers.length===u.limits.peers)throw new W('Decode error - repeated field "peers" had too many elements');l.peers.push(Ye.codec().decode(i,i.uint32(),{limits:u.limits?.peers$}));break}case 7:{l.pubsub=Ir.codec().decode(i,i.uint32(),{limits:u.limits?.pubsub});break}case 8:{l.peerStore=Br.codec().decode(i,i.uint32(),{limits:u.limits?.peerStore});break}default:{i.skipType(d&7);break}}}return l},function*(i,a,u,l={}){let f={peers:0},d=a==null?i.len:i.pos+a;for(;i.pos<d;){let p=i.uint32();switch(p>>>3){case 1:{yield{field:`${u}.type`,value:t.Type.codec().decode(i)};break}case 2:{yield*Tr.codec().stream(i,i.uint32(),`${u}.error`,{limits:l.limits?.error});break}case 3:{yield*It.codec().stream(i,i.uint32(),`${u}.streamInfo`,{limits:l.limits?.streamInfo});break}case 4:{yield*xr.codec().stream(i,i.uint32(),`${u}.identify`,{limits:l.limits?.identify});break}case 5:{yield*He.codec().stream(i,i.uint32(),`${u}.dht`,{limits:l.limits?.dht});break}case 6:{if(l.limits?.peers!=null&&f.peers===l.limits.peers)throw new W('Streaming decode error - repeated field "peers" had too many elements');for(let E of Ye.codec().stream(i,i.uint32(),`${u}.peers[]`,{limits:l.limits?.peers$}))yield{...E,index:f.peers};f.peers++;break}case 7:{yield*Ir.codec().stream(i,i.uint32(),`${u}.pubsub`,{limits:l.limits?.pubsub});break}case 8:{yield*Br.codec().stream(i,i.uint32(),`${u}.peerStore`,{limits:l.limits?.peerStore});break}default:{i.skipType(p&7);break}}}})),n);function s(i){return ee(i,t.codec())}t.encode=s;function o(i,a){return J(i,t.codec(),a)}t.decode=o;function c(i,a){return te(i,t.codec(),a)}t.stream=c})(L||(L={}));var xr;(function(t){let e;t.codec=()=>(e==null&&(e=re((o,c,i={})=>{if(i.lengthDelimited!==!1&&c.fork(),o.id!=null&&o.id.byteLength>0&&(c.uint32(10),c.bytes(o.id)),o.addrs!=null&&o.addrs.length>0)for(let a of o.addrs)c.uint32(18),c.bytes(a);i.lengthDelimited!==!1&&c.ldelim()},(o,c,i={})=>{let a={id:le(0),addrs:[]},u=c==null?o.len:o.pos+c;for(;o.pos<u;){let l=o.uint32();switch(l>>>3){case 1:{a.id=o.bytes();break}case 2:{if(i.limits?.addrs!=null&&a.addrs.length===i.limits.addrs)throw new W('Decode error - repeated field "addrs" had too many elements');a.addrs.push(o.bytes());break}default:{o.skipType(l&7);break}}}return a},function*(o,c,i,a={}){let u={addrs:0},l=c==null?o.len:o.pos+c;for(;o.pos<l;){let f=o.uint32();switch(f>>>3){case 1:{yield{field:`${i}.id`,value:o.bytes()};break}case 2:{if(a.limits?.addrs!=null&&u.addrs===a.limits.addrs)throw new W('Streaming decode error - repeated field "addrs" had too many elements');yield{field:`${i}.addrs[]`,index:u.addrs,value:o.bytes()},u.addrs++;break}default:{o.skipType(f&7);break}}}})),e);function r(o){return ee(o,t.codec())}t.encode=r;function n(o,c){return J(o,t.codec(),c)}t.decode=n;function s(o,c){return te(o,t.codec(),c)}t.stream=s})(xr||(xr={}));var Er;(function(t){let e;t.codec=()=>(e==null&&(e=re((o,c,i={})=>{if(i.lengthDelimited!==!1&&c.fork(),o.peer!=null&&o.peer.byteLength>0&&(c.uint32(10),c.bytes(o.peer)),o.addrs!=null&&o.addrs.length>0)for(let a of o.addrs)c.uint32(18),c.bytes(a);o.timeout!=null&&(c.uint32(24),c.int64(o.timeout)),i.lengthDelimited!==!1&&c.ldelim()},(o,c,i={})=>{let a={peer:le(0),addrs:[]},u=c==null?o.len:o.pos+c;for(;o.pos<u;){let l=o.uint32();switch(l>>>3){case 1:{a.peer=o.bytes();break}case 2:{if(i.limits?.addrs!=null&&a.addrs.length===i.limits.addrs)throw new W('Decode error - repeated field "addrs" had too many elements');a.addrs.push(o.bytes());break}case 3:{a.timeout=o.int64();break}default:{o.skipType(l&7);break}}}return a},function*(o,c,i,a={}){let u={addrs:0},l=c==null?o.len:o.pos+c;for(;o.pos<l;){let f=o.uint32();switch(f>>>3){case 1:{yield{field:`${i}.peer`,value:o.bytes()};break}case 2:{if(a.limits?.addrs!=null&&u.addrs===a.limits.addrs)throw new W('Streaming decode error - repeated field "addrs" had too many elements');yield{field:`${i}.addrs[]`,index:u.addrs,value:o.bytes()},u.addrs++;break}case 3:{yield{field:`${i}.timeout`,value:o.int64()};break}default:{o.skipType(f&7);break}}}})),e);function r(o){return ee(o,t.codec())}t.encode=r;function n(o,c){return J(o,t.codec(),c)}t.decode=n;function s(o,c){return te(o,t.codec(),c)}t.stream=s})(Er||(Er={}));var vr;(function(t){let e;t.codec=()=>(e==null&&(e=re((o,c,i={})=>{if(i.lengthDelimited!==!1&&c.fork(),o.peer!=null&&o.peer.byteLength>0&&(c.uint32(10),c.bytes(o.peer)),o.proto!=null&&o.proto.length>0)for(let a of o.proto)c.uint32(18),c.string(a);o.timeout!=null&&(c.uint32(24),c.int64(o.timeout)),i.lengthDelimited!==!1&&c.ldelim()},(o,c,i={})=>{let a={peer:le(0),proto:[]},u=c==null?o.len:o.pos+c;for(;o.pos<u;){let l=o.uint32();switch(l>>>3){case 1:{a.peer=o.bytes();break}case 2:{if(i.limits?.proto!=null&&a.proto.length===i.limits.proto)throw new W('Decode error - repeated field "proto" had too many elements');a.proto.push(o.string());break}case 3:{a.timeout=o.int64();break}default:{o.skipType(l&7);break}}}return a},function*(o,c,i,a={}){let u={proto:0},l=c==null?o.len:o.pos+c;for(;o.pos<l;){let f=o.uint32();switch(f>>>3){case 1:{yield{field:`${i}.peer`,value:o.bytes()};break}case 2:{if(a.limits?.proto!=null&&u.proto===a.limits.proto)throw new W('Streaming decode error - repeated field "proto" had too many elements');yield{field:`${i}.proto[]`,index:u.proto,value:o.string()},u.proto++;break}case 3:{yield{field:`${i}.timeout`,value:o.int64()};break}default:{o.skipType(f&7);break}}}})),e);function r(o){return ee(o,t.codec())}t.encode=r;function n(o,c){return J(o,t.codec(),c)}t.decode=n;function s(o,c){return te(o,t.codec(),c)}t.stream=s})(vr||(vr={}));var Sr;(function(t){let e;t.codec=()=>(e==null&&(e=re((o,c,i={})=>{if(i.lengthDelimited!==!1&&c.fork(),o.addr!=null&&o.addr.byteLength>0&&(c.uint32(10),c.bytes(o.addr)),o.proto!=null&&o.proto.length>0)for(let a of o.proto)c.uint32(18),c.string(a);i.lengthDelimited!==!1&&c.ldelim()},(o,c,i={})=>{let a={addr:le(0),proto:[]},u=c==null?o.len:o.pos+c;for(;o.pos<u;){let l=o.uint32();switch(l>>>3){case 1:{a.addr=o.bytes();break}case 2:{if(i.limits?.proto!=null&&a.proto.length===i.limits.proto)throw new W('Decode error - repeated field "proto" had too many elements');a.proto.push(o.string());break}default:{o.skipType(l&7);break}}}return a},function*(o,c,i,a={}){let u={proto:0},l=c==null?o.len:o.pos+c;for(;o.pos<l;){let f=o.uint32();switch(f>>>3){case 1:{yield{field:`${i}.addr`,value:o.bytes()};break}case 2:{if(a.limits?.proto!=null&&u.proto===a.limits.proto)throw new W('Streaming decode error - repeated field "proto" had too many elements');yield{field:`${i}.proto[]`,index:u.proto,value:o.string()},u.proto++;break}default:{o.skipType(f&7);break}}}})),e);function r(o){return ee(o,t.codec())}t.encode=r;function n(o,c){return J(o,t.codec(),c)}t.decode=n;function s(o,c){return te(o,t.codec(),c)}t.stream=s})(Sr||(Sr={}));var Tr;(function(t){let e;t.codec=()=>(e==null&&(e=re((o,c,i={})=>{i.lengthDelimited!==!1&&c.fork(),o.msg!=null&&o.msg!==""&&(c.uint32(10),c.string(o.msg)),i.lengthDelimited!==!1&&c.ldelim()},(o,c,i={})=>{let a={msg:""},u=c==null?o.len:o.pos+c;for(;o.pos<u;){let l=o.uint32();l>>>3===1?a.msg=o.string():o.skipType(l&7)}return a},function*(o,c,i,a={}){let u=c==null?o.len:o.pos+c;for(;o.pos<u;){let l=o.uint32();l>>>3===1?yield{field:`${i}.msg`,value:o.string()}:o.skipType(l&7)}})),e);function r(o){return ee(o,t.codec())}t.encode=r;function n(o,c){return J(o,t.codec(),c)}t.decode=n;function s(o,c){return te(o,t.codec(),c)}t.stream=s})(Tr||(Tr={}));var It;(function(t){let e;t.codec=()=>(e==null&&(e=re((o,c,i={})=>{i.lengthDelimited!==!1&&c.fork(),o.peer!=null&&o.peer.byteLength>0&&(c.uint32(10),c.bytes(o.peer)),o.addr!=null&&o.addr.byteLength>0&&(c.uint32(18),c.bytes(o.addr)),o.proto!=null&&o.proto!==""&&(c.uint32(26),c.string(o.proto)),i.lengthDelimited!==!1&&c.ldelim()},(o,c,i={})=>{let a={peer:le(0),addr:le(0),proto:""},u=c==null?o.len:o.pos+c;for(;o.pos<u;){let l=o.uint32();switch(l>>>3){case 1:{a.peer=o.bytes();break}case 2:{a.addr=o.bytes();break}case 3:{a.proto=o.string();break}default:{o.skipType(l&7);break}}}return a},function*(o,c,i,a={}){let u=c==null?o.len:o.pos+c;for(;o.pos<u;){let l=o.uint32();switch(l>>>3){case 1:{yield{field:`${i}.peer`,value:o.bytes()};break}case 2:{yield{field:`${i}.addr`,value:o.bytes()};break}case 3:{yield{field:`${i}.proto`,value:o.string()};break}default:{o.skipType(l&7);break}}}})),e);function r(o){return ee(o,t.codec())}t.encode=r;function n(o,c){return J(o,t.codec(),c)}t.decode=n;function s(o,c){return te(o,t.codec(),c)}t.stream=s})(It||(It={}));var Pe;(function(t){let e;(function(i){i.FIND_PEER="FIND_PEER",i.FIND_PEERS_CONNECTED_TO_PEER="FIND_PEERS_CONNECTED_TO_PEER",i.FIND_PROVIDERS="FIND_PROVIDERS",i.GET_CLOSEST_PEERS="GET_CLOSEST_PEERS",i.GET_PUBLIC_KEY="GET_PUBLIC_KEY",i.GET_VALUE="GET_VALUE",i.SEARCH_VALUE="SEARCH_VALUE",i.PUT_VALUE="PUT_VALUE",i.PROVIDE="PROVIDE"})(e=t.Type||(t.Type={}));let r;(function(i){i[i.FIND_PEER=0]="FIND_PEER",i[i.FIND_PEERS_CONNECTED_TO_PEER=1]="FIND_PEERS_CONNECTED_TO_PEER",i[i.FIND_PROVIDERS=2]="FIND_PROVIDERS",i[i.GET_CLOSEST_PEERS=3]="GET_CLOSEST_PEERS",i[i.GET_PUBLIC_KEY=4]="GET_PUBLIC_KEY",i[i.GET_VALUE=5]="GET_VALUE",i[i.SEARCH_VALUE=6]="SEARCH_VALUE",i[i.PUT_VALUE=7]="PUT_VALUE",i[i.PROVIDE=8]="PROVIDE"})(r||(r={})),(function(i){i.codec=()=>We(r)})(e=t.Type||(t.Type={}));let n;t.codec=()=>(n==null&&(n=re((i,a,u={})=>{u.lengthDelimited!==!1&&a.fork(),i.type!=null&&(a.uint32(8),t.Type.codec().encode(i.type,a)),i.peer!=null&&(a.uint32(18),a.bytes(i.peer)),i.cid!=null&&(a.uint32(26),a.bytes(i.cid)),i.key!=null&&(a.uint32(34),a.bytes(i.key)),i.value!=null&&(a.uint32(42),a.bytes(i.value)),i.count!=null&&(a.uint32(48),a.int32(i.count)),i.timeout!=null&&(a.uint32(56),a.int64(i.timeout)),u.lengthDelimited!==!1&&a.ldelim()},(i,a,u={})=>{let l={},f=a==null?i.len:i.pos+a;for(;i.pos<f;){let d=i.uint32();switch(d>>>3){case 1:{l.type=t.Type.codec().decode(i);break}case 2:{l.peer=i.bytes();break}case 3:{l.cid=i.bytes();break}case 4:{l.key=i.bytes();break}case 5:{l.value=i.bytes();break}case 6:{l.count=i.int32();break}case 7:{l.timeout=i.int64();break}default:{i.skipType(d&7);break}}}return l},function*(i,a,u,l={}){let f=a==null?i.len:i.pos+a;for(;i.pos<f;){let d=i.uint32();switch(d>>>3){case 1:{yield{field:`${u}.type`,value:t.Type.codec().decode(i)};break}case 2:{yield{field:`${u}.peer`,value:i.bytes()};break}case 3:{yield{field:`${u}.cid`,value:i.bytes()};break}case 4:{yield{field:`${u}.key`,value:i.bytes()};break}case 5:{yield{field:`${u}.value`,value:i.bytes()};break}case 6:{yield{field:`${u}.count`,value:i.int32()};break}case 7:{yield{field:`${u}.timeout`,value:i.int64()};break}default:{i.skipType(d&7);break}}}})),n);function s(i){return ee(i,t.codec())}t.encode=s;function o(i,a){return J(i,t.codec(),a)}t.decode=o;function c(i,a){return te(i,t.codec(),a)}t.stream=c})(Pe||(Pe={}));var He;(function(t){let e;(function(i){i.BEGIN="BEGIN",i.VALUE="VALUE",i.END="END"})(e=t.Type||(t.Type={}));let r;(function(i){i[i.BEGIN=0]="BEGIN",i[i.VALUE=1]="VALUE",i[i.END=2]="END"})(r||(r={})),(function(i){i.codec=()=>We(r)})(e=t.Type||(t.Type={}));let n;t.codec=()=>(n==null&&(n=re((i,a,u={})=>{u.lengthDelimited!==!1&&a.fork(),i.type!=null&&(a.uint32(8),t.Type.codec().encode(i.type,a)),i.peer!=null&&(a.uint32(18),Ye.codec().encode(i.peer,a)),i.value!=null&&(a.uint32(26),a.bytes(i.value)),u.lengthDelimited!==!1&&a.ldelim()},(i,a,u={})=>{let l={},f=a==null?i.len:i.pos+a;for(;i.pos<f;){let d=i.uint32();switch(d>>>3){case 1:{l.type=t.Type.codec().decode(i);break}case 2:{l.peer=Ye.codec().decode(i,i.uint32(),{limits:u.limits?.peer});break}case 3:{l.value=i.bytes();break}default:{i.skipType(d&7);break}}}return l},function*(i,a,u,l={}){let f=a==null?i.len:i.pos+a;for(;i.pos<f;){let d=i.uint32();switch(d>>>3){case 1:{yield{field:`${u}.type`,value:t.Type.codec().decode(i)};break}case 2:{yield*Ye.codec().stream(i,i.uint32(),`${u}.peer`,{limits:l.limits?.peer});break}case 3:{yield{field:`${u}.value`,value:i.bytes()};break}default:{i.skipType(d&7);break}}}})),n);function s(i){return ee(i,t.codec())}t.encode=s;function o(i,a){return J(i,t.codec(),a)}t.decode=o;function c(i,a){return te(i,t.codec(),a)}t.stream=c})(He||(He={}));var Ye;(function(t){let e;t.codec=()=>(e==null&&(e=re((o,c,i={})=>{if(i.lengthDelimited!==!1&&c.fork(),o.id!=null&&o.id.byteLength>0&&(c.uint32(10),c.bytes(o.id)),o.addrs!=null&&o.addrs.length>0)for(let a of o.addrs)c.uint32(18),c.bytes(a);i.lengthDelimited!==!1&&c.ldelim()},(o,c,i={})=>{let a={id:le(0),addrs:[]},u=c==null?o.len:o.pos+c;for(;o.pos<u;){let l=o.uint32();switch(l>>>3){case 1:{a.id=o.bytes();break}case 2:{if(i.limits?.addrs!=null&&a.addrs.length===i.limits.addrs)throw new W('Decode error - repeated field "addrs" had too many elements');a.addrs.push(o.bytes());break}default:{o.skipType(l&7);break}}}return a},function*(o,c,i,a={}){let u={addrs:0},l=c==null?o.len:o.pos+c;for(;o.pos<l;){let f=o.uint32();switch(f>>>3){case 1:{yield{field:`${i}.id`,value:o.bytes()};break}case 2:{if(a.limits?.addrs!=null&&u.addrs===a.limits.addrs)throw new W('Streaming decode error - repeated field "addrs" had too many elements');yield{field:`${i}.addrs[]`,index:u.addrs,value:o.bytes()},u.addrs++;break}default:{o.skipType(f&7);break}}}})),e);function r(o){return ee(o,t.codec())}t.encode=r;function n(o,c){return J(o,t.codec(),c)}t.decode=n;function s(o,c){return te(o,t.codec(),c)}t.stream=s})(Ye||(Ye={}));var Ar;(function(t){let e;(function(i){i.TAG_PEER="TAG_PEER",i.UNTAG_PEER="UNTAG_PEER",i.TRIM="TRIM"})(e=t.Type||(t.Type={}));let r;(function(i){i[i.TAG_PEER=0]="TAG_PEER",i[i.UNTAG_PEER=1]="UNTAG_PEER",i[i.TRIM=2]="TRIM"})(r||(r={})),(function(i){i.codec=()=>We(r)})(e=t.Type||(t.Type={}));let n;t.codec=()=>(n==null&&(n=re((i,a,u={})=>{u.lengthDelimited!==!1&&a.fork(),i.type!=null&&(a.uint32(8),t.Type.codec().encode(i.type,a)),i.peer!=null&&(a.uint32(18),a.bytes(i.peer)),i.tag!=null&&(a.uint32(26),a.string(i.tag)),i.weight!=null&&(a.uint32(32),a.int64(i.weight)),u.lengthDelimited!==!1&&a.ldelim()},(i,a,u={})=>{let l={},f=a==null?i.len:i.pos+a;for(;i.pos<f;){let d=i.uint32();switch(d>>>3){case 1:{l.type=t.Type.codec().decode(i);break}case 2:{l.peer=i.bytes();break}case 3:{l.tag=i.string();break}case 4:{l.weight=i.int64();break}default:{i.skipType(d&7);break}}}return l},function*(i,a,u,l={}){let f=a==null?i.len:i.pos+a;for(;i.pos<f;){let d=i.uint32();switch(d>>>3){case 1:{yield{field:`${u}.type`,value:t.Type.codec().decode(i)};break}case 2:{yield{field:`${u}.peer`,value:i.bytes()};break}case 3:{yield{field:`${u}.tag`,value:i.string()};break}case 4:{yield{field:`${u}.weight`,value:i.int64()};break}default:{i.skipType(d&7);break}}}})),n);function s(i){return ee(i,t.codec())}t.encode=s;function o(i,a){return J(i,t.codec(),a)}t.decode=o;function c(i,a){return te(i,t.codec(),a)}t.stream=c})(Ar||(Ar={}));var Dr;(function(t){let e;t.codec=()=>(e==null&&(e=re((o,c,i={})=>{i.lengthDelimited!==!1&&c.fork(),o.peer!=null&&o.peer.byteLength>0&&(c.uint32(10),c.bytes(o.peer)),i.lengthDelimited!==!1&&c.ldelim()},(o,c,i={})=>{let a={peer:le(0)},u=c==null?o.len:o.pos+c;for(;o.pos<u;){let l=o.uint32();l>>>3===1?a.peer=o.bytes():o.skipType(l&7)}return a},function*(o,c,i,a={}){let u=c==null?o.len:o.pos+c;for(;o.pos<u;){let l=o.uint32();l>>>3===1?yield{field:`${i}.peer`,value:o.bytes()}:o.skipType(l&7)}})),e);function r(o){return ee(o,t.codec())}t.encode=r;function n(o,c){return J(o,t.codec(),c)}t.decode=n;function s(o,c){return te(o,t.codec(),c)}t.stream=s})(Dr||(Dr={}));var Xe;(function(t){let e;(function(i){i.GET_TOPICS="GET_TOPICS",i.LIST_PEERS="LIST_PEERS",i.PUBLISH="PUBLISH",i.SUBSCRIBE="SUBSCRIBE"})(e=t.Type||(t.Type={}));let r;(function(i){i[i.GET_TOPICS=0]="GET_TOPICS",i[i.LIST_PEERS=1]="LIST_PEERS",i[i.PUBLISH=2]="PUBLISH",i[i.SUBSCRIBE=3]="SUBSCRIBE"})(r||(r={})),(function(i){i.codec=()=>We(r)})(e=t.Type||(t.Type={}));let n;t.codec=()=>(n==null&&(n=re((i,a,u={})=>{u.lengthDelimited!==!1&&a.fork(),i.type!=null&&(a.uint32(8),t.Type.codec().encode(i.type,a)),i.topic!=null&&(a.uint32(18),a.string(i.topic)),i.data!=null&&(a.uint32(26),a.bytes(i.data)),u.lengthDelimited!==!1&&a.ldelim()},(i,a,u={})=>{let l={},f=a==null?i.len:i.pos+a;for(;i.pos<f;){let d=i.uint32();switch(d>>>3){case 1:{l.type=t.Type.codec().decode(i);break}case 2:{l.topic=i.string();break}case 3:{l.data=i.bytes();break}default:{i.skipType(d&7);break}}}return l},function*(i,a,u,l={}){let f=a==null?i.len:i.pos+a;for(;i.pos<f;){let d=i.uint32();switch(d>>>3){case 1:{yield{field:`${u}.type`,value:t.Type.codec().decode(i)};break}case 2:{yield{field:`${u}.topic`,value:i.string()};break}case 3:{yield{field:`${u}.data`,value:i.bytes()};break}default:{i.skipType(d&7);break}}}})),n);function s(i){return ee(i,t.codec())}t.encode=s;function o(i,a){return J(i,t.codec(),a)}t.decode=o;function c(i,a){return te(i,t.codec(),a)}t.stream=c})(Xe||(Xe={}));var sn;(function(t){let e;t.codec=()=>(e==null&&(e=re((o,c,i={})=>{if(i.lengthDelimited!==!1&&c.fork(),o.from!=null&&(c.uint32(10),c.bytes(o.from)),o.data!=null&&(c.uint32(18),c.bytes(o.data)),o.seqno!=null&&(c.uint32(26),c.bytes(o.seqno)),o.topicIDs!=null&&o.topicIDs.length>0)for(let a of o.topicIDs)c.uint32(34),c.string(a);o.signature!=null&&(c.uint32(42),c.bytes(o.signature)),o.key!=null&&(c.uint32(50),c.bytes(o.key)),i.lengthDelimited!==!1&&c.ldelim()},(o,c,i={})=>{let a={topicIDs:[]},u=c==null?o.len:o.pos+c;for(;o.pos<u;){let l=o.uint32();switch(l>>>3){case 1:{a.from=o.bytes();break}case 2:{a.data=o.bytes();break}case 3:{a.seqno=o.bytes();break}case 4:{if(i.limits?.topicIDs!=null&&a.topicIDs.length===i.limits.topicIDs)throw new W('Decode error - repeated field "topicIDs" had too many elements');a.topicIDs.push(o.string());break}case 5:{a.signature=o.bytes();break}case 6:{a.key=o.bytes();break}default:{o.skipType(l&7);break}}}return a},function*(o,c,i,a={}){let u={topicIDs:0},l=c==null?o.len:o.pos+c;for(;o.pos<l;){let f=o.uint32();switch(f>>>3){case 1:{yield{field:`${i}.from`,value:o.bytes()};break}case 2:{yield{field:`${i}.data`,value:o.bytes()};break}case 3:{yield{field:`${i}.seqno`,value:o.bytes()};break}case 4:{if(a.limits?.topicIDs!=null&&u.topicIDs===a.limits.topicIDs)throw new W('Streaming decode error - repeated field "topicIDs" had too many elements');yield{field:`${i}.topicIDs[]`,index:u.topicIDs,value:o.string()},u.topicIDs++;break}case 5:{yield{field:`${i}.signature`,value:o.bytes()};break}case 6:{yield{field:`${i}.key`,value:o.bytes()};break}default:{o.skipType(f&7);break}}}})),e);function r(o){return ee(o,t.codec())}t.encode=r;function n(o,c){return J(o,t.codec(),c)}t.decode=n;function s(o,c){return te(o,t.codec(),c)}t.stream=s})(sn||(sn={}));var Ir;(function(t){let e;t.codec=()=>(e==null&&(e=re((o,c,i={})=>{if(i.lengthDelimited!==!1&&c.fork(),o.topics!=null&&o.topics.length>0)for(let a of o.topics)c.uint32(10),c.string(a);if(o.peerIDs!=null&&o.peerIDs.length>0)for(let a of o.peerIDs)c.uint32(18),c.bytes(a);i.lengthDelimited!==!1&&c.ldelim()},(o,c,i={})=>{let a={topics:[],peerIDs:[]},u=c==null?o.len:o.pos+c;for(;o.pos<u;){let l=o.uint32();switch(l>>>3){case 1:{if(i.limits?.topics!=null&&a.topics.length===i.limits.topics)throw new W('Decode error - repeated field "topics" had too many elements');a.topics.push(o.string());break}case 2:{if(i.limits?.peerIDs!=null&&a.peerIDs.length===i.limits.peerIDs)throw new W('Decode error - repeated field "peerIDs" had too many elements');a.peerIDs.push(o.bytes());break}default:{o.skipType(l&7);break}}}return a},function*(o,c,i,a={}){let u={topics:0,peerIDs:0},l=c==null?o.len:o.pos+c;for(;o.pos<l;){let f=o.uint32();switch(f>>>3){case 1:{if(a.limits?.topics!=null&&u.topics===a.limits.topics)throw new W('Streaming decode error - repeated field "topics" had too many elements');yield{field:`${i}.topics[]`,index:u.topics,value:o.string()},u.topics++;break}case 2:{if(a.limits?.peerIDs!=null&&u.peerIDs===a.limits.peerIDs)throw new W('Streaming decode error - repeated field "peerIDs" had too many elements');yield{field:`${i}.peerIDs[]`,index:u.peerIDs,value:o.bytes()},u.peerIDs++;break}default:{o.skipType(f&7);break}}}})),e);function r(o){return ee(o,t.codec())}t.encode=r;function n(o,c){return J(o,t.codec(),c)}t.decode=n;function s(o,c){return te(o,t.codec(),c)}t.stream=s})(Ir||(Ir={}));var Cr;(function(t){let e;(function(i){i.UNSPECIFIED="UNSPECIFIED",i.GET_PROTOCOLS="GET_PROTOCOLS",i.GET_PEER_INFO="GET_PEER_INFO"})(e=t.Type||(t.Type={}));let r;(function(i){i[i.UNSPECIFIED=0]="UNSPECIFIED",i[i.GET_PROTOCOLS=1]="GET_PROTOCOLS",i[i.GET_PEER_INFO=2]="GET_PEER_INFO"})(r||(r={})),(function(i){i.codec=()=>We(r)})(e=t.Type||(t.Type={}));let n;t.codec=()=>(n==null&&(n=re((i,a,u={})=>{if(u.lengthDelimited!==!1&&a.fork(),i.type!=null&&(a.uint32(8),t.Type.codec().encode(i.type,a)),i.id!=null&&(a.uint32(18),a.bytes(i.id)),i.protos!=null&&i.protos.length>0)for(let l of i.protos)a.uint32(26),a.string(l);u.lengthDelimited!==!1&&a.ldelim()},(i,a,u={})=>{let l={protos:[]},f=a==null?i.len:i.pos+a;for(;i.pos<f;){let d=i.uint32();switch(d>>>3){case 1:{l.type=t.Type.codec().decode(i);break}case 2:{l.id=i.bytes();break}case 3:{if(u.limits?.protos!=null&&l.protos.length===u.limits.protos)throw new W('Decode error - repeated field "protos" had too many elements');l.protos.push(i.string());break}default:{i.skipType(d&7);break}}}return l},function*(i,a,u,l={}){let f={protos:0},d=a==null?i.len:i.pos+a;for(;i.pos<d;){let p=i.uint32();switch(p>>>3){case 1:{yield{field:`${u}.type`,value:t.Type.codec().decode(i)};break}case 2:{yield{field:`${u}.id`,value:i.bytes()};break}case 3:{if(l.limits?.protos!=null&&f.protos===l.limits.protos)throw new W('Streaming decode error - repeated field "protos" had too many elements');yield{field:`${u}.protos[]`,index:f.protos,value:i.string()},f.protos++;break}default:{i.skipType(p&7);break}}}})),n);function s(i){return ee(i,t.codec())}t.encode=s;function o(i,a){return J(i,t.codec(),a)}t.decode=o;function c(i,a){return te(i,t.codec(),a)}t.stream=c})(Cr||(Cr={}));var Br;(function(t){let e;t.codec=()=>(e==null&&(e=re((o,c,i={})=>{if(i.lengthDelimited!==!1&&c.fork(),o.peer!=null&&(c.uint32(10),Ye.codec().encode(o.peer,c)),o.protos!=null&&o.protos.length>0)for(let a of o.protos)c.uint32(18),c.string(a);i.lengthDelimited!==!1&&c.ldelim()},(o,c,i={})=>{let a={protos:[]},u=c==null?o.len:o.pos+c;for(;o.pos<u;){let l=o.uint32();switch(l>>>3){case 1:{a.peer=Ye.codec().decode(o,o.uint32(),{limits:i.limits?.peer});break}case 2:{if(i.limits?.protos!=null&&a.protos.length===i.limits.protos)throw new W('Decode error - repeated field "protos" had too many elements');a.protos.push(o.string());break}default:{o.skipType(l&7);break}}}return a},function*(o,c,i,a={}){let u={protos:0},l=c==null?o.len:o.pos+c;for(;o.pos<l;){let f=o.uint32();switch(f>>>3){case 1:{yield*Ye.codec().stream(o,o.uint32(),`${i}.peer`,{limits:a.limits?.peer});break}case 2:{if(a.limits?.protos!=null&&u.protos===a.limits.protos)throw new W('Streaming decode error - repeated field "protos" had too many elements');yield{field:`${i}.protos[]`,index:u.protos,value:o.string()},u.protos++;break}default:{o.skipType(f&7);break}}}})),e);function r(o){return ee(o,t.codec())}t.encode=r;function n(o,c){return J(o,t.codec(),c)}t.decode=n;function s(o,c){return te(o,t.codec(),c)}t.stream=s})(Br||(Br={}));function mc(t){let e=new globalThis.AbortController;function r(){let o=t.filter(c=>c?.aborted===!0).map(c=>c?.reason).pop();e.abort(o);for(let c of t)c?.removeEventListener!=null&&c.removeEventListener("abort",r)}for(let o of t){if(o?.aborted===!0){r();break}o?.addEventListener!=null&&o.addEventListener("abort",r)}function n(){for(let o of t)o?.removeEventListener!=null&&o.removeEventListener("abort",r)}let s=e.signal;return s.clear=n,s}var Lr=class{onConnection;constructor(e){this.onConnection=e}async upgradeInbound(e){this.onConnection?.(e)}async upgradeOutbound(e){return e}createInboundAbortSignal(e){return mc([e])}getStreamMuxers(){return new Map}getConnectionEncrypters(){return new Map}};var cn=class extends Error{static name="AbortError";constructor(e="The operation was aborted"){super(e),this.name="AbortError"}};var B=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}},Or=class extends Error{static name="InvalidPublicKeyError";constructor(e="Invalid public key"){super(e),this.name="InvalidPublicKeyError"}};var an=class extends Error{static name="StreamResetError";constructor(e="The stream has been reset"){super(e),this.name="StreamResetError"}};var yt=class extends Error{static name="StreamStateError";constructor(e="The stream is in an invalid state"){super(e),this.name="StreamStateError"}},Ct=class extends Error{static name="StreamBufferError";constructor(e="The stream buffer was full"){super(e),this.name="StreamBufferError"}};var un=class extends Error{static name="InvalidMultihashError";constructor(e="Invalid Multihash"){super(e),this.name="InvalidMultihashError"}};var kr=class extends Error{static name="InvalidMessageError";constructor(e="Invalid message"){super(e),this.name="InvalidMessageError"}},_r=class extends Error{static name="ProtocolError";constructor(e="Protocol error"){super(e),this.name="ProtocolError"}},zt=class extends Error{static name="TimeoutError";constructor(e="Timed out"){super(e),this.name="TimeoutError"}},ln=class extends Error{static name="NotStartedError";constructor(e="Not started"){super(e),this.name="NotStartedError"}},fn=class extends Error{static name="AlreadyStartedError";constructor(e="Already started"){super(e),this.name="AlreadyStartedError"}};var Pr=class extends Error{static name="UnsupportedKeyTypeError";constructor(e="Unsupported key type"){super(e),this.name="UnsupportedKeyTypeError"}};var dn=class extends Event{data;constructor(e,r){super("message",r),this.data=e}},Vt=class extends Event{error;local;constructor(e,r,n){super("close",n),this.error=r,this.local=e}},hn=class extends Vt{constructor(e,r){super(!0,e,r)}},pn=class extends Vt{constructor(e,r){super(!1,e,r)}};var mn=Symbol.for("@libp2p/peer-id");function Gt(t){return!!t?.[mn]}var bc=Symbol.for("@libp2p/transport");var yc;(function(t){t[t.FATAL_ALL=0]="FATAL_ALL",t[t.NO_FATAL=1]="NO_FATAL"})(yc||(yc={}));var gc=ue("node:events"),yn=(t,...e)=>{try{(0,gc.setMaxListeners)(t,...e)}catch{}};function ql(t){return typeof t?.handleEvent=="function"}function Zl(t){return t===!0||t===!1}function jl(t){return Zl(t)?t:t?.capture??!1}function gi(t){let e={capture:jl(t),once:!!t?.once};return t?.passive!=null&&(e.passive=t?.passive),t?.signal!=null&&(e.signal=t?.signal),e}function wc(t,e){return gi(t).capture===gi(e).capture}var Wt=class extends EventTarget{#e=new Map;constructor(){super(),yn(1/0,this)}listenerCount(e){let r=this.#e.get(e);return r==null?0:r.length}addEventListener(e,r,n){let s=gi(n);if(s?.signal?.aborted===!0)return;let o=u=>{s.once&&this.removeEventListener(e,r,s),ql(r)?r.handleEvent(u):r(u)},c=this.#e.get(e);if(c==null&&(c=[],this.#e.set(e,c)),c.some(u=>u.callback!==r?!1:wc(u.options,s)))return;super.addEventListener(e,o,s);let a=()=>{this.removeEventListener(e,r,s)};s.signal?.addEventListener("abort",a),c.push({callback:r,wrapper:o,options:s,onAbort:a})}removeEventListener(e,r,n){let s=this.#e.get(e);if(s==null){super.removeEventListener(e,r??null,n);return}this.#e.set(e,s.filter(o=>o.callback===r&&wc(o.options,n)?(super.removeEventListener(e,o.wrapper,n),o.options?.signal?.removeEventListener("abort",o.onAbort),!1):!0))}safeDispatchEvent(e,r={}){return this.dispatchEvent(new CustomEvent(e,r))}};var xc=Symbol.for("@libp2p/service-capabilities");var Sc=ke(ue("node:tty"),1),En=ke(ue("node:util"),1);function bn(t,e){if(typeof t=="string")return Xl(t);if(typeof t=="number")return ef(t,e);throw new Error(`Value provided to ms() must be a string or number. value=${JSON.stringify(t)}`)}function Xl(t){if(typeof t!="string"||t.length===0||t.length>100)throw new Error(`Value provided to ms.parse() must be a string with length between 1 and 99. value=${JSON.stringify(t)}`);let e=/^(?<value>-?\d*\.?\d+) *(?<unit>milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|months?|mo|years?|yrs?|y)?$/i.exec(t);if(!e?.groups)return NaN;let{value:r,unit:n="ms"}=e.groups,s=parseFloat(r),o=n.toLowerCase();switch(o){case"years":case"year":case"yrs":case"yr":case"y":return s*315576e5;case"months":case"month":case"mo":return s*26298e5;case"weeks":case"week":case"w":return s*6048e5;case"days":case"day":case"d":return s*864e5;case"hours":case"hour":case"hrs":case"hr":case"h":return s*36e5;case"minutes":case"minute":case"mins":case"min":case"m":return s*6e4;case"seconds":case"second":case"secs":case"sec":case"s":return s*1e3;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return s;default:throw new Error(`Unknown unit "${o}" provided to ms.parse(). value=${JSON.stringify(t)}`)}}function Ql(t){let e=Math.abs(t);return e>=315576e5?`${Math.round(t/315576e5)}y`:e>=26298e5?`${Math.round(t/26298e5)}mo`:e>=6048e5?`${Math.round(t/6048e5)}w`:e>=864e5?`${Math.round(t/864e5)}d`:e>=36e5?`${Math.round(t/36e5)}h`:e>=6e4?`${Math.round(t/6e4)}m`:e>=1e3?`${Math.round(t/1e3)}s`:`${t}ms`}function Jl(t){let e=Math.abs(t);return e>=315576e5?Bt(t,e,315576e5,"year"):e>=26298e5?Bt(t,e,26298e5,"month"):e>=6048e5?Bt(t,e,6048e5,"week"):e>=864e5?Bt(t,e,864e5,"day"):e>=36e5?Bt(t,e,36e5,"hour"):e>=6e4?Bt(t,e,6e4,"minute"):e>=1e3?Bt(t,e,1e3,"second"):`${t} ms`}function ef(t,e){if(typeof t!="number"||!Number.isFinite(t))throw new Error("Value provided to ms.format() must be of type number.");return e?.long?Jl(t):Ql(t)}function Bt(t,e,r,n){let s=e>=r*1.5;return`${Math.round(t/r)} ${n}${s?"s":""}`}var wn=ke(ue("node:process"),1),vc=ke(ue("node:os"),1),wi=ke(ue("node:tty"),1);function ze(t,e=globalThis.Deno?globalThis.Deno.args:wn.default.argv){let r=t.startsWith("-")?"":t.length===1?"-":"--",n=e.indexOf(r+t),s=e.indexOf("--");return n!==-1&&(s===-1||n<s)}var{env:X}=wn.default,gn;ze("no-color")||ze("no-colors")||ze("color=false")||ze("color=never")?gn=0:(ze("color")||ze("colors")||ze("color=true")||ze("color=always"))&&(gn=1);function tf(){if(!("FORCE_COLOR"in X))return;if(X.FORCE_COLOR==="true")return 1;if(X.FORCE_COLOR==="false")return 0;if(X.FORCE_COLOR.length===0)return 1;let t=Math.min(Number.parseInt(X.FORCE_COLOR,10),3);if([0,1,2,3].includes(t))return t}function rf(t){return t===0?!1:{level:t,hasBasic:!0,has256:t>=2,has16m:t>=3}}function nf(t,{streamIsTTY:e,sniffFlags:r=!0}={}){let n=tf();n!==void 0&&(gn=n);let s=r?gn:n;if(s===0)return 0;if(r){if(ze("color=16m")||ze("color=full")||ze("color=truecolor"))return 3;if(ze("color=256"))return 2}if("TF_BUILD"in X&&"AGENT_NAME"in X)return 1;if(t&&!e&&s===void 0)return 0;let o=s||0;if(X.TERM==="dumb")return o;if(wn.default.platform==="win32"){let c=vc.default.release().split(".");return Number(c[0])>=10&&Number(c[2])>=10586?Number(c[2])>=14931?3:2:1}if("CI"in X)return["GITHUB_ACTIONS","GITEA_ACTIONS","CIRCLECI"].some(c=>c in X)?3:["TRAVIS","APPVEYOR","GITLAB_CI","BUILDKITE","DRONE"].some(c=>c in X)||X.CI_NAME==="codeship"?1:o;if("TEAMCITY_VERSION"in X)return/^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(X.TEAMCITY_VERSION)?1:0;if(X.COLORTERM==="truecolor"||X.TERM==="xterm-kitty"||X.TERM==="xterm-ghostty"||X.TERM==="wezterm")return 3;if("TERM_PROGRAM"in X){let c=Number.parseInt((X.TERM_PROGRAM_VERSION||"").split(".")[0],10);switch(X.TERM_PROGRAM){case"iTerm.app":return c>=3?3:2;case"Apple_Terminal":return 2}}return/-256(color)?$/i.test(X.TERM)?2:/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(X.TERM)||"COLORTERM"in X?1:o}function Ec(t,e={}){let r=nf(t,{streamIsTTY:t&&t.isTTY,...e});return rf(r)}var of={stdout:Ec({isTTY:wi.default.isatty(1)}),stderr:Ec({isTTY:wi.default.isatty(2)})},xn=of;function xi(t){r.debug=r,r.default=r,r.coerce=a,r.disable=o,r.enable=s,r.enabled=c,r.humanize=bn,r.destroy=u,Object.keys(t).forEach(l=>{r[l]=t[l]}),r.names=[],r.skips=[],r.formatters={};function e(l){let f=0;for(let d=0;d<l.length;d++)f=(f<<5)-f+l.charCodeAt(d),f|=0;return r.colors[Math.abs(f)%r.colors.length]}r.selectColor=e;function r(l,f){let d,p=null,E,D;function b(...y){if(!b.enabled)return;let T=b,P=Number(new Date),_=P-(d||P);T.diff=_,T.prev=d,T.curr=P,d=P,y[0]=r.coerce(y[0]),typeof y[0]!="string"&&y.unshift("%O");let F=0;y[0]=y[0].replace(/%([a-zA-Z%])/g,(G,pe)=>{if(G==="%%")return"%";F++;let me=r.formatters[pe];if(typeof me=="function"){let H=y[F];G=me.call(T,H),y.splice(F,1),F--}return G}),r.formatArgs.call(T,y),f?.onLog!=null&&f.onLog(...y),(T.log||r.log).apply(T,y)}return b.namespace=l,b.useColors=r.useColors(),b.color=r.selectColor(l),b.extend=n,b.destroy=r.destroy,Object.defineProperty(b,"enabled",{enumerable:!0,configurable:!1,get:()=>p!==null?p:(E!==r.namespaces&&(E=r.namespaces,D=r.enabled(l)),D),set:y=>{p=y}}),typeof r.init=="function"&&r.init(b),b}function n(l,f){let d=r(this.namespace+(typeof f>"u"?":":f)+l);return d.log=this.log,d}function s(l){r.save(l),r.namespaces=l,r.names=[],r.skips=[];let f,d=(typeof l=="string"?l:"").split(/[\s,]+/),p=d.length;for(f=0;f<p;f++)d[f]&&(l=d[f].replace(/\*/g,".*?"),l[0]==="-"?r.skips.push(new RegExp("^"+l.substr(1)+"$")):r.names.push(new RegExp("^"+l+"$")))}function o(){let l=[...r.names.map(i),...r.skips.map(i).map(f=>"-"+f)].join(",");return r.enable(""),l}function c(l){if(l[l.length-1]==="*")return!0;let f,d;for(f=0,d=r.skips.length;f<d;f++)if(r.skips[f].test(l))return!1;for(f=0,d=r.names.length;f<d;f++)if(r.names[f].test(l))return!0;return!1}function i(l){return l.toString().substring(2,l.toString().length-2).replace(/\.\*\?$/,"*")}function a(l){return l instanceof Error?l.stack??l.message:l}function u(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")}return r.setupFormatters(r.formatters),r.enable(r.load()),r}var Tc=[6,2,3,4,5,1];xn.stderr!==!1&&(xn.stderr??xn).level>=2&&(Tc=[20,21,26,27,32,33,38,39,40,41,42,43,44,45,56,57,62,63,68,69,74,75,76,77,78,79,80,81,92,93,98,99,112,113,128,129,134,135,148,149,160,161,162,163,164,165,166,167,168,169,170,171,172,173,178,179,184,185,196,197,198,199,200,201,202,203,204,205,206,207,208,209,214,215,220,221]);var Yt=Object.keys(process.env).filter(t=>/^debug_/i.test(t)).reduce((t,e)=>{let r=e.substring(6).toLowerCase().replace(/_([a-z])/g,(s,o)=>o.toUpperCase()),n=process.env[e];return/^(yes|on|true|enabled)$/i.test(n)?n=!0:/^(no|off|false|disabled)$/i.test(n)?n=!1:n==="null"?n=null:n=Number(n),t[r]=n,t},{});function sf(){return"colors"in Yt?!!Yt.colors:Sc.default.isatty(process.stderr.fd)}function cf(t){let{namespace:e,useColors:r}=this;if(r===!0){let n=this.color,s="\x1B[3"+(n<8?n:"8;5;"+n),o=` ${s};1m${e} \x1B[0m`;t[0]=o+t[0].split(`
2
+ "use strict";var Libp2PDaemonClient=(()=>{var Eu=Object.create;var Qr=Object.defineProperty;var vu=Object.getOwnPropertyDescriptor;var Su=Object.getOwnPropertyNames;var Tu=Object.getPrototypeOf,Au=Object.prototype.hasOwnProperty;var le=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(e,r)=>(typeof require<"u"?require:e)[r]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')});var ke=(t,e)=>{for(var r in e)Qr(t,r,{get:e[r],enumerable:!0})},Ns=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of Su(e))!Au.call(t,s)&&s!==r&&Qr(t,s,{get:()=>e[s],enumerable:!(n=vu(e,s))||n.enumerable});return t};var _e=(t,e,r)=>(r=t!=null?Eu(Tu(t)):{},Ns(e||!t||!t.__esModule?Qr(r,"default",{value:t,enumerable:!0}):r,t)),Du=t=>Ns(Qr({},"__esModule",{value:!0}),t);var wh={};ke(wh,{OperationFailedError:()=>z,createClient:()=>gh});var Oo=le("node:buffer");function ht(t){if(t.buffer instanceof ArrayBuffer)return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);let e=t.slice();return new Uint8Array(e.buffer,0,e.byteLength)}function fe(t=0){return ht(Oo.Buffer.alloc(t))}function Ce(t=0){return ht(Oo.Buffer.allocUnsafe(t))}var Iu=Math.pow(2,7),Cu=Math.pow(2,14),Bu=Math.pow(2,21),ko=Math.pow(2,28),_o=Math.pow(2,35),Po=Math.pow(2,42),Ro=Math.pow(2,49),U=128,Ee=127;function Be(t){if(t<Iu)return 1;if(t<Cu)return 2;if(t<Bu)return 3;if(t<ko)return 4;if(t<_o)return 5;if(t<Po)return 6;if(t<Ro)return 7;if(Number.MAX_SAFE_INTEGER!=null&&t>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Ut(t,e,r=0){switch(Be(t)){case 8:e[r++]=t&255|U,t/=128;case 7:e[r++]=t&255|U,t/=128;case 6:e[r++]=t&255|U,t/=128;case 5:e[r++]=t&255|U,t/=128;case 4:e[r++]=t&255|U,t>>>=7;case 3:e[r++]=t&255|U,t>>>=7;case 2:e[r++]=t&255|U,t>>>=7;case 1:{e[r++]=t&255,t>>>=7;break}default:throw new Error("unreachable")}return e}function Lu(t,e,r=0){switch(Be(t)){case 8:e.set(r++,t&255|U),t/=128;case 7:e.set(r++,t&255|U),t/=128;case 6:e.set(r++,t&255|U),t/=128;case 5:e.set(r++,t&255|U),t/=128;case 4:e.set(r++,t&255|U),t>>>=7;case 3:e.set(r++,t&255|U),t>>>=7;case 2:e.set(r++,t&255|U),t>>>=7;case 1:{e.set(r++,t&255),t>>>=7;break}default:throw new Error("unreachable")}return e}function No(t,e){let r=t[e],n=0;if(n+=r&Ee,r<U||(r=t[e+1],n+=(r&Ee)<<7,r<U)||(r=t[e+2],n+=(r&Ee)<<14,r<U)||(r=t[e+3],n+=(r&Ee)<<21,r<U)||(r=t[e+4],n+=(r&Ee)*ko,r<U)||(r=t[e+5],n+=(r&Ee)*_o,r<U)||(r=t[e+6],n+=(r&Ee)*Po,r<U)||(r=t[e+7],n+=(r&Ee)*Ro,r<U))return n;throw new RangeError("Could not decode varint")}function Ou(t,e){let r=t.get(e),n=0;if(n+=r&Ee,r<U||(r=t.get(e+1),n+=(r&Ee)<<7,r<U)||(r=t.get(e+2),n+=(r&Ee)<<14,r<U)||(r=t.get(e+3),n+=(r&Ee)<<21,r<U)||(r=t.get(e+4),n+=(r&Ee)*ko,r<U)||(r=t.get(e+5),n+=(r&Ee)*_o,r<U)||(r=t.get(e+6),n+=(r&Ee)*Po,r<U)||(r=t.get(e+7),n+=(r&Ee)*Ro,r<U))return n;throw new RangeError("Could not decode varint")}function Us(t,e,r=0){return e==null&&(e=Ce(Be(t))),e instanceof Uint8Array?Ut(t,e,r):Lu(t,e,r)}function fr(t,e=0){return t instanceof Uint8Array?No(t,e):Ou(t,e)}function ku(t){return t.buffer instanceof ArrayBuffer}function pt(t){return ku(t)?t:t.slice()}var Uo=new Float32Array([-0]),mt=new Uint8Array(Uo.buffer);function Fs(t,e,r){Uo[0]=t,e[r]=mt[0],e[r+1]=mt[1],e[r+2]=mt[2],e[r+3]=mt[3]}function Ks(t,e){return mt[0]=t[e],mt[1]=t[e+1],mt[2]=t[e+2],mt[3]=t[e+3],Uo[0]}var Mo=new Float64Array([-0]),ve=new Uint8Array(Mo.buffer);function $s(t,e,r){Mo[0]=t,e[r]=ve[0],e[r+1]=ve[1],e[r+2]=ve[2],e[r+3]=ve[3],e[r+4]=ve[4],e[r+5]=ve[5],e[r+6]=ve[6],e[r+7]=ve[7]}function Hs(t,e){return ve[0]=t[e],ve[1]=t[e+1],ve[2]=t[e+2],ve[3]=t[e+3],ve[4]=t[e+4],ve[5]=t[e+5],ve[6]=t[e+6],ve[7]=t[e+7],Mo[0]}var _u=BigInt(Number.MAX_SAFE_INTEGER),Pu=BigInt(Number.MIN_SAFE_INTEGER),Pe=class t{lo;hi;constructor(e,r){this.lo=e|0,this.hi=r|0}toNumber(e=!1){if(!e&&this.hi>>>31>0){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(r+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 r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(BigInt(r)+(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,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?e<16384?e<128?1:2:e<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(e){if(e===0n)return At;if(e<_u&&e>Pu)return this.fromNumber(Number(e));let r=e<0n;r&&(e=-e);let n=e>>32n,s=e-(n<<32n);return r&&(n=~n|0n,s=~s|0n,++s>zs&&(s=0n,++n>zs&&(n=0n))),new t(Number(s),Number(n))}static fromNumber(e){if(e===0)return At;let r=e<0;r&&(e=-e);let n=e>>>0,s=(e-n)/4294967296>>>0;return r&&(s=~s>>>0,n=~n>>>0,++n>4294967295&&(n=0,++s>4294967295&&(s=0))),new t(n,s)}static from(e){return typeof e=="number"?t.fromNumber(e):typeof e=="bigint"?t.fromBigInt(e):typeof e=="string"?t.fromBigInt(BigInt(e)):e.low!=null||e.high!=null?new t(e.low>>>0,e.high>>>0):At}},At=new Pe(0,0);At.toBigInt=function(){return 0n};At.zzEncode=At.zzDecode=function(){return this};At.length=function(){return 1};var zs=4294967296n;function Vs(t){let e=0,r=0;for(let n=0;n<t.length;++n)r=t.charCodeAt(n),r<128?e+=1:r<2048?e+=2:(r&64512)===55296&&(t.charCodeAt(n+1)&64512)===56320?(++n,e+=4):e+=3;return e}function Gs(t,e,r){if(r-e<1)return"";let s,o=[],c=0,i;for(;e<r;)i=t[e++],i<128?o[c++]=i:i>191&&i<224?o[c++]=(i&31)<<6|t[e++]&63:i>239&&i<365?(i=((i&7)<<18|(t[e++]&63)<<12|(t[e++]&63)<<6|t[e++]&63)-65536,o[c++]=55296+(i>>10),o[c++]=56320+(i&1023)):o[c++]=(i&15)<<12|(t[e++]&63)<<6|t[e++]&63,c>8191&&((s??(s=[])).push(String.fromCharCode.apply(String,o)),c=0);return s!=null?(c>0&&s.push(String.fromCharCode.apply(String,o.slice(0,c))),s.join("")):String.fromCharCode.apply(String,o.slice(0,c))}function Fo(t,e,r){let n=r,s,o;for(let c=0;c<t.length;++c)s=t.charCodeAt(c),s<128?e[r++]=s:s<2048?(e[r++]=s>>6|192,e[r++]=s&63|128):(s&64512)===55296&&((o=t.charCodeAt(c+1))&64512)===56320?(s=65536+((s&1023)<<10)+(o&1023),++c,e[r++]=s>>18|240,e[r++]=s>>12&63|128,e[r++]=s>>6&63|128,e[r++]=s&63|128):(e[r++]=s>>12|224,e[r++]=s>>6&63|128,e[r++]=s&63|128);return r-n}function Ve(t,e){return RangeError(`index out of range: ${t.pos} + ${e??1} > ${t.len}`)}function Jr(t,e){return(t[e-4]|t[e-3]<<8|t[e-2]<<16|t[e-1]<<24)>>>0}var Ko=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(e){this.buf=pt(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,Ve(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 Ve(this,4);return Jr(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Ve(this,4);return Jr(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Ve(this,4);let e=Ks(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw Ve(this,4);let e=Hs(this.buf,this.pos);return this.pos+=8,e}bytes(){let e=this.uint32(),r=this.pos,n=this.pos+e;if(n>this.len)throw Ve(this,e);return this.pos+=e,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let e=this.bytes();return Gs(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw Ve(this,e);this.pos+=e}else do if(this.pos>=this.len)throw Ve(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 Pe(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(e.lo=(e.lo|(this.buf[this.pos]&127)<<r*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;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw Ve(this);if(e.lo=(e.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return e}return e.lo=(e.lo|(this.buf[this.pos++]&127)<<r*7)>>>0,e}if(this.len-this.pos>4){for(;r<5;++r)if(e.hi=(e.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return e}else for(;r<5;++r){if(this.pos>=this.len)throw Ve(this);if(e.hi=(e.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return e}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Ve(this,8);let e=Jr(this.buf,this.pos+=4),r=Jr(this.buf,this.pos+=4);return new Pe(e,r)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let e=No(this.buf,this.pos);return this.pos+=Be(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 dr(t){return new Ko(t instanceof Uint8Array?t:t.subarray())}function Q(t,e,r){let n=dr(t);return e.decode(n,void 0,r)}var pc=le("node:buffer");var Go={};ke(Go,{base10:()=>Hu});var Rh=new Uint8Array(0);function qs(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}function Te(t){if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return Dt(t);if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return Dt(new Uint8Array(t.buffer,t.byteOffset,t.byteLength));throw new Error("Unknown type, must be binary type")}function Zs(t){let e=new Uint8Array(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}var Ys=4096;function js(t){let e=t.length;if(e<=Ys)return String.fromCharCode.apply(String,t);let r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.subarray(n,n+=Ys));return r}function Ru(t){return t?.buffer instanceof ArrayBuffer}function Dt(t){return Ru(t)?t:t.slice()}function Nu(t,e,r){if(t.length>=255)throw new TypeError("Alphabet too long");for(var n=new Uint8Array(256),s=0;s<n.length;s++)n[s]=255;for(var o=0;o<t.length;o++){var c=t.charAt(o),i=c.charCodeAt(0);if(n[i]!==255)throw new TypeError(c+" is ambiguous");if(n[i]=o,r){var a=c.toLowerCase().charCodeAt(0),u=c.toUpperCase().charCodeAt(0);a!==i&&(n[a]=o),u!==i&&(n[u]=o)}}var l=t.length,f=t.charAt(0),d=Math.log(l)/Math.log(256),p=Math.log(256)/Math.log(l);function x(y){if(y instanceof Uint8Array||(ArrayBuffer.isView(y)?y=new Uint8Array(y.buffer,y.byteOffset,y.byteLength):Array.isArray(y)&&(y=Uint8Array.from(y))),!(y instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(y.length===0)return"";for(var T=0,P=0,_=0,M=y.length;_!==M&&y[_]===0;)_++,T++;for(var X=(M-_)*p+1>>>0,ie=new Uint8Array(X);_!==M;){for(var re=y[_],we=0,V=X-1;(re!==0||we<P)&&V!==-1;V--,we++)re+=256*ie[V]>>>0,ie[V]=re%l>>>0,re=re/l>>>0;if(re!==0)throw new Error("Non-zero carry");P=we,_++}for(var me=X-P;me!==X&&ie[me]===0;)me++;for(var Oe=f.repeat(T);me<X;++me)Oe+=t.charAt(ie[me]);return Oe}function D(y){if(typeof y!="string")throw new TypeError("Expected String");if(y.length===0)return new Uint8Array;var T=0;if(y[T]!==" "){for(var P=0,_=0;y[T]===f;)P++,T++;for(var M=(y.length-T)*d+1>>>0,X=new Uint8Array(M);y[T];){var ie=y.charCodeAt(T);if(ie>255)return;var re=n[ie];if(re===255)return;for(var we=0,V=M-1;(re!==0||we<_)&&V!==-1;V--,we++)re+=l*X[V]>>>0,X[V]=re%256>>>0,re=re/256>>>0;if(re!==0)throw new Error("Non-zero carry");_=we,T++}if(y[T]!==" "){for(var me=M-_;me!==M&&X[me]===0;)me++;for(var Oe=new Uint8Array(P+(M-me)),ft=P;me!==M;)Oe[ft++]=X[me++];return Oe}}}function b(y){var T=D(y);if(T)return T;throw new Error(`Non-${e} character`)}return{encode:x,decodeUnsafe:D,decode:b}}var Uu=Nu,Mu=Uu,Qs=Mu;var $o=class{name;prefix;baseEncode;constructor(e,r,n){this.name=e,this.prefix=r,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},Ho=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,r,n){this.name=e,this.prefix=r;let s=r.codePointAt(0);if(s===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=s,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 Js(this,e)}},zo=class{decoders;constructor(e){this.decoders=e}or(e){return Js(this,e)}decode(e){let r=e[0],n=this.decoders[r];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 Js(t,e){return new zo({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var Vo=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,r,n,s){this.name=e,this.prefix=r,this.baseEncode=n,this.baseDecode=s,this.encoder=new $o(e,r,n),this.decoder=new Ho(e,r,s)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function Mt({name:t,prefix:e,encode:r,decode:n}){return new Vo(t,e,r,n)}function yt({name:t,prefix:e,alphabet:r,caseInsensitive:n=!1}){let{encode:s,decode:o}=Qs(r,t,n);return Mt({prefix:e,name:t,encode:s,decode:c=>Te(o(c))})}function Fu(t,e,r,n){let s=t.length;for(;t[s-1]==="=";)--s;let o=new Uint8Array(s*r/8|0),c=0,i=0,a=0;for(let u=0;u<s;++u){let l=e[t[u]];if(l===void 0)throw new SyntaxError(`Non-${n} character`);i=i<<r|l,c+=r,c>=8&&(c-=8,o[a++]=255&i>>c)}if(c>=r||(255&i<<8-c)!==0)throw new SyntaxError("Unexpected end of data");return o}function Ku(t,e,r){let n=e[e.length-1]==="=",s=(1<<r)-1,o="",c=0,i=0;for(let a=0;a<t.length;++a)for(i=i<<8|t[a],c+=8;c>r;)c-=r,o+=e[s&i>>c];if(c!==0&&(o+=e[s&i<<r-c]),n)for(;(o.length*r&7)!==0;)o+="=";return o}function $u(t,e){let r={};for(let n=0;n<t.length;++n)if(r[t[n]]=n,e){let s=t[n].toLowerCase(),o=t[n].toUpperCase();s!==t[n]&&(r[s]=n),o!==t[n]&&(r[o]=n)}return r}function ne({name:t,prefix:e,bitsPerChar:r,alphabet:n,caseInsensitive:s=!1}){let o=$u(n,s);return Mt({prefix:e,name:t,encode(c){return Ku(c,n,r)},decode(c){return Fu(c,o,r,t)}})}var Hu=yt({prefix:"9",name:"base10",alphabet:"0123456789"});var Wo={};ke(Wo,{base16:()=>zu,base16upper:()=>Vu});var zu=ne({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4,caseInsensitive:!0}),Vu=ne({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4,caseInsensitive:!0});var Yo={};ke(Yo,{base2:()=>Gu});var Gu=ne({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var qo={};ke(qo,{base256emoji:()=>ju});var ec=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}"),Wu=ec.reduce((t,e,r)=>(t[r]=e,t),[]),Yu=ec.reduce((t,e,r)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return t[n]=r,t},[]);function qu(t){return t.reduce((e,r)=>(e+=Wu[r],e),"")}function Zu(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let s=Yu[n];if(s==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(s)}return new Uint8Array(e)}var ju=Mt({prefix:"\u{1F680}",name:"base256emoji",encode:qu,decode:Zu});var Zo={};ke(Zo,{base32:()=>je,base32hex:()=>el,base32hexpad:()=>rl,base32hexpadupper:()=>nl,base32hexupper:()=>tl,base32pad:()=>Qu,base32padupper:()=>Ju,base32upper:()=>Xu,base32z:()=>ol});var je=ne({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5,caseInsensitive:!0}),Xu=ne({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5,caseInsensitive:!0}),Qu=ne({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5,caseInsensitive:!0}),Ju=ne({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5,caseInsensitive:!0}),el=ne({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5,caseInsensitive:!0}),tl=ne({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5,caseInsensitive:!0}),rl=ne({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5,caseInsensitive:!0}),nl=ne({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5,caseInsensitive:!0}),ol=ne({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var jo={};ke(jo,{base36:()=>hr,base36upper:()=>il});var hr=yt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz",caseInsensitive:!0}),il=yt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",caseInsensitive:!0});var Xo={};ke(Xo,{base58btc:()=>ae,base58flickr:()=>sl});var ae=yt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),sl=yt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var ei={};ke(ei,{base64:()=>Qo,base64pad:()=>cl,base64url:()=>Jo,base64urlpad:()=>al});var Qo=ne({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),cl=ne({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Jo=ne({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),al=ne({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var ti={};ke(ti,{base8:()=>ul});var ul=ne({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var ri={};ke(ri,{identity:()=>ll});var ll=Mt({prefix:"\0",name:"identity",encode:t=>js(Te(t)),decode:t=>Te(Zs(t))});var Xh=new TextEncoder,Qh=new TextDecoder;var oi={};ke(oi,{identity:()=>Ge});var hl=nc,tc=128,pl=127,ml=~pl,yl=Math.pow(2,31);function nc(t,e,r){e=e||[],r=r||0;for(var n=r;t>=yl;)e[r++]=t&255|tc,t/=128;for(;t&ml;)e[r++]=t&255|tc,t>>>=7;return e[r]=t|0,nc.bytes=r-n+1,e}var bl=ni,gl=128,rc=127;function ni(t,n){var r=0,n=n||0,s=0,o=n,c,i=t.length;do{if(o>=i)throw ni.bytes=0,new RangeError("Could not decode varint");c=t[o++],r+=s<28?(c&rc)<<s:(c&rc)*Math.pow(2,s),s+=7}while(c>=gl);return ni.bytes=o-n,r}var wl=Math.pow(2,7),xl=Math.pow(2,14),El=Math.pow(2,21),vl=Math.pow(2,28),Sl=Math.pow(2,35),Tl=Math.pow(2,42),Al=Math.pow(2,49),Dl=Math.pow(2,56),Il=Math.pow(2,63),Cl=function(t){return t<wl?1:t<xl?2:t<El?3:t<vl?4:t<Sl?5:t<Tl?6:t<Al?7:t<Dl?8:t<Il?9:10},Bl={encode:hl,decode:bl,encodingLength:Cl},Ll=Bl,pr=Ll;function mr(t,e=0){let r=pr.decode(t,e),n=pr.decode.bytes;if(n>9)throw new RangeError("Invalid varint: too long");if(n>1&&t[e+n-1]===0)throw new RangeError("Invalid varint: not minimally encoded");return[r,n]}function Ft(t,e,r=0){return pr.encode(t,e,r),e}function Kt(t){return pr.encodingLength(t)}function Ht(t,e){let r=e.byteLength,n=Kt(t),s=n+Kt(r),o=new Uint8Array(s+r);return Ft(t,o,0),Ft(r,o,n),o.set(e,s),new $t(t,r,e,o)}function $e(t){let e=Te(t),[r,n]=mr(e),[s,o]=mr(e.subarray(n)),c=e.subarray(n+o);if(c.byteLength!==s)throw new Error("Incorrect length");return new $t(r,s,c,e)}function oc(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&qs(t.bytes,r.bytes)}}var $t=class{code;size;digest;bytes;constructor(e,r,n,s){this.code=e,this.size=r,this.digest=Dt(n),this.bytes=Dt(s)}};var ic=0,Ol="identity",sc=Te;function kl(t,e){if(e?.truncate!=null&&e.truncate!==t.byteLength){if(e.truncate<0||e.truncate>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,e.truncate)}return Ht(ic,sc(t))}var Ge={code:ic,name:Ol,encode:sc,digest:kl};var ui={};ke(ui,{sha256:()=>ai,sha512:()=>Pl});var ci=_e(le("node:crypto"),1);var _l=20;function si({name:t,code:e,encode:r,minDigestLength:n,maxDigestLength:s}){return new ii(t,e,r,n,s)}var ii=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,r,n,s,o){this.name=e,this.code=r,this.encode=n,this.minDigestLength=s??_l,this.maxDigestLength=o}digest(e,r){if(r?.truncate!=null){if(r.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&r.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?cc(n,this.code,r?.truncate):n.then(s=>cc(s,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function cc(t,e,r){if(r!=null&&r!==t.byteLength){if(r>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,r)}return Ht(e,t)}var ai=si({name:"sha2-256",code:18,encode:t=>Te(ci.default.createHash("sha256").update(t).digest())}),Pl=si({name:"sha2-512",code:19,encode:t=>Te(ci.default.createHash("sha512").update(t).digest())});function uc(t,e){let{bytes:r,version:n}=t;return n===0?Nl(r,li(t),e??ae.encoder):Ul(r,li(t),e??je.encoder)}var lc=new WeakMap;function li(t){let e=lc.get(t);if(e==null){let r=new Map;return lc.set(t,r),r}return e}var de=class t{code;version;multihash;bytes;"/";constructor(e,r,n,s){this.code=r,this.version=e,this.multihash=n,this.bytes=Dt(s),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:r}=this;if(e!==yr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Ml)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return t.createV0(r)}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:r}=this.multihash,n=Ht(e,r);return t.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 t.equals(this,e)}static equals(e,r){let n=r;return n!=null&&e.code===n.code&&e.version===n.version&&oc(e.multihash,n.multihash)}toString(e){return uc(this,e)}toJSON(){return{"/":uc(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 r=e;if(r instanceof t)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:s,multihash:o,bytes:c}=r;return new t(n,s,o,c??fc(n,s,o.bytes))}else if(r[Fl]===!0){let{version:n,multihash:s,code:o}=r,c=$e(s);return t.create(n,o,c)}else return null}static create(e,r,n){if(typeof r!="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(r!==yr)throw new Error(`Version 0 CID must use dag-pb (code: ${yr}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let s=fc(e,r,n.bytes);return new t(e,r,n,s)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,yr,e)}static createV1(e,r){return t.create(1,e,r)}static decode(e){let[r,n]=t.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(e){let r=t.inspectBytes(e),n=r.size-r.multihashSize,s=Te(e.subarray(n,n+r.multihashSize));if(s.byteLength!==r.multihashSize)throw new Error("Incorrect length");let o=s.subarray(r.multihashSize-r.digestSize),c=new $t(r.multihashCode,r.digestSize,o,s);return[r.version===0?t.createV0(c):t.createV1(r.codec,c),e.subarray(r.size)]}static inspectBytes(e){let r=0,n=()=>{let[f,d]=mr(e.subarray(r));return r+=d,f},s=n(),o=yr;if(s===18)s=0,r=0;else if(s===1)o=n();else throw s===0?new RangeError("Invalid CID version, v0 is always implicit"):new RangeError(`Invalid CID version ${s}`);let c=r,i=n(),a=n(),u=r+a,l=u-c;return{version:s,codec:o,multihashCode:i,digestSize:a,multihashSize:l,size:u}}static parse(e,r){let[n,s]=Rl(e,r),o=t.decode(s);if(o.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return li(o).set(n,e),o}};function Rl(t,e){switch(t[0]){case"Q":{let r=e??ae;return[ae.prefix,r.decode(`${ae.prefix}${t}`)]}case ae.prefix:{let r=e??ae;return[ae.prefix,r.decode(t)]}case je.prefix:{let r=e??je;return[je.prefix,r.decode(t)]}case hr.prefix:{let r=e??hr;return[hr.prefix,r.decode(t)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[t[0],e.decode(t)]}}}function Nl(t,e,r){let{prefix:n}=r;if(n!==ae.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let s=e.get(n);if(s==null){let o=r.encode(t).slice(1);return e.set(n,o),o}else return s}function Ul(t,e,r){let{prefix:n}=r,s=e.get(n);if(s==null){let o=r.encode(t);return e.set(n,o),o}else return s}var yr=112,Ml=18;function fc(t,e,r){let n=Kt(t),s=n+Kt(e),o=new Uint8Array(s+r.byteLength);return Ft(t,o,0),Ft(e,o,n),o.set(r,s),o}var Fl=Symbol.for("@ipld/js-cid/CID");var br={...ri,...Yo,...ti,...Go,...Wo,...Zo,...jo,...Xo,...ei,...qo},Ep={...ui,...oi};function hc(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var dc=hc("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),fi=hc("ascii","a",t=>{let e="a";for(let r=0;r<t.length;r++)e+=String.fromCharCode(t[r]);return e},t=>{t=t.substring(1);let e=Ce(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),Kl={utf8:dc,"utf-8":dc,hex:br.base16,latin1:fi,ascii:fi,binary:fi,...br},tn=Kl;function Ae(t,e="utf8"){let r=tn[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return e==="utf8"||e==="utf-8"?ht(pc.Buffer.from(t,"utf-8")):r.decoder.decode(`${r.prefix}${t}`)}function di(t){let e=t??8192,r=e>>>1,n,s=e;return function(c){if(c<1||c>r)return Ce(c);s+c>e&&(n=Ce(e),s=0);let i=n.subarray(s,s+=c);return(s&7)!==0&&(s=(s|7)+1),i}}var It=class{fn;len;next;val;constructor(e,r,n){this.fn=e,this.len=r,this.next=void 0,this.val=n}};function hi(){}var mi=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},$l=di();function Hl(t){return globalThis.Buffer!=null?Ce(t):$l(t)}var wr=class{len;head;tail;states;constructor(){this.len=0,this.head=new It(hi,0,0),this.tail=this.head,this.states=null}_push(e,r,n){return this.tail=this.tail.next=new It(e,r,n),this.len+=r,this}uint32(e){return this.len+=(this.tail=this.tail.next=new yi((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(rn,10,Pe.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let r=Pe.fromBigInt(e);return this._push(rn,r.length(),r)}uint64Number(e){return this._push(Ut,Be(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 r=Pe.fromBigInt(e).zzEncode();return this._push(rn,r.length(),r)}sint64Number(e){let r=Pe.fromNumber(e).zzEncode();return this._push(rn,r.length(),r)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(pi,1,e?1:0)}fixed32(e){return this._push(gr,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let r=Pe.fromBigInt(e);return this._push(gr,4,r.lo)._push(gr,4,r.hi)}fixed64Number(e){let r=Pe.fromNumber(e);return this._push(gr,4,r.lo)._push(gr,4,r.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(Fs,4,e)}double(e){return this._push($s,8,e)}bytes(e){let r=e.length>>>0;return r===0?this._push(pi,1,0):this.uint32(r)._push(Vl,r,e)}string(e){let r=Vs(e);return r!==0?this.uint32(r)._push(Fo,r,e):this._push(pi,1,0)}fork(){return this.states=new mi(this),this.head=this.tail=new It(hi,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new It(hi,0,0),this.len=0),this}ldelim(){let e=this.head,r=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=e.next,this.tail=r,this.len+=n),this}finish(){let e=this.head.next,r=Hl(this.len),n=0;for(;e!=null;)e.fn(e.val,r,n),n+=e.len,e=e.next;return r}};function pi(t,e,r){e[r]=t&255}function zl(t,e,r){for(;t>127;)e[r++]=t&127|128,t>>>=7;e[r]=t}var yi=class extends It{next;constructor(e,r){super(zl,e,r),this.next=void 0}};function rn(t,e,r){for(;t.hi!==0;)e[r++]=t.lo&127|128,t.lo=(t.lo>>>7|t.hi<<25)>>>0,t.hi>>>=7;for(;t.lo>127;)e[r++]=t.lo&127|128,t.lo=t.lo>>>7;e[r++]=t.lo}function gr(t,e,r){e[r]=t&255,e[r+1]=t>>>8&255,e[r+2]=t>>>16&255,e[r+3]=t>>>24}function Vl(t,e,r){e.set(t,r)}globalThis.Buffer!=null&&(wr.prototype.bytes=function(t){let e=t.length>>>0;return this.uint32(e),e>0&&this._push(Gl,e,t),this},wr.prototype.string=function(t){let e=globalThis.Buffer.byteLength(t);return this.uint32(e),e>0&&this._push(Wl,e,t),this});function Gl(t,e,r){e.set(t,r)}function Wl(t,e,r){t.length<40?Fo(t,e,r):e.utf8Write!=null?e.utf8Write(t,r):e.set(Ae(t),r)}function bi(){return new wr}function J(t,e){let r=bi();return e.encode(t,r,{lengthDelimited:!1}),r.finish()}function*ee(t,e,r){let n=dr(t);yield*e.stream(n,void 0,".",r)}var nn={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function on(t,e,r,n,s){return{name:t,type:e,encode:r,decode:n,stream:s}}function We(t){function e(o){if(t[o.toString()]==null)throw new Error("Invalid enum value");return t[o]}let r=function(c,i){let a=e(c);i.int32(a)},n=function(c){let i=c.int32();return e(i)},s=function*(c,i){};return on("enum",nn.VARINT,r,n,s)}function te(t,e,r){return on("message",nn.LENGTH_DELIMITED,t,e,r)}var G=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var H;(function(t){let e;(function(i){i.IDENTIFY="IDENTIFY",i.CONNECT="CONNECT",i.STREAM_OPEN="STREAM_OPEN",i.STREAM_HANDLER="STREAM_HANDLER",i.DHT="DHT",i.LIST_PEERS="LIST_PEERS",i.CONNMANAGER="CONNMANAGER",i.DISCONNECT="DISCONNECT",i.PUBSUB="PUBSUB",i.PEERSTORE="PEERSTORE"})(e=t.Type||(t.Type={}));let r;(function(i){i[i.IDENTIFY=0]="IDENTIFY",i[i.CONNECT=1]="CONNECT",i[i.STREAM_OPEN=2]="STREAM_OPEN",i[i.STREAM_HANDLER=3]="STREAM_HANDLER",i[i.DHT=4]="DHT",i[i.LIST_PEERS=5]="LIST_PEERS",i[i.CONNMANAGER=6]="CONNMANAGER",i[i.DISCONNECT=7]="DISCONNECT",i[i.PUBSUB=8]="PUBSUB",i[i.PEERSTORE=9]="PEERSTORE"})(r||(r={})),(function(i){i.codec=()=>We(r)})(e=t.Type||(t.Type={}));let n;t.codec=()=>(n==null&&(n=te((i,a,u={})=>{u.lengthDelimited!==!1&&a.fork(),i.type!=null&&(a.uint32(8),t.Type.codec().encode(i.type,a)),i.connect!=null&&(a.uint32(18),Er.codec().encode(i.connect,a)),i.streamOpen!=null&&(a.uint32(26),vr.codec().encode(i.streamOpen,a)),i.streamHandler!=null&&(a.uint32(34),Sr.codec().encode(i.streamHandler,a)),i.dht!=null&&(a.uint32(42),Re.codec().encode(i.dht,a)),i.connManager!=null&&(a.uint32(50),Ar.codec().encode(i.connManager,a)),i.disconnect!=null&&(a.uint32(58),Dr.codec().encode(i.disconnect,a)),i.pubsub!=null&&(a.uint32(66),Xe.codec().encode(i.pubsub,a)),i.peerStore!=null&&(a.uint32(74),Cr.codec().encode(i.peerStore,a)),u.lengthDelimited!==!1&&a.ldelim()},(i,a,u={})=>{let l={},f=a==null?i.len:i.pos+a;for(;i.pos<f;){let d=i.uint32();switch(d>>>3){case 1:{l.type=t.Type.codec().decode(i);break}case 2:{l.connect=Er.codec().decode(i,i.uint32(),{limits:u.limits?.connect});break}case 3:{l.streamOpen=vr.codec().decode(i,i.uint32(),{limits:u.limits?.streamOpen});break}case 4:{l.streamHandler=Sr.codec().decode(i,i.uint32(),{limits:u.limits?.streamHandler});break}case 5:{l.dht=Re.codec().decode(i,i.uint32(),{limits:u.limits?.dht});break}case 6:{l.connManager=Ar.codec().decode(i,i.uint32(),{limits:u.limits?.connManager});break}case 7:{l.disconnect=Dr.codec().decode(i,i.uint32(),{limits:u.limits?.disconnect});break}case 8:{l.pubsub=Xe.codec().decode(i,i.uint32(),{limits:u.limits?.pubsub});break}case 9:{l.peerStore=Cr.codec().decode(i,i.uint32(),{limits:u.limits?.peerStore});break}default:{i.skipType(d&7);break}}}return l},function*(i,a,u,l={}){let f=a==null?i.len:i.pos+a;for(;i.pos<f;){let d=i.uint32();switch(d>>>3){case 1:{yield{field:`${u}.type`,value:t.Type.codec().decode(i)};break}case 2:{yield*Er.codec().stream(i,i.uint32(),`${u}.connect`,{limits:l.limits?.connect});break}case 3:{yield*vr.codec().stream(i,i.uint32(),`${u}.streamOpen`,{limits:l.limits?.streamOpen});break}case 4:{yield*Sr.codec().stream(i,i.uint32(),`${u}.streamHandler`,{limits:l.limits?.streamHandler});break}case 5:{yield*Re.codec().stream(i,i.uint32(),`${u}.dht`,{limits:l.limits?.dht});break}case 6:{yield*Ar.codec().stream(i,i.uint32(),`${u}.connManager`,{limits:l.limits?.connManager});break}case 7:{yield*Dr.codec().stream(i,i.uint32(),`${u}.disconnect`,{limits:l.limits?.disconnect});break}case 8:{yield*Xe.codec().stream(i,i.uint32(),`${u}.pubsub`,{limits:l.limits?.pubsub});break}case 9:{yield*Cr.codec().stream(i,i.uint32(),`${u}.peerStore`,{limits:l.limits?.peerStore});break}default:{i.skipType(d&7);break}}}})),n);function s(i){return J(i,t.codec())}t.encode=s;function o(i,a){return Q(i,t.codec(),a)}t.decode=o;function c(i,a){return ee(i,t.codec(),a)}t.stream=c})(H||(H={}));var L;(function(t){let e;(function(i){i.OK="OK",i.ERROR="ERROR"})(e=t.Type||(t.Type={}));let r;(function(i){i[i.OK=0]="OK",i[i.ERROR=1]="ERROR"})(r||(r={})),(function(i){i.codec=()=>We(r)})(e=t.Type||(t.Type={}));let n;t.codec=()=>(n==null&&(n=te((i,a,u={})=>{if(u.lengthDelimited!==!1&&a.fork(),i.type!=null&&(a.uint32(8),t.Type.codec().encode(i.type,a)),i.error!=null&&(a.uint32(18),Tr.codec().encode(i.error,a)),i.streamInfo!=null&&(a.uint32(26),Ct.codec().encode(i.streamInfo,a)),i.identify!=null&&(a.uint32(34),xr.codec().encode(i.identify,a)),i.dht!=null&&(a.uint32(42),He.codec().encode(i.dht,a)),i.peers!=null&&i.peers.length>0)for(let l of i.peers)a.uint32(50),Ye.codec().encode(l,a);i.pubsub!=null&&(a.uint32(58),Ir.codec().encode(i.pubsub,a)),i.peerStore!=null&&(a.uint32(66),Br.codec().encode(i.peerStore,a)),u.lengthDelimited!==!1&&a.ldelim()},(i,a,u={})=>{let l={peers:[]},f=a==null?i.len:i.pos+a;for(;i.pos<f;){let d=i.uint32();switch(d>>>3){case 1:{l.type=t.Type.codec().decode(i);break}case 2:{l.error=Tr.codec().decode(i,i.uint32(),{limits:u.limits?.error});break}case 3:{l.streamInfo=Ct.codec().decode(i,i.uint32(),{limits:u.limits?.streamInfo});break}case 4:{l.identify=xr.codec().decode(i,i.uint32(),{limits:u.limits?.identify});break}case 5:{l.dht=He.codec().decode(i,i.uint32(),{limits:u.limits?.dht});break}case 6:{if(u.limits?.peers!=null&&l.peers.length===u.limits.peers)throw new G('Decode error - repeated field "peers" had too many elements');l.peers.push(Ye.codec().decode(i,i.uint32(),{limits:u.limits?.peers$}));break}case 7:{l.pubsub=Ir.codec().decode(i,i.uint32(),{limits:u.limits?.pubsub});break}case 8:{l.peerStore=Br.codec().decode(i,i.uint32(),{limits:u.limits?.peerStore});break}default:{i.skipType(d&7);break}}}return l},function*(i,a,u,l={}){let f={peers:0},d=a==null?i.len:i.pos+a;for(;i.pos<d;){let p=i.uint32();switch(p>>>3){case 1:{yield{field:`${u}.type`,value:t.Type.codec().decode(i)};break}case 2:{yield*Tr.codec().stream(i,i.uint32(),`${u}.error`,{limits:l.limits?.error});break}case 3:{yield*Ct.codec().stream(i,i.uint32(),`${u}.streamInfo`,{limits:l.limits?.streamInfo});break}case 4:{yield*xr.codec().stream(i,i.uint32(),`${u}.identify`,{limits:l.limits?.identify});break}case 5:{yield*He.codec().stream(i,i.uint32(),`${u}.dht`,{limits:l.limits?.dht});break}case 6:{if(l.limits?.peers!=null&&f.peers===l.limits.peers)throw new G('Streaming decode error - repeated field "peers" had too many elements');for(let x of Ye.codec().stream(i,i.uint32(),`${u}.peers[]`,{limits:l.limits?.peers$}))yield{...x,index:f.peers};f.peers++;break}case 7:{yield*Ir.codec().stream(i,i.uint32(),`${u}.pubsub`,{limits:l.limits?.pubsub});break}case 8:{yield*Br.codec().stream(i,i.uint32(),`${u}.peerStore`,{limits:l.limits?.peerStore});break}default:{i.skipType(p&7);break}}}})),n);function s(i){return J(i,t.codec())}t.encode=s;function o(i,a){return Q(i,t.codec(),a)}t.decode=o;function c(i,a){return ee(i,t.codec(),a)}t.stream=c})(L||(L={}));var xr;(function(t){let e;t.codec=()=>(e==null&&(e=te((o,c,i={})=>{if(i.lengthDelimited!==!1&&c.fork(),o.id!=null&&o.id.byteLength>0&&(c.uint32(10),c.bytes(o.id)),o.addrs!=null&&o.addrs.length>0)for(let a of o.addrs)c.uint32(18),c.bytes(a);i.lengthDelimited!==!1&&c.ldelim()},(o,c,i={})=>{let a={id:fe(0),addrs:[]},u=c==null?o.len:o.pos+c;for(;o.pos<u;){let l=o.uint32();switch(l>>>3){case 1:{a.id=o.bytes();break}case 2:{if(i.limits?.addrs!=null&&a.addrs.length===i.limits.addrs)throw new G('Decode error - repeated field "addrs" had too many elements');a.addrs.push(o.bytes());break}default:{o.skipType(l&7);break}}}return a},function*(o,c,i,a={}){let u={addrs:0},l=c==null?o.len:o.pos+c;for(;o.pos<l;){let f=o.uint32();switch(f>>>3){case 1:{yield{field:`${i}.id`,value:o.bytes()};break}case 2:{if(a.limits?.addrs!=null&&u.addrs===a.limits.addrs)throw new G('Streaming decode error - repeated field "addrs" had too many elements');yield{field:`${i}.addrs[]`,index:u.addrs,value:o.bytes()},u.addrs++;break}default:{o.skipType(f&7);break}}}})),e);function r(o){return J(o,t.codec())}t.encode=r;function n(o,c){return Q(o,t.codec(),c)}t.decode=n;function s(o,c){return ee(o,t.codec(),c)}t.stream=s})(xr||(xr={}));var Er;(function(t){let e;t.codec=()=>(e==null&&(e=te((o,c,i={})=>{if(i.lengthDelimited!==!1&&c.fork(),o.peer!=null&&o.peer.byteLength>0&&(c.uint32(10),c.bytes(o.peer)),o.addrs!=null&&o.addrs.length>0)for(let a of o.addrs)c.uint32(18),c.bytes(a);o.timeout!=null&&(c.uint32(24),c.int64(o.timeout)),i.lengthDelimited!==!1&&c.ldelim()},(o,c,i={})=>{let a={peer:fe(0),addrs:[]},u=c==null?o.len:o.pos+c;for(;o.pos<u;){let l=o.uint32();switch(l>>>3){case 1:{a.peer=o.bytes();break}case 2:{if(i.limits?.addrs!=null&&a.addrs.length===i.limits.addrs)throw new G('Decode error - repeated field "addrs" had too many elements');a.addrs.push(o.bytes());break}case 3:{a.timeout=o.int64();break}default:{o.skipType(l&7);break}}}return a},function*(o,c,i,a={}){let u={addrs:0},l=c==null?o.len:o.pos+c;for(;o.pos<l;){let f=o.uint32();switch(f>>>3){case 1:{yield{field:`${i}.peer`,value:o.bytes()};break}case 2:{if(a.limits?.addrs!=null&&u.addrs===a.limits.addrs)throw new G('Streaming decode error - repeated field "addrs" had too many elements');yield{field:`${i}.addrs[]`,index:u.addrs,value:o.bytes()},u.addrs++;break}case 3:{yield{field:`${i}.timeout`,value:o.int64()};break}default:{o.skipType(f&7);break}}}})),e);function r(o){return J(o,t.codec())}t.encode=r;function n(o,c){return Q(o,t.codec(),c)}t.decode=n;function s(o,c){return ee(o,t.codec(),c)}t.stream=s})(Er||(Er={}));var vr;(function(t){let e;t.codec=()=>(e==null&&(e=te((o,c,i={})=>{if(i.lengthDelimited!==!1&&c.fork(),o.peer!=null&&o.peer.byteLength>0&&(c.uint32(10),c.bytes(o.peer)),o.proto!=null&&o.proto.length>0)for(let a of o.proto)c.uint32(18),c.string(a);o.timeout!=null&&(c.uint32(24),c.int64(o.timeout)),i.lengthDelimited!==!1&&c.ldelim()},(o,c,i={})=>{let a={peer:fe(0),proto:[]},u=c==null?o.len:o.pos+c;for(;o.pos<u;){let l=o.uint32();switch(l>>>3){case 1:{a.peer=o.bytes();break}case 2:{if(i.limits?.proto!=null&&a.proto.length===i.limits.proto)throw new G('Decode error - repeated field "proto" had too many elements');a.proto.push(o.string());break}case 3:{a.timeout=o.int64();break}default:{o.skipType(l&7);break}}}return a},function*(o,c,i,a={}){let u={proto:0},l=c==null?o.len:o.pos+c;for(;o.pos<l;){let f=o.uint32();switch(f>>>3){case 1:{yield{field:`${i}.peer`,value:o.bytes()};break}case 2:{if(a.limits?.proto!=null&&u.proto===a.limits.proto)throw new G('Streaming decode error - repeated field "proto" had too many elements');yield{field:`${i}.proto[]`,index:u.proto,value:o.string()},u.proto++;break}case 3:{yield{field:`${i}.timeout`,value:o.int64()};break}default:{o.skipType(f&7);break}}}})),e);function r(o){return J(o,t.codec())}t.encode=r;function n(o,c){return Q(o,t.codec(),c)}t.decode=n;function s(o,c){return ee(o,t.codec(),c)}t.stream=s})(vr||(vr={}));var Sr;(function(t){let e;t.codec=()=>(e==null&&(e=te((o,c,i={})=>{if(i.lengthDelimited!==!1&&c.fork(),o.addr!=null&&o.addr.byteLength>0&&(c.uint32(10),c.bytes(o.addr)),o.proto!=null&&o.proto.length>0)for(let a of o.proto)c.uint32(18),c.string(a);i.lengthDelimited!==!1&&c.ldelim()},(o,c,i={})=>{let a={addr:fe(0),proto:[]},u=c==null?o.len:o.pos+c;for(;o.pos<u;){let l=o.uint32();switch(l>>>3){case 1:{a.addr=o.bytes();break}case 2:{if(i.limits?.proto!=null&&a.proto.length===i.limits.proto)throw new G('Decode error - repeated field "proto" had too many elements');a.proto.push(o.string());break}default:{o.skipType(l&7);break}}}return a},function*(o,c,i,a={}){let u={proto:0},l=c==null?o.len:o.pos+c;for(;o.pos<l;){let f=o.uint32();switch(f>>>3){case 1:{yield{field:`${i}.addr`,value:o.bytes()};break}case 2:{if(a.limits?.proto!=null&&u.proto===a.limits.proto)throw new G('Streaming decode error - repeated field "proto" had too many elements');yield{field:`${i}.proto[]`,index:u.proto,value:o.string()},u.proto++;break}default:{o.skipType(f&7);break}}}})),e);function r(o){return J(o,t.codec())}t.encode=r;function n(o,c){return Q(o,t.codec(),c)}t.decode=n;function s(o,c){return ee(o,t.codec(),c)}t.stream=s})(Sr||(Sr={}));var Tr;(function(t){let e;t.codec=()=>(e==null&&(e=te((o,c,i={})=>{i.lengthDelimited!==!1&&c.fork(),o.msg!=null&&o.msg!==""&&(c.uint32(10),c.string(o.msg)),i.lengthDelimited!==!1&&c.ldelim()},(o,c,i={})=>{let a={msg:""},u=c==null?o.len:o.pos+c;for(;o.pos<u;){let l=o.uint32();l>>>3===1?a.msg=o.string():o.skipType(l&7)}return a},function*(o,c,i,a={}){let u=c==null?o.len:o.pos+c;for(;o.pos<u;){let l=o.uint32();l>>>3===1?yield{field:`${i}.msg`,value:o.string()}:o.skipType(l&7)}})),e);function r(o){return J(o,t.codec())}t.encode=r;function n(o,c){return Q(o,t.codec(),c)}t.decode=n;function s(o,c){return ee(o,t.codec(),c)}t.stream=s})(Tr||(Tr={}));var Ct;(function(t){let e;t.codec=()=>(e==null&&(e=te((o,c,i={})=>{i.lengthDelimited!==!1&&c.fork(),o.peer!=null&&o.peer.byteLength>0&&(c.uint32(10),c.bytes(o.peer)),o.addr!=null&&o.addr.byteLength>0&&(c.uint32(18),c.bytes(o.addr)),o.proto!=null&&o.proto!==""&&(c.uint32(26),c.string(o.proto)),i.lengthDelimited!==!1&&c.ldelim()},(o,c,i={})=>{let a={peer:fe(0),addr:fe(0),proto:""},u=c==null?o.len:o.pos+c;for(;o.pos<u;){let l=o.uint32();switch(l>>>3){case 1:{a.peer=o.bytes();break}case 2:{a.addr=o.bytes();break}case 3:{a.proto=o.string();break}default:{o.skipType(l&7);break}}}return a},function*(o,c,i,a={}){let u=c==null?o.len:o.pos+c;for(;o.pos<u;){let l=o.uint32();switch(l>>>3){case 1:{yield{field:`${i}.peer`,value:o.bytes()};break}case 2:{yield{field:`${i}.addr`,value:o.bytes()};break}case 3:{yield{field:`${i}.proto`,value:o.string()};break}default:{o.skipType(l&7);break}}}})),e);function r(o){return J(o,t.codec())}t.encode=r;function n(o,c){return Q(o,t.codec(),c)}t.decode=n;function s(o,c){return ee(o,t.codec(),c)}t.stream=s})(Ct||(Ct={}));var Re;(function(t){let e;(function(i){i.FIND_PEER="FIND_PEER",i.FIND_PEERS_CONNECTED_TO_PEER="FIND_PEERS_CONNECTED_TO_PEER",i.FIND_PROVIDERS="FIND_PROVIDERS",i.GET_CLOSEST_PEERS="GET_CLOSEST_PEERS",i.GET_PUBLIC_KEY="GET_PUBLIC_KEY",i.GET_VALUE="GET_VALUE",i.SEARCH_VALUE="SEARCH_VALUE",i.PUT_VALUE="PUT_VALUE",i.PROVIDE="PROVIDE"})(e=t.Type||(t.Type={}));let r;(function(i){i[i.FIND_PEER=0]="FIND_PEER",i[i.FIND_PEERS_CONNECTED_TO_PEER=1]="FIND_PEERS_CONNECTED_TO_PEER",i[i.FIND_PROVIDERS=2]="FIND_PROVIDERS",i[i.GET_CLOSEST_PEERS=3]="GET_CLOSEST_PEERS",i[i.GET_PUBLIC_KEY=4]="GET_PUBLIC_KEY",i[i.GET_VALUE=5]="GET_VALUE",i[i.SEARCH_VALUE=6]="SEARCH_VALUE",i[i.PUT_VALUE=7]="PUT_VALUE",i[i.PROVIDE=8]="PROVIDE"})(r||(r={})),(function(i){i.codec=()=>We(r)})(e=t.Type||(t.Type={}));let n;t.codec=()=>(n==null&&(n=te((i,a,u={})=>{u.lengthDelimited!==!1&&a.fork(),i.type!=null&&(a.uint32(8),t.Type.codec().encode(i.type,a)),i.peer!=null&&(a.uint32(18),a.bytes(i.peer)),i.cid!=null&&(a.uint32(26),a.bytes(i.cid)),i.key!=null&&(a.uint32(34),a.bytes(i.key)),i.value!=null&&(a.uint32(42),a.bytes(i.value)),i.count!=null&&(a.uint32(48),a.int32(i.count)),i.timeout!=null&&(a.uint32(56),a.int64(i.timeout)),u.lengthDelimited!==!1&&a.ldelim()},(i,a,u={})=>{let l={},f=a==null?i.len:i.pos+a;for(;i.pos<f;){let d=i.uint32();switch(d>>>3){case 1:{l.type=t.Type.codec().decode(i);break}case 2:{l.peer=i.bytes();break}case 3:{l.cid=i.bytes();break}case 4:{l.key=i.bytes();break}case 5:{l.value=i.bytes();break}case 6:{l.count=i.int32();break}case 7:{l.timeout=i.int64();break}default:{i.skipType(d&7);break}}}return l},function*(i,a,u,l={}){let f=a==null?i.len:i.pos+a;for(;i.pos<f;){let d=i.uint32();switch(d>>>3){case 1:{yield{field:`${u}.type`,value:t.Type.codec().decode(i)};break}case 2:{yield{field:`${u}.peer`,value:i.bytes()};break}case 3:{yield{field:`${u}.cid`,value:i.bytes()};break}case 4:{yield{field:`${u}.key`,value:i.bytes()};break}case 5:{yield{field:`${u}.value`,value:i.bytes()};break}case 6:{yield{field:`${u}.count`,value:i.int32()};break}case 7:{yield{field:`${u}.timeout`,value:i.int64()};break}default:{i.skipType(d&7);break}}}})),n);function s(i){return J(i,t.codec())}t.encode=s;function o(i,a){return Q(i,t.codec(),a)}t.decode=o;function c(i,a){return ee(i,t.codec(),a)}t.stream=c})(Re||(Re={}));var He;(function(t){let e;(function(i){i.BEGIN="BEGIN",i.VALUE="VALUE",i.END="END"})(e=t.Type||(t.Type={}));let r;(function(i){i[i.BEGIN=0]="BEGIN",i[i.VALUE=1]="VALUE",i[i.END=2]="END"})(r||(r={})),(function(i){i.codec=()=>We(r)})(e=t.Type||(t.Type={}));let n;t.codec=()=>(n==null&&(n=te((i,a,u={})=>{u.lengthDelimited!==!1&&a.fork(),i.type!=null&&(a.uint32(8),t.Type.codec().encode(i.type,a)),i.peer!=null&&(a.uint32(18),Ye.codec().encode(i.peer,a)),i.value!=null&&(a.uint32(26),a.bytes(i.value)),u.lengthDelimited!==!1&&a.ldelim()},(i,a,u={})=>{let l={},f=a==null?i.len:i.pos+a;for(;i.pos<f;){let d=i.uint32();switch(d>>>3){case 1:{l.type=t.Type.codec().decode(i);break}case 2:{l.peer=Ye.codec().decode(i,i.uint32(),{limits:u.limits?.peer});break}case 3:{l.value=i.bytes();break}default:{i.skipType(d&7);break}}}return l},function*(i,a,u,l={}){let f=a==null?i.len:i.pos+a;for(;i.pos<f;){let d=i.uint32();switch(d>>>3){case 1:{yield{field:`${u}.type`,value:t.Type.codec().decode(i)};break}case 2:{yield*Ye.codec().stream(i,i.uint32(),`${u}.peer`,{limits:l.limits?.peer});break}case 3:{yield{field:`${u}.value`,value:i.bytes()};break}default:{i.skipType(d&7);break}}}})),n);function s(i){return J(i,t.codec())}t.encode=s;function o(i,a){return Q(i,t.codec(),a)}t.decode=o;function c(i,a){return ee(i,t.codec(),a)}t.stream=c})(He||(He={}));var Ye;(function(t){let e;t.codec=()=>(e==null&&(e=te((o,c,i={})=>{if(i.lengthDelimited!==!1&&c.fork(),o.id!=null&&o.id.byteLength>0&&(c.uint32(10),c.bytes(o.id)),o.addrs!=null&&o.addrs.length>0)for(let a of o.addrs)c.uint32(18),c.bytes(a);i.lengthDelimited!==!1&&c.ldelim()},(o,c,i={})=>{let a={id:fe(0),addrs:[]},u=c==null?o.len:o.pos+c;for(;o.pos<u;){let l=o.uint32();switch(l>>>3){case 1:{a.id=o.bytes();break}case 2:{if(i.limits?.addrs!=null&&a.addrs.length===i.limits.addrs)throw new G('Decode error - repeated field "addrs" had too many elements');a.addrs.push(o.bytes());break}default:{o.skipType(l&7);break}}}return a},function*(o,c,i,a={}){let u={addrs:0},l=c==null?o.len:o.pos+c;for(;o.pos<l;){let f=o.uint32();switch(f>>>3){case 1:{yield{field:`${i}.id`,value:o.bytes()};break}case 2:{if(a.limits?.addrs!=null&&u.addrs===a.limits.addrs)throw new G('Streaming decode error - repeated field "addrs" had too many elements');yield{field:`${i}.addrs[]`,index:u.addrs,value:o.bytes()},u.addrs++;break}default:{o.skipType(f&7);break}}}})),e);function r(o){return J(o,t.codec())}t.encode=r;function n(o,c){return Q(o,t.codec(),c)}t.decode=n;function s(o,c){return ee(o,t.codec(),c)}t.stream=s})(Ye||(Ye={}));var Ar;(function(t){let e;(function(i){i.TAG_PEER="TAG_PEER",i.UNTAG_PEER="UNTAG_PEER",i.TRIM="TRIM"})(e=t.Type||(t.Type={}));let r;(function(i){i[i.TAG_PEER=0]="TAG_PEER",i[i.UNTAG_PEER=1]="UNTAG_PEER",i[i.TRIM=2]="TRIM"})(r||(r={})),(function(i){i.codec=()=>We(r)})(e=t.Type||(t.Type={}));let n;t.codec=()=>(n==null&&(n=te((i,a,u={})=>{u.lengthDelimited!==!1&&a.fork(),i.type!=null&&(a.uint32(8),t.Type.codec().encode(i.type,a)),i.peer!=null&&(a.uint32(18),a.bytes(i.peer)),i.tag!=null&&(a.uint32(26),a.string(i.tag)),i.weight!=null&&(a.uint32(32),a.int64(i.weight)),u.lengthDelimited!==!1&&a.ldelim()},(i,a,u={})=>{let l={},f=a==null?i.len:i.pos+a;for(;i.pos<f;){let d=i.uint32();switch(d>>>3){case 1:{l.type=t.Type.codec().decode(i);break}case 2:{l.peer=i.bytes();break}case 3:{l.tag=i.string();break}case 4:{l.weight=i.int64();break}default:{i.skipType(d&7);break}}}return l},function*(i,a,u,l={}){let f=a==null?i.len:i.pos+a;for(;i.pos<f;){let d=i.uint32();switch(d>>>3){case 1:{yield{field:`${u}.type`,value:t.Type.codec().decode(i)};break}case 2:{yield{field:`${u}.peer`,value:i.bytes()};break}case 3:{yield{field:`${u}.tag`,value:i.string()};break}case 4:{yield{field:`${u}.weight`,value:i.int64()};break}default:{i.skipType(d&7);break}}}})),n);function s(i){return J(i,t.codec())}t.encode=s;function o(i,a){return Q(i,t.codec(),a)}t.decode=o;function c(i,a){return ee(i,t.codec(),a)}t.stream=c})(Ar||(Ar={}));var Dr;(function(t){let e;t.codec=()=>(e==null&&(e=te((o,c,i={})=>{i.lengthDelimited!==!1&&c.fork(),o.peer!=null&&o.peer.byteLength>0&&(c.uint32(10),c.bytes(o.peer)),i.lengthDelimited!==!1&&c.ldelim()},(o,c,i={})=>{let a={peer:fe(0)},u=c==null?o.len:o.pos+c;for(;o.pos<u;){let l=o.uint32();l>>>3===1?a.peer=o.bytes():o.skipType(l&7)}return a},function*(o,c,i,a={}){let u=c==null?o.len:o.pos+c;for(;o.pos<u;){let l=o.uint32();l>>>3===1?yield{field:`${i}.peer`,value:o.bytes()}:o.skipType(l&7)}})),e);function r(o){return J(o,t.codec())}t.encode=r;function n(o,c){return Q(o,t.codec(),c)}t.decode=n;function s(o,c){return ee(o,t.codec(),c)}t.stream=s})(Dr||(Dr={}));var Xe;(function(t){let e;(function(i){i.GET_TOPICS="GET_TOPICS",i.LIST_PEERS="LIST_PEERS",i.PUBLISH="PUBLISH",i.SUBSCRIBE="SUBSCRIBE"})(e=t.Type||(t.Type={}));let r;(function(i){i[i.GET_TOPICS=0]="GET_TOPICS",i[i.LIST_PEERS=1]="LIST_PEERS",i[i.PUBLISH=2]="PUBLISH",i[i.SUBSCRIBE=3]="SUBSCRIBE"})(r||(r={})),(function(i){i.codec=()=>We(r)})(e=t.Type||(t.Type={}));let n;t.codec=()=>(n==null&&(n=te((i,a,u={})=>{u.lengthDelimited!==!1&&a.fork(),i.type!=null&&(a.uint32(8),t.Type.codec().encode(i.type,a)),i.topic!=null&&(a.uint32(18),a.string(i.topic)),i.data!=null&&(a.uint32(26),a.bytes(i.data)),u.lengthDelimited!==!1&&a.ldelim()},(i,a,u={})=>{let l={},f=a==null?i.len:i.pos+a;for(;i.pos<f;){let d=i.uint32();switch(d>>>3){case 1:{l.type=t.Type.codec().decode(i);break}case 2:{l.topic=i.string();break}case 3:{l.data=i.bytes();break}default:{i.skipType(d&7);break}}}return l},function*(i,a,u,l={}){let f=a==null?i.len:i.pos+a;for(;i.pos<f;){let d=i.uint32();switch(d>>>3){case 1:{yield{field:`${u}.type`,value:t.Type.codec().decode(i)};break}case 2:{yield{field:`${u}.topic`,value:i.string()};break}case 3:{yield{field:`${u}.data`,value:i.bytes()};break}default:{i.skipType(d&7);break}}}})),n);function s(i){return J(i,t.codec())}t.encode=s;function o(i,a){return Q(i,t.codec(),a)}t.decode=o;function c(i,a){return ee(i,t.codec(),a)}t.stream=c})(Xe||(Xe={}));var sn;(function(t){let e;t.codec=()=>(e==null&&(e=te((o,c,i={})=>{if(i.lengthDelimited!==!1&&c.fork(),o.from!=null&&(c.uint32(10),c.bytes(o.from)),o.data!=null&&(c.uint32(18),c.bytes(o.data)),o.seqno!=null&&(c.uint32(26),c.bytes(o.seqno)),o.topicIDs!=null&&o.topicIDs.length>0)for(let a of o.topicIDs)c.uint32(34),c.string(a);o.signature!=null&&(c.uint32(42),c.bytes(o.signature)),o.key!=null&&(c.uint32(50),c.bytes(o.key)),i.lengthDelimited!==!1&&c.ldelim()},(o,c,i={})=>{let a={topicIDs:[]},u=c==null?o.len:o.pos+c;for(;o.pos<u;){let l=o.uint32();switch(l>>>3){case 1:{a.from=o.bytes();break}case 2:{a.data=o.bytes();break}case 3:{a.seqno=o.bytes();break}case 4:{if(i.limits?.topicIDs!=null&&a.topicIDs.length===i.limits.topicIDs)throw new G('Decode error - repeated field "topicIDs" had too many elements');a.topicIDs.push(o.string());break}case 5:{a.signature=o.bytes();break}case 6:{a.key=o.bytes();break}default:{o.skipType(l&7);break}}}return a},function*(o,c,i,a={}){let u={topicIDs:0},l=c==null?o.len:o.pos+c;for(;o.pos<l;){let f=o.uint32();switch(f>>>3){case 1:{yield{field:`${i}.from`,value:o.bytes()};break}case 2:{yield{field:`${i}.data`,value:o.bytes()};break}case 3:{yield{field:`${i}.seqno`,value:o.bytes()};break}case 4:{if(a.limits?.topicIDs!=null&&u.topicIDs===a.limits.topicIDs)throw new G('Streaming decode error - repeated field "topicIDs" had too many elements');yield{field:`${i}.topicIDs[]`,index:u.topicIDs,value:o.string()},u.topicIDs++;break}case 5:{yield{field:`${i}.signature`,value:o.bytes()};break}case 6:{yield{field:`${i}.key`,value:o.bytes()};break}default:{o.skipType(f&7);break}}}})),e);function r(o){return J(o,t.codec())}t.encode=r;function n(o,c){return Q(o,t.codec(),c)}t.decode=n;function s(o,c){return ee(o,t.codec(),c)}t.stream=s})(sn||(sn={}));var Ir;(function(t){let e;t.codec=()=>(e==null&&(e=te((o,c,i={})=>{if(i.lengthDelimited!==!1&&c.fork(),o.topics!=null&&o.topics.length>0)for(let a of o.topics)c.uint32(10),c.string(a);if(o.peerIDs!=null&&o.peerIDs.length>0)for(let a of o.peerIDs)c.uint32(18),c.bytes(a);i.lengthDelimited!==!1&&c.ldelim()},(o,c,i={})=>{let a={topics:[],peerIDs:[]},u=c==null?o.len:o.pos+c;for(;o.pos<u;){let l=o.uint32();switch(l>>>3){case 1:{if(i.limits?.topics!=null&&a.topics.length===i.limits.topics)throw new G('Decode error - repeated field "topics" had too many elements');a.topics.push(o.string());break}case 2:{if(i.limits?.peerIDs!=null&&a.peerIDs.length===i.limits.peerIDs)throw new G('Decode error - repeated field "peerIDs" had too many elements');a.peerIDs.push(o.bytes());break}default:{o.skipType(l&7);break}}}return a},function*(o,c,i,a={}){let u={topics:0,peerIDs:0},l=c==null?o.len:o.pos+c;for(;o.pos<l;){let f=o.uint32();switch(f>>>3){case 1:{if(a.limits?.topics!=null&&u.topics===a.limits.topics)throw new G('Streaming decode error - repeated field "topics" had too many elements');yield{field:`${i}.topics[]`,index:u.topics,value:o.string()},u.topics++;break}case 2:{if(a.limits?.peerIDs!=null&&u.peerIDs===a.limits.peerIDs)throw new G('Streaming decode error - repeated field "peerIDs" had too many elements');yield{field:`${i}.peerIDs[]`,index:u.peerIDs,value:o.bytes()},u.peerIDs++;break}default:{o.skipType(f&7);break}}}})),e);function r(o){return J(o,t.codec())}t.encode=r;function n(o,c){return Q(o,t.codec(),c)}t.decode=n;function s(o,c){return ee(o,t.codec(),c)}t.stream=s})(Ir||(Ir={}));var Cr;(function(t){let e;(function(i){i.UNSPECIFIED="UNSPECIFIED",i.GET_PROTOCOLS="GET_PROTOCOLS",i.GET_PEER_INFO="GET_PEER_INFO"})(e=t.Type||(t.Type={}));let r;(function(i){i[i.UNSPECIFIED=0]="UNSPECIFIED",i[i.GET_PROTOCOLS=1]="GET_PROTOCOLS",i[i.GET_PEER_INFO=2]="GET_PEER_INFO"})(r||(r={})),(function(i){i.codec=()=>We(r)})(e=t.Type||(t.Type={}));let n;t.codec=()=>(n==null&&(n=te((i,a,u={})=>{if(u.lengthDelimited!==!1&&a.fork(),i.type!=null&&(a.uint32(8),t.Type.codec().encode(i.type,a)),i.id!=null&&(a.uint32(18),a.bytes(i.id)),i.protos!=null&&i.protos.length>0)for(let l of i.protos)a.uint32(26),a.string(l);u.lengthDelimited!==!1&&a.ldelim()},(i,a,u={})=>{let l={protos:[]},f=a==null?i.len:i.pos+a;for(;i.pos<f;){let d=i.uint32();switch(d>>>3){case 1:{l.type=t.Type.codec().decode(i);break}case 2:{l.id=i.bytes();break}case 3:{if(u.limits?.protos!=null&&l.protos.length===u.limits.protos)throw new G('Decode error - repeated field "protos" had too many elements');l.protos.push(i.string());break}default:{i.skipType(d&7);break}}}return l},function*(i,a,u,l={}){let f={protos:0},d=a==null?i.len:i.pos+a;for(;i.pos<d;){let p=i.uint32();switch(p>>>3){case 1:{yield{field:`${u}.type`,value:t.Type.codec().decode(i)};break}case 2:{yield{field:`${u}.id`,value:i.bytes()};break}case 3:{if(l.limits?.protos!=null&&f.protos===l.limits.protos)throw new G('Streaming decode error - repeated field "protos" had too many elements');yield{field:`${u}.protos[]`,index:f.protos,value:i.string()},f.protos++;break}default:{i.skipType(p&7);break}}}})),n);function s(i){return J(i,t.codec())}t.encode=s;function o(i,a){return Q(i,t.codec(),a)}t.decode=o;function c(i,a){return ee(i,t.codec(),a)}t.stream=c})(Cr||(Cr={}));var Br;(function(t){let e;t.codec=()=>(e==null&&(e=te((o,c,i={})=>{if(i.lengthDelimited!==!1&&c.fork(),o.peer!=null&&(c.uint32(10),Ye.codec().encode(o.peer,c)),o.protos!=null&&o.protos.length>0)for(let a of o.protos)c.uint32(18),c.string(a);i.lengthDelimited!==!1&&c.ldelim()},(o,c,i={})=>{let a={protos:[]},u=c==null?o.len:o.pos+c;for(;o.pos<u;){let l=o.uint32();switch(l>>>3){case 1:{a.peer=Ye.codec().decode(o,o.uint32(),{limits:i.limits?.peer});break}case 2:{if(i.limits?.protos!=null&&a.protos.length===i.limits.protos)throw new G('Decode error - repeated field "protos" had too many elements');a.protos.push(o.string());break}default:{o.skipType(l&7);break}}}return a},function*(o,c,i,a={}){let u={protos:0},l=c==null?o.len:o.pos+c;for(;o.pos<l;){let f=o.uint32();switch(f>>>3){case 1:{yield*Ye.codec().stream(o,o.uint32(),`${i}.peer`,{limits:a.limits?.peer});break}case 2:{if(a.limits?.protos!=null&&u.protos===a.limits.protos)throw new G('Streaming decode error - repeated field "protos" had too many elements');yield{field:`${i}.protos[]`,index:u.protos,value:o.string()},u.protos++;break}default:{o.skipType(f&7);break}}}})),e);function r(o){return J(o,t.codec())}t.encode=r;function n(o,c){return Q(o,t.codec(),c)}t.decode=n;function s(o,c){return ee(o,t.codec(),c)}t.stream=s})(Br||(Br={}));function mc(t){let e=new globalThis.AbortController;function r(){let o=t.filter(c=>c?.aborted===!0).map(c=>c?.reason).pop();e.abort(o);for(let c of t)c?.removeEventListener!=null&&c.removeEventListener("abort",r)}for(let o of t){if(o?.aborted===!0){r();break}o?.addEventListener!=null&&o.addEventListener("abort",r)}function n(){for(let o of t)o?.removeEventListener!=null&&o.removeEventListener("abort",r)}let s=e.signal;return s.clear=n,s}var Lr=class{onConnection;constructor(e){this.onConnection=e}async upgradeInbound(e){this.onConnection?.(e)}async upgradeOutbound(e){return e}createInboundAbortSignal(e){return mc([e])}getStreamMuxers(){return new Map}getConnectionEncrypters(){return new Map}};var cn=class extends Error{static name="AbortError";constructor(e="The operation was aborted"){super(e),this.name="AbortError"}};var B=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}},Or=class extends Error{static name="InvalidPublicKeyError";constructor(e="Invalid public key"){super(e),this.name="InvalidPublicKeyError"}};var an=class extends Error{static name="StreamResetError";constructor(e="The stream has been reset"){super(e),this.name="StreamResetError"}};var bt=class extends Error{static name="StreamStateError";constructor(e="The stream is in an invalid state"){super(e),this.name="StreamStateError"}},Bt=class extends Error{static name="StreamBufferError";constructor(e="The stream buffer was full"){super(e),this.name="StreamBufferError"}};var un=class extends Error{static name="InvalidMultihashError";constructor(e="Invalid Multihash"){super(e),this.name="InvalidMultihashError"}};var kr=class extends Error{static name="InvalidMessageError";constructor(e="Invalid message"){super(e),this.name="InvalidMessageError"}},_r=class extends Error{static name="ProtocolError";constructor(e="Protocol error"){super(e),this.name="ProtocolError"}},zt=class extends Error{static name="TimeoutError";constructor(e="Timed out"){super(e),this.name="TimeoutError"}},ln=class extends Error{static name="NotStartedError";constructor(e="Not started"){super(e),this.name="NotStartedError"}},fn=class extends Error{static name="AlreadyStartedError";constructor(e="Already started"){super(e),this.name="AlreadyStartedError"}};var Pr=class extends Error{static name="UnsupportedKeyTypeError";constructor(e="Unsupported key type"){super(e),this.name="UnsupportedKeyTypeError"}};var dn=class extends Event{data;constructor(e,r){super("message",r),this.data=e}},Vt=class extends Event{error;local;constructor(e,r,n){super("close",n),this.error=r,this.local=e}},hn=class extends Vt{constructor(e,r){super(!0,e,r)}},pn=class extends Vt{constructor(e,r){super(!1,e,r)}};var mn=Symbol.for("@libp2p/peer-id");function Gt(t){return!!t?.[mn]}var bc=Symbol.for("@libp2p/transport");var yc;(function(t){t[t.FATAL_ALL=0]="FATAL_ALL",t[t.NO_FATAL=1]="NO_FATAL"})(yc||(yc={}));var gc=le("node:events"),yn=(t,...e)=>{try{(0,gc.setMaxListeners)(t,...e)}catch{}};function Yl(t){return typeof t?.handleEvent=="function"}function ql(t){return t===!0||t===!1}function Zl(t){return ql(t)?t:t?.capture??!1}function gi(t){let e={capture:Zl(t),once:!!t?.once};return t?.passive!=null&&(e.passive=t?.passive),t?.signal!=null&&(e.signal=t?.signal),e}function wc(t,e){return gi(t).capture===gi(e).capture}var Wt=class extends EventTarget{#e=new Map;constructor(){super(),yn(1/0,this)}listenerCount(e){let r=this.#e.get(e);return r==null?0:r.length}addEventListener(e,r,n){let s=gi(n);if(s?.signal?.aborted===!0)return;let o=u=>{s.once&&this.removeEventListener(e,r,s),Yl(r)?r.handleEvent(u):r(u)},c=this.#e.get(e);if(c==null&&(c=[],this.#e.set(e,c)),c.some(u=>u.callback!==r?!1:wc(u.options,s)))return;super.addEventListener(e,o,s);let a=()=>{this.removeEventListener(e,r,s)};s.signal?.addEventListener("abort",a),c.push({callback:r,wrapper:o,options:s,onAbort:a})}removeEventListener(e,r,n){let s=this.#e.get(e);if(s==null){super.removeEventListener(e,r??null,n);return}this.#e.set(e,s.filter(o=>o.callback===r&&wc(o.options,n)?(super.removeEventListener(e,o.wrapper,n),o.options?.signal?.removeEventListener("abort",o.onAbort),!1):!0))}safeDispatchEvent(e,r={}){return this.dispatchEvent(new CustomEvent(e,r))}};var xc=Symbol.for("@libp2p/service-capabilities");var Sc=_e(le("node:tty"),1),En=_e(le("node:util"),1);function bn(t,e){if(typeof t=="string")return jl(t);if(typeof t=="number")return Jl(t,e);throw new Error(`Value provided to ms() must be a string or number. value=${JSON.stringify(t)}`)}function jl(t){if(typeof t!="string"||t.length===0||t.length>100)throw new Error(`Value provided to ms.parse() must be a string with length between 1 and 99. value=${JSON.stringify(t)}`);let e=/^(?<value>-?\d*\.?\d+) *(?<unit>milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|months?|mo|years?|yrs?|y)?$/i.exec(t);if(!e?.groups)return NaN;let{value:r,unit:n="ms"}=e.groups,s=parseFloat(r),o=n.toLowerCase();switch(o){case"years":case"year":case"yrs":case"yr":case"y":return s*315576e5;case"months":case"month":case"mo":return s*26298e5;case"weeks":case"week":case"w":return s*6048e5;case"days":case"day":case"d":return s*864e5;case"hours":case"hour":case"hrs":case"hr":case"h":return s*36e5;case"minutes":case"minute":case"mins":case"min":case"m":return s*6e4;case"seconds":case"second":case"secs":case"sec":case"s":return s*1e3;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return s;default:throw new Error(`Unknown unit "${o}" provided to ms.parse(). value=${JSON.stringify(t)}`)}}function Xl(t){let e=Math.abs(t);return e>=315576e5?`${Math.round(t/315576e5)}y`:e>=26298e5?`${Math.round(t/26298e5)}mo`:e>=6048e5?`${Math.round(t/6048e5)}w`:e>=864e5?`${Math.round(t/864e5)}d`:e>=36e5?`${Math.round(t/36e5)}h`:e>=6e4?`${Math.round(t/6e4)}m`:e>=1e3?`${Math.round(t/1e3)}s`:`${t}ms`}function Ql(t){let e=Math.abs(t);return e>=315576e5?Lt(t,e,315576e5,"year"):e>=26298e5?Lt(t,e,26298e5,"month"):e>=6048e5?Lt(t,e,6048e5,"week"):e>=864e5?Lt(t,e,864e5,"day"):e>=36e5?Lt(t,e,36e5,"hour"):e>=6e4?Lt(t,e,6e4,"minute"):e>=1e3?Lt(t,e,1e3,"second"):`${t} ms`}function Jl(t,e){if(typeof t!="number"||!Number.isFinite(t))throw new Error("Value provided to ms.format() must be of type number.");return e?.long?Ql(t):Xl(t)}function Lt(t,e,r,n){let s=e>=r*1.5;return`${Math.round(t/r)} ${n}${s?"s":""}`}var wn=_e(le("node:process"),1),vc=_e(le("node:os"),1),wi=_e(le("node:tty"),1);function ze(t,e=globalThis.Deno?globalThis.Deno.args:wn.default.argv){let r=t.startsWith("-")?"":t.length===1?"-":"--",n=e.indexOf(r+t),s=e.indexOf("--");return n!==-1&&(s===-1||n<s)}var{env:j}=wn.default,gn;ze("no-color")||ze("no-colors")||ze("color=false")||ze("color=never")?gn=0:(ze("color")||ze("colors")||ze("color=true")||ze("color=always"))&&(gn=1);function ef(){if(!("FORCE_COLOR"in j))return;if(j.FORCE_COLOR==="true")return 1;if(j.FORCE_COLOR==="false")return 0;if(j.FORCE_COLOR.length===0)return 1;let t=Math.min(Number.parseInt(j.FORCE_COLOR,10),3);if([0,1,2,3].includes(t))return t}function tf(t){return t===0?!1:{level:t,hasBasic:!0,has256:t>=2,has16m:t>=3}}function rf(t,{streamIsTTY:e,sniffFlags:r=!0}={}){let n=ef();n!==void 0&&(gn=n);let s=r?gn:n;if(s===0)return 0;if(r){if(ze("color=16m")||ze("color=full")||ze("color=truecolor"))return 3;if(ze("color=256"))return 2}if("TF_BUILD"in j&&"AGENT_NAME"in j)return 1;if(t&&!e&&s===void 0)return 0;let o=s||0;if(j.TERM==="dumb")return o;if(wn.default.platform==="win32"){let c=vc.default.release().split(".");return Number(c[0])>=10&&Number(c[2])>=10586?Number(c[2])>=14931?3:2:1}if("CI"in j)return["GITHUB_ACTIONS","GITEA_ACTIONS","CIRCLECI"].some(c=>c in j)?3:["TRAVIS","APPVEYOR","GITLAB_CI","BUILDKITE","DRONE"].some(c=>c in j)||j.CI_NAME==="codeship"?1:o;if("TEAMCITY_VERSION"in j)return/^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(j.TEAMCITY_VERSION)?1:0;if(j.COLORTERM==="truecolor"||j.TERM==="xterm-kitty"||j.TERM==="xterm-ghostty"||j.TERM==="wezterm")return 3;if("TERM_PROGRAM"in j){let c=Number.parseInt((j.TERM_PROGRAM_VERSION||"").split(".")[0],10);switch(j.TERM_PROGRAM){case"iTerm.app":return c>=3?3:2;case"Apple_Terminal":return 2}}return/-256(color)?$/i.test(j.TERM)?2:/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(j.TERM)||"COLORTERM"in j?1:o}function Ec(t,e={}){let r=rf(t,{streamIsTTY:t&&t.isTTY,...e});return tf(r)}var nf={stdout:Ec({isTTY:wi.default.isatty(1)}),stderr:Ec({isTTY:wi.default.isatty(2)})},xn=nf;function xi(t){r.debug=r,r.default=r,r.coerce=a,r.disable=o,r.enable=s,r.enabled=c,r.humanize=bn,r.destroy=u,Object.keys(t).forEach(l=>{r[l]=t[l]}),r.names=[],r.skips=[],r.formatters={};function e(l){let f=0;for(let d=0;d<l.length;d++)f=(f<<5)-f+l.charCodeAt(d),f|=0;return r.colors[Math.abs(f)%r.colors.length]}r.selectColor=e;function r(l,f){let d,p=null,x,D;function b(...y){if(!b.enabled)return;let T=b,P=Number(new Date),_=P-(d||P);T.diff=_,T.prev=d,T.curr=P,d=P,y[0]=r.coerce(y[0]),typeof y[0]!="string"&&y.unshift("%O");let M=0;y[0]=y[0].replace(/%([a-zA-Z%])/g,(ie,re)=>{if(ie==="%%")return"%";M++;let we=r.formatters[re];if(typeof we=="function"){let V=y[M];ie=we.call(T,V),y.splice(M,1),M--}return ie}),r.formatArgs.call(T,y),f?.onLog!=null&&f.onLog(...y),(T.log||r.log).apply(T,y)}return b.namespace=l,b.useColors=r.useColors(),b.color=r.selectColor(l),b.extend=n,b.destroy=r.destroy,Object.defineProperty(b,"enabled",{enumerable:!0,configurable:!1,get:()=>p!==null?p:(x!==r.namespaces&&(x=r.namespaces,D=r.enabled(l)),D),set:y=>{p=y}}),typeof r.init=="function"&&r.init(b),b}function n(l,f){let d=r(this.namespace+(typeof f>"u"?":":f)+l);return d.log=this.log,d}function s(l){r.save(l),r.namespaces=l,r.names=[],r.skips=[];let f,d=(typeof l=="string"?l:"").split(/[\s,]+/),p=d.length;for(f=0;f<p;f++)d[f]&&(l=d[f].replace(/\*/g,".*?"),l[0]==="-"?r.skips.push(new RegExp("^"+l.substr(1)+"$")):r.names.push(new RegExp("^"+l+"$")))}function o(){let l=[...r.names.map(i),...r.skips.map(i).map(f=>"-"+f)].join(",");return r.enable(""),l}function c(l){if(l[l.length-1]==="*")return!0;let f,d;for(f=0,d=r.skips.length;f<d;f++)if(r.skips[f].test(l))return!1;for(f=0,d=r.names.length;f<d;f++)if(r.names[f].test(l))return!0;return!1}function i(l){return l.toString().substring(2,l.toString().length-2).replace(/\.\*\?$/,"*")}function a(l){return l instanceof Error?l.stack??l.message:l}function u(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")}return r.setupFormatters(r.formatters),r.enable(r.load()),r}var Tc=[6,2,3,4,5,1];xn.stderr!==!1&&(xn.stderr??xn).level>=2&&(Tc=[20,21,26,27,32,33,38,39,40,41,42,43,44,45,56,57,62,63,68,69,74,75,76,77,78,79,80,81,92,93,98,99,112,113,128,129,134,135,148,149,160,161,162,163,164,165,166,167,168,169,170,171,172,173,178,179,184,185,196,197,198,199,200,201,202,203,204,205,206,207,208,209,214,215,220,221]);var Yt=Object.keys(process.env).filter(t=>/^debug_/i.test(t)).reduce((t,e)=>{let r=e.substring(6).toLowerCase().replace(/_([a-z])/g,(s,o)=>o.toUpperCase()),n=process.env[e];return/^(yes|on|true|enabled)$/i.test(n)?n=!0:/^(no|off|false|disabled)$/i.test(n)?n=!1:n==="null"?n=null:n=Number(n),t[r]=n,t},{});function of(){return"colors"in Yt?!!Yt.colors:Sc.default.isatty(process.stderr.fd)}function sf(t){let{namespace:e,useColors:r}=this;if(r===!0){let n=this.color,s="\x1B[3"+(n<8?n:"8;5;"+n),o=` ${s};1m${e} \x1B[0m`;t[0]=o+t[0].split(`
3
3
  `).join(`
4
- `+o),t.push(s+"m+"+bn(this.diff)+"\x1B[0m")}else t[0]=af()+e+" "+t[0]}function af(){return Yt.hideDate!=null?"":new Date().toISOString()+" "}function uf(...t){return process.stderr.write(En.default.format(...t)+`
5
- `)}function lf(t){t!=null?process.env.DEBUG=t:delete process.env.DEBUG}function ff(){return process.env.DEBUG}function df(t){t.inspectOpts={};let e=Object.keys(Yt);for(let r=0;r<e.length;r++)t.inspectOpts[e[r]]=Yt[e[r]]}function hf(t){t.o=function(e){return this.inspectOpts.colors=this.useColors,En.default.inspect(e,this.inspectOpts).split(`
6
- `).map(r=>r.trim()).join(" ")},t.O=function(e){return this.inspectOpts.colors=this.useColors,En.default.inspect(e,this.inspectOpts)}}var Ac=xi({init:df,log:uf,formatArgs:cf,save:lf,load:ff,useColors:sf,setupFormatters:hf,colors:Tc,inspectOpts:Yt});var Le=Ac;Le.formatters.b=t=>t==null?"undefined":ce.baseEncode(t);Le.formatters.t=t=>t==null?"undefined":je.baseEncode(t);Le.formatters.m=t=>t==null?"undefined":Qo.baseEncode(t);Le.formatters.p=t=>t==null?"undefined":t.toString();Le.formatters.c=t=>t==null?"undefined":t.toString();Le.formatters.k=t=>t==null?"undefined":t.toString();Le.formatters.a=t=>t==null?"undefined":t.toString();function Dc(t,e=""){let r=Ic(t.message),n=Ic(t.stack);return r!=null&&n!=null?n.includes(r)?`${n.split(`
4
+ `+o),t.push(s+"m+"+bn(this.diff)+"\x1B[0m")}else t[0]=cf()+e+" "+t[0]}function cf(){return Yt.hideDate!=null?"":new Date().toISOString()+" "}function af(...t){return process.stderr.write(En.default.format(...t)+`
5
+ `)}function uf(t){t!=null?process.env.DEBUG=t:delete process.env.DEBUG}function lf(){return process.env.DEBUG}function ff(t){t.inspectOpts={};let e=Object.keys(Yt);for(let r=0;r<e.length;r++)t.inspectOpts[e[r]]=Yt[e[r]]}function df(t){t.o=function(e){return this.inspectOpts.colors=this.useColors,En.default.inspect(e,this.inspectOpts).split(`
6
+ `).map(r=>r.trim()).join(" ")},t.O=function(e){return this.inspectOpts.colors=this.useColors,En.default.inspect(e,this.inspectOpts)}}var Ac=xi({init:ff,log:af,formatArgs:sf,save:uf,load:lf,useColors:of,setupFormatters:df,colors:Tc,inspectOpts:Yt});var Le=Ac;Le.formatters.b=t=>t==null?"undefined":ae.baseEncode(t);Le.formatters.t=t=>t==null?"undefined":je.baseEncode(t);Le.formatters.m=t=>t==null?"undefined":Qo.baseEncode(t);Le.formatters.p=t=>t==null?"undefined":t.toString();Le.formatters.c=t=>t==null?"undefined":t.toString();Le.formatters.k=t=>t==null?"undefined":t.toString();Le.formatters.a=t=>t==null?"undefined":t.toString();function Dc(t,e=""){let r=Ic(t.message),n=Ic(t.stack);return r!=null&&n!=null?n.includes(r)?`${n.split(`
7
7
  `).join(`
8
8
  ${e}`)}`:`${r}
9
9
  ${e}${n.split(`
10
10
  `).join(`
11
11
  ${e}`)}`:n!=null?`${n.split(`
12
12
  `).join(`
13
- ${e}`)}`:r!=null?`${r}`:`${t.toString()}`}function pf(t){return t instanceof AggregateError||t?.name==="AggregateError"&&Array.isArray(t.errors)}function Cc(t,e=""){if(pf(t)){let r=Dc(t,e);return t.errors.length>0?(e=`${e} `,r+=`
13
+ ${e}`)}`:r!=null?`${r}`:`${t.toString()}`}function hf(t){return t instanceof AggregateError||t?.name==="AggregateError"&&Array.isArray(t.errors)}function Cc(t,e=""){if(hf(t)){let r=Dc(t,e);return t.errors.length>0?(e=`${e} `,r+=`
14
14
  ${e}${t.errors.map(n=>`${Cc(n,`${e}`)}`).join(`
15
15
  ${e}`)}`):r+=`
16
- ${e}[Error list was empty]`,r.trim()}return Dc(t,e)}Le.formatters.e=t=>t==null?"undefined":Cc(t);function mf(t){let e=()=>{};return e.enabled=!1,e.color="",e.diff=0,e.log=()=>{},e.namespace=t,e.destroy=()=>!0,e.extend=()=>e,e.useColors=()=>!1,e}function Bc(t){return{forComponent(e){return qt(e,t)}}}function qt(t,e){let r=mf(`${t}:trace`);return Le.enabled(`${t}:trace`)&&Le.names.map(n=>n.toString()).find(n=>n.includes(":trace"))!=null&&(r=Le(`${t}:trace`,e)),Object.assign(Le(t,e),{error:Le(`${t}:error`,e),trace:r,newScope:n=>qt(`${t}:${n}`,e)})}function Ic(t){if(t!=null&&(t=t.trim(),t.length!==0))return t}function Ae(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}async function Lc(t,e,r,n){let s=await crypto.subtle.importKey("jwk",t,{name:"ECDSA",namedCurve:t.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let o=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},s,ht(e),ht(r.subarray()));return n?.signal?.throwIfAborted(),o}var Oc=ue("node:buffer");function qe(t,e){return dt(Oc.Buffer.concat(t,e))}var _c=Symbol.for("@achingbrain/uint8arraylist");function kc(t,e){if(e==null||e<0)throw new RangeError("index is out of bounds");let r=0;for(let n of t){let s=r+n.byteLength;if(e<s)return{buf:n,index:e-r};r=s}throw new RangeError("index is out of bounds")}function vn(t){return!!t?.[_c]}var oe=class t{bufs;length;[_c]=!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 r=0;for(let n of e)if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.push(n);else if(vn(n)){r+=n.byteLength;for(let s of n.bufs)this.bufs.push(s)}else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}prepend(...e){this.prependAll(e)}prependAll(e){let r=0;for(let n of e.reverse())if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.unshift(n);else if(vn(n))r+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}get(e){let r=kc(this.bufs,e);return r.buf[r.index]}set(e,r){let n=kc(this.bufs,e);n.buf[n.index]=r}write(e,r=0){if(e instanceof Uint8Array)for(let n=0;n<e.length;n++)this.set(r+n,e[n]);else if(vn(e))for(let n=0;n<e.length;n++)this.set(r+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,r){let{bufs:n,length:s}=this._subList(e,r);return qe(n,s)}subarray(e,r){let{bufs:n,length:s}=this._subList(e,r);return n.length===1?n[0]:qe(n,s)}sublist(e,r){let{bufs:n,length:s}=this._subList(e,r),o=new t;return o.length=s,o.bufs=n,o}_subList(e,r){if(e=e??0,r=r??this.length,e<0&&(e=this.length+e),r<0&&(r=this.length+r),e<0||r>this.length)throw new RangeError("index is out of bounds");if(e===r)return{bufs:[],length:0};if(e===0&&r===this.length)return{bufs:[...this.bufs],length:this.length};let n=[],s=0;for(let o=0;o<this.bufs.length;o++){let c=this.bufs[o],i=s,a=i+c.byteLength;if(s=a,e>=a)continue;let u=e>=i&&e<a,l=r>i&&r<=a;if(u&&l){if(e===i&&r===a){n.push(c);break}let f=e-i;n.push(c.subarray(f,f+(r-e)));break}if(u){if(e===0){n.push(c);continue}n.push(c.subarray(e-i));continue}if(l){if(r===a){n.push(c);break}n.push(c.subarray(0,r-i));break}n.push(c)}return{bufs:n,length:r-e}}indexOf(e,r=0){if(!vn(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(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),e.length===0)return r>this.length?this.length:r;let s=n.byteLength;if(s===0)throw new TypeError("search must be at least 1 byte long");let o=256,c=new Int32Array(o);for(let f=0;f<o;f++)c[f]=-1;for(let f=0;f<s;f++)c[n[f]]=f;let i=c,a=this.byteLength-n.byteLength,u=n.byteLength-1,l;for(let f=r;f<=a;f+=l){l=0;for(let d=u;d>=0;d--){let p=this.get(f+d);if(n[d]!==p){l=Math.max(1,d-i[p]);break}}if(l===0)return f}return-1}getInt8(e){let r=this.subarray(e,e+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(e,r){let n=Ce(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,r),this.write(n,e)}getInt16(e,r){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,r)}setInt16(e,r,n){let s=le(2);new DataView(s.buffer,s.byteOffset,s.byteLength).setInt16(0,r,n),this.write(s,e)}getInt32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,r)}setInt32(e,r,n){let s=le(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setInt32(0,r,n),this.write(s,e)}getBigInt64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,r)}setBigInt64(e,r,n){let s=le(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setBigInt64(0,r,n),this.write(s,e)}getUint8(e){let r=this.subarray(e,e+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint8(0)}setUint8(e,r){let n=Ce(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,r),this.write(n,e)}getUint16(e,r){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,r)}setUint16(e,r,n){let s=le(2);new DataView(s.buffer,s.byteOffset,s.byteLength).setUint16(0,r,n),this.write(s,e)}getUint32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,r)}setUint32(e,r,n){let s=le(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setUint32(0,r,n),this.write(s,e)}getBigUint64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,r)}setBigUint64(e,r,n){let s=le(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setBigUint64(0,r,n),this.write(s,e)}getFloat32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,r)}setFloat32(e,r,n){let s=le(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setFloat32(0,r,n),this.write(s,e)}getFloat64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,r)}setFloat64(e,r,n){let s=le(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setFloat64(0,r,n),this.write(s,e)}equals(e){if(e==null||!(e instanceof t)||e.bufs.length!==this.bufs.length)return!1;for(let r=0;r<this.bufs.length;r++)if(!Ae(this.bufs[r],e.bufs[r]))return!1;return!0}static fromUint8Arrays(e,r){let n=new t;return n.bufs=e,r==null&&(r=e.reduce((s,o)=>s+o.byteLength,0)),n.length=r,n}};var Pc=ue("node:buffer");function ae(t,e="utf8"){let r=tn[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return e==="utf8"||e==="utf-8"?Pc.Buffer.from(t.buffer,t.byteOffset,t.byteLength).toString("utf8"):r.encoder.encode(t).substring(1)}var yf=parseInt("11111",2),Ei=parseInt("10000000",2),bf=parseInt("01111111",2),Rc={0:Rr,1:Rr,2:gf,3:Ef,4:vf,5:xf,6:wf,16:Rr,22:Rr,48:Rr};function vi(t,e={offset:0}){let r=t[e.offset]&yf;if(e.offset++,Rc[r]!=null)return Rc[r](t,e);throw new Error("No decoder for tag "+r)}function Nr(t,e){let r=0;if((t[e.offset]&Ei)===Ei){let n=t[e.offset]&bf,s="0x";e.offset++;for(let o=0;o<n;o++,e.offset++){if(e.offset>=t.byteLength)throw new Error("invalid DER element length");s+=t[e.offset].toString(16).padStart(2,"0")}r=parseInt(s,16)}else r=t[e.offset],e.offset++;if(!Number.isInteger(r)||r<0||r>t.byteLength-e.offset)throw new Error("invalid DER element length");return r}function Rr(t,e){Nr(t,e);let r=[];for(;!(e.offset>=t.byteLength);){let n=vi(t,e);if(n===null)break;r.push(n)}return r}function gf(t,e){let r=Nr(t,e),n=e.offset,s=e.offset+r,o=[];for(let c=n;c<s;c++)c===n&&t[c]===0||o.push(t[c]);return e.offset+=r,Uint8Array.from(o)}function wf(t,e){let r=Nr(t,e),n=e.offset+r,s=t[e.offset];e.offset++;let o=0,c=0;s<40?(o=0,c=s):s<80?(o=1,c=s-40):(o=2,c=s-80);let i=`${o}.${c}`,a=[];for(;e.offset<n;){let u=t[e.offset];if(e.offset++,a.push(u&127),u<128){a.reverse();let l=0;for(let f=0;f<a.length;f++)l+=a[f]<<f*7;i+=`.${l}`,a=[]}}return i}function xf(t,e){return e.offset++,null}function Ef(t,e){let r=Nr(t,e),n=t[e.offset];e.offset++;let s=t.subarray(e.offset,e.offset+r-1);if(e.offset+=r,n!==0)throw new Error("Unused bits in bit string is unimplemented");return s}function vf(t,e){let r=Nr(t,e),n=t.subarray(e.offset,e.offset+r);return e.offset+=r,n}function Sf(t){let e=t.toString(16);e.length%2===1&&(e="0"+e);let r=new oe;for(let n=0;n<e.length;n+=2)r.append(Uint8Array.from([parseInt(`${e[n]}${e[n+1]}`,16)]));return r}function Si(t){if(t.byteLength<128)return Uint8Array.from([t.byteLength]);let e=Sf(t.byteLength);return new oe(Uint8Array.from([e.byteLength|Ei]),e)}function Nc(t){let e=new oe,r=128;return(t.subarray()[0]&r)===r&&e.append(Uint8Array.from([0])),e.append(t),new oe(Uint8Array.from([2]),Si(e),e)}function Uc(t){let e=Uint8Array.from([0]),r=new oe(e,t);return new oe(Uint8Array.from([3]),Si(r),r)}function Sn(t,e=48){let r=new oe;for(let n of t)r.append(n);return new oe(Uint8Array.from([e]),Si(r),r)}var Tf=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Af=Uint8Array.from([6,5,43,129,4,0,34]),Df=Uint8Array.from([6,5,43,129,4,0,35]),If={ext:!0,kty:"EC",crv:"P-256"},Cf={ext:!0,kty:"EC",crv:"P-384"},Bf={ext:!0,kty:"EC",crv:"P-521"},Ti=32,Ai=48,Di=66;function Fc(t){let e=vi(t);return Mc(e)}function Mc(t){let e=t[1][1][0],r=1,n,s;if(e.byteLength===Ti*2+1)return n=ae(e.subarray(r,r+Ti),"base64url"),s=ae(e.subarray(r+Ti),"base64url"),new Zt({...If,key_ops:["verify"],x:n,y:s});if(e.byteLength===Ai*2+1)return n=ae(e.subarray(r,r+Ai),"base64url"),s=ae(e.subarray(r+Ai),"base64url"),new Zt({...Cf,key_ops:["verify"],x:n,y:s});if(e.byteLength===Di*2+1)return n=ae(e.subarray(r,r+Di),"base64url"),s=ae(e.subarray(r+Di),"base64url"),new Zt({...Bf,key_ops:["verify"],x:n,y:s});throw new B(`coordinates were wrong length, got ${e.byteLength}, expected 65, 97 or 133`)}function Kc(t){return Sn([Nc(Uint8Array.from([1])),Sn([Lf(t.crv)],160),Sn([Uc(new oe(Uint8Array.from([4]),Te(t.x??"","base64url"),Te(t.y??"","base64url")))],161)]).subarray()}function Lf(t){if(t==="P-256")return Tf;if(t==="P-384")return Af;if(t==="P-521")return Df;throw new B(`Invalid curve ${t}`)}var Zt=class{type="ECDSA";jwk;_raw;constructor(e){this.jwk=e}get raw(){return this._raw==null&&(this._raw=Kc(this.jwk)),this._raw}toMultihash(){return Ge.digest(jt(this))}toCID(){return fe.createV1(114,this.toMultihash())}toString(){return ce.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Ae(this.raw,e.raw)}async verify(e,r,n){return Lc(this.jwk,r,e,n)}};var $n=ke(ue("crypto"),1);var Of=t=>t/2**32|0,kf=t=>t>>>0;function $c(t,e,r,n){let s=Of(r),o=kf(r);t.setUint32(e,n?o:s,n),t.setUint32(e+4,n?s:o,n)}function Tn(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in t&&t.BYTES_PER_ELEMENT===1}var Ii=t=>t?`"${t}" `:"";function nt(t,e=""){if(typeof t!="number")throw new TypeError(Ii(e)+"expected number, got "+typeof t);if(!Number.isSafeInteger(t)||t<0)throw new RangeError(Ii(e)+"expected integer >= 0, got "+t);return t}function Qe(t,e,r=""){if(Tn(t)&&(e===void 0||t.length===e))return t;e!==void 0&&nt(e,"length");let n=Tn(t),s=e!==void 0?` of length ${e}`:"",o=n?`length=${t.length}`:`type=${typeof t}`,c=Ii(r)+"expected Uint8Array"+s+", got "+o;throw n?new RangeError(c):new TypeError(c)}function An(t){if(typeof t!="function"||typeof t.create!="function")throw new TypeError("expected hash wrapped by utils.createHasher");if(nt(t.outputLen),nt(t.blockLen),t.outputLen<1||t.blockLen<1)throw new Error("hash blockLen / outputLen must be >= 1")}var _f=(t,e)=>{if(t===null||typeof t!="object"||Array.isArray(t))throw new TypeError((e==="object"?"":`"${e}" `)+"expected object, got type="+typeof t)},Hc=(t,e)=>{_f(t,e);let r=Object.getPrototypeOf(t);if(r!==Object.prototype&&r!==null)throw new TypeError(`"${e}" expected plain object`);if(Object.hasOwn(t,"__proto__"))throw new TypeError(`"${e}.__proto__" is not allowed`)};function Xt(t,e=!0){if(t.destroyed)throw new Error("hash was destroyed");if(e&&t.finished)throw new Error("digest() was already called")}function Dn(t,e){Qe(t,void 0,"output");let r=e.outputLen;if(!(t.length>=r))throw new RangeError('"output" expected length >= '+r)}function Ur(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function In(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function Ze(t,e){return t<<32-e|t>>>e}var Vc=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Pf=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function Cn(t){if(Qe(t),Vc)return t.toHex();let e="";for(let r=0;r<t.length;r++)e+=Pf[t[r]];return e}function zc(t){return t>=48&&t<=57?t-48:t>=65&&t<=70?t-55:t>=97&&t<=102?t-87:void 0}function Ci(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);if(Vc)try{return Uint8Array.fromHex(t)}catch(s){throw s instanceof SyntaxError?new RangeError(s.message):s}let e=t.length,r=e/2;if(e%2)throw new RangeError("hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(r);for(let s=0,o=0;s<r;s++,o+=2){let c=zc(t.charCodeAt(o)),i=zc(t.charCodeAt(o+1));if(c===void 0||i===void 0){let a=t[o]+t[o+1];throw new RangeError('hex string expected, got non-hex character "'+a+'" at index '+o)}n[s]=c*16+i}return n}function Gc(...t){let e=0;for(let n=0;n<t.length;n++){let s=t[n];Qe(s),e+=s.length}let r=new Uint8Array(e);for(let n=0,s=0;n<t.length;n++){let o=t[n];r.set(o,s),s+=o.length}return r}function Rf(t,e,r="opts"){return Hc(t,"defaults"),e!==void 0&&Hc(e,r),Object.assign(Object.create(null),t,e)}function Wc(t,e={}){if(typeof t!="function")throw new TypeError('"hashCons" expected function, got type='+typeof t);e=Rf({},e,"info");let r=(s,o)=>t(o).update(s).digest(),n=t(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.canXOF=n.canXOF,r.create=s=>t(s),Object.assign(r,e),Object.freeze(r)}function Yc(t=32){nt(t,"bytesLength");let e=typeof globalThis=="object"?globalThis.crypto:null;if(typeof e?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");if(t>65536)throw new RangeError(`"bytesLength" expected <= 65536, got ${t}`);return e.getRandomValues(new Uint8Array(t))}var qc=t=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,t])});function Zc(t,e,r){return t&e^~t&r}function jc(t,e,r){return t&e^t&r^e&r}var Bn=class{blockLen;outputLen;canXOF=!1;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(e,r,n,s){this.blockLen=e,this.outputLen=r,this.padOffset=n,this.isLE=s,this.buffer=new Uint8Array(e),this.view=In(this.buffer)}update(e){Xt(this),Qe(e);let{view:r,buffer:n,blockLen:s}=this,o=e.length,c=!1;for(let i=0;i<o;){let a=Math.min(s-this.pos,o-i);if(a===s){let u=In(e);for(;s<=o-i;i+=s)this.process(u,i);c=!0;continue}n.set(i===0&&a===o?e:e.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===s&&(this.process(r,0),this.pos=0,c=!0)}return this.length+=e.length,c&&this.roundClean(),this}digestInto(e){Xt(this),Dn(e,this),this.finished=!0;let{buffer:r,view:n,blockLen:s,isLE:o}=this,{pos:c}=this;r[c++]=128,r.fill(0,c),this.padOffset>s-c&&(this.process(n,0),r.fill(0)),$c(n,s-8,this.length*8,o),this.process(n,0),this.roundClean();let i=e===r?n:In(e),a=this.outputLen,u=a/4,l=this.get();if(a%4||u>l.length)throw new Error("invalid outputLen");for(let f=0;f<u;f++)i.setUint32(4*f,l[f],o)}digest(){let{buffer:e,outputLen:r}=this;this.digestInto(e);let n=e.slice(0,r);return this.destroy(),n}_cloneIntoMeta(e){let{buffer:r,length:n,finished:s,destroyed:o,pos:c}=this;return e.destroyed=o,e.finished=s,e.length=n,e.pos=c,c&&e.buffer.set(r),e}clone(){return this._cloneInto()}},Xc=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var Nf=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),bt=new Uint32Array(64),Bi=class extends Bn{A=0;B=0;C=0;D=0;E=0;F=0;G=0;H=0;constructor(e,r){super(64,e,8,!1),this.A=r[0]|0,this.B=r[1]|0,this.C=r[2]|0,this.D=r[3]|0,this.E=r[4]|0,this.F=r[5]|0,this.G=r[6]|0,this.H=r[7]|0}get(){let{A:e,B:r,C:n,D:s,E:o,F:c,G:i,H:a}=this;return[e,r,n,s,o,c,i,a]}set(e,r,n,s,o,c,i,a){this.A=e|0,this.B=r|0,this.C=n|0,this.D=s|0,this.E=o|0,this.F=c|0,this.G=i|0,this.H=a|0}_cloneInto(e){return(e||=new this.constructor).set(...this.get()),this._cloneIntoMeta(e)}process(e,r){for(let f=0;f<16;f++,r+=4)bt[f]=e.getUint32(r,!1);for(let f=16;f<64;f++){let d=bt[f-15],p=bt[f-2],E=Ze(d,7)^Ze(d,18)^d>>>3,D=Ze(p,17)^Ze(p,19)^p>>>10;bt[f]=D+bt[f-7]+E+bt[f-16]|0}let{A:n,B:s,C:o,D:c,E:i,F:a,G:u,H:l}=this;for(let f=0;f<64;f++){let d=Ze(i,6)^Ze(i,11)^Ze(i,25),p=l+d+Zc(i,a,u)+Nf[f]+bt[f]|0,D=(Ze(n,2)^Ze(n,13)^Ze(n,22))+jc(n,s,o)|0;l=u,u=a,a=i,i=c+p|0,c=o,o=s,s=n,n=p+D|0}n=n+this.A|0,s=s+this.B|0,o=o+this.C|0,c=c+this.D|0,i=i+this.E|0,a=a+this.F|0,u=u+this.G|0,l=l+this.H|0,this.set(n,s,o,c,i,a,u,l)}roundClean(){Ur(bt)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),Ur(this.buffer)}},Li=class extends Bi{constructor(){super(32,Xc)}};var Qc=Wc(()=>new Li,qc(1));function On(t,e,r=()=>{}){if(!Array.isArray(t))throw new TypeError(`"${e}" expected array, got type=${typeof t}`);for(let n=0;n<t.length;n++)r(t[n],`${e}[${n}]`);return t}var de=(t,e,r)=>Qe(t,e,r),Oi=nt;function ea(t,e=""){if(typeof t!="string"){let r=e&&`"${e}" `;throw new TypeError(r+"expected string, got type="+typeof t)}return t}function gt(t,e="object"){if(t===null||typeof t!="object"||Array.isArray(t))throw new TypeError(e==="object"?"expected valid options object":`"${e}" expected object, got type=${typeof t}`);return t}function Lt(t,e){if(typeof t!="function")throw new TypeError(`"${e}" is invalid: expected function, got ${typeof t}`);return t}var ki=Cn,ot=(...t)=>Gc(...t),kn=t=>Ci(t),Qt=Tn,_n=t=>Yc(t),Ln=BigInt(0),Jc=BigInt(1),Uf=t=>t?`"${t}" `:"";function Je(t,e=""){if(typeof t!="boolean")throw new TypeError(Uf(e)+"expected boolean, got type="+typeof t);return t}function Pn(t){if(typeof t=="bigint"){if(!wt(t))throw new RangeError("positive bigint expected, got "+t)}else Oi(t);return t}function Ot(t,e=""){if(typeof t!="number"){let r=e&&`"${e}" `;throw new TypeError(r+"expected number, got type="+typeof t)}if(!Number.isSafeInteger(t)){let r=e&&`"${e}" `;throw new RangeError(r+"expected safe integer, got "+t)}}function Fr(t){let e=Pn(t).toString(16);return e.length&1?"0"+e:e}function ta(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);return t===""?Ln:BigInt("0x"+t)}function et(t){return ta(Cn(t))}function _i(t){return ta(Cn(Ff(Qe(t)).reverse()))}function Rn(t,e){if(nt(e),e===0)throw new Error("zero output length is invalid");t=Pn(t);let r=e*2,n=t.toString(16);if(n.length>r)throw new RangeError("number is too large");return Ci(n.padStart(r,"0"))}function Pi(t,e){return Rn(t,e).reverse()}function Ff(t){return Uint8Array.from(de(t))}function wt(t){return typeof t=="bigint"&&Ln<=t}function Ri(t,e,r){return wt(t)&&wt(e)&&wt(r)&&e<=t&&t<r}function Ni(t,e,r,n){if(!Ri(e,r,n))throw new RangeError("expected valid "+t+": "+r+" <= n < "+n+", got "+e)}function Jt(t){if(t<Ln)throw new Error("expected non-negative bigint, got "+t);return t===Ln?0:t.toString(2).length}var Mr=t=>(Ot(t,"n"),(Jc<<BigInt(t))-Jc);function ra(t,e,r){if(nt(t,"hashLen"),nt(e,"qByteLen"),typeof r!="function")throw new TypeError("hmacFn must be a function");let n=b=>new Uint8Array(b),s=Uint8Array.of(),o=Uint8Array.of(0),c=Uint8Array.of(1),i=1e3,a=n(t),u=n(t),l=0,f=()=>{a.fill(1),u.fill(0),l=0},d=(...b)=>r(u,ot(a,...b)),p=(b=s)=>{u=d(o,b),a=d(),b.length!==0&&(u=d(c,b),a=d())},E=()=>{if(l++>=i)throw new Error("drbg: tried max amount of iterations");let b=0,y=[];for(;b<e;){a=d();let T=a.slice();y.push(T),b+=a.length}return ot(...y)};return(b,y)=>{f(),p(b);let T;for(;(T=y(E()))===void 0;)p();return f(),T}}function xt(t,e={},r={},n="object"){gt(t,n),gt(e,"fields"),gt(r,"optFields");function s(c,i,a){let u=n==="object"?`param "${String(c)}"`:`"${n}.${String(c)}"`,l=t[c];if(!Object.hasOwn(t,c)&&(a?l!==void 0:i!=="function"))throw new TypeError(`${u} is invalid: expected own property`);if(a&&l===void 0)return;let f=typeof l;if(f!==i||l===null)throw new TypeError(`${u} is invalid: expected ${i}, got ${f}`)}let o=(c,i)=>Object.entries(c).forEach(([a,u])=>s(a,u,i));o(e,!1),o(r,!0)}var he=BigInt(0),K=BigInt(1),Et=BigInt(2),sa=BigInt(3),Ui=BigInt(4),ca=BigInt(5),Mf=BigInt(7),aa=BigInt(8),Kf=BigInt(9),$f=BigInt(15),ua=BigInt(16),Hf=BigInt("0x10000000000000000");function Re(t,e){if(e<=he)throw new Error("mod: expected positive modulus, got "+e);let r=t%e;return r>=he?r:e+r}function la(t,e,r){if(r<=K)throw new Error("pow: expected modulus > 1, got "+r);if(typeof e!="bigint")throw new TypeError("invalid exponent: expected bigint, got "+typeof e);if(e<he)throw new Error("invalid exponent, negatives unsupported");if(e===he)return K;if(e===K)return t;let n=t%r;if(n<he&&(n+=r),e<Hf){let i=K;for(;e>he;)e&K&&(i=i*n%r),n=n*n%r,e>>=K;return i}let s=[];for(;e>he;)s.push(Number(e&$f)),e>>=Ui;let o=new Array(16);o[0]=K,o[1]=n;for(let i=2;i<16;i++)o[i]=o[i-1]*n%r;let c=o[s[s.length-1]];for(let i=s.length-2;i>=0;i--){c=c*c%r,c=c*c%r,c=c*c%r,c=c*c%r;let a=s[i];a!==0&&(c=c*o[a]%r)}return c}function Ne(t,e,r){if(r<=K)throw new Error("pow2: expected modulus > 1, got "+r);if(e<he)throw new Error("pow2: expected non-negative exponent, got "+e);let n=t;for(;e-- >he;)n*=n,n%=r;return n}function na(t,e){if(t===he)throw new Error("invert: expected non-zero number");if(e<=K)throw new Error("invert: expected modulus > 1, got "+e);let r=Re(t,e),n=e,s=he,o=K;for(;r!==he;){let i=n/r,a=n-r*i,u=s-o*i;n=r,r=a,s=o,o=u}if(n!==K)throw new Error("invert: does not exist");return Re(s,e)}function fa(t,e){if(e<=K)throw new Error("invertCt: expected prime modulus > 1, got "+e);let r=Re(t,e);if(r===he)throw new Error("invertCt: expected non-zero number");let n=la(r,e-Et,e);if(Re(r*n,e)!==K)throw new Error("invertCt: does not exist");return n}function Fi(t,e,r){let n=t;if(!n.eql(n.sqr(e),r))throw new Error("Cannot find square root")}function Mi(t,e){if((t&K)===he)throw new Error(e+": expected odd modulus, got "+t)}function da(t,e){let r=t,n=(r.ORDER+K)/Ui,s=r.pow(e,n);return Fi(r,s,e),s}function zf(t,e){let r=t,n=(r.ORDER-ca)/aa,s=r.mul(e,Et),o=r.pow(s,n),c=r.mul(e,o),i=r.mul(r.mul(c,Et),o),a=r.mul(c,r.sub(i,r.ONE));return Fi(r,a,e),a}function Vf(t){let e=tr(t),r=ha(t),n=r(e,e.neg(e.ONE)),s=r(e,n),o=r(e,e.neg(n)),c=(t+Mf)/ua;return((i,a)=>{let u=i,l=u.pow(a,c),f=u.mul(l,n),d=u.mul(l,s),p=u.mul(l,o),E=u.eql(u.sqr(f),a),D=u.eql(u.sqr(d),a);l=u.cmov(l,f,E),f=u.cmov(p,d,D);let b=u.eql(u.sqr(f),a),y=u.cmov(l,f,b);return Fi(u,y,a),y})}function ha(t){if(t<sa)throw new Error("sqrt is not defined for small field");Mi(t,"tonelliShanks");let e=t-K,r=0;for(;e%Et===he;)e/=Et,r++;let n=Et,s=tr(t);for(;oa(s,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return da;let o=s.pow(n,e),c=(e+K)/Et;return function(a,u){let l=a;if(l.is0(u))return u;if(oa(l,u)!==1)throw new Error("Cannot find square root");let f=r,d=l.mul(l.ONE,o),p=l.pow(u,e),E=l.pow(u,c);for(;!l.eql(p,l.ONE);){if(l.is0(p))throw new Error("Cannot find square root: probably non-prime P");let D=1,b=l.sqr(p);for(;!l.eql(b,l.ONE);)if(D++,b=l.sqr(b),D===f)throw new Error("Cannot find square root");let y=K<<BigInt(f-D-1),T=l.pow(d,y);f=D,d=l.sqr(T),p=l.mul(p,d),E=l.mul(E,T)}return E}}function Gf(t){return Mi(t,"Fp.sqrt"),t%Ui===sa?da:t%aa===ca?zf:t%ua===Kf?Vf(t):ha(t)}var Wf=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function er(t){if(gt(t,"field"),typeof t.ORDER!="bigint")throw new TypeError('param "ORDER" is invalid: expected bigint, got '+typeof t.ORDER);Ot(t.BYTES,"BYTES"),Ot(t.BITS,"BITS");for(let e of Wf)Lt(t[e],"field."+e);if(t.BYTES<1||t.BITS<1)throw new Error("invalid field: expected BYTES/BITS > 0");if(t.ORDER<=K)throw new Error("invalid field: expected ORDER > 1, got "+t.ORDER);return t}function Ki(t,e,r=!1){er(t),On(e,"nums"),Je(r,"passZero");let n=t,s=new Array(e.length).fill(r?n.ZERO:void 0),o=e.reduce((i,a,u)=>n.is0(a)?i:(s[u]=i,n.mul(i,a)),n.ONE),c=n.inv(o);return e.reduceRight((i,a,u)=>n.is0(a)?i:(s[u]=n.mul(i,s[u]),n.mul(i,a)),c),s}function oa(t,e){er(t);let r=t;Mi(r.ORDER,"FpLegendre");let n=(r.ORDER-K)/Et,s=r.pow(e,n),o=r.eql(s,r.ONE),c=r.eql(s,r.ZERO),i=r.eql(s,r.neg(r.ONE));if(!o&&!c&&!i)throw new Error("invalid Legendre symbol result");return o?1:c?0:-1}function Yf(t,e){if(e!==void 0&&Oi(e),t<=he)throw new Error("invalid n length: expected positive n, got "+t);if(e!==void 0&&e<1)throw new Error("invalid n length: expected positive bit length, got "+e);let r=Jt(t);if(e!==void 0&&e<r)throw new Error(`invalid n length: expected nBitLength (${e}) >= bitLen(n) (${r})`);let n=e!==void 0?e:r,s=Math.ceil(n/8);return{nBitLength:n,nByteLength:s}}var ia=new WeakMap,Nn=class{ORDER;BITS;BYTES;isLE;ZERO=he;ONE=K;_lengths;_mod;constructor(e,r={}){if(e<=K)throw new Error("invalid field: expected ORDER > 1, got "+e);let n;this.isLE=!1,r!=null&&typeof r=="object"&&(typeof r.BITS=="number"&&(n=r.BITS),typeof r.sqrt=="function"&&Object.defineProperty(this,"sqrt",{value:r.sqrt,enumerable:!0}),typeof r.isLE=="boolean"&&(this.isLE=r.isLE),r.allowedLengths&&(this._lengths=Object.freeze(r.allowedLengths.slice())),typeof r.modFromBytes=="boolean"&&(this._mod=r.modFromBytes));let{nBitLength:s,nByteLength:o}=Yf(e,n);if(o>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=e,this.BITS=s,this.BYTES=o,Object.freeze(this)}create(e){return Re(e,this.ORDER)}isValid(e){if(typeof e!="bigint")throw new TypeError("invalid field element: expected bigint, got "+typeof e);return he<=e&&e<this.ORDER}is0(e){return e===he}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}isOdd(e){return(e&K)===K}neg(e){return Re(-e,this.ORDER)}eql(e,r){return e===r}sqr(e){return Re(e*e,this.ORDER)}add(e,r){return Re(e+r,this.ORDER)}sub(e,r){return Re(e-r,this.ORDER)}mul(e,r){return Re(e*r,this.ORDER)}pow(e,r){return la(e,r,this.ORDER)}div(e,r){return Re(e*na(r,this.ORDER),this.ORDER)}sqrN(e){return e*e}addN(e,r){return e+r}subN(e,r){return e-r}mulN(e,r){return e*r}inv(e){return na(e,this.ORDER)}sqrt(e){let r=ia.get(this);return r||ia.set(this,r=Gf(this.ORDER)),r(this,e)}toBytes(e){return this.isLE?Pi(e,this.BYTES):Rn(e,this.BYTES)}fromBytes(e,r=!1){de(e);let{_lengths:n,BYTES:s,isLE:o,ORDER:c,_mod:i}=this;if(n){if(e.length<1||!n.includes(e.length)||e.length>s)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+e.length);let u=new Uint8Array(s);u.set(e,o?0:u.length-e.length),e=u}if(e.length!==s)throw new Error("Field.fromBytes: expected "+s+" bytes, got "+e.length);let a=o?_i(e):et(e);if(i&&(a=Re(a,c)),!r&&!this.isValid(a))throw new Error("invalid field element: outside of range 0..ORDER");return a}invertBatch(e){return Ki(this,e,!0)}cmov(e,r,n){return Je(n,"condition"),n?r:e}};function tr(t,e={}){return Object.freeze(Nn.prototype),new Nn(t,e)}function pa(t){if(typeof t!="bigint")throw new Error("field order must be bigint");if(t<=K)throw new Error("field order must be greater than 1");let e=Jt(t-K);return Math.ceil(e/8)}function Un(t){let e=pa(t);return e+Math.ceil(e/2)}function Fn(t,e,r=!1){de(t);let n=t.length,s=pa(e),o=Math.max(Un(e),16);if(n<o||n>1024)throw new Error("expected "+o+"-1024 bytes of input, got "+n);let c=r?_i(t):et(t),i=Re(c,e-K)+K;return r?Pi(i,s):Rn(i,s)}var zi=BigInt(0),Kr=BigInt(1),qf=BigInt(4),$i=16,ma=128,Zf=5,ya=2**31;function rr(t){let e=t;if(typeof e!="function")throw new TypeError('"Point" expected constructor, got type='+typeof t);Lt(e.fromAffine,"Point.fromAffine"),Lt(e.fromBytes,"Point.fromBytes"),Lt(e.fromHex,"Point.fromHex"),gt(e.BASE,"Point.BASE"),gt(e.ZERO,"Point.ZERO"),er(e.Fp),er(e.Fn)}function ga(t,e){rr(t),wa(e,t);let r=Ki(t.Fp,e.map(n=>n.Z));return e.map((n,s)=>t.fromAffine(n.toAffine(r[s])))}function jf(t,e,r=1){if(!Number.isSafeInteger(t)||t<r||t>e)throw new Error("invalid window size, expected ["+r+".."+e+"], got W="+t)}function Xf(t,e){let r=t*(4*e+128);if(r>ya)throw new Error("invalid window size: table would need ~"+Math.ceil(r/2**20)+" MiB, max "+ya/2**20+" MiB")}function Vi(t,e){if(t!==void 0){Lt(t,"randomBytes");try{let r=t(e);if(!Qt(r)||r.length!==e)return}catch{return}return t}}function wa(t,e){On(t,"points"),t.forEach((r,n)=>{if(!(r instanceof e))throw new Error("invalid point at index "+n)})}function Qf(t,e,r){if(!Array.isArray(t))throw new Error("array of scalars expected");t.forEach((n,s)=>{if(!(r===void 0?e.isValid(n):wt(n)&&n<r))throw new Error("invalid scalar at index "+s)})}var xa=new WeakMap;function Hi(t){return xa.get(t)||1}function Jf(t,e){let r=t.double(),n=[t];for(let s=1;s<e;s++)n.push(n[s-1].add(r));return n}function ed(t,e){let r=2**e,n=r/2,s=BigInt(r-1),o=[];for(;t>zi;){let c=0;t&Kr&&(c=Number(t&s),c>=n&&(c-=r),t-=BigInt(c)),o.push(c),t>>=Kr}return o}function td(t,e,r){let n=2**e,s=n/2,o=BigInt(n-1),c=BigInt(e),i=[];for(let a=0;a<r;a++){let u=Number(t&o);t>>=c,u>s&&(u-=n,t+=Kr),i.push(u)}if(t!==zi)throw new Error("invalid wnaf");return i}function rd(t,e,r){let n=0;for(let o of r)n=Math.max(n,o.length);let s=t;for(let o=n-1;o>=0;o--){o!==n-1&&(s=s.double());for(let c=0;c<r.length;c++){let i=r[c][o];if(i){let a=e[c][Math.abs(i)-1>>1];s=s.add(i<0?a.negate():a)}}}return s}var Mn=class{Point;BASE;ZERO;randomBytes;wnafPrecomputes=new WeakMap;baseCanBeBlinded;bits;constructor(e,r){rr(e),this.randomBytes=Vi(r,$i),this.Point=e,this.BASE=e.BASE,this.ZERO=e.ZERO,this.bits=e.Fn.BITS}buildWnafTable(e,r,n){let s=Math.ceil(n/r)+1,o=2**(r-1),c=[],i=e;for(let a=0;a<s;a++){let u=i;for(let l=0;l<o;l++)c.push(u),u=u.add(i);i=c[c.length-1].double()}return{W:r,bits:n,windows:s,comp:c}}wnafCachedCT(e,r){let{W:n,windows:s,comp:o}=e,c=2**(n-1),i=td(r,n,s),a=this.ZERO,u=this.BASE;for(let l=0;l<s;l++){let f=i[l],d=l*c,p=Math.abs(f)-1,E=o[d];for(let b=1;b<c;b++)E=b===p?o[d+b]:E;let D=E.negate();f===0?u=u.add(o[d]):a=a.add(f<0?D:E)}return{p:a,f:u}}getWnafPrecomputes(e,r,n,s){let o=this.wnafPrecomputes.get(r),c=o?.find(i=>i.W===e&&i.bits===n);return c||(c=this.buildWnafTable(r,e,n),typeof s=="function"&&(c={...c,comp:s(c.comp)}),o||(o=[],this.wnafPrecomputes.set(r,o)),o.push(c)),c}assertPoint(e){if(!(e instanceof this.Point))throw new TypeError('"point" expected Point instance, got type='+typeof e)}validateMulInput(e,r){if(this.assertPoint(e),!Ri(r,Kr,this.Point.Fn.ORDER))throw new Error("invalid scalar")}runCT(e,r,n,s){let o=Hi(e);return o===1?this.fixedWindowCT(e,r,n):this.wnafCachedCT(this.getWnafPrecomputes(o,e,n,s),r)}mulCT(e,r,n){return this.validateMulInput(e,r),this.runCT(e,r,this.bits,n)}mulCTBlinded(e,r,n){if(this.validateMulInput(e,r),this.randomBytes===void 0)throw new Error("randomBytes is required for scalar blinding");let s=this.Point.Fn.BITS+ma,o=this.randomBytes($i);if(!Qt(o)||o.length!==$i)throw new Error("randomBytes returned invalid byte array");o[0]=o[0]&63|128;let c=r+et(o)*this.Point.Fn.ORDER;return this.runCT(e,c,s,n)}fixedWindowCT(e,r,n){let s=Zf,o=1<<s,c=Mr(s),i=new Array(o);i[0]=this.ZERO;for(let l=1;l<o;l++)i[l]=i[l-1].add(e);let a=Math.ceil(n/s),u=this.ZERO;for(let l=a-1;l>=0;l--){if(l!==a-1)for(let p=0;p<s;p++)u=u.double();let f=Number(r>>BigInt(l*s)&c),d=i[0];for(let p=1;p<o;p++)d=p===f?i[p]:d;u=u.add(d)}return{p:u,f:u}}shouldBlind(e,r){return this.randomBytes===void 0?!1:r===Kr?!0:e!==this.BASE?!1:(this.baseCanBeBlinded===void 0&&(this.baseCanBeBlinded=this.mulUnsafe(this.BASE,this.Point.Fn.ORDER).is0()),this.baseCanBeBlinded)}mulSecret(e,r,n,s){return this.shouldBlind(e,n)?this.mulCTBlinded(e,r,s):this.mulCT(e,r,s)}mulUnsafe(e,r,n){if(this.assertPoint(e),!wt(r))throw new Error("invalid scalar");let s=Hi(e);if(s===1||r>=this.Point.Fn.ORDER)return Kn(this.Point,[e],[r],!0);let o=this.getWnafPrecomputes(s,e,this.bits,n);return this.wnafCachedCT(o,r).p}setWindowSize(e,r){this.assertPoint(e),jf(r,this.bits);let n=Math.ceil((this.bits+ma)/r)+1;Xf(n*2**(r-1),this.Point.Fp.BYTES),xa.set(e,r),this.wnafPrecomputes.delete(e)}hasWindowSize(e){return Hi(e)!==1}};function Kn(t,e,r,n=!1){if(rr(t),wa(e,t),Je(n,"allowOversized"),Qf(r,t.Fn,n?t.Fn.ORDER**qf:void 0),e.length!==r.length)throw new Error("arrays of points and scalars must have equal length");let s=e.map(c=>Jf(c,4)),o=r.map(c=>ed(c,4));return rd(t.ZERO,s,o)}function ba(t,e,r){if(e){if(e.ORDER!==t)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return er(e),e}else return tr(t,{isLE:r})}function Ea(t,e,r={},n){if(t!=="weierstrass"&&t!=="edwards")throw new Error('expected curve type "weierstrass" or "edwards"');if(n===void 0&&(n=t==="edwards"),!e||typeof e!="object")throw new Error(`expected valid ${t} CURVE object`);xt(r);for(let a of["p","n","h"]){let u=e[a];if(!(wt(u)&&u!==zi))throw new Error(`CURVE.${a} must be positive bigint`)}let s=ba(e.p,r.Fp,n),o=ba(e.n,r.Fn,n),i=["Gx","Gy","a",t==="weierstrass"?"b":"d"];for(let a of i)if(!s.isValid(e[a]))throw new Error(`CURVE.${a} must be valid field element of CURVE.Fp`);return e=Object.freeze(Object.assign({},e)),{CURVE:e,Fp:s,Fn:o}}function va(t,e){return function(n){let s=t(n);return{secretKey:s,publicKey:e(s)}}}var Xy=$n.default.generateKeyPairSync,$r=32;var nd=64;function Sa(t,e,r){if(t.byteLength!==$r)throw new TypeError('"key" must be 32 bytes in length.');if(!(t instanceof Uint8Array))throw new TypeError('"key" must be a node.js Buffer, or Uint8Array.');if(e.byteLength!==nd)throw new TypeError('"sig" must be 64 bytes in length.');if(!(e instanceof Uint8Array))throw new TypeError('"sig" must be a node.js Buffer, or Uint8Array.');let n=$n.default.createPublicKey({format:"jwk",key:{crv:"Ed25519",x:ae(t,"base64url"),kty:"OKP"}});return $n.default.verify(null,r instanceof Uint8Array?r:r.subarray(),n,e)}function Aa(t){return t==null?!1:typeof t.then=="function"&&typeof t.catch=="function"&&typeof t.finally=="function"}var Hn=class{type="Ed25519";raw;constructor(e){this.raw=Gi(e,$r)}toMultihash(){return Ge.digest(jt(this))}toCID(){return fe.createV1(114,this.toMultihash())}toString(){return ce.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Ae(this.raw,e.raw)}verify(e,r,n){n?.signal?.throwIfAborted();let s=Sa(this.raw,r,e);return Aa(s)?s.then(o=>(n?.signal?.throwIfAborted(),o)):s}};function Da(t){return t=Gi(t,$r),new Hn(t)}function Gi(t,e){if(t=Uint8Array.from(t??[]),t.length!==e)throw new B(`Key must be a Uint8Array of length ${e}, got ${t.length}`);return t}var De;(function(t){t.RSA="RSA",t.Ed25519="Ed25519",t.secp256k1="secp256k1",t.ECDSA="ECDSA"})(De||(De={}));var Wi;(function(t){t[t.RSA=0]="RSA",t[t.Ed25519=1]="Ed25519",t[t.secp256k1=2]="secp256k1",t[t.ECDSA=3]="ECDSA"})(Wi||(Wi={}));(function(t){t.codec=()=>We(Wi)})(De||(De={}));var Hr;(function(t){let e;t.codec=()=>(e==null&&(e=re((o,c,i={})=>{i.lengthDelimited!==!1&&c.fork(),o.Type!=null&&(c.uint32(8),De.codec().encode(o.Type,c)),o.Data!=null&&(c.uint32(18),c.bytes(o.Data)),i.lengthDelimited!==!1&&c.ldelim()},(o,c,i={})=>{let a={},u=c==null?o.len:o.pos+c;for(;o.pos<u;){let l=o.uint32();switch(l>>>3){case 1:{a.Type=De.codec().decode(o);break}case 2:{a.Data=o.bytes();break}default:{o.skipType(l&7);break}}}return a},function*(o,c,i,a={}){let u=c==null?o.len:o.pos+c;for(;o.pos<u;){let l=o.uint32();switch(l>>>3){case 1:{yield{field:`${i}.Type`,value:De.codec().decode(o)};break}case 2:{yield{field:`${i}.Data`,value:o.bytes()};break}default:{o.skipType(l&7);break}}}})),e);function r(o){return ee(o,t.codec())}t.encode=r;function n(o,c){return J(o,t.codec(),c)}t.decode=n;function s(o,c){return te(o,t.codec(),c)}t.stream=s})(Hr||(Hr={}));var Yi;(function(t){let e;t.codec=()=>(e==null&&(e=re((o,c,i={})=>{i.lengthDelimited!==!1&&c.fork(),o.Type!=null&&(c.uint32(8),De.codec().encode(o.Type,c)),o.Data!=null&&(c.uint32(18),c.bytes(o.Data)),i.lengthDelimited!==!1&&c.ldelim()},(o,c,i={})=>{let a={},u=c==null?o.len:o.pos+c;for(;o.pos<u;){let l=o.uint32();switch(l>>>3){case 1:{a.Type=De.codec().decode(o);break}case 2:{a.Data=o.bytes();break}default:{o.skipType(l&7);break}}}return a},function*(o,c,i,a={}){let u=c==null?o.len:o.pos+c;for(;o.pos<u;){let l=o.uint32();switch(l>>>3){case 1:{yield{field:`${i}.Type`,value:De.codec().decode(o)};break}case 2:{yield{field:`${i}.Data`,value:o.bytes()};break}default:{o.skipType(l&7);break}}}})),e);function r(o){return ee(o,t.codec())}t.encode=r;function n(o,c){return J(o,t.codec(),c)}t.decode=n;function s(o,c){return te(o,t.codec(),c)}t.stream=s})(Yi||(Yi={}));var Ra=ke(ue("node:crypto"),1);var zn=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(e,r){if(An(e),Qe(r,void 0,"key"),this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("expected Hash instance");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,s=new Uint8Array(n);s.set(r.length>n?e.create().update(r).digest():r);for(let o=0;o<s.length;o++)s[o]^=54;this.iHash.update(s),this.oHash=e.create();for(let o=0;o<s.length;o++)s[o]^=106;this.oHash.update(s),Ur(s)}update(e){return Xt(this),this.iHash.update(e),this}digestInto(e){Xt(this),Dn(e,this),this.finished=!0;let r=e.subarray(0,this.outputLen);this.iHash.digestInto(r),this.oHash.update(r),this.oHash.digestInto(r),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||=Object.create(Object.getPrototypeOf(this),{});let{oHash:r,iHash:n,finished:s,destroyed:o,blockLen:c,outputLen:i,canXOF:a}=this;return e=e,e.finished=s,e.destroyed=o,e.blockLen=c,e.outputLen=i,e.canXOF=a,e.oHash=r._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Ia=(()=>{let t=((e,r,n)=>new zn(e,r).update(n).digest());return t.create=(e,r)=>new zn(e,r),t})();var sd=BigInt(0),qi=class extends Error{constructor(e=""){super(e)}},it={Err:qi,_tlv:{encode:(t,e)=>{let{Err:r}=it;if(Ot(t,"tag"),t<0||t>255)throw new r("tlv.encode: wrong tag");if(ea(e,"data"),e.length&1)throw new r("tlv.encode: unpadded data");let n=e.length/2,s=Fr(n);if(s.length/2&128)throw new r("tlv.encode: long form length too big");let o=n>127?Fr(s.length/2|128):"";return Fr(t)+o+s+e},decode(t,e){let{Err:r}=it;e=de(e,void 0,"DER data");let n=0;if(t<0||t>255)throw new r("tlv.decode: wrong tag");if(e.length<2||e[n++]!==t)throw new r("tlv.decode: wrong tlv");let s=e[n++],o=!!(s&128),c=0;if(!o)c=s;else{let a=s&127;if(!a)throw new r("tlv.decode(long): indefinite length not supported");if(a>4)throw new r("tlv.decode(long): byte length is too big");let u=e.subarray(n,n+a);if(u.length!==a)throw new r("tlv.decode: length bytes not complete");if(u[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let l of u)c=c<<8|l;if(n+=a,c<128)throw new r("tlv.decode(long): not minimal encoding")}let i=e.subarray(n,n+c);if(i.length!==c)throw new r("tlv.decode: wrong value length");return{v:i,l:e.subarray(n+c)}}},_int:{encode(t){let{Err:e}=it;if(Pn(t),t<sd)throw new e("integer: negative integers are not allowed");let r=Fr(t);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new e("unexpected DER parsing assertion: unpadded hex");return r},decode(t){let{Err:e}=it;if(t.length<1)throw new e("invalid signature integer: empty");if(t[0]&128)throw new e("invalid signature integer: negative");if(t.length>1&&t[0]===0&&!(t[1]&128))throw new e("invalid signature integer: unnecessary leading zero");return et(t)}},toSig(t,e){let{Err:r,_int:n,_tlv:s}=it;if(e!==void 0&&(Ot(e,"maxScalarBytes"),e<1))throw new r("invalid signature: maxScalarBytes must be positive");let o=de(t,void 0,"signature"),{v:c,l:i}=s.decode(48,o);if(i.length)throw new r("invalid signature: left bytes after parsing");let{v:a,l:u}=s.decode(2,c),{v:l,l:f}=s.decode(2,u);if(f.length)throw new r("invalid signature: left bytes after parsing");if(e!==void 0&&(a.length>e||l.length>e))throw new r("invalid signature: integer too large");return{r:n.decode(a),s:n.decode(l)}},hexFromSig(t){let{_tlv:e,_int:r}=it;xt(t,{r:"bigint",s:"bigint"},{},"sig");let n=e.encode(2,r.encode(t.r)),s=e.encode(2,r.encode(t.s)),o=n+s;return e.encode(48,o)}},Vn=(Object.freeze(it._tlv),Object.freeze(it._int),Object.freeze(it));var Ca=(t,e)=>(t+(t>=0?e:-e)/Ba)/e;function cd(t,e,r){Ni("scalar",t,st,r);let[[n,s],[o,c]]=e,i=Ca(c*t,r),a=Ca(-s*t,r),u=t-i*n-a*o,l=-i*s-a*c,f=u<st,d=l<st;f&&(u=-u),d&&(l=-l);let p=Mr(Math.ceil(Jt(r)/2))+kt;if(u<st||u>=p||l<st||l>=p)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:f,k1:u,k2neg:d,k2:l}}function Xi(t){if(!["compact","recovered","der"].includes(t))throw new Error('Signature format must be "compact", "recovered", or "der"');return t}function Zi(t,e){xt(t);let r={};for(let n of Object.keys(e))r[n]=t[n]===void 0?e[n]:t[n];return Je(r.lowS,"lowS"),Je(r.prehash,"prehash"),r.format!==void 0&&Xi(r.format),r}var st=BigInt(0),kt=BigInt(1),Ba=BigInt(2),ji=BigInt(3),ad=BigInt(4);function La(t,e={}){let r=Ea("weierstrass",t,e),n=r.Fp,s=r.Fn,o=r.CURVE,{h:c,n:i}=o;xt(e,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",randomBytes:"function"});let{endo:a,allowInfinityPoint:u,clearCofactor:l,isTorsionFree:f,fromBytes:d,toBytes:p}=e,E=e.randomBytes===void 0?_n:e.randomBytes;if(a&&(!n.is0(o.a)||typeof a.beta!="bigint"||!Array.isArray(a.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let D=a?{beta:a.beta,basises:a.basises.map(w=>[...w])}:void 0,b=ka(n,s);function y(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function T(w,h,m){if(h.is0()){if(!u)throw new Error("bad point: ZERO");return Uint8Array.of(0)}let{x:g,y:x}=h.toAffine(),v=n.toBytes(g);if(Je(m,"isCompressed"),m){y();let A=!n.isOdd(x);return ot(Oa(A),v)}else return ot(Uint8Array.of(4),v,n.toBytes(x))}function P(w){de(w,void 0,"Point");let{publicKey:h,publicKeyUncompressed:m}=b,g=w.length,x=w[0],v=w.subarray(1);if(u&&g===1&&x===0)return{x:n.ZERO,y:n.ZERO};if(g===h&&(x===2||x===3)){let A=n.fromBytes(v);if(!n.isValid(A))throw new Error("bad point: is not on curve, wrong x");let I=pe(A),C;try{C=n.sqrt(I)}catch(ie){let Z=ie instanceof Error?": "+ie.message:"";throw new Error("bad point: is not on curve, sqrt error"+Z)}y();let N=n.isOdd(C);return(x&1)===1!==N&&(C=n.neg(C)),{x:A,y:C}}else if(g===m&&x===4){let A=n.BYTES,I=n.fromBytes(v.subarray(0,A)),C=n.fromBytes(v.subarray(A,A*2));if(!me(I,C))throw new Error("bad point: is not on curve");return{x:I,y:C}}else throw new Error(`bad point: got length ${g}, expected compressed=${h} or uncompressed=${m}`)}let _=p===void 0?T:p,F=d===void 0?P:d,Q=n.mul(o.b,ji),G=n.is0(o.a)?w=>n.ZERO:w=>n.mul(o.a,w);function pe(w){let h=n.sqr(w),m=n.mul(h,w);return n.add(n.add(m,n.mul(w,o.a)),o.b)}function me(w,h){let m=n.sqr(h),g=pe(w);return n.eql(m,g)}if(!me(o.Gx,o.Gy))throw new Error("bad curve params: generator point");let H=n.mul(n.pow(o.a,ji),ad),Ie=n.mul(n.sqr(o.b),BigInt(27));if(n.is0(n.add(H,Ie)))throw new Error("bad curve params: a or b");function Me(w,h,m=!1){if(!n.isValid(h)||m&&n.is0(h))throw new Error(`bad point coordinate ${w}`);return typeof h=="object"&&h!==null?n.create(h):h}function Nt(w){if(!(w instanceof M))throw new Error("Weierstrass Point expected")}function jr(w){if(!D||!D.basises)throw new Error("no endo");return cd(w,D.basises,s.ORDER)}function St(w,h,m,g){if(!s.isValid(g))throw new RangeError("invalid scalar: out of range");if(D){let{k1neg:x,k1:v,k2neg:A,k2:I}=jr(g),C=new M(n.mul(m.X,D.beta),m.Y,m.Z);w.push(x?m.negate():m,A?C.negate():C),h.push(v,I)}else w.push(m),h.push(g)}let Xr=new WeakSet;class M{static BASE=new M(o.Gx,o.Gy,n.ONE);static ZERO=new M(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=s;X;Y;Z;constructor(h,m,g){this.X=Me("x",h),this.Y=Me("y",m,!0),this.Z=Me("z",g),Object.freeze(this)}static CURVE(){return o}static fromAffine(h){let{x:m,y:g}=h||{};if(!h||!n.isValid(m)||!n.isValid(g))throw new Error("invalid affine point");if(h instanceof M)throw new Error("projective point not allowed");return n.is0(m)&&n.is0(g)?M.ZERO:new M(m,g,n.ONE)}static fromBytes(h){let m=M.fromAffine(F(de(h,void 0,"point")));return m.assertValidity(),m}static fromHex(h){return M.fromBytes(kn(h))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(h=6,m=!0){return ft.setWindowSize(this,h),m||this.multiply(ji),this}assertValidity(){let h=this;if(h.is0()){if(u&&n.is0(h.X)&&n.eql(h.Y,n.ONE)&&n.is0(h.Z))return;throw new Error("bad point: ZERO")}if(Xr.has(h))return;let{x:m,y:g}=h.toAffine();if(!n.isValid(m)||!n.isValid(g))throw new Error("bad point: x or y not field elements");if(!me(m,g))throw new Error("bad point: equation left != right");if(!h.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");Xr.add(h)}hasEvenY(){let{y:h}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(h)}equals(h){Nt(h);let{X:m,Y:g,Z:x}=this,{X:v,Y:A,Z:I}=h,C=n.eql(n.mul(m,I),n.mul(v,x)),N=n.eql(n.mul(g,I),n.mul(A,x));return C&&N}negate(){return new M(this.X,n.neg(this.Y),this.Z)}double(){let{X:h,Y:m,Z:g}=this,x=n.ZERO,v=n.ZERO,A=n.ZERO,I=n.mul(h,h),C=n.mul(m,m),N=n.mul(g,g),k=n.mul(h,m);return k=n.add(k,k),A=n.mul(h,g),A=n.add(A,A),x=G(A),v=n.mul(Q,N),v=n.add(x,v),x=n.sub(C,v),v=n.add(C,v),v=n.mul(x,v),x=n.mul(k,x),A=n.mul(Q,A),N=G(N),k=n.sub(I,N),k=G(k),k=n.add(k,A),A=n.add(I,I),I=n.add(A,I),I=n.add(I,N),I=n.mul(I,k),v=n.add(v,I),N=n.mul(m,g),N=n.add(N,N),I=n.mul(N,k),x=n.sub(x,I),A=n.mul(N,C),A=n.add(A,A),A=n.add(A,A),new M(x,v,A)}add(h){Nt(h);let{X:m,Y:g,Z:x}=this,{X:v,Y:A,Z:I}=h,C=n.ZERO,N=n.ZERO,k=n.ZERO,ie=n.mul(m,v),Z=n.mul(g,A),ye=n.mul(x,I),Ke=n.add(m,g),j=n.add(v,A);Ke=n.mul(Ke,j),j=n.add(ie,Z),Ke=n.sub(Ke,j),j=n.add(m,x);let se=n.add(v,I);return j=n.mul(j,se),se=n.add(ie,ye),j=n.sub(j,se),se=n.add(g,x),C=n.add(A,I),se=n.mul(se,C),C=n.add(Z,ye),se=n.sub(se,C),k=G(j),C=n.mul(Q,ye),k=n.add(C,k),C=n.sub(Z,k),k=n.add(Z,k),N=n.mul(C,k),Z=n.add(ie,ie),Z=n.add(Z,ie),ye=G(ye),j=n.mul(Q,j),Z=n.add(Z,ye),ye=n.sub(ie,ye),ye=G(ye),j=n.add(j,ye),ie=n.mul(Z,j),N=n.add(N,ie),ie=n.mul(se,j),C=n.mul(Ke,C),C=n.sub(C,ie),ie=n.mul(Ke,Z),k=n.mul(se,k),k=n.add(k,ie),new M(C,N,k)}subtract(h){return Nt(h),this.add(h.negate())}is0(){return this.equals(M.ZERO)}multiply(h){if(!s.isValidNot0(h))throw new RangeError("invalid scalar: out of range");let{p:m,f:g}=ft.mulSecret(this,h,c,ur);return ur([m,g])[0]}multiplyUnsafe(h){let m=this,g=h;if(!s.isValid(g))throw new RangeError("invalid scalar: out of range");if(g===st||m.is0())return M.ZERO;if(g===kt)return m;if(ft.hasWindowSize(this))return ft.mulUnsafe(m,g,ur);let x=[],v=[];return St(x,v,m,g),Kn(M,x,v)}mulAddUnsafe(h,m,g){Nt(m);let x=[],v=[];return St(x,v,this,h),St(x,v,m,g),Kn(M,x,v)}toAffine(h){let m=this,g=h;if(g!=null&&!n.isValid(g))throw new RangeError('"invertedZ" expected valid field element');let{X:x,Y:v,Z:A}=m;if(n.eql(A,n.ONE))return{x,y:v};let I=m.is0();g==null&&(g=I?n.ONE:n.inv(A));let C=n.mul(x,g),N=n.mul(v,g),k=n.mul(A,g);if(I)return{x:n.ZERO,y:n.ZERO};if(!n.eql(k,n.ONE))throw new Error("invZ was invalid");return{x:C,y:N}}isTorsionFree(){return c===kt?!0:f?f(M,this):ft.mulUnsafe(this,i).is0()}clearCofactor(){return c===kt?this:l?l(M,this):this.multiplyUnsafe(c)}isSmallOrder(){return c===kt?this.is0():this.clearCofactor().is0()}toBytes(h=!0){return Je(h,"isCompressed"),this.assertValidity(),_(M,this,h)}toHex(h=!0){return ki(this.toBytes(h))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let ur=w=>ga(M,w),ft=new Mn(M,E);return ft.bits>=6&&M.BASE.precompute(6),Object.freeze(M.prototype),Object.freeze(M),M}function Oa(t){return Uint8Array.of(t?2:3)}function ka(t,e){return{secretKey:e.BYTES,publicKey:1+t.BYTES,publicKeyUncompressed:1+2*t.BYTES,publicKeyHasPrefix:!0,signature:2*e.BYTES}}function ud(t,e={}){rr(t);let{Fn:r}=t,n=e.randomBytes===void 0?_n:e.randomBytes,s=Object.assign(ka(t.Fp,r),{seed:Math.max(Un(r.ORDER),16)});function o(p){try{let E=r.fromBytes(p);return r.isValidNot0(E)}catch{return!1}}function c(p,E){let{publicKey:D,publicKeyUncompressed:b}=s;try{let y=p.length;return E===!0&&y!==D||E===!1&&y!==b?!1:!t.fromBytes(p).is0()}catch{return!1}}function i(p){return p=p===void 0?n(s.seed):p,Fn(de(p,s.seed,"seed"),r.ORDER)}function a(p,E=!0){return t.BASE.multiply(r.fromBytes(p)).toBytes(E)}function u(p){let{secretKey:E,publicKey:D,publicKeyUncompressed:b}=s,y=r._lengths;if(!Qt(p))return;let T=de(p,void 0,"key").length,P=T===D||T===b,_=T===E||!!y?.includes(T);if(!(P&&_))return P}function l(p,E,D=!0){if(u(p)===!0)throw new Error("first arg must be private key");if(u(E)===!1)throw new Error("second arg must be public key");let b=r.fromBytes(p),y=t.fromBytes(E);if(y.is0())throw new Error("invalid public key: point at infinity");return y.multiply(b).toBytes(D)}let f={isValidSecretKey:o,isValidPublicKey:c,randomSecretKey:i},d=va(i,a);return Object.freeze(f),Object.freeze(s),Object.freeze({getPublicKey:a,getSharedSecret:l,keygen:d,Point:t,utils:f,lengths:s})}function _a(t,e,r={}){rr(t);let n=e;An(n),xt(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let s=Object.assign({},r),o=s.randomBytes===void 0?_n:s.randomBytes,c=s.hmac===void 0?(w,h)=>Ia(n,w,h):s.hmac,{Fp:i,Fn:a}=t,{ORDER:u,BITS:l}=a,f=Un(u),d=Vi(o,f),{keygen:p,getPublicKey:E,getSharedSecret:D,utils:b,lengths:y}=ud(t,s),T={prehash:!0,lowS:typeof s.lowS=="boolean"?s.lowS:!0,format:"compact",extraEntropy:!1},P=u*Ba+kt<i.ORDER;function _(w){let h=u>>kt;return w>h}function F(w,h){if(!a.isValidNot0(h))throw new Error(`invalid signature ${w}: out of range 1..Point.Fn.ORDER`);return h}function Q(){if(!i.isOdd)throw new Error("Field doesn't support isOdd")}function G(w,h,m){return Q(),(w===m?0:2)|Number(i.isOdd(h))}function pe(){if(P)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function me(w,h){Xi(h);let m=y.signature,g=h==="compact"?m:h==="recovered"?m+1:void 0;return de(w,g)}class H{r;s;recovery;constructor(h,m,g){if(this.r=F("r",h),this.s=F("s",m),g!=null){if(pe(),![0,1,2,3].includes(g))throw new Error("invalid recovery id");this.recovery=g}Object.freeze(this)}static fromBytes(h,m=T.format){me(h,m);let g;if(m==="der"){if(h.length>2*a.BYTES+16)throw new Vn.Err("invalid signature: DER signature too long");let{r:I,s:C}=Vn.toSig(de(h),a.BYTES+1);return new H(I,C)}m==="recovered"&&(g=h[0],m="compact",h=h.subarray(1));let x=y.signature/2,v=h.subarray(0,x),A=h.subarray(x,x*2);return new H(a.fromBytes(v),a.fromBytes(A),g)}static fromHex(h,m){return this.fromBytes(kn(h),m)}assertRecovery(){let{recovery:h}=this;if(h==null)throw new Error("invalid recovery id: must be present");return h}addRecoveryBit(h){return new H(this.r,this.s,h)}recoverPublicKey(h){let{r:m,s:g}=this,x=this.assertRecovery(),v=x===2||x===3?m+u:m;if(!i.isValid(v))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let A=i.toBytes(v),I=t.fromBytes(ot(Oa((x&1)===0),A)),C=a.inv(v),N=Me(de(h,void 0,"msgHash")),k=a.create(-N*C),ie=a.create(g*C),Z=t.BASE.mulAddUnsafe(k,I,ie);if(Z.is0())throw new Error("invalid recovery: point at infinify");return Z.assertValidity(),Z}hasHighS(){return _(this.s)}toBytes(h=T.format){if(Xi(h),h==="der")return kn(Vn.hexFromSig(this));let{r:m,s:g}=this,x=a.toBytes(m),v=a.toBytes(g);return h==="recovered"?(pe(),ot(Uint8Array.of(this.assertRecovery()),x,v)):ot(x,v)}toHex(h){return ki(this.toBytes(h))}}Object.freeze(H.prototype),Object.freeze(H);let Ie=s.bits2int===void 0?function(h){if(h.length>8192)throw new Error("input is too large");let m=et(h),g=h.length*8-l;return g>0?m>>BigInt(g):m}:s.bits2int,Me=s.bits2int_modN===void 0?function(h){return a.create(Ie(h))}:s.bits2int_modN,Nt=Mr(l);function jr(w){return Ni("num < 2^"+l,w,st,Nt),a.toBytes(w)}function St(w,h){return de(w,void 0,"message"),h?de(n(w),void 0,"prehashed message"):w}function Xr(w,h,m){let{lowS:g,prehash:x,extraEntropy:v}=Zi(m,T);w=St(w,x);let A=Me(w),I=a.fromBytes(h);if(!a.isValidNot0(I))throw new Error("invalid private key");let C=[jr(I),jr(A)];if(v!=null&&v!==!1){let Z=v===!0?o(y.secretKey):v;C.push(de(Z,void 0,"extraEntropy"))}let N=ot(...C),k=A;function ie(Z){let ye=Ie(Z);if(!a.isValidNot0(ye))return;let Ke=t.BASE.multiply(ye).toAffine(),j=a.create(Ke.x);if(j===st)return;let se;if(d!==void 0){let lr=et(Fn(d(f),u)),wu=a.inv(a.mul(lr,ye)),xu=a.mul(lr,k),Eu=a.mul(lr,I);se=a.create(wu*a.create(xu+Eu*j))}else{let lr=fa(ye,u);se=a.create(lr*a.create(k+j*I))}if(se===st)return;let Lo=G(Ke.x,Ke.y,j),Rs=se;return g&&_(se)&&(Rs=a.neg(se),Lo^=1),new H(j,Rs,P?void 0:Lo)}return{seed:N,k2sig:ie}}function M(w,h,m={}){let{seed:g,k2sig:x}=Xr(w,h,m);return ra(n.outputLen,a.BYTES,c)(g,x).toBytes(m.format)}function ur(w,h,m,g={}){let{lowS:x,prehash:v,format:A}=Zi(g,T);if(m=de(m,void 0,"publicKey"),h=St(h,v),!Qt(w)){let I=w instanceof H?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+I)}me(w,A);try{let I=H.fromBytes(w,A),C=t.fromBytes(m);if(C.is0()||x&&I.hasHighS())return!1;let{r:N,s:k}=I,ie=Me(h),Z=a.inv(k),ye=a.create(ie*Z),Ke=a.create(N*Z),j=t.BASE.mulAddUnsafe(ye,C,Ke);if(j.is0())return!1;let se=j.toAffine();return!(a.create(se.x)!==N||A==="recovered"&&I.recovery!==G(se.x,se.y,N))}catch{return!1}}function ft(w,h,m={}){let{prehash:g}=Zi(m,T);return h=St(h,g),H.fromBytes(w,"recovered").recoverPublicKey(h).toBytes()}return Object.freeze({keygen:p,getPublicKey:E,getSharedSecret:D,utils:b,lengths:y,Point:t,sign:M,verify:ur,recoverPublicKey:ft,Signature:H,hash:n})}var Ji={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},ld={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var Pa=BigInt(2);function fd(t){let e=Ji.p,r=BigInt(3),n=BigInt(6),s=BigInt(11),o=BigInt(22),c=BigInt(23),i=BigInt(44),a=BigInt(88),u=t*t*t%e,l=u*u*t%e,f=Ne(l,r,e)*l%e,d=Ne(f,r,e)*l%e,p=Ne(d,Pa,e)*u%e,E=Ne(p,s,e)*p%e,D=Ne(E,o,e)*E%e,b=Ne(D,i,e)*D%e,y=Ne(b,a,e)*b%e,T=Ne(y,i,e)*D%e,P=Ne(T,r,e)*l%e,_=Ne(P,c,e)*E%e,F=Ne(_,n,e)*u%e,Q=Ne(F,Pa,e);if(!Qi.eql(Qi.sqr(Q),t))throw new Error("Cannot find square root");return Q}var Qi=tr(Ji.p,{sqrt:fd}),dd=La(Ji,{Fp:Qi,endo:ld}),zr=_a(dd,Qc);var Gn=class extends Error{constructor(e="An error occurred while verifying a message"){super(e),this.name="VerificationError"}};function Na(t,e,r,n){n?.signal?.throwIfAborted();let s=Ra.default.createHash("sha256");if(r instanceof Uint8Array)s.update(r);else for(let c of r)s.update(c);let o=s.digest();try{return zr.verify(e,o,t,{prehash:!1,format:"der"})}catch(c){throw new Gn(String(c))}}var Wn=class{type="secp256k1";raw;_key;constructor(e){this._key=Fa(e),this.raw=Ua(this._key)}toMultihash(){return Ge.digest(jt(this))}toCID(){return fe.createV1(114,this.toMultihash())}toString(){return ce.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Ae(this.raw,e.raw)}verify(e,r,n){return Na(this._key,r,e,n)}};function Ma(t){return new Wn(t)}function Ua(t){return zr.Point.fromBytes(t).toBytes()}function Fa(t){try{return zr.Point.fromBytes(t),t}catch(e){throw new Or(String(e))}}function Ka(t){let{Type:e,Data:r}=Hr.decode(t.digest),n=r??new Uint8Array;switch(e){case De.Ed25519:return Da(n);case De.secp256k1:return Ma(n);case De.ECDSA:return Fc(n);default:throw new Pr}}function jt(t){return Hr.encode({Type:De[t.type],Data:t.raw})}var $a=Symbol.for("nodejs.util.inspect.custom"),hd=114,Vr=class{type;multihash;publicKey;string;constructor(e){this.type=e.type,this.multihash=e.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[mn]=!0;toString(){return this.string==null&&(this.string=ce.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return fe.createV1(hd,this.multihash)}toJSON(){return this.toString()}equals(e){if(e==null)return!1;if(e instanceof Uint8Array)return Ae(this.multihash.bytes,e);if(typeof e=="string")return this.toString()===e;if(e?.toMultihash()?.bytes!=null)return Ae(this.multihash.bytes,e.toMultihash().bytes);throw new Error("not valid Id")}[$a](){return`PeerId(${this.toString()})`}},Yn=class extends Vr{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},qn=class extends Vr{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.publicKey}},Zn=class extends Vr{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.publicKey}},pd=2336,jn=class{type="url";multihash;publicKey;url;constructor(e){this.url=e.toString(),this.multihash=Ge.digest(Te(this.url))}[$a](){return`PeerId(${this.url})`}[mn]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return fe.createV1(pd,this.toMultihash())}toJSON(){return this.toString()}equals(e){return e==null?!1:(e instanceof Uint8Array&&(e=ae(e)),e.toString()===this.toString())}};function ct(t){if(yd(t))return new Yn({multihash:t});if(md(t))try{let e=Ka(t);if(e.type==="Ed25519")return new qn({multihash:t,publicKey:e});if(e.type==="secp256k1")return new Zn({multihash:t,publicKey:e})}catch{let r=ae(t.digest);return new jn(new URL(r))}throw new un("Supplied PeerID Multihash is invalid")}function md(t){return t.code===Ge.code}function yd(t){return t.code===ai.code}var bu=ke(ue("net"),1);var we=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},at=class extends Error{static name="ValidationError";name="ValidationError"},Xn=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},Qn=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};var Ue=ue("node:net");function ts(t){return e=>ae(e,t)}function rs(t){return e=>Te(e,t)}function nr(t){return new DataView(t.buffer).getUint16(t.byteOffset).toString()}function _t(t){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,typeof t=="string"?parseInt(t):t),new Uint8Array(e)}function Ha(t){let e=t.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 r=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 s=_t(n);return qe([r,s],r.length+s.length)}function za(t){let e=t.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 r=je.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 s=_t(n);return qe([r,s],r.length+s.length)}function ns(t){let e=t.subarray(0,t.length-2),r=t.subarray(t.length-2),n=ae(e,"base32"),s=nr(r);return`${n}:${s}`}var os=function(t){t=t.toString().trim();let e=new Uint8Array(4);return t.split(/\./g).forEach((r,n)=>{let s=parseInt(r,10);if(isNaN(s)||s<0||s>255)throw new we("Invalid byte value in IP address");e[n]=s}),e},Va=function(t){let e=0;t=t.toString().trim();let r=t.split(":",8),n;for(n=0;n<r.length;n++){let o=(0,Ue.isIPv4)(r[n]),c;o&&(c=os(r[n]),r[n]=ae(c.subarray(0,2),"base16")),c!=null&&++n<8&&r.splice(n,0,ae(c.subarray(2,4),"base16"))}if(r[0]==="")for(;r.length<8;)r.unshift("0");else if(r[r.length-1]==="")for(;r.length<8;)r.push("0");else if(r.length<8){for(n=0;n<r.length&&r[n]!=="";n++);let o=[n,1];for(n=9-r.length;n>0;n--)o.push("0");r.splice.apply(r,o)}let s=new Uint8Array(e+16);for(n=0;n<r.length;n++){r[n]===""&&(r[n]="0");let o=parseInt(r[n],16);if(isNaN(o)||o<0||o>65535)throw new we("Invalid byte value in IP address");s[e++]=o>>8&255,s[e++]=o&255}return s},Ga=function(t){if(t.byteLength!==4)throw new we("IPv4 address was incorrect length");let e=[];for(let r=0;r<t.byteLength;r++)e.push(t[r]);return e.join(".")},Wa=function(t){if(t.byteLength!==16)throw new we("IPv6 address was incorrect length");let e=[];for(let n=0;n<t.byteLength;n+=2){let s=t[n],o=t[n+1],c=`${s.toString(16).padStart(2,"0")}${o.toString(16).padStart(2,"0")}`;e.push(c)}let r=e.join(":");try{let n=new URL(`http://[${r}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new we(`Invalid IPv6 address "${r}"`)}};function Ya(t){try{let e=new URL(`http://[${t}]`);return e.hostname.substring(1,e.hostname.length-1)}catch{throw new we(`Invalid IPv6 address "${t}"`)}}var es=Object.values(br).map(t=>t.decoder),bd=(function(){let t=es[0].or(es[1]);return es.slice(2).forEach(e=>t=t.or(e)),t})();function qa(t){return bd.decode(t)}function Za(t){return e=>t.encoder.encode(e)}function gd(t){if(parseInt(t).toString()!==t)throw new at("Value must be an integer")}function wd(t){if(t<0)throw new at("Value must be a positive integer, or zero")}function xd(t){return e=>{if(e>t)throw new at(`Value must be smaller than or equal to ${t}`)}}function Ed(...t){return e=>{for(let r of t)r(e)}}var Gr=Ed(gd,wd,xd(65535));var be=-1,is=class{protocolsByCode=new Map;protocolsByName=new Map;getProtocol(e){let r;if(typeof e=="string"?r=this.protocolsByName.get(e):r=this.protocolsByCode.get(e),r==null)throw new Qn(`Protocol ${e} was unknown`);return r}addProtocol(e){this.protocolsByCode.set(e.code,e),this.protocolsByName.set(e.name,e),e.aliases?.forEach(r=>{this.protocolsByName.set(r,e)})}removeProtocol(e){let r=this.protocolsByCode.get(e);r!=null&&(this.protocolsByCode.delete(r.code),this.protocolsByName.delete(r.name),r.aliases?.forEach(n=>{this.protocolsByName.delete(n)}))}},lt=new is,Rd=[{code:4,name:"ip4",size:32,valueToBytes:os,bytesToValue:Ga,validate:t=>{if(!(0,Ue.isIPv4)(t))throw new at(`Invalid IPv4 address "${t}"`)}},{code:6,name:"tcp",size:16,valueToBytes:_t,bytesToValue:nr,validate:Gr},{code:273,name:"udp",size:16,valueToBytes:_t,bytesToValue:nr,validate:Gr},{code:33,name:"dccp",size:16,valueToBytes:_t,bytesToValue:nr,validate:Gr},{code:41,name:"ip6",size:128,valueToBytes:Va,bytesToValue:Wa,stringToValue:Ya,validate:t=>{if(!(0,Ue.isIPv6)(t))throw new at(`Invalid IPv6 address "${t}"`)}},{code:42,name:"ip6zone",size:be},{code:43,name:"ipcidr",size:8,bytesToValue:ts("base10"),valueToBytes:rs("base10")},{code:53,name:"dns",size:be},{code:54,name:"dns4",size:be},{code:55,name:"dns6",size:be},{code:56,name:"dnsaddr",size:be},{code:132,name:"sctp",size:16,valueToBytes:_t,bytesToValue:nr,validate:Gr},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:be,stringToValue:t=>decodeURIComponent(t),valueToString:t=>encodeURIComponent(t)},{code:421,name:"p2p",aliases:["ipfs"],size:be,bytesToValue:ts("base58btc"),valueToBytes:t=>t.startsWith("Q")||t.startsWith("1")?rs("base58btc")(t):fe.parse(t).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:ns,valueToBytes:Ha},{code:445,name:"onion3",size:296,bytesToValue:ns,valueToBytes:za},{code:446,name:"garlic64",size:be},{code:447,name:"garlic32",size:be},{code:448,name:"tls"},{code:449,name:"sni",size:be},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:be,bytesToValue:Za(Jo),valueToBytes:qa},{code:480,name:"http"},{code:481,name:"http-path",size:be,stringToValue:t=>`/${decodeURIComponent(t)}`,valueToString:t=>encodeURIComponent(t.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:be}];Rd.forEach(t=>{lt.addProtocol(t)});function ja(t){let e=[],r=0;for(;r<t.length;){let n=fr(t,r),s=lt.getProtocol(n),o=Be(n),c=Nd(s,t,r+o),i=0;c>0&&s.size===be&&(i=Be(c));let a=o+i+c,u={code:n,name:s.name,bytes:ht(t.subarray(r,r+a))};if(c>0){let l=r+o+i,f=t.subarray(l,l+c);u.value=s.bytesToValue?.(f)??ae(f)}e.push(u),r+=a}return e}function Xa(t){let e=0,r=[];for(let n of t){if(n.bytes==null){let s=lt.getProtocol(n.code),o=Be(n.code),c,i=0,a=0;n.value!=null&&(c=s.valueToBytes?.(n.value)??Te(n.value),i=c.byteLength,s.size===be&&(a=Be(i)));let u=new Uint8Array(o+a+i),l=0;Ut(n.code,u,l),l+=o,c!=null&&(s.size===be&&(Ut(i,u,l),l+=a),u.set(c,l)),n.bytes=u}r.push(n.bytes),e+=n.bytes.byteLength}return qe(r,e)}function Qa(t){if(t.charAt(0)!=="/")throw new we('String multiaddr must start with "/"');let e=[],r="protocol",n="",s="";for(let o=1;o<t.length;o++){let c=t.charAt(o);c!=="/"&&(r==="protocol"?s+=t.charAt(o):n+=t.charAt(o));let i=o===t.length-1;if(c==="/"||i){let a=lt.getProtocol(s);if(r==="protocol"){if(a.size==null||a.size===0){e.push({code:a.code,name:a.name}),n="",s="",r="protocol";continue}else if(i)throw new we(`Component ${s} was missing value`);r="value"}else if(r==="value"){let u={code:a.code,name:a.name};if(a.size!=null&&a.size!==0){if(n==="")throw new we(`Component ${s} was missing value`);u.value=a.stringToValue?.(n)??n}e.push(u),n="",s="",r="protocol"}}}if(s!==""&&n!=="")throw new we("Incomplete multiaddr");return e}function Ja(t){return`/${t.flatMap(e=>{if(e.value==null)return e.name;let r=lt.getProtocol(e.code);if(r==null)throw new we(`Unknown protocol code ${e.code}`);return[e.name,r.valueToString?.(e.value)??e.value]}).join("/")}`}function Nd(t,e,r){return t.size==null||t.size===0?0:t.size>0?t.size/8:fr(e,r)}var Ud=Symbol.for("nodejs.util.inspect.custom"),gs=Symbol.for("@multiformats/multiaddr");function Fd(t){if(t==null&&(t="/"),ao(t))return t.getComponents();if(t instanceof Uint8Array)return ja(t);if(typeof t=="string")return t=t.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),t===""&&(t="/"),Qa(t);if(Array.isArray(t))return t;throw new we("Must be a string, Uint8Array, Component[], or another Multiaddr")}var co=class t{[gs]=!0;#e;#t;#r;constructor(e="/",r={}){this.#e=Fd(e),r.validate!==!1&&Md(this)}get bytes(){return this.#r==null&&(this.#r=Xa(this.#e)),this.#r}toString(){return this.#t==null&&(this.#t=Ja(this.#e)),this.#t}toJSON(){return this.toString()}getComponents(){return[...this.#e.map(e=>({...e}))]}encapsulate(e){let r=new t(e);return new t([...this.#e,...r.getComponents()],{validate:!1})}decapsulate(e){let r=e.toString(),n=this.toString(),s=n.lastIndexOf(r);if(s<0)throw new Xn(`Address ${this.toString()} does not contain subaddress: ${r}`);return new t(n.slice(0,s),{validate:!1})}decapsulateCode(e){let r;for(let n=this.#e.length-1;n>-1;n--)if(this.#e[n].code===e){r=n;break}return new t(this.#e.slice(0,r),{validate:!1})}equals(e){return Ae(this.bytes,e.bytes)}[Ud](){return`Multiaddr(${this.toString()})`}};function Md(t){t.getComponents().forEach(e=>{let r=lt.getProtocol(e.code);e.value!=null&&r.validate?.(e.value)})}function ao(t){return!!t?.[gs]}function Fe(t){return new co(t)}var Y=t=>({match:e=>{let r=e[0];return r==null||r.code!==t||r.value!=null?!1:e.slice(1)}}),S=(t,e)=>({match:r=>{let n=r[0];return n?.code!==t||n.value==null||e!=null&&n.value!==e?!1:r.slice(1)}}),eu=t=>({match:e=>t.match(e)===!1?e:!1}),O=t=>({match:e=>{let r=t.match(e);return r===!1?e:r}}),ve=(...t)=>({match:e=>{let r;for(let n of t){let s=n.match(e);s!==!1&&(r==null||s.length<r.length)&&(r=s)}return r??!1}}),R=(...t)=>({match:e=>{for(let r of t){let n=r.match(e);if(n===!1)return!1;e=n}return e}});function q(...t){function e(s){if(s==null)return!1;let o=s.getComponents();for(let c of t){let i=c.match(o);if(i===!1)return!1;o=i}return o}function r(s){return e(s)!==!1}function n(s){let o=e(s);return o===!1?!1:o.length===0}return{matchers:t,matches:r,exactMatch:n}}var Kd=S(421),U0=q(Kd),lo=S(54),fo=S(55),ho=S(56),xs=S(53),F0=q(lo,O(S(421))),M0=q(fo,O(S(421))),K0=q(ho,O(S(421))),$0=q(ve(xs,ho,lo,fo),O(S(421))),tu=R(S(4),O(S(43))),ru=R(O(S(42)),S(41),O(S(43))),Es=ve(tu,ru),cr=ve(Es,xs,lo,fo,ho),H0=q(ve(Es,R(ve(xs,ho,lo,fo),O(S(421))))),z0=q(tu),V0=q(ru),G0=q(Es),vs=R(cr,S(6)),Yr=R(cr,S(273)),nu=q(R(vs,O(S(421)))),W0=q(Yr),Ss=R(Yr,Y(460),O(S(421))),po=R(Yr,Y(461),O(S(421))),$d=ve(Ss,po),Y0=q(Ss),q0=q(po),ws=ve(cr,vs,Yr,Ss,po),ou=ve(R(ws,Y(477),O(S(421)))),Z0=q(ou),iu=ve(R(ws,Y(478),O(S(421))),R(ws,Y(448),O(S(449)),Y(477),O(S(421)))),j0=q(iu),su=R(Yr,Y(280),O(S(466)),O(S(466)),O(S(421))),X0=q(su),cu=R(po,Y(465),O(S(466)),O(S(466)),O(S(421))),Q0=q(cu),uo=ve(ou,iu,R(vs,O(S(421))),R($d,O(S(421))),R(cr,O(S(421))),su,cu,S(421)),J0=q(uo),Hd=R(O(uo),Y(290),eu(Y(281)),O(S(421))),ew=q(Hd),zd=ve(R(uo,Y(290),Y(281),O(S(421))),R(uo,Y(281),O(S(421))),R(Y(281),O(S(421)))),tw=q(zd),Vd=R(cr,ve(R(S(6,"80")),R(S(6),Y(480)),Y(480)),O(S(481)),O(S(421))),rw=q(Vd),Gd=R(cr,ve(R(S(6,"443")),R(S(6,"443"),Y(480)),R(S(6),Y(443)),R(S(6),Y(448),Y(480)),R(Y(448),Y(480)),Y(448),Y(443)),O(S(481)),O(S(421))),nw=q(Gd),Wd=ve(R(S(777),O(S(421)))),ow=q(Wd),Yd=ve(R(S(400),O(S(421)))),qr=q(Yd);var mo=class extends Event{type;detail;constructor(e,r){super(e),this.type=e,this.detail=r}};var yu=ke(ue("node:net"),1);function qd(t){let e=t.getComponents(),r={},n=0;return e[n]?.name==="ip6zone"&&(r.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"?(r.type=e[n].name,r.host=e[n].value,n++):e[n]?.name==="dnsaddr"&&(r.type=e[n].name,r.host=`_dnsaddr.${e[n].value}`,n++),(e[n]?.name==="tcp"||e[n]?.name==="udp")&&(r.protocol=e[n].name==="tcp"?"tcp":"udp",r.port=parseInt(`${e[n].value}`),n++),e[n]?.name==="ipcidr"&&(r.type==="ip4"?r.cidr=parseInt(`${e[n].value}`):r.type==="ip6"&&(r.cidr=`${e[n].value}`),n++),r.type==null||r.host==null?null:(e[n]?.name==="tls"&&e[n+1]?.name==="sni"&&(r.sni=e[n+1].value,n+=2),r)}function yo(t){let e=qd(t);if(e==null)throw new B(`Multiaddr ${t} was not an IPv4, IPv6, DNS, DNS4, DNS6 or DNSADDR address`);return e}function bo(){let t={};return t.promise=new Promise((e,r)=>{t.resolve=e,t.reject=r}),t}var go=class{buffer;mask;top;btm;next;constructor(e){if(!(e>0)||(e-1&e)!==0)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(e),this.mask=e-1,this.top=0,this.btm=0,this.next=null}push(e){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=e,this.top=this.top+1&this.mask,!0)}shift(){let e=this.buffer[this.btm];if(e!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,e}isEmpty(){return this.buffer[this.btm]===void 0}},ar=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new go(this.hwm),this.tail=this.head,this.size=0}calculateSize(e){return e?.byteLength!=null?e.byteLength:1}push(e){if(e?.value!=null&&(this.size+=this.calculateSize(e.value)),!this.head.push(e)){let r=this.head;this.head=r.next=new go(2*this.head.buffer.length),this.head.push(e)}}shift(){let e=this.tail.shift();if(e===void 0&&this.tail.next!=null){let r=this.tail.next;this.tail.next=null,this.tail=r,e=this.tail.shift()}return e?.value!=null&&(this.size-=this.calculateSize(e.value)),e}isEmpty(){return this.head.isEmpty()}};var Ts=class extends Error{type;code;constructor(e,r){super(e??"The operation was aborted"),this.type="aborted",this.code=r??"ABORT_ERR"}};function wo(t={}){return Zd(r=>{let n=r.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},t)}function Zd(t,e){e=e??{};let r=e.onEnd,n=new ar,s,o,c,i=bo(),a=async()=>{try{return n.isEmpty()?c?{done:!0}:await new Promise((b,y)=>{o=T=>{o=null,n.push(T);try{b(t(n))}catch(P){y(P)}return s}}):t(n)}finally{n.isEmpty()&&queueMicrotask(()=>{i.resolve(),i=bo()})}},u=b=>o!=null?o(b):(n.push(b),s),l=b=>(n=new ar,o!=null?o({error:b}):(n.push({error:b}),s)),f=b=>{if(c)return s;if(e?.objectMode!==!0&&b?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return u({done:!1,value:b})},d=b=>c?s:(c=!0,b!=null?l(b):u({done:!0})),p=()=>(n=new ar,d(),{done:!0}),E=b=>(d(b),{done:!0});if(s={[Symbol.asyncIterator](){return this},next:a,return:p,throw:E,push:f,end:d,get readableLength(){return n.size},onEmpty:async b=>{let y=b?.signal;if(y?.throwIfAborted(),n.isEmpty())return;let T,P;y!=null&&(T=new Promise((_,F)=>{P=()=>{F(new Ts)},y.addEventListener("abort",P)}));try{await Promise.race([i.promise,T])}finally{P!=null&&y!=null&&y?.removeEventListener("abort",P)}}},r==null)return s;let D=s;return s={[Symbol.asyncIterator](){return this},next(){return D.next()},throw(b){return D.throw(b),r!=null&&(r(b),r=void 0),{done:!0}},return(){return D.return(),r!=null&&(r(),r=void 0),{done:!0}},push:f,end(b){return D.end(b),r!=null&&(r(b),r=void 0),s},get readableLength(){return D.readableLength},onEmpty:b=>D.onEmpty(b)},s}var As=class t extends Error{name="TimeoutError";constructor(e,r){super(e,r),Error.captureStackTrace?.(this,t)}},au=t=>t.reason??new DOMException("This operation was aborted.","AbortError");function Ds(t,e){let{milliseconds:r,fallback:n,message:s,customTimers:o={setTimeout,clearTimeout},signal:c}=e,i,a,l=new Promise((f,d)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(c?.aborted){d(au(c)),t.then(f,d);return}if(c&&(a=()=>{d(au(c))},c.addEventListener("abort",a,{once:!0})),t.then(f,d),r===Number.POSITIVE_INFINITY)return;let p=new As;i=o.setTimeout.call(void 0,()=>{if(n){try{f(n())}catch(E){d(E)}return}typeof t.cancel=="function"&&t.cancel(),s===!1?f():s instanceof Error?d(s):(p.message=s??`Promise timed out after ${r} milliseconds`,d(p))},r)}).finally(()=>{l.clear(),a&&c&&c.removeEventListener("abort",a)});return l.clear=()=>{o.clearTimeout.call(void 0,i),i=void 0},l}var uu=t=>typeof t=="function"?{filter:t}:{...t},jd=t=>t===1/0||Number.isSafeInteger(t)&&t>=0,Xd=[["addEventListener","removeEventListener"],["on","off"],["addListener","removeListener"]],Qd=t=>{for(let[e,r]of Xd){let n=t?.[e],s=t?.[r];if(typeof n=="function"&&typeof s=="function")return{addListener:n.bind(t),removeListener:s.bind(t)}}throw new TypeError("Emitter is not compatible")},Jd=t=>{let e=new Map;for(let[r,n]of t)for(let s of Array.isArray(r)?r:[r])e.has(s)||e.set(s,n);return e},eh=({addListener:t,removeListener:e,handlers:r,signal:n,abortHandler:s,isDone:o})=>{n?.addEventListener("abort",s,{once:!0});for(let[c,i]of r)if(t(c,i),o()){e(c,i);return}},th=({removeListener:t,handlers:e,signal:r,abortHandler:n})=>{for(let[s,o]of e)t(s,o);r?.removeEventListener("abort",n)},rh=(t,e,r)=>{let n=Promise.resolve();return(s,o)=>{n=n.then(async()=>{if(e())return;let c;try{c=t?await t(s):!0}catch(i){e()||r(i);return}e()||o(c)})}};function nh(t,e,r){let n=()=>{},s=!1,o,c=new Promise((i,a)=>{r=uu(r);let{filter:u}=r;if(!jd(r.count))throw new TypeError("The `count` option should be at least 0 or more");if(typeof r.timeout=="number"&&!(r.timeout>0))throw new TypeError(`Expected the \`timeout\` option to be a positive number, got \`${r.timeout}\``);r.signal?.throwIfAborted();let{addListener:l,removeListener:f}=Qd(t);if(r.count===0){i([]);return}let d=[],p=_=>{n(),a(_)},E=rh(u,()=>s,p),D=_=>{d.push(_),r.count===d.length&&(n(),i(d))},b=(..._)=>{if(s)return;let F=r.multiArgs?_:_[0];if(!u){D(F);return}E(F,Q=>{Q&&D(F)})},y=(..._)=>{p(r.rejectionMultiArgs?_:_[0])},T=()=>{p(r.signal.reason)},P={addListener:l,removeListener:f,handlers:Jd([[e,b],[r.rejectionEvents??["error"],y]]),signal:r.signal,abortHandler:T,isDone:()=>s};n=()=>{s=!0,clearTimeout(o),th(P)},eh(P),!(s||!r.resolveImmediately)&&(Number.isFinite(r.timeout)&&(o=setTimeout(n,r.timeout)),i(d))});if(c.cancel=n,typeof r.timeout=="number"&&r.timeout>0&&!r.resolveImmediately){let i=Ds(c,{milliseconds:r.timeout});return i.cancel=()=>{n(),i.clear()},i}return c}function tt(t,e,r){let n=nh(t,e,{...uu(r),count:1,resolveImmediately:!1}),s=n.then(o=>o[0]);return s.cancel=n.cancel,s}var Rt=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"};var xo=class extends Error{static name="StreamClosedError";name="StreamClosedError"};function oh(t){return t.reason}function Zr(t,e,r){if(e==null||t==null)return t;let n=r?.translateError??oh;if(e.aborted)return t.catch(()=>{}),Promise.reject(n(e));let s;return Promise.race([t,new Promise((o,c)=>{s=()=>{c(n(e))},e.addEventListener("abort",s)})]).finally(()=>{s!=null&&e.removeEventListener("abort",s)})}var ih=Math.pow(2,20)*4,Eo=class extends Wt{status;timeline;inactivityTimeout;maxReadBufferLength;maxWriteBufferLength;log;direction;maxMessageSize;readStatus;writeStatus;remoteReadStatus;remoteWriteStatus;writableNeedsDrain;readBuffer;writeBuffer;sendingData;#e=!1;#t;#r=new Set;onDrainPromise;constructor(e){super(),this.status="open",this.log=e.log,this.direction=e.direction??"outbound",this.inactivityTimeout=e.inactivityTimeout??12e4,this.maxReadBufferLength=e.maxReadBufferLength??ih,this.maxWriteBufferLength=e.maxWriteBufferLength,this.maxMessageSize=e.maxMessageSize,this.readBuffer=new oe,this.writeBuffer=new oe,this.readStatus="readable",this.remoteReadStatus="readable",this.writeStatus="writable",this.remoteWriteStatus="writable",this.sendingData=!1,this.writableNeedsDrain=!1,this.timeline={open:Date.now()},this.processSendQueue=this.processSendQueue.bind(this);let r=()=>{this.writableNeedsDrain&&(this.log.trace("drain event received, continue sending data"),this.writableNeedsDrain=!1,queueMicrotask(()=>{try{this.processSendQueue()}catch(s){this.log.error("processSendQueue threw - %e",s)}})),this.onDrainPromise?.resolve()};this.addEventListener("drain",r);let n=s=>{this.onDrainPromise?.reject(s.error??new xo)};this.addEventListener("close",n)}get readBufferLength(){return this.readBuffer.byteLength}get readableEnded(){return this.#e}get writeBufferLength(){return this.writeBuffer.byteLength}async onDrain(e){return this.writableNeedsDrain!==!0?Promise.resolve():(this.onDrainPromise==null&&(this.onDrainPromise=Promise.withResolvers()),Zr(this.onDrainPromise.promise,e?.signal))}async*[Symbol.asyncIterator](){let e=wo(),r,n=o=>{e.push(o.data)};this.addEventListener("message",n);let s=()=>{this.#r.delete(s),this.removeEventListener("message",n),r=this.#t,e.end()};this.#r.add(s),this.readableDone()&&s();try{if(yield*e,r!=null)throw r}finally{this.removeEventListener("message",n),this.#r.delete(s)}}readableDone(){return this.readBuffer.byteLength===0&&(this.remoteWriteStatus==="closed"||this.readStatus==="closing"||this.readStatus==="closed")}isReadable(){return this.status==="open"}send(e){if(this.writeStatus==="closed"||this.writeStatus==="closing")throw new yt(`Cannot write to a stream that is ${this.writeStatus}`);return this.log.trace("append %d bytes to write buffer",e.byteLength),this.writeBuffer.append(e),this.processSendQueue()}abort(e){if(this.status==="aborted"||this.status==="reset"||this.status==="closed"){this.readBuffer.byteLength>0&&(this.#t??=e,this.readBuffer.consume(this.readBuffer.byteLength),this.readStatus="closed",this.maybeDispatchEnd());return}this.log.error("abort with error - %e",e),this.status="aborted",this.#t=e,this.readBuffer.byteLength>0&&this.readBuffer.consume(this.readBuffer.byteLength),this.writeBuffer.byteLength>0&&(this.writeBuffer.consume(this.writeBuffer.byteLength),this.safeDispatchEvent("idle")),this.writeStatus="closed",this.remoteWriteStatus="closed",this.readStatus="closed",this.remoteReadStatus="closed",this.timeline.close=Date.now(),this.maybeDispatchEnd();try{this.sendReset(e)}catch(r){this.log.error("failed to send reset to remote - %e",r)}this.dispatchEvent(new hn(e))}pause(){if(this.readStatus==="closed"||this.readStatus==="closing")throw new yt("Cannot pause a stream that is closing/closed");this.readStatus!=="paused"&&(this.readStatus="paused",this.sendPause())}resume(){if(this.readStatus==="closed"||this.readStatus==="closing")throw new yt("Cannot resume a stream that is closing/closed");this.readStatus!=="readable"&&(this.readStatus="readable",this.dispatchReadBuffer(),this.sendResume())}push(e){if(this.readStatus==="closed"||this.readStatus==="closing")throw new yt(`Cannot push data onto a stream that is ${this.readStatus}`);if(e.byteLength!==0){if(this.readBuffer.append(e),this.readStatus==="paused"||this.listenerCount("message")===0){this.checkReadBufferLength();return}setTimeout(()=>{this.dispatchReadBuffer()},0)}}unshift(e){if(this.readStatus==="closed"||this.readStatus==="closing")throw new yt(`Cannot push data onto a stream that is ${this.readStatus}`);if(e.byteLength!==0){if(this.readBuffer.prepend(e),this.readStatus==="paused"||this.listenerCount("message")===0){this.checkReadBufferLength();return}setTimeout(()=>{this.dispatchReadBuffer()},0)}}onData(e){if(e.byteLength!==0){if(this.readStatus==="closing"||this.readStatus==="closed"){this.log("ignoring data - read status %s",this.readStatus);return}this.readBuffer.append(e),this.dispatchReadBuffer()}}addEventListener(...e){super.addEventListener.apply(this,e),e[0]==="message"&&this.readBuffer.byteLength>0&&queueMicrotask(()=>{this.dispatchReadBuffer()})}onRemoteReset(){if(this.status==="aborted"||this.status==="reset"||this.status==="closed")return;this.log("remote reset");let e=new an;this.#t=e,this.status="reset",this.writeStatus="closed",this.remoteWriteStatus="closed",this.remoteReadStatus="closed",this.timeline.close=Date.now(),this.readBuffer.byteLength===0&&(this.readStatus="closed",this.maybeDispatchEnd()),this.dispatchEvent(new pn(e))}onTransportClosed(e){this.log("transport closed"),this.readStatus==="readable"&&this.readBuffer.byteLength===0&&(this.log("close readable end after transport closed and read buffer is empty"),this.readStatus="closed"),this.remoteReadStatus!=="closed"&&(this.remoteReadStatus="closed"),this.remoteWriteStatus!=="closed"&&(this.remoteWriteStatus="closed"),this.writeStatus!=="closed"&&(this.writeStatus="closed"),e!=null?this.abort(e):(this.status==="open"||this.status==="closing")&&(this.timeline.close=Date.now(),this.status="closed",this.maybeDispatchEnd(),this.dispatchEvent(new Vt))}onRemoteCloseWrite(){this.remoteWriteStatus!=="closed"&&(this.log.trace("on remote close write"),this.remoteWriteStatus="closed",this.safeDispatchEvent("remoteCloseWrite"),this.maybeDispatchEnd(),this.writeStatus==="closed"&&this.onTransportClosed())}onRemoteCloseRead(){this.log.trace("on remote close read"),this.remoteReadStatus="closed",this.writeBuffer.byteLength>0&&(this.writeBuffer.consume(this.writeBuffer.byteLength),this.safeDispatchEvent("idle"))}processSendQueue(){if(this.writableNeedsDrain)return this.log.trace("not processing send queue as drain is required"),this.checkWriteBufferLength(),!1;if(this.writeBuffer.byteLength===0)return this.log.trace("not processing send queue as no bytes to send"),!0;if(this.sendingData)return this.log.trace("not processing send queue as already sending data"),!0;if(this.writeStatus!=="writable"&&this.writeStatus!=="closing")return this.log.trace("not processing send queue as stream is %s",this.writeStatus),!1;this.sendingData=!0,this.log.trace("processing send queue with %d queued bytes",this.writeBuffer.byteLength);try{let e=!0,r=this.writeBuffer.byteLength,n=0;for(;this.writeBuffer.byteLength>0;){let s=Math.min(this.maxMessageSize??this.writeBuffer.byteLength,this.writeBuffer.byteLength);if(s===0){e=!1;break}let o=this.writeBuffer.sublist(0,s),c=new oe(o);this.writeBuffer.consume(o.byteLength);let i;try{i=this.sendData(o)}catch(a){throw this.writeBuffer.prepend(c),this.abort(a),a}if(e=i.canSendMore,n+=i.sentBytes,i.sentBytes!==c.byteLength&&(c.consume(i.sentBytes),this.writeBuffer.prepend(c)),!e)break}return e||(this.log.trace("sent %d/%d bytes, pausing sending because underlying stream is full, %d bytes left in the write buffer",n,r,this.writeBuffer.byteLength),this.writableNeedsDrain=!0,this.checkWriteBufferLength()),this.writeBuffer.byteLength===0&&this.safeDispatchEvent("idle"),e}finally{this.sendingData=!1}}maybeDispatchEnd(){this.readableDone()&&(this.#r.forEach(e=>{e()}),!this.#e&&(this.#e=!0,this.safeDispatchEvent("end")))}dispatchReadBuffer(){try{if(this.listenerCount("message")===0){this.log.trace("not dispatching pause buffer as there are no listeners for the message event");return}if(this.readBuffer.byteLength===0){this.log.trace("not dispatching pause buffer as there is no data to dispatch");return}if(this.readStatus==="paused"){this.log.trace("not dispatching pause buffer we are paused");return}if(this.readStatus==="closing"||this.readStatus==="closed"){this.log("dropping %d bytes because the readable end is %s",this.readBuffer.byteLength,this.readStatus),this.readBuffer.consume(this.readBuffer.byteLength);return}let e=this.readBuffer.sublist();this.readBuffer.consume(e.byteLength),this.dispatchEvent(new dn(e))}finally{this.readBuffer.byteLength===0&&this.remoteWriteStatus==="closed"&&(this.log("close readable end after dispatching read buffer and remote writable end is closed"),this.readStatus="closed",this.maybeDispatchEnd()),this.checkReadBufferLength()}}checkReadBufferLength(){this.readBuffer.byteLength>this.maxReadBufferLength&&this.abort(new Ct(`Read buffer length of ${this.readBuffer.byteLength} exceeded limit of ${this.maxReadBufferLength}, read status is ${this.readStatus}`))}checkWriteBufferLength(){this.maxWriteBufferLength!=null&&this.writeBuffer.byteLength>this.maxWriteBufferLength&&this.abort(new Ct(`Write buffer length of ${this.writeBuffer.byteLength} exceeded limit of ${this.maxWriteBufferLength}, write status is ${this.writeStatus}`))}onMuxerNeedsDrain(){this.writableNeedsDrain=!0}onMuxerDrain(){this.safeDispatchEvent("drain")}};var vo=class extends Eo{remoteAddr;metricPrefix;metrics;constructor(e){super(e),this.metricPrefix=e.metricPrefix??"",this.metrics=e.metrics,this.remoteAddr=e.remoteAddr,this.addEventListener("close",r=>{this.metrics?.increment({[`${this.metricPrefix}end`]:!0}),r.error!=null?r.local?this.metrics?.increment({[`${this.metricPrefix}abort`]:!0}):this.metrics?.increment({[`${this.metricPrefix}reset`]:!0}):r.local?this.metrics?.increment({[`${this.metricPrefix}_local_close`]:!0}):this.metrics?.increment({[`${this.metricPrefix}_remote_close`]:!0})})}async close(e){this.status==="open"&&(this.status="closing",this.writeStatus="closing",this.remoteWriteStatus="closing",this.remoteReadStatus="closing",(this.sendingData||this.writeBuffer.byteLength>0)&&(this.log("waiting for write queue to become idle before closing writable end of stream, %d unsent bytes",this.writeBuffer.byteLength),await tt(this,"idle",{...e,rejectionEvents:["close"]})),this.writableNeedsDrain&&(this.log("waiting for write queue to drain before closing writable end of stream, %d unsent bytes",this.writeBuffer.byteLength),await tt(this,"drain",{...e,rejectionEvents:["close"]})),await this.sendClose(e),this.onTransportClosed())}};var fu=ke(ue("node:os"),1);function lu(t){return!!(t.startsWith("169.254.")||t.toLowerCase().startsWith("fe80"))}function Is(t,e,r){let n=[t.type,r??t.host];if(t.protocol!=null){let s=e??t.port;s!=null&&n.push(t.protocol,s)}return t.type==="ip6"&&t.zone!=null&&n.unshift("ip6zone",t.zone),t.cidr!=null&&n.push("ipcidr",t.cidr),Fe(`/${n.join("/")}`)}var sh={4:"IPv4",6:"IPv6"};function ch(t){return["0.0.0.0","::"].includes(t)}function ah(t){let e=[],r=fu.default.networkInterfaces();for(let[,n]of Object.entries(r))if(n!=null)for(let s of n)lu(s.address)||s.family===sh[t]&&e.push(s.address);return e}function du(t,e){if(t==null)return[];let r=yo(t);return(r.type==="ip4"||r.type==="ip6")&&ch(r.host)?ah(r.type==="ip4"?4:6).map(n=>Is(r,e,n)):[Is(r,e)]}function hu(t,e){if(typeof t!="string")throw new B(`invalid ip provided: ${t}`);if(typeof e=="string"&&(e=parseInt(e)),isNaN(e))throw new B(`invalid port provided: ${e}`);if((0,Ue.isIPv4)(t))return Fe(`/ip4/${t}/tcp/${e}`);if((0,Ue.isIPv6)(t))return Fe(`/ip6/${t}/tcp/${e}`);throw new B(`invalid ip:port for creating a multiaddr: ${t}:${e}`)}var uh=4194304,So=class extends Error{static name="UnwrappedError";name="UnwrappedError"},Bs=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},Ls=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},Os=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function lh(t){return typeof t?.closeRead=="function"}function fh(t){return typeof t?.close=="function"}function Cs(t){return lh(t)?t.remoteWriteStatus!=="writable"&&t.readBufferLength===0:fh(t)?t.status!=="open":!1}function dh(t){return t?.addEventListener!=null&&t?.removeEventListener!=null&&t?.send!=null&&t?.push!=null&&t?.log!=null}function hh(t,e){let r=e?.maxBufferSize??uh,n=new oe,s,o=!1,c;if(!dh(t))throw new B("Argument should be a Stream or a Multiaddr");let i=f=>{if(!o&&c==null){if(n.append(f.data),n.byteLength>r){let d=n.byteLength;n.consume(d);let p=new Ct(`Read buffer overflow - ${d} > ${r}`);c=p,s?.reject(p),queueMicrotask(()=>{t.abort(p)});return}s?.resolve()}};t.addEventListener("message",i);let a=f=>{f.error!=null?s?.reject(f.error):s?.resolve()};t.addEventListener("close",a);let u=()=>{s?.resolve()};t.addEventListener("remoteCloseWrite",u);let l={readBuffer:n,async read(f){if(o===!0)throw new So("Stream was unwrapped");if(c!=null)throw c;if(Cs(t)){if(n.byteLength===0&&f?.bytes==null)return null;if(f?.bytes!=null&&n.byteLength<f.bytes)throw t.log.error("closed after reading %d/%d bytes",n.byteLength,f.bytes),new Rt(`Unexpected EOF - stream closed after reading ${n.byteLength}/${f.bytes} bytes`)}let d=f?.bytes??1;for(s=Promise.withResolvers();;){if(n.byteLength>=d){s.resolve();break}if(await Zr(s.promise,f?.signal),Cs(t)){if(n.byteLength===0&&f?.bytes==null)return null;break}s=Promise.withResolvers()}let p=f?.bytes??n.byteLength;if(n.byteLength<p){if(Cs(t))throw t.log.error("closed while reading %d/%d bytes",n.byteLength,p),new Rt(`Unexpected EOF - stream closed while reading ${n.byteLength}/${p} bytes`);return l.read(f)}let E=n.sublist(0,p);return n.consume(p),E},async write(f,d){if(o===!0)throw new So("Stream was unwrapped");t.send(f)||await tt(t,"drain",{signal:d?.signal,rejectionEvents:["close"]})},unwrap(){return o||(o=!0,t.removeEventListener("message",i),t.removeEventListener("close",a),t.removeEventListener("remoteCloseWrite",u),n.byteLength>0&&(t.log("stream unwrapped with %d unread bytes",n.byteLength),t.unshift(n),n.consume(n.byteLength))),t}};return l}function ph(t,e={}){let r=hh(t,e);e.maxDataLength!=null&&e.maxLengthLength==null&&(e.maxLengthLength=Be(e.maxDataLength));let n=e?.lengthDecoder??fr,s=e?.lengthEncoder??Us;return{async read(c){let i=-1,a=new oe;for(;;){let l=await r.read({...c,bytes:1});if(l==null)break;a.append(l);try{i=n(a)}catch(f){if(f instanceof RangeError)continue;throw f}if(i<0)throw new Bs("Invalid message length");if(e?.maxLengthLength!=null&&a.byteLength>e.maxLengthLength)throw new Os(`Message length length too long - ${a.byteLength} > ${e.maxLengthLength}`);if(i>-1)break}if(e?.maxDataLength!=null&&i>e.maxDataLength)throw new Ls(`Message length too long - ${i} > ${e.maxDataLength}`);let u=await r.read({...c,bytes:i});if(u==null)throw t.log.error("tried to read %d bytes but the stream closed",i),new Rt(`Unexpected EOF - tried to read ${i} bytes but the stream closed`);if(u.byteLength!==i)throw t.log.error("read %d/%d bytes before the stream closed",u.byteLength,i),new Rt(`Unexpected EOF - read ${u.byteLength}/${i} bytes before the stream closed`);return u},async write(c,i){await r.write(new oe(s(c.byteLength),c),i)},async writeV(c,i){let a=new oe(...c.flatMap(u=>[s(u.byteLength),u]));await r.write(a,i)},unwrap(){return r.unwrap()}}}function ks(t,e){let r=ph(t,e),n={read:async(s,o)=>{let c=await r.read(o);return s.decode(c,o)},write:async(s,o,c)=>{await r.write(o.encode(s),c)},writeV:async(s,o,c)=>{await r.writeV(s.map(i=>o.encode(i)),c)},pb:s=>({read:async o=>n.read(s,o),write:async(o,c)=>n.write(o,s,c),writeV:async(o,c)=>n.writeV(o,s,c),unwrap:()=>n}),unwrap:()=>r.unwrap()};return n}var _s=class extends vo{socket;constructor(e){let r=e.remoteAddr;if(e.localAddr!=null&&qr.matches(e.localAddr))r=e.localAddr;else if(r==null){if(e.socket.remoteAddress==null||e.socket.remotePort==null)throw new B("Could not determine remote address or port");r=hu(e.socket.remoteAddress,e.socket.remotePort)}super({...e,remoteAddr:r}),this.socket=e.socket,this.socket.on("data",n=>{this.onData(n)}),this.socket.on("error",n=>{this.log("tcp error",r,n),this.abort(n)}),this.socket.setTimeout(e.inactivityTimeout??120*1e3),this.socket.once("timeout",()=>{this.log("tcp timeout",r),this.abort(new zt)}),this.socket.once("end",()=>{this.log("tcp end",r),this.onTransportClosed()}),this.socket.once("close",n=>{if(this.log("tcp close",r),n){this.abort(new Error("TCP transmission error"));return}this.onTransportClosed()}),this.socket.on("drain",()=>{this.log("tcp drain"),this.safeDispatchEvent("drain")})}sendData(e){let r=0,n=!0;for(let s of e)if(r+=s.byteLength,n=this.socket.write(s),!n)break;return{sentBytes:r,canSendMore:n}}async sendClose(e){this.socket.destroyed||(this.socket.destroySoon(),await tt(this.socket,"close",e))}sendReset(){if(this.socket.writableEnded){this.socket.destroy();return}if(qr.matches(this.remoteAddr)){this.socket.destroy();return}this.socket.resetAndDestroy()}sendPause(){this.socket.pause()}sendResume(){this.socket.resume()}},To=t=>new _s(t);var pu=ke(ue("os"),1),mu=ke(ue("path"),1);function Ao(t,e={}){if(qr.exactMatch(t)){let o=t.getComponents().find(c=>c.code===400)?.value;if(o==null)throw new B(`Multiaddr ${t} was not a Unix address`);return pu.default.platform()==="win32"?{path:mu.default.join("\\\\.\\pipe\\",o)}:{path:o}}let r=yo(t),n=r.host,s=r.port;return{host:n,port:s,ipv6Only:r.type==="ip6",...e}}var ge;(function(t){t[t.INACTIVE=0]="INACTIVE",t[t.ACTIVE=1]="ACTIVE",t[t.PAUSED=2]="PAUSED"})(ge||(ge={}));var Do=class extends Wt{context;server;sockets=new Set;status={code:ge.INACTIVE};metrics;addr;log;shutdownController;constructor(e){if(super(),this.context=e,e.keepAlive=e.keepAlive??!0,e.noDelay=e.noDelay??!0,e.allowHalfOpen=e.allowHalfOpen??!1,this.shutdownController=new AbortController,yn(1/0,this.shutdownController.signal),this.log=e.logger.forComponent("libp2p:tcp:listener"),this.addr="unknown",this.server=yu.default.createServer(e,this.onSocket.bind(this)),e.maxConnections!==void 0&&(this.server.maxConnections=e.maxConnections),e.closeServerOnMaxConnections!=null&&e.closeServerOnMaxConnections.closeAbove<e.closeServerOnMaxConnections.listenBelow)throw new B("closeAbove must be >= listenBelow");e.metrics?.registerMetricGroup("libp2p_tcp_inbound_connections_total",{label:"address",help:"Current active connections in TCP listener",calculate:()=>({[this.addr]:this.sockets.size})}),this.metrics={status:e.metrics?.registerMetricGroup("libp2p_tcp_listener_status_info",{label:"address",help:"Current status of the TCP listener socket"}),errors:e.metrics?.registerMetricGroup("libp2p_tcp_listener_errors_total",{label:"address",help:"Total count of TCP listener errors by type"}),events:e.metrics?.registerMetricGroup("libp2p_tcp_listener_events_total",{label:"address",help:"Total count of TCP listener events by type"})},this.server.on("listening",()=>{let r=this.server.address();r==null?this.addr="unknown":typeof r=="string"?this.addr=r:this.addr=`${r.address}:${r.port}`,this.metrics.status?.update({[this.addr]:ge.ACTIVE}),this.safeDispatchEvent("listening")}).on("error",r=>{this.metrics.errors?.increment({[`${this.addr} listen_error`]:!0}),this.safeDispatchEvent("error",{detail:r})}).on("close",()=>{this.metrics.status?.update({[this.addr]:this.status.code}),this.status.code!==ge.PAUSED&&this.safeDispatchEvent("close")}).on("drop",()=>{this.metrics.events?.increment({[`${this.addr} drop`]:!0})})}onSocket(e){if(this.metrics.events?.increment({[`${this.addr} connection`]:!0}),this.status.code!==ge.ACTIVE)throw e.destroy(),new ln("Server is not listening yet");let r;try{r=To({socket:e,inactivityTimeout:this.context.inactivityTimeout,metrics:this.metrics?.events,metricPrefix:`${this.addr} `,direction:"inbound",localAddr:this.status.listeningAddr,log:this.context.logger.forComponent("libp2p:tcp:connection")})}catch(n){this.log.error("inbound connection failed - %e",n),this.metrics.errors?.increment({[`${this.addr} inbound_to_connection`]:!0}),e.destroy();return}this.log("new inbound connection %s",r.remoteAddr),this.sockets.add(e),this.context.upgrader.upgradeInbound(r,{signal:this.shutdownController.signal}).then(()=>{this.log("inbound connection upgraded %s",r.remoteAddr),e.once("close",()=>{this.sockets.delete(e),this.context.closeServerOnMaxConnections!=null&&this.sockets.size<this.context.closeServerOnMaxConnections.listenBelow&&this.resume().catch(n=>{this.log.error("error attempting to listen server once connection count under limit - %e",n),this.context.closeServerOnMaxConnections?.onListenError?.(n)})}),this.context.closeServerOnMaxConnections!=null&&this.sockets.size>=this.context.closeServerOnMaxConnections.closeAbove&&(this.log("pausing incoming connections as limit is exceeded - %d/%d",this.sockets.size,this.context.closeServerOnMaxConnections.closeAbove),this.pause())}).catch(async n=>{this.log.error("inbound connection upgrade failed - %e",n),this.metrics.errors?.increment({[`${this.addr} inbound_upgrade`]:!0}),this.sockets.delete(e),r.abort(n)})}getAddrs(){if(this.status.code===ge.INACTIVE)return[];let e=this.server.address();return e==null?[]:typeof e=="string"?[Fe(`/unix/${encodeURIComponent(e)}`)]:du(this.status.listeningAddr,e.port)}updateAnnounceAddrs(){}async listen(e){if(this.status.code===ge.ACTIVE||this.status.code===ge.PAUSED)throw new fn("server is already listening");try{this.status={code:ge.ACTIVE,listeningAddr:e,netConfig:Ao(e,this.context)},await this.resume()}catch(r){throw this.status={code:ge.INACTIVE},r}}async close(e){let r=[];this.server.listening&&r.push(tt(this.server,"close",e)),this.pause(!0),this.shutdownController.abort(),this.sockets.forEach(n=>{n.readable&&(r.push(tt(n,"close",e)),n.destroy())}),await Promise.all(r)}async resume(){if(this.server.listening||this.status.code===ge.INACTIVE)return;let e=this.status.netConfig;await new Promise((r,n)=>{this.server.once("error",n),this.server.listen(e,r)}),this.status={...this.status,code:ge.ACTIVE},this.log("listening on %s",this.server.address())}pause(e=!1){if(!this.server.listening&&this.status.code===ge.PAUSED&&e){this.status={code:ge.INACTIVE};return}!this.server.listening||this.status.code!==ge.ACTIVE||(this.log("%s server on %s",e?"closing":"pausing",this.server.address()),this.status=e?{code:ge.INACTIVE}:{...this.status,code:ge.PAUSED},this.server.close())}};var Io=class{opts;metrics;components;log;constructor(e,r={}){this.log=e.logger.forComponent("libp2p:tcp"),this.opts=r,this.components=e,e.metrics!=null&&(this.metrics={events:e.metrics.registerCounterGroup("libp2p_tcp_dialer_events_total",{label:"event",help:"Total count of TCP dialer events by type"}),errors:e.metrics.registerCounterGroup("libp2p_tcp_dialer_errors_total",{label:"event",help:"Total count of TCP dialer events by type"})})}[bc]=!0;[Symbol.toStringTag]="@libp2p/tcp";[xc]=["@libp2p/transport"];async dial(e,r){r.keepAlive=r.keepAlive??!0,r.noDelay=r.noDelay??!0,r.allowHalfOpen=r.allowHalfOpen??!1;let n=await this._connect(e,r),s;try{s=To({socket:n,inactivityTimeout:this.opts.outboundSocketInactivityTimeout,metrics:this.metrics?.events,direction:"outbound",remoteAddr:e,log:this.log.newScope("connection")})}catch(o){throw this.metrics?.errors.increment({outbound_to_connection:!0}),n.destroy(o),o}try{return this.log("new outbound connection %s",s.remoteAddr),await r.upgrader.upgradeOutbound(s,r)}catch(o){throw this.metrics?.errors.increment({outbound_upgrade:!0}),this.log.error("error upgrading outbound connection - %e",o),s.abort(o),o}}async _connect(e,r){r.signal.throwIfAborted(),r.onProgress?.(new mo("tcp:open-connection"));let n;return new Promise((s,o)=>{let c=Date.now(),i=Ao(e,{...this.opts.dialOpts??{},...r});this.log("dialing %a with opts %o",e,i),n=bu.default.connect(i);let a=p=>{this.log.error("dial to %a errored - %e",e,p);let E=i.path??`${i.host??""}:${i.port}`;p.message=`connection error ${E}: ${p.message}`,this.metrics?.events.increment({error:!0}),d(p)},u=()=>{this.log("connection timeout %a",e),this.metrics?.events.increment({timeout:!0});let p=new zt(`Connection timeout after ${Date.now()-c}ms`);n.emit("error",p)},l=()=>{this.log("connection opened %a",e),this.metrics?.events.increment({connect:!0}),d()},f=()=>{this.log("connection aborted %a",e),this.metrics?.events.increment({abort:!0}),d(new cn)},d=p=>{if(n.removeListener("error",a),n.removeListener("timeout",u),n.removeListener("connect",l),r.signal!=null&&r.signal.removeEventListener("abort",f),p!=null){o(p);return}s(n)};n.on("error",a),n.on("timeout",u),n.on("connect",l),r.signal.addEventListener("abort",f)}).catch(s=>{throw n?.destroy(),s})}createListener(e){return new Do({...this.opts.listenOpts??{},...e,maxConnections:this.opts.maxConnections,backlog:this.opts.backlog,closeServerOnMaxConnections:this.opts.closeServerOnMaxConnections,inactivityTimeout:this.opts.inboundSocketInactivityTimeout,metrics:this.components.metrics,logger:this.components.logger})}listenFilter(e){return e.filter(r=>nu.exactMatch(r)||r.toString().startsWith("/unix/"))}dialFilter(e){return this.listenFilter(e)}};function gu(t={}){return e=>new Io(e,t)}var mh=qt("libp2p:daemon-client:dht"),Co=class{client;constructor(e){this.client=e}async put(e,r){if(!(e instanceof Uint8Array))throw new B("invalid key received");if(!(r instanceof Uint8Array))throw new B("value received is not a Uint8Array");let n=await this.client.send({type:z.Type.DHT,dht:{type:Pe.Type.PUT_VALUE,key:e,value:r}}),s=await n.read(L);if(mh("read",s),await n.unwrap().close(),s.type!==L.Type.OK)throw new _r(s.error?.msg??"DHT put failed")}async get(e){if(!(e instanceof Uint8Array))throw new B("invalid key received");let r=await this.client.send({type:z.Type.DHT,dht:{type:Pe.Type.GET_VALUE,key:e}}),n=await r.read(L);if(await r.unwrap().close(),n.type!==L.Type.OK)throw new V(n.error?.msg??"DHT get failed");if(n.dht?.value==null)throw new V("Invalid DHT get response");return n.dht.value}async findPeer(e){if(!Gt(e))throw new B("invalid peer id received");let r=await this.client.send({type:z.Type.DHT,dht:{type:Pe.Type.FIND_PEER,peer:e.toMultihash().bytes}}),n=await r.read(L);if(await r.unwrap().close(),n.type!==L.Type.OK)throw new V(n.error?.msg??"DHT find peer failed");if(n.dht?.peer?.addrs==null)throw new V("Invalid response");return{id:ct($e(n.dht.peer.id)),multiaddrs:n.dht.peer.addrs.map(s=>Fe(s))}}async provide(e){if(e==null||fe.asCID(e)==null)throw new B("invalid cid received");let r=await this.client.send({type:z.Type.DHT,dht:{type:Pe.Type.PROVIDE,cid:e.bytes}}),n=await r.read(L);if(await r.unwrap().close(),n.type!==L.Type.OK)throw new V(n.error?.msg??"DHT provide failed")}async*findProviders(e,r=1){if(e==null||fe.asCID(e)==null)throw new B("invalid cid received");let n=await this.client.send({type:z.Type.DHT,dht:{type:Pe.Type.FIND_PROVIDERS,cid:e.bytes,count:r}}),s=await n.read(L);if(s.type!==L.Type.OK)throw await n.unwrap().close(),new V(s.error?.msg??"DHT find providers failed");for(;;){let o=await n.read(He);if(o.type===He.Type.END){await n.unwrap().close();return}if(o.type===He.Type.VALUE&&o.peer?.addrs!=null)yield{id:ct($e(o.peer.id)),multiaddrs:o.peer.addrs.map(c=>Fe(c))};else throw await n.unwrap().close(),new _r("unexpected message received")}}async*getClosestPeers(e){if(!(e instanceof Uint8Array))throw new B("invalid key received");let r=await this.client.send({type:z.Type.DHT,dht:{type:Pe.Type.GET_CLOSEST_PEERS,key:e}}),n=await r.read(L);if(n.type!==L.Type.OK)throw await r.unwrap().close(),new V(n.error?.msg??"DHT find providers failed");for(;;){let s=await r.read(He);if(s.type===He.Type.END){await r.unwrap().close();return}if(s.type===He.Type.VALUE&&s.value!=null)yield{id:ct($e(s.value)),multiaddrs:[]};else throw await r.unwrap().close(),new kr("unexpected message received")}}async getPublicKey(e){if(!Gt(e))throw new B("invalid peer id received");let r=await this.client.send({type:z.Type.DHT,dht:{type:Pe.Type.GET_PUBLIC_KEY,peer:e.toMultihash().bytes}}),n=await r.read(L);if(await r.unwrap().close(),n.type!==L.Type.OK)throw new V(n.error?.msg??"DHT get public key failed");if(n.dht==null)throw new kr("Invalid response");return n.dht.value}};var Bo=class{client;constructor(e){this.client=e}async getTopics(){let e=await this.client.send({type:z.Type.PUBSUB,pubsub:{type:Xe.Type.GET_TOPICS}}),r=await e.read(L);if(await e.unwrap().close(),r.type!==L.Type.OK)throw new V(r.error?.msg??"Pubsub get topics failed");if(r.pubsub?.topics==null)throw new V("Invalid response");return r.pubsub.topics}async publish(e,r){if(typeof e!="string")throw new B("invalid topic received");if(!(r instanceof Uint8Array))throw new B("data received is not a Uint8Array");let n=await this.client.send({type:z.Type.PUBSUB,pubsub:{type:Xe.Type.PUBLISH,topic:e,data:r}}),s=await n.read(L);if(await n.unwrap().close(),s.type!==L.Type.OK)throw new V(s.error?.msg??"Pubsub publish failed")}async subscribe(e){if(typeof e!="string")throw new B("invalid topic received");let r=await this.client.send({type:z.Type.PUBSUB,pubsub:{type:Xe.Type.SUBSCRIBE,topic:e}}),n=await r.read(L);if(n.type!==L.Type.OK)throw new V(n.error?.msg??"Pubsub publish failed");let s=!0;return{async*messages(){for(;s;)yield await r.read(sn)},async cancel(){s=!1,await r.unwrap().close()}}}async getSubscribers(e){if(typeof e!="string")throw new B("invalid topic received");let r=await this.client.send({type:z.Type.PUBSUB,pubsub:{type:Xe.Type.LIST_PEERS,topic:e}}),n=await r.read(L);if(await r.unwrap().close(),n.type!==L.Type.OK)throw new V(n.error?.msg??"Pubsub get subscribers failed");if(n.pubsub?.topics==null)throw new V("Invalid response");return n.pubsub.peerIDs.map(s=>ct($e(s)))}};var vt=qt("libp2p:daemon-client"),V=class extends Error{constructor(e="Operation failed"){super(e),this.name="OperationFailedError"}},Ps=class{multiaddr;dht;pubsub;tcp;constructor(e){this.multiaddr=e,this.tcp=gu()({logger:Bc()}),this.dht=new Co(this),this.pubsub=new Bo(this)}async connectDaemon(e){return this.tcp.dial(this.multiaddr,{upgrader:new Lr,signal:e??AbortSignal.timeout(1e4)})}async send(e){let r=await this.connectDaemon(),n=e.pubsub?.type??e.dht?.type??e.peerStore?.type??"";vt("send",e.type,n);let s=ks(r);return await s.write(e,z),s}async connect(e,r){if(!Gt(e))throw new B("invalid peer id received");if(!Array.isArray(r))throw new B("addrs received are not in an array");r.forEach(o=>{if(!ao(o))throw new B("received an address that is not a multiaddr")});let n=await this.send({type:z.Type.CONNECT,connect:{peer:e.toMultihash().bytes,addrs:r.map(o=>o.bytes)}}),s=await n.read(L);if(vt("%s response %s",z.Type.CONNECT,s.type),s.type!==L.Type.OK){let o=s.error??{msg:"unspecified"};throw new V(o.msg??"unspecified")}await n.unwrap().close()}async identify(){let e=await this.send({type:z.Type.IDENTIFY}),r=await e.read(L);if(vt("%s response %s",z.Type.IDENTIFY,r.type),r.type!==L.Type.OK)throw new V(r.error?.msg??"Identify failed");if(r.identify?.addrs==null)throw new V("Invalid response");let n=ct($e(r.identify?.id)),s=r.identify.addrs.map(o=>Fe(o));return await e.unwrap().close(),{peerId:n,addrs:s}}async listPeers(){let e=await this.send({type:z.Type.LIST_PEERS}),r=await e.read(L);if(vt("%s response %s",z.Type.LIST_PEERS,r.type),r.type!==L.Type.OK)throw new V(r.error?.msg??"List peers failed");return await e.unwrap().close(),r.peers.map(n=>ct($e(n.id)))}async openStream(e,r){if(!Gt(e))throw new B("invalid peer id received");if(typeof r!="string")throw new B("invalid protocol received");let n=await this.send({type:z.Type.STREAM_OPEN,streamOpen:{peer:e.toMultihash().bytes,proto:[r]}}),s=await n.read(L);if(vt("%s response %s",z.Type.STREAM_OPEN,s.type),s.type!==L.Type.OK){let o=new V(s.error?.msg??"Open stream failed");throw n.unwrap().abort(o),o}return n.unwrap()}async registerStreamHandler(e,r){if(typeof e!="string")throw new B("invalid protocol received");let n=this.tcp.createListener({upgrader:new Lr(i=>{this.onConnection(e,n,r,i)})});await n.listen(Fe("/ip4/127.0.0.1/tcp/0"));let s=n.getAddrs()[0];if(s==null)throw new V("Could not listen on port");let o=await this.send({type:z.Type.STREAM_HANDLER,streamHandler:{addr:s.bytes,proto:[e]}}),c=await o.read(L);if(vt("%s response %s",z.Type.STREAM_HANDLER,c.type),await o.unwrap().close(),c.type!==L.Type.OK)throw new V(c.error?.msg??"Register stream handler failed")}onConnection(e,r,n,s){Promise.resolve().then(async()=>{let o=ks(s).pb(It);if((await o.read()).proto!==e)throw new V("Incorrect protocol");await n(o.unwrap().unwrap())}).catch(o=>{s.abort(o)}).finally(()=>{s.close().catch(o=>{vt.error("error closing connection - %e",o)}),r.close().catch(o=>{vt.error("error closing listener - %e",o)})})}};function yh(t){return new Ps(t)}return Iu(bh);})();
16
+ ${e}[Error list was empty]`,r.trim()}return Dc(t,e)}Le.formatters.e=t=>t==null?"undefined":Cc(t);function pf(t){let e=()=>{};return e.enabled=!1,e.color="",e.diff=0,e.log=()=>{},e.namespace=t,e.destroy=()=>!0,e.extend=()=>e,e.useColors=()=>!1,e}function Bc(t){return{forComponent(e){return qt(e,t)}}}function qt(t,e){let r=pf(`${t}:trace`);return Le.enabled(`${t}:trace`)&&Le.names.map(n=>n.toString()).find(n=>n.includes(":trace"))!=null&&(r=Le(`${t}:trace`,e)),Object.assign(Le(t,e),{error:Le(`${t}:error`,e),trace:r,newScope:n=>qt(`${t}:${n}`,e)})}function Ic(t){if(t!=null&&(t=t.trim(),t.length!==0))return t}function De(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}async function Lc(t,e,r,n){let s=await crypto.subtle.importKey("jwk",t,{name:"ECDSA",namedCurve:t.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let o=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},s,pt(e),pt(r.subarray()));return n?.signal?.throwIfAborted(),o}var Oc=le("node:buffer");function qe(t,e){return ht(Oc.Buffer.concat(t,e))}var _c=Symbol.for("@achingbrain/uint8arraylist");function kc(t,e){if(e==null||e<0)throw new RangeError("index is out of bounds");let r=0;for(let n of t){let s=r+n.byteLength;if(e<s)return{buf:n,index:e-r};r=s}throw new RangeError("index is out of bounds")}function vn(t){return!!t?.[_c]}var oe=class t{bufs;length;[_c]=!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 r=0;for(let n of e)if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.push(n);else if(vn(n)){r+=n.byteLength;for(let s of n.bufs)this.bufs.push(s)}else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}prepend(...e){this.prependAll(e)}prependAll(e){let r=0;for(let n of e.reverse())if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.unshift(n);else if(vn(n))r+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}get(e){let r=kc(this.bufs,e);return r.buf[r.index]}set(e,r){let n=kc(this.bufs,e);n.buf[n.index]=r}write(e,r=0){if(e instanceof Uint8Array)for(let n=0;n<e.length;n++)this.set(r+n,e[n]);else if(vn(e))for(let n=0;n<e.length;n++)this.set(r+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,r){let{bufs:n,length:s}=this._subList(e,r);return qe(n,s)}subarray(e,r){let{bufs:n,length:s}=this._subList(e,r);return n.length===1?n[0]:qe(n,s)}sublist(e,r){let{bufs:n,length:s}=this._subList(e,r),o=new t;return o.length=s,o.bufs=n,o}_subList(e,r){if(e=e??0,r=r??this.length,e<0&&(e=this.length+e),r<0&&(r=this.length+r),e<0||r>this.length)throw new RangeError("index is out of bounds");if(e===r)return{bufs:[],length:0};if(e===0&&r===this.length)return{bufs:[...this.bufs],length:this.length};let n=[],s=0;for(let o=0;o<this.bufs.length;o++){let c=this.bufs[o],i=s,a=i+c.byteLength;if(s=a,e>=a)continue;let u=e>=i&&e<a,l=r>i&&r<=a;if(u&&l){if(e===i&&r===a){n.push(c);break}let f=e-i;n.push(c.subarray(f,f+(r-e)));break}if(u){if(e===0){n.push(c);continue}n.push(c.subarray(e-i));continue}if(l){if(r===a){n.push(c);break}n.push(c.subarray(0,r-i));break}n.push(c)}return{bufs:n,length:r-e}}indexOf(e,r=0){if(!vn(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(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),e.length===0)return r>this.length?this.length:r;let s=n.byteLength;if(s===0)throw new TypeError("search must be at least 1 byte long");let o=256,c=new Int32Array(o);for(let f=0;f<o;f++)c[f]=-1;for(let f=0;f<s;f++)c[n[f]]=f;let i=c,a=this.byteLength-n.byteLength,u=n.byteLength-1,l;for(let f=r;f<=a;f+=l){l=0;for(let d=u;d>=0;d--){let p=this.get(f+d);if(n[d]!==p){l=Math.max(1,d-i[p]);break}}if(l===0)return f}return-1}getInt8(e){let r=this.subarray(e,e+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(e,r){let n=Ce(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,r),this.write(n,e)}getInt16(e,r){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,r)}setInt16(e,r,n){let s=fe(2);new DataView(s.buffer,s.byteOffset,s.byteLength).setInt16(0,r,n),this.write(s,e)}getInt32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,r)}setInt32(e,r,n){let s=fe(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setInt32(0,r,n),this.write(s,e)}getBigInt64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,r)}setBigInt64(e,r,n){let s=fe(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setBigInt64(0,r,n),this.write(s,e)}getUint8(e){let r=this.subarray(e,e+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint8(0)}setUint8(e,r){let n=Ce(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,r),this.write(n,e)}getUint16(e,r){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,r)}setUint16(e,r,n){let s=fe(2);new DataView(s.buffer,s.byteOffset,s.byteLength).setUint16(0,r,n),this.write(s,e)}getUint32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,r)}setUint32(e,r,n){let s=fe(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setUint32(0,r,n),this.write(s,e)}getBigUint64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,r)}setBigUint64(e,r,n){let s=fe(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setBigUint64(0,r,n),this.write(s,e)}getFloat32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,r)}setFloat32(e,r,n){let s=fe(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setFloat32(0,r,n),this.write(s,e)}getFloat64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,r)}setFloat64(e,r,n){let s=fe(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setFloat64(0,r,n),this.write(s,e)}equals(e){if(e==null||!(e instanceof t)||e.bufs.length!==this.bufs.length)return!1;for(let r=0;r<this.bufs.length;r++)if(!De(this.bufs[r],e.bufs[r]))return!1;return!0}static fromUint8Arrays(e,r){let n=new t;return n.bufs=e,r==null&&(r=e.reduce((s,o)=>s+o.byteLength,0)),n.length=r,n}};var Pc=le("node:buffer");function ue(t,e="utf8"){let r=tn[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return e==="utf8"||e==="utf-8"?Pc.Buffer.from(t.buffer,t.byteOffset,t.byteLength).toString("utf8"):r.encoder.encode(t).substring(1)}var mf=parseInt("11111",2),Ei=parseInt("10000000",2),yf=parseInt("01111111",2),Rc={0:Rr,1:Rr,2:bf,3:xf,4:Ef,5:wf,6:gf,16:Rr,22:Rr,48:Rr};function vi(t,e={offset:0}){let r=t[e.offset]&mf;if(e.offset++,Rc[r]!=null)return Rc[r](t,e);throw new Error("No decoder for tag "+r)}function Nr(t,e){let r=0;if((t[e.offset]&Ei)===Ei){let n=t[e.offset]&yf,s="0x";e.offset++;for(let o=0;o<n;o++,e.offset++){if(e.offset>=t.byteLength)throw new Error("invalid DER element length");s+=t[e.offset].toString(16).padStart(2,"0")}r=parseInt(s,16)}else r=t[e.offset],e.offset++;if(!Number.isInteger(r)||r<0||r>t.byteLength-e.offset)throw new Error("invalid DER element length");return r}function Rr(t,e){Nr(t,e);let r=[];for(;!(e.offset>=t.byteLength);){let n=vi(t,e);if(n===null)break;r.push(n)}return r}function bf(t,e){let r=Nr(t,e),n=e.offset,s=e.offset+r,o=[];for(let c=n;c<s;c++)c===n&&t[c]===0||o.push(t[c]);return e.offset+=r,Uint8Array.from(o)}function gf(t,e){let r=Nr(t,e),n=e.offset+r,s=t[e.offset];e.offset++;let o=0,c=0;s<40?(o=0,c=s):s<80?(o=1,c=s-40):(o=2,c=s-80);let i=`${o}.${c}`,a=[];for(;e.offset<n;){let u=t[e.offset];if(e.offset++,a.push(u&127),u<128){a.reverse();let l=0;for(let f=0;f<a.length;f++)l+=a[f]<<f*7;i+=`.${l}`,a=[]}}return i}function wf(t,e){return e.offset++,null}function xf(t,e){let r=Nr(t,e),n=t[e.offset];e.offset++;let s=t.subarray(e.offset,e.offset+r-1);if(e.offset+=r,n!==0)throw new Error("Unused bits in bit string is unimplemented");return s}function Ef(t,e){let r=Nr(t,e),n=t.subarray(e.offset,e.offset+r);return e.offset+=r,n}function vf(t){let e=t.toString(16);e.length%2===1&&(e="0"+e);let r=new oe;for(let n=0;n<e.length;n+=2)r.append(Uint8Array.from([parseInt(`${e[n]}${e[n+1]}`,16)]));return r}function Si(t){if(t.byteLength<128)return Uint8Array.from([t.byteLength]);let e=vf(t.byteLength);return new oe(Uint8Array.from([e.byteLength|Ei]),e)}function Nc(t){let e=new oe,r=128;return(t.subarray()[0]&r)===r&&e.append(Uint8Array.from([0])),e.append(t),new oe(Uint8Array.from([2]),Si(e),e)}function Uc(t){let e=Uint8Array.from([0]),r=new oe(e,t);return new oe(Uint8Array.from([3]),Si(r),r)}function Sn(t,e=48){let r=new oe;for(let n of t)r.append(n);return new oe(Uint8Array.from([e]),Si(r),r)}var Sf=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Tf=Uint8Array.from([6,5,43,129,4,0,34]),Af=Uint8Array.from([6,5,43,129,4,0,35]),Df={ext:!0,kty:"EC",crv:"P-256"},If={ext:!0,kty:"EC",crv:"P-384"},Cf={ext:!0,kty:"EC",crv:"P-521"},Ti=32,Ai=48,Di=66;function Mc(t){let e=vi(t);return Fc(e)}function Fc(t){let e=t[1][1][0],r=1,n,s;if(e.byteLength===Ti*2+1)return n=ue(e.subarray(r,r+Ti),"base64url"),s=ue(e.subarray(r+Ti),"base64url"),new Zt({...Df,key_ops:["verify"],x:n,y:s});if(e.byteLength===Ai*2+1)return n=ue(e.subarray(r,r+Ai),"base64url"),s=ue(e.subarray(r+Ai),"base64url"),new Zt({...If,key_ops:["verify"],x:n,y:s});if(e.byteLength===Di*2+1)return n=ue(e.subarray(r,r+Di),"base64url"),s=ue(e.subarray(r+Di),"base64url"),new Zt({...Cf,key_ops:["verify"],x:n,y:s});throw new B(`coordinates were wrong length, got ${e.byteLength}, expected 65, 97 or 133`)}function Kc(t){return Sn([Nc(Uint8Array.from([1])),Sn([Bf(t.crv)],160),Sn([Uc(new oe(Uint8Array.from([4]),Ae(t.x??"","base64url"),Ae(t.y??"","base64url")))],161)]).subarray()}function Bf(t){if(t==="P-256")return Sf;if(t==="P-384")return Tf;if(t==="P-521")return Af;throw new B(`Invalid curve ${t}`)}var Zt=class{type="ECDSA";jwk;_raw;constructor(e){this.jwk=e}get raw(){return this._raw==null&&(this._raw=Kc(this.jwk)),this._raw}toMultihash(){return Ge.digest(jt(this))}toCID(){return de.createV1(114,this.toMultihash())}toString(){return ae.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:De(this.raw,e.raw)}async verify(e,r,n){return Lc(this.jwk,r,e,n)}};var $n=_e(le("crypto"),1);var Lf=t=>t/2**32|0,Of=t=>t>>>0;function $c(t,e,r,n){let s=Lf(r),o=Of(r);t.setUint32(e,n?o:s,n),t.setUint32(e+4,n?s:o,n)}function Tn(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in t&&t.BYTES_PER_ELEMENT===1}var Ii=t=>t?`"${t}" `:"";function nt(t,e=""){if(typeof t!="number")throw new TypeError(Ii(e)+"expected number, got "+typeof t);if(!Number.isSafeInteger(t)||t<0)throw new RangeError(Ii(e)+"expected integer >= 0, got "+t);return t}function Qe(t,e,r=""){if(Tn(t)&&(e===void 0||t.length===e))return t;e!==void 0&&nt(e,"length");let n=Tn(t),s=e!==void 0?` of length ${e}`:"",o=n?`length=${t.length}`:`type=${typeof t}`,c=Ii(r)+"expected Uint8Array"+s+", got "+o;throw n?new RangeError(c):new TypeError(c)}function An(t){if(typeof t!="function"||typeof t.create!="function")throw new TypeError("expected hash wrapped by utils.createHasher");if(nt(t.outputLen),nt(t.blockLen),t.outputLen<1||t.blockLen<1)throw new Error("hash blockLen / outputLen must be >= 1")}var kf=(t,e)=>{if(t===null||typeof t!="object"||Array.isArray(t))throw new TypeError((e==="object"?"":`"${e}" `)+"expected object, got type="+typeof t)},Hc=(t,e)=>{kf(t,e);let r=Object.getPrototypeOf(t);if(r!==Object.prototype&&r!==null)throw new TypeError(`"${e}" expected plain object`);if(Object.hasOwn(t,"__proto__"))throw new TypeError(`"${e}.__proto__" is not allowed`)};function Xt(t,e=!0){if(t.destroyed)throw new Error("hash was destroyed");if(e&&t.finished)throw new Error("digest() was already called")}function Dn(t,e){Qe(t,void 0,"output");let r=e.outputLen;if(!(t.length>=r))throw new RangeError('"output" expected length >= '+r)}function Ur(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function In(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function Ze(t,e){return t<<32-e|t>>>e}var Vc=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",_f=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function Cn(t){if(Qe(t),Vc)return t.toHex();let e="";for(let r=0;r<t.length;r++)e+=_f[t[r]];return e}function zc(t){return t>=48&&t<=57?t-48:t>=65&&t<=70?t-55:t>=97&&t<=102?t-87:void 0}function Ci(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);if(Vc)try{return Uint8Array.fromHex(t)}catch(s){throw s instanceof SyntaxError?new RangeError(s.message):s}let e=t.length,r=e/2;if(e%2)throw new RangeError("hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(r);for(let s=0,o=0;s<r;s++,o+=2){let c=zc(t.charCodeAt(o)),i=zc(t.charCodeAt(o+1));if(c===void 0||i===void 0){let a=t[o]+t[o+1];throw new RangeError('hex string expected, got non-hex character "'+a+'" at index '+o)}n[s]=c*16+i}return n}function Gc(...t){let e=0;for(let n=0;n<t.length;n++){let s=t[n];Qe(s),e+=s.length}let r=new Uint8Array(e);for(let n=0,s=0;n<t.length;n++){let o=t[n];r.set(o,s),s+=o.length}return r}function Pf(t,e,r="opts"){return Hc(t,"defaults"),e!==void 0&&Hc(e,r),Object.assign(Object.create(null),t,e)}function Wc(t,e={}){if(typeof t!="function")throw new TypeError('"hashCons" expected function, got type='+typeof t);e=Pf({},e,"info");let r=(s,o)=>t(o).update(s).digest(),n=t(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.canXOF=n.canXOF,r.create=s=>t(s),Object.assign(r,e),Object.freeze(r)}function Yc(t=32){nt(t,"bytesLength");let e=typeof globalThis=="object"?globalThis.crypto:null;if(typeof e?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");if(t>65536)throw new RangeError(`"bytesLength" expected <= 65536, got ${t}`);return e.getRandomValues(new Uint8Array(t))}var qc=t=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,t])});function Zc(t,e,r){return t&e^~t&r}function jc(t,e,r){return t&e^t&r^e&r}var Bn=class{blockLen;outputLen;canXOF=!1;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(e,r,n,s){this.blockLen=e,this.outputLen=r,this.padOffset=n,this.isLE=s,this.buffer=new Uint8Array(e),this.view=In(this.buffer)}update(e){Xt(this),Qe(e);let{view:r,buffer:n,blockLen:s}=this,o=e.length,c=!1;for(let i=0;i<o;){let a=Math.min(s-this.pos,o-i);if(a===s){let u=In(e);for(;s<=o-i;i+=s)this.process(u,i);c=!0;continue}n.set(i===0&&a===o?e:e.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===s&&(this.process(r,0),this.pos=0,c=!0)}return this.length+=e.length,c&&this.roundClean(),this}digestInto(e){Xt(this),Dn(e,this),this.finished=!0;let{buffer:r,view:n,blockLen:s,isLE:o}=this,{pos:c}=this;r[c++]=128,r.fill(0,c),this.padOffset>s-c&&(this.process(n,0),r.fill(0)),$c(n,s-8,this.length*8,o),this.process(n,0),this.roundClean();let i=e===r?n:In(e),a=this.outputLen,u=a/4,l=this.get();if(a%4||u>l.length)throw new Error("invalid outputLen");for(let f=0;f<u;f++)i.setUint32(4*f,l[f],o)}digest(){let{buffer:e,outputLen:r}=this;this.digestInto(e);let n=e.slice(0,r);return this.destroy(),n}_cloneIntoMeta(e){let{buffer:r,length:n,finished:s,destroyed:o,pos:c}=this;return e.destroyed=o,e.finished=s,e.length=n,e.pos=c,c&&e.buffer.set(r),e}clone(){return this._cloneInto()}},Xc=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var Rf=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),gt=new Uint32Array(64),Bi=class extends Bn{A=0;B=0;C=0;D=0;E=0;F=0;G=0;H=0;constructor(e,r){super(64,e,8,!1),this.A=r[0]|0,this.B=r[1]|0,this.C=r[2]|0,this.D=r[3]|0,this.E=r[4]|0,this.F=r[5]|0,this.G=r[6]|0,this.H=r[7]|0}get(){let{A:e,B:r,C:n,D:s,E:o,F:c,G:i,H:a}=this;return[e,r,n,s,o,c,i,a]}set(e,r,n,s,o,c,i,a){this.A=e|0,this.B=r|0,this.C=n|0,this.D=s|0,this.E=o|0,this.F=c|0,this.G=i|0,this.H=a|0}_cloneInto(e){return(e||=new this.constructor).set(...this.get()),this._cloneIntoMeta(e)}process(e,r){for(let f=0;f<16;f++,r+=4)gt[f]=e.getUint32(r,!1);for(let f=16;f<64;f++){let d=gt[f-15],p=gt[f-2],x=Ze(d,7)^Ze(d,18)^d>>>3,D=Ze(p,17)^Ze(p,19)^p>>>10;gt[f]=D+gt[f-7]+x+gt[f-16]|0}let{A:n,B:s,C:o,D:c,E:i,F:a,G:u,H:l}=this;for(let f=0;f<64;f++){let d=Ze(i,6)^Ze(i,11)^Ze(i,25),p=l+d+Zc(i,a,u)+Rf[f]+gt[f]|0,D=(Ze(n,2)^Ze(n,13)^Ze(n,22))+jc(n,s,o)|0;l=u,u=a,a=i,i=c+p|0,c=o,o=s,s=n,n=p+D|0}n=n+this.A|0,s=s+this.B|0,o=o+this.C|0,c=c+this.D|0,i=i+this.E|0,a=a+this.F|0,u=u+this.G|0,l=l+this.H|0,this.set(n,s,o,c,i,a,u,l)}roundClean(){Ur(gt)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),Ur(this.buffer)}},Li=class extends Bi{constructor(){super(32,Xc)}};var Qc=Wc(()=>new Li,qc(1));function On(t,e,r=()=>{}){if(!Array.isArray(t))throw new TypeError(`"${e}" expected array, got type=${typeof t}`);for(let n=0;n<t.length;n++)r(t[n],`${e}[${n}]`);return t}var he=(t,e,r)=>Qe(t,e,r),Oi=nt;function ea(t,e=""){if(typeof t!="string"){let r=e&&`"${e}" `;throw new TypeError(r+"expected string, got type="+typeof t)}return t}function wt(t,e="object"){if(t===null||typeof t!="object"||Array.isArray(t))throw new TypeError(e==="object"?"expected valid options object":`"${e}" expected object, got type=${typeof t}`);return t}function Ot(t,e){if(typeof t!="function")throw new TypeError(`"${e}" is invalid: expected function, got ${typeof t}`);return t}var ki=Cn,ot=(...t)=>Gc(...t),kn=t=>Ci(t),Qt=Tn,_n=t=>Yc(t),Ln=BigInt(0),Jc=BigInt(1),Nf=t=>t?`"${t}" `:"";function Je(t,e=""){if(typeof t!="boolean")throw new TypeError(Nf(e)+"expected boolean, got type="+typeof t);return t}function Pn(t){if(typeof t=="bigint"){if(!xt(t))throw new RangeError("positive bigint expected, got "+t)}else Oi(t);return t}function kt(t,e=""){if(typeof t!="number"){let r=e&&`"${e}" `;throw new TypeError(r+"expected number, got type="+typeof t)}if(!Number.isSafeInteger(t)){let r=e&&`"${e}" `;throw new RangeError(r+"expected safe integer, got "+t)}}function Mr(t){let e=Pn(t).toString(16);return e.length&1?"0"+e:e}function ta(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);return t===""?Ln:BigInt("0x"+t)}function et(t){return ta(Cn(t))}function _i(t){return ta(Cn(Uf(Qe(t)).reverse()))}function Rn(t,e){if(nt(e),e===0)throw new Error("zero output length is invalid");t=Pn(t);let r=e*2,n=t.toString(16);if(n.length>r)throw new RangeError("number is too large");return Ci(n.padStart(r,"0"))}function Pi(t,e){return Rn(t,e).reverse()}function Uf(t){return Uint8Array.from(he(t))}function xt(t){return typeof t=="bigint"&&Ln<=t}function Ri(t,e,r){return xt(t)&&xt(e)&&xt(r)&&e<=t&&t<r}function Ni(t,e,r,n){if(!Ri(e,r,n))throw new RangeError("expected valid "+t+": "+r+" <= n < "+n+", got "+e)}function Jt(t){if(t<Ln)throw new Error("expected non-negative bigint, got "+t);return t===Ln?0:t.toString(2).length}var Fr=t=>(kt(t,"n"),(Jc<<BigInt(t))-Jc);function ra(t,e,r){if(nt(t,"hashLen"),nt(e,"qByteLen"),typeof r!="function")throw new TypeError("hmacFn must be a function");let n=b=>new Uint8Array(b),s=Uint8Array.of(),o=Uint8Array.of(0),c=Uint8Array.of(1),i=1e3,a=n(t),u=n(t),l=0,f=()=>{a.fill(1),u.fill(0),l=0},d=(...b)=>r(u,ot(a,...b)),p=(b=s)=>{u=d(o,b),a=d(),b.length!==0&&(u=d(c,b),a=d())},x=()=>{if(l++>=i)throw new Error("drbg: tried max amount of iterations");let b=0,y=[];for(;b<e;){a=d();let T=a.slice();y.push(T),b+=a.length}return ot(...y)};return(b,y)=>{f(),p(b);let T;for(;(T=y(x()))===void 0;)p();return f(),T}}function Et(t,e={},r={},n="object"){wt(t,n),wt(e,"fields"),wt(r,"optFields");function s(c,i,a){let u=n==="object"?`param "${String(c)}"`:`"${n}.${String(c)}"`,l=t[c];if(!Object.hasOwn(t,c)&&(a?l!==void 0:i!=="function"))throw new TypeError(`${u} is invalid: expected own property`);if(a&&l===void 0)return;let f=typeof l;if(f!==i||l===null)throw new TypeError(`${u} is invalid: expected ${i}, got ${f}`)}let o=(c,i)=>Object.entries(c).forEach(([a,u])=>s(a,u,i));o(e,!1),o(r,!0)}var pe=BigInt(0),K=BigInt(1),vt=BigInt(2),sa=BigInt(3),Ui=BigInt(4),ca=BigInt(5),Mf=BigInt(7),aa=BigInt(8),Ff=BigInt(9),Kf=BigInt(15),ua=BigInt(16),$f=BigInt("0x10000000000000000");function Ne(t,e){if(e<=pe)throw new Error("mod: expected positive modulus, got "+e);let r=t%e;return r>=pe?r:e+r}function la(t,e,r){if(r<=K)throw new Error("pow: expected modulus > 1, got "+r);if(typeof e!="bigint")throw new TypeError("invalid exponent: expected bigint, got "+typeof e);if(e<pe)throw new Error("invalid exponent, negatives unsupported");if(e===pe)return K;if(e===K)return t;let n=t%r;if(n<pe&&(n+=r),e<$f){let i=K;for(;e>pe;)e&K&&(i=i*n%r),n=n*n%r,e>>=K;return i}let s=[];for(;e>pe;)s.push(Number(e&Kf)),e>>=Ui;let o=new Array(16);o[0]=K,o[1]=n;for(let i=2;i<16;i++)o[i]=o[i-1]*n%r;let c=o[s[s.length-1]];for(let i=s.length-2;i>=0;i--){c=c*c%r,c=c*c%r,c=c*c%r,c=c*c%r;let a=s[i];a!==0&&(c=c*o[a]%r)}return c}function Ue(t,e,r){if(r<=K)throw new Error("pow2: expected modulus > 1, got "+r);if(e<pe)throw new Error("pow2: expected non-negative exponent, got "+e);let n=t;for(;e-- >pe;)n*=n,n%=r;return n}function na(t,e){if(t===pe)throw new Error("invert: expected non-zero number");if(e<=K)throw new Error("invert: expected modulus > 1, got "+e);let r=Ne(t,e),n=e,s=pe,o=K;for(;r!==pe;){let i=n/r,a=n-r*i,u=s-o*i;n=r,r=a,s=o,o=u}if(n!==K)throw new Error("invert: does not exist");return Ne(s,e)}function fa(t,e){if(e<=K)throw new Error("invertCt: expected prime modulus > 1, got "+e);let r=Ne(t,e);if(r===pe)throw new Error("invertCt: expected non-zero number");let n=la(r,e-vt,e);if(Ne(r*n,e)!==K)throw new Error("invertCt: does not exist");return n}function Mi(t,e,r){let n=t;if(!n.eql(n.sqr(e),r))throw new Error("Cannot find square root")}function Fi(t,e){if((t&K)===pe)throw new Error(e+": expected odd modulus, got "+t)}function da(t,e){let r=t,n=(r.ORDER+K)/Ui,s=r.pow(e,n);return Mi(r,s,e),s}function Hf(t,e){let r=t,n=(r.ORDER-ca)/aa,s=r.mul(e,vt),o=r.pow(s,n),c=r.mul(e,o),i=r.mul(r.mul(c,vt),o),a=r.mul(c,r.sub(i,r.ONE));return Mi(r,a,e),a}function zf(t){let e=tr(t),r=ha(t),n=r(e,e.neg(e.ONE)),s=r(e,n),o=r(e,e.neg(n)),c=(t+Mf)/ua;return((i,a)=>{let u=i,l=u.pow(a,c),f=u.mul(l,n),d=u.mul(l,s),p=u.mul(l,o),x=u.eql(u.sqr(f),a),D=u.eql(u.sqr(d),a);l=u.cmov(l,f,x),f=u.cmov(p,d,D);let b=u.eql(u.sqr(f),a),y=u.cmov(l,f,b);return Mi(u,y,a),y})}function ha(t){if(t<sa)throw new Error("sqrt is not defined for small field");Fi(t,"tonelliShanks");let e=t-K,r=0;for(;e%vt===pe;)e/=vt,r++;let n=vt,s=tr(t);for(;oa(s,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return da;let o=s.pow(n,e),c=(e+K)/vt;return function(a,u){let l=a;if(l.is0(u))return u;if(oa(l,u)!==1)throw new Error("Cannot find square root");let f=r,d=l.mul(l.ONE,o),p=l.pow(u,e),x=l.pow(u,c);for(;!l.eql(p,l.ONE);){if(l.is0(p))throw new Error("Cannot find square root: probably non-prime P");let D=1,b=l.sqr(p);for(;!l.eql(b,l.ONE);)if(D++,b=l.sqr(b),D===f)throw new Error("Cannot find square root");let y=K<<BigInt(f-D-1),T=l.pow(d,y);f=D,d=l.sqr(T),p=l.mul(p,d),x=l.mul(x,T)}return x}}function Vf(t){return Fi(t,"Fp.sqrt"),t%Ui===sa?da:t%aa===ca?Hf:t%ua===Ff?zf(t):ha(t)}var Gf=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function er(t){if(wt(t,"field"),typeof t.ORDER!="bigint")throw new TypeError('param "ORDER" is invalid: expected bigint, got '+typeof t.ORDER);kt(t.BYTES,"BYTES"),kt(t.BITS,"BITS");for(let e of Gf)Ot(t[e],"field."+e);if(t.BYTES<1||t.BITS<1)throw new Error("invalid field: expected BYTES/BITS > 0");if(t.ORDER<=K)throw new Error("invalid field: expected ORDER > 1, got "+t.ORDER);return t}function Ki(t,e,r=!1){er(t),On(e,"nums"),Je(r,"passZero");let n=t,s=new Array(e.length).fill(r?n.ZERO:void 0),o=e.reduce((i,a,u)=>n.is0(a)?i:(s[u]=i,n.mul(i,a)),n.ONE),c=n.inv(o);return e.reduceRight((i,a,u)=>n.is0(a)?i:(s[u]=n.mul(i,s[u]),n.mul(i,a)),c),s}function oa(t,e){er(t);let r=t;Fi(r.ORDER,"FpLegendre");let n=(r.ORDER-K)/vt,s=r.pow(e,n),o=r.eql(s,r.ONE),c=r.eql(s,r.ZERO),i=r.eql(s,r.neg(r.ONE));if(!o&&!c&&!i)throw new Error("invalid Legendre symbol result");return o?1:c?0:-1}function Wf(t,e){if(e!==void 0&&Oi(e),t<=pe)throw new Error("invalid n length: expected positive n, got "+t);if(e!==void 0&&e<1)throw new Error("invalid n length: expected positive bit length, got "+e);let r=Jt(t);if(e!==void 0&&e<r)throw new Error(`invalid n length: expected nBitLength (${e}) >= bitLen(n) (${r})`);let n=e!==void 0?e:r,s=Math.ceil(n/8);return{nBitLength:n,nByteLength:s}}var ia=new WeakMap,Nn=class{ORDER;BITS;BYTES;isLE;ZERO=pe;ONE=K;_lengths;_mod;constructor(e,r={}){if(e<=K)throw new Error("invalid field: expected ORDER > 1, got "+e);let n;this.isLE=!1,r!=null&&typeof r=="object"&&(typeof r.BITS=="number"&&(n=r.BITS),typeof r.sqrt=="function"&&Object.defineProperty(this,"sqrt",{value:r.sqrt,enumerable:!0}),typeof r.isLE=="boolean"&&(this.isLE=r.isLE),r.allowedLengths&&(this._lengths=Object.freeze(r.allowedLengths.slice())),typeof r.modFromBytes=="boolean"&&(this._mod=r.modFromBytes));let{nBitLength:s,nByteLength:o}=Wf(e,n);if(o>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=e,this.BITS=s,this.BYTES=o,Object.freeze(this)}create(e){return Ne(e,this.ORDER)}isValid(e){if(typeof e!="bigint")throw new TypeError("invalid field element: expected bigint, got "+typeof e);return pe<=e&&e<this.ORDER}is0(e){return e===pe}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}isOdd(e){return(e&K)===K}neg(e){return Ne(-e,this.ORDER)}eql(e,r){return e===r}sqr(e){return Ne(e*e,this.ORDER)}add(e,r){return Ne(e+r,this.ORDER)}sub(e,r){return Ne(e-r,this.ORDER)}mul(e,r){return Ne(e*r,this.ORDER)}pow(e,r){return la(e,r,this.ORDER)}div(e,r){return Ne(e*na(r,this.ORDER),this.ORDER)}sqrN(e){return e*e}addN(e,r){return e+r}subN(e,r){return e-r}mulN(e,r){return e*r}inv(e){return na(e,this.ORDER)}sqrt(e){let r=ia.get(this);return r||ia.set(this,r=Vf(this.ORDER)),r(this,e)}toBytes(e){return this.isLE?Pi(e,this.BYTES):Rn(e,this.BYTES)}fromBytes(e,r=!1){he(e);let{_lengths:n,BYTES:s,isLE:o,ORDER:c,_mod:i}=this;if(n){if(e.length<1||!n.includes(e.length)||e.length>s)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+e.length);let u=new Uint8Array(s);u.set(e,o?0:u.length-e.length),e=u}if(e.length!==s)throw new Error("Field.fromBytes: expected "+s+" bytes, got "+e.length);let a=o?_i(e):et(e);if(i&&(a=Ne(a,c)),!r&&!this.isValid(a))throw new Error("invalid field element: outside of range 0..ORDER");return a}invertBatch(e){return Ki(this,e,!0)}cmov(e,r,n){return Je(n,"condition"),n?r:e}};function tr(t,e={}){return Object.freeze(Nn.prototype),new Nn(t,e)}function pa(t){if(typeof t!="bigint")throw new Error("field order must be bigint");if(t<=K)throw new Error("field order must be greater than 1");let e=Jt(t-K);return Math.ceil(e/8)}function Un(t){let e=pa(t);return e+Math.ceil(e/2)}function Mn(t,e,r=!1){he(t);let n=t.length,s=pa(e),o=Math.max(Un(e),16);if(n<o||n>1024)throw new Error("expected "+o+"-1024 bytes of input, got "+n);let c=r?_i(t):et(t),i=Ne(c,e-K)+K;return r?Pi(i,s):Rn(i,s)}var zi=BigInt(0),Kr=BigInt(1),Yf=BigInt(4),$i=16,ma=128,qf=5,ya=2**31;function rr(t){let e=t;if(typeof e!="function")throw new TypeError('"Point" expected constructor, got type='+typeof t);Ot(e.fromAffine,"Point.fromAffine"),Ot(e.fromBytes,"Point.fromBytes"),Ot(e.fromHex,"Point.fromHex"),wt(e.BASE,"Point.BASE"),wt(e.ZERO,"Point.ZERO"),er(e.Fp),er(e.Fn)}function ga(t,e){rr(t),wa(e,t);let r=Ki(t.Fp,e.map(n=>n.Z));return e.map((n,s)=>t.fromAffine(n.toAffine(r[s])))}function Zf(t,e,r=1){if(!Number.isSafeInteger(t)||t<r||t>e)throw new Error("invalid window size, expected ["+r+".."+e+"], got W="+t)}function jf(t,e){let r=t*(4*e+128);if(r>ya)throw new Error("invalid window size: table would need ~"+Math.ceil(r/2**20)+" MiB, max "+ya/2**20+" MiB")}function Vi(t,e){if(t!==void 0){Ot(t,"randomBytes");try{let r=t(e);if(!Qt(r)||r.length!==e)return}catch{return}return t}}function wa(t,e){On(t,"points"),t.forEach((r,n)=>{if(!(r instanceof e))throw new Error("invalid point at index "+n)})}function Xf(t,e,r){if(!Array.isArray(t))throw new Error("array of scalars expected");t.forEach((n,s)=>{if(!(r===void 0?e.isValid(n):xt(n)&&n<r))throw new Error("invalid scalar at index "+s)})}var xa=new WeakMap;function Hi(t){return xa.get(t)||1}function Qf(t,e){let r=t.double(),n=[t];for(let s=1;s<e;s++)n.push(n[s-1].add(r));return n}function Jf(t,e){let r=2**e,n=r/2,s=BigInt(r-1),o=[];for(;t>zi;){let c=0;t&Kr&&(c=Number(t&s),c>=n&&(c-=r),t-=BigInt(c)),o.push(c),t>>=Kr}return o}function ed(t,e,r){let n=2**e,s=n/2,o=BigInt(n-1),c=BigInt(e),i=[];for(let a=0;a<r;a++){let u=Number(t&o);t>>=c,u>s&&(u-=n,t+=Kr),i.push(u)}if(t!==zi)throw new Error("invalid wnaf");return i}function td(t,e,r){let n=0;for(let o of r)n=Math.max(n,o.length);let s=t;for(let o=n-1;o>=0;o--){o!==n-1&&(s=s.double());for(let c=0;c<r.length;c++){let i=r[c][o];if(i){let a=e[c][Math.abs(i)-1>>1];s=s.add(i<0?a.negate():a)}}}return s}var Fn=class{Point;BASE;ZERO;randomBytes;wnafPrecomputes=new WeakMap;baseCanBeBlinded;bits;constructor(e,r){rr(e),this.randomBytes=Vi(r,$i),this.Point=e,this.BASE=e.BASE,this.ZERO=e.ZERO,this.bits=e.Fn.BITS}buildWnafTable(e,r,n){let s=Math.ceil(n/r)+1,o=2**(r-1),c=[],i=e;for(let a=0;a<s;a++){let u=i;for(let l=0;l<o;l++)c.push(u),u=u.add(i);i=c[c.length-1].double()}return{W:r,bits:n,windows:s,comp:c}}wnafCachedCT(e,r){let{W:n,windows:s,comp:o}=e,c=2**(n-1),i=ed(r,n,s),a=this.ZERO,u=this.BASE;for(let l=0;l<s;l++){let f=i[l],d=l*c,p=Math.abs(f)-1,x=o[d];for(let b=1;b<c;b++)x=b===p?o[d+b]:x;let D=x.negate();f===0?u=u.add(o[d]):a=a.add(f<0?D:x)}return{p:a,f:u}}getWnafPrecomputes(e,r,n,s){let o=this.wnafPrecomputes.get(r),c=o?.find(i=>i.W===e&&i.bits===n);return c||(c=this.buildWnafTable(r,e,n),typeof s=="function"&&(c={...c,comp:s(c.comp)}),o||(o=[],this.wnafPrecomputes.set(r,o)),o.push(c)),c}assertPoint(e){if(!(e instanceof this.Point))throw new TypeError('"point" expected Point instance, got type='+typeof e)}validateMulInput(e,r){if(this.assertPoint(e),!Ri(r,Kr,this.Point.Fn.ORDER))throw new Error("invalid scalar")}runCT(e,r,n,s){let o=Hi(e);return o===1?this.fixedWindowCT(e,r,n):this.wnafCachedCT(this.getWnafPrecomputes(o,e,n,s),r)}mulCT(e,r,n){return this.validateMulInput(e,r),this.runCT(e,r,this.bits,n)}mulCTBlinded(e,r,n){if(this.validateMulInput(e,r),this.randomBytes===void 0)throw new Error("randomBytes is required for scalar blinding");let s=this.Point.Fn.BITS+ma,o=this.randomBytes($i);if(!Qt(o)||o.length!==$i)throw new Error("randomBytes returned invalid byte array");o[0]=o[0]&63|128;let c=r+et(o)*this.Point.Fn.ORDER;return this.runCT(e,c,s,n)}fixedWindowCT(e,r,n){let s=qf,o=1<<s,c=Fr(s),i=new Array(o);i[0]=this.ZERO;for(let l=1;l<o;l++)i[l]=i[l-1].add(e);let a=Math.ceil(n/s),u=this.ZERO;for(let l=a-1;l>=0;l--){if(l!==a-1)for(let p=0;p<s;p++)u=u.double();let f=Number(r>>BigInt(l*s)&c),d=i[0];for(let p=1;p<o;p++)d=p===f?i[p]:d;u=u.add(d)}return{p:u,f:u}}shouldBlind(e,r){return this.randomBytes===void 0?!1:r===Kr?!0:e!==this.BASE?!1:(this.baseCanBeBlinded===void 0&&(this.baseCanBeBlinded=this.mulUnsafe(this.BASE,this.Point.Fn.ORDER).is0()),this.baseCanBeBlinded)}mulSecret(e,r,n,s){return this.shouldBlind(e,n)?this.mulCTBlinded(e,r,s):this.mulCT(e,r,s)}mulUnsafe(e,r,n){if(this.assertPoint(e),!xt(r))throw new Error("invalid scalar");let s=Hi(e);if(s===1||r>=this.Point.Fn.ORDER)return Kn(this.Point,[e],[r],!0);let o=this.getWnafPrecomputes(s,e,this.bits,n);return this.wnafCachedCT(o,r).p}setWindowSize(e,r){this.assertPoint(e),Zf(r,this.bits);let n=Math.ceil((this.bits+ma)/r)+1;jf(n*2**(r-1),this.Point.Fp.BYTES),xa.set(e,r),this.wnafPrecomputes.delete(e)}hasWindowSize(e){return Hi(e)!==1}};function Kn(t,e,r,n=!1){if(rr(t),wa(e,t),Je(n,"allowOversized"),Xf(r,t.Fn,n?t.Fn.ORDER**Yf:void 0),e.length!==r.length)throw new Error("arrays of points and scalars must have equal length");let s=e.map(c=>Qf(c,4)),o=r.map(c=>Jf(c,4));return td(t.ZERO,s,o)}function ba(t,e,r){if(e){if(e.ORDER!==t)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return er(e),e}else return tr(t,{isLE:r})}function Ea(t,e,r={},n){if(t!=="weierstrass"&&t!=="edwards")throw new Error('expected curve type "weierstrass" or "edwards"');if(n===void 0&&(n=t==="edwards"),!e||typeof e!="object")throw new Error(`expected valid ${t} CURVE object`);Et(r);for(let a of["p","n","h"]){let u=e[a];if(!(xt(u)&&u!==zi))throw new Error(`CURVE.${a} must be positive bigint`)}let s=ba(e.p,r.Fp,n),o=ba(e.n,r.Fn,n),i=["Gx","Gy","a",t==="weierstrass"?"b":"d"];for(let a of i)if(!s.isValid(e[a]))throw new Error(`CURVE.${a} must be valid field element of CURVE.Fp`);return e=Object.freeze(Object.assign({},e)),{CURVE:e,Fp:s,Fn:o}}function va(t,e){return function(n){let s=t(n);return{secretKey:s,publicKey:e(s)}}}var Jy=$n.default.generateKeyPairSync,$r=32;var rd=64;function Sa(t,e,r){if(t.byteLength!==$r)throw new TypeError('"key" must be 32 bytes in length.');if(!(t instanceof Uint8Array))throw new TypeError('"key" must be a node.js Buffer, or Uint8Array.');if(e.byteLength!==rd)throw new TypeError('"sig" must be 64 bytes in length.');if(!(e instanceof Uint8Array))throw new TypeError('"sig" must be a node.js Buffer, or Uint8Array.');let n=$n.default.createPublicKey({format:"jwk",key:{crv:"Ed25519",x:ue(t,"base64url"),kty:"OKP"}});return $n.default.verify(null,r instanceof Uint8Array?r:r.subarray(),n,e)}function Aa(t){return t==null?!1:typeof t.then=="function"&&typeof t.catch=="function"&&typeof t.finally=="function"}var Hn=class{type="Ed25519";raw;constructor(e){this.raw=Gi(e,$r)}toMultihash(){return Ge.digest(jt(this))}toCID(){return de.createV1(114,this.toMultihash())}toString(){return ae.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:De(this.raw,e.raw)}verify(e,r,n){n?.signal?.throwIfAborted();let s=Sa(this.raw,r,e);return Aa(s)?s.then(o=>(n?.signal?.throwIfAborted(),o)):s}};function Da(t){return t=Gi(t,$r),new Hn(t)}function Gi(t,e){if(t=Uint8Array.from(t??[]),t.length!==e)throw new B(`Key must be a Uint8Array of length ${e}, got ${t.length}`);return t}var Ie;(function(t){t.RSA="RSA",t.Ed25519="Ed25519",t.secp256k1="secp256k1",t.ECDSA="ECDSA"})(Ie||(Ie={}));var Wi;(function(t){t[t.RSA=0]="RSA",t[t.Ed25519=1]="Ed25519",t[t.secp256k1=2]="secp256k1",t[t.ECDSA=3]="ECDSA"})(Wi||(Wi={}));(function(t){t.codec=()=>We(Wi)})(Ie||(Ie={}));var Hr;(function(t){let e;t.codec=()=>(e==null&&(e=te((o,c,i={})=>{i.lengthDelimited!==!1&&c.fork(),o.Type!=null&&(c.uint32(8),Ie.codec().encode(o.Type,c)),o.Data!=null&&(c.uint32(18),c.bytes(o.Data)),i.lengthDelimited!==!1&&c.ldelim()},(o,c,i={})=>{let a={},u=c==null?o.len:o.pos+c;for(;o.pos<u;){let l=o.uint32();switch(l>>>3){case 1:{a.Type=Ie.codec().decode(o);break}case 2:{a.Data=o.bytes();break}default:{o.skipType(l&7);break}}}return a},function*(o,c,i,a={}){let u=c==null?o.len:o.pos+c;for(;o.pos<u;){let l=o.uint32();switch(l>>>3){case 1:{yield{field:`${i}.Type`,value:Ie.codec().decode(o)};break}case 2:{yield{field:`${i}.Data`,value:o.bytes()};break}default:{o.skipType(l&7);break}}}})),e);function r(o){return J(o,t.codec())}t.encode=r;function n(o,c){return Q(o,t.codec(),c)}t.decode=n;function s(o,c){return ee(o,t.codec(),c)}t.stream=s})(Hr||(Hr={}));var Yi;(function(t){let e;t.codec=()=>(e==null&&(e=te((o,c,i={})=>{i.lengthDelimited!==!1&&c.fork(),o.Type!=null&&(c.uint32(8),Ie.codec().encode(o.Type,c)),o.Data!=null&&(c.uint32(18),c.bytes(o.Data)),i.lengthDelimited!==!1&&c.ldelim()},(o,c,i={})=>{let a={},u=c==null?o.len:o.pos+c;for(;o.pos<u;){let l=o.uint32();switch(l>>>3){case 1:{a.Type=Ie.codec().decode(o);break}case 2:{a.Data=o.bytes();break}default:{o.skipType(l&7);break}}}return a},function*(o,c,i,a={}){let u=c==null?o.len:o.pos+c;for(;o.pos<u;){let l=o.uint32();switch(l>>>3){case 1:{yield{field:`${i}.Type`,value:Ie.codec().decode(o)};break}case 2:{yield{field:`${i}.Data`,value:o.bytes()};break}default:{o.skipType(l&7);break}}}})),e);function r(o){return J(o,t.codec())}t.encode=r;function n(o,c){return Q(o,t.codec(),c)}t.decode=n;function s(o,c){return ee(o,t.codec(),c)}t.stream=s})(Yi||(Yi={}));var Ra=_e(le("node:crypto"),1);var zn=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(e,r){if(An(e),Qe(r,void 0,"key"),this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("expected Hash instance");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,s=new Uint8Array(n);s.set(r.length>n?e.create().update(r).digest():r);for(let o=0;o<s.length;o++)s[o]^=54;this.iHash.update(s),this.oHash=e.create();for(let o=0;o<s.length;o++)s[o]^=106;this.oHash.update(s),Ur(s)}update(e){return Xt(this),this.iHash.update(e),this}digestInto(e){Xt(this),Dn(e,this),this.finished=!0;let r=e.subarray(0,this.outputLen);this.iHash.digestInto(r),this.oHash.update(r),this.oHash.digestInto(r),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||=Object.create(Object.getPrototypeOf(this),{});let{oHash:r,iHash:n,finished:s,destroyed:o,blockLen:c,outputLen:i,canXOF:a}=this;return e=e,e.finished=s,e.destroyed=o,e.blockLen=c,e.outputLen=i,e.canXOF=a,e.oHash=r._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Ia=(()=>{let t=((e,r,n)=>new zn(e,r).update(n).digest());return t.create=(e,r)=>new zn(e,r),t})();var id=BigInt(0),qi=class extends Error{constructor(e=""){super(e)}},it={Err:qi,_tlv:{encode:(t,e)=>{let{Err:r}=it;if(kt(t,"tag"),t<0||t>255)throw new r("tlv.encode: wrong tag");if(ea(e,"data"),e.length&1)throw new r("tlv.encode: unpadded data");let n=e.length/2,s=Mr(n);if(s.length/2&128)throw new r("tlv.encode: long form length too big");let o=n>127?Mr(s.length/2|128):"";return Mr(t)+o+s+e},decode(t,e){let{Err:r}=it;e=he(e,void 0,"DER data");let n=0;if(t<0||t>255)throw new r("tlv.decode: wrong tag");if(e.length<2||e[n++]!==t)throw new r("tlv.decode: wrong tlv");let s=e[n++],o=!!(s&128),c=0;if(!o)c=s;else{let a=s&127;if(!a)throw new r("tlv.decode(long): indefinite length not supported");if(a>4)throw new r("tlv.decode(long): byte length is too big");let u=e.subarray(n,n+a);if(u.length!==a)throw new r("tlv.decode: length bytes not complete");if(u[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let l of u)c=c<<8|l;if(n+=a,c<128)throw new r("tlv.decode(long): not minimal encoding")}let i=e.subarray(n,n+c);if(i.length!==c)throw new r("tlv.decode: wrong value length");return{v:i,l:e.subarray(n+c)}}},_int:{encode(t){let{Err:e}=it;if(Pn(t),t<id)throw new e("integer: negative integers are not allowed");let r=Mr(t);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new e("unexpected DER parsing assertion: unpadded hex");return r},decode(t){let{Err:e}=it;if(t.length<1)throw new e("invalid signature integer: empty");if(t[0]&128)throw new e("invalid signature integer: negative");if(t.length>1&&t[0]===0&&!(t[1]&128))throw new e("invalid signature integer: unnecessary leading zero");return et(t)}},toSig(t,e){let{Err:r,_int:n,_tlv:s}=it;if(e!==void 0&&(kt(e,"maxScalarBytes"),e<1))throw new r("invalid signature: maxScalarBytes must be positive");let o=he(t,void 0,"signature"),{v:c,l:i}=s.decode(48,o);if(i.length)throw new r("invalid signature: left bytes after parsing");let{v:a,l:u}=s.decode(2,c),{v:l,l:f}=s.decode(2,u);if(f.length)throw new r("invalid signature: left bytes after parsing");if(e!==void 0&&(a.length>e||l.length>e))throw new r("invalid signature: integer too large");return{r:n.decode(a),s:n.decode(l)}},hexFromSig(t){let{_tlv:e,_int:r}=it;Et(t,{r:"bigint",s:"bigint"},{},"sig");let n=e.encode(2,r.encode(t.r)),s=e.encode(2,r.encode(t.s)),o=n+s;return e.encode(48,o)}},Vn=(Object.freeze(it._tlv),Object.freeze(it._int),Object.freeze(it));var Ca=(t,e)=>(t+(t>=0?e:-e)/Ba)/e;function sd(t,e,r){Ni("scalar",t,st,r);let[[n,s],[o,c]]=e,i=Ca(c*t,r),a=Ca(-s*t,r),u=t-i*n-a*o,l=-i*s-a*c,f=u<st,d=l<st;f&&(u=-u),d&&(l=-l);let p=Fr(Math.ceil(Jt(r)/2))+_t;if(u<st||u>=p||l<st||l>=p)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:f,k1:u,k2neg:d,k2:l}}function Xi(t){if(!["compact","recovered","der"].includes(t))throw new Error('Signature format must be "compact", "recovered", or "der"');return t}function Zi(t,e){Et(t);let r={};for(let n of Object.keys(e))r[n]=t[n]===void 0?e[n]:t[n];return Je(r.lowS,"lowS"),Je(r.prehash,"prehash"),r.format!==void 0&&Xi(r.format),r}var st=BigInt(0),_t=BigInt(1),Ba=BigInt(2),ji=BigInt(3),cd=BigInt(4);function La(t,e={}){let r=Ea("weierstrass",t,e),n=r.Fp,s=r.Fn,o=r.CURVE,{h:c,n:i}=o;Et(e,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",randomBytes:"function"});let{endo:a,allowInfinityPoint:u,clearCofactor:l,isTorsionFree:f,fromBytes:d,toBytes:p}=e,x=e.randomBytes===void 0?_n:e.randomBytes;if(a&&(!n.is0(o.a)||typeof a.beta!="bigint"||!Array.isArray(a.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let D=a?{beta:a.beta,basises:a.basises.map(w=>[...w])}:void 0,b=ka(n,s);function y(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function T(w,h,m){if(h.is0()){if(!u)throw new Error("bad point: ZERO");return Uint8Array.of(0)}let{x:g,y:E}=h.toAffine(),v=n.toBytes(g);if(Je(m,"isCompressed"),m){y();let A=!n.isOdd(E);return ot(Oa(A),v)}else return ot(Uint8Array.of(4),v,n.toBytes(E))}function P(w){he(w,void 0,"Point");let{publicKey:h,publicKeyUncompressed:m}=b,g=w.length,E=w[0],v=w.subarray(1);if(u&&g===1&&E===0)return{x:n.ZERO,y:n.ZERO};if(g===h&&(E===2||E===3)){let A=n.fromBytes(v);if(!n.isValid(A))throw new Error("bad point: is not on curve, wrong x");let I=re(A),C;try{C=n.sqrt(I)}catch(se){let q=se instanceof Error?": "+se.message:"";throw new Error("bad point: is not on curve, sqrt error"+q)}y();let N=n.isOdd(C);return(E&1)===1!==N&&(C=n.neg(C)),{x:A,y:C}}else if(g===m&&E===4){let A=n.BYTES,I=n.fromBytes(v.subarray(0,A)),C=n.fromBytes(v.subarray(A,A*2));if(!we(I,C))throw new Error("bad point: is not on curve");return{x:I,y:C}}else throw new Error(`bad point: got length ${g}, expected compressed=${h} or uncompressed=${m}`)}let _=p===void 0?T:p,M=d===void 0?P:d,X=n.mul(o.b,ji),ie=n.is0(o.a)?w=>n.ZERO:w=>n.mul(o.a,w);function re(w){let h=n.sqr(w),m=n.mul(h,w);return n.add(n.add(m,n.mul(w,o.a)),o.b)}function we(w,h){let m=n.sqr(h),g=re(w);return n.eql(m,g)}if(!we(o.Gx,o.Gy))throw new Error("bad curve params: generator point");let V=n.mul(n.pow(o.a,ji),cd),me=n.mul(n.sqr(o.b),BigInt(27));if(n.is0(n.add(V,me)))throw new Error("bad curve params: a or b");function Oe(w,h,m=!1){if(!n.isValid(h)||m&&n.is0(h))throw new Error(`bad point coordinate ${w}`);return typeof h=="object"&&h!==null?n.create(h):h}function ft(w){if(!(w instanceof F))throw new Error("Weierstrass Point expected")}function jr(w){if(!D||!D.basises)throw new Error("no endo");return sd(w,D.basises,s.ORDER)}function Tt(w,h,m,g){if(!s.isValid(g))throw new RangeError("invalid scalar: out of range");if(D){let{k1neg:E,k1:v,k2neg:A,k2:I}=jr(g),C=new F(n.mul(m.X,D.beta),m.Y,m.Z);w.push(E?m.negate():m,A?C.negate():C),h.push(v,I)}else w.push(m),h.push(g)}let Xr=new WeakSet;class F{static BASE=new F(o.Gx,o.Gy,n.ONE);static ZERO=new F(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=s;X;Y;Z;constructor(h,m,g){this.X=Oe("x",h),this.Y=Oe("y",m,!0),this.Z=Oe("z",g),Object.freeze(this)}static CURVE(){return o}static fromAffine(h){let{x:m,y:g}=h||{};if(!h||!n.isValid(m)||!n.isValid(g))throw new Error("invalid affine point");if(h instanceof F)throw new Error("projective point not allowed");return n.is0(m)&&n.is0(g)?F.ZERO:new F(m,g,n.ONE)}static fromBytes(h){let m=F.fromAffine(M(he(h,void 0,"point")));return m.assertValidity(),m}static fromHex(h){return F.fromBytes(kn(h))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(h=6,m=!0){return dt.setWindowSize(this,h),m||this.multiply(ji),this}assertValidity(){let h=this;if(h.is0()){if(u&&n.is0(h.X)&&n.eql(h.Y,n.ONE)&&n.is0(h.Z))return;throw new Error("bad point: ZERO")}if(Xr.has(h))return;let{x:m,y:g}=h.toAffine();if(!n.isValid(m)||!n.isValid(g))throw new Error("bad point: x or y not field elements");if(!we(m,g))throw new Error("bad point: equation left != right");if(!h.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");Xr.add(h)}hasEvenY(){let{y:h}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(h)}equals(h){ft(h);let{X:m,Y:g,Z:E}=this,{X:v,Y:A,Z:I}=h,C=n.eql(n.mul(m,I),n.mul(v,E)),N=n.eql(n.mul(g,I),n.mul(A,E));return C&&N}negate(){return new F(this.X,n.neg(this.Y),this.Z)}double(){let{X:h,Y:m,Z:g}=this,E=n.ZERO,v=n.ZERO,A=n.ZERO,I=n.mul(h,h),C=n.mul(m,m),N=n.mul(g,g),k=n.mul(h,m);return k=n.add(k,k),A=n.mul(h,g),A=n.add(A,A),E=ie(A),v=n.mul(X,N),v=n.add(E,v),E=n.sub(C,v),v=n.add(C,v),v=n.mul(E,v),E=n.mul(k,E),A=n.mul(X,A),N=ie(N),k=n.sub(I,N),k=ie(k),k=n.add(k,A),A=n.add(I,I),I=n.add(A,I),I=n.add(I,N),I=n.mul(I,k),v=n.add(v,I),N=n.mul(m,g),N=n.add(N,N),I=n.mul(N,k),E=n.sub(E,I),A=n.mul(N,C),A=n.add(A,A),A=n.add(A,A),new F(E,v,A)}add(h){ft(h);let{X:m,Y:g,Z:E}=this,{X:v,Y:A,Z:I}=h,C=n.ZERO,N=n.ZERO,k=n.ZERO,se=n.mul(m,v),q=n.mul(g,A),ye=n.mul(E,I),Ke=n.add(m,g),Z=n.add(v,A);Ke=n.mul(Ke,Z),Z=n.add(se,q),Ke=n.sub(Ke,Z),Z=n.add(m,E);let ce=n.add(v,I);return Z=n.mul(Z,ce),ce=n.add(se,ye),Z=n.sub(Z,ce),ce=n.add(g,E),C=n.add(A,I),ce=n.mul(ce,C),C=n.add(q,ye),ce=n.sub(ce,C),k=ie(Z),C=n.mul(X,ye),k=n.add(C,k),C=n.sub(q,k),k=n.add(q,k),N=n.mul(C,k),q=n.add(se,se),q=n.add(q,se),ye=ie(ye),Z=n.mul(X,Z),q=n.add(q,ye),ye=n.sub(se,ye),ye=ie(ye),Z=n.add(Z,ye),se=n.mul(q,Z),N=n.add(N,se),se=n.mul(ce,Z),C=n.mul(Ke,C),C=n.sub(C,se),se=n.mul(Ke,q),k=n.mul(ce,k),k=n.add(k,se),new F(C,N,k)}subtract(h){return ft(h),this.add(h.negate())}is0(){return this.equals(F.ZERO)}multiply(h){if(!s.isValidNot0(h))throw new RangeError("invalid scalar: out of range");let{p:m,f:g}=dt.mulSecret(this,h,c,ur);return ur([m,g])[0]}multiplyUnsafe(h){let m=this,g=h;if(!s.isValid(g))throw new RangeError("invalid scalar: out of range");if(g===st||m.is0())return F.ZERO;if(g===_t)return m;if(dt.hasWindowSize(this))return dt.mulUnsafe(m,g,ur);let E=[],v=[];return Tt(E,v,m,g),Kn(F,E,v)}mulAddUnsafe(h,m,g){ft(m);let E=[],v=[];return Tt(E,v,this,h),Tt(E,v,m,g),Kn(F,E,v)}toAffine(h){let m=this,g=h;if(g!=null&&!n.isValid(g))throw new RangeError('"invertedZ" expected valid field element');let{X:E,Y:v,Z:A}=m;if(n.eql(A,n.ONE))return{x:E,y:v};let I=m.is0();g==null&&(g=I?n.ONE:n.inv(A));let C=n.mul(E,g),N=n.mul(v,g),k=n.mul(A,g);if(I)return{x:n.ZERO,y:n.ZERO};if(!n.eql(k,n.ONE))throw new Error("invZ was invalid");return{x:C,y:N}}isTorsionFree(){return c===_t?!0:f?f(F,this):dt.mulUnsafe(this,i).is0()}clearCofactor(){return c===_t?this:l?l(F,this):this.multiplyUnsafe(c)}isSmallOrder(){return c===_t?this.is0():this.clearCofactor().is0()}toBytes(h=!0){return Je(h,"isCompressed"),this.assertValidity(),_(F,this,h)}toHex(h=!0){return ki(this.toBytes(h))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let ur=w=>ga(F,w),dt=new Fn(F,x);return dt.bits>=6&&F.BASE.precompute(6),Object.freeze(F.prototype),Object.freeze(F),F}function Oa(t){return Uint8Array.of(t?2:3)}function ka(t,e){return{secretKey:e.BYTES,publicKey:1+t.BYTES,publicKeyUncompressed:1+2*t.BYTES,publicKeyHasPrefix:!0,signature:2*e.BYTES}}function ad(t,e={}){rr(t);let{Fn:r}=t,n=e.randomBytes===void 0?_n:e.randomBytes,s=Object.assign(ka(t.Fp,r),{seed:Math.max(Un(r.ORDER),16)});function o(p){try{let x=r.fromBytes(p);return r.isValidNot0(x)}catch{return!1}}function c(p,x){let{publicKey:D,publicKeyUncompressed:b}=s;try{let y=p.length;return x===!0&&y!==D||x===!1&&y!==b?!1:!t.fromBytes(p).is0()}catch{return!1}}function i(p){return p=p===void 0?n(s.seed):p,Mn(he(p,s.seed,"seed"),r.ORDER)}function a(p,x=!0){return t.BASE.multiply(r.fromBytes(p)).toBytes(x)}function u(p){let{secretKey:x,publicKey:D,publicKeyUncompressed:b}=s,y=r._lengths;if(!Qt(p))return;let T=he(p,void 0,"key").length,P=T===D||T===b,_=T===x||!!y?.includes(T);if(!(P&&_))return P}function l(p,x,D=!0){if(u(p)===!0)throw new Error("first arg must be private key");if(u(x)===!1)throw new Error("second arg must be public key");let b=r.fromBytes(p),y=t.fromBytes(x);if(y.is0())throw new Error("invalid public key: point at infinity");return y.multiply(b).toBytes(D)}let f={isValidSecretKey:o,isValidPublicKey:c,randomSecretKey:i},d=va(i,a);return Object.freeze(f),Object.freeze(s),Object.freeze({getPublicKey:a,getSharedSecret:l,keygen:d,Point:t,utils:f,lengths:s})}function _a(t,e,r={}){rr(t);let n=e;An(n),Et(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let s=Object.assign({},r),o=s.randomBytes===void 0?_n:s.randomBytes,c=s.hmac===void 0?(w,h)=>Ia(n,w,h):s.hmac,{Fp:i,Fn:a}=t,{ORDER:u,BITS:l}=a,f=Un(u),d=Vi(o,f),{keygen:p,getPublicKey:x,getSharedSecret:D,utils:b,lengths:y}=ad(t,s),T={prehash:!0,lowS:typeof s.lowS=="boolean"?s.lowS:!0,format:"compact",extraEntropy:!1},P=u*Ba+_t<i.ORDER;function _(w){let h=u>>_t;return w>h}function M(w,h){if(!a.isValidNot0(h))throw new Error(`invalid signature ${w}: out of range 1..Point.Fn.ORDER`);return h}function X(){if(!i.isOdd)throw new Error("Field doesn't support isOdd")}function ie(w,h,m){return X(),(w===m?0:2)|Number(i.isOdd(h))}function re(){if(P)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function we(w,h){Xi(h);let m=y.signature,g=h==="compact"?m:h==="recovered"?m+1:void 0;return he(w,g)}class V{r;s;recovery;constructor(h,m,g){if(this.r=M("r",h),this.s=M("s",m),g!=null){if(re(),![0,1,2,3].includes(g))throw new Error("invalid recovery id");this.recovery=g}Object.freeze(this)}static fromBytes(h,m=T.format){we(h,m);let g;if(m==="der"){if(h.length>2*a.BYTES+16)throw new Vn.Err("invalid signature: DER signature too long");let{r:I,s:C}=Vn.toSig(he(h),a.BYTES+1);return new V(I,C)}m==="recovered"&&(g=h[0],m="compact",h=h.subarray(1));let E=y.signature/2,v=h.subarray(0,E),A=h.subarray(E,E*2);return new V(a.fromBytes(v),a.fromBytes(A),g)}static fromHex(h,m){return this.fromBytes(kn(h),m)}assertRecovery(){let{recovery:h}=this;if(h==null)throw new Error("invalid recovery id: must be present");return h}addRecoveryBit(h){return new V(this.r,this.s,h)}recoverPublicKey(h){let{r:m,s:g}=this,E=this.assertRecovery(),v=E===2||E===3?m+u:m;if(!i.isValid(v))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let A=i.toBytes(v),I=t.fromBytes(ot(Oa((E&1)===0),A)),C=a.inv(v),N=Oe(he(h,void 0,"msgHash")),k=a.create(-N*C),se=a.create(g*C),q=t.BASE.mulAddUnsafe(k,I,se);if(q.is0())throw new Error("invalid recovery: point at infinify");return q.assertValidity(),q}hasHighS(){return _(this.s)}toBytes(h=T.format){if(Xi(h),h==="der")return kn(Vn.hexFromSig(this));let{r:m,s:g}=this,E=a.toBytes(m),v=a.toBytes(g);return h==="recovered"?(re(),ot(Uint8Array.of(this.assertRecovery()),E,v)):ot(E,v)}toHex(h){return ki(this.toBytes(h))}}Object.freeze(V.prototype),Object.freeze(V);let me=s.bits2int===void 0?function(h){if(h.length>8192)throw new Error("input is too large");let m=et(h),g=h.length*8-l;return g>0?m>>BigInt(g):m}:s.bits2int,Oe=s.bits2int_modN===void 0?function(h){return a.create(me(h))}:s.bits2int_modN,ft=Fr(l);function jr(w){return Ni("num < 2^"+l,w,st,ft),a.toBytes(w)}function Tt(w,h){return he(w,void 0,"message"),h?he(n(w),void 0,"prehashed message"):w}function Xr(w,h,m){let{lowS:g,prehash:E,extraEntropy:v}=Zi(m,T);w=Tt(w,E);let A=Oe(w),I=a.fromBytes(h);if(!a.isValidNot0(I))throw new Error("invalid private key");let C=[jr(I),jr(A)];if(v!=null&&v!==!1){let q=v===!0?o(y.secretKey):v;C.push(he(q,void 0,"extraEntropy"))}let N=ot(...C),k=A;function se(q){let ye=me(q);if(!a.isValidNot0(ye))return;let Ke=t.BASE.multiply(ye).toAffine(),Z=a.create(Ke.x);if(Z===st)return;let ce;if(d!==void 0){let lr=et(Mn(d(f),u)),gu=a.inv(a.mul(lr,ye)),wu=a.mul(lr,k),xu=a.mul(lr,I);ce=a.create(gu*a.create(wu+xu*Z))}else{let lr=fa(ye,u);ce=a.create(lr*a.create(k+Z*I))}if(ce===st)return;let Lo=ie(Ke.x,Ke.y,Z),Rs=ce;return g&&_(ce)&&(Rs=a.neg(ce),Lo^=1),new V(Z,Rs,P?void 0:Lo)}return{seed:N,k2sig:se}}function F(w,h,m={}){let{seed:g,k2sig:E}=Xr(w,h,m);return ra(n.outputLen,a.BYTES,c)(g,E).toBytes(m.format)}function ur(w,h,m,g={}){let{lowS:E,prehash:v,format:A}=Zi(g,T);if(m=he(m,void 0,"publicKey"),h=Tt(h,v),!Qt(w)){let I=w instanceof V?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+I)}we(w,A);try{let I=V.fromBytes(w,A),C=t.fromBytes(m);if(C.is0()||E&&I.hasHighS())return!1;let{r:N,s:k}=I,se=Oe(h),q=a.inv(k),ye=a.create(se*q),Ke=a.create(N*q),Z=t.BASE.mulAddUnsafe(ye,C,Ke);if(Z.is0())return!1;let ce=Z.toAffine();return!(a.create(ce.x)!==N||A==="recovered"&&I.recovery!==ie(ce.x,ce.y,N))}catch{return!1}}function dt(w,h,m={}){let{prehash:g}=Zi(m,T);return h=Tt(h,g),V.fromBytes(w,"recovered").recoverPublicKey(h).toBytes()}return Object.freeze({keygen:p,getPublicKey:x,getSharedSecret:D,utils:b,lengths:y,Point:t,sign:F,verify:ur,recoverPublicKey:dt,Signature:V,hash:n})}var Ji={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},ud={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var Pa=BigInt(2);function ld(t){let e=Ji.p,r=BigInt(3),n=BigInt(6),s=BigInt(11),o=BigInt(22),c=BigInt(23),i=BigInt(44),a=BigInt(88),u=t*t*t%e,l=u*u*t%e,f=Ue(l,r,e)*l%e,d=Ue(f,r,e)*l%e,p=Ue(d,Pa,e)*u%e,x=Ue(p,s,e)*p%e,D=Ue(x,o,e)*x%e,b=Ue(D,i,e)*D%e,y=Ue(b,a,e)*b%e,T=Ue(y,i,e)*D%e,P=Ue(T,r,e)*l%e,_=Ue(P,c,e)*x%e,M=Ue(_,n,e)*u%e,X=Ue(M,Pa,e);if(!Qi.eql(Qi.sqr(X),t))throw new Error("Cannot find square root");return X}var Qi=tr(Ji.p,{sqrt:ld}),fd=La(Ji,{Fp:Qi,endo:ud}),zr=_a(fd,Qc);var Gn=class extends Error{constructor(e="An error occurred while verifying a message"){super(e),this.name="VerificationError"}};function Na(t,e,r,n){n?.signal?.throwIfAborted();let s=Ra.default.createHash("sha256");if(r instanceof Uint8Array)s.update(r);else for(let c of r)s.update(c);let o=s.digest();try{return zr.verify(e,o,t,{prehash:!1,format:"der"})}catch(c){throw new Gn(String(c))}}var Wn=class{type="secp256k1";raw;_key;constructor(e){this._key=Ma(e),this.raw=Ua(this._key)}toMultihash(){return Ge.digest(jt(this))}toCID(){return de.createV1(114,this.toMultihash())}toString(){return ae.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:De(this.raw,e.raw)}verify(e,r,n){return Na(this._key,r,e,n)}};function Fa(t){return new Wn(t)}function Ua(t){return zr.Point.fromBytes(t).toBytes()}function Ma(t){try{return zr.Point.fromBytes(t),t}catch(e){throw new Or(String(e))}}function Ka(t){let{Type:e,Data:r}=Hr.decode(t.digest),n=r??new Uint8Array;switch(e){case Ie.Ed25519:return Da(n);case Ie.secp256k1:return Fa(n);case Ie.ECDSA:return Mc(n);default:throw new Pr}}function jt(t){return Hr.encode({Type:Ie[t.type],Data:t.raw})}var $a=Symbol.for("nodejs.util.inspect.custom"),dd=114,Vr=class{type;multihash;publicKey;string;constructor(e){this.type=e.type,this.multihash=e.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[mn]=!0;toString(){return this.string==null&&(this.string=ae.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return de.createV1(dd,this.multihash)}toJSON(){return this.toString()}equals(e){if(e==null)return!1;if(e instanceof Uint8Array)return De(this.multihash.bytes,e);if(typeof e=="string")return this.toString()===e;if(e?.toMultihash()?.bytes!=null)return De(this.multihash.bytes,e.toMultihash().bytes);throw new Error("not valid Id")}[$a](){return`PeerId(${this.toString()})`}},Yn=class extends Vr{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},qn=class extends Vr{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.publicKey}},Zn=class extends Vr{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.publicKey}},hd=2336,jn=class{type="url";multihash;publicKey;url;constructor(e){this.url=e.toString(),this.multihash=Ge.digest(Ae(this.url))}[$a](){return`PeerId(${this.url})`}[mn]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return de.createV1(hd,this.toMultihash())}toJSON(){return this.toString()}equals(e){return e==null?!1:(e instanceof Uint8Array&&(e=ue(e)),e.toString()===this.toString())}};function ct(t){if(md(t))return new Yn({multihash:t});if(pd(t))try{let e=Ka(t);if(e.type==="Ed25519")return new qn({multihash:t,publicKey:e});if(e.type==="secp256k1")return new Zn({multihash:t,publicKey:e})}catch{let r=ue(t.digest);return new jn(new URL(r))}throw new un("Supplied PeerID Multihash is invalid")}function pd(t){return t.code===Ge.code}function md(t){return t.code===ai.code}var yu=_e(le("net"),1);var xe=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},at=class extends Error{static name="ValidationError";name="ValidationError"},Xn=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},Qn=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};var Me=le("node:net");function ts(t){return e=>ue(e,t)}function rs(t){return e=>Ae(e,t)}function nr(t){return new DataView(t.buffer).getUint16(t.byteOffset).toString()}function Pt(t){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,typeof t=="string"?parseInt(t):t),new Uint8Array(e)}function Ha(t){let e=t.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 r=Ae(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 s=Pt(n);return qe([r,s],r.length+s.length)}function za(t){let e=t.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 r=je.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 s=Pt(n);return qe([r,s],r.length+s.length)}function ns(t){let e=t.subarray(0,t.length-2),r=t.subarray(t.length-2),n=ue(e,"base32"),s=nr(r);return`${n}:${s}`}var os=function(t){t=t.toString().trim();let e=new Uint8Array(4);return t.split(/\./g).forEach((r,n)=>{let s=parseInt(r,10);if(isNaN(s)||s<0||s>255)throw new xe("Invalid byte value in IP address");e[n]=s}),e},Va=function(t){let e=0;t=t.toString().trim();let r=t.split(":",8),n;for(n=0;n<r.length;n++){let o=(0,Me.isIPv4)(r[n]),c;o&&(c=os(r[n]),r[n]=ue(c.subarray(0,2),"base16")),c!=null&&++n<8&&r.splice(n,0,ue(c.subarray(2,4),"base16"))}if(r[0]==="")for(;r.length<8;)r.unshift("0");else if(r[r.length-1]==="")for(;r.length<8;)r.push("0");else if(r.length<8){for(n=0;n<r.length&&r[n]!=="";n++);let o=[n,1];for(n=9-r.length;n>0;n--)o.push("0");r.splice.apply(r,o)}let s=new Uint8Array(e+16);for(n=0;n<r.length;n++){r[n]===""&&(r[n]="0");let o=parseInt(r[n],16);if(isNaN(o)||o<0||o>65535)throw new xe("Invalid byte value in IP address");s[e++]=o>>8&255,s[e++]=o&255}return s},Ga=function(t){if(t.byteLength!==4)throw new xe("IPv4 address was incorrect length");let e=[];for(let r=0;r<t.byteLength;r++)e.push(t[r]);return e.join(".")},Wa=function(t){if(t.byteLength!==16)throw new xe("IPv6 address was incorrect length");let e=[];for(let n=0;n<t.byteLength;n+=2){let s=t[n],o=t[n+1],c=`${s.toString(16).padStart(2,"0")}${o.toString(16).padStart(2,"0")}`;e.push(c)}let r=e.join(":");try{let n=new URL(`http://[${r}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new xe(`Invalid IPv6 address "${r}"`)}};function Ya(t){try{let e=new URL(`http://[${t}]`);return e.hostname.substring(1,e.hostname.length-1)}catch{throw new xe(`Invalid IPv6 address "${t}"`)}}var es=Object.values(br).map(t=>t.decoder),yd=(function(){let t=es[0].or(es[1]);return es.slice(2).forEach(e=>t=t.or(e)),t})();function qa(t){return yd.decode(t)}function Za(t){return e=>t.encoder.encode(e)}function bd(t){if(parseInt(t).toString()!==t)throw new at("Value must be an integer")}function gd(t){if(t<0)throw new at("Value must be a positive integer, or zero")}function wd(t){return e=>{if(e>t)throw new at(`Value must be smaller than or equal to ${t}`)}}function xd(...t){return e=>{for(let r of t)r(e)}}var Gr=xd(bd,gd,wd(65535));var be=-1,is=class{protocolsByCode=new Map;protocolsByName=new Map;getProtocol(e){let r;if(typeof e=="string"?r=this.protocolsByName.get(e):r=this.protocolsByCode.get(e),r==null)throw new Qn(`Protocol ${e} was unknown`);return r}addProtocol(e){this.protocolsByCode.set(e.code,e),this.protocolsByName.set(e.name,e),e.aliases?.forEach(r=>{this.protocolsByName.set(r,e)})}removeProtocol(e){let r=this.protocolsByCode.get(e);r!=null&&(this.protocolsByCode.delete(r.code),this.protocolsByName.delete(r.name),r.aliases?.forEach(n=>{this.protocolsByName.delete(n)}))}},lt=new is,Pd=[{code:4,name:"ip4",size:32,valueToBytes:os,bytesToValue:Ga,validate:t=>{if(!(0,Me.isIPv4)(t))throw new at(`Invalid IPv4 address "${t}"`)}},{code:6,name:"tcp",size:16,valueToBytes:Pt,bytesToValue:nr,validate:Gr},{code:273,name:"udp",size:16,valueToBytes:Pt,bytesToValue:nr,validate:Gr},{code:33,name:"dccp",size:16,valueToBytes:Pt,bytesToValue:nr,validate:Gr},{code:41,name:"ip6",size:128,valueToBytes:Va,bytesToValue:Wa,stringToValue:Ya,validate:t=>{if(!(0,Me.isIPv6)(t))throw new at(`Invalid IPv6 address "${t}"`)}},{code:42,name:"ip6zone",size:be},{code:43,name:"ipcidr",size:8,bytesToValue:ts("base10"),valueToBytes:rs("base10")},{code:53,name:"dns",size:be},{code:54,name:"dns4",size:be},{code:55,name:"dns6",size:be},{code:56,name:"dnsaddr",size:be},{code:132,name:"sctp",size:16,valueToBytes:Pt,bytesToValue:nr,validate:Gr},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:be,stringToValue:t=>decodeURIComponent(t),valueToString:t=>encodeURIComponent(t)},{code:421,name:"p2p",aliases:["ipfs"],size:be,bytesToValue:ts("base58btc"),valueToBytes:t=>t.startsWith("Q")||t.startsWith("1")?rs("base58btc")(t):de.parse(t).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:ns,valueToBytes:Ha},{code:445,name:"onion3",size:296,bytesToValue:ns,valueToBytes:za},{code:446,name:"garlic64",size:be},{code:447,name:"garlic32",size:be},{code:448,name:"tls"},{code:449,name:"sni",size:be},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:be,bytesToValue:Za(Jo),valueToBytes:qa},{code:480,name:"http"},{code:481,name:"http-path",size:be,stringToValue:t=>`/${decodeURIComponent(t)}`,valueToString:t=>encodeURIComponent(t.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:be}];Pd.forEach(t=>{lt.addProtocol(t)});function ja(t){let e=[],r=0;for(;r<t.length;){let n=fr(t,r),s=lt.getProtocol(n),o=Be(n),c=Rd(s,t,r+o),i=0;c>0&&s.size===be&&(i=Be(c));let a=o+i+c,u={code:n,name:s.name,bytes:pt(t.subarray(r,r+a))};if(c>0){let l=r+o+i,f=t.subarray(l,l+c);u.value=s.bytesToValue?.(f)??ue(f)}e.push(u),r+=a}return e}function Xa(t){let e=0,r=[];for(let n of t){if(n.bytes==null){let s=lt.getProtocol(n.code),o=Be(n.code),c,i=0,a=0;n.value!=null&&(c=s.valueToBytes?.(n.value)??Ae(n.value),i=c.byteLength,s.size===be&&(a=Be(i)));let u=new Uint8Array(o+a+i),l=0;Ut(n.code,u,l),l+=o,c!=null&&(s.size===be&&(Ut(i,u,l),l+=a),u.set(c,l)),n.bytes=u}r.push(n.bytes),e+=n.bytes.byteLength}return qe(r,e)}function Qa(t){if(t.charAt(0)!=="/")throw new xe('String multiaddr must start with "/"');let e=[],r="protocol",n="",s="";for(let o=1;o<t.length;o++){let c=t.charAt(o);c!=="/"&&(r==="protocol"?s+=t.charAt(o):n+=t.charAt(o));let i=o===t.length-1;if(c==="/"||i){let a=lt.getProtocol(s);if(r==="protocol"){if(a.size==null||a.size===0){e.push({code:a.code,name:a.name}),n="",s="",r="protocol";continue}else if(i)throw new xe(`Component ${s} was missing value`);r="value"}else if(r==="value"){let u={code:a.code,name:a.name};if(a.size!=null&&a.size!==0){if(n==="")throw new xe(`Component ${s} was missing value`);u.value=a.stringToValue?.(n)??n}e.push(u),n="",s="",r="protocol"}}}if(s!==""&&n!=="")throw new xe("Incomplete multiaddr");return e}function Ja(t){return`/${t.flatMap(e=>{if(e.value==null)return e.name;let r=lt.getProtocol(e.code);if(r==null)throw new xe(`Unknown protocol code ${e.code}`);return[e.name,r.valueToString?.(e.value)??e.value]}).join("/")}`}function Rd(t,e,r){return t.size==null||t.size===0?0:t.size>0?t.size/8:fr(e,r)}var Nd=Symbol.for("nodejs.util.inspect.custom"),gs=Symbol.for("@multiformats/multiaddr");function Ud(t){if(t==null&&(t="/"),ao(t))return t.getComponents();if(t instanceof Uint8Array)return ja(t);if(typeof t=="string")return t=t.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),t===""&&(t="/"),Qa(t);if(Array.isArray(t))return t;throw new xe("Must be a string, Uint8Array, Component[], or another Multiaddr")}var co=class t{[gs]=!0;#e;#t;#r;constructor(e="/",r={}){this.#e=Ud(e),r.validate!==!1&&Md(this)}get bytes(){return this.#r==null&&(this.#r=Xa(this.#e)),this.#r}toString(){return this.#t==null&&(this.#t=Ja(this.#e)),this.#t}toJSON(){return this.toString()}getComponents(){return[...this.#e.map(e=>({...e}))]}encapsulate(e){let r=new t(e);return new t([...this.#e,...r.getComponents()],{validate:!1})}decapsulate(e){let r=e.toString(),n=this.toString(),s=n.lastIndexOf(r);if(s<0)throw new Xn(`Address ${this.toString()} does not contain subaddress: ${r}`);return new t(n.slice(0,s),{validate:!1})}decapsulateCode(e){let r;for(let n=this.#e.length-1;n>-1;n--)if(this.#e[n].code===e){r=n;break}return new t(this.#e.slice(0,r),{validate:!1})}equals(e){return De(this.bytes,e.bytes)}[Nd](){return`Multiaddr(${this.toString()})`}};function Md(t){t.getComponents().forEach(e=>{let r=lt.getProtocol(e.code);e.value!=null&&r.validate?.(e.value)})}function ao(t){return!!t?.[gs]}function Fe(t){return new co(t)}var W=t=>({match:e=>{let r=e[0];return r==null||r.code!==t||r.value!=null?!1:e.slice(1)}}),S=(t,e)=>({match:r=>{let n=r[0];return n?.code!==t||n.value==null||e!=null&&n.value!==e?!1:r.slice(1)}}),eu=t=>({match:e=>t.match(e)===!1?e:!1}),O=t=>({match:e=>{let r=t.match(e);return r===!1?e:r}}),Se=(...t)=>({match:e=>{let r;for(let n of t){let s=n.match(e);s!==!1&&(r==null||s.length<r.length)&&(r=s)}return r??!1}}),R=(...t)=>({match:e=>{for(let r of t){let n=r.match(e);if(n===!1)return!1;e=n}return e}});function Y(...t){function e(s){if(s==null)return!1;let o=s.getComponents();for(let c of t){let i=c.match(o);if(i===!1)return!1;o=i}return o}function r(s){return e(s)!==!1}function n(s){let o=e(s);return o===!1?!1:o.length===0}return{matchers:t,matches:r,exactMatch:n}}var Fd=S(421),F0=Y(Fd),lo=S(54),fo=S(55),ho=S(56),xs=S(53),K0=Y(lo,O(S(421))),$0=Y(fo,O(S(421))),H0=Y(ho,O(S(421))),z0=Y(Se(xs,ho,lo,fo),O(S(421))),tu=R(S(4),O(S(43))),ru=R(O(S(42)),S(41),O(S(43))),Es=Se(tu,ru),cr=Se(Es,xs,lo,fo,ho),V0=Y(Se(Es,R(Se(xs,ho,lo,fo),O(S(421))))),G0=Y(tu),W0=Y(ru),Y0=Y(Es),vs=R(cr,S(6)),Yr=R(cr,S(273)),nu=Y(R(vs,O(S(421)))),q0=Y(Yr),Ss=R(Yr,W(460),O(S(421))),po=R(Yr,W(461),O(S(421))),Kd=Se(Ss,po),Z0=Y(Ss),j0=Y(po),ws=Se(cr,vs,Yr,Ss,po),ou=Se(R(ws,W(477),O(S(421)))),X0=Y(ou),iu=Se(R(ws,W(478),O(S(421))),R(ws,W(448),O(S(449)),W(477),O(S(421)))),Q0=Y(iu),su=R(Yr,W(280),O(S(466)),O(S(466)),O(S(421))),J0=Y(su),cu=R(po,W(465),O(S(466)),O(S(466)),O(S(421))),ew=Y(cu),uo=Se(ou,iu,R(vs,O(S(421))),R(Kd,O(S(421))),R(cr,O(S(421))),su,cu,S(421)),tw=Y(uo),$d=R(O(uo),W(290),eu(W(281)),O(S(421))),rw=Y($d),Hd=Se(R(uo,W(290),W(281),O(S(421))),R(uo,W(281),O(S(421))),R(W(281),O(S(421)))),nw=Y(Hd),zd=R(cr,Se(R(S(6,"80")),R(S(6),W(480)),W(480)),O(S(481)),O(S(421))),ow=Y(zd),Vd=R(cr,Se(R(S(6,"443")),R(S(6,"443"),W(480)),R(S(6),W(443)),R(S(6),W(448),W(480)),R(W(448),W(480)),W(448),W(443)),O(S(481)),O(S(421))),iw=Y(Vd),Gd=Se(R(S(777),O(S(421)))),sw=Y(Gd),Wd=Se(R(S(400),O(S(421)))),qr=Y(Wd);var mo=class extends Event{type;detail;constructor(e,r){super(e),this.type=e,this.detail=r}};var mu=_e(le("node:net"),1);function Yd(t){let e=t.getComponents(),r={},n=0;return e[n]?.name==="ip6zone"&&(r.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"?(r.type=e[n].name,r.host=e[n].value,n++):e[n]?.name==="dnsaddr"&&(r.type=e[n].name,r.host=`_dnsaddr.${e[n].value}`,n++),(e[n]?.name==="tcp"||e[n]?.name==="udp")&&(r.protocol=e[n].name==="tcp"?"tcp":"udp",r.port=parseInt(`${e[n].value}`),n++),e[n]?.name==="ipcidr"&&(r.type==="ip4"?r.cidr=parseInt(`${e[n].value}`):r.type==="ip6"&&(r.cidr=`${e[n].value}`),n++),r.type==null||r.host==null?null:(e[n]?.name==="tls"&&e[n+1]?.name==="sni"&&(r.sni=e[n+1].value,n+=2),r)}function yo(t){let e=Yd(t);if(e==null)throw new B(`Multiaddr ${t} was not an IPv4, IPv6, DNS, DNS4, DNS6 or DNSADDR address`);return e}function bo(){let t={};return t.promise=new Promise((e,r)=>{t.resolve=e,t.reject=r}),t}var go=class{buffer;mask;top;btm;next;constructor(e){if(!(e>0)||(e-1&e)!==0)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(e),this.mask=e-1,this.top=0,this.btm=0,this.next=null}push(e){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=e,this.top=this.top+1&this.mask,!0)}shift(){let e=this.buffer[this.btm];if(e!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,e}isEmpty(){return this.buffer[this.btm]===void 0}},ar=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new go(this.hwm),this.tail=this.head,this.size=0}calculateSize(e){return e?.byteLength!=null?e.byteLength:1}push(e){if(e?.value!=null&&(this.size+=this.calculateSize(e.value)),!this.head.push(e)){let r=this.head;this.head=r.next=new go(2*this.head.buffer.length),this.head.push(e)}}shift(){let e=this.tail.shift();if(e===void 0&&this.tail.next!=null){let r=this.tail.next;this.tail.next=null,this.tail=r,e=this.tail.shift()}return e?.value!=null&&(this.size-=this.calculateSize(e.value)),e}isEmpty(){return this.head.isEmpty()}};var Ts=class extends Error{type;code;constructor(e,r){super(e??"The operation was aborted"),this.type="aborted",this.code=r??"ABORT_ERR"}};function wo(t={}){return qd(r=>{let n=r.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},t)}function qd(t,e){e=e??{};let r=e.onEnd,n=new ar,s,o,c,i=bo(),a=async()=>{try{return n.isEmpty()?c?{done:!0}:await new Promise((b,y)=>{o=T=>{o=null,n.push(T);try{b(t(n))}catch(P){y(P)}return s}}):t(n)}finally{n.isEmpty()&&queueMicrotask(()=>{i.resolve(),i=bo()})}},u=b=>o!=null?o(b):(n.push(b),s),l=b=>(n=new ar,o!=null?o({error:b}):(n.push({error:b}),s)),f=b=>{if(c)return s;if(e?.objectMode!==!0&&b?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return u({done:!1,value:b})},d=b=>c?s:(c=!0,b!=null?l(b):u({done:!0})),p=()=>(n=new ar,d(),{done:!0}),x=b=>(d(b),{done:!0});if(s={[Symbol.asyncIterator](){return this},next:a,return:p,throw:x,push:f,end:d,get readableLength(){return n.size},onEmpty:async b=>{let y=b?.signal;if(y?.throwIfAborted(),n.isEmpty())return;let T,P;y!=null&&(T=new Promise((_,M)=>{P=()=>{M(new Ts)},y.addEventListener("abort",P)}));try{await Promise.race([i.promise,T])}finally{P!=null&&y!=null&&y?.removeEventListener("abort",P)}}},r==null)return s;let D=s;return s={[Symbol.asyncIterator](){return this},next(){return D.next()},throw(b){return D.throw(b),r!=null&&(r(b),r=void 0),{done:!0}},return(){return D.return(),r!=null&&(r(),r=void 0),{done:!0}},push:f,end(b){return D.end(b),r!=null&&(r(b),r=void 0),s},get readableLength(){return D.readableLength},onEmpty:b=>D.onEmpty(b)},s}var As=class t extends Error{name="TimeoutError";constructor(e,r){super(e,r),Error.captureStackTrace?.(this,t)}},Zd=t=>"reason"in t?t.reason:new DOMException("This operation was aborted.","AbortError"),jd=2**31-1,Xd=(t,e)=>{if(typeof t!="number"||Math.sign(t)!==1)return new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${t}\``);if(typeof e?.setTimeout!="function"||typeof e?.clearTimeout!="function")return new TypeError("Expected `customTimers` to have a `setTimeout` and a `clearTimeout` function")};function Ds(t,e){let{milliseconds:r,fallback:n,message:s,customTimers:o={setTimeout,clearTimeout},signal:c}=e,i,a,u=()=>{try{t.cancel?.()}catch{}},f=new Promise((d,p)=>{let x=()=>{p(Zd(c)),u()},D=Xd(r,o);try{D?p(D):c?.aborted?x():c&&(a=x,c.addEventListener("abort",a,{once:!0}))}finally{t.then(d,p)}if(D||c?.aborted||r>jd)return;let b=n||s===!1||s instanceof Error?void 0:new As(s??`Promise timed out after ${r} milliseconds`);i=o.setTimeout.call(void 0,()=>{if(n)try{d(n())}catch(y){p(y)}else s===!1?d():p(s instanceof Error?s:b);u()},r)}).finally(()=>{try{f.clear()}catch{}try{a&&c.removeEventListener("abort",a)}catch{}});return f.clear=()=>{i!==void 0&&(o.clearTimeout.call(void 0,i),i=void 0)},f}var au=t=>typeof t=="function"?{filter:t}:{...t},Qd=t=>t===1/0||Number.isSafeInteger(t)&&t>=0,Jd=[["addEventListener","removeEventListener"],["on","off"],["addListener","removeListener"]],eh=t=>{for(let[e,r]of Jd){let n=t?.[e],s=t?.[r];if(typeof n=="function"&&typeof s=="function")return{addListener:n.bind(t),removeListener:s.bind(t)}}throw new TypeError("Emitter is not compatible")},th=t=>{let e=new Map;for(let[r,n]of t)for(let s of Array.isArray(r)?r:[r])e.has(s)||e.set(s,n);return e},rh=({addListener:t,removeListener:e,handlers:r,signal:n,abortHandler:s,isDone:o})=>{n?.addEventListener("abort",s,{once:!0});for(let[c,i]of r)if(t(c,i),o()){e(c,i);return}},nh=({removeListener:t,handlers:e,signal:r,abortHandler:n})=>{for(let[s,o]of e)t(s,o);r?.removeEventListener("abort",n)},oh=(t,e,r)=>{let n=Promise.resolve();return(s,o)=>{n=n.then(async()=>{if(e())return;let c;try{c=t?await t(s):!0}catch(i){e()||r(i);return}e()||o(c)})}};function ih(t,e,r){let n=()=>{},s=!1,o,c=new Promise((i,a)=>{r=au(r);let{filter:u}=r;if(!Qd(r.count))throw new TypeError("The `count` option should be at least 0 or more");if(typeof r.timeout=="number"&&!(r.timeout>0))throw new TypeError(`Expected the \`timeout\` option to be a positive number, got \`${r.timeout}\``);r.signal?.throwIfAborted();let{addListener:l,removeListener:f}=eh(t);if(r.count===0){i([]);return}let d=[],p=_=>{n(),a(_)},x=oh(u,()=>s,p),D=_=>{d.push(_),r.count===d.length&&(n(),i(d))},b=(..._)=>{if(s)return;let M=r.multiArgs?_:_[0];if(!u){D(M);return}x(M,X=>{X&&D(M)})},y=(..._)=>{p(r.rejectionMultiArgs?_:_[0])},T=()=>{p(r.signal.reason)},P={addListener:l,removeListener:f,handlers:th([[e,b],[r.rejectionEvents??["error"],y]]),signal:r.signal,abortHandler:T,isDone:()=>s};n=()=>{s=!0,clearTimeout(o),nh(P)},rh(P),!(s||!r.resolveImmediately)&&(Number.isFinite(r.timeout)&&r.timeout<=2**31-1&&(o=setTimeout(n,r.timeout)),i(d))});if(c.cancel=n,typeof r.timeout=="number"&&r.timeout>0&&!r.resolveImmediately){let i=Ds(c,{milliseconds:r.timeout});return i.cancel=()=>{n(),i.clear()},i}return c}function tt(t,e,r){let n=ih(t,e,{...au(r),count:1,resolveImmediately:!1}),s=n.then(o=>o[0]);return s.cancel=n.cancel,s}var Nt=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"};var xo=class extends Error{static name="StreamClosedError";name="StreamClosedError"};function sh(t){return t.reason}function Zr(t,e,r){if(e==null||t==null)return t;let n=r?.translateError??sh;if(e.aborted)return t.catch(()=>{}),Promise.reject(n(e));let s;return Promise.race([t,new Promise((o,c)=>{s=()=>{c(n(e))},e.addEventListener("abort",s)})]).finally(()=>{s!=null&&e.removeEventListener("abort",s)})}var ch=Math.pow(2,20)*4,Eo=class extends Wt{status;timeline;inactivityTimeout;maxReadBufferLength;maxWriteBufferLength;log;direction;maxMessageSize;readStatus;writeStatus;remoteReadStatus;remoteWriteStatus;writableNeedsDrain;readBuffer;writeBuffer;sendingData;#e=!1;#t;#r=new Set;onDrainPromise;constructor(e){super(),this.status="open",this.log=e.log,this.direction=e.direction??"outbound",this.inactivityTimeout=e.inactivityTimeout??12e4,this.maxReadBufferLength=e.maxReadBufferLength??ch,this.maxWriteBufferLength=e.maxWriteBufferLength,this.maxMessageSize=e.maxMessageSize,this.readBuffer=new oe,this.writeBuffer=new oe,this.readStatus="readable",this.remoteReadStatus="readable",this.writeStatus="writable",this.remoteWriteStatus="writable",this.sendingData=!1,this.writableNeedsDrain=!1,this.timeline={open:Date.now()},this.processSendQueue=this.processSendQueue.bind(this);let r=()=>{this.writableNeedsDrain&&(this.log.trace("drain event received, continue sending data"),this.writableNeedsDrain=!1,queueMicrotask(()=>{try{this.processSendQueue()}catch(s){this.log.error("processSendQueue threw - %e",s)}})),this.onDrainPromise?.resolve()};this.addEventListener("drain",r);let n=s=>{this.onDrainPromise?.reject(s.error??new xo)};this.addEventListener("close",n)}get readBufferLength(){return this.readBuffer.byteLength}get readableEnded(){return this.#e}get writeBufferLength(){return this.writeBuffer.byteLength}async onDrain(e){return this.writableNeedsDrain!==!0?Promise.resolve():(this.onDrainPromise==null&&(this.onDrainPromise=Promise.withResolvers()),Zr(this.onDrainPromise.promise,e?.signal))}async*[Symbol.asyncIterator](){let e=wo(),r,n=o=>{e.push(o.data)};this.addEventListener("message",n);let s=()=>{this.#r.delete(s),this.removeEventListener("message",n),r=this.#t,e.end()};this.#r.add(s),this.readableDone()&&s();try{if(yield*e,r!=null)throw r}finally{this.removeEventListener("message",n),this.#r.delete(s)}}readableDone(){return this.readBuffer.byteLength===0&&(this.remoteWriteStatus==="closed"||this.readStatus==="closing"||this.readStatus==="closed")}isReadable(){return this.status==="open"}send(e){if(this.writeStatus==="closed"||this.writeStatus==="closing")throw new bt(`Cannot write to a stream that is ${this.writeStatus}`);return this.log.trace("append %d bytes to write buffer",e.byteLength),this.writeBuffer.append(e),this.processSendQueue()}abort(e){if(this.status==="aborted"||this.status==="reset"||this.status==="closed"){this.readBuffer.byteLength>0&&(this.#t??=e,this.readBuffer.consume(this.readBuffer.byteLength),this.readStatus="closed",this.maybeDispatchEnd());return}this.log.error("abort with error - %e",e),this.status="aborted",this.#t=e,this.readBuffer.byteLength>0&&this.readBuffer.consume(this.readBuffer.byteLength),this.writeBuffer.byteLength>0&&(this.writeBuffer.consume(this.writeBuffer.byteLength),this.safeDispatchEvent("idle")),this.writeStatus="closed",this.remoteWriteStatus="closed",this.readStatus="closed",this.remoteReadStatus="closed",this.timeline.close=Date.now(),this.maybeDispatchEnd();try{this.sendReset(e)}catch(r){this.log.error("failed to send reset to remote - %e",r)}this.dispatchEvent(new hn(e))}pause(){if(this.readStatus==="closed"||this.readStatus==="closing")throw new bt("Cannot pause a stream that is closing/closed");this.readStatus!=="paused"&&(this.readStatus="paused",this.sendPause())}resume(){if(this.readStatus==="closed"||this.readStatus==="closing")throw new bt("Cannot resume a stream that is closing/closed");this.readStatus!=="readable"&&(this.readStatus="readable",this.dispatchReadBuffer(),this.sendResume())}push(e){if(this.readStatus==="closed"||this.readStatus==="closing")throw new bt(`Cannot push data onto a stream that is ${this.readStatus}`);if(e.byteLength!==0){if(this.readBuffer.append(e),this.readStatus==="paused"||this.listenerCount("message")===0){this.checkReadBufferLength();return}setTimeout(()=>{this.dispatchReadBuffer()},0)}}unshift(e){if(this.readStatus==="closed"||this.readStatus==="closing")throw new bt(`Cannot push data onto a stream that is ${this.readStatus}`);if(e.byteLength!==0){if(this.readBuffer.prepend(e),this.readStatus==="paused"||this.listenerCount("message")===0){this.checkReadBufferLength();return}setTimeout(()=>{this.dispatchReadBuffer()},0)}}onData(e){if(e.byteLength!==0){if(this.readStatus==="closing"||this.readStatus==="closed"){this.log("ignoring data - read status %s",this.readStatus);return}this.readBuffer.append(e),this.dispatchReadBuffer()}}addEventListener(...e){super.addEventListener.apply(this,e),e[0]==="message"&&this.readBuffer.byteLength>0&&queueMicrotask(()=>{this.dispatchReadBuffer()})}onRemoteReset(){if(this.status==="aborted"||this.status==="reset"||this.status==="closed")return;this.log("remote reset");let e=new an;this.#t=e,this.status="reset",this.writeStatus="closed",this.remoteWriteStatus="closed",this.remoteReadStatus="closed",this.timeline.close=Date.now(),this.readBuffer.byteLength===0&&(this.readStatus="closed",this.maybeDispatchEnd()),this.dispatchEvent(new pn(e))}onTransportClosed(e){this.log("transport closed"),this.readStatus==="readable"&&this.readBuffer.byteLength===0&&(this.log("close readable end after transport closed and read buffer is empty"),this.readStatus="closed"),this.remoteReadStatus!=="closed"&&(this.remoteReadStatus="closed"),this.remoteWriteStatus!=="closed"&&(this.remoteWriteStatus="closed"),this.writeStatus!=="closed"&&(this.writeStatus="closed"),e!=null?this.abort(e):(this.status==="open"||this.status==="closing")&&(this.timeline.close=Date.now(),this.status="closed",this.maybeDispatchEnd(),this.dispatchEvent(new Vt))}onRemoteCloseWrite(){this.remoteWriteStatus!=="closed"&&(this.log.trace("on remote close write"),this.remoteWriteStatus="closed",this.safeDispatchEvent("remoteCloseWrite"),this.maybeDispatchEnd(),this.writeStatus==="closed"&&this.onTransportClosed())}onRemoteCloseRead(){this.log.trace("on remote close read"),this.remoteReadStatus="closed",this.writeBuffer.byteLength>0&&(this.writeBuffer.consume(this.writeBuffer.byteLength),this.safeDispatchEvent("idle"))}processSendQueue(){if(this.writableNeedsDrain)return this.log.trace("not processing send queue as drain is required"),this.checkWriteBufferLength(),!1;if(this.writeBuffer.byteLength===0)return this.log.trace("not processing send queue as no bytes to send"),!0;if(this.sendingData)return this.log.trace("not processing send queue as already sending data"),!0;if(this.writeStatus!=="writable"&&this.writeStatus!=="closing")return this.log.trace("not processing send queue as stream is %s",this.writeStatus),!1;this.sendingData=!0,this.log.trace("processing send queue with %d queued bytes",this.writeBuffer.byteLength);try{let e=!0,r=this.writeBuffer.byteLength,n=0;for(;this.writeBuffer.byteLength>0;){let s=Math.min(this.maxMessageSize??this.writeBuffer.byteLength,this.writeBuffer.byteLength);if(s===0){e=!1;break}let o=this.writeBuffer.sublist(0,s),c=new oe(o);this.writeBuffer.consume(o.byteLength);let i;try{i=this.sendData(o)}catch(a){throw this.writeBuffer.prepend(c),this.abort(a),a}if(e=i.canSendMore,n+=i.sentBytes,i.sentBytes!==c.byteLength&&(c.consume(i.sentBytes),this.writeBuffer.prepend(c)),!e)break}return e||(this.log.trace("sent %d/%d bytes, pausing sending because underlying stream is full, %d bytes left in the write buffer",n,r,this.writeBuffer.byteLength),this.writableNeedsDrain=!0,this.checkWriteBufferLength()),this.writeBuffer.byteLength===0&&this.safeDispatchEvent("idle"),e}finally{this.sendingData=!1}}maybeDispatchEnd(){this.readableDone()&&(this.#r.forEach(e=>{e()}),!this.#e&&(this.#e=!0,this.safeDispatchEvent("end")))}dispatchReadBuffer(){try{if(this.listenerCount("message")===0){this.log.trace("not dispatching pause buffer as there are no listeners for the message event");return}if(this.readBuffer.byteLength===0){this.log.trace("not dispatching pause buffer as there is no data to dispatch");return}if(this.readStatus==="paused"){this.log.trace("not dispatching pause buffer we are paused");return}if(this.readStatus==="closing"||this.readStatus==="closed"){this.log("dropping %d bytes because the readable end is %s",this.readBuffer.byteLength,this.readStatus),this.readBuffer.consume(this.readBuffer.byteLength);return}let e=this.readBuffer.sublist();this.readBuffer.consume(e.byteLength),this.dispatchEvent(new dn(e))}finally{this.readBuffer.byteLength===0&&this.remoteWriteStatus==="closed"&&(this.log("close readable end after dispatching read buffer and remote writable end is closed"),this.readStatus="closed",this.maybeDispatchEnd()),this.checkReadBufferLength()}}checkReadBufferLength(){this.readBuffer.byteLength>this.maxReadBufferLength&&this.abort(new Bt(`Read buffer length of ${this.readBuffer.byteLength} exceeded limit of ${this.maxReadBufferLength}, read status is ${this.readStatus}`))}checkWriteBufferLength(){this.maxWriteBufferLength!=null&&this.writeBuffer.byteLength>this.maxWriteBufferLength&&this.abort(new Bt(`Write buffer length of ${this.writeBuffer.byteLength} exceeded limit of ${this.maxWriteBufferLength}, write status is ${this.writeStatus}`))}onMuxerNeedsDrain(){this.writableNeedsDrain=!0}onMuxerDrain(){this.safeDispatchEvent("drain")}};var vo=class extends Eo{remoteAddr;metricPrefix;metrics;constructor(e){super(e),this.metricPrefix=e.metricPrefix??"",this.metrics=e.metrics,this.remoteAddr=e.remoteAddr,this.addEventListener("close",r=>{this.metrics?.increment({[`${this.metricPrefix}end`]:!0}),r.error!=null?r.local?this.metrics?.increment({[`${this.metricPrefix}abort`]:!0}):this.metrics?.increment({[`${this.metricPrefix}reset`]:!0}):r.local?this.metrics?.increment({[`${this.metricPrefix}_local_close`]:!0}):this.metrics?.increment({[`${this.metricPrefix}_remote_close`]:!0})})}async close(e){this.status==="open"&&(this.status="closing",this.writeStatus="closing",this.remoteWriteStatus="closing",this.remoteReadStatus="closing",(this.sendingData||this.writeBuffer.byteLength>0)&&(this.log("waiting for write queue to become idle before closing writable end of stream, %d unsent bytes",this.writeBuffer.byteLength),await tt(this,"idle",{...e,rejectionEvents:["close"]})),this.writableNeedsDrain&&(this.log("waiting for write queue to drain before closing writable end of stream, %d unsent bytes",this.writeBuffer.byteLength),await tt(this,"drain",{...e,rejectionEvents:["close"]})),await this.sendClose(e),this.onTransportClosed())}};var lu=_e(le("node:os"),1);function uu(t){return!!(t.startsWith("169.254.")||t.toLowerCase().startsWith("fe80"))}function Is(t,e,r){let n=[t.type,r??t.host];if(t.protocol!=null){let s=e??t.port;s!=null&&n.push(t.protocol,s)}return t.type==="ip6"&&t.zone!=null&&n.unshift("ip6zone",t.zone),t.cidr!=null&&n.push("ipcidr",t.cidr),Fe(`/${n.join("/")}`)}var ah={4:"IPv4",6:"IPv6"};function uh(t){return["0.0.0.0","::"].includes(t)}function lh(t){let e=[],r=lu.default.networkInterfaces();for(let[,n]of Object.entries(r))if(n!=null)for(let s of n)uu(s.address)||s.family===ah[t]&&e.push(s.address);return e}function fu(t,e){if(t==null)return[];let r=yo(t);return(r.type==="ip4"||r.type==="ip6")&&uh(r.host)?lh(r.type==="ip4"?4:6).map(n=>Is(r,e,n)):[Is(r,e)]}function du(t,e){if(typeof t!="string")throw new B(`invalid ip provided: ${t}`);if(typeof e=="string"&&(e=parseInt(e)),isNaN(e))throw new B(`invalid port provided: ${e}`);if((0,Me.isIPv4)(t))return Fe(`/ip4/${t}/tcp/${e}`);if((0,Me.isIPv6)(t))return Fe(`/ip6/${t}/tcp/${e}`);throw new B(`invalid ip:port for creating a multiaddr: ${t}:${e}`)}var fh=4194304,So=class extends Error{static name="UnwrappedError";name="UnwrappedError"},Bs=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},Ls=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},Os=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function dh(t){return typeof t?.closeRead=="function"}function hh(t){return typeof t?.close=="function"}function Cs(t){return dh(t)?t.remoteWriteStatus!=="writable"&&t.readBufferLength===0:hh(t)?t.status!=="open":!1}function ph(t){return t?.addEventListener!=null&&t?.removeEventListener!=null&&t?.send!=null&&t?.push!=null&&t?.log!=null}function mh(t,e){let r=e?.maxBufferSize??fh,n=new oe,s,o=!1,c;if(!ph(t))throw new B("Argument should be a Stream or a Multiaddr");let i=f=>{if(!o&&c==null){if(n.append(f.data),n.byteLength>r){let d=n.byteLength;n.consume(d);let p=new Bt(`Read buffer overflow - ${d} > ${r}`);c=p,s?.reject(p),queueMicrotask(()=>{t.abort(p)});return}s?.resolve()}};t.addEventListener("message",i);let a=f=>{f.error!=null?s?.reject(f.error):s?.resolve()};t.addEventListener("close",a);let u=()=>{s?.resolve()};t.addEventListener("remoteCloseWrite",u);let l={readBuffer:n,async read(f){if(o===!0)throw new So("Stream was unwrapped");if(c!=null)throw c;if(Cs(t)){if(n.byteLength===0&&f?.bytes==null)return null;if(f?.bytes!=null&&n.byteLength<f.bytes)throw t.log.error("closed after reading %d/%d bytes",n.byteLength,f.bytes),new Nt(`Unexpected EOF - stream closed after reading ${n.byteLength}/${f.bytes} bytes`)}let d=f?.bytes??1;for(s=Promise.withResolvers();;){if(n.byteLength>=d){s.resolve();break}if(await Zr(s.promise,f?.signal),Cs(t)){if(n.byteLength===0&&f?.bytes==null)return null;break}s=Promise.withResolvers()}let p=f?.bytes??n.byteLength;if(n.byteLength<p){if(Cs(t))throw t.log.error("closed while reading %d/%d bytes",n.byteLength,p),new Nt(`Unexpected EOF - stream closed while reading ${n.byteLength}/${p} bytes`);return l.read(f)}let x=n.sublist(0,p);return n.consume(p),x},async write(f,d){if(o===!0)throw new So("Stream was unwrapped");t.send(f)||await tt(t,"drain",{signal:d?.signal,rejectionEvents:["close"]})},unwrap(){return o||(o=!0,t.removeEventListener("message",i),t.removeEventListener("close",a),t.removeEventListener("remoteCloseWrite",u),n.byteLength>0&&(t.log("stream unwrapped with %d unread bytes",n.byteLength),t.unshift(n),n.consume(n.byteLength))),t}};return l}function yh(t,e={}){let r=mh(t,e);e.maxDataLength!=null&&e.maxLengthLength==null&&(e.maxLengthLength=Be(e.maxDataLength));let n=e?.lengthDecoder??fr,s=e?.lengthEncoder??Us;return{async read(c){let i=-1,a=new oe;for(;;){let l=await r.read({...c,bytes:1});if(l==null)break;a.append(l);try{i=n(a)}catch(f){if(f instanceof RangeError)continue;throw f}if(i<0)throw new Bs("Invalid message length");if(e?.maxLengthLength!=null&&a.byteLength>e.maxLengthLength)throw new Os(`Message length length too long - ${a.byteLength} > ${e.maxLengthLength}`);if(i>-1)break}if(e?.maxDataLength!=null&&i>e.maxDataLength)throw new Ls(`Message length too long - ${i} > ${e.maxDataLength}`);let u=await r.read({...c,bytes:i});if(u==null)throw t.log.error("tried to read %d bytes but the stream closed",i),new Nt(`Unexpected EOF - tried to read ${i} bytes but the stream closed`);if(u.byteLength!==i)throw t.log.error("read %d/%d bytes before the stream closed",u.byteLength,i),new Nt(`Unexpected EOF - read ${u.byteLength}/${i} bytes before the stream closed`);return u},async write(c,i){await r.write(new oe(s(c.byteLength),c),i)},async writeV(c,i){let a=new oe(...c.flatMap(u=>[s(u.byteLength),u]));await r.write(a,i)},unwrap(){return r.unwrap()}}}function ks(t,e){let r=yh(t,e),n={read:async(s,o)=>{let c=await r.read(o);return s.decode(c,o)},write:async(s,o,c)=>{await r.write(o.encode(s),c)},writeV:async(s,o,c)=>{await r.writeV(s.map(i=>o.encode(i)),c)},pb:s=>({read:async o=>n.read(s,o),write:async(o,c)=>n.write(o,s,c),writeV:async(o,c)=>n.writeV(o,s,c),unwrap:()=>n}),unwrap:()=>r.unwrap()};return n}var _s=class extends vo{socket;constructor(e){let r=e.remoteAddr;if(e.localAddr!=null&&qr.matches(e.localAddr))r=e.localAddr;else if(r==null){if(e.socket.remoteAddress==null||e.socket.remotePort==null)throw new B("Could not determine remote address or port");r=du(e.socket.remoteAddress,e.socket.remotePort)}super({...e,remoteAddr:r}),this.socket=e.socket,this.socket.on("data",n=>{this.onData(n)}),this.socket.on("error",n=>{this.log("tcp error",r,n),this.abort(n)}),this.socket.setTimeout(e.inactivityTimeout??120*1e3),this.socket.once("timeout",()=>{this.log("tcp timeout",r),this.abort(new zt)}),this.socket.once("end",()=>{this.log("tcp end",r),this.onTransportClosed()}),this.socket.once("close",n=>{if(this.log("tcp close",r),n){this.abort(new Error("TCP transmission error"));return}this.onTransportClosed()}),this.socket.on("drain",()=>{this.log("tcp drain"),this.safeDispatchEvent("drain")})}sendData(e){let r=0,n=!0;for(let s of e)if(r+=s.byteLength,n=this.socket.write(s),!n)break;return{sentBytes:r,canSendMore:n}}async sendClose(e){this.socket.destroyed||(this.socket.destroySoon(),await tt(this.socket,"close",e))}sendReset(){if(this.socket.writableEnded){this.socket.destroy();return}if(qr.matches(this.remoteAddr)){this.socket.destroy();return}this.socket.resetAndDestroy()}sendPause(){this.socket.pause()}sendResume(){this.socket.resume()}},To=t=>new _s(t);var hu=_e(le("os"),1),pu=_e(le("path"),1);function Ao(t,e={}){if(qr.exactMatch(t)){let o=t.getComponents().find(c=>c.code===400)?.value;if(o==null)throw new B(`Multiaddr ${t} was not a Unix address`);return hu.default.platform()==="win32"?{path:pu.default.join("\\\\.\\pipe\\",o)}:{path:o}}let r=yo(t),n=r.host,s=r.port;return{host:n,port:s,ipv6Only:r.type==="ip6",...e}}var ge;(function(t){t[t.INACTIVE=0]="INACTIVE",t[t.ACTIVE=1]="ACTIVE",t[t.PAUSED=2]="PAUSED"})(ge||(ge={}));var Do=class extends Wt{context;server;sockets=new Set;status={code:ge.INACTIVE};metrics;addr;log;shutdownController;constructor(e){if(super(),this.context=e,e.keepAlive=e.keepAlive??!0,e.noDelay=e.noDelay??!0,e.allowHalfOpen=e.allowHalfOpen??!1,this.shutdownController=new AbortController,yn(1/0,this.shutdownController.signal),this.log=e.logger.forComponent("libp2p:tcp:listener"),this.addr="unknown",this.server=mu.default.createServer(e,this.onSocket.bind(this)),e.maxConnections!==void 0&&(this.server.maxConnections=e.maxConnections),e.closeServerOnMaxConnections!=null&&e.closeServerOnMaxConnections.closeAbove<e.closeServerOnMaxConnections.listenBelow)throw new B("closeAbove must be >= listenBelow");e.metrics?.registerMetricGroup("libp2p_tcp_inbound_connections_total",{label:"address",help:"Current active connections in TCP listener",calculate:()=>({[this.addr]:this.sockets.size})}),this.metrics={status:e.metrics?.registerMetricGroup("libp2p_tcp_listener_status_info",{label:"address",help:"Current status of the TCP listener socket"}),errors:e.metrics?.registerMetricGroup("libp2p_tcp_listener_errors_total",{label:"address",help:"Total count of TCP listener errors by type"}),events:e.metrics?.registerMetricGroup("libp2p_tcp_listener_events_total",{label:"address",help:"Total count of TCP listener events by type"})},this.server.on("listening",()=>{let r=this.server.address();r==null?this.addr="unknown":typeof r=="string"?this.addr=r:this.addr=`${r.address}:${r.port}`,this.metrics.status?.update({[this.addr]:ge.ACTIVE}),this.safeDispatchEvent("listening")}).on("error",r=>{this.metrics.errors?.increment({[`${this.addr} listen_error`]:!0}),this.safeDispatchEvent("error",{detail:r})}).on("close",()=>{this.metrics.status?.update({[this.addr]:this.status.code}),this.status.code!==ge.PAUSED&&this.safeDispatchEvent("close")}).on("drop",()=>{this.metrics.events?.increment({[`${this.addr} drop`]:!0})})}onSocket(e){if(this.metrics.events?.increment({[`${this.addr} connection`]:!0}),this.status.code!==ge.ACTIVE)throw e.destroy(),new ln("Server is not listening yet");let r;try{r=To({socket:e,inactivityTimeout:this.context.inactivityTimeout,metrics:this.metrics?.events,metricPrefix:`${this.addr} `,direction:"inbound",localAddr:this.status.listeningAddr,log:this.context.logger.forComponent("libp2p:tcp:connection")})}catch(n){this.log.error("inbound connection failed - %e",n),this.metrics.errors?.increment({[`${this.addr} inbound_to_connection`]:!0}),e.destroy();return}this.log("new inbound connection %s",r.remoteAddr),this.sockets.add(e),this.context.upgrader.upgradeInbound(r,{signal:this.shutdownController.signal}).then(()=>{this.log("inbound connection upgraded %s",r.remoteAddr),e.once("close",()=>{this.sockets.delete(e),this.context.closeServerOnMaxConnections!=null&&this.sockets.size<this.context.closeServerOnMaxConnections.listenBelow&&this.resume().catch(n=>{this.log.error("error attempting to listen server once connection count under limit - %e",n),this.context.closeServerOnMaxConnections?.onListenError?.(n)})}),this.context.closeServerOnMaxConnections!=null&&this.sockets.size>=this.context.closeServerOnMaxConnections.closeAbove&&(this.log("pausing incoming connections as limit is exceeded - %d/%d",this.sockets.size,this.context.closeServerOnMaxConnections.closeAbove),this.pause())}).catch(async n=>{this.log.error("inbound connection upgrade failed - %e",n),this.metrics.errors?.increment({[`${this.addr} inbound_upgrade`]:!0}),this.sockets.delete(e),r.abort(n)})}getAddrs(){if(this.status.code===ge.INACTIVE)return[];let e=this.server.address();return e==null?[]:typeof e=="string"?[Fe(`/unix/${encodeURIComponent(e)}`)]:fu(this.status.listeningAddr,e.port)}updateAnnounceAddrs(){}async listen(e){if(this.status.code===ge.ACTIVE||this.status.code===ge.PAUSED)throw new fn("server is already listening");try{this.status={code:ge.ACTIVE,listeningAddr:e,netConfig:Ao(e,this.context)},await this.resume()}catch(r){throw this.status={code:ge.INACTIVE},r}}async close(e){let r=[];this.server.listening&&r.push(tt(this.server,"close",e)),this.pause(!0),this.shutdownController.abort(),this.sockets.forEach(n=>{n.readable&&(r.push(tt(n,"close",e)),n.destroy())}),await Promise.all(r)}async resume(){if(this.server.listening||this.status.code===ge.INACTIVE)return;let e=this.status.netConfig;await new Promise((r,n)=>{this.server.once("error",n),this.server.listen(e,r)}),this.status={...this.status,code:ge.ACTIVE},this.log("listening on %s",this.server.address())}pause(e=!1){if(!this.server.listening&&this.status.code===ge.PAUSED&&e){this.status={code:ge.INACTIVE};return}!this.server.listening||this.status.code!==ge.ACTIVE||(this.log("%s server on %s",e?"closing":"pausing",this.server.address()),this.status=e?{code:ge.INACTIVE}:{...this.status,code:ge.PAUSED},this.server.close())}};var Io=class{opts;metrics;components;log;constructor(e,r={}){this.log=e.logger.forComponent("libp2p:tcp"),this.opts=r,this.components=e,e.metrics!=null&&(this.metrics={events:e.metrics.registerCounterGroup("libp2p_tcp_dialer_events_total",{label:"event",help:"Total count of TCP dialer events by type"}),errors:e.metrics.registerCounterGroup("libp2p_tcp_dialer_errors_total",{label:"event",help:"Total count of TCP dialer events by type"})})}[bc]=!0;[Symbol.toStringTag]="@libp2p/tcp";[xc]=["@libp2p/transport"];async dial(e,r){r.keepAlive=r.keepAlive??!0,r.noDelay=r.noDelay??!0,r.allowHalfOpen=r.allowHalfOpen??!1;let n=await this._connect(e,r),s;try{s=To({socket:n,inactivityTimeout:this.opts.outboundSocketInactivityTimeout,metrics:this.metrics?.events,direction:"outbound",remoteAddr:e,log:this.log.newScope("connection")})}catch(o){throw this.metrics?.errors.increment({outbound_to_connection:!0}),n.destroy(o),o}try{return this.log("new outbound connection %s",s.remoteAddr),await r.upgrader.upgradeOutbound(s,r)}catch(o){throw this.metrics?.errors.increment({outbound_upgrade:!0}),this.log.error("error upgrading outbound connection - %e",o),s.abort(o),o}}async _connect(e,r){r.signal.throwIfAborted(),r.onProgress?.(new mo("tcp:open-connection"));let n;return new Promise((s,o)=>{let c=Date.now(),i=Ao(e,{...this.opts.dialOpts??{},...r});this.log("dialing %a with opts %o",e,i),n=yu.default.connect(i);let a=p=>{this.log.error("dial to %a errored - %e",e,p);let x=i.path??`${i.host??""}:${i.port}`;p.message=`connection error ${x}: ${p.message}`,this.metrics?.events.increment({error:!0}),d(p)},u=()=>{this.log("connection timeout %a",e),this.metrics?.events.increment({timeout:!0});let p=new zt(`Connection timeout after ${Date.now()-c}ms`);n.emit("error",p)},l=()=>{this.log("connection opened %a",e),this.metrics?.events.increment({connect:!0}),d()},f=()=>{this.log("connection aborted %a",e),this.metrics?.events.increment({abort:!0}),d(new cn)},d=p=>{if(n.removeListener("error",a),n.removeListener("timeout",u),n.removeListener("connect",l),r.signal!=null&&r.signal.removeEventListener("abort",f),p!=null){o(p);return}s(n)};n.on("error",a),n.on("timeout",u),n.on("connect",l),r.signal.addEventListener("abort",f)}).catch(s=>{throw n?.destroy(),s})}createListener(e){return new Do({...this.opts.listenOpts??{},...e,maxConnections:this.opts.maxConnections,backlog:this.opts.backlog,closeServerOnMaxConnections:this.opts.closeServerOnMaxConnections,inactivityTimeout:this.opts.inboundSocketInactivityTimeout,metrics:this.components.metrics,logger:this.components.logger})}listenFilter(e){return e.filter(r=>nu.exactMatch(r)||r.toString().startsWith("/unix/"))}dialFilter(e){return this.listenFilter(e)}};function bu(t={}){return e=>new Io(e,t)}var bh=qt("libp2p:daemon-client:dht"),Co=class{client;constructor(e){this.client=e}async put(e,r){if(!(e instanceof Uint8Array))throw new B("invalid key received");if(!(r instanceof Uint8Array))throw new B("value received is not a Uint8Array");let n=await this.client.send({type:H.Type.DHT,dht:{type:Re.Type.PUT_VALUE,key:e,value:r}}),s=await n.read(L);if(bh("read",s),await n.unwrap().close(),s.type!==L.Type.OK)throw new _r(s.error?.msg??"DHT put failed")}async get(e){if(!(e instanceof Uint8Array))throw new B("invalid key received");let r=await this.client.send({type:H.Type.DHT,dht:{type:Re.Type.GET_VALUE,key:e}}),n=await r.read(L);if(await r.unwrap().close(),n.type!==L.Type.OK)throw new z(n.error?.msg??"DHT get failed");if(n.dht?.value==null)throw new z("Invalid DHT get response");return n.dht.value}async findPeer(e){if(!Gt(e))throw new B("invalid peer id received");let r=await this.client.send({type:H.Type.DHT,dht:{type:Re.Type.FIND_PEER,peer:e.toMultihash().bytes}}),n=await r.read(L);if(await r.unwrap().close(),n.type!==L.Type.OK)throw new z(n.error?.msg??"DHT find peer failed");if(n.dht?.peer?.addrs==null)throw new z("Invalid response");return{id:ct($e(n.dht.peer.id)),multiaddrs:n.dht.peer.addrs.map(s=>Fe(s))}}async provide(e){if(e==null||de.asCID(e)==null)throw new B("invalid cid received");let r=await this.client.send({type:H.Type.DHT,dht:{type:Re.Type.PROVIDE,cid:e.bytes}}),n=await r.read(L);if(await r.unwrap().close(),n.type!==L.Type.OK)throw new z(n.error?.msg??"DHT provide failed")}async*findProviders(e,r=1){if(e==null||de.asCID(e)==null)throw new B("invalid cid received");let n=await this.client.send({type:H.Type.DHT,dht:{type:Re.Type.FIND_PROVIDERS,cid:e.bytes,count:r}}),s=await n.read(L);if(s.type!==L.Type.OK)throw await n.unwrap().close(),new z(s.error?.msg??"DHT find providers failed");for(;;){let o=await n.read(He);if(o.type===He.Type.END){await n.unwrap().close();return}if(o.type===He.Type.VALUE&&o.peer?.addrs!=null)yield{id:ct($e(o.peer.id)),multiaddrs:o.peer.addrs.map(c=>Fe(c))};else throw await n.unwrap().close(),new _r("unexpected message received")}}async*getClosestPeers(e){if(!(e instanceof Uint8Array))throw new B("invalid key received");let r=await this.client.send({type:H.Type.DHT,dht:{type:Re.Type.GET_CLOSEST_PEERS,key:e}}),n=await r.read(L);if(n.type!==L.Type.OK)throw await r.unwrap().close(),new z(n.error?.msg??"DHT find providers failed");for(;;){let s=await r.read(He);if(s.type===He.Type.END){await r.unwrap().close();return}if(s.type===He.Type.VALUE&&s.value!=null)yield{id:ct($e(s.value)),multiaddrs:[]};else throw await r.unwrap().close(),new kr("unexpected message received")}}async getPublicKey(e){if(!Gt(e))throw new B("invalid peer id received");let r=await this.client.send({type:H.Type.DHT,dht:{type:Re.Type.GET_PUBLIC_KEY,peer:e.toMultihash().bytes}}),n=await r.read(L);if(await r.unwrap().close(),n.type!==L.Type.OK)throw new z(n.error?.msg??"DHT get public key failed");if(n.dht==null)throw new kr("Invalid response");return n.dht.value}};var Bo=class{client;constructor(e){this.client=e}async getTopics(){let e=await this.client.send({type:H.Type.PUBSUB,pubsub:{type:Xe.Type.GET_TOPICS}}),r=await e.read(L);if(await e.unwrap().close(),r.type!==L.Type.OK)throw new z(r.error?.msg??"Pubsub get topics failed");if(r.pubsub?.topics==null)throw new z("Invalid response");return r.pubsub.topics}async publish(e,r){if(typeof e!="string")throw new B("invalid topic received");if(!(r instanceof Uint8Array))throw new B("data received is not a Uint8Array");let n=await this.client.send({type:H.Type.PUBSUB,pubsub:{type:Xe.Type.PUBLISH,topic:e,data:r}}),s=await n.read(L);if(await n.unwrap().close(),s.type!==L.Type.OK)throw new z(s.error?.msg??"Pubsub publish failed")}async subscribe(e){if(typeof e!="string")throw new B("invalid topic received");let r=await this.client.send({type:H.Type.PUBSUB,pubsub:{type:Xe.Type.SUBSCRIBE,topic:e}}),n=await r.read(L);if(n.type!==L.Type.OK)throw new z(n.error?.msg??"Pubsub publish failed");let s=!0;return{async*messages(){for(;s;)yield await r.read(sn)},async cancel(){s=!1,await r.unwrap().close()}}}async getSubscribers(e){if(typeof e!="string")throw new B("invalid topic received");let r=await this.client.send({type:H.Type.PUBSUB,pubsub:{type:Xe.Type.LIST_PEERS,topic:e}}),n=await r.read(L);if(await r.unwrap().close(),n.type!==L.Type.OK)throw new z(n.error?.msg??"Pubsub get subscribers failed");if(n.pubsub?.topics==null)throw new z("Invalid response");return n.pubsub.peerIDs.map(s=>ct($e(s)))}};var St=qt("libp2p:daemon-client"),z=class extends Error{constructor(e="Operation failed"){super(e),this.name="OperationFailedError"}},Ps=class{multiaddr;dht;pubsub;tcp;constructor(e){this.multiaddr=e,this.tcp=bu()({logger:Bc()}),this.dht=new Co(this),this.pubsub=new Bo(this)}async connectDaemon(e){return this.tcp.dial(this.multiaddr,{upgrader:new Lr,signal:e??AbortSignal.timeout(1e4)})}async send(e){let r=await this.connectDaemon(),n=e.pubsub?.type??e.dht?.type??e.peerStore?.type??"";St("send",e.type,n);let s=ks(r);return await s.write(e,H),s}async connect(e,r){if(!Gt(e))throw new B("invalid peer id received");if(!Array.isArray(r))throw new B("addrs received are not in an array");r.forEach(o=>{if(!ao(o))throw new B("received an address that is not a multiaddr")});let n=await this.send({type:H.Type.CONNECT,connect:{peer:e.toMultihash().bytes,addrs:r.map(o=>o.bytes)}}),s=await n.read(L);if(St("%s response %s",H.Type.CONNECT,s.type),s.type!==L.Type.OK){let o=s.error??{msg:"unspecified"};throw new z(o.msg??"unspecified")}await n.unwrap().close()}async identify(){let e=await this.send({type:H.Type.IDENTIFY}),r=await e.read(L);if(St("%s response %s",H.Type.IDENTIFY,r.type),r.type!==L.Type.OK)throw new z(r.error?.msg??"Identify failed");if(r.identify?.addrs==null)throw new z("Invalid response");let n=ct($e(r.identify?.id)),s=r.identify.addrs.map(o=>Fe(o));return await e.unwrap().close(),{peerId:n,addrs:s}}async listPeers(){let e=await this.send({type:H.Type.LIST_PEERS}),r=await e.read(L);if(St("%s response %s",H.Type.LIST_PEERS,r.type),r.type!==L.Type.OK)throw new z(r.error?.msg??"List peers failed");return await e.unwrap().close(),r.peers.map(n=>ct($e(n.id)))}async openStream(e,r){if(!Gt(e))throw new B("invalid peer id received");if(typeof r!="string")throw new B("invalid protocol received");let n=await this.send({type:H.Type.STREAM_OPEN,streamOpen:{peer:e.toMultihash().bytes,proto:[r]}}),s=await n.read(L);if(St("%s response %s",H.Type.STREAM_OPEN,s.type),s.type!==L.Type.OK){let o=new z(s.error?.msg??"Open stream failed");throw n.unwrap().abort(o),o}return n.unwrap()}async registerStreamHandler(e,r){if(typeof e!="string")throw new B("invalid protocol received");let n=this.tcp.createListener({upgrader:new Lr(i=>{this.onConnection(e,n,r,i)})});await n.listen(Fe("/ip4/127.0.0.1/tcp/0"));let s=n.getAddrs()[0];if(s==null)throw new z("Could not listen on port");let o=await this.send({type:H.Type.STREAM_HANDLER,streamHandler:{addr:s.bytes,proto:[e]}}),c=await o.read(L);if(St("%s response %s",H.Type.STREAM_HANDLER,c.type),await o.unwrap().close(),c.type!==L.Type.OK)throw new z(c.error?.msg??"Register stream handler failed")}onConnection(e,r,n,s){Promise.resolve().then(async()=>{let o=ks(s).pb(Ct);if((await o.read()).proto!==e)throw new z("Incorrect protocol");await n(o.unwrap().unwrap())}).catch(o=>{s.abort(o)}).finally(()=>{s.close().catch(o=>{St.error("error closing connection - %e",o)}),r.close().catch(o=>{St.error("error closing listener - %e",o)})})}};function gh(t){return new Ps(t)}return Du(wh);})();
17
17
  /*! Bundled license information:
18
18
 
19
19
  @noble/curves/utils.js: