@helia/delegated-routing-v1-http-api-client 5.1.4 → 5.2.1

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,16 +1,16 @@
1
1
  (function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.HeliaDelegatedRoutingV1HttpApiClient = factory()}(typeof self !== 'undefined' ? self : this, function () {
2
- "use strict";var HeliaDelegatedRoutingV1HttpApiClient=(()=>{var uf=Object.create;var un=Object.defineProperty;var ff=Object.getOwnPropertyDescriptor;var lf=Object.getOwnPropertyNames;var df=Object.getPrototypeOf,hf=Object.prototype.hasOwnProperty;var As=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),Et=(e,t)=>{for(var r in t)un(e,r,{get:t[r],enumerable:!0})},Cs=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of lf(t))!hf.call(e,o)&&o!==r&&un(e,o,{get:()=>t[o],enumerable:!(n=ff(t,o))||n.enumerable});return e};var yo=(e,t,r)=>(r=e!=null?uf(df(e)):{},Cs(t||!e||!e.__esModule?un(r,"default",{value:e,enumerable:!0}):r,e)),pf=e=>Cs(un({},"__esModule",{value:!0}),e);var cs=As((Mb,as)=>{var Vb=(function(){typeof as<"u"&&(as.exports=T);var e=86400,t=3200,r=146097*t/400,n=e*r,o=1e3*n,i=864e13,s=4294967296,c=1e6,a="000000000",l=Math.trunc||function(h){var p=h-h%1;return p==0&&(h<0||h===0&&1/h!=1/0)?-0:p},u=T.prototype,f=(T.fromDate=function(h){return new T(+h)},T.fromInt64BE=P(0,1,2,3,0,4),T.fromInt64LE=P(3,2,1,0,4,0),T.fromString=function(D){var p,_=new T,D=(D+="").replace(/^\s*[+\-]?\d+/,function(m){var m=+m,y=1970+(m-1970)%400;return _.year=m-y,y}).replace(/(?:Z|([+\-]\d{2}):?(\d{2}))$/,function(A,m,y){return m<0&&(y*=-1),p=6e4*(60*+m+ +y),""}).replace(/\.\d+$/,function(A){return _.nano=+(A+a).substr(1,9),""}).split(/\D+/);if(1<D.length?D[1]--:D[1]=0,_.time=p=Date.UTC.apply(Date,D)-(p||0),isNaN(p))throw new TypeError("Invalid Date");return C(_)},T.fromTimeT=function(h){return I(h,0)},u.year=0,u.time=0,u.nano=0,u.addNano=function(h){return this.nano+=+h||0,this},u.getNano=function(){var h=C(this);return(h.time%1e3*c+ +h.nano+1e9)%1e9},u.getTimeT=function(){var p=C(this),h=Math.floor(p.time/1e3),p=p.year;return p&&(h+=p*r*e/t),h},u.getYear=function(){return this.toDate().getUTCFullYear()+this.year},u.toDate=function(){return w(C(this).time)},u.toJSON=function(){return this.toString().replace(/0{1,6}Z$/,"Z")},u.toString=function(h){var p=this,_=p.toDate(),D={H:function(){return M(_.getUTCHours())},L:function(){return V(_.getUTCMilliseconds(),3)},M:function(){return M(_.getUTCMinutes())},N:function(){return V(p.getNano(),9)},S:function(){return M(_.getUTCSeconds())},Y:function(){var A=p.getYear();return 999999<A?"+"+A:9999<A?"+"+V(A,6):0<=A?V(A,4):-999999<=A?"-"+V(-A,6):A},a:function(){return v[_.getUTCDay()]},b:function(){return x[_.getUTCMonth()]},d:function(){return M(_.getUTCDate())},e:function(){return(function(A){return(9<A?"":" ")+(0|A)})(_.getUTCDate())},m:function(){return M(_.getUTCMonth()+1)}};return(function A(m){return m.replace(/%./g,function(y){var E=y[1],d=b[E],E=D[E];return d?A(d):E?E():y})})(h||f)},u.writeInt64BE=S(0,1,2,3,0,4),u.writeInt64LE=S(3,2,1,0,4,0),"%Y-%m-%dT%H:%M:%S.%NZ"),x=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],v=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],b={"%":"%",F:"%Y-%m-%d",n:`
3
- `,R:"%H:%M",T:"%H:%M:%S",t:" ",X:"%T",Z:"GMT",z:"+0000"};return T;function T(h,p,_){var D=this;if(!(D instanceof T))return new T(h,p,_);D.time=+h||0,D.nano=+p||0,D.year=+_||0,C(D)}function C(h){var p,_,D,A=h.year,m=h.time,y=h.nano,d=((y<0||c<=y)&&(y-=(_=Math.floor(y/c))*c,m+=_,_=1),A%t);return(m<-i||i<m||d)&&((p=l(m/o))&&(A+=p*t,m-=p*o),(D=w(m)).setUTCFullYear(d+D.getUTCFullYear()),D=(m=+D)+(p=l((A-=d)/t))*o,p&&-i<=D&&D<=i&&(A-=p*t,m=D),_=1),_&&(h.year=A,h.time=m,h.nano=y),h}function w(h){var p=new Date(0);return p.setTime(h),p}function I(A,D){A=+A||0;var _=l((D=(D|0)*s)/n)+l(A/n),D=D%n+A%n,A=l(D/n);return A&&(_+=A,D-=A*n),new T(1e3*D,0,_*t)}function S(h,p,_,D,A,m){return function(d,E){var U=C(this);d=d||new Array(8),k(d,E|=0);var N=Math.floor(U.time/1e3),U=U.year*(r*e/t),R=l(U/s)+l(N/s),U=U%s+N%s,N=Math.floor(U/s);return N&&(R+=N,U-=N*s),y(d,E+A,R),y(d,E+m,U),d};function y(d,E,R){d[E+h]=R>>24&255,d[E+p]=R>>16&255,d[E+_]=R>>8&255,d[E+D]=255&R}}function P(h,p,_,D,A,m){return function(d,E){k(d,E|=0);var R=y(d,E+A);return I(y(d,E+m),R)};function y(d,E){return 16777216*d[E+h]+(d[E+p]<<16|d[E+_]<<8|d[E+D])}}function k(h,p){if(h=h&&h.length,h==null)throw new TypeError("Invalid Buffer");if(h<p+8)throw new RangeError("Out of range")}function M(h){return(9<h?"":"0")+(0|h)}function V(h,p){return(a+(0|h)).substr(-p)}})()});var ef=As((T1,gs)=>{"use strict";var Fp=Object.prototype.hasOwnProperty,wt="~";function nn(){}Object.create&&(nn.prototype=Object.create(null),new nn().__proto__||(wt=!1));function qp(e,t,r){this.fn=e,this.context=t,this.once=r||!1}function tf(e,t,r,n,o){if(typeof r!="function")throw new TypeError("The listener must be a function");var i=new qp(r,n||e,o),s=wt?wt+t:t;return e._events[s]?e._events[s].fn?e._events[s]=[e._events[s],i]:e._events[s].push(i):(e._events[s]=i,e._eventsCount++),e}function lo(e,t){--e._eventsCount===0?e._events=new nn:delete e._events[t]}function xt(){this._events=new nn,this._eventsCount=0}xt.prototype.eventNames=function(){var t=[],r,n;if(this._eventsCount===0)return t;for(n in r=this._events)Fp.call(r,n)&&t.push(wt?n.slice(1):n);return Object.getOwnPropertySymbols?t.concat(Object.getOwnPropertySymbols(r)):t};xt.prototype.listeners=function(t){var r=wt?wt+t:t,n=this._events[r];if(!n)return[];if(n.fn)return[n.fn];for(var o=0,i=n.length,s=new Array(i);o<i;o++)s[o]=n[o].fn;return s};xt.prototype.listenerCount=function(t){var r=wt?wt+t:t,n=this._events[r];return n?n.fn?1:n.length:0};xt.prototype.emit=function(t,r,n,o,i,s){var c=wt?wt+t:t;if(!this._events[c])return!1;var a=this._events[c],l=arguments.length,u,f;if(a.fn){switch(a.once&&this.removeListener(t,a.fn,void 0,!0),l){case 1:return a.fn.call(a.context),!0;case 2:return a.fn.call(a.context,r),!0;case 3:return a.fn.call(a.context,r,n),!0;case 4:return a.fn.call(a.context,r,n,o),!0;case 5:return a.fn.call(a.context,r,n,o,i),!0;case 6:return a.fn.call(a.context,r,n,o,i,s),!0}for(f=1,u=new Array(l-1);f<l;f++)u[f-1]=arguments[f];a.fn.apply(a.context,u)}else{var x=a.length,v;for(f=0;f<x;f++)switch(a[f].once&&this.removeListener(t,a[f].fn,void 0,!0),l){case 1:a[f].fn.call(a[f].context);break;case 2:a[f].fn.call(a[f].context,r);break;case 3:a[f].fn.call(a[f].context,r,n);break;case 4:a[f].fn.call(a[f].context,r,n,o);break;default:if(!u)for(v=1,u=new Array(l-1);v<l;v++)u[v-1]=arguments[v];a[f].fn.apply(a[f].context,u)}}return!0};xt.prototype.on=function(t,r,n){return tf(this,t,r,n,!1)};xt.prototype.once=function(t,r,n){return tf(this,t,r,n,!0)};xt.prototype.removeListener=function(t,r,n,o){var i=wt?wt+t:t;if(!this._events[i])return this;if(!r)return lo(this,i),this;var s=this._events[i];if(s.fn)s.fn===r&&(!o||s.once)&&(!n||s.context===n)&&lo(this,i);else{for(var c=0,a=[],l=s.length;c<l;c++)(s[c].fn!==r||o&&!s[c].once||n&&s[c].context!==n)&&a.push(s[c]);a.length?this._events[i]=a.length===1?a[0]:a:lo(this,i)}return this};xt.prototype.removeAllListeners=function(t){var r;return t?(r=wt?wt+t:t,this._events[r]&&lo(this,r)):(this._events=new nn,this._eventsCount=0),this};xt.prototype.off=xt.prototype.removeListener;xt.prototype.addListener=xt.prototype.on;xt.prefixed=wt;xt.EventEmitter=xt;typeof gs<"u"&&(gs.exports=xt)});var Wp={};Et(Wp,{createDelegatedRoutingV1HttpApiClient:()=>jp,delegatedRoutingV1HttpApiClient:()=>Yp});var Eo={};Et(Eo,{base32:()=>zt,base32hex:()=>Af,base32hexpad:()=>Tf,base32hexpadupper:()=>If,base32hexupper:()=>Cf,base32pad:()=>Sf,base32padupper:()=>vf,base32upper:()=>Ef,base32z:()=>Bf});var Jp=new Uint8Array(0);function Ts(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function te(e){if(e instanceof Uint8Array&&e.constructor.name==="Uint8Array")return e;if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);throw new Error("Unknown type, must be binary type")}function Is(e){return new TextEncoder().encode(e)}function Bs(e){return new TextDecoder().decode(e)}function mf(e,t){if(e.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var o=0;o<e.length;o++){var i=e.charAt(o),s=i.charCodeAt(0);if(r[s]!==255)throw new TypeError(i+" is ambiguous");r[s]=o}var c=e.length,a=e.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 T=0,C=0,w=0,I=b.length;w!==I&&b[w]===0;)w++,T++;for(var S=(I-w)*u+1>>>0,P=new Uint8Array(S);w!==I;){for(var k=b[w],M=0,V=S-1;(k!==0||M<C)&&V!==-1;V--,M++)k+=256*P[V]>>>0,P[V]=k%c>>>0,k=k/c>>>0;if(k!==0)throw new Error("Non-zero carry");C=M,w++}for(var h=S-C;h!==S&&P[h]===0;)h++;for(var p=a.repeat(T);h<S;++h)p+=e.charAt(P[h]);return p}function x(b){if(typeof b!="string")throw new TypeError("Expected String");if(b.length===0)return new Uint8Array;var T=0;if(b[T]!==" "){for(var C=0,w=0;b[T]===a;)C++,T++;for(var I=(b.length-T)*l+1>>>0,S=new Uint8Array(I);b[T];){var P=r[b.charCodeAt(T)];if(P===255)return;for(var k=0,M=I-1;(P!==0||k<w)&&M!==-1;M--,k++)P+=c*S[M]>>>0,S[M]=P%256>>>0,P=P/256>>>0;if(P!==0)throw new Error("Non-zero carry");w=k,T++}if(b[T]!==" "){for(var V=I-w;V!==I&&S[V]===0;)V++;for(var h=new Uint8Array(C+(I-V)),p=C;V!==I;)h[p++]=S[V++];return h}}}function v(b){var T=x(b);if(T)return T;throw new Error(`Non-${t} character`)}return{encode:f,decodeUnsafe:x,decode:v}}var yf=mf,gf=yf,Ds=gf;var go=class{name;prefix;baseEncode;constructor(t,r,n){this.name=t,this.prefix=r,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},xo=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,r,n){this.name=t,this.prefix=r;let o=r.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 Rs(this,t)}},bo=class{decoders;constructor(t){this.decoders=t}or(t){return Rs(this,t)}decode(t){let r=t[0],n=this.decoders[r];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 Rs(e,t){return new bo({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var wo=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,r,n,o){this.name=t,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new go(t,r,n),this.decoder=new xo(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Me({name:e,prefix:t,encode:r,decode:n}){return new wo(e,t,r,n)}function he({name:e,prefix:t,alphabet:r}){let{encode:n,decode:o}=Ds(r,e);return Me({prefix:t,name:e,encode:n,decode:i=>te(o(i))})}function xf(e,t,r,n){let o=e.length;for(;e[o-1]==="=";)--o;let i=new Uint8Array(o*r/8|0),s=0,c=0,a=0;for(let l=0;l<o;++l){let u=t[e[l]];if(u===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<r|u,s+=r,s>=8&&(s-=8,i[a++]=255&c>>s)}if(s>=r||(255&c<<8-s)!==0)throw new SyntaxError("Unexpected end of data");return i}function bf(e,t,r){let n=t[t.length-1]==="=",o=(1<<r)-1,i="",s=0,c=0;for(let a=0;a<e.length;++a)for(c=c<<8|e[a],s+=8;s>r;)s-=r,i+=t[o&c>>s];if(s!==0&&(i+=t[o&c<<r-s]),n)for(;(i.length*r&7)!==0;)i+="=";return i}function wf(e){let t={};for(let r=0;r<e.length;++r)t[e[r]]=r;return t}function nt({name:e,prefix:t,bitsPerChar:r,alphabet:n}){let o=wf(n);return Me({prefix:t,name:e,encode(i){return bf(i,n,r)},decode(i){return xf(i,o,r,e)}})}var zt=nt({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Ef=nt({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Sf=nt({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),vf=nt({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Af=nt({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Cf=nt({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Tf=nt({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),If=nt({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Bf=nt({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var So={};Et(So,{base58btc:()=>W,base58flickr:()=>_f});var W=he({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),_f=he({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Co={};Et(Co,{base64:()=>vo,base64pad:()=>Df,base64url:()=>Ao,base64urlpad:()=>Rf});var vo=nt({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Df=nt({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Ao=nt({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Rf=nt({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});function Lf(e,t){if(typeof e=="string")return Uf(e);if(typeof e=="number")return Of(e,t);throw Error(`Value provided to ms() must be a string or number. value=${JSON.stringify(e)}`)}var fn=Lf;function Uf(e){if(typeof e!="string"||e.length===0||e.length>100)throw Error(`Value provided to ms.parse() must be a string with length between 1 and 99. value=${JSON.stringify(e)}`);let t=/^(?<value>-?\d*\.?\d+) *(?<unit>milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|months?|mo|years?|yrs?|y)?$/i.exec(e);if(!t?.groups)return NaN;let{value:r,unit:n="ms"}=t.groups,o=parseFloat(r),i=n.toLowerCase();switch(i){case"years":case"year":case"yrs":case"yr":case"y":return o*315576e5;case"months":case"month":case"mo":return o*26298e5;case"weeks":case"week":case"w":return o*6048e5;case"days":case"day":case"d":return o*864e5;case"hours":case"hour":case"hrs":case"hr":case"h":return o*36e5;case"minutes":case"minute":case"mins":case"min":case"m":return o*6e4;case"seconds":case"second":case"secs":case"sec":case"s":return o*1e3;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return o;default:throw Error(`Unknown unit "${i}" provided to ms.parse(). value=${JSON.stringify(e)}`)}}function Pf(e){let t=Math.abs(e);return t>=315576e5?`${Math.round(e/315576e5)}y`:t>=26298e5?`${Math.round(e/26298e5)}mo`:t>=6048e5?`${Math.round(e/6048e5)}w`:t>=864e5?`${Math.round(e/864e5)}d`:t>=36e5?`${Math.round(e/36e5)}h`:t>=6e4?`${Math.round(e/6e4)}m`:t>=1e3?`${Math.round(e/1e3)}s`:`${e}ms`}function Nf(e){let t=Math.abs(e);return t>=315576e5?Te(e,t,315576e5,"year"):t>=26298e5?Te(e,t,26298e5,"month"):t>=6048e5?Te(e,t,6048e5,"week"):t>=864e5?Te(e,t,864e5,"day"):t>=36e5?Te(e,t,36e5,"hour"):t>=6e4?Te(e,t,6e4,"minute"):t>=1e3?Te(e,t,1e3,"second"):`${e} ms`}function Of(e,t){if(typeof e!="number"||!Number.isFinite(e))throw Error("Value provided to ms.format() must be of type number.");return t?.long?Nf(e):Pf(e)}function Te(e,t,r,n){let o=t>=r*1.5;return`${Math.round(e/r)} ${n}${o?"s":""}`}function To(e){r.debug=r,r.default=r,r.coerce=a,r.disable=i,r.enable=o,r.enabled=s,r.humanize=fn,r.destroy=l,Object.keys(e).forEach(u=>{r[u]=e[u]}),r.names=[],r.skips=[],r.formatters={};function t(u){let f=0;for(let x=0;x<u.length;x++)f=(f<<5)-f+u.charCodeAt(x),f|=0;return r.colors[Math.abs(f)%r.colors.length]}r.selectColor=t;function r(u,f){let x,v=null,b,T;function C(...w){if(!C.enabled)return;let I=C,S=Number(new Date),P=S-(x||S);I.diff=P,I.prev=x,I.curr=S,x=S,w[0]=r.coerce(w[0]),typeof w[0]!="string"&&w.unshift("%O");let k=0;w[0]=w[0].replace(/%([a-zA-Z%])/g,(V,h)=>{if(V==="%%")return"%";k++;let p=r.formatters[h];if(typeof p=="function"){let _=w[k];V=p.call(I,_),w.splice(k,1),k--}return V}),r.formatArgs.call(I,w),f?.onLog!=null&&f.onLog(...w),(I.log||r.log).apply(I,w)}return C.namespace=u,C.useColors=r.useColors(),C.color=r.selectColor(u),C.extend=n,C.destroy=r.destroy,Object.defineProperty(C,"enabled",{enumerable:!0,configurable:!1,get:()=>v!==null?v:(b!==r.namespaces&&(b=r.namespaces,T=r.enabled(u)),T),set:w=>{v=w}}),typeof r.init=="function"&&r.init(C),C}function n(u,f){let x=r(this.namespace+(typeof f>"u"?":":f)+u);return x.log=this.log,x}function o(u){r.save(u),r.namespaces=u,r.names=[],r.skips=[];let f,x=(typeof u=="string"?u:"").split(/[\s,]+/),v=x.length;for(f=0;f<v;f++)x[f]&&(u=x[f].replace(/\*/g,".*?"),u[0]==="-"?r.skips.push(new RegExp("^"+u.substr(1)+"$")):r.names.push(new RegExp("^"+u+"$")))}function i(){let u=[...r.names.map(c),...r.skips.map(c).map(f=>"-"+f)].join(",");return r.enable(""),u}function s(u){if(u[u.length-1]==="*")return!0;let f,x;for(f=0,x=r.skips.length;f<x;f++)if(r.skips[f].test(u))return!1;for(f=0,x=r.names.length;f<x;f++)if(r.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 r.setupFormatters(r.formatters),r.enable(r.load()),r}var ln=$f(),kf=["#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 Kf(){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 Vf(e){if(e[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+e[0]+(this.useColors?"%c ":" ")+"+"+fn(this.diff),!this.useColors)return;let t="color: "+this.color;e.splice(1,0,t,"color: inherit");let r=0,n=0;e[0].replace(/%[a-zA-Z%]/g,o=>{o!=="%%"&&(r++,o==="%c"&&(n=r))}),e.splice(n,0,t)}var Mf=console.debug??console.log??(()=>{});function Ff(e){try{e?ln?.setItem("debug",e):ln?.removeItem("debug")}catch{}}function qf(){let e;try{e=ln?.getItem("debug")}catch{}return!e&&typeof globalThis.process<"u"&&"env"in globalThis.process&&(e=globalThis.process.env.DEBUG),e}function $f(){try{return localStorage}catch{}}function Hf(e){e.j=function(t){try{return JSON.stringify(t)}catch(r){return"[UnexpectedJSONParseError]: "+r.message}}}var Ls=To({formatArgs:Vf,save:Ff,load:qf,useColors:Kf,setupFormatters:Hf,colors:kf,storage:ln,log:Mf});var St=Ls;St.formatters.b=e=>e==null?"undefined":W.baseEncode(e);St.formatters.t=e=>e==null?"undefined":zt.baseEncode(e);St.formatters.m=e=>e==null?"undefined":vo.baseEncode(e);St.formatters.p=e=>e==null?"undefined":e.toString();St.formatters.c=e=>e==null?"undefined":e.toString();St.formatters.k=e=>e==null?"undefined":e.toString();St.formatters.a=e=>e==null?"undefined":e.toString();function Us(e,t=""){let r=Ps(e.message),n=Ps(e.stack);return r!=null&&n!=null?n.includes(r)?`${n.split(`
2
+ "use strict";var HeliaDelegatedRoutingV1HttpApiClient=(()=>{var ff=Object.create;var fn=Object.defineProperty;var lf=Object.getOwnPropertyDescriptor;var df=Object.getOwnPropertyNames;var hf=Object.getPrototypeOf,pf=Object.prototype.hasOwnProperty;var Is=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),bt=(e,t)=>{for(var r in t)fn(e,r,{get:t[r],enumerable:!0})},Ts=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of df(t))!pf.call(e,o)&&o!==r&&fn(e,o,{get:()=>t[o],enumerable:!(n=lf(t,o))||n.enumerable});return e};var xo=(e,t,r)=>(r=e!=null?ff(hf(e)):{},Ts(t||!e||!e.__esModule?fn(r,"default",{value:e,enumerable:!0}):r,e)),mf=e=>Ts(fn({},"__esModule",{value:!0}),e);var fs=Is((qb,us)=>{var Fb=(function(){typeof us<"u"&&(us.exports=I);var e=86400,t=3200,r=146097*t/400,n=e*r,o=1e3*n,i=864e13,s=4294967296,c=1e6,a="000000000",l=Math.trunc||function(h){var p=h-h%1;return p==0&&(h<0||h===0&&1/h!=1/0)?-0:p},u=I.prototype,f=(I.fromDate=function(h){return new I(+h)},I.fromInt64BE=U(0,1,2,3,0,4),I.fromInt64LE=U(3,2,1,0,4,0),I.fromString=function(D){var p,_=new I,D=(D+="").replace(/^\s*[+\-]?\d+/,function(m){var m=+m,g=1970+(m-1970)%400;return _.year=m-g,g}).replace(/(?:Z|([+\-]\d{2}):?(\d{2}))$/,function(A,m,g){return m<0&&(g*=-1),p=6e4*(60*+m+ +g),""}).replace(/\.\d+$/,function(A){return _.nano=+(A+a).substr(1,9),""}).split(/\D+/);if(1<D.length?D[1]--:D[1]=0,_.time=p=Date.UTC.apply(Date,D)-(p||0),isNaN(p))throw new TypeError("Invalid Date");return C(_)},I.fromTimeT=function(h){return T(h,0)},u.year=0,u.time=0,u.nano=0,u.addNano=function(h){return this.nano+=+h||0,this},u.getNano=function(){var h=C(this);return(h.time%1e3*c+ +h.nano+1e9)%1e9},u.getTimeT=function(){var p=C(this),h=Math.floor(p.time/1e3),p=p.year;return p&&(h+=p*r*e/t),h},u.getYear=function(){return this.toDate().getUTCFullYear()+this.year},u.toDate=function(){return w(C(this).time)},u.toJSON=function(){return this.toString().replace(/0{1,6}Z$/,"Z")},u.toString=function(h){var p=this,_=p.toDate(),D={H:function(){return M(_.getUTCHours())},L:function(){return V(_.getUTCMilliseconds(),3)},M:function(){return M(_.getUTCMinutes())},N:function(){return V(p.getNano(),9)},S:function(){return M(_.getUTCSeconds())},Y:function(){var A=p.getYear();return 999999<A?"+"+A:9999<A?"+"+V(A,6):0<=A?V(A,4):-999999<=A?"-"+V(-A,6):A},a:function(){return E[_.getUTCDay()]},b:function(){return y[_.getUTCMonth()]},d:function(){return M(_.getUTCDate())},e:function(){return(function(A){return(9<A?"":" ")+(0|A)})(_.getUTCDate())},m:function(){return M(_.getUTCMonth()+1)}};return(function A(m){return m.replace(/%./g,function(g){var S=g[1],d=b[S],S=D[S];return d?A(d):S?S():g})})(h||f)},u.writeInt64BE=v(0,1,2,3,0,4),u.writeInt64LE=v(3,2,1,0,4,0),"%Y-%m-%dT%H:%M:%S.%NZ"),y=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],E=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],b={"%":"%",F:"%Y-%m-%d",n:`
3
+ `,R:"%H:%M",T:"%H:%M:%S",t:" ",X:"%T",Z:"GMT",z:"+0000"};return I;function I(h,p,_){var D=this;if(!(D instanceof I))return new I(h,p,_);D.time=+h||0,D.nano=+p||0,D.year=+_||0,C(D)}function C(h){var p,_,D,A=h.year,m=h.time,g=h.nano,d=((g<0||c<=g)&&(g-=(_=Math.floor(g/c))*c,m+=_,_=1),A%t);return(m<-i||i<m||d)&&((p=l(m/o))&&(A+=p*t,m-=p*o),(D=w(m)).setUTCFullYear(d+D.getUTCFullYear()),D=(m=+D)+(p=l((A-=d)/t))*o,p&&-i<=D&&D<=i&&(A-=p*t,m=D),_=1),_&&(h.year=A,h.time=m,h.nano=g),h}function w(h){var p=new Date(0);return p.setTime(h),p}function T(A,D){A=+A||0;var _=l((D=(D|0)*s)/n)+l(A/n),D=D%n+A%n,A=l(D/n);return A&&(_+=A,D-=A*n),new I(1e3*D,0,_*t)}function v(h,p,_,D,A,m){return function(d,S){var P=C(this);d=d||new Array(8),k(d,S|=0);var N=Math.floor(P.time/1e3),P=P.year*(r*e/t),R=l(P/s)+l(N/s),P=P%s+N%s,N=Math.floor(P/s);return N&&(R+=N,P-=N*s),g(d,S+A,R),g(d,S+m,P),d};function g(d,S,R){d[S+h]=R>>24&255,d[S+p]=R>>16&255,d[S+_]=R>>8&255,d[S+D]=255&R}}function U(h,p,_,D,A,m){return function(d,S){k(d,S|=0);var R=g(d,S+A);return T(g(d,S+m),R)};function g(d,S){return 16777216*d[S+h]+(d[S+p]<<16|d[S+_]<<8|d[S+D])}}function k(h,p){if(h=h&&h.length,h==null)throw new TypeError("Invalid Buffer");if(h<p+8)throw new RangeError("Out of range")}function M(h){return(9<h?"":"0")+(0|h)}function V(h,p){return(a+(0|h)).substr(-p)}})()});var rf=Is((B1,bs)=>{"use strict";var $p=Object.prototype.hasOwnProperty,Et="~";function on(){}Object.create&&(on.prototype=Object.create(null),new on().__proto__||(Et=!1));function Hp(e,t,r){this.fn=e,this.context=t,this.once=r||!1}function ef(e,t,r,n,o){if(typeof r!="function")throw new TypeError("The listener must be a function");var i=new Hp(r,n||e,o),s=Et?Et+t:t;return e._events[s]?e._events[s].fn?e._events[s]=[e._events[s],i]:e._events[s].push(i):(e._events[s]=i,e._eventsCount++),e}function po(e,t){--e._eventsCount===0?e._events=new on:delete e._events[t]}function xt(){this._events=new on,this._eventsCount=0}xt.prototype.eventNames=function(){var t=[],r,n;if(this._eventsCount===0)return t;for(n in r=this._events)$p.call(r,n)&&t.push(Et?n.slice(1):n);return Object.getOwnPropertySymbols?t.concat(Object.getOwnPropertySymbols(r)):t};xt.prototype.listeners=function(t){var r=Et?Et+t:t,n=this._events[r];if(!n)return[];if(n.fn)return[n.fn];for(var o=0,i=n.length,s=new Array(i);o<i;o++)s[o]=n[o].fn;return s};xt.prototype.listenerCount=function(t){var r=Et?Et+t:t,n=this._events[r];return n?n.fn?1:n.length:0};xt.prototype.emit=function(t,r,n,o,i,s){var c=Et?Et+t:t;if(!this._events[c])return!1;var a=this._events[c],l=arguments.length,u,f;if(a.fn){switch(a.once&&this.removeListener(t,a.fn,void 0,!0),l){case 1:return a.fn.call(a.context),!0;case 2:return a.fn.call(a.context,r),!0;case 3:return a.fn.call(a.context,r,n),!0;case 4:return a.fn.call(a.context,r,n,o),!0;case 5:return a.fn.call(a.context,r,n,o,i),!0;case 6:return a.fn.call(a.context,r,n,o,i,s),!0}for(f=1,u=new Array(l-1);f<l;f++)u[f-1]=arguments[f];a.fn.apply(a.context,u)}else{var y=a.length,E;for(f=0;f<y;f++)switch(a[f].once&&this.removeListener(t,a[f].fn,void 0,!0),l){case 1:a[f].fn.call(a[f].context);break;case 2:a[f].fn.call(a[f].context,r);break;case 3:a[f].fn.call(a[f].context,r,n);break;case 4:a[f].fn.call(a[f].context,r,n,o);break;default:if(!u)for(E=1,u=new Array(l-1);E<l;E++)u[E-1]=arguments[E];a[f].fn.apply(a[f].context,u)}}return!0};xt.prototype.on=function(t,r,n){return ef(this,t,r,n,!1)};xt.prototype.once=function(t,r,n){return ef(this,t,r,n,!0)};xt.prototype.removeListener=function(t,r,n,o){var i=Et?Et+t:t;if(!this._events[i])return this;if(!r)return po(this,i),this;var s=this._events[i];if(s.fn)s.fn===r&&(!o||s.once)&&(!n||s.context===n)&&po(this,i);else{for(var c=0,a=[],l=s.length;c<l;c++)(s[c].fn!==r||o&&!s[c].once||n&&s[c].context!==n)&&a.push(s[c]);a.length?this._events[i]=a.length===1?a[0]:a:po(this,i)}return this};xt.prototype.removeAllListeners=function(t){var r;return t?(r=Et?Et+t:t,this._events[r]&&po(this,r)):(this._events=new on,this._eventsCount=0),this};xt.prototype.off=xt.prototype.removeListener;xt.prototype.addListener=xt.prototype.on;xt.prefixed=Et;xt.EventEmitter=xt;typeof bs<"u"&&(bs.exports=xt)});var Jp={};bt(Jp,{createDelegatedRoutingV1HttpApiClient:()=>Wp,delegatedRoutingV1HttpApiClient:()=>Xp});var vo={};bt(vo,{base32:()=>Zt,base32hex:()=>Cf,base32hexpad:()=>Tf,base32hexpadupper:()=>Bf,base32hexupper:()=>If,base32pad:()=>vf,base32padupper:()=>Af,base32upper:()=>Sf,base32z:()=>_f});var t0=new Uint8Array(0);function Bs(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function ee(e){if(e instanceof Uint8Array&&e.constructor.name==="Uint8Array")return e;if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);throw new Error("Unknown type, must be binary type")}function _s(e){return new TextEncoder().encode(e)}function Ds(e){return new TextDecoder().decode(e)}function yf(e,t){if(e.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var o=0;o<e.length;o++){var i=e.charAt(o),s=i.charCodeAt(0);if(r[s]!==255)throw new TypeError(i+" is ambiguous");r[s]=o}var c=e.length,a=e.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 I=0,C=0,w=0,T=b.length;w!==T&&b[w]===0;)w++,I++;for(var v=(T-w)*u+1>>>0,U=new Uint8Array(v);w!==T;){for(var k=b[w],M=0,V=v-1;(k!==0||M<C)&&V!==-1;V--,M++)k+=256*U[V]>>>0,U[V]=k%c>>>0,k=k/c>>>0;if(k!==0)throw new Error("Non-zero carry");C=M,w++}for(var h=v-C;h!==v&&U[h]===0;)h++;for(var p=a.repeat(I);h<v;++h)p+=e.charAt(U[h]);return p}function y(b){if(typeof b!="string")throw new TypeError("Expected String");if(b.length===0)return new Uint8Array;var I=0;if(b[I]!==" "){for(var C=0,w=0;b[I]===a;)C++,I++;for(var T=(b.length-I)*l+1>>>0,v=new Uint8Array(T);b[I];){var U=r[b.charCodeAt(I)];if(U===255)return;for(var k=0,M=T-1;(U!==0||k<w)&&M!==-1;M--,k++)U+=c*v[M]>>>0,v[M]=U%256>>>0,U=U/256>>>0;if(U!==0)throw new Error("Non-zero carry");w=k,I++}if(b[I]!==" "){for(var V=T-w;V!==T&&v[V]===0;)V++;for(var h=new Uint8Array(C+(T-V)),p=C;V!==T;)h[p++]=v[V++];return h}}}function E(b){var I=y(b);if(I)return I;throw new Error(`Non-${t} character`)}return{encode:f,decodeUnsafe:y,decode:E}}var gf=yf,xf=gf,Ls=xf;var bo=class{name;prefix;baseEncode;constructor(t,r,n){this.name=t,this.prefix=r,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},wo=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,r,n){this.name=t,this.prefix=r;let o=r.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 Ps(this,t)}},Eo=class{decoders;constructor(t){this.decoders=t}or(t){return Ps(this,t)}decode(t){let r=t[0],n=this.decoders[r];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 Ps(e,t){return new Eo({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var So=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,r,n,o){this.name=t,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new bo(t,r,n),this.decoder=new wo(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function qe({name:e,prefix:t,encode:r,decode:n}){return new So(e,t,r,n)}function pe({name:e,prefix:t,alphabet:r}){let{encode:n,decode:o}=Ls(r,e);return qe({prefix:t,name:e,encode:n,decode:i=>ee(o(i))})}function bf(e,t,r,n){let o=e.length;for(;e[o-1]==="=";)--o;let i=new Uint8Array(o*r/8|0),s=0,c=0,a=0;for(let l=0;l<o;++l){let u=t[e[l]];if(u===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<r|u,s+=r,s>=8&&(s-=8,i[a++]=255&c>>s)}if(s>=r||(255&c<<8-s)!==0)throw new SyntaxError("Unexpected end of data");return i}function wf(e,t,r){let n=t[t.length-1]==="=",o=(1<<r)-1,i="",s=0,c=0;for(let a=0;a<e.length;++a)for(c=c<<8|e[a],s+=8;s>r;)s-=r,i+=t[o&c>>s];if(s!==0&&(i+=t[o&c<<r-s]),n)for(;(i.length*r&7)!==0;)i+="=";return i}function Ef(e){let t={};for(let r=0;r<e.length;++r)t[e[r]]=r;return t}function nt({name:e,prefix:t,bitsPerChar:r,alphabet:n}){let o=Ef(n);return qe({prefix:t,name:e,encode(i){return wf(i,n,r)},decode(i){return bf(i,o,r,e)}})}var Zt=nt({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Sf=nt({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),vf=nt({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Af=nt({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Cf=nt({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),If=nt({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Tf=nt({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Bf=nt({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),_f=nt({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Ao={};bt(Ao,{base58btc:()=>W,base58flickr:()=>Df});var W=pe({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Df=pe({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var To={};bt(To,{base64:()=>Co,base64pad:()=>Rf,base64url:()=>Io,base64urlpad:()=>Lf});var Co=nt({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Rf=nt({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Io=nt({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Lf=nt({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});function Pf(e,t){if(typeof e=="string")return Uf(e);if(typeof e=="number")return kf(e,t);throw Error(`Value provided to ms() must be a string or number. value=${JSON.stringify(e)}`)}var ln=Pf;function Uf(e){if(typeof e!="string"||e.length===0||e.length>100)throw Error(`Value provided to ms.parse() must be a string with length between 1 and 99. value=${JSON.stringify(e)}`);let t=/^(?<value>-?\d*\.?\d+) *(?<unit>milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|months?|mo|years?|yrs?|y)?$/i.exec(e);if(!t?.groups)return NaN;let{value:r,unit:n="ms"}=t.groups,o=parseFloat(r),i=n.toLowerCase();switch(i){case"years":case"year":case"yrs":case"yr":case"y":return o*315576e5;case"months":case"month":case"mo":return o*26298e5;case"weeks":case"week":case"w":return o*6048e5;case"days":case"day":case"d":return o*864e5;case"hours":case"hour":case"hrs":case"hr":case"h":return o*36e5;case"minutes":case"minute":case"mins":case"min":case"m":return o*6e4;case"seconds":case"second":case"secs":case"sec":case"s":return o*1e3;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return o;default:throw Error(`Unknown unit "${i}" provided to ms.parse(). value=${JSON.stringify(e)}`)}}function Nf(e){let t=Math.abs(e);return t>=315576e5?`${Math.round(e/315576e5)}y`:t>=26298e5?`${Math.round(e/26298e5)}mo`:t>=6048e5?`${Math.round(e/6048e5)}w`:t>=864e5?`${Math.round(e/864e5)}d`:t>=36e5?`${Math.round(e/36e5)}h`:t>=6e4?`${Math.round(e/6e4)}m`:t>=1e3?`${Math.round(e/1e3)}s`:`${e}ms`}function Of(e){let t=Math.abs(e);return t>=315576e5?Be(e,t,315576e5,"year"):t>=26298e5?Be(e,t,26298e5,"month"):t>=6048e5?Be(e,t,6048e5,"week"):t>=864e5?Be(e,t,864e5,"day"):t>=36e5?Be(e,t,36e5,"hour"):t>=6e4?Be(e,t,6e4,"minute"):t>=1e3?Be(e,t,1e3,"second"):`${e} ms`}function kf(e,t){if(typeof e!="number"||!Number.isFinite(e))throw Error("Value provided to ms.format() must be of type number.");return t?.long?Of(e):Nf(e)}function Be(e,t,r,n){let o=t>=r*1.5;return`${Math.round(e/r)} ${n}${o?"s":""}`}function Bo(e){r.debug=r,r.default=r,r.coerce=a,r.disable=i,r.enable=o,r.enabled=s,r.humanize=ln,r.destroy=l,Object.keys(e).forEach(u=>{r[u]=e[u]}),r.names=[],r.skips=[],r.formatters={};function t(u){let f=0;for(let y=0;y<u.length;y++)f=(f<<5)-f+u.charCodeAt(y),f|=0;return r.colors[Math.abs(f)%r.colors.length]}r.selectColor=t;function r(u,f){let y,E=null,b,I;function C(...w){if(!C.enabled)return;let T=C,v=Number(new Date),U=v-(y||v);T.diff=U,T.prev=y,T.curr=v,y=v,w[0]=r.coerce(w[0]),typeof w[0]!="string"&&w.unshift("%O");let k=0;w[0]=w[0].replace(/%([a-zA-Z%])/g,(V,h)=>{if(V==="%%")return"%";k++;let p=r.formatters[h];if(typeof p=="function"){let _=w[k];V=p.call(T,_),w.splice(k,1),k--}return V}),r.formatArgs.call(T,w),f?.onLog!=null&&f.onLog(...w),(T.log||r.log).apply(T,w)}return C.namespace=u,C.useColors=r.useColors(),C.color=r.selectColor(u),C.extend=n,C.destroy=r.destroy,Object.defineProperty(C,"enabled",{enumerable:!0,configurable:!1,get:()=>E!==null?E:(b!==r.namespaces&&(b=r.namespaces,I=r.enabled(u)),I),set:w=>{E=w}}),typeof r.init=="function"&&r.init(C),C}function n(u,f){let y=r(this.namespace+(typeof f>"u"?":":f)+u);return y.log=this.log,y}function o(u){r.save(u),r.namespaces=u,r.names=[],r.skips=[];let f,y=(typeof u=="string"?u:"").split(/[\s,]+/),E=y.length;for(f=0;f<E;f++)y[f]&&(u=y[f].replace(/\*/g,".*?"),u[0]==="-"?r.skips.push(new RegExp("^"+u.substr(1)+"$")):r.names.push(new RegExp("^"+u+"$")))}function i(){let u=[...r.names.map(c),...r.skips.map(c).map(f=>"-"+f)].join(",");return r.enable(""),u}function s(u){if(u[u.length-1]==="*")return!0;let f,y;for(f=0,y=r.skips.length;f<y;f++)if(r.skips[f].test(u))return!1;for(f=0,y=r.names.length;f<y;f++)if(r.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 r.setupFormatters(r.formatters),r.enable(r.load()),r}var dn=Hf(),Kf=["#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 Vf(){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 Mf(e){if(e[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+e[0]+(this.useColors?"%c ":" ")+"+"+ln(this.diff),!this.useColors)return;let t="color: "+this.color;e.splice(1,0,t,"color: inherit");let r=0,n=0;e[0].replace(/%[a-zA-Z%]/g,o=>{o!=="%%"&&(r++,o==="%c"&&(n=r))}),e.splice(n,0,t)}var Ff=console.debug??console.log??(()=>{});function qf(e){try{e?dn?.setItem("debug",e):dn?.removeItem("debug")}catch{}}function $f(){let e;try{e=dn?.getItem("debug")}catch{}return!e&&typeof globalThis.process<"u"&&"env"in globalThis.process&&(e=globalThis.process.env.DEBUG),e}function Hf(){try{return localStorage}catch{}}function zf(e){e.j=function(t){try{return JSON.stringify(t)}catch(r){return"[UnexpectedJSONParseError]: "+r.message}}}var Us=Bo({formatArgs:Mf,save:qf,load:$f,useColors:Vf,setupFormatters:zf,colors:Kf,storage:dn,log:Ff});var St=Us;St.formatters.b=e=>e==null?"undefined":W.baseEncode(e);St.formatters.t=e=>e==null?"undefined":Zt.baseEncode(e);St.formatters.m=e=>e==null?"undefined":Co.baseEncode(e);St.formatters.p=e=>e==null?"undefined":e.toString();St.formatters.c=e=>e==null?"undefined":e.toString();St.formatters.k=e=>e==null?"undefined":e.toString();St.formatters.a=e=>e==null?"undefined":e.toString();function Ns(e,t=""){let r=Os(e.message),n=Os(e.stack);return r!=null&&n!=null?n.includes(r)?`${n.split(`
4
4
  `).join(`
5
5
  ${t}`)}`:`${r}
6
6
  ${t}${n.split(`
7
7
  `).join(`
8
8
  ${t}`)}`:n!=null?`${n.split(`
9
9
  `).join(`
10
- ${t}`)}`:r!=null?`${r}`:`${e.toString()}`}function zf(e){return e instanceof AggregateError||e?.name==="AggregateError"&&Array.isArray(e.errors)}function Ns(e,t=""){if(zf(e)){let r=Us(e,t);return e.errors.length>0?(t=`${t} `,r+=`
11
- ${t}${e.errors.map(n=>`${Ns(n,`${t}`)}`).join(`
10
+ ${t}`)}`:r!=null?`${r}`:`${e.toString()}`}function Gf(e){return e instanceof AggregateError||e?.name==="AggregateError"&&Array.isArray(e.errors)}function ks(e,t=""){if(Gf(e)){let r=Ns(e,t);return e.errors.length>0?(t=`${t} `,r+=`
11
+ ${t}${e.errors.map(n=>`${ks(n,`${t}`)}`).join(`
12
12
  ${t}`)}`):r+=`
13
- ${t}[Error list was empty]`,r.trim()}return Us(e,t)}St.formatters.e=e=>e==null?"undefined":Ns(e);function Gf(e){let t=()=>{};return t.enabled=!1,t.color="",t.diff=0,t.log=()=>{},t.namespace=e,t.destroy=()=>!0,t.extend=()=>t,t}function Os(e){return{forComponent(t){return pe(t,e)}}}function pe(e,t){let r=Gf(`${e}:trace`);return St.enabled(`${e}:trace`)&&St.names.map(n=>n.toString()).find(n=>n.includes(":trace"))!=null&&(r=St(`${e}:trace`,t)),Object.assign(St(e,t),{error:St(`${e}:error`,t),trace:r,newScope:n=>pe(`${e}:${n}`,t)})}function Ps(e){if(e!=null&&(e=e.trim(),e.length!==0))return e}var ks=Symbol.for("@libp2p/content-routing");var st=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},Fe=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var Gt=class extends Error{static name="NotFoundError";constructor(t="Not found"){super(t),this.name="NotFoundError"}};var dn=class extends Error{static name="InvalidCIDError";constructor(t="Invalid CID"){super(t),this.name="InvalidCIDError"}},qe=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var $e=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var Io=Symbol.for("@libp2p/peer-id");var Ks=Symbol.for("@libp2p/peer-routing");var Bo={};Et(Bo,{base36:()=>He,base36upper:()=>Zf});var He=he({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Zf=he({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var jf=Fs,Vs=128,Yf=127,Wf=~Yf,Xf=Math.pow(2,31);function Fs(e,t,r){t=t||[],r=r||0;for(var n=r;e>=Xf;)t[r++]=e&255|Vs,e/=128;for(;e&Wf;)t[r++]=e&255|Vs,e>>>=7;return t[r]=e|0,Fs.bytes=r-n+1,t}var Jf=_o,Qf=128,Ms=127;function _o(e,n){var r=0,n=n||0,o=0,i=n,s,c=e.length;do{if(i>=c)throw _o.bytes=0,new RangeError("Could not decode varint");s=e[i++],r+=o<28?(s&Ms)<<o:(s&Ms)*Math.pow(2,o),o+=7}while(s>=Qf);return _o.bytes=i-n,r}var tl=Math.pow(2,7),el=Math.pow(2,14),rl=Math.pow(2,21),nl=Math.pow(2,28),ol=Math.pow(2,35),il=Math.pow(2,42),sl=Math.pow(2,49),al=Math.pow(2,56),cl=Math.pow(2,63),ul=function(e){return e<tl?1:e<el?2:e<rl?3:e<nl?4:e<ol?5:e<il?6:e<sl?7:e<al?8:e<cl?9:10},fl={encode:jf,decode:Jf,encodingLength:ul},ll=fl,Sr=ll;function vr(e,t=0){return[Sr.decode(e,t),Sr.decode.bytes]}function ze(e,t,r=0){return Sr.encode(e,t,r),t}function Ge(e){return Sr.encodingLength(e)}function Zt(e,t){let r=t.byteLength,n=Ge(e),o=n+Ge(r),i=new Uint8Array(o+r);return ze(e,i,0),ze(r,i,n),i.set(t,o),new Ze(e,r,t,i)}function Ie(e){let t=te(e),[r,n]=vr(t),[o,i]=vr(t.subarray(n)),s=t.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new Ze(r,o,s,t)}function qs(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&Ts(e.bytes,r.bytes)}}var Ze=class{code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=n,this.bytes=o}};function $s(e,t){let{bytes:r,version:n}=e;switch(n){case 0:return hl(r,Do(e),t??W.encoder);default:return pl(r,Do(e),t??zt.encoder)}}var Hs=new WeakMap;function Do(e){let t=Hs.get(e);if(t==null){let r=new Map;return Hs.set(e,r),r}return t}var j=class e{code;version;multihash;bytes;"/";constructor(t,r,n,o){this.code=r,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:r}=this;if(t!==Ar)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==ml)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return e.createV0(r)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:t,digest:r}=this.multihash,n=Zt(t,r);return e.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 e.equals(this,t)}static equals(t,r){let n=r;return n!=null&&t.code===n.code&&t.version===n.version&&qs(t.multihash,n.multihash)}toString(t){return $s(this,t)}toJSON(){return{"/":$s(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 r=t;if(r instanceof e)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:i,bytes:s}=r;return new e(n,o,i,s??zs(n,o,i.bytes))}else if(r[yl]===!0){let{version:n,multihash:o,code:i}=r,s=Ie(o);return e.create(n,i,s)}else return null}static create(t,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(r!==Ar)throw new Error(`Version 0 CID must use dag-pb (code: ${Ar}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=zs(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,Ar,t)}static createV1(t,r){return e.create(1,t,r)}static decode(t){let[r,n]=e.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(t){let r=e.inspectBytes(t),n=r.size-r.multihashSize,o=te(t.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let i=o.subarray(r.multihashSize-r.digestSize),s=new Ze(r.multihashCode,r.digestSize,i,o);return[r.version===0?e.createV0(s):e.createV1(r.codec,s),t.subarray(r.size)]}static inspectBytes(t){let r=0,n=()=>{let[f,x]=vr(t.subarray(r));return r+=x,f},o=n(),i=Ar;if(o===18?(o=0,r=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let s=r,c=n(),a=n(),l=r+a,u=l-s;return{version:o,codec:i,multihashCode:c,digestSize:a,multihashSize:u,size:l}}static parse(t,r){let[n,o]=dl(t,r),i=e.decode(o);if(i.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Do(i).set(n,t),i}};function dl(e,t){switch(e[0]){case"Q":{let r=t??W;return[W.prefix,r.decode(`${W.prefix}${e}`)]}case W.prefix:{let r=t??W;return[W.prefix,r.decode(e)]}case zt.prefix:{let r=t??zt;return[zt.prefix,r.decode(e)]}case He.prefix:{let r=t??He;return[He.prefix,r.decode(e)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[e[0],t.decode(e)]}}}function hl(e,t,r){let{prefix:n}=r;if(n!==W.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=t.get(n);if(o==null){let i=r.encode(e).slice(1);return t.set(n,i),i}else return o}function pl(e,t,r){let{prefix:n}=r,o=t.get(n);if(o==null){let i=r.encode(e);return t.set(n,i),i}else return o}var Ar=112,ml=18;function zs(e,t,r){let n=Ge(e),o=n+Ge(t),i=new Uint8Array(o+r.byteLength);return ze(e,i,0),ze(t,i,n),i.set(r,o),i}var yl=Symbol.for("@ipld/js-cid/CID");var Ro={};Et(Ro,{identity:()=>Ot});var Gs=0,gl="identity",Zs=te;function xl(e,t){if(t?.truncate!=null&&t.truncate!==e.byteLength){if(t.truncate<0||t.truncate>e.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${e.byteLength}`);e=e.subarray(0,t.truncate)}return Zt(Gs,Zs(e))}var Ot={code:Gs,name:gl,encode:Zs,digest:xl};function J(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function ee(e=0){return new Uint8Array(e)}function Ct(e=0){return new Uint8Array(e)}function Lt(e,t){t==null&&(t=e.reduce((o,i)=>o+i.length,0));let r=Ct(t),n=0;for(let o of e)r.set(o,n),n+=o.length;return r}var Ys=Symbol.for("@achingbrain/uint8arraylist");function js(e,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let r=0;for(let n of e){let o=r+n.byteLength;if(t<o)return{buf:n,index:t-r};r=o}throw new RangeError("index is out of bounds")}function je(e){return!!e?.[Ys]}var Tt=class e{bufs;length;[Ys]=!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 r=0;for(let n of t)if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.push(n);else if(je(n))r+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}prepend(...t){this.prependAll(t)}prependAll(t){let r=0;for(let n of t.reverse())if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.unshift(n);else if(je(n))r+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}get(t){let r=js(this.bufs,t);return r.buf[r.index]}set(t,r){let n=js(this.bufs,t);n.buf[n.index]=r}write(t,r=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(r+n,t[n]);else if(je(t))for(let n=0;n<t.length;n++)this.set(r+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,r){let{bufs:n,length:o}=this._subList(t,r);return Lt(n,o)}subarray(t,r){let{bufs:n,length:o}=this._subList(t,r);return n.length===1?n[0]:Lt(n,o)}sublist(t,r){let{bufs:n,length:o}=this._subList(t,r),i=new e;return i.length=o,i.bufs=[...n],i}_subList(t,r){if(t=t??0,r=r??this.length,t<0&&(t=this.length+t),r<0&&(r=this.length+r),t<0||r>this.length)throw new RangeError("index is out of bounds");if(t===r)return{bufs:[],length:0};if(t===0&&r===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=r>c&&r<=a;if(l&&u){if(t===c&&r===a){n.push(s);break}let f=t-c;n.push(s.subarray(f,f+(r-t)));break}if(l){if(t===0){n.push(s);continue}n.push(s.subarray(t-c));continue}if(u){if(r===a){n.push(s);break}n.push(s.subarray(0,r-c));break}n.push(s)}return{bufs:n,length:r-t}}indexOf(t,r=0){if(!je(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(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),t.length===0)return r>this.length?this.length:r;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=r;f<=a;f+=u){u=0;for(let x=l;x>=0;x--){let v=this.get(f+x);if(n[x]!==v){u=Math.max(1,x-c[v]);break}}if(u===0)return f}return-1}getInt8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(t,r){let n=Ct(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,r),this.write(n,t)}getInt16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,r)}setInt16(t,r,n){let o=ee(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,r,n),this.write(o,t)}getInt32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,r)}setInt32(t,r,n){let o=ee(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,r,n),this.write(o,t)}getBigInt64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,r)}setBigInt64(t,r,n){let o=ee(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,r,n),this.write(o,t)}getUint8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint8(0)}setUint8(t,r){let n=Ct(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,r),this.write(n,t)}getUint16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,r)}setUint16(t,r,n){let o=ee(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,r,n),this.write(o,t)}getUint32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,r)}setUint32(t,r,n){let o=ee(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,r,n),this.write(o,t)}getBigUint64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,r)}setBigUint64(t,r,n){let o=ee(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,r,n),this.write(o,t)}getFloat32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,r)}setFloat32(t,r,n){let o=ee(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,r,n),this.write(o,t)}getFloat64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,r)}setFloat64(t,r,n){let o=ee(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,r,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof e)||t.bufs.length!==this.bufs.length)return!1;for(let r=0;r<this.bufs.length;r++)if(!J(this.bufs[r],t.bufs[r]))return!1;return!0}static fromUint8Arrays(t,r){let n=new e;return n.bufs=t,r==null&&(r=t.reduce((o,i)=>o+i.byteLength,0)),n.length=r,n}};var Lo={};Et(Lo,{base10:()=>bl});var bl=he({prefix:"9",name:"base10",alphabet:"0123456789"});var Uo={};Et(Uo,{base16:()=>wl,base16upper:()=>El});var wl=nt({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),El=nt({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Po={};Et(Po,{base2:()=>Sl});var Sl=nt({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var No={};Et(No,{base256emoji:()=>Il});var Ws=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}"),vl=Ws.reduce((e,t,r)=>(e[r]=t,e),[]),Al=Ws.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function Cl(e){return e.reduce((t,r)=>(t+=vl[r],t),"")}function Tl(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=Al[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(o)}return new Uint8Array(t)}var Il=Me({prefix:"\u{1F680}",name:"base256emoji",encode:Cl,decode:Tl});var Oo={};Et(Oo,{base8:()=>Bl});var Bl=nt({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var ko={};Et(ko,{identity:()=>_l});var _l=Me({prefix:"\0",name:"identity",encode:e=>Bs(e),decode:e=>Is(e)});var J0=new TextEncoder,Q0=new TextDecoder;var Mo={};Et(Mo,{sha256:()=>Cr,sha512:()=>Ul});var Ll=20;function Vo({name:e,code:t,encode:r,minDigestLength:n,maxDigestLength:o}){return new Ko(e,t,r,n,o)}var Ko=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,r,n,o,i){this.name=t,this.code=r,this.encode=n,this.minDigestLength=o??Ll,this.maxDigestLength=i}digest(t,r){if(r?.truncate!=null){if(r.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&r.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(t instanceof Uint8Array){let n=this.encode(t);return n instanceof Uint8Array?Xs(n,this.code,r?.truncate):n.then(o=>Xs(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function Xs(e,t,r){if(r!=null&&r!==e.byteLength){if(r>e.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${e.byteLength}`);e=e.subarray(0,r)}return Zt(t,e)}function Qs(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var Cr=Vo({name:"sha2-256",code:18,encode:Qs("SHA-256")}),Ul=Vo({name:"sha2-512",code:19,encode:Qs("SHA-512")});var Tr={...ko,...Po,...Oo,...Lo,...Uo,...Eo,...Bo,...So,...Co,...No},lm={...Mo,...Ro};function ea(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var ta=ea("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),Fo=ea("ascii","a",e=>{let t="a";for(let r=0;r<e.length;r++)t+=String.fromCharCode(e[r]);return t},e=>{e=e.substring(1);let t=Ct(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),Pl={utf8:ta,"utf-8":ta,hex:Tr.base16,latin1:Fo,ascii:Fo,binary:Fo,...Tr},pn=Pl;function H(e,t="utf8"){let r=pn[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function z(e,t="utf8"){let r=pn[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var Nl=parseInt("11111",2),qo=parseInt("10000000",2),Ol=parseInt("01111111",2),ra={0:Ir,1:Ir,2:kl,3:Ml,4:Fl,5:Vl,6:Kl,16:Ir,22:Ir,48:Ir};function re(e,t={offset:0}){let r=e[t.offset]&Nl;if(t.offset++,ra[r]!=null)return ra[r](e,t);throw new Error("No decoder for tag "+r)}function Br(e,t){let r=0;if((e[t.offset]&qo)===qo){let n=e[t.offset]&Ol,o="0x";t.offset++;for(let i=0;i<n;i++,t.offset++)o+=e[t.offset].toString(16).padStart(2,"0");r=parseInt(o,16)}else r=e[t.offset],t.offset++;return r}function Ir(e,t){Br(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=re(e,t);if(n===null)break;r.push(n)}return r}function kl(e,t){let r=Br(e,t),n=t.offset,o=t.offset+r,i=[];for(let s=n;s<o;s++)s===n&&e[s]===0||i.push(e[s]);return t.offset+=r,Uint8Array.from(i)}function Kl(e,t){let r=Br(e,t),n=t.offset+r,o=e[t.offset];t.offset++;let i=0,s=0;o<40?(i=0,s=o):o<80?(i=1,s=o-40):(i=2,s=o-80);let c=`${i}.${s}`,a=[];for(;t.offset<n;){let l=e[t.offset];if(t.offset++,a.push(l&127),l<128){a.reverse();let u=0;for(let f=0;f<a.length;f++)u+=a[f]<<f*7;c+=`.${u}`,a=[]}}return c}function Vl(e,t){return t.offset++,null}function Ml(e,t){let r=Br(e,t),n=e[t.offset];t.offset++;let o=e.subarray(t.offset,t.offset+r-1);if(t.offset+=r,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function Fl(e,t){let r=Br(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function ql(e){let t=e.toString(16);t.length%2===1&&(t="0"+t);let r=new Tt;for(let n=0;n<t.length;n+=2)r.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return r}function $o(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);let t=ql(e.byteLength);return new Tt(Uint8Array.from([t.byteLength|qo]),t)}function vt(e){let t=new Tt,r=128;return(e.subarray()[0]&r)===r&&t.append(Uint8Array.from([0])),t.append(e),new Tt(Uint8Array.from([2]),$o(t),t)}function mn(e){let t=Uint8Array.from([0]),r=new Tt(t,e);return new Tt(Uint8Array.from([3]),$o(r),r)}function me(e,t=48){let r=new Tt;for(let n of e)r.append(n);return new Tt(Uint8Array.from([t]),$o(r),r)}async function na(e,t,r,n){let o=await crypto.subtle.importKey("jwk",e,{name:"ECDSA",namedCurve:e.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let i=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,t,r.subarray());return n?.signal?.throwIfAborted(),i}var $l=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Hl=Uint8Array.from([6,5,43,129,4,0,34]),zl=Uint8Array.from([6,5,43,129,4,0,35]),Gl={ext:!0,kty:"EC",crv:"P-256"},Zl={ext:!0,kty:"EC",crv:"P-384"},jl={ext:!0,kty:"EC",crv:"P-521"},Ho=32,zo=48,Go=66;function Zo(e){let t=re(e);return oa(t)}function oa(e){let t=e[1][1][0],r=1,n,o;if(t.byteLength===Ho*2+1)return n=z(t.subarray(r,r+Ho),"base64url"),o=z(t.subarray(r+Ho),"base64url"),new Ye({...Gl,key_ops:["verify"],x:n,y:o});if(t.byteLength===zo*2+1)return n=z(t.subarray(r,r+zo),"base64url"),o=z(t.subarray(r+zo),"base64url"),new Ye({...Zl,key_ops:["verify"],x:n,y:o});if(t.byteLength===Go*2+1)return n=z(t.subarray(r,r+Go),"base64url"),o=z(t.subarray(r+Go),"base64url"),new Ye({...jl,key_ops:["verify"],x:n,y:o});throw new st(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function ia(e){return me([vt(Uint8Array.from([1])),me([Yl(e.crv)],160),me([mn(new Tt(Uint8Array.from([4]),H(e.x??"","base64url"),H(e.y??"","base64url")))],161)]).subarray()}function Yl(e){if(e==="P-256")return $l;if(e==="P-384")return Hl;if(e==="P-521")return zl;throw new st(`Invalid curve ${e}`)}var Ye=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=ia(this.jwk)),this._raw}toMultihash(){return Ot.digest(We(this))}toCID(){return j.createV1(114,this.toMultihash())}toString(){return W.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:J(this.raw,t.raw)}async verify(t,r,n){return na(this.jwk,r,t,n)}};function _e(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function jt(e,t=""){if(!Number.isSafeInteger(e)||e<0){let r=t&&`"${t}" `;throw new Error(`${r}expected integer >= 0, got ${e}`)}}function $(e,t,r=""){let n=_e(e),o=e?.length,i=t!==void 0;if(!n||i&&o!==t){let s=r&&`"${r}" `,c=i?` of length ${t}`:"",a=n?`length=${o}`:`type=${typeof e}`;throw new Error(s+"expected Uint8Array"+c+", got "+a)}return e}function yn(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash must wrapped by utils.createHasher");jt(e.outputLen),jt(e.blockLen)}function Xe(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function aa(e,t){$(e,void 0,"digestInto() output");let r=t.outputLen;if(e.length<r)throw new Error('"digestInto() output" expected to be of length >='+r)}function oe(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function gn(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function kt(e,t){return e<<32-t|e>>>t}var ca=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Wl=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function ie(e){if($(e),ca)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=Wl[e[r]];return t}var ne={_0:48,_9:57,A:65,F:70,a:97,f:102};function sa(e){if(e>=ne._0&&e<=ne._9)return e-ne._0;if(e>=ne.A&&e<=ne.F)return e-(ne.A-10);if(e>=ne.a&&e<=ne.f)return e-(ne.a-10)}function se(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);if(ca)return Uint8Array.fromHex(e);let t=e.length,r=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(r);for(let o=0,i=0;o<r;o++,i+=2){let s=sa(e.charCodeAt(i)),c=sa(e.charCodeAt(i+1));if(s===void 0||c===void 0){let a=e[i]+e[i+1];throw new Error('hex string expected, got non-hex character "'+a+'" at index '+i)}n[o]=s*16+c}return n}function At(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];$(o),t+=o.length}let r=new Uint8Array(t);for(let n=0,o=0;n<e.length;n++){let i=e[n];r.set(i,o),o+=i.length}return r}function jo(e,t={}){let r=(o,i)=>e(i).update(o).digest(),n=e(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.create=o=>e(o),Object.assign(r,t),Object.freeze(r)}function Je(e=32){let t=typeof globalThis=="object"?globalThis.crypto:null;if(typeof t?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");return t.getRandomValues(new Uint8Array(e))}var Yo=e=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,e])});function ua(e,t,r){return e&t^~e&r}function fa(e,t,r){return e&t^e&r^t&r}var _r=class{blockLen;outputLen;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(t,r,n,o){this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=gn(this.buffer)}update(t){Xe(this),$(t);let{view:r,buffer:n,blockLen:o}=this,i=t.length;for(let s=0;s<i;){let c=Math.min(o-this.pos,i-s);if(c===o){let a=gn(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(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Xe(this),aa(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:i}=this,{pos:s}=this;r[s++]=128,oe(this.buffer.subarray(s)),this.padOffset>o-s&&(this.process(n,0),s=0);for(let f=s;f<o;f++)r[f]=0;n.setBigUint64(o-8,BigInt(this.length*8),i),this.process(n,0);let c=gn(t),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen must 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:r}=this;this.digestInto(t);let n=t.slice(0,r);return this.destroy(),n}_cloneInto(t){t||=new this.constructor,t.set(...this.get());let{blockLen:r,buffer:n,length:o,finished:i,destroyed:s,pos:c}=this;return t.destroyed=s,t.finished=i,t.length=o,t.pos=c,o%r&&t.buffer.set(n),t}clone(){return this._cloneInto()}},ae=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var dt=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var xn=BigInt(4294967295),la=BigInt(32);function Xl(e,t=!1){return t?{h:Number(e&xn),l:Number(e>>la&xn)}:{h:Number(e>>la&xn)|0,l:Number(e&xn)|0}}function da(e,t=!1){let r=e.length,n=new Uint32Array(r),o=new Uint32Array(r);for(let i=0;i<r;i++){let{h:s,l:c}=Xl(e[i],t);[n[i],o[i]]=[s,c]}return[n,o]}var Wo=(e,t,r)=>e>>>r,Xo=(e,t,r)=>e<<32-r|t>>>r,De=(e,t,r)=>e>>>r|t<<32-r,Re=(e,t,r)=>e<<32-r|t>>>r,Dr=(e,t,r)=>e<<64-r|t>>>r-32,Rr=(e,t,r)=>e>>>r-32|t<<64-r;function Yt(e,t,r,n){let o=(t>>>0)+(n>>>0);return{h:e+r+(o/2**32|0)|0,l:o|0}}var ha=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),pa=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,ma=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),ya=(e,t,r,n,o)=>t+r+n+o+(e/2**32|0)|0,ga=(e,t,r,n,o)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(o>>>0),xa=(e,t,r,n,o,i)=>t+r+n+o+i+(e/2**32|0)|0;var Ql=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),ye=new Uint32Array(64),Jo=class extends _r{constructor(t){super(64,t,8,!1)}get(){let{A:t,B:r,C:n,D:o,E:i,F:s,G:c,H:a}=this;return[t,r,n,o,i,s,c,a]}set(t,r,n,o,i,s,c,a){this.A=t|0,this.B=r|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,r){for(let f=0;f<16;f++,r+=4)ye[f]=t.getUint32(r,!1);for(let f=16;f<64;f++){let x=ye[f-15],v=ye[f-2],b=kt(x,7)^kt(x,18)^x>>>3,T=kt(v,17)^kt(v,19)^v>>>10;ye[f]=T+ye[f-7]+b+ye[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 x=kt(c,6)^kt(c,11)^kt(c,25),v=u+x+ua(c,a,l)+Ql[f]+ye[f]|0,T=(kt(n,2)^kt(n,13)^kt(n,22))+fa(n,o,i)|0;u=l,l=a,a=c,c=s+v|0,s=i,i=o,o=n,n=v+T|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(){oe(ye)}destroy(){this.set(0,0,0,0,0,0,0,0),oe(this.buffer)}},Qo=class extends Jo{A=ae[0]|0;B=ae[1]|0;C=ae[2]|0;D=ae[3]|0;E=ae[4]|0;F=ae[5]|0;G=ae[6]|0;H=ae[7]|0;constructor(){super(32)}};var ba=da(["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(e=>BigInt(e))),td=ba[0],ed=ba[1],ge=new Uint32Array(80),xe=new Uint32Array(80),ti=class extends _r{constructor(t){super(128,t,16,!1)}get(){let{Ah:t,Al:r,Bh:n,Bl:o,Ch:i,Cl:s,Dh:c,Dl:a,Eh:l,El:u,Fh:f,Fl:x,Gh:v,Gl:b,Hh:T,Hl:C}=this;return[t,r,n,o,i,s,c,a,l,u,f,x,v,b,T,C]}set(t,r,n,o,i,s,c,a,l,u,f,x,v,b,T,C){this.Ah=t|0,this.Al=r|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=x|0,this.Gh=v|0,this.Gl=b|0,this.Hh=T|0,this.Hl=C|0}process(t,r){for(let S=0;S<16;S++,r+=4)ge[S]=t.getUint32(r),xe[S]=t.getUint32(r+=4);for(let S=16;S<80;S++){let P=ge[S-15]|0,k=xe[S-15]|0,M=De(P,k,1)^De(P,k,8)^Wo(P,k,7),V=Re(P,k,1)^Re(P,k,8)^Xo(P,k,7),h=ge[S-2]|0,p=xe[S-2]|0,_=De(h,p,19)^Dr(h,p,61)^Wo(h,p,6),D=Re(h,p,19)^Rr(h,p,61)^Xo(h,p,6),A=ma(V,D,xe[S-7],xe[S-16]),m=ya(A,M,_,ge[S-7],ge[S-16]);ge[S]=m|0,xe[S]=A|0}let{Ah:n,Al:o,Bh:i,Bl:s,Ch:c,Cl:a,Dh:l,Dl:u,Eh:f,El:x,Fh:v,Fl:b,Gh:T,Gl:C,Hh:w,Hl:I}=this;for(let S=0;S<80;S++){let P=De(f,x,14)^De(f,x,18)^Dr(f,x,41),k=Re(f,x,14)^Re(f,x,18)^Rr(f,x,41),M=f&v^~f&T,V=x&b^~x&C,h=ga(I,k,V,ed[S],xe[S]),p=xa(h,w,P,M,td[S],ge[S]),_=h|0,D=De(n,o,28)^Dr(n,o,34)^Dr(n,o,39),A=Re(n,o,28)^Rr(n,o,34)^Rr(n,o,39),m=n&i^n&c^i&c,y=o&s^o&a^s&a;w=T|0,I=C|0,T=v|0,C=b|0,v=f|0,b=x|0,{h:f,l:x}=Yt(l|0,u|0,p|0,_|0),l=c|0,u=a|0,c=i|0,a=s|0,i=n|0,s=o|0;let d=ha(_,A,y);n=pa(d,p,D,m),o=d|0}({h:n,l:o}=Yt(this.Ah|0,this.Al|0,n|0,o|0)),{h:i,l:s}=Yt(this.Bh|0,this.Bl|0,i|0,s|0),{h:c,l:a}=Yt(this.Ch|0,this.Cl|0,c|0,a|0),{h:l,l:u}=Yt(this.Dh|0,this.Dl|0,l|0,u|0),{h:f,l:x}=Yt(this.Eh|0,this.El|0,f|0,x|0),{h:v,l:b}=Yt(this.Fh|0,this.Fl|0,v|0,b|0),{h:T,l:C}=Yt(this.Gh|0,this.Gl|0,T|0,C|0),{h:w,l:I}=Yt(this.Hh|0,this.Hl|0,w|0,I|0),this.set(n,o,i,s,c,a,l,u,f,x,v,b,T,C,w,I)}roundClean(){oe(ge,xe)}destroy(){oe(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},ei=class extends ti{Ah=dt[0]|0;Al=dt[1]|0;Bh=dt[2]|0;Bl=dt[3]|0;Ch=dt[4]|0;Cl=dt[5]|0;Dh=dt[6]|0;Dl=dt[7]|0;Eh=dt[8]|0;El=dt[9]|0;Fh=dt[10]|0;Fl=dt[11]|0;Gh=dt[12]|0;Gl=dt[13]|0;Hh=dt[14]|0;Hl=dt[15]|0;constructor(){super(64)}};var Qe=jo(()=>new Qo,Yo(1));var wa=jo(()=>new ei,Yo(3));var ni=BigInt(0),ri=BigInt(1);function ce(e,t=""){if(typeof e!="boolean"){let r=t&&`"${t}" `;throw new Error(r+"expected boolean, got type="+typeof e)}return e}function Ea(e){if(typeof e=="bigint"){if(!bn(e))throw new Error("positive bigint expected, got "+e)}else jt(e);return e}function Lr(e){let t=Ea(e).toString(16);return t.length&1?"0"+t:t}function Sa(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return e===""?ni:BigInt("0x"+e)}function tr(e){return Sa(ie(e))}function Le(e){return Sa(ie(En($(e)).reverse()))}function wn(e,t){jt(t),e=Ea(e);let r=se(e.toString(16).padStart(t*2,"0"));if(r.length!==t)throw new Error("number too large");return r}function oi(e,t){return wn(e,t).reverse()}function En(e){return Uint8Array.from(e)}var bn=e=>typeof e=="bigint"&&ni<=e;function rd(e,t,r){return bn(e)&&bn(t)&&bn(r)&&t<=e&&e<r}function Ur(e,t,r,n){if(!rd(t,r,n))throw new Error("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function ii(e){let t;for(t=0;e>ni;e>>=ri,t+=1);return t}var Pr=e=>(ri<<BigInt(e))-ri;function va(e,t,r){if(jt(e,"hashLen"),jt(t,"qByteLen"),typeof r!="function")throw new Error("hmacFn must be a function");let n=C=>new Uint8Array(C),o=Uint8Array.of(),i=Uint8Array.of(0),s=Uint8Array.of(1),c=1e3,a=n(e),l=n(e),u=0,f=()=>{a.fill(1),l.fill(0),u=0},x=(...C)=>r(l,At(a,...C)),v=(C=o)=>{l=x(i,C),a=x(),C.length!==0&&(l=x(s,C),a=x())},b=()=>{if(u++>=c)throw new Error("drbg: tried max amount of iterations");let C=0,w=[];for(;C<t;){a=x();let I=a.slice();w.push(I),C+=a.length}return At(...w)};return(C,w)=>{f(),v(C);let I;for(;!(I=w(b()));)v();return f(),I}}function be(e,t={},r={}){if(!e||typeof e!="object")throw new Error("expected valid options object");function n(i,s,c){let a=e[i];if(c&&a===void 0)return;let l=typeof a;if(l!==s||a===null)throw new Error(`param "${i}" is invalid: expected ${s}, got ${l}`)}let o=(i,s)=>Object.entries(i).forEach(([c,a])=>n(c,a,s));o(t,!1),o(r,!0)}function er(e){let t=new WeakMap;return(r,...n)=>{let o=t.get(r);if(o!==void 0)return o;let i=e(r,...n);return t.set(r,i),i}}var bt=BigInt(0),at=BigInt(1),Ue=BigInt(2),Ta=BigInt(3),Ia=BigInt(4),Ba=BigInt(5),nd=BigInt(7),_a=BigInt(8),od=BigInt(9),Da=BigInt(16);function ot(e,t){let r=e%t;return r>=bt?r:t+r}function X(e,t,r){let n=e;for(;t-- >bt;)n*=n,n%=r;return n}function Aa(e,t){if(e===bt)throw new Error("invert: expected non-zero number");if(t<=bt)throw new Error("invert: expected positive modulus, got "+t);let r=ot(e,t),n=t,o=bt,i=at,s=at,c=bt;for(;r!==bt;){let l=n/r,u=n%r,f=o-s*l,x=i-c*l;n=r,r=u,o=s,i=c,s=f,c=x}if(n!==at)throw new Error("invert: does not exist");return ot(o,t)}function ai(e,t,r){if(!e.eql(e.sqr(t),r))throw new Error("Cannot find square root")}function Ra(e,t){let r=(e.ORDER+at)/Ia,n=e.pow(t,r);return ai(e,n,t),n}function id(e,t){let r=(e.ORDER-Ba)/_a,n=e.mul(t,Ue),o=e.pow(n,r),i=e.mul(t,o),s=e.mul(e.mul(i,Ue),o),c=e.mul(i,e.sub(s,e.ONE));return ai(e,c,t),c}function sd(e){let t=rr(e),r=La(e),n=r(t,t.neg(t.ONE)),o=r(t,n),i=r(t,t.neg(n)),s=(e+nd)/Da;return(c,a)=>{let l=c.pow(a,s),u=c.mul(l,n),f=c.mul(l,o),x=c.mul(l,i),v=c.eql(c.sqr(u),a),b=c.eql(c.sqr(f),a);l=c.cmov(l,u,v),u=c.cmov(x,f,b);let T=c.eql(c.sqr(u),a),C=c.cmov(l,u,T);return ai(c,C,a),C}}function La(e){if(e<Ta)throw new Error("sqrt is not defined for small field");let t=e-at,r=0;for(;t%Ue===bt;)t/=Ue,r++;let n=Ue,o=rr(e);for(;Ca(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return Ra;let i=o.pow(n,t),s=(t+at)/Ue;return function(a,l){if(a.is0(l))return l;if(Ca(a,l)!==1)throw new Error("Cannot find square root");let u=r,f=a.mul(a.ONE,i),x=a.pow(l,t),v=a.pow(l,s);for(;!a.eql(x,a.ONE);){if(a.is0(x))return a.ZERO;let b=1,T=a.sqr(x);for(;!a.eql(T,a.ONE);)if(b++,T=a.sqr(T),b===u)throw new Error("Cannot find square root");let C=at<<BigInt(u-b-1),w=a.pow(f,C);u=b,f=a.sqr(w),x=a.mul(x,f),v=a.mul(v,w)}return v}}function ad(e){return e%Ia===Ta?Ra:e%_a===Ba?id:e%Da===od?sd(e):La(e)}var Ua=(e,t)=>(ot(e,t)&at)===at,cd=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function ci(e){let t={ORDER:"bigint",BYTES:"number",BITS:"number"},r=cd.reduce((n,o)=>(n[o]="function",n),t);return be(e,r),e}function ud(e,t,r){if(r<bt)throw new Error("invalid exponent, negatives unsupported");if(r===bt)return e.ONE;if(r===at)return t;let n=e.ONE,o=t;for(;r>bt;)r&at&&(n=e.mul(n,o)),o=e.sqr(o),r>>=at;return n}function Nr(e,t,r=!1){let n=new Array(t.length).fill(r?e.ZERO:void 0),o=t.reduce((s,c,a)=>e.is0(c)?s:(n[a]=s,e.mul(s,c)),e.ONE),i=e.inv(o);return t.reduceRight((s,c,a)=>e.is0(c)?s:(n[a]=e.mul(s,n[a]),e.mul(s,c)),i),n}function Ca(e,t){let r=(e.ORDER-at)/Ue,n=e.pow(t,r),o=e.eql(n,e.ONE),i=e.eql(n,e.ZERO),s=e.eql(n,e.neg(e.ONE));if(!o&&!i&&!s)throw new Error("invalid Legendre symbol result");return o?1:i?0:-1}function fd(e,t){t!==void 0&&jt(t);let r=t!==void 0?t:e.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}var si=class{ORDER;BITS;BYTES;isLE;ZERO=bt;ONE=at;_lengths;_sqrt;_mod;constructor(t,r={}){if(t<=bt)throw new Error("invalid field: expected ORDER > 0, got "+t);let n;this.isLE=!1,r!=null&&typeof r=="object"&&(typeof r.BITS=="number"&&(n=r.BITS),typeof r.sqrt=="function"&&(this.sqrt=r.sqrt),typeof r.isLE=="boolean"&&(this.isLE=r.isLE),r.allowedLengths&&(this._lengths=r.allowedLengths?.slice()),typeof r.modFromBytes=="boolean"&&(this._mod=r.modFromBytes));let{nBitLength:o,nByteLength:i}=fd(t,n);if(i>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=t,this.BITS=o,this.BYTES=i,this._sqrt=void 0,Object.preventExtensions(this)}create(t){return ot(t,this.ORDER)}isValid(t){if(typeof t!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof t);return bt<=t&&t<this.ORDER}is0(t){return t===bt}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}isOdd(t){return(t&at)===at}neg(t){return ot(-t,this.ORDER)}eql(t,r){return t===r}sqr(t){return ot(t*t,this.ORDER)}add(t,r){return ot(t+r,this.ORDER)}sub(t,r){return ot(t-r,this.ORDER)}mul(t,r){return ot(t*r,this.ORDER)}pow(t,r){return ud(this,t,r)}div(t,r){return ot(t*Aa(r,this.ORDER),this.ORDER)}sqrN(t){return t*t}addN(t,r){return t+r}subN(t,r){return t-r}mulN(t,r){return t*r}inv(t){return Aa(t,this.ORDER)}sqrt(t){return this._sqrt||(this._sqrt=ad(this.ORDER)),this._sqrt(this,t)}toBytes(t){return this.isLE?oi(t,this.BYTES):wn(t,this.BYTES)}fromBytes(t,r=!1){$(t);let{_lengths:n,BYTES:o,isLE:i,ORDER:s,_mod:c}=this;if(n){if(!n.includes(t.length)||t.length>o)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+t.length);let l=new Uint8Array(o);l.set(t,i?0:l.length-t.length),t=l}if(t.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+t.length);let a=i?Le(t):tr(t);if(c&&(a=ot(a,s)),!r&&!this.isValid(a))throw new Error("invalid field element: outside of range 0..ORDER");return a}invertBatch(t){return Nr(this,t)}cmov(t,r,n){return n?r:t}};function rr(e,t={}){return new si(e,t)}function Pa(e){if(typeof e!="bigint")throw new Error("field order must be bigint");let t=e.toString(2).length;return Math.ceil(t/8)}function ui(e){let t=Pa(e);return t+Math.ceil(t/2)}function fi(e,t,r=!1){$(e);let n=e.length,o=Pa(t),i=ui(t);if(n<16||n<i||n>1024)throw new Error("expected "+i+"-1024 bytes of input, got "+n);let s=r?Le(e):tr(e),c=ot(s,t-at)+at;return r?oi(c,o):wn(c,o)}var nr=BigInt(0),Pe=BigInt(1);function Or(e,t){let r=t.negate();return e?r:t}function Ne(e,t){let r=Nr(e.Fp,t.map(n=>n.Z));return t.map((n,o)=>e.fromAffine(n.toAffine(r[o])))}function Ka(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function li(e,t){Ka(e,t);let r=Math.ceil(t/e)+1,n=2**(e-1),o=2**e,i=Pr(e),s=BigInt(e);return{windows:r,windowSize:n,mask:i,maxNumber:o,shiftBy:s}}function Na(e,t,r){let{windowSize:n,mask:o,maxNumber:i,shiftBy:s}=r,c=Number(e&o),a=e>>s;c>n&&(c-=i,a+=Pe);let l=t*n,u=l+Math.abs(c)-1,f=c===0,x=c<0,v=t%2!==0;return{nextN:a,offset:u,isZero:f,isNeg:x,isNegF:v,offsetF:l}}var di=new WeakMap,Va=new WeakMap;function hi(e){return Va.get(e)||1}function Oa(e){if(e!==nr)throw new Error("invalid wNAF")}var or=class{BASE;ZERO;Fn;bits;constructor(t,r){this.BASE=t.BASE,this.ZERO=t.ZERO,this.Fn=t.Fn,this.bits=r}_unsafeLadder(t,r,n=this.ZERO){let o=t;for(;r>nr;)r&Pe&&(n=n.add(o)),o=o.double(),r>>=Pe;return n}precomputeWindow(t,r){let{windows:n,windowSize:o}=li(r,this.bits),i=[],s=t,c=s;for(let a=0;a<n;a++){c=s,i.push(c);for(let l=1;l<o;l++)c=c.add(s),i.push(c);s=c.double()}return i}wNAF(t,r,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let o=this.ZERO,i=this.BASE,s=li(t,this.bits);for(let c=0;c<s.windows;c++){let{nextN:a,offset:l,isZero:u,isNeg:f,isNegF:x,offsetF:v}=Na(n,c,s);n=a,u?i=i.add(Or(x,r[v])):o=o.add(Or(f,r[l]))}return Oa(n),{p:o,f:i}}wNAFUnsafe(t,r,n,o=this.ZERO){let i=li(t,this.bits);for(let s=0;s<i.windows&&n!==nr;s++){let{nextN:c,offset:a,isZero:l,isNeg:u}=Na(n,s,i);if(n=c,!l){let f=r[a];o=o.add(u?f.negate():f)}}return Oa(n),o}getPrecomputes(t,r,n){let o=di.get(r);return o||(o=this.precomputeWindow(r,t),t!==1&&(typeof n=="function"&&(o=n(o)),di.set(r,o))),o}cached(t,r,n){let o=hi(t);return this.wNAF(o,this.getPrecomputes(o,t,n),r)}unsafe(t,r,n,o){let i=hi(t);return i===1?this._unsafeLadder(t,r,o):this.wNAFUnsafe(i,this.getPrecomputes(i,t,n),r,o)}createCache(t,r){Ka(r,this.bits),Va.set(t,r),di.delete(t)}hasCache(t){return hi(t)!==1}};function Ma(e,t,r,n){let o=t,i=e.ZERO,s=e.ZERO;for(;r>nr||n>nr;)r&Pe&&(i=i.add(o)),n&Pe&&(s=s.add(o)),o=o.double(),r>>=Pe,n>>=Pe;return{p1:i,p2:s}}function ka(e,t,r){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return ci(t),t}else return rr(e,{isLE:r})}function Sn(e,t,r={},n){if(n===void 0&&(n=e==="edwards"),!t||typeof t!="object")throw new Error(`expected valid ${e} CURVE object`);for(let a of["p","n","h"]){let l=t[a];if(!(typeof l=="bigint"&&l>nr))throw new Error(`CURVE.${a} must be positive bigint`)}let o=ka(t.p,r.Fp,n),i=ka(t.n,r.Fn,n),c=["Gx","Gy","a",e==="weierstrass"?"b":"d"];for(let a of c)if(!o.isValid(t[a]))throw new Error(`CURVE.${a} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:o,Fn:i}}function vn(e,t){return function(n){let o=e(n);return{secretKey:o,publicKey:t(o)}}}var we=BigInt(0),ct=BigInt(1),pi=BigInt(2),ld=BigInt(8);function dd(e,t,r,n){let o=e.sqr(r),i=e.sqr(n),s=e.add(e.mul(t.a,o),i),c=e.add(e.ONE,e.mul(t.d,e.mul(o,i)));return e.eql(s,c)}function Fa(e,t={}){let r=Sn("edwards",e,t,t.FpFnLE),{Fp:n,Fn:o}=r,i=r.CURVE,{h:s}=i;be(t,{},{uvRatio:"function"});let c=pi<<BigInt(o.BYTES*8)-ct,a=C=>n.create(C),l=t.uvRatio||((C,w)=>{try{return{isValid:!0,value:n.sqrt(n.div(C,w))}}catch{return{isValid:!1,value:we}}});if(!dd(n,i,i.Gx,i.Gy))throw new Error("bad curve params: generator point");function u(C,w,I=!1){let S=I?ct:we;return Ur("coordinate "+C,w,S,c),w}function f(C){if(!(C instanceof b))throw new Error("EdwardsPoint expected")}let x=er((C,w)=>{let{X:I,Y:S,Z:P}=C,k=C.is0();w==null&&(w=k?ld:n.inv(P));let M=a(I*w),V=a(S*w),h=n.mul(P,w);if(k)return{x:we,y:ct};if(h!==ct)throw new Error("invZ was invalid");return{x:M,y:V}}),v=er(C=>{let{a:w,d:I}=i;if(C.is0())throw new Error("bad point: ZERO");let{X:S,Y:P,Z:k,T:M}=C,V=a(S*S),h=a(P*P),p=a(k*k),_=a(p*p),D=a(V*w),A=a(p*a(D+h)),m=a(_+a(I*a(V*h)));if(A!==m)throw new Error("bad point: equation left != right (1)");let y=a(S*P),d=a(k*M);if(y!==d)throw new Error("bad point: equation left != right (2)");return!0});class b{static BASE=new b(i.Gx,i.Gy,ct,a(i.Gx*i.Gy));static ZERO=new b(we,ct,ct,we);static Fp=n;static Fn=o;X;Y;Z;T;constructor(w,I,S,P){this.X=u("x",w),this.Y=u("y",I),this.Z=u("z",S,!0),this.T=u("t",P),Object.freeze(this)}static CURVE(){return i}static fromAffine(w){if(w instanceof b)throw new Error("extended point not allowed");let{x:I,y:S}=w||{};return u("x",I),u("y",S),new b(I,S,ct,a(I*S))}static fromBytes(w,I=!1){let S=n.BYTES,{a:P,d:k}=i;w=En($(w,S,"point")),ce(I,"zip215");let M=En(w),V=w[S-1];M[S-1]=V&-129;let h=Le(M),p=I?c:n.ORDER;Ur("point.y",h,we,p);let _=a(h*h),D=a(_-ct),A=a(k*_-P),{isValid:m,value:y}=l(D,A);if(!m)throw new Error("bad point: invalid y coordinate");let d=(y&ct)===ct,E=(V&128)!==0;if(!I&&y===we&&E)throw new Error("bad point: x=0 and x_0=1");return E!==d&&(y=a(-y)),b.fromAffine({x:y,y:h})}static fromHex(w,I=!1){return b.fromBytes(se(w),I)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(w=8,I=!0){return T.createCache(this,w),I||this.multiply(pi),this}assertValidity(){v(this)}equals(w){f(w);let{X:I,Y:S,Z:P}=this,{X:k,Y:M,Z:V}=w,h=a(I*V),p=a(k*P),_=a(S*V),D=a(M*P);return h===p&&_===D}is0(){return this.equals(b.ZERO)}negate(){return new b(a(-this.X),this.Y,this.Z,a(-this.T))}double(){let{a:w}=i,{X:I,Y:S,Z:P}=this,k=a(I*I),M=a(S*S),V=a(pi*a(P*P)),h=a(w*k),p=I+S,_=a(a(p*p)-k-M),D=h+M,A=D-V,m=h-M,y=a(_*A),d=a(D*m),E=a(_*m),R=a(A*D);return new b(y,d,R,E)}add(w){f(w);let{a:I,d:S}=i,{X:P,Y:k,Z:M,T:V}=this,{X:h,Y:p,Z:_,T:D}=w,A=a(P*h),m=a(k*p),y=a(V*S*D),d=a(M*_),E=a((P+k)*(h+p)-A-m),R=d-y,U=d+y,N=a(m-I*A),O=a(E*R),K=a(U*N),q=a(E*N),tt=a(R*U);return new b(O,K,tt,q)}subtract(w){return this.add(w.negate())}multiply(w){if(!o.isValidNot0(w))throw new Error("invalid scalar: expected 1 <= sc < curve.n");let{p:I,f:S}=T.cached(this,w,P=>Ne(b,P));return Ne(b,[I,S])[0]}multiplyUnsafe(w,I=b.ZERO){if(!o.isValid(w))throw new Error("invalid scalar: expected 0 <= sc < curve.n");return w===we?b.ZERO:this.is0()||w===ct?this:T.unsafe(this,w,S=>Ne(b,S),I)}isSmallOrder(){return this.multiplyUnsafe(s).is0()}isTorsionFree(){return T.unsafe(this,i.n).is0()}toAffine(w){return x(this,w)}clearCofactor(){return s===ct?this:this.multiplyUnsafe(s)}toBytes(){let{x:w,y:I}=this.toAffine(),S=n.toBytes(I);return S[S.length-1]|=w&ct?128:0,S}toHex(){return ie(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let T=new or(b,o.BITS);return b.BASE.precompute(8),b}function qa(e,t,r={}){if(typeof t!="function")throw new Error('"hash" function param is required');be(r,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:n}=r,{BASE:o,Fp:i,Fn:s}=e,c=r.randomBytes||Je,a=r.adjustScalarBytes||(h=>h),l=r.domain||((h,p,_)=>{if(ce(_,"phflag"),p.length||_)throw new Error("Contexts/pre-hash are not supported");return h});function u(h){return s.create(Le(h))}function f(h){let p=S.secretKey;$(h,S.secretKey,"secretKey");let _=$(t(h),2*p,"hashedSecretKey"),D=a(_.slice(0,p)),A=_.slice(p,2*p),m=u(D);return{head:D,prefix:A,scalar:m}}function x(h){let{head:p,prefix:_,scalar:D}=f(h),A=o.multiply(D),m=A.toBytes();return{head:p,prefix:_,scalar:D,point:A,pointBytes:m}}function v(h){return x(h).pointBytes}function b(h=Uint8Array.of(),...p){let _=At(...p);return u(t(l(_,$(h,void 0,"context"),!!n)))}function T(h,p,_={}){h=$(h,void 0,"message"),n&&(h=n(h));let{prefix:D,scalar:A,pointBytes:m}=x(p),y=b(_.context,D,h),d=o.multiply(y).toBytes(),E=b(_.context,d,m,h),R=s.create(y+E*A);if(!s.isValid(R))throw new Error("sign failed: invalid s");let U=At(d,s.toBytes(R));return $(U,S.signature,"result")}let C={zip215:!0};function w(h,p,_,D=C){let{context:A,zip215:m}=D,y=S.signature;h=$(h,y,"signature"),p=$(p,void 0,"message"),_=$(_,S.publicKey,"publicKey"),m!==void 0&&ce(m,"zip215"),n&&(p=n(p));let d=y/2,E=h.subarray(0,d),R=Le(h.subarray(d,y)),U,N,O;try{U=e.fromBytes(_,m),N=e.fromBytes(E,m),O=o.multiplyUnsafe(R)}catch{return!1}if(!m&&U.isSmallOrder())return!1;let K=b(A,N.toBytes(),U.toBytes(),p);return N.add(U.multiplyUnsafe(K)).subtract(O).clearCofactor().is0()}let I=i.BYTES,S={secretKey:I,publicKey:I,signature:2*I,seed:I};function P(h=c(S.seed)){return $(h,S.seed,"seed")}function k(h){return _e(h)&&h.length===s.BYTES}function M(h,p){try{return!!e.fromBytes(h,p)}catch{return!1}}let V={getExtendedPublicKey:x,randomSecretKey:P,isValidSecretKey:k,isValidPublicKey:M,toMontgomery(h){let{y:p}=e.fromBytes(h),_=S.publicKey,D=_===32;if(!D&&_!==57)throw new Error("only defined for 25519 and 448");let A=D?i.div(ct+p,ct-p):i.div(p-ct,p+ct);return i.toBytes(A)},toMontgomerySecret(h){let p=S.secretKey;$(h,p);let _=t(h.subarray(0,p));return a(_).subarray(0,p)}};return Object.freeze({keygen:vn(P,v),getPublicKey:v,sign:T,verify:w,utils:V,Point:e,lengths:S})}var hd=BigInt(1),$a=BigInt(2);var pd=BigInt(5),md=BigInt(8),mi=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),yd={p:mi,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:md,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function gd(e){let t=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),i=mi,c=e*e%i*e%i,a=X(c,$a,i)*c%i,l=X(a,hd,i)*e%i,u=X(l,pd,i)*l%i,f=X(u,t,i)*u%i,x=X(f,r,i)*f%i,v=X(x,n,i)*x%i,b=X(v,o,i)*v%i,T=X(b,o,i)*v%i,C=X(T,t,i)*u%i;return{pow_p_5_8:X(C,$a,i)*e%i,b2:c}}function xd(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}var Ha=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function bd(e,t){let r=mi,n=ot(t*t*t,r),o=ot(n*n*t,r),i=gd(e*o).pow_p_5_8,s=ot(e*n*i,r),c=ot(t*s*s,r),a=s,l=ot(s*Ha,r),u=c===e,f=c===ot(-e,r),x=c===ot(-e*Ha,r);return u&&(s=a),(f||x)&&(s=l),Ua(s,r)&&(s=ot(-s,r)),{isValid:u||f,value:s}}var wd=Fa(yd,{uvRatio:bd});function Ed(e){return qa(wd,wa,Object.assign({adjustScalarBytes:xd},e))}var za=Ed({});var kr=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},An=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var Ga={get(e=globalThis){let t=e.crypto;if(t?.subtle==null)throw new An("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api");return t}};var Ut=Ga;var Cn=32;var yi,Sd=(async()=>{try{return await Ut.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function vd(e,t,r){if(e.buffer instanceof ArrayBuffer){let n=await Ut.get().subtle.importKey("raw",e.buffer,{name:"Ed25519"},!1,["verify"]);return await Ut.get().subtle.verify({name:"Ed25519"},n,t,r instanceof Uint8Array?r:r.subarray())}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function Ad(e,t,r){return za.verify(t,r instanceof Uint8Array?r:r.subarray(),e)}async function Za(e,t,r){return yi==null&&(yi=await Sd),yi?vd(e,t,r):Ad(e,t,r)}function Tn(e){return e==null?!1:typeof e.then=="function"&&typeof e.catch=="function"&&typeof e.finally=="function"}var In=class{type="Ed25519";raw;constructor(t){this.raw=gi(t,Cn)}toMultihash(){return Ot.digest(We(this))}toCID(){return j.createV1(114,this.toMultihash())}toString(){return W.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:J(this.raw,t.raw)}verify(t,r,n){n?.signal?.throwIfAborted();let o=Za(this.raw,r,t);return Tn(o)?o.then(i=>(n?.signal?.throwIfAborted(),i)):o}};function xi(e){return e=gi(e,Cn),new In(e)}function gi(e,t){if(e=Uint8Array.from(e??[]),e.length!==t)throw new st(`Key must be a Uint8Array of length ${t}, got ${e.length}`);return e}var Td=Math.pow(2,7),Id=Math.pow(2,14),Bd=Math.pow(2,21),bi=Math.pow(2,28),wi=Math.pow(2,35),Ei=Math.pow(2,42),Si=Math.pow(2,49),Q=128,yt=127;function Wt(e){if(e<Td)return 1;if(e<Id)return 2;if(e<Bd)return 3;if(e<bi)return 4;if(e<wi)return 5;if(e<Ei)return 6;if(e<Si)return 7;if(Number.MAX_SAFE_INTEGER!=null&&e>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Kr(e,t,r=0){switch(Wt(e)){case 8:t[r++]=e&255|Q,e/=128;case 7:t[r++]=e&255|Q,e/=128;case 6:t[r++]=e&255|Q,e/=128;case 5:t[r++]=e&255|Q,e/=128;case 4:t[r++]=e&255|Q,e>>>=7;case 3:t[r++]=e&255|Q,e>>>=7;case 2:t[r++]=e&255|Q,e>>>=7;case 1:{t[r++]=e&255,e>>>=7;break}default:throw new Error("unreachable")}return t}function vi(e,t){let r=e[t],n=0;if(n+=r&yt,r<Q||(r=e[t+1],n+=(r&yt)<<7,r<Q)||(r=e[t+2],n+=(r&yt)<<14,r<Q)||(r=e[t+3],n+=(r&yt)<<21,r<Q)||(r=e[t+4],n+=(r&yt)*bi,r<Q)||(r=e[t+5],n+=(r&yt)*wi,r<Q)||(r=e[t+6],n+=(r&yt)*Ei,r<Q)||(r=e[t+7],n+=(r&yt)*Si,r<Q))return n;throw new RangeError("Could not decode varint")}function _d(e,t){let r=e.get(t),n=0;if(n+=r&yt,r<Q||(r=e.get(t+1),n+=(r&yt)<<7,r<Q)||(r=e.get(t+2),n+=(r&yt)<<14,r<Q)||(r=e.get(t+3),n+=(r&yt)<<21,r<Q)||(r=e.get(t+4),n+=(r&yt)*bi,r<Q)||(r=e.get(t+5),n+=(r&yt)*wi,r<Q)||(r=e.get(t+6),n+=(r&yt)*Ei,r<Q)||(r=e.get(t+7),n+=(r&yt)*Si,r<Q))return n;throw new RangeError("Could not decode varint")}function Ai(e,t=0){return e instanceof Uint8Array?vi(e,t):_d(e,t)}var Ci=new Float32Array([-0]),Ee=new Uint8Array(Ci.buffer);function Ya(e,t,r){Ci[0]=e,t[r]=Ee[0],t[r+1]=Ee[1],t[r+2]=Ee[2],t[r+3]=Ee[3]}function Wa(e,t){return Ee[0]=e[t],Ee[1]=e[t+1],Ee[2]=e[t+2],Ee[3]=e[t+3],Ci[0]}var Ti=new Float64Array([-0]),gt=new Uint8Array(Ti.buffer);function Xa(e,t,r){Ti[0]=e,t[r]=gt[0],t[r+1]=gt[1],t[r+2]=gt[2],t[r+3]=gt[3],t[r+4]=gt[4],t[r+5]=gt[5],t[r+6]=gt[6],t[r+7]=gt[7]}function Ja(e,t){return gt[0]=e[t],gt[1]=e[t+1],gt[2]=e[t+2],gt[3]=e[t+3],gt[4]=e[t+4],gt[5]=e[t+5],gt[6]=e[t+6],gt[7]=e[t+7],Ti[0]}var Rd=BigInt(Number.MAX_SAFE_INTEGER),Ld=BigInt(Number.MIN_SAFE_INTEGER),It=class e{lo;hi;constructor(t,r){this.lo=t|0,this.hi=r|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(r+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(BigInt(r)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(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,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?t<16384?t<128?1:2:t<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return Oe;if(t<Rd&&t>Ld)return this.fromNumber(Number(t));let r=t<0n;r&&(t=-t);let n=t>>32n,o=t-(n<<32n);return r&&(n=~n|0n,o=~o|0n,++o>Qa&&(o=0n,++n>Qa&&(n=0n))),new e(Number(o),Number(n))}static fromNumber(t){if(t===0)return Oe;let r=t<0;r&&(t=-t);let n=t>>>0,o=(t-n)/4294967296>>>0;return r&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new e(n,o)}static from(t){return typeof t=="number"?e.fromNumber(t):typeof t=="bigint"?e.fromBigInt(t):typeof t=="string"?e.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new e(t.low>>>0,t.high>>>0):Oe}},Oe=new It(0,0);Oe.toBigInt=function(){return 0n};Oe.zzEncode=Oe.zzDecode=function(){return this};Oe.length=function(){return 1};var Qa=4294967296n;function tc(e){let t=0,r=0;for(let n=0;n<e.length;++n)r=e.charCodeAt(n),r<128?t+=1:r<2048?t+=2:(r&64512)===55296&&(e.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function ec(e,t,r){if(r-t<1)return"";let o,i=[],s=0,c;for(;t<r;)c=e[t++],c<128?i[s++]=c:c>191&&c<224?i[s++]=(c&31)<<6|e[t++]&63:c>239&&c<365?(c=((c&7)<<18|(e[t++]&63)<<12|(e[t++]&63)<<6|e[t++]&63)-65536,i[s++]=55296+(c>>10),i[s++]=56320+(c&1023)):i[s++]=(c&15)<<12|(e[t++]&63)<<6|e[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 Ii(e,t,r){let n=r,o,i;for(let s=0;s<e.length;++s)o=e.charCodeAt(s),o<128?t[r++]=o:o<2048?(t[r++]=o>>6|192,t[r++]=o&63|128):(o&64512)===55296&&((i=e.charCodeAt(s+1))&64512)===56320?(o=65536+((o&1023)<<10)+(i&1023),++s,t[r++]=o>>18|240,t[r++]=o>>12&63|128,t[r++]=o>>6&63|128,t[r++]=o&63|128):(t[r++]=o>>12|224,t[r++]=o>>6&63|128,t[r++]=o&63|128);return r-n}function Kt(e,t){return RangeError(`index out of range: ${e.pos} + ${t??1} > ${e.len}`)}function Bn(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}var Bi=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,Kt(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 Kt(this,4);return Bn(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Kt(this,4);return Bn(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Kt(this,4);let t=Wa(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Kt(this,4);let t=Ja(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),r=this.pos,n=this.pos+t;if(n>this.len)throw Kt(this,t);return this.pos+=t,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let t=this.bytes();return ec(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Kt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Kt(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 It(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*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;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw Kt(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<r*7)>>>0,t}if(this.len-this.pos>4){for(;r<5;++r)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;r<5;++r){if(this.pos>=this.len)throw Kt(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Kt(this,8);let t=Bn(this.buf,this.pos+=4),r=Bn(this.buf,this.pos+=4);return new It(t,r)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=vi(this.buf,this.pos);return this.pos+=Wt(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 _i(e){return new Bi(e instanceof Uint8Array?e:e.subarray())}function ir(e,t,r){let n=_i(e);return t.decode(n,void 0,r)}function Di(e){let t=e??8192,r=t>>>1,n,o=t;return function(s){if(s<1||s>r)return Ct(s);o+s>t&&(n=Ct(t),o=0);let c=n.subarray(o,o+=s);return(o&7)!==0&&(o=(o|7)+1),c}}var ke=class{fn;len;next;val;constructor(t,r,n){this.fn=t,this.len=r,this.next=void 0,this.val=n}};function Ri(){}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}},Ud=Di();function Pd(e){return globalThis.Buffer!=null?Ct(e):Ud(e)}var Mr=class{len;head;tail;states;constructor(){this.len=0,this.head=new ke(Ri,0,0),this.tail=this.head,this.states=null}_push(t,r,n){return this.tail=this.tail.next=new ke(t,r,n),this.len+=r,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Pi((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(_n,10,It.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let r=It.fromBigInt(t);return this._push(_n,r.length(),r)}uint64Number(t){return this._push(Kr,Wt(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 r=It.fromBigInt(t).zzEncode();return this._push(_n,r.length(),r)}sint64Number(t){let r=It.fromNumber(t).zzEncode();return this._push(_n,r.length(),r)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Li,1,t?1:0)}fixed32(t){return this._push(Vr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let r=It.fromBigInt(t);return this._push(Vr,4,r.lo)._push(Vr,4,r.hi)}fixed64Number(t){let r=It.fromNumber(t);return this._push(Vr,4,r.lo)._push(Vr,4,r.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(Ya,4,t)}double(t){return this._push(Xa,8,t)}bytes(t){let r=t.length>>>0;return r===0?this._push(Li,1,0):this.uint32(r)._push(Od,r,t)}string(t){let r=tc(t);return r!==0?this.uint32(r)._push(Ii,r,t):this._push(Li,1,0)}fork(){return this.states=new Ui(this),this.head=this.tail=new ke(Ri,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 ke(Ri,0,0),this.len=0),this}ldelim(){let t=this.head,r=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=r,this.len+=n),this}finish(){let t=this.head.next,r=Pd(this.len),n=0;for(;t!=null;)t.fn(t.val,r,n),n+=t.len,t=t.next;return r}};function Li(e,t,r){t[r]=e&255}function Nd(e,t,r){for(;e>127;)t[r++]=e&127|128,e>>>=7;t[r]=e}var Pi=class extends ke{next;constructor(t,r){super(Nd,t,r),this.next=void 0}};function _n(e,t,r){for(;e.hi!==0;)t[r++]=e.lo&127|128,e.lo=(e.lo>>>7|e.hi<<25)>>>0,e.hi>>>=7;for(;e.lo>127;)t[r++]=e.lo&127|128,e.lo=e.lo>>>7;t[r++]=e.lo}function Vr(e,t,r){t[r]=e&255,t[r+1]=e>>>8&255,t[r+2]=e>>>16&255,t[r+3]=e>>>24}function Od(e,t,r){t.set(e,r)}globalThis.Buffer!=null&&(Mr.prototype.bytes=function(e){let t=e.length>>>0;return this.uint32(t),t>0&&this._push(kd,t,e),this},Mr.prototype.string=function(e){let t=globalThis.Buffer.byteLength(e);return this.uint32(t),t>0&&this._push(Kd,t,e),this});function kd(e,t,r){t.set(e,r)}function Kd(e,t,r){e.length<40?Ii(e,t,r):t.utf8Write!=null?t.utf8Write(e,r):t.set(H(e),r)}function Ni(){return new Mr}function sr(e,t){let r=Ni();return t.encode(e,r,{lengthDelimited:!1}),r.finish()}var ar;(function(e){e[e.VARINT=0]="VARINT",e[e.BIT64=1]="BIT64",e[e.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",e[e.START_GROUP=3]="START_GROUP",e[e.END_GROUP=4]="END_GROUP",e[e.BIT32=5]="BIT32"})(ar||(ar={}));function Dn(e,t,r,n){return{name:e,type:t,encode:r,decode:n}}function Fr(e){function t(o){if(e[o.toString()]==null)throw new Error("Invalid enum value");return e[o]}let r=function(i,s){let c=t(i);s.int32(c)},n=function(i){let s=i.int32();return t(s)};return Dn("enum",ar.VARINT,r,n)}function cr(e,t){return Dn("message",ar.LENGTH_DELIMITED,e,t)}var it;(function(e){e.RSA="RSA",e.Ed25519="Ed25519",e.secp256k1="secp256k1",e.ECDSA="ECDSA"})(it||(it={}));var Oi;(function(e){e[e.RSA=0]="RSA",e[e.Ed25519=1]="Ed25519",e[e.secp256k1=2]="secp256k1",e[e.ECDSA=3]="ECDSA"})(Oi||(Oi={}));(function(e){e.codec=()=>Fr(Oi)})(it||(it={}));var Xt;(function(e){let t;e.codec=()=>(t==null&&(t=cr((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),it.codec().encode(r.Type,n)),r.Data!=null&&(n.uint32(18),n.bytes(r.Data)),o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let i={},s=n==null?r.len:r.pos+n;for(;r.pos<s;){let c=r.uint32();switch(c>>>3){case 1:{i.Type=it.codec().decode(r);break}case 2:{i.Data=r.bytes();break}default:{r.skipType(c&7);break}}}return i})),t),e.encode=r=>sr(r,e.codec()),e.decode=(r,n)=>ir(r,e.codec(),n)})(Xt||(Xt={}));var ki;(function(e){let t;e.codec=()=>(t==null&&(t=cr((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),it.codec().encode(r.Type,n)),r.Data!=null&&(n.uint32(18),n.bytes(r.Data)),o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let i={},s=n==null?r.len:r.pos+n;for(;r.pos<s;){let c=r.uint32();switch(c>>>3){case 1:{i.Type=it.codec().decode(r);break}case 2:{i.Data=r.bytes();break}default:{r.skipType(c&7);break}}}return i})),t),e.encode=r=>sr(r,e.codec()),e.decode=(r,n)=>ir(r,e.codec(),n)})(ki||(ki={}));var $r={};Et($r,{MAX_RSA_KEY_SIZE:()=>Ki,generateRSAKeyPair:()=>ac,jwkToJWKKeyPair:()=>cc,jwkToPkcs1:()=>qd,jwkToPkix:()=>qi,jwkToRSAPrivateKey:()=>Gi,pkcs1MessageToJwk:()=>Mi,pkcs1MessageToRSAPrivateKey:()=>$i,pkcs1ToJwk:()=>Fd,pkcs1ToRSAPrivateKey:()=>sc,pkixMessageToJwk:()=>Fi,pkixMessageToRSAPublicKey:()=>zi,pkixToJwk:()=>$d,pkixToRSAPublicKey:()=>Hi});var ur=class{type="RSA";jwk;_raw;_multihash;constructor(t,r){this.jwk=t,this._multihash=r}get raw(){return this._raw==null&&(this._raw=$r.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return j.createV1(114,this._multihash)}toString(){return W.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:J(this.raw,t.raw)}verify(t,r,n){return ic(this.jwk,r,t,n)}},qr=class{type="RSA";jwk;_raw;publicKey;constructor(t,r){this.jwk=t,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=$r.jwkToPkcs1(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:J(this.raw,t.raw)}sign(t,r){return oc(this.jwk,t,r)}};var Ki=8192,Vi=18,Vd=1062,Md=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function Fd(e){let t=re(e);return Mi(t)}function Mi(e){return{n:z(e[1],"base64url"),e:z(e[2],"base64url"),d:z(e[3],"base64url"),p:z(e[4],"base64url"),q:z(e[5],"base64url"),dp:z(e[6],"base64url"),dq:z(e[7],"base64url"),qi:z(e[8],"base64url"),kty:"RSA"}}function qd(e){if(e.n==null||e.e==null||e.d==null||e.p==null||e.q==null||e.dp==null||e.dq==null||e.qi==null)throw new st("JWK was missing components");return me([vt(Uint8Array.from([0])),vt(H(e.n,"base64url")),vt(H(e.e,"base64url")),vt(H(e.d,"base64url")),vt(H(e.p,"base64url")),vt(H(e.q,"base64url")),vt(H(e.dp,"base64url")),vt(H(e.dq,"base64url")),vt(H(e.qi,"base64url"))]).subarray()}function $d(e){let t=re(e,{offset:0});return Fi(t)}function Fi(e){let t=re(e[1],{offset:0});return{kty:"RSA",n:z(t[0],"base64url"),e:z(t[1],"base64url")}}function qi(e){if(e.n==null||e.e==null)throw new st("JWK was missing components");return me([Md,mn(me([vt(H(e.n,"base64url")),vt(H(e.e,"base64url"))]))]).subarray()}function sc(e){let t=re(e);return $i(t)}function $i(e){let t=Mi(e);return Gi(t)}function Hi(e,t){if(e.byteLength>=Vd)throw new Fe("Key size is too large");let r=re(e,{offset:0});return zi(r,e,t)}function zi(e,t,r){let n=Fi(e);if(r==null){let o=Qe(Xt.encode({Type:it.RSA,Data:t}));r=Zt(Vi,o)}return new ur(n,r)}function Gi(e){if(fc(e)>Ki)throw new st("Key size is too large");let t=cc(e),r=Qe(Xt.encode({Type:it.RSA,Data:qi(t.publicKey)})),n=Zt(Vi,r);return new qr(t.privateKey,new ur(t.publicKey,n))}async function ac(e){if(e>Ki)throw new st("Key size is too large");let t=await uc(e),r=Qe(Xt.encode({Type:it.RSA,Data:qi(t.publicKey)})),n=Zt(Vi,r);return new qr(t.privateKey,new ur(t.publicKey,n))}function cc(e){if(e==null)throw new st("Missing key parameter");return{privateKey:e,publicKey:{kty:e.kty,n:e.n,e:e.e}}}async function uc(e,t){let r=await Ut.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:e,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]);t?.signal?.throwIfAborted();let n=await Hd(r,t);return{privateKey:n[0],publicKey:n[1]}}async function oc(e,t,r){let n=await Ut.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);r?.signal?.throwIfAborted();let o=await Ut.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,t instanceof Uint8Array?t:t.subarray());return r?.signal?.throwIfAborted(),new Uint8Array(o,0,o.byteLength)}async function ic(e,t,r,n){let o=await Ut.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let i=await Ut.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,t,r instanceof Uint8Array?r:r.subarray());return n?.signal?.throwIfAborted(),i}async function Hd(e,t){if(e.privateKey==null||e.publicKey==null)throw new st("Private and public key are required");let r=await Promise.all([Ut.get().subtle.exportKey("jwk",e.privateKey),Ut.get().subtle.exportKey("jwk",e.publicKey)]);return t?.signal?.throwIfAborted(),r}function fc(e){if(e.kty!=="RSA")throw new st("invalid key type");if(e.n==null)throw new st("invalid key modulus");return H(e.n,"base64url").length*8}var Rn=class{oHash;iHash;blockLen;outputLen;finished=!1;destroyed=!1;constructor(t,r){if(yn(t),$(r,void 0,"key"),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 n=this.blockLen,o=new Uint8Array(n);o.set(r.length>n?t.create().update(r).digest():r);for(let i=0;i<o.length;i++)o[i]^=54;this.iHash.update(o),this.oHash=t.create();for(let i=0;i<o.length;i++)o[i]^=106;this.oHash.update(o),oe(o)}update(t){return Xe(this),this.iHash.update(t),this}digestInto(t){Xe(this),$(t,this.outputLen,"output"),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||=Object.create(Object.getPrototypeOf(this),{});let{oHash:r,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=r._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Zi=(e,t,r)=>new Rn(e,t).update(r).digest();Zi.create=(e,t)=>new Rn(e,t);var lc=(e,t)=>(e+(e>=0?t:-t)/dc)/t;function zd(e,t,r){let[[n,o],[i,s]]=t,c=lc(s*e,r),a=lc(-o*e,r),l=e-c*n-a*i,u=-c*o-a*s,f=l<ue,x=u<ue;f&&(l=-l),x&&(u=-u);let v=Pr(Math.ceil(ii(r)/2))+fr;if(l<ue||l>=v||u<ue||u>=v)throw new Error("splitScalar (endomorphism): failed, k="+e);return{k1neg:f,k1:l,k2neg:x,k2:u}}function Yi(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function ji(e,t){let r={};for(let n of Object.keys(t))r[n]=e[n]===void 0?t[n]:e[n];return ce(r.lowS,"lowS"),ce(r.prehash,"prehash"),r.format!==void 0&&Yi(r.format),r}var Wi=class extends Error{constructor(t=""){super(t)}},Se={Err:Wi,_tlv:{encode:(e,t)=>{let{Err:r}=Se;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(t.length&1)throw new r("tlv.encode: unpadded data");let n=t.length/2,o=Lr(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let i=n>127?Lr(o.length/2|128):"";return Lr(e)+i+o+t},decode(e,t){let{Err:r}=Se,n=0;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(t.length<2||t[n++]!==e)throw new r("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 r("tlv.decode(long): indefinite length not supported");if(a>4)throw new r("tlv.decode(long): byte length is too big");let l=t.subarray(n,n+a);if(l.length!==a)throw new r("tlv.decode: length bytes not complete");if(l[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let u of l)s=s<<8|u;if(n+=a,s<128)throw new r("tlv.decode(long): not minimal encoding")}let c=t.subarray(n,n+s);if(c.length!==s)throw new r("tlv.decode: wrong value length");return{v:c,l:t.subarray(n+s)}}},_int:{encode(e){let{Err:t}=Se;if(e<ue)throw new t("integer: negative integers are not allowed");let r=Lr(e);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new t("unexpected DER parsing assertion: unpadded hex");return r},decode(e){let{Err:t}=Se;if(e[0]&128)throw new t("invalid signature integer: negative");if(e[0]===0&&!(e[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return tr(e)}},toSig(e){let{Err:t,_int:r,_tlv:n}=Se,o=$(e,void 0,"signature"),{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:r.decode(c),s:r.decode(l)}},hexFromSig(e){let{_tlv:t,_int:r}=Se,n=t.encode(2,r.encode(e.r)),o=t.encode(2,r.encode(e.s)),i=n+o;return t.encode(48,i)}},ue=BigInt(0),fr=BigInt(1),dc=BigInt(2),Ln=BigInt(3),Gd=BigInt(4);function hc(e,t={}){let r=Sn("weierstrass",e,t),{Fp:n,Fn:o}=r,i=r.CURVE,{h:s,n:c}=i;be(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object"});let{endo:a}=t;if(a&&(!n.is0(i.a)||typeof a.beta!="bigint"||!Array.isArray(a.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let l=mc(n,o);function u(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function f(A,m,y){let{x:d,y:E}=m.toAffine(),R=n.toBytes(d);if(ce(y,"isCompressed"),y){u();let U=!n.isOdd(E);return At(pc(U),R)}else return At(Uint8Array.of(4),R,n.toBytes(E))}function x(A){$(A,void 0,"Point");let{publicKey:m,publicKeyUncompressed:y}=l,d=A.length,E=A[0],R=A.subarray(1);if(d===m&&(E===2||E===3)){let U=n.fromBytes(R);if(!n.isValid(U))throw new Error("bad point: is not on curve, wrong x");let N=T(U),O;try{O=n.sqrt(N)}catch(tt){let Y=tt instanceof Error?": "+tt.message:"";throw new Error("bad point: is not on curve, sqrt error"+Y)}u();let K=n.isOdd(O);return(E&1)===1!==K&&(O=n.neg(O)),{x:U,y:O}}else if(d===y&&E===4){let U=n.BYTES,N=n.fromBytes(R.subarray(0,U)),O=n.fromBytes(R.subarray(U,U*2));if(!C(N,O))throw new Error("bad point: is not on curve");return{x:N,y:O}}else throw new Error(`bad point: got length ${d}, expected compressed=${m} or uncompressed=${y}`)}let v=t.toBytes||f,b=t.fromBytes||x;function T(A){let m=n.sqr(A),y=n.mul(m,A);return n.add(n.add(y,n.mul(A,i.a)),i.b)}function C(A,m){let y=n.sqr(m),d=T(A);return n.eql(y,d)}if(!C(i.Gx,i.Gy))throw new Error("bad curve params: generator point");let w=n.mul(n.pow(i.a,Ln),Gd),I=n.mul(n.sqr(i.b),BigInt(27));if(n.is0(n.add(w,I)))throw new Error("bad curve params: a or b");function S(A,m,y=!1){if(!n.isValid(m)||y&&n.is0(m))throw new Error(`bad point coordinate ${A}`);return m}function P(A){if(!(A instanceof p))throw new Error("Weierstrass Point expected")}function k(A){if(!a||!a.basises)throw new Error("no endo");return zd(A,a.basises,o.ORDER)}let M=er((A,m)=>{let{X:y,Y:d,Z:E}=A;if(n.eql(E,n.ONE))return{x:y,y:d};let R=A.is0();m==null&&(m=R?n.ONE:n.inv(E));let U=n.mul(y,m),N=n.mul(d,m),O=n.mul(E,m);if(R)return{x:n.ZERO,y:n.ZERO};if(!n.eql(O,n.ONE))throw new Error("invZ was invalid");return{x:U,y:N}}),V=er(A=>{if(A.is0()){if(t.allowInfinityPoint&&!n.is0(A.Y))return;throw new Error("bad point: ZERO")}let{x:m,y}=A.toAffine();if(!n.isValid(m)||!n.isValid(y))throw new Error("bad point: x or y not field elements");if(!C(m,y))throw new Error("bad point: equation left != right");if(!A.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function h(A,m,y,d,E){return y=new p(n.mul(y.X,A),y.Y,y.Z),m=Or(d,m),y=Or(E,y),m.add(y)}class p{static BASE=new p(i.Gx,i.Gy,n.ONE);static ZERO=new p(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(m,y,d){this.X=S("x",m),this.Y=S("y",y,!0),this.Z=S("z",d),Object.freeze(this)}static CURVE(){return i}static fromAffine(m){let{x:y,y:d}=m||{};if(!m||!n.isValid(y)||!n.isValid(d))throw new Error("invalid affine point");if(m instanceof p)throw new Error("projective point not allowed");return n.is0(y)&&n.is0(d)?p.ZERO:new p(y,d,n.ONE)}static fromBytes(m){let y=p.fromAffine(b($(m,void 0,"point")));return y.assertValidity(),y}static fromHex(m){return p.fromBytes(se(m))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(m=8,y=!0){return D.createCache(this,m),y||this.multiply(Ln),this}assertValidity(){V(this)}hasEvenY(){let{y:m}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(m)}equals(m){P(m);let{X:y,Y:d,Z:E}=this,{X:R,Y:U,Z:N}=m,O=n.eql(n.mul(y,N),n.mul(R,E)),K=n.eql(n.mul(d,N),n.mul(U,E));return O&&K}negate(){return new p(this.X,n.neg(this.Y),this.Z)}double(){let{a:m,b:y}=i,d=n.mul(y,Ln),{X:E,Y:R,Z:U}=this,N=n.ZERO,O=n.ZERO,K=n.ZERO,q=n.mul(E,E),tt=n.mul(R,R),Y=n.mul(U,U),G=n.mul(E,R);return G=n.add(G,G),K=n.mul(E,U),K=n.add(K,K),N=n.mul(m,K),O=n.mul(d,Y),O=n.add(N,O),N=n.sub(tt,O),O=n.add(tt,O),O=n.mul(N,O),N=n.mul(G,N),K=n.mul(d,K),Y=n.mul(m,Y),G=n.sub(q,Y),G=n.mul(m,G),G=n.add(G,K),K=n.add(q,q),q=n.add(K,q),q=n.add(q,Y),q=n.mul(q,G),O=n.add(O,q),Y=n.mul(R,U),Y=n.add(Y,Y),q=n.mul(Y,G),N=n.sub(N,q),K=n.mul(Y,tt),K=n.add(K,K),K=n.add(K,K),new p(N,O,K)}add(m){P(m);let{X:y,Y:d,Z:E}=this,{X:R,Y:U,Z:N}=m,O=n.ZERO,K=n.ZERO,q=n.ZERO,tt=i.a,Y=n.mul(i.b,Ln),G=n.mul(y,R),et=n.mul(d,U),lt=n.mul(E,N),Ht=n.add(y,d),rt=n.add(R,U);Ht=n.mul(Ht,rt),rt=n.add(G,et),Ht=n.sub(Ht,rt),rt=n.add(y,E);let mt=n.add(R,N);return rt=n.mul(rt,mt),mt=n.add(G,lt),rt=n.sub(rt,mt),mt=n.add(d,E),O=n.add(U,N),mt=n.mul(mt,O),O=n.add(et,lt),mt=n.sub(mt,O),q=n.mul(tt,rt),O=n.mul(Y,lt),q=n.add(O,q),O=n.sub(et,q),q=n.add(et,q),K=n.mul(O,q),et=n.add(G,G),et=n.add(et,G),lt=n.mul(tt,lt),rt=n.mul(Y,rt),et=n.add(et,lt),lt=n.sub(G,lt),lt=n.mul(tt,lt),rt=n.add(rt,lt),G=n.mul(et,rt),K=n.add(K,G),G=n.mul(mt,rt),O=n.mul(Ht,O),O=n.sub(O,G),G=n.mul(Ht,et),q=n.mul(mt,q),q=n.add(q,G),new p(O,K,q)}subtract(m){return this.add(m.negate())}is0(){return this.equals(p.ZERO)}multiply(m){let{endo:y}=t;if(!o.isValidNot0(m))throw new Error("invalid scalar: out of range");let d,E,R=U=>D.cached(this,U,N=>Ne(p,N));if(y){let{k1neg:U,k1:N,k2neg:O,k2:K}=k(m),{p:q,f:tt}=R(N),{p:Y,f:G}=R(K);E=tt.add(G),d=h(y.beta,q,Y,U,O)}else{let{p:U,f:N}=R(m);d=U,E=N}return Ne(p,[d,E])[0]}multiplyUnsafe(m){let{endo:y}=t,d=this;if(!o.isValid(m))throw new Error("invalid scalar: out of range");if(m===ue||d.is0())return p.ZERO;if(m===fr)return d;if(D.hasCache(this))return this.multiply(m);if(y){let{k1neg:E,k1:R,k2neg:U,k2:N}=k(m),{p1:O,p2:K}=Ma(p,d,R,N);return h(y.beta,O,K,E,U)}else return D.unsafe(d,m)}toAffine(m){return M(this,m)}isTorsionFree(){let{isTorsionFree:m}=t;return s===fr?!0:m?m(p,this):D.unsafe(this,c).is0()}clearCofactor(){let{clearCofactor:m}=t;return s===fr?this:m?m(p,this):this.multiplyUnsafe(s)}isSmallOrder(){return this.multiplyUnsafe(s).is0()}toBytes(m=!0){return ce(m,"isCompressed"),this.assertValidity(),v(p,this,m)}toHex(m=!0){return ie(this.toBytes(m))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let _=o.BITS,D=new or(p,t.endo?Math.ceil(_/2):_);return p.BASE.precompute(8),p}function pc(e){return Uint8Array.of(e?2:3)}function mc(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function Zd(e,t={}){let{Fn:r}=e,n=t.randomBytes||Je,o=Object.assign(mc(e.Fp,r),{seed:ui(r.ORDER)});function i(v){try{let b=r.fromBytes(v);return r.isValidNot0(b)}catch{return!1}}function s(v,b){let{publicKey:T,publicKeyUncompressed:C}=o;try{let w=v.length;return b===!0&&w!==T||b===!1&&w!==C?!1:!!e.fromBytes(v)}catch{return!1}}function c(v=n(o.seed)){return fi($(v,o.seed,"seed"),r.ORDER)}function a(v,b=!0){return e.BASE.multiply(r.fromBytes(v)).toBytes(b)}function l(v){let{secretKey:b,publicKey:T,publicKeyUncompressed:C}=o;if(!_e(v)||"_lengths"in r&&r._lengths||b===T)return;let w=$(v,void 0,"key").length;return w===T||w===C}function u(v,b,T=!0){if(l(v)===!0)throw new Error("first arg must be private key");if(l(b)===!1)throw new Error("second arg must be public key");let C=r.fromBytes(v);return e.fromBytes(b).multiply(C).toBytes(T)}let f={isValidSecretKey:i,isValidPublicKey:s,randomSecretKey:c},x=vn(c,a);return Object.freeze({getPublicKey:a,getSharedSecret:u,keygen:x,Point:e,utils:f,lengths:o})}function yc(e,t,r={}){yn(t),be(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),r=Object.assign({},r);let n=r.randomBytes||Je,o=r.hmac||((y,d)=>Zi(t,y,d)),{Fp:i,Fn:s}=e,{ORDER:c,BITS:a}=s,{keygen:l,getPublicKey:u,getSharedSecret:f,utils:x,lengths:v}=Zd(e,r),b={prehash:!0,lowS:typeof r.lowS=="boolean"?r.lowS:!0,format:"compact",extraEntropy:!1},T=c*dc<i.ORDER;function C(y){let d=c>>fr;return y>d}function w(y,d){if(!s.isValidNot0(d))throw new Error(`invalid signature ${y}: out of range 1..Point.Fn.ORDER`);return d}function I(){if(T)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function S(y,d){Yi(d);let E=v.signature,R=d==="compact"?E:d==="recovered"?E+1:void 0;return $(y,R)}class P{r;s;recovery;constructor(d,E,R){if(this.r=w("r",d),this.s=w("s",E),R!=null){if(I(),![0,1,2,3].includes(R))throw new Error("invalid recovery id");this.recovery=R}Object.freeze(this)}static fromBytes(d,E=b.format){S(d,E);let R;if(E==="der"){let{r:K,s:q}=Se.toSig($(d));return new P(K,q)}E==="recovered"&&(R=d[0],E="compact",d=d.subarray(1));let U=v.signature/2,N=d.subarray(0,U),O=d.subarray(U,U*2);return new P(s.fromBytes(N),s.fromBytes(O),R)}static fromHex(d,E){return this.fromBytes(se(d),E)}assertRecovery(){let{recovery:d}=this;if(d==null)throw new Error("invalid recovery id: must be present");return d}addRecoveryBit(d){return new P(this.r,this.s,d)}recoverPublicKey(d){let{r:E,s:R}=this,U=this.assertRecovery(),N=U===2||U===3?E+c:E;if(!i.isValid(N))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let O=i.toBytes(N),K=e.fromBytes(At(pc((U&1)===0),O)),q=s.inv(N),tt=M($(d,void 0,"msgHash")),Y=s.create(-tt*q),G=s.create(R*q),et=e.BASE.multiplyUnsafe(Y).add(K.multiplyUnsafe(G));if(et.is0())throw new Error("invalid recovery: point at infinify");return et.assertValidity(),et}hasHighS(){return C(this.s)}toBytes(d=b.format){if(Yi(d),d==="der")return se(Se.hexFromSig(this));let{r:E,s:R}=this,U=s.toBytes(E),N=s.toBytes(R);return d==="recovered"?(I(),At(Uint8Array.of(this.assertRecovery()),U,N)):At(U,N)}toHex(d){return ie(this.toBytes(d))}}let k=r.bits2int||function(d){if(d.length>8192)throw new Error("input is too large");let E=tr(d),R=d.length*8-a;return R>0?E>>BigInt(R):E},M=r.bits2int_modN||function(d){return s.create(k(d))},V=Pr(a);function h(y){return Ur("num < 2^"+a,y,ue,V),s.toBytes(y)}function p(y,d){return $(y,void 0,"message"),d?$(t(y),void 0,"prehashed message"):y}function _(y,d,E){let{lowS:R,prehash:U,extraEntropy:N}=ji(E,b);y=p(y,U);let O=M(y),K=s.fromBytes(d);if(!s.isValidNot0(K))throw new Error("invalid private key");let q=[h(K),h(O)];if(N!=null&&N!==!1){let et=N===!0?n(v.secretKey):N;q.push($(et,void 0,"extraEntropy"))}let tt=At(...q),Y=O;function G(et){let lt=k(et);if(!s.isValidNot0(lt))return;let Ht=s.inv(lt),rt=e.BASE.multiply(lt).toAffine(),mt=s.create(rt.x);if(mt===ue)return;let cn=s.create(Ht*s.create(Y+mt*K));if(cn===ue)return;let Ss=(rt.x===mt?0:2)|Number(rt.y&fr),vs=cn;return R&&C(cn)&&(vs=s.neg(cn),Ss^=1),new P(mt,vs,T?void 0:Ss)}return{seed:tt,k2sig:G}}function D(y,d,E={}){let{seed:R,k2sig:U}=_(y,d,E);return va(t.outputLen,s.BYTES,o)(R,U).toBytes(E.format)}function A(y,d,E,R={}){let{lowS:U,prehash:N,format:O}=ji(R,b);if(E=$(E,void 0,"publicKey"),d=p(d,N),!_e(y)){let K=y instanceof P?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+K)}S(y,O);try{let K=P.fromBytes(y,O),q=e.fromBytes(E);if(U&&K.hasHighS())return!1;let{r:tt,s:Y}=K,G=M(d),et=s.inv(Y),lt=s.create(G*et),Ht=s.create(tt*et),rt=e.BASE.multiplyUnsafe(lt).add(q.multiplyUnsafe(Ht));return rt.is0()?!1:s.create(rt.x)===tt}catch{return!1}}function m(y,d,E={}){let{prehash:R}=ji(E,b);return d=p(d,R),P.fromBytes(y,"recovered").recoverPublicKey(d).toBytes()}return Object.freeze({keygen:l,getPublicKey:u,getSharedSecret:f,utils:x,lengths:v,Point:e,sign:D,verify:A,recoverPublicKey:m,Signature:P,hash:t})}var Ji={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},jd={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var gc=BigInt(2);function Yd(e){let t=Ji.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),i=BigInt(22),s=BigInt(23),c=BigInt(44),a=BigInt(88),l=e*e*e%t,u=l*l*e%t,f=X(u,r,t)*u%t,x=X(f,r,t)*u%t,v=X(x,gc,t)*l%t,b=X(v,o,t)*v%t,T=X(b,i,t)*b%t,C=X(T,c,t)*T%t,w=X(C,a,t)*C%t,I=X(w,c,t)*T%t,S=X(I,r,t)*u%t,P=X(S,s,t)*b%t,k=X(P,n,t)*l%t,M=X(k,gc,t);if(!Xi.eql(Xi.sqr(M),e))throw new Error("Cannot find square root");return M}var Xi=rr(Ji.p,{sqrt:Yd}),Wd=hc(Ji,{Fp:Xi,endo:jd}),lr=yc(Wd,Qe);function xc(e,t,r,n){let o=Cr.digest(r instanceof Uint8Array?r:r.subarray());if(Tn(o))return o.then(({digest:i})=>(n?.signal?.throwIfAborted(),lr.verify(t,i,e,{prehash:!1,format:"der"}))).catch(i=>{throw i.name==="AbortError"?i:new kr(String(i))});try{return n?.signal?.throwIfAborted(),lr.verify(t,o.digest,e,{prehash:!1,format:"der"})}catch(i){throw new kr(String(i))}}var Un=class{type="secp256k1";raw;_key;constructor(t){this._key=wc(t),this.raw=bc(this._key)}toMultihash(){return Ot.digest(We(this))}toCID(){return j.createV1(114,this.toMultihash())}toString(){return W.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:J(this.raw,t.raw)}verify(t,r,n){return xc(this._key,r,t,n)}};function Qi(e){return new Un(e)}function bc(e){return lr.Point.fromBytes(e).toBytes()}function wc(e){try{return lr.Point.fromBytes(e),e}catch(t){throw new Fe(String(t))}}function Ec(e,t){let{Type:r,Data:n}=Xt.decode(e),o=n??new Uint8Array;switch(r){case it.RSA:return Hi(o,t);case it.Ed25519:return xi(o);case it.secp256k1:return Qi(o);case it.ECDSA:return Zo(o);default:throw new $e}}function Pn(e){let{Type:t,Data:r}=Xt.decode(e.digest),n=r??new Uint8Array;switch(t){case it.Ed25519:return xi(n);case it.secp256k1:return Qi(n);case it.ECDSA:return Zo(n);default:throw new $e}}function We(e){return Xt.encode({Type:it[e.type],Data:e.raw})}var Sc=Symbol.for("nodejs.util.inspect.custom"),Xd=114,Hr=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()})`}[Io]=!0;toString(){return this.string==null&&(this.string=W.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return j.createV1(Xd,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return J(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return J(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[Sc](){return`PeerId(${this.toString()})`}},Nn=class extends Hr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},On=class extends Hr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},kn=class extends Hr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},Jd=2336,zr=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=Ot.digest(H(this.url))}[Sc](){return`PeerId(${this.url})`}[Io]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return j.createV1(Jd,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=z(t)),t.toString()===this.toString())}};var Qd=114,vc=2336;function Ac(e,t){let r;if(e.charAt(0)==="1"||e.charAt(0)==="Q")r=Ie(W.decode(`z${e}`));else{if(e.startsWith("k51qzi5uqu5")||e.startsWith("kzwfwjn5ji4")||e.startsWith("k2k4r8")||e.startsWith("bafz"))return th(j.parse(e));if(t==null)throw new st('Please pass a multibase decoder for strings that do not start with "1" or "Q"');r=Ie(t.decode(e))}return Cc(r)}function Cc(e){if(rh(e))return new Nn({multihash:e});if(eh(e))try{let t=Pn(e);if(t.type==="Ed25519")return new On({multihash:e,publicKey:t});if(t.type==="secp256k1")return new kn({multihash:e,publicKey:t})}catch{let r=z(e.digest);return new zr(new URL(r))}throw new qe("Supplied PeerID Multihash is invalid")}function th(e){if(e?.multihash==null||e.version==null||e.version===1&&e.code!==Qd&&e.code!==vc)throw new dn("Supplied PeerID CID is invalid");if(e.code===vc){let t=z(e.multihash.digest);return new zr(new URL(t))}return Cc(e.multihash)}function eh(e){return e.code===Ot.code}function rh(e){return e.code===Cr.code}var ht=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},fe=class extends Error{static name="ValidationError";name="ValidationError"},Kn=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},Vn=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};var Mn=class{index=0;input="";new(t){return this.index=0,this.input=t,this}readAtomically(t){let r=this.index,n=t();return n===void 0&&(this.index=r),n}parseWith(t){let r=t();if(this.index===this.input.length)return r}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 r=this.readChar();if(r===t)return r})}readSeparator(t,r,n){return this.readAtomically(()=>{if(!(r>0&&this.readGivenChar(t)===void 0))return n()})}readNumber(t,r,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 x=Number.parseInt(f,t);if(!Number.isNaN(x))return x});if(u===void 0)break;if(i*=t,i+=u,i>l||(s+=1,r!==void 0&&s>r))return}if(s!==0)return!n&&a&&s>1?void 0:i})}readIPv4Addr(){return this.readAtomically(()=>{let t=new Uint8Array(4);for(let r=0;r<t.length;r++){let n=this.readSeparator(".",r,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;t[r]=n}return t})}readIPv6Addr(){let t=r=>{for(let n=0;n<r.length/2;n++){let o=n*2;if(n<r.length-3){let s=this.readSeparator(":",n,()=>this.readIPv4Addr());if(s!==void 0)return r[o]=s[0],r[o+1]=s[1],r[o+2]=s[2],r[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];r[o]=i>>8,r[o+1]=i&255}return[r.length,!1]};return this.readAtomically(()=>{let r=new Uint8Array(16),[n,o]=t(r);if(n===16)return r;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 r.set(i.subarray(0,c),16-c),r})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var nh=45,oh=15,Fn=new Mn;function Tc(e){if(!(e.length>oh))return Fn.new(e).parseWith(()=>Fn.readIPv4Addr())}function Ic(e){if(e.includes("%")&&(e=e.split("%")[0]),!(e.length>nh))return Fn.new(e).parseWith(()=>Fn.readIPv6Addr())}function qn(e){return!!Tc(e)}function Bc(e){return!!Ic(e)}function es(e){return t=>z(t,e)}function rs(e){return t=>H(t,e)}function dr(e){return new DataView(e.buffer).getUint16(e.byteOffset).toString()}function Ke(e){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,typeof e=="string"?parseInt(e):e),new Uint8Array(t)}function _c(e){let t=e.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 r=H(t[0],"base32"),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=Ke(n);return Lt([r,o],r.length+o.length)}function Dc(e){let t=e.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 r=zt.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=Ke(n);return Lt([r,o],r.length+o.length)}function ns(e){let t=e.subarray(0,e.length-2),r=e.subarray(e.length-2),n=z(t,"base32"),o=dr(r);return`${n}:${o}`}var os=function(e){e=e.toString().trim();let t=new Uint8Array(4);return e.split(/\./g).forEach((r,n)=>{let o=parseInt(r,10);if(isNaN(o)||o<0||o>255)throw new ht("Invalid byte value in IP address");t[n]=o}),t},Rc=function(e){let t=0;e=e.toString().trim();let r=e.split(":",8),n;for(n=0;n<r.length;n++){let i=qn(r[n]),s;i&&(s=os(r[n]),r[n]=z(s.subarray(0,2),"base16")),s!=null&&++n<8&&r.splice(n,0,z(s.subarray(2,4),"base16"))}if(r[0]==="")for(;r.length<8;)r.unshift("0");else if(r[r.length-1]==="")for(;r.length<8;)r.push("0");else if(r.length<8){for(n=0;n<r.length&&r[n]!=="";n++);let i=[n,1];for(n=9-r.length;n>0;n--)i.push("0");r.splice.apply(r,i)}let o=new Uint8Array(t+16);for(n=0;n<r.length;n++){r[n]===""&&(r[n]="0");let i=parseInt(r[n],16);if(isNaN(i)||i<0||i>65535)throw new ht("Invalid byte value in IP address");o[t++]=i>>8&255,o[t++]=i&255}return o},Lc=function(e){if(e.byteLength!==4)throw new ht("IPv4 address was incorrect length");let t=[];for(let r=0;r<e.byteLength;r++)t.push(e[r]);return t.join(".")},Uc=function(e){if(e.byteLength!==16)throw new ht("IPv6 address was incorrect length");let t=[];for(let n=0;n<e.byteLength;n+=2){let o=e[n],i=e[n+1],s=`${o.toString(16).padStart(2,"0")}${i.toString(16).padStart(2,"0")}`;t.push(s)}let r=t.join(":");try{let n=new URL(`http://[${r}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new ht(`Invalid IPv6 address "${r}"`)}};function Pc(e){try{let t=new URL(`http://[${e}]`);return t.hostname.substring(1,t.hostname.length-1)}catch{throw new ht(`Invalid IPv6 address "${e}"`)}}var ts=Object.values(Tr).map(e=>e.decoder),ih=(function(){let e=ts[0].or(ts[1]);return ts.slice(2).forEach(t=>e=e.or(t)),e})();function Nc(e){return ih.decode(e)}function Oc(e){return t=>e.encoder.encode(t)}function sh(e){if(parseInt(e).toString()!==e)throw new fe("Value must be an integer")}function ah(e){if(e<0)throw new fe("Value must be a positive integer, or zero")}function ch(e){return t=>{if(t>e)throw new fe(`Value must be smaller than or equal to ${e}`)}}function uh(...e){return t=>{for(let r of e)r(t)}}var Gr=uh(sh,ah,ch(65535));var ut=-1,is=class{protocolsByCode=new Map;protocolsByName=new Map;getProtocol(t){let r;if(typeof t=="string"?r=this.protocolsByName.get(t):r=this.protocolsByCode.get(t),r==null)throw new Vn(`Protocol ${t} was unknown`);return r}addProtocol(t){this.protocolsByCode.set(t.code,t),this.protocolsByName.set(t.name,t),t.aliases?.forEach(r=>{this.protocolsByName.set(r,t)})}removeProtocol(t){let r=this.protocolsByCode.get(t);r!=null&&(this.protocolsByCode.delete(r.code),this.protocolsByName.delete(r.name),r.aliases?.forEach(n=>{this.protocolsByName.delete(n)}))}},le=new is,Wh=[{code:4,name:"ip4",size:32,valueToBytes:os,bytesToValue:Lc,validate:e=>{if(!qn(e))throw new fe(`Invalid IPv4 address "${e}"`)}},{code:6,name:"tcp",size:16,valueToBytes:Ke,bytesToValue:dr,validate:Gr},{code:273,name:"udp",size:16,valueToBytes:Ke,bytesToValue:dr,validate:Gr},{code:33,name:"dccp",size:16,valueToBytes:Ke,bytesToValue:dr,validate:Gr},{code:41,name:"ip6",size:128,valueToBytes:Rc,bytesToValue:Uc,stringToValue:Pc,validate:e=>{if(!Bc(e))throw new fe(`Invalid IPv6 address "${e}"`)}},{code:42,name:"ip6zone",size:ut},{code:43,name:"ipcidr",size:8,bytesToValue:es("base10"),valueToBytes:rs("base10")},{code:53,name:"dns",size:ut},{code:54,name:"dns4",size:ut},{code:55,name:"dns6",size:ut},{code:56,name:"dnsaddr",size:ut},{code:132,name:"sctp",size:16,valueToBytes:Ke,bytesToValue:dr,validate:Gr},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:ut,stringToValue:e=>decodeURIComponent(e),valueToString:e=>encodeURIComponent(e)},{code:421,name:"p2p",aliases:["ipfs"],size:ut,bytesToValue:es("base58btc"),valueToBytes:e=>e.startsWith("Q")||e.startsWith("1")?rs("base58btc")(e):j.parse(e).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:ns,valueToBytes:_c},{code:445,name:"onion3",size:296,bytesToValue:ns,valueToBytes:Dc},{code:446,name:"garlic64",size:ut},{code:447,name:"garlic32",size:ut},{code:448,name:"tls"},{code:449,name:"sni",size:ut},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:ut,bytesToValue:Oc(Ao),valueToBytes:Nc},{code:480,name:"http"},{code:481,name:"http-path",size:ut,stringToValue:e=>`/${decodeURIComponent(e)}`,valueToString:e=>encodeURIComponent(e.substring(1))},{code:443,name:"https"},{code:477,name:"ws"},{code:478,name:"wss"},{code:479,name:"p2p-websocket-star"},{code:277,name:"p2p-stardust"},{code:275,name:"p2p-webrtc-star"},{code:276,name:"p2p-webrtc-direct"},{code:280,name:"webrtc-direct"},{code:281,name:"webrtc"},{code:290,name:"p2p-circuit"},{code:777,name:"memory",size:ut}];Wh.forEach(e=>{le.addProtocol(e)});function kc(e){let t=[],r=0;for(;r<e.length;){let n=Ai(e,r),o=le.getProtocol(n),i=Wt(n),s=Xh(o,e,r+i),c=0;s>0&&o.size===ut&&(c=Wt(s));let a=i+c+s,l={code:n,name:o.name,bytes:e.subarray(r,r+a)};if(s>0){let u=r+i+c,f=e.subarray(u,u+s);l.value=o.bytesToValue?.(f)??z(f)}t.push(l),r+=a}return t}function Kc(e){let t=0,r=[];for(let n of e){if(n.bytes==null){let o=le.getProtocol(n.code),i=Wt(n.code),s,c=0,a=0;n.value!=null&&(s=o.valueToBytes?.(n.value)??H(n.value),c=s.byteLength,o.size===ut&&(a=Wt(c)));let l=new Uint8Array(i+a+c),u=0;Kr(n.code,l,u),u+=i,s!=null&&(o.size===ut&&(Kr(c,l,u),u+=a),l.set(s,u)),n.bytes=l}r.push(n.bytes),t+=n.bytes.byteLength}return Lt(r,t)}function Vc(e){if(e.charAt(0)!=="/")throw new ht('String multiaddr must start with "/"');let t=[],r="protocol",n="",o="";for(let i=1;i<e.length;i++){let s=e.charAt(i);s!=="/"&&(r==="protocol"?o+=e.charAt(i):n+=e.charAt(i));let c=i===e.length-1;if(s==="/"||c){let a=le.getProtocol(o);if(r==="protocol"){if(a.size==null||a.size===0){t.push({code:a.code,name:a.name}),n="",o="",r="protocol";continue}else if(c)throw new ht(`Component ${o} was missing value`);r="value"}else if(r==="value"){let l={code:a.code,name:a.name};if(a.size!=null&&a.size!==0){if(n==="")throw new ht(`Component ${o} was missing value`);l.value=a.stringToValue?.(n)??n}t.push(l),n="",o="",r="protocol"}}}if(o!==""&&n!=="")throw new ht("Incomplete multiaddr");return t}function Mc(e){return`/${e.flatMap(t=>{if(t.value==null)return t.name;let r=le.getProtocol(t.code);if(r==null)throw new ht(`Unknown protocol code ${t.code}`);return[t.name,r.valueToString?.(t.value)??t.value]}).join("/")}`}function Xh(e,t,r){return e.size==null||e.size===0?0:e.size>0?e.size/8:Ai(t,r)}var Jh=Symbol.for("nodejs.util.inspect.custom"),ss=Symbol.for("@multiformats/multiaddr");function Qh(e){if(e==null&&(e="/"),Fc(e))return e.getComponents();if(e instanceof Uint8Array)return kc(e);if(typeof e=="string")return e=e.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),e===""&&(e="/"),Vc(e);if(Array.isArray(e))return e;throw new ht("Must be a string, Uint8Array, Component[], or another Multiaddr")}var $n=class e{[ss]=!0;#t;#n;#r;constructor(t="/",r={}){this.#t=Qh(t),r.validate!==!1&&tp(this)}get bytes(){return this.#r==null&&(this.#r=Kc(this.#t)),this.#r}toString(){return this.#n==null&&(this.#n=Mc(this.#t)),this.#n}toJSON(){return this.toString()}getComponents(){return[...this.#t.map(t=>({...t}))]}encapsulate(t){let r=new e(t);return new e([...this.#t,...r.getComponents()],{validate:!1})}decapsulate(t){let r=t.toString(),n=this.toString(),o=n.lastIndexOf(r);if(o<0)throw new Kn(`Address ${this.toString()} does not contain subaddress: ${r}`);return new e(n.slice(0,o),{validate:!1})}decapsulateCode(t){let r;for(let n=this.#t.length-1;n>-1;n--)if(this.#t[n].code===t){r=n;break}return new e(this.#t.slice(0,r),{validate:!1})}equals(t){return J(this.bytes,t.bytes)}[Jh](){return`Multiaddr(${this.toString()})`}};function tp(e){e.getComponents().forEach(t=>{let r=le.getProtocol(t.code);t.value!=null&&r.validate?.(t.value)})}function Fc(e){return!!e?.[ss]}function qc(e){return new $n(e)}function Zr(e){let t=new globalThis.AbortController;function r(){t.abort();for(let i of e)i?.removeEventListener!=null&&i.removeEventListener("abort",r)}for(let i of e){if(i?.aborted===!0){r();break}i?.addEventListener!=null&&i.addEventListener("abort",r)}function n(){for(let i of e)i?.removeEventListener!=null&&i.removeEventListener("abort",r)}let o=t.signal;return o.clear=n,o}async function*Hn(e,t={}){let r=e.getReader();try{for(;;){let n=await r.read();if(n.done)return;yield n.value}}finally{t.preventCancel!==!0&&await r.cancel(),r.releaseLock()}}var kp=yo(cs(),1);var Vt=class extends Error{static name="SignatureVerificationError";constructor(t="Record signature verification failed"){super(t),this.name="SignatureVerificationError"}},zn=class extends Error{static name="RecordExpiredError";constructor(t="Record has expired"){super(t),this.name="RecordExpiredError"}},hr=class extends Error{static name="UnsupportedValidityError";constructor(t="The validity type is unsupported"){super(t),this.name="UnsupportedValidityError"}},Gn=class extends Error{static name="RecordTooLargeError";constructor(t="The record is too large"){super(t),this.name="RecordTooLargeError"}},Zn=class extends Error{static name="InvalidValueError";constructor(t="Value must be a valid content path starting with /"){super(t),this.name="InvalidValueError"}},jn=class extends Error{static name="InvalidRecordDataError";constructor(t="Invalid record data"){super(t),this.name="InvalidRecordDataError"}},jr=class extends Error{static name="InvalidEmbeddedPublicKeyError";constructor(t="Invalid embedded public key"){super(t),this.name="InvalidEmbeddedPublicKeyError"}};var Mt;(function(e){let t;(function(o){o.EOL="EOL"})(t=e.ValidityType||(e.ValidityType={}));let r;(function(o){o[o.EOL=0]="EOL"})(r||(r={})),(function(o){o.codec=()=>Fr(r)})(t=e.ValidityType||(e.ValidityType={}));let n;e.codec=()=>(n==null&&(n=cr((o,i,s={})=>{s.lengthDelimited!==!1&&i.fork(),o.value!=null&&(i.uint32(10),i.bytes(o.value)),o.signatureV1!=null&&(i.uint32(18),i.bytes(o.signatureV1)),o.validityType!=null&&(i.uint32(24),e.ValidityType.codec().encode(o.validityType,i)),o.validity!=null&&(i.uint32(34),i.bytes(o.validity)),o.sequence!=null&&(i.uint32(40),i.uint64(o.sequence)),o.ttl!=null&&(i.uint32(48),i.uint64(o.ttl)),o.pubKey!=null&&(i.uint32(58),i.bytes(o.pubKey)),o.signatureV2!=null&&(i.uint32(66),i.bytes(o.signatureV2)),o.data!=null&&(i.uint32(74),i.bytes(o.data)),s.lengthDelimited!==!1&&i.ldelim()},(o,i,s={})=>{let c={},a=i==null?o.len:o.pos+i;for(;o.pos<a;){let l=o.uint32();switch(l>>>3){case 1:{c.value=o.bytes();break}case 2:{c.signatureV1=o.bytes();break}case 3:{c.validityType=e.ValidityType.codec().decode(o);break}case 4:{c.validity=o.bytes();break}case 5:{c.sequence=o.uint64();break}case 6:{c.ttl=o.uint64();break}case 7:{c.pubKey=o.bytes();break}case 8:{c.signatureV2=o.bytes();break}case 9:{c.data=o.bytes();break}default:{o.skipType(l&7);break}}}return c})),n),e.encode=o=>sr(o,e.codec()),e.decode=(o,i)=>ir(o,e.codec(),i)})(Mt||(Mt={}));var ep=["string","number","bigint","symbol"],rp=["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 $c(e){if(e===null)return"null";if(e===void 0)return"undefined";if(e===!0||e===!1)return"boolean";let t=typeof e;if(ep.includes(t))return t;if(t==="function")return"Function";if(Array.isArray(e))return"Array";if(np(e))return"Buffer";let r=op(e);return r||"Object"}function np(e){return e&&e.constructor&&e.constructor.isBuffer&&e.constructor.isBuffer.call(null,e)}function op(e){let t=Object.prototype.toString.call(e).slice(8,-1);if(rp.includes(t))return t}var g=class{constructor(t,r,n){this.major=t,this.majorEncoded=t<<5,this.name=r,this.terminal=n}toString(){return`Type[${this.major}].${this.name}`}compare(t){return this.major<t.major?-1:this.major>t.major?1:0}};g.uint=new g(0,"uint",!0);g.negint=new g(1,"negint",!0);g.bytes=new g(2,"bytes",!0);g.string=new g(3,"string",!0);g.array=new g(4,"array",!1);g.map=new g(5,"map",!1);g.tag=new g(6,"tag",!1);g.float=new g(7,"float",!0);g.false=new g(7,"false",!0);g.true=new g(7,"true",!0);g.null=new g(7,"null",!0);g.undefined=new g(7,"undefined",!0);g.break=new g(7,"break",!0);var L=class{constructor(t,r,n){this.type=t,this.value=r,this.encodedLength=n,this.encodedBytes=void 0,this.byteValue=void 0}toString(){return`Token[${this.type}].${this.value}`}};var pr=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",ip=new TextDecoder,sp=new TextEncoder;function Yn(e){return pr&&globalThis.Buffer.isBuffer(e)}function us(e){return e instanceof Uint8Array?Yn(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):e:Uint8Array.from(e)}var Zc=pr?(e,t,r)=>r-t>64?globalThis.Buffer.from(e.subarray(t,r)).toString("utf8"):zc(e,t,r):(e,t,r)=>r-t>64?ip.decode(e.subarray(t,r)):zc(e,t,r),jc=pr?e=>e.length>64?globalThis.Buffer.from(e):Hc(e):e=>e.length>64?sp.encode(e):Hc(e),Jt=e=>Uint8Array.from(e),mr=pr?(e,t,r)=>Yn(e)?new Uint8Array(e.subarray(t,r)):e.slice(t,r):(e,t,r)=>e.slice(t,r),Yc=pr?(e,t)=>(e=e.map(r=>r instanceof Uint8Array?r:globalThis.Buffer.from(r)),us(globalThis.Buffer.concat(e,t))):(e,t)=>{let r=new Uint8Array(t),n=0;for(let o of e)n+o.length>r.length&&(o=o.subarray(0,r.length-n)),r.set(o,n),n+=o.length;return r},Wc=pr?e=>globalThis.Buffer.allocUnsafe(e):e=>new Uint8Array(e);function Wn(e,t){if(Yn(e)&&Yn(t))return e.compare(t);for(let r=0;r<e.length;r++)if(e[r]!==t[r])return e[r]<t[r]?-1:1;return 0}function Hc(e){let t=[],r=0;for(let n=0;n<e.length;n++){let o=e.charCodeAt(n);o<128?t[r++]=o:o<2048?(t[r++]=o>>6|192,t[r++]=o&63|128):(o&64512)===55296&&n+1<e.length&&(e.charCodeAt(n+1)&64512)===56320?(o=65536+((o&1023)<<10)+(e.charCodeAt(++n)&1023),t[r++]=o>>18|240,t[r++]=o>>12&63|128,t[r++]=o>>6&63|128,t[r++]=o&63|128):(t[r++]=o>>12|224,t[r++]=o>>6&63|128,t[r++]=o&63|128)}return t}function zc(e,t,r){let n=[];for(;t<r;){let o=e[t],i=null,s=o>239?4:o>223?3:o>191?2:1;if(t+s<=r){let c,a,l,u;switch(s){case 1:o<128&&(i=o);break;case 2:c=e[t+1],(c&192)===128&&(u=(o&31)<<6|c&63,u>127&&(i=u));break;case 3:c=e[t+1],a=e[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=e[t+1],a=e[t+2],l=e[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 ap(n)}var Gc=4096;function ap(e){let t=e.length;if(t<=Gc)return String.fromCharCode.apply(String,e);let r="",n=0;for(;n<t;)r+=String.fromCharCode.apply(String,e.slice(n,n+=Gc));return r}var cp=256,Yr=class{constructor(t=cp){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 r=this.chunks[this.chunks.length-1];if(this.cursor+t.length<=this.maxCursor+1){let o=r.length-(this.maxCursor-this.cursor)-1;r.set(t,o)}else{if(r){let o=r.length-(this.maxCursor-this.cursor)-1;o<r.length&&(this.chunks[this.chunks.length-1]=r.subarray(0,o),this.maxCursor=this.cursor-1)}t.length<64&&t.length<this.chunkSize?(r=Wc(this.chunkSize),this.chunks.push(r),this.maxCursor+=r.length,this._initReuseChunk===null&&(this._initReuseChunk=r),r.set(t,0)):(this.chunks.push(t),this.maxCursor+=t.length)}this.cursor+=t.length}toBytes(t=!1){let r;if(this.chunks.length===1){let n=this.chunks[0];t&&this.cursor>n.length/2?(r=this.cursor===n.length?n:n.subarray(0,this.cursor),this._initReuseChunk=null,this.chunks=[]):r=mr(n,0,this.cursor)}else r=Yc(this.chunks,this.cursor);return t&&this.reset(),r}};var F="CBOR decode error:",fs="CBOR encode error:",Wr=[];Wr[23]=1;Wr[24]=2;Wr[25]=3;Wr[26]=5;Wr[27]=9;function de(e,t,r){if(e.length-t<r)throw new Error(`${F} not enough data for type`)}var ft=[24,256,65536,4294967296,BigInt("18446744073709551616")];function Bt(e,t,r){de(e,t,1);let n=e[t];if(r.strict===!0&&n<ft[0])throw new Error(`${F} integer encoded in more bytes than necessary (strict decode)`);return n}function _t(e,t,r){de(e,t,2);let n=e[t]<<8|e[t+1];if(r.strict===!0&&n<ft[1])throw new Error(`${F} integer encoded in more bytes than necessary (strict decode)`);return n}function Dt(e,t,r){de(e,t,4);let n=e[t]*16777216+(e[t+1]<<16)+(e[t+2]<<8)+e[t+3];if(r.strict===!0&&n<ft[2])throw new Error(`${F} integer encoded in more bytes than necessary (strict decode)`);return n}function Rt(e,t,r){de(e,t,8);let n=e[t]*16777216+(e[t+1]<<16)+(e[t+2]<<8)+e[t+3],o=e[t+4]*16777216+(e[t+5]<<16)+(e[t+6]<<8)+e[t+7],i=(BigInt(n)<<BigInt(32))+BigInt(o);if(r.strict===!0&&i<ft[3])throw new Error(`${F} integer encoded in more bytes than necessary (strict decode)`);if(i<=Number.MAX_SAFE_INTEGER)return Number(i);if(r.allowBigInt===!0)return i;throw new Error(`${F} integers outside of the safe integer range are not supported`)}function Xc(e,t,r,n){return new L(g.uint,Bt(e,t+1,n),2)}function Jc(e,t,r,n){return new L(g.uint,_t(e,t+1,n),3)}function Qc(e,t,r,n){return new L(g.uint,Dt(e,t+1,n),5)}function tu(e,t,r,n){return new L(g.uint,Rt(e,t+1,n),9)}function Pt(e,t){return pt(e,0,t.value)}function pt(e,t,r){if(r<ft[0]){let n=Number(r);e.push([t|n])}else if(r<ft[1]){let n=Number(r);e.push([t|24,n])}else if(r<ft[2]){let n=Number(r);e.push([t|25,n>>>8,n&255])}else if(r<ft[3]){let n=Number(r);e.push([t|26,n>>>24&255,n>>>16&255,n>>>8&255,n&255])}else{let n=BigInt(r);if(n<ft[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,e.push(o)}else throw new Error(`${F} encountered BigInt larger than allowable range`)}}Pt.encodedSize=function(t){return pt.encodedSize(t.value)};pt.encodedSize=function(t){return t<ft[0]?1:t<ft[1]?2:t<ft[2]?3:t<ft[3]?5:9};Pt.compareTokens=function(t,r){return t.value<r.value?-1:t.value>r.value?1:0};function eu(e,t,r,n){return new L(g.negint,-1-Bt(e,t+1,n),2)}function ru(e,t,r,n){return new L(g.negint,-1-_t(e,t+1,n),3)}function nu(e,t,r,n){return new L(g.negint,-1-Dt(e,t+1,n),5)}var ls=BigInt(-1),ou=BigInt(1);function iu(e,t,r,n){let o=Rt(e,t+1,n);if(typeof o!="bigint"){let i=-1-o;if(i>=Number.MIN_SAFE_INTEGER)return new L(g.negint,i,9)}if(n.allowBigInt!==!0)throw new Error(`${F} integers outside of the safe integer range are not supported`);return new L(g.negint,ls-BigInt(o),9)}function Xn(e,t){let r=t.value,n=typeof r=="bigint"?r*ls-ou:r*-1-1;pt(e,t.type.majorEncoded,n)}Xn.encodedSize=function(t){let r=t.value,n=typeof r=="bigint"?r*ls-ou:r*-1-1;return n<ft[0]?1:n<ft[1]?2:n<ft[2]?3:n<ft[3]?5:9};Xn.compareTokens=function(t,r){return t.value<r.value?1:t.value>r.value?-1:0};function Xr(e,t,r,n){de(e,t,r+n);let o=mr(e,t+r,t+r+n);return new L(g.bytes,o,r+n)}function su(e,t,r,n){return Xr(e,t,1,r)}function au(e,t,r,n){return Xr(e,t,2,Bt(e,t+1,n))}function cu(e,t,r,n){return Xr(e,t,3,_t(e,t+1,n))}function uu(e,t,r,n){return Xr(e,t,5,Dt(e,t+1,n))}function fu(e,t,r,n){let o=Rt(e,t+1,n);if(typeof o=="bigint")throw new Error(`${F} 64-bit integer bytes lengths not supported`);return Xr(e,t,9,o)}function Jn(e){return e.encodedBytes===void 0&&(e.encodedBytes=e.type===g.string?jc(e.value):e.value),e.encodedBytes}function yr(e,t){let r=Jn(t);pt(e,t.type.majorEncoded,r.length),e.push(r)}yr.encodedSize=function(t){let r=Jn(t);return pt.encodedSize(r.length)+r.length};yr.compareTokens=function(t,r){return fp(Jn(t),Jn(r))};function fp(e,t){return e.length<t.length?-1:e.length>t.length?1:Wn(e,t)}function Jr(e,t,r,n,o){let i=r+n;de(e,t,i);let s=new L(g.string,Zc(e,t+r,t+i),i);return o.retainStringBytes===!0&&(s.byteValue=mr(e,t+r,t+i)),s}function lu(e,t,r,n){return Jr(e,t,1,r,n)}function du(e,t,r,n){return Jr(e,t,2,Bt(e,t+1,n),n)}function hu(e,t,r,n){return Jr(e,t,3,_t(e,t+1,n),n)}function pu(e,t,r,n){return Jr(e,t,5,Dt(e,t+1,n),n)}function mu(e,t,r,n){let o=Rt(e,t+1,n);if(typeof o=="bigint")throw new Error(`${F} 64-bit integer string lengths not supported`);return Jr(e,t,9,o,n)}var yu=yr;function gr(e,t,r,n){return new L(g.array,n,r)}function gu(e,t,r,n){return gr(e,t,1,r)}function xu(e,t,r,n){return gr(e,t,2,Bt(e,t+1,n))}function bu(e,t,r,n){return gr(e,t,3,_t(e,t+1,n))}function wu(e,t,r,n){return gr(e,t,5,Dt(e,t+1,n))}function Eu(e,t,r,n){let o=Rt(e,t+1,n);if(typeof o=="bigint")throw new Error(`${F} 64-bit integer array lengths not supported`);return gr(e,t,9,o)}function Su(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${F} indefinite length items not allowed`);return gr(e,t,1,1/0)}function Qn(e,t){pt(e,g.array.majorEncoded,t.value)}Qn.compareTokens=Pt.compareTokens;Qn.encodedSize=function(t){return pt.encodedSize(t.value)};function xr(e,t,r,n){return new L(g.map,n,r)}function vu(e,t,r,n){return xr(e,t,1,r)}function Au(e,t,r,n){return xr(e,t,2,Bt(e,t+1,n))}function Cu(e,t,r,n){return xr(e,t,3,_t(e,t+1,n))}function Tu(e,t,r,n){return xr(e,t,5,Dt(e,t+1,n))}function Iu(e,t,r,n){let o=Rt(e,t+1,n);if(typeof o=="bigint")throw new Error(`${F} 64-bit integer map lengths not supported`);return xr(e,t,9,o)}function Bu(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${F} indefinite length items not allowed`);return xr(e,t,1,1/0)}function to(e,t){pt(e,g.map.majorEncoded,t.value)}to.compareTokens=Pt.compareTokens;to.encodedSize=function(t){return pt.encodedSize(t.value)};function _u(e,t,r,n){return new L(g.tag,r,1)}function Du(e,t,r,n){return new L(g.tag,Bt(e,t+1,n),2)}function Ru(e,t,r,n){return new L(g.tag,_t(e,t+1,n),3)}function Lu(e,t,r,n){return new L(g.tag,Dt(e,t+1,n),5)}function Uu(e,t,r,n){return new L(g.tag,Rt(e,t+1,n),9)}function eo(e,t){pt(e,g.tag.majorEncoded,t.value)}eo.compareTokens=Pt.compareTokens;eo.encodedSize=function(t){return pt.encodedSize(t.value)};var yp=20,gp=21,xp=22,bp=23;function Pu(e,t,r,n){if(n.allowUndefined===!1)throw new Error(`${F} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new L(g.null,null,1):new L(g.undefined,void 0,1)}function Nu(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${F} indefinite length items not allowed`);return new L(g.break,void 0,1)}function ds(e,t,r){if(r){if(r.allowNaN===!1&&Number.isNaN(e))throw new Error(`${F} NaN values are not supported`);if(r.allowInfinity===!1&&(e===1/0||e===-1/0))throw new Error(`${F} Infinity values are not supported`)}return new L(g.float,e,t)}function Ou(e,t,r,n){return ds(hs(e,t+1),3,n)}function ku(e,t,r,n){return ds(ps(e,t+1),5,n)}function Ku(e,t,r,n){return ds(qu(e,t+1),9,n)}function ro(e,t,r){let n=t.value;if(n===!1)e.push([g.float.majorEncoded|yp]);else if(n===!0)e.push([g.float.majorEncoded|gp]);else if(n===null)e.push([g.float.majorEncoded|xp]);else if(n===void 0)e.push([g.float.majorEncoded|bp]);else{let o,i=!1;(!r||r.float64!==!0)&&(Mu(n),o=hs(Ft,1),n===o||Number.isNaN(n)?(Ft[0]=249,e.push(Ft.slice(0,3)),i=!0):(Fu(n),o=ps(Ft,1),n===o&&(Ft[0]=250,e.push(Ft.slice(0,5)),i=!0))),i||(wp(n),o=qu(Ft,1),Ft[0]=251,e.push(Ft.slice(0,9)))}}ro.encodedSize=function(t,r){let n=t.value;if(n===!1||n===!0||n===null||n===void 0)return 1;if(!r||r.float64!==!0){Mu(n);let o=hs(Ft,1);if(n===o||Number.isNaN(n))return 3;if(Fu(n),o=ps(Ft,1),n===o)return 5}return 9};var Vu=new ArrayBuffer(9),Nt=new DataView(Vu,1),Ft=new Uint8Array(Vu,0);function Mu(e){if(e===1/0)Nt.setUint16(0,31744,!1);else if(e===-1/0)Nt.setUint16(0,64512,!1);else if(Number.isNaN(e))Nt.setUint16(0,32256,!1);else{Nt.setFloat32(0,e);let t=Nt.getUint32(0),r=(t&2139095040)>>23,n=t&8388607;if(r===255)Nt.setUint16(0,31744,!1);else if(r===0)Nt.setUint16(0,(e&2147483648)>>16|n>>13,!1);else{let o=r-127;o<-24?Nt.setUint16(0,0):o<-14?Nt.setUint16(0,(t&2147483648)>>16|1<<24+o,!1):Nt.setUint16(0,(t&2147483648)>>16|o+15<<10|n>>13,!1)}}}function hs(e,t){if(e.length-t<2)throw new Error(`${F} not enough data for float16`);let r=(e[t]<<8)+e[t+1];if(r===31744)return 1/0;if(r===64512)return-1/0;if(r===32256)return NaN;let n=r>>10&31,o=r&1023,i;return n===0?i=o*2**-24:n!==31?i=(o+1024)*2**(n-25):i=o===0?1/0:NaN,r&32768?-i:i}function Fu(e){Nt.setFloat32(0,e,!1)}function ps(e,t){if(e.length-t<4)throw new Error(`${F} not enough data for float32`);let r=(e.byteOffset||0)+t;return new DataView(e.buffer,r,4).getFloat32(0,!1)}function wp(e){Nt.setFloat64(0,e,!1)}function qu(e,t){if(e.length-t<8)throw new Error(`${F} not enough data for float64`);let r=(e.byteOffset||0)+t;return new DataView(e.buffer,r,8).getFloat64(0,!1)}ro.compareTokens=Pt.compareTokens;function Z(e,t,r){throw new Error(`${F} encountered invalid minor (${r}) for major ${e[t]>>>5}`)}function no(e){return()=>{throw new Error(`${F} ${e}`)}}var B=[];for(let e=0;e<=23;e++)B[e]=Z;B[24]=Xc;B[25]=Jc;B[26]=Qc;B[27]=tu;B[28]=Z;B[29]=Z;B[30]=Z;B[31]=Z;for(let e=32;e<=55;e++)B[e]=Z;B[56]=eu;B[57]=ru;B[58]=nu;B[59]=iu;B[60]=Z;B[61]=Z;B[62]=Z;B[63]=Z;for(let e=64;e<=87;e++)B[e]=su;B[88]=au;B[89]=cu;B[90]=uu;B[91]=fu;B[92]=Z;B[93]=Z;B[94]=Z;B[95]=no("indefinite length bytes/strings are not supported");for(let e=96;e<=119;e++)B[e]=lu;B[120]=du;B[121]=hu;B[122]=pu;B[123]=mu;B[124]=Z;B[125]=Z;B[126]=Z;B[127]=no("indefinite length bytes/strings are not supported");for(let e=128;e<=151;e++)B[e]=gu;B[152]=xu;B[153]=bu;B[154]=wu;B[155]=Eu;B[156]=Z;B[157]=Z;B[158]=Z;B[159]=Su;for(let e=160;e<=183;e++)B[e]=vu;B[184]=Au;B[185]=Cu;B[186]=Tu;B[187]=Iu;B[188]=Z;B[189]=Z;B[190]=Z;B[191]=Bu;for(let e=192;e<=215;e++)B[e]=_u;B[216]=Du;B[217]=Ru;B[218]=Lu;B[219]=Uu;B[220]=Z;B[221]=Z;B[222]=Z;B[223]=Z;for(let e=224;e<=243;e++)B[e]=no("simple values are not supported");B[244]=Z;B[245]=Z;B[246]=Z;B[247]=Pu;B[248]=no("simple values are not supported");B[249]=Ou;B[250]=ku;B[251]=Ku;B[252]=Z;B[253]=Z;B[254]=Z;B[255]=Nu;var qt=[];for(let e=0;e<24;e++)qt[e]=new L(g.uint,e,1);for(let e=-1;e>=-24;e--)qt[31-e]=new L(g.negint,e,1);qt[64]=new L(g.bytes,new Uint8Array(0),1);qt[96]=new L(g.string,"",1);qt[128]=new L(g.array,0,1);qt[160]=new L(g.map,0,1);qt[244]=new L(g.false,!1,1);qt[245]=new L(g.true,!0,1);qt[246]=new L(g.null,null,1);function $u(e){switch(e.type){case g.false:return Jt([244]);case g.true:return Jt([245]);case g.null:return Jt([246]);case g.bytes:return e.value.length?void 0:Jt([64]);case g.string:return e.value===""?Jt([96]):void 0;case g.array:return e.value===0?Jt([128]):void 0;case g.map:return e.value===0?Jt([160]):void 0;case g.uint:return e.value<24?Jt([Number(e.value)]):void 0;case g.negint:if(e.value>=-24)return Jt([31-Number(e.value)])}}var zu=Object.freeze({float64:!0,mapSorter:Cp,quickEncodeToken:$u});function Sp(){let e=[];return e[g.uint.major]=Pt,e[g.negint.major]=Xn,e[g.bytes.major]=yr,e[g.string.major]=yu,e[g.array.major]=Qn,e[g.map.major]=to,e[g.tag.major]=eo,e[g.float.major]=ro,e}var vp=Sp(),ms=new Yr,io=class e{constructor(t,r){this.obj=t,this.parent=r}includes(t){let r=this;do if(r.obj===t)return!0;while(r=r.parent);return!1}static createCheck(t,r){if(t&&t.includes(r))throw new Error(`${fs} object contains circular references`);return new e(r,t)}},ve={null:new L(g.null,null),undefined:new L(g.undefined,void 0),true:new L(g.true,!0),false:new L(g.false,!1),emptyArray:new L(g.array,0),emptyMap:new L(g.map,0)},Ae={number(e,t,r,n){return!Number.isInteger(e)||!Number.isSafeInteger(e)?new L(g.float,e):e>=0?new L(g.uint,e):new L(g.negint,e)},bigint(e,t,r,n){return e>=BigInt(0)?new L(g.uint,e):new L(g.negint,e)},Uint8Array(e,t,r,n){return new L(g.bytes,e)},string(e,t,r,n){return new L(g.string,e)},boolean(e,t,r,n){return e?ve.true:ve.false},null(e,t,r,n){return ve.null},undefined(e,t,r,n){return ve.undefined},ArrayBuffer(e,t,r,n){return new L(g.bytes,new Uint8Array(e))},DataView(e,t,r,n){return new L(g.bytes,new Uint8Array(e.buffer,e.byteOffset,e.byteLength))},Array(e,t,r,n){if(!e.length)return r.addBreakTokens===!0?[ve.emptyArray,new L(g.break)]:ve.emptyArray;n=io.createCheck(n,e);let o=[],i=0;for(let s of e)o[i++]=oo(s,r,n);return r.addBreakTokens?[new L(g.array,e.length),o,new L(g.break)]:[new L(g.array,e.length),o]},Object(e,t,r,n){let o=t!=="Object",i=o?e.keys():Object.keys(e),s=o?e.size:i.length;if(!s)return r.addBreakTokens===!0?[ve.emptyMap,new L(g.break)]:ve.emptyMap;n=io.createCheck(n,e);let c=[],a=0;for(let l of i)c[a++]=[oo(l,r,n),oo(o?e.get(l):e[l],r,n)];return Ap(c,r),r.addBreakTokens?[new L(g.map,s),c,new L(g.break)]:[new L(g.map,s),c]}};Ae.Map=Ae.Object;Ae.Buffer=Ae.Uint8Array;for(let e of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))Ae[`${e}Array`]=Ae.DataView;function oo(e,t={},r){let n=$c(e),o=t&&t.typeEncoders&&t.typeEncoders[n]||Ae[n];if(typeof o=="function"){let s=o(e,n,t,r);if(s!=null)return s}let i=Ae[n];if(!i)throw new Error(`${fs} unsupported type: ${n}`);return i(e,n,t,r)}function Ap(e,t){t.mapSorter&&e.sort(t.mapSorter)}function Cp(e,t){if(e[0]instanceof L&&t[0]instanceof L){let r=e[0],n=t[0];return r._keyBytes||(r._keyBytes=Hu(r.value)),n._keyBytes||(n._keyBytes=Hu(n.value)),Wn(r._keyBytes,n._keyBytes)}throw new Error("rfc8949MapSorter: complex key types are not supported yet")}function Hu(e){return Tp(e,vp,zu)}function Gu(e,t,r,n){if(Array.isArray(t))for(let o of t)Gu(e,o,r,n);else r[t.type.major](e,t,n)}function Tp(e,t,r){let n=oo(e,r);if(!Array.isArray(n)&&r.quickEncodeToken){let o=r.quickEncodeToken(n);if(o)return o;let i=t[n.type.major];if(i.encodedSize){let s=i.encodedSize(n,r),c=new Yr(s);if(i(c,n,r),c.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${n} was wrong`);return us(c.chunks[0])}}return ms.reset(),Gu(ms,n,t,r),ms.toBytes(!0)}var Ip={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},so=class{constructor(t,r={}){this._pos=0,this.data=t,this.options=r}pos(){return this._pos}done(){return this._pos>=this.data.length}next(){let t=this.data[this._pos],r=qt[t];if(r===void 0){let n=B[t];if(!n)throw new Error(`${F} no decoder for major type ${t>>>5} (byte 0x${t.toString(16).padStart(2,"0")})`);let o=t&31;r=n(this.data,this._pos,o,this.options)}return this._pos+=r.encodedLength,r}},Qr=Symbol.for("DONE"),ao=Symbol.for("BREAK");function Bp(e,t,r){let n=[];for(let o=0;o<e.value;o++){let i=br(t,r);if(i===ao){if(e.value===1/0)break;throw new Error(`${F} got unexpected break to lengthed array`)}if(i===Qr)throw new Error(`${F} found array but not enough entries (got ${o}, expected ${e.value})`);n[o]=i}return n}function _p(e,t,r){let n=r.useMaps===!0,o=n?void 0:{},i=n?new Map:void 0;for(let s=0;s<e.value;s++){let c=br(t,r);if(c===ao){if(e.value===1/0)break;throw new Error(`${F} got unexpected break to lengthed map`)}if(c===Qr)throw new Error(`${F} found map but not enough entries (got ${s} [no key], expected ${e.value})`);if(n!==!0&&typeof c!="string")throw new Error(`${F} non-string keys not supported (got ${typeof c})`);if(r.rejectDuplicateMapKeys===!0&&(n&&i.has(c)||!n&&c in o))throw new Error(`${F} found repeat map key "${c}"`);let a=br(t,r);if(a===Qr)throw new Error(`${F} found map but not enough entries (got ${s} [no value], expected ${e.value})`);n?i.set(c,a):o[c]=a}return n?i:o}function br(e,t){if(e.done())return Qr;let r=e.next();if(r.type===g.break)return ao;if(r.type.terminal)return r.value;if(r.type===g.array)return Bp(r,e,t);if(r.type===g.map)return _p(r,e,t);if(r.type===g.tag){if(t.tags&&typeof t.tags[r.value]=="function"){let n=br(e,t);return t.tags[r.value](n)}throw new Error(`${F} tag not supported (${r.value})`)}throw new Error("unsupported")}function Zu(e,t){if(!(e instanceof Uint8Array))throw new Error(`${F} data to decode must be a Uint8Array`);t=Object.assign({},Ip,t);let r=t.tokenizer||new so(e,t),n=br(r,t);if(n===Qr)throw new Error(`${F} did not find any content to decode`);if(n===ao)throw new Error(`${F} got unexpected break`);return[n,e.subarray(r.pos())]}function ys(e,t){let[r,n]=Zu(e,t);if(n.length>0)throw new Error(`${F} too many terminals, data makes no sense`);return r}var Lp=pe("ipns:utils"),ju=H("/ipns/");var Up=0,Pp=18;function Yu(e){let t;if(e.pubKey!=null)try{t=Ec(e.pubKey)}catch(r){throw Lp.error(r),r}if(t!=null)return t}function Wu(e){let t=H("ipns-signature:");return Lt([t,e])}function tn(e){return"signatureV1"in e?Mt.encode({value:H(e.value),signatureV1:e.signatureV1,validityType:e.validityType,validity:H(e.validity),sequence:e.sequence,ttl:e.ttl,pubKey:e.pubKey,signatureV2:e.signatureV2,data:e.data}):Mt.encode({pubKey:e.pubKey,signatureV2:e.signatureV2,data:e.data})}function Ce(e){let t=Mt.decode(e);if(t.sequence!=null&&(t.sequence=BigInt(t.sequence)),t.ttl!=null&&(t.ttl=BigInt(t.ttl)),t.signatureV2==null||t.data==null)throw new Vt("Missing data or signatureV2");let r=Xu(t.data),n=Np(r.Value),o=z(r.Validity);if(t.value!=null&&t.signatureV1!=null)return Op(t),{value:n,validityType:Mt.ValidityType.EOL,validity:o,sequence:r.Sequence,ttl:r.TTL,pubKey:t.pubKey,signatureV1:t.signatureV1,signatureV2:t.signatureV2,data:t.data};if(t.signatureV2!=null)return{value:n,validityType:Mt.ValidityType.EOL,validity:o,sequence:r.Sequence,ttl:r.TTL,pubKey:t.pubKey,signatureV2:t.signatureV2,data:t.data};throw new Error("invalid record: does not include signatureV1 or signatureV2")}function en(e){return Lt([ju,e.bytes])}function wr(e){let t=Ie(e.slice(ju.length));if(!co(t,Up)&&!co(t,Pp))throw new qe("Multihash in IPNS key was not identity or sha2-256");return t}function Xu(e){let t=ys(e);if(t.ValidityType===0)t.ValidityType=Mt.ValidityType.EOL;else throw new hr("The validity type is unsupported");return Number.isInteger(t.Sequence)&&(t.Sequence=BigInt(t.Sequence)),Number.isInteger(t.TTL)&&(t.TTL=BigInt(t.TTL)),t}function Np(e){let t=z(e).trim();if(t.startsWith("/"))return t;try{return`/ipfs/${j.decode(e).toV1().toString()}`}catch{}try{return`/ipfs/${j.parse(t).toV1().toString()}`}catch{}throw new Zn("Value must be a valid content path starting with /")}function Op(e){if(e.data==null)throw new jn("Record data is missing");let t=Xu(e.data);if(!J(t.Value,e.value??new Uint8Array(0)))throw new Vt('Field "value" did not match between protobuf and CBOR');if(!J(t.Validity,e.validity??new Uint8Array(0)))throw new Vt('Field "validity" did not match between protobuf and CBOR');if(t.ValidityType!==e.validityType)throw new Vt('Field "validityType" did not match between protobuf and CBOR');if(t.Sequence!==e.sequence)throw new Vt('Field "sequence" did not match between protobuf and CBOR');if(t.TTL!==e.ttl)throw new Vt('Field "ttl" did not match between protobuf and CBOR')}function co(e,t){return e.code===t}var e1=pe("ipns"),r1=300*1e9,Kp="/ipns/",n1=Kp.length;var Ju=yo(cs(),1);var uo=pe("ipns:validator"),Vp=1024*10;async function Mp(e,t){let r=Ce(t),n;try{let o=Wu(r.data);n=await e.verify(o,r.signatureV2)}catch{n=!1}if(!n)throw uo.error("record signature verification failed"),new Vt("Record signature verification failed");if(r.validityType===Mt.ValidityType.EOL){if(Ju.default.fromString(r.validity).toDate().getTime()<Date.now())throw uo.error("record has expired"),new zn("record has expired")}else if(r.validityType!=null)throw uo.error("the validity type is unsupported"),new hr("The validity type is unsupported");uo("ipns record for %s is valid",r.value)}async function Qu(e,t){if(t.byteLength>Vp)throw new Gn("The record is too large");let r=wr(e),n;co(r,0)&&(n=Pn(r));let o=Ce(t),i=Yu(o)??n;if(i==null)throw new jr("Could not extract public key from IPNS record or routing key");let s=en(i.toMultihash());if(!J(s,e))throw new jr("Embedded public key did not match routing key");await Mp(i,t)}var fo=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MESSAGE_LENGTH"};async function*rn(e,t={}){let r=/\r?\n/,n=new TextDecoder("utf8"),o="";for await(let i of e){if(typeof i=="string"&&(i=new TextEncoder().encode(i)),je(i)&&(i=i.subarray()),o+=n.decode(i,{stream:!0}),o.length>(t?.maxMessageLength??o.length))throw new fo("Incoming message too long");let s=o.split(r);o=s.pop()??"";for(let c=0;c<s.length;c++)yield JSON.parse(s[c])}o+=n.decode(),o!==""&&(yield JSON.parse(o))}function Qt(){let e={};return e.promise=new Promise((t,r)=>{e.resolve=t,e.reject=r}),e}var xs=yo(ef(),1);var bs=class e extends Error{name="TimeoutError";constructor(t,r){super(t,r),Error.captureStackTrace?.(this,e)}},rf=e=>e.reason??new DOMException("This operation was aborted.","AbortError");function ws(e,t){let{milliseconds:r,fallback:n,message:o,customTimers:i={setTimeout,clearTimeout},signal:s}=t,c,a,u=new Promise((f,x)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(s?.aborted){x(rf(s));return}if(s&&(a=()=>{x(rf(s))},s.addEventListener("abort",a,{once:!0})),e.then(f,x),r===Number.POSITIVE_INFINITY)return;let v=new bs;c=i.setTimeout.call(void 0,()=>{if(n){try{f(n())}catch(b){x(b)}return}typeof e.cancel=="function"&&e.cancel(),o===!1?f():o instanceof Error?x(o):(v.message=o??`Promise timed out after ${r} milliseconds`,x(v))},r)}).finally(()=>{u.clear(),a&&s&&s.removeEventListener("abort",a)});return u.clear=()=>{i.clearTimeout.call(void 0,c),c=void 0},u}function Es(e,t,r){let n=0,o=e.length;for(;o>0;){let i=Math.trunc(o/2),s=n+i;r(e[s],t)<=0?(n=++s,o-=i+1):o=i}return n}var on=class{#t=[];enqueue(t,r){let{priority:n=0,id:o}=r??{},i={priority:n,id:o,run:t};if(this.size===0||this.#t[this.size-1].priority>=n){this.#t.push(i);return}let s=Es(this.#t,i,(c,a)=>a.priority-c.priority);this.#t.splice(s,0,i)}setPriority(t,r){let n=this.#t.findIndex(i=>i.id===t);if(n===-1)throw new ReferenceError(`No promise function with the id "${t}" exists in the queue.`);let[o]=this.#t.splice(n,1);this.enqueue(o.run,{priority:r,id:t})}dequeue(){return this.#t.shift()?.run}filter(t){return this.#t.filter(r=>r.priority===t.priority).map(r=>r.run)}get size(){return this.#t.length}};var sn=class extends xs.default{#t;#n;#r=0;#h;#p=!1;#m=!1;#u;#b=0;#y=0;#i;#s;#e;#w;#o=0;#f;#a;#T=1n;#l=new Map;timeout;constructor(t){if(super(),t={carryoverIntervalCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:on,...t},!(typeof t.intervalCap=="number"&&t.intervalCap>=1))throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${t.intervalCap?.toString()??""}\` (${typeof t.intervalCap})`);if(t.interval===void 0||!(Number.isFinite(t.interval)&&t.interval>=0))throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${t.interval?.toString()??""}\` (${typeof t.interval})`);if(this.#t=t.carryoverIntervalCount??t.carryoverConcurrencyCount??!1,this.#n=t.intervalCap===Number.POSITIVE_INFINITY||t.interval===0,this.#h=t.intervalCap,this.#u=t.interval,this.#e=new t.queueClass,this.#w=t.queueClass,this.concurrency=t.concurrency,t.timeout!==void 0&&!(Number.isFinite(t.timeout)&&t.timeout>0))throw new TypeError(`Expected \`timeout\` to be a positive finite number, got \`${t.timeout}\` (${typeof t.timeout})`);this.timeout=t.timeout,this.#a=t.autoStart===!1,this.#U()}get#I(){return this.#n||this.#r<this.#h}get#B(){return this.#o<this.#f}#_(){this.#o--,this.#o===0&&this.emit("pendingZero"),this.#g(),this.emit("next")}#D(){this.#A(),this.#v(),this.#s=void 0}get#R(){let t=Date.now();if(this.#i===void 0){let r=this.#b-t;if(r<0){if(this.#y>0){let n=t-this.#y;if(n<this.#u)return this.#E(this.#u-n),!0}this.#r=this.#t?this.#o:0}else return this.#E(r),!0}return!1}#E(t){this.#s===void 0&&(this.#s=setTimeout(()=>{this.#D()},t))}#S(){this.#i&&(clearInterval(this.#i),this.#i=void 0)}#L(){this.#s&&(clearTimeout(this.#s),this.#s=void 0)}#g(){if(this.#e.size===0)return this.#S(),this.emit("empty"),this.#o===0&&(this.#L(),this.emit("idle")),!1;let t=!1;if(!this.#a){let r=!this.#R;if(this.#I&&this.#B){let n=this.#e.dequeue();this.#n||(this.#r++,this.#d()),this.emit("active"),this.#y=Date.now(),n(),r&&this.#v(),t=!0}}return t}#v(){this.#n||this.#i!==void 0||(this.#i=setInterval(()=>{this.#A()},this.#u),this.#b=Date.now()+this.#u)}#A(){this.#r===0&&this.#o===0&&this.#i&&this.#S(),this.#r=this.#t?this.#o:0,this.#x(),this.#d()}#x(){for(;this.#g(););}get concurrency(){return this.#f}set concurrency(t){if(!(typeof t=="number"&&t>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${t}\` (${typeof t})`);this.#f=t,this.#x()}setPriority(t,r){if(typeof r!="number"||!Number.isFinite(r))throw new TypeError(`Expected \`priority\` to be a finite number, got \`${r}\` (${typeof r})`);this.#e.setPriority(t,r)}async add(t,r={}){return r.id??=(this.#T++).toString(),r={timeout:this.timeout,...r},new Promise((n,o)=>{let i=Symbol(`task-${r.id}`);this.#e.enqueue(async()=>{this.#o++,this.#l.set(i,{id:r.id,priority:r.priority??0,startTime:Date.now(),timeout:r.timeout});let s;try{try{r.signal?.throwIfAborted()}catch(l){throw this.#n||this.#r--,this.#l.delete(i),l}let c=t({signal:r.signal});if(r.timeout&&(c=ws(Promise.resolve(c),{milliseconds:r.timeout,message:`Task timed out after ${r.timeout}ms (queue has ${this.#o} running, ${this.#e.size} waiting)`})),r.signal){let{signal:l}=r;c=Promise.race([c,new Promise((u,f)=>{s=()=>{f(l.reason)},l.addEventListener("abort",s,{once:!0})})])}let a=await c;n(a),this.emit("completed",a)}catch(c){o(c),this.emit("error",c)}finally{s&&r.signal?.removeEventListener("abort",s),this.#l.delete(i),queueMicrotask(()=>{this.#_()})}},r),this.emit("add"),this.#g()})}async addAll(t,r){return Promise.all(t.map(async n=>this.add(n,r)))}start(){return this.#a?(this.#a=!1,this.#x(),this):this}pause(){this.#a=!0}clear(){this.#e=new this.#w,this.#C()}async onEmpty(){this.#e.size!==0&&await this.#c("empty")}async onSizeLessThan(t){this.#e.size<t||await this.#c("next",()=>this.#e.size<t)}async onIdle(){this.#o===0&&this.#e.size===0||await this.#c("idle")}async onPendingZero(){this.#o!==0&&await this.#c("pendingZero")}async onRateLimit(){this.isRateLimited||await this.#c("rateLimit")}async onRateLimitCleared(){this.isRateLimited&&await this.#c("rateLimitCleared")}async onError(){return new Promise((t,r)=>{let n=o=>{this.off("error",n),r(o)};this.on("error",n)})}async#c(t,r){return new Promise(n=>{let o=()=>{r&&!r()||(this.off(t,o),n())};this.on(t,o)})}get size(){return this.#e.size}sizeBy(t){return this.#e.filter(t).length}get pending(){return this.#o}get isPaused(){return this.#a}#U(){this.#n||(this.on("add",()=>{this.#e.size>0&&this.#d()}),this.on("next",()=>{this.#d()}))}#d(){this.#n||this.#m||(this.#m=!0,queueMicrotask(()=>{this.#m=!1,this.#C()}))}#C(){let t=this.#p,r=!this.#n&&this.#r>=this.#h&&this.#e.size>0;r!==t&&(this.#p=r,this.emit(r?"rateLimit":"rateLimitCleared"))}get isRateLimited(){return this.#p}get isSaturated(){return this.#o===this.#f&&this.#e.size>0||this.isRateLimited&&this.#e.size>0}get runningTasks(){return[...this.#l.values()].map(t=>({...t}))}};var Er=class extends Error{static name="InvalidRequestError";constructor(t="Invalid request"){super(t),this.name="InvalidRequestError"}},$t=class extends Error{static name="BadResponseError";constructor(t="Bad response"){super(t),this.name="BadResponseError"}};function $p(e){return e[Symbol.asyncIterator]!=null}function Hp(e){if($p(e))return(async()=>{for await(let t of e)return t})();for(let t of e)return t}var nf=Hp;function zp(e){let[t,r]=e[Symbol.asyncIterator]!=null?[e[Symbol.asyncIterator](),Symbol.asyncIterator]:[e[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(),[r](){return this}}}var of=zp;function Gp(e){return e[Symbol.asyncIterator]!=null}function Zp(e,t){let r=0;if(Gp(e))return(async function*(){for await(let a of e)yield t(a,r++)})();let n=of(e),{value:o,done:i}=n.next();if(i===!0)return(function*(){})();let s=t(o,r++);if(typeof s.then=="function")return(async function*(){yield await s;for(let a of n)yield t(a,r++)})();let c=t;return(function*(){yield s;for(let a of n)yield c(a,r++)})()}var sf=Zp;var af=H("/ipns/");function cf(e){return J(e.subarray(0,af.byteLength),af)}var ho=class{client;constructor(t){this.client=t}async*findProviders(t,r={}){try{yield*sf(this.client.getProviders(t,r),n=>({id:n.ID,multiaddrs:n.Addrs??[],routing:"delegated-http-routing-v1"}))}catch(n){if(n instanceof Gt)return;throw n}}async provide(){}async cancelReprovide(){}async put(t,r,n){if(!cf(t))return;let o=wr(t),i=j.createV1(114,o),s=Ce(r);await this.client.putIPNS(i,s,n)}async get(t,r){if(!cf(t))throw new Gt("Not found");let n=wr(t),o=j.createV1(114,n);try{let i=await this.client.getIPNS(o,r);return tn(i)}catch(i){throw i.name==="BadResponseError"?new Gt("Not found"):i}}toString(){return`DelegatedRoutingV1HttpApiClientContentRouting(${this.client.url})`}},po=class{client;constructor(t){this.client=t}async findPeer(t,r={}){let n=await nf(this.client.getPeers(t,r));if(n!=null)return{id:n.ID,multiaddrs:n.Addrs??[]};throw new Gt("Not found")}async*getClosestPeers(t,r={}){}toString(){return`DelegatedRoutingV1HttpApiClientPeerRouting(${this.client.url})`}};var mo={concurrentRequests:4,timeout:3e4,cacheTTL:300*1e3,cacheName:"delegated-routing-v1-cache"},an=class{url;started;httpQueue;shutDownController;timeout;contentRouting;peerRouting;filterAddrs;filterProtocols;inFlightRequests;cacheName;cache;cacheTTL;log;constructor(t,r){this.log=t.logger.forComponent("delegated-routing-v1-http-api-client"),this.started=!1,this.shutDownController=new AbortController,this.shutDownController.signal,this.httpQueue=new sn({concurrency:r.concurrentRequests??mo.concurrentRequests}),this.inFlightRequests=new Map,this.url=r.url instanceof URL?r.url:new URL(r.url),this.timeout=r.timeout??mo.timeout,this.filterAddrs=r.filterAddrs,this.filterProtocols=r.filterProtocols,this.contentRouting=new ho(this),this.peerRouting=new po(this),this.cacheName=r.cacheName??mo.cacheName,this.cacheTTL=r.cacheTTL??mo.cacheTTL}get[ks](){return this.contentRouting}get[Ks](){return this.peerRouting}isStarted(){return this.started}async start(){this.started||(this.started=!0,this.cacheTTL>0&&(this.cache=await globalThis.caches?.open(this.cacheName),this.cache!=null&&this.log("cache enabled with ttl %d",this.cacheTTL)))}async stop(){this.httpQueue.clear(),this.shutDownController.abort(),await globalThis.caches?.delete(this.cacheName),this.started=!1}async*getProviders(t,r={}){this.log("getProviders starts: %c",t);let n=AbortSignal.timeout(this.timeout),o=Zr([this.shutDownController.signal,n,r.signal]);let i=Qt(),s=Qt(),c=0;this.httpQueue.add(async()=>(i.resolve(),s.promise));try{await i.promise;let a=new URL(`${this.url}routing/v1/providers/${t}`);this.#n(a,r.filterAddrs,r.filterProtocols);let l={headers:{accept:"application/x-ndjson, application/json;q=0.8"},signal:o},u=await this.#r(a.toString(),l);if(!u.ok){if(u.status===404)return;throw u.status===422?new Er("Request does not conform to schema or semantic constraints"):new $t(`Unexpected status code: ${u.status}`)}let f=u.headers.get("Content-Type");if(f==null)throw new $t("No Content-Type header received");if(u.body==null){if(f!=="application/x-ndjson")throw new $t("Routing response had no body");return}if(f.startsWith("application/json")){let v=(await u.json()).Providers??[];for(let b of v){let T=this.#t(b);T!=null&&(c++,yield T)}}else if(f.includes("application/x-ndjson"))for await(let x of rn(Hn(u.body))){let v=this.#t(x);v!=null&&(c++,yield v)}else throw new $t(`Unsupported Content-Type: ${f}`)}finally{o.clear(),s.resolve(),this.log("getProviders finished found %d providers for %c",c,t)}}async*getPeers(t,r={}){this.log("getPeers starts: %c",t);let n=AbortSignal.timeout(this.timeout),o=Zr([this.shutDownController.signal,n,r.signal]);let i=Qt(),s=Qt();this.httpQueue.add(async()=>(i.resolve(),s.promise));try{await i.promise;let c=new URL(`${this.url}routing/v1/peers/${t.toCID().toString()}`);this.#n(c,r.filterAddrs,r.filterProtocols);let a={headers:{Accept:"application/x-ndjson"},signal:o},l=await this.#r(c.toString(),a);if(l.status===404)return;if(l.status===422)throw new Er("Request does not conform to schema or semantic constraints");if(l.body==null)throw new $t("Routing response had no body");if(l.headers.get("Content-Type")?.startsWith("application/json")){let x=(await l.json()).Peers??[];for(let v of x){let b=this.#t(v);b!=null&&(yield b)}}else for await(let f of rn(Hn(l.body))){let x=this.#t(f);x!=null&&(yield x)}}catch(c){this.log.error("getPeers errored - %e",c)}finally{o.clear(),s.resolve(),this.log("getPeers finished: %c",t)}}async getIPNS(t,r={}){this.log("getIPNS starts: %s",t);let n=AbortSignal.timeout(this.timeout),o=Zr([this.shutDownController.signal,n,r.signal]);let i=Qt(),s=Qt();this.httpQueue.add(async()=>(i.resolve(),s.promise));let c=`${this.url}routing/v1/ipns/${t}`;try{await i.promise;let a={headers:{Accept:"application/vnd.ipfs.ipns-record"},signal:o},l=await this.#r(c,a);if(this.log("getIPNS GET %s %d",c,l.status),l.status===404)throw new Gt("No matching records found");if(l.status===422)throw new Er("Request does not conform to schema or semantic constraints");if(!l.ok)throw new $t(`Unexpected status code: ${l.status}`);let u=l.headers.get("Content-Type");if(u==null||!u.includes("application/vnd.ipfs.ipns-record"))throw new Gt("No matching records found");if(l.body==null)throw new $t("GET ipns response had no body");let f=await l.arrayBuffer(),x=new Uint8Array(f,0,f.byteLength);return r.validate!==!1&&await Qu(en(t.multihash),x),Ce(x)}catch(a){throw this.log.error("getIPNS GET %s error - %e",c,a),a}finally{o.clear(),s.resolve(),this.log("getIPNS finished: %s",t)}}async putIPNS(t,r,n={}){this.log("putIPNS starts: %c",t);let o=AbortSignal.timeout(this.timeout),i=Zr([this.shutDownController.signal,o,n.signal]);let s=Qt(),c=Qt();this.httpQueue.add(async()=>(s.resolve(),c.promise));let a=`${this.url}routing/v1/ipns/${t}`;try{await s.promise;let l=tn(r),u={method:"PUT",headers:{"Content-Type":"application/vnd.ipfs.ipns-record"},body:l,signal:i},f=await this.#r(a,u);if(this.log("putIPNS PUT %s %d",a,f.status),f.status!==200)throw new $t("PUT ipns response had status other than 200")}catch(l){throw this.log.error("putIPNS PUT %s error - %e",a,l.stack),l}finally{i.clear(),c.resolve(),this.log("putIPNS finished: %c",t)}}#t(t){try{let r=[],n=t.Addrs?.map(qc)??[];return t.Protocols!=null&&r.push(...t.Protocols),t.Protocol!=null&&(r.push(t.Protocol),delete t.Protocol),{...t,Schema:"peer",ID:Ac(t.ID),Addrs:n,Protocols:r}}catch(r){this.log.error("could not conform record to peer schema - %e",r)}}#n(t,r,n){if(r!=null||this.filterAddrs!=null){let o=r?.join(",")??this.filterAddrs?.join(",")??"";o!==""&&t.searchParams.set("filter-addrs",o)}if(n!=null||this.filterProtocols!=null){let o=n?.join(",")??this.filterProtocols?.join(",")??"";o!==""&&t.searchParams.set("filter-protocols",o)}}async#r(t,r){let n=r.method??"GET",o=`${n}-${t}`;if(n==="GET"){let a=await this.cache?.match(t);if(a!=null){if(parseInt(a.headers.get("x-cache-expires")??"0",10)>Date.now())return this.log("returning cached response for %s",o),this.logResponse(a),a;this.log("evicting cached response for %s",o),await this.cache?.delete(t)}else this.cache!=null&&this.log("cache miss for %s",o)}let i=this.inFlightRequests.get(o);if(i!=null){let a=await i;return this.log("deduplicating outgoing request for %s",o),a.clone()}this.log("outgoing request:"),this.logRequest(t,r);let s=fetch(t,r).then(async a=>{if(this.log("incoming response:"),this.logResponse(a),this.cache!=null&&a.ok&&n==="GET"){let l=Date.now()+this.cacheTTL,u=new Headers(a.headers);u.set("x-cache-expires",l.toString());let f=new Response(a.clone().body,{status:a.status,statusText:a.statusText,headers:u});await this.cache.put(t,f)}return a}).finally(()=>{this.inFlightRequests.delete(o)});return this.inFlightRequests.set(o,s),await s}toString(){return`DefaultDelegatedRoutingV1HttpApiClient(${this.url})`}logRequest(t,r){let n=new Headers(r.headers);this.log("%s %s HTTP/1.1",r.method??"GET",t);for(let[o,i]of n.entries())this.log("%s: %s",o,i)}logResponse(t){this.log("HTTP/1.1 %d %s",t.status,t.statusText);for(let[r,n]of t.headers.entries())this.log("%s: %s",r,n)}};function jp(e,t={}){return new an({logger:Os()},{...t,url:new URL(e)})}function Yp(e){return t=>new an(t,e)}return pf(Wp);})();
13
+ ${t}[Error list was empty]`,r.trim()}return Ns(e,t)}St.formatters.e=e=>e==null?"undefined":ks(e);function Zf(e){let t=()=>{};return t.enabled=!1,t.color="",t.diff=0,t.log=()=>{},t.namespace=e,t.destroy=()=>!0,t.extend=()=>t,t}function Ks(e){return{forComponent(t){return me(t,e)}}}function me(e,t){let r=Zf(`${e}:trace`);return St.enabled(`${e}:trace`)&&St.names.map(n=>n.toString()).find(n=>n.includes(":trace"))!=null&&(r=St(`${e}:trace`,t)),Object.assign(St(e,t),{error:St(`${e}:error`,t),trace:r,newScope:n=>me(`${e}:${n}`,t)})}function Os(e){if(e!=null&&(e=e.trim(),e.length!==0))return e}var Vs=Symbol.for("@libp2p/content-routing");var ot=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},$e=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var jt=class extends Error{static name="NotFoundError";constructor(t="Not found"){super(t),this.name="NotFoundError"}};var hn=class extends Error{static name="InvalidCIDError";constructor(t="Invalid CID"){super(t),this.name="InvalidCIDError"}},He=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var ze=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var pn=Symbol.for("@libp2p/peer-id");function Ms(e){return!!e?.[pn]}var Fs=Symbol.for("@libp2p/peer-routing");var _o={};bt(_o,{base36:()=>Ge,base36upper:()=>jf});var Ge=pe({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),jf=pe({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Yt={};bt(Yt,{Digest:()=>_e,create:()=>Kt,decode:()=>ye,equals:()=>Ro,hasCode:()=>hl});var Yf=Hs,qs=128,Wf=127,Xf=~Wf,Jf=Math.pow(2,31);function Hs(e,t,r){t=t||[],r=r||0;for(var n=r;e>=Jf;)t[r++]=e&255|qs,e/=128;for(;e&Xf;)t[r++]=e&255|qs,e>>>=7;return t[r]=e|0,Hs.bytes=r-n+1,t}var Qf=Do,tl=128,$s=127;function Do(e,n){var r=0,n=n||0,o=0,i=n,s,c=e.length;do{if(i>=c)throw Do.bytes=0,new RangeError("Could not decode varint");s=e[i++],r+=o<28?(s&$s)<<o:(s&$s)*Math.pow(2,o),o+=7}while(s>=tl);return Do.bytes=i-n,r}var el=Math.pow(2,7),rl=Math.pow(2,14),nl=Math.pow(2,21),ol=Math.pow(2,28),il=Math.pow(2,35),sl=Math.pow(2,42),al=Math.pow(2,49),cl=Math.pow(2,56),ul=Math.pow(2,63),fl=function(e){return e<el?1:e<rl?2:e<nl?3:e<ol?4:e<il?5:e<sl?6:e<al?7:e<cl?8:e<ul?9:10},ll={encode:Yf,decode:Qf,encodingLength:fl},dl=ll,Ar=dl;function Cr(e,t=0){return[Ar.decode(e,t),Ar.decode.bytes]}function Ze(e,t,r=0){return Ar.encode(e,t,r),t}function je(e){return Ar.encodingLength(e)}function Kt(e,t){let r=t.byteLength,n=je(e),o=n+je(r),i=new Uint8Array(o+r);return Ze(e,i,0),Ze(r,i,n),i.set(t,o),new _e(e,r,t,i)}function ye(e){let t=ee(e),[r,n]=Cr(t),[o,i]=Cr(t.subarray(n)),s=t.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new _e(r,o,s,t)}function Ro(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&Bs(e.bytes,r.bytes)}}var _e=class{code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=n,this.bytes=o}};function hl(e,t){return e.code===t}function zs(e,t){let{bytes:r,version:n}=e;switch(n){case 0:return ml(r,Lo(e),t??W.encoder);default:return yl(r,Lo(e),t??Zt.encoder)}}var Gs=new WeakMap;function Lo(e){let t=Gs.get(e);if(t==null){let r=new Map;return Gs.set(e,r),r}return t}var j=class e{code;version;multihash;bytes;"/";constructor(t,r,n,o){this.code=r,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:r}=this;if(t!==Ir)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==gl)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return e.createV0(r)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:t,digest:r}=this.multihash,n=Kt(t,r);return e.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 e.equals(this,t)}static equals(t,r){let n=r;return n!=null&&t.code===n.code&&t.version===n.version&&Ro(t.multihash,n.multihash)}toString(t){return zs(this,t)}toJSON(){return{"/":zs(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 r=t;if(r instanceof e)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:i,bytes:s}=r;return new e(n,o,i,s??Zs(n,o,i.bytes))}else if(r[xl]===!0){let{version:n,multihash:o,code:i}=r,s=ye(o);return e.create(n,i,s)}else return null}static create(t,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(r!==Ir)throw new Error(`Version 0 CID must use dag-pb (code: ${Ir}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=Zs(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,Ir,t)}static createV1(t,r){return e.create(1,t,r)}static decode(t){let[r,n]=e.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(t){let r=e.inspectBytes(t),n=r.size-r.multihashSize,o=ee(t.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let i=o.subarray(r.multihashSize-r.digestSize),s=new _e(r.multihashCode,r.digestSize,i,o);return[r.version===0?e.createV0(s):e.createV1(r.codec,s),t.subarray(r.size)]}static inspectBytes(t){let r=0,n=()=>{let[f,y]=Cr(t.subarray(r));return r+=y,f},o=n(),i=Ir;if(o===18?(o=0,r=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let s=r,c=n(),a=n(),l=r+a,u=l-s;return{version:o,codec:i,multihashCode:c,digestSize:a,multihashSize:u,size:l}}static parse(t,r){let[n,o]=pl(t,r),i=e.decode(o);if(i.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Lo(i).set(n,t),i}};function pl(e,t){switch(e[0]){case"Q":{let r=t??W;return[W.prefix,r.decode(`${W.prefix}${e}`)]}case W.prefix:{let r=t??W;return[W.prefix,r.decode(e)]}case Zt.prefix:{let r=t??Zt;return[Zt.prefix,r.decode(e)]}case Ge.prefix:{let r=t??Ge;return[Ge.prefix,r.decode(e)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[e[0],t.decode(e)]}}}function ml(e,t,r){let{prefix:n}=r;if(n!==W.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=t.get(n);if(o==null){let i=r.encode(e).slice(1);return t.set(n,i),i}else return o}function yl(e,t,r){let{prefix:n}=r,o=t.get(n);if(o==null){let i=r.encode(e);return t.set(n,i),i}else return o}var Ir=112,gl=18;function Zs(e,t,r){let n=je(e),o=n+je(t),i=new Uint8Array(o+r.byteLength);return Ze(e,i,0),Ze(t,i,n),i.set(r,o),i}var xl=Symbol.for("@ipld/js-cid/CID");var Po={};bt(Po,{identity:()=>Vt});var js=0,bl="identity",Ys=ee;function wl(e,t){if(t?.truncate!=null&&t.truncate!==e.byteLength){if(t.truncate<0||t.truncate>e.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${e.byteLength}`);e=e.subarray(0,t.truncate)}return Kt(js,Ys(e))}var Vt={code:js,name:bl,encode:Ys,digest:wl};function J(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function re(e=0){return new Uint8Array(e)}function Ct(e=0){return new Uint8Array(e)}function Lt(e,t){t==null&&(t=e.reduce((o,i)=>o+i.length,0));let r=Ct(t),n=0;for(let o of e)r.set(o,n),n+=o.length;return r}var Xs=Symbol.for("@achingbrain/uint8arraylist");function Ws(e,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let r=0;for(let n of e){let o=r+n.byteLength;if(t<o)return{buf:n,index:t-r};r=o}throw new RangeError("index is out of bounds")}function Ye(e){return!!e?.[Xs]}var It=class e{bufs;length;[Xs]=!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 r=0;for(let n of t)if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.push(n);else if(Ye(n))r+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}prepend(...t){this.prependAll(t)}prependAll(t){let r=0;for(let n of t.reverse())if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.unshift(n);else if(Ye(n))r+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}get(t){let r=Ws(this.bufs,t);return r.buf[r.index]}set(t,r){let n=Ws(this.bufs,t);n.buf[n.index]=r}write(t,r=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(r+n,t[n]);else if(Ye(t))for(let n=0;n<t.length;n++)this.set(r+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,r){let{bufs:n,length:o}=this._subList(t,r);return Lt(n,o)}subarray(t,r){let{bufs:n,length:o}=this._subList(t,r);return n.length===1?n[0]:Lt(n,o)}sublist(t,r){let{bufs:n,length:o}=this._subList(t,r),i=new e;return i.length=o,i.bufs=[...n],i}_subList(t,r){if(t=t??0,r=r??this.length,t<0&&(t=this.length+t),r<0&&(r=this.length+r),t<0||r>this.length)throw new RangeError("index is out of bounds");if(t===r)return{bufs:[],length:0};if(t===0&&r===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=r>c&&r<=a;if(l&&u){if(t===c&&r===a){n.push(s);break}let f=t-c;n.push(s.subarray(f,f+(r-t)));break}if(l){if(t===0){n.push(s);continue}n.push(s.subarray(t-c));continue}if(u){if(r===a){n.push(s);break}n.push(s.subarray(0,r-c));break}n.push(s)}return{bufs:n,length:r-t}}indexOf(t,r=0){if(!Ye(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(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),t.length===0)return r>this.length?this.length:r;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=r;f<=a;f+=u){u=0;for(let y=l;y>=0;y--){let E=this.get(f+y);if(n[y]!==E){u=Math.max(1,y-c[E]);break}}if(u===0)return f}return-1}getInt8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(t,r){let n=Ct(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,r),this.write(n,t)}getInt16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,r)}setInt16(t,r,n){let o=re(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,r,n),this.write(o,t)}getInt32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,r)}setInt32(t,r,n){let o=re(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,r,n),this.write(o,t)}getBigInt64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,r)}setBigInt64(t,r,n){let o=re(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,r,n),this.write(o,t)}getUint8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint8(0)}setUint8(t,r){let n=Ct(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,r),this.write(n,t)}getUint16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,r)}setUint16(t,r,n){let o=re(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,r,n),this.write(o,t)}getUint32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,r)}setUint32(t,r,n){let o=re(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,r,n),this.write(o,t)}getBigUint64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,r)}setBigUint64(t,r,n){let o=re(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,r,n),this.write(o,t)}getFloat32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,r)}setFloat32(t,r,n){let o=re(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,r,n),this.write(o,t)}getFloat64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,r)}setFloat64(t,r,n){let o=re(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,r,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof e)||t.bufs.length!==this.bufs.length)return!1;for(let r=0;r<this.bufs.length;r++)if(!J(this.bufs[r],t.bufs[r]))return!1;return!0}static fromUint8Arrays(t,r){let n=new e;return n.bufs=t,r==null&&(r=t.reduce((o,i)=>o+i.byteLength,0)),n.length=r,n}};var Uo={};bt(Uo,{base10:()=>El});var El=pe({prefix:"9",name:"base10",alphabet:"0123456789"});var No={};bt(No,{base16:()=>Sl,base16upper:()=>vl});var Sl=nt({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),vl=nt({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Oo={};bt(Oo,{base2:()=>Al});var Al=nt({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var ko={};bt(ko,{base256emoji:()=>_l});var Js=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}"),Cl=Js.reduce((e,t,r)=>(e[r]=t,e),[]),Il=Js.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function Tl(e){return e.reduce((t,r)=>(t+=Cl[r],t),"")}function Bl(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=Il[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(o)}return new Uint8Array(t)}var _l=qe({prefix:"\u{1F680}",name:"base256emoji",encode:Tl,decode:Bl});var Ko={};bt(Ko,{base8:()=>Dl});var Dl=nt({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Vo={};bt(Vo,{identity:()=>Rl});var Rl=qe({prefix:"\0",name:"identity",encode:e=>Ds(e),decode:e=>_s(e)});var tm=new TextEncoder,em=new TextDecoder;var qo={};bt(qo,{sha256:()=>Tr,sha512:()=>Nl});var Ul=20;function Fo({name:e,code:t,encode:r,minDigestLength:n,maxDigestLength:o}){return new Mo(e,t,r,n,o)}var Mo=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,r,n,o,i){this.name=t,this.code=r,this.encode=n,this.minDigestLength=o??Ul,this.maxDigestLength=i}digest(t,r){if(r?.truncate!=null){if(r.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&r.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(t instanceof Uint8Array){let n=this.encode(t);return n instanceof Uint8Array?Qs(n,this.code,r?.truncate):n.then(o=>Qs(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function Qs(e,t,r){if(r!=null&&r!==e.byteLength){if(r>e.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${e.byteLength}`);e=e.subarray(0,r)}return Kt(t,e)}function ea(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var Tr=Fo({name:"sha2-256",code:18,encode:ea("SHA-256")}),Nl=Fo({name:"sha2-512",code:19,encode:ea("SHA-512")});var Br={...Vo,...Oo,...Ko,...Uo,...No,...vo,..._o,...Ao,...To,...ko},hm={...qo,...Po};function na(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var ra=na("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),$o=na("ascii","a",e=>{let t="a";for(let r=0;r<e.length;r++)t+=String.fromCharCode(e[r]);return t},e=>{e=e.substring(1);let t=Ct(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),Ol={utf8:ra,"utf-8":ra,hex:Br.base16,latin1:$o,ascii:$o,binary:$o,...Br},yn=Ol;function H(e,t="utf8"){let r=yn[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function z(e,t="utf8"){let r=yn[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var kl=parseInt("11111",2),Ho=parseInt("10000000",2),Kl=parseInt("01111111",2),oa={0:_r,1:_r,2:Vl,3:ql,4:$l,5:Fl,6:Ml,16:_r,22:_r,48:_r};function ne(e,t={offset:0}){let r=e[t.offset]&kl;if(t.offset++,oa[r]!=null)return oa[r](e,t);throw new Error("No decoder for tag "+r)}function Dr(e,t){let r=0;if((e[t.offset]&Ho)===Ho){let n=e[t.offset]&Kl,o="0x";t.offset++;for(let i=0;i<n;i++,t.offset++)o+=e[t.offset].toString(16).padStart(2,"0");r=parseInt(o,16)}else r=e[t.offset],t.offset++;return r}function _r(e,t){Dr(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=ne(e,t);if(n===null)break;r.push(n)}return r}function Vl(e,t){let r=Dr(e,t),n=t.offset,o=t.offset+r,i=[];for(let s=n;s<o;s++)s===n&&e[s]===0||i.push(e[s]);return t.offset+=r,Uint8Array.from(i)}function Ml(e,t){let r=Dr(e,t),n=t.offset+r,o=e[t.offset];t.offset++;let i=0,s=0;o<40?(i=0,s=o):o<80?(i=1,s=o-40):(i=2,s=o-80);let c=`${i}.${s}`,a=[];for(;t.offset<n;){let l=e[t.offset];if(t.offset++,a.push(l&127),l<128){a.reverse();let u=0;for(let f=0;f<a.length;f++)u+=a[f]<<f*7;c+=`.${u}`,a=[]}}return c}function Fl(e,t){return t.offset++,null}function ql(e,t){let r=Dr(e,t),n=e[t.offset];t.offset++;let o=e.subarray(t.offset,t.offset+r-1);if(t.offset+=r,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function $l(e,t){let r=Dr(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function Hl(e){let t=e.toString(16);t.length%2===1&&(t="0"+t);let r=new It;for(let n=0;n<t.length;n+=2)r.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return r}function zo(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);let t=Hl(e.byteLength);return new It(Uint8Array.from([t.byteLength|Ho]),t)}function vt(e){let t=new It,r=128;return(e.subarray()[0]&r)===r&&t.append(Uint8Array.from([0])),t.append(e),new It(Uint8Array.from([2]),zo(t),t)}function gn(e){let t=Uint8Array.from([0]),r=new It(t,e);return new It(Uint8Array.from([3]),zo(r),r)}function ge(e,t=48){let r=new It;for(let n of e)r.append(n);return new It(Uint8Array.from([t]),zo(r),r)}async function ia(e,t,r,n){let o=await crypto.subtle.importKey("jwk",e,{name:"ECDSA",namedCurve:e.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let i=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,t,r.subarray());return n?.signal?.throwIfAborted(),i}var zl=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Gl=Uint8Array.from([6,5,43,129,4,0,34]),Zl=Uint8Array.from([6,5,43,129,4,0,35]),jl={ext:!0,kty:"EC",crv:"P-256"},Yl={ext:!0,kty:"EC",crv:"P-384"},Wl={ext:!0,kty:"EC",crv:"P-521"},Go=32,Zo=48,jo=66;function Yo(e){let t=ne(e);return sa(t)}function sa(e){let t=e[1][1][0],r=1,n,o;if(t.byteLength===Go*2+1)return n=z(t.subarray(r,r+Go),"base64url"),o=z(t.subarray(r+Go),"base64url"),new We({...jl,key_ops:["verify"],x:n,y:o});if(t.byteLength===Zo*2+1)return n=z(t.subarray(r,r+Zo),"base64url"),o=z(t.subarray(r+Zo),"base64url"),new We({...Yl,key_ops:["verify"],x:n,y:o});if(t.byteLength===jo*2+1)return n=z(t.subarray(r,r+jo),"base64url"),o=z(t.subarray(r+jo),"base64url"),new We({...Wl,key_ops:["verify"],x:n,y:o});throw new ot(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function aa(e){return ge([vt(Uint8Array.from([1])),ge([Xl(e.crv)],160),ge([gn(new It(Uint8Array.from([4]),H(e.x??"","base64url"),H(e.y??"","base64url")))],161)]).subarray()}function Xl(e){if(e==="P-256")return zl;if(e==="P-384")return Gl;if(e==="P-521")return Zl;throw new ot(`Invalid curve ${e}`)}var We=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=aa(this.jwk)),this._raw}toMultihash(){return Vt.digest(Xe(this))}toCID(){return j.createV1(114,this.toMultihash())}toString(){return W.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:J(this.raw,t.raw)}async verify(t,r,n){return ia(this.jwk,r,t,n)}};function De(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function Wt(e,t=""){if(!Number.isSafeInteger(e)||e<0){let r=t&&`"${t}" `;throw new Error(`${r}expected integer >= 0, got ${e}`)}}function $(e,t,r=""){let n=De(e),o=e?.length,i=t!==void 0;if(!n||i&&o!==t){let s=r&&`"${r}" `,c=i?` of length ${t}`:"",a=n?`length=${o}`:`type=${typeof e}`;throw new Error(s+"expected Uint8Array"+c+", got "+a)}return e}function xn(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash must wrapped by utils.createHasher");Wt(e.outputLen),Wt(e.blockLen)}function Je(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function ua(e,t){$(e,void 0,"digestInto() output");let r=t.outputLen;if(e.length<r)throw new Error('"digestInto() output" expected to be of length >='+r)}function ie(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function bn(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function Mt(e,t){return e<<32-t|e>>>t}var fa=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Jl=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function se(e){if($(e),fa)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=Jl[e[r]];return t}var oe={_0:48,_9:57,A:65,F:70,a:97,f:102};function ca(e){if(e>=oe._0&&e<=oe._9)return e-oe._0;if(e>=oe.A&&e<=oe.F)return e-(oe.A-10);if(e>=oe.a&&e<=oe.f)return e-(oe.a-10)}function ae(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);if(fa)return Uint8Array.fromHex(e);let t=e.length,r=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(r);for(let o=0,i=0;o<r;o++,i+=2){let s=ca(e.charCodeAt(i)),c=ca(e.charCodeAt(i+1));if(s===void 0||c===void 0){let a=e[i]+e[i+1];throw new Error('hex string expected, got non-hex character "'+a+'" at index '+i)}n[o]=s*16+c}return n}function At(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];$(o),t+=o.length}let r=new Uint8Array(t);for(let n=0,o=0;n<e.length;n++){let i=e[n];r.set(i,o),o+=i.length}return r}function Wo(e,t={}){let r=(o,i)=>e(i).update(o).digest(),n=e(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.create=o=>e(o),Object.assign(r,t),Object.freeze(r)}function Qe(e=32){let t=typeof globalThis=="object"?globalThis.crypto:null;if(typeof t?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");return t.getRandomValues(new Uint8Array(e))}var Xo=e=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,e])});function la(e,t,r){return e&t^~e&r}function da(e,t,r){return e&t^e&r^t&r}var Rr=class{blockLen;outputLen;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(t,r,n,o){this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=bn(this.buffer)}update(t){Je(this),$(t);let{view:r,buffer:n,blockLen:o}=this,i=t.length;for(let s=0;s<i;){let c=Math.min(o-this.pos,i-s);if(c===o){let a=bn(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(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Je(this),ua(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:i}=this,{pos:s}=this;r[s++]=128,ie(this.buffer.subarray(s)),this.padOffset>o-s&&(this.process(n,0),s=0);for(let f=s;f<o;f++)r[f]=0;n.setBigUint64(o-8,BigInt(this.length*8),i),this.process(n,0);let c=bn(t),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen must 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:r}=this;this.digestInto(t);let n=t.slice(0,r);return this.destroy(),n}_cloneInto(t){t||=new this.constructor,t.set(...this.get());let{blockLen:r,buffer:n,length:o,finished:i,destroyed:s,pos:c}=this;return t.destroyed=s,t.finished=i,t.length=o,t.pos=c,o%r&&t.buffer.set(n),t}clone(){return this._cloneInto()}},ce=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var dt=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var wn=BigInt(4294967295),ha=BigInt(32);function Ql(e,t=!1){return t?{h:Number(e&wn),l:Number(e>>ha&wn)}:{h:Number(e>>ha&wn)|0,l:Number(e&wn)|0}}function pa(e,t=!1){let r=e.length,n=new Uint32Array(r),o=new Uint32Array(r);for(let i=0;i<r;i++){let{h:s,l:c}=Ql(e[i],t);[n[i],o[i]]=[s,c]}return[n,o]}var Jo=(e,t,r)=>e>>>r,Qo=(e,t,r)=>e<<32-r|t>>>r,Re=(e,t,r)=>e>>>r|t<<32-r,Le=(e,t,r)=>e<<32-r|t>>>r,Lr=(e,t,r)=>e<<64-r|t>>>r-32,Pr=(e,t,r)=>e>>>r-32|t<<64-r;function Xt(e,t,r,n){let o=(t>>>0)+(n>>>0);return{h:e+r+(o/2**32|0)|0,l:o|0}}var ma=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),ya=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,ga=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),xa=(e,t,r,n,o)=>t+r+n+o+(e/2**32|0)|0,ba=(e,t,r,n,o)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(o>>>0),wa=(e,t,r,n,o,i)=>t+r+n+o+i+(e/2**32|0)|0;var ed=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),xe=new Uint32Array(64),ti=class extends Rr{constructor(t){super(64,t,8,!1)}get(){let{A:t,B:r,C:n,D:o,E:i,F:s,G:c,H:a}=this;return[t,r,n,o,i,s,c,a]}set(t,r,n,o,i,s,c,a){this.A=t|0,this.B=r|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,r){for(let f=0;f<16;f++,r+=4)xe[f]=t.getUint32(r,!1);for(let f=16;f<64;f++){let y=xe[f-15],E=xe[f-2],b=Mt(y,7)^Mt(y,18)^y>>>3,I=Mt(E,17)^Mt(E,19)^E>>>10;xe[f]=I+xe[f-7]+b+xe[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 y=Mt(c,6)^Mt(c,11)^Mt(c,25),E=u+y+la(c,a,l)+ed[f]+xe[f]|0,I=(Mt(n,2)^Mt(n,13)^Mt(n,22))+da(n,o,i)|0;u=l,l=a,a=c,c=s+E|0,s=i,i=o,o=n,n=E+I|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(){ie(xe)}destroy(){this.set(0,0,0,0,0,0,0,0),ie(this.buffer)}},ei=class extends ti{A=ce[0]|0;B=ce[1]|0;C=ce[2]|0;D=ce[3]|0;E=ce[4]|0;F=ce[5]|0;G=ce[6]|0;H=ce[7]|0;constructor(){super(32)}};var Ea=pa(["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(e=>BigInt(e))),rd=Ea[0],nd=Ea[1],be=new Uint32Array(80),we=new Uint32Array(80),ri=class extends Rr{constructor(t){super(128,t,16,!1)}get(){let{Ah:t,Al:r,Bh:n,Bl:o,Ch:i,Cl:s,Dh:c,Dl:a,Eh:l,El:u,Fh:f,Fl:y,Gh:E,Gl:b,Hh:I,Hl:C}=this;return[t,r,n,o,i,s,c,a,l,u,f,y,E,b,I,C]}set(t,r,n,o,i,s,c,a,l,u,f,y,E,b,I,C){this.Ah=t|0,this.Al=r|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=y|0,this.Gh=E|0,this.Gl=b|0,this.Hh=I|0,this.Hl=C|0}process(t,r){for(let v=0;v<16;v++,r+=4)be[v]=t.getUint32(r),we[v]=t.getUint32(r+=4);for(let v=16;v<80;v++){let U=be[v-15]|0,k=we[v-15]|0,M=Re(U,k,1)^Re(U,k,8)^Jo(U,k,7),V=Le(U,k,1)^Le(U,k,8)^Qo(U,k,7),h=be[v-2]|0,p=we[v-2]|0,_=Re(h,p,19)^Lr(h,p,61)^Jo(h,p,6),D=Le(h,p,19)^Pr(h,p,61)^Qo(h,p,6),A=ga(V,D,we[v-7],we[v-16]),m=xa(A,M,_,be[v-7],be[v-16]);be[v]=m|0,we[v]=A|0}let{Ah:n,Al:o,Bh:i,Bl:s,Ch:c,Cl:a,Dh:l,Dl:u,Eh:f,El:y,Fh:E,Fl:b,Gh:I,Gl:C,Hh:w,Hl:T}=this;for(let v=0;v<80;v++){let U=Re(f,y,14)^Re(f,y,18)^Lr(f,y,41),k=Le(f,y,14)^Le(f,y,18)^Pr(f,y,41),M=f&E^~f&I,V=y&b^~y&C,h=ba(T,k,V,nd[v],we[v]),p=wa(h,w,U,M,rd[v],be[v]),_=h|0,D=Re(n,o,28)^Lr(n,o,34)^Lr(n,o,39),A=Le(n,o,28)^Pr(n,o,34)^Pr(n,o,39),m=n&i^n&c^i&c,g=o&s^o&a^s&a;w=I|0,T=C|0,I=E|0,C=b|0,E=f|0,b=y|0,{h:f,l:y}=Xt(l|0,u|0,p|0,_|0),l=c|0,u=a|0,c=i|0,a=s|0,i=n|0,s=o|0;let d=ma(_,A,g);n=ya(d,p,D,m),o=d|0}({h:n,l:o}=Xt(this.Ah|0,this.Al|0,n|0,o|0)),{h:i,l:s}=Xt(this.Bh|0,this.Bl|0,i|0,s|0),{h:c,l:a}=Xt(this.Ch|0,this.Cl|0,c|0,a|0),{h:l,l:u}=Xt(this.Dh|0,this.Dl|0,l|0,u|0),{h:f,l:y}=Xt(this.Eh|0,this.El|0,f|0,y|0),{h:E,l:b}=Xt(this.Fh|0,this.Fl|0,E|0,b|0),{h:I,l:C}=Xt(this.Gh|0,this.Gl|0,I|0,C|0),{h:w,l:T}=Xt(this.Hh|0,this.Hl|0,w|0,T|0),this.set(n,o,i,s,c,a,l,u,f,y,E,b,I,C,w,T)}roundClean(){ie(be,we)}destroy(){ie(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},ni=class extends ri{Ah=dt[0]|0;Al=dt[1]|0;Bh=dt[2]|0;Bl=dt[3]|0;Ch=dt[4]|0;Cl=dt[5]|0;Dh=dt[6]|0;Dl=dt[7]|0;Eh=dt[8]|0;El=dt[9]|0;Fh=dt[10]|0;Fl=dt[11]|0;Gh=dt[12]|0;Gl=dt[13]|0;Hh=dt[14]|0;Hl=dt[15]|0;constructor(){super(64)}};var tr=Wo(()=>new ei,Xo(1));var Sa=Wo(()=>new ni,Xo(3));var ii=BigInt(0),oi=BigInt(1);function ue(e,t=""){if(typeof e!="boolean"){let r=t&&`"${t}" `;throw new Error(r+"expected boolean, got type="+typeof e)}return e}function va(e){if(typeof e=="bigint"){if(!En(e))throw new Error("positive bigint expected, got "+e)}else Wt(e);return e}function Ur(e){let t=va(e).toString(16);return t.length&1?"0"+t:t}function Aa(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return e===""?ii:BigInt("0x"+e)}function er(e){return Aa(se(e))}function Pe(e){return Aa(se(vn($(e)).reverse()))}function Sn(e,t){Wt(t),e=va(e);let r=ae(e.toString(16).padStart(t*2,"0"));if(r.length!==t)throw new Error("number too large");return r}function si(e,t){return Sn(e,t).reverse()}function vn(e){return Uint8Array.from(e)}var En=e=>typeof e=="bigint"&&ii<=e;function od(e,t,r){return En(e)&&En(t)&&En(r)&&t<=e&&e<r}function Nr(e,t,r,n){if(!od(t,r,n))throw new Error("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function ai(e){let t;for(t=0;e>ii;e>>=oi,t+=1);return t}var Or=e=>(oi<<BigInt(e))-oi;function Ca(e,t,r){if(Wt(e,"hashLen"),Wt(t,"qByteLen"),typeof r!="function")throw new Error("hmacFn must be a function");let n=C=>new Uint8Array(C),o=Uint8Array.of(),i=Uint8Array.of(0),s=Uint8Array.of(1),c=1e3,a=n(e),l=n(e),u=0,f=()=>{a.fill(1),l.fill(0),u=0},y=(...C)=>r(l,At(a,...C)),E=(C=o)=>{l=y(i,C),a=y(),C.length!==0&&(l=y(s,C),a=y())},b=()=>{if(u++>=c)throw new Error("drbg: tried max amount of iterations");let C=0,w=[];for(;C<t;){a=y();let T=a.slice();w.push(T),C+=a.length}return At(...w)};return(C,w)=>{f(),E(C);let T;for(;!(T=w(b()));)E();return f(),T}}function Ee(e,t={},r={}){if(!e||typeof e!="object")throw new Error("expected valid options object");function n(i,s,c){let a=e[i];if(c&&a===void 0)return;let l=typeof a;if(l!==s||a===null)throw new Error(`param "${i}" is invalid: expected ${s}, got ${l}`)}let o=(i,s)=>Object.entries(i).forEach(([c,a])=>n(c,a,s));o(t,!1),o(r,!0)}function rr(e){let t=new WeakMap;return(r,...n)=>{let o=t.get(r);if(o!==void 0)return o;let i=e(r,...n);return t.set(r,i),i}}var wt=BigInt(0),at=BigInt(1),Ue=BigInt(2),Ba=BigInt(3),_a=BigInt(4),Da=BigInt(5),id=BigInt(7),Ra=BigInt(8),sd=BigInt(9),La=BigInt(16);function it(e,t){let r=e%t;return r>=wt?r:t+r}function X(e,t,r){let n=e;for(;t-- >wt;)n*=n,n%=r;return n}function Ia(e,t){if(e===wt)throw new Error("invert: expected non-zero number");if(t<=wt)throw new Error("invert: expected positive modulus, got "+t);let r=it(e,t),n=t,o=wt,i=at,s=at,c=wt;for(;r!==wt;){let l=n/r,u=n%r,f=o-s*l,y=i-c*l;n=r,r=u,o=s,i=c,s=f,c=y}if(n!==at)throw new Error("invert: does not exist");return it(o,t)}function ui(e,t,r){if(!e.eql(e.sqr(t),r))throw new Error("Cannot find square root")}function Pa(e,t){let r=(e.ORDER+at)/_a,n=e.pow(t,r);return ui(e,n,t),n}function ad(e,t){let r=(e.ORDER-Da)/Ra,n=e.mul(t,Ue),o=e.pow(n,r),i=e.mul(t,o),s=e.mul(e.mul(i,Ue),o),c=e.mul(i,e.sub(s,e.ONE));return ui(e,c,t),c}function cd(e){let t=nr(e),r=Ua(e),n=r(t,t.neg(t.ONE)),o=r(t,n),i=r(t,t.neg(n)),s=(e+id)/La;return(c,a)=>{let l=c.pow(a,s),u=c.mul(l,n),f=c.mul(l,o),y=c.mul(l,i),E=c.eql(c.sqr(u),a),b=c.eql(c.sqr(f),a);l=c.cmov(l,u,E),u=c.cmov(y,f,b);let I=c.eql(c.sqr(u),a),C=c.cmov(l,u,I);return ui(c,C,a),C}}function Ua(e){if(e<Ba)throw new Error("sqrt is not defined for small field");let t=e-at,r=0;for(;t%Ue===wt;)t/=Ue,r++;let n=Ue,o=nr(e);for(;Ta(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return Pa;let i=o.pow(n,t),s=(t+at)/Ue;return function(a,l){if(a.is0(l))return l;if(Ta(a,l)!==1)throw new Error("Cannot find square root");let u=r,f=a.mul(a.ONE,i),y=a.pow(l,t),E=a.pow(l,s);for(;!a.eql(y,a.ONE);){if(a.is0(y))return a.ZERO;let b=1,I=a.sqr(y);for(;!a.eql(I,a.ONE);)if(b++,I=a.sqr(I),b===u)throw new Error("Cannot find square root");let C=at<<BigInt(u-b-1),w=a.pow(f,C);u=b,f=a.sqr(w),y=a.mul(y,f),E=a.mul(E,w)}return E}}function ud(e){return e%_a===Ba?Pa:e%Ra===Da?ad:e%La===sd?cd(e):Ua(e)}var Na=(e,t)=>(it(e,t)&at)===at,fd=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function fi(e){let t={ORDER:"bigint",BYTES:"number",BITS:"number"},r=fd.reduce((n,o)=>(n[o]="function",n),t);return Ee(e,r),e}function ld(e,t,r){if(r<wt)throw new Error("invalid exponent, negatives unsupported");if(r===wt)return e.ONE;if(r===at)return t;let n=e.ONE,o=t;for(;r>wt;)r&at&&(n=e.mul(n,o)),o=e.sqr(o),r>>=at;return n}function kr(e,t,r=!1){let n=new Array(t.length).fill(r?e.ZERO:void 0),o=t.reduce((s,c,a)=>e.is0(c)?s:(n[a]=s,e.mul(s,c)),e.ONE),i=e.inv(o);return t.reduceRight((s,c,a)=>e.is0(c)?s:(n[a]=e.mul(s,n[a]),e.mul(s,c)),i),n}function Ta(e,t){let r=(e.ORDER-at)/Ue,n=e.pow(t,r),o=e.eql(n,e.ONE),i=e.eql(n,e.ZERO),s=e.eql(n,e.neg(e.ONE));if(!o&&!i&&!s)throw new Error("invalid Legendre symbol result");return o?1:i?0:-1}function dd(e,t){t!==void 0&&Wt(t);let r=t!==void 0?t:e.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}var ci=class{ORDER;BITS;BYTES;isLE;ZERO=wt;ONE=at;_lengths;_sqrt;_mod;constructor(t,r={}){if(t<=wt)throw new Error("invalid field: expected ORDER > 0, got "+t);let n;this.isLE=!1,r!=null&&typeof r=="object"&&(typeof r.BITS=="number"&&(n=r.BITS),typeof r.sqrt=="function"&&(this.sqrt=r.sqrt),typeof r.isLE=="boolean"&&(this.isLE=r.isLE),r.allowedLengths&&(this._lengths=r.allowedLengths?.slice()),typeof r.modFromBytes=="boolean"&&(this._mod=r.modFromBytes));let{nBitLength:o,nByteLength:i}=dd(t,n);if(i>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=t,this.BITS=o,this.BYTES=i,this._sqrt=void 0,Object.preventExtensions(this)}create(t){return it(t,this.ORDER)}isValid(t){if(typeof t!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof t);return wt<=t&&t<this.ORDER}is0(t){return t===wt}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}isOdd(t){return(t&at)===at}neg(t){return it(-t,this.ORDER)}eql(t,r){return t===r}sqr(t){return it(t*t,this.ORDER)}add(t,r){return it(t+r,this.ORDER)}sub(t,r){return it(t-r,this.ORDER)}mul(t,r){return it(t*r,this.ORDER)}pow(t,r){return ld(this,t,r)}div(t,r){return it(t*Ia(r,this.ORDER),this.ORDER)}sqrN(t){return t*t}addN(t,r){return t+r}subN(t,r){return t-r}mulN(t,r){return t*r}inv(t){return Ia(t,this.ORDER)}sqrt(t){return this._sqrt||(this._sqrt=ud(this.ORDER)),this._sqrt(this,t)}toBytes(t){return this.isLE?si(t,this.BYTES):Sn(t,this.BYTES)}fromBytes(t,r=!1){$(t);let{_lengths:n,BYTES:o,isLE:i,ORDER:s,_mod:c}=this;if(n){if(!n.includes(t.length)||t.length>o)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+t.length);let l=new Uint8Array(o);l.set(t,i?0:l.length-t.length),t=l}if(t.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+t.length);let a=i?Pe(t):er(t);if(c&&(a=it(a,s)),!r&&!this.isValid(a))throw new Error("invalid field element: outside of range 0..ORDER");return a}invertBatch(t){return kr(this,t)}cmov(t,r,n){return n?r:t}};function nr(e,t={}){return new ci(e,t)}function Oa(e){if(typeof e!="bigint")throw new Error("field order must be bigint");let t=e.toString(2).length;return Math.ceil(t/8)}function li(e){let t=Oa(e);return t+Math.ceil(t/2)}function di(e,t,r=!1){$(e);let n=e.length,o=Oa(t),i=li(t);if(n<16||n<i||n>1024)throw new Error("expected "+i+"-1024 bytes of input, got "+n);let s=r?Pe(e):er(e),c=it(s,t-at)+at;return r?si(c,o):Sn(c,o)}var or=BigInt(0),Ne=BigInt(1);function Kr(e,t){let r=t.negate();return e?r:t}function Oe(e,t){let r=kr(e.Fp,t.map(n=>n.Z));return t.map((n,o)=>e.fromAffine(n.toAffine(r[o])))}function Ma(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function hi(e,t){Ma(e,t);let r=Math.ceil(t/e)+1,n=2**(e-1),o=2**e,i=Or(e),s=BigInt(e);return{windows:r,windowSize:n,mask:i,maxNumber:o,shiftBy:s}}function ka(e,t,r){let{windowSize:n,mask:o,maxNumber:i,shiftBy:s}=r,c=Number(e&o),a=e>>s;c>n&&(c-=i,a+=Ne);let l=t*n,u=l+Math.abs(c)-1,f=c===0,y=c<0,E=t%2!==0;return{nextN:a,offset:u,isZero:f,isNeg:y,isNegF:E,offsetF:l}}var pi=new WeakMap,Fa=new WeakMap;function mi(e){return Fa.get(e)||1}function Ka(e){if(e!==or)throw new Error("invalid wNAF")}var ir=class{BASE;ZERO;Fn;bits;constructor(t,r){this.BASE=t.BASE,this.ZERO=t.ZERO,this.Fn=t.Fn,this.bits=r}_unsafeLadder(t,r,n=this.ZERO){let o=t;for(;r>or;)r&Ne&&(n=n.add(o)),o=o.double(),r>>=Ne;return n}precomputeWindow(t,r){let{windows:n,windowSize:o}=hi(r,this.bits),i=[],s=t,c=s;for(let a=0;a<n;a++){c=s,i.push(c);for(let l=1;l<o;l++)c=c.add(s),i.push(c);s=c.double()}return i}wNAF(t,r,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let o=this.ZERO,i=this.BASE,s=hi(t,this.bits);for(let c=0;c<s.windows;c++){let{nextN:a,offset:l,isZero:u,isNeg:f,isNegF:y,offsetF:E}=ka(n,c,s);n=a,u?i=i.add(Kr(y,r[E])):o=o.add(Kr(f,r[l]))}return Ka(n),{p:o,f:i}}wNAFUnsafe(t,r,n,o=this.ZERO){let i=hi(t,this.bits);for(let s=0;s<i.windows&&n!==or;s++){let{nextN:c,offset:a,isZero:l,isNeg:u}=ka(n,s,i);if(n=c,!l){let f=r[a];o=o.add(u?f.negate():f)}}return Ka(n),o}getPrecomputes(t,r,n){let o=pi.get(r);return o||(o=this.precomputeWindow(r,t),t!==1&&(typeof n=="function"&&(o=n(o)),pi.set(r,o))),o}cached(t,r,n){let o=mi(t);return this.wNAF(o,this.getPrecomputes(o,t,n),r)}unsafe(t,r,n,o){let i=mi(t);return i===1?this._unsafeLadder(t,r,o):this.wNAFUnsafe(i,this.getPrecomputes(i,t,n),r,o)}createCache(t,r){Ma(r,this.bits),Fa.set(t,r),pi.delete(t)}hasCache(t){return mi(t)!==1}};function qa(e,t,r,n){let o=t,i=e.ZERO,s=e.ZERO;for(;r>or||n>or;)r&Ne&&(i=i.add(o)),n&Ne&&(s=s.add(o)),o=o.double(),r>>=Ne,n>>=Ne;return{p1:i,p2:s}}function Va(e,t,r){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return fi(t),t}else return nr(e,{isLE:r})}function An(e,t,r={},n){if(n===void 0&&(n=e==="edwards"),!t||typeof t!="object")throw new Error(`expected valid ${e} CURVE object`);for(let a of["p","n","h"]){let l=t[a];if(!(typeof l=="bigint"&&l>or))throw new Error(`CURVE.${a} must be positive bigint`)}let o=Va(t.p,r.Fp,n),i=Va(t.n,r.Fn,n),c=["Gx","Gy","a",e==="weierstrass"?"b":"d"];for(let a of c)if(!o.isValid(t[a]))throw new Error(`CURVE.${a} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:o,Fn:i}}function Cn(e,t){return function(n){let o=e(n);return{secretKey:o,publicKey:t(o)}}}var Se=BigInt(0),ct=BigInt(1),yi=BigInt(2),hd=BigInt(8);function pd(e,t,r,n){let o=e.sqr(r),i=e.sqr(n),s=e.add(e.mul(t.a,o),i),c=e.add(e.ONE,e.mul(t.d,e.mul(o,i)));return e.eql(s,c)}function $a(e,t={}){let r=An("edwards",e,t,t.FpFnLE),{Fp:n,Fn:o}=r,i=r.CURVE,{h:s}=i;Ee(t,{},{uvRatio:"function"});let c=yi<<BigInt(o.BYTES*8)-ct,a=C=>n.create(C),l=t.uvRatio||((C,w)=>{try{return{isValid:!0,value:n.sqrt(n.div(C,w))}}catch{return{isValid:!1,value:Se}}});if(!pd(n,i,i.Gx,i.Gy))throw new Error("bad curve params: generator point");function u(C,w,T=!1){let v=T?ct:Se;return Nr("coordinate "+C,w,v,c),w}function f(C){if(!(C instanceof b))throw new Error("EdwardsPoint expected")}let y=rr((C,w)=>{let{X:T,Y:v,Z:U}=C,k=C.is0();w==null&&(w=k?hd:n.inv(U));let M=a(T*w),V=a(v*w),h=n.mul(U,w);if(k)return{x:Se,y:ct};if(h!==ct)throw new Error("invZ was invalid");return{x:M,y:V}}),E=rr(C=>{let{a:w,d:T}=i;if(C.is0())throw new Error("bad point: ZERO");let{X:v,Y:U,Z:k,T:M}=C,V=a(v*v),h=a(U*U),p=a(k*k),_=a(p*p),D=a(V*w),A=a(p*a(D+h)),m=a(_+a(T*a(V*h)));if(A!==m)throw new Error("bad point: equation left != right (1)");let g=a(v*U),d=a(k*M);if(g!==d)throw new Error("bad point: equation left != right (2)");return!0});class b{static BASE=new b(i.Gx,i.Gy,ct,a(i.Gx*i.Gy));static ZERO=new b(Se,ct,ct,Se);static Fp=n;static Fn=o;X;Y;Z;T;constructor(w,T,v,U){this.X=u("x",w),this.Y=u("y",T),this.Z=u("z",v,!0),this.T=u("t",U),Object.freeze(this)}static CURVE(){return i}static fromAffine(w){if(w instanceof b)throw new Error("extended point not allowed");let{x:T,y:v}=w||{};return u("x",T),u("y",v),new b(T,v,ct,a(T*v))}static fromBytes(w,T=!1){let v=n.BYTES,{a:U,d:k}=i;w=vn($(w,v,"point")),ue(T,"zip215");let M=vn(w),V=w[v-1];M[v-1]=V&-129;let h=Pe(M),p=T?c:n.ORDER;Nr("point.y",h,Se,p);let _=a(h*h),D=a(_-ct),A=a(k*_-U),{isValid:m,value:g}=l(D,A);if(!m)throw new Error("bad point: invalid y coordinate");let d=(g&ct)===ct,S=(V&128)!==0;if(!T&&g===Se&&S)throw new Error("bad point: x=0 and x_0=1");return S!==d&&(g=a(-g)),b.fromAffine({x:g,y:h})}static fromHex(w,T=!1){return b.fromBytes(ae(w),T)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(w=8,T=!0){return I.createCache(this,w),T||this.multiply(yi),this}assertValidity(){E(this)}equals(w){f(w);let{X:T,Y:v,Z:U}=this,{X:k,Y:M,Z:V}=w,h=a(T*V),p=a(k*U),_=a(v*V),D=a(M*U);return h===p&&_===D}is0(){return this.equals(b.ZERO)}negate(){return new b(a(-this.X),this.Y,this.Z,a(-this.T))}double(){let{a:w}=i,{X:T,Y:v,Z:U}=this,k=a(T*T),M=a(v*v),V=a(yi*a(U*U)),h=a(w*k),p=T+v,_=a(a(p*p)-k-M),D=h+M,A=D-V,m=h-M,g=a(_*A),d=a(D*m),S=a(_*m),R=a(A*D);return new b(g,d,R,S)}add(w){f(w);let{a:T,d:v}=i,{X:U,Y:k,Z:M,T:V}=this,{X:h,Y:p,Z:_,T:D}=w,A=a(U*h),m=a(k*p),g=a(V*v*D),d=a(M*_),S=a((U+k)*(h+p)-A-m),R=d-g,P=d+g,N=a(m-T*A),O=a(S*R),K=a(P*N),q=a(S*N),tt=a(R*P);return new b(O,K,tt,q)}subtract(w){return this.add(w.negate())}multiply(w){if(!o.isValidNot0(w))throw new Error("invalid scalar: expected 1 <= sc < curve.n");let{p:T,f:v}=I.cached(this,w,U=>Oe(b,U));return Oe(b,[T,v])[0]}multiplyUnsafe(w,T=b.ZERO){if(!o.isValid(w))throw new Error("invalid scalar: expected 0 <= sc < curve.n");return w===Se?b.ZERO:this.is0()||w===ct?this:I.unsafe(this,w,v=>Oe(b,v),T)}isSmallOrder(){return this.multiplyUnsafe(s).is0()}isTorsionFree(){return I.unsafe(this,i.n).is0()}toAffine(w){return y(this,w)}clearCofactor(){return s===ct?this:this.multiplyUnsafe(s)}toBytes(){let{x:w,y:T}=this.toAffine(),v=n.toBytes(T);return v[v.length-1]|=w&ct?128:0,v}toHex(){return se(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let I=new ir(b,o.BITS);return b.BASE.precompute(8),b}function Ha(e,t,r={}){if(typeof t!="function")throw new Error('"hash" function param is required');Ee(r,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:n}=r,{BASE:o,Fp:i,Fn:s}=e,c=r.randomBytes||Qe,a=r.adjustScalarBytes||(h=>h),l=r.domain||((h,p,_)=>{if(ue(_,"phflag"),p.length||_)throw new Error("Contexts/pre-hash are not supported");return h});function u(h){return s.create(Pe(h))}function f(h){let p=v.secretKey;$(h,v.secretKey,"secretKey");let _=$(t(h),2*p,"hashedSecretKey"),D=a(_.slice(0,p)),A=_.slice(p,2*p),m=u(D);return{head:D,prefix:A,scalar:m}}function y(h){let{head:p,prefix:_,scalar:D}=f(h),A=o.multiply(D),m=A.toBytes();return{head:p,prefix:_,scalar:D,point:A,pointBytes:m}}function E(h){return y(h).pointBytes}function b(h=Uint8Array.of(),...p){let _=At(...p);return u(t(l(_,$(h,void 0,"context"),!!n)))}function I(h,p,_={}){h=$(h,void 0,"message"),n&&(h=n(h));let{prefix:D,scalar:A,pointBytes:m}=y(p),g=b(_.context,D,h),d=o.multiply(g).toBytes(),S=b(_.context,d,m,h),R=s.create(g+S*A);if(!s.isValid(R))throw new Error("sign failed: invalid s");let P=At(d,s.toBytes(R));return $(P,v.signature,"result")}let C={zip215:!0};function w(h,p,_,D=C){let{context:A,zip215:m}=D,g=v.signature;h=$(h,g,"signature"),p=$(p,void 0,"message"),_=$(_,v.publicKey,"publicKey"),m!==void 0&&ue(m,"zip215"),n&&(p=n(p));let d=g/2,S=h.subarray(0,d),R=Pe(h.subarray(d,g)),P,N,O;try{P=e.fromBytes(_,m),N=e.fromBytes(S,m),O=o.multiplyUnsafe(R)}catch{return!1}if(!m&&P.isSmallOrder())return!1;let K=b(A,N.toBytes(),P.toBytes(),p);return N.add(P.multiplyUnsafe(K)).subtract(O).clearCofactor().is0()}let T=i.BYTES,v={secretKey:T,publicKey:T,signature:2*T,seed:T};function U(h=c(v.seed)){return $(h,v.seed,"seed")}function k(h){return De(h)&&h.length===s.BYTES}function M(h,p){try{return!!e.fromBytes(h,p)}catch{return!1}}let V={getExtendedPublicKey:y,randomSecretKey:U,isValidSecretKey:k,isValidPublicKey:M,toMontgomery(h){let{y:p}=e.fromBytes(h),_=v.publicKey,D=_===32;if(!D&&_!==57)throw new Error("only defined for 25519 and 448");let A=D?i.div(ct+p,ct-p):i.div(p-ct,p+ct);return i.toBytes(A)},toMontgomerySecret(h){let p=v.secretKey;$(h,p);let _=t(h.subarray(0,p));return a(_).subarray(0,p)}};return Object.freeze({keygen:Cn(U,E),getPublicKey:E,sign:I,verify:w,utils:V,Point:e,lengths:v})}var md=BigInt(1),za=BigInt(2);var yd=BigInt(5),gd=BigInt(8),gi=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),xd={p:gi,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:gd,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function bd(e){let t=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),i=gi,c=e*e%i*e%i,a=X(c,za,i)*c%i,l=X(a,md,i)*e%i,u=X(l,yd,i)*l%i,f=X(u,t,i)*u%i,y=X(f,r,i)*f%i,E=X(y,n,i)*y%i,b=X(E,o,i)*E%i,I=X(b,o,i)*E%i,C=X(I,t,i)*u%i;return{pow_p_5_8:X(C,za,i)*e%i,b2:c}}function wd(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}var Ga=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function Ed(e,t){let r=gi,n=it(t*t*t,r),o=it(n*n*t,r),i=bd(e*o).pow_p_5_8,s=it(e*n*i,r),c=it(t*s*s,r),a=s,l=it(s*Ga,r),u=c===e,f=c===it(-e,r),y=c===it(-e*Ga,r);return u&&(s=a),(f||y)&&(s=l),Na(s,r)&&(s=it(-s,r)),{isValid:u||f,value:s}}var Sd=$a(xd,{uvRatio:Ed});function vd(e){return Ha(Sd,Sa,Object.assign({adjustScalarBytes:wd},e))}var Za=vd({});var Vr=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},In=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var ja={get(e=globalThis){let t=e.crypto;if(t?.subtle==null)throw new In("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api");return t}};var Pt=ja;var Tn=32;var xi,Ad=(async()=>{try{return await Pt.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function Cd(e,t,r){if(e.buffer instanceof ArrayBuffer){let n=await Pt.get().subtle.importKey("raw",e.buffer,{name:"Ed25519"},!1,["verify"]);return await Pt.get().subtle.verify({name:"Ed25519"},n,t,r instanceof Uint8Array?r:r.subarray())}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function Id(e,t,r){return Za.verify(t,r instanceof Uint8Array?r:r.subarray(),e)}async function Ya(e,t,r){return xi==null&&(xi=await Ad),xi?Cd(e,t,r):Id(e,t,r)}function Bn(e){return e==null?!1:typeof e.then=="function"&&typeof e.catch=="function"&&typeof e.finally=="function"}var _n=class{type="Ed25519";raw;constructor(t){this.raw=bi(t,Tn)}toMultihash(){return Vt.digest(Xe(this))}toCID(){return j.createV1(114,this.toMultihash())}toString(){return W.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:J(this.raw,t.raw)}verify(t,r,n){n?.signal?.throwIfAborted();let o=Ya(this.raw,r,t);return Bn(o)?o.then(i=>(n?.signal?.throwIfAborted(),i)):o}};function wi(e){return e=bi(e,Tn),new _n(e)}function bi(e,t){if(e=Uint8Array.from(e??[]),e.length!==t)throw new ot(`Key must be a Uint8Array of length ${t}, got ${e.length}`);return e}var Bd=Math.pow(2,7),_d=Math.pow(2,14),Dd=Math.pow(2,21),Ei=Math.pow(2,28),Si=Math.pow(2,35),vi=Math.pow(2,42),Ai=Math.pow(2,49),Q=128,yt=127;function Jt(e){if(e<Bd)return 1;if(e<_d)return 2;if(e<Dd)return 3;if(e<Ei)return 4;if(e<Si)return 5;if(e<vi)return 6;if(e<Ai)return 7;if(Number.MAX_SAFE_INTEGER!=null&&e>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Mr(e,t,r=0){switch(Jt(e)){case 8:t[r++]=e&255|Q,e/=128;case 7:t[r++]=e&255|Q,e/=128;case 6:t[r++]=e&255|Q,e/=128;case 5:t[r++]=e&255|Q,e/=128;case 4:t[r++]=e&255|Q,e>>>=7;case 3:t[r++]=e&255|Q,e>>>=7;case 2:t[r++]=e&255|Q,e>>>=7;case 1:{t[r++]=e&255,e>>>=7;break}default:throw new Error("unreachable")}return t}function Ci(e,t){let r=e[t],n=0;if(n+=r&yt,r<Q||(r=e[t+1],n+=(r&yt)<<7,r<Q)||(r=e[t+2],n+=(r&yt)<<14,r<Q)||(r=e[t+3],n+=(r&yt)<<21,r<Q)||(r=e[t+4],n+=(r&yt)*Ei,r<Q)||(r=e[t+5],n+=(r&yt)*Si,r<Q)||(r=e[t+6],n+=(r&yt)*vi,r<Q)||(r=e[t+7],n+=(r&yt)*Ai,r<Q))return n;throw new RangeError("Could not decode varint")}function Rd(e,t){let r=e.get(t),n=0;if(n+=r&yt,r<Q||(r=e.get(t+1),n+=(r&yt)<<7,r<Q)||(r=e.get(t+2),n+=(r&yt)<<14,r<Q)||(r=e.get(t+3),n+=(r&yt)<<21,r<Q)||(r=e.get(t+4),n+=(r&yt)*Ei,r<Q)||(r=e.get(t+5),n+=(r&yt)*Si,r<Q)||(r=e.get(t+6),n+=(r&yt)*vi,r<Q)||(r=e.get(t+7),n+=(r&yt)*Ai,r<Q))return n;throw new RangeError("Could not decode varint")}function Ii(e,t=0){return e instanceof Uint8Array?Ci(e,t):Rd(e,t)}var Ti=new Float32Array([-0]),ve=new Uint8Array(Ti.buffer);function Xa(e,t,r){Ti[0]=e,t[r]=ve[0],t[r+1]=ve[1],t[r+2]=ve[2],t[r+3]=ve[3]}function Ja(e,t){return ve[0]=e[t],ve[1]=e[t+1],ve[2]=e[t+2],ve[3]=e[t+3],Ti[0]}var Bi=new Float64Array([-0]),gt=new Uint8Array(Bi.buffer);function Qa(e,t,r){Bi[0]=e,t[r]=gt[0],t[r+1]=gt[1],t[r+2]=gt[2],t[r+3]=gt[3],t[r+4]=gt[4],t[r+5]=gt[5],t[r+6]=gt[6],t[r+7]=gt[7]}function tc(e,t){return gt[0]=e[t],gt[1]=e[t+1],gt[2]=e[t+2],gt[3]=e[t+3],gt[4]=e[t+4],gt[5]=e[t+5],gt[6]=e[t+6],gt[7]=e[t+7],Bi[0]}var Pd=BigInt(Number.MAX_SAFE_INTEGER),Ud=BigInt(Number.MIN_SAFE_INTEGER),Tt=class e{lo;hi;constructor(t,r){this.lo=t|0,this.hi=r|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(r+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(BigInt(r)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(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,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?t<16384?t<128?1:2:t<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return ke;if(t<Pd&&t>Ud)return this.fromNumber(Number(t));let r=t<0n;r&&(t=-t);let n=t>>32n,o=t-(n<<32n);return r&&(n=~n|0n,o=~o|0n,++o>ec&&(o=0n,++n>ec&&(n=0n))),new e(Number(o),Number(n))}static fromNumber(t){if(t===0)return ke;let r=t<0;r&&(t=-t);let n=t>>>0,o=(t-n)/4294967296>>>0;return r&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new e(n,o)}static from(t){return typeof t=="number"?e.fromNumber(t):typeof t=="bigint"?e.fromBigInt(t):typeof t=="string"?e.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new e(t.low>>>0,t.high>>>0):ke}},ke=new Tt(0,0);ke.toBigInt=function(){return 0n};ke.zzEncode=ke.zzDecode=function(){return this};ke.length=function(){return 1};var ec=4294967296n;function rc(e){let t=0,r=0;for(let n=0;n<e.length;++n)r=e.charCodeAt(n),r<128?t+=1:r<2048?t+=2:(r&64512)===55296&&(e.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function nc(e,t,r){if(r-t<1)return"";let o,i=[],s=0,c;for(;t<r;)c=e[t++],c<128?i[s++]=c:c>191&&c<224?i[s++]=(c&31)<<6|e[t++]&63:c>239&&c<365?(c=((c&7)<<18|(e[t++]&63)<<12|(e[t++]&63)<<6|e[t++]&63)-65536,i[s++]=55296+(c>>10),i[s++]=56320+(c&1023)):i[s++]=(c&15)<<12|(e[t++]&63)<<6|e[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 _i(e,t,r){let n=r,o,i;for(let s=0;s<e.length;++s)o=e.charCodeAt(s),o<128?t[r++]=o:o<2048?(t[r++]=o>>6|192,t[r++]=o&63|128):(o&64512)===55296&&((i=e.charCodeAt(s+1))&64512)===56320?(o=65536+((o&1023)<<10)+(i&1023),++s,t[r++]=o>>18|240,t[r++]=o>>12&63|128,t[r++]=o>>6&63|128,t[r++]=o&63|128):(t[r++]=o>>12|224,t[r++]=o>>6&63|128,t[r++]=o&63|128);return r-n}function Ft(e,t){return RangeError(`index out of range: ${e.pos} + ${t??1} > ${e.len}`)}function Dn(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[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,Ft(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 Ft(this,4);return Dn(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Ft(this,4);return Dn(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Ft(this,4);let t=Ja(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Ft(this,4);let t=tc(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),r=this.pos,n=this.pos+t;if(n>this.len)throw Ft(this,t);return this.pos+=t,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let t=this.bytes();return nc(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Ft(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Ft(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 Tt(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*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;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw Ft(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<r*7)>>>0,t}if(this.len-this.pos>4){for(;r<5;++r)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;r<5;++r){if(this.pos>=this.len)throw Ft(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Ft(this,8);let t=Dn(this.buf,this.pos+=4),r=Dn(this.buf,this.pos+=4);return new Tt(t,r)}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+=Jt(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 Ri(e){return new Di(e instanceof Uint8Array?e:e.subarray())}function sr(e,t,r){let n=Ri(e);return t.decode(n,void 0,r)}function Li(e){let t=e??8192,r=t>>>1,n,o=t;return function(s){if(s<1||s>r)return Ct(s);o+s>t&&(n=Ct(t),o=0);let c=n.subarray(o,o+=s);return(o&7)!==0&&(o=(o|7)+1),c}}var Ke=class{fn;len;next;val;constructor(t,r,n){this.fn=t,this.len=r,this.next=void 0,this.val=n}};function Pi(){}var Ni=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Nd=Li();function Od(e){return globalThis.Buffer!=null?Ct(e):Nd(e)}var qr=class{len;head;tail;states;constructor(){this.len=0,this.head=new Ke(Pi,0,0),this.tail=this.head,this.states=null}_push(t,r,n){return this.tail=this.tail.next=new Ke(t,r,n),this.len+=r,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Oi((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(Rn,10,Tt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let r=Tt.fromBigInt(t);return this._push(Rn,r.length(),r)}uint64Number(t){return this._push(Mr,Jt(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 r=Tt.fromBigInt(t).zzEncode();return this._push(Rn,r.length(),r)}sint64Number(t){let r=Tt.fromNumber(t).zzEncode();return this._push(Rn,r.length(),r)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Ui,1,t?1:0)}fixed32(t){return this._push(Fr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let r=Tt.fromBigInt(t);return this._push(Fr,4,r.lo)._push(Fr,4,r.hi)}fixed64Number(t){let r=Tt.fromNumber(t);return this._push(Fr,4,r.lo)._push(Fr,4,r.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(Xa,4,t)}double(t){return this._push(Qa,8,t)}bytes(t){let r=t.length>>>0;return r===0?this._push(Ui,1,0):this.uint32(r)._push(Kd,r,t)}string(t){let r=rc(t);return r!==0?this.uint32(r)._push(_i,r,t):this._push(Ui,1,0)}fork(){return this.states=new Ni(this),this.head=this.tail=new Ke(Pi,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 Ke(Pi,0,0),this.len=0),this}ldelim(){let t=this.head,r=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=r,this.len+=n),this}finish(){let t=this.head.next,r=Od(this.len),n=0;for(;t!=null;)t.fn(t.val,r,n),n+=t.len,t=t.next;return r}};function Ui(e,t,r){t[r]=e&255}function kd(e,t,r){for(;e>127;)t[r++]=e&127|128,e>>>=7;t[r]=e}var Oi=class extends Ke{next;constructor(t,r){super(kd,t,r),this.next=void 0}};function Rn(e,t,r){for(;e.hi!==0;)t[r++]=e.lo&127|128,e.lo=(e.lo>>>7|e.hi<<25)>>>0,e.hi>>>=7;for(;e.lo>127;)t[r++]=e.lo&127|128,e.lo=e.lo>>>7;t[r++]=e.lo}function Fr(e,t,r){t[r]=e&255,t[r+1]=e>>>8&255,t[r+2]=e>>>16&255,t[r+3]=e>>>24}function Kd(e,t,r){t.set(e,r)}globalThis.Buffer!=null&&(qr.prototype.bytes=function(e){let t=e.length>>>0;return this.uint32(t),t>0&&this._push(Vd,t,e),this},qr.prototype.string=function(e){let t=globalThis.Buffer.byteLength(e);return this.uint32(t),t>0&&this._push(Md,t,e),this});function Vd(e,t,r){t.set(e,r)}function Md(e,t,r){e.length<40?_i(e,t,r):t.utf8Write!=null?t.utf8Write(e,r):t.set(H(e),r)}function ki(){return new qr}function ar(e,t){let r=ki();return t.encode(e,r,{lengthDelimited:!1}),r.finish()}var cr;(function(e){e[e.VARINT=0]="VARINT",e[e.BIT64=1]="BIT64",e[e.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",e[e.START_GROUP=3]="START_GROUP",e[e.END_GROUP=4]="END_GROUP",e[e.BIT32=5]="BIT32"})(cr||(cr={}));function Ln(e,t,r,n){return{name:e,type:t,encode:r,decode:n}}function $r(e){function t(o){if(e[o.toString()]==null)throw new Error("Invalid enum value");return e[o]}let r=function(i,s){let c=t(i);s.int32(c)},n=function(i){let s=i.int32();return t(s)};return Ln("enum",cr.VARINT,r,n)}function ur(e,t){return Ln("message",cr.LENGTH_DELIMITED,e,t)}var st;(function(e){e.RSA="RSA",e.Ed25519="Ed25519",e.secp256k1="secp256k1",e.ECDSA="ECDSA"})(st||(st={}));var Ki;(function(e){e[e.RSA=0]="RSA",e[e.Ed25519=1]="Ed25519",e[e.secp256k1=2]="secp256k1",e[e.ECDSA=3]="ECDSA"})(Ki||(Ki={}));(function(e){e.codec=()=>$r(Ki)})(st||(st={}));var Qt;(function(e){let t;e.codec=()=>(t==null&&(t=ur((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),st.codec().encode(r.Type,n)),r.Data!=null&&(n.uint32(18),n.bytes(r.Data)),o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let i={},s=n==null?r.len:r.pos+n;for(;r.pos<s;){let c=r.uint32();switch(c>>>3){case 1:{i.Type=st.codec().decode(r);break}case 2:{i.Data=r.bytes();break}default:{r.skipType(c&7);break}}}return i})),t),e.encode=r=>ar(r,e.codec()),e.decode=(r,n)=>sr(r,e.codec(),n)})(Qt||(Qt={}));var Vi;(function(e){let t;e.codec=()=>(t==null&&(t=ur((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),st.codec().encode(r.Type,n)),r.Data!=null&&(n.uint32(18),n.bytes(r.Data)),o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let i={},s=n==null?r.len:r.pos+n;for(;r.pos<s;){let c=r.uint32();switch(c>>>3){case 1:{i.Type=st.codec().decode(r);break}case 2:{i.Data=r.bytes();break}default:{r.skipType(c&7);break}}}return i})),t),e.encode=r=>ar(r,e.codec()),e.decode=(r,n)=>sr(r,e.codec(),n)})(Vi||(Vi={}));var zr={};bt(zr,{MAX_RSA_KEY_SIZE:()=>Mi,generateRSAKeyPair:()=>uc,jwkToJWKKeyPair:()=>fc,jwkToPkcs1:()=>Hd,jwkToPkix:()=>Hi,jwkToRSAPrivateKey:()=>ji,pkcs1MessageToJwk:()=>qi,pkcs1MessageToRSAPrivateKey:()=>zi,pkcs1ToJwk:()=>$d,pkcs1ToRSAPrivateKey:()=>cc,pkixMessageToJwk:()=>$i,pkixMessageToRSAPublicKey:()=>Zi,pkixToJwk:()=>zd,pkixToRSAPublicKey:()=>Gi});var fr=class{type="RSA";jwk;_raw;_multihash;constructor(t,r){this.jwk=t,this._multihash=r}get raw(){return this._raw==null&&(this._raw=zr.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return j.createV1(114,this._multihash)}toString(){return W.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:J(this.raw,t.raw)}verify(t,r,n){return ac(this.jwk,r,t,n)}},Hr=class{type="RSA";jwk;_raw;publicKey;constructor(t,r){this.jwk=t,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=zr.jwkToPkcs1(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:J(this.raw,t.raw)}sign(t,r){return sc(this.jwk,t,r)}};var Mi=8192,Fi=18,Fd=1062,qd=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function $d(e){let t=ne(e);return qi(t)}function qi(e){return{n:z(e[1],"base64url"),e:z(e[2],"base64url"),d:z(e[3],"base64url"),p:z(e[4],"base64url"),q:z(e[5],"base64url"),dp:z(e[6],"base64url"),dq:z(e[7],"base64url"),qi:z(e[8],"base64url"),kty:"RSA"}}function Hd(e){if(e.n==null||e.e==null||e.d==null||e.p==null||e.q==null||e.dp==null||e.dq==null||e.qi==null)throw new ot("JWK was missing components");return ge([vt(Uint8Array.from([0])),vt(H(e.n,"base64url")),vt(H(e.e,"base64url")),vt(H(e.d,"base64url")),vt(H(e.p,"base64url")),vt(H(e.q,"base64url")),vt(H(e.dp,"base64url")),vt(H(e.dq,"base64url")),vt(H(e.qi,"base64url"))]).subarray()}function zd(e){let t=ne(e,{offset:0});return $i(t)}function $i(e){let t=ne(e[1],{offset:0});return{kty:"RSA",n:z(t[0],"base64url"),e:z(t[1],"base64url")}}function Hi(e){if(e.n==null||e.e==null)throw new ot("JWK was missing components");return ge([qd,gn(ge([vt(H(e.n,"base64url")),vt(H(e.e,"base64url"))]))]).subarray()}function cc(e){let t=ne(e);return zi(t)}function zi(e){let t=qi(e);return ji(t)}function Gi(e,t){if(e.byteLength>=Fd)throw new $e("Key size is too large");let r=ne(e,{offset:0});return Zi(r,e,t)}function Zi(e,t,r){let n=$i(e);if(r==null){let o=tr(Qt.encode({Type:st.RSA,Data:t}));r=Kt(Fi,o)}return new fr(n,r)}function ji(e){if(dc(e)>Mi)throw new ot("Key size is too large");let t=fc(e),r=tr(Qt.encode({Type:st.RSA,Data:Hi(t.publicKey)})),n=Kt(Fi,r);return new Hr(t.privateKey,new fr(t.publicKey,n))}async function uc(e){if(e>Mi)throw new ot("Key size is too large");let t=await lc(e),r=tr(Qt.encode({Type:st.RSA,Data:Hi(t.publicKey)})),n=Kt(Fi,r);return new Hr(t.privateKey,new fr(t.publicKey,n))}function fc(e){if(e==null)throw new ot("Missing key parameter");return{privateKey:e,publicKey:{kty:e.kty,n:e.n,e:e.e}}}async function lc(e,t){let r=await Pt.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:e,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]);t?.signal?.throwIfAborted();let n=await Gd(r,t);return{privateKey:n[0],publicKey:n[1]}}async function sc(e,t,r){let n=await Pt.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);r?.signal?.throwIfAborted();let o=await Pt.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,t instanceof Uint8Array?t:t.subarray());return r?.signal?.throwIfAborted(),new Uint8Array(o,0,o.byteLength)}async function ac(e,t,r,n){let o=await Pt.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let i=await Pt.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,t,r instanceof Uint8Array?r:r.subarray());return n?.signal?.throwIfAborted(),i}async function Gd(e,t){if(e.privateKey==null||e.publicKey==null)throw new ot("Private and public key are required");let r=await Promise.all([Pt.get().subtle.exportKey("jwk",e.privateKey),Pt.get().subtle.exportKey("jwk",e.publicKey)]);return t?.signal?.throwIfAborted(),r}function dc(e){if(e.kty!=="RSA")throw new ot("invalid key type");if(e.n==null)throw new ot("invalid key modulus");return H(e.n,"base64url").length*8}var Pn=class{oHash;iHash;blockLen;outputLen;finished=!1;destroyed=!1;constructor(t,r){if(xn(t),$(r,void 0,"key"),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 n=this.blockLen,o=new Uint8Array(n);o.set(r.length>n?t.create().update(r).digest():r);for(let i=0;i<o.length;i++)o[i]^=54;this.iHash.update(o),this.oHash=t.create();for(let i=0;i<o.length;i++)o[i]^=106;this.oHash.update(o),ie(o)}update(t){return Je(this),this.iHash.update(t),this}digestInto(t){Je(this),$(t,this.outputLen,"output"),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||=Object.create(Object.getPrototypeOf(this),{});let{oHash:r,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=r._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Yi=(e,t,r)=>new Pn(e,t).update(r).digest();Yi.create=(e,t)=>new Pn(e,t);var hc=(e,t)=>(e+(e>=0?t:-t)/pc)/t;function Zd(e,t,r){let[[n,o],[i,s]]=t,c=hc(s*e,r),a=hc(-o*e,r),l=e-c*n-a*i,u=-c*o-a*s,f=l<fe,y=u<fe;f&&(l=-l),y&&(u=-u);let E=Or(Math.ceil(ai(r)/2))+lr;if(l<fe||l>=E||u<fe||u>=E)throw new Error("splitScalar (endomorphism): failed, k="+e);return{k1neg:f,k1:l,k2neg:y,k2:u}}function Xi(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function Wi(e,t){let r={};for(let n of Object.keys(t))r[n]=e[n]===void 0?t[n]:e[n];return ue(r.lowS,"lowS"),ue(r.prehash,"prehash"),r.format!==void 0&&Xi(r.format),r}var Ji=class extends Error{constructor(t=""){super(t)}},Ae={Err:Ji,_tlv:{encode:(e,t)=>{let{Err:r}=Ae;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(t.length&1)throw new r("tlv.encode: unpadded data");let n=t.length/2,o=Ur(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let i=n>127?Ur(o.length/2|128):"";return Ur(e)+i+o+t},decode(e,t){let{Err:r}=Ae,n=0;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(t.length<2||t[n++]!==e)throw new r("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 r("tlv.decode(long): indefinite length not supported");if(a>4)throw new r("tlv.decode(long): byte length is too big");let l=t.subarray(n,n+a);if(l.length!==a)throw new r("tlv.decode: length bytes not complete");if(l[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let u of l)s=s<<8|u;if(n+=a,s<128)throw new r("tlv.decode(long): not minimal encoding")}let c=t.subarray(n,n+s);if(c.length!==s)throw new r("tlv.decode: wrong value length");return{v:c,l:t.subarray(n+s)}}},_int:{encode(e){let{Err:t}=Ae;if(e<fe)throw new t("integer: negative integers are not allowed");let r=Ur(e);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new t("unexpected DER parsing assertion: unpadded hex");return r},decode(e){let{Err:t}=Ae;if(e[0]&128)throw new t("invalid signature integer: negative");if(e[0]===0&&!(e[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return er(e)}},toSig(e){let{Err:t,_int:r,_tlv:n}=Ae,o=$(e,void 0,"signature"),{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:r.decode(c),s:r.decode(l)}},hexFromSig(e){let{_tlv:t,_int:r}=Ae,n=t.encode(2,r.encode(e.r)),o=t.encode(2,r.encode(e.s)),i=n+o;return t.encode(48,i)}},fe=BigInt(0),lr=BigInt(1),pc=BigInt(2),Un=BigInt(3),jd=BigInt(4);function mc(e,t={}){let r=An("weierstrass",e,t),{Fp:n,Fn:o}=r,i=r.CURVE,{h:s,n:c}=i;Ee(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object"});let{endo:a}=t;if(a&&(!n.is0(i.a)||typeof a.beta!="bigint"||!Array.isArray(a.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let l=gc(n,o);function u(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function f(A,m,g){let{x:d,y:S}=m.toAffine(),R=n.toBytes(d);if(ue(g,"isCompressed"),g){u();let P=!n.isOdd(S);return At(yc(P),R)}else return At(Uint8Array.of(4),R,n.toBytes(S))}function y(A){$(A,void 0,"Point");let{publicKey:m,publicKeyUncompressed:g}=l,d=A.length,S=A[0],R=A.subarray(1);if(d===m&&(S===2||S===3)){let P=n.fromBytes(R);if(!n.isValid(P))throw new Error("bad point: is not on curve, wrong x");let N=I(P),O;try{O=n.sqrt(N)}catch(tt){let Y=tt instanceof Error?": "+tt.message:"";throw new Error("bad point: is not on curve, sqrt error"+Y)}u();let K=n.isOdd(O);return(S&1)===1!==K&&(O=n.neg(O)),{x:P,y:O}}else if(d===g&&S===4){let P=n.BYTES,N=n.fromBytes(R.subarray(0,P)),O=n.fromBytes(R.subarray(P,P*2));if(!C(N,O))throw new Error("bad point: is not on curve");return{x:N,y:O}}else throw new Error(`bad point: got length ${d}, expected compressed=${m} or uncompressed=${g}`)}let E=t.toBytes||f,b=t.fromBytes||y;function I(A){let m=n.sqr(A),g=n.mul(m,A);return n.add(n.add(g,n.mul(A,i.a)),i.b)}function C(A,m){let g=n.sqr(m),d=I(A);return n.eql(g,d)}if(!C(i.Gx,i.Gy))throw new Error("bad curve params: generator point");let w=n.mul(n.pow(i.a,Un),jd),T=n.mul(n.sqr(i.b),BigInt(27));if(n.is0(n.add(w,T)))throw new Error("bad curve params: a or b");function v(A,m,g=!1){if(!n.isValid(m)||g&&n.is0(m))throw new Error(`bad point coordinate ${A}`);return m}function U(A){if(!(A instanceof p))throw new Error("Weierstrass Point expected")}function k(A){if(!a||!a.basises)throw new Error("no endo");return Zd(A,a.basises,o.ORDER)}let M=rr((A,m)=>{let{X:g,Y:d,Z:S}=A;if(n.eql(S,n.ONE))return{x:g,y:d};let R=A.is0();m==null&&(m=R?n.ONE:n.inv(S));let P=n.mul(g,m),N=n.mul(d,m),O=n.mul(S,m);if(R)return{x:n.ZERO,y:n.ZERO};if(!n.eql(O,n.ONE))throw new Error("invZ was invalid");return{x:P,y:N}}),V=rr(A=>{if(A.is0()){if(t.allowInfinityPoint&&!n.is0(A.Y))return;throw new Error("bad point: ZERO")}let{x:m,y:g}=A.toAffine();if(!n.isValid(m)||!n.isValid(g))throw new Error("bad point: x or y not field elements");if(!C(m,g))throw new Error("bad point: equation left != right");if(!A.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function h(A,m,g,d,S){return g=new p(n.mul(g.X,A),g.Y,g.Z),m=Kr(d,m),g=Kr(S,g),m.add(g)}class p{static BASE=new p(i.Gx,i.Gy,n.ONE);static ZERO=new p(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(m,g,d){this.X=v("x",m),this.Y=v("y",g,!0),this.Z=v("z",d),Object.freeze(this)}static CURVE(){return i}static fromAffine(m){let{x:g,y:d}=m||{};if(!m||!n.isValid(g)||!n.isValid(d))throw new Error("invalid affine point");if(m instanceof p)throw new Error("projective point not allowed");return n.is0(g)&&n.is0(d)?p.ZERO:new p(g,d,n.ONE)}static fromBytes(m){let g=p.fromAffine(b($(m,void 0,"point")));return g.assertValidity(),g}static fromHex(m){return p.fromBytes(ae(m))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(m=8,g=!0){return D.createCache(this,m),g||this.multiply(Un),this}assertValidity(){V(this)}hasEvenY(){let{y:m}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(m)}equals(m){U(m);let{X:g,Y:d,Z:S}=this,{X:R,Y:P,Z:N}=m,O=n.eql(n.mul(g,N),n.mul(R,S)),K=n.eql(n.mul(d,N),n.mul(P,S));return O&&K}negate(){return new p(this.X,n.neg(this.Y),this.Z)}double(){let{a:m,b:g}=i,d=n.mul(g,Un),{X:S,Y:R,Z:P}=this,N=n.ZERO,O=n.ZERO,K=n.ZERO,q=n.mul(S,S),tt=n.mul(R,R),Y=n.mul(P,P),G=n.mul(S,R);return G=n.add(G,G),K=n.mul(S,P),K=n.add(K,K),N=n.mul(m,K),O=n.mul(d,Y),O=n.add(N,O),N=n.sub(tt,O),O=n.add(tt,O),O=n.mul(N,O),N=n.mul(G,N),K=n.mul(d,K),Y=n.mul(m,Y),G=n.sub(q,Y),G=n.mul(m,G),G=n.add(G,K),K=n.add(q,q),q=n.add(K,q),q=n.add(q,Y),q=n.mul(q,G),O=n.add(O,q),Y=n.mul(R,P),Y=n.add(Y,Y),q=n.mul(Y,G),N=n.sub(N,q),K=n.mul(Y,tt),K=n.add(K,K),K=n.add(K,K),new p(N,O,K)}add(m){U(m);let{X:g,Y:d,Z:S}=this,{X:R,Y:P,Z:N}=m,O=n.ZERO,K=n.ZERO,q=n.ZERO,tt=i.a,Y=n.mul(i.b,Un),G=n.mul(g,R),et=n.mul(d,P),lt=n.mul(S,N),Gt=n.add(g,d),rt=n.add(R,P);Gt=n.mul(Gt,rt),rt=n.add(G,et),Gt=n.sub(Gt,rt),rt=n.add(g,S);let mt=n.add(R,N);return rt=n.mul(rt,mt),mt=n.add(G,lt),rt=n.sub(rt,mt),mt=n.add(d,S),O=n.add(P,N),mt=n.mul(mt,O),O=n.add(et,lt),mt=n.sub(mt,O),q=n.mul(tt,rt),O=n.mul(Y,lt),q=n.add(O,q),O=n.sub(et,q),q=n.add(et,q),K=n.mul(O,q),et=n.add(G,G),et=n.add(et,G),lt=n.mul(tt,lt),rt=n.mul(Y,rt),et=n.add(et,lt),lt=n.sub(G,lt),lt=n.mul(tt,lt),rt=n.add(rt,lt),G=n.mul(et,rt),K=n.add(K,G),G=n.mul(mt,rt),O=n.mul(Gt,O),O=n.sub(O,G),G=n.mul(Gt,et),q=n.mul(mt,q),q=n.add(q,G),new p(O,K,q)}subtract(m){return this.add(m.negate())}is0(){return this.equals(p.ZERO)}multiply(m){let{endo:g}=t;if(!o.isValidNot0(m))throw new Error("invalid scalar: out of range");let d,S,R=P=>D.cached(this,P,N=>Oe(p,N));if(g){let{k1neg:P,k1:N,k2neg:O,k2:K}=k(m),{p:q,f:tt}=R(N),{p:Y,f:G}=R(K);S=tt.add(G),d=h(g.beta,q,Y,P,O)}else{let{p:P,f:N}=R(m);d=P,S=N}return Oe(p,[d,S])[0]}multiplyUnsafe(m){let{endo:g}=t,d=this;if(!o.isValid(m))throw new Error("invalid scalar: out of range");if(m===fe||d.is0())return p.ZERO;if(m===lr)return d;if(D.hasCache(this))return this.multiply(m);if(g){let{k1neg:S,k1:R,k2neg:P,k2:N}=k(m),{p1:O,p2:K}=qa(p,d,R,N);return h(g.beta,O,K,S,P)}else return D.unsafe(d,m)}toAffine(m){return M(this,m)}isTorsionFree(){let{isTorsionFree:m}=t;return s===lr?!0:m?m(p,this):D.unsafe(this,c).is0()}clearCofactor(){let{clearCofactor:m}=t;return s===lr?this:m?m(p,this):this.multiplyUnsafe(s)}isSmallOrder(){return this.multiplyUnsafe(s).is0()}toBytes(m=!0){return ue(m,"isCompressed"),this.assertValidity(),E(p,this,m)}toHex(m=!0){return se(this.toBytes(m))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let _=o.BITS,D=new ir(p,t.endo?Math.ceil(_/2):_);return p.BASE.precompute(8),p}function yc(e){return Uint8Array.of(e?2:3)}function gc(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function Yd(e,t={}){let{Fn:r}=e,n=t.randomBytes||Qe,o=Object.assign(gc(e.Fp,r),{seed:li(r.ORDER)});function i(E){try{let b=r.fromBytes(E);return r.isValidNot0(b)}catch{return!1}}function s(E,b){let{publicKey:I,publicKeyUncompressed:C}=o;try{let w=E.length;return b===!0&&w!==I||b===!1&&w!==C?!1:!!e.fromBytes(E)}catch{return!1}}function c(E=n(o.seed)){return di($(E,o.seed,"seed"),r.ORDER)}function a(E,b=!0){return e.BASE.multiply(r.fromBytes(E)).toBytes(b)}function l(E){let{secretKey:b,publicKey:I,publicKeyUncompressed:C}=o;if(!De(E)||"_lengths"in r&&r._lengths||b===I)return;let w=$(E,void 0,"key").length;return w===I||w===C}function u(E,b,I=!0){if(l(E)===!0)throw new Error("first arg must be private key");if(l(b)===!1)throw new Error("second arg must be public key");let C=r.fromBytes(E);return e.fromBytes(b).multiply(C).toBytes(I)}let f={isValidSecretKey:i,isValidPublicKey:s,randomSecretKey:c},y=Cn(c,a);return Object.freeze({getPublicKey:a,getSharedSecret:u,keygen:y,Point:e,utils:f,lengths:o})}function xc(e,t,r={}){xn(t),Ee(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),r=Object.assign({},r);let n=r.randomBytes||Qe,o=r.hmac||((g,d)=>Yi(t,g,d)),{Fp:i,Fn:s}=e,{ORDER:c,BITS:a}=s,{keygen:l,getPublicKey:u,getSharedSecret:f,utils:y,lengths:E}=Yd(e,r),b={prehash:!0,lowS:typeof r.lowS=="boolean"?r.lowS:!0,format:"compact",extraEntropy:!1},I=c*pc<i.ORDER;function C(g){let d=c>>lr;return g>d}function w(g,d){if(!s.isValidNot0(d))throw new Error(`invalid signature ${g}: out of range 1..Point.Fn.ORDER`);return d}function T(){if(I)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function v(g,d){Xi(d);let S=E.signature,R=d==="compact"?S:d==="recovered"?S+1:void 0;return $(g,R)}class U{r;s;recovery;constructor(d,S,R){if(this.r=w("r",d),this.s=w("s",S),R!=null){if(T(),![0,1,2,3].includes(R))throw new Error("invalid recovery id");this.recovery=R}Object.freeze(this)}static fromBytes(d,S=b.format){v(d,S);let R;if(S==="der"){let{r:K,s:q}=Ae.toSig($(d));return new U(K,q)}S==="recovered"&&(R=d[0],S="compact",d=d.subarray(1));let P=E.signature/2,N=d.subarray(0,P),O=d.subarray(P,P*2);return new U(s.fromBytes(N),s.fromBytes(O),R)}static fromHex(d,S){return this.fromBytes(ae(d),S)}assertRecovery(){let{recovery:d}=this;if(d==null)throw new Error("invalid recovery id: must be present");return d}addRecoveryBit(d){return new U(this.r,this.s,d)}recoverPublicKey(d){let{r:S,s:R}=this,P=this.assertRecovery(),N=P===2||P===3?S+c:S;if(!i.isValid(N))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let O=i.toBytes(N),K=e.fromBytes(At(yc((P&1)===0),O)),q=s.inv(N),tt=M($(d,void 0,"msgHash")),Y=s.create(-tt*q),G=s.create(R*q),et=e.BASE.multiplyUnsafe(Y).add(K.multiplyUnsafe(G));if(et.is0())throw new Error("invalid recovery: point at infinify");return et.assertValidity(),et}hasHighS(){return C(this.s)}toBytes(d=b.format){if(Xi(d),d==="der")return ae(Ae.hexFromSig(this));let{r:S,s:R}=this,P=s.toBytes(S),N=s.toBytes(R);return d==="recovered"?(T(),At(Uint8Array.of(this.assertRecovery()),P,N)):At(P,N)}toHex(d){return se(this.toBytes(d))}}let k=r.bits2int||function(d){if(d.length>8192)throw new Error("input is too large");let S=er(d),R=d.length*8-a;return R>0?S>>BigInt(R):S},M=r.bits2int_modN||function(d){return s.create(k(d))},V=Or(a);function h(g){return Nr("num < 2^"+a,g,fe,V),s.toBytes(g)}function p(g,d){return $(g,void 0,"message"),d?$(t(g),void 0,"prehashed message"):g}function _(g,d,S){let{lowS:R,prehash:P,extraEntropy:N}=Wi(S,b);g=p(g,P);let O=M(g),K=s.fromBytes(d);if(!s.isValidNot0(K))throw new Error("invalid private key");let q=[h(K),h(O)];if(N!=null&&N!==!1){let et=N===!0?n(E.secretKey):N;q.push($(et,void 0,"extraEntropy"))}let tt=At(...q),Y=O;function G(et){let lt=k(et);if(!s.isValidNot0(lt))return;let Gt=s.inv(lt),rt=e.BASE.multiply(lt).toAffine(),mt=s.create(rt.x);if(mt===fe)return;let un=s.create(Gt*s.create(Y+mt*K));if(un===fe)return;let As=(rt.x===mt?0:2)|Number(rt.y&lr),Cs=un;return R&&C(un)&&(Cs=s.neg(un),As^=1),new U(mt,Cs,I?void 0:As)}return{seed:tt,k2sig:G}}function D(g,d,S={}){let{seed:R,k2sig:P}=_(g,d,S);return Ca(t.outputLen,s.BYTES,o)(R,P).toBytes(S.format)}function A(g,d,S,R={}){let{lowS:P,prehash:N,format:O}=Wi(R,b);if(S=$(S,void 0,"publicKey"),d=p(d,N),!De(g)){let K=g instanceof U?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+K)}v(g,O);try{let K=U.fromBytes(g,O),q=e.fromBytes(S);if(P&&K.hasHighS())return!1;let{r:tt,s:Y}=K,G=M(d),et=s.inv(Y),lt=s.create(G*et),Gt=s.create(tt*et),rt=e.BASE.multiplyUnsafe(lt).add(q.multiplyUnsafe(Gt));return rt.is0()?!1:s.create(rt.x)===tt}catch{return!1}}function m(g,d,S={}){let{prehash:R}=Wi(S,b);return d=p(d,R),U.fromBytes(g,"recovered").recoverPublicKey(d).toBytes()}return Object.freeze({keygen:l,getPublicKey:u,getSharedSecret:f,utils:y,lengths:E,Point:e,sign:D,verify:A,recoverPublicKey:m,Signature:U,hash:t})}var ts={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Wd={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var bc=BigInt(2);function Xd(e){let t=ts.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),i=BigInt(22),s=BigInt(23),c=BigInt(44),a=BigInt(88),l=e*e*e%t,u=l*l*e%t,f=X(u,r,t)*u%t,y=X(f,r,t)*u%t,E=X(y,bc,t)*l%t,b=X(E,o,t)*E%t,I=X(b,i,t)*b%t,C=X(I,c,t)*I%t,w=X(C,a,t)*C%t,T=X(w,c,t)*I%t,v=X(T,r,t)*u%t,U=X(v,s,t)*b%t,k=X(U,n,t)*l%t,M=X(k,bc,t);if(!Qi.eql(Qi.sqr(M),e))throw new Error("Cannot find square root");return M}var Qi=nr(ts.p,{sqrt:Xd}),Jd=mc(ts,{Fp:Qi,endo:Wd}),dr=xc(Jd,tr);function wc(e,t,r,n){let o=Tr.digest(r instanceof Uint8Array?r:r.subarray());if(Bn(o))return o.then(({digest:i})=>(n?.signal?.throwIfAborted(),dr.verify(t,i,e,{prehash:!1,format:"der"}))).catch(i=>{throw i.name==="AbortError"?i:new Vr(String(i))});try{return n?.signal?.throwIfAborted(),dr.verify(t,o.digest,e,{prehash:!1,format:"der"})}catch(i){throw new Vr(String(i))}}var Nn=class{type="secp256k1";raw;_key;constructor(t){this._key=Sc(t),this.raw=Ec(this._key)}toMultihash(){return Vt.digest(Xe(this))}toCID(){return j.createV1(114,this.toMultihash())}toString(){return W.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:J(this.raw,t.raw)}verify(t,r,n){return wc(this._key,r,t,n)}};function es(e){return new Nn(e)}function Ec(e){return dr.Point.fromBytes(e).toBytes()}function Sc(e){try{return dr.Point.fromBytes(e),e}catch(t){throw new $e(String(t))}}function vc(e,t){let{Type:r,Data:n}=Qt.decode(e),o=n??new Uint8Array;switch(r){case st.RSA:return Gi(o,t);case st.Ed25519:return wi(o);case st.secp256k1:return es(o);case st.ECDSA:return Yo(o);default:throw new ze}}function On(e){let{Type:t,Data:r}=Qt.decode(e.digest),n=r??new Uint8Array;switch(t){case st.Ed25519:return wi(n);case st.secp256k1:return es(n);case st.ECDSA:return Yo(n);default:throw new ze}}function Xe(e){return Qt.encode({Type:st[e.type],Data:e.raw})}var Ac=Symbol.for("nodejs.util.inspect.custom"),Qd=114,Gr=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()})`}[pn]=!0;toString(){return this.string==null&&(this.string=W.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return j.createV1(Qd,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return J(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return J(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[Ac](){return`PeerId(${this.toString()})`}},kn=class extends Gr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},Kn=class extends Gr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},Vn=class extends Gr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},th=2336,Zr=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=Vt.digest(H(this.url))}[Ac](){return`PeerId(${this.url})`}[pn]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return j.createV1(th,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=z(t)),t.toString()===this.toString())}};var eh=114,Cc=2336;function Ic(e,t){let r;if(e.charAt(0)==="1"||e.charAt(0)==="Q")r=ye(W.decode(`z${e}`));else{if(e.startsWith("k51qzi5uqu5")||e.startsWith("kzwfwjn5ji4")||e.startsWith("k2k4r8")||e.startsWith("bafz"))return rh(j.parse(e));if(t==null)throw new ot('Please pass a multibase decoder for strings that do not start with "1" or "Q"');r=ye(t.decode(e))}return Mn(r)}function Mn(e){if(oh(e))return new kn({multihash:e});if(nh(e))try{let t=On(e);if(t.type==="Ed25519")return new Kn({multihash:e,publicKey:t});if(t.type==="secp256k1")return new Vn({multihash:e,publicKey:t})}catch{let r=z(e.digest);return new Zr(new URL(r))}throw new He("Supplied PeerID Multihash is invalid")}function rh(e){if(e?.multihash==null||e.version==null||e.version===1&&e.code!==eh&&e.code!==Cc)throw new hn("Supplied PeerID CID is invalid");if(e.code===Cc){let t=z(e.multihash.digest);return new Zr(new URL(t))}return Mn(e.multihash)}function nh(e){return e.code===Vt.code}function oh(e){return e.code===Tr.code}var ht=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},le=class extends Error{static name="ValidationError";name="ValidationError"},Fn=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},qn=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};var $n=class{index=0;input="";new(t){return this.index=0,this.input=t,this}readAtomically(t){let r=this.index,n=t();return n===void 0&&(this.index=r),n}parseWith(t){let r=t();if(this.index===this.input.length)return r}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 r=this.readChar();if(r===t)return r})}readSeparator(t,r,n){return this.readAtomically(()=>{if(!(r>0&&this.readGivenChar(t)===void 0))return n()})}readNumber(t,r,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 y=Number.parseInt(f,t);if(!Number.isNaN(y))return y});if(u===void 0)break;if(i*=t,i+=u,i>l||(s+=1,r!==void 0&&s>r))return}if(s!==0)return!n&&a&&s>1?void 0:i})}readIPv4Addr(){return this.readAtomically(()=>{let t=new Uint8Array(4);for(let r=0;r<t.length;r++){let n=this.readSeparator(".",r,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;t[r]=n}return t})}readIPv6Addr(){let t=r=>{for(let n=0;n<r.length/2;n++){let o=n*2;if(n<r.length-3){let s=this.readSeparator(":",n,()=>this.readIPv4Addr());if(s!==void 0)return r[o]=s[0],r[o+1]=s[1],r[o+2]=s[2],r[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];r[o]=i>>8,r[o+1]=i&255}return[r.length,!1]};return this.readAtomically(()=>{let r=new Uint8Array(16),[n,o]=t(r);if(n===16)return r;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 r.set(i.subarray(0,c),16-c),r})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var ih=45,sh=15,Hn=new $n;function Tc(e){if(!(e.length>sh))return Hn.new(e).parseWith(()=>Hn.readIPv4Addr())}function Bc(e){if(e.includes("%")&&(e=e.split("%")[0]),!(e.length>ih))return Hn.new(e).parseWith(()=>Hn.readIPv6Addr())}function zn(e){return!!Tc(e)}function _c(e){return!!Bc(e)}function ns(e){return t=>z(t,e)}function os(e){return t=>H(t,e)}function hr(e){return new DataView(e.buffer).getUint16(e.byteOffset).toString()}function Ve(e){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,typeof e=="string"?parseInt(e):e),new Uint8Array(t)}function Dc(e){let t=e.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 r=H(t[0],"base32"),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=Ve(n);return Lt([r,o],r.length+o.length)}function Rc(e){let t=e.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 r=Zt.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=Ve(n);return Lt([r,o],r.length+o.length)}function is(e){let t=e.subarray(0,e.length-2),r=e.subarray(e.length-2),n=z(t,"base32"),o=hr(r);return`${n}:${o}`}var ss=function(e){e=e.toString().trim();let t=new Uint8Array(4);return e.split(/\./g).forEach((r,n)=>{let o=parseInt(r,10);if(isNaN(o)||o<0||o>255)throw new ht("Invalid byte value in IP address");t[n]=o}),t},Lc=function(e){let t=0;e=e.toString().trim();let r=e.split(":",8),n;for(n=0;n<r.length;n++){let i=zn(r[n]),s;i&&(s=ss(r[n]),r[n]=z(s.subarray(0,2),"base16")),s!=null&&++n<8&&r.splice(n,0,z(s.subarray(2,4),"base16"))}if(r[0]==="")for(;r.length<8;)r.unshift("0");else if(r[r.length-1]==="")for(;r.length<8;)r.push("0");else if(r.length<8){for(n=0;n<r.length&&r[n]!=="";n++);let i=[n,1];for(n=9-r.length;n>0;n--)i.push("0");r.splice.apply(r,i)}let o=new Uint8Array(t+16);for(n=0;n<r.length;n++){r[n]===""&&(r[n]="0");let i=parseInt(r[n],16);if(isNaN(i)||i<0||i>65535)throw new ht("Invalid byte value in IP address");o[t++]=i>>8&255,o[t++]=i&255}return o},Pc=function(e){if(e.byteLength!==4)throw new ht("IPv4 address was incorrect length");let t=[];for(let r=0;r<e.byteLength;r++)t.push(e[r]);return t.join(".")},Uc=function(e){if(e.byteLength!==16)throw new ht("IPv6 address was incorrect length");let t=[];for(let n=0;n<e.byteLength;n+=2){let o=e[n],i=e[n+1],s=`${o.toString(16).padStart(2,"0")}${i.toString(16).padStart(2,"0")}`;t.push(s)}let r=t.join(":");try{let n=new URL(`http://[${r}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new ht(`Invalid IPv6 address "${r}"`)}};function Nc(e){try{let t=new URL(`http://[${e}]`);return t.hostname.substring(1,t.hostname.length-1)}catch{throw new ht(`Invalid IPv6 address "${e}"`)}}var rs=Object.values(Br).map(e=>e.decoder),ah=(function(){let e=rs[0].or(rs[1]);return rs.slice(2).forEach(t=>e=e.or(t)),e})();function Oc(e){return ah.decode(e)}function kc(e){return t=>e.encoder.encode(t)}function ch(e){if(parseInt(e).toString()!==e)throw new le("Value must be an integer")}function uh(e){if(e<0)throw new le("Value must be a positive integer, or zero")}function fh(e){return t=>{if(t>e)throw new le(`Value must be smaller than or equal to ${e}`)}}function lh(...e){return t=>{for(let r of e)r(t)}}var jr=lh(ch,uh,fh(65535));var ut=-1,as=class{protocolsByCode=new Map;protocolsByName=new Map;getProtocol(t){let r;if(typeof t=="string"?r=this.protocolsByName.get(t):r=this.protocolsByCode.get(t),r==null)throw new qn(`Protocol ${t} was unknown`);return r}addProtocol(t){this.protocolsByCode.set(t.code,t),this.protocolsByName.set(t.name,t),t.aliases?.forEach(r=>{this.protocolsByName.set(r,t)})}removeProtocol(t){let r=this.protocolsByCode.get(t);r!=null&&(this.protocolsByCode.delete(r.code),this.protocolsByName.delete(r.name),r.aliases?.forEach(n=>{this.protocolsByName.delete(n)}))}},de=new as,Jh=[{code:4,name:"ip4",size:32,valueToBytes:ss,bytesToValue:Pc,validate:e=>{if(!zn(e))throw new le(`Invalid IPv4 address "${e}"`)}},{code:6,name:"tcp",size:16,valueToBytes:Ve,bytesToValue:hr,validate:jr},{code:273,name:"udp",size:16,valueToBytes:Ve,bytesToValue:hr,validate:jr},{code:33,name:"dccp",size:16,valueToBytes:Ve,bytesToValue:hr,validate:jr},{code:41,name:"ip6",size:128,valueToBytes:Lc,bytesToValue:Uc,stringToValue:Nc,validate:e=>{if(!_c(e))throw new le(`Invalid IPv6 address "${e}"`)}},{code:42,name:"ip6zone",size:ut},{code:43,name:"ipcidr",size:8,bytesToValue:ns("base10"),valueToBytes:os("base10")},{code:53,name:"dns",size:ut},{code:54,name:"dns4",size:ut},{code:55,name:"dns6",size:ut},{code:56,name:"dnsaddr",size:ut},{code:132,name:"sctp",size:16,valueToBytes:Ve,bytesToValue:hr,validate:jr},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:ut,stringToValue:e=>decodeURIComponent(e),valueToString:e=>encodeURIComponent(e)},{code:421,name:"p2p",aliases:["ipfs"],size:ut,bytesToValue:ns("base58btc"),valueToBytes:e=>e.startsWith("Q")||e.startsWith("1")?os("base58btc")(e):j.parse(e).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:is,valueToBytes:Dc},{code:445,name:"onion3",size:296,bytesToValue:is,valueToBytes:Rc},{code:446,name:"garlic64",size:ut},{code:447,name:"garlic32",size:ut},{code:448,name:"tls"},{code:449,name:"sni",size:ut},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:ut,bytesToValue:kc(Io),valueToBytes:Oc},{code:480,name:"http"},{code:481,name:"http-path",size:ut,stringToValue:e=>`/${decodeURIComponent(e)}`,valueToString:e=>encodeURIComponent(e.substring(1))},{code:443,name:"https"},{code:477,name:"ws"},{code:478,name:"wss"},{code:479,name:"p2p-websocket-star"},{code:277,name:"p2p-stardust"},{code:275,name:"p2p-webrtc-star"},{code:276,name:"p2p-webrtc-direct"},{code:280,name:"webrtc-direct"},{code:281,name:"webrtc"},{code:290,name:"p2p-circuit"},{code:777,name:"memory",size:ut}];Jh.forEach(e=>{de.addProtocol(e)});function Kc(e){let t=[],r=0;for(;r<e.length;){let n=Ii(e,r),o=de.getProtocol(n),i=Jt(n),s=Qh(o,e,r+i),c=0;s>0&&o.size===ut&&(c=Jt(s));let a=i+c+s,l={code:n,name:o.name,bytes:e.subarray(r,r+a)};if(s>0){let u=r+i+c,f=e.subarray(u,u+s);l.value=o.bytesToValue?.(f)??z(f)}t.push(l),r+=a}return t}function Vc(e){let t=0,r=[];for(let n of e){if(n.bytes==null){let o=de.getProtocol(n.code),i=Jt(n.code),s,c=0,a=0;n.value!=null&&(s=o.valueToBytes?.(n.value)??H(n.value),c=s.byteLength,o.size===ut&&(a=Jt(c)));let l=new Uint8Array(i+a+c),u=0;Mr(n.code,l,u),u+=i,s!=null&&(o.size===ut&&(Mr(c,l,u),u+=a),l.set(s,u)),n.bytes=l}r.push(n.bytes),t+=n.bytes.byteLength}return Lt(r,t)}function Mc(e){if(e.charAt(0)!=="/")throw new ht('String multiaddr must start with "/"');let t=[],r="protocol",n="",o="";for(let i=1;i<e.length;i++){let s=e.charAt(i);s!=="/"&&(r==="protocol"?o+=e.charAt(i):n+=e.charAt(i));let c=i===e.length-1;if(s==="/"||c){let a=de.getProtocol(o);if(r==="protocol"){if(a.size==null||a.size===0){t.push({code:a.code,name:a.name}),n="",o="",r="protocol";continue}else if(c)throw new ht(`Component ${o} was missing value`);r="value"}else if(r==="value"){let l={code:a.code,name:a.name};if(a.size!=null&&a.size!==0){if(n==="")throw new ht(`Component ${o} was missing value`);l.value=a.stringToValue?.(n)??n}t.push(l),n="",o="",r="protocol"}}}if(o!==""&&n!=="")throw new ht("Incomplete multiaddr");return t}function Fc(e){return`/${e.flatMap(t=>{if(t.value==null)return t.name;let r=de.getProtocol(t.code);if(r==null)throw new ht(`Unknown protocol code ${t.code}`);return[t.name,r.valueToString?.(t.value)??t.value]}).join("/")}`}function Qh(e,t,r){return e.size==null||e.size===0?0:e.size>0?e.size/8:Ii(t,r)}var tp=Symbol.for("nodejs.util.inspect.custom"),cs=Symbol.for("@multiformats/multiaddr");function ep(e){if(e==null&&(e="/"),qc(e))return e.getComponents();if(e instanceof Uint8Array)return Kc(e);if(typeof e=="string")return e=e.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),e===""&&(e="/"),Mc(e);if(Array.isArray(e))return e;throw new ht("Must be a string, Uint8Array, Component[], or another Multiaddr")}var Gn=class e{[cs]=!0;#t;#n;#e;constructor(t="/",r={}){this.#t=ep(t),r.validate!==!1&&rp(this)}get bytes(){return this.#e==null&&(this.#e=Vc(this.#t)),this.#e}toString(){return this.#n==null&&(this.#n=Fc(this.#t)),this.#n}toJSON(){return this.toString()}getComponents(){return[...this.#t.map(t=>({...t}))]}encapsulate(t){let r=new e(t);return new e([...this.#t,...r.getComponents()],{validate:!1})}decapsulate(t){let r=t.toString(),n=this.toString(),o=n.lastIndexOf(r);if(o<0)throw new Fn(`Address ${this.toString()} does not contain subaddress: ${r}`);return new e(n.slice(0,o),{validate:!1})}decapsulateCode(t){let r;for(let n=this.#t.length-1;n>-1;n--)if(this.#t[n].code===t){r=n;break}return new e(this.#t.slice(0,r),{validate:!1})}equals(t){return J(this.bytes,t.bytes)}[tp](){return`Multiaddr(${this.toString()})`}};function rp(e){e.getComponents().forEach(t=>{let r=de.getProtocol(t.code);t.value!=null&&r.validate?.(t.value)})}function qc(e){return!!e?.[cs]}function $c(e){return new Gn(e)}function pr(e){let t=new globalThis.AbortController;function r(){let i=e.filter(s=>s?.aborted===!0).map(s=>s?.reason).pop();t.abort(i);for(let s of e)s?.removeEventListener!=null&&s.removeEventListener("abort",r)}for(let i of e){if(i?.aborted===!0){r();break}i?.addEventListener!=null&&i.addEventListener("abort",r)}function n(){for(let i of e)i?.removeEventListener!=null&&i.removeEventListener("abort",r)}let o=t.signal;return o.clear=n,o}async function*Yr(e,t={}){let r=e.getReader();try{for(;;){let n=await r.read();if(n.done)return;yield n.value}}finally{t.preventCancel!==!0&&await r.cancel(),r.releaseLock()}}var Vp=xo(fs(),1);var qt=class extends Error{static name="SignatureVerificationError";constructor(t="Record signature verification failed"){super(t),this.name="SignatureVerificationError"}},Zn=class extends Error{static name="RecordExpiredError";constructor(t="Record has expired"){super(t),this.name="RecordExpiredError"}},mr=class extends Error{static name="UnsupportedValidityError";constructor(t="The validity type is unsupported"){super(t),this.name="UnsupportedValidityError"}},jn=class extends Error{static name="RecordTooLargeError";constructor(t="The record is too large"){super(t),this.name="RecordTooLargeError"}},Yn=class extends Error{static name="InvalidValueError";constructor(t="Value must be a valid content path starting with /"){super(t),this.name="InvalidValueError"}},Wn=class extends Error{static name="InvalidRecordDataError";constructor(t="Invalid record data"){super(t),this.name="InvalidRecordDataError"}},Wr=class extends Error{static name="InvalidEmbeddedPublicKeyError";constructor(t="Invalid embedded public key"){super(t),this.name="InvalidEmbeddedPublicKeyError"}};var $t;(function(e){let t;(function(o){o.EOL="EOL"})(t=e.ValidityType||(e.ValidityType={}));let r;(function(o){o[o.EOL=0]="EOL"})(r||(r={})),(function(o){o.codec=()=>$r(r)})(t=e.ValidityType||(e.ValidityType={}));let n;e.codec=()=>(n==null&&(n=ur((o,i,s={})=>{s.lengthDelimited!==!1&&i.fork(),o.value!=null&&(i.uint32(10),i.bytes(o.value)),o.signatureV1!=null&&(i.uint32(18),i.bytes(o.signatureV1)),o.validityType!=null&&(i.uint32(24),e.ValidityType.codec().encode(o.validityType,i)),o.validity!=null&&(i.uint32(34),i.bytes(o.validity)),o.sequence!=null&&(i.uint32(40),i.uint64(o.sequence)),o.ttl!=null&&(i.uint32(48),i.uint64(o.ttl)),o.pubKey!=null&&(i.uint32(58),i.bytes(o.pubKey)),o.signatureV2!=null&&(i.uint32(66),i.bytes(o.signatureV2)),o.data!=null&&(i.uint32(74),i.bytes(o.data)),s.lengthDelimited!==!1&&i.ldelim()},(o,i,s={})=>{let c={},a=i==null?o.len:o.pos+i;for(;o.pos<a;){let l=o.uint32();switch(l>>>3){case 1:{c.value=o.bytes();break}case 2:{c.signatureV1=o.bytes();break}case 3:{c.validityType=e.ValidityType.codec().decode(o);break}case 4:{c.validity=o.bytes();break}case 5:{c.sequence=o.uint64();break}case 6:{c.ttl=o.uint64();break}case 7:{c.pubKey=o.bytes();break}case 8:{c.signatureV2=o.bytes();break}case 9:{c.data=o.bytes();break}default:{o.skipType(l&7);break}}}return c})),n),e.encode=o=>ar(o,e.codec()),e.decode=(o,i)=>sr(o,e.codec(),i)})($t||($t={}));var np=["string","number","bigint","symbol"],op=["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 Hc(e){if(e===null)return"null";if(e===void 0)return"undefined";if(e===!0||e===!1)return"boolean";let t=typeof e;if(np.includes(t))return t;if(t==="function")return"Function";if(Array.isArray(e))return"Array";if(ip(e))return"Buffer";let r=sp(e);return r||"Object"}function ip(e){return e&&e.constructor&&e.constructor.isBuffer&&e.constructor.isBuffer.call(null,e)}function sp(e){let t=Object.prototype.toString.call(e).slice(8,-1);if(op.includes(t))return t}var x=class{constructor(t,r,n){this.major=t,this.majorEncoded=t<<5,this.name=r,this.terminal=n}toString(){return`Type[${this.major}].${this.name}`}compare(t){return this.major<t.major?-1:this.major>t.major?1:0}};x.uint=new x(0,"uint",!0);x.negint=new x(1,"negint",!0);x.bytes=new x(2,"bytes",!0);x.string=new x(3,"string",!0);x.array=new x(4,"array",!1);x.map=new x(5,"map",!1);x.tag=new x(6,"tag",!1);x.float=new x(7,"float",!0);x.false=new x(7,"false",!0);x.true=new x(7,"true",!0);x.null=new x(7,"null",!0);x.undefined=new x(7,"undefined",!0);x.break=new x(7,"break",!0);var L=class{constructor(t,r,n){this.type=t,this.value=r,this.encodedLength=n,this.encodedBytes=void 0,this.byteValue=void 0}toString(){return`Token[${this.type}].${this.value}`}};var yr=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",ap=new TextDecoder,cp=new TextEncoder;function Xn(e){return yr&&globalThis.Buffer.isBuffer(e)}function ls(e){return e instanceof Uint8Array?Xn(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):e:Uint8Array.from(e)}var jc=yr?(e,t,r)=>r-t>64?globalThis.Buffer.from(e.subarray(t,r)).toString("utf8"):Gc(e,t,r):(e,t,r)=>r-t>64?ap.decode(e.subarray(t,r)):Gc(e,t,r),Yc=yr?e=>e.length>64?globalThis.Buffer.from(e):zc(e):e=>e.length>64?cp.encode(e):zc(e),te=e=>Uint8Array.from(e),gr=yr?(e,t,r)=>Xn(e)?new Uint8Array(e.subarray(t,r)):e.slice(t,r):(e,t,r)=>e.slice(t,r),Wc=yr?(e,t)=>(e=e.map(r=>r instanceof Uint8Array?r:globalThis.Buffer.from(r)),ls(globalThis.Buffer.concat(e,t))):(e,t)=>{let r=new Uint8Array(t),n=0;for(let o of e)n+o.length>r.length&&(o=o.subarray(0,r.length-n)),r.set(o,n),n+=o.length;return r},Xc=yr?e=>globalThis.Buffer.allocUnsafe(e):e=>new Uint8Array(e);function Jn(e,t){if(Xn(e)&&Xn(t))return e.compare(t);for(let r=0;r<e.length;r++)if(e[r]!==t[r])return e[r]<t[r]?-1:1;return 0}function zc(e){let t=[],r=0;for(let n=0;n<e.length;n++){let o=e.charCodeAt(n);o<128?t[r++]=o:o<2048?(t[r++]=o>>6|192,t[r++]=o&63|128):(o&64512)===55296&&n+1<e.length&&(e.charCodeAt(n+1)&64512)===56320?(o=65536+((o&1023)<<10)+(e.charCodeAt(++n)&1023),t[r++]=o>>18|240,t[r++]=o>>12&63|128,t[r++]=o>>6&63|128,t[r++]=o&63|128):(t[r++]=o>>12|224,t[r++]=o>>6&63|128,t[r++]=o&63|128)}return t}function Gc(e,t,r){let n=[];for(;t<r;){let o=e[t],i=null,s=o>239?4:o>223?3:o>191?2:1;if(t+s<=r){let c,a,l,u;switch(s){case 1:o<128&&(i=o);break;case 2:c=e[t+1],(c&192)===128&&(u=(o&31)<<6|c&63,u>127&&(i=u));break;case 3:c=e[t+1],a=e[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=e[t+1],a=e[t+2],l=e[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 up(n)}var Zc=4096;function up(e){let t=e.length;if(t<=Zc)return String.fromCharCode.apply(String,e);let r="",n=0;for(;n<t;)r+=String.fromCharCode.apply(String,e.slice(n,n+=Zc));return r}var fp=256,Xr=class{constructor(t=fp){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 r=this.chunks[this.chunks.length-1];if(this.cursor+t.length<=this.maxCursor+1){let o=r.length-(this.maxCursor-this.cursor)-1;r.set(t,o)}else{if(r){let o=r.length-(this.maxCursor-this.cursor)-1;o<r.length&&(this.chunks[this.chunks.length-1]=r.subarray(0,o),this.maxCursor=this.cursor-1)}t.length<64&&t.length<this.chunkSize?(r=Xc(this.chunkSize),this.chunks.push(r),this.maxCursor+=r.length,this._initReuseChunk===null&&(this._initReuseChunk=r),r.set(t,0)):(this.chunks.push(t),this.maxCursor+=t.length)}this.cursor+=t.length}toBytes(t=!1){let r;if(this.chunks.length===1){let n=this.chunks[0];t&&this.cursor>n.length/2?(r=this.cursor===n.length?n:n.subarray(0,this.cursor),this._initReuseChunk=null,this.chunks=[]):r=gr(n,0,this.cursor)}else r=Wc(this.chunks,this.cursor);return t&&this.reset(),r}};var F="CBOR decode error:",ds="CBOR encode error:",Jr=[];Jr[23]=1;Jr[24]=2;Jr[25]=3;Jr[26]=5;Jr[27]=9;function he(e,t,r){if(e.length-t<r)throw new Error(`${F} not enough data for type`)}var ft=[24,256,65536,4294967296,BigInt("18446744073709551616")];function Bt(e,t,r){he(e,t,1);let n=e[t];if(r.strict===!0&&n<ft[0])throw new Error(`${F} integer encoded in more bytes than necessary (strict decode)`);return n}function _t(e,t,r){he(e,t,2);let n=e[t]<<8|e[t+1];if(r.strict===!0&&n<ft[1])throw new Error(`${F} integer encoded in more bytes than necessary (strict decode)`);return n}function Dt(e,t,r){he(e,t,4);let n=e[t]*16777216+(e[t+1]<<16)+(e[t+2]<<8)+e[t+3];if(r.strict===!0&&n<ft[2])throw new Error(`${F} integer encoded in more bytes than necessary (strict decode)`);return n}function Rt(e,t,r){he(e,t,8);let n=e[t]*16777216+(e[t+1]<<16)+(e[t+2]<<8)+e[t+3],o=e[t+4]*16777216+(e[t+5]<<16)+(e[t+6]<<8)+e[t+7],i=(BigInt(n)<<BigInt(32))+BigInt(o);if(r.strict===!0&&i<ft[3])throw new Error(`${F} integer encoded in more bytes than necessary (strict decode)`);if(i<=Number.MAX_SAFE_INTEGER)return Number(i);if(r.allowBigInt===!0)return i;throw new Error(`${F} integers outside of the safe integer range are not supported`)}function Jc(e,t,r,n){return new L(x.uint,Bt(e,t+1,n),2)}function Qc(e,t,r,n){return new L(x.uint,_t(e,t+1,n),3)}function tu(e,t,r,n){return new L(x.uint,Dt(e,t+1,n),5)}function eu(e,t,r,n){return new L(x.uint,Rt(e,t+1,n),9)}function Ut(e,t){return pt(e,0,t.value)}function pt(e,t,r){if(r<ft[0]){let n=Number(r);e.push([t|n])}else if(r<ft[1]){let n=Number(r);e.push([t|24,n])}else if(r<ft[2]){let n=Number(r);e.push([t|25,n>>>8,n&255])}else if(r<ft[3]){let n=Number(r);e.push([t|26,n>>>24&255,n>>>16&255,n>>>8&255,n&255])}else{let n=BigInt(r);if(n<ft[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,e.push(o)}else throw new Error(`${F} encountered BigInt larger than allowable range`)}}Ut.encodedSize=function(t){return pt.encodedSize(t.value)};pt.encodedSize=function(t){return t<ft[0]?1:t<ft[1]?2:t<ft[2]?3:t<ft[3]?5:9};Ut.compareTokens=function(t,r){return t.value<r.value?-1:t.value>r.value?1:0};function ru(e,t,r,n){return new L(x.negint,-1-Bt(e,t+1,n),2)}function nu(e,t,r,n){return new L(x.negint,-1-_t(e,t+1,n),3)}function ou(e,t,r,n){return new L(x.negint,-1-Dt(e,t+1,n),5)}var hs=BigInt(-1),iu=BigInt(1);function su(e,t,r,n){let o=Rt(e,t+1,n);if(typeof o!="bigint"){let i=-1-o;if(i>=Number.MIN_SAFE_INTEGER)return new L(x.negint,i,9)}if(n.allowBigInt!==!0)throw new Error(`${F} integers outside of the safe integer range are not supported`);return new L(x.negint,hs-BigInt(o),9)}function Qn(e,t){let r=t.value,n=typeof r=="bigint"?r*hs-iu:r*-1-1;pt(e,t.type.majorEncoded,n)}Qn.encodedSize=function(t){let r=t.value,n=typeof r=="bigint"?r*hs-iu:r*-1-1;return n<ft[0]?1:n<ft[1]?2:n<ft[2]?3:n<ft[3]?5:9};Qn.compareTokens=function(t,r){return t.value<r.value?1:t.value>r.value?-1:0};function Qr(e,t,r,n){he(e,t,r+n);let o=gr(e,t+r,t+r+n);return new L(x.bytes,o,r+n)}function au(e,t,r,n){return Qr(e,t,1,r)}function cu(e,t,r,n){return Qr(e,t,2,Bt(e,t+1,n))}function uu(e,t,r,n){return Qr(e,t,3,_t(e,t+1,n))}function fu(e,t,r,n){return Qr(e,t,5,Dt(e,t+1,n))}function lu(e,t,r,n){let o=Rt(e,t+1,n);if(typeof o=="bigint")throw new Error(`${F} 64-bit integer bytes lengths not supported`);return Qr(e,t,9,o)}function to(e){return e.encodedBytes===void 0&&(e.encodedBytes=e.type===x.string?Yc(e.value):e.value),e.encodedBytes}function xr(e,t){let r=to(t);pt(e,t.type.majorEncoded,r.length),e.push(r)}xr.encodedSize=function(t){let r=to(t);return pt.encodedSize(r.length)+r.length};xr.compareTokens=function(t,r){return dp(to(t),to(r))};function dp(e,t){return e.length<t.length?-1:e.length>t.length?1:Jn(e,t)}function tn(e,t,r,n,o){let i=r+n;he(e,t,i);let s=new L(x.string,jc(e,t+r,t+i),i);return o.retainStringBytes===!0&&(s.byteValue=gr(e,t+r,t+i)),s}function du(e,t,r,n){return tn(e,t,1,r,n)}function hu(e,t,r,n){return tn(e,t,2,Bt(e,t+1,n),n)}function pu(e,t,r,n){return tn(e,t,3,_t(e,t+1,n),n)}function mu(e,t,r,n){return tn(e,t,5,Dt(e,t+1,n),n)}function yu(e,t,r,n){let o=Rt(e,t+1,n);if(typeof o=="bigint")throw new Error(`${F} 64-bit integer string lengths not supported`);return tn(e,t,9,o,n)}var gu=xr;function br(e,t,r,n){return new L(x.array,n,r)}function xu(e,t,r,n){return br(e,t,1,r)}function bu(e,t,r,n){return br(e,t,2,Bt(e,t+1,n))}function wu(e,t,r,n){return br(e,t,3,_t(e,t+1,n))}function Eu(e,t,r,n){return br(e,t,5,Dt(e,t+1,n))}function Su(e,t,r,n){let o=Rt(e,t+1,n);if(typeof o=="bigint")throw new Error(`${F} 64-bit integer array lengths not supported`);return br(e,t,9,o)}function vu(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${F} indefinite length items not allowed`);return br(e,t,1,1/0)}function eo(e,t){pt(e,x.array.majorEncoded,t.value)}eo.compareTokens=Ut.compareTokens;eo.encodedSize=function(t){return pt.encodedSize(t.value)};function wr(e,t,r,n){return new L(x.map,n,r)}function Au(e,t,r,n){return wr(e,t,1,r)}function Cu(e,t,r,n){return wr(e,t,2,Bt(e,t+1,n))}function Iu(e,t,r,n){return wr(e,t,3,_t(e,t+1,n))}function Tu(e,t,r,n){return wr(e,t,5,Dt(e,t+1,n))}function Bu(e,t,r,n){let o=Rt(e,t+1,n);if(typeof o=="bigint")throw new Error(`${F} 64-bit integer map lengths not supported`);return wr(e,t,9,o)}function _u(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${F} indefinite length items not allowed`);return wr(e,t,1,1/0)}function ro(e,t){pt(e,x.map.majorEncoded,t.value)}ro.compareTokens=Ut.compareTokens;ro.encodedSize=function(t){return pt.encodedSize(t.value)};function Du(e,t,r,n){return new L(x.tag,r,1)}function Ru(e,t,r,n){return new L(x.tag,Bt(e,t+1,n),2)}function Lu(e,t,r,n){return new L(x.tag,_t(e,t+1,n),3)}function Pu(e,t,r,n){return new L(x.tag,Dt(e,t+1,n),5)}function Uu(e,t,r,n){return new L(x.tag,Rt(e,t+1,n),9)}function no(e,t){pt(e,x.tag.majorEncoded,t.value)}no.compareTokens=Ut.compareTokens;no.encodedSize=function(t){return pt.encodedSize(t.value)};var xp=20,bp=21,wp=22,Ep=23;function Nu(e,t,r,n){if(n.allowUndefined===!1)throw new Error(`${F} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new L(x.null,null,1):new L(x.undefined,void 0,1)}function Ou(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${F} indefinite length items not allowed`);return new L(x.break,void 0,1)}function ps(e,t,r){if(r){if(r.allowNaN===!1&&Number.isNaN(e))throw new Error(`${F} NaN values are not supported`);if(r.allowInfinity===!1&&(e===1/0||e===-1/0))throw new Error(`${F} Infinity values are not supported`)}return new L(x.float,e,t)}function ku(e,t,r,n){return ps(ms(e,t+1),3,n)}function Ku(e,t,r,n){return ps(ys(e,t+1),5,n)}function Vu(e,t,r,n){return ps($u(e,t+1),9,n)}function oo(e,t,r){let n=t.value;if(n===!1)e.push([x.float.majorEncoded|xp]);else if(n===!0)e.push([x.float.majorEncoded|bp]);else if(n===null)e.push([x.float.majorEncoded|wp]);else if(n===void 0)e.push([x.float.majorEncoded|Ep]);else{let o,i=!1;(!r||r.float64!==!0)&&(Fu(n),o=ms(Ht,1),n===o||Number.isNaN(n)?(Ht[0]=249,e.push(Ht.slice(0,3)),i=!0):(qu(n),o=ys(Ht,1),n===o&&(Ht[0]=250,e.push(Ht.slice(0,5)),i=!0))),i||(Sp(n),o=$u(Ht,1),Ht[0]=251,e.push(Ht.slice(0,9)))}}oo.encodedSize=function(t,r){let n=t.value;if(n===!1||n===!0||n===null||n===void 0)return 1;if(!r||r.float64!==!0){Fu(n);let o=ms(Ht,1);if(n===o||Number.isNaN(n))return 3;if(qu(n),o=ys(Ht,1),n===o)return 5}return 9};var Mu=new ArrayBuffer(9),Nt=new DataView(Mu,1),Ht=new Uint8Array(Mu,0);function Fu(e){if(e===1/0)Nt.setUint16(0,31744,!1);else if(e===-1/0)Nt.setUint16(0,64512,!1);else if(Number.isNaN(e))Nt.setUint16(0,32256,!1);else{Nt.setFloat32(0,e);let t=Nt.getUint32(0),r=(t&2139095040)>>23,n=t&8388607;if(r===255)Nt.setUint16(0,31744,!1);else if(r===0)Nt.setUint16(0,(e&2147483648)>>16|n>>13,!1);else{let o=r-127;o<-24?Nt.setUint16(0,0):o<-14?Nt.setUint16(0,(t&2147483648)>>16|1<<24+o,!1):Nt.setUint16(0,(t&2147483648)>>16|o+15<<10|n>>13,!1)}}}function ms(e,t){if(e.length-t<2)throw new Error(`${F} not enough data for float16`);let r=(e[t]<<8)+e[t+1];if(r===31744)return 1/0;if(r===64512)return-1/0;if(r===32256)return NaN;let n=r>>10&31,o=r&1023,i;return n===0?i=o*2**-24:n!==31?i=(o+1024)*2**(n-25):i=o===0?1/0:NaN,r&32768?-i:i}function qu(e){Nt.setFloat32(0,e,!1)}function ys(e,t){if(e.length-t<4)throw new Error(`${F} not enough data for float32`);let r=(e.byteOffset||0)+t;return new DataView(e.buffer,r,4).getFloat32(0,!1)}function Sp(e){Nt.setFloat64(0,e,!1)}function $u(e,t){if(e.length-t<8)throw new Error(`${F} not enough data for float64`);let r=(e.byteOffset||0)+t;return new DataView(e.buffer,r,8).getFloat64(0,!1)}oo.compareTokens=Ut.compareTokens;function Z(e,t,r){throw new Error(`${F} encountered invalid minor (${r}) for major ${e[t]>>>5}`)}function io(e){return()=>{throw new Error(`${F} ${e}`)}}var B=[];for(let e=0;e<=23;e++)B[e]=Z;B[24]=Jc;B[25]=Qc;B[26]=tu;B[27]=eu;B[28]=Z;B[29]=Z;B[30]=Z;B[31]=Z;for(let e=32;e<=55;e++)B[e]=Z;B[56]=ru;B[57]=nu;B[58]=ou;B[59]=su;B[60]=Z;B[61]=Z;B[62]=Z;B[63]=Z;for(let e=64;e<=87;e++)B[e]=au;B[88]=cu;B[89]=uu;B[90]=fu;B[91]=lu;B[92]=Z;B[93]=Z;B[94]=Z;B[95]=io("indefinite length bytes/strings are not supported");for(let e=96;e<=119;e++)B[e]=du;B[120]=hu;B[121]=pu;B[122]=mu;B[123]=yu;B[124]=Z;B[125]=Z;B[126]=Z;B[127]=io("indefinite length bytes/strings are not supported");for(let e=128;e<=151;e++)B[e]=xu;B[152]=bu;B[153]=wu;B[154]=Eu;B[155]=Su;B[156]=Z;B[157]=Z;B[158]=Z;B[159]=vu;for(let e=160;e<=183;e++)B[e]=Au;B[184]=Cu;B[185]=Iu;B[186]=Tu;B[187]=Bu;B[188]=Z;B[189]=Z;B[190]=Z;B[191]=_u;for(let e=192;e<=215;e++)B[e]=Du;B[216]=Ru;B[217]=Lu;B[218]=Pu;B[219]=Uu;B[220]=Z;B[221]=Z;B[222]=Z;B[223]=Z;for(let e=224;e<=243;e++)B[e]=io("simple values are not supported");B[244]=Z;B[245]=Z;B[246]=Z;B[247]=Nu;B[248]=io("simple values are not supported");B[249]=ku;B[250]=Ku;B[251]=Vu;B[252]=Z;B[253]=Z;B[254]=Z;B[255]=Ou;var zt=[];for(let e=0;e<24;e++)zt[e]=new L(x.uint,e,1);for(let e=-1;e>=-24;e--)zt[31-e]=new L(x.negint,e,1);zt[64]=new L(x.bytes,new Uint8Array(0),1);zt[96]=new L(x.string,"",1);zt[128]=new L(x.array,0,1);zt[160]=new L(x.map,0,1);zt[244]=new L(x.false,!1,1);zt[245]=new L(x.true,!0,1);zt[246]=new L(x.null,null,1);function Hu(e){switch(e.type){case x.false:return te([244]);case x.true:return te([245]);case x.null:return te([246]);case x.bytes:return e.value.length?void 0:te([64]);case x.string:return e.value===""?te([96]):void 0;case x.array:return e.value===0?te([128]):void 0;case x.map:return e.value===0?te([160]):void 0;case x.uint:return e.value<24?te([Number(e.value)]):void 0;case x.negint:if(e.value>=-24)return te([31-Number(e.value)])}}var Gu=Object.freeze({float64:!0,mapSorter:Tp,quickEncodeToken:Hu});function Ap(){let e=[];return e[x.uint.major]=Ut,e[x.negint.major]=Qn,e[x.bytes.major]=xr,e[x.string.major]=gu,e[x.array.major]=eo,e[x.map.major]=ro,e[x.tag.major]=no,e[x.float.major]=oo,e}var Cp=Ap(),gs=new Xr,ao=class e{constructor(t,r){this.obj=t,this.parent=r}includes(t){let r=this;do if(r.obj===t)return!0;while(r=r.parent);return!1}static createCheck(t,r){if(t&&t.includes(r))throw new Error(`${ds} object contains circular references`);return new e(r,t)}},Ce={null:new L(x.null,null),undefined:new L(x.undefined,void 0),true:new L(x.true,!0),false:new L(x.false,!1),emptyArray:new L(x.array,0),emptyMap:new L(x.map,0)},Ie={number(e,t,r,n){return!Number.isInteger(e)||!Number.isSafeInteger(e)?new L(x.float,e):e>=0?new L(x.uint,e):new L(x.negint,e)},bigint(e,t,r,n){return e>=BigInt(0)?new L(x.uint,e):new L(x.negint,e)},Uint8Array(e,t,r,n){return new L(x.bytes,e)},string(e,t,r,n){return new L(x.string,e)},boolean(e,t,r,n){return e?Ce.true:Ce.false},null(e,t,r,n){return Ce.null},undefined(e,t,r,n){return Ce.undefined},ArrayBuffer(e,t,r,n){return new L(x.bytes,new Uint8Array(e))},DataView(e,t,r,n){return new L(x.bytes,new Uint8Array(e.buffer,e.byteOffset,e.byteLength))},Array(e,t,r,n){if(!e.length)return r.addBreakTokens===!0?[Ce.emptyArray,new L(x.break)]:Ce.emptyArray;n=ao.createCheck(n,e);let o=[],i=0;for(let s of e)o[i++]=so(s,r,n);return r.addBreakTokens?[new L(x.array,e.length),o,new L(x.break)]:[new L(x.array,e.length),o]},Object(e,t,r,n){let o=t!=="Object",i=o?e.keys():Object.keys(e),s=o?e.size:i.length;if(!s)return r.addBreakTokens===!0?[Ce.emptyMap,new L(x.break)]:Ce.emptyMap;n=ao.createCheck(n,e);let c=[],a=0;for(let l of i)c[a++]=[so(l,r,n),so(o?e.get(l):e[l],r,n)];return Ip(c,r),r.addBreakTokens?[new L(x.map,s),c,new L(x.break)]:[new L(x.map,s),c]}};Ie.Map=Ie.Object;Ie.Buffer=Ie.Uint8Array;for(let e of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))Ie[`${e}Array`]=Ie.DataView;function so(e,t={},r){let n=Hc(e),o=t&&t.typeEncoders&&t.typeEncoders[n]||Ie[n];if(typeof o=="function"){let s=o(e,n,t,r);if(s!=null)return s}let i=Ie[n];if(!i)throw new Error(`${ds} unsupported type: ${n}`);return i(e,n,t,r)}function Ip(e,t){t.mapSorter&&e.sort(t.mapSorter)}function Tp(e,t){if(e[0]instanceof L&&t[0]instanceof L){let r=e[0],n=t[0];return r._keyBytes||(r._keyBytes=zu(r.value)),n._keyBytes||(n._keyBytes=zu(n.value)),Jn(r._keyBytes,n._keyBytes)}throw new Error("rfc8949MapSorter: complex key types are not supported yet")}function zu(e){return Bp(e,Cp,Gu)}function Zu(e,t,r,n){if(Array.isArray(t))for(let o of t)Zu(e,o,r,n);else r[t.type.major](e,t,n)}function Bp(e,t,r){let n=so(e,r);if(!Array.isArray(n)&&r.quickEncodeToken){let o=r.quickEncodeToken(n);if(o)return o;let i=t[n.type.major];if(i.encodedSize){let s=i.encodedSize(n,r),c=new Xr(s);if(i(c,n,r),c.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${n} was wrong`);return ls(c.chunks[0])}}return gs.reset(),Zu(gs,n,t,r),gs.toBytes(!0)}var _p={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},co=class{constructor(t,r={}){this._pos=0,this.data=t,this.options=r}pos(){return this._pos}done(){return this._pos>=this.data.length}next(){let t=this.data[this._pos],r=zt[t];if(r===void 0){let n=B[t];if(!n)throw new Error(`${F} no decoder for major type ${t>>>5} (byte 0x${t.toString(16).padStart(2,"0")})`);let o=t&31;r=n(this.data,this._pos,o,this.options)}return this._pos+=r.encodedLength,r}},en=Symbol.for("DONE"),uo=Symbol.for("BREAK");function Dp(e,t,r){let n=[];for(let o=0;o<e.value;o++){let i=Er(t,r);if(i===uo){if(e.value===1/0)break;throw new Error(`${F} got unexpected break to lengthed array`)}if(i===en)throw new Error(`${F} found array but not enough entries (got ${o}, expected ${e.value})`);n[o]=i}return n}function Rp(e,t,r){let n=r.useMaps===!0,o=n?void 0:{},i=n?new Map:void 0;for(let s=0;s<e.value;s++){let c=Er(t,r);if(c===uo){if(e.value===1/0)break;throw new Error(`${F} got unexpected break to lengthed map`)}if(c===en)throw new Error(`${F} found map but not enough entries (got ${s} [no key], expected ${e.value})`);if(n!==!0&&typeof c!="string")throw new Error(`${F} non-string keys not supported (got ${typeof c})`);if(r.rejectDuplicateMapKeys===!0&&(n&&i.has(c)||!n&&c in o))throw new Error(`${F} found repeat map key "${c}"`);let a=Er(t,r);if(a===en)throw new Error(`${F} found map but not enough entries (got ${s} [no value], expected ${e.value})`);n?i.set(c,a):o[c]=a}return n?i:o}function Er(e,t){if(e.done())return en;let r=e.next();if(r.type===x.break)return uo;if(r.type.terminal)return r.value;if(r.type===x.array)return Dp(r,e,t);if(r.type===x.map)return Rp(r,e,t);if(r.type===x.tag){if(t.tags&&typeof t.tags[r.value]=="function"){let n=Er(e,t);return t.tags[r.value](n)}throw new Error(`${F} tag not supported (${r.value})`)}throw new Error("unsupported")}function ju(e,t){if(!(e instanceof Uint8Array))throw new Error(`${F} data to decode must be a Uint8Array`);t=Object.assign({},_p,t);let r=t.tokenizer||new co(e,t),n=Er(r,t);if(n===en)throw new Error(`${F} did not find any content to decode`);if(n===uo)throw new Error(`${F} got unexpected break`);return[n,e.subarray(r.pos())]}function xs(e,t){let[r,n]=ju(e,t);if(n.length>0)throw new Error(`${F} too many terminals, data makes no sense`);return r}var Up=me("ipns:utils"),Yu=H("/ipns/");var Np=0,Op=18;function Wu(e){let t;if(e.pubKey!=null)try{t=vc(e.pubKey)}catch(r){throw Up.error(r),r}if(t!=null)return t}function Xu(e){let t=H("ipns-signature:");return Lt([t,e])}function rn(e){return"signatureV1"in e?$t.encode({value:H(e.value),signatureV1:e.signatureV1,validityType:e.validityType,validity:H(e.validity),sequence:e.sequence,ttl:e.ttl,pubKey:e.pubKey,signatureV2:e.signatureV2,data:e.data}):$t.encode({pubKey:e.pubKey,signatureV2:e.signatureV2,data:e.data})}function Te(e){let t=$t.decode(e);if(t.sequence!=null&&(t.sequence=BigInt(t.sequence)),t.ttl!=null&&(t.ttl=BigInt(t.ttl)),t.signatureV2==null||t.data==null)throw new qt("Missing data or signatureV2");let r=Ju(t.data),n=kp(r.Value),o=z(r.Validity);if(t.value!=null&&t.signatureV1!=null)return Kp(t),{value:n,validityType:$t.ValidityType.EOL,validity:o,sequence:r.Sequence,ttl:r.TTL,pubKey:t.pubKey,signatureV1:t.signatureV1,signatureV2:t.signatureV2,data:t.data};if(t.signatureV2!=null)return{value:n,validityType:$t.ValidityType.EOL,validity:o,sequence:r.Sequence,ttl:r.TTL,pubKey:t.pubKey,signatureV2:t.signatureV2,data:t.data};throw new Error("invalid record: does not include signatureV1 or signatureV2")}function nn(e){return Lt([Yu,e.bytes])}function Sr(e){let t=ye(e.slice(Yu.length));if(!fo(t,Np)&&!fo(t,Op))throw new He("Multihash in IPNS key was not identity or sha2-256");return t}function Ju(e){let t=xs(e);if(t.ValidityType===0)t.ValidityType=$t.ValidityType.EOL;else throw new mr("The validity type is unsupported");return Number.isInteger(t.Sequence)&&(t.Sequence=BigInt(t.Sequence)),Number.isInteger(t.TTL)&&(t.TTL=BigInt(t.TTL)),t}function kp(e){let t=z(e).trim();if(t.startsWith("/"))return t;try{return`/ipfs/${j.decode(e).toV1().toString()}`}catch{}try{return`/ipfs/${j.parse(t).toV1().toString()}`}catch{}throw new Yn("Value must be a valid content path starting with /")}function Kp(e){if(e.data==null)throw new Wn("Record data is missing");let t=Ju(e.data);if(!J(t.Value,e.value??new Uint8Array(0)))throw new qt('Field "value" did not match between protobuf and CBOR');if(!J(t.Validity,e.validity??new Uint8Array(0)))throw new qt('Field "validity" did not match between protobuf and CBOR');if(t.ValidityType!==e.validityType)throw new qt('Field "validityType" did not match between protobuf and CBOR');if(t.Sequence!==e.sequence)throw new qt('Field "sequence" did not match between protobuf and CBOR');if(t.TTL!==e.ttl)throw new qt('Field "ttl" did not match between protobuf and CBOR')}function fo(e,t){return e.code===t}var n1=me("ipns"),o1=300*1e9,Mp="/ipns/",i1=Mp.length;var Qu=xo(fs(),1);var lo=me("ipns:validator"),Fp=1024*10;async function qp(e,t){let r=Te(t),n;try{let o=Xu(r.data);n=await e.verify(o,r.signatureV2)}catch{n=!1}if(!n)throw lo.error("record signature verification failed"),new qt("Record signature verification failed");if(r.validityType===$t.ValidityType.EOL){if(Qu.default.fromString(r.validity).toDate().getTime()<Date.now())throw lo.error("record has expired"),new Zn("record has expired")}else if(r.validityType!=null)throw lo.error("the validity type is unsupported"),new mr("The validity type is unsupported");lo("ipns record for %s is valid",r.value)}async function tf(e,t){if(t.byteLength>Fp)throw new jn("The record is too large");let r=Sr(e),n;fo(r,0)&&(n=On(r));let o=Te(t),i=Wu(o)??n;if(i==null)throw new Wr("Could not extract public key from IPNS record or routing key");let s=nn(i.toMultihash());if(!J(s,e))throw new Wr("Embedded public key did not match routing key");await qp(i,t)}var ho=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MESSAGE_LENGTH"};async function*vr(e,t={}){let r=/\r?\n/,n=new TextDecoder("utf8"),o="";for await(let i of e){if(typeof i=="string"&&(i=new TextEncoder().encode(i)),Ye(i)&&(i=i.subarray()),o+=n.decode(i,{stream:!0}),o.length>(t?.maxMessageLength??o.length))throw new ho("Incoming message too long");let s=o.split(r);o=s.pop()??"";for(let c=0;c<s.length;c++)yield JSON.parse(s[c])}o+=n.decode(),o!==""&&(yield JSON.parse(o))}function Ot(){let e={};return e.promise=new Promise((t,r)=>{e.resolve=t,e.reject=r}),e}var ws=xo(rf(),1);var Es=class e extends Error{name="TimeoutError";constructor(t,r){super(t,r),Error.captureStackTrace?.(this,e)}},nf=e=>e.reason??new DOMException("This operation was aborted.","AbortError");function Ss(e,t){let{milliseconds:r,fallback:n,message:o,customTimers:i={setTimeout,clearTimeout},signal:s}=t,c,a,u=new Promise((f,y)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(s?.aborted){y(nf(s));return}if(s&&(a=()=>{y(nf(s))},s.addEventListener("abort",a,{once:!0})),e.then(f,y),r===Number.POSITIVE_INFINITY)return;let E=new Es;c=i.setTimeout.call(void 0,()=>{if(n){try{f(n())}catch(b){y(b)}return}typeof e.cancel=="function"&&e.cancel(),o===!1?f():o instanceof Error?y(o):(E.message=o??`Promise timed out after ${r} milliseconds`,y(E))},r)}).finally(()=>{u.clear(),a&&s&&s.removeEventListener("abort",a)});return u.clear=()=>{i.clearTimeout.call(void 0,c),c=void 0},u}function vs(e,t,r){let n=0,o=e.length;for(;o>0;){let i=Math.trunc(o/2),s=n+i;r(e[s],t)<=0?(n=++s,o-=i+1):o=i}return n}var sn=class{#t=[];enqueue(t,r){let{priority:n=0,id:o}=r??{},i={priority:n,id:o,run:t};if(this.size===0||this.#t[this.size-1].priority>=n){this.#t.push(i);return}let s=vs(this.#t,i,(c,a)=>a.priority-c.priority);this.#t.splice(s,0,i)}setPriority(t,r){let n=this.#t.findIndex(i=>i.id===t);if(n===-1)throw new ReferenceError(`No promise function with the id "${t}" exists in the queue.`);let[o]=this.#t.splice(n,1);this.enqueue(o.run,{priority:r,id:t})}dequeue(){return this.#t.shift()?.run}filter(t){return this.#t.filter(r=>r.priority===t.priority).map(r=>r.run)}get size(){return this.#t.length}};var an=class extends ws.default{#t;#n;#e=0;#h;#m=!1;#x=!1;#c;#I=0;#b=0;#u;#f;#a;#s=[];#i=0;#r;#T;#o=0;#y;#l;#L=1n;#g=new Map;timeout;constructor(t){if(super(),t={carryoverIntervalCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:sn,strict:!1,...t},!(typeof t.intervalCap=="number"&&t.intervalCap>=1))throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${t.intervalCap?.toString()??""}\` (${typeof t.intervalCap})`);if(t.interval===void 0||!(Number.isFinite(t.interval)&&t.interval>=0))throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${t.interval?.toString()??""}\` (${typeof t.interval})`);if(t.strict&&t.interval===0)throw new TypeError("The `strict` option requires a non-zero `interval`");if(t.strict&&t.intervalCap===Number.POSITIVE_INFINITY)throw new TypeError("The `strict` option requires a finite `intervalCap`");if(this.#t=t.carryoverIntervalCount??t.carryoverConcurrencyCount??!1,this.#n=t.intervalCap===Number.POSITIVE_INFINITY||t.interval===0,this.#h=t.intervalCap,this.#c=t.interval,this.#a=t.strict,this.#r=new t.queueClass,this.#T=t.queueClass,this.concurrency=t.concurrency,t.timeout!==void 0&&!(Number.isFinite(t.timeout)&&t.timeout>0))throw new TypeError(`Expected \`timeout\` to be a positive finite number, got \`${t.timeout}\` (${typeof t.timeout})`);this.timeout=t.timeout,this.#l=t.autoStart===!1,this.#M()}#w(t){for(;this.#i<this.#s.length;){let n=this.#s[this.#i];if(n!==void 0&&t-n>=this.#c)this.#i++;else break}(this.#i>100&&this.#i>this.#s.length/2||this.#i===this.#s.length)&&(this.#s=this.#s.slice(this.#i),this.#i=0)}#P(t){this.#a?this.#s.push(t):this.#e++}#U(){this.#a?this.#s.length>this.#i&&this.#s.pop():this.#e>0&&this.#e--}#E(){return this.#s.length-this.#i}get#N(){return this.#n?!0:this.#a?this.#E()<this.#h:this.#e<this.#h}get#O(){return this.#o<this.#y}#k(){this.#o--,this.#o===0&&this.emit("pendingZero"),this.#A(),this.emit("next")}#K(){this.#f=void 0,this.#D(),this.#_()}#V(t){if(this.#a){if(this.#w(t),this.#E()>=this.#h){let n=this.#s[this.#i],o=this.#c-(t-n);return this.#S(o),!0}return!1}if(this.#u===void 0){let r=this.#I-t;if(r<0){if(this.#b>0){let n=t-this.#b;if(n<this.#c)return this.#S(this.#c-n),!0}this.#e=this.#t?this.#o:0}else return this.#S(r),!0}return!1}#S(t){this.#f===void 0&&(this.#f=setTimeout(()=>{this.#K()},t))}#v(){this.#u&&(clearInterval(this.#u),this.#u=void 0)}#B(){this.#f&&(clearTimeout(this.#f),this.#f=void 0)}#A(){if(this.#r.size===0){if(this.#v(),this.emit("empty"),this.#o===0){if(this.#B(),this.#a&&this.#i>0){let r=Date.now();this.#w(r)}this.emit("idle")}return!1}let t=!1;if(!this.#l){let r=Date.now(),n=!this.#V(r);if(this.#N&&this.#O){let o=this.#r.dequeue();this.#n||(this.#P(r),this.#p()),this.emit("active"),o(),n&&this.#_(),t=!0}}return t}#_(){this.#n||this.#u!==void 0||this.#a||(this.#u=setInterval(()=>{this.#D()},this.#c),this.#I=Date.now()+this.#c)}#D(){this.#a||(this.#e===0&&this.#o===0&&this.#u&&this.#v(),this.#e=this.#t?this.#o:0),this.#C(),this.#p()}#C(){for(;this.#A(););}get concurrency(){return this.#y}set concurrency(t){if(!(typeof t=="number"&&t>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${t}\` (${typeof t})`);this.#y=t,this.#C()}setPriority(t,r){if(typeof r!="number"||!Number.isFinite(r))throw new TypeError(`Expected \`priority\` to be a finite number, got \`${r}\` (${typeof r})`);this.#r.setPriority(t,r)}async add(t,r={}){return r={timeout:this.timeout,...r,id:r.id??(this.#L++).toString()},new Promise((n,o)=>{let i=Symbol(`task-${r.id}`);this.#r.enqueue(async()=>{this.#o++,this.#g.set(i,{id:r.id,priority:r.priority??0,startTime:Date.now(),timeout:r.timeout});let s;try{try{r.signal?.throwIfAborted()}catch(l){throw this.#F(),this.#g.delete(i),l}this.#b=Date.now();let c=t({signal:r.signal});if(r.timeout&&(c=Ss(Promise.resolve(c),{milliseconds:r.timeout,message:`Task timed out after ${r.timeout}ms (queue has ${this.#o} running, ${this.#r.size} waiting)`})),r.signal){let{signal:l}=r;c=Promise.race([c,new Promise((u,f)=>{s=()=>{f(l.reason)},l.addEventListener("abort",s,{once:!0})})])}let a=await c;n(a),this.emit("completed",a)}catch(c){o(c),this.emit("error",c)}finally{s&&r.signal?.removeEventListener("abort",s),this.#g.delete(i),queueMicrotask(()=>{this.#k()})}},r),this.emit("add"),this.#A()})}async addAll(t,r){return Promise.all(t.map(async n=>this.add(n,r)))}start(){return this.#l?(this.#l=!1,this.#C(),this):this}pause(){this.#l=!0}clear(){this.#r=new this.#T,this.#v(),this.#R(),this.emit("empty"),this.#o===0&&(this.#B(),this.emit("idle")),this.emit("next")}async onEmpty(){this.#r.size!==0&&await this.#d("empty")}async onSizeLessThan(t){this.#r.size<t||await this.#d("next",()=>this.#r.size<t)}async onIdle(){this.#o===0&&this.#r.size===0||await this.#d("idle")}async onPendingZero(){this.#o!==0&&await this.#d("pendingZero")}async onRateLimit(){this.isRateLimited||await this.#d("rateLimit")}async onRateLimitCleared(){this.isRateLimited&&await this.#d("rateLimitCleared")}onError(){return new Promise((t,r)=>{let n=o=>{this.off("error",n),r(o)};this.on("error",n)})}async#d(t,r){return new Promise(n=>{let o=()=>{r&&!r()||(this.off(t,o),n())};this.on(t,o)})}get size(){return this.#r.size}sizeBy(t){return this.#r.filter(t).length}get pending(){return this.#o}get isPaused(){return this.#l}#M(){this.#n||(this.on("add",()=>{this.#r.size>0&&this.#p()}),this.on("next",()=>{this.#p()}))}#p(){this.#n||this.#x||(this.#x=!0,queueMicrotask(()=>{this.#x=!1,this.#R()}))}#F(){this.#n||(this.#U(),this.#p())}#R(){let t=this.#m;if(this.#n||this.#r.size===0){t&&(this.#m=!1,this.emit("rateLimitCleared"));return}let r;if(this.#a){let o=Date.now();this.#w(o),r=this.#E()}else r=this.#e;let n=r>=this.#h;n!==t&&(this.#m=n,this.emit(n?"rateLimit":"rateLimitCleared"))}get isRateLimited(){return this.#m}get isSaturated(){return this.#o===this.#y&&this.#r.size>0||this.isRateLimited&&this.#r.size>0}get runningTasks(){return[...this.#g.values()].map(t=>({...t}))}};var Fe=class extends Error{static name="InvalidRequestError";constructor(t="Invalid request"){super(t),this.name="InvalidRequestError"}},kt=class extends Error{static name="BadResponseError";constructor(t="Bad response"){super(t),this.name="BadResponseError"}};function zp(e){return e[Symbol.asyncIterator]!=null}function Gp(e){if(zp(e))return(async()=>{for await(let t of e)return t})();for(let t of e)return t}var of=Gp;function Zp(e){let[t,r]=e[Symbol.asyncIterator]!=null?[e[Symbol.asyncIterator](),Symbol.asyncIterator]:[e[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(),[r](){return this}}}var sf=Zp;function jp(e){return e[Symbol.asyncIterator]!=null}function Yp(e,t){let r=0;if(jp(e))return(async function*(){for await(let a of e)yield t(a,r++)})();let n=sf(e),{value:o,done:i}=n.next();if(i===!0)return(function*(){})();let s=t(o,r++);if(typeof s.then=="function")return(async function*(){yield await s;for(let a of n)yield t(a,r++)})();let c=t;return(function*(){yield s;for(let a of n)yield c(a,r++)})()}var af=Yp;var cf=H("/ipns/");function uf(e){return J(e.subarray(0,cf.byteLength),cf)}var mo=class{client;constructor(t){this.client=t}async*findProviders(t,r={}){try{yield*af(this.client.getProviders(t,r),n=>({id:n.ID,multiaddrs:n.Addrs??[],routing:"delegated-http-routing-v1"}))}catch(n){if(n instanceof jt)return;throw n}}async provide(){}async cancelReprovide(){}async put(t,r,n){if(!uf(t))return;let o=Sr(t),i=j.createV1(114,o),s=Te(r);await this.client.putIPNS(i,s,n)}async get(t,r){if(!uf(t))throw new jt("Not found");let n=Sr(t),o=j.createV1(114,n);try{let i=await this.client.getIPNS(o,r);return rn(i)}catch(i){throw i.name==="BadResponseError"?new jt("Not found"):i}}toString(){return`DelegatedRoutingV1HttpApiClientContentRouting(${this.client.url})`}},yo=class{client;constructor(t){this.client=t}async findPeer(t,r={}){let n=await of(this.client.getPeers(t,r));if(n!=null)return{id:n.ID,multiaddrs:n.Addrs??[]};throw new jt("Not found")}async*getClosestPeers(t,r={}){let n;try{n=j.decode(t)}catch{n=Mn(Yt.decode(t))}for await(let o of this.client.getClosestPeers(n,r))yield{id:o.ID,multiaddrs:o.Addrs??[]}}toString(){return`DelegatedRoutingV1HttpApiClientPeerRouting(${this.client.url})`}};var go={concurrentRequests:4,timeout:3e4,cacheTTL:300*1e3,cacheName:"delegated-routing-v1-cache"},cn=class{url;started;httpQueue;shutDownController;timeout;contentRouting;peerRouting;filterAddrs;filterProtocols;inFlightRequests;cacheName;cache;cacheTTL;log;constructor(t,r){this.log=t.logger.forComponent("delegated-routing-v1-http-api-client"),this.started=!1,this.shutDownController=new AbortController,this.shutDownController.signal,this.httpQueue=new an({concurrency:r.concurrentRequests??go.concurrentRequests}),this.inFlightRequests=new Map,this.url=r.url instanceof URL?r.url:new URL(r.url),this.timeout=r.timeout??go.timeout,this.filterAddrs=r.filterAddrs,this.filterProtocols=r.filterProtocols,this.contentRouting=new mo(this),this.peerRouting=new yo(this),this.cacheName=r.cacheName??go.cacheName,this.cacheTTL=r.cacheTTL??go.cacheTTL}get[Vs](){return this.contentRouting}get[Fs](){return this.peerRouting}isStarted(){return this.started}async start(){this.started||(this.started=!0,this.cacheTTL>0&&(this.cache=await globalThis.caches?.open(this.cacheName),this.cache!=null&&this.log("cache enabled with ttl %d",this.cacheTTL)))}async stop(){this.httpQueue.clear(),this.shutDownController.abort(),await globalThis.caches?.delete(this.cacheName),this.started=!1}async*getProviders(t,r={}){this.log("getProviders starts: %c",t);let n=AbortSignal.timeout(this.timeout),o=pr([this.shutDownController.signal,n,r.signal]);let i=Ot(),s=Ot(),c=0;this.httpQueue.add(async()=>(i.resolve(),s.promise));try{await i.promise;let a=new URL(`${this.url}routing/v1/providers/${t}`);this.#n(a,r.filterAddrs,r.filterProtocols);let l={headers:{accept:"application/x-ndjson, application/json;q=0.8"},signal:o},u=await this.#e(a.toString(),l);if(!u.ok){if(u.status===404)return;throw u.status===422?new Fe("Request does not conform to schema or semantic constraints"):new kt(`Unexpected status code: ${u.status}`)}let f=u.headers.get("Content-Type");if(f==null)throw new kt("No Content-Type header received");if(u.body==null){if(f!=="application/x-ndjson")throw new kt("Routing response had no body");return}if(f.startsWith("application/json")){let E=(await u.json()).Providers??[];for(let b of E){let I=this.#t(b);I!=null&&(c++,yield I)}}else if(f.includes("application/x-ndjson"))for await(let y of vr(Yr(u.body))){let E=this.#t(y);E!=null&&(c++,yield E)}else throw new kt(`Unsupported Content-Type: ${f}`)}finally{o.clear(),s.resolve(),this.log("getProviders finished found %d providers for %c",c,t)}}async*getPeers(t,r={}){this.log("getPeers starts: %c",t);let n=AbortSignal.timeout(this.timeout),o=pr([this.shutDownController.signal,n,r.signal]);let i=Ot(),s=Ot();this.httpQueue.add(async()=>(i.resolve(),s.promise));try{await i.promise;let c=new URL(`${this.url}routing/v1/peers/${t.toCID().toString()}`);this.#n(c,r.filterAddrs,r.filterProtocols);let a={headers:{Accept:"application/x-ndjson"},signal:o},l=await this.#e(c.toString(),a);if(l.status===404)return;if(l.status===422)throw new Fe("Request does not conform to schema or semantic constraints");if(l.body==null)throw new kt("Routing response had no body");if(l.headers.get("Content-Type")?.startsWith("application/json")){let y=(await l.json()).Peers??[];for(let E of y){let b=this.#t(E);b!=null&&(yield b)}}else for await(let f of vr(Yr(l.body))){let y=this.#t(f);y!=null&&(yield y)}}catch(c){this.log.error("getPeers errored - %e",c)}finally{o.clear(),s.resolve(),this.log("getPeers finished: %c",t)}}async*getClosestPeers(t,r={}){let n;if(Ms(t))n=t.toCID().toString();else if(j.asCID(t)===t||t instanceof j)n=t.toV1().toString();else throw new ot("Key must be CID or PeerId");this.log("getClosestPeers starts: %s",n);let o=AbortSignal.timeout(this.timeout),i=pr([this.shutDownController.signal,o,r.signal]);let s=Ot(),c=Ot();this.httpQueue.add(async()=>(s.resolve(),c.promise));try{await s.promise;let a=new URL(`${this.url}routing/v1/dht/closest/peers/${n}`);this.#n(a,r.filterAddrs,r.filterProtocols);let l={headers:{Accept:"application/x-ndjson"},signal:i},u=await this.#e(a.toString(),l);if(u.status===404)return;if(u.status===422)throw new Fe("Request does not conform to schema or semantic constraints");if(u.body==null)throw new kt("Routing response had no body");if(u.headers.get("Content-Type")?.startsWith("application/json")){let E=(await u.json()).Peers??[];for(let b of E){let I=this.#t(b);I!=null&&(yield I)}}else for await(let y of vr(Yr(u.body))){let E=this.#t(y);E!=null&&(yield E)}}catch(a){this.log.error("getClosestPeers errored - %e",a)}finally{i.clear(),c.resolve(),this.log("getClosestPeers finished: %s",n)}}async getIPNS(t,r={}){this.log("getIPNS starts: %s",t);let n=AbortSignal.timeout(this.timeout),o=pr([this.shutDownController.signal,n,r.signal]);let i=Ot(),s=Ot();this.httpQueue.add(async()=>(i.resolve(),s.promise));let c=`${this.url}routing/v1/ipns/${t}`;try{await i.promise;let a={headers:{Accept:"application/vnd.ipfs.ipns-record"},signal:o},l=await this.#e(c,a);if(this.log("getIPNS GET %s %d",c,l.status),l.status===404)throw new jt("No matching records found");if(l.status===422)throw new Fe("Request does not conform to schema or semantic constraints");if(!l.ok)throw new kt(`Unexpected status code: ${l.status}`);let u=l.headers.get("Content-Type");if(u==null||!u.includes("application/vnd.ipfs.ipns-record"))throw new jt("No matching records found");if(l.body==null)throw new kt("GET ipns response had no body");let f=await l.arrayBuffer(),y=new Uint8Array(f,0,f.byteLength);return r.validate!==!1&&await tf(nn(t.multihash),y),Te(y)}catch(a){throw this.log.error("getIPNS GET %s error - %e",c,a),a}finally{o.clear(),s.resolve(),this.log("getIPNS finished: %s",t)}}async putIPNS(t,r,n={}){this.log("putIPNS starts: %c",t);let o=AbortSignal.timeout(this.timeout),i=pr([this.shutDownController.signal,o,n.signal]);let s=Ot(),c=Ot();this.httpQueue.add(async()=>(s.resolve(),c.promise));let a=`${this.url}routing/v1/ipns/${t}`;try{await s.promise;let l=rn(r),u={method:"PUT",headers:{"Content-Type":"application/vnd.ipfs.ipns-record"},body:l,signal:i},f=await this.#e(a,u);if(this.log("putIPNS PUT %s %d",a,f.status),f.status!==200)throw new kt("PUT ipns response had status other than 200")}catch(l){throw this.log.error("putIPNS PUT %s error - %e",a,l.stack),l}finally{i.clear(),c.resolve(),this.log("putIPNS finished: %c",t)}}#t(t){try{let r=[],n=t.Addrs?.map($c)??[];return t.Protocols!=null&&r.push(...t.Protocols),t.Protocol!=null&&(r.push(t.Protocol),delete t.Protocol),{...t,Schema:"peer",ID:Ic(t.ID),Addrs:n,Protocols:r}}catch(r){this.log.error("could not conform record to peer schema - %e",r)}}#n(t,r,n){if(r!=null||this.filterAddrs!=null){let o=r?.join(",")??this.filterAddrs?.join(",")??"";o!==""&&t.searchParams.set("filter-addrs",o)}if(n!=null||this.filterProtocols!=null){let o=n?.join(",")??this.filterProtocols?.join(",")??"";o!==""&&t.searchParams.set("filter-protocols",o)}}async#e(t,r){let n=r.method??"GET",o=`${n}-${t}`;if(n==="GET"){let a=await this.cache?.match(t);if(a!=null){if(parseInt(a.headers.get("x-cache-expires")??"0",10)>Date.now())return this.log("returning cached response for %s",o),this.logResponse(a),a;this.log("evicting cached response for %s",o),await this.cache?.delete(t)}else this.cache!=null&&this.log("cache miss for %s",o)}let i=this.inFlightRequests.get(o);if(i!=null){let a=await i;return this.log("deduplicating outgoing request for %s",o),a.clone()}this.log("outgoing request:"),this.logRequest(t,r);let s=fetch(t,r).then(async a=>{if(this.log("incoming response:"),this.logResponse(a),this.cache!=null&&a.ok&&n==="GET"){let l=Date.now()+this.cacheTTL,u=new Headers(a.headers);u.set("x-cache-expires",l.toString());let f=new Response(a.clone().body,{status:a.status,statusText:a.statusText,headers:u});await this.cache.put(t,f)}return a}).finally(()=>{this.inFlightRequests.delete(o)});return this.inFlightRequests.set(o,s),await s}toString(){return`DefaultDelegatedRoutingV1HttpApiClient(${this.url})`}logRequest(t,r){let n=new Headers(r.headers);this.log("%s %s HTTP/1.1",r.method??"GET",t);for(let[o,i]of n.entries())this.log("%s: %s",o,i)}logResponse(t){this.log("HTTP/1.1 %d %s",t.status,t.statusText);for(let[r,n]of t.headers.entries())this.log("%s: %s",r,n)}};function Wp(e,t={}){return new cn({logger:Ks()},{...t,url:new URL(e)})}function Xp(e){return t=>new cn(t,e)}return mf(Jp);})();
14
14
  /*! Bundled license information:
15
15
 
16
16
  @noble/hashes/utils.js: