@chainsafe/libp2p-quic
Version:
A QUIC transport for libp2p
2 lines • 79.8 kB
JavaScript
(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 F=(r,t)=>{for(var e in t)co(r,e,{get:t[e],enumerable:!0})};var Hr=Symbol.for("@libp2p/transport");var Gr;(function(r){r[r.FATAL_ALL=0]="FATAL_ALL",r[r.NO_FATAL=1]="NO_FATAL"})(Gr||(Gr={}));var Yt=class extends Error{static name="AbortError";constructor(t="The operation was aborted"){super(t),this.name="AbortError"}};var te=class extends Error{static name="StreamResetError";constructor(t="The stream has been reset"){super(t),this.name="StreamResetError"}},ee=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 re=(r,...t)=>{try{uo(r,...t)}catch{}};var bt=class extends EventTarget{#t=new Map;constructor(){super(),re(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:s})=>s!==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"),$i=Symbol.for("@libp2p/service-dependencies");var Ue={};F(Ue,{base58btc:()=>z,base58flickr:()=>bo});var ha=new Uint8Array(0);function Xr(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 M(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 Jr(r){return new TextEncoder().encode(r)}function Zr(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 s=r.charAt(o),i=s.charCodeAt(0);if(e[i]!==255)throw new TypeError(s+" is ambiguous");e[i]=o}var a=r.length,l=r.charAt(0),d=Math.log(a)/Math.log(256),w=Math.log(256)/Math.log(a);function b(x){if(x instanceof Uint8Array||(ArrayBuffer.isView(x)?x=new Uint8Array(x.buffer,x.byteOffset,x.byteLength):Array.isArray(x)&&(x=Uint8Array.from(x))),!(x instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(x.length===0)return"";for(var v=0,p=0,D=0,L=x.length;D!==L&&x[D]===0;)D++,v++;for(var _=(L-D)*w+1>>>0,k=new Uint8Array(_);D!==L;){for(var B=x[D],tt=0,q=_-1;(B!==0||tt<p)&&q!==-1;q--,tt++)B+=256*k[q]>>>0,k[q]=B%a>>>0,B=B/a>>>0;if(B!==0)throw new Error("Non-zero carry");p=tt,D++}for(var X=_-p;X!==_&&k[X]===0;)X++;for(var Zt=l.repeat(v);X<_;++X)Zt+=r.charAt(k[X]);return Zt}function A(x){if(typeof x!="string")throw new TypeError("Expected String");if(x.length===0)return new Uint8Array;var v=0;if(x[v]!==" "){for(var p=0,D=0;x[v]===l;)p++,v++;for(var L=(x.length-v)*d+1>>>0,_=new Uint8Array(L);x[v];){var k=e[x.charCodeAt(v)];if(k===255)return;for(var B=0,tt=L-1;(k!==0||B<D)&&tt!==-1;tt--,B++)k+=a*_[tt]>>>0,_[tt]=k%256>>>0,k=k/256>>>0;if(k!==0)throw new Error("Non-zero carry");D=B,v++}if(x[v]!==" "){for(var q=L-D;q!==L&&_[q]===0;)q++;for(var X=new Uint8Array(p+(L-q)),Zt=p;q!==L;)X[Zt++]=_[q++];return X}}}function gt(x){var v=A(x);if(v)return v;throw new Error(`Non-${t} character`)}return{encode:b,decodeUnsafe:A,decode:gt}}var ho=lo,po=ho,tn=po;var Ne=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")}},Le=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 Re=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 Ne(t,e,n),this.decoder=new Le(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function wt({name:r,prefix:t,encode:e,decode:n}){return new Re(r,t,e,n)}function et({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=tn(e,r);return wt({prefix:t,name:r,encode:n,decode:s=>M(o(s))})}function fo(r,t,e,n){let o=r.length;for(;r[o-1]==="=";)--o;let s=new Uint8Array(o*e/8|0),i=0,a=0,l=0;for(let d=0;d<o;++d){let w=t[r[d]];if(w===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<e|w,i+=e,i>=8&&(i-=8,s[l++]=255&a>>i)}if(i>=e||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function mo(r,t,e){let n=t[t.length-1]==="=",o=(1<<e)-1,s="",i=0,a=0;for(let l=0;l<r.length;++l)for(a=a<<8|r[l],i+=8;i>e;)i-=e,s+=t[o&a>>i];if(i!==0&&(s+=t[o&a<<e-i]),n)for(;(s.length*e&7)!==0;)s+="=";return s}function go(r){let t={};for(let e=0;e<r.length;++e)t[r[e]]=e;return t}function C({name:r,prefix:t,bitsPerChar:e,alphabet:n}){let o=go(n);return wt({prefix:t,name:r,encode(s){return mo(s,n,e)},decode(s){return fo(s,o,e,r)}})}var z=et({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),bo=et({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Be={};F(Be,{base32:()=>rt,base32hex:()=>Eo,base32hexpad:()=>Co,base32hexpadupper:()=>vo,base32hexupper:()=>So,base32pad:()=>xo,base32padupper:()=>yo,base32upper:()=>wo,base32z:()=>Do});var rt=C({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),wo=C({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),xo=C({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),yo=C({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Eo=C({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),So=C({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Co=C({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),vo=C({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Do=C({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Fe={};F(Fe,{base36:()=>kt,base36upper:()=>Io});var kt=et({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Io=et({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Ao=on,rn=128,_o=127,Po=~_o,To=Math.pow(2,31);function on(r,t,e){t=t||[],e=e||0;for(var n=e;r>=To;)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 Oo=Me,No=128,nn=127;function Me(r,n){var e=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw Me.bytes=0,new RangeError("Could not decode varint");i=r[s++],e+=o<28?(i&nn)<<o:(i&nn)*Math.pow(2,o),o+=7}while(i>=No);return Me.bytes=s-n,e}var Lo=Math.pow(2,7),ko=Math.pow(2,14),Ro=Math.pow(2,21),Uo=Math.pow(2,28),Bo=Math.pow(2,35),Fo=Math.pow(2,42),Mo=Math.pow(2,49),zo=Math.pow(2,56),Vo=Math.pow(2,63),qo=function(r){return r<Lo?1:r<ko?2:r<Ro?3:r<Uo?4:r<Bo?5:r<Fo?6:r<Mo?7:r<zo?8:r<Vo?9:10},$o={encode:Ao,decode:Oo,encodingLength:qo},Ko=$o,Rt=Ko;function Ut(r,t=0){return[Rt.decode(r,t),Rt.decode.bytes]}function xt(r,t,e=0){return Rt.encode(r,t,e),t}function yt(r){return Rt.encodingLength(r)}function ct(r,t){let e=t.byteLength,n=yt(r),o=n+yt(e),s=new Uint8Array(o+e);return xt(r,s,0),xt(e,s,n),s.set(t,o),new Et(r,e,t,s)}function sn(r){let t=M(r),[e,n]=Ut(t),[o,s]=Ut(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Et(e,o,i,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&&Xr(r.bytes,e.bytes)}}var Et=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 jo(e,ze(r),t??z.encoder);default:return Go(e,ze(r),t??rt.encoder)}}var un=new WeakMap;function ze(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!==Ft)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==Ho)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=ct(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:s,bytes:i}=e;return new r(n,o,s,i??ln(n,o,s.bytes))}else if(e[Qo]===!0){let{version:n,multihash:o,code:s}=e,i=sn(o);return r.create(n,s,i)}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!==Ft)throw new Error(`Version 0 CID must use dag-pb (code: ${Ft}) 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,Ft,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=M(t.subarray(n,n+e.multihashSize));if(o.byteLength!==e.multihashSize)throw new Error("Incorrect length");let s=o.subarray(e.multihashSize-e.digestSize),i=new Et(e.multihashCode,e.digestSize,s,o);return[e.version===0?r.createV0(i):r.createV1(e.codec,i),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[b,A]=Ut(t.subarray(e));return e+=A,b},o=n(),s=Ft;if(o===18?(o=0,e=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=e,a=n(),l=n(),d=e+l,w=d-i;return{version:o,codec:s,multihashCode:a,digestSize:l,multihashSize:w,size:d}}static parse(t,e){let[n,o]=Wo(t,e),s=r.decode(o);if(s.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return ze(s).set(n,t),s}};function Wo(r,t){switch(r[0]){case"Q":{let e=t??z;return[z.prefix,e.decode(`${z.prefix}${r}`)]}case z.prefix:{let e=t??z;return[z.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 jo(r,t,e){let{prefix:n}=e;if(n!==z.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let o=t.get(n);if(o==null){let s=e.encode(r).slice(1);return t.set(n,s),s}else return o}function Go(r,t,e){let{prefix:n}=e,o=t.get(n);if(o==null){let s=e.encode(r);return t.set(n,s),s}else return o}var Ft=112,Ho=18;function ln(r,t,e){let n=yt(r),o=n+yt(t),s=new Uint8Array(o+e.byteLength);return xt(r,s,0),xt(t,s,n),s.set(e,o),s}var Qo=Symbol.for("@ipld/js-cid/CID");var Ve={};F(Ve,{identity:()=>Zo});var hn=0,Xo="identity",dn=M;function Jo(r){return ct(hn,dn(r))}var Zo={code:hn,name:Xo,encode:dn,digest:Jo};function oe(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 pn}from"node:buffer";function ut(r){return new Uint8Array(r.buffer,r.byteOffset,r.byteLength)}function J(r=0){return ut(pn.alloc(r))}function $(r=0){return ut(pn.allocUnsafe(r))}import{Buffer as Yo}from"node:buffer";function ot(r,t){return ut(Yo.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 St=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),s=new r;return s.length=o,s.bufs=[...n],s}_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 s=0;s<this.bufs.length;s++){let i=this.bufs[s],a=o,l=a+i.byteLength;if(o=l,t>=l)continue;let d=t>=a&&t<l,w=e>a&&e<=l;if(d&&w){if(t===a&&e===l){n.push(i);break}let b=t-a;n.push(i.subarray(b,b+(e-t)));break}if(d){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(w){if(e===l){n.push(i);break}n.push(i.subarray(0,e-a));break}n.push(i)}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 s=256,i=new Int32Array(s);for(let b=0;b<s;b++)i[b]=-1;for(let b=0;b<o;b++)i[n[b]]=b;let a=i,l=this.byteLength-n.byteLength,d=n.byteLength-1,w;for(let b=e;b<=l;b+=w){w=0;for(let A=d;A>=0;A--){let gt=this.get(b+A);if(n[A]!==gt){w=Math.max(1,A-a[gt]);break}}if(w===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=J(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=J(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=J(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=J(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=J(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=J(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=J(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=J(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(!oe(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,s)=>o+s.byteLength,0)),n.length=e,n}};import{Buffer as xs}from"node:buffer";var qe={};F(qe,{base10:()=>ts});var ts=et({prefix:"9",name:"base10",alphabet:"0123456789"});var $e={};F($e,{base16:()=>es,base16upper:()=>rs});var es=C({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),rs=C({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Ke={};F(Ke,{base2:()=>ns});var ns=C({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var We={};F(We,{base256emoji:()=>cs});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}"),os=gn.reduce((r,t,e)=>(r[e]=t,r),[]),ss=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 is(r){return r.reduce((t,e)=>(t+=os[e],t),"")}function as(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let o=ss[n];if(o==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(o)}return new Uint8Array(t)}var cs=wt({prefix:"\u{1F680}",name:"base256emoji",encode:is,decode:as});var Ge={};F(Ge,{base64:()=>us,base64pad:()=>ls,base64url:()=>je,base64urlpad:()=>hs});var us=C({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),ls=C({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),je=C({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),hs=C({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var He={};F(He,{base8:()=>ds});var ds=C({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Qe={};F(Qe,{identity:()=>ps});var ps=wt({prefix:"\0",name:"identity",encode:r=>Zr(r),decode:r=>Jr(r)});var Qa=new TextEncoder,Xa=new TextDecoder;var Ze={};F(Ze,{sha256:()=>gs,sha512:()=>bs});import wn from"crypto";function Je({name:r,code:t,encode:e}){return new Xe(r,t,e)}var Xe=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?ct(this.code,e):e.then(n=>ct(this.code,n))}else throw Error("Unknown type, must be binary type")}};var gs=Je({name:"sha2-256",code:18,encode:r=>M(wn.createHash("sha256").update(r).digest())}),bs=Je({name:"sha2-512",code:19,encode:r=>M(wn.createHash("sha512").update(r).digest())});var Mt={...Qe,...Ke,...He,...qe,...$e,...Be,...Fe,...Ue,...Ge,...We},lc={...Ze,...Ve};function yn(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var xn=yn("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Ye=yn("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}),ws={utf8:xn,"utf-8":xn,hex:Mt.base16,latin1:Ye,ascii:Ye,binary:Ye,...Mt},ie=ws;function W(r,t="utf8"){let e=ie[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return t==="utf8"||t==="utf-8"?ut(xs.from(r,"utf-8")):e.decoder.decode(`${e.prefix}${r}`)}import{Buffer as ys}from"node:buffer";function V(r,t="utf8"){let e=ie[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return t==="utf8"||t==="utf-8"?ys.from(r.buffer,r.byteOffset,r.byteLength).toString("utf8"):e.encoder.encode(r).substring(1)}var Es=Math.pow(2,7),Ss=Math.pow(2,14),Cs=Math.pow(2,21),tr=Math.pow(2,28),er=Math.pow(2,35),rr=Math.pow(2,42),nr=Math.pow(2,49),S=128,T=127;function j(r){if(r<Es)return 1;if(r<Ss)return 2;if(r<Cs)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 zt(r,t,e=0){switch(j(r)){case 8:t[e++]=r&255|S,r/=128;case 7:t[e++]=r&255|S,r/=128;case 6:t[e++]=r&255|S,r/=128;case 5:t[e++]=r&255|S,r/=128;case 4:t[e++]=r&255|S,r>>>=7;case 3:t[e++]=r&255|S,r>>>=7;case 2:t[e++]=r&255|S,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&T,e<S||(e=r[t+1],n+=(e&T)<<7,e<S)||(e=r[t+2],n+=(e&T)<<14,e<S)||(e=r[t+3],n+=(e&T)<<21,e<S)||(e=r[t+4],n+=(e&T)*tr,e<S)||(e=r[t+5],n+=(e&T)*er,e<S)||(e=r[t+6],n+=(e&T)*rr,e<S)||(e=r[t+7],n+=(e&T)*nr,e<S))return n;throw new RangeError("Could not decode varint")}function vs(r,t){let e=r.get(t),n=0;if(n+=e&T,e<S||(e=r.get(t+1),n+=(e&T)<<7,e<S)||(e=r.get(t+2),n+=(e&T)<<14,e<S)||(e=r.get(t+3),n+=(e&T)<<21,e<S)||(e=r.get(t+4),n+=(e&T)*tr,e<S)||(e=r.get(t+5),n+=(e&T)*er,e<S)||(e=r.get(t+6),n+=(e&T)*rr,e<S)||(e=r.get(t+7),n+=(e&T)*nr,e<S))return n;throw new RangeError("Could not decode varint")}function sr(r,t=0){return r instanceof Uint8Array?or(r,t):vs(r,t)}var ir=new Float32Array([-0]),st=new Uint8Array(ir.buffer);function En(r,t,e){ir[0]=r,t[e]=st[0],t[e+1]=st[1],t[e+2]=st[2],t[e+3]=st[3]}function Sn(r,t){return st[0]=r[t],st[1]=r[t+1],st[2]=r[t+2],st[3]=r[t+3],ir[0]}var ar=new Float64Array([-0]),O=new Uint8Array(ar.buffer);function Cn(r,t,e){ar[0]=r,t[e]=O[0],t[e+1]=O[1],t[e+2]=O[2],t[e+3]=O[3],t[e+4]=O[4],t[e+5]=O[5],t[e+6]=O[6],t[e+7]=O[7]}function vn(r,t){return O[0]=r[t],O[1]=r[t+1],O[2]=r[t+2],O[3]=r[t+3],O[4]=r[t+4],O[5]=r[t+5],O[6]=r[t+6],O[7]=r[t+7],ar[0]}var Is=BigInt(Number.MAX_SAFE_INTEGER),As=BigInt(Number.MIN_SAFE_INTEGER),R=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 lt;if(t<Is&&t>As)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>Dn&&(o=0n,++n>Dn&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(t){if(t===0)return lt;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):lt}},lt=new R(0,0);lt.toBigInt=function(){return 0n};lt.zzEncode=lt.zzDecode=function(){return this};lt.length=function(){return 1};var Dn=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 An(r,t,e){if(e-t<1)return"";let o,s=[],i=0,a;for(;t<e;)a=r[t++],a<128?s[i++]=a:a>191&&a<224?s[i++]=(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,s[i++]=55296+(a>>10),s[i++]=56320+(a&1023)):s[i++]=(a&15)<<12|(r[t++]&63)<<6|r[t++]&63,i>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,s)),i=0);return o!=null?(i>0&&o.push(String.fromCharCode.apply(String,s.slice(0,i))),o.join("")):String.fromCharCode.apply(String,s.slice(0,i))}function cr(r,t,e){let n=e,o,s;for(let i=0;i<r.length;++i)o=r.charCodeAt(i),o<128?t[e++]=o:o<2048?(t[e++]=o>>6|192,t[e++]=o&63|128):(o&64512)===55296&&((s=r.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,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 K(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function ae(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,K(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 K(this,4);return ae(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw K(this,4);return ae(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw K(this,4);let t=Sn(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw K(this,4);let t=vn(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 K(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return An(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw K(this,t);this.pos+=t}else do if(this.pos>=this.len)throw K(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 R(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 K(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 K(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 K(this,8);let t=ae(this.buf,this.pos+=4),e=ae(this.buf,this.pos+=4);return new R(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+=j(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 ce(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(i){if(i<1||i>e)return $(i);o+i>t&&(n=$(t),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var ht=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function dr(){}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}},_s=hr();function Ps(r){return globalThis.Buffer!=null?$(r):_s(r)}var qt=class{len;head;tail;states;constructor(){this.len=0,this.head=new ht(dr,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new ht(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(ue,10,R.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=R.fromBigInt(t);return this._push(ue,e.length(),e)}uint64Number(t){return this._push(zt,j(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=R.fromBigInt(t).zzEncode();return this._push(ue,e.length(),e)}sint64Number(t){let e=R.fromNumber(t).zzEncode();return this._push(ue,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(pr,1,t?1:0)}fixed32(t){return this._push(Vt,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=R.fromBigInt(t);return this._push(Vt,4,e.lo)._push(Vt,4,e.hi)}fixed64Number(t){let e=R.fromNumber(t);return this._push(Vt,4,e.lo)._push(Vt,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(En,4,t)}double(t){return this._push(Cn,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(pr,1,0):this.uint32(e)._push(Os,e,t)}string(t){let e=In(t);return e!==0?this.uint32(e)._push(cr,e,t):this._push(pr,1,0)}fork(){return this.states=new fr(this),this.head=this.tail=new ht(dr,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 ht(dr,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=Ps(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function pr(r,t,e){t[e]=r&255}function Ts(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var mr=class extends ht{next;constructor(t,e){super(Ts,t,e),this.next=void 0}};function ue(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 Vt(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 Os(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(qt.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(Ns,t,r),this},qt.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(Ls,t,r),this});function Ns(r,t,e){t.set(r,e)}function Ls(r,t,e){r.length<40?cr(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(W(r),e)}function gr(){return new qt}function le(r,t){let e=gr();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var Ct;(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"})(Ct||(Ct={}));function he(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(s,i){let a=t(s);i.int32(a)},n=function(s){let i=s.int32();return t(i)};return he("enum",Ct.VARINT,e,n)}function de(r,t){return he("message",Ct.LENGTH_DELIMITED,r,t)}var G;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1",r.ECDSA="ECDSA"})(G||(G={}));var wr;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1",r[r.ECDSA=3]="ECDSA"})(wr||(wr={}));(function(r){r.codec=()=>br(wr)})(G||(G={}));var xr;(function(r){let t;r.codec=()=>(t==null&&(t=de((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),G.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{s.Type=G.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>le(e,r.codec()),r.decode=(e,n)=>ce(e,r.codec(),n)})(xr||(xr={}));var pe;(function(r){let t;r.codec=()=>(t==null&&(t=de((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),G.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{s.Type=G.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>le(e,r.codec()),r.decode=(e,n)=>ce(e,r.codec(),n)})(pe||(pe={}));function Pn(r){return pe.encode({Type:G[r.type],Data:r.raw})}var P=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},Z=class extends Error{static name="ValidationError";name="ValidationError"},$t=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},fe=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};import{isIPv4 as me,isIPv6 as Tn,isIP as ou}from"node:net";function Er(r){return t=>V(t,r)}function Sr(r){return t=>W(t,r)}function vt(r){return new DataView(r.buffer).getUint16(r.byteOffset).toString()}function dt(r){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,typeof r=="string"?parseInt(r):r),new Uint8Array(t)}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!==16)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion address.`);let e=W(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=dt(n);return ot([e,o],e.length+o.length)}function Nn(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=dt(n);return ot([e,o],e.length+o.length)}function Cr(r){let t=r.subarray(0,r.length-2),e=r.subarray(r.length-2),n=V(t,"base32"),o=vt(e);return`${n}:${o}`}var vr=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},Ln=function(r){let t=0;r=r.toString().trim();let e=r.split(":",8),n;for(n=0;n<e.length;n++){let s=me(e[n]),i;s&&(i=vr(e[n]),e[n]=V(i.subarray(0,2),"base16")),i!=null&&++n<8&&e.splice(n,0,V(i.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 s=[n,1];for(n=9-e.length;n>0;n--)s.push("0");e.splice.apply(e,s)}let o=new Uint8Array(t+16);for(n=0;n<e.length;n++){e[n]===""&&(e[n]="0");let s=parseInt(e[n],16);if(isNaN(s)||s<0||s>65535)throw new P("Invalid byte value in IP address");o[t++]=s>>8&255,o[t++]=s&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(".")},Rn=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],s=r[n+1],i=`${o.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}`;t.push(i)}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 Un(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 yr=Object.values(Mt).map(r=>r.decoder),Rs=function(){let r=yr[0].or(yr[1]);return yr.slice(2).forEach(t=>r=r.or(t)),r}();function Bn(r){return Rs.decode(r)}function Fn(r){return t=>r.encoder.encode(t)}function Us(r){if(parseInt(r).toString()!==r)throw new Z("Value must be an integer")}function Bs(r){if(r<0)throw new Z("Value must be a positive integer, or zero")}function Fs(r){return t=>{if(t>r)throw new Z(`Value must be smaller than or equal to ${r}`)}}function Ms(...r){return t=>{for(let e of r)e(t)}}var Kt=Ms(Us,Bs,Fs(65535));var I=-1,Dr=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 fe(`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)}))}},U=new Dr,ti=[{code:4,name:"ip4",size:32,valueToBytes:vr,bytesToValue:kn,validate:r=>{if(!me(r))throw new Z(`Invalid IPv4 address "${r}"`)}},{code:6,name:"tcp",size:16,valueToBytes:dt,bytesToValue:vt,validate:Kt},{code:273,name:"udp",size:16,valueToBytes:dt,bytesToValue:vt,validate:Kt},{code:33,name:"dccp",size:16,valueToBytes:dt,bytesToValue:vt,validate:Kt},{code:41,name:"ip6",size:128,valueToBytes:Ln,bytesToValue:Rn,stringToValue:Un,validate:r=>{if(!Tn(r))throw new Z(`Invalid IPv6 address "${r}"`)}},{code:42,name:"ip6zone",size:I},{code:43,name:"ipcidr",size:8,bytesToValue:Er("base10"),valueToBytes:Sr("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:dt,bytesToValue:vt,validate:Kt},{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:Er("base58btc"),valueToBytes:r=>r.startsWith("Q")||r.startsWith("1")?Sr("base58btc")(r):nt.parse(r).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:Cr,valueToBytes:On},{code:445,name:"onion3",size:296,bytesToValue:Cr,valueToBytes:Nn},{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:Fn(je),valueToBytes:Bn},{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}];ti.forEach(r=>{U.addProtocol(r)});function Mn(r){let t=[],e=0;for(;e<r.length;){let n=sr(r,e),o=U.getProtocol(n),s=j(n),i=ei(o,r,e+s),a=0;i>0&&o.size===I&&(a=j(i));let l=s+a+i,d={code:n,name:o.name,bytes:r.subarray(e,e+l)};if(i>0){let w=e+s+a,b=r.subarray(w,w+i);d.value=o.bytesToValue?.(b)??V(b)}t.push(d),e+=l}return t}function zn(r){let t=0,e=[];for(let n of r){if(n.bytes==null){let o=U.getProtocol(n.code),s=j(n.code),i,a=0,l=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??W(n.value),a=i.byteLength,o.size===I&&(l=j(a)));let d=new Uint8Array(s+l+a),w=0;zt(n.code,d,w),w+=s,i!=null&&(o.size===I&&(zt(a,d,w),w+=l),d.set(i,w)),n.bytes=d}e.push(n.bytes),t+=n.bytes.byteLength}return ot(e,t)}function Vn(r){if(r.charAt(0)!=="/")throw new P('String multiaddr must start with "/"');let t=[],e="protocol",n="",o="";for(let s=1;s<r.length;s++){let i=r.charAt(s);i!=="/"&&(e==="protocol"?o+=r.charAt(s):n+=r.charAt(s));let a=s===r.length-1;if(i==="/"||a){let l=U.getProtocol(o);if(e==="protocol"){if(l.size==null||l.size===0){t.push({code:l.code,name:l.name}),n="",o="",e="protocol";continue}else if(a)throw new P(`Component ${o} was missing value`);e="value"}else if(e==="value"){let d={code:l.code,name:l.name};if(l.size!=null&&l.size!==0){if(n==="")throw new P(`Component ${o} was missing value`);d.value=l.stringToValue?.(n)??n}t.push(d),n="",o="",e="protocol"}}}if(o!==""&&n!=="")throw new P("Incomplete multiaddr");return t}function qn(r){return`/${r.flatMap(t=>{if(t.value==null)return t.name;let e=U.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 ei(r,t,e){return r.size==null||r.size===0?0:r.size>0?r.size/8:sr(t,e)}var ri=Symbol.for("nodejs.util.inspect.custom"),Rr=Symbol.for("@multiformats/multiaddr"),ni=[53,54,55,56],kr=class extends Error{constructor(t="No available resolver"){super(t),this.name="NoAvailableResolverError"}};function oi(r){if(r==null&&(r="/"),Kn(r))return r.getComponents();if(r instanceof Uint8Array)return Mn(r);if(typeof r=="string")return r=r.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),r===""&&(r="/"),Vn(r);if(Array.isArray(r))return r;throw new P("Must be a string, Uint8Array, Component[], or another Multiaddr")}var xe=class r{[Rr]=!0;#t;#e;#r;constructor(t="/",e={}){this.#t=oi(t),e.validate!==!1&&si(this)}get bytes(){return this.#r==null&&(this.#r=zn(this.#t)),this.#r}toString(){return this.#e==null&&(this.#e=qn(this.#t)),this.#e}toJSON(){return this.toString()}toOptions(){let t,e,n,o,s="";for(let{code:a,name:l,value:d}of this.#t)a===42&&(s=`%${d??""}`),ni.includes(a)&&(e="tcp",o=443,n=`${d??""}${s}`,t=a===55?6:4),(a===6||a===273)&&(e=l==="tcp"?"tcp":"udp",o=parseInt(d??"")),(a===4||a===41)&&(e="tcp",n=`${d??""}${s}`,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=U.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=U.getProtocol(t),o=[t];return e!=null&&o.push(n.valueToBytes?.(e)??W(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"?V(z.decode(`z${n}`),"base58btc"):V(nt.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){for(let t of this.#t)if(U.getProtocol(t.code).path)return t.value??null;return null}equals(t){return oe(this.bytes,t.bytes)}async resolve(t){let e=this.protos().find(s=>s.resolvable);if(e==null)return[this];let n=$n.get(e.name);if(n==null)th