@helia/delegated-routing-v1-http-api-client 5.2.0 → 6.0.0
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/README.md +26 -11
- package/dist/index.min.js +5 -5
- package/dist/index.min.js.map +4 -4
- package/dist/src/index.d.ts +30 -21
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +25 -26
- package/dist/src/index.js.map +1 -1
- package/dist/typedoc-urls.json +0 -2
- package/package.json +2 -2
- package/src/index.ts +31 -28
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
|
|
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(`
|
|
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 Is=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),bt=(e,t)=>{for(var r in t)un(e,r,{get:t[r],enumerable:!0})},Ts=(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 xo=(e,t,r)=>(r=e!=null?uf(df(e)):{},Ts(t||!e||!e.__esModule?un(r,"default",{value:e,enumerable:!0}):r,e)),pf=e=>Ts(un({},"__esModule",{value:!0}),e);var fs=Is((Mb,us)=>{var Vb=(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 ef=Is((I1,bs)=>{"use strict";var qp=Object.prototype.hasOwnProperty,Et="~";function on(){}Object.create&&(on.prototype=Object.create(null),new on().__proto__||(Et=!1));function $p(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 $p(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 ho(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)qp.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 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=Et?Et+t:t;if(!this._events[i])return this;if(!r)return ho(this,i),this;var s=this._events[i];if(s.fn)s.fn===r&&(!o||s.once)&&(!n||s.context===n)&&ho(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:ho(this,i)}return this};xt.prototype.removeAllListeners=function(t){var r;return t?(r=Et?Et+t:t,this._events[r]&&ho(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 Wp={};bt(Wp,{delegatedRoutingV1HttpApiClient:()=>Yp});var Bs=Symbol.for("@libp2p/content-routing");var nt=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},qe=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var Zt=class extends Error{static name="NotFoundError";constructor(t="Not found"){super(t),this.name="NotFoundError"}};var fn=class extends Error{static name="InvalidCIDError";constructor(t="Invalid CID"){super(t),this.name="InvalidCIDError"}},$e=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var He=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var ln=Symbol.for("@libp2p/peer-id");function _s(e){return!!e?.[ln]}var Ds=Symbol.for("@libp2p/peer-routing");var vo={};bt(vo,{base58btc:()=>W,base58flickr:()=>Ef});var r0=new Uint8Array(0);function Rs(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 Ls(e){return new TextEncoder().encode(e)}function Ps(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 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 yf=mf,gf=yf,Ns=gf;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 Os(this,t)}},Eo=class{decoders;constructor(t){this.decoders=t}or(t){return Os(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 Os(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 ze({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}=Ns(r,e);return ze({prefix:t,name:e,encode:n,decode:i=>ee(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 ot({name:e,prefix:t,bitsPerChar:r,alphabet:n}){let o=wf(n);return ze({prefix:t,name:e,encode(i){return bf(i,n,r)},decode(i){return xf(i,o,r,e)}})}var W=pe({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Ef=pe({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Ao={};bt(Ao,{base32:()=>jt,base32hex:()=>Cf,base32hexpad:()=>Tf,base32hexpadupper:()=>Bf,base32hexupper:()=>If,base32pad:()=>vf,base32padupper:()=>Af,base32upper:()=>Sf,base32z:()=>_f});var jt=ot({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Sf=ot({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),vf=ot({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Af=ot({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Cf=ot({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),If=ot({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Tf=ot({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Bf=ot({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),_f=ot({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Co={};bt(Co,{base36:()=>Ge,base36upper:()=>Df});var Ge=pe({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Df=pe({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Yt={};bt(Yt,{Digest:()=>Te,create:()=>Kt,decode:()=>me,equals:()=>To,hasCode:()=>Yf});var Rf=Vs,ks=128,Lf=127,Pf=~Lf,Uf=Math.pow(2,31);function Vs(e,t,r){t=t||[],r=r||0;for(var n=r;e>=Uf;)t[r++]=e&255|ks,e/=128;for(;e&Pf;)t[r++]=e&255|ks,e>>>=7;return t[r]=e|0,Vs.bytes=r-n+1,t}var Nf=Io,Of=128,Ks=127;function Io(e,n){var r=0,n=n||0,o=0,i=n,s,c=e.length;do{if(i>=c)throw Io.bytes=0,new RangeError("Could not decode varint");s=e[i++],r+=o<28?(s&Ks)<<o:(s&Ks)*Math.pow(2,o),o+=7}while(s>=Of);return Io.bytes=i-n,r}var kf=Math.pow(2,7),Kf=Math.pow(2,14),Vf=Math.pow(2,21),Mf=Math.pow(2,28),Ff=Math.pow(2,35),qf=Math.pow(2,42),$f=Math.pow(2,49),Hf=Math.pow(2,56),zf=Math.pow(2,63),Gf=function(e){return e<kf?1:e<Kf?2:e<Vf?3:e<Mf?4:e<Ff?5:e<qf?6:e<$f?7:e<Hf?8:e<zf?9:10},Zf={encode:Rf,decode:Nf,encodingLength:Gf},jf=Zf,Ar=jf;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 Te(e,r,t,i)}function me(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 Te(r,o,s,t)}function To(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&Rs(e.bytes,r.bytes)}}var Te=class{code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=n,this.bytes=o}};function Yf(e,t){return e.code===t}function Ms(e,t){let{bytes:r,version:n}=e;switch(n){case 0:return Xf(r,Bo(e),t??W.encoder);default:return Jf(r,Bo(e),t??jt.encoder)}}var Fs=new WeakMap;function Bo(e){let t=Fs.get(e);if(t==null){let r=new Map;return Fs.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!==Qf)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&&To(t.multihash,n.multihash)}toString(t){return Ms(this,t)}toJSON(){return{"/":Ms(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??qs(n,o,i.bytes))}else if(r[tl]===!0){let{version:n,multihash:o,code:i}=r,s=me(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=qs(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 Te(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]=Wf(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 Bo(i).set(n,t),i}};function Wf(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 jt.prefix:{let r=t??jt;return[jt.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 Xf(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 Jf(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,Qf=18;function qs(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 tl=Symbol.for("@ipld/js-cid/CID");var _o={};bt(_o,{identity:()=>Vt});var $s=0,el="identity",Hs=ee;function rl(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($s,Hs(e))}var Vt={code:$s,name:el,encode:Hs,digest:rl};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 Gs=Symbol.for("@achingbrain/uint8arraylist");function zs(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?.[Gs]}var It=class e{bufs;length;[Gs]=!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=zs(this.bufs,t);return r.buf[r.index]}set(t,r){let n=zs(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 Do={};bt(Do,{base10:()=>nl});var nl=pe({prefix:"9",name:"base10",alphabet:"0123456789"});var Ro={};bt(Ro,{base16:()=>ol,base16upper:()=>il});var ol=ot({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),il=ot({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Lo={};bt(Lo,{base2:()=>sl});var sl=ot({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Po={};bt(Po,{base256emoji:()=>ll});var Zs=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}"),al=Zs.reduce((e,t,r)=>(e[r]=t,e),[]),cl=Zs.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function ul(e){return e.reduce((t,r)=>(t+=al[r],t),"")}function fl(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=cl[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(o)}return new Uint8Array(t)}var ll=ze({prefix:"\u{1F680}",name:"base256emoji",encode:ul,decode:fl});var Oo={};bt(Oo,{base64:()=>Uo,base64pad:()=>dl,base64url:()=>No,base64urlpad:()=>hl});var Uo=ot({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),dl=ot({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),No=ot({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),hl=ot({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var ko={};bt(ko,{base8:()=>pl});var pl=ot({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Ko={};bt(Ko,{identity:()=>ml});var ml=ze({prefix:"\0",name:"identity",encode:e=>Ps(e),decode:e=>Ls(e)});var V0=new TextEncoder,M0=new TextDecoder;var Fo={};bt(Fo,{sha256:()=>Tr,sha512:()=>bl});var xl=20;function Mo({name:e,code:t,encode:r,minDigestLength:n,maxDigestLength:o}){return new Vo(e,t,r,n,o)}var Vo=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,r,n,o,i){this.name=t,this.code=r,this.encode=n,this.minDigestLength=o??xl,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?js(n,this.code,r?.truncate):n.then(o=>js(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function js(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 Ws(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var Tr=Mo({name:"sha2-256",code:18,encode:Ws("SHA-256")}),bl=Mo({name:"sha2-512",code:19,encode:Ws("SHA-512")});var Br={...Ko,...Lo,...ko,...Do,...Ro,...Ao,...Co,...vo,...Oo,...Po},J0={...Fo,..._o};function Js(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var Xs=Js("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),qo=Js("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}),wl={utf8:Xs,"utf-8":Xs,hex:Br.base16,latin1:qo,ascii:qo,binary:qo,...Br},hn=wl;function H(e,t="utf8"){let r=hn[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function z(e,t="utf8"){let r=hn[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var El=parseInt("11111",2),$o=parseInt("10000000",2),Sl=parseInt("01111111",2),Qs={0:_r,1:_r,2:vl,3:Il,4:Tl,5:Cl,6:Al,16:_r,22:_r,48:_r};function ne(e,t={offset:0}){let r=e[t.offset]&El;if(t.offset++,Qs[r]!=null)return Qs[r](e,t);throw new Error("No decoder for tag "+r)}function Dr(e,t){let r=0;if((e[t.offset]&$o)===$o){let n=e[t.offset]&Sl,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 Al(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 Cl(e,t){return t.offset++,null}function Il(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 Tl(e,t){let r=Dr(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function Bl(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 Ho(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);let t=Bl(e.byteLength);return new It(Uint8Array.from([t.byteLength|$o]),t)}function St(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]),Ho(t),t)}function pn(e){let t=Uint8Array.from([0]),r=new It(t,e);return new It(Uint8Array.from([3]),Ho(r),r)}function ye(e,t=48){let r=new It;for(let n of e)r.append(n);return new It(Uint8Array.from([t]),Ho(r),r)}async function ta(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]),Dl=Uint8Array.from([6,5,43,129,4,0,34]),Rl=Uint8Array.from([6,5,43,129,4,0,35]),Ll={ext:!0,kty:"EC",crv:"P-256"},Pl={ext:!0,kty:"EC",crv:"P-384"},Ul={ext:!0,kty:"EC",crv:"P-521"},zo=32,Go=48,Zo=66;function jo(e){let t=ne(e);return ea(t)}function ea(e){let t=e[1][1][0],r=1,n,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({...Ll,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 We({...Pl,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({...Ul,key_ops:["verify"],x:n,y:o});throw new nt(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function ra(e){return ye([St(Uint8Array.from([1])),ye([Nl(e.crv)],160),ye([pn(new It(Uint8Array.from([4]),H(e.x??"","base64url"),H(e.y??"","base64url")))],161)]).subarray()}function Nl(e){if(e==="P-256")return _l;if(e==="P-384")return Dl;if(e==="P-521")return Rl;throw new nt(`Invalid curve ${e}`)}var We=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=ra(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 ta(this.jwk,r,t,n)}};function Be(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=Be(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 mn(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 oa(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 yn(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function Mt(e,t){return e<<32-t|e>>>t}var ia=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Ol=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function se(e){if($(e),ia)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=Ol[e[r]];return t}var oe={_0:48,_9:57,A:65,F:70,a:97,f:102};function na(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(ia)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=na(e.charCodeAt(i)),c=na(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 vt(...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 Yo(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 Wo=e=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,e])});function sa(e,t,r){return e&t^~e&r}function aa(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=yn(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=yn(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),oa(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=yn(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 gn=BigInt(4294967295),ca=BigInt(32);function kl(e,t=!1){return t?{h:Number(e&gn),l:Number(e>>ca&gn)}:{h:Number(e>>ca&gn)|0,l:Number(e&gn)|0}}function ua(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}=kl(e[i],t);[n[i],o[i]]=[s,c]}return[n,o]}var Xo=(e,t,r)=>e>>>r,Jo=(e,t,r)=>e<<32-r|t>>>r,_e=(e,t,r)=>e>>>r|t<<32-r,De=(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 fa=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),la=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,da=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),ha=(e,t,r,n,o)=>t+r+n+o+(e/2**32|0)|0,pa=(e,t,r,n,o)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(o>>>0),ma=(e,t,r,n,o,i)=>t+r+n+o+i+(e/2**32|0)|0;var Vl=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]),ge=new Uint32Array(64),Qo=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)ge[f]=t.getUint32(r,!1);for(let f=16;f<64;f++){let y=ge[f-15],E=ge[f-2],b=Mt(y,7)^Mt(y,18)^y>>>3,I=Mt(E,17)^Mt(E,19)^E>>>10;ge[f]=I+ge[f-7]+b+ge[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+sa(c,a,l)+Vl[f]+ge[f]|0,I=(Mt(n,2)^Mt(n,13)^Mt(n,22))+aa(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(ge)}destroy(){this.set(0,0,0,0,0,0,0,0),ie(this.buffer)}},ti=class extends Qo{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 ya=ua(["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))),Ml=ya[0],Fl=ya[1],xe=new Uint32Array(80),be=new Uint32Array(80),ei=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)xe[v]=t.getUint32(r),be[v]=t.getUint32(r+=4);for(let v=16;v<80;v++){let U=xe[v-15]|0,k=be[v-15]|0,M=_e(U,k,1)^_e(U,k,8)^Xo(U,k,7),V=De(U,k,1)^De(U,k,8)^Jo(U,k,7),h=xe[v-2]|0,p=be[v-2]|0,_=_e(h,p,19)^Lr(h,p,61)^Xo(h,p,6),D=De(h,p,19)^Pr(h,p,61)^Jo(h,p,6),A=da(V,D,be[v-7],be[v-16]),m=ha(A,M,_,xe[v-7],xe[v-16]);xe[v]=m|0,be[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=_e(f,y,14)^_e(f,y,18)^Lr(f,y,41),k=De(f,y,14)^De(f,y,18)^Pr(f,y,41),M=f&E^~f&I,V=y&b^~y&C,h=pa(T,k,V,Fl[v],be[v]),p=ma(h,w,U,M,Ml[v],xe[v]),_=h|0,D=_e(n,o,28)^Lr(n,o,34)^Lr(n,o,39),A=De(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=fa(_,A,g);n=la(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(xe,be)}destroy(){ie(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},ri=class extends ei{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=Yo(()=>new ti,Wo(1));var ga=Yo(()=>new ri,Wo(3));var oi=BigInt(0),ni=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 xa(e){if(typeof e=="bigint"){if(!xn(e))throw new Error("positive bigint expected, got "+e)}else Wt(e);return e}function Ur(e){let t=xa(e).toString(16);return t.length&1?"0"+t:t}function ba(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return e===""?oi:BigInt("0x"+e)}function er(e){return ba(se(e))}function Re(e){return ba(se(wn($(e)).reverse()))}function bn(e,t){Wt(t),e=xa(e);let r=ae(e.toString(16).padStart(t*2,"0"));if(r.length!==t)throw new Error("number too large");return r}function ii(e,t){return bn(e,t).reverse()}function wn(e){return Uint8Array.from(e)}var xn=e=>typeof e=="bigint"&&oi<=e;function ql(e,t,r){return xn(e)&&xn(t)&&xn(r)&&t<=e&&e<r}function Nr(e,t,r,n){if(!ql(t,r,n))throw new Error("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function si(e){let t;for(t=0;e>oi;e>>=ni,t+=1);return t}var Or=e=>(ni<<BigInt(e))-ni;function wa(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,vt(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 vt(...w)};return(C,w)=>{f(),E(C);let T;for(;!(T=w(b()));)E();return f(),T}}function we(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),Le=BigInt(2),va=BigInt(3),Aa=BigInt(4),Ca=BigInt(5),$l=BigInt(7),Ia=BigInt(8),Hl=BigInt(9),Ta=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 Ea(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 ci(e,t,r){if(!e.eql(e.sqr(t),r))throw new Error("Cannot find square root")}function Ba(e,t){let r=(e.ORDER+at)/Aa,n=e.pow(t,r);return ci(e,n,t),n}function zl(e,t){let r=(e.ORDER-Ca)/Ia,n=e.mul(t,Le),o=e.pow(n,r),i=e.mul(t,o),s=e.mul(e.mul(i,Le),o),c=e.mul(i,e.sub(s,e.ONE));return ci(e,c,t),c}function Gl(e){let t=nr(e),r=_a(e),n=r(t,t.neg(t.ONE)),o=r(t,n),i=r(t,t.neg(n)),s=(e+$l)/Ta;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 ci(c,C,a),C}}function _a(e){if(e<va)throw new Error("sqrt is not defined for small field");let t=e-at,r=0;for(;t%Le===wt;)t/=Le,r++;let n=Le,o=nr(e);for(;Sa(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return Ba;let i=o.pow(n,t),s=(t+at)/Le;return function(a,l){if(a.is0(l))return l;if(Sa(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 Zl(e){return e%Aa===va?Ba:e%Ia===Ca?zl:e%Ta===Hl?Gl(e):_a(e)}var Da=(e,t)=>(it(e,t)&at)===at,jl=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function ui(e){let t={ORDER:"bigint",BYTES:"number",BITS:"number"},r=jl.reduce((n,o)=>(n[o]="function",n),t);return we(e,r),e}function Yl(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 Sa(e,t){let r=(e.ORDER-at)/Le,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 Wl(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 ai=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}=Wl(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 Yl(this,t,r)}div(t,r){return it(t*Ea(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 Ea(t,this.ORDER)}sqrt(t){return this._sqrt||(this._sqrt=Zl(this.ORDER)),this._sqrt(this,t)}toBytes(t){return this.isLE?ii(t,this.BYTES):bn(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?Re(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 ai(e,t)}function Ra(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 fi(e){let t=Ra(e);return t+Math.ceil(t/2)}function li(e,t,r=!1){$(e);let n=e.length,o=Ra(t),i=fi(t);if(n<16||n<i||n>1024)throw new Error("expected "+i+"-1024 bytes of input, got "+n);let s=r?Re(e):er(e),c=it(s,t-at)+at;return r?ii(c,o):bn(c,o)}var or=BigInt(0),Pe=BigInt(1);function Kr(e,t){let r=t.negate();return e?r:t}function Ue(e,t){let r=kr(e.Fp,t.map(n=>n.Z));return t.map((n,o)=>e.fromAffine(n.toAffine(r[o])))}function Na(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function di(e,t){Na(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 La(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,y=c<0,E=t%2!==0;return{nextN:a,offset:u,isZero:f,isNeg:y,isNegF:E,offsetF:l}}var hi=new WeakMap,Oa=new WeakMap;function pi(e){return Oa.get(e)||1}function Pa(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&Pe&&(n=n.add(o)),o=o.double(),r>>=Pe;return n}precomputeWindow(t,r){let{windows:n,windowSize:o}=di(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=di(t,this.bits);for(let c=0;c<s.windows;c++){let{nextN:a,offset:l,isZero:u,isNeg:f,isNegF:y,offsetF:E}=La(n,c,s);n=a,u?i=i.add(Kr(y,r[E])):o=o.add(Kr(f,r[l]))}return Pa(n),{p:o,f:i}}wNAFUnsafe(t,r,n,o=this.ZERO){let i=di(t,this.bits);for(let s=0;s<i.windows&&n!==or;s++){let{nextN:c,offset:a,isZero:l,isNeg:u}=La(n,s,i);if(n=c,!l){let f=r[a];o=o.add(u?f.negate():f)}}return Pa(n),o}getPrecomputes(t,r,n){let o=hi.get(r);return o||(o=this.precomputeWindow(r,t),t!==1&&(typeof n=="function"&&(o=n(o)),hi.set(r,o))),o}cached(t,r,n){let o=pi(t);return this.wNAF(o,this.getPrecomputes(o,t,n),r)}unsafe(t,r,n,o){let i=pi(t);return i===1?this._unsafeLadder(t,r,o):this.wNAFUnsafe(i,this.getPrecomputes(i,t,n),r,o)}createCache(t,r){Na(r,this.bits),Oa.set(t,r),hi.delete(t)}hasCache(t){return pi(t)!==1}};function ka(e,t,r,n){let o=t,i=e.ZERO,s=e.ZERO;for(;r>or||n>or;)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 Ua(e,t,r){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return ui(t),t}else return nr(e,{isLE:r})}function En(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=Ua(t.p,r.Fp,n),i=Ua(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 Sn(e,t){return function(n){let o=e(n);return{secretKey:o,publicKey:t(o)}}}var Ee=BigInt(0),ct=BigInt(1),mi=BigInt(2),Xl=BigInt(8);function Jl(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 Ka(e,t={}){let r=En("edwards",e,t,t.FpFnLE),{Fp:n,Fn:o}=r,i=r.CURVE,{h:s}=i;we(t,{},{uvRatio:"function"});let c=mi<<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:Ee}}});if(!Jl(n,i,i.Gx,i.Gy))throw new Error("bad curve params: generator point");function u(C,w,T=!1){let v=T?ct:Ee;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?Xl:n.inv(U));let M=a(T*w),V=a(v*w),h=n.mul(U,w);if(k)return{x:Ee,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(Ee,ct,ct,Ee);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=wn($(w,v,"point")),ue(T,"zip215");let M=wn(w),V=w[v-1];M[v-1]=V&-129;let h=Re(M),p=T?c:n.ORDER;Nr("point.y",h,Ee,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===Ee&&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(mi),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(mi*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=>Ue(b,U));return Ue(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===Ee?b.ZERO:this.is0()||w===ct?this:I.unsafe(this,w,v=>Ue(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 Va(e,t,r={}){if(typeof t!="function")throw new Error('"hash" function param is required');we(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(Re(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 _=vt(...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=vt(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=Re(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 Be(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:Sn(U,E),getPublicKey:E,sign:I,verify:w,utils:V,Point:e,lengths:v})}var Ql=BigInt(1),Ma=BigInt(2);var td=BigInt(5),ed=BigInt(8),yi=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),rd={p:yi,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:ed,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function nd(e){let t=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),i=yi,c=e*e%i*e%i,a=X(c,Ma,i)*c%i,l=X(a,Ql,i)*e%i,u=X(l,td,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,Ma,i)*e%i,b2:c}}function od(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}var Fa=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function id(e,t){let r=yi,n=it(t*t*t,r),o=it(n*n*t,r),i=nd(e*o).pow_p_5_8,s=it(e*n*i,r),c=it(t*s*s,r),a=s,l=it(s*Fa,r),u=c===e,f=c===it(-e,r),y=c===it(-e*Fa,r);return u&&(s=a),(f||y)&&(s=l),Da(s,r)&&(s=it(-s,r)),{isValid:u||f,value:s}}var sd=Ka(rd,{uvRatio:id});function ad(e){return Va(sd,ga,Object.assign({adjustScalarBytes:od},e))}var qa=ad({});var Vr=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},vn=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var $a={get(e=globalThis){let t=e.crypto;if(t?.subtle==null)throw new vn("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=$a;var An=32;var gi,cd=(async()=>{try{return await Pt.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function ud(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 fd(e,t,r){return qa.verify(t,r instanceof Uint8Array?r:r.subarray(),e)}async function Ha(e,t,r){return gi==null&&(gi=await cd),gi?ud(e,t,r):fd(e,t,r)}function Cn(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=xi(t,An)}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=Ha(this.raw,r,t);return Cn(o)?o.then(i=>(n?.signal?.throwIfAborted(),i)):o}};function bi(e){return e=xi(e,An),new In(e)}function xi(e,t){if(e=Uint8Array.from(e??[]),e.length!==t)throw new nt(`Key must be a Uint8Array of length ${t}, got ${e.length}`);return e}var dd=Math.pow(2,7),hd=Math.pow(2,14),pd=Math.pow(2,21),wi=Math.pow(2,28),Ei=Math.pow(2,35),Si=Math.pow(2,42),vi=Math.pow(2,49),Q=128,yt=127;function Jt(e){if(e<dd)return 1;if(e<hd)return 2;if(e<pd)return 3;if(e<wi)return 4;if(e<Ei)return 5;if(e<Si)return 6;if(e<vi)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 Ai(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)*wi,r<Q)||(r=e[t+5],n+=(r&yt)*Ei,r<Q)||(r=e[t+6],n+=(r&yt)*Si,r<Q)||(r=e[t+7],n+=(r&yt)*vi,r<Q))return n;throw new RangeError("Could not decode varint")}function md(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)*wi,r<Q)||(r=e.get(t+5),n+=(r&yt)*Ei,r<Q)||(r=e.get(t+6),n+=(r&yt)*Si,r<Q)||(r=e.get(t+7),n+=(r&yt)*vi,r<Q))return n;throw new RangeError("Could not decode varint")}function Ci(e,t=0){return e instanceof Uint8Array?Ai(e,t):md(e,t)}var Ii=new Float32Array([-0]),Se=new Uint8Array(Ii.buffer);function Ga(e,t,r){Ii[0]=e,t[r]=Se[0],t[r+1]=Se[1],t[r+2]=Se[2],t[r+3]=Se[3]}function Za(e,t){return Se[0]=e[t],Se[1]=e[t+1],Se[2]=e[t+2],Se[3]=e[t+3],Ii[0]}var Ti=new Float64Array([-0]),gt=new Uint8Array(Ti.buffer);function ja(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 Ya(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 gd=BigInt(Number.MAX_SAFE_INTEGER),xd=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 Ne;if(t<gd&&t>xd)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>Wa&&(o=0n,++n>Wa&&(n=0n))),new e(Number(o),Number(n))}static fromNumber(t){if(t===0)return Ne;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):Ne}},Ne=new Tt(0,0);Ne.toBigInt=function(){return 0n};Ne.zzEncode=Ne.zzDecode=function(){return this};Ne.length=function(){return 1};var Wa=4294967296n;function Xa(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 Ja(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 Bi(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 Tn(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}var _i=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 Tn(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Ft(this,4);return Tn(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Ft(this,4);let t=Za(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Ft(this,4);let t=Ya(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 Ja(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=Tn(this.buf,this.pos+=4),r=Tn(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=Ai(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 Di(e){return new _i(e instanceof Uint8Array?e:e.subarray())}function sr(e,t,r){let n=Di(e);return t.decode(n,void 0,r)}function Ri(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 Oe=class{fn;len;next;val;constructor(t,r,n){this.fn=t,this.len=r,this.next=void 0,this.val=n}};function Li(){}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}},bd=Ri();function wd(e){return globalThis.Buffer!=null?Ct(e):bd(e)}var qr=class{len;head;tail;states;constructor(){this.len=0,this.head=new Oe(Li,0,0),this.tail=this.head,this.states=null}_push(t,r,n){return this.tail=this.tail.next=new Oe(t,r,n),this.len+=r,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Ni((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(Bn,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(Bn,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(Bn,r.length(),r)}sint64Number(t){let r=Tt.fromNumber(t).zzEncode();return this._push(Bn,r.length(),r)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Pi,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(Ga,4,t)}double(t){return this._push(ja,8,t)}bytes(t){let r=t.length>>>0;return r===0?this._push(Pi,1,0):this.uint32(r)._push(Sd,r,t)}string(t){let r=Xa(t);return r!==0?this.uint32(r)._push(Bi,r,t):this._push(Pi,1,0)}fork(){return this.states=new Ui(this),this.head=this.tail=new Oe(Li,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new Oe(Li,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=wd(this.len),n=0;for(;t!=null;)t.fn(t.val,r,n),n+=t.len,t=t.next;return r}};function Pi(e,t,r){t[r]=e&255}function Ed(e,t,r){for(;e>127;)t[r++]=e&127|128,e>>>=7;t[r]=e}var Ni=class extends Oe{next;constructor(t,r){super(Ed,t,r),this.next=void 0}};function Bn(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 Sd(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(Ad,t,e),this});function vd(e,t,r){t.set(e,r)}function Ad(e,t,r){e.length<40?Bi(e,t,r):t.utf8Write!=null?t.utf8Write(e,r):t.set(H(e),r)}function Oi(){return new qr}function ar(e,t){let r=Oi();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 _n(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 _n("enum",cr.VARINT,r,n)}function ur(e,t){return _n("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 Ki;(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)})(Ki||(Ki={}));var zr={};bt(zr,{MAX_RSA_KEY_SIZE:()=>Vi,generateRSAKeyPair:()=>oc,jwkToJWKKeyPair:()=>ic,jwkToPkcs1:()=>Bd,jwkToPkix:()=>$i,jwkToRSAPrivateKey:()=>Zi,pkcs1MessageToJwk:()=>Fi,pkcs1MessageToRSAPrivateKey:()=>Hi,pkcs1ToJwk:()=>Td,pkcs1ToRSAPrivateKey:()=>nc,pkixMessageToJwk:()=>qi,pkixMessageToRSAPublicKey:()=>Gi,pkixToJwk:()=>_d,pkixToRSAPublicKey:()=>zi});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 rc(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 ec(this.jwk,t,r)}};var Vi=8192,Mi=18,Cd=1062,Id=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function Td(e){let t=ne(e);return Fi(t)}function Fi(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 Bd(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 nt("JWK was missing components");return ye([St(Uint8Array.from([0])),St(H(e.n,"base64url")),St(H(e.e,"base64url")),St(H(e.d,"base64url")),St(H(e.p,"base64url")),St(H(e.q,"base64url")),St(H(e.dp,"base64url")),St(H(e.dq,"base64url")),St(H(e.qi,"base64url"))]).subarray()}function _d(e){let t=ne(e,{offset:0});return qi(t)}function qi(e){let t=ne(e[1],{offset:0});return{kty:"RSA",n:z(t[0],"base64url"),e:z(t[1],"base64url")}}function $i(e){if(e.n==null||e.e==null)throw new nt("JWK was missing components");return ye([Id,pn(ye([St(H(e.n,"base64url")),St(H(e.e,"base64url"))]))]).subarray()}function nc(e){let t=ne(e);return Hi(t)}function Hi(e){let t=Fi(e);return Zi(t)}function zi(e,t){if(e.byteLength>=Cd)throw new qe("Key size is too large");let r=ne(e,{offset:0});return Gi(r,e,t)}function Gi(e,t,r){let n=qi(e);if(r==null){let o=tr(Qt.encode({Type:st.RSA,Data:t}));r=Kt(Mi,o)}return new fr(n,r)}function Zi(e){if(ac(e)>Vi)throw new nt("Key size is too large");let t=ic(e),r=tr(Qt.encode({Type:st.RSA,Data:$i(t.publicKey)})),n=Kt(Mi,r);return new Hr(t.privateKey,new fr(t.publicKey,n))}async function oc(e){if(e>Vi)throw new nt("Key size is too large");let t=await sc(e),r=tr(Qt.encode({Type:st.RSA,Data:$i(t.publicKey)})),n=Kt(Mi,r);return new Hr(t.privateKey,new fr(t.publicKey,n))}function ic(e){if(e==null)throw new nt("Missing key parameter");return{privateKey:e,publicKey:{kty:e.kty,n:e.n,e:e.e}}}async function sc(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 Dd(r,t);return{privateKey:n[0],publicKey:n[1]}}async function ec(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 rc(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 Dd(e,t){if(e.privateKey==null||e.publicKey==null)throw new nt("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 ac(e){if(e.kty!=="RSA")throw new nt("invalid key type");if(e.n==null)throw new nt("invalid key modulus");return H(e.n,"base64url").length*8}var Dn=class{oHash;iHash;blockLen;outputLen;finished=!1;destroyed=!1;constructor(t,r){if(mn(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()}},ji=(e,t,r)=>new Dn(e,t).update(r).digest();ji.create=(e,t)=>new Dn(e,t);var cc=(e,t)=>(e+(e>=0?t:-t)/uc)/t;function Rd(e,t,r){let[[n,o],[i,s]]=t,c=cc(s*e,r),a=cc(-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(si(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 Wi(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function Yi(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&&Wi(r.format),r}var Xi=class extends Error{constructor(t=""){super(t)}},ve={Err:Xi,_tlv:{encode:(e,t)=>{let{Err:r}=ve;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}=ve,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}=ve;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}=ve;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}=ve,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}=ve,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),uc=BigInt(2),Rn=BigInt(3),Ld=BigInt(4);function fc(e,t={}){let r=En("weierstrass",e,t),{Fp:n,Fn:o}=r,i=r.CURVE,{h:s,n:c}=i;we(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=dc(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 vt(lc(P),R)}else return vt(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,Rn),Ld),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 Rd(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(Rn),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,Rn),{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,Rn),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=>Ue(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 Ue(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}=ka(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 lc(e){return Uint8Array.of(e?2:3)}function dc(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function Pd(e,t={}){let{Fn:r}=e,n=t.randomBytes||Qe,o=Object.assign(dc(e.Fp,r),{seed:fi(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 li($(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(!Be(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=Sn(c,a);return Object.freeze({getPublicKey:a,getSharedSecret:u,keygen:y,Point:e,utils:f,lengths:o})}function hc(e,t,r={}){mn(t),we(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)=>ji(t,g,d)),{Fp:i,Fn:s}=e,{ORDER:c,BITS:a}=s,{keygen:l,getPublicKey:u,getSharedSecret:f,utils:y,lengths:E}=Pd(e,r),b={prehash:!0,lowS:typeof r.lowS=="boolean"?r.lowS:!0,format:"compact",extraEntropy:!1},I=c*uc<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){Wi(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}=ve.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(vt(lc((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(Wi(d),d==="der")return ae(ve.hexFromSig(this));let{r:S,s:R}=this,P=s.toBytes(S),N=s.toBytes(R);return d==="recovered"?(T(),vt(Uint8Array.of(this.assertRecovery()),P,N)):vt(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}=Yi(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=vt(...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 cn=s.create(Gt*s.create(Y+mt*K));if(cn===fe)return;let As=(rt.x===mt?0:2)|Number(rt.y&lr),Cs=cn;return R&&C(cn)&&(Cs=s.neg(cn),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 wa(t.outputLen,s.BYTES,o)(R,P).toBytes(S.format)}function A(g,d,S,R={}){let{lowS:P,prehash:N,format:O}=Yi(R,b);if(S=$(S,void 0,"publicKey"),d=p(d,N),!Be(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}=Yi(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 Qi={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Ud={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var pc=BigInt(2);function Nd(e){let t=Qi.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,pc,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,pc,t);if(!Ji.eql(Ji.sqr(M),e))throw new Error("Cannot find square root");return M}var Ji=nr(Qi.p,{sqrt:Nd}),Od=fc(Qi,{Fp:Ji,endo:Ud}),dr=hc(Od,tr);function mc(e,t,r,n){let o=Tr.digest(r instanceof Uint8Array?r:r.subarray());if(Cn(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 Ln=class{type="secp256k1";raw;_key;constructor(t){this._key=gc(t),this.raw=yc(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 mc(this._key,r,t,n)}};function ts(e){return new Ln(e)}function yc(e){return dr.Point.fromBytes(e).toBytes()}function gc(e){try{return dr.Point.fromBytes(e),e}catch(t){throw new qe(String(t))}}function xc(e,t){let{Type:r,Data:n}=Qt.decode(e),o=n??new Uint8Array;switch(r){case st.RSA:return zi(o,t);case st.Ed25519:return bi(o);case st.secp256k1:return ts(o);case st.ECDSA:return jo(o);default:throw new He}}function Pn(e){let{Type:t,Data:r}=Qt.decode(e.digest),n=r??new Uint8Array;switch(t){case st.Ed25519:return bi(n);case st.secp256k1:return ts(n);case st.ECDSA:return jo(n);default:throw new He}}function Xe(e){return Qt.encode({Type:st[e.type],Data:e.raw})}var bc=Symbol.for("nodejs.util.inspect.custom"),kd=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()})`}[ln]=!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(kd,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")}[bc](){return`PeerId(${this.toString()})`}},Un=class extends Gr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},Nn=class extends Gr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},On=class extends Gr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},Kd=2336,Zr=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=Vt.digest(H(this.url))}[bc](){return`PeerId(${this.url})`}[ln]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return j.createV1(Kd,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=z(t)),t.toString()===this.toString())}};var Vd=114,wc=2336;function Ec(e,t){let r;if(e.charAt(0)==="1"||e.charAt(0)==="Q")r=me(W.decode(`z${e}`));else{if(e.startsWith("k51qzi5uqu5")||e.startsWith("kzwfwjn5ji4")||e.startsWith("k2k4r8")||e.startsWith("bafz"))return Md(j.parse(e));if(t==null)throw new nt('Please pass a multibase decoder for strings that do not start with "1" or "Q"');r=me(t.decode(e))}return kn(r)}function kn(e){if(qd(e))return new Un({multihash:e});if(Fd(e))try{let t=Pn(e);if(t.type==="Ed25519")return new Nn({multihash:e,publicKey:t});if(t.type==="secp256k1")return new On({multihash:e,publicKey:t})}catch{let r=z(e.digest);return new Zr(new URL(r))}throw new $e("Supplied PeerID Multihash is invalid")}function Md(e){if(e?.multihash==null||e.version==null||e.version===1&&e.code!==Vd&&e.code!==wc)throw new fn("Supplied PeerID CID is invalid");if(e.code===wc){let t=z(e.multihash.digest);return new Zr(new URL(t))}return kn(e.multihash)}function Fd(e){return e.code===Vt.code}function qd(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"},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 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 $d=45,Hd=15,Fn=new Mn;function Sc(e){if(!(e.length>Hd))return Fn.new(e).parseWith(()=>Fn.readIPv4Addr())}function vc(e){if(e.includes("%")&&(e=e.split("%")[0]),!(e.length>$d))return Fn.new(e).parseWith(()=>Fn.readIPv6Addr())}function qn(e){return!!Sc(e)}function Ac(e){return!!vc(e)}function rs(e){return t=>z(t,e)}function ns(e){return t=>H(t,e)}function hr(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 Cc(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 Ic(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=jt.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 os(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 is=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},Tc=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=is(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},Bc=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(".")},_c=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 Dc(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 es=Object.values(Br).map(e=>e.decoder),zd=(function(){let e=es[0].or(es[1]);return es.slice(2).forEach(t=>e=e.or(t)),e})();function Rc(e){return zd.decode(e)}function Lc(e){return t=>e.encoder.encode(t)}function Gd(e){if(parseInt(e).toString()!==e)throw new le("Value must be an integer")}function Zd(e){if(e<0)throw new le("Value must be a positive integer, or zero")}function jd(e){return t=>{if(t>e)throw new le(`Value must be smaller than or equal to ${e}`)}}function Yd(...e){return t=>{for(let r of e)r(t)}}var jr=Yd(Gd,Zd,jd(65535));var ut=-1,ss=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)}))}},de=new ss,Oh=[{code:4,name:"ip4",size:32,valueToBytes:is,bytesToValue:Bc,validate:e=>{if(!qn(e))throw new le(`Invalid IPv4 address "${e}"`)}},{code:6,name:"tcp",size:16,valueToBytes:ke,bytesToValue:hr,validate:jr},{code:273,name:"udp",size:16,valueToBytes:ke,bytesToValue:hr,validate:jr},{code:33,name:"dccp",size:16,valueToBytes:ke,bytesToValue:hr,validate:jr},{code:41,name:"ip6",size:128,valueToBytes:Tc,bytesToValue:_c,stringToValue:Dc,validate:e=>{if(!Ac(e))throw new le(`Invalid IPv6 address "${e}"`)}},{code:42,name:"ip6zone",size:ut},{code:43,name:"ipcidr",size:8,bytesToValue:rs("base10"),valueToBytes:ns("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: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:rs("base58btc"),valueToBytes:e=>e.startsWith("Q")||e.startsWith("1")?ns("base58btc")(e):j.parse(e).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:os,valueToBytes:Cc},{code:445,name:"onion3",size:296,bytesToValue:os,valueToBytes:Ic},{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:Lc(No),valueToBytes:Rc},{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}];Oh.forEach(e=>{de.addProtocol(e)});function Pc(e){let t=[],r=0;for(;r<e.length;){let n=Ci(e,r),o=de.getProtocol(n),i=Jt(n),s=kh(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 Uc(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 Nc(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 Oc(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 kh(e,t,r){return e.size==null||e.size===0?0:e.size>0?e.size/8:Ci(t,r)}var Kh=Symbol.for("nodejs.util.inspect.custom"),as=Symbol.for("@multiformats/multiaddr");function Vh(e){if(e==null&&(e="/"),kc(e))return e.getComponents();if(e instanceof Uint8Array)return Pc(e);if(typeof e=="string")return e=e.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),e===""&&(e="/"),Nc(e);if(Array.isArray(e))return e;throw new ht("Must be a string, Uint8Array, Component[], or another Multiaddr")}var $n=class e{[as]=!0;#t;#n;#e;constructor(t="/",r={}){this.#t=Vh(t),r.validate!==!1&&Mh(this)}get bytes(){return this.#e==null&&(this.#e=Uc(this.#t)),this.#e}toString(){return this.#n==null&&(this.#n=Oc(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)}[Kh](){return`Multiaddr(${this.toString()})`}};function Mh(e){e.getComponents().forEach(t=>{let r=de.getProtocol(t.code);t.value!=null&&r.validate?.(t.value)})}function kc(e){return!!e?.[as]}function Kc(e){return new $n(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()}}function Fh(e,t){if(typeof e=="string")return qh(e);if(typeof e=="number")return zh(e,t);throw Error(`Value provided to ms() must be a string or number. value=${JSON.stringify(e)}`)}var Hn=Fh;function qh(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 $h(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 Hh(e){let t=Math.abs(e);return t>=315576e5?Ke(e,t,315576e5,"year"):t>=26298e5?Ke(e,t,26298e5,"month"):t>=6048e5?Ke(e,t,6048e5,"week"):t>=864e5?Ke(e,t,864e5,"day"):t>=36e5?Ke(e,t,36e5,"hour"):t>=6e4?Ke(e,t,6e4,"minute"):t>=1e3?Ke(e,t,1e3,"second"):`${e} ms`}function zh(e,t){if(typeof e!="number"||!Number.isFinite(e))throw Error("Value provided to ms.format() must be of type number.");return t?.long?Hh(e):$h(e)}function Ke(e,t,r,n){let o=t>=r*1.5;return`${Math.round(e/r)} ${n}${o?"s":""}`}function cs(e){r.debug=r,r.default=r,r.coerce=a,r.disable=i,r.enable=o,r.enabled=s,r.humanize=Hn,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 zn=Jh(),Gh=["#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 Zh(){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 jh(e){if(e[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+e[0]+(this.useColors?"%c ":" ")+"+"+Hn(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 Yh=console.debug??console.log??(()=>{});function Wh(e){try{e?zn?.setItem("debug",e):zn?.removeItem("debug")}catch{}}function Xh(){let e;try{e=zn?.getItem("debug")}catch{}return!e&&typeof globalThis.process<"u"&&"env"in globalThis.process&&(e=globalThis.process.env.DEBUG),e}function Jh(){try{return localStorage}catch{}}function Qh(e){e.j=function(t){try{return JSON.stringify(t)}catch(r){return"[UnexpectedJSONParseError]: "+r.message}}}var Vc=cs({formatArgs:jh,save:Wh,load:Xh,useColors:Zh,setupFormatters:Qh,colors:Gh,storage:zn,log:Yh});var At=Vc;At.formatters.b=e=>e==null?"undefined":W.baseEncode(e);At.formatters.t=e=>e==null?"undefined":jt.baseEncode(e);At.formatters.m=e=>e==null?"undefined":Uo.baseEncode(e);At.formatters.p=e=>e==null?"undefined":e.toString();At.formatters.c=e=>e==null?"undefined":e.toString();At.formatters.k=e=>e==null?"undefined":e.toString();At.formatters.a=e=>e==null?"undefined":e.toString();function Mc(e,t=""){let r=Fc(e.message),n=Fc(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
|
|
11
|
-
${t}${e.errors.map(n=>`${
|
|
10
|
+
${t}`)}`:r!=null?`${r}`:`${e.toString()}`}function tp(e){return e instanceof AggregateError||e?.name==="AggregateError"&&Array.isArray(e.errors)}function qc(e,t=""){if(tp(e)){let r=Mc(e,t);return e.errors.length>0?(t=`${t} `,r+=`
|
|
11
|
+
${t}${e.errors.map(n=>`${qc(n,`${t}`)}`).join(`
|
|
12
12
|
${t}`)}`):r+=`
|
|
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);})();
|
|
13
|
+
${t}[Error list was empty]`,r.trim()}return Mc(e,t)}At.formatters.e=e=>e==null?"undefined":qc(e);function ep(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 Ve(e,t){let r=ep(`${e}:trace`);return At.enabled(`${e}:trace`)&&At.names.map(n=>n.toString()).find(n=>n.includes(":trace"))!=null&&(r=At(`${e}:trace`,t)),Object.assign(At(e,t),{error:At(`${e}:error`,t),trace:r,newScope:n=>Ve(`${e}:${n}`,t)})}function Fc(e){if(e!=null&&(e=e.trim(),e.length!==0))return e}var Kp=xo(fs(),1);var qt=class extends Error{static name="SignatureVerificationError";constructor(t="Record signature verification failed"){super(t),this.name="SignatureVerificationError"}},Gn=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"}},Zn=class extends Error{static name="RecordTooLargeError";constructor(t="The record is too large"){super(t),this.name="RecordTooLargeError"}},jn=class extends Error{static name="InvalidValueError";constructor(t="Value must be a valid content path starting with /"){super(t),this.name="InvalidValueError"}},Yn=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 rp=["string","number","bigint","symbol"],np=["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(rp.includes(t))return t;if(t==="function")return"Function";if(Array.isArray(e))return"Array";if(op(e))return"Buffer";let r=ip(e);return r||"Object"}function op(e){return e&&e.constructor&&e.constructor.isBuffer&&e.constructor.isBuffer.call(null,e)}function ip(e){let t=Object.prototype.toString.call(e).slice(8,-1);if(np.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",sp=new TextDecoder,ap=new TextEncoder;function Wn(e){return yr&&globalThis.Buffer.isBuffer(e)}function ls(e){return e instanceof Uint8Array?Wn(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):e:Uint8Array.from(e)}var Zc=yr?(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?sp.decode(e.subarray(t,r)):zc(e,t,r),jc=yr?e=>e.length>64?globalThis.Buffer.from(e):Hc(e):e=>e.length>64?ap.encode(e):Hc(e),te=e=>Uint8Array.from(e),gr=yr?(e,t,r)=>Wn(e)?new Uint8Array(e.subarray(t,r)):e.slice(t,r):(e,t,r)=>e.slice(t,r),Yc=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},Wc=yr?e=>globalThis.Buffer.allocUnsafe(e):e=>new Uint8Array(e);function Xn(e,t){if(Wn(e)&&Wn(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 cp(n)}var Gc=4096;function cp(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 up=256,Xr=class{constructor(t=up){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=gr(n,0,this.cursor)}else r=Yc(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 Xc(e,t,r,n){return new L(x.uint,Bt(e,t+1,n),2)}function Jc(e,t,r,n){return new L(x.uint,_t(e,t+1,n),3)}function Qc(e,t,r,n){return new L(x.uint,Dt(e,t+1,n),5)}function tu(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 eu(e,t,r,n){return new L(x.negint,-1-Bt(e,t+1,n),2)}function ru(e,t,r,n){return new L(x.negint,-1-_t(e,t+1,n),3)}function nu(e,t,r,n){return new L(x.negint,-1-Dt(e,t+1,n),5)}var hs=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(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 Jn(e,t){let r=t.value,n=typeof r=="bigint"?r*hs-ou:r*-1-1;pt(e,t.type.majorEncoded,n)}Jn.encodedSize=function(t){let r=t.value,n=typeof r=="bigint"?r*hs-ou:r*-1-1;return n<ft[0]?1:n<ft[1]?2:n<ft[2]?3:n<ft[3]?5:9};Jn.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 su(e,t,r,n){return Qr(e,t,1,r)}function au(e,t,r,n){return Qr(e,t,2,Bt(e,t+1,n))}function cu(e,t,r,n){return Qr(e,t,3,_t(e,t+1,n))}function uu(e,t,r,n){return Qr(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 Qr(e,t,9,o)}function Qn(e){return e.encodedBytes===void 0&&(e.encodedBytes=e.type===x.string?jc(e.value):e.value),e.encodedBytes}function xr(e,t){let r=Qn(t);pt(e,t.type.majorEncoded,r.length),e.push(r)}xr.encodedSize=function(t){let r=Qn(t);return pt.encodedSize(r.length)+r.length};xr.compareTokens=function(t,r){return lp(Qn(t),Qn(r))};function lp(e,t){return e.length<t.length?-1:e.length>t.length?1:Xn(e,t)}function tn(e,t,r,n,o){let i=r+n;he(e,t,i);let s=new L(x.string,Zc(e,t+r,t+i),i);return o.retainStringBytes===!0&&(s.byteValue=gr(e,t+r,t+i)),s}function lu(e,t,r,n){return tn(e,t,1,r,n)}function du(e,t,r,n){return tn(e,t,2,Bt(e,t+1,n),n)}function hu(e,t,r,n){return tn(e,t,3,_t(e,t+1,n),n)}function pu(e,t,r,n){return tn(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 tn(e,t,9,o,n)}var yu=xr;function br(e,t,r,n){return new L(x.array,n,r)}function gu(e,t,r,n){return br(e,t,1,r)}function xu(e,t,r,n){return br(e,t,2,Bt(e,t+1,n))}function bu(e,t,r,n){return br(e,t,3,_t(e,t+1,n))}function wu(e,t,r,n){return br(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 br(e,t,9,o)}function Su(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 to(e,t){pt(e,x.array.majorEncoded,t.value)}to.compareTokens=Ut.compareTokens;to.encodedSize=function(t){return pt.encodedSize(t.value)};function wr(e,t,r,n){return new L(x.map,n,r)}function vu(e,t,r,n){return wr(e,t,1,r)}function Au(e,t,r,n){return wr(e,t,2,Bt(e,t+1,n))}function Cu(e,t,r,n){return wr(e,t,3,_t(e,t+1,n))}function Iu(e,t,r,n){return wr(e,t,5,Dt(e,t+1,n))}function Tu(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 Bu(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 eo(e,t){pt(e,x.map.majorEncoded,t.value)}eo.compareTokens=Ut.compareTokens;eo.encodedSize=function(t){return pt.encodedSize(t.value)};function _u(e,t,r,n){return new L(x.tag,r,1)}function Du(e,t,r,n){return new L(x.tag,Bt(e,t+1,n),2)}function Ru(e,t,r,n){return new L(x.tag,_t(e,t+1,n),3)}function Lu(e,t,r,n){return new L(x.tag,Dt(e,t+1,n),5)}function Pu(e,t,r,n){return new L(x.tag,Rt(e,t+1,n),9)}function ro(e,t){pt(e,x.tag.majorEncoded,t.value)}ro.compareTokens=Ut.compareTokens;ro.encodedSize=function(t){return pt.encodedSize(t.value)};var gp=20,xp=21,bp=22,wp=23;function Uu(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 Nu(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 Ou(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 Ku(e,t,r,n){return ps(qu(e,t+1),9,n)}function no(e,t,r){let n=t.value;if(n===!1)e.push([x.float.majorEncoded|gp]);else if(n===!0)e.push([x.float.majorEncoded|xp]);else if(n===null)e.push([x.float.majorEncoded|bp]);else if(n===void 0)e.push([x.float.majorEncoded|wp]);else{let o,i=!1;(!r||r.float64!==!0)&&(Mu(n),o=ms(Ht,1),n===o||Number.isNaN(n)?(Ht[0]=249,e.push(Ht.slice(0,3)),i=!0):(Fu(n),o=ys(Ht,1),n===o&&(Ht[0]=250,e.push(Ht.slice(0,5)),i=!0))),i||(Ep(n),o=qu(Ht,1),Ht[0]=251,e.push(Ht.slice(0,9)))}}no.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=ms(Ht,1);if(n===o||Number.isNaN(n))return 3;if(Fu(n),o=ys(Ht,1),n===o)return 5}return 9};var Vu=new ArrayBuffer(9),Nt=new DataView(Vu,1),Ht=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 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 Fu(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 Ep(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)}no.compareTokens=Ut.compareTokens;function Z(e,t,r){throw new Error(`${F} encountered invalid minor (${r}) for major ${e[t]>>>5}`)}function oo(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]=oo("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]=oo("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]=Iu;B[187]=Tu;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]=Pu;B[220]=Z;B[221]=Z;B[222]=Z;B[223]=Z;for(let e=224;e<=243;e++)B[e]=oo("simple values are not supported");B[244]=Z;B[245]=Z;B[246]=Z;B[247]=Uu;B[248]=oo("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 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 $u(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 zu=Object.freeze({float64:!0,mapSorter:Ip,quickEncodeToken:$u});function vp(){let e=[];return e[x.uint.major]=Ut,e[x.negint.major]=Jn,e[x.bytes.major]=xr,e[x.string.major]=yu,e[x.array.major]=to,e[x.map.major]=eo,e[x.tag.major]=ro,e[x.float.major]=no,e}var Ap=vp(),gs=new Xr,so=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)}},Ae={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)},Ce={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?Ae.true:Ae.false},null(e,t,r,n){return Ae.null},undefined(e,t,r,n){return Ae.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?[Ae.emptyArray,new L(x.break)]:Ae.emptyArray;n=so.createCheck(n,e);let o=[],i=0;for(let s of e)o[i++]=io(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?[Ae.emptyMap,new L(x.break)]:Ae.emptyMap;n=so.createCheck(n,e);let c=[],a=0;for(let l of i)c[a++]=[io(l,r,n),io(o?e.get(l):e[l],r,n)];return Cp(c,r),r.addBreakTokens?[new L(x.map,s),c,new L(x.break)]:[new L(x.map,s),c]}};Ce.Map=Ce.Object;Ce.Buffer=Ce.Uint8Array;for(let e of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))Ce[`${e}Array`]=Ce.DataView;function io(e,t={},r){let n=$c(e),o=t&&t.typeEncoders&&t.typeEncoders[n]||Ce[n];if(typeof o=="function"){let s=o(e,n,t,r);if(s!=null)return s}let i=Ce[n];if(!i)throw new Error(`${ds} unsupported type: ${n}`);return i(e,n,t,r)}function Cp(e,t){t.mapSorter&&e.sort(t.mapSorter)}function Ip(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)),Xn(r._keyBytes,n._keyBytes)}throw new Error("rfc8949MapSorter: complex key types are not supported yet")}function Hu(e){return Tp(e,Ap,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=io(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(),Gu(gs,n,t,r),gs.toBytes(!0)}var Bp={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},ao=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"),co=Symbol.for("BREAK");function _p(e,t,r){let n=[];for(let o=0;o<e.value;o++){let i=Er(t,r);if(i===co){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 Dp(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===co){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 co;if(r.type.terminal)return r.value;if(r.type===x.array)return _p(r,e,t);if(r.type===x.map)return Dp(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 Zu(e,t){if(!(e instanceof Uint8Array))throw new Error(`${F} data to decode must be a Uint8Array`);t=Object.assign({},Bp,t);let r=t.tokenizer||new ao(e,t),n=Er(r,t);if(n===en)throw new Error(`${F} did not find any content to decode`);if(n===co)throw new Error(`${F} got unexpected break`);return[n,e.subarray(r.pos())]}function xs(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 Pp=Ve("ipns:utils"),ju=H("/ipns/");var Up=0,Np=18;function Yu(e){let t;if(e.pubKey!=null)try{t=xc(e.pubKey)}catch(r){throw Pp.error(r),r}if(t!=null)return t}function Wu(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 Ie(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=Xu(t.data),n=Op(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([ju,e.bytes])}function Sr(e){let t=me(e.slice(ju.length));if(!uo(t,Up)&&!uo(t,Np))throw new $e("Multihash in IPNS key was not identity or sha2-256");return t}function Xu(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 Op(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 jn("Value must be a valid content path starting with /")}function kp(e){if(e.data==null)throw new Yn("Record data is missing");let t=Xu(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 uo(e,t){return e.code===t}var e1=Ve("ipns"),r1=300*1e9,Vp="/ipns/",n1=Vp.length;var Ju=xo(fs(),1);var fo=Ve("ipns:validator"),Mp=1024*10;async function Fp(e,t){let r=Ie(t),n;try{let o=Wu(r.data);n=await e.verify(o,r.signatureV2)}catch{n=!1}if(!n)throw fo.error("record signature verification failed"),new qt("Record signature verification failed");if(r.validityType===$t.ValidityType.EOL){if(Ju.default.fromString(r.validity).toDate().getTime()<Date.now())throw fo.error("record has expired"),new Gn("record has expired")}else if(r.validityType!=null)throw fo.error("the validity type is unsupported"),new mr("The validity type is unsupported");fo("ipns record for %s is valid",r.value)}async function Qu(e,t){if(t.byteLength>Mp)throw new Zn("The record is too large");let r=Sr(e),n;uo(r,0)&&(n=Pn(r));let o=Ie(t),i=Yu(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 Fp(i,t)}var lo=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 lo("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(ef(),1);var Es=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 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(rf(s));return}if(s&&(a=()=>{y(rf(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 Hp(e){return e[Symbol.asyncIterator]!=null}function zp(e){if(Hp(e))return(async()=>{for await(let t of e)return t})();for(let t of e)return t}var nf=zp;function Gp(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=Gp;function Zp(e){return e[Symbol.asyncIterator]!=null}function jp(e,t){let r=0;if(Zp(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=jp;var af=H("/ipns/");function cf(e){return J(e.subarray(0,af.byteLength),af)}var po=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 Zt)return;throw n}}async provide(){}async cancelReprovide(){}async put(t,r,n){if(!cf(t))return;let o=Sr(t),i=j.createV1(114,o),s=Ie(r);await this.client.putIPNS(i,s,n)}async get(t,r){if(!cf(t))throw new Zt("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 Zt("Not found"):i}}toString(){return`DelegatedRoutingV1HttpApiClientContentRouting(${this.client.url})`}},mo=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 Zt("Not found")}async*getClosestPeers(t,r={}){let n;try{n=j.decode(t)}catch{n=kn(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 yo={concurrentRequests:4,timeout:3e4,cacheTTL:300*1e3,cacheName:"delegated-routing-v1-cache"},go=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??yo.concurrentRequests}),this.inFlightRequests=new Map,this.url=r.url instanceof URL?r.url:new URL(r.url),this.timeout=r.timeout??yo.timeout,this.filterAddrs=r.filterAddrs,this.filterProtocols=r.filterProtocols,this.contentRouting=new po(this),this.peerRouting=new mo(this),this.cacheName=r.cacheName??yo.cacheName,this.cacheTTL=r.cacheTTL??yo.cacheTTL}get[Bs](){return this.contentRouting}get[Ds](){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(_s(t))n=t.toCID().toString();else if(j.asCID(t)===t||t instanceof j)n=t.toV1().toString();else throw new nt("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 Zt("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 Zt("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 Qu(nn(t.multihash),y),Ie(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(Kc)??[];return t.Protocols!=null&&r.push(...t.Protocols),t.Protocol!=null&&(r.push(t.Protocol),delete t.Protocol),{...t,Schema:"peer",ID:Ec(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 Yp(e){return t=>new go(t,e)}return pf(Wp);})();
|
|
14
14
|
/*! Bundled license information:
|
|
15
15
|
|
|
16
16
|
@noble/hashes/utils.js:
|