UNPKG

@chainsafe/libp2p-quic

Version:
2 lines 89.8 kB
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.ChainsafeLibp2PQuic = factory()}(typeof self !== 'undefined' ? self : this, function () { var co=Object.defineProperty;var V=(r,t)=>{for(var e in t)co(r,e,{get:t[e],enumerable:!0})};var Gr=Symbol.for("@libp2p/transport");var jr;(function(r){r[r.FATAL_ALL=0]="FATAL_ALL",r[r.NO_FATAL=1]="NO_FATAL"})(jr||(jr={}));var te=class extends Error{static name="AbortError";constructor(t="The operation was aborted"){super(t),this.name="AbortError"}};var ee=class extends Error{static name="StreamResetError";constructor(t="The stream has been reset"){super(t),this.name="StreamResetError"}},re=class extends Error{static name="StreamStateError";constructor(t="The stream is in an invalid state"){super(t),this.name="StreamStateError"}};import{setMaxListeners as uo}from"node:events";var ne=(r,...t)=>{try{uo(r,...t)}catch{}};var bt=class extends EventTarget{#t=new Map;constructor(){super(),ne(1/0,this)}listenerCount(t){let e=this.#t.get(t);return e==null?0:e.length}addEventListener(t,e,n){super.addEventListener(t,e,n);let o=this.#t.get(t);o==null&&(o=[],this.#t.set(t,o)),o.push({callback:e,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(t,e,n){super.removeEventListener(t.toString(),e??null,n);let o=this.#t.get(t);o!=null&&(o=o.filter(({callback:i})=>i!==e),this.#t.set(t,o))}dispatchEvent(t){let e=super.dispatchEvent(t),n=this.#t.get(t.type);return n==null||(n=n.filter(({once:o})=>!o),this.#t.set(t.type,n)),e}safeDispatchEvent(t,e={}){return this.dispatchEvent(new CustomEvent(t,e))}};var Qr=Symbol.for("@libp2p/service-capabilities"),$s=Symbol.for("@libp2p/service-dependencies");var Le={};V(Le,{base58btc:()=>M,base58flickr:()=>bo});var ha=new Uint8Array(0);function Yr(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function B(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")}function Xr(r){return new TextEncoder().encode(r)}function Jr(r){return new TextDecoder().decode(r)}function lo(r,t){if(r.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),n=0;n<e.length;n++)e[n]=255;for(var o=0;o<r.length;o++){var i=r.charAt(o),s=i.charCodeAt(0);if(e[s]!==255)throw new TypeError(i+" is ambiguous");e[s]=o}var a=r.length,h=r.charAt(0),p=Math.log(a)/Math.log(256),x=Math.log(256)/Math.log(a);function b(w){if(w instanceof Uint8Array||(ArrayBuffer.isView(w)?w=new Uint8Array(w.buffer,w.byteOffset,w.byteLength):Array.isArray(w)&&(w=Uint8Array.from(w))),!(w instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(w.length===0)return"";for(var _=0,d=0,v=0,T=w.length;v!==T&&w[v]===0;)v++,_++;for(var A=(T-v)*x+1>>>0,k=new Uint8Array(A);v!==T;){for(var U=w[v],tt=0,K=A-1;(U!==0||tt<d)&&K!==-1;K--,tt++)U+=256*k[K]>>>0,k[K]=U%a>>>0,U=U/a>>>0;if(U!==0)throw new Error("Non-zero carry");d=tt,v++}for(var Y=A-d;Y!==A&&k[Y]===0;)Y++;for(var Zt=h.repeat(_);Y<A;++Y)Zt+=r.charAt(k[Y]);return Zt}function N(w){if(typeof w!="string")throw new TypeError("Expected String");if(w.length===0)return new Uint8Array;var _=0;if(w[_]!==" "){for(var d=0,v=0;w[_]===h;)d++,_++;for(var T=(w.length-_)*p+1>>>0,A=new Uint8Array(T);w[_];){var k=e[w.charCodeAt(_)];if(k===255)return;for(var U=0,tt=T-1;(k!==0||U<v)&&tt!==-1;tt--,U++)k+=a*A[tt]>>>0,A[tt]=k%256>>>0,k=k/256>>>0;if(k!==0)throw new Error("Non-zero carry");v=U,_++}if(w[_]!==" "){for(var K=T-v;K!==T&&A[K]===0;)K++;for(var Y=new Uint8Array(d+(T-K)),Zt=d;K!==T;)Y[Zt++]=A[K++];return Y}}}function gt(w){var _=N(w);if(_)return _;throw new Error(`Non-${t} character`)}return{encode:b,decodeUnsafe:N,decode:gt}}var ho=lo,po=ho,tn=po;var Oe=class{name;prefix;baseEncode;constructor(t,e,n){this.name=t,this.prefix=e,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},Te=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,e,n){this.name=t,this.prefix=e;let o=e.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return en(this,t)}},ke=class{decoders;constructor(t){this.decoders=t}or(t){return en(this,t)}decode(t){let e=t[0],n=this.decoders[e];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function en(r,t){return new ke({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var Fe=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,e,n,o){this.name=t,this.prefix=e,this.baseEncode=n,this.baseDecode=o,this.encoder=new Oe(t,e,n),this.decoder=new Te(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function xt({name:r,prefix:t,encode:e,decode:n}){return new Fe(r,t,e,n)}function et({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=tn(e,r);return xt({prefix:t,name:r,encode:n,decode:i=>B(o(i))})}function fo(r,t,e,n){let o=r.length;for(;r[o-1]==="=";)--o;let i=new Uint8Array(o*e/8|0),s=0,a=0,h=0;for(let p=0;p<o;++p){let x=t[r[p]];if(x===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<e|x,s+=e,s>=8&&(s-=8,i[h++]=255&a>>s)}if(s>=e||(255&a<<8-s)!==0)throw new SyntaxError("Unexpected end of data");return i}function mo(r,t,e){let n=t[t.length-1]==="=",o=(1<<e)-1,i="",s=0,a=0;for(let h=0;h<r.length;++h)for(a=a<<8|r[h],s+=8;s>e;)s-=e,i+=t[o&a>>s];if(s!==0&&(i+=t[o&a<<e-s]),n)for(;(i.length*e&7)!==0;)i+="=";return i}function go(r){let t={};for(let e=0;e<r.length;++e)t[r[e]]=e;return t}function S({name:r,prefix:t,bitsPerChar:e,alphabet:n}){let o=go(n);return xt({prefix:t,name:r,encode(i){return mo(i,n,e)},decode(i){return fo(i,o,e,r)}})}var M=et({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),bo=et({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Ue={};V(Ue,{base32:()=>rt,base32hex:()=>yo,base32hexpad:()=>So,base32hexpadupper:()=>_o,base32hexupper:()=>Co,base32pad:()=>wo,base32padupper:()=>Eo,base32upper:()=>xo,base32z:()=>vo});var rt=S({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),xo=S({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),wo=S({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Eo=S({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),yo=S({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Co=S({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),So=S({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),_o=S({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),vo=S({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Ve={};V(Ve,{base36:()=>kt,base36upper:()=>Io});var kt=et({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Io=et({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var No=on,rn=128,Ao=127,Po=~Ao,Ro=Math.pow(2,31);function on(r,t,e){t=t||[],e=e||0;for(var n=e;r>=Ro;)t[e++]=r&255|rn,r/=128;for(;r&Po;)t[e++]=r&255|rn,r>>>=7;return t[e]=r|0,on.bytes=e-n+1,t}var Do=Be,Oo=128,nn=127;function Be(r,n){var e=0,n=n||0,o=0,i=n,s,a=r.length;do{if(i>=a)throw Be.bytes=0,new RangeError("Could not decode varint");s=r[i++],e+=o<28?(s&nn)<<o:(s&nn)*Math.pow(2,o),o+=7}while(s>=Oo);return Be.bytes=i-n,e}var To=Math.pow(2,7),ko=Math.pow(2,14),Fo=Math.pow(2,21),Lo=Math.pow(2,28),Uo=Math.pow(2,35),Vo=Math.pow(2,42),Bo=Math.pow(2,49),Mo=Math.pow(2,56),qo=Math.pow(2,63),Ko=function(r){return r<To?1:r<ko?2:r<Fo?3:r<Lo?4:r<Uo?5:r<Vo?6:r<Bo?7:r<Mo?8:r<qo?9:10},$o={encode:No,decode:Do,encodingLength:Ko},zo=$o,Ft=zo;function Lt(r,t=0){return[Ft.decode(r,t),Ft.decode.bytes]}function wt(r,t,e=0){return Ft.encode(r,t,e),t}function Et(r){return Ft.encodingLength(r)}function at(r,t){let e=t.byteLength,n=Et(r),o=n+Et(e),i=new Uint8Array(o+e);return wt(r,i,0),wt(e,i,n),i.set(t,o),new yt(r,e,t,i)}function sn(r){let t=B(r),[e,n]=Lt(t),[o,i]=Lt(t.subarray(n)),s=t.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new yt(e,o,s,t)}function an(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&Yr(r.bytes,e.bytes)}}var yt=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=n,this.bytes=o}};function cn(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return Wo(e,Me(r),t??M.encoder);default:return jo(e,Me(r),t??rt.encoder)}}var un=new WeakMap;function Me(r){let t=un.get(r);if(t==null){let e=new Map;return un.set(r,e),e}return t}var nt=class r{code;version;multihash;bytes;"/";constructor(t,e,n,o){this.code=e,this.version=t,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:e}=this;if(t!==Vt)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==Go)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(e)}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:t,digest:e}=this.multihash,n=at(t,e);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return r.equals(this,t)}static equals(t,e){let n=e;return n!=null&&t.code===n.code&&t.version===n.version&&an(t.multihash,n.multihash)}toString(t){return cn(this,t)}toJSON(){return{"/":cn(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let e=t;if(e instanceof r)return e;if(e["/"]!=null&&e["/"]===e.bytes||e.asCID===e){let{version:n,code:o,multihash:i,bytes:s}=e;return new r(n,o,i,s??ln(n,o,i.bytes))}else if(e[Qo]===!0){let{version:n,multihash:o,code:i}=e,s=sn(o);return r.create(n,i,s)}else return null}static create(t,e,n){if(typeof e!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(e!==Vt)throw new Error(`Version 0 CID must use dag-pb (code: ${Vt}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=ln(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,Vt,t)}static createV1(t,e){return r.create(1,t,e)}static decode(t){let[e,n]=r.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return e}static decodeFirst(t){let e=r.inspectBytes(t),n=e.size-e.multihashSize,o=B(t.subarray(n,n+e.multihashSize));if(o.byteLength!==e.multihashSize)throw new Error("Incorrect length");let i=o.subarray(e.multihashSize-e.digestSize),s=new yt(e.multihashCode,e.digestSize,i,o);return[e.version===0?r.createV0(s):r.createV1(e.codec,s),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[b,N]=Lt(t.subarray(e));return e+=N,b},o=n(),i=Vt;if(o===18?(o=0,e=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let s=e,a=n(),h=n(),p=e+h,x=p-s;return{version:o,codec:i,multihashCode:a,digestSize:h,multihashSize:x,size:p}}static parse(t,e){let[n,o]=Ho(t,e),i=r.decode(o);if(i.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Me(i).set(n,t),i}};function Ho(r,t){switch(r[0]){case"Q":{let e=t??M;return[M.prefix,e.decode(`${M.prefix}${r}`)]}case M.prefix:{let e=t??M;return[M.prefix,e.decode(r)]}case rt.prefix:{let e=t??rt;return[rt.prefix,e.decode(r)]}case kt.prefix:{let e=t??kt;return[kt.prefix,e.decode(r)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],t.decode(r)]}}}function Wo(r,t,e){let{prefix:n}=e;if(n!==M.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let o=t.get(n);if(o==null){let i=e.encode(r).slice(1);return t.set(n,i),i}else return o}function jo(r,t,e){let{prefix:n}=e,o=t.get(n);if(o==null){let i=e.encode(r);return t.set(n,i),i}else return o}var Vt=112,Go=18;function ln(r,t,e){let n=Et(r),o=n+Et(t),i=new Uint8Array(o+e.byteLength);return wt(r,i,0),wt(t,i,n),i.set(e,o),i}var Qo=Symbol.for("@ipld/js-cid/CID");var qe={};V(qe,{identity:()=>Jo});var hn=0,Yo="identity",pn=B;function Xo(r){return at(hn,pn(r))}var Jo={code:hn,name:Yo,encode:pn,digest:Xo};function ie(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}import{Buffer as dn}from"node:buffer";function ct(r){return new Uint8Array(r.buffer,r.byteOffset,r.byteLength)}function X(r=0){return ct(dn.alloc(r))}function $(r=0){return ct(dn.allocUnsafe(r))}import{Buffer as Zo}from"node:buffer";function ot(r,t){return ct(Zo.concat(r,t))}var mn=Symbol.for("@achingbrain/uint8arraylist");function fn(r,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let e=0;for(let n of r){let o=e+n.byteLength;if(t<o)return{buf:n,index:t-e};e=o}throw new RangeError("index is out of bounds")}function se(r){return!!r?.[mn]}var Ct=class r{bufs;length;[mn]=!0;constructor(...t){this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let e=0;for(let n of t)if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.push(n);else if(se(n))e+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}prepend(...t){this.prependAll(t)}prependAll(t){let e=0;for(let n of t.reverse())if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.unshift(n);else if(se(n))e+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}get(t){let e=fn(this.bufs,t);return e.buf[e.index]}set(t,e){let n=fn(this.bufs,t);n.buf[n.index]=e}write(t,e=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(e+n,t[n]);else if(se(t))for(let n=0;n<t.length;n++)this.set(e+n,t.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,e){let{bufs:n,length:o}=this._subList(t,e);return ot(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:ot(n,o)}sublist(t,e){let{bufs:n,length:o}=this._subList(t,e),i=new r;return i.length=o,i.bufs=[...n],i}_subList(t,e){if(t=t??0,e=e??this.length,t<0&&(t=this.length+t),e<0&&(e=this.length+e),t<0||e>this.length)throw new RangeError("index is out of bounds");if(t===e)return{bufs:[],length:0};if(t===0&&e===this.length)return{bufs:this.bufs,length:this.length};let n=[],o=0;for(let i=0;i<this.bufs.length;i++){let s=this.bufs[i],a=o,h=a+s.byteLength;if(o=h,t>=h)continue;let p=t>=a&&t<h,x=e>a&&e<=h;if(p&&x){if(t===a&&e===h){n.push(s);break}let b=t-a;n.push(s.subarray(b,b+(e-t)));break}if(p){if(t===0){n.push(s);continue}n.push(s.subarray(t-a));continue}if(x){if(e===h){n.push(s);break}n.push(s.subarray(0,e-a));break}n.push(s)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!se(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(e=Number(e??0),isNaN(e)&&(e=0),e<0&&(e=this.length+e),e<0&&(e=0),t.length===0)return e>this.length?this.length:e;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let i=256,s=new Int32Array(i);for(let b=0;b<i;b++)s[b]=-1;for(let b=0;b<o;b++)s[n[b]]=b;let a=s,h=this.byteLength-n.byteLength,p=n.byteLength-1,x;for(let b=e;b<=h;b+=x){x=0;for(let N=p;N>=0;N--){let gt=this.get(b+N);if(n[N]!==gt){x=Math.max(1,N-a[gt]);break}}if(x===0)return b}return-1}getInt8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getInt8(0)}setInt8(t,e){let n=$(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,e),this.write(n,t)}getInt16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,e)}setInt16(t,e,n){let o=X(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,e,n),this.write(o,t)}getInt32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,e)}setInt32(t,e,n){let o=X(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,e,n),this.write(o,t)}getBigInt64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,e)}setBigInt64(t,e,n){let o=X(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,e,n),this.write(o,t)}getUint8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getUint8(0)}setUint8(t,e){let n=$(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,e),this.write(n,t)}getUint16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,e)}setUint16(t,e,n){let o=X(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,e,n),this.write(o,t)}getUint32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,e)}setUint32(t,e,n){let o=X(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,e,n),this.write(o,t)}getBigUint64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,e)}setBigUint64(t,e,n){let o=X(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,e,n),this.write(o,t)}getFloat32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,e)}setFloat32(t,e,n){let o=X(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,e,n),this.write(o,t)}getFloat64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,e)}setFloat64(t,e,n){let o=X(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,e,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof r)||t.bufs.length!==this.bufs.length)return!1;for(let e=0;e<this.bufs.length;e++)if(!ie(this.bufs[e],t.bufs[e]))return!1;return!0}static fromUint8Arrays(t,e){let n=new r;return n.bufs=t,e==null&&(e=t.reduce((o,i)=>o+i.byteLength,0)),n.length=e,n}};import{Buffer as wi}from"node:buffer";var Ke={};V(Ke,{base10:()=>ti});var ti=et({prefix:"9",name:"base10",alphabet:"0123456789"});var $e={};V($e,{base16:()=>ei,base16upper:()=>ri});var ei=S({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),ri=S({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var ze={};V(ze,{base2:()=>ni});var ni=S({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var He={};V(He,{base256emoji:()=>ci});var gn=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),oi=gn.reduce((r,t,e)=>(r[e]=t,r),[]),ii=gn.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function si(r){return r.reduce((t,e)=>(t+=oi[e],t),"")}function ai(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let o=ii[n];if(o==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(o)}return new Uint8Array(t)}var ci=xt({prefix:"\u{1F680}",name:"base256emoji",encode:si,decode:ai});var je={};V(je,{base64:()=>ui,base64pad:()=>li,base64url:()=>We,base64urlpad:()=>hi});var ui=S({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),li=S({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),We=S({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),hi=S({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Ge={};V(Ge,{base8:()=>pi});var pi=S({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Qe={};V(Qe,{identity:()=>di});var di=xt({prefix:"\0",name:"identity",encode:r=>Jr(r),decode:r=>Xr(r)});var Qa=new TextEncoder,Ya=new TextDecoder;var Je={};V(Je,{sha256:()=>gi,sha512:()=>bi});import xn from"crypto";function Xe({name:r,code:t,encode:e}){return new Ye(r,t,e)}var Ye=class{name;code;encode;constructor(t,e,n){this.name=t,this.code=e,this.encode=n}digest(t){if(t instanceof Uint8Array){let e=this.encode(t);return e instanceof Uint8Array?at(this.code,e):e.then(n=>at(this.code,n))}else throw Error("Unknown type, must be binary type")}};var gi=Xe({name:"sha2-256",code:18,encode:r=>B(xn.createHash("sha256").update(r).digest())}),bi=Xe({name:"sha2-512",code:19,encode:r=>B(xn.createHash("sha512").update(r).digest())});var Bt={...Qe,...ze,...Ge,...Ke,...$e,...Ue,...Ve,...Le,...je,...He},lc={...Je,...qe};function En(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var wn=En("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Ze=En("ascii","a",r=>{let t="a";for(let e=0;e<r.length;e++)t+=String.fromCharCode(r[e]);return t},r=>{r=r.substring(1);let t=$(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),xi={utf8:wn,"utf-8":wn,hex:Bt.base16,latin1:Ze,ascii:Ze,binary:Ze,...Bt},ae=xi;function H(r,t="utf8"){let e=ae[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return t==="utf8"||t==="utf-8"?ct(wi.from(r,"utf-8")):e.decoder.decode(`${e.prefix}${r}`)}import{Buffer as Ei}from"node:buffer";function q(r,t="utf8"){let e=ae[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return t==="utf8"||t==="utf-8"?Ei.from(r.buffer,r.byteOffset,r.byteLength).toString("utf8"):e.encoder.encode(r).substring(1)}var yi=Math.pow(2,7),Ci=Math.pow(2,14),Si=Math.pow(2,21),tr=Math.pow(2,28),er=Math.pow(2,35),rr=Math.pow(2,42),nr=Math.pow(2,49),C=128,R=127;function W(r){if(r<yi)return 1;if(r<Ci)return 2;if(r<Si)return 3;if(r<tr)return 4;if(r<er)return 5;if(r<rr)return 6;if(r<nr)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Mt(r,t,e=0){switch(W(r)){case 8:t[e++]=r&255|C,r/=128;case 7:t[e++]=r&255|C,r/=128;case 6:t[e++]=r&255|C,r/=128;case 5:t[e++]=r&255|C,r/=128;case 4:t[e++]=r&255|C,r>>>=7;case 3:t[e++]=r&255|C,r>>>=7;case 2:t[e++]=r&255|C,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function or(r,t){let e=r[t],n=0;if(n+=e&R,e<C||(e=r[t+1],n+=(e&R)<<7,e<C)||(e=r[t+2],n+=(e&R)<<14,e<C)||(e=r[t+3],n+=(e&R)<<21,e<C)||(e=r[t+4],n+=(e&R)*tr,e<C)||(e=r[t+5],n+=(e&R)*er,e<C)||(e=r[t+6],n+=(e&R)*rr,e<C)||(e=r[t+7],n+=(e&R)*nr,e<C))return n;throw new RangeError("Could not decode varint")}function _i(r,t){let e=r.get(t),n=0;if(n+=e&R,e<C||(e=r.get(t+1),n+=(e&R)<<7,e<C)||(e=r.get(t+2),n+=(e&R)<<14,e<C)||(e=r.get(t+3),n+=(e&R)<<21,e<C)||(e=r.get(t+4),n+=(e&R)*tr,e<C)||(e=r.get(t+5),n+=(e&R)*er,e<C)||(e=r.get(t+6),n+=(e&R)*rr,e<C)||(e=r.get(t+7),n+=(e&R)*nr,e<C))return n;throw new RangeError("Could not decode varint")}function ir(r,t=0){return r instanceof Uint8Array?or(r,t):_i(r,t)}var sr=new Float32Array([-0]),it=new Uint8Array(sr.buffer);function yn(r,t,e){sr[0]=r,t[e]=it[0],t[e+1]=it[1],t[e+2]=it[2],t[e+3]=it[3]}function Cn(r,t){return it[0]=r[t],it[1]=r[t+1],it[2]=r[t+2],it[3]=r[t+3],sr[0]}var ar=new Float64Array([-0]),D=new Uint8Array(ar.buffer);function Sn(r,t,e){ar[0]=r,t[e]=D[0],t[e+1]=D[1],t[e+2]=D[2],t[e+3]=D[3],t[e+4]=D[4],t[e+5]=D[5],t[e+6]=D[6],t[e+7]=D[7]}function _n(r,t){return D[0]=r[t],D[1]=r[t+1],D[2]=r[t+2],D[3]=r[t+3],D[4]=r[t+4],D[5]=r[t+5],D[6]=r[t+6],D[7]=r[t+7],ar[0]}var Ii=BigInt(Number.MAX_SAFE_INTEGER),Ni=BigInt(Number.MIN_SAFE_INTEGER),F=class r{lo;hi;constructor(t,e){this.lo=t|0,this.hi=e|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(e+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(BigInt(e)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,e=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?e===0?t<16384?t<128?1:2:t<2097152?3:4:e<16384?e<128?5:6:e<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return ut;if(t<Ii&&t>Ni)return this.fromNumber(Number(t));let e=t<0n;e&&(t=-t);let n=t>>32n,o=t-(n<<32n);return e&&(n=~n|0n,o=~o|0n,++o>vn&&(o=0n,++n>vn&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(t){if(t===0)return ut;let e=t<0;e&&(t=-t);let n=t>>>0,o=(t-n)/4294967296>>>0;return e&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new r(n,o)}static from(t){return typeof t=="number"?r.fromNumber(t):typeof t=="bigint"?r.fromBigInt(t):typeof t=="string"?r.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new r(t.low>>>0,t.high>>>0):ut}},ut=new F(0,0);ut.toBigInt=function(){return 0n};ut.zzEncode=ut.zzDecode=function(){return this};ut.length=function(){return 1};var vn=4294967296n;function In(r){let t=0,e=0;for(let n=0;n<r.length;++n)e=r.charCodeAt(n),e<128?t+=1:e<2048?t+=2:(e&64512)===55296&&(r.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function Nn(r,t,e){if(e-t<1)return"";let o,i=[],s=0,a;for(;t<e;)a=r[t++],a<128?i[s++]=a:a>191&&a<224?i[s++]=(a&31)<<6|r[t++]&63:a>239&&a<365?(a=((a&7)<<18|(r[t++]&63)<<12|(r[t++]&63)<<6|r[t++]&63)-65536,i[s++]=55296+(a>>10),i[s++]=56320+(a&1023)):i[s++]=(a&15)<<12|(r[t++]&63)<<6|r[t++]&63,s>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,i)),s=0);return o!=null?(s>0&&o.push(String.fromCharCode.apply(String,i.slice(0,s))),o.join("")):String.fromCharCode.apply(String,i.slice(0,s))}function cr(r,t,e){let n=e,o,i;for(let s=0;s<r.length;++s)o=r.charCodeAt(s),o<128?t[e++]=o:o<2048?(t[e++]=o>>6|192,t[e++]=o&63|128):(o&64512)===55296&&((i=r.charCodeAt(s+1))&64512)===56320?(o=65536+((o&1023)<<10)+(i&1023),++s,t[e++]=o>>18|240,t[e++]=o>>12&63|128,t[e++]=o>>6&63|128,t[e++]=o&63|128):(t[e++]=o>>12|224,t[e++]=o>>6&63|128,t[e++]=o&63|128);return e-n}function z(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function ce(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var ur=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=t,this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,z(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw z(this,4);return ce(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw z(this,4);return ce(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw z(this,4);let t=Cn(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw z(this,4);let t=_n(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),e=this.pos,n=this.pos+t;if(n>this.len)throw z(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return Nn(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw z(this,t);this.pos+=t}else do if(this.pos>=this.len)throw z(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new F(0,0),e=0;if(this.len-this.pos>4){for(;e<4;++e)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;e=0}else{for(;e<3;++e){if(this.pos>=this.len)throw z(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<e*7)>>>0,t}if(this.len-this.pos>4){for(;e<5;++e)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;e<5;++e){if(this.pos>=this.len)throw z(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw z(this,8);let t=ce(this.buf,this.pos+=4),e=ce(this.buf,this.pos+=4);return new F(t,e)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=or(this.buf,this.pos);return this.pos+=W(t),t}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 lr(r){return new ur(r instanceof Uint8Array?r:r.subarray())}function ue(r,t,e){let n=lr(r);return t.decode(n,void 0,e)}function hr(r){let t=r??8192,e=t>>>1,n,o=t;return function(s){if(s<1||s>e)return $(s);o+s>t&&(n=$(t),o=0);let a=n.subarray(o,o+=s);return(o&7)!==0&&(o=(o|7)+1),a}}var lt=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function pr(){}var fr=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Ai=hr();function Pi(r){return globalThis.Buffer!=null?$(r):Ai(r)}var Kt=class{len;head;tail;states;constructor(){this.len=0,this.head=new lt(pr,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new lt(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new mr((t=t>>>0)<128?1:t<16384?2:t<2097152?3:t<268435456?4:5,t)).len,this}int32(t){return t<0?this._push(le,10,F.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=F.fromBigInt(t);return this._push(le,e.length(),e)}uint64Number(t){return this._push(Mt,W(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let e=F.fromBigInt(t).zzEncode();return this._push(le,e.length(),e)}sint64Number(t){let e=F.fromNumber(t).zzEncode();return this._push(le,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(dr,1,t?1:0)}fixed32(t){return this._push(qt,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=F.fromBigInt(t);return this._push(qt,4,e.lo)._push(qt,4,e.hi)}fixed64Number(t){let e=F.fromNumber(t);return this._push(qt,4,e.lo)._push(qt,4,e.hi)}fixed64String(t){return this.fixed64(BigInt(t))}sfixed64(t){return this.fixed64(t)}sfixed64Number(t){return this.fixed64Number(t)}sfixed64String(t){return this.fixed64String(t)}float(t){return this._push(yn,4,t)}double(t){return this._push(Sn,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(dr,1,0):this.uint32(e)._push(Di,e,t)}string(t){let e=In(t);return e!==0?this.uint32(e)._push(cr,e,t):this._push(dr,1,0)}fork(){return this.states=new fr(this),this.head=this.tail=new lt(pr,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 lt(pr,0,0),this.len=0),this}ldelim(){let t=this.head,e=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=e,this.len+=n),this}finish(){let t=this.head.next,e=Pi(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function dr(r,t,e){t[e]=r&255}function Ri(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var mr=class extends lt{next;constructor(t,e){super(Ri,t,e),this.next=void 0}};function le(r,t,e){for(;r.hi!==0;)t[e++]=r.lo&127|128,r.lo=(r.lo>>>7|r.hi<<25)>>>0,r.hi>>>=7;for(;r.lo>127;)t[e++]=r.lo&127|128,r.lo=r.lo>>>7;t[e++]=r.lo}function qt(r,t,e){t[e]=r&255,t[e+1]=r>>>8&255,t[e+2]=r>>>16&255,t[e+3]=r>>>24}function Di(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(Kt.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(Oi,t,r),this},Kt.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(Ti,t,r),this});function Oi(r,t,e){t.set(r,e)}function Ti(r,t,e){r.length<40?cr(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(H(r),e)}function gr(){return new Kt}function he(r,t){let e=gr();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var St;(function(r){r[r.VARINT=0]="VARINT",r[r.BIT64=1]="BIT64",r[r.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",r[r.START_GROUP=3]="START_GROUP",r[r.END_GROUP=4]="END_GROUP",r[r.BIT32=5]="BIT32"})(St||(St={}));function pe(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function br(r){function t(o){if(r[o.toString()]==null)throw new Error("Invalid enum value");return r[o]}let e=function(i,s){let a=t(i);s.int32(a)},n=function(i){let s=i.int32();return t(s)};return pe("enum",St.VARINT,e,n)}function de(r,t){return pe("message",St.LENGTH_DELIMITED,r,t)}var j;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1",r.ECDSA="ECDSA"})(j||(j={}));var xr;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1",r[r.ECDSA=3]="ECDSA"})(xr||(xr={}));(function(r){r.codec=()=>br(xr)})(j||(j={}));var wr;(function(r){let t;r.codec=()=>(t==null&&(t=de((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),j.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let i={},s=n==null?e.len:e.pos+n;for(;e.pos<s;){let a=e.uint32();switch(a>>>3){case 1:{i.Type=j.codec().decode(e);break}case 2:{i.Data=e.bytes();break}default:{e.skipType(a&7);break}}}return i})),t),r.encode=e=>he(e,r.codec()),r.decode=(e,n)=>ue(e,r.codec(),n)})(wr||(wr={}));var fe;(function(r){let t;r.codec=()=>(t==null&&(t=de((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),j.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let i={},s=n==null?e.len:e.pos+n;for(;e.pos<s;){let a=e.uint32();switch(a>>>3){case 1:{i.Type=j.codec().decode(e);break}case 2:{i.Data=e.bytes();break}default:{e.skipType(a&7);break}}}return i})),t),r.encode=e=>he(e,r.codec()),r.decode=(e,n)=>ue(e,r.codec(),n)})(fe||(fe={}));function Pn(r){return fe.encode({Type:j[r.type],Data:r.raw})}var P=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},J=class extends Error{static name="ValidationError";name="ValidationError"},$t=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},me=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};import{isIPv4 as ge,isIPv6 as Rn,isIP as ou}from"node:net";function yr(r){return t=>q(t,r)}function Cr(r){return t=>H(t,r)}function _t(r){return new DataView(r.buffer).getUint16(r.byteOffset).toString()}function ht(r){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,typeof r=="string"?parseInt(r):r),new Uint8Array(t)}function Dn(r){let t=r.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==16)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion address.`);let e=H(t[0],"base32"),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=ht(n);return ot([e,o],e.length+o.length)}function On(r){let t=r.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==56)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion3 address.`);let e=rt.decode(`b${t[0]}`),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=ht(n);return ot([e,o],e.length+o.length)}function Sr(r){let t=r.subarray(0,r.length-2),e=r.subarray(r.length-2),n=q(t,"base32"),o=_t(e);return`${n}:${o}`}var _r=function(r){r=r.toString().trim();let t=new Uint8Array(4);return r.split(/\./g).forEach((e,n)=>{let o=parseInt(e,10);if(isNaN(o)||o<0||o>255)throw new P("Invalid byte value in IP address");t[n]=o}),t},Tn=function(r){let t=0;r=r.toString().trim();let e=r.split(":",8),n;for(n=0;n<e.length;n++){let i=ge(e[n]),s;i&&(s=_r(e[n]),e[n]=q(s.subarray(0,2),"base16")),s!=null&&++n<8&&e.splice(n,0,q(s.subarray(2,4),"base16"))}if(e[0]==="")for(;e.length<8;)e.unshift("0");else if(e[e.length-1]==="")for(;e.length<8;)e.push("0");else if(e.length<8){for(n=0;n<e.length&&e[n]!=="";n++);let i=[n,1];for(n=9-e.length;n>0;n--)i.push("0");e.splice.apply(e,i)}let o=new Uint8Array(t+16);for(n=0;n<e.length;n++){e[n]===""&&(e[n]="0");let i=parseInt(e[n],16);if(isNaN(i)||i<0||i>65535)throw new P("Invalid byte value in IP address");o[t++]=i>>8&255,o[t++]=i&255}return o},kn=function(r){if(r.byteLength!==4)throw new P("IPv4 address was incorrect length");let t=[];for(let e=0;e<r.byteLength;e++)t.push(r[e]);return t.join(".")},Fn=function(r){if(r.byteLength!==16)throw new P("IPv6 address was incorrect length");let t=[];for(let n=0;n<r.byteLength;n+=2){let o=r[n],i=r[n+1],s=`${o.toString(16).padStart(2,"0")}${i.toString(16).padStart(2,"0")}`;t.push(s)}let e=t.join(":");try{let n=new URL(`http://[${e}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new P(`Invalid IPv6 address "${e}"`)}};function Ln(r){try{let t=new URL(`http://[${r}]`);return t.hostname.substring(1,t.hostname.length-1)}catch{throw new P(`Invalid IPv6 address "${r}"`)}}var Er=Object.values(Bt).map(r=>r.decoder),Fi=function(){let r=Er[0].or(Er[1]);return Er.slice(2).forEach(t=>r=r.or(t)),r}();function Un(r){return Fi.decode(r)}function Vn(r){return t=>r.encoder.encode(t)}function Li(r){if(parseInt(r).toString()!==r)throw new J("Value must be an integer")}function Ui(r){if(r<0)throw new J("Value must be a positive integer, or zero")}function Vi(r){return t=>{if(t>r)throw new J(`Value must be smaller than or equal to ${r}`)}}function Bi(...r){return t=>{for(let e of r)e(t)}}var zt=Bi(Li,Ui,Vi(65535));var I=-1,vr=class{protocolsByCode=new Map;protocolsByName=new Map;getProtocol(t){let e;if(typeof t=="string"?e=this.protocolsByName.get(t):e=this.protocolsByCode.get(t),e==null)throw new me(`Protocol ${t} was unknown`);return e}addProtocol(t){this.protocolsByCode.set(t.code,t),this.protocolsByName.set(t.name,t),t.aliases?.forEach(e=>{this.protocolsByName.set(e,t)})}removeProtocol(t){let e=this.protocolsByCode.get(t);e!=null&&(this.protocolsByCode.delete(e.code),this.protocolsByName.delete(e.name),e.aliases?.forEach(n=>{this.protocolsByName.delete(n)}))}},L=new vr,ts=[{code:4,name:"ip4",size:32,valueToBytes:_r,bytesToValue:kn,validate:r=>{if(!ge(r))throw new J(`Invalid IPv4 address "${r}"`)}},{code:6,name:"tcp",size:16,valueToBytes:ht,bytesToValue:_t,validate:zt},{code:273,name:"udp",size:16,valueToBytes:ht,bytesToValue:_t,validate:zt},{code:33,name:"dccp",size:16,valueToBytes:ht,bytesToValue:_t,validate:zt},{code:41,name:"ip6",size:128,valueToBytes:Tn,bytesToValue:Fn,stringToValue:Ln,validate:r=>{if(!Rn(r))throw new J(`Invalid IPv6 address "${r}"`)}},{code:42,name:"ip6zone",size:I},{code:43,name:"ipcidr",size:8,bytesToValue:yr("base10"),valueToBytes:Cr("base10")},{code:53,name:"dns",size:I,resolvable:!0},{code:54,name:"dns4",size:I,resolvable:!0},{code:55,name:"dns6",size:I,resolvable:!0},{code:56,name:"dnsaddr",size:I,resolvable:!0},{code:132,name:"sctp",size:16,valueToBytes:ht,bytesToValue:_t,validate:zt},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:I,path:!0,stringToValue:r=>decodeURIComponent(r),valueToString:r=>encodeURIComponent(r)},{code:421,name:"p2p",aliases:["ipfs"],size:I,bytesToValue:yr("base58btc"),valueToBytes:r=>r.startsWith("Q")||r.startsWith("1")?Cr("base58btc")(r):nt.parse(r).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:Sr,valueToBytes:Dn},{code:445,name:"onion3",size:296,bytesToValue:Sr,valueToBytes:On},{code:446,name:"garlic64",size:I},{code:447,name:"garlic32",size:I},{code:448,name:"tls"},{code:449,name:"sni",size:I},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:I,bytesToValue:Vn(We),valueToBytes:Un},{code:480,name:"http"},{code:481,name:"http-path",size:I,stringToValue:r=>`/${decodeURIComponent(r)}`,valueToString:r=>encodeURIComponent(r.substring(1))},{code:443,name:"https"},{code:477,name:"ws"},{code:478,name:"wss"},{code:479,name:"p2p-websocket-star"},{code:277,name:"p2p-stardust"},{code:275,name:"p2p-webrtc-star"},{code:276,name:"p2p-webrtc-direct"},{code:280,name:"webrtc-direct"},{code:281,name:"webrtc"},{code:290,name:"p2p-circuit"},{code:777,name:"memory",size:I}];ts.forEach(r=>{L.addProtocol(r)});function Bn(r){let t=[],e=0;for(;e<r.length;){let n=ir(r,e),o=L.getProtocol(n),i=W(n),s=es(o,r,e+i),a=0;s>0&&o.size===I&&(a=W(s));let h=i+a+s,p={code:n,name:o.name,bytes:r.subarray(e,e+h)};if(s>0){let x=e+i+a,b=r.subarray(x,x+s);p.value=o.bytesToValue?.(b)??q(b)}t.push(p),e+=h}return t}function Mn(r){let t=0,e=[];for(let n of r){if(n.bytes==null){let o=L.getProtocol(n.code),i=W(n.code),s,a=0,h=0;n.value!=null&&(s=o.valueToBytes?.(n.value)??H(n.value),a=s.byteLength,o.size===I&&(h=W(a)));let p=new Uint8Array(i+h+a),x=0;Mt(n.code,p,x),x+=i,s!=null&&(o.size===I&&(Mt(a,p,x),x+=h),p.set(s,x)),n.bytes=p}e.push(n.bytes),t+=n.bytes.byteLength}return ot(e,t)}function qn(r){if(r.charAt(0)!=="/")throw new P('String multiaddr must start with "/"');let t=[],e="protocol",n="",o="";for(let i=1;i<r.length;i++){let s=r.charAt(i);s!=="/"&&(e==="protocol"?o+=r.charAt(i):n+=r.charAt(i));let a=i===r.length-1;if(s==="/"||a){let h=L.getProtocol(o);if(e==="protocol"){if(h.size==null||h.size===0){t.push({code:h.code,name:h.name}),n="",o="",e="protocol";continue}else if(a)throw new P(`Component ${o} was missing value`);e="value"}else if(e==="value"){let p={code:h.code,name:h.name};if(h.size!=null&&h.size!==0){if(n==="")throw new P(`Component ${o} was missing value`);p.value=h.stringToValue?.(n)??n}t.push(p),n="",o="",e="protocol"}}}if(o!==""&&n!=="")throw new P("Incomplete multiaddr");return t}function Kn(r){return`/${r.flatMap(t=>{if(t.value==null)return t.name;let e=L.getProtocol(t.code);if(e==null)throw new P(`Unknown protocol code ${t.code}`);return[t.name,e.valueToString?.(t.value)??t.value]}).join("/")}`}function es(r,t,e){return r.size==null||r.size===0?0:r.size>0?r.size/8:ir(t,e)}var rs=Symbol.for("nodejs.util.inspect.custom"),Fr=Symbol.for("@multiformats/multiaddr"),ns=[53,54,55,56],kr=class extends Error{constructor(t="No available resolver"){super(t),this.name="NoAvailableResolverError"}};function os(r){if(r==null&&(r="/"),zn(r))return r.getComponents();if(r instanceof Uint8Array)return Bn(r);if(typeof r=="string")return r=r.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),r===""&&(r="/"),qn(r);if(Array.isArray(r))return r;throw new P("Must be a string, Uint8Array, Component[], or another Multiaddr")}var Ee=class r{[Fr]=!0;#t;#e;#r;constructor(t="/",e={}){this.#t=os(t),e.validate!==!1&&is(this)}get bytes(){return this.#r==null&&(this.#r=Mn(this.#t)),this.#r}toString(){return this.#e==null&&(this.#e=Kn(this.#t)),this.#e}toJSON(){return this.toString()}toOptions(){let t,e,n,o,i="";for(let{code:a,name:h,value:p}of this.#t)a===42&&(i=`%${p??""}`),ns.includes(a)&&(e="tcp",o=443,n=`${p??""}${i}`,t=a===55?6:4),(a===6||a===273)&&(e=h==="tcp"?"tcp":"udp",o=parseInt(p??"")),(a===4||a===41)&&(e="tcp",n=`${p??""}${i}`,t=a===41?6:4);if(t==null||e==null||n==null||o==null)throw new Error('multiaddr must have a valid format: "/{ip4, ip6, dns4, dns6, dnsaddr}/{address}/{tcp, udp}/{port}".');return{family:t,host:n,transport:e,port:o}}getComponents(){return[...this.#t]}protos(){return this.#t.map(({code:t,value:e})=>{let n=L.getProtocol(t);return{code:t,size:n.size??0,name:n.name,resolvable:!!n.resolvable,path:!!n.path}})}protoCodes(){return this.#t.map(({code:t})=>t)}protoNames(){return this.#t.map(({name:t})=>t)}tuples(){return this.#t.map(({code:t,value:e})=>{if(e==null)return[t];let n=L.getProtocol(t),o=[t];return e!=null&&o.push(n.valueToBytes?.(e)??H(e)),o})}stringTuples(){return this.#t.map(({code:t,value:e})=>e==null?[t]:[t,e])}encapsulate(t){let e=new r(t);return new r([...this.#t,...e.getComponents()],{validate:!1})}decapsulate(t){let e=t.toString(),n=this.toString(),o=n.lastIndexOf(e);if(o<0)throw new $t(`Address ${this.toString()} does not contain subaddress: ${t.toString()}`);return new r(n.slice(0,o),{validate:!1})}decapsulateCode(t){let e;for(let n=this.#t.length-1;n>-1;n--)if(this.#t[n].code===t){e=n;break}return new r(this.#t.slice(0,e),{validate:!1})}getPeerId(){try{let t=[];this.#t.forEach(({code:n,value:o})=>{n===421&&t.push([n,o]),n===290&&(t=[])});let e=t.pop();if(e?.[1]!=null){let n=e[1];return n[0]==="Q"||n[0]==="1"?q(M.decode(`z${n}`),"base58btc"):q(nt.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){for(let t of this.#t)if(L.getProtocol(t.code).path)return t.value??null;return null}equals(t){return ie(this.bytes,t.bytes)}async resolve(t){let e=this.protos().find(i=>i.resolvable);if(e==null)return[this];let n=$n.get(e.name);if(n==null)th