@libp2p/devtools-metrics 1.2.12-b2124c2db → 1.2.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.min.js CHANGED
@@ -1,6 +1,6 @@
1
1
  (function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PDevtoolsMetrics = factory()}(typeof self !== 'undefined' ? self : this, function () {
2
- "use strict";var Libp2PDevtoolsMetrics=(()=>{var Ol=Object.create;var pn=Object.defineProperty;var Fl=Object.getOwnPropertyDescriptor;var Vl=Object.getOwnPropertyNames;var zl=Object.getPrototypeOf,Hl=Object.prototype.hasOwnProperty;var _r=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),Tt=(r,t)=>{for(var e in t)pn(r,e,{get:t[e],enumerable:!0})},Ms=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Vl(t))!Hl.call(r,o)&&o!==e&&pn(r,o,{get:()=>t[o],enumerable:!(n=Fl(t,o))||n.enumerable});return r};var ql=(r,t,e)=>(e=r!=null?Ol(zl(r)):{},Ms(t||!r||!r.__esModule?pn(e,"default",{value:r,enumerable:!0}):e,r)),Kl=r=>Ms(pn({},"__esModule",{value:!0}),r);var Yo=_r((Cm,rc)=>{function Kt(){}Kt.prototype.clear=function(){this._root=null,this.size=0};Kt.prototype.find=function(r){for(var t=this._root;t!==null;){var e=this._comparator(r,t.data);if(e===0)return t.data;t=t.get_child(e>0)}return null};Kt.prototype.findIter=function(r){for(var t=this._root,e=this.iterator();t!==null;){var n=this._comparator(r,t.data);if(n===0)return e._cursor=t,e;e._ancestors.push(t),t=t.get_child(n>0)}return null};Kt.prototype.lowerBound=function(r){for(var t=this._root,e=this.iterator(),n=this._comparator;t!==null;){var o=n(r,t.data);if(o===0)return e._cursor=t,e;e._ancestors.push(t),t=t.get_child(o>0)}for(var i=e._ancestors.length-1;i>=0;--i)if(t=e._ancestors[i],n(r,t.data)<0)return e._cursor=t,e._ancestors.length=i,e;return e._ancestors.length=0,e};Kt.prototype.upperBound=function(r){for(var t=this.lowerBound(r),e=this._comparator;t.data()!==null&&e(t.data(),r)===0;)t.next();return t};Kt.prototype.min=function(){var r=this._root;if(r===null)return null;for(;r.left!==null;)r=r.left;return r.data};Kt.prototype.max=function(){var r=this._root;if(r===null)return null;for(;r.right!==null;)r=r.right;return r.data};Kt.prototype.iterator=function(){return new We(this)};Kt.prototype.each=function(r){for(var t=this.iterator(),e;(e=t.next())!==null;)if(r(e)===!1)return};Kt.prototype.reach=function(r){for(var t=this.iterator(),e;(e=t.prev())!==null;)if(r(e)===!1)return};function We(r){this._tree=r,this._ancestors=[],this._cursor=null}We.prototype.data=function(){return this._cursor!==null?this._cursor.data:null};We.prototype.next=function(){if(this._cursor===null){var r=this._tree._root;r!==null&&this._minNode(r)}else if(this._cursor.right===null){var t;do if(t=this._cursor,this._ancestors.length)this._cursor=this._ancestors.pop();else{this._cursor=null;break}while(this._cursor.right===t)}else this._ancestors.push(this._cursor),this._minNode(this._cursor.right);return this._cursor!==null?this._cursor.data:null};We.prototype.prev=function(){if(this._cursor===null){var r=this._tree._root;r!==null&&this._maxNode(r)}else if(this._cursor.left===null){var t;do if(t=this._cursor,this._ancestors.length)this._cursor=this._ancestors.pop();else{this._cursor=null;break}while(this._cursor.left===t)}else this._ancestors.push(this._cursor),this._maxNode(this._cursor.left);return this._cursor!==null?this._cursor.data:null};We.prototype._minNode=function(r){for(;r.left!==null;)this._ancestors.push(r),r=r.left;this._cursor=r};We.prototype._maxNode=function(r){for(;r.right!==null;)this._ancestors.push(r),r=r.right;this._cursor=r};rc.exports=Kt});var ic=_r((Tm,oc)=>{var If=Yo();function Xe(r){this.data=r,this.left=null,this.right=null,this.red=!0}Xe.prototype.get_child=function(r){return r?this.right:this.left};Xe.prototype.set_child=function(r,t){r?this.right=t:this.left=t};function Sn(r){this._root=null,this._comparator=r,this.size=0}Sn.prototype=new If;Sn.prototype.insert=function(r){var t=!1;if(this._root===null)this._root=new Xe(r),t=!0,this.size++;else{var e=new Xe(void 0),n=0,o=0,i=null,s=e,c=null,a=this._root;for(s.right=this._root;;){if(a===null?(a=new Xe(r),c.set_child(n,a),t=!0,this.size++):Ft(a.left)&&Ft(a.right)&&(a.red=!0,a.left.red=!1,a.right.red=!1),Ft(a)&&Ft(c)){var l=s.right===i;a===c.get_child(o)?s.set_child(l,Cr(i,!o)):s.set_child(l,nc(i,!o))}var u=this._comparator(a.data,r);if(u===0)break;o=n,n=u<0,i!==null&&(s=i),i=c,c=a,a=a.get_child(n)}this._root=e.right}return this._root.red=!1,t};Sn.prototype.remove=function(r){if(this._root===null)return!1;var t=new Xe(void 0),e=t;e.right=this._root;for(var n=null,o=null,i=null,s=1;e.get_child(s)!==null;){var c=s;o=n,n=e,e=e.get_child(s);var a=this._comparator(r,e.data);if(s=a>0,a===0&&(i=e),!Ft(e)&&!Ft(e.get_child(s))){if(Ft(e.get_child(!s))){var l=Cr(e,s);n.set_child(c,l),n=l}else if(!Ft(e.get_child(!s))){var u=n.get_child(!c);if(u!==null)if(!Ft(u.get_child(!c))&&!Ft(u.get_child(c)))n.red=!1,u.red=!0,e.red=!0;else{var f=o.right===n;Ft(u.get_child(c))?o.set_child(f,nc(n,c)):Ft(u.get_child(!c))&&o.set_child(f,Cr(n,c));var h=o.get_child(f);h.red=!0,e.red=!0,h.left.red=!1,h.right.red=!1}}}}return i!==null&&(i.data=e.data,n.set_child(n.right===e,e.get_child(e.left===null)),this.size--),this._root=t.right,this._root!==null&&(this._root.red=!1),i!==null};function Ft(r){return r!==null&&r.red}function Cr(r,t){var e=r.get_child(!t);return r.set_child(!t,e.get_child(t)),e.set_child(t,r),r.red=!0,e.red=!1,e}function nc(r,t){return r.set_child(!t,Cr(r.get_child(!t),!t)),Cr(r,t)}oc.exports=Sn});var cc=_r((km,sc)=>{var Cf=Yo();function Tr(r){this.data=r,this.left=null,this.right=null}Tr.prototype.get_child=function(r){return r?this.right:this.left};Tr.prototype.set_child=function(r,t){r?this.right=t:this.left=t};function An(r){this._root=null,this._comparator=r,this.size=0}An.prototype=new Cf;An.prototype.insert=function(r){if(this._root===null)return this._root=new Tr(r),this.size++,!0;for(var t=0,e=null,n=this._root;;){if(n===null)return n=new Tr(r),e.set_child(t,n),ret=!0,this.size++,!0;if(this._comparator(n.data,r)===0)return!1;t=this._comparator(n.data,r)<0,e=n,n=n.get_child(t)}};An.prototype.remove=function(r){if(this._root===null)return!1;var t=new Tr(void 0),e=t;e.right=this._root;for(var n=null,o=null,i=1;e.get_child(i)!==null;){n=e,e=e.get_child(i);var s=this._comparator(r,e.data);i=s>0,s===0&&(o=e)}return o!==null?(o.data=e.data,n.set_child(n.right===e,e.get_child(e.left===null)),this._root=t.right,this.size--,!0):!1};sc.exports=An});var uc=_r((Um,ac)=>{ac.exports={RBTree:ic(),BinTree:cc()}});var dc=_r((Lm,fc)=>{var Tf=uc().RBTree;function et(r,t,e){this.discrete=r===!1,this.delta=r||.01,this.K=t===void 0?25:t,this.CX=e===void 0?1.1:e,this.centroids=new Tf(lc),this.nreset=0,this.reset()}et.prototype.reset=function(){this.centroids.clear(),this.n=0,this.nreset+=1,this.last_cumulate=0};et.prototype.size=function(){return this.centroids.size};et.prototype.toArray=function(r){var t=[];return r?(this._cumulate(!0),this.centroids.each(function(e){t.push(e)})):this.centroids.each(function(e){t.push({mean:e.mean,n:e.n})}),t};et.prototype.summary=function(){var r=this.discrete?"exact ":"approximating ",t=[r+this.n+" samples using "+this.size()+" centroids","min = "+this.percentile(0),"Q1 = "+this.percentile(.25),"Q2 = "+this.percentile(.5),"Q3 = "+this.percentile(.75),"max = "+this.percentile(1)];return t.join(`
3
- `)};function lc(r,t){return r.mean>t.mean?1:r.mean<t.mean?-1:0}function kf(r,t){return r.mean_cumn-t.mean_cumn}et.prototype.push=function(r,t){t=t||1,r=Array.isArray(r)?r:[r];for(var e=0;e<r.length;e++)this._digest(r[e],t)};et.prototype.push_centroid=function(r){r=Array.isArray(r)?r:[r];for(var t=0;t<r.length;t++)this._digest(r[t].mean,r[t].n)};et.prototype._cumulate=function(r){if(!(this.n===this.last_cumulate||!r&&this.CX&&this.CX>this.n/this.last_cumulate)){var t=0;this.centroids.each(function(e){e.mean_cumn=t+e.n/2,t=e.cumn=t+e.n}),this.n=this.last_cumulate=t}};et.prototype.find_nearest=function(r){if(this.size()===0)return null;var t=this.centroids.lowerBound({mean:r}),e=t.data()===null?t.prev():t.data();if(e.mean===r||this.discrete)return e;var n=t.prev();return n&&Math.abs(n.mean-r)<Math.abs(e.mean-r)?n:e};et.prototype._new_centroid=function(r,t,e){var n={mean:r,n:t,cumn:e};return this.centroids.insert(n),this.n+=t,n};et.prototype._addweight=function(r,t,e){t!==r.mean&&(r.mean+=e*(t-r.mean)/(r.n+e)),r.cumn+=e,r.mean_cumn+=e/2,r.n+=e,this.n+=e};et.prototype._digest=function(r,t){var e=this.centroids.min(),n=this.centroids.max(),o=this.find_nearest(r);if(o&&o.mean===r)this._addweight(o,r,t);else if(o===e)this._new_centroid(r,t,0);else if(o===n)this._new_centroid(r,t,this.n);else if(this.discrete)this._new_centroid(r,t,o.cumn);else{var i=o.mean_cumn/this.n,s=Math.floor(4*this.n*this.delta*i*(1-i));s-o.n>=t?this._addweight(o,r,t):this._new_centroid(r,t,o.cumn)}this._cumulate(!1),!this.discrete&&this.K&&this.size()>this.K/this.delta&&this.compress()};et.prototype.bound_mean=function(r){var t=this.centroids.upperBound({mean:r}),e=t.prev(),n=e.mean===r?e:t.next();return[e,n]};et.prototype.p_rank=function(r){var t=Array.isArray(r)?r:[r],e=t.map(this._p_rank,this);return Array.isArray(r)?e:e[0]};et.prototype._p_rank=function(r){if(this.size()!==0){{if(r<this.centroids.min().mean)return 0;if(r>this.centroids.max().mean)return 1}this._cumulate(!0);var t=this.bound_mean(r),e=t[0],n=t[1];if(this.discrete)return e.cumn/this.n;var o=e.mean_cumn;return e!==n&&(o+=(r-e.mean)*(n.mean_cumn-e.mean_cumn)/(n.mean-e.mean)),o/this.n}};et.prototype.bound_mean_cumn=function(r){this.centroids._comparator=kf;var t=this.centroids.upperBound({mean_cumn:r});this.centroids._comparator=lc;var e=t.prev(),n=e&&e.mean_cumn===r?e:t.next();return[e,n]};et.prototype.percentile=function(r){var t=Array.isArray(r)?r:[r],e=t.map(this._percentile,this);return Array.isArray(r)?e:e[0]};et.prototype._percentile=function(r){if(this.size()!==0){this._cumulate(!0);var t=this.n*r,e=this.bound_mean_cumn(t),n=e[0],o=e[1];return o===n||n===null||o===null?(n||o).mean:this.discrete?t<=n.cumn?n.mean:o.mean:n.mean+(t-n.mean_cumn)*(o.mean-n.mean)/(o.mean_cumn-n.mean_cumn)}};function Uf(r){var t=Math.floor(Math.random()*r.length);return r.splice(t,1)[0]}et.prototype.compress=function(){if(!this.compressing){var r=this.toArray();for(this.reset(),this.compressing=!0;r.length>0;)this.push_centroid(Uf(r));this._cumulate(!0),this.compressing=!1}};function we(r){this.config=r||{},this.mode=this.config.mode||"auto",et.call(this,this.mode==="cont"?r.delta:!1),this.digest_ratio=this.config.ratio||.9,this.digest_thresh=this.config.thresh||1e3,this.n_unique=0}we.prototype=Object.create(et.prototype);we.prototype.constructor=we;we.prototype.push=function(r){et.prototype.push.call(this,r),this.check_continuous()};we.prototype._new_centroid=function(r,t,e){this.n_unique+=1,et.prototype._new_centroid.call(this,r,t,e)};we.prototype._addweight=function(r,t,e){r.n===1&&(this.n_unique-=1),et.prototype._addweight.call(this,r,t,e)};we.prototype.check_continuous=function(){return this.mode!=="auto"||this.size()<this.digest_thresh?!1:this.n_unique/this.size()>this.digest_ratio?(this.mode="cont",this.discrete=!1,this.delta=this.config.delta||.01,this.compress(),!0):!1};fc.exports={TDigest:et,Digest:we}});var T0={};Tt(T0,{LIBP2P_DEVTOOLS_METRICS_KEY:()=>Tl,SOURCE_CONTENT_SCRIPT:()=>I0,SOURCE_DEVTOOLS:()=>Il,SOURCE_METRICS:()=>Cl,SOURCE_SERVICE_WORKER:()=>_0,devToolsMetrics:()=>C0,valueCodecs:()=>Is});var mn=Symbol.for("@libp2p/peer-id");function Os(r){return!!r?.[mn]}var Fs;(function(r){r.Accept="accept",r.Ignore="ignore",r.Reject="reject"})(Fs||(Fs={}));var $l=Symbol.for("@libp2p/pubsub");function gn(r){return!!r?.[$l]}var ye=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},yn=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var xn=class extends Error{static name="InvalidCIDError";constructor(t="Invalid CID"){super(t),this.name="InvalidCIDError"}},bn=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var Ir=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};function Vs(r){return r!=null&&typeof r.start=="function"&&typeof r.stop=="function"}async function zs(...r){let t=[];for(let e of r)Vs(e)&&t.push(e);await Promise.all(t.map(async e=>{e.beforeStart!=null&&await e.beforeStart()})),await Promise.all(t.map(async e=>{await e.start()})),await Promise.all(t.map(async e=>{e.afterStart!=null&&await e.afterStart()}))}async function Hs(...r){let t=[];for(let e of r)Vs(e)&&t.push(e);await Promise.all(t.map(async e=>{e.beforeStop!=null&&await e.beforeStop()})),await Promise.all(t.map(async e=>{await e.stop()})),await Promise.all(t.map(async e=>{e.afterStop!=null&&await e.afterStop()}))}var xe=Symbol.for("@libp2p/service-capabilities"),P0=Symbol.for("@libp2p/service-dependencies");var Go={};Tt(Go,{base32:()=>qt,base32hex:()=>tf,base32hexpad:()=>rf,base32hexpadupper:()=>nf,base32hexupper:()=>ef,base32pad:()=>Ql,base32padupper:()=>Jl,base32upper:()=>Yl,base32z:()=>of});var om=new Uint8Array(0);function qs(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 oe(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 Ks(r){return new TextEncoder().encode(r)}function $s(r){return new TextDecoder().decode(r)}function Gl(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 c=r.length,a=r.charAt(0),l=Math.log(c)/Math.log(256),u=Math.log(256)/Math.log(c);function f(b){if(b instanceof Uint8Array||(ArrayBuffer.isView(b)?b=new Uint8Array(b.buffer,b.byteOffset,b.byteLength):Array.isArray(b)&&(b=Uint8Array.from(b))),!(b instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(b.length===0)return"";for(var g=0,d=0,E=0,A=b.length;E!==A&&b[E]===0;)E++,g++;for(var m=(A-E)*u+1>>>0,_=new Uint8Array(m);E!==A;){for(var R=b[E],N=0,T=m-1;(R!==0||N<d)&&T!==-1;T--,N++)R+=256*_[T]>>>0,_[T]=R%c>>>0,R=R/c>>>0;if(R!==0)throw new Error("Non-zero carry");d=N,E++}for(var U=m-d;U!==m&&_[U]===0;)U++;for(var k=a.repeat(g);U<m;++U)k+=r.charAt(_[U]);return k}function h(b){if(typeof b!="string")throw new TypeError("Expected String");if(b.length===0)return new Uint8Array;var g=0;if(b[g]!==" "){for(var d=0,E=0;b[g]===a;)d++,g++;for(var A=(b.length-g)*l+1>>>0,m=new Uint8Array(A);b[g];){var _=e[b.charCodeAt(g)];if(_===255)return;for(var R=0,N=A-1;(_!==0||R<E)&&N!==-1;N--,R++)_+=c*m[N]>>>0,m[N]=_%256>>>0,_=_/256>>>0;if(_!==0)throw new Error("Non-zero carry");E=R,g++}if(b[g]!==" "){for(var T=A-E;T!==A&&m[T]===0;)T++;for(var U=new Uint8Array(d+(A-T)),k=d;T!==A;)U[k++]=m[T++];return U}}}function x(b){var g=h(b);if(g)return g;throw new Error(`Non-${t} character`)}return{encode:f,decodeUnsafe:h,decode:x}}var jl=Gl,Zl=jl,js=Zl;var Ho=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")}},qo=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 Zs(this,t)}},Ko=class{decoders;constructor(t){this.decoders=t}or(t){return Zs(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 Zs(r,t){return new Ko({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var $o=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 Ho(t,e,n),this.decoder=new qo(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Ze({name:r,prefix:t,encode:e,decode:n}){return new $o(r,t,e,n)}function be({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=js(e,r);return Ze({prefix:t,name:r,encode:n,decode:i=>oe(o(i))})}function Wl(r,t,e,n){let o={};for(let u=0;u<t.length;++u)o[t[u]]=u;let i=r.length;for(;r[i-1]==="=";)--i;let s=new Uint8Array(i*e/8|0),c=0,a=0,l=0;for(let u=0;u<i;++u){let f=o[r[u]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<e|f,c+=e,c>=8&&(c-=8,s[l++]=255&a>>c)}if(c>=e||(255&a<<8-c)!==0)throw new SyntaxError("Unexpected end of data");return s}function Xl(r,t,e){let n=t[t.length-1]==="=",o=(1<<e)-1,i="",s=0,c=0;for(let a=0;a<r.length;++a)for(c=c<<8|r[a],s+=8;s>e;)s-=e,i+=t[o&c>>s];if(s!==0&&(i+=t[o&c<<e-s]),n)for(;(i.length*e&7)!==0;)i+="=";return i}function it({name:r,prefix:t,bitsPerChar:e,alphabet:n}){return Ze({prefix:t,name:r,encode(o){return Xl(o,n,e)},decode(o){return Wl(o,n,e,r)}})}var qt=it({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Yl=it({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Ql=it({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Jl=it({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),tf=it({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),ef=it({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),rf=it({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),nf=it({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),of=it({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var jo={};Tt(jo,{base58btc:()=>tt,base58flickr:()=>sf});var tt=be({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),sf=be({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Zo={};Tt(Zo,{base64:()=>te,base64pad:()=>cf,base64url:()=>af,base64urlpad:()=>uf});var te=it({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),cf=it({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),af=it({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),uf=it({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});function lf(r,t){try{if(typeof r=="string"&&r.length>0)return ff(r);if(typeof r=="number"&&isFinite(r))return t?.long?hf(r):df(r);throw new Error("Value is not a string or number.")}catch(e){let n=pf(e)?`${e.message}. value=${JSON.stringify(r)}`:"An unknown error has occured.";throw new Error(n)}}function ff(r){if(r=String(r),r.length>100)throw new Error("Value exceeds the maximum length of 100 characters.");let t=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(r);if(!t)return NaN;let e=parseFloat(t[1]),n=(t[2]||"ms").toLowerCase();switch(n){case"years":case"year":case"yrs":case"yr":case"y":return e*315576e5;case"weeks":case"week":case"w":return e*6048e5;case"days":case"day":case"d":return e*864e5;case"hours":case"hour":case"hrs":case"hr":case"h":return e*36e5;case"minutes":case"minute":case"mins":case"min":case"m":return e*6e4;case"seconds":case"second":case"secs":case"sec":case"s":return e*1e3;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return e;default:throw new Error(`The unit ${n} was matched, but no matching case exists.`)}}var En=lf;function df(r){let t=Math.abs(r);return t>=864e5?`${Math.round(r/864e5)}d`:t>=36e5?`${Math.round(r/36e5)}h`:t>=6e4?`${Math.round(r/6e4)}m`:t>=1e3?`${Math.round(r/1e3)}s`:`${r}ms`}function hf(r){let t=Math.abs(r);return t>=864e5?wn(r,t,864e5,"day"):t>=36e5?wn(r,t,36e5,"hour"):t>=6e4?wn(r,t,6e4,"minute"):t>=1e3?wn(r,t,1e3,"second"):`${r} ms`}function wn(r,t,e,n){let o=t>=e*1.5;return`${Math.round(r/e)} ${n}${o?"s":""}`}function pf(r){return typeof r=="object"&&r!==null&&"message"in r}function Wo(r){e.debug=e,e.default=e,e.coerce=a,e.disable=i,e.enable=o,e.enabled=s,e.humanize=En,e.destroy=l,Object.keys(r).forEach(u=>{e[u]=r[u]}),e.names=[],e.skips=[],e.formatters={};function t(u){let f=0;for(let h=0;h<u.length;h++)f=(f<<5)-f+u.charCodeAt(h),f|=0;return e.colors[Math.abs(f)%e.colors.length]}e.selectColor=t;function e(u){let f,h=null,x,b;function g(...d){if(!g.enabled)return;let E=g,A=Number(new Date),m=A-(f||A);E.diff=m,E.prev=f,E.curr=A,f=A,d[0]=e.coerce(d[0]),typeof d[0]!="string"&&d.unshift("%O");let _=0;d[0]=d[0].replace(/%([a-zA-Z%])/g,(N,T)=>{if(N==="%%")return"%";_++;let U=e.formatters[T];if(typeof U=="function"){let k=d[_];N=U.call(E,k),d.splice(_,1),_--}return N}),e.formatArgs.call(E,d),(E.log||e.log).apply(E,d)}return g.namespace=u,g.useColors=e.useColors(),g.color=e.selectColor(u),g.extend=n,g.destroy=e.destroy,Object.defineProperty(g,"enabled",{enumerable:!0,configurable:!1,get:()=>h!==null?h:(x!==e.namespaces&&(x=e.namespaces,b=e.enabled(u)),b),set:d=>{h=d}}),typeof e.init=="function"&&e.init(g),g}function n(u,f){let h=e(this.namespace+(typeof f>"u"?":":f)+u);return h.log=this.log,h}function o(u){e.save(u),e.namespaces=u,e.names=[],e.skips=[];let f,h=(typeof u=="string"?u:"").split(/[\s,]+/),x=h.length;for(f=0;f<x;f++)h[f]&&(u=h[f].replace(/\*/g,".*?"),u[0]==="-"?e.skips.push(new RegExp("^"+u.substr(1)+"$")):e.names.push(new RegExp("^"+u+"$")))}function i(){let u=[...e.names.map(c),...e.skips.map(c).map(f=>"-"+f)].join(",");return e.enable(""),u}function s(u){if(u[u.length-1]==="*")return!0;let f,h;for(f=0,h=e.skips.length;f<h;f++)if(e.skips[f].test(u))return!1;for(f=0,h=e.names.length;f<h;f++)if(e.names[f].test(u))return!0;return!1}function c(u){return u.toString().substring(2,u.toString().length-2).replace(/\.\*\?$/,"*")}function a(u){return u instanceof Error?u.stack??u.message:u}function l(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")}return e.setupFormatters(e.formatters),e.enable(e.load()),e}var vn=Ef(),mf=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"];function gf(){return typeof window<"u"&&window.process&&(window.process.type==="renderer"||window.process.__nwjs)?!0:typeof navigator<"u"&&navigator.userAgent?.toLowerCase().match(/(edge|trident)\/(\d+)/)!=null?!1:typeof document<"u"&&document.documentElement?.style?.WebkitAppearance||typeof window<"u"&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator<"u"&&navigator.userAgent?.toLowerCase().match(/firefox\/(\d+)/)!=null&&parseInt(RegExp.$1,10)>=31||typeof navigator<"u"&&navigator.userAgent?.toLowerCase().match(/applewebkit\/(\d+)/)}function yf(r){if(r[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+r[0]+(this.useColors?"%c ":" ")+"+"+En(this.diff),!this.useColors)return;let t="color: "+this.color;r.splice(1,0,t,"color: inherit");let e=0,n=0;r[0].replace(/%[a-zA-Z%]/g,o=>{o!=="%%"&&(e++,o==="%c"&&(n=e))}),r.splice(n,0,t)}var xf=console.debug??console.log??(()=>{});function bf(r){try{r?vn?.setItem("debug",r):vn?.removeItem("debug")}catch{}}function wf(){let r;try{r=vn?.getItem("debug")}catch{}return!r&&typeof globalThis.process<"u"&&"env"in globalThis.process&&(r=globalThis.process.env.DEBUG),r}function Ef(){try{return localStorage}catch{}}function vf(r){r.j=function(t){try{return JSON.stringify(t)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}}}var Ws=Wo({formatArgs:yf,save:bf,load:wf,useColors:gf,setupFormatters:vf,colors:mf,storage:vn,log:xf});var xt=Ws;xt.formatters.b=r=>r==null?"undefined":tt.baseEncode(r);xt.formatters.t=r=>r==null?"undefined":qt.baseEncode(r);xt.formatters.m=r=>r==null?"undefined":te.baseEncode(r);xt.formatters.p=r=>r==null?"undefined":r.toString();xt.formatters.c=r=>r==null?"undefined":r.toString();xt.formatters.k=r=>r==null?"undefined":r.toString();xt.formatters.a=r=>r==null?"undefined":r.toString();xt.formatters.e=r=>r==null?"undefined":Xs(r.stack)??Xs(r.message)??r.toString();function Sf(r){let t=()=>{};return t.enabled=!1,t.color="",t.diff=0,t.log=()=>{},t.namespace=r,t.destroy=()=>!0,t.extend=()=>t,t}function Ys(r){let t=Sf(`${r}:trace`);return xt.enabled(`${r}:trace`)&&xt.names.map(e=>e.toString()).find(e=>e.includes(":trace"))!=null&&(t=xt(`${r}:trace`)),Object.assign(xt(r),{error:xt(`${r}:error`),trace:t})}function Qs(){xt.disable()}function Js(r){xt.enable(r)}function Xs(r){if(r!=null&&(r=r.trim(),r.length!==0))return r}function Af(r){let[t,e]=r[Symbol.asyncIterator]!=null?[r[Symbol.asyncIterator](),Symbol.asyncIterator]:[r[Symbol.iterator](),Symbol.iterator],n=[];return{peek:()=>t.next(),push:o=>{n.push(o)},next:()=>n.length>0?{done:!1,value:n.shift()}:t.next(),[e](){return this}}}var tc=Af;function Bf(r){return r[Symbol.asyncIterator]!=null}function ec(r){return r?.then!=null}function _f(r,t){let e=0;if(Bf(r))return async function*(){for await(let a of r){let l=t(a,e++);ec(l)&&await l,yield a}}();let n=tc(r),{value:o,done:i}=n.next();if(i===!0)return function*(){}();if(typeof t(o,e++)?.then=="function")return async function*(){yield o;for await(let a of n){let l=t(a,e++);ec(l)&&await l,yield a}}();let c=t;return function*(){yield o;for(let a of n)c(a,e++),yield a}()}var Xo=_f;var hc=ql(dc(),1),Lf=Ys("libp2p:simple-metrics"),kr=class{value=0;update(t){this.value=t}increment(t=1){this.value+=t}decrement(t=1){this.value-=t}reset(){this.value=0}timer(){let t=Date.now();return()=>{this.value=Date.now()-t}}},Ur=class{values={};update(t){Object.entries(t).forEach(([e,n])=>{this.values[e]=n})}increment(t){Object.entries(t).forEach(([e,n])=>{this.values[e]=this.values[e]??0;let o=typeof n=="number"?n:1;this.values[e]+=Number(o)})}decrement(t){Object.entries(t).forEach(([e,n])=>{this.values[e]=this.values[e]??0;let o=typeof n=="number"?n:1;this.values[e]-=Number(o)})}reset(){this.values={}}timer(t){let e=Date.now();return()=>{this.values[t]=Date.now()-e}}},Lr=class{bucketValues=new Map;countValue=0;sumValue=0;constructor(t){let e=[...t.buckets??[.005,.01,.025,.05,.1,.25,.5,1,2.5,5,10],1/0];for(let n of e)this.bucketValues.set(n,0)}observe(t){this.countValue++,this.sumValue+=t;for(let[e,n]of this.bucketValues.entries())t<=e&&this.bucketValues.set(e,n+1)}reset(){this.countValue=0,this.sumValue=0;for(let t of this.bucketValues.keys())this.bucketValues.set(t,0)}timer(){let t=Date.now();return()=>{this.observe(Date.now()-t)}}},Bn=class{histograms={};constructor(t){this.histograms={}}observe(t){for(let[e,n]of Object.entries(t))this.histograms[e]===void 0&&(this.histograms[e]=new Lr({})),this.histograms[e].observe(n)}reset(){for(let t of Object.values(this.histograms))t.reset()}timer(t){let e=Date.now();return()=>{this.observe({[t]:Date.now()-e})}}},Nr=class{sumValue=0;countValue=0;percentiles;tdigest=new hc.TDigest(.01);compressCount;constructor(t){this.percentiles=t.percentiles??[.01,.05,.5,.9,.95,.99,.999],this.compressCount=t.compressCount??1e3}observe(t){this.sumValue+=t,this.countValue++,this.tdigest.push(t),this.tdigest.size()>this.compressCount&&this.tdigest.compress()}reset(){this.sumValue=0,this.countValue=0,this.tdigest.reset()}timer(){let t=Date.now();return()=>{this.observe(Date.now()-t)}}},_n=class{summaries={};opts;constructor(t){this.summaries={},this.opts=t}observe(t){for(let[e,n]of Object.entries(t))this.summaries[e]===void 0&&(this.summaries[e]=new Nr(this.opts)),this.summaries[e].observe(n)}reset(){for(let t of Object.values(this.summaries))t.reset()}timer(t){let e=Date.now();return()=>{this.observe({[t]:Date.now()-e})}}},Qo=class{metrics=new Map;transferStats;started;interval;intervalMs;onMetrics;constructor(t,e){this.started=!1,this._emitMetrics=this._emitMetrics.bind(this),this.intervalMs=e.intervalMs??1e3,this.onMetrics=e.onMetrics,this.transferStats=new Map}[Symbol.toStringTag]="@libp2p/metrics-simple";[xe]=["@libp2p/metrics"];isStarted(){return this.started}start(){this.started=!0,this.interval=setInterval(this._emitMetrics,this.intervalMs)}stop(){this.started=!1,clearInterval(this.interval)}_emitMetrics(){Promise.resolve().then(async()=>{let t={};for(let[e,n]of this.metrics.entries())n instanceof kr?t[e]=n.value:n instanceof Ur?t[e]=n.values:n instanceof Lr?t[e]={count:n.countValue,sum:n.sumValue,buckets:{...n.bucketValues}}:n instanceof Bn?t[e]={...Object.fromEntries(Object.entries(n.histograms).map(([o,i])=>[o,{count:i.countValue,sum:i.sumValue,buckets:{...i.bucketValues}}]))}:n instanceof Nr?t[e]={count:n.countValue,sum:n.sumValue,percentiles:Object.fromEntries(n.percentiles.map(o=>[o,n.tdigest.percentile(o)]))}:n instanceof _n?t[e]={...Object.fromEntries(Object.entries(n.summaries).map(([o,i])=>[o,{count:i.countValue,sum:i.sumValue,percentiles:Object.fromEntries(i.percentiles.map(s=>[s,i.tdigest.percentile(s)]))}]))}:t[e]=await n();this.onMetrics(structuredClone(t))}).catch(t=>{Lf.error("could not invoke onMetrics callback",t)})}_incrementValue(t,e){let n=this.transferStats.get(t)??0;this.transferStats.set(t,n+e)}_track(t,e){let n=this,o=t.sink;t.sink=async function(c){await o(Xo(c,a=>{n._incrementValue(`${e} sent`,a.byteLength)}))};let i=t.source;t.source=Xo(i,s=>{n._incrementValue(`${e} received`,s.byteLength)})}trackMultiaddrConnection(t){this._track(t,"global")}trackProtocolStream(t,e){t.protocol!=null&&this._track(t,t.protocol)}registerMetric(t,e={}){if(t==null||t.trim()==="")throw new Error("Metric name is required");if(e?.calculate!=null){this.metrics.set(t,e.calculate);return}let n=new kr;return this.metrics.set(t,n),n}registerMetricGroup(t,e={}){if(t==null||t.trim()==="")throw new Error("Metric name is required");if(e?.calculate!=null){this.metrics.set(t,e.calculate);return}let n=new Ur;return this.metrics.set(t,n),n}registerCounter(t,e={}){if(t==null||t.trim()==="")throw new Error("Metric name is required");if(e?.calculate!=null){this.metrics.set(t,e.calculate);return}let n=new kr;return this.metrics.set(t,n),n}registerCounterGroup(t,e={}){if(t==null||t.trim()==="")throw new Error("Metric name is required");if(e?.calculate!=null){this.metrics.set(t,e.calculate);return}let n=new Ur;return this.metrics.set(t,n),n}registerHistogram(t,e={}){if(t==null||t.trim()==="")throw new Error("Metric name is required");if(e?.calculate!=null){this.metrics.set(t,e.calculate);return}let n=new Lr(e);return this.metrics.set(t,n),n}registerHistogramGroup(t,e={}){if(t==null||t.trim()==="")throw new Error("Metric name is required");if(e?.calculate!=null){this.metrics.set(t,e.calculate);return}let n=new Bn(e);return this.metrics.set(t,n),n}registerSummary(t,e={}){if(t==null||t.trim()==="")throw new Error("Metric name is required");if(e?.calculate!=null){this.metrics.set(t,e.calculate);return}let n=new Nr(e);return this.metrics.set(t,n),n}registerSummaryGroup(t,e={}){if(t==null||t.trim()==="")throw new Error("Metric name is required");if(e?.calculate!=null){this.metrics.set(t,e.calculate);return}let n=new _n(e);return this.metrics.set(t,n),n}createTrace(){}traceFunction(t,e){return e}};function pc(r){return t=>new Qo(t,r)}function bt(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var In=class{buffer;mask;top;btm;next;constructor(t){if(!(t>0)||(t-1&t)!==0)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(t),this.mask=t-1,this.top=0,this.btm=0,this.next=null}push(t){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=t,this.top=this.top+1&this.mask,!0)}shift(){let t=this.buffer[this.btm];if(t!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,t}isEmpty(){return this.buffer[this.btm]===void 0}},Ye=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new In(this.hwm),this.tail=this.head,this.size=0}calculateSize(t){return t?.byteLength!=null?t.byteLength:1}push(t){if(t?.value!=null&&(this.size+=this.calculateSize(t.value)),!this.head.push(t)){let e=this.head;this.head=e.next=new In(2*this.head.buffer.length),this.head.push(t)}}shift(){let t=this.tail.shift();if(t===void 0&&this.tail.next!=null){let e=this.tail.next;this.tail.next=null,this.tail=e,t=this.tail.shift()}return t?.value!=null&&(this.size-=this.calculateSize(t.value)),t}isEmpty(){return this.head.isEmpty()}};var Jo=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.code=e??"ABORT_ERR"}};function Qe(r={}){return Nf(e=>{let n=e.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},r)}function Nf(r,t){t=t??{};let e=t.onEnd,n=new Ye,o,i,s,c=bt(),a=async()=>{try{return n.isEmpty()?s?{done:!0}:await new Promise((d,E)=>{i=A=>{i=null,n.push(A);try{d(r(n))}catch(m){E(m)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{c.resolve(),c=bt()})}},l=d=>i!=null?i(d):(n.push(d),o),u=d=>(n=new Ye,i!=null?i({error:d}):(n.push({error:d}),o)),f=d=>{if(s)return o;if(t?.objectMode!==!0&&d?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return l({done:!1,value:d})},h=d=>s?o:(s=!0,d!=null?u(d):l({done:!0})),x=()=>(n=new Ye,h(),{done:!0}),b=d=>(h(d),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:a,return:x,throw:b,push:f,end:h,get readableLength(){return n.size},onEmpty:async d=>{let E=d?.signal;if(E?.throwIfAborted(),n.isEmpty())return;let A,m;E!=null&&(A=new Promise((_,R)=>{m=()=>{R(new Jo)},E.addEventListener("abort",m)}));try{await Promise.race([c.promise,A])}finally{m!=null&&E!=null&&E?.removeEventListener("abort",m)}}},e==null)return o;let g=o;return o={[Symbol.asyncIterator](){return this},next(){return g.next()},throw(d){return g.throw(d),e!=null&&(e(d),e=void 0),{done:!0}},return(){return g.return(),e!=null&&(e(),e=void 0),{done:!0}},push:f,end(d){return g.end(d),e!=null&&(e(d),e=void 0),o},get readableLength(){return g.readableLength},onEmpty:d=>g.onEmpty(d)},o}var Cn=class extends Error{type;code;constructor(t,e,n){super(t??"The operation was aborted"),this.type="aborted",this.name=n??"AbortError",this.code=e??"ABORT_ERR"}};async function mc(r,t,e){if(t==null)return r;if(t.aborted)return r.catch(()=>{}),Promise.reject(new Cn(e?.errorMessage,e?.errorCode,e?.errorName));let n,o=new Cn(e?.errorMessage,e?.errorCode,e?.errorName);try{return await Promise.race([r,new Promise((i,s)=>{n=()=>{s(o)},t.addEventListener("abort",n)})])}finally{n!=null&&t.removeEventListener("abort",n)}}var ti=class{readNext;haveNext;ended;nextResult;error;constructor(){this.ended=!1,this.readNext=bt(),this.haveNext=bt()}[Symbol.asyncIterator](){return this}async next(){if(this.nextResult==null&&await this.haveNext.promise,this.nextResult==null)throw new Error("HaveNext promise resolved but nextResult was undefined");let t=this.nextResult;return this.nextResult=void 0,this.readNext.resolve(),this.readNext=bt(),t}async throw(t){return this.ended=!0,this.error=t,t!=null&&(this.haveNext.promise.catch(()=>{}),this.haveNext.reject(t)),{done:!0,value:void 0}}async return(){let t={done:!0,value:void 0};return this.ended=!0,this.nextResult=t,this.haveNext.resolve(),t}async push(t,e){await this._push(t,e)}async end(t,e){t!=null?await this.throw(t):await this._push(void 0,e)}async _push(t,e){if(t!=null&&this.ended)throw this.error??new Error("Cannot push value onto an ended pushable");for(;this.nextResult!=null;)await this.readNext.promise;t!=null?this.nextResult={done:!1,value:t}:(this.ended=!0,this.nextResult={done:!0,value:void 0}),this.haveNext.resolve(),this.haveNext=bt(),await mc(this.readNext.promise,e?.signal,e)}};function gc(){return new ti}function Rf(r){return r[Symbol.asyncIterator]!=null}async function Pf(r,t){try{await Promise.all(r.map(async e=>{for await(let n of e)await t.push(n)})),await t.end()}catch(e){await t.end(e).catch(()=>{})}}async function*Df(r){let t=gc();Pf(r,t).catch(()=>{}),yield*t}function*Mf(r){for(let t of r)yield*t}function Of(...r){let t=[];for(let e of r)Rf(e)||t.push(e);return t.length===r.length?Mf(t):Df(r)}var yc=Of;function xc(r,...t){if(r==null)throw new Error("Empty pipeline");if(ei(r)){let n=r;r=()=>n.source}else if(wc(r)||bc(r)){let n=r;r=()=>n}let e=[r,...t];if(e.length>1&&ei(e[e.length-1])&&(e[e.length-1]=e[e.length-1].sink),e.length>2)for(let n=1;n<e.length-1;n++)ei(e[n])&&(e[n]=Vf(e[n]));return Ff(...e)}var Ff=(...r)=>{let t;for(;r.length>0;)t=r.shift()(t);return t},bc=r=>r?.[Symbol.asyncIterator]!=null,wc=r=>r?.[Symbol.iterator]!=null,ei=r=>r==null?!1:r.sink!=null&&r.source!=null,Vf=r=>t=>{let e=r.sink(t);if(e?.then!=null){let n=Qe({objectMode:!0});e.then(()=>{n.end()},s=>{n.end(s)});let o,i=r.source;if(bc(i))o=async function*(){yield*i,n.end()};else if(wc(i))o=function*(){yield*i,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return yc(n,o())}return r.source};function Tn(r){let t=new globalThis.AbortController;function e(){t.abort();for(let i of r)i?.removeEventListener!=null&&i.removeEventListener("abort",e)}for(let i of r){if(i?.aborted===!0){e();break}i?.addEventListener!=null&&i.addEventListener("abort",e)}function n(){for(let i of r)i?.removeEventListener!=null&&i.removeEventListener("abort",e)}let o=t.signal;return o.clear=n,o}function $t(r=0){return new Uint8Array(r)}function wt(r=0){return new Uint8Array(r)}var zf=Math.pow(2,7),Hf=Math.pow(2,14),qf=Math.pow(2,21),ri=Math.pow(2,28),ni=Math.pow(2,35),oi=Math.pow(2,42),ii=Math.pow(2,49),G=128,Et=127;function dt(r){if(r<zf)return 1;if(r<Hf)return 2;if(r<qf)return 3;if(r<ri)return 4;if(r<ni)return 5;if(r<oi)return 6;if(r<ii)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function si(r,t,e=0){switch(dt(r)){case 8:t[e++]=r&255|G,r/=128;case 7:t[e++]=r&255|G,r/=128;case 6:t[e++]=r&255|G,r/=128;case 5:t[e++]=r&255|G,r/=128;case 4:t[e++]=r&255|G,r>>>=7;case 3:t[e++]=r&255|G,r>>>=7;case 2:t[e++]=r&255|G,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function Kf(r,t,e=0){switch(dt(r)){case 8:t.set(e++,r&255|G),r/=128;case 7:t.set(e++,r&255|G),r/=128;case 6:t.set(e++,r&255|G),r/=128;case 5:t.set(e++,r&255|G),r/=128;case 4:t.set(e++,r&255|G),r>>>=7;case 3:t.set(e++,r&255|G),r>>>=7;case 2:t.set(e++,r&255|G),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function ci(r,t){let e=r[t],n=0;if(n+=e&Et,e<G||(e=r[t+1],n+=(e&Et)<<7,e<G)||(e=r[t+2],n+=(e&Et)<<14,e<G)||(e=r[t+3],n+=(e&Et)<<21,e<G)||(e=r[t+4],n+=(e&Et)*ri,e<G)||(e=r[t+5],n+=(e&Et)*ni,e<G)||(e=r[t+6],n+=(e&Et)*oi,e<G)||(e=r[t+7],n+=(e&Et)*ii,e<G))return n;throw new RangeError("Could not decode varint")}function $f(r,t){let e=r.get(t),n=0;if(n+=e&Et,e<G||(e=r.get(t+1),n+=(e&Et)<<7,e<G)||(e=r.get(t+2),n+=(e&Et)<<14,e<G)||(e=r.get(t+3),n+=(e&Et)<<21,e<G)||(e=r.get(t+4),n+=(e&Et)*ri,e<G)||(e=r.get(t+5),n+=(e&Et)*ni,e<G)||(e=r.get(t+6),n+=(e&Et)*oi,e<G)||(e=r.get(t+7),n+=(e&Et)*ii,e<G))return n;throw new RangeError("Could not decode varint")}function Ee(r,t,e=0){return t==null&&(t=wt(dt(r))),t instanceof Uint8Array?si(r,t,e):Kf(r,t,e)}function ie(r,t=0){return r instanceof Uint8Array?ci(r,t):$f(r,t)}function Nt(r,t){t==null&&(t=r.reduce((o,i)=>o+i.length,0));let e=wt(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return e}function Gt(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}var vc=Symbol.for("@achingbrain/uint8arraylist");function Ec(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 Un(r){return!!r?.[vc]}var Je=class r{bufs;length;[vc]=!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(Un(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(Un(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=Ec(this.bufs,t);return e.buf[e.index]}set(t,e){let n=Ec(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(Un(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 Nt(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:Nt(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],c=o,a=c+s.byteLength;if(o=a,t>=a)continue;let l=t>=c&&t<a,u=e>c&&e<=a;if(l&&u){if(t===c&&e===a){n.push(s);break}let f=t-c;n.push(s.subarray(f,f+(e-t)));break}if(l){if(t===0){n.push(s);continue}n.push(s.subarray(t-c));continue}if(u){if(e===a){n.push(s);break}n.push(s.subarray(0,e-c));break}n.push(s)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!Un(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 f=0;f<i;f++)s[f]=-1;for(let f=0;f<o;f++)s[n[f]]=f;let c=s,a=this.byteLength-n.byteLength,l=n.byteLength-1,u;for(let f=e;f<=a;f+=u){u=0;for(let h=l;h>=0;h--){let x=this.get(f+h);if(n[h]!==x){u=Math.max(1,h-c[x]);break}}if(u===0)return f}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=wt(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=$t(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=$t(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=$t(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=wt(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=$t(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=$t(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=$t(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=$t(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=$t(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(!Gt(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}};var Ln=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},tr=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},Nn=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"},Rr=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};function Rn(r){return r[Symbol.asyncIterator]!=null}function Sc(r,t){if(r.byteLength>t)throw new tr("Message length too long")}var Dn=r=>{let t=dt(r),e=wt(t);return Ee(r,e),Dn.bytes=t,e};Dn.bytes=0;function Mn(r,t){t=t??{};let e=t.lengthEncoder??Dn,n=t?.maxDataLength??4194304;function*o(i){Sc(i,n);let s=e(i.byteLength);s instanceof Uint8Array?yield s:yield*s,i instanceof Uint8Array?yield i:yield*i}return Rn(r)?async function*(){for await(let i of r)yield*o(i)}():function*(){for(let i of r)yield*o(i)}()}Mn.single=(r,t)=>{t=t??{};let e=t.lengthEncoder??Dn,n=t?.maxDataLength??4194304;return Sc(r,n),new Je(e(r.byteLength),r)};var Re;(function(r){r[r.LENGTH=0]="LENGTH",r[r.DATA=1]="DATA"})(Re||(Re={}));var ai=r=>{let t=ie(r);return ai.bytes=dt(t),t};ai.bytes=0;function Pr(r,t){let e=new Je,n=Re.LENGTH,o=-1,i=t?.lengthDecoder??ai,s=t?.maxLengthLength??8,c=t?.maxDataLength??4194304;function*a(){for(;e.byteLength>0;){if(n===Re.LENGTH)try{if(o=i(e),o<0)throw new Ln("Invalid message length");if(o>c)throw new tr("Message length too long");let l=i.bytes;e.consume(l),t?.onLength!=null&&t.onLength(o),n=Re.DATA}catch(l){if(l instanceof RangeError){if(e.byteLength>s)throw new Nn("Message length length too long");break}throw l}if(n===Re.DATA){if(e.byteLength<o)break;let l=e.sublist(0,o);e.consume(o),t?.onData!=null&&t.onData(l),yield l,n=Re.LENGTH}}}return Rn(r)?async function*(){for await(let l of r)e.append(l),yield*a();if(e.byteLength>0)throw new Rr("Unexpected end of input")}():function*(){for(let l of r)e.append(l),yield*a();if(e.byteLength>0)throw new Rr("Unexpected end of input")}()}Pr.fromReader=(r,t)=>{let e=1,n=async function*(){for(;;)try{let{done:i,value:s}=await r.next(e);if(i===!0)return;s!=null&&(yield s)}catch(i){if(i.code==="ERR_UNDER_READ")return{done:!0,value:null};throw i}finally{e=1}}();return Pr(n,{...t??{},onLength:i=>{e=i}})};var Ac="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";var er=(r=21)=>{let t="",e=crypto.getRandomValues(new Uint8Array(r|=0));for(;r--;)t+=Ac[e[r]&63];return t};var On=class extends Error{constructor(t="Method not found"){super(t),this.name="MethodNotFoundError"}},Fn=class extends Error{constructor(t="Invocation target was not a function"){super(t),this.name="InvalidMethodError"}},Dr=class extends Error{constructor(t="Unsupported value type"){super(t),this.name="UnsupportedValueTypeError"}},Vn=class extends Error{constructor(t="Cannot reuse RPC target name"){super(t),this.name="DuplicateTargetNameError"}},Mr=class extends Error{constructor(t="Duplicate scope"){super(t),this.name="DuplicateScopeError"}},zn=class extends Error{constructor(t="Invalid return type"){super(t),this.name="InvalidReturnTypeError"}},Or=class extends Error{constructor(t="Invocation target was not a function"){super(t),this.name="InvalidInvocationTypeError"}},rr=class extends Error{constructor(t="Parent invocation scope not found"){super(t),this.name="MissingParentScopeError"}},Hn=class extends Error{constructor(t="Invocation not found"){super(t),this.name="MissingInvocationError"}},qn=class extends Error{constructor(t="Callback not found"){super(t),this.name="MissingCallbackError"}};var ui=new Float32Array([-0]),ve=new Uint8Array(ui.buffer);function Bc(r,t,e){ui[0]=r,t[e]=ve[0],t[e+1]=ve[1],t[e+2]=ve[2],t[e+3]=ve[3]}function _c(r,t){return ve[0]=r[t],ve[1]=r[t+1],ve[2]=r[t+2],ve[3]=r[t+3],ui[0]}var li=new Float64Array([-0]),vt=new Uint8Array(li.buffer);function Ic(r,t,e){li[0]=r,t[e]=vt[0],t[e+1]=vt[1],t[e+2]=vt[2],t[e+3]=vt[3],t[e+4]=vt[4],t[e+5]=vt[5],t[e+6]=vt[6],t[e+7]=vt[7]}function Cc(r,t){return vt[0]=r[t],vt[1]=r[t+1],vt[2]=r[t+2],vt[3]=r[t+3],vt[4]=r[t+4],vt[5]=r[t+5],vt[6]=r[t+6],vt[7]=r[t+7],li[0]}var jf=BigInt(Number.MAX_SAFE_INTEGER),Zf=BigInt(Number.MIN_SAFE_INTEGER),Rt=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 Pe;if(t<jf&&t>Zf)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>Tc&&(o=0n,++n>Tc&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(t){if(t===0)return Pe;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):Pe}},Pe=new Rt(0,0);Pe.toBigInt=function(){return 0n};Pe.zzEncode=Pe.zzDecode=function(){return this};Pe.length=function(){return 1};var Tc=4294967296n;function kc(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 Uc(r,t,e){if(e-t<1)return"";let o,i=[],s=0,c;for(;t<e;)c=r[t++],c<128?i[s++]=c:c>191&&c<224?i[s++]=(c&31)<<6|r[t++]&63:c>239&&c<365?(c=((c&7)<<18|(r[t++]&63)<<12|(r[t++]&63)<<6|r[t++]&63)-65536,i[s++]=55296+(c>>10),i[s++]=56320+(c&1023)):i[s++]=(c&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 fi(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 jt(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function Kn(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var di=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,jt(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 jt(this,4);return Kn(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw jt(this,4);return Kn(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw jt(this,4);let t=_c(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw jt(this,4);let t=Cc(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 jt(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return Uc(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw jt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw jt(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 Rt(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 jt(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 jt(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 jt(this,8);let t=Kn(this.buf,this.pos+=4),e=Kn(this.buf,this.pos+=4);return new Rt(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=ci(this.buf,this.pos);return this.pos+=dt(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 hi(r){return new di(r instanceof Uint8Array?r:r.subarray())}function At(r,t,e){let n=hi(r);return t.decode(n,void 0,e)}var pi={};Tt(pi,{base10:()=>Wf});var Wf=be({prefix:"9",name:"base10",alphabet:"0123456789"});var mi={};Tt(mi,{base16:()=>Xf,base16upper:()=>Yf});var Xf=it({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Yf=it({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var gi={};Tt(gi,{base2:()=>Qf});var Qf=it({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var yi={};Tt(yi,{base256emoji:()=>nd});var Nc=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}"),Jf=Nc.reduce((r,t,e)=>(r[e]=t,r),[]),td=Nc.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function ed(r){return r.reduce((t,e)=>(t+=Jf[e],t),"")}function rd(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let o=td[n];if(o==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(o)}return new Uint8Array(t)}var nd=Ze({prefix:"\u{1F680}",name:"base256emoji",encode:ed,decode:rd});var xi={};Tt(xi,{base36:()=>Fr,base36upper:()=>od});var Fr=be({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),od=be({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var bi={};Tt(bi,{base8:()=>id});var id=it({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var wi={};Tt(wi,{identity:()=>sd});var sd=Ze({prefix:"\0",name:"identity",encode:r=>$s(r),decode:r=>Ks(r)});var jg=new TextEncoder,Zg=new TextDecoder;var vi={};Tt(vi,{identity:()=>ce});var ud=Dc,Rc=128,ld=127,fd=~ld,dd=Math.pow(2,31);function Dc(r,t,e){t=t||[],e=e||0;for(var n=e;r>=dd;)t[e++]=r&255|Rc,r/=128;for(;r&fd;)t[e++]=r&255|Rc,r>>>=7;return t[e]=r|0,Dc.bytes=e-n+1,t}var hd=Ei,pd=128,Pc=127;function Ei(r,n){var e=0,n=n||0,o=0,i=n,s,c=r.length;do{if(i>=c)throw Ei.bytes=0,new RangeError("Could not decode varint");s=r[i++],e+=o<28?(s&Pc)<<o:(s&Pc)*Math.pow(2,o),o+=7}while(s>=pd);return Ei.bytes=i-n,e}var md=Math.pow(2,7),gd=Math.pow(2,14),yd=Math.pow(2,21),xd=Math.pow(2,28),bd=Math.pow(2,35),wd=Math.pow(2,42),Ed=Math.pow(2,49),vd=Math.pow(2,56),Sd=Math.pow(2,63),Ad=function(r){return r<md?1:r<gd?2:r<yd?3:r<xd?4:r<bd?5:r<wd?6:r<Ed?7:r<vd?8:r<Sd?9:10},Bd={encode:ud,decode:hd,encodingLength:Ad},_d=Bd,Vr=_d;function zr(r,t=0){return[Vr.decode(r,t),Vr.decode.bytes]}function nr(r,t,e=0){return Vr.encode(r,t,e),t}function or(r){return Vr.encodingLength(r)}function De(r,t){let e=t.byteLength,n=or(r),o=n+or(e),i=new Uint8Array(o+e);return nr(r,i,0),nr(e,i,n),i.set(t,o),new ir(r,e,t,i)}function se(r){let t=oe(r),[e,n]=zr(t),[o,i]=zr(t.subarray(n)),s=t.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new ir(e,o,s,t)}function Mc(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&qs(r.bytes,e.bytes)}}var ir=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=n,this.bytes=o}};var Oc=0,Id="identity",Fc=oe;function Cd(r){return De(Oc,Fc(r))}var ce={code:Oc,name:Id,encode:Fc,digest:Cd};var Bi={};Tt(Bi,{sha256:()=>Hr,sha512:()=>Td});function Ai({name:r,code:t,encode:e}){return new Si(r,t,e)}var Si=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?De(this.code,e):e.then(n=>De(this.code,n))}else throw Error("Unknown type, must be binary type")}};function zc(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var Hr=Ai({name:"sha2-256",code:18,encode:zc("SHA-256")}),Td=Ai({name:"sha2-512",code:19,encode:zc("SHA-512")});function Hc(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return Ud(e,_i(r),t??tt.encoder);default:return Ld(e,_i(r),t??qt.encoder)}}var qc=new WeakMap;function _i(r){let t=qc.get(r);if(t==null){let e=new Map;return qc.set(r,e),e}return t}var at=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!==qr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==Nd)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=De(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&&Mc(t.multihash,n.multihash)}toString(t){return Hc(this,t)}toJSON(){return{"/":Hc(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??Kc(n,o,i.bytes))}else if(e[Rd]===!0){let{version:n,multihash:o,code:i}=e,s=se(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!==qr)throw new Error(`Version 0 CID must use dag-pb (code: ${qr}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=Kc(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,qr,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=oe(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 ir(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[f,h]=zr(t.subarray(e));return e+=h,f},o=n(),i=qr;if(o===18?(o=0,e=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let s=e,c=n(),a=n(),l=e+a,u=l-s;return{version:o,codec:i,multihashCode:c,digestSize:a,multihashSize:u,size:l}}static parse(t,e){let[n,o]=kd(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 _i(i).set(n,t),i}};function kd(r,t){switch(r[0]){case"Q":{let e=t??tt;return[tt.prefix,e.decode(`${tt.prefix}${r}`)]}case tt.prefix:{let e=t??tt;return[tt.prefix,e.decode(r)]}case qt.prefix:{let e=t??qt;return[qt.prefix,e.decode(r)]}case Fr.prefix:{let e=t??Fr;return[Fr.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 Ud(r,t,e){let{prefix:n}=e;if(n!==tt.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 Ld(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 qr=112,Nd=18;function Kc(r,t,e){let n=or(r),o=n+or(t),i=new Uint8Array(o+e.byteLength);return nr(r,i,0),nr(t,i,n),i.set(e,o),i}var Rd=Symbol.for("@ipld/js-cid/CID");var Kr={...wi,...gi,...bi,...pi,...mi,...Go,...xi,...jo,...Zo,...yi},gy={...Bi,...vi};function Gc(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var $c=Gc("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Ii=Gc("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=wt(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),Pd={utf8:$c,"utf-8":$c,hex:Kr.base16,latin1:Ii,ascii:Ii,binary:Ii,...Kr},Gn=Pd;function ae(r,t="utf8"){let e=Gn[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function Ci(r){let t=r??8192,e=t>>>1,n,o=t;return function(s){if(s<1||s>e)return wt(s);o+s>t&&(n=wt(t),o=0);let c=n.subarray(o,o+=s);return(o&7)!==0&&(o=(o|7)+1),c}}var Me=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function Ti(){}var Ui=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Dd=Ci();function Md(r){return globalThis.Buffer!=null?wt(r):Dd(r)}var Gr=class{len;head;tail;states;constructor(){this.len=0,this.head=new Me(Ti,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new Me(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Li((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(jn,10,Rt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=Rt.fromBigInt(t);return this._push(jn,e.length(),e)}uint64Number(t){return this._push(si,dt(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=Rt.fromBigInt(t).zzEncode();return this._push(jn,e.length(),e)}sint64Number(t){let e=Rt.fromNumber(t).zzEncode();return this._push(jn,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(ki,1,t?1:0)}fixed32(t){return this._push($r,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=Rt.fromBigInt(t);return this._push($r,4,e.lo)._push($r,4,e.hi)}fixed64Number(t){let e=Rt.fromNumber(t);return this._push($r,4,e.lo)._push($r,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(Bc,4,t)}double(t){return this._push(Ic,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(ki,1,0):this.uint32(e)._push(Fd,e,t)}string(t){let e=kc(t);return e!==0?this.uint32(e)._push(fi,e,t):this._push(ki,1,0)}fork(){return this.states=new Ui(this),this.head=this.tail=new Me(Ti,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 Me(Ti,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=Md(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function ki(r,t,e){t[e]=r&255}function Od(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var Li=class extends Me{next;constructor(t,e){super(Od,t,e),this.next=void 0}};function jn(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 $r(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 Fd(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(Gr.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(Vd,t,r),this},Gr.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(zd,t,r),this});function Vd(r,t,e){t.set(r,e)}function zd(r,t,e){r.length<40?fi(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(ae(r),e)}function Ni(){return new Gr}function Bt(r,t){let e=Ni();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var sr;(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"})(sr||(sr={}));function Zn(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function jr(r){function t(o){if(r[o.toString()]==null)throw new Error("Invalid enum value");return r[o]}let e=function(i,s){let c=t(i);s.int32(c)},n=function(i){let s=i.int32();return t(s)};return Zn("enum",sr.VARINT,e,n)}function _t(r,t){return Zn("message",sr.LENGTH_DELIMITED,r,t)}var ue=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var K;(function(r){r.invokeMethod="invokeMethod",r.methodResolved="methodResolved",r.methodRejected="methodRejected",r.invokeGeneratorMethod="invokeGeneratorMethod",r.abortMethodInvocation="abortMethodInvocation",r.invokeCallback="invokeCallback",r.callbackResolved="callbackResolved",r.callbackRejected="callbackRejected",r.abortCallbackInvocation="abortCallbackInvocation"})(K||(K={}));var Wn;(function(r){r[r.invokeMethod=0]="invokeMethod",r[r.methodResolved=1]="methodResolved",r[r.methodRejected=2]="methodRejected",r[r.invokeGeneratorMethod=3]="invokeGeneratorMethod",r[r.abortMethodInvocation=4]="abortMethodInvocation",r[r.invokeCallback=5]="invokeCallback",r[r.callbackResolved=6]="callbackResolved",r[r.callbackRejected=7]="callbackRejected",r[r.abortCallbackInvocation=8]="abortCallbackInvocation"})(Wn||(Wn={}));(function(r){r.codec=()=>jr(Wn)})(K||(K={}));var kt;(function(r){let t;r.codec=()=>(t==null&&(t=_t((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.type!=null&&e.type!==0&&(n.uint32(8),n.uint32(e.type)),e.value!=null&&(n.uint32(18),n.bytes(e.value)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let i={type:0},s=n==null?e.len:e.pos+n;for(;e.pos<s;){let c=e.uint32();switch(c>>>3){case 1:{i.type=e.uint32();break}case 2:{i.value=e.bytes();break}default:{e.skipType(c&7);break}}}return i})),t),r.encode=e=>Bt(e,r.codec()),r.decode=(e,n)=>At(e,r.codec(),n)})(kt||(kt={}));var It;(function(r){let t;r.codec=()=>(t==null&&(t=_t((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.type!=null&&Wn[e.type]!==0&&(n.uint32(8),K.codec().encode(e.type,n)),e.message!=null&&e.message.byteLength>0&&(n.uint32(18),n.bytes(e.message)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let i={type:K.invokeMethod,message:$t(0)},s=n==null?e.len:e.pos+n;for(;e.pos<s;){let c=e.uint32();switch(c>>>3){case 1:{i.type=K.codec().decode(e);break}case 2:{i.message=e.bytes();break}default:{e.skipType(c&7);break}}}return i})),t),r.encode=e=>Bt(e,r.codec()),r.decode=(e,n)=>At(e,r.codec(),n)})(It||(It={}));var Oe;(function(r){let t;r.codec=()=>(t==null&&(t=_t((e,n,o={})=>{if(o.lengthDelimited!==!1&&n.fork(),e.scope!=null&&e.scope!==""&&(n.uint32(10),n.string(e.scope)),e.path!=null&&e.path!==""&&(n.uint32(18),n.string(e.path)),e.args!=null)for(let i of e.args)n.uint32(26),kt.codec().encode(i,n);o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let i={scope:"",path:"",args:[]},s=n==null?e.len:e.pos+n;for(;e.pos<s;){let c=e.uint32();switch(c>>>3){case 1:{i.scope=e.string();break}case 2:{i.path=e.string();break}case 3:{if(o.limits?.args!=null&&i.args.length===o.limits.args)throw new ue('Decode error - map field "args" had too many elements');i.args.push(kt.codec().decode(e,e.uint32(),{limits:o.limits?.args$}));break}default:{e.skipType(c&7);break}}}return i})),t),r.encode=e=>Bt(e,r.codec()),r.decode=(e,n)=>At(e,r.codec(),n)})(Oe||(Oe={}));var Zr;(function(r){let t;r.codec=()=>(t==null&&(t=_t((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.scope!=null&&e.scope!==""&&(n.uint32(10),n.string(e.scope)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let i={scope:""},s=n==null?e.len:e.pos+n;for(;e.pos<s;){let c=e.uint32();switch(c>>>3){case 1:{i.scope=e.string();break}default:{e.skipType(c&7);break}}}return i})),t),r.encode=e=>Bt(e,r.codec()),r.decode=(e,n)=>At(e,r.codec(),n)})(Zr||(Zr={}));var cr;(function(r){let t;r.codec=()=>(t==null&&(t=_t((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.scope!=null&&e.scope!==""&&(n.uint32(10),n.string(e.scope)),e.value!=null&&(n.uint32(18),kt.codec().encode(e.value,n)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let i={scope:""},s=n==null?e.len:e.pos+n;for(;e.pos<s;){let c=e.uint32();switch(c>>>3){case 1:{i.scope=e.string();break}case 2:{i.value=kt.codec().decode(e,e.uint32(),{limits:o.limits?.value});break}default:{e.skipType(c&7);break}}}return i})),t),r.encode=e=>Bt(e,r.codec()),r.decode=(e,n)=>At(e,r.codec(),n)})(cr||(cr={}));var Wr;(function(r){let t;r.codec=()=>(t==null&&(t=_t((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.scope!=null&&e.scope!==""&&(n.uint32(10),n.string(e.scope)),e.error!=null&&(n.uint32(18),kt.codec().encode(e.error,n)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let i={scope:""},s=n==null?e.len:e.pos+n;for(;e.pos<s;){let c=e.uint32();switch(c>>>3){case 1:{i.scope=e.string();break}case 2:{i.error=kt.codec().decode(e,e.uint32(),{limits:o.limits?.error});break}default:{e.skipType(c&7);break}}}return i})),t),r.encode=e=>Bt(e,r.codec()),r.decode=(e,n)=>At(e,r.codec(),n)})(Wr||(Wr={}));var ar;(function(r){let t;r.codec=()=>(t==null&&(t=_t((e,n,o={})=>{if(o.lengthDelimited!==!1&&n.fork(),e.scope!=null&&e.scope!==""&&(n.uint32(10),n.string(e.scope)),e.parents!=null)for(let i of e.parents)n.uint32(18),n.string(i);if(e.callback!=null&&e.callback!==""&&(n.uint32(26),n.string(e.callback)),e.args!=null)for(let i of e.args)n.uint32(34),kt.codec().encode(i,n);o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let i={scope:"",parents:[],callback:"",args:[]},s=n==null?e.len:e.pos+n;for(;e.pos<s;){let c=e.uint32();switch(c>>>3){case 1:{i.scope=e.string();break}case 2:{if(o.limits?.parents!=null&&i.parents.length===o.limits.parents)throw new ue('Decode error - map field "parents" had too many elements');i.parents.push(e.string());break}case 3:{i.callback=e.string();break}case 4:{if(o.limits?.args!=null&&i.args.length===o.limits.args)throw new ue('Decode error - map field "args" had too many elements');i.args.push(kt.codec().decode(e,e.uint32(),{limits:o.limits?.args$}));break}default:{e.skipType(c&7);break}}}return i})),t),r.encode=e=>Bt(e,r.codec()),r.decode=(e,n)=>At(e,r.codec(),n)})(ar||(ar={}));var ur;(function(r){let t;r.codec=()=>(t==null&&(t=_t((e,n,o={})=>{if(o.lengthDelimited!==!1&&n.fork(),e.scope!=null&&e.scope!==""&&(n.uint32(10),n.string(e.scope)),e.parents!=null)for(let i of e.parents)n.uint32(18),n.string(i);o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let i={scope:"",parents:[]},s=n==null?e.len:e.pos+n;for(;e.pos<s;){let c=e.uint32();switch(c>>>3){case 1:{i.scope=e.string();break}case 2:{if(o.limits?.parents!=null&&i.parents.length===o.limits.parents)throw new ue('Decode error - map field "parents" had too many elements');i.parents.push(e.string());break}default:{e.skipType(c&7);break}}}return i})),t),r.encode=e=>Bt(e,r.codec()),r.decode=(e,n)=>At(e,r.codec(),n)})(ur||(ur={}));var Xr;(function(r){let t;r.codec=()=>(t==null&&(t=_t((e,n,o={})=>{if(o.lengthDelimited!==!1&&n.fork(),e.scope!=null&&e.scope!==""&&(n.uint32(10),n.string(e.scope)),e.parents!=null)for(let i of e.parents)n.uint32(18),n.string(i);e.value!=null&&(n.uint32(26),kt.codec().encode(e.value,n)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let i={scope:"",parents:[]},s=n==null?e.len:e.pos+n;for(;e.pos<s;){let c=e.uint32();switch(c>>>3){case 1:{i.scope=e.string();break}case 2:{if(o.limits?.parents!=null&&i.parents.length===o.limits.parents)throw new ue('Decode error - map field "parents" had too many elements');i.parents.push(e.string());break}case 3:{i.value=kt.codec().decode(e,e.uint32(),{limits:o.limits?.value});break}default:{e.skipType(c&7);break}}}return i})),t),r.encode=e=>Bt(e,r.codec()),r.decode=(e,n)=>At(e,r.codec(),n)})(Xr||(Xr={}));var Yr;(function(r){let t;r.codec=()=>(t==null&&(t=_t((e,n,o={})=>{if(o.lengthDelimited!==!1&&n.fork(),e.scope!=null&&e.scope!==""&&(n.uint32(10),n.string(e.scope)),e.parents!=null)for(let i of e.parents)n.uint32(18),n.string(i);e.error!=null&&(n.uint32(26),kt.codec().encode(e.error,n)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let i={scope:"",parents:[]},s=n==null?e.len:e.pos+n;for(;e.pos<s;){let c=e.uint32();switch(c>>>3){case 1:{i.scope=e.string();break}case 2:{if(o.limits?.parents!=null&&i.parents.length===o.limits.parents)throw new ue('Decode error - map field "parents" had too many elements');i.parents.push(e.string());break}case 3:{i.error=kt.codec().decode(e,e.uint32(),{limits:o.limits?.error});break}default:{e.skipType(c&7);break}}}return i})),t),r.encode=e=>Bt(e,r.codec()),r.decode=(e,n)=>At(e,r.codec(),n)})(Yr||(Yr={}));function Hd(r){return r.parents!=null}function jc(r,t){if(Hd(r))return qd(r.parents,t);let e=t.get(r.scope);if(e==null)throw new Hn;return e}function qd(r,t){let e;for(let n of r){if(e==null){if(e=t.get(n),e==null)throw new rr;continue}if(e=e.children.get(n),e==null)throw new rr}if(e==null)throw new rr;return e}var Kd={type:1024,canEncode:r=>r===void 0,decode:()=>{}},Zc=Kd;var $d={type:1025,canEncode:r=>r===null,decode:()=>null},Wc=$d;var Gd=["string","number","bigint","symbol"],jd=["Function","Generator","AsyncGenerator","GeneratorFunction","AsyncGeneratorFunction","AsyncFunction","Observable","Array","Buffer","Object","RegExp","Date","Error","Map","Set","WeakMap","WeakSet","ArrayBuffer","SharedArrayBuffer","DataView","Promise","URL","HTMLElement","Int8Array","Uint8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array"];function Xc(r){if(r===null)return"null";if(r===void 0)return"undefined";if(r===!0||r===!1)return"boolean";let t=typeof r;if(Gd.includes(t))return t;if(t==="function")return"Function";if(Array.isArray(r))return"Array";if(Zd(r))return"Buffer";let e=Wd(r);return e||"Object"}function Zd(r){return r&&r.constructor&&r.constructor.isBuffer&&r.constructor.isBuffer.call(null,r)}function Wd(r){let t=Object.prototype.toString.call(r).slice(8,-1);if(jd.includes(t))return t}var p=class{constructor(t,e,n){this.major=t,this.majorEncoded=t<<5,this.name=e,this.terminal=n}toString(){return`Type[${this.major}].${this.name}`}compare(t){return this.major<t.major?-1:this.major>t.major?1:0}};p.uint=new p(0,"uint",!0);p.negint=new p(1,"negint",!0);p.bytes=new p(2,"bytes",!0);p.string=new p(3,"string",!0);p.array=new p(4,"array",!1);p.map=new p(5,"map",!1);p.tag=new p(6,"tag",!1);p.float=new p(7,"float",!0);p.false=new p(7,"false",!0);p.true=new p(7,"true",!0);p.null=new p(7,"null",!0);p.undefined=new p(7,"undefined",!0);p.break=new p(7,"break",!0);var I=class{constructor(t,e,n){this.type=t,this.value=e,this.encodedLength=n,this.encodedBytes=void 0,this.byteValue=void 0}toString(){return`Token[${this.type}].${this.value}`}};var lr=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",Xd=new TextDecoder,Yd=new TextEncoder;function Xn(r){return lr&&globalThis.Buffer.isBuffer(r)}function Ri(r){return r instanceof Uint8Array?Xn(r)?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):r:Uint8Array.from(r)}var ta=lr?(r,t,e)=>e-t>64?globalThis.Buffer.from(r.subarray(t,e)).toString("utf8"):Qc(r,t,e):(r,t,e)=>e-t>64?Xd.decode(r.subarray(t,e)):Qc(r,t,e),ea=lr?r=>r.length>64?globalThis.Buffer.from(r):Yc(r):r=>r.length>64?Yd.encode(r):Yc(r),ee=r=>Uint8Array.from(r),fr=lr?(r,t,e)=>Xn(r)?new Uint8Array(r.subarray(t,e)):r.slice(t,e):(r,t,e)=>r.slice(t,e),ra=lr?(r,t)=>(r=r.map(e=>e instanceof Uint8Array?e:globalThis.Buffer.from(e)),Ri(globalThis.Buffer.concat(r,t))):(r,t)=>{let e=new Uint8Array(t),n=0;for(let o of r)n+o.length>e.length&&(o=o.subarray(0,e.length-n)),e.set(o,n),n+=o.length;return e},na=lr?r=>globalThis.Buffer.allocUnsafe(r):r=>new Uint8Array(r);function oa(r,t){if(Xn(r)&&Xn(t))return r.compare(t);for(let e=0;e<r.length;e++)if(r[e]!==t[e])return r[e]<t[e]?-1:1;return 0}function Yc(r){let t=[],e=0;for(let n=0;n<r.length;n++){let o=r.charCodeAt(n);o<128?t[e++]=o:o<2048?(t[e++]=o>>6|192,t[e++]=o&63|128):(o&64512)===55296&&n+1<r.length&&(r.charCodeAt(n+1)&64512)===56320?(o=65536+((o&1023)<<10)+(r.charCodeAt(++n)&1023),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 t}function Qc(r,t,e){let n=[];for(;t<e;){let o=r[t],i=null,s=o>239?4:o>223?3:o>191?2:1;if(t+s<=e){let c,a,l,u;switch(s){case 1:o<128&&(i=o);break;case 2:c=r[t+1],(c&192)===128&&(u=(o&31)<<6|c&63,u>127&&(i=u));break;case 3:c=r[t+1],a=r[t+2],(c&192)===128&&(a&192)===128&&(u=(o&15)<<12|(c&63)<<6|a&63,u>2047&&(u<55296||u>57343)&&(i=u));break;case 4:c=r[t+1],a=r[t+2],l=r[t+3],(c&192)===128&&(a&192)===128&&(l&192)===128&&(u=(o&15)<<18|(c&63)<<12|(a&63)<<6|l&63,u>65535&&u<1114112&&(i=u))}}i===null?(i=65533,s=1):i>65535&&(i-=65536,n.push(i>>>10&1023|55296),i=56320|i&1023),n.push(i),t+=s}return Qd(n)}var Jc=4096;function Qd(r){let t=r.length;if(t<=Jc)return String.fromCharCode.apply(String,r);let e="",n=0;for(;n<t;)e+=String.fromCharCode.apply(String,r.slice(n,n+=Jc));return e}var Jd=256,Qr=class{constructor(t=Jd){this.chunkSize=t,this.cursor=0,this.maxCursor=-1,this.chunks=[],this._initReuseChunk=null}reset(){this.cursor=0,this.maxCursor=-1,this.chunks.length&&(this.chunks=[]),this._initReuseChunk!==null&&(this.chunks.push(this._initReuseChunk),this.maxCursor=this._initReuseChunk.length-1)}push(t){let e=this.chunks[this.chunks.length-1];if(this.cursor+t.length<=this.maxCursor+1){let o=e.length-(this.maxCursor-this.cursor)-1;e.set(t,o)}else{if(e){let o=e.length-(this.maxCursor-this.cursor)-1;o<e.length&&(this.chunks[this.chunks.length-1]=e.subarray(0,o),this.maxCursor=this.cursor-1)}t.length<64&&t.length<this.chunkSize?(e=na(this.chunkSize),this.chunks.push(e),this.maxCursor+=e.length,this._initReuseChunk===null&&(this._initReuseChunk=e),e.set(t,0)):(this.chunks.push(t),this.maxCursor+=t.length)}this.cursor+=t.length}toBytes(t=!1){let e;if(this.chunks.length===1){let n=this.chunks[0];t&&this.cursor>n.length/2?(e=this.cursor===n.length?n:n.subarray(0,this.cursor),this._initReuseChunk=null,this.chunks=[]):e=fr(n,0,this.cursor)}else e=ra(this.chunks,this.cursor);return t&&this.reset(),e}};var M="CBOR decode error:",Pi="CBOR encode error:",Jr=[];Jr[23]=1;Jr[24]=2;Jr[25]=3;Jr[26]=5;Jr[27]=9;function le(r,t,e){if(r.length-t<e)throw new Error(`${M} not enough data for type`)}var ht=[24,256,65536,4294967296,BigInt("18446744073709551616")];function Pt(r,t,e){le(r,t,1);let n=r[t];if(e.strict===!0&&n<ht[0])throw new Error(`${M} integer encoded in more bytes than necessary (strict decode)`);return n}function Dt(r,t,e){le(r,t,2);let n=r[t]<<8|r[t+1];if(e.strict===!0&&n<ht[1])throw new Error(`${M} integer encoded in more bytes than necessary (strict decode)`);return n}function Mt(r,t,e){le(r,t,4);let n=r[t]*16777216+(r[t+1]<<16)+(r[t+2]<<8)+r[t+3];if(e.strict===!0&&n<ht[2])throw new Error(`${M} integer encoded in more bytes than necessary (strict decode)`);return n}function Ot(r,t,e){le(r,t,8);let n=r[t]*16777216+(r[t+1]<<16)+(r[t+2]<<8)+r[t+3],o=r[t+4]*16777216+(r[t+5]<<16)+(r[t+6]<<8)+r[t+7],i=(BigInt(n)<<BigInt(32))+BigInt(o);if(e.strict===!0&&i<ht[3])throw new Error(`${M} integer encoded in more bytes than necessary (strict decode)`);if(i<=Number.MAX_SAFE_INTEGER)return Number(i);if(e.allowBigInt===!0)return i;throw new Error(`${M} integers outside of the safe integer range are not supported`)}function ia(r,t,e,n){return new I(p.uint,Pt(r,t+1,n),2)}function sa(r,t,e,n){return new I(p.uint,Dt(r,t+1,n),3)}function ca(r,t,e,n){return new I(p.uint,Mt(r,t+1,n),5)}function aa(r,t,e,n){return new I(p.uint,Ot(r,t+1,n),9)}function Vt(r,t){return gt(r,0,t.value)}function gt(r,t,e){if(e<ht[0]){let n=Number(e);r.push([t|n])}else if(e<ht[1]){let n=Number(e);r.push([t|24,n])}else if(e<ht[2]){let n=Number(e);r.push([t|25,n>>>8,n&255])}else if(e<ht[3]){let n=Number(e);r.push([t|26,n>>>24&255,n>>>16&255,n>>>8&255,n&255])}else{let n=BigInt(e);if(n<ht[4]){let o=[t|27,0,0,0,0,0,0,0],i=Number(n&BigInt(4294967295)),s=Number(n>>BigInt(32)&BigInt(4294967295));o[8]=i&255,i=i>>8,o[7]=i&255,i=i>>8,o[6]=i&255,i=i>>8,o[5]=i&255,o[4]=s&255,s=s>>8,o[3]=s&255,s=s>>8,o[2]=s&255,s=s>>8,o[1]=s&255,r.push(o)}else throw new Error(`${M} encountered BigInt larger than allowable range`)}}Vt.encodedSize=function(t){return gt.encodedSize(t.value)};gt.encodedSize=function(t){return t<ht[0]?1:t<ht[1]?2:t<ht[2]?3:t<ht[3]?5:9};Vt.compareTokens=function(t,e){return t.value<e.value?-1:t.value>e.value?1:0};function ua(r,t,e,n){return new I(p.negint,-1-Pt(r,t+1,n),2)}function la(r,t,e,n){return new I(p.negint,-1-Dt(r,t+1,n),3)}function fa(r,t,e,n){return new I(p.negint,-1-Mt(r,t+1,n),5)}var Di=BigInt(-1),da=BigInt(1);function ha(r,t,e,n){let o=Ot(r,t+1,n);if(typeof o!="bigint"){let i=-1-o;if(i>=Number.MIN_SAFE_INTEGER)return new I(p.negint,i,9)}if(n.allowBigInt!==!0)throw new Error(`${M} integers outside of the safe integer range are not supported`);return new I(p.negint,Di-BigInt(o),9)}function Yn(r,t){let e=t.value,n=typeof e=="bigint"?e*Di-da:e*-1-1;gt(r,t.type.majorEncoded,n)}Yn.encodedSize=function(t){let e=t.value,n=typeof e=="bigint"?e*Di-da:e*-1-1;return n<ht[0]?1:n<ht[1]?2:n<ht[2]?3:n<ht[3]?5:9};Yn.compareTokens=function(t,e){return t.value<e.value?1:t.value>e.value?-1:0};function tn(r,t,e,n){le(r,t,e+n);let o=fr(r,t+e,t+e+n);return new I(p.bytes,o,e+n)}function pa(r,t,e,n){return tn(r,t,1,e)}function ma(r,t,e,n){return tn(r,t,2,Pt(r,t+1,n))}function ga(r,t,e,n){return tn(r,t,3,Dt(r,t+1,n))}function ya(r,t,e,n){return tn(r,t,5,Mt(r,t+1,n))}function xa(r,t,e,n){let o=Ot(r,t+1,n);if(typeof o=="bigint")throw new Error(`${M} 64-bit integer bytes lengths not supported`);return tn(r,t,9,o)}function Qn(r){return r.encodedBytes===void 0&&(r.encodedBytes=r.type===p.string?ea(r.value):r.value),r.encodedBytes}function dr(r,t){let e=Qn(t);gt(r,t.type.majorEncoded,e.length),r.push(e)}dr.encodedSize=function(t){let e=Qn(t);return gt.encodedSize(e.length)+e.length};dr.compareTokens=function(t,e){return eh(Qn(t),Qn(e))};function eh(r,t){return r.length<t.length?-1:r.length>t.length?1:oa(r,t)}function en(r,t,e,n,o){let i=e+n;le(r,t,i);let s=new I(p.string,ta(r,t+e,t+i),i);return o.retainStringBytes===!0&&(s.byteValue=fr(r,t+e,t+i)),s}function ba(r,t,e,n){return en(r,t,1,e,n)}function wa(r,t,e,n){return en(r,t,2,Pt(r,t+1,n),n)}function Ea(r,t,e,n){return en(r,t,3,Dt(r,t+1,n),n)}function va(r,t,e,n){return en(r,t,5,Mt(r,t+1,n),n)}function Sa(r,t,e,n){let o=Ot(r,t+1,n);if(typeof o=="bigint")throw new Error(`${M} 64-bit integer string lengths not supported`);return en(r,t,9,o,n)}var Aa=dr;function hr(r,t,e,n){return new I(p.array,n,e)}function Ba(r,t,e,n){return hr(r,t,1,e)}function _a(r,t,e,n){return hr(r,t,2,Pt(r,t+1,n))}function Ia(r,t,e,n){return hr(r,t,3,Dt(r,t+1,n))}function Ca(r,t,e,n){return hr(r,t,5,Mt(r,t+1,n))}function Ta(r,t,e,n){let o=Ot(r,t+1,n);if(typeof o=="bigint")throw new Error(`${M} 64-bit integer array lengths not supported`);return hr(r,t,9,o)}function ka(r,t,e,n){if(n.allowIndefinite===!1)throw new Error(`${M} indefinite length items not allowed`);return hr(r,t,1,1/0)}function Jn(r,t){gt(r,p.array.majorEncoded,t.value)}Jn.compareTokens=Vt.compareTokens;Jn.encodedSize=function(t){return gt.encodedSize(t.value)};function pr(r,t,e,n){return new I(p.map,n,e)}function Ua(r,t,e,n){return pr(r,t,1,e)}function La(r,t,e,n){return pr(r,t,2,Pt(r,t+1,n))}function Na(r,t,e,n){return pr(r,t,3,Dt(r,t+1,n))}function Ra(r,t,e,n){return pr(r,t,5,Mt(r,t+1,n))}function Pa(r,t,e,n){let o=Ot(r,t+1,n);if(typeof o=="bigint")throw new Error(`${M} 64-bit integer map lengths not supported`);return pr(r,t,9,o)}function Da(r,t,e,n){if(n.allowIndefinite===!1)throw new Error(`${M} indefinite length items not allowed`);return pr(r,t,1,1/0)}function to(r,t){gt(r,p.map.majorEncoded,t.value)}to.compareTokens=Vt.compareTokens;to.encodedSize=function(t){return gt.encodedSize(t.value)};function Ma(r,t,e,n){return new I(p.tag,e,1)}function Oa(r,t,e,n){return new I(p.tag,Pt(r,t+1,n),2)}function Fa(r,t,e,n){return new I(p.tag,Dt(r,t+1,n),3)}function Va(r,t,e,n){return new I(p.tag,Mt(r,t+1,n),5)}function za(r,t,e,n){return new I(p.tag,Ot(r,t+1,n),9)}function eo(r,t){gt(r,p.tag.majorEncoded,t.value)}eo.compareTokens=Vt.compareTokens;eo.encodedSize=function(t){return gt.encodedSize(t.value)};var ch=20,ah=21,uh=22,lh=23;function Ha(r,t,e,n){if(n.allowUndefined===!1)throw new Error(`${M} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new I(p.null,null,1):new I(p.undefined,void 0,1)}function qa(r,t,e,n){if(n.allowIndefinite===!1)throw new Error(`${M} indefinite length items not allowed`);return new I(p.break,void 0,1)}function Mi(r,t,e){if(e){if(e.allowNaN===!1&&Number.isNaN(r))throw new Error(`${M} NaN values are not supported`);if(e.allowInfinity===!1&&(r===1/0||r===-1/0))throw new Error(`${M} Infinity values are not supported`)}return new I(p.float,r,t)}function Ka(r,t,e,n){return Mi(Oi(r,t+1),3,n)}function $a(r,t,e,n){return Mi(Fi(r,t+1),5,n)}function Ga(r,t,e,n){return Mi(Xa(r,t+1),9,n)}function ro(r,t,e){let n=t.value;if(n===!1)r.push([p.float.majorEncoded|ch]);else if(n===!0)r.push([p.float.majorEncoded|ah]);else if(n===null)r.push([p.float.majorEncoded|uh]);else if(n===void 0)r.push([p.float.majorEncoded|lh]);else{let o,i=!1;(!e||e.float64!==!0)&&(Za(n),o=Oi(Zt,1),n===o||Number.isNaN(n)?(Zt[0]=249,r.push(Zt.slice(0,3)),i=!0):(Wa(n),o=Fi(Zt,1),n===o&&(Zt[0]=250,r.push(Zt.slice(0,5)),i=!0))),i||(fh(n),o=Xa(Zt,1),Zt[0]=251,r.push(Zt.slice(0,9)))}}ro.encodedSize=function(t,e){let n=t.value;if(n===!1||n===!0||n===null||n===void 0)return 1;if(!e||e.float64!==!0){Za(n);let o=Oi(Zt,1);if(n===o||Number.isNaN(n))return 3;if(Wa(n),o=Fi(Zt,1),n===o)return 5}return 9};var ja=new ArrayBuffer(9),zt=new DataView(ja,1),Zt=new Uint8Array(ja,0);function Za(r){if(r===1/0)zt.setUint16(0,31744,!1);else if(r===-1/0)zt.setUint16(0,64512,!1);else if(Number.isNaN(r))zt.setUint16(0,32256,!1);else{zt.setFloat32(0,r);let t=zt.getUint32(0),e=(t&2139095040)>>23,n=t&8388607;if(e===255)zt.setUint16(0,31744,!1);else if(e===0)zt.setUint16(0,(r&2147483648)>>16|n>>13,!1);else{let o=e-127;o<-24?zt.setUint16(0,0):o<-14?zt.setUint16(0,(t&2147483648)>>16|1<<24+o,!1):zt.setUint16(0,(t&2147483648)>>16|o+15<<10|n>>13,!1)}}}function Oi(r,t){if(r.length-t<2)throw new Error(`${M} not enough data for float16`);let e=(r[t]<<8)+r[t+1];if(e===31744)return 1/0;if(e===64512)return-1/0;if(e===32256)return NaN;let n=e>>10&31,o=e&1023,i;return n===0?i=o*2**-24:n!==31?i=(o+1024)*2**(n-25):i=o===0?1/0:NaN,e&32768?-i:i}function Wa(r){zt.setFloat32(0,r,!1)}function Fi(r,t){if(r.length-t<4)throw new Error(`${M} not enough data for float32`);let e=(r.byteOffset||0)+t;return new DataView(r.buffer,e,4).getFloat32(0,!1)}function fh(r){zt.setFloat64(0,r,!1)}function Xa(r,t){if(r.length-t<8)throw new Error(`${M} not enough data for float64`);let e=(r.byteOffset||0)+t;return new DataView(r.buffer,e,8).getFloat64(0,!1)}ro.compareTokens=Vt.compareTokens;function $(r,t,e){throw new Error(`${M} encountered invalid minor (${e}) for major ${r[t]>>>5}`)}function no(r){return()=>{throw new Error(`${M} ${r}`)}}var S=[];for(let r=0;r<=23;r++)S[r]=$;S[24]=ia;S[25]=sa;S[26]=ca;S[27]=aa;S[28]=$;S[29]=$;S[30]=$;S[31]=$;for(let r=32;r<=55;r++)S[r]=$;S[56]=ua;S[57]=la;S[58]=fa;S[59]=ha;S[60]=$;S[61]=$;S[62]=$;S[63]=$;for(let r=64;r<=87;r++)S[r]=pa;S[88]=ma;S[89]=ga;S[90]=ya;S[91]=xa;S[92]=$;S[93]=$;S[94]=$;S[95]=no("indefinite length bytes/strings are not supported");for(let r=96;r<=119;r++)S[r]=ba;S[120]=wa;S[121]=Ea;S[122]=va;S[123]=Sa;S[124]=$;S[125]=$;S[126]=$;S[127]=no("indefinite length bytes/strings are not supported");for(let r=128;r<=151;r++)S[r]=Ba;S[152]=_a;S[153]=Ia;S[154]=Ca;S[155]=Ta;S[156]=$;S[157]=$;S[158]=$;S[159]=ka;for(let r=160;r<=183;r++)S[r]=Ua;S[184]=La;S[185]=Na;S[186]=Ra;S[187]=Pa;S[188]=$;S[189]=$;S[190]=$;S[191]=Da;for(let r=192;r<=215;r++)S[r]=Ma;S[216]=Oa;S[217]=Fa;S[218]=Va;S[219]=za;S[220]=$;S[221]=$;S[222]=$;S[223]=$;for(let r=224;r<=243;r++)S[r]=no("simple values are not supported");S[244]=$;S[245]=$;S[246]=$;S[247]=Ha;S[248]=no("simple values are not supported");S[249]=Ka;S[250]=$a;S[251]=Ga;S[252]=$;S[253]=$;S[254]=$;S[255]=qa;var Wt=[];for(let r=0;r<24;r++)Wt[r]=new I(p.uint,r,1);for(let r=-1;r>=-24;r--)Wt[31-r]=new I(p.negint,r,1);Wt[64]=new I(p.bytes,new Uint8Array(0),1);Wt[96]=new I(p.string,"",1);Wt[128]=new I(p.array,0,1);Wt[160]=new I(p.map,0,1);Wt[244]=new I(p.false,!1,1);Wt[245]=new I(p.true,!0,1);Wt[246]=new I(p.null,null,1);function Ya(r){switch(r.type){case p.false:return ee([244]);case p.true:return ee([245]);case p.null:return ee([246]);case p.bytes:return r.value.length?void 0:ee([64]);case p.string:return r.value===""?ee([96]):void 0;case p.array:return r.value===0?ee([128]):void 0;case p.map:return r.value===0?ee([160]):void 0;case p.uint:return r.value<24?ee([Number(r.value)]):void 0;case p.negint:if(r.value>=-24)return ee([31-Number(r.value)])}}var hh={float64:!1,mapSorter:gh,quickEncodeToken:Ya};function ph(){let r=[];return r[p.uint.major]=Vt,r[p.negint.major]=Yn,r[p.bytes.major]=dr,r[p.string.major]=Aa,r[p.array.major]=Jn,r[p.map.major]=to,r[p.tag.major]=eo,r[p.float.major]=ro,r}var Qa=ph(),Vi=new Qr,io=class r{constructor(t,e){this.obj=t,this.parent=e}includes(t){let e=this;do if(e.obj===t)return!0;while(e=e.parent);return!1}static createCheck(t,e){if(t&&t.includes(e))throw new Error(`${Pi} object contains circular references`);return new r(e,t)}},Ae={null:new I(p.null,null),undefined:new I(p.undefined,void 0),true:new I(p.true,!0),false:new I(p.false,!1),emptyArray:new I(p.array,0),emptyMap:new I(p.map,0)},Be={number(r,t,e,n){return!Number.isInteger(r)||!Number.isSafeInteger(r)?new I(p.float,r):r>=0?new I(p.uint,r):new I(p.negint,r)},bigint(r,t,e,n){return r>=BigInt(0)?new I(p.uint,r):new I(p.negint,r)},Uint8Array(r,t,e,n){return new I(p.bytes,r)},string(r,t,e,n){return new I(p.string,r)},boolean(r,t,e,n){return r?Ae.true:Ae.false},null(r,t,e,n){return Ae.null},undefined(r,t,e,n){return Ae.undefined},ArrayBuffer(r,t,e,n){return new I(p.bytes,new Uint8Array(r))},DataView(r,t,e,n){return new I(p.bytes,new Uint8Array(r.buffer,r.byteOffset,r.byteLength))},Array(r,t,e,n){if(!r.length)return e.addBreakTokens===!0?[Ae.emptyArray,new I(p.break)]:Ae.emptyArray;n=io.createCheck(n,r);let o=[],i=0;for(let s of r)o[i++]=oo(s,e,n);return e.addBreakTokens?[new I(p.array,r.length),o,new I(p.break)]:[new I(p.array,r.length),o]},Object(r,t,e,n){let o=t!=="Object",i=o?r.keys():Object.keys(r),s=o?r.size:i.length;if(!s)return e.addBreakTokens===!0?[Ae.emptyMap,new I(p.break)]:Ae.emptyMap;n=io.createCheck(n,r);let c=[],a=0;for(let l of i)c[a++]=[oo(l,e,n),oo(o?r.get(l):r[l],e,n)];return mh(c,e),e.addBreakTokens?[new I(p.map,s),c,new I(p.break)]:[new I(p.map,s),c]}};Be.Map=Be.Object;Be.Buffer=Be.Uint8Array;for(let r of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))Be[`${r}Array`]=Be.DataView;function oo(r,t={},e){let n=Xc(r),o=t&&t.typeEncoders&&t.typeEncoders[n]||Be[n];if(typeof o=="function"){let s=o(r,n,t,e);if(s!=null)return s}let i=Be[n];if(!i)throw new Error(`${Pi} unsupported type: ${n}`);return i(r,n,t,e)}function mh(r,t){t.mapSorter&&r.sort(t.mapSorter)}function gh(r,t){let e=Array.isArray(r[0])?r[0][0]:r[0],n=Array.isArray(t[0])?t[0][0]:t[0];if(e.type!==n.type)return e.type.compare(n.type);let o=e.type.major,i=Qa[o].compareTokens(e,n);return i===0&&console.warn("WARNING: complex key types used, CBOR key sorting guarantees are gone"),i}function Ja(r,t,e,n){if(Array.isArray(t))for(let o of t)Ja(r,o,e,n);else e[t.type.major](r,t,n)}function yh(r,t,e){let n=oo(r,e);if(!Array.isArray(n)&&e.quickEncodeToken){let o=e.quickEncodeToken(n);if(o)return o;let i=t[n.type.major];if(i.encodedSize){let s=i.encodedSize(n,e),c=new Qr(s);if(i(c,n,e),c.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${n} was wrong`);return Ri(c.chunks[0])}}return Vi.reset(),Ja(Vi,n,t,e),Vi.toBytes(!0)}function W(r,t){return t=Object.assign({},hh,t),yh(r,Qa,t)}var xh={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},so=class{constructor(t,e={}){this._pos=0,this.data=t,this.options=e}pos(){return this._pos}done(){return this._pos>=this.data.length}next(){let t=this.data[this._pos],e=Wt[t];if(e===void 0){let n=S[t];if(!n)throw new Error(`${M} no decoder for major type ${t>>>5} (byte 0x${t.toString(16).padStart(2,"0")})`);let o=t&31;e=n(this.data,this._pos,o,this.options)}return this._pos+=e.encodedLength,e}},rn=Symbol.for("DONE"),co=Symbol.for("BREAK");function bh(r,t,e){let n=[];for(let o=0;o<r.value;o++){let i=mr(t,e);if(i===co){if(r.value===1/0)break;throw new Error(`${M} got unexpected break to lengthed array`)}if(i===rn)throw new Error(`${M} found array but not enough entries (got ${o}, expected ${r.value})`);n[o]=i}return n}function wh(r,t,e){let n=e.useMaps===!0,o=n?void 0:{},i=n?new Map:void 0;for(let s=0;s<r.value;s++){let c=mr(t,e);if(c===co){if(r.value===1/0)break;throw new Error(`${M} got unexpected break to lengthed map`)}if(c===rn)throw new Error(`${M} found map but not enough entries (got ${s} [no key], expected ${r.value})`);if(n!==!0&&typeof c!="string")throw new Error(`${M} non-string keys not supported (got ${typeof c})`);if(e.rejectDuplicateMapKeys===!0&&(n&&i.has(c)||!n&&c in o))throw new Error(`${M} found repeat map key "${c}"`);let a=mr(t,e);if(a===rn)throw new Error(`${M} found map but not enough entries (got ${s} [no value], expected ${r.value})`);n?i.set(c,a):o[c]=a}return n?i:o}function mr(r,t){if(r.done())return rn;let e=r.next();if(e.type===p.break)return co;if(e.type.terminal)return e.value;if(e.type===p.array)return bh(e,r,t);if(e.type===p.map)return wh(e,r,t);if(e.type===p.tag){if(t.tags&&typeof t.tags[e.value]=="function"){let n=mr(r,t);return t.tags[e.value](n)}throw new Error(`${M} tag not supported (${e.value})`)}throw new Error("unsupported")}function tu(r,t){if(!(r instanceof Uint8Array))throw new Error(`${M} data to decode must be a Uint8Array`);t=Object.assign({},xh,t);let e=t.tokenizer||new so(r,t),n=mr(e,t);if(n===rn)throw new Error(`${M} did not find any content to decode`);if(n===co)throw new Error(`${M} got unexpected break`);return[n,r.subarray(e.pos())]}function X(r,t){let[e,n]=tu(r,t);if(n.length>0)throw new Error(`${M} too many terminals, data makes no sense`);return e}var Eh={type:1026,canEncode:r=>r===!0||r===!1,encode:r=>W(r),decode:r=>X(r)},eu=Eh;var vh={type:1027,canEncode:r=>typeof r=="number"&&!isNaN(r),encode:r=>W(r),decode:r=>X(r)},ru=vh;var Sh={type:1028,canEncode:r=>typeof r=="string",encode:r=>W(r),decode:r=>X(r)},nu=Sh;var Ah={type:1029,canEncode:r=>Array.isArray(r),encode:(r,t,e,n)=>W(r.map(o=>t.toValue(o,e,n))),decode:(r,t,e,n)=>X(r).map(o=>t.fromValue(o,e,n))},ou=Ah;var Bh={type:1030,canEncode:r=>typeof r=="function",encode:(r,t,e,n)=>{let o=er();return n?.callbacks.set(o,{context:e,fn:r}),W(o)},decode:(r,t,e,n)=>async(...o)=>new Promise((i,s)=>{let c=X(r),a=er(),l={scope:a,result:bt(),callbacks:new Map,children:new Map,parents:[...n.parents,n.scope],abortControllers:[],abortSignals:[]};n.children.set(a,l),o=o.map(f=>t.toValue(f,null,l));let u=Tn(l.abortSignals);u.addEventListener("abort",()=>{e.push(It.encode({type:K.abortCallbackInvocation,message:ur.encode({scope:a,parents:l.parents})}))}),e.push(It.encode({type:K.invokeCallback,message:ar.encode({scope:a,parents:l.parents,callback:c,args:o})})),l.result.promise.then(f=>{i(f)},f=>{s(f)}).finally(()=>{n.children.delete(a),u.clear()})})},iu=Bh;var _h={type:1031,canEncode:r=>r.toString()==="NaN"&&isNaN(r),decode:()=>NaN},su=_h;var Ih={type:1032,canEncode:r=>r instanceof Error,encode:r=>W({message:r.message,name:r.name,code:r.code,type:r.type,stack:r.stack}),decode:r=>{let t=X(r),e=new Error(t.message);return e.name=t.name,e.stack=t.stack,e.code=t.code,e.type=t.type,e}},cu=Ih;var Ch={type:1033,canEncode:r=>Array.isArray(r),encode:(r,t,e,n)=>{throw new Error("Promises are not supported")},decode:(r,t,e,n)=>{throw new Error("Promises are not supported")}},au=Ch;var uu=["__defineGetter__","__defineSetter__","hasOwnProperty","__lookupGetter__","__lookupSetter__","isPrototypeOf","propertyIsEnumerable","toString","valueOf","__proto__","toLocaleString","constructor"],Th={type:2147483647,canEncode:r=>typeof r=="object",encode:(r,t,e,n)=>{let o={};for(let i in r)uu.includes(i)||Object.hasOwn(r,i)&&(o[i]=r[i]);for(let i of Object.getOwnPropertyNames(Object.getPrototypeOf(r)))uu.includes(i)||(o[i]=r[i]);return W([...Object.entries(o)].map(([i,s])=>[t.toValue(i,r,n),t.toValue(s,r,n)]))},decode:(r,t,e,n)=>{let o={};return X(r).forEach(([s,c])=>{o[t.fromValue(s,e,n)]=t.fromValue(c,e,n)}),o}},nn=Th;var kh={type:1034,canEncode:r=>typeof r.next=="function"&&typeof r.throw=="function"&&typeof r.return=="function",encode:(r,t,e,n)=>nn.encode({next:r.next.bind(r),throw:r.throw.bind(r),return:r.return.bind(r)},t,e,n),decode:(r,t,e,n)=>{let o=nn.decode(r,t,e,n);return o[Symbol.asyncIterator]=()=>o,o}},lu=kh;var Uh={type:1035,canEncode:r=>typeof r=="bigint",encode:r=>W(r),decode:r=>BigInt(X(r))},fu=Uh;var Lh={type:1036,canEncode:r=>r instanceof Map,encode:(r,t,e,n)=>W([...r.entries()].map(([o,i])=>[t.toValue(o,e,n),t.toValue(i,e,n)])),decode:(r,t,e,n)=>{let o=new Map;return X(r).forEach(([s,c])=>{let a=t.fromValue(s,e,n),l=t.fromValue(c,e,n);o.set(a,l)}),o}},du=Lh;var Nh={type:1037,canEncode:r=>r instanceof Set,encode:(r,t,e,n)=>W([...r.values()].map(o=>t.toValue(o,e,n))),decode:(r,t,e,n)=>{let o=new Set;return X(r).forEach(s=>{o.add(t.fromValue(s,e,n))}),o}},hu=Nh;var Rh={type:1038,canEncode:r=>r instanceof Uint8Array,encode:r=>r,decode:r=>r},pu=Rh;var Ph={type:1039,canEncode:r=>r instanceof AbortSignal,encode:(r,t,e,n)=>(n?.abortSignals.push(r),new Uint8Array(0)),decode:(r,t,e,n)=>{let o=new AbortController;return n.abortControllers.push(o),o.signal}},mu=Ph;var Dh={type:1040,canEncode:r=>r instanceof Date,encode:r=>W(r.toString()),decode:r=>new Date(X(r))},gu=Dh;var Mh={type:1041,canEncode:r=>r instanceof RegExp,encode:r=>W({source:r.source,flags:r.flags}),decode:r=>{let{source:t,flags:e}=X(r);return new RegExp(t,e)}},yu=Mh;var xu=[Zc,Wc,eu,ru,nu,ou,iu,su,cu,au,lu,fu,du,hu,pu,mu,gu,yu,nn];var ao=class{transformersMap;transformersList;constructor(t){this.transformersList=[...xu,...t?.valueCodecs??[]].sort((e,n)=>e.type<n.type?-1:e.type>n.type?1:0),this.transformersMap={},this.transformersList.forEach(e=>{if(this.transformersMap[e.type]!=null)throw new Error(`Duplicate transformer type ${e.type}`);this.transformersMap[e.type]=e})}toValue(t,e,n){for(let o=0;o<this.transformersList.length;o++){let i=this.transformersList[o];if(i.canEncode(t))return{type:i.type,value:i.encode?.(t,this,e,n)}}throw new Dr(`Unsupported value type "${t}"`)}fromValue(t,e,n){let o=this.transformersMap[t.type];if(o==null)throw new Dr(`Unsupported value type "${t.type}"`);return o.decode(t.value??new Uint8Array(0),this,e,n)}};function Oh(r){return r.isScope===!0}function Fh(r){return r.type===K.invokeMethod||r.type===K.invokeGeneratorMethod||r.type===K.invokeCallback}var zi=class{source;output;targets;invocations;values;messageHandlers;constructor(t){this.output=Qe(),this.source=Mn(this.output),this.targets=new Map,this.invocations=new Map,this.values=new ao(t),this.sink=this.sink.bind(this),this.messageHandlers={[K.invokeMethod]:{decoder:Oe,handler:this.handleInvokeMethod.bind(this)},[K.invokeGeneratorMethod]:{decoder:Oe,handler:this.handleInvokeGeneratorMethod.bind(this)},[K.abortMethodInvocation]:{decoder:Zr,handler:this.handleAbortMethod.bind(this),isScope:!0},[K.methodResolved]:{decoder:cr,handler:this.handleMethodResolved.bind(this),isScope:!0},[K.methodRejected]:{decoder:Wr,handler:this.handleMethodRejected.bind(this),isScope:!0,isError:!0},[K.invokeCallback]:{decoder:ar,handler:this.handleInvokeCallback.bind(this),isScope:!0},[K.abortCallbackInvocation]:{decoder:ur,handler:this.handleAbortCallback.bind(this),isScope:!0},[K.callbackResolved]:{decoder:Xr,handler:this.handleCallbackResolved.bind(this),isScope:!0},[K.callbackRejected]:{decoder:Yr,handler:this.handleCallbackRejected.bind(this),isScope:!0,isError:!0}}}async sink(t){for await(let e of Pr(t))try{let n=It.decode(e),o=this.messageHandlers[n.type];if(o==null)continue;let i=o.decoder.decode(n.message),s;if(Oh(o))try{s=jc(i,this.invocations)}catch{continue}o.handler(i,s).catch(c=>{Fh(n)&&this.sendError(i,c),this.invocations.delete(i.scope)}).finally(()=>{n.type===K.invokeMethod&&this.invocations.delete(i.scope)})}catch{continue}}sendError(t,e){t.parents!=null?this.output.push(It.encode({type:K.callbackRejected,message:Yr.encode({scope:t.scope,parents:t.parents,error:this.values.toValue(e)})})):this.output.push(It.encode({type:K.methodRejected,message:Wr.encode({scope:t.scope,error:this.values.toValue(e)})}))}createClient(t){return this.proxy(t)}createTarget(t,e){if(this.targets.has(t))throw new Vn(`Cannot reuse RPC target name "${t}"`);this.targets.set(t,e)}async handleInvokeMethod(t){if(this.invocations.has(t.scope))throw new Mr;let e=new Map,n=new Map,o={scope:t.scope,result:bt(),callbacks:e,children:n,parents:[],abortControllers:[],abortSignals:[]};this.invocations.set(t.scope,o);let i=this.lookupInvocationTarget(t.path),s=await i.fn.apply(i.context,t.args.map(c=>this.values.fromValue(c,this.output,o)));this.output.push(It.encode({type:K.methodResolved,message:cr.encode({scope:t.scope,value:this.values.toValue(s)})}))}async handleAbortMethod(t,e){e.abortControllers.forEach(n=>{n.abort()})}async handleInvokeGeneratorMethod(t){if(this.invocations.has(t.scope))throw new Mr;let e=new Map,n=new Map,o={scope:t.scope,result:bt(),callbacks:e,children:n,parents:[],abortControllers:[],abortSignals:[]};this.invocations.set(t.scope,o);let i=this.lookupInvocationTarget(t.path),s=i.fn.apply(i.context,t.args.map(a=>this.values.fromValue(a,this.output,o)));if(typeof s.next!="function")throw new zn(`${t.path} did not return an async generator`);let c={next:async()=>{let a=await s.next();return a.done===!0&&this.invocations.delete(t.scope),a},throw:async a=>{try{let l=await s.throw(a);return l.done===!0&&this.invocations.delete(t.scope),l}catch(l){throw this.invocations.delete(t.scope),l}},return:async a=>{let l=await s.return(a);return l.done===!0&&this.invocations.delete(t.scope),l},[Symbol.asyncIterator]:()=>c};this.output.push(It.encode({type:K.methodResolved,message:cr.encode({scope:t.scope,value:this.values.toValue(c,null,o)})}))}lookupInvocationTarget(t){let e=t.split("."),n=this.targets.get(e[0]),o=n;for(let i=1;i<e.length;i++)o=n,n=n?.[e[i]];if(n==null)throw o!=null&&t.endsWith(".then")?new Fn(`"${t.substring(0,t.length-5)}" was not a function`):new On(`Could not find "${t}" on target`);if(typeof n!="function")throw new Or("Invocation target was not a function");return{context:o,fn:n}}async handleMethodResolved(t,e){let n;t.value!=null&&(n=this.values.fromValue(t.value,this.output,e)),e.result.resolve(n)}async handleMethodRejected(t,e){let n;t.error!=null&&(n=this.values.fromValue(t.error,this.output,e)),e.result.reject(n)}async handleInvokeCallback(t,e){let n=e.callbacks.get(t.callback);if(n==null)throw new qn;let o=await n.fn.apply(n.context,t.args.map(i=>this.values.fromValue(i,this.output,e)));this.output.push(It.encode({type:K.callbackResolved,message:Xr.encode({scope:t.scope,parents:t.parents,value:this.values.toValue(o)})}))}async handleAbortCallback(t,e){e.abortControllers.forEach(n=>{n.abort()})}async handleCallbackResolved(t,e){let n;t.value!=null&&(n=this.values.fromValue(t.value,this.output,e)),e.children.get(t.scope)?.result.resolve(n),e.children.delete(t.scope)}async handleCallbackRejected(t,e){let n;t.error!=null&&(n=this.values.fromValue(t.error,this.output,e)),e.children.get(t.scope)?.result.reject(n),e.children.delete(t.scope)}proxy(t){let e=()=>{},n=this;return new Proxy(e,{get(o,i,s){return n.proxy(`${t==null?"":`${t}.`}${i.toString()}`)},apply(o,i,s){let c,a;function l(){return a==null&&(a=new Promise((f,h)=>{let x=er(),b={scope:x,result:bt(),callbacks:new Map,children:new Map,parents:[],abortControllers:[],abortSignals:[]};n.invocations.set(x,b),n.output.push(It.encode({type:K.invokeMethod,message:Oe.encode({scope:x,path:t,args:s.map(d=>n.values.toValue(d,null,b))})}));let g=Tn(b.abortSignals);g.addEventListener("abort",()=>{n.output.push(It.encode({type:K.abortMethodInvocation,message:Zr.encode({scope:x})}))}),b.result.promise.then(d=>{f(d)},d=>{h(d)}).finally(()=>{n.invocations.delete(x),g.clear()})})),a}function u(){if(c==null){let f=er(),h={scope:f,result:bt(),callbacks:new Map,children:new Map,parents:[],abortControllers:[],abortSignals:[]};n.invocations.set(f,h),n.output.push(It.encode({type:K.invokeGeneratorMethod,message:Oe.encode({scope:f,path:t,args:s.map(b=>n.values.toValue(b,null,h))})}));let x;c={async next(){if(x!=null)throw x;let g=await(await h.result.promise).next();return g.done===!0&&n.invocations.delete(f),g},async throw(b){if(x!=null)throw x;try{let d=await(await h.result.promise).throw(b);return d.done===!0&&n.invocations.delete(f),d}catch(g){throw n.invocations.delete(f),x=b,g}},async return(b){if(x!=null)throw x;let d=await(await h.result.promise).return(b);return d.done===!0&&n.invocations.delete(f),d},[Symbol.asyncIterator]:()=>c}}return c}return new Proxy(e,{get(f,h,x){if(h==="then")return l().then.bind(a);if(h==="catch")return l().catch.bind(a);if(h==="finally")return l().finally.bind(a);if(h===Symbol.asyncIterator)return()=>u();if(h==="next")return u().next.bind(c);if(h==="return")return u().return.bind(c);if(h==="throw")return u().throw.bind(c);if(h===Symbol.toStringTag)return"[object Object]";if(h==="constructor")return()=>{};throw new Or(`Property ${h.toString()} was not used as a promise or async generator`)}})}})}};function bu(r){return new zi(r)}var wu={type:4096,canEncode:r=>r.code!=null&&r.version!=null&&r.multihash!=null&&r["/"]!=null,encode:r=>r.bytes,decode:r=>at.decode(r)};var on=class extends Event{type;detail;constructor(t,e){super(t),this.type=t,this.detail=e}};var Eu={type:4099,canEncode:r=>r instanceof on,encode:(r,t,e,n)=>W({type:r.type,detail:t.toValue(r.detail,e,n)}),decode:(r,t,e,n)=>{let{type:o,detail:i}=X(r);return new on(o,t.fromValue(i,e,n))}};function st(r,t="utf8"){let e=Gn[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var uo=class{index=0;input="";new(t){return this.index=0,this.input=t,this}readAtomically(t){let e=this.index,n=t();return n===void 0&&(this.index=e),n}parseWith(t){let e=t();if(this.index===this.input.length)return e}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(t){return this.readAtomically(()=>{let e=this.readChar();if(e===t)return e})}readSeparator(t,e,n){return this.readAtomically(()=>{if(!(e>0&&this.readGivenChar(t)===void 0))return n()})}readNumber(t,e,n,o){return this.readAtomically(()=>{let i=0,s=0,c=this.peekChar();if(c===void 0)return;let a=c==="0",l=2**(8*o)-1;for(;;){let u=this.readAtomically(()=>{let f=this.readChar();if(f===void 0)return;let h=Number.parseInt(f,t);if(!Number.isNaN(h))return h});if(u===void 0)break;if(i*=t,i+=u,i>l||(s+=1,e!==void 0&&s>e))return}if(s!==0)return!n&&a&&s>1?void 0:i})}readIPv4Addr(){return this.readAtomically(()=>{let t=new Uint8Array(4);for(let e=0;e<t.length;e++){let n=this.readSeparator(".",e,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;t[e]=n}return t})}readIPv6Addr(){let t=e=>{for(let n=0;n<e.length/2;n++){let o=n*2;if(n<e.length-3){let s=this.readSeparator(":",n,()=>this.readIPv4Addr());if(s!==void 0)return e[o]=s[0],e[o+1]=s[1],e[o+2]=s[2],e[o+3]=s[3],[o+4,!0]}let i=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(i===void 0)return[o,!1];e[o]=i>>8,e[o+1]=i&255}return[e.length,!1]};return this.readAtomically(()=>{let e=new Uint8Array(16),[n,o]=t(e);if(n===16)return e;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let i=new Uint8Array(14),s=16-(n+2),[c]=t(i.subarray(0,s));return e.set(i.subarray(0,c),16-c),e})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var vu=45,Vh=15,gr=new uo;function Hi(r){if(!(r.length>Vh))return gr.new(r).parseWith(()=>gr.readIPv4Addr())}function qi(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>vu))return gr.new(r).parseWith(()=>gr.readIPv6Addr())}function lo(r,t=!1){if(r.includes("%")&&(r=r.split("%")[0]),r.length>vu)return;let e=gr.new(r).parseWith(()=>gr.readIPAddr());if(e)return t&&e.length===4?Uint8Array.from([0,0,0,0,0,0,0,0,0,0,255,255,e[0],e[1],e[2],e[3]]):e}var Iw=parseInt("0xFFFF",16),Cw=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function Bu(r){return!!Hi(r)}function _u(r){return!!qi(r)}function fo(r){return!!lo(r)}var Iu=Bu,$h=_u,Ki=function(r){let t=0;if(r=r.toString().trim(),Iu(r)){let e=new Uint8Array(t+4);return r.split(/\./g).forEach(n=>{e[t++]=parseInt(n,10)&255}),e}if($h(r)){let e=r.split(":",8),n;for(n=0;n<e.length;n++){let i=Iu(e[n]),s;i&&(s=Ki(e[n]),e[n]=st(s.slice(0,2),"base16")),s!=null&&++n<8&&e.splice(n,0,st(s.slice(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++){let i=parseInt(e[n],16);o[t++]=i>>8&255,o[t++]=i&255}return o}throw new Error("invalid ip address")},Cu=function(r,t=0,e){t=~~t,e=e??r.length-t;let n=new DataView(r.buffer);if(e===4){let o=[];for(let i=0;i<e;i++)o.push(r[t+i]);return o.join(".")}if(e===16){let o=[];for(let i=0;i<e;i+=2)o.push(n.getUint16(t+i).toString(16));return o.join(":").replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}return""};var yr={},$i={},jh=[[4,32,"ip4"],[6,16,"tcp"],[33,16,"dccp"],[41,128,"ip6"],[42,-1,"ip6zone"],[43,8,"ipcidr"],[53,-1,"dns",!0],[54,-1,"dns4",!0],[55,-1,"dns6",!0],[56,-1,"dnsaddr",!0],[132,16,"sctp"],[273,16,"udp"],[275,0,"p2p-webrtc-star"],[276,0,"p2p-webrtc-direct"],[277,0,"p2p-stardust"],[280,0,"webrtc-direct"],[281,0,"webrtc"],[290,0,"p2p-circuit"],[301,0,"udt"],[302,0,"utp"],[400,-1,"unix",!1,!0],[421,-1,"ipfs"],[421,-1,"p2p"],[443,0,"https"],[444,96,"onion"],[445,296,"onion3"],[446,-1,"garlic64"],[448,0,"tls"],[449,-1,"sni"],[460,0,"quic"],[461,0,"quic-v1"],[465,0,"webtransport"],[466,-1,"certhash"],[477,0,"ws"],[478,0,"wss"],[479,0,"p2p-websocket-star"],[480,0,"http"],[481,-1,"http-path"],[777,-1,"memory"]];jh.forEach(r=>{let t=Zh(...r);$i[t.code]=t,yr[t.name]=t});function Zh(r,t,e,n,o){return{code:r,size:t,name:e,resolvable:!!n,path:!!o}}function Y(r){if(typeof r=="number"){if($i[r]!=null)return $i[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(yr[r]!=null)return yr[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var f1=Y("ip4"),d1=Y("ip6"),h1=Y("ipcidr");function Wi(r,t){switch(Y(r).code){case 4:case 41:return Xh(t);case 42:return Zi(t);case 43:return st(t,"base10");case 6:case 273:case 33:case 132:return Uu(t).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return Zi(t);case 421:return tp(t);case 444:return ku(t);case 445:return ku(t);case 466:return Jh(t);case 481:return globalThis.encodeURIComponent(Zi(t));default:return st(t,"base16")}}function Xi(r,t){switch(Y(r).code){case 4:return Tu(t);case 41:return Tu(t);case 42:return ji(t);case 43:return ae(t,"base10");case 6:case 273:case 33:case 132:return Yi(parseInt(t,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return ji(t);case 421:return Yh(t);case 444:return ep(t);case 445:return rp(t);case 466:return Qh(t);case 481:return ji(globalThis.decodeURIComponent(t));default:return ae(t,"base16")}}var Gi=Object.values(Kr).map(r=>r.decoder),Wh=function(){let r=Gi[0].or(Gi[1]);return Gi.slice(2).forEach(t=>r=r.or(t)),r}();function Tu(r){if(!fo(r))throw new Error("invalid ip address");return Ki(r)}function Xh(r){let t=Cu(r,0,r.length);if(t==null)throw new Error("ipBuff is required");if(!fo(t))throw new Error("invalid ip address");return t}function Yi(r){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,r),new Uint8Array(t)}function Uu(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function ji(r){let t=ae(r),e=Uint8Array.from(Ee(t.length));return Nt([e,t],e.length+t.length)}function Zi(r){let t=ie(r);if(r=r.slice(dt(t)),r.length!==t)throw new Error("inconsistent lengths");return st(r)}function Yh(r){let t;r[0]==="Q"||r[0]==="1"?t=se(tt.decode(`z${r}`)).bytes:t=at.parse(r).multihash.bytes;let e=Uint8Array.from(Ee(t.length));return Nt([e,t],e.length+t.length)}function Qh(r){let t=Wh.decode(r),e=Uint8Array.from(Ee(t.length));return Nt([e,t],e.length+t.length)}function Jh(r){let t=ie(r),e=r.slice(dt(t));if(e.length!==t)throw new Error("inconsistent lengths");return"u"+st(e,"base64url")}function tp(r){let t=ie(r),e=r.slice(dt(t));if(e.length!==t)throw new Error("inconsistent lengths");return st(e,"base58btc")}function ep(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=qt.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=Yi(n);return Nt([e,o],e.length+o.length)}function rp(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=qt.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=Yi(n);return Nt([e,o],e.length+o.length)}function ku(r){let t=r.slice(0,r.length-2),e=r.slice(r.length-2),n=st(t,"base32"),o=Uu(e);return`${n}:${o}`}function Lu(r){r=Qi(r);let t=[],e=[],n=null,o=r.split("/").slice(1);if(o.length===1&&o[0]==="")return{bytes:new Uint8Array,string:"/",tuples:[],stringTuples:[],path:null};for(let i=0;i<o.length;i++){let s=o[i],c=Y(s);if(c.size===0){t.push([c.code]),e.push([c.code]);continue}if(i++,i>=o.length)throw new ho("invalid address: "+r);if(c.path===!0){n=Qi(o.slice(i).join("/")),t.push([c.code,Xi(c.code,n)]),e.push([c.code,n]);break}let a=Xi(c.code,o[i]);t.push([c.code,a]),e.push([c.code,Wi(c.code,a)])}return{string:Nu(e),bytes:po(t),tuples:t,stringTuples:e,path:n}}function Ji(r){let t=[],e=[],n=null,o=0;for(;o<r.length;){let i=ie(r,o),s=dt(i),c=Y(i),a=np(c,r.slice(o+s));if(a===0){t.push([i]),e.push([i]),o+=s;continue}let l=r.slice(o+s,o+s+a);if(o+=a+s,o>r.length)throw new ho("Invalid address Uint8Array: "+st(r,"base16"));t.push([i,l]);let u=Wi(i,l);if(e.push([i,u]),c.path===!0){n=u;break}}return{bytes:Uint8Array.from(r),string:Nu(e),tuples:t,stringTuples:e,path:n}}function Nu(r){let t=[];return r.map(e=>{let n=Y(e[0]);return t.push(n.name),e.length>1&&e[1]!=null&&t.push(e[1]),null}),Qi(t.join("/"))}function po(r){return Nt(r.map(t=>{let e=Y(t[0]),n=Uint8Array.from(Ee(e.code));return t.length>1&&t[1]!=null&&(n=Nt([n,t[1]])),n}))}function np(r,t){if(r.size>0)return r.size/8;if(r.size===0)return 0;{let e=ie(t instanceof Uint8Array?t:Uint8Array.from(t));return e+dt(e)}}function Qi(r){return"/"+r.trim().split("/").filter(t=>t).join("/")}var ho=class extends Error{static name="ParseError";name="ParseError";constructor(t){super(`Error parsing address: ${t}`)}};var op=Symbol.for("nodejs.util.inspect.custom"),es=Symbol.for("@multiformats/js-multiaddr/multiaddr"),ip=[Y("dns").code,Y("dns4").code,Y("dns6").code,Y("dnsaddr").code],ts=class extends Error{constructor(t="No available resolver"){super(t),this.name="NoAvailableResolverError"}},mo=class r{bytes;#e;#t;#r;#n;[es]=!0;constructor(t){t==null&&(t="");let e;if(t instanceof Uint8Array)e=Ji(t);else if(typeof t=="string"){if(t.length>0&&t.charAt(0)!=="/")throw new Error(`multiaddr "${t}" must start with a "/"`);e=Lu(t)}else if(go(t))e=Ji(t.bytes);else throw new Error("addr must be a string, Buffer, or another Multiaddr");this.bytes=e.bytes,this.#e=e.string,this.#t=e.tuples,this.#r=e.stringTuples,this.#n=e.path}toString(){return this.#e}toJSON(){return this.toString()}toOptions(){let t,e,n,o,i="",s=Y("tcp"),c=Y("udp"),a=Y("ip4"),l=Y("ip6"),u=Y("dns6"),f=Y("ip6zone");for(let[x,b]of this.stringTuples())x===f.code&&(i=`%${b??""}`),ip.includes(x)&&(e=s.name==="tcp"?"tcp":"udp",o=443,n=`${b??""}${i}`,t=x===u.code?6:4),(x===s.code||x===c.code)&&(e=Y(x).name==="tcp"?"tcp":"udp",o=parseInt(b??"")),(x===a.code||x===l.code)&&(e=Y(x).name==="tcp"?"tcp":"udp",n=`${b??""}${i}`,t=x===l.code?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}}protos(){return this.#t.map(([t])=>Object.assign({},Y(t)))}protoCodes(){return this.#t.map(([t])=>t)}protoNames(){return this.#t.map(([t])=>Y(t).name)}tuples(){return this.#t.map(([t,e])=>e==null?[t]:[t,e])}stringTuples(){return this.#r.map(([t,e])=>e==null?[t]:[t,e])}encapsulate(t){return t=new r(t),new r(this.toString()+t.toString())}decapsulate(t){let e=t.toString(),n=this.toString(),o=n.lastIndexOf(e);if(o<0)throw new Error(`Address ${this.toString()} does not contain subaddress: ${t.toString()}`);return new r(n.slice(0,o))}decapsulateCode(t){let e=this.tuples();for(let n=e.length-1;n>=0;n--)if(e[n][0]===t)return new r(po(e.slice(0,n)));return this}getPeerId(){try{let t=[];this.stringTuples().forEach(([n,o])=>{n===yr.p2p.code&&t.push([n,o]),n===yr["p2p-circuit"].code&&(t=[])});let e=t.pop();if(e?.[1]!=null){let n=e[1];return n[0]==="Q"||n[0]==="1"?st(tt.decode(`z${n}`),"base58btc"):st(at.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){return this.#n}equals(t){return Gt(this.bytes,t.bytes)}async resolve(t){let e=this.protos().find(i=>i.resolvable);if(e==null)return[this];let n=Ru.get(e.name);if(n==null)throw new ts(`no available resolver for ${e.name}`);return(await n(this,t)).map(i=>Ve(i))}nodeAddress(){let t=this.toOptions();if(t.transport!=="tcp"&&t.transport!=="udp")throw new Error(`multiaddr must have a valid format - no protocol with name: "${t.transport}". Must have a valid transport protocol: "{tcp, udp}"`);return{family:t.family,address:t.host,port:t.port}}isThinWaistAddress(t){let e=(t??this).protos();return!(e.length!==2||e[0].code!==4&&e[0].code!==41||e[1].code!==6&&e[1].code!==273)}[op](){return`Multiaddr(${this.#e})`}};var Ru=new Map;function go(r){return!!r?.[es]}function Ve(r){return new mo(r)}var Pu={type:4097,canEncode:r=>go(r),encode:r=>r.bytes,decode:r=>Ve(r)};function Du(r){if(!Number.isSafeInteger(r)||r<0)throw new Error("positive integer expected, got "+r)}function sp(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function xr(r,...t){if(!sp(r))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(r.length))throw new Error("Uint8Array expected of length "+t+", got length="+r.length)}function Mu(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");Du(r.outputLen),Du(r.blockLen)}function br(r,t=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(t&&r.finished)throw new Error("Hash#digest() has already been called")}function Ou(r,t){xr(r);let e=t.outputLen;if(r.length<e)throw new Error("digestInto() expects output buffer of length at least "+e)}var ze=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function yo(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function Xt(r,t){return r<<32-t|r>>>t}function Fu(r){if(typeof r!="string")throw new Error("utf8ToBytes expected string, got "+typeof r);return new Uint8Array(new TextEncoder().encode(r))}function sn(r){return typeof r=="string"&&(r=Fu(r)),xr(r),r}function rs(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];xr(o),t+=o.length}let e=new Uint8Array(t);for(let n=0,o=0;n<r.length;n++){let i=r[n];e.set(i,o),o+=i.length}return e}var wr=class{clone(){return this._cloneInto()}};function xo(r){let t=n=>r().update(sn(n)).digest(),e=r();return t.outputLen=e.outputLen,t.blockLen=e.blockLen,t.create=()=>r(),t}function bo(r=32){if(ze&&typeof ze.getRandomValues=="function")return ze.getRandomValues(new Uint8Array(r));if(ze&&typeof ze.randomBytes=="function")return ze.randomBytes(r);throw new Error("crypto.getRandomValues must be defined")}function cp(r,t,e,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(t,e,n);let o=BigInt(32),i=BigInt(4294967295),s=Number(e>>o&i),c=Number(e&i),a=n?4:0,l=n?0:4;r.setUint32(t+a,s,n),r.setUint32(t+l,c,n)}function Vu(r,t,e){return r&t^~r&e}function zu(r,t,e){return r&t^r&e^t&e}var Er=class extends wr{constructor(t,e,n,o){super(),this.blockLen=t,this.outputLen=e,this.padOffset=n,this.isLE=o,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=yo(this.buffer)}update(t){br(this);let{view:e,buffer:n,blockLen:o}=this;t=sn(t);let i=t.length;for(let s=0;s<i;){let c=Math.min(o-this.pos,i-s);if(c===o){let a=yo(t);for(;o<=i-s;s+=o)this.process(a,s);continue}n.set(t.subarray(s,s+c),this.pos),this.pos+=c,s+=c,this.pos===o&&(this.process(e,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){br(this),Ou(t,this),this.finished=!0;let{buffer:e,view:n,blockLen:o,isLE:i}=this,{pos:s}=this;e[s++]=128,this.buffer.subarray(s).fill(0),this.padOffset>o-s&&(this.process(n,0),s=0);for(let f=s;f<o;f++)e[f]=0;cp(n,o-8,BigInt(this.length*8),i),this.process(n,0);let c=yo(t),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let l=a/4,u=this.get();if(l>u.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;f<l;f++)c.setUint32(4*f,u[f],i)}digest(){let{buffer:t,outputLen:e}=this;this.digestInto(t);let n=t.slice(0,e);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());let{blockLen:e,buffer:n,length:o,finished:i,destroyed:s,pos:c}=this;return t.length=o,t.pos=c,t.finished=i,t.destroyed=s,o%e&&t.buffer.set(n),t}};var wo=BigInt(4294967295),ns=BigInt(32);function Hu(r,t=!1){return t?{h:Number(r&wo),l:Number(r>>ns&wo)}:{h:Number(r>>ns&wo)|0,l:Number(r&wo)|0}}function ap(r,t=!1){let e=new Uint32Array(r.length),n=new Uint32Array(r.length);for(let o=0;o<r.length;o++){let{h:i,l:s}=Hu(r[o],t);[e[o],n[o]]=[i,s]}return[e,n]}var up=(r,t)=>BigInt(r>>>0)<<ns|BigInt(t>>>0),lp=(r,t,e)=>r>>>e,fp=(r,t,e)=>r<<32-e|t>>>e,dp=(r,t,e)=>r>>>e|t<<32-e,hp=(r,t,e)=>r<<32-e|t>>>e,pp=(r,t,e)=>r<<64-e|t>>>e-32,mp=(r,t,e)=>r>>>e-32|t<<64-e,gp=(r,t)=>t,yp=(r,t)=>r,xp=(r,t,e)=>r<<e|t>>>32-e,bp=(r,t,e)=>t<<e|r>>>32-e,wp=(r,t,e)=>t<<e-32|r>>>64-e,Ep=(r,t,e)=>r<<e-32|t>>>64-e;function vp(r,t,e,n){let o=(t>>>0)+(n>>>0);return{h:r+e+(o/2**32|0)|0,l:o|0}}var Sp=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),Ap=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,Bp=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),_p=(r,t,e,n,o)=>t+e+n+o+(r/2**32|0)|0,Ip=(r,t,e,n,o)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(o>>>0),Cp=(r,t,e,n,o,i)=>t+e+n+o+i+(r/2**32|0)|0;var Tp={fromBig:Hu,split:ap,toBig:up,shrSH:lp,shrSL:fp,rotrSH:dp,rotrSL:hp,rotrBH:pp,rotrBL:mp,rotr32H:gp,rotr32L:yp,rotlSH:xp,rotlSL:bp,rotlBH:wp,rotlBL:Ep,add:vp,add3L:Sp,add3H:Ap,add4L:Bp,add4H:_p,add5H:Cp,add5L:Ip},F=Tp;var[kp,Up]=F.split(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(r=>BigInt(r))),_e=new Uint32Array(80),Ie=new Uint32Array(80),os=class extends Er{constructor(){super(128,64,16,!1),this.Ah=1779033703,this.Al=-205731576,this.Bh=-1150833019,this.Bl=-2067093701,this.Ch=1013904242,this.Cl=-23791573,this.Dh=-1521486534,this.Dl=1595750129,this.Eh=1359893119,this.El=-1377402159,this.Fh=-1694144372,this.Fl=725511199,this.Gh=528734635,this.Gl=-79577749,this.Hh=1541459225,this.Hl=327033209}get(){let{Ah:t,Al:e,Bh:n,Bl:o,Ch:i,Cl:s,Dh:c,Dl:a,Eh:l,El:u,Fh:f,Fl:h,Gh:x,Gl:b,Hh:g,Hl:d}=this;return[t,e,n,o,i,s,c,a,l,u,f,h,x,b,g,d]}set(t,e,n,o,i,s,c,a,l,u,f,h,x,b,g,d){this.Ah=t|0,this.Al=e|0,this.Bh=n|0,this.Bl=o|0,this.Ch=i|0,this.Cl=s|0,this.Dh=c|0,this.Dl=a|0,this.Eh=l|0,this.El=u|0,this.Fh=f|0,this.Fl=h|0,this.Gh=x|0,this.Gl=b|0,this.Hh=g|0,this.Hl=d|0}process(t,e){for(let m=0;m<16;m++,e+=4)_e[m]=t.getUint32(e),Ie[m]=t.getUint32(e+=4);for(let m=16;m<80;m++){let _=_e[m-15]|0,R=Ie[m-15]|0,N=F.rotrSH(_,R,1)^F.rotrSH(_,R,8)^F.shrSH(_,R,7),T=F.rotrSL(_,R,1)^F.rotrSL(_,R,8)^F.shrSL(_,R,7),U=_e[m-2]|0,k=Ie[m-2]|0,J=F.rotrSH(U,k,19)^F.rotrBH(U,k,61)^F.shrSH(U,k,6),q=F.rotrSL(U,k,19)^F.rotrBL(U,k,61)^F.shrSL(U,k,6),z=F.add4L(T,q,Ie[m-7],Ie[m-16]),ct=F.add4H(z,N,J,_e[m-7],_e[m-16]);_e[m]=ct|0,Ie[m]=z|0}let{Ah:n,Al:o,Bh:i,Bl:s,Ch:c,Cl:a,Dh:l,Dl:u,Eh:f,El:h,Fh:x,Fl:b,Gh:g,Gl:d,Hh:E,Hl:A}=this;for(let m=0;m<80;m++){let _=F.rotrSH(f,h,14)^F.rotrSH(f,h,18)^F.rotrBH(f,h,41),R=F.rotrSL(f,h,14)^F.rotrSL(f,h,18)^F.rotrBL(f,h,41),N=f&x^~f&g,T=h&b^~h&d,U=F.add5L(A,R,T,Up[m],Ie[m]),k=F.add5H(U,E,_,N,kp[m],_e[m]),J=U|0,q=F.rotrSH(n,o,28)^F.rotrBH(n,o,34)^F.rotrBH(n,o,39),z=F.rotrSL(n,o,28)^F.rotrBL(n,o,34)^F.rotrBL(n,o,39),ct=n&i^n&c^i&c,B=o&s^o&a^s&a;E=g|0,A=d|0,g=x|0,d=b|0,x=f|0,b=h|0,{h:f,l:h}=F.add(l|0,u|0,k|0,J|0),l=c|0,u=a|0,c=i|0,a=s|0,i=n|0,s=o|0;let L=F.add3L(J,z,B);n=F.add3H(L,k,q,ct),o=L|0}({h:n,l:o}=F.add(this.Ah|0,this.Al|0,n|0,o|0)),{h:i,l:s}=F.add(this.Bh|0,this.Bl|0,i|0,s|0),{h:c,l:a}=F.add(this.Ch|0,this.Cl|0,c|0,a|0),{h:l,l:u}=F.add(this.Dh|0,this.Dl|0,l|0,u|0),{h:f,l:h}=F.add(this.Eh|0,this.El|0,f|0,h|0),{h:x,l:b}=F.add(this.Fh|0,this.Fl|0,x|0,b|0),{h:g,l:d}=F.add(this.Gh|0,this.Gl|0,g|0,d|0),{h:E,l:A}=F.add(this.Hh|0,this.Hl|0,E|0,A|0),this.set(n,o,i,s,c,a,l,u,f,h,x,b,g,d,E,A)}roundClean(){_e.fill(0),Ie.fill(0)}destroy(){this.buffer.fill(0),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var qu=xo(()=>new os);var So={};Tt(So,{aInRange:()=>Ut,abool:()=>Yt,abytes:()=>vr,bitGet:()=>Mp,bitLen:()=>as,bitMask:()=>an,bitSet:()=>Op,bytesToHex:()=>de,bytesToNumberBE:()=>he,bytesToNumberLE:()=>Te,concatBytes:()=>pe,createHmacDrbg:()=>us,ensureBytes:()=>ot,equalBytes:()=>Pp,hexToBytes:()=>qe,hexToNumber:()=>cs,inRange:()=>cn,isBytes:()=>Ce,memoized:()=>$e,notImplemented:()=>Vp,numberToBytesBE:()=>ke,numberToBytesLE:()=>Ke,numberToHexUnpadded:()=>He,numberToVarBytesBE:()=>Rp,utf8ToBytes:()=>Dp,validateObject:()=>re});var Eo=BigInt(0),vo=BigInt(1),Lp=BigInt(2);function Ce(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function vr(r){if(!Ce(r))throw new Error("Uint8Array expected")}function Yt(r,t){if(typeof t!="boolean")throw new Error(r+" boolean expected, got "+t)}var Np=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function de(r){vr(r);let t="";for(let e=0;e<r.length;e++)t+=Np[r[e]];return t}function He(r){let t=r.toString(16);return t.length&1?"0"+t:t}function cs(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return r===""?Eo:BigInt("0x"+r)}var fe={_0:48,_9:57,A:65,F:70,a:97,f:102};function Ku(r){if(r>=fe._0&&r<=fe._9)return r-fe._0;if(r>=fe.A&&r<=fe.F)return r-(fe.A-10);if(r>=fe.a&&r<=fe.f)return r-(fe.a-10)}function qe(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);let t=r.length,e=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(e);for(let o=0,i=0;o<e;o++,i+=2){let s=Ku(r.charCodeAt(i)),c=Ku(r.charCodeAt(i+1));if(s===void 0||c===void 0){let a=r[i]+r[i+1];throw new Error('hex string expected, got non-hex character "'+a+'" at index '+i)}n[o]=s*16+c}return n}function he(r){return cs(de(r))}function Te(r){return vr(r),cs(de(Uint8Array.from(r).reverse()))}function ke(r,t){return qe(r.toString(16).padStart(t*2,"0"))}function Ke(r,t){return ke(r,t).reverse()}function Rp(r){return qe(He(r))}function ot(r,t,e){let n;if(typeof t=="string")try{n=qe(t)}catch(i){throw new Error(r+" must be hex string or Uint8Array, cause: "+i)}else if(Ce(t))n=Uint8Array.from(t);else throw new Error(r+" must be hex string or Uint8Array");let o=n.length;if(typeof e=="number"&&o!==e)throw new Error(r+" of length "+e+" expected, got "+o);return n}function pe(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];vr(o),t+=o.length}let e=new Uint8Array(t);for(let n=0,o=0;n<r.length;n++){let i=r[n];e.set(i,o),o+=i.length}return e}function Pp(r,t){if(r.length!==t.length)return!1;let e=0;for(let n=0;n<r.length;n++)e|=r[n]^t[n];return e===0}function Dp(r){if(typeof r!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(r))}var is=r=>typeof r=="bigint"&&Eo<=r;function cn(r,t,e){return is(r)&&is(t)&&is(e)&&t<=r&&r<e}function Ut(r,t,e,n){if(!cn(t,e,n))throw new Error("expected valid "+r+": "+e+" <= n < "+n+", got "+t)}function as(r){let t;for(t=0;r>Eo;r>>=vo,t+=1);return t}function Mp(r,t){return r>>BigInt(t)&vo}function Op(r,t,e){return r|(e?vo:Eo)<<BigInt(t)}var an=r=>(Lp<<BigInt(r-1))-vo,ss=r=>new Uint8Array(r),$u=r=>Uint8Array.from(r);function us(r,t,e){if(typeof r!="number"||r<2)throw new Error("hashLen must be a number");if(typeof t!="number"||t<2)throw new Error("qByteLen must be a number");if(typeof e!="function")throw new Error("hmacFn must be a function");let n=ss(r),o=ss(r),i=0,s=()=>{n.fill(1),o.fill(0),i=0},c=(...f)=>e(o,n,...f),a=(f=ss())=>{o=c($u([0]),f),n=c(),f.length!==0&&(o=c($u([1]),f),n=c())},l=()=>{if(i++>=1e3)throw new Error("drbg: tried 1000 values");let f=0,h=[];for(;f<t;){n=c();let x=n.slice();h.push(x),f+=n.length}return pe(...h)};return(f,h)=>{s(),a(f);let x;for(;!(x=h(l()));)a();return s(),x}}var Fp={bigint:r=>typeof r=="bigint",function:r=>typeof r=="function",boolean:r=>typeof r=="boolean",string:r=>typeof r=="string",stringOrUint8Array:r=>typeof r=="string"||Ce(r),isSafeInteger:r=>Number.isSafeInteger(r),array:r=>Array.isArray(r),field:(r,t)=>t.Fp.isValid(r),hash:r=>typeof r=="function"&&Number.isSafeInteger(r.outputLen)};function re(r,t,e={}){let n=(o,i,s)=>{let c=Fp[i];if(typeof c!="function")throw new Error("invalid validator function");let a=r[o];if(!(s&&a===void 0)&&!c(a,r))throw new Error("param "+String(o)+" is invalid. Expected "+i+", got "+a)};for(let[o,i]of Object.entries(t))n(o,i,!1);for(let[o,i]of Object.entries(e))n(o,i,!0);return r}var Vp=()=>{throw new Error("not implemented")};function $e(r){let t=new WeakMap;return(e,...n)=>{let o=t.get(e);if(o!==void 0)return o;let i=r(e,...n);return t.set(e,i),i}}var ut=BigInt(0),rt=BigInt(1),Ge=BigInt(2),zp=BigInt(3),ls=BigInt(4),Gu=BigInt(5),ju=BigInt(8),Hp=BigInt(9),qp=BigInt(16);function Z(r,t){let e=r%t;return e>=ut?e:t+e}function Kp(r,t,e){if(t<ut)throw new Error("invalid exponent, negatives unsupported");if(e<=ut)throw new Error("invalid modulus");if(e===rt)return ut;let n=rt;for(;t>ut;)t&rt&&(n=n*r%e),r=r*r%e,t>>=rt;return n}function nt(r,t,e){let n=r;for(;t-- >ut;)n*=n,n%=e;return n}function Ao(r,t){if(r===ut)throw new Error("invert: expected non-zero number");if(t<=ut)throw new Error("invert: expected positive modulus, got "+t);let e=Z(r,t),n=t,o=ut,i=rt,s=rt,c=ut;for(;e!==ut;){let l=n/e,u=n%e,f=o-s*l,h=i-c*l;n=e,e=u,o=s,i=c,s=f,c=h}if(n!==rt)throw new Error("invert: does not exist");return Z(o,t)}function $p(r){let t=(r-rt)/Ge,e,n,o;for(e=r-rt,n=0;e%Ge===ut;e/=Ge,n++);for(o=Ge;o<r&&Kp(o,t,r)!==r-rt;o++)if(o>1e3)throw new Error("Cannot find square root: likely non-prime P");if(n===1){let s=(r+rt)/ls;return function(a,l){let u=a.pow(l,s);if(!a.eql(a.sqr(u),l))throw new Error("Cannot find square root");return u}}let i=(e+rt)/Ge;return function(c,a){if(c.pow(a,t)===c.neg(c.ONE))throw new Error("Cannot find square root");let l=n,u=c.pow(c.mul(c.ONE,o),e),f=c.pow(a,i),h=c.pow(a,e);for(;!c.eql(h,c.ONE);){if(c.eql(h,c.ZERO))return c.ZERO;let x=1;for(let g=c.sqr(h);x<l&&!c.eql(g,c.ONE);x++)g=c.sqr(g);let b=c.pow(u,rt<<BigInt(l-x-1));u=c.sqr(b),f=c.mul(f,b),h=c.mul(h,u),l=x}return f}}function Gp(r){if(r%ls===zp){let t=(r+rt)/ls;return function(n,o){let i=n.pow(o,t);if(!n.eql(n.sqr(i),o))throw new Error("Cannot find square root");return i}}if(r%ju===Gu){let t=(r-Gu)/ju;return function(n,o){let i=n.mul(o,Ge),s=n.pow(i,t),c=n.mul(o,s),a=n.mul(n.mul(c,Ge),s),l=n.mul(c,n.sub(a,n.ONE));if(!n.eql(n.sqr(l),o))throw new Error("Cannot find square root");return l}}return r%qp,$p(r)}var Zu=(r,t)=>(Z(r,t)&rt)===rt,jp=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function fs(r){let t={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},e=jp.reduce((n,o)=>(n[o]="function",n),t);return re(r,e)}function Zp(r,t,e){if(e<ut)throw new Error("invalid exponent, negatives unsupported");if(e===ut)return r.ONE;if(e===rt)return t;let n=r.ONE,o=t;for(;e>ut;)e&rt&&(n=r.mul(n,o)),o=r.sqr(o),e>>=rt;return n}function Wp(r,t){let e=new Array(t.length),n=t.reduce((i,s,c)=>r.is0(s)?i:(e[c]=i,r.mul(i,s)),r.ONE),o=r.inv(n);return t.reduceRight((i,s,c)=>r.is0(s)?i:(e[c]=r.mul(i,e[c]),r.mul(i,s)),o),e}function ds(r,t){let e=t!==void 0?t:r.toString(2).length,n=Math.ceil(e/8);return{nBitLength:e,nByteLength:n}}function Ue(r,t,e=!1,n={}){if(r<=ut)throw new Error("invalid field: expected ORDER > 0, got "+r);let{nBitLength:o,nByteLength:i}=ds(r,t);if(i>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let s,c=Object.freeze({ORDER:r,isLE:e,BITS:o,BYTES:i,MASK:an(o),ZERO:ut,ONE:rt,create:a=>Z(a,r),isValid:a=>{if(typeof a!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof a);return ut<=a&&a<r},is0:a=>a===ut,isOdd:a=>(a&rt)===rt,neg:a=>Z(-a,r),eql:(a,l)=>a===l,sqr:a=>Z(a*a,r),add:(a,l)=>Z(a+l,r),sub:(a,l)=>Z(a-l,r),mul:(a,l)=>Z(a*l,r),pow:(a,l)=>Zp(c,a,l),div:(a,l)=>Z(a*Ao(l,r),r),sqrN:a=>a*a,addN:(a,l)=>a+l,subN:(a,l)=>a-l,mulN:(a,l)=>a*l,inv:a=>Ao(a,r),sqrt:n.sqrt||(a=>(s||(s=Gp(r)),s(c,a))),invertBatch:a=>Wp(c,a),cmov:(a,l,u)=>u?l:a,toBytes:a=>e?Ke(a,i):ke(a,i),fromBytes:a=>{if(a.length!==i)throw new Error("Field.fromBytes: expected "+i+" bytes, got "+a.length);return e?Te(a):he(a)}});return Object.freeze(c)}function Wu(r){if(typeof r!="bigint")throw new Error("field order must be bigint");let t=r.toString(2).length;return Math.ceil(t/8)}function hs(r){let t=Wu(r);return t+Math.ceil(t/2)}function Xu(r,t,e=!1){let n=r.length,o=Wu(t),i=hs(t);if(n<16||n<i||n>1024)throw new Error("expected "+i+"-1024 bytes of input, got "+n);let s=e?Te(r):he(r),c=Z(s,t-rt)+rt;return e?Ke(c,o):ke(c,o)}var Yu=BigInt(0),Bo=BigInt(1);function ps(r,t){let e=t.negate();return r?e:t}function Qu(r,t){if(!Number.isSafeInteger(r)||r<=0||r>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+r)}function ms(r,t){Qu(r,t);let e=Math.ceil(t/r)+1,n=2**(r-1);return{windows:e,windowSize:n}}function Xp(r,t){if(!Array.isArray(r))throw new Error("array expected");r.forEach((e,n)=>{if(!(e instanceof t))throw new Error("invalid point at index "+n)})}function Yp(r,t){if(!Array.isArray(r))throw new Error("array of scalars expected");r.forEach((e,n)=>{if(!t.isValid(e))throw new Error("invalid scalar at index "+n)})}var gs=new WeakMap,Ju=new WeakMap;function ys(r){return Ju.get(r)||1}function _o(r,t){return{constTimeNegate:ps,hasPrecomputes(e){return ys(e)!==1},unsafeLadder(e,n,o=r.ZERO){let i=e;for(;n>Yu;)n&Bo&&(o=o.add(i)),i=i.double(),n>>=Bo;return o},precomputeWindow(e,n){let{windows:o,windowSize:i}=ms(n,t),s=[],c=e,a=c;for(let l=0;l<o;l++){a=c,s.push(a);for(let u=1;u<i;u++)a=a.add(c),s.push(a);c=a.double()}return s},wNAF(e,n,o){let{windows:i,windowSize:s}=ms(e,t),c=r.ZERO,a=r.BASE,l=BigInt(2**e-1),u=2**e,f=BigInt(e);for(let h=0;h<i;h++){let x=h*s,b=Number(o&l);o>>=f,b>s&&(b-=u,o+=Bo);let g=x,d=x+Math.abs(b)-1,E=h%2!==0,A=b<0;b===0?a=a.add(ps(E,n[g])):c=c.add(ps(A,n[d]))}return{p:c,f:a}},wNAFUnsafe(e,n,o,i=r.ZERO){let{windows:s,windowSize:c}=ms(e,t),a=BigInt(2**e-1),l=2**e,u=BigInt(e);for(let f=0;f<s;f++){let h=f*c;if(o===Yu)break;let x=Number(o&a);if(o>>=u,x>c&&(x-=l,o+=Bo),x===0)continue;let b=n[h+Math.abs(x)-1];x<0&&(b=b.negate()),i=i.add(b)}return i},getPrecomputes(e,n,o){let i=gs.get(n);return i||(i=this.precomputeWindow(n,e),e!==1&&gs.set(n,o(i))),i},wNAFCached(e,n,o){let i=ys(e);return this.wNAF(i,this.getPrecomputes(i,e,o),n)},wNAFCachedUnsafe(e,n,o,i){let s=ys(e);return s===1?this.unsafeLadder(e,n,i):this.wNAFUnsafe(s,this.getPrecomputes(s,e,o),n,i)},setWindowSize(e,n){Qu(n,t),Ju.set(e,n),gs.delete(e)}}}function Io(r,t,e,n){if(Xp(e,r),Yp(n,t),e.length!==n.length)throw new Error("arrays of points and scalars must have equal length");let o=r.ZERO,i=as(BigInt(e.length)),s=i>12?i-3:i>4?i-2:i?2:1,c=(1<<s)-1,a=new Array(c+1).fill(o),l=Math.floor((t.BITS-1)/s)*s,u=o;for(let f=l;f>=0;f-=s){a.fill(o);for(let x=0;x<n.length;x++){let b=n[x],g=Number(b>>BigInt(f)&BigInt(c));a[g]=a[g].add(e[x])}let h=o;for(let x=a.length-1,b=o;x>0;x--)b=b.add(a[x]),h=h.add(b);if(u=u.add(h),f!==0)for(let x=0;x<s;x++)u=u.double()}return u}function un(r){return fs(r.Fp),re(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...ds(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}var Qt=BigInt(0),Lt=BigInt(1),Co=BigInt(2),Qp=BigInt(8),Jp={zip215:!0};function t0(r){let t=un(r);return re(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...t})}function tl(r){let t=t0(r),{Fp:e,n,prehash:o,hash:i,randomBytes:s,nByteLength:c,h:a}=t,l=Co<<BigInt(c*8)-Lt,u=e.create,f=Ue(t.n,t.nBitLength),h=t.uvRatio||((w,y)=>{try{return{isValid:!0,value:e.sqrt(w*e.inv(y))}}catch{return{isValid:!1,value:Qt}}}),x=t.adjustScalarBytes||(w=>w),b=t.domain||((w,y,v)=>{if(Yt("phflag",v),y.length||v)throw new Error("Contexts/pre-hash are not supported");return w});function g(w,y){Ut("coordinate "+w,y,Qt,l)}function d(w){if(!(w instanceof m))throw new Error("ExtendedPoint expected")}let E=$e((w,y)=>{let{ex:v,ey:C,ez:P}=w,D=w.is0();y==null&&(y=D?Qp:e.inv(P));let V=u(v*y),H=u(C*y),O=u(P*y);if(D)return{x:Qt,y:Lt};if(O!==Lt)throw new Error("invZ was invalid");return{x:V,y:H}}),A=$e(w=>{let{a:y,d:v}=t;if(w.is0())throw new Error("bad point: ZERO");let{ex:C,ey:P,ez:D,et:V}=w,H=u(C*C),O=u(P*P),j=u(D*D),Q=u(j*j),lt=u(H*y),ft=u(j*u(lt+O)),mt=u(Q+u(v*u(H*O)));if(ft!==mt)throw new Error("bad point: equation left != right (1)");let yt=u(C*P),Ct=u(D*V);if(yt!==Ct)throw new Error("bad point: equation left != right (2)");return!0});class m{constructor(y,v,C,P){this.ex=y,this.ey=v,this.ez=C,this.et=P,g("x",y),g("y",v),g("z",C),g("t",P),Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(y){if(y instanceof m)throw new Error("extended point not allowed");let{x:v,y:C}=y||{};return g("x",v),g("y",C),new m(v,C,Lt,u(v*C))}static normalizeZ(y){let v=e.invertBatch(y.map(C=>C.ez));return y.map((C,P)=>C.toAffine(v[P])).map(m.fromAffine)}static msm(y,v){return Io(m,f,y,v)}_setWindowSize(y){N.setWindowSize(this,y)}assertValidity(){A(this)}equals(y){d(y);let{ex:v,ey:C,ez:P}=this,{ex:D,ey:V,ez:H}=y,O=u(v*H),j=u(D*P),Q=u(C*H),lt=u(V*P);return O===j&&Q===lt}is0(){return this.equals(m.ZERO)}negate(){return new m(u(-this.ex),this.ey,this.ez,u(-this.et))}double(){let{a:y}=t,{ex:v,ey:C,ez:P}=this,D=u(v*v),V=u(C*C),H=u(Co*u(P*P)),O=u(y*D),j=v+C,Q=u(u(j*j)-D-V),lt=O+V,ft=lt-H,mt=O-V,yt=u(Q*ft),Ct=u(lt*mt),St=u(Q*mt),Jt=u(ft*lt);return new m(yt,Ct,Jt,St)}add(y){d(y);let{a:v,d:C}=t,{ex:P,ey:D,ez:V,et:H}=this,{ex:O,ey:j,ez:Q,et:lt}=y;if(v===BigInt(-1)){let ks=u((D-P)*(j+O)),Us=u((D+P)*(j-O)),zo=u(Us-ks);if(zo===Qt)return this.double();let Ls=u(V*Co*lt),Ns=u(H*Co*Q),Rs=Ns+Ls,Ps=Us+ks,Ds=Ns-Ls,Rl=u(Rs*zo),Pl=u(Ps*Ds),Dl=u(Rs*Ds),Ml=u(zo*Ps);return new m(Rl,Pl,Ml,Dl)}let ft=u(P*O),mt=u(D*j),yt=u(H*C*lt),Ct=u(V*Q),St=u((P+D)*(O+j)-ft-mt),Jt=Ct-yt,ne=Ct+yt,Br=u(mt-v*ft),kl=u(St*Jt),Ul=u(ne*Br),Ll=u(St*Br),Nl=u(Jt*ne);return new m(kl,Ul,Nl,Ll)}subtract(y){return this.add(y.negate())}wNAF(y){return N.wNAFCached(this,y,m.normalizeZ)}multiply(y){let v=y;Ut("scalar",v,Lt,n);let{p:C,f:P}=this.wNAF(v);return m.normalizeZ([C,P])[0]}multiplyUnsafe(y,v=m.ZERO){let C=y;return Ut("scalar",C,Qt,n),C===Qt?R:this.is0()||C===Lt?this:N.wNAFCachedUnsafe(this,C,m.normalizeZ,v)}isSmallOrder(){return this.multiplyUnsafe(a).is0()}isTorsionFree(){return N.unsafeLadder(this,n).is0()}toAffine(y){return E(this,y)}clearCofactor(){let{h:y}=t;return y===Lt?this:this.multiplyUnsafe(y)}static fromHex(y,v=!1){let{d:C,a:P}=t,D=e.BYTES;y=ot("pointHex",y,D),Yt("zip215",v);let V=y.slice(),H=y[D-1];V[D-1]=H&-129;let O=Te(V),j=v?l:e.ORDER;Ut("pointHex.y",O,Qt,j);let Q=u(O*O),lt=u(Q-Lt),ft=u(C*Q-P),{isValid:mt,value:yt}=h(lt,ft);if(!mt)throw new Error("Point.fromHex: invalid y coordinate");let Ct=(yt&Lt)===Lt,St=(H&128)!==0;if(!v&&yt===Qt&&St)throw new Error("Point.fromHex: x=0 and x_0=1");return St!==Ct&&(yt=u(-yt)),m.fromAffine({x:yt,y:O})}static fromPrivateKey(y){return k(y).point}toRawBytes(){let{x:y,y:v}=this.toAffine(),C=Ke(v,e.BYTES);return C[C.length-1]|=y&Lt?128:0,C}toHex(){return de(this.toRawBytes())}}m.BASE=new m(t.Gx,t.Gy,Lt,u(t.Gx*t.Gy)),m.ZERO=new m(Qt,Lt,Lt,Qt);let{BASE:_,ZERO:R}=m,N=_o(m,c*8);function T(w){return Z(w,n)}function U(w){return T(Te(w))}function k(w){let y=e.BYTES;w=ot("private key",w,y);let v=ot("hashed private key",i(w),2*y),C=x(v.slice(0,y)),P=v.slice(y,2*y),D=U(C),V=_.multiply(D),H=V.toRawBytes();return{head:C,prefix:P,scalar:D,point:V,pointBytes:H}}function J(w){return k(w).pointBytes}function q(w=new Uint8Array,...y){let v=pe(...y);return U(i(b(v,ot("context",w),!!o)))}function z(w,y,v={}){w=ot("message",w),o&&(w=o(w));let{prefix:C,scalar:P,pointBytes:D}=k(y),V=q(v.context,C,w),H=_.multiply(V).toRawBytes(),O=q(v.context,H,D,w),j=T(V+O*P);Ut("signature.s",j,Qt,n);let Q=pe(H,Ke(j,e.BYTES));return ot("result",Q,e.BYTES*2)}let ct=Jp;function B(w,y,v,C=ct){let{context:P,zip215:D}=C,V=e.BYTES;w=ot("signature",w,2*V),y=ot("message",y),v=ot("publicKey",v,V),D!==void 0&&Yt("zip215",D),o&&(y=o(y));let H=Te(w.slice(V,2*V)),O,j,Q;try{O=m.fromHex(v,D),j=m.fromHex(w.slice(0,V),D),Q=_.multiplyUnsafe(H)}catch{return!1}if(!D&&O.isSmallOrder())return!1;let lt=q(P,j.toRawBytes(),O.toRawBytes(),y);return j.add(O.multiplyUnsafe(lt)).subtract(Q).clearCofactor().equals(m.ZERO)}return _._setWindowSize(8),{CURVE:t,getPublicKey:J,sign:z,verify:B,ExtendedPoint:m,utils:{getExtendedPublicKey:k,randomPrivateKey:()=>s(e.BYTES),precompute(w=8,y=m.BASE){return y._setWindowSize(w),y.multiply(BigInt(3)),y}}}}var xs=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),el=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),p2=BigInt(0),e0=BigInt(1),rl=BigInt(2),m2=BigInt(3),r0=BigInt(5),n0=BigInt(8);function o0(r){let t=BigInt(10),e=BigInt(20),n=BigInt(40),o=BigInt(80),i=xs,c=r*r%i*r%i,a=nt(c,rl,i)*c%i,l=nt(a,e0,i)*r%i,u=nt(l,r0,i)*l%i,f=nt(u,t,i)*u%i,h=nt(f,e,i)*f%i,x=nt(h,n,i)*h%i,b=nt(x,o,i)*x%i,g=nt(b,o,i)*x%i,d=nt(g,t,i)*u%i;return{pow_p_5_8:nt(d,rl,i)*r%i,b2:c}}function i0(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function s0(r,t){let e=xs,n=Z(t*t*t,e),o=Z(n*n*t,e),i=o0(r*o).pow_p_5_8,s=Z(r*n*i,e),c=Z(t*s*s,e),a=s,l=Z(s*el,e),u=c===r,f=c===Z(-r,e),h=c===Z(-r*el,e);return u&&(s=a),(f||h)&&(s=l),Zu(s,e)&&(s=Z(-s,e)),{isValid:u||f,value:s}}var c0=Ue(xs,void 0,!0),a0={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:c0,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:n0,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:qu,randomBytes:bo,adjustScalarBytes:i0,uvRatio:s0},nl=tl(a0);var To=32;function ol(r,t,e){return nl.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}var ko=class{type="Ed25519";raw;constructor(t){this.raw=bs(t,To)}toMultihash(){return ce.digest(Uo(this))}toCID(){return at.createV1(114,this.toMultihash())}toString(){return tt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:Gt(this.raw,t.raw)}verify(t,e){return ol(this.raw,e,t)}};function sl(r){return r=bs(r,To),new ko(r)}function bs(r,t){if(r=Uint8Array.from(r??[]),r.length!==t)throw new ye(`Key must be a Uint8Array of length ${t}, got ${r.length}`);return r}var Ht;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1"})(Ht||(Ht={}));var ws;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1"})(ws||(ws={}));(function(r){r.codec=()=>jr(ws)})(Ht||(Ht={}));var ln;(function(r){let t;r.codec=()=>(t==null&&(t=_t((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),Ht.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 c=e.uint32();switch(c>>>3){case 1:{i.Type=Ht.codec().decode(e);break}case 2:{i.Data=e.bytes();break}default:{e.skipType(c&7);break}}}return i})),t),r.encode=e=>Bt(e,r.codec()),r.decode=(e,n)=>At(e,r.codec(),n)})(ln||(ln={}));var Es;(function(r){let t;r.codec=()=>(t==null&&(t=_t((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),Ht.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 c=e.uint32();switch(c>>>3){case 1:{i.Type=Ht.codec().decode(e);break}case 2:{i.Data=e.bytes();break}default:{e.skipType(c&7);break}}}return i})),t),r.encode=e=>Bt(e,r.codec()),r.decode=(e,n)=>At(e,r.codec(),n)})(Es||(Es={}));var f0=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Le=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Ne=new Uint32Array(64),vs=class extends Er{constructor(){super(64,32,8,!1),this.A=Le[0]|0,this.B=Le[1]|0,this.C=Le[2]|0,this.D=Le[3]|0,this.E=Le[4]|0,this.F=Le[5]|0,this.G=Le[6]|0,this.H=Le[7]|0}get(){let{A:t,B:e,C:n,D:o,E:i,F:s,G:c,H:a}=this;return[t,e,n,o,i,s,c,a]}set(t,e,n,o,i,s,c,a){this.A=t|0,this.B=e|0,this.C=n|0,this.D=o|0,this.E=i|0,this.F=s|0,this.G=c|0,this.H=a|0}process(t,e){for(let f=0;f<16;f++,e+=4)Ne[f]=t.getUint32(e,!1);for(let f=16;f<64;f++){let h=Ne[f-15],x=Ne[f-2],b=Xt(h,7)^Xt(h,18)^h>>>3,g=Xt(x,17)^Xt(x,19)^x>>>10;Ne[f]=g+Ne[f-7]+b+Ne[f-16]|0}let{A:n,B:o,C:i,D:s,E:c,F:a,G:l,H:u}=this;for(let f=0;f<64;f++){let h=Xt(c,6)^Xt(c,11)^Xt(c,25),x=u+h+Vu(c,a,l)+f0[f]+Ne[f]|0,g=(Xt(n,2)^Xt(n,13)^Xt(n,22))+zu(n,o,i)|0;u=l,l=a,a=c,c=s+x|0,s=i,i=o,o=n,n=x+g|0}n=n+this.A|0,o=o+this.B|0,i=i+this.C|0,s=s+this.D|0,c=c+this.E|0,a=a+this.F|0,l=l+this.G|0,u=u+this.H|0,this.set(n,o,i,s,c,a,l,u)}roundClean(){Ne.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var cl=xo(()=>new vs);var fn=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}};var Lo=class extends wr{constructor(t,e){super(),this.finished=!1,this.destroyed=!1,Mu(t);let n=sn(e);if(this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let o=this.blockLen,i=new Uint8Array(o);i.set(n.length>o?t.create().update(n).digest():n);for(let s=0;s<i.length;s++)i[s]^=54;this.iHash.update(i),this.oHash=t.create();for(let s=0;s<i.length;s++)i[s]^=106;this.oHash.update(i),i.fill(0)}update(t){return br(this),this.iHash.update(t),this}digestInto(t){br(this),xr(t,this.outputLen),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}));let{oHash:e,iHash:n,finished:o,destroyed:i,blockLen:s,outputLen:c}=this;return t=t,t.finished=o,t.destroyed=i,t.blockLen=s,t.outputLen=c,t.oHash=e._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Ss=(r,t,e)=>new Lo(r,t).update(e).digest();Ss.create=(r,t)=>new Lo(r,t);function al(r){r.lowS!==void 0&&Yt("lowS",r.lowS),r.prehash!==void 0&&Yt("prehash",r.prehash)}function d0(r){let t=un(r);re(t,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});let{endo:e,Fp:n,a:o}=t;if(e){if(!n.eql(o,n.ZERO))throw new Error("invalid endomorphism, can only be defined for Koblitz curves that have a=0");if(typeof e!="object"||typeof e.beta!="bigint"||typeof e.splitScalar!="function")throw new Error("invalid endomorphism, expected beta: bigint and splitScalar: function")}return Object.freeze({...t})}var{bytesToNumberBE:h0,hexToBytes:p0}=So,As=class extends Error{constructor(t=""){super(t)}},me={Err:As,_tlv:{encode:(r,t)=>{let{Err:e}=me;if(r<0||r>256)throw new e("tlv.encode: wrong tag");if(t.length&1)throw new e("tlv.encode: unpadded data");let n=t.length/2,o=He(n);if(o.length/2&128)throw new e("tlv.encode: long form length too big");let i=n>127?He(o.length/2|128):"";return He(r)+i+o+t},decode(r,t){let{Err:e}=me,n=0;if(r<0||r>256)throw new e("tlv.encode: wrong tag");if(t.length<2||t[n++]!==r)throw new e("tlv.decode: wrong tlv");let o=t[n++],i=!!(o&128),s=0;if(!i)s=o;else{let a=o&127;if(!a)throw new e("tlv.decode(long): indefinite length not supported");if(a>4)throw new e("tlv.decode(long): byte length is too big");let l=t.subarray(n,n+a);if(l.length!==a)throw new e("tlv.decode: length bytes not complete");if(l[0]===0)throw new e("tlv.decode(long): zero leftmost byte");for(let u of l)s=s<<8|u;if(n+=a,s<128)throw new e("tlv.decode(long): not minimal encoding")}let c=t.subarray(n,n+s);if(c.length!==s)throw new e("tlv.decode: wrong value length");return{v:c,l:t.subarray(n+s)}}},_int:{encode(r){let{Err:t}=me;if(r<ge)throw new t("integer: negative integers are not allowed");let e=He(r);if(Number.parseInt(e[0],16)&8&&(e="00"+e),e.length&1)throw new t("unexpected DER parsing assertion: unpadded hex");return e},decode(r){let{Err:t}=me;if(r[0]&128)throw new t("invalid signature integer: negative");if(r[0]===0&&!(r[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return h0(r)}},toSig(r){let{Err:t,_int:e,_tlv:n}=me,o=typeof r=="string"?p0(r):r;vr(o);let{v:i,l:s}=n.decode(48,o);if(s.length)throw new t("invalid signature: left bytes after parsing");let{v:c,l:a}=n.decode(2,i),{v:l,l:u}=n.decode(2,a);if(u.length)throw new t("invalid signature: left bytes after parsing");return{r:e.decode(c),s:e.decode(l)}},hexFromSig(r){let{_tlv:t,_int:e}=me,n=t.encode(2,e.encode(r.r)),o=t.encode(2,e.encode(r.s)),i=n+o;return t.encode(48,i)}},ge=BigInt(0),pt=BigInt(1),K2=BigInt(2),ul=BigInt(3),$2=BigInt(4);function m0(r){let t=d0(r),{Fp:e}=t,n=Ue(t.n,t.nBitLength),o=t.toBytes||((g,d,E)=>{let A=d.toAffine();return pe(Uint8Array.from([4]),e.toBytes(A.x),e.toBytes(A.y))}),i=t.fromBytes||(g=>{let d=g.subarray(1),E=e.fromBytes(d.subarray(0,e.BYTES)),A=e.fromBytes(d.subarray(e.BYTES,2*e.BYTES));return{x:E,y:A}});function s(g){let{a:d,b:E}=t,A=e.sqr(g),m=e.mul(A,g);return e.add(e.add(m,e.mul(g,d)),E)}if(!e.eql(e.sqr(t.Gy),s(t.Gx)))throw new Error("bad generator point: equation left != right");function c(g){return cn(g,pt,t.n)}function a(g){let{allowedPrivateKeyLengths:d,nByteLength:E,wrapPrivateKey:A,n:m}=t;if(d&&typeof g!="bigint"){if(Ce(g)&&(g=de(g)),typeof g!="string"||!d.includes(g.length))throw new Error("invalid private key");g=g.padStart(E*2,"0")}let _;try{_=typeof g=="bigint"?g:he(ot("private key",g,E))}catch{throw new Error("invalid private key, expected hex or "+E+" bytes, got "+typeof g)}return A&&(_=Z(_,m)),Ut("private key",_,pt,m),_}function l(g){if(!(g instanceof h))throw new Error("ProjectivePoint expected")}let u=$e((g,d)=>{let{px:E,py:A,pz:m}=g;if(e.eql(m,e.ONE))return{x:E,y:A};let _=g.is0();d==null&&(d=_?e.ONE:e.inv(m));let R=e.mul(E,d),N=e.mul(A,d),T=e.mul(m,d);if(_)return{x:e.ZERO,y:e.ZERO};if(!e.eql(T,e.ONE))throw new Error("invZ was invalid");return{x:R,y:N}}),f=$e(g=>{if(g.is0()){if(t.allowInfinityPoint&&!e.is0(g.py))return;throw new Error("bad point: ZERO")}let{x:d,y:E}=g.toAffine();if(!e.isValid(d)||!e.isValid(E))throw new Error("bad point: x or y not FE");let A=e.sqr(E),m=s(d);if(!e.eql(A,m))throw new Error("bad point: equation left != right");if(!g.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});class h{constructor(d,E,A){if(this.px=d,this.py=E,this.pz=A,d==null||!e.isValid(d))throw new Error("x required");if(E==null||!e.isValid(E))throw new Error("y required");if(A==null||!e.isValid(A))throw new Error("z required");Object.freeze(this)}static fromAffine(d){let{x:E,y:A}=d||{};if(!d||!e.isValid(E)||!e.isValid(A))throw new Error("invalid affine point");if(d instanceof h)throw new Error("projective point not allowed");let m=_=>e.eql(_,e.ZERO);return m(E)&&m(A)?h.ZERO:new h(E,A,e.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(d){let E=e.invertBatch(d.map(A=>A.pz));return d.map((A,m)=>A.toAffine(E[m])).map(h.fromAffine)}static fromHex(d){let E=h.fromAffine(i(ot("pointHex",d)));return E.assertValidity(),E}static fromPrivateKey(d){return h.BASE.multiply(a(d))}static msm(d,E){return Io(h,n,d,E)}_setWindowSize(d){b.setWindowSize(this,d)}assertValidity(){f(this)}hasEvenY(){let{y:d}=this.toAffine();if(e.isOdd)return!e.isOdd(d);throw new Error("Field doesn't support isOdd")}equals(d){l(d);let{px:E,py:A,pz:m}=this,{px:_,py:R,pz:N}=d,T=e.eql(e.mul(E,N),e.mul(_,m)),U=e.eql(e.mul(A,N),e.mul(R,m));return T&&U}negate(){return new h(this.px,e.neg(this.py),this.pz)}double(){let{a:d,b:E}=t,A=e.mul(E,ul),{px:m,py:_,pz:R}=this,N=e.ZERO,T=e.ZERO,U=e.ZERO,k=e.mul(m,m),J=e.mul(_,_),q=e.mul(R,R),z=e.mul(m,_);return z=e.add(z,z),U=e.mul(m,R),U=e.add(U,U),N=e.mul(d,U),T=e.mul(A,q),T=e.add(N,T),N=e.sub(J,T),T=e.add(J,T),T=e.mul(N,T),N=e.mul(z,N),U=e.mul(A,U),q=e.mul(d,q),z=e.sub(k,q),z=e.mul(d,z),z=e.add(z,U),U=e.add(k,k),k=e.add(U,k),k=e.add(k,q),k=e.mul(k,z),T=e.add(T,k),q=e.mul(_,R),q=e.add(q,q),k=e.mul(q,z),N=e.sub(N,k),U=e.mul(q,J),U=e.add(U,U),U=e.add(U,U),new h(N,T,U)}add(d){l(d);let{px:E,py:A,pz:m}=this,{px:_,py:R,pz:N}=d,T=e.ZERO,U=e.ZERO,k=e.ZERO,J=t.a,q=e.mul(t.b,ul),z=e.mul(E,_),ct=e.mul(A,R),B=e.mul(m,N),L=e.add(E,A),w=e.add(_,R);L=e.mul(L,w),w=e.add(z,ct),L=e.sub(L,w),w=e.add(E,m);let y=e.add(_,N);return w=e.mul(w,y),y=e.add(z,B),w=e.sub(w,y),y=e.add(A,m),T=e.add(R,N),y=e.mul(y,T),T=e.add(ct,B),y=e.sub(y,T),k=e.mul(J,w),T=e.mul(q,B),k=e.add(T,k),T=e.sub(ct,k),k=e.add(ct,k),U=e.mul(T,k),ct=e.add(z,z),ct=e.add(ct,z),B=e.mul(J,B),w=e.mul(q,w),ct=e.add(ct,B),B=e.sub(z,B),B=e.mul(J,B),w=e.add(w,B),z=e.mul(ct,w),U=e.add(U,z),z=e.mul(y,w),T=e.mul(L,T),T=e.sub(T,z),z=e.mul(L,ct),k=e.mul(y,k),k=e.add(k,z),new h(T,U,k)}subtract(d){return this.add(d.negate())}is0(){return this.equals(h.ZERO)}wNAF(d){return b.wNAFCached(this,d,h.normalizeZ)}multiplyUnsafe(d){let{endo:E,n:A}=t;Ut("scalar",d,ge,A);let m=h.ZERO;if(d===ge)return m;if(this.is0()||d===pt)return this;if(!E||b.hasPrecomputes(this))return b.wNAFCachedUnsafe(this,d,h.normalizeZ);let{k1neg:_,k1:R,k2neg:N,k2:T}=E.splitScalar(d),U=m,k=m,J=this;for(;R>ge||T>ge;)R&pt&&(U=U.add(J)),T&pt&&(k=k.add(J)),J=J.double(),R>>=pt,T>>=pt;return _&&(U=U.negate()),N&&(k=k.negate()),k=new h(e.mul(k.px,E.beta),k.py,k.pz),U.add(k)}multiply(d){let{endo:E,n:A}=t;Ut("scalar",d,pt,A);let m,_;if(E){let{k1neg:R,k1:N,k2neg:T,k2:U}=E.splitScalar(d),{p:k,f:J}=this.wNAF(N),{p:q,f:z}=this.wNAF(U);k=b.constTimeNegate(R,k),q=b.constTimeNegate(T,q),q=new h(e.mul(q.px,E.beta),q.py,q.pz),m=k.add(q),_=J.add(z)}else{let{p:R,f:N}=this.wNAF(d);m=R,_=N}return h.normalizeZ([m,_])[0]}multiplyAndAddUnsafe(d,E,A){let m=h.BASE,_=(N,T)=>T===ge||T===pt||!N.equals(m)?N.multiplyUnsafe(T):N.multiply(T),R=_(this,E).add(_(d,A));return R.is0()?void 0:R}toAffine(d){return u(this,d)}isTorsionFree(){let{h:d,isTorsionFree:E}=t;if(d===pt)return!0;if(E)return E(h,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h:d,clearCofactor:E}=t;return d===pt?this:E?E(h,this):this.multiplyUnsafe(t.h)}toRawBytes(d=!0){return Yt("isCompressed",d),this.assertValidity(),o(h,this,d)}toHex(d=!0){return Yt("isCompressed",d),de(this.toRawBytes(d))}}h.BASE=new h(t.Gx,t.Gy,e.ONE),h.ZERO=new h(e.ZERO,e.ONE,e.ZERO);let x=t.nBitLength,b=_o(h,t.endo?Math.ceil(x/2):x);return{CURVE:t,ProjectivePoint:h,normPrivateKeyToScalar:a,weierstrassEquation:s,isWithinCurveOrder:c}}function g0(r){let t=un(r);return re(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}function ll(r){let t=g0(r),{Fp:e,n}=t,o=e.BYTES+1,i=2*e.BYTES+1;function s(B){return Z(B,n)}function c(B){return Ao(B,n)}let{ProjectivePoint:a,normPrivateKeyToScalar:l,weierstrassEquation:u,isWithinCurveOrder:f}=m0({...t,toBytes(B,L,w){let y=L.toAffine(),v=e.toBytes(y.x),C=pe;return Yt("isCompressed",w),w?C(Uint8Array.from([L.hasEvenY()?2:3]),v):C(Uint8Array.from([4]),v,e.toBytes(y.y))},fromBytes(B){let L=B.length,w=B[0],y=B.subarray(1);if(L===o&&(w===2||w===3)){let v=he(y);if(!cn(v,pt,e.ORDER))throw new Error("Point is not on curve");let C=u(v),P;try{P=e.sqrt(C)}catch(H){let O=H instanceof Error?": "+H.message:"";throw new Error("Point is not on curve"+O)}let D=(P&pt)===pt;return(w&1)===1!==D&&(P=e.neg(P)),{x:v,y:P}}else if(L===i&&w===4){let v=e.fromBytes(y.subarray(0,e.BYTES)),C=e.fromBytes(y.subarray(e.BYTES,2*e.BYTES));return{x:v,y:C}}else{let v=o,C=i;throw new Error("invalid Point, expected length of "+v+", or uncompressed "+C+", got "+L)}}}),h=B=>de(ke(B,t.nByteLength));function x(B){let L=n>>pt;return B>L}function b(B){return x(B)?s(-B):B}let g=(B,L,w)=>he(B.slice(L,w));class d{constructor(L,w,y){this.r=L,this.s=w,this.recovery=y,this.assertValidity()}static fromCompact(L){let w=t.nByteLength;return L=ot("compactSignature",L,w*2),new d(g(L,0,w),g(L,w,2*w))}static fromDER(L){let{r:w,s:y}=me.toSig(ot("DER",L));return new d(w,y)}assertValidity(){Ut("r",this.r,pt,n),Ut("s",this.s,pt,n)}addRecoveryBit(L){return new d(this.r,this.s,L)}recoverPublicKey(L){let{r:w,s:y,recovery:v}=this,C=N(ot("msgHash",L));if(v==null||![0,1,2,3].includes(v))throw new Error("recovery id invalid");let P=v===2||v===3?w+t.n:w;if(P>=e.ORDER)throw new Error("recovery id 2 or 3 invalid");let D=(v&1)===0?"02":"03",V=a.fromHex(D+h(P)),H=c(P),O=s(-C*H),j=s(y*H),Q=a.BASE.multiplyAndAddUnsafe(V,O,j);if(!Q)throw new Error("point at infinify");return Q.assertValidity(),Q}hasHighS(){return x(this.s)}normalizeS(){return this.hasHighS()?new d(this.r,s(-this.s),this.recovery):this}toDERRawBytes(){return qe(this.toDERHex())}toDERHex(){return me.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return qe(this.toCompactHex())}toCompactHex(){return h(this.r)+h(this.s)}}let E={isValidPrivateKey(B){try{return l(B),!0}catch{return!1}},normPrivateKeyToScalar:l,randomPrivateKey:()=>{let B=hs(t.n);return Xu(t.randomBytes(B),t.n)},precompute(B=8,L=a.BASE){return L._setWindowSize(B),L.multiply(BigInt(3)),L}};function A(B,L=!0){return a.fromPrivateKey(B).toRawBytes(L)}function m(B){let L=Ce(B),w=typeof B=="string",y=(L||w)&&B.length;return L?y===o||y===i:w?y===2*o||y===2*i:B instanceof a}function _(B,L,w=!0){if(m(B))throw new Error("first arg must be private key");if(!m(L))throw new Error("second arg must be public key");return a.fromHex(L).multiply(l(B)).toRawBytes(w)}let R=t.bits2int||function(B){if(B.length>8192)throw new Error("input is too large");let L=he(B),w=B.length*8-t.nBitLength;return w>0?L>>BigInt(w):L},N=t.bits2int_modN||function(B){return s(R(B))},T=an(t.nBitLength);function U(B){return Ut("num < 2^"+t.nBitLength,B,ge,T),ke(B,t.nByteLength)}function k(B,L,w=J){if(["recovered","canonical"].some(ft=>ft in w))throw new Error("sign() legacy options not supported");let{hash:y,randomBytes:v}=t,{lowS:C,prehash:P,extraEntropy:D}=w;C==null&&(C=!0),B=ot("msgHash",B),al(w),P&&(B=ot("prehashed msgHash",y(B)));let V=N(B),H=l(L),O=[U(H),U(V)];if(D!=null&&D!==!1){let ft=D===!0?v(e.BYTES):D;O.push(ot("extraEntropy",ft))}let j=pe(...O),Q=V;function lt(ft){let mt=R(ft);if(!f(mt))return;let yt=c(mt),Ct=a.BASE.multiply(mt).toAffine(),St=s(Ct.x);if(St===ge)return;let Jt=s(yt*s(Q+St*H));if(Jt===ge)return;let ne=(Ct.x===St?0:2)|Number(Ct.y&pt),Br=Jt;return C&&x(Jt)&&(Br=b(Jt),ne^=1),new d(St,Br,ne)}return{seed:j,k2sig:lt}}let J={lowS:t.lowS,prehash:!1},q={lowS:t.lowS,prehash:!1};function z(B,L,w=J){let{seed:y,k2sig:v}=k(B,L,w),C=t;return us(C.hash.outputLen,C.nByteLength,C.hmac)(y,v)}a.BASE._setWindowSize(8);function ct(B,L,w,y=q){let v=B;L=ot("msgHash",L),w=ot("publicKey",w);let{lowS:C,prehash:P,format:D}=y;if(al(y),"strict"in y)throw new Error("options.strict was renamed to lowS");if(D!==void 0&&D!=="compact"&&D!=="der")throw new Error("format must be compact or der");let V=typeof v=="string"||Ce(v),H=!V&&!D&&typeof v=="object"&&v!==null&&typeof v.r=="bigint"&&typeof v.s=="bigint";if(!V&&!H)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");let O,j;try{if(H&&(O=new d(v.r,v.s)),V){try{D!=="compact"&&(O=d.fromDER(v))}catch(ne){if(!(ne instanceof me.Err))throw ne}!O&&D!=="der"&&(O=d.fromCompact(v))}j=a.fromHex(w)}catch{return!1}if(!O||C&&O.hasHighS())return!1;P&&(L=t.hash(L));let{r:Q,s:lt}=O,ft=N(L),mt=c(lt),yt=s(ft*mt),Ct=s(Q*mt),St=a.BASE.multiplyAndAddUnsafe(j,yt,Ct)?.toAffine();return St?s(St.x)===Q:!1}return{CURVE:t,getPublicKey:A,getSharedSecret:_,sign:z,verify:ct,ProjectivePoint:a,Signature:d,utils:E}}function y0(r){return{hash:r,hmac:(t,...e)=>Ss(r,t,rs(...e)),randomBytes:bo}}function fl(r,t){let e=n=>ll({...r,...y0(n)});return{...e(t),create:e}}var pl=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),dl=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),x0=BigInt(1),Bs=BigInt(2),hl=(r,t)=>(r+t/Bs)/t;function b0(r){let t=pl,e=BigInt(3),n=BigInt(6),o=BigInt(11),i=BigInt(22),s=BigInt(23),c=BigInt(44),a=BigInt(88),l=r*r*r%t,u=l*l*r%t,f=nt(u,e,t)*u%t,h=nt(f,e,t)*u%t,x=nt(h,Bs,t)*l%t,b=nt(x,o,t)*x%t,g=nt(b,i,t)*b%t,d=nt(g,c,t)*g%t,E=nt(d,a,t)*d%t,A=nt(E,c,t)*g%t,m=nt(A,e,t)*u%t,_=nt(m,s,t)*b%t,R=nt(_,n,t)*l%t,N=nt(R,Bs,t);if(!_s.eql(_s.sqr(N),r))throw new Error("Cannot find square root");return N}var _s=Ue(pl,void 0,void 0,{sqrt:b0}),je=fl({a:BigInt(0),b:BigInt(7),Fp:_s,n:dl,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let t=dl,e=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-x0*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),i=e,s=BigInt("0x100000000000000000000000000000000"),c=hl(i*r,t),a=hl(-n*r,t),l=Z(r-c*e-a*o,t),u=Z(-c*n-a*i,t),f=l>s,h=u>s;if(f&&(l=t-l),h&&(u=t-u),l>s||u>s)throw new Error("splitScalar: Endomorphism failed, k="+r);return{k1neg:f,k1:l,k2neg:h,k2:u}}}},cl),t3=BigInt(0);var e3=je.ProjectivePoint;function ml(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function gl(r,t,e){let n=Hr.digest(e instanceof Uint8Array?e:e.subarray());if(ml(n))return n.then(({digest:o})=>je.verify(t,o,r)).catch(o=>{throw new fn(String(o))});try{return je.verify(t,n.digest,r)}catch(o){throw new fn(String(o))}}var No=class{type="secp256k1";raw;_key;constructor(t){this._key=xl(t),this.raw=yl(this._key)}toMultihash(){return ce.digest(Uo(this))}toCID(){return at.createV1(114,this.toMultihash())}toString(){return tt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:Gt(this.raw,t.raw)}verify(t,e){return gl(this._key,e,t)}};function bl(r){return new No(r)}function yl(r){return je.ProjectivePoint.fromHex(r).toRawBytes(!0)}function xl(r){try{return je.ProjectivePoint.fromHex(r),r}catch(t){throw new yn(String(t))}}function wl(r){let{Type:t,Data:e}=ln.decode(r.digest),n=e??new Uint8Array;switch(t){case Ht.Ed25519:return sl(n);case Ht.secp256k1:return bl(n);default:throw new Ir}}function Uo(r){return ln.encode({Type:Ht[r.type],Data:r.raw})}var El=Symbol.for("nodejs.util.inspect.custom"),w0=114,dn=class{type;multihash;publicKey;string;constructor(t){this.type=t.type,this.multihash=t.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[mn]=!0;toString(){return this.string==null&&(this.string=tt.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return at.createV1(w0,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return Gt(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return Gt(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[El](){return`PeerId(${this.toString()})`}},Ro=class extends dn{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},Po=class extends dn{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},Do=class extends dn{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},E0=2336,hn=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=ce.digest(ae(this.url))}[El](){return`PeerId(${this.url})`}[mn]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return at.createV1(E0,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=st(t)),t.toString()===this.toString())}};var v0=114,vl=2336;function Sl(r,t){let e;if(r.charAt(0)==="1"||r.charAt(0)==="Q")e=se(tt.decode(`z${r}`));else{if(r.startsWith("k51qzi5uqu5")||r.startsWith("kzwfwjn5ji4")||r.startsWith("k2k4r8")||r.startsWith("bafz"))return S0(at.parse(r));if(t==null)throw new ye('Please pass a multibase decoder for strings that do not start with "1" or "Q"');e=se(t.decode(r))}return Mo(e)}function Mo(r){if(B0(r))return new Ro({multihash:r});if(A0(r))try{let t=wl(r);if(t.type==="Ed25519")return new Po({multihash:r,publicKey:t});if(t.type==="secp256k1")return new Do({multihash:r,publicKey:t})}catch{let e=st(r.digest);return new hn(new URL(e))}throw new bn("Supplied PeerID Multihash is invalid")}function S0(r){if(r?.multihash==null||r.version==null||r.version===1&&r.code!==v0&&r.code!==vl)throw new xn("Supplied PeerID CID is invalid");if(r.code===vl){let t=st(r.multihash.digest);return new hn(new URL(t))}return Mo(r.multihash)}function A0(r){return r.code===ce.code}function B0(r){return r.code===Hr.code}var Al={type:4098,canEncode:r=>Os(r),encode:r=>r.toMultihash().bytes,decode:r=>Mo(se(r))};var Is=[wu,Pu,Al,Eu];function Oo(r){let t={},e=r.components??r;return Object.entries(e).forEach(([n,o])=>{o?.[xe]!=null&&Array.isArray(o[xe])&&(t[n]=o[xe])}),t}function Sr(r,t){let e={};for(let[n,o]of r.entries())e[n]=t(o);return e}async function Fo(r,t){let e=[],n=r.connectionManager.getConnectionsMap(),o=[...n.values()].flatMap(i=>i).map(i=>i.remoteAddr.toString());for(let[i,s]of n.entries())try{let c=await r.peerStore.get(i);e.push({id:i,addresses:c.addresses.map(({isCertified:a,multiaddr:l})=>({multiaddr:l,isCertified:a,isConnected:o.includes(l.toString())})),protocols:[...c.protocols],tags:Sr(c.tags,a=>a.value),metadata:Sr(c.metadata,a=>te.encode(a))})}catch(c){t.error("could not load peer data from peer store",c),e.push({id:i,addresses:s.map(a=>({multiaddr:a.remoteAddr,isConnected:o.includes(a.remoteAddr.toString())})),protocols:[],tags:{},metadata:{}})}return e}function Ar(r,t){let e=t[r];if(!gn(e))throw new ye(`Component ${r} did not implement the PubSub interface`);return e}async function Vo(r){let t=await r.peerStore.get(r.peerId);return{id:t.id,addresses:t.addresses,protocols:[...t.protocols],tags:Sr(t.tags,e=>e.value),metadata:Sr(t.metadata,e=>te.encode(e))}}function Bl(r){let t=r.logger.forComponent("libp2p:devtools-metrics:metrics-rpc");return{init:async()=>({self:await Vo(r),peers:await Fo(r,t),debug:localStorage.getItem("debug")??"",capabilities:Oo(r)}),setDebug:async e=>{e?.length!=null&&e?.length>0?(Js(e),localStorage.setItem("debug",e)):(Qs(),localStorage.removeItem("debug"))},openConnection:async(e,n)=>{let o;try{o=Sl(e)}catch{o=Ve(e)}await r.connectionManager.openConnection(o,n)},closeConnection:async(e,n)=>{await Promise.all(r.connectionManager.getConnections(e).map(async o=>{try{await o.close(n)}catch(i){o.abort(i)}}))},contentRouting:r.contentRouting,peerRouting:r.peerRouting,pubsub:{async getTopics(e){return Ar(e,r).getTopics()},async subscribe(e,n){Ar(e,r).subscribe(n)},async unsubscribe(e,n){Ar(e,r).unsubscribe(n)},async publish(e,n,o){await Ar(e,r).publish(n,o)},async getSubscribers(e,n){return Ar(e,r).getSubscribers(n)}}}}function Cs(r,t=100){let e,n;return()=>{if(n==null&&(n=Date.now()),e!=null&&Date.now()-n>t){clearTimeout(e),n=void 0,r();return}clearTimeout(e),e=setTimeout(()=>{n=void 0,r()},t)}}function _l(r,t){for(let[e,n]of Object.entries(Oo(t)))if(n.includes(r))return t[e]}var Il="@libp2p/devtools-metrics:devtools",_0="@libp2p/devtools-metrics:worker",I0="@libp2p/devtools-metrics:content",Cl="@libp2p/devtools-metrics:metrics",Tl="________libp2p_devtools_metrics";Object.defineProperty(globalThis,Tl,{value:!0,enumerable:!1,writable:!1});var Ts=class{log;components;simpleMetrics;intervalMs;rpcQueue;rpc;devTools;constructor(t,e){this.log=t.logger.forComponent("libp2p:devtools-metrics"),this.intervalMs=e?.intervalMs,this.components=t,this.rpcQueue=Qe(),this.rpc=bu({valueCodecs:Is}),this.devTools=this.rpc.createClient("devTools"),this.onPeersUpdate=Cs(this.onPeersUpdate.bind(this),1e3),this.onSelfUpdate=Cs(this.onSelfUpdate.bind(this),1e3),this.onIncomingMessage=this.onIncomingMessage.bind(this),this.onPubSubMessage=this.onPubSubMessage.bind(this),this.onPubSubSubscriptionChange=this.onPubSubSubscriptionChange.bind(this),this.simpleMetrics=pc({intervalMs:this.intervalMs,onMetrics:n=>{this.devTools.safeDispatchEvent("metrics",{detail:n}).catch(o=>{this.log.error("error sending metrics",o)})}})({})}[Symbol.toStringTag]="@libp2p/devtools-metrics";[xe]=["@libp2p/metrics"];trackMultiaddrConnection(t){this.simpleMetrics.trackMultiaddrConnection(t)}trackProtocolStream(t,e){this.simpleMetrics.trackProtocolStream(t,e)}registerMetric(t,e){return this.simpleMetrics.registerMetric(t,e)}registerMetricGroup(t,e){return this.simpleMetrics.registerMetricGroup(t,e)}registerCounter(t,e){return this.simpleMetrics.registerCounter(t,e)}registerCounterGroup(t,e){return this.simpleMetrics.registerCounterGroup(t,e)}registerHistogram(t,e){return this.simpleMetrics.registerHistogram(t,e)}registerHistogramGroup(t,e){return this.simpleMetrics.registerHistogramGroup(t,e)}registerSummary(t,e){return this.simpleMetrics.registerSummary(t,e)}registerSummaryGroup(t,e){return this.simpleMetrics.registerSummaryGroup(t,e)}createTrace(){return this.simpleMetrics.createTrace()}traceFunction(t,e,n){return this.simpleMetrics.traceFunction(t,e,n)}async start(){this.components.events.addEventListener("peer:connect",this.onPeersUpdate),this.components.events.addEventListener("peer:disconnect",this.onPeersUpdate),this.components.events.addEventListener("peer:identify",this.onPeersUpdate),this.components.events.addEventListener("peer:update",this.onPeersUpdate),this.components.events.addEventListener("self:peer:update",this.onSelfUpdate),window.addEventListener("message",this.onIncomingMessage),this.rpc.createTarget("metrics",Bl(this.components)),await zs(this.simpleMetrics),Promise.resolve().then(async()=>{await xc(this.rpcQueue,this.rpc,async e=>{for await(let n of e)window.postMessage({source:Cl,type:"libp2p-rpc",message:te.encode(n)})})}).catch(e=>{this.log.error("error while reading RPC messages",e)});let t=_l("@libp2p/pubsub",this.components);gn(t)&&(t.addEventListener("message",this.onPubSubMessage),t.addEventListener("subscription-change",this.onPubSubSubscriptionChange))}async stop(){window.removeEventListener("message",this.onIncomingMessage),this.components.events.removeEventListener("self:peer:update",this.onSelfUpdate),this.components.events.removeEventListener("peer:connect",this.onPeersUpdate),this.components.events.removeEventListener("peer:disconnect",this.onPeersUpdate),this.components.events.removeEventListener("peer:identify",this.onPeersUpdate),this.components.events.removeEventListener("peer:update",this.onPeersUpdate),await Hs(this.simpleMetrics)}onIncomingMessage(t){if(t.source!==window)return;let e=t.data;e?.source===Il&&e.type==="libp2p-rpc"&&this.rpcQueue.push(te.decode(e.message))}onPubSubMessage(t){this.devTools.safeDispatchEvent("pubsub:message",{detail:t.detail}).catch(e=>{this.log.error("error relaying pubsub message",e)})}onPubSubSubscriptionChange(t){this.devTools.safeDispatchEvent("pubsub:subscription-change",{detail:t.detail}).catch(e=>{this.log.error("error relaying pubsub subscription change",e)})}onSelfUpdate(){Promise.resolve().then(async()=>{await this.devTools.safeDispatchEvent("self",{detail:await Vo(this.components)})}).catch(t=>{this.log.error("error sending peers message",t)})}onPeersUpdate(){Promise.resolve().then(async()=>{await this.devTools.safeDispatchEvent("peers",{detail:await Fo(this.components,this.log)})}).catch(t=>{this.log.error("error sending peers message",t)})}};function C0(r){return t=>new Ts(t,r)}return Kl(T0);})();
2
+ "use strict";var Libp2PDevtoolsMetrics=(()=>{var Rl=Object.create;var pn=Object.defineProperty;var Pl=Object.getOwnPropertyDescriptor;var Dl=Object.getOwnPropertyNames;var Ml=Object.getPrototypeOf,Ol=Object.prototype.hasOwnProperty;var Ir=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),Ct=(r,t)=>{for(var e in t)pn(r,e,{get:t[e],enumerable:!0})},Ps=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Dl(t))!Ol.call(r,o)&&o!==e&&pn(r,o,{get:()=>t[o],enumerable:!(n=Pl(t,o))||n.enumerable});return r};var Fl=(r,t,e)=>(e=r!=null?Rl(Ml(r)):{},Ps(t||!r||!r.__esModule?pn(e,"default",{value:r,enumerable:!0}):e,r)),Vl=r=>Ps(pn({},"__esModule",{value:!0}),r);var Xo=Ir((Am,tc)=>{function qt(){}qt.prototype.clear=function(){this._root=null,this.size=0};qt.prototype.find=function(r){for(var t=this._root;t!==null;){var e=this._comparator(r,t.data);if(e===0)return t.data;t=t.get_child(e>0)}return null};qt.prototype.findIter=function(r){for(var t=this._root,e=this.iterator();t!==null;){var n=this._comparator(r,t.data);if(n===0)return e._cursor=t,e;e._ancestors.push(t),t=t.get_child(n>0)}return null};qt.prototype.lowerBound=function(r){for(var t=this._root,e=this.iterator(),n=this._comparator;t!==null;){var o=n(r,t.data);if(o===0)return e._cursor=t,e;e._ancestors.push(t),t=t.get_child(o>0)}for(var i=e._ancestors.length-1;i>=0;--i)if(t=e._ancestors[i],n(r,t.data)<0)return e._cursor=t,e._ancestors.length=i,e;return e._ancestors.length=0,e};qt.prototype.upperBound=function(r){for(var t=this.lowerBound(r),e=this._comparator;t.data()!==null&&e(t.data(),r)===0;)t.next();return t};qt.prototype.min=function(){var r=this._root;if(r===null)return null;for(;r.left!==null;)r=r.left;return r.data};qt.prototype.max=function(){var r=this._root;if(r===null)return null;for(;r.right!==null;)r=r.right;return r.data};qt.prototype.iterator=function(){return new Xe(this)};qt.prototype.each=function(r){for(var t=this.iterator(),e;(e=t.next())!==null;)if(r(e)===!1)return};qt.prototype.reach=function(r){for(var t=this.iterator(),e;(e=t.prev())!==null;)if(r(e)===!1)return};function Xe(r){this._tree=r,this._ancestors=[],this._cursor=null}Xe.prototype.data=function(){return this._cursor!==null?this._cursor.data:null};Xe.prototype.next=function(){if(this._cursor===null){var r=this._tree._root;r!==null&&this._minNode(r)}else if(this._cursor.right===null){var t;do if(t=this._cursor,this._ancestors.length)this._cursor=this._ancestors.pop();else{this._cursor=null;break}while(this._cursor.right===t)}else this._ancestors.push(this._cursor),this._minNode(this._cursor.right);return this._cursor!==null?this._cursor.data:null};Xe.prototype.prev=function(){if(this._cursor===null){var r=this._tree._root;r!==null&&this._maxNode(r)}else if(this._cursor.left===null){var t;do if(t=this._cursor,this._ancestors.length)this._cursor=this._ancestors.pop();else{this._cursor=null;break}while(this._cursor.left===t)}else this._ancestors.push(this._cursor),this._maxNode(this._cursor.left);return this._cursor!==null?this._cursor.data:null};Xe.prototype._minNode=function(r){for(;r.left!==null;)this._ancestors.push(r),r=r.left;this._cursor=r};Xe.prototype._maxNode=function(r){for(;r.right!==null;)this._ancestors.push(r),r=r.right;this._cursor=r};tc.exports=qt});var nc=Ir((Bm,rc)=>{var Sf=Xo();function Ye(r){this.data=r,this.left=null,this.right=null,this.red=!0}Ye.prototype.get_child=function(r){return r?this.right:this.left};Ye.prototype.set_child=function(r,t){r?this.right=t:this.left=t};function Sn(r){this._root=null,this._comparator=r,this.size=0}Sn.prototype=new Sf;Sn.prototype.insert=function(r){var t=!1;if(this._root===null)this._root=new Ye(r),t=!0,this.size++;else{var e=new Ye(void 0),n=0,o=0,i=null,s=e,c=null,a=this._root;for(s.right=this._root;;){if(a===null?(a=new Ye(r),c.set_child(n,a),t=!0,this.size++):Ot(a.left)&&Ot(a.right)&&(a.red=!0,a.left.red=!1,a.right.red=!1),Ot(a)&&Ot(c)){var l=s.right===i;a===c.get_child(o)?s.set_child(l,Cr(i,!o)):s.set_child(l,ec(i,!o))}var u=this._comparator(a.data,r);if(u===0)break;o=n,n=u<0,i!==null&&(s=i),i=c,c=a,a=a.get_child(n)}this._root=e.right}return this._root.red=!1,t};Sn.prototype.remove=function(r){if(this._root===null)return!1;var t=new Ye(void 0),e=t;e.right=this._root;for(var n=null,o=null,i=null,s=1;e.get_child(s)!==null;){var c=s;o=n,n=e,e=e.get_child(s);var a=this._comparator(r,e.data);if(s=a>0,a===0&&(i=e),!Ot(e)&&!Ot(e.get_child(s))){if(Ot(e.get_child(!s))){var l=Cr(e,s);n.set_child(c,l),n=l}else if(!Ot(e.get_child(!s))){var u=n.get_child(!c);if(u!==null)if(!Ot(u.get_child(!c))&&!Ot(u.get_child(c)))n.red=!1,u.red=!0,e.red=!0;else{var f=o.right===n;Ot(u.get_child(c))?o.set_child(f,ec(n,c)):Ot(u.get_child(!c))&&o.set_child(f,Cr(n,c));var h=o.get_child(f);h.red=!0,e.red=!0,h.left.red=!1,h.right.red=!1}}}}return i!==null&&(i.data=e.data,n.set_child(n.right===e,e.get_child(e.left===null)),this.size--),this._root=t.right,this._root!==null&&(this._root.red=!1),i!==null};function Ot(r){return r!==null&&r.red}function Cr(r,t){var e=r.get_child(!t);return r.set_child(!t,e.get_child(t)),e.set_child(t,r),r.red=!0,e.red=!1,e}function ec(r,t){return r.set_child(!t,Cr(r.get_child(!t),!t)),Cr(r,t)}rc.exports=Sn});var ic=Ir((Im,oc)=>{var Af=Xo();function Tr(r){this.data=r,this.left=null,this.right=null}Tr.prototype.get_child=function(r){return r?this.right:this.left};Tr.prototype.set_child=function(r,t){r?this.right=t:this.left=t};function An(r){this._root=null,this._comparator=r,this.size=0}An.prototype=new Af;An.prototype.insert=function(r){if(this._root===null)return this._root=new Tr(r),this.size++,!0;for(var t=0,e=null,n=this._root;;){if(n===null)return n=new Tr(r),e.set_child(t,n),ret=!0,this.size++,!0;if(this._comparator(n.data,r)===0)return!1;t=this._comparator(n.data,r)<0,e=n,n=n.get_child(t)}};An.prototype.remove=function(r){if(this._root===null)return!1;var t=new Tr(void 0),e=t;e.right=this._root;for(var n=null,o=null,i=1;e.get_child(i)!==null;){n=e,e=e.get_child(i);var s=this._comparator(r,e.data);i=s>0,s===0&&(o=e)}return o!==null?(o.data=e.data,n.set_child(n.right===e,e.get_child(e.left===null)),this._root=t.right,this.size--,!0):!1};oc.exports=An});var cc=Ir((_m,sc)=>{sc.exports={RBTree:nc(),BinTree:ic()}});var lc=Ir((Cm,uc)=>{var Bf=cc().RBTree;function et(r,t,e){this.discrete=r===!1,this.delta=r||.01,this.K=t===void 0?25:t,this.CX=e===void 0?1.1:e,this.centroids=new Bf(ac),this.nreset=0,this.reset()}et.prototype.reset=function(){this.centroids.clear(),this.n=0,this.nreset+=1,this.last_cumulate=0};et.prototype.size=function(){return this.centroids.size};et.prototype.toArray=function(r){var t=[];return r?(this._cumulate(!0),this.centroids.each(function(e){t.push(e)})):this.centroids.each(function(e){t.push({mean:e.mean,n:e.n})}),t};et.prototype.summary=function(){var r=this.discrete?"exact ":"approximating ",t=[r+this.n+" samples using "+this.size()+" centroids","min = "+this.percentile(0),"Q1 = "+this.percentile(.25),"Q2 = "+this.percentile(.5),"Q3 = "+this.percentile(.75),"max = "+this.percentile(1)];return t.join(`
3
+ `)};function ac(r,t){return r.mean>t.mean?1:r.mean<t.mean?-1:0}function If(r,t){return r.mean_cumn-t.mean_cumn}et.prototype.push=function(r,t){t=t||1,r=Array.isArray(r)?r:[r];for(var e=0;e<r.length;e++)this._digest(r[e],t)};et.prototype.push_centroid=function(r){r=Array.isArray(r)?r:[r];for(var t=0;t<r.length;t++)this._digest(r[t].mean,r[t].n)};et.prototype._cumulate=function(r){if(!(this.n===this.last_cumulate||!r&&this.CX&&this.CX>this.n/this.last_cumulate)){var t=0;this.centroids.each(function(e){e.mean_cumn=t+e.n/2,t=e.cumn=t+e.n}),this.n=this.last_cumulate=t}};et.prototype.find_nearest=function(r){if(this.size()===0)return null;var t=this.centroids.lowerBound({mean:r}),e=t.data()===null?t.prev():t.data();if(e.mean===r||this.discrete)return e;var n=t.prev();return n&&Math.abs(n.mean-r)<Math.abs(e.mean-r)?n:e};et.prototype._new_centroid=function(r,t,e){var n={mean:r,n:t,cumn:e};return this.centroids.insert(n),this.n+=t,n};et.prototype._addweight=function(r,t,e){t!==r.mean&&(r.mean+=e*(t-r.mean)/(r.n+e)),r.cumn+=e,r.mean_cumn+=e/2,r.n+=e,this.n+=e};et.prototype._digest=function(r,t){var e=this.centroids.min(),n=this.centroids.max(),o=this.find_nearest(r);if(o&&o.mean===r)this._addweight(o,r,t);else if(o===e)this._new_centroid(r,t,0);else if(o===n)this._new_centroid(r,t,this.n);else if(this.discrete)this._new_centroid(r,t,o.cumn);else{var i=o.mean_cumn/this.n,s=Math.floor(4*this.n*this.delta*i*(1-i));s-o.n>=t?this._addweight(o,r,t):this._new_centroid(r,t,o.cumn)}this._cumulate(!1),!this.discrete&&this.K&&this.size()>this.K/this.delta&&this.compress()};et.prototype.bound_mean=function(r){var t=this.centroids.upperBound({mean:r}),e=t.prev(),n=e.mean===r?e:t.next();return[e,n]};et.prototype.p_rank=function(r){var t=Array.isArray(r)?r:[r],e=t.map(this._p_rank,this);return Array.isArray(r)?e:e[0]};et.prototype._p_rank=function(r){if(this.size()!==0){{if(r<this.centroids.min().mean)return 0;if(r>this.centroids.max().mean)return 1}this._cumulate(!0);var t=this.bound_mean(r),e=t[0],n=t[1];if(this.discrete)return e.cumn/this.n;var o=e.mean_cumn;return e!==n&&(o+=(r-e.mean)*(n.mean_cumn-e.mean_cumn)/(n.mean-e.mean)),o/this.n}};et.prototype.bound_mean_cumn=function(r){this.centroids._comparator=If;var t=this.centroids.upperBound({mean_cumn:r});this.centroids._comparator=ac;var e=t.prev(),n=e&&e.mean_cumn===r?e:t.next();return[e,n]};et.prototype.percentile=function(r){var t=Array.isArray(r)?r:[r],e=t.map(this._percentile,this);return Array.isArray(r)?e:e[0]};et.prototype._percentile=function(r){if(this.size()!==0){this._cumulate(!0);var t=this.n*r,e=this.bound_mean_cumn(t),n=e[0],o=e[1];return o===n||n===null||o===null?(n||o).mean:this.discrete?t<=n.cumn?n.mean:o.mean:n.mean+(t-n.mean_cumn)*(o.mean-n.mean)/(o.mean_cumn-n.mean_cumn)}};function _f(r){var t=Math.floor(Math.random()*r.length);return r.splice(t,1)[0]}et.prototype.compress=function(){if(!this.compressing){var r=this.toArray();for(this.reset(),this.compressing=!0;r.length>0;)this.push_centroid(_f(r));this._cumulate(!0),this.compressing=!1}};function we(r){this.config=r||{},this.mode=this.config.mode||"auto",et.call(this,this.mode==="cont"?r.delta:!1),this.digest_ratio=this.config.ratio||.9,this.digest_thresh=this.config.thresh||1e3,this.n_unique=0}we.prototype=Object.create(et.prototype);we.prototype.constructor=we;we.prototype.push=function(r){et.prototype.push.call(this,r),this.check_continuous()};we.prototype._new_centroid=function(r,t,e){this.n_unique+=1,et.prototype._new_centroid.call(this,r,t,e)};we.prototype._addweight=function(r,t,e){r.n===1&&(this.n_unique-=1),et.prototype._addweight.call(this,r,t,e)};we.prototype.check_continuous=function(){return this.mode!=="auto"||this.size()<this.digest_thresh?!1:this.n_unique/this.size()>this.digest_ratio?(this.mode="cont",this.discrete=!1,this.delta=this.config.delta||.01,this.compress(),!0):!1};uc.exports={TDigest:et,Digest:we}});var B0={};Ct(B0,{LIBP2P_DEVTOOLS_METRICS_KEY:()=>Bl,SOURCE_CONTENT_SCRIPT:()=>S0,SOURCE_DEVTOOLS:()=>Sl,SOURCE_METRICS:()=>Al,SOURCE_SERVICE_WORKER:()=>v0,devToolsMetrics:()=>A0,valueCodecs:()=>Bs});var mn=Symbol.for("@libp2p/peer-id");function Ds(r){return!!r?.[mn]}var Ms;(function(r){r.Accept="accept",r.Ignore="ignore",r.Reject="reject"})(Ms||(Ms={}));var zl=Symbol.for("@libp2p/pubsub");function gn(r){return!!r?.[zl]}var ye=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},yn=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var bn=class extends Error{static name="InvalidCIDError";constructor(t="Invalid CID"){super(t),this.name="InvalidCIDError"}},xn=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var _r=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};function Os(r){return r!=null&&typeof r.start=="function"&&typeof r.stop=="function"}async function Fs(...r){let t=[];for(let e of r)Os(e)&&t.push(e);await Promise.all(t.map(async e=>{e.beforeStart!=null&&await e.beforeStart()})),await Promise.all(t.map(async e=>{await e.start()})),await Promise.all(t.map(async e=>{e.afterStart!=null&&await e.afterStart()}))}async function Vs(...r){let t=[];for(let e of r)Os(e)&&t.push(e);await Promise.all(t.map(async e=>{e.beforeStop!=null&&await e.beforeStop()})),await Promise.all(t.map(async e=>{await e.stop()})),await Promise.all(t.map(async e=>{e.afterStop!=null&&await e.afterStop()}))}var be=Symbol.for("@libp2p/service-capabilities"),U0=Symbol.for("@libp2p/service-dependencies");var $o={};Ct($o,{base32:()=>Ht,base32hex:()=>Xl,base32hexpad:()=>Ql,base32hexpadupper:()=>Jl,base32hexupper:()=>Yl,base32pad:()=>Zl,base32padupper:()=>Wl,base32upper:()=>jl,base32z:()=>tf});var tm=new Uint8Array(0);function zs(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 oe(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 Hs(r){return new TextEncoder().encode(r)}function qs(r){return new TextDecoder().decode(r)}function Hl(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 c=r.length,a=r.charAt(0),l=Math.log(c)/Math.log(256),u=Math.log(256)/Math.log(c);function f(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 g=0,d=0,E=0,A=x.length;E!==A&&x[E]===0;)E++,g++;for(var m=(A-E)*u+1>>>0,I=new Uint8Array(m);E!==A;){for(var R=x[E],N=0,T=m-1;(R!==0||N<d)&&T!==-1;T--,N++)R+=256*I[T]>>>0,I[T]=R%c>>>0,R=R/c>>>0;if(R!==0)throw new Error("Non-zero carry");d=N,E++}for(var U=m-d;U!==m&&I[U]===0;)U++;for(var k=a.repeat(g);U<m;++U)k+=r.charAt(I[U]);return k}function h(x){if(typeof x!="string")throw new TypeError("Expected String");if(x.length===0)return new Uint8Array;var g=0;if(x[g]!==" "){for(var d=0,E=0;x[g]===a;)d++,g++;for(var A=(x.length-g)*l+1>>>0,m=new Uint8Array(A);x[g];){var I=e[x.charCodeAt(g)];if(I===255)return;for(var R=0,N=A-1;(I!==0||R<E)&&N!==-1;N--,R++)I+=c*m[N]>>>0,m[N]=I%256>>>0,I=I/256>>>0;if(I!==0)throw new Error("Non-zero carry");E=R,g++}if(x[g]!==" "){for(var T=A-E;T!==A&&m[T]===0;)T++;for(var U=new Uint8Array(d+(A-T)),k=d;T!==A;)U[k++]=m[T++];return U}}}function b(x){var g=h(x);if(g)return g;throw new Error(`Non-${t} character`)}return{encode:f,decodeUnsafe:h,decode:b}}var ql=Hl,Kl=ql,$s=Kl;var zo=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")}},Ho=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 Gs(this,t)}},qo=class{decoders;constructor(t){this.decoders=t}or(t){return Gs(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 Gs(r,t){return new qo({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var Ko=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 zo(t,e,n),this.decoder=new Ho(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function We({name:r,prefix:t,encode:e,decode:n}){return new Ko(r,t,e,n)}function xe({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=$s(e,r);return We({prefix:t,name:r,encode:n,decode:i=>oe(o(i))})}function $l(r,t,e,n){let o={};for(let u=0;u<t.length;++u)o[t[u]]=u;let i=r.length;for(;r[i-1]==="=";)--i;let s=new Uint8Array(i*e/8|0),c=0,a=0,l=0;for(let u=0;u<i;++u){let f=o[r[u]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<e|f,c+=e,c>=8&&(c-=8,s[l++]=255&a>>c)}if(c>=e||(255&a<<8-c)!==0)throw new SyntaxError("Unexpected end of data");return s}function Gl(r,t,e){let n=t[t.length-1]==="=",o=(1<<e)-1,i="",s=0,c=0;for(let a=0;a<r.length;++a)for(c=c<<8|r[a],s+=8;s>e;)s-=e,i+=t[o&c>>s];if(s!==0&&(i+=t[o&c<<e-s]),n)for(;(i.length*e&7)!==0;)i+="=";return i}function it({name:r,prefix:t,bitsPerChar:e,alphabet:n}){return We({prefix:t,name:r,encode(o){return Gl(o,n,e)},decode(o){return $l(o,n,e,r)}})}var Ht=it({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),jl=it({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Zl=it({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Wl=it({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Xl=it({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Yl=it({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Ql=it({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Jl=it({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),tf=it({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Go={};Ct(Go,{base58btc:()=>tt,base58flickr:()=>ef});var tt=xe({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),ef=xe({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var jo={};Ct(jo,{base64:()=>te,base64pad:()=>rf,base64url:()=>nf,base64urlpad:()=>of});var te=it({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),rf=it({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),nf=it({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),of=it({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});function sf(r,t){try{if(typeof r=="string"&&r.length>0)return cf(r);if(typeof r=="number"&&isFinite(r))return t?.long?uf(r):af(r);throw new Error("Value is not a string or number.")}catch(e){let n=lf(e)?`${e.message}. value=${JSON.stringify(r)}`:"An unknown error has occured.";throw new Error(n)}}function cf(r){if(r=String(r),r.length>100)throw new Error("Value exceeds the maximum length of 100 characters.");let t=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(r);if(!t)return NaN;let e=parseFloat(t[1]),n=(t[2]||"ms").toLowerCase();switch(n){case"years":case"year":case"yrs":case"yr":case"y":return e*315576e5;case"weeks":case"week":case"w":return e*6048e5;case"days":case"day":case"d":return e*864e5;case"hours":case"hour":case"hrs":case"hr":case"h":return e*36e5;case"minutes":case"minute":case"mins":case"min":case"m":return e*6e4;case"seconds":case"second":case"secs":case"sec":case"s":return e*1e3;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return e;default:throw new Error(`The unit ${n} was matched, but no matching case exists.`)}}var En=sf;function af(r){let t=Math.abs(r);return t>=864e5?`${Math.round(r/864e5)}d`:t>=36e5?`${Math.round(r/36e5)}h`:t>=6e4?`${Math.round(r/6e4)}m`:t>=1e3?`${Math.round(r/1e3)}s`:`${r}ms`}function uf(r){let t=Math.abs(r);return t>=864e5?wn(r,t,864e5,"day"):t>=36e5?wn(r,t,36e5,"hour"):t>=6e4?wn(r,t,6e4,"minute"):t>=1e3?wn(r,t,1e3,"second"):`${r} ms`}function wn(r,t,e,n){let o=t>=e*1.5;return`${Math.round(r/e)} ${n}${o?"s":""}`}function lf(r){return typeof r=="object"&&r!==null&&"message"in r}function Zo(r){e.debug=e,e.default=e,e.coerce=a,e.disable=i,e.enable=o,e.enabled=s,e.humanize=En,e.destroy=l,Object.keys(r).forEach(u=>{e[u]=r[u]}),e.names=[],e.skips=[],e.formatters={};function t(u){let f=0;for(let h=0;h<u.length;h++)f=(f<<5)-f+u.charCodeAt(h),f|=0;return e.colors[Math.abs(f)%e.colors.length]}e.selectColor=t;function e(u){let f,h=null,b,x;function g(...d){if(!g.enabled)return;let E=g,A=Number(new Date),m=A-(f||A);E.diff=m,E.prev=f,E.curr=A,f=A,d[0]=e.coerce(d[0]),typeof d[0]!="string"&&d.unshift("%O");let I=0;d[0]=d[0].replace(/%([a-zA-Z%])/g,(N,T)=>{if(N==="%%")return"%";I++;let U=e.formatters[T];if(typeof U=="function"){let k=d[I];N=U.call(E,k),d.splice(I,1),I--}return N}),e.formatArgs.call(E,d),(E.log||e.log).apply(E,d)}return g.namespace=u,g.useColors=e.useColors(),g.color=e.selectColor(u),g.extend=n,g.destroy=e.destroy,Object.defineProperty(g,"enabled",{enumerable:!0,configurable:!1,get:()=>h!==null?h:(b!==e.namespaces&&(b=e.namespaces,x=e.enabled(u)),x),set:d=>{h=d}}),typeof e.init=="function"&&e.init(g),g}function n(u,f){let h=e(this.namespace+(typeof f>"u"?":":f)+u);return h.log=this.log,h}function o(u){e.save(u),e.namespaces=u,e.names=[],e.skips=[];let f,h=(typeof u=="string"?u:"").split(/[\s,]+/),b=h.length;for(f=0;f<b;f++)h[f]&&(u=h[f].replace(/\*/g,".*?"),u[0]==="-"?e.skips.push(new RegExp("^"+u.substr(1)+"$")):e.names.push(new RegExp("^"+u+"$")))}function i(){let u=[...e.names.map(c),...e.skips.map(c).map(f=>"-"+f)].join(",");return e.enable(""),u}function s(u){if(u[u.length-1]==="*")return!0;let f,h;for(f=0,h=e.skips.length;f<h;f++)if(e.skips[f].test(u))return!1;for(f=0,h=e.names.length;f<h;f++)if(e.names[f].test(u))return!0;return!1}function c(u){return u.toString().substring(2,u.toString().length-2).replace(/\.\*\?$/,"*")}function a(u){return u instanceof Error?u.stack??u.message:u}function l(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")}return e.setupFormatters(e.formatters),e.enable(e.load()),e}var vn=yf(),ff=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"];function df(){return typeof window<"u"&&window.process&&(window.process.type==="renderer"||window.process.__nwjs)?!0:typeof navigator<"u"&&navigator.userAgent?.toLowerCase().match(/(edge|trident)\/(\d+)/)!=null?!1:typeof document<"u"&&document.documentElement?.style?.WebkitAppearance||typeof window<"u"&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator<"u"&&navigator.userAgent?.toLowerCase().match(/firefox\/(\d+)/)!=null&&parseInt(RegExp.$1,10)>=31||typeof navigator<"u"&&navigator.userAgent?.toLowerCase().match(/applewebkit\/(\d+)/)}function hf(r){if(r[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+r[0]+(this.useColors?"%c ":" ")+"+"+En(this.diff),!this.useColors)return;let t="color: "+this.color;r.splice(1,0,t,"color: inherit");let e=0,n=0;r[0].replace(/%[a-zA-Z%]/g,o=>{o!=="%%"&&(e++,o==="%c"&&(n=e))}),r.splice(n,0,t)}var pf=console.debug??console.log??(()=>{});function mf(r){try{r?vn?.setItem("debug",r):vn?.removeItem("debug")}catch{}}function gf(){let r;try{r=vn?.getItem("debug")}catch{}return!r&&typeof globalThis.process<"u"&&"env"in globalThis.process&&(r=globalThis.process.env.DEBUG),r}function yf(){try{return localStorage}catch{}}function bf(r){r.j=function(t){try{return JSON.stringify(t)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}}}var js=Zo({formatArgs:hf,save:mf,load:gf,useColors:df,setupFormatters:bf,colors:ff,storage:vn,log:pf});var bt=js;bt.formatters.b=r=>r==null?"undefined":tt.baseEncode(r);bt.formatters.t=r=>r==null?"undefined":Ht.baseEncode(r);bt.formatters.m=r=>r==null?"undefined":te.baseEncode(r);bt.formatters.p=r=>r==null?"undefined":r.toString();bt.formatters.c=r=>r==null?"undefined":r.toString();bt.formatters.k=r=>r==null?"undefined":r.toString();bt.formatters.a=r=>r==null?"undefined":r.toString();bt.formatters.e=r=>r==null?"undefined":Zs(r.stack)??Zs(r.message)??r.toString();function xf(r){let t=()=>{};return t.enabled=!1,t.color="",t.diff=0,t.log=()=>{},t.namespace=r,t.destroy=()=>!0,t.extend=()=>t,t}function Ws(r){let t=xf(`${r}:trace`);return bt.enabled(`${r}:trace`)&&bt.names.map(e=>e.toString()).find(e=>e.includes(":trace"))!=null&&(t=bt(`${r}:trace`)),Object.assign(bt(r),{error:bt(`${r}:error`),trace:t})}function Xs(){bt.disable()}function Ys(r){bt.enable(r)}function Zs(r){if(r!=null&&(r=r.trim(),r.length!==0))return r}function wf(r){let[t,e]=r[Symbol.asyncIterator]!=null?[r[Symbol.asyncIterator](),Symbol.asyncIterator]:[r[Symbol.iterator](),Symbol.iterator],n=[];return{peek:()=>t.next(),push:o=>{n.push(o)},next:()=>n.length>0?{done:!1,value:n.shift()}:t.next(),[e](){return this}}}var Qs=wf;function Ef(r){return r[Symbol.asyncIterator]!=null}function Js(r){return r?.then!=null}function vf(r,t){let e=0;if(Ef(r))return async function*(){for await(let a of r){let l=t(a,e++);Js(l)&&await l,yield a}}();let n=Qs(r),{value:o,done:i}=n.next();if(i===!0)return function*(){}();if(typeof t(o,e++)?.then=="function")return async function*(){yield o;for await(let a of n){let l=t(a,e++);Js(l)&&await l,yield a}}();let c=t;return function*(){yield o;for(let a of n)c(a,e++),yield a}()}var Wo=vf;var fc=Fl(lc(),1),Cf=Ws("libp2p:simple-metrics"),kr=class{value=0;update(t){this.value=t}increment(t=1){this.value+=t}decrement(t=1){this.value-=t}reset(){this.value=0}timer(){let t=Date.now();return()=>{this.value=Date.now()-t}}},Ur=class{values={};update(t){Object.entries(t).forEach(([e,n])=>{this.values[e]=n})}increment(t){Object.entries(t).forEach(([e,n])=>{this.values[e]=this.values[e]??0;let o=typeof n=="number"?n:1;this.values[e]+=Number(o)})}decrement(t){Object.entries(t).forEach(([e,n])=>{this.values[e]=this.values[e]??0;let o=typeof n=="number"?n:1;this.values[e]-=Number(o)})}reset(){this.values={}}timer(t){let e=Date.now();return()=>{this.values[t]=Date.now()-e}}},Lr=class{bucketValues=new Map;countValue=0;sumValue=0;constructor(t){let e=[...t.buckets??[.005,.01,.025,.05,.1,.25,.5,1,2.5,5,10],1/0];for(let n of e)this.bucketValues.set(n,0)}observe(t){this.countValue++,this.sumValue+=t;for(let[e,n]of this.bucketValues.entries())t<=e&&this.bucketValues.set(e,n+1)}reset(){this.countValue=0,this.sumValue=0;for(let t of this.bucketValues.keys())this.bucketValues.set(t,0)}timer(){let t=Date.now();return()=>{this.observe(Date.now()-t)}}},Bn=class{histograms={};constructor(t){this.histograms={}}observe(t){for(let[e,n]of Object.entries(t))this.histograms[e]===void 0&&(this.histograms[e]=new Lr({})),this.histograms[e].observe(n)}reset(){for(let t of Object.values(this.histograms))t.reset()}timer(t){let e=Date.now();return()=>{this.observe({[t]:Date.now()-e})}}},Nr=class{sumValue=0;countValue=0;percentiles;tdigest=new fc.TDigest(.01);compressCount;constructor(t){this.percentiles=t.percentiles??[.01,.05,.5,.9,.95,.99,.999],this.compressCount=t.compressCount??1e3}observe(t){this.sumValue+=t,this.countValue++,this.tdigest.push(t),this.tdigest.size()>this.compressCount&&this.tdigest.compress()}reset(){this.sumValue=0,this.countValue=0,this.tdigest.reset()}timer(){let t=Date.now();return()=>{this.observe(Date.now()-t)}}},In=class{summaries={};opts;constructor(t){this.summaries={},this.opts=t}observe(t){for(let[e,n]of Object.entries(t))this.summaries[e]===void 0&&(this.summaries[e]=new Nr(this.opts)),this.summaries[e].observe(n)}reset(){for(let t of Object.values(this.summaries))t.reset()}timer(t){let e=Date.now();return()=>{this.observe({[t]:Date.now()-e})}}},Yo=class{metrics=new Map;transferStats;started;interval;intervalMs;onMetrics;constructor(t,e){this.started=!1,this._emitMetrics=this._emitMetrics.bind(this),this.intervalMs=e.intervalMs??1e3,this.onMetrics=e.onMetrics,this.transferStats=new Map}[Symbol.toStringTag]="@libp2p/metrics-simple";[be]=["@libp2p/metrics"];isStarted(){return this.started}start(){this.started=!0,this.interval=setInterval(this._emitMetrics,this.intervalMs)}stop(){this.started=!1,clearInterval(this.interval)}_emitMetrics(){Promise.resolve().then(async()=>{let t={};for(let[e,n]of this.metrics.entries())n instanceof kr?t[e]=n.value:n instanceof Ur?t[e]=n.values:n instanceof Lr?t[e]={count:n.countValue,sum:n.sumValue,buckets:{...n.bucketValues}}:n instanceof Bn?t[e]={...Object.fromEntries(Object.entries(n.histograms).map(([o,i])=>[o,{count:i.countValue,sum:i.sumValue,buckets:{...i.bucketValues}}]))}:n instanceof Nr?t[e]={count:n.countValue,sum:n.sumValue,percentiles:Object.fromEntries(n.percentiles.map(o=>[o,n.tdigest.percentile(o)]))}:n instanceof In?t[e]={...Object.fromEntries(Object.entries(n.summaries).map(([o,i])=>[o,{count:i.countValue,sum:i.sumValue,percentiles:Object.fromEntries(i.percentiles.map(s=>[s,i.tdigest.percentile(s)]))}]))}:t[e]=await n();this.onMetrics(structuredClone(t))}).catch(t=>{Cf.error("could not invoke onMetrics callback",t)})}_incrementValue(t,e){let n=this.transferStats.get(t)??0;this.transferStats.set(t,n+e)}_track(t,e){let n=this,o=t.sink;t.sink=async function(c){await o(Wo(c,a=>{n._incrementValue(`${e} sent`,a.byteLength)}))};let i=t.source;t.source=Wo(i,s=>{n._incrementValue(`${e} received`,s.byteLength)})}trackMultiaddrConnection(t){this._track(t,"global")}trackProtocolStream(t,e){t.protocol!=null&&this._track(t,t.protocol)}registerMetric(t,e={}){if(t==null||t.trim()==="")throw new Error("Metric name is required");if(e?.calculate!=null){this.metrics.set(t,e.calculate);return}let n=new kr;return this.metrics.set(t,n),n}registerMetricGroup(t,e={}){if(t==null||t.trim()==="")throw new Error("Metric name is required");if(e?.calculate!=null){this.metrics.set(t,e.calculate);return}let n=new Ur;return this.metrics.set(t,n),n}registerCounter(t,e={}){if(t==null||t.trim()==="")throw new Error("Metric name is required");if(e?.calculate!=null){this.metrics.set(t,e.calculate);return}let n=new kr;return this.metrics.set(t,n),n}registerCounterGroup(t,e={}){if(t==null||t.trim()==="")throw new Error("Metric name is required");if(e?.calculate!=null){this.metrics.set(t,e.calculate);return}let n=new Ur;return this.metrics.set(t,n),n}registerHistogram(t,e={}){if(t==null||t.trim()==="")throw new Error("Metric name is required");if(e?.calculate!=null){this.metrics.set(t,e.calculate);return}let n=new Lr(e);return this.metrics.set(t,n),n}registerHistogramGroup(t,e={}){if(t==null||t.trim()==="")throw new Error("Metric name is required");if(e?.calculate!=null){this.metrics.set(t,e.calculate);return}let n=new Bn(e);return this.metrics.set(t,n),n}registerSummary(t,e={}){if(t==null||t.trim()==="")throw new Error("Metric name is required");if(e?.calculate!=null){this.metrics.set(t,e.calculate);return}let n=new Nr(e);return this.metrics.set(t,n),n}registerSummaryGroup(t,e={}){if(t==null||t.trim()==="")throw new Error("Metric name is required");if(e?.calculate!=null){this.metrics.set(t,e.calculate);return}let n=new In(e);return this.metrics.set(t,n),n}createTrace(){}traceFunction(t,e){return e}};function dc(r){return t=>new Yo(t,r)}function Kt(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var _n=class{buffer;mask;top;btm;next;constructor(t){if(!(t>0)||(t-1&t)!==0)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(t),this.mask=t-1,this.top=0,this.btm=0,this.next=null}push(t){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=t,this.top=this.top+1&this.mask,!0)}shift(){let t=this.buffer[this.btm];if(t!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,t}isEmpty(){return this.buffer[this.btm]===void 0}},Qe=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new _n(this.hwm),this.tail=this.head,this.size=0}calculateSize(t){return t?.byteLength!=null?t.byteLength:1}push(t){if(t?.value!=null&&(this.size+=this.calculateSize(t.value)),!this.head.push(t)){let e=this.head;this.head=e.next=new _n(2*this.head.buffer.length),this.head.push(t)}}shift(){let t=this.tail.shift();if(t===void 0&&this.tail.next!=null){let e=this.tail.next;this.tail.next=null,this.tail=e,t=this.tail.shift()}return t?.value!=null&&(this.size-=this.calculateSize(t.value)),t}isEmpty(){return this.head.isEmpty()}};var Qo=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.code=e??"ABORT_ERR"}};function Ee(r={}){return Tf(e=>{let n=e.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},r)}function Tf(r,t){t=t??{};let e=t.onEnd,n=new Qe,o,i,s,c=Kt(),a=async()=>{try{return n.isEmpty()?s?{done:!0}:await new Promise((d,E)=>{i=A=>{i=null,n.push(A);try{d(r(n))}catch(m){E(m)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{c.resolve(),c=Kt()})}},l=d=>i!=null?i(d):(n.push(d),o),u=d=>(n=new Qe,i!=null?i({error:d}):(n.push({error:d}),o)),f=d=>{if(s)return o;if(t?.objectMode!==!0&&d?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return l({done:!1,value:d})},h=d=>s?o:(s=!0,d!=null?u(d):l({done:!0})),b=()=>(n=new Qe,h(),{done:!0}),x=d=>(h(d),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:a,return:b,throw:x,push:f,end:h,get readableLength(){return n.size},onEmpty:async d=>{let E=d?.signal;if(E?.throwIfAborted(),n.isEmpty())return;let A,m;E!=null&&(A=new Promise((I,R)=>{m=()=>{R(new Qo)},E.addEventListener("abort",m)}));try{await Promise.race([c.promise,A])}finally{m!=null&&E!=null&&E?.removeEventListener("abort",m)}}},e==null)return o;let g=o;return o={[Symbol.asyncIterator](){return this},next(){return g.next()},throw(d){return g.throw(d),e!=null&&(e(d),e=void 0),{done:!0}},return(){return g.return(),e!=null&&(e(),e=void 0),{done:!0}},push:f,end(d){return g.end(d),e!=null&&(e(d),e=void 0),o},get readableLength(){return g.readableLength},onEmpty:d=>g.onEmpty(d)},o}function kf(r){return r[Symbol.asyncIterator]!=null}async function Uf(r,t){try{await Promise.all(r.map(async e=>{for await(let n of e)t.push(n)})),t.end()}catch(e){t.end(e)}}async function*Lf(r){let t=Ee({objectMode:!0});Uf(r,t).catch(()=>{}),yield*t}function*Nf(r){for(let t of r)yield*t}function Rf(...r){let t=[];for(let e of r)kf(e)||t.push(e);return t.length===r.length?Nf(t):Lf(r)}var hc=Rf;function pc(r,...t){if(r==null)throw new Error("Empty pipeline");if(Jo(r)){let n=r;r=()=>n.source}else if(gc(r)||mc(r)){let n=r;r=()=>n}let e=[r,...t];if(e.length>1&&Jo(e[e.length-1])&&(e[e.length-1]=e[e.length-1].sink),e.length>2)for(let n=1;n<e.length-1;n++)Jo(e[n])&&(e[n]=Df(e[n]));return Pf(...e)}var Pf=(...r)=>{let t;for(;r.length>0;)t=r.shift()(t);return t},mc=r=>r?.[Symbol.asyncIterator]!=null,gc=r=>r?.[Symbol.iterator]!=null,Jo=r=>r==null?!1:r.sink!=null&&r.source!=null,Df=r=>t=>{let e=r.sink(t);if(e?.then!=null){let n=Ee({objectMode:!0});e.then(()=>{n.end()},s=>{n.end(s)});let o,i=r.source;if(mc(i))o=async function*(){yield*i,n.end()};else if(gc(i))o=function*(){yield*i,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return hc(n,o())}return r.source};function Cn(r){let t=new globalThis.AbortController;function e(){t.abort();for(let i of r)i?.removeEventListener!=null&&i.removeEventListener("abort",e)}for(let i of r){if(i?.aborted===!0){e();break}i?.addEventListener!=null&&i.addEventListener("abort",e)}function n(){for(let i of r)i?.removeEventListener!=null&&i.removeEventListener("abort",e)}let o=t.signal;return o.clear=n,o}function $t(r=0){return new Uint8Array(r)}function xt(r=0){return new Uint8Array(r)}var Mf=Math.pow(2,7),Of=Math.pow(2,14),Ff=Math.pow(2,21),ti=Math.pow(2,28),ei=Math.pow(2,35),ri=Math.pow(2,42),ni=Math.pow(2,49),G=128,wt=127;function dt(r){if(r<Mf)return 1;if(r<Of)return 2;if(r<Ff)return 3;if(r<ti)return 4;if(r<ei)return 5;if(r<ri)return 6;if(r<ni)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function oi(r,t,e=0){switch(dt(r)){case 8:t[e++]=r&255|G,r/=128;case 7:t[e++]=r&255|G,r/=128;case 6:t[e++]=r&255|G,r/=128;case 5:t[e++]=r&255|G,r/=128;case 4:t[e++]=r&255|G,r>>>=7;case 3:t[e++]=r&255|G,r>>>=7;case 2:t[e++]=r&255|G,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function Vf(r,t,e=0){switch(dt(r)){case 8:t.set(e++,r&255|G),r/=128;case 7:t.set(e++,r&255|G),r/=128;case 6:t.set(e++,r&255|G),r/=128;case 5:t.set(e++,r&255|G),r/=128;case 4:t.set(e++,r&255|G),r>>>=7;case 3:t.set(e++,r&255|G),r>>>=7;case 2:t.set(e++,r&255|G),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function ii(r,t){let e=r[t],n=0;if(n+=e&wt,e<G||(e=r[t+1],n+=(e&wt)<<7,e<G)||(e=r[t+2],n+=(e&wt)<<14,e<G)||(e=r[t+3],n+=(e&wt)<<21,e<G)||(e=r[t+4],n+=(e&wt)*ti,e<G)||(e=r[t+5],n+=(e&wt)*ei,e<G)||(e=r[t+6],n+=(e&wt)*ri,e<G)||(e=r[t+7],n+=(e&wt)*ni,e<G))return n;throw new RangeError("Could not decode varint")}function zf(r,t){let e=r.get(t),n=0;if(n+=e&wt,e<G||(e=r.get(t+1),n+=(e&wt)<<7,e<G)||(e=r.get(t+2),n+=(e&wt)<<14,e<G)||(e=r.get(t+3),n+=(e&wt)<<21,e<G)||(e=r.get(t+4),n+=(e&wt)*ti,e<G)||(e=r.get(t+5),n+=(e&wt)*ei,e<G)||(e=r.get(t+6),n+=(e&wt)*ri,e<G)||(e=r.get(t+7),n+=(e&wt)*ni,e<G))return n;throw new RangeError("Could not decode varint")}function ve(r,t,e=0){return t==null&&(t=xt(dt(r))),t instanceof Uint8Array?oi(r,t,e):Vf(r,t,e)}function ie(r,t=0){return r instanceof Uint8Array?ii(r,t):zf(r,t)}function Lt(r,t){t==null&&(t=r.reduce((o,i)=>o+i.length,0));let e=xt(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return e}function Gt(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}var bc=Symbol.for("@achingbrain/uint8arraylist");function yc(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 kn(r){return!!r?.[bc]}var Je=class r{bufs;length;[bc]=!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(kn(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(kn(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=yc(this.bufs,t);return e.buf[e.index]}set(t,e){let n=yc(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(kn(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 Lt(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:Lt(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],c=o,a=c+s.byteLength;if(o=a,t>=a)continue;let l=t>=c&&t<a,u=e>c&&e<=a;if(l&&u){if(t===c&&e===a){n.push(s);break}let f=t-c;n.push(s.subarray(f,f+(e-t)));break}if(l){if(t===0){n.push(s);continue}n.push(s.subarray(t-c));continue}if(u){if(e===a){n.push(s);break}n.push(s.subarray(0,e-c));break}n.push(s)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!kn(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 f=0;f<i;f++)s[f]=-1;for(let f=0;f<o;f++)s[n[f]]=f;let c=s,a=this.byteLength-n.byteLength,l=n.byteLength-1,u;for(let f=e;f<=a;f+=u){u=0;for(let h=l;h>=0;h--){let b=this.get(f+h);if(n[h]!==b){u=Math.max(1,h-c[b]);break}}if(u===0)return f}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=xt(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=$t(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=$t(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=$t(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=xt(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=$t(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=$t(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=$t(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=$t(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=$t(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(!Gt(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}};var Un=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},tr=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},Ln=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"},Rr=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};function Nn(r){return r[Symbol.asyncIterator]!=null}function xc(r,t){if(r.byteLength>t)throw new tr("Message length too long")}var Pn=r=>{let t=dt(r),e=xt(t);return ve(r,e),Pn.bytes=t,e};Pn.bytes=0;function Dn(r,t){t=t??{};let e=t.lengthEncoder??Pn,n=t?.maxDataLength??4194304;function*o(i){xc(i,n);let s=e(i.byteLength);s instanceof Uint8Array?yield s:yield*s,i instanceof Uint8Array?yield i:yield*i}return Nn(r)?async function*(){for await(let i of r)yield*o(i)}():function*(){for(let i of r)yield*o(i)}()}Dn.single=(r,t)=>{t=t??{};let e=t.lengthEncoder??Pn,n=t?.maxDataLength??4194304;return xc(r,n),new Je(e(r.byteLength),r)};var Pe;(function(r){r[r.LENGTH=0]="LENGTH",r[r.DATA=1]="DATA"})(Pe||(Pe={}));var si=r=>{let t=ie(r);return si.bytes=dt(t),t};si.bytes=0;function Pr(r,t){let e=new Je,n=Pe.LENGTH,o=-1,i=t?.lengthDecoder??si,s=t?.maxLengthLength??8,c=t?.maxDataLength??4194304;function*a(){for(;e.byteLength>0;){if(n===Pe.LENGTH)try{if(o=i(e),o<0)throw new Un("Invalid message length");if(o>c)throw new tr("Message length too long");let l=i.bytes;e.consume(l),t?.onLength!=null&&t.onLength(o),n=Pe.DATA}catch(l){if(l instanceof RangeError){if(e.byteLength>s)throw new Ln("Message length length too long");break}throw l}if(n===Pe.DATA){if(e.byteLength<o)break;let l=e.sublist(0,o);e.consume(o),t?.onData!=null&&t.onData(l),yield l,n=Pe.LENGTH}}}return Nn(r)?async function*(){for await(let l of r)e.append(l),yield*a();if(e.byteLength>0)throw new Rr("Unexpected end of input")}():function*(){for(let l of r)e.append(l),yield*a();if(e.byteLength>0)throw new Rr("Unexpected end of input")}()}Pr.fromReader=(r,t)=>{let e=1,n=async function*(){for(;;)try{let{done:i,value:s}=await r.next(e);if(i===!0)return;s!=null&&(yield s)}catch(i){if(i.code==="ERR_UNDER_READ")return{done:!0,value:null};throw i}finally{e=1}}();return Pr(n,{...t??{},onLength:i=>{e=i}})};var wc="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";var er=(r=21)=>{let t="",e=crypto.getRandomValues(new Uint8Array(r|=0));for(;r--;)t+=wc[e[r]&63];return t};var Mn=class extends Error{constructor(t="Method not found"){super(t),this.name="MethodNotFoundError"}},On=class extends Error{constructor(t="Invocation target was not a function"){super(t),this.name="InvalidMethodError"}},Dr=class extends Error{constructor(t="Unsupported value type"){super(t),this.name="UnsupportedValueTypeError"}},Fn=class extends Error{constructor(t="Cannot reuse RPC target name"){super(t),this.name="DuplicateTargetNameError"}},Mr=class extends Error{constructor(t="Duplicate scope"){super(t),this.name="DuplicateScopeError"}},Vn=class extends Error{constructor(t="Invalid return type"){super(t),this.name="InvalidReturnTypeError"}},Or=class extends Error{constructor(t="Invocation target was not a function"){super(t),this.name="InvalidInvocationTypeError"}},rr=class extends Error{constructor(t="Parent invocation scope not found"){super(t),this.name="MissingParentScopeError"}},zn=class extends Error{constructor(t="Invocation not found"){super(t),this.name="MissingInvocationError"}},Hn=class extends Error{constructor(t="Callback not found"){super(t),this.name="MissingCallbackError"}};var ci=new Float32Array([-0]),Se=new Uint8Array(ci.buffer);function Ec(r,t,e){ci[0]=r,t[e]=Se[0],t[e+1]=Se[1],t[e+2]=Se[2],t[e+3]=Se[3]}function vc(r,t){return Se[0]=r[t],Se[1]=r[t+1],Se[2]=r[t+2],Se[3]=r[t+3],ci[0]}var ai=new Float64Array([-0]),Et=new Uint8Array(ai.buffer);function Sc(r,t,e){ai[0]=r,t[e]=Et[0],t[e+1]=Et[1],t[e+2]=Et[2],t[e+3]=Et[3],t[e+4]=Et[4],t[e+5]=Et[5],t[e+6]=Et[6],t[e+7]=Et[7]}function Ac(r,t){return Et[0]=r[t],Et[1]=r[t+1],Et[2]=r[t+2],Et[3]=r[t+3],Et[4]=r[t+4],Et[5]=r[t+5],Et[6]=r[t+6],Et[7]=r[t+7],ai[0]}var qf=BigInt(Number.MAX_SAFE_INTEGER),Kf=BigInt(Number.MIN_SAFE_INTEGER),Nt=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 De;if(t<qf&&t>Kf)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>Bc&&(o=0n,++n>Bc&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(t){if(t===0)return De;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):De}},De=new Nt(0,0);De.toBigInt=function(){return 0n};De.zzEncode=De.zzDecode=function(){return this};De.length=function(){return 1};var Bc=4294967296n;function Ic(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 _c(r,t,e){if(e-t<1)return"";let o,i=[],s=0,c;for(;t<e;)c=r[t++],c<128?i[s++]=c:c>191&&c<224?i[s++]=(c&31)<<6|r[t++]&63:c>239&&c<365?(c=((c&7)<<18|(r[t++]&63)<<12|(r[t++]&63)<<6|r[t++]&63)-65536,i[s++]=55296+(c>>10),i[s++]=56320+(c&1023)):i[s++]=(c&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 ui(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 jt(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function qn(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var li=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,jt(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 jt(this,4);return qn(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw jt(this,4);return qn(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw jt(this,4);let t=vc(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw jt(this,4);let t=Ac(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 jt(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return _c(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw jt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw jt(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 Nt(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 jt(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 jt(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 jt(this,8);let t=qn(this.buf,this.pos+=4),e=qn(this.buf,this.pos+=4);return new Nt(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=ii(this.buf,this.pos);return this.pos+=dt(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 fi(r){return new li(r instanceof Uint8Array?r:r.subarray())}function St(r,t,e){let n=fi(r);return t.decode(n,void 0,e)}var di={};Ct(di,{base10:()=>$f});var $f=xe({prefix:"9",name:"base10",alphabet:"0123456789"});var hi={};Ct(hi,{base16:()=>Gf,base16upper:()=>jf});var Gf=it({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),jf=it({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var pi={};Ct(pi,{base2:()=>Zf});var Zf=it({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var mi={};Ct(mi,{base256emoji:()=>Jf});var Tc=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}"),Wf=Tc.reduce((r,t,e)=>(r[e]=t,r),[]),Xf=Tc.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function Yf(r){return r.reduce((t,e)=>(t+=Wf[e],t),"")}function Qf(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let o=Xf[n];if(o==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(o)}return new Uint8Array(t)}var Jf=We({prefix:"\u{1F680}",name:"base256emoji",encode:Yf,decode:Qf});var gi={};Ct(gi,{base36:()=>Fr,base36upper:()=>td});var Fr=xe({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),td=xe({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var yi={};Ct(yi,{base8:()=>ed});var ed=it({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var bi={};Ct(bi,{identity:()=>rd});var rd=We({prefix:"\0",name:"identity",encode:r=>qs(r),decode:r=>Hs(r)});var Fg=new TextEncoder,Vg=new TextDecoder;var wi={};Ct(wi,{identity:()=>ce});var id=Lc,kc=128,sd=127,cd=~sd,ad=Math.pow(2,31);function Lc(r,t,e){t=t||[],e=e||0;for(var n=e;r>=ad;)t[e++]=r&255|kc,r/=128;for(;r&cd;)t[e++]=r&255|kc,r>>>=7;return t[e]=r|0,Lc.bytes=e-n+1,t}var ud=xi,ld=128,Uc=127;function xi(r,n){var e=0,n=n||0,o=0,i=n,s,c=r.length;do{if(i>=c)throw xi.bytes=0,new RangeError("Could not decode varint");s=r[i++],e+=o<28?(s&Uc)<<o:(s&Uc)*Math.pow(2,o),o+=7}while(s>=ld);return xi.bytes=i-n,e}var fd=Math.pow(2,7),dd=Math.pow(2,14),hd=Math.pow(2,21),pd=Math.pow(2,28),md=Math.pow(2,35),gd=Math.pow(2,42),yd=Math.pow(2,49),bd=Math.pow(2,56),xd=Math.pow(2,63),wd=function(r){return r<fd?1:r<dd?2:r<hd?3:r<pd?4:r<md?5:r<gd?6:r<yd?7:r<bd?8:r<xd?9:10},Ed={encode:id,decode:ud,encodingLength:wd},vd=Ed,Vr=vd;function zr(r,t=0){return[Vr.decode(r,t),Vr.decode.bytes]}function nr(r,t,e=0){return Vr.encode(r,t,e),t}function or(r){return Vr.encodingLength(r)}function Me(r,t){let e=t.byteLength,n=or(r),o=n+or(e),i=new Uint8Array(o+e);return nr(r,i,0),nr(e,i,n),i.set(t,o),new ir(r,e,t,i)}function se(r){let t=oe(r),[e,n]=zr(t),[o,i]=zr(t.subarray(n)),s=t.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new ir(e,o,s,t)}function Nc(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&zs(r.bytes,e.bytes)}}var ir=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=n,this.bytes=o}};var Rc=0,Sd="identity",Pc=oe;function Ad(r){return Me(Rc,Pc(r))}var ce={code:Rc,name:Sd,encode:Pc,digest:Ad};var Si={};Ct(Si,{sha256:()=>Hr,sha512:()=>Bd});function vi({name:r,code:t,encode:e}){return new Ei(r,t,e)}var Ei=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?Me(this.code,e):e.then(n=>Me(this.code,n))}else throw Error("Unknown type, must be binary type")}};function Mc(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var Hr=vi({name:"sha2-256",code:18,encode:Mc("SHA-256")}),Bd=vi({name:"sha2-512",code:19,encode:Mc("SHA-512")});function Oc(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return _d(e,Ai(r),t??tt.encoder);default:return Cd(e,Ai(r),t??Ht.encoder)}}var Fc=new WeakMap;function Ai(r){let t=Fc.get(r);if(t==null){let e=new Map;return Fc.set(r,e),e}return t}var at=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!==qr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==Td)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=Me(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&&Nc(t.multihash,n.multihash)}toString(t){return Oc(this,t)}toJSON(){return{"/":Oc(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??Vc(n,o,i.bytes))}else if(e[kd]===!0){let{version:n,multihash:o,code:i}=e,s=se(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!==qr)throw new Error(`Version 0 CID must use dag-pb (code: ${qr}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=Vc(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,qr,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=oe(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 ir(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[f,h]=zr(t.subarray(e));return e+=h,f},o=n(),i=qr;if(o===18?(o=0,e=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let s=e,c=n(),a=n(),l=e+a,u=l-s;return{version:o,codec:i,multihashCode:c,digestSize:a,multihashSize:u,size:l}}static parse(t,e){let[n,o]=Id(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 Ai(i).set(n,t),i}};function Id(r,t){switch(r[0]){case"Q":{let e=t??tt;return[tt.prefix,e.decode(`${tt.prefix}${r}`)]}case tt.prefix:{let e=t??tt;return[tt.prefix,e.decode(r)]}case Ht.prefix:{let e=t??Ht;return[Ht.prefix,e.decode(r)]}case Fr.prefix:{let e=t??Fr;return[Fr.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 _d(r,t,e){let{prefix:n}=e;if(n!==tt.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 Cd(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 qr=112,Td=18;function Vc(r,t,e){let n=or(r),o=n+or(t),i=new Uint8Array(o+e.byteLength);return nr(r,i,0),nr(t,i,n),i.set(e,o),i}var kd=Symbol.for("@ipld/js-cid/CID");var Kr={...bi,...pi,...yi,...di,...hi,...$o,...gi,...Go,...jo,...mi},ay={...Si,...wi};function Hc(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var zc=Hc("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Bi=Hc("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=xt(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),Ud={utf8:zc,"utf-8":zc,hex:Kr.base16,latin1:Bi,ascii:Bi,binary:Bi,...Kr},$n=Ud;function ae(r,t="utf8"){let e=$n[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function Ii(r){let t=r??8192,e=t>>>1,n,o=t;return function(s){if(s<1||s>e)return xt(s);o+s>t&&(n=xt(t),o=0);let c=n.subarray(o,o+=s);return(o&7)!==0&&(o=(o|7)+1),c}}var Oe=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function _i(){}var Ti=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Ld=Ii();function Nd(r){return globalThis.Buffer!=null?xt(r):Ld(r)}var Gr=class{len;head;tail;states;constructor(){this.len=0,this.head=new Oe(_i,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new Oe(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new ki((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(Gn,10,Nt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=Nt.fromBigInt(t);return this._push(Gn,e.length(),e)}uint64Number(t){return this._push(oi,dt(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=Nt.fromBigInt(t).zzEncode();return this._push(Gn,e.length(),e)}sint64Number(t){let e=Nt.fromNumber(t).zzEncode();return this._push(Gn,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Ci,1,t?1:0)}fixed32(t){return this._push($r,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=Nt.fromBigInt(t);return this._push($r,4,e.lo)._push($r,4,e.hi)}fixed64Number(t){let e=Nt.fromNumber(t);return this._push($r,4,e.lo)._push($r,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(Ec,4,t)}double(t){return this._push(Sc,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(Ci,1,0):this.uint32(e)._push(Pd,e,t)}string(t){let e=Ic(t);return e!==0?this.uint32(e)._push(ui,e,t):this._push(Ci,1,0)}fork(){return this.states=new Ti(this),this.head=this.tail=new Oe(_i,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 Oe(_i,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=Nd(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function Ci(r,t,e){t[e]=r&255}function Rd(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var ki=class extends Oe{next;constructor(t,e){super(Rd,t,e),this.next=void 0}};function Gn(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 $r(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 Pd(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(Gr.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(Dd,t,r),this},Gr.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(Md,t,r),this});function Dd(r,t,e){t.set(r,e)}function Md(r,t,e){r.length<40?ui(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(ae(r),e)}function Ui(){return new Gr}function At(r,t){let e=Ui();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var sr;(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"})(sr||(sr={}));function jn(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function jr(r){function t(o){if(r[o.toString()]==null)throw new Error("Invalid enum value");return r[o]}let e=function(i,s){let c=t(i);s.int32(c)},n=function(i){let s=i.int32();return t(s)};return jn("enum",sr.VARINT,e,n)}function Bt(r,t){return jn("message",sr.LENGTH_DELIMITED,r,t)}var ue=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var K;(function(r){r.invokeMethod="invokeMethod",r.methodResolved="methodResolved",r.methodRejected="methodRejected",r.invokeGeneratorMethod="invokeGeneratorMethod",r.abortMethodInvocation="abortMethodInvocation",r.invokeCallback="invokeCallback",r.callbackResolved="callbackResolved",r.callbackRejected="callbackRejected",r.abortCallbackInvocation="abortCallbackInvocation"})(K||(K={}));var Zn;(function(r){r[r.invokeMethod=0]="invokeMethod",r[r.methodResolved=1]="methodResolved",r[r.methodRejected=2]="methodRejected",r[r.invokeGeneratorMethod=3]="invokeGeneratorMethod",r[r.abortMethodInvocation=4]="abortMethodInvocation",r[r.invokeCallback=5]="invokeCallback",r[r.callbackResolved=6]="callbackResolved",r[r.callbackRejected=7]="callbackRejected",r[r.abortCallbackInvocation=8]="abortCallbackInvocation"})(Zn||(Zn={}));(function(r){r.codec=()=>jr(Zn)})(K||(K={}));var Tt;(function(r){let t;r.codec=()=>(t==null&&(t=Bt((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.type!=null&&e.type!==0&&(n.uint32(8),n.uint32(e.type)),e.value!=null&&(n.uint32(18),n.bytes(e.value)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let i={type:0},s=n==null?e.len:e.pos+n;for(;e.pos<s;){let c=e.uint32();switch(c>>>3){case 1:{i.type=e.uint32();break}case 2:{i.value=e.bytes();break}default:{e.skipType(c&7);break}}}return i})),t),r.encode=e=>At(e,r.codec()),r.decode=(e,n)=>St(e,r.codec(),n)})(Tt||(Tt={}));var It;(function(r){let t;r.codec=()=>(t==null&&(t=Bt((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.type!=null&&Zn[e.type]!==0&&(n.uint32(8),K.codec().encode(e.type,n)),e.message!=null&&e.message.byteLength>0&&(n.uint32(18),n.bytes(e.message)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let i={type:K.invokeMethod,message:$t(0)},s=n==null?e.len:e.pos+n;for(;e.pos<s;){let c=e.uint32();switch(c>>>3){case 1:{i.type=K.codec().decode(e);break}case 2:{i.message=e.bytes();break}default:{e.skipType(c&7);break}}}return i})),t),r.encode=e=>At(e,r.codec()),r.decode=(e,n)=>St(e,r.codec(),n)})(It||(It={}));var Fe;(function(r){let t;r.codec=()=>(t==null&&(t=Bt((e,n,o={})=>{if(o.lengthDelimited!==!1&&n.fork(),e.scope!=null&&e.scope!==""&&(n.uint32(10),n.string(e.scope)),e.path!=null&&e.path!==""&&(n.uint32(18),n.string(e.path)),e.args!=null)for(let i of e.args)n.uint32(26),Tt.codec().encode(i,n);o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let i={scope:"",path:"",args:[]},s=n==null?e.len:e.pos+n;for(;e.pos<s;){let c=e.uint32();switch(c>>>3){case 1:{i.scope=e.string();break}case 2:{i.path=e.string();break}case 3:{if(o.limits?.args!=null&&i.args.length===o.limits.args)throw new ue('Decode error - map field "args" had too many elements');i.args.push(Tt.codec().decode(e,e.uint32(),{limits:o.limits?.args$}));break}default:{e.skipType(c&7);break}}}return i})),t),r.encode=e=>At(e,r.codec()),r.decode=(e,n)=>St(e,r.codec(),n)})(Fe||(Fe={}));var Zr;(function(r){let t;r.codec=()=>(t==null&&(t=Bt((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.scope!=null&&e.scope!==""&&(n.uint32(10),n.string(e.scope)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let i={scope:""},s=n==null?e.len:e.pos+n;for(;e.pos<s;){let c=e.uint32();switch(c>>>3){case 1:{i.scope=e.string();break}default:{e.skipType(c&7);break}}}return i})),t),r.encode=e=>At(e,r.codec()),r.decode=(e,n)=>St(e,r.codec(),n)})(Zr||(Zr={}));var cr;(function(r){let t;r.codec=()=>(t==null&&(t=Bt((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.scope!=null&&e.scope!==""&&(n.uint32(10),n.string(e.scope)),e.value!=null&&(n.uint32(18),Tt.codec().encode(e.value,n)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let i={scope:""},s=n==null?e.len:e.pos+n;for(;e.pos<s;){let c=e.uint32();switch(c>>>3){case 1:{i.scope=e.string();break}case 2:{i.value=Tt.codec().decode(e,e.uint32(),{limits:o.limits?.value});break}default:{e.skipType(c&7);break}}}return i})),t),r.encode=e=>At(e,r.codec()),r.decode=(e,n)=>St(e,r.codec(),n)})(cr||(cr={}));var Wr;(function(r){let t;r.codec=()=>(t==null&&(t=Bt((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.scope!=null&&e.scope!==""&&(n.uint32(10),n.string(e.scope)),e.error!=null&&(n.uint32(18),Tt.codec().encode(e.error,n)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let i={scope:""},s=n==null?e.len:e.pos+n;for(;e.pos<s;){let c=e.uint32();switch(c>>>3){case 1:{i.scope=e.string();break}case 2:{i.error=Tt.codec().decode(e,e.uint32(),{limits:o.limits?.error});break}default:{e.skipType(c&7);break}}}return i})),t),r.encode=e=>At(e,r.codec()),r.decode=(e,n)=>St(e,r.codec(),n)})(Wr||(Wr={}));var ar;(function(r){let t;r.codec=()=>(t==null&&(t=Bt((e,n,o={})=>{if(o.lengthDelimited!==!1&&n.fork(),e.scope!=null&&e.scope!==""&&(n.uint32(10),n.string(e.scope)),e.parents!=null)for(let i of e.parents)n.uint32(18),n.string(i);if(e.callback!=null&&e.callback!==""&&(n.uint32(26),n.string(e.callback)),e.args!=null)for(let i of e.args)n.uint32(34),Tt.codec().encode(i,n);o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let i={scope:"",parents:[],callback:"",args:[]},s=n==null?e.len:e.pos+n;for(;e.pos<s;){let c=e.uint32();switch(c>>>3){case 1:{i.scope=e.string();break}case 2:{if(o.limits?.parents!=null&&i.parents.length===o.limits.parents)throw new ue('Decode error - map field "parents" had too many elements');i.parents.push(e.string());break}case 3:{i.callback=e.string();break}case 4:{if(o.limits?.args!=null&&i.args.length===o.limits.args)throw new ue('Decode error - map field "args" had too many elements');i.args.push(Tt.codec().decode(e,e.uint32(),{limits:o.limits?.args$}));break}default:{e.skipType(c&7);break}}}return i})),t),r.encode=e=>At(e,r.codec()),r.decode=(e,n)=>St(e,r.codec(),n)})(ar||(ar={}));var ur;(function(r){let t;r.codec=()=>(t==null&&(t=Bt((e,n,o={})=>{if(o.lengthDelimited!==!1&&n.fork(),e.scope!=null&&e.scope!==""&&(n.uint32(10),n.string(e.scope)),e.parents!=null)for(let i of e.parents)n.uint32(18),n.string(i);o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let i={scope:"",parents:[]},s=n==null?e.len:e.pos+n;for(;e.pos<s;){let c=e.uint32();switch(c>>>3){case 1:{i.scope=e.string();break}case 2:{if(o.limits?.parents!=null&&i.parents.length===o.limits.parents)throw new ue('Decode error - map field "parents" had too many elements');i.parents.push(e.string());break}default:{e.skipType(c&7);break}}}return i})),t),r.encode=e=>At(e,r.codec()),r.decode=(e,n)=>St(e,r.codec(),n)})(ur||(ur={}));var Xr;(function(r){let t;r.codec=()=>(t==null&&(t=Bt((e,n,o={})=>{if(o.lengthDelimited!==!1&&n.fork(),e.scope!=null&&e.scope!==""&&(n.uint32(10),n.string(e.scope)),e.parents!=null)for(let i of e.parents)n.uint32(18),n.string(i);e.value!=null&&(n.uint32(26),Tt.codec().encode(e.value,n)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let i={scope:"",parents:[]},s=n==null?e.len:e.pos+n;for(;e.pos<s;){let c=e.uint32();switch(c>>>3){case 1:{i.scope=e.string();break}case 2:{if(o.limits?.parents!=null&&i.parents.length===o.limits.parents)throw new ue('Decode error - map field "parents" had too many elements');i.parents.push(e.string());break}case 3:{i.value=Tt.codec().decode(e,e.uint32(),{limits:o.limits?.value});break}default:{e.skipType(c&7);break}}}return i})),t),r.encode=e=>At(e,r.codec()),r.decode=(e,n)=>St(e,r.codec(),n)})(Xr||(Xr={}));var Yr;(function(r){let t;r.codec=()=>(t==null&&(t=Bt((e,n,o={})=>{if(o.lengthDelimited!==!1&&n.fork(),e.scope!=null&&e.scope!==""&&(n.uint32(10),n.string(e.scope)),e.parents!=null)for(let i of e.parents)n.uint32(18),n.string(i);e.error!=null&&(n.uint32(26),Tt.codec().encode(e.error,n)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let i={scope:"",parents:[]},s=n==null?e.len:e.pos+n;for(;e.pos<s;){let c=e.uint32();switch(c>>>3){case 1:{i.scope=e.string();break}case 2:{if(o.limits?.parents!=null&&i.parents.length===o.limits.parents)throw new ue('Decode error - map field "parents" had too many elements');i.parents.push(e.string());break}case 3:{i.error=Tt.codec().decode(e,e.uint32(),{limits:o.limits?.error});break}default:{e.skipType(c&7);break}}}return i})),t),r.encode=e=>At(e,r.codec()),r.decode=(e,n)=>St(e,r.codec(),n)})(Yr||(Yr={}));function Od(r){return r.parents!=null}function qc(r,t){if(Od(r))return Fd(r.parents,t);let e=t.get(r.scope);if(e==null)throw new zn;return e}function Fd(r,t){let e;for(let n of r){if(e==null){if(e=t.get(n),e==null)throw new rr;continue}if(e=e.children.get(n),e==null)throw new rr}if(e==null)throw new rr;return e}var Vd={type:1024,canEncode:r=>r===void 0,decode:()=>{}},Kc=Vd;var zd={type:1025,canEncode:r=>r===null,decode:()=>null},$c=zd;var Hd=["string","number","bigint","symbol"],qd=["Function","Generator","AsyncGenerator","GeneratorFunction","AsyncGeneratorFunction","AsyncFunction","Observable","Array","Buffer","Object","RegExp","Date","Error","Map","Set","WeakMap","WeakSet","ArrayBuffer","SharedArrayBuffer","DataView","Promise","URL","HTMLElement","Int8Array","Uint8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array"];function Gc(r){if(r===null)return"null";if(r===void 0)return"undefined";if(r===!0||r===!1)return"boolean";let t=typeof r;if(Hd.includes(t))return t;if(t==="function")return"Function";if(Array.isArray(r))return"Array";if(Kd(r))return"Buffer";let e=$d(r);return e||"Object"}function Kd(r){return r&&r.constructor&&r.constructor.isBuffer&&r.constructor.isBuffer.call(null,r)}function $d(r){let t=Object.prototype.toString.call(r).slice(8,-1);if(qd.includes(t))return t}var p=class{constructor(t,e,n){this.major=t,this.majorEncoded=t<<5,this.name=e,this.terminal=n}toString(){return`Type[${this.major}].${this.name}`}compare(t){return this.major<t.major?-1:this.major>t.major?1:0}};p.uint=new p(0,"uint",!0);p.negint=new p(1,"negint",!0);p.bytes=new p(2,"bytes",!0);p.string=new p(3,"string",!0);p.array=new p(4,"array",!1);p.map=new p(5,"map",!1);p.tag=new p(6,"tag",!1);p.float=new p(7,"float",!0);p.false=new p(7,"false",!0);p.true=new p(7,"true",!0);p.null=new p(7,"null",!0);p.undefined=new p(7,"undefined",!0);p.break=new p(7,"break",!0);var _=class{constructor(t,e,n){this.type=t,this.value=e,this.encodedLength=n,this.encodedBytes=void 0,this.byteValue=void 0}toString(){return`Token[${this.type}].${this.value}`}};var lr=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",Gd=new TextDecoder,jd=new TextEncoder;function Wn(r){return lr&&globalThis.Buffer.isBuffer(r)}function Li(r){return r instanceof Uint8Array?Wn(r)?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):r:Uint8Array.from(r)}var Xc=lr?(r,t,e)=>e-t>64?globalThis.Buffer.from(r.subarray(t,e)).toString("utf8"):Zc(r,t,e):(r,t,e)=>e-t>64?Gd.decode(r.subarray(t,e)):Zc(r,t,e),Yc=lr?r=>r.length>64?globalThis.Buffer.from(r):jc(r):r=>r.length>64?jd.encode(r):jc(r),ee=r=>Uint8Array.from(r),fr=lr?(r,t,e)=>Wn(r)?new Uint8Array(r.subarray(t,e)):r.slice(t,e):(r,t,e)=>r.slice(t,e),Qc=lr?(r,t)=>(r=r.map(e=>e instanceof Uint8Array?e:globalThis.Buffer.from(e)),Li(globalThis.Buffer.concat(r,t))):(r,t)=>{let e=new Uint8Array(t),n=0;for(let o of r)n+o.length>e.length&&(o=o.subarray(0,e.length-n)),e.set(o,n),n+=o.length;return e},Jc=lr?r=>globalThis.Buffer.allocUnsafe(r):r=>new Uint8Array(r);function ta(r,t){if(Wn(r)&&Wn(t))return r.compare(t);for(let e=0;e<r.length;e++)if(r[e]!==t[e])return r[e]<t[e]?-1:1;return 0}function jc(r){let t=[],e=0;for(let n=0;n<r.length;n++){let o=r.charCodeAt(n);o<128?t[e++]=o:o<2048?(t[e++]=o>>6|192,t[e++]=o&63|128):(o&64512)===55296&&n+1<r.length&&(r.charCodeAt(n+1)&64512)===56320?(o=65536+((o&1023)<<10)+(r.charCodeAt(++n)&1023),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 t}function Zc(r,t,e){let n=[];for(;t<e;){let o=r[t],i=null,s=o>239?4:o>223?3:o>191?2:1;if(t+s<=e){let c,a,l,u;switch(s){case 1:o<128&&(i=o);break;case 2:c=r[t+1],(c&192)===128&&(u=(o&31)<<6|c&63,u>127&&(i=u));break;case 3:c=r[t+1],a=r[t+2],(c&192)===128&&(a&192)===128&&(u=(o&15)<<12|(c&63)<<6|a&63,u>2047&&(u<55296||u>57343)&&(i=u));break;case 4:c=r[t+1],a=r[t+2],l=r[t+3],(c&192)===128&&(a&192)===128&&(l&192)===128&&(u=(o&15)<<18|(c&63)<<12|(a&63)<<6|l&63,u>65535&&u<1114112&&(i=u))}}i===null?(i=65533,s=1):i>65535&&(i-=65536,n.push(i>>>10&1023|55296),i=56320|i&1023),n.push(i),t+=s}return Zd(n)}var Wc=4096;function Zd(r){let t=r.length;if(t<=Wc)return String.fromCharCode.apply(String,r);let e="",n=0;for(;n<t;)e+=String.fromCharCode.apply(String,r.slice(n,n+=Wc));return e}var Wd=256,Qr=class{constructor(t=Wd){this.chunkSize=t,this.cursor=0,this.maxCursor=-1,this.chunks=[],this._initReuseChunk=null}reset(){this.cursor=0,this.maxCursor=-1,this.chunks.length&&(this.chunks=[]),this._initReuseChunk!==null&&(this.chunks.push(this._initReuseChunk),this.maxCursor=this._initReuseChunk.length-1)}push(t){let e=this.chunks[this.chunks.length-1];if(this.cursor+t.length<=this.maxCursor+1){let o=e.length-(this.maxCursor-this.cursor)-1;e.set(t,o)}else{if(e){let o=e.length-(this.maxCursor-this.cursor)-1;o<e.length&&(this.chunks[this.chunks.length-1]=e.subarray(0,o),this.maxCursor=this.cursor-1)}t.length<64&&t.length<this.chunkSize?(e=Jc(this.chunkSize),this.chunks.push(e),this.maxCursor+=e.length,this._initReuseChunk===null&&(this._initReuseChunk=e),e.set(t,0)):(this.chunks.push(t),this.maxCursor+=t.length)}this.cursor+=t.length}toBytes(t=!1){let e;if(this.chunks.length===1){let n=this.chunks[0];t&&this.cursor>n.length/2?(e=this.cursor===n.length?n:n.subarray(0,this.cursor),this._initReuseChunk=null,this.chunks=[]):e=fr(n,0,this.cursor)}else e=Qc(this.chunks,this.cursor);return t&&this.reset(),e}};var M="CBOR decode error:",Ni="CBOR encode error:",Jr=[];Jr[23]=1;Jr[24]=2;Jr[25]=3;Jr[26]=5;Jr[27]=9;function le(r,t,e){if(r.length-t<e)throw new Error(`${M} not enough data for type`)}var ht=[24,256,65536,4294967296,BigInt("18446744073709551616")];function Rt(r,t,e){le(r,t,1);let n=r[t];if(e.strict===!0&&n<ht[0])throw new Error(`${M} integer encoded in more bytes than necessary (strict decode)`);return n}function Pt(r,t,e){le(r,t,2);let n=r[t]<<8|r[t+1];if(e.strict===!0&&n<ht[1])throw new Error(`${M} integer encoded in more bytes than necessary (strict decode)`);return n}function Dt(r,t,e){le(r,t,4);let n=r[t]*16777216+(r[t+1]<<16)+(r[t+2]<<8)+r[t+3];if(e.strict===!0&&n<ht[2])throw new Error(`${M} integer encoded in more bytes than necessary (strict decode)`);return n}function Mt(r,t,e){le(r,t,8);let n=r[t]*16777216+(r[t+1]<<16)+(r[t+2]<<8)+r[t+3],o=r[t+4]*16777216+(r[t+5]<<16)+(r[t+6]<<8)+r[t+7],i=(BigInt(n)<<BigInt(32))+BigInt(o);if(e.strict===!0&&i<ht[3])throw new Error(`${M} integer encoded in more bytes than necessary (strict decode)`);if(i<=Number.MAX_SAFE_INTEGER)return Number(i);if(e.allowBigInt===!0)return i;throw new Error(`${M} integers outside of the safe integer range are not supported`)}function ea(r,t,e,n){return new _(p.uint,Rt(r,t+1,n),2)}function ra(r,t,e,n){return new _(p.uint,Pt(r,t+1,n),3)}function na(r,t,e,n){return new _(p.uint,Dt(r,t+1,n),5)}function oa(r,t,e,n){return new _(p.uint,Mt(r,t+1,n),9)}function Ft(r,t){return gt(r,0,t.value)}function gt(r,t,e){if(e<ht[0]){let n=Number(e);r.push([t|n])}else if(e<ht[1]){let n=Number(e);r.push([t|24,n])}else if(e<ht[2]){let n=Number(e);r.push([t|25,n>>>8,n&255])}else if(e<ht[3]){let n=Number(e);r.push([t|26,n>>>24&255,n>>>16&255,n>>>8&255,n&255])}else{let n=BigInt(e);if(n<ht[4]){let o=[t|27,0,0,0,0,0,0,0],i=Number(n&BigInt(4294967295)),s=Number(n>>BigInt(32)&BigInt(4294967295));o[8]=i&255,i=i>>8,o[7]=i&255,i=i>>8,o[6]=i&255,i=i>>8,o[5]=i&255,o[4]=s&255,s=s>>8,o[3]=s&255,s=s>>8,o[2]=s&255,s=s>>8,o[1]=s&255,r.push(o)}else throw new Error(`${M} encountered BigInt larger than allowable range`)}}Ft.encodedSize=function(t){return gt.encodedSize(t.value)};gt.encodedSize=function(t){return t<ht[0]?1:t<ht[1]?2:t<ht[2]?3:t<ht[3]?5:9};Ft.compareTokens=function(t,e){return t.value<e.value?-1:t.value>e.value?1:0};function ia(r,t,e,n){return new _(p.negint,-1-Rt(r,t+1,n),2)}function sa(r,t,e,n){return new _(p.negint,-1-Pt(r,t+1,n),3)}function ca(r,t,e,n){return new _(p.negint,-1-Dt(r,t+1,n),5)}var Ri=BigInt(-1),aa=BigInt(1);function ua(r,t,e,n){let o=Mt(r,t+1,n);if(typeof o!="bigint"){let i=-1-o;if(i>=Number.MIN_SAFE_INTEGER)return new _(p.negint,i,9)}if(n.allowBigInt!==!0)throw new Error(`${M} integers outside of the safe integer range are not supported`);return new _(p.negint,Ri-BigInt(o),9)}function Xn(r,t){let e=t.value,n=typeof e=="bigint"?e*Ri-aa:e*-1-1;gt(r,t.type.majorEncoded,n)}Xn.encodedSize=function(t){let e=t.value,n=typeof e=="bigint"?e*Ri-aa:e*-1-1;return n<ht[0]?1:n<ht[1]?2:n<ht[2]?3:n<ht[3]?5:9};Xn.compareTokens=function(t,e){return t.value<e.value?1:t.value>e.value?-1:0};function tn(r,t,e,n){le(r,t,e+n);let o=fr(r,t+e,t+e+n);return new _(p.bytes,o,e+n)}function la(r,t,e,n){return tn(r,t,1,e)}function fa(r,t,e,n){return tn(r,t,2,Rt(r,t+1,n))}function da(r,t,e,n){return tn(r,t,3,Pt(r,t+1,n))}function ha(r,t,e,n){return tn(r,t,5,Dt(r,t+1,n))}function pa(r,t,e,n){let o=Mt(r,t+1,n);if(typeof o=="bigint")throw new Error(`${M} 64-bit integer bytes lengths not supported`);return tn(r,t,9,o)}function Yn(r){return r.encodedBytes===void 0&&(r.encodedBytes=r.type===p.string?Yc(r.value):r.value),r.encodedBytes}function dr(r,t){let e=Yn(t);gt(r,t.type.majorEncoded,e.length),r.push(e)}dr.encodedSize=function(t){let e=Yn(t);return gt.encodedSize(e.length)+e.length};dr.compareTokens=function(t,e){return Yd(Yn(t),Yn(e))};function Yd(r,t){return r.length<t.length?-1:r.length>t.length?1:ta(r,t)}function en(r,t,e,n,o){let i=e+n;le(r,t,i);let s=new _(p.string,Xc(r,t+e,t+i),i);return o.retainStringBytes===!0&&(s.byteValue=fr(r,t+e,t+i)),s}function ma(r,t,e,n){return en(r,t,1,e,n)}function ga(r,t,e,n){return en(r,t,2,Rt(r,t+1,n),n)}function ya(r,t,e,n){return en(r,t,3,Pt(r,t+1,n),n)}function ba(r,t,e,n){return en(r,t,5,Dt(r,t+1,n),n)}function xa(r,t,e,n){let o=Mt(r,t+1,n);if(typeof o=="bigint")throw new Error(`${M} 64-bit integer string lengths not supported`);return en(r,t,9,o,n)}var wa=dr;function hr(r,t,e,n){return new _(p.array,n,e)}function Ea(r,t,e,n){return hr(r,t,1,e)}function va(r,t,e,n){return hr(r,t,2,Rt(r,t+1,n))}function Sa(r,t,e,n){return hr(r,t,3,Pt(r,t+1,n))}function Aa(r,t,e,n){return hr(r,t,5,Dt(r,t+1,n))}function Ba(r,t,e,n){let o=Mt(r,t+1,n);if(typeof o=="bigint")throw new Error(`${M} 64-bit integer array lengths not supported`);return hr(r,t,9,o)}function Ia(r,t,e,n){if(n.allowIndefinite===!1)throw new Error(`${M} indefinite length items not allowed`);return hr(r,t,1,1/0)}function Qn(r,t){gt(r,p.array.majorEncoded,t.value)}Qn.compareTokens=Ft.compareTokens;Qn.encodedSize=function(t){return gt.encodedSize(t.value)};function pr(r,t,e,n){return new _(p.map,n,e)}function _a(r,t,e,n){return pr(r,t,1,e)}function Ca(r,t,e,n){return pr(r,t,2,Rt(r,t+1,n))}function Ta(r,t,e,n){return pr(r,t,3,Pt(r,t+1,n))}function ka(r,t,e,n){return pr(r,t,5,Dt(r,t+1,n))}function Ua(r,t,e,n){let o=Mt(r,t+1,n);if(typeof o=="bigint")throw new Error(`${M} 64-bit integer map lengths not supported`);return pr(r,t,9,o)}function La(r,t,e,n){if(n.allowIndefinite===!1)throw new Error(`${M} indefinite length items not allowed`);return pr(r,t,1,1/0)}function Jn(r,t){gt(r,p.map.majorEncoded,t.value)}Jn.compareTokens=Ft.compareTokens;Jn.encodedSize=function(t){return gt.encodedSize(t.value)};function Na(r,t,e,n){return new _(p.tag,e,1)}function Ra(r,t,e,n){return new _(p.tag,Rt(r,t+1,n),2)}function Pa(r,t,e,n){return new _(p.tag,Pt(r,t+1,n),3)}function Da(r,t,e,n){return new _(p.tag,Dt(r,t+1,n),5)}function Ma(r,t,e,n){return new _(p.tag,Mt(r,t+1,n),9)}function to(r,t){gt(r,p.tag.majorEncoded,t.value)}to.compareTokens=Ft.compareTokens;to.encodedSize=function(t){return gt.encodedSize(t.value)};var nh=20,oh=21,ih=22,sh=23;function Oa(r,t,e,n){if(n.allowUndefined===!1)throw new Error(`${M} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new _(p.null,null,1):new _(p.undefined,void 0,1)}function Fa(r,t,e,n){if(n.allowIndefinite===!1)throw new Error(`${M} indefinite length items not allowed`);return new _(p.break,void 0,1)}function Pi(r,t,e){if(e){if(e.allowNaN===!1&&Number.isNaN(r))throw new Error(`${M} NaN values are not supported`);if(e.allowInfinity===!1&&(r===1/0||r===-1/0))throw new Error(`${M} Infinity values are not supported`)}return new _(p.float,r,t)}function Va(r,t,e,n){return Pi(Di(r,t+1),3,n)}function za(r,t,e,n){return Pi(Mi(r,t+1),5,n)}function Ha(r,t,e,n){return Pi(Ga(r,t+1),9,n)}function eo(r,t,e){let n=t.value;if(n===!1)r.push([p.float.majorEncoded|nh]);else if(n===!0)r.push([p.float.majorEncoded|oh]);else if(n===null)r.push([p.float.majorEncoded|ih]);else if(n===void 0)r.push([p.float.majorEncoded|sh]);else{let o,i=!1;(!e||e.float64!==!0)&&(Ka(n),o=Di(Zt,1),n===o||Number.isNaN(n)?(Zt[0]=249,r.push(Zt.slice(0,3)),i=!0):($a(n),o=Mi(Zt,1),n===o&&(Zt[0]=250,r.push(Zt.slice(0,5)),i=!0))),i||(ch(n),o=Ga(Zt,1),Zt[0]=251,r.push(Zt.slice(0,9)))}}eo.encodedSize=function(t,e){let n=t.value;if(n===!1||n===!0||n===null||n===void 0)return 1;if(!e||e.float64!==!0){Ka(n);let o=Di(Zt,1);if(n===o||Number.isNaN(n))return 3;if($a(n),o=Mi(Zt,1),n===o)return 5}return 9};var qa=new ArrayBuffer(9),Vt=new DataView(qa,1),Zt=new Uint8Array(qa,0);function Ka(r){if(r===1/0)Vt.setUint16(0,31744,!1);else if(r===-1/0)Vt.setUint16(0,64512,!1);else if(Number.isNaN(r))Vt.setUint16(0,32256,!1);else{Vt.setFloat32(0,r);let t=Vt.getUint32(0),e=(t&2139095040)>>23,n=t&8388607;if(e===255)Vt.setUint16(0,31744,!1);else if(e===0)Vt.setUint16(0,(r&2147483648)>>16|n>>13,!1);else{let o=e-127;o<-24?Vt.setUint16(0,0):o<-14?Vt.setUint16(0,(t&2147483648)>>16|1<<24+o,!1):Vt.setUint16(0,(t&2147483648)>>16|o+15<<10|n>>13,!1)}}}function Di(r,t){if(r.length-t<2)throw new Error(`${M} not enough data for float16`);let e=(r[t]<<8)+r[t+1];if(e===31744)return 1/0;if(e===64512)return-1/0;if(e===32256)return NaN;let n=e>>10&31,o=e&1023,i;return n===0?i=o*2**-24:n!==31?i=(o+1024)*2**(n-25):i=o===0?1/0:NaN,e&32768?-i:i}function $a(r){Vt.setFloat32(0,r,!1)}function Mi(r,t){if(r.length-t<4)throw new Error(`${M} not enough data for float32`);let e=(r.byteOffset||0)+t;return new DataView(r.buffer,e,4).getFloat32(0,!1)}function ch(r){Vt.setFloat64(0,r,!1)}function Ga(r,t){if(r.length-t<8)throw new Error(`${M} not enough data for float64`);let e=(r.byteOffset||0)+t;return new DataView(r.buffer,e,8).getFloat64(0,!1)}eo.compareTokens=Ft.compareTokens;function $(r,t,e){throw new Error(`${M} encountered invalid minor (${e}) for major ${r[t]>>>5}`)}function ro(r){return()=>{throw new Error(`${M} ${r}`)}}var S=[];for(let r=0;r<=23;r++)S[r]=$;S[24]=ea;S[25]=ra;S[26]=na;S[27]=oa;S[28]=$;S[29]=$;S[30]=$;S[31]=$;for(let r=32;r<=55;r++)S[r]=$;S[56]=ia;S[57]=sa;S[58]=ca;S[59]=ua;S[60]=$;S[61]=$;S[62]=$;S[63]=$;for(let r=64;r<=87;r++)S[r]=la;S[88]=fa;S[89]=da;S[90]=ha;S[91]=pa;S[92]=$;S[93]=$;S[94]=$;S[95]=ro("indefinite length bytes/strings are not supported");for(let r=96;r<=119;r++)S[r]=ma;S[120]=ga;S[121]=ya;S[122]=ba;S[123]=xa;S[124]=$;S[125]=$;S[126]=$;S[127]=ro("indefinite length bytes/strings are not supported");for(let r=128;r<=151;r++)S[r]=Ea;S[152]=va;S[153]=Sa;S[154]=Aa;S[155]=Ba;S[156]=$;S[157]=$;S[158]=$;S[159]=Ia;for(let r=160;r<=183;r++)S[r]=_a;S[184]=Ca;S[185]=Ta;S[186]=ka;S[187]=Ua;S[188]=$;S[189]=$;S[190]=$;S[191]=La;for(let r=192;r<=215;r++)S[r]=Na;S[216]=Ra;S[217]=Pa;S[218]=Da;S[219]=Ma;S[220]=$;S[221]=$;S[222]=$;S[223]=$;for(let r=224;r<=243;r++)S[r]=ro("simple values are not supported");S[244]=$;S[245]=$;S[246]=$;S[247]=Oa;S[248]=ro("simple values are not supported");S[249]=Va;S[250]=za;S[251]=Ha;S[252]=$;S[253]=$;S[254]=$;S[255]=Fa;var Wt=[];for(let r=0;r<24;r++)Wt[r]=new _(p.uint,r,1);for(let r=-1;r>=-24;r--)Wt[31-r]=new _(p.negint,r,1);Wt[64]=new _(p.bytes,new Uint8Array(0),1);Wt[96]=new _(p.string,"",1);Wt[128]=new _(p.array,0,1);Wt[160]=new _(p.map,0,1);Wt[244]=new _(p.false,!1,1);Wt[245]=new _(p.true,!0,1);Wt[246]=new _(p.null,null,1);function ja(r){switch(r.type){case p.false:return ee([244]);case p.true:return ee([245]);case p.null:return ee([246]);case p.bytes:return r.value.length?void 0:ee([64]);case p.string:return r.value===""?ee([96]):void 0;case p.array:return r.value===0?ee([128]):void 0;case p.map:return r.value===0?ee([160]):void 0;case p.uint:return r.value<24?ee([Number(r.value)]):void 0;case p.negint:if(r.value>=-24)return ee([31-Number(r.value)])}}var uh={float64:!1,mapSorter:dh,quickEncodeToken:ja};function lh(){let r=[];return r[p.uint.major]=Ft,r[p.negint.major]=Xn,r[p.bytes.major]=dr,r[p.string.major]=wa,r[p.array.major]=Qn,r[p.map.major]=Jn,r[p.tag.major]=to,r[p.float.major]=eo,r}var Za=lh(),Oi=new Qr,oo=class r{constructor(t,e){this.obj=t,this.parent=e}includes(t){let e=this;do if(e.obj===t)return!0;while(e=e.parent);return!1}static createCheck(t,e){if(t&&t.includes(e))throw new Error(`${Ni} object contains circular references`);return new r(e,t)}},Be={null:new _(p.null,null),undefined:new _(p.undefined,void 0),true:new _(p.true,!0),false:new _(p.false,!1),emptyArray:new _(p.array,0),emptyMap:new _(p.map,0)},Ie={number(r,t,e,n){return!Number.isInteger(r)||!Number.isSafeInteger(r)?new _(p.float,r):r>=0?new _(p.uint,r):new _(p.negint,r)},bigint(r,t,e,n){return r>=BigInt(0)?new _(p.uint,r):new _(p.negint,r)},Uint8Array(r,t,e,n){return new _(p.bytes,r)},string(r,t,e,n){return new _(p.string,r)},boolean(r,t,e,n){return r?Be.true:Be.false},null(r,t,e,n){return Be.null},undefined(r,t,e,n){return Be.undefined},ArrayBuffer(r,t,e,n){return new _(p.bytes,new Uint8Array(r))},DataView(r,t,e,n){return new _(p.bytes,new Uint8Array(r.buffer,r.byteOffset,r.byteLength))},Array(r,t,e,n){if(!r.length)return e.addBreakTokens===!0?[Be.emptyArray,new _(p.break)]:Be.emptyArray;n=oo.createCheck(n,r);let o=[],i=0;for(let s of r)o[i++]=no(s,e,n);return e.addBreakTokens?[new _(p.array,r.length),o,new _(p.break)]:[new _(p.array,r.length),o]},Object(r,t,e,n){let o=t!=="Object",i=o?r.keys():Object.keys(r),s=o?r.size:i.length;if(!s)return e.addBreakTokens===!0?[Be.emptyMap,new _(p.break)]:Be.emptyMap;n=oo.createCheck(n,r);let c=[],a=0;for(let l of i)c[a++]=[no(l,e,n),no(o?r.get(l):r[l],e,n)];return fh(c,e),e.addBreakTokens?[new _(p.map,s),c,new _(p.break)]:[new _(p.map,s),c]}};Ie.Map=Ie.Object;Ie.Buffer=Ie.Uint8Array;for(let r of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))Ie[`${r}Array`]=Ie.DataView;function no(r,t={},e){let n=Gc(r),o=t&&t.typeEncoders&&t.typeEncoders[n]||Ie[n];if(typeof o=="function"){let s=o(r,n,t,e);if(s!=null)return s}let i=Ie[n];if(!i)throw new Error(`${Ni} unsupported type: ${n}`);return i(r,n,t,e)}function fh(r,t){t.mapSorter&&r.sort(t.mapSorter)}function dh(r,t){let e=Array.isArray(r[0])?r[0][0]:r[0],n=Array.isArray(t[0])?t[0][0]:t[0];if(e.type!==n.type)return e.type.compare(n.type);let o=e.type.major,i=Za[o].compareTokens(e,n);return i===0&&console.warn("WARNING: complex key types used, CBOR key sorting guarantees are gone"),i}function Wa(r,t,e,n){if(Array.isArray(t))for(let o of t)Wa(r,o,e,n);else e[t.type.major](r,t,n)}function hh(r,t,e){let n=no(r,e);if(!Array.isArray(n)&&e.quickEncodeToken){let o=e.quickEncodeToken(n);if(o)return o;let i=t[n.type.major];if(i.encodedSize){let s=i.encodedSize(n,e),c=new Qr(s);if(i(c,n,e),c.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${n} was wrong`);return Li(c.chunks[0])}}return Oi.reset(),Wa(Oi,n,t,e),Oi.toBytes(!0)}function W(r,t){return t=Object.assign({},uh,t),hh(r,Za,t)}var ph={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},io=class{constructor(t,e={}){this._pos=0,this.data=t,this.options=e}pos(){return this._pos}done(){return this._pos>=this.data.length}next(){let t=this.data[this._pos],e=Wt[t];if(e===void 0){let n=S[t];if(!n)throw new Error(`${M} no decoder for major type ${t>>>5} (byte 0x${t.toString(16).padStart(2,"0")})`);let o=t&31;e=n(this.data,this._pos,o,this.options)}return this._pos+=e.encodedLength,e}},rn=Symbol.for("DONE"),so=Symbol.for("BREAK");function mh(r,t,e){let n=[];for(let o=0;o<r.value;o++){let i=mr(t,e);if(i===so){if(r.value===1/0)break;throw new Error(`${M} got unexpected break to lengthed array`)}if(i===rn)throw new Error(`${M} found array but not enough entries (got ${o}, expected ${r.value})`);n[o]=i}return n}function gh(r,t,e){let n=e.useMaps===!0,o=n?void 0:{},i=n?new Map:void 0;for(let s=0;s<r.value;s++){let c=mr(t,e);if(c===so){if(r.value===1/0)break;throw new Error(`${M} got unexpected break to lengthed map`)}if(c===rn)throw new Error(`${M} found map but not enough entries (got ${s} [no key], expected ${r.value})`);if(n!==!0&&typeof c!="string")throw new Error(`${M} non-string keys not supported (got ${typeof c})`);if(e.rejectDuplicateMapKeys===!0&&(n&&i.has(c)||!n&&c in o))throw new Error(`${M} found repeat map key "${c}"`);let a=mr(t,e);if(a===rn)throw new Error(`${M} found map but not enough entries (got ${s} [no value], expected ${r.value})`);n?i.set(c,a):o[c]=a}return n?i:o}function mr(r,t){if(r.done())return rn;let e=r.next();if(e.type===p.break)return so;if(e.type.terminal)return e.value;if(e.type===p.array)return mh(e,r,t);if(e.type===p.map)return gh(e,r,t);if(e.type===p.tag){if(t.tags&&typeof t.tags[e.value]=="function"){let n=mr(r,t);return t.tags[e.value](n)}throw new Error(`${M} tag not supported (${e.value})`)}throw new Error("unsupported")}function Xa(r,t){if(!(r instanceof Uint8Array))throw new Error(`${M} data to decode must be a Uint8Array`);t=Object.assign({},ph,t);let e=t.tokenizer||new io(r,t),n=mr(e,t);if(n===rn)throw new Error(`${M} did not find any content to decode`);if(n===so)throw new Error(`${M} got unexpected break`);return[n,r.subarray(e.pos())]}function X(r,t){let[e,n]=Xa(r,t);if(n.length>0)throw new Error(`${M} too many terminals, data makes no sense`);return e}var yh={type:1026,canEncode:r=>r===!0||r===!1,encode:r=>W(r),decode:r=>X(r)},Ya=yh;var bh={type:1027,canEncode:r=>typeof r=="number"&&!isNaN(r),encode:r=>W(r),decode:r=>X(r)},Qa=bh;var xh={type:1028,canEncode:r=>typeof r=="string",encode:r=>W(r),decode:r=>X(r)},Ja=xh;var wh={type:1029,canEncode:r=>Array.isArray(r),encode:(r,t,e,n)=>W(r.map(o=>t.toValue(o,e,n))),decode:(r,t,e,n)=>X(r).map(o=>t.fromValue(o,e,n))},tu=wh;var Eh={type:1030,canEncode:r=>typeof r=="function",encode:(r,t,e,n)=>{let o=er();return n?.callbacks.set(o,{context:e,fn:r}),W(o)},decode:(r,t,e,n)=>async(...o)=>new Promise((i,s)=>{let c=X(r),a=er(),l={scope:a,result:Kt(),callbacks:new Map,children:new Map,parents:[...n.parents,n.scope],abortControllers:[],abortSignals:[]};n.children.set(a,l),o=o.map(f=>t.toValue(f,null,l));let u=Cn(l.abortSignals);u.addEventListener("abort",()=>{e.push(It.encode({type:K.abortCallbackInvocation,message:ur.encode({scope:a,parents:l.parents})}))}),e.push(It.encode({type:K.invokeCallback,message:ar.encode({scope:a,parents:l.parents,callback:c,args:o})})),l.result.promise.then(f=>{i(f)},f=>{s(f)}).finally(()=>{n.children.delete(a),u.clear()})})},eu=Eh;var vh={type:1031,canEncode:r=>r.toString()==="NaN"&&isNaN(r),decode:()=>NaN},ru=vh;var Sh={type:1032,canEncode:r=>r instanceof Error,encode:r=>W({message:r.message,name:r.name,code:r.code,type:r.type,stack:r.stack}),decode:r=>{let t=X(r),e=new Error(t.message);return e.name=t.name,e.stack=t.stack,e.code=t.code,e.type=t.type,e}},nu=Sh;var Ah={type:1033,canEncode:r=>Array.isArray(r),encode:(r,t,e,n)=>{throw new Error("Promises are not supported")},decode:(r,t,e,n)=>{throw new Error("Promises are not supported")}},ou=Ah;var iu=["__defineGetter__","__defineSetter__","hasOwnProperty","__lookupGetter__","__lookupSetter__","isPrototypeOf","propertyIsEnumerable","toString","valueOf","__proto__","toLocaleString","constructor"],Bh={type:2147483647,canEncode:r=>typeof r=="object",encode:(r,t,e,n)=>{let o={};for(let i in r)iu.includes(i)||Object.hasOwn(r,i)&&(o[i]=r[i]);for(let i of Object.getOwnPropertyNames(Object.getPrototypeOf(r)))iu.includes(i)||(o[i]=r[i]);return W([...Object.entries(o)].map(([i,s])=>[t.toValue(i,r,n),t.toValue(s,r,n)]))},decode:(r,t,e,n)=>{let o={};return X(r).forEach(([s,c])=>{o[t.fromValue(s,e,n)]=t.fromValue(c,e,n)}),o}},nn=Bh;var Ih={type:1034,canEncode:r=>typeof r.next=="function"&&typeof r.throw=="function"&&typeof r.return=="function",encode:(r,t,e,n)=>nn.encode({next:r.next.bind(r),throw:r.throw.bind(r),return:r.return.bind(r)},t,e,n),decode:(r,t,e,n)=>{let o=nn.decode(r,t,e,n);return o[Symbol.asyncIterator]=()=>o,o}},su=Ih;var _h={type:1035,canEncode:r=>typeof r=="bigint",encode:r=>W(r),decode:r=>BigInt(X(r))},cu=_h;var Ch={type:1036,canEncode:r=>r instanceof Map,encode:(r,t,e,n)=>W([...r.entries()].map(([o,i])=>[t.toValue(o,e,n),t.toValue(i,e,n)])),decode:(r,t,e,n)=>{let o=new Map;return X(r).forEach(([s,c])=>{let a=t.fromValue(s,e,n),l=t.fromValue(c,e,n);o.set(a,l)}),o}},au=Ch;var Th={type:1037,canEncode:r=>r instanceof Set,encode:(r,t,e,n)=>W([...r.values()].map(o=>t.toValue(o,e,n))),decode:(r,t,e,n)=>{let o=new Set;return X(r).forEach(s=>{o.add(t.fromValue(s,e,n))}),o}},uu=Th;var kh={type:1038,canEncode:r=>r instanceof Uint8Array,encode:r=>r,decode:r=>r},lu=kh;var Uh={type:1039,canEncode:r=>r instanceof AbortSignal,encode:(r,t,e,n)=>(n?.abortSignals.push(r),new Uint8Array(0)),decode:(r,t,e,n)=>{let o=new AbortController;return n.abortControllers.push(o),o.signal}},fu=Uh;var Lh={type:1040,canEncode:r=>r instanceof Date,encode:r=>W(r.toString()),decode:r=>new Date(X(r))},du=Lh;var Nh={type:1041,canEncode:r=>r instanceof RegExp,encode:r=>W({source:r.source,flags:r.flags}),decode:r=>{let{source:t,flags:e}=X(r);return new RegExp(t,e)}},hu=Nh;var pu=[Kc,$c,Ya,Qa,Ja,tu,eu,ru,nu,ou,su,cu,au,uu,lu,fu,du,hu,nn];var co=class{transformersMap;transformersList;constructor(t){this.transformersList=[...pu,...t?.valueCodecs??[]].sort((e,n)=>e.type<n.type?-1:e.type>n.type?1:0),this.transformersMap={},this.transformersList.forEach(e=>{if(this.transformersMap[e.type]!=null)throw new Error(`Duplicate transformer type ${e.type}`);this.transformersMap[e.type]=e})}toValue(t,e,n){for(let o=0;o<this.transformersList.length;o++){let i=this.transformersList[o];if(i.canEncode(t))return{type:i.type,value:i.encode?.(t,this,e,n)}}throw new Dr(`Unsupported value type "${t}"`)}fromValue(t,e,n){let o=this.transformersMap[t.type];if(o==null)throw new Dr(`Unsupported value type "${t.type}"`);return o.decode(t.value??new Uint8Array(0),this,e,n)}};function Rh(r){return r.isScope===!0}function Ph(r){return r.type===K.invokeMethod||r.type===K.invokeGeneratorMethod||r.type===K.invokeCallback}var Fi=class{source;output;targets;invocations;values;messageHandlers;constructor(t){this.output=Ee(),this.source=Dn(this.output),this.targets=new Map,this.invocations=new Map,this.values=new co(t),this.sink=this.sink.bind(this),this.messageHandlers={[K.invokeMethod]:{decoder:Fe,handler:this.handleInvokeMethod.bind(this)},[K.invokeGeneratorMethod]:{decoder:Fe,handler:this.handleInvokeGeneratorMethod.bind(this)},[K.abortMethodInvocation]:{decoder:Zr,handler:this.handleAbortMethod.bind(this),isScope:!0},[K.methodResolved]:{decoder:cr,handler:this.handleMethodResolved.bind(this),isScope:!0},[K.methodRejected]:{decoder:Wr,handler:this.handleMethodRejected.bind(this),isScope:!0,isError:!0},[K.invokeCallback]:{decoder:ar,handler:this.handleInvokeCallback.bind(this),isScope:!0},[K.abortCallbackInvocation]:{decoder:ur,handler:this.handleAbortCallback.bind(this),isScope:!0},[K.callbackResolved]:{decoder:Xr,handler:this.handleCallbackResolved.bind(this),isScope:!0},[K.callbackRejected]:{decoder:Yr,handler:this.handleCallbackRejected.bind(this),isScope:!0,isError:!0}}}async sink(t){for await(let e of Pr(t))try{let n=It.decode(e),o=this.messageHandlers[n.type];if(o==null)continue;let i=o.decoder.decode(n.message),s;if(Rh(o))try{s=qc(i,this.invocations)}catch{continue}o.handler(i,s).catch(c=>{Ph(n)&&this.sendError(i,c),this.invocations.delete(i.scope)}).finally(()=>{n.type===K.invokeMethod&&this.invocations.delete(i.scope)})}catch{continue}}sendError(t,e){t.parents!=null?this.output.push(It.encode({type:K.callbackRejected,message:Yr.encode({scope:t.scope,parents:t.parents,error:this.values.toValue(e)})})):this.output.push(It.encode({type:K.methodRejected,message:Wr.encode({scope:t.scope,error:this.values.toValue(e)})}))}createClient(t){return this.proxy(t)}createTarget(t,e){if(this.targets.has(t))throw new Fn(`Cannot reuse RPC target name "${t}"`);this.targets.set(t,e)}async handleInvokeMethod(t){if(this.invocations.has(t.scope))throw new Mr;let e=new Map,n=new Map,o={scope:t.scope,result:Kt(),callbacks:e,children:n,parents:[],abortControllers:[],abortSignals:[]};this.invocations.set(t.scope,o);let i=this.lookupInvocationTarget(t.path),s=await i.fn.apply(i.context,t.args.map(c=>this.values.fromValue(c,this.output,o)));this.output.push(It.encode({type:K.methodResolved,message:cr.encode({scope:t.scope,value:this.values.toValue(s)})}))}async handleAbortMethod(t,e){e.abortControllers.forEach(n=>{n.abort()})}async handleInvokeGeneratorMethod(t){if(this.invocations.has(t.scope))throw new Mr;let e=new Map,n=new Map,o={scope:t.scope,result:Kt(),callbacks:e,children:n,parents:[],abortControllers:[],abortSignals:[]};this.invocations.set(t.scope,o);let i=this.lookupInvocationTarget(t.path),s=i.fn.apply(i.context,t.args.map(a=>this.values.fromValue(a,this.output,o)));if(typeof s.next!="function")throw new Vn(`${t.path} did not return an async generator`);let c={next:async()=>{let a=await s.next();return a.done===!0&&this.invocations.delete(t.scope),a},throw:async a=>{try{let l=await s.throw(a);return l.done===!0&&this.invocations.delete(t.scope),l}catch(l){throw this.invocations.delete(t.scope),l}},return:async a=>{let l=await s.return(a);return l.done===!0&&this.invocations.delete(t.scope),l},[Symbol.asyncIterator]:()=>c};this.output.push(It.encode({type:K.methodResolved,message:cr.encode({scope:t.scope,value:this.values.toValue(c,null,o)})}))}lookupInvocationTarget(t){let e=t.split("."),n=this.targets.get(e[0]),o=n;for(let i=1;i<e.length;i++)o=n,n=n?.[e[i]];if(n==null)throw o!=null&&t.endsWith(".then")?new On(`"${t.substring(0,t.length-5)}" was not a function`):new Mn(`Could not find "${t}" on target`);if(typeof n!="function")throw new Or("Invocation target was not a function");return{context:o,fn:n}}async handleMethodResolved(t,e){let n;t.value!=null&&(n=this.values.fromValue(t.value,this.output,e)),e.result.resolve(n)}async handleMethodRejected(t,e){let n;t.error!=null&&(n=this.values.fromValue(t.error,this.output,e)),e.result.reject(n)}async handleInvokeCallback(t,e){let n=e.callbacks.get(t.callback);if(n==null)throw new Hn;let o=await n.fn.apply(n.context,t.args.map(i=>this.values.fromValue(i,this.output,e)));this.output.push(It.encode({type:K.callbackResolved,message:Xr.encode({scope:t.scope,parents:t.parents,value:this.values.toValue(o)})}))}async handleAbortCallback(t,e){e.abortControllers.forEach(n=>{n.abort()})}async handleCallbackResolved(t,e){let n;t.value!=null&&(n=this.values.fromValue(t.value,this.output,e)),e.children.get(t.scope)?.result.resolve(n),e.children.delete(t.scope)}async handleCallbackRejected(t,e){let n;t.error!=null&&(n=this.values.fromValue(t.error,this.output,e)),e.children.get(t.scope)?.result.reject(n),e.children.delete(t.scope)}proxy(t){let e=()=>{},n=this;return new Proxy(e,{get(o,i,s){return n.proxy(`${t==null?"":`${t}.`}${i.toString()}`)},apply(o,i,s){let c,a;function l(){return a==null&&(a=new Promise((f,h)=>{let b=er(),x={scope:b,result:Kt(),callbacks:new Map,children:new Map,parents:[],abortControllers:[],abortSignals:[]};n.invocations.set(b,x),n.output.push(It.encode({type:K.invokeMethod,message:Fe.encode({scope:b,path:t,args:s.map(d=>n.values.toValue(d,null,x))})}));let g=Cn(x.abortSignals);g.addEventListener("abort",()=>{n.output.push(It.encode({type:K.abortMethodInvocation,message:Zr.encode({scope:b})}))}),x.result.promise.then(d=>{f(d)},d=>{h(d)}).finally(()=>{n.invocations.delete(b),g.clear()})})),a}function u(){if(c==null){let f=er(),h={scope:f,result:Kt(),callbacks:new Map,children:new Map,parents:[],abortControllers:[],abortSignals:[]};n.invocations.set(f,h),n.output.push(It.encode({type:K.invokeGeneratorMethod,message:Fe.encode({scope:f,path:t,args:s.map(x=>n.values.toValue(x,null,h))})}));let b;c={async next(){if(b!=null)throw b;let g=await(await h.result.promise).next();return g.done===!0&&n.invocations.delete(f),g},async throw(x){if(b!=null)throw b;try{let d=await(await h.result.promise).throw(x);return d.done===!0&&n.invocations.delete(f),d}catch(g){throw n.invocations.delete(f),b=x,g}},async return(x){if(b!=null)throw b;let d=await(await h.result.promise).return(x);return d.done===!0&&n.invocations.delete(f),d},[Symbol.asyncIterator]:()=>c}}return c}return new Proxy(e,{get(f,h,b){if(h==="then")return l().then.bind(a);if(h==="catch")return l().catch.bind(a);if(h==="finally")return l().finally.bind(a);if(h===Symbol.asyncIterator)return()=>u();if(h==="next")return u().next.bind(c);if(h==="return")return u().return.bind(c);if(h==="throw")return u().throw.bind(c);if(h===Symbol.toStringTag)return"[object Object]";if(h==="constructor")return()=>{};throw new Or(`Property ${h.toString()} was not used as a promise or async generator`)}})}})}};function mu(r){return new Fi(r)}var gu={type:4096,canEncode:r=>r.code!=null&&r.version!=null&&r.multihash!=null&&r["/"]!=null,encode:r=>r.bytes,decode:r=>at.decode(r)};var on=class extends Event{type;detail;constructor(t,e){super(t),this.type=t,this.detail=e}};var yu={type:4099,canEncode:r=>r instanceof on,encode:(r,t,e,n)=>W({type:r.type,detail:t.toValue(r.detail,e,n)}),decode:(r,t,e,n)=>{let{type:o,detail:i}=X(r);return new on(o,t.fromValue(i,e,n))}};function st(r,t="utf8"){let e=$n[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var ao=class{index=0;input="";new(t){return this.index=0,this.input=t,this}readAtomically(t){let e=this.index,n=t();return n===void 0&&(this.index=e),n}parseWith(t){let e=t();if(this.index===this.input.length)return e}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(t){return this.readAtomically(()=>{let e=this.readChar();if(e===t)return e})}readSeparator(t,e,n){return this.readAtomically(()=>{if(!(e>0&&this.readGivenChar(t)===void 0))return n()})}readNumber(t,e,n,o){return this.readAtomically(()=>{let i=0,s=0,c=this.peekChar();if(c===void 0)return;let a=c==="0",l=2**(8*o)-1;for(;;){let u=this.readAtomically(()=>{let f=this.readChar();if(f===void 0)return;let h=Number.parseInt(f,t);if(!Number.isNaN(h))return h});if(u===void 0)break;if(i*=t,i+=u,i>l||(s+=1,e!==void 0&&s>e))return}if(s!==0)return!n&&a&&s>1?void 0:i})}readIPv4Addr(){return this.readAtomically(()=>{let t=new Uint8Array(4);for(let e=0;e<t.length;e++){let n=this.readSeparator(".",e,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;t[e]=n}return t})}readIPv6Addr(){let t=e=>{for(let n=0;n<e.length/2;n++){let o=n*2;if(n<e.length-3){let s=this.readSeparator(":",n,()=>this.readIPv4Addr());if(s!==void 0)return e[o]=s[0],e[o+1]=s[1],e[o+2]=s[2],e[o+3]=s[3],[o+4,!0]}let i=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(i===void 0)return[o,!1];e[o]=i>>8,e[o+1]=i&255}return[e.length,!1]};return this.readAtomically(()=>{let e=new Uint8Array(16),[n,o]=t(e);if(n===16)return e;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let i=new Uint8Array(14),s=16-(n+2),[c]=t(i.subarray(0,s));return e.set(i.subarray(0,c),16-c),e})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var bu=45,Dh=15,gr=new ao;function Vi(r){if(!(r.length>Dh))return gr.new(r).parseWith(()=>gr.readIPv4Addr())}function zi(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>bu))return gr.new(r).parseWith(()=>gr.readIPv6Addr())}function uo(r,t=!1){if(r.includes("%")&&(r=r.split("%")[0]),r.length>bu)return;let e=gr.new(r).parseWith(()=>gr.readIPAddr());if(e)return t&&e.length===4?Uint8Array.from([0,0,0,0,0,0,0,0,0,0,255,255,e[0],e[1],e[2],e[3]]):e}var xw=parseInt("0xFFFF",16),ww=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function Eu(r){return!!Vi(r)}function vu(r){return!!zi(r)}function lo(r){return!!uo(r)}var Su=Eu,zh=vu,Hi=function(r){let t=0;if(r=r.toString().trim(),Su(r)){let e=new Uint8Array(t+4);return r.split(/\./g).forEach(n=>{e[t++]=parseInt(n,10)&255}),e}if(zh(r)){let e=r.split(":",8),n;for(n=0;n<e.length;n++){let i=Su(e[n]),s;i&&(s=Hi(e[n]),e[n]=st(s.slice(0,2),"base16")),s!=null&&++n<8&&e.splice(n,0,st(s.slice(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++){let i=parseInt(e[n],16);o[t++]=i>>8&255,o[t++]=i&255}return o}throw new Error("invalid ip address")},Au=function(r,t=0,e){t=~~t,e=e??r.length-t;let n=new DataView(r.buffer);if(e===4){let o=[];for(let i=0;i<e;i++)o.push(r[t+i]);return o.join(".")}if(e===16){let o=[];for(let i=0;i<e;i+=2)o.push(n.getUint16(t+i).toString(16));return o.join(":").replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}return""};var yr={},qi={},qh=[[4,32,"ip4"],[6,16,"tcp"],[33,16,"dccp"],[41,128,"ip6"],[42,-1,"ip6zone"],[43,8,"ipcidr"],[53,-1,"dns",!0],[54,-1,"dns4",!0],[55,-1,"dns6",!0],[56,-1,"dnsaddr",!0],[132,16,"sctp"],[273,16,"udp"],[275,0,"p2p-webrtc-star"],[276,0,"p2p-webrtc-direct"],[277,0,"p2p-stardust"],[280,0,"webrtc-direct"],[281,0,"webrtc"],[290,0,"p2p-circuit"],[301,0,"udt"],[302,0,"utp"],[400,-1,"unix",!1,!0],[421,-1,"ipfs"],[421,-1,"p2p"],[443,0,"https"],[444,96,"onion"],[445,296,"onion3"],[446,-1,"garlic64"],[448,0,"tls"],[449,-1,"sni"],[460,0,"quic"],[461,0,"quic-v1"],[465,0,"webtransport"],[466,-1,"certhash"],[477,0,"ws"],[478,0,"wss"],[479,0,"p2p-websocket-star"],[480,0,"http"],[481,-1,"http-path"],[777,-1,"memory"]];qh.forEach(r=>{let t=Kh(...r);qi[t.code]=t,yr[t.name]=t});function Kh(r,t,e,n,o){return{code:r,size:t,name:e,resolvable:!!n,path:!!o}}function Y(r){if(typeof r=="number"){if(qi[r]!=null)return qi[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(yr[r]!=null)return yr[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var n1=Y("ip4"),o1=Y("ip6"),i1=Y("ipcidr");function ji(r,t){switch(Y(r).code){case 4:case 41:return Gh(t);case 42:return Gi(t);case 43:return st(t,"base10");case 6:case 273:case 33:case 132:return _u(t).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return Gi(t);case 421:return Xh(t);case 444:return Iu(t);case 445:return Iu(t);case 466:return Wh(t);case 481:return globalThis.encodeURIComponent(Gi(t));default:return st(t,"base16")}}function Zi(r,t){switch(Y(r).code){case 4:return Bu(t);case 41:return Bu(t);case 42:return $i(t);case 43:return ae(t,"base10");case 6:case 273:case 33:case 132:return Wi(parseInt(t,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return $i(t);case 421:return jh(t);case 444:return Yh(t);case 445:return Qh(t);case 466:return Zh(t);case 481:return $i(globalThis.decodeURIComponent(t));default:return ae(t,"base16")}}var Ki=Object.values(Kr).map(r=>r.decoder),$h=function(){let r=Ki[0].or(Ki[1]);return Ki.slice(2).forEach(t=>r=r.or(t)),r}();function Bu(r){if(!lo(r))throw new Error("invalid ip address");return Hi(r)}function Gh(r){let t=Au(r,0,r.length);if(t==null)throw new Error("ipBuff is required");if(!lo(t))throw new Error("invalid ip address");return t}function Wi(r){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,r),new Uint8Array(t)}function _u(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function $i(r){let t=ae(r),e=Uint8Array.from(ve(t.length));return Lt([e,t],e.length+t.length)}function Gi(r){let t=ie(r);if(r=r.slice(dt(t)),r.length!==t)throw new Error("inconsistent lengths");return st(r)}function jh(r){let t;r[0]==="Q"||r[0]==="1"?t=se(tt.decode(`z${r}`)).bytes:t=at.parse(r).multihash.bytes;let e=Uint8Array.from(ve(t.length));return Lt([e,t],e.length+t.length)}function Zh(r){let t=$h.decode(r),e=Uint8Array.from(ve(t.length));return Lt([e,t],e.length+t.length)}function Wh(r){let t=ie(r),e=r.slice(dt(t));if(e.length!==t)throw new Error("inconsistent lengths");return"u"+st(e,"base64url")}function Xh(r){let t=ie(r),e=r.slice(dt(t));if(e.length!==t)throw new Error("inconsistent lengths");return st(e,"base58btc")}function Yh(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=Ht.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=Wi(n);return Lt([e,o],e.length+o.length)}function Qh(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=Ht.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=Wi(n);return Lt([e,o],e.length+o.length)}function Iu(r){let t=r.slice(0,r.length-2),e=r.slice(r.length-2),n=st(t,"base32"),o=_u(e);return`${n}:${o}`}function Cu(r){r=Xi(r);let t=[],e=[],n=null,o=r.split("/").slice(1);if(o.length===1&&o[0]==="")return{bytes:new Uint8Array,string:"/",tuples:[],stringTuples:[],path:null};for(let i=0;i<o.length;i++){let s=o[i],c=Y(s);if(c.size===0){t.push([c.code]),e.push([c.code]);continue}if(i++,i>=o.length)throw new fo("invalid address: "+r);if(c.path===!0){n=Xi(o.slice(i).join("/")),t.push([c.code,Zi(c.code,n)]),e.push([c.code,n]);break}let a=Zi(c.code,o[i]);t.push([c.code,a]),e.push([c.code,ji(c.code,a)])}return{string:Tu(e),bytes:ho(t),tuples:t,stringTuples:e,path:n}}function Yi(r){let t=[],e=[],n=null,o=0;for(;o<r.length;){let i=ie(r,o),s=dt(i),c=Y(i),a=Jh(c,r.slice(o+s));if(a===0){t.push([i]),e.push([i]),o+=s;continue}let l=r.slice(o+s,o+s+a);if(o+=a+s,o>r.length)throw new fo("Invalid address Uint8Array: "+st(r,"base16"));t.push([i,l]);let u=ji(i,l);if(e.push([i,u]),c.path===!0){n=u;break}}return{bytes:Uint8Array.from(r),string:Tu(e),tuples:t,stringTuples:e,path:n}}function Tu(r){let t=[];return r.map(e=>{let n=Y(e[0]);return t.push(n.name),e.length>1&&e[1]!=null&&t.push(e[1]),null}),Xi(t.join("/"))}function ho(r){return Lt(r.map(t=>{let e=Y(t[0]),n=Uint8Array.from(ve(e.code));return t.length>1&&t[1]!=null&&(n=Lt([n,t[1]])),n}))}function Jh(r,t){if(r.size>0)return r.size/8;if(r.size===0)return 0;{let e=ie(t instanceof Uint8Array?t:Uint8Array.from(t));return e+dt(e)}}function Xi(r){return"/"+r.trim().split("/").filter(t=>t).join("/")}var fo=class extends Error{static name="ParseError";name="ParseError";constructor(t){super(`Error parsing address: ${t}`)}};var tp=Symbol.for("nodejs.util.inspect.custom"),Ji=Symbol.for("@multiformats/js-multiaddr/multiaddr"),ep=[Y("dns").code,Y("dns4").code,Y("dns6").code,Y("dnsaddr").code],Qi=class extends Error{constructor(t="No available resolver"){super(t),this.name="NoAvailableResolverError"}},po=class r{bytes;#e;#t;#r;#n;[Ji]=!0;constructor(t){t==null&&(t="");let e;if(t instanceof Uint8Array)e=Yi(t);else if(typeof t=="string"){if(t.length>0&&t.charAt(0)!=="/")throw new Error(`multiaddr "${t}" must start with a "/"`);e=Cu(t)}else if(mo(t))e=Yi(t.bytes);else throw new Error("addr must be a string, Buffer, or another Multiaddr");this.bytes=e.bytes,this.#e=e.string,this.#t=e.tuples,this.#r=e.stringTuples,this.#n=e.path}toString(){return this.#e}toJSON(){return this.toString()}toOptions(){let t,e,n,o,i="",s=Y("tcp"),c=Y("udp"),a=Y("ip4"),l=Y("ip6"),u=Y("dns6"),f=Y("ip6zone");for(let[b,x]of this.stringTuples())b===f.code&&(i=`%${x??""}`),ep.includes(b)&&(e=s.name==="tcp"?"tcp":"udp",o=443,n=`${x??""}${i}`,t=b===u.code?6:4),(b===s.code||b===c.code)&&(e=Y(b).name==="tcp"?"tcp":"udp",o=parseInt(x??"")),(b===a.code||b===l.code)&&(e=Y(b).name==="tcp"?"tcp":"udp",n=`${x??""}${i}`,t=b===l.code?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}}protos(){return this.#t.map(([t])=>Object.assign({},Y(t)))}protoCodes(){return this.#t.map(([t])=>t)}protoNames(){return this.#t.map(([t])=>Y(t).name)}tuples(){return this.#t.map(([t,e])=>e==null?[t]:[t,e])}stringTuples(){return this.#r.map(([t,e])=>e==null?[t]:[t,e])}encapsulate(t){return t=new r(t),new r(this.toString()+t.toString())}decapsulate(t){let e=t.toString(),n=this.toString(),o=n.lastIndexOf(e);if(o<0)throw new Error(`Address ${this.toString()} does not contain subaddress: ${t.toString()}`);return new r(n.slice(0,o))}decapsulateCode(t){let e=this.tuples();for(let n=e.length-1;n>=0;n--)if(e[n][0]===t)return new r(ho(e.slice(0,n)));return this}getPeerId(){try{let t=[];this.stringTuples().forEach(([n,o])=>{n===yr.p2p.code&&t.push([n,o]),n===yr["p2p-circuit"].code&&(t=[])});let e=t.pop();if(e?.[1]!=null){let n=e[1];return n[0]==="Q"||n[0]==="1"?st(tt.decode(`z${n}`),"base58btc"):st(at.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){return this.#n}equals(t){return Gt(this.bytes,t.bytes)}async resolve(t){let e=this.protos().find(i=>i.resolvable);if(e==null)return[this];let n=ku.get(e.name);if(n==null)throw new Qi(`no available resolver for ${e.name}`);return(await n(this,t)).map(i=>ze(i))}nodeAddress(){let t=this.toOptions();if(t.transport!=="tcp"&&t.transport!=="udp")throw new Error(`multiaddr must have a valid format - no protocol with name: "${t.transport}". Must have a valid transport protocol: "{tcp, udp}"`);return{family:t.family,address:t.host,port:t.port}}isThinWaistAddress(t){let e=(t??this).protos();return!(e.length!==2||e[0].code!==4&&e[0].code!==41||e[1].code!==6&&e[1].code!==273)}[tp](){return`Multiaddr(${this.#e})`}};var ku=new Map;function mo(r){return!!r?.[Ji]}function ze(r){return new po(r)}var Uu={type:4097,canEncode:r=>mo(r),encode:r=>r.bytes,decode:r=>ze(r)};function Lu(r){if(!Number.isSafeInteger(r)||r<0)throw new Error("positive integer expected, got "+r)}function rp(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function br(r,...t){if(!rp(r))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(r.length))throw new Error("Uint8Array expected of length "+t+", got length="+r.length)}function Nu(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");Lu(r.outputLen),Lu(r.blockLen)}function xr(r,t=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(t&&r.finished)throw new Error("Hash#digest() has already been called")}function Ru(r,t){br(r);let e=t.outputLen;if(r.length<e)throw new Error("digestInto() expects output buffer of length at least "+e)}var He=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function go(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function Xt(r,t){return r<<32-t|r>>>t}function Pu(r){if(typeof r!="string")throw new Error("utf8ToBytes expected string, got "+typeof r);return new Uint8Array(new TextEncoder().encode(r))}function sn(r){return typeof r=="string"&&(r=Pu(r)),br(r),r}function ts(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];br(o),t+=o.length}let e=new Uint8Array(t);for(let n=0,o=0;n<r.length;n++){let i=r[n];e.set(i,o),o+=i.length}return e}var wr=class{clone(){return this._cloneInto()}};function yo(r){let t=n=>r().update(sn(n)).digest(),e=r();return t.outputLen=e.outputLen,t.blockLen=e.blockLen,t.create=()=>r(),t}function bo(r=32){if(He&&typeof He.getRandomValues=="function")return He.getRandomValues(new Uint8Array(r));if(He&&typeof He.randomBytes=="function")return He.randomBytes(r);throw new Error("crypto.getRandomValues must be defined")}function np(r,t,e,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(t,e,n);let o=BigInt(32),i=BigInt(4294967295),s=Number(e>>o&i),c=Number(e&i),a=n?4:0,l=n?0:4;r.setUint32(t+a,s,n),r.setUint32(t+l,c,n)}function Du(r,t,e){return r&t^~r&e}function Mu(r,t,e){return r&t^r&e^t&e}var Er=class extends wr{constructor(t,e,n,o){super(),this.blockLen=t,this.outputLen=e,this.padOffset=n,this.isLE=o,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=go(this.buffer)}update(t){xr(this);let{view:e,buffer:n,blockLen:o}=this;t=sn(t);let i=t.length;for(let s=0;s<i;){let c=Math.min(o-this.pos,i-s);if(c===o){let a=go(t);for(;o<=i-s;s+=o)this.process(a,s);continue}n.set(t.subarray(s,s+c),this.pos),this.pos+=c,s+=c,this.pos===o&&(this.process(e,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){xr(this),Ru(t,this),this.finished=!0;let{buffer:e,view:n,blockLen:o,isLE:i}=this,{pos:s}=this;e[s++]=128,this.buffer.subarray(s).fill(0),this.padOffset>o-s&&(this.process(n,0),s=0);for(let f=s;f<o;f++)e[f]=0;np(n,o-8,BigInt(this.length*8),i),this.process(n,0);let c=go(t),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let l=a/4,u=this.get();if(l>u.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;f<l;f++)c.setUint32(4*f,u[f],i)}digest(){let{buffer:t,outputLen:e}=this;this.digestInto(t);let n=t.slice(0,e);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());let{blockLen:e,buffer:n,length:o,finished:i,destroyed:s,pos:c}=this;return t.length=o,t.pos=c,t.finished=i,t.destroyed=s,o%e&&t.buffer.set(n),t}};var xo=BigInt(4294967295),es=BigInt(32);function Ou(r,t=!1){return t?{h:Number(r&xo),l:Number(r>>es&xo)}:{h:Number(r>>es&xo)|0,l:Number(r&xo)|0}}function op(r,t=!1){let e=new Uint32Array(r.length),n=new Uint32Array(r.length);for(let o=0;o<r.length;o++){let{h:i,l:s}=Ou(r[o],t);[e[o],n[o]]=[i,s]}return[e,n]}var ip=(r,t)=>BigInt(r>>>0)<<es|BigInt(t>>>0),sp=(r,t,e)=>r>>>e,cp=(r,t,e)=>r<<32-e|t>>>e,ap=(r,t,e)=>r>>>e|t<<32-e,up=(r,t,e)=>r<<32-e|t>>>e,lp=(r,t,e)=>r<<64-e|t>>>e-32,fp=(r,t,e)=>r>>>e-32|t<<64-e,dp=(r,t)=>t,hp=(r,t)=>r,pp=(r,t,e)=>r<<e|t>>>32-e,mp=(r,t,e)=>t<<e|r>>>32-e,gp=(r,t,e)=>t<<e-32|r>>>64-e,yp=(r,t,e)=>r<<e-32|t>>>64-e;function bp(r,t,e,n){let o=(t>>>0)+(n>>>0);return{h:r+e+(o/2**32|0)|0,l:o|0}}var xp=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),wp=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,Ep=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),vp=(r,t,e,n,o)=>t+e+n+o+(r/2**32|0)|0,Sp=(r,t,e,n,o)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(o>>>0),Ap=(r,t,e,n,o,i)=>t+e+n+o+i+(r/2**32|0)|0;var Bp={fromBig:Ou,split:op,toBig:ip,shrSH:sp,shrSL:cp,rotrSH:ap,rotrSL:up,rotrBH:lp,rotrBL:fp,rotr32H:dp,rotr32L:hp,rotlSH:pp,rotlSL:mp,rotlBH:gp,rotlBL:yp,add:bp,add3L:xp,add3H:wp,add4L:Ep,add4H:vp,add5H:Ap,add5L:Sp},F=Bp;var[Ip,_p]=F.split(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(r=>BigInt(r))),_e=new Uint32Array(80),Ce=new Uint32Array(80),rs=class extends Er{constructor(){super(128,64,16,!1),this.Ah=1779033703,this.Al=-205731576,this.Bh=-1150833019,this.Bl=-2067093701,this.Ch=1013904242,this.Cl=-23791573,this.Dh=-1521486534,this.Dl=1595750129,this.Eh=1359893119,this.El=-1377402159,this.Fh=-1694144372,this.Fl=725511199,this.Gh=528734635,this.Gl=-79577749,this.Hh=1541459225,this.Hl=327033209}get(){let{Ah:t,Al:e,Bh:n,Bl:o,Ch:i,Cl:s,Dh:c,Dl:a,Eh:l,El:u,Fh:f,Fl:h,Gh:b,Gl:x,Hh:g,Hl:d}=this;return[t,e,n,o,i,s,c,a,l,u,f,h,b,x,g,d]}set(t,e,n,o,i,s,c,a,l,u,f,h,b,x,g,d){this.Ah=t|0,this.Al=e|0,this.Bh=n|0,this.Bl=o|0,this.Ch=i|0,this.Cl=s|0,this.Dh=c|0,this.Dl=a|0,this.Eh=l|0,this.El=u|0,this.Fh=f|0,this.Fl=h|0,this.Gh=b|0,this.Gl=x|0,this.Hh=g|0,this.Hl=d|0}process(t,e){for(let m=0;m<16;m++,e+=4)_e[m]=t.getUint32(e),Ce[m]=t.getUint32(e+=4);for(let m=16;m<80;m++){let I=_e[m-15]|0,R=Ce[m-15]|0,N=F.rotrSH(I,R,1)^F.rotrSH(I,R,8)^F.shrSH(I,R,7),T=F.rotrSL(I,R,1)^F.rotrSL(I,R,8)^F.shrSL(I,R,7),U=_e[m-2]|0,k=Ce[m-2]|0,J=F.rotrSH(U,k,19)^F.rotrBH(U,k,61)^F.shrSH(U,k,6),q=F.rotrSL(U,k,19)^F.rotrBL(U,k,61)^F.shrSL(U,k,6),z=F.add4L(T,q,Ce[m-7],Ce[m-16]),ct=F.add4H(z,N,J,_e[m-7],_e[m-16]);_e[m]=ct|0,Ce[m]=z|0}let{Ah:n,Al:o,Bh:i,Bl:s,Ch:c,Cl:a,Dh:l,Dl:u,Eh:f,El:h,Fh:b,Fl:x,Gh:g,Gl:d,Hh:E,Hl:A}=this;for(let m=0;m<80;m++){let I=F.rotrSH(f,h,14)^F.rotrSH(f,h,18)^F.rotrBH(f,h,41),R=F.rotrSL(f,h,14)^F.rotrSL(f,h,18)^F.rotrBL(f,h,41),N=f&b^~f&g,T=h&x^~h&d,U=F.add5L(A,R,T,_p[m],Ce[m]),k=F.add5H(U,E,I,N,Ip[m],_e[m]),J=U|0,q=F.rotrSH(n,o,28)^F.rotrBH(n,o,34)^F.rotrBH(n,o,39),z=F.rotrSL(n,o,28)^F.rotrBL(n,o,34)^F.rotrBL(n,o,39),ct=n&i^n&c^i&c,B=o&s^o&a^s&a;E=g|0,A=d|0,g=b|0,d=x|0,b=f|0,x=h|0,{h:f,l:h}=F.add(l|0,u|0,k|0,J|0),l=c|0,u=a|0,c=i|0,a=s|0,i=n|0,s=o|0;let L=F.add3L(J,z,B);n=F.add3H(L,k,q,ct),o=L|0}({h:n,l:o}=F.add(this.Ah|0,this.Al|0,n|0,o|0)),{h:i,l:s}=F.add(this.Bh|0,this.Bl|0,i|0,s|0),{h:c,l:a}=F.add(this.Ch|0,this.Cl|0,c|0,a|0),{h:l,l:u}=F.add(this.Dh|0,this.Dl|0,l|0,u|0),{h:f,l:h}=F.add(this.Eh|0,this.El|0,f|0,h|0),{h:b,l:x}=F.add(this.Fh|0,this.Fl|0,b|0,x|0),{h:g,l:d}=F.add(this.Gh|0,this.Gl|0,g|0,d|0),{h:E,l:A}=F.add(this.Hh|0,this.Hl|0,E|0,A|0),this.set(n,o,i,s,c,a,l,u,f,h,b,x,g,d,E,A)}roundClean(){_e.fill(0),Ce.fill(0)}destroy(){this.buffer.fill(0),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var Fu=yo(()=>new rs);var vo={};Ct(vo,{aInRange:()=>kt,abool:()=>Yt,abytes:()=>vr,bitGet:()=>Np,bitLen:()=>ss,bitMask:()=>an,bitSet:()=>Rp,bytesToHex:()=>de,bytesToNumberBE:()=>he,bytesToNumberLE:()=>ke,concatBytes:()=>pe,createHmacDrbg:()=>cs,ensureBytes:()=>ot,equalBytes:()=>Up,hexToBytes:()=>Ke,hexToNumber:()=>is,inRange:()=>cn,isBytes:()=>Te,memoized:()=>Ge,notImplemented:()=>Dp,numberToBytesBE:()=>Ue,numberToBytesLE:()=>$e,numberToHexUnpadded:()=>qe,numberToVarBytesBE:()=>kp,utf8ToBytes:()=>Lp,validateObject:()=>re});var wo=BigInt(0),Eo=BigInt(1),Cp=BigInt(2);function Te(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function vr(r){if(!Te(r))throw new Error("Uint8Array expected")}function Yt(r,t){if(typeof t!="boolean")throw new Error(r+" boolean expected, got "+t)}var Tp=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function de(r){vr(r);let t="";for(let e=0;e<r.length;e++)t+=Tp[r[e]];return t}function qe(r){let t=r.toString(16);return t.length&1?"0"+t:t}function is(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return r===""?wo:BigInt("0x"+r)}var fe={_0:48,_9:57,A:65,F:70,a:97,f:102};function Vu(r){if(r>=fe._0&&r<=fe._9)return r-fe._0;if(r>=fe.A&&r<=fe.F)return r-(fe.A-10);if(r>=fe.a&&r<=fe.f)return r-(fe.a-10)}function Ke(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);let t=r.length,e=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(e);for(let o=0,i=0;o<e;o++,i+=2){let s=Vu(r.charCodeAt(i)),c=Vu(r.charCodeAt(i+1));if(s===void 0||c===void 0){let a=r[i]+r[i+1];throw new Error('hex string expected, got non-hex character "'+a+'" at index '+i)}n[o]=s*16+c}return n}function he(r){return is(de(r))}function ke(r){return vr(r),is(de(Uint8Array.from(r).reverse()))}function Ue(r,t){return Ke(r.toString(16).padStart(t*2,"0"))}function $e(r,t){return Ue(r,t).reverse()}function kp(r){return Ke(qe(r))}function ot(r,t,e){let n;if(typeof t=="string")try{n=Ke(t)}catch(i){throw new Error(r+" must be hex string or Uint8Array, cause: "+i)}else if(Te(t))n=Uint8Array.from(t);else throw new Error(r+" must be hex string or Uint8Array");let o=n.length;if(typeof e=="number"&&o!==e)throw new Error(r+" of length "+e+" expected, got "+o);return n}function pe(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];vr(o),t+=o.length}let e=new Uint8Array(t);for(let n=0,o=0;n<r.length;n++){let i=r[n];e.set(i,o),o+=i.length}return e}function Up(r,t){if(r.length!==t.length)return!1;let e=0;for(let n=0;n<r.length;n++)e|=r[n]^t[n];return e===0}function Lp(r){if(typeof r!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(r))}var ns=r=>typeof r=="bigint"&&wo<=r;function cn(r,t,e){return ns(r)&&ns(t)&&ns(e)&&t<=r&&r<e}function kt(r,t,e,n){if(!cn(t,e,n))throw new Error("expected valid "+r+": "+e+" <= n < "+n+", got "+t)}function ss(r){let t;for(t=0;r>wo;r>>=Eo,t+=1);return t}function Np(r,t){return r>>BigInt(t)&Eo}function Rp(r,t,e){return r|(e?Eo:wo)<<BigInt(t)}var an=r=>(Cp<<BigInt(r-1))-Eo,os=r=>new Uint8Array(r),zu=r=>Uint8Array.from(r);function cs(r,t,e){if(typeof r!="number"||r<2)throw new Error("hashLen must be a number");if(typeof t!="number"||t<2)throw new Error("qByteLen must be a number");if(typeof e!="function")throw new Error("hmacFn must be a function");let n=os(r),o=os(r),i=0,s=()=>{n.fill(1),o.fill(0),i=0},c=(...f)=>e(o,n,...f),a=(f=os())=>{o=c(zu([0]),f),n=c(),f.length!==0&&(o=c(zu([1]),f),n=c())},l=()=>{if(i++>=1e3)throw new Error("drbg: tried 1000 values");let f=0,h=[];for(;f<t;){n=c();let b=n.slice();h.push(b),f+=n.length}return pe(...h)};return(f,h)=>{s(),a(f);let b;for(;!(b=h(l()));)a();return s(),b}}var Pp={bigint:r=>typeof r=="bigint",function:r=>typeof r=="function",boolean:r=>typeof r=="boolean",string:r=>typeof r=="string",stringOrUint8Array:r=>typeof r=="string"||Te(r),isSafeInteger:r=>Number.isSafeInteger(r),array:r=>Array.isArray(r),field:(r,t)=>t.Fp.isValid(r),hash:r=>typeof r=="function"&&Number.isSafeInteger(r.outputLen)};function re(r,t,e={}){let n=(o,i,s)=>{let c=Pp[i];if(typeof c!="function")throw new Error("invalid validator function");let a=r[o];if(!(s&&a===void 0)&&!c(a,r))throw new Error("param "+String(o)+" is invalid. Expected "+i+", got "+a)};for(let[o,i]of Object.entries(t))n(o,i,!1);for(let[o,i]of Object.entries(e))n(o,i,!0);return r}var Dp=()=>{throw new Error("not implemented")};function Ge(r){let t=new WeakMap;return(e,...n)=>{let o=t.get(e);if(o!==void 0)return o;let i=r(e,...n);return t.set(e,i),i}}var ut=BigInt(0),rt=BigInt(1),je=BigInt(2),Mp=BigInt(3),as=BigInt(4),Hu=BigInt(5),qu=BigInt(8),Op=BigInt(9),Fp=BigInt(16);function Z(r,t){let e=r%t;return e>=ut?e:t+e}function Vp(r,t,e){if(t<ut)throw new Error("invalid exponent, negatives unsupported");if(e<=ut)throw new Error("invalid modulus");if(e===rt)return ut;let n=rt;for(;t>ut;)t&rt&&(n=n*r%e),r=r*r%e,t>>=rt;return n}function nt(r,t,e){let n=r;for(;t-- >ut;)n*=n,n%=e;return n}function So(r,t){if(r===ut)throw new Error("invert: expected non-zero number");if(t<=ut)throw new Error("invert: expected positive modulus, got "+t);let e=Z(r,t),n=t,o=ut,i=rt,s=rt,c=ut;for(;e!==ut;){let l=n/e,u=n%e,f=o-s*l,h=i-c*l;n=e,e=u,o=s,i=c,s=f,c=h}if(n!==rt)throw new Error("invert: does not exist");return Z(o,t)}function zp(r){let t=(r-rt)/je,e,n,o;for(e=r-rt,n=0;e%je===ut;e/=je,n++);for(o=je;o<r&&Vp(o,t,r)!==r-rt;o++)if(o>1e3)throw new Error("Cannot find square root: likely non-prime P");if(n===1){let s=(r+rt)/as;return function(a,l){let u=a.pow(l,s);if(!a.eql(a.sqr(u),l))throw new Error("Cannot find square root");return u}}let i=(e+rt)/je;return function(c,a){if(c.pow(a,t)===c.neg(c.ONE))throw new Error("Cannot find square root");let l=n,u=c.pow(c.mul(c.ONE,o),e),f=c.pow(a,i),h=c.pow(a,e);for(;!c.eql(h,c.ONE);){if(c.eql(h,c.ZERO))return c.ZERO;let b=1;for(let g=c.sqr(h);b<l&&!c.eql(g,c.ONE);b++)g=c.sqr(g);let x=c.pow(u,rt<<BigInt(l-b-1));u=c.sqr(x),f=c.mul(f,x),h=c.mul(h,u),l=b}return f}}function Hp(r){if(r%as===Mp){let t=(r+rt)/as;return function(n,o){let i=n.pow(o,t);if(!n.eql(n.sqr(i),o))throw new Error("Cannot find square root");return i}}if(r%qu===Hu){let t=(r-Hu)/qu;return function(n,o){let i=n.mul(o,je),s=n.pow(i,t),c=n.mul(o,s),a=n.mul(n.mul(c,je),s),l=n.mul(c,n.sub(a,n.ONE));if(!n.eql(n.sqr(l),o))throw new Error("Cannot find square root");return l}}return r%Fp,zp(r)}var Ku=(r,t)=>(Z(r,t)&rt)===rt,qp=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function us(r){let t={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},e=qp.reduce((n,o)=>(n[o]="function",n),t);return re(r,e)}function Kp(r,t,e){if(e<ut)throw new Error("invalid exponent, negatives unsupported");if(e===ut)return r.ONE;if(e===rt)return t;let n=r.ONE,o=t;for(;e>ut;)e&rt&&(n=r.mul(n,o)),o=r.sqr(o),e>>=rt;return n}function $p(r,t){let e=new Array(t.length),n=t.reduce((i,s,c)=>r.is0(s)?i:(e[c]=i,r.mul(i,s)),r.ONE),o=r.inv(n);return t.reduceRight((i,s,c)=>r.is0(s)?i:(e[c]=r.mul(i,e[c]),r.mul(i,s)),o),e}function ls(r,t){let e=t!==void 0?t:r.toString(2).length,n=Math.ceil(e/8);return{nBitLength:e,nByteLength:n}}function Le(r,t,e=!1,n={}){if(r<=ut)throw new Error("invalid field: expected ORDER > 0, got "+r);let{nBitLength:o,nByteLength:i}=ls(r,t);if(i>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let s,c=Object.freeze({ORDER:r,isLE:e,BITS:o,BYTES:i,MASK:an(o),ZERO:ut,ONE:rt,create:a=>Z(a,r),isValid:a=>{if(typeof a!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof a);return ut<=a&&a<r},is0:a=>a===ut,isOdd:a=>(a&rt)===rt,neg:a=>Z(-a,r),eql:(a,l)=>a===l,sqr:a=>Z(a*a,r),add:(a,l)=>Z(a+l,r),sub:(a,l)=>Z(a-l,r),mul:(a,l)=>Z(a*l,r),pow:(a,l)=>Kp(c,a,l),div:(a,l)=>Z(a*So(l,r),r),sqrN:a=>a*a,addN:(a,l)=>a+l,subN:(a,l)=>a-l,mulN:(a,l)=>a*l,inv:a=>So(a,r),sqrt:n.sqrt||(a=>(s||(s=Hp(r)),s(c,a))),invertBatch:a=>$p(c,a),cmov:(a,l,u)=>u?l:a,toBytes:a=>e?$e(a,i):Ue(a,i),fromBytes:a=>{if(a.length!==i)throw new Error("Field.fromBytes: expected "+i+" bytes, got "+a.length);return e?ke(a):he(a)}});return Object.freeze(c)}function $u(r){if(typeof r!="bigint")throw new Error("field order must be bigint");let t=r.toString(2).length;return Math.ceil(t/8)}function fs(r){let t=$u(r);return t+Math.ceil(t/2)}function Gu(r,t,e=!1){let n=r.length,o=$u(t),i=fs(t);if(n<16||n<i||n>1024)throw new Error("expected "+i+"-1024 bytes of input, got "+n);let s=e?ke(r):he(r),c=Z(s,t-rt)+rt;return e?$e(c,o):Ue(c,o)}var ju=BigInt(0),Ao=BigInt(1);function ds(r,t){let e=t.negate();return r?e:t}function Zu(r,t){if(!Number.isSafeInteger(r)||r<=0||r>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+r)}function hs(r,t){Zu(r,t);let e=Math.ceil(t/r)+1,n=2**(r-1);return{windows:e,windowSize:n}}function Gp(r,t){if(!Array.isArray(r))throw new Error("array expected");r.forEach((e,n)=>{if(!(e instanceof t))throw new Error("invalid point at index "+n)})}function jp(r,t){if(!Array.isArray(r))throw new Error("array of scalars expected");r.forEach((e,n)=>{if(!t.isValid(e))throw new Error("invalid scalar at index "+n)})}var ps=new WeakMap,Wu=new WeakMap;function ms(r){return Wu.get(r)||1}function Bo(r,t){return{constTimeNegate:ds,hasPrecomputes(e){return ms(e)!==1},unsafeLadder(e,n,o=r.ZERO){let i=e;for(;n>ju;)n&Ao&&(o=o.add(i)),i=i.double(),n>>=Ao;return o},precomputeWindow(e,n){let{windows:o,windowSize:i}=hs(n,t),s=[],c=e,a=c;for(let l=0;l<o;l++){a=c,s.push(a);for(let u=1;u<i;u++)a=a.add(c),s.push(a);c=a.double()}return s},wNAF(e,n,o){let{windows:i,windowSize:s}=hs(e,t),c=r.ZERO,a=r.BASE,l=BigInt(2**e-1),u=2**e,f=BigInt(e);for(let h=0;h<i;h++){let b=h*s,x=Number(o&l);o>>=f,x>s&&(x-=u,o+=Ao);let g=b,d=b+Math.abs(x)-1,E=h%2!==0,A=x<0;x===0?a=a.add(ds(E,n[g])):c=c.add(ds(A,n[d]))}return{p:c,f:a}},wNAFUnsafe(e,n,o,i=r.ZERO){let{windows:s,windowSize:c}=hs(e,t),a=BigInt(2**e-1),l=2**e,u=BigInt(e);for(let f=0;f<s;f++){let h=f*c;if(o===ju)break;let b=Number(o&a);if(o>>=u,b>c&&(b-=l,o+=Ao),b===0)continue;let x=n[h+Math.abs(b)-1];b<0&&(x=x.negate()),i=i.add(x)}return i},getPrecomputes(e,n,o){let i=ps.get(n);return i||(i=this.precomputeWindow(n,e),e!==1&&ps.set(n,o(i))),i},wNAFCached(e,n,o){let i=ms(e);return this.wNAF(i,this.getPrecomputes(i,e,o),n)},wNAFCachedUnsafe(e,n,o,i){let s=ms(e);return s===1?this.unsafeLadder(e,n,i):this.wNAFUnsafe(s,this.getPrecomputes(s,e,o),n,i)},setWindowSize(e,n){Zu(n,t),Wu.set(e,n),ps.delete(e)}}}function Io(r,t,e,n){if(Gp(e,r),jp(n,t),e.length!==n.length)throw new Error("arrays of points and scalars must have equal length");let o=r.ZERO,i=ss(BigInt(e.length)),s=i>12?i-3:i>4?i-2:i?2:1,c=(1<<s)-1,a=new Array(c+1).fill(o),l=Math.floor((t.BITS-1)/s)*s,u=o;for(let f=l;f>=0;f-=s){a.fill(o);for(let b=0;b<n.length;b++){let x=n[b],g=Number(x>>BigInt(f)&BigInt(c));a[g]=a[g].add(e[b])}let h=o;for(let b=a.length-1,x=o;b>0;b--)x=x.add(a[b]),h=h.add(x);if(u=u.add(h),f!==0)for(let b=0;b<s;b++)u=u.double()}return u}function un(r){return us(r.Fp),re(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...ls(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}var Qt=BigInt(0),Ut=BigInt(1),_o=BigInt(2),Zp=BigInt(8),Wp={zip215:!0};function Xp(r){let t=un(r);return re(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...t})}function Xu(r){let t=Xp(r),{Fp:e,n,prehash:o,hash:i,randomBytes:s,nByteLength:c,h:a}=t,l=_o<<BigInt(c*8)-Ut,u=e.create,f=Le(t.n,t.nBitLength),h=t.uvRatio||((w,y)=>{try{return{isValid:!0,value:e.sqrt(w*e.inv(y))}}catch{return{isValid:!1,value:Qt}}}),b=t.adjustScalarBytes||(w=>w),x=t.domain||((w,y,v)=>{if(Yt("phflag",v),y.length||v)throw new Error("Contexts/pre-hash are not supported");return w});function g(w,y){kt("coordinate "+w,y,Qt,l)}function d(w){if(!(w instanceof m))throw new Error("ExtendedPoint expected")}let E=Ge((w,y)=>{let{ex:v,ey:C,ez:P}=w,D=w.is0();y==null&&(y=D?Zp:e.inv(P));let V=u(v*y),H=u(C*y),O=u(P*y);if(D)return{x:Qt,y:Ut};if(O!==Ut)throw new Error("invZ was invalid");return{x:V,y:H}}),A=Ge(w=>{let{a:y,d:v}=t;if(w.is0())throw new Error("bad point: ZERO");let{ex:C,ey:P,ez:D,et:V}=w,H=u(C*C),O=u(P*P),j=u(D*D),Q=u(j*j),lt=u(H*y),ft=u(j*u(lt+O)),mt=u(Q+u(v*u(H*O)));if(ft!==mt)throw new Error("bad point: equation left != right (1)");let yt=u(C*P),_t=u(D*V);if(yt!==_t)throw new Error("bad point: equation left != right (2)");return!0});class m{constructor(y,v,C,P){this.ex=y,this.ey=v,this.ez=C,this.et=P,g("x",y),g("y",v),g("z",C),g("t",P),Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(y){if(y instanceof m)throw new Error("extended point not allowed");let{x:v,y:C}=y||{};return g("x",v),g("y",C),new m(v,C,Ut,u(v*C))}static normalizeZ(y){let v=e.invertBatch(y.map(C=>C.ez));return y.map((C,P)=>C.toAffine(v[P])).map(m.fromAffine)}static msm(y,v){return Io(m,f,y,v)}_setWindowSize(y){N.setWindowSize(this,y)}assertValidity(){A(this)}equals(y){d(y);let{ex:v,ey:C,ez:P}=this,{ex:D,ey:V,ez:H}=y,O=u(v*H),j=u(D*P),Q=u(C*H),lt=u(V*P);return O===j&&Q===lt}is0(){return this.equals(m.ZERO)}negate(){return new m(u(-this.ex),this.ey,this.ez,u(-this.et))}double(){let{a:y}=t,{ex:v,ey:C,ez:P}=this,D=u(v*v),V=u(C*C),H=u(_o*u(P*P)),O=u(y*D),j=v+C,Q=u(u(j*j)-D-V),lt=O+V,ft=lt-H,mt=O-V,yt=u(Q*ft),_t=u(lt*mt),vt=u(Q*mt),Jt=u(ft*lt);return new m(yt,_t,Jt,vt)}add(y){d(y);let{a:v,d:C}=t,{ex:P,ey:D,ez:V,et:H}=this,{ex:O,ey:j,ez:Q,et:lt}=y;if(v===BigInt(-1)){let Cs=u((D-P)*(j+O)),Ts=u((D+P)*(j-O)),Vo=u(Ts-Cs);if(Vo===Qt)return this.double();let ks=u(V*_o*lt),Us=u(H*_o*Q),Ls=Us+ks,Ns=Ts+Cs,Rs=Us-ks,kl=u(Ls*Vo),Ul=u(Ns*Rs),Ll=u(Ls*Rs),Nl=u(Vo*Ns);return new m(kl,Ul,Nl,Ll)}let ft=u(P*O),mt=u(D*j),yt=u(H*C*lt),_t=u(V*Q),vt=u((P+D)*(O+j)-ft-mt),Jt=_t-yt,ne=_t+yt,Br=u(mt-v*ft),Il=u(vt*Jt),_l=u(ne*Br),Cl=u(vt*Br),Tl=u(Jt*ne);return new m(Il,_l,Tl,Cl)}subtract(y){return this.add(y.negate())}wNAF(y){return N.wNAFCached(this,y,m.normalizeZ)}multiply(y){let v=y;kt("scalar",v,Ut,n);let{p:C,f:P}=this.wNAF(v);return m.normalizeZ([C,P])[0]}multiplyUnsafe(y,v=m.ZERO){let C=y;return kt("scalar",C,Qt,n),C===Qt?R:this.is0()||C===Ut?this:N.wNAFCachedUnsafe(this,C,m.normalizeZ,v)}isSmallOrder(){return this.multiplyUnsafe(a).is0()}isTorsionFree(){return N.unsafeLadder(this,n).is0()}toAffine(y){return E(this,y)}clearCofactor(){let{h:y}=t;return y===Ut?this:this.multiplyUnsafe(y)}static fromHex(y,v=!1){let{d:C,a:P}=t,D=e.BYTES;y=ot("pointHex",y,D),Yt("zip215",v);let V=y.slice(),H=y[D-1];V[D-1]=H&-129;let O=ke(V),j=v?l:e.ORDER;kt("pointHex.y",O,Qt,j);let Q=u(O*O),lt=u(Q-Ut),ft=u(C*Q-P),{isValid:mt,value:yt}=h(lt,ft);if(!mt)throw new Error("Point.fromHex: invalid y coordinate");let _t=(yt&Ut)===Ut,vt=(H&128)!==0;if(!v&&yt===Qt&&vt)throw new Error("Point.fromHex: x=0 and x_0=1");return vt!==_t&&(yt=u(-yt)),m.fromAffine({x:yt,y:O})}static fromPrivateKey(y){return k(y).point}toRawBytes(){let{x:y,y:v}=this.toAffine(),C=$e(v,e.BYTES);return C[C.length-1]|=y&Ut?128:0,C}toHex(){return de(this.toRawBytes())}}m.BASE=new m(t.Gx,t.Gy,Ut,u(t.Gx*t.Gy)),m.ZERO=new m(Qt,Ut,Ut,Qt);let{BASE:I,ZERO:R}=m,N=Bo(m,c*8);function T(w){return Z(w,n)}function U(w){return T(ke(w))}function k(w){let y=e.BYTES;w=ot("private key",w,y);let v=ot("hashed private key",i(w),2*y),C=b(v.slice(0,y)),P=v.slice(y,2*y),D=U(C),V=I.multiply(D),H=V.toRawBytes();return{head:C,prefix:P,scalar:D,point:V,pointBytes:H}}function J(w){return k(w).pointBytes}function q(w=new Uint8Array,...y){let v=pe(...y);return U(i(x(v,ot("context",w),!!o)))}function z(w,y,v={}){w=ot("message",w),o&&(w=o(w));let{prefix:C,scalar:P,pointBytes:D}=k(y),V=q(v.context,C,w),H=I.multiply(V).toRawBytes(),O=q(v.context,H,D,w),j=T(V+O*P);kt("signature.s",j,Qt,n);let Q=pe(H,$e(j,e.BYTES));return ot("result",Q,e.BYTES*2)}let ct=Wp;function B(w,y,v,C=ct){let{context:P,zip215:D}=C,V=e.BYTES;w=ot("signature",w,2*V),y=ot("message",y),v=ot("publicKey",v,V),D!==void 0&&Yt("zip215",D),o&&(y=o(y));let H=ke(w.slice(V,2*V)),O,j,Q;try{O=m.fromHex(v,D),j=m.fromHex(w.slice(0,V),D),Q=I.multiplyUnsafe(H)}catch{return!1}if(!D&&O.isSmallOrder())return!1;let lt=q(P,j.toRawBytes(),O.toRawBytes(),y);return j.add(O.multiplyUnsafe(lt)).subtract(Q).clearCofactor().equals(m.ZERO)}return I._setWindowSize(8),{CURVE:t,getPublicKey:J,sign:z,verify:B,ExtendedPoint:m,utils:{getExtendedPublicKey:k,randomPrivateKey:()=>s(e.BYTES),precompute(w=8,y=m.BASE){return y._setWindowSize(w),y.multiply(BigInt(3)),y}}}}var gs=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),Yu=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),s2=BigInt(0),Yp=BigInt(1),Qu=BigInt(2),c2=BigInt(3),Qp=BigInt(5),Jp=BigInt(8);function t0(r){let t=BigInt(10),e=BigInt(20),n=BigInt(40),o=BigInt(80),i=gs,c=r*r%i*r%i,a=nt(c,Qu,i)*c%i,l=nt(a,Yp,i)*r%i,u=nt(l,Qp,i)*l%i,f=nt(u,t,i)*u%i,h=nt(f,e,i)*f%i,b=nt(h,n,i)*h%i,x=nt(b,o,i)*b%i,g=nt(x,o,i)*b%i,d=nt(g,t,i)*u%i;return{pow_p_5_8:nt(d,Qu,i)*r%i,b2:c}}function e0(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function r0(r,t){let e=gs,n=Z(t*t*t,e),o=Z(n*n*t,e),i=t0(r*o).pow_p_5_8,s=Z(r*n*i,e),c=Z(t*s*s,e),a=s,l=Z(s*Yu,e),u=c===r,f=c===Z(-r,e),h=c===Z(-r*Yu,e);return u&&(s=a),(f||h)&&(s=l),Ku(s,e)&&(s=Z(-s,e)),{isValid:u||f,value:s}}var n0=Le(gs,void 0,!0),o0={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:n0,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:Jp,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:Fu,randomBytes:bo,adjustScalarBytes:e0,uvRatio:r0},Ju=Xu(o0);var Co=32;function tl(r,t,e){return Ju.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}var To=class{type="Ed25519";raw;constructor(t){this.raw=ys(t,Co)}toMultihash(){return ce.digest(ko(this))}toCID(){return at.createV1(114,this.toMultihash())}toString(){return tt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:Gt(this.raw,t.raw)}verify(t,e){return tl(this.raw,e,t)}};function rl(r){return r=ys(r,Co),new To(r)}function ys(r,t){if(r=Uint8Array.from(r??[]),r.length!==t)throw new ye(`Key must be a Uint8Array of length ${t}, got ${r.length}`);return r}var zt;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1"})(zt||(zt={}));var bs;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1"})(bs||(bs={}));(function(r){r.codec=()=>jr(bs)})(zt||(zt={}));var ln;(function(r){let t;r.codec=()=>(t==null&&(t=Bt((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),zt.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 c=e.uint32();switch(c>>>3){case 1:{i.Type=zt.codec().decode(e);break}case 2:{i.Data=e.bytes();break}default:{e.skipType(c&7);break}}}return i})),t),r.encode=e=>At(e,r.codec()),r.decode=(e,n)=>St(e,r.codec(),n)})(ln||(ln={}));var xs;(function(r){let t;r.codec=()=>(t==null&&(t=Bt((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),zt.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 c=e.uint32();switch(c>>>3){case 1:{i.Type=zt.codec().decode(e);break}case 2:{i.Data=e.bytes();break}default:{e.skipType(c&7);break}}}return i})),t),r.encode=e=>At(e,r.codec()),r.decode=(e,n)=>St(e,r.codec(),n)})(xs||(xs={}));var c0=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Ne=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Re=new Uint32Array(64),ws=class extends Er{constructor(){super(64,32,8,!1),this.A=Ne[0]|0,this.B=Ne[1]|0,this.C=Ne[2]|0,this.D=Ne[3]|0,this.E=Ne[4]|0,this.F=Ne[5]|0,this.G=Ne[6]|0,this.H=Ne[7]|0}get(){let{A:t,B:e,C:n,D:o,E:i,F:s,G:c,H:a}=this;return[t,e,n,o,i,s,c,a]}set(t,e,n,o,i,s,c,a){this.A=t|0,this.B=e|0,this.C=n|0,this.D=o|0,this.E=i|0,this.F=s|0,this.G=c|0,this.H=a|0}process(t,e){for(let f=0;f<16;f++,e+=4)Re[f]=t.getUint32(e,!1);for(let f=16;f<64;f++){let h=Re[f-15],b=Re[f-2],x=Xt(h,7)^Xt(h,18)^h>>>3,g=Xt(b,17)^Xt(b,19)^b>>>10;Re[f]=g+Re[f-7]+x+Re[f-16]|0}let{A:n,B:o,C:i,D:s,E:c,F:a,G:l,H:u}=this;for(let f=0;f<64;f++){let h=Xt(c,6)^Xt(c,11)^Xt(c,25),b=u+h+Du(c,a,l)+c0[f]+Re[f]|0,g=(Xt(n,2)^Xt(n,13)^Xt(n,22))+Mu(n,o,i)|0;u=l,l=a,a=c,c=s+b|0,s=i,i=o,o=n,n=b+g|0}n=n+this.A|0,o=o+this.B|0,i=i+this.C|0,s=s+this.D|0,c=c+this.E|0,a=a+this.F|0,l=l+this.G|0,u=u+this.H|0,this.set(n,o,i,s,c,a,l,u)}roundClean(){Re.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var nl=yo(()=>new ws);var fn=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}};var Uo=class extends wr{constructor(t,e){super(),this.finished=!1,this.destroyed=!1,Nu(t);let n=sn(e);if(this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let o=this.blockLen,i=new Uint8Array(o);i.set(n.length>o?t.create().update(n).digest():n);for(let s=0;s<i.length;s++)i[s]^=54;this.iHash.update(i),this.oHash=t.create();for(let s=0;s<i.length;s++)i[s]^=106;this.oHash.update(i),i.fill(0)}update(t){return xr(this),this.iHash.update(t),this}digestInto(t){xr(this),br(t,this.outputLen),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}));let{oHash:e,iHash:n,finished:o,destroyed:i,blockLen:s,outputLen:c}=this;return t=t,t.finished=o,t.destroyed=i,t.blockLen=s,t.outputLen=c,t.oHash=e._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Es=(r,t,e)=>new Uo(r,t).update(e).digest();Es.create=(r,t)=>new Uo(r,t);function ol(r){r.lowS!==void 0&&Yt("lowS",r.lowS),r.prehash!==void 0&&Yt("prehash",r.prehash)}function a0(r){let t=un(r);re(t,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});let{endo:e,Fp:n,a:o}=t;if(e){if(!n.eql(o,n.ZERO))throw new Error("invalid endomorphism, can only be defined for Koblitz curves that have a=0");if(typeof e!="object"||typeof e.beta!="bigint"||typeof e.splitScalar!="function")throw new Error("invalid endomorphism, expected beta: bigint and splitScalar: function")}return Object.freeze({...t})}var{bytesToNumberBE:u0,hexToBytes:l0}=vo,vs=class extends Error{constructor(t=""){super(t)}},me={Err:vs,_tlv:{encode:(r,t)=>{let{Err:e}=me;if(r<0||r>256)throw new e("tlv.encode: wrong tag");if(t.length&1)throw new e("tlv.encode: unpadded data");let n=t.length/2,o=qe(n);if(o.length/2&128)throw new e("tlv.encode: long form length too big");let i=n>127?qe(o.length/2|128):"";return qe(r)+i+o+t},decode(r,t){let{Err:e}=me,n=0;if(r<0||r>256)throw new e("tlv.encode: wrong tag");if(t.length<2||t[n++]!==r)throw new e("tlv.decode: wrong tlv");let o=t[n++],i=!!(o&128),s=0;if(!i)s=o;else{let a=o&127;if(!a)throw new e("tlv.decode(long): indefinite length not supported");if(a>4)throw new e("tlv.decode(long): byte length is too big");let l=t.subarray(n,n+a);if(l.length!==a)throw new e("tlv.decode: length bytes not complete");if(l[0]===0)throw new e("tlv.decode(long): zero leftmost byte");for(let u of l)s=s<<8|u;if(n+=a,s<128)throw new e("tlv.decode(long): not minimal encoding")}let c=t.subarray(n,n+s);if(c.length!==s)throw new e("tlv.decode: wrong value length");return{v:c,l:t.subarray(n+s)}}},_int:{encode(r){let{Err:t}=me;if(r<ge)throw new t("integer: negative integers are not allowed");let e=qe(r);if(Number.parseInt(e[0],16)&8&&(e="00"+e),e.length&1)throw new t("unexpected DER parsing assertion: unpadded hex");return e},decode(r){let{Err:t}=me;if(r[0]&128)throw new t("invalid signature integer: negative");if(r[0]===0&&!(r[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return u0(r)}},toSig(r){let{Err:t,_int:e,_tlv:n}=me,o=typeof r=="string"?l0(r):r;vr(o);let{v:i,l:s}=n.decode(48,o);if(s.length)throw new t("invalid signature: left bytes after parsing");let{v:c,l:a}=n.decode(2,i),{v:l,l:u}=n.decode(2,a);if(u.length)throw new t("invalid signature: left bytes after parsing");return{r:e.decode(c),s:e.decode(l)}},hexFromSig(r){let{_tlv:t,_int:e}=me,n=t.encode(2,e.encode(r.r)),o=t.encode(2,e.encode(r.s)),i=n+o;return t.encode(48,i)}},ge=BigInt(0),pt=BigInt(1),D2=BigInt(2),il=BigInt(3),M2=BigInt(4);function f0(r){let t=a0(r),{Fp:e}=t,n=Le(t.n,t.nBitLength),o=t.toBytes||((g,d,E)=>{let A=d.toAffine();return pe(Uint8Array.from([4]),e.toBytes(A.x),e.toBytes(A.y))}),i=t.fromBytes||(g=>{let d=g.subarray(1),E=e.fromBytes(d.subarray(0,e.BYTES)),A=e.fromBytes(d.subarray(e.BYTES,2*e.BYTES));return{x:E,y:A}});function s(g){let{a:d,b:E}=t,A=e.sqr(g),m=e.mul(A,g);return e.add(e.add(m,e.mul(g,d)),E)}if(!e.eql(e.sqr(t.Gy),s(t.Gx)))throw new Error("bad generator point: equation left != right");function c(g){return cn(g,pt,t.n)}function a(g){let{allowedPrivateKeyLengths:d,nByteLength:E,wrapPrivateKey:A,n:m}=t;if(d&&typeof g!="bigint"){if(Te(g)&&(g=de(g)),typeof g!="string"||!d.includes(g.length))throw new Error("invalid private key");g=g.padStart(E*2,"0")}let I;try{I=typeof g=="bigint"?g:he(ot("private key",g,E))}catch{throw new Error("invalid private key, expected hex or "+E+" bytes, got "+typeof g)}return A&&(I=Z(I,m)),kt("private key",I,pt,m),I}function l(g){if(!(g instanceof h))throw new Error("ProjectivePoint expected")}let u=Ge((g,d)=>{let{px:E,py:A,pz:m}=g;if(e.eql(m,e.ONE))return{x:E,y:A};let I=g.is0();d==null&&(d=I?e.ONE:e.inv(m));let R=e.mul(E,d),N=e.mul(A,d),T=e.mul(m,d);if(I)return{x:e.ZERO,y:e.ZERO};if(!e.eql(T,e.ONE))throw new Error("invZ was invalid");return{x:R,y:N}}),f=Ge(g=>{if(g.is0()){if(t.allowInfinityPoint&&!e.is0(g.py))return;throw new Error("bad point: ZERO")}let{x:d,y:E}=g.toAffine();if(!e.isValid(d)||!e.isValid(E))throw new Error("bad point: x or y not FE");let A=e.sqr(E),m=s(d);if(!e.eql(A,m))throw new Error("bad point: equation left != right");if(!g.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});class h{constructor(d,E,A){if(this.px=d,this.py=E,this.pz=A,d==null||!e.isValid(d))throw new Error("x required");if(E==null||!e.isValid(E))throw new Error("y required");if(A==null||!e.isValid(A))throw new Error("z required");Object.freeze(this)}static fromAffine(d){let{x:E,y:A}=d||{};if(!d||!e.isValid(E)||!e.isValid(A))throw new Error("invalid affine point");if(d instanceof h)throw new Error("projective point not allowed");let m=I=>e.eql(I,e.ZERO);return m(E)&&m(A)?h.ZERO:new h(E,A,e.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(d){let E=e.invertBatch(d.map(A=>A.pz));return d.map((A,m)=>A.toAffine(E[m])).map(h.fromAffine)}static fromHex(d){let E=h.fromAffine(i(ot("pointHex",d)));return E.assertValidity(),E}static fromPrivateKey(d){return h.BASE.multiply(a(d))}static msm(d,E){return Io(h,n,d,E)}_setWindowSize(d){x.setWindowSize(this,d)}assertValidity(){f(this)}hasEvenY(){let{y:d}=this.toAffine();if(e.isOdd)return!e.isOdd(d);throw new Error("Field doesn't support isOdd")}equals(d){l(d);let{px:E,py:A,pz:m}=this,{px:I,py:R,pz:N}=d,T=e.eql(e.mul(E,N),e.mul(I,m)),U=e.eql(e.mul(A,N),e.mul(R,m));return T&&U}negate(){return new h(this.px,e.neg(this.py),this.pz)}double(){let{a:d,b:E}=t,A=e.mul(E,il),{px:m,py:I,pz:R}=this,N=e.ZERO,T=e.ZERO,U=e.ZERO,k=e.mul(m,m),J=e.mul(I,I),q=e.mul(R,R),z=e.mul(m,I);return z=e.add(z,z),U=e.mul(m,R),U=e.add(U,U),N=e.mul(d,U),T=e.mul(A,q),T=e.add(N,T),N=e.sub(J,T),T=e.add(J,T),T=e.mul(N,T),N=e.mul(z,N),U=e.mul(A,U),q=e.mul(d,q),z=e.sub(k,q),z=e.mul(d,z),z=e.add(z,U),U=e.add(k,k),k=e.add(U,k),k=e.add(k,q),k=e.mul(k,z),T=e.add(T,k),q=e.mul(I,R),q=e.add(q,q),k=e.mul(q,z),N=e.sub(N,k),U=e.mul(q,J),U=e.add(U,U),U=e.add(U,U),new h(N,T,U)}add(d){l(d);let{px:E,py:A,pz:m}=this,{px:I,py:R,pz:N}=d,T=e.ZERO,U=e.ZERO,k=e.ZERO,J=t.a,q=e.mul(t.b,il),z=e.mul(E,I),ct=e.mul(A,R),B=e.mul(m,N),L=e.add(E,A),w=e.add(I,R);L=e.mul(L,w),w=e.add(z,ct),L=e.sub(L,w),w=e.add(E,m);let y=e.add(I,N);return w=e.mul(w,y),y=e.add(z,B),w=e.sub(w,y),y=e.add(A,m),T=e.add(R,N),y=e.mul(y,T),T=e.add(ct,B),y=e.sub(y,T),k=e.mul(J,w),T=e.mul(q,B),k=e.add(T,k),T=e.sub(ct,k),k=e.add(ct,k),U=e.mul(T,k),ct=e.add(z,z),ct=e.add(ct,z),B=e.mul(J,B),w=e.mul(q,w),ct=e.add(ct,B),B=e.sub(z,B),B=e.mul(J,B),w=e.add(w,B),z=e.mul(ct,w),U=e.add(U,z),z=e.mul(y,w),T=e.mul(L,T),T=e.sub(T,z),z=e.mul(L,ct),k=e.mul(y,k),k=e.add(k,z),new h(T,U,k)}subtract(d){return this.add(d.negate())}is0(){return this.equals(h.ZERO)}wNAF(d){return x.wNAFCached(this,d,h.normalizeZ)}multiplyUnsafe(d){let{endo:E,n:A}=t;kt("scalar",d,ge,A);let m=h.ZERO;if(d===ge)return m;if(this.is0()||d===pt)return this;if(!E||x.hasPrecomputes(this))return x.wNAFCachedUnsafe(this,d,h.normalizeZ);let{k1neg:I,k1:R,k2neg:N,k2:T}=E.splitScalar(d),U=m,k=m,J=this;for(;R>ge||T>ge;)R&pt&&(U=U.add(J)),T&pt&&(k=k.add(J)),J=J.double(),R>>=pt,T>>=pt;return I&&(U=U.negate()),N&&(k=k.negate()),k=new h(e.mul(k.px,E.beta),k.py,k.pz),U.add(k)}multiply(d){let{endo:E,n:A}=t;kt("scalar",d,pt,A);let m,I;if(E){let{k1neg:R,k1:N,k2neg:T,k2:U}=E.splitScalar(d),{p:k,f:J}=this.wNAF(N),{p:q,f:z}=this.wNAF(U);k=x.constTimeNegate(R,k),q=x.constTimeNegate(T,q),q=new h(e.mul(q.px,E.beta),q.py,q.pz),m=k.add(q),I=J.add(z)}else{let{p:R,f:N}=this.wNAF(d);m=R,I=N}return h.normalizeZ([m,I])[0]}multiplyAndAddUnsafe(d,E,A){let m=h.BASE,I=(N,T)=>T===ge||T===pt||!N.equals(m)?N.multiplyUnsafe(T):N.multiply(T),R=I(this,E).add(I(d,A));return R.is0()?void 0:R}toAffine(d){return u(this,d)}isTorsionFree(){let{h:d,isTorsionFree:E}=t;if(d===pt)return!0;if(E)return E(h,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h:d,clearCofactor:E}=t;return d===pt?this:E?E(h,this):this.multiplyUnsafe(t.h)}toRawBytes(d=!0){return Yt("isCompressed",d),this.assertValidity(),o(h,this,d)}toHex(d=!0){return Yt("isCompressed",d),de(this.toRawBytes(d))}}h.BASE=new h(t.Gx,t.Gy,e.ONE),h.ZERO=new h(e.ZERO,e.ONE,e.ZERO);let b=t.nBitLength,x=Bo(h,t.endo?Math.ceil(b/2):b);return{CURVE:t,ProjectivePoint:h,normPrivateKeyToScalar:a,weierstrassEquation:s,isWithinCurveOrder:c}}function d0(r){let t=un(r);return re(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}function sl(r){let t=d0(r),{Fp:e,n}=t,o=e.BYTES+1,i=2*e.BYTES+1;function s(B){return Z(B,n)}function c(B){return So(B,n)}let{ProjectivePoint:a,normPrivateKeyToScalar:l,weierstrassEquation:u,isWithinCurveOrder:f}=f0({...t,toBytes(B,L,w){let y=L.toAffine(),v=e.toBytes(y.x),C=pe;return Yt("isCompressed",w),w?C(Uint8Array.from([L.hasEvenY()?2:3]),v):C(Uint8Array.from([4]),v,e.toBytes(y.y))},fromBytes(B){let L=B.length,w=B[0],y=B.subarray(1);if(L===o&&(w===2||w===3)){let v=he(y);if(!cn(v,pt,e.ORDER))throw new Error("Point is not on curve");let C=u(v),P;try{P=e.sqrt(C)}catch(H){let O=H instanceof Error?": "+H.message:"";throw new Error("Point is not on curve"+O)}let D=(P&pt)===pt;return(w&1)===1!==D&&(P=e.neg(P)),{x:v,y:P}}else if(L===i&&w===4){let v=e.fromBytes(y.subarray(0,e.BYTES)),C=e.fromBytes(y.subarray(e.BYTES,2*e.BYTES));return{x:v,y:C}}else{let v=o,C=i;throw new Error("invalid Point, expected length of "+v+", or uncompressed "+C+", got "+L)}}}),h=B=>de(Ue(B,t.nByteLength));function b(B){let L=n>>pt;return B>L}function x(B){return b(B)?s(-B):B}let g=(B,L,w)=>he(B.slice(L,w));class d{constructor(L,w,y){this.r=L,this.s=w,this.recovery=y,this.assertValidity()}static fromCompact(L){let w=t.nByteLength;return L=ot("compactSignature",L,w*2),new d(g(L,0,w),g(L,w,2*w))}static fromDER(L){let{r:w,s:y}=me.toSig(ot("DER",L));return new d(w,y)}assertValidity(){kt("r",this.r,pt,n),kt("s",this.s,pt,n)}addRecoveryBit(L){return new d(this.r,this.s,L)}recoverPublicKey(L){let{r:w,s:y,recovery:v}=this,C=N(ot("msgHash",L));if(v==null||![0,1,2,3].includes(v))throw new Error("recovery id invalid");let P=v===2||v===3?w+t.n:w;if(P>=e.ORDER)throw new Error("recovery id 2 or 3 invalid");let D=(v&1)===0?"02":"03",V=a.fromHex(D+h(P)),H=c(P),O=s(-C*H),j=s(y*H),Q=a.BASE.multiplyAndAddUnsafe(V,O,j);if(!Q)throw new Error("point at infinify");return Q.assertValidity(),Q}hasHighS(){return b(this.s)}normalizeS(){return this.hasHighS()?new d(this.r,s(-this.s),this.recovery):this}toDERRawBytes(){return Ke(this.toDERHex())}toDERHex(){return me.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return Ke(this.toCompactHex())}toCompactHex(){return h(this.r)+h(this.s)}}let E={isValidPrivateKey(B){try{return l(B),!0}catch{return!1}},normPrivateKeyToScalar:l,randomPrivateKey:()=>{let B=fs(t.n);return Gu(t.randomBytes(B),t.n)},precompute(B=8,L=a.BASE){return L._setWindowSize(B),L.multiply(BigInt(3)),L}};function A(B,L=!0){return a.fromPrivateKey(B).toRawBytes(L)}function m(B){let L=Te(B),w=typeof B=="string",y=(L||w)&&B.length;return L?y===o||y===i:w?y===2*o||y===2*i:B instanceof a}function I(B,L,w=!0){if(m(B))throw new Error("first arg must be private key");if(!m(L))throw new Error("second arg must be public key");return a.fromHex(L).multiply(l(B)).toRawBytes(w)}let R=t.bits2int||function(B){if(B.length>8192)throw new Error("input is too large");let L=he(B),w=B.length*8-t.nBitLength;return w>0?L>>BigInt(w):L},N=t.bits2int_modN||function(B){return s(R(B))},T=an(t.nBitLength);function U(B){return kt("num < 2^"+t.nBitLength,B,ge,T),Ue(B,t.nByteLength)}function k(B,L,w=J){if(["recovered","canonical"].some(ft=>ft in w))throw new Error("sign() legacy options not supported");let{hash:y,randomBytes:v}=t,{lowS:C,prehash:P,extraEntropy:D}=w;C==null&&(C=!0),B=ot("msgHash",B),ol(w),P&&(B=ot("prehashed msgHash",y(B)));let V=N(B),H=l(L),O=[U(H),U(V)];if(D!=null&&D!==!1){let ft=D===!0?v(e.BYTES):D;O.push(ot("extraEntropy",ft))}let j=pe(...O),Q=V;function lt(ft){let mt=R(ft);if(!f(mt))return;let yt=c(mt),_t=a.BASE.multiply(mt).toAffine(),vt=s(_t.x);if(vt===ge)return;let Jt=s(yt*s(Q+vt*H));if(Jt===ge)return;let ne=(_t.x===vt?0:2)|Number(_t.y&pt),Br=Jt;return C&&b(Jt)&&(Br=x(Jt),ne^=1),new d(vt,Br,ne)}return{seed:j,k2sig:lt}}let J={lowS:t.lowS,prehash:!1},q={lowS:t.lowS,prehash:!1};function z(B,L,w=J){let{seed:y,k2sig:v}=k(B,L,w),C=t;return cs(C.hash.outputLen,C.nByteLength,C.hmac)(y,v)}a.BASE._setWindowSize(8);function ct(B,L,w,y=q){let v=B;L=ot("msgHash",L),w=ot("publicKey",w);let{lowS:C,prehash:P,format:D}=y;if(ol(y),"strict"in y)throw new Error("options.strict was renamed to lowS");if(D!==void 0&&D!=="compact"&&D!=="der")throw new Error("format must be compact or der");let V=typeof v=="string"||Te(v),H=!V&&!D&&typeof v=="object"&&v!==null&&typeof v.r=="bigint"&&typeof v.s=="bigint";if(!V&&!H)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");let O,j;try{if(H&&(O=new d(v.r,v.s)),V){try{D!=="compact"&&(O=d.fromDER(v))}catch(ne){if(!(ne instanceof me.Err))throw ne}!O&&D!=="der"&&(O=d.fromCompact(v))}j=a.fromHex(w)}catch{return!1}if(!O||C&&O.hasHighS())return!1;P&&(L=t.hash(L));let{r:Q,s:lt}=O,ft=N(L),mt=c(lt),yt=s(ft*mt),_t=s(Q*mt),vt=a.BASE.multiplyAndAddUnsafe(j,yt,_t)?.toAffine();return vt?s(vt.x)===Q:!1}return{CURVE:t,getPublicKey:A,getSharedSecret:I,sign:z,verify:ct,ProjectivePoint:a,Signature:d,utils:E}}function h0(r){return{hash:r,hmac:(t,...e)=>Es(r,t,ts(...e)),randomBytes:bo}}function cl(r,t){let e=n=>sl({...r,...h0(n)});return{...e(t),create:e}}var ll=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),al=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),p0=BigInt(1),Ss=BigInt(2),ul=(r,t)=>(r+t/Ss)/t;function m0(r){let t=ll,e=BigInt(3),n=BigInt(6),o=BigInt(11),i=BigInt(22),s=BigInt(23),c=BigInt(44),a=BigInt(88),l=r*r*r%t,u=l*l*r%t,f=nt(u,e,t)*u%t,h=nt(f,e,t)*u%t,b=nt(h,Ss,t)*l%t,x=nt(b,o,t)*b%t,g=nt(x,i,t)*x%t,d=nt(g,c,t)*g%t,E=nt(d,a,t)*d%t,A=nt(E,c,t)*g%t,m=nt(A,e,t)*u%t,I=nt(m,s,t)*x%t,R=nt(I,n,t)*l%t,N=nt(R,Ss,t);if(!As.eql(As.sqr(N),r))throw new Error("Cannot find square root");return N}var As=Le(ll,void 0,void 0,{sqrt:m0}),Ze=cl({a:BigInt(0),b:BigInt(7),Fp:As,n:al,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let t=al,e=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-p0*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),i=e,s=BigInt("0x100000000000000000000000000000000"),c=ul(i*r,t),a=ul(-n*r,t),l=Z(r-c*e-a*o,t),u=Z(-c*n-a*i,t),f=l>s,h=u>s;if(f&&(l=t-l),h&&(u=t-u),l>s||u>s)throw new Error("splitScalar: Endomorphism failed, k="+r);return{k1neg:f,k1:l,k2neg:h,k2:u}}}},nl),G2=BigInt(0);var j2=Ze.ProjectivePoint;function fl(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function dl(r,t,e){let n=Hr.digest(e instanceof Uint8Array?e:e.subarray());if(fl(n))return n.then(({digest:o})=>Ze.verify(t,o,r)).catch(o=>{throw new fn(String(o))});try{return Ze.verify(t,n.digest,r)}catch(o){throw new fn(String(o))}}var Lo=class{type="secp256k1";raw;_key;constructor(t){this._key=pl(t),this.raw=hl(this._key)}toMultihash(){return ce.digest(ko(this))}toCID(){return at.createV1(114,this.toMultihash())}toString(){return tt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:Gt(this.raw,t.raw)}verify(t,e){return dl(this._key,e,t)}};function ml(r){return new Lo(r)}function hl(r){return Ze.ProjectivePoint.fromHex(r).toRawBytes(!0)}function pl(r){try{return Ze.ProjectivePoint.fromHex(r),r}catch(t){throw new yn(String(t))}}function gl(r){let{Type:t,Data:e}=ln.decode(r.digest),n=e??new Uint8Array;switch(t){case zt.Ed25519:return rl(n);case zt.secp256k1:return ml(n);default:throw new _r}}function ko(r){return ln.encode({Type:zt[r.type],Data:r.raw})}var yl=Symbol.for("nodejs.util.inspect.custom"),g0=114,dn=class{type;multihash;publicKey;string;constructor(t){this.type=t.type,this.multihash=t.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[mn]=!0;toString(){return this.string==null&&(this.string=tt.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return at.createV1(g0,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return Gt(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return Gt(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[yl](){return`PeerId(${this.toString()})`}},No=class extends dn{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},Ro=class extends dn{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},Po=class extends dn{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},y0=2336,hn=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=ce.digest(ae(this.url))}[yl](){return`PeerId(${this.url})`}[mn]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return at.createV1(y0,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=st(t)),t.toString()===this.toString())}};var b0=114,bl=2336;function xl(r,t){let e;if(r.charAt(0)==="1"||r.charAt(0)==="Q")e=se(tt.decode(`z${r}`));else{if(r.startsWith("k51qzi5uqu5")||r.startsWith("kzwfwjn5ji4")||r.startsWith("k2k4r8")||r.startsWith("bafz"))return x0(at.parse(r));if(t==null)throw new ye('Please pass a multibase decoder for strings that do not start with "1" or "Q"');e=se(t.decode(r))}return Do(e)}function Do(r){if(E0(r))return new No({multihash:r});if(w0(r))try{let t=gl(r);if(t.type==="Ed25519")return new Ro({multihash:r,publicKey:t});if(t.type==="secp256k1")return new Po({multihash:r,publicKey:t})}catch{let e=st(r.digest);return new hn(new URL(e))}throw new xn("Supplied PeerID Multihash is invalid")}function x0(r){if(r?.multihash==null||r.version==null||r.version===1&&r.code!==b0&&r.code!==bl)throw new bn("Supplied PeerID CID is invalid");if(r.code===bl){let t=st(r.multihash.digest);return new hn(new URL(t))}return Do(r.multihash)}function w0(r){return r.code===ce.code}function E0(r){return r.code===Hr.code}var wl={type:4098,canEncode:r=>Ds(r),encode:r=>r.toMultihash().bytes,decode:r=>Do(se(r))};var Bs=[gu,Uu,wl,yu];function Mo(r){let t={},e=r.components??r;return Object.entries(e).forEach(([n,o])=>{o?.[be]!=null&&Array.isArray(o[be])&&(t[n]=o[be])}),t}function Sr(r,t){let e={};for(let[n,o]of r.entries())e[n]=t(o);return e}async function Oo(r,t){let e=[],n=r.connectionManager.getConnectionsMap(),o=[...n.values()].flatMap(i=>i).map(i=>i.remoteAddr.toString());for(let[i,s]of n.entries())try{let c=await r.peerStore.get(i);e.push({id:i,addresses:c.addresses.map(({isCertified:a,multiaddr:l})=>({multiaddr:l,isCertified:a,isConnected:o.includes(l.toString())})),protocols:[...c.protocols],tags:Sr(c.tags,a=>a.value),metadata:Sr(c.metadata,a=>te.encode(a))})}catch(c){t.error("could not load peer data from peer store",c),e.push({id:i,addresses:s.map(a=>({multiaddr:a.remoteAddr,isConnected:o.includes(a.remoteAddr.toString())})),protocols:[],tags:{},metadata:{}})}return e}function Ar(r,t){let e=t[r];if(!gn(e))throw new ye(`Component ${r} did not implement the PubSub interface`);return e}async function Fo(r){let t=await r.peerStore.get(r.peerId);return{id:t.id,addresses:t.addresses,protocols:[...t.protocols],tags:Sr(t.tags,e=>e.value),metadata:Sr(t.metadata,e=>te.encode(e))}}function El(r){let t=r.logger.forComponent("libp2p:devtools-metrics:metrics-rpc");return{init:async()=>({self:await Fo(r),peers:await Oo(r,t),debug:localStorage.getItem("debug")??"",capabilities:Mo(r)}),setDebug:async e=>{e?.length!=null&&e?.length>0?(Ys(e),localStorage.setItem("debug",e)):(Xs(),localStorage.removeItem("debug"))},openConnection:async(e,n)=>{let o;try{o=xl(e)}catch{o=ze(e)}await r.connectionManager.openConnection(o,n)},closeConnection:async(e,n)=>{await Promise.all(r.connectionManager.getConnections(e).map(async o=>{try{await o.close(n)}catch(i){o.abort(i)}}))},contentRouting:r.contentRouting,peerRouting:r.peerRouting,pubsub:{async getTopics(e){return Ar(e,r).getTopics()},async subscribe(e,n){Ar(e,r).subscribe(n)},async unsubscribe(e,n){Ar(e,r).unsubscribe(n)},async publish(e,n,o){await Ar(e,r).publish(n,o)},async getSubscribers(e,n){return Ar(e,r).getSubscribers(n)}}}}function Is(r,t=100){let e,n;return()=>{if(n==null&&(n=Date.now()),e!=null&&Date.now()-n>t){clearTimeout(e),n=void 0,r();return}clearTimeout(e),e=setTimeout(()=>{n=void 0,r()},t)}}function vl(r,t){for(let[e,n]of Object.entries(Mo(t)))if(n.includes(r))return t[e]}var Sl="@libp2p/devtools-metrics:devtools",v0="@libp2p/devtools-metrics:worker",S0="@libp2p/devtools-metrics:content",Al="@libp2p/devtools-metrics:metrics",Bl="________libp2p_devtools_metrics";Object.defineProperty(globalThis,Bl,{value:!0,enumerable:!1,writable:!1});var _s=class{log;components;simpleMetrics;intervalMs;rpcQueue;rpc;devTools;constructor(t,e){this.log=t.logger.forComponent("libp2p:devtools-metrics"),this.intervalMs=e?.intervalMs,this.components=t,this.rpcQueue=Ee(),this.rpc=mu({valueCodecs:Bs}),this.devTools=this.rpc.createClient("devTools"),this.onPeersUpdate=Is(this.onPeersUpdate.bind(this),1e3),this.onSelfUpdate=Is(this.onSelfUpdate.bind(this),1e3),this.onIncomingMessage=this.onIncomingMessage.bind(this),this.onPubSubMessage=this.onPubSubMessage.bind(this),this.onPubSubSubscriptionChange=this.onPubSubSubscriptionChange.bind(this),this.simpleMetrics=dc({intervalMs:this.intervalMs,onMetrics:n=>{this.devTools.safeDispatchEvent("metrics",{detail:n}).catch(o=>{this.log.error("error sending metrics",o)})}})({})}[Symbol.toStringTag]="@libp2p/devtools-metrics";[be]=["@libp2p/metrics"];trackMultiaddrConnection(t){this.simpleMetrics.trackMultiaddrConnection(t)}trackProtocolStream(t,e){this.simpleMetrics.trackProtocolStream(t,e)}registerMetric(t,e){return this.simpleMetrics.registerMetric(t,e)}registerMetricGroup(t,e){return this.simpleMetrics.registerMetricGroup(t,e)}registerCounter(t,e){return this.simpleMetrics.registerCounter(t,e)}registerCounterGroup(t,e){return this.simpleMetrics.registerCounterGroup(t,e)}registerHistogram(t,e){return this.simpleMetrics.registerHistogram(t,e)}registerHistogramGroup(t,e){return this.simpleMetrics.registerHistogramGroup(t,e)}registerSummary(t,e){return this.simpleMetrics.registerSummary(t,e)}registerSummaryGroup(t,e){return this.simpleMetrics.registerSummaryGroup(t,e)}createTrace(){return this.simpleMetrics.createTrace()}traceFunction(t,e,n){return this.simpleMetrics.traceFunction(t,e,n)}async start(){this.components.events.addEventListener("peer:connect",this.onPeersUpdate),this.components.events.addEventListener("peer:disconnect",this.onPeersUpdate),this.components.events.addEventListener("peer:identify",this.onPeersUpdate),this.components.events.addEventListener("peer:update",this.onPeersUpdate),this.components.events.addEventListener("self:peer:update",this.onSelfUpdate),window.addEventListener("message",this.onIncomingMessage),this.rpc.createTarget("metrics",El(this.components)),await Fs(this.simpleMetrics),Promise.resolve().then(async()=>{await pc(this.rpcQueue,this.rpc,async e=>{for await(let n of e)window.postMessage({source:Al,type:"libp2p-rpc",message:te.encode(n)})})}).catch(e=>{this.log.error("error while reading RPC messages",e)});let t=vl("@libp2p/pubsub",this.components);gn(t)&&(t.addEventListener("message",this.onPubSubMessage),t.addEventListener("subscription-change",this.onPubSubSubscriptionChange))}async stop(){window.removeEventListener("message",this.onIncomingMessage),this.components.events.removeEventListener("self:peer:update",this.onSelfUpdate),this.components.events.removeEventListener("peer:connect",this.onPeersUpdate),this.components.events.removeEventListener("peer:disconnect",this.onPeersUpdate),this.components.events.removeEventListener("peer:identify",this.onPeersUpdate),this.components.events.removeEventListener("peer:update",this.onPeersUpdate),await Vs(this.simpleMetrics)}onIncomingMessage(t){if(t.source!==window)return;let e=t.data;e?.source===Sl&&e.type==="libp2p-rpc"&&this.rpcQueue.push(te.decode(e.message))}onPubSubMessage(t){this.devTools.safeDispatchEvent("pubsub:message",{detail:t.detail}).catch(e=>{this.log.error("error relaying pubsub message",e)})}onPubSubSubscriptionChange(t){this.devTools.safeDispatchEvent("pubsub:subscription-change",{detail:t.detail}).catch(e=>{this.log.error("error relaying pubsub subscription change",e)})}onSelfUpdate(){Promise.resolve().then(async()=>{await this.devTools.safeDispatchEvent("self",{detail:await Fo(this.components)})}).catch(t=>{this.log.error("error sending peers message",t)})}onPeersUpdate(){Promise.resolve().then(async()=>{await this.devTools.safeDispatchEvent("peers",{detail:await Oo(this.components,this.log)})}).catch(t=>{this.log.error("error sending peers message",t)})}};function A0(r){return t=>new _s(t,r)}return Vl(B0);})();
4
4
  /*! Bundled license information:
5
5
 
6
6
  @noble/hashes/esm/utils.js:
@@ -0,0 +1,46 @@
1
+ {
2
+ "Address": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_devtools_metrics.index.Address.html",
3
+ ".:Address": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_devtools_metrics.index.Address.html",
4
+ "CopyToClipboardMessage": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_devtools_metrics.index.CopyToClipboardMessage.html",
5
+ ".:CopyToClipboardMessage": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_devtools_metrics.index.CopyToClipboardMessage.html",
6
+ "DevToolsMetricsComponents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_devtools_metrics.index.DevToolsMetricsComponents.html",
7
+ ".:DevToolsMetricsComponents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_devtools_metrics.index.DevToolsMetricsComponents.html",
8
+ "DevToolsMetricsInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_devtools_metrics.index.DevToolsMetricsInit.html",
9
+ ".:DevToolsMetricsInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_devtools_metrics.index.DevToolsMetricsInit.html",
10
+ "PageLoadedMessage": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_devtools_metrics.index.PageLoadedMessage.html",
11
+ ".:PageLoadedMessage": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_devtools_metrics.index.PageLoadedMessage.html",
12
+ "PermissionsErrorMessage": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_devtools_metrics.index.PermissionsErrorMessage.html",
13
+ ".:PermissionsErrorMessage": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_devtools_metrics.index.PermissionsErrorMessage.html",
14
+ "RPCMessage": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_devtools_metrics.index.RPCMessage.html",
15
+ ".:RPCMessage": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_devtools_metrics.index.RPCMessage.html",
16
+ "ApplicationMessage": "https://libp2p.github.io/js-libp2p/types/_libp2p_devtools_metrics.index.ApplicationMessage.html",
17
+ ".:ApplicationMessage": "https://libp2p.github.io/js-libp2p/types/_libp2p_devtools_metrics.index.ApplicationMessage.html",
18
+ "DevToolsMessage": "https://libp2p.github.io/js-libp2p/types/_libp2p_devtools_metrics.index.DevToolsMessage.html",
19
+ ".:DevToolsMessage": "https://libp2p.github.io/js-libp2p/types/_libp2p_devtools_metrics.index.DevToolsMessage.html",
20
+ "WorkerMessage": "https://libp2p.github.io/js-libp2p/types/_libp2p_devtools_metrics.index.WorkerMessage.html",
21
+ ".:WorkerMessage": "https://libp2p.github.io/js-libp2p/types/_libp2p_devtools_metrics.index.WorkerMessage.html",
22
+ "LIBP2P_DEVTOOLS_METRICS_KEY": "https://libp2p.github.io/js-libp2p/variables/_libp2p_devtools_metrics.index.LIBP2P_DEVTOOLS_METRICS_KEY.html",
23
+ ".:LIBP2P_DEVTOOLS_METRICS_KEY": "https://libp2p.github.io/js-libp2p/variables/_libp2p_devtools_metrics.index.LIBP2P_DEVTOOLS_METRICS_KEY.html",
24
+ "SOURCE_CONTENT_SCRIPT": "https://libp2p.github.io/js-libp2p/variables/_libp2p_devtools_metrics.index.SOURCE_CONTENT_SCRIPT.html",
25
+ ".:SOURCE_CONTENT_SCRIPT": "https://libp2p.github.io/js-libp2p/variables/_libp2p_devtools_metrics.index.SOURCE_CONTENT_SCRIPT.html",
26
+ "SOURCE_DEVTOOLS": "https://libp2p.github.io/js-libp2p/variables/_libp2p_devtools_metrics.index.SOURCE_DEVTOOLS.html",
27
+ ".:SOURCE_DEVTOOLS": "https://libp2p.github.io/js-libp2p/variables/_libp2p_devtools_metrics.index.SOURCE_DEVTOOLS.html",
28
+ "SOURCE_METRICS": "https://libp2p.github.io/js-libp2p/variables/_libp2p_devtools_metrics.index.SOURCE_METRICS.html",
29
+ ".:SOURCE_METRICS": "https://libp2p.github.io/js-libp2p/variables/_libp2p_devtools_metrics.index.SOURCE_METRICS.html",
30
+ "SOURCE_SERVICE_WORKER": "https://libp2p.github.io/js-libp2p/variables/_libp2p_devtools_metrics.index.SOURCE_SERVICE_WORKER.html",
31
+ ".:SOURCE_SERVICE_WORKER": "https://libp2p.github.io/js-libp2p/variables/_libp2p_devtools_metrics.index.SOURCE_SERVICE_WORKER.html",
32
+ "devToolsMetrics": "https://libp2p.github.io/js-libp2p/functions/_libp2p_devtools_metrics.index.devToolsMetrics.html",
33
+ ".:devToolsMetrics": "https://libp2p.github.io/js-libp2p/functions/_libp2p_devtools_metrics.index.devToolsMetrics.html",
34
+ "DevToolsEvents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_devtools_metrics.rpc.DevToolsEvents.html",
35
+ "./rpc:DevToolsEvents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_devtools_metrics.rpc.DevToolsEvents.html",
36
+ "DevToolsRPC": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_devtools_metrics.rpc.DevToolsRPC.html",
37
+ "./rpc:DevToolsRPC": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_devtools_metrics.rpc.DevToolsRPC.html",
38
+ "MetricsRPC": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_devtools_metrics.rpc.MetricsRPC.html",
39
+ "./rpc:MetricsRPC": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_devtools_metrics.rpc.MetricsRPC.html",
40
+ "Peer": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_devtools_metrics.rpc.Peer.html",
41
+ "./rpc:Peer": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_devtools_metrics.rpc.Peer.html",
42
+ "PeerAddress": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_devtools_metrics.rpc.PeerAddress.html",
43
+ "./rpc:PeerAddress": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_devtools_metrics.rpc.PeerAddress.html",
44
+ "valueCodecs": "https://libp2p.github.io/js-libp2p/variables/_libp2p_devtools_metrics.rpc.valueCodecs.html",
45
+ "./rpc:valueCodecs": "https://libp2p.github.io/js-libp2p/variables/_libp2p_devtools_metrics.rpc.valueCodecs.html"
46
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@libp2p/devtools-metrics",
3
- "version": "1.2.12-b2124c2db",
3
+ "version": "1.2.12",
4
4
  "description": "Collect libp2p metrics and send them to browser DevTools",
5
5
  "author": "",
6
6
  "license": "Apache-2.0 OR MIT",
@@ -68,11 +68,11 @@
68
68
  "test:firefox": "aegir test -t browser --browser firefox"
69
69
  },
70
70
  "dependencies": {
71
- "@libp2p/interface": "2.7.0-b2124c2db",
72
- "@libp2p/interface-internal": "2.3.9-b2124c2db",
73
- "@libp2p/logger": "5.1.13-b2124c2db",
74
- "@libp2p/peer-id": "5.1.0-b2124c2db",
75
- "@libp2p/simple-metrics": "1.3.7-b2124c2db",
71
+ "@libp2p/interface": "^2.7.0",
72
+ "@libp2p/interface-internal": "^2.3.9",
73
+ "@libp2p/logger": "^5.1.13",
74
+ "@libp2p/peer-id": "^5.1.0",
75
+ "@libp2p/simple-metrics": "^1.3.7",
76
76
  "@multiformats/multiaddr": "^12.3.3",
77
77
  "cborg": "^4.2.6",
78
78
  "it-pipe": "^3.0.1",
@@ -82,7 +82,7 @@
82
82
  "progress-events": "^1.0.1"
83
83
  },
84
84
  "devDependencies": {
85
- "@libp2p/crypto": "5.0.15-b2124c2db",
85
+ "@libp2p/crypto": "^5.0.15",
86
86
  "aegir": "^45.1.1",
87
87
  "sinon-ts": "^2.0.0"
88
88
  },